bd72b6314b5536a1dbf6d5a5d0d0d4e8851f48c7
[openwrt/openwrt.git] /
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
5
6 ath11k fails to load if there are multiple ath11k PCI devices with same name:
7
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
14
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.
18
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.
24
25 Here's an example hierarchy with one WCN6855:
26
27 ath11k
28 `-- pci-0000:06:00.0
29 |-- mac0
30 | |-- dfs_block_radar_events
31 | |-- dfs_simulate_radar
32 | |-- ext_rx_stats
33 | |-- ext_tx_stats
34 | |-- fw_dbglog_config
35 | |-- fw_stats
36 | | |-- beacon_stats
37 | | |-- pdev_stats
38 | | `-- vdev_stats
39 | |-- htt_stats
40 | |-- htt_stats_reset
41 | |-- htt_stats_type
42 | `-- pktlog_filter
43 |-- simulate_fw_crash
44 `-- soc_dp_stats
45
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.
48
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
52
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
56 ---
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(-)
60
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;
68 #endif
69 struct ath11k_soc_dp_stats soc_stats;
70
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))
75 return 0;
76
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);
80 -
81 debugfs_create_file("simulate_fw_crash", 0600, ab->debugfs_soc, ab,
82 &fops_simulate_fw_crash);
83
84 @@ -1001,15 +997,51 @@ void ath11k_debugfs_pdev_destroy(struct
85
86 int ath11k_debugfs_soc_create(struct ath11k_base *ab)
87 {
88 - ab->debugfs_ath11k = debugfs_create_dir("ath11k", NULL);
89 + struct dentry *root;
90 + bool dput_needed;
91 + char name[64];
92 + int ret;
93 +
94 + root = debugfs_lookup("ath11k", NULL);
95 + if (!root) {
96 + root = debugfs_create_dir("ath11k", NULL);
97 + if (IS_ERR_OR_NULL(root))
98 + return PTR_ERR(root);
99 +
100 + dput_needed = false;
101 + } else {
102 + /* a dentry from lookup() needs dput() after we don't use it */
103 + dput_needed = true;
104 + }
105 +
106 + scnprintf(name, sizeof(name), "%s-%s", ath11k_bus_str(ab->hif.bus),
107 + dev_name(ab->dev));
108 +
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);
112 + goto out;
113 + }
114 +
115 + ret = 0;
116 +
117 +out:
118 + if (dput_needed)
119 + dput(root);
120
121 - return PTR_ERR_OR_ZERO(ab->debugfs_ath11k);
122 + return ret;
123 }
124
125 void ath11k_debugfs_soc_destroy(struct ath11k_base *ab)
126 {
127 - debugfs_remove_recursive(ab->debugfs_ath11k);
128 - ab->debugfs_ath11k = NULL;
129 + debugfs_remove_recursive(ab->debugfs_soc);
130 + ab->debugfs_soc = NULL;
131 +
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
135 + * debugfs.
136 + */
137 }
138 EXPORT_SYMBOL(ath11k_debugfs_soc_destroy);
139