xref: /linux/drivers/net/wireless/ath/wil6210/debugfs.c (revision 0c936b3c96337c3fd5ad4951ca7bdc54fa578a02)
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 */
33d98b8539SMaya Erez static u32 dbg_status_msg_index;
34d98b8539SMaya Erez /* 0..wil->num_rx_status_rings-1 for Rx, wil->tx_sring_idx for Tx */
35d98b8539SMaya Erez static u32 dbg_sring_index;
362be7d22fSVladimir Kondratiev 
37b7cde470SVladimir Kondratiev enum dbg_off_type {
38b7cde470SVladimir Kondratiev 	doff_u32 = 0,
39b7cde470SVladimir Kondratiev 	doff_x32 = 1,
40b7cde470SVladimir Kondratiev 	doff_ulong = 2,
41b7cde470SVladimir Kondratiev 	doff_io32 = 3,
4274997a53SLior David 	doff_u8 = 4
43b7cde470SVladimir Kondratiev };
44b7cde470SVladimir Kondratiev 
45b7cde470SVladimir Kondratiev /* offset to "wil" */
46b7cde470SVladimir Kondratiev struct dbg_off {
47b7cde470SVladimir Kondratiev 	const char *name;
48b7cde470SVladimir Kondratiev 	umode_t mode;
49b7cde470SVladimir Kondratiev 	ulong off;
50b7cde470SVladimir Kondratiev 	enum dbg_off_type type;
51b7cde470SVladimir Kondratiev };
52b7cde470SVladimir Kondratiev 
53d98b8539SMaya Erez static void wil_print_desc_edma(struct seq_file *s, struct wil6210_priv *wil,
54d98b8539SMaya Erez 				struct wil_ring *ring,
55d98b8539SMaya Erez 				char _s, char _h, int idx)
56d98b8539SMaya Erez {
57d98b8539SMaya Erez 	u8 num_of_descs;
58d98b8539SMaya Erez 	bool has_skb = false;
59d98b8539SMaya Erez 
60d98b8539SMaya Erez 	if (ring->is_rx) {
61d98b8539SMaya Erez 		struct wil_rx_enhanced_desc *rx_d =
62d98b8539SMaya Erez 			(struct wil_rx_enhanced_desc *)
63d98b8539SMaya Erez 			&ring->va[idx].rx.enhanced;
64d98b8539SMaya Erez 		u16 buff_id = le16_to_cpu(rx_d->mac.buff_id);
65d98b8539SMaya Erez 
66d98b8539SMaya Erez 		has_skb = wil->rx_buff_mgmt.buff_arr[buff_id].skb;
67d98b8539SMaya Erez 		seq_printf(s, "%c", (has_skb) ? _h : _s);
68d98b8539SMaya Erez 	} else {
69d98b8539SMaya Erez 		struct wil_tx_enhanced_desc *d =
70d98b8539SMaya Erez 			(struct wil_tx_enhanced_desc *)
71d98b8539SMaya Erez 			&ring->va[idx].tx.enhanced;
72d98b8539SMaya Erez 
73d98b8539SMaya Erez 		num_of_descs = (u8)d->mac.d[2];
74d98b8539SMaya Erez 		has_skb = ring->ctx[idx].skb;
75d98b8539SMaya Erez 		if (num_of_descs >= 1)
76d98b8539SMaya Erez 			seq_printf(s, "%c", ring->ctx[idx].skb ? _h : _s);
77d98b8539SMaya Erez 		else
78d98b8539SMaya Erez 			/* num_of_descs == 0, it's a frag in a list of descs */
79d98b8539SMaya Erez 			seq_printf(s, "%c", has_skb ? 'h' : _s);
80d98b8539SMaya Erez 	}
81d98b8539SMaya Erez }
82d98b8539SMaya Erez 
8310590c6aSGidon Studinski static void wil_print_ring(struct seq_file *s, struct wil6210_priv *wil,
8410590c6aSGidon Studinski 			   const char *name, struct wil_ring *ring,
8559f7c0a9SVladimir Kondratiev 			   char _s, char _h)
862be7d22fSVladimir Kondratiev {
8710590c6aSGidon Studinski 	void __iomem *x = wmi_addr(wil, ring->hwtail);
88995cdd0eSVladimir Kondratiev 	u32 v;
892be7d22fSVladimir Kondratiev 
9010590c6aSGidon Studinski 	seq_printf(s, "RING %s = {\n", name);
9110590c6aSGidon Studinski 	seq_printf(s, "  pa     = %pad\n", &ring->pa);
9210590c6aSGidon Studinski 	seq_printf(s, "  va     = 0x%p\n", ring->va);
9310590c6aSGidon Studinski 	seq_printf(s, "  size   = %d\n", ring->size);
94d98b8539SMaya Erez 	if (wil->use_enhanced_dma_hw && ring->is_rx)
95d98b8539SMaya Erez 		seq_printf(s, "  swtail = %u\n", *ring->edma_rx_swtail.va);
96d98b8539SMaya Erez 	else
9710590c6aSGidon Studinski 		seq_printf(s, "  swtail = %d\n", ring->swtail);
9810590c6aSGidon Studinski 	seq_printf(s, "  swhead = %d\n", ring->swhead);
9910590c6aSGidon Studinski 	seq_printf(s, "  hwtail = [0x%08x] -> ", ring->hwtail);
100995cdd0eSVladimir Kondratiev 	if (x) {
101b9eeb512SVladimir Kondratiev 		v = readl(x);
102995cdd0eSVladimir Kondratiev 		seq_printf(s, "0x%08x = %d\n", v, v);
103995cdd0eSVladimir Kondratiev 	} else {
1048fe59627SVladimir Kondratiev 		seq_puts(s, "???\n");
105995cdd0eSVladimir Kondratiev 	}
1062be7d22fSVladimir Kondratiev 
10710590c6aSGidon Studinski 	if (ring->va && (ring->size <= (1 << WIL_RING_SIZE_ORDER_MAX))) {
1082be7d22fSVladimir Kondratiev 		uint i;
1098fe59627SVladimir Kondratiev 
11010590c6aSGidon Studinski 		for (i = 0; i < ring->size; i++) {
111d98b8539SMaya Erez 			if ((i % 128) == 0 && i != 0)
112d98b8539SMaya Erez 				seq_puts(s, "\n");
113d98b8539SMaya Erez 			if (wil->use_enhanced_dma_hw) {
114d98b8539SMaya Erez 				wil_print_desc_edma(s, wil, ring, _s, _h, i);
115d98b8539SMaya Erez 			} else {
11610590c6aSGidon Studinski 				volatile struct vring_tx_desc *d =
11710590c6aSGidon Studinski 					&ring->va[i].tx.legacy;
11859f7c0a9SVladimir Kondratiev 				seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
11910590c6aSGidon Studinski 					   _s : (ring->ctx[i].skb ? _h : 'h'));
1202be7d22fSVladimir Kondratiev 			}
121d98b8539SMaya Erez 		}
1228fe59627SVladimir Kondratiev 		seq_puts(s, "\n");
1232be7d22fSVladimir Kondratiev 	}
1248fe59627SVladimir Kondratiev 	seq_puts(s, "}\n");
1252be7d22fSVladimir Kondratiev }
1262be7d22fSVladimir Kondratiev 
12710590c6aSGidon Studinski static int wil_ring_debugfs_show(struct seq_file *s, void *data)
1282be7d22fSVladimir Kondratiev {
1292be7d22fSVladimir Kondratiev 	uint i;
1302be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
1312be7d22fSVladimir Kondratiev 
13210590c6aSGidon Studinski 	wil_print_ring(s, wil, "rx", &wil->ring_rx, 'S', '_');
1332be7d22fSVladimir Kondratiev 
13410590c6aSGidon Studinski 	for (i = 0; i < ARRAY_SIZE(wil->ring_tx); i++) {
13510590c6aSGidon Studinski 		struct wil_ring *ring = &wil->ring_tx[i];
13610590c6aSGidon Studinski 		struct wil_ring_tx_data *txdata = &wil->ring_tx_data[i];
1377c0acf86SVladimir Kondratiev 
13810590c6aSGidon Studinski 		if (ring->va) {
13910590c6aSGidon Studinski 			int cid = wil->ring2cid_tid[i][0];
14010590c6aSGidon Studinski 			int tid = wil->ring2cid_tid[i][1];
14110590c6aSGidon Studinski 			u32 swhead = ring->swhead;
14210590c6aSGidon Studinski 			u32 swtail = ring->swtail;
14310590c6aSGidon Studinski 			int used = (ring->size + swhead - swtail)
14410590c6aSGidon Studinski 				   % ring->size;
14510590c6aSGidon Studinski 			int avail = ring->size - used - 1;
1462be7d22fSVladimir Kondratiev 			char name[10];
1478f55cbecSBoris Sorochkin 			char sidle[10];
1487c0acf86SVladimir Kondratiev 			/* performance monitoring */
1497c0acf86SVladimir Kondratiev 			cycles_t now = get_cycles();
150c20e7789SChen Gang 			uint64_t idle = txdata->idle * 100;
151c20e7789SChen Gang 			uint64_t total = now - txdata->begin;
1527c0acf86SVladimir Kondratiev 
1538f55cbecSBoris Sorochkin 			if (total != 0) {
154e48b1790SVladimir Kondratiev 				do_div(idle, total);
1558f55cbecSBoris Sorochkin 				snprintf(sidle, sizeof(sidle), "%3d%%",
1568f55cbecSBoris Sorochkin 					 (int)idle);
1578f55cbecSBoris Sorochkin 			} else {
1588f55cbecSBoris Sorochkin 				snprintf(sidle, sizeof(sidle), "N/A");
1598f55cbecSBoris Sorochkin 			}
1607c0acf86SVladimir Kondratiev 			txdata->begin = now;
1617c0acf86SVladimir Kondratiev 			txdata->idle = 0ULL;
1627c0acf86SVladimir Kondratiev 
1632be7d22fSVladimir Kondratiev 			snprintf(name, sizeof(name), "tx_%2d", i);
1643df2cd36SVladimir Kondratiev 
16541d6b093SVladimir Kondratiev 			if (cid < WIL6210_MAX_CID)
1663277213fSVladimir Kondratiev 				seq_printf(s,
167230d8442SVladimir Kondratiev 					   "\n%pM CID %d TID %d 1x%s BACK([%u] %u TU A%s) [%3d|%3d] idle %s\n",
1683277213fSVladimir Kondratiev 					   wil->sta[cid].addr, cid, tid,
169230d8442SVladimir Kondratiev 					   txdata->dot1x_open ? "+" : "-",
17041d6b093SVladimir Kondratiev 					   txdata->agg_wsize,
17141d6b093SVladimir Kondratiev 					   txdata->agg_timeout,
172cbcf5866SVladimir Kondratiev 					   txdata->agg_amsdu ? "+" : "-",
1738f55cbecSBoris Sorochkin 					   used, avail, sidle);
17441d6b093SVladimir Kondratiev 			else
17541d6b093SVladimir Kondratiev 				seq_printf(s,
176230d8442SVladimir Kondratiev 					   "\nBroadcast 1x%s [%3d|%3d] idle %s\n",
177230d8442SVladimir Kondratiev 					   txdata->dot1x_open ? "+" : "-",
17841d6b093SVladimir Kondratiev 					   used, avail, sidle);
1797c0acf86SVladimir Kondratiev 
18010590c6aSGidon Studinski 			wil_print_ring(s, wil, name, ring, '_', 'H');
1812be7d22fSVladimir Kondratiev 		}
1822be7d22fSVladimir Kondratiev 	}
1832be7d22fSVladimir Kondratiev 
1842be7d22fSVladimir Kondratiev 	return 0;
1852be7d22fSVladimir Kondratiev }
1862be7d22fSVladimir Kondratiev 
18710590c6aSGidon Studinski static int wil_ring_seq_open(struct inode *inode, struct file *file)
1882be7d22fSVladimir Kondratiev {
18910590c6aSGidon Studinski 	return single_open(file, wil_ring_debugfs_show, inode->i_private);
1902be7d22fSVladimir Kondratiev }
1912be7d22fSVladimir Kondratiev 
19210590c6aSGidon Studinski static const struct file_operations fops_ring = {
19310590c6aSGidon Studinski 	.open		= wil_ring_seq_open,
1942be7d22fSVladimir Kondratiev 	.release	= single_release,
1952be7d22fSVladimir Kondratiev 	.read		= seq_read,
1962be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
1972be7d22fSVladimir Kondratiev };
1982be7d22fSVladimir Kondratiev 
199d98b8539SMaya Erez static void wil_print_sring(struct seq_file *s, struct wil6210_priv *wil,
200d98b8539SMaya Erez 			    struct wil_status_ring *sring)
201d98b8539SMaya Erez {
202d98b8539SMaya Erez 	void __iomem *x = wmi_addr(wil, sring->hwtail);
203d98b8539SMaya Erez 	int sring_idx = sring - wil->srings;
204d98b8539SMaya Erez 	u32 v;
205d98b8539SMaya Erez 
206d98b8539SMaya Erez 	seq_printf(s, "Status Ring %s [ %d ] = {\n",
207d98b8539SMaya Erez 		   sring->is_rx ? "RX" : "TX", sring_idx);
208d98b8539SMaya Erez 	seq_printf(s, "  pa     = %pad\n", &sring->pa);
209d98b8539SMaya Erez 	seq_printf(s, "  va     = 0x%pK\n", sring->va);
210d98b8539SMaya Erez 	seq_printf(s, "  size   = %d\n", sring->size);
211d98b8539SMaya Erez 	seq_printf(s, "  elem_size   = %zu\n", sring->elem_size);
212d98b8539SMaya Erez 	seq_printf(s, "  swhead = %d\n", sring->swhead);
213d98b8539SMaya Erez 	seq_printf(s, "  hwtail = [0x%08x] -> ", sring->hwtail);
214d98b8539SMaya Erez 	if (x) {
215d98b8539SMaya Erez 		v = readl_relaxed(x);
216d98b8539SMaya Erez 		seq_printf(s, "0x%08x = %d\n", v, v);
217d98b8539SMaya Erez 	} else {
218d98b8539SMaya Erez 		seq_puts(s, "???\n");
219d98b8539SMaya Erez 	}
220d98b8539SMaya Erez 	seq_printf(s, "  desc_rdy_pol   = %d\n", sring->desc_rdy_pol);
221d98b8539SMaya Erez 
222d98b8539SMaya Erez 	if (sring->va && (sring->size <= (1 << WIL_RING_SIZE_ORDER_MAX))) {
223d98b8539SMaya Erez 		uint i;
224d98b8539SMaya Erez 
225d98b8539SMaya Erez 		for (i = 0; i < sring->size; i++) {
226d98b8539SMaya Erez 			u32 *sdword_0 =
227d98b8539SMaya Erez 				(u32 *)(sring->va + (sring->elem_size * i));
228d98b8539SMaya Erez 
229d98b8539SMaya Erez 			if ((i % 128) == 0 && i != 0)
230d98b8539SMaya Erez 				seq_puts(s, "\n");
231d98b8539SMaya Erez 			if (i == sring->swhead)
232d98b8539SMaya Erez 				seq_printf(s, "%c", (*sdword_0 & BIT(31)) ?
233d98b8539SMaya Erez 					   'X' : 'x');
234d98b8539SMaya Erez 			else
235d98b8539SMaya Erez 				seq_printf(s, "%c", (*sdword_0 & BIT(31)) ?
236d98b8539SMaya Erez 					   '1' : '0');
237d98b8539SMaya Erez 		}
238d98b8539SMaya Erez 		seq_puts(s, "\n");
239d98b8539SMaya Erez 	}
240d98b8539SMaya Erez 	seq_puts(s, "}\n");
241d98b8539SMaya Erez }
242d98b8539SMaya Erez 
243d98b8539SMaya Erez static int wil_srings_debugfs_show(struct seq_file *s, void *data)
244d98b8539SMaya Erez {
245d98b8539SMaya Erez 	struct wil6210_priv *wil = s->private;
246d98b8539SMaya Erez 	int i = 0;
247d98b8539SMaya Erez 
248d98b8539SMaya Erez 	for (i = 0; i < WIL6210_MAX_STATUS_RINGS; i++)
249d98b8539SMaya Erez 		if (wil->srings[i].va)
250d98b8539SMaya Erez 			wil_print_sring(s, wil, &wil->srings[i]);
251d98b8539SMaya Erez 
252d98b8539SMaya Erez 	return 0;
253d98b8539SMaya Erez }
254d98b8539SMaya Erez 
255d98b8539SMaya Erez static int wil_srings_seq_open(struct inode *inode, struct file *file)
256d98b8539SMaya Erez {
257d98b8539SMaya Erez 	return single_open(file, wil_srings_debugfs_show, inode->i_private);
258d98b8539SMaya Erez }
259d98b8539SMaya Erez 
260d98b8539SMaya Erez static const struct file_operations fops_srings = {
261d98b8539SMaya Erez 	.open		= wil_srings_seq_open,
262d98b8539SMaya Erez 	.release	= single_release,
263d98b8539SMaya Erez 	.read		= seq_read,
264d98b8539SMaya Erez 	.llseek		= seq_lseek,
265d98b8539SMaya Erez };
266d98b8539SMaya Erez 
267a202fbbfSAndy Shevchenko static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
268a202fbbfSAndy Shevchenko 			    const char *prefix)
269a202fbbfSAndy Shevchenko {
270a202fbbfSAndy Shevchenko 	seq_hex_dump(s, prefix, DUMP_PREFIX_NONE, 16, 1, p, len, false);
271a202fbbfSAndy Shevchenko }
272a202fbbfSAndy Shevchenko 
27310590c6aSGidon Studinski static void wil_print_mbox_ring(struct seq_file *s, const char *prefix,
2742be7d22fSVladimir Kondratiev 				void __iomem *off)
2752be7d22fSVladimir Kondratiev {
2762be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
2772be7d22fSVladimir Kondratiev 	struct wil6210_mbox_ring r;
2782be7d22fSVladimir Kondratiev 	int rsize;
2792be7d22fSVladimir Kondratiev 	uint i;
2802be7d22fSVladimir Kondratiev 
281349214c1SMaya Erez 	wil_halp_vote(wil);
282349214c1SMaya Erez 
2832be7d22fSVladimir Kondratiev 	wil_memcpy_fromio_32(&r, off, sizeof(r));
2842be7d22fSVladimir Kondratiev 	wil_mbox_ring_le2cpus(&r);
2852be7d22fSVladimir Kondratiev 	/*
2862be7d22fSVladimir Kondratiev 	 * we just read memory block from NIC. This memory may be
2872be7d22fSVladimir Kondratiev 	 * garbage. Check validity before using it.
2882be7d22fSVladimir Kondratiev 	 */
2892be7d22fSVladimir Kondratiev 	rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
2902be7d22fSVladimir Kondratiev 
2912be7d22fSVladimir Kondratiev 	seq_printf(s, "ring %s = {\n", prefix);
2922be7d22fSVladimir Kondratiev 	seq_printf(s, "  base = 0x%08x\n", r.base);
2932be7d22fSVladimir Kondratiev 	seq_printf(s, "  size = 0x%04x bytes -> %d entries\n", r.size, rsize);
2942be7d22fSVladimir Kondratiev 	seq_printf(s, "  tail = 0x%08x\n", r.tail);
2952be7d22fSVladimir Kondratiev 	seq_printf(s, "  head = 0x%08x\n", r.head);
2962be7d22fSVladimir Kondratiev 	seq_printf(s, "  entry size = %d\n", r.entry_size);
2972be7d22fSVladimir Kondratiev 
2982be7d22fSVladimir Kondratiev 	if (r.size % sizeof(struct wil6210_mbox_ring_desc)) {
2992be7d22fSVladimir Kondratiev 		seq_printf(s, "  ??? size is not multiple of %zd, garbage?\n",
3002be7d22fSVladimir Kondratiev 			   sizeof(struct wil6210_mbox_ring_desc));
3012be7d22fSVladimir Kondratiev 		goto out;
3022be7d22fSVladimir Kondratiev 	}
3032be7d22fSVladimir Kondratiev 
3042be7d22fSVladimir Kondratiev 	if (!wmi_addr(wil, r.base) ||
3052be7d22fSVladimir Kondratiev 	    !wmi_addr(wil, r.tail) ||
3062be7d22fSVladimir Kondratiev 	    !wmi_addr(wil, r.head)) {
3078fe59627SVladimir Kondratiev 		seq_puts(s, "  ??? pointers are garbage?\n");
3082be7d22fSVladimir Kondratiev 		goto out;
3092be7d22fSVladimir Kondratiev 	}
3102be7d22fSVladimir Kondratiev 
3112be7d22fSVladimir Kondratiev 	for (i = 0; i < rsize; i++) {
3122be7d22fSVladimir Kondratiev 		struct wil6210_mbox_ring_desc d;
3132be7d22fSVladimir Kondratiev 		struct wil6210_mbox_hdr hdr;
3142be7d22fSVladimir Kondratiev 		size_t delta = i * sizeof(d);
3152be7d22fSVladimir Kondratiev 		void __iomem *x = wil->csr + HOSTADDR(r.base) + delta;
3162be7d22fSVladimir Kondratiev 
3172be7d22fSVladimir Kondratiev 		wil_memcpy_fromio_32(&d, x, sizeof(d));
3182be7d22fSVladimir Kondratiev 
3192be7d22fSVladimir Kondratiev 		seq_printf(s, "  [%2x] %s %s%s 0x%08x", i,
3202be7d22fSVladimir Kondratiev 			   d.sync ? "F" : "E",
3212be7d22fSVladimir Kondratiev 			   (r.tail - r.base == delta) ? "t" : " ",
3222be7d22fSVladimir Kondratiev 			   (r.head - r.base == delta) ? "h" : " ",
3232be7d22fSVladimir Kondratiev 			   le32_to_cpu(d.addr));
3242be7d22fSVladimir Kondratiev 		if (0 == wmi_read_hdr(wil, d.addr, &hdr)) {
3252be7d22fSVladimir Kondratiev 			u16 len = le16_to_cpu(hdr.len);
3268fe59627SVladimir Kondratiev 
3272be7d22fSVladimir Kondratiev 			seq_printf(s, " -> %04x %04x %04x %02x\n",
3282be7d22fSVladimir Kondratiev 				   le16_to_cpu(hdr.seq), len,
3292be7d22fSVladimir Kondratiev 				   le16_to_cpu(hdr.type), hdr.flags);
3302be7d22fSVladimir Kondratiev 			if (len <= MAX_MBOXITEM_SIZE) {
3312be7d22fSVladimir Kondratiev 				unsigned char databuf[MAX_MBOXITEM_SIZE];
3322be7d22fSVladimir Kondratiev 				void __iomem *src = wmi_buffer(wil, d.addr) +
3332be7d22fSVladimir Kondratiev 					sizeof(struct wil6210_mbox_hdr);
3342be7d22fSVladimir Kondratiev 				/*
3352be7d22fSVladimir Kondratiev 				 * No need to check @src for validity -
3362be7d22fSVladimir Kondratiev 				 * we already validated @d.addr while
3372be7d22fSVladimir Kondratiev 				 * reading header
3382be7d22fSVladimir Kondratiev 				 */
3392be7d22fSVladimir Kondratiev 				wil_memcpy_fromio_32(databuf, src, len);
340a202fbbfSAndy Shevchenko 				wil_seq_hexdump(s, databuf, len, "      : ");
3412be7d22fSVladimir Kondratiev 			}
3422be7d22fSVladimir Kondratiev 		} else {
3438fe59627SVladimir Kondratiev 			seq_puts(s, "\n");
3442be7d22fSVladimir Kondratiev 		}
3452be7d22fSVladimir Kondratiev 	}
3462be7d22fSVladimir Kondratiev  out:
3478fe59627SVladimir Kondratiev 	seq_puts(s, "}\n");
348349214c1SMaya Erez 	wil_halp_unvote(wil);
3492be7d22fSVladimir Kondratiev }
3502be7d22fSVladimir Kondratiev 
3512be7d22fSVladimir Kondratiev static int wil_mbox_debugfs_show(struct seq_file *s, void *data)
3522be7d22fSVladimir Kondratiev {
3532be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
35494162666SLazar Alexei 	int ret;
35594162666SLazar Alexei 
35694162666SLazar Alexei 	ret = wil_pm_runtime_get(wil);
35794162666SLazar Alexei 	if (ret < 0)
35894162666SLazar Alexei 		return ret;
3592be7d22fSVladimir Kondratiev 
36010590c6aSGidon Studinski 	wil_print_mbox_ring(s, "tx", wil->csr + HOST_MBOX +
3612be7d22fSVladimir Kondratiev 		       offsetof(struct wil6210_mbox_ctl, tx));
36210590c6aSGidon Studinski 	wil_print_mbox_ring(s, "rx", wil->csr + HOST_MBOX +
3632be7d22fSVladimir Kondratiev 		       offsetof(struct wil6210_mbox_ctl, rx));
3642be7d22fSVladimir Kondratiev 
36594162666SLazar Alexei 	wil_pm_runtime_put(wil);
36694162666SLazar Alexei 
3672be7d22fSVladimir Kondratiev 	return 0;
3682be7d22fSVladimir Kondratiev }
3692be7d22fSVladimir Kondratiev 
3702be7d22fSVladimir Kondratiev static int wil_mbox_seq_open(struct inode *inode, struct file *file)
3712be7d22fSVladimir Kondratiev {
3722be7d22fSVladimir Kondratiev 	return single_open(file, wil_mbox_debugfs_show, inode->i_private);
3732be7d22fSVladimir Kondratiev }
3742be7d22fSVladimir Kondratiev 
3752be7d22fSVladimir Kondratiev static const struct file_operations fops_mbox = {
3762be7d22fSVladimir Kondratiev 	.open		= wil_mbox_seq_open,
3772be7d22fSVladimir Kondratiev 	.release	= single_release,
3782be7d22fSVladimir Kondratiev 	.read		= seq_read,
3792be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
3802be7d22fSVladimir Kondratiev };
3812be7d22fSVladimir Kondratiev 
3822be7d22fSVladimir Kondratiev static int wil_debugfs_iomem_x32_set(void *data, u64 val)
3832be7d22fSVladimir Kondratiev {
38494162666SLazar Alexei 	struct wil_debugfs_iomem_data *d = (struct
38594162666SLazar Alexei 					    wil_debugfs_iomem_data *)data;
38694162666SLazar Alexei 	struct wil6210_priv *wil = d->wil;
38794162666SLazar Alexei 	int ret;
38894162666SLazar Alexei 
38994162666SLazar Alexei 	ret = wil_pm_runtime_get(wil);
39094162666SLazar Alexei 	if (ret < 0)
39194162666SLazar Alexei 		return ret;
39294162666SLazar Alexei 
39394162666SLazar Alexei 	writel(val, (void __iomem *)d->offset);
3942be7d22fSVladimir Kondratiev 	wmb(); /* make sure write propagated to HW */
3952be7d22fSVladimir Kondratiev 
39694162666SLazar Alexei 	wil_pm_runtime_put(wil);
39794162666SLazar Alexei 
3982be7d22fSVladimir Kondratiev 	return 0;
3992be7d22fSVladimir Kondratiev }
4002be7d22fSVladimir Kondratiev 
4012be7d22fSVladimir Kondratiev static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
4022be7d22fSVladimir Kondratiev {
40394162666SLazar Alexei 	struct wil_debugfs_iomem_data *d = (struct
40494162666SLazar Alexei 					    wil_debugfs_iomem_data *)data;
40594162666SLazar Alexei 	struct wil6210_priv *wil = d->wil;
40694162666SLazar Alexei 	int ret;
40794162666SLazar Alexei 
40894162666SLazar Alexei 	ret = wil_pm_runtime_get(wil);
40994162666SLazar Alexei 	if (ret < 0)
41094162666SLazar Alexei 		return ret;
41194162666SLazar Alexei 
41294162666SLazar Alexei 	*val = readl((void __iomem *)d->offset);
41394162666SLazar Alexei 
41494162666SLazar Alexei 	wil_pm_runtime_put(wil);
4152be7d22fSVladimir Kondratiev 
4162be7d22fSVladimir Kondratiev 	return 0;
4172be7d22fSVladimir Kondratiev }
4182be7d22fSVladimir Kondratiev 
4192be7d22fSVladimir Kondratiev DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
4202be7d22fSVladimir Kondratiev 			wil_debugfs_iomem_x32_set, "0x%08llx\n");
4212be7d22fSVladimir Kondratiev 
4222be7d22fSVladimir Kondratiev static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
4230ecc833bSAl Viro 						   umode_t mode,
4242be7d22fSVladimir Kondratiev 						   struct dentry *parent,
42594162666SLazar Alexei 						   void *value,
42694162666SLazar Alexei 						   struct wil6210_priv *wil)
4272be7d22fSVladimir Kondratiev {
42894162666SLazar Alexei 	struct dentry *file;
42994162666SLazar Alexei 	struct wil_debugfs_iomem_data *data = &wil->dbg_data.data_arr[
43094162666SLazar Alexei 					      wil->dbg_data.iomem_data_count];
43194162666SLazar Alexei 
43294162666SLazar Alexei 	data->wil = wil;
43394162666SLazar Alexei 	data->offset = value;
43494162666SLazar Alexei 
43594162666SLazar Alexei 	file = debugfs_create_file(name, mode, parent, data, &fops_iomem_x32);
43694162666SLazar Alexei 	if (!IS_ERR_OR_NULL(file))
43794162666SLazar Alexei 		wil->dbg_data.iomem_data_count++;
43894162666SLazar Alexei 
43994162666SLazar Alexei 	return file;
4402be7d22fSVladimir Kondratiev }
4412be7d22fSVladimir Kondratiev 
4423de6cf20SVladimir Kondratiev static int wil_debugfs_ulong_set(void *data, u64 val)
4433de6cf20SVladimir Kondratiev {
4443de6cf20SVladimir Kondratiev 	*(ulong *)data = val;
4453de6cf20SVladimir Kondratiev 	return 0;
4463de6cf20SVladimir Kondratiev }
4478fe59627SVladimir Kondratiev 
4483de6cf20SVladimir Kondratiev static int wil_debugfs_ulong_get(void *data, u64 *val)
4493de6cf20SVladimir Kondratiev {
4503de6cf20SVladimir Kondratiev 	*val = *(ulong *)data;
4513de6cf20SVladimir Kondratiev 	return 0;
4523de6cf20SVladimir Kondratiev }
4538fe59627SVladimir Kondratiev 
4543de6cf20SVladimir Kondratiev DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
4558ea06188SVladimir Kondratiev 			wil_debugfs_ulong_set, "0x%llx\n");
4563de6cf20SVladimir Kondratiev 
4573de6cf20SVladimir Kondratiev static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode,
4583de6cf20SVladimir Kondratiev 					       struct dentry *parent,
4593de6cf20SVladimir Kondratiev 					       ulong *value)
4603de6cf20SVladimir Kondratiev {
4613de6cf20SVladimir Kondratiev 	return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong);
4623de6cf20SVladimir Kondratiev }
4633de6cf20SVladimir Kondratiev 
464b7cde470SVladimir Kondratiev /**
465b7cde470SVladimir Kondratiev  * wil6210_debugfs_init_offset - create set of debugfs files
466b7cde470SVladimir Kondratiev  * @wil - driver's context, used for printing
467b7cde470SVladimir Kondratiev  * @dbg - directory on the debugfs, where files will be created
468b7cde470SVladimir Kondratiev  * @base - base address used in address calculation
469b7cde470SVladimir Kondratiev  * @tbl - table with file descriptions. Should be terminated with empty element.
470b7cde470SVladimir Kondratiev  *
471b7cde470SVladimir Kondratiev  * Creates files accordingly to the @tbl.
472b7cde470SVladimir Kondratiev  */
473b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_offset(struct wil6210_priv *wil,
474b7cde470SVladimir Kondratiev 					struct dentry *dbg, void *base,
475b7cde470SVladimir Kondratiev 					const struct dbg_off * const tbl)
476b7cde470SVladimir Kondratiev {
477b7cde470SVladimir Kondratiev 	int i;
478b7cde470SVladimir Kondratiev 
479b7cde470SVladimir Kondratiev 	for (i = 0; tbl[i].name; i++) {
480867fa0d4SVladimir Kondratiev 		struct dentry *f;
481b7cde470SVladimir Kondratiev 
482b7cde470SVladimir Kondratiev 		switch (tbl[i].type) {
483b7cde470SVladimir Kondratiev 		case doff_u32:
484b7cde470SVladimir Kondratiev 			f = debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg,
485b7cde470SVladimir Kondratiev 					       base + tbl[i].off);
486b7cde470SVladimir Kondratiev 			break;
487b7cde470SVladimir Kondratiev 		case doff_x32:
488b7cde470SVladimir Kondratiev 			f = debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg,
489b7cde470SVladimir Kondratiev 					       base + tbl[i].off);
490b7cde470SVladimir Kondratiev 			break;
491b7cde470SVladimir Kondratiev 		case doff_ulong:
492b7cde470SVladimir Kondratiev 			f = wil_debugfs_create_ulong(tbl[i].name, tbl[i].mode,
493b7cde470SVladimir Kondratiev 						     dbg, base + tbl[i].off);
494b7cde470SVladimir Kondratiev 			break;
495b7cde470SVladimir Kondratiev 		case doff_io32:
496b7cde470SVladimir Kondratiev 			f = wil_debugfs_create_iomem_x32(tbl[i].name,
497b7cde470SVladimir Kondratiev 							 tbl[i].mode, dbg,
49894162666SLazar Alexei 							 base + tbl[i].off,
49994162666SLazar Alexei 							 wil);
500b7cde470SVladimir Kondratiev 			break;
50174997a53SLior David 		case doff_u8:
50274997a53SLior David 			f = debugfs_create_u8(tbl[i].name, tbl[i].mode, dbg,
50374997a53SLior David 					      base + tbl[i].off);
50474997a53SLior David 			break;
505867fa0d4SVladimir Kondratiev 		default:
506867fa0d4SVladimir Kondratiev 			f = ERR_PTR(-EINVAL);
507b7cde470SVladimir Kondratiev 		}
508b7cde470SVladimir Kondratiev 		if (IS_ERR_OR_NULL(f))
509b7cde470SVladimir Kondratiev 			wil_err(wil, "Create file \"%s\": err %ld\n",
510b7cde470SVladimir Kondratiev 				tbl[i].name, PTR_ERR(f));
511b7cde470SVladimir Kondratiev 	}
512b7cde470SVladimir Kondratiev }
513b7cde470SVladimir Kondratiev 
514b7cde470SVladimir Kondratiev static const struct dbg_off isr_off[] = {
51578484c44SMaya Erez 	{"ICC", 0644, offsetof(struct RGF_ICR, ICC), doff_io32},
51678484c44SMaya Erez 	{"ICR", 0644, offsetof(struct RGF_ICR, ICR), doff_io32},
51778484c44SMaya Erez 	{"ICM", 0644, offsetof(struct RGF_ICR, ICM), doff_io32},
51878484c44SMaya Erez 	{"ICS",	0244, offsetof(struct RGF_ICR, ICS), doff_io32},
51978484c44SMaya Erez 	{"IMV", 0644, offsetof(struct RGF_ICR, IMV), doff_io32},
52078484c44SMaya Erez 	{"IMS",	0244, offsetof(struct RGF_ICR, IMS), doff_io32},
52178484c44SMaya Erez 	{"IMC",	0244, offsetof(struct RGF_ICR, IMC), doff_io32},
522b7cde470SVladimir Kondratiev 	{},
523b7cde470SVladimir Kondratiev };
5248fe59627SVladimir Kondratiev 
5252be7d22fSVladimir Kondratiev static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
5262be7d22fSVladimir Kondratiev 				      const char *name,
5272be7d22fSVladimir Kondratiev 				      struct dentry *parent, u32 off)
5282be7d22fSVladimir Kondratiev {
5292be7d22fSVladimir Kondratiev 	struct dentry *d = debugfs_create_dir(name, parent);
5302be7d22fSVladimir Kondratiev 
5312be7d22fSVladimir Kondratiev 	if (IS_ERR_OR_NULL(d))
5322be7d22fSVladimir Kondratiev 		return -ENODEV;
5332be7d22fSVladimir Kondratiev 
534b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off,
535b7cde470SVladimir Kondratiev 				    isr_off);
5362be7d22fSVladimir Kondratiev 
5372be7d22fSVladimir Kondratiev 	return 0;
5382be7d22fSVladimir Kondratiev }
5392be7d22fSVladimir Kondratiev 
540b7cde470SVladimir Kondratiev static const struct dbg_off pseudo_isr_off[] = {
54178484c44SMaya Erez 	{"CAUSE",   0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32},
54278484c44SMaya Erez 	{"MASK_SW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32},
54378484c44SMaya Erez 	{"MASK_FW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32},
544b7cde470SVladimir Kondratiev 	{},
545b7cde470SVladimir Kondratiev };
546b7cde470SVladimir Kondratiev 
5472be7d22fSVladimir Kondratiev static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
5482be7d22fSVladimir Kondratiev 					     struct dentry *parent)
5492be7d22fSVladimir Kondratiev {
5502be7d22fSVladimir Kondratiev 	struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
5512be7d22fSVladimir Kondratiev 
5522be7d22fSVladimir Kondratiev 	if (IS_ERR_OR_NULL(d))
5532be7d22fSVladimir Kondratiev 		return -ENODEV;
5542be7d22fSVladimir Kondratiev 
555b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
556b7cde470SVladimir Kondratiev 				    pseudo_isr_off);
5572be7d22fSVladimir Kondratiev 
5582be7d22fSVladimir Kondratiev 	return 0;
5592be7d22fSVladimir Kondratiev }
5602be7d22fSVladimir Kondratiev 
56178366f69SVladimir Kondratiev static const struct dbg_off lgc_itr_cnt_off[] = {
56278484c44SMaya Erez 	{"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32},
56378484c44SMaya Erez 	{"DATA", 0644, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32},
56478484c44SMaya Erez 	{"CTL",  0644, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32},
565b7cde470SVladimir Kondratiev 	{},
566b7cde470SVladimir Kondratiev };
567b7cde470SVladimir Kondratiev 
56878366f69SVladimir Kondratiev static const struct dbg_off tx_itr_cnt_off[] = {
56978484c44SMaya Erez 	{"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_TRSH),
57078366f69SVladimir Kondratiev 	 doff_io32},
57178484c44SMaya Erez 	{"DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_DATA),
57278366f69SVladimir Kondratiev 	 doff_io32},
57378484c44SMaya Erez 	{"CTL",  0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_CTL),
57478366f69SVladimir Kondratiev 	 doff_io32},
57578484c44SMaya Erez 	{"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_TRSH),
57678366f69SVladimir Kondratiev 	 doff_io32},
57778484c44SMaya Erez 	{"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_DATA),
57878366f69SVladimir Kondratiev 	 doff_io32},
57978484c44SMaya Erez 	{"IDL_CTL",  0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_CTL),
58078366f69SVladimir Kondratiev 	 doff_io32},
58178366f69SVladimir Kondratiev 	{},
58278366f69SVladimir Kondratiev };
58378366f69SVladimir Kondratiev 
58478366f69SVladimir Kondratiev static const struct dbg_off rx_itr_cnt_off[] = {
58578484c44SMaya Erez 	{"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_TRSH),
58678366f69SVladimir Kondratiev 	 doff_io32},
58778484c44SMaya Erez 	{"DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_DATA),
58878366f69SVladimir Kondratiev 	 doff_io32},
58978484c44SMaya Erez 	{"CTL",  0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_CTL),
59078366f69SVladimir Kondratiev 	 doff_io32},
59178484c44SMaya Erez 	{"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_TRSH),
59278366f69SVladimir Kondratiev 	 doff_io32},
59378484c44SMaya Erez 	{"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_DATA),
59478366f69SVladimir Kondratiev 	 doff_io32},
59578484c44SMaya Erez 	{"IDL_CTL",  0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_CTL),
59678366f69SVladimir Kondratiev 	 doff_io32},
59778366f69SVladimir Kondratiev 	{},
59878366f69SVladimir Kondratiev };
59978366f69SVladimir Kondratiev 
6002be7d22fSVladimir Kondratiev static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
6012be7d22fSVladimir Kondratiev 					  struct dentry *parent)
6022be7d22fSVladimir Kondratiev {
60378366f69SVladimir Kondratiev 	struct dentry *d, *dtx, *drx;
6042be7d22fSVladimir Kondratiev 
60578366f69SVladimir Kondratiev 	d = debugfs_create_dir("ITR_CNT", parent);
6062be7d22fSVladimir Kondratiev 	if (IS_ERR_OR_NULL(d))
6072be7d22fSVladimir Kondratiev 		return -ENODEV;
6082be7d22fSVladimir Kondratiev 
60978366f69SVladimir Kondratiev 	dtx = debugfs_create_dir("TX", d);
61078366f69SVladimir Kondratiev 	drx = debugfs_create_dir("RX", d);
61178366f69SVladimir Kondratiev 	if (IS_ERR_OR_NULL(dtx) || IS_ERR_OR_NULL(drx))
61278366f69SVladimir Kondratiev 		return -ENODEV;
6132be7d22fSVladimir Kondratiev 
61478366f69SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
61578366f69SVladimir Kondratiev 				    lgc_itr_cnt_off);
61678366f69SVladimir Kondratiev 
61778366f69SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, dtx, (void * __force)wil->csr,
61878366f69SVladimir Kondratiev 				    tx_itr_cnt_off);
61978366f69SVladimir Kondratiev 
62078366f69SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, drx, (void * __force)wil->csr,
62178366f69SVladimir Kondratiev 				    rx_itr_cnt_off);
6222be7d22fSVladimir Kondratiev 	return 0;
6232be7d22fSVladimir Kondratiev }
6242be7d22fSVladimir Kondratiev 
6252be7d22fSVladimir Kondratiev static int wil_memread_debugfs_show(struct seq_file *s, void *data)
6262be7d22fSVladimir Kondratiev {
6272be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
62894162666SLazar Alexei 	void __iomem *a;
62994162666SLazar Alexei 	int ret;
63094162666SLazar Alexei 
63194162666SLazar Alexei 	ret = wil_pm_runtime_get(wil);
63294162666SLazar Alexei 	if (ret < 0)
63394162666SLazar Alexei 		return ret;
63494162666SLazar Alexei 
63594162666SLazar Alexei 	a = wmi_buffer(wil, cpu_to_le32(mem_addr));
6362be7d22fSVladimir Kondratiev 
6372be7d22fSVladimir Kondratiev 	if (a)
638b9eeb512SVladimir Kondratiev 		seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, readl(a));
6392be7d22fSVladimir Kondratiev 	else
6402be7d22fSVladimir Kondratiev 		seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
6412be7d22fSVladimir Kondratiev 
64294162666SLazar Alexei 	wil_pm_runtime_put(wil);
64394162666SLazar Alexei 
6442be7d22fSVladimir Kondratiev 	return 0;
6452be7d22fSVladimir Kondratiev }
6462be7d22fSVladimir Kondratiev 
6472be7d22fSVladimir Kondratiev static int wil_memread_seq_open(struct inode *inode, struct file *file)
6482be7d22fSVladimir Kondratiev {
6492be7d22fSVladimir Kondratiev 	return single_open(file, wil_memread_debugfs_show, inode->i_private);
6502be7d22fSVladimir Kondratiev }
6512be7d22fSVladimir Kondratiev 
6522be7d22fSVladimir Kondratiev static const struct file_operations fops_memread = {
6532be7d22fSVladimir Kondratiev 	.open		= wil_memread_seq_open,
6542be7d22fSVladimir Kondratiev 	.release	= single_release,
6552be7d22fSVladimir Kondratiev 	.read		= seq_read,
6562be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
6572be7d22fSVladimir Kondratiev };
6582be7d22fSVladimir Kondratiev 
6592be7d22fSVladimir Kondratiev static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
6602be7d22fSVladimir Kondratiev 				    size_t count, loff_t *ppos)
6612be7d22fSVladimir Kondratiev {
6622be7d22fSVladimir Kondratiev 	enum { max_count = 4096 };
663349214c1SMaya Erez 	struct wil_blob_wrapper *wil_blob = file->private_data;
66494162666SLazar Alexei 	struct wil6210_priv *wil = wil_blob->wil;
6652be7d22fSVladimir Kondratiev 	loff_t pos = *ppos;
666349214c1SMaya Erez 	size_t available = wil_blob->blob.size;
6672be7d22fSVladimir Kondratiev 	void *buf;
6682be7d22fSVladimir Kondratiev 	size_t ret;
66994162666SLazar Alexei 	int rc;
6702be7d22fSVladimir Kondratiev 
671fe9ee51eSMaya Erez 	if (test_bit(wil_status_suspending, wil_blob->wil->status) ||
672fe9ee51eSMaya Erez 	    test_bit(wil_status_suspended, wil_blob->wil->status))
673fe9ee51eSMaya Erez 		return 0;
674fe9ee51eSMaya Erez 
6752be7d22fSVladimir Kondratiev 	if (pos < 0)
6762be7d22fSVladimir Kondratiev 		return -EINVAL;
6772be7d22fSVladimir Kondratiev 
6782be7d22fSVladimir Kondratiev 	if (pos >= available || !count)
6792be7d22fSVladimir Kondratiev 		return 0;
6802be7d22fSVladimir Kondratiev 
6812be7d22fSVladimir Kondratiev 	if (count > available - pos)
6822be7d22fSVladimir Kondratiev 		count = available - pos;
6832be7d22fSVladimir Kondratiev 	if (count > max_count)
6842be7d22fSVladimir Kondratiev 		count = max_count;
6852be7d22fSVladimir Kondratiev 
6862be7d22fSVladimir Kondratiev 	buf = kmalloc(count, GFP_KERNEL);
6872be7d22fSVladimir Kondratiev 	if (!buf)
6882be7d22fSVladimir Kondratiev 		return -ENOMEM;
6892be7d22fSVladimir Kondratiev 
69094162666SLazar Alexei 	rc = wil_pm_runtime_get(wil);
69194162666SLazar Alexei 	if (rc < 0) {
69294162666SLazar Alexei 		kfree(buf);
69394162666SLazar Alexei 		return rc;
69494162666SLazar Alexei 	}
69594162666SLazar Alexei 
696bd50e268SMaya Erez 	wil_memcpy_fromio_32(buf, (const void __iomem *)
697349214c1SMaya Erez 			     wil_blob->blob.data + pos, count);
6982be7d22fSVladimir Kondratiev 
6992be7d22fSVladimir Kondratiev 	ret = copy_to_user(user_buf, buf, count);
70094162666SLazar Alexei 
70194162666SLazar Alexei 	wil_pm_runtime_put(wil);
70294162666SLazar Alexei 
7032be7d22fSVladimir Kondratiev 	kfree(buf);
7042be7d22fSVladimir Kondratiev 	if (ret == count)
7052be7d22fSVladimir Kondratiev 		return -EFAULT;
7062be7d22fSVladimir Kondratiev 
7072be7d22fSVladimir Kondratiev 	count -= ret;
7082be7d22fSVladimir Kondratiev 	*ppos = pos + count;
7092be7d22fSVladimir Kondratiev 
7102be7d22fSVladimir Kondratiev 	return count;
7112be7d22fSVladimir Kondratiev }
7122be7d22fSVladimir Kondratiev 
7132be7d22fSVladimir Kondratiev static const struct file_operations fops_ioblob = {
7142be7d22fSVladimir Kondratiev 	.read =		wil_read_file_ioblob,
71593ecbd64SWei Yongjun 	.open =		simple_open,
7162be7d22fSVladimir Kondratiev 	.llseek =	default_llseek,
7172be7d22fSVladimir Kondratiev };
7182be7d22fSVladimir Kondratiev 
7192be7d22fSVladimir Kondratiev static
7202be7d22fSVladimir Kondratiev struct dentry *wil_debugfs_create_ioblob(const char *name,
7210ecc833bSAl Viro 					 umode_t mode,
7222be7d22fSVladimir Kondratiev 					 struct dentry *parent,
723349214c1SMaya Erez 					 struct wil_blob_wrapper *wil_blob)
7242be7d22fSVladimir Kondratiev {
725349214c1SMaya Erez 	return debugfs_create_file(name, mode, parent, wil_blob, &fops_ioblob);
7262be7d22fSVladimir Kondratiev }
7278fe59627SVladimir Kondratiev 
7282be7d22fSVladimir Kondratiev /*---reset---*/
7292be7d22fSVladimir Kondratiev static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
7302be7d22fSVladimir Kondratiev 				    size_t len, loff_t *ppos)
7312be7d22fSVladimir Kondratiev {
7322be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
733e00243faSLior David 	struct net_device *ndev = wil->main_ndev;
7342be7d22fSVladimir Kondratiev 
7352be7d22fSVladimir Kondratiev 	/**
7362be7d22fSVladimir Kondratiev 	 * BUG:
7372be7d22fSVladimir Kondratiev 	 * this code does NOT sync device state with the rest of system
7382be7d22fSVladimir Kondratiev 	 * use with care, debug only!!!
7392be7d22fSVladimir Kondratiev 	 */
7402be7d22fSVladimir Kondratiev 	rtnl_lock();
7412be7d22fSVladimir Kondratiev 	dev_close(ndev);
7422be7d22fSVladimir Kondratiev 	ndev->flags &= ~IFF_UP;
7432be7d22fSVladimir Kondratiev 	rtnl_unlock();
7442cd0f021SVladimir Kondratiev 	wil_reset(wil, true);
7452be7d22fSVladimir Kondratiev 
7462be7d22fSVladimir Kondratiev 	return len;
7472be7d22fSVladimir Kondratiev }
7482be7d22fSVladimir Kondratiev 
7492be7d22fSVladimir Kondratiev static const struct file_operations fops_reset = {
7502be7d22fSVladimir Kondratiev 	.write = wil_write_file_reset,
75193ecbd64SWei Yongjun 	.open  = simple_open,
7522be7d22fSVladimir Kondratiev };
7538fe59627SVladimir Kondratiev 
7540b39aaf2SVladimir Kondratiev /*---write channel 1..4 to rxon for it, 0 to rxoff---*/
7550b39aaf2SVladimir Kondratiev static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
7560b39aaf2SVladimir Kondratiev 				   size_t len, loff_t *ppos)
7570b39aaf2SVladimir Kondratiev {
7580b39aaf2SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
7590b39aaf2SVladimir Kondratiev 	int rc;
7600b39aaf2SVladimir Kondratiev 	long channel;
7610b39aaf2SVladimir Kondratiev 	bool on;
7620b39aaf2SVladimir Kondratiev 
76316e5c1fcSAl Viro 	char *kbuf = memdup_user_nul(buf, len);
7648fe59627SVladimir Kondratiev 
76516e5c1fcSAl Viro 	if (IS_ERR(kbuf))
76616e5c1fcSAl Viro 		return PTR_ERR(kbuf);
7670b39aaf2SVladimir Kondratiev 	rc = kstrtol(kbuf, 0, &channel);
7680b39aaf2SVladimir Kondratiev 	kfree(kbuf);
7690b39aaf2SVladimir Kondratiev 	if (rc)
7700b39aaf2SVladimir Kondratiev 		return rc;
7710b39aaf2SVladimir Kondratiev 
7720b39aaf2SVladimir Kondratiev 	if ((channel < 0) || (channel > 4)) {
7730b39aaf2SVladimir Kondratiev 		wil_err(wil, "Invalid channel %ld\n", channel);
7740b39aaf2SVladimir Kondratiev 		return -EINVAL;
7750b39aaf2SVladimir Kondratiev 	}
7760b39aaf2SVladimir Kondratiev 	on = !!channel;
7770b39aaf2SVladimir Kondratiev 
7780b39aaf2SVladimir Kondratiev 	if (on) {
7790b39aaf2SVladimir Kondratiev 		rc = wmi_set_channel(wil, (int)channel);
7800b39aaf2SVladimir Kondratiev 		if (rc)
7810b39aaf2SVladimir Kondratiev 			return rc;
7820b39aaf2SVladimir Kondratiev 	}
7830b39aaf2SVladimir Kondratiev 
7840b39aaf2SVladimir Kondratiev 	rc = wmi_rxon(wil, on);
7850b39aaf2SVladimir Kondratiev 	if (rc)
7860b39aaf2SVladimir Kondratiev 		return rc;
7870b39aaf2SVladimir Kondratiev 
7880b39aaf2SVladimir Kondratiev 	return len;
7890b39aaf2SVladimir Kondratiev }
7900b39aaf2SVladimir Kondratiev 
7910b39aaf2SVladimir Kondratiev static const struct file_operations fops_rxon = {
7920b39aaf2SVladimir Kondratiev 	.write = wil_write_file_rxon,
7930b39aaf2SVladimir Kondratiev 	.open  = simple_open,
7940b39aaf2SVladimir Kondratiev };
7958fe59627SVladimir Kondratiev 
79649cb5dfbSVladimir Kondratiev /* block ack control, write:
79749cb5dfbSVladimir Kondratiev  * - "add <ringid> <agg_size> <timeout>" to trigger ADDBA
79849cb5dfbSVladimir Kondratiev  * - "del_tx <ringid> <reason>" to trigger DELBA for Tx side
79949cb5dfbSVladimir Kondratiev  * - "del_rx <CID> <TID> <reason>" to trigger DELBA for Rx side
8003277213fSVladimir Kondratiev  */
80149cb5dfbSVladimir Kondratiev static ssize_t wil_write_back(struct file *file, const char __user *buf,
8023277213fSVladimir Kondratiev 			      size_t len, loff_t *ppos)
8033277213fSVladimir Kondratiev {
8043277213fSVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
8053277213fSVladimir Kondratiev 	int rc;
8063277213fSVladimir Kondratiev 	char *kbuf = kmalloc(len + 1, GFP_KERNEL);
8072a19f776SColin Ian King 	char cmd[9];
80849cb5dfbSVladimir Kondratiev 	int p1, p2, p3;
8093277213fSVladimir Kondratiev 
8103277213fSVladimir Kondratiev 	if (!kbuf)
8113277213fSVladimir Kondratiev 		return -ENOMEM;
8123277213fSVladimir Kondratiev 
8133277213fSVladimir Kondratiev 	rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
8143277213fSVladimir Kondratiev 	if (rc != len) {
8153277213fSVladimir Kondratiev 		kfree(kbuf);
8163277213fSVladimir Kondratiev 		return rc >= 0 ? -EIO : rc;
8173277213fSVladimir Kondratiev 	}
8183277213fSVladimir Kondratiev 
8193277213fSVladimir Kondratiev 	kbuf[len] = '\0';
82049cb5dfbSVladimir Kondratiev 	rc = sscanf(kbuf, "%8s %d %d %d", cmd, &p1, &p2, &p3);
8213277213fSVladimir Kondratiev 	kfree(kbuf);
8223277213fSVladimir Kondratiev 
82349cb5dfbSVladimir Kondratiev 	if (rc < 0)
8243277213fSVladimir Kondratiev 		return rc;
82549cb5dfbSVladimir Kondratiev 	if (rc < 2)
8263277213fSVladimir Kondratiev 		return -EINVAL;
8273277213fSVladimir Kondratiev 
828e00243faSLior David 	if ((strcmp(cmd, "add") == 0) ||
829e00243faSLior David 	    (strcmp(cmd, "del_tx") == 0)) {
83010590c6aSGidon Studinski 		struct wil_ring_tx_data *txdata;
831e00243faSLior David 
832e00243faSLior David 		if (p1 < 0 || p1 >= WIL6210_MAX_TX_RINGS) {
833e00243faSLior David 			wil_err(wil, "BACK: invalid ring id %d\n", p1);
834e00243faSLior David 			return -EINVAL;
835e00243faSLior David 		}
83610590c6aSGidon Studinski 		txdata = &wil->ring_tx_data[p1];
837e00243faSLior David 		if (strcmp(cmd, "add") == 0) {
83849cb5dfbSVladimir Kondratiev 			if (rc < 3) {
83949cb5dfbSVladimir Kondratiev 				wil_err(wil, "BACK: add require at least 2 params\n");
84049cb5dfbSVladimir Kondratiev 				return -EINVAL;
84149cb5dfbSVladimir Kondratiev 			}
84249cb5dfbSVladimir Kondratiev 			if (rc < 4)
84349cb5dfbSVladimir Kondratiev 				p3 = 0;
844e00243faSLior David 			wmi_addba(wil, txdata->mid, p1, p2, p3);
845e00243faSLior David 		} else {
84649cb5dfbSVladimir Kondratiev 			if (rc < 3)
84749cb5dfbSVladimir Kondratiev 				p2 = WLAN_REASON_QSTA_LEAVE_QBSS;
848e00243faSLior David 			wmi_delba_tx(wil, txdata->mid, p1, p2);
849e00243faSLior David 		}
850e00243faSLior David 	} else if (strcmp(cmd, "del_rx") == 0) {
851e00243faSLior David 		struct wil_sta_info *sta;
852e00243faSLior David 
85349cb5dfbSVladimir Kondratiev 		if (rc < 3) {
85449cb5dfbSVladimir Kondratiev 			wil_err(wil,
85549cb5dfbSVladimir Kondratiev 				"BACK: del_rx require at least 2 params\n");
85649cb5dfbSVladimir Kondratiev 			return -EINVAL;
85749cb5dfbSVladimir Kondratiev 		}
858e00243faSLior David 		if (p1 < 0 || p1 >= WIL6210_MAX_CID) {
859e00243faSLior David 			wil_err(wil, "BACK: invalid CID %d\n", p1);
860e00243faSLior David 			return -EINVAL;
861e00243faSLior David 		}
86249cb5dfbSVladimir Kondratiev 		if (rc < 4)
86349cb5dfbSVladimir Kondratiev 			p3 = WLAN_REASON_QSTA_LEAVE_QBSS;
864e00243faSLior David 		sta = &wil->sta[p1];
865e00243faSLior David 		wmi_delba_rx(wil, sta->mid, mk_cidxtid(p1, p2), p3);
86649cb5dfbSVladimir Kondratiev 	} else {
86749cb5dfbSVladimir Kondratiev 		wil_err(wil, "BACK: Unrecognized command \"%s\"\n", cmd);
86849cb5dfbSVladimir Kondratiev 		return -EINVAL;
86949cb5dfbSVladimir Kondratiev 	}
8703277213fSVladimir Kondratiev 
8713277213fSVladimir Kondratiev 	return len;
8723277213fSVladimir Kondratiev }
8733277213fSVladimir Kondratiev 
87449cb5dfbSVladimir Kondratiev static ssize_t wil_read_back(struct file *file, char __user *user_buf,
87549cb5dfbSVladimir Kondratiev 			     size_t count, loff_t *ppos)
87649cb5dfbSVladimir Kondratiev {
87749cb5dfbSVladimir Kondratiev 	static const char text[] = "block ack control, write:\n"
87849cb5dfbSVladimir Kondratiev 	" - \"add <ringid> <agg_size> <timeout>\" to trigger ADDBA\n"
87949cb5dfbSVladimir Kondratiev 	"If missing, <timeout> defaults to 0\n"
88049cb5dfbSVladimir Kondratiev 	" - \"del_tx <ringid> <reason>\" to trigger DELBA for Tx side\n"
88149cb5dfbSVladimir Kondratiev 	" - \"del_rx <CID> <TID> <reason>\" to trigger DELBA for Rx side\n"
88249cb5dfbSVladimir Kondratiev 	"If missing, <reason> set to \"STA_LEAVING\" (36)\n";
88349cb5dfbSVladimir Kondratiev 
88449cb5dfbSVladimir Kondratiev 	return simple_read_from_buffer(user_buf, count, ppos, text,
88549cb5dfbSVladimir Kondratiev 				       sizeof(text));
88649cb5dfbSVladimir Kondratiev }
88749cb5dfbSVladimir Kondratiev 
88849cb5dfbSVladimir Kondratiev static const struct file_operations fops_back = {
88949cb5dfbSVladimir Kondratiev 	.read = wil_read_back,
89049cb5dfbSVladimir Kondratiev 	.write = wil_write_back,
8913277213fSVladimir Kondratiev 	.open  = simple_open,
8923277213fSVladimir Kondratiev };
8933277213fSVladimir Kondratiev 
894dc16427bSVladimir Kondratiev /* pmc control, write:
895dc16427bSVladimir Kondratiev  * - "alloc <num descriptors> <descriptor_size>" to allocate PMC
896dc16427bSVladimir Kondratiev  * - "free" to release memory allocated for PMC
897dc16427bSVladimir Kondratiev  */
898dc16427bSVladimir Kondratiev static ssize_t wil_write_pmccfg(struct file *file, const char __user *buf,
899dc16427bSVladimir Kondratiev 				size_t len, loff_t *ppos)
900dc16427bSVladimir Kondratiev {
901dc16427bSVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
902dc16427bSVladimir Kondratiev 	int rc;
903dc16427bSVladimir Kondratiev 	char *kbuf = kmalloc(len + 1, GFP_KERNEL);
904dc16427bSVladimir Kondratiev 	char cmd[9];
905dc16427bSVladimir Kondratiev 	int num_descs, desc_size;
906dc16427bSVladimir Kondratiev 
907dc16427bSVladimir Kondratiev 	if (!kbuf)
908dc16427bSVladimir Kondratiev 		return -ENOMEM;
909dc16427bSVladimir Kondratiev 
910dc16427bSVladimir Kondratiev 	rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
911dc16427bSVladimir Kondratiev 	if (rc != len) {
912dc16427bSVladimir Kondratiev 		kfree(kbuf);
913dc16427bSVladimir Kondratiev 		return rc >= 0 ? -EIO : rc;
914dc16427bSVladimir Kondratiev 	}
915dc16427bSVladimir Kondratiev 
916dc16427bSVladimir Kondratiev 	kbuf[len] = '\0';
917dc16427bSVladimir Kondratiev 	rc = sscanf(kbuf, "%8s %d %d", cmd, &num_descs, &desc_size);
918dc16427bSVladimir Kondratiev 	kfree(kbuf);
919dc16427bSVladimir Kondratiev 
920dc16427bSVladimir Kondratiev 	if (rc < 0)
921dc16427bSVladimir Kondratiev 		return rc;
922dc16427bSVladimir Kondratiev 
923dc16427bSVladimir Kondratiev 	if (rc < 1) {
924dc16427bSVladimir Kondratiev 		wil_err(wil, "pmccfg: no params given\n");
925dc16427bSVladimir Kondratiev 		return -EINVAL;
926dc16427bSVladimir Kondratiev 	}
927dc16427bSVladimir Kondratiev 
928dc16427bSVladimir Kondratiev 	if (0 == strcmp(cmd, "alloc")) {
929dc16427bSVladimir Kondratiev 		if (rc != 3) {
930dc16427bSVladimir Kondratiev 			wil_err(wil, "pmccfg: alloc requires 2 params\n");
931dc16427bSVladimir Kondratiev 			return -EINVAL;
932dc16427bSVladimir Kondratiev 		}
933dc16427bSVladimir Kondratiev 		wil_pmc_alloc(wil, num_descs, desc_size);
934dc16427bSVladimir Kondratiev 	} else if (0 == strcmp(cmd, "free")) {
935dc16427bSVladimir Kondratiev 		if (rc != 1) {
936dc16427bSVladimir Kondratiev 			wil_err(wil, "pmccfg: free does not have any params\n");
937dc16427bSVladimir Kondratiev 			return -EINVAL;
938dc16427bSVladimir Kondratiev 		}
939dc16427bSVladimir Kondratiev 		wil_pmc_free(wil, true);
940dc16427bSVladimir Kondratiev 	} else {
941dc16427bSVladimir Kondratiev 		wil_err(wil, "pmccfg: Unrecognized command \"%s\"\n", cmd);
942dc16427bSVladimir Kondratiev 		return -EINVAL;
943dc16427bSVladimir Kondratiev 	}
944dc16427bSVladimir Kondratiev 
945dc16427bSVladimir Kondratiev 	return len;
946dc16427bSVladimir Kondratiev }
947dc16427bSVladimir Kondratiev 
948dc16427bSVladimir Kondratiev static ssize_t wil_read_pmccfg(struct file *file, char __user *user_buf,
949dc16427bSVladimir Kondratiev 			       size_t count, loff_t *ppos)
950dc16427bSVladimir Kondratiev {
951dc16427bSVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
952dc16427bSVladimir Kondratiev 	char text[256];
953dc16427bSVladimir Kondratiev 	char help[] = "pmc control, write:\n"
954dc16427bSVladimir Kondratiev 	" - \"alloc <num descriptors> <descriptor_size>\" to allocate pmc\n"
955dc16427bSVladimir Kondratiev 	" - \"free\" to free memory allocated for pmc\n";
956dc16427bSVladimir Kondratiev 
957dc16427bSVladimir Kondratiev 	sprintf(text, "Last command status: %d\n\n%s",
958dc16427bSVladimir Kondratiev 		wil_pmc_last_cmd_status(wil),
959dc16427bSVladimir Kondratiev 		help);
960dc16427bSVladimir Kondratiev 
961dc16427bSVladimir Kondratiev 	return simple_read_from_buffer(user_buf, count, ppos, text,
962dc16427bSVladimir Kondratiev 				       strlen(text) + 1);
963dc16427bSVladimir Kondratiev }
964dc16427bSVladimir Kondratiev 
965dc16427bSVladimir Kondratiev static const struct file_operations fops_pmccfg = {
966dc16427bSVladimir Kondratiev 	.read = wil_read_pmccfg,
967dc16427bSVladimir Kondratiev 	.write = wil_write_pmccfg,
968dc16427bSVladimir Kondratiev 	.open  = simple_open,
969dc16427bSVladimir Kondratiev };
970dc16427bSVladimir Kondratiev 
971dc16427bSVladimir Kondratiev static const struct file_operations fops_pmcdata = {
972dc16427bSVladimir Kondratiev 	.open		= simple_open,
973dc16427bSVladimir Kondratiev 	.read		= wil_pmc_read,
974dc16427bSVladimir Kondratiev 	.llseek		= wil_pmc_llseek,
975dc16427bSVladimir Kondratiev };
976dc16427bSVladimir Kondratiev 
9770b39aaf2SVladimir Kondratiev /*---tx_mgmt---*/
9780b39aaf2SVladimir Kondratiev /* Write mgmt frame to this file to send it */
9790b39aaf2SVladimir Kondratiev static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
9800b39aaf2SVladimir Kondratiev 				     size_t len, loff_t *ppos)
9810b39aaf2SVladimir Kondratiev {
9820b39aaf2SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
9830b39aaf2SVladimir Kondratiev 	struct wiphy *wiphy = wil_to_wiphy(wil);
984e00243faSLior David 	struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr;
9850b39aaf2SVladimir Kondratiev 	struct cfg80211_mgmt_tx_params params;
9860b39aaf2SVladimir Kondratiev 	int rc;
9879a492909SGeliang Tang 	void *frame;
9888fe59627SVladimir Kondratiev 
9896641525cSHamad Kadmany 	if (!len)
9906641525cSHamad Kadmany 		return -EINVAL;
9916641525cSHamad Kadmany 
9929a492909SGeliang Tang 	frame = memdup_user(buf, len);
9939a492909SGeliang Tang 	if (IS_ERR(frame))
9949a492909SGeliang Tang 		return PTR_ERR(frame);
9950b39aaf2SVladimir Kondratiev 
9960b39aaf2SVladimir Kondratiev 	params.buf = frame;
9970b39aaf2SVladimir Kondratiev 	params.len = len;
9980b39aaf2SVladimir Kondratiev 
9990b39aaf2SVladimir Kondratiev 	rc = wil_cfg80211_mgmt_tx(wiphy, wdev, &params, NULL);
10000b39aaf2SVladimir Kondratiev 
10010b39aaf2SVladimir Kondratiev 	kfree(frame);
1002af3db60aSLazar Alexei 	wil_info(wil, "-> %d\n", rc);
10030b39aaf2SVladimir Kondratiev 
10040b39aaf2SVladimir Kondratiev 	return len;
10050b39aaf2SVladimir Kondratiev }
10060b39aaf2SVladimir Kondratiev 
10070b39aaf2SVladimir Kondratiev static const struct file_operations fops_txmgmt = {
10080b39aaf2SVladimir Kondratiev 	.write = wil_write_file_txmgmt,
10090b39aaf2SVladimir Kondratiev 	.open  = simple_open,
10100b39aaf2SVladimir Kondratiev };
10112be7d22fSVladimir Kondratiev 
1012ff974e40SVladimir Kondratiev /* Write WMI command (w/o mbox header) to this file to send it
1013ff974e40SVladimir Kondratiev  * WMI starts from wil6210_mbox_hdr_wmi header
1014ff974e40SVladimir Kondratiev  */
1015ff974e40SVladimir Kondratiev static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
1016ff974e40SVladimir Kondratiev 				  size_t len, loff_t *ppos)
1017ff974e40SVladimir Kondratiev {
1018ff974e40SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
1019e00243faSLior David 	struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
1020b874ddecSLior David 	struct wmi_cmd_hdr *wmi;
1021ff974e40SVladimir Kondratiev 	void *cmd;
1022b874ddecSLior David 	int cmdlen = len - sizeof(struct wmi_cmd_hdr);
1023ff974e40SVladimir Kondratiev 	u16 cmdid;
1024ff974e40SVladimir Kondratiev 	int rc, rc1;
1025ff974e40SVladimir Kondratiev 
102669218a48SLior David 	if (cmdlen < 0)
1027ff974e40SVladimir Kondratiev 		return -EINVAL;
1028ff974e40SVladimir Kondratiev 
1029ff974e40SVladimir Kondratiev 	wmi = kmalloc(len, GFP_KERNEL);
1030ff974e40SVladimir Kondratiev 	if (!wmi)
1031ff974e40SVladimir Kondratiev 		return -ENOMEM;
1032ff974e40SVladimir Kondratiev 
1033ff974e40SVladimir Kondratiev 	rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
10348e09b7d2SLino Sanfilippo 	if (rc < 0) {
10358e09b7d2SLino Sanfilippo 		kfree(wmi);
1036ff974e40SVladimir Kondratiev 		return rc;
10378e09b7d2SLino Sanfilippo 	}
1038ff974e40SVladimir Kondratiev 
103969218a48SLior David 	cmd = (cmdlen > 0) ? &wmi[1] : NULL;
1040b874ddecSLior David 	cmdid = le16_to_cpu(wmi->command_id);
1041ff974e40SVladimir Kondratiev 
1042e00243faSLior David 	rc1 = wmi_send(wil, cmdid, vif->mid, cmd, cmdlen);
1043ff974e40SVladimir Kondratiev 	kfree(wmi);
1044ff974e40SVladimir Kondratiev 
1045af3db60aSLazar Alexei 	wil_info(wil, "0x%04x[%d] -> %d\n", cmdid, cmdlen, rc1);
1046ff974e40SVladimir Kondratiev 
1047ff974e40SVladimir Kondratiev 	return rc;
1048ff974e40SVladimir Kondratiev }
1049ff974e40SVladimir Kondratiev 
1050ff974e40SVladimir Kondratiev static const struct file_operations fops_wmi = {
1051ff974e40SVladimir Kondratiev 	.write = wil_write_file_wmi,
1052ff974e40SVladimir Kondratiev 	.open  = simple_open,
1053ff974e40SVladimir Kondratiev };
1054ff974e40SVladimir Kondratiev 
1055c236658fSVladimir Kondratiev static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
1056c236658fSVladimir Kondratiev {
1057c236658fSVladimir Kondratiev 	int i = 0;
1058c236658fSVladimir Kondratiev 	int len = skb_headlen(skb);
1059c236658fSVladimir Kondratiev 	void *p = skb->data;
1060c236658fSVladimir Kondratiev 	int nr_frags = skb_shinfo(skb)->nr_frags;
1061c236658fSVladimir Kondratiev 
1062c236658fSVladimir Kondratiev 	seq_printf(s, "    len = %d\n", len);
1063c236658fSVladimir Kondratiev 	wil_seq_hexdump(s, p, len, "      : ");
1064c236658fSVladimir Kondratiev 
1065c236658fSVladimir Kondratiev 	if (nr_frags) {
1066c236658fSVladimir Kondratiev 		seq_printf(s, "    nr_frags = %d\n", nr_frags);
1067c236658fSVladimir Kondratiev 		for (i = 0; i < nr_frags; i++) {
1068c236658fSVladimir Kondratiev 			const struct skb_frag_struct *frag =
1069c236658fSVladimir Kondratiev 					&skb_shinfo(skb)->frags[i];
1070c236658fSVladimir Kondratiev 
1071c236658fSVladimir Kondratiev 			len = skb_frag_size(frag);
1072c236658fSVladimir Kondratiev 			p = skb_frag_address_safe(frag);
1073c236658fSVladimir Kondratiev 			seq_printf(s, "    [%2d] : len = %d\n", i, len);
1074c236658fSVladimir Kondratiev 			wil_seq_hexdump(s, p, len, "      : ");
1075c236658fSVladimir Kondratiev 		}
1076c236658fSVladimir Kondratiev 	}
1077c236658fSVladimir Kondratiev }
1078c236658fSVladimir Kondratiev 
10793a85543eSVladimir Kondratiev /*---------Tx/Rx descriptor------------*/
10802be7d22fSVladimir Kondratiev static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
10812be7d22fSVladimir Kondratiev {
10822be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
108310590c6aSGidon Studinski 	struct wil_ring *ring;
1084d98b8539SMaya Erez 	bool tx;
1085d98b8539SMaya Erez 	int ring_idx = dbg_ring_index;
1086d98b8539SMaya Erez 	int txdesc_idx = dbg_txdesc_index;
1087d98b8539SMaya Erez 	volatile struct vring_tx_desc *d;
1088d98b8539SMaya Erez 	volatile u32 *u;
1089d98b8539SMaya Erez 	struct sk_buff *skb;
10908fe59627SVladimir Kondratiev 
1091d98b8539SMaya Erez 	if (wil->use_enhanced_dma_hw) {
1092d98b8539SMaya Erez 		/* RX ring index == 0 */
1093d98b8539SMaya Erez 		if (ring_idx >= WIL6210_MAX_TX_RINGS) {
1094d98b8539SMaya Erez 			seq_printf(s, "invalid ring index %d\n", ring_idx);
1095d98b8539SMaya Erez 			return 0;
1096d98b8539SMaya Erez 		}
1097d98b8539SMaya Erez 		tx = ring_idx > 0; /* desc ring 0 is reserved for RX */
1098d98b8539SMaya Erez 	} else {
1099d98b8539SMaya Erez 		/* RX ring index == WIL6210_MAX_TX_RINGS */
1100d98b8539SMaya Erez 		if (ring_idx > WIL6210_MAX_TX_RINGS) {
1101d98b8539SMaya Erez 			seq_printf(s, "invalid ring index %d\n", ring_idx);
1102d98b8539SMaya Erez 			return 0;
1103d98b8539SMaya Erez 		}
1104d98b8539SMaya Erez 		tx = (ring_idx < WIL6210_MAX_TX_RINGS);
1105d98b8539SMaya Erez 	}
1106d98b8539SMaya Erez 
1107d98b8539SMaya Erez 	ring = tx ? &wil->ring_tx[ring_idx] : &wil->ring_rx;
11082be7d22fSVladimir Kondratiev 
110910590c6aSGidon Studinski 	if (!ring->va) {
1110af31cb5aSVladimir Kondratiev 		if (tx)
1111d98b8539SMaya Erez 			seq_printf(s, "No Tx[%2d] RING\n", ring_idx);
11123a85543eSVladimir Kondratiev 		else
1113d98b8539SMaya Erez 			seq_puts(s, "No Rx RING\n");
11142be7d22fSVladimir Kondratiev 		return 0;
11152be7d22fSVladimir Kondratiev 	}
11162be7d22fSVladimir Kondratiev 
1117d98b8539SMaya Erez 	if (txdesc_idx >= ring->size) {
1118d98b8539SMaya Erez 		if (tx)
1119d98b8539SMaya Erez 			seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
1120d98b8539SMaya Erez 				   ring_idx, txdesc_idx, ring->size);
1121d98b8539SMaya Erez 		else
1122d98b8539SMaya Erez 			seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
1123d98b8539SMaya Erez 				   txdesc_idx, ring->size);
1124d98b8539SMaya Erez 		return 0;
1125d98b8539SMaya Erez 	}
1126d98b8539SMaya Erez 
11273a85543eSVladimir Kondratiev 	/* use struct vring_tx_desc for Rx as well,
11283a85543eSVladimir Kondratiev 	 * only field used, .dma.length, is the same
11293a85543eSVladimir Kondratiev 	 */
1130d98b8539SMaya Erez 	d = &ring->va[txdesc_idx].tx.legacy;
1131d98b8539SMaya Erez 	u = (volatile u32 *)d;
1132d98b8539SMaya Erez 	skb = NULL;
11332be7d22fSVladimir Kondratiev 
1134d98b8539SMaya Erez 	if (wil->use_enhanced_dma_hw) {
1135d98b8539SMaya Erez 		if (tx) {
1136d98b8539SMaya Erez 			skb = ring->ctx[txdesc_idx].skb;
1137d98b8539SMaya Erez 		} else {
1138d98b8539SMaya Erez 			struct wil_rx_enhanced_desc *rx_d =
1139d98b8539SMaya Erez 				(struct wil_rx_enhanced_desc *)
1140d98b8539SMaya Erez 				&ring->va[txdesc_idx].rx.enhanced;
1141d98b8539SMaya Erez 			u16 buff_id = le16_to_cpu(rx_d->mac.buff_id);
1142d98b8539SMaya Erez 
1143d98b8539SMaya Erez 			if (!wil_val_in_range(buff_id, 0,
1144d98b8539SMaya Erez 					      wil->rx_buff_mgmt.size)) {
1145d98b8539SMaya Erez 				seq_printf(s, "invalid buff_id %d\n", buff_id);
1146d98b8539SMaya Erez 				return 0;
1147d98b8539SMaya Erez 			}
1148d98b8539SMaya Erez 			skb = wil->rx_buff_mgmt.buff_arr[buff_id].skb;
1149d98b8539SMaya Erez 		}
1150d98b8539SMaya Erez 	} else {
1151d98b8539SMaya Erez 		skb = ring->ctx[txdesc_idx].skb;
1152d98b8539SMaya Erez 	}
1153af31cb5aSVladimir Kondratiev 	if (tx)
1154d98b8539SMaya Erez 		seq_printf(s, "Tx[%2d][%3d] = {\n", ring_idx,
1155d98b8539SMaya Erez 			   txdesc_idx);
11563a85543eSVladimir Kondratiev 	else
1157d98b8539SMaya Erez 		seq_printf(s, "Rx[%3d] = {\n", txdesc_idx);
11582be7d22fSVladimir Kondratiev 	seq_printf(s, "  MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
11592be7d22fSVladimir Kondratiev 		   u[0], u[1], u[2], u[3]);
11602be7d22fSVladimir Kondratiev 	seq_printf(s, "  DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
11612be7d22fSVladimir Kondratiev 		   u[4], u[5], u[6], u[7]);
116239c52ee8SVladimir Kondratiev 	seq_printf(s, "  SKB = 0x%p\n", skb);
11632be7d22fSVladimir Kondratiev 
11642be7d22fSVladimir Kondratiev 	if (skb) {
1165c236658fSVladimir Kondratiev 		skb_get(skb);
1166c236658fSVladimir Kondratiev 		wil_seq_print_skb(s, skb);
1167c236658fSVladimir Kondratiev 		kfree_skb(skb);
11682be7d22fSVladimir Kondratiev 	}
11698fe59627SVladimir Kondratiev 	seq_puts(s, "}\n");
11702be7d22fSVladimir Kondratiev 
11712be7d22fSVladimir Kondratiev 	return 0;
11722be7d22fSVladimir Kondratiev }
11732be7d22fSVladimir Kondratiev 
11742be7d22fSVladimir Kondratiev static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
11752be7d22fSVladimir Kondratiev {
11762be7d22fSVladimir Kondratiev 	return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
11772be7d22fSVladimir Kondratiev }
11782be7d22fSVladimir Kondratiev 
11792be7d22fSVladimir Kondratiev static const struct file_operations fops_txdesc = {
11802be7d22fSVladimir Kondratiev 	.open		= wil_txdesc_seq_open,
11812be7d22fSVladimir Kondratiev 	.release	= single_release,
11822be7d22fSVladimir Kondratiev 	.read		= seq_read,
11832be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
11842be7d22fSVladimir Kondratiev };
11852be7d22fSVladimir Kondratiev 
1186d98b8539SMaya Erez /*---------Tx/Rx status message------------*/
1187d98b8539SMaya Erez static int wil_status_msg_debugfs_show(struct seq_file *s, void *data)
1188d98b8539SMaya Erez {
1189d98b8539SMaya Erez 	struct wil6210_priv *wil = s->private;
1190d98b8539SMaya Erez 	int sring_idx = dbg_sring_index;
1191d98b8539SMaya Erez 	struct wil_status_ring *sring;
1192d98b8539SMaya Erez 	bool tx = sring_idx == wil->tx_sring_idx ? 1 : 0;
1193d98b8539SMaya Erez 	u32 status_msg_idx = dbg_status_msg_index;
1194d98b8539SMaya Erez 	u32 *u;
1195d98b8539SMaya Erez 
1196d98b8539SMaya Erez 	if (sring_idx >= WIL6210_MAX_STATUS_RINGS) {
1197d98b8539SMaya Erez 		seq_printf(s, "invalid status ring index %d\n", sring_idx);
1198d98b8539SMaya Erez 		return 0;
1199d98b8539SMaya Erez 	}
1200d98b8539SMaya Erez 
1201d98b8539SMaya Erez 	sring = &wil->srings[sring_idx];
1202d98b8539SMaya Erez 
1203d98b8539SMaya Erez 	if (!sring->va) {
1204d98b8539SMaya Erez 		seq_printf(s, "No %cX status ring\n", tx ? 'T' : 'R');
1205d98b8539SMaya Erez 		return 0;
1206d98b8539SMaya Erez 	}
1207d98b8539SMaya Erez 
1208d98b8539SMaya Erez 	if (status_msg_idx >= sring->size) {
1209d98b8539SMaya Erez 		seq_printf(s, "%cxDesc index (%d) >= size (%d)\n",
1210d98b8539SMaya Erez 			   tx ? 'T' : 'R', status_msg_idx, sring->size);
1211d98b8539SMaya Erez 		return 0;
1212d98b8539SMaya Erez 	}
1213d98b8539SMaya Erez 
1214d98b8539SMaya Erez 	u = sring->va + (sring->elem_size * status_msg_idx);
1215d98b8539SMaya Erez 
1216d98b8539SMaya Erez 	seq_printf(s, "%cx[%d][%3d] = {\n",
1217d98b8539SMaya Erez 		   tx ? 'T' : 'R', sring_idx, status_msg_idx);
1218d98b8539SMaya Erez 
1219d98b8539SMaya Erez 	seq_printf(s, "  0x%08x 0x%08x 0x%08x 0x%08x\n",
1220d98b8539SMaya Erez 		   u[0], u[1], u[2], u[3]);
1221d98b8539SMaya Erez 	if (!tx && !wil->use_compressed_rx_status)
1222d98b8539SMaya Erez 		seq_printf(s, "  0x%08x 0x%08x 0x%08x 0x%08x\n",
1223d98b8539SMaya Erez 			   u[4], u[5], u[6], u[7]);
1224d98b8539SMaya Erez 
1225d98b8539SMaya Erez 	seq_puts(s, "}\n");
1226d98b8539SMaya Erez 
1227d98b8539SMaya Erez 	return 0;
1228d98b8539SMaya Erez }
1229d98b8539SMaya Erez 
1230d98b8539SMaya Erez static int wil_status_msg_seq_open(struct inode *inode, struct file *file)
1231d98b8539SMaya Erez {
1232d98b8539SMaya Erez 	return single_open(file, wil_status_msg_debugfs_show,
1233d98b8539SMaya Erez 			   inode->i_private);
1234d98b8539SMaya Erez }
1235d98b8539SMaya Erez 
1236d98b8539SMaya Erez static const struct file_operations fops_status_msg = {
1237d98b8539SMaya Erez 	.open		= wil_status_msg_seq_open,
1238d98b8539SMaya Erez 	.release	= single_release,
1239d98b8539SMaya Erez 	.read		= seq_read,
1240d98b8539SMaya Erez 	.llseek		= seq_lseek,
1241d98b8539SMaya Erez };
1242d98b8539SMaya Erez 
1243d98b8539SMaya Erez static int wil_print_rx_buff(struct seq_file *s, struct list_head *lh)
1244d98b8539SMaya Erez {
1245d98b8539SMaya Erez 	struct wil_rx_buff *it;
1246d98b8539SMaya Erez 	int i = 0;
1247d98b8539SMaya Erez 
1248d98b8539SMaya Erez 	list_for_each_entry(it, lh, list) {
1249d98b8539SMaya Erez 		if ((i % 16) == 0 && i != 0)
1250d98b8539SMaya Erez 			seq_puts(s, "\n    ");
1251d98b8539SMaya Erez 		seq_printf(s, "[%4d] ", it->id);
1252d98b8539SMaya Erez 		i++;
1253d98b8539SMaya Erez 	}
1254d98b8539SMaya Erez 	seq_printf(s, "\nNumber of buffers: %u\n", i);
1255d98b8539SMaya Erez 
1256d98b8539SMaya Erez 	return i;
1257d98b8539SMaya Erez }
1258d98b8539SMaya Erez 
1259d98b8539SMaya Erez static int wil_rx_buff_mgmt_debugfs_show(struct seq_file *s, void *data)
1260d98b8539SMaya Erez {
1261d98b8539SMaya Erez 	struct wil6210_priv *wil = s->private;
1262d98b8539SMaya Erez 	struct wil_rx_buff_mgmt *rbm = &wil->rx_buff_mgmt;
1263d98b8539SMaya Erez 	int num_active;
1264d98b8539SMaya Erez 	int num_free;
1265d98b8539SMaya Erez 
1266d98b8539SMaya Erez 	seq_printf(s, "  size = %zu\n", rbm->size);
1267d98b8539SMaya Erez 	seq_printf(s, "  free_list_empty_cnt = %lu\n",
1268d98b8539SMaya Erez 		   rbm->free_list_empty_cnt);
1269d98b8539SMaya Erez 
1270d98b8539SMaya Erez 	/* Print active list */
1271d98b8539SMaya Erez 	seq_puts(s, "  Active list:\n");
1272d98b8539SMaya Erez 	num_active = wil_print_rx_buff(s, &rbm->active);
1273d98b8539SMaya Erez 	seq_puts(s, "\n  Free list:\n");
1274d98b8539SMaya Erez 	num_free = wil_print_rx_buff(s, &rbm->free);
1275d98b8539SMaya Erez 
1276d98b8539SMaya Erez 	seq_printf(s, "  Total number of buffers: %u\n",
1277d98b8539SMaya Erez 		   num_active + num_free);
1278d98b8539SMaya Erez 
1279d98b8539SMaya Erez 	return 0;
1280d98b8539SMaya Erez }
1281d98b8539SMaya Erez 
1282d98b8539SMaya Erez static int wil_rx_buff_mgmt_seq_open(struct inode *inode, struct file *file)
1283d98b8539SMaya Erez {
1284d98b8539SMaya Erez 	return single_open(file, wil_rx_buff_mgmt_debugfs_show,
1285d98b8539SMaya Erez 			   inode->i_private);
1286d98b8539SMaya Erez }
1287d98b8539SMaya Erez 
1288d98b8539SMaya Erez static const struct file_operations fops_rx_buff_mgmt = {
1289d98b8539SMaya Erez 	.open		= wil_rx_buff_mgmt_seq_open,
1290d98b8539SMaya Erez 	.release	= single_release,
1291d98b8539SMaya Erez 	.read		= seq_read,
1292d98b8539SMaya Erez 	.llseek		= seq_lseek,
1293d98b8539SMaya Erez };
1294d98b8539SMaya Erez 
12952be7d22fSVladimir Kondratiev /*---------beamforming------------*/
129636345ac3SVladimir Kondratiev static char *wil_bfstatus_str(u32 status)
129736345ac3SVladimir Kondratiev {
129836345ac3SVladimir Kondratiev 	switch (status) {
129936345ac3SVladimir Kondratiev 	case 0:
130036345ac3SVladimir Kondratiev 		return "Failed";
130136345ac3SVladimir Kondratiev 	case 1:
130236345ac3SVladimir Kondratiev 		return "OK";
130336345ac3SVladimir Kondratiev 	case 2:
130436345ac3SVladimir Kondratiev 		return "Retrying";
130536345ac3SVladimir Kondratiev 	default:
130636345ac3SVladimir Kondratiev 		return "??";
130736345ac3SVladimir Kondratiev 	}
130836345ac3SVladimir Kondratiev }
130936345ac3SVladimir Kondratiev 
131036345ac3SVladimir Kondratiev static bool is_all_zeros(void * const x_, size_t sz)
131136345ac3SVladimir Kondratiev {
131236345ac3SVladimir Kondratiev 	/* if reply is all-0, ignore this CID */
131336345ac3SVladimir Kondratiev 	u32 *x = x_;
131436345ac3SVladimir Kondratiev 	int n;
131536345ac3SVladimir Kondratiev 
131636345ac3SVladimir Kondratiev 	for (n = 0; n < sz / sizeof(*x); n++)
131736345ac3SVladimir Kondratiev 		if (x[n])
131836345ac3SVladimir Kondratiev 			return false;
131936345ac3SVladimir Kondratiev 
132036345ac3SVladimir Kondratiev 	return true;
132136345ac3SVladimir Kondratiev }
132236345ac3SVladimir Kondratiev 
13232be7d22fSVladimir Kondratiev static int wil_bf_debugfs_show(struct seq_file *s, void *data)
13242be7d22fSVladimir Kondratiev {
132536345ac3SVladimir Kondratiev 	int rc;
132636345ac3SVladimir Kondratiev 	int i;
13272be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
1328e00243faSLior David 	struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
132936345ac3SVladimir Kondratiev 	struct wmi_notify_req_cmd cmd = {
133036345ac3SVladimir Kondratiev 		.interval_usec = 0,
133136345ac3SVladimir Kondratiev 	};
133236345ac3SVladimir Kondratiev 	struct {
1333b874ddecSLior David 		struct wmi_cmd_hdr wmi;
133436345ac3SVladimir Kondratiev 		struct wmi_notify_req_done_event evt;
133536345ac3SVladimir Kondratiev 	} __packed reply;
133636345ac3SVladimir Kondratiev 
1337807b0860SAlexei Avshalom Lazar 	memset(&reply, 0, sizeof(reply));
1338807b0860SAlexei Avshalom Lazar 
133936345ac3SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
134036345ac3SVladimir Kondratiev 		u32 status;
134136345ac3SVladimir Kondratiev 
134236345ac3SVladimir Kondratiev 		cmd.cid = i;
1343e00243faSLior David 		rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, vif->mid,
1344e00243faSLior David 			      &cmd, sizeof(cmd),
134536345ac3SVladimir Kondratiev 			      WMI_NOTIFY_REQ_DONE_EVENTID, &reply,
134636345ac3SVladimir Kondratiev 			      sizeof(reply), 20);
134736345ac3SVladimir Kondratiev 		/* if reply is all-0, ignore this CID */
134836345ac3SVladimir Kondratiev 		if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt)))
134936345ac3SVladimir Kondratiev 			continue;
135036345ac3SVladimir Kondratiev 
135136345ac3SVladimir Kondratiev 		status = le32_to_cpu(reply.evt.status);
135236345ac3SVladimir Kondratiev 		seq_printf(s, "CID %d {\n"
135336345ac3SVladimir Kondratiev 			   "  TSF = 0x%016llx\n"
135436345ac3SVladimir Kondratiev 			   "  TxMCS = %2d TxTpt = %4d\n"
135536345ac3SVladimir Kondratiev 			   "  SQI = %4d\n"
135630868f5dSDedy Lansky 			   "  RSSI = %4d\n"
135736345ac3SVladimir Kondratiev 			   "  Status = 0x%08x %s\n"
135836345ac3SVladimir Kondratiev 			   "  Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
135936345ac3SVladimir Kondratiev 			   "  Goodput(rx:tx) %4d:%4d\n"
136036345ac3SVladimir Kondratiev 			   "}\n",
136136345ac3SVladimir Kondratiev 			   i,
136236345ac3SVladimir Kondratiev 			   le64_to_cpu(reply.evt.tsf),
136336345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.bf_mcs),
136436345ac3SVladimir Kondratiev 			   le32_to_cpu(reply.evt.tx_tpt),
136536345ac3SVladimir Kondratiev 			   reply.evt.sqi,
136630868f5dSDedy Lansky 			   reply.evt.rssi,
136736345ac3SVladimir Kondratiev 			   status, wil_bfstatus_str(status),
136836345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.my_rx_sector),
136936345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.my_tx_sector),
137036345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.other_rx_sector),
137136345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.other_tx_sector),
137236345ac3SVladimir Kondratiev 			   le32_to_cpu(reply.evt.rx_goodput),
137336345ac3SVladimir Kondratiev 			   le32_to_cpu(reply.evt.tx_goodput));
137436345ac3SVladimir Kondratiev 	}
13752be7d22fSVladimir Kondratiev 	return 0;
13762be7d22fSVladimir Kondratiev }
13772be7d22fSVladimir Kondratiev 
13782be7d22fSVladimir Kondratiev static int wil_bf_seq_open(struct inode *inode, struct file *file)
13792be7d22fSVladimir Kondratiev {
13802be7d22fSVladimir Kondratiev 	return single_open(file, wil_bf_debugfs_show, inode->i_private);
13812be7d22fSVladimir Kondratiev }
13822be7d22fSVladimir Kondratiev 
13832be7d22fSVladimir Kondratiev static const struct file_operations fops_bf = {
13842be7d22fSVladimir Kondratiev 	.open		= wil_bf_seq_open,
13852be7d22fSVladimir Kondratiev 	.release	= single_release,
13862be7d22fSVladimir Kondratiev 	.read		= seq_read,
13872be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
13882be7d22fSVladimir Kondratiev };
13898fe59627SVladimir Kondratiev 
13901a2780e0SVladimir Kondratiev /*---------temp------------*/
13916d9eb7ebSDedy Lansky static void print_temp(struct seq_file *s, const char *prefix, s32 t)
13921a2780e0SVladimir Kondratiev {
13931a2780e0SVladimir Kondratiev 	switch (t) {
13941a2780e0SVladimir Kondratiev 	case 0:
13951a2780e0SVladimir Kondratiev 	case ~(u32)0:
13961a2780e0SVladimir Kondratiev 		seq_printf(s, "%s N/A\n", prefix);
13971a2780e0SVladimir Kondratiev 	break;
13981a2780e0SVladimir Kondratiev 	default:
13996d9eb7ebSDedy Lansky 		seq_printf(s, "%s %s%d.%03d\n", prefix, (t < 0 ? "-" : ""),
14006d9eb7ebSDedy Lansky 			   abs(t / 1000), abs(t % 1000));
14011a2780e0SVladimir Kondratiev 		break;
14021a2780e0SVladimir Kondratiev 	}
14031a2780e0SVladimir Kondratiev }
14041a2780e0SVladimir Kondratiev 
14051a2780e0SVladimir Kondratiev static int wil_temp_debugfs_show(struct seq_file *s, void *data)
14061a2780e0SVladimir Kondratiev {
14071a2780e0SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
14086d9eb7ebSDedy Lansky 	s32 t_m, t_r;
14091a2780e0SVladimir Kondratiev 	int rc = wmi_get_temperature(wil, &t_m, &t_r);
14108fe59627SVladimir Kondratiev 
14111a2780e0SVladimir Kondratiev 	if (rc) {
14128fe59627SVladimir Kondratiev 		seq_puts(s, "Failed\n");
14131a2780e0SVladimir Kondratiev 		return 0;
14141a2780e0SVladimir Kondratiev 	}
14151a2780e0SVladimir Kondratiev 
1416d45cff9fSVladimir Kondratiev 	print_temp(s, "T_mac   =", t_m);
1417d45cff9fSVladimir Kondratiev 	print_temp(s, "T_radio =", t_r);
14181a2780e0SVladimir Kondratiev 
14191a2780e0SVladimir Kondratiev 	return 0;
14201a2780e0SVladimir Kondratiev }
14211a2780e0SVladimir Kondratiev 
14221a2780e0SVladimir Kondratiev static int wil_temp_seq_open(struct inode *inode, struct file *file)
14231a2780e0SVladimir Kondratiev {
14241a2780e0SVladimir Kondratiev 	return single_open(file, wil_temp_debugfs_show, inode->i_private);
14251a2780e0SVladimir Kondratiev }
14261a2780e0SVladimir Kondratiev 
14271a2780e0SVladimir Kondratiev static const struct file_operations fops_temp = {
14281a2780e0SVladimir Kondratiev 	.open		= wil_temp_seq_open,
14291a2780e0SVladimir Kondratiev 	.release	= single_release,
14301a2780e0SVladimir Kondratiev 	.read		= seq_read,
14311a2780e0SVladimir Kondratiev 	.llseek		= seq_lseek,
14321a2780e0SVladimir Kondratiev };
14331a2780e0SVladimir Kondratiev 
14349eb82d43SVladimir Kondratiev /*---------freq------------*/
14359eb82d43SVladimir Kondratiev static int wil_freq_debugfs_show(struct seq_file *s, void *data)
14369eb82d43SVladimir Kondratiev {
14379eb82d43SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
1438e00243faSLior David 	struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr;
14399eb82d43SVladimir Kondratiev 	u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
14409eb82d43SVladimir Kondratiev 
14419eb82d43SVladimir Kondratiev 	seq_printf(s, "Freq = %d\n", freq);
14429eb82d43SVladimir Kondratiev 
14439eb82d43SVladimir Kondratiev 	return 0;
14449eb82d43SVladimir Kondratiev }
14459eb82d43SVladimir Kondratiev 
14469eb82d43SVladimir Kondratiev static int wil_freq_seq_open(struct inode *inode, struct file *file)
14479eb82d43SVladimir Kondratiev {
14489eb82d43SVladimir Kondratiev 	return single_open(file, wil_freq_debugfs_show, inode->i_private);
14499eb82d43SVladimir Kondratiev }
14509eb82d43SVladimir Kondratiev 
14519eb82d43SVladimir Kondratiev static const struct file_operations fops_freq = {
14529eb82d43SVladimir Kondratiev 	.open		= wil_freq_seq_open,
14539eb82d43SVladimir Kondratiev 	.release	= single_release,
14549eb82d43SVladimir Kondratiev 	.read		= seq_read,
14559eb82d43SVladimir Kondratiev 	.llseek		= seq_lseek,
14569eb82d43SVladimir Kondratiev };
14579eb82d43SVladimir Kondratiev 
14589eb82d43SVladimir Kondratiev /*---------link------------*/
14599eb82d43SVladimir Kondratiev static int wil_link_debugfs_show(struct seq_file *s, void *data)
14609eb82d43SVladimir Kondratiev {
14619eb82d43SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
146241bd3d58SToke Høiland-Jørgensen 	struct station_info *sinfo;
146341bd3d58SToke Høiland-Jørgensen 	int i, rc = 0;
146441bd3d58SToke Høiland-Jørgensen 
146541bd3d58SToke Høiland-Jørgensen 	sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL);
146641bd3d58SToke Høiland-Jørgensen 	if (!sinfo)
146741bd3d58SToke Høiland-Jørgensen 		return -ENOMEM;
14689eb82d43SVladimir Kondratiev 
14699eb82d43SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
14709eb82d43SVladimir Kondratiev 		struct wil_sta_info *p = &wil->sta[i];
14719eb82d43SVladimir Kondratiev 		char *status = "unknown";
14725bd60982SLior David 		struct wil6210_vif *vif;
14735bd60982SLior David 		u8 mid;
14748fe59627SVladimir Kondratiev 
14759eb82d43SVladimir Kondratiev 		switch (p->status) {
14769eb82d43SVladimir Kondratiev 		case wil_sta_unused:
14779eb82d43SVladimir Kondratiev 			status = "unused   ";
14789eb82d43SVladimir Kondratiev 			break;
14799eb82d43SVladimir Kondratiev 		case wil_sta_conn_pending:
14809eb82d43SVladimir Kondratiev 			status = "pending  ";
14819eb82d43SVladimir Kondratiev 			break;
14829eb82d43SVladimir Kondratiev 		case wil_sta_connected:
14839eb82d43SVladimir Kondratiev 			status = "connected";
14849eb82d43SVladimir Kondratiev 			break;
14859eb82d43SVladimir Kondratiev 		}
14865bd60982SLior David 		mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
14875bd60982SLior David 		seq_printf(s, "[%d][MID %d] %pM %s\n",
14885bd60982SLior David 			   i, mid, p->addr, status);
14899eb82d43SVladimir Kondratiev 
14905bd60982SLior David 		if (p->status != wil_sta_connected)
14915bd60982SLior David 			continue;
14925bd60982SLior David 
14935bd60982SLior David 		vif = (mid < wil->max_vifs) ? wil->vifs[mid] : NULL;
14945bd60982SLior David 		if (vif) {
149541bd3d58SToke Høiland-Jørgensen 			rc = wil_cid_fill_sinfo(vif, i, sinfo);
14969eb82d43SVladimir Kondratiev 			if (rc)
149741bd3d58SToke Høiland-Jørgensen 				goto out;
14989eb82d43SVladimir Kondratiev 
149941bd3d58SToke Høiland-Jørgensen 			seq_printf(s, "  Tx_mcs = %d\n", sinfo->txrate.mcs);
150041bd3d58SToke Høiland-Jørgensen 			seq_printf(s, "  Rx_mcs = %d\n", sinfo->rxrate.mcs);
150141bd3d58SToke Høiland-Jørgensen 			seq_printf(s, "  SQ     = %d\n", sinfo->signal);
15025bd60982SLior David 		} else {
15035bd60982SLior David 			seq_puts(s, "  INVALID MID\n");
15049eb82d43SVladimir Kondratiev 		}
15059eb82d43SVladimir Kondratiev 	}
15069eb82d43SVladimir Kondratiev 
150741bd3d58SToke Høiland-Jørgensen out:
150841bd3d58SToke Høiland-Jørgensen 	kfree(sinfo);
150941bd3d58SToke Høiland-Jørgensen 	return rc;
15109eb82d43SVladimir Kondratiev }
15119eb82d43SVladimir Kondratiev 
15129eb82d43SVladimir Kondratiev static int wil_link_seq_open(struct inode *inode, struct file *file)
15139eb82d43SVladimir Kondratiev {
15149eb82d43SVladimir Kondratiev 	return single_open(file, wil_link_debugfs_show, inode->i_private);
15159eb82d43SVladimir Kondratiev }
15169eb82d43SVladimir Kondratiev 
15179eb82d43SVladimir Kondratiev static const struct file_operations fops_link = {
15189eb82d43SVladimir Kondratiev 	.open		= wil_link_seq_open,
15199eb82d43SVladimir Kondratiev 	.release	= single_release,
15209eb82d43SVladimir Kondratiev 	.read		= seq_read,
15219eb82d43SVladimir Kondratiev 	.llseek		= seq_lseek,
15229eb82d43SVladimir Kondratiev };
15239eb82d43SVladimir Kondratiev 
152484bb29b7SVladimir Kondratiev /*---------info------------*/
152584bb29b7SVladimir Kondratiev static int wil_info_debugfs_show(struct seq_file *s, void *data)
152684bb29b7SVladimir Kondratiev {
1527be299858SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
1528e00243faSLior David 	struct net_device *ndev = wil->main_ndev;
152984bb29b7SVladimir Kondratiev 	int is_ac = power_supply_is_system_supplied();
1530be299858SVladimir Kondratiev 	int rx = atomic_xchg(&wil->isr_count_rx, 0);
1531be299858SVladimir Kondratiev 	int tx = atomic_xchg(&wil->isr_count_tx, 0);
1532be299858SVladimir Kondratiev 	static ulong rxf_old, txf_old;
1533be299858SVladimir Kondratiev 	ulong rxf = ndev->stats.rx_packets;
1534be299858SVladimir Kondratiev 	ulong txf = ndev->stats.tx_packets;
153555f8f680SVladimir Kondratiev 	unsigned int i;
153684bb29b7SVladimir Kondratiev 
153784bb29b7SVladimir Kondratiev 	/* >0 : AC; 0 : battery; <0 : error */
153884bb29b7SVladimir Kondratiev 	seq_printf(s, "AC powered : %d\n", is_ac);
1539be299858SVladimir Kondratiev 	seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
1540be299858SVladimir Kondratiev 	seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
1541be299858SVladimir Kondratiev 	rxf_old = rxf;
1542be299858SVladimir Kondratiev 	txf_old = txf;
154384bb29b7SVladimir Kondratiev 
154455f8f680SVladimir Kondratiev #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
154555f8f680SVladimir Kondratiev 	" " __stringify(x) : ""
154655f8f680SVladimir Kondratiev 
154755f8f680SVladimir Kondratiev 	for (i = 0; i < ndev->num_tx_queues; i++) {
154855f8f680SVladimir Kondratiev 		struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
154955f8f680SVladimir Kondratiev 		unsigned long state = txq->state;
155055f8f680SVladimir Kondratiev 
155155f8f680SVladimir Kondratiev 		seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
155255f8f680SVladimir Kondratiev 			   CHECK_QSTATE(DRV_XOFF),
155355f8f680SVladimir Kondratiev 			   CHECK_QSTATE(STACK_XOFF),
155455f8f680SVladimir Kondratiev 			   CHECK_QSTATE(FROZEN)
155555f8f680SVladimir Kondratiev 			  );
155655f8f680SVladimir Kondratiev 	}
155755f8f680SVladimir Kondratiev #undef CHECK_QSTATE
155884bb29b7SVladimir Kondratiev 	return 0;
155984bb29b7SVladimir Kondratiev }
156084bb29b7SVladimir Kondratiev 
156184bb29b7SVladimir Kondratiev static int wil_info_seq_open(struct inode *inode, struct file *file)
156284bb29b7SVladimir Kondratiev {
156384bb29b7SVladimir Kondratiev 	return single_open(file, wil_info_debugfs_show, inode->i_private);
156484bb29b7SVladimir Kondratiev }
156584bb29b7SVladimir Kondratiev 
156684bb29b7SVladimir Kondratiev static const struct file_operations fops_info = {
156784bb29b7SVladimir Kondratiev 	.open		= wil_info_seq_open,
156884bb29b7SVladimir Kondratiev 	.release	= single_release,
156984bb29b7SVladimir Kondratiev 	.read		= seq_read,
157084bb29b7SVladimir Kondratiev 	.llseek		= seq_lseek,
157184bb29b7SVladimir Kondratiev };
157284bb29b7SVladimir Kondratiev 
1573c33407a8SVladimir Kondratiev /*---------recovery------------*/
1574c33407a8SVladimir Kondratiev /* mode = [manual|auto]
1575c33407a8SVladimir Kondratiev  * state = [idle|pending|running]
1576c33407a8SVladimir Kondratiev  */
1577c33407a8SVladimir Kondratiev static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf,
1578c33407a8SVladimir Kondratiev 				      size_t count, loff_t *ppos)
1579c33407a8SVladimir Kondratiev {
1580c33407a8SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
1581c33407a8SVladimir Kondratiev 	char buf[80];
1582c33407a8SVladimir Kondratiev 	int n;
1583c33407a8SVladimir Kondratiev 	static const char * const sstate[] = {"idle", "pending", "running"};
1584c33407a8SVladimir Kondratiev 
1585c33407a8SVladimir Kondratiev 	n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n",
1586c33407a8SVladimir Kondratiev 		     no_fw_recovery ? "manual" : "auto",
1587c33407a8SVladimir Kondratiev 		     sstate[wil->recovery_state]);
1588c33407a8SVladimir Kondratiev 
1589c33407a8SVladimir Kondratiev 	n = min_t(int, n, sizeof(buf));
1590c33407a8SVladimir Kondratiev 
1591c33407a8SVladimir Kondratiev 	return simple_read_from_buffer(user_buf, count, ppos,
1592c33407a8SVladimir Kondratiev 				       buf, n);
1593c33407a8SVladimir Kondratiev }
1594c33407a8SVladimir Kondratiev 
1595c33407a8SVladimir Kondratiev static ssize_t wil_write_file_recovery(struct file *file,
1596c33407a8SVladimir Kondratiev 				       const char __user *buf_,
1597c33407a8SVladimir Kondratiev 				       size_t count, loff_t *ppos)
1598c33407a8SVladimir Kondratiev {
1599c33407a8SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
1600c33407a8SVladimir Kondratiev 	static const char run_command[] = "run";
1601c33407a8SVladimir Kondratiev 	char buf[sizeof(run_command) + 1]; /* to detect "runx" */
1602c33407a8SVladimir Kondratiev 	ssize_t rc;
1603c33407a8SVladimir Kondratiev 
1604c33407a8SVladimir Kondratiev 	if (wil->recovery_state != fw_recovery_pending) {
1605c33407a8SVladimir Kondratiev 		wil_err(wil, "No recovery pending\n");
1606c33407a8SVladimir Kondratiev 		return -EINVAL;
1607c33407a8SVladimir Kondratiev 	}
1608c33407a8SVladimir Kondratiev 
1609c33407a8SVladimir Kondratiev 	if (*ppos != 0) {
1610c33407a8SVladimir Kondratiev 		wil_err(wil, "Offset [%d]\n", (int)*ppos);
1611c33407a8SVladimir Kondratiev 		return -EINVAL;
1612c33407a8SVladimir Kondratiev 	}
1613c33407a8SVladimir Kondratiev 
1614c33407a8SVladimir Kondratiev 	if (count > sizeof(buf)) {
1615c33407a8SVladimir Kondratiev 		wil_err(wil, "Input too long, len = %d\n", (int)count);
1616c33407a8SVladimir Kondratiev 		return -EINVAL;
1617c33407a8SVladimir Kondratiev 	}
1618c33407a8SVladimir Kondratiev 
1619c33407a8SVladimir Kondratiev 	rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count);
1620c33407a8SVladimir Kondratiev 	if (rc < 0)
1621c33407a8SVladimir Kondratiev 		return rc;
1622c33407a8SVladimir Kondratiev 
1623c33407a8SVladimir Kondratiev 	buf[rc] = '\0';
1624c33407a8SVladimir Kondratiev 	if (0 == strcmp(buf, run_command))
1625c33407a8SVladimir Kondratiev 		wil_set_recovery_state(wil, fw_recovery_running);
1626c33407a8SVladimir Kondratiev 	else
1627c33407a8SVladimir Kondratiev 		wil_err(wil, "Bad recovery command \"%s\"\n", buf);
1628c33407a8SVladimir Kondratiev 
1629c33407a8SVladimir Kondratiev 	return rc;
1630c33407a8SVladimir Kondratiev }
1631c33407a8SVladimir Kondratiev 
1632c33407a8SVladimir Kondratiev static const struct file_operations fops_recovery = {
1633c33407a8SVladimir Kondratiev 	.read = wil_read_file_recovery,
1634c33407a8SVladimir Kondratiev 	.write = wil_write_file_recovery,
1635c33407a8SVladimir Kondratiev 	.open  = simple_open,
1636c33407a8SVladimir Kondratiev };
1637c33407a8SVladimir Kondratiev 
16383df2cd36SVladimir Kondratiev /*---------Station matrix------------*/
1639b4490f42SVladimir Kondratiev static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
1640b4490f42SVladimir Kondratiev {
1641b4490f42SVladimir Kondratiev 	int i;
1642b4490f42SVladimir Kondratiev 	u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
164391a8edccSVladimir Kondratiev 	unsigned long long drop_dup = r->drop_dup, drop_old = r->drop_old;
16441bd82ee0SDedy Lansky 	unsigned long long drop_dup_mcast = r->drop_dup_mcast;
16458fe59627SVladimir Kondratiev 
164637f8d26dSDedy Lansky 	seq_printf(s, "([%2d]) 0x%03x [", r->buf_size, r->head_seq_num);
1647b4490f42SVladimir Kondratiev 	for (i = 0; i < r->buf_size; i++) {
1648b4490f42SVladimir Kondratiev 		if (i == index)
1649b4490f42SVladimir Kondratiev 			seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
1650b4490f42SVladimir Kondratiev 		else
1651b4490f42SVladimir Kondratiev 			seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
1652b4490f42SVladimir Kondratiev 	}
165391a8edccSVladimir Kondratiev 	seq_printf(s,
16541bd82ee0SDedy Lansky 		   "] total %llu drop %llu (dup %llu + old %llu + dup mcast %llu) last 0x%03x\n",
16551bd82ee0SDedy Lansky 		   r->total, drop_dup + drop_old + drop_dup_mcast, drop_dup,
16561bd82ee0SDedy Lansky 		   drop_old, drop_dup_mcast, r->ssn_last_drop);
1657b4490f42SVladimir Kondratiev }
16583df2cd36SVladimir Kondratiev 
165958527421SVladimir Kondratiev static void wil_print_rxtid_crypto(struct seq_file *s, int tid,
166058527421SVladimir Kondratiev 				   struct wil_tid_crypto_rx *c)
166158527421SVladimir Kondratiev {
166258527421SVladimir Kondratiev 	int i;
166358527421SVladimir Kondratiev 
166458527421SVladimir Kondratiev 	for (i = 0; i < 4; i++) {
166558527421SVladimir Kondratiev 		struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
166658527421SVladimir Kondratiev 
166758527421SVladimir Kondratiev 		if (cc->key_set)
166858527421SVladimir Kondratiev 			goto has_keys;
166958527421SVladimir Kondratiev 	}
167058527421SVladimir Kondratiev 	return;
167158527421SVladimir Kondratiev 
167258527421SVladimir Kondratiev has_keys:
167358527421SVladimir Kondratiev 	if (tid < WIL_STA_TID_NUM)
167458527421SVladimir Kondratiev 		seq_printf(s, "  [%2d] PN", tid);
167558527421SVladimir Kondratiev 	else
167658527421SVladimir Kondratiev 		seq_puts(s, "  [GR] PN");
167758527421SVladimir Kondratiev 
167858527421SVladimir Kondratiev 	for (i = 0; i < 4; i++) {
167958527421SVladimir Kondratiev 		struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
168058527421SVladimir Kondratiev 
168158527421SVladimir Kondratiev 		seq_printf(s, " [%i%s]%6phN", i, cc->key_set ? "+" : "-",
168258527421SVladimir Kondratiev 			   cc->pn);
168358527421SVladimir Kondratiev 	}
168458527421SVladimir Kondratiev 	seq_puts(s, "\n");
168558527421SVladimir Kondratiev }
168658527421SVladimir Kondratiev 
16873df2cd36SVladimir Kondratiev static int wil_sta_debugfs_show(struct seq_file *s, void *data)
1688bd33273bSVladimir Kondratiev __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
16893df2cd36SVladimir Kondratiev {
16903df2cd36SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
1691c4a110d8SVladimir Kondratiev 	int i, tid, mcs;
16923df2cd36SVladimir Kondratiev 
16933df2cd36SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
16943df2cd36SVladimir Kondratiev 		struct wil_sta_info *p = &wil->sta[i];
16953df2cd36SVladimir Kondratiev 		char *status = "unknown";
16969d865ee2SLior David 		u8 aid = 0;
16975bd60982SLior David 		u8 mid;
16988fe59627SVladimir Kondratiev 
16993df2cd36SVladimir Kondratiev 		switch (p->status) {
17003df2cd36SVladimir Kondratiev 		case wil_sta_unused:
17013df2cd36SVladimir Kondratiev 			status = "unused   ";
17023df2cd36SVladimir Kondratiev 			break;
17033df2cd36SVladimir Kondratiev 		case wil_sta_conn_pending:
17043df2cd36SVladimir Kondratiev 			status = "pending  ";
17053df2cd36SVladimir Kondratiev 			break;
17063df2cd36SVladimir Kondratiev 		case wil_sta_connected:
17073df2cd36SVladimir Kondratiev 			status = "connected";
17089d865ee2SLior David 			aid = p->aid;
17093df2cd36SVladimir Kondratiev 			break;
17103df2cd36SVladimir Kondratiev 		}
17115bd60982SLior David 		mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
17125bd60982SLior David 		seq_printf(s, "[%d] %pM %s MID %d AID %d\n", i, p->addr, status,
17135bd60982SLior David 			   mid, aid);
1714b4490f42SVladimir Kondratiev 
1715b4490f42SVladimir Kondratiev 		if (p->status == wil_sta_connected) {
1716bd33273bSVladimir Kondratiev 			spin_lock_bh(&p->tid_rx_lock);
1717b4490f42SVladimir Kondratiev 			for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1718b4490f42SVladimir Kondratiev 				struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
171958527421SVladimir Kondratiev 				struct wil_tid_crypto_rx *c =
172058527421SVladimir Kondratiev 						&p->tid_crypto_rx[tid];
17218fe59627SVladimir Kondratiev 
1722b4490f42SVladimir Kondratiev 				if (r) {
1723b4490f42SVladimir Kondratiev 					seq_printf(s, "  [%2d] ", tid);
1724b4490f42SVladimir Kondratiev 					wil_print_rxtid(s, r);
1725b4490f42SVladimir Kondratiev 				}
172658527421SVladimir Kondratiev 
172758527421SVladimir Kondratiev 				wil_print_rxtid_crypto(s, tid, c);
1728b4490f42SVladimir Kondratiev 			}
172958527421SVladimir Kondratiev 			wil_print_rxtid_crypto(s, WIL_STA_TID_NUM,
173058527421SVladimir Kondratiev 					       &p->group_crypto_rx);
1731bd33273bSVladimir Kondratiev 			spin_unlock_bh(&p->tid_rx_lock);
17323b282bc6SVladimir Kondratiev 			seq_printf(s,
173358527421SVladimir Kondratiev 				   "Rx invalid frame: non-data %lu, short %lu, large %lu, replay %lu\n",
17343b282bc6SVladimir Kondratiev 				   p->stats.rx_non_data_frame,
17353b282bc6SVladimir Kondratiev 				   p->stats.rx_short_frame,
173658527421SVladimir Kondratiev 				   p->stats.rx_large_frame,
173758527421SVladimir Kondratiev 				   p->stats.rx_replay);
1738d98b8539SMaya Erez 			seq_printf(s,
17390b853210SMaya Erez 				   "mic error %lu, key error %lu, amsdu error %lu, csum error %lu\n",
1740d98b8539SMaya Erez 				   p->stats.rx_mic_error,
1741d98b8539SMaya Erez 				   p->stats.rx_key_error,
17420b853210SMaya Erez 				   p->stats.rx_amsdu_error,
17430b853210SMaya Erez 				   p->stats.rx_csum_err);
1744d98b8539SMaya Erez 
1745c4a110d8SVladimir Kondratiev 			seq_puts(s, "Rx/MCS:");
1746c4a110d8SVladimir Kondratiev 			for (mcs = 0; mcs < ARRAY_SIZE(p->stats.rx_per_mcs);
1747c4a110d8SVladimir Kondratiev 			     mcs++)
1748c4a110d8SVladimir Kondratiev 				seq_printf(s, " %lld",
1749c4a110d8SVladimir Kondratiev 					   p->stats.rx_per_mcs[mcs]);
1750c4a110d8SVladimir Kondratiev 			seq_puts(s, "\n");
1751b4490f42SVladimir Kondratiev 		}
17523df2cd36SVladimir Kondratiev 	}
17533df2cd36SVladimir Kondratiev 
17543df2cd36SVladimir Kondratiev 	return 0;
17553df2cd36SVladimir Kondratiev }
17563df2cd36SVladimir Kondratiev 
17573df2cd36SVladimir Kondratiev static int wil_sta_seq_open(struct inode *inode, struct file *file)
17583df2cd36SVladimir Kondratiev {
17593df2cd36SVladimir Kondratiev 	return single_open(file, wil_sta_debugfs_show, inode->i_private);
17603df2cd36SVladimir Kondratiev }
17613df2cd36SVladimir Kondratiev 
17623df2cd36SVladimir Kondratiev static const struct file_operations fops_sta = {
17633df2cd36SVladimir Kondratiev 	.open		= wil_sta_seq_open,
17643df2cd36SVladimir Kondratiev 	.release	= single_release,
17653df2cd36SVladimir Kondratiev 	.read		= seq_read,
17663df2cd36SVladimir Kondratiev 	.llseek		= seq_lseek,
17673df2cd36SVladimir Kondratiev };
17683df2cd36SVladimir Kondratiev 
17693a3b745fSLior David static int wil_mids_debugfs_show(struct seq_file *s, void *data)
17703a3b745fSLior David {
17713a3b745fSLior David 	struct wil6210_priv *wil = s->private;
17723a3b745fSLior David 	struct wil6210_vif *vif;
17733a3b745fSLior David 	struct net_device *ndev;
17743a3b745fSLior David 	int i;
17753a3b745fSLior David 
17763a3b745fSLior David 	mutex_lock(&wil->vif_mutex);
17773a3b745fSLior David 	for (i = 0; i < wil->max_vifs; i++) {
17783a3b745fSLior David 		vif = wil->vifs[i];
17793a3b745fSLior David 
17803a3b745fSLior David 		if (vif) {
17813a3b745fSLior David 			ndev = vif_to_ndev(vif);
17823a3b745fSLior David 			seq_printf(s, "[%d] %pM %s\n", i, ndev->dev_addr,
17833a3b745fSLior David 				   ndev->name);
17843a3b745fSLior David 		} else {
17853a3b745fSLior David 			seq_printf(s, "[%d] unused\n", i);
17863a3b745fSLior David 		}
17873a3b745fSLior David 	}
17883a3b745fSLior David 	mutex_unlock(&wil->vif_mutex);
17893a3b745fSLior David 
17903a3b745fSLior David 	return 0;
17913a3b745fSLior David }
17923a3b745fSLior David 
17933a3b745fSLior David static int wil_mids_seq_open(struct inode *inode, struct file *file)
17943a3b745fSLior David {
17953a3b745fSLior David 	return single_open(file, wil_mids_debugfs_show, inode->i_private);
17963a3b745fSLior David }
17973a3b745fSLior David 
17983a3b745fSLior David static const struct file_operations fops_mids = {
17993a3b745fSLior David 	.open		= wil_mids_seq_open,
18003a3b745fSLior David 	.release	= single_release,
18013a3b745fSLior David 	.read		= seq_read,
18023a3b745fSLior David 	.llseek		= seq_lseek,
18033a3b745fSLior David };
18043a3b745fSLior David 
1805a24a3d6aSDedy Lansky static int wil_tx_latency_debugfs_show(struct seq_file *s, void *data)
1806a24a3d6aSDedy Lansky __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
1807a24a3d6aSDedy Lansky {
1808a24a3d6aSDedy Lansky 	struct wil6210_priv *wil = s->private;
1809a24a3d6aSDedy Lansky 	int i, bin;
1810a24a3d6aSDedy Lansky 
1811a24a3d6aSDedy Lansky 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1812a24a3d6aSDedy Lansky 		struct wil_sta_info *p = &wil->sta[i];
1813a24a3d6aSDedy Lansky 		char *status = "unknown";
1814a24a3d6aSDedy Lansky 		u8 aid = 0;
1815a24a3d6aSDedy Lansky 		u8 mid;
1816a24a3d6aSDedy Lansky 
1817a24a3d6aSDedy Lansky 		if (!p->tx_latency_bins)
1818a24a3d6aSDedy Lansky 			continue;
1819a24a3d6aSDedy Lansky 
1820a24a3d6aSDedy Lansky 		switch (p->status) {
1821a24a3d6aSDedy Lansky 		case wil_sta_unused:
1822a24a3d6aSDedy Lansky 			status = "unused   ";
1823a24a3d6aSDedy Lansky 			break;
1824a24a3d6aSDedy Lansky 		case wil_sta_conn_pending:
1825a24a3d6aSDedy Lansky 			status = "pending  ";
1826a24a3d6aSDedy Lansky 			break;
1827a24a3d6aSDedy Lansky 		case wil_sta_connected:
1828a24a3d6aSDedy Lansky 			status = "connected";
1829a24a3d6aSDedy Lansky 			aid = p->aid;
1830a24a3d6aSDedy Lansky 			break;
1831a24a3d6aSDedy Lansky 		}
1832a24a3d6aSDedy Lansky 		mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
1833a24a3d6aSDedy Lansky 		seq_printf(s, "[%d] %pM %s MID %d AID %d\n", i, p->addr, status,
1834a24a3d6aSDedy Lansky 			   mid, aid);
1835a24a3d6aSDedy Lansky 
1836a24a3d6aSDedy Lansky 		if (p->status == wil_sta_connected) {
1837a24a3d6aSDedy Lansky 			u64 num_packets = 0;
1838a24a3d6aSDedy Lansky 			u64 tx_latency_avg = p->stats.tx_latency_total_us;
1839a24a3d6aSDedy Lansky 
1840a24a3d6aSDedy Lansky 			seq_puts(s, "Tx/Latency bin:");
1841a24a3d6aSDedy Lansky 			for (bin = 0; bin < WIL_NUM_LATENCY_BINS; bin++) {
1842a24a3d6aSDedy Lansky 				seq_printf(s, " %lld",
1843a24a3d6aSDedy Lansky 					   p->tx_latency_bins[bin]);
1844a24a3d6aSDedy Lansky 				num_packets += p->tx_latency_bins[bin];
1845a24a3d6aSDedy Lansky 			}
1846a24a3d6aSDedy Lansky 			seq_puts(s, "\n");
1847a24a3d6aSDedy Lansky 			if (!num_packets)
1848a24a3d6aSDedy Lansky 				continue;
1849a24a3d6aSDedy Lansky 			do_div(tx_latency_avg, num_packets);
1850a24a3d6aSDedy Lansky 			seq_printf(s, "Tx/Latency min/avg/max (us): %d/%lld/%d",
1851a24a3d6aSDedy Lansky 				   p->stats.tx_latency_min_us,
1852a24a3d6aSDedy Lansky 				   tx_latency_avg,
1853a24a3d6aSDedy Lansky 				   p->stats.tx_latency_max_us);
1854a24a3d6aSDedy Lansky 
1855a24a3d6aSDedy Lansky 			seq_puts(s, "\n");
1856a24a3d6aSDedy Lansky 		}
1857a24a3d6aSDedy Lansky 	}
1858a24a3d6aSDedy Lansky 
1859a24a3d6aSDedy Lansky 	return 0;
1860a24a3d6aSDedy Lansky }
1861a24a3d6aSDedy Lansky 
1862a24a3d6aSDedy Lansky static int wil_tx_latency_seq_open(struct inode *inode, struct file *file)
1863a24a3d6aSDedy Lansky {
1864a24a3d6aSDedy Lansky 	return single_open(file, wil_tx_latency_debugfs_show,
1865a24a3d6aSDedy Lansky 			   inode->i_private);
1866a24a3d6aSDedy Lansky }
1867a24a3d6aSDedy Lansky 
1868a24a3d6aSDedy Lansky static ssize_t wil_tx_latency_write(struct file *file, const char __user *buf,
1869a24a3d6aSDedy Lansky 				    size_t len, loff_t *ppos)
1870a24a3d6aSDedy Lansky {
1871a24a3d6aSDedy Lansky 	struct seq_file *s = file->private_data;
1872a24a3d6aSDedy Lansky 	struct wil6210_priv *wil = s->private;
1873a24a3d6aSDedy Lansky 	int val, rc, i;
1874a24a3d6aSDedy Lansky 	bool enable;
1875a24a3d6aSDedy Lansky 
1876a24a3d6aSDedy Lansky 	rc = kstrtoint_from_user(buf, len, 0, &val);
1877a24a3d6aSDedy Lansky 	if (rc) {
1878a24a3d6aSDedy Lansky 		wil_err(wil, "Invalid argument\n");
1879a24a3d6aSDedy Lansky 		return rc;
1880a24a3d6aSDedy Lansky 	}
1881a24a3d6aSDedy Lansky 	if (val == 1)
1882a24a3d6aSDedy Lansky 		/* default resolution */
1883a24a3d6aSDedy Lansky 		val = 500;
1884a24a3d6aSDedy Lansky 	if (val && (val < 50 || val > 1000)) {
1885a24a3d6aSDedy Lansky 		wil_err(wil, "Invalid resolution %d\n", val);
1886a24a3d6aSDedy Lansky 		return -EINVAL;
1887a24a3d6aSDedy Lansky 	}
1888a24a3d6aSDedy Lansky 
1889a24a3d6aSDedy Lansky 	enable = !!val;
1890a24a3d6aSDedy Lansky 	if (wil->tx_latency == enable)
1891a24a3d6aSDedy Lansky 		return len;
1892a24a3d6aSDedy Lansky 
1893a24a3d6aSDedy Lansky 	wil_info(wil, "%s TX latency measurements (resolution %dusec)\n",
1894a24a3d6aSDedy Lansky 		 enable ? "Enabling" : "Disabling", val);
1895a24a3d6aSDedy Lansky 
1896a24a3d6aSDedy Lansky 	if (enable) {
1897a24a3d6aSDedy Lansky 		size_t sz = sizeof(u64) * WIL_NUM_LATENCY_BINS;
1898a24a3d6aSDedy Lansky 
1899a24a3d6aSDedy Lansky 		wil->tx_latency_res = val;
1900a24a3d6aSDedy Lansky 		for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1901a24a3d6aSDedy Lansky 			struct wil_sta_info *sta = &wil->sta[i];
1902a24a3d6aSDedy Lansky 
1903a24a3d6aSDedy Lansky 			kfree(sta->tx_latency_bins);
1904a24a3d6aSDedy Lansky 			sta->tx_latency_bins = kzalloc(sz, GFP_KERNEL);
1905a24a3d6aSDedy Lansky 			if (!sta->tx_latency_bins)
1906a24a3d6aSDedy Lansky 				return -ENOMEM;
1907a24a3d6aSDedy Lansky 			sta->stats.tx_latency_min_us = U32_MAX;
1908a24a3d6aSDedy Lansky 			sta->stats.tx_latency_max_us = 0;
1909a24a3d6aSDedy Lansky 			sta->stats.tx_latency_total_us = 0;
1910a24a3d6aSDedy Lansky 		}
1911a24a3d6aSDedy Lansky 	}
1912a24a3d6aSDedy Lansky 	wil->tx_latency = enable;
1913a24a3d6aSDedy Lansky 
1914a24a3d6aSDedy Lansky 	return len;
1915a24a3d6aSDedy Lansky }
1916a24a3d6aSDedy Lansky 
1917a24a3d6aSDedy Lansky static const struct file_operations fops_tx_latency = {
1918a24a3d6aSDedy Lansky 	.open		= wil_tx_latency_seq_open,
1919a24a3d6aSDedy Lansky 	.release	= single_release,
1920a24a3d6aSDedy Lansky 	.read		= seq_read,
1921a24a3d6aSDedy Lansky 	.write		= wil_tx_latency_write,
1922a24a3d6aSDedy Lansky 	.llseek		= seq_lseek,
1923a24a3d6aSDedy Lansky };
1924a24a3d6aSDedy Lansky 
1925*0c936b3cSDedy Lansky static void wil_link_stats_print_basic(struct wil6210_vif *vif,
1926*0c936b3cSDedy Lansky 				       struct seq_file *s,
1927*0c936b3cSDedy Lansky 				       struct wmi_link_stats_basic *basic)
1928*0c936b3cSDedy Lansky {
1929*0c936b3cSDedy Lansky 	char per[5] = "?";
1930*0c936b3cSDedy Lansky 
1931*0c936b3cSDedy Lansky 	if (basic->per_average != 0xff)
1932*0c936b3cSDedy Lansky 		snprintf(per, sizeof(per), "%d%%", basic->per_average);
1933*0c936b3cSDedy Lansky 
1934*0c936b3cSDedy Lansky 	seq_printf(s, "CID %d {\n"
1935*0c936b3cSDedy Lansky 		   "\tTxMCS %d TxTpt %d\n"
1936*0c936b3cSDedy Lansky 		   "\tGoodput(rx:tx) %d:%d\n"
1937*0c936b3cSDedy Lansky 		   "\tRxBcastFrames %d\n"
1938*0c936b3cSDedy Lansky 		   "\tRSSI %d SQI %d SNR %d PER %s\n"
1939*0c936b3cSDedy Lansky 		   "\tRx RFC %d Ant num %d\n"
1940*0c936b3cSDedy Lansky 		   "\tSectors(rx:tx) my %d:%d peer %d:%d\n"
1941*0c936b3cSDedy Lansky 		   "}\n",
1942*0c936b3cSDedy Lansky 		   basic->cid,
1943*0c936b3cSDedy Lansky 		   basic->bf_mcs, le32_to_cpu(basic->tx_tpt),
1944*0c936b3cSDedy Lansky 		   le32_to_cpu(basic->rx_goodput),
1945*0c936b3cSDedy Lansky 		   le32_to_cpu(basic->tx_goodput),
1946*0c936b3cSDedy Lansky 		   le32_to_cpu(basic->rx_bcast_frames),
1947*0c936b3cSDedy Lansky 		   basic->rssi, basic->sqi, basic->snr, per,
1948*0c936b3cSDedy Lansky 		   basic->selected_rfc, basic->rx_effective_ant_num,
1949*0c936b3cSDedy Lansky 		   basic->my_rx_sector, basic->my_tx_sector,
1950*0c936b3cSDedy Lansky 		   basic->other_rx_sector, basic->other_tx_sector);
1951*0c936b3cSDedy Lansky }
1952*0c936b3cSDedy Lansky 
1953*0c936b3cSDedy Lansky static void wil_link_stats_print_global(struct wil6210_priv *wil,
1954*0c936b3cSDedy Lansky 					struct seq_file *s,
1955*0c936b3cSDedy Lansky 					struct wmi_link_stats_global *global)
1956*0c936b3cSDedy Lansky {
1957*0c936b3cSDedy Lansky 	seq_printf(s, "Frames(rx:tx) %d:%d\n"
1958*0c936b3cSDedy Lansky 		   "BA Frames(rx:tx) %d:%d\n"
1959*0c936b3cSDedy Lansky 		   "Beacons %d\n"
1960*0c936b3cSDedy Lansky 		   "Rx Errors (MIC:CRC) %d:%d\n"
1961*0c936b3cSDedy Lansky 		   "Tx Errors (no ack) %d\n",
1962*0c936b3cSDedy Lansky 		   le32_to_cpu(global->rx_frames),
1963*0c936b3cSDedy Lansky 		   le32_to_cpu(global->tx_frames),
1964*0c936b3cSDedy Lansky 		   le32_to_cpu(global->rx_ba_frames),
1965*0c936b3cSDedy Lansky 		   le32_to_cpu(global->tx_ba_frames),
1966*0c936b3cSDedy Lansky 		   le32_to_cpu(global->tx_beacons),
1967*0c936b3cSDedy Lansky 		   le32_to_cpu(global->rx_mic_errors),
1968*0c936b3cSDedy Lansky 		   le32_to_cpu(global->rx_crc_errors),
1969*0c936b3cSDedy Lansky 		   le32_to_cpu(global->tx_fail_no_ack));
1970*0c936b3cSDedy Lansky }
1971*0c936b3cSDedy Lansky 
1972*0c936b3cSDedy Lansky static void wil_link_stats_debugfs_show_vif(struct wil6210_vif *vif,
1973*0c936b3cSDedy Lansky 					    struct seq_file *s)
1974*0c936b3cSDedy Lansky {
1975*0c936b3cSDedy Lansky 	struct wil6210_priv *wil = vif_to_wil(vif);
1976*0c936b3cSDedy Lansky 	struct wmi_link_stats_basic *stats;
1977*0c936b3cSDedy Lansky 	int i;
1978*0c936b3cSDedy Lansky 
1979*0c936b3cSDedy Lansky 	if (!vif->fw_stats_ready) {
1980*0c936b3cSDedy Lansky 		seq_puts(s, "no statistics\n");
1981*0c936b3cSDedy Lansky 		return;
1982*0c936b3cSDedy Lansky 	}
1983*0c936b3cSDedy Lansky 
1984*0c936b3cSDedy Lansky 	seq_printf(s, "TSF %lld\n", vif->fw_stats_tsf);
1985*0c936b3cSDedy Lansky 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1986*0c936b3cSDedy Lansky 		if (wil->sta[i].status == wil_sta_unused)
1987*0c936b3cSDedy Lansky 			continue;
1988*0c936b3cSDedy Lansky 		if (wil->sta[i].mid != vif->mid)
1989*0c936b3cSDedy Lansky 			continue;
1990*0c936b3cSDedy Lansky 
1991*0c936b3cSDedy Lansky 		stats = &wil->sta[i].fw_stats_basic;
1992*0c936b3cSDedy Lansky 		wil_link_stats_print_basic(vif, s, stats);
1993*0c936b3cSDedy Lansky 	}
1994*0c936b3cSDedy Lansky }
1995*0c936b3cSDedy Lansky 
1996*0c936b3cSDedy Lansky static int wil_link_stats_debugfs_show(struct seq_file *s, void *data)
1997*0c936b3cSDedy Lansky {
1998*0c936b3cSDedy Lansky 	struct wil6210_priv *wil = s->private;
1999*0c936b3cSDedy Lansky 	struct wil6210_vif *vif;
2000*0c936b3cSDedy Lansky 	int i, rc;
2001*0c936b3cSDedy Lansky 
2002*0c936b3cSDedy Lansky 	rc = mutex_lock_interruptible(&wil->vif_mutex);
2003*0c936b3cSDedy Lansky 	if (rc)
2004*0c936b3cSDedy Lansky 		return rc;
2005*0c936b3cSDedy Lansky 
2006*0c936b3cSDedy Lansky 	/* iterate over all MIDs and show per-cid statistics. Then show the
2007*0c936b3cSDedy Lansky 	 * global statistics
2008*0c936b3cSDedy Lansky 	 */
2009*0c936b3cSDedy Lansky 	for (i = 0; i < wil->max_vifs; i++) {
2010*0c936b3cSDedy Lansky 		vif = wil->vifs[i];
2011*0c936b3cSDedy Lansky 
2012*0c936b3cSDedy Lansky 		seq_printf(s, "MID %d ", i);
2013*0c936b3cSDedy Lansky 		if (!vif) {
2014*0c936b3cSDedy Lansky 			seq_puts(s, "unused\n");
2015*0c936b3cSDedy Lansky 			continue;
2016*0c936b3cSDedy Lansky 		}
2017*0c936b3cSDedy Lansky 
2018*0c936b3cSDedy Lansky 		wil_link_stats_debugfs_show_vif(vif, s);
2019*0c936b3cSDedy Lansky 	}
2020*0c936b3cSDedy Lansky 
2021*0c936b3cSDedy Lansky 	mutex_unlock(&wil->vif_mutex);
2022*0c936b3cSDedy Lansky 
2023*0c936b3cSDedy Lansky 	return 0;
2024*0c936b3cSDedy Lansky }
2025*0c936b3cSDedy Lansky 
2026*0c936b3cSDedy Lansky static int wil_link_stats_seq_open(struct inode *inode, struct file *file)
2027*0c936b3cSDedy Lansky {
2028*0c936b3cSDedy Lansky 	return single_open(file, wil_link_stats_debugfs_show, inode->i_private);
2029*0c936b3cSDedy Lansky }
2030*0c936b3cSDedy Lansky 
2031*0c936b3cSDedy Lansky static ssize_t wil_link_stats_write(struct file *file, const char __user *buf,
2032*0c936b3cSDedy Lansky 				    size_t len, loff_t *ppos)
2033*0c936b3cSDedy Lansky {
2034*0c936b3cSDedy Lansky 	struct seq_file *s = file->private_data;
2035*0c936b3cSDedy Lansky 	struct wil6210_priv *wil = s->private;
2036*0c936b3cSDedy Lansky 	int cid, interval, rc, i;
2037*0c936b3cSDedy Lansky 	struct wil6210_vif *vif;
2038*0c936b3cSDedy Lansky 	char *kbuf = kmalloc(len + 1, GFP_KERNEL);
2039*0c936b3cSDedy Lansky 
2040*0c936b3cSDedy Lansky 	if (!kbuf)
2041*0c936b3cSDedy Lansky 		return -ENOMEM;
2042*0c936b3cSDedy Lansky 
2043*0c936b3cSDedy Lansky 	rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
2044*0c936b3cSDedy Lansky 	if (rc != len) {
2045*0c936b3cSDedy Lansky 		kfree(kbuf);
2046*0c936b3cSDedy Lansky 		return rc >= 0 ? -EIO : rc;
2047*0c936b3cSDedy Lansky 	}
2048*0c936b3cSDedy Lansky 
2049*0c936b3cSDedy Lansky 	kbuf[len] = '\0';
2050*0c936b3cSDedy Lansky 	/* specify cid (use -1 for all cids) and snapshot interval in ms */
2051*0c936b3cSDedy Lansky 	rc = sscanf(kbuf, "%d %d", &cid, &interval);
2052*0c936b3cSDedy Lansky 	kfree(kbuf);
2053*0c936b3cSDedy Lansky 	if (rc < 0)
2054*0c936b3cSDedy Lansky 		return rc;
2055*0c936b3cSDedy Lansky 	if (rc < 2 || interval < 0)
2056*0c936b3cSDedy Lansky 		return -EINVAL;
2057*0c936b3cSDedy Lansky 
2058*0c936b3cSDedy Lansky 	wil_info(wil, "request link statistics, cid %d interval %d\n",
2059*0c936b3cSDedy Lansky 		 cid, interval);
2060*0c936b3cSDedy Lansky 
2061*0c936b3cSDedy Lansky 	rc = mutex_lock_interruptible(&wil->vif_mutex);
2062*0c936b3cSDedy Lansky 	if (rc)
2063*0c936b3cSDedy Lansky 		return rc;
2064*0c936b3cSDedy Lansky 
2065*0c936b3cSDedy Lansky 	for (i = 0; i < wil->max_vifs; i++) {
2066*0c936b3cSDedy Lansky 		vif = wil->vifs[i];
2067*0c936b3cSDedy Lansky 		if (!vif)
2068*0c936b3cSDedy Lansky 			continue;
2069*0c936b3cSDedy Lansky 
2070*0c936b3cSDedy Lansky 		rc = wmi_link_stats_cfg(vif, WMI_LINK_STATS_TYPE_BASIC,
2071*0c936b3cSDedy Lansky 					(cid == -1 ? 0xff : cid), interval);
2072*0c936b3cSDedy Lansky 		if (rc)
2073*0c936b3cSDedy Lansky 			wil_err(wil, "link statistics failed for mid %d\n", i);
2074*0c936b3cSDedy Lansky 	}
2075*0c936b3cSDedy Lansky 	mutex_unlock(&wil->vif_mutex);
2076*0c936b3cSDedy Lansky 
2077*0c936b3cSDedy Lansky 	return len;
2078*0c936b3cSDedy Lansky }
2079*0c936b3cSDedy Lansky 
2080*0c936b3cSDedy Lansky static const struct file_operations fops_link_stats = {
2081*0c936b3cSDedy Lansky 	.open		= wil_link_stats_seq_open,
2082*0c936b3cSDedy Lansky 	.release	= single_release,
2083*0c936b3cSDedy Lansky 	.read		= seq_read,
2084*0c936b3cSDedy Lansky 	.write		= wil_link_stats_write,
2085*0c936b3cSDedy Lansky 	.llseek		= seq_lseek,
2086*0c936b3cSDedy Lansky };
2087*0c936b3cSDedy Lansky 
2088*0c936b3cSDedy Lansky static int
2089*0c936b3cSDedy Lansky wil_link_stats_global_debugfs_show(struct seq_file *s, void *data)
2090*0c936b3cSDedy Lansky {
2091*0c936b3cSDedy Lansky 	struct wil6210_priv *wil = s->private;
2092*0c936b3cSDedy Lansky 
2093*0c936b3cSDedy Lansky 	if (!wil->fw_stats_global.ready)
2094*0c936b3cSDedy Lansky 		return 0;
2095*0c936b3cSDedy Lansky 
2096*0c936b3cSDedy Lansky 	seq_printf(s, "TSF %lld\n", wil->fw_stats_global.tsf);
2097*0c936b3cSDedy Lansky 	wil_link_stats_print_global(wil, s, &wil->fw_stats_global.stats);
2098*0c936b3cSDedy Lansky 
2099*0c936b3cSDedy Lansky 	return 0;
2100*0c936b3cSDedy Lansky }
2101*0c936b3cSDedy Lansky 
2102*0c936b3cSDedy Lansky static int
2103*0c936b3cSDedy Lansky wil_link_stats_global_seq_open(struct inode *inode, struct file *file)
2104*0c936b3cSDedy Lansky {
2105*0c936b3cSDedy Lansky 	return single_open(file, wil_link_stats_global_debugfs_show,
2106*0c936b3cSDedy Lansky 			   inode->i_private);
2107*0c936b3cSDedy Lansky }
2108*0c936b3cSDedy Lansky 
2109*0c936b3cSDedy Lansky static ssize_t
2110*0c936b3cSDedy Lansky wil_link_stats_global_write(struct file *file, const char __user *buf,
2111*0c936b3cSDedy Lansky 			    size_t len, loff_t *ppos)
2112*0c936b3cSDedy Lansky {
2113*0c936b3cSDedy Lansky 	struct seq_file *s = file->private_data;
2114*0c936b3cSDedy Lansky 	struct wil6210_priv *wil = s->private;
2115*0c936b3cSDedy Lansky 	int interval, rc;
2116*0c936b3cSDedy Lansky 	struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
2117*0c936b3cSDedy Lansky 
2118*0c936b3cSDedy Lansky 	/* specify snapshot interval in ms */
2119*0c936b3cSDedy Lansky 	rc = kstrtoint_from_user(buf, len, 0, &interval);
2120*0c936b3cSDedy Lansky 	if (rc || interval < 0) {
2121*0c936b3cSDedy Lansky 		wil_err(wil, "Invalid argument\n");
2122*0c936b3cSDedy Lansky 		return -EINVAL;
2123*0c936b3cSDedy Lansky 	}
2124*0c936b3cSDedy Lansky 
2125*0c936b3cSDedy Lansky 	wil_info(wil, "request global link stats, interval %d\n", interval);
2126*0c936b3cSDedy Lansky 
2127*0c936b3cSDedy Lansky 	rc = wmi_link_stats_cfg(vif, WMI_LINK_STATS_TYPE_GLOBAL, 0, interval);
2128*0c936b3cSDedy Lansky 	if (rc)
2129*0c936b3cSDedy Lansky 		wil_err(wil, "global link stats failed %d\n", rc);
2130*0c936b3cSDedy Lansky 
2131*0c936b3cSDedy Lansky 	return rc ? rc : len;
2132*0c936b3cSDedy Lansky }
2133*0c936b3cSDedy Lansky 
2134*0c936b3cSDedy Lansky static const struct file_operations fops_link_stats_global = {
2135*0c936b3cSDedy Lansky 	.open		= wil_link_stats_global_seq_open,
2136*0c936b3cSDedy Lansky 	.release	= single_release,
2137*0c936b3cSDedy Lansky 	.read		= seq_read,
2138*0c936b3cSDedy Lansky 	.write		= wil_link_stats_global_write,
2139*0c936b3cSDedy Lansky 	.llseek		= seq_lseek,
2140*0c936b3cSDedy Lansky };
2141*0c936b3cSDedy Lansky 
214210d599adSMaya Erez static ssize_t wil_read_file_led_cfg(struct file *file, char __user *user_buf,
214310d599adSMaya Erez 				     size_t count, loff_t *ppos)
214410d599adSMaya Erez {
214510d599adSMaya Erez 	char buf[80];
214610d599adSMaya Erez 	int n;
214710d599adSMaya Erez 
214810d599adSMaya Erez 	n = snprintf(buf, sizeof(buf),
214910d599adSMaya Erez 		     "led_id is set to %d, echo 1 to enable, 0 to disable\n",
215010d599adSMaya Erez 		     led_id);
215110d599adSMaya Erez 
215210d599adSMaya Erez 	n = min_t(int, n, sizeof(buf));
215310d599adSMaya Erez 
215410d599adSMaya Erez 	return simple_read_from_buffer(user_buf, count, ppos,
215510d599adSMaya Erez 				       buf, n);
215610d599adSMaya Erez }
215710d599adSMaya Erez 
215810d599adSMaya Erez static ssize_t wil_write_file_led_cfg(struct file *file,
215910d599adSMaya Erez 				      const char __user *buf_,
216010d599adSMaya Erez 				      size_t count, loff_t *ppos)
216110d599adSMaya Erez {
216210d599adSMaya Erez 	struct wil6210_priv *wil = file->private_data;
216310d599adSMaya Erez 	int val;
216410d599adSMaya Erez 	int rc;
216510d599adSMaya Erez 
216610d599adSMaya Erez 	rc = kstrtoint_from_user(buf_, count, 0, &val);
216710d599adSMaya Erez 	if (rc) {
216810d599adSMaya Erez 		wil_err(wil, "Invalid argument\n");
216910d599adSMaya Erez 		return rc;
217010d599adSMaya Erez 	}
217110d599adSMaya Erez 
217210d599adSMaya Erez 	wil_info(wil, "%s led %d\n", val ? "Enabling" : "Disabling", led_id);
217310d599adSMaya Erez 	rc = wmi_led_cfg(wil, val);
217410d599adSMaya Erez 	if (rc) {
217510d599adSMaya Erez 		wil_info(wil, "%s led %d failed\n",
217610d599adSMaya Erez 			 val ? "Enabling" : "Disabling", led_id);
217710d599adSMaya Erez 		return rc;
217810d599adSMaya Erez 	}
217910d599adSMaya Erez 
218010d599adSMaya Erez 	return count;
218110d599adSMaya Erez }
218210d599adSMaya Erez 
218310d599adSMaya Erez static const struct file_operations fops_led_cfg = {
218410d599adSMaya Erez 	.read = wil_read_file_led_cfg,
218510d599adSMaya Erez 	.write = wil_write_file_led_cfg,
218610d599adSMaya Erez 	.open  = simple_open,
218710d599adSMaya Erez };
218810d599adSMaya Erez 
218910d599adSMaya Erez /* led_blink_time, write:
219010d599adSMaya Erez  * "<blink_on_slow> <blink_off_slow> <blink_on_med> <blink_off_med> <blink_on_fast> <blink_off_fast>
219110d599adSMaya Erez  */
219210d599adSMaya Erez static ssize_t wil_write_led_blink_time(struct file *file,
219310d599adSMaya Erez 					const char __user *buf,
219410d599adSMaya Erez 					size_t len, loff_t *ppos)
219510d599adSMaya Erez {
219610d599adSMaya Erez 	int rc;
219710d599adSMaya Erez 	char *kbuf = kmalloc(len + 1, GFP_KERNEL);
219810d599adSMaya Erez 
219910d599adSMaya Erez 	if (!kbuf)
220010d599adSMaya Erez 		return -ENOMEM;
220110d599adSMaya Erez 
220210d599adSMaya Erez 	rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
220310d599adSMaya Erez 	if (rc != len) {
220410d599adSMaya Erez 		kfree(kbuf);
220510d599adSMaya Erez 		return rc >= 0 ? -EIO : rc;
220610d599adSMaya Erez 	}
220710d599adSMaya Erez 
220810d599adSMaya Erez 	kbuf[len] = '\0';
220910d599adSMaya Erez 	rc = sscanf(kbuf, "%d %d %d %d %d %d",
221010d599adSMaya Erez 		    &led_blink_time[WIL_LED_TIME_SLOW].on_ms,
221110d599adSMaya Erez 		    &led_blink_time[WIL_LED_TIME_SLOW].off_ms,
221210d599adSMaya Erez 		    &led_blink_time[WIL_LED_TIME_MED].on_ms,
221310d599adSMaya Erez 		    &led_blink_time[WIL_LED_TIME_MED].off_ms,
221410d599adSMaya Erez 		    &led_blink_time[WIL_LED_TIME_FAST].on_ms,
221510d599adSMaya Erez 		    &led_blink_time[WIL_LED_TIME_FAST].off_ms);
221610d599adSMaya Erez 	kfree(kbuf);
221710d599adSMaya Erez 
221810d599adSMaya Erez 	if (rc < 0)
221910d599adSMaya Erez 		return rc;
222010d599adSMaya Erez 	if (rc < 6)
222110d599adSMaya Erez 		return -EINVAL;
222210d599adSMaya Erez 
222310d599adSMaya Erez 	return len;
222410d599adSMaya Erez }
222510d599adSMaya Erez 
222610d599adSMaya Erez static ssize_t wil_read_led_blink_time(struct file *file, char __user *user_buf,
222710d599adSMaya Erez 				       size_t count, loff_t *ppos)
222810d599adSMaya Erez {
222910d599adSMaya Erez 	static char text[400];
223010d599adSMaya Erez 
223110d599adSMaya Erez 	snprintf(text, sizeof(text),
223210d599adSMaya Erez 		 "To set led blink on/off time variables write:\n"
223310d599adSMaya Erez 		 "<blink_on_slow> <blink_off_slow> <blink_on_med> "
223410d599adSMaya Erez 		 "<blink_off_med> <blink_on_fast> <blink_off_fast>\n"
223510d599adSMaya Erez 		 "The current values are:\n"
223610d599adSMaya Erez 		 "%d %d %d %d %d %d\n",
223710d599adSMaya Erez 		 led_blink_time[WIL_LED_TIME_SLOW].on_ms,
223810d599adSMaya Erez 		 led_blink_time[WIL_LED_TIME_SLOW].off_ms,
223910d599adSMaya Erez 		 led_blink_time[WIL_LED_TIME_MED].on_ms,
224010d599adSMaya Erez 		 led_blink_time[WIL_LED_TIME_MED].off_ms,
224110d599adSMaya Erez 		 led_blink_time[WIL_LED_TIME_FAST].on_ms,
224210d599adSMaya Erez 		 led_blink_time[WIL_LED_TIME_FAST].off_ms);
224310d599adSMaya Erez 
224410d599adSMaya Erez 	return simple_read_from_buffer(user_buf, count, ppos, text,
224510d599adSMaya Erez 				       sizeof(text));
224610d599adSMaya Erez }
224710d599adSMaya Erez 
224810d599adSMaya Erez static const struct file_operations fops_led_blink_time = {
224910d599adSMaya Erez 	.read = wil_read_led_blink_time,
225010d599adSMaya Erez 	.write = wil_write_led_blink_time,
225110d599adSMaya Erez 	.open  = simple_open,
225210d599adSMaya Erez };
225310d599adSMaya Erez 
225412bace75SLior David /*---------FW capabilities------------*/
225512bace75SLior David static int wil_fw_capabilities_debugfs_show(struct seq_file *s, void *data)
225612bace75SLior David {
225712bace75SLior David 	struct wil6210_priv *wil = s->private;
225812bace75SLior David 
225912bace75SLior David 	seq_printf(s, "fw_capabilities : %*pb\n", WMI_FW_CAPABILITY_MAX,
226012bace75SLior David 		   wil->fw_capabilities);
226112bace75SLior David 
226212bace75SLior David 	return 0;
226312bace75SLior David }
226412bace75SLior David 
226512bace75SLior David static int wil_fw_capabilities_seq_open(struct inode *inode, struct file *file)
226612bace75SLior David {
226712bace75SLior David 	return single_open(file, wil_fw_capabilities_debugfs_show,
226812bace75SLior David 			   inode->i_private);
226912bace75SLior David }
227012bace75SLior David 
227112bace75SLior David static const struct file_operations fops_fw_capabilities = {
227212bace75SLior David 	.open		= wil_fw_capabilities_seq_open,
227312bace75SLior David 	.release	= single_release,
227412bace75SLior David 	.read		= seq_read,
227512bace75SLior David 	.llseek		= seq_lseek,
227612bace75SLior David };
227712bace75SLior David 
227813cd9f75SLior David /*---------FW version------------*/
227913cd9f75SLior David static int wil_fw_version_debugfs_show(struct seq_file *s, void *data)
228013cd9f75SLior David {
228113cd9f75SLior David 	struct wil6210_priv *wil = s->private;
228213cd9f75SLior David 
228313cd9f75SLior David 	if (wil->fw_version[0])
228413cd9f75SLior David 		seq_printf(s, "%s\n", wil->fw_version);
228513cd9f75SLior David 	else
228613cd9f75SLior David 		seq_puts(s, "N/A\n");
228713cd9f75SLior David 
228813cd9f75SLior David 	return 0;
228913cd9f75SLior David }
229013cd9f75SLior David 
229113cd9f75SLior David static int wil_fw_version_seq_open(struct inode *inode, struct file *file)
229213cd9f75SLior David {
229313cd9f75SLior David 	return single_open(file, wil_fw_version_debugfs_show,
229413cd9f75SLior David 			   inode->i_private);
229513cd9f75SLior David }
229613cd9f75SLior David 
229713cd9f75SLior David static const struct file_operations fops_fw_version = {
229813cd9f75SLior David 	.open		= wil_fw_version_seq_open,
229913cd9f75SLior David 	.release	= single_release,
230013cd9f75SLior David 	.read		= seq_read,
230113cd9f75SLior David 	.llseek		= seq_lseek,
230213cd9f75SLior David };
230313cd9f75SLior David 
2304fe9ee51eSMaya Erez /*---------suspend_stats---------*/
2305fe9ee51eSMaya Erez static ssize_t wil_write_suspend_stats(struct file *file,
2306fe9ee51eSMaya Erez 				       const char __user *buf,
2307fe9ee51eSMaya Erez 				       size_t len, loff_t *ppos)
2308fe9ee51eSMaya Erez {
2309fe9ee51eSMaya Erez 	struct wil6210_priv *wil = file->private_data;
2310fe9ee51eSMaya Erez 
2311fe9ee51eSMaya Erez 	memset(&wil->suspend_stats, 0, sizeof(wil->suspend_stats));
2312fe9ee51eSMaya Erez 
2313fe9ee51eSMaya Erez 	return len;
2314fe9ee51eSMaya Erez }
2315fe9ee51eSMaya Erez 
2316fe9ee51eSMaya Erez static ssize_t wil_read_suspend_stats(struct file *file,
2317fe9ee51eSMaya Erez 				      char __user *user_buf,
2318fe9ee51eSMaya Erez 				      size_t count, loff_t *ppos)
2319fe9ee51eSMaya Erez {
2320fe9ee51eSMaya Erez 	struct wil6210_priv *wil = file->private_data;
2321bd8bdc6cSLazar Alexei 	char *text;
2322bd8bdc6cSLazar Alexei 	int n, ret, text_size = 500;
2323fe9ee51eSMaya Erez 
2324bd8bdc6cSLazar Alexei 	text = kmalloc(text_size, GFP_KERNEL);
2325bd8bdc6cSLazar Alexei 	if (!text)
2326bd8bdc6cSLazar Alexei 		return -ENOMEM;
2327bd8bdc6cSLazar Alexei 
2328bd8bdc6cSLazar Alexei 	n = snprintf(text, text_size,
2329bd8bdc6cSLazar Alexei 		     "Radio on suspend statistics:\n"
2330fe9ee51eSMaya Erez 		     "successful suspends:%ld failed suspends:%ld\n"
2331fe9ee51eSMaya Erez 		     "successful resumes:%ld failed resumes:%ld\n"
2332bd8bdc6cSLazar Alexei 		     "rejected by device:%ld\n"
2333bd8bdc6cSLazar Alexei 		     "Radio off suspend statistics:\n"
2334bd8bdc6cSLazar Alexei 		     "successful suspends:%ld failed suspends:%ld\n"
2335bd8bdc6cSLazar Alexei 		     "successful resumes:%ld failed resumes:%ld\n"
2336bd8bdc6cSLazar Alexei 		     "General statistics:\n"
2337bd8bdc6cSLazar Alexei 		     "rejected by host:%ld\n",
2338bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_on.successful_suspends,
2339bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_on.failed_suspends,
2340bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_on.successful_resumes,
2341bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_on.failed_resumes,
2342bd8bdc6cSLazar Alexei 		     wil->suspend_stats.rejected_by_device,
2343bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_off.successful_suspends,
2344bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_off.failed_suspends,
2345bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_off.successful_resumes,
2346bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_off.failed_resumes,
2347bd8bdc6cSLazar Alexei 		     wil->suspend_stats.rejected_by_host);
2348fe9ee51eSMaya Erez 
2349bd8bdc6cSLazar Alexei 	n = min_t(int, n, text_size);
2350fe9ee51eSMaya Erez 
2351bd8bdc6cSLazar Alexei 	ret = simple_read_from_buffer(user_buf, count, ppos, text, n);
2352bd8bdc6cSLazar Alexei 
2353bd8bdc6cSLazar Alexei 	kfree(text);
2354bd8bdc6cSLazar Alexei 
2355bd8bdc6cSLazar Alexei 	return ret;
2356fe9ee51eSMaya Erez }
2357fe9ee51eSMaya Erez 
2358fe9ee51eSMaya Erez static const struct file_operations fops_suspend_stats = {
2359fe9ee51eSMaya Erez 	.read = wil_read_suspend_stats,
2360fe9ee51eSMaya Erez 	.write = wil_write_suspend_stats,
2361fe9ee51eSMaya Erez 	.open  = simple_open,
2362fe9ee51eSMaya Erez };
2363fe9ee51eSMaya Erez 
236496c93589SGidon Studinski /*---------compressed_rx_status---------*/
236596c93589SGidon Studinski static ssize_t wil_compressed_rx_status_write(struct file *file,
236696c93589SGidon Studinski 					      const char __user *buf,
236796c93589SGidon Studinski 					      size_t len, loff_t *ppos)
236896c93589SGidon Studinski {
236996c93589SGidon Studinski 	struct seq_file *s = file->private_data;
237096c93589SGidon Studinski 	struct wil6210_priv *wil = s->private;
237196c93589SGidon Studinski 	int compressed_rx_status;
237296c93589SGidon Studinski 	int rc;
237396c93589SGidon Studinski 
237496c93589SGidon Studinski 	rc = kstrtoint_from_user(buf, len, 0, &compressed_rx_status);
237596c93589SGidon Studinski 	if (rc) {
237696c93589SGidon Studinski 		wil_err(wil, "Invalid argument\n");
237796c93589SGidon Studinski 		return rc;
237896c93589SGidon Studinski 	}
237996c93589SGidon Studinski 
238096c93589SGidon Studinski 	if (wil_has_active_ifaces(wil, true, false)) {
238196c93589SGidon Studinski 		wil_err(wil, "cannot change edma config after iface is up\n");
238296c93589SGidon Studinski 		return -EPERM;
238396c93589SGidon Studinski 	}
238496c93589SGidon Studinski 
238596c93589SGidon Studinski 	wil_info(wil, "%sable compressed_rx_status\n",
238696c93589SGidon Studinski 		 compressed_rx_status ? "En" : "Dis");
238796c93589SGidon Studinski 
238896c93589SGidon Studinski 	wil->use_compressed_rx_status = compressed_rx_status;
238996c93589SGidon Studinski 
239096c93589SGidon Studinski 	return len;
239196c93589SGidon Studinski }
239296c93589SGidon Studinski 
239396c93589SGidon Studinski static int
239496c93589SGidon Studinski wil_compressed_rx_status_show(struct seq_file *s, void *data)
239596c93589SGidon Studinski {
239696c93589SGidon Studinski 	struct wil6210_priv *wil = s->private;
239796c93589SGidon Studinski 
239896c93589SGidon Studinski 	seq_printf(s, "%d\n", wil->use_compressed_rx_status);
239996c93589SGidon Studinski 
240096c93589SGidon Studinski 	return 0;
240196c93589SGidon Studinski }
240296c93589SGidon Studinski 
240396c93589SGidon Studinski static int
240496c93589SGidon Studinski wil_compressed_rx_status_seq_open(struct inode *inode, struct file *file)
240596c93589SGidon Studinski {
240696c93589SGidon Studinski 	return single_open(file, wil_compressed_rx_status_show,
240796c93589SGidon Studinski 			   inode->i_private);
240896c93589SGidon Studinski }
240996c93589SGidon Studinski 
241096c93589SGidon Studinski static const struct file_operations fops_compressed_rx_status = {
241196c93589SGidon Studinski 	.open  = wil_compressed_rx_status_seq_open,
241296c93589SGidon Studinski 	.release = single_release,
241396c93589SGidon Studinski 	.read = seq_read,
241496c93589SGidon Studinski 	.write = wil_compressed_rx_status_write,
241596c93589SGidon Studinski 	.llseek	= seq_lseek,
241696c93589SGidon Studinski };
241796c93589SGidon Studinski 
24182be7d22fSVladimir Kondratiev /*----------------*/
2419b541d0a0SVladimir Kondratiev static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
2420b541d0a0SVladimir Kondratiev 				       struct dentry *dbg)
2421b541d0a0SVladimir Kondratiev {
2422b541d0a0SVladimir Kondratiev 	int i;
2423b541d0a0SVladimir Kondratiev 	char name[32];
2424b541d0a0SVladimir Kondratiev 
2425b541d0a0SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
2426349214c1SMaya Erez 		struct wil_blob_wrapper *wil_blob = &wil->blobs[i];
2427349214c1SMaya Erez 		struct debugfs_blob_wrapper *blob = &wil_blob->blob;
2428b541d0a0SVladimir Kondratiev 		const struct fw_map *map = &fw_mapping[i];
2429b541d0a0SVladimir Kondratiev 
2430b541d0a0SVladimir Kondratiev 		if (!map->name)
2431b541d0a0SVladimir Kondratiev 			continue;
2432b541d0a0SVladimir Kondratiev 
2433349214c1SMaya Erez 		wil_blob->wil = wil;
2434b541d0a0SVladimir Kondratiev 		blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
2435b541d0a0SVladimir Kondratiev 		blob->size = map->to - map->from;
2436b541d0a0SVladimir Kondratiev 		snprintf(name, sizeof(name), "blob_%s", map->name);
243778484c44SMaya Erez 		wil_debugfs_create_ioblob(name, 0444, dbg, wil_blob);
2438b541d0a0SVladimir Kondratiev 	}
2439b541d0a0SVladimir Kondratiev }
2440b541d0a0SVladimir Kondratiev 
2441b7cde470SVladimir Kondratiev /* misc files */
2442b7cde470SVladimir Kondratiev static const struct {
2443b7cde470SVladimir Kondratiev 	const char *name;
2444b7cde470SVladimir Kondratiev 	umode_t mode;
2445b7cde470SVladimir Kondratiev 	const struct file_operations *fops;
2446b7cde470SVladimir Kondratiev } dbg_files[] = {
244778484c44SMaya Erez 	{"mbox",	0444,		&fops_mbox},
244810590c6aSGidon Studinski 	{"rings",	0444,		&fops_ring},
244978484c44SMaya Erez 	{"stations", 0444,		&fops_sta},
24503a3b745fSLior David 	{"mids",	0444,		&fops_mids},
245178484c44SMaya Erez 	{"desc",	0444,		&fops_txdesc},
245278484c44SMaya Erez 	{"bf",		0444,		&fops_bf},
245378484c44SMaya Erez 	{"mem_val",	0644,		&fops_memread},
245478484c44SMaya Erez 	{"reset",	0244,		&fops_reset},
245578484c44SMaya Erez 	{"rxon",	0244,		&fops_rxon},
245678484c44SMaya Erez 	{"tx_mgmt",	0244,		&fops_txmgmt},
245778484c44SMaya Erez 	{"wmi_send", 0244,		&fops_wmi},
245878484c44SMaya Erez 	{"back",	0644,		&fops_back},
245978484c44SMaya Erez 	{"pmccfg",	0644,		&fops_pmccfg},
246078484c44SMaya Erez 	{"pmcdata",	0444,		&fops_pmcdata},
246178484c44SMaya Erez 	{"temp",	0444,		&fops_temp},
246278484c44SMaya Erez 	{"freq",	0444,		&fops_freq},
246378484c44SMaya Erez 	{"link",	0444,		&fops_link},
246478484c44SMaya Erez 	{"info",	0444,		&fops_info},
246578484c44SMaya Erez 	{"recovery", 0644,		&fops_recovery},
246678484c44SMaya Erez 	{"led_cfg",	0644,		&fops_led_cfg},
246778484c44SMaya Erez 	{"led_blink_time",	0644,	&fops_led_blink_time},
246878484c44SMaya Erez 	{"fw_capabilities",	0444,	&fops_fw_capabilities},
246978484c44SMaya Erez 	{"fw_version",	0444,		&fops_fw_version},
2470fe9ee51eSMaya Erez 	{"suspend_stats",	0644,	&fops_suspend_stats},
247196c93589SGidon Studinski 	{"compressed_rx_status", 0644,	&fops_compressed_rx_status},
2472d98b8539SMaya Erez 	{"srings",	0444,		&fops_srings},
2473d98b8539SMaya Erez 	{"status_msg",	0444,		&fops_status_msg},
2474d98b8539SMaya Erez 	{"rx_buff_mgmt",	0444,	&fops_rx_buff_mgmt},
2475a24a3d6aSDedy Lansky 	{"tx_latency",	0644,		&fops_tx_latency},
2476*0c936b3cSDedy Lansky 	{"link_stats",	0644,		&fops_link_stats},
2477*0c936b3cSDedy Lansky 	{"link_stats_global",	0644,	&fops_link_stats_global},
2478b7cde470SVladimir Kondratiev };
2479b7cde470SVladimir Kondratiev 
2480b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
2481b7cde470SVladimir Kondratiev 				       struct dentry *dbg)
2482b7cde470SVladimir Kondratiev {
2483b7cde470SVladimir Kondratiev 	int i;
2484b7cde470SVladimir Kondratiev 
2485b7cde470SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
2486b7cde470SVladimir Kondratiev 		debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
2487b7cde470SVladimir Kondratiev 				    wil, dbg_files[i].fops);
2488b7cde470SVladimir Kondratiev }
2489b7cde470SVladimir Kondratiev 
2490b7cde470SVladimir Kondratiev /* interrupt control blocks */
2491b7cde470SVladimir Kondratiev static const struct {
2492b7cde470SVladimir Kondratiev 	const char *name;
2493b7cde470SVladimir Kondratiev 	u32 icr_off;
2494b7cde470SVladimir Kondratiev } dbg_icr[] = {
2495b7cde470SVladimir Kondratiev 	{"USER_ICR",		HOSTADDR(RGF_USER_USER_ICR)},
2496b7cde470SVladimir Kondratiev 	{"DMA_EP_TX_ICR",	HOSTADDR(RGF_DMA_EP_TX_ICR)},
2497b7cde470SVladimir Kondratiev 	{"DMA_EP_RX_ICR",	HOSTADDR(RGF_DMA_EP_RX_ICR)},
2498b7cde470SVladimir Kondratiev 	{"DMA_EP_MISC_ICR",	HOSTADDR(RGF_DMA_EP_MISC_ICR)},
2499b7cde470SVladimir Kondratiev };
2500b7cde470SVladimir Kondratiev 
2501b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
2502b7cde470SVladimir Kondratiev 				     struct dentry *dbg)
2503b7cde470SVladimir Kondratiev {
2504b7cde470SVladimir Kondratiev 	int i;
2505b7cde470SVladimir Kondratiev 
2506b7cde470SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
2507b7cde470SVladimir Kondratiev 		wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
2508b7cde470SVladimir Kondratiev 					   dbg_icr[i].icr_off);
2509b7cde470SVladimir Kondratiev }
2510b7cde470SVladimir Kondratiev 
2511b7cde470SVladimir Kondratiev #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
2512b7cde470SVladimir Kondratiev 	offsetof(struct wil6210_priv, name), type}
2513b7cde470SVladimir Kondratiev 
2514b7cde470SVladimir Kondratiev /* fields in struct wil6210_priv */
2515b7cde470SVladimir Kondratiev static const struct dbg_off dbg_wil_off[] = {
251678484c44SMaya Erez 	WIL_FIELD(status[0],	0644,	doff_ulong),
251778484c44SMaya Erez 	WIL_FIELD(hw_version,	0444,	doff_x32),
251878484c44SMaya Erez 	WIL_FIELD(recovery_count, 0444,	doff_u32),
251978484c44SMaya Erez 	WIL_FIELD(discovery_mode, 0644,	doff_u8),
252078484c44SMaya Erez 	WIL_FIELD(chip_revision, 0444,	doff_u8),
252178484c44SMaya Erez 	WIL_FIELD(abft_len, 0644,		doff_u8),
2522fe9ee51eSMaya Erez 	WIL_FIELD(wakeup_trigger, 0644,		doff_u8),
252310590c6aSGidon Studinski 	WIL_FIELD(ring_idle_trsh, 0644,	doff_u32),
252496c93589SGidon Studinski 	WIL_FIELD(num_rx_status_rings, 0644,	doff_u8),
252596c93589SGidon Studinski 	WIL_FIELD(rx_status_ring_order, 0644,	doff_u32),
252696c93589SGidon Studinski 	WIL_FIELD(tx_status_ring_order, 0644,	doff_u32),
252796c93589SGidon Studinski 	WIL_FIELD(rx_buff_id_count, 0644,	doff_u32),
25287be13fc3SGidon Studinski 	WIL_FIELD(amsdu_en, 0644,	doff_u8),
2529b7cde470SVladimir Kondratiev 	{},
2530b7cde470SVladimir Kondratiev };
2531b7cde470SVladimir Kondratiev 
2532b7cde470SVladimir Kondratiev static const struct dbg_off dbg_wil_regs[] = {
253378484c44SMaya Erez 	{"RGF_MAC_MTRL_COUNTER_0", 0444, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
2534b7cde470SVladimir Kondratiev 		doff_io32},
253578484c44SMaya Erez 	{"RGF_USER_USAGE_1", 0444, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
2536b7cde470SVladimir Kondratiev 	{},
2537b7cde470SVladimir Kondratiev };
2538b7cde470SVladimir Kondratiev 
2539b7cde470SVladimir Kondratiev /* static parameters */
2540b7cde470SVladimir Kondratiev static const struct dbg_off dbg_statics[] = {
254178484c44SMaya Erez 	{"desc_index",	0644, (ulong)&dbg_txdesc_index, doff_u32},
254210590c6aSGidon Studinski 	{"ring_index",	0644, (ulong)&dbg_ring_index, doff_u32},
254378484c44SMaya Erez 	{"mem_addr",	0644, (ulong)&mem_addr, doff_u32},
254478484c44SMaya Erez 	{"led_polarity", 0644, (ulong)&led_polarity, doff_u8},
2545d98b8539SMaya Erez 	{"status_index", 0644, (ulong)&dbg_status_msg_index, doff_u32},
2546d98b8539SMaya Erez 	{"sring_index",	0644, (ulong)&dbg_sring_index, doff_u32},
2547b7cde470SVladimir Kondratiev 	{},
2548b7cde470SVladimir Kondratiev };
2549b7cde470SVladimir Kondratiev 
255094162666SLazar Alexei static const int dbg_off_count = 4 * (ARRAY_SIZE(isr_off) - 1) +
255194162666SLazar Alexei 				ARRAY_SIZE(dbg_wil_regs) - 1 +
255294162666SLazar Alexei 				ARRAY_SIZE(pseudo_isr_off) - 1 +
255394162666SLazar Alexei 				ARRAY_SIZE(lgc_itr_cnt_off) - 1 +
255494162666SLazar Alexei 				ARRAY_SIZE(tx_itr_cnt_off) - 1 +
255594162666SLazar Alexei 				ARRAY_SIZE(rx_itr_cnt_off) - 1;
255694162666SLazar Alexei 
25572be7d22fSVladimir Kondratiev int wil6210_debugfs_init(struct wil6210_priv *wil)
25582be7d22fSVladimir Kondratiev {
25592be7d22fSVladimir Kondratiev 	struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
25602be7d22fSVladimir Kondratiev 			wil_to_wiphy(wil)->debugfsdir);
25612be7d22fSVladimir Kondratiev 	if (IS_ERR_OR_NULL(dbg))
25622be7d22fSVladimir Kondratiev 		return -ENODEV;
25632be7d22fSVladimir Kondratiev 
256494162666SLazar Alexei 	wil->dbg_data.data_arr = kcalloc(dbg_off_count,
256594162666SLazar Alexei 					 sizeof(struct wil_debugfs_iomem_data),
256694162666SLazar Alexei 					 GFP_KERNEL);
256794162666SLazar Alexei 	if (!wil->dbg_data.data_arr) {
256894162666SLazar Alexei 		debugfs_remove_recursive(dbg);
256994162666SLazar Alexei 		wil->debug = NULL;
257094162666SLazar Alexei 		return -ENOMEM;
257194162666SLazar Alexei 	}
257294162666SLazar Alexei 
257394162666SLazar Alexei 	wil->dbg_data.iomem_data_count = 0;
257494162666SLazar Alexei 
2575dc16427bSVladimir Kondratiev 	wil_pmc_init(wil);
2576dc16427bSVladimir Kondratiev 
2577b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_files(wil, dbg);
2578b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_isr(wil, dbg);
2579b541d0a0SVladimir Kondratiev 	wil6210_debugfs_init_blobs(wil, dbg);
2580b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
2581b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
2582b7cde470SVladimir Kondratiev 				    dbg_wil_regs);
2583b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
2584b7cde470SVladimir Kondratiev 
2585b7cde470SVladimir Kondratiev 	wil6210_debugfs_create_pseudo_ISR(wil, dbg);
2586b7cde470SVladimir Kondratiev 
2587b7cde470SVladimir Kondratiev 	wil6210_debugfs_create_ITR_CNT(wil, dbg);
25882be7d22fSVladimir Kondratiev 
25892be7d22fSVladimir Kondratiev 	return 0;
25902be7d22fSVladimir Kondratiev }
25912be7d22fSVladimir Kondratiev 
25922be7d22fSVladimir Kondratiev void wil6210_debugfs_remove(struct wil6210_priv *wil)
25932be7d22fSVladimir Kondratiev {
2594a24a3d6aSDedy Lansky 	int i;
2595a24a3d6aSDedy Lansky 
25962be7d22fSVladimir Kondratiev 	debugfs_remove_recursive(wil->debug);
25972be7d22fSVladimir Kondratiev 	wil->debug = NULL;
2598dc16427bSVladimir Kondratiev 
259994162666SLazar Alexei 	kfree(wil->dbg_data.data_arr);
2600a24a3d6aSDedy Lansky 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++)
2601a24a3d6aSDedy Lansky 		kfree(wil->sta[i].tx_latency_bins);
260294162666SLazar Alexei 
2603dc16427bSVladimir Kondratiev 	/* free pmc memory without sending command to fw, as it will
2604dc16427bSVladimir Kondratiev 	 * be reset on the way down anyway
2605dc16427bSVladimir Kondratiev 	 */
2606dc16427bSVladimir Kondratiev 	wil_pmc_free(wil, false);
26072be7d22fSVladimir Kondratiev }
2608