xref: /linux/drivers/net/wireless/st/cw1200/debug.c (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1*d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2560424e9SKalle Valo /*
3560424e9SKalle Valo  * mac80211 glue code for mac80211 ST-Ericsson CW1200 drivers
4560424e9SKalle Valo  * DebugFS code
5560424e9SKalle Valo  *
6560424e9SKalle Valo  * Copyright (c) 2010, ST-Ericsson
7560424e9SKalle Valo  * Author: Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no>
8560424e9SKalle Valo  */
9560424e9SKalle Valo 
10560424e9SKalle Valo #include <linux/module.h>
11560424e9SKalle Valo #include <linux/debugfs.h>
12560424e9SKalle Valo #include <linux/seq_file.h>
13560424e9SKalle Valo #include "cw1200.h"
14560424e9SKalle Valo #include "debug.h"
15560424e9SKalle Valo #include "fwio.h"
16560424e9SKalle Valo 
17560424e9SKalle Valo /* join_status */
18560424e9SKalle Valo static const char * const cw1200_debug_join_status[] = {
19560424e9SKalle Valo 	"passive",
20560424e9SKalle Valo 	"monitor",
21560424e9SKalle Valo 	"station (joining)",
22560424e9SKalle Valo 	"station (not authenticated yet)",
23560424e9SKalle Valo 	"station",
24560424e9SKalle Valo 	"adhoc",
25560424e9SKalle Valo 	"access point",
26560424e9SKalle Valo };
27560424e9SKalle Valo 
28560424e9SKalle Valo /* WSM_JOIN_PREAMBLE_... */
29560424e9SKalle Valo static const char * const cw1200_debug_preamble[] = {
30560424e9SKalle Valo 	"long",
31560424e9SKalle Valo 	"short",
32560424e9SKalle Valo 	"long on 1 and 2 Mbps",
33560424e9SKalle Valo };
34560424e9SKalle Valo 
35560424e9SKalle Valo 
36560424e9SKalle Valo static const char * const cw1200_debug_link_id[] = {
37560424e9SKalle Valo 	"OFF",
38560424e9SKalle Valo 	"REQ",
39560424e9SKalle Valo 	"SOFT",
40560424e9SKalle Valo 	"HARD",
41560424e9SKalle Valo 	"RESET",
42560424e9SKalle Valo 	"RESET_REMAP",
43560424e9SKalle Valo };
44560424e9SKalle Valo 
cw1200_debug_mode(int mode)45560424e9SKalle Valo static const char *cw1200_debug_mode(int mode)
46560424e9SKalle Valo {
47560424e9SKalle Valo 	switch (mode) {
48560424e9SKalle Valo 	case NL80211_IFTYPE_UNSPECIFIED:
49560424e9SKalle Valo 		return "unspecified";
50560424e9SKalle Valo 	case NL80211_IFTYPE_MONITOR:
51560424e9SKalle Valo 		return "monitor";
52560424e9SKalle Valo 	case NL80211_IFTYPE_STATION:
53560424e9SKalle Valo 		return "station";
54560424e9SKalle Valo 	case NL80211_IFTYPE_ADHOC:
55560424e9SKalle Valo 		return "adhoc";
56560424e9SKalle Valo 	case NL80211_IFTYPE_MESH_POINT:
57560424e9SKalle Valo 		return "mesh point";
58560424e9SKalle Valo 	case NL80211_IFTYPE_AP:
59560424e9SKalle Valo 		return "access point";
60560424e9SKalle Valo 	case NL80211_IFTYPE_P2P_CLIENT:
61560424e9SKalle Valo 		return "p2p client";
62560424e9SKalle Valo 	case NL80211_IFTYPE_P2P_GO:
63560424e9SKalle Valo 		return "p2p go";
64560424e9SKalle Valo 	default:
65560424e9SKalle Valo 		return "unsupported";
66560424e9SKalle Valo 	}
67560424e9SKalle Valo }
68560424e9SKalle Valo 
cw1200_queue_status_show(struct seq_file * seq,struct cw1200_queue * q)69560424e9SKalle Valo static void cw1200_queue_status_show(struct seq_file *seq,
70560424e9SKalle Valo 				     struct cw1200_queue *q)
71560424e9SKalle Valo {
72560424e9SKalle Valo 	int i;
73560424e9SKalle Valo 	seq_printf(seq, "Queue       %d:\n", q->queue_id);
74560424e9SKalle Valo 	seq_printf(seq, "  capacity: %zu\n", q->capacity);
75560424e9SKalle Valo 	seq_printf(seq, "  queued:   %zu\n", q->num_queued);
76560424e9SKalle Valo 	seq_printf(seq, "  pending:  %zu\n", q->num_pending);
77560424e9SKalle Valo 	seq_printf(seq, "  sent:     %zu\n", q->num_sent);
78560424e9SKalle Valo 	seq_printf(seq, "  locked:   %s\n", q->tx_locked_cnt ? "yes" : "no");
79560424e9SKalle Valo 	seq_printf(seq, "  overfull: %s\n", q->overfull ? "yes" : "no");
80560424e9SKalle Valo 	seq_puts(seq,   "  link map: 0-> ");
81560424e9SKalle Valo 	for (i = 0; i < q->stats->map_capacity; ++i)
82560424e9SKalle Valo 		seq_printf(seq, "%.2d ", q->link_map_cache[i]);
83560424e9SKalle Valo 	seq_printf(seq, "<-%zu\n", q->stats->map_capacity);
84560424e9SKalle Valo }
85560424e9SKalle Valo 
cw1200_debug_print_map(struct seq_file * seq,struct cw1200_common * priv,const char * label,u32 map)86560424e9SKalle Valo static void cw1200_debug_print_map(struct seq_file *seq,
87560424e9SKalle Valo 				   struct cw1200_common *priv,
88560424e9SKalle Valo 				   const char *label,
89560424e9SKalle Valo 				   u32 map)
90560424e9SKalle Valo {
91560424e9SKalle Valo 	int i;
92560424e9SKalle Valo 	seq_printf(seq, "%s0-> ", label);
93560424e9SKalle Valo 	for (i = 0; i < priv->tx_queue_stats.map_capacity; ++i)
94560424e9SKalle Valo 		seq_printf(seq, "%s ", (map & BIT(i)) ? "**" : "..");
95560424e9SKalle Valo 	seq_printf(seq, "<-%zu\n", priv->tx_queue_stats.map_capacity - 1);
96560424e9SKalle Valo }
97560424e9SKalle Valo 
cw1200_status_show(struct seq_file * seq,void * v)98560424e9SKalle Valo static int cw1200_status_show(struct seq_file *seq, void *v)
99560424e9SKalle Valo {
100560424e9SKalle Valo 	int i;
101560424e9SKalle Valo 	struct list_head *item;
102560424e9SKalle Valo 	struct cw1200_common *priv = seq->private;
103560424e9SKalle Valo 	struct cw1200_debug_priv *d = priv->debug;
104560424e9SKalle Valo 
105560424e9SKalle Valo 	seq_puts(seq,   "CW1200 Wireless LAN driver status\n");
106560424e9SKalle Valo 	seq_printf(seq, "Hardware:   %d.%d\n",
107560424e9SKalle Valo 		   priv->wsm_caps.hw_id,
108560424e9SKalle Valo 		   priv->wsm_caps.hw_subid);
109560424e9SKalle Valo 	seq_printf(seq, "Firmware:   %s %d.%d\n",
110560424e9SKalle Valo 		   cw1200_fw_types[priv->wsm_caps.fw_type],
111560424e9SKalle Valo 		   priv->wsm_caps.fw_ver,
112560424e9SKalle Valo 		   priv->wsm_caps.fw_build);
113560424e9SKalle Valo 	seq_printf(seq, "FW API:     %d\n",
114560424e9SKalle Valo 		   priv->wsm_caps.fw_api);
115560424e9SKalle Valo 	seq_printf(seq, "FW caps:    0x%.4X\n",
116560424e9SKalle Valo 		   priv->wsm_caps.fw_cap);
117560424e9SKalle Valo 	seq_printf(seq, "FW label:  '%s'\n",
118560424e9SKalle Valo 		   priv->wsm_caps.fw_label);
119560424e9SKalle Valo 	seq_printf(seq, "Mode:       %s%s\n",
120560424e9SKalle Valo 		   cw1200_debug_mode(priv->mode),
121560424e9SKalle Valo 		   priv->listening ? " (listening)" : "");
122560424e9SKalle Valo 	seq_printf(seq, "Join state: %s\n",
123560424e9SKalle Valo 		   cw1200_debug_join_status[priv->join_status]);
124560424e9SKalle Valo 	if (priv->channel)
125560424e9SKalle Valo 		seq_printf(seq, "Channel:    %d%s\n",
126560424e9SKalle Valo 			   priv->channel->hw_value,
127560424e9SKalle Valo 			   priv->channel_switch_in_progress ?
128560424e9SKalle Valo 			   " (switching)" : "");
129560424e9SKalle Valo 	if (priv->rx_filter.promiscuous)
130560424e9SKalle Valo 		seq_puts(seq,   "Filter:     promisc\n");
131560424e9SKalle Valo 	else if (priv->rx_filter.fcs)
132560424e9SKalle Valo 		seq_puts(seq,   "Filter:     fcs\n");
133560424e9SKalle Valo 	if (priv->rx_filter.bssid)
134560424e9SKalle Valo 		seq_puts(seq,   "Filter:     bssid\n");
135560424e9SKalle Valo 	if (!priv->disable_beacon_filter)
136560424e9SKalle Valo 		seq_puts(seq,   "Filter:     beacons\n");
137560424e9SKalle Valo 
138560424e9SKalle Valo 	if (priv->enable_beacon ||
139560424e9SKalle Valo 	    priv->mode == NL80211_IFTYPE_AP ||
140560424e9SKalle Valo 	    priv->mode == NL80211_IFTYPE_ADHOC ||
141560424e9SKalle Valo 	    priv->mode == NL80211_IFTYPE_MESH_POINT ||
142560424e9SKalle Valo 	    priv->mode == NL80211_IFTYPE_P2P_GO)
143560424e9SKalle Valo 		seq_printf(seq, "Beaconing:  %s\n",
144560424e9SKalle Valo 			   priv->enable_beacon ?
145560424e9SKalle Valo 			   "enabled" : "disabled");
146560424e9SKalle Valo 
147560424e9SKalle Valo 	for (i = 0; i < 4; ++i)
148560424e9SKalle Valo 		seq_printf(seq, "EDCA(%d):    %d, %d, %d, %d, %d\n", i,
149560424e9SKalle Valo 			   priv->edca.params[i].cwmin,
150560424e9SKalle Valo 			   priv->edca.params[i].cwmax,
151560424e9SKalle Valo 			   priv->edca.params[i].aifns,
152560424e9SKalle Valo 			   priv->edca.params[i].txop_limit,
153560424e9SKalle Valo 			   priv->edca.params[i].max_rx_lifetime);
154560424e9SKalle Valo 
155560424e9SKalle Valo 	if (priv->join_status == CW1200_JOIN_STATUS_STA) {
156560424e9SKalle Valo 		static const char *pm_mode = "unknown";
157560424e9SKalle Valo 		switch (priv->powersave_mode.mode) {
158560424e9SKalle Valo 		case WSM_PSM_ACTIVE:
159560424e9SKalle Valo 			pm_mode = "off";
160560424e9SKalle Valo 			break;
161560424e9SKalle Valo 		case WSM_PSM_PS:
162560424e9SKalle Valo 			pm_mode = "on";
163560424e9SKalle Valo 			break;
164560424e9SKalle Valo 		case WSM_PSM_FAST_PS:
165560424e9SKalle Valo 			pm_mode = "dynamic";
166560424e9SKalle Valo 			break;
167560424e9SKalle Valo 		}
168560424e9SKalle Valo 		seq_printf(seq, "Preamble:   %s\n",
169560424e9SKalle Valo 			   cw1200_debug_preamble[priv->association_mode.preamble]);
170560424e9SKalle Valo 		seq_printf(seq, "AMPDU spcn: %d\n",
171560424e9SKalle Valo 			   priv->association_mode.mpdu_start_spacing);
172560424e9SKalle Valo 		seq_printf(seq, "Basic rate: 0x%.8X\n",
173560424e9SKalle Valo 			   le32_to_cpu(priv->association_mode.basic_rate_set));
174560424e9SKalle Valo 		seq_printf(seq, "Bss lost:   %d beacons\n",
175560424e9SKalle Valo 			   priv->bss_params.beacon_lost_count);
176560424e9SKalle Valo 		seq_printf(seq, "AID:        %d\n",
177560424e9SKalle Valo 			   priv->bss_params.aid);
178560424e9SKalle Valo 		seq_printf(seq, "Rates:      0x%.8X\n",
179560424e9SKalle Valo 			   priv->bss_params.operational_rate_set);
180560424e9SKalle Valo 		seq_printf(seq, "Powersave:  %s\n", pm_mode);
181560424e9SKalle Valo 	}
182560424e9SKalle Valo 	seq_printf(seq, "HT:         %s\n",
183560424e9SKalle Valo 		   cw1200_is_ht(&priv->ht_info) ? "on" : "off");
184560424e9SKalle Valo 	if (cw1200_is_ht(&priv->ht_info)) {
185560424e9SKalle Valo 		seq_printf(seq, "Greenfield: %s\n",
186560424e9SKalle Valo 			   cw1200_ht_greenfield(&priv->ht_info) ? "yes" : "no");
187560424e9SKalle Valo 		seq_printf(seq, "AMPDU dens: %d\n",
188560424e9SKalle Valo 			   cw1200_ht_ampdu_density(&priv->ht_info));
189560424e9SKalle Valo 	}
190560424e9SKalle Valo 	seq_printf(seq, "RSSI thold: %d\n",
191560424e9SKalle Valo 		   priv->cqm_rssi_thold);
192560424e9SKalle Valo 	seq_printf(seq, "RSSI hyst:  %d\n",
193560424e9SKalle Valo 		   priv->cqm_rssi_hyst);
194560424e9SKalle Valo 	seq_printf(seq, "Long retr:  %d\n",
195560424e9SKalle Valo 		   priv->long_frame_max_tx_count);
196560424e9SKalle Valo 	seq_printf(seq, "Short retr: %d\n",
197560424e9SKalle Valo 		   priv->short_frame_max_tx_count);
198560424e9SKalle Valo 	spin_lock_bh(&priv->tx_policy_cache.lock);
199560424e9SKalle Valo 	i = 0;
200560424e9SKalle Valo 	list_for_each(item, &priv->tx_policy_cache.used)
201560424e9SKalle Valo 		++i;
202560424e9SKalle Valo 	spin_unlock_bh(&priv->tx_policy_cache.lock);
203560424e9SKalle Valo 	seq_printf(seq, "RC in use:  %d\n", i);
204560424e9SKalle Valo 
205560424e9SKalle Valo 	seq_puts(seq, "\n");
206560424e9SKalle Valo 	for (i = 0; i < 4; ++i) {
207560424e9SKalle Valo 		cw1200_queue_status_show(seq, &priv->tx_queue[i]);
208560424e9SKalle Valo 		seq_puts(seq, "\n");
209560424e9SKalle Valo 	}
210560424e9SKalle Valo 
211560424e9SKalle Valo 	cw1200_debug_print_map(seq, priv, "Link map:   ",
212560424e9SKalle Valo 			       priv->link_id_map);
213560424e9SKalle Valo 	cw1200_debug_print_map(seq, priv, "Asleep map: ",
214560424e9SKalle Valo 			       priv->sta_asleep_mask);
215560424e9SKalle Valo 	cw1200_debug_print_map(seq, priv, "PSPOLL map: ",
216560424e9SKalle Valo 			       priv->pspoll_mask);
217560424e9SKalle Valo 
218560424e9SKalle Valo 	seq_puts(seq, "\n");
219560424e9SKalle Valo 
220560424e9SKalle Valo 	for (i = 0; i < CW1200_MAX_STA_IN_AP_MODE; ++i) {
221560424e9SKalle Valo 		if (priv->link_id_db[i].status) {
222560424e9SKalle Valo 			seq_printf(seq, "Link %d:     %s, %pM\n",
223560424e9SKalle Valo 				   i + 1,
224560424e9SKalle Valo 				   cw1200_debug_link_id[priv->link_id_db[i].status],
225560424e9SKalle Valo 				   priv->link_id_db[i].mac);
226560424e9SKalle Valo 		}
227560424e9SKalle Valo 	}
228560424e9SKalle Valo 
229560424e9SKalle Valo 	seq_puts(seq, "\n");
230560424e9SKalle Valo 
231560424e9SKalle Valo 	seq_printf(seq, "BH status:  %s\n",
232560424e9SKalle Valo 		   atomic_read(&priv->bh_term) ? "terminated" : "alive");
233560424e9SKalle Valo 	seq_printf(seq, "Pending RX: %d\n",
234560424e9SKalle Valo 		   atomic_read(&priv->bh_rx));
235560424e9SKalle Valo 	seq_printf(seq, "Pending TX: %d\n",
236560424e9SKalle Valo 		   atomic_read(&priv->bh_tx));
237560424e9SKalle Valo 	if (priv->bh_error)
238560424e9SKalle Valo 		seq_printf(seq, "BH errcode: %d\n",
239560424e9SKalle Valo 			   priv->bh_error);
240560424e9SKalle Valo 	seq_printf(seq, "TX bufs:    %d x %d bytes\n",
241560424e9SKalle Valo 		   priv->wsm_caps.input_buffers,
242560424e9SKalle Valo 		   priv->wsm_caps.input_buffer_size);
243560424e9SKalle Valo 	seq_printf(seq, "Used bufs:  %d\n",
244560424e9SKalle Valo 		   priv->hw_bufs_used);
245560424e9SKalle Valo 	seq_printf(seq, "Powermgmt:  %s\n",
246560424e9SKalle Valo 		   priv->powersave_enabled ? "on" : "off");
247560424e9SKalle Valo 	seq_printf(seq, "Device:     %s\n",
248560424e9SKalle Valo 		   priv->device_can_sleep ? "asleep" : "awake");
249560424e9SKalle Valo 
250560424e9SKalle Valo 	spin_lock(&priv->wsm_cmd.lock);
251560424e9SKalle Valo 	seq_printf(seq, "WSM status: %s\n",
252560424e9SKalle Valo 		   priv->wsm_cmd.done ? "idle" : "active");
253560424e9SKalle Valo 	seq_printf(seq, "WSM cmd:    0x%.4X (%td bytes)\n",
254560424e9SKalle Valo 		   priv->wsm_cmd.cmd, priv->wsm_cmd.len);
255560424e9SKalle Valo 	seq_printf(seq, "WSM retval: %d\n",
256560424e9SKalle Valo 		   priv->wsm_cmd.ret);
257560424e9SKalle Valo 	spin_unlock(&priv->wsm_cmd.lock);
258560424e9SKalle Valo 
259560424e9SKalle Valo 	seq_printf(seq, "Datapath:   %s\n",
260560424e9SKalle Valo 		   atomic_read(&priv->tx_lock) ? "locked" : "unlocked");
261560424e9SKalle Valo 	if (atomic_read(&priv->tx_lock))
262560424e9SKalle Valo 		seq_printf(seq, "TXlock cnt: %d\n",
263560424e9SKalle Valo 			   atomic_read(&priv->tx_lock));
264560424e9SKalle Valo 
265560424e9SKalle Valo 	seq_printf(seq, "TXed:       %d\n",
266560424e9SKalle Valo 		   d->tx);
267560424e9SKalle Valo 	seq_printf(seq, "AGG TXed:   %d\n",
268560424e9SKalle Valo 		   d->tx_agg);
269560424e9SKalle Valo 	seq_printf(seq, "MULTI TXed: %d (%d)\n",
270560424e9SKalle Valo 		   d->tx_multi, d->tx_multi_frames);
271560424e9SKalle Valo 	seq_printf(seq, "RXed:       %d\n",
272560424e9SKalle Valo 		   d->rx);
273560424e9SKalle Valo 	seq_printf(seq, "AGG RXed:   %d\n",
274560424e9SKalle Valo 		   d->rx_agg);
275560424e9SKalle Valo 	seq_printf(seq, "TX miss:    %d\n",
276560424e9SKalle Valo 		   d->tx_cache_miss);
277560424e9SKalle Valo 	seq_printf(seq, "TX align:   %d\n",
278560424e9SKalle Valo 		   d->tx_align);
279560424e9SKalle Valo 	seq_printf(seq, "TX burst:   %d\n",
280560424e9SKalle Valo 		   d->tx_burst);
281560424e9SKalle Valo 	seq_printf(seq, "TX TTL:     %d\n",
282560424e9SKalle Valo 		   d->tx_ttl);
283560424e9SKalle Valo 	seq_printf(seq, "Scan:       %s\n",
284560424e9SKalle Valo 		   atomic_read(&priv->scan.in_progress) ? "active" : "idle");
285560424e9SKalle Valo 
286560424e9SKalle Valo 	return 0;
287560424e9SKalle Valo }
288560424e9SKalle Valo 
289cc4dc97fSYangtao Li DEFINE_SHOW_ATTRIBUTE(cw1200_status);
290560424e9SKalle Valo 
cw1200_counters_show(struct seq_file * seq,void * v)291560424e9SKalle Valo static int cw1200_counters_show(struct seq_file *seq, void *v)
292560424e9SKalle Valo {
293560424e9SKalle Valo 	int ret;
294560424e9SKalle Valo 	struct cw1200_common *priv = seq->private;
295560424e9SKalle Valo 	struct wsm_mib_counters_table counters;
296560424e9SKalle Valo 
297560424e9SKalle Valo 	ret = wsm_get_counters_table(priv, &counters);
298560424e9SKalle Valo 	if (ret)
299560424e9SKalle Valo 		return ret;
300560424e9SKalle Valo 
301560424e9SKalle Valo #define PUT_COUNTER(tab, name) \
302560424e9SKalle Valo 	seq_printf(seq, "%s:" tab "%d\n", #name, \
303560424e9SKalle Valo 		__le32_to_cpu(counters.name))
304560424e9SKalle Valo 
305560424e9SKalle Valo 	PUT_COUNTER("\t\t", plcp_errors);
306560424e9SKalle Valo 	PUT_COUNTER("\t\t", fcs_errors);
307560424e9SKalle Valo 	PUT_COUNTER("\t\t", tx_packets);
308560424e9SKalle Valo 	PUT_COUNTER("\t\t", rx_packets);
309560424e9SKalle Valo 	PUT_COUNTER("\t\t", rx_packet_errors);
310560424e9SKalle Valo 	PUT_COUNTER("\t",   rx_decryption_failures);
311560424e9SKalle Valo 	PUT_COUNTER("\t\t", rx_mic_failures);
312560424e9SKalle Valo 	PUT_COUNTER("\t",   rx_no_key_failures);
313560424e9SKalle Valo 	PUT_COUNTER("\t",   tx_multicast_frames);
314560424e9SKalle Valo 	PUT_COUNTER("\t",   tx_frames_success);
315560424e9SKalle Valo 	PUT_COUNTER("\t",   tx_frame_failures);
316560424e9SKalle Valo 	PUT_COUNTER("\t",   tx_frames_retried);
317560424e9SKalle Valo 	PUT_COUNTER("\t",   tx_frames_multi_retried);
318560424e9SKalle Valo 	PUT_COUNTER("\t",   rx_frame_duplicates);
319560424e9SKalle Valo 	PUT_COUNTER("\t\t", rts_success);
320560424e9SKalle Valo 	PUT_COUNTER("\t\t", rts_failures);
321560424e9SKalle Valo 	PUT_COUNTER("\t\t", ack_failures);
322560424e9SKalle Valo 	PUT_COUNTER("\t",   rx_multicast_frames);
323560424e9SKalle Valo 	PUT_COUNTER("\t",   rx_frames_success);
324560424e9SKalle Valo 	PUT_COUNTER("\t",   rx_cmac_icv_errors);
325560424e9SKalle Valo 	PUT_COUNTER("\t\t", rx_cmac_replays);
326560424e9SKalle Valo 	PUT_COUNTER("\t",   rx_mgmt_ccmp_replays);
327560424e9SKalle Valo 
328560424e9SKalle Valo #undef PUT_COUNTER
329560424e9SKalle Valo 
330560424e9SKalle Valo 	return 0;
331560424e9SKalle Valo }
332560424e9SKalle Valo 
333cc4dc97fSYangtao Li DEFINE_SHOW_ATTRIBUTE(cw1200_counters);
334560424e9SKalle Valo 
cw1200_wsm_dumps(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)335560424e9SKalle Valo static ssize_t cw1200_wsm_dumps(struct file *file,
336560424e9SKalle Valo 	const char __user *user_buf, size_t count, loff_t *ppos)
337560424e9SKalle Valo {
338560424e9SKalle Valo 	struct cw1200_common *priv = file->private_data;
339560424e9SKalle Valo 	char buf[1];
340560424e9SKalle Valo 
341560424e9SKalle Valo 	if (!count)
342560424e9SKalle Valo 		return -EINVAL;
343560424e9SKalle Valo 	if (copy_from_user(buf, user_buf, 1))
344560424e9SKalle Valo 		return -EFAULT;
345560424e9SKalle Valo 
346560424e9SKalle Valo 	if (buf[0] == '1')
347560424e9SKalle Valo 		priv->wsm_enable_wsm_dumps = 1;
348560424e9SKalle Valo 	else
349560424e9SKalle Valo 		priv->wsm_enable_wsm_dumps = 0;
350560424e9SKalle Valo 
351560424e9SKalle Valo 	return count;
352560424e9SKalle Valo }
353560424e9SKalle Valo 
354560424e9SKalle Valo static const struct file_operations fops_wsm_dumps = {
355560424e9SKalle Valo 	.open = simple_open,
356560424e9SKalle Valo 	.write = cw1200_wsm_dumps,
357560424e9SKalle Valo 	.llseek = default_llseek,
358560424e9SKalle Valo };
359560424e9SKalle Valo 
cw1200_debug_init(struct cw1200_common * priv)360560424e9SKalle Valo int cw1200_debug_init(struct cw1200_common *priv)
361560424e9SKalle Valo {
362560424e9SKalle Valo 	int ret = -ENOMEM;
363560424e9SKalle Valo 	struct cw1200_debug_priv *d = kzalloc(sizeof(struct cw1200_debug_priv),
364560424e9SKalle Valo 			GFP_KERNEL);
365560424e9SKalle Valo 	priv->debug = d;
366560424e9SKalle Valo 	if (!d)
367560424e9SKalle Valo 		return ret;
368560424e9SKalle Valo 
369560424e9SKalle Valo 	d->debugfs_phy = debugfs_create_dir("cw1200",
370560424e9SKalle Valo 					    priv->hw->wiphy->debugfsdir);
37180f4c5e3SGreg Kroah-Hartman 	debugfs_create_file("status", 0400, d->debugfs_phy, priv,
37280f4c5e3SGreg Kroah-Hartman 			    &cw1200_status_fops);
37380f4c5e3SGreg Kroah-Hartman 	debugfs_create_file("counters", 0400, d->debugfs_phy, priv,
37480f4c5e3SGreg Kroah-Hartman 			    &cw1200_counters_fops);
37580f4c5e3SGreg Kroah-Hartman 	debugfs_create_file("wsm_dumps", 0200, d->debugfs_phy, priv,
37680f4c5e3SGreg Kroah-Hartman 			    &fops_wsm_dumps);
377560424e9SKalle Valo 
378560424e9SKalle Valo 	return 0;
379560424e9SKalle Valo }
380560424e9SKalle Valo 
cw1200_debug_release(struct cw1200_common * priv)381560424e9SKalle Valo void cw1200_debug_release(struct cw1200_common *priv)
382560424e9SKalle Valo {
383560424e9SKalle Valo 	struct cw1200_debug_priv *d = priv->debug;
384560424e9SKalle Valo 	if (d) {
385560424e9SKalle Valo 		debugfs_remove_recursive(d->debugfs_phy);
386560424e9SKalle Valo 		priv->debug = NULL;
387560424e9SKalle Valo 		kfree(d);
388560424e9SKalle Valo 	}
389560424e9SKalle Valo }
390