Loading...
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * mac80211 glue code for mac80211 ST-Ericsson CW1200 drivers
4 * DebugFS code
5 *
6 * Copyright (c) 2010, ST-Ericsson
7 * Author: Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no>
8 */
9
10#include <linux/module.h>
11#include <linux/debugfs.h>
12#include <linux/seq_file.h>
13#include "cw1200.h"
14#include "debug.h"
15#include "fwio.h"
16
17/* join_status */
18static const char * const cw1200_debug_join_status[] = {
19 "passive",
20 "monitor",
21 "station (joining)",
22 "station (not authenticated yet)",
23 "station",
24 "adhoc",
25 "access point",
26};
27
28/* WSM_JOIN_PREAMBLE_... */
29static const char * const cw1200_debug_preamble[] = {
30 "long",
31 "short",
32 "long on 1 and 2 Mbps",
33};
34
35
36static const char * const cw1200_debug_link_id[] = {
37 "OFF",
38 "REQ",
39 "SOFT",
40 "HARD",
41 "RESET",
42 "RESET_REMAP",
43};
44
45static const char *cw1200_debug_mode(int mode)
46{
47 switch (mode) {
48 case NL80211_IFTYPE_UNSPECIFIED:
49 return "unspecified";
50 case NL80211_IFTYPE_MONITOR:
51 return "monitor";
52 case NL80211_IFTYPE_STATION:
53 return "station";
54 case NL80211_IFTYPE_ADHOC:
55 return "adhoc";
56 case NL80211_IFTYPE_MESH_POINT:
57 return "mesh point";
58 case NL80211_IFTYPE_AP:
59 return "access point";
60 case NL80211_IFTYPE_P2P_CLIENT:
61 return "p2p client";
62 case NL80211_IFTYPE_P2P_GO:
63 return "p2p go";
64 default:
65 return "unsupported";
66 }
67}
68
69static void cw1200_queue_status_show(struct seq_file *seq,
70 struct cw1200_queue *q)
71{
72 int i;
73 seq_printf(seq, "Queue %d:\n", q->queue_id);
74 seq_printf(seq, " capacity: %zu\n", q->capacity);
75 seq_printf(seq, " queued: %zu\n", q->num_queued);
76 seq_printf(seq, " pending: %zu\n", q->num_pending);
77 seq_printf(seq, " sent: %zu\n", q->num_sent);
78 seq_printf(seq, " locked: %s\n", q->tx_locked_cnt ? "yes" : "no");
79 seq_printf(seq, " overfull: %s\n", q->overfull ? "yes" : "no");
80 seq_puts(seq, " link map: 0-> ");
81 for (i = 0; i < q->stats->map_capacity; ++i)
82 seq_printf(seq, "%.2d ", q->link_map_cache[i]);
83 seq_printf(seq, "<-%zu\n", q->stats->map_capacity);
84}
85
86static void cw1200_debug_print_map(struct seq_file *seq,
87 struct cw1200_common *priv,
88 const char *label,
89 u32 map)
90{
91 int i;
92 seq_printf(seq, "%s0-> ", label);
93 for (i = 0; i < priv->tx_queue_stats.map_capacity; ++i)
94 seq_printf(seq, "%s ", (map & BIT(i)) ? "**" : "..");
95 seq_printf(seq, "<-%zu\n", priv->tx_queue_stats.map_capacity - 1);
96}
97
98static int cw1200_status_show(struct seq_file *seq, void *v)
99{
100 int i;
101 struct list_head *item;
102 struct cw1200_common *priv = seq->private;
103 struct cw1200_debug_priv *d = priv->debug;
104
105 seq_puts(seq, "CW1200 Wireless LAN driver status\n");
106 seq_printf(seq, "Hardware: %d.%d\n",
107 priv->wsm_caps.hw_id,
108 priv->wsm_caps.hw_subid);
109 seq_printf(seq, "Firmware: %s %d.%d\n",
110 cw1200_fw_types[priv->wsm_caps.fw_type],
111 priv->wsm_caps.fw_ver,
112 priv->wsm_caps.fw_build);
113 seq_printf(seq, "FW API: %d\n",
114 priv->wsm_caps.fw_api);
115 seq_printf(seq, "FW caps: 0x%.4X\n",
116 priv->wsm_caps.fw_cap);
117 seq_printf(seq, "FW label: '%s'\n",
118 priv->wsm_caps.fw_label);
119 seq_printf(seq, "Mode: %s%s\n",
120 cw1200_debug_mode(priv->mode),
121 priv->listening ? " (listening)" : "");
122 seq_printf(seq, "Join state: %s\n",
123 cw1200_debug_join_status[priv->join_status]);
124 if (priv->channel)
125 seq_printf(seq, "Channel: %d%s\n",
126 priv->channel->hw_value,
127 priv->channel_switch_in_progress ?
128 " (switching)" : "");
129 if (priv->rx_filter.promiscuous)
130 seq_puts(seq, "Filter: promisc\n");
131 else if (priv->rx_filter.fcs)
132 seq_puts(seq, "Filter: fcs\n");
133 if (priv->rx_filter.bssid)
134 seq_puts(seq, "Filter: bssid\n");
135 if (!priv->disable_beacon_filter)
136 seq_puts(seq, "Filter: beacons\n");
137
138 if (priv->enable_beacon ||
139 priv->mode == NL80211_IFTYPE_AP ||
140 priv->mode == NL80211_IFTYPE_ADHOC ||
141 priv->mode == NL80211_IFTYPE_MESH_POINT ||
142 priv->mode == NL80211_IFTYPE_P2P_GO)
143 seq_printf(seq, "Beaconing: %s\n",
144 priv->enable_beacon ?
145 "enabled" : "disabled");
146
147 for (i = 0; i < 4; ++i)
148 seq_printf(seq, "EDCA(%d): %d, %d, %d, %d, %d\n", i,
149 priv->edca.params[i].cwmin,
150 priv->edca.params[i].cwmax,
151 priv->edca.params[i].aifns,
152 priv->edca.params[i].txop_limit,
153 priv->edca.params[i].max_rx_lifetime);
154
155 if (priv->join_status == CW1200_JOIN_STATUS_STA) {
156 static const char *pm_mode = "unknown";
157 switch (priv->powersave_mode.mode) {
158 case WSM_PSM_ACTIVE:
159 pm_mode = "off";
160 break;
161 case WSM_PSM_PS:
162 pm_mode = "on";
163 break;
164 case WSM_PSM_FAST_PS:
165 pm_mode = "dynamic";
166 break;
167 }
168 seq_printf(seq, "Preamble: %s\n",
169 cw1200_debug_preamble[priv->association_mode.preamble]);
170 seq_printf(seq, "AMPDU spcn: %d\n",
171 priv->association_mode.mpdu_start_spacing);
172 seq_printf(seq, "Basic rate: 0x%.8X\n",
173 le32_to_cpu(priv->association_mode.basic_rate_set));
174 seq_printf(seq, "Bss lost: %d beacons\n",
175 priv->bss_params.beacon_lost_count);
176 seq_printf(seq, "AID: %d\n",
177 priv->bss_params.aid);
178 seq_printf(seq, "Rates: 0x%.8X\n",
179 priv->bss_params.operational_rate_set);
180 seq_printf(seq, "Powersave: %s\n", pm_mode);
181 }
182 seq_printf(seq, "HT: %s\n",
183 cw1200_is_ht(&priv->ht_info) ? "on" : "off");
184 if (cw1200_is_ht(&priv->ht_info)) {
185 seq_printf(seq, "Greenfield: %s\n",
186 cw1200_ht_greenfield(&priv->ht_info) ? "yes" : "no");
187 seq_printf(seq, "AMPDU dens: %d\n",
188 cw1200_ht_ampdu_density(&priv->ht_info));
189 }
190 seq_printf(seq, "RSSI thold: %d\n",
191 priv->cqm_rssi_thold);
192 seq_printf(seq, "RSSI hyst: %d\n",
193 priv->cqm_rssi_hyst);
194 seq_printf(seq, "Long retr: %d\n",
195 priv->long_frame_max_tx_count);
196 seq_printf(seq, "Short retr: %d\n",
197 priv->short_frame_max_tx_count);
198 spin_lock_bh(&priv->tx_policy_cache.lock);
199 i = 0;
200 list_for_each(item, &priv->tx_policy_cache.used)
201 ++i;
202 spin_unlock_bh(&priv->tx_policy_cache.lock);
203 seq_printf(seq, "RC in use: %d\n", i);
204
205 seq_puts(seq, "\n");
206 for (i = 0; i < 4; ++i) {
207 cw1200_queue_status_show(seq, &priv->tx_queue[i]);
208 seq_puts(seq, "\n");
209 }
210
211 cw1200_debug_print_map(seq, priv, "Link map: ",
212 priv->link_id_map);
213 cw1200_debug_print_map(seq, priv, "Asleep map: ",
214 priv->sta_asleep_mask);
215 cw1200_debug_print_map(seq, priv, "PSPOLL map: ",
216 priv->pspoll_mask);
217
218 seq_puts(seq, "\n");
219
220 for (i = 0; i < CW1200_MAX_STA_IN_AP_MODE; ++i) {
221 if (priv->link_id_db[i].status) {
222 seq_printf(seq, "Link %d: %s, %pM\n",
223 i + 1,
224 cw1200_debug_link_id[priv->link_id_db[i].status],
225 priv->link_id_db[i].mac);
226 }
227 }
228
229 seq_puts(seq, "\n");
230
231 seq_printf(seq, "BH status: %s\n",
232 atomic_read(&priv->bh_term) ? "terminated" : "alive");
233 seq_printf(seq, "Pending RX: %d\n",
234 atomic_read(&priv->bh_rx));
235 seq_printf(seq, "Pending TX: %d\n",
236 atomic_read(&priv->bh_tx));
237 if (priv->bh_error)
238 seq_printf(seq, "BH errcode: %d\n",
239 priv->bh_error);
240 seq_printf(seq, "TX bufs: %d x %d bytes\n",
241 priv->wsm_caps.input_buffers,
242 priv->wsm_caps.input_buffer_size);
243 seq_printf(seq, "Used bufs: %d\n",
244 priv->hw_bufs_used);
245 seq_printf(seq, "Powermgmt: %s\n",
246 priv->powersave_enabled ? "on" : "off");
247 seq_printf(seq, "Device: %s\n",
248 priv->device_can_sleep ? "asleep" : "awake");
249
250 spin_lock(&priv->wsm_cmd.lock);
251 seq_printf(seq, "WSM status: %s\n",
252 priv->wsm_cmd.done ? "idle" : "active");
253 seq_printf(seq, "WSM cmd: 0x%.4X (%td bytes)\n",
254 priv->wsm_cmd.cmd, priv->wsm_cmd.len);
255 seq_printf(seq, "WSM retval: %d\n",
256 priv->wsm_cmd.ret);
257 spin_unlock(&priv->wsm_cmd.lock);
258
259 seq_printf(seq, "Datapath: %s\n",
260 atomic_read(&priv->tx_lock) ? "locked" : "unlocked");
261 if (atomic_read(&priv->tx_lock))
262 seq_printf(seq, "TXlock cnt: %d\n",
263 atomic_read(&priv->tx_lock));
264
265 seq_printf(seq, "TXed: %d\n",
266 d->tx);
267 seq_printf(seq, "AGG TXed: %d\n",
268 d->tx_agg);
269 seq_printf(seq, "MULTI TXed: %d (%d)\n",
270 d->tx_multi, d->tx_multi_frames);
271 seq_printf(seq, "RXed: %d\n",
272 d->rx);
273 seq_printf(seq, "AGG RXed: %d\n",
274 d->rx_agg);
275 seq_printf(seq, "TX miss: %d\n",
276 d->tx_cache_miss);
277 seq_printf(seq, "TX align: %d\n",
278 d->tx_align);
279 seq_printf(seq, "TX burst: %d\n",
280 d->tx_burst);
281 seq_printf(seq, "TX TTL: %d\n",
282 d->tx_ttl);
283 seq_printf(seq, "Scan: %s\n",
284 atomic_read(&priv->scan.in_progress) ? "active" : "idle");
285
286 return 0;
287}
288
289DEFINE_SHOW_ATTRIBUTE(cw1200_status);
290
291static int cw1200_counters_show(struct seq_file *seq, void *v)
292{
293 int ret;
294 struct cw1200_common *priv = seq->private;
295 struct wsm_mib_counters_table counters;
296
297 ret = wsm_get_counters_table(priv, &counters);
298 if (ret)
299 return ret;
300
301#define PUT_COUNTER(tab, name) \
302 seq_printf(seq, "%s:" tab "%d\n", #name, \
303 __le32_to_cpu(counters.name))
304
305 PUT_COUNTER("\t\t", plcp_errors);
306 PUT_COUNTER("\t\t", fcs_errors);
307 PUT_COUNTER("\t\t", tx_packets);
308 PUT_COUNTER("\t\t", rx_packets);
309 PUT_COUNTER("\t\t", rx_packet_errors);
310 PUT_COUNTER("\t", rx_decryption_failures);
311 PUT_COUNTER("\t\t", rx_mic_failures);
312 PUT_COUNTER("\t", rx_no_key_failures);
313 PUT_COUNTER("\t", tx_multicast_frames);
314 PUT_COUNTER("\t", tx_frames_success);
315 PUT_COUNTER("\t", tx_frame_failures);
316 PUT_COUNTER("\t", tx_frames_retried);
317 PUT_COUNTER("\t", tx_frames_multi_retried);
318 PUT_COUNTER("\t", rx_frame_duplicates);
319 PUT_COUNTER("\t\t", rts_success);
320 PUT_COUNTER("\t\t", rts_failures);
321 PUT_COUNTER("\t\t", ack_failures);
322 PUT_COUNTER("\t", rx_multicast_frames);
323 PUT_COUNTER("\t", rx_frames_success);
324 PUT_COUNTER("\t", rx_cmac_icv_errors);
325 PUT_COUNTER("\t\t", rx_cmac_replays);
326 PUT_COUNTER("\t", rx_mgmt_ccmp_replays);
327
328#undef PUT_COUNTER
329
330 return 0;
331}
332
333DEFINE_SHOW_ATTRIBUTE(cw1200_counters);
334
335static ssize_t cw1200_wsm_dumps(struct file *file,
336 const char __user *user_buf, size_t count, loff_t *ppos)
337{
338 struct cw1200_common *priv = file->private_data;
339 char buf[1];
340
341 if (!count)
342 return -EINVAL;
343 if (copy_from_user(buf, user_buf, 1))
344 return -EFAULT;
345
346 if (buf[0] == '1')
347 priv->wsm_enable_wsm_dumps = 1;
348 else
349 priv->wsm_enable_wsm_dumps = 0;
350
351 return count;
352}
353
354static const struct file_operations fops_wsm_dumps = {
355 .open = simple_open,
356 .write = cw1200_wsm_dumps,
357 .llseek = default_llseek,
358};
359
360int cw1200_debug_init(struct cw1200_common *priv)
361{
362 int ret = -ENOMEM;
363 struct cw1200_debug_priv *d = kzalloc(sizeof(struct cw1200_debug_priv),
364 GFP_KERNEL);
365 priv->debug = d;
366 if (!d)
367 return ret;
368
369 d->debugfs_phy = debugfs_create_dir("cw1200",
370 priv->hw->wiphy->debugfsdir);
371 debugfs_create_file("status", 0400, d->debugfs_phy, priv,
372 &cw1200_status_fops);
373 debugfs_create_file("counters", 0400, d->debugfs_phy, priv,
374 &cw1200_counters_fops);
375 debugfs_create_file("wsm_dumps", 0200, d->debugfs_phy, priv,
376 &fops_wsm_dumps);
377
378 return 0;
379}
380
381void cw1200_debug_release(struct cw1200_common *priv)
382{
383 struct cw1200_debug_priv *d = priv->debug;
384 if (d) {
385 debugfs_remove_recursive(d->debugfs_phy);
386 priv->debug = NULL;
387 kfree(d);
388 }
389}
1/*
2 * mac80211 glue code for mac80211 ST-Ericsson CW1200 drivers
3 * DebugFS code
4 *
5 * Copyright (c) 2010, ST-Ericsson
6 * Author: Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/module.h>
14#include <linux/debugfs.h>
15#include <linux/seq_file.h>
16#include "cw1200.h"
17#include "debug.h"
18#include "fwio.h"
19
20/* join_status */
21static const char * const cw1200_debug_join_status[] = {
22 "passive",
23 "monitor",
24 "station (joining)",
25 "station (not authenticated yet)",
26 "station",
27 "adhoc",
28 "access point",
29};
30
31/* WSM_JOIN_PREAMBLE_... */
32static const char * const cw1200_debug_preamble[] = {
33 "long",
34 "short",
35 "long on 1 and 2 Mbps",
36};
37
38
39static const char * const cw1200_debug_link_id[] = {
40 "OFF",
41 "REQ",
42 "SOFT",
43 "HARD",
44 "RESET",
45 "RESET_REMAP",
46};
47
48static const char *cw1200_debug_mode(int mode)
49{
50 switch (mode) {
51 case NL80211_IFTYPE_UNSPECIFIED:
52 return "unspecified";
53 case NL80211_IFTYPE_MONITOR:
54 return "monitor";
55 case NL80211_IFTYPE_STATION:
56 return "station";
57 case NL80211_IFTYPE_ADHOC:
58 return "adhoc";
59 case NL80211_IFTYPE_MESH_POINT:
60 return "mesh point";
61 case NL80211_IFTYPE_AP:
62 return "access point";
63 case NL80211_IFTYPE_P2P_CLIENT:
64 return "p2p client";
65 case NL80211_IFTYPE_P2P_GO:
66 return "p2p go";
67 default:
68 return "unsupported";
69 }
70}
71
72static void cw1200_queue_status_show(struct seq_file *seq,
73 struct cw1200_queue *q)
74{
75 int i;
76 seq_printf(seq, "Queue %d:\n", q->queue_id);
77 seq_printf(seq, " capacity: %zu\n", q->capacity);
78 seq_printf(seq, " queued: %zu\n", q->num_queued);
79 seq_printf(seq, " pending: %zu\n", q->num_pending);
80 seq_printf(seq, " sent: %zu\n", q->num_sent);
81 seq_printf(seq, " locked: %s\n", q->tx_locked_cnt ? "yes" : "no");
82 seq_printf(seq, " overfull: %s\n", q->overfull ? "yes" : "no");
83 seq_puts(seq, " link map: 0-> ");
84 for (i = 0; i < q->stats->map_capacity; ++i)
85 seq_printf(seq, "%.2d ", q->link_map_cache[i]);
86 seq_printf(seq, "<-%zu\n", q->stats->map_capacity);
87}
88
89static void cw1200_debug_print_map(struct seq_file *seq,
90 struct cw1200_common *priv,
91 const char *label,
92 u32 map)
93{
94 int i;
95 seq_printf(seq, "%s0-> ", label);
96 for (i = 0; i < priv->tx_queue_stats.map_capacity; ++i)
97 seq_printf(seq, "%s ", (map & BIT(i)) ? "**" : "..");
98 seq_printf(seq, "<-%zu\n", priv->tx_queue_stats.map_capacity - 1);
99}
100
101static int cw1200_status_show(struct seq_file *seq, void *v)
102{
103 int i;
104 struct list_head *item;
105 struct cw1200_common *priv = seq->private;
106 struct cw1200_debug_priv *d = priv->debug;
107
108 seq_puts(seq, "CW1200 Wireless LAN driver status\n");
109 seq_printf(seq, "Hardware: %d.%d\n",
110 priv->wsm_caps.hw_id,
111 priv->wsm_caps.hw_subid);
112 seq_printf(seq, "Firmware: %s %d.%d\n",
113 cw1200_fw_types[priv->wsm_caps.fw_type],
114 priv->wsm_caps.fw_ver,
115 priv->wsm_caps.fw_build);
116 seq_printf(seq, "FW API: %d\n",
117 priv->wsm_caps.fw_api);
118 seq_printf(seq, "FW caps: 0x%.4X\n",
119 priv->wsm_caps.fw_cap);
120 seq_printf(seq, "FW label: '%s'\n",
121 priv->wsm_caps.fw_label);
122 seq_printf(seq, "Mode: %s%s\n",
123 cw1200_debug_mode(priv->mode),
124 priv->listening ? " (listening)" : "");
125 seq_printf(seq, "Join state: %s\n",
126 cw1200_debug_join_status[priv->join_status]);
127 if (priv->channel)
128 seq_printf(seq, "Channel: %d%s\n",
129 priv->channel->hw_value,
130 priv->channel_switch_in_progress ?
131 " (switching)" : "");
132 if (priv->rx_filter.promiscuous)
133 seq_puts(seq, "Filter: promisc\n");
134 else if (priv->rx_filter.fcs)
135 seq_puts(seq, "Filter: fcs\n");
136 if (priv->rx_filter.bssid)
137 seq_puts(seq, "Filter: bssid\n");
138 if (!priv->disable_beacon_filter)
139 seq_puts(seq, "Filter: beacons\n");
140
141 if (priv->enable_beacon ||
142 priv->mode == NL80211_IFTYPE_AP ||
143 priv->mode == NL80211_IFTYPE_ADHOC ||
144 priv->mode == NL80211_IFTYPE_MESH_POINT ||
145 priv->mode == NL80211_IFTYPE_P2P_GO)
146 seq_printf(seq, "Beaconing: %s\n",
147 priv->enable_beacon ?
148 "enabled" : "disabled");
149
150 for (i = 0; i < 4; ++i)
151 seq_printf(seq, "EDCA(%d): %d, %d, %d, %d, %d\n", i,
152 priv->edca.params[i].cwmin,
153 priv->edca.params[i].cwmax,
154 priv->edca.params[i].aifns,
155 priv->edca.params[i].txop_limit,
156 priv->edca.params[i].max_rx_lifetime);
157
158 if (priv->join_status == CW1200_JOIN_STATUS_STA) {
159 static const char *pm_mode = "unknown";
160 switch (priv->powersave_mode.mode) {
161 case WSM_PSM_ACTIVE:
162 pm_mode = "off";
163 break;
164 case WSM_PSM_PS:
165 pm_mode = "on";
166 break;
167 case WSM_PSM_FAST_PS:
168 pm_mode = "dynamic";
169 break;
170 }
171 seq_printf(seq, "Preamble: %s\n",
172 cw1200_debug_preamble[priv->association_mode.preamble]);
173 seq_printf(seq, "AMPDU spcn: %d\n",
174 priv->association_mode.mpdu_start_spacing);
175 seq_printf(seq, "Basic rate: 0x%.8X\n",
176 le32_to_cpu(priv->association_mode.basic_rate_set));
177 seq_printf(seq, "Bss lost: %d beacons\n",
178 priv->bss_params.beacon_lost_count);
179 seq_printf(seq, "AID: %d\n",
180 priv->bss_params.aid);
181 seq_printf(seq, "Rates: 0x%.8X\n",
182 priv->bss_params.operational_rate_set);
183 seq_printf(seq, "Powersave: %s\n", pm_mode);
184 }
185 seq_printf(seq, "HT: %s\n",
186 cw1200_is_ht(&priv->ht_info) ? "on" : "off");
187 if (cw1200_is_ht(&priv->ht_info)) {
188 seq_printf(seq, "Greenfield: %s\n",
189 cw1200_ht_greenfield(&priv->ht_info) ? "yes" : "no");
190 seq_printf(seq, "AMPDU dens: %d\n",
191 cw1200_ht_ampdu_density(&priv->ht_info));
192 }
193 seq_printf(seq, "RSSI thold: %d\n",
194 priv->cqm_rssi_thold);
195 seq_printf(seq, "RSSI hyst: %d\n",
196 priv->cqm_rssi_hyst);
197 seq_printf(seq, "Long retr: %d\n",
198 priv->long_frame_max_tx_count);
199 seq_printf(seq, "Short retr: %d\n",
200 priv->short_frame_max_tx_count);
201 spin_lock_bh(&priv->tx_policy_cache.lock);
202 i = 0;
203 list_for_each(item, &priv->tx_policy_cache.used)
204 ++i;
205 spin_unlock_bh(&priv->tx_policy_cache.lock);
206 seq_printf(seq, "RC in use: %d\n", i);
207
208 seq_puts(seq, "\n");
209 for (i = 0; i < 4; ++i) {
210 cw1200_queue_status_show(seq, &priv->tx_queue[i]);
211 seq_puts(seq, "\n");
212 }
213
214 cw1200_debug_print_map(seq, priv, "Link map: ",
215 priv->link_id_map);
216 cw1200_debug_print_map(seq, priv, "Asleep map: ",
217 priv->sta_asleep_mask);
218 cw1200_debug_print_map(seq, priv, "PSPOLL map: ",
219 priv->pspoll_mask);
220
221 seq_puts(seq, "\n");
222
223 for (i = 0; i < CW1200_MAX_STA_IN_AP_MODE; ++i) {
224 if (priv->link_id_db[i].status) {
225 seq_printf(seq, "Link %d: %s, %pM\n",
226 i + 1,
227 cw1200_debug_link_id[priv->link_id_db[i].status],
228 priv->link_id_db[i].mac);
229 }
230 }
231
232 seq_puts(seq, "\n");
233
234 seq_printf(seq, "BH status: %s\n",
235 atomic_read(&priv->bh_term) ? "terminated" : "alive");
236 seq_printf(seq, "Pending RX: %d\n",
237 atomic_read(&priv->bh_rx));
238 seq_printf(seq, "Pending TX: %d\n",
239 atomic_read(&priv->bh_tx));
240 if (priv->bh_error)
241 seq_printf(seq, "BH errcode: %d\n",
242 priv->bh_error);
243 seq_printf(seq, "TX bufs: %d x %d bytes\n",
244 priv->wsm_caps.input_buffers,
245 priv->wsm_caps.input_buffer_size);
246 seq_printf(seq, "Used bufs: %d\n",
247 priv->hw_bufs_used);
248 seq_printf(seq, "Powermgmt: %s\n",
249 priv->powersave_enabled ? "on" : "off");
250 seq_printf(seq, "Device: %s\n",
251 priv->device_can_sleep ? "asleep" : "awake");
252
253 spin_lock(&priv->wsm_cmd.lock);
254 seq_printf(seq, "WSM status: %s\n",
255 priv->wsm_cmd.done ? "idle" : "active");
256 seq_printf(seq, "WSM cmd: 0x%.4X (%td bytes)\n",
257 priv->wsm_cmd.cmd, priv->wsm_cmd.len);
258 seq_printf(seq, "WSM retval: %d\n",
259 priv->wsm_cmd.ret);
260 spin_unlock(&priv->wsm_cmd.lock);
261
262 seq_printf(seq, "Datapath: %s\n",
263 atomic_read(&priv->tx_lock) ? "locked" : "unlocked");
264 if (atomic_read(&priv->tx_lock))
265 seq_printf(seq, "TXlock cnt: %d\n",
266 atomic_read(&priv->tx_lock));
267
268 seq_printf(seq, "TXed: %d\n",
269 d->tx);
270 seq_printf(seq, "AGG TXed: %d\n",
271 d->tx_agg);
272 seq_printf(seq, "MULTI TXed: %d (%d)\n",
273 d->tx_multi, d->tx_multi_frames);
274 seq_printf(seq, "RXed: %d\n",
275 d->rx);
276 seq_printf(seq, "AGG RXed: %d\n",
277 d->rx_agg);
278 seq_printf(seq, "TX miss: %d\n",
279 d->tx_cache_miss);
280 seq_printf(seq, "TX align: %d\n",
281 d->tx_align);
282 seq_printf(seq, "TX burst: %d\n",
283 d->tx_burst);
284 seq_printf(seq, "TX TTL: %d\n",
285 d->tx_ttl);
286 seq_printf(seq, "Scan: %s\n",
287 atomic_read(&priv->scan.in_progress) ? "active" : "idle");
288
289 return 0;
290}
291
292static int cw1200_status_open(struct inode *inode, struct file *file)
293{
294 return single_open(file, &cw1200_status_show,
295 inode->i_private);
296}
297
298static const struct file_operations fops_status = {
299 .open = cw1200_status_open,
300 .read = seq_read,
301 .llseek = seq_lseek,
302 .release = single_release,
303 .owner = THIS_MODULE,
304};
305
306static int cw1200_counters_show(struct seq_file *seq, void *v)
307{
308 int ret;
309 struct cw1200_common *priv = seq->private;
310 struct wsm_mib_counters_table counters;
311
312 ret = wsm_get_counters_table(priv, &counters);
313 if (ret)
314 return ret;
315
316#define PUT_COUNTER(tab, name) \
317 seq_printf(seq, "%s:" tab "%d\n", #name, \
318 __le32_to_cpu(counters.name))
319
320 PUT_COUNTER("\t\t", plcp_errors);
321 PUT_COUNTER("\t\t", fcs_errors);
322 PUT_COUNTER("\t\t", tx_packets);
323 PUT_COUNTER("\t\t", rx_packets);
324 PUT_COUNTER("\t\t", rx_packet_errors);
325 PUT_COUNTER("\t", rx_decryption_failures);
326 PUT_COUNTER("\t\t", rx_mic_failures);
327 PUT_COUNTER("\t", rx_no_key_failures);
328 PUT_COUNTER("\t", tx_multicast_frames);
329 PUT_COUNTER("\t", tx_frames_success);
330 PUT_COUNTER("\t", tx_frame_failures);
331 PUT_COUNTER("\t", tx_frames_retried);
332 PUT_COUNTER("\t", tx_frames_multi_retried);
333 PUT_COUNTER("\t", rx_frame_duplicates);
334 PUT_COUNTER("\t\t", rts_success);
335 PUT_COUNTER("\t\t", rts_failures);
336 PUT_COUNTER("\t\t", ack_failures);
337 PUT_COUNTER("\t", rx_multicast_frames);
338 PUT_COUNTER("\t", rx_frames_success);
339 PUT_COUNTER("\t", rx_cmac_icv_errors);
340 PUT_COUNTER("\t\t", rx_cmac_replays);
341 PUT_COUNTER("\t", rx_mgmt_ccmp_replays);
342
343#undef PUT_COUNTER
344
345 return 0;
346}
347
348static int cw1200_counters_open(struct inode *inode, struct file *file)
349{
350 return single_open(file, &cw1200_counters_show,
351 inode->i_private);
352}
353
354static const struct file_operations fops_counters = {
355 .open = cw1200_counters_open,
356 .read = seq_read,
357 .llseek = seq_lseek,
358 .release = single_release,
359 .owner = THIS_MODULE,
360};
361
362static ssize_t cw1200_wsm_dumps(struct file *file,
363 const char __user *user_buf, size_t count, loff_t *ppos)
364{
365 struct cw1200_common *priv = file->private_data;
366 char buf[1];
367
368 if (!count)
369 return -EINVAL;
370 if (copy_from_user(buf, user_buf, 1))
371 return -EFAULT;
372
373 if (buf[0] == '1')
374 priv->wsm_enable_wsm_dumps = 1;
375 else
376 priv->wsm_enable_wsm_dumps = 0;
377
378 return count;
379}
380
381static const struct file_operations fops_wsm_dumps = {
382 .open = simple_open,
383 .write = cw1200_wsm_dumps,
384 .llseek = default_llseek,
385};
386
387int cw1200_debug_init(struct cw1200_common *priv)
388{
389 int ret = -ENOMEM;
390 struct cw1200_debug_priv *d = kzalloc(sizeof(struct cw1200_debug_priv),
391 GFP_KERNEL);
392 priv->debug = d;
393 if (!d)
394 return ret;
395
396 d->debugfs_phy = debugfs_create_dir("cw1200",
397 priv->hw->wiphy->debugfsdir);
398 if (!d->debugfs_phy)
399 goto err;
400
401 if (!debugfs_create_file("status", S_IRUSR, d->debugfs_phy,
402 priv, &fops_status))
403 goto err;
404
405 if (!debugfs_create_file("counters", S_IRUSR, d->debugfs_phy,
406 priv, &fops_counters))
407 goto err;
408
409 if (!debugfs_create_file("wsm_dumps", S_IWUSR, d->debugfs_phy,
410 priv, &fops_wsm_dumps))
411 goto err;
412
413 return 0;
414
415err:
416 priv->debug = NULL;
417 debugfs_remove_recursive(d->debugfs_phy);
418 kfree(d);
419 return ret;
420}
421
422void cw1200_debug_release(struct cw1200_common *priv)
423{
424 struct cw1200_debug_priv *d = priv->debug;
425 if (d) {
426 debugfs_remove_recursive(d->debugfs_phy);
427 priv->debug = NULL;
428 kfree(d);
429 }
430}