xref: /linux/drivers/net/wireless/ath/wil6210/debugfs.c (revision c33407a8c50430f1634a8809f9528b6888360e56)
12be7d22fSVladimir Kondratiev /*
202525a79SVladimir Kondratiev  * Copyright (c) 2012-2014 Qualcomm Atheros, Inc.
32be7d22fSVladimir Kondratiev  *
42be7d22fSVladimir Kondratiev  * Permission to use, copy, modify, and/or distribute this software for any
52be7d22fSVladimir Kondratiev  * purpose with or without fee is hereby granted, provided that the above
62be7d22fSVladimir Kondratiev  * copyright notice and this permission notice appear in all copies.
72be7d22fSVladimir Kondratiev  *
82be7d22fSVladimir Kondratiev  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
92be7d22fSVladimir Kondratiev  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
102be7d22fSVladimir Kondratiev  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
112be7d22fSVladimir Kondratiev  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
122be7d22fSVladimir Kondratiev  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
132be7d22fSVladimir Kondratiev  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
142be7d22fSVladimir Kondratiev  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
152be7d22fSVladimir Kondratiev  */
162be7d22fSVladimir Kondratiev 
172be7d22fSVladimir Kondratiev #include <linux/module.h>
182be7d22fSVladimir Kondratiev #include <linux/debugfs.h>
192be7d22fSVladimir Kondratiev #include <linux/seq_file.h>
202be7d22fSVladimir Kondratiev #include <linux/pci.h>
212be7d22fSVladimir Kondratiev #include <linux/rtnetlink.h>
2284bb29b7SVladimir Kondratiev #include <linux/power_supply.h>
232be7d22fSVladimir Kondratiev 
242be7d22fSVladimir Kondratiev #include "wil6210.h"
2536345ac3SVladimir Kondratiev #include "wmi.h"
262be7d22fSVladimir Kondratiev #include "txrx.h"
272be7d22fSVladimir Kondratiev 
282be7d22fSVladimir Kondratiev /* Nasty hack. Better have per device instances */
292be7d22fSVladimir Kondratiev static u32 mem_addr;
302be7d22fSVladimir Kondratiev static u32 dbg_txdesc_index;
31af31cb5aSVladimir Kondratiev static u32 dbg_vring_index; /* 24+ for Rx, 0..23 for Tx */
322be7d22fSVladimir Kondratiev 
33b7cde470SVladimir Kondratiev enum dbg_off_type {
34b7cde470SVladimir Kondratiev 	doff_u32 = 0,
35b7cde470SVladimir Kondratiev 	doff_x32 = 1,
36b7cde470SVladimir Kondratiev 	doff_ulong = 2,
37b7cde470SVladimir Kondratiev 	doff_io32 = 3,
38b7cde470SVladimir Kondratiev };
39b7cde470SVladimir Kondratiev 
40b7cde470SVladimir Kondratiev /* offset to "wil" */
41b7cde470SVladimir Kondratiev struct dbg_off {
42b7cde470SVladimir Kondratiev 	const char *name;
43b7cde470SVladimir Kondratiev 	umode_t mode;
44b7cde470SVladimir Kondratiev 	ulong off;
45b7cde470SVladimir Kondratiev 	enum dbg_off_type type;
46b7cde470SVladimir Kondratiev };
47b7cde470SVladimir Kondratiev 
482be7d22fSVladimir Kondratiev static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil,
4959f7c0a9SVladimir Kondratiev 			    const char *name, struct vring *vring,
5059f7c0a9SVladimir Kondratiev 			    char _s, char _h)
512be7d22fSVladimir Kondratiev {
522be7d22fSVladimir Kondratiev 	void __iomem *x = wmi_addr(wil, vring->hwtail);
532be7d22fSVladimir Kondratiev 
542be7d22fSVladimir Kondratiev 	seq_printf(s, "VRING %s = {\n", name);
5539c52ee8SVladimir Kondratiev 	seq_printf(s, "  pa     = %pad\n", &vring->pa);
562be7d22fSVladimir Kondratiev 	seq_printf(s, "  va     = 0x%p\n", vring->va);
572be7d22fSVladimir Kondratiev 	seq_printf(s, "  size   = %d\n", vring->size);
582be7d22fSVladimir Kondratiev 	seq_printf(s, "  swtail = %d\n", vring->swtail);
592be7d22fSVladimir Kondratiev 	seq_printf(s, "  swhead = %d\n", vring->swhead);
602be7d22fSVladimir Kondratiev 	seq_printf(s, "  hwtail = [0x%08x] -> ", vring->hwtail);
612be7d22fSVladimir Kondratiev 	if (x)
622be7d22fSVladimir Kondratiev 		seq_printf(s, "0x%08x\n", ioread32(x));
632be7d22fSVladimir Kondratiev 	else
648fe59627SVladimir Kondratiev 		seq_puts(s, "???\n");
652be7d22fSVladimir Kondratiev 
662be7d22fSVladimir Kondratiev 	if (vring->va && (vring->size < 1025)) {
672be7d22fSVladimir Kondratiev 		uint i;
688fe59627SVladimir Kondratiev 
692be7d22fSVladimir Kondratiev 		for (i = 0; i < vring->size; i++) {
702be7d22fSVladimir Kondratiev 			volatile struct vring_tx_desc *d = &vring->va[i].tx;
718fe59627SVladimir Kondratiev 
722be7d22fSVladimir Kondratiev 			if ((i % 64) == 0 && (i != 0))
738fe59627SVladimir Kondratiev 				seq_puts(s, "\n");
7459f7c0a9SVladimir Kondratiev 			seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
7559f7c0a9SVladimir Kondratiev 					_s : (vring->ctx[i].skb ? _h : 'h'));
762be7d22fSVladimir Kondratiev 		}
778fe59627SVladimir Kondratiev 		seq_puts(s, "\n");
782be7d22fSVladimir Kondratiev 	}
798fe59627SVladimir Kondratiev 	seq_puts(s, "}\n");
802be7d22fSVladimir Kondratiev }
812be7d22fSVladimir Kondratiev 
822be7d22fSVladimir Kondratiev static int wil_vring_debugfs_show(struct seq_file *s, void *data)
832be7d22fSVladimir Kondratiev {
842be7d22fSVladimir Kondratiev 	uint i;
852be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
862be7d22fSVladimir Kondratiev 
8759f7c0a9SVladimir Kondratiev 	wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_');
882be7d22fSVladimir Kondratiev 
892be7d22fSVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
908fe59627SVladimir Kondratiev 		struct vring *vring = &wil->vring_tx[i];
917c0acf86SVladimir Kondratiev 		struct vring_tx_data *txdata = &wil->vring_tx_data[i];
927c0acf86SVladimir Kondratiev 
932be7d22fSVladimir Kondratiev 		if (vring->va) {
943df2cd36SVladimir Kondratiev 			int cid = wil->vring2cid_tid[i][0];
953df2cd36SVladimir Kondratiev 			int tid = wil->vring2cid_tid[i][1];
9667c3e1b4SVladimir Kondratiev 			u32 swhead = vring->swhead;
9767c3e1b4SVladimir Kondratiev 			u32 swtail = vring->swtail;
9867c3e1b4SVladimir Kondratiev 			int used = (vring->size + swhead - swtail)
9967c3e1b4SVladimir Kondratiev 				   % vring->size;
10067c3e1b4SVladimir Kondratiev 			int avail = vring->size - used - 1;
1012be7d22fSVladimir Kondratiev 			char name[10];
1027c0acf86SVladimir Kondratiev 			/* performance monitoring */
1037c0acf86SVladimir Kondratiev 			cycles_t now = get_cycles();
104e48b1790SVladimir Kondratiev 			cycles_t idle = txdata->idle * 100;
1057c0acf86SVladimir Kondratiev 			cycles_t total = now - txdata->begin;
1067c0acf86SVladimir Kondratiev 
107e48b1790SVladimir Kondratiev 			do_div(idle, total);
1087c0acf86SVladimir Kondratiev 			txdata->begin = now;
1097c0acf86SVladimir Kondratiev 			txdata->idle = 0ULL;
1107c0acf86SVladimir Kondratiev 
1112be7d22fSVladimir Kondratiev 			snprintf(name, sizeof(name), "tx_%2d", i);
1123df2cd36SVladimir Kondratiev 
1137c0acf86SVladimir Kondratiev 			seq_printf(s, "\n%pM CID %d TID %d [%3d|%3d] idle %3d%%\n",
1147c0acf86SVladimir Kondratiev 				   wil->sta[cid].addr, cid, tid, used, avail,
115e48b1790SVladimir Kondratiev 				   (int)idle);
1167c0acf86SVladimir Kondratiev 
11759f7c0a9SVladimir Kondratiev 			wil_print_vring(s, wil, name, vring, '_', 'H');
1182be7d22fSVladimir Kondratiev 		}
1192be7d22fSVladimir Kondratiev 	}
1202be7d22fSVladimir Kondratiev 
1212be7d22fSVladimir Kondratiev 	return 0;
1222be7d22fSVladimir Kondratiev }
1232be7d22fSVladimir Kondratiev 
1242be7d22fSVladimir Kondratiev static int wil_vring_seq_open(struct inode *inode, struct file *file)
1252be7d22fSVladimir Kondratiev {
1262be7d22fSVladimir Kondratiev 	return single_open(file, wil_vring_debugfs_show, inode->i_private);
1272be7d22fSVladimir Kondratiev }
1282be7d22fSVladimir Kondratiev 
1292be7d22fSVladimir Kondratiev static const struct file_operations fops_vring = {
1302be7d22fSVladimir Kondratiev 	.open		= wil_vring_seq_open,
1312be7d22fSVladimir Kondratiev 	.release	= single_release,
1322be7d22fSVladimir Kondratiev 	.read		= seq_read,
1332be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
1342be7d22fSVladimir Kondratiev };
1352be7d22fSVladimir Kondratiev 
1362be7d22fSVladimir Kondratiev static void wil_print_ring(struct seq_file *s, const char *prefix,
1372be7d22fSVladimir Kondratiev 			   void __iomem *off)
1382be7d22fSVladimir Kondratiev {
1392be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
1402be7d22fSVladimir Kondratiev 	struct wil6210_mbox_ring r;
1412be7d22fSVladimir Kondratiev 	int rsize;
1422be7d22fSVladimir Kondratiev 	uint i;
1432be7d22fSVladimir Kondratiev 
1442be7d22fSVladimir Kondratiev 	wil_memcpy_fromio_32(&r, off, sizeof(r));
1452be7d22fSVladimir Kondratiev 	wil_mbox_ring_le2cpus(&r);
1462be7d22fSVladimir Kondratiev 	/*
1472be7d22fSVladimir Kondratiev 	 * we just read memory block from NIC. This memory may be
1482be7d22fSVladimir Kondratiev 	 * garbage. Check validity before using it.
1492be7d22fSVladimir Kondratiev 	 */
1502be7d22fSVladimir Kondratiev 	rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
1512be7d22fSVladimir Kondratiev 
1522be7d22fSVladimir Kondratiev 	seq_printf(s, "ring %s = {\n", prefix);
1532be7d22fSVladimir Kondratiev 	seq_printf(s, "  base = 0x%08x\n", r.base);
1542be7d22fSVladimir Kondratiev 	seq_printf(s, "  size = 0x%04x bytes -> %d entries\n", r.size, rsize);
1552be7d22fSVladimir Kondratiev 	seq_printf(s, "  tail = 0x%08x\n", r.tail);
1562be7d22fSVladimir Kondratiev 	seq_printf(s, "  head = 0x%08x\n", r.head);
1572be7d22fSVladimir Kondratiev 	seq_printf(s, "  entry size = %d\n", r.entry_size);
1582be7d22fSVladimir Kondratiev 
1592be7d22fSVladimir Kondratiev 	if (r.size % sizeof(struct wil6210_mbox_ring_desc)) {
1602be7d22fSVladimir Kondratiev 		seq_printf(s, "  ??? size is not multiple of %zd, garbage?\n",
1612be7d22fSVladimir Kondratiev 			   sizeof(struct wil6210_mbox_ring_desc));
1622be7d22fSVladimir Kondratiev 		goto out;
1632be7d22fSVladimir Kondratiev 	}
1642be7d22fSVladimir Kondratiev 
1652be7d22fSVladimir Kondratiev 	if (!wmi_addr(wil, r.base) ||
1662be7d22fSVladimir Kondratiev 	    !wmi_addr(wil, r.tail) ||
1672be7d22fSVladimir Kondratiev 	    !wmi_addr(wil, r.head)) {
1688fe59627SVladimir Kondratiev 		seq_puts(s, "  ??? pointers are garbage?\n");
1692be7d22fSVladimir Kondratiev 		goto out;
1702be7d22fSVladimir Kondratiev 	}
1712be7d22fSVladimir Kondratiev 
1722be7d22fSVladimir Kondratiev 	for (i = 0; i < rsize; i++) {
1732be7d22fSVladimir Kondratiev 		struct wil6210_mbox_ring_desc d;
1742be7d22fSVladimir Kondratiev 		struct wil6210_mbox_hdr hdr;
1752be7d22fSVladimir Kondratiev 		size_t delta = i * sizeof(d);
1762be7d22fSVladimir Kondratiev 		void __iomem *x = wil->csr + HOSTADDR(r.base) + delta;
1772be7d22fSVladimir Kondratiev 
1782be7d22fSVladimir Kondratiev 		wil_memcpy_fromio_32(&d, x, sizeof(d));
1792be7d22fSVladimir Kondratiev 
1802be7d22fSVladimir Kondratiev 		seq_printf(s, "  [%2x] %s %s%s 0x%08x", i,
1812be7d22fSVladimir Kondratiev 			   d.sync ? "F" : "E",
1822be7d22fSVladimir Kondratiev 			   (r.tail - r.base == delta) ? "t" : " ",
1832be7d22fSVladimir Kondratiev 			   (r.head - r.base == delta) ? "h" : " ",
1842be7d22fSVladimir Kondratiev 			   le32_to_cpu(d.addr));
1852be7d22fSVladimir Kondratiev 		if (0 == wmi_read_hdr(wil, d.addr, &hdr)) {
1862be7d22fSVladimir Kondratiev 			u16 len = le16_to_cpu(hdr.len);
1878fe59627SVladimir Kondratiev 
1882be7d22fSVladimir Kondratiev 			seq_printf(s, " -> %04x %04x %04x %02x\n",
1892be7d22fSVladimir Kondratiev 				   le16_to_cpu(hdr.seq), len,
1902be7d22fSVladimir Kondratiev 				   le16_to_cpu(hdr.type), hdr.flags);
1912be7d22fSVladimir Kondratiev 			if (len <= MAX_MBOXITEM_SIZE) {
1922be7d22fSVladimir Kondratiev 				int n = 0;
1935d21608aSLarry Finger 				char printbuf[16 * 3 + 2];
1942be7d22fSVladimir Kondratiev 				unsigned char databuf[MAX_MBOXITEM_SIZE];
1952be7d22fSVladimir Kondratiev 				void __iomem *src = wmi_buffer(wil, d.addr) +
1962be7d22fSVladimir Kondratiev 					sizeof(struct wil6210_mbox_hdr);
1972be7d22fSVladimir Kondratiev 				/*
1982be7d22fSVladimir Kondratiev 				 * No need to check @src for validity -
1992be7d22fSVladimir Kondratiev 				 * we already validated @d.addr while
2002be7d22fSVladimir Kondratiev 				 * reading header
2012be7d22fSVladimir Kondratiev 				 */
2022be7d22fSVladimir Kondratiev 				wil_memcpy_fromio_32(databuf, src, len);
2032be7d22fSVladimir Kondratiev 				while (n < len) {
2042be7d22fSVladimir Kondratiev 					int l = min(len - n, 16);
2058fe59627SVladimir Kondratiev 
2062be7d22fSVladimir Kondratiev 					hex_dump_to_buffer(databuf + n, l,
2072be7d22fSVladimir Kondratiev 							   16, 1, printbuf,
2082be7d22fSVladimir Kondratiev 							   sizeof(printbuf),
2092be7d22fSVladimir Kondratiev 							   false);
2102be7d22fSVladimir Kondratiev 					seq_printf(s, "      : %s\n", printbuf);
2112be7d22fSVladimir Kondratiev 					n += l;
2122be7d22fSVladimir Kondratiev 				}
2132be7d22fSVladimir Kondratiev 			}
2142be7d22fSVladimir Kondratiev 		} else {
2158fe59627SVladimir Kondratiev 			seq_puts(s, "\n");
2162be7d22fSVladimir Kondratiev 		}
2172be7d22fSVladimir Kondratiev 	}
2182be7d22fSVladimir Kondratiev  out:
2198fe59627SVladimir Kondratiev 	seq_puts(s, "}\n");
2202be7d22fSVladimir Kondratiev }
2212be7d22fSVladimir Kondratiev 
2222be7d22fSVladimir Kondratiev static int wil_mbox_debugfs_show(struct seq_file *s, void *data)
2232be7d22fSVladimir Kondratiev {
2242be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
2252be7d22fSVladimir Kondratiev 
2262be7d22fSVladimir Kondratiev 	wil_print_ring(s, "tx", wil->csr + HOST_MBOX +
2272be7d22fSVladimir Kondratiev 		       offsetof(struct wil6210_mbox_ctl, tx));
2282be7d22fSVladimir Kondratiev 	wil_print_ring(s, "rx", wil->csr + HOST_MBOX +
2292be7d22fSVladimir Kondratiev 		       offsetof(struct wil6210_mbox_ctl, rx));
2302be7d22fSVladimir Kondratiev 
2312be7d22fSVladimir Kondratiev 	return 0;
2322be7d22fSVladimir Kondratiev }
2332be7d22fSVladimir Kondratiev 
2342be7d22fSVladimir Kondratiev static int wil_mbox_seq_open(struct inode *inode, struct file *file)
2352be7d22fSVladimir Kondratiev {
2362be7d22fSVladimir Kondratiev 	return single_open(file, wil_mbox_debugfs_show, inode->i_private);
2372be7d22fSVladimir Kondratiev }
2382be7d22fSVladimir Kondratiev 
2392be7d22fSVladimir Kondratiev static const struct file_operations fops_mbox = {
2402be7d22fSVladimir Kondratiev 	.open		= wil_mbox_seq_open,
2412be7d22fSVladimir Kondratiev 	.release	= single_release,
2422be7d22fSVladimir Kondratiev 	.read		= seq_read,
2432be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
2442be7d22fSVladimir Kondratiev };
2452be7d22fSVladimir Kondratiev 
2462be7d22fSVladimir Kondratiev static int wil_debugfs_iomem_x32_set(void *data, u64 val)
2472be7d22fSVladimir Kondratiev {
2482be7d22fSVladimir Kondratiev 	iowrite32(val, (void __iomem *)data);
2492be7d22fSVladimir Kondratiev 	wmb(); /* make sure write propagated to HW */
2502be7d22fSVladimir Kondratiev 
2512be7d22fSVladimir Kondratiev 	return 0;
2522be7d22fSVladimir Kondratiev }
2532be7d22fSVladimir Kondratiev 
2542be7d22fSVladimir Kondratiev static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
2552be7d22fSVladimir Kondratiev {
2562be7d22fSVladimir Kondratiev 	*val = ioread32((void __iomem *)data);
2572be7d22fSVladimir Kondratiev 
2582be7d22fSVladimir Kondratiev 	return 0;
2592be7d22fSVladimir Kondratiev }
2602be7d22fSVladimir Kondratiev 
2612be7d22fSVladimir Kondratiev DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
2622be7d22fSVladimir Kondratiev 			wil_debugfs_iomem_x32_set, "0x%08llx\n");
2632be7d22fSVladimir Kondratiev 
2642be7d22fSVladimir Kondratiev static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
2650ecc833bSAl Viro 						   umode_t mode,
2662be7d22fSVladimir Kondratiev 						   struct dentry *parent,
267b7cde470SVladimir Kondratiev 						   void *value)
2682be7d22fSVladimir Kondratiev {
269b7cde470SVladimir Kondratiev 	return debugfs_create_file(name, mode, parent, value,
2702be7d22fSVladimir Kondratiev 				   &fops_iomem_x32);
2712be7d22fSVladimir Kondratiev }
2722be7d22fSVladimir Kondratiev 
2733de6cf20SVladimir Kondratiev static int wil_debugfs_ulong_set(void *data, u64 val)
2743de6cf20SVladimir Kondratiev {
2753de6cf20SVladimir Kondratiev 	*(ulong *)data = val;
2763de6cf20SVladimir Kondratiev 	return 0;
2773de6cf20SVladimir Kondratiev }
2788fe59627SVladimir Kondratiev 
2793de6cf20SVladimir Kondratiev static int wil_debugfs_ulong_get(void *data, u64 *val)
2803de6cf20SVladimir Kondratiev {
2813de6cf20SVladimir Kondratiev 	*val = *(ulong *)data;
2823de6cf20SVladimir Kondratiev 	return 0;
2833de6cf20SVladimir Kondratiev }
2848fe59627SVladimir Kondratiev 
2853de6cf20SVladimir Kondratiev DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
2863de6cf20SVladimir Kondratiev 			wil_debugfs_ulong_set, "%llu\n");
2873de6cf20SVladimir Kondratiev 
2883de6cf20SVladimir Kondratiev static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode,
2893de6cf20SVladimir Kondratiev 					       struct dentry *parent,
2903de6cf20SVladimir Kondratiev 					       ulong *value)
2913de6cf20SVladimir Kondratiev {
2923de6cf20SVladimir Kondratiev 	return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong);
2933de6cf20SVladimir Kondratiev }
2943de6cf20SVladimir Kondratiev 
295b7cde470SVladimir Kondratiev /**
296b7cde470SVladimir Kondratiev  * wil6210_debugfs_init_offset - create set of debugfs files
297b7cde470SVladimir Kondratiev  * @wil - driver's context, used for printing
298b7cde470SVladimir Kondratiev  * @dbg - directory on the debugfs, where files will be created
299b7cde470SVladimir Kondratiev  * @base - base address used in address calculation
300b7cde470SVladimir Kondratiev  * @tbl - table with file descriptions. Should be terminated with empty element.
301b7cde470SVladimir Kondratiev  *
302b7cde470SVladimir Kondratiev  * Creates files accordingly to the @tbl.
303b7cde470SVladimir Kondratiev  */
304b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_offset(struct wil6210_priv *wil,
305b7cde470SVladimir Kondratiev 					struct dentry *dbg, void *base,
306b7cde470SVladimir Kondratiev 					const struct dbg_off * const tbl)
307b7cde470SVladimir Kondratiev {
308b7cde470SVladimir Kondratiev 	int i;
309b7cde470SVladimir Kondratiev 
310b7cde470SVladimir Kondratiev 	for (i = 0; tbl[i].name; i++) {
311867fa0d4SVladimir Kondratiev 		struct dentry *f;
312b7cde470SVladimir Kondratiev 
313b7cde470SVladimir Kondratiev 		switch (tbl[i].type) {
314b7cde470SVladimir Kondratiev 		case doff_u32:
315b7cde470SVladimir Kondratiev 			f = debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg,
316b7cde470SVladimir Kondratiev 					       base + tbl[i].off);
317b7cde470SVladimir Kondratiev 			break;
318b7cde470SVladimir Kondratiev 		case doff_x32:
319b7cde470SVladimir Kondratiev 			f = debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg,
320b7cde470SVladimir Kondratiev 					       base + tbl[i].off);
321b7cde470SVladimir Kondratiev 			break;
322b7cde470SVladimir Kondratiev 		case doff_ulong:
323b7cde470SVladimir Kondratiev 			f = wil_debugfs_create_ulong(tbl[i].name, tbl[i].mode,
324b7cde470SVladimir Kondratiev 						     dbg, base + tbl[i].off);
325b7cde470SVladimir Kondratiev 			break;
326b7cde470SVladimir Kondratiev 		case doff_io32:
327b7cde470SVladimir Kondratiev 			f = wil_debugfs_create_iomem_x32(tbl[i].name,
328b7cde470SVladimir Kondratiev 							 tbl[i].mode, dbg,
329b7cde470SVladimir Kondratiev 							 base + tbl[i].off);
330b7cde470SVladimir Kondratiev 			break;
331867fa0d4SVladimir Kondratiev 		default:
332867fa0d4SVladimir Kondratiev 			f = ERR_PTR(-EINVAL);
333b7cde470SVladimir Kondratiev 		}
334b7cde470SVladimir Kondratiev 		if (IS_ERR_OR_NULL(f))
335b7cde470SVladimir Kondratiev 			wil_err(wil, "Create file \"%s\": err %ld\n",
336b7cde470SVladimir Kondratiev 				tbl[i].name, PTR_ERR(f));
337b7cde470SVladimir Kondratiev 	}
338b7cde470SVladimir Kondratiev }
339b7cde470SVladimir Kondratiev 
340b7cde470SVladimir Kondratiev static const struct dbg_off isr_off[] = {
341b7cde470SVladimir Kondratiev 	{"ICC", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICC), doff_io32},
342b7cde470SVladimir Kondratiev 	{"ICR", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICR), doff_io32},
343b7cde470SVladimir Kondratiev 	{"ICM", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICM), doff_io32},
344b7cde470SVladimir Kondratiev 	{"ICS",		  S_IWUSR, offsetof(struct RGF_ICR, ICS), doff_io32},
345b7cde470SVladimir Kondratiev 	{"IMV", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, IMV), doff_io32},
346b7cde470SVladimir Kondratiev 	{"IMS",		  S_IWUSR, offsetof(struct RGF_ICR, IMS), doff_io32},
347b7cde470SVladimir Kondratiev 	{"IMC",		  S_IWUSR, offsetof(struct RGF_ICR, IMC), doff_io32},
348b7cde470SVladimir Kondratiev 	{},
349b7cde470SVladimir Kondratiev };
3508fe59627SVladimir Kondratiev 
3512be7d22fSVladimir Kondratiev static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
3522be7d22fSVladimir Kondratiev 				      const char *name,
3532be7d22fSVladimir Kondratiev 				      struct dentry *parent, u32 off)
3542be7d22fSVladimir Kondratiev {
3552be7d22fSVladimir Kondratiev 	struct dentry *d = debugfs_create_dir(name, parent);
3562be7d22fSVladimir Kondratiev 
3572be7d22fSVladimir Kondratiev 	if (IS_ERR_OR_NULL(d))
3582be7d22fSVladimir Kondratiev 		return -ENODEV;
3592be7d22fSVladimir Kondratiev 
360b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off,
361b7cde470SVladimir Kondratiev 				    isr_off);
3622be7d22fSVladimir Kondratiev 
3632be7d22fSVladimir Kondratiev 	return 0;
3642be7d22fSVladimir Kondratiev }
3652be7d22fSVladimir Kondratiev 
366b7cde470SVladimir Kondratiev static const struct dbg_off pseudo_isr_off[] = {
367b7cde470SVladimir Kondratiev 	{"CAUSE",   S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32},
368b7cde470SVladimir Kondratiev 	{"MASK_SW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32},
369b7cde470SVladimir Kondratiev 	{"MASK_FW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32},
370b7cde470SVladimir Kondratiev 	{},
371b7cde470SVladimir Kondratiev };
372b7cde470SVladimir Kondratiev 
3732be7d22fSVladimir Kondratiev static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
3742be7d22fSVladimir Kondratiev 					     struct dentry *parent)
3752be7d22fSVladimir Kondratiev {
3762be7d22fSVladimir Kondratiev 	struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
3772be7d22fSVladimir Kondratiev 
3782be7d22fSVladimir Kondratiev 	if (IS_ERR_OR_NULL(d))
3792be7d22fSVladimir Kondratiev 		return -ENODEV;
3802be7d22fSVladimir Kondratiev 
381b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
382b7cde470SVladimir Kondratiev 				    pseudo_isr_off);
3832be7d22fSVladimir Kondratiev 
3842be7d22fSVladimir Kondratiev 	return 0;
3852be7d22fSVladimir Kondratiev }
3862be7d22fSVladimir Kondratiev 
387b7cde470SVladimir Kondratiev static const struct dbg_off itr_cnt_off[] = {
388b7cde470SVladimir Kondratiev 	{"TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32},
389b7cde470SVladimir Kondratiev 	{"DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32},
390b7cde470SVladimir Kondratiev 	{"CTL",  S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32},
391b7cde470SVladimir Kondratiev 	{},
392b7cde470SVladimir Kondratiev };
393b7cde470SVladimir Kondratiev 
3942be7d22fSVladimir Kondratiev static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
3952be7d22fSVladimir Kondratiev 					  struct dentry *parent)
3962be7d22fSVladimir Kondratiev {
3972be7d22fSVladimir Kondratiev 	struct dentry *d = debugfs_create_dir("ITR_CNT", parent);
3982be7d22fSVladimir Kondratiev 
3992be7d22fSVladimir Kondratiev 	if (IS_ERR_OR_NULL(d))
4002be7d22fSVladimir Kondratiev 		return -ENODEV;
4012be7d22fSVladimir Kondratiev 
402b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
403b7cde470SVladimir Kondratiev 				    itr_cnt_off);
4042be7d22fSVladimir Kondratiev 
4052be7d22fSVladimir Kondratiev 	return 0;
4062be7d22fSVladimir Kondratiev }
4072be7d22fSVladimir Kondratiev 
4082be7d22fSVladimir Kondratiev static int wil_memread_debugfs_show(struct seq_file *s, void *data)
4092be7d22fSVladimir Kondratiev {
4102be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
4112be7d22fSVladimir Kondratiev 	void __iomem *a = wmi_buffer(wil, cpu_to_le32(mem_addr));
4122be7d22fSVladimir Kondratiev 
4132be7d22fSVladimir Kondratiev 	if (a)
4142be7d22fSVladimir Kondratiev 		seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, ioread32(a));
4152be7d22fSVladimir Kondratiev 	else
4162be7d22fSVladimir Kondratiev 		seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
4172be7d22fSVladimir Kondratiev 
4182be7d22fSVladimir Kondratiev 	return 0;
4192be7d22fSVladimir Kondratiev }
4202be7d22fSVladimir Kondratiev 
4212be7d22fSVladimir Kondratiev static int wil_memread_seq_open(struct inode *inode, struct file *file)
4222be7d22fSVladimir Kondratiev {
4232be7d22fSVladimir Kondratiev 	return single_open(file, wil_memread_debugfs_show, inode->i_private);
4242be7d22fSVladimir Kondratiev }
4252be7d22fSVladimir Kondratiev 
4262be7d22fSVladimir Kondratiev static const struct file_operations fops_memread = {
4272be7d22fSVladimir Kondratiev 	.open		= wil_memread_seq_open,
4282be7d22fSVladimir Kondratiev 	.release	= single_release,
4292be7d22fSVladimir Kondratiev 	.read		= seq_read,
4302be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
4312be7d22fSVladimir Kondratiev };
4322be7d22fSVladimir Kondratiev 
4332be7d22fSVladimir Kondratiev static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
4342be7d22fSVladimir Kondratiev 				    size_t count, loff_t *ppos)
4352be7d22fSVladimir Kondratiev {
4362be7d22fSVladimir Kondratiev 	enum { max_count = 4096 };
4372be7d22fSVladimir Kondratiev 	struct debugfs_blob_wrapper *blob = file->private_data;
4382be7d22fSVladimir Kondratiev 	loff_t pos = *ppos;
4392be7d22fSVladimir Kondratiev 	size_t available = blob->size;
4402be7d22fSVladimir Kondratiev 	void *buf;
4412be7d22fSVladimir Kondratiev 	size_t ret;
4422be7d22fSVladimir Kondratiev 
4432be7d22fSVladimir Kondratiev 	if (pos < 0)
4442be7d22fSVladimir Kondratiev 		return -EINVAL;
4452be7d22fSVladimir Kondratiev 
4462be7d22fSVladimir Kondratiev 	if (pos >= available || !count)
4472be7d22fSVladimir Kondratiev 		return 0;
4482be7d22fSVladimir Kondratiev 
4492be7d22fSVladimir Kondratiev 	if (count > available - pos)
4502be7d22fSVladimir Kondratiev 		count = available - pos;
4512be7d22fSVladimir Kondratiev 	if (count > max_count)
4522be7d22fSVladimir Kondratiev 		count = max_count;
4532be7d22fSVladimir Kondratiev 
4542be7d22fSVladimir Kondratiev 	buf = kmalloc(count, GFP_KERNEL);
4552be7d22fSVladimir Kondratiev 	if (!buf)
4562be7d22fSVladimir Kondratiev 		return -ENOMEM;
4572be7d22fSVladimir Kondratiev 
4582be7d22fSVladimir Kondratiev 	wil_memcpy_fromio_32(buf, (const volatile void __iomem *)blob->data +
4592be7d22fSVladimir Kondratiev 			     pos, count);
4602be7d22fSVladimir Kondratiev 
4612be7d22fSVladimir Kondratiev 	ret = copy_to_user(user_buf, buf, count);
4622be7d22fSVladimir Kondratiev 	kfree(buf);
4632be7d22fSVladimir Kondratiev 	if (ret == count)
4642be7d22fSVladimir Kondratiev 		return -EFAULT;
4652be7d22fSVladimir Kondratiev 
4662be7d22fSVladimir Kondratiev 	count -= ret;
4672be7d22fSVladimir Kondratiev 	*ppos = pos + count;
4682be7d22fSVladimir Kondratiev 
4692be7d22fSVladimir Kondratiev 	return count;
4702be7d22fSVladimir Kondratiev }
4712be7d22fSVladimir Kondratiev 
4722be7d22fSVladimir Kondratiev static const struct file_operations fops_ioblob = {
4732be7d22fSVladimir Kondratiev 	.read =		wil_read_file_ioblob,
47493ecbd64SWei Yongjun 	.open =		simple_open,
4752be7d22fSVladimir Kondratiev 	.llseek =	default_llseek,
4762be7d22fSVladimir Kondratiev };
4772be7d22fSVladimir Kondratiev 
4782be7d22fSVladimir Kondratiev static
4792be7d22fSVladimir Kondratiev struct dentry *wil_debugfs_create_ioblob(const char *name,
4800ecc833bSAl Viro 					 umode_t mode,
4812be7d22fSVladimir Kondratiev 					 struct dentry *parent,
4822be7d22fSVladimir Kondratiev 					 struct debugfs_blob_wrapper *blob)
4832be7d22fSVladimir Kondratiev {
4842be7d22fSVladimir Kondratiev 	return debugfs_create_file(name, mode, parent, blob, &fops_ioblob);
4852be7d22fSVladimir Kondratiev }
4868fe59627SVladimir Kondratiev 
4872be7d22fSVladimir Kondratiev /*---reset---*/
4882be7d22fSVladimir Kondratiev static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
4892be7d22fSVladimir Kondratiev 				    size_t len, loff_t *ppos)
4902be7d22fSVladimir Kondratiev {
4912be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
4922be7d22fSVladimir Kondratiev 	struct net_device *ndev = wil_to_ndev(wil);
4932be7d22fSVladimir Kondratiev 
4942be7d22fSVladimir Kondratiev 	/**
4952be7d22fSVladimir Kondratiev 	 * BUG:
4962be7d22fSVladimir Kondratiev 	 * this code does NOT sync device state with the rest of system
4972be7d22fSVladimir Kondratiev 	 * use with care, debug only!!!
4982be7d22fSVladimir Kondratiev 	 */
4992be7d22fSVladimir Kondratiev 	rtnl_lock();
5002be7d22fSVladimir Kondratiev 	dev_close(ndev);
5012be7d22fSVladimir Kondratiev 	ndev->flags &= ~IFF_UP;
5022be7d22fSVladimir Kondratiev 	rtnl_unlock();
5032be7d22fSVladimir Kondratiev 	wil_reset(wil);
5042be7d22fSVladimir Kondratiev 
5052be7d22fSVladimir Kondratiev 	return len;
5062be7d22fSVladimir Kondratiev }
5072be7d22fSVladimir Kondratiev 
5082be7d22fSVladimir Kondratiev static const struct file_operations fops_reset = {
5092be7d22fSVladimir Kondratiev 	.write = wil_write_file_reset,
51093ecbd64SWei Yongjun 	.open  = simple_open,
5112be7d22fSVladimir Kondratiev };
5128fe59627SVladimir Kondratiev 
5130b39aaf2SVladimir Kondratiev /*---write channel 1..4 to rxon for it, 0 to rxoff---*/
5140b39aaf2SVladimir Kondratiev static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
5150b39aaf2SVladimir Kondratiev 				   size_t len, loff_t *ppos)
5160b39aaf2SVladimir Kondratiev {
5170b39aaf2SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
5180b39aaf2SVladimir Kondratiev 	int rc;
5190b39aaf2SVladimir Kondratiev 	long channel;
5200b39aaf2SVladimir Kondratiev 	bool on;
5210b39aaf2SVladimir Kondratiev 
5220b39aaf2SVladimir Kondratiev 	char *kbuf = kmalloc(len + 1, GFP_KERNEL);
5238fe59627SVladimir Kondratiev 
5240b39aaf2SVladimir Kondratiev 	if (!kbuf)
5250b39aaf2SVladimir Kondratiev 		return -ENOMEM;
526359ee627SVladimir Kondratiev 	if (copy_from_user(kbuf, buf, len)) {
527359ee627SVladimir Kondratiev 		kfree(kbuf);
5280b39aaf2SVladimir Kondratiev 		return -EIO;
529359ee627SVladimir Kondratiev 	}
5300b39aaf2SVladimir Kondratiev 
5310b39aaf2SVladimir Kondratiev 	kbuf[len] = '\0';
5320b39aaf2SVladimir Kondratiev 	rc = kstrtol(kbuf, 0, &channel);
5330b39aaf2SVladimir Kondratiev 	kfree(kbuf);
5340b39aaf2SVladimir Kondratiev 	if (rc)
5350b39aaf2SVladimir Kondratiev 		return rc;
5360b39aaf2SVladimir Kondratiev 
5370b39aaf2SVladimir Kondratiev 	if ((channel < 0) || (channel > 4)) {
5380b39aaf2SVladimir Kondratiev 		wil_err(wil, "Invalid channel %ld\n", channel);
5390b39aaf2SVladimir Kondratiev 		return -EINVAL;
5400b39aaf2SVladimir Kondratiev 	}
5410b39aaf2SVladimir Kondratiev 	on = !!channel;
5420b39aaf2SVladimir Kondratiev 
5430b39aaf2SVladimir Kondratiev 	if (on) {
5440b39aaf2SVladimir Kondratiev 		rc = wmi_set_channel(wil, (int)channel);
5450b39aaf2SVladimir Kondratiev 		if (rc)
5460b39aaf2SVladimir Kondratiev 			return rc;
5470b39aaf2SVladimir Kondratiev 	}
5480b39aaf2SVladimir Kondratiev 
5490b39aaf2SVladimir Kondratiev 	rc = wmi_rxon(wil, on);
5500b39aaf2SVladimir Kondratiev 	if (rc)
5510b39aaf2SVladimir Kondratiev 		return rc;
5520b39aaf2SVladimir Kondratiev 
5530b39aaf2SVladimir Kondratiev 	return len;
5540b39aaf2SVladimir Kondratiev }
5550b39aaf2SVladimir Kondratiev 
5560b39aaf2SVladimir Kondratiev static const struct file_operations fops_rxon = {
5570b39aaf2SVladimir Kondratiev 	.write = wil_write_file_rxon,
5580b39aaf2SVladimir Kondratiev 	.open  = simple_open,
5590b39aaf2SVladimir Kondratiev };
5608fe59627SVladimir Kondratiev 
5610b39aaf2SVladimir Kondratiev /*---tx_mgmt---*/
5620b39aaf2SVladimir Kondratiev /* Write mgmt frame to this file to send it */
5630b39aaf2SVladimir Kondratiev static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
5640b39aaf2SVladimir Kondratiev 				     size_t len, loff_t *ppos)
5650b39aaf2SVladimir Kondratiev {
5660b39aaf2SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
5670b39aaf2SVladimir Kondratiev 	struct wiphy *wiphy = wil_to_wiphy(wil);
5680b39aaf2SVladimir Kondratiev 	struct wireless_dev *wdev = wil_to_wdev(wil);
5690b39aaf2SVladimir Kondratiev 	struct cfg80211_mgmt_tx_params params;
5700b39aaf2SVladimir Kondratiev 	int rc;
5710b39aaf2SVladimir Kondratiev 	void *frame = kmalloc(len, GFP_KERNEL);
5728fe59627SVladimir Kondratiev 
5730b39aaf2SVladimir Kondratiev 	if (!frame)
5740b39aaf2SVladimir Kondratiev 		return -ENOMEM;
5750b39aaf2SVladimir Kondratiev 
5760b39aaf2SVladimir Kondratiev 	if (copy_from_user(frame, buf, len))
5770b39aaf2SVladimir Kondratiev 		return -EIO;
5780b39aaf2SVladimir Kondratiev 
5790b39aaf2SVladimir Kondratiev 	params.buf = frame;
5800b39aaf2SVladimir Kondratiev 	params.len = len;
5810b39aaf2SVladimir Kondratiev 	params.chan = wdev->preset_chandef.chan;
5820b39aaf2SVladimir Kondratiev 
5830b39aaf2SVladimir Kondratiev 	rc = wil_cfg80211_mgmt_tx(wiphy, wdev, &params, NULL);
5840b39aaf2SVladimir Kondratiev 
5850b39aaf2SVladimir Kondratiev 	kfree(frame);
5860b39aaf2SVladimir Kondratiev 	wil_info(wil, "%s() -> %d\n", __func__, rc);
5870b39aaf2SVladimir Kondratiev 
5880b39aaf2SVladimir Kondratiev 	return len;
5890b39aaf2SVladimir Kondratiev }
5900b39aaf2SVladimir Kondratiev 
5910b39aaf2SVladimir Kondratiev static const struct file_operations fops_txmgmt = {
5920b39aaf2SVladimir Kondratiev 	.write = wil_write_file_txmgmt,
5930b39aaf2SVladimir Kondratiev 	.open  = simple_open,
5940b39aaf2SVladimir Kondratiev };
5952be7d22fSVladimir Kondratiev 
596ff974e40SVladimir Kondratiev /* Write WMI command (w/o mbox header) to this file to send it
597ff974e40SVladimir Kondratiev  * WMI starts from wil6210_mbox_hdr_wmi header
598ff974e40SVladimir Kondratiev  */
599ff974e40SVladimir Kondratiev static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
600ff974e40SVladimir Kondratiev 				  size_t len, loff_t *ppos)
601ff974e40SVladimir Kondratiev {
602ff974e40SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
603ff974e40SVladimir Kondratiev 	struct wil6210_mbox_hdr_wmi *wmi;
604ff974e40SVladimir Kondratiev 	void *cmd;
605ff974e40SVladimir Kondratiev 	int cmdlen = len - sizeof(struct wil6210_mbox_hdr_wmi);
606ff974e40SVladimir Kondratiev 	u16 cmdid;
607ff974e40SVladimir Kondratiev 	int rc, rc1;
608ff974e40SVladimir Kondratiev 
609ff974e40SVladimir Kondratiev 	if (cmdlen <= 0)
610ff974e40SVladimir Kondratiev 		return -EINVAL;
611ff974e40SVladimir Kondratiev 
612ff974e40SVladimir Kondratiev 	wmi = kmalloc(len, GFP_KERNEL);
613ff974e40SVladimir Kondratiev 	if (!wmi)
614ff974e40SVladimir Kondratiev 		return -ENOMEM;
615ff974e40SVladimir Kondratiev 
616ff974e40SVladimir Kondratiev 	rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
617ff974e40SVladimir Kondratiev 	if (rc < 0)
618ff974e40SVladimir Kondratiev 		return rc;
619ff974e40SVladimir Kondratiev 
620ff974e40SVladimir Kondratiev 	cmd = &wmi[1];
621ff974e40SVladimir Kondratiev 	cmdid = le16_to_cpu(wmi->id);
622ff974e40SVladimir Kondratiev 
623ff974e40SVladimir Kondratiev 	rc1 = wmi_send(wil, cmdid, cmd, cmdlen);
624ff974e40SVladimir Kondratiev 	kfree(wmi);
625ff974e40SVladimir Kondratiev 
626ff974e40SVladimir Kondratiev 	wil_info(wil, "%s(0x%04x[%d]) -> %d\n", __func__, cmdid, cmdlen, rc1);
627ff974e40SVladimir Kondratiev 
628ff974e40SVladimir Kondratiev 	return rc;
629ff974e40SVladimir Kondratiev }
630ff974e40SVladimir Kondratiev 
631ff974e40SVladimir Kondratiev static const struct file_operations fops_wmi = {
632ff974e40SVladimir Kondratiev 	.write = wil_write_file_wmi,
633ff974e40SVladimir Kondratiev 	.open  = simple_open,
634ff974e40SVladimir Kondratiev };
635ff974e40SVladimir Kondratiev 
636c236658fSVladimir Kondratiev static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
637c236658fSVladimir Kondratiev 			    const char *prefix)
638c236658fSVladimir Kondratiev {
639c236658fSVladimir Kondratiev 	char printbuf[16 * 3 + 2];
640c236658fSVladimir Kondratiev 	int i = 0;
6418fe59627SVladimir Kondratiev 
642c236658fSVladimir Kondratiev 	while (i < len) {
643c236658fSVladimir Kondratiev 		int l = min(len - i, 16);
6448fe59627SVladimir Kondratiev 
645c236658fSVladimir Kondratiev 		hex_dump_to_buffer(p + i, l, 16, 1, printbuf,
646c236658fSVladimir Kondratiev 				   sizeof(printbuf), false);
647c236658fSVladimir Kondratiev 		seq_printf(s, "%s%s\n", prefix, printbuf);
648c236658fSVladimir Kondratiev 		i += l;
649c236658fSVladimir Kondratiev 	}
650c236658fSVladimir Kondratiev }
651c236658fSVladimir Kondratiev 
652c236658fSVladimir Kondratiev static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
653c236658fSVladimir Kondratiev {
654c236658fSVladimir Kondratiev 	int i = 0;
655c236658fSVladimir Kondratiev 	int len = skb_headlen(skb);
656c236658fSVladimir Kondratiev 	void *p = skb->data;
657c236658fSVladimir Kondratiev 	int nr_frags = skb_shinfo(skb)->nr_frags;
658c236658fSVladimir Kondratiev 
659c236658fSVladimir Kondratiev 	seq_printf(s, "    len = %d\n", len);
660c236658fSVladimir Kondratiev 	wil_seq_hexdump(s, p, len, "      : ");
661c236658fSVladimir Kondratiev 
662c236658fSVladimir Kondratiev 	if (nr_frags) {
663c236658fSVladimir Kondratiev 		seq_printf(s, "    nr_frags = %d\n", nr_frags);
664c236658fSVladimir Kondratiev 		for (i = 0; i < nr_frags; i++) {
665c236658fSVladimir Kondratiev 			const struct skb_frag_struct *frag =
666c236658fSVladimir Kondratiev 					&skb_shinfo(skb)->frags[i];
667c236658fSVladimir Kondratiev 
668c236658fSVladimir Kondratiev 			len = skb_frag_size(frag);
669c236658fSVladimir Kondratiev 			p = skb_frag_address_safe(frag);
670c236658fSVladimir Kondratiev 			seq_printf(s, "    [%2d] : len = %d\n", i, len);
671c236658fSVladimir Kondratiev 			wil_seq_hexdump(s, p, len, "      : ");
672c236658fSVladimir Kondratiev 		}
673c236658fSVladimir Kondratiev 	}
674c236658fSVladimir Kondratiev }
675c236658fSVladimir Kondratiev 
6763a85543eSVladimir Kondratiev /*---------Tx/Rx descriptor------------*/
6772be7d22fSVladimir Kondratiev static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
6782be7d22fSVladimir Kondratiev {
6792be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
6803a85543eSVladimir Kondratiev 	struct vring *vring;
681af31cb5aSVladimir Kondratiev 	bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS);
6828fe59627SVladimir Kondratiev 
6838fe59627SVladimir Kondratiev 	vring = tx ? &wil->vring_tx[dbg_vring_index] : &wil->vring_rx;
6842be7d22fSVladimir Kondratiev 
6852be7d22fSVladimir Kondratiev 	if (!vring->va) {
686af31cb5aSVladimir Kondratiev 		if (tx)
6873a85543eSVladimir Kondratiev 			seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index);
6883a85543eSVladimir Kondratiev 		else
6893a85543eSVladimir Kondratiev 			seq_puts(s, "No Rx VRING\n");
6902be7d22fSVladimir Kondratiev 		return 0;
6912be7d22fSVladimir Kondratiev 	}
6922be7d22fSVladimir Kondratiev 
6932be7d22fSVladimir Kondratiev 	if (dbg_txdesc_index < vring->size) {
6943a85543eSVladimir Kondratiev 		/* use struct vring_tx_desc for Rx as well,
6953a85543eSVladimir Kondratiev 		 * only field used, .dma.length, is the same
6963a85543eSVladimir Kondratiev 		 */
6972be7d22fSVladimir Kondratiev 		volatile struct vring_tx_desc *d =
6988fe59627SVladimir Kondratiev 				&vring->va[dbg_txdesc_index].tx;
6992be7d22fSVladimir Kondratiev 		volatile u32 *u = (volatile u32 *)d;
700f88f113aSVladimir Kondratiev 		struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb;
7012be7d22fSVladimir Kondratiev 
702af31cb5aSVladimir Kondratiev 		if (tx)
7033a85543eSVladimir Kondratiev 			seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index,
7043a85543eSVladimir Kondratiev 				   dbg_txdesc_index);
7053a85543eSVladimir Kondratiev 		else
7063a85543eSVladimir Kondratiev 			seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
7072be7d22fSVladimir Kondratiev 		seq_printf(s, "  MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
7082be7d22fSVladimir Kondratiev 			   u[0], u[1], u[2], u[3]);
7092be7d22fSVladimir Kondratiev 		seq_printf(s, "  DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
7102be7d22fSVladimir Kondratiev 			   u[4], u[5], u[6], u[7]);
71139c52ee8SVladimir Kondratiev 		seq_printf(s, "  SKB = 0x%p\n", skb);
7122be7d22fSVladimir Kondratiev 
7132be7d22fSVladimir Kondratiev 		if (skb) {
714c236658fSVladimir Kondratiev 			skb_get(skb);
715c236658fSVladimir Kondratiev 			wil_seq_print_skb(s, skb);
716c236658fSVladimir Kondratiev 			kfree_skb(skb);
7172be7d22fSVladimir Kondratiev 		}
7188fe59627SVladimir Kondratiev 		seq_puts(s, "}\n");
7192be7d22fSVladimir Kondratiev 	} else {
720af31cb5aSVladimir Kondratiev 		if (tx)
7213a85543eSVladimir Kondratiev 			seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
7223a85543eSVladimir Kondratiev 				   dbg_vring_index, dbg_txdesc_index,
7233a85543eSVladimir Kondratiev 				   vring->size);
7243a85543eSVladimir Kondratiev 		else
7253a85543eSVladimir Kondratiev 			seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
7262be7d22fSVladimir Kondratiev 				   dbg_txdesc_index, vring->size);
7272be7d22fSVladimir Kondratiev 	}
7282be7d22fSVladimir Kondratiev 
7292be7d22fSVladimir Kondratiev 	return 0;
7302be7d22fSVladimir Kondratiev }
7312be7d22fSVladimir Kondratiev 
7322be7d22fSVladimir Kondratiev static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
7332be7d22fSVladimir Kondratiev {
7342be7d22fSVladimir Kondratiev 	return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
7352be7d22fSVladimir Kondratiev }
7362be7d22fSVladimir Kondratiev 
7372be7d22fSVladimir Kondratiev static const struct file_operations fops_txdesc = {
7382be7d22fSVladimir Kondratiev 	.open		= wil_txdesc_seq_open,
7392be7d22fSVladimir Kondratiev 	.release	= single_release,
7402be7d22fSVladimir Kondratiev 	.read		= seq_read,
7412be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
7422be7d22fSVladimir Kondratiev };
7432be7d22fSVladimir Kondratiev 
7442be7d22fSVladimir Kondratiev /*---------beamforming------------*/
74536345ac3SVladimir Kondratiev static char *wil_bfstatus_str(u32 status)
74636345ac3SVladimir Kondratiev {
74736345ac3SVladimir Kondratiev 	switch (status) {
74836345ac3SVladimir Kondratiev 	case 0:
74936345ac3SVladimir Kondratiev 		return "Failed";
75036345ac3SVladimir Kondratiev 	case 1:
75136345ac3SVladimir Kondratiev 		return "OK";
75236345ac3SVladimir Kondratiev 	case 2:
75336345ac3SVladimir Kondratiev 		return "Retrying";
75436345ac3SVladimir Kondratiev 	default:
75536345ac3SVladimir Kondratiev 		return "??";
75636345ac3SVladimir Kondratiev 	}
75736345ac3SVladimir Kondratiev }
75836345ac3SVladimir Kondratiev 
75936345ac3SVladimir Kondratiev static bool is_all_zeros(void * const x_, size_t sz)
76036345ac3SVladimir Kondratiev {
76136345ac3SVladimir Kondratiev 	/* if reply is all-0, ignore this CID */
76236345ac3SVladimir Kondratiev 	u32 *x = x_;
76336345ac3SVladimir Kondratiev 	int n;
76436345ac3SVladimir Kondratiev 
76536345ac3SVladimir Kondratiev 	for (n = 0; n < sz / sizeof(*x); n++)
76636345ac3SVladimir Kondratiev 		if (x[n])
76736345ac3SVladimir Kondratiev 			return false;
76836345ac3SVladimir Kondratiev 
76936345ac3SVladimir Kondratiev 	return true;
77036345ac3SVladimir Kondratiev }
77136345ac3SVladimir Kondratiev 
7722be7d22fSVladimir Kondratiev static int wil_bf_debugfs_show(struct seq_file *s, void *data)
7732be7d22fSVladimir Kondratiev {
77436345ac3SVladimir Kondratiev 	int rc;
77536345ac3SVladimir Kondratiev 	int i;
7762be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
77736345ac3SVladimir Kondratiev 	struct wmi_notify_req_cmd cmd = {
77836345ac3SVladimir Kondratiev 		.interval_usec = 0,
77936345ac3SVladimir Kondratiev 	};
78036345ac3SVladimir Kondratiev 	struct {
78136345ac3SVladimir Kondratiev 		struct wil6210_mbox_hdr_wmi wmi;
78236345ac3SVladimir Kondratiev 		struct wmi_notify_req_done_event evt;
78336345ac3SVladimir Kondratiev 	} __packed reply;
78436345ac3SVladimir Kondratiev 
78536345ac3SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
78636345ac3SVladimir Kondratiev 		u32 status;
78736345ac3SVladimir Kondratiev 
78836345ac3SVladimir Kondratiev 		cmd.cid = i;
78936345ac3SVladimir Kondratiev 		rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd),
79036345ac3SVladimir Kondratiev 			      WMI_NOTIFY_REQ_DONE_EVENTID, &reply,
79136345ac3SVladimir Kondratiev 			      sizeof(reply), 20);
79236345ac3SVladimir Kondratiev 		/* if reply is all-0, ignore this CID */
79336345ac3SVladimir Kondratiev 		if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt)))
79436345ac3SVladimir Kondratiev 			continue;
79536345ac3SVladimir Kondratiev 
79636345ac3SVladimir Kondratiev 		status = le32_to_cpu(reply.evt.status);
79736345ac3SVladimir Kondratiev 		seq_printf(s, "CID %d {\n"
79836345ac3SVladimir Kondratiev 			   "  TSF = 0x%016llx\n"
79936345ac3SVladimir Kondratiev 			   "  TxMCS = %2d TxTpt = %4d\n"
80036345ac3SVladimir Kondratiev 			   "  SQI = %4d\n"
80136345ac3SVladimir Kondratiev 			   "  Status = 0x%08x %s\n"
80236345ac3SVladimir Kondratiev 			   "  Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
80336345ac3SVladimir Kondratiev 			   "  Goodput(rx:tx) %4d:%4d\n"
80436345ac3SVladimir Kondratiev 			   "}\n",
80536345ac3SVladimir Kondratiev 			   i,
80636345ac3SVladimir Kondratiev 			   le64_to_cpu(reply.evt.tsf),
80736345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.bf_mcs),
80836345ac3SVladimir Kondratiev 			   le32_to_cpu(reply.evt.tx_tpt),
80936345ac3SVladimir Kondratiev 			   reply.evt.sqi,
81036345ac3SVladimir Kondratiev 			   status, wil_bfstatus_str(status),
81136345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.my_rx_sector),
81236345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.my_tx_sector),
81336345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.other_rx_sector),
81436345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.other_tx_sector),
81536345ac3SVladimir Kondratiev 			   le32_to_cpu(reply.evt.rx_goodput),
81636345ac3SVladimir Kondratiev 			   le32_to_cpu(reply.evt.tx_goodput));
81736345ac3SVladimir Kondratiev 	}
8182be7d22fSVladimir Kondratiev 	return 0;
8192be7d22fSVladimir Kondratiev }
8202be7d22fSVladimir Kondratiev 
8212be7d22fSVladimir Kondratiev static int wil_bf_seq_open(struct inode *inode, struct file *file)
8222be7d22fSVladimir Kondratiev {
8232be7d22fSVladimir Kondratiev 	return single_open(file, wil_bf_debugfs_show, inode->i_private);
8242be7d22fSVladimir Kondratiev }
8252be7d22fSVladimir Kondratiev 
8262be7d22fSVladimir Kondratiev static const struct file_operations fops_bf = {
8272be7d22fSVladimir Kondratiev 	.open		= wil_bf_seq_open,
8282be7d22fSVladimir Kondratiev 	.release	= single_release,
8292be7d22fSVladimir Kondratiev 	.read		= seq_read,
8302be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
8312be7d22fSVladimir Kondratiev };
8328fe59627SVladimir Kondratiev 
8332be7d22fSVladimir Kondratiev /*---------SSID------------*/
8342be7d22fSVladimir Kondratiev static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf,
8352be7d22fSVladimir Kondratiev 				  size_t count, loff_t *ppos)
8362be7d22fSVladimir Kondratiev {
8372be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
8382be7d22fSVladimir Kondratiev 	struct wireless_dev *wdev = wil_to_wdev(wil);
8392be7d22fSVladimir Kondratiev 
8402be7d22fSVladimir Kondratiev 	return simple_read_from_buffer(user_buf, count, ppos,
8412be7d22fSVladimir Kondratiev 				       wdev->ssid, wdev->ssid_len);
8422be7d22fSVladimir Kondratiev }
8432be7d22fSVladimir Kondratiev 
8442be7d22fSVladimir Kondratiev static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf,
8452be7d22fSVladimir Kondratiev 				   size_t count, loff_t *ppos)
8462be7d22fSVladimir Kondratiev {
8472be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
8482be7d22fSVladimir Kondratiev 	struct wireless_dev *wdev = wil_to_wdev(wil);
8492be7d22fSVladimir Kondratiev 	struct net_device *ndev = wil_to_ndev(wil);
8502be7d22fSVladimir Kondratiev 
8512be7d22fSVladimir Kondratiev 	if (*ppos != 0) {
8522be7d22fSVladimir Kondratiev 		wil_err(wil, "Unable to set SSID substring from [%d]\n",
8532be7d22fSVladimir Kondratiev 			(int)*ppos);
8542be7d22fSVladimir Kondratiev 		return -EINVAL;
8552be7d22fSVladimir Kondratiev 	}
8562be7d22fSVladimir Kondratiev 
8572be7d22fSVladimir Kondratiev 	if (count > sizeof(wdev->ssid)) {
8582be7d22fSVladimir Kondratiev 		wil_err(wil, "SSID too long, len = %d\n", (int)count);
8592be7d22fSVladimir Kondratiev 		return -EINVAL;
8602be7d22fSVladimir Kondratiev 	}
8612be7d22fSVladimir Kondratiev 	if (netif_running(ndev)) {
8622be7d22fSVladimir Kondratiev 		wil_err(wil, "Unable to change SSID on running interface\n");
8632be7d22fSVladimir Kondratiev 		return -EINVAL;
8642be7d22fSVladimir Kondratiev 	}
8652be7d22fSVladimir Kondratiev 
8662be7d22fSVladimir Kondratiev 	wdev->ssid_len = count;
8672be7d22fSVladimir Kondratiev 	return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos,
8682be7d22fSVladimir Kondratiev 				      buf, count);
8692be7d22fSVladimir Kondratiev }
8702be7d22fSVladimir Kondratiev 
8712be7d22fSVladimir Kondratiev static const struct file_operations fops_ssid = {
8722be7d22fSVladimir Kondratiev 	.read = wil_read_file_ssid,
8732be7d22fSVladimir Kondratiev 	.write = wil_write_file_ssid,
87493ecbd64SWei Yongjun 	.open  = simple_open,
8752be7d22fSVladimir Kondratiev };
8762be7d22fSVladimir Kondratiev 
8771a2780e0SVladimir Kondratiev /*---------temp------------*/
8781a2780e0SVladimir Kondratiev static void print_temp(struct seq_file *s, const char *prefix, u32 t)
8791a2780e0SVladimir Kondratiev {
8801a2780e0SVladimir Kondratiev 	switch (t) {
8811a2780e0SVladimir Kondratiev 	case 0:
8821a2780e0SVladimir Kondratiev 	case ~(u32)0:
8831a2780e0SVladimir Kondratiev 		seq_printf(s, "%s N/A\n", prefix);
8841a2780e0SVladimir Kondratiev 	break;
8851a2780e0SVladimir Kondratiev 	default:
8861a2780e0SVladimir Kondratiev 		seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
8871a2780e0SVladimir Kondratiev 		break;
8881a2780e0SVladimir Kondratiev 	}
8891a2780e0SVladimir Kondratiev }
8901a2780e0SVladimir Kondratiev 
8911a2780e0SVladimir Kondratiev static int wil_temp_debugfs_show(struct seq_file *s, void *data)
8921a2780e0SVladimir Kondratiev {
8931a2780e0SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
8941a2780e0SVladimir Kondratiev 	u32 t_m, t_r;
8951a2780e0SVladimir Kondratiev 	int rc = wmi_get_temperature(wil, &t_m, &t_r);
8968fe59627SVladimir Kondratiev 
8971a2780e0SVladimir Kondratiev 	if (rc) {
8988fe59627SVladimir Kondratiev 		seq_puts(s, "Failed\n");
8991a2780e0SVladimir Kondratiev 		return 0;
9001a2780e0SVladimir Kondratiev 	}
9011a2780e0SVladimir Kondratiev 
902d45cff9fSVladimir Kondratiev 	print_temp(s, "T_mac   =", t_m);
903d45cff9fSVladimir Kondratiev 	print_temp(s, "T_radio =", t_r);
9041a2780e0SVladimir Kondratiev 
9051a2780e0SVladimir Kondratiev 	return 0;
9061a2780e0SVladimir Kondratiev }
9071a2780e0SVladimir Kondratiev 
9081a2780e0SVladimir Kondratiev static int wil_temp_seq_open(struct inode *inode, struct file *file)
9091a2780e0SVladimir Kondratiev {
9101a2780e0SVladimir Kondratiev 	return single_open(file, wil_temp_debugfs_show, inode->i_private);
9111a2780e0SVladimir Kondratiev }
9121a2780e0SVladimir Kondratiev 
9131a2780e0SVladimir Kondratiev static const struct file_operations fops_temp = {
9141a2780e0SVladimir Kondratiev 	.open		= wil_temp_seq_open,
9151a2780e0SVladimir Kondratiev 	.release	= single_release,
9161a2780e0SVladimir Kondratiev 	.read		= seq_read,
9171a2780e0SVladimir Kondratiev 	.llseek		= seq_lseek,
9181a2780e0SVladimir Kondratiev };
9191a2780e0SVladimir Kondratiev 
9209eb82d43SVladimir Kondratiev /*---------freq------------*/
9219eb82d43SVladimir Kondratiev static int wil_freq_debugfs_show(struct seq_file *s, void *data)
9229eb82d43SVladimir Kondratiev {
9239eb82d43SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
9249eb82d43SVladimir Kondratiev 	struct wireless_dev *wdev = wil_to_wdev(wil);
9259eb82d43SVladimir Kondratiev 	u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
9269eb82d43SVladimir Kondratiev 
9279eb82d43SVladimir Kondratiev 	seq_printf(s, "Freq = %d\n", freq);
9289eb82d43SVladimir Kondratiev 
9299eb82d43SVladimir Kondratiev 	return 0;
9309eb82d43SVladimir Kondratiev }
9319eb82d43SVladimir Kondratiev 
9329eb82d43SVladimir Kondratiev static int wil_freq_seq_open(struct inode *inode, struct file *file)
9339eb82d43SVladimir Kondratiev {
9349eb82d43SVladimir Kondratiev 	return single_open(file, wil_freq_debugfs_show, inode->i_private);
9359eb82d43SVladimir Kondratiev }
9369eb82d43SVladimir Kondratiev 
9379eb82d43SVladimir Kondratiev static const struct file_operations fops_freq = {
9389eb82d43SVladimir Kondratiev 	.open		= wil_freq_seq_open,
9399eb82d43SVladimir Kondratiev 	.release	= single_release,
9409eb82d43SVladimir Kondratiev 	.read		= seq_read,
9419eb82d43SVladimir Kondratiev 	.llseek		= seq_lseek,
9429eb82d43SVladimir Kondratiev };
9439eb82d43SVladimir Kondratiev 
9449eb82d43SVladimir Kondratiev /*---------link------------*/
9459eb82d43SVladimir Kondratiev static int wil_link_debugfs_show(struct seq_file *s, void *data)
9469eb82d43SVladimir Kondratiev {
9479eb82d43SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
9489eb82d43SVladimir Kondratiev 	struct station_info sinfo;
9499eb82d43SVladimir Kondratiev 	int i, rc;
9509eb82d43SVladimir Kondratiev 
9519eb82d43SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
9529eb82d43SVladimir Kondratiev 		struct wil_sta_info *p = &wil->sta[i];
9539eb82d43SVladimir Kondratiev 		char *status = "unknown";
9548fe59627SVladimir Kondratiev 
9559eb82d43SVladimir Kondratiev 		switch (p->status) {
9569eb82d43SVladimir Kondratiev 		case wil_sta_unused:
9579eb82d43SVladimir Kondratiev 			status = "unused   ";
9589eb82d43SVladimir Kondratiev 			break;
9599eb82d43SVladimir Kondratiev 		case wil_sta_conn_pending:
9609eb82d43SVladimir Kondratiev 			status = "pending  ";
9619eb82d43SVladimir Kondratiev 			break;
9629eb82d43SVladimir Kondratiev 		case wil_sta_connected:
9639eb82d43SVladimir Kondratiev 			status = "connected";
9649eb82d43SVladimir Kondratiev 			break;
9659eb82d43SVladimir Kondratiev 		}
9669eb82d43SVladimir Kondratiev 		seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
9679eb82d43SVladimir Kondratiev 			   (p->data_port_open ? " data_port_open" : ""));
9689eb82d43SVladimir Kondratiev 
9699eb82d43SVladimir Kondratiev 		if (p->status == wil_sta_connected) {
9709eb82d43SVladimir Kondratiev 			rc = wil_cid_fill_sinfo(wil, i, &sinfo);
9719eb82d43SVladimir Kondratiev 			if (rc)
9729eb82d43SVladimir Kondratiev 				return rc;
9739eb82d43SVladimir Kondratiev 
9749eb82d43SVladimir Kondratiev 			seq_printf(s, "  Tx_mcs = %d\n", sinfo.txrate.mcs);
9759eb82d43SVladimir Kondratiev 			seq_printf(s, "  Rx_mcs = %d\n", sinfo.rxrate.mcs);
9769eb82d43SVladimir Kondratiev 			seq_printf(s, "  SQ     = %d\n", sinfo.signal);
9779eb82d43SVladimir Kondratiev 		}
9789eb82d43SVladimir Kondratiev 	}
9799eb82d43SVladimir Kondratiev 
9809eb82d43SVladimir Kondratiev 	return 0;
9819eb82d43SVladimir Kondratiev }
9829eb82d43SVladimir Kondratiev 
9839eb82d43SVladimir Kondratiev static int wil_link_seq_open(struct inode *inode, struct file *file)
9849eb82d43SVladimir Kondratiev {
9859eb82d43SVladimir Kondratiev 	return single_open(file, wil_link_debugfs_show, inode->i_private);
9869eb82d43SVladimir Kondratiev }
9879eb82d43SVladimir Kondratiev 
9889eb82d43SVladimir Kondratiev static const struct file_operations fops_link = {
9899eb82d43SVladimir Kondratiev 	.open		= wil_link_seq_open,
9909eb82d43SVladimir Kondratiev 	.release	= single_release,
9919eb82d43SVladimir Kondratiev 	.read		= seq_read,
9929eb82d43SVladimir Kondratiev 	.llseek		= seq_lseek,
9939eb82d43SVladimir Kondratiev };
9949eb82d43SVladimir Kondratiev 
99584bb29b7SVladimir Kondratiev /*---------info------------*/
99684bb29b7SVladimir Kondratiev static int wil_info_debugfs_show(struct seq_file *s, void *data)
99784bb29b7SVladimir Kondratiev {
998be299858SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
999be299858SVladimir Kondratiev 	struct net_device *ndev = wil_to_ndev(wil);
100084bb29b7SVladimir Kondratiev 	int is_ac = power_supply_is_system_supplied();
1001be299858SVladimir Kondratiev 	int rx = atomic_xchg(&wil->isr_count_rx, 0);
1002be299858SVladimir Kondratiev 	int tx = atomic_xchg(&wil->isr_count_tx, 0);
1003be299858SVladimir Kondratiev 	static ulong rxf_old, txf_old;
1004be299858SVladimir Kondratiev 	ulong rxf = ndev->stats.rx_packets;
1005be299858SVladimir Kondratiev 	ulong txf = ndev->stats.tx_packets;
100655f8f680SVladimir Kondratiev 	unsigned int i;
100784bb29b7SVladimir Kondratiev 
100884bb29b7SVladimir Kondratiev 	/* >0 : AC; 0 : battery; <0 : error */
100984bb29b7SVladimir Kondratiev 	seq_printf(s, "AC powered : %d\n", is_ac);
1010be299858SVladimir Kondratiev 	seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
1011be299858SVladimir Kondratiev 	seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
1012be299858SVladimir Kondratiev 	rxf_old = rxf;
1013be299858SVladimir Kondratiev 	txf_old = txf;
101484bb29b7SVladimir Kondratiev 
101555f8f680SVladimir Kondratiev #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
101655f8f680SVladimir Kondratiev 	" " __stringify(x) : ""
101755f8f680SVladimir Kondratiev 
101855f8f680SVladimir Kondratiev 	for (i = 0; i < ndev->num_tx_queues; i++) {
101955f8f680SVladimir Kondratiev 		struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
102055f8f680SVladimir Kondratiev 		unsigned long state = txq->state;
102155f8f680SVladimir Kondratiev 
102255f8f680SVladimir Kondratiev 		seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
102355f8f680SVladimir Kondratiev 			   CHECK_QSTATE(DRV_XOFF),
102455f8f680SVladimir Kondratiev 			   CHECK_QSTATE(STACK_XOFF),
102555f8f680SVladimir Kondratiev 			   CHECK_QSTATE(FROZEN)
102655f8f680SVladimir Kondratiev 			  );
102755f8f680SVladimir Kondratiev 	}
102855f8f680SVladimir Kondratiev #undef CHECK_QSTATE
102984bb29b7SVladimir Kondratiev 	return 0;
103084bb29b7SVladimir Kondratiev }
103184bb29b7SVladimir Kondratiev 
103284bb29b7SVladimir Kondratiev static int wil_info_seq_open(struct inode *inode, struct file *file)
103384bb29b7SVladimir Kondratiev {
103484bb29b7SVladimir Kondratiev 	return single_open(file, wil_info_debugfs_show, inode->i_private);
103584bb29b7SVladimir Kondratiev }
103684bb29b7SVladimir Kondratiev 
103784bb29b7SVladimir Kondratiev static const struct file_operations fops_info = {
103884bb29b7SVladimir Kondratiev 	.open		= wil_info_seq_open,
103984bb29b7SVladimir Kondratiev 	.release	= single_release,
104084bb29b7SVladimir Kondratiev 	.read		= seq_read,
104184bb29b7SVladimir Kondratiev 	.llseek		= seq_lseek,
104284bb29b7SVladimir Kondratiev };
104384bb29b7SVladimir Kondratiev 
1044*c33407a8SVladimir Kondratiev /*---------recovery------------*/
1045*c33407a8SVladimir Kondratiev /* mode = [manual|auto]
1046*c33407a8SVladimir Kondratiev  * state = [idle|pending|running]
1047*c33407a8SVladimir Kondratiev  */
1048*c33407a8SVladimir Kondratiev static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf,
1049*c33407a8SVladimir Kondratiev 				      size_t count, loff_t *ppos)
1050*c33407a8SVladimir Kondratiev {
1051*c33407a8SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
1052*c33407a8SVladimir Kondratiev 	char buf[80];
1053*c33407a8SVladimir Kondratiev 	int n;
1054*c33407a8SVladimir Kondratiev 	static const char * const sstate[] = {"idle", "pending", "running"};
1055*c33407a8SVladimir Kondratiev 
1056*c33407a8SVladimir Kondratiev 	n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n",
1057*c33407a8SVladimir Kondratiev 		     no_fw_recovery ? "manual" : "auto",
1058*c33407a8SVladimir Kondratiev 		     sstate[wil->recovery_state]);
1059*c33407a8SVladimir Kondratiev 
1060*c33407a8SVladimir Kondratiev 	n = min_t(int, n, sizeof(buf));
1061*c33407a8SVladimir Kondratiev 
1062*c33407a8SVladimir Kondratiev 	return simple_read_from_buffer(user_buf, count, ppos,
1063*c33407a8SVladimir Kondratiev 				       buf, n);
1064*c33407a8SVladimir Kondratiev }
1065*c33407a8SVladimir Kondratiev 
1066*c33407a8SVladimir Kondratiev static ssize_t wil_write_file_recovery(struct file *file,
1067*c33407a8SVladimir Kondratiev 				       const char __user *buf_,
1068*c33407a8SVladimir Kondratiev 				       size_t count, loff_t *ppos)
1069*c33407a8SVladimir Kondratiev {
1070*c33407a8SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
1071*c33407a8SVladimir Kondratiev 	static const char run_command[] = "run";
1072*c33407a8SVladimir Kondratiev 	char buf[sizeof(run_command) + 1]; /* to detect "runx" */
1073*c33407a8SVladimir Kondratiev 	ssize_t rc;
1074*c33407a8SVladimir Kondratiev 
1075*c33407a8SVladimir Kondratiev 	if (wil->recovery_state != fw_recovery_pending) {
1076*c33407a8SVladimir Kondratiev 		wil_err(wil, "No recovery pending\n");
1077*c33407a8SVladimir Kondratiev 		return -EINVAL;
1078*c33407a8SVladimir Kondratiev 	}
1079*c33407a8SVladimir Kondratiev 
1080*c33407a8SVladimir Kondratiev 	if (*ppos != 0) {
1081*c33407a8SVladimir Kondratiev 		wil_err(wil, "Offset [%d]\n", (int)*ppos);
1082*c33407a8SVladimir Kondratiev 		return -EINVAL;
1083*c33407a8SVladimir Kondratiev 	}
1084*c33407a8SVladimir Kondratiev 
1085*c33407a8SVladimir Kondratiev 	if (count > sizeof(buf)) {
1086*c33407a8SVladimir Kondratiev 		wil_err(wil, "Input too long, len = %d\n", (int)count);
1087*c33407a8SVladimir Kondratiev 		return -EINVAL;
1088*c33407a8SVladimir Kondratiev 	}
1089*c33407a8SVladimir Kondratiev 
1090*c33407a8SVladimir Kondratiev 	rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count);
1091*c33407a8SVladimir Kondratiev 	if (rc < 0)
1092*c33407a8SVladimir Kondratiev 		return rc;
1093*c33407a8SVladimir Kondratiev 
1094*c33407a8SVladimir Kondratiev 	buf[rc] = '\0';
1095*c33407a8SVladimir Kondratiev 	if (0 == strcmp(buf, run_command))
1096*c33407a8SVladimir Kondratiev 		wil_set_recovery_state(wil, fw_recovery_running);
1097*c33407a8SVladimir Kondratiev 	else
1098*c33407a8SVladimir Kondratiev 		wil_err(wil, "Bad recovery command \"%s\"\n", buf);
1099*c33407a8SVladimir Kondratiev 
1100*c33407a8SVladimir Kondratiev 	return rc;
1101*c33407a8SVladimir Kondratiev }
1102*c33407a8SVladimir Kondratiev 
1103*c33407a8SVladimir Kondratiev static const struct file_operations fops_recovery = {
1104*c33407a8SVladimir Kondratiev 	.read = wil_read_file_recovery,
1105*c33407a8SVladimir Kondratiev 	.write = wil_write_file_recovery,
1106*c33407a8SVladimir Kondratiev 	.open  = simple_open,
1107*c33407a8SVladimir Kondratiev };
1108*c33407a8SVladimir Kondratiev 
11093df2cd36SVladimir Kondratiev /*---------Station matrix------------*/
1110b4490f42SVladimir Kondratiev static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
1111b4490f42SVladimir Kondratiev {
1112b4490f42SVladimir Kondratiev 	int i;
1113b4490f42SVladimir Kondratiev 	u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
11148fe59627SVladimir Kondratiev 
1115b4490f42SVladimir Kondratiev 	seq_printf(s, "0x%03x [", r->head_seq_num);
1116b4490f42SVladimir Kondratiev 	for (i = 0; i < r->buf_size; i++) {
1117b4490f42SVladimir Kondratiev 		if (i == index)
1118b4490f42SVladimir Kondratiev 			seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
1119b4490f42SVladimir Kondratiev 		else
1120b4490f42SVladimir Kondratiev 			seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
1121b4490f42SVladimir Kondratiev 	}
1122d5b1c32fSVladimir Kondratiev 	seq_printf(s, "] last drop 0x%03x\n", r->ssn_last_drop);
1123b4490f42SVladimir Kondratiev }
11243df2cd36SVladimir Kondratiev 
11253df2cd36SVladimir Kondratiev static int wil_sta_debugfs_show(struct seq_file *s, void *data)
11263df2cd36SVladimir Kondratiev {
11273df2cd36SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
1128b4490f42SVladimir Kondratiev 	int i, tid;
1129ec81b5adSDedy Lansky 	unsigned long flags;
11303df2cd36SVladimir Kondratiev 
11313df2cd36SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
11323df2cd36SVladimir Kondratiev 		struct wil_sta_info *p = &wil->sta[i];
11333df2cd36SVladimir Kondratiev 		char *status = "unknown";
11348fe59627SVladimir Kondratiev 
11353df2cd36SVladimir Kondratiev 		switch (p->status) {
11363df2cd36SVladimir Kondratiev 		case wil_sta_unused:
11373df2cd36SVladimir Kondratiev 			status = "unused   ";
11383df2cd36SVladimir Kondratiev 			break;
11393df2cd36SVladimir Kondratiev 		case wil_sta_conn_pending:
11403df2cd36SVladimir Kondratiev 			status = "pending  ";
11413df2cd36SVladimir Kondratiev 			break;
11423df2cd36SVladimir Kondratiev 		case wil_sta_connected:
11433df2cd36SVladimir Kondratiev 			status = "connected";
11443df2cd36SVladimir Kondratiev 			break;
11453df2cd36SVladimir Kondratiev 		}
1146e58c9f70SVladimir Kondratiev 		seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
1147e58c9f70SVladimir Kondratiev 			   (p->data_port_open ? " data_port_open" : ""));
1148b4490f42SVladimir Kondratiev 
1149b4490f42SVladimir Kondratiev 		if (p->status == wil_sta_connected) {
1150ec81b5adSDedy Lansky 			spin_lock_irqsave(&p->tid_rx_lock, flags);
1151b4490f42SVladimir Kondratiev 			for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1152b4490f42SVladimir Kondratiev 				struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
11538fe59627SVladimir Kondratiev 
1154b4490f42SVladimir Kondratiev 				if (r) {
1155b4490f42SVladimir Kondratiev 					seq_printf(s, "[%2d] ", tid);
1156b4490f42SVladimir Kondratiev 					wil_print_rxtid(s, r);
1157b4490f42SVladimir Kondratiev 				}
1158b4490f42SVladimir Kondratiev 			}
1159ec81b5adSDedy Lansky 			spin_unlock_irqrestore(&p->tid_rx_lock, flags);
1160b4490f42SVladimir Kondratiev 		}
11613df2cd36SVladimir Kondratiev 	}
11623df2cd36SVladimir Kondratiev 
11633df2cd36SVladimir Kondratiev 	return 0;
11643df2cd36SVladimir Kondratiev }
11653df2cd36SVladimir Kondratiev 
11663df2cd36SVladimir Kondratiev static int wil_sta_seq_open(struct inode *inode, struct file *file)
11673df2cd36SVladimir Kondratiev {
11683df2cd36SVladimir Kondratiev 	return single_open(file, wil_sta_debugfs_show, inode->i_private);
11693df2cd36SVladimir Kondratiev }
11703df2cd36SVladimir Kondratiev 
11713df2cd36SVladimir Kondratiev static const struct file_operations fops_sta = {
11723df2cd36SVladimir Kondratiev 	.open		= wil_sta_seq_open,
11733df2cd36SVladimir Kondratiev 	.release	= single_release,
11743df2cd36SVladimir Kondratiev 	.read		= seq_read,
11753df2cd36SVladimir Kondratiev 	.llseek		= seq_lseek,
11763df2cd36SVladimir Kondratiev };
11773df2cd36SVladimir Kondratiev 
11782be7d22fSVladimir Kondratiev /*----------------*/
1179b541d0a0SVladimir Kondratiev static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
1180b541d0a0SVladimir Kondratiev 				       struct dentry *dbg)
1181b541d0a0SVladimir Kondratiev {
1182b541d0a0SVladimir Kondratiev 	int i;
1183b541d0a0SVladimir Kondratiev 	char name[32];
1184b541d0a0SVladimir Kondratiev 
1185b541d0a0SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
1186b541d0a0SVladimir Kondratiev 		struct debugfs_blob_wrapper *blob = &wil->blobs[i];
1187b541d0a0SVladimir Kondratiev 		const struct fw_map *map = &fw_mapping[i];
1188b541d0a0SVladimir Kondratiev 
1189b541d0a0SVladimir Kondratiev 		if (!map->name)
1190b541d0a0SVladimir Kondratiev 			continue;
1191b541d0a0SVladimir Kondratiev 
1192b541d0a0SVladimir Kondratiev 		blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
1193b541d0a0SVladimir Kondratiev 		blob->size = map->to - map->from;
1194b541d0a0SVladimir Kondratiev 		snprintf(name, sizeof(name), "blob_%s", map->name);
1195b541d0a0SVladimir Kondratiev 		wil_debugfs_create_ioblob(name, S_IRUGO, dbg, blob);
1196b541d0a0SVladimir Kondratiev 	}
1197b541d0a0SVladimir Kondratiev }
1198b541d0a0SVladimir Kondratiev 
1199b7cde470SVladimir Kondratiev /* misc files */
1200b7cde470SVladimir Kondratiev static const struct {
1201b7cde470SVladimir Kondratiev 	const char *name;
1202b7cde470SVladimir Kondratiev 	umode_t mode;
1203b7cde470SVladimir Kondratiev 	const struct file_operations *fops;
1204b7cde470SVladimir Kondratiev } dbg_files[] = {
1205b7cde470SVladimir Kondratiev 	{"mbox",	S_IRUGO,		&fops_mbox},
1206b7cde470SVladimir Kondratiev 	{"vrings",	S_IRUGO,		&fops_vring},
1207b7cde470SVladimir Kondratiev 	{"stations",	S_IRUGO,		&fops_sta},
1208b7cde470SVladimir Kondratiev 	{"desc",	S_IRUGO,		&fops_txdesc},
1209b7cde470SVladimir Kondratiev 	{"bf",		S_IRUGO,		&fops_bf},
1210b7cde470SVladimir Kondratiev 	{"ssid",	S_IRUGO | S_IWUSR,	&fops_ssid},
1211b7cde470SVladimir Kondratiev 	{"mem_val",	S_IRUGO,		&fops_memread},
1212b7cde470SVladimir Kondratiev 	{"reset",		  S_IWUSR,	&fops_reset},
1213b7cde470SVladimir Kondratiev 	{"rxon",		  S_IWUSR,	&fops_rxon},
1214b7cde470SVladimir Kondratiev 	{"tx_mgmt",		  S_IWUSR,	&fops_txmgmt},
1215b7cde470SVladimir Kondratiev 	{"wmi_send",		  S_IWUSR,	&fops_wmi},
1216b7cde470SVladimir Kondratiev 	{"temp",	S_IRUGO,		&fops_temp},
1217b7cde470SVladimir Kondratiev 	{"freq",	S_IRUGO,		&fops_freq},
1218b7cde470SVladimir Kondratiev 	{"link",	S_IRUGO,		&fops_link},
1219b7cde470SVladimir Kondratiev 	{"info",	S_IRUGO,		&fops_info},
1220*c33407a8SVladimir Kondratiev 	{"recovery",	S_IRUGO | S_IWUSR,	&fops_recovery},
1221b7cde470SVladimir Kondratiev };
1222b7cde470SVladimir Kondratiev 
1223b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
1224b7cde470SVladimir Kondratiev 				       struct dentry *dbg)
1225b7cde470SVladimir Kondratiev {
1226b7cde470SVladimir Kondratiev 	int i;
1227b7cde470SVladimir Kondratiev 
1228b7cde470SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
1229b7cde470SVladimir Kondratiev 		debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
1230b7cde470SVladimir Kondratiev 				    wil, dbg_files[i].fops);
1231b7cde470SVladimir Kondratiev }
1232b7cde470SVladimir Kondratiev 
1233b7cde470SVladimir Kondratiev /* interrupt control blocks */
1234b7cde470SVladimir Kondratiev static const struct {
1235b7cde470SVladimir Kondratiev 	const char *name;
1236b7cde470SVladimir Kondratiev 	u32 icr_off;
1237b7cde470SVladimir Kondratiev } dbg_icr[] = {
1238b7cde470SVladimir Kondratiev 	{"USER_ICR",		HOSTADDR(RGF_USER_USER_ICR)},
1239b7cde470SVladimir Kondratiev 	{"DMA_EP_TX_ICR",	HOSTADDR(RGF_DMA_EP_TX_ICR)},
1240b7cde470SVladimir Kondratiev 	{"DMA_EP_RX_ICR",	HOSTADDR(RGF_DMA_EP_RX_ICR)},
1241b7cde470SVladimir Kondratiev 	{"DMA_EP_MISC_ICR",	HOSTADDR(RGF_DMA_EP_MISC_ICR)},
1242b7cde470SVladimir Kondratiev };
1243b7cde470SVladimir Kondratiev 
1244b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
1245b7cde470SVladimir Kondratiev 				     struct dentry *dbg)
1246b7cde470SVladimir Kondratiev {
1247b7cde470SVladimir Kondratiev 	int i;
1248b7cde470SVladimir Kondratiev 
1249b7cde470SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
1250b7cde470SVladimir Kondratiev 		wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
1251b7cde470SVladimir Kondratiev 					   dbg_icr[i].icr_off);
1252b7cde470SVladimir Kondratiev }
1253b7cde470SVladimir Kondratiev 
1254b7cde470SVladimir Kondratiev #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
1255b7cde470SVladimir Kondratiev 	offsetof(struct wil6210_priv, name), type}
1256b7cde470SVladimir Kondratiev 
1257b7cde470SVladimir Kondratiev /* fields in struct wil6210_priv */
1258b7cde470SVladimir Kondratiev static const struct dbg_off dbg_wil_off[] = {
1259b7cde470SVladimir Kondratiev 	WIL_FIELD(secure_pcp,	S_IRUGO | S_IWUSR,	doff_u32),
1260b7cde470SVladimir Kondratiev 	WIL_FIELD(status,	S_IRUGO | S_IWUSR,	doff_ulong),
1261b7cde470SVladimir Kondratiev 	WIL_FIELD(fw_version,	S_IRUGO,		doff_u32),
1262b7cde470SVladimir Kondratiev 	WIL_FIELD(hw_version,	S_IRUGO,		doff_x32),
1263*c33407a8SVladimir Kondratiev 	WIL_FIELD(recovery_count, S_IRUGO,		doff_u32),
1264b7cde470SVladimir Kondratiev 	{},
1265b7cde470SVladimir Kondratiev };
1266b7cde470SVladimir Kondratiev 
1267b7cde470SVladimir Kondratiev static const struct dbg_off dbg_wil_regs[] = {
1268b7cde470SVladimir Kondratiev 	{"RGF_MAC_MTRL_COUNTER_0", S_IRUGO, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
1269b7cde470SVladimir Kondratiev 		doff_io32},
1270b7cde470SVladimir Kondratiev 	{"RGF_USER_USAGE_1", S_IRUGO, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
1271b7cde470SVladimir Kondratiev 	{},
1272b7cde470SVladimir Kondratiev };
1273b7cde470SVladimir Kondratiev 
1274b7cde470SVladimir Kondratiev /* static parameters */
1275b7cde470SVladimir Kondratiev static const struct dbg_off dbg_statics[] = {
1276b7cde470SVladimir Kondratiev 	{"desc_index",	S_IRUGO | S_IWUSR, (ulong)&dbg_txdesc_index, doff_u32},
1277b7cde470SVladimir Kondratiev 	{"vring_index",	S_IRUGO | S_IWUSR, (ulong)&dbg_vring_index, doff_u32},
1278b7cde470SVladimir Kondratiev 	{"mem_addr",	S_IRUGO | S_IWUSR, (ulong)&mem_addr, doff_u32},
1279b7cde470SVladimir Kondratiev 	{},
1280b7cde470SVladimir Kondratiev };
1281b7cde470SVladimir Kondratiev 
12822be7d22fSVladimir Kondratiev int wil6210_debugfs_init(struct wil6210_priv *wil)
12832be7d22fSVladimir Kondratiev {
12842be7d22fSVladimir Kondratiev 	struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
12852be7d22fSVladimir Kondratiev 			wil_to_wiphy(wil)->debugfsdir);
12862be7d22fSVladimir Kondratiev 
12872be7d22fSVladimir Kondratiev 	if (IS_ERR_OR_NULL(dbg))
12882be7d22fSVladimir Kondratiev 		return -ENODEV;
12892be7d22fSVladimir Kondratiev 
1290b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_files(wil, dbg);
1291b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_isr(wil, dbg);
1292b541d0a0SVladimir Kondratiev 	wil6210_debugfs_init_blobs(wil, dbg);
1293b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
1294b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
1295b7cde470SVladimir Kondratiev 				    dbg_wil_regs);
1296b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
1297b7cde470SVladimir Kondratiev 
1298b7cde470SVladimir Kondratiev 	wil6210_debugfs_create_pseudo_ISR(wil, dbg);
1299b7cde470SVladimir Kondratiev 
1300b7cde470SVladimir Kondratiev 	wil6210_debugfs_create_ITR_CNT(wil, dbg);
13012be7d22fSVladimir Kondratiev 
13022be7d22fSVladimir Kondratiev 	return 0;
13032be7d22fSVladimir Kondratiev }
13042be7d22fSVladimir Kondratiev 
13052be7d22fSVladimir Kondratiev void wil6210_debugfs_remove(struct wil6210_priv *wil)
13062be7d22fSVladimir Kondratiev {
13072be7d22fSVladimir Kondratiev 	debugfs_remove_recursive(wil->debug);
13082be7d22fSVladimir Kondratiev 	wil->debug = NULL;
13092be7d22fSVladimir Kondratiev }
1310