xref: /linux/drivers/net/wireless/ath/wil6210/debugfs.c (revision a24a3d6abb978d4abc25d541e787981e7ef555c8)
12be7d22fSVladimir Kondratiev /*
2a351f2f5SLazar Alexei  * Copyright (c) 2012-2017 Qualcomm Atheros, Inc.
3e00243faSLior David  * Copyright (c) 2018, The Linux Foundation. All rights reserved.
42be7d22fSVladimir Kondratiev  *
52be7d22fSVladimir Kondratiev  * Permission to use, copy, modify, and/or distribute this software for any
62be7d22fSVladimir Kondratiev  * purpose with or without fee is hereby granted, provided that the above
72be7d22fSVladimir Kondratiev  * copyright notice and this permission notice appear in all copies.
82be7d22fSVladimir Kondratiev  *
92be7d22fSVladimir Kondratiev  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
102be7d22fSVladimir Kondratiev  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
112be7d22fSVladimir Kondratiev  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
122be7d22fSVladimir Kondratiev  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
132be7d22fSVladimir Kondratiev  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
142be7d22fSVladimir Kondratiev  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
152be7d22fSVladimir Kondratiev  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
162be7d22fSVladimir Kondratiev  */
172be7d22fSVladimir Kondratiev 
182be7d22fSVladimir Kondratiev #include <linux/module.h>
192be7d22fSVladimir Kondratiev #include <linux/debugfs.h>
202be7d22fSVladimir Kondratiev #include <linux/seq_file.h>
212be7d22fSVladimir Kondratiev #include <linux/pci.h>
222be7d22fSVladimir Kondratiev #include <linux/rtnetlink.h>
2384bb29b7SVladimir Kondratiev #include <linux/power_supply.h>
242be7d22fSVladimir Kondratiev #include "wil6210.h"
2536345ac3SVladimir Kondratiev #include "wmi.h"
262be7d22fSVladimir Kondratiev #include "txrx.h"
27dc16427bSVladimir Kondratiev #include "pmc.h"
282be7d22fSVladimir Kondratiev 
292be7d22fSVladimir Kondratiev /* Nasty hack. Better have per device instances */
302be7d22fSVladimir Kondratiev static u32 mem_addr;
312be7d22fSVladimir Kondratiev static u32 dbg_txdesc_index;
3210590c6aSGidon Studinski static u32 dbg_ring_index; /* 24+ for Rx, 0..23 for Tx */
33d98b8539SMaya Erez static u32 dbg_status_msg_index;
34d98b8539SMaya Erez /* 0..wil->num_rx_status_rings-1 for Rx, wil->tx_sring_idx for Tx */
35d98b8539SMaya Erez static u32 dbg_sring_index;
362be7d22fSVladimir Kondratiev 
37b7cde470SVladimir Kondratiev enum dbg_off_type {
38b7cde470SVladimir Kondratiev 	doff_u32 = 0,
39b7cde470SVladimir Kondratiev 	doff_x32 = 1,
40b7cde470SVladimir Kondratiev 	doff_ulong = 2,
41b7cde470SVladimir Kondratiev 	doff_io32 = 3,
4274997a53SLior David 	doff_u8 = 4
43b7cde470SVladimir Kondratiev };
44b7cde470SVladimir Kondratiev 
45b7cde470SVladimir Kondratiev /* offset to "wil" */
46b7cde470SVladimir Kondratiev struct dbg_off {
47b7cde470SVladimir Kondratiev 	const char *name;
48b7cde470SVladimir Kondratiev 	umode_t mode;
49b7cde470SVladimir Kondratiev 	ulong off;
50b7cde470SVladimir Kondratiev 	enum dbg_off_type type;
51b7cde470SVladimir Kondratiev };
52b7cde470SVladimir Kondratiev 
53d98b8539SMaya Erez static void wil_print_desc_edma(struct seq_file *s, struct wil6210_priv *wil,
54d98b8539SMaya Erez 				struct wil_ring *ring,
55d98b8539SMaya Erez 				char _s, char _h, int idx)
56d98b8539SMaya Erez {
57d98b8539SMaya Erez 	u8 num_of_descs;
58d98b8539SMaya Erez 	bool has_skb = false;
59d98b8539SMaya Erez 
60d98b8539SMaya Erez 	if (ring->is_rx) {
61d98b8539SMaya Erez 		struct wil_rx_enhanced_desc *rx_d =
62d98b8539SMaya Erez 			(struct wil_rx_enhanced_desc *)
63d98b8539SMaya Erez 			&ring->va[idx].rx.enhanced;
64d98b8539SMaya Erez 		u16 buff_id = le16_to_cpu(rx_d->mac.buff_id);
65d98b8539SMaya Erez 
66d98b8539SMaya Erez 		has_skb = wil->rx_buff_mgmt.buff_arr[buff_id].skb;
67d98b8539SMaya Erez 		seq_printf(s, "%c", (has_skb) ? _h : _s);
68d98b8539SMaya Erez 	} else {
69d98b8539SMaya Erez 		struct wil_tx_enhanced_desc *d =
70d98b8539SMaya Erez 			(struct wil_tx_enhanced_desc *)
71d98b8539SMaya Erez 			&ring->va[idx].tx.enhanced;
72d98b8539SMaya Erez 
73d98b8539SMaya Erez 		num_of_descs = (u8)d->mac.d[2];
74d98b8539SMaya Erez 		has_skb = ring->ctx[idx].skb;
75d98b8539SMaya Erez 		if (num_of_descs >= 1)
76d98b8539SMaya Erez 			seq_printf(s, "%c", ring->ctx[idx].skb ? _h : _s);
77d98b8539SMaya Erez 		else
78d98b8539SMaya Erez 			/* num_of_descs == 0, it's a frag in a list of descs */
79d98b8539SMaya Erez 			seq_printf(s, "%c", has_skb ? 'h' : _s);
80d98b8539SMaya Erez 	}
81d98b8539SMaya Erez }
82d98b8539SMaya Erez 
8310590c6aSGidon Studinski static void wil_print_ring(struct seq_file *s, struct wil6210_priv *wil,
8410590c6aSGidon Studinski 			   const char *name, struct wil_ring *ring,
8559f7c0a9SVladimir Kondratiev 			   char _s, char _h)
862be7d22fSVladimir Kondratiev {
8710590c6aSGidon Studinski 	void __iomem *x = wmi_addr(wil, ring->hwtail);
88995cdd0eSVladimir Kondratiev 	u32 v;
892be7d22fSVladimir Kondratiev 
9010590c6aSGidon Studinski 	seq_printf(s, "RING %s = {\n", name);
9110590c6aSGidon Studinski 	seq_printf(s, "  pa     = %pad\n", &ring->pa);
9210590c6aSGidon Studinski 	seq_printf(s, "  va     = 0x%p\n", ring->va);
9310590c6aSGidon Studinski 	seq_printf(s, "  size   = %d\n", ring->size);
94d98b8539SMaya Erez 	if (wil->use_enhanced_dma_hw && ring->is_rx)
95d98b8539SMaya Erez 		seq_printf(s, "  swtail = %u\n", *ring->edma_rx_swtail.va);
96d98b8539SMaya Erez 	else
9710590c6aSGidon Studinski 		seq_printf(s, "  swtail = %d\n", ring->swtail);
9810590c6aSGidon Studinski 	seq_printf(s, "  swhead = %d\n", ring->swhead);
9910590c6aSGidon Studinski 	seq_printf(s, "  hwtail = [0x%08x] -> ", ring->hwtail);
100995cdd0eSVladimir Kondratiev 	if (x) {
101b9eeb512SVladimir Kondratiev 		v = readl(x);
102995cdd0eSVladimir Kondratiev 		seq_printf(s, "0x%08x = %d\n", v, v);
103995cdd0eSVladimir Kondratiev 	} else {
1048fe59627SVladimir Kondratiev 		seq_puts(s, "???\n");
105995cdd0eSVladimir Kondratiev 	}
1062be7d22fSVladimir Kondratiev 
10710590c6aSGidon Studinski 	if (ring->va && (ring->size <= (1 << WIL_RING_SIZE_ORDER_MAX))) {
1082be7d22fSVladimir Kondratiev 		uint i;
1098fe59627SVladimir Kondratiev 
11010590c6aSGidon Studinski 		for (i = 0; i < ring->size; i++) {
111d98b8539SMaya Erez 			if ((i % 128) == 0 && i != 0)
112d98b8539SMaya Erez 				seq_puts(s, "\n");
113d98b8539SMaya Erez 			if (wil->use_enhanced_dma_hw) {
114d98b8539SMaya Erez 				wil_print_desc_edma(s, wil, ring, _s, _h, i);
115d98b8539SMaya Erez 			} else {
11610590c6aSGidon Studinski 				volatile struct vring_tx_desc *d =
11710590c6aSGidon Studinski 					&ring->va[i].tx.legacy;
11859f7c0a9SVladimir Kondratiev 				seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
11910590c6aSGidon Studinski 					   _s : (ring->ctx[i].skb ? _h : 'h'));
1202be7d22fSVladimir Kondratiev 			}
121d98b8539SMaya Erez 		}
1228fe59627SVladimir Kondratiev 		seq_puts(s, "\n");
1232be7d22fSVladimir Kondratiev 	}
1248fe59627SVladimir Kondratiev 	seq_puts(s, "}\n");
1252be7d22fSVladimir Kondratiev }
1262be7d22fSVladimir Kondratiev 
12710590c6aSGidon Studinski static int wil_ring_debugfs_show(struct seq_file *s, void *data)
1282be7d22fSVladimir Kondratiev {
1292be7d22fSVladimir Kondratiev 	uint i;
1302be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
1312be7d22fSVladimir Kondratiev 
13210590c6aSGidon Studinski 	wil_print_ring(s, wil, "rx", &wil->ring_rx, 'S', '_');
1332be7d22fSVladimir Kondratiev 
13410590c6aSGidon Studinski 	for (i = 0; i < ARRAY_SIZE(wil->ring_tx); i++) {
13510590c6aSGidon Studinski 		struct wil_ring *ring = &wil->ring_tx[i];
13610590c6aSGidon Studinski 		struct wil_ring_tx_data *txdata = &wil->ring_tx_data[i];
1377c0acf86SVladimir Kondratiev 
13810590c6aSGidon Studinski 		if (ring->va) {
13910590c6aSGidon Studinski 			int cid = wil->ring2cid_tid[i][0];
14010590c6aSGidon Studinski 			int tid = wil->ring2cid_tid[i][1];
14110590c6aSGidon Studinski 			u32 swhead = ring->swhead;
14210590c6aSGidon Studinski 			u32 swtail = ring->swtail;
14310590c6aSGidon Studinski 			int used = (ring->size + swhead - swtail)
14410590c6aSGidon Studinski 				   % ring->size;
14510590c6aSGidon Studinski 			int avail = ring->size - used - 1;
1462be7d22fSVladimir Kondratiev 			char name[10];
1478f55cbecSBoris Sorochkin 			char sidle[10];
1487c0acf86SVladimir Kondratiev 			/* performance monitoring */
1497c0acf86SVladimir Kondratiev 			cycles_t now = get_cycles();
150c20e7789SChen Gang 			uint64_t idle = txdata->idle * 100;
151c20e7789SChen Gang 			uint64_t total = now - txdata->begin;
1527c0acf86SVladimir Kondratiev 
1538f55cbecSBoris Sorochkin 			if (total != 0) {
154e48b1790SVladimir Kondratiev 				do_div(idle, total);
1558f55cbecSBoris Sorochkin 				snprintf(sidle, sizeof(sidle), "%3d%%",
1568f55cbecSBoris Sorochkin 					 (int)idle);
1578f55cbecSBoris Sorochkin 			} else {
1588f55cbecSBoris Sorochkin 				snprintf(sidle, sizeof(sidle), "N/A");
1598f55cbecSBoris Sorochkin 			}
1607c0acf86SVladimir Kondratiev 			txdata->begin = now;
1617c0acf86SVladimir Kondratiev 			txdata->idle = 0ULL;
1627c0acf86SVladimir Kondratiev 
1632be7d22fSVladimir Kondratiev 			snprintf(name, sizeof(name), "tx_%2d", i);
1643df2cd36SVladimir Kondratiev 
16541d6b093SVladimir Kondratiev 			if (cid < WIL6210_MAX_CID)
1663277213fSVladimir Kondratiev 				seq_printf(s,
167230d8442SVladimir Kondratiev 					   "\n%pM CID %d TID %d 1x%s BACK([%u] %u TU A%s) [%3d|%3d] idle %s\n",
1683277213fSVladimir Kondratiev 					   wil->sta[cid].addr, cid, tid,
169230d8442SVladimir Kondratiev 					   txdata->dot1x_open ? "+" : "-",
17041d6b093SVladimir Kondratiev 					   txdata->agg_wsize,
17141d6b093SVladimir Kondratiev 					   txdata->agg_timeout,
172cbcf5866SVladimir Kondratiev 					   txdata->agg_amsdu ? "+" : "-",
1738f55cbecSBoris Sorochkin 					   used, avail, sidle);
17441d6b093SVladimir Kondratiev 			else
17541d6b093SVladimir Kondratiev 				seq_printf(s,
176230d8442SVladimir Kondratiev 					   "\nBroadcast 1x%s [%3d|%3d] idle %s\n",
177230d8442SVladimir Kondratiev 					   txdata->dot1x_open ? "+" : "-",
17841d6b093SVladimir Kondratiev 					   used, avail, sidle);
1797c0acf86SVladimir Kondratiev 
18010590c6aSGidon Studinski 			wil_print_ring(s, wil, name, ring, '_', 'H');
1812be7d22fSVladimir Kondratiev 		}
1822be7d22fSVladimir Kondratiev 	}
1832be7d22fSVladimir Kondratiev 
1842be7d22fSVladimir Kondratiev 	return 0;
1852be7d22fSVladimir Kondratiev }
1862be7d22fSVladimir Kondratiev 
18710590c6aSGidon Studinski static int wil_ring_seq_open(struct inode *inode, struct file *file)
1882be7d22fSVladimir Kondratiev {
18910590c6aSGidon Studinski 	return single_open(file, wil_ring_debugfs_show, inode->i_private);
1902be7d22fSVladimir Kondratiev }
1912be7d22fSVladimir Kondratiev 
19210590c6aSGidon Studinski static const struct file_operations fops_ring = {
19310590c6aSGidon Studinski 	.open		= wil_ring_seq_open,
1942be7d22fSVladimir Kondratiev 	.release	= single_release,
1952be7d22fSVladimir Kondratiev 	.read		= seq_read,
1962be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
1972be7d22fSVladimir Kondratiev };
1982be7d22fSVladimir Kondratiev 
199d98b8539SMaya Erez static void wil_print_sring(struct seq_file *s, struct wil6210_priv *wil,
200d98b8539SMaya Erez 			    struct wil_status_ring *sring)
201d98b8539SMaya Erez {
202d98b8539SMaya Erez 	void __iomem *x = wmi_addr(wil, sring->hwtail);
203d98b8539SMaya Erez 	int sring_idx = sring - wil->srings;
204d98b8539SMaya Erez 	u32 v;
205d98b8539SMaya Erez 
206d98b8539SMaya Erez 	seq_printf(s, "Status Ring %s [ %d ] = {\n",
207d98b8539SMaya Erez 		   sring->is_rx ? "RX" : "TX", sring_idx);
208d98b8539SMaya Erez 	seq_printf(s, "  pa     = %pad\n", &sring->pa);
209d98b8539SMaya Erez 	seq_printf(s, "  va     = 0x%pK\n", sring->va);
210d98b8539SMaya Erez 	seq_printf(s, "  size   = %d\n", sring->size);
211d98b8539SMaya Erez 	seq_printf(s, "  elem_size   = %zu\n", sring->elem_size);
212d98b8539SMaya Erez 	seq_printf(s, "  swhead = %d\n", sring->swhead);
213d98b8539SMaya Erez 	seq_printf(s, "  hwtail = [0x%08x] -> ", sring->hwtail);
214d98b8539SMaya Erez 	if (x) {
215d98b8539SMaya Erez 		v = readl_relaxed(x);
216d98b8539SMaya Erez 		seq_printf(s, "0x%08x = %d\n", v, v);
217d98b8539SMaya Erez 	} else {
218d98b8539SMaya Erez 		seq_puts(s, "???\n");
219d98b8539SMaya Erez 	}
220d98b8539SMaya Erez 	seq_printf(s, "  desc_rdy_pol   = %d\n", sring->desc_rdy_pol);
221d98b8539SMaya Erez 
222d98b8539SMaya Erez 	if (sring->va && (sring->size <= (1 << WIL_RING_SIZE_ORDER_MAX))) {
223d98b8539SMaya Erez 		uint i;
224d98b8539SMaya Erez 
225d98b8539SMaya Erez 		for (i = 0; i < sring->size; i++) {
226d98b8539SMaya Erez 			u32 *sdword_0 =
227d98b8539SMaya Erez 				(u32 *)(sring->va + (sring->elem_size * i));
228d98b8539SMaya Erez 
229d98b8539SMaya Erez 			if ((i % 128) == 0 && i != 0)
230d98b8539SMaya Erez 				seq_puts(s, "\n");
231d98b8539SMaya Erez 			if (i == sring->swhead)
232d98b8539SMaya Erez 				seq_printf(s, "%c", (*sdword_0 & BIT(31)) ?
233d98b8539SMaya Erez 					   'X' : 'x');
234d98b8539SMaya Erez 			else
235d98b8539SMaya Erez 				seq_printf(s, "%c", (*sdword_0 & BIT(31)) ?
236d98b8539SMaya Erez 					   '1' : '0');
237d98b8539SMaya Erez 		}
238d98b8539SMaya Erez 		seq_puts(s, "\n");
239d98b8539SMaya Erez 	}
240d98b8539SMaya Erez 	seq_puts(s, "}\n");
241d98b8539SMaya Erez }
242d98b8539SMaya Erez 
243d98b8539SMaya Erez static int wil_srings_debugfs_show(struct seq_file *s, void *data)
244d98b8539SMaya Erez {
245d98b8539SMaya Erez 	struct wil6210_priv *wil = s->private;
246d98b8539SMaya Erez 	int i = 0;
247d98b8539SMaya Erez 
248d98b8539SMaya Erez 	for (i = 0; i < WIL6210_MAX_STATUS_RINGS; i++)
249d98b8539SMaya Erez 		if (wil->srings[i].va)
250d98b8539SMaya Erez 			wil_print_sring(s, wil, &wil->srings[i]);
251d98b8539SMaya Erez 
252d98b8539SMaya Erez 	return 0;
253d98b8539SMaya Erez }
254d98b8539SMaya Erez 
255d98b8539SMaya Erez static int wil_srings_seq_open(struct inode *inode, struct file *file)
256d98b8539SMaya Erez {
257d98b8539SMaya Erez 	return single_open(file, wil_srings_debugfs_show, inode->i_private);
258d98b8539SMaya Erez }
259d98b8539SMaya Erez 
260d98b8539SMaya Erez static const struct file_operations fops_srings = {
261d98b8539SMaya Erez 	.open		= wil_srings_seq_open,
262d98b8539SMaya Erez 	.release	= single_release,
263d98b8539SMaya Erez 	.read		= seq_read,
264d98b8539SMaya Erez 	.llseek		= seq_lseek,
265d98b8539SMaya Erez };
266d98b8539SMaya Erez 
267a202fbbfSAndy Shevchenko static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
268a202fbbfSAndy Shevchenko 			    const char *prefix)
269a202fbbfSAndy Shevchenko {
270a202fbbfSAndy Shevchenko 	seq_hex_dump(s, prefix, DUMP_PREFIX_NONE, 16, 1, p, len, false);
271a202fbbfSAndy Shevchenko }
272a202fbbfSAndy Shevchenko 
27310590c6aSGidon Studinski static void wil_print_mbox_ring(struct seq_file *s, const char *prefix,
2742be7d22fSVladimir Kondratiev 				void __iomem *off)
2752be7d22fSVladimir Kondratiev {
2762be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
2772be7d22fSVladimir Kondratiev 	struct wil6210_mbox_ring r;
2782be7d22fSVladimir Kondratiev 	int rsize;
2792be7d22fSVladimir Kondratiev 	uint i;
2802be7d22fSVladimir Kondratiev 
281349214c1SMaya Erez 	wil_halp_vote(wil);
282349214c1SMaya Erez 
2832be7d22fSVladimir Kondratiev 	wil_memcpy_fromio_32(&r, off, sizeof(r));
2842be7d22fSVladimir Kondratiev 	wil_mbox_ring_le2cpus(&r);
2852be7d22fSVladimir Kondratiev 	/*
2862be7d22fSVladimir Kondratiev 	 * we just read memory block from NIC. This memory may be
2872be7d22fSVladimir Kondratiev 	 * garbage. Check validity before using it.
2882be7d22fSVladimir Kondratiev 	 */
2892be7d22fSVladimir Kondratiev 	rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
2902be7d22fSVladimir Kondratiev 
2912be7d22fSVladimir Kondratiev 	seq_printf(s, "ring %s = {\n", prefix);
2922be7d22fSVladimir Kondratiev 	seq_printf(s, "  base = 0x%08x\n", r.base);
2932be7d22fSVladimir Kondratiev 	seq_printf(s, "  size = 0x%04x bytes -> %d entries\n", r.size, rsize);
2942be7d22fSVladimir Kondratiev 	seq_printf(s, "  tail = 0x%08x\n", r.tail);
2952be7d22fSVladimir Kondratiev 	seq_printf(s, "  head = 0x%08x\n", r.head);
2962be7d22fSVladimir Kondratiev 	seq_printf(s, "  entry size = %d\n", r.entry_size);
2972be7d22fSVladimir Kondratiev 
2982be7d22fSVladimir Kondratiev 	if (r.size % sizeof(struct wil6210_mbox_ring_desc)) {
2992be7d22fSVladimir Kondratiev 		seq_printf(s, "  ??? size is not multiple of %zd, garbage?\n",
3002be7d22fSVladimir Kondratiev 			   sizeof(struct wil6210_mbox_ring_desc));
3012be7d22fSVladimir Kondratiev 		goto out;
3022be7d22fSVladimir Kondratiev 	}
3032be7d22fSVladimir Kondratiev 
3042be7d22fSVladimir Kondratiev 	if (!wmi_addr(wil, r.base) ||
3052be7d22fSVladimir Kondratiev 	    !wmi_addr(wil, r.tail) ||
3062be7d22fSVladimir Kondratiev 	    !wmi_addr(wil, r.head)) {
3078fe59627SVladimir Kondratiev 		seq_puts(s, "  ??? pointers are garbage?\n");
3082be7d22fSVladimir Kondratiev 		goto out;
3092be7d22fSVladimir Kondratiev 	}
3102be7d22fSVladimir Kondratiev 
3112be7d22fSVladimir Kondratiev 	for (i = 0; i < rsize; i++) {
3122be7d22fSVladimir Kondratiev 		struct wil6210_mbox_ring_desc d;
3132be7d22fSVladimir Kondratiev 		struct wil6210_mbox_hdr hdr;
3142be7d22fSVladimir Kondratiev 		size_t delta = i * sizeof(d);
3152be7d22fSVladimir Kondratiev 		void __iomem *x = wil->csr + HOSTADDR(r.base) + delta;
3162be7d22fSVladimir Kondratiev 
3172be7d22fSVladimir Kondratiev 		wil_memcpy_fromio_32(&d, x, sizeof(d));
3182be7d22fSVladimir Kondratiev 
3192be7d22fSVladimir Kondratiev 		seq_printf(s, "  [%2x] %s %s%s 0x%08x", i,
3202be7d22fSVladimir Kondratiev 			   d.sync ? "F" : "E",
3212be7d22fSVladimir Kondratiev 			   (r.tail - r.base == delta) ? "t" : " ",
3222be7d22fSVladimir Kondratiev 			   (r.head - r.base == delta) ? "h" : " ",
3232be7d22fSVladimir Kondratiev 			   le32_to_cpu(d.addr));
3242be7d22fSVladimir Kondratiev 		if (0 == wmi_read_hdr(wil, d.addr, &hdr)) {
3252be7d22fSVladimir Kondratiev 			u16 len = le16_to_cpu(hdr.len);
3268fe59627SVladimir Kondratiev 
3272be7d22fSVladimir Kondratiev 			seq_printf(s, " -> %04x %04x %04x %02x\n",
3282be7d22fSVladimir Kondratiev 				   le16_to_cpu(hdr.seq), len,
3292be7d22fSVladimir Kondratiev 				   le16_to_cpu(hdr.type), hdr.flags);
3302be7d22fSVladimir Kondratiev 			if (len <= MAX_MBOXITEM_SIZE) {
3312be7d22fSVladimir Kondratiev 				unsigned char databuf[MAX_MBOXITEM_SIZE];
3322be7d22fSVladimir Kondratiev 				void __iomem *src = wmi_buffer(wil, d.addr) +
3332be7d22fSVladimir Kondratiev 					sizeof(struct wil6210_mbox_hdr);
3342be7d22fSVladimir Kondratiev 				/*
3352be7d22fSVladimir Kondratiev 				 * No need to check @src for validity -
3362be7d22fSVladimir Kondratiev 				 * we already validated @d.addr while
3372be7d22fSVladimir Kondratiev 				 * reading header
3382be7d22fSVladimir Kondratiev 				 */
3392be7d22fSVladimir Kondratiev 				wil_memcpy_fromio_32(databuf, src, len);
340a202fbbfSAndy Shevchenko 				wil_seq_hexdump(s, databuf, len, "      : ");
3412be7d22fSVladimir Kondratiev 			}
3422be7d22fSVladimir Kondratiev 		} else {
3438fe59627SVladimir Kondratiev 			seq_puts(s, "\n");
3442be7d22fSVladimir Kondratiev 		}
3452be7d22fSVladimir Kondratiev 	}
3462be7d22fSVladimir Kondratiev  out:
3478fe59627SVladimir Kondratiev 	seq_puts(s, "}\n");
348349214c1SMaya Erez 	wil_halp_unvote(wil);
3492be7d22fSVladimir Kondratiev }
3502be7d22fSVladimir Kondratiev 
3512be7d22fSVladimir Kondratiev static int wil_mbox_debugfs_show(struct seq_file *s, void *data)
3522be7d22fSVladimir Kondratiev {
3532be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
35494162666SLazar Alexei 	int ret;
35594162666SLazar Alexei 
35694162666SLazar Alexei 	ret = wil_pm_runtime_get(wil);
35794162666SLazar Alexei 	if (ret < 0)
35894162666SLazar Alexei 		return ret;
3592be7d22fSVladimir Kondratiev 
36010590c6aSGidon Studinski 	wil_print_mbox_ring(s, "tx", wil->csr + HOST_MBOX +
3612be7d22fSVladimir Kondratiev 		       offsetof(struct wil6210_mbox_ctl, tx));
36210590c6aSGidon Studinski 	wil_print_mbox_ring(s, "rx", wil->csr + HOST_MBOX +
3632be7d22fSVladimir Kondratiev 		       offsetof(struct wil6210_mbox_ctl, rx));
3642be7d22fSVladimir Kondratiev 
36594162666SLazar Alexei 	wil_pm_runtime_put(wil);
36694162666SLazar Alexei 
3672be7d22fSVladimir Kondratiev 	return 0;
3682be7d22fSVladimir Kondratiev }
3692be7d22fSVladimir Kondratiev 
3702be7d22fSVladimir Kondratiev static int wil_mbox_seq_open(struct inode *inode, struct file *file)
3712be7d22fSVladimir Kondratiev {
3722be7d22fSVladimir Kondratiev 	return single_open(file, wil_mbox_debugfs_show, inode->i_private);
3732be7d22fSVladimir Kondratiev }
3742be7d22fSVladimir Kondratiev 
3752be7d22fSVladimir Kondratiev static const struct file_operations fops_mbox = {
3762be7d22fSVladimir Kondratiev 	.open		= wil_mbox_seq_open,
3772be7d22fSVladimir Kondratiev 	.release	= single_release,
3782be7d22fSVladimir Kondratiev 	.read		= seq_read,
3792be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
3802be7d22fSVladimir Kondratiev };
3812be7d22fSVladimir Kondratiev 
3822be7d22fSVladimir Kondratiev static int wil_debugfs_iomem_x32_set(void *data, u64 val)
3832be7d22fSVladimir Kondratiev {
38494162666SLazar Alexei 	struct wil_debugfs_iomem_data *d = (struct
38594162666SLazar Alexei 					    wil_debugfs_iomem_data *)data;
38694162666SLazar Alexei 	struct wil6210_priv *wil = d->wil;
38794162666SLazar Alexei 	int ret;
38894162666SLazar Alexei 
38994162666SLazar Alexei 	ret = wil_pm_runtime_get(wil);
39094162666SLazar Alexei 	if (ret < 0)
39194162666SLazar Alexei 		return ret;
39294162666SLazar Alexei 
39394162666SLazar Alexei 	writel(val, (void __iomem *)d->offset);
3942be7d22fSVladimir Kondratiev 	wmb(); /* make sure write propagated to HW */
3952be7d22fSVladimir Kondratiev 
39694162666SLazar Alexei 	wil_pm_runtime_put(wil);
39794162666SLazar Alexei 
3982be7d22fSVladimir Kondratiev 	return 0;
3992be7d22fSVladimir Kondratiev }
4002be7d22fSVladimir Kondratiev 
4012be7d22fSVladimir Kondratiev static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
4022be7d22fSVladimir Kondratiev {
40394162666SLazar Alexei 	struct wil_debugfs_iomem_data *d = (struct
40494162666SLazar Alexei 					    wil_debugfs_iomem_data *)data;
40594162666SLazar Alexei 	struct wil6210_priv *wil = d->wil;
40694162666SLazar Alexei 	int ret;
40794162666SLazar Alexei 
40894162666SLazar Alexei 	ret = wil_pm_runtime_get(wil);
40994162666SLazar Alexei 	if (ret < 0)
41094162666SLazar Alexei 		return ret;
41194162666SLazar Alexei 
41294162666SLazar Alexei 	*val = readl((void __iomem *)d->offset);
41394162666SLazar Alexei 
41494162666SLazar Alexei 	wil_pm_runtime_put(wil);
4152be7d22fSVladimir Kondratiev 
4162be7d22fSVladimir Kondratiev 	return 0;
4172be7d22fSVladimir Kondratiev }
4182be7d22fSVladimir Kondratiev 
4192be7d22fSVladimir Kondratiev DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
4202be7d22fSVladimir Kondratiev 			wil_debugfs_iomem_x32_set, "0x%08llx\n");
4212be7d22fSVladimir Kondratiev 
4222be7d22fSVladimir Kondratiev static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
4230ecc833bSAl Viro 						   umode_t mode,
4242be7d22fSVladimir Kondratiev 						   struct dentry *parent,
42594162666SLazar Alexei 						   void *value,
42694162666SLazar Alexei 						   struct wil6210_priv *wil)
4272be7d22fSVladimir Kondratiev {
42894162666SLazar Alexei 	struct dentry *file;
42994162666SLazar Alexei 	struct wil_debugfs_iomem_data *data = &wil->dbg_data.data_arr[
43094162666SLazar Alexei 					      wil->dbg_data.iomem_data_count];
43194162666SLazar Alexei 
43294162666SLazar Alexei 	data->wil = wil;
43394162666SLazar Alexei 	data->offset = value;
43494162666SLazar Alexei 
43594162666SLazar Alexei 	file = debugfs_create_file(name, mode, parent, data, &fops_iomem_x32);
43694162666SLazar Alexei 	if (!IS_ERR_OR_NULL(file))
43794162666SLazar Alexei 		wil->dbg_data.iomem_data_count++;
43894162666SLazar Alexei 
43994162666SLazar Alexei 	return file;
4402be7d22fSVladimir Kondratiev }
4412be7d22fSVladimir Kondratiev 
4423de6cf20SVladimir Kondratiev static int wil_debugfs_ulong_set(void *data, u64 val)
4433de6cf20SVladimir Kondratiev {
4443de6cf20SVladimir Kondratiev 	*(ulong *)data = val;
4453de6cf20SVladimir Kondratiev 	return 0;
4463de6cf20SVladimir Kondratiev }
4478fe59627SVladimir Kondratiev 
4483de6cf20SVladimir Kondratiev static int wil_debugfs_ulong_get(void *data, u64 *val)
4493de6cf20SVladimir Kondratiev {
4503de6cf20SVladimir Kondratiev 	*val = *(ulong *)data;
4513de6cf20SVladimir Kondratiev 	return 0;
4523de6cf20SVladimir Kondratiev }
4538fe59627SVladimir Kondratiev 
4543de6cf20SVladimir Kondratiev DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
4558ea06188SVladimir Kondratiev 			wil_debugfs_ulong_set, "0x%llx\n");
4563de6cf20SVladimir Kondratiev 
4573de6cf20SVladimir Kondratiev static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode,
4583de6cf20SVladimir Kondratiev 					       struct dentry *parent,
4593de6cf20SVladimir Kondratiev 					       ulong *value)
4603de6cf20SVladimir Kondratiev {
4613de6cf20SVladimir Kondratiev 	return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong);
4623de6cf20SVladimir Kondratiev }
4633de6cf20SVladimir Kondratiev 
464b7cde470SVladimir Kondratiev /**
465b7cde470SVladimir Kondratiev  * wil6210_debugfs_init_offset - create set of debugfs files
466b7cde470SVladimir Kondratiev  * @wil - driver's context, used for printing
467b7cde470SVladimir Kondratiev  * @dbg - directory on the debugfs, where files will be created
468b7cde470SVladimir Kondratiev  * @base - base address used in address calculation
469b7cde470SVladimir Kondratiev  * @tbl - table with file descriptions. Should be terminated with empty element.
470b7cde470SVladimir Kondratiev  *
471b7cde470SVladimir Kondratiev  * Creates files accordingly to the @tbl.
472b7cde470SVladimir Kondratiev  */
473b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_offset(struct wil6210_priv *wil,
474b7cde470SVladimir Kondratiev 					struct dentry *dbg, void *base,
475b7cde470SVladimir Kondratiev 					const struct dbg_off * const tbl)
476b7cde470SVladimir Kondratiev {
477b7cde470SVladimir Kondratiev 	int i;
478b7cde470SVladimir Kondratiev 
479b7cde470SVladimir Kondratiev 	for (i = 0; tbl[i].name; i++) {
480867fa0d4SVladimir Kondratiev 		struct dentry *f;
481b7cde470SVladimir Kondratiev 
482b7cde470SVladimir Kondratiev 		switch (tbl[i].type) {
483b7cde470SVladimir Kondratiev 		case doff_u32:
484b7cde470SVladimir Kondratiev 			f = debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg,
485b7cde470SVladimir Kondratiev 					       base + tbl[i].off);
486b7cde470SVladimir Kondratiev 			break;
487b7cde470SVladimir Kondratiev 		case doff_x32:
488b7cde470SVladimir Kondratiev 			f = debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg,
489b7cde470SVladimir Kondratiev 					       base + tbl[i].off);
490b7cde470SVladimir Kondratiev 			break;
491b7cde470SVladimir Kondratiev 		case doff_ulong:
492b7cde470SVladimir Kondratiev 			f = wil_debugfs_create_ulong(tbl[i].name, tbl[i].mode,
493b7cde470SVladimir Kondratiev 						     dbg, base + tbl[i].off);
494b7cde470SVladimir Kondratiev 			break;
495b7cde470SVladimir Kondratiev 		case doff_io32:
496b7cde470SVladimir Kondratiev 			f = wil_debugfs_create_iomem_x32(tbl[i].name,
497b7cde470SVladimir Kondratiev 							 tbl[i].mode, dbg,
49894162666SLazar Alexei 							 base + tbl[i].off,
49994162666SLazar Alexei 							 wil);
500b7cde470SVladimir Kondratiev 			break;
50174997a53SLior David 		case doff_u8:
50274997a53SLior David 			f = debugfs_create_u8(tbl[i].name, tbl[i].mode, dbg,
50374997a53SLior David 					      base + tbl[i].off);
50474997a53SLior David 			break;
505867fa0d4SVladimir Kondratiev 		default:
506867fa0d4SVladimir Kondratiev 			f = ERR_PTR(-EINVAL);
507b7cde470SVladimir Kondratiev 		}
508b7cde470SVladimir Kondratiev 		if (IS_ERR_OR_NULL(f))
509b7cde470SVladimir Kondratiev 			wil_err(wil, "Create file \"%s\": err %ld\n",
510b7cde470SVladimir Kondratiev 				tbl[i].name, PTR_ERR(f));
511b7cde470SVladimir Kondratiev 	}
512b7cde470SVladimir Kondratiev }
513b7cde470SVladimir Kondratiev 
514b7cde470SVladimir Kondratiev static const struct dbg_off isr_off[] = {
51578484c44SMaya Erez 	{"ICC", 0644, offsetof(struct RGF_ICR, ICC), doff_io32},
51678484c44SMaya Erez 	{"ICR", 0644, offsetof(struct RGF_ICR, ICR), doff_io32},
51778484c44SMaya Erez 	{"ICM", 0644, offsetof(struct RGF_ICR, ICM), doff_io32},
51878484c44SMaya Erez 	{"ICS",	0244, offsetof(struct RGF_ICR, ICS), doff_io32},
51978484c44SMaya Erez 	{"IMV", 0644, offsetof(struct RGF_ICR, IMV), doff_io32},
52078484c44SMaya Erez 	{"IMS",	0244, offsetof(struct RGF_ICR, IMS), doff_io32},
52178484c44SMaya Erez 	{"IMC",	0244, offsetof(struct RGF_ICR, IMC), doff_io32},
522b7cde470SVladimir Kondratiev 	{},
523b7cde470SVladimir Kondratiev };
5248fe59627SVladimir Kondratiev 
5252be7d22fSVladimir Kondratiev static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
5262be7d22fSVladimir Kondratiev 				      const char *name,
5272be7d22fSVladimir Kondratiev 				      struct dentry *parent, u32 off)
5282be7d22fSVladimir Kondratiev {
5292be7d22fSVladimir Kondratiev 	struct dentry *d = debugfs_create_dir(name, parent);
5302be7d22fSVladimir Kondratiev 
5312be7d22fSVladimir Kondratiev 	if (IS_ERR_OR_NULL(d))
5322be7d22fSVladimir Kondratiev 		return -ENODEV;
5332be7d22fSVladimir Kondratiev 
534b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off,
535b7cde470SVladimir Kondratiev 				    isr_off);
5362be7d22fSVladimir Kondratiev 
5372be7d22fSVladimir Kondratiev 	return 0;
5382be7d22fSVladimir Kondratiev }
5392be7d22fSVladimir Kondratiev 
540b7cde470SVladimir Kondratiev static const struct dbg_off pseudo_isr_off[] = {
54178484c44SMaya Erez 	{"CAUSE",   0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32},
54278484c44SMaya Erez 	{"MASK_SW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32},
54378484c44SMaya Erez 	{"MASK_FW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32},
544b7cde470SVladimir Kondratiev 	{},
545b7cde470SVladimir Kondratiev };
546b7cde470SVladimir Kondratiev 
5472be7d22fSVladimir Kondratiev static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
5482be7d22fSVladimir Kondratiev 					     struct dentry *parent)
5492be7d22fSVladimir Kondratiev {
5502be7d22fSVladimir Kondratiev 	struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
5512be7d22fSVladimir Kondratiev 
5522be7d22fSVladimir Kondratiev 	if (IS_ERR_OR_NULL(d))
5532be7d22fSVladimir Kondratiev 		return -ENODEV;
5542be7d22fSVladimir Kondratiev 
555b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
556b7cde470SVladimir Kondratiev 				    pseudo_isr_off);
5572be7d22fSVladimir Kondratiev 
5582be7d22fSVladimir Kondratiev 	return 0;
5592be7d22fSVladimir Kondratiev }
5602be7d22fSVladimir Kondratiev 
56178366f69SVladimir Kondratiev static const struct dbg_off lgc_itr_cnt_off[] = {
56278484c44SMaya Erez 	{"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32},
56378484c44SMaya Erez 	{"DATA", 0644, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32},
56478484c44SMaya Erez 	{"CTL",  0644, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32},
565b7cde470SVladimir Kondratiev 	{},
566b7cde470SVladimir Kondratiev };
567b7cde470SVladimir Kondratiev 
56878366f69SVladimir Kondratiev static const struct dbg_off tx_itr_cnt_off[] = {
56978484c44SMaya Erez 	{"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_TRSH),
57078366f69SVladimir Kondratiev 	 doff_io32},
57178484c44SMaya Erez 	{"DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_DATA),
57278366f69SVladimir Kondratiev 	 doff_io32},
57378484c44SMaya Erez 	{"CTL",  0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_CTL),
57478366f69SVladimir Kondratiev 	 doff_io32},
57578484c44SMaya Erez 	{"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_TRSH),
57678366f69SVladimir Kondratiev 	 doff_io32},
57778484c44SMaya Erez 	{"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_DATA),
57878366f69SVladimir Kondratiev 	 doff_io32},
57978484c44SMaya Erez 	{"IDL_CTL",  0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_CTL),
58078366f69SVladimir Kondratiev 	 doff_io32},
58178366f69SVladimir Kondratiev 	{},
58278366f69SVladimir Kondratiev };
58378366f69SVladimir Kondratiev 
58478366f69SVladimir Kondratiev static const struct dbg_off rx_itr_cnt_off[] = {
58578484c44SMaya Erez 	{"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_TRSH),
58678366f69SVladimir Kondratiev 	 doff_io32},
58778484c44SMaya Erez 	{"DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_DATA),
58878366f69SVladimir Kondratiev 	 doff_io32},
58978484c44SMaya Erez 	{"CTL",  0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_CTL),
59078366f69SVladimir Kondratiev 	 doff_io32},
59178484c44SMaya Erez 	{"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_TRSH),
59278366f69SVladimir Kondratiev 	 doff_io32},
59378484c44SMaya Erez 	{"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_DATA),
59478366f69SVladimir Kondratiev 	 doff_io32},
59578484c44SMaya Erez 	{"IDL_CTL",  0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_CTL),
59678366f69SVladimir Kondratiev 	 doff_io32},
59778366f69SVladimir Kondratiev 	{},
59878366f69SVladimir Kondratiev };
59978366f69SVladimir Kondratiev 
6002be7d22fSVladimir Kondratiev static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
6012be7d22fSVladimir Kondratiev 					  struct dentry *parent)
6022be7d22fSVladimir Kondratiev {
60378366f69SVladimir Kondratiev 	struct dentry *d, *dtx, *drx;
6042be7d22fSVladimir Kondratiev 
60578366f69SVladimir Kondratiev 	d = debugfs_create_dir("ITR_CNT", parent);
6062be7d22fSVladimir Kondratiev 	if (IS_ERR_OR_NULL(d))
6072be7d22fSVladimir Kondratiev 		return -ENODEV;
6082be7d22fSVladimir Kondratiev 
60978366f69SVladimir Kondratiev 	dtx = debugfs_create_dir("TX", d);
61078366f69SVladimir Kondratiev 	drx = debugfs_create_dir("RX", d);
61178366f69SVladimir Kondratiev 	if (IS_ERR_OR_NULL(dtx) || IS_ERR_OR_NULL(drx))
61278366f69SVladimir Kondratiev 		return -ENODEV;
6132be7d22fSVladimir Kondratiev 
61478366f69SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
61578366f69SVladimir Kondratiev 				    lgc_itr_cnt_off);
61678366f69SVladimir Kondratiev 
61778366f69SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, dtx, (void * __force)wil->csr,
61878366f69SVladimir Kondratiev 				    tx_itr_cnt_off);
61978366f69SVladimir Kondratiev 
62078366f69SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, drx, (void * __force)wil->csr,
62178366f69SVladimir Kondratiev 				    rx_itr_cnt_off);
6222be7d22fSVladimir Kondratiev 	return 0;
6232be7d22fSVladimir Kondratiev }
6242be7d22fSVladimir Kondratiev 
6252be7d22fSVladimir Kondratiev static int wil_memread_debugfs_show(struct seq_file *s, void *data)
6262be7d22fSVladimir Kondratiev {
6272be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
62894162666SLazar Alexei 	void __iomem *a;
62994162666SLazar Alexei 	int ret;
63094162666SLazar Alexei 
63194162666SLazar Alexei 	ret = wil_pm_runtime_get(wil);
63294162666SLazar Alexei 	if (ret < 0)
63394162666SLazar Alexei 		return ret;
63494162666SLazar Alexei 
63594162666SLazar Alexei 	a = wmi_buffer(wil, cpu_to_le32(mem_addr));
6362be7d22fSVladimir Kondratiev 
6372be7d22fSVladimir Kondratiev 	if (a)
638b9eeb512SVladimir Kondratiev 		seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, readl(a));
6392be7d22fSVladimir Kondratiev 	else
6402be7d22fSVladimir Kondratiev 		seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
6412be7d22fSVladimir Kondratiev 
64294162666SLazar Alexei 	wil_pm_runtime_put(wil);
64394162666SLazar Alexei 
6442be7d22fSVladimir Kondratiev 	return 0;
6452be7d22fSVladimir Kondratiev }
6462be7d22fSVladimir Kondratiev 
6472be7d22fSVladimir Kondratiev static int wil_memread_seq_open(struct inode *inode, struct file *file)
6482be7d22fSVladimir Kondratiev {
6492be7d22fSVladimir Kondratiev 	return single_open(file, wil_memread_debugfs_show, inode->i_private);
6502be7d22fSVladimir Kondratiev }
6512be7d22fSVladimir Kondratiev 
6522be7d22fSVladimir Kondratiev static const struct file_operations fops_memread = {
6532be7d22fSVladimir Kondratiev 	.open		= wil_memread_seq_open,
6542be7d22fSVladimir Kondratiev 	.release	= single_release,
6552be7d22fSVladimir Kondratiev 	.read		= seq_read,
6562be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
6572be7d22fSVladimir Kondratiev };
6582be7d22fSVladimir Kondratiev 
6592be7d22fSVladimir Kondratiev static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
6602be7d22fSVladimir Kondratiev 				    size_t count, loff_t *ppos)
6612be7d22fSVladimir Kondratiev {
6622be7d22fSVladimir Kondratiev 	enum { max_count = 4096 };
663349214c1SMaya Erez 	struct wil_blob_wrapper *wil_blob = file->private_data;
66494162666SLazar Alexei 	struct wil6210_priv *wil = wil_blob->wil;
6652be7d22fSVladimir Kondratiev 	loff_t pos = *ppos;
666349214c1SMaya Erez 	size_t available = wil_blob->blob.size;
6672be7d22fSVladimir Kondratiev 	void *buf;
6682be7d22fSVladimir Kondratiev 	size_t ret;
66994162666SLazar Alexei 	int rc;
6702be7d22fSVladimir Kondratiev 
671fe9ee51eSMaya Erez 	if (test_bit(wil_status_suspending, wil_blob->wil->status) ||
672fe9ee51eSMaya Erez 	    test_bit(wil_status_suspended, wil_blob->wil->status))
673fe9ee51eSMaya Erez 		return 0;
674fe9ee51eSMaya Erez 
6752be7d22fSVladimir Kondratiev 	if (pos < 0)
6762be7d22fSVladimir Kondratiev 		return -EINVAL;
6772be7d22fSVladimir Kondratiev 
6782be7d22fSVladimir Kondratiev 	if (pos >= available || !count)
6792be7d22fSVladimir Kondratiev 		return 0;
6802be7d22fSVladimir Kondratiev 
6812be7d22fSVladimir Kondratiev 	if (count > available - pos)
6822be7d22fSVladimir Kondratiev 		count = available - pos;
6832be7d22fSVladimir Kondratiev 	if (count > max_count)
6842be7d22fSVladimir Kondratiev 		count = max_count;
6852be7d22fSVladimir Kondratiev 
6862be7d22fSVladimir Kondratiev 	buf = kmalloc(count, GFP_KERNEL);
6872be7d22fSVladimir Kondratiev 	if (!buf)
6882be7d22fSVladimir Kondratiev 		return -ENOMEM;
6892be7d22fSVladimir Kondratiev 
69094162666SLazar Alexei 	rc = wil_pm_runtime_get(wil);
69194162666SLazar Alexei 	if (rc < 0) {
69294162666SLazar Alexei 		kfree(buf);
69394162666SLazar Alexei 		return rc;
69494162666SLazar Alexei 	}
69594162666SLazar Alexei 
696bd50e268SMaya Erez 	wil_memcpy_fromio_32(buf, (const void __iomem *)
697349214c1SMaya Erez 			     wil_blob->blob.data + pos, count);
6982be7d22fSVladimir Kondratiev 
6992be7d22fSVladimir Kondratiev 	ret = copy_to_user(user_buf, buf, count);
70094162666SLazar Alexei 
70194162666SLazar Alexei 	wil_pm_runtime_put(wil);
70294162666SLazar Alexei 
7032be7d22fSVladimir Kondratiev 	kfree(buf);
7042be7d22fSVladimir Kondratiev 	if (ret == count)
7052be7d22fSVladimir Kondratiev 		return -EFAULT;
7062be7d22fSVladimir Kondratiev 
7072be7d22fSVladimir Kondratiev 	count -= ret;
7082be7d22fSVladimir Kondratiev 	*ppos = pos + count;
7092be7d22fSVladimir Kondratiev 
7102be7d22fSVladimir Kondratiev 	return count;
7112be7d22fSVladimir Kondratiev }
7122be7d22fSVladimir Kondratiev 
7132be7d22fSVladimir Kondratiev static const struct file_operations fops_ioblob = {
7142be7d22fSVladimir Kondratiev 	.read =		wil_read_file_ioblob,
71593ecbd64SWei Yongjun 	.open =		simple_open,
7162be7d22fSVladimir Kondratiev 	.llseek =	default_llseek,
7172be7d22fSVladimir Kondratiev };
7182be7d22fSVladimir Kondratiev 
7192be7d22fSVladimir Kondratiev static
7202be7d22fSVladimir Kondratiev struct dentry *wil_debugfs_create_ioblob(const char *name,
7210ecc833bSAl Viro 					 umode_t mode,
7222be7d22fSVladimir Kondratiev 					 struct dentry *parent,
723349214c1SMaya Erez 					 struct wil_blob_wrapper *wil_blob)
7242be7d22fSVladimir Kondratiev {
725349214c1SMaya Erez 	return debugfs_create_file(name, mode, parent, wil_blob, &fops_ioblob);
7262be7d22fSVladimir Kondratiev }
7278fe59627SVladimir Kondratiev 
7282be7d22fSVladimir Kondratiev /*---reset---*/
7292be7d22fSVladimir Kondratiev static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
7302be7d22fSVladimir Kondratiev 				    size_t len, loff_t *ppos)
7312be7d22fSVladimir Kondratiev {
7322be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
733e00243faSLior David 	struct net_device *ndev = wil->main_ndev;
7342be7d22fSVladimir Kondratiev 
7352be7d22fSVladimir Kondratiev 	/**
7362be7d22fSVladimir Kondratiev 	 * BUG:
7372be7d22fSVladimir Kondratiev 	 * this code does NOT sync device state with the rest of system
7382be7d22fSVladimir Kondratiev 	 * use with care, debug only!!!
7392be7d22fSVladimir Kondratiev 	 */
7402be7d22fSVladimir Kondratiev 	rtnl_lock();
7412be7d22fSVladimir Kondratiev 	dev_close(ndev);
7422be7d22fSVladimir Kondratiev 	ndev->flags &= ~IFF_UP;
7432be7d22fSVladimir Kondratiev 	rtnl_unlock();
7442cd0f021SVladimir Kondratiev 	wil_reset(wil, true);
7452be7d22fSVladimir Kondratiev 
7462be7d22fSVladimir Kondratiev 	return len;
7472be7d22fSVladimir Kondratiev }
7482be7d22fSVladimir Kondratiev 
7492be7d22fSVladimir Kondratiev static const struct file_operations fops_reset = {
7502be7d22fSVladimir Kondratiev 	.write = wil_write_file_reset,
75193ecbd64SWei Yongjun 	.open  = simple_open,
7522be7d22fSVladimir Kondratiev };
7538fe59627SVladimir Kondratiev 
7540b39aaf2SVladimir Kondratiev /*---write channel 1..4 to rxon for it, 0 to rxoff---*/
7550b39aaf2SVladimir Kondratiev static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
7560b39aaf2SVladimir Kondratiev 				   size_t len, loff_t *ppos)
7570b39aaf2SVladimir Kondratiev {
7580b39aaf2SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
7590b39aaf2SVladimir Kondratiev 	int rc;
7600b39aaf2SVladimir Kondratiev 	long channel;
7610b39aaf2SVladimir Kondratiev 	bool on;
7620b39aaf2SVladimir Kondratiev 
76316e5c1fcSAl Viro 	char *kbuf = memdup_user_nul(buf, len);
7648fe59627SVladimir Kondratiev 
76516e5c1fcSAl Viro 	if (IS_ERR(kbuf))
76616e5c1fcSAl Viro 		return PTR_ERR(kbuf);
7670b39aaf2SVladimir Kondratiev 	rc = kstrtol(kbuf, 0, &channel);
7680b39aaf2SVladimir Kondratiev 	kfree(kbuf);
7690b39aaf2SVladimir Kondratiev 	if (rc)
7700b39aaf2SVladimir Kondratiev 		return rc;
7710b39aaf2SVladimir Kondratiev 
7720b39aaf2SVladimir Kondratiev 	if ((channel < 0) || (channel > 4)) {
7730b39aaf2SVladimir Kondratiev 		wil_err(wil, "Invalid channel %ld\n", channel);
7740b39aaf2SVladimir Kondratiev 		return -EINVAL;
7750b39aaf2SVladimir Kondratiev 	}
7760b39aaf2SVladimir Kondratiev 	on = !!channel;
7770b39aaf2SVladimir Kondratiev 
7780b39aaf2SVladimir Kondratiev 	if (on) {
7790b39aaf2SVladimir Kondratiev 		rc = wmi_set_channel(wil, (int)channel);
7800b39aaf2SVladimir Kondratiev 		if (rc)
7810b39aaf2SVladimir Kondratiev 			return rc;
7820b39aaf2SVladimir Kondratiev 	}
7830b39aaf2SVladimir Kondratiev 
7840b39aaf2SVladimir Kondratiev 	rc = wmi_rxon(wil, on);
7850b39aaf2SVladimir Kondratiev 	if (rc)
7860b39aaf2SVladimir Kondratiev 		return rc;
7870b39aaf2SVladimir Kondratiev 
7880b39aaf2SVladimir Kondratiev 	return len;
7890b39aaf2SVladimir Kondratiev }
7900b39aaf2SVladimir Kondratiev 
7910b39aaf2SVladimir Kondratiev static const struct file_operations fops_rxon = {
7920b39aaf2SVladimir Kondratiev 	.write = wil_write_file_rxon,
7930b39aaf2SVladimir Kondratiev 	.open  = simple_open,
7940b39aaf2SVladimir Kondratiev };
7958fe59627SVladimir Kondratiev 
79649cb5dfbSVladimir Kondratiev /* block ack control, write:
79749cb5dfbSVladimir Kondratiev  * - "add <ringid> <agg_size> <timeout>" to trigger ADDBA
79849cb5dfbSVladimir Kondratiev  * - "del_tx <ringid> <reason>" to trigger DELBA for Tx side
79949cb5dfbSVladimir Kondratiev  * - "del_rx <CID> <TID> <reason>" to trigger DELBA for Rx side
8003277213fSVladimir Kondratiev  */
80149cb5dfbSVladimir Kondratiev static ssize_t wil_write_back(struct file *file, const char __user *buf,
8023277213fSVladimir Kondratiev 			      size_t len, loff_t *ppos)
8033277213fSVladimir Kondratiev {
8043277213fSVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
8053277213fSVladimir Kondratiev 	int rc;
8063277213fSVladimir Kondratiev 	char *kbuf = kmalloc(len + 1, GFP_KERNEL);
8072a19f776SColin Ian King 	char cmd[9];
80849cb5dfbSVladimir Kondratiev 	int p1, p2, p3;
8093277213fSVladimir Kondratiev 
8103277213fSVladimir Kondratiev 	if (!kbuf)
8113277213fSVladimir Kondratiev 		return -ENOMEM;
8123277213fSVladimir Kondratiev 
8133277213fSVladimir Kondratiev 	rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
8143277213fSVladimir Kondratiev 	if (rc != len) {
8153277213fSVladimir Kondratiev 		kfree(kbuf);
8163277213fSVladimir Kondratiev 		return rc >= 0 ? -EIO : rc;
8173277213fSVladimir Kondratiev 	}
8183277213fSVladimir Kondratiev 
8193277213fSVladimir Kondratiev 	kbuf[len] = '\0';
82049cb5dfbSVladimir Kondratiev 	rc = sscanf(kbuf, "%8s %d %d %d", cmd, &p1, &p2, &p3);
8213277213fSVladimir Kondratiev 	kfree(kbuf);
8223277213fSVladimir Kondratiev 
82349cb5dfbSVladimir Kondratiev 	if (rc < 0)
8243277213fSVladimir Kondratiev 		return rc;
82549cb5dfbSVladimir Kondratiev 	if (rc < 2)
8263277213fSVladimir Kondratiev 		return -EINVAL;
8273277213fSVladimir Kondratiev 
828e00243faSLior David 	if ((strcmp(cmd, "add") == 0) ||
829e00243faSLior David 	    (strcmp(cmd, "del_tx") == 0)) {
83010590c6aSGidon Studinski 		struct wil_ring_tx_data *txdata;
831e00243faSLior David 
832e00243faSLior David 		if (p1 < 0 || p1 >= WIL6210_MAX_TX_RINGS) {
833e00243faSLior David 			wil_err(wil, "BACK: invalid ring id %d\n", p1);
834e00243faSLior David 			return -EINVAL;
835e00243faSLior David 		}
83610590c6aSGidon Studinski 		txdata = &wil->ring_tx_data[p1];
837e00243faSLior David 		if (strcmp(cmd, "add") == 0) {
83849cb5dfbSVladimir Kondratiev 			if (rc < 3) {
83949cb5dfbSVladimir Kondratiev 				wil_err(wil, "BACK: add require at least 2 params\n");
84049cb5dfbSVladimir Kondratiev 				return -EINVAL;
84149cb5dfbSVladimir Kondratiev 			}
84249cb5dfbSVladimir Kondratiev 			if (rc < 4)
84349cb5dfbSVladimir Kondratiev 				p3 = 0;
844e00243faSLior David 			wmi_addba(wil, txdata->mid, p1, p2, p3);
845e00243faSLior David 		} else {
84649cb5dfbSVladimir Kondratiev 			if (rc < 3)
84749cb5dfbSVladimir Kondratiev 				p2 = WLAN_REASON_QSTA_LEAVE_QBSS;
848e00243faSLior David 			wmi_delba_tx(wil, txdata->mid, p1, p2);
849e00243faSLior David 		}
850e00243faSLior David 	} else if (strcmp(cmd, "del_rx") == 0) {
851e00243faSLior David 		struct wil_sta_info *sta;
852e00243faSLior David 
85349cb5dfbSVladimir Kondratiev 		if (rc < 3) {
85449cb5dfbSVladimir Kondratiev 			wil_err(wil,
85549cb5dfbSVladimir Kondratiev 				"BACK: del_rx require at least 2 params\n");
85649cb5dfbSVladimir Kondratiev 			return -EINVAL;
85749cb5dfbSVladimir Kondratiev 		}
858e00243faSLior David 		if (p1 < 0 || p1 >= WIL6210_MAX_CID) {
859e00243faSLior David 			wil_err(wil, "BACK: invalid CID %d\n", p1);
860e00243faSLior David 			return -EINVAL;
861e00243faSLior David 		}
86249cb5dfbSVladimir Kondratiev 		if (rc < 4)
86349cb5dfbSVladimir Kondratiev 			p3 = WLAN_REASON_QSTA_LEAVE_QBSS;
864e00243faSLior David 		sta = &wil->sta[p1];
865e00243faSLior David 		wmi_delba_rx(wil, sta->mid, mk_cidxtid(p1, p2), p3);
86649cb5dfbSVladimir Kondratiev 	} else {
86749cb5dfbSVladimir Kondratiev 		wil_err(wil, "BACK: Unrecognized command \"%s\"\n", cmd);
86849cb5dfbSVladimir Kondratiev 		return -EINVAL;
86949cb5dfbSVladimir Kondratiev 	}
8703277213fSVladimir Kondratiev 
8713277213fSVladimir Kondratiev 	return len;
8723277213fSVladimir Kondratiev }
8733277213fSVladimir Kondratiev 
87449cb5dfbSVladimir Kondratiev static ssize_t wil_read_back(struct file *file, char __user *user_buf,
87549cb5dfbSVladimir Kondratiev 			     size_t count, loff_t *ppos)
87649cb5dfbSVladimir Kondratiev {
87749cb5dfbSVladimir Kondratiev 	static const char text[] = "block ack control, write:\n"
87849cb5dfbSVladimir Kondratiev 	" - \"add <ringid> <agg_size> <timeout>\" to trigger ADDBA\n"
87949cb5dfbSVladimir Kondratiev 	"If missing, <timeout> defaults to 0\n"
88049cb5dfbSVladimir Kondratiev 	" - \"del_tx <ringid> <reason>\" to trigger DELBA for Tx side\n"
88149cb5dfbSVladimir Kondratiev 	" - \"del_rx <CID> <TID> <reason>\" to trigger DELBA for Rx side\n"
88249cb5dfbSVladimir Kondratiev 	"If missing, <reason> set to \"STA_LEAVING\" (36)\n";
88349cb5dfbSVladimir Kondratiev 
88449cb5dfbSVladimir Kondratiev 	return simple_read_from_buffer(user_buf, count, ppos, text,
88549cb5dfbSVladimir Kondratiev 				       sizeof(text));
88649cb5dfbSVladimir Kondratiev }
88749cb5dfbSVladimir Kondratiev 
88849cb5dfbSVladimir Kondratiev static const struct file_operations fops_back = {
88949cb5dfbSVladimir Kondratiev 	.read = wil_read_back,
89049cb5dfbSVladimir Kondratiev 	.write = wil_write_back,
8913277213fSVladimir Kondratiev 	.open  = simple_open,
8923277213fSVladimir Kondratiev };
8933277213fSVladimir Kondratiev 
894dc16427bSVladimir Kondratiev /* pmc control, write:
895dc16427bSVladimir Kondratiev  * - "alloc <num descriptors> <descriptor_size>" to allocate PMC
896dc16427bSVladimir Kondratiev  * - "free" to release memory allocated for PMC
897dc16427bSVladimir Kondratiev  */
898dc16427bSVladimir Kondratiev static ssize_t wil_write_pmccfg(struct file *file, const char __user *buf,
899dc16427bSVladimir Kondratiev 				size_t len, loff_t *ppos)
900dc16427bSVladimir Kondratiev {
901dc16427bSVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
902dc16427bSVladimir Kondratiev 	int rc;
903dc16427bSVladimir Kondratiev 	char *kbuf = kmalloc(len + 1, GFP_KERNEL);
904dc16427bSVladimir Kondratiev 	char cmd[9];
905dc16427bSVladimir Kondratiev 	int num_descs, desc_size;
906dc16427bSVladimir Kondratiev 
907dc16427bSVladimir Kondratiev 	if (!kbuf)
908dc16427bSVladimir Kondratiev 		return -ENOMEM;
909dc16427bSVladimir Kondratiev 
910dc16427bSVladimir Kondratiev 	rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
911dc16427bSVladimir Kondratiev 	if (rc != len) {
912dc16427bSVladimir Kondratiev 		kfree(kbuf);
913dc16427bSVladimir Kondratiev 		return rc >= 0 ? -EIO : rc;
914dc16427bSVladimir Kondratiev 	}
915dc16427bSVladimir Kondratiev 
916dc16427bSVladimir Kondratiev 	kbuf[len] = '\0';
917dc16427bSVladimir Kondratiev 	rc = sscanf(kbuf, "%8s %d %d", cmd, &num_descs, &desc_size);
918dc16427bSVladimir Kondratiev 	kfree(kbuf);
919dc16427bSVladimir Kondratiev 
920dc16427bSVladimir Kondratiev 	if (rc < 0)
921dc16427bSVladimir Kondratiev 		return rc;
922dc16427bSVladimir Kondratiev 
923dc16427bSVladimir Kondratiev 	if (rc < 1) {
924dc16427bSVladimir Kondratiev 		wil_err(wil, "pmccfg: no params given\n");
925dc16427bSVladimir Kondratiev 		return -EINVAL;
926dc16427bSVladimir Kondratiev 	}
927dc16427bSVladimir Kondratiev 
928dc16427bSVladimir Kondratiev 	if (0 == strcmp(cmd, "alloc")) {
929dc16427bSVladimir Kondratiev 		if (rc != 3) {
930dc16427bSVladimir Kondratiev 			wil_err(wil, "pmccfg: alloc requires 2 params\n");
931dc16427bSVladimir Kondratiev 			return -EINVAL;
932dc16427bSVladimir Kondratiev 		}
933dc16427bSVladimir Kondratiev 		wil_pmc_alloc(wil, num_descs, desc_size);
934dc16427bSVladimir Kondratiev 	} else if (0 == strcmp(cmd, "free")) {
935dc16427bSVladimir Kondratiev 		if (rc != 1) {
936dc16427bSVladimir Kondratiev 			wil_err(wil, "pmccfg: free does not have any params\n");
937dc16427bSVladimir Kondratiev 			return -EINVAL;
938dc16427bSVladimir Kondratiev 		}
939dc16427bSVladimir Kondratiev 		wil_pmc_free(wil, true);
940dc16427bSVladimir Kondratiev 	} else {
941dc16427bSVladimir Kondratiev 		wil_err(wil, "pmccfg: Unrecognized command \"%s\"\n", cmd);
942dc16427bSVladimir Kondratiev 		return -EINVAL;
943dc16427bSVladimir Kondratiev 	}
944dc16427bSVladimir Kondratiev 
945dc16427bSVladimir Kondratiev 	return len;
946dc16427bSVladimir Kondratiev }
947dc16427bSVladimir Kondratiev 
948dc16427bSVladimir Kondratiev static ssize_t wil_read_pmccfg(struct file *file, char __user *user_buf,
949dc16427bSVladimir Kondratiev 			       size_t count, loff_t *ppos)
950dc16427bSVladimir Kondratiev {
951dc16427bSVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
952dc16427bSVladimir Kondratiev 	char text[256];
953dc16427bSVladimir Kondratiev 	char help[] = "pmc control, write:\n"
954dc16427bSVladimir Kondratiev 	" - \"alloc <num descriptors> <descriptor_size>\" to allocate pmc\n"
955dc16427bSVladimir Kondratiev 	" - \"free\" to free memory allocated for pmc\n";
956dc16427bSVladimir Kondratiev 
957dc16427bSVladimir Kondratiev 	sprintf(text, "Last command status: %d\n\n%s",
958dc16427bSVladimir Kondratiev 		wil_pmc_last_cmd_status(wil),
959dc16427bSVladimir Kondratiev 		help);
960dc16427bSVladimir Kondratiev 
961dc16427bSVladimir Kondratiev 	return simple_read_from_buffer(user_buf, count, ppos, text,
962dc16427bSVladimir Kondratiev 				       strlen(text) + 1);
963dc16427bSVladimir Kondratiev }
964dc16427bSVladimir Kondratiev 
965dc16427bSVladimir Kondratiev static const struct file_operations fops_pmccfg = {
966dc16427bSVladimir Kondratiev 	.read = wil_read_pmccfg,
967dc16427bSVladimir Kondratiev 	.write = wil_write_pmccfg,
968dc16427bSVladimir Kondratiev 	.open  = simple_open,
969dc16427bSVladimir Kondratiev };
970dc16427bSVladimir Kondratiev 
971dc16427bSVladimir Kondratiev static const struct file_operations fops_pmcdata = {
972dc16427bSVladimir Kondratiev 	.open		= simple_open,
973dc16427bSVladimir Kondratiev 	.read		= wil_pmc_read,
974dc16427bSVladimir Kondratiev 	.llseek		= wil_pmc_llseek,
975dc16427bSVladimir Kondratiev };
976dc16427bSVladimir Kondratiev 
9770b39aaf2SVladimir Kondratiev /*---tx_mgmt---*/
9780b39aaf2SVladimir Kondratiev /* Write mgmt frame to this file to send it */
9790b39aaf2SVladimir Kondratiev static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
9800b39aaf2SVladimir Kondratiev 				     size_t len, loff_t *ppos)
9810b39aaf2SVladimir Kondratiev {
9820b39aaf2SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
9830b39aaf2SVladimir Kondratiev 	struct wiphy *wiphy = wil_to_wiphy(wil);
984e00243faSLior David 	struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr;
9850b39aaf2SVladimir Kondratiev 	struct cfg80211_mgmt_tx_params params;
9860b39aaf2SVladimir Kondratiev 	int rc;
9879a492909SGeliang Tang 	void *frame;
9888fe59627SVladimir Kondratiev 
9896641525cSHamad Kadmany 	if (!len)
9906641525cSHamad Kadmany 		return -EINVAL;
9916641525cSHamad Kadmany 
9929a492909SGeliang Tang 	frame = memdup_user(buf, len);
9939a492909SGeliang Tang 	if (IS_ERR(frame))
9949a492909SGeliang Tang 		return PTR_ERR(frame);
9950b39aaf2SVladimir Kondratiev 
9960b39aaf2SVladimir Kondratiev 	params.buf = frame;
9970b39aaf2SVladimir Kondratiev 	params.len = len;
9980b39aaf2SVladimir Kondratiev 
9990b39aaf2SVladimir Kondratiev 	rc = wil_cfg80211_mgmt_tx(wiphy, wdev, &params, NULL);
10000b39aaf2SVladimir Kondratiev 
10010b39aaf2SVladimir Kondratiev 	kfree(frame);
1002af3db60aSLazar Alexei 	wil_info(wil, "-> %d\n", rc);
10030b39aaf2SVladimir Kondratiev 
10040b39aaf2SVladimir Kondratiev 	return len;
10050b39aaf2SVladimir Kondratiev }
10060b39aaf2SVladimir Kondratiev 
10070b39aaf2SVladimir Kondratiev static const struct file_operations fops_txmgmt = {
10080b39aaf2SVladimir Kondratiev 	.write = wil_write_file_txmgmt,
10090b39aaf2SVladimir Kondratiev 	.open  = simple_open,
10100b39aaf2SVladimir Kondratiev };
10112be7d22fSVladimir Kondratiev 
1012ff974e40SVladimir Kondratiev /* Write WMI command (w/o mbox header) to this file to send it
1013ff974e40SVladimir Kondratiev  * WMI starts from wil6210_mbox_hdr_wmi header
1014ff974e40SVladimir Kondratiev  */
1015ff974e40SVladimir Kondratiev static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
1016ff974e40SVladimir Kondratiev 				  size_t len, loff_t *ppos)
1017ff974e40SVladimir Kondratiev {
1018ff974e40SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
1019e00243faSLior David 	struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
1020b874ddecSLior David 	struct wmi_cmd_hdr *wmi;
1021ff974e40SVladimir Kondratiev 	void *cmd;
1022b874ddecSLior David 	int cmdlen = len - sizeof(struct wmi_cmd_hdr);
1023ff974e40SVladimir Kondratiev 	u16 cmdid;
1024ff974e40SVladimir Kondratiev 	int rc, rc1;
1025ff974e40SVladimir Kondratiev 
102669218a48SLior David 	if (cmdlen < 0)
1027ff974e40SVladimir Kondratiev 		return -EINVAL;
1028ff974e40SVladimir Kondratiev 
1029ff974e40SVladimir Kondratiev 	wmi = kmalloc(len, GFP_KERNEL);
1030ff974e40SVladimir Kondratiev 	if (!wmi)
1031ff974e40SVladimir Kondratiev 		return -ENOMEM;
1032ff974e40SVladimir Kondratiev 
1033ff974e40SVladimir Kondratiev 	rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
10348e09b7d2SLino Sanfilippo 	if (rc < 0) {
10358e09b7d2SLino Sanfilippo 		kfree(wmi);
1036ff974e40SVladimir Kondratiev 		return rc;
10378e09b7d2SLino Sanfilippo 	}
1038ff974e40SVladimir Kondratiev 
103969218a48SLior David 	cmd = (cmdlen > 0) ? &wmi[1] : NULL;
1040b874ddecSLior David 	cmdid = le16_to_cpu(wmi->command_id);
1041ff974e40SVladimir Kondratiev 
1042e00243faSLior David 	rc1 = wmi_send(wil, cmdid, vif->mid, cmd, cmdlen);
1043ff974e40SVladimir Kondratiev 	kfree(wmi);
1044ff974e40SVladimir Kondratiev 
1045af3db60aSLazar Alexei 	wil_info(wil, "0x%04x[%d] -> %d\n", cmdid, cmdlen, rc1);
1046ff974e40SVladimir Kondratiev 
1047ff974e40SVladimir Kondratiev 	return rc;
1048ff974e40SVladimir Kondratiev }
1049ff974e40SVladimir Kondratiev 
1050ff974e40SVladimir Kondratiev static const struct file_operations fops_wmi = {
1051ff974e40SVladimir Kondratiev 	.write = wil_write_file_wmi,
1052ff974e40SVladimir Kondratiev 	.open  = simple_open,
1053ff974e40SVladimir Kondratiev };
1054ff974e40SVladimir Kondratiev 
1055c236658fSVladimir Kondratiev static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
1056c236658fSVladimir Kondratiev {
1057c236658fSVladimir Kondratiev 	int i = 0;
1058c236658fSVladimir Kondratiev 	int len = skb_headlen(skb);
1059c236658fSVladimir Kondratiev 	void *p = skb->data;
1060c236658fSVladimir Kondratiev 	int nr_frags = skb_shinfo(skb)->nr_frags;
1061c236658fSVladimir Kondratiev 
1062c236658fSVladimir Kondratiev 	seq_printf(s, "    len = %d\n", len);
1063c236658fSVladimir Kondratiev 	wil_seq_hexdump(s, p, len, "      : ");
1064c236658fSVladimir Kondratiev 
1065c236658fSVladimir Kondratiev 	if (nr_frags) {
1066c236658fSVladimir Kondratiev 		seq_printf(s, "    nr_frags = %d\n", nr_frags);
1067c236658fSVladimir Kondratiev 		for (i = 0; i < nr_frags; i++) {
1068c236658fSVladimir Kondratiev 			const struct skb_frag_struct *frag =
1069c236658fSVladimir Kondratiev 					&skb_shinfo(skb)->frags[i];
1070c236658fSVladimir Kondratiev 
1071c236658fSVladimir Kondratiev 			len = skb_frag_size(frag);
1072c236658fSVladimir Kondratiev 			p = skb_frag_address_safe(frag);
1073c236658fSVladimir Kondratiev 			seq_printf(s, "    [%2d] : len = %d\n", i, len);
1074c236658fSVladimir Kondratiev 			wil_seq_hexdump(s, p, len, "      : ");
1075c236658fSVladimir Kondratiev 		}
1076c236658fSVladimir Kondratiev 	}
1077c236658fSVladimir Kondratiev }
1078c236658fSVladimir Kondratiev 
10793a85543eSVladimir Kondratiev /*---------Tx/Rx descriptor------------*/
10802be7d22fSVladimir Kondratiev static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
10812be7d22fSVladimir Kondratiev {
10822be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
108310590c6aSGidon Studinski 	struct wil_ring *ring;
1084d98b8539SMaya Erez 	bool tx;
1085d98b8539SMaya Erez 	int ring_idx = dbg_ring_index;
1086d98b8539SMaya Erez 	int txdesc_idx = dbg_txdesc_index;
1087d98b8539SMaya Erez 	volatile struct vring_tx_desc *d;
1088d98b8539SMaya Erez 	volatile u32 *u;
1089d98b8539SMaya Erez 	struct sk_buff *skb;
10908fe59627SVladimir Kondratiev 
1091d98b8539SMaya Erez 	if (wil->use_enhanced_dma_hw) {
1092d98b8539SMaya Erez 		/* RX ring index == 0 */
1093d98b8539SMaya Erez 		if (ring_idx >= WIL6210_MAX_TX_RINGS) {
1094d98b8539SMaya Erez 			seq_printf(s, "invalid ring index %d\n", ring_idx);
1095d98b8539SMaya Erez 			return 0;
1096d98b8539SMaya Erez 		}
1097d98b8539SMaya Erez 		tx = ring_idx > 0; /* desc ring 0 is reserved for RX */
1098d98b8539SMaya Erez 	} else {
1099d98b8539SMaya Erez 		/* RX ring index == WIL6210_MAX_TX_RINGS */
1100d98b8539SMaya Erez 		if (ring_idx > WIL6210_MAX_TX_RINGS) {
1101d98b8539SMaya Erez 			seq_printf(s, "invalid ring index %d\n", ring_idx);
1102d98b8539SMaya Erez 			return 0;
1103d98b8539SMaya Erez 		}
1104d98b8539SMaya Erez 		tx = (ring_idx < WIL6210_MAX_TX_RINGS);
1105d98b8539SMaya Erez 	}
1106d98b8539SMaya Erez 
1107d98b8539SMaya Erez 	ring = tx ? &wil->ring_tx[ring_idx] : &wil->ring_rx;
11082be7d22fSVladimir Kondratiev 
110910590c6aSGidon Studinski 	if (!ring->va) {
1110af31cb5aSVladimir Kondratiev 		if (tx)
1111d98b8539SMaya Erez 			seq_printf(s, "No Tx[%2d] RING\n", ring_idx);
11123a85543eSVladimir Kondratiev 		else
1113d98b8539SMaya Erez 			seq_puts(s, "No Rx RING\n");
11142be7d22fSVladimir Kondratiev 		return 0;
11152be7d22fSVladimir Kondratiev 	}
11162be7d22fSVladimir Kondratiev 
1117d98b8539SMaya Erez 	if (txdesc_idx >= ring->size) {
1118d98b8539SMaya Erez 		if (tx)
1119d98b8539SMaya Erez 			seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
1120d98b8539SMaya Erez 				   ring_idx, txdesc_idx, ring->size);
1121d98b8539SMaya Erez 		else
1122d98b8539SMaya Erez 			seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
1123d98b8539SMaya Erez 				   txdesc_idx, ring->size);
1124d98b8539SMaya Erez 		return 0;
1125d98b8539SMaya Erez 	}
1126d98b8539SMaya Erez 
11273a85543eSVladimir Kondratiev 	/* use struct vring_tx_desc for Rx as well,
11283a85543eSVladimir Kondratiev 	 * only field used, .dma.length, is the same
11293a85543eSVladimir Kondratiev 	 */
1130d98b8539SMaya Erez 	d = &ring->va[txdesc_idx].tx.legacy;
1131d98b8539SMaya Erez 	u = (volatile u32 *)d;
1132d98b8539SMaya Erez 	skb = NULL;
11332be7d22fSVladimir Kondratiev 
1134d98b8539SMaya Erez 	if (wil->use_enhanced_dma_hw) {
1135d98b8539SMaya Erez 		if (tx) {
1136d98b8539SMaya Erez 			skb = ring->ctx[txdesc_idx].skb;
1137d98b8539SMaya Erez 		} else {
1138d98b8539SMaya Erez 			struct wil_rx_enhanced_desc *rx_d =
1139d98b8539SMaya Erez 				(struct wil_rx_enhanced_desc *)
1140d98b8539SMaya Erez 				&ring->va[txdesc_idx].rx.enhanced;
1141d98b8539SMaya Erez 			u16 buff_id = le16_to_cpu(rx_d->mac.buff_id);
1142d98b8539SMaya Erez 
1143d98b8539SMaya Erez 			if (!wil_val_in_range(buff_id, 0,
1144d98b8539SMaya Erez 					      wil->rx_buff_mgmt.size)) {
1145d98b8539SMaya Erez 				seq_printf(s, "invalid buff_id %d\n", buff_id);
1146d98b8539SMaya Erez 				return 0;
1147d98b8539SMaya Erez 			}
1148d98b8539SMaya Erez 			skb = wil->rx_buff_mgmt.buff_arr[buff_id].skb;
1149d98b8539SMaya Erez 		}
1150d98b8539SMaya Erez 	} else {
1151d98b8539SMaya Erez 		skb = ring->ctx[txdesc_idx].skb;
1152d98b8539SMaya Erez 	}
1153af31cb5aSVladimir Kondratiev 	if (tx)
1154d98b8539SMaya Erez 		seq_printf(s, "Tx[%2d][%3d] = {\n", ring_idx,
1155d98b8539SMaya Erez 			   txdesc_idx);
11563a85543eSVladimir Kondratiev 	else
1157d98b8539SMaya Erez 		seq_printf(s, "Rx[%3d] = {\n", txdesc_idx);
11582be7d22fSVladimir Kondratiev 	seq_printf(s, "  MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
11592be7d22fSVladimir Kondratiev 		   u[0], u[1], u[2], u[3]);
11602be7d22fSVladimir Kondratiev 	seq_printf(s, "  DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
11612be7d22fSVladimir Kondratiev 		   u[4], u[5], u[6], u[7]);
116239c52ee8SVladimir Kondratiev 	seq_printf(s, "  SKB = 0x%p\n", skb);
11632be7d22fSVladimir Kondratiev 
11642be7d22fSVladimir Kondratiev 	if (skb) {
1165c236658fSVladimir Kondratiev 		skb_get(skb);
1166c236658fSVladimir Kondratiev 		wil_seq_print_skb(s, skb);
1167c236658fSVladimir Kondratiev 		kfree_skb(skb);
11682be7d22fSVladimir Kondratiev 	}
11698fe59627SVladimir Kondratiev 	seq_puts(s, "}\n");
11702be7d22fSVladimir Kondratiev 
11712be7d22fSVladimir Kondratiev 	return 0;
11722be7d22fSVladimir Kondratiev }
11732be7d22fSVladimir Kondratiev 
11742be7d22fSVladimir Kondratiev static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
11752be7d22fSVladimir Kondratiev {
11762be7d22fSVladimir Kondratiev 	return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
11772be7d22fSVladimir Kondratiev }
11782be7d22fSVladimir Kondratiev 
11792be7d22fSVladimir Kondratiev static const struct file_operations fops_txdesc = {
11802be7d22fSVladimir Kondratiev 	.open		= wil_txdesc_seq_open,
11812be7d22fSVladimir Kondratiev 	.release	= single_release,
11822be7d22fSVladimir Kondratiev 	.read		= seq_read,
11832be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
11842be7d22fSVladimir Kondratiev };
11852be7d22fSVladimir Kondratiev 
1186d98b8539SMaya Erez /*---------Tx/Rx status message------------*/
1187d98b8539SMaya Erez static int wil_status_msg_debugfs_show(struct seq_file *s, void *data)
1188d98b8539SMaya Erez {
1189d98b8539SMaya Erez 	struct wil6210_priv *wil = s->private;
1190d98b8539SMaya Erez 	int sring_idx = dbg_sring_index;
1191d98b8539SMaya Erez 	struct wil_status_ring *sring;
1192d98b8539SMaya Erez 	bool tx = sring_idx == wil->tx_sring_idx ? 1 : 0;
1193d98b8539SMaya Erez 	u32 status_msg_idx = dbg_status_msg_index;
1194d98b8539SMaya Erez 	u32 *u;
1195d98b8539SMaya Erez 
1196d98b8539SMaya Erez 	if (sring_idx >= WIL6210_MAX_STATUS_RINGS) {
1197d98b8539SMaya Erez 		seq_printf(s, "invalid status ring index %d\n", sring_idx);
1198d98b8539SMaya Erez 		return 0;
1199d98b8539SMaya Erez 	}
1200d98b8539SMaya Erez 
1201d98b8539SMaya Erez 	sring = &wil->srings[sring_idx];
1202d98b8539SMaya Erez 
1203d98b8539SMaya Erez 	if (!sring->va) {
1204d98b8539SMaya Erez 		seq_printf(s, "No %cX status ring\n", tx ? 'T' : 'R');
1205d98b8539SMaya Erez 		return 0;
1206d98b8539SMaya Erez 	}
1207d98b8539SMaya Erez 
1208d98b8539SMaya Erez 	if (status_msg_idx >= sring->size) {
1209d98b8539SMaya Erez 		seq_printf(s, "%cxDesc index (%d) >= size (%d)\n",
1210d98b8539SMaya Erez 			   tx ? 'T' : 'R', status_msg_idx, sring->size);
1211d98b8539SMaya Erez 		return 0;
1212d98b8539SMaya Erez 	}
1213d98b8539SMaya Erez 
1214d98b8539SMaya Erez 	u = sring->va + (sring->elem_size * status_msg_idx);
1215d98b8539SMaya Erez 
1216d98b8539SMaya Erez 	seq_printf(s, "%cx[%d][%3d] = {\n",
1217d98b8539SMaya Erez 		   tx ? 'T' : 'R', sring_idx, status_msg_idx);
1218d98b8539SMaya Erez 
1219d98b8539SMaya Erez 	seq_printf(s, "  0x%08x 0x%08x 0x%08x 0x%08x\n",
1220d98b8539SMaya Erez 		   u[0], u[1], u[2], u[3]);
1221d98b8539SMaya Erez 	if (!tx && !wil->use_compressed_rx_status)
1222d98b8539SMaya Erez 		seq_printf(s, "  0x%08x 0x%08x 0x%08x 0x%08x\n",
1223d98b8539SMaya Erez 			   u[4], u[5], u[6], u[7]);
1224d98b8539SMaya Erez 
1225d98b8539SMaya Erez 	seq_puts(s, "}\n");
1226d98b8539SMaya Erez 
1227d98b8539SMaya Erez 	return 0;
1228d98b8539SMaya Erez }
1229d98b8539SMaya Erez 
1230d98b8539SMaya Erez static int wil_status_msg_seq_open(struct inode *inode, struct file *file)
1231d98b8539SMaya Erez {
1232d98b8539SMaya Erez 	return single_open(file, wil_status_msg_debugfs_show,
1233d98b8539SMaya Erez 			   inode->i_private);
1234d98b8539SMaya Erez }
1235d98b8539SMaya Erez 
1236d98b8539SMaya Erez static const struct file_operations fops_status_msg = {
1237d98b8539SMaya Erez 	.open		= wil_status_msg_seq_open,
1238d98b8539SMaya Erez 	.release	= single_release,
1239d98b8539SMaya Erez 	.read		= seq_read,
1240d98b8539SMaya Erez 	.llseek		= seq_lseek,
1241d98b8539SMaya Erez };
1242d98b8539SMaya Erez 
1243d98b8539SMaya Erez static int wil_print_rx_buff(struct seq_file *s, struct list_head *lh)
1244d98b8539SMaya Erez {
1245d98b8539SMaya Erez 	struct wil_rx_buff *it;
1246d98b8539SMaya Erez 	int i = 0;
1247d98b8539SMaya Erez 
1248d98b8539SMaya Erez 	list_for_each_entry(it, lh, list) {
1249d98b8539SMaya Erez 		if ((i % 16) == 0 && i != 0)
1250d98b8539SMaya Erez 			seq_puts(s, "\n    ");
1251d98b8539SMaya Erez 		seq_printf(s, "[%4d] ", it->id);
1252d98b8539SMaya Erez 		i++;
1253d98b8539SMaya Erez 	}
1254d98b8539SMaya Erez 	seq_printf(s, "\nNumber of buffers: %u\n", i);
1255d98b8539SMaya Erez 
1256d98b8539SMaya Erez 	return i;
1257d98b8539SMaya Erez }
1258d98b8539SMaya Erez 
1259d98b8539SMaya Erez static int wil_rx_buff_mgmt_debugfs_show(struct seq_file *s, void *data)
1260d98b8539SMaya Erez {
1261d98b8539SMaya Erez 	struct wil6210_priv *wil = s->private;
1262d98b8539SMaya Erez 	struct wil_rx_buff_mgmt *rbm = &wil->rx_buff_mgmt;
1263d98b8539SMaya Erez 	int num_active;
1264d98b8539SMaya Erez 	int num_free;
1265d98b8539SMaya Erez 
1266d98b8539SMaya Erez 	seq_printf(s, "  size = %zu\n", rbm->size);
1267d98b8539SMaya Erez 	seq_printf(s, "  free_list_empty_cnt = %lu\n",
1268d98b8539SMaya Erez 		   rbm->free_list_empty_cnt);
1269d98b8539SMaya Erez 
1270d98b8539SMaya Erez 	/* Print active list */
1271d98b8539SMaya Erez 	seq_puts(s, "  Active list:\n");
1272d98b8539SMaya Erez 	num_active = wil_print_rx_buff(s, &rbm->active);
1273d98b8539SMaya Erez 	seq_puts(s, "\n  Free list:\n");
1274d98b8539SMaya Erez 	num_free = wil_print_rx_buff(s, &rbm->free);
1275d98b8539SMaya Erez 
1276d98b8539SMaya Erez 	seq_printf(s, "  Total number of buffers: %u\n",
1277d98b8539SMaya Erez 		   num_active + num_free);
1278d98b8539SMaya Erez 
1279d98b8539SMaya Erez 	return 0;
1280d98b8539SMaya Erez }
1281d98b8539SMaya Erez 
1282d98b8539SMaya Erez static int wil_rx_buff_mgmt_seq_open(struct inode *inode, struct file *file)
1283d98b8539SMaya Erez {
1284d98b8539SMaya Erez 	return single_open(file, wil_rx_buff_mgmt_debugfs_show,
1285d98b8539SMaya Erez 			   inode->i_private);
1286d98b8539SMaya Erez }
1287d98b8539SMaya Erez 
1288d98b8539SMaya Erez static const struct file_operations fops_rx_buff_mgmt = {
1289d98b8539SMaya Erez 	.open		= wil_rx_buff_mgmt_seq_open,
1290d98b8539SMaya Erez 	.release	= single_release,
1291d98b8539SMaya Erez 	.read		= seq_read,
1292d98b8539SMaya Erez 	.llseek		= seq_lseek,
1293d98b8539SMaya Erez };
1294d98b8539SMaya Erez 
12952be7d22fSVladimir Kondratiev /*---------beamforming------------*/
129636345ac3SVladimir Kondratiev static char *wil_bfstatus_str(u32 status)
129736345ac3SVladimir Kondratiev {
129836345ac3SVladimir Kondratiev 	switch (status) {
129936345ac3SVladimir Kondratiev 	case 0:
130036345ac3SVladimir Kondratiev 		return "Failed";
130136345ac3SVladimir Kondratiev 	case 1:
130236345ac3SVladimir Kondratiev 		return "OK";
130336345ac3SVladimir Kondratiev 	case 2:
130436345ac3SVladimir Kondratiev 		return "Retrying";
130536345ac3SVladimir Kondratiev 	default:
130636345ac3SVladimir Kondratiev 		return "??";
130736345ac3SVladimir Kondratiev 	}
130836345ac3SVladimir Kondratiev }
130936345ac3SVladimir Kondratiev 
131036345ac3SVladimir Kondratiev static bool is_all_zeros(void * const x_, size_t sz)
131136345ac3SVladimir Kondratiev {
131236345ac3SVladimir Kondratiev 	/* if reply is all-0, ignore this CID */
131336345ac3SVladimir Kondratiev 	u32 *x = x_;
131436345ac3SVladimir Kondratiev 	int n;
131536345ac3SVladimir Kondratiev 
131636345ac3SVladimir Kondratiev 	for (n = 0; n < sz / sizeof(*x); n++)
131736345ac3SVladimir Kondratiev 		if (x[n])
131836345ac3SVladimir Kondratiev 			return false;
131936345ac3SVladimir Kondratiev 
132036345ac3SVladimir Kondratiev 	return true;
132136345ac3SVladimir Kondratiev }
132236345ac3SVladimir Kondratiev 
13232be7d22fSVladimir Kondratiev static int wil_bf_debugfs_show(struct seq_file *s, void *data)
13242be7d22fSVladimir Kondratiev {
132536345ac3SVladimir Kondratiev 	int rc;
132636345ac3SVladimir Kondratiev 	int i;
13272be7d22fSVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
1328e00243faSLior David 	struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
132936345ac3SVladimir Kondratiev 	struct wmi_notify_req_cmd cmd = {
133036345ac3SVladimir Kondratiev 		.interval_usec = 0,
133136345ac3SVladimir Kondratiev 	};
133236345ac3SVladimir Kondratiev 	struct {
1333b874ddecSLior David 		struct wmi_cmd_hdr wmi;
133436345ac3SVladimir Kondratiev 		struct wmi_notify_req_done_event evt;
133536345ac3SVladimir Kondratiev 	} __packed reply;
133636345ac3SVladimir Kondratiev 
1337807b0860SAlexei Avshalom Lazar 	memset(&reply, 0, sizeof(reply));
1338807b0860SAlexei Avshalom Lazar 
133936345ac3SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
134036345ac3SVladimir Kondratiev 		u32 status;
134136345ac3SVladimir Kondratiev 
134236345ac3SVladimir Kondratiev 		cmd.cid = i;
1343e00243faSLior David 		rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, vif->mid,
1344e00243faSLior David 			      &cmd, sizeof(cmd),
134536345ac3SVladimir Kondratiev 			      WMI_NOTIFY_REQ_DONE_EVENTID, &reply,
134636345ac3SVladimir Kondratiev 			      sizeof(reply), 20);
134736345ac3SVladimir Kondratiev 		/* if reply is all-0, ignore this CID */
134836345ac3SVladimir Kondratiev 		if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt)))
134936345ac3SVladimir Kondratiev 			continue;
135036345ac3SVladimir Kondratiev 
135136345ac3SVladimir Kondratiev 		status = le32_to_cpu(reply.evt.status);
135236345ac3SVladimir Kondratiev 		seq_printf(s, "CID %d {\n"
135336345ac3SVladimir Kondratiev 			   "  TSF = 0x%016llx\n"
135436345ac3SVladimir Kondratiev 			   "  TxMCS = %2d TxTpt = %4d\n"
135536345ac3SVladimir Kondratiev 			   "  SQI = %4d\n"
135630868f5dSDedy Lansky 			   "  RSSI = %4d\n"
135736345ac3SVladimir Kondratiev 			   "  Status = 0x%08x %s\n"
135836345ac3SVladimir Kondratiev 			   "  Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
135936345ac3SVladimir Kondratiev 			   "  Goodput(rx:tx) %4d:%4d\n"
136036345ac3SVladimir Kondratiev 			   "}\n",
136136345ac3SVladimir Kondratiev 			   i,
136236345ac3SVladimir Kondratiev 			   le64_to_cpu(reply.evt.tsf),
136336345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.bf_mcs),
136436345ac3SVladimir Kondratiev 			   le32_to_cpu(reply.evt.tx_tpt),
136536345ac3SVladimir Kondratiev 			   reply.evt.sqi,
136630868f5dSDedy Lansky 			   reply.evt.rssi,
136736345ac3SVladimir Kondratiev 			   status, wil_bfstatus_str(status),
136836345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.my_rx_sector),
136936345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.my_tx_sector),
137036345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.other_rx_sector),
137136345ac3SVladimir Kondratiev 			   le16_to_cpu(reply.evt.other_tx_sector),
137236345ac3SVladimir Kondratiev 			   le32_to_cpu(reply.evt.rx_goodput),
137336345ac3SVladimir Kondratiev 			   le32_to_cpu(reply.evt.tx_goodput));
137436345ac3SVladimir Kondratiev 	}
13752be7d22fSVladimir Kondratiev 	return 0;
13762be7d22fSVladimir Kondratiev }
13772be7d22fSVladimir Kondratiev 
13782be7d22fSVladimir Kondratiev static int wil_bf_seq_open(struct inode *inode, struct file *file)
13792be7d22fSVladimir Kondratiev {
13802be7d22fSVladimir Kondratiev 	return single_open(file, wil_bf_debugfs_show, inode->i_private);
13812be7d22fSVladimir Kondratiev }
13822be7d22fSVladimir Kondratiev 
13832be7d22fSVladimir Kondratiev static const struct file_operations fops_bf = {
13842be7d22fSVladimir Kondratiev 	.open		= wil_bf_seq_open,
13852be7d22fSVladimir Kondratiev 	.release	= single_release,
13862be7d22fSVladimir Kondratiev 	.read		= seq_read,
13872be7d22fSVladimir Kondratiev 	.llseek		= seq_lseek,
13882be7d22fSVladimir Kondratiev };
13898fe59627SVladimir Kondratiev 
13901a2780e0SVladimir Kondratiev /*---------temp------------*/
13911a2780e0SVladimir Kondratiev static void print_temp(struct seq_file *s, const char *prefix, u32 t)
13921a2780e0SVladimir Kondratiev {
13931a2780e0SVladimir Kondratiev 	switch (t) {
13941a2780e0SVladimir Kondratiev 	case 0:
13951a2780e0SVladimir Kondratiev 	case ~(u32)0:
13961a2780e0SVladimir Kondratiev 		seq_printf(s, "%s N/A\n", prefix);
13971a2780e0SVladimir Kondratiev 	break;
13981a2780e0SVladimir Kondratiev 	default:
13991a2780e0SVladimir Kondratiev 		seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
14001a2780e0SVladimir Kondratiev 		break;
14011a2780e0SVladimir Kondratiev 	}
14021a2780e0SVladimir Kondratiev }
14031a2780e0SVladimir Kondratiev 
14041a2780e0SVladimir Kondratiev static int wil_temp_debugfs_show(struct seq_file *s, void *data)
14051a2780e0SVladimir Kondratiev {
14061a2780e0SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
14071a2780e0SVladimir Kondratiev 	u32 t_m, t_r;
14081a2780e0SVladimir Kondratiev 	int rc = wmi_get_temperature(wil, &t_m, &t_r);
14098fe59627SVladimir Kondratiev 
14101a2780e0SVladimir Kondratiev 	if (rc) {
14118fe59627SVladimir Kondratiev 		seq_puts(s, "Failed\n");
14121a2780e0SVladimir Kondratiev 		return 0;
14131a2780e0SVladimir Kondratiev 	}
14141a2780e0SVladimir Kondratiev 
1415d45cff9fSVladimir Kondratiev 	print_temp(s, "T_mac   =", t_m);
1416d45cff9fSVladimir Kondratiev 	print_temp(s, "T_radio =", t_r);
14171a2780e0SVladimir Kondratiev 
14181a2780e0SVladimir Kondratiev 	return 0;
14191a2780e0SVladimir Kondratiev }
14201a2780e0SVladimir Kondratiev 
14211a2780e0SVladimir Kondratiev static int wil_temp_seq_open(struct inode *inode, struct file *file)
14221a2780e0SVladimir Kondratiev {
14231a2780e0SVladimir Kondratiev 	return single_open(file, wil_temp_debugfs_show, inode->i_private);
14241a2780e0SVladimir Kondratiev }
14251a2780e0SVladimir Kondratiev 
14261a2780e0SVladimir Kondratiev static const struct file_operations fops_temp = {
14271a2780e0SVladimir Kondratiev 	.open		= wil_temp_seq_open,
14281a2780e0SVladimir Kondratiev 	.release	= single_release,
14291a2780e0SVladimir Kondratiev 	.read		= seq_read,
14301a2780e0SVladimir Kondratiev 	.llseek		= seq_lseek,
14311a2780e0SVladimir Kondratiev };
14321a2780e0SVladimir Kondratiev 
14339eb82d43SVladimir Kondratiev /*---------freq------------*/
14349eb82d43SVladimir Kondratiev static int wil_freq_debugfs_show(struct seq_file *s, void *data)
14359eb82d43SVladimir Kondratiev {
14369eb82d43SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
1437e00243faSLior David 	struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr;
14389eb82d43SVladimir Kondratiev 	u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
14399eb82d43SVladimir Kondratiev 
14409eb82d43SVladimir Kondratiev 	seq_printf(s, "Freq = %d\n", freq);
14419eb82d43SVladimir Kondratiev 
14429eb82d43SVladimir Kondratiev 	return 0;
14439eb82d43SVladimir Kondratiev }
14449eb82d43SVladimir Kondratiev 
14459eb82d43SVladimir Kondratiev static int wil_freq_seq_open(struct inode *inode, struct file *file)
14469eb82d43SVladimir Kondratiev {
14479eb82d43SVladimir Kondratiev 	return single_open(file, wil_freq_debugfs_show, inode->i_private);
14489eb82d43SVladimir Kondratiev }
14499eb82d43SVladimir Kondratiev 
14509eb82d43SVladimir Kondratiev static const struct file_operations fops_freq = {
14519eb82d43SVladimir Kondratiev 	.open		= wil_freq_seq_open,
14529eb82d43SVladimir Kondratiev 	.release	= single_release,
14539eb82d43SVladimir Kondratiev 	.read		= seq_read,
14549eb82d43SVladimir Kondratiev 	.llseek		= seq_lseek,
14559eb82d43SVladimir Kondratiev };
14569eb82d43SVladimir Kondratiev 
14579eb82d43SVladimir Kondratiev /*---------link------------*/
14589eb82d43SVladimir Kondratiev static int wil_link_debugfs_show(struct seq_file *s, void *data)
14599eb82d43SVladimir Kondratiev {
14609eb82d43SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
146141bd3d58SToke Høiland-Jørgensen 	struct station_info *sinfo;
146241bd3d58SToke Høiland-Jørgensen 	int i, rc = 0;
146341bd3d58SToke Høiland-Jørgensen 
146441bd3d58SToke Høiland-Jørgensen 	sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL);
146541bd3d58SToke Høiland-Jørgensen 	if (!sinfo)
146641bd3d58SToke Høiland-Jørgensen 		return -ENOMEM;
14679eb82d43SVladimir Kondratiev 
14689eb82d43SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
14699eb82d43SVladimir Kondratiev 		struct wil_sta_info *p = &wil->sta[i];
14709eb82d43SVladimir Kondratiev 		char *status = "unknown";
14715bd60982SLior David 		struct wil6210_vif *vif;
14725bd60982SLior David 		u8 mid;
14738fe59627SVladimir Kondratiev 
14749eb82d43SVladimir Kondratiev 		switch (p->status) {
14759eb82d43SVladimir Kondratiev 		case wil_sta_unused:
14769eb82d43SVladimir Kondratiev 			status = "unused   ";
14779eb82d43SVladimir Kondratiev 			break;
14789eb82d43SVladimir Kondratiev 		case wil_sta_conn_pending:
14799eb82d43SVladimir Kondratiev 			status = "pending  ";
14809eb82d43SVladimir Kondratiev 			break;
14819eb82d43SVladimir Kondratiev 		case wil_sta_connected:
14829eb82d43SVladimir Kondratiev 			status = "connected";
14839eb82d43SVladimir Kondratiev 			break;
14849eb82d43SVladimir Kondratiev 		}
14855bd60982SLior David 		mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
14865bd60982SLior David 		seq_printf(s, "[%d][MID %d] %pM %s\n",
14875bd60982SLior David 			   i, mid, p->addr, status);
14889eb82d43SVladimir Kondratiev 
14895bd60982SLior David 		if (p->status != wil_sta_connected)
14905bd60982SLior David 			continue;
14915bd60982SLior David 
14925bd60982SLior David 		vif = (mid < wil->max_vifs) ? wil->vifs[mid] : NULL;
14935bd60982SLior David 		if (vif) {
149441bd3d58SToke Høiland-Jørgensen 			rc = wil_cid_fill_sinfo(vif, i, sinfo);
14959eb82d43SVladimir Kondratiev 			if (rc)
149641bd3d58SToke Høiland-Jørgensen 				goto out;
14979eb82d43SVladimir Kondratiev 
149841bd3d58SToke Høiland-Jørgensen 			seq_printf(s, "  Tx_mcs = %d\n", sinfo->txrate.mcs);
149941bd3d58SToke Høiland-Jørgensen 			seq_printf(s, "  Rx_mcs = %d\n", sinfo->rxrate.mcs);
150041bd3d58SToke Høiland-Jørgensen 			seq_printf(s, "  SQ     = %d\n", sinfo->signal);
15015bd60982SLior David 		} else {
15025bd60982SLior David 			seq_puts(s, "  INVALID MID\n");
15039eb82d43SVladimir Kondratiev 		}
15049eb82d43SVladimir Kondratiev 	}
15059eb82d43SVladimir Kondratiev 
150641bd3d58SToke Høiland-Jørgensen out:
150741bd3d58SToke Høiland-Jørgensen 	kfree(sinfo);
150841bd3d58SToke Høiland-Jørgensen 	return rc;
15099eb82d43SVladimir Kondratiev }
15109eb82d43SVladimir Kondratiev 
15119eb82d43SVladimir Kondratiev static int wil_link_seq_open(struct inode *inode, struct file *file)
15129eb82d43SVladimir Kondratiev {
15139eb82d43SVladimir Kondratiev 	return single_open(file, wil_link_debugfs_show, inode->i_private);
15149eb82d43SVladimir Kondratiev }
15159eb82d43SVladimir Kondratiev 
15169eb82d43SVladimir Kondratiev static const struct file_operations fops_link = {
15179eb82d43SVladimir Kondratiev 	.open		= wil_link_seq_open,
15189eb82d43SVladimir Kondratiev 	.release	= single_release,
15199eb82d43SVladimir Kondratiev 	.read		= seq_read,
15209eb82d43SVladimir Kondratiev 	.llseek		= seq_lseek,
15219eb82d43SVladimir Kondratiev };
15229eb82d43SVladimir Kondratiev 
152384bb29b7SVladimir Kondratiev /*---------info------------*/
152484bb29b7SVladimir Kondratiev static int wil_info_debugfs_show(struct seq_file *s, void *data)
152584bb29b7SVladimir Kondratiev {
1526be299858SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
1527e00243faSLior David 	struct net_device *ndev = wil->main_ndev;
152884bb29b7SVladimir Kondratiev 	int is_ac = power_supply_is_system_supplied();
1529be299858SVladimir Kondratiev 	int rx = atomic_xchg(&wil->isr_count_rx, 0);
1530be299858SVladimir Kondratiev 	int tx = atomic_xchg(&wil->isr_count_tx, 0);
1531be299858SVladimir Kondratiev 	static ulong rxf_old, txf_old;
1532be299858SVladimir Kondratiev 	ulong rxf = ndev->stats.rx_packets;
1533be299858SVladimir Kondratiev 	ulong txf = ndev->stats.tx_packets;
153455f8f680SVladimir Kondratiev 	unsigned int i;
153584bb29b7SVladimir Kondratiev 
153684bb29b7SVladimir Kondratiev 	/* >0 : AC; 0 : battery; <0 : error */
153784bb29b7SVladimir Kondratiev 	seq_printf(s, "AC powered : %d\n", is_ac);
1538be299858SVladimir Kondratiev 	seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
1539be299858SVladimir Kondratiev 	seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
1540be299858SVladimir Kondratiev 	rxf_old = rxf;
1541be299858SVladimir Kondratiev 	txf_old = txf;
154284bb29b7SVladimir Kondratiev 
154355f8f680SVladimir Kondratiev #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
154455f8f680SVladimir Kondratiev 	" " __stringify(x) : ""
154555f8f680SVladimir Kondratiev 
154655f8f680SVladimir Kondratiev 	for (i = 0; i < ndev->num_tx_queues; i++) {
154755f8f680SVladimir Kondratiev 		struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
154855f8f680SVladimir Kondratiev 		unsigned long state = txq->state;
154955f8f680SVladimir Kondratiev 
155055f8f680SVladimir Kondratiev 		seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
155155f8f680SVladimir Kondratiev 			   CHECK_QSTATE(DRV_XOFF),
155255f8f680SVladimir Kondratiev 			   CHECK_QSTATE(STACK_XOFF),
155355f8f680SVladimir Kondratiev 			   CHECK_QSTATE(FROZEN)
155455f8f680SVladimir Kondratiev 			  );
155555f8f680SVladimir Kondratiev 	}
155655f8f680SVladimir Kondratiev #undef CHECK_QSTATE
155784bb29b7SVladimir Kondratiev 	return 0;
155884bb29b7SVladimir Kondratiev }
155984bb29b7SVladimir Kondratiev 
156084bb29b7SVladimir Kondratiev static int wil_info_seq_open(struct inode *inode, struct file *file)
156184bb29b7SVladimir Kondratiev {
156284bb29b7SVladimir Kondratiev 	return single_open(file, wil_info_debugfs_show, inode->i_private);
156384bb29b7SVladimir Kondratiev }
156484bb29b7SVladimir Kondratiev 
156584bb29b7SVladimir Kondratiev static const struct file_operations fops_info = {
156684bb29b7SVladimir Kondratiev 	.open		= wil_info_seq_open,
156784bb29b7SVladimir Kondratiev 	.release	= single_release,
156884bb29b7SVladimir Kondratiev 	.read		= seq_read,
156984bb29b7SVladimir Kondratiev 	.llseek		= seq_lseek,
157084bb29b7SVladimir Kondratiev };
157184bb29b7SVladimir Kondratiev 
1572c33407a8SVladimir Kondratiev /*---------recovery------------*/
1573c33407a8SVladimir Kondratiev /* mode = [manual|auto]
1574c33407a8SVladimir Kondratiev  * state = [idle|pending|running]
1575c33407a8SVladimir Kondratiev  */
1576c33407a8SVladimir Kondratiev static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf,
1577c33407a8SVladimir Kondratiev 				      size_t count, loff_t *ppos)
1578c33407a8SVladimir Kondratiev {
1579c33407a8SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
1580c33407a8SVladimir Kondratiev 	char buf[80];
1581c33407a8SVladimir Kondratiev 	int n;
1582c33407a8SVladimir Kondratiev 	static const char * const sstate[] = {"idle", "pending", "running"};
1583c33407a8SVladimir Kondratiev 
1584c33407a8SVladimir Kondratiev 	n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n",
1585c33407a8SVladimir Kondratiev 		     no_fw_recovery ? "manual" : "auto",
1586c33407a8SVladimir Kondratiev 		     sstate[wil->recovery_state]);
1587c33407a8SVladimir Kondratiev 
1588c33407a8SVladimir Kondratiev 	n = min_t(int, n, sizeof(buf));
1589c33407a8SVladimir Kondratiev 
1590c33407a8SVladimir Kondratiev 	return simple_read_from_buffer(user_buf, count, ppos,
1591c33407a8SVladimir Kondratiev 				       buf, n);
1592c33407a8SVladimir Kondratiev }
1593c33407a8SVladimir Kondratiev 
1594c33407a8SVladimir Kondratiev static ssize_t wil_write_file_recovery(struct file *file,
1595c33407a8SVladimir Kondratiev 				       const char __user *buf_,
1596c33407a8SVladimir Kondratiev 				       size_t count, loff_t *ppos)
1597c33407a8SVladimir Kondratiev {
1598c33407a8SVladimir Kondratiev 	struct wil6210_priv *wil = file->private_data;
1599c33407a8SVladimir Kondratiev 	static const char run_command[] = "run";
1600c33407a8SVladimir Kondratiev 	char buf[sizeof(run_command) + 1]; /* to detect "runx" */
1601c33407a8SVladimir Kondratiev 	ssize_t rc;
1602c33407a8SVladimir Kondratiev 
1603c33407a8SVladimir Kondratiev 	if (wil->recovery_state != fw_recovery_pending) {
1604c33407a8SVladimir Kondratiev 		wil_err(wil, "No recovery pending\n");
1605c33407a8SVladimir Kondratiev 		return -EINVAL;
1606c33407a8SVladimir Kondratiev 	}
1607c33407a8SVladimir Kondratiev 
1608c33407a8SVladimir Kondratiev 	if (*ppos != 0) {
1609c33407a8SVladimir Kondratiev 		wil_err(wil, "Offset [%d]\n", (int)*ppos);
1610c33407a8SVladimir Kondratiev 		return -EINVAL;
1611c33407a8SVladimir Kondratiev 	}
1612c33407a8SVladimir Kondratiev 
1613c33407a8SVladimir Kondratiev 	if (count > sizeof(buf)) {
1614c33407a8SVladimir Kondratiev 		wil_err(wil, "Input too long, len = %d\n", (int)count);
1615c33407a8SVladimir Kondratiev 		return -EINVAL;
1616c33407a8SVladimir Kondratiev 	}
1617c33407a8SVladimir Kondratiev 
1618c33407a8SVladimir Kondratiev 	rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count);
1619c33407a8SVladimir Kondratiev 	if (rc < 0)
1620c33407a8SVladimir Kondratiev 		return rc;
1621c33407a8SVladimir Kondratiev 
1622c33407a8SVladimir Kondratiev 	buf[rc] = '\0';
1623c33407a8SVladimir Kondratiev 	if (0 == strcmp(buf, run_command))
1624c33407a8SVladimir Kondratiev 		wil_set_recovery_state(wil, fw_recovery_running);
1625c33407a8SVladimir Kondratiev 	else
1626c33407a8SVladimir Kondratiev 		wil_err(wil, "Bad recovery command \"%s\"\n", buf);
1627c33407a8SVladimir Kondratiev 
1628c33407a8SVladimir Kondratiev 	return rc;
1629c33407a8SVladimir Kondratiev }
1630c33407a8SVladimir Kondratiev 
1631c33407a8SVladimir Kondratiev static const struct file_operations fops_recovery = {
1632c33407a8SVladimir Kondratiev 	.read = wil_read_file_recovery,
1633c33407a8SVladimir Kondratiev 	.write = wil_write_file_recovery,
1634c33407a8SVladimir Kondratiev 	.open  = simple_open,
1635c33407a8SVladimir Kondratiev };
1636c33407a8SVladimir Kondratiev 
16373df2cd36SVladimir Kondratiev /*---------Station matrix------------*/
1638b4490f42SVladimir Kondratiev static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
1639b4490f42SVladimir Kondratiev {
1640b4490f42SVladimir Kondratiev 	int i;
1641b4490f42SVladimir Kondratiev 	u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
164291a8edccSVladimir Kondratiev 	unsigned long long drop_dup = r->drop_dup, drop_old = r->drop_old;
16431bd82ee0SDedy Lansky 	unsigned long long drop_dup_mcast = r->drop_dup_mcast;
16448fe59627SVladimir Kondratiev 
164537f8d26dSDedy Lansky 	seq_printf(s, "([%2d]) 0x%03x [", r->buf_size, r->head_seq_num);
1646b4490f42SVladimir Kondratiev 	for (i = 0; i < r->buf_size; i++) {
1647b4490f42SVladimir Kondratiev 		if (i == index)
1648b4490f42SVladimir Kondratiev 			seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
1649b4490f42SVladimir Kondratiev 		else
1650b4490f42SVladimir Kondratiev 			seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
1651b4490f42SVladimir Kondratiev 	}
165291a8edccSVladimir Kondratiev 	seq_printf(s,
16531bd82ee0SDedy Lansky 		   "] total %llu drop %llu (dup %llu + old %llu + dup mcast %llu) last 0x%03x\n",
16541bd82ee0SDedy Lansky 		   r->total, drop_dup + drop_old + drop_dup_mcast, drop_dup,
16551bd82ee0SDedy Lansky 		   drop_old, drop_dup_mcast, r->ssn_last_drop);
1656b4490f42SVladimir Kondratiev }
16573df2cd36SVladimir Kondratiev 
165858527421SVladimir Kondratiev static void wil_print_rxtid_crypto(struct seq_file *s, int tid,
165958527421SVladimir Kondratiev 				   struct wil_tid_crypto_rx *c)
166058527421SVladimir Kondratiev {
166158527421SVladimir Kondratiev 	int i;
166258527421SVladimir Kondratiev 
166358527421SVladimir Kondratiev 	for (i = 0; i < 4; i++) {
166458527421SVladimir Kondratiev 		struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
166558527421SVladimir Kondratiev 
166658527421SVladimir Kondratiev 		if (cc->key_set)
166758527421SVladimir Kondratiev 			goto has_keys;
166858527421SVladimir Kondratiev 	}
166958527421SVladimir Kondratiev 	return;
167058527421SVladimir Kondratiev 
167158527421SVladimir Kondratiev has_keys:
167258527421SVladimir Kondratiev 	if (tid < WIL_STA_TID_NUM)
167358527421SVladimir Kondratiev 		seq_printf(s, "  [%2d] PN", tid);
167458527421SVladimir Kondratiev 	else
167558527421SVladimir Kondratiev 		seq_puts(s, "  [GR] PN");
167658527421SVladimir Kondratiev 
167758527421SVladimir Kondratiev 	for (i = 0; i < 4; i++) {
167858527421SVladimir Kondratiev 		struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
167958527421SVladimir Kondratiev 
168058527421SVladimir Kondratiev 		seq_printf(s, " [%i%s]%6phN", i, cc->key_set ? "+" : "-",
168158527421SVladimir Kondratiev 			   cc->pn);
168258527421SVladimir Kondratiev 	}
168358527421SVladimir Kondratiev 	seq_puts(s, "\n");
168458527421SVladimir Kondratiev }
168558527421SVladimir Kondratiev 
16863df2cd36SVladimir Kondratiev static int wil_sta_debugfs_show(struct seq_file *s, void *data)
1687bd33273bSVladimir Kondratiev __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
16883df2cd36SVladimir Kondratiev {
16893df2cd36SVladimir Kondratiev 	struct wil6210_priv *wil = s->private;
1690c4a110d8SVladimir Kondratiev 	int i, tid, mcs;
16913df2cd36SVladimir Kondratiev 
16923df2cd36SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
16933df2cd36SVladimir Kondratiev 		struct wil_sta_info *p = &wil->sta[i];
16943df2cd36SVladimir Kondratiev 		char *status = "unknown";
16959d865ee2SLior David 		u8 aid = 0;
16965bd60982SLior David 		u8 mid;
16978fe59627SVladimir Kondratiev 
16983df2cd36SVladimir Kondratiev 		switch (p->status) {
16993df2cd36SVladimir Kondratiev 		case wil_sta_unused:
17003df2cd36SVladimir Kondratiev 			status = "unused   ";
17013df2cd36SVladimir Kondratiev 			break;
17023df2cd36SVladimir Kondratiev 		case wil_sta_conn_pending:
17033df2cd36SVladimir Kondratiev 			status = "pending  ";
17043df2cd36SVladimir Kondratiev 			break;
17053df2cd36SVladimir Kondratiev 		case wil_sta_connected:
17063df2cd36SVladimir Kondratiev 			status = "connected";
17079d865ee2SLior David 			aid = p->aid;
17083df2cd36SVladimir Kondratiev 			break;
17093df2cd36SVladimir Kondratiev 		}
17105bd60982SLior David 		mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
17115bd60982SLior David 		seq_printf(s, "[%d] %pM %s MID %d AID %d\n", i, p->addr, status,
17125bd60982SLior David 			   mid, aid);
1713b4490f42SVladimir Kondratiev 
1714b4490f42SVladimir Kondratiev 		if (p->status == wil_sta_connected) {
1715bd33273bSVladimir Kondratiev 			spin_lock_bh(&p->tid_rx_lock);
1716b4490f42SVladimir Kondratiev 			for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1717b4490f42SVladimir Kondratiev 				struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
171858527421SVladimir Kondratiev 				struct wil_tid_crypto_rx *c =
171958527421SVladimir Kondratiev 						&p->tid_crypto_rx[tid];
17208fe59627SVladimir Kondratiev 
1721b4490f42SVladimir Kondratiev 				if (r) {
1722b4490f42SVladimir Kondratiev 					seq_printf(s, "  [%2d] ", tid);
1723b4490f42SVladimir Kondratiev 					wil_print_rxtid(s, r);
1724b4490f42SVladimir Kondratiev 				}
172558527421SVladimir Kondratiev 
172658527421SVladimir Kondratiev 				wil_print_rxtid_crypto(s, tid, c);
1727b4490f42SVladimir Kondratiev 			}
172858527421SVladimir Kondratiev 			wil_print_rxtid_crypto(s, WIL_STA_TID_NUM,
172958527421SVladimir Kondratiev 					       &p->group_crypto_rx);
1730bd33273bSVladimir Kondratiev 			spin_unlock_bh(&p->tid_rx_lock);
17313b282bc6SVladimir Kondratiev 			seq_printf(s,
173258527421SVladimir Kondratiev 				   "Rx invalid frame: non-data %lu, short %lu, large %lu, replay %lu\n",
17333b282bc6SVladimir Kondratiev 				   p->stats.rx_non_data_frame,
17343b282bc6SVladimir Kondratiev 				   p->stats.rx_short_frame,
173558527421SVladimir Kondratiev 				   p->stats.rx_large_frame,
173658527421SVladimir Kondratiev 				   p->stats.rx_replay);
1737d98b8539SMaya Erez 			seq_printf(s,
1738d98b8539SMaya Erez 				   "mic error %lu, key error %lu, amsdu error %lu\n",
1739d98b8539SMaya Erez 				   p->stats.rx_mic_error,
1740d98b8539SMaya Erez 				   p->stats.rx_key_error,
1741d98b8539SMaya Erez 				   p->stats.rx_amsdu_error);
1742d98b8539SMaya Erez 
1743c4a110d8SVladimir Kondratiev 			seq_puts(s, "Rx/MCS:");
1744c4a110d8SVladimir Kondratiev 			for (mcs = 0; mcs < ARRAY_SIZE(p->stats.rx_per_mcs);
1745c4a110d8SVladimir Kondratiev 			     mcs++)
1746c4a110d8SVladimir Kondratiev 				seq_printf(s, " %lld",
1747c4a110d8SVladimir Kondratiev 					   p->stats.rx_per_mcs[mcs]);
1748c4a110d8SVladimir Kondratiev 			seq_puts(s, "\n");
1749b4490f42SVladimir Kondratiev 		}
17503df2cd36SVladimir Kondratiev 	}
17513df2cd36SVladimir Kondratiev 
17523df2cd36SVladimir Kondratiev 	return 0;
17533df2cd36SVladimir Kondratiev }
17543df2cd36SVladimir Kondratiev 
17553df2cd36SVladimir Kondratiev static int wil_sta_seq_open(struct inode *inode, struct file *file)
17563df2cd36SVladimir Kondratiev {
17573df2cd36SVladimir Kondratiev 	return single_open(file, wil_sta_debugfs_show, inode->i_private);
17583df2cd36SVladimir Kondratiev }
17593df2cd36SVladimir Kondratiev 
17603df2cd36SVladimir Kondratiev static const struct file_operations fops_sta = {
17613df2cd36SVladimir Kondratiev 	.open		= wil_sta_seq_open,
17623df2cd36SVladimir Kondratiev 	.release	= single_release,
17633df2cd36SVladimir Kondratiev 	.read		= seq_read,
17643df2cd36SVladimir Kondratiev 	.llseek		= seq_lseek,
17653df2cd36SVladimir Kondratiev };
17663df2cd36SVladimir Kondratiev 
17673a3b745fSLior David static int wil_mids_debugfs_show(struct seq_file *s, void *data)
17683a3b745fSLior David {
17693a3b745fSLior David 	struct wil6210_priv *wil = s->private;
17703a3b745fSLior David 	struct wil6210_vif *vif;
17713a3b745fSLior David 	struct net_device *ndev;
17723a3b745fSLior David 	int i;
17733a3b745fSLior David 
17743a3b745fSLior David 	mutex_lock(&wil->vif_mutex);
17753a3b745fSLior David 	for (i = 0; i < wil->max_vifs; i++) {
17763a3b745fSLior David 		vif = wil->vifs[i];
17773a3b745fSLior David 
17783a3b745fSLior David 		if (vif) {
17793a3b745fSLior David 			ndev = vif_to_ndev(vif);
17803a3b745fSLior David 			seq_printf(s, "[%d] %pM %s\n", i, ndev->dev_addr,
17813a3b745fSLior David 				   ndev->name);
17823a3b745fSLior David 		} else {
17833a3b745fSLior David 			seq_printf(s, "[%d] unused\n", i);
17843a3b745fSLior David 		}
17853a3b745fSLior David 	}
17863a3b745fSLior David 	mutex_unlock(&wil->vif_mutex);
17873a3b745fSLior David 
17883a3b745fSLior David 	return 0;
17893a3b745fSLior David }
17903a3b745fSLior David 
17913a3b745fSLior David static int wil_mids_seq_open(struct inode *inode, struct file *file)
17923a3b745fSLior David {
17933a3b745fSLior David 	return single_open(file, wil_mids_debugfs_show, inode->i_private);
17943a3b745fSLior David }
17953a3b745fSLior David 
17963a3b745fSLior David static const struct file_operations fops_mids = {
17973a3b745fSLior David 	.open		= wil_mids_seq_open,
17983a3b745fSLior David 	.release	= single_release,
17993a3b745fSLior David 	.read		= seq_read,
18003a3b745fSLior David 	.llseek		= seq_lseek,
18013a3b745fSLior David };
18023a3b745fSLior David 
1803*a24a3d6aSDedy Lansky static int wil_tx_latency_debugfs_show(struct seq_file *s, void *data)
1804*a24a3d6aSDedy Lansky __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
1805*a24a3d6aSDedy Lansky {
1806*a24a3d6aSDedy Lansky 	struct wil6210_priv *wil = s->private;
1807*a24a3d6aSDedy Lansky 	int i, bin;
1808*a24a3d6aSDedy Lansky 
1809*a24a3d6aSDedy Lansky 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1810*a24a3d6aSDedy Lansky 		struct wil_sta_info *p = &wil->sta[i];
1811*a24a3d6aSDedy Lansky 		char *status = "unknown";
1812*a24a3d6aSDedy Lansky 		u8 aid = 0;
1813*a24a3d6aSDedy Lansky 		u8 mid;
1814*a24a3d6aSDedy Lansky 
1815*a24a3d6aSDedy Lansky 		if (!p->tx_latency_bins)
1816*a24a3d6aSDedy Lansky 			continue;
1817*a24a3d6aSDedy Lansky 
1818*a24a3d6aSDedy Lansky 		switch (p->status) {
1819*a24a3d6aSDedy Lansky 		case wil_sta_unused:
1820*a24a3d6aSDedy Lansky 			status = "unused   ";
1821*a24a3d6aSDedy Lansky 			break;
1822*a24a3d6aSDedy Lansky 		case wil_sta_conn_pending:
1823*a24a3d6aSDedy Lansky 			status = "pending  ";
1824*a24a3d6aSDedy Lansky 			break;
1825*a24a3d6aSDedy Lansky 		case wil_sta_connected:
1826*a24a3d6aSDedy Lansky 			status = "connected";
1827*a24a3d6aSDedy Lansky 			aid = p->aid;
1828*a24a3d6aSDedy Lansky 			break;
1829*a24a3d6aSDedy Lansky 		}
1830*a24a3d6aSDedy Lansky 		mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
1831*a24a3d6aSDedy Lansky 		seq_printf(s, "[%d] %pM %s MID %d AID %d\n", i, p->addr, status,
1832*a24a3d6aSDedy Lansky 			   mid, aid);
1833*a24a3d6aSDedy Lansky 
1834*a24a3d6aSDedy Lansky 		if (p->status == wil_sta_connected) {
1835*a24a3d6aSDedy Lansky 			u64 num_packets = 0;
1836*a24a3d6aSDedy Lansky 			u64 tx_latency_avg = p->stats.tx_latency_total_us;
1837*a24a3d6aSDedy Lansky 
1838*a24a3d6aSDedy Lansky 			seq_puts(s, "Tx/Latency bin:");
1839*a24a3d6aSDedy Lansky 			for (bin = 0; bin < WIL_NUM_LATENCY_BINS; bin++) {
1840*a24a3d6aSDedy Lansky 				seq_printf(s, " %lld",
1841*a24a3d6aSDedy Lansky 					   p->tx_latency_bins[bin]);
1842*a24a3d6aSDedy Lansky 				num_packets += p->tx_latency_bins[bin];
1843*a24a3d6aSDedy Lansky 			}
1844*a24a3d6aSDedy Lansky 			seq_puts(s, "\n");
1845*a24a3d6aSDedy Lansky 			if (!num_packets)
1846*a24a3d6aSDedy Lansky 				continue;
1847*a24a3d6aSDedy Lansky 			do_div(tx_latency_avg, num_packets);
1848*a24a3d6aSDedy Lansky 			seq_printf(s, "Tx/Latency min/avg/max (us): %d/%lld/%d",
1849*a24a3d6aSDedy Lansky 				   p->stats.tx_latency_min_us,
1850*a24a3d6aSDedy Lansky 				   tx_latency_avg,
1851*a24a3d6aSDedy Lansky 				   p->stats.tx_latency_max_us);
1852*a24a3d6aSDedy Lansky 
1853*a24a3d6aSDedy Lansky 			seq_puts(s, "\n");
1854*a24a3d6aSDedy Lansky 		}
1855*a24a3d6aSDedy Lansky 	}
1856*a24a3d6aSDedy Lansky 
1857*a24a3d6aSDedy Lansky 	return 0;
1858*a24a3d6aSDedy Lansky }
1859*a24a3d6aSDedy Lansky 
1860*a24a3d6aSDedy Lansky static int wil_tx_latency_seq_open(struct inode *inode, struct file *file)
1861*a24a3d6aSDedy Lansky {
1862*a24a3d6aSDedy Lansky 	return single_open(file, wil_tx_latency_debugfs_show,
1863*a24a3d6aSDedy Lansky 			   inode->i_private);
1864*a24a3d6aSDedy Lansky }
1865*a24a3d6aSDedy Lansky 
1866*a24a3d6aSDedy Lansky static ssize_t wil_tx_latency_write(struct file *file, const char __user *buf,
1867*a24a3d6aSDedy Lansky 				    size_t len, loff_t *ppos)
1868*a24a3d6aSDedy Lansky {
1869*a24a3d6aSDedy Lansky 	struct seq_file *s = file->private_data;
1870*a24a3d6aSDedy Lansky 	struct wil6210_priv *wil = s->private;
1871*a24a3d6aSDedy Lansky 	int val, rc, i;
1872*a24a3d6aSDedy Lansky 	bool enable;
1873*a24a3d6aSDedy Lansky 
1874*a24a3d6aSDedy Lansky 	rc = kstrtoint_from_user(buf, len, 0, &val);
1875*a24a3d6aSDedy Lansky 	if (rc) {
1876*a24a3d6aSDedy Lansky 		wil_err(wil, "Invalid argument\n");
1877*a24a3d6aSDedy Lansky 		return rc;
1878*a24a3d6aSDedy Lansky 	}
1879*a24a3d6aSDedy Lansky 	if (val == 1)
1880*a24a3d6aSDedy Lansky 		/* default resolution */
1881*a24a3d6aSDedy Lansky 		val = 500;
1882*a24a3d6aSDedy Lansky 	if (val && (val < 50 || val > 1000)) {
1883*a24a3d6aSDedy Lansky 		wil_err(wil, "Invalid resolution %d\n", val);
1884*a24a3d6aSDedy Lansky 		return -EINVAL;
1885*a24a3d6aSDedy Lansky 	}
1886*a24a3d6aSDedy Lansky 
1887*a24a3d6aSDedy Lansky 	enable = !!val;
1888*a24a3d6aSDedy Lansky 	if (wil->tx_latency == enable)
1889*a24a3d6aSDedy Lansky 		return len;
1890*a24a3d6aSDedy Lansky 
1891*a24a3d6aSDedy Lansky 	wil_info(wil, "%s TX latency measurements (resolution %dusec)\n",
1892*a24a3d6aSDedy Lansky 		 enable ? "Enabling" : "Disabling", val);
1893*a24a3d6aSDedy Lansky 
1894*a24a3d6aSDedy Lansky 	if (enable) {
1895*a24a3d6aSDedy Lansky 		size_t sz = sizeof(u64) * WIL_NUM_LATENCY_BINS;
1896*a24a3d6aSDedy Lansky 
1897*a24a3d6aSDedy Lansky 		wil->tx_latency_res = val;
1898*a24a3d6aSDedy Lansky 		for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1899*a24a3d6aSDedy Lansky 			struct wil_sta_info *sta = &wil->sta[i];
1900*a24a3d6aSDedy Lansky 
1901*a24a3d6aSDedy Lansky 			kfree(sta->tx_latency_bins);
1902*a24a3d6aSDedy Lansky 			sta->tx_latency_bins = kzalloc(sz, GFP_KERNEL);
1903*a24a3d6aSDedy Lansky 			if (!sta->tx_latency_bins)
1904*a24a3d6aSDedy Lansky 				return -ENOMEM;
1905*a24a3d6aSDedy Lansky 			sta->stats.tx_latency_min_us = U32_MAX;
1906*a24a3d6aSDedy Lansky 			sta->stats.tx_latency_max_us = 0;
1907*a24a3d6aSDedy Lansky 			sta->stats.tx_latency_total_us = 0;
1908*a24a3d6aSDedy Lansky 		}
1909*a24a3d6aSDedy Lansky 	}
1910*a24a3d6aSDedy Lansky 	wil->tx_latency = enable;
1911*a24a3d6aSDedy Lansky 
1912*a24a3d6aSDedy Lansky 	return len;
1913*a24a3d6aSDedy Lansky }
1914*a24a3d6aSDedy Lansky 
1915*a24a3d6aSDedy Lansky static const struct file_operations fops_tx_latency = {
1916*a24a3d6aSDedy Lansky 	.open		= wil_tx_latency_seq_open,
1917*a24a3d6aSDedy Lansky 	.release	= single_release,
1918*a24a3d6aSDedy Lansky 	.read		= seq_read,
1919*a24a3d6aSDedy Lansky 	.write		= wil_tx_latency_write,
1920*a24a3d6aSDedy Lansky 	.llseek		= seq_lseek,
1921*a24a3d6aSDedy Lansky };
1922*a24a3d6aSDedy Lansky 
192310d599adSMaya Erez static ssize_t wil_read_file_led_cfg(struct file *file, char __user *user_buf,
192410d599adSMaya Erez 				     size_t count, loff_t *ppos)
192510d599adSMaya Erez {
192610d599adSMaya Erez 	char buf[80];
192710d599adSMaya Erez 	int n;
192810d599adSMaya Erez 
192910d599adSMaya Erez 	n = snprintf(buf, sizeof(buf),
193010d599adSMaya Erez 		     "led_id is set to %d, echo 1 to enable, 0 to disable\n",
193110d599adSMaya Erez 		     led_id);
193210d599adSMaya Erez 
193310d599adSMaya Erez 	n = min_t(int, n, sizeof(buf));
193410d599adSMaya Erez 
193510d599adSMaya Erez 	return simple_read_from_buffer(user_buf, count, ppos,
193610d599adSMaya Erez 				       buf, n);
193710d599adSMaya Erez }
193810d599adSMaya Erez 
193910d599adSMaya Erez static ssize_t wil_write_file_led_cfg(struct file *file,
194010d599adSMaya Erez 				      const char __user *buf_,
194110d599adSMaya Erez 				      size_t count, loff_t *ppos)
194210d599adSMaya Erez {
194310d599adSMaya Erez 	struct wil6210_priv *wil = file->private_data;
194410d599adSMaya Erez 	int val;
194510d599adSMaya Erez 	int rc;
194610d599adSMaya Erez 
194710d599adSMaya Erez 	rc = kstrtoint_from_user(buf_, count, 0, &val);
194810d599adSMaya Erez 	if (rc) {
194910d599adSMaya Erez 		wil_err(wil, "Invalid argument\n");
195010d599adSMaya Erez 		return rc;
195110d599adSMaya Erez 	}
195210d599adSMaya Erez 
195310d599adSMaya Erez 	wil_info(wil, "%s led %d\n", val ? "Enabling" : "Disabling", led_id);
195410d599adSMaya Erez 	rc = wmi_led_cfg(wil, val);
195510d599adSMaya Erez 	if (rc) {
195610d599adSMaya Erez 		wil_info(wil, "%s led %d failed\n",
195710d599adSMaya Erez 			 val ? "Enabling" : "Disabling", led_id);
195810d599adSMaya Erez 		return rc;
195910d599adSMaya Erez 	}
196010d599adSMaya Erez 
196110d599adSMaya Erez 	return count;
196210d599adSMaya Erez }
196310d599adSMaya Erez 
196410d599adSMaya Erez static const struct file_operations fops_led_cfg = {
196510d599adSMaya Erez 	.read = wil_read_file_led_cfg,
196610d599adSMaya Erez 	.write = wil_write_file_led_cfg,
196710d599adSMaya Erez 	.open  = simple_open,
196810d599adSMaya Erez };
196910d599adSMaya Erez 
197010d599adSMaya Erez /* led_blink_time, write:
197110d599adSMaya Erez  * "<blink_on_slow> <blink_off_slow> <blink_on_med> <blink_off_med> <blink_on_fast> <blink_off_fast>
197210d599adSMaya Erez  */
197310d599adSMaya Erez static ssize_t wil_write_led_blink_time(struct file *file,
197410d599adSMaya Erez 					const char __user *buf,
197510d599adSMaya Erez 					size_t len, loff_t *ppos)
197610d599adSMaya Erez {
197710d599adSMaya Erez 	int rc;
197810d599adSMaya Erez 	char *kbuf = kmalloc(len + 1, GFP_KERNEL);
197910d599adSMaya Erez 
198010d599adSMaya Erez 	if (!kbuf)
198110d599adSMaya Erez 		return -ENOMEM;
198210d599adSMaya Erez 
198310d599adSMaya Erez 	rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
198410d599adSMaya Erez 	if (rc != len) {
198510d599adSMaya Erez 		kfree(kbuf);
198610d599adSMaya Erez 		return rc >= 0 ? -EIO : rc;
198710d599adSMaya Erez 	}
198810d599adSMaya Erez 
198910d599adSMaya Erez 	kbuf[len] = '\0';
199010d599adSMaya Erez 	rc = sscanf(kbuf, "%d %d %d %d %d %d",
199110d599adSMaya Erez 		    &led_blink_time[WIL_LED_TIME_SLOW].on_ms,
199210d599adSMaya Erez 		    &led_blink_time[WIL_LED_TIME_SLOW].off_ms,
199310d599adSMaya Erez 		    &led_blink_time[WIL_LED_TIME_MED].on_ms,
199410d599adSMaya Erez 		    &led_blink_time[WIL_LED_TIME_MED].off_ms,
199510d599adSMaya Erez 		    &led_blink_time[WIL_LED_TIME_FAST].on_ms,
199610d599adSMaya Erez 		    &led_blink_time[WIL_LED_TIME_FAST].off_ms);
199710d599adSMaya Erez 	kfree(kbuf);
199810d599adSMaya Erez 
199910d599adSMaya Erez 	if (rc < 0)
200010d599adSMaya Erez 		return rc;
200110d599adSMaya Erez 	if (rc < 6)
200210d599adSMaya Erez 		return -EINVAL;
200310d599adSMaya Erez 
200410d599adSMaya Erez 	return len;
200510d599adSMaya Erez }
200610d599adSMaya Erez 
200710d599adSMaya Erez static ssize_t wil_read_led_blink_time(struct file *file, char __user *user_buf,
200810d599adSMaya Erez 				       size_t count, loff_t *ppos)
200910d599adSMaya Erez {
201010d599adSMaya Erez 	static char text[400];
201110d599adSMaya Erez 
201210d599adSMaya Erez 	snprintf(text, sizeof(text),
201310d599adSMaya Erez 		 "To set led blink on/off time variables write:\n"
201410d599adSMaya Erez 		 "<blink_on_slow> <blink_off_slow> <blink_on_med> "
201510d599adSMaya Erez 		 "<blink_off_med> <blink_on_fast> <blink_off_fast>\n"
201610d599adSMaya Erez 		 "The current values are:\n"
201710d599adSMaya Erez 		 "%d %d %d %d %d %d\n",
201810d599adSMaya Erez 		 led_blink_time[WIL_LED_TIME_SLOW].on_ms,
201910d599adSMaya Erez 		 led_blink_time[WIL_LED_TIME_SLOW].off_ms,
202010d599adSMaya Erez 		 led_blink_time[WIL_LED_TIME_MED].on_ms,
202110d599adSMaya Erez 		 led_blink_time[WIL_LED_TIME_MED].off_ms,
202210d599adSMaya Erez 		 led_blink_time[WIL_LED_TIME_FAST].on_ms,
202310d599adSMaya Erez 		 led_blink_time[WIL_LED_TIME_FAST].off_ms);
202410d599adSMaya Erez 
202510d599adSMaya Erez 	return simple_read_from_buffer(user_buf, count, ppos, text,
202610d599adSMaya Erez 				       sizeof(text));
202710d599adSMaya Erez }
202810d599adSMaya Erez 
202910d599adSMaya Erez static const struct file_operations fops_led_blink_time = {
203010d599adSMaya Erez 	.read = wil_read_led_blink_time,
203110d599adSMaya Erez 	.write = wil_write_led_blink_time,
203210d599adSMaya Erez 	.open  = simple_open,
203310d599adSMaya Erez };
203410d599adSMaya Erez 
203512bace75SLior David /*---------FW capabilities------------*/
203612bace75SLior David static int wil_fw_capabilities_debugfs_show(struct seq_file *s, void *data)
203712bace75SLior David {
203812bace75SLior David 	struct wil6210_priv *wil = s->private;
203912bace75SLior David 
204012bace75SLior David 	seq_printf(s, "fw_capabilities : %*pb\n", WMI_FW_CAPABILITY_MAX,
204112bace75SLior David 		   wil->fw_capabilities);
204212bace75SLior David 
204312bace75SLior David 	return 0;
204412bace75SLior David }
204512bace75SLior David 
204612bace75SLior David static int wil_fw_capabilities_seq_open(struct inode *inode, struct file *file)
204712bace75SLior David {
204812bace75SLior David 	return single_open(file, wil_fw_capabilities_debugfs_show,
204912bace75SLior David 			   inode->i_private);
205012bace75SLior David }
205112bace75SLior David 
205212bace75SLior David static const struct file_operations fops_fw_capabilities = {
205312bace75SLior David 	.open		= wil_fw_capabilities_seq_open,
205412bace75SLior David 	.release	= single_release,
205512bace75SLior David 	.read		= seq_read,
205612bace75SLior David 	.llseek		= seq_lseek,
205712bace75SLior David };
205812bace75SLior David 
205913cd9f75SLior David /*---------FW version------------*/
206013cd9f75SLior David static int wil_fw_version_debugfs_show(struct seq_file *s, void *data)
206113cd9f75SLior David {
206213cd9f75SLior David 	struct wil6210_priv *wil = s->private;
206313cd9f75SLior David 
206413cd9f75SLior David 	if (wil->fw_version[0])
206513cd9f75SLior David 		seq_printf(s, "%s\n", wil->fw_version);
206613cd9f75SLior David 	else
206713cd9f75SLior David 		seq_puts(s, "N/A\n");
206813cd9f75SLior David 
206913cd9f75SLior David 	return 0;
207013cd9f75SLior David }
207113cd9f75SLior David 
207213cd9f75SLior David static int wil_fw_version_seq_open(struct inode *inode, struct file *file)
207313cd9f75SLior David {
207413cd9f75SLior David 	return single_open(file, wil_fw_version_debugfs_show,
207513cd9f75SLior David 			   inode->i_private);
207613cd9f75SLior David }
207713cd9f75SLior David 
207813cd9f75SLior David static const struct file_operations fops_fw_version = {
207913cd9f75SLior David 	.open		= wil_fw_version_seq_open,
208013cd9f75SLior David 	.release	= single_release,
208113cd9f75SLior David 	.read		= seq_read,
208213cd9f75SLior David 	.llseek		= seq_lseek,
208313cd9f75SLior David };
208413cd9f75SLior David 
2085fe9ee51eSMaya Erez /*---------suspend_stats---------*/
2086fe9ee51eSMaya Erez static ssize_t wil_write_suspend_stats(struct file *file,
2087fe9ee51eSMaya Erez 				       const char __user *buf,
2088fe9ee51eSMaya Erez 				       size_t len, loff_t *ppos)
2089fe9ee51eSMaya Erez {
2090fe9ee51eSMaya Erez 	struct wil6210_priv *wil = file->private_data;
2091fe9ee51eSMaya Erez 
2092fe9ee51eSMaya Erez 	memset(&wil->suspend_stats, 0, sizeof(wil->suspend_stats));
2093fe9ee51eSMaya Erez 
2094fe9ee51eSMaya Erez 	return len;
2095fe9ee51eSMaya Erez }
2096fe9ee51eSMaya Erez 
2097fe9ee51eSMaya Erez static ssize_t wil_read_suspend_stats(struct file *file,
2098fe9ee51eSMaya Erez 				      char __user *user_buf,
2099fe9ee51eSMaya Erez 				      size_t count, loff_t *ppos)
2100fe9ee51eSMaya Erez {
2101fe9ee51eSMaya Erez 	struct wil6210_priv *wil = file->private_data;
2102bd8bdc6cSLazar Alexei 	char *text;
2103bd8bdc6cSLazar Alexei 	int n, ret, text_size = 500;
2104fe9ee51eSMaya Erez 
2105bd8bdc6cSLazar Alexei 	text = kmalloc(text_size, GFP_KERNEL);
2106bd8bdc6cSLazar Alexei 	if (!text)
2107bd8bdc6cSLazar Alexei 		return -ENOMEM;
2108bd8bdc6cSLazar Alexei 
2109bd8bdc6cSLazar Alexei 	n = snprintf(text, text_size,
2110bd8bdc6cSLazar Alexei 		     "Radio on suspend statistics:\n"
2111fe9ee51eSMaya Erez 		     "successful suspends:%ld failed suspends:%ld\n"
2112fe9ee51eSMaya Erez 		     "successful resumes:%ld failed resumes:%ld\n"
2113bd8bdc6cSLazar Alexei 		     "rejected by device:%ld\n"
2114bd8bdc6cSLazar Alexei 		     "Radio off suspend statistics:\n"
2115bd8bdc6cSLazar Alexei 		     "successful suspends:%ld failed suspends:%ld\n"
2116bd8bdc6cSLazar Alexei 		     "successful resumes:%ld failed resumes:%ld\n"
2117bd8bdc6cSLazar Alexei 		     "General statistics:\n"
2118bd8bdc6cSLazar Alexei 		     "rejected by host:%ld\n",
2119bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_on.successful_suspends,
2120bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_on.failed_suspends,
2121bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_on.successful_resumes,
2122bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_on.failed_resumes,
2123bd8bdc6cSLazar Alexei 		     wil->suspend_stats.rejected_by_device,
2124bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_off.successful_suspends,
2125bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_off.failed_suspends,
2126bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_off.successful_resumes,
2127bd8bdc6cSLazar Alexei 		     wil->suspend_stats.r_off.failed_resumes,
2128bd8bdc6cSLazar Alexei 		     wil->suspend_stats.rejected_by_host);
2129fe9ee51eSMaya Erez 
2130bd8bdc6cSLazar Alexei 	n = min_t(int, n, text_size);
2131fe9ee51eSMaya Erez 
2132bd8bdc6cSLazar Alexei 	ret = simple_read_from_buffer(user_buf, count, ppos, text, n);
2133bd8bdc6cSLazar Alexei 
2134bd8bdc6cSLazar Alexei 	kfree(text);
2135bd8bdc6cSLazar Alexei 
2136bd8bdc6cSLazar Alexei 	return ret;
2137fe9ee51eSMaya Erez }
2138fe9ee51eSMaya Erez 
2139fe9ee51eSMaya Erez static const struct file_operations fops_suspend_stats = {
2140fe9ee51eSMaya Erez 	.read = wil_read_suspend_stats,
2141fe9ee51eSMaya Erez 	.write = wil_write_suspend_stats,
2142fe9ee51eSMaya Erez 	.open  = simple_open,
2143fe9ee51eSMaya Erez };
2144fe9ee51eSMaya Erez 
214596c93589SGidon Studinski /*---------compressed_rx_status---------*/
214696c93589SGidon Studinski static ssize_t wil_compressed_rx_status_write(struct file *file,
214796c93589SGidon Studinski 					      const char __user *buf,
214896c93589SGidon Studinski 					      size_t len, loff_t *ppos)
214996c93589SGidon Studinski {
215096c93589SGidon Studinski 	struct seq_file *s = file->private_data;
215196c93589SGidon Studinski 	struct wil6210_priv *wil = s->private;
215296c93589SGidon Studinski 	int compressed_rx_status;
215396c93589SGidon Studinski 	int rc;
215496c93589SGidon Studinski 
215596c93589SGidon Studinski 	rc = kstrtoint_from_user(buf, len, 0, &compressed_rx_status);
215696c93589SGidon Studinski 	if (rc) {
215796c93589SGidon Studinski 		wil_err(wil, "Invalid argument\n");
215896c93589SGidon Studinski 		return rc;
215996c93589SGidon Studinski 	}
216096c93589SGidon Studinski 
216196c93589SGidon Studinski 	if (wil_has_active_ifaces(wil, true, false)) {
216296c93589SGidon Studinski 		wil_err(wil, "cannot change edma config after iface is up\n");
216396c93589SGidon Studinski 		return -EPERM;
216496c93589SGidon Studinski 	}
216596c93589SGidon Studinski 
216696c93589SGidon Studinski 	wil_info(wil, "%sable compressed_rx_status\n",
216796c93589SGidon Studinski 		 compressed_rx_status ? "En" : "Dis");
216896c93589SGidon Studinski 
216996c93589SGidon Studinski 	wil->use_compressed_rx_status = compressed_rx_status;
217096c93589SGidon Studinski 
217196c93589SGidon Studinski 	return len;
217296c93589SGidon Studinski }
217396c93589SGidon Studinski 
217496c93589SGidon Studinski static int
217596c93589SGidon Studinski wil_compressed_rx_status_show(struct seq_file *s, void *data)
217696c93589SGidon Studinski {
217796c93589SGidon Studinski 	struct wil6210_priv *wil = s->private;
217896c93589SGidon Studinski 
217996c93589SGidon Studinski 	seq_printf(s, "%d\n", wil->use_compressed_rx_status);
218096c93589SGidon Studinski 
218196c93589SGidon Studinski 	return 0;
218296c93589SGidon Studinski }
218396c93589SGidon Studinski 
218496c93589SGidon Studinski static int
218596c93589SGidon Studinski wil_compressed_rx_status_seq_open(struct inode *inode, struct file *file)
218696c93589SGidon Studinski {
218796c93589SGidon Studinski 	return single_open(file, wil_compressed_rx_status_show,
218896c93589SGidon Studinski 			   inode->i_private);
218996c93589SGidon Studinski }
219096c93589SGidon Studinski 
219196c93589SGidon Studinski static const struct file_operations fops_compressed_rx_status = {
219296c93589SGidon Studinski 	.open  = wil_compressed_rx_status_seq_open,
219396c93589SGidon Studinski 	.release = single_release,
219496c93589SGidon Studinski 	.read = seq_read,
219596c93589SGidon Studinski 	.write = wil_compressed_rx_status_write,
219696c93589SGidon Studinski 	.llseek	= seq_lseek,
219796c93589SGidon Studinski };
219896c93589SGidon Studinski 
21992be7d22fSVladimir Kondratiev /*----------------*/
2200b541d0a0SVladimir Kondratiev static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
2201b541d0a0SVladimir Kondratiev 				       struct dentry *dbg)
2202b541d0a0SVladimir Kondratiev {
2203b541d0a0SVladimir Kondratiev 	int i;
2204b541d0a0SVladimir Kondratiev 	char name[32];
2205b541d0a0SVladimir Kondratiev 
2206b541d0a0SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
2207349214c1SMaya Erez 		struct wil_blob_wrapper *wil_blob = &wil->blobs[i];
2208349214c1SMaya Erez 		struct debugfs_blob_wrapper *blob = &wil_blob->blob;
2209b541d0a0SVladimir Kondratiev 		const struct fw_map *map = &fw_mapping[i];
2210b541d0a0SVladimir Kondratiev 
2211b541d0a0SVladimir Kondratiev 		if (!map->name)
2212b541d0a0SVladimir Kondratiev 			continue;
2213b541d0a0SVladimir Kondratiev 
2214349214c1SMaya Erez 		wil_blob->wil = wil;
2215b541d0a0SVladimir Kondratiev 		blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
2216b541d0a0SVladimir Kondratiev 		blob->size = map->to - map->from;
2217b541d0a0SVladimir Kondratiev 		snprintf(name, sizeof(name), "blob_%s", map->name);
221878484c44SMaya Erez 		wil_debugfs_create_ioblob(name, 0444, dbg, wil_blob);
2219b541d0a0SVladimir Kondratiev 	}
2220b541d0a0SVladimir Kondratiev }
2221b541d0a0SVladimir Kondratiev 
2222b7cde470SVladimir Kondratiev /* misc files */
2223b7cde470SVladimir Kondratiev static const struct {
2224b7cde470SVladimir Kondratiev 	const char *name;
2225b7cde470SVladimir Kondratiev 	umode_t mode;
2226b7cde470SVladimir Kondratiev 	const struct file_operations *fops;
2227b7cde470SVladimir Kondratiev } dbg_files[] = {
222878484c44SMaya Erez 	{"mbox",	0444,		&fops_mbox},
222910590c6aSGidon Studinski 	{"rings",	0444,		&fops_ring},
223078484c44SMaya Erez 	{"stations", 0444,		&fops_sta},
22313a3b745fSLior David 	{"mids",	0444,		&fops_mids},
223278484c44SMaya Erez 	{"desc",	0444,		&fops_txdesc},
223378484c44SMaya Erez 	{"bf",		0444,		&fops_bf},
223478484c44SMaya Erez 	{"mem_val",	0644,		&fops_memread},
223578484c44SMaya Erez 	{"reset",	0244,		&fops_reset},
223678484c44SMaya Erez 	{"rxon",	0244,		&fops_rxon},
223778484c44SMaya Erez 	{"tx_mgmt",	0244,		&fops_txmgmt},
223878484c44SMaya Erez 	{"wmi_send", 0244,		&fops_wmi},
223978484c44SMaya Erez 	{"back",	0644,		&fops_back},
224078484c44SMaya Erez 	{"pmccfg",	0644,		&fops_pmccfg},
224178484c44SMaya Erez 	{"pmcdata",	0444,		&fops_pmcdata},
224278484c44SMaya Erez 	{"temp",	0444,		&fops_temp},
224378484c44SMaya Erez 	{"freq",	0444,		&fops_freq},
224478484c44SMaya Erez 	{"link",	0444,		&fops_link},
224578484c44SMaya Erez 	{"info",	0444,		&fops_info},
224678484c44SMaya Erez 	{"recovery", 0644,		&fops_recovery},
224778484c44SMaya Erez 	{"led_cfg",	0644,		&fops_led_cfg},
224878484c44SMaya Erez 	{"led_blink_time",	0644,	&fops_led_blink_time},
224978484c44SMaya Erez 	{"fw_capabilities",	0444,	&fops_fw_capabilities},
225078484c44SMaya Erez 	{"fw_version",	0444,		&fops_fw_version},
2251fe9ee51eSMaya Erez 	{"suspend_stats",	0644,	&fops_suspend_stats},
225296c93589SGidon Studinski 	{"compressed_rx_status", 0644,	&fops_compressed_rx_status},
2253d98b8539SMaya Erez 	{"srings",	0444,		&fops_srings},
2254d98b8539SMaya Erez 	{"status_msg",	0444,		&fops_status_msg},
2255d98b8539SMaya Erez 	{"rx_buff_mgmt",	0444,	&fops_rx_buff_mgmt},
2256*a24a3d6aSDedy Lansky 	{"tx_latency",	0644,		&fops_tx_latency},
2257b7cde470SVladimir Kondratiev };
2258b7cde470SVladimir Kondratiev 
2259b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
2260b7cde470SVladimir Kondratiev 				       struct dentry *dbg)
2261b7cde470SVladimir Kondratiev {
2262b7cde470SVladimir Kondratiev 	int i;
2263b7cde470SVladimir Kondratiev 
2264b7cde470SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
2265b7cde470SVladimir Kondratiev 		debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
2266b7cde470SVladimir Kondratiev 				    wil, dbg_files[i].fops);
2267b7cde470SVladimir Kondratiev }
2268b7cde470SVladimir Kondratiev 
2269b7cde470SVladimir Kondratiev /* interrupt control blocks */
2270b7cde470SVladimir Kondratiev static const struct {
2271b7cde470SVladimir Kondratiev 	const char *name;
2272b7cde470SVladimir Kondratiev 	u32 icr_off;
2273b7cde470SVladimir Kondratiev } dbg_icr[] = {
2274b7cde470SVladimir Kondratiev 	{"USER_ICR",		HOSTADDR(RGF_USER_USER_ICR)},
2275b7cde470SVladimir Kondratiev 	{"DMA_EP_TX_ICR",	HOSTADDR(RGF_DMA_EP_TX_ICR)},
2276b7cde470SVladimir Kondratiev 	{"DMA_EP_RX_ICR",	HOSTADDR(RGF_DMA_EP_RX_ICR)},
2277b7cde470SVladimir Kondratiev 	{"DMA_EP_MISC_ICR",	HOSTADDR(RGF_DMA_EP_MISC_ICR)},
2278b7cde470SVladimir Kondratiev };
2279b7cde470SVladimir Kondratiev 
2280b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
2281b7cde470SVladimir Kondratiev 				     struct dentry *dbg)
2282b7cde470SVladimir Kondratiev {
2283b7cde470SVladimir Kondratiev 	int i;
2284b7cde470SVladimir Kondratiev 
2285b7cde470SVladimir Kondratiev 	for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
2286b7cde470SVladimir Kondratiev 		wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
2287b7cde470SVladimir Kondratiev 					   dbg_icr[i].icr_off);
2288b7cde470SVladimir Kondratiev }
2289b7cde470SVladimir Kondratiev 
2290b7cde470SVladimir Kondratiev #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
2291b7cde470SVladimir Kondratiev 	offsetof(struct wil6210_priv, name), type}
2292b7cde470SVladimir Kondratiev 
2293b7cde470SVladimir Kondratiev /* fields in struct wil6210_priv */
2294b7cde470SVladimir Kondratiev static const struct dbg_off dbg_wil_off[] = {
229578484c44SMaya Erez 	WIL_FIELD(status[0],	0644,	doff_ulong),
229678484c44SMaya Erez 	WIL_FIELD(hw_version,	0444,	doff_x32),
229778484c44SMaya Erez 	WIL_FIELD(recovery_count, 0444,	doff_u32),
229878484c44SMaya Erez 	WIL_FIELD(discovery_mode, 0644,	doff_u8),
229978484c44SMaya Erez 	WIL_FIELD(chip_revision, 0444,	doff_u8),
230078484c44SMaya Erez 	WIL_FIELD(abft_len, 0644,		doff_u8),
2301fe9ee51eSMaya Erez 	WIL_FIELD(wakeup_trigger, 0644,		doff_u8),
230210590c6aSGidon Studinski 	WIL_FIELD(ring_idle_trsh, 0644,	doff_u32),
230396c93589SGidon Studinski 	WIL_FIELD(num_rx_status_rings, 0644,	doff_u8),
230496c93589SGidon Studinski 	WIL_FIELD(rx_status_ring_order, 0644,	doff_u32),
230596c93589SGidon Studinski 	WIL_FIELD(tx_status_ring_order, 0644,	doff_u32),
230696c93589SGidon Studinski 	WIL_FIELD(rx_buff_id_count, 0644,	doff_u32),
23077be13fc3SGidon Studinski 	WIL_FIELD(amsdu_en, 0644,	doff_u8),
2308b7cde470SVladimir Kondratiev 	{},
2309b7cde470SVladimir Kondratiev };
2310b7cde470SVladimir Kondratiev 
2311b7cde470SVladimir Kondratiev static const struct dbg_off dbg_wil_regs[] = {
231278484c44SMaya Erez 	{"RGF_MAC_MTRL_COUNTER_0", 0444, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
2313b7cde470SVladimir Kondratiev 		doff_io32},
231478484c44SMaya Erez 	{"RGF_USER_USAGE_1", 0444, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
2315b7cde470SVladimir Kondratiev 	{},
2316b7cde470SVladimir Kondratiev };
2317b7cde470SVladimir Kondratiev 
2318b7cde470SVladimir Kondratiev /* static parameters */
2319b7cde470SVladimir Kondratiev static const struct dbg_off dbg_statics[] = {
232078484c44SMaya Erez 	{"desc_index",	0644, (ulong)&dbg_txdesc_index, doff_u32},
232110590c6aSGidon Studinski 	{"ring_index",	0644, (ulong)&dbg_ring_index, doff_u32},
232278484c44SMaya Erez 	{"mem_addr",	0644, (ulong)&mem_addr, doff_u32},
232378484c44SMaya Erez 	{"led_polarity", 0644, (ulong)&led_polarity, doff_u8},
2324d98b8539SMaya Erez 	{"status_index", 0644, (ulong)&dbg_status_msg_index, doff_u32},
2325d98b8539SMaya Erez 	{"sring_index",	0644, (ulong)&dbg_sring_index, doff_u32},
2326b7cde470SVladimir Kondratiev 	{},
2327b7cde470SVladimir Kondratiev };
2328b7cde470SVladimir Kondratiev 
232994162666SLazar Alexei static const int dbg_off_count = 4 * (ARRAY_SIZE(isr_off) - 1) +
233094162666SLazar Alexei 				ARRAY_SIZE(dbg_wil_regs) - 1 +
233194162666SLazar Alexei 				ARRAY_SIZE(pseudo_isr_off) - 1 +
233294162666SLazar Alexei 				ARRAY_SIZE(lgc_itr_cnt_off) - 1 +
233394162666SLazar Alexei 				ARRAY_SIZE(tx_itr_cnt_off) - 1 +
233494162666SLazar Alexei 				ARRAY_SIZE(rx_itr_cnt_off) - 1;
233594162666SLazar Alexei 
23362be7d22fSVladimir Kondratiev int wil6210_debugfs_init(struct wil6210_priv *wil)
23372be7d22fSVladimir Kondratiev {
23382be7d22fSVladimir Kondratiev 	struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
23392be7d22fSVladimir Kondratiev 			wil_to_wiphy(wil)->debugfsdir);
23402be7d22fSVladimir Kondratiev 	if (IS_ERR_OR_NULL(dbg))
23412be7d22fSVladimir Kondratiev 		return -ENODEV;
23422be7d22fSVladimir Kondratiev 
234394162666SLazar Alexei 	wil->dbg_data.data_arr = kcalloc(dbg_off_count,
234494162666SLazar Alexei 					 sizeof(struct wil_debugfs_iomem_data),
234594162666SLazar Alexei 					 GFP_KERNEL);
234694162666SLazar Alexei 	if (!wil->dbg_data.data_arr) {
234794162666SLazar Alexei 		debugfs_remove_recursive(dbg);
234894162666SLazar Alexei 		wil->debug = NULL;
234994162666SLazar Alexei 		return -ENOMEM;
235094162666SLazar Alexei 	}
235194162666SLazar Alexei 
235294162666SLazar Alexei 	wil->dbg_data.iomem_data_count = 0;
235394162666SLazar Alexei 
2354dc16427bSVladimir Kondratiev 	wil_pmc_init(wil);
2355dc16427bSVladimir Kondratiev 
2356b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_files(wil, dbg);
2357b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_isr(wil, dbg);
2358b541d0a0SVladimir Kondratiev 	wil6210_debugfs_init_blobs(wil, dbg);
2359b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
2360b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
2361b7cde470SVladimir Kondratiev 				    dbg_wil_regs);
2362b7cde470SVladimir Kondratiev 	wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
2363b7cde470SVladimir Kondratiev 
2364b7cde470SVladimir Kondratiev 	wil6210_debugfs_create_pseudo_ISR(wil, dbg);
2365b7cde470SVladimir Kondratiev 
2366b7cde470SVladimir Kondratiev 	wil6210_debugfs_create_ITR_CNT(wil, dbg);
23672be7d22fSVladimir Kondratiev 
23682be7d22fSVladimir Kondratiev 	return 0;
23692be7d22fSVladimir Kondratiev }
23702be7d22fSVladimir Kondratiev 
23712be7d22fSVladimir Kondratiev void wil6210_debugfs_remove(struct wil6210_priv *wil)
23722be7d22fSVladimir Kondratiev {
2373*a24a3d6aSDedy Lansky 	int i;
2374*a24a3d6aSDedy Lansky 
23752be7d22fSVladimir Kondratiev 	debugfs_remove_recursive(wil->debug);
23762be7d22fSVladimir Kondratiev 	wil->debug = NULL;
2377dc16427bSVladimir Kondratiev 
237894162666SLazar Alexei 	kfree(wil->dbg_data.data_arr);
2379*a24a3d6aSDedy Lansky 	for (i = 0; i < ARRAY_SIZE(wil->sta); i++)
2380*a24a3d6aSDedy Lansky 		kfree(wil->sta[i].tx_latency_bins);
238194162666SLazar Alexei 
2382dc16427bSVladimir Kondratiev 	/* free pmc memory without sending command to fw, as it will
2383dc16427bSVladimir Kondratiev 	 * be reset on the way down anyway
2384dc16427bSVladimir Kondratiev 	 */
2385dc16427bSVladimir Kondratiev 	wil_pmc_free(wil, false);
23862be7d22fSVladimir Kondratiev }
2387