185630469SLior David // SPDX-License-Identifier: ISC
22be7d22fSVladimir Kondratiev /*
3a351f2f5SLazar Alexei * Copyright (c) 2012-2017 Qualcomm Atheros, Inc.
40439a5e0SDedy Lansky * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
52be7d22fSVladimir Kondratiev */
62be7d22fSVladimir Kondratiev
72be7d22fSVladimir Kondratiev #include <linux/module.h>
82be7d22fSVladimir Kondratiev #include <linux/debugfs.h>
92be7d22fSVladimir Kondratiev #include <linux/seq_file.h>
102be7d22fSVladimir Kondratiev #include <linux/pci.h>
112be7d22fSVladimir Kondratiev #include <linux/rtnetlink.h>
1284bb29b7SVladimir Kondratiev #include <linux/power_supply.h>
132be7d22fSVladimir Kondratiev #include "wil6210.h"
1436345ac3SVladimir Kondratiev #include "wmi.h"
152be7d22fSVladimir Kondratiev #include "txrx.h"
16dc16427bSVladimir Kondratiev #include "pmc.h"
172be7d22fSVladimir Kondratiev
182be7d22fSVladimir Kondratiev /* Nasty hack. Better have per device instances */
192be7d22fSVladimir Kondratiev static u32 mem_addr;
202be7d22fSVladimir Kondratiev static u32 dbg_txdesc_index;
2110590c6aSGidon Studinski static u32 dbg_ring_index; /* 24+ for Rx, 0..23 for Tx */
22d98b8539SMaya Erez static u32 dbg_status_msg_index;
23d98b8539SMaya Erez /* 0..wil->num_rx_status_rings-1 for Rx, wil->tx_sring_idx for Tx */
24d98b8539SMaya Erez static u32 dbg_sring_index;
252be7d22fSVladimir Kondratiev
26b7cde470SVladimir Kondratiev enum dbg_off_type {
27b7cde470SVladimir Kondratiev doff_u32 = 0,
28b7cde470SVladimir Kondratiev doff_x32 = 1,
29b7cde470SVladimir Kondratiev doff_ulong = 2,
30b7cde470SVladimir Kondratiev doff_io32 = 3,
3174997a53SLior David doff_u8 = 4
32b7cde470SVladimir Kondratiev };
33b7cde470SVladimir Kondratiev
34b7cde470SVladimir Kondratiev /* offset to "wil" */
35b7cde470SVladimir Kondratiev struct dbg_off {
36b7cde470SVladimir Kondratiev const char *name;
37b7cde470SVladimir Kondratiev umode_t mode;
38b7cde470SVladimir Kondratiev ulong off;
39b7cde470SVladimir Kondratiev enum dbg_off_type type;
40b7cde470SVladimir Kondratiev };
41b7cde470SVladimir Kondratiev
wil_print_desc_edma(struct seq_file * s,struct wil6210_priv * wil,struct wil_ring * ring,char _s,char _h,int idx)42d98b8539SMaya Erez static void wil_print_desc_edma(struct seq_file *s, struct wil6210_priv *wil,
43d98b8539SMaya Erez struct wil_ring *ring,
44d98b8539SMaya Erez char _s, char _h, int idx)
45d98b8539SMaya Erez {
46d98b8539SMaya Erez u8 num_of_descs;
47d98b8539SMaya Erez bool has_skb = false;
48d98b8539SMaya Erez
49d98b8539SMaya Erez if (ring->is_rx) {
50d98b8539SMaya Erez struct wil_rx_enhanced_desc *rx_d =
51d98b8539SMaya Erez (struct wil_rx_enhanced_desc *)
52d98b8539SMaya Erez &ring->va[idx].rx.enhanced;
53d98b8539SMaya Erez u16 buff_id = le16_to_cpu(rx_d->mac.buff_id);
54d98b8539SMaya Erez
559a874d04SDedy Lansky if (wil->rx_buff_mgmt.buff_arr &&
569a874d04SDedy Lansky wil_val_in_range(buff_id, 0, wil->rx_buff_mgmt.size))
57d98b8539SMaya Erez has_skb = wil->rx_buff_mgmt.buff_arr[buff_id].skb;
58d98b8539SMaya Erez seq_printf(s, "%c", (has_skb) ? _h : _s);
59d98b8539SMaya Erez } else {
60d98b8539SMaya Erez struct wil_tx_enhanced_desc *d =
61d98b8539SMaya Erez (struct wil_tx_enhanced_desc *)
62d98b8539SMaya Erez &ring->va[idx].tx.enhanced;
63d98b8539SMaya Erez
64d98b8539SMaya Erez num_of_descs = (u8)d->mac.d[2];
659a874d04SDedy Lansky has_skb = ring->ctx && ring->ctx[idx].skb;
66d98b8539SMaya Erez if (num_of_descs >= 1)
679a874d04SDedy Lansky seq_printf(s, "%c", has_skb ? _h : _s);
68d98b8539SMaya Erez else
69d98b8539SMaya Erez /* num_of_descs == 0, it's a frag in a list of descs */
70d98b8539SMaya Erez seq_printf(s, "%c", has_skb ? 'h' : _s);
71d98b8539SMaya Erez }
72d98b8539SMaya Erez }
73d98b8539SMaya Erez
wil_print_ring(struct seq_file * s,struct wil6210_priv * wil,const char * name,struct wil_ring * ring,char _s,char _h)7410590c6aSGidon Studinski static void wil_print_ring(struct seq_file *s, struct wil6210_priv *wil,
7510590c6aSGidon Studinski const char *name, struct wil_ring *ring,
7659f7c0a9SVladimir Kondratiev char _s, char _h)
772be7d22fSVladimir Kondratiev {
789a874d04SDedy Lansky void __iomem *x;
79995cdd0eSVladimir Kondratiev u32 v;
802be7d22fSVladimir Kondratiev
8110590c6aSGidon Studinski seq_printf(s, "RING %s = {\n", name);
8210590c6aSGidon Studinski seq_printf(s, " pa = %pad\n", &ring->pa);
8310590c6aSGidon Studinski seq_printf(s, " va = 0x%p\n", ring->va);
8410590c6aSGidon Studinski seq_printf(s, " size = %d\n", ring->size);
85d98b8539SMaya Erez if (wil->use_enhanced_dma_hw && ring->is_rx)
86d98b8539SMaya Erez seq_printf(s, " swtail = %u\n", *ring->edma_rx_swtail.va);
87d98b8539SMaya Erez else
8810590c6aSGidon Studinski seq_printf(s, " swtail = %d\n", ring->swtail);
8910590c6aSGidon Studinski seq_printf(s, " swhead = %d\n", ring->swhead);
909a874d04SDedy Lansky if (wil->use_enhanced_dma_hw) {
919a874d04SDedy Lansky int ring_id = ring->is_rx ?
929a874d04SDedy Lansky WIL_RX_DESC_RING_ID : ring - wil->ring_tx;
939a874d04SDedy Lansky /* SUBQ_CONS is a table of 32 entries, one for each Q pair.
949a874d04SDedy Lansky * lower 16bits are for even ring_id and upper 16bits are for
959a874d04SDedy Lansky * odd ring_id
969a874d04SDedy Lansky */
979a874d04SDedy Lansky x = wmi_addr(wil, RGF_DMA_SCM_SUBQ_CONS + 4 * (ring_id / 2));
989a874d04SDedy Lansky v = readl_relaxed(x);
999a874d04SDedy Lansky
1009a874d04SDedy Lansky v = (ring_id % 2 ? (v >> 16) : (v & 0xffff));
1019a874d04SDedy Lansky seq_printf(s, " hwhead = %u\n", v);
1029a874d04SDedy Lansky }
10310590c6aSGidon Studinski seq_printf(s, " hwtail = [0x%08x] -> ", ring->hwtail);
1049a874d04SDedy Lansky x = wmi_addr(wil, ring->hwtail);
105995cdd0eSVladimir Kondratiev if (x) {
106b9eeb512SVladimir Kondratiev v = readl(x);
107995cdd0eSVladimir Kondratiev seq_printf(s, "0x%08x = %d\n", v, v);
108995cdd0eSVladimir Kondratiev } else {
1098fe59627SVladimir Kondratiev seq_puts(s, "???\n");
110995cdd0eSVladimir Kondratiev }
1112be7d22fSVladimir Kondratiev
11210590c6aSGidon Studinski if (ring->va && (ring->size <= (1 << WIL_RING_SIZE_ORDER_MAX))) {
1132be7d22fSVladimir Kondratiev uint i;
1148fe59627SVladimir Kondratiev
11510590c6aSGidon Studinski for (i = 0; i < ring->size; i++) {
116d98b8539SMaya Erez if ((i % 128) == 0 && i != 0)
117d98b8539SMaya Erez seq_puts(s, "\n");
118d98b8539SMaya Erez if (wil->use_enhanced_dma_hw) {
119d98b8539SMaya Erez wil_print_desc_edma(s, wil, ring, _s, _h, i);
120d98b8539SMaya Erez } else {
12110590c6aSGidon Studinski volatile struct vring_tx_desc *d =
12210590c6aSGidon Studinski &ring->va[i].tx.legacy;
12359f7c0a9SVladimir Kondratiev seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
12410590c6aSGidon Studinski _s : (ring->ctx[i].skb ? _h : 'h'));
1252be7d22fSVladimir Kondratiev }
126d98b8539SMaya Erez }
1278fe59627SVladimir Kondratiev seq_puts(s, "\n");
1282be7d22fSVladimir Kondratiev }
1298fe59627SVladimir Kondratiev seq_puts(s, "}\n");
1302be7d22fSVladimir Kondratiev }
1312be7d22fSVladimir Kondratiev
ring_show(struct seq_file * s,void * data)132986b8348SYangtao Li static int ring_show(struct seq_file *s, void *data)
1332be7d22fSVladimir Kondratiev {
1342be7d22fSVladimir Kondratiev uint i;
1352be7d22fSVladimir Kondratiev struct wil6210_priv *wil = s->private;
1362be7d22fSVladimir Kondratiev
13710590c6aSGidon Studinski wil_print_ring(s, wil, "rx", &wil->ring_rx, 'S', '_');
1382be7d22fSVladimir Kondratiev
13910590c6aSGidon Studinski for (i = 0; i < ARRAY_SIZE(wil->ring_tx); i++) {
14010590c6aSGidon Studinski struct wil_ring *ring = &wil->ring_tx[i];
14110590c6aSGidon Studinski struct wil_ring_tx_data *txdata = &wil->ring_tx_data[i];
1427c0acf86SVladimir Kondratiev
14310590c6aSGidon Studinski if (ring->va) {
14410590c6aSGidon Studinski int cid = wil->ring2cid_tid[i][0];
14510590c6aSGidon Studinski int tid = wil->ring2cid_tid[i][1];
14610590c6aSGidon Studinski u32 swhead = ring->swhead;
14710590c6aSGidon Studinski u32 swtail = ring->swtail;
14810590c6aSGidon Studinski int used = (ring->size + swhead - swtail)
14910590c6aSGidon Studinski % ring->size;
15010590c6aSGidon Studinski int avail = ring->size - used - 1;
1512be7d22fSVladimir Kondratiev char name[10];
1528f55cbecSBoris Sorochkin char sidle[10];
1537c0acf86SVladimir Kondratiev /* performance monitoring */
1547c0acf86SVladimir Kondratiev cycles_t now = get_cycles();
155c20e7789SChen Gang uint64_t idle = txdata->idle * 100;
156c20e7789SChen Gang uint64_t total = now - txdata->begin;
1577c0acf86SVladimir Kondratiev
1588f55cbecSBoris Sorochkin if (total != 0) {
159e48b1790SVladimir Kondratiev do_div(idle, total);
1608f55cbecSBoris Sorochkin snprintf(sidle, sizeof(sidle), "%3d%%",
1618f55cbecSBoris Sorochkin (int)idle);
1628f55cbecSBoris Sorochkin } else {
1638f55cbecSBoris Sorochkin snprintf(sidle, sizeof(sidle), "N/A");
1648f55cbecSBoris Sorochkin }
1657c0acf86SVladimir Kondratiev txdata->begin = now;
1667c0acf86SVladimir Kondratiev txdata->idle = 0ULL;
1677c0acf86SVladimir Kondratiev
1682be7d22fSVladimir Kondratiev snprintf(name, sizeof(name), "tx_%2d", i);
1693df2cd36SVladimir Kondratiev
170ddf7afddSAhmad Masri if (cid < wil->max_assoc_sta)
1713277213fSVladimir Kondratiev seq_printf(s,
172230d8442SVladimir Kondratiev "\n%pM CID %d TID %d 1x%s BACK([%u] %u TU A%s) [%3d|%3d] idle %s\n",
1733277213fSVladimir Kondratiev wil->sta[cid].addr, cid, tid,
174230d8442SVladimir Kondratiev txdata->dot1x_open ? "+" : "-",
17541d6b093SVladimir Kondratiev txdata->agg_wsize,
17641d6b093SVladimir Kondratiev txdata->agg_timeout,
177cbcf5866SVladimir Kondratiev txdata->agg_amsdu ? "+" : "-",
1788f55cbecSBoris Sorochkin used, avail, sidle);
17941d6b093SVladimir Kondratiev else
18041d6b093SVladimir Kondratiev seq_printf(s,
181230d8442SVladimir Kondratiev "\nBroadcast 1x%s [%3d|%3d] idle %s\n",
182230d8442SVladimir Kondratiev txdata->dot1x_open ? "+" : "-",
18341d6b093SVladimir Kondratiev used, avail, sidle);
1847c0acf86SVladimir Kondratiev
18510590c6aSGidon Studinski wil_print_ring(s, wil, name, ring, '_', 'H');
1862be7d22fSVladimir Kondratiev }
1872be7d22fSVladimir Kondratiev }
1882be7d22fSVladimir Kondratiev
1892be7d22fSVladimir Kondratiev return 0;
1902be7d22fSVladimir Kondratiev }
191986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(ring);
1922be7d22fSVladimir Kondratiev
wil_print_sring(struct seq_file * s,struct wil6210_priv * wil,struct wil_status_ring * sring)193d98b8539SMaya Erez static void wil_print_sring(struct seq_file *s, struct wil6210_priv *wil,
194d98b8539SMaya Erez struct wil_status_ring *sring)
195d98b8539SMaya Erez {
1969a874d04SDedy Lansky void __iomem *x;
197d98b8539SMaya Erez int sring_idx = sring - wil->srings;
198d98b8539SMaya Erez u32 v;
199d98b8539SMaya Erez
200d98b8539SMaya Erez seq_printf(s, "Status Ring %s [ %d ] = {\n",
201d98b8539SMaya Erez sring->is_rx ? "RX" : "TX", sring_idx);
202d98b8539SMaya Erez seq_printf(s, " pa = %pad\n", &sring->pa);
203d98b8539SMaya Erez seq_printf(s, " va = 0x%pK\n", sring->va);
204d98b8539SMaya Erez seq_printf(s, " size = %d\n", sring->size);
205d98b8539SMaya Erez seq_printf(s, " elem_size = %zu\n", sring->elem_size);
206d98b8539SMaya Erez seq_printf(s, " swhead = %d\n", sring->swhead);
2079a874d04SDedy Lansky if (wil->use_enhanced_dma_hw) {
2089a874d04SDedy Lansky /* COMPQ_PROD is a table of 32 entries, one for each Q pair.
2099a874d04SDedy Lansky * lower 16bits are for even ring_id and upper 16bits are for
2109a874d04SDedy Lansky * odd ring_id
2119a874d04SDedy Lansky */
2129a874d04SDedy Lansky x = wmi_addr(wil, RGF_DMA_SCM_COMPQ_PROD + 4 * (sring_idx / 2));
2139a874d04SDedy Lansky v = readl_relaxed(x);
2149a874d04SDedy Lansky
2159a874d04SDedy Lansky v = (sring_idx % 2 ? (v >> 16) : (v & 0xffff));
2169a874d04SDedy Lansky seq_printf(s, " hwhead = %u\n", v);
2179a874d04SDedy Lansky }
218d98b8539SMaya Erez seq_printf(s, " hwtail = [0x%08x] -> ", sring->hwtail);
2199a874d04SDedy Lansky x = wmi_addr(wil, sring->hwtail);
220d98b8539SMaya Erez if (x) {
221d98b8539SMaya Erez v = readl_relaxed(x);
222d98b8539SMaya Erez seq_printf(s, "0x%08x = %d\n", v, v);
223d98b8539SMaya Erez } else {
224d98b8539SMaya Erez seq_puts(s, "???\n");
225d98b8539SMaya Erez }
226d98b8539SMaya Erez seq_printf(s, " desc_rdy_pol = %d\n", sring->desc_rdy_pol);
227b4a967b7SMaya Erez seq_printf(s, " invalid_buff_id_cnt = %d\n",
228b4a967b7SMaya Erez sring->invalid_buff_id_cnt);
229d98b8539SMaya Erez
230d98b8539SMaya Erez if (sring->va && (sring->size <= (1 << WIL_RING_SIZE_ORDER_MAX))) {
231d98b8539SMaya Erez uint i;
232d98b8539SMaya Erez
233d98b8539SMaya Erez for (i = 0; i < sring->size; i++) {
234d98b8539SMaya Erez u32 *sdword_0 =
235d98b8539SMaya Erez (u32 *)(sring->va + (sring->elem_size * i));
236d98b8539SMaya Erez
237d98b8539SMaya Erez if ((i % 128) == 0 && i != 0)
238d98b8539SMaya Erez seq_puts(s, "\n");
239d98b8539SMaya Erez if (i == sring->swhead)
240d98b8539SMaya Erez seq_printf(s, "%c", (*sdword_0 & BIT(31)) ?
241d98b8539SMaya Erez 'X' : 'x');
242d98b8539SMaya Erez else
243d98b8539SMaya Erez seq_printf(s, "%c", (*sdword_0 & BIT(31)) ?
244d98b8539SMaya Erez '1' : '0');
245d98b8539SMaya Erez }
246d98b8539SMaya Erez seq_puts(s, "\n");
247d98b8539SMaya Erez }
248d98b8539SMaya Erez seq_puts(s, "}\n");
249d98b8539SMaya Erez }
250d98b8539SMaya Erez
srings_show(struct seq_file * s,void * data)251986b8348SYangtao Li static int srings_show(struct seq_file *s, void *data)
252d98b8539SMaya Erez {
253d98b8539SMaya Erez struct wil6210_priv *wil = s->private;
254d98b8539SMaya Erez int i = 0;
255d98b8539SMaya Erez
256d98b8539SMaya Erez for (i = 0; i < WIL6210_MAX_STATUS_RINGS; i++)
257d98b8539SMaya Erez if (wil->srings[i].va)
258d98b8539SMaya Erez wil_print_sring(s, wil, &wil->srings[i]);
259d98b8539SMaya Erez
260d98b8539SMaya Erez return 0;
261d98b8539SMaya Erez }
262986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(srings);
263d98b8539SMaya Erez
wil_seq_hexdump(struct seq_file * s,void * p,int len,const char * prefix)264a202fbbfSAndy Shevchenko static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
265a202fbbfSAndy Shevchenko const char *prefix)
266a202fbbfSAndy Shevchenko {
267a202fbbfSAndy Shevchenko seq_hex_dump(s, prefix, DUMP_PREFIX_NONE, 16, 1, p, len, false);
268a202fbbfSAndy Shevchenko }
269a202fbbfSAndy Shevchenko
wil_print_mbox_ring(struct seq_file * s,const char * prefix,void __iomem * off)27010590c6aSGidon Studinski static void wil_print_mbox_ring(struct seq_file *s, const char *prefix,
2712be7d22fSVladimir Kondratiev void __iomem *off)
2722be7d22fSVladimir Kondratiev {
2732be7d22fSVladimir Kondratiev struct wil6210_priv *wil = s->private;
2742be7d22fSVladimir Kondratiev struct wil6210_mbox_ring r;
2752be7d22fSVladimir Kondratiev int rsize;
2762be7d22fSVladimir Kondratiev uint i;
2772be7d22fSVladimir Kondratiev
278349214c1SMaya Erez wil_halp_vote(wil);
279349214c1SMaya Erez
280a0618945SAhmad Masri if (wil_mem_access_lock(wil)) {
281a0618945SAhmad Masri wil_halp_unvote(wil);
282a0618945SAhmad Masri return;
283a0618945SAhmad Masri }
284a0618945SAhmad Masri
2852be7d22fSVladimir Kondratiev wil_memcpy_fromio_32(&r, off, sizeof(r));
2862be7d22fSVladimir Kondratiev wil_mbox_ring_le2cpus(&r);
2872be7d22fSVladimir Kondratiev /*
2882be7d22fSVladimir Kondratiev * we just read memory block from NIC. This memory may be
2892be7d22fSVladimir Kondratiev * garbage. Check validity before using it.
2902be7d22fSVladimir Kondratiev */
2912be7d22fSVladimir Kondratiev rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
2922be7d22fSVladimir Kondratiev
2932be7d22fSVladimir Kondratiev seq_printf(s, "ring %s = {\n", prefix);
2942be7d22fSVladimir Kondratiev seq_printf(s, " base = 0x%08x\n", r.base);
2952be7d22fSVladimir Kondratiev seq_printf(s, " size = 0x%04x bytes -> %d entries\n", r.size, rsize);
2962be7d22fSVladimir Kondratiev seq_printf(s, " tail = 0x%08x\n", r.tail);
2972be7d22fSVladimir Kondratiev seq_printf(s, " head = 0x%08x\n", r.head);
2982be7d22fSVladimir Kondratiev seq_printf(s, " entry size = %d\n", r.entry_size);
2992be7d22fSVladimir Kondratiev
3002be7d22fSVladimir Kondratiev if (r.size % sizeof(struct wil6210_mbox_ring_desc)) {
3012be7d22fSVladimir Kondratiev seq_printf(s, " ??? size is not multiple of %zd, garbage?\n",
3022be7d22fSVladimir Kondratiev sizeof(struct wil6210_mbox_ring_desc));
3032be7d22fSVladimir Kondratiev goto out;
3042be7d22fSVladimir Kondratiev }
3052be7d22fSVladimir Kondratiev
3062be7d22fSVladimir Kondratiev if (!wmi_addr(wil, r.base) ||
3072be7d22fSVladimir Kondratiev !wmi_addr(wil, r.tail) ||
3082be7d22fSVladimir Kondratiev !wmi_addr(wil, r.head)) {
3098fe59627SVladimir Kondratiev seq_puts(s, " ??? pointers are garbage?\n");
3102be7d22fSVladimir Kondratiev goto out;
3112be7d22fSVladimir Kondratiev }
3122be7d22fSVladimir Kondratiev
3132be7d22fSVladimir Kondratiev for (i = 0; i < rsize; i++) {
3142be7d22fSVladimir Kondratiev struct wil6210_mbox_ring_desc d;
3152be7d22fSVladimir Kondratiev struct wil6210_mbox_hdr hdr;
3162be7d22fSVladimir Kondratiev size_t delta = i * sizeof(d);
3172be7d22fSVladimir Kondratiev void __iomem *x = wil->csr + HOSTADDR(r.base) + delta;
3182be7d22fSVladimir Kondratiev
3192be7d22fSVladimir Kondratiev wil_memcpy_fromio_32(&d, x, sizeof(d));
3202be7d22fSVladimir Kondratiev
3212be7d22fSVladimir Kondratiev seq_printf(s, " [%2x] %s %s%s 0x%08x", i,
3222be7d22fSVladimir Kondratiev d.sync ? "F" : "E",
3232be7d22fSVladimir Kondratiev (r.tail - r.base == delta) ? "t" : " ",
3242be7d22fSVladimir Kondratiev (r.head - r.base == delta) ? "h" : " ",
3252be7d22fSVladimir Kondratiev le32_to_cpu(d.addr));
3262be7d22fSVladimir Kondratiev if (0 == wmi_read_hdr(wil, d.addr, &hdr)) {
3272be7d22fSVladimir Kondratiev u16 len = le16_to_cpu(hdr.len);
3288fe59627SVladimir Kondratiev
3292be7d22fSVladimir Kondratiev seq_printf(s, " -> %04x %04x %04x %02x\n",
3302be7d22fSVladimir Kondratiev le16_to_cpu(hdr.seq), len,
3312be7d22fSVladimir Kondratiev le16_to_cpu(hdr.type), hdr.flags);
3322be7d22fSVladimir Kondratiev if (len <= MAX_MBOXITEM_SIZE) {
3332be7d22fSVladimir Kondratiev unsigned char databuf[MAX_MBOXITEM_SIZE];
3342be7d22fSVladimir Kondratiev void __iomem *src = wmi_buffer(wil, d.addr) +
3352be7d22fSVladimir Kondratiev sizeof(struct wil6210_mbox_hdr);
3362be7d22fSVladimir Kondratiev /*
3372be7d22fSVladimir Kondratiev * No need to check @src for validity -
3382be7d22fSVladimir Kondratiev * we already validated @d.addr while
3392be7d22fSVladimir Kondratiev * reading header
3402be7d22fSVladimir Kondratiev */
3412be7d22fSVladimir Kondratiev wil_memcpy_fromio_32(databuf, src, len);
342a202fbbfSAndy Shevchenko wil_seq_hexdump(s, databuf, len, " : ");
3432be7d22fSVladimir Kondratiev }
3442be7d22fSVladimir Kondratiev } else {
3458fe59627SVladimir Kondratiev seq_puts(s, "\n");
3462be7d22fSVladimir Kondratiev }
3472be7d22fSVladimir Kondratiev }
3482be7d22fSVladimir Kondratiev out:
3498fe59627SVladimir Kondratiev seq_puts(s, "}\n");
350a0618945SAhmad Masri wil_mem_access_unlock(wil);
351349214c1SMaya Erez wil_halp_unvote(wil);
3522be7d22fSVladimir Kondratiev }
3532be7d22fSVladimir Kondratiev
mbox_show(struct seq_file * s,void * data)354986b8348SYangtao Li static int mbox_show(struct seq_file *s, void *data)
3552be7d22fSVladimir Kondratiev {
3562be7d22fSVladimir Kondratiev struct wil6210_priv *wil = s->private;
35794162666SLazar Alexei int ret;
35894162666SLazar Alexei
35994162666SLazar Alexei ret = wil_pm_runtime_get(wil);
36094162666SLazar Alexei if (ret < 0)
36194162666SLazar Alexei return ret;
3622be7d22fSVladimir Kondratiev
36310590c6aSGidon Studinski wil_print_mbox_ring(s, "tx", wil->csr + HOST_MBOX +
3642be7d22fSVladimir Kondratiev offsetof(struct wil6210_mbox_ctl, tx));
36510590c6aSGidon Studinski wil_print_mbox_ring(s, "rx", wil->csr + HOST_MBOX +
3662be7d22fSVladimir Kondratiev offsetof(struct wil6210_mbox_ctl, rx));
3672be7d22fSVladimir Kondratiev
36894162666SLazar Alexei wil_pm_runtime_put(wil);
36994162666SLazar Alexei
3702be7d22fSVladimir Kondratiev return 0;
3712be7d22fSVladimir Kondratiev }
372986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(mbox);
3732be7d22fSVladimir Kondratiev
wil_debugfs_iomem_x32_set(void * data,u64 val)3742be7d22fSVladimir Kondratiev static int wil_debugfs_iomem_x32_set(void *data, u64 val)
3752be7d22fSVladimir Kondratiev {
37694162666SLazar Alexei struct wil_debugfs_iomem_data *d = (struct
37794162666SLazar Alexei wil_debugfs_iomem_data *)data;
37894162666SLazar Alexei struct wil6210_priv *wil = d->wil;
37994162666SLazar Alexei int ret;
38094162666SLazar Alexei
38194162666SLazar Alexei ret = wil_pm_runtime_get(wil);
38294162666SLazar Alexei if (ret < 0)
38394162666SLazar Alexei return ret;
38494162666SLazar Alexei
3850e698cd0SLior David writel_relaxed(val, (void __iomem *)d->offset);
3860e698cd0SLior David
3872be7d22fSVladimir Kondratiev wmb(); /* make sure write propagated to HW */
3882be7d22fSVladimir Kondratiev
38994162666SLazar Alexei wil_pm_runtime_put(wil);
39094162666SLazar Alexei
3912be7d22fSVladimir Kondratiev return 0;
3922be7d22fSVladimir Kondratiev }
3932be7d22fSVladimir Kondratiev
wil_debugfs_iomem_x32_get(void * data,u64 * val)3942be7d22fSVladimir Kondratiev static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
3952be7d22fSVladimir Kondratiev {
39694162666SLazar Alexei struct wil_debugfs_iomem_data *d = (struct
39794162666SLazar Alexei wil_debugfs_iomem_data *)data;
39894162666SLazar Alexei struct wil6210_priv *wil = d->wil;
39994162666SLazar Alexei int ret;
40094162666SLazar Alexei
40194162666SLazar Alexei ret = wil_pm_runtime_get(wil);
40294162666SLazar Alexei if (ret < 0)
40394162666SLazar Alexei return ret;
40494162666SLazar Alexei
40594162666SLazar Alexei *val = readl((void __iomem *)d->offset);
40694162666SLazar Alexei
40794162666SLazar Alexei wil_pm_runtime_put(wil);
4082be7d22fSVladimir Kondratiev
4092be7d22fSVladimir Kondratiev return 0;
4102be7d22fSVladimir Kondratiev }
4112be7d22fSVladimir Kondratiev
412f9dca154SYueHaibing DEFINE_DEBUGFS_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
4132be7d22fSVladimir Kondratiev wil_debugfs_iomem_x32_set, "0x%08llx\n");
4142be7d22fSVladimir Kondratiev
wil_debugfs_create_iomem_x32(const char * name,umode_t mode,struct dentry * parent,void * value,struct wil6210_priv * wil)415ce564170SGreg Kroah-Hartman static void wil_debugfs_create_iomem_x32(const char *name, umode_t mode,
416ce564170SGreg Kroah-Hartman struct dentry *parent, void *value,
41794162666SLazar Alexei struct wil6210_priv *wil)
4182be7d22fSVladimir Kondratiev {
41994162666SLazar Alexei struct wil_debugfs_iomem_data *data = &wil->dbg_data.data_arr[
42094162666SLazar Alexei wil->dbg_data.iomem_data_count];
42194162666SLazar Alexei
42294162666SLazar Alexei data->wil = wil;
42394162666SLazar Alexei data->offset = value;
42494162666SLazar Alexei
425ce564170SGreg Kroah-Hartman debugfs_create_file_unsafe(name, mode, parent, data, &fops_iomem_x32);
42694162666SLazar Alexei wil->dbg_data.iomem_data_count++;
4272be7d22fSVladimir Kondratiev }
4282be7d22fSVladimir Kondratiev
wil_debugfs_ulong_set(void * data,u64 val)4293de6cf20SVladimir Kondratiev static int wil_debugfs_ulong_set(void *data, u64 val)
4303de6cf20SVladimir Kondratiev {
4313de6cf20SVladimir Kondratiev *(ulong *)data = val;
4323de6cf20SVladimir Kondratiev return 0;
4333de6cf20SVladimir Kondratiev }
4348fe59627SVladimir Kondratiev
wil_debugfs_ulong_get(void * data,u64 * val)4353de6cf20SVladimir Kondratiev static int wil_debugfs_ulong_get(void *data, u64 *val)
4363de6cf20SVladimir Kondratiev {
4373de6cf20SVladimir Kondratiev *val = *(ulong *)data;
4383de6cf20SVladimir Kondratiev return 0;
4393de6cf20SVladimir Kondratiev }
4408fe59627SVladimir Kondratiev
441f9dca154SYueHaibing DEFINE_DEBUGFS_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
4428ea06188SVladimir Kondratiev wil_debugfs_ulong_set, "0x%llx\n");
4433de6cf20SVladimir Kondratiev
444b7cde470SVladimir Kondratiev /**
445b7cde470SVladimir Kondratiev * wil6210_debugfs_init_offset - create set of debugfs files
44648e12d00SLee Jones * @wil: driver's context, used for printing
44748e12d00SLee Jones * @dbg: directory on the debugfs, where files will be created
44848e12d00SLee Jones * @base: base address used in address calculation
44948e12d00SLee Jones * @tbl: table with file descriptions. Should be terminated with empty element.
450b7cde470SVladimir Kondratiev *
451b7cde470SVladimir Kondratiev * Creates files accordingly to the @tbl.
452b7cde470SVladimir Kondratiev */
wil6210_debugfs_init_offset(struct wil6210_priv * wil,struct dentry * dbg,void * base,const struct dbg_off * const tbl)453b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_offset(struct wil6210_priv *wil,
454b7cde470SVladimir Kondratiev struct dentry *dbg, void *base,
455b7cde470SVladimir Kondratiev const struct dbg_off * const tbl)
456b7cde470SVladimir Kondratiev {
457b7cde470SVladimir Kondratiev int i;
458b7cde470SVladimir Kondratiev
459b7cde470SVladimir Kondratiev for (i = 0; tbl[i].name; i++) {
460b7cde470SVladimir Kondratiev switch (tbl[i].type) {
461b7cde470SVladimir Kondratiev case doff_u32:
462ce564170SGreg Kroah-Hartman debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg,
463b7cde470SVladimir Kondratiev base + tbl[i].off);
464b7cde470SVladimir Kondratiev break;
465b7cde470SVladimir Kondratiev case doff_x32:
466ce564170SGreg Kroah-Hartman debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg,
467b7cde470SVladimir Kondratiev base + tbl[i].off);
468b7cde470SVladimir Kondratiev break;
469b7cde470SVladimir Kondratiev case doff_ulong:
470ce564170SGreg Kroah-Hartman debugfs_create_file_unsafe(tbl[i].name, tbl[i].mode,
471ce564170SGreg Kroah-Hartman dbg, base + tbl[i].off,
472ce564170SGreg Kroah-Hartman &wil_fops_ulong);
473b7cde470SVladimir Kondratiev break;
474b7cde470SVladimir Kondratiev case doff_io32:
475ce564170SGreg Kroah-Hartman wil_debugfs_create_iomem_x32(tbl[i].name, tbl[i].mode,
476ce564170SGreg Kroah-Hartman dbg, base + tbl[i].off,
47794162666SLazar Alexei wil);
478b7cde470SVladimir Kondratiev break;
47974997a53SLior David case doff_u8:
480ce564170SGreg Kroah-Hartman debugfs_create_u8(tbl[i].name, tbl[i].mode, dbg,
48174997a53SLior David base + tbl[i].off);
48274997a53SLior David break;
483b7cde470SVladimir Kondratiev }
484b7cde470SVladimir Kondratiev }
485b7cde470SVladimir Kondratiev }
486b7cde470SVladimir Kondratiev
487b7cde470SVladimir Kondratiev static const struct dbg_off isr_off[] = {
48878484c44SMaya Erez {"ICC", 0644, offsetof(struct RGF_ICR, ICC), doff_io32},
48978484c44SMaya Erez {"ICR", 0644, offsetof(struct RGF_ICR, ICR), doff_io32},
49078484c44SMaya Erez {"ICM", 0644, offsetof(struct RGF_ICR, ICM), doff_io32},
49178484c44SMaya Erez {"ICS", 0244, offsetof(struct RGF_ICR, ICS), doff_io32},
49278484c44SMaya Erez {"IMV", 0644, offsetof(struct RGF_ICR, IMV), doff_io32},
49378484c44SMaya Erez {"IMS", 0244, offsetof(struct RGF_ICR, IMS), doff_io32},
49478484c44SMaya Erez {"IMC", 0244, offsetof(struct RGF_ICR, IMC), doff_io32},
495b7cde470SVladimir Kondratiev {},
496b7cde470SVladimir Kondratiev };
4978fe59627SVladimir Kondratiev
wil6210_debugfs_create_ISR(struct wil6210_priv * wil,const char * name,struct dentry * parent,u32 off)498ce564170SGreg Kroah-Hartman static void wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
499ce564170SGreg Kroah-Hartman const char *name, struct dentry *parent,
500ce564170SGreg Kroah-Hartman u32 off)
5012be7d22fSVladimir Kondratiev {
5022be7d22fSVladimir Kondratiev struct dentry *d = debugfs_create_dir(name, parent);
5032be7d22fSVladimir Kondratiev
504b7cde470SVladimir Kondratiev wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off,
505b7cde470SVladimir Kondratiev isr_off);
5062be7d22fSVladimir Kondratiev }
5072be7d22fSVladimir Kondratiev
508b7cde470SVladimir Kondratiev static const struct dbg_off pseudo_isr_off[] = {
50978484c44SMaya Erez {"CAUSE", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32},
51078484c44SMaya Erez {"MASK_SW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32},
51178484c44SMaya Erez {"MASK_FW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32},
512b7cde470SVladimir Kondratiev {},
513b7cde470SVladimir Kondratiev };
514b7cde470SVladimir Kondratiev
wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv * wil,struct dentry * parent)515ce564170SGreg Kroah-Hartman static void wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
5162be7d22fSVladimir Kondratiev struct dentry *parent)
5172be7d22fSVladimir Kondratiev {
5182be7d22fSVladimir Kondratiev struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
5192be7d22fSVladimir Kondratiev
520b7cde470SVladimir Kondratiev wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
521b7cde470SVladimir Kondratiev pseudo_isr_off);
5222be7d22fSVladimir Kondratiev }
5232be7d22fSVladimir Kondratiev
52478366f69SVladimir Kondratiev static const struct dbg_off lgc_itr_cnt_off[] = {
52578484c44SMaya Erez {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32},
52678484c44SMaya Erez {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32},
52778484c44SMaya Erez {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32},
528b7cde470SVladimir Kondratiev {},
529b7cde470SVladimir Kondratiev };
530b7cde470SVladimir Kondratiev
53178366f69SVladimir Kondratiev static const struct dbg_off tx_itr_cnt_off[] = {
53278484c44SMaya Erez {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_TRSH),
53378366f69SVladimir Kondratiev doff_io32},
53478484c44SMaya Erez {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_DATA),
53578366f69SVladimir Kondratiev doff_io32},
53678484c44SMaya Erez {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_CTL),
53778366f69SVladimir Kondratiev doff_io32},
53878484c44SMaya Erez {"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_TRSH),
53978366f69SVladimir Kondratiev doff_io32},
54078484c44SMaya Erez {"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_DATA),
54178366f69SVladimir Kondratiev doff_io32},
54278484c44SMaya Erez {"IDL_CTL", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_CTL),
54378366f69SVladimir Kondratiev doff_io32},
54478366f69SVladimir Kondratiev {},
54578366f69SVladimir Kondratiev };
54678366f69SVladimir Kondratiev
54778366f69SVladimir Kondratiev static const struct dbg_off rx_itr_cnt_off[] = {
54878484c44SMaya Erez {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_TRSH),
54978366f69SVladimir Kondratiev doff_io32},
55078484c44SMaya Erez {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_DATA),
55178366f69SVladimir Kondratiev doff_io32},
55278484c44SMaya Erez {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_CTL),
55378366f69SVladimir Kondratiev doff_io32},
55478484c44SMaya Erez {"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_TRSH),
55578366f69SVladimir Kondratiev doff_io32},
55678484c44SMaya Erez {"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_DATA),
55778366f69SVladimir Kondratiev doff_io32},
55878484c44SMaya Erez {"IDL_CTL", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_CTL),
55978366f69SVladimir Kondratiev doff_io32},
56078366f69SVladimir Kondratiev {},
56178366f69SVladimir Kondratiev };
56278366f69SVladimir Kondratiev
wil6210_debugfs_create_ITR_CNT(struct wil6210_priv * wil,struct dentry * parent)5632be7d22fSVladimir Kondratiev static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
5642be7d22fSVladimir Kondratiev struct dentry *parent)
5652be7d22fSVladimir Kondratiev {
56678366f69SVladimir Kondratiev struct dentry *d, *dtx, *drx;
5672be7d22fSVladimir Kondratiev
56878366f69SVladimir Kondratiev d = debugfs_create_dir("ITR_CNT", parent);
5692be7d22fSVladimir Kondratiev
57078366f69SVladimir Kondratiev dtx = debugfs_create_dir("TX", d);
57178366f69SVladimir Kondratiev drx = debugfs_create_dir("RX", d);
5722be7d22fSVladimir Kondratiev
57378366f69SVladimir Kondratiev wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
57478366f69SVladimir Kondratiev lgc_itr_cnt_off);
57578366f69SVladimir Kondratiev
57678366f69SVladimir Kondratiev wil6210_debugfs_init_offset(wil, dtx, (void * __force)wil->csr,
57778366f69SVladimir Kondratiev tx_itr_cnt_off);
57878366f69SVladimir Kondratiev
57978366f69SVladimir Kondratiev wil6210_debugfs_init_offset(wil, drx, (void * __force)wil->csr,
58078366f69SVladimir Kondratiev rx_itr_cnt_off);
5812be7d22fSVladimir Kondratiev return 0;
5822be7d22fSVladimir Kondratiev }
5832be7d22fSVladimir Kondratiev
memread_show(struct seq_file * s,void * data)584986b8348SYangtao Li static int memread_show(struct seq_file *s, void *data)
5852be7d22fSVladimir Kondratiev {
5862be7d22fSVladimir Kondratiev struct wil6210_priv *wil = s->private;
58794162666SLazar Alexei void __iomem *a;
58894162666SLazar Alexei int ret;
58994162666SLazar Alexei
59094162666SLazar Alexei ret = wil_pm_runtime_get(wil);
59194162666SLazar Alexei if (ret < 0)
59294162666SLazar Alexei return ret;
59394162666SLazar Alexei
594a0618945SAhmad Masri ret = wil_mem_access_lock(wil);
595a0618945SAhmad Masri if (ret) {
596a0618945SAhmad Masri wil_pm_runtime_put(wil);
597a0618945SAhmad Masri return ret;
598a0618945SAhmad Masri }
599a0618945SAhmad Masri
60094162666SLazar Alexei a = wmi_buffer(wil, cpu_to_le32(mem_addr));
6012be7d22fSVladimir Kondratiev
6022be7d22fSVladimir Kondratiev if (a)
603b9eeb512SVladimir Kondratiev seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, readl(a));
6042be7d22fSVladimir Kondratiev else
6052be7d22fSVladimir Kondratiev seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
6062be7d22fSVladimir Kondratiev
607a0618945SAhmad Masri wil_mem_access_unlock(wil);
60894162666SLazar Alexei wil_pm_runtime_put(wil);
60994162666SLazar Alexei
6102be7d22fSVladimir Kondratiev return 0;
6112be7d22fSVladimir Kondratiev }
612986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(memread);
6132be7d22fSVladimir Kondratiev
wil_read_file_ioblob(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)6142be7d22fSVladimir Kondratiev static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
6152be7d22fSVladimir Kondratiev size_t count, loff_t *ppos)
6162be7d22fSVladimir Kondratiev {
6172be7d22fSVladimir Kondratiev enum { max_count = 4096 };
618349214c1SMaya Erez struct wil_blob_wrapper *wil_blob = file->private_data;
61994162666SLazar Alexei struct wil6210_priv *wil = wil_blob->wil;
62084ec040dSAhmad Masri loff_t aligned_pos, pos = *ppos;
621349214c1SMaya Erez size_t available = wil_blob->blob.size;
6222be7d22fSVladimir Kondratiev void *buf;
62384ec040dSAhmad Masri size_t unaligned_bytes, aligned_count, ret;
62494162666SLazar Alexei int rc;
6252be7d22fSVladimir Kondratiev
6262be7d22fSVladimir Kondratiev if (pos < 0)
6272be7d22fSVladimir Kondratiev return -EINVAL;
6282be7d22fSVladimir Kondratiev
6292be7d22fSVladimir Kondratiev if (pos >= available || !count)
6302be7d22fSVladimir Kondratiev return 0;
6312be7d22fSVladimir Kondratiev
6322be7d22fSVladimir Kondratiev if (count > available - pos)
6332be7d22fSVladimir Kondratiev count = available - pos;
6342be7d22fSVladimir Kondratiev if (count > max_count)
6352be7d22fSVladimir Kondratiev count = max_count;
6362be7d22fSVladimir Kondratiev
63784ec040dSAhmad Masri /* set pos to 4 bytes aligned */
63884ec040dSAhmad Masri unaligned_bytes = pos % 4;
63984ec040dSAhmad Masri aligned_pos = pos - unaligned_bytes;
64084ec040dSAhmad Masri aligned_count = count + unaligned_bytes;
64184ec040dSAhmad Masri
64284ec040dSAhmad Masri buf = kmalloc(aligned_count, GFP_KERNEL);
6432be7d22fSVladimir Kondratiev if (!buf)
6442be7d22fSVladimir Kondratiev return -ENOMEM;
6452be7d22fSVladimir Kondratiev
64694162666SLazar Alexei rc = wil_pm_runtime_get(wil);
64794162666SLazar Alexei if (rc < 0) {
64894162666SLazar Alexei kfree(buf);
64994162666SLazar Alexei return rc;
65094162666SLazar Alexei }
65194162666SLazar Alexei
652a0618945SAhmad Masri rc = wil_mem_access_lock(wil);
653a0618945SAhmad Masri if (rc) {
654a0618945SAhmad Masri kfree(buf);
655a0618945SAhmad Masri wil_pm_runtime_put(wil);
656a0618945SAhmad Masri return rc;
657a0618945SAhmad Masri }
658a0618945SAhmad Masri
659bd50e268SMaya Erez wil_memcpy_fromio_32(buf, (const void __iomem *)
66084ec040dSAhmad Masri wil_blob->blob.data + aligned_pos, aligned_count);
6612be7d22fSVladimir Kondratiev
66284ec040dSAhmad Masri ret = copy_to_user(user_buf, buf + unaligned_bytes, count);
66394162666SLazar Alexei
664a0618945SAhmad Masri wil_mem_access_unlock(wil);
66594162666SLazar Alexei wil_pm_runtime_put(wil);
66694162666SLazar Alexei
6672be7d22fSVladimir Kondratiev kfree(buf);
6682be7d22fSVladimir Kondratiev if (ret == count)
6692be7d22fSVladimir Kondratiev return -EFAULT;
6702be7d22fSVladimir Kondratiev
6712be7d22fSVladimir Kondratiev count -= ret;
6722be7d22fSVladimir Kondratiev *ppos = pos + count;
6732be7d22fSVladimir Kondratiev
6742be7d22fSVladimir Kondratiev return count;
6752be7d22fSVladimir Kondratiev }
6762be7d22fSVladimir Kondratiev
6772be7d22fSVladimir Kondratiev static const struct file_operations fops_ioblob = {
6782be7d22fSVladimir Kondratiev .read = wil_read_file_ioblob,
67993ecbd64SWei Yongjun .open = simple_open,
6802be7d22fSVladimir Kondratiev .llseek = default_llseek,
6812be7d22fSVladimir Kondratiev };
6822be7d22fSVladimir Kondratiev
6832be7d22fSVladimir Kondratiev static
wil_debugfs_create_ioblob(const char * name,umode_t mode,struct dentry * parent,struct wil_blob_wrapper * wil_blob)6842be7d22fSVladimir Kondratiev struct dentry *wil_debugfs_create_ioblob(const char *name,
6850ecc833bSAl Viro umode_t mode,
6862be7d22fSVladimir Kondratiev struct dentry *parent,
687349214c1SMaya Erez struct wil_blob_wrapper *wil_blob)
6882be7d22fSVladimir Kondratiev {
689349214c1SMaya Erez return debugfs_create_file(name, mode, parent, wil_blob, &fops_ioblob);
6902be7d22fSVladimir Kondratiev }
6918fe59627SVladimir Kondratiev
6920b39aaf2SVladimir Kondratiev /*---write channel 1..4 to rxon for it, 0 to rxoff---*/
wil_write_file_rxon(struct file * file,const char __user * buf,size_t len,loff_t * ppos)6930b39aaf2SVladimir Kondratiev static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
6940b39aaf2SVladimir Kondratiev size_t len, loff_t *ppos)
6950b39aaf2SVladimir Kondratiev {
6960b39aaf2SVladimir Kondratiev struct wil6210_priv *wil = file->private_data;
6970b39aaf2SVladimir Kondratiev int rc;
6980b39aaf2SVladimir Kondratiev long channel;
6990b39aaf2SVladimir Kondratiev bool on;
7000b39aaf2SVladimir Kondratiev
70116e5c1fcSAl Viro char *kbuf = memdup_user_nul(buf, len);
7028fe59627SVladimir Kondratiev
70316e5c1fcSAl Viro if (IS_ERR(kbuf))
70416e5c1fcSAl Viro return PTR_ERR(kbuf);
7050b39aaf2SVladimir Kondratiev rc = kstrtol(kbuf, 0, &channel);
7060b39aaf2SVladimir Kondratiev kfree(kbuf);
7070b39aaf2SVladimir Kondratiev if (rc)
7080b39aaf2SVladimir Kondratiev return rc;
7090b39aaf2SVladimir Kondratiev
7100b39aaf2SVladimir Kondratiev if ((channel < 0) || (channel > 4)) {
7110b39aaf2SVladimir Kondratiev wil_err(wil, "Invalid channel %ld\n", channel);
7120b39aaf2SVladimir Kondratiev return -EINVAL;
7130b39aaf2SVladimir Kondratiev }
7140b39aaf2SVladimir Kondratiev on = !!channel;
7150b39aaf2SVladimir Kondratiev
7160b39aaf2SVladimir Kondratiev if (on) {
7170b39aaf2SVladimir Kondratiev rc = wmi_set_channel(wil, (int)channel);
7180b39aaf2SVladimir Kondratiev if (rc)
7190b39aaf2SVladimir Kondratiev return rc;
7200b39aaf2SVladimir Kondratiev }
7210b39aaf2SVladimir Kondratiev
7220b39aaf2SVladimir Kondratiev rc = wmi_rxon(wil, on);
7230b39aaf2SVladimir Kondratiev if (rc)
7240b39aaf2SVladimir Kondratiev return rc;
7250b39aaf2SVladimir Kondratiev
7260b39aaf2SVladimir Kondratiev return len;
7270b39aaf2SVladimir Kondratiev }
7280b39aaf2SVladimir Kondratiev
7290b39aaf2SVladimir Kondratiev static const struct file_operations fops_rxon = {
7300b39aaf2SVladimir Kondratiev .write = wil_write_file_rxon,
7310b39aaf2SVladimir Kondratiev .open = simple_open,
7320b39aaf2SVladimir Kondratiev };
7338fe59627SVladimir Kondratiev
wil_write_file_rbufcap(struct file * file,const char __user * buf,size_t count,loff_t * ppos)734c5b3a658SAlexei Avshalom Lazar static ssize_t wil_write_file_rbufcap(struct file *file,
735c5b3a658SAlexei Avshalom Lazar const char __user *buf,
736c5b3a658SAlexei Avshalom Lazar size_t count, loff_t *ppos)
737c5b3a658SAlexei Avshalom Lazar {
738c5b3a658SAlexei Avshalom Lazar struct wil6210_priv *wil = file->private_data;
739c5b3a658SAlexei Avshalom Lazar int val;
740c5b3a658SAlexei Avshalom Lazar int rc;
741c5b3a658SAlexei Avshalom Lazar
742c5b3a658SAlexei Avshalom Lazar rc = kstrtoint_from_user(buf, count, 0, &val);
743c5b3a658SAlexei Avshalom Lazar if (rc) {
744c5b3a658SAlexei Avshalom Lazar wil_err(wil, "Invalid argument\n");
745c5b3a658SAlexei Avshalom Lazar return rc;
746c5b3a658SAlexei Avshalom Lazar }
747c5b3a658SAlexei Avshalom Lazar /* input value: negative to disable, 0 to use system default,
748c5b3a658SAlexei Avshalom Lazar * 1..ring size to set descriptor threshold
749c5b3a658SAlexei Avshalom Lazar */
750c5b3a658SAlexei Avshalom Lazar wil_info(wil, "%s RBUFCAP, descriptors threshold - %d\n",
751c5b3a658SAlexei Avshalom Lazar val < 0 ? "Disabling" : "Enabling", val);
752c5b3a658SAlexei Avshalom Lazar
753c5b3a658SAlexei Avshalom Lazar if (!wil->ring_rx.va || val > wil->ring_rx.size) {
754c5b3a658SAlexei Avshalom Lazar wil_err(wil, "Invalid descriptors threshold, %d\n", val);
755c5b3a658SAlexei Avshalom Lazar return -EINVAL;
756c5b3a658SAlexei Avshalom Lazar }
757c5b3a658SAlexei Avshalom Lazar
758c5b3a658SAlexei Avshalom Lazar rc = wmi_rbufcap_cfg(wil, val < 0 ? 0 : 1, val < 0 ? 0 : val);
759c5b3a658SAlexei Avshalom Lazar if (rc) {
760c5b3a658SAlexei Avshalom Lazar wil_err(wil, "RBUFCAP config failed: %d\n", rc);
761c5b3a658SAlexei Avshalom Lazar return rc;
762c5b3a658SAlexei Avshalom Lazar }
763c5b3a658SAlexei Avshalom Lazar
764c5b3a658SAlexei Avshalom Lazar return count;
765c5b3a658SAlexei Avshalom Lazar }
766c5b3a658SAlexei Avshalom Lazar
767c5b3a658SAlexei Avshalom Lazar static const struct file_operations fops_rbufcap = {
768c5b3a658SAlexei Avshalom Lazar .write = wil_write_file_rbufcap,
769c5b3a658SAlexei Avshalom Lazar .open = simple_open,
770c5b3a658SAlexei Avshalom Lazar };
771c5b3a658SAlexei Avshalom Lazar
77249cb5dfbSVladimir Kondratiev /* block ack control, write:
77349cb5dfbSVladimir Kondratiev * - "add <ringid> <agg_size> <timeout>" to trigger ADDBA
77449cb5dfbSVladimir Kondratiev * - "del_tx <ringid> <reason>" to trigger DELBA for Tx side
77549cb5dfbSVladimir Kondratiev * - "del_rx <CID> <TID> <reason>" to trigger DELBA for Rx side
7763277213fSVladimir Kondratiev */
wil_write_back(struct file * file,const char __user * buf,size_t len,loff_t * ppos)77749cb5dfbSVladimir Kondratiev static ssize_t wil_write_back(struct file *file, const char __user *buf,
7783277213fSVladimir Kondratiev size_t len, loff_t *ppos)
7793277213fSVladimir Kondratiev {
7803277213fSVladimir Kondratiev struct wil6210_priv *wil = file->private_data;
7813277213fSVladimir Kondratiev int rc;
7823277213fSVladimir Kondratiev char *kbuf = kmalloc(len + 1, GFP_KERNEL);
7832a19f776SColin Ian King char cmd[9];
78449cb5dfbSVladimir Kondratiev int p1, p2, p3;
7853277213fSVladimir Kondratiev
7863277213fSVladimir Kondratiev if (!kbuf)
7873277213fSVladimir Kondratiev return -ENOMEM;
7883277213fSVladimir Kondratiev
7893277213fSVladimir Kondratiev rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
7903277213fSVladimir Kondratiev if (rc != len) {
7913277213fSVladimir Kondratiev kfree(kbuf);
7923277213fSVladimir Kondratiev return rc >= 0 ? -EIO : rc;
7933277213fSVladimir Kondratiev }
7943277213fSVladimir Kondratiev
7953277213fSVladimir Kondratiev kbuf[len] = '\0';
79649cb5dfbSVladimir Kondratiev rc = sscanf(kbuf, "%8s %d %d %d", cmd, &p1, &p2, &p3);
7973277213fSVladimir Kondratiev kfree(kbuf);
7983277213fSVladimir Kondratiev
79949cb5dfbSVladimir Kondratiev if (rc < 0)
8003277213fSVladimir Kondratiev return rc;
80149cb5dfbSVladimir Kondratiev if (rc < 2)
8023277213fSVladimir Kondratiev return -EINVAL;
8033277213fSVladimir Kondratiev
804e00243faSLior David if ((strcmp(cmd, "add") == 0) ||
805e00243faSLior David (strcmp(cmd, "del_tx") == 0)) {
80610590c6aSGidon Studinski struct wil_ring_tx_data *txdata;
807e00243faSLior David
808e00243faSLior David if (p1 < 0 || p1 >= WIL6210_MAX_TX_RINGS) {
809e00243faSLior David wil_err(wil, "BACK: invalid ring id %d\n", p1);
810e00243faSLior David return -EINVAL;
811e00243faSLior David }
81210590c6aSGidon Studinski txdata = &wil->ring_tx_data[p1];
813e00243faSLior David if (strcmp(cmd, "add") == 0) {
81449cb5dfbSVladimir Kondratiev if (rc < 3) {
81549cb5dfbSVladimir Kondratiev wil_err(wil, "BACK: add require at least 2 params\n");
81649cb5dfbSVladimir Kondratiev return -EINVAL;
81749cb5dfbSVladimir Kondratiev }
81849cb5dfbSVladimir Kondratiev if (rc < 4)
81949cb5dfbSVladimir Kondratiev p3 = 0;
820e00243faSLior David wmi_addba(wil, txdata->mid, p1, p2, p3);
821e00243faSLior David } else {
82249cb5dfbSVladimir Kondratiev if (rc < 3)
82349cb5dfbSVladimir Kondratiev p2 = WLAN_REASON_QSTA_LEAVE_QBSS;
824e00243faSLior David wmi_delba_tx(wil, txdata->mid, p1, p2);
825e00243faSLior David }
826e00243faSLior David } else if (strcmp(cmd, "del_rx") == 0) {
827e00243faSLior David struct wil_sta_info *sta;
828e00243faSLior David
82949cb5dfbSVladimir Kondratiev if (rc < 3) {
83049cb5dfbSVladimir Kondratiev wil_err(wil,
83149cb5dfbSVladimir Kondratiev "BACK: del_rx require at least 2 params\n");
83249cb5dfbSVladimir Kondratiev return -EINVAL;
83349cb5dfbSVladimir Kondratiev }
834ddf7afddSAhmad Masri if (p1 < 0 || p1 >= wil->max_assoc_sta) {
835e00243faSLior David wil_err(wil, "BACK: invalid CID %d\n", p1);
836e00243faSLior David return -EINVAL;
837e00243faSLior David }
83849cb5dfbSVladimir Kondratiev if (rc < 4)
83949cb5dfbSVladimir Kondratiev p3 = WLAN_REASON_QSTA_LEAVE_QBSS;
840e00243faSLior David sta = &wil->sta[p1];
841bf0353a6SAhmad Masri wmi_delba_rx(wil, sta->mid, p1, p2, p3);
84249cb5dfbSVladimir Kondratiev } else {
84349cb5dfbSVladimir Kondratiev wil_err(wil, "BACK: Unrecognized command \"%s\"\n", cmd);
84449cb5dfbSVladimir Kondratiev return -EINVAL;
84549cb5dfbSVladimir Kondratiev }
8463277213fSVladimir Kondratiev
8473277213fSVladimir Kondratiev return len;
8483277213fSVladimir Kondratiev }
8493277213fSVladimir Kondratiev
wil_read_back(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)85049cb5dfbSVladimir Kondratiev static ssize_t wil_read_back(struct file *file, char __user *user_buf,
85149cb5dfbSVladimir Kondratiev size_t count, loff_t *ppos)
85249cb5dfbSVladimir Kondratiev {
85349cb5dfbSVladimir Kondratiev static const char text[] = "block ack control, write:\n"
85449cb5dfbSVladimir Kondratiev " - \"add <ringid> <agg_size> <timeout>\" to trigger ADDBA\n"
85549cb5dfbSVladimir Kondratiev "If missing, <timeout> defaults to 0\n"
85649cb5dfbSVladimir Kondratiev " - \"del_tx <ringid> <reason>\" to trigger DELBA for Tx side\n"
85749cb5dfbSVladimir Kondratiev " - \"del_rx <CID> <TID> <reason>\" to trigger DELBA for Rx side\n"
85849cb5dfbSVladimir Kondratiev "If missing, <reason> set to \"STA_LEAVING\" (36)\n";
85949cb5dfbSVladimir Kondratiev
86049cb5dfbSVladimir Kondratiev return simple_read_from_buffer(user_buf, count, ppos, text,
86149cb5dfbSVladimir Kondratiev sizeof(text));
86249cb5dfbSVladimir Kondratiev }
86349cb5dfbSVladimir Kondratiev
86449cb5dfbSVladimir Kondratiev static const struct file_operations fops_back = {
86549cb5dfbSVladimir Kondratiev .read = wil_read_back,
86649cb5dfbSVladimir Kondratiev .write = wil_write_back,
8673277213fSVladimir Kondratiev .open = simple_open,
8683277213fSVladimir Kondratiev };
8693277213fSVladimir Kondratiev
870dc16427bSVladimir Kondratiev /* pmc control, write:
871dc16427bSVladimir Kondratiev * - "alloc <num descriptors> <descriptor_size>" to allocate PMC
872dc16427bSVladimir Kondratiev * - "free" to release memory allocated for PMC
873dc16427bSVladimir Kondratiev */
wil_write_pmccfg(struct file * file,const char __user * buf,size_t len,loff_t * ppos)874dc16427bSVladimir Kondratiev static ssize_t wil_write_pmccfg(struct file *file, const char __user *buf,
875dc16427bSVladimir Kondratiev size_t len, loff_t *ppos)
876dc16427bSVladimir Kondratiev {
877dc16427bSVladimir Kondratiev struct wil6210_priv *wil = file->private_data;
878dc16427bSVladimir Kondratiev int rc;
879dc16427bSVladimir Kondratiev char *kbuf = kmalloc(len + 1, GFP_KERNEL);
880dc16427bSVladimir Kondratiev char cmd[9];
881dc16427bSVladimir Kondratiev int num_descs, desc_size;
882dc16427bSVladimir Kondratiev
883dc16427bSVladimir Kondratiev if (!kbuf)
884dc16427bSVladimir Kondratiev return -ENOMEM;
885dc16427bSVladimir Kondratiev
886dc16427bSVladimir Kondratiev rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
887dc16427bSVladimir Kondratiev if (rc != len) {
888dc16427bSVladimir Kondratiev kfree(kbuf);
889dc16427bSVladimir Kondratiev return rc >= 0 ? -EIO : rc;
890dc16427bSVladimir Kondratiev }
891dc16427bSVladimir Kondratiev
892dc16427bSVladimir Kondratiev kbuf[len] = '\0';
893dc16427bSVladimir Kondratiev rc = sscanf(kbuf, "%8s %d %d", cmd, &num_descs, &desc_size);
894dc16427bSVladimir Kondratiev kfree(kbuf);
895dc16427bSVladimir Kondratiev
896dc16427bSVladimir Kondratiev if (rc < 0)
897dc16427bSVladimir Kondratiev return rc;
898dc16427bSVladimir Kondratiev
899dc16427bSVladimir Kondratiev if (rc < 1) {
900dc16427bSVladimir Kondratiev wil_err(wil, "pmccfg: no params given\n");
901dc16427bSVladimir Kondratiev return -EINVAL;
902dc16427bSVladimir Kondratiev }
903dc16427bSVladimir Kondratiev
904dc16427bSVladimir Kondratiev if (0 == strcmp(cmd, "alloc")) {
905dc16427bSVladimir Kondratiev if (rc != 3) {
906dc16427bSVladimir Kondratiev wil_err(wil, "pmccfg: alloc requires 2 params\n");
907dc16427bSVladimir Kondratiev return -EINVAL;
908dc16427bSVladimir Kondratiev }
909dc16427bSVladimir Kondratiev wil_pmc_alloc(wil, num_descs, desc_size);
910dc16427bSVladimir Kondratiev } else if (0 == strcmp(cmd, "free")) {
911dc16427bSVladimir Kondratiev if (rc != 1) {
912dc16427bSVladimir Kondratiev wil_err(wil, "pmccfg: free does not have any params\n");
913dc16427bSVladimir Kondratiev return -EINVAL;
914dc16427bSVladimir Kondratiev }
915dc16427bSVladimir Kondratiev wil_pmc_free(wil, true);
916dc16427bSVladimir Kondratiev } else {
917dc16427bSVladimir Kondratiev wil_err(wil, "pmccfg: Unrecognized command \"%s\"\n", cmd);
918dc16427bSVladimir Kondratiev return -EINVAL;
919dc16427bSVladimir Kondratiev }
920dc16427bSVladimir Kondratiev
921dc16427bSVladimir Kondratiev return len;
922dc16427bSVladimir Kondratiev }
923dc16427bSVladimir Kondratiev
wil_read_pmccfg(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)924dc16427bSVladimir Kondratiev static ssize_t wil_read_pmccfg(struct file *file, char __user *user_buf,
925dc16427bSVladimir Kondratiev size_t count, loff_t *ppos)
926dc16427bSVladimir Kondratiev {
927dc16427bSVladimir Kondratiev struct wil6210_priv *wil = file->private_data;
928dc16427bSVladimir Kondratiev char text[256];
929dc16427bSVladimir Kondratiev char help[] = "pmc control, write:\n"
930dc16427bSVladimir Kondratiev " - \"alloc <num descriptors> <descriptor_size>\" to allocate pmc\n"
931dc16427bSVladimir Kondratiev " - \"free\" to free memory allocated for pmc\n";
932dc16427bSVladimir Kondratiev
933dedec35bSDedy Lansky snprintf(text, sizeof(text), "Last command status: %d\n\n%s",
934dedec35bSDedy Lansky wil_pmc_last_cmd_status(wil), help);
935dc16427bSVladimir Kondratiev
936dc16427bSVladimir Kondratiev return simple_read_from_buffer(user_buf, count, ppos, text,
937dc16427bSVladimir Kondratiev strlen(text) + 1);
938dc16427bSVladimir Kondratiev }
939dc16427bSVladimir Kondratiev
940dc16427bSVladimir Kondratiev static const struct file_operations fops_pmccfg = {
941dc16427bSVladimir Kondratiev .read = wil_read_pmccfg,
942dc16427bSVladimir Kondratiev .write = wil_write_pmccfg,
943dc16427bSVladimir Kondratiev .open = simple_open,
944dc16427bSVladimir Kondratiev };
945dc16427bSVladimir Kondratiev
946dc16427bSVladimir Kondratiev static const struct file_operations fops_pmcdata = {
947dc16427bSVladimir Kondratiev .open = simple_open,
948dc16427bSVladimir Kondratiev .read = wil_pmc_read,
949dc16427bSVladimir Kondratiev .llseek = wil_pmc_llseek,
950dc16427bSVladimir Kondratiev };
951dc16427bSVladimir Kondratiev
wil_pmcring_seq_open(struct inode * inode,struct file * file)952977c45abSDedy Lansky static int wil_pmcring_seq_open(struct inode *inode, struct file *file)
953977c45abSDedy Lansky {
954977c45abSDedy Lansky return single_open(file, wil_pmcring_read, inode->i_private);
955977c45abSDedy Lansky }
956977c45abSDedy Lansky
957977c45abSDedy Lansky static const struct file_operations fops_pmcring = {
958977c45abSDedy Lansky .open = wil_pmcring_seq_open,
959977c45abSDedy Lansky .release = single_release,
960977c45abSDedy Lansky .read = seq_read,
961977c45abSDedy Lansky .llseek = seq_lseek,
962977c45abSDedy Lansky };
963977c45abSDedy Lansky
9640b39aaf2SVladimir Kondratiev /*---tx_mgmt---*/
9650b39aaf2SVladimir Kondratiev /* Write mgmt frame to this file to send it */
wil_write_file_txmgmt(struct file * file,const char __user * buf,size_t len,loff_t * ppos)9660b39aaf2SVladimir Kondratiev static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
9670b39aaf2SVladimir Kondratiev size_t len, loff_t *ppos)
9680b39aaf2SVladimir Kondratiev {
9690b39aaf2SVladimir Kondratiev struct wil6210_priv *wil = file->private_data;
9700b39aaf2SVladimir Kondratiev struct wiphy *wiphy = wil_to_wiphy(wil);
971e00243faSLior David struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr;
9720b39aaf2SVladimir Kondratiev struct cfg80211_mgmt_tx_params params;
9730b39aaf2SVladimir Kondratiev int rc;
9749a492909SGeliang Tang void *frame;
9758fe59627SVladimir Kondratiev
976ac0e541aSAlexei Avshalom Lazar memset(¶ms, 0, sizeof(params));
977ac0e541aSAlexei Avshalom Lazar
9786641525cSHamad Kadmany if (!len)
9796641525cSHamad Kadmany return -EINVAL;
9806641525cSHamad Kadmany
9819a492909SGeliang Tang frame = memdup_user(buf, len);
9829a492909SGeliang Tang if (IS_ERR(frame))
9839a492909SGeliang Tang return PTR_ERR(frame);
9840b39aaf2SVladimir Kondratiev
9850b39aaf2SVladimir Kondratiev params.buf = frame;
9860b39aaf2SVladimir Kondratiev params.len = len;
9870b39aaf2SVladimir Kondratiev
9880b39aaf2SVladimir Kondratiev rc = wil_cfg80211_mgmt_tx(wiphy, wdev, ¶ms, NULL);
9890b39aaf2SVladimir Kondratiev
9900b39aaf2SVladimir Kondratiev kfree(frame);
991af3db60aSLazar Alexei wil_info(wil, "-> %d\n", rc);
9920b39aaf2SVladimir Kondratiev
9930b39aaf2SVladimir Kondratiev return len;
9940b39aaf2SVladimir Kondratiev }
9950b39aaf2SVladimir Kondratiev
9960b39aaf2SVladimir Kondratiev static const struct file_operations fops_txmgmt = {
9970b39aaf2SVladimir Kondratiev .write = wil_write_file_txmgmt,
9980b39aaf2SVladimir Kondratiev .open = simple_open,
9990b39aaf2SVladimir Kondratiev };
10002be7d22fSVladimir Kondratiev
1001ff974e40SVladimir Kondratiev /* Write WMI command (w/o mbox header) to this file to send it
1002ff974e40SVladimir Kondratiev * WMI starts from wil6210_mbox_hdr_wmi header
1003ff974e40SVladimir Kondratiev */
wil_write_file_wmi(struct file * file,const char __user * buf,size_t len,loff_t * ppos)1004ff974e40SVladimir Kondratiev static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
1005ff974e40SVladimir Kondratiev size_t len, loff_t *ppos)
1006ff974e40SVladimir Kondratiev {
1007ff974e40SVladimir Kondratiev struct wil6210_priv *wil = file->private_data;
1008e00243faSLior David struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
1009b874ddecSLior David struct wmi_cmd_hdr *wmi;
1010ff974e40SVladimir Kondratiev void *cmd;
1011b874ddecSLior David int cmdlen = len - sizeof(struct wmi_cmd_hdr);
1012ff974e40SVladimir Kondratiev u16 cmdid;
1013d578e0afSAmmar Faizi int rc1;
1014ff974e40SVladimir Kondratiev
10157a483656SDan Carpenter if (cmdlen < 0 || *ppos != 0)
1016ff974e40SVladimir Kondratiev return -EINVAL;
1017ff974e40SVladimir Kondratiev
10187a483656SDan Carpenter wmi = memdup_user(buf, len);
10197a483656SDan Carpenter if (IS_ERR(wmi))
10207a483656SDan Carpenter return PTR_ERR(wmi);
1021ff974e40SVladimir Kondratiev
102269218a48SLior David cmd = (cmdlen > 0) ? &wmi[1] : NULL;
1023b874ddecSLior David cmdid = le16_to_cpu(wmi->command_id);
1024ff974e40SVladimir Kondratiev
1025e00243faSLior David rc1 = wmi_send(wil, cmdid, vif->mid, cmd, cmdlen);
1026ff974e40SVladimir Kondratiev kfree(wmi);
1027ff974e40SVladimir Kondratiev
1028af3db60aSLazar Alexei wil_info(wil, "0x%04x[%d] -> %d\n", cmdid, cmdlen, rc1);
1029ff974e40SVladimir Kondratiev
1030d578e0afSAmmar Faizi return len;
1031ff974e40SVladimir Kondratiev }
1032ff974e40SVladimir Kondratiev
1033ff974e40SVladimir Kondratiev static const struct file_operations fops_wmi = {
1034ff974e40SVladimir Kondratiev .write = wil_write_file_wmi,
1035ff974e40SVladimir Kondratiev .open = simple_open,
1036ff974e40SVladimir Kondratiev };
1037ff974e40SVladimir Kondratiev
wil_seq_print_skb(struct seq_file * s,struct sk_buff * skb)1038c236658fSVladimir Kondratiev static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
1039c236658fSVladimir Kondratiev {
1040c236658fSVladimir Kondratiev int i = 0;
1041c236658fSVladimir Kondratiev int len = skb_headlen(skb);
1042c236658fSVladimir Kondratiev void *p = skb->data;
1043c236658fSVladimir Kondratiev int nr_frags = skb_shinfo(skb)->nr_frags;
1044c236658fSVladimir Kondratiev
1045c236658fSVladimir Kondratiev seq_printf(s, " len = %d\n", len);
1046c236658fSVladimir Kondratiev wil_seq_hexdump(s, p, len, " : ");
1047c236658fSVladimir Kondratiev
1048c236658fSVladimir Kondratiev if (nr_frags) {
1049c236658fSVladimir Kondratiev seq_printf(s, " nr_frags = %d\n", nr_frags);
1050c236658fSVladimir Kondratiev for (i = 0; i < nr_frags; i++) {
1051d7840976SMatthew Wilcox (Oracle) const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1052c236658fSVladimir Kondratiev
1053c236658fSVladimir Kondratiev len = skb_frag_size(frag);
1054c236658fSVladimir Kondratiev p = skb_frag_address_safe(frag);
1055c236658fSVladimir Kondratiev seq_printf(s, " [%2d] : len = %d\n", i, len);
1056c236658fSVladimir Kondratiev wil_seq_hexdump(s, p, len, " : ");
1057c236658fSVladimir Kondratiev }
1058c236658fSVladimir Kondratiev }
1059c236658fSVladimir Kondratiev }
1060c236658fSVladimir Kondratiev
10613a85543eSVladimir Kondratiev /*---------Tx/Rx descriptor------------*/
txdesc_show(struct seq_file * s,void * data)1062986b8348SYangtao Li static int txdesc_show(struct seq_file *s, void *data)
10632be7d22fSVladimir Kondratiev {
10642be7d22fSVladimir Kondratiev struct wil6210_priv *wil = s->private;
106510590c6aSGidon Studinski struct wil_ring *ring;
1066d98b8539SMaya Erez bool tx;
1067d98b8539SMaya Erez int ring_idx = dbg_ring_index;
1068d98b8539SMaya Erez int txdesc_idx = dbg_txdesc_index;
1069d98b8539SMaya Erez volatile struct vring_tx_desc *d;
1070d98b8539SMaya Erez volatile u32 *u;
1071d98b8539SMaya Erez struct sk_buff *skb;
10728fe59627SVladimir Kondratiev
1073d98b8539SMaya Erez if (wil->use_enhanced_dma_hw) {
1074d98b8539SMaya Erez /* RX ring index == 0 */
1075d98b8539SMaya Erez if (ring_idx >= WIL6210_MAX_TX_RINGS) {
1076d98b8539SMaya Erez seq_printf(s, "invalid ring index %d\n", ring_idx);
1077d98b8539SMaya Erez return 0;
1078d98b8539SMaya Erez }
1079d98b8539SMaya Erez tx = ring_idx > 0; /* desc ring 0 is reserved for RX */
1080d98b8539SMaya Erez } else {
1081d98b8539SMaya Erez /* RX ring index == WIL6210_MAX_TX_RINGS */
1082d98b8539SMaya Erez if (ring_idx > WIL6210_MAX_TX_RINGS) {
1083d98b8539SMaya Erez seq_printf(s, "invalid ring index %d\n", ring_idx);
1084d98b8539SMaya Erez return 0;
1085d98b8539SMaya Erez }
1086d98b8539SMaya Erez tx = (ring_idx < WIL6210_MAX_TX_RINGS);
1087d98b8539SMaya Erez }
1088d98b8539SMaya Erez
1089d98b8539SMaya Erez ring = tx ? &wil->ring_tx[ring_idx] : &wil->ring_rx;
10902be7d22fSVladimir Kondratiev
109110590c6aSGidon Studinski if (!ring->va) {
1092af31cb5aSVladimir Kondratiev if (tx)
1093d98b8539SMaya Erez seq_printf(s, "No Tx[%2d] RING\n", ring_idx);
10943a85543eSVladimir Kondratiev else
1095d98b8539SMaya Erez seq_puts(s, "No Rx RING\n");
10962be7d22fSVladimir Kondratiev return 0;
10972be7d22fSVladimir Kondratiev }
10982be7d22fSVladimir Kondratiev
1099d98b8539SMaya Erez if (txdesc_idx >= ring->size) {
1100d98b8539SMaya Erez if (tx)
1101d98b8539SMaya Erez seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
1102d98b8539SMaya Erez ring_idx, txdesc_idx, ring->size);
1103d98b8539SMaya Erez else
1104d98b8539SMaya Erez seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
1105d98b8539SMaya Erez txdesc_idx, ring->size);
1106d98b8539SMaya Erez return 0;
1107d98b8539SMaya Erez }
1108d98b8539SMaya Erez
11093a85543eSVladimir Kondratiev /* use struct vring_tx_desc for Rx as well,
11103a85543eSVladimir Kondratiev * only field used, .dma.length, is the same
11113a85543eSVladimir Kondratiev */
1112d98b8539SMaya Erez d = &ring->va[txdesc_idx].tx.legacy;
1113d98b8539SMaya Erez u = (volatile u32 *)d;
1114d98b8539SMaya Erez skb = NULL;
11152be7d22fSVladimir Kondratiev
1116d98b8539SMaya Erez if (wil->use_enhanced_dma_hw) {
1117d98b8539SMaya Erez if (tx) {
11189a874d04SDedy Lansky skb = ring->ctx ? ring->ctx[txdesc_idx].skb : NULL;
11199a874d04SDedy Lansky } else if (wil->rx_buff_mgmt.buff_arr) {
1120d98b8539SMaya Erez struct wil_rx_enhanced_desc *rx_d =
1121d98b8539SMaya Erez (struct wil_rx_enhanced_desc *)
1122d98b8539SMaya Erez &ring->va[txdesc_idx].rx.enhanced;
1123d98b8539SMaya Erez u16 buff_id = le16_to_cpu(rx_d->mac.buff_id);
1124d98b8539SMaya Erez
1125d98b8539SMaya Erez if (!wil_val_in_range(buff_id, 0,
11269a874d04SDedy Lansky wil->rx_buff_mgmt.size))
1127d98b8539SMaya Erez seq_printf(s, "invalid buff_id %d\n", buff_id);
11289a874d04SDedy Lansky else
1129d98b8539SMaya Erez skb = wil->rx_buff_mgmt.buff_arr[buff_id].skb;
1130d98b8539SMaya Erez }
1131d98b8539SMaya Erez } else {
1132d98b8539SMaya Erez skb = ring->ctx[txdesc_idx].skb;
1133d98b8539SMaya Erez }
1134af31cb5aSVladimir Kondratiev if (tx)
1135d98b8539SMaya Erez seq_printf(s, "Tx[%2d][%3d] = {\n", ring_idx,
1136d98b8539SMaya Erez txdesc_idx);
11373a85543eSVladimir Kondratiev else
1138d98b8539SMaya Erez seq_printf(s, "Rx[%3d] = {\n", txdesc_idx);
11392be7d22fSVladimir Kondratiev seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
11402be7d22fSVladimir Kondratiev u[0], u[1], u[2], u[3]);
11412be7d22fSVladimir Kondratiev seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
11422be7d22fSVladimir Kondratiev u[4], u[5], u[6], u[7]);
114339c52ee8SVladimir Kondratiev seq_printf(s, " SKB = 0x%p\n", skb);
11442be7d22fSVladimir Kondratiev
11452be7d22fSVladimir Kondratiev if (skb) {
1146c236658fSVladimir Kondratiev skb_get(skb);
1147c236658fSVladimir Kondratiev wil_seq_print_skb(s, skb);
1148c236658fSVladimir Kondratiev kfree_skb(skb);
11492be7d22fSVladimir Kondratiev }
11508fe59627SVladimir Kondratiev seq_puts(s, "}\n");
11512be7d22fSVladimir Kondratiev
11522be7d22fSVladimir Kondratiev return 0;
11532be7d22fSVladimir Kondratiev }
1154986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(txdesc);
11552be7d22fSVladimir Kondratiev
1156d98b8539SMaya Erez /*---------Tx/Rx status message------------*/
status_msg_show(struct seq_file * s,void * data)1157986b8348SYangtao Li static int status_msg_show(struct seq_file *s, void *data)
1158d98b8539SMaya Erez {
1159d98b8539SMaya Erez struct wil6210_priv *wil = s->private;
1160d98b8539SMaya Erez int sring_idx = dbg_sring_index;
1161d98b8539SMaya Erez struct wil_status_ring *sring;
11629a874d04SDedy Lansky bool tx;
1163d98b8539SMaya Erez u32 status_msg_idx = dbg_status_msg_index;
1164d98b8539SMaya Erez u32 *u;
1165d98b8539SMaya Erez
1166d98b8539SMaya Erez if (sring_idx >= WIL6210_MAX_STATUS_RINGS) {
1167d98b8539SMaya Erez seq_printf(s, "invalid status ring index %d\n", sring_idx);
1168d98b8539SMaya Erez return 0;
1169d98b8539SMaya Erez }
1170d98b8539SMaya Erez
1171d98b8539SMaya Erez sring = &wil->srings[sring_idx];
11729a874d04SDedy Lansky tx = !sring->is_rx;
1173d98b8539SMaya Erez
1174d98b8539SMaya Erez if (!sring->va) {
1175d98b8539SMaya Erez seq_printf(s, "No %cX status ring\n", tx ? 'T' : 'R');
1176d98b8539SMaya Erez return 0;
1177d98b8539SMaya Erez }
1178d98b8539SMaya Erez
1179d98b8539SMaya Erez if (status_msg_idx >= sring->size) {
1180d98b8539SMaya Erez seq_printf(s, "%cxDesc index (%d) >= size (%d)\n",
1181d98b8539SMaya Erez tx ? 'T' : 'R', status_msg_idx, sring->size);
1182d98b8539SMaya Erez return 0;
1183d98b8539SMaya Erez }
1184d98b8539SMaya Erez
1185d98b8539SMaya Erez u = sring->va + (sring->elem_size * status_msg_idx);
1186d98b8539SMaya Erez
1187d98b8539SMaya Erez seq_printf(s, "%cx[%d][%3d] = {\n",
1188d98b8539SMaya Erez tx ? 'T' : 'R', sring_idx, status_msg_idx);
1189d98b8539SMaya Erez
1190d98b8539SMaya Erez seq_printf(s, " 0x%08x 0x%08x 0x%08x 0x%08x\n",
1191d98b8539SMaya Erez u[0], u[1], u[2], u[3]);
1192d98b8539SMaya Erez if (!tx && !wil->use_compressed_rx_status)
1193d98b8539SMaya Erez seq_printf(s, " 0x%08x 0x%08x 0x%08x 0x%08x\n",
1194d98b8539SMaya Erez u[4], u[5], u[6], u[7]);
1195d98b8539SMaya Erez
1196d98b8539SMaya Erez seq_puts(s, "}\n");
1197d98b8539SMaya Erez
1198d98b8539SMaya Erez return 0;
1199d98b8539SMaya Erez }
1200986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(status_msg);
1201d98b8539SMaya Erez
wil_print_rx_buff(struct seq_file * s,struct list_head * lh)1202d98b8539SMaya Erez static int wil_print_rx_buff(struct seq_file *s, struct list_head *lh)
1203d98b8539SMaya Erez {
1204d98b8539SMaya Erez struct wil_rx_buff *it;
1205d98b8539SMaya Erez int i = 0;
1206d98b8539SMaya Erez
1207d98b8539SMaya Erez list_for_each_entry(it, lh, list) {
1208d98b8539SMaya Erez if ((i % 16) == 0 && i != 0)
1209d98b8539SMaya Erez seq_puts(s, "\n ");
1210d98b8539SMaya Erez seq_printf(s, "[%4d] ", it->id);
1211d98b8539SMaya Erez i++;
1212d98b8539SMaya Erez }
1213d98b8539SMaya Erez seq_printf(s, "\nNumber of buffers: %u\n", i);
1214d98b8539SMaya Erez
1215d98b8539SMaya Erez return i;
1216d98b8539SMaya Erez }
1217d98b8539SMaya Erez
rx_buff_mgmt_show(struct seq_file * s,void * data)1218986b8348SYangtao Li static int rx_buff_mgmt_show(struct seq_file *s, void *data)
1219d98b8539SMaya Erez {
1220d98b8539SMaya Erez struct wil6210_priv *wil = s->private;
1221d98b8539SMaya Erez struct wil_rx_buff_mgmt *rbm = &wil->rx_buff_mgmt;
1222d98b8539SMaya Erez int num_active;
1223d98b8539SMaya Erez int num_free;
1224d98b8539SMaya Erez
12254405b632SDedy Lansky if (!rbm->buff_arr)
12264405b632SDedy Lansky return -EINVAL;
12274405b632SDedy Lansky
1228d98b8539SMaya Erez seq_printf(s, " size = %zu\n", rbm->size);
1229d98b8539SMaya Erez seq_printf(s, " free_list_empty_cnt = %lu\n",
1230d98b8539SMaya Erez rbm->free_list_empty_cnt);
1231d98b8539SMaya Erez
1232d98b8539SMaya Erez /* Print active list */
1233d98b8539SMaya Erez seq_puts(s, " Active list:\n");
1234d98b8539SMaya Erez num_active = wil_print_rx_buff(s, &rbm->active);
1235d98b8539SMaya Erez seq_puts(s, "\n Free list:\n");
1236d98b8539SMaya Erez num_free = wil_print_rx_buff(s, &rbm->free);
1237d98b8539SMaya Erez
1238d98b8539SMaya Erez seq_printf(s, " Total number of buffers: %u\n",
1239d98b8539SMaya Erez num_active + num_free);
1240d98b8539SMaya Erez
1241d98b8539SMaya Erez return 0;
1242d98b8539SMaya Erez }
1243986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(rx_buff_mgmt);
1244d98b8539SMaya Erez
12452be7d22fSVladimir Kondratiev /*---------beamforming------------*/
wil_bfstatus_str(u32 status)124636345ac3SVladimir Kondratiev static char *wil_bfstatus_str(u32 status)
124736345ac3SVladimir Kondratiev {
124836345ac3SVladimir Kondratiev switch (status) {
124936345ac3SVladimir Kondratiev case 0:
125036345ac3SVladimir Kondratiev return "Failed";
125136345ac3SVladimir Kondratiev case 1:
125236345ac3SVladimir Kondratiev return "OK";
125336345ac3SVladimir Kondratiev case 2:
125436345ac3SVladimir Kondratiev return "Retrying";
125536345ac3SVladimir Kondratiev default:
125636345ac3SVladimir Kondratiev return "??";
125736345ac3SVladimir Kondratiev }
125836345ac3SVladimir Kondratiev }
125936345ac3SVladimir Kondratiev
is_all_zeros(void * const x_,size_t sz)126036345ac3SVladimir Kondratiev static bool is_all_zeros(void * const x_, size_t sz)
126136345ac3SVladimir Kondratiev {
126236345ac3SVladimir Kondratiev /* if reply is all-0, ignore this CID */
126336345ac3SVladimir Kondratiev u32 *x = x_;
126436345ac3SVladimir Kondratiev int n;
126536345ac3SVladimir Kondratiev
126636345ac3SVladimir Kondratiev for (n = 0; n < sz / sizeof(*x); n++)
126736345ac3SVladimir Kondratiev if (x[n])
126836345ac3SVladimir Kondratiev return false;
126936345ac3SVladimir Kondratiev
127036345ac3SVladimir Kondratiev return true;
127136345ac3SVladimir Kondratiev }
127236345ac3SVladimir Kondratiev
bf_show(struct seq_file * s,void * data)1273986b8348SYangtao Li static int bf_show(struct seq_file *s, void *data)
12742be7d22fSVladimir Kondratiev {
127536345ac3SVladimir Kondratiev int rc;
127636345ac3SVladimir Kondratiev int i;
12772be7d22fSVladimir Kondratiev struct wil6210_priv *wil = s->private;
1278e00243faSLior David struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
127936345ac3SVladimir Kondratiev struct wmi_notify_req_cmd cmd = {
128036345ac3SVladimir Kondratiev .interval_usec = 0,
128136345ac3SVladimir Kondratiev };
128236345ac3SVladimir Kondratiev struct {
1283b874ddecSLior David struct wmi_cmd_hdr wmi;
128436345ac3SVladimir Kondratiev struct wmi_notify_req_done_event evt;
128536345ac3SVladimir Kondratiev } __packed reply;
128636345ac3SVladimir Kondratiev
1287807b0860SAlexei Avshalom Lazar memset(&reply, 0, sizeof(reply));
1288807b0860SAlexei Avshalom Lazar
1289ddf7afddSAhmad Masri for (i = 0; i < wil->max_assoc_sta; i++) {
129036345ac3SVladimir Kondratiev u32 status;
12917064e219SMax Chen u8 bf_mcs;
129236345ac3SVladimir Kondratiev
129336345ac3SVladimir Kondratiev cmd.cid = i;
1294e00243faSLior David rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, vif->mid,
1295e00243faSLior David &cmd, sizeof(cmd),
129636345ac3SVladimir Kondratiev WMI_NOTIFY_REQ_DONE_EVENTID, &reply,
12972a32c20bSAhmad Masri sizeof(reply), WIL_WMI_CALL_GENERAL_TO_MS);
129836345ac3SVladimir Kondratiev /* if reply is all-0, ignore this CID */
129936345ac3SVladimir Kondratiev if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt)))
130036345ac3SVladimir Kondratiev continue;
130136345ac3SVladimir Kondratiev
130236345ac3SVladimir Kondratiev status = le32_to_cpu(reply.evt.status);
13037064e219SMax Chen bf_mcs = le16_to_cpu(reply.evt.bf_mcs);
130436345ac3SVladimir Kondratiev seq_printf(s, "CID %d {\n"
130536345ac3SVladimir Kondratiev " TSF = 0x%016llx\n"
13067064e219SMax Chen " TxMCS = %s TxTpt = %4d\n"
130736345ac3SVladimir Kondratiev " SQI = %4d\n"
130830868f5dSDedy Lansky " RSSI = %4d\n"
130936345ac3SVladimir Kondratiev " Status = 0x%08x %s\n"
131036345ac3SVladimir Kondratiev " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
131136345ac3SVladimir Kondratiev " Goodput(rx:tx) %4d:%4d\n"
131236345ac3SVladimir Kondratiev "}\n",
131336345ac3SVladimir Kondratiev i,
131436345ac3SVladimir Kondratiev le64_to_cpu(reply.evt.tsf),
13157064e219SMax Chen WIL_EXTENDED_MCS_CHECK(bf_mcs),
131636345ac3SVladimir Kondratiev le32_to_cpu(reply.evt.tx_tpt),
131736345ac3SVladimir Kondratiev reply.evt.sqi,
131830868f5dSDedy Lansky reply.evt.rssi,
131936345ac3SVladimir Kondratiev status, wil_bfstatus_str(status),
132036345ac3SVladimir Kondratiev le16_to_cpu(reply.evt.my_rx_sector),
132136345ac3SVladimir Kondratiev le16_to_cpu(reply.evt.my_tx_sector),
132236345ac3SVladimir Kondratiev le16_to_cpu(reply.evt.other_rx_sector),
132336345ac3SVladimir Kondratiev le16_to_cpu(reply.evt.other_tx_sector),
132436345ac3SVladimir Kondratiev le32_to_cpu(reply.evt.rx_goodput),
132536345ac3SVladimir Kondratiev le32_to_cpu(reply.evt.tx_goodput));
132636345ac3SVladimir Kondratiev }
13272be7d22fSVladimir Kondratiev return 0;
13282be7d22fSVladimir Kondratiev }
1329986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(bf);
13308fe59627SVladimir Kondratiev
13311a2780e0SVladimir Kondratiev /*---------temp------------*/
print_temp(struct seq_file * s,const char * prefix,s32 t)13326d9eb7ebSDedy Lansky static void print_temp(struct seq_file *s, const char *prefix, s32 t)
13331a2780e0SVladimir Kondratiev {
13341a2780e0SVladimir Kondratiev switch (t) {
13351a2780e0SVladimir Kondratiev case 0:
13369b586118STzahi Sabo case WMI_INVALID_TEMPERATURE:
13371a2780e0SVladimir Kondratiev seq_printf(s, "%s N/A\n", prefix);
13381a2780e0SVladimir Kondratiev break;
13391a2780e0SVladimir Kondratiev default:
13406d9eb7ebSDedy Lansky seq_printf(s, "%s %s%d.%03d\n", prefix, (t < 0 ? "-" : ""),
13416d9eb7ebSDedy Lansky abs(t / 1000), abs(t % 1000));
13421a2780e0SVladimir Kondratiev break;
13431a2780e0SVladimir Kondratiev }
13441a2780e0SVladimir Kondratiev }
13451a2780e0SVladimir Kondratiev
temp_show(struct seq_file * s,void * data)1346986b8348SYangtao Li static int temp_show(struct seq_file *s, void *data)
13471a2780e0SVladimir Kondratiev {
13481a2780e0SVladimir Kondratiev struct wil6210_priv *wil = s->private;
13499b586118STzahi Sabo int rc, i;
13508fe59627SVladimir Kondratiev
13519b586118STzahi Sabo if (test_bit(WMI_FW_CAPABILITY_TEMPERATURE_ALL_RF,
13529b586118STzahi Sabo wil->fw_capabilities)) {
13539b586118STzahi Sabo struct wmi_temp_sense_all_done_event sense_all_evt;
13549b586118STzahi Sabo
13559b586118STzahi Sabo wil_dbg_misc(wil,
13569b586118STzahi Sabo "WMI_FW_CAPABILITY_TEMPERATURE_ALL_RF is supported");
13579b586118STzahi Sabo rc = wmi_get_all_temperatures(wil, &sense_all_evt);
13581a2780e0SVladimir Kondratiev if (rc) {
13598fe59627SVladimir Kondratiev seq_puts(s, "Failed\n");
13601a2780e0SVladimir Kondratiev return 0;
13611a2780e0SVladimir Kondratiev }
13629b586118STzahi Sabo print_temp(s, "T_mac =",
13639b586118STzahi Sabo le32_to_cpu(sense_all_evt.baseband_t1000));
13649b586118STzahi Sabo seq_printf(s, "Connected RFs [0x%08x]\n",
13659b586118STzahi Sabo sense_all_evt.rf_bitmap);
13669b586118STzahi Sabo for (i = 0; i < WMI_MAX_XIF_PORTS_NUM; i++) {
13679b586118STzahi Sabo seq_printf(s, "RF[%d] = ", i);
13689b586118STzahi Sabo print_temp(s, "",
13699b586118STzahi Sabo le32_to_cpu(sense_all_evt.rf_t1000[i]));
13709b586118STzahi Sabo }
13719b586118STzahi Sabo } else {
13729b586118STzahi Sabo s32 t_m, t_r;
13731a2780e0SVladimir Kondratiev
13749b586118STzahi Sabo wil_dbg_misc(wil,
13759b586118STzahi Sabo "WMI_FW_CAPABILITY_TEMPERATURE_ALL_RF is not supported");
13769b586118STzahi Sabo rc = wmi_get_temperature(wil, &t_m, &t_r);
13779b586118STzahi Sabo if (rc) {
13789b586118STzahi Sabo seq_puts(s, "Failed\n");
13799b586118STzahi Sabo return 0;
13809b586118STzahi Sabo }
1381d45cff9fSVladimir Kondratiev print_temp(s, "T_mac =", t_m);
1382d45cff9fSVladimir Kondratiev print_temp(s, "T_radio =", t_r);
13839b586118STzahi Sabo }
13841a2780e0SVladimir Kondratiev return 0;
13851a2780e0SVladimir Kondratiev }
1386986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(temp);
13871a2780e0SVladimir Kondratiev
13889eb82d43SVladimir Kondratiev /*---------link------------*/
link_show(struct seq_file * s,void * data)1389986b8348SYangtao Li static int link_show(struct seq_file *s, void *data)
13909eb82d43SVladimir Kondratiev {
13919eb82d43SVladimir Kondratiev struct wil6210_priv *wil = s->private;
139241bd3d58SToke Høiland-Jørgensen struct station_info *sinfo;
139341bd3d58SToke Høiland-Jørgensen int i, rc = 0;
139441bd3d58SToke Høiland-Jørgensen
139541bd3d58SToke Høiland-Jørgensen sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL);
139641bd3d58SToke Høiland-Jørgensen if (!sinfo)
139741bd3d58SToke Høiland-Jørgensen return -ENOMEM;
13989eb82d43SVladimir Kondratiev
1399ddf7afddSAhmad Masri for (i = 0; i < wil->max_assoc_sta; i++) {
14009eb82d43SVladimir Kondratiev struct wil_sta_info *p = &wil->sta[i];
14019eb82d43SVladimir Kondratiev char *status = "unknown";
14025bd60982SLior David struct wil6210_vif *vif;
14035bd60982SLior David u8 mid;
14048fe59627SVladimir Kondratiev
14059eb82d43SVladimir Kondratiev switch (p->status) {
14069eb82d43SVladimir Kondratiev case wil_sta_unused:
14079eb82d43SVladimir Kondratiev status = "unused ";
14089eb82d43SVladimir Kondratiev break;
14099eb82d43SVladimir Kondratiev case wil_sta_conn_pending:
14109eb82d43SVladimir Kondratiev status = "pending ";
14119eb82d43SVladimir Kondratiev break;
14129eb82d43SVladimir Kondratiev case wil_sta_connected:
14139eb82d43SVladimir Kondratiev status = "connected";
14149eb82d43SVladimir Kondratiev break;
14159eb82d43SVladimir Kondratiev }
14165bd60982SLior David mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
14175bd60982SLior David seq_printf(s, "[%d][MID %d] %pM %s\n",
14185bd60982SLior David i, mid, p->addr, status);
14199eb82d43SVladimir Kondratiev
14205bd60982SLior David if (p->status != wil_sta_connected)
14215bd60982SLior David continue;
14225bd60982SLior David
1423e4a29bddSAhmad Masri vif = (mid < GET_MAX_VIFS(wil)) ? wil->vifs[mid] : NULL;
14245bd60982SLior David if (vif) {
142541bd3d58SToke Høiland-Jørgensen rc = wil_cid_fill_sinfo(vif, i, sinfo);
14269eb82d43SVladimir Kondratiev if (rc)
142741bd3d58SToke Høiland-Jørgensen goto out;
14289eb82d43SVladimir Kondratiev
14297064e219SMax Chen seq_printf(s, " Tx_mcs = %s\n",
14307064e219SMax Chen WIL_EXTENDED_MCS_CHECK(sinfo->txrate.mcs));
14317064e219SMax Chen seq_printf(s, " Rx_mcs = %s\n",
14327064e219SMax Chen WIL_EXTENDED_MCS_CHECK(sinfo->rxrate.mcs));
143341bd3d58SToke Høiland-Jørgensen seq_printf(s, " SQ = %d\n", sinfo->signal);
14345bd60982SLior David } else {
14355bd60982SLior David seq_puts(s, " INVALID MID\n");
14369eb82d43SVladimir Kondratiev }
14379eb82d43SVladimir Kondratiev }
14389eb82d43SVladimir Kondratiev
143941bd3d58SToke Høiland-Jørgensen out:
144041bd3d58SToke Høiland-Jørgensen kfree(sinfo);
144141bd3d58SToke Høiland-Jørgensen return rc;
14429eb82d43SVladimir Kondratiev }
1443986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(link);
14449eb82d43SVladimir Kondratiev
144584bb29b7SVladimir Kondratiev /*---------info------------*/
info_show(struct seq_file * s,void * data)1446986b8348SYangtao Li static int info_show(struct seq_file *s, void *data)
144784bb29b7SVladimir Kondratiev {
1448be299858SVladimir Kondratiev struct wil6210_priv *wil = s->private;
1449e00243faSLior David struct net_device *ndev = wil->main_ndev;
145084bb29b7SVladimir Kondratiev int is_ac = power_supply_is_system_supplied();
1451be299858SVladimir Kondratiev int rx = atomic_xchg(&wil->isr_count_rx, 0);
1452be299858SVladimir Kondratiev int tx = atomic_xchg(&wil->isr_count_tx, 0);
1453be299858SVladimir Kondratiev static ulong rxf_old, txf_old;
1454be299858SVladimir Kondratiev ulong rxf = ndev->stats.rx_packets;
1455be299858SVladimir Kondratiev ulong txf = ndev->stats.tx_packets;
145655f8f680SVladimir Kondratiev unsigned int i;
145784bb29b7SVladimir Kondratiev
145884bb29b7SVladimir Kondratiev /* >0 : AC; 0 : battery; <0 : error */
145984bb29b7SVladimir Kondratiev seq_printf(s, "AC powered : %d\n", is_ac);
1460be299858SVladimir Kondratiev seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
1461be299858SVladimir Kondratiev seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
1462be299858SVladimir Kondratiev rxf_old = rxf;
1463be299858SVladimir Kondratiev txf_old = txf;
146484bb29b7SVladimir Kondratiev
146555f8f680SVladimir Kondratiev #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
146655f8f680SVladimir Kondratiev " " __stringify(x) : ""
146755f8f680SVladimir Kondratiev
146855f8f680SVladimir Kondratiev for (i = 0; i < ndev->num_tx_queues; i++) {
146955f8f680SVladimir Kondratiev struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
147055f8f680SVladimir Kondratiev unsigned long state = txq->state;
147155f8f680SVladimir Kondratiev
147255f8f680SVladimir Kondratiev seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
147355f8f680SVladimir Kondratiev CHECK_QSTATE(DRV_XOFF),
147455f8f680SVladimir Kondratiev CHECK_QSTATE(STACK_XOFF),
147555f8f680SVladimir Kondratiev CHECK_QSTATE(FROZEN)
147655f8f680SVladimir Kondratiev );
147755f8f680SVladimir Kondratiev }
147855f8f680SVladimir Kondratiev #undef CHECK_QSTATE
147984bb29b7SVladimir Kondratiev return 0;
148084bb29b7SVladimir Kondratiev }
1481986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(info);
148284bb29b7SVladimir Kondratiev
1483c33407a8SVladimir Kondratiev /*---------recovery------------*/
1484c33407a8SVladimir Kondratiev /* mode = [manual|auto]
1485c33407a8SVladimir Kondratiev * state = [idle|pending|running]
1486c33407a8SVladimir Kondratiev */
wil_read_file_recovery(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)1487c33407a8SVladimir Kondratiev static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf,
1488c33407a8SVladimir Kondratiev size_t count, loff_t *ppos)
1489c33407a8SVladimir Kondratiev {
1490c33407a8SVladimir Kondratiev struct wil6210_priv *wil = file->private_data;
1491c33407a8SVladimir Kondratiev char buf[80];
1492c33407a8SVladimir Kondratiev int n;
1493c33407a8SVladimir Kondratiev static const char * const sstate[] = {"idle", "pending", "running"};
1494c33407a8SVladimir Kondratiev
1495c33407a8SVladimir Kondratiev n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n",
1496c33407a8SVladimir Kondratiev no_fw_recovery ? "manual" : "auto",
1497c33407a8SVladimir Kondratiev sstate[wil->recovery_state]);
1498c33407a8SVladimir Kondratiev
1499c33407a8SVladimir Kondratiev n = min_t(int, n, sizeof(buf));
1500c33407a8SVladimir Kondratiev
1501c33407a8SVladimir Kondratiev return simple_read_from_buffer(user_buf, count, ppos,
1502c33407a8SVladimir Kondratiev buf, n);
1503c33407a8SVladimir Kondratiev }
1504c33407a8SVladimir Kondratiev
wil_write_file_recovery(struct file * file,const char __user * buf_,size_t count,loff_t * ppos)1505c33407a8SVladimir Kondratiev static ssize_t wil_write_file_recovery(struct file *file,
1506c33407a8SVladimir Kondratiev const char __user *buf_,
1507c33407a8SVladimir Kondratiev size_t count, loff_t *ppos)
1508c33407a8SVladimir Kondratiev {
1509c33407a8SVladimir Kondratiev struct wil6210_priv *wil = file->private_data;
1510c33407a8SVladimir Kondratiev static const char run_command[] = "run";
1511c33407a8SVladimir Kondratiev char buf[sizeof(run_command) + 1]; /* to detect "runx" */
1512c33407a8SVladimir Kondratiev ssize_t rc;
1513c33407a8SVladimir Kondratiev
1514c33407a8SVladimir Kondratiev if (wil->recovery_state != fw_recovery_pending) {
1515c33407a8SVladimir Kondratiev wil_err(wil, "No recovery pending\n");
1516c33407a8SVladimir Kondratiev return -EINVAL;
1517c33407a8SVladimir Kondratiev }
1518c33407a8SVladimir Kondratiev
1519c33407a8SVladimir Kondratiev if (*ppos != 0) {
1520c33407a8SVladimir Kondratiev wil_err(wil, "Offset [%d]\n", (int)*ppos);
1521c33407a8SVladimir Kondratiev return -EINVAL;
1522c33407a8SVladimir Kondratiev }
1523c33407a8SVladimir Kondratiev
1524c33407a8SVladimir Kondratiev if (count > sizeof(buf)) {
1525c33407a8SVladimir Kondratiev wil_err(wil, "Input too long, len = %d\n", (int)count);
1526c33407a8SVladimir Kondratiev return -EINVAL;
1527c33407a8SVladimir Kondratiev }
1528c33407a8SVladimir Kondratiev
1529c33407a8SVladimir Kondratiev rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count);
1530c33407a8SVladimir Kondratiev if (rc < 0)
1531c33407a8SVladimir Kondratiev return rc;
1532c33407a8SVladimir Kondratiev
1533c33407a8SVladimir Kondratiev buf[rc] = '\0';
1534c33407a8SVladimir Kondratiev if (0 == strcmp(buf, run_command))
1535c33407a8SVladimir Kondratiev wil_set_recovery_state(wil, fw_recovery_running);
1536c33407a8SVladimir Kondratiev else
1537c33407a8SVladimir Kondratiev wil_err(wil, "Bad recovery command \"%s\"\n", buf);
1538c33407a8SVladimir Kondratiev
1539c33407a8SVladimir Kondratiev return rc;
1540c33407a8SVladimir Kondratiev }
1541c33407a8SVladimir Kondratiev
1542c33407a8SVladimir Kondratiev static const struct file_operations fops_recovery = {
1543c33407a8SVladimir Kondratiev .read = wil_read_file_recovery,
1544c33407a8SVladimir Kondratiev .write = wil_write_file_recovery,
1545c33407a8SVladimir Kondratiev .open = simple_open,
1546c33407a8SVladimir Kondratiev };
1547c33407a8SVladimir Kondratiev
15483df2cd36SVladimir Kondratiev /*---------Station matrix------------*/
wil_print_rxtid(struct seq_file * s,struct wil_tid_ampdu_rx * r)1549b4490f42SVladimir Kondratiev static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
1550b4490f42SVladimir Kondratiev {
1551b4490f42SVladimir Kondratiev int i;
1552b4490f42SVladimir Kondratiev u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
155391a8edccSVladimir Kondratiev unsigned long long drop_dup = r->drop_dup, drop_old = r->drop_old;
15541bd82ee0SDedy Lansky unsigned long long drop_dup_mcast = r->drop_dup_mcast;
15558fe59627SVladimir Kondratiev
155637f8d26dSDedy Lansky seq_printf(s, "([%2d]) 0x%03x [", r->buf_size, r->head_seq_num);
1557b4490f42SVladimir Kondratiev for (i = 0; i < r->buf_size; i++) {
1558b4490f42SVladimir Kondratiev if (i == index)
1559b4490f42SVladimir Kondratiev seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
1560b4490f42SVladimir Kondratiev else
1561b4490f42SVladimir Kondratiev seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
1562b4490f42SVladimir Kondratiev }
156391a8edccSVladimir Kondratiev seq_printf(s,
15641bd82ee0SDedy Lansky "] total %llu drop %llu (dup %llu + old %llu + dup mcast %llu) last 0x%03x\n",
15651bd82ee0SDedy Lansky r->total, drop_dup + drop_old + drop_dup_mcast, drop_dup,
15661bd82ee0SDedy Lansky drop_old, drop_dup_mcast, r->ssn_last_drop);
1567b4490f42SVladimir Kondratiev }
15683df2cd36SVladimir Kondratiev
wil_print_rxtid_crypto(struct seq_file * s,int tid,struct wil_tid_crypto_rx * c)156958527421SVladimir Kondratiev static void wil_print_rxtid_crypto(struct seq_file *s, int tid,
157058527421SVladimir Kondratiev struct wil_tid_crypto_rx *c)
157158527421SVladimir Kondratiev {
157258527421SVladimir Kondratiev int i;
157358527421SVladimir Kondratiev
157458527421SVladimir Kondratiev for (i = 0; i < 4; i++) {
157558527421SVladimir Kondratiev struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
157658527421SVladimir Kondratiev
157758527421SVladimir Kondratiev if (cc->key_set)
157858527421SVladimir Kondratiev goto has_keys;
157958527421SVladimir Kondratiev }
158058527421SVladimir Kondratiev return;
158158527421SVladimir Kondratiev
158258527421SVladimir Kondratiev has_keys:
158358527421SVladimir Kondratiev if (tid < WIL_STA_TID_NUM)
158458527421SVladimir Kondratiev seq_printf(s, " [%2d] PN", tid);
158558527421SVladimir Kondratiev else
158658527421SVladimir Kondratiev seq_puts(s, " [GR] PN");
158758527421SVladimir Kondratiev
158858527421SVladimir Kondratiev for (i = 0; i < 4; i++) {
158958527421SVladimir Kondratiev struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
159058527421SVladimir Kondratiev
159158527421SVladimir Kondratiev seq_printf(s, " [%i%s]%6phN", i, cc->key_set ? "+" : "-",
159258527421SVladimir Kondratiev cc->pn);
159358527421SVladimir Kondratiev }
159458527421SVladimir Kondratiev seq_puts(s, "\n");
159558527421SVladimir Kondratiev }
159658527421SVladimir Kondratiev
sta_show(struct seq_file * s,void * data)1597986b8348SYangtao Li static int sta_show(struct seq_file *s, void *data)
1598bd33273bSVladimir Kondratiev __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
15993df2cd36SVladimir Kondratiev {
16003df2cd36SVladimir Kondratiev struct wil6210_priv *wil = s->private;
1601c4a110d8SVladimir Kondratiev int i, tid, mcs;
16023df2cd36SVladimir Kondratiev
1603ddf7afddSAhmad Masri for (i = 0; i < wil->max_assoc_sta; i++) {
16043df2cd36SVladimir Kondratiev struct wil_sta_info *p = &wil->sta[i];
16053df2cd36SVladimir Kondratiev char *status = "unknown";
16069d865ee2SLior David u8 aid = 0;
16075bd60982SLior David u8 mid;
1608b9010f10SAhmad Masri bool sta_connected = false;
16098fe59627SVladimir Kondratiev
16103df2cd36SVladimir Kondratiev switch (p->status) {
16113df2cd36SVladimir Kondratiev case wil_sta_unused:
16123df2cd36SVladimir Kondratiev status = "unused ";
16133df2cd36SVladimir Kondratiev break;
16143df2cd36SVladimir Kondratiev case wil_sta_conn_pending:
16153df2cd36SVladimir Kondratiev status = "pending ";
16163df2cd36SVladimir Kondratiev break;
16173df2cd36SVladimir Kondratiev case wil_sta_connected:
16183df2cd36SVladimir Kondratiev status = "connected";
16199d865ee2SLior David aid = p->aid;
16203df2cd36SVladimir Kondratiev break;
16213df2cd36SVladimir Kondratiev }
16225bd60982SLior David mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
1623e4a29bddSAhmad Masri if (mid < GET_MAX_VIFS(wil)) {
1624b9010f10SAhmad Masri struct wil6210_vif *vif = wil->vifs[mid];
1625b9010f10SAhmad Masri
1626b9010f10SAhmad Masri if (vif->wdev.iftype == NL80211_IFTYPE_STATION &&
1627b9010f10SAhmad Masri p->status == wil_sta_connected)
1628b9010f10SAhmad Masri sta_connected = true;
1629b9010f10SAhmad Masri }
1630b9010f10SAhmad Masri /* print roam counter only for connected stations */
1631b9010f10SAhmad Masri if (sta_connected)
1632b9010f10SAhmad Masri seq_printf(s, "[%d] %pM connected (roam counter %d) MID %d AID %d\n",
1633b9010f10SAhmad Masri i, p->addr, p->stats.ft_roams, mid, aid);
1634b9010f10SAhmad Masri else
1635b9010f10SAhmad Masri seq_printf(s, "[%d] %pM %s MID %d AID %d\n", i,
1636b9010f10SAhmad Masri p->addr, status, mid, aid);
1637b4490f42SVladimir Kondratiev
1638b4490f42SVladimir Kondratiev if (p->status == wil_sta_connected) {
1639bd33273bSVladimir Kondratiev spin_lock_bh(&p->tid_rx_lock);
1640b4490f42SVladimir Kondratiev for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1641b4490f42SVladimir Kondratiev struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
164258527421SVladimir Kondratiev struct wil_tid_crypto_rx *c =
164358527421SVladimir Kondratiev &p->tid_crypto_rx[tid];
16448fe59627SVladimir Kondratiev
1645b4490f42SVladimir Kondratiev if (r) {
1646b4490f42SVladimir Kondratiev seq_printf(s, " [%2d] ", tid);
1647b4490f42SVladimir Kondratiev wil_print_rxtid(s, r);
1648b4490f42SVladimir Kondratiev }
164958527421SVladimir Kondratiev
165058527421SVladimir Kondratiev wil_print_rxtid_crypto(s, tid, c);
1651b4490f42SVladimir Kondratiev }
165258527421SVladimir Kondratiev wil_print_rxtid_crypto(s, WIL_STA_TID_NUM,
165358527421SVladimir Kondratiev &p->group_crypto_rx);
1654bd33273bSVladimir Kondratiev spin_unlock_bh(&p->tid_rx_lock);
16553b282bc6SVladimir Kondratiev seq_printf(s,
165658527421SVladimir Kondratiev "Rx invalid frame: non-data %lu, short %lu, large %lu, replay %lu\n",
16573b282bc6SVladimir Kondratiev p->stats.rx_non_data_frame,
16583b282bc6SVladimir Kondratiev p->stats.rx_short_frame,
165958527421SVladimir Kondratiev p->stats.rx_large_frame,
166058527421SVladimir Kondratiev p->stats.rx_replay);
1661d98b8539SMaya Erez seq_printf(s,
16620b853210SMaya Erez "mic error %lu, key error %lu, amsdu error %lu, csum error %lu\n",
1663d98b8539SMaya Erez p->stats.rx_mic_error,
1664d98b8539SMaya Erez p->stats.rx_key_error,
16650b853210SMaya Erez p->stats.rx_amsdu_error,
16660b853210SMaya Erez p->stats.rx_csum_err);
1667d98b8539SMaya Erez
1668c4a110d8SVladimir Kondratiev seq_puts(s, "Rx/MCS:");
1669c4a110d8SVladimir Kondratiev for (mcs = 0; mcs < ARRAY_SIZE(p->stats.rx_per_mcs);
1670c4a110d8SVladimir Kondratiev mcs++)
1671c4a110d8SVladimir Kondratiev seq_printf(s, " %lld",
1672c4a110d8SVladimir Kondratiev p->stats.rx_per_mcs[mcs]);
1673c4a110d8SVladimir Kondratiev seq_puts(s, "\n");
1674b4490f42SVladimir Kondratiev }
16753df2cd36SVladimir Kondratiev }
16763df2cd36SVladimir Kondratiev
16773df2cd36SVladimir Kondratiev return 0;
16783df2cd36SVladimir Kondratiev }
1679986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(sta);
16803df2cd36SVladimir Kondratiev
mids_show(struct seq_file * s,void * data)1681986b8348SYangtao Li static int mids_show(struct seq_file *s, void *data)
16823a3b745fSLior David {
16833a3b745fSLior David struct wil6210_priv *wil = s->private;
16843a3b745fSLior David struct wil6210_vif *vif;
16853a3b745fSLior David struct net_device *ndev;
16863a3b745fSLior David int i;
16873a3b745fSLior David
16883a3b745fSLior David mutex_lock(&wil->vif_mutex);
1689e4a29bddSAhmad Masri for (i = 0; i < GET_MAX_VIFS(wil); i++) {
16903a3b745fSLior David vif = wil->vifs[i];
16913a3b745fSLior David
16923a3b745fSLior David if (vif) {
16933a3b745fSLior David ndev = vif_to_ndev(vif);
16943a3b745fSLior David seq_printf(s, "[%d] %pM %s\n", i, ndev->dev_addr,
16953a3b745fSLior David ndev->name);
16963a3b745fSLior David } else {
16973a3b745fSLior David seq_printf(s, "[%d] unused\n", i);
16983a3b745fSLior David }
16993a3b745fSLior David }
17003a3b745fSLior David mutex_unlock(&wil->vif_mutex);
17013a3b745fSLior David
17023a3b745fSLior David return 0;
17033a3b745fSLior David }
1704986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(mids);
17053a3b745fSLior David
wil_tx_latency_debugfs_show(struct seq_file * s,void * data)1706a24a3d6aSDedy Lansky static int wil_tx_latency_debugfs_show(struct seq_file *s, void *data)
1707a24a3d6aSDedy Lansky __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
1708a24a3d6aSDedy Lansky {
1709a24a3d6aSDedy Lansky struct wil6210_priv *wil = s->private;
1710a24a3d6aSDedy Lansky int i, bin;
1711a24a3d6aSDedy Lansky
1712ddf7afddSAhmad Masri for (i = 0; i < wil->max_assoc_sta; i++) {
1713a24a3d6aSDedy Lansky struct wil_sta_info *p = &wil->sta[i];
1714a24a3d6aSDedy Lansky char *status = "unknown";
1715a24a3d6aSDedy Lansky u8 aid = 0;
1716a24a3d6aSDedy Lansky u8 mid;
1717a24a3d6aSDedy Lansky
1718a24a3d6aSDedy Lansky if (!p->tx_latency_bins)
1719a24a3d6aSDedy Lansky continue;
1720a24a3d6aSDedy Lansky
1721a24a3d6aSDedy Lansky switch (p->status) {
1722a24a3d6aSDedy Lansky case wil_sta_unused:
1723a24a3d6aSDedy Lansky status = "unused ";
1724a24a3d6aSDedy Lansky break;
1725a24a3d6aSDedy Lansky case wil_sta_conn_pending:
1726a24a3d6aSDedy Lansky status = "pending ";
1727a24a3d6aSDedy Lansky break;
1728a24a3d6aSDedy Lansky case wil_sta_connected:
1729a24a3d6aSDedy Lansky status = "connected";
1730a24a3d6aSDedy Lansky aid = p->aid;
1731a24a3d6aSDedy Lansky break;
1732a24a3d6aSDedy Lansky }
1733a24a3d6aSDedy Lansky mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
1734a24a3d6aSDedy Lansky seq_printf(s, "[%d] %pM %s MID %d AID %d\n", i, p->addr, status,
1735a24a3d6aSDedy Lansky mid, aid);
1736a24a3d6aSDedy Lansky
1737a24a3d6aSDedy Lansky if (p->status == wil_sta_connected) {
1738a24a3d6aSDedy Lansky u64 num_packets = 0;
1739a24a3d6aSDedy Lansky u64 tx_latency_avg = p->stats.tx_latency_total_us;
1740a24a3d6aSDedy Lansky
1741a24a3d6aSDedy Lansky seq_puts(s, "Tx/Latency bin:");
1742a24a3d6aSDedy Lansky for (bin = 0; bin < WIL_NUM_LATENCY_BINS; bin++) {
1743a24a3d6aSDedy Lansky seq_printf(s, " %lld",
1744a24a3d6aSDedy Lansky p->tx_latency_bins[bin]);
1745a24a3d6aSDedy Lansky num_packets += p->tx_latency_bins[bin];
1746a24a3d6aSDedy Lansky }
1747a24a3d6aSDedy Lansky seq_puts(s, "\n");
1748a24a3d6aSDedy Lansky if (!num_packets)
1749a24a3d6aSDedy Lansky continue;
1750a24a3d6aSDedy Lansky do_div(tx_latency_avg, num_packets);
1751a24a3d6aSDedy Lansky seq_printf(s, "Tx/Latency min/avg/max (us): %d/%lld/%d",
1752a24a3d6aSDedy Lansky p->stats.tx_latency_min_us,
1753a24a3d6aSDedy Lansky tx_latency_avg,
1754a24a3d6aSDedy Lansky p->stats.tx_latency_max_us);
1755a24a3d6aSDedy Lansky
1756a24a3d6aSDedy Lansky seq_puts(s, "\n");
1757a24a3d6aSDedy Lansky }
1758a24a3d6aSDedy Lansky }
1759a24a3d6aSDedy Lansky
1760a24a3d6aSDedy Lansky return 0;
1761a24a3d6aSDedy Lansky }
1762a24a3d6aSDedy Lansky
wil_tx_latency_seq_open(struct inode * inode,struct file * file)1763a24a3d6aSDedy Lansky static int wil_tx_latency_seq_open(struct inode *inode, struct file *file)
1764a24a3d6aSDedy Lansky {
1765a24a3d6aSDedy Lansky return single_open(file, wil_tx_latency_debugfs_show,
1766a24a3d6aSDedy Lansky inode->i_private);
1767a24a3d6aSDedy Lansky }
1768a24a3d6aSDedy Lansky
wil_tx_latency_write(struct file * file,const char __user * buf,size_t len,loff_t * ppos)1769a24a3d6aSDedy Lansky static ssize_t wil_tx_latency_write(struct file *file, const char __user *buf,
1770a24a3d6aSDedy Lansky size_t len, loff_t *ppos)
1771a24a3d6aSDedy Lansky {
1772a24a3d6aSDedy Lansky struct seq_file *s = file->private_data;
1773a24a3d6aSDedy Lansky struct wil6210_priv *wil = s->private;
1774a24a3d6aSDedy Lansky int val, rc, i;
1775a24a3d6aSDedy Lansky bool enable;
1776a24a3d6aSDedy Lansky
1777a24a3d6aSDedy Lansky rc = kstrtoint_from_user(buf, len, 0, &val);
1778a24a3d6aSDedy Lansky if (rc) {
1779a24a3d6aSDedy Lansky wil_err(wil, "Invalid argument\n");
1780a24a3d6aSDedy Lansky return rc;
1781a24a3d6aSDedy Lansky }
1782a24a3d6aSDedy Lansky if (val == 1)
1783a24a3d6aSDedy Lansky /* default resolution */
1784a24a3d6aSDedy Lansky val = 500;
1785a24a3d6aSDedy Lansky if (val && (val < 50 || val > 1000)) {
1786a24a3d6aSDedy Lansky wil_err(wil, "Invalid resolution %d\n", val);
1787a24a3d6aSDedy Lansky return -EINVAL;
1788a24a3d6aSDedy Lansky }
1789a24a3d6aSDedy Lansky
1790a24a3d6aSDedy Lansky enable = !!val;
1791a24a3d6aSDedy Lansky if (wil->tx_latency == enable)
1792a24a3d6aSDedy Lansky return len;
1793a24a3d6aSDedy Lansky
1794a24a3d6aSDedy Lansky wil_info(wil, "%s TX latency measurements (resolution %dusec)\n",
1795a24a3d6aSDedy Lansky enable ? "Enabling" : "Disabling", val);
1796a24a3d6aSDedy Lansky
1797a24a3d6aSDedy Lansky if (enable) {
1798a24a3d6aSDedy Lansky size_t sz = sizeof(u64) * WIL_NUM_LATENCY_BINS;
1799a24a3d6aSDedy Lansky
1800a24a3d6aSDedy Lansky wil->tx_latency_res = val;
1801ddf7afddSAhmad Masri for (i = 0; i < wil->max_assoc_sta; i++) {
1802a24a3d6aSDedy Lansky struct wil_sta_info *sta = &wil->sta[i];
1803a24a3d6aSDedy Lansky
1804a24a3d6aSDedy Lansky kfree(sta->tx_latency_bins);
1805a24a3d6aSDedy Lansky sta->tx_latency_bins = kzalloc(sz, GFP_KERNEL);
1806a24a3d6aSDedy Lansky if (!sta->tx_latency_bins)
1807a24a3d6aSDedy Lansky return -ENOMEM;
1808a24a3d6aSDedy Lansky sta->stats.tx_latency_min_us = U32_MAX;
1809a24a3d6aSDedy Lansky sta->stats.tx_latency_max_us = 0;
1810a24a3d6aSDedy Lansky sta->stats.tx_latency_total_us = 0;
1811a24a3d6aSDedy Lansky }
1812a24a3d6aSDedy Lansky }
1813a24a3d6aSDedy Lansky wil->tx_latency = enable;
1814a24a3d6aSDedy Lansky
1815a24a3d6aSDedy Lansky return len;
1816a24a3d6aSDedy Lansky }
1817a24a3d6aSDedy Lansky
1818a24a3d6aSDedy Lansky static const struct file_operations fops_tx_latency = {
1819a24a3d6aSDedy Lansky .open = wil_tx_latency_seq_open,
1820a24a3d6aSDedy Lansky .release = single_release,
1821a24a3d6aSDedy Lansky .read = seq_read,
1822a24a3d6aSDedy Lansky .write = wil_tx_latency_write,
1823a24a3d6aSDedy Lansky .llseek = seq_lseek,
1824a24a3d6aSDedy Lansky };
1825a24a3d6aSDedy Lansky
wil_link_stats_print_basic(struct wil6210_vif * vif,struct seq_file * s,struct wmi_link_stats_basic * basic)18260c936b3cSDedy Lansky static void wil_link_stats_print_basic(struct wil6210_vif *vif,
18270c936b3cSDedy Lansky struct seq_file *s,
18280c936b3cSDedy Lansky struct wmi_link_stats_basic *basic)
18290c936b3cSDedy Lansky {
18300c936b3cSDedy Lansky char per[5] = "?";
18310c936b3cSDedy Lansky
18320c936b3cSDedy Lansky if (basic->per_average != 0xff)
18330c936b3cSDedy Lansky snprintf(per, sizeof(per), "%d%%", basic->per_average);
18340c936b3cSDedy Lansky
18350c936b3cSDedy Lansky seq_printf(s, "CID %d {\n"
18367064e219SMax Chen "\tTxMCS %s TxTpt %d\n"
18370c936b3cSDedy Lansky "\tGoodput(rx:tx) %d:%d\n"
18380c936b3cSDedy Lansky "\tRxBcastFrames %d\n"
18390c936b3cSDedy Lansky "\tRSSI %d SQI %d SNR %d PER %s\n"
18400c936b3cSDedy Lansky "\tRx RFC %d Ant num %d\n"
18410c936b3cSDedy Lansky "\tSectors(rx:tx) my %d:%d peer %d:%d\n"
18420c936b3cSDedy Lansky "}\n",
18430c936b3cSDedy Lansky basic->cid,
18447064e219SMax Chen WIL_EXTENDED_MCS_CHECK(basic->bf_mcs),
18457064e219SMax Chen le32_to_cpu(basic->tx_tpt),
18460c936b3cSDedy Lansky le32_to_cpu(basic->rx_goodput),
18470c936b3cSDedy Lansky le32_to_cpu(basic->tx_goodput),
18480c936b3cSDedy Lansky le32_to_cpu(basic->rx_bcast_frames),
18490c936b3cSDedy Lansky basic->rssi, basic->sqi, basic->snr, per,
18500c936b3cSDedy Lansky basic->selected_rfc, basic->rx_effective_ant_num,
18510c936b3cSDedy Lansky basic->my_rx_sector, basic->my_tx_sector,
18520c936b3cSDedy Lansky basic->other_rx_sector, basic->other_tx_sector);
18530c936b3cSDedy Lansky }
18540c936b3cSDedy Lansky
wil_link_stats_print_global(struct wil6210_priv * wil,struct seq_file * s,struct wmi_link_stats_global * global)18550c936b3cSDedy Lansky static void wil_link_stats_print_global(struct wil6210_priv *wil,
18560c936b3cSDedy Lansky struct seq_file *s,
18570c936b3cSDedy Lansky struct wmi_link_stats_global *global)
18580c936b3cSDedy Lansky {
18590c936b3cSDedy Lansky seq_printf(s, "Frames(rx:tx) %d:%d\n"
18600c936b3cSDedy Lansky "BA Frames(rx:tx) %d:%d\n"
18610c936b3cSDedy Lansky "Beacons %d\n"
18620c936b3cSDedy Lansky "Rx Errors (MIC:CRC) %d:%d\n"
18630c936b3cSDedy Lansky "Tx Errors (no ack) %d\n",
18640c936b3cSDedy Lansky le32_to_cpu(global->rx_frames),
18650c936b3cSDedy Lansky le32_to_cpu(global->tx_frames),
18660c936b3cSDedy Lansky le32_to_cpu(global->rx_ba_frames),
18670c936b3cSDedy Lansky le32_to_cpu(global->tx_ba_frames),
18680c936b3cSDedy Lansky le32_to_cpu(global->tx_beacons),
18690c936b3cSDedy Lansky le32_to_cpu(global->rx_mic_errors),
18700c936b3cSDedy Lansky le32_to_cpu(global->rx_crc_errors),
18710c936b3cSDedy Lansky le32_to_cpu(global->tx_fail_no_ack));
18720c936b3cSDedy Lansky }
18730c936b3cSDedy Lansky
wil_link_stats_debugfs_show_vif(struct wil6210_vif * vif,struct seq_file * s)18740c936b3cSDedy Lansky static void wil_link_stats_debugfs_show_vif(struct wil6210_vif *vif,
18750c936b3cSDedy Lansky struct seq_file *s)
18760c936b3cSDedy Lansky {
18770c936b3cSDedy Lansky struct wil6210_priv *wil = vif_to_wil(vif);
18780c936b3cSDedy Lansky struct wmi_link_stats_basic *stats;
18790c936b3cSDedy Lansky int i;
18800c936b3cSDedy Lansky
18810c936b3cSDedy Lansky if (!vif->fw_stats_ready) {
18820c936b3cSDedy Lansky seq_puts(s, "no statistics\n");
18830c936b3cSDedy Lansky return;
18840c936b3cSDedy Lansky }
18850c936b3cSDedy Lansky
18860c936b3cSDedy Lansky seq_printf(s, "TSF %lld\n", vif->fw_stats_tsf);
1887ddf7afddSAhmad Masri for (i = 0; i < wil->max_assoc_sta; i++) {
18880c936b3cSDedy Lansky if (wil->sta[i].status == wil_sta_unused)
18890c936b3cSDedy Lansky continue;
18900c936b3cSDedy Lansky if (wil->sta[i].mid != vif->mid)
18910c936b3cSDedy Lansky continue;
18920c936b3cSDedy Lansky
18930c936b3cSDedy Lansky stats = &wil->sta[i].fw_stats_basic;
18940c936b3cSDedy Lansky wil_link_stats_print_basic(vif, s, stats);
18950c936b3cSDedy Lansky }
18960c936b3cSDedy Lansky }
18970c936b3cSDedy Lansky
wil_link_stats_debugfs_show(struct seq_file * s,void * data)18980c936b3cSDedy Lansky static int wil_link_stats_debugfs_show(struct seq_file *s, void *data)
18990c936b3cSDedy Lansky {
19000c936b3cSDedy Lansky struct wil6210_priv *wil = s->private;
19010c936b3cSDedy Lansky struct wil6210_vif *vif;
19020c936b3cSDedy Lansky int i, rc;
19030c936b3cSDedy Lansky
19040c936b3cSDedy Lansky rc = mutex_lock_interruptible(&wil->vif_mutex);
19050c936b3cSDedy Lansky if (rc)
19060c936b3cSDedy Lansky return rc;
19070c936b3cSDedy Lansky
19080c936b3cSDedy Lansky /* iterate over all MIDs and show per-cid statistics. Then show the
19090c936b3cSDedy Lansky * global statistics
19100c936b3cSDedy Lansky */
1911e4a29bddSAhmad Masri for (i = 0; i < GET_MAX_VIFS(wil); i++) {
19120c936b3cSDedy Lansky vif = wil->vifs[i];
19130c936b3cSDedy Lansky
19140c936b3cSDedy Lansky seq_printf(s, "MID %d ", i);
19150c936b3cSDedy Lansky if (!vif) {
19160c936b3cSDedy Lansky seq_puts(s, "unused\n");
19170c936b3cSDedy Lansky continue;
19180c936b3cSDedy Lansky }
19190c936b3cSDedy Lansky
19200c936b3cSDedy Lansky wil_link_stats_debugfs_show_vif(vif, s);
19210c936b3cSDedy Lansky }
19220c936b3cSDedy Lansky
19230c936b3cSDedy Lansky mutex_unlock(&wil->vif_mutex);
19240c936b3cSDedy Lansky
19250c936b3cSDedy Lansky return 0;
19260c936b3cSDedy Lansky }
19270c936b3cSDedy Lansky
wil_link_stats_seq_open(struct inode * inode,struct file * file)19280c936b3cSDedy Lansky static int wil_link_stats_seq_open(struct inode *inode, struct file *file)
19290c936b3cSDedy Lansky {
19300c936b3cSDedy Lansky return single_open(file, wil_link_stats_debugfs_show, inode->i_private);
19310c936b3cSDedy Lansky }
19320c936b3cSDedy Lansky
wil_link_stats_write(struct file * file,const char __user * buf,size_t len,loff_t * ppos)19330c936b3cSDedy Lansky static ssize_t wil_link_stats_write(struct file *file, const char __user *buf,
19340c936b3cSDedy Lansky size_t len, loff_t *ppos)
19350c936b3cSDedy Lansky {
19360c936b3cSDedy Lansky struct seq_file *s = file->private_data;
19370c936b3cSDedy Lansky struct wil6210_priv *wil = s->private;
19380c936b3cSDedy Lansky int cid, interval, rc, i;
19390c936b3cSDedy Lansky struct wil6210_vif *vif;
19400c936b3cSDedy Lansky char *kbuf = kmalloc(len + 1, GFP_KERNEL);
19410c936b3cSDedy Lansky
19420c936b3cSDedy Lansky if (!kbuf)
19430c936b3cSDedy Lansky return -ENOMEM;
19440c936b3cSDedy Lansky
19450c936b3cSDedy Lansky rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
19460c936b3cSDedy Lansky if (rc != len) {
19470c936b3cSDedy Lansky kfree(kbuf);
19480c936b3cSDedy Lansky return rc >= 0 ? -EIO : rc;
19490c936b3cSDedy Lansky }
19500c936b3cSDedy Lansky
19510c936b3cSDedy Lansky kbuf[len] = '\0';
19520c936b3cSDedy Lansky /* specify cid (use -1 for all cids) and snapshot interval in ms */
19530c936b3cSDedy Lansky rc = sscanf(kbuf, "%d %d", &cid, &interval);
19540c936b3cSDedy Lansky kfree(kbuf);
19550c936b3cSDedy Lansky if (rc < 0)
19560c936b3cSDedy Lansky return rc;
19570c936b3cSDedy Lansky if (rc < 2 || interval < 0)
19580c936b3cSDedy Lansky return -EINVAL;
19590c936b3cSDedy Lansky
19600c936b3cSDedy Lansky wil_info(wil, "request link statistics, cid %d interval %d\n",
19610c936b3cSDedy Lansky cid, interval);
19620c936b3cSDedy Lansky
19630c936b3cSDedy Lansky rc = mutex_lock_interruptible(&wil->vif_mutex);
19640c936b3cSDedy Lansky if (rc)
19650c936b3cSDedy Lansky return rc;
19660c936b3cSDedy Lansky
1967e4a29bddSAhmad Masri for (i = 0; i < GET_MAX_VIFS(wil); i++) {
19680c936b3cSDedy Lansky vif = wil->vifs[i];
19690c936b3cSDedy Lansky if (!vif)
19700c936b3cSDedy Lansky continue;
19710c936b3cSDedy Lansky
19720c936b3cSDedy Lansky rc = wmi_link_stats_cfg(vif, WMI_LINK_STATS_TYPE_BASIC,
19730c936b3cSDedy Lansky (cid == -1 ? 0xff : cid), interval);
19740c936b3cSDedy Lansky if (rc)
19750c936b3cSDedy Lansky wil_err(wil, "link statistics failed for mid %d\n", i);
19760c936b3cSDedy Lansky }
19770c936b3cSDedy Lansky mutex_unlock(&wil->vif_mutex);
19780c936b3cSDedy Lansky
19790c936b3cSDedy Lansky return len;
19800c936b3cSDedy Lansky }
19810c936b3cSDedy Lansky
19820c936b3cSDedy Lansky static const struct file_operations fops_link_stats = {
19830c936b3cSDedy Lansky .open = wil_link_stats_seq_open,
19840c936b3cSDedy Lansky .release = single_release,
19850c936b3cSDedy Lansky .read = seq_read,
19860c936b3cSDedy Lansky .write = wil_link_stats_write,
19870c936b3cSDedy Lansky .llseek = seq_lseek,
19880c936b3cSDedy Lansky };
19890c936b3cSDedy Lansky
19900c936b3cSDedy Lansky static int
wil_link_stats_global_debugfs_show(struct seq_file * s,void * data)19910c936b3cSDedy Lansky wil_link_stats_global_debugfs_show(struct seq_file *s, void *data)
19920c936b3cSDedy Lansky {
19930c936b3cSDedy Lansky struct wil6210_priv *wil = s->private;
19940c936b3cSDedy Lansky
19950c936b3cSDedy Lansky if (!wil->fw_stats_global.ready)
19960c936b3cSDedy Lansky return 0;
19970c936b3cSDedy Lansky
19980c936b3cSDedy Lansky seq_printf(s, "TSF %lld\n", wil->fw_stats_global.tsf);
19990c936b3cSDedy Lansky wil_link_stats_print_global(wil, s, &wil->fw_stats_global.stats);
20000c936b3cSDedy Lansky
20010c936b3cSDedy Lansky return 0;
20020c936b3cSDedy Lansky }
20030c936b3cSDedy Lansky
20040c936b3cSDedy Lansky static int
wil_link_stats_global_seq_open(struct inode * inode,struct file * file)20050c936b3cSDedy Lansky wil_link_stats_global_seq_open(struct inode *inode, struct file *file)
20060c936b3cSDedy Lansky {
20070c936b3cSDedy Lansky return single_open(file, wil_link_stats_global_debugfs_show,
20080c936b3cSDedy Lansky inode->i_private);
20090c936b3cSDedy Lansky }
20100c936b3cSDedy Lansky
20110c936b3cSDedy Lansky static ssize_t
wil_link_stats_global_write(struct file * file,const char __user * buf,size_t len,loff_t * ppos)20120c936b3cSDedy Lansky wil_link_stats_global_write(struct file *file, const char __user *buf,
20130c936b3cSDedy Lansky size_t len, loff_t *ppos)
20140c936b3cSDedy Lansky {
20150c936b3cSDedy Lansky struct seq_file *s = file->private_data;
20160c936b3cSDedy Lansky struct wil6210_priv *wil = s->private;
20170c936b3cSDedy Lansky int interval, rc;
20180c936b3cSDedy Lansky struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
20190c936b3cSDedy Lansky
20200c936b3cSDedy Lansky /* specify snapshot interval in ms */
20210c936b3cSDedy Lansky rc = kstrtoint_from_user(buf, len, 0, &interval);
20220c936b3cSDedy Lansky if (rc || interval < 0) {
20230c936b3cSDedy Lansky wil_err(wil, "Invalid argument\n");
20240c936b3cSDedy Lansky return -EINVAL;
20250c936b3cSDedy Lansky }
20260c936b3cSDedy Lansky
20270c936b3cSDedy Lansky wil_info(wil, "request global link stats, interval %d\n", interval);
20280c936b3cSDedy Lansky
20290c936b3cSDedy Lansky rc = wmi_link_stats_cfg(vif, WMI_LINK_STATS_TYPE_GLOBAL, 0, interval);
20300c936b3cSDedy Lansky if (rc)
20310c936b3cSDedy Lansky wil_err(wil, "global link stats failed %d\n", rc);
20320c936b3cSDedy Lansky
20330c936b3cSDedy Lansky return rc ? rc : len;
20340c936b3cSDedy Lansky }
20350c936b3cSDedy Lansky
20360c936b3cSDedy Lansky static const struct file_operations fops_link_stats_global = {
20370c936b3cSDedy Lansky .open = wil_link_stats_global_seq_open,
20380c936b3cSDedy Lansky .release = single_release,
20390c936b3cSDedy Lansky .read = seq_read,
20400c936b3cSDedy Lansky .write = wil_link_stats_global_write,
20410c936b3cSDedy Lansky .llseek = seq_lseek,
20420c936b3cSDedy Lansky };
20430c936b3cSDedy Lansky
wil_read_file_led_cfg(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)204410d599adSMaya Erez static ssize_t wil_read_file_led_cfg(struct file *file, char __user *user_buf,
204510d599adSMaya Erez size_t count, loff_t *ppos)
204610d599adSMaya Erez {
204710d599adSMaya Erez char buf[80];
204810d599adSMaya Erez int n;
204910d599adSMaya Erez
205010d599adSMaya Erez n = snprintf(buf, sizeof(buf),
205110d599adSMaya Erez "led_id is set to %d, echo 1 to enable, 0 to disable\n",
205210d599adSMaya Erez led_id);
205310d599adSMaya Erez
205410d599adSMaya Erez n = min_t(int, n, sizeof(buf));
205510d599adSMaya Erez
205610d599adSMaya Erez return simple_read_from_buffer(user_buf, count, ppos,
205710d599adSMaya Erez buf, n);
205810d599adSMaya Erez }
205910d599adSMaya Erez
wil_write_file_led_cfg(struct file * file,const char __user * buf_,size_t count,loff_t * ppos)206010d599adSMaya Erez static ssize_t wil_write_file_led_cfg(struct file *file,
206110d599adSMaya Erez const char __user *buf_,
206210d599adSMaya Erez size_t count, loff_t *ppos)
206310d599adSMaya Erez {
206410d599adSMaya Erez struct wil6210_priv *wil = file->private_data;
206510d599adSMaya Erez int val;
206610d599adSMaya Erez int rc;
206710d599adSMaya Erez
206810d599adSMaya Erez rc = kstrtoint_from_user(buf_, count, 0, &val);
206910d599adSMaya Erez if (rc) {
207010d599adSMaya Erez wil_err(wil, "Invalid argument\n");
207110d599adSMaya Erez return rc;
207210d599adSMaya Erez }
207310d599adSMaya Erez
207410d599adSMaya Erez wil_info(wil, "%s led %d\n", val ? "Enabling" : "Disabling", led_id);
207510d599adSMaya Erez rc = wmi_led_cfg(wil, val);
207610d599adSMaya Erez if (rc) {
207710d599adSMaya Erez wil_info(wil, "%s led %d failed\n",
207810d599adSMaya Erez val ? "Enabling" : "Disabling", led_id);
207910d599adSMaya Erez return rc;
208010d599adSMaya Erez }
208110d599adSMaya Erez
208210d599adSMaya Erez return count;
208310d599adSMaya Erez }
208410d599adSMaya Erez
208510d599adSMaya Erez static const struct file_operations fops_led_cfg = {
208610d599adSMaya Erez .read = wil_read_file_led_cfg,
208710d599adSMaya Erez .write = wil_write_file_led_cfg,
208810d599adSMaya Erez .open = simple_open,
208910d599adSMaya Erez };
209010d599adSMaya Erez
209110d599adSMaya Erez /* led_blink_time, write:
209210d599adSMaya Erez * "<blink_on_slow> <blink_off_slow> <blink_on_med> <blink_off_med> <blink_on_fast> <blink_off_fast>
209310d599adSMaya Erez */
wil_write_led_blink_time(struct file * file,const char __user * buf,size_t len,loff_t * ppos)209410d599adSMaya Erez static ssize_t wil_write_led_blink_time(struct file *file,
209510d599adSMaya Erez const char __user *buf,
209610d599adSMaya Erez size_t len, loff_t *ppos)
209710d599adSMaya Erez {
209810d599adSMaya Erez int rc;
209910d599adSMaya Erez char *kbuf = kmalloc(len + 1, GFP_KERNEL);
210010d599adSMaya Erez
210110d599adSMaya Erez if (!kbuf)
210210d599adSMaya Erez return -ENOMEM;
210310d599adSMaya Erez
210410d599adSMaya Erez rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
210510d599adSMaya Erez if (rc != len) {
210610d599adSMaya Erez kfree(kbuf);
210710d599adSMaya Erez return rc >= 0 ? -EIO : rc;
210810d599adSMaya Erez }
210910d599adSMaya Erez
211010d599adSMaya Erez kbuf[len] = '\0';
211110d599adSMaya Erez rc = sscanf(kbuf, "%d %d %d %d %d %d",
211210d599adSMaya Erez &led_blink_time[WIL_LED_TIME_SLOW].on_ms,
211310d599adSMaya Erez &led_blink_time[WIL_LED_TIME_SLOW].off_ms,
211410d599adSMaya Erez &led_blink_time[WIL_LED_TIME_MED].on_ms,
211510d599adSMaya Erez &led_blink_time[WIL_LED_TIME_MED].off_ms,
211610d599adSMaya Erez &led_blink_time[WIL_LED_TIME_FAST].on_ms,
211710d599adSMaya Erez &led_blink_time[WIL_LED_TIME_FAST].off_ms);
211810d599adSMaya Erez kfree(kbuf);
211910d599adSMaya Erez
212010d599adSMaya Erez if (rc < 0)
212110d599adSMaya Erez return rc;
212210d599adSMaya Erez if (rc < 6)
212310d599adSMaya Erez return -EINVAL;
212410d599adSMaya Erez
212510d599adSMaya Erez return len;
212610d599adSMaya Erez }
212710d599adSMaya Erez
wil_read_led_blink_time(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)212810d599adSMaya Erez static ssize_t wil_read_led_blink_time(struct file *file, char __user *user_buf,
212910d599adSMaya Erez size_t count, loff_t *ppos)
213010d599adSMaya Erez {
213110d599adSMaya Erez static char text[400];
213210d599adSMaya Erez
213310d599adSMaya Erez snprintf(text, sizeof(text),
213410d599adSMaya Erez "To set led blink on/off time variables write:\n"
213510d599adSMaya Erez "<blink_on_slow> <blink_off_slow> <blink_on_med> "
213610d599adSMaya Erez "<blink_off_med> <blink_on_fast> <blink_off_fast>\n"
213710d599adSMaya Erez "The current values are:\n"
213810d599adSMaya Erez "%d %d %d %d %d %d\n",
213910d599adSMaya Erez led_blink_time[WIL_LED_TIME_SLOW].on_ms,
214010d599adSMaya Erez led_blink_time[WIL_LED_TIME_SLOW].off_ms,
214110d599adSMaya Erez led_blink_time[WIL_LED_TIME_MED].on_ms,
214210d599adSMaya Erez led_blink_time[WIL_LED_TIME_MED].off_ms,
214310d599adSMaya Erez led_blink_time[WIL_LED_TIME_FAST].on_ms,
214410d599adSMaya Erez led_blink_time[WIL_LED_TIME_FAST].off_ms);
214510d599adSMaya Erez
214610d599adSMaya Erez return simple_read_from_buffer(user_buf, count, ppos, text,
214710d599adSMaya Erez sizeof(text));
214810d599adSMaya Erez }
214910d599adSMaya Erez
215010d599adSMaya Erez static const struct file_operations fops_led_blink_time = {
215110d599adSMaya Erez .read = wil_read_led_blink_time,
215210d599adSMaya Erez .write = wil_write_led_blink_time,
215310d599adSMaya Erez .open = simple_open,
215410d599adSMaya Erez };
215510d599adSMaya Erez
215612bace75SLior David /*---------FW capabilities------------*/
fw_capabilities_show(struct seq_file * s,void * data)2157*e5398f92SLiu Shixin static int fw_capabilities_show(struct seq_file *s, void *data)
215812bace75SLior David {
215912bace75SLior David struct wil6210_priv *wil = s->private;
216012bace75SLior David
216112bace75SLior David seq_printf(s, "fw_capabilities : %*pb\n", WMI_FW_CAPABILITY_MAX,
216212bace75SLior David wil->fw_capabilities);
216312bace75SLior David
216412bace75SLior David return 0;
216512bace75SLior David }
2166*e5398f92SLiu Shixin DEFINE_SHOW_ATTRIBUTE(fw_capabilities);
216712bace75SLior David
216813cd9f75SLior David /*---------FW version------------*/
fw_version_show(struct seq_file * s,void * data)2169*e5398f92SLiu Shixin static int fw_version_show(struct seq_file *s, void *data)
217013cd9f75SLior David {
217113cd9f75SLior David struct wil6210_priv *wil = s->private;
217213cd9f75SLior David
217313cd9f75SLior David if (wil->fw_version[0])
217413cd9f75SLior David seq_printf(s, "%s\n", wil->fw_version);
217513cd9f75SLior David else
217613cd9f75SLior David seq_puts(s, "N/A\n");
217713cd9f75SLior David
217813cd9f75SLior David return 0;
217913cd9f75SLior David }
2180*e5398f92SLiu Shixin DEFINE_SHOW_ATTRIBUTE(fw_version);
218113cd9f75SLior David
2182fe9ee51eSMaya Erez /*---------suspend_stats---------*/
wil_write_suspend_stats(struct file * file,const char __user * buf,size_t len,loff_t * ppos)2183fe9ee51eSMaya Erez static ssize_t wil_write_suspend_stats(struct file *file,
2184fe9ee51eSMaya Erez const char __user *buf,
2185fe9ee51eSMaya Erez size_t len, loff_t *ppos)
2186fe9ee51eSMaya Erez {
2187fe9ee51eSMaya Erez struct wil6210_priv *wil = file->private_data;
2188fe9ee51eSMaya Erez
2189fe9ee51eSMaya Erez memset(&wil->suspend_stats, 0, sizeof(wil->suspend_stats));
2190fe9ee51eSMaya Erez
2191fe9ee51eSMaya Erez return len;
2192fe9ee51eSMaya Erez }
2193fe9ee51eSMaya Erez
wil_read_suspend_stats(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)2194fe9ee51eSMaya Erez static ssize_t wil_read_suspend_stats(struct file *file,
2195fe9ee51eSMaya Erez char __user *user_buf,
2196fe9ee51eSMaya Erez size_t count, loff_t *ppos)
2197fe9ee51eSMaya Erez {
2198fe9ee51eSMaya Erez struct wil6210_priv *wil = file->private_data;
2199bd8bdc6cSLazar Alexei char *text;
2200bd8bdc6cSLazar Alexei int n, ret, text_size = 500;
2201fe9ee51eSMaya Erez
2202bd8bdc6cSLazar Alexei text = kmalloc(text_size, GFP_KERNEL);
2203bd8bdc6cSLazar Alexei if (!text)
2204bd8bdc6cSLazar Alexei return -ENOMEM;
2205bd8bdc6cSLazar Alexei
2206bd8bdc6cSLazar Alexei n = snprintf(text, text_size,
2207bd8bdc6cSLazar Alexei "Radio on suspend statistics:\n"
2208fe9ee51eSMaya Erez "successful suspends:%ld failed suspends:%ld\n"
2209fe9ee51eSMaya Erez "successful resumes:%ld failed resumes:%ld\n"
2210bd8bdc6cSLazar Alexei "rejected by device:%ld\n"
2211bd8bdc6cSLazar Alexei "Radio off suspend statistics:\n"
2212bd8bdc6cSLazar Alexei "successful suspends:%ld failed suspends:%ld\n"
2213bd8bdc6cSLazar Alexei "successful resumes:%ld failed resumes:%ld\n"
2214bd8bdc6cSLazar Alexei "General statistics:\n"
2215bd8bdc6cSLazar Alexei "rejected by host:%ld\n",
2216bd8bdc6cSLazar Alexei wil->suspend_stats.r_on.successful_suspends,
2217bd8bdc6cSLazar Alexei wil->suspend_stats.r_on.failed_suspends,
2218bd8bdc6cSLazar Alexei wil->suspend_stats.r_on.successful_resumes,
2219bd8bdc6cSLazar Alexei wil->suspend_stats.r_on.failed_resumes,
2220bd8bdc6cSLazar Alexei wil->suspend_stats.rejected_by_device,
2221bd8bdc6cSLazar Alexei wil->suspend_stats.r_off.successful_suspends,
2222bd8bdc6cSLazar Alexei wil->suspend_stats.r_off.failed_suspends,
2223bd8bdc6cSLazar Alexei wil->suspend_stats.r_off.successful_resumes,
2224bd8bdc6cSLazar Alexei wil->suspend_stats.r_off.failed_resumes,
2225bd8bdc6cSLazar Alexei wil->suspend_stats.rejected_by_host);
2226fe9ee51eSMaya Erez
2227bd8bdc6cSLazar Alexei n = min_t(int, n, text_size);
2228fe9ee51eSMaya Erez
2229bd8bdc6cSLazar Alexei ret = simple_read_from_buffer(user_buf, count, ppos, text, n);
2230bd8bdc6cSLazar Alexei
2231bd8bdc6cSLazar Alexei kfree(text);
2232bd8bdc6cSLazar Alexei
2233bd8bdc6cSLazar Alexei return ret;
2234fe9ee51eSMaya Erez }
2235fe9ee51eSMaya Erez
2236fe9ee51eSMaya Erez static const struct file_operations fops_suspend_stats = {
2237fe9ee51eSMaya Erez .read = wil_read_suspend_stats,
2238fe9ee51eSMaya Erez .write = wil_write_suspend_stats,
2239fe9ee51eSMaya Erez .open = simple_open,
2240fe9ee51eSMaya Erez };
2241fe9ee51eSMaya Erez
224296c93589SGidon Studinski /*---------compressed_rx_status---------*/
wil_compressed_rx_status_write(struct file * file,const char __user * buf,size_t len,loff_t * ppos)224396c93589SGidon Studinski static ssize_t wil_compressed_rx_status_write(struct file *file,
224496c93589SGidon Studinski const char __user *buf,
224596c93589SGidon Studinski size_t len, loff_t *ppos)
224696c93589SGidon Studinski {
224796c93589SGidon Studinski struct seq_file *s = file->private_data;
224896c93589SGidon Studinski struct wil6210_priv *wil = s->private;
224996c93589SGidon Studinski int compressed_rx_status;
225096c93589SGidon Studinski int rc;
225196c93589SGidon Studinski
225296c93589SGidon Studinski rc = kstrtoint_from_user(buf, len, 0, &compressed_rx_status);
225396c93589SGidon Studinski if (rc) {
225496c93589SGidon Studinski wil_err(wil, "Invalid argument\n");
225596c93589SGidon Studinski return rc;
225696c93589SGidon Studinski }
225796c93589SGidon Studinski
225896c93589SGidon Studinski if (wil_has_active_ifaces(wil, true, false)) {
225996c93589SGidon Studinski wil_err(wil, "cannot change edma config after iface is up\n");
226096c93589SGidon Studinski return -EPERM;
226196c93589SGidon Studinski }
226296c93589SGidon Studinski
226396c93589SGidon Studinski wil_info(wil, "%sable compressed_rx_status\n",
226496c93589SGidon Studinski compressed_rx_status ? "En" : "Dis");
226596c93589SGidon Studinski
226696c93589SGidon Studinski wil->use_compressed_rx_status = compressed_rx_status;
226796c93589SGidon Studinski
226896c93589SGidon Studinski return len;
226996c93589SGidon Studinski }
227096c93589SGidon Studinski
227196c93589SGidon Studinski static int
wil_compressed_rx_status_show(struct seq_file * s,void * data)227296c93589SGidon Studinski wil_compressed_rx_status_show(struct seq_file *s, void *data)
227396c93589SGidon Studinski {
227496c93589SGidon Studinski struct wil6210_priv *wil = s->private;
227596c93589SGidon Studinski
227696c93589SGidon Studinski seq_printf(s, "%d\n", wil->use_compressed_rx_status);
227796c93589SGidon Studinski
227896c93589SGidon Studinski return 0;
227996c93589SGidon Studinski }
228096c93589SGidon Studinski
228196c93589SGidon Studinski static int
wil_compressed_rx_status_seq_open(struct inode * inode,struct file * file)228296c93589SGidon Studinski wil_compressed_rx_status_seq_open(struct inode *inode, struct file *file)
228396c93589SGidon Studinski {
228496c93589SGidon Studinski return single_open(file, wil_compressed_rx_status_show,
228596c93589SGidon Studinski inode->i_private);
228696c93589SGidon Studinski }
228796c93589SGidon Studinski
228896c93589SGidon Studinski static const struct file_operations fops_compressed_rx_status = {
228996c93589SGidon Studinski .open = wil_compressed_rx_status_seq_open,
229096c93589SGidon Studinski .release = single_release,
229196c93589SGidon Studinski .read = seq_read,
229296c93589SGidon Studinski .write = wil_compressed_rx_status_write,
229396c93589SGidon Studinski .llseek = seq_lseek,
229496c93589SGidon Studinski };
229596c93589SGidon Studinski
22962be7d22fSVladimir Kondratiev /*----------------*/
wil6210_debugfs_init_blobs(struct wil6210_priv * wil,struct dentry * dbg)2297b541d0a0SVladimir Kondratiev static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
2298b541d0a0SVladimir Kondratiev struct dentry *dbg)
2299b541d0a0SVladimir Kondratiev {
2300b541d0a0SVladimir Kondratiev int i;
2301b541d0a0SVladimir Kondratiev char name[32];
2302b541d0a0SVladimir Kondratiev
2303b541d0a0SVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
2304349214c1SMaya Erez struct wil_blob_wrapper *wil_blob = &wil->blobs[i];
2305349214c1SMaya Erez struct debugfs_blob_wrapper *blob = &wil_blob->blob;
2306b541d0a0SVladimir Kondratiev const struct fw_map *map = &fw_mapping[i];
2307b541d0a0SVladimir Kondratiev
2308b541d0a0SVladimir Kondratiev if (!map->name)
2309b541d0a0SVladimir Kondratiev continue;
2310b541d0a0SVladimir Kondratiev
2311349214c1SMaya Erez wil_blob->wil = wil;
2312b541d0a0SVladimir Kondratiev blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
2313b541d0a0SVladimir Kondratiev blob->size = map->to - map->from;
2314b541d0a0SVladimir Kondratiev snprintf(name, sizeof(name), "blob_%s", map->name);
231578484c44SMaya Erez wil_debugfs_create_ioblob(name, 0444, dbg, wil_blob);
2316b541d0a0SVladimir Kondratiev }
2317b541d0a0SVladimir Kondratiev }
2318b541d0a0SVladimir Kondratiev
2319b7cde470SVladimir Kondratiev /* misc files */
2320b7cde470SVladimir Kondratiev static const struct {
2321b7cde470SVladimir Kondratiev const char *name;
2322b7cde470SVladimir Kondratiev umode_t mode;
2323b7cde470SVladimir Kondratiev const struct file_operations *fops;
2324b7cde470SVladimir Kondratiev } dbg_files[] = {
2325986b8348SYangtao Li {"mbox", 0444, &mbox_fops},
2326986b8348SYangtao Li {"rings", 0444, &ring_fops},
2327986b8348SYangtao Li {"stations", 0444, &sta_fops},
2328986b8348SYangtao Li {"mids", 0444, &mids_fops},
2329986b8348SYangtao Li {"desc", 0444, &txdesc_fops},
2330986b8348SYangtao Li {"bf", 0444, &bf_fops},
2331986b8348SYangtao Li {"mem_val", 0644, &memread_fops},
233278484c44SMaya Erez {"rxon", 0244, &fops_rxon},
233378484c44SMaya Erez {"tx_mgmt", 0244, &fops_txmgmt},
233478484c44SMaya Erez {"wmi_send", 0244, &fops_wmi},
233578484c44SMaya Erez {"back", 0644, &fops_back},
233678484c44SMaya Erez {"pmccfg", 0644, &fops_pmccfg},
233778484c44SMaya Erez {"pmcdata", 0444, &fops_pmcdata},
2338977c45abSDedy Lansky {"pmcring", 0444, &fops_pmcring},
2339986b8348SYangtao Li {"temp", 0444, &temp_fops},
2340986b8348SYangtao Li {"link", 0444, &link_fops},
2341986b8348SYangtao Li {"info", 0444, &info_fops},
234278484c44SMaya Erez {"recovery", 0644, &fops_recovery},
234378484c44SMaya Erez {"led_cfg", 0644, &fops_led_cfg},
234478484c44SMaya Erez {"led_blink_time", 0644, &fops_led_blink_time},
2345*e5398f92SLiu Shixin {"fw_capabilities", 0444, &fw_capabilities_fops},
2346*e5398f92SLiu Shixin {"fw_version", 0444, &fw_version_fops},
2347fe9ee51eSMaya Erez {"suspend_stats", 0644, &fops_suspend_stats},
234896c93589SGidon Studinski {"compressed_rx_status", 0644, &fops_compressed_rx_status},
2349986b8348SYangtao Li {"srings", 0444, &srings_fops},
2350986b8348SYangtao Li {"status_msg", 0444, &status_msg_fops},
2351986b8348SYangtao Li {"rx_buff_mgmt", 0444, &rx_buff_mgmt_fops},
2352a24a3d6aSDedy Lansky {"tx_latency", 0644, &fops_tx_latency},
23530c936b3cSDedy Lansky {"link_stats", 0644, &fops_link_stats},
23540c936b3cSDedy Lansky {"link_stats_global", 0644, &fops_link_stats_global},
2355c5b3a658SAlexei Avshalom Lazar {"rbufcap", 0244, &fops_rbufcap},
2356b7cde470SVladimir Kondratiev };
2357b7cde470SVladimir Kondratiev
wil6210_debugfs_init_files(struct wil6210_priv * wil,struct dentry * dbg)2358b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
2359b7cde470SVladimir Kondratiev struct dentry *dbg)
2360b7cde470SVladimir Kondratiev {
2361b7cde470SVladimir Kondratiev int i;
2362b7cde470SVladimir Kondratiev
2363b7cde470SVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
2364b7cde470SVladimir Kondratiev debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
2365b7cde470SVladimir Kondratiev wil, dbg_files[i].fops);
2366b7cde470SVladimir Kondratiev }
2367b7cde470SVladimir Kondratiev
2368b7cde470SVladimir Kondratiev /* interrupt control blocks */
2369b7cde470SVladimir Kondratiev static const struct {
2370b7cde470SVladimir Kondratiev const char *name;
2371b7cde470SVladimir Kondratiev u32 icr_off;
2372b7cde470SVladimir Kondratiev } dbg_icr[] = {
2373b7cde470SVladimir Kondratiev {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)},
2374b7cde470SVladimir Kondratiev {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)},
2375b7cde470SVladimir Kondratiev {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)},
2376b7cde470SVladimir Kondratiev {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)},
2377b7cde470SVladimir Kondratiev };
2378b7cde470SVladimir Kondratiev
wil6210_debugfs_init_isr(struct wil6210_priv * wil,struct dentry * dbg)2379b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
2380b7cde470SVladimir Kondratiev struct dentry *dbg)
2381b7cde470SVladimir Kondratiev {
2382b7cde470SVladimir Kondratiev int i;
2383b7cde470SVladimir Kondratiev
2384b7cde470SVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
2385b7cde470SVladimir Kondratiev wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
2386b7cde470SVladimir Kondratiev dbg_icr[i].icr_off);
2387b7cde470SVladimir Kondratiev }
2388b7cde470SVladimir Kondratiev
2389b7cde470SVladimir Kondratiev #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
2390b7cde470SVladimir Kondratiev offsetof(struct wil6210_priv, name), type}
2391b7cde470SVladimir Kondratiev
2392b7cde470SVladimir Kondratiev /* fields in struct wil6210_priv */
2393b7cde470SVladimir Kondratiev static const struct dbg_off dbg_wil_off[] = {
239478484c44SMaya Erez WIL_FIELD(status[0], 0644, doff_ulong),
239578484c44SMaya Erez WIL_FIELD(hw_version, 0444, doff_x32),
239678484c44SMaya Erez WIL_FIELD(recovery_count, 0444, doff_u32),
239778484c44SMaya Erez WIL_FIELD(discovery_mode, 0644, doff_u8),
239878484c44SMaya Erez WIL_FIELD(chip_revision, 0444, doff_u8),
239978484c44SMaya Erez WIL_FIELD(abft_len, 0644, doff_u8),
2400fe9ee51eSMaya Erez WIL_FIELD(wakeup_trigger, 0644, doff_u8),
240110590c6aSGidon Studinski WIL_FIELD(ring_idle_trsh, 0644, doff_u32),
240296c93589SGidon Studinski WIL_FIELD(num_rx_status_rings, 0644, doff_u8),
240396c93589SGidon Studinski WIL_FIELD(rx_status_ring_order, 0644, doff_u32),
240496c93589SGidon Studinski WIL_FIELD(tx_status_ring_order, 0644, doff_u32),
240596c93589SGidon Studinski WIL_FIELD(rx_buff_id_count, 0644, doff_u32),
24067be13fc3SGidon Studinski WIL_FIELD(amsdu_en, 0644, doff_u8),
2407b7cde470SVladimir Kondratiev {},
2408b7cde470SVladimir Kondratiev };
2409b7cde470SVladimir Kondratiev
2410b7cde470SVladimir Kondratiev static const struct dbg_off dbg_wil_regs[] = {
241178484c44SMaya Erez {"RGF_MAC_MTRL_COUNTER_0", 0444, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
2412b7cde470SVladimir Kondratiev doff_io32},
241378484c44SMaya Erez {"RGF_USER_USAGE_1", 0444, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
24148454e72aSAhmad Masri {"RGF_USER_USAGE_2", 0444, HOSTADDR(RGF_USER_USAGE_2), doff_io32},
2415b7cde470SVladimir Kondratiev {},
2416b7cde470SVladimir Kondratiev };
2417b7cde470SVladimir Kondratiev
2418b7cde470SVladimir Kondratiev /* static parameters */
2419b7cde470SVladimir Kondratiev static const struct dbg_off dbg_statics[] = {
242078484c44SMaya Erez {"desc_index", 0644, (ulong)&dbg_txdesc_index, doff_u32},
242110590c6aSGidon Studinski {"ring_index", 0644, (ulong)&dbg_ring_index, doff_u32},
242278484c44SMaya Erez {"mem_addr", 0644, (ulong)&mem_addr, doff_u32},
242378484c44SMaya Erez {"led_polarity", 0644, (ulong)&led_polarity, doff_u8},
2424d98b8539SMaya Erez {"status_index", 0644, (ulong)&dbg_status_msg_index, doff_u32},
2425d98b8539SMaya Erez {"sring_index", 0644, (ulong)&dbg_sring_index, doff_u32},
24260439a5e0SDedy Lansky {"drop_if_ring_full", 0644, (ulong)&drop_if_ring_full, doff_u8},
2427b7cde470SVladimir Kondratiev {},
2428b7cde470SVladimir Kondratiev };
2429b7cde470SVladimir Kondratiev
243094162666SLazar Alexei static const int dbg_off_count = 4 * (ARRAY_SIZE(isr_off) - 1) +
243194162666SLazar Alexei ARRAY_SIZE(dbg_wil_regs) - 1 +
243294162666SLazar Alexei ARRAY_SIZE(pseudo_isr_off) - 1 +
243394162666SLazar Alexei ARRAY_SIZE(lgc_itr_cnt_off) - 1 +
243494162666SLazar Alexei ARRAY_SIZE(tx_itr_cnt_off) - 1 +
243594162666SLazar Alexei ARRAY_SIZE(rx_itr_cnt_off) - 1;
243694162666SLazar Alexei
wil6210_debugfs_init(struct wil6210_priv * wil)24372be7d22fSVladimir Kondratiev int wil6210_debugfs_init(struct wil6210_priv *wil)
24382be7d22fSVladimir Kondratiev {
24392be7d22fSVladimir Kondratiev struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
24402be7d22fSVladimir Kondratiev wil_to_wiphy(wil)->debugfsdir);
24412be7d22fSVladimir Kondratiev if (IS_ERR_OR_NULL(dbg))
24422be7d22fSVladimir Kondratiev return -ENODEV;
24432be7d22fSVladimir Kondratiev
244494162666SLazar Alexei wil->dbg_data.data_arr = kcalloc(dbg_off_count,
244594162666SLazar Alexei sizeof(struct wil_debugfs_iomem_data),
244694162666SLazar Alexei GFP_KERNEL);
244794162666SLazar Alexei if (!wil->dbg_data.data_arr) {
244894162666SLazar Alexei debugfs_remove_recursive(dbg);
244994162666SLazar Alexei wil->debug = NULL;
245094162666SLazar Alexei return -ENOMEM;
245194162666SLazar Alexei }
245294162666SLazar Alexei
245394162666SLazar Alexei wil->dbg_data.iomem_data_count = 0;
245494162666SLazar Alexei
2455dc16427bSVladimir Kondratiev wil_pmc_init(wil);
2456dc16427bSVladimir Kondratiev
2457b7cde470SVladimir Kondratiev wil6210_debugfs_init_files(wil, dbg);
2458b7cde470SVladimir Kondratiev wil6210_debugfs_init_isr(wil, dbg);
2459b541d0a0SVladimir Kondratiev wil6210_debugfs_init_blobs(wil, dbg);
2460b7cde470SVladimir Kondratiev wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
2461b7cde470SVladimir Kondratiev wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
2462b7cde470SVladimir Kondratiev dbg_wil_regs);
2463b7cde470SVladimir Kondratiev wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
2464b7cde470SVladimir Kondratiev
2465b7cde470SVladimir Kondratiev wil6210_debugfs_create_pseudo_ISR(wil, dbg);
2466b7cde470SVladimir Kondratiev
2467b7cde470SVladimir Kondratiev wil6210_debugfs_create_ITR_CNT(wil, dbg);
24682be7d22fSVladimir Kondratiev
24692be7d22fSVladimir Kondratiev return 0;
24702be7d22fSVladimir Kondratiev }
24712be7d22fSVladimir Kondratiev
wil6210_debugfs_remove(struct wil6210_priv * wil)24722be7d22fSVladimir Kondratiev void wil6210_debugfs_remove(struct wil6210_priv *wil)
24732be7d22fSVladimir Kondratiev {
2474a24a3d6aSDedy Lansky int i;
2475a24a3d6aSDedy Lansky
24762be7d22fSVladimir Kondratiev debugfs_remove_recursive(wil->debug);
24772be7d22fSVladimir Kondratiev wil->debug = NULL;
2478dc16427bSVladimir Kondratiev
247994162666SLazar Alexei kfree(wil->dbg_data.data_arr);
2480ddf7afddSAhmad Masri for (i = 0; i < wil->max_assoc_sta; i++)
2481a24a3d6aSDedy Lansky kfree(wil->sta[i].tx_latency_bins);
248294162666SLazar Alexei
2483dc16427bSVladimir Kondratiev /* free pmc memory without sending command to fw, as it will
2484dc16427bSVladimir Kondratiev * be reset on the way down anyway
2485dc16427bSVladimir Kondratiev */
2486dc16427bSVladimir Kondratiev wil_pmc_free(wil, false);
24872be7d22fSVladimir Kondratiev }
2488