xref: /linux/drivers/net/wireless/ath/wil6210/debugfs.c (revision 96c93589e2dfd43ad16b92e6677ceaf279ae5062)
12be7d22fSVladimir Kondratiev /*
2a351f2f5SLazar Alexei  * Copyright (c) 2012-2017 Qualcomm Atheros, Inc.
3e00243faSLior David  * Copyright (c) 2018, The Linux Foundation. All rights reserved.
42be7d22fSVladimir Kondratiev  *
52be7d22fSVladimir Kondratiev  * Permission to use, copy, modify, and/or distribute this software for any
62be7d22fSVladimir Kondratiev  * purpose with or without fee is hereby granted, provided that the above
72be7d22fSVladimir Kondratiev  * copyright notice and this permission notice appear in all copies.
82be7d22fSVladimir Kondratiev  *
92be7d22fSVladimir Kondratiev  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
102be7d22fSVladimir Kondratiev  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
112be7d22fSVladimir Kondratiev  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
122be7d22fSVladimir Kondratiev  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
132be7d22fSVladimir Kondratiev  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
142be7d22fSVladimir Kondratiev  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
152be7d22fSVladimir Kondratiev  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
162be7d22fSVladimir Kondratiev  */
172be7d22fSVladimir Kondratiev 
182be7d22fSVladimir Kondratiev #include <linux/module.h>
192be7d22fSVladimir Kondratiev #include <linux/debugfs.h>
202be7d22fSVladimir Kondratiev #include <linux/seq_file.h>
212be7d22fSVladimir Kondratiev #include <linux/pci.h>
222be7d22fSVladimir Kondratiev #include <linux/rtnetlink.h>
2384bb29b7SVladimir Kondratiev #include <linux/power_supply.h>
242be7d22fSVladimir Kondratiev #include "wil6210.h"
2536345ac3SVladimir Kondratiev #include "wmi.h"
262be7d22fSVladimir Kondratiev #include "txrx.h"
27dc16427bSVladimir Kondratiev #include "pmc.h"
282be7d22fSVladimir Kondratiev 
292be7d22fSVladimir Kondratiev /* Nasty hack. Better have per device instances */
302be7d22fSVladimir Kondratiev static u32 mem_addr;
312be7d22fSVladimir Kondratiev static u32 dbg_txdesc_index;
3210590c6aSGidon Studinski static u32 dbg_ring_index; /* 24+ for Rx, 0..23 for Tx */
332be7d22fSVladimir Kondratiev 
34b7cde470SVladimir Kondratiev enum dbg_off_type {
35b7cde470SVladimir Kondratiev 	doff_u32 = 0,
36b7cde470SVladimir Kondratiev 	doff_x32 = 1,
37b7cde470SVladimir Kondratiev 	doff_ulong = 2,
38b7cde470SVladimir Kondratiev 	doff_io32 = 3,
3974997a53SLior David 	doff_u8 = 4
40b7cde470SVladimir Kondratiev };
41b7cde470SVladimir Kondratiev 
42b7cde470SVladimir Kondratiev /* offset to "wil" */
43b7cde470SVladimir Kondratiev struct dbg_off {
44b7cde470SVladimir Kondratiev 	const char *name;
45b7cde470SVladimir Kondratiev 	umode_t mode;
46b7cde470SVladimir Kondratiev 	ulong off;
47b7cde470SVladimir Kondratiev 	enum dbg_off_type type;
48b7cde470SVladimir Kondratiev };
49b7cde470SVladimir Kondratiev 
5010590c6aSGidon Studinski static void wil_print_ring(struct seq_file *s, struct wil6210_priv *wil,
5110590c6aSGidon Studinski 			   const char *name, struct wil_ring *ring,
5259f7c0a9SVladimir Kondratiev 			   char _s, char _h)
532be7d22fSVladimir Kondratiev {
5410590c6aSGidon Studinski 	void __iomem *x = wmi_addr(wil, ring->hwtail);
55995cdd0eSVladimir Kondratiev 	u32 v;
562be7d22fSVladimir Kondratiev 
5710590c6aSGidon Studinski 	seq_printf(s, "RING %s = {\n", name);
5810590c6aSGidon Studinski 	seq_printf(s, "  pa     = %pad\n", &ring->pa);
5910590c6aSGidon Studinski 	seq_printf(s, "  va     = 0x%p\n", ring->va);
6010590c6aSGidon Studinski 	seq_printf(s, "  size   = %d\n", ring->size);
6110590c6aSGidon Studinski 	seq_printf(s, "  swtail = %d\n", ring->swtail);
6210590c6aSGidon Studinski 	seq_printf(s, "  swhead = %d\n", ring->swhead);
6310590c6aSGidon Studinski 	seq_printf(s, "  hwtail = [0x%08x] -> ", ring->hwtail);
64995cdd0eSVladimir Kondratiev 	if (x) {
65b9eeb512SVladimir Kondratiev 		v = readl(x);
66995cdd0eSVladimir Kondratiev 		seq_printf(s, "0x%08x = %d\n", v, v);
67995cdd0eSVladimir Kondratiev 	} else {
688fe59627SVladimir Kondratiev 		seq_puts(s, "???\n");
69995cdd0eSVladimir Kondratiev 	}
702be7d22fSVladimir Kondratiev 
7110590c6aSGidon Studinski 	if (ring->va && (ring->size <= (1 << WIL_RING_SIZE_ORDER_MAX))) {
722be7d22fSVladimir Kondratiev 		uint i;
738fe59627SVladimir Kondratiev 
7410590c6aSGidon Studinski 		for (i = 0; i < ring->size; i++) {
7510590c6aSGidon Studinski 			volatile struct vring_tx_desc *d =
7610590c6aSGidon Studinski 				&ring->va[i].tx.legacy;
778fe59627SVladimir Kondratiev 
78ee5dfe0dSHamad Kadmany 			if ((i % 128) == 0 && (i != 0))
798fe59627SVladimir Kondratiev 				seq_puts(s, "\n");
8059f7c0a9SVladimir Kondratiev 			seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
8110590c6aSGidon Studinski 					_s : (ring->ctx[i].skb ? _h : 'h'));
822be7d22fSVladimir Kondratiev 		}
838fe59627SVladimir Kondratiev 		seq_puts(s, "\n");
842be7d22fSVladimir Kondratiev 	}
858fe59627SVladimir Kondratiev 	seq_puts(s, "}\n");
862be7d22fSVladimir Kondratiev }
872be7d22fSVladimir Kondratiev 
8810590c6aSGidon Studinski static int wil_ring_debugfs_show(struct seq_file *s, void *data)
892be7d22fSVladimir Kondratiev {
902be7d22fSVladimir Kondratiev 	uint i;
912be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
922be7d22fSVladimir Kondratiev 
9310590c6aSGidon Studinski 	wil_print_ring(s, wil, "rx", &wil->ring_rx, 'S', '_');
942be7d22fSVladimir Kondratiev 
9510590c6aSGidon Studinski 	for (i = 0; i < ARRAY_SIZE(wil->ring_tx); i++) {
9610590c6aSGidon Studinski 		struct wil_ring *ring = &wil->ring_tx[i];
9710590c6aSGidon Studinski 		struct wil_ring_tx_data *txdata = &wil->ring_tx_data[i];
987c0acf86SVladimir Kondratiev 
9910590c6aSGidon Studinski 		if (ring->va) {
10010590c6aSGidon Studinski 			int cid = wil->ring2cid_tid[i][0];
10110590c6aSGidon Studinski 			int tid = wil->ring2cid_tid[i][1];
10210590c6aSGidon Studinski 			u32 swhead = ring->swhead;
10310590c6aSGidon Studinski 			u32 swtail = ring->swtail;
10410590c6aSGidon Studinski 			int used = (ring->size + swhead - swtail)
10510590c6aSGidon Studinski 				   % ring->size;
10610590c6aSGidon Studinski 			int avail = ring->size - used - 1;
1072be7d22fSVladimir Kondratiev 			char name[10];
1088f55cbecSBoris Sorochkin 			char sidle[10];
1097c0acf86SVladimir Kondratiev 			/* performance monitoring */
1107c0acf86SVladimir Kondratiev 			cycles_t now = get_cycles();
111c20e7789SChen Gang 			uint64_t idle = txdata->idle * 100;
112c20e7789SChen Gang 			uint64_t total = now - txdata->begin;
1137c0acf86SVladimir Kondratiev 
1148f55cbecSBoris Sorochkin 			if (total != 0) {
115e48b1790SVladimir Kondratiev 				do_div(idle, total);
1168f55cbecSBoris Sorochkin 				snprintf(sidle, sizeof(sidle), "%3d%%",
1178f55cbecSBoris Sorochkin 					 (int)idle);
1188f55cbecSBoris Sorochkin 			} else {
1198f55cbecSBoris Sorochkin 				snprintf(sidle, sizeof(sidle), "N/A");
1208f55cbecSBoris Sorochkin 			}
1217c0acf86SVladimir Kondratiev 			txdata->begin = now;
1227c0acf86SVladimir Kondratiev 			txdata->idle = 0ULL;
1237c0acf86SVladimir Kondratiev 
1242be7d22fSVladimir Kondratiev 			snprintf(name, sizeof(name), "tx_%2d", i);
1253df2cd36SVladimir Kondratiev 
12641d6b093SVladimir Kondratiev 			if (cid < WIL6210_MAX_CID)
1273277213fSVladimir Kondratiev 				seq_printf(s,
128230d8442SVladimir Kondratiev 					   "\n%pM CID %d TID %d 1x%s BACK([%u] %u TU A%s) [%3d|%3d] idle %s\n",
1293277213fSVladimir Kondratiev 					   wil->sta[cid].addr, cid, tid,
130230d8442SVladimir Kondratiev 					   txdata->dot1x_open ? "+" : "-",
13141d6b093SVladimir Kondratiev 					   txdata->agg_wsize,
13241d6b093SVladimir Kondratiev 					   txdata->agg_timeout,
133cbcf5866SVladimir Kondratiev 					   txdata->agg_amsdu ? "+" : "-",
1348f55cbecSBoris Sorochkin 					   used, avail, sidle);
13541d6b093SVladimir Kondratiev 			else
13641d6b093SVladimir Kondratiev 				seq_printf(s,
137230d8442SVladimir Kondratiev 					   "\nBroadcast 1x%s [%3d|%3d] idle %s\n",
138230d8442SVladimir Kondratiev 					   txdata->dot1x_open ? "+" : "-",
13941d6b093SVladimir Kondratiev 					   used, avail, sidle);
1407c0acf86SVladimir Kondratiev 
14110590c6aSGidon Studinski 			wil_print_ring(s, wil, name, ring, '_', 'H');
1422be7d22fSVladimir Kondratiev 		}
1432be7d22fSVladimir Kondratiev 	}
1442be7d22fSVladimir Kondratiev 
1452be7d22fSVladimir Kondratiev 	return 0;
1462be7d22fSVladimir Kondratiev }
1472be7d22fSVladimir Kondratiev 
14810590c6aSGidon Studinski static int wil_ring_seq_open(struct inode *inode, struct file *file)
1492be7d22fSVladimir Kondratiev {
15010590c6aSGidon Studinski 	return single_open(file, wil_ring_debugfs_show, inode->i_private);
1512be7d22fSVladimir Kondratiev }
1522be7d22fSVladimir Kondratiev 
15310590c6aSGidon Studinski static const struct file_operations fops_ring = {
15410590c6aSGidon Studinski 	.open		= wil_ring_seq_open,
1552be7d22fSVladimir Kondratiev 	.release	= single_release,
1562be7d22fSVladimir Kondratiev 	.read		= seq_read,
1572be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
1582be7d22fSVladimir Kondratiev };
1592be7d22fSVladimir Kondratiev 
160a202fbbfSAndy Shevchenko static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
161a202fbbfSAndy Shevchenko 			    const char *prefix)
162a202fbbfSAndy Shevchenko {
163a202fbbfSAndy Shevchenko 	seq_hex_dump(s, prefix, DUMP_PREFIX_NONE, 16, 1, p, len, false);
164a202fbbfSAndy Shevchenko }
165a202fbbfSAndy Shevchenko 
16610590c6aSGidon Studinski static void wil_print_mbox_ring(struct seq_file *s, const char *prefix,
1672be7d22fSVladimir Kondratiev 				void __iomem *off)
1682be7d22fSVladimir Kondratiev {
1692be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
1702be7d22fSVladimir Kondratiev 	struct wil6210_mbox_ring r;
1712be7d22fSVladimir Kondratiev 	int rsize;
1722be7d22fSVladimir Kondratiev 	uint i;
1732be7d22fSVladimir Kondratiev 
174349214c1SMaya Erez 	wil_halp_vote(wil);
175349214c1SMaya Erez 
1762be7d22fSVladimir Kondratiev 	wil_memcpy_fromio_32(&r, off, sizeof(r));
1772be7d22fSVladimir Kondratiev 	wil_mbox_ring_le2cpus(&r);
1782be7d22fSVladimir Kondratiev 	/*
1792be7d22fSVladimir Kondratiev 	 * we just read memory block from NIC. This memory may be
1802be7d22fSVladimir Kondratiev 	 * garbage. Check validity before using it.
1812be7d22fSVladimir Kondratiev 	 */
1822be7d22fSVladimir Kondratiev 	rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
1832be7d22fSVladimir Kondratiev 
1842be7d22fSVladimir Kondratiev 	seq_printf(s, "ring %s = {\n", prefix);
1852be7d22fSVladimir Kondratiev 	seq_printf(s, "  base = 0x%08x\n", r.base);
1862be7d22fSVladimir Kondratiev 	seq_printf(s, "  size = 0x%04x bytes -> %d entries\n", r.size, rsize);
1872be7d22fSVladimir Kondratiev 	seq_printf(s, "  tail = 0x%08x\n", r.tail);
1882be7d22fSVladimir Kondratiev 	seq_printf(s, "  head = 0x%08x\n", r.head);
1892be7d22fSVladimir Kondratiev 	seq_printf(s, "  entry size = %d\n", r.entry_size);
1902be7d22fSVladimir Kondratiev 
1912be7d22fSVladimir Kondratiev 	if (r.size % sizeof(struct wil6210_mbox_ring_desc)) {
1922be7d22fSVladimir Kondratiev 		seq_printf(s, "  ??? size is not multiple of %zd, garbage?\n",
1932be7d22fSVladimir Kondratiev 			   sizeof(struct wil6210_mbox_ring_desc));
1942be7d22fSVladimir Kondratiev 		goto out;
1952be7d22fSVladimir Kondratiev 	}
1962be7d22fSVladimir Kondratiev 
1972be7d22fSVladimir Kondratiev 	if (!wmi_addr(wil, r.base) ||
1982be7d22fSVladimir Kondratiev 	    !wmi_addr(wil, r.tail) ||
1992be7d22fSVladimir Kondratiev 	    !wmi_addr(wil, r.head)) {
2008fe59627SVladimir Kondratiev 		seq_puts(s, "  ??? pointers are garbage?\n");
2012be7d22fSVladimir Kondratiev 		goto out;
2022be7d22fSVladimir Kondratiev 	}
2032be7d22fSVladimir Kondratiev 
2042be7d22fSVladimir Kondratiev 	for (i = 0; i < rsize; i++) {
2052be7d22fSVladimir Kondratiev 		struct wil6210_mbox_ring_desc d;
2062be7d22fSVladimir Kondratiev 		struct wil6210_mbox_hdr hdr;
2072be7d22fSVladimir Kondratiev 		size_t delta = i * sizeof(d);
2082be7d22fSVladimir Kondratiev 		void __iomem *x = wil->csr + HOSTADDR(r.base) + delta;
2092be7d22fSVladimir Kondratiev 
2102be7d22fSVladimir Kondratiev 		wil_memcpy_fromio_32(&d, x, sizeof(d));
2112be7d22fSVladimir Kondratiev 
2122be7d22fSVladimir Kondratiev 		seq_printf(s, "  [%2x] %s %s%s 0x%08x", i,
2132be7d22fSVladimir Kondratiev 			   d.sync ? "F" : "E",
2142be7d22fSVladimir Kondratiev 			   (r.tail - r.base == delta) ? "t" : " ",
2152be7d22fSVladimir Kondratiev 			   (r.head - r.base == delta) ? "h" : " ",
2162be7d22fSVladimir Kondratiev 			   le32_to_cpu(d.addr));
2172be7d22fSVladimir Kondratiev 		if (0 == wmi_read_hdr(wil, d.addr, &hdr)) {
2182be7d22fSVladimir Kondratiev 			u16 len = le16_to_cpu(hdr.len);
2198fe59627SVladimir Kondratiev 
2202be7d22fSVladimir Kondratiev 			seq_printf(s, " -> %04x %04x %04x %02x\n",
2212be7d22fSVladimir Kondratiev 				   le16_to_cpu(hdr.seq), len,
2222be7d22fSVladimir Kondratiev 				   le16_to_cpu(hdr.type), hdr.flags);
2232be7d22fSVladimir Kondratiev 			if (len <= MAX_MBOXITEM_SIZE) {
2242be7d22fSVladimir Kondratiev 				unsigned char databuf[MAX_MBOXITEM_SIZE];
2252be7d22fSVladimir Kondratiev 				void __iomem *src = wmi_buffer(wil, d.addr) +
2262be7d22fSVladimir Kondratiev 					sizeof(struct wil6210_mbox_hdr);
2272be7d22fSVladimir Kondratiev 				/*
2282be7d22fSVladimir Kondratiev 				 * No need to check @src for validity -
2292be7d22fSVladimir Kondratiev 				 * we already validated @d.addr while
2302be7d22fSVladimir Kondratiev 				 * reading header
2312be7d22fSVladimir Kondratiev 				 */
2322be7d22fSVladimir Kondratiev 				wil_memcpy_fromio_32(databuf, src, len);
233a202fbbfSAndy Shevchenko 				wil_seq_hexdump(s, databuf, len, "      : ");
2342be7d22fSVladimir Kondratiev 			}
2352be7d22fSVladimir Kondratiev 		} else {
2368fe59627SVladimir Kondratiev 			seq_puts(s, "\n");
2372be7d22fSVladimir Kondratiev 		}
2382be7d22fSVladimir Kondratiev 	}
2392be7d22fSVladimir Kondratiev  out:
2408fe59627SVladimir Kondratiev 	seq_puts(s, "}\n");
241349214c1SMaya Erez 	wil_halp_unvote(wil);
2422be7d22fSVladimir Kondratiev }
2432be7d22fSVladimir Kondratiev 
2442be7d22fSVladimir Kondratiev static int wil_mbox_debugfs_show(struct seq_file *s, void *data)
2452be7d22fSVladimir Kondratiev {
2462be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
24794162666SLazar Alexei 	int ret;
24894162666SLazar Alexei 
24994162666SLazar Alexei 	ret = wil_pm_runtime_get(wil);
25094162666SLazar Alexei 	if (ret < 0)
25194162666SLazar Alexei 		return ret;
2522be7d22fSVladimir Kondratiev 
25310590c6aSGidon Studinski 	wil_print_mbox_ring(s, "tx", wil->csr + HOST_MBOX +
2542be7d22fSVladimir Kondratiev 		       offsetof(struct wil6210_mbox_ctl, tx));
25510590c6aSGidon Studinski 	wil_print_mbox_ring(s, "rx", wil->csr + HOST_MBOX +
2562be7d22fSVladimir Kondratiev 		       offsetof(struct wil6210_mbox_ctl, rx));
2572be7d22fSVladimir Kondratiev 
25894162666SLazar Alexei 	wil_pm_runtime_put(wil);
25994162666SLazar Alexei 
2602be7d22fSVladimir Kondratiev 	return 0;
2612be7d22fSVladimir Kondratiev }
2622be7d22fSVladimir Kondratiev 
2632be7d22fSVladimir Kondratiev static int wil_mbox_seq_open(struct inode *inode, struct file *file)
2642be7d22fSVladimir Kondratiev {
2652be7d22fSVladimir Kondratiev 	return single_open(file, wil_mbox_debugfs_show, inode->i_private);
2662be7d22fSVladimir Kondratiev }
2672be7d22fSVladimir Kondratiev 
2682be7d22fSVladimir Kondratiev static const struct file_operations fops_mbox = {
2692be7d22fSVladimir Kondratiev 	.open		= wil_mbox_seq_open,
2702be7d22fSVladimir Kondratiev 	.release	= single_release,
2712be7d22fSVladimir Kondratiev 	.read		= seq_read,
2722be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
2732be7d22fSVladimir Kondratiev };
2742be7d22fSVladimir Kondratiev 
2752be7d22fSVladimir Kondratiev static int wil_debugfs_iomem_x32_set(void *data, u64 val)
2762be7d22fSVladimir Kondratiev {
27794162666SLazar Alexei 	struct wil_debugfs_iomem_data *d = (struct
27894162666SLazar Alexei 					    wil_debugfs_iomem_data *)data;
27994162666SLazar Alexei 	struct wil6210_priv *wil = d->wil;
28094162666SLazar Alexei 	int ret;
28194162666SLazar Alexei 
28294162666SLazar Alexei 	ret = wil_pm_runtime_get(wil);
28394162666SLazar Alexei 	if (ret < 0)
28494162666SLazar Alexei 		return ret;
28594162666SLazar Alexei 
28694162666SLazar Alexei 	writel(val, (void __iomem *)d->offset);
2872be7d22fSVladimir Kondratiev 	wmb(); /* make sure write propagated to HW */
2882be7d22fSVladimir Kondratiev 
28994162666SLazar Alexei 	wil_pm_runtime_put(wil);
29094162666SLazar Alexei 
2912be7d22fSVladimir Kondratiev 	return 0;
2922be7d22fSVladimir Kondratiev }
2932be7d22fSVladimir Kondratiev 
2942be7d22fSVladimir Kondratiev static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
2952be7d22fSVladimir Kondratiev {
29694162666SLazar Alexei 	struct wil_debugfs_iomem_data *d = (struct
29794162666SLazar Alexei 					    wil_debugfs_iomem_data *)data;
29894162666SLazar Alexei 	struct wil6210_priv *wil = d->wil;
29994162666SLazar Alexei 	int ret;
30094162666SLazar Alexei 
30194162666SLazar Alexei 	ret = wil_pm_runtime_get(wil);
30294162666SLazar Alexei 	if (ret < 0)
30394162666SLazar Alexei 		return ret;
30494162666SLazar Alexei 
30594162666SLazar Alexei 	*val = readl((void __iomem *)d->offset);
30694162666SLazar Alexei 
30794162666SLazar Alexei 	wil_pm_runtime_put(wil);
3082be7d22fSVladimir Kondratiev 
3092be7d22fSVladimir Kondratiev 	return 0;
3102be7d22fSVladimir Kondratiev }
3112be7d22fSVladimir Kondratiev 
3122be7d22fSVladimir Kondratiev DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
3132be7d22fSVladimir Kondratiev 			wil_debugfs_iomem_x32_set, "0x%08llx\n");
3142be7d22fSVladimir Kondratiev 
3152be7d22fSVladimir Kondratiev static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
3160ecc833bSAl Viro 						   umode_t mode,
3172be7d22fSVladimir Kondratiev 						   struct dentry *parent,
31894162666SLazar Alexei 						   void *value,
31994162666SLazar Alexei 						   struct wil6210_priv *wil)
3202be7d22fSVladimir Kondratiev {
32194162666SLazar Alexei 	struct dentry *file;
32294162666SLazar Alexei 	struct wil_debugfs_iomem_data *data = &wil->dbg_data.data_arr[
32394162666SLazar Alexei 					      wil->dbg_data.iomem_data_count];
32494162666SLazar Alexei 
32594162666SLazar Alexei 	data->wil = wil;
32694162666SLazar Alexei 	data->offset = value;
32794162666SLazar Alexei 
32894162666SLazar Alexei 	file = debugfs_create_file(name, mode, parent, data, &fops_iomem_x32);
32994162666SLazar Alexei 	if (!IS_ERR_OR_NULL(file))
33094162666SLazar Alexei 		wil->dbg_data.iomem_data_count++;
33194162666SLazar Alexei 
33294162666SLazar Alexei 	return file;
3332be7d22fSVladimir Kondratiev }
3342be7d22fSVladimir Kondratiev 
3353de6cf20SVladimir Kondratiev static int wil_debugfs_ulong_set(void *data, u64 val)
3363de6cf20SVladimir Kondratiev {
3373de6cf20SVladimir Kondratiev 	*(ulong *)data = val;
3383de6cf20SVladimir Kondratiev 	return 0;
3393de6cf20SVladimir Kondratiev }
3408fe59627SVladimir Kondratiev 
3413de6cf20SVladimir Kondratiev static int wil_debugfs_ulong_get(void *data, u64 *val)
3423de6cf20SVladimir Kondratiev {
3433de6cf20SVladimir Kondratiev 	*val = *(ulong *)data;
3443de6cf20SVladimir Kondratiev 	return 0;
3453de6cf20SVladimir Kondratiev }
3468fe59627SVladimir Kondratiev 
3473de6cf20SVladimir Kondratiev DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
3488ea06188SVladimir Kondratiev 			wil_debugfs_ulong_set, "0x%llx\n");
3493de6cf20SVladimir Kondratiev 
3503de6cf20SVladimir Kondratiev static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode,
3513de6cf20SVladimir Kondratiev 					       struct dentry *parent,
3523de6cf20SVladimir Kondratiev 					       ulong *value)
3533de6cf20SVladimir Kondratiev {
3543de6cf20SVladimir Kondratiev 	return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong);
3553de6cf20SVladimir Kondratiev }
3563de6cf20SVladimir Kondratiev 
357b7cde470SVladimir Kondratiev /**
358b7cde470SVladimir Kondratiev  * wil6210_debugfs_init_offset - create set of debugfs files
359b7cde470SVladimir Kondratiev  * @wil - driver's context, used for printing
360b7cde470SVladimir Kondratiev  * @dbg - directory on the debugfs, where files will be created
361b7cde470SVladimir Kondratiev  * @base - base address used in address calculation
362b7cde470SVladimir Kondratiev  * @tbl - table with file descriptions. Should be terminated with empty element.
363b7cde470SVladimir Kondratiev  *
364b7cde470SVladimir Kondratiev  * Creates files accordingly to the @tbl.
365b7cde470SVladimir Kondratiev  */
366b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_offset(struct wil6210_priv *wil,
367b7cde470SVladimir Kondratiev 					struct dentry *dbg, void *base,
368b7cde470SVladimir Kondratiev 					const struct dbg_off * const tbl)
369b7cde470SVladimir Kondratiev {
370b7cde470SVladimir Kondratiev 	int i;
371b7cde470SVladimir Kondratiev 
372b7cde470SVladimir Kondratiev 	for (i = 0; tbl[i].name; i++) {
373867fa0d4SVladimir Kondratiev 		struct dentry *f;
374b7cde470SVladimir Kondratiev 
375b7cde470SVladimir Kondratiev 		switch (tbl[i].type) {
376b7cde470SVladimir Kondratiev 		case doff_u32:
377b7cde470SVladimir Kondratiev 			f = debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg,
378b7cde470SVladimir Kondratiev 					       base + tbl[i].off);
379b7cde470SVladimir Kondratiev 			break;
380b7cde470SVladimir Kondratiev 		case doff_x32:
381b7cde470SVladimir Kondratiev 			f = debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg,
382b7cde470SVladimir Kondratiev 					       base + tbl[i].off);
383b7cde470SVladimir Kondratiev 			break;
384b7cde470SVladimir Kondratiev 		case doff_ulong:
385b7cde470SVladimir Kondratiev 			f = wil_debugfs_create_ulong(tbl[i].name, tbl[i].mode,
386b7cde470SVladimir Kondratiev 						     dbg, base + tbl[i].off);
387b7cde470SVladimir Kondratiev 			break;
388b7cde470SVladimir Kondratiev 		case doff_io32:
389b7cde470SVladimir Kondratiev 			f = wil_debugfs_create_iomem_x32(tbl[i].name,
390b7cde470SVladimir Kondratiev 							 tbl[i].mode, dbg,
39194162666SLazar Alexei 							 base + tbl[i].off,
39294162666SLazar Alexei 							 wil);
393b7cde470SVladimir Kondratiev 			break;
39474997a53SLior David 		case doff_u8:
39574997a53SLior David 			f = debugfs_create_u8(tbl[i].name, tbl[i].mode, dbg,
39674997a53SLior David 					      base + tbl[i].off);
39774997a53SLior David 			break;
398867fa0d4SVladimir Kondratiev 		default:
399867fa0d4SVladimir Kondratiev 			f = ERR_PTR(-EINVAL);
400b7cde470SVladimir Kondratiev 		}
401b7cde470SVladimir Kondratiev 		if (IS_ERR_OR_NULL(f))
402b7cde470SVladimir Kondratiev 			wil_err(wil, "Create file \"%s\": err %ld\n",
403b7cde470SVladimir Kondratiev 				tbl[i].name, PTR_ERR(f));
404b7cde470SVladimir Kondratiev 	}
405b7cde470SVladimir Kondratiev }
406b7cde470SVladimir Kondratiev 
407b7cde470SVladimir Kondratiev static const struct dbg_off isr_off[] = {
40878484c44SMaya Erez 	{"ICC", 0644, offsetof(struct RGF_ICR, ICC), doff_io32},
40978484c44SMaya Erez 	{"ICR", 0644, offsetof(struct RGF_ICR, ICR), doff_io32},
41078484c44SMaya Erez 	{"ICM", 0644, offsetof(struct RGF_ICR, ICM), doff_io32},
41178484c44SMaya Erez 	{"ICS",	0244, offsetof(struct RGF_ICR, ICS), doff_io32},
41278484c44SMaya Erez 	{"IMV", 0644, offsetof(struct RGF_ICR, IMV), doff_io32},
41378484c44SMaya Erez 	{"IMS",	0244, offsetof(struct RGF_ICR, IMS), doff_io32},
41478484c44SMaya Erez 	{"IMC",	0244, offsetof(struct RGF_ICR, IMC), doff_io32},
415b7cde470SVladimir Kondratiev 	{},
416b7cde470SVladimir Kondratiev };
4178fe59627SVladimir Kondratiev 
4182be7d22fSVladimir Kondratiev static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
4192be7d22fSVladimir Kondratiev 				      const char *name,
4202be7d22fSVladimir Kondratiev 				      struct dentry *parent, u32 off)
4212be7d22fSVladimir Kondratiev {
4222be7d22fSVladimir Kondratiev 	struct dentry *d = debugfs_create_dir(name, parent);
4232be7d22fSVladimir Kondratiev 
4242be7d22fSVladimir Kondratiev 	if (IS_ERR_OR_NULL(d))
4252be7d22fSVladimir Kondratiev 		return -ENODEV;
4262be7d22fSVladimir Kondratiev 
427b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off,
428b7cde470SVladimir Kondratiev 				    isr_off);
4292be7d22fSVladimir Kondratiev 
4302be7d22fSVladimir Kondratiev 	return 0;
4312be7d22fSVladimir Kondratiev }
4322be7d22fSVladimir Kondratiev 
433b7cde470SVladimir Kondratiev static const struct dbg_off pseudo_isr_off[] = {
43478484c44SMaya Erez 	{"CAUSE",   0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32},
43578484c44SMaya Erez 	{"MASK_SW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32},
43678484c44SMaya Erez 	{"MASK_FW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32},
437b7cde470SVladimir Kondratiev 	{},
438b7cde470SVladimir Kondratiev };
439b7cde470SVladimir Kondratiev 
4402be7d22fSVladimir Kondratiev static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
4412be7d22fSVladimir Kondratiev 					     struct dentry *parent)
4422be7d22fSVladimir Kondratiev {
4432be7d22fSVladimir Kondratiev 	struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
4442be7d22fSVladimir Kondratiev 
4452be7d22fSVladimir Kondratiev 	if (IS_ERR_OR_NULL(d))
4462be7d22fSVladimir Kondratiev 		return -ENODEV;
4472be7d22fSVladimir Kondratiev 
448b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
449b7cde470SVladimir Kondratiev 				    pseudo_isr_off);
4502be7d22fSVladimir Kondratiev 
4512be7d22fSVladimir Kondratiev 	return 0;
4522be7d22fSVladimir Kondratiev }
4532be7d22fSVladimir Kondratiev 
45478366f69SVladimir Kondratiev static const struct dbg_off lgc_itr_cnt_off[] = {
45578484c44SMaya Erez 	{"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32},
45678484c44SMaya Erez 	{"DATA", 0644, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32},
45778484c44SMaya Erez 	{"CTL",  0644, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32},
458b7cde470SVladimir Kondratiev 	{},
459b7cde470SVladimir Kondratiev };
460b7cde470SVladimir Kondratiev 
46178366f69SVladimir Kondratiev static const struct dbg_off tx_itr_cnt_off[] = {
46278484c44SMaya Erez 	{"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_TRSH),
46378366f69SVladimir Kondratiev 	 doff_io32},
46478484c44SMaya Erez 	{"DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_DATA),
46578366f69SVladimir Kondratiev 	 doff_io32},
46678484c44SMaya Erez 	{"CTL",  0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_CTL),
46778366f69SVladimir Kondratiev 	 doff_io32},
46878484c44SMaya Erez 	{"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_TRSH),
46978366f69SVladimir Kondratiev 	 doff_io32},
47078484c44SMaya Erez 	{"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_DATA),
47178366f69SVladimir Kondratiev 	 doff_io32},
47278484c44SMaya Erez 	{"IDL_CTL",  0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_CTL),
47378366f69SVladimir Kondratiev 	 doff_io32},
47478366f69SVladimir Kondratiev 	{},
47578366f69SVladimir Kondratiev };
47678366f69SVladimir Kondratiev 
47778366f69SVladimir Kondratiev static const struct dbg_off rx_itr_cnt_off[] = {
47878484c44SMaya Erez 	{"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_TRSH),
47978366f69SVladimir Kondratiev 	 doff_io32},
48078484c44SMaya Erez 	{"DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_DATA),
48178366f69SVladimir Kondratiev 	 doff_io32},
48278484c44SMaya Erez 	{"CTL",  0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_CTL),
48378366f69SVladimir Kondratiev 	 doff_io32},
48478484c44SMaya Erez 	{"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_TRSH),
48578366f69SVladimir Kondratiev 	 doff_io32},
48678484c44SMaya Erez 	{"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_DATA),
48778366f69SVladimir Kondratiev 	 doff_io32},
48878484c44SMaya Erez 	{"IDL_CTL",  0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_CTL),
48978366f69SVladimir Kondratiev 	 doff_io32},
49078366f69SVladimir Kondratiev 	{},
49178366f69SVladimir Kondratiev };
49278366f69SVladimir Kondratiev 
4932be7d22fSVladimir Kondratiev static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
4942be7d22fSVladimir Kondratiev 					  struct dentry *parent)
4952be7d22fSVladimir Kondratiev {
49678366f69SVladimir Kondratiev 	struct dentry *d, *dtx, *drx;
4972be7d22fSVladimir Kondratiev 
49878366f69SVladimir Kondratiev 	d = debugfs_create_dir("ITR_CNT", parent);
4992be7d22fSVladimir Kondratiev 	if (IS_ERR_OR_NULL(d))
5002be7d22fSVladimir Kondratiev 		return -ENODEV;
5012be7d22fSVladimir Kondratiev 
50278366f69SVladimir Kondratiev 	dtx = debugfs_create_dir("TX", d);
50378366f69SVladimir Kondratiev 	drx = debugfs_create_dir("RX", d);
50478366f69SVladimir Kondratiev 	if (IS_ERR_OR_NULL(dtx) || IS_ERR_OR_NULL(drx))
50578366f69SVladimir Kondratiev 		return -ENODEV;
5062be7d22fSVladimir Kondratiev 
50778366f69SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
50878366f69SVladimir Kondratiev 				    lgc_itr_cnt_off);
50978366f69SVladimir Kondratiev 
51078366f69SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, dtx, (void * __force)wil->csr,
51178366f69SVladimir Kondratiev 				    tx_itr_cnt_off);
51278366f69SVladimir Kondratiev 
51378366f69SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, drx, (void * __force)wil->csr,
51478366f69SVladimir Kondratiev 				    rx_itr_cnt_off);
5152be7d22fSVladimir Kondratiev 	return 0;
5162be7d22fSVladimir Kondratiev }
5172be7d22fSVladimir Kondratiev 
5182be7d22fSVladimir Kondratiev static int wil_memread_debugfs_show(struct seq_file *s, void *data)
5192be7d22fSVladimir Kondratiev {
5202be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
52194162666SLazar Alexei 	void __iomem *a;
52294162666SLazar Alexei 	int ret;
52394162666SLazar Alexei 
52494162666SLazar Alexei 	ret = wil_pm_runtime_get(wil);
52594162666SLazar Alexei 	if (ret < 0)
52694162666SLazar Alexei 		return ret;
52794162666SLazar Alexei 
52894162666SLazar Alexei 	a = wmi_buffer(wil, cpu_to_le32(mem_addr));
5292be7d22fSVladimir Kondratiev 
5302be7d22fSVladimir Kondratiev 	if (a)
531b9eeb512SVladimir Kondratiev 		seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, readl(a));
5322be7d22fSVladimir Kondratiev 	else
5332be7d22fSVladimir Kondratiev 		seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
5342be7d22fSVladimir Kondratiev 
53594162666SLazar Alexei 	wil_pm_runtime_put(wil);
53694162666SLazar Alexei 
5372be7d22fSVladimir Kondratiev 	return 0;
5382be7d22fSVladimir Kondratiev }
5392be7d22fSVladimir Kondratiev 
5402be7d22fSVladimir Kondratiev static int wil_memread_seq_open(struct inode *inode, struct file *file)
5412be7d22fSVladimir Kondratiev {
5422be7d22fSVladimir Kondratiev 	return single_open(file, wil_memread_debugfs_show, inode->i_private);
5432be7d22fSVladimir Kondratiev }
5442be7d22fSVladimir Kondratiev 
5452be7d22fSVladimir Kondratiev static const struct file_operations fops_memread = {
5462be7d22fSVladimir Kondratiev 	.open		= wil_memread_seq_open,
5472be7d22fSVladimir Kondratiev 	.release	= single_release,
5482be7d22fSVladimir Kondratiev 	.read		= seq_read,
5492be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
5502be7d22fSVladimir Kondratiev };
5512be7d22fSVladimir Kondratiev 
5522be7d22fSVladimir Kondratiev static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
5532be7d22fSVladimir Kondratiev 				    size_t count, loff_t *ppos)
5542be7d22fSVladimir Kondratiev {
5552be7d22fSVladimir Kondratiev 	enum { max_count = 4096 };
556349214c1SMaya Erez 	struct wil_blob_wrapper *wil_blob = file->private_data;
55794162666SLazar Alexei 	struct wil6210_priv *wil = wil_blob->wil;
5582be7d22fSVladimir Kondratiev 	loff_t pos = *ppos;
559349214c1SMaya Erez 	size_t available = wil_blob->blob.size;
5602be7d22fSVladimir Kondratiev 	void *buf;
5612be7d22fSVladimir Kondratiev 	size_t ret;
56294162666SLazar Alexei 	int rc;
5632be7d22fSVladimir Kondratiev 
564fe9ee51eSMaya Erez 	if (test_bit(wil_status_suspending, wil_blob->wil->status) ||
565fe9ee51eSMaya Erez 	    test_bit(wil_status_suspended, wil_blob->wil->status))
566fe9ee51eSMaya Erez 		return 0;
567fe9ee51eSMaya Erez 
5682be7d22fSVladimir Kondratiev 	if (pos < 0)
5692be7d22fSVladimir Kondratiev 		return -EINVAL;
5702be7d22fSVladimir Kondratiev 
5712be7d22fSVladimir Kondratiev 	if (pos >= available || !count)
5722be7d22fSVladimir Kondratiev 		return 0;
5732be7d22fSVladimir Kondratiev 
5742be7d22fSVladimir Kondratiev 	if (count > available - pos)
5752be7d22fSVladimir Kondratiev 		count = available - pos;
5762be7d22fSVladimir Kondratiev 	if (count > max_count)
5772be7d22fSVladimir Kondratiev 		count = max_count;
5782be7d22fSVladimir Kondratiev 
5792be7d22fSVladimir Kondratiev 	buf = kmalloc(count, GFP_KERNEL);
5802be7d22fSVladimir Kondratiev 	if (!buf)
5812be7d22fSVladimir Kondratiev 		return -ENOMEM;
5822be7d22fSVladimir Kondratiev 
58394162666SLazar Alexei 	rc = wil_pm_runtime_get(wil);
58494162666SLazar Alexei 	if (rc < 0) {
58594162666SLazar Alexei 		kfree(buf);
58694162666SLazar Alexei 		return rc;
58794162666SLazar Alexei 	}
58894162666SLazar Alexei 
589bd50e268SMaya Erez 	wil_memcpy_fromio_32(buf, (const void __iomem *)
590349214c1SMaya Erez 			     wil_blob->blob.data + pos, count);
5912be7d22fSVladimir Kondratiev 
5922be7d22fSVladimir Kondratiev 	ret = copy_to_user(user_buf, buf, count);
59394162666SLazar Alexei 
59494162666SLazar Alexei 	wil_pm_runtime_put(wil);
59594162666SLazar Alexei 
5962be7d22fSVladimir Kondratiev 	kfree(buf);
5972be7d22fSVladimir Kondratiev 	if (ret == count)
5982be7d22fSVladimir Kondratiev 		return -EFAULT;
5992be7d22fSVladimir Kondratiev 
6002be7d22fSVladimir Kondratiev 	count -= ret;
6012be7d22fSVladimir Kondratiev 	*ppos = pos + count;
6022be7d22fSVladimir Kondratiev 
6032be7d22fSVladimir Kondratiev 	return count;
6042be7d22fSVladimir Kondratiev }
6052be7d22fSVladimir Kondratiev 
6062be7d22fSVladimir Kondratiev static const struct file_operations fops_ioblob = {
6072be7d22fSVladimir Kondratiev 	.read =		wil_read_file_ioblob,
60893ecbd64SWei Yongjun 	.open =		simple_open,
6092be7d22fSVladimir Kondratiev 	.llseek =	default_llseek,
6102be7d22fSVladimir Kondratiev };
6112be7d22fSVladimir Kondratiev 
6122be7d22fSVladimir Kondratiev static
6132be7d22fSVladimir Kondratiev struct dentry *wil_debugfs_create_ioblob(const char *name,
6140ecc833bSAl Viro 					 umode_t mode,
6152be7d22fSVladimir Kondratiev 					 struct dentry *parent,
616349214c1SMaya Erez 					 struct wil_blob_wrapper *wil_blob)
6172be7d22fSVladimir Kondratiev {
618349214c1SMaya Erez 	return debugfs_create_file(name, mode, parent, wil_blob, &fops_ioblob);
6192be7d22fSVladimir Kondratiev }
6208fe59627SVladimir Kondratiev 
6212be7d22fSVladimir Kondratiev /*---reset---*/
6222be7d22fSVladimir Kondratiev static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
6232be7d22fSVladimir Kondratiev 				    size_t len, loff_t *ppos)
6242be7d22fSVladimir Kondratiev {
6252be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
626e00243faSLior David 	struct net_device *ndev = wil->main_ndev;
6272be7d22fSVladimir Kondratiev 
6282be7d22fSVladimir Kondratiev 	/**
6292be7d22fSVladimir Kondratiev 	 * BUG:
6302be7d22fSVladimir Kondratiev 	 * this code does NOT sync device state with the rest of system
6312be7d22fSVladimir Kondratiev 	 * use with care, debug only!!!
6322be7d22fSVladimir Kondratiev 	 */
6332be7d22fSVladimir Kondratiev 	rtnl_lock();
6342be7d22fSVladimir Kondratiev 	dev_close(ndev);
6352be7d22fSVladimir Kondratiev 	ndev->flags &= ~IFF_UP;
6362be7d22fSVladimir Kondratiev 	rtnl_unlock();
6372cd0f021SVladimir Kondratiev 	wil_reset(wil, true);
6382be7d22fSVladimir Kondratiev 
6392be7d22fSVladimir Kondratiev 	return len;
6402be7d22fSVladimir Kondratiev }
6412be7d22fSVladimir Kondratiev 
6422be7d22fSVladimir Kondratiev static const struct file_operations fops_reset = {
6432be7d22fSVladimir Kondratiev 	.write = wil_write_file_reset,
64493ecbd64SWei Yongjun 	.open  = simple_open,
6452be7d22fSVladimir Kondratiev };
6468fe59627SVladimir Kondratiev 
6470b39aaf2SVladimir Kondratiev /*---write channel 1..4 to rxon for it, 0 to rxoff---*/
6480b39aaf2SVladimir Kondratiev static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
6490b39aaf2SVladimir Kondratiev 				   size_t len, loff_t *ppos)
6500b39aaf2SVladimir Kondratiev {
6510b39aaf2SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
6520b39aaf2SVladimir Kondratiev 	int rc;
6530b39aaf2SVladimir Kondratiev 	long channel;
6540b39aaf2SVladimir Kondratiev 	bool on;
6550b39aaf2SVladimir Kondratiev 
65616e5c1fcSAl Viro 	char *kbuf = memdup_user_nul(buf, len);
6578fe59627SVladimir Kondratiev 
65816e5c1fcSAl Viro 	if (IS_ERR(kbuf))
65916e5c1fcSAl Viro 		return PTR_ERR(kbuf);
6600b39aaf2SVladimir Kondratiev 	rc = kstrtol(kbuf, 0, &channel);
6610b39aaf2SVladimir Kondratiev 	kfree(kbuf);
6620b39aaf2SVladimir Kondratiev 	if (rc)
6630b39aaf2SVladimir Kondratiev 		return rc;
6640b39aaf2SVladimir Kondratiev 
6650b39aaf2SVladimir Kondratiev 	if ((channel < 0) || (channel > 4)) {
6660b39aaf2SVladimir Kondratiev 		wil_err(wil, "Invalid channel %ld\n", channel);
6670b39aaf2SVladimir Kondratiev 		return -EINVAL;
6680b39aaf2SVladimir Kondratiev 	}
6690b39aaf2SVladimir Kondratiev 	on = !!channel;
6700b39aaf2SVladimir Kondratiev 
6710b39aaf2SVladimir Kondratiev 	if (on) {
6720b39aaf2SVladimir Kondratiev 		rc = wmi_set_channel(wil, (int)channel);
6730b39aaf2SVladimir Kondratiev 		if (rc)
6740b39aaf2SVladimir Kondratiev 			return rc;
6750b39aaf2SVladimir Kondratiev 	}
6760b39aaf2SVladimir Kondratiev 
6770b39aaf2SVladimir Kondratiev 	rc = wmi_rxon(wil, on);
6780b39aaf2SVladimir Kondratiev 	if (rc)
6790b39aaf2SVladimir Kondratiev 		return rc;
6800b39aaf2SVladimir Kondratiev 
6810b39aaf2SVladimir Kondratiev 	return len;
6820b39aaf2SVladimir Kondratiev }
6830b39aaf2SVladimir Kondratiev 
6840b39aaf2SVladimir Kondratiev static const struct file_operations fops_rxon = {
6850b39aaf2SVladimir Kondratiev 	.write = wil_write_file_rxon,
6860b39aaf2SVladimir Kondratiev 	.open  = simple_open,
6870b39aaf2SVladimir Kondratiev };
6888fe59627SVladimir Kondratiev 
68949cb5dfbSVladimir Kondratiev /* block ack control, write:
69049cb5dfbSVladimir Kondratiev  * - "add <ringid> <agg_size> <timeout>" to trigger ADDBA
69149cb5dfbSVladimir Kondratiev  * - "del_tx <ringid> <reason>" to trigger DELBA for Tx side
69249cb5dfbSVladimir Kondratiev  * - "del_rx <CID> <TID> <reason>" to trigger DELBA for Rx side
6933277213fSVladimir Kondratiev  */
69449cb5dfbSVladimir Kondratiev static ssize_t wil_write_back(struct file *file, const char __user *buf,
6953277213fSVladimir Kondratiev 			      size_t len, loff_t *ppos)
6963277213fSVladimir Kondratiev {
6973277213fSVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
6983277213fSVladimir Kondratiev 	int rc;
6993277213fSVladimir Kondratiev 	char *kbuf = kmalloc(len + 1, GFP_KERNEL);
7002a19f776SColin Ian King 	char cmd[9];
70149cb5dfbSVladimir Kondratiev 	int p1, p2, p3;
7023277213fSVladimir Kondratiev 
7033277213fSVladimir Kondratiev 	if (!kbuf)
7043277213fSVladimir Kondratiev 		return -ENOMEM;
7053277213fSVladimir Kondratiev 
7063277213fSVladimir Kondratiev 	rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
7073277213fSVladimir Kondratiev 	if (rc != len) {
7083277213fSVladimir Kondratiev 		kfree(kbuf);
7093277213fSVladimir Kondratiev 		return rc >= 0 ? -EIO : rc;
7103277213fSVladimir Kondratiev 	}
7113277213fSVladimir Kondratiev 
7123277213fSVladimir Kondratiev 	kbuf[len] = '\0';
71349cb5dfbSVladimir Kondratiev 	rc = sscanf(kbuf, "%8s %d %d %d", cmd, &p1, &p2, &p3);
7143277213fSVladimir Kondratiev 	kfree(kbuf);
7153277213fSVladimir Kondratiev 
71649cb5dfbSVladimir Kondratiev 	if (rc < 0)
7173277213fSVladimir Kondratiev 		return rc;
71849cb5dfbSVladimir Kondratiev 	if (rc < 2)
7193277213fSVladimir Kondratiev 		return -EINVAL;
7203277213fSVladimir Kondratiev 
721e00243faSLior David 	if ((strcmp(cmd, "add") == 0) ||
722e00243faSLior David 	    (strcmp(cmd, "del_tx") == 0)) {
72310590c6aSGidon Studinski 		struct wil_ring_tx_data *txdata;
724e00243faSLior David 
725e00243faSLior David 		if (p1 < 0 || p1 >= WIL6210_MAX_TX_RINGS) {
726e00243faSLior David 			wil_err(wil, "BACK: invalid ring id %d\n", p1);
727e00243faSLior David 			return -EINVAL;
728e00243faSLior David 		}
72910590c6aSGidon Studinski 		txdata = &wil->ring_tx_data[p1];
730e00243faSLior David 		if (strcmp(cmd, "add") == 0) {
73149cb5dfbSVladimir Kondratiev 			if (rc < 3) {
73249cb5dfbSVladimir Kondratiev 				wil_err(wil, "BACK: add require at least 2 params\n");
73349cb5dfbSVladimir Kondratiev 				return -EINVAL;
73449cb5dfbSVladimir Kondratiev 			}
73549cb5dfbSVladimir Kondratiev 			if (rc < 4)
73649cb5dfbSVladimir Kondratiev 				p3 = 0;
737e00243faSLior David 			wmi_addba(wil, txdata->mid, p1, p2, p3);
738e00243faSLior David 		} else {
73949cb5dfbSVladimir Kondratiev 			if (rc < 3)
74049cb5dfbSVladimir Kondratiev 				p2 = WLAN_REASON_QSTA_LEAVE_QBSS;
741e00243faSLior David 			wmi_delba_tx(wil, txdata->mid, p1, p2);
742e00243faSLior David 		}
743e00243faSLior David 	} else if (strcmp(cmd, "del_rx") == 0) {
744e00243faSLior David 		struct wil_sta_info *sta;
745e00243faSLior David 
74649cb5dfbSVladimir Kondratiev 		if (rc < 3) {
74749cb5dfbSVladimir Kondratiev 			wil_err(wil,
74849cb5dfbSVladimir Kondratiev 				"BACK: del_rx require at least 2 params\n");
74949cb5dfbSVladimir Kondratiev 			return -EINVAL;
75049cb5dfbSVladimir Kondratiev 		}
751e00243faSLior David 		if (p1 < 0 || p1 >= WIL6210_MAX_CID) {
752e00243faSLior David 			wil_err(wil, "BACK: invalid CID %d\n", p1);
753e00243faSLior David 			return -EINVAL;
754e00243faSLior David 		}
75549cb5dfbSVladimir Kondratiev 		if (rc < 4)
75649cb5dfbSVladimir Kondratiev 			p3 = WLAN_REASON_QSTA_LEAVE_QBSS;
757e00243faSLior David 		sta = &wil->sta[p1];
758e00243faSLior David 		wmi_delba_rx(wil, sta->mid, mk_cidxtid(p1, p2), p3);
75949cb5dfbSVladimir Kondratiev 	} else {
76049cb5dfbSVladimir Kondratiev 		wil_err(wil, "BACK: Unrecognized command \"%s\"\n", cmd);
76149cb5dfbSVladimir Kondratiev 		return -EINVAL;
76249cb5dfbSVladimir Kondratiev 	}
7633277213fSVladimir Kondratiev 
7643277213fSVladimir Kondratiev 	return len;
7653277213fSVladimir Kondratiev }
7663277213fSVladimir Kondratiev 
76749cb5dfbSVladimir Kondratiev static ssize_t wil_read_back(struct file *file, char __user *user_buf,
76849cb5dfbSVladimir Kondratiev 			     size_t count, loff_t *ppos)
76949cb5dfbSVladimir Kondratiev {
77049cb5dfbSVladimir Kondratiev 	static const char text[] = "block ack control, write:\n"
77149cb5dfbSVladimir Kondratiev 	" - \"add <ringid> <agg_size> <timeout>\" to trigger ADDBA\n"
77249cb5dfbSVladimir Kondratiev 	"If missing, <timeout> defaults to 0\n"
77349cb5dfbSVladimir Kondratiev 	" - \"del_tx <ringid> <reason>\" to trigger DELBA for Tx side\n"
77449cb5dfbSVladimir Kondratiev 	" - \"del_rx <CID> <TID> <reason>\" to trigger DELBA for Rx side\n"
77549cb5dfbSVladimir Kondratiev 	"If missing, <reason> set to \"STA_LEAVING\" (36)\n";
77649cb5dfbSVladimir Kondratiev 
77749cb5dfbSVladimir Kondratiev 	return simple_read_from_buffer(user_buf, count, ppos, text,
77849cb5dfbSVladimir Kondratiev 				       sizeof(text));
77949cb5dfbSVladimir Kondratiev }
78049cb5dfbSVladimir Kondratiev 
78149cb5dfbSVladimir Kondratiev static const struct file_operations fops_back = {
78249cb5dfbSVladimir Kondratiev 	.read = wil_read_back,
78349cb5dfbSVladimir Kondratiev 	.write = wil_write_back,
7843277213fSVladimir Kondratiev 	.open  = simple_open,
7853277213fSVladimir Kondratiev };
7863277213fSVladimir Kondratiev 
787dc16427bSVladimir Kondratiev /* pmc control, write:
788dc16427bSVladimir Kondratiev  * - "alloc <num descriptors> <descriptor_size>" to allocate PMC
789dc16427bSVladimir Kondratiev  * - "free" to release memory allocated for PMC
790dc16427bSVladimir Kondratiev  */
791dc16427bSVladimir Kondratiev static ssize_t wil_write_pmccfg(struct file *file, const char __user *buf,
792dc16427bSVladimir Kondratiev 				size_t len, loff_t *ppos)
793dc16427bSVladimir Kondratiev {
794dc16427bSVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
795dc16427bSVladimir Kondratiev 	int rc;
796dc16427bSVladimir Kondratiev 	char *kbuf = kmalloc(len + 1, GFP_KERNEL);
797dc16427bSVladimir Kondratiev 	char cmd[9];
798dc16427bSVladimir Kondratiev 	int num_descs, desc_size;
799dc16427bSVladimir Kondratiev 
800dc16427bSVladimir Kondratiev 	if (!kbuf)
801dc16427bSVladimir Kondratiev 		return -ENOMEM;
802dc16427bSVladimir Kondratiev 
803dc16427bSVladimir Kondratiev 	rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
804dc16427bSVladimir Kondratiev 	if (rc != len) {
805dc16427bSVladimir Kondratiev 		kfree(kbuf);
806dc16427bSVladimir Kondratiev 		return rc >= 0 ? -EIO : rc;
807dc16427bSVladimir Kondratiev 	}
808dc16427bSVladimir Kondratiev 
809dc16427bSVladimir Kondratiev 	kbuf[len] = '\0';
810dc16427bSVladimir Kondratiev 	rc = sscanf(kbuf, "%8s %d %d", cmd, &num_descs, &desc_size);
811dc16427bSVladimir Kondratiev 	kfree(kbuf);
812dc16427bSVladimir Kondratiev 
813dc16427bSVladimir Kondratiev 	if (rc < 0)
814dc16427bSVladimir Kondratiev 		return rc;
815dc16427bSVladimir Kondratiev 
816dc16427bSVladimir Kondratiev 	if (rc < 1) {
817dc16427bSVladimir Kondratiev 		wil_err(wil, "pmccfg: no params given\n");
818dc16427bSVladimir Kondratiev 		return -EINVAL;
819dc16427bSVladimir Kondratiev 	}
820dc16427bSVladimir Kondratiev 
821dc16427bSVladimir Kondratiev 	if (0 == strcmp(cmd, "alloc")) {
822dc16427bSVladimir Kondratiev 		if (rc != 3) {
823dc16427bSVladimir Kondratiev 			wil_err(wil, "pmccfg: alloc requires 2 params\n");
824dc16427bSVladimir Kondratiev 			return -EINVAL;
825dc16427bSVladimir Kondratiev 		}
826dc16427bSVladimir Kondratiev 		wil_pmc_alloc(wil, num_descs, desc_size);
827dc16427bSVladimir Kondratiev 	} else if (0 == strcmp(cmd, "free")) {
828dc16427bSVladimir Kondratiev 		if (rc != 1) {
829dc16427bSVladimir Kondratiev 			wil_err(wil, "pmccfg: free does not have any params\n");
830dc16427bSVladimir Kondratiev 			return -EINVAL;
831dc16427bSVladimir Kondratiev 		}
832dc16427bSVladimir Kondratiev 		wil_pmc_free(wil, true);
833dc16427bSVladimir Kondratiev 	} else {
834dc16427bSVladimir Kondratiev 		wil_err(wil, "pmccfg: Unrecognized command \"%s\"\n", cmd);
835dc16427bSVladimir Kondratiev 		return -EINVAL;
836dc16427bSVladimir Kondratiev 	}
837dc16427bSVladimir Kondratiev 
838dc16427bSVladimir Kondratiev 	return len;
839dc16427bSVladimir Kondratiev }
840dc16427bSVladimir Kondratiev 
841dc16427bSVladimir Kondratiev static ssize_t wil_read_pmccfg(struct file *file, char __user *user_buf,
842dc16427bSVladimir Kondratiev 			       size_t count, loff_t *ppos)
843dc16427bSVladimir Kondratiev {
844dc16427bSVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
845dc16427bSVladimir Kondratiev 	char text[256];
846dc16427bSVladimir Kondratiev 	char help[] = "pmc control, write:\n"
847dc16427bSVladimir Kondratiev 	" - \"alloc <num descriptors> <descriptor_size>\" to allocate pmc\n"
848dc16427bSVladimir Kondratiev 	" - \"free\" to free memory allocated for pmc\n";
849dc16427bSVladimir Kondratiev 
850dc16427bSVladimir Kondratiev 	sprintf(text, "Last command status: %d\n\n%s",
851dc16427bSVladimir Kondratiev 		wil_pmc_last_cmd_status(wil),
852dc16427bSVladimir Kondratiev 		help);
853dc16427bSVladimir Kondratiev 
854dc16427bSVladimir Kondratiev 	return simple_read_from_buffer(user_buf, count, ppos, text,
855dc16427bSVladimir Kondratiev 				       strlen(text) + 1);
856dc16427bSVladimir Kondratiev }
857dc16427bSVladimir Kondratiev 
858dc16427bSVladimir Kondratiev static const struct file_operations fops_pmccfg = {
859dc16427bSVladimir Kondratiev 	.read = wil_read_pmccfg,
860dc16427bSVladimir Kondratiev 	.write = wil_write_pmccfg,
861dc16427bSVladimir Kondratiev 	.open  = simple_open,
862dc16427bSVladimir Kondratiev };
863dc16427bSVladimir Kondratiev 
864dc16427bSVladimir Kondratiev static const struct file_operations fops_pmcdata = {
865dc16427bSVladimir Kondratiev 	.open		= simple_open,
866dc16427bSVladimir Kondratiev 	.read		= wil_pmc_read,
867dc16427bSVladimir Kondratiev 	.llseek		= wil_pmc_llseek,
868dc16427bSVladimir Kondratiev };
869dc16427bSVladimir Kondratiev 
8700b39aaf2SVladimir Kondratiev /*---tx_mgmt---*/
8710b39aaf2SVladimir Kondratiev /* Write mgmt frame to this file to send it */
8720b39aaf2SVladimir Kondratiev static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
8730b39aaf2SVladimir Kondratiev 				     size_t len, loff_t *ppos)
8740b39aaf2SVladimir Kondratiev {
8750b39aaf2SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
8760b39aaf2SVladimir Kondratiev 	struct wiphy *wiphy = wil_to_wiphy(wil);
877e00243faSLior David 	struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr;
8780b39aaf2SVladimir Kondratiev 	struct cfg80211_mgmt_tx_params params;
8790b39aaf2SVladimir Kondratiev 	int rc;
8809a492909SGeliang Tang 	void *frame;
8818fe59627SVladimir Kondratiev 
8826641525cSHamad Kadmany 	if (!len)
8836641525cSHamad Kadmany 		return -EINVAL;
8846641525cSHamad Kadmany 
8859a492909SGeliang Tang 	frame = memdup_user(buf, len);
8869a492909SGeliang Tang 	if (IS_ERR(frame))
8879a492909SGeliang Tang 		return PTR_ERR(frame);
8880b39aaf2SVladimir Kondratiev 
8890b39aaf2SVladimir Kondratiev 	params.buf = frame;
8900b39aaf2SVladimir Kondratiev 	params.len = len;
8910b39aaf2SVladimir Kondratiev 
8920b39aaf2SVladimir Kondratiev 	rc = wil_cfg80211_mgmt_tx(wiphy, wdev, &params, NULL);
8930b39aaf2SVladimir Kondratiev 
8940b39aaf2SVladimir Kondratiev 	kfree(frame);
895af3db60aSLazar Alexei 	wil_info(wil, "-> %d\n", rc);
8960b39aaf2SVladimir Kondratiev 
8970b39aaf2SVladimir Kondratiev 	return len;
8980b39aaf2SVladimir Kondratiev }
8990b39aaf2SVladimir Kondratiev 
9000b39aaf2SVladimir Kondratiev static const struct file_operations fops_txmgmt = {
9010b39aaf2SVladimir Kondratiev 	.write = wil_write_file_txmgmt,
9020b39aaf2SVladimir Kondratiev 	.open  = simple_open,
9030b39aaf2SVladimir Kondratiev };
9042be7d22fSVladimir Kondratiev 
905ff974e40SVladimir Kondratiev /* Write WMI command (w/o mbox header) to this file to send it
906ff974e40SVladimir Kondratiev  * WMI starts from wil6210_mbox_hdr_wmi header
907ff974e40SVladimir Kondratiev  */
908ff974e40SVladimir Kondratiev static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
909ff974e40SVladimir Kondratiev 				  size_t len, loff_t *ppos)
910ff974e40SVladimir Kondratiev {
911ff974e40SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
912e00243faSLior David 	struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
913b874ddecSLior David 	struct wmi_cmd_hdr *wmi;
914ff974e40SVladimir Kondratiev 	void *cmd;
915b874ddecSLior David 	int cmdlen = len - sizeof(struct wmi_cmd_hdr);
916ff974e40SVladimir Kondratiev 	u16 cmdid;
917ff974e40SVladimir Kondratiev 	int rc, rc1;
918ff974e40SVladimir Kondratiev 
91969218a48SLior David 	if (cmdlen < 0)
920ff974e40SVladimir Kondratiev 		return -EINVAL;
921ff974e40SVladimir Kondratiev 
922ff974e40SVladimir Kondratiev 	wmi = kmalloc(len, GFP_KERNEL);
923ff974e40SVladimir Kondratiev 	if (!wmi)
924ff974e40SVladimir Kondratiev 		return -ENOMEM;
925ff974e40SVladimir Kondratiev 
926ff974e40SVladimir Kondratiev 	rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
9278e09b7d2SLino Sanfilippo 	if (rc < 0) {
9288e09b7d2SLino Sanfilippo 		kfree(wmi);
929ff974e40SVladimir Kondratiev 		return rc;
9308e09b7d2SLino Sanfilippo 	}
931ff974e40SVladimir Kondratiev 
93269218a48SLior David 	cmd = (cmdlen > 0) ? &wmi[1] : NULL;
933b874ddecSLior David 	cmdid = le16_to_cpu(wmi->command_id);
934ff974e40SVladimir Kondratiev 
935e00243faSLior David 	rc1 = wmi_send(wil, cmdid, vif->mid, cmd, cmdlen);
936ff974e40SVladimir Kondratiev 	kfree(wmi);
937ff974e40SVladimir Kondratiev 
938af3db60aSLazar Alexei 	wil_info(wil, "0x%04x[%d] -> %d\n", cmdid, cmdlen, rc1);
939ff974e40SVladimir Kondratiev 
940ff974e40SVladimir Kondratiev 	return rc;
941ff974e40SVladimir Kondratiev }
942ff974e40SVladimir Kondratiev 
943ff974e40SVladimir Kondratiev static const struct file_operations fops_wmi = {
944ff974e40SVladimir Kondratiev 	.write = wil_write_file_wmi,
945ff974e40SVladimir Kondratiev 	.open  = simple_open,
946ff974e40SVladimir Kondratiev };
947ff974e40SVladimir Kondratiev 
948c236658fSVladimir Kondratiev static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
949c236658fSVladimir Kondratiev {
950c236658fSVladimir Kondratiev 	int i = 0;
951c236658fSVladimir Kondratiev 	int len = skb_headlen(skb);
952c236658fSVladimir Kondratiev 	void *p = skb->data;
953c236658fSVladimir Kondratiev 	int nr_frags = skb_shinfo(skb)->nr_frags;
954c236658fSVladimir Kondratiev 
955c236658fSVladimir Kondratiev 	seq_printf(s, "    len = %d\n", len);
956c236658fSVladimir Kondratiev 	wil_seq_hexdump(s, p, len, "      : ");
957c236658fSVladimir Kondratiev 
958c236658fSVladimir Kondratiev 	if (nr_frags) {
959c236658fSVladimir Kondratiev 		seq_printf(s, "    nr_frags = %d\n", nr_frags);
960c236658fSVladimir Kondratiev 		for (i = 0; i < nr_frags; i++) {
961c236658fSVladimir Kondratiev 			const struct skb_frag_struct *frag =
962c236658fSVladimir Kondratiev 					&skb_shinfo(skb)->frags[i];
963c236658fSVladimir Kondratiev 
964c236658fSVladimir Kondratiev 			len = skb_frag_size(frag);
965c236658fSVladimir Kondratiev 			p = skb_frag_address_safe(frag);
966c236658fSVladimir Kondratiev 			seq_printf(s, "    [%2d] : len = %d\n", i, len);
967c236658fSVladimir Kondratiev 			wil_seq_hexdump(s, p, len, "      : ");
968c236658fSVladimir Kondratiev 		}
969c236658fSVladimir Kondratiev 	}
970c236658fSVladimir Kondratiev }
971c236658fSVladimir Kondratiev 
9723a85543eSVladimir Kondratiev /*---------Tx/Rx descriptor------------*/
9732be7d22fSVladimir Kondratiev static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
9742be7d22fSVladimir Kondratiev {
9752be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
97610590c6aSGidon Studinski 	struct wil_ring *ring;
97710590c6aSGidon Studinski 	bool tx = (dbg_ring_index < WIL6210_MAX_TX_RINGS);
9788fe59627SVladimir Kondratiev 
97910590c6aSGidon Studinski 	ring = tx ? &wil->ring_tx[dbg_ring_index] : &wil->ring_rx;
9802be7d22fSVladimir Kondratiev 
98110590c6aSGidon Studinski 	if (!ring->va) {
982af31cb5aSVladimir Kondratiev 		if (tx)
98310590c6aSGidon Studinski 			seq_printf(s, "No Tx[%2d] VRING\n", dbg_ring_index);
9843a85543eSVladimir Kondratiev 		else
9853a85543eSVladimir Kondratiev 			seq_puts(s, "No Rx VRING\n");
9862be7d22fSVladimir Kondratiev 		return 0;
9872be7d22fSVladimir Kondratiev 	}
9882be7d22fSVladimir Kondratiev 
98910590c6aSGidon Studinski 	if (dbg_txdesc_index < ring->size) {
9903a85543eSVladimir Kondratiev 		/* use struct vring_tx_desc for Rx as well,
9913a85543eSVladimir Kondratiev 		 * only field used, .dma.length, is the same
9923a85543eSVladimir Kondratiev 		 */
9932be7d22fSVladimir Kondratiev 		volatile struct vring_tx_desc *d =
99410590c6aSGidon Studinski 				&ring->va[dbg_txdesc_index].tx.legacy;
9952be7d22fSVladimir Kondratiev 		volatile u32 *u = (volatile u32 *)d;
99610590c6aSGidon Studinski 		struct sk_buff *skb = ring->ctx[dbg_txdesc_index].skb;
9972be7d22fSVladimir Kondratiev 
998af31cb5aSVladimir Kondratiev 		if (tx)
99910590c6aSGidon Studinski 			seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_ring_index,
10003a85543eSVladimir Kondratiev 				   dbg_txdesc_index);
10013a85543eSVladimir Kondratiev 		else
10023a85543eSVladimir Kondratiev 			seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
10032be7d22fSVladimir Kondratiev 		seq_printf(s, "  MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
10042be7d22fSVladimir Kondratiev 			   u[0], u[1], u[2], u[3]);
10052be7d22fSVladimir Kondratiev 		seq_printf(s, "  DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
10062be7d22fSVladimir Kondratiev 			   u[4], u[5], u[6], u[7]);
100739c52ee8SVladimir Kondratiev 		seq_printf(s, "  SKB = 0x%p\n", skb);
10082be7d22fSVladimir Kondratiev 
10092be7d22fSVladimir Kondratiev 		if (skb) {
1010c236658fSVladimir Kondratiev 			skb_get(skb);
1011c236658fSVladimir Kondratiev 			wil_seq_print_skb(s, skb);
1012c236658fSVladimir Kondratiev 			kfree_skb(skb);
10132be7d22fSVladimir Kondratiev 		}
10148fe59627SVladimir Kondratiev 		seq_puts(s, "}\n");
10152be7d22fSVladimir Kondratiev 	} else {
1016af31cb5aSVladimir Kondratiev 		if (tx)
10173a85543eSVladimir Kondratiev 			seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
101810590c6aSGidon Studinski 				   dbg_ring_index, dbg_txdesc_index,
101910590c6aSGidon Studinski 				   ring->size);
10203a85543eSVladimir Kondratiev 		else
10213a85543eSVladimir Kondratiev 			seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
102210590c6aSGidon Studinski 				   dbg_txdesc_index, ring->size);
10232be7d22fSVladimir Kondratiev 	}
10242be7d22fSVladimir Kondratiev 
10252be7d22fSVladimir Kondratiev 	return 0;
10262be7d22fSVladimir Kondratiev }
10272be7d22fSVladimir Kondratiev 
10282be7d22fSVladimir Kondratiev static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
10292be7d22fSVladimir Kondratiev {
10302be7d22fSVladimir Kondratiev 	return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
10312be7d22fSVladimir Kondratiev }
10322be7d22fSVladimir Kondratiev 
10332be7d22fSVladimir Kondratiev static const struct file_operations fops_txdesc = {
10342be7d22fSVladimir Kondratiev 	.open		= wil_txdesc_seq_open,
10352be7d22fSVladimir Kondratiev 	.release	= single_release,
10362be7d22fSVladimir Kondratiev 	.read		= seq_read,
10372be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
10382be7d22fSVladimir Kondratiev };
10392be7d22fSVladimir Kondratiev 
10402be7d22fSVladimir Kondratiev /*---------beamforming------------*/
104136345ac3SVladimir Kondratiev static char *wil_bfstatus_str(u32 status)
104236345ac3SVladimir Kondratiev {
104336345ac3SVladimir Kondratiev 	switch (status) {
104436345ac3SVladimir Kondratiev 	case 0:
104536345ac3SVladimir Kondratiev 		return "Failed";
104636345ac3SVladimir Kondratiev 	case 1:
104736345ac3SVladimir Kondratiev 		return "OK";
104836345ac3SVladimir Kondratiev 	case 2:
104936345ac3SVladimir Kondratiev 		return "Retrying";
105036345ac3SVladimir Kondratiev 	default:
105136345ac3SVladimir Kondratiev 		return "??";
105236345ac3SVladimir Kondratiev 	}
105336345ac3SVladimir Kondratiev }
105436345ac3SVladimir Kondratiev 
105536345ac3SVladimir Kondratiev static bool is_all_zeros(void * const x_, size_t sz)
105636345ac3SVladimir Kondratiev {
105736345ac3SVladimir Kondratiev 	/* if reply is all-0, ignore this CID */
105836345ac3SVladimir Kondratiev 	u32 *x = x_;
105936345ac3SVladimir Kondratiev 	int n;
106036345ac3SVladimir Kondratiev 
106136345ac3SVladimir Kondratiev 	for (n = 0; n < sz / sizeof(*x); n++)
106236345ac3SVladimir Kondratiev 		if (x[n])
106336345ac3SVladimir Kondratiev 			return false;
106436345ac3SVladimir Kondratiev 
106536345ac3SVladimir Kondratiev 	return true;
106636345ac3SVladimir Kondratiev }
106736345ac3SVladimir Kondratiev 
10682be7d22fSVladimir Kondratiev static int wil_bf_debugfs_show(struct seq_file *s, void *data)
10692be7d22fSVladimir Kondratiev {
107036345ac3SVladimir Kondratiev 	int rc;
107136345ac3SVladimir Kondratiev 	int i;
10722be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
1073e00243faSLior David 	struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
107436345ac3SVladimir Kondratiev 	struct wmi_notify_req_cmd cmd = {
107536345ac3SVladimir Kondratiev 		.interval_usec = 0,
107636345ac3SVladimir Kondratiev 	};
107736345ac3SVladimir Kondratiev 	struct {
1078b874ddecSLior David 		struct wmi_cmd_hdr wmi;
107936345ac3SVladimir Kondratiev 		struct wmi_notify_req_done_event evt;
108036345ac3SVladimir Kondratiev 	} __packed reply;
108136345ac3SVladimir Kondratiev 
1082807b0860SAlexei Avshalom Lazar 	memset(&reply, 0, sizeof(reply));
1083807b0860SAlexei Avshalom Lazar 
108436345ac3SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
108536345ac3SVladimir Kondratiev 		u32 status;
108636345ac3SVladimir Kondratiev 
108736345ac3SVladimir Kondratiev 		cmd.cid = i;
1088e00243faSLior David 		rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, vif->mid,
1089e00243faSLior David 			      &cmd, sizeof(cmd),
109036345ac3SVladimir Kondratiev 			      WMI_NOTIFY_REQ_DONE_EVENTID, &reply,
109136345ac3SVladimir Kondratiev 			      sizeof(reply), 20);
109236345ac3SVladimir Kondratiev 		/* if reply is all-0, ignore this CID */
109336345ac3SVladimir Kondratiev 		if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt)))
109436345ac3SVladimir Kondratiev 			continue;
109536345ac3SVladimir Kondratiev 
109636345ac3SVladimir Kondratiev 		status = le32_to_cpu(reply.evt.status);
109736345ac3SVladimir Kondratiev 		seq_printf(s, "CID %d {\n"
109836345ac3SVladimir Kondratiev 			   "  TSF = 0x%016llx\n"
109936345ac3SVladimir Kondratiev 			   "  TxMCS = %2d TxTpt = %4d\n"
110036345ac3SVladimir Kondratiev 			   "  SQI = %4d\n"
110130868f5dSDedy Lansky 			   "  RSSI = %4d\n"
110236345ac3SVladimir Kondratiev 			   "  Status = 0x%08x %s\n"
110336345ac3SVladimir Kondratiev 			   "  Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
110436345ac3SVladimir Kondratiev 			   "  Goodput(rx:tx) %4d:%4d\n"
110536345ac3SVladimir Kondratiev 			   "}\n",
110636345ac3SVladimir Kondratiev 			   i,
110736345ac3SVladimir Kondratiev 			   le64_to_cpu(reply.evt.tsf),
110836345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.bf_mcs),
110936345ac3SVladimir Kondratiev 			   le32_to_cpu(reply.evt.tx_tpt),
111036345ac3SVladimir Kondratiev 			   reply.evt.sqi,
111130868f5dSDedy Lansky 			   reply.evt.rssi,
111236345ac3SVladimir Kondratiev 			   status, wil_bfstatus_str(status),
111336345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.my_rx_sector),
111436345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.my_tx_sector),
111536345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.other_rx_sector),
111636345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.other_tx_sector),
111736345ac3SVladimir Kondratiev 			   le32_to_cpu(reply.evt.rx_goodput),
111836345ac3SVladimir Kondratiev 			   le32_to_cpu(reply.evt.tx_goodput));
111936345ac3SVladimir Kondratiev 	}
11202be7d22fSVladimir Kondratiev 	return 0;
11212be7d22fSVladimir Kondratiev }
11222be7d22fSVladimir Kondratiev 
11232be7d22fSVladimir Kondratiev static int wil_bf_seq_open(struct inode *inode, struct file *file)
11242be7d22fSVladimir Kondratiev {
11252be7d22fSVladimir Kondratiev 	return single_open(file, wil_bf_debugfs_show, inode->i_private);
11262be7d22fSVladimir Kondratiev }
11272be7d22fSVladimir Kondratiev 
11282be7d22fSVladimir Kondratiev static const struct file_operations fops_bf = {
11292be7d22fSVladimir Kondratiev 	.open		= wil_bf_seq_open,
11302be7d22fSVladimir Kondratiev 	.release	= single_release,
11312be7d22fSVladimir Kondratiev 	.read		= seq_read,
11322be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
11332be7d22fSVladimir Kondratiev };
11348fe59627SVladimir Kondratiev 
11351a2780e0SVladimir Kondratiev /*---------temp------------*/
11361a2780e0SVladimir Kondratiev static void print_temp(struct seq_file *s, const char *prefix, u32 t)
11371a2780e0SVladimir Kondratiev {
11381a2780e0SVladimir Kondratiev 	switch (t) {
11391a2780e0SVladimir Kondratiev 	case 0:
11401a2780e0SVladimir Kondratiev 	case ~(u32)0:
11411a2780e0SVladimir Kondratiev 		seq_printf(s, "%s N/A\n", prefix);
11421a2780e0SVladimir Kondratiev 	break;
11431a2780e0SVladimir Kondratiev 	default:
11441a2780e0SVladimir Kondratiev 		seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
11451a2780e0SVladimir Kondratiev 		break;
11461a2780e0SVladimir Kondratiev 	}
11471a2780e0SVladimir Kondratiev }
11481a2780e0SVladimir Kondratiev 
11491a2780e0SVladimir Kondratiev static int wil_temp_debugfs_show(struct seq_file *s, void *data)
11501a2780e0SVladimir Kondratiev {
11511a2780e0SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
11521a2780e0SVladimir Kondratiev 	u32 t_m, t_r;
11531a2780e0SVladimir Kondratiev 	int rc = wmi_get_temperature(wil, &t_m, &t_r);
11548fe59627SVladimir Kondratiev 
11551a2780e0SVladimir Kondratiev 	if (rc) {
11568fe59627SVladimir Kondratiev 		seq_puts(s, "Failed\n");
11571a2780e0SVladimir Kondratiev 		return 0;
11581a2780e0SVladimir Kondratiev 	}
11591a2780e0SVladimir Kondratiev 
1160d45cff9fSVladimir Kondratiev 	print_temp(s, "T_mac   =", t_m);
1161d45cff9fSVladimir Kondratiev 	print_temp(s, "T_radio =", t_r);
11621a2780e0SVladimir Kondratiev 
11631a2780e0SVladimir Kondratiev 	return 0;
11641a2780e0SVladimir Kondratiev }
11651a2780e0SVladimir Kondratiev 
11661a2780e0SVladimir Kondratiev static int wil_temp_seq_open(struct inode *inode, struct file *file)
11671a2780e0SVladimir Kondratiev {
11681a2780e0SVladimir Kondratiev 	return single_open(file, wil_temp_debugfs_show, inode->i_private);
11691a2780e0SVladimir Kondratiev }
11701a2780e0SVladimir Kondratiev 
11711a2780e0SVladimir Kondratiev static const struct file_operations fops_temp = {
11721a2780e0SVladimir Kondratiev 	.open		= wil_temp_seq_open,
11731a2780e0SVladimir Kondratiev 	.release	= single_release,
11741a2780e0SVladimir Kondratiev 	.read		= seq_read,
11751a2780e0SVladimir Kondratiev 	.llseek		= seq_lseek,
11761a2780e0SVladimir Kondratiev };
11771a2780e0SVladimir Kondratiev 
11789eb82d43SVladimir Kondratiev /*---------freq------------*/
11799eb82d43SVladimir Kondratiev static int wil_freq_debugfs_show(struct seq_file *s, void *data)
11809eb82d43SVladimir Kondratiev {
11819eb82d43SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
1182e00243faSLior David 	struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr;
11839eb82d43SVladimir Kondratiev 	u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
11849eb82d43SVladimir Kondratiev 
11859eb82d43SVladimir Kondratiev 	seq_printf(s, "Freq = %d\n", freq);
11869eb82d43SVladimir Kondratiev 
11879eb82d43SVladimir Kondratiev 	return 0;
11889eb82d43SVladimir Kondratiev }
11899eb82d43SVladimir Kondratiev 
11909eb82d43SVladimir Kondratiev static int wil_freq_seq_open(struct inode *inode, struct file *file)
11919eb82d43SVladimir Kondratiev {
11929eb82d43SVladimir Kondratiev 	return single_open(file, wil_freq_debugfs_show, inode->i_private);
11939eb82d43SVladimir Kondratiev }
11949eb82d43SVladimir Kondratiev 
11959eb82d43SVladimir Kondratiev static const struct file_operations fops_freq = {
11969eb82d43SVladimir Kondratiev 	.open		= wil_freq_seq_open,
11979eb82d43SVladimir Kondratiev 	.release	= single_release,
11989eb82d43SVladimir Kondratiev 	.read		= seq_read,
11999eb82d43SVladimir Kondratiev 	.llseek		= seq_lseek,
12009eb82d43SVladimir Kondratiev };
12019eb82d43SVladimir Kondratiev 
12029eb82d43SVladimir Kondratiev /*---------link------------*/
12039eb82d43SVladimir Kondratiev static int wil_link_debugfs_show(struct seq_file *s, void *data)
12049eb82d43SVladimir Kondratiev {
12059eb82d43SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
120641bd3d58SToke Høiland-Jørgensen 	struct station_info *sinfo;
120741bd3d58SToke Høiland-Jørgensen 	int i, rc = 0;
120841bd3d58SToke Høiland-Jørgensen 
120941bd3d58SToke Høiland-Jørgensen 	sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL);
121041bd3d58SToke Høiland-Jørgensen 	if (!sinfo)
121141bd3d58SToke Høiland-Jørgensen 		return -ENOMEM;
12129eb82d43SVladimir Kondratiev 
12139eb82d43SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
12149eb82d43SVladimir Kondratiev 		struct wil_sta_info *p = &wil->sta[i];
12159eb82d43SVladimir Kondratiev 		char *status = "unknown";
12165bd60982SLior David 		struct wil6210_vif *vif;
12175bd60982SLior David 		u8 mid;
12188fe59627SVladimir Kondratiev 
12199eb82d43SVladimir Kondratiev 		switch (p->status) {
12209eb82d43SVladimir Kondratiev 		case wil_sta_unused:
12219eb82d43SVladimir Kondratiev 			status = "unused   ";
12229eb82d43SVladimir Kondratiev 			break;
12239eb82d43SVladimir Kondratiev 		case wil_sta_conn_pending:
12249eb82d43SVladimir Kondratiev 			status = "pending  ";
12259eb82d43SVladimir Kondratiev 			break;
12269eb82d43SVladimir Kondratiev 		case wil_sta_connected:
12279eb82d43SVladimir Kondratiev 			status = "connected";
12289eb82d43SVladimir Kondratiev 			break;
12299eb82d43SVladimir Kondratiev 		}
12305bd60982SLior David 		mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
12315bd60982SLior David 		seq_printf(s, "[%d][MID %d] %pM %s\n",
12325bd60982SLior David 			   i, mid, p->addr, status);
12339eb82d43SVladimir Kondratiev 
12345bd60982SLior David 		if (p->status != wil_sta_connected)
12355bd60982SLior David 			continue;
12365bd60982SLior David 
12375bd60982SLior David 		vif = (mid < wil->max_vifs) ? wil->vifs[mid] : NULL;
12385bd60982SLior David 		if (vif) {
123941bd3d58SToke Høiland-Jørgensen 			rc = wil_cid_fill_sinfo(vif, i, sinfo);
12409eb82d43SVladimir Kondratiev 			if (rc)
124141bd3d58SToke Høiland-Jørgensen 				goto out;
12429eb82d43SVladimir Kondratiev 
124341bd3d58SToke Høiland-Jørgensen 			seq_printf(s, "  Tx_mcs = %d\n", sinfo->txrate.mcs);
124441bd3d58SToke Høiland-Jørgensen 			seq_printf(s, "  Rx_mcs = %d\n", sinfo->rxrate.mcs);
124541bd3d58SToke Høiland-Jørgensen 			seq_printf(s, "  SQ     = %d\n", sinfo->signal);
12465bd60982SLior David 		} else {
12475bd60982SLior David 			seq_puts(s, "  INVALID MID\n");
12489eb82d43SVladimir Kondratiev 		}
12499eb82d43SVladimir Kondratiev 	}
12509eb82d43SVladimir Kondratiev 
125141bd3d58SToke Høiland-Jørgensen out:
125241bd3d58SToke Høiland-Jørgensen 	kfree(sinfo);
125341bd3d58SToke Høiland-Jørgensen 	return rc;
12549eb82d43SVladimir Kondratiev }
12559eb82d43SVladimir Kondratiev 
12569eb82d43SVladimir Kondratiev static int wil_link_seq_open(struct inode *inode, struct file *file)
12579eb82d43SVladimir Kondratiev {
12589eb82d43SVladimir Kondratiev 	return single_open(file, wil_link_debugfs_show, inode->i_private);
12599eb82d43SVladimir Kondratiev }
12609eb82d43SVladimir Kondratiev 
12619eb82d43SVladimir Kondratiev static const struct file_operations fops_link = {
12629eb82d43SVladimir Kondratiev 	.open		= wil_link_seq_open,
12639eb82d43SVladimir Kondratiev 	.release	= single_release,
12649eb82d43SVladimir Kondratiev 	.read		= seq_read,
12659eb82d43SVladimir Kondratiev 	.llseek		= seq_lseek,
12669eb82d43SVladimir Kondratiev };
12679eb82d43SVladimir Kondratiev 
126884bb29b7SVladimir Kondratiev /*---------info------------*/
126984bb29b7SVladimir Kondratiev static int wil_info_debugfs_show(struct seq_file *s, void *data)
127084bb29b7SVladimir Kondratiev {
1271be299858SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
1272e00243faSLior David 	struct net_device *ndev = wil->main_ndev;
127384bb29b7SVladimir Kondratiev 	int is_ac = power_supply_is_system_supplied();
1274be299858SVladimir Kondratiev 	int rx = atomic_xchg(&wil->isr_count_rx, 0);
1275be299858SVladimir Kondratiev 	int tx = atomic_xchg(&wil->isr_count_tx, 0);
1276be299858SVladimir Kondratiev 	static ulong rxf_old, txf_old;
1277be299858SVladimir Kondratiev 	ulong rxf = ndev->stats.rx_packets;
1278be299858SVladimir Kondratiev 	ulong txf = ndev->stats.tx_packets;
127955f8f680SVladimir Kondratiev 	unsigned int i;
128084bb29b7SVladimir Kondratiev 
128184bb29b7SVladimir Kondratiev 	/* >0 : AC; 0 : battery; <0 : error */
128284bb29b7SVladimir Kondratiev 	seq_printf(s, "AC powered : %d\n", is_ac);
1283be299858SVladimir Kondratiev 	seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
1284be299858SVladimir Kondratiev 	seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
1285be299858SVladimir Kondratiev 	rxf_old = rxf;
1286be299858SVladimir Kondratiev 	txf_old = txf;
128784bb29b7SVladimir Kondratiev 
128855f8f680SVladimir Kondratiev #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
128955f8f680SVladimir Kondratiev 	" " __stringify(x) : ""
129055f8f680SVladimir Kondratiev 
129155f8f680SVladimir Kondratiev 	for (i = 0; i < ndev->num_tx_queues; i++) {
129255f8f680SVladimir Kondratiev 		struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
129355f8f680SVladimir Kondratiev 		unsigned long state = txq->state;
129455f8f680SVladimir Kondratiev 
129555f8f680SVladimir Kondratiev 		seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
129655f8f680SVladimir Kondratiev 			   CHECK_QSTATE(DRV_XOFF),
129755f8f680SVladimir Kondratiev 			   CHECK_QSTATE(STACK_XOFF),
129855f8f680SVladimir Kondratiev 			   CHECK_QSTATE(FROZEN)
129955f8f680SVladimir Kondratiev 			  );
130055f8f680SVladimir Kondratiev 	}
130155f8f680SVladimir Kondratiev #undef CHECK_QSTATE
130284bb29b7SVladimir Kondratiev 	return 0;
130384bb29b7SVladimir Kondratiev }
130484bb29b7SVladimir Kondratiev 
130584bb29b7SVladimir Kondratiev static int wil_info_seq_open(struct inode *inode, struct file *file)
130684bb29b7SVladimir Kondratiev {
130784bb29b7SVladimir Kondratiev 	return single_open(file, wil_info_debugfs_show, inode->i_private);
130884bb29b7SVladimir Kondratiev }
130984bb29b7SVladimir Kondratiev 
131084bb29b7SVladimir Kondratiev static const struct file_operations fops_info = {
131184bb29b7SVladimir Kondratiev 	.open		= wil_info_seq_open,
131284bb29b7SVladimir Kondratiev 	.release	= single_release,
131384bb29b7SVladimir Kondratiev 	.read		= seq_read,
131484bb29b7SVladimir Kondratiev 	.llseek		= seq_lseek,
131584bb29b7SVladimir Kondratiev };
131684bb29b7SVladimir Kondratiev 
1317c33407a8SVladimir Kondratiev /*---------recovery------------*/
1318c33407a8SVladimir Kondratiev /* mode = [manual|auto]
1319c33407a8SVladimir Kondratiev  * state = [idle|pending|running]
1320c33407a8SVladimir Kondratiev  */
1321c33407a8SVladimir Kondratiev static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf,
1322c33407a8SVladimir Kondratiev 				      size_t count, loff_t *ppos)
1323c33407a8SVladimir Kondratiev {
1324c33407a8SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
1325c33407a8SVladimir Kondratiev 	char buf[80];
1326c33407a8SVladimir Kondratiev 	int n;
1327c33407a8SVladimir Kondratiev 	static const char * const sstate[] = {"idle", "pending", "running"};
1328c33407a8SVladimir Kondratiev 
1329c33407a8SVladimir Kondratiev 	n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n",
1330c33407a8SVladimir Kondratiev 		     no_fw_recovery ? "manual" : "auto",
1331c33407a8SVladimir Kondratiev 		     sstate[wil->recovery_state]);
1332c33407a8SVladimir Kondratiev 
1333c33407a8SVladimir Kondratiev 	n = min_t(int, n, sizeof(buf));
1334c33407a8SVladimir Kondratiev 
1335c33407a8SVladimir Kondratiev 	return simple_read_from_buffer(user_buf, count, ppos,
1336c33407a8SVladimir Kondratiev 				       buf, n);
1337c33407a8SVladimir Kondratiev }
1338c33407a8SVladimir Kondratiev 
1339c33407a8SVladimir Kondratiev static ssize_t wil_write_file_recovery(struct file *file,
1340c33407a8SVladimir Kondratiev 				       const char __user *buf_,
1341c33407a8SVladimir Kondratiev 				       size_t count, loff_t *ppos)
1342c33407a8SVladimir Kondratiev {
1343c33407a8SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
1344c33407a8SVladimir Kondratiev 	static const char run_command[] = "run";
1345c33407a8SVladimir Kondratiev 	char buf[sizeof(run_command) + 1]; /* to detect "runx" */
1346c33407a8SVladimir Kondratiev 	ssize_t rc;
1347c33407a8SVladimir Kondratiev 
1348c33407a8SVladimir Kondratiev 	if (wil->recovery_state != fw_recovery_pending) {
1349c33407a8SVladimir Kondratiev 		wil_err(wil, "No recovery pending\n");
1350c33407a8SVladimir Kondratiev 		return -EINVAL;
1351c33407a8SVladimir Kondratiev 	}
1352c33407a8SVladimir Kondratiev 
1353c33407a8SVladimir Kondratiev 	if (*ppos != 0) {
1354c33407a8SVladimir Kondratiev 		wil_err(wil, "Offset [%d]\n", (int)*ppos);
1355c33407a8SVladimir Kondratiev 		return -EINVAL;
1356c33407a8SVladimir Kondratiev 	}
1357c33407a8SVladimir Kondratiev 
1358c33407a8SVladimir Kondratiev 	if (count > sizeof(buf)) {
1359c33407a8SVladimir Kondratiev 		wil_err(wil, "Input too long, len = %d\n", (int)count);
1360c33407a8SVladimir Kondratiev 		return -EINVAL;
1361c33407a8SVladimir Kondratiev 	}
1362c33407a8SVladimir Kondratiev 
1363c33407a8SVladimir Kondratiev 	rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count);
1364c33407a8SVladimir Kondratiev 	if (rc < 0)
1365c33407a8SVladimir Kondratiev 		return rc;
1366c33407a8SVladimir Kondratiev 
1367c33407a8SVladimir Kondratiev 	buf[rc] = '\0';
1368c33407a8SVladimir Kondratiev 	if (0 == strcmp(buf, run_command))
1369c33407a8SVladimir Kondratiev 		wil_set_recovery_state(wil, fw_recovery_running);
1370c33407a8SVladimir Kondratiev 	else
1371c33407a8SVladimir Kondratiev 		wil_err(wil, "Bad recovery command \"%s\"\n", buf);
1372c33407a8SVladimir Kondratiev 
1373c33407a8SVladimir Kondratiev 	return rc;
1374c33407a8SVladimir Kondratiev }
1375c33407a8SVladimir Kondratiev 
1376c33407a8SVladimir Kondratiev static const struct file_operations fops_recovery = {
1377c33407a8SVladimir Kondratiev 	.read = wil_read_file_recovery,
1378c33407a8SVladimir Kondratiev 	.write = wil_write_file_recovery,
1379c33407a8SVladimir Kondratiev 	.open  = simple_open,
1380c33407a8SVladimir Kondratiev };
1381c33407a8SVladimir Kondratiev 
13823df2cd36SVladimir Kondratiev /*---------Station matrix------------*/
1383b4490f42SVladimir Kondratiev static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
1384b4490f42SVladimir Kondratiev {
1385b4490f42SVladimir Kondratiev 	int i;
1386b4490f42SVladimir Kondratiev 	u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
138791a8edccSVladimir Kondratiev 	unsigned long long drop_dup = r->drop_dup, drop_old = r->drop_old;
13888fe59627SVladimir Kondratiev 
138937f8d26dSDedy Lansky 	seq_printf(s, "([%2d]) 0x%03x [", r->buf_size, r->head_seq_num);
1390b4490f42SVladimir Kondratiev 	for (i = 0; i < r->buf_size; i++) {
1391b4490f42SVladimir Kondratiev 		if (i == index)
1392b4490f42SVladimir Kondratiev 			seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
1393b4490f42SVladimir Kondratiev 		else
1394b4490f42SVladimir Kondratiev 			seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
1395b4490f42SVladimir Kondratiev 	}
139691a8edccSVladimir Kondratiev 	seq_printf(s,
139791a8edccSVladimir Kondratiev 		   "] total %llu drop %llu (dup %llu + old %llu) last 0x%03x\n",
139891a8edccSVladimir Kondratiev 		   r->total, drop_dup + drop_old, drop_dup, drop_old,
139991a8edccSVladimir Kondratiev 		   r->ssn_last_drop);
1400b4490f42SVladimir Kondratiev }
14013df2cd36SVladimir Kondratiev 
140258527421SVladimir Kondratiev static void wil_print_rxtid_crypto(struct seq_file *s, int tid,
140358527421SVladimir Kondratiev 				   struct wil_tid_crypto_rx *c)
140458527421SVladimir Kondratiev {
140558527421SVladimir Kondratiev 	int i;
140658527421SVladimir Kondratiev 
140758527421SVladimir Kondratiev 	for (i = 0; i < 4; i++) {
140858527421SVladimir Kondratiev 		struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
140958527421SVladimir Kondratiev 
141058527421SVladimir Kondratiev 		if (cc->key_set)
141158527421SVladimir Kondratiev 			goto has_keys;
141258527421SVladimir Kondratiev 	}
141358527421SVladimir Kondratiev 	return;
141458527421SVladimir Kondratiev 
141558527421SVladimir Kondratiev has_keys:
141658527421SVladimir Kondratiev 	if (tid < WIL_STA_TID_NUM)
141758527421SVladimir Kondratiev 		seq_printf(s, "  [%2d] PN", tid);
141858527421SVladimir Kondratiev 	else
141958527421SVladimir Kondratiev 		seq_puts(s, "  [GR] PN");
142058527421SVladimir Kondratiev 
142158527421SVladimir Kondratiev 	for (i = 0; i < 4; i++) {
142258527421SVladimir Kondratiev 		struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
142358527421SVladimir Kondratiev 
142458527421SVladimir Kondratiev 		seq_printf(s, " [%i%s]%6phN", i, cc->key_set ? "+" : "-",
142558527421SVladimir Kondratiev 			   cc->pn);
142658527421SVladimir Kondratiev 	}
142758527421SVladimir Kondratiev 	seq_puts(s, "\n");
142858527421SVladimir Kondratiev }
142958527421SVladimir Kondratiev 
14303df2cd36SVladimir Kondratiev static int wil_sta_debugfs_show(struct seq_file *s, void *data)
1431bd33273bSVladimir Kondratiev __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
14323df2cd36SVladimir Kondratiev {
14333df2cd36SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
1434c4a110d8SVladimir Kondratiev 	int i, tid, mcs;
14353df2cd36SVladimir Kondratiev 
14363df2cd36SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
14373df2cd36SVladimir Kondratiev 		struct wil_sta_info *p = &wil->sta[i];
14383df2cd36SVladimir Kondratiev 		char *status = "unknown";
14399d865ee2SLior David 		u8 aid = 0;
14405bd60982SLior David 		u8 mid;
14418fe59627SVladimir Kondratiev 
14423df2cd36SVladimir Kondratiev 		switch (p->status) {
14433df2cd36SVladimir Kondratiev 		case wil_sta_unused:
14443df2cd36SVladimir Kondratiev 			status = "unused   ";
14453df2cd36SVladimir Kondratiev 			break;
14463df2cd36SVladimir Kondratiev 		case wil_sta_conn_pending:
14473df2cd36SVladimir Kondratiev 			status = "pending  ";
14483df2cd36SVladimir Kondratiev 			break;
14493df2cd36SVladimir Kondratiev 		case wil_sta_connected:
14503df2cd36SVladimir Kondratiev 			status = "connected";
14519d865ee2SLior David 			aid = p->aid;
14523df2cd36SVladimir Kondratiev 			break;
14533df2cd36SVladimir Kondratiev 		}
14545bd60982SLior David 		mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
14555bd60982SLior David 		seq_printf(s, "[%d] %pM %s MID %d AID %d\n", i, p->addr, status,
14565bd60982SLior David 			   mid, aid);
1457b4490f42SVladimir Kondratiev 
1458b4490f42SVladimir Kondratiev 		if (p->status == wil_sta_connected) {
1459bd33273bSVladimir Kondratiev 			spin_lock_bh(&p->tid_rx_lock);
1460b4490f42SVladimir Kondratiev 			for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1461b4490f42SVladimir Kondratiev 				struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
146258527421SVladimir Kondratiev 				struct wil_tid_crypto_rx *c =
146358527421SVladimir Kondratiev 						&p->tid_crypto_rx[tid];
14648fe59627SVladimir Kondratiev 
1465b4490f42SVladimir Kondratiev 				if (r) {
1466b4490f42SVladimir Kondratiev 					seq_printf(s, "  [%2d] ", tid);
1467b4490f42SVladimir Kondratiev 					wil_print_rxtid(s, r);
1468b4490f42SVladimir Kondratiev 				}
146958527421SVladimir Kondratiev 
147058527421SVladimir Kondratiev 				wil_print_rxtid_crypto(s, tid, c);
1471b4490f42SVladimir Kondratiev 			}
147258527421SVladimir Kondratiev 			wil_print_rxtid_crypto(s, WIL_STA_TID_NUM,
147358527421SVladimir Kondratiev 					       &p->group_crypto_rx);
1474bd33273bSVladimir Kondratiev 			spin_unlock_bh(&p->tid_rx_lock);
14753b282bc6SVladimir Kondratiev 			seq_printf(s,
147658527421SVladimir Kondratiev 				   "Rx invalid frame: non-data %lu, short %lu, large %lu, replay %lu\n",
14773b282bc6SVladimir Kondratiev 				   p->stats.rx_non_data_frame,
14783b282bc6SVladimir Kondratiev 				   p->stats.rx_short_frame,
147958527421SVladimir Kondratiev 				   p->stats.rx_large_frame,
148058527421SVladimir Kondratiev 				   p->stats.rx_replay);
14813b282bc6SVladimir Kondratiev 
1482c4a110d8SVladimir Kondratiev 			seq_puts(s, "Rx/MCS:");
1483c4a110d8SVladimir Kondratiev 			for (mcs = 0; mcs < ARRAY_SIZE(p->stats.rx_per_mcs);
1484c4a110d8SVladimir Kondratiev 			     mcs++)
1485c4a110d8SVladimir Kondratiev 				seq_printf(s, " %lld",
1486c4a110d8SVladimir Kondratiev 					   p->stats.rx_per_mcs[mcs]);
1487c4a110d8SVladimir Kondratiev 			seq_puts(s, "\n");
1488b4490f42SVladimir Kondratiev 		}
14893df2cd36SVladimir Kondratiev 	}
14903df2cd36SVladimir Kondratiev 
14913df2cd36SVladimir Kondratiev 	return 0;
14923df2cd36SVladimir Kondratiev }
14933df2cd36SVladimir Kondratiev 
14943df2cd36SVladimir Kondratiev static int wil_sta_seq_open(struct inode *inode, struct file *file)
14953df2cd36SVladimir Kondratiev {
14963df2cd36SVladimir Kondratiev 	return single_open(file, wil_sta_debugfs_show, inode->i_private);
14973df2cd36SVladimir Kondratiev }
14983df2cd36SVladimir Kondratiev 
14993df2cd36SVladimir Kondratiev static const struct file_operations fops_sta = {
15003df2cd36SVladimir Kondratiev 	.open		= wil_sta_seq_open,
15013df2cd36SVladimir Kondratiev 	.release	= single_release,
15023df2cd36SVladimir Kondratiev 	.read		= seq_read,
15033df2cd36SVladimir Kondratiev 	.llseek		= seq_lseek,
15043df2cd36SVladimir Kondratiev };
15053df2cd36SVladimir Kondratiev 
15063a3b745fSLior David static int wil_mids_debugfs_show(struct seq_file *s, void *data)
15073a3b745fSLior David {
15083a3b745fSLior David 	struct wil6210_priv *wil = s->private;
15093a3b745fSLior David 	struct wil6210_vif *vif;
15103a3b745fSLior David 	struct net_device *ndev;
15113a3b745fSLior David 	int i;
15123a3b745fSLior David 
15133a3b745fSLior David 	mutex_lock(&wil->vif_mutex);
15143a3b745fSLior David 	for (i = 0; i < wil->max_vifs; i++) {
15153a3b745fSLior David 		vif = wil->vifs[i];
15163a3b745fSLior David 
15173a3b745fSLior David 		if (vif) {
15183a3b745fSLior David 			ndev = vif_to_ndev(vif);
15193a3b745fSLior David 			seq_printf(s, "[%d] %pM %s\n", i, ndev->dev_addr,
15203a3b745fSLior David 				   ndev->name);
15213a3b745fSLior David 		} else {
15223a3b745fSLior David 			seq_printf(s, "[%d] unused\n", i);
15233a3b745fSLior David 		}
15243a3b745fSLior David 	}
15253a3b745fSLior David 	mutex_unlock(&wil->vif_mutex);
15263a3b745fSLior David 
15273a3b745fSLior David 	return 0;
15283a3b745fSLior David }
15293a3b745fSLior David 
15303a3b745fSLior David static int wil_mids_seq_open(struct inode *inode, struct file *file)
15313a3b745fSLior David {
15323a3b745fSLior David 	return single_open(file, wil_mids_debugfs_show, inode->i_private);
15333a3b745fSLior David }
15343a3b745fSLior David 
15353a3b745fSLior David static const struct file_operations fops_mids = {
15363a3b745fSLior David 	.open		= wil_mids_seq_open,
15373a3b745fSLior David 	.release	= single_release,
15383a3b745fSLior David 	.read		= seq_read,
15393a3b745fSLior David 	.llseek		= seq_lseek,
15403a3b745fSLior David };
15413a3b745fSLior David 
154210d599adSMaya Erez static ssize_t wil_read_file_led_cfg(struct file *file, char __user *user_buf,
154310d599adSMaya Erez 				     size_t count, loff_t *ppos)
154410d599adSMaya Erez {
154510d599adSMaya Erez 	char buf[80];
154610d599adSMaya Erez 	int n;
154710d599adSMaya Erez 
154810d599adSMaya Erez 	n = snprintf(buf, sizeof(buf),
154910d599adSMaya Erez 		     "led_id is set to %d, echo 1 to enable, 0 to disable\n",
155010d599adSMaya Erez 		     led_id);
155110d599adSMaya Erez 
155210d599adSMaya Erez 	n = min_t(int, n, sizeof(buf));
155310d599adSMaya Erez 
155410d599adSMaya Erez 	return simple_read_from_buffer(user_buf, count, ppos,
155510d599adSMaya Erez 				       buf, n);
155610d599adSMaya Erez }
155710d599adSMaya Erez 
155810d599adSMaya Erez static ssize_t wil_write_file_led_cfg(struct file *file,
155910d599adSMaya Erez 				      const char __user *buf_,
156010d599adSMaya Erez 				      size_t count, loff_t *ppos)
156110d599adSMaya Erez {
156210d599adSMaya Erez 	struct wil6210_priv *wil = file->private_data;
156310d599adSMaya Erez 	int val;
156410d599adSMaya Erez 	int rc;
156510d599adSMaya Erez 
156610d599adSMaya Erez 	rc = kstrtoint_from_user(buf_, count, 0, &val);
156710d599adSMaya Erez 	if (rc) {
156810d599adSMaya Erez 		wil_err(wil, "Invalid argument\n");
156910d599adSMaya Erez 		return rc;
157010d599adSMaya Erez 	}
157110d599adSMaya Erez 
157210d599adSMaya Erez 	wil_info(wil, "%s led %d\n", val ? "Enabling" : "Disabling", led_id);
157310d599adSMaya Erez 	rc = wmi_led_cfg(wil, val);
157410d599adSMaya Erez 	if (rc) {
157510d599adSMaya Erez 		wil_info(wil, "%s led %d failed\n",
157610d599adSMaya Erez 			 val ? "Enabling" : "Disabling", led_id);
157710d599adSMaya Erez 		return rc;
157810d599adSMaya Erez 	}
157910d599adSMaya Erez 
158010d599adSMaya Erez 	return count;
158110d599adSMaya Erez }
158210d599adSMaya Erez 
158310d599adSMaya Erez static const struct file_operations fops_led_cfg = {
158410d599adSMaya Erez 	.read = wil_read_file_led_cfg,
158510d599adSMaya Erez 	.write = wil_write_file_led_cfg,
158610d599adSMaya Erez 	.open  = simple_open,
158710d599adSMaya Erez };
158810d599adSMaya Erez 
158910d599adSMaya Erez /* led_blink_time, write:
159010d599adSMaya Erez  * "<blink_on_slow> <blink_off_slow> <blink_on_med> <blink_off_med> <blink_on_fast> <blink_off_fast>
159110d599adSMaya Erez  */
159210d599adSMaya Erez static ssize_t wil_write_led_blink_time(struct file *file,
159310d599adSMaya Erez 					const char __user *buf,
159410d599adSMaya Erez 					size_t len, loff_t *ppos)
159510d599adSMaya Erez {
159610d599adSMaya Erez 	int rc;
159710d599adSMaya Erez 	char *kbuf = kmalloc(len + 1, GFP_KERNEL);
159810d599adSMaya Erez 
159910d599adSMaya Erez 	if (!kbuf)
160010d599adSMaya Erez 		return -ENOMEM;
160110d599adSMaya Erez 
160210d599adSMaya Erez 	rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
160310d599adSMaya Erez 	if (rc != len) {
160410d599adSMaya Erez 		kfree(kbuf);
160510d599adSMaya Erez 		return rc >= 0 ? -EIO : rc;
160610d599adSMaya Erez 	}
160710d599adSMaya Erez 
160810d599adSMaya Erez 	kbuf[len] = '\0';
160910d599adSMaya Erez 	rc = sscanf(kbuf, "%d %d %d %d %d %d",
161010d599adSMaya Erez 		    &led_blink_time[WIL_LED_TIME_SLOW].on_ms,
161110d599adSMaya Erez 		    &led_blink_time[WIL_LED_TIME_SLOW].off_ms,
161210d599adSMaya Erez 		    &led_blink_time[WIL_LED_TIME_MED].on_ms,
161310d599adSMaya Erez 		    &led_blink_time[WIL_LED_TIME_MED].off_ms,
161410d599adSMaya Erez 		    &led_blink_time[WIL_LED_TIME_FAST].on_ms,
161510d599adSMaya Erez 		    &led_blink_time[WIL_LED_TIME_FAST].off_ms);
161610d599adSMaya Erez 	kfree(kbuf);
161710d599adSMaya Erez 
161810d599adSMaya Erez 	if (rc < 0)
161910d599adSMaya Erez 		return rc;
162010d599adSMaya Erez 	if (rc < 6)
162110d599adSMaya Erez 		return -EINVAL;
162210d599adSMaya Erez 
162310d599adSMaya Erez 	return len;
162410d599adSMaya Erez }
162510d599adSMaya Erez 
162610d599adSMaya Erez static ssize_t wil_read_led_blink_time(struct file *file, char __user *user_buf,
162710d599adSMaya Erez 				       size_t count, loff_t *ppos)
162810d599adSMaya Erez {
162910d599adSMaya Erez 	static char text[400];
163010d599adSMaya Erez 
163110d599adSMaya Erez 	snprintf(text, sizeof(text),
163210d599adSMaya Erez 		 "To set led blink on/off time variables write:\n"
163310d599adSMaya Erez 		 "<blink_on_slow> <blink_off_slow> <blink_on_med> "
163410d599adSMaya Erez 		 "<blink_off_med> <blink_on_fast> <blink_off_fast>\n"
163510d599adSMaya Erez 		 "The current values are:\n"
163610d599adSMaya Erez 		 "%d %d %d %d %d %d\n",
163710d599adSMaya Erez 		 led_blink_time[WIL_LED_TIME_SLOW].on_ms,
163810d599adSMaya Erez 		 led_blink_time[WIL_LED_TIME_SLOW].off_ms,
163910d599adSMaya Erez 		 led_blink_time[WIL_LED_TIME_MED].on_ms,
164010d599adSMaya Erez 		 led_blink_time[WIL_LED_TIME_MED].off_ms,
164110d599adSMaya Erez 		 led_blink_time[WIL_LED_TIME_FAST].on_ms,
164210d599adSMaya Erez 		 led_blink_time[WIL_LED_TIME_FAST].off_ms);
164310d599adSMaya Erez 
164410d599adSMaya Erez 	return simple_read_from_buffer(user_buf, count, ppos, text,
164510d599adSMaya Erez 				       sizeof(text));
164610d599adSMaya Erez }
164710d599adSMaya Erez 
164810d599adSMaya Erez static const struct file_operations fops_led_blink_time = {
164910d599adSMaya Erez 	.read = wil_read_led_blink_time,
165010d599adSMaya Erez 	.write = wil_write_led_blink_time,
165110d599adSMaya Erez 	.open  = simple_open,
165210d599adSMaya Erez };
165310d599adSMaya Erez 
165412bace75SLior David /*---------FW capabilities------------*/
165512bace75SLior David static int wil_fw_capabilities_debugfs_show(struct seq_file *s, void *data)
165612bace75SLior David {
165712bace75SLior David 	struct wil6210_priv *wil = s->private;
165812bace75SLior David 
165912bace75SLior David 	seq_printf(s, "fw_capabilities : %*pb\n", WMI_FW_CAPABILITY_MAX,
166012bace75SLior David 		   wil->fw_capabilities);
166112bace75SLior David 
166212bace75SLior David 	return 0;
166312bace75SLior David }
166412bace75SLior David 
166512bace75SLior David static int wil_fw_capabilities_seq_open(struct inode *inode, struct file *file)
166612bace75SLior David {
166712bace75SLior David 	return single_open(file, wil_fw_capabilities_debugfs_show,
166812bace75SLior David 			   inode->i_private);
166912bace75SLior David }
167012bace75SLior David 
167112bace75SLior David static const struct file_operations fops_fw_capabilities = {
167212bace75SLior David 	.open		= wil_fw_capabilities_seq_open,
167312bace75SLior David 	.release	= single_release,
167412bace75SLior David 	.read		= seq_read,
167512bace75SLior David 	.llseek		= seq_lseek,
167612bace75SLior David };
167712bace75SLior David 
167813cd9f75SLior David /*---------FW version------------*/
167913cd9f75SLior David static int wil_fw_version_debugfs_show(struct seq_file *s, void *data)
168013cd9f75SLior David {
168113cd9f75SLior David 	struct wil6210_priv *wil = s->private;
168213cd9f75SLior David 
168313cd9f75SLior David 	if (wil->fw_version[0])
168413cd9f75SLior David 		seq_printf(s, "%s\n", wil->fw_version);
168513cd9f75SLior David 	else
168613cd9f75SLior David 		seq_puts(s, "N/A\n");
168713cd9f75SLior David 
168813cd9f75SLior David 	return 0;
168913cd9f75SLior David }
169013cd9f75SLior David 
169113cd9f75SLior David static int wil_fw_version_seq_open(struct inode *inode, struct file *file)
169213cd9f75SLior David {
169313cd9f75SLior David 	return single_open(file, wil_fw_version_debugfs_show,
169413cd9f75SLior David 			   inode->i_private);
169513cd9f75SLior David }
169613cd9f75SLior David 
169713cd9f75SLior David static const struct file_operations fops_fw_version = {
169813cd9f75SLior David 	.open		= wil_fw_version_seq_open,
169913cd9f75SLior David 	.release	= single_release,
170013cd9f75SLior David 	.read		= seq_read,
170113cd9f75SLior David 	.llseek		= seq_lseek,
170213cd9f75SLior David };
170313cd9f75SLior David 
1704fe9ee51eSMaya Erez /*---------suspend_stats---------*/
1705fe9ee51eSMaya Erez static ssize_t wil_write_suspend_stats(struct file *file,
1706fe9ee51eSMaya Erez 				       const char __user *buf,
1707fe9ee51eSMaya Erez 				       size_t len, loff_t *ppos)
1708fe9ee51eSMaya Erez {
1709fe9ee51eSMaya Erez 	struct wil6210_priv *wil = file->private_data;
1710fe9ee51eSMaya Erez 
1711fe9ee51eSMaya Erez 	memset(&wil->suspend_stats, 0, sizeof(wil->suspend_stats));
1712fe9ee51eSMaya Erez 
1713fe9ee51eSMaya Erez 	return len;
1714fe9ee51eSMaya Erez }
1715fe9ee51eSMaya Erez 
1716fe9ee51eSMaya Erez static ssize_t wil_read_suspend_stats(struct file *file,
1717fe9ee51eSMaya Erez 				      char __user *user_buf,
1718fe9ee51eSMaya Erez 				      size_t count, loff_t *ppos)
1719fe9ee51eSMaya Erez {
1720fe9ee51eSMaya Erez 	struct wil6210_priv *wil = file->private_data;
1721bd8bdc6cSLazar Alexei 	char *text;
1722bd8bdc6cSLazar Alexei 	int n, ret, text_size = 500;
1723fe9ee51eSMaya Erez 
1724bd8bdc6cSLazar Alexei 	text = kmalloc(text_size, GFP_KERNEL);
1725bd8bdc6cSLazar Alexei 	if (!text)
1726bd8bdc6cSLazar Alexei 		return -ENOMEM;
1727bd8bdc6cSLazar Alexei 
1728bd8bdc6cSLazar Alexei 	n = snprintf(text, text_size,
1729bd8bdc6cSLazar Alexei 		     "Radio on suspend statistics:\n"
1730fe9ee51eSMaya Erez 		     "successful suspends:%ld failed suspends:%ld\n"
1731fe9ee51eSMaya Erez 		     "successful resumes:%ld failed resumes:%ld\n"
1732bd8bdc6cSLazar Alexei 		     "rejected by device:%ld\n"
1733bd8bdc6cSLazar Alexei 		     "Radio off suspend statistics:\n"
1734bd8bdc6cSLazar Alexei 		     "successful suspends:%ld failed suspends:%ld\n"
1735bd8bdc6cSLazar Alexei 		     "successful resumes:%ld failed resumes:%ld\n"
1736bd8bdc6cSLazar Alexei 		     "General statistics:\n"
1737bd8bdc6cSLazar Alexei 		     "rejected by host:%ld\n",
1738bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_on.successful_suspends,
1739bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_on.failed_suspends,
1740bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_on.successful_resumes,
1741bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_on.failed_resumes,
1742bd8bdc6cSLazar Alexei 		     wil->suspend_stats.rejected_by_device,
1743bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_off.successful_suspends,
1744bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_off.failed_suspends,
1745bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_off.successful_resumes,
1746bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_off.failed_resumes,
1747bd8bdc6cSLazar Alexei 		     wil->suspend_stats.rejected_by_host);
1748fe9ee51eSMaya Erez 
1749bd8bdc6cSLazar Alexei 	n = min_t(int, n, text_size);
1750fe9ee51eSMaya Erez 
1751bd8bdc6cSLazar Alexei 	ret = simple_read_from_buffer(user_buf, count, ppos, text, n);
1752bd8bdc6cSLazar Alexei 
1753bd8bdc6cSLazar Alexei 	kfree(text);
1754bd8bdc6cSLazar Alexei 
1755bd8bdc6cSLazar Alexei 	return ret;
1756fe9ee51eSMaya Erez }
1757fe9ee51eSMaya Erez 
1758fe9ee51eSMaya Erez static const struct file_operations fops_suspend_stats = {
1759fe9ee51eSMaya Erez 	.read = wil_read_suspend_stats,
1760fe9ee51eSMaya Erez 	.write = wil_write_suspend_stats,
1761fe9ee51eSMaya Erez 	.open  = simple_open,
1762fe9ee51eSMaya Erez };
1763fe9ee51eSMaya Erez 
1764*96c93589SGidon Studinski /*---------compressed_rx_status---------*/
1765*96c93589SGidon Studinski static ssize_t wil_compressed_rx_status_write(struct file *file,
1766*96c93589SGidon Studinski 					      const char __user *buf,
1767*96c93589SGidon Studinski 					      size_t len, loff_t *ppos)
1768*96c93589SGidon Studinski {
1769*96c93589SGidon Studinski 	struct seq_file *s = file->private_data;
1770*96c93589SGidon Studinski 	struct wil6210_priv *wil = s->private;
1771*96c93589SGidon Studinski 	int compressed_rx_status;
1772*96c93589SGidon Studinski 	int rc;
1773*96c93589SGidon Studinski 
1774*96c93589SGidon Studinski 	rc = kstrtoint_from_user(buf, len, 0, &compressed_rx_status);
1775*96c93589SGidon Studinski 	if (rc) {
1776*96c93589SGidon Studinski 		wil_err(wil, "Invalid argument\n");
1777*96c93589SGidon Studinski 		return rc;
1778*96c93589SGidon Studinski 	}
1779*96c93589SGidon Studinski 
1780*96c93589SGidon Studinski 	if (wil_has_active_ifaces(wil, true, false)) {
1781*96c93589SGidon Studinski 		wil_err(wil, "cannot change edma config after iface is up\n");
1782*96c93589SGidon Studinski 		return -EPERM;
1783*96c93589SGidon Studinski 	}
1784*96c93589SGidon Studinski 
1785*96c93589SGidon Studinski 	wil_info(wil, "%sable compressed_rx_status\n",
1786*96c93589SGidon Studinski 		 compressed_rx_status ? "En" : "Dis");
1787*96c93589SGidon Studinski 
1788*96c93589SGidon Studinski 	wil->use_compressed_rx_status = compressed_rx_status;
1789*96c93589SGidon Studinski 
1790*96c93589SGidon Studinski 	return len;
1791*96c93589SGidon Studinski }
1792*96c93589SGidon Studinski 
1793*96c93589SGidon Studinski static int
1794*96c93589SGidon Studinski wil_compressed_rx_status_show(struct seq_file *s, void *data)
1795*96c93589SGidon Studinski {
1796*96c93589SGidon Studinski 	struct wil6210_priv *wil = s->private;
1797*96c93589SGidon Studinski 
1798*96c93589SGidon Studinski 	seq_printf(s, "%d\n", wil->use_compressed_rx_status);
1799*96c93589SGidon Studinski 
1800*96c93589SGidon Studinski 	return 0;
1801*96c93589SGidon Studinski }
1802*96c93589SGidon Studinski 
1803*96c93589SGidon Studinski static int
1804*96c93589SGidon Studinski wil_compressed_rx_status_seq_open(struct inode *inode, struct file *file)
1805*96c93589SGidon Studinski {
1806*96c93589SGidon Studinski 	return single_open(file, wil_compressed_rx_status_show,
1807*96c93589SGidon Studinski 			   inode->i_private);
1808*96c93589SGidon Studinski }
1809*96c93589SGidon Studinski 
1810*96c93589SGidon Studinski static const struct file_operations fops_compressed_rx_status = {
1811*96c93589SGidon Studinski 	.open  = wil_compressed_rx_status_seq_open,
1812*96c93589SGidon Studinski 	.release = single_release,
1813*96c93589SGidon Studinski 	.read = seq_read,
1814*96c93589SGidon Studinski 	.write = wil_compressed_rx_status_write,
1815*96c93589SGidon Studinski 	.llseek	= seq_lseek,
1816*96c93589SGidon Studinski };
1817*96c93589SGidon Studinski 
18182be7d22fSVladimir Kondratiev /*----------------*/
1819b541d0a0SVladimir Kondratiev static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
1820b541d0a0SVladimir Kondratiev 				       struct dentry *dbg)
1821b541d0a0SVladimir Kondratiev {
1822b541d0a0SVladimir Kondratiev 	int i;
1823b541d0a0SVladimir Kondratiev 	char name[32];
1824b541d0a0SVladimir Kondratiev 
1825b541d0a0SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
1826349214c1SMaya Erez 		struct wil_blob_wrapper *wil_blob = &wil->blobs[i];
1827349214c1SMaya Erez 		struct debugfs_blob_wrapper *blob = &wil_blob->blob;
1828b541d0a0SVladimir Kondratiev 		const struct fw_map *map = &fw_mapping[i];
1829b541d0a0SVladimir Kondratiev 
1830b541d0a0SVladimir Kondratiev 		if (!map->name)
1831b541d0a0SVladimir Kondratiev 			continue;
1832b541d0a0SVladimir Kondratiev 
1833349214c1SMaya Erez 		wil_blob->wil = wil;
1834b541d0a0SVladimir Kondratiev 		blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
1835b541d0a0SVladimir Kondratiev 		blob->size = map->to - map->from;
1836b541d0a0SVladimir Kondratiev 		snprintf(name, sizeof(name), "blob_%s", map->name);
183778484c44SMaya Erez 		wil_debugfs_create_ioblob(name, 0444, dbg, wil_blob);
1838b541d0a0SVladimir Kondratiev 	}
1839b541d0a0SVladimir Kondratiev }
1840b541d0a0SVladimir Kondratiev 
1841b7cde470SVladimir Kondratiev /* misc files */
1842b7cde470SVladimir Kondratiev static const struct {
1843b7cde470SVladimir Kondratiev 	const char *name;
1844b7cde470SVladimir Kondratiev 	umode_t mode;
1845b7cde470SVladimir Kondratiev 	const struct file_operations *fops;
1846b7cde470SVladimir Kondratiev } dbg_files[] = {
184778484c44SMaya Erez 	{"mbox",	0444,		&fops_mbox},
184810590c6aSGidon Studinski 	{"rings",	0444,		&fops_ring},
184978484c44SMaya Erez 	{"stations", 0444,		&fops_sta},
18503a3b745fSLior David 	{"mids",	0444,		&fops_mids},
185178484c44SMaya Erez 	{"desc",	0444,		&fops_txdesc},
185278484c44SMaya Erez 	{"bf",		0444,		&fops_bf},
185378484c44SMaya Erez 	{"mem_val",	0644,		&fops_memread},
185478484c44SMaya Erez 	{"reset",	0244,		&fops_reset},
185578484c44SMaya Erez 	{"rxon",	0244,		&fops_rxon},
185678484c44SMaya Erez 	{"tx_mgmt",	0244,		&fops_txmgmt},
185778484c44SMaya Erez 	{"wmi_send", 0244,		&fops_wmi},
185878484c44SMaya Erez 	{"back",	0644,		&fops_back},
185978484c44SMaya Erez 	{"pmccfg",	0644,		&fops_pmccfg},
186078484c44SMaya Erez 	{"pmcdata",	0444,		&fops_pmcdata},
186178484c44SMaya Erez 	{"temp",	0444,		&fops_temp},
186278484c44SMaya Erez 	{"freq",	0444,		&fops_freq},
186378484c44SMaya Erez 	{"link",	0444,		&fops_link},
186478484c44SMaya Erez 	{"info",	0444,		&fops_info},
186578484c44SMaya Erez 	{"recovery", 0644,		&fops_recovery},
186678484c44SMaya Erez 	{"led_cfg",	0644,		&fops_led_cfg},
186778484c44SMaya Erez 	{"led_blink_time",	0644,	&fops_led_blink_time},
186878484c44SMaya Erez 	{"fw_capabilities",	0444,	&fops_fw_capabilities},
186978484c44SMaya Erez 	{"fw_version",	0444,		&fops_fw_version},
1870fe9ee51eSMaya Erez 	{"suspend_stats",	0644,	&fops_suspend_stats},
1871*96c93589SGidon Studinski 	{"compressed_rx_status", 0644,	&fops_compressed_rx_status},
1872b7cde470SVladimir Kondratiev };
1873b7cde470SVladimir Kondratiev 
1874b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
1875b7cde470SVladimir Kondratiev 				       struct dentry *dbg)
1876b7cde470SVladimir Kondratiev {
1877b7cde470SVladimir Kondratiev 	int i;
1878b7cde470SVladimir Kondratiev 
1879b7cde470SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
1880b7cde470SVladimir Kondratiev 		debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
1881b7cde470SVladimir Kondratiev 				    wil, dbg_files[i].fops);
1882b7cde470SVladimir Kondratiev }
1883b7cde470SVladimir Kondratiev 
1884b7cde470SVladimir Kondratiev /* interrupt control blocks */
1885b7cde470SVladimir Kondratiev static const struct {
1886b7cde470SVladimir Kondratiev 	const char *name;
1887b7cde470SVladimir Kondratiev 	u32 icr_off;
1888b7cde470SVladimir Kondratiev } dbg_icr[] = {
1889b7cde470SVladimir Kondratiev 	{"USER_ICR",		HOSTADDR(RGF_USER_USER_ICR)},
1890b7cde470SVladimir Kondratiev 	{"DMA_EP_TX_ICR",	HOSTADDR(RGF_DMA_EP_TX_ICR)},
1891b7cde470SVladimir Kondratiev 	{"DMA_EP_RX_ICR",	HOSTADDR(RGF_DMA_EP_RX_ICR)},
1892b7cde470SVladimir Kondratiev 	{"DMA_EP_MISC_ICR",	HOSTADDR(RGF_DMA_EP_MISC_ICR)},
1893b7cde470SVladimir Kondratiev };
1894b7cde470SVladimir Kondratiev 
1895b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
1896b7cde470SVladimir Kondratiev 				     struct dentry *dbg)
1897b7cde470SVladimir Kondratiev {
1898b7cde470SVladimir Kondratiev 	int i;
1899b7cde470SVladimir Kondratiev 
1900b7cde470SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
1901b7cde470SVladimir Kondratiev 		wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
1902b7cde470SVladimir Kondratiev 					   dbg_icr[i].icr_off);
1903b7cde470SVladimir Kondratiev }
1904b7cde470SVladimir Kondratiev 
1905b7cde470SVladimir Kondratiev #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
1906b7cde470SVladimir Kondratiev 	offsetof(struct wil6210_priv, name), type}
1907b7cde470SVladimir Kondratiev 
1908b7cde470SVladimir Kondratiev /* fields in struct wil6210_priv */
1909b7cde470SVladimir Kondratiev static const struct dbg_off dbg_wil_off[] = {
191078484c44SMaya Erez 	WIL_FIELD(status[0],	0644,	doff_ulong),
191178484c44SMaya Erez 	WIL_FIELD(hw_version,	0444,	doff_x32),
191278484c44SMaya Erez 	WIL_FIELD(recovery_count, 0444,	doff_u32),
191378484c44SMaya Erez 	WIL_FIELD(discovery_mode, 0644,	doff_u8),
191478484c44SMaya Erez 	WIL_FIELD(chip_revision, 0444,	doff_u8),
191578484c44SMaya Erez 	WIL_FIELD(abft_len, 0644,		doff_u8),
1916fe9ee51eSMaya Erez 	WIL_FIELD(wakeup_trigger, 0644,		doff_u8),
191710590c6aSGidon Studinski 	WIL_FIELD(ring_idle_trsh, 0644,	doff_u32),
1918*96c93589SGidon Studinski 	WIL_FIELD(num_rx_status_rings, 0644,	doff_u8),
1919*96c93589SGidon Studinski 	WIL_FIELD(rx_status_ring_order, 0644,	doff_u32),
1920*96c93589SGidon Studinski 	WIL_FIELD(tx_status_ring_order, 0644,	doff_u32),
1921*96c93589SGidon Studinski 	WIL_FIELD(rx_buff_id_count, 0644,	doff_u32),
1922b7cde470SVladimir Kondratiev 	{},
1923b7cde470SVladimir Kondratiev };
1924b7cde470SVladimir Kondratiev 
1925b7cde470SVladimir Kondratiev static const struct dbg_off dbg_wil_regs[] = {
192678484c44SMaya Erez 	{"RGF_MAC_MTRL_COUNTER_0", 0444, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
1927b7cde470SVladimir Kondratiev 		doff_io32},
192878484c44SMaya Erez 	{"RGF_USER_USAGE_1", 0444, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
1929b7cde470SVladimir Kondratiev 	{},
1930b7cde470SVladimir Kondratiev };
1931b7cde470SVladimir Kondratiev 
1932b7cde470SVladimir Kondratiev /* static parameters */
1933b7cde470SVladimir Kondratiev static const struct dbg_off dbg_statics[] = {
193478484c44SMaya Erez 	{"desc_index",	0644, (ulong)&dbg_txdesc_index, doff_u32},
193510590c6aSGidon Studinski 	{"ring_index",	0644, (ulong)&dbg_ring_index, doff_u32},
193678484c44SMaya Erez 	{"mem_addr",	0644, (ulong)&mem_addr, doff_u32},
193778484c44SMaya Erez 	{"led_polarity", 0644, (ulong)&led_polarity, doff_u8},
1938b7cde470SVladimir Kondratiev 	{},
1939b7cde470SVladimir Kondratiev };
1940b7cde470SVladimir Kondratiev 
194194162666SLazar Alexei static const int dbg_off_count = 4 * (ARRAY_SIZE(isr_off) - 1) +
194294162666SLazar Alexei 				ARRAY_SIZE(dbg_wil_regs) - 1 +
194394162666SLazar Alexei 				ARRAY_SIZE(pseudo_isr_off) - 1 +
194494162666SLazar Alexei 				ARRAY_SIZE(lgc_itr_cnt_off) - 1 +
194594162666SLazar Alexei 				ARRAY_SIZE(tx_itr_cnt_off) - 1 +
194694162666SLazar Alexei 				ARRAY_SIZE(rx_itr_cnt_off) - 1;
194794162666SLazar Alexei 
19482be7d22fSVladimir Kondratiev int wil6210_debugfs_init(struct wil6210_priv *wil)
19492be7d22fSVladimir Kondratiev {
19502be7d22fSVladimir Kondratiev 	struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
19512be7d22fSVladimir Kondratiev 			wil_to_wiphy(wil)->debugfsdir);
19522be7d22fSVladimir Kondratiev 	if (IS_ERR_OR_NULL(dbg))
19532be7d22fSVladimir Kondratiev 		return -ENODEV;
19542be7d22fSVladimir Kondratiev 
195594162666SLazar Alexei 	wil->dbg_data.data_arr = kcalloc(dbg_off_count,
195694162666SLazar Alexei 					 sizeof(struct wil_debugfs_iomem_data),
195794162666SLazar Alexei 					 GFP_KERNEL);
195894162666SLazar Alexei 	if (!wil->dbg_data.data_arr) {
195994162666SLazar Alexei 		debugfs_remove_recursive(dbg);
196094162666SLazar Alexei 		wil->debug = NULL;
196194162666SLazar Alexei 		return -ENOMEM;
196294162666SLazar Alexei 	}
196394162666SLazar Alexei 
196494162666SLazar Alexei 	wil->dbg_data.iomem_data_count = 0;
196594162666SLazar Alexei 
1966dc16427bSVladimir Kondratiev 	wil_pmc_init(wil);
1967dc16427bSVladimir Kondratiev 
1968b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_files(wil, dbg);
1969b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_isr(wil, dbg);
1970b541d0a0SVladimir Kondratiev 	wil6210_debugfs_init_blobs(wil, dbg);
1971b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
1972b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
1973b7cde470SVladimir Kondratiev 				    dbg_wil_regs);
1974b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
1975b7cde470SVladimir Kondratiev 
1976b7cde470SVladimir Kondratiev 	wil6210_debugfs_create_pseudo_ISR(wil, dbg);
1977b7cde470SVladimir Kondratiev 
1978b7cde470SVladimir Kondratiev 	wil6210_debugfs_create_ITR_CNT(wil, dbg);
19792be7d22fSVladimir Kondratiev 
19802be7d22fSVladimir Kondratiev 	return 0;
19812be7d22fSVladimir Kondratiev }
19822be7d22fSVladimir Kondratiev 
19832be7d22fSVladimir Kondratiev void wil6210_debugfs_remove(struct wil6210_priv *wil)
19842be7d22fSVladimir Kondratiev {
19852be7d22fSVladimir Kondratiev 	debugfs_remove_recursive(wil->debug);
19862be7d22fSVladimir Kondratiev 	wil->debug = NULL;
1987dc16427bSVladimir Kondratiev 
198894162666SLazar Alexei 	kfree(wil->dbg_data.data_arr);
198994162666SLazar Alexei 
1990dc16427bSVladimir Kondratiev 	/* free pmc memory without sending command to fw, as it will
1991dc16427bSVladimir Kondratiev 	 * be reset on the way down anyway
1992dc16427bSVladimir Kondratiev 	 */
1993dc16427bSVladimir Kondratiev 	wil_pmc_free(wil, false);
19942be7d22fSVladimir Kondratiev }
1995