xref: /linux/drivers/net/wireless/ath/wil6210/debugfs.c (revision b9010f105f21788b2dbe0e9599677a27247a9092)
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 
7280b39aaf2SVladimir Kondratiev /*---write channel 1..4 to rxon for it, 0 to rxoff---*/
7290b39aaf2SVladimir Kondratiev static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
7300b39aaf2SVladimir Kondratiev 				   size_t len, loff_t *ppos)
7310b39aaf2SVladimir Kondratiev {
7320b39aaf2SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
7330b39aaf2SVladimir Kondratiev 	int rc;
7340b39aaf2SVladimir Kondratiev 	long channel;
7350b39aaf2SVladimir Kondratiev 	bool on;
7360b39aaf2SVladimir Kondratiev 
73716e5c1fcSAl Viro 	char *kbuf = memdup_user_nul(buf, len);
7388fe59627SVladimir Kondratiev 
73916e5c1fcSAl Viro 	if (IS_ERR(kbuf))
74016e5c1fcSAl Viro 		return PTR_ERR(kbuf);
7410b39aaf2SVladimir Kondratiev 	rc = kstrtol(kbuf, 0, &channel);
7420b39aaf2SVladimir Kondratiev 	kfree(kbuf);
7430b39aaf2SVladimir Kondratiev 	if (rc)
7440b39aaf2SVladimir Kondratiev 		return rc;
7450b39aaf2SVladimir Kondratiev 
7460b39aaf2SVladimir Kondratiev 	if ((channel < 0) || (channel > 4)) {
7470b39aaf2SVladimir Kondratiev 		wil_err(wil, "Invalid channel %ld\n", channel);
7480b39aaf2SVladimir Kondratiev 		return -EINVAL;
7490b39aaf2SVladimir Kondratiev 	}
7500b39aaf2SVladimir Kondratiev 	on = !!channel;
7510b39aaf2SVladimir Kondratiev 
7520b39aaf2SVladimir Kondratiev 	if (on) {
7530b39aaf2SVladimir Kondratiev 		rc = wmi_set_channel(wil, (int)channel);
7540b39aaf2SVladimir Kondratiev 		if (rc)
7550b39aaf2SVladimir Kondratiev 			return rc;
7560b39aaf2SVladimir Kondratiev 	}
7570b39aaf2SVladimir Kondratiev 
7580b39aaf2SVladimir Kondratiev 	rc = wmi_rxon(wil, on);
7590b39aaf2SVladimir Kondratiev 	if (rc)
7600b39aaf2SVladimir Kondratiev 		return rc;
7610b39aaf2SVladimir Kondratiev 
7620b39aaf2SVladimir Kondratiev 	return len;
7630b39aaf2SVladimir Kondratiev }
7640b39aaf2SVladimir Kondratiev 
7650b39aaf2SVladimir Kondratiev static const struct file_operations fops_rxon = {
7660b39aaf2SVladimir Kondratiev 	.write = wil_write_file_rxon,
7670b39aaf2SVladimir Kondratiev 	.open  = simple_open,
7680b39aaf2SVladimir Kondratiev };
7698fe59627SVladimir Kondratiev 
77049cb5dfbSVladimir Kondratiev /* block ack control, write:
77149cb5dfbSVladimir Kondratiev  * - "add <ringid> <agg_size> <timeout>" to trigger ADDBA
77249cb5dfbSVladimir Kondratiev  * - "del_tx <ringid> <reason>" to trigger DELBA for Tx side
77349cb5dfbSVladimir Kondratiev  * - "del_rx <CID> <TID> <reason>" to trigger DELBA for Rx side
7743277213fSVladimir Kondratiev  */
77549cb5dfbSVladimir Kondratiev static ssize_t wil_write_back(struct file *file, const char __user *buf,
7763277213fSVladimir Kondratiev 			      size_t len, loff_t *ppos)
7773277213fSVladimir Kondratiev {
7783277213fSVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
7793277213fSVladimir Kondratiev 	int rc;
7803277213fSVladimir Kondratiev 	char *kbuf = kmalloc(len + 1, GFP_KERNEL);
7812a19f776SColin Ian King 	char cmd[9];
78249cb5dfbSVladimir Kondratiev 	int p1, p2, p3;
7833277213fSVladimir Kondratiev 
7843277213fSVladimir Kondratiev 	if (!kbuf)
7853277213fSVladimir Kondratiev 		return -ENOMEM;
7863277213fSVladimir Kondratiev 
7873277213fSVladimir Kondratiev 	rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
7883277213fSVladimir Kondratiev 	if (rc != len) {
7893277213fSVladimir Kondratiev 		kfree(kbuf);
7903277213fSVladimir Kondratiev 		return rc >= 0 ? -EIO : rc;
7913277213fSVladimir Kondratiev 	}
7923277213fSVladimir Kondratiev 
7933277213fSVladimir Kondratiev 	kbuf[len] = '\0';
79449cb5dfbSVladimir Kondratiev 	rc = sscanf(kbuf, "%8s %d %d %d", cmd, &p1, &p2, &p3);
7953277213fSVladimir Kondratiev 	kfree(kbuf);
7963277213fSVladimir Kondratiev 
79749cb5dfbSVladimir Kondratiev 	if (rc < 0)
7983277213fSVladimir Kondratiev 		return rc;
79949cb5dfbSVladimir Kondratiev 	if (rc < 2)
8003277213fSVladimir Kondratiev 		return -EINVAL;
8013277213fSVladimir Kondratiev 
802e00243faSLior David 	if ((strcmp(cmd, "add") == 0) ||
803e00243faSLior David 	    (strcmp(cmd, "del_tx") == 0)) {
80410590c6aSGidon Studinski 		struct wil_ring_tx_data *txdata;
805e00243faSLior David 
806e00243faSLior David 		if (p1 < 0 || p1 >= WIL6210_MAX_TX_RINGS) {
807e00243faSLior David 			wil_err(wil, "BACK: invalid ring id %d\n", p1);
808e00243faSLior David 			return -EINVAL;
809e00243faSLior David 		}
81010590c6aSGidon Studinski 		txdata = &wil->ring_tx_data[p1];
811e00243faSLior David 		if (strcmp(cmd, "add") == 0) {
81249cb5dfbSVladimir Kondratiev 			if (rc < 3) {
81349cb5dfbSVladimir Kondratiev 				wil_err(wil, "BACK: add require at least 2 params\n");
81449cb5dfbSVladimir Kondratiev 				return -EINVAL;
81549cb5dfbSVladimir Kondratiev 			}
81649cb5dfbSVladimir Kondratiev 			if (rc < 4)
81749cb5dfbSVladimir Kondratiev 				p3 = 0;
818e00243faSLior David 			wmi_addba(wil, txdata->mid, p1, p2, p3);
819e00243faSLior David 		} else {
82049cb5dfbSVladimir Kondratiev 			if (rc < 3)
82149cb5dfbSVladimir Kondratiev 				p2 = WLAN_REASON_QSTA_LEAVE_QBSS;
822e00243faSLior David 			wmi_delba_tx(wil, txdata->mid, p1, p2);
823e00243faSLior David 		}
824e00243faSLior David 	} else if (strcmp(cmd, "del_rx") == 0) {
825e00243faSLior David 		struct wil_sta_info *sta;
826e00243faSLior David 
82749cb5dfbSVladimir Kondratiev 		if (rc < 3) {
82849cb5dfbSVladimir Kondratiev 			wil_err(wil,
82949cb5dfbSVladimir Kondratiev 				"BACK: del_rx require at least 2 params\n");
83049cb5dfbSVladimir Kondratiev 			return -EINVAL;
83149cb5dfbSVladimir Kondratiev 		}
832e00243faSLior David 		if (p1 < 0 || p1 >= WIL6210_MAX_CID) {
833e00243faSLior David 			wil_err(wil, "BACK: invalid CID %d\n", p1);
834e00243faSLior David 			return -EINVAL;
835e00243faSLior David 		}
83649cb5dfbSVladimir Kondratiev 		if (rc < 4)
83749cb5dfbSVladimir Kondratiev 			p3 = WLAN_REASON_QSTA_LEAVE_QBSS;
838e00243faSLior David 		sta = &wil->sta[p1];
839e00243faSLior David 		wmi_delba_rx(wil, sta->mid, mk_cidxtid(p1, p2), p3);
84049cb5dfbSVladimir Kondratiev 	} else {
84149cb5dfbSVladimir Kondratiev 		wil_err(wil, "BACK: Unrecognized command \"%s\"\n", cmd);
84249cb5dfbSVladimir Kondratiev 		return -EINVAL;
84349cb5dfbSVladimir Kondratiev 	}
8443277213fSVladimir Kondratiev 
8453277213fSVladimir Kondratiev 	return len;
8463277213fSVladimir Kondratiev }
8473277213fSVladimir Kondratiev 
84849cb5dfbSVladimir Kondratiev static ssize_t wil_read_back(struct file *file, char __user *user_buf,
84949cb5dfbSVladimir Kondratiev 			     size_t count, loff_t *ppos)
85049cb5dfbSVladimir Kondratiev {
85149cb5dfbSVladimir Kondratiev 	static const char text[] = "block ack control, write:\n"
85249cb5dfbSVladimir Kondratiev 	" - \"add <ringid> <agg_size> <timeout>\" to trigger ADDBA\n"
85349cb5dfbSVladimir Kondratiev 	"If missing, <timeout> defaults to 0\n"
85449cb5dfbSVladimir Kondratiev 	" - \"del_tx <ringid> <reason>\" to trigger DELBA for Tx side\n"
85549cb5dfbSVladimir Kondratiev 	" - \"del_rx <CID> <TID> <reason>\" to trigger DELBA for Rx side\n"
85649cb5dfbSVladimir Kondratiev 	"If missing, <reason> set to \"STA_LEAVING\" (36)\n";
85749cb5dfbSVladimir Kondratiev 
85849cb5dfbSVladimir Kondratiev 	return simple_read_from_buffer(user_buf, count, ppos, text,
85949cb5dfbSVladimir Kondratiev 				       sizeof(text));
86049cb5dfbSVladimir Kondratiev }
86149cb5dfbSVladimir Kondratiev 
86249cb5dfbSVladimir Kondratiev static const struct file_operations fops_back = {
86349cb5dfbSVladimir Kondratiev 	.read = wil_read_back,
86449cb5dfbSVladimir Kondratiev 	.write = wil_write_back,
8653277213fSVladimir Kondratiev 	.open  = simple_open,
8663277213fSVladimir Kondratiev };
8673277213fSVladimir Kondratiev 
868dc16427bSVladimir Kondratiev /* pmc control, write:
869dc16427bSVladimir Kondratiev  * - "alloc <num descriptors> <descriptor_size>" to allocate PMC
870dc16427bSVladimir Kondratiev  * - "free" to release memory allocated for PMC
871dc16427bSVladimir Kondratiev  */
872dc16427bSVladimir Kondratiev static ssize_t wil_write_pmccfg(struct file *file, const char __user *buf,
873dc16427bSVladimir Kondratiev 				size_t len, loff_t *ppos)
874dc16427bSVladimir Kondratiev {
875dc16427bSVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
876dc16427bSVladimir Kondratiev 	int rc;
877dc16427bSVladimir Kondratiev 	char *kbuf = kmalloc(len + 1, GFP_KERNEL);
878dc16427bSVladimir Kondratiev 	char cmd[9];
879dc16427bSVladimir Kondratiev 	int num_descs, desc_size;
880dc16427bSVladimir Kondratiev 
881dc16427bSVladimir Kondratiev 	if (!kbuf)
882dc16427bSVladimir Kondratiev 		return -ENOMEM;
883dc16427bSVladimir Kondratiev 
884dc16427bSVladimir Kondratiev 	rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
885dc16427bSVladimir Kondratiev 	if (rc != len) {
886dc16427bSVladimir Kondratiev 		kfree(kbuf);
887dc16427bSVladimir Kondratiev 		return rc >= 0 ? -EIO : rc;
888dc16427bSVladimir Kondratiev 	}
889dc16427bSVladimir Kondratiev 
890dc16427bSVladimir Kondratiev 	kbuf[len] = '\0';
891dc16427bSVladimir Kondratiev 	rc = sscanf(kbuf, "%8s %d %d", cmd, &num_descs, &desc_size);
892dc16427bSVladimir Kondratiev 	kfree(kbuf);
893dc16427bSVladimir Kondratiev 
894dc16427bSVladimir Kondratiev 	if (rc < 0)
895dc16427bSVladimir Kondratiev 		return rc;
896dc16427bSVladimir Kondratiev 
897dc16427bSVladimir Kondratiev 	if (rc < 1) {
898dc16427bSVladimir Kondratiev 		wil_err(wil, "pmccfg: no params given\n");
899dc16427bSVladimir Kondratiev 		return -EINVAL;
900dc16427bSVladimir Kondratiev 	}
901dc16427bSVladimir Kondratiev 
902dc16427bSVladimir Kondratiev 	if (0 == strcmp(cmd, "alloc")) {
903dc16427bSVladimir Kondratiev 		if (rc != 3) {
904dc16427bSVladimir Kondratiev 			wil_err(wil, "pmccfg: alloc requires 2 params\n");
905dc16427bSVladimir Kondratiev 			return -EINVAL;
906dc16427bSVladimir Kondratiev 		}
907dc16427bSVladimir Kondratiev 		wil_pmc_alloc(wil, num_descs, desc_size);
908dc16427bSVladimir Kondratiev 	} else if (0 == strcmp(cmd, "free")) {
909dc16427bSVladimir Kondratiev 		if (rc != 1) {
910dc16427bSVladimir Kondratiev 			wil_err(wil, "pmccfg: free does not have any params\n");
911dc16427bSVladimir Kondratiev 			return -EINVAL;
912dc16427bSVladimir Kondratiev 		}
913dc16427bSVladimir Kondratiev 		wil_pmc_free(wil, true);
914dc16427bSVladimir Kondratiev 	} else {
915dc16427bSVladimir Kondratiev 		wil_err(wil, "pmccfg: Unrecognized command \"%s\"\n", cmd);
916dc16427bSVladimir Kondratiev 		return -EINVAL;
917dc16427bSVladimir Kondratiev 	}
918dc16427bSVladimir Kondratiev 
919dc16427bSVladimir Kondratiev 	return len;
920dc16427bSVladimir Kondratiev }
921dc16427bSVladimir Kondratiev 
922dc16427bSVladimir Kondratiev static ssize_t wil_read_pmccfg(struct file *file, char __user *user_buf,
923dc16427bSVladimir Kondratiev 			       size_t count, loff_t *ppos)
924dc16427bSVladimir Kondratiev {
925dc16427bSVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
926dc16427bSVladimir Kondratiev 	char text[256];
927dc16427bSVladimir Kondratiev 	char help[] = "pmc control, write:\n"
928dc16427bSVladimir Kondratiev 	" - \"alloc <num descriptors> <descriptor_size>\" to allocate pmc\n"
929dc16427bSVladimir Kondratiev 	" - \"free\" to free memory allocated for pmc\n";
930dc16427bSVladimir Kondratiev 
931dc16427bSVladimir Kondratiev 	sprintf(text, "Last command status: %d\n\n%s",
932dc16427bSVladimir Kondratiev 		wil_pmc_last_cmd_status(wil),
933dc16427bSVladimir Kondratiev 		help);
934dc16427bSVladimir Kondratiev 
935dc16427bSVladimir Kondratiev 	return simple_read_from_buffer(user_buf, count, ppos, text,
936dc16427bSVladimir Kondratiev 				       strlen(text) + 1);
937dc16427bSVladimir Kondratiev }
938dc16427bSVladimir Kondratiev 
939dc16427bSVladimir Kondratiev static const struct file_operations fops_pmccfg = {
940dc16427bSVladimir Kondratiev 	.read = wil_read_pmccfg,
941dc16427bSVladimir Kondratiev 	.write = wil_write_pmccfg,
942dc16427bSVladimir Kondratiev 	.open  = simple_open,
943dc16427bSVladimir Kondratiev };
944dc16427bSVladimir Kondratiev 
945dc16427bSVladimir Kondratiev static const struct file_operations fops_pmcdata = {
946dc16427bSVladimir Kondratiev 	.open		= simple_open,
947dc16427bSVladimir Kondratiev 	.read		= wil_pmc_read,
948dc16427bSVladimir Kondratiev 	.llseek		= wil_pmc_llseek,
949dc16427bSVladimir Kondratiev };
950dc16427bSVladimir Kondratiev 
9510b39aaf2SVladimir Kondratiev /*---tx_mgmt---*/
9520b39aaf2SVladimir Kondratiev /* Write mgmt frame to this file to send it */
9530b39aaf2SVladimir Kondratiev static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
9540b39aaf2SVladimir Kondratiev 				     size_t len, loff_t *ppos)
9550b39aaf2SVladimir Kondratiev {
9560b39aaf2SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
9570b39aaf2SVladimir Kondratiev 	struct wiphy *wiphy = wil_to_wiphy(wil);
958e00243faSLior David 	struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr;
9590b39aaf2SVladimir Kondratiev 	struct cfg80211_mgmt_tx_params params;
9600b39aaf2SVladimir Kondratiev 	int rc;
9619a492909SGeliang Tang 	void *frame;
9628fe59627SVladimir Kondratiev 
9636641525cSHamad Kadmany 	if (!len)
9646641525cSHamad Kadmany 		return -EINVAL;
9656641525cSHamad Kadmany 
9669a492909SGeliang Tang 	frame = memdup_user(buf, len);
9679a492909SGeliang Tang 	if (IS_ERR(frame))
9689a492909SGeliang Tang 		return PTR_ERR(frame);
9690b39aaf2SVladimir Kondratiev 
9700b39aaf2SVladimir Kondratiev 	params.buf = frame;
9710b39aaf2SVladimir Kondratiev 	params.len = len;
9720b39aaf2SVladimir Kondratiev 
9730b39aaf2SVladimir Kondratiev 	rc = wil_cfg80211_mgmt_tx(wiphy, wdev, &params, NULL);
9740b39aaf2SVladimir Kondratiev 
9750b39aaf2SVladimir Kondratiev 	kfree(frame);
976af3db60aSLazar Alexei 	wil_info(wil, "-> %d\n", rc);
9770b39aaf2SVladimir Kondratiev 
9780b39aaf2SVladimir Kondratiev 	return len;
9790b39aaf2SVladimir Kondratiev }
9800b39aaf2SVladimir Kondratiev 
9810b39aaf2SVladimir Kondratiev static const struct file_operations fops_txmgmt = {
9820b39aaf2SVladimir Kondratiev 	.write = wil_write_file_txmgmt,
9830b39aaf2SVladimir Kondratiev 	.open  = simple_open,
9840b39aaf2SVladimir Kondratiev };
9852be7d22fSVladimir Kondratiev 
986ff974e40SVladimir Kondratiev /* Write WMI command (w/o mbox header) to this file to send it
987ff974e40SVladimir Kondratiev  * WMI starts from wil6210_mbox_hdr_wmi header
988ff974e40SVladimir Kondratiev  */
989ff974e40SVladimir Kondratiev static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
990ff974e40SVladimir Kondratiev 				  size_t len, loff_t *ppos)
991ff974e40SVladimir Kondratiev {
992ff974e40SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
993e00243faSLior David 	struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
994b874ddecSLior David 	struct wmi_cmd_hdr *wmi;
995ff974e40SVladimir Kondratiev 	void *cmd;
996b874ddecSLior David 	int cmdlen = len - sizeof(struct wmi_cmd_hdr);
997ff974e40SVladimir Kondratiev 	u16 cmdid;
998ff974e40SVladimir Kondratiev 	int rc, rc1;
999ff974e40SVladimir Kondratiev 
100069218a48SLior David 	if (cmdlen < 0)
1001ff974e40SVladimir Kondratiev 		return -EINVAL;
1002ff974e40SVladimir Kondratiev 
1003ff974e40SVladimir Kondratiev 	wmi = kmalloc(len, GFP_KERNEL);
1004ff974e40SVladimir Kondratiev 	if (!wmi)
1005ff974e40SVladimir Kondratiev 		return -ENOMEM;
1006ff974e40SVladimir Kondratiev 
1007ff974e40SVladimir Kondratiev 	rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
10088e09b7d2SLino Sanfilippo 	if (rc < 0) {
10098e09b7d2SLino Sanfilippo 		kfree(wmi);
1010ff974e40SVladimir Kondratiev 		return rc;
10118e09b7d2SLino Sanfilippo 	}
1012ff974e40SVladimir Kondratiev 
101369218a48SLior David 	cmd = (cmdlen > 0) ? &wmi[1] : NULL;
1014b874ddecSLior David 	cmdid = le16_to_cpu(wmi->command_id);
1015ff974e40SVladimir Kondratiev 
1016e00243faSLior David 	rc1 = wmi_send(wil, cmdid, vif->mid, cmd, cmdlen);
1017ff974e40SVladimir Kondratiev 	kfree(wmi);
1018ff974e40SVladimir Kondratiev 
1019af3db60aSLazar Alexei 	wil_info(wil, "0x%04x[%d] -> %d\n", cmdid, cmdlen, rc1);
1020ff974e40SVladimir Kondratiev 
1021ff974e40SVladimir Kondratiev 	return rc;
1022ff974e40SVladimir Kondratiev }
1023ff974e40SVladimir Kondratiev 
1024ff974e40SVladimir Kondratiev static const struct file_operations fops_wmi = {
1025ff974e40SVladimir Kondratiev 	.write = wil_write_file_wmi,
1026ff974e40SVladimir Kondratiev 	.open  = simple_open,
1027ff974e40SVladimir Kondratiev };
1028ff974e40SVladimir Kondratiev 
1029c236658fSVladimir Kondratiev static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
1030c236658fSVladimir Kondratiev {
1031c236658fSVladimir Kondratiev 	int i = 0;
1032c236658fSVladimir Kondratiev 	int len = skb_headlen(skb);
1033c236658fSVladimir Kondratiev 	void *p = skb->data;
1034c236658fSVladimir Kondratiev 	int nr_frags = skb_shinfo(skb)->nr_frags;
1035c236658fSVladimir Kondratiev 
1036c236658fSVladimir Kondratiev 	seq_printf(s, "    len = %d\n", len);
1037c236658fSVladimir Kondratiev 	wil_seq_hexdump(s, p, len, "      : ");
1038c236658fSVladimir Kondratiev 
1039c236658fSVladimir Kondratiev 	if (nr_frags) {
1040c236658fSVladimir Kondratiev 		seq_printf(s, "    nr_frags = %d\n", nr_frags);
1041c236658fSVladimir Kondratiev 		for (i = 0; i < nr_frags; i++) {
1042c236658fSVladimir Kondratiev 			const struct skb_frag_struct *frag =
1043c236658fSVladimir Kondratiev 					&skb_shinfo(skb)->frags[i];
1044c236658fSVladimir Kondratiev 
1045c236658fSVladimir Kondratiev 			len = skb_frag_size(frag);
1046c236658fSVladimir Kondratiev 			p = skb_frag_address_safe(frag);
1047c236658fSVladimir Kondratiev 			seq_printf(s, "    [%2d] : len = %d\n", i, len);
1048c236658fSVladimir Kondratiev 			wil_seq_hexdump(s, p, len, "      : ");
1049c236658fSVladimir Kondratiev 		}
1050c236658fSVladimir Kondratiev 	}
1051c236658fSVladimir Kondratiev }
1052c236658fSVladimir Kondratiev 
10533a85543eSVladimir Kondratiev /*---------Tx/Rx descriptor------------*/
10542be7d22fSVladimir Kondratiev static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
10552be7d22fSVladimir Kondratiev {
10562be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
105710590c6aSGidon Studinski 	struct wil_ring *ring;
1058d98b8539SMaya Erez 	bool tx;
1059d98b8539SMaya Erez 	int ring_idx = dbg_ring_index;
1060d98b8539SMaya Erez 	int txdesc_idx = dbg_txdesc_index;
1061d98b8539SMaya Erez 	volatile struct vring_tx_desc *d;
1062d98b8539SMaya Erez 	volatile u32 *u;
1063d98b8539SMaya Erez 	struct sk_buff *skb;
10648fe59627SVladimir Kondratiev 
1065d98b8539SMaya Erez 	if (wil->use_enhanced_dma_hw) {
1066d98b8539SMaya Erez 		/* RX ring index == 0 */
1067d98b8539SMaya Erez 		if (ring_idx >= WIL6210_MAX_TX_RINGS) {
1068d98b8539SMaya Erez 			seq_printf(s, "invalid ring index %d\n", ring_idx);
1069d98b8539SMaya Erez 			return 0;
1070d98b8539SMaya Erez 		}
1071d98b8539SMaya Erez 		tx = ring_idx > 0; /* desc ring 0 is reserved for RX */
1072d98b8539SMaya Erez 	} else {
1073d98b8539SMaya Erez 		/* RX ring index == WIL6210_MAX_TX_RINGS */
1074d98b8539SMaya Erez 		if (ring_idx > WIL6210_MAX_TX_RINGS) {
1075d98b8539SMaya Erez 			seq_printf(s, "invalid ring index %d\n", ring_idx);
1076d98b8539SMaya Erez 			return 0;
1077d98b8539SMaya Erez 		}
1078d98b8539SMaya Erez 		tx = (ring_idx < WIL6210_MAX_TX_RINGS);
1079d98b8539SMaya Erez 	}
1080d98b8539SMaya Erez 
1081d98b8539SMaya Erez 	ring = tx ? &wil->ring_tx[ring_idx] : &wil->ring_rx;
10822be7d22fSVladimir Kondratiev 
108310590c6aSGidon Studinski 	if (!ring->va) {
1084af31cb5aSVladimir Kondratiev 		if (tx)
1085d98b8539SMaya Erez 			seq_printf(s, "No Tx[%2d] RING\n", ring_idx);
10863a85543eSVladimir Kondratiev 		else
1087d98b8539SMaya Erez 			seq_puts(s, "No Rx RING\n");
10882be7d22fSVladimir Kondratiev 		return 0;
10892be7d22fSVladimir Kondratiev 	}
10902be7d22fSVladimir Kondratiev 
1091d98b8539SMaya Erez 	if (txdesc_idx >= ring->size) {
1092d98b8539SMaya Erez 		if (tx)
1093d98b8539SMaya Erez 			seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
1094d98b8539SMaya Erez 				   ring_idx, txdesc_idx, ring->size);
1095d98b8539SMaya Erez 		else
1096d98b8539SMaya Erez 			seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
1097d98b8539SMaya Erez 				   txdesc_idx, ring->size);
1098d98b8539SMaya Erez 		return 0;
1099d98b8539SMaya Erez 	}
1100d98b8539SMaya Erez 
11013a85543eSVladimir Kondratiev 	/* use struct vring_tx_desc for Rx as well,
11023a85543eSVladimir Kondratiev 	 * only field used, .dma.length, is the same
11033a85543eSVladimir Kondratiev 	 */
1104d98b8539SMaya Erez 	d = &ring->va[txdesc_idx].tx.legacy;
1105d98b8539SMaya Erez 	u = (volatile u32 *)d;
1106d98b8539SMaya Erez 	skb = NULL;
11072be7d22fSVladimir Kondratiev 
1108d98b8539SMaya Erez 	if (wil->use_enhanced_dma_hw) {
1109d98b8539SMaya Erez 		if (tx) {
1110d98b8539SMaya Erez 			skb = ring->ctx[txdesc_idx].skb;
1111d98b8539SMaya Erez 		} else {
1112d98b8539SMaya Erez 			struct wil_rx_enhanced_desc *rx_d =
1113d98b8539SMaya Erez 				(struct wil_rx_enhanced_desc *)
1114d98b8539SMaya Erez 				&ring->va[txdesc_idx].rx.enhanced;
1115d98b8539SMaya Erez 			u16 buff_id = le16_to_cpu(rx_d->mac.buff_id);
1116d98b8539SMaya Erez 
1117d98b8539SMaya Erez 			if (!wil_val_in_range(buff_id, 0,
1118d98b8539SMaya Erez 					      wil->rx_buff_mgmt.size)) {
1119d98b8539SMaya Erez 				seq_printf(s, "invalid buff_id %d\n", buff_id);
1120d98b8539SMaya Erez 				return 0;
1121d98b8539SMaya Erez 			}
1122d98b8539SMaya Erez 			skb = wil->rx_buff_mgmt.buff_arr[buff_id].skb;
1123d98b8539SMaya Erez 		}
1124d98b8539SMaya Erez 	} else {
1125d98b8539SMaya Erez 		skb = ring->ctx[txdesc_idx].skb;
1126d98b8539SMaya Erez 	}
1127af31cb5aSVladimir Kondratiev 	if (tx)
1128d98b8539SMaya Erez 		seq_printf(s, "Tx[%2d][%3d] = {\n", ring_idx,
1129d98b8539SMaya Erez 			   txdesc_idx);
11303a85543eSVladimir Kondratiev 	else
1131d98b8539SMaya Erez 		seq_printf(s, "Rx[%3d] = {\n", txdesc_idx);
11322be7d22fSVladimir Kondratiev 	seq_printf(s, "  MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
11332be7d22fSVladimir Kondratiev 		   u[0], u[1], u[2], u[3]);
11342be7d22fSVladimir Kondratiev 	seq_printf(s, "  DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
11352be7d22fSVladimir Kondratiev 		   u[4], u[5], u[6], u[7]);
113639c52ee8SVladimir Kondratiev 	seq_printf(s, "  SKB = 0x%p\n", skb);
11372be7d22fSVladimir Kondratiev 
11382be7d22fSVladimir Kondratiev 	if (skb) {
1139c236658fSVladimir Kondratiev 		skb_get(skb);
1140c236658fSVladimir Kondratiev 		wil_seq_print_skb(s, skb);
1141c236658fSVladimir Kondratiev 		kfree_skb(skb);
11422be7d22fSVladimir Kondratiev 	}
11438fe59627SVladimir Kondratiev 	seq_puts(s, "}\n");
11442be7d22fSVladimir Kondratiev 
11452be7d22fSVladimir Kondratiev 	return 0;
11462be7d22fSVladimir Kondratiev }
11472be7d22fSVladimir Kondratiev 
11482be7d22fSVladimir Kondratiev static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
11492be7d22fSVladimir Kondratiev {
11502be7d22fSVladimir Kondratiev 	return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
11512be7d22fSVladimir Kondratiev }
11522be7d22fSVladimir Kondratiev 
11532be7d22fSVladimir Kondratiev static const struct file_operations fops_txdesc = {
11542be7d22fSVladimir Kondratiev 	.open		= wil_txdesc_seq_open,
11552be7d22fSVladimir Kondratiev 	.release	= single_release,
11562be7d22fSVladimir Kondratiev 	.read		= seq_read,
11572be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
11582be7d22fSVladimir Kondratiev };
11592be7d22fSVladimir Kondratiev 
1160d98b8539SMaya Erez /*---------Tx/Rx status message------------*/
1161d98b8539SMaya Erez static int wil_status_msg_debugfs_show(struct seq_file *s, void *data)
1162d98b8539SMaya Erez {
1163d98b8539SMaya Erez 	struct wil6210_priv *wil = s->private;
1164d98b8539SMaya Erez 	int sring_idx = dbg_sring_index;
1165d98b8539SMaya Erez 	struct wil_status_ring *sring;
1166d98b8539SMaya Erez 	bool tx = sring_idx == wil->tx_sring_idx ? 1 : 0;
1167d98b8539SMaya Erez 	u32 status_msg_idx = dbg_status_msg_index;
1168d98b8539SMaya Erez 	u32 *u;
1169d98b8539SMaya Erez 
1170d98b8539SMaya Erez 	if (sring_idx >= WIL6210_MAX_STATUS_RINGS) {
1171d98b8539SMaya Erez 		seq_printf(s, "invalid status ring index %d\n", sring_idx);
1172d98b8539SMaya Erez 		return 0;
1173d98b8539SMaya Erez 	}
1174d98b8539SMaya Erez 
1175d98b8539SMaya Erez 	sring = &wil->srings[sring_idx];
1176d98b8539SMaya Erez 
1177d98b8539SMaya Erez 	if (!sring->va) {
1178d98b8539SMaya Erez 		seq_printf(s, "No %cX status ring\n", tx ? 'T' : 'R');
1179d98b8539SMaya Erez 		return 0;
1180d98b8539SMaya Erez 	}
1181d98b8539SMaya Erez 
1182d98b8539SMaya Erez 	if (status_msg_idx >= sring->size) {
1183d98b8539SMaya Erez 		seq_printf(s, "%cxDesc index (%d) >= size (%d)\n",
1184d98b8539SMaya Erez 			   tx ? 'T' : 'R', status_msg_idx, sring->size);
1185d98b8539SMaya Erez 		return 0;
1186d98b8539SMaya Erez 	}
1187d98b8539SMaya Erez 
1188d98b8539SMaya Erez 	u = sring->va + (sring->elem_size * status_msg_idx);
1189d98b8539SMaya Erez 
1190d98b8539SMaya Erez 	seq_printf(s, "%cx[%d][%3d] = {\n",
1191d98b8539SMaya Erez 		   tx ? 'T' : 'R', sring_idx, status_msg_idx);
1192d98b8539SMaya Erez 
1193d98b8539SMaya Erez 	seq_printf(s, "  0x%08x 0x%08x 0x%08x 0x%08x\n",
1194d98b8539SMaya Erez 		   u[0], u[1], u[2], u[3]);
1195d98b8539SMaya Erez 	if (!tx && !wil->use_compressed_rx_status)
1196d98b8539SMaya Erez 		seq_printf(s, "  0x%08x 0x%08x 0x%08x 0x%08x\n",
1197d98b8539SMaya Erez 			   u[4], u[5], u[6], u[7]);
1198d98b8539SMaya Erez 
1199d98b8539SMaya Erez 	seq_puts(s, "}\n");
1200d98b8539SMaya Erez 
1201d98b8539SMaya Erez 	return 0;
1202d98b8539SMaya Erez }
1203d98b8539SMaya Erez 
1204d98b8539SMaya Erez static int wil_status_msg_seq_open(struct inode *inode, struct file *file)
1205d98b8539SMaya Erez {
1206d98b8539SMaya Erez 	return single_open(file, wil_status_msg_debugfs_show,
1207d98b8539SMaya Erez 			   inode->i_private);
1208d98b8539SMaya Erez }
1209d98b8539SMaya Erez 
1210d98b8539SMaya Erez static const struct file_operations fops_status_msg = {
1211d98b8539SMaya Erez 	.open		= wil_status_msg_seq_open,
1212d98b8539SMaya Erez 	.release	= single_release,
1213d98b8539SMaya Erez 	.read		= seq_read,
1214d98b8539SMaya Erez 	.llseek		= seq_lseek,
1215d98b8539SMaya Erez };
1216d98b8539SMaya Erez 
1217d98b8539SMaya Erez static int wil_print_rx_buff(struct seq_file *s, struct list_head *lh)
1218d98b8539SMaya Erez {
1219d98b8539SMaya Erez 	struct wil_rx_buff *it;
1220d98b8539SMaya Erez 	int i = 0;
1221d98b8539SMaya Erez 
1222d98b8539SMaya Erez 	list_for_each_entry(it, lh, list) {
1223d98b8539SMaya Erez 		if ((i % 16) == 0 && i != 0)
1224d98b8539SMaya Erez 			seq_puts(s, "\n    ");
1225d98b8539SMaya Erez 		seq_printf(s, "[%4d] ", it->id);
1226d98b8539SMaya Erez 		i++;
1227d98b8539SMaya Erez 	}
1228d98b8539SMaya Erez 	seq_printf(s, "\nNumber of buffers: %u\n", i);
1229d98b8539SMaya Erez 
1230d98b8539SMaya Erez 	return i;
1231d98b8539SMaya Erez }
1232d98b8539SMaya Erez 
1233d98b8539SMaya Erez static int wil_rx_buff_mgmt_debugfs_show(struct seq_file *s, void *data)
1234d98b8539SMaya Erez {
1235d98b8539SMaya Erez 	struct wil6210_priv *wil = s->private;
1236d98b8539SMaya Erez 	struct wil_rx_buff_mgmt *rbm = &wil->rx_buff_mgmt;
1237d98b8539SMaya Erez 	int num_active;
1238d98b8539SMaya Erez 	int num_free;
1239d98b8539SMaya Erez 
1240d98b8539SMaya Erez 	seq_printf(s, "  size = %zu\n", rbm->size);
1241d98b8539SMaya Erez 	seq_printf(s, "  free_list_empty_cnt = %lu\n",
1242d98b8539SMaya Erez 		   rbm->free_list_empty_cnt);
1243d98b8539SMaya Erez 
1244d98b8539SMaya Erez 	/* Print active list */
1245d98b8539SMaya Erez 	seq_puts(s, "  Active list:\n");
1246d98b8539SMaya Erez 	num_active = wil_print_rx_buff(s, &rbm->active);
1247d98b8539SMaya Erez 	seq_puts(s, "\n  Free list:\n");
1248d98b8539SMaya Erez 	num_free = wil_print_rx_buff(s, &rbm->free);
1249d98b8539SMaya Erez 
1250d98b8539SMaya Erez 	seq_printf(s, "  Total number of buffers: %u\n",
1251d98b8539SMaya Erez 		   num_active + num_free);
1252d98b8539SMaya Erez 
1253d98b8539SMaya Erez 	return 0;
1254d98b8539SMaya Erez }
1255d98b8539SMaya Erez 
1256d98b8539SMaya Erez static int wil_rx_buff_mgmt_seq_open(struct inode *inode, struct file *file)
1257d98b8539SMaya Erez {
1258d98b8539SMaya Erez 	return single_open(file, wil_rx_buff_mgmt_debugfs_show,
1259d98b8539SMaya Erez 			   inode->i_private);
1260d98b8539SMaya Erez }
1261d98b8539SMaya Erez 
1262d98b8539SMaya Erez static const struct file_operations fops_rx_buff_mgmt = {
1263d98b8539SMaya Erez 	.open		= wil_rx_buff_mgmt_seq_open,
1264d98b8539SMaya Erez 	.release	= single_release,
1265d98b8539SMaya Erez 	.read		= seq_read,
1266d98b8539SMaya Erez 	.llseek		= seq_lseek,
1267d98b8539SMaya Erez };
1268d98b8539SMaya Erez 
12692be7d22fSVladimir Kondratiev /*---------beamforming------------*/
127036345ac3SVladimir Kondratiev static char *wil_bfstatus_str(u32 status)
127136345ac3SVladimir Kondratiev {
127236345ac3SVladimir Kondratiev 	switch (status) {
127336345ac3SVladimir Kondratiev 	case 0:
127436345ac3SVladimir Kondratiev 		return "Failed";
127536345ac3SVladimir Kondratiev 	case 1:
127636345ac3SVladimir Kondratiev 		return "OK";
127736345ac3SVladimir Kondratiev 	case 2:
127836345ac3SVladimir Kondratiev 		return "Retrying";
127936345ac3SVladimir Kondratiev 	default:
128036345ac3SVladimir Kondratiev 		return "??";
128136345ac3SVladimir Kondratiev 	}
128236345ac3SVladimir Kondratiev }
128336345ac3SVladimir Kondratiev 
128436345ac3SVladimir Kondratiev static bool is_all_zeros(void * const x_, size_t sz)
128536345ac3SVladimir Kondratiev {
128636345ac3SVladimir Kondratiev 	/* if reply is all-0, ignore this CID */
128736345ac3SVladimir Kondratiev 	u32 *x = x_;
128836345ac3SVladimir Kondratiev 	int n;
128936345ac3SVladimir Kondratiev 
129036345ac3SVladimir Kondratiev 	for (n = 0; n < sz / sizeof(*x); n++)
129136345ac3SVladimir Kondratiev 		if (x[n])
129236345ac3SVladimir Kondratiev 			return false;
129336345ac3SVladimir Kondratiev 
129436345ac3SVladimir Kondratiev 	return true;
129536345ac3SVladimir Kondratiev }
129636345ac3SVladimir Kondratiev 
12972be7d22fSVladimir Kondratiev static int wil_bf_debugfs_show(struct seq_file *s, void *data)
12982be7d22fSVladimir Kondratiev {
129936345ac3SVladimir Kondratiev 	int rc;
130036345ac3SVladimir Kondratiev 	int i;
13012be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
1302e00243faSLior David 	struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
130336345ac3SVladimir Kondratiev 	struct wmi_notify_req_cmd cmd = {
130436345ac3SVladimir Kondratiev 		.interval_usec = 0,
130536345ac3SVladimir Kondratiev 	};
130636345ac3SVladimir Kondratiev 	struct {
1307b874ddecSLior David 		struct wmi_cmd_hdr wmi;
130836345ac3SVladimir Kondratiev 		struct wmi_notify_req_done_event evt;
130936345ac3SVladimir Kondratiev 	} __packed reply;
131036345ac3SVladimir Kondratiev 
1311807b0860SAlexei Avshalom Lazar 	memset(&reply, 0, sizeof(reply));
1312807b0860SAlexei Avshalom Lazar 
131336345ac3SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
131436345ac3SVladimir Kondratiev 		u32 status;
131536345ac3SVladimir Kondratiev 
131636345ac3SVladimir Kondratiev 		cmd.cid = i;
1317e00243faSLior David 		rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, vif->mid,
1318e00243faSLior David 			      &cmd, sizeof(cmd),
131936345ac3SVladimir Kondratiev 			      WMI_NOTIFY_REQ_DONE_EVENTID, &reply,
132036345ac3SVladimir Kondratiev 			      sizeof(reply), 20);
132136345ac3SVladimir Kondratiev 		/* if reply is all-0, ignore this CID */
132236345ac3SVladimir Kondratiev 		if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt)))
132336345ac3SVladimir Kondratiev 			continue;
132436345ac3SVladimir Kondratiev 
132536345ac3SVladimir Kondratiev 		status = le32_to_cpu(reply.evt.status);
132636345ac3SVladimir Kondratiev 		seq_printf(s, "CID %d {\n"
132736345ac3SVladimir Kondratiev 			   "  TSF = 0x%016llx\n"
132836345ac3SVladimir Kondratiev 			   "  TxMCS = %2d TxTpt = %4d\n"
132936345ac3SVladimir Kondratiev 			   "  SQI = %4d\n"
133030868f5dSDedy Lansky 			   "  RSSI = %4d\n"
133136345ac3SVladimir Kondratiev 			   "  Status = 0x%08x %s\n"
133236345ac3SVladimir Kondratiev 			   "  Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
133336345ac3SVladimir Kondratiev 			   "  Goodput(rx:tx) %4d:%4d\n"
133436345ac3SVladimir Kondratiev 			   "}\n",
133536345ac3SVladimir Kondratiev 			   i,
133636345ac3SVladimir Kondratiev 			   le64_to_cpu(reply.evt.tsf),
133736345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.bf_mcs),
133836345ac3SVladimir Kondratiev 			   le32_to_cpu(reply.evt.tx_tpt),
133936345ac3SVladimir Kondratiev 			   reply.evt.sqi,
134030868f5dSDedy Lansky 			   reply.evt.rssi,
134136345ac3SVladimir Kondratiev 			   status, wil_bfstatus_str(status),
134236345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.my_rx_sector),
134336345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.my_tx_sector),
134436345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.other_rx_sector),
134536345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.other_tx_sector),
134636345ac3SVladimir Kondratiev 			   le32_to_cpu(reply.evt.rx_goodput),
134736345ac3SVladimir Kondratiev 			   le32_to_cpu(reply.evt.tx_goodput));
134836345ac3SVladimir Kondratiev 	}
13492be7d22fSVladimir Kondratiev 	return 0;
13502be7d22fSVladimir Kondratiev }
13512be7d22fSVladimir Kondratiev 
13522be7d22fSVladimir Kondratiev static int wil_bf_seq_open(struct inode *inode, struct file *file)
13532be7d22fSVladimir Kondratiev {
13542be7d22fSVladimir Kondratiev 	return single_open(file, wil_bf_debugfs_show, inode->i_private);
13552be7d22fSVladimir Kondratiev }
13562be7d22fSVladimir Kondratiev 
13572be7d22fSVladimir Kondratiev static const struct file_operations fops_bf = {
13582be7d22fSVladimir Kondratiev 	.open		= wil_bf_seq_open,
13592be7d22fSVladimir Kondratiev 	.release	= single_release,
13602be7d22fSVladimir Kondratiev 	.read		= seq_read,
13612be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
13622be7d22fSVladimir Kondratiev };
13638fe59627SVladimir Kondratiev 
13641a2780e0SVladimir Kondratiev /*---------temp------------*/
13656d9eb7ebSDedy Lansky static void print_temp(struct seq_file *s, const char *prefix, s32 t)
13661a2780e0SVladimir Kondratiev {
13671a2780e0SVladimir Kondratiev 	switch (t) {
13681a2780e0SVladimir Kondratiev 	case 0:
13691a2780e0SVladimir Kondratiev 	case ~(u32)0:
13701a2780e0SVladimir Kondratiev 		seq_printf(s, "%s N/A\n", prefix);
13711a2780e0SVladimir Kondratiev 	break;
13721a2780e0SVladimir Kondratiev 	default:
13736d9eb7ebSDedy Lansky 		seq_printf(s, "%s %s%d.%03d\n", prefix, (t < 0 ? "-" : ""),
13746d9eb7ebSDedy Lansky 			   abs(t / 1000), abs(t % 1000));
13751a2780e0SVladimir Kondratiev 		break;
13761a2780e0SVladimir Kondratiev 	}
13771a2780e0SVladimir Kondratiev }
13781a2780e0SVladimir Kondratiev 
13791a2780e0SVladimir Kondratiev static int wil_temp_debugfs_show(struct seq_file *s, void *data)
13801a2780e0SVladimir Kondratiev {
13811a2780e0SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
13826d9eb7ebSDedy Lansky 	s32 t_m, t_r;
13831a2780e0SVladimir Kondratiev 	int rc = wmi_get_temperature(wil, &t_m, &t_r);
13848fe59627SVladimir Kondratiev 
13851a2780e0SVladimir Kondratiev 	if (rc) {
13868fe59627SVladimir Kondratiev 		seq_puts(s, "Failed\n");
13871a2780e0SVladimir Kondratiev 		return 0;
13881a2780e0SVladimir Kondratiev 	}
13891a2780e0SVladimir Kondratiev 
1390d45cff9fSVladimir Kondratiev 	print_temp(s, "T_mac   =", t_m);
1391d45cff9fSVladimir Kondratiev 	print_temp(s, "T_radio =", t_r);
13921a2780e0SVladimir Kondratiev 
13931a2780e0SVladimir Kondratiev 	return 0;
13941a2780e0SVladimir Kondratiev }
13951a2780e0SVladimir Kondratiev 
13961a2780e0SVladimir Kondratiev static int wil_temp_seq_open(struct inode *inode, struct file *file)
13971a2780e0SVladimir Kondratiev {
13981a2780e0SVladimir Kondratiev 	return single_open(file, wil_temp_debugfs_show, inode->i_private);
13991a2780e0SVladimir Kondratiev }
14001a2780e0SVladimir Kondratiev 
14011a2780e0SVladimir Kondratiev static const struct file_operations fops_temp = {
14021a2780e0SVladimir Kondratiev 	.open		= wil_temp_seq_open,
14031a2780e0SVladimir Kondratiev 	.release	= single_release,
14041a2780e0SVladimir Kondratiev 	.read		= seq_read,
14051a2780e0SVladimir Kondratiev 	.llseek		= seq_lseek,
14061a2780e0SVladimir Kondratiev };
14071a2780e0SVladimir Kondratiev 
14089eb82d43SVladimir Kondratiev /*---------freq------------*/
14099eb82d43SVladimir Kondratiev static int wil_freq_debugfs_show(struct seq_file *s, void *data)
14109eb82d43SVladimir Kondratiev {
14119eb82d43SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
1412e00243faSLior David 	struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr;
14139eb82d43SVladimir Kondratiev 	u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
14149eb82d43SVladimir Kondratiev 
14159eb82d43SVladimir Kondratiev 	seq_printf(s, "Freq = %d\n", freq);
14169eb82d43SVladimir Kondratiev 
14179eb82d43SVladimir Kondratiev 	return 0;
14189eb82d43SVladimir Kondratiev }
14199eb82d43SVladimir Kondratiev 
14209eb82d43SVladimir Kondratiev static int wil_freq_seq_open(struct inode *inode, struct file *file)
14219eb82d43SVladimir Kondratiev {
14229eb82d43SVladimir Kondratiev 	return single_open(file, wil_freq_debugfs_show, inode->i_private);
14239eb82d43SVladimir Kondratiev }
14249eb82d43SVladimir Kondratiev 
14259eb82d43SVladimir Kondratiev static const struct file_operations fops_freq = {
14269eb82d43SVladimir Kondratiev 	.open		= wil_freq_seq_open,
14279eb82d43SVladimir Kondratiev 	.release	= single_release,
14289eb82d43SVladimir Kondratiev 	.read		= seq_read,
14299eb82d43SVladimir Kondratiev 	.llseek		= seq_lseek,
14309eb82d43SVladimir Kondratiev };
14319eb82d43SVladimir Kondratiev 
14329eb82d43SVladimir Kondratiev /*---------link------------*/
14339eb82d43SVladimir Kondratiev static int wil_link_debugfs_show(struct seq_file *s, void *data)
14349eb82d43SVladimir Kondratiev {
14359eb82d43SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
143641bd3d58SToke Høiland-Jørgensen 	struct station_info *sinfo;
143741bd3d58SToke Høiland-Jørgensen 	int i, rc = 0;
143841bd3d58SToke Høiland-Jørgensen 
143941bd3d58SToke Høiland-Jørgensen 	sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL);
144041bd3d58SToke Høiland-Jørgensen 	if (!sinfo)
144141bd3d58SToke Høiland-Jørgensen 		return -ENOMEM;
14429eb82d43SVladimir Kondratiev 
14439eb82d43SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
14449eb82d43SVladimir Kondratiev 		struct wil_sta_info *p = &wil->sta[i];
14459eb82d43SVladimir Kondratiev 		char *status = "unknown";
14465bd60982SLior David 		struct wil6210_vif *vif;
14475bd60982SLior David 		u8 mid;
14488fe59627SVladimir Kondratiev 
14499eb82d43SVladimir Kondratiev 		switch (p->status) {
14509eb82d43SVladimir Kondratiev 		case wil_sta_unused:
14519eb82d43SVladimir Kondratiev 			status = "unused   ";
14529eb82d43SVladimir Kondratiev 			break;
14539eb82d43SVladimir Kondratiev 		case wil_sta_conn_pending:
14549eb82d43SVladimir Kondratiev 			status = "pending  ";
14559eb82d43SVladimir Kondratiev 			break;
14569eb82d43SVladimir Kondratiev 		case wil_sta_connected:
14579eb82d43SVladimir Kondratiev 			status = "connected";
14589eb82d43SVladimir Kondratiev 			break;
14599eb82d43SVladimir Kondratiev 		}
14605bd60982SLior David 		mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
14615bd60982SLior David 		seq_printf(s, "[%d][MID %d] %pM %s\n",
14625bd60982SLior David 			   i, mid, p->addr, status);
14639eb82d43SVladimir Kondratiev 
14645bd60982SLior David 		if (p->status != wil_sta_connected)
14655bd60982SLior David 			continue;
14665bd60982SLior David 
14675bd60982SLior David 		vif = (mid < wil->max_vifs) ? wil->vifs[mid] : NULL;
14685bd60982SLior David 		if (vif) {
146941bd3d58SToke Høiland-Jørgensen 			rc = wil_cid_fill_sinfo(vif, i, sinfo);
14709eb82d43SVladimir Kondratiev 			if (rc)
147141bd3d58SToke Høiland-Jørgensen 				goto out;
14729eb82d43SVladimir Kondratiev 
147341bd3d58SToke Høiland-Jørgensen 			seq_printf(s, "  Tx_mcs = %d\n", sinfo->txrate.mcs);
147441bd3d58SToke Høiland-Jørgensen 			seq_printf(s, "  Rx_mcs = %d\n", sinfo->rxrate.mcs);
147541bd3d58SToke Høiland-Jørgensen 			seq_printf(s, "  SQ     = %d\n", sinfo->signal);
14765bd60982SLior David 		} else {
14775bd60982SLior David 			seq_puts(s, "  INVALID MID\n");
14789eb82d43SVladimir Kondratiev 		}
14799eb82d43SVladimir Kondratiev 	}
14809eb82d43SVladimir Kondratiev 
148141bd3d58SToke Høiland-Jørgensen out:
148241bd3d58SToke Høiland-Jørgensen 	kfree(sinfo);
148341bd3d58SToke Høiland-Jørgensen 	return rc;
14849eb82d43SVladimir Kondratiev }
14859eb82d43SVladimir Kondratiev 
14869eb82d43SVladimir Kondratiev static int wil_link_seq_open(struct inode *inode, struct file *file)
14879eb82d43SVladimir Kondratiev {
14889eb82d43SVladimir Kondratiev 	return single_open(file, wil_link_debugfs_show, inode->i_private);
14899eb82d43SVladimir Kondratiev }
14909eb82d43SVladimir Kondratiev 
14919eb82d43SVladimir Kondratiev static const struct file_operations fops_link = {
14929eb82d43SVladimir Kondratiev 	.open		= wil_link_seq_open,
14939eb82d43SVladimir Kondratiev 	.release	= single_release,
14949eb82d43SVladimir Kondratiev 	.read		= seq_read,
14959eb82d43SVladimir Kondratiev 	.llseek		= seq_lseek,
14969eb82d43SVladimir Kondratiev };
14979eb82d43SVladimir Kondratiev 
149884bb29b7SVladimir Kondratiev /*---------info------------*/
149984bb29b7SVladimir Kondratiev static int wil_info_debugfs_show(struct seq_file *s, void *data)
150084bb29b7SVladimir Kondratiev {
1501be299858SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
1502e00243faSLior David 	struct net_device *ndev = wil->main_ndev;
150384bb29b7SVladimir Kondratiev 	int is_ac = power_supply_is_system_supplied();
1504be299858SVladimir Kondratiev 	int rx = atomic_xchg(&wil->isr_count_rx, 0);
1505be299858SVladimir Kondratiev 	int tx = atomic_xchg(&wil->isr_count_tx, 0);
1506be299858SVladimir Kondratiev 	static ulong rxf_old, txf_old;
1507be299858SVladimir Kondratiev 	ulong rxf = ndev->stats.rx_packets;
1508be299858SVladimir Kondratiev 	ulong txf = ndev->stats.tx_packets;
150955f8f680SVladimir Kondratiev 	unsigned int i;
151084bb29b7SVladimir Kondratiev 
151184bb29b7SVladimir Kondratiev 	/* >0 : AC; 0 : battery; <0 : error */
151284bb29b7SVladimir Kondratiev 	seq_printf(s, "AC powered : %d\n", is_ac);
1513be299858SVladimir Kondratiev 	seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
1514be299858SVladimir Kondratiev 	seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
1515be299858SVladimir Kondratiev 	rxf_old = rxf;
1516be299858SVladimir Kondratiev 	txf_old = txf;
151784bb29b7SVladimir Kondratiev 
151855f8f680SVladimir Kondratiev #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
151955f8f680SVladimir Kondratiev 	" " __stringify(x) : ""
152055f8f680SVladimir Kondratiev 
152155f8f680SVladimir Kondratiev 	for (i = 0; i < ndev->num_tx_queues; i++) {
152255f8f680SVladimir Kondratiev 		struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
152355f8f680SVladimir Kondratiev 		unsigned long state = txq->state;
152455f8f680SVladimir Kondratiev 
152555f8f680SVladimir Kondratiev 		seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
152655f8f680SVladimir Kondratiev 			   CHECK_QSTATE(DRV_XOFF),
152755f8f680SVladimir Kondratiev 			   CHECK_QSTATE(STACK_XOFF),
152855f8f680SVladimir Kondratiev 			   CHECK_QSTATE(FROZEN)
152955f8f680SVladimir Kondratiev 			  );
153055f8f680SVladimir Kondratiev 	}
153155f8f680SVladimir Kondratiev #undef CHECK_QSTATE
153284bb29b7SVladimir Kondratiev 	return 0;
153384bb29b7SVladimir Kondratiev }
153484bb29b7SVladimir Kondratiev 
153584bb29b7SVladimir Kondratiev static int wil_info_seq_open(struct inode *inode, struct file *file)
153684bb29b7SVladimir Kondratiev {
153784bb29b7SVladimir Kondratiev 	return single_open(file, wil_info_debugfs_show, inode->i_private);
153884bb29b7SVladimir Kondratiev }
153984bb29b7SVladimir Kondratiev 
154084bb29b7SVladimir Kondratiev static const struct file_operations fops_info = {
154184bb29b7SVladimir Kondratiev 	.open		= wil_info_seq_open,
154284bb29b7SVladimir Kondratiev 	.release	= single_release,
154384bb29b7SVladimir Kondratiev 	.read		= seq_read,
154484bb29b7SVladimir Kondratiev 	.llseek		= seq_lseek,
154584bb29b7SVladimir Kondratiev };
154684bb29b7SVladimir Kondratiev 
1547c33407a8SVladimir Kondratiev /*---------recovery------------*/
1548c33407a8SVladimir Kondratiev /* mode = [manual|auto]
1549c33407a8SVladimir Kondratiev  * state = [idle|pending|running]
1550c33407a8SVladimir Kondratiev  */
1551c33407a8SVladimir Kondratiev static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf,
1552c33407a8SVladimir Kondratiev 				      size_t count, loff_t *ppos)
1553c33407a8SVladimir Kondratiev {
1554c33407a8SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
1555c33407a8SVladimir Kondratiev 	char buf[80];
1556c33407a8SVladimir Kondratiev 	int n;
1557c33407a8SVladimir Kondratiev 	static const char * const sstate[] = {"idle", "pending", "running"};
1558c33407a8SVladimir Kondratiev 
1559c33407a8SVladimir Kondratiev 	n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n",
1560c33407a8SVladimir Kondratiev 		     no_fw_recovery ? "manual" : "auto",
1561c33407a8SVladimir Kondratiev 		     sstate[wil->recovery_state]);
1562c33407a8SVladimir Kondratiev 
1563c33407a8SVladimir Kondratiev 	n = min_t(int, n, sizeof(buf));
1564c33407a8SVladimir Kondratiev 
1565c33407a8SVladimir Kondratiev 	return simple_read_from_buffer(user_buf, count, ppos,
1566c33407a8SVladimir Kondratiev 				       buf, n);
1567c33407a8SVladimir Kondratiev }
1568c33407a8SVladimir Kondratiev 
1569c33407a8SVladimir Kondratiev static ssize_t wil_write_file_recovery(struct file *file,
1570c33407a8SVladimir Kondratiev 				       const char __user *buf_,
1571c33407a8SVladimir Kondratiev 				       size_t count, loff_t *ppos)
1572c33407a8SVladimir Kondratiev {
1573c33407a8SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
1574c33407a8SVladimir Kondratiev 	static const char run_command[] = "run";
1575c33407a8SVladimir Kondratiev 	char buf[sizeof(run_command) + 1]; /* to detect "runx" */
1576c33407a8SVladimir Kondratiev 	ssize_t rc;
1577c33407a8SVladimir Kondratiev 
1578c33407a8SVladimir Kondratiev 	if (wil->recovery_state != fw_recovery_pending) {
1579c33407a8SVladimir Kondratiev 		wil_err(wil, "No recovery pending\n");
1580c33407a8SVladimir Kondratiev 		return -EINVAL;
1581c33407a8SVladimir Kondratiev 	}
1582c33407a8SVladimir Kondratiev 
1583c33407a8SVladimir Kondratiev 	if (*ppos != 0) {
1584c33407a8SVladimir Kondratiev 		wil_err(wil, "Offset [%d]\n", (int)*ppos);
1585c33407a8SVladimir Kondratiev 		return -EINVAL;
1586c33407a8SVladimir Kondratiev 	}
1587c33407a8SVladimir Kondratiev 
1588c33407a8SVladimir Kondratiev 	if (count > sizeof(buf)) {
1589c33407a8SVladimir Kondratiev 		wil_err(wil, "Input too long, len = %d\n", (int)count);
1590c33407a8SVladimir Kondratiev 		return -EINVAL;
1591c33407a8SVladimir Kondratiev 	}
1592c33407a8SVladimir Kondratiev 
1593c33407a8SVladimir Kondratiev 	rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count);
1594c33407a8SVladimir Kondratiev 	if (rc < 0)
1595c33407a8SVladimir Kondratiev 		return rc;
1596c33407a8SVladimir Kondratiev 
1597c33407a8SVladimir Kondratiev 	buf[rc] = '\0';
1598c33407a8SVladimir Kondratiev 	if (0 == strcmp(buf, run_command))
1599c33407a8SVladimir Kondratiev 		wil_set_recovery_state(wil, fw_recovery_running);
1600c33407a8SVladimir Kondratiev 	else
1601c33407a8SVladimir Kondratiev 		wil_err(wil, "Bad recovery command \"%s\"\n", buf);
1602c33407a8SVladimir Kondratiev 
1603c33407a8SVladimir Kondratiev 	return rc;
1604c33407a8SVladimir Kondratiev }
1605c33407a8SVladimir Kondratiev 
1606c33407a8SVladimir Kondratiev static const struct file_operations fops_recovery = {
1607c33407a8SVladimir Kondratiev 	.read = wil_read_file_recovery,
1608c33407a8SVladimir Kondratiev 	.write = wil_write_file_recovery,
1609c33407a8SVladimir Kondratiev 	.open  = simple_open,
1610c33407a8SVladimir Kondratiev };
1611c33407a8SVladimir Kondratiev 
16123df2cd36SVladimir Kondratiev /*---------Station matrix------------*/
1613b4490f42SVladimir Kondratiev static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
1614b4490f42SVladimir Kondratiev {
1615b4490f42SVladimir Kondratiev 	int i;
1616b4490f42SVladimir Kondratiev 	u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
161791a8edccSVladimir Kondratiev 	unsigned long long drop_dup = r->drop_dup, drop_old = r->drop_old;
16181bd82ee0SDedy Lansky 	unsigned long long drop_dup_mcast = r->drop_dup_mcast;
16198fe59627SVladimir Kondratiev 
162037f8d26dSDedy Lansky 	seq_printf(s, "([%2d]) 0x%03x [", r->buf_size, r->head_seq_num);
1621b4490f42SVladimir Kondratiev 	for (i = 0; i < r->buf_size; i++) {
1622b4490f42SVladimir Kondratiev 		if (i == index)
1623b4490f42SVladimir Kondratiev 			seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
1624b4490f42SVladimir Kondratiev 		else
1625b4490f42SVladimir Kondratiev 			seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
1626b4490f42SVladimir Kondratiev 	}
162791a8edccSVladimir Kondratiev 	seq_printf(s,
16281bd82ee0SDedy Lansky 		   "] total %llu drop %llu (dup %llu + old %llu + dup mcast %llu) last 0x%03x\n",
16291bd82ee0SDedy Lansky 		   r->total, drop_dup + drop_old + drop_dup_mcast, drop_dup,
16301bd82ee0SDedy Lansky 		   drop_old, drop_dup_mcast, r->ssn_last_drop);
1631b4490f42SVladimir Kondratiev }
16323df2cd36SVladimir Kondratiev 
163358527421SVladimir Kondratiev static void wil_print_rxtid_crypto(struct seq_file *s, int tid,
163458527421SVladimir Kondratiev 				   struct wil_tid_crypto_rx *c)
163558527421SVladimir Kondratiev {
163658527421SVladimir Kondratiev 	int i;
163758527421SVladimir Kondratiev 
163858527421SVladimir Kondratiev 	for (i = 0; i < 4; i++) {
163958527421SVladimir Kondratiev 		struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
164058527421SVladimir Kondratiev 
164158527421SVladimir Kondratiev 		if (cc->key_set)
164258527421SVladimir Kondratiev 			goto has_keys;
164358527421SVladimir Kondratiev 	}
164458527421SVladimir Kondratiev 	return;
164558527421SVladimir Kondratiev 
164658527421SVladimir Kondratiev has_keys:
164758527421SVladimir Kondratiev 	if (tid < WIL_STA_TID_NUM)
164858527421SVladimir Kondratiev 		seq_printf(s, "  [%2d] PN", tid);
164958527421SVladimir Kondratiev 	else
165058527421SVladimir Kondratiev 		seq_puts(s, "  [GR] PN");
165158527421SVladimir Kondratiev 
165258527421SVladimir Kondratiev 	for (i = 0; i < 4; i++) {
165358527421SVladimir Kondratiev 		struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
165458527421SVladimir Kondratiev 
165558527421SVladimir Kondratiev 		seq_printf(s, " [%i%s]%6phN", i, cc->key_set ? "+" : "-",
165658527421SVladimir Kondratiev 			   cc->pn);
165758527421SVladimir Kondratiev 	}
165858527421SVladimir Kondratiev 	seq_puts(s, "\n");
165958527421SVladimir Kondratiev }
166058527421SVladimir Kondratiev 
16613df2cd36SVladimir Kondratiev static int wil_sta_debugfs_show(struct seq_file *s, void *data)
1662bd33273bSVladimir Kondratiev __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
16633df2cd36SVladimir Kondratiev {
16643df2cd36SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
1665c4a110d8SVladimir Kondratiev 	int i, tid, mcs;
16663df2cd36SVladimir Kondratiev 
16673df2cd36SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
16683df2cd36SVladimir Kondratiev 		struct wil_sta_info *p = &wil->sta[i];
16693df2cd36SVladimir Kondratiev 		char *status = "unknown";
16709d865ee2SLior David 		u8 aid = 0;
16715bd60982SLior David 		u8 mid;
1672*b9010f10SAhmad Masri 		bool sta_connected = false;
16738fe59627SVladimir Kondratiev 
16743df2cd36SVladimir Kondratiev 		switch (p->status) {
16753df2cd36SVladimir Kondratiev 		case wil_sta_unused:
16763df2cd36SVladimir Kondratiev 			status = "unused   ";
16773df2cd36SVladimir Kondratiev 			break;
16783df2cd36SVladimir Kondratiev 		case wil_sta_conn_pending:
16793df2cd36SVladimir Kondratiev 			status = "pending  ";
16803df2cd36SVladimir Kondratiev 			break;
16813df2cd36SVladimir Kondratiev 		case wil_sta_connected:
16823df2cd36SVladimir Kondratiev 			status = "connected";
16839d865ee2SLior David 			aid = p->aid;
16843df2cd36SVladimir Kondratiev 			break;
16853df2cd36SVladimir Kondratiev 		}
16865bd60982SLior David 		mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
1687*b9010f10SAhmad Masri 		if (mid < wil->max_vifs) {
1688*b9010f10SAhmad Masri 			struct wil6210_vif *vif = wil->vifs[mid];
1689*b9010f10SAhmad Masri 
1690*b9010f10SAhmad Masri 			if (vif->wdev.iftype == NL80211_IFTYPE_STATION &&
1691*b9010f10SAhmad Masri 			    p->status == wil_sta_connected)
1692*b9010f10SAhmad Masri 				sta_connected = true;
1693*b9010f10SAhmad Masri 		}
1694*b9010f10SAhmad Masri 		/* print roam counter only for connected stations */
1695*b9010f10SAhmad Masri 		if (sta_connected)
1696*b9010f10SAhmad Masri 			seq_printf(s, "[%d] %pM connected (roam counter %d) MID %d AID %d\n",
1697*b9010f10SAhmad Masri 				   i, p->addr, p->stats.ft_roams, mid, aid);
1698*b9010f10SAhmad Masri 		else
1699*b9010f10SAhmad Masri 			seq_printf(s, "[%d] %pM %s MID %d AID %d\n", i,
1700*b9010f10SAhmad Masri 				   p->addr, status, mid, aid);
1701b4490f42SVladimir Kondratiev 
1702b4490f42SVladimir Kondratiev 		if (p->status == wil_sta_connected) {
1703bd33273bSVladimir Kondratiev 			spin_lock_bh(&p->tid_rx_lock);
1704b4490f42SVladimir Kondratiev 			for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1705b4490f42SVladimir Kondratiev 				struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
170658527421SVladimir Kondratiev 				struct wil_tid_crypto_rx *c =
170758527421SVladimir Kondratiev 						&p->tid_crypto_rx[tid];
17088fe59627SVladimir Kondratiev 
1709b4490f42SVladimir Kondratiev 				if (r) {
1710b4490f42SVladimir Kondratiev 					seq_printf(s, "  [%2d] ", tid);
1711b4490f42SVladimir Kondratiev 					wil_print_rxtid(s, r);
1712b4490f42SVladimir Kondratiev 				}
171358527421SVladimir Kondratiev 
171458527421SVladimir Kondratiev 				wil_print_rxtid_crypto(s, tid, c);
1715b4490f42SVladimir Kondratiev 			}
171658527421SVladimir Kondratiev 			wil_print_rxtid_crypto(s, WIL_STA_TID_NUM,
171758527421SVladimir Kondratiev 					       &p->group_crypto_rx);
1718bd33273bSVladimir Kondratiev 			spin_unlock_bh(&p->tid_rx_lock);
17193b282bc6SVladimir Kondratiev 			seq_printf(s,
172058527421SVladimir Kondratiev 				   "Rx invalid frame: non-data %lu, short %lu, large %lu, replay %lu\n",
17213b282bc6SVladimir Kondratiev 				   p->stats.rx_non_data_frame,
17223b282bc6SVladimir Kondratiev 				   p->stats.rx_short_frame,
172358527421SVladimir Kondratiev 				   p->stats.rx_large_frame,
172458527421SVladimir Kondratiev 				   p->stats.rx_replay);
1725d98b8539SMaya Erez 			seq_printf(s,
17260b853210SMaya Erez 				   "mic error %lu, key error %lu, amsdu error %lu, csum error %lu\n",
1727d98b8539SMaya Erez 				   p->stats.rx_mic_error,
1728d98b8539SMaya Erez 				   p->stats.rx_key_error,
17290b853210SMaya Erez 				   p->stats.rx_amsdu_error,
17300b853210SMaya Erez 				   p->stats.rx_csum_err);
1731d98b8539SMaya Erez 
1732c4a110d8SVladimir Kondratiev 			seq_puts(s, "Rx/MCS:");
1733c4a110d8SVladimir Kondratiev 			for (mcs = 0; mcs < ARRAY_SIZE(p->stats.rx_per_mcs);
1734c4a110d8SVladimir Kondratiev 			     mcs++)
1735c4a110d8SVladimir Kondratiev 				seq_printf(s, " %lld",
1736c4a110d8SVladimir Kondratiev 					   p->stats.rx_per_mcs[mcs]);
1737c4a110d8SVladimir Kondratiev 			seq_puts(s, "\n");
1738b4490f42SVladimir Kondratiev 		}
17393df2cd36SVladimir Kondratiev 	}
17403df2cd36SVladimir Kondratiev 
17413df2cd36SVladimir Kondratiev 	return 0;
17423df2cd36SVladimir Kondratiev }
17433df2cd36SVladimir Kondratiev 
17443df2cd36SVladimir Kondratiev static int wil_sta_seq_open(struct inode *inode, struct file *file)
17453df2cd36SVladimir Kondratiev {
17463df2cd36SVladimir Kondratiev 	return single_open(file, wil_sta_debugfs_show, inode->i_private);
17473df2cd36SVladimir Kondratiev }
17483df2cd36SVladimir Kondratiev 
17493df2cd36SVladimir Kondratiev static const struct file_operations fops_sta = {
17503df2cd36SVladimir Kondratiev 	.open		= wil_sta_seq_open,
17513df2cd36SVladimir Kondratiev 	.release	= single_release,
17523df2cd36SVladimir Kondratiev 	.read		= seq_read,
17533df2cd36SVladimir Kondratiev 	.llseek		= seq_lseek,
17543df2cd36SVladimir Kondratiev };
17553df2cd36SVladimir Kondratiev 
17563a3b745fSLior David static int wil_mids_debugfs_show(struct seq_file *s, void *data)
17573a3b745fSLior David {
17583a3b745fSLior David 	struct wil6210_priv *wil = s->private;
17593a3b745fSLior David 	struct wil6210_vif *vif;
17603a3b745fSLior David 	struct net_device *ndev;
17613a3b745fSLior David 	int i;
17623a3b745fSLior David 
17633a3b745fSLior David 	mutex_lock(&wil->vif_mutex);
17643a3b745fSLior David 	for (i = 0; i < wil->max_vifs; i++) {
17653a3b745fSLior David 		vif = wil->vifs[i];
17663a3b745fSLior David 
17673a3b745fSLior David 		if (vif) {
17683a3b745fSLior David 			ndev = vif_to_ndev(vif);
17693a3b745fSLior David 			seq_printf(s, "[%d] %pM %s\n", i, ndev->dev_addr,
17703a3b745fSLior David 				   ndev->name);
17713a3b745fSLior David 		} else {
17723a3b745fSLior David 			seq_printf(s, "[%d] unused\n", i);
17733a3b745fSLior David 		}
17743a3b745fSLior David 	}
17753a3b745fSLior David 	mutex_unlock(&wil->vif_mutex);
17763a3b745fSLior David 
17773a3b745fSLior David 	return 0;
17783a3b745fSLior David }
17793a3b745fSLior David 
17803a3b745fSLior David static int wil_mids_seq_open(struct inode *inode, struct file *file)
17813a3b745fSLior David {
17823a3b745fSLior David 	return single_open(file, wil_mids_debugfs_show, inode->i_private);
17833a3b745fSLior David }
17843a3b745fSLior David 
17853a3b745fSLior David static const struct file_operations fops_mids = {
17863a3b745fSLior David 	.open		= wil_mids_seq_open,
17873a3b745fSLior David 	.release	= single_release,
17883a3b745fSLior David 	.read		= seq_read,
17893a3b745fSLior David 	.llseek		= seq_lseek,
17903a3b745fSLior David };
17913a3b745fSLior David 
1792a24a3d6aSDedy Lansky static int wil_tx_latency_debugfs_show(struct seq_file *s, void *data)
1793a24a3d6aSDedy Lansky __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
1794a24a3d6aSDedy Lansky {
1795a24a3d6aSDedy Lansky 	struct wil6210_priv *wil = s->private;
1796a24a3d6aSDedy Lansky 	int i, bin;
1797a24a3d6aSDedy Lansky 
1798a24a3d6aSDedy Lansky 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1799a24a3d6aSDedy Lansky 		struct wil_sta_info *p = &wil->sta[i];
1800a24a3d6aSDedy Lansky 		char *status = "unknown";
1801a24a3d6aSDedy Lansky 		u8 aid = 0;
1802a24a3d6aSDedy Lansky 		u8 mid;
1803a24a3d6aSDedy Lansky 
1804a24a3d6aSDedy Lansky 		if (!p->tx_latency_bins)
1805a24a3d6aSDedy Lansky 			continue;
1806a24a3d6aSDedy Lansky 
1807a24a3d6aSDedy Lansky 		switch (p->status) {
1808a24a3d6aSDedy Lansky 		case wil_sta_unused:
1809a24a3d6aSDedy Lansky 			status = "unused   ";
1810a24a3d6aSDedy Lansky 			break;
1811a24a3d6aSDedy Lansky 		case wil_sta_conn_pending:
1812a24a3d6aSDedy Lansky 			status = "pending  ";
1813a24a3d6aSDedy Lansky 			break;
1814a24a3d6aSDedy Lansky 		case wil_sta_connected:
1815a24a3d6aSDedy Lansky 			status = "connected";
1816a24a3d6aSDedy Lansky 			aid = p->aid;
1817a24a3d6aSDedy Lansky 			break;
1818a24a3d6aSDedy Lansky 		}
1819a24a3d6aSDedy Lansky 		mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
1820a24a3d6aSDedy Lansky 		seq_printf(s, "[%d] %pM %s MID %d AID %d\n", i, p->addr, status,
1821a24a3d6aSDedy Lansky 			   mid, aid);
1822a24a3d6aSDedy Lansky 
1823a24a3d6aSDedy Lansky 		if (p->status == wil_sta_connected) {
1824a24a3d6aSDedy Lansky 			u64 num_packets = 0;
1825a24a3d6aSDedy Lansky 			u64 tx_latency_avg = p->stats.tx_latency_total_us;
1826a24a3d6aSDedy Lansky 
1827a24a3d6aSDedy Lansky 			seq_puts(s, "Tx/Latency bin:");
1828a24a3d6aSDedy Lansky 			for (bin = 0; bin < WIL_NUM_LATENCY_BINS; bin++) {
1829a24a3d6aSDedy Lansky 				seq_printf(s, " %lld",
1830a24a3d6aSDedy Lansky 					   p->tx_latency_bins[bin]);
1831a24a3d6aSDedy Lansky 				num_packets += p->tx_latency_bins[bin];
1832a24a3d6aSDedy Lansky 			}
1833a24a3d6aSDedy Lansky 			seq_puts(s, "\n");
1834a24a3d6aSDedy Lansky 			if (!num_packets)
1835a24a3d6aSDedy Lansky 				continue;
1836a24a3d6aSDedy Lansky 			do_div(tx_latency_avg, num_packets);
1837a24a3d6aSDedy Lansky 			seq_printf(s, "Tx/Latency min/avg/max (us): %d/%lld/%d",
1838a24a3d6aSDedy Lansky 				   p->stats.tx_latency_min_us,
1839a24a3d6aSDedy Lansky 				   tx_latency_avg,
1840a24a3d6aSDedy Lansky 				   p->stats.tx_latency_max_us);
1841a24a3d6aSDedy Lansky 
1842a24a3d6aSDedy Lansky 			seq_puts(s, "\n");
1843a24a3d6aSDedy Lansky 		}
1844a24a3d6aSDedy Lansky 	}
1845a24a3d6aSDedy Lansky 
1846a24a3d6aSDedy Lansky 	return 0;
1847a24a3d6aSDedy Lansky }
1848a24a3d6aSDedy Lansky 
1849a24a3d6aSDedy Lansky static int wil_tx_latency_seq_open(struct inode *inode, struct file *file)
1850a24a3d6aSDedy Lansky {
1851a24a3d6aSDedy Lansky 	return single_open(file, wil_tx_latency_debugfs_show,
1852a24a3d6aSDedy Lansky 			   inode->i_private);
1853a24a3d6aSDedy Lansky }
1854a24a3d6aSDedy Lansky 
1855a24a3d6aSDedy Lansky static ssize_t wil_tx_latency_write(struct file *file, const char __user *buf,
1856a24a3d6aSDedy Lansky 				    size_t len, loff_t *ppos)
1857a24a3d6aSDedy Lansky {
1858a24a3d6aSDedy Lansky 	struct seq_file *s = file->private_data;
1859a24a3d6aSDedy Lansky 	struct wil6210_priv *wil = s->private;
1860a24a3d6aSDedy Lansky 	int val, rc, i;
1861a24a3d6aSDedy Lansky 	bool enable;
1862a24a3d6aSDedy Lansky 
1863a24a3d6aSDedy Lansky 	rc = kstrtoint_from_user(buf, len, 0, &val);
1864a24a3d6aSDedy Lansky 	if (rc) {
1865a24a3d6aSDedy Lansky 		wil_err(wil, "Invalid argument\n");
1866a24a3d6aSDedy Lansky 		return rc;
1867a24a3d6aSDedy Lansky 	}
1868a24a3d6aSDedy Lansky 	if (val == 1)
1869a24a3d6aSDedy Lansky 		/* default resolution */
1870a24a3d6aSDedy Lansky 		val = 500;
1871a24a3d6aSDedy Lansky 	if (val && (val < 50 || val > 1000)) {
1872a24a3d6aSDedy Lansky 		wil_err(wil, "Invalid resolution %d\n", val);
1873a24a3d6aSDedy Lansky 		return -EINVAL;
1874a24a3d6aSDedy Lansky 	}
1875a24a3d6aSDedy Lansky 
1876a24a3d6aSDedy Lansky 	enable = !!val;
1877a24a3d6aSDedy Lansky 	if (wil->tx_latency == enable)
1878a24a3d6aSDedy Lansky 		return len;
1879a24a3d6aSDedy Lansky 
1880a24a3d6aSDedy Lansky 	wil_info(wil, "%s TX latency measurements (resolution %dusec)\n",
1881a24a3d6aSDedy Lansky 		 enable ? "Enabling" : "Disabling", val);
1882a24a3d6aSDedy Lansky 
1883a24a3d6aSDedy Lansky 	if (enable) {
1884a24a3d6aSDedy Lansky 		size_t sz = sizeof(u64) * WIL_NUM_LATENCY_BINS;
1885a24a3d6aSDedy Lansky 
1886a24a3d6aSDedy Lansky 		wil->tx_latency_res = val;
1887a24a3d6aSDedy Lansky 		for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1888a24a3d6aSDedy Lansky 			struct wil_sta_info *sta = &wil->sta[i];
1889a24a3d6aSDedy Lansky 
1890a24a3d6aSDedy Lansky 			kfree(sta->tx_latency_bins);
1891a24a3d6aSDedy Lansky 			sta->tx_latency_bins = kzalloc(sz, GFP_KERNEL);
1892a24a3d6aSDedy Lansky 			if (!sta->tx_latency_bins)
1893a24a3d6aSDedy Lansky 				return -ENOMEM;
1894a24a3d6aSDedy Lansky 			sta->stats.tx_latency_min_us = U32_MAX;
1895a24a3d6aSDedy Lansky 			sta->stats.tx_latency_max_us = 0;
1896a24a3d6aSDedy Lansky 			sta->stats.tx_latency_total_us = 0;
1897a24a3d6aSDedy Lansky 		}
1898a24a3d6aSDedy Lansky 	}
1899a24a3d6aSDedy Lansky 	wil->tx_latency = enable;
1900a24a3d6aSDedy Lansky 
1901a24a3d6aSDedy Lansky 	return len;
1902a24a3d6aSDedy Lansky }
1903a24a3d6aSDedy Lansky 
1904a24a3d6aSDedy Lansky static const struct file_operations fops_tx_latency = {
1905a24a3d6aSDedy Lansky 	.open		= wil_tx_latency_seq_open,
1906a24a3d6aSDedy Lansky 	.release	= single_release,
1907a24a3d6aSDedy Lansky 	.read		= seq_read,
1908a24a3d6aSDedy Lansky 	.write		= wil_tx_latency_write,
1909a24a3d6aSDedy Lansky 	.llseek		= seq_lseek,
1910a24a3d6aSDedy Lansky };
1911a24a3d6aSDedy Lansky 
19120c936b3cSDedy Lansky static void wil_link_stats_print_basic(struct wil6210_vif *vif,
19130c936b3cSDedy Lansky 				       struct seq_file *s,
19140c936b3cSDedy Lansky 				       struct wmi_link_stats_basic *basic)
19150c936b3cSDedy Lansky {
19160c936b3cSDedy Lansky 	char per[5] = "?";
19170c936b3cSDedy Lansky 
19180c936b3cSDedy Lansky 	if (basic->per_average != 0xff)
19190c936b3cSDedy Lansky 		snprintf(per, sizeof(per), "%d%%", basic->per_average);
19200c936b3cSDedy Lansky 
19210c936b3cSDedy Lansky 	seq_printf(s, "CID %d {\n"
19220c936b3cSDedy Lansky 		   "\tTxMCS %d TxTpt %d\n"
19230c936b3cSDedy Lansky 		   "\tGoodput(rx:tx) %d:%d\n"
19240c936b3cSDedy Lansky 		   "\tRxBcastFrames %d\n"
19250c936b3cSDedy Lansky 		   "\tRSSI %d SQI %d SNR %d PER %s\n"
19260c936b3cSDedy Lansky 		   "\tRx RFC %d Ant num %d\n"
19270c936b3cSDedy Lansky 		   "\tSectors(rx:tx) my %d:%d peer %d:%d\n"
19280c936b3cSDedy Lansky 		   "}\n",
19290c936b3cSDedy Lansky 		   basic->cid,
19300c936b3cSDedy Lansky 		   basic->bf_mcs, le32_to_cpu(basic->tx_tpt),
19310c936b3cSDedy Lansky 		   le32_to_cpu(basic->rx_goodput),
19320c936b3cSDedy Lansky 		   le32_to_cpu(basic->tx_goodput),
19330c936b3cSDedy Lansky 		   le32_to_cpu(basic->rx_bcast_frames),
19340c936b3cSDedy Lansky 		   basic->rssi, basic->sqi, basic->snr, per,
19350c936b3cSDedy Lansky 		   basic->selected_rfc, basic->rx_effective_ant_num,
19360c936b3cSDedy Lansky 		   basic->my_rx_sector, basic->my_tx_sector,
19370c936b3cSDedy Lansky 		   basic->other_rx_sector, basic->other_tx_sector);
19380c936b3cSDedy Lansky }
19390c936b3cSDedy Lansky 
19400c936b3cSDedy Lansky static void wil_link_stats_print_global(struct wil6210_priv *wil,
19410c936b3cSDedy Lansky 					struct seq_file *s,
19420c936b3cSDedy Lansky 					struct wmi_link_stats_global *global)
19430c936b3cSDedy Lansky {
19440c936b3cSDedy Lansky 	seq_printf(s, "Frames(rx:tx) %d:%d\n"
19450c936b3cSDedy Lansky 		   "BA Frames(rx:tx) %d:%d\n"
19460c936b3cSDedy Lansky 		   "Beacons %d\n"
19470c936b3cSDedy Lansky 		   "Rx Errors (MIC:CRC) %d:%d\n"
19480c936b3cSDedy Lansky 		   "Tx Errors (no ack) %d\n",
19490c936b3cSDedy Lansky 		   le32_to_cpu(global->rx_frames),
19500c936b3cSDedy Lansky 		   le32_to_cpu(global->tx_frames),
19510c936b3cSDedy Lansky 		   le32_to_cpu(global->rx_ba_frames),
19520c936b3cSDedy Lansky 		   le32_to_cpu(global->tx_ba_frames),
19530c936b3cSDedy Lansky 		   le32_to_cpu(global->tx_beacons),
19540c936b3cSDedy Lansky 		   le32_to_cpu(global->rx_mic_errors),
19550c936b3cSDedy Lansky 		   le32_to_cpu(global->rx_crc_errors),
19560c936b3cSDedy Lansky 		   le32_to_cpu(global->tx_fail_no_ack));
19570c936b3cSDedy Lansky }
19580c936b3cSDedy Lansky 
19590c936b3cSDedy Lansky static void wil_link_stats_debugfs_show_vif(struct wil6210_vif *vif,
19600c936b3cSDedy Lansky 					    struct seq_file *s)
19610c936b3cSDedy Lansky {
19620c936b3cSDedy Lansky 	struct wil6210_priv *wil = vif_to_wil(vif);
19630c936b3cSDedy Lansky 	struct wmi_link_stats_basic *stats;
19640c936b3cSDedy Lansky 	int i;
19650c936b3cSDedy Lansky 
19660c936b3cSDedy Lansky 	if (!vif->fw_stats_ready) {
19670c936b3cSDedy Lansky 		seq_puts(s, "no statistics\n");
19680c936b3cSDedy Lansky 		return;
19690c936b3cSDedy Lansky 	}
19700c936b3cSDedy Lansky 
19710c936b3cSDedy Lansky 	seq_printf(s, "TSF %lld\n", vif->fw_stats_tsf);
19720c936b3cSDedy Lansky 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
19730c936b3cSDedy Lansky 		if (wil->sta[i].status == wil_sta_unused)
19740c936b3cSDedy Lansky 			continue;
19750c936b3cSDedy Lansky 		if (wil->sta[i].mid != vif->mid)
19760c936b3cSDedy Lansky 			continue;
19770c936b3cSDedy Lansky 
19780c936b3cSDedy Lansky 		stats = &wil->sta[i].fw_stats_basic;
19790c936b3cSDedy Lansky 		wil_link_stats_print_basic(vif, s, stats);
19800c936b3cSDedy Lansky 	}
19810c936b3cSDedy Lansky }
19820c936b3cSDedy Lansky 
19830c936b3cSDedy Lansky static int wil_link_stats_debugfs_show(struct seq_file *s, void *data)
19840c936b3cSDedy Lansky {
19850c936b3cSDedy Lansky 	struct wil6210_priv *wil = s->private;
19860c936b3cSDedy Lansky 	struct wil6210_vif *vif;
19870c936b3cSDedy Lansky 	int i, rc;
19880c936b3cSDedy Lansky 
19890c936b3cSDedy Lansky 	rc = mutex_lock_interruptible(&wil->vif_mutex);
19900c936b3cSDedy Lansky 	if (rc)
19910c936b3cSDedy Lansky 		return rc;
19920c936b3cSDedy Lansky 
19930c936b3cSDedy Lansky 	/* iterate over all MIDs and show per-cid statistics. Then show the
19940c936b3cSDedy Lansky 	 * global statistics
19950c936b3cSDedy Lansky 	 */
19960c936b3cSDedy Lansky 	for (i = 0; i < wil->max_vifs; i++) {
19970c936b3cSDedy Lansky 		vif = wil->vifs[i];
19980c936b3cSDedy Lansky 
19990c936b3cSDedy Lansky 		seq_printf(s, "MID %d ", i);
20000c936b3cSDedy Lansky 		if (!vif) {
20010c936b3cSDedy Lansky 			seq_puts(s, "unused\n");
20020c936b3cSDedy Lansky 			continue;
20030c936b3cSDedy Lansky 		}
20040c936b3cSDedy Lansky 
20050c936b3cSDedy Lansky 		wil_link_stats_debugfs_show_vif(vif, s);
20060c936b3cSDedy Lansky 	}
20070c936b3cSDedy Lansky 
20080c936b3cSDedy Lansky 	mutex_unlock(&wil->vif_mutex);
20090c936b3cSDedy Lansky 
20100c936b3cSDedy Lansky 	return 0;
20110c936b3cSDedy Lansky }
20120c936b3cSDedy Lansky 
20130c936b3cSDedy Lansky static int wil_link_stats_seq_open(struct inode *inode, struct file *file)
20140c936b3cSDedy Lansky {
20150c936b3cSDedy Lansky 	return single_open(file, wil_link_stats_debugfs_show, inode->i_private);
20160c936b3cSDedy Lansky }
20170c936b3cSDedy Lansky 
20180c936b3cSDedy Lansky static ssize_t wil_link_stats_write(struct file *file, const char __user *buf,
20190c936b3cSDedy Lansky 				    size_t len, loff_t *ppos)
20200c936b3cSDedy Lansky {
20210c936b3cSDedy Lansky 	struct seq_file *s = file->private_data;
20220c936b3cSDedy Lansky 	struct wil6210_priv *wil = s->private;
20230c936b3cSDedy Lansky 	int cid, interval, rc, i;
20240c936b3cSDedy Lansky 	struct wil6210_vif *vif;
20250c936b3cSDedy Lansky 	char *kbuf = kmalloc(len + 1, GFP_KERNEL);
20260c936b3cSDedy Lansky 
20270c936b3cSDedy Lansky 	if (!kbuf)
20280c936b3cSDedy Lansky 		return -ENOMEM;
20290c936b3cSDedy Lansky 
20300c936b3cSDedy Lansky 	rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
20310c936b3cSDedy Lansky 	if (rc != len) {
20320c936b3cSDedy Lansky 		kfree(kbuf);
20330c936b3cSDedy Lansky 		return rc >= 0 ? -EIO : rc;
20340c936b3cSDedy Lansky 	}
20350c936b3cSDedy Lansky 
20360c936b3cSDedy Lansky 	kbuf[len] = '\0';
20370c936b3cSDedy Lansky 	/* specify cid (use -1 for all cids) and snapshot interval in ms */
20380c936b3cSDedy Lansky 	rc = sscanf(kbuf, "%d %d", &cid, &interval);
20390c936b3cSDedy Lansky 	kfree(kbuf);
20400c936b3cSDedy Lansky 	if (rc < 0)
20410c936b3cSDedy Lansky 		return rc;
20420c936b3cSDedy Lansky 	if (rc < 2 || interval < 0)
20430c936b3cSDedy Lansky 		return -EINVAL;
20440c936b3cSDedy Lansky 
20450c936b3cSDedy Lansky 	wil_info(wil, "request link statistics, cid %d interval %d\n",
20460c936b3cSDedy Lansky 		 cid, interval);
20470c936b3cSDedy Lansky 
20480c936b3cSDedy Lansky 	rc = mutex_lock_interruptible(&wil->vif_mutex);
20490c936b3cSDedy Lansky 	if (rc)
20500c936b3cSDedy Lansky 		return rc;
20510c936b3cSDedy Lansky 
20520c936b3cSDedy Lansky 	for (i = 0; i < wil->max_vifs; i++) {
20530c936b3cSDedy Lansky 		vif = wil->vifs[i];
20540c936b3cSDedy Lansky 		if (!vif)
20550c936b3cSDedy Lansky 			continue;
20560c936b3cSDedy Lansky 
20570c936b3cSDedy Lansky 		rc = wmi_link_stats_cfg(vif, WMI_LINK_STATS_TYPE_BASIC,
20580c936b3cSDedy Lansky 					(cid == -1 ? 0xff : cid), interval);
20590c936b3cSDedy Lansky 		if (rc)
20600c936b3cSDedy Lansky 			wil_err(wil, "link statistics failed for mid %d\n", i);
20610c936b3cSDedy Lansky 	}
20620c936b3cSDedy Lansky 	mutex_unlock(&wil->vif_mutex);
20630c936b3cSDedy Lansky 
20640c936b3cSDedy Lansky 	return len;
20650c936b3cSDedy Lansky }
20660c936b3cSDedy Lansky 
20670c936b3cSDedy Lansky static const struct file_operations fops_link_stats = {
20680c936b3cSDedy Lansky 	.open		= wil_link_stats_seq_open,
20690c936b3cSDedy Lansky 	.release	= single_release,
20700c936b3cSDedy Lansky 	.read		= seq_read,
20710c936b3cSDedy Lansky 	.write		= wil_link_stats_write,
20720c936b3cSDedy Lansky 	.llseek		= seq_lseek,
20730c936b3cSDedy Lansky };
20740c936b3cSDedy Lansky 
20750c936b3cSDedy Lansky static int
20760c936b3cSDedy Lansky wil_link_stats_global_debugfs_show(struct seq_file *s, void *data)
20770c936b3cSDedy Lansky {
20780c936b3cSDedy Lansky 	struct wil6210_priv *wil = s->private;
20790c936b3cSDedy Lansky 
20800c936b3cSDedy Lansky 	if (!wil->fw_stats_global.ready)
20810c936b3cSDedy Lansky 		return 0;
20820c936b3cSDedy Lansky 
20830c936b3cSDedy Lansky 	seq_printf(s, "TSF %lld\n", wil->fw_stats_global.tsf);
20840c936b3cSDedy Lansky 	wil_link_stats_print_global(wil, s, &wil->fw_stats_global.stats);
20850c936b3cSDedy Lansky 
20860c936b3cSDedy Lansky 	return 0;
20870c936b3cSDedy Lansky }
20880c936b3cSDedy Lansky 
20890c936b3cSDedy Lansky static int
20900c936b3cSDedy Lansky wil_link_stats_global_seq_open(struct inode *inode, struct file *file)
20910c936b3cSDedy Lansky {
20920c936b3cSDedy Lansky 	return single_open(file, wil_link_stats_global_debugfs_show,
20930c936b3cSDedy Lansky 			   inode->i_private);
20940c936b3cSDedy Lansky }
20950c936b3cSDedy Lansky 
20960c936b3cSDedy Lansky static ssize_t
20970c936b3cSDedy Lansky wil_link_stats_global_write(struct file *file, const char __user *buf,
20980c936b3cSDedy Lansky 			    size_t len, loff_t *ppos)
20990c936b3cSDedy Lansky {
21000c936b3cSDedy Lansky 	struct seq_file *s = file->private_data;
21010c936b3cSDedy Lansky 	struct wil6210_priv *wil = s->private;
21020c936b3cSDedy Lansky 	int interval, rc;
21030c936b3cSDedy Lansky 	struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
21040c936b3cSDedy Lansky 
21050c936b3cSDedy Lansky 	/* specify snapshot interval in ms */
21060c936b3cSDedy Lansky 	rc = kstrtoint_from_user(buf, len, 0, &interval);
21070c936b3cSDedy Lansky 	if (rc || interval < 0) {
21080c936b3cSDedy Lansky 		wil_err(wil, "Invalid argument\n");
21090c936b3cSDedy Lansky 		return -EINVAL;
21100c936b3cSDedy Lansky 	}
21110c936b3cSDedy Lansky 
21120c936b3cSDedy Lansky 	wil_info(wil, "request global link stats, interval %d\n", interval);
21130c936b3cSDedy Lansky 
21140c936b3cSDedy Lansky 	rc = wmi_link_stats_cfg(vif, WMI_LINK_STATS_TYPE_GLOBAL, 0, interval);
21150c936b3cSDedy Lansky 	if (rc)
21160c936b3cSDedy Lansky 		wil_err(wil, "global link stats failed %d\n", rc);
21170c936b3cSDedy Lansky 
21180c936b3cSDedy Lansky 	return rc ? rc : len;
21190c936b3cSDedy Lansky }
21200c936b3cSDedy Lansky 
21210c936b3cSDedy Lansky static const struct file_operations fops_link_stats_global = {
21220c936b3cSDedy Lansky 	.open		= wil_link_stats_global_seq_open,
21230c936b3cSDedy Lansky 	.release	= single_release,
21240c936b3cSDedy Lansky 	.read		= seq_read,
21250c936b3cSDedy Lansky 	.write		= wil_link_stats_global_write,
21260c936b3cSDedy Lansky 	.llseek		= seq_lseek,
21270c936b3cSDedy Lansky };
21280c936b3cSDedy Lansky 
212910d599adSMaya Erez static ssize_t wil_read_file_led_cfg(struct file *file, char __user *user_buf,
213010d599adSMaya Erez 				     size_t count, loff_t *ppos)
213110d599adSMaya Erez {
213210d599adSMaya Erez 	char buf[80];
213310d599adSMaya Erez 	int n;
213410d599adSMaya Erez 
213510d599adSMaya Erez 	n = snprintf(buf, sizeof(buf),
213610d599adSMaya Erez 		     "led_id is set to %d, echo 1 to enable, 0 to disable\n",
213710d599adSMaya Erez 		     led_id);
213810d599adSMaya Erez 
213910d599adSMaya Erez 	n = min_t(int, n, sizeof(buf));
214010d599adSMaya Erez 
214110d599adSMaya Erez 	return simple_read_from_buffer(user_buf, count, ppos,
214210d599adSMaya Erez 				       buf, n);
214310d599adSMaya Erez }
214410d599adSMaya Erez 
214510d599adSMaya Erez static ssize_t wil_write_file_led_cfg(struct file *file,
214610d599adSMaya Erez 				      const char __user *buf_,
214710d599adSMaya Erez 				      size_t count, loff_t *ppos)
214810d599adSMaya Erez {
214910d599adSMaya Erez 	struct wil6210_priv *wil = file->private_data;
215010d599adSMaya Erez 	int val;
215110d599adSMaya Erez 	int rc;
215210d599adSMaya Erez 
215310d599adSMaya Erez 	rc = kstrtoint_from_user(buf_, count, 0, &val);
215410d599adSMaya Erez 	if (rc) {
215510d599adSMaya Erez 		wil_err(wil, "Invalid argument\n");
215610d599adSMaya Erez 		return rc;
215710d599adSMaya Erez 	}
215810d599adSMaya Erez 
215910d599adSMaya Erez 	wil_info(wil, "%s led %d\n", val ? "Enabling" : "Disabling", led_id);
216010d599adSMaya Erez 	rc = wmi_led_cfg(wil, val);
216110d599adSMaya Erez 	if (rc) {
216210d599adSMaya Erez 		wil_info(wil, "%s led %d failed\n",
216310d599adSMaya Erez 			 val ? "Enabling" : "Disabling", led_id);
216410d599adSMaya Erez 		return rc;
216510d599adSMaya Erez 	}
216610d599adSMaya Erez 
216710d599adSMaya Erez 	return count;
216810d599adSMaya Erez }
216910d599adSMaya Erez 
217010d599adSMaya Erez static const struct file_operations fops_led_cfg = {
217110d599adSMaya Erez 	.read = wil_read_file_led_cfg,
217210d599adSMaya Erez 	.write = wil_write_file_led_cfg,
217310d599adSMaya Erez 	.open  = simple_open,
217410d599adSMaya Erez };
217510d599adSMaya Erez 
217610d599adSMaya Erez /* led_blink_time, write:
217710d599adSMaya Erez  * "<blink_on_slow> <blink_off_slow> <blink_on_med> <blink_off_med> <blink_on_fast> <blink_off_fast>
217810d599adSMaya Erez  */
217910d599adSMaya Erez static ssize_t wil_write_led_blink_time(struct file *file,
218010d599adSMaya Erez 					const char __user *buf,
218110d599adSMaya Erez 					size_t len, loff_t *ppos)
218210d599adSMaya Erez {
218310d599adSMaya Erez 	int rc;
218410d599adSMaya Erez 	char *kbuf = kmalloc(len + 1, GFP_KERNEL);
218510d599adSMaya Erez 
218610d599adSMaya Erez 	if (!kbuf)
218710d599adSMaya Erez 		return -ENOMEM;
218810d599adSMaya Erez 
218910d599adSMaya Erez 	rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
219010d599adSMaya Erez 	if (rc != len) {
219110d599adSMaya Erez 		kfree(kbuf);
219210d599adSMaya Erez 		return rc >= 0 ? -EIO : rc;
219310d599adSMaya Erez 	}
219410d599adSMaya Erez 
219510d599adSMaya Erez 	kbuf[len] = '\0';
219610d599adSMaya Erez 	rc = sscanf(kbuf, "%d %d %d %d %d %d",
219710d599adSMaya Erez 		    &led_blink_time[WIL_LED_TIME_SLOW].on_ms,
219810d599adSMaya Erez 		    &led_blink_time[WIL_LED_TIME_SLOW].off_ms,
219910d599adSMaya Erez 		    &led_blink_time[WIL_LED_TIME_MED].on_ms,
220010d599adSMaya Erez 		    &led_blink_time[WIL_LED_TIME_MED].off_ms,
220110d599adSMaya Erez 		    &led_blink_time[WIL_LED_TIME_FAST].on_ms,
220210d599adSMaya Erez 		    &led_blink_time[WIL_LED_TIME_FAST].off_ms);
220310d599adSMaya Erez 	kfree(kbuf);
220410d599adSMaya Erez 
220510d599adSMaya Erez 	if (rc < 0)
220610d599adSMaya Erez 		return rc;
220710d599adSMaya Erez 	if (rc < 6)
220810d599adSMaya Erez 		return -EINVAL;
220910d599adSMaya Erez 
221010d599adSMaya Erez 	return len;
221110d599adSMaya Erez }
221210d599adSMaya Erez 
221310d599adSMaya Erez static ssize_t wil_read_led_blink_time(struct file *file, char __user *user_buf,
221410d599adSMaya Erez 				       size_t count, loff_t *ppos)
221510d599adSMaya Erez {
221610d599adSMaya Erez 	static char text[400];
221710d599adSMaya Erez 
221810d599adSMaya Erez 	snprintf(text, sizeof(text),
221910d599adSMaya Erez 		 "To set led blink on/off time variables write:\n"
222010d599adSMaya Erez 		 "<blink_on_slow> <blink_off_slow> <blink_on_med> "
222110d599adSMaya Erez 		 "<blink_off_med> <blink_on_fast> <blink_off_fast>\n"
222210d599adSMaya Erez 		 "The current values are:\n"
222310d599adSMaya Erez 		 "%d %d %d %d %d %d\n",
222410d599adSMaya Erez 		 led_blink_time[WIL_LED_TIME_SLOW].on_ms,
222510d599adSMaya Erez 		 led_blink_time[WIL_LED_TIME_SLOW].off_ms,
222610d599adSMaya Erez 		 led_blink_time[WIL_LED_TIME_MED].on_ms,
222710d599adSMaya Erez 		 led_blink_time[WIL_LED_TIME_MED].off_ms,
222810d599adSMaya Erez 		 led_blink_time[WIL_LED_TIME_FAST].on_ms,
222910d599adSMaya Erez 		 led_blink_time[WIL_LED_TIME_FAST].off_ms);
223010d599adSMaya Erez 
223110d599adSMaya Erez 	return simple_read_from_buffer(user_buf, count, ppos, text,
223210d599adSMaya Erez 				       sizeof(text));
223310d599adSMaya Erez }
223410d599adSMaya Erez 
223510d599adSMaya Erez static const struct file_operations fops_led_blink_time = {
223610d599adSMaya Erez 	.read = wil_read_led_blink_time,
223710d599adSMaya Erez 	.write = wil_write_led_blink_time,
223810d599adSMaya Erez 	.open  = simple_open,
223910d599adSMaya Erez };
224010d599adSMaya Erez 
224112bace75SLior David /*---------FW capabilities------------*/
224212bace75SLior David static int wil_fw_capabilities_debugfs_show(struct seq_file *s, void *data)
224312bace75SLior David {
224412bace75SLior David 	struct wil6210_priv *wil = s->private;
224512bace75SLior David 
224612bace75SLior David 	seq_printf(s, "fw_capabilities : %*pb\n", WMI_FW_CAPABILITY_MAX,
224712bace75SLior David 		   wil->fw_capabilities);
224812bace75SLior David 
224912bace75SLior David 	return 0;
225012bace75SLior David }
225112bace75SLior David 
225212bace75SLior David static int wil_fw_capabilities_seq_open(struct inode *inode, struct file *file)
225312bace75SLior David {
225412bace75SLior David 	return single_open(file, wil_fw_capabilities_debugfs_show,
225512bace75SLior David 			   inode->i_private);
225612bace75SLior David }
225712bace75SLior David 
225812bace75SLior David static const struct file_operations fops_fw_capabilities = {
225912bace75SLior David 	.open		= wil_fw_capabilities_seq_open,
226012bace75SLior David 	.release	= single_release,
226112bace75SLior David 	.read		= seq_read,
226212bace75SLior David 	.llseek		= seq_lseek,
226312bace75SLior David };
226412bace75SLior David 
226513cd9f75SLior David /*---------FW version------------*/
226613cd9f75SLior David static int wil_fw_version_debugfs_show(struct seq_file *s, void *data)
226713cd9f75SLior David {
226813cd9f75SLior David 	struct wil6210_priv *wil = s->private;
226913cd9f75SLior David 
227013cd9f75SLior David 	if (wil->fw_version[0])
227113cd9f75SLior David 		seq_printf(s, "%s\n", wil->fw_version);
227213cd9f75SLior David 	else
227313cd9f75SLior David 		seq_puts(s, "N/A\n");
227413cd9f75SLior David 
227513cd9f75SLior David 	return 0;
227613cd9f75SLior David }
227713cd9f75SLior David 
227813cd9f75SLior David static int wil_fw_version_seq_open(struct inode *inode, struct file *file)
227913cd9f75SLior David {
228013cd9f75SLior David 	return single_open(file, wil_fw_version_debugfs_show,
228113cd9f75SLior David 			   inode->i_private);
228213cd9f75SLior David }
228313cd9f75SLior David 
228413cd9f75SLior David static const struct file_operations fops_fw_version = {
228513cd9f75SLior David 	.open		= wil_fw_version_seq_open,
228613cd9f75SLior David 	.release	= single_release,
228713cd9f75SLior David 	.read		= seq_read,
228813cd9f75SLior David 	.llseek		= seq_lseek,
228913cd9f75SLior David };
229013cd9f75SLior David 
2291fe9ee51eSMaya Erez /*---------suspend_stats---------*/
2292fe9ee51eSMaya Erez static ssize_t wil_write_suspend_stats(struct file *file,
2293fe9ee51eSMaya Erez 				       const char __user *buf,
2294fe9ee51eSMaya Erez 				       size_t len, loff_t *ppos)
2295fe9ee51eSMaya Erez {
2296fe9ee51eSMaya Erez 	struct wil6210_priv *wil = file->private_data;
2297fe9ee51eSMaya Erez 
2298fe9ee51eSMaya Erez 	memset(&wil->suspend_stats, 0, sizeof(wil->suspend_stats));
2299fe9ee51eSMaya Erez 
2300fe9ee51eSMaya Erez 	return len;
2301fe9ee51eSMaya Erez }
2302fe9ee51eSMaya Erez 
2303fe9ee51eSMaya Erez static ssize_t wil_read_suspend_stats(struct file *file,
2304fe9ee51eSMaya Erez 				      char __user *user_buf,
2305fe9ee51eSMaya Erez 				      size_t count, loff_t *ppos)
2306fe9ee51eSMaya Erez {
2307fe9ee51eSMaya Erez 	struct wil6210_priv *wil = file->private_data;
2308bd8bdc6cSLazar Alexei 	char *text;
2309bd8bdc6cSLazar Alexei 	int n, ret, text_size = 500;
2310fe9ee51eSMaya Erez 
2311bd8bdc6cSLazar Alexei 	text = kmalloc(text_size, GFP_KERNEL);
2312bd8bdc6cSLazar Alexei 	if (!text)
2313bd8bdc6cSLazar Alexei 		return -ENOMEM;
2314bd8bdc6cSLazar Alexei 
2315bd8bdc6cSLazar Alexei 	n = snprintf(text, text_size,
2316bd8bdc6cSLazar Alexei 		     "Radio on suspend statistics:\n"
2317fe9ee51eSMaya Erez 		     "successful suspends:%ld failed suspends:%ld\n"
2318fe9ee51eSMaya Erez 		     "successful resumes:%ld failed resumes:%ld\n"
2319bd8bdc6cSLazar Alexei 		     "rejected by device:%ld\n"
2320bd8bdc6cSLazar Alexei 		     "Radio off suspend statistics:\n"
2321bd8bdc6cSLazar Alexei 		     "successful suspends:%ld failed suspends:%ld\n"
2322bd8bdc6cSLazar Alexei 		     "successful resumes:%ld failed resumes:%ld\n"
2323bd8bdc6cSLazar Alexei 		     "General statistics:\n"
2324bd8bdc6cSLazar Alexei 		     "rejected by host:%ld\n",
2325bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_on.successful_suspends,
2326bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_on.failed_suspends,
2327bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_on.successful_resumes,
2328bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_on.failed_resumes,
2329bd8bdc6cSLazar Alexei 		     wil->suspend_stats.rejected_by_device,
2330bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_off.successful_suspends,
2331bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_off.failed_suspends,
2332bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_off.successful_resumes,
2333bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_off.failed_resumes,
2334bd8bdc6cSLazar Alexei 		     wil->suspend_stats.rejected_by_host);
2335fe9ee51eSMaya Erez 
2336bd8bdc6cSLazar Alexei 	n = min_t(int, n, text_size);
2337fe9ee51eSMaya Erez 
2338bd8bdc6cSLazar Alexei 	ret = simple_read_from_buffer(user_buf, count, ppos, text, n);
2339bd8bdc6cSLazar Alexei 
2340bd8bdc6cSLazar Alexei 	kfree(text);
2341bd8bdc6cSLazar Alexei 
2342bd8bdc6cSLazar Alexei 	return ret;
2343fe9ee51eSMaya Erez }
2344fe9ee51eSMaya Erez 
2345fe9ee51eSMaya Erez static const struct file_operations fops_suspend_stats = {
2346fe9ee51eSMaya Erez 	.read = wil_read_suspend_stats,
2347fe9ee51eSMaya Erez 	.write = wil_write_suspend_stats,
2348fe9ee51eSMaya Erez 	.open  = simple_open,
2349fe9ee51eSMaya Erez };
2350fe9ee51eSMaya Erez 
235196c93589SGidon Studinski /*---------compressed_rx_status---------*/
235296c93589SGidon Studinski static ssize_t wil_compressed_rx_status_write(struct file *file,
235396c93589SGidon Studinski 					      const char __user *buf,
235496c93589SGidon Studinski 					      size_t len, loff_t *ppos)
235596c93589SGidon Studinski {
235696c93589SGidon Studinski 	struct seq_file *s = file->private_data;
235796c93589SGidon Studinski 	struct wil6210_priv *wil = s->private;
235896c93589SGidon Studinski 	int compressed_rx_status;
235996c93589SGidon Studinski 	int rc;
236096c93589SGidon Studinski 
236196c93589SGidon Studinski 	rc = kstrtoint_from_user(buf, len, 0, &compressed_rx_status);
236296c93589SGidon Studinski 	if (rc) {
236396c93589SGidon Studinski 		wil_err(wil, "Invalid argument\n");
236496c93589SGidon Studinski 		return rc;
236596c93589SGidon Studinski 	}
236696c93589SGidon Studinski 
236796c93589SGidon Studinski 	if (wil_has_active_ifaces(wil, true, false)) {
236896c93589SGidon Studinski 		wil_err(wil, "cannot change edma config after iface is up\n");
236996c93589SGidon Studinski 		return -EPERM;
237096c93589SGidon Studinski 	}
237196c93589SGidon Studinski 
237296c93589SGidon Studinski 	wil_info(wil, "%sable compressed_rx_status\n",
237396c93589SGidon Studinski 		 compressed_rx_status ? "En" : "Dis");
237496c93589SGidon Studinski 
237596c93589SGidon Studinski 	wil->use_compressed_rx_status = compressed_rx_status;
237696c93589SGidon Studinski 
237796c93589SGidon Studinski 	return len;
237896c93589SGidon Studinski }
237996c93589SGidon Studinski 
238096c93589SGidon Studinski static int
238196c93589SGidon Studinski wil_compressed_rx_status_show(struct seq_file *s, void *data)
238296c93589SGidon Studinski {
238396c93589SGidon Studinski 	struct wil6210_priv *wil = s->private;
238496c93589SGidon Studinski 
238596c93589SGidon Studinski 	seq_printf(s, "%d\n", wil->use_compressed_rx_status);
238696c93589SGidon Studinski 
238796c93589SGidon Studinski 	return 0;
238896c93589SGidon Studinski }
238996c93589SGidon Studinski 
239096c93589SGidon Studinski static int
239196c93589SGidon Studinski wil_compressed_rx_status_seq_open(struct inode *inode, struct file *file)
239296c93589SGidon Studinski {
239396c93589SGidon Studinski 	return single_open(file, wil_compressed_rx_status_show,
239496c93589SGidon Studinski 			   inode->i_private);
239596c93589SGidon Studinski }
239696c93589SGidon Studinski 
239796c93589SGidon Studinski static const struct file_operations fops_compressed_rx_status = {
239896c93589SGidon Studinski 	.open  = wil_compressed_rx_status_seq_open,
239996c93589SGidon Studinski 	.release = single_release,
240096c93589SGidon Studinski 	.read = seq_read,
240196c93589SGidon Studinski 	.write = wil_compressed_rx_status_write,
240296c93589SGidon Studinski 	.llseek	= seq_lseek,
240396c93589SGidon Studinski };
240496c93589SGidon Studinski 
24052be7d22fSVladimir Kondratiev /*----------------*/
2406b541d0a0SVladimir Kondratiev static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
2407b541d0a0SVladimir Kondratiev 				       struct dentry *dbg)
2408b541d0a0SVladimir Kondratiev {
2409b541d0a0SVladimir Kondratiev 	int i;
2410b541d0a0SVladimir Kondratiev 	char name[32];
2411b541d0a0SVladimir Kondratiev 
2412b541d0a0SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
2413349214c1SMaya Erez 		struct wil_blob_wrapper *wil_blob = &wil->blobs[i];
2414349214c1SMaya Erez 		struct debugfs_blob_wrapper *blob = &wil_blob->blob;
2415b541d0a0SVladimir Kondratiev 		const struct fw_map *map = &fw_mapping[i];
2416b541d0a0SVladimir Kondratiev 
2417b541d0a0SVladimir Kondratiev 		if (!map->name)
2418b541d0a0SVladimir Kondratiev 			continue;
2419b541d0a0SVladimir Kondratiev 
2420349214c1SMaya Erez 		wil_blob->wil = wil;
2421b541d0a0SVladimir Kondratiev 		blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
2422b541d0a0SVladimir Kondratiev 		blob->size = map->to - map->from;
2423b541d0a0SVladimir Kondratiev 		snprintf(name, sizeof(name), "blob_%s", map->name);
242478484c44SMaya Erez 		wil_debugfs_create_ioblob(name, 0444, dbg, wil_blob);
2425b541d0a0SVladimir Kondratiev 	}
2426b541d0a0SVladimir Kondratiev }
2427b541d0a0SVladimir Kondratiev 
2428b7cde470SVladimir Kondratiev /* misc files */
2429b7cde470SVladimir Kondratiev static const struct {
2430b7cde470SVladimir Kondratiev 	const char *name;
2431b7cde470SVladimir Kondratiev 	umode_t mode;
2432b7cde470SVladimir Kondratiev 	const struct file_operations *fops;
2433b7cde470SVladimir Kondratiev } dbg_files[] = {
243478484c44SMaya Erez 	{"mbox",	0444,		&fops_mbox},
243510590c6aSGidon Studinski 	{"rings",	0444,		&fops_ring},
243678484c44SMaya Erez 	{"stations", 0444,		&fops_sta},
24373a3b745fSLior David 	{"mids",	0444,		&fops_mids},
243878484c44SMaya Erez 	{"desc",	0444,		&fops_txdesc},
243978484c44SMaya Erez 	{"bf",		0444,		&fops_bf},
244078484c44SMaya Erez 	{"mem_val",	0644,		&fops_memread},
244178484c44SMaya Erez 	{"rxon",	0244,		&fops_rxon},
244278484c44SMaya Erez 	{"tx_mgmt",	0244,		&fops_txmgmt},
244378484c44SMaya Erez 	{"wmi_send", 0244,		&fops_wmi},
244478484c44SMaya Erez 	{"back",	0644,		&fops_back},
244578484c44SMaya Erez 	{"pmccfg",	0644,		&fops_pmccfg},
244678484c44SMaya Erez 	{"pmcdata",	0444,		&fops_pmcdata},
244778484c44SMaya Erez 	{"temp",	0444,		&fops_temp},
244878484c44SMaya Erez 	{"freq",	0444,		&fops_freq},
244978484c44SMaya Erez 	{"link",	0444,		&fops_link},
245078484c44SMaya Erez 	{"info",	0444,		&fops_info},
245178484c44SMaya Erez 	{"recovery", 0644,		&fops_recovery},
245278484c44SMaya Erez 	{"led_cfg",	0644,		&fops_led_cfg},
245378484c44SMaya Erez 	{"led_blink_time",	0644,	&fops_led_blink_time},
245478484c44SMaya Erez 	{"fw_capabilities",	0444,	&fops_fw_capabilities},
245578484c44SMaya Erez 	{"fw_version",	0444,		&fops_fw_version},
2456fe9ee51eSMaya Erez 	{"suspend_stats",	0644,	&fops_suspend_stats},
245796c93589SGidon Studinski 	{"compressed_rx_status", 0644,	&fops_compressed_rx_status},
2458d98b8539SMaya Erez 	{"srings",	0444,		&fops_srings},
2459d98b8539SMaya Erez 	{"status_msg",	0444,		&fops_status_msg},
2460d98b8539SMaya Erez 	{"rx_buff_mgmt",	0444,	&fops_rx_buff_mgmt},
2461a24a3d6aSDedy Lansky 	{"tx_latency",	0644,		&fops_tx_latency},
24620c936b3cSDedy Lansky 	{"link_stats",	0644,		&fops_link_stats},
24630c936b3cSDedy Lansky 	{"link_stats_global",	0644,	&fops_link_stats_global},
2464b7cde470SVladimir Kondratiev };
2465b7cde470SVladimir Kondratiev 
2466b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
2467b7cde470SVladimir Kondratiev 				       struct dentry *dbg)
2468b7cde470SVladimir Kondratiev {
2469b7cde470SVladimir Kondratiev 	int i;
2470b7cde470SVladimir Kondratiev 
2471b7cde470SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
2472b7cde470SVladimir Kondratiev 		debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
2473b7cde470SVladimir Kondratiev 				    wil, dbg_files[i].fops);
2474b7cde470SVladimir Kondratiev }
2475b7cde470SVladimir Kondratiev 
2476b7cde470SVladimir Kondratiev /* interrupt control blocks */
2477b7cde470SVladimir Kondratiev static const struct {
2478b7cde470SVladimir Kondratiev 	const char *name;
2479b7cde470SVladimir Kondratiev 	u32 icr_off;
2480b7cde470SVladimir Kondratiev } dbg_icr[] = {
2481b7cde470SVladimir Kondratiev 	{"USER_ICR",		HOSTADDR(RGF_USER_USER_ICR)},
2482b7cde470SVladimir Kondratiev 	{"DMA_EP_TX_ICR",	HOSTADDR(RGF_DMA_EP_TX_ICR)},
2483b7cde470SVladimir Kondratiev 	{"DMA_EP_RX_ICR",	HOSTADDR(RGF_DMA_EP_RX_ICR)},
2484b7cde470SVladimir Kondratiev 	{"DMA_EP_MISC_ICR",	HOSTADDR(RGF_DMA_EP_MISC_ICR)},
2485b7cde470SVladimir Kondratiev };
2486b7cde470SVladimir Kondratiev 
2487b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
2488b7cde470SVladimir Kondratiev 				     struct dentry *dbg)
2489b7cde470SVladimir Kondratiev {
2490b7cde470SVladimir Kondratiev 	int i;
2491b7cde470SVladimir Kondratiev 
2492b7cde470SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
2493b7cde470SVladimir Kondratiev 		wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
2494b7cde470SVladimir Kondratiev 					   dbg_icr[i].icr_off);
2495b7cde470SVladimir Kondratiev }
2496b7cde470SVladimir Kondratiev 
2497b7cde470SVladimir Kondratiev #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
2498b7cde470SVladimir Kondratiev 	offsetof(struct wil6210_priv, name), type}
2499b7cde470SVladimir Kondratiev 
2500b7cde470SVladimir Kondratiev /* fields in struct wil6210_priv */
2501b7cde470SVladimir Kondratiev static const struct dbg_off dbg_wil_off[] = {
250278484c44SMaya Erez 	WIL_FIELD(status[0],	0644,	doff_ulong),
250378484c44SMaya Erez 	WIL_FIELD(hw_version,	0444,	doff_x32),
250478484c44SMaya Erez 	WIL_FIELD(recovery_count, 0444,	doff_u32),
250578484c44SMaya Erez 	WIL_FIELD(discovery_mode, 0644,	doff_u8),
250678484c44SMaya Erez 	WIL_FIELD(chip_revision, 0444,	doff_u8),
250778484c44SMaya Erez 	WIL_FIELD(abft_len, 0644,		doff_u8),
2508fe9ee51eSMaya Erez 	WIL_FIELD(wakeup_trigger, 0644,		doff_u8),
250910590c6aSGidon Studinski 	WIL_FIELD(ring_idle_trsh, 0644,	doff_u32),
251096c93589SGidon Studinski 	WIL_FIELD(num_rx_status_rings, 0644,	doff_u8),
251196c93589SGidon Studinski 	WIL_FIELD(rx_status_ring_order, 0644,	doff_u32),
251296c93589SGidon Studinski 	WIL_FIELD(tx_status_ring_order, 0644,	doff_u32),
251396c93589SGidon Studinski 	WIL_FIELD(rx_buff_id_count, 0644,	doff_u32),
25147be13fc3SGidon Studinski 	WIL_FIELD(amsdu_en, 0644,	doff_u8),
2515b7cde470SVladimir Kondratiev 	{},
2516b7cde470SVladimir Kondratiev };
2517b7cde470SVladimir Kondratiev 
2518b7cde470SVladimir Kondratiev static const struct dbg_off dbg_wil_regs[] = {
251978484c44SMaya Erez 	{"RGF_MAC_MTRL_COUNTER_0", 0444, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
2520b7cde470SVladimir Kondratiev 		doff_io32},
252178484c44SMaya Erez 	{"RGF_USER_USAGE_1", 0444, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
2522b7cde470SVladimir Kondratiev 	{},
2523b7cde470SVladimir Kondratiev };
2524b7cde470SVladimir Kondratiev 
2525b7cde470SVladimir Kondratiev /* static parameters */
2526b7cde470SVladimir Kondratiev static const struct dbg_off dbg_statics[] = {
252778484c44SMaya Erez 	{"desc_index",	0644, (ulong)&dbg_txdesc_index, doff_u32},
252810590c6aSGidon Studinski 	{"ring_index",	0644, (ulong)&dbg_ring_index, doff_u32},
252978484c44SMaya Erez 	{"mem_addr",	0644, (ulong)&mem_addr, doff_u32},
253078484c44SMaya Erez 	{"led_polarity", 0644, (ulong)&led_polarity, doff_u8},
2531d98b8539SMaya Erez 	{"status_index", 0644, (ulong)&dbg_status_msg_index, doff_u32},
2532d98b8539SMaya Erez 	{"sring_index",	0644, (ulong)&dbg_sring_index, doff_u32},
2533b7cde470SVladimir Kondratiev 	{},
2534b7cde470SVladimir Kondratiev };
2535b7cde470SVladimir Kondratiev 
253694162666SLazar Alexei static const int dbg_off_count = 4 * (ARRAY_SIZE(isr_off) - 1) +
253794162666SLazar Alexei 				ARRAY_SIZE(dbg_wil_regs) - 1 +
253894162666SLazar Alexei 				ARRAY_SIZE(pseudo_isr_off) - 1 +
253994162666SLazar Alexei 				ARRAY_SIZE(lgc_itr_cnt_off) - 1 +
254094162666SLazar Alexei 				ARRAY_SIZE(tx_itr_cnt_off) - 1 +
254194162666SLazar Alexei 				ARRAY_SIZE(rx_itr_cnt_off) - 1;
254294162666SLazar Alexei 
25432be7d22fSVladimir Kondratiev int wil6210_debugfs_init(struct wil6210_priv *wil)
25442be7d22fSVladimir Kondratiev {
25452be7d22fSVladimir Kondratiev 	struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
25462be7d22fSVladimir Kondratiev 			wil_to_wiphy(wil)->debugfsdir);
25472be7d22fSVladimir Kondratiev 	if (IS_ERR_OR_NULL(dbg))
25482be7d22fSVladimir Kondratiev 		return -ENODEV;
25492be7d22fSVladimir Kondratiev 
255094162666SLazar Alexei 	wil->dbg_data.data_arr = kcalloc(dbg_off_count,
255194162666SLazar Alexei 					 sizeof(struct wil_debugfs_iomem_data),
255294162666SLazar Alexei 					 GFP_KERNEL);
255394162666SLazar Alexei 	if (!wil->dbg_data.data_arr) {
255494162666SLazar Alexei 		debugfs_remove_recursive(dbg);
255594162666SLazar Alexei 		wil->debug = NULL;
255694162666SLazar Alexei 		return -ENOMEM;
255794162666SLazar Alexei 	}
255894162666SLazar Alexei 
255994162666SLazar Alexei 	wil->dbg_data.iomem_data_count = 0;
256094162666SLazar Alexei 
2561dc16427bSVladimir Kondratiev 	wil_pmc_init(wil);
2562dc16427bSVladimir Kondratiev 
2563b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_files(wil, dbg);
2564b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_isr(wil, dbg);
2565b541d0a0SVladimir Kondratiev 	wil6210_debugfs_init_blobs(wil, dbg);
2566b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
2567b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
2568b7cde470SVladimir Kondratiev 				    dbg_wil_regs);
2569b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
2570b7cde470SVladimir Kondratiev 
2571b7cde470SVladimir Kondratiev 	wil6210_debugfs_create_pseudo_ISR(wil, dbg);
2572b7cde470SVladimir Kondratiev 
2573b7cde470SVladimir Kondratiev 	wil6210_debugfs_create_ITR_CNT(wil, dbg);
25742be7d22fSVladimir Kondratiev 
25752be7d22fSVladimir Kondratiev 	return 0;
25762be7d22fSVladimir Kondratiev }
25772be7d22fSVladimir Kondratiev 
25782be7d22fSVladimir Kondratiev void wil6210_debugfs_remove(struct wil6210_priv *wil)
25792be7d22fSVladimir Kondratiev {
2580a24a3d6aSDedy Lansky 	int i;
2581a24a3d6aSDedy Lansky 
25822be7d22fSVladimir Kondratiev 	debugfs_remove_recursive(wil->debug);
25832be7d22fSVladimir Kondratiev 	wil->debug = NULL;
2584dc16427bSVladimir Kondratiev 
258594162666SLazar Alexei 	kfree(wil->dbg_data.data_arr);
2586a24a3d6aSDedy Lansky 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++)
2587a24a3d6aSDedy Lansky 		kfree(wil->sta[i].tx_latency_bins);
258894162666SLazar Alexei 
2589dc16427bSVladimir Kondratiev 	/* free pmc memory without sending command to fw, as it will
2590dc16427bSVladimir Kondratiev 	 * be reset on the way down anyway
2591dc16427bSVladimir Kondratiev 	 */
2592dc16427bSVladimir Kondratiev 	wil_pmc_free(wil, false);
25932be7d22fSVladimir Kondratiev }
2594