xref: /linux/drivers/net/wireless/ath/wil6210/debugfs.c (revision ba95c7452439756d4f6dceb5a188b7c31dbbe5b6)
1 /*
2  * Copyright (c) 2012-2017 Qualcomm Atheros, Inc.
3  * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #include <linux/module.h>
19 #include <linux/debugfs.h>
20 #include <linux/seq_file.h>
21 #include <linux/pci.h>
22 #include <linux/rtnetlink.h>
23 #include <linux/power_supply.h>
24 #include "wil6210.h"
25 #include "wmi.h"
26 #include "txrx.h"
27 #include "pmc.h"
28 
29 /* Nasty hack. Better have per device instances */
30 static u32 mem_addr;
31 static u32 dbg_txdesc_index;
32 static u32 dbg_ring_index; /* 24+ for Rx, 0..23 for Tx */
33 static u32 dbg_status_msg_index;
34 /* 0..wil->num_rx_status_rings-1 for Rx, wil->tx_sring_idx for Tx */
35 static u32 dbg_sring_index;
36 
37 enum dbg_off_type {
38 	doff_u32 = 0,
39 	doff_x32 = 1,
40 	doff_ulong = 2,
41 	doff_io32 = 3,
42 	doff_u8 = 4
43 };
44 
45 /* offset to "wil" */
46 struct dbg_off {
47 	const char *name;
48 	umode_t mode;
49 	ulong off;
50 	enum dbg_off_type type;
51 };
52 
53 static void wil_print_desc_edma(struct seq_file *s, struct wil6210_priv *wil,
54 				struct wil_ring *ring,
55 				char _s, char _h, int idx)
56 {
57 	u8 num_of_descs;
58 	bool has_skb = false;
59 
60 	if (ring->is_rx) {
61 		struct wil_rx_enhanced_desc *rx_d =
62 			(struct wil_rx_enhanced_desc *)
63 			&ring->va[idx].rx.enhanced;
64 		u16 buff_id = le16_to_cpu(rx_d->mac.buff_id);
65 
66 		if (wil->rx_buff_mgmt.buff_arr &&
67 		    wil_val_in_range(buff_id, 0, wil->rx_buff_mgmt.size))
68 			has_skb = wil->rx_buff_mgmt.buff_arr[buff_id].skb;
69 		seq_printf(s, "%c", (has_skb) ? _h : _s);
70 	} else {
71 		struct wil_tx_enhanced_desc *d =
72 			(struct wil_tx_enhanced_desc *)
73 			&ring->va[idx].tx.enhanced;
74 
75 		num_of_descs = (u8)d->mac.d[2];
76 		has_skb = ring->ctx && ring->ctx[idx].skb;
77 		if (num_of_descs >= 1)
78 			seq_printf(s, "%c", has_skb ? _h : _s);
79 		else
80 			/* num_of_descs == 0, it's a frag in a list of descs */
81 			seq_printf(s, "%c", has_skb ? 'h' : _s);
82 	}
83 }
84 
85 static void wil_print_ring(struct seq_file *s, struct wil6210_priv *wil,
86 			   const char *name, struct wil_ring *ring,
87 			   char _s, char _h)
88 {
89 	void __iomem *x;
90 	u32 v;
91 
92 	seq_printf(s, "RING %s = {\n", name);
93 	seq_printf(s, "  pa     = %pad\n", &ring->pa);
94 	seq_printf(s, "  va     = 0x%p\n", ring->va);
95 	seq_printf(s, "  size   = %d\n", ring->size);
96 	if (wil->use_enhanced_dma_hw && ring->is_rx)
97 		seq_printf(s, "  swtail = %u\n", *ring->edma_rx_swtail.va);
98 	else
99 		seq_printf(s, "  swtail = %d\n", ring->swtail);
100 	seq_printf(s, "  swhead = %d\n", ring->swhead);
101 	if (wil->use_enhanced_dma_hw) {
102 		int ring_id = ring->is_rx ?
103 			WIL_RX_DESC_RING_ID : ring - wil->ring_tx;
104 		/* SUBQ_CONS is a table of 32 entries, one for each Q pair.
105 		 * lower 16bits are for even ring_id and upper 16bits are for
106 		 * odd ring_id
107 		 */
108 		x = wmi_addr(wil, RGF_DMA_SCM_SUBQ_CONS + 4 * (ring_id / 2));
109 		v = readl_relaxed(x);
110 
111 		v = (ring_id % 2 ? (v >> 16) : (v & 0xffff));
112 		seq_printf(s, "  hwhead = %u\n", v);
113 	}
114 	seq_printf(s, "  hwtail = [0x%08x] -> ", ring->hwtail);
115 	x = wmi_addr(wil, ring->hwtail);
116 	if (x) {
117 		v = readl(x);
118 		seq_printf(s, "0x%08x = %d\n", v, v);
119 	} else {
120 		seq_puts(s, "???\n");
121 	}
122 
123 	if (ring->va && (ring->size <= (1 << WIL_RING_SIZE_ORDER_MAX))) {
124 		uint i;
125 
126 		for (i = 0; i < ring->size; i++) {
127 			if ((i % 128) == 0 && i != 0)
128 				seq_puts(s, "\n");
129 			if (wil->use_enhanced_dma_hw) {
130 				wil_print_desc_edma(s, wil, ring, _s, _h, i);
131 			} else {
132 				volatile struct vring_tx_desc *d =
133 					&ring->va[i].tx.legacy;
134 				seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
135 					   _s : (ring->ctx[i].skb ? _h : 'h'));
136 			}
137 		}
138 		seq_puts(s, "\n");
139 	}
140 	seq_puts(s, "}\n");
141 }
142 
143 static int ring_show(struct seq_file *s, void *data)
144 {
145 	uint i;
146 	struct wil6210_priv *wil = s->private;
147 
148 	wil_print_ring(s, wil, "rx", &wil->ring_rx, 'S', '_');
149 
150 	for (i = 0; i < ARRAY_SIZE(wil->ring_tx); i++) {
151 		struct wil_ring *ring = &wil->ring_tx[i];
152 		struct wil_ring_tx_data *txdata = &wil->ring_tx_data[i];
153 
154 		if (ring->va) {
155 			int cid = wil->ring2cid_tid[i][0];
156 			int tid = wil->ring2cid_tid[i][1];
157 			u32 swhead = ring->swhead;
158 			u32 swtail = ring->swtail;
159 			int used = (ring->size + swhead - swtail)
160 				   % ring->size;
161 			int avail = ring->size - used - 1;
162 			char name[10];
163 			char sidle[10];
164 			/* performance monitoring */
165 			cycles_t now = get_cycles();
166 			uint64_t idle = txdata->idle * 100;
167 			uint64_t total = now - txdata->begin;
168 
169 			if (total != 0) {
170 				do_div(idle, total);
171 				snprintf(sidle, sizeof(sidle), "%3d%%",
172 					 (int)idle);
173 			} else {
174 				snprintf(sidle, sizeof(sidle), "N/A");
175 			}
176 			txdata->begin = now;
177 			txdata->idle = 0ULL;
178 
179 			snprintf(name, sizeof(name), "tx_%2d", i);
180 
181 			if (cid < wil->max_assoc_sta)
182 				seq_printf(s,
183 					   "\n%pM CID %d TID %d 1x%s BACK([%u] %u TU A%s) [%3d|%3d] idle %s\n",
184 					   wil->sta[cid].addr, cid, tid,
185 					   txdata->dot1x_open ? "+" : "-",
186 					   txdata->agg_wsize,
187 					   txdata->agg_timeout,
188 					   txdata->agg_amsdu ? "+" : "-",
189 					   used, avail, sidle);
190 			else
191 				seq_printf(s,
192 					   "\nBroadcast 1x%s [%3d|%3d] idle %s\n",
193 					   txdata->dot1x_open ? "+" : "-",
194 					   used, avail, sidle);
195 
196 			wil_print_ring(s, wil, name, ring, '_', 'H');
197 		}
198 	}
199 
200 	return 0;
201 }
202 DEFINE_SHOW_ATTRIBUTE(ring);
203 
204 static void wil_print_sring(struct seq_file *s, struct wil6210_priv *wil,
205 			    struct wil_status_ring *sring)
206 {
207 	void __iomem *x;
208 	int sring_idx = sring - wil->srings;
209 	u32 v;
210 
211 	seq_printf(s, "Status Ring %s [ %d ] = {\n",
212 		   sring->is_rx ? "RX" : "TX", sring_idx);
213 	seq_printf(s, "  pa     = %pad\n", &sring->pa);
214 	seq_printf(s, "  va     = 0x%pK\n", sring->va);
215 	seq_printf(s, "  size   = %d\n", sring->size);
216 	seq_printf(s, "  elem_size   = %zu\n", sring->elem_size);
217 	seq_printf(s, "  swhead = %d\n", sring->swhead);
218 	if (wil->use_enhanced_dma_hw) {
219 		/* COMPQ_PROD is a table of 32 entries, one for each Q pair.
220 		 * lower 16bits are for even ring_id and upper 16bits are for
221 		 * odd ring_id
222 		 */
223 		x = wmi_addr(wil, RGF_DMA_SCM_COMPQ_PROD + 4 * (sring_idx / 2));
224 		v = readl_relaxed(x);
225 
226 		v = (sring_idx % 2 ? (v >> 16) : (v & 0xffff));
227 		seq_printf(s, "  hwhead = %u\n", v);
228 	}
229 	seq_printf(s, "  hwtail = [0x%08x] -> ", sring->hwtail);
230 	x = wmi_addr(wil, sring->hwtail);
231 	if (x) {
232 		v = readl_relaxed(x);
233 		seq_printf(s, "0x%08x = %d\n", v, v);
234 	} else {
235 		seq_puts(s, "???\n");
236 	}
237 	seq_printf(s, "  desc_rdy_pol   = %d\n", sring->desc_rdy_pol);
238 	seq_printf(s, "  invalid_buff_id_cnt   = %d\n",
239 		   sring->invalid_buff_id_cnt);
240 
241 	if (sring->va && (sring->size <= (1 << WIL_RING_SIZE_ORDER_MAX))) {
242 		uint i;
243 
244 		for (i = 0; i < sring->size; i++) {
245 			u32 *sdword_0 =
246 				(u32 *)(sring->va + (sring->elem_size * i));
247 
248 			if ((i % 128) == 0 && i != 0)
249 				seq_puts(s, "\n");
250 			if (i == sring->swhead)
251 				seq_printf(s, "%c", (*sdword_0 & BIT(31)) ?
252 					   'X' : 'x');
253 			else
254 				seq_printf(s, "%c", (*sdword_0 & BIT(31)) ?
255 					   '1' : '0');
256 		}
257 		seq_puts(s, "\n");
258 	}
259 	seq_puts(s, "}\n");
260 }
261 
262 static int srings_show(struct seq_file *s, void *data)
263 {
264 	struct wil6210_priv *wil = s->private;
265 	int i = 0;
266 
267 	for (i = 0; i < WIL6210_MAX_STATUS_RINGS; i++)
268 		if (wil->srings[i].va)
269 			wil_print_sring(s, wil, &wil->srings[i]);
270 
271 	return 0;
272 }
273 DEFINE_SHOW_ATTRIBUTE(srings);
274 
275 static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
276 			    const char *prefix)
277 {
278 	seq_hex_dump(s, prefix, DUMP_PREFIX_NONE, 16, 1, p, len, false);
279 }
280 
281 static void wil_print_mbox_ring(struct seq_file *s, const char *prefix,
282 				void __iomem *off)
283 {
284 	struct wil6210_priv *wil = s->private;
285 	struct wil6210_mbox_ring r;
286 	int rsize;
287 	uint i;
288 
289 	wil_halp_vote(wil);
290 
291 	if (wil_mem_access_lock(wil)) {
292 		wil_halp_unvote(wil);
293 		return;
294 	}
295 
296 	wil_memcpy_fromio_32(&r, off, sizeof(r));
297 	wil_mbox_ring_le2cpus(&r);
298 	/*
299 	 * we just read memory block from NIC. This memory may be
300 	 * garbage. Check validity before using it.
301 	 */
302 	rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
303 
304 	seq_printf(s, "ring %s = {\n", prefix);
305 	seq_printf(s, "  base = 0x%08x\n", r.base);
306 	seq_printf(s, "  size = 0x%04x bytes -> %d entries\n", r.size, rsize);
307 	seq_printf(s, "  tail = 0x%08x\n", r.tail);
308 	seq_printf(s, "  head = 0x%08x\n", r.head);
309 	seq_printf(s, "  entry size = %d\n", r.entry_size);
310 
311 	if (r.size % sizeof(struct wil6210_mbox_ring_desc)) {
312 		seq_printf(s, "  ??? size is not multiple of %zd, garbage?\n",
313 			   sizeof(struct wil6210_mbox_ring_desc));
314 		goto out;
315 	}
316 
317 	if (!wmi_addr(wil, r.base) ||
318 	    !wmi_addr(wil, r.tail) ||
319 	    !wmi_addr(wil, r.head)) {
320 		seq_puts(s, "  ??? pointers are garbage?\n");
321 		goto out;
322 	}
323 
324 	for (i = 0; i < rsize; i++) {
325 		struct wil6210_mbox_ring_desc d;
326 		struct wil6210_mbox_hdr hdr;
327 		size_t delta = i * sizeof(d);
328 		void __iomem *x = wil->csr + HOSTADDR(r.base) + delta;
329 
330 		wil_memcpy_fromio_32(&d, x, sizeof(d));
331 
332 		seq_printf(s, "  [%2x] %s %s%s 0x%08x", i,
333 			   d.sync ? "F" : "E",
334 			   (r.tail - r.base == delta) ? "t" : " ",
335 			   (r.head - r.base == delta) ? "h" : " ",
336 			   le32_to_cpu(d.addr));
337 		if (0 == wmi_read_hdr(wil, d.addr, &hdr)) {
338 			u16 len = le16_to_cpu(hdr.len);
339 
340 			seq_printf(s, " -> %04x %04x %04x %02x\n",
341 				   le16_to_cpu(hdr.seq), len,
342 				   le16_to_cpu(hdr.type), hdr.flags);
343 			if (len <= MAX_MBOXITEM_SIZE) {
344 				unsigned char databuf[MAX_MBOXITEM_SIZE];
345 				void __iomem *src = wmi_buffer(wil, d.addr) +
346 					sizeof(struct wil6210_mbox_hdr);
347 				/*
348 				 * No need to check @src for validity -
349 				 * we already validated @d.addr while
350 				 * reading header
351 				 */
352 				wil_memcpy_fromio_32(databuf, src, len);
353 				wil_seq_hexdump(s, databuf, len, "      : ");
354 			}
355 		} else {
356 			seq_puts(s, "\n");
357 		}
358 	}
359  out:
360 	seq_puts(s, "}\n");
361 	wil_mem_access_unlock(wil);
362 	wil_halp_unvote(wil);
363 }
364 
365 static int mbox_show(struct seq_file *s, void *data)
366 {
367 	struct wil6210_priv *wil = s->private;
368 	int ret;
369 
370 	ret = wil_pm_runtime_get(wil);
371 	if (ret < 0)
372 		return ret;
373 
374 	wil_print_mbox_ring(s, "tx", wil->csr + HOST_MBOX +
375 		       offsetof(struct wil6210_mbox_ctl, tx));
376 	wil_print_mbox_ring(s, "rx", wil->csr + HOST_MBOX +
377 		       offsetof(struct wil6210_mbox_ctl, rx));
378 
379 	wil_pm_runtime_put(wil);
380 
381 	return 0;
382 }
383 DEFINE_SHOW_ATTRIBUTE(mbox);
384 
385 static int wil_debugfs_iomem_x32_set(void *data, u64 val)
386 {
387 	struct wil_debugfs_iomem_data *d = (struct
388 					    wil_debugfs_iomem_data *)data;
389 	struct wil6210_priv *wil = d->wil;
390 	int ret;
391 
392 	ret = wil_pm_runtime_get(wil);
393 	if (ret < 0)
394 		return ret;
395 
396 	writel(val, (void __iomem *)d->offset);
397 	wmb(); /* make sure write propagated to HW */
398 
399 	wil_pm_runtime_put(wil);
400 
401 	return 0;
402 }
403 
404 static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
405 {
406 	struct wil_debugfs_iomem_data *d = (struct
407 					    wil_debugfs_iomem_data *)data;
408 	struct wil6210_priv *wil = d->wil;
409 	int ret;
410 
411 	ret = wil_pm_runtime_get(wil);
412 	if (ret < 0)
413 		return ret;
414 
415 	*val = readl((void __iomem *)d->offset);
416 
417 	wil_pm_runtime_put(wil);
418 
419 	return 0;
420 }
421 
422 DEFINE_DEBUGFS_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
423 			 wil_debugfs_iomem_x32_set, "0x%08llx\n");
424 
425 static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
426 						   umode_t mode,
427 						   struct dentry *parent,
428 						   void *value,
429 						   struct wil6210_priv *wil)
430 {
431 	struct dentry *file;
432 	struct wil_debugfs_iomem_data *data = &wil->dbg_data.data_arr[
433 					      wil->dbg_data.iomem_data_count];
434 
435 	data->wil = wil;
436 	data->offset = value;
437 
438 	file = debugfs_create_file_unsafe(name, mode, parent, data,
439 					  &fops_iomem_x32);
440 	if (!IS_ERR_OR_NULL(file))
441 		wil->dbg_data.iomem_data_count++;
442 
443 	return file;
444 }
445 
446 static int wil_debugfs_ulong_set(void *data, u64 val)
447 {
448 	*(ulong *)data = val;
449 	return 0;
450 }
451 
452 static int wil_debugfs_ulong_get(void *data, u64 *val)
453 {
454 	*val = *(ulong *)data;
455 	return 0;
456 }
457 
458 DEFINE_DEBUGFS_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
459 			 wil_debugfs_ulong_set, "0x%llx\n");
460 
461 static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode,
462 					       struct dentry *parent,
463 					       ulong *value)
464 {
465 	return debugfs_create_file_unsafe(name, mode, parent, value,
466 					  &wil_fops_ulong);
467 }
468 
469 /**
470  * wil6210_debugfs_init_offset - create set of debugfs files
471  * @wil - driver's context, used for printing
472  * @dbg - directory on the debugfs, where files will be created
473  * @base - base address used in address calculation
474  * @tbl - table with file descriptions. Should be terminated with empty element.
475  *
476  * Creates files accordingly to the @tbl.
477  */
478 static void wil6210_debugfs_init_offset(struct wil6210_priv *wil,
479 					struct dentry *dbg, void *base,
480 					const struct dbg_off * const tbl)
481 {
482 	int i;
483 
484 	for (i = 0; tbl[i].name; i++) {
485 		struct dentry *f;
486 
487 		switch (tbl[i].type) {
488 		case doff_u32:
489 			f = debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg,
490 					       base + tbl[i].off);
491 			break;
492 		case doff_x32:
493 			f = debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg,
494 					       base + tbl[i].off);
495 			break;
496 		case doff_ulong:
497 			f = wil_debugfs_create_ulong(tbl[i].name, tbl[i].mode,
498 						     dbg, base + tbl[i].off);
499 			break;
500 		case doff_io32:
501 			f = wil_debugfs_create_iomem_x32(tbl[i].name,
502 							 tbl[i].mode, dbg,
503 							 base + tbl[i].off,
504 							 wil);
505 			break;
506 		case doff_u8:
507 			f = debugfs_create_u8(tbl[i].name, tbl[i].mode, dbg,
508 					      base + tbl[i].off);
509 			break;
510 		default:
511 			f = ERR_PTR(-EINVAL);
512 		}
513 		if (IS_ERR_OR_NULL(f))
514 			wil_err(wil, "Create file \"%s\": err %ld\n",
515 				tbl[i].name, PTR_ERR(f));
516 	}
517 }
518 
519 static const struct dbg_off isr_off[] = {
520 	{"ICC", 0644, offsetof(struct RGF_ICR, ICC), doff_io32},
521 	{"ICR", 0644, offsetof(struct RGF_ICR, ICR), doff_io32},
522 	{"ICM", 0644, offsetof(struct RGF_ICR, ICM), doff_io32},
523 	{"ICS",	0244, offsetof(struct RGF_ICR, ICS), doff_io32},
524 	{"IMV", 0644, offsetof(struct RGF_ICR, IMV), doff_io32},
525 	{"IMS",	0244, offsetof(struct RGF_ICR, IMS), doff_io32},
526 	{"IMC",	0244, offsetof(struct RGF_ICR, IMC), doff_io32},
527 	{},
528 };
529 
530 static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
531 				      const char *name,
532 				      struct dentry *parent, u32 off)
533 {
534 	struct dentry *d = debugfs_create_dir(name, parent);
535 
536 	if (IS_ERR_OR_NULL(d))
537 		return -ENODEV;
538 
539 	wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off,
540 				    isr_off);
541 
542 	return 0;
543 }
544 
545 static const struct dbg_off pseudo_isr_off[] = {
546 	{"CAUSE",   0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32},
547 	{"MASK_SW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32},
548 	{"MASK_FW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32},
549 	{},
550 };
551 
552 static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
553 					     struct dentry *parent)
554 {
555 	struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
556 
557 	if (IS_ERR_OR_NULL(d))
558 		return -ENODEV;
559 
560 	wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
561 				    pseudo_isr_off);
562 
563 	return 0;
564 }
565 
566 static const struct dbg_off lgc_itr_cnt_off[] = {
567 	{"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32},
568 	{"DATA", 0644, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32},
569 	{"CTL",  0644, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32},
570 	{},
571 };
572 
573 static const struct dbg_off tx_itr_cnt_off[] = {
574 	{"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_TRSH),
575 	 doff_io32},
576 	{"DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_DATA),
577 	 doff_io32},
578 	{"CTL",  0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_CTL),
579 	 doff_io32},
580 	{"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_TRSH),
581 	 doff_io32},
582 	{"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_DATA),
583 	 doff_io32},
584 	{"IDL_CTL",  0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_CTL),
585 	 doff_io32},
586 	{},
587 };
588 
589 static const struct dbg_off rx_itr_cnt_off[] = {
590 	{"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_TRSH),
591 	 doff_io32},
592 	{"DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_DATA),
593 	 doff_io32},
594 	{"CTL",  0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_CTL),
595 	 doff_io32},
596 	{"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_TRSH),
597 	 doff_io32},
598 	{"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_DATA),
599 	 doff_io32},
600 	{"IDL_CTL",  0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_CTL),
601 	 doff_io32},
602 	{},
603 };
604 
605 static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
606 					  struct dentry *parent)
607 {
608 	struct dentry *d, *dtx, *drx;
609 
610 	d = debugfs_create_dir("ITR_CNT", parent);
611 	if (IS_ERR_OR_NULL(d))
612 		return -ENODEV;
613 
614 	dtx = debugfs_create_dir("TX", d);
615 	drx = debugfs_create_dir("RX", d);
616 	if (IS_ERR_OR_NULL(dtx) || IS_ERR_OR_NULL(drx))
617 		return -ENODEV;
618 
619 	wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
620 				    lgc_itr_cnt_off);
621 
622 	wil6210_debugfs_init_offset(wil, dtx, (void * __force)wil->csr,
623 				    tx_itr_cnt_off);
624 
625 	wil6210_debugfs_init_offset(wil, drx, (void * __force)wil->csr,
626 				    rx_itr_cnt_off);
627 	return 0;
628 }
629 
630 static int memread_show(struct seq_file *s, void *data)
631 {
632 	struct wil6210_priv *wil = s->private;
633 	void __iomem *a;
634 	int ret;
635 
636 	ret = wil_pm_runtime_get(wil);
637 	if (ret < 0)
638 		return ret;
639 
640 	ret = wil_mem_access_lock(wil);
641 	if (ret) {
642 		wil_pm_runtime_put(wil);
643 		return ret;
644 	}
645 
646 	a = wmi_buffer(wil, cpu_to_le32(mem_addr));
647 
648 	if (a)
649 		seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, readl(a));
650 	else
651 		seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
652 
653 	wil_mem_access_unlock(wil);
654 	wil_pm_runtime_put(wil);
655 
656 	return 0;
657 }
658 DEFINE_SHOW_ATTRIBUTE(memread);
659 
660 static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
661 				    size_t count, loff_t *ppos)
662 {
663 	enum { max_count = 4096 };
664 	struct wil_blob_wrapper *wil_blob = file->private_data;
665 	struct wil6210_priv *wil = wil_blob->wil;
666 	loff_t aligned_pos, pos = *ppos;
667 	size_t available = wil_blob->blob.size;
668 	void *buf;
669 	size_t unaligned_bytes, aligned_count, ret;
670 	int rc;
671 
672 	if (pos < 0)
673 		return -EINVAL;
674 
675 	if (pos >= available || !count)
676 		return 0;
677 
678 	if (count > available - pos)
679 		count = available - pos;
680 	if (count > max_count)
681 		count = max_count;
682 
683 	/* set pos to 4 bytes aligned */
684 	unaligned_bytes = pos % 4;
685 	aligned_pos = pos - unaligned_bytes;
686 	aligned_count = count + unaligned_bytes;
687 
688 	buf = kmalloc(aligned_count, GFP_KERNEL);
689 	if (!buf)
690 		return -ENOMEM;
691 
692 	rc = wil_pm_runtime_get(wil);
693 	if (rc < 0) {
694 		kfree(buf);
695 		return rc;
696 	}
697 
698 	rc = wil_mem_access_lock(wil);
699 	if (rc) {
700 		kfree(buf);
701 		wil_pm_runtime_put(wil);
702 		return rc;
703 	}
704 
705 	wil_memcpy_fromio_32(buf, (const void __iomem *)
706 			     wil_blob->blob.data + aligned_pos, aligned_count);
707 
708 	ret = copy_to_user(user_buf, buf + unaligned_bytes, count);
709 
710 	wil_mem_access_unlock(wil);
711 	wil_pm_runtime_put(wil);
712 
713 	kfree(buf);
714 	if (ret == count)
715 		return -EFAULT;
716 
717 	count -= ret;
718 	*ppos = pos + count;
719 
720 	return count;
721 }
722 
723 static const struct file_operations fops_ioblob = {
724 	.read =		wil_read_file_ioblob,
725 	.open =		simple_open,
726 	.llseek =	default_llseek,
727 };
728 
729 static
730 struct dentry *wil_debugfs_create_ioblob(const char *name,
731 					 umode_t mode,
732 					 struct dentry *parent,
733 					 struct wil_blob_wrapper *wil_blob)
734 {
735 	return debugfs_create_file(name, mode, parent, wil_blob, &fops_ioblob);
736 }
737 
738 /*---write channel 1..4 to rxon for it, 0 to rxoff---*/
739 static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
740 				   size_t len, loff_t *ppos)
741 {
742 	struct wil6210_priv *wil = file->private_data;
743 	int rc;
744 	long channel;
745 	bool on;
746 
747 	char *kbuf = memdup_user_nul(buf, len);
748 
749 	if (IS_ERR(kbuf))
750 		return PTR_ERR(kbuf);
751 	rc = kstrtol(kbuf, 0, &channel);
752 	kfree(kbuf);
753 	if (rc)
754 		return rc;
755 
756 	if ((channel < 0) || (channel > 4)) {
757 		wil_err(wil, "Invalid channel %ld\n", channel);
758 		return -EINVAL;
759 	}
760 	on = !!channel;
761 
762 	if (on) {
763 		rc = wmi_set_channel(wil, (int)channel);
764 		if (rc)
765 			return rc;
766 	}
767 
768 	rc = wmi_rxon(wil, on);
769 	if (rc)
770 		return rc;
771 
772 	return len;
773 }
774 
775 static const struct file_operations fops_rxon = {
776 	.write = wil_write_file_rxon,
777 	.open  = simple_open,
778 };
779 
780 /* block ack control, write:
781  * - "add <ringid> <agg_size> <timeout>" to trigger ADDBA
782  * - "del_tx <ringid> <reason>" to trigger DELBA for Tx side
783  * - "del_rx <CID> <TID> <reason>" to trigger DELBA for Rx side
784  */
785 static ssize_t wil_write_back(struct file *file, const char __user *buf,
786 			      size_t len, loff_t *ppos)
787 {
788 	struct wil6210_priv *wil = file->private_data;
789 	int rc;
790 	char *kbuf = kmalloc(len + 1, GFP_KERNEL);
791 	char cmd[9];
792 	int p1, p2, p3;
793 
794 	if (!kbuf)
795 		return -ENOMEM;
796 
797 	rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
798 	if (rc != len) {
799 		kfree(kbuf);
800 		return rc >= 0 ? -EIO : rc;
801 	}
802 
803 	kbuf[len] = '\0';
804 	rc = sscanf(kbuf, "%8s %d %d %d", cmd, &p1, &p2, &p3);
805 	kfree(kbuf);
806 
807 	if (rc < 0)
808 		return rc;
809 	if (rc < 2)
810 		return -EINVAL;
811 
812 	if ((strcmp(cmd, "add") == 0) ||
813 	    (strcmp(cmd, "del_tx") == 0)) {
814 		struct wil_ring_tx_data *txdata;
815 
816 		if (p1 < 0 || p1 >= WIL6210_MAX_TX_RINGS) {
817 			wil_err(wil, "BACK: invalid ring id %d\n", p1);
818 			return -EINVAL;
819 		}
820 		txdata = &wil->ring_tx_data[p1];
821 		if (strcmp(cmd, "add") == 0) {
822 			if (rc < 3) {
823 				wil_err(wil, "BACK: add require at least 2 params\n");
824 				return -EINVAL;
825 			}
826 			if (rc < 4)
827 				p3 = 0;
828 			wmi_addba(wil, txdata->mid, p1, p2, p3);
829 		} else {
830 			if (rc < 3)
831 				p2 = WLAN_REASON_QSTA_LEAVE_QBSS;
832 			wmi_delba_tx(wil, txdata->mid, p1, p2);
833 		}
834 	} else if (strcmp(cmd, "del_rx") == 0) {
835 		struct wil_sta_info *sta;
836 
837 		if (rc < 3) {
838 			wil_err(wil,
839 				"BACK: del_rx require at least 2 params\n");
840 			return -EINVAL;
841 		}
842 		if (p1 < 0 || p1 >= wil->max_assoc_sta) {
843 			wil_err(wil, "BACK: invalid CID %d\n", p1);
844 			return -EINVAL;
845 		}
846 		if (rc < 4)
847 			p3 = WLAN_REASON_QSTA_LEAVE_QBSS;
848 		sta = &wil->sta[p1];
849 		wmi_delba_rx(wil, sta->mid, p1, p2, p3);
850 	} else {
851 		wil_err(wil, "BACK: Unrecognized command \"%s\"\n", cmd);
852 		return -EINVAL;
853 	}
854 
855 	return len;
856 }
857 
858 static ssize_t wil_read_back(struct file *file, char __user *user_buf,
859 			     size_t count, loff_t *ppos)
860 {
861 	static const char text[] = "block ack control, write:\n"
862 	" - \"add <ringid> <agg_size> <timeout>\" to trigger ADDBA\n"
863 	"If missing, <timeout> defaults to 0\n"
864 	" - \"del_tx <ringid> <reason>\" to trigger DELBA for Tx side\n"
865 	" - \"del_rx <CID> <TID> <reason>\" to trigger DELBA for Rx side\n"
866 	"If missing, <reason> set to \"STA_LEAVING\" (36)\n";
867 
868 	return simple_read_from_buffer(user_buf, count, ppos, text,
869 				       sizeof(text));
870 }
871 
872 static const struct file_operations fops_back = {
873 	.read = wil_read_back,
874 	.write = wil_write_back,
875 	.open  = simple_open,
876 };
877 
878 /* pmc control, write:
879  * - "alloc <num descriptors> <descriptor_size>" to allocate PMC
880  * - "free" to release memory allocated for PMC
881  */
882 static ssize_t wil_write_pmccfg(struct file *file, const char __user *buf,
883 				size_t len, loff_t *ppos)
884 {
885 	struct wil6210_priv *wil = file->private_data;
886 	int rc;
887 	char *kbuf = kmalloc(len + 1, GFP_KERNEL);
888 	char cmd[9];
889 	int num_descs, desc_size;
890 
891 	if (!kbuf)
892 		return -ENOMEM;
893 
894 	rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
895 	if (rc != len) {
896 		kfree(kbuf);
897 		return rc >= 0 ? -EIO : rc;
898 	}
899 
900 	kbuf[len] = '\0';
901 	rc = sscanf(kbuf, "%8s %d %d", cmd, &num_descs, &desc_size);
902 	kfree(kbuf);
903 
904 	if (rc < 0)
905 		return rc;
906 
907 	if (rc < 1) {
908 		wil_err(wil, "pmccfg: no params given\n");
909 		return -EINVAL;
910 	}
911 
912 	if (0 == strcmp(cmd, "alloc")) {
913 		if (rc != 3) {
914 			wil_err(wil, "pmccfg: alloc requires 2 params\n");
915 			return -EINVAL;
916 		}
917 		wil_pmc_alloc(wil, num_descs, desc_size);
918 	} else if (0 == strcmp(cmd, "free")) {
919 		if (rc != 1) {
920 			wil_err(wil, "pmccfg: free does not have any params\n");
921 			return -EINVAL;
922 		}
923 		wil_pmc_free(wil, true);
924 	} else {
925 		wil_err(wil, "pmccfg: Unrecognized command \"%s\"\n", cmd);
926 		return -EINVAL;
927 	}
928 
929 	return len;
930 }
931 
932 static ssize_t wil_read_pmccfg(struct file *file, char __user *user_buf,
933 			       size_t count, loff_t *ppos)
934 {
935 	struct wil6210_priv *wil = file->private_data;
936 	char text[256];
937 	char help[] = "pmc control, write:\n"
938 	" - \"alloc <num descriptors> <descriptor_size>\" to allocate pmc\n"
939 	" - \"free\" to free memory allocated for pmc\n";
940 
941 	sprintf(text, "Last command status: %d\n\n%s",
942 		wil_pmc_last_cmd_status(wil),
943 		help);
944 
945 	return simple_read_from_buffer(user_buf, count, ppos, text,
946 				       strlen(text) + 1);
947 }
948 
949 static const struct file_operations fops_pmccfg = {
950 	.read = wil_read_pmccfg,
951 	.write = wil_write_pmccfg,
952 	.open  = simple_open,
953 };
954 
955 static const struct file_operations fops_pmcdata = {
956 	.open		= simple_open,
957 	.read		= wil_pmc_read,
958 	.llseek		= wil_pmc_llseek,
959 };
960 
961 /*---tx_mgmt---*/
962 /* Write mgmt frame to this file to send it */
963 static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
964 				     size_t len, loff_t *ppos)
965 {
966 	struct wil6210_priv *wil = file->private_data;
967 	struct wiphy *wiphy = wil_to_wiphy(wil);
968 	struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr;
969 	struct cfg80211_mgmt_tx_params params;
970 	int rc;
971 	void *frame;
972 
973 	memset(&params, 0, sizeof(params));
974 
975 	if (!len)
976 		return -EINVAL;
977 
978 	frame = memdup_user(buf, len);
979 	if (IS_ERR(frame))
980 		return PTR_ERR(frame);
981 
982 	params.buf = frame;
983 	params.len = len;
984 
985 	rc = wil_cfg80211_mgmt_tx(wiphy, wdev, &params, NULL);
986 
987 	kfree(frame);
988 	wil_info(wil, "-> %d\n", rc);
989 
990 	return len;
991 }
992 
993 static const struct file_operations fops_txmgmt = {
994 	.write = wil_write_file_txmgmt,
995 	.open  = simple_open,
996 };
997 
998 /* Write WMI command (w/o mbox header) to this file to send it
999  * WMI starts from wil6210_mbox_hdr_wmi header
1000  */
1001 static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
1002 				  size_t len, loff_t *ppos)
1003 {
1004 	struct wil6210_priv *wil = file->private_data;
1005 	struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
1006 	struct wmi_cmd_hdr *wmi;
1007 	void *cmd;
1008 	int cmdlen = len - sizeof(struct wmi_cmd_hdr);
1009 	u16 cmdid;
1010 	int rc, rc1;
1011 
1012 	if (cmdlen < 0)
1013 		return -EINVAL;
1014 
1015 	wmi = kmalloc(len, GFP_KERNEL);
1016 	if (!wmi)
1017 		return -ENOMEM;
1018 
1019 	rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
1020 	if (rc < 0) {
1021 		kfree(wmi);
1022 		return rc;
1023 	}
1024 
1025 	cmd = (cmdlen > 0) ? &wmi[1] : NULL;
1026 	cmdid = le16_to_cpu(wmi->command_id);
1027 
1028 	rc1 = wmi_send(wil, cmdid, vif->mid, cmd, cmdlen);
1029 	kfree(wmi);
1030 
1031 	wil_info(wil, "0x%04x[%d] -> %d\n", cmdid, cmdlen, rc1);
1032 
1033 	return rc;
1034 }
1035 
1036 static const struct file_operations fops_wmi = {
1037 	.write = wil_write_file_wmi,
1038 	.open  = simple_open,
1039 };
1040 
1041 static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
1042 {
1043 	int i = 0;
1044 	int len = skb_headlen(skb);
1045 	void *p = skb->data;
1046 	int nr_frags = skb_shinfo(skb)->nr_frags;
1047 
1048 	seq_printf(s, "    len = %d\n", len);
1049 	wil_seq_hexdump(s, p, len, "      : ");
1050 
1051 	if (nr_frags) {
1052 		seq_printf(s, "    nr_frags = %d\n", nr_frags);
1053 		for (i = 0; i < nr_frags; i++) {
1054 			const struct skb_frag_struct *frag =
1055 					&skb_shinfo(skb)->frags[i];
1056 
1057 			len = skb_frag_size(frag);
1058 			p = skb_frag_address_safe(frag);
1059 			seq_printf(s, "    [%2d] : len = %d\n", i, len);
1060 			wil_seq_hexdump(s, p, len, "      : ");
1061 		}
1062 	}
1063 }
1064 
1065 /*---------Tx/Rx descriptor------------*/
1066 static int txdesc_show(struct seq_file *s, void *data)
1067 {
1068 	struct wil6210_priv *wil = s->private;
1069 	struct wil_ring *ring;
1070 	bool tx;
1071 	int ring_idx = dbg_ring_index;
1072 	int txdesc_idx = dbg_txdesc_index;
1073 	volatile struct vring_tx_desc *d;
1074 	volatile u32 *u;
1075 	struct sk_buff *skb;
1076 
1077 	if (wil->use_enhanced_dma_hw) {
1078 		/* RX ring index == 0 */
1079 		if (ring_idx >= WIL6210_MAX_TX_RINGS) {
1080 			seq_printf(s, "invalid ring index %d\n", ring_idx);
1081 			return 0;
1082 		}
1083 		tx = ring_idx > 0; /* desc ring 0 is reserved for RX */
1084 	} else {
1085 		/* RX ring index == WIL6210_MAX_TX_RINGS */
1086 		if (ring_idx > WIL6210_MAX_TX_RINGS) {
1087 			seq_printf(s, "invalid ring index %d\n", ring_idx);
1088 			return 0;
1089 		}
1090 		tx = (ring_idx < WIL6210_MAX_TX_RINGS);
1091 	}
1092 
1093 	ring = tx ? &wil->ring_tx[ring_idx] : &wil->ring_rx;
1094 
1095 	if (!ring->va) {
1096 		if (tx)
1097 			seq_printf(s, "No Tx[%2d] RING\n", ring_idx);
1098 		else
1099 			seq_puts(s, "No Rx RING\n");
1100 		return 0;
1101 	}
1102 
1103 	if (txdesc_idx >= ring->size) {
1104 		if (tx)
1105 			seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
1106 				   ring_idx, txdesc_idx, ring->size);
1107 		else
1108 			seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
1109 				   txdesc_idx, ring->size);
1110 		return 0;
1111 	}
1112 
1113 	/* use struct vring_tx_desc for Rx as well,
1114 	 * only field used, .dma.length, is the same
1115 	 */
1116 	d = &ring->va[txdesc_idx].tx.legacy;
1117 	u = (volatile u32 *)d;
1118 	skb = NULL;
1119 
1120 	if (wil->use_enhanced_dma_hw) {
1121 		if (tx) {
1122 			skb = ring->ctx ? ring->ctx[txdesc_idx].skb : NULL;
1123 		} else if (wil->rx_buff_mgmt.buff_arr) {
1124 			struct wil_rx_enhanced_desc *rx_d =
1125 				(struct wil_rx_enhanced_desc *)
1126 				&ring->va[txdesc_idx].rx.enhanced;
1127 			u16 buff_id = le16_to_cpu(rx_d->mac.buff_id);
1128 
1129 			if (!wil_val_in_range(buff_id, 0,
1130 					      wil->rx_buff_mgmt.size))
1131 				seq_printf(s, "invalid buff_id %d\n", buff_id);
1132 			else
1133 				skb = wil->rx_buff_mgmt.buff_arr[buff_id].skb;
1134 		}
1135 	} else {
1136 		skb = ring->ctx[txdesc_idx].skb;
1137 	}
1138 	if (tx)
1139 		seq_printf(s, "Tx[%2d][%3d] = {\n", ring_idx,
1140 			   txdesc_idx);
1141 	else
1142 		seq_printf(s, "Rx[%3d] = {\n", txdesc_idx);
1143 	seq_printf(s, "  MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
1144 		   u[0], u[1], u[2], u[3]);
1145 	seq_printf(s, "  DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
1146 		   u[4], u[5], u[6], u[7]);
1147 	seq_printf(s, "  SKB = 0x%p\n", skb);
1148 
1149 	if (skb) {
1150 		skb_get(skb);
1151 		wil_seq_print_skb(s, skb);
1152 		kfree_skb(skb);
1153 	}
1154 	seq_puts(s, "}\n");
1155 
1156 	return 0;
1157 }
1158 DEFINE_SHOW_ATTRIBUTE(txdesc);
1159 
1160 /*---------Tx/Rx status message------------*/
1161 static int status_msg_show(struct seq_file *s, void *data)
1162 {
1163 	struct wil6210_priv *wil = s->private;
1164 	int sring_idx = dbg_sring_index;
1165 	struct wil_status_ring *sring;
1166 	bool tx;
1167 	u32 status_msg_idx = dbg_status_msg_index;
1168 	u32 *u;
1169 
1170 	if (sring_idx >= WIL6210_MAX_STATUS_RINGS) {
1171 		seq_printf(s, "invalid status ring index %d\n", sring_idx);
1172 		return 0;
1173 	}
1174 
1175 	sring = &wil->srings[sring_idx];
1176 	tx = !sring->is_rx;
1177 
1178 	if (!sring->va) {
1179 		seq_printf(s, "No %cX status ring\n", tx ? 'T' : 'R');
1180 		return 0;
1181 	}
1182 
1183 	if (status_msg_idx >= sring->size) {
1184 		seq_printf(s, "%cxDesc index (%d) >= size (%d)\n",
1185 			   tx ? 'T' : 'R', status_msg_idx, sring->size);
1186 		return 0;
1187 	}
1188 
1189 	u = sring->va + (sring->elem_size * status_msg_idx);
1190 
1191 	seq_printf(s, "%cx[%d][%3d] = {\n",
1192 		   tx ? 'T' : 'R', sring_idx, status_msg_idx);
1193 
1194 	seq_printf(s, "  0x%08x 0x%08x 0x%08x 0x%08x\n",
1195 		   u[0], u[1], u[2], u[3]);
1196 	if (!tx && !wil->use_compressed_rx_status)
1197 		seq_printf(s, "  0x%08x 0x%08x 0x%08x 0x%08x\n",
1198 			   u[4], u[5], u[6], u[7]);
1199 
1200 	seq_puts(s, "}\n");
1201 
1202 	return 0;
1203 }
1204 DEFINE_SHOW_ATTRIBUTE(status_msg);
1205 
1206 static int wil_print_rx_buff(struct seq_file *s, struct list_head *lh)
1207 {
1208 	struct wil_rx_buff *it;
1209 	int i = 0;
1210 
1211 	list_for_each_entry(it, lh, list) {
1212 		if ((i % 16) == 0 && i != 0)
1213 			seq_puts(s, "\n    ");
1214 		seq_printf(s, "[%4d] ", it->id);
1215 		i++;
1216 	}
1217 	seq_printf(s, "\nNumber of buffers: %u\n", i);
1218 
1219 	return i;
1220 }
1221 
1222 static int rx_buff_mgmt_show(struct seq_file *s, void *data)
1223 {
1224 	struct wil6210_priv *wil = s->private;
1225 	struct wil_rx_buff_mgmt *rbm = &wil->rx_buff_mgmt;
1226 	int num_active;
1227 	int num_free;
1228 
1229 	if (!rbm->buff_arr)
1230 		return -EINVAL;
1231 
1232 	seq_printf(s, "  size = %zu\n", rbm->size);
1233 	seq_printf(s, "  free_list_empty_cnt = %lu\n",
1234 		   rbm->free_list_empty_cnt);
1235 
1236 	/* Print active list */
1237 	seq_puts(s, "  Active list:\n");
1238 	num_active = wil_print_rx_buff(s, &rbm->active);
1239 	seq_puts(s, "\n  Free list:\n");
1240 	num_free = wil_print_rx_buff(s, &rbm->free);
1241 
1242 	seq_printf(s, "  Total number of buffers: %u\n",
1243 		   num_active + num_free);
1244 
1245 	return 0;
1246 }
1247 DEFINE_SHOW_ATTRIBUTE(rx_buff_mgmt);
1248 
1249 /*---------beamforming------------*/
1250 static char *wil_bfstatus_str(u32 status)
1251 {
1252 	switch (status) {
1253 	case 0:
1254 		return "Failed";
1255 	case 1:
1256 		return "OK";
1257 	case 2:
1258 		return "Retrying";
1259 	default:
1260 		return "??";
1261 	}
1262 }
1263 
1264 static bool is_all_zeros(void * const x_, size_t sz)
1265 {
1266 	/* if reply is all-0, ignore this CID */
1267 	u32 *x = x_;
1268 	int n;
1269 
1270 	for (n = 0; n < sz / sizeof(*x); n++)
1271 		if (x[n])
1272 			return false;
1273 
1274 	return true;
1275 }
1276 
1277 static int bf_show(struct seq_file *s, void *data)
1278 {
1279 	int rc;
1280 	int i;
1281 	struct wil6210_priv *wil = s->private;
1282 	struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
1283 	struct wmi_notify_req_cmd cmd = {
1284 		.interval_usec = 0,
1285 	};
1286 	struct {
1287 		struct wmi_cmd_hdr wmi;
1288 		struct wmi_notify_req_done_event evt;
1289 	} __packed reply;
1290 
1291 	memset(&reply, 0, sizeof(reply));
1292 
1293 	for (i = 0; i < wil->max_assoc_sta; i++) {
1294 		u32 status;
1295 
1296 		cmd.cid = i;
1297 		rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, vif->mid,
1298 			      &cmd, sizeof(cmd),
1299 			      WMI_NOTIFY_REQ_DONE_EVENTID, &reply,
1300 			      sizeof(reply), 20);
1301 		/* if reply is all-0, ignore this CID */
1302 		if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt)))
1303 			continue;
1304 
1305 		status = le32_to_cpu(reply.evt.status);
1306 		seq_printf(s, "CID %d {\n"
1307 			   "  TSF = 0x%016llx\n"
1308 			   "  TxMCS = %2d TxTpt = %4d\n"
1309 			   "  SQI = %4d\n"
1310 			   "  RSSI = %4d\n"
1311 			   "  Status = 0x%08x %s\n"
1312 			   "  Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
1313 			   "  Goodput(rx:tx) %4d:%4d\n"
1314 			   "}\n",
1315 			   i,
1316 			   le64_to_cpu(reply.evt.tsf),
1317 			   le16_to_cpu(reply.evt.bf_mcs),
1318 			   le32_to_cpu(reply.evt.tx_tpt),
1319 			   reply.evt.sqi,
1320 			   reply.evt.rssi,
1321 			   status, wil_bfstatus_str(status),
1322 			   le16_to_cpu(reply.evt.my_rx_sector),
1323 			   le16_to_cpu(reply.evt.my_tx_sector),
1324 			   le16_to_cpu(reply.evt.other_rx_sector),
1325 			   le16_to_cpu(reply.evt.other_tx_sector),
1326 			   le32_to_cpu(reply.evt.rx_goodput),
1327 			   le32_to_cpu(reply.evt.tx_goodput));
1328 	}
1329 	return 0;
1330 }
1331 DEFINE_SHOW_ATTRIBUTE(bf);
1332 
1333 /*---------temp------------*/
1334 static void print_temp(struct seq_file *s, const char *prefix, s32 t)
1335 {
1336 	switch (t) {
1337 	case 0:
1338 	case ~(u32)0:
1339 		seq_printf(s, "%s N/A\n", prefix);
1340 	break;
1341 	default:
1342 		seq_printf(s, "%s %s%d.%03d\n", prefix, (t < 0 ? "-" : ""),
1343 			   abs(t / 1000), abs(t % 1000));
1344 		break;
1345 	}
1346 }
1347 
1348 static int temp_show(struct seq_file *s, void *data)
1349 {
1350 	struct wil6210_priv *wil = s->private;
1351 	s32 t_m, t_r;
1352 	int rc = wmi_get_temperature(wil, &t_m, &t_r);
1353 
1354 	if (rc) {
1355 		seq_puts(s, "Failed\n");
1356 		return 0;
1357 	}
1358 
1359 	print_temp(s, "T_mac   =", t_m);
1360 	print_temp(s, "T_radio =", t_r);
1361 
1362 	return 0;
1363 }
1364 DEFINE_SHOW_ATTRIBUTE(temp);
1365 
1366 /*---------freq------------*/
1367 static int freq_show(struct seq_file *s, void *data)
1368 {
1369 	struct wil6210_priv *wil = s->private;
1370 	struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr;
1371 	u32 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
1372 
1373 	seq_printf(s, "Freq = %d\n", freq);
1374 
1375 	return 0;
1376 }
1377 DEFINE_SHOW_ATTRIBUTE(freq);
1378 
1379 /*---------link------------*/
1380 static int link_show(struct seq_file *s, void *data)
1381 {
1382 	struct wil6210_priv *wil = s->private;
1383 	struct station_info *sinfo;
1384 	int i, rc = 0;
1385 
1386 	sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL);
1387 	if (!sinfo)
1388 		return -ENOMEM;
1389 
1390 	for (i = 0; i < wil->max_assoc_sta; i++) {
1391 		struct wil_sta_info *p = &wil->sta[i];
1392 		char *status = "unknown";
1393 		struct wil6210_vif *vif;
1394 		u8 mid;
1395 
1396 		switch (p->status) {
1397 		case wil_sta_unused:
1398 			status = "unused   ";
1399 			break;
1400 		case wil_sta_conn_pending:
1401 			status = "pending  ";
1402 			break;
1403 		case wil_sta_connected:
1404 			status = "connected";
1405 			break;
1406 		}
1407 		mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
1408 		seq_printf(s, "[%d][MID %d] %pM %s\n",
1409 			   i, mid, p->addr, status);
1410 
1411 		if (p->status != wil_sta_connected)
1412 			continue;
1413 
1414 		vif = (mid < GET_MAX_VIFS(wil)) ? wil->vifs[mid] : NULL;
1415 		if (vif) {
1416 			rc = wil_cid_fill_sinfo(vif, i, sinfo);
1417 			if (rc)
1418 				goto out;
1419 
1420 			seq_printf(s, "  Tx_mcs = %d\n", sinfo->txrate.mcs);
1421 			seq_printf(s, "  Rx_mcs = %d\n", sinfo->rxrate.mcs);
1422 			seq_printf(s, "  SQ     = %d\n", sinfo->signal);
1423 		} else {
1424 			seq_puts(s, "  INVALID MID\n");
1425 		}
1426 	}
1427 
1428 out:
1429 	kfree(sinfo);
1430 	return rc;
1431 }
1432 DEFINE_SHOW_ATTRIBUTE(link);
1433 
1434 /*---------info------------*/
1435 static int info_show(struct seq_file *s, void *data)
1436 {
1437 	struct wil6210_priv *wil = s->private;
1438 	struct net_device *ndev = wil->main_ndev;
1439 	int is_ac = power_supply_is_system_supplied();
1440 	int rx = atomic_xchg(&wil->isr_count_rx, 0);
1441 	int tx = atomic_xchg(&wil->isr_count_tx, 0);
1442 	static ulong rxf_old, txf_old;
1443 	ulong rxf = ndev->stats.rx_packets;
1444 	ulong txf = ndev->stats.tx_packets;
1445 	unsigned int i;
1446 
1447 	/* >0 : AC; 0 : battery; <0 : error */
1448 	seq_printf(s, "AC powered : %d\n", is_ac);
1449 	seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
1450 	seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
1451 	rxf_old = rxf;
1452 	txf_old = txf;
1453 
1454 #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
1455 	" " __stringify(x) : ""
1456 
1457 	for (i = 0; i < ndev->num_tx_queues; i++) {
1458 		struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
1459 		unsigned long state = txq->state;
1460 
1461 		seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
1462 			   CHECK_QSTATE(DRV_XOFF),
1463 			   CHECK_QSTATE(STACK_XOFF),
1464 			   CHECK_QSTATE(FROZEN)
1465 			  );
1466 	}
1467 #undef CHECK_QSTATE
1468 	return 0;
1469 }
1470 DEFINE_SHOW_ATTRIBUTE(info);
1471 
1472 /*---------recovery------------*/
1473 /* mode = [manual|auto]
1474  * state = [idle|pending|running]
1475  */
1476 static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf,
1477 				      size_t count, loff_t *ppos)
1478 {
1479 	struct wil6210_priv *wil = file->private_data;
1480 	char buf[80];
1481 	int n;
1482 	static const char * const sstate[] = {"idle", "pending", "running"};
1483 
1484 	n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n",
1485 		     no_fw_recovery ? "manual" : "auto",
1486 		     sstate[wil->recovery_state]);
1487 
1488 	n = min_t(int, n, sizeof(buf));
1489 
1490 	return simple_read_from_buffer(user_buf, count, ppos,
1491 				       buf, n);
1492 }
1493 
1494 static ssize_t wil_write_file_recovery(struct file *file,
1495 				       const char __user *buf_,
1496 				       size_t count, loff_t *ppos)
1497 {
1498 	struct wil6210_priv *wil = file->private_data;
1499 	static const char run_command[] = "run";
1500 	char buf[sizeof(run_command) + 1]; /* to detect "runx" */
1501 	ssize_t rc;
1502 
1503 	if (wil->recovery_state != fw_recovery_pending) {
1504 		wil_err(wil, "No recovery pending\n");
1505 		return -EINVAL;
1506 	}
1507 
1508 	if (*ppos != 0) {
1509 		wil_err(wil, "Offset [%d]\n", (int)*ppos);
1510 		return -EINVAL;
1511 	}
1512 
1513 	if (count > sizeof(buf)) {
1514 		wil_err(wil, "Input too long, len = %d\n", (int)count);
1515 		return -EINVAL;
1516 	}
1517 
1518 	rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count);
1519 	if (rc < 0)
1520 		return rc;
1521 
1522 	buf[rc] = '\0';
1523 	if (0 == strcmp(buf, run_command))
1524 		wil_set_recovery_state(wil, fw_recovery_running);
1525 	else
1526 		wil_err(wil, "Bad recovery command \"%s\"\n", buf);
1527 
1528 	return rc;
1529 }
1530 
1531 static const struct file_operations fops_recovery = {
1532 	.read = wil_read_file_recovery,
1533 	.write = wil_write_file_recovery,
1534 	.open  = simple_open,
1535 };
1536 
1537 /*---------Station matrix------------*/
1538 static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
1539 {
1540 	int i;
1541 	u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
1542 	unsigned long long drop_dup = r->drop_dup, drop_old = r->drop_old;
1543 	unsigned long long drop_dup_mcast = r->drop_dup_mcast;
1544 
1545 	seq_printf(s, "([%2d]) 0x%03x [", r->buf_size, r->head_seq_num);
1546 	for (i = 0; i < r->buf_size; i++) {
1547 		if (i == index)
1548 			seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
1549 		else
1550 			seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
1551 	}
1552 	seq_printf(s,
1553 		   "] total %llu drop %llu (dup %llu + old %llu + dup mcast %llu) last 0x%03x\n",
1554 		   r->total, drop_dup + drop_old + drop_dup_mcast, drop_dup,
1555 		   drop_old, drop_dup_mcast, r->ssn_last_drop);
1556 }
1557 
1558 static void wil_print_rxtid_crypto(struct seq_file *s, int tid,
1559 				   struct wil_tid_crypto_rx *c)
1560 {
1561 	int i;
1562 
1563 	for (i = 0; i < 4; i++) {
1564 		struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
1565 
1566 		if (cc->key_set)
1567 			goto has_keys;
1568 	}
1569 	return;
1570 
1571 has_keys:
1572 	if (tid < WIL_STA_TID_NUM)
1573 		seq_printf(s, "  [%2d] PN", tid);
1574 	else
1575 		seq_puts(s, "  [GR] PN");
1576 
1577 	for (i = 0; i < 4; i++) {
1578 		struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
1579 
1580 		seq_printf(s, " [%i%s]%6phN", i, cc->key_set ? "+" : "-",
1581 			   cc->pn);
1582 	}
1583 	seq_puts(s, "\n");
1584 }
1585 
1586 static int sta_show(struct seq_file *s, void *data)
1587 __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
1588 {
1589 	struct wil6210_priv *wil = s->private;
1590 	int i, tid, mcs;
1591 
1592 	for (i = 0; i < wil->max_assoc_sta; i++) {
1593 		struct wil_sta_info *p = &wil->sta[i];
1594 		char *status = "unknown";
1595 		u8 aid = 0;
1596 		u8 mid;
1597 		bool sta_connected = false;
1598 
1599 		switch (p->status) {
1600 		case wil_sta_unused:
1601 			status = "unused   ";
1602 			break;
1603 		case wil_sta_conn_pending:
1604 			status = "pending  ";
1605 			break;
1606 		case wil_sta_connected:
1607 			status = "connected";
1608 			aid = p->aid;
1609 			break;
1610 		}
1611 		mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
1612 		if (mid < GET_MAX_VIFS(wil)) {
1613 			struct wil6210_vif *vif = wil->vifs[mid];
1614 
1615 			if (vif->wdev.iftype == NL80211_IFTYPE_STATION &&
1616 			    p->status == wil_sta_connected)
1617 				sta_connected = true;
1618 		}
1619 		/* print roam counter only for connected stations */
1620 		if (sta_connected)
1621 			seq_printf(s, "[%d] %pM connected (roam counter %d) MID %d AID %d\n",
1622 				   i, p->addr, p->stats.ft_roams, mid, aid);
1623 		else
1624 			seq_printf(s, "[%d] %pM %s MID %d AID %d\n", i,
1625 				   p->addr, status, mid, aid);
1626 
1627 		if (p->status == wil_sta_connected) {
1628 			spin_lock_bh(&p->tid_rx_lock);
1629 			for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1630 				struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
1631 				struct wil_tid_crypto_rx *c =
1632 						&p->tid_crypto_rx[tid];
1633 
1634 				if (r) {
1635 					seq_printf(s, "  [%2d] ", tid);
1636 					wil_print_rxtid(s, r);
1637 				}
1638 
1639 				wil_print_rxtid_crypto(s, tid, c);
1640 			}
1641 			wil_print_rxtid_crypto(s, WIL_STA_TID_NUM,
1642 					       &p->group_crypto_rx);
1643 			spin_unlock_bh(&p->tid_rx_lock);
1644 			seq_printf(s,
1645 				   "Rx invalid frame: non-data %lu, short %lu, large %lu, replay %lu\n",
1646 				   p->stats.rx_non_data_frame,
1647 				   p->stats.rx_short_frame,
1648 				   p->stats.rx_large_frame,
1649 				   p->stats.rx_replay);
1650 			seq_printf(s,
1651 				   "mic error %lu, key error %lu, amsdu error %lu, csum error %lu\n",
1652 				   p->stats.rx_mic_error,
1653 				   p->stats.rx_key_error,
1654 				   p->stats.rx_amsdu_error,
1655 				   p->stats.rx_csum_err);
1656 
1657 			seq_puts(s, "Rx/MCS:");
1658 			for (mcs = 0; mcs < ARRAY_SIZE(p->stats.rx_per_mcs);
1659 			     mcs++)
1660 				seq_printf(s, " %lld",
1661 					   p->stats.rx_per_mcs[mcs]);
1662 			seq_puts(s, "\n");
1663 		}
1664 	}
1665 
1666 	return 0;
1667 }
1668 DEFINE_SHOW_ATTRIBUTE(sta);
1669 
1670 static int mids_show(struct seq_file *s, void *data)
1671 {
1672 	struct wil6210_priv *wil = s->private;
1673 	struct wil6210_vif *vif;
1674 	struct net_device *ndev;
1675 	int i;
1676 
1677 	mutex_lock(&wil->vif_mutex);
1678 	for (i = 0; i < GET_MAX_VIFS(wil); i++) {
1679 		vif = wil->vifs[i];
1680 
1681 		if (vif) {
1682 			ndev = vif_to_ndev(vif);
1683 			seq_printf(s, "[%d] %pM %s\n", i, ndev->dev_addr,
1684 				   ndev->name);
1685 		} else {
1686 			seq_printf(s, "[%d] unused\n", i);
1687 		}
1688 	}
1689 	mutex_unlock(&wil->vif_mutex);
1690 
1691 	return 0;
1692 }
1693 DEFINE_SHOW_ATTRIBUTE(mids);
1694 
1695 static int wil_tx_latency_debugfs_show(struct seq_file *s, void *data)
1696 __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
1697 {
1698 	struct wil6210_priv *wil = s->private;
1699 	int i, bin;
1700 
1701 	for (i = 0; i < wil->max_assoc_sta; i++) {
1702 		struct wil_sta_info *p = &wil->sta[i];
1703 		char *status = "unknown";
1704 		u8 aid = 0;
1705 		u8 mid;
1706 
1707 		if (!p->tx_latency_bins)
1708 			continue;
1709 
1710 		switch (p->status) {
1711 		case wil_sta_unused:
1712 			status = "unused   ";
1713 			break;
1714 		case wil_sta_conn_pending:
1715 			status = "pending  ";
1716 			break;
1717 		case wil_sta_connected:
1718 			status = "connected";
1719 			aid = p->aid;
1720 			break;
1721 		}
1722 		mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
1723 		seq_printf(s, "[%d] %pM %s MID %d AID %d\n", i, p->addr, status,
1724 			   mid, aid);
1725 
1726 		if (p->status == wil_sta_connected) {
1727 			u64 num_packets = 0;
1728 			u64 tx_latency_avg = p->stats.tx_latency_total_us;
1729 
1730 			seq_puts(s, "Tx/Latency bin:");
1731 			for (bin = 0; bin < WIL_NUM_LATENCY_BINS; bin++) {
1732 				seq_printf(s, " %lld",
1733 					   p->tx_latency_bins[bin]);
1734 				num_packets += p->tx_latency_bins[bin];
1735 			}
1736 			seq_puts(s, "\n");
1737 			if (!num_packets)
1738 				continue;
1739 			do_div(tx_latency_avg, num_packets);
1740 			seq_printf(s, "Tx/Latency min/avg/max (us): %d/%lld/%d",
1741 				   p->stats.tx_latency_min_us,
1742 				   tx_latency_avg,
1743 				   p->stats.tx_latency_max_us);
1744 
1745 			seq_puts(s, "\n");
1746 		}
1747 	}
1748 
1749 	return 0;
1750 }
1751 
1752 static int wil_tx_latency_seq_open(struct inode *inode, struct file *file)
1753 {
1754 	return single_open(file, wil_tx_latency_debugfs_show,
1755 			   inode->i_private);
1756 }
1757 
1758 static ssize_t wil_tx_latency_write(struct file *file, const char __user *buf,
1759 				    size_t len, loff_t *ppos)
1760 {
1761 	struct seq_file *s = file->private_data;
1762 	struct wil6210_priv *wil = s->private;
1763 	int val, rc, i;
1764 	bool enable;
1765 
1766 	rc = kstrtoint_from_user(buf, len, 0, &val);
1767 	if (rc) {
1768 		wil_err(wil, "Invalid argument\n");
1769 		return rc;
1770 	}
1771 	if (val == 1)
1772 		/* default resolution */
1773 		val = 500;
1774 	if (val && (val < 50 || val > 1000)) {
1775 		wil_err(wil, "Invalid resolution %d\n", val);
1776 		return -EINVAL;
1777 	}
1778 
1779 	enable = !!val;
1780 	if (wil->tx_latency == enable)
1781 		return len;
1782 
1783 	wil_info(wil, "%s TX latency measurements (resolution %dusec)\n",
1784 		 enable ? "Enabling" : "Disabling", val);
1785 
1786 	if (enable) {
1787 		size_t sz = sizeof(u64) * WIL_NUM_LATENCY_BINS;
1788 
1789 		wil->tx_latency_res = val;
1790 		for (i = 0; i < wil->max_assoc_sta; i++) {
1791 			struct wil_sta_info *sta = &wil->sta[i];
1792 
1793 			kfree(sta->tx_latency_bins);
1794 			sta->tx_latency_bins = kzalloc(sz, GFP_KERNEL);
1795 			if (!sta->tx_latency_bins)
1796 				return -ENOMEM;
1797 			sta->stats.tx_latency_min_us = U32_MAX;
1798 			sta->stats.tx_latency_max_us = 0;
1799 			sta->stats.tx_latency_total_us = 0;
1800 		}
1801 	}
1802 	wil->tx_latency = enable;
1803 
1804 	return len;
1805 }
1806 
1807 static const struct file_operations fops_tx_latency = {
1808 	.open		= wil_tx_latency_seq_open,
1809 	.release	= single_release,
1810 	.read		= seq_read,
1811 	.write		= wil_tx_latency_write,
1812 	.llseek		= seq_lseek,
1813 };
1814 
1815 static void wil_link_stats_print_basic(struct wil6210_vif *vif,
1816 				       struct seq_file *s,
1817 				       struct wmi_link_stats_basic *basic)
1818 {
1819 	char per[5] = "?";
1820 
1821 	if (basic->per_average != 0xff)
1822 		snprintf(per, sizeof(per), "%d%%", basic->per_average);
1823 
1824 	seq_printf(s, "CID %d {\n"
1825 		   "\tTxMCS %d TxTpt %d\n"
1826 		   "\tGoodput(rx:tx) %d:%d\n"
1827 		   "\tRxBcastFrames %d\n"
1828 		   "\tRSSI %d SQI %d SNR %d PER %s\n"
1829 		   "\tRx RFC %d Ant num %d\n"
1830 		   "\tSectors(rx:tx) my %d:%d peer %d:%d\n"
1831 		   "}\n",
1832 		   basic->cid,
1833 		   basic->bf_mcs, le32_to_cpu(basic->tx_tpt),
1834 		   le32_to_cpu(basic->rx_goodput),
1835 		   le32_to_cpu(basic->tx_goodput),
1836 		   le32_to_cpu(basic->rx_bcast_frames),
1837 		   basic->rssi, basic->sqi, basic->snr, per,
1838 		   basic->selected_rfc, basic->rx_effective_ant_num,
1839 		   basic->my_rx_sector, basic->my_tx_sector,
1840 		   basic->other_rx_sector, basic->other_tx_sector);
1841 }
1842 
1843 static void wil_link_stats_print_global(struct wil6210_priv *wil,
1844 					struct seq_file *s,
1845 					struct wmi_link_stats_global *global)
1846 {
1847 	seq_printf(s, "Frames(rx:tx) %d:%d\n"
1848 		   "BA Frames(rx:tx) %d:%d\n"
1849 		   "Beacons %d\n"
1850 		   "Rx Errors (MIC:CRC) %d:%d\n"
1851 		   "Tx Errors (no ack) %d\n",
1852 		   le32_to_cpu(global->rx_frames),
1853 		   le32_to_cpu(global->tx_frames),
1854 		   le32_to_cpu(global->rx_ba_frames),
1855 		   le32_to_cpu(global->tx_ba_frames),
1856 		   le32_to_cpu(global->tx_beacons),
1857 		   le32_to_cpu(global->rx_mic_errors),
1858 		   le32_to_cpu(global->rx_crc_errors),
1859 		   le32_to_cpu(global->tx_fail_no_ack));
1860 }
1861 
1862 static void wil_link_stats_debugfs_show_vif(struct wil6210_vif *vif,
1863 					    struct seq_file *s)
1864 {
1865 	struct wil6210_priv *wil = vif_to_wil(vif);
1866 	struct wmi_link_stats_basic *stats;
1867 	int i;
1868 
1869 	if (!vif->fw_stats_ready) {
1870 		seq_puts(s, "no statistics\n");
1871 		return;
1872 	}
1873 
1874 	seq_printf(s, "TSF %lld\n", vif->fw_stats_tsf);
1875 	for (i = 0; i < wil->max_assoc_sta; i++) {
1876 		if (wil->sta[i].status == wil_sta_unused)
1877 			continue;
1878 		if (wil->sta[i].mid != vif->mid)
1879 			continue;
1880 
1881 		stats = &wil->sta[i].fw_stats_basic;
1882 		wil_link_stats_print_basic(vif, s, stats);
1883 	}
1884 }
1885 
1886 static int wil_link_stats_debugfs_show(struct seq_file *s, void *data)
1887 {
1888 	struct wil6210_priv *wil = s->private;
1889 	struct wil6210_vif *vif;
1890 	int i, rc;
1891 
1892 	rc = mutex_lock_interruptible(&wil->vif_mutex);
1893 	if (rc)
1894 		return rc;
1895 
1896 	/* iterate over all MIDs and show per-cid statistics. Then show the
1897 	 * global statistics
1898 	 */
1899 	for (i = 0; i < GET_MAX_VIFS(wil); i++) {
1900 		vif = wil->vifs[i];
1901 
1902 		seq_printf(s, "MID %d ", i);
1903 		if (!vif) {
1904 			seq_puts(s, "unused\n");
1905 			continue;
1906 		}
1907 
1908 		wil_link_stats_debugfs_show_vif(vif, s);
1909 	}
1910 
1911 	mutex_unlock(&wil->vif_mutex);
1912 
1913 	return 0;
1914 }
1915 
1916 static int wil_link_stats_seq_open(struct inode *inode, struct file *file)
1917 {
1918 	return single_open(file, wil_link_stats_debugfs_show, inode->i_private);
1919 }
1920 
1921 static ssize_t wil_link_stats_write(struct file *file, const char __user *buf,
1922 				    size_t len, loff_t *ppos)
1923 {
1924 	struct seq_file *s = file->private_data;
1925 	struct wil6210_priv *wil = s->private;
1926 	int cid, interval, rc, i;
1927 	struct wil6210_vif *vif;
1928 	char *kbuf = kmalloc(len + 1, GFP_KERNEL);
1929 
1930 	if (!kbuf)
1931 		return -ENOMEM;
1932 
1933 	rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
1934 	if (rc != len) {
1935 		kfree(kbuf);
1936 		return rc >= 0 ? -EIO : rc;
1937 	}
1938 
1939 	kbuf[len] = '\0';
1940 	/* specify cid (use -1 for all cids) and snapshot interval in ms */
1941 	rc = sscanf(kbuf, "%d %d", &cid, &interval);
1942 	kfree(kbuf);
1943 	if (rc < 0)
1944 		return rc;
1945 	if (rc < 2 || interval < 0)
1946 		return -EINVAL;
1947 
1948 	wil_info(wil, "request link statistics, cid %d interval %d\n",
1949 		 cid, interval);
1950 
1951 	rc = mutex_lock_interruptible(&wil->vif_mutex);
1952 	if (rc)
1953 		return rc;
1954 
1955 	for (i = 0; i < GET_MAX_VIFS(wil); i++) {
1956 		vif = wil->vifs[i];
1957 		if (!vif)
1958 			continue;
1959 
1960 		rc = wmi_link_stats_cfg(vif, WMI_LINK_STATS_TYPE_BASIC,
1961 					(cid == -1 ? 0xff : cid), interval);
1962 		if (rc)
1963 			wil_err(wil, "link statistics failed for mid %d\n", i);
1964 	}
1965 	mutex_unlock(&wil->vif_mutex);
1966 
1967 	return len;
1968 }
1969 
1970 static const struct file_operations fops_link_stats = {
1971 	.open		= wil_link_stats_seq_open,
1972 	.release	= single_release,
1973 	.read		= seq_read,
1974 	.write		= wil_link_stats_write,
1975 	.llseek		= seq_lseek,
1976 };
1977 
1978 static int
1979 wil_link_stats_global_debugfs_show(struct seq_file *s, void *data)
1980 {
1981 	struct wil6210_priv *wil = s->private;
1982 
1983 	if (!wil->fw_stats_global.ready)
1984 		return 0;
1985 
1986 	seq_printf(s, "TSF %lld\n", wil->fw_stats_global.tsf);
1987 	wil_link_stats_print_global(wil, s, &wil->fw_stats_global.stats);
1988 
1989 	return 0;
1990 }
1991 
1992 static int
1993 wil_link_stats_global_seq_open(struct inode *inode, struct file *file)
1994 {
1995 	return single_open(file, wil_link_stats_global_debugfs_show,
1996 			   inode->i_private);
1997 }
1998 
1999 static ssize_t
2000 wil_link_stats_global_write(struct file *file, const char __user *buf,
2001 			    size_t len, loff_t *ppos)
2002 {
2003 	struct seq_file *s = file->private_data;
2004 	struct wil6210_priv *wil = s->private;
2005 	int interval, rc;
2006 	struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
2007 
2008 	/* specify snapshot interval in ms */
2009 	rc = kstrtoint_from_user(buf, len, 0, &interval);
2010 	if (rc || interval < 0) {
2011 		wil_err(wil, "Invalid argument\n");
2012 		return -EINVAL;
2013 	}
2014 
2015 	wil_info(wil, "request global link stats, interval %d\n", interval);
2016 
2017 	rc = wmi_link_stats_cfg(vif, WMI_LINK_STATS_TYPE_GLOBAL, 0, interval);
2018 	if (rc)
2019 		wil_err(wil, "global link stats failed %d\n", rc);
2020 
2021 	return rc ? rc : len;
2022 }
2023 
2024 static const struct file_operations fops_link_stats_global = {
2025 	.open		= wil_link_stats_global_seq_open,
2026 	.release	= single_release,
2027 	.read		= seq_read,
2028 	.write		= wil_link_stats_global_write,
2029 	.llseek		= seq_lseek,
2030 };
2031 
2032 static ssize_t wil_read_file_led_cfg(struct file *file, char __user *user_buf,
2033 				     size_t count, loff_t *ppos)
2034 {
2035 	char buf[80];
2036 	int n;
2037 
2038 	n = snprintf(buf, sizeof(buf),
2039 		     "led_id is set to %d, echo 1 to enable, 0 to disable\n",
2040 		     led_id);
2041 
2042 	n = min_t(int, n, sizeof(buf));
2043 
2044 	return simple_read_from_buffer(user_buf, count, ppos,
2045 				       buf, n);
2046 }
2047 
2048 static ssize_t wil_write_file_led_cfg(struct file *file,
2049 				      const char __user *buf_,
2050 				      size_t count, loff_t *ppos)
2051 {
2052 	struct wil6210_priv *wil = file->private_data;
2053 	int val;
2054 	int rc;
2055 
2056 	rc = kstrtoint_from_user(buf_, count, 0, &val);
2057 	if (rc) {
2058 		wil_err(wil, "Invalid argument\n");
2059 		return rc;
2060 	}
2061 
2062 	wil_info(wil, "%s led %d\n", val ? "Enabling" : "Disabling", led_id);
2063 	rc = wmi_led_cfg(wil, val);
2064 	if (rc) {
2065 		wil_info(wil, "%s led %d failed\n",
2066 			 val ? "Enabling" : "Disabling", led_id);
2067 		return rc;
2068 	}
2069 
2070 	return count;
2071 }
2072 
2073 static const struct file_operations fops_led_cfg = {
2074 	.read = wil_read_file_led_cfg,
2075 	.write = wil_write_file_led_cfg,
2076 	.open  = simple_open,
2077 };
2078 
2079 /* led_blink_time, write:
2080  * "<blink_on_slow> <blink_off_slow> <blink_on_med> <blink_off_med> <blink_on_fast> <blink_off_fast>
2081  */
2082 static ssize_t wil_write_led_blink_time(struct file *file,
2083 					const char __user *buf,
2084 					size_t len, loff_t *ppos)
2085 {
2086 	int rc;
2087 	char *kbuf = kmalloc(len + 1, GFP_KERNEL);
2088 
2089 	if (!kbuf)
2090 		return -ENOMEM;
2091 
2092 	rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
2093 	if (rc != len) {
2094 		kfree(kbuf);
2095 		return rc >= 0 ? -EIO : rc;
2096 	}
2097 
2098 	kbuf[len] = '\0';
2099 	rc = sscanf(kbuf, "%d %d %d %d %d %d",
2100 		    &led_blink_time[WIL_LED_TIME_SLOW].on_ms,
2101 		    &led_blink_time[WIL_LED_TIME_SLOW].off_ms,
2102 		    &led_blink_time[WIL_LED_TIME_MED].on_ms,
2103 		    &led_blink_time[WIL_LED_TIME_MED].off_ms,
2104 		    &led_blink_time[WIL_LED_TIME_FAST].on_ms,
2105 		    &led_blink_time[WIL_LED_TIME_FAST].off_ms);
2106 	kfree(kbuf);
2107 
2108 	if (rc < 0)
2109 		return rc;
2110 	if (rc < 6)
2111 		return -EINVAL;
2112 
2113 	return len;
2114 }
2115 
2116 static ssize_t wil_read_led_blink_time(struct file *file, char __user *user_buf,
2117 				       size_t count, loff_t *ppos)
2118 {
2119 	static char text[400];
2120 
2121 	snprintf(text, sizeof(text),
2122 		 "To set led blink on/off time variables write:\n"
2123 		 "<blink_on_slow> <blink_off_slow> <blink_on_med> "
2124 		 "<blink_off_med> <blink_on_fast> <blink_off_fast>\n"
2125 		 "The current values are:\n"
2126 		 "%d %d %d %d %d %d\n",
2127 		 led_blink_time[WIL_LED_TIME_SLOW].on_ms,
2128 		 led_blink_time[WIL_LED_TIME_SLOW].off_ms,
2129 		 led_blink_time[WIL_LED_TIME_MED].on_ms,
2130 		 led_blink_time[WIL_LED_TIME_MED].off_ms,
2131 		 led_blink_time[WIL_LED_TIME_FAST].on_ms,
2132 		 led_blink_time[WIL_LED_TIME_FAST].off_ms);
2133 
2134 	return simple_read_from_buffer(user_buf, count, ppos, text,
2135 				       sizeof(text));
2136 }
2137 
2138 static const struct file_operations fops_led_blink_time = {
2139 	.read = wil_read_led_blink_time,
2140 	.write = wil_write_led_blink_time,
2141 	.open  = simple_open,
2142 };
2143 
2144 /*---------FW capabilities------------*/
2145 static int wil_fw_capabilities_debugfs_show(struct seq_file *s, void *data)
2146 {
2147 	struct wil6210_priv *wil = s->private;
2148 
2149 	seq_printf(s, "fw_capabilities : %*pb\n", WMI_FW_CAPABILITY_MAX,
2150 		   wil->fw_capabilities);
2151 
2152 	return 0;
2153 }
2154 
2155 static int wil_fw_capabilities_seq_open(struct inode *inode, struct file *file)
2156 {
2157 	return single_open(file, wil_fw_capabilities_debugfs_show,
2158 			   inode->i_private);
2159 }
2160 
2161 static const struct file_operations fops_fw_capabilities = {
2162 	.open		= wil_fw_capabilities_seq_open,
2163 	.release	= single_release,
2164 	.read		= seq_read,
2165 	.llseek		= seq_lseek,
2166 };
2167 
2168 /*---------FW version------------*/
2169 static int wil_fw_version_debugfs_show(struct seq_file *s, void *data)
2170 {
2171 	struct wil6210_priv *wil = s->private;
2172 
2173 	if (wil->fw_version[0])
2174 		seq_printf(s, "%s\n", wil->fw_version);
2175 	else
2176 		seq_puts(s, "N/A\n");
2177 
2178 	return 0;
2179 }
2180 
2181 static int wil_fw_version_seq_open(struct inode *inode, struct file *file)
2182 {
2183 	return single_open(file, wil_fw_version_debugfs_show,
2184 			   inode->i_private);
2185 }
2186 
2187 static const struct file_operations fops_fw_version = {
2188 	.open		= wil_fw_version_seq_open,
2189 	.release	= single_release,
2190 	.read		= seq_read,
2191 	.llseek		= seq_lseek,
2192 };
2193 
2194 /*---------suspend_stats---------*/
2195 static ssize_t wil_write_suspend_stats(struct file *file,
2196 				       const char __user *buf,
2197 				       size_t len, loff_t *ppos)
2198 {
2199 	struct wil6210_priv *wil = file->private_data;
2200 
2201 	memset(&wil->suspend_stats, 0, sizeof(wil->suspend_stats));
2202 
2203 	return len;
2204 }
2205 
2206 static ssize_t wil_read_suspend_stats(struct file *file,
2207 				      char __user *user_buf,
2208 				      size_t count, loff_t *ppos)
2209 {
2210 	struct wil6210_priv *wil = file->private_data;
2211 	char *text;
2212 	int n, ret, text_size = 500;
2213 
2214 	text = kmalloc(text_size, GFP_KERNEL);
2215 	if (!text)
2216 		return -ENOMEM;
2217 
2218 	n = snprintf(text, text_size,
2219 		     "Radio on suspend statistics:\n"
2220 		     "successful suspends:%ld failed suspends:%ld\n"
2221 		     "successful resumes:%ld failed resumes:%ld\n"
2222 		     "rejected by device:%ld\n"
2223 		     "Radio off suspend statistics:\n"
2224 		     "successful suspends:%ld failed suspends:%ld\n"
2225 		     "successful resumes:%ld failed resumes:%ld\n"
2226 		     "General statistics:\n"
2227 		     "rejected by host:%ld\n",
2228 		     wil->suspend_stats.r_on.successful_suspends,
2229 		     wil->suspend_stats.r_on.failed_suspends,
2230 		     wil->suspend_stats.r_on.successful_resumes,
2231 		     wil->suspend_stats.r_on.failed_resumes,
2232 		     wil->suspend_stats.rejected_by_device,
2233 		     wil->suspend_stats.r_off.successful_suspends,
2234 		     wil->suspend_stats.r_off.failed_suspends,
2235 		     wil->suspend_stats.r_off.successful_resumes,
2236 		     wil->suspend_stats.r_off.failed_resumes,
2237 		     wil->suspend_stats.rejected_by_host);
2238 
2239 	n = min_t(int, n, text_size);
2240 
2241 	ret = simple_read_from_buffer(user_buf, count, ppos, text, n);
2242 
2243 	kfree(text);
2244 
2245 	return ret;
2246 }
2247 
2248 static const struct file_operations fops_suspend_stats = {
2249 	.read = wil_read_suspend_stats,
2250 	.write = wil_write_suspend_stats,
2251 	.open  = simple_open,
2252 };
2253 
2254 /*---------compressed_rx_status---------*/
2255 static ssize_t wil_compressed_rx_status_write(struct file *file,
2256 					      const char __user *buf,
2257 					      size_t len, loff_t *ppos)
2258 {
2259 	struct seq_file *s = file->private_data;
2260 	struct wil6210_priv *wil = s->private;
2261 	int compressed_rx_status;
2262 	int rc;
2263 
2264 	rc = kstrtoint_from_user(buf, len, 0, &compressed_rx_status);
2265 	if (rc) {
2266 		wil_err(wil, "Invalid argument\n");
2267 		return rc;
2268 	}
2269 
2270 	if (wil_has_active_ifaces(wil, true, false)) {
2271 		wil_err(wil, "cannot change edma config after iface is up\n");
2272 		return -EPERM;
2273 	}
2274 
2275 	wil_info(wil, "%sable compressed_rx_status\n",
2276 		 compressed_rx_status ? "En" : "Dis");
2277 
2278 	wil->use_compressed_rx_status = compressed_rx_status;
2279 
2280 	return len;
2281 }
2282 
2283 static int
2284 wil_compressed_rx_status_show(struct seq_file *s, void *data)
2285 {
2286 	struct wil6210_priv *wil = s->private;
2287 
2288 	seq_printf(s, "%d\n", wil->use_compressed_rx_status);
2289 
2290 	return 0;
2291 }
2292 
2293 static int
2294 wil_compressed_rx_status_seq_open(struct inode *inode, struct file *file)
2295 {
2296 	return single_open(file, wil_compressed_rx_status_show,
2297 			   inode->i_private);
2298 }
2299 
2300 static const struct file_operations fops_compressed_rx_status = {
2301 	.open  = wil_compressed_rx_status_seq_open,
2302 	.release = single_release,
2303 	.read = seq_read,
2304 	.write = wil_compressed_rx_status_write,
2305 	.llseek	= seq_lseek,
2306 };
2307 
2308 /*----------------*/
2309 static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
2310 				       struct dentry *dbg)
2311 {
2312 	int i;
2313 	char name[32];
2314 
2315 	for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
2316 		struct wil_blob_wrapper *wil_blob = &wil->blobs[i];
2317 		struct debugfs_blob_wrapper *blob = &wil_blob->blob;
2318 		const struct fw_map *map = &fw_mapping[i];
2319 
2320 		if (!map->name)
2321 			continue;
2322 
2323 		wil_blob->wil = wil;
2324 		blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
2325 		blob->size = map->to - map->from;
2326 		snprintf(name, sizeof(name), "blob_%s", map->name);
2327 		wil_debugfs_create_ioblob(name, 0444, dbg, wil_blob);
2328 	}
2329 }
2330 
2331 /* misc files */
2332 static const struct {
2333 	const char *name;
2334 	umode_t mode;
2335 	const struct file_operations *fops;
2336 } dbg_files[] = {
2337 	{"mbox",	0444,		&mbox_fops},
2338 	{"rings",	0444,		&ring_fops},
2339 	{"stations", 0444,		&sta_fops},
2340 	{"mids",	0444,		&mids_fops},
2341 	{"desc",	0444,		&txdesc_fops},
2342 	{"bf",		0444,		&bf_fops},
2343 	{"mem_val",	0644,		&memread_fops},
2344 	{"rxon",	0244,		&fops_rxon},
2345 	{"tx_mgmt",	0244,		&fops_txmgmt},
2346 	{"wmi_send", 0244,		&fops_wmi},
2347 	{"back",	0644,		&fops_back},
2348 	{"pmccfg",	0644,		&fops_pmccfg},
2349 	{"pmcdata",	0444,		&fops_pmcdata},
2350 	{"temp",	0444,		&temp_fops},
2351 	{"freq",	0444,		&freq_fops},
2352 	{"link",	0444,		&link_fops},
2353 	{"info",	0444,		&info_fops},
2354 	{"recovery", 0644,		&fops_recovery},
2355 	{"led_cfg",	0644,		&fops_led_cfg},
2356 	{"led_blink_time",	0644,	&fops_led_blink_time},
2357 	{"fw_capabilities",	0444,	&fops_fw_capabilities},
2358 	{"fw_version",	0444,		&fops_fw_version},
2359 	{"suspend_stats",	0644,	&fops_suspend_stats},
2360 	{"compressed_rx_status", 0644,	&fops_compressed_rx_status},
2361 	{"srings",	0444,		&srings_fops},
2362 	{"status_msg",	0444,		&status_msg_fops},
2363 	{"rx_buff_mgmt",	0444,	&rx_buff_mgmt_fops},
2364 	{"tx_latency",	0644,		&fops_tx_latency},
2365 	{"link_stats",	0644,		&fops_link_stats},
2366 	{"link_stats_global",	0644,	&fops_link_stats_global},
2367 };
2368 
2369 static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
2370 				       struct dentry *dbg)
2371 {
2372 	int i;
2373 
2374 	for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
2375 		debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
2376 				    wil, dbg_files[i].fops);
2377 }
2378 
2379 /* interrupt control blocks */
2380 static const struct {
2381 	const char *name;
2382 	u32 icr_off;
2383 } dbg_icr[] = {
2384 	{"USER_ICR",		HOSTADDR(RGF_USER_USER_ICR)},
2385 	{"DMA_EP_TX_ICR",	HOSTADDR(RGF_DMA_EP_TX_ICR)},
2386 	{"DMA_EP_RX_ICR",	HOSTADDR(RGF_DMA_EP_RX_ICR)},
2387 	{"DMA_EP_MISC_ICR",	HOSTADDR(RGF_DMA_EP_MISC_ICR)},
2388 };
2389 
2390 static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
2391 				     struct dentry *dbg)
2392 {
2393 	int i;
2394 
2395 	for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
2396 		wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
2397 					   dbg_icr[i].icr_off);
2398 }
2399 
2400 #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
2401 	offsetof(struct wil6210_priv, name), type}
2402 
2403 /* fields in struct wil6210_priv */
2404 static const struct dbg_off dbg_wil_off[] = {
2405 	WIL_FIELD(status[0],	0644,	doff_ulong),
2406 	WIL_FIELD(hw_version,	0444,	doff_x32),
2407 	WIL_FIELD(recovery_count, 0444,	doff_u32),
2408 	WIL_FIELD(discovery_mode, 0644,	doff_u8),
2409 	WIL_FIELD(chip_revision, 0444,	doff_u8),
2410 	WIL_FIELD(abft_len, 0644,		doff_u8),
2411 	WIL_FIELD(wakeup_trigger, 0644,		doff_u8),
2412 	WIL_FIELD(ring_idle_trsh, 0644,	doff_u32),
2413 	WIL_FIELD(num_rx_status_rings, 0644,	doff_u8),
2414 	WIL_FIELD(rx_status_ring_order, 0644,	doff_u32),
2415 	WIL_FIELD(tx_status_ring_order, 0644,	doff_u32),
2416 	WIL_FIELD(rx_buff_id_count, 0644,	doff_u32),
2417 	WIL_FIELD(amsdu_en, 0644,	doff_u8),
2418 	{},
2419 };
2420 
2421 static const struct dbg_off dbg_wil_regs[] = {
2422 	{"RGF_MAC_MTRL_COUNTER_0", 0444, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
2423 		doff_io32},
2424 	{"RGF_USER_USAGE_1", 0444, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
2425 	{"RGF_USER_USAGE_2", 0444, HOSTADDR(RGF_USER_USAGE_2), doff_io32},
2426 	{},
2427 };
2428 
2429 /* static parameters */
2430 static const struct dbg_off dbg_statics[] = {
2431 	{"desc_index",	0644, (ulong)&dbg_txdesc_index, doff_u32},
2432 	{"ring_index",	0644, (ulong)&dbg_ring_index, doff_u32},
2433 	{"mem_addr",	0644, (ulong)&mem_addr, doff_u32},
2434 	{"led_polarity", 0644, (ulong)&led_polarity, doff_u8},
2435 	{"status_index", 0644, (ulong)&dbg_status_msg_index, doff_u32},
2436 	{"sring_index",	0644, (ulong)&dbg_sring_index, doff_u32},
2437 	{"drop_if_ring_full", 0644, (ulong)&drop_if_ring_full, doff_u8},
2438 	{},
2439 };
2440 
2441 static const int dbg_off_count = 4 * (ARRAY_SIZE(isr_off) - 1) +
2442 				ARRAY_SIZE(dbg_wil_regs) - 1 +
2443 				ARRAY_SIZE(pseudo_isr_off) - 1 +
2444 				ARRAY_SIZE(lgc_itr_cnt_off) - 1 +
2445 				ARRAY_SIZE(tx_itr_cnt_off) - 1 +
2446 				ARRAY_SIZE(rx_itr_cnt_off) - 1;
2447 
2448 int wil6210_debugfs_init(struct wil6210_priv *wil)
2449 {
2450 	struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
2451 			wil_to_wiphy(wil)->debugfsdir);
2452 	if (IS_ERR_OR_NULL(dbg))
2453 		return -ENODEV;
2454 
2455 	wil->dbg_data.data_arr = kcalloc(dbg_off_count,
2456 					 sizeof(struct wil_debugfs_iomem_data),
2457 					 GFP_KERNEL);
2458 	if (!wil->dbg_data.data_arr) {
2459 		debugfs_remove_recursive(dbg);
2460 		wil->debug = NULL;
2461 		return -ENOMEM;
2462 	}
2463 
2464 	wil->dbg_data.iomem_data_count = 0;
2465 
2466 	wil_pmc_init(wil);
2467 
2468 	wil6210_debugfs_init_files(wil, dbg);
2469 	wil6210_debugfs_init_isr(wil, dbg);
2470 	wil6210_debugfs_init_blobs(wil, dbg);
2471 	wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
2472 	wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
2473 				    dbg_wil_regs);
2474 	wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
2475 
2476 	wil6210_debugfs_create_pseudo_ISR(wil, dbg);
2477 
2478 	wil6210_debugfs_create_ITR_CNT(wil, dbg);
2479 
2480 	return 0;
2481 }
2482 
2483 void wil6210_debugfs_remove(struct wil6210_priv *wil)
2484 {
2485 	int i;
2486 
2487 	debugfs_remove_recursive(wil->debug);
2488 	wil->debug = NULL;
2489 
2490 	kfree(wil->dbg_data.data_arr);
2491 	for (i = 0; i < wil->max_assoc_sta; i++)
2492 		kfree(wil->sta[i].tx_latency_bins);
2493 
2494 	/* free pmc memory without sending command to fw, as it will
2495 	 * be reset on the way down anyway
2496 	 */
2497 	wil_pmc_free(wil, false);
2498 }
2499