1 // SPDX-License-Identifier: GPL-2.0-only
3 * mac80211 glue code for mac80211 ST-Ericsson CW1200 drivers
6 * Copyright (c) 2010, ST-Ericsson
7 * Author: Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no>
10 #include <linux/module.h>
11 #include <linux/debugfs.h>
12 #include <linux/seq_file.h>
18 static const char * const cw1200_debug_join_status[] = {
22 "station (not authenticated yet)",
28 /* WSM_JOIN_PREAMBLE_... */
29 static const char * const cw1200_debug_preamble[] = {
32 "long on 1 and 2 Mbps",
36 static const char * const cw1200_debug_link_id[] = {
45 static const char *cw1200_debug_mode(int mode)
48 case NL80211_IFTYPE_UNSPECIFIED:
50 case NL80211_IFTYPE_MONITOR:
52 case NL80211_IFTYPE_STATION:
54 case NL80211_IFTYPE_ADHOC:
56 case NL80211_IFTYPE_MESH_POINT:
58 case NL80211_IFTYPE_AP:
59 return "access point";
60 case NL80211_IFTYPE_P2P_CLIENT:
62 case NL80211_IFTYPE_P2P_GO:
69 static void cw1200_queue_status_show(struct seq_file *seq,
70 struct cw1200_queue *q)
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);
86 static void cw1200_debug_print_map(struct seq_file *seq,
87 struct cw1200_common *priv,
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);
98 static int cw1200_status_show(struct seq_file *seq, void *v)
101 struct list_head *item;
102 struct cw1200_common *priv = seq->private;
103 struct cw1200_debug_priv *d = priv->debug;
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]);
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");
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");
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);
155 if (priv->join_status == CW1200_JOIN_STATUS_STA) {
156 static const char *pm_mode = "unknown";
157 switch (priv->powersave_mode.mode) {
164 case WSM_PSM_FAST_PS:
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);
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));
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);
200 list_for_each(item, &priv->tx_policy_cache.used)
202 spin_unlock_bh(&priv->tx_policy_cache.lock);
203 seq_printf(seq, "RC in use: %d\n", i);
206 for (i = 0; i < 4; ++i) {
207 cw1200_queue_status_show(seq, &priv->tx_queue[i]);
211 cw1200_debug_print_map(seq, priv, "Link map: ",
213 cw1200_debug_print_map(seq, priv, "Asleep map: ",
214 priv->sta_asleep_mask);
215 cw1200_debug_print_map(seq, priv, "PSPOLL map: ",
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",
224 cw1200_debug_link_id[priv->link_id_db[i].status],
225 priv->link_id_db[i].mac);
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));
238 seq_printf(seq, "BH errcode: %d\n",
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",
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");
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",
257 spin_unlock(&priv->wsm_cmd.lock);
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));
265 seq_printf(seq, "TXed: %d\n",
267 seq_printf(seq, "AGG TXed: %d\n",
269 seq_printf(seq, "MULTI TXed: %d (%d)\n",
270 d->tx_multi, d->tx_multi_frames);
271 seq_printf(seq, "RXed: %d\n",
273 seq_printf(seq, "AGG RXed: %d\n",
275 seq_printf(seq, "TX miss: %d\n",
277 seq_printf(seq, "TX align: %d\n",
279 seq_printf(seq, "TX burst: %d\n",
281 seq_printf(seq, "TX TTL: %d\n",
283 seq_printf(seq, "Scan: %s\n",
284 atomic_read(&priv->scan.in_progress) ? "active" : "idle");
289 DEFINE_SHOW_ATTRIBUTE(cw1200_status);
291 static int cw1200_counters_show(struct seq_file *seq, void *v)
294 struct cw1200_common *priv = seq->private;
295 struct wsm_mib_counters_table counters;
297 ret = wsm_get_counters_table(priv, &counters);
301 #define PUT_COUNTER(tab, name) \
302 seq_printf(seq, "%s:" tab "%d\n", #name, \
303 __le32_to_cpu(counters.name))
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);
333 DEFINE_SHOW_ATTRIBUTE(cw1200_counters);
335 static ssize_t cw1200_wsm_dumps(struct file *file,
336 const char __user *user_buf, size_t count, loff_t *ppos)
338 struct cw1200_common *priv = file->private_data;
343 if (copy_from_user(buf, user_buf, 1))
347 priv->wsm_enable_wsm_dumps = 1;
349 priv->wsm_enable_wsm_dumps = 0;
354 static const struct file_operations fops_wsm_dumps = {
356 .write = cw1200_wsm_dumps,
357 .llseek = default_llseek,
360 int cw1200_debug_init(struct cw1200_common *priv)
363 struct cw1200_debug_priv *d = kzalloc(sizeof(struct cw1200_debug_priv),
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,
381 void cw1200_debug_release(struct cw1200_common *priv)
383 struct cw1200_debug_priv *d = priv->debug;
385 debugfs_remove_recursive(d->debugfs_phy);