xref: /linux/drivers/net/wireless/ath/wil6210/debugfs.c (revision b7cde47009640b88cb3629ee7078a43bc2642459)
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"
252be7d22fSVladimir Kondratiev #include "txrx.h"
262be7d22fSVladimir Kondratiev 
272be7d22fSVladimir Kondratiev /* Nasty hack. Better have per device instances */
282be7d22fSVladimir Kondratiev static u32 mem_addr;
292be7d22fSVladimir Kondratiev static u32 dbg_txdesc_index;
30af31cb5aSVladimir Kondratiev static u32 dbg_vring_index; /* 24+ for Rx, 0..23 for Tx */
312be7d22fSVladimir Kondratiev 
32*b7cde470SVladimir Kondratiev enum dbg_off_type {
33*b7cde470SVladimir Kondratiev 	doff_u32 = 0,
34*b7cde470SVladimir Kondratiev 	doff_x32 = 1,
35*b7cde470SVladimir Kondratiev 	doff_ulong = 2,
36*b7cde470SVladimir Kondratiev 	doff_io32 = 3,
37*b7cde470SVladimir Kondratiev };
38*b7cde470SVladimir Kondratiev 
39*b7cde470SVladimir Kondratiev /* offset to "wil" */
40*b7cde470SVladimir Kondratiev struct dbg_off {
41*b7cde470SVladimir Kondratiev 	const char *name;
42*b7cde470SVladimir Kondratiev 	umode_t mode;
43*b7cde470SVladimir Kondratiev 	ulong off;
44*b7cde470SVladimir Kondratiev 	enum dbg_off_type type;
45*b7cde470SVladimir Kondratiev };
46*b7cde470SVladimir Kondratiev 
472be7d22fSVladimir Kondratiev static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil,
4859f7c0a9SVladimir Kondratiev 			    const char *name, struct vring *vring,
4959f7c0a9SVladimir Kondratiev 			    char _s, char _h)
502be7d22fSVladimir Kondratiev {
512be7d22fSVladimir Kondratiev 	void __iomem *x = wmi_addr(wil, vring->hwtail);
522be7d22fSVladimir Kondratiev 
532be7d22fSVladimir Kondratiev 	seq_printf(s, "VRING %s = {\n", name);
5439c52ee8SVladimir Kondratiev 	seq_printf(s, "  pa     = %pad\n", &vring->pa);
552be7d22fSVladimir Kondratiev 	seq_printf(s, "  va     = 0x%p\n", vring->va);
562be7d22fSVladimir Kondratiev 	seq_printf(s, "  size   = %d\n", vring->size);
572be7d22fSVladimir Kondratiev 	seq_printf(s, "  swtail = %d\n", vring->swtail);
582be7d22fSVladimir Kondratiev 	seq_printf(s, "  swhead = %d\n", vring->swhead);
592be7d22fSVladimir Kondratiev 	seq_printf(s, "  hwtail = [0x%08x] -> ", vring->hwtail);
602be7d22fSVladimir Kondratiev 	if (x)
612be7d22fSVladimir Kondratiev 		seq_printf(s, "0x%08x\n", ioread32(x));
622be7d22fSVladimir Kondratiev 	else
632be7d22fSVladimir Kondratiev 		seq_printf(s, "???\n");
642be7d22fSVladimir Kondratiev 
652be7d22fSVladimir Kondratiev 	if (vring->va && (vring->size < 1025)) {
662be7d22fSVladimir Kondratiev 		uint i;
672be7d22fSVladimir Kondratiev 		for (i = 0; i < vring->size; i++) {
682be7d22fSVladimir Kondratiev 			volatile struct vring_tx_desc *d = &vring->va[i].tx;
692be7d22fSVladimir Kondratiev 			if ((i % 64) == 0 && (i != 0))
702be7d22fSVladimir Kondratiev 				seq_printf(s, "\n");
7159f7c0a9SVladimir Kondratiev 			seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
7259f7c0a9SVladimir Kondratiev 					_s : (vring->ctx[i].skb ? _h : 'h'));
732be7d22fSVladimir Kondratiev 		}
742be7d22fSVladimir Kondratiev 		seq_printf(s, "\n");
752be7d22fSVladimir Kondratiev 	}
762be7d22fSVladimir Kondratiev 	seq_printf(s, "}\n");
772be7d22fSVladimir Kondratiev }
782be7d22fSVladimir Kondratiev 
792be7d22fSVladimir Kondratiev static int wil_vring_debugfs_show(struct seq_file *s, void *data)
802be7d22fSVladimir Kondratiev {
812be7d22fSVladimir Kondratiev 	uint i;
822be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
832be7d22fSVladimir Kondratiev 
8459f7c0a9SVladimir Kondratiev 	wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_');
852be7d22fSVladimir Kondratiev 
862be7d22fSVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
872be7d22fSVladimir Kondratiev 		struct vring *vring = &(wil->vring_tx[i]);
887c0acf86SVladimir Kondratiev 		struct vring_tx_data *txdata = &wil->vring_tx_data[i];
897c0acf86SVladimir Kondratiev 
902be7d22fSVladimir Kondratiev 		if (vring->va) {
913df2cd36SVladimir Kondratiev 			int cid = wil->vring2cid_tid[i][0];
923df2cd36SVladimir Kondratiev 			int tid = wil->vring2cid_tid[i][1];
9367c3e1b4SVladimir Kondratiev 			u32 swhead = vring->swhead;
9467c3e1b4SVladimir Kondratiev 			u32 swtail = vring->swtail;
9567c3e1b4SVladimir Kondratiev 			int used = (vring->size + swhead - swtail)
9667c3e1b4SVladimir Kondratiev 				   % vring->size;
9767c3e1b4SVladimir Kondratiev 			int avail = vring->size - used - 1;
982be7d22fSVladimir Kondratiev 			char name[10];
997c0acf86SVladimir Kondratiev 			/* performance monitoring */
1007c0acf86SVladimir Kondratiev 			cycles_t now = get_cycles();
101e48b1790SVladimir Kondratiev 			cycles_t idle = txdata->idle * 100;
1027c0acf86SVladimir Kondratiev 			cycles_t total = now - txdata->begin;
1037c0acf86SVladimir Kondratiev 
104e48b1790SVladimir Kondratiev 			do_div(idle, total);
1057c0acf86SVladimir Kondratiev 			txdata->begin = now;
1067c0acf86SVladimir Kondratiev 			txdata->idle = 0ULL;
1077c0acf86SVladimir Kondratiev 
1082be7d22fSVladimir Kondratiev 			snprintf(name, sizeof(name), "tx_%2d", i);
1093df2cd36SVladimir Kondratiev 
1107c0acf86SVladimir Kondratiev 			seq_printf(s, "\n%pM CID %d TID %d [%3d|%3d] idle %3d%%\n",
1117c0acf86SVladimir Kondratiev 				   wil->sta[cid].addr, cid, tid, used, avail,
112e48b1790SVladimir Kondratiev 				   (int)idle);
1137c0acf86SVladimir Kondratiev 
11459f7c0a9SVladimir Kondratiev 			wil_print_vring(s, wil, name, vring, '_', 'H');
1152be7d22fSVladimir Kondratiev 		}
1162be7d22fSVladimir Kondratiev 	}
1172be7d22fSVladimir Kondratiev 
1182be7d22fSVladimir Kondratiev 	return 0;
1192be7d22fSVladimir Kondratiev }
1202be7d22fSVladimir Kondratiev 
1212be7d22fSVladimir Kondratiev static int wil_vring_seq_open(struct inode *inode, struct file *file)
1222be7d22fSVladimir Kondratiev {
1232be7d22fSVladimir Kondratiev 	return single_open(file, wil_vring_debugfs_show, inode->i_private);
1242be7d22fSVladimir Kondratiev }
1252be7d22fSVladimir Kondratiev 
1262be7d22fSVladimir Kondratiev static const struct file_operations fops_vring = {
1272be7d22fSVladimir Kondratiev 	.open		= wil_vring_seq_open,
1282be7d22fSVladimir Kondratiev 	.release	= single_release,
1292be7d22fSVladimir Kondratiev 	.read		= seq_read,
1302be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
1312be7d22fSVladimir Kondratiev };
1322be7d22fSVladimir Kondratiev 
1332be7d22fSVladimir Kondratiev static void wil_print_ring(struct seq_file *s, const char *prefix,
1342be7d22fSVladimir Kondratiev 			   void __iomem *off)
1352be7d22fSVladimir Kondratiev {
1362be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
1372be7d22fSVladimir Kondratiev 	struct wil6210_mbox_ring r;
1382be7d22fSVladimir Kondratiev 	int rsize;
1392be7d22fSVladimir Kondratiev 	uint i;
1402be7d22fSVladimir Kondratiev 
1412be7d22fSVladimir Kondratiev 	wil_memcpy_fromio_32(&r, off, sizeof(r));
1422be7d22fSVladimir Kondratiev 	wil_mbox_ring_le2cpus(&r);
1432be7d22fSVladimir Kondratiev 	/*
1442be7d22fSVladimir Kondratiev 	 * we just read memory block from NIC. This memory may be
1452be7d22fSVladimir Kondratiev 	 * garbage. Check validity before using it.
1462be7d22fSVladimir Kondratiev 	 */
1472be7d22fSVladimir Kondratiev 	rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
1482be7d22fSVladimir Kondratiev 
1492be7d22fSVladimir Kondratiev 	seq_printf(s, "ring %s = {\n", prefix);
1502be7d22fSVladimir Kondratiev 	seq_printf(s, "  base = 0x%08x\n", r.base);
1512be7d22fSVladimir Kondratiev 	seq_printf(s, "  size = 0x%04x bytes -> %d entries\n", r.size, rsize);
1522be7d22fSVladimir Kondratiev 	seq_printf(s, "  tail = 0x%08x\n", r.tail);
1532be7d22fSVladimir Kondratiev 	seq_printf(s, "  head = 0x%08x\n", r.head);
1542be7d22fSVladimir Kondratiev 	seq_printf(s, "  entry size = %d\n", r.entry_size);
1552be7d22fSVladimir Kondratiev 
1562be7d22fSVladimir Kondratiev 	if (r.size % sizeof(struct wil6210_mbox_ring_desc)) {
1572be7d22fSVladimir Kondratiev 		seq_printf(s, "  ??? size is not multiple of %zd, garbage?\n",
1582be7d22fSVladimir Kondratiev 			   sizeof(struct wil6210_mbox_ring_desc));
1592be7d22fSVladimir Kondratiev 		goto out;
1602be7d22fSVladimir Kondratiev 	}
1612be7d22fSVladimir Kondratiev 
1622be7d22fSVladimir Kondratiev 	if (!wmi_addr(wil, r.base) ||
1632be7d22fSVladimir Kondratiev 	    !wmi_addr(wil, r.tail) ||
1642be7d22fSVladimir Kondratiev 	    !wmi_addr(wil, r.head)) {
1652be7d22fSVladimir Kondratiev 		seq_printf(s, "  ??? pointers are garbage?\n");
1662be7d22fSVladimir Kondratiev 		goto out;
1672be7d22fSVladimir Kondratiev 	}
1682be7d22fSVladimir Kondratiev 
1692be7d22fSVladimir Kondratiev 	for (i = 0; i < rsize; i++) {
1702be7d22fSVladimir Kondratiev 		struct wil6210_mbox_ring_desc d;
1712be7d22fSVladimir Kondratiev 		struct wil6210_mbox_hdr hdr;
1722be7d22fSVladimir Kondratiev 		size_t delta = i * sizeof(d);
1732be7d22fSVladimir Kondratiev 		void __iomem *x = wil->csr + HOSTADDR(r.base) + delta;
1742be7d22fSVladimir Kondratiev 
1752be7d22fSVladimir Kondratiev 		wil_memcpy_fromio_32(&d, x, sizeof(d));
1762be7d22fSVladimir Kondratiev 
1772be7d22fSVladimir Kondratiev 		seq_printf(s, "  [%2x] %s %s%s 0x%08x", i,
1782be7d22fSVladimir Kondratiev 			   d.sync ? "F" : "E",
1792be7d22fSVladimir Kondratiev 			   (r.tail - r.base == delta) ? "t" : " ",
1802be7d22fSVladimir Kondratiev 			   (r.head - r.base == delta) ? "h" : " ",
1812be7d22fSVladimir Kondratiev 			   le32_to_cpu(d.addr));
1822be7d22fSVladimir Kondratiev 		if (0 == wmi_read_hdr(wil, d.addr, &hdr)) {
1832be7d22fSVladimir Kondratiev 			u16 len = le16_to_cpu(hdr.len);
1842be7d22fSVladimir Kondratiev 			seq_printf(s, " -> %04x %04x %04x %02x\n",
1852be7d22fSVladimir Kondratiev 				   le16_to_cpu(hdr.seq), len,
1862be7d22fSVladimir Kondratiev 				   le16_to_cpu(hdr.type), hdr.flags);
1872be7d22fSVladimir Kondratiev 			if (len <= MAX_MBOXITEM_SIZE) {
1882be7d22fSVladimir Kondratiev 				int n = 0;
1895d21608aSLarry Finger 				char printbuf[16 * 3 + 2];
1902be7d22fSVladimir Kondratiev 				unsigned char databuf[MAX_MBOXITEM_SIZE];
1912be7d22fSVladimir Kondratiev 				void __iomem *src = wmi_buffer(wil, d.addr) +
1922be7d22fSVladimir Kondratiev 					sizeof(struct wil6210_mbox_hdr);
1932be7d22fSVladimir Kondratiev 				/*
1942be7d22fSVladimir Kondratiev 				 * No need to check @src for validity -
1952be7d22fSVladimir Kondratiev 				 * we already validated @d.addr while
1962be7d22fSVladimir Kondratiev 				 * reading header
1972be7d22fSVladimir Kondratiev 				 */
1982be7d22fSVladimir Kondratiev 				wil_memcpy_fromio_32(databuf, src, len);
1992be7d22fSVladimir Kondratiev 				while (n < len) {
2002be7d22fSVladimir Kondratiev 					int l = min(len - n, 16);
2012be7d22fSVladimir Kondratiev 					hex_dump_to_buffer(databuf + n, l,
2022be7d22fSVladimir Kondratiev 							   16, 1, printbuf,
2032be7d22fSVladimir Kondratiev 							   sizeof(printbuf),
2042be7d22fSVladimir Kondratiev 							   false);
2052be7d22fSVladimir Kondratiev 					seq_printf(s, "      : %s\n", printbuf);
2062be7d22fSVladimir Kondratiev 					n += l;
2072be7d22fSVladimir Kondratiev 				}
2082be7d22fSVladimir Kondratiev 			}
2092be7d22fSVladimir Kondratiev 		} else {
2102be7d22fSVladimir Kondratiev 			seq_printf(s, "\n");
2112be7d22fSVladimir Kondratiev 		}
2122be7d22fSVladimir Kondratiev 	}
2132be7d22fSVladimir Kondratiev  out:
2142be7d22fSVladimir Kondratiev 	seq_printf(s, "}\n");
2152be7d22fSVladimir Kondratiev }
2162be7d22fSVladimir Kondratiev 
2172be7d22fSVladimir Kondratiev static int wil_mbox_debugfs_show(struct seq_file *s, void *data)
2182be7d22fSVladimir Kondratiev {
2192be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
2202be7d22fSVladimir Kondratiev 
2212be7d22fSVladimir Kondratiev 	wil_print_ring(s, "tx", wil->csr + HOST_MBOX +
2222be7d22fSVladimir Kondratiev 		       offsetof(struct wil6210_mbox_ctl, tx));
2232be7d22fSVladimir Kondratiev 	wil_print_ring(s, "rx", wil->csr + HOST_MBOX +
2242be7d22fSVladimir Kondratiev 		       offsetof(struct wil6210_mbox_ctl, rx));
2252be7d22fSVladimir Kondratiev 
2262be7d22fSVladimir Kondratiev 	return 0;
2272be7d22fSVladimir Kondratiev }
2282be7d22fSVladimir Kondratiev 
2292be7d22fSVladimir Kondratiev static int wil_mbox_seq_open(struct inode *inode, struct file *file)
2302be7d22fSVladimir Kondratiev {
2312be7d22fSVladimir Kondratiev 	return single_open(file, wil_mbox_debugfs_show, inode->i_private);
2322be7d22fSVladimir Kondratiev }
2332be7d22fSVladimir Kondratiev 
2342be7d22fSVladimir Kondratiev static const struct file_operations fops_mbox = {
2352be7d22fSVladimir Kondratiev 	.open		= wil_mbox_seq_open,
2362be7d22fSVladimir Kondratiev 	.release	= single_release,
2372be7d22fSVladimir Kondratiev 	.read		= seq_read,
2382be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
2392be7d22fSVladimir Kondratiev };
2402be7d22fSVladimir Kondratiev 
2412be7d22fSVladimir Kondratiev static int wil_debugfs_iomem_x32_set(void *data, u64 val)
2422be7d22fSVladimir Kondratiev {
2432be7d22fSVladimir Kondratiev 	iowrite32(val, (void __iomem *)data);
2442be7d22fSVladimir Kondratiev 	wmb(); /* make sure write propagated to HW */
2452be7d22fSVladimir Kondratiev 
2462be7d22fSVladimir Kondratiev 	return 0;
2472be7d22fSVladimir Kondratiev }
2482be7d22fSVladimir Kondratiev 
2492be7d22fSVladimir Kondratiev static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
2502be7d22fSVladimir Kondratiev {
2512be7d22fSVladimir Kondratiev 	*val = ioread32((void __iomem *)data);
2522be7d22fSVladimir Kondratiev 
2532be7d22fSVladimir Kondratiev 	return 0;
2542be7d22fSVladimir Kondratiev }
2552be7d22fSVladimir Kondratiev 
2562be7d22fSVladimir Kondratiev DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
2572be7d22fSVladimir Kondratiev 			wil_debugfs_iomem_x32_set, "0x%08llx\n");
2582be7d22fSVladimir Kondratiev 
2592be7d22fSVladimir Kondratiev static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
2600ecc833bSAl Viro 						   umode_t mode,
2612be7d22fSVladimir Kondratiev 						   struct dentry *parent,
262*b7cde470SVladimir Kondratiev 						   void *value)
2632be7d22fSVladimir Kondratiev {
264*b7cde470SVladimir Kondratiev 	return debugfs_create_file(name, mode, parent, value,
2652be7d22fSVladimir Kondratiev 				   &fops_iomem_x32);
2662be7d22fSVladimir Kondratiev }
2672be7d22fSVladimir Kondratiev 
2683de6cf20SVladimir Kondratiev static int wil_debugfs_ulong_set(void *data, u64 val)
2693de6cf20SVladimir Kondratiev {
2703de6cf20SVladimir Kondratiev 	*(ulong *)data = val;
2713de6cf20SVladimir Kondratiev 	return 0;
2723de6cf20SVladimir Kondratiev }
2733de6cf20SVladimir Kondratiev static int wil_debugfs_ulong_get(void *data, u64 *val)
2743de6cf20SVladimir Kondratiev {
2753de6cf20SVladimir Kondratiev 	*val = *(ulong *)data;
2763de6cf20SVladimir Kondratiev 	return 0;
2773de6cf20SVladimir Kondratiev }
2783de6cf20SVladimir Kondratiev DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
2793de6cf20SVladimir Kondratiev 			wil_debugfs_ulong_set, "%llu\n");
2803de6cf20SVladimir Kondratiev 
2813de6cf20SVladimir Kondratiev static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode,
2823de6cf20SVladimir Kondratiev 					       struct dentry *parent,
2833de6cf20SVladimir Kondratiev 					       ulong *value)
2843de6cf20SVladimir Kondratiev {
2853de6cf20SVladimir Kondratiev 	return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong);
2863de6cf20SVladimir Kondratiev }
2873de6cf20SVladimir Kondratiev 
288*b7cde470SVladimir Kondratiev /**
289*b7cde470SVladimir Kondratiev  * wil6210_debugfs_init_offset - create set of debugfs files
290*b7cde470SVladimir Kondratiev  * @wil - driver's context, used for printing
291*b7cde470SVladimir Kondratiev  * @dbg - directory on the debugfs, where files will be created
292*b7cde470SVladimir Kondratiev  * @base - base address used in address calculation
293*b7cde470SVladimir Kondratiev  * @tbl - table with file descriptions. Should be terminated with empty element.
294*b7cde470SVladimir Kondratiev  *
295*b7cde470SVladimir Kondratiev  * Creates files accordingly to the @tbl.
296*b7cde470SVladimir Kondratiev  */
297*b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_offset(struct wil6210_priv *wil,
298*b7cde470SVladimir Kondratiev 					struct dentry *dbg, void *base,
299*b7cde470SVladimir Kondratiev 					const struct dbg_off * const tbl)
300*b7cde470SVladimir Kondratiev {
301*b7cde470SVladimir Kondratiev 	int i;
302*b7cde470SVladimir Kondratiev 
303*b7cde470SVladimir Kondratiev 	for (i = 0; tbl[i].name; i++) {
304*b7cde470SVladimir Kondratiev 		struct dentry *f = NULL;
305*b7cde470SVladimir Kondratiev 
306*b7cde470SVladimir Kondratiev 		switch (tbl[i].type) {
307*b7cde470SVladimir Kondratiev 		case doff_u32:
308*b7cde470SVladimir Kondratiev 			f = debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg,
309*b7cde470SVladimir Kondratiev 					       base + tbl[i].off);
310*b7cde470SVladimir Kondratiev 			break;
311*b7cde470SVladimir Kondratiev 		case doff_x32:
312*b7cde470SVladimir Kondratiev 			f = debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg,
313*b7cde470SVladimir Kondratiev 					       base + tbl[i].off);
314*b7cde470SVladimir Kondratiev 			break;
315*b7cde470SVladimir Kondratiev 		case doff_ulong:
316*b7cde470SVladimir Kondratiev 			f = wil_debugfs_create_ulong(tbl[i].name, tbl[i].mode,
317*b7cde470SVladimir Kondratiev 						     dbg, base + tbl[i].off);
318*b7cde470SVladimir Kondratiev 			break;
319*b7cde470SVladimir Kondratiev 		case doff_io32:
320*b7cde470SVladimir Kondratiev 			f = wil_debugfs_create_iomem_x32(tbl[i].name,
321*b7cde470SVladimir Kondratiev 							 tbl[i].mode, dbg,
322*b7cde470SVladimir Kondratiev 							 base + tbl[i].off);
323*b7cde470SVladimir Kondratiev 			break;
324*b7cde470SVladimir Kondratiev 		}
325*b7cde470SVladimir Kondratiev 		if (IS_ERR_OR_NULL(f))
326*b7cde470SVladimir Kondratiev 			wil_err(wil, "Create file \"%s\": err %ld\n",
327*b7cde470SVladimir Kondratiev 				tbl[i].name, PTR_ERR(f));
328*b7cde470SVladimir Kondratiev 	}
329*b7cde470SVladimir Kondratiev }
330*b7cde470SVladimir Kondratiev 
331*b7cde470SVladimir Kondratiev static const struct dbg_off isr_off[] = {
332*b7cde470SVladimir Kondratiev 	{"ICC", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICC), doff_io32},
333*b7cde470SVladimir Kondratiev 	{"ICR", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICR), doff_io32},
334*b7cde470SVladimir Kondratiev 	{"ICM", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICM), doff_io32},
335*b7cde470SVladimir Kondratiev 	{"ICS",		  S_IWUSR, offsetof(struct RGF_ICR, ICS), doff_io32},
336*b7cde470SVladimir Kondratiev 	{"IMV", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, IMV), doff_io32},
337*b7cde470SVladimir Kondratiev 	{"IMS",		  S_IWUSR, offsetof(struct RGF_ICR, IMS), doff_io32},
338*b7cde470SVladimir Kondratiev 	{"IMC",		  S_IWUSR, offsetof(struct RGF_ICR, IMC), doff_io32},
339*b7cde470SVladimir Kondratiev 	{},
340*b7cde470SVladimir Kondratiev };
3412be7d22fSVladimir Kondratiev static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
3422be7d22fSVladimir Kondratiev 				      const char *name,
3432be7d22fSVladimir Kondratiev 				      struct dentry *parent, u32 off)
3442be7d22fSVladimir Kondratiev {
3452be7d22fSVladimir Kondratiev 	struct dentry *d = debugfs_create_dir(name, parent);
3462be7d22fSVladimir Kondratiev 
3472be7d22fSVladimir Kondratiev 	if (IS_ERR_OR_NULL(d))
3482be7d22fSVladimir Kondratiev 		return -ENODEV;
3492be7d22fSVladimir Kondratiev 
350*b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off,
351*b7cde470SVladimir Kondratiev 				    isr_off);
3522be7d22fSVladimir Kondratiev 
3532be7d22fSVladimir Kondratiev 	return 0;
3542be7d22fSVladimir Kondratiev }
3552be7d22fSVladimir Kondratiev 
356*b7cde470SVladimir Kondratiev static const struct dbg_off pseudo_isr_off[] = {
357*b7cde470SVladimir Kondratiev 	{"CAUSE",   S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32},
358*b7cde470SVladimir Kondratiev 	{"MASK_SW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32},
359*b7cde470SVladimir Kondratiev 	{"MASK_FW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32},
360*b7cde470SVladimir Kondratiev 	{},
361*b7cde470SVladimir Kondratiev };
362*b7cde470SVladimir Kondratiev 
3632be7d22fSVladimir Kondratiev static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
3642be7d22fSVladimir Kondratiev 					     struct dentry *parent)
3652be7d22fSVladimir Kondratiev {
3662be7d22fSVladimir Kondratiev 	struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
3672be7d22fSVladimir Kondratiev 
3682be7d22fSVladimir Kondratiev 	if (IS_ERR_OR_NULL(d))
3692be7d22fSVladimir Kondratiev 		return -ENODEV;
3702be7d22fSVladimir Kondratiev 
371*b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
372*b7cde470SVladimir Kondratiev 				    pseudo_isr_off);
3732be7d22fSVladimir Kondratiev 
3742be7d22fSVladimir Kondratiev 	return 0;
3752be7d22fSVladimir Kondratiev }
3762be7d22fSVladimir Kondratiev 
377*b7cde470SVladimir Kondratiev static const struct dbg_off itr_cnt_off[] = {
378*b7cde470SVladimir Kondratiev 	{"TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32},
379*b7cde470SVladimir Kondratiev 	{"DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32},
380*b7cde470SVladimir Kondratiev 	{"CTL",  S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32},
381*b7cde470SVladimir Kondratiev 	{},
382*b7cde470SVladimir Kondratiev };
383*b7cde470SVladimir Kondratiev 
3842be7d22fSVladimir Kondratiev static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
3852be7d22fSVladimir Kondratiev 					  struct dentry *parent)
3862be7d22fSVladimir Kondratiev {
3872be7d22fSVladimir Kondratiev 	struct dentry *d = debugfs_create_dir("ITR_CNT", parent);
3882be7d22fSVladimir Kondratiev 
3892be7d22fSVladimir Kondratiev 	if (IS_ERR_OR_NULL(d))
3902be7d22fSVladimir Kondratiev 		return -ENODEV;
3912be7d22fSVladimir Kondratiev 
392*b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
393*b7cde470SVladimir Kondratiev 				    itr_cnt_off);
3942be7d22fSVladimir Kondratiev 
3952be7d22fSVladimir Kondratiev 	return 0;
3962be7d22fSVladimir Kondratiev }
3972be7d22fSVladimir Kondratiev 
3982be7d22fSVladimir Kondratiev static int wil_memread_debugfs_show(struct seq_file *s, void *data)
3992be7d22fSVladimir Kondratiev {
4002be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
4012be7d22fSVladimir Kondratiev 	void __iomem *a = wmi_buffer(wil, cpu_to_le32(mem_addr));
4022be7d22fSVladimir Kondratiev 
4032be7d22fSVladimir Kondratiev 	if (a)
4042be7d22fSVladimir Kondratiev 		seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, ioread32(a));
4052be7d22fSVladimir Kondratiev 	else
4062be7d22fSVladimir Kondratiev 		seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
4072be7d22fSVladimir Kondratiev 
4082be7d22fSVladimir Kondratiev 	return 0;
4092be7d22fSVladimir Kondratiev }
4102be7d22fSVladimir Kondratiev 
4112be7d22fSVladimir Kondratiev static int wil_memread_seq_open(struct inode *inode, struct file *file)
4122be7d22fSVladimir Kondratiev {
4132be7d22fSVladimir Kondratiev 	return single_open(file, wil_memread_debugfs_show, inode->i_private);
4142be7d22fSVladimir Kondratiev }
4152be7d22fSVladimir Kondratiev 
4162be7d22fSVladimir Kondratiev static const struct file_operations fops_memread = {
4172be7d22fSVladimir Kondratiev 	.open		= wil_memread_seq_open,
4182be7d22fSVladimir Kondratiev 	.release	= single_release,
4192be7d22fSVladimir Kondratiev 	.read		= seq_read,
4202be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
4212be7d22fSVladimir Kondratiev };
4222be7d22fSVladimir Kondratiev 
4232be7d22fSVladimir Kondratiev static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
4242be7d22fSVladimir Kondratiev 				size_t count, loff_t *ppos)
4252be7d22fSVladimir Kondratiev {
4262be7d22fSVladimir Kondratiev 	enum { max_count = 4096 };
4272be7d22fSVladimir Kondratiev 	struct debugfs_blob_wrapper *blob = file->private_data;
4282be7d22fSVladimir Kondratiev 	loff_t pos = *ppos;
4292be7d22fSVladimir Kondratiev 	size_t available = blob->size;
4302be7d22fSVladimir Kondratiev 	void *buf;
4312be7d22fSVladimir Kondratiev 	size_t ret;
4322be7d22fSVladimir Kondratiev 
4332be7d22fSVladimir Kondratiev 	if (pos < 0)
4342be7d22fSVladimir Kondratiev 		return -EINVAL;
4352be7d22fSVladimir Kondratiev 
4362be7d22fSVladimir Kondratiev 	if (pos >= available || !count)
4372be7d22fSVladimir Kondratiev 		return 0;
4382be7d22fSVladimir Kondratiev 
4392be7d22fSVladimir Kondratiev 	if (count > available - pos)
4402be7d22fSVladimir Kondratiev 		count = available - pos;
4412be7d22fSVladimir Kondratiev 	if (count > max_count)
4422be7d22fSVladimir Kondratiev 		count = max_count;
4432be7d22fSVladimir Kondratiev 
4442be7d22fSVladimir Kondratiev 	buf = kmalloc(count, GFP_KERNEL);
4452be7d22fSVladimir Kondratiev 	if (!buf)
4462be7d22fSVladimir Kondratiev 		return -ENOMEM;
4472be7d22fSVladimir Kondratiev 
4482be7d22fSVladimir Kondratiev 	wil_memcpy_fromio_32(buf, (const volatile void __iomem *)blob->data +
4492be7d22fSVladimir Kondratiev 			     pos, count);
4502be7d22fSVladimir Kondratiev 
4512be7d22fSVladimir Kondratiev 	ret = copy_to_user(user_buf, buf, count);
4522be7d22fSVladimir Kondratiev 	kfree(buf);
4532be7d22fSVladimir Kondratiev 	if (ret == count)
4542be7d22fSVladimir Kondratiev 		return -EFAULT;
4552be7d22fSVladimir Kondratiev 
4562be7d22fSVladimir Kondratiev 	count -= ret;
4572be7d22fSVladimir Kondratiev 	*ppos = pos + count;
4582be7d22fSVladimir Kondratiev 
4592be7d22fSVladimir Kondratiev 	return count;
4602be7d22fSVladimir Kondratiev }
4612be7d22fSVladimir Kondratiev 
4622be7d22fSVladimir Kondratiev static const struct file_operations fops_ioblob = {
4632be7d22fSVladimir Kondratiev 	.read =		wil_read_file_ioblob,
46493ecbd64SWei Yongjun 	.open =		simple_open,
4652be7d22fSVladimir Kondratiev 	.llseek =	default_llseek,
4662be7d22fSVladimir Kondratiev };
4672be7d22fSVladimir Kondratiev 
4682be7d22fSVladimir Kondratiev static
4692be7d22fSVladimir Kondratiev struct dentry *wil_debugfs_create_ioblob(const char *name,
4700ecc833bSAl Viro 					 umode_t mode,
4712be7d22fSVladimir Kondratiev 					 struct dentry *parent,
4722be7d22fSVladimir Kondratiev 					 struct debugfs_blob_wrapper *blob)
4732be7d22fSVladimir Kondratiev {
4742be7d22fSVladimir Kondratiev 	return debugfs_create_file(name, mode, parent, blob, &fops_ioblob);
4752be7d22fSVladimir Kondratiev }
4762be7d22fSVladimir Kondratiev /*---reset---*/
4772be7d22fSVladimir Kondratiev static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
4782be7d22fSVladimir Kondratiev 				    size_t len, loff_t *ppos)
4792be7d22fSVladimir Kondratiev {
4802be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
4812be7d22fSVladimir Kondratiev 	struct net_device *ndev = wil_to_ndev(wil);
4822be7d22fSVladimir Kondratiev 
4832be7d22fSVladimir Kondratiev 	/**
4842be7d22fSVladimir Kondratiev 	 * BUG:
4852be7d22fSVladimir Kondratiev 	 * this code does NOT sync device state with the rest of system
4862be7d22fSVladimir Kondratiev 	 * use with care, debug only!!!
4872be7d22fSVladimir Kondratiev 	 */
4882be7d22fSVladimir Kondratiev 	rtnl_lock();
4892be7d22fSVladimir Kondratiev 	dev_close(ndev);
4902be7d22fSVladimir Kondratiev 	ndev->flags &= ~IFF_UP;
4912be7d22fSVladimir Kondratiev 	rtnl_unlock();
4922be7d22fSVladimir Kondratiev 	wil_reset(wil);
4932be7d22fSVladimir Kondratiev 
4942be7d22fSVladimir Kondratiev 	return len;
4952be7d22fSVladimir Kondratiev }
4962be7d22fSVladimir Kondratiev 
4972be7d22fSVladimir Kondratiev static const struct file_operations fops_reset = {
4982be7d22fSVladimir Kondratiev 	.write = wil_write_file_reset,
49993ecbd64SWei Yongjun 	.open  = simple_open,
5002be7d22fSVladimir Kondratiev };
5010b39aaf2SVladimir Kondratiev /*---write channel 1..4 to rxon for it, 0 to rxoff---*/
5020b39aaf2SVladimir Kondratiev static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
5030b39aaf2SVladimir Kondratiev 				   size_t len, loff_t *ppos)
5040b39aaf2SVladimir Kondratiev {
5050b39aaf2SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
5060b39aaf2SVladimir Kondratiev 	int rc;
5070b39aaf2SVladimir Kondratiev 	long channel;
5080b39aaf2SVladimir Kondratiev 	bool on;
5090b39aaf2SVladimir Kondratiev 
5100b39aaf2SVladimir Kondratiev 	char *kbuf = kmalloc(len + 1, GFP_KERNEL);
5110b39aaf2SVladimir Kondratiev 	if (!kbuf)
5120b39aaf2SVladimir Kondratiev 		return -ENOMEM;
513359ee627SVladimir Kondratiev 	if (copy_from_user(kbuf, buf, len)) {
514359ee627SVladimir Kondratiev 		kfree(kbuf);
5150b39aaf2SVladimir Kondratiev 		return -EIO;
516359ee627SVladimir Kondratiev 	}
5170b39aaf2SVladimir Kondratiev 
5180b39aaf2SVladimir Kondratiev 	kbuf[len] = '\0';
5190b39aaf2SVladimir Kondratiev 	rc = kstrtol(kbuf, 0, &channel);
5200b39aaf2SVladimir Kondratiev 	kfree(kbuf);
5210b39aaf2SVladimir Kondratiev 	if (rc)
5220b39aaf2SVladimir Kondratiev 		return rc;
5230b39aaf2SVladimir Kondratiev 
5240b39aaf2SVladimir Kondratiev 	if ((channel < 0) || (channel > 4)) {
5250b39aaf2SVladimir Kondratiev 		wil_err(wil, "Invalid channel %ld\n", channel);
5260b39aaf2SVladimir Kondratiev 		return -EINVAL;
5270b39aaf2SVladimir Kondratiev 	}
5280b39aaf2SVladimir Kondratiev 	on = !!channel;
5290b39aaf2SVladimir Kondratiev 
5300b39aaf2SVladimir Kondratiev 	if (on) {
5310b39aaf2SVladimir Kondratiev 		rc = wmi_set_channel(wil, (int)channel);
5320b39aaf2SVladimir Kondratiev 		if (rc)
5330b39aaf2SVladimir Kondratiev 			return rc;
5340b39aaf2SVladimir Kondratiev 	}
5350b39aaf2SVladimir Kondratiev 
5360b39aaf2SVladimir Kondratiev 	rc = wmi_rxon(wil, on);
5370b39aaf2SVladimir Kondratiev 	if (rc)
5380b39aaf2SVladimir Kondratiev 		return rc;
5390b39aaf2SVladimir Kondratiev 
5400b39aaf2SVladimir Kondratiev 	return len;
5410b39aaf2SVladimir Kondratiev }
5420b39aaf2SVladimir Kondratiev 
5430b39aaf2SVladimir Kondratiev static const struct file_operations fops_rxon = {
5440b39aaf2SVladimir Kondratiev 	.write = wil_write_file_rxon,
5450b39aaf2SVladimir Kondratiev 	.open  = simple_open,
5460b39aaf2SVladimir Kondratiev };
5470b39aaf2SVladimir Kondratiev /*---tx_mgmt---*/
5480b39aaf2SVladimir Kondratiev /* Write mgmt frame to this file to send it */
5490b39aaf2SVladimir Kondratiev static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
5500b39aaf2SVladimir Kondratiev 				     size_t len, loff_t *ppos)
5510b39aaf2SVladimir Kondratiev {
5520b39aaf2SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
5530b39aaf2SVladimir Kondratiev 	struct wiphy *wiphy = wil_to_wiphy(wil);
5540b39aaf2SVladimir Kondratiev 	struct wireless_dev *wdev = wil_to_wdev(wil);
5550b39aaf2SVladimir Kondratiev 	struct cfg80211_mgmt_tx_params params;
5560b39aaf2SVladimir Kondratiev 	int rc;
5570b39aaf2SVladimir Kondratiev 
5580b39aaf2SVladimir Kondratiev 	void *frame = kmalloc(len, GFP_KERNEL);
5590b39aaf2SVladimir Kondratiev 	if (!frame)
5600b39aaf2SVladimir Kondratiev 		return -ENOMEM;
5610b39aaf2SVladimir Kondratiev 
5620b39aaf2SVladimir Kondratiev 	if (copy_from_user(frame, buf, len))
5630b39aaf2SVladimir Kondratiev 		return -EIO;
5640b39aaf2SVladimir Kondratiev 
5650b39aaf2SVladimir Kondratiev 	params.buf = frame;
5660b39aaf2SVladimir Kondratiev 	params.len = len;
5670b39aaf2SVladimir Kondratiev 	params.chan = wdev->preset_chandef.chan;
5680b39aaf2SVladimir Kondratiev 
5690b39aaf2SVladimir Kondratiev 	rc = wil_cfg80211_mgmt_tx(wiphy, wdev, &params, NULL);
5700b39aaf2SVladimir Kondratiev 
5710b39aaf2SVladimir Kondratiev 	kfree(frame);
5720b39aaf2SVladimir Kondratiev 	wil_info(wil, "%s() -> %d\n", __func__, rc);
5730b39aaf2SVladimir Kondratiev 
5740b39aaf2SVladimir Kondratiev 	return len;
5750b39aaf2SVladimir Kondratiev }
5760b39aaf2SVladimir Kondratiev 
5770b39aaf2SVladimir Kondratiev static const struct file_operations fops_txmgmt = {
5780b39aaf2SVladimir Kondratiev 	.write = wil_write_file_txmgmt,
5790b39aaf2SVladimir Kondratiev 	.open  = simple_open,
5800b39aaf2SVladimir Kondratiev };
5812be7d22fSVladimir Kondratiev 
582ff974e40SVladimir Kondratiev /* Write WMI command (w/o mbox header) to this file to send it
583ff974e40SVladimir Kondratiev  * WMI starts from wil6210_mbox_hdr_wmi header
584ff974e40SVladimir Kondratiev  */
585ff974e40SVladimir Kondratiev static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
586ff974e40SVladimir Kondratiev 				  size_t len, loff_t *ppos)
587ff974e40SVladimir Kondratiev {
588ff974e40SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
589ff974e40SVladimir Kondratiev 	struct wil6210_mbox_hdr_wmi *wmi;
590ff974e40SVladimir Kondratiev 	void *cmd;
591ff974e40SVladimir Kondratiev 	int cmdlen = len - sizeof(struct wil6210_mbox_hdr_wmi);
592ff974e40SVladimir Kondratiev 	u16 cmdid;
593ff974e40SVladimir Kondratiev 	int rc, rc1;
594ff974e40SVladimir Kondratiev 
595ff974e40SVladimir Kondratiev 	if (cmdlen <= 0)
596ff974e40SVladimir Kondratiev 		return -EINVAL;
597ff974e40SVladimir Kondratiev 
598ff974e40SVladimir Kondratiev 	wmi = kmalloc(len, GFP_KERNEL);
599ff974e40SVladimir Kondratiev 	if (!wmi)
600ff974e40SVladimir Kondratiev 		return -ENOMEM;
601ff974e40SVladimir Kondratiev 
602ff974e40SVladimir Kondratiev 	rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
603ff974e40SVladimir Kondratiev 	if (rc < 0)
604ff974e40SVladimir Kondratiev 		return rc;
605ff974e40SVladimir Kondratiev 
606ff974e40SVladimir Kondratiev 	cmd = &wmi[1];
607ff974e40SVladimir Kondratiev 	cmdid = le16_to_cpu(wmi->id);
608ff974e40SVladimir Kondratiev 
609ff974e40SVladimir Kondratiev 	rc1 = wmi_send(wil, cmdid, cmd, cmdlen);
610ff974e40SVladimir Kondratiev 	kfree(wmi);
611ff974e40SVladimir Kondratiev 
612ff974e40SVladimir Kondratiev 	wil_info(wil, "%s(0x%04x[%d]) -> %d\n", __func__, cmdid, cmdlen, rc1);
613ff974e40SVladimir Kondratiev 
614ff974e40SVladimir Kondratiev 	return rc;
615ff974e40SVladimir Kondratiev }
616ff974e40SVladimir Kondratiev 
617ff974e40SVladimir Kondratiev static const struct file_operations fops_wmi = {
618ff974e40SVladimir Kondratiev 	.write = wil_write_file_wmi,
619ff974e40SVladimir Kondratiev 	.open  = simple_open,
620ff974e40SVladimir Kondratiev };
621ff974e40SVladimir Kondratiev 
622c236658fSVladimir Kondratiev static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
623c236658fSVladimir Kondratiev 			    const char *prefix)
624c236658fSVladimir Kondratiev {
625c236658fSVladimir Kondratiev 	char printbuf[16 * 3 + 2];
626c236658fSVladimir Kondratiev 	int i = 0;
627c236658fSVladimir Kondratiev 	while (i < len) {
628c236658fSVladimir Kondratiev 		int l = min(len - i, 16);
629c236658fSVladimir Kondratiev 		hex_dump_to_buffer(p + i, l, 16, 1, printbuf,
630c236658fSVladimir Kondratiev 				   sizeof(printbuf), false);
631c236658fSVladimir Kondratiev 		seq_printf(s, "%s%s\n", prefix, printbuf);
632c236658fSVladimir Kondratiev 		i += l;
633c236658fSVladimir Kondratiev 	}
634c236658fSVladimir Kondratiev }
635c236658fSVladimir Kondratiev 
636c236658fSVladimir Kondratiev static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
637c236658fSVladimir Kondratiev {
638c236658fSVladimir Kondratiev 	int i = 0;
639c236658fSVladimir Kondratiev 	int len = skb_headlen(skb);
640c236658fSVladimir Kondratiev 	void *p = skb->data;
641c236658fSVladimir Kondratiev 	int nr_frags = skb_shinfo(skb)->nr_frags;
642c236658fSVladimir Kondratiev 
643c236658fSVladimir Kondratiev 	seq_printf(s, "    len = %d\n", len);
644c236658fSVladimir Kondratiev 	wil_seq_hexdump(s, p, len, "      : ");
645c236658fSVladimir Kondratiev 
646c236658fSVladimir Kondratiev 	if (nr_frags) {
647c236658fSVladimir Kondratiev 		seq_printf(s, "    nr_frags = %d\n", nr_frags);
648c236658fSVladimir Kondratiev 		for (i = 0; i < nr_frags; i++) {
649c236658fSVladimir Kondratiev 			const struct skb_frag_struct *frag =
650c236658fSVladimir Kondratiev 					&skb_shinfo(skb)->frags[i];
651c236658fSVladimir Kondratiev 
652c236658fSVladimir Kondratiev 			len = skb_frag_size(frag);
653c236658fSVladimir Kondratiev 			p = skb_frag_address_safe(frag);
654c236658fSVladimir Kondratiev 			seq_printf(s, "    [%2d] : len = %d\n", i, len);
655c236658fSVladimir Kondratiev 			wil_seq_hexdump(s, p, len, "      : ");
656c236658fSVladimir Kondratiev 		}
657c236658fSVladimir Kondratiev 	}
658c236658fSVladimir Kondratiev }
659c236658fSVladimir Kondratiev 
6603a85543eSVladimir Kondratiev /*---------Tx/Rx descriptor------------*/
6612be7d22fSVladimir Kondratiev static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
6622be7d22fSVladimir Kondratiev {
6632be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
6643a85543eSVladimir Kondratiev 	struct vring *vring;
665af31cb5aSVladimir Kondratiev 	bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS);
666af31cb5aSVladimir Kondratiev 	if (tx)
6673a85543eSVladimir Kondratiev 		vring = &(wil->vring_tx[dbg_vring_index]);
6683a85543eSVladimir Kondratiev 	else
6693a85543eSVladimir Kondratiev 		vring = &wil->vring_rx;
6702be7d22fSVladimir Kondratiev 
6712be7d22fSVladimir Kondratiev 	if (!vring->va) {
672af31cb5aSVladimir Kondratiev 		if (tx)
6733a85543eSVladimir Kondratiev 			seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index);
6743a85543eSVladimir Kondratiev 		else
6753a85543eSVladimir Kondratiev 			seq_puts(s, "No Rx VRING\n");
6762be7d22fSVladimir Kondratiev 		return 0;
6772be7d22fSVladimir Kondratiev 	}
6782be7d22fSVladimir Kondratiev 
6792be7d22fSVladimir Kondratiev 	if (dbg_txdesc_index < vring->size) {
6803a85543eSVladimir Kondratiev 		/* use struct vring_tx_desc for Rx as well,
6813a85543eSVladimir Kondratiev 		 * only field used, .dma.length, is the same
6823a85543eSVladimir Kondratiev 		 */
6832be7d22fSVladimir Kondratiev 		volatile struct vring_tx_desc *d =
6842be7d22fSVladimir Kondratiev 				&(vring->va[dbg_txdesc_index].tx);
6852be7d22fSVladimir Kondratiev 		volatile u32 *u = (volatile u32 *)d;
686f88f113aSVladimir Kondratiev 		struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb;
6872be7d22fSVladimir Kondratiev 
688af31cb5aSVladimir Kondratiev 		if (tx)
6893a85543eSVladimir Kondratiev 			seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index,
6903a85543eSVladimir Kondratiev 				   dbg_txdesc_index);
6913a85543eSVladimir Kondratiev 		else
6923a85543eSVladimir Kondratiev 			seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
6932be7d22fSVladimir Kondratiev 		seq_printf(s, "  MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
6942be7d22fSVladimir Kondratiev 			   u[0], u[1], u[2], u[3]);
6952be7d22fSVladimir Kondratiev 		seq_printf(s, "  DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
6962be7d22fSVladimir Kondratiev 			   u[4], u[5], u[6], u[7]);
69739c52ee8SVladimir Kondratiev 		seq_printf(s, "  SKB = 0x%p\n", skb);
6982be7d22fSVladimir Kondratiev 
6992be7d22fSVladimir Kondratiev 		if (skb) {
700c236658fSVladimir Kondratiev 			skb_get(skb);
701c236658fSVladimir Kondratiev 			wil_seq_print_skb(s, skb);
702c236658fSVladimir Kondratiev 			kfree_skb(skb);
7032be7d22fSVladimir Kondratiev 		}
7042be7d22fSVladimir Kondratiev 		seq_printf(s, "}\n");
7052be7d22fSVladimir Kondratiev 	} else {
706af31cb5aSVladimir Kondratiev 		if (tx)
7073a85543eSVladimir Kondratiev 			seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
7083a85543eSVladimir Kondratiev 				   dbg_vring_index, dbg_txdesc_index,
7093a85543eSVladimir Kondratiev 				   vring->size);
7103a85543eSVladimir Kondratiev 		else
7113a85543eSVladimir Kondratiev 			seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
7122be7d22fSVladimir Kondratiev 				   dbg_txdesc_index, vring->size);
7132be7d22fSVladimir Kondratiev 	}
7142be7d22fSVladimir Kondratiev 
7152be7d22fSVladimir Kondratiev 	return 0;
7162be7d22fSVladimir Kondratiev }
7172be7d22fSVladimir Kondratiev 
7182be7d22fSVladimir Kondratiev static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
7192be7d22fSVladimir Kondratiev {
7202be7d22fSVladimir Kondratiev 	return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
7212be7d22fSVladimir Kondratiev }
7222be7d22fSVladimir Kondratiev 
7232be7d22fSVladimir Kondratiev static const struct file_operations fops_txdesc = {
7242be7d22fSVladimir Kondratiev 	.open		= wil_txdesc_seq_open,
7252be7d22fSVladimir Kondratiev 	.release	= single_release,
7262be7d22fSVladimir Kondratiev 	.read		= seq_read,
7272be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
7282be7d22fSVladimir Kondratiev };
7292be7d22fSVladimir Kondratiev 
7302be7d22fSVladimir Kondratiev /*---------beamforming------------*/
7312be7d22fSVladimir Kondratiev static int wil_bf_debugfs_show(struct seq_file *s, void *data)
7322be7d22fSVladimir Kondratiev {
7332be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
7342be7d22fSVladimir Kondratiev 	seq_printf(s,
7352be7d22fSVladimir Kondratiev 		   "TSF : 0x%016llx\n"
7362be7d22fSVladimir Kondratiev 		   "TxMCS : %d\n"
7372be7d22fSVladimir Kondratiev 		   "Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n",
7382be7d22fSVladimir Kondratiev 		   wil->stats.tsf, wil->stats.bf_mcs,
7392be7d22fSVladimir Kondratiev 		   wil->stats.my_rx_sector, wil->stats.my_tx_sector,
7402be7d22fSVladimir Kondratiev 		   wil->stats.peer_rx_sector, wil->stats.peer_tx_sector);
7412be7d22fSVladimir Kondratiev 	return 0;
7422be7d22fSVladimir Kondratiev }
7432be7d22fSVladimir Kondratiev 
7442be7d22fSVladimir Kondratiev static int wil_bf_seq_open(struct inode *inode, struct file *file)
7452be7d22fSVladimir Kondratiev {
7462be7d22fSVladimir Kondratiev 	return single_open(file, wil_bf_debugfs_show, inode->i_private);
7472be7d22fSVladimir Kondratiev }
7482be7d22fSVladimir Kondratiev 
7492be7d22fSVladimir Kondratiev static const struct file_operations fops_bf = {
7502be7d22fSVladimir Kondratiev 	.open		= wil_bf_seq_open,
7512be7d22fSVladimir Kondratiev 	.release	= single_release,
7522be7d22fSVladimir Kondratiev 	.read		= seq_read,
7532be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
7542be7d22fSVladimir Kondratiev };
7552be7d22fSVladimir Kondratiev /*---------SSID------------*/
7562be7d22fSVladimir Kondratiev static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf,
7572be7d22fSVladimir Kondratiev 				  size_t count, loff_t *ppos)
7582be7d22fSVladimir Kondratiev {
7592be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
7602be7d22fSVladimir Kondratiev 	struct wireless_dev *wdev = wil_to_wdev(wil);
7612be7d22fSVladimir Kondratiev 
7622be7d22fSVladimir Kondratiev 	return simple_read_from_buffer(user_buf, count, ppos,
7632be7d22fSVladimir Kondratiev 				       wdev->ssid, wdev->ssid_len);
7642be7d22fSVladimir Kondratiev }
7652be7d22fSVladimir Kondratiev 
7662be7d22fSVladimir Kondratiev static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf,
7672be7d22fSVladimir Kondratiev 				   size_t count, loff_t *ppos)
7682be7d22fSVladimir Kondratiev {
7692be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
7702be7d22fSVladimir Kondratiev 	struct wireless_dev *wdev = wil_to_wdev(wil);
7712be7d22fSVladimir Kondratiev 	struct net_device *ndev = wil_to_ndev(wil);
7722be7d22fSVladimir Kondratiev 
7732be7d22fSVladimir Kondratiev 	if (*ppos != 0) {
7742be7d22fSVladimir Kondratiev 		wil_err(wil, "Unable to set SSID substring from [%d]\n",
7752be7d22fSVladimir Kondratiev 			(int)*ppos);
7762be7d22fSVladimir Kondratiev 		return -EINVAL;
7772be7d22fSVladimir Kondratiev 	}
7782be7d22fSVladimir Kondratiev 
7792be7d22fSVladimir Kondratiev 	if (count > sizeof(wdev->ssid)) {
7802be7d22fSVladimir Kondratiev 		wil_err(wil, "SSID too long, len = %d\n", (int)count);
7812be7d22fSVladimir Kondratiev 		return -EINVAL;
7822be7d22fSVladimir Kondratiev 	}
7832be7d22fSVladimir Kondratiev 	if (netif_running(ndev)) {
7842be7d22fSVladimir Kondratiev 		wil_err(wil, "Unable to change SSID on running interface\n");
7852be7d22fSVladimir Kondratiev 		return -EINVAL;
7862be7d22fSVladimir Kondratiev 	}
7872be7d22fSVladimir Kondratiev 
7882be7d22fSVladimir Kondratiev 	wdev->ssid_len = count;
7892be7d22fSVladimir Kondratiev 	return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos,
7902be7d22fSVladimir Kondratiev 				      buf, count);
7912be7d22fSVladimir Kondratiev }
7922be7d22fSVladimir Kondratiev 
7932be7d22fSVladimir Kondratiev static const struct file_operations fops_ssid = {
7942be7d22fSVladimir Kondratiev 	.read = wil_read_file_ssid,
7952be7d22fSVladimir Kondratiev 	.write = wil_write_file_ssid,
79693ecbd64SWei Yongjun 	.open  = simple_open,
7972be7d22fSVladimir Kondratiev };
7982be7d22fSVladimir Kondratiev 
7991a2780e0SVladimir Kondratiev /*---------temp------------*/
8001a2780e0SVladimir Kondratiev static void print_temp(struct seq_file *s, const char *prefix, u32 t)
8011a2780e0SVladimir Kondratiev {
8021a2780e0SVladimir Kondratiev 	switch (t) {
8031a2780e0SVladimir Kondratiev 	case 0:
8041a2780e0SVladimir Kondratiev 	case ~(u32)0:
8051a2780e0SVladimir Kondratiev 		seq_printf(s, "%s N/A\n", prefix);
8061a2780e0SVladimir Kondratiev 	break;
8071a2780e0SVladimir Kondratiev 	default:
8081a2780e0SVladimir Kondratiev 		seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
8091a2780e0SVladimir Kondratiev 		break;
8101a2780e0SVladimir Kondratiev 	}
8111a2780e0SVladimir Kondratiev }
8121a2780e0SVladimir Kondratiev 
8131a2780e0SVladimir Kondratiev static int wil_temp_debugfs_show(struct seq_file *s, void *data)
8141a2780e0SVladimir Kondratiev {
8151a2780e0SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
8161a2780e0SVladimir Kondratiev 	u32 t_m, t_r;
8171a2780e0SVladimir Kondratiev 
8181a2780e0SVladimir Kondratiev 	int rc = wmi_get_temperature(wil, &t_m, &t_r);
8191a2780e0SVladimir Kondratiev 	if (rc) {
8201a2780e0SVladimir Kondratiev 		seq_printf(s, "Failed\n");
8211a2780e0SVladimir Kondratiev 		return 0;
8221a2780e0SVladimir Kondratiev 	}
8231a2780e0SVladimir Kondratiev 
824d45cff9fSVladimir Kondratiev 	print_temp(s, "T_mac   =", t_m);
825d45cff9fSVladimir Kondratiev 	print_temp(s, "T_radio =", t_r);
8261a2780e0SVladimir Kondratiev 
8271a2780e0SVladimir Kondratiev 	return 0;
8281a2780e0SVladimir Kondratiev }
8291a2780e0SVladimir Kondratiev 
8301a2780e0SVladimir Kondratiev static int wil_temp_seq_open(struct inode *inode, struct file *file)
8311a2780e0SVladimir Kondratiev {
8321a2780e0SVladimir Kondratiev 	return single_open(file, wil_temp_debugfs_show, inode->i_private);
8331a2780e0SVladimir Kondratiev }
8341a2780e0SVladimir Kondratiev 
8351a2780e0SVladimir Kondratiev static const struct file_operations fops_temp = {
8361a2780e0SVladimir Kondratiev 	.open		= wil_temp_seq_open,
8371a2780e0SVladimir Kondratiev 	.release	= single_release,
8381a2780e0SVladimir Kondratiev 	.read		= seq_read,
8391a2780e0SVladimir Kondratiev 	.llseek		= seq_lseek,
8401a2780e0SVladimir Kondratiev };
8411a2780e0SVladimir Kondratiev 
8429eb82d43SVladimir Kondratiev /*---------freq------------*/
8439eb82d43SVladimir Kondratiev static int wil_freq_debugfs_show(struct seq_file *s, void *data)
8449eb82d43SVladimir Kondratiev {
8459eb82d43SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
8469eb82d43SVladimir Kondratiev 	struct wireless_dev *wdev = wil_to_wdev(wil);
8479eb82d43SVladimir Kondratiev 	u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
8489eb82d43SVladimir Kondratiev 
8499eb82d43SVladimir Kondratiev 	seq_printf(s, "Freq = %d\n", freq);
8509eb82d43SVladimir Kondratiev 
8519eb82d43SVladimir Kondratiev 	return 0;
8529eb82d43SVladimir Kondratiev }
8539eb82d43SVladimir Kondratiev 
8549eb82d43SVladimir Kondratiev static int wil_freq_seq_open(struct inode *inode, struct file *file)
8559eb82d43SVladimir Kondratiev {
8569eb82d43SVladimir Kondratiev 	return single_open(file, wil_freq_debugfs_show, inode->i_private);
8579eb82d43SVladimir Kondratiev }
8589eb82d43SVladimir Kondratiev 
8599eb82d43SVladimir Kondratiev static const struct file_operations fops_freq = {
8609eb82d43SVladimir Kondratiev 	.open		= wil_freq_seq_open,
8619eb82d43SVladimir Kondratiev 	.release	= single_release,
8629eb82d43SVladimir Kondratiev 	.read		= seq_read,
8639eb82d43SVladimir Kondratiev 	.llseek		= seq_lseek,
8649eb82d43SVladimir Kondratiev };
8659eb82d43SVladimir Kondratiev 
8669eb82d43SVladimir Kondratiev /*---------link------------*/
8679eb82d43SVladimir Kondratiev static int wil_link_debugfs_show(struct seq_file *s, void *data)
8689eb82d43SVladimir Kondratiev {
8699eb82d43SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
8709eb82d43SVladimir Kondratiev 	struct station_info sinfo;
8719eb82d43SVladimir Kondratiev 	int i, rc;
8729eb82d43SVladimir Kondratiev 
8739eb82d43SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
8749eb82d43SVladimir Kondratiev 		struct wil_sta_info *p = &wil->sta[i];
8759eb82d43SVladimir Kondratiev 		char *status = "unknown";
8769eb82d43SVladimir Kondratiev 		switch (p->status) {
8779eb82d43SVladimir Kondratiev 		case wil_sta_unused:
8789eb82d43SVladimir Kondratiev 			status = "unused   ";
8799eb82d43SVladimir Kondratiev 			break;
8809eb82d43SVladimir Kondratiev 		case wil_sta_conn_pending:
8819eb82d43SVladimir Kondratiev 			status = "pending  ";
8829eb82d43SVladimir Kondratiev 			break;
8839eb82d43SVladimir Kondratiev 		case wil_sta_connected:
8849eb82d43SVladimir Kondratiev 			status = "connected";
8859eb82d43SVladimir Kondratiev 			break;
8869eb82d43SVladimir Kondratiev 		}
8879eb82d43SVladimir Kondratiev 		seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
8889eb82d43SVladimir Kondratiev 			   (p->data_port_open ? " data_port_open" : ""));
8899eb82d43SVladimir Kondratiev 
8909eb82d43SVladimir Kondratiev 		if (p->status == wil_sta_connected) {
8919eb82d43SVladimir Kondratiev 			rc = wil_cid_fill_sinfo(wil, i, &sinfo);
8929eb82d43SVladimir Kondratiev 			if (rc)
8939eb82d43SVladimir Kondratiev 				return rc;
8949eb82d43SVladimir Kondratiev 
8959eb82d43SVladimir Kondratiev 			seq_printf(s, "  Tx_mcs = %d\n", sinfo.txrate.mcs);
8969eb82d43SVladimir Kondratiev 			seq_printf(s, "  Rx_mcs = %d\n", sinfo.rxrate.mcs);
8979eb82d43SVladimir Kondratiev 			seq_printf(s, "  SQ     = %d\n", sinfo.signal);
8989eb82d43SVladimir Kondratiev 		}
8999eb82d43SVladimir Kondratiev 	}
9009eb82d43SVladimir Kondratiev 
9019eb82d43SVladimir Kondratiev 	return 0;
9029eb82d43SVladimir Kondratiev }
9039eb82d43SVladimir Kondratiev 
9049eb82d43SVladimir Kondratiev static int wil_link_seq_open(struct inode *inode, struct file *file)
9059eb82d43SVladimir Kondratiev {
9069eb82d43SVladimir Kondratiev 	return single_open(file, wil_link_debugfs_show, inode->i_private);
9079eb82d43SVladimir Kondratiev }
9089eb82d43SVladimir Kondratiev 
9099eb82d43SVladimir Kondratiev static const struct file_operations fops_link = {
9109eb82d43SVladimir Kondratiev 	.open		= wil_link_seq_open,
9119eb82d43SVladimir Kondratiev 	.release	= single_release,
9129eb82d43SVladimir Kondratiev 	.read		= seq_read,
9139eb82d43SVladimir Kondratiev 	.llseek		= seq_lseek,
9149eb82d43SVladimir Kondratiev };
9159eb82d43SVladimir Kondratiev 
91684bb29b7SVladimir Kondratiev /*---------info------------*/
91784bb29b7SVladimir Kondratiev static int wil_info_debugfs_show(struct seq_file *s, void *data)
91884bb29b7SVladimir Kondratiev {
919be299858SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
920be299858SVladimir Kondratiev 	struct net_device *ndev = wil_to_ndev(wil);
92184bb29b7SVladimir Kondratiev 	int is_ac = power_supply_is_system_supplied();
922be299858SVladimir Kondratiev 	int rx = atomic_xchg(&wil->isr_count_rx, 0);
923be299858SVladimir Kondratiev 	int tx = atomic_xchg(&wil->isr_count_tx, 0);
924be299858SVladimir Kondratiev 	static ulong rxf_old, txf_old;
925be299858SVladimir Kondratiev 	ulong rxf = ndev->stats.rx_packets;
926be299858SVladimir Kondratiev 	ulong txf = ndev->stats.tx_packets;
92755f8f680SVladimir Kondratiev 	unsigned int i;
92884bb29b7SVladimir Kondratiev 
92984bb29b7SVladimir Kondratiev 	/* >0 : AC; 0 : battery; <0 : error */
93084bb29b7SVladimir Kondratiev 	seq_printf(s, "AC powered : %d\n", is_ac);
931be299858SVladimir Kondratiev 	seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
932be299858SVladimir Kondratiev 	seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
933be299858SVladimir Kondratiev 	rxf_old = rxf;
934be299858SVladimir Kondratiev 	txf_old = txf;
93584bb29b7SVladimir Kondratiev 
93655f8f680SVladimir Kondratiev 
93755f8f680SVladimir Kondratiev #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
93855f8f680SVladimir Kondratiev 	" " __stringify(x) : ""
93955f8f680SVladimir Kondratiev 
94055f8f680SVladimir Kondratiev 	for (i = 0; i < ndev->num_tx_queues; i++) {
94155f8f680SVladimir Kondratiev 		struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
94255f8f680SVladimir Kondratiev 		unsigned long state = txq->state;
94355f8f680SVladimir Kondratiev 
94455f8f680SVladimir Kondratiev 		seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
94555f8f680SVladimir Kondratiev 			   CHECK_QSTATE(DRV_XOFF),
94655f8f680SVladimir Kondratiev 			   CHECK_QSTATE(STACK_XOFF),
94755f8f680SVladimir Kondratiev 			   CHECK_QSTATE(FROZEN)
94855f8f680SVladimir Kondratiev 			  );
94955f8f680SVladimir Kondratiev 	}
95055f8f680SVladimir Kondratiev #undef CHECK_QSTATE
95184bb29b7SVladimir Kondratiev 	return 0;
95284bb29b7SVladimir Kondratiev }
95384bb29b7SVladimir Kondratiev 
95484bb29b7SVladimir Kondratiev static int wil_info_seq_open(struct inode *inode, struct file *file)
95584bb29b7SVladimir Kondratiev {
95684bb29b7SVladimir Kondratiev 	return single_open(file, wil_info_debugfs_show, inode->i_private);
95784bb29b7SVladimir Kondratiev }
95884bb29b7SVladimir Kondratiev 
95984bb29b7SVladimir Kondratiev static const struct file_operations fops_info = {
96084bb29b7SVladimir Kondratiev 	.open		= wil_info_seq_open,
96184bb29b7SVladimir Kondratiev 	.release	= single_release,
96284bb29b7SVladimir Kondratiev 	.read		= seq_read,
96384bb29b7SVladimir Kondratiev 	.llseek		= seq_lseek,
96484bb29b7SVladimir Kondratiev };
96584bb29b7SVladimir Kondratiev 
9663df2cd36SVladimir Kondratiev /*---------Station matrix------------*/
967b4490f42SVladimir Kondratiev static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
968b4490f42SVladimir Kondratiev {
969b4490f42SVladimir Kondratiev 	int i;
970b4490f42SVladimir Kondratiev 	u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
971b4490f42SVladimir Kondratiev 	seq_printf(s, "0x%03x [", r->head_seq_num);
972b4490f42SVladimir Kondratiev 	for (i = 0; i < r->buf_size; i++) {
973b4490f42SVladimir Kondratiev 		if (i == index)
974b4490f42SVladimir Kondratiev 			seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
975b4490f42SVladimir Kondratiev 		else
976b4490f42SVladimir Kondratiev 			seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
977b4490f42SVladimir Kondratiev 	}
978d5b1c32fSVladimir Kondratiev 	seq_printf(s, "] last drop 0x%03x\n", r->ssn_last_drop);
979b4490f42SVladimir Kondratiev }
9803df2cd36SVladimir Kondratiev 
9813df2cd36SVladimir Kondratiev static int wil_sta_debugfs_show(struct seq_file *s, void *data)
9823df2cd36SVladimir Kondratiev {
9833df2cd36SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
984b4490f42SVladimir Kondratiev 	int i, tid;
9853df2cd36SVladimir Kondratiev 
9863df2cd36SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
9873df2cd36SVladimir Kondratiev 		struct wil_sta_info *p = &wil->sta[i];
9883df2cd36SVladimir Kondratiev 		char *status = "unknown";
9893df2cd36SVladimir Kondratiev 		switch (p->status) {
9903df2cd36SVladimir Kondratiev 		case wil_sta_unused:
9913df2cd36SVladimir Kondratiev 			status = "unused   ";
9923df2cd36SVladimir Kondratiev 			break;
9933df2cd36SVladimir Kondratiev 		case wil_sta_conn_pending:
9943df2cd36SVladimir Kondratiev 			status = "pending  ";
9953df2cd36SVladimir Kondratiev 			break;
9963df2cd36SVladimir Kondratiev 		case wil_sta_connected:
9973df2cd36SVladimir Kondratiev 			status = "connected";
9983df2cd36SVladimir Kondratiev 			break;
9993df2cd36SVladimir Kondratiev 		}
1000e58c9f70SVladimir Kondratiev 		seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
1001e58c9f70SVladimir Kondratiev 			   (p->data_port_open ? " data_port_open" : ""));
1002b4490f42SVladimir Kondratiev 
1003b4490f42SVladimir Kondratiev 		if (p->status == wil_sta_connected) {
1004b4490f42SVladimir Kondratiev 			for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1005b4490f42SVladimir Kondratiev 				struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
1006b4490f42SVladimir Kondratiev 				if (r) {
1007b4490f42SVladimir Kondratiev 					seq_printf(s, "[%2d] ", tid);
1008b4490f42SVladimir Kondratiev 					wil_print_rxtid(s, r);
1009b4490f42SVladimir Kondratiev 				}
1010b4490f42SVladimir Kondratiev 			}
1011b4490f42SVladimir Kondratiev 		}
10123df2cd36SVladimir Kondratiev 	}
10133df2cd36SVladimir Kondratiev 
10143df2cd36SVladimir Kondratiev 	return 0;
10153df2cd36SVladimir Kondratiev }
10163df2cd36SVladimir Kondratiev 
10173df2cd36SVladimir Kondratiev static int wil_sta_seq_open(struct inode *inode, struct file *file)
10183df2cd36SVladimir Kondratiev {
10193df2cd36SVladimir Kondratiev 	return single_open(file, wil_sta_debugfs_show, inode->i_private);
10203df2cd36SVladimir Kondratiev }
10213df2cd36SVladimir Kondratiev 
10223df2cd36SVladimir Kondratiev static const struct file_operations fops_sta = {
10233df2cd36SVladimir Kondratiev 	.open		= wil_sta_seq_open,
10243df2cd36SVladimir Kondratiev 	.release	= single_release,
10253df2cd36SVladimir Kondratiev 	.read		= seq_read,
10263df2cd36SVladimir Kondratiev 	.llseek		= seq_lseek,
10273df2cd36SVladimir Kondratiev };
10283df2cd36SVladimir Kondratiev 
10292be7d22fSVladimir Kondratiev /*----------------*/
1030b541d0a0SVladimir Kondratiev static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
1031b541d0a0SVladimir Kondratiev 				       struct dentry *dbg)
1032b541d0a0SVladimir Kondratiev {
1033b541d0a0SVladimir Kondratiev 	int i;
1034b541d0a0SVladimir Kondratiev 	char name[32];
1035b541d0a0SVladimir Kondratiev 
1036b541d0a0SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
1037b541d0a0SVladimir Kondratiev 		struct debugfs_blob_wrapper *blob = &wil->blobs[i];
1038b541d0a0SVladimir Kondratiev 		const struct fw_map *map = &fw_mapping[i];
1039b541d0a0SVladimir Kondratiev 
1040b541d0a0SVladimir Kondratiev 		if (!map->name)
1041b541d0a0SVladimir Kondratiev 			continue;
1042b541d0a0SVladimir Kondratiev 
1043b541d0a0SVladimir Kondratiev 		blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
1044b541d0a0SVladimir Kondratiev 		blob->size = map->to - map->from;
1045b541d0a0SVladimir Kondratiev 		snprintf(name, sizeof(name), "blob_%s", map->name);
1046b541d0a0SVladimir Kondratiev 		wil_debugfs_create_ioblob(name, S_IRUGO, dbg, blob);
1047b541d0a0SVladimir Kondratiev 	}
1048b541d0a0SVladimir Kondratiev }
1049b541d0a0SVladimir Kondratiev 
1050*b7cde470SVladimir Kondratiev /* misc files */
1051*b7cde470SVladimir Kondratiev static const struct {
1052*b7cde470SVladimir Kondratiev 	const char *name;
1053*b7cde470SVladimir Kondratiev 	umode_t mode;
1054*b7cde470SVladimir Kondratiev 	const struct file_operations *fops;
1055*b7cde470SVladimir Kondratiev } dbg_files[] = {
1056*b7cde470SVladimir Kondratiev 	{"mbox",	S_IRUGO,		&fops_mbox},
1057*b7cde470SVladimir Kondratiev 	{"vrings",	S_IRUGO,		&fops_vring},
1058*b7cde470SVladimir Kondratiev 	{"stations",	S_IRUGO,		&fops_sta},
1059*b7cde470SVladimir Kondratiev 	{"desc",	S_IRUGO,		&fops_txdesc},
1060*b7cde470SVladimir Kondratiev 	{"bf",		S_IRUGO,		&fops_bf},
1061*b7cde470SVladimir Kondratiev 	{"ssid",	S_IRUGO | S_IWUSR,	&fops_ssid},
1062*b7cde470SVladimir Kondratiev 	{"mem_val",	S_IRUGO,		&fops_memread},
1063*b7cde470SVladimir Kondratiev 	{"reset",		  S_IWUSR,	&fops_reset},
1064*b7cde470SVladimir Kondratiev 	{"rxon",		  S_IWUSR,	&fops_rxon},
1065*b7cde470SVladimir Kondratiev 	{"tx_mgmt",		  S_IWUSR,	&fops_txmgmt},
1066*b7cde470SVladimir Kondratiev 	{"wmi_send",		  S_IWUSR,	&fops_wmi},
1067*b7cde470SVladimir Kondratiev 	{"temp",	S_IRUGO,		&fops_temp},
1068*b7cde470SVladimir Kondratiev 	{"freq",	S_IRUGO,		&fops_freq},
1069*b7cde470SVladimir Kondratiev 	{"link",	S_IRUGO,		&fops_link},
1070*b7cde470SVladimir Kondratiev 	{"info",	S_IRUGO,		&fops_info},
1071*b7cde470SVladimir Kondratiev };
1072*b7cde470SVladimir Kondratiev 
1073*b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
1074*b7cde470SVladimir Kondratiev 				       struct dentry *dbg)
1075*b7cde470SVladimir Kondratiev {
1076*b7cde470SVladimir Kondratiev 	int i;
1077*b7cde470SVladimir Kondratiev 
1078*b7cde470SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
1079*b7cde470SVladimir Kondratiev 		debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
1080*b7cde470SVladimir Kondratiev 				    wil, dbg_files[i].fops);
1081*b7cde470SVladimir Kondratiev }
1082*b7cde470SVladimir Kondratiev 
1083*b7cde470SVladimir Kondratiev /* interrupt control blocks */
1084*b7cde470SVladimir Kondratiev static const struct {
1085*b7cde470SVladimir Kondratiev 	const char *name;
1086*b7cde470SVladimir Kondratiev 	u32 icr_off;
1087*b7cde470SVladimir Kondratiev } dbg_icr[] = {
1088*b7cde470SVladimir Kondratiev 	{"USER_ICR",		HOSTADDR(RGF_USER_USER_ICR)},
1089*b7cde470SVladimir Kondratiev 	{"DMA_EP_TX_ICR",	HOSTADDR(RGF_DMA_EP_TX_ICR)},
1090*b7cde470SVladimir Kondratiev 	{"DMA_EP_RX_ICR",	HOSTADDR(RGF_DMA_EP_RX_ICR)},
1091*b7cde470SVladimir Kondratiev 	{"DMA_EP_MISC_ICR",	HOSTADDR(RGF_DMA_EP_MISC_ICR)},
1092*b7cde470SVladimir Kondratiev };
1093*b7cde470SVladimir Kondratiev 
1094*b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
1095*b7cde470SVladimir Kondratiev 				     struct dentry *dbg)
1096*b7cde470SVladimir Kondratiev {
1097*b7cde470SVladimir Kondratiev 	int i;
1098*b7cde470SVladimir Kondratiev 
1099*b7cde470SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
1100*b7cde470SVladimir Kondratiev 		wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
1101*b7cde470SVladimir Kondratiev 					   dbg_icr[i].icr_off);
1102*b7cde470SVladimir Kondratiev }
1103*b7cde470SVladimir Kondratiev 
1104*b7cde470SVladimir Kondratiev #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
1105*b7cde470SVladimir Kondratiev 	offsetof(struct wil6210_priv, name), type}
1106*b7cde470SVladimir Kondratiev 
1107*b7cde470SVladimir Kondratiev /* fields in struct wil6210_priv */
1108*b7cde470SVladimir Kondratiev static const struct dbg_off dbg_wil_off[] = {
1109*b7cde470SVladimir Kondratiev 	WIL_FIELD(secure_pcp,	S_IRUGO | S_IWUSR,	doff_u32),
1110*b7cde470SVladimir Kondratiev 	WIL_FIELD(status,	S_IRUGO | S_IWUSR,	doff_ulong),
1111*b7cde470SVladimir Kondratiev 	WIL_FIELD(fw_version,	S_IRUGO,		doff_u32),
1112*b7cde470SVladimir Kondratiev 	WIL_FIELD(hw_version,	S_IRUGO,		doff_x32),
1113*b7cde470SVladimir Kondratiev 	{},
1114*b7cde470SVladimir Kondratiev };
1115*b7cde470SVladimir Kondratiev 
1116*b7cde470SVladimir Kondratiev static const struct dbg_off dbg_wil_regs[] = {
1117*b7cde470SVladimir Kondratiev 	{"RGF_MAC_MTRL_COUNTER_0", S_IRUGO, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
1118*b7cde470SVladimir Kondratiev 		doff_io32},
1119*b7cde470SVladimir Kondratiev 	{"RGF_USER_USAGE_1", S_IRUGO, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
1120*b7cde470SVladimir Kondratiev 	{},
1121*b7cde470SVladimir Kondratiev };
1122*b7cde470SVladimir Kondratiev 
1123*b7cde470SVladimir Kondratiev /* static parameters */
1124*b7cde470SVladimir Kondratiev static const struct dbg_off dbg_statics[] = {
1125*b7cde470SVladimir Kondratiev 	{"desc_index",	S_IRUGO | S_IWUSR, (ulong)&dbg_txdesc_index, doff_u32},
1126*b7cde470SVladimir Kondratiev 	{"vring_index",	S_IRUGO | S_IWUSR, (ulong)&dbg_vring_index, doff_u32},
1127*b7cde470SVladimir Kondratiev 	{"mem_addr",	S_IRUGO | S_IWUSR, (ulong)&mem_addr, doff_u32},
1128*b7cde470SVladimir Kondratiev 	{},
1129*b7cde470SVladimir Kondratiev };
1130*b7cde470SVladimir Kondratiev 
11312be7d22fSVladimir Kondratiev int wil6210_debugfs_init(struct wil6210_priv *wil)
11322be7d22fSVladimir Kondratiev {
11332be7d22fSVladimir Kondratiev 	struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
11342be7d22fSVladimir Kondratiev 			wil_to_wiphy(wil)->debugfsdir);
11352be7d22fSVladimir Kondratiev 
11362be7d22fSVladimir Kondratiev 	if (IS_ERR_OR_NULL(dbg))
11372be7d22fSVladimir Kondratiev 		return -ENODEV;
11382be7d22fSVladimir Kondratiev 
1139*b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_files(wil, dbg);
1140*b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_isr(wil, dbg);
1141b541d0a0SVladimir Kondratiev 	wil6210_debugfs_init_blobs(wil, dbg);
1142*b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
1143*b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
1144*b7cde470SVladimir Kondratiev 				    dbg_wil_regs);
1145*b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
1146*b7cde470SVladimir Kondratiev 
1147*b7cde470SVladimir Kondratiev 	wil6210_debugfs_create_pseudo_ISR(wil, dbg);
1148*b7cde470SVladimir Kondratiev 
1149*b7cde470SVladimir Kondratiev 	wil6210_debugfs_create_ITR_CNT(wil, dbg);
11502be7d22fSVladimir Kondratiev 
11512be7d22fSVladimir Kondratiev 	return 0;
11522be7d22fSVladimir Kondratiev }
11532be7d22fSVladimir Kondratiev 
11542be7d22fSVladimir Kondratiev void wil6210_debugfs_remove(struct wil6210_priv *wil)
11552be7d22fSVladimir Kondratiev {
11562be7d22fSVladimir Kondratiev 	debugfs_remove_recursive(wil->debug);
11572be7d22fSVladimir Kondratiev 	wil->debug = NULL;
11582be7d22fSVladimir Kondratiev }
1159