1 From 323d91d4684d238f6bc3693fed93caf795378fe0 Mon Sep 17 00:00:00 2001
2 From: Kalle Valo <quic_kvalo@quicinc.com>
3 Date: Thu, 22 Dec 2022 19:15:59 +0200
4 Subject: [PATCH] wifi: ath11k: debugfs: fix to work with multiple PCI devices
6 ath11k fails to load if there are multiple ath11k PCI devices with same name:
8 ath11k_pci 0000:01:00.0: Hardware name qcn9074 hw1.0
9 debugfs: Directory 'ath11k' with parent '/' already present!
10 ath11k_pci 0000:01:00.0: failed to create ath11k debugfs
11 ath11k_pci 0000:01:00.0: failed to create soc core: -17
12 ath11k_pci 0000:01:00.0: failed to init core: -17
13 ath11k_pci: probe of 0000:01:00.0 failed with error -17
15 Fix this by creating a directory for each ath11k device using schema
16 <bus>-<devname>, for example "pci-0000:06:00.0". This directory created under
17 the top-level ath11k directory, for example /sys/kernel/debug/ath11k.
19 The reference to the toplevel ath11k directory is not stored anymore within ath11k, instead
20 it's retrieved using debugfs_lookup(). If the directory does not exist it will
21 be created. After the last directory from the ath11k directory is removed, for
22 example when doing rmmod ath11k, the empty ath11k directory is left in place,
23 it's a minor cosmetic issue anyway.
25 Here's an example hierarchy with one WCN6855:
30 | |-- dfs_block_radar_events
31 | |-- dfs_simulate_radar
34 | |-- fw_dbglog_config
46 I didn't have a test setup where I could connect multiple ath11k devices to the
47 same the host, so I have only tested this with one device.
49 Tested-on: WCN6855 hw2.0 PCI WLAN.HSP.1.1-03125-QCAHSPSWPL_V1_V2_SILICONZ_LITE-3.6510.9
50 Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.5.0.1-01208-QCAHKSWPL_SILICONZ-1
51 Tested-on: QCN9074 hw1.0 PCI WLAN.HK.2.5.0.1-01208-QCAHKSWPL_SILICONZ-1
53 Tested-by: Robert Marko <robert.marko@sartura.hr>
54 Signed-off-by: Kalle Valo <quic_kvalo@quicinc.com>
55 Link: https://lore.kernel.org/r/20221220121231.20120-1-kvalo@kernel.org
57 drivers/net/wireless/ath/ath11k/core.h | 1 -
58 drivers/net/wireless/ath/ath11k/debugfs.c | 48 +++++++++++++++++++----
59 2 files changed, 40 insertions(+), 9 deletions(-)
61 --- a/drivers/net/wireless/ath/ath11k/core.h
62 +++ b/drivers/net/wireless/ath/ath11k/core.h
63 @@ -912,7 +912,6 @@ struct ath11k_base {
64 enum ath11k_dfs_region dfs_region;
65 #ifdef CPTCFG_ATH11K_DEBUGFS
66 struct dentry *debugfs_soc;
67 - struct dentry *debugfs_ath11k;
69 struct ath11k_soc_dp_stats soc_stats;
71 --- a/drivers/net/wireless/ath/ath11k/debugfs.c
72 +++ b/drivers/net/wireless/ath/ath11k/debugfs.c
73 @@ -976,10 +976,6 @@ int ath11k_debugfs_pdev_create(struct at
74 if (test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags))
77 - ab->debugfs_soc = debugfs_create_dir(ab->hw_params.name, ab->debugfs_ath11k);
78 - if (IS_ERR(ab->debugfs_soc))
79 - return PTR_ERR(ab->debugfs_soc);
81 debugfs_create_file("simulate_fw_crash", 0600, ab->debugfs_soc, ab,
82 &fops_simulate_fw_crash);
84 @@ -1001,15 +997,51 @@ void ath11k_debugfs_pdev_destroy(struct
86 int ath11k_debugfs_soc_create(struct ath11k_base *ab)
88 - ab->debugfs_ath11k = debugfs_create_dir("ath11k", NULL);
89 + struct dentry *root;
94 + root = debugfs_lookup("ath11k", NULL);
96 + root = debugfs_create_dir("ath11k", NULL);
97 + if (IS_ERR_OR_NULL(root))
98 + return PTR_ERR(root);
100 + dput_needed = false;
102 + /* a dentry from lookup() needs dput() after we don't use it */
103 + dput_needed = true;
106 + scnprintf(name, sizeof(name), "%s-%s", ath11k_bus_str(ab->hif.bus),
107 + dev_name(ab->dev));
109 + ab->debugfs_soc = debugfs_create_dir(name, root);
110 + if (IS_ERR_OR_NULL(ab->debugfs_soc)) {
111 + ret = PTR_ERR(ab->debugfs_soc);
121 - return PTR_ERR_OR_ZERO(ab->debugfs_ath11k);
125 void ath11k_debugfs_soc_destroy(struct ath11k_base *ab)
127 - debugfs_remove_recursive(ab->debugfs_ath11k);
128 - ab->debugfs_ath11k = NULL;
129 + debugfs_remove_recursive(ab->debugfs_soc);
130 + ab->debugfs_soc = NULL;
132 + /* We are not removing ath11k directory on purpose, even if it
133 + * would be empty. This simplifies the directory handling and it's
134 + * a minor cosmetic issue to leave an empty ath11k directory to
138 EXPORT_SYMBOL(ath11k_debugfs_soc_destroy);