12be7d22fSVladimir Kondratiev /* 2a351f2f5SLazar Alexei * Copyright (c) 2012-2017 Qualcomm Atheros, Inc. 32be7d22fSVladimir Kondratiev * 42be7d22fSVladimir Kondratiev * Permission to use, copy, modify, and/or distribute this software for any 52be7d22fSVladimir Kondratiev * purpose with or without fee is hereby granted, provided that the above 62be7d22fSVladimir Kondratiev * copyright notice and this permission notice appear in all copies. 72be7d22fSVladimir Kondratiev * 82be7d22fSVladimir Kondratiev * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 92be7d22fSVladimir Kondratiev * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 102be7d22fSVladimir Kondratiev * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 112be7d22fSVladimir Kondratiev * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 122be7d22fSVladimir Kondratiev * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 132be7d22fSVladimir Kondratiev * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 142be7d22fSVladimir Kondratiev * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 152be7d22fSVladimir Kondratiev */ 162be7d22fSVladimir Kondratiev 172be7d22fSVladimir Kondratiev #include <linux/module.h> 182be7d22fSVladimir Kondratiev #include <linux/debugfs.h> 192be7d22fSVladimir Kondratiev #include <linux/seq_file.h> 202be7d22fSVladimir Kondratiev #include <linux/pci.h> 212be7d22fSVladimir Kondratiev #include <linux/rtnetlink.h> 2284bb29b7SVladimir Kondratiev #include <linux/power_supply.h> 232be7d22fSVladimir Kondratiev 242be7d22fSVladimir Kondratiev #include "wil6210.h" 2536345ac3SVladimir Kondratiev #include "wmi.h" 262be7d22fSVladimir Kondratiev #include "txrx.h" 27dc16427bSVladimir Kondratiev #include "pmc.h" 282be7d22fSVladimir Kondratiev 292be7d22fSVladimir Kondratiev /* Nasty hack. Better have per device instances */ 302be7d22fSVladimir Kondratiev static u32 mem_addr; 312be7d22fSVladimir Kondratiev static u32 dbg_txdesc_index; 32af31cb5aSVladimir Kondratiev static u32 dbg_vring_index; /* 24+ for Rx, 0..23 for Tx */ 330436fd9aSVladimir Shulman u32 vring_idle_trsh = 16; /* HW fetches up to 16 descriptors at once */ 342be7d22fSVladimir Kondratiev 35b7cde470SVladimir Kondratiev enum dbg_off_type { 36b7cde470SVladimir Kondratiev doff_u32 = 0, 37b7cde470SVladimir Kondratiev doff_x32 = 1, 38b7cde470SVladimir Kondratiev doff_ulong = 2, 39b7cde470SVladimir Kondratiev doff_io32 = 3, 4074997a53SLior David doff_u8 = 4 41b7cde470SVladimir Kondratiev }; 42b7cde470SVladimir Kondratiev 43b7cde470SVladimir Kondratiev /* offset to "wil" */ 44b7cde470SVladimir Kondratiev struct dbg_off { 45b7cde470SVladimir Kondratiev const char *name; 46b7cde470SVladimir Kondratiev umode_t mode; 47b7cde470SVladimir Kondratiev ulong off; 48b7cde470SVladimir Kondratiev enum dbg_off_type type; 49b7cde470SVladimir Kondratiev }; 50b7cde470SVladimir Kondratiev 512be7d22fSVladimir Kondratiev static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil, 5259f7c0a9SVladimir Kondratiev const char *name, struct vring *vring, 5359f7c0a9SVladimir Kondratiev char _s, char _h) 542be7d22fSVladimir Kondratiev { 552be7d22fSVladimir Kondratiev void __iomem *x = wmi_addr(wil, vring->hwtail); 56995cdd0eSVladimir Kondratiev u32 v; 572be7d22fSVladimir Kondratiev 582be7d22fSVladimir Kondratiev seq_printf(s, "VRING %s = {\n", name); 5939c52ee8SVladimir Kondratiev seq_printf(s, " pa = %pad\n", &vring->pa); 602be7d22fSVladimir Kondratiev seq_printf(s, " va = 0x%p\n", vring->va); 612be7d22fSVladimir Kondratiev seq_printf(s, " size = %d\n", vring->size); 622be7d22fSVladimir Kondratiev seq_printf(s, " swtail = %d\n", vring->swtail); 632be7d22fSVladimir Kondratiev seq_printf(s, " swhead = %d\n", vring->swhead); 642be7d22fSVladimir Kondratiev seq_printf(s, " hwtail = [0x%08x] -> ", vring->hwtail); 65995cdd0eSVladimir Kondratiev if (x) { 66b9eeb512SVladimir Kondratiev v = readl(x); 67995cdd0eSVladimir Kondratiev seq_printf(s, "0x%08x = %d\n", v, v); 68995cdd0eSVladimir Kondratiev } else { 698fe59627SVladimir Kondratiev seq_puts(s, "???\n"); 70995cdd0eSVladimir Kondratiev } 712be7d22fSVladimir Kondratiev 72ee5dfe0dSHamad Kadmany if (vring->va && (vring->size <= (1 << WIL_RING_SIZE_ORDER_MAX))) { 732be7d22fSVladimir Kondratiev uint i; 748fe59627SVladimir Kondratiev 752be7d22fSVladimir Kondratiev for (i = 0; i < vring->size; i++) { 762be7d22fSVladimir Kondratiev volatile struct vring_tx_desc *d = &vring->va[i].tx; 778fe59627SVladimir Kondratiev 78ee5dfe0dSHamad Kadmany if ((i % 128) == 0 && (i != 0)) 798fe59627SVladimir Kondratiev seq_puts(s, "\n"); 8059f7c0a9SVladimir Kondratiev seq_printf(s, "%c", (d->dma.status & BIT(0)) ? 8159f7c0a9SVladimir Kondratiev _s : (vring->ctx[i].skb ? _h : 'h')); 822be7d22fSVladimir Kondratiev } 838fe59627SVladimir Kondratiev seq_puts(s, "\n"); 842be7d22fSVladimir Kondratiev } 858fe59627SVladimir Kondratiev seq_puts(s, "}\n"); 862be7d22fSVladimir Kondratiev } 872be7d22fSVladimir Kondratiev 882be7d22fSVladimir Kondratiev static int wil_vring_debugfs_show(struct seq_file *s, void *data) 892be7d22fSVladimir Kondratiev { 902be7d22fSVladimir Kondratiev uint i; 912be7d22fSVladimir Kondratiev struct wil6210_priv *wil = s->private; 922be7d22fSVladimir Kondratiev 9359f7c0a9SVladimir Kondratiev wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_'); 942be7d22fSVladimir Kondratiev 952be7d22fSVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) { 968fe59627SVladimir Kondratiev struct vring *vring = &wil->vring_tx[i]; 977c0acf86SVladimir Kondratiev struct vring_tx_data *txdata = &wil->vring_tx_data[i]; 987c0acf86SVladimir Kondratiev 992be7d22fSVladimir Kondratiev if (vring->va) { 1003df2cd36SVladimir Kondratiev int cid = wil->vring2cid_tid[i][0]; 1013df2cd36SVladimir Kondratiev int tid = wil->vring2cid_tid[i][1]; 10267c3e1b4SVladimir Kondratiev u32 swhead = vring->swhead; 10367c3e1b4SVladimir Kondratiev u32 swtail = vring->swtail; 10467c3e1b4SVladimir Kondratiev int used = (vring->size + swhead - swtail) 10567c3e1b4SVladimir Kondratiev % vring->size; 10667c3e1b4SVladimir Kondratiev int avail = vring->size - used - 1; 1072be7d22fSVladimir Kondratiev char name[10]; 1088f55cbecSBoris Sorochkin char sidle[10]; 1097c0acf86SVladimir Kondratiev /* performance monitoring */ 1107c0acf86SVladimir Kondratiev cycles_t now = get_cycles(); 111c20e7789SChen Gang uint64_t idle = txdata->idle * 100; 112c20e7789SChen Gang uint64_t total = now - txdata->begin; 1137c0acf86SVladimir Kondratiev 1148f55cbecSBoris Sorochkin if (total != 0) { 115e48b1790SVladimir Kondratiev do_div(idle, total); 1168f55cbecSBoris Sorochkin snprintf(sidle, sizeof(sidle), "%3d%%", 1178f55cbecSBoris Sorochkin (int)idle); 1188f55cbecSBoris Sorochkin } else { 1198f55cbecSBoris Sorochkin snprintf(sidle, sizeof(sidle), "N/A"); 1208f55cbecSBoris Sorochkin } 1217c0acf86SVladimir Kondratiev txdata->begin = now; 1227c0acf86SVladimir Kondratiev txdata->idle = 0ULL; 1237c0acf86SVladimir Kondratiev 1242be7d22fSVladimir Kondratiev snprintf(name, sizeof(name), "tx_%2d", i); 1253df2cd36SVladimir Kondratiev 12641d6b093SVladimir Kondratiev if (cid < WIL6210_MAX_CID) 1273277213fSVladimir Kondratiev seq_printf(s, 128230d8442SVladimir Kondratiev "\n%pM CID %d TID %d 1x%s BACK([%u] %u TU A%s) [%3d|%3d] idle %s\n", 1293277213fSVladimir Kondratiev wil->sta[cid].addr, cid, tid, 130230d8442SVladimir Kondratiev txdata->dot1x_open ? "+" : "-", 13141d6b093SVladimir Kondratiev txdata->agg_wsize, 13241d6b093SVladimir Kondratiev txdata->agg_timeout, 133cbcf5866SVladimir Kondratiev txdata->agg_amsdu ? "+" : "-", 1348f55cbecSBoris Sorochkin used, avail, sidle); 13541d6b093SVladimir Kondratiev else 13641d6b093SVladimir Kondratiev seq_printf(s, 137230d8442SVladimir Kondratiev "\nBroadcast 1x%s [%3d|%3d] idle %s\n", 138230d8442SVladimir Kondratiev txdata->dot1x_open ? "+" : "-", 13941d6b093SVladimir Kondratiev used, avail, sidle); 1407c0acf86SVladimir Kondratiev 14159f7c0a9SVladimir Kondratiev wil_print_vring(s, wil, name, vring, '_', 'H'); 1422be7d22fSVladimir Kondratiev } 1432be7d22fSVladimir Kondratiev } 1442be7d22fSVladimir Kondratiev 1452be7d22fSVladimir Kondratiev return 0; 1462be7d22fSVladimir Kondratiev } 1472be7d22fSVladimir Kondratiev 1482be7d22fSVladimir Kondratiev static int wil_vring_seq_open(struct inode *inode, struct file *file) 1492be7d22fSVladimir Kondratiev { 1502be7d22fSVladimir Kondratiev return single_open(file, wil_vring_debugfs_show, inode->i_private); 1512be7d22fSVladimir Kondratiev } 1522be7d22fSVladimir Kondratiev 1532be7d22fSVladimir Kondratiev static const struct file_operations fops_vring = { 1542be7d22fSVladimir Kondratiev .open = wil_vring_seq_open, 1552be7d22fSVladimir Kondratiev .release = single_release, 1562be7d22fSVladimir Kondratiev .read = seq_read, 1572be7d22fSVladimir Kondratiev .llseek = seq_lseek, 1582be7d22fSVladimir Kondratiev }; 1592be7d22fSVladimir Kondratiev 160a202fbbfSAndy Shevchenko static void wil_seq_hexdump(struct seq_file *s, void *p, int len, 161a202fbbfSAndy Shevchenko const char *prefix) 162a202fbbfSAndy Shevchenko { 163a202fbbfSAndy Shevchenko seq_hex_dump(s, prefix, DUMP_PREFIX_NONE, 16, 1, p, len, false); 164a202fbbfSAndy Shevchenko } 165a202fbbfSAndy Shevchenko 1662be7d22fSVladimir Kondratiev static void wil_print_ring(struct seq_file *s, const char *prefix, 1672be7d22fSVladimir Kondratiev void __iomem *off) 1682be7d22fSVladimir Kondratiev { 1692be7d22fSVladimir Kondratiev struct wil6210_priv *wil = s->private; 1702be7d22fSVladimir Kondratiev struct wil6210_mbox_ring r; 1712be7d22fSVladimir Kondratiev int rsize; 1722be7d22fSVladimir Kondratiev uint i; 1732be7d22fSVladimir Kondratiev 174349214c1SMaya Erez wil_halp_vote(wil); 175349214c1SMaya Erez 1762be7d22fSVladimir Kondratiev wil_memcpy_fromio_32(&r, off, sizeof(r)); 1772be7d22fSVladimir Kondratiev wil_mbox_ring_le2cpus(&r); 1782be7d22fSVladimir Kondratiev /* 1792be7d22fSVladimir Kondratiev * we just read memory block from NIC. This memory may be 1802be7d22fSVladimir Kondratiev * garbage. Check validity before using it. 1812be7d22fSVladimir Kondratiev */ 1822be7d22fSVladimir Kondratiev rsize = r.size / sizeof(struct wil6210_mbox_ring_desc); 1832be7d22fSVladimir Kondratiev 1842be7d22fSVladimir Kondratiev seq_printf(s, "ring %s = {\n", prefix); 1852be7d22fSVladimir Kondratiev seq_printf(s, " base = 0x%08x\n", r.base); 1862be7d22fSVladimir Kondratiev seq_printf(s, " size = 0x%04x bytes -> %d entries\n", r.size, rsize); 1872be7d22fSVladimir Kondratiev seq_printf(s, " tail = 0x%08x\n", r.tail); 1882be7d22fSVladimir Kondratiev seq_printf(s, " head = 0x%08x\n", r.head); 1892be7d22fSVladimir Kondratiev seq_printf(s, " entry size = %d\n", r.entry_size); 1902be7d22fSVladimir Kondratiev 1912be7d22fSVladimir Kondratiev if (r.size % sizeof(struct wil6210_mbox_ring_desc)) { 1922be7d22fSVladimir Kondratiev seq_printf(s, " ??? size is not multiple of %zd, garbage?\n", 1932be7d22fSVladimir Kondratiev sizeof(struct wil6210_mbox_ring_desc)); 1942be7d22fSVladimir Kondratiev goto out; 1952be7d22fSVladimir Kondratiev } 1962be7d22fSVladimir Kondratiev 1972be7d22fSVladimir Kondratiev if (!wmi_addr(wil, r.base) || 1982be7d22fSVladimir Kondratiev !wmi_addr(wil, r.tail) || 1992be7d22fSVladimir Kondratiev !wmi_addr(wil, r.head)) { 2008fe59627SVladimir Kondratiev seq_puts(s, " ??? pointers are garbage?\n"); 2012be7d22fSVladimir Kondratiev goto out; 2022be7d22fSVladimir Kondratiev } 2032be7d22fSVladimir Kondratiev 2042be7d22fSVladimir Kondratiev for (i = 0; i < rsize; i++) { 2052be7d22fSVladimir Kondratiev struct wil6210_mbox_ring_desc d; 2062be7d22fSVladimir Kondratiev struct wil6210_mbox_hdr hdr; 2072be7d22fSVladimir Kondratiev size_t delta = i * sizeof(d); 2082be7d22fSVladimir Kondratiev void __iomem *x = wil->csr + HOSTADDR(r.base) + delta; 2092be7d22fSVladimir Kondratiev 2102be7d22fSVladimir Kondratiev wil_memcpy_fromio_32(&d, x, sizeof(d)); 2112be7d22fSVladimir Kondratiev 2122be7d22fSVladimir Kondratiev seq_printf(s, " [%2x] %s %s%s 0x%08x", i, 2132be7d22fSVladimir Kondratiev d.sync ? "F" : "E", 2142be7d22fSVladimir Kondratiev (r.tail - r.base == delta) ? "t" : " ", 2152be7d22fSVladimir Kondratiev (r.head - r.base == delta) ? "h" : " ", 2162be7d22fSVladimir Kondratiev le32_to_cpu(d.addr)); 2172be7d22fSVladimir Kondratiev if (0 == wmi_read_hdr(wil, d.addr, &hdr)) { 2182be7d22fSVladimir Kondratiev u16 len = le16_to_cpu(hdr.len); 2198fe59627SVladimir Kondratiev 2202be7d22fSVladimir Kondratiev seq_printf(s, " -> %04x %04x %04x %02x\n", 2212be7d22fSVladimir Kondratiev le16_to_cpu(hdr.seq), len, 2222be7d22fSVladimir Kondratiev le16_to_cpu(hdr.type), hdr.flags); 2232be7d22fSVladimir Kondratiev if (len <= MAX_MBOXITEM_SIZE) { 2242be7d22fSVladimir Kondratiev unsigned char databuf[MAX_MBOXITEM_SIZE]; 2252be7d22fSVladimir Kondratiev void __iomem *src = wmi_buffer(wil, d.addr) + 2262be7d22fSVladimir Kondratiev sizeof(struct wil6210_mbox_hdr); 2272be7d22fSVladimir Kondratiev /* 2282be7d22fSVladimir Kondratiev * No need to check @src for validity - 2292be7d22fSVladimir Kondratiev * we already validated @d.addr while 2302be7d22fSVladimir Kondratiev * reading header 2312be7d22fSVladimir Kondratiev */ 2322be7d22fSVladimir Kondratiev wil_memcpy_fromio_32(databuf, src, len); 233a202fbbfSAndy Shevchenko wil_seq_hexdump(s, databuf, len, " : "); 2342be7d22fSVladimir Kondratiev } 2352be7d22fSVladimir Kondratiev } else { 2368fe59627SVladimir Kondratiev seq_puts(s, "\n"); 2372be7d22fSVladimir Kondratiev } 2382be7d22fSVladimir Kondratiev } 2392be7d22fSVladimir Kondratiev out: 2408fe59627SVladimir Kondratiev seq_puts(s, "}\n"); 241349214c1SMaya Erez wil_halp_unvote(wil); 2422be7d22fSVladimir Kondratiev } 2432be7d22fSVladimir Kondratiev 2442be7d22fSVladimir Kondratiev static int wil_mbox_debugfs_show(struct seq_file *s, void *data) 2452be7d22fSVladimir Kondratiev { 2462be7d22fSVladimir Kondratiev struct wil6210_priv *wil = s->private; 2472be7d22fSVladimir Kondratiev 2482be7d22fSVladimir Kondratiev wil_print_ring(s, "tx", wil->csr + HOST_MBOX + 2492be7d22fSVladimir Kondratiev offsetof(struct wil6210_mbox_ctl, tx)); 2502be7d22fSVladimir Kondratiev wil_print_ring(s, "rx", wil->csr + HOST_MBOX + 2512be7d22fSVladimir Kondratiev offsetof(struct wil6210_mbox_ctl, rx)); 2522be7d22fSVladimir Kondratiev 2532be7d22fSVladimir Kondratiev return 0; 2542be7d22fSVladimir Kondratiev } 2552be7d22fSVladimir Kondratiev 2562be7d22fSVladimir Kondratiev static int wil_mbox_seq_open(struct inode *inode, struct file *file) 2572be7d22fSVladimir Kondratiev { 2582be7d22fSVladimir Kondratiev return single_open(file, wil_mbox_debugfs_show, inode->i_private); 2592be7d22fSVladimir Kondratiev } 2602be7d22fSVladimir Kondratiev 2612be7d22fSVladimir Kondratiev static const struct file_operations fops_mbox = { 2622be7d22fSVladimir Kondratiev .open = wil_mbox_seq_open, 2632be7d22fSVladimir Kondratiev .release = single_release, 2642be7d22fSVladimir Kondratiev .read = seq_read, 2652be7d22fSVladimir Kondratiev .llseek = seq_lseek, 2662be7d22fSVladimir Kondratiev }; 2672be7d22fSVladimir Kondratiev 2682be7d22fSVladimir Kondratiev static int wil_debugfs_iomem_x32_set(void *data, u64 val) 2692be7d22fSVladimir Kondratiev { 270b9eeb512SVladimir Kondratiev writel(val, (void __iomem *)data); 2712be7d22fSVladimir Kondratiev wmb(); /* make sure write propagated to HW */ 2722be7d22fSVladimir Kondratiev 2732be7d22fSVladimir Kondratiev return 0; 2742be7d22fSVladimir Kondratiev } 2752be7d22fSVladimir Kondratiev 2762be7d22fSVladimir Kondratiev static int wil_debugfs_iomem_x32_get(void *data, u64 *val) 2772be7d22fSVladimir Kondratiev { 278b9eeb512SVladimir Kondratiev *val = readl((void __iomem *)data); 2792be7d22fSVladimir Kondratiev 2802be7d22fSVladimir Kondratiev return 0; 2812be7d22fSVladimir Kondratiev } 2822be7d22fSVladimir Kondratiev 2832be7d22fSVladimir Kondratiev DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get, 2842be7d22fSVladimir Kondratiev wil_debugfs_iomem_x32_set, "0x%08llx\n"); 2852be7d22fSVladimir Kondratiev 2862be7d22fSVladimir Kondratiev static struct dentry *wil_debugfs_create_iomem_x32(const char *name, 2870ecc833bSAl Viro umode_t mode, 2882be7d22fSVladimir Kondratiev struct dentry *parent, 289b7cde470SVladimir Kondratiev void *value) 2902be7d22fSVladimir Kondratiev { 291b7cde470SVladimir Kondratiev return debugfs_create_file(name, mode, parent, value, 2922be7d22fSVladimir Kondratiev &fops_iomem_x32); 2932be7d22fSVladimir Kondratiev } 2942be7d22fSVladimir Kondratiev 2953de6cf20SVladimir Kondratiev static int wil_debugfs_ulong_set(void *data, u64 val) 2963de6cf20SVladimir Kondratiev { 2973de6cf20SVladimir Kondratiev *(ulong *)data = val; 2983de6cf20SVladimir Kondratiev return 0; 2993de6cf20SVladimir Kondratiev } 3008fe59627SVladimir Kondratiev 3013de6cf20SVladimir Kondratiev static int wil_debugfs_ulong_get(void *data, u64 *val) 3023de6cf20SVladimir Kondratiev { 3033de6cf20SVladimir Kondratiev *val = *(ulong *)data; 3043de6cf20SVladimir Kondratiev return 0; 3053de6cf20SVladimir Kondratiev } 3068fe59627SVladimir Kondratiev 3073de6cf20SVladimir Kondratiev DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get, 3088ea06188SVladimir Kondratiev wil_debugfs_ulong_set, "0x%llx\n"); 3093de6cf20SVladimir Kondratiev 3103de6cf20SVladimir Kondratiev static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode, 3113de6cf20SVladimir Kondratiev struct dentry *parent, 3123de6cf20SVladimir Kondratiev ulong *value) 3133de6cf20SVladimir Kondratiev { 3143de6cf20SVladimir Kondratiev return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong); 3153de6cf20SVladimir Kondratiev } 3163de6cf20SVladimir Kondratiev 317b7cde470SVladimir Kondratiev /** 318b7cde470SVladimir Kondratiev * wil6210_debugfs_init_offset - create set of debugfs files 319b7cde470SVladimir Kondratiev * @wil - driver's context, used for printing 320b7cde470SVladimir Kondratiev * @dbg - directory on the debugfs, where files will be created 321b7cde470SVladimir Kondratiev * @base - base address used in address calculation 322b7cde470SVladimir Kondratiev * @tbl - table with file descriptions. Should be terminated with empty element. 323b7cde470SVladimir Kondratiev * 324b7cde470SVladimir Kondratiev * Creates files accordingly to the @tbl. 325b7cde470SVladimir Kondratiev */ 326b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_offset(struct wil6210_priv *wil, 327b7cde470SVladimir Kondratiev struct dentry *dbg, void *base, 328b7cde470SVladimir Kondratiev const struct dbg_off * const tbl) 329b7cde470SVladimir Kondratiev { 330b7cde470SVladimir Kondratiev int i; 331b7cde470SVladimir Kondratiev 332b7cde470SVladimir Kondratiev for (i = 0; tbl[i].name; i++) { 333867fa0d4SVladimir Kondratiev struct dentry *f; 334b7cde470SVladimir Kondratiev 335b7cde470SVladimir Kondratiev switch (tbl[i].type) { 336b7cde470SVladimir Kondratiev case doff_u32: 337b7cde470SVladimir Kondratiev f = debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg, 338b7cde470SVladimir Kondratiev base + tbl[i].off); 339b7cde470SVladimir Kondratiev break; 340b7cde470SVladimir Kondratiev case doff_x32: 341b7cde470SVladimir Kondratiev f = debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg, 342b7cde470SVladimir Kondratiev base + tbl[i].off); 343b7cde470SVladimir Kondratiev break; 344b7cde470SVladimir Kondratiev case doff_ulong: 345b7cde470SVladimir Kondratiev f = wil_debugfs_create_ulong(tbl[i].name, tbl[i].mode, 346b7cde470SVladimir Kondratiev dbg, base + tbl[i].off); 347b7cde470SVladimir Kondratiev break; 348b7cde470SVladimir Kondratiev case doff_io32: 349b7cde470SVladimir Kondratiev f = wil_debugfs_create_iomem_x32(tbl[i].name, 350b7cde470SVladimir Kondratiev tbl[i].mode, dbg, 351b7cde470SVladimir Kondratiev base + tbl[i].off); 352b7cde470SVladimir Kondratiev break; 35374997a53SLior David case doff_u8: 35474997a53SLior David f = debugfs_create_u8(tbl[i].name, tbl[i].mode, dbg, 35574997a53SLior David base + tbl[i].off); 35674997a53SLior David break; 357867fa0d4SVladimir Kondratiev default: 358867fa0d4SVladimir Kondratiev f = ERR_PTR(-EINVAL); 359b7cde470SVladimir Kondratiev } 360b7cde470SVladimir Kondratiev if (IS_ERR_OR_NULL(f)) 361b7cde470SVladimir Kondratiev wil_err(wil, "Create file \"%s\": err %ld\n", 362b7cde470SVladimir Kondratiev tbl[i].name, PTR_ERR(f)); 363b7cde470SVladimir Kondratiev } 364b7cde470SVladimir Kondratiev } 365b7cde470SVladimir Kondratiev 366b7cde470SVladimir Kondratiev static const struct dbg_off isr_off[] = { 367b7cde470SVladimir Kondratiev {"ICC", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICC), doff_io32}, 368b7cde470SVladimir Kondratiev {"ICR", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICR), doff_io32}, 369b7cde470SVladimir Kondratiev {"ICM", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICM), doff_io32}, 370b7cde470SVladimir Kondratiev {"ICS", S_IWUSR, offsetof(struct RGF_ICR, ICS), doff_io32}, 371b7cde470SVladimir Kondratiev {"IMV", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, IMV), doff_io32}, 372b7cde470SVladimir Kondratiev {"IMS", S_IWUSR, offsetof(struct RGF_ICR, IMS), doff_io32}, 373b7cde470SVladimir Kondratiev {"IMC", S_IWUSR, offsetof(struct RGF_ICR, IMC), doff_io32}, 374b7cde470SVladimir Kondratiev {}, 375b7cde470SVladimir Kondratiev }; 3768fe59627SVladimir Kondratiev 3772be7d22fSVladimir Kondratiev static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil, 3782be7d22fSVladimir Kondratiev const char *name, 3792be7d22fSVladimir Kondratiev struct dentry *parent, u32 off) 3802be7d22fSVladimir Kondratiev { 3812be7d22fSVladimir Kondratiev struct dentry *d = debugfs_create_dir(name, parent); 3822be7d22fSVladimir Kondratiev 3832be7d22fSVladimir Kondratiev if (IS_ERR_OR_NULL(d)) 3842be7d22fSVladimir Kondratiev return -ENODEV; 3852be7d22fSVladimir Kondratiev 386b7cde470SVladimir Kondratiev wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off, 387b7cde470SVladimir Kondratiev isr_off); 3882be7d22fSVladimir Kondratiev 3892be7d22fSVladimir Kondratiev return 0; 3902be7d22fSVladimir Kondratiev } 3912be7d22fSVladimir Kondratiev 392b7cde470SVladimir Kondratiev static const struct dbg_off pseudo_isr_off[] = { 393b7cde470SVladimir Kondratiev {"CAUSE", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32}, 394b7cde470SVladimir Kondratiev {"MASK_SW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32}, 395b7cde470SVladimir Kondratiev {"MASK_FW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32}, 396b7cde470SVladimir Kondratiev {}, 397b7cde470SVladimir Kondratiev }; 398b7cde470SVladimir Kondratiev 3992be7d22fSVladimir Kondratiev static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil, 4002be7d22fSVladimir Kondratiev struct dentry *parent) 4012be7d22fSVladimir Kondratiev { 4022be7d22fSVladimir Kondratiev struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent); 4032be7d22fSVladimir Kondratiev 4042be7d22fSVladimir Kondratiev if (IS_ERR_OR_NULL(d)) 4052be7d22fSVladimir Kondratiev return -ENODEV; 4062be7d22fSVladimir Kondratiev 407b7cde470SVladimir Kondratiev wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr, 408b7cde470SVladimir Kondratiev pseudo_isr_off); 4092be7d22fSVladimir Kondratiev 4102be7d22fSVladimir Kondratiev return 0; 4112be7d22fSVladimir Kondratiev } 4122be7d22fSVladimir Kondratiev 41378366f69SVladimir Kondratiev static const struct dbg_off lgc_itr_cnt_off[] = { 414b7cde470SVladimir Kondratiev {"TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32}, 415b7cde470SVladimir Kondratiev {"DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32}, 416b7cde470SVladimir Kondratiev {"CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32}, 417b7cde470SVladimir Kondratiev {}, 418b7cde470SVladimir Kondratiev }; 419b7cde470SVladimir Kondratiev 42078366f69SVladimir Kondratiev static const struct dbg_off tx_itr_cnt_off[] = { 42178366f69SVladimir Kondratiev {"TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_CNT_TRSH), 42278366f69SVladimir Kondratiev doff_io32}, 42378366f69SVladimir Kondratiev {"DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_CNT_DATA), 42478366f69SVladimir Kondratiev doff_io32}, 42578366f69SVladimir Kondratiev {"CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_CNT_CTL), 42678366f69SVladimir Kondratiev doff_io32}, 42778366f69SVladimir Kondratiev {"IDL_TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_TRSH), 42878366f69SVladimir Kondratiev doff_io32}, 42978366f69SVladimir Kondratiev {"IDL_DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_DATA), 43078366f69SVladimir Kondratiev doff_io32}, 43178366f69SVladimir Kondratiev {"IDL_CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_CTL), 43278366f69SVladimir Kondratiev doff_io32}, 43378366f69SVladimir Kondratiev {}, 43478366f69SVladimir Kondratiev }; 43578366f69SVladimir Kondratiev 43678366f69SVladimir Kondratiev static const struct dbg_off rx_itr_cnt_off[] = { 43778366f69SVladimir Kondratiev {"TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_CNT_TRSH), 43878366f69SVladimir Kondratiev doff_io32}, 43978366f69SVladimir Kondratiev {"DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_CNT_DATA), 44078366f69SVladimir Kondratiev doff_io32}, 44178366f69SVladimir Kondratiev {"CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_CNT_CTL), 44278366f69SVladimir Kondratiev doff_io32}, 44378366f69SVladimir Kondratiev {"IDL_TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_TRSH), 44478366f69SVladimir Kondratiev doff_io32}, 44578366f69SVladimir Kondratiev {"IDL_DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_DATA), 44678366f69SVladimir Kondratiev doff_io32}, 44778366f69SVladimir Kondratiev {"IDL_CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_CTL), 44878366f69SVladimir Kondratiev doff_io32}, 44978366f69SVladimir Kondratiev {}, 45078366f69SVladimir Kondratiev }; 45178366f69SVladimir Kondratiev 4522be7d22fSVladimir Kondratiev static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil, 4532be7d22fSVladimir Kondratiev struct dentry *parent) 4542be7d22fSVladimir Kondratiev { 45578366f69SVladimir Kondratiev struct dentry *d, *dtx, *drx; 4562be7d22fSVladimir Kondratiev 45778366f69SVladimir Kondratiev d = debugfs_create_dir("ITR_CNT", parent); 4582be7d22fSVladimir Kondratiev if (IS_ERR_OR_NULL(d)) 4592be7d22fSVladimir Kondratiev return -ENODEV; 4602be7d22fSVladimir Kondratiev 46178366f69SVladimir Kondratiev dtx = debugfs_create_dir("TX", d); 46278366f69SVladimir Kondratiev drx = debugfs_create_dir("RX", d); 46378366f69SVladimir Kondratiev if (IS_ERR_OR_NULL(dtx) || IS_ERR_OR_NULL(drx)) 46478366f69SVladimir Kondratiev return -ENODEV; 4652be7d22fSVladimir Kondratiev 46678366f69SVladimir Kondratiev wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr, 46778366f69SVladimir Kondratiev lgc_itr_cnt_off); 46878366f69SVladimir Kondratiev 46978366f69SVladimir Kondratiev wil6210_debugfs_init_offset(wil, dtx, (void * __force)wil->csr, 47078366f69SVladimir Kondratiev tx_itr_cnt_off); 47178366f69SVladimir Kondratiev 47278366f69SVladimir Kondratiev wil6210_debugfs_init_offset(wil, drx, (void * __force)wil->csr, 47378366f69SVladimir Kondratiev rx_itr_cnt_off); 4742be7d22fSVladimir Kondratiev return 0; 4752be7d22fSVladimir Kondratiev } 4762be7d22fSVladimir Kondratiev 4772be7d22fSVladimir Kondratiev static int wil_memread_debugfs_show(struct seq_file *s, void *data) 4782be7d22fSVladimir Kondratiev { 4792be7d22fSVladimir Kondratiev struct wil6210_priv *wil = s->private; 4802be7d22fSVladimir Kondratiev void __iomem *a = wmi_buffer(wil, cpu_to_le32(mem_addr)); 4812be7d22fSVladimir Kondratiev 4822be7d22fSVladimir Kondratiev if (a) 483b9eeb512SVladimir Kondratiev seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, readl(a)); 4842be7d22fSVladimir Kondratiev else 4852be7d22fSVladimir Kondratiev seq_printf(s, "[0x%08x] = INVALID\n", mem_addr); 4862be7d22fSVladimir Kondratiev 4872be7d22fSVladimir Kondratiev return 0; 4882be7d22fSVladimir Kondratiev } 4892be7d22fSVladimir Kondratiev 4902be7d22fSVladimir Kondratiev static int wil_memread_seq_open(struct inode *inode, struct file *file) 4912be7d22fSVladimir Kondratiev { 4922be7d22fSVladimir Kondratiev return single_open(file, wil_memread_debugfs_show, inode->i_private); 4932be7d22fSVladimir Kondratiev } 4942be7d22fSVladimir Kondratiev 4952be7d22fSVladimir Kondratiev static const struct file_operations fops_memread = { 4962be7d22fSVladimir Kondratiev .open = wil_memread_seq_open, 4972be7d22fSVladimir Kondratiev .release = single_release, 4982be7d22fSVladimir Kondratiev .read = seq_read, 4992be7d22fSVladimir Kondratiev .llseek = seq_lseek, 5002be7d22fSVladimir Kondratiev }; 5012be7d22fSVladimir Kondratiev 5022be7d22fSVladimir Kondratiev static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf, 5032be7d22fSVladimir Kondratiev size_t count, loff_t *ppos) 5042be7d22fSVladimir Kondratiev { 5052be7d22fSVladimir Kondratiev enum { max_count = 4096 }; 506349214c1SMaya Erez struct wil_blob_wrapper *wil_blob = file->private_data; 5072be7d22fSVladimir Kondratiev loff_t pos = *ppos; 508349214c1SMaya Erez size_t available = wil_blob->blob.size; 5092be7d22fSVladimir Kondratiev void *buf; 5102be7d22fSVladimir Kondratiev size_t ret; 5112be7d22fSVladimir Kondratiev 5122be7d22fSVladimir Kondratiev if (pos < 0) 5132be7d22fSVladimir Kondratiev return -EINVAL; 5142be7d22fSVladimir Kondratiev 5152be7d22fSVladimir Kondratiev if (pos >= available || !count) 5162be7d22fSVladimir Kondratiev return 0; 5172be7d22fSVladimir Kondratiev 5182be7d22fSVladimir Kondratiev if (count > available - pos) 5192be7d22fSVladimir Kondratiev count = available - pos; 5202be7d22fSVladimir Kondratiev if (count > max_count) 5212be7d22fSVladimir Kondratiev count = max_count; 5222be7d22fSVladimir Kondratiev 5232be7d22fSVladimir Kondratiev buf = kmalloc(count, GFP_KERNEL); 5242be7d22fSVladimir Kondratiev if (!buf) 5252be7d22fSVladimir Kondratiev return -ENOMEM; 5262be7d22fSVladimir Kondratiev 527349214c1SMaya Erez wil_memcpy_fromio_halp_vote(wil_blob->wil, buf, 528349214c1SMaya Erez (const volatile void __iomem *) 529349214c1SMaya Erez wil_blob->blob.data + pos, count); 5302be7d22fSVladimir Kondratiev 5312be7d22fSVladimir Kondratiev ret = copy_to_user(user_buf, buf, count); 5322be7d22fSVladimir Kondratiev kfree(buf); 5332be7d22fSVladimir Kondratiev if (ret == count) 5342be7d22fSVladimir Kondratiev return -EFAULT; 5352be7d22fSVladimir Kondratiev 5362be7d22fSVladimir Kondratiev count -= ret; 5372be7d22fSVladimir Kondratiev *ppos = pos + count; 5382be7d22fSVladimir Kondratiev 5392be7d22fSVladimir Kondratiev return count; 5402be7d22fSVladimir Kondratiev } 5412be7d22fSVladimir Kondratiev 5422be7d22fSVladimir Kondratiev static const struct file_operations fops_ioblob = { 5432be7d22fSVladimir Kondratiev .read = wil_read_file_ioblob, 54493ecbd64SWei Yongjun .open = simple_open, 5452be7d22fSVladimir Kondratiev .llseek = default_llseek, 5462be7d22fSVladimir Kondratiev }; 5472be7d22fSVladimir Kondratiev 5482be7d22fSVladimir Kondratiev static 5492be7d22fSVladimir Kondratiev struct dentry *wil_debugfs_create_ioblob(const char *name, 5500ecc833bSAl Viro umode_t mode, 5512be7d22fSVladimir Kondratiev struct dentry *parent, 552349214c1SMaya Erez struct wil_blob_wrapper *wil_blob) 5532be7d22fSVladimir Kondratiev { 554349214c1SMaya Erez return debugfs_create_file(name, mode, parent, wil_blob, &fops_ioblob); 5552be7d22fSVladimir Kondratiev } 5568fe59627SVladimir Kondratiev 5572be7d22fSVladimir Kondratiev /*---reset---*/ 5582be7d22fSVladimir Kondratiev static ssize_t wil_write_file_reset(struct file *file, const char __user *buf, 5592be7d22fSVladimir Kondratiev size_t len, loff_t *ppos) 5602be7d22fSVladimir Kondratiev { 5612be7d22fSVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 5622be7d22fSVladimir Kondratiev struct net_device *ndev = wil_to_ndev(wil); 5632be7d22fSVladimir Kondratiev 5642be7d22fSVladimir Kondratiev /** 5652be7d22fSVladimir Kondratiev * BUG: 5662be7d22fSVladimir Kondratiev * this code does NOT sync device state with the rest of system 5672be7d22fSVladimir Kondratiev * use with care, debug only!!! 5682be7d22fSVladimir Kondratiev */ 5692be7d22fSVladimir Kondratiev rtnl_lock(); 5702be7d22fSVladimir Kondratiev dev_close(ndev); 5712be7d22fSVladimir Kondratiev ndev->flags &= ~IFF_UP; 5722be7d22fSVladimir Kondratiev rtnl_unlock(); 5732cd0f021SVladimir Kondratiev wil_reset(wil, true); 5742be7d22fSVladimir Kondratiev 5752be7d22fSVladimir Kondratiev return len; 5762be7d22fSVladimir Kondratiev } 5772be7d22fSVladimir Kondratiev 5782be7d22fSVladimir Kondratiev static const struct file_operations fops_reset = { 5792be7d22fSVladimir Kondratiev .write = wil_write_file_reset, 58093ecbd64SWei Yongjun .open = simple_open, 5812be7d22fSVladimir Kondratiev }; 5828fe59627SVladimir Kondratiev 5830b39aaf2SVladimir Kondratiev /*---write channel 1..4 to rxon for it, 0 to rxoff---*/ 5840b39aaf2SVladimir Kondratiev static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf, 5850b39aaf2SVladimir Kondratiev size_t len, loff_t *ppos) 5860b39aaf2SVladimir Kondratiev { 5870b39aaf2SVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 5880b39aaf2SVladimir Kondratiev int rc; 5890b39aaf2SVladimir Kondratiev long channel; 5900b39aaf2SVladimir Kondratiev bool on; 5910b39aaf2SVladimir Kondratiev 59216e5c1fcSAl Viro char *kbuf = memdup_user_nul(buf, len); 5938fe59627SVladimir Kondratiev 59416e5c1fcSAl Viro if (IS_ERR(kbuf)) 59516e5c1fcSAl Viro return PTR_ERR(kbuf); 5960b39aaf2SVladimir Kondratiev rc = kstrtol(kbuf, 0, &channel); 5970b39aaf2SVladimir Kondratiev kfree(kbuf); 5980b39aaf2SVladimir Kondratiev if (rc) 5990b39aaf2SVladimir Kondratiev return rc; 6000b39aaf2SVladimir Kondratiev 6010b39aaf2SVladimir Kondratiev if ((channel < 0) || (channel > 4)) { 6020b39aaf2SVladimir Kondratiev wil_err(wil, "Invalid channel %ld\n", channel); 6030b39aaf2SVladimir Kondratiev return -EINVAL; 6040b39aaf2SVladimir Kondratiev } 6050b39aaf2SVladimir Kondratiev on = !!channel; 6060b39aaf2SVladimir Kondratiev 6070b39aaf2SVladimir Kondratiev if (on) { 6080b39aaf2SVladimir Kondratiev rc = wmi_set_channel(wil, (int)channel); 6090b39aaf2SVladimir Kondratiev if (rc) 6100b39aaf2SVladimir Kondratiev return rc; 6110b39aaf2SVladimir Kondratiev } 6120b39aaf2SVladimir Kondratiev 6130b39aaf2SVladimir Kondratiev rc = wmi_rxon(wil, on); 6140b39aaf2SVladimir Kondratiev if (rc) 6150b39aaf2SVladimir Kondratiev return rc; 6160b39aaf2SVladimir Kondratiev 6170b39aaf2SVladimir Kondratiev return len; 6180b39aaf2SVladimir Kondratiev } 6190b39aaf2SVladimir Kondratiev 6200b39aaf2SVladimir Kondratiev static const struct file_operations fops_rxon = { 6210b39aaf2SVladimir Kondratiev .write = wil_write_file_rxon, 6220b39aaf2SVladimir Kondratiev .open = simple_open, 6230b39aaf2SVladimir Kondratiev }; 6248fe59627SVladimir Kondratiev 62549cb5dfbSVladimir Kondratiev /* block ack control, write: 62649cb5dfbSVladimir Kondratiev * - "add <ringid> <agg_size> <timeout>" to trigger ADDBA 62749cb5dfbSVladimir Kondratiev * - "del_tx <ringid> <reason>" to trigger DELBA for Tx side 62849cb5dfbSVladimir Kondratiev * - "del_rx <CID> <TID> <reason>" to trigger DELBA for Rx side 6293277213fSVladimir Kondratiev */ 63049cb5dfbSVladimir Kondratiev static ssize_t wil_write_back(struct file *file, const char __user *buf, 6313277213fSVladimir Kondratiev size_t len, loff_t *ppos) 6323277213fSVladimir Kondratiev { 6333277213fSVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 6343277213fSVladimir Kondratiev int rc; 6353277213fSVladimir Kondratiev char *kbuf = kmalloc(len + 1, GFP_KERNEL); 6362a19f776SColin Ian King char cmd[9]; 63749cb5dfbSVladimir Kondratiev int p1, p2, p3; 6383277213fSVladimir Kondratiev 6393277213fSVladimir Kondratiev if (!kbuf) 6403277213fSVladimir Kondratiev return -ENOMEM; 6413277213fSVladimir Kondratiev 6423277213fSVladimir Kondratiev rc = simple_write_to_buffer(kbuf, len, ppos, buf, len); 6433277213fSVladimir Kondratiev if (rc != len) { 6443277213fSVladimir Kondratiev kfree(kbuf); 6453277213fSVladimir Kondratiev return rc >= 0 ? -EIO : rc; 6463277213fSVladimir Kondratiev } 6473277213fSVladimir Kondratiev 6483277213fSVladimir Kondratiev kbuf[len] = '\0'; 64949cb5dfbSVladimir Kondratiev rc = sscanf(kbuf, "%8s %d %d %d", cmd, &p1, &p2, &p3); 6503277213fSVladimir Kondratiev kfree(kbuf); 6513277213fSVladimir Kondratiev 65249cb5dfbSVladimir Kondratiev if (rc < 0) 6533277213fSVladimir Kondratiev return rc; 65449cb5dfbSVladimir Kondratiev if (rc < 2) 6553277213fSVladimir Kondratiev return -EINVAL; 6563277213fSVladimir Kondratiev 65749cb5dfbSVladimir Kondratiev if (0 == strcmp(cmd, "add")) { 65849cb5dfbSVladimir Kondratiev if (rc < 3) { 65949cb5dfbSVladimir Kondratiev wil_err(wil, "BACK: add require at least 2 params\n"); 66049cb5dfbSVladimir Kondratiev return -EINVAL; 66149cb5dfbSVladimir Kondratiev } 66249cb5dfbSVladimir Kondratiev if (rc < 4) 66349cb5dfbSVladimir Kondratiev p3 = 0; 66449cb5dfbSVladimir Kondratiev wmi_addba(wil, p1, p2, p3); 66549cb5dfbSVladimir Kondratiev } else if (0 == strcmp(cmd, "del_tx")) { 66649cb5dfbSVladimir Kondratiev if (rc < 3) 66749cb5dfbSVladimir Kondratiev p2 = WLAN_REASON_QSTA_LEAVE_QBSS; 66849cb5dfbSVladimir Kondratiev wmi_delba_tx(wil, p1, p2); 66949cb5dfbSVladimir Kondratiev } else if (0 == strcmp(cmd, "del_rx")) { 67049cb5dfbSVladimir Kondratiev if (rc < 3) { 67149cb5dfbSVladimir Kondratiev wil_err(wil, 67249cb5dfbSVladimir Kondratiev "BACK: del_rx require at least 2 params\n"); 67349cb5dfbSVladimir Kondratiev return -EINVAL; 67449cb5dfbSVladimir Kondratiev } 67549cb5dfbSVladimir Kondratiev if (rc < 4) 67649cb5dfbSVladimir Kondratiev p3 = WLAN_REASON_QSTA_LEAVE_QBSS; 67749cb5dfbSVladimir Kondratiev wmi_delba_rx(wil, mk_cidxtid(p1, p2), p3); 67849cb5dfbSVladimir Kondratiev } else { 67949cb5dfbSVladimir Kondratiev wil_err(wil, "BACK: Unrecognized command \"%s\"\n", cmd); 68049cb5dfbSVladimir Kondratiev return -EINVAL; 68149cb5dfbSVladimir Kondratiev } 6823277213fSVladimir Kondratiev 6833277213fSVladimir Kondratiev return len; 6843277213fSVladimir Kondratiev } 6853277213fSVladimir Kondratiev 68649cb5dfbSVladimir Kondratiev static ssize_t wil_read_back(struct file *file, char __user *user_buf, 68749cb5dfbSVladimir Kondratiev size_t count, loff_t *ppos) 68849cb5dfbSVladimir Kondratiev { 68949cb5dfbSVladimir Kondratiev static const char text[] = "block ack control, write:\n" 69049cb5dfbSVladimir Kondratiev " - \"add <ringid> <agg_size> <timeout>\" to trigger ADDBA\n" 69149cb5dfbSVladimir Kondratiev "If missing, <timeout> defaults to 0\n" 69249cb5dfbSVladimir Kondratiev " - \"del_tx <ringid> <reason>\" to trigger DELBA for Tx side\n" 69349cb5dfbSVladimir Kondratiev " - \"del_rx <CID> <TID> <reason>\" to trigger DELBA for Rx side\n" 69449cb5dfbSVladimir Kondratiev "If missing, <reason> set to \"STA_LEAVING\" (36)\n"; 69549cb5dfbSVladimir Kondratiev 69649cb5dfbSVladimir Kondratiev return simple_read_from_buffer(user_buf, count, ppos, text, 69749cb5dfbSVladimir Kondratiev sizeof(text)); 69849cb5dfbSVladimir Kondratiev } 69949cb5dfbSVladimir Kondratiev 70049cb5dfbSVladimir Kondratiev static const struct file_operations fops_back = { 70149cb5dfbSVladimir Kondratiev .read = wil_read_back, 70249cb5dfbSVladimir Kondratiev .write = wil_write_back, 7033277213fSVladimir Kondratiev .open = simple_open, 7043277213fSVladimir Kondratiev }; 7053277213fSVladimir Kondratiev 706dc16427bSVladimir Kondratiev /* pmc control, write: 707dc16427bSVladimir Kondratiev * - "alloc <num descriptors> <descriptor_size>" to allocate PMC 708dc16427bSVladimir Kondratiev * - "free" to release memory allocated for PMC 709dc16427bSVladimir Kondratiev */ 710dc16427bSVladimir Kondratiev static ssize_t wil_write_pmccfg(struct file *file, const char __user *buf, 711dc16427bSVladimir Kondratiev size_t len, loff_t *ppos) 712dc16427bSVladimir Kondratiev { 713dc16427bSVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 714dc16427bSVladimir Kondratiev int rc; 715dc16427bSVladimir Kondratiev char *kbuf = kmalloc(len + 1, GFP_KERNEL); 716dc16427bSVladimir Kondratiev char cmd[9]; 717dc16427bSVladimir Kondratiev int num_descs, desc_size; 718dc16427bSVladimir Kondratiev 719dc16427bSVladimir Kondratiev if (!kbuf) 720dc16427bSVladimir Kondratiev return -ENOMEM; 721dc16427bSVladimir Kondratiev 722dc16427bSVladimir Kondratiev rc = simple_write_to_buffer(kbuf, len, ppos, buf, len); 723dc16427bSVladimir Kondratiev if (rc != len) { 724dc16427bSVladimir Kondratiev kfree(kbuf); 725dc16427bSVladimir Kondratiev return rc >= 0 ? -EIO : rc; 726dc16427bSVladimir Kondratiev } 727dc16427bSVladimir Kondratiev 728dc16427bSVladimir Kondratiev kbuf[len] = '\0'; 729dc16427bSVladimir Kondratiev rc = sscanf(kbuf, "%8s %d %d", cmd, &num_descs, &desc_size); 730dc16427bSVladimir Kondratiev kfree(kbuf); 731dc16427bSVladimir Kondratiev 732dc16427bSVladimir Kondratiev if (rc < 0) 733dc16427bSVladimir Kondratiev return rc; 734dc16427bSVladimir Kondratiev 735dc16427bSVladimir Kondratiev if (rc < 1) { 736dc16427bSVladimir Kondratiev wil_err(wil, "pmccfg: no params given\n"); 737dc16427bSVladimir Kondratiev return -EINVAL; 738dc16427bSVladimir Kondratiev } 739dc16427bSVladimir Kondratiev 740dc16427bSVladimir Kondratiev if (0 == strcmp(cmd, "alloc")) { 741dc16427bSVladimir Kondratiev if (rc != 3) { 742dc16427bSVladimir Kondratiev wil_err(wil, "pmccfg: alloc requires 2 params\n"); 743dc16427bSVladimir Kondratiev return -EINVAL; 744dc16427bSVladimir Kondratiev } 745dc16427bSVladimir Kondratiev wil_pmc_alloc(wil, num_descs, desc_size); 746dc16427bSVladimir Kondratiev } else if (0 == strcmp(cmd, "free")) { 747dc16427bSVladimir Kondratiev if (rc != 1) { 748dc16427bSVladimir Kondratiev wil_err(wil, "pmccfg: free does not have any params\n"); 749dc16427bSVladimir Kondratiev return -EINVAL; 750dc16427bSVladimir Kondratiev } 751dc16427bSVladimir Kondratiev wil_pmc_free(wil, true); 752dc16427bSVladimir Kondratiev } else { 753dc16427bSVladimir Kondratiev wil_err(wil, "pmccfg: Unrecognized command \"%s\"\n", cmd); 754dc16427bSVladimir Kondratiev return -EINVAL; 755dc16427bSVladimir Kondratiev } 756dc16427bSVladimir Kondratiev 757dc16427bSVladimir Kondratiev return len; 758dc16427bSVladimir Kondratiev } 759dc16427bSVladimir Kondratiev 760dc16427bSVladimir Kondratiev static ssize_t wil_read_pmccfg(struct file *file, char __user *user_buf, 761dc16427bSVladimir Kondratiev size_t count, loff_t *ppos) 762dc16427bSVladimir Kondratiev { 763dc16427bSVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 764dc16427bSVladimir Kondratiev char text[256]; 765dc16427bSVladimir Kondratiev char help[] = "pmc control, write:\n" 766dc16427bSVladimir Kondratiev " - \"alloc <num descriptors> <descriptor_size>\" to allocate pmc\n" 767dc16427bSVladimir Kondratiev " - \"free\" to free memory allocated for pmc\n"; 768dc16427bSVladimir Kondratiev 769dc16427bSVladimir Kondratiev sprintf(text, "Last command status: %d\n\n%s", 770dc16427bSVladimir Kondratiev wil_pmc_last_cmd_status(wil), 771dc16427bSVladimir Kondratiev help); 772dc16427bSVladimir Kondratiev 773dc16427bSVladimir Kondratiev return simple_read_from_buffer(user_buf, count, ppos, text, 774dc16427bSVladimir Kondratiev strlen(text) + 1); 775dc16427bSVladimir Kondratiev } 776dc16427bSVladimir Kondratiev 777dc16427bSVladimir Kondratiev static const struct file_operations fops_pmccfg = { 778dc16427bSVladimir Kondratiev .read = wil_read_pmccfg, 779dc16427bSVladimir Kondratiev .write = wil_write_pmccfg, 780dc16427bSVladimir Kondratiev .open = simple_open, 781dc16427bSVladimir Kondratiev }; 782dc16427bSVladimir Kondratiev 783dc16427bSVladimir Kondratiev static const struct file_operations fops_pmcdata = { 784dc16427bSVladimir Kondratiev .open = simple_open, 785dc16427bSVladimir Kondratiev .read = wil_pmc_read, 786dc16427bSVladimir Kondratiev .llseek = wil_pmc_llseek, 787dc16427bSVladimir Kondratiev }; 788dc16427bSVladimir Kondratiev 7890b39aaf2SVladimir Kondratiev /*---tx_mgmt---*/ 7900b39aaf2SVladimir Kondratiev /* Write mgmt frame to this file to send it */ 7910b39aaf2SVladimir Kondratiev static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf, 7920b39aaf2SVladimir Kondratiev size_t len, loff_t *ppos) 7930b39aaf2SVladimir Kondratiev { 7940b39aaf2SVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 7950b39aaf2SVladimir Kondratiev struct wiphy *wiphy = wil_to_wiphy(wil); 7960b39aaf2SVladimir Kondratiev struct wireless_dev *wdev = wil_to_wdev(wil); 7970b39aaf2SVladimir Kondratiev struct cfg80211_mgmt_tx_params params; 7980b39aaf2SVladimir Kondratiev int rc; 7990b39aaf2SVladimir Kondratiev void *frame = kmalloc(len, GFP_KERNEL); 8008fe59627SVladimir Kondratiev 8010b39aaf2SVladimir Kondratiev if (!frame) 8020b39aaf2SVladimir Kondratiev return -ENOMEM; 8030b39aaf2SVladimir Kondratiev 8048e09b7d2SLino Sanfilippo if (copy_from_user(frame, buf, len)) { 8058e09b7d2SLino Sanfilippo kfree(frame); 8060b39aaf2SVladimir Kondratiev return -EIO; 8078e09b7d2SLino Sanfilippo } 8080b39aaf2SVladimir Kondratiev 8090b39aaf2SVladimir Kondratiev params.buf = frame; 8100b39aaf2SVladimir Kondratiev params.len = len; 8110b39aaf2SVladimir Kondratiev params.chan = wdev->preset_chandef.chan; 8120b39aaf2SVladimir Kondratiev 8130b39aaf2SVladimir Kondratiev rc = wil_cfg80211_mgmt_tx(wiphy, wdev, ¶ms, NULL); 8140b39aaf2SVladimir Kondratiev 8150b39aaf2SVladimir Kondratiev kfree(frame); 816*af3db60aSLazar Alexei wil_info(wil, "-> %d\n", rc); 8170b39aaf2SVladimir Kondratiev 8180b39aaf2SVladimir Kondratiev return len; 8190b39aaf2SVladimir Kondratiev } 8200b39aaf2SVladimir Kondratiev 8210b39aaf2SVladimir Kondratiev static const struct file_operations fops_txmgmt = { 8220b39aaf2SVladimir Kondratiev .write = wil_write_file_txmgmt, 8230b39aaf2SVladimir Kondratiev .open = simple_open, 8240b39aaf2SVladimir Kondratiev }; 8252be7d22fSVladimir Kondratiev 826ff974e40SVladimir Kondratiev /* Write WMI command (w/o mbox header) to this file to send it 827ff974e40SVladimir Kondratiev * WMI starts from wil6210_mbox_hdr_wmi header 828ff974e40SVladimir Kondratiev */ 829ff974e40SVladimir Kondratiev static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf, 830ff974e40SVladimir Kondratiev size_t len, loff_t *ppos) 831ff974e40SVladimir Kondratiev { 832ff974e40SVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 833b874ddecSLior David struct wmi_cmd_hdr *wmi; 834ff974e40SVladimir Kondratiev void *cmd; 835b874ddecSLior David int cmdlen = len - sizeof(struct wmi_cmd_hdr); 836ff974e40SVladimir Kondratiev u16 cmdid; 837ff974e40SVladimir Kondratiev int rc, rc1; 838ff974e40SVladimir Kondratiev 83969218a48SLior David if (cmdlen < 0) 840ff974e40SVladimir Kondratiev return -EINVAL; 841ff974e40SVladimir Kondratiev 842ff974e40SVladimir Kondratiev wmi = kmalloc(len, GFP_KERNEL); 843ff974e40SVladimir Kondratiev if (!wmi) 844ff974e40SVladimir Kondratiev return -ENOMEM; 845ff974e40SVladimir Kondratiev 846ff974e40SVladimir Kondratiev rc = simple_write_to_buffer(wmi, len, ppos, buf, len); 8478e09b7d2SLino Sanfilippo if (rc < 0) { 8488e09b7d2SLino Sanfilippo kfree(wmi); 849ff974e40SVladimir Kondratiev return rc; 8508e09b7d2SLino Sanfilippo } 851ff974e40SVladimir Kondratiev 85269218a48SLior David cmd = (cmdlen > 0) ? &wmi[1] : NULL; 853b874ddecSLior David cmdid = le16_to_cpu(wmi->command_id); 854ff974e40SVladimir Kondratiev 855ff974e40SVladimir Kondratiev rc1 = wmi_send(wil, cmdid, cmd, cmdlen); 856ff974e40SVladimir Kondratiev kfree(wmi); 857ff974e40SVladimir Kondratiev 858*af3db60aSLazar Alexei wil_info(wil, "0x%04x[%d] -> %d\n", cmdid, cmdlen, rc1); 859ff974e40SVladimir Kondratiev 860ff974e40SVladimir Kondratiev return rc; 861ff974e40SVladimir Kondratiev } 862ff974e40SVladimir Kondratiev 863ff974e40SVladimir Kondratiev static const struct file_operations fops_wmi = { 864ff974e40SVladimir Kondratiev .write = wil_write_file_wmi, 865ff974e40SVladimir Kondratiev .open = simple_open, 866ff974e40SVladimir Kondratiev }; 867ff974e40SVladimir Kondratiev 868c236658fSVladimir Kondratiev static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb) 869c236658fSVladimir Kondratiev { 870c236658fSVladimir Kondratiev int i = 0; 871c236658fSVladimir Kondratiev int len = skb_headlen(skb); 872c236658fSVladimir Kondratiev void *p = skb->data; 873c236658fSVladimir Kondratiev int nr_frags = skb_shinfo(skb)->nr_frags; 874c236658fSVladimir Kondratiev 875c236658fSVladimir Kondratiev seq_printf(s, " len = %d\n", len); 876c236658fSVladimir Kondratiev wil_seq_hexdump(s, p, len, " : "); 877c236658fSVladimir Kondratiev 878c236658fSVladimir Kondratiev if (nr_frags) { 879c236658fSVladimir Kondratiev seq_printf(s, " nr_frags = %d\n", nr_frags); 880c236658fSVladimir Kondratiev for (i = 0; i < nr_frags; i++) { 881c236658fSVladimir Kondratiev const struct skb_frag_struct *frag = 882c236658fSVladimir Kondratiev &skb_shinfo(skb)->frags[i]; 883c236658fSVladimir Kondratiev 884c236658fSVladimir Kondratiev len = skb_frag_size(frag); 885c236658fSVladimir Kondratiev p = skb_frag_address_safe(frag); 886c236658fSVladimir Kondratiev seq_printf(s, " [%2d] : len = %d\n", i, len); 887c236658fSVladimir Kondratiev wil_seq_hexdump(s, p, len, " : "); 888c236658fSVladimir Kondratiev } 889c236658fSVladimir Kondratiev } 890c236658fSVladimir Kondratiev } 891c236658fSVladimir Kondratiev 8923a85543eSVladimir Kondratiev /*---------Tx/Rx descriptor------------*/ 8932be7d22fSVladimir Kondratiev static int wil_txdesc_debugfs_show(struct seq_file *s, void *data) 8942be7d22fSVladimir Kondratiev { 8952be7d22fSVladimir Kondratiev struct wil6210_priv *wil = s->private; 8963a85543eSVladimir Kondratiev struct vring *vring; 897af31cb5aSVladimir Kondratiev bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS); 8988fe59627SVladimir Kondratiev 8998fe59627SVladimir Kondratiev vring = tx ? &wil->vring_tx[dbg_vring_index] : &wil->vring_rx; 9002be7d22fSVladimir Kondratiev 9012be7d22fSVladimir Kondratiev if (!vring->va) { 902af31cb5aSVladimir Kondratiev if (tx) 9033a85543eSVladimir Kondratiev seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index); 9043a85543eSVladimir Kondratiev else 9053a85543eSVladimir Kondratiev seq_puts(s, "No Rx VRING\n"); 9062be7d22fSVladimir Kondratiev return 0; 9072be7d22fSVladimir Kondratiev } 9082be7d22fSVladimir Kondratiev 9092be7d22fSVladimir Kondratiev if (dbg_txdesc_index < vring->size) { 9103a85543eSVladimir Kondratiev /* use struct vring_tx_desc for Rx as well, 9113a85543eSVladimir Kondratiev * only field used, .dma.length, is the same 9123a85543eSVladimir Kondratiev */ 9132be7d22fSVladimir Kondratiev volatile struct vring_tx_desc *d = 9148fe59627SVladimir Kondratiev &vring->va[dbg_txdesc_index].tx; 9152be7d22fSVladimir Kondratiev volatile u32 *u = (volatile u32 *)d; 916f88f113aSVladimir Kondratiev struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb; 9172be7d22fSVladimir Kondratiev 918af31cb5aSVladimir Kondratiev if (tx) 9193a85543eSVladimir Kondratiev seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index, 9203a85543eSVladimir Kondratiev dbg_txdesc_index); 9213a85543eSVladimir Kondratiev else 9223a85543eSVladimir Kondratiev seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index); 9232be7d22fSVladimir Kondratiev seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n", 9242be7d22fSVladimir Kondratiev u[0], u[1], u[2], u[3]); 9252be7d22fSVladimir Kondratiev seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n", 9262be7d22fSVladimir Kondratiev u[4], u[5], u[6], u[7]); 92739c52ee8SVladimir Kondratiev seq_printf(s, " SKB = 0x%p\n", skb); 9282be7d22fSVladimir Kondratiev 9292be7d22fSVladimir Kondratiev if (skb) { 930c236658fSVladimir Kondratiev skb_get(skb); 931c236658fSVladimir Kondratiev wil_seq_print_skb(s, skb); 932c236658fSVladimir Kondratiev kfree_skb(skb); 9332be7d22fSVladimir Kondratiev } 9348fe59627SVladimir Kondratiev seq_puts(s, "}\n"); 9352be7d22fSVladimir Kondratiev } else { 936af31cb5aSVladimir Kondratiev if (tx) 9373a85543eSVladimir Kondratiev seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n", 9383a85543eSVladimir Kondratiev dbg_vring_index, dbg_txdesc_index, 9393a85543eSVladimir Kondratiev vring->size); 9403a85543eSVladimir Kondratiev else 9413a85543eSVladimir Kondratiev seq_printf(s, "RxDesc index (%d) >= size (%d)\n", 9422be7d22fSVladimir Kondratiev dbg_txdesc_index, vring->size); 9432be7d22fSVladimir Kondratiev } 9442be7d22fSVladimir Kondratiev 9452be7d22fSVladimir Kondratiev return 0; 9462be7d22fSVladimir Kondratiev } 9472be7d22fSVladimir Kondratiev 9482be7d22fSVladimir Kondratiev static int wil_txdesc_seq_open(struct inode *inode, struct file *file) 9492be7d22fSVladimir Kondratiev { 9502be7d22fSVladimir Kondratiev return single_open(file, wil_txdesc_debugfs_show, inode->i_private); 9512be7d22fSVladimir Kondratiev } 9522be7d22fSVladimir Kondratiev 9532be7d22fSVladimir Kondratiev static const struct file_operations fops_txdesc = { 9542be7d22fSVladimir Kondratiev .open = wil_txdesc_seq_open, 9552be7d22fSVladimir Kondratiev .release = single_release, 9562be7d22fSVladimir Kondratiev .read = seq_read, 9572be7d22fSVladimir Kondratiev .llseek = seq_lseek, 9582be7d22fSVladimir Kondratiev }; 9592be7d22fSVladimir Kondratiev 9602be7d22fSVladimir Kondratiev /*---------beamforming------------*/ 96136345ac3SVladimir Kondratiev static char *wil_bfstatus_str(u32 status) 96236345ac3SVladimir Kondratiev { 96336345ac3SVladimir Kondratiev switch (status) { 96436345ac3SVladimir Kondratiev case 0: 96536345ac3SVladimir Kondratiev return "Failed"; 96636345ac3SVladimir Kondratiev case 1: 96736345ac3SVladimir Kondratiev return "OK"; 96836345ac3SVladimir Kondratiev case 2: 96936345ac3SVladimir Kondratiev return "Retrying"; 97036345ac3SVladimir Kondratiev default: 97136345ac3SVladimir Kondratiev return "??"; 97236345ac3SVladimir Kondratiev } 97336345ac3SVladimir Kondratiev } 97436345ac3SVladimir Kondratiev 97536345ac3SVladimir Kondratiev static bool is_all_zeros(void * const x_, size_t sz) 97636345ac3SVladimir Kondratiev { 97736345ac3SVladimir Kondratiev /* if reply is all-0, ignore this CID */ 97836345ac3SVladimir Kondratiev u32 *x = x_; 97936345ac3SVladimir Kondratiev int n; 98036345ac3SVladimir Kondratiev 98136345ac3SVladimir Kondratiev for (n = 0; n < sz / sizeof(*x); n++) 98236345ac3SVladimir Kondratiev if (x[n]) 98336345ac3SVladimir Kondratiev return false; 98436345ac3SVladimir Kondratiev 98536345ac3SVladimir Kondratiev return true; 98636345ac3SVladimir Kondratiev } 98736345ac3SVladimir Kondratiev 9882be7d22fSVladimir Kondratiev static int wil_bf_debugfs_show(struct seq_file *s, void *data) 9892be7d22fSVladimir Kondratiev { 99036345ac3SVladimir Kondratiev int rc; 99136345ac3SVladimir Kondratiev int i; 9922be7d22fSVladimir Kondratiev struct wil6210_priv *wil = s->private; 99336345ac3SVladimir Kondratiev struct wmi_notify_req_cmd cmd = { 99436345ac3SVladimir Kondratiev .interval_usec = 0, 99536345ac3SVladimir Kondratiev }; 99636345ac3SVladimir Kondratiev struct { 997b874ddecSLior David struct wmi_cmd_hdr wmi; 99836345ac3SVladimir Kondratiev struct wmi_notify_req_done_event evt; 99936345ac3SVladimir Kondratiev } __packed reply; 100036345ac3SVladimir Kondratiev 100136345ac3SVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(wil->sta); i++) { 100236345ac3SVladimir Kondratiev u32 status; 100336345ac3SVladimir Kondratiev 100436345ac3SVladimir Kondratiev cmd.cid = i; 100536345ac3SVladimir Kondratiev rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd), 100636345ac3SVladimir Kondratiev WMI_NOTIFY_REQ_DONE_EVENTID, &reply, 100736345ac3SVladimir Kondratiev sizeof(reply), 20); 100836345ac3SVladimir Kondratiev /* if reply is all-0, ignore this CID */ 100936345ac3SVladimir Kondratiev if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt))) 101036345ac3SVladimir Kondratiev continue; 101136345ac3SVladimir Kondratiev 101236345ac3SVladimir Kondratiev status = le32_to_cpu(reply.evt.status); 101336345ac3SVladimir Kondratiev seq_printf(s, "CID %d {\n" 101436345ac3SVladimir Kondratiev " TSF = 0x%016llx\n" 101536345ac3SVladimir Kondratiev " TxMCS = %2d TxTpt = %4d\n" 101636345ac3SVladimir Kondratiev " SQI = %4d\n" 101736345ac3SVladimir Kondratiev " Status = 0x%08x %s\n" 101836345ac3SVladimir Kondratiev " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n" 101936345ac3SVladimir Kondratiev " Goodput(rx:tx) %4d:%4d\n" 102036345ac3SVladimir Kondratiev "}\n", 102136345ac3SVladimir Kondratiev i, 102236345ac3SVladimir Kondratiev le64_to_cpu(reply.evt.tsf), 102336345ac3SVladimir Kondratiev le16_to_cpu(reply.evt.bf_mcs), 102436345ac3SVladimir Kondratiev le32_to_cpu(reply.evt.tx_tpt), 102536345ac3SVladimir Kondratiev reply.evt.sqi, 102636345ac3SVladimir Kondratiev status, wil_bfstatus_str(status), 102736345ac3SVladimir Kondratiev le16_to_cpu(reply.evt.my_rx_sector), 102836345ac3SVladimir Kondratiev le16_to_cpu(reply.evt.my_tx_sector), 102936345ac3SVladimir Kondratiev le16_to_cpu(reply.evt.other_rx_sector), 103036345ac3SVladimir Kondratiev le16_to_cpu(reply.evt.other_tx_sector), 103136345ac3SVladimir Kondratiev le32_to_cpu(reply.evt.rx_goodput), 103236345ac3SVladimir Kondratiev le32_to_cpu(reply.evt.tx_goodput)); 103336345ac3SVladimir Kondratiev } 10342be7d22fSVladimir Kondratiev return 0; 10352be7d22fSVladimir Kondratiev } 10362be7d22fSVladimir Kondratiev 10372be7d22fSVladimir Kondratiev static int wil_bf_seq_open(struct inode *inode, struct file *file) 10382be7d22fSVladimir Kondratiev { 10392be7d22fSVladimir Kondratiev return single_open(file, wil_bf_debugfs_show, inode->i_private); 10402be7d22fSVladimir Kondratiev } 10412be7d22fSVladimir Kondratiev 10422be7d22fSVladimir Kondratiev static const struct file_operations fops_bf = { 10432be7d22fSVladimir Kondratiev .open = wil_bf_seq_open, 10442be7d22fSVladimir Kondratiev .release = single_release, 10452be7d22fSVladimir Kondratiev .read = seq_read, 10462be7d22fSVladimir Kondratiev .llseek = seq_lseek, 10472be7d22fSVladimir Kondratiev }; 10488fe59627SVladimir Kondratiev 10492be7d22fSVladimir Kondratiev /*---------SSID------------*/ 10502be7d22fSVladimir Kondratiev static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf, 10512be7d22fSVladimir Kondratiev size_t count, loff_t *ppos) 10522be7d22fSVladimir Kondratiev { 10532be7d22fSVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 10542be7d22fSVladimir Kondratiev struct wireless_dev *wdev = wil_to_wdev(wil); 10552be7d22fSVladimir Kondratiev 10562be7d22fSVladimir Kondratiev return simple_read_from_buffer(user_buf, count, ppos, 10572be7d22fSVladimir Kondratiev wdev->ssid, wdev->ssid_len); 10582be7d22fSVladimir Kondratiev } 10592be7d22fSVladimir Kondratiev 10602be7d22fSVladimir Kondratiev static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf, 10612be7d22fSVladimir Kondratiev size_t count, loff_t *ppos) 10622be7d22fSVladimir Kondratiev { 10632be7d22fSVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 10642be7d22fSVladimir Kondratiev struct wireless_dev *wdev = wil_to_wdev(wil); 10652be7d22fSVladimir Kondratiev struct net_device *ndev = wil_to_ndev(wil); 10662be7d22fSVladimir Kondratiev 10672be7d22fSVladimir Kondratiev if (*ppos != 0) { 10682be7d22fSVladimir Kondratiev wil_err(wil, "Unable to set SSID substring from [%d]\n", 10692be7d22fSVladimir Kondratiev (int)*ppos); 10702be7d22fSVladimir Kondratiev return -EINVAL; 10712be7d22fSVladimir Kondratiev } 10722be7d22fSVladimir Kondratiev 10732be7d22fSVladimir Kondratiev if (count > sizeof(wdev->ssid)) { 10742be7d22fSVladimir Kondratiev wil_err(wil, "SSID too long, len = %d\n", (int)count); 10752be7d22fSVladimir Kondratiev return -EINVAL; 10762be7d22fSVladimir Kondratiev } 10772be7d22fSVladimir Kondratiev if (netif_running(ndev)) { 10782be7d22fSVladimir Kondratiev wil_err(wil, "Unable to change SSID on running interface\n"); 10792be7d22fSVladimir Kondratiev return -EINVAL; 10802be7d22fSVladimir Kondratiev } 10812be7d22fSVladimir Kondratiev 10822be7d22fSVladimir Kondratiev wdev->ssid_len = count; 10832be7d22fSVladimir Kondratiev return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos, 10842be7d22fSVladimir Kondratiev buf, count); 10852be7d22fSVladimir Kondratiev } 10862be7d22fSVladimir Kondratiev 10872be7d22fSVladimir Kondratiev static const struct file_operations fops_ssid = { 10882be7d22fSVladimir Kondratiev .read = wil_read_file_ssid, 10892be7d22fSVladimir Kondratiev .write = wil_write_file_ssid, 109093ecbd64SWei Yongjun .open = simple_open, 10912be7d22fSVladimir Kondratiev }; 10922be7d22fSVladimir Kondratiev 10931a2780e0SVladimir Kondratiev /*---------temp------------*/ 10941a2780e0SVladimir Kondratiev static void print_temp(struct seq_file *s, const char *prefix, u32 t) 10951a2780e0SVladimir Kondratiev { 10961a2780e0SVladimir Kondratiev switch (t) { 10971a2780e0SVladimir Kondratiev case 0: 10981a2780e0SVladimir Kondratiev case ~(u32)0: 10991a2780e0SVladimir Kondratiev seq_printf(s, "%s N/A\n", prefix); 11001a2780e0SVladimir Kondratiev break; 11011a2780e0SVladimir Kondratiev default: 11021a2780e0SVladimir Kondratiev seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000); 11031a2780e0SVladimir Kondratiev break; 11041a2780e0SVladimir Kondratiev } 11051a2780e0SVladimir Kondratiev } 11061a2780e0SVladimir Kondratiev 11071a2780e0SVladimir Kondratiev static int wil_temp_debugfs_show(struct seq_file *s, void *data) 11081a2780e0SVladimir Kondratiev { 11091a2780e0SVladimir Kondratiev struct wil6210_priv *wil = s->private; 11101a2780e0SVladimir Kondratiev u32 t_m, t_r; 11111a2780e0SVladimir Kondratiev int rc = wmi_get_temperature(wil, &t_m, &t_r); 11128fe59627SVladimir Kondratiev 11131a2780e0SVladimir Kondratiev if (rc) { 11148fe59627SVladimir Kondratiev seq_puts(s, "Failed\n"); 11151a2780e0SVladimir Kondratiev return 0; 11161a2780e0SVladimir Kondratiev } 11171a2780e0SVladimir Kondratiev 1118d45cff9fSVladimir Kondratiev print_temp(s, "T_mac =", t_m); 1119d45cff9fSVladimir Kondratiev print_temp(s, "T_radio =", t_r); 11201a2780e0SVladimir Kondratiev 11211a2780e0SVladimir Kondratiev return 0; 11221a2780e0SVladimir Kondratiev } 11231a2780e0SVladimir Kondratiev 11241a2780e0SVladimir Kondratiev static int wil_temp_seq_open(struct inode *inode, struct file *file) 11251a2780e0SVladimir Kondratiev { 11261a2780e0SVladimir Kondratiev return single_open(file, wil_temp_debugfs_show, inode->i_private); 11271a2780e0SVladimir Kondratiev } 11281a2780e0SVladimir Kondratiev 11291a2780e0SVladimir Kondratiev static const struct file_operations fops_temp = { 11301a2780e0SVladimir Kondratiev .open = wil_temp_seq_open, 11311a2780e0SVladimir Kondratiev .release = single_release, 11321a2780e0SVladimir Kondratiev .read = seq_read, 11331a2780e0SVladimir Kondratiev .llseek = seq_lseek, 11341a2780e0SVladimir Kondratiev }; 11351a2780e0SVladimir Kondratiev 11369eb82d43SVladimir Kondratiev /*---------freq------------*/ 11379eb82d43SVladimir Kondratiev static int wil_freq_debugfs_show(struct seq_file *s, void *data) 11389eb82d43SVladimir Kondratiev { 11399eb82d43SVladimir Kondratiev struct wil6210_priv *wil = s->private; 11409eb82d43SVladimir Kondratiev struct wireless_dev *wdev = wil_to_wdev(wil); 11419eb82d43SVladimir Kondratiev u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0; 11429eb82d43SVladimir Kondratiev 11439eb82d43SVladimir Kondratiev seq_printf(s, "Freq = %d\n", freq); 11449eb82d43SVladimir Kondratiev 11459eb82d43SVladimir Kondratiev return 0; 11469eb82d43SVladimir Kondratiev } 11479eb82d43SVladimir Kondratiev 11489eb82d43SVladimir Kondratiev static int wil_freq_seq_open(struct inode *inode, struct file *file) 11499eb82d43SVladimir Kondratiev { 11509eb82d43SVladimir Kondratiev return single_open(file, wil_freq_debugfs_show, inode->i_private); 11519eb82d43SVladimir Kondratiev } 11529eb82d43SVladimir Kondratiev 11539eb82d43SVladimir Kondratiev static const struct file_operations fops_freq = { 11549eb82d43SVladimir Kondratiev .open = wil_freq_seq_open, 11559eb82d43SVladimir Kondratiev .release = single_release, 11569eb82d43SVladimir Kondratiev .read = seq_read, 11579eb82d43SVladimir Kondratiev .llseek = seq_lseek, 11589eb82d43SVladimir Kondratiev }; 11599eb82d43SVladimir Kondratiev 11609eb82d43SVladimir Kondratiev /*---------link------------*/ 11619eb82d43SVladimir Kondratiev static int wil_link_debugfs_show(struct seq_file *s, void *data) 11629eb82d43SVladimir Kondratiev { 11639eb82d43SVladimir Kondratiev struct wil6210_priv *wil = s->private; 11649eb82d43SVladimir Kondratiev struct station_info sinfo; 11659eb82d43SVladimir Kondratiev int i, rc; 11669eb82d43SVladimir Kondratiev 11679eb82d43SVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(wil->sta); i++) { 11689eb82d43SVladimir Kondratiev struct wil_sta_info *p = &wil->sta[i]; 11699eb82d43SVladimir Kondratiev char *status = "unknown"; 11708fe59627SVladimir Kondratiev 11719eb82d43SVladimir Kondratiev switch (p->status) { 11729eb82d43SVladimir Kondratiev case wil_sta_unused: 11739eb82d43SVladimir Kondratiev status = "unused "; 11749eb82d43SVladimir Kondratiev break; 11759eb82d43SVladimir Kondratiev case wil_sta_conn_pending: 11769eb82d43SVladimir Kondratiev status = "pending "; 11779eb82d43SVladimir Kondratiev break; 11789eb82d43SVladimir Kondratiev case wil_sta_connected: 11799eb82d43SVladimir Kondratiev status = "connected"; 11809eb82d43SVladimir Kondratiev break; 11819eb82d43SVladimir Kondratiev } 1182230d8442SVladimir Kondratiev seq_printf(s, "[%d] %pM %s\n", i, p->addr, status); 11839eb82d43SVladimir Kondratiev 11849eb82d43SVladimir Kondratiev if (p->status == wil_sta_connected) { 11859eb82d43SVladimir Kondratiev rc = wil_cid_fill_sinfo(wil, i, &sinfo); 11869eb82d43SVladimir Kondratiev if (rc) 11879eb82d43SVladimir Kondratiev return rc; 11889eb82d43SVladimir Kondratiev 11899eb82d43SVladimir Kondratiev seq_printf(s, " Tx_mcs = %d\n", sinfo.txrate.mcs); 11909eb82d43SVladimir Kondratiev seq_printf(s, " Rx_mcs = %d\n", sinfo.rxrate.mcs); 11919eb82d43SVladimir Kondratiev seq_printf(s, " SQ = %d\n", sinfo.signal); 11929eb82d43SVladimir Kondratiev } 11939eb82d43SVladimir Kondratiev } 11949eb82d43SVladimir Kondratiev 11959eb82d43SVladimir Kondratiev return 0; 11969eb82d43SVladimir Kondratiev } 11979eb82d43SVladimir Kondratiev 11989eb82d43SVladimir Kondratiev static int wil_link_seq_open(struct inode *inode, struct file *file) 11999eb82d43SVladimir Kondratiev { 12009eb82d43SVladimir Kondratiev return single_open(file, wil_link_debugfs_show, inode->i_private); 12019eb82d43SVladimir Kondratiev } 12029eb82d43SVladimir Kondratiev 12039eb82d43SVladimir Kondratiev static const struct file_operations fops_link = { 12049eb82d43SVladimir Kondratiev .open = wil_link_seq_open, 12059eb82d43SVladimir Kondratiev .release = single_release, 12069eb82d43SVladimir Kondratiev .read = seq_read, 12079eb82d43SVladimir Kondratiev .llseek = seq_lseek, 12089eb82d43SVladimir Kondratiev }; 12099eb82d43SVladimir Kondratiev 121084bb29b7SVladimir Kondratiev /*---------info------------*/ 121184bb29b7SVladimir Kondratiev static int wil_info_debugfs_show(struct seq_file *s, void *data) 121284bb29b7SVladimir Kondratiev { 1213be299858SVladimir Kondratiev struct wil6210_priv *wil = s->private; 1214be299858SVladimir Kondratiev struct net_device *ndev = wil_to_ndev(wil); 121584bb29b7SVladimir Kondratiev int is_ac = power_supply_is_system_supplied(); 1216be299858SVladimir Kondratiev int rx = atomic_xchg(&wil->isr_count_rx, 0); 1217be299858SVladimir Kondratiev int tx = atomic_xchg(&wil->isr_count_tx, 0); 1218be299858SVladimir Kondratiev static ulong rxf_old, txf_old; 1219be299858SVladimir Kondratiev ulong rxf = ndev->stats.rx_packets; 1220be299858SVladimir Kondratiev ulong txf = ndev->stats.tx_packets; 122155f8f680SVladimir Kondratiev unsigned int i; 122284bb29b7SVladimir Kondratiev 122384bb29b7SVladimir Kondratiev /* >0 : AC; 0 : battery; <0 : error */ 122484bb29b7SVladimir Kondratiev seq_printf(s, "AC powered : %d\n", is_ac); 1225be299858SVladimir Kondratiev seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old); 1226be299858SVladimir Kondratiev seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old); 1227be299858SVladimir Kondratiev rxf_old = rxf; 1228be299858SVladimir Kondratiev txf_old = txf; 122984bb29b7SVladimir Kondratiev 123055f8f680SVladimir Kondratiev #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \ 123155f8f680SVladimir Kondratiev " " __stringify(x) : "" 123255f8f680SVladimir Kondratiev 123355f8f680SVladimir Kondratiev for (i = 0; i < ndev->num_tx_queues; i++) { 123455f8f680SVladimir Kondratiev struct netdev_queue *txq = netdev_get_tx_queue(ndev, i); 123555f8f680SVladimir Kondratiev unsigned long state = txq->state; 123655f8f680SVladimir Kondratiev 123755f8f680SVladimir Kondratiev seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state, 123855f8f680SVladimir Kondratiev CHECK_QSTATE(DRV_XOFF), 123955f8f680SVladimir Kondratiev CHECK_QSTATE(STACK_XOFF), 124055f8f680SVladimir Kondratiev CHECK_QSTATE(FROZEN) 124155f8f680SVladimir Kondratiev ); 124255f8f680SVladimir Kondratiev } 124355f8f680SVladimir Kondratiev #undef CHECK_QSTATE 124484bb29b7SVladimir Kondratiev return 0; 124584bb29b7SVladimir Kondratiev } 124684bb29b7SVladimir Kondratiev 124784bb29b7SVladimir Kondratiev static int wil_info_seq_open(struct inode *inode, struct file *file) 124884bb29b7SVladimir Kondratiev { 124984bb29b7SVladimir Kondratiev return single_open(file, wil_info_debugfs_show, inode->i_private); 125084bb29b7SVladimir Kondratiev } 125184bb29b7SVladimir Kondratiev 125284bb29b7SVladimir Kondratiev static const struct file_operations fops_info = { 125384bb29b7SVladimir Kondratiev .open = wil_info_seq_open, 125484bb29b7SVladimir Kondratiev .release = single_release, 125584bb29b7SVladimir Kondratiev .read = seq_read, 125684bb29b7SVladimir Kondratiev .llseek = seq_lseek, 125784bb29b7SVladimir Kondratiev }; 125884bb29b7SVladimir Kondratiev 1259c33407a8SVladimir Kondratiev /*---------recovery------------*/ 1260c33407a8SVladimir Kondratiev /* mode = [manual|auto] 1261c33407a8SVladimir Kondratiev * state = [idle|pending|running] 1262c33407a8SVladimir Kondratiev */ 1263c33407a8SVladimir Kondratiev static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf, 1264c33407a8SVladimir Kondratiev size_t count, loff_t *ppos) 1265c33407a8SVladimir Kondratiev { 1266c33407a8SVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 1267c33407a8SVladimir Kondratiev char buf[80]; 1268c33407a8SVladimir Kondratiev int n; 1269c33407a8SVladimir Kondratiev static const char * const sstate[] = {"idle", "pending", "running"}; 1270c33407a8SVladimir Kondratiev 1271c33407a8SVladimir Kondratiev n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n", 1272c33407a8SVladimir Kondratiev no_fw_recovery ? "manual" : "auto", 1273c33407a8SVladimir Kondratiev sstate[wil->recovery_state]); 1274c33407a8SVladimir Kondratiev 1275c33407a8SVladimir Kondratiev n = min_t(int, n, sizeof(buf)); 1276c33407a8SVladimir Kondratiev 1277c33407a8SVladimir Kondratiev return simple_read_from_buffer(user_buf, count, ppos, 1278c33407a8SVladimir Kondratiev buf, n); 1279c33407a8SVladimir Kondratiev } 1280c33407a8SVladimir Kondratiev 1281c33407a8SVladimir Kondratiev static ssize_t wil_write_file_recovery(struct file *file, 1282c33407a8SVladimir Kondratiev const char __user *buf_, 1283c33407a8SVladimir Kondratiev size_t count, loff_t *ppos) 1284c33407a8SVladimir Kondratiev { 1285c33407a8SVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 1286c33407a8SVladimir Kondratiev static const char run_command[] = "run"; 1287c33407a8SVladimir Kondratiev char buf[sizeof(run_command) + 1]; /* to detect "runx" */ 1288c33407a8SVladimir Kondratiev ssize_t rc; 1289c33407a8SVladimir Kondratiev 1290c33407a8SVladimir Kondratiev if (wil->recovery_state != fw_recovery_pending) { 1291c33407a8SVladimir Kondratiev wil_err(wil, "No recovery pending\n"); 1292c33407a8SVladimir Kondratiev return -EINVAL; 1293c33407a8SVladimir Kondratiev } 1294c33407a8SVladimir Kondratiev 1295c33407a8SVladimir Kondratiev if (*ppos != 0) { 1296c33407a8SVladimir Kondratiev wil_err(wil, "Offset [%d]\n", (int)*ppos); 1297c33407a8SVladimir Kondratiev return -EINVAL; 1298c33407a8SVladimir Kondratiev } 1299c33407a8SVladimir Kondratiev 1300c33407a8SVladimir Kondratiev if (count > sizeof(buf)) { 1301c33407a8SVladimir Kondratiev wil_err(wil, "Input too long, len = %d\n", (int)count); 1302c33407a8SVladimir Kondratiev return -EINVAL; 1303c33407a8SVladimir Kondratiev } 1304c33407a8SVladimir Kondratiev 1305c33407a8SVladimir Kondratiev rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count); 1306c33407a8SVladimir Kondratiev if (rc < 0) 1307c33407a8SVladimir Kondratiev return rc; 1308c33407a8SVladimir Kondratiev 1309c33407a8SVladimir Kondratiev buf[rc] = '\0'; 1310c33407a8SVladimir Kondratiev if (0 == strcmp(buf, run_command)) 1311c33407a8SVladimir Kondratiev wil_set_recovery_state(wil, fw_recovery_running); 1312c33407a8SVladimir Kondratiev else 1313c33407a8SVladimir Kondratiev wil_err(wil, "Bad recovery command \"%s\"\n", buf); 1314c33407a8SVladimir Kondratiev 1315c33407a8SVladimir Kondratiev return rc; 1316c33407a8SVladimir Kondratiev } 1317c33407a8SVladimir Kondratiev 1318c33407a8SVladimir Kondratiev static const struct file_operations fops_recovery = { 1319c33407a8SVladimir Kondratiev .read = wil_read_file_recovery, 1320c33407a8SVladimir Kondratiev .write = wil_write_file_recovery, 1321c33407a8SVladimir Kondratiev .open = simple_open, 1322c33407a8SVladimir Kondratiev }; 1323c33407a8SVladimir Kondratiev 13243df2cd36SVladimir Kondratiev /*---------Station matrix------------*/ 1325b4490f42SVladimir Kondratiev static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r) 1326b4490f42SVladimir Kondratiev { 1327b4490f42SVladimir Kondratiev int i; 1328b4490f42SVladimir Kondratiev u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size; 132991a8edccSVladimir Kondratiev unsigned long long drop_dup = r->drop_dup, drop_old = r->drop_old; 13308fe59627SVladimir Kondratiev 133156637e7bSVladimir Kondratiev seq_printf(s, "([%2d] %3d TU) 0x%03x [", r->buf_size, r->timeout, 133256637e7bSVladimir Kondratiev r->head_seq_num); 1333b4490f42SVladimir Kondratiev for (i = 0; i < r->buf_size; i++) { 1334b4490f42SVladimir Kondratiev if (i == index) 1335b4490f42SVladimir Kondratiev seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|'); 1336b4490f42SVladimir Kondratiev else 1337b4490f42SVladimir Kondratiev seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_'); 1338b4490f42SVladimir Kondratiev } 133991a8edccSVladimir Kondratiev seq_printf(s, 134091a8edccSVladimir Kondratiev "] total %llu drop %llu (dup %llu + old %llu) last 0x%03x\n", 134191a8edccSVladimir Kondratiev r->total, drop_dup + drop_old, drop_dup, drop_old, 134291a8edccSVladimir Kondratiev r->ssn_last_drop); 1343b4490f42SVladimir Kondratiev } 13443df2cd36SVladimir Kondratiev 134558527421SVladimir Kondratiev static void wil_print_rxtid_crypto(struct seq_file *s, int tid, 134658527421SVladimir Kondratiev struct wil_tid_crypto_rx *c) 134758527421SVladimir Kondratiev { 134858527421SVladimir Kondratiev int i; 134958527421SVladimir Kondratiev 135058527421SVladimir Kondratiev for (i = 0; i < 4; i++) { 135158527421SVladimir Kondratiev struct wil_tid_crypto_rx_single *cc = &c->key_id[i]; 135258527421SVladimir Kondratiev 135358527421SVladimir Kondratiev if (cc->key_set) 135458527421SVladimir Kondratiev goto has_keys; 135558527421SVladimir Kondratiev } 135658527421SVladimir Kondratiev return; 135758527421SVladimir Kondratiev 135858527421SVladimir Kondratiev has_keys: 135958527421SVladimir Kondratiev if (tid < WIL_STA_TID_NUM) 136058527421SVladimir Kondratiev seq_printf(s, " [%2d] PN", tid); 136158527421SVladimir Kondratiev else 136258527421SVladimir Kondratiev seq_puts(s, " [GR] PN"); 136358527421SVladimir Kondratiev 136458527421SVladimir Kondratiev for (i = 0; i < 4; i++) { 136558527421SVladimir Kondratiev struct wil_tid_crypto_rx_single *cc = &c->key_id[i]; 136658527421SVladimir Kondratiev 136758527421SVladimir Kondratiev seq_printf(s, " [%i%s]%6phN", i, cc->key_set ? "+" : "-", 136858527421SVladimir Kondratiev cc->pn); 136958527421SVladimir Kondratiev } 137058527421SVladimir Kondratiev seq_puts(s, "\n"); 137158527421SVladimir Kondratiev } 137258527421SVladimir Kondratiev 13733df2cd36SVladimir Kondratiev static int wil_sta_debugfs_show(struct seq_file *s, void *data) 1374bd33273bSVladimir Kondratiev __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock) 13753df2cd36SVladimir Kondratiev { 13763df2cd36SVladimir Kondratiev struct wil6210_priv *wil = s->private; 1377c4a110d8SVladimir Kondratiev int i, tid, mcs; 13783df2cd36SVladimir Kondratiev 13793df2cd36SVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(wil->sta); i++) { 13803df2cd36SVladimir Kondratiev struct wil_sta_info *p = &wil->sta[i]; 13813df2cd36SVladimir Kondratiev char *status = "unknown"; 13828fe59627SVladimir Kondratiev 13833df2cd36SVladimir Kondratiev switch (p->status) { 13843df2cd36SVladimir Kondratiev case wil_sta_unused: 13853df2cd36SVladimir Kondratiev status = "unused "; 13863df2cd36SVladimir Kondratiev break; 13873df2cd36SVladimir Kondratiev case wil_sta_conn_pending: 13883df2cd36SVladimir Kondratiev status = "pending "; 13893df2cd36SVladimir Kondratiev break; 13903df2cd36SVladimir Kondratiev case wil_sta_connected: 13913df2cd36SVladimir Kondratiev status = "connected"; 13923df2cd36SVladimir Kondratiev break; 13933df2cd36SVladimir Kondratiev } 1394230d8442SVladimir Kondratiev seq_printf(s, "[%d] %pM %s\n", i, p->addr, status); 1395b4490f42SVladimir Kondratiev 1396b4490f42SVladimir Kondratiev if (p->status == wil_sta_connected) { 1397bd33273bSVladimir Kondratiev spin_lock_bh(&p->tid_rx_lock); 1398b4490f42SVladimir Kondratiev for (tid = 0; tid < WIL_STA_TID_NUM; tid++) { 1399b4490f42SVladimir Kondratiev struct wil_tid_ampdu_rx *r = p->tid_rx[tid]; 140058527421SVladimir Kondratiev struct wil_tid_crypto_rx *c = 140158527421SVladimir Kondratiev &p->tid_crypto_rx[tid]; 14028fe59627SVladimir Kondratiev 1403b4490f42SVladimir Kondratiev if (r) { 1404b4490f42SVladimir Kondratiev seq_printf(s, " [%2d] ", tid); 1405b4490f42SVladimir Kondratiev wil_print_rxtid(s, r); 1406b4490f42SVladimir Kondratiev } 140758527421SVladimir Kondratiev 140858527421SVladimir Kondratiev wil_print_rxtid_crypto(s, tid, c); 1409b4490f42SVladimir Kondratiev } 141058527421SVladimir Kondratiev wil_print_rxtid_crypto(s, WIL_STA_TID_NUM, 141158527421SVladimir Kondratiev &p->group_crypto_rx); 1412bd33273bSVladimir Kondratiev spin_unlock_bh(&p->tid_rx_lock); 14133b282bc6SVladimir Kondratiev seq_printf(s, 141458527421SVladimir Kondratiev "Rx invalid frame: non-data %lu, short %lu, large %lu, replay %lu\n", 14153b282bc6SVladimir Kondratiev p->stats.rx_non_data_frame, 14163b282bc6SVladimir Kondratiev p->stats.rx_short_frame, 141758527421SVladimir Kondratiev p->stats.rx_large_frame, 141858527421SVladimir Kondratiev p->stats.rx_replay); 14193b282bc6SVladimir Kondratiev 1420c4a110d8SVladimir Kondratiev seq_puts(s, "Rx/MCS:"); 1421c4a110d8SVladimir Kondratiev for (mcs = 0; mcs < ARRAY_SIZE(p->stats.rx_per_mcs); 1422c4a110d8SVladimir Kondratiev mcs++) 1423c4a110d8SVladimir Kondratiev seq_printf(s, " %lld", 1424c4a110d8SVladimir Kondratiev p->stats.rx_per_mcs[mcs]); 1425c4a110d8SVladimir Kondratiev seq_puts(s, "\n"); 1426b4490f42SVladimir Kondratiev } 14273df2cd36SVladimir Kondratiev } 14283df2cd36SVladimir Kondratiev 14293df2cd36SVladimir Kondratiev return 0; 14303df2cd36SVladimir Kondratiev } 14313df2cd36SVladimir Kondratiev 14323df2cd36SVladimir Kondratiev static int wil_sta_seq_open(struct inode *inode, struct file *file) 14333df2cd36SVladimir Kondratiev { 14343df2cd36SVladimir Kondratiev return single_open(file, wil_sta_debugfs_show, inode->i_private); 14353df2cd36SVladimir Kondratiev } 14363df2cd36SVladimir Kondratiev 14373df2cd36SVladimir Kondratiev static const struct file_operations fops_sta = { 14383df2cd36SVladimir Kondratiev .open = wil_sta_seq_open, 14393df2cd36SVladimir Kondratiev .release = single_release, 14403df2cd36SVladimir Kondratiev .read = seq_read, 14413df2cd36SVladimir Kondratiev .llseek = seq_lseek, 14423df2cd36SVladimir Kondratiev }; 14433df2cd36SVladimir Kondratiev 144410d599adSMaya Erez static ssize_t wil_read_file_led_cfg(struct file *file, char __user *user_buf, 144510d599adSMaya Erez size_t count, loff_t *ppos) 144610d599adSMaya Erez { 144710d599adSMaya Erez char buf[80]; 144810d599adSMaya Erez int n; 144910d599adSMaya Erez 145010d599adSMaya Erez n = snprintf(buf, sizeof(buf), 145110d599adSMaya Erez "led_id is set to %d, echo 1 to enable, 0 to disable\n", 145210d599adSMaya Erez led_id); 145310d599adSMaya Erez 145410d599adSMaya Erez n = min_t(int, n, sizeof(buf)); 145510d599adSMaya Erez 145610d599adSMaya Erez return simple_read_from_buffer(user_buf, count, ppos, 145710d599adSMaya Erez buf, n); 145810d599adSMaya Erez } 145910d599adSMaya Erez 146010d599adSMaya Erez static ssize_t wil_write_file_led_cfg(struct file *file, 146110d599adSMaya Erez const char __user *buf_, 146210d599adSMaya Erez size_t count, loff_t *ppos) 146310d599adSMaya Erez { 146410d599adSMaya Erez struct wil6210_priv *wil = file->private_data; 146510d599adSMaya Erez int val; 146610d599adSMaya Erez int rc; 146710d599adSMaya Erez 146810d599adSMaya Erez rc = kstrtoint_from_user(buf_, count, 0, &val); 146910d599adSMaya Erez if (rc) { 147010d599adSMaya Erez wil_err(wil, "Invalid argument\n"); 147110d599adSMaya Erez return rc; 147210d599adSMaya Erez } 147310d599adSMaya Erez 147410d599adSMaya Erez wil_info(wil, "%s led %d\n", val ? "Enabling" : "Disabling", led_id); 147510d599adSMaya Erez rc = wmi_led_cfg(wil, val); 147610d599adSMaya Erez if (rc) { 147710d599adSMaya Erez wil_info(wil, "%s led %d failed\n", 147810d599adSMaya Erez val ? "Enabling" : "Disabling", led_id); 147910d599adSMaya Erez return rc; 148010d599adSMaya Erez } 148110d599adSMaya Erez 148210d599adSMaya Erez return count; 148310d599adSMaya Erez } 148410d599adSMaya Erez 148510d599adSMaya Erez static const struct file_operations fops_led_cfg = { 148610d599adSMaya Erez .read = wil_read_file_led_cfg, 148710d599adSMaya Erez .write = wil_write_file_led_cfg, 148810d599adSMaya Erez .open = simple_open, 148910d599adSMaya Erez }; 149010d599adSMaya Erez 149110d599adSMaya Erez /* led_blink_time, write: 149210d599adSMaya Erez * "<blink_on_slow> <blink_off_slow> <blink_on_med> <blink_off_med> <blink_on_fast> <blink_off_fast> 149310d599adSMaya Erez */ 149410d599adSMaya Erez static ssize_t wil_write_led_blink_time(struct file *file, 149510d599adSMaya Erez const char __user *buf, 149610d599adSMaya Erez size_t len, loff_t *ppos) 149710d599adSMaya Erez { 149810d599adSMaya Erez int rc; 149910d599adSMaya Erez char *kbuf = kmalloc(len + 1, GFP_KERNEL); 150010d599adSMaya Erez 150110d599adSMaya Erez if (!kbuf) 150210d599adSMaya Erez return -ENOMEM; 150310d599adSMaya Erez 150410d599adSMaya Erez rc = simple_write_to_buffer(kbuf, len, ppos, buf, len); 150510d599adSMaya Erez if (rc != len) { 150610d599adSMaya Erez kfree(kbuf); 150710d599adSMaya Erez return rc >= 0 ? -EIO : rc; 150810d599adSMaya Erez } 150910d599adSMaya Erez 151010d599adSMaya Erez kbuf[len] = '\0'; 151110d599adSMaya Erez rc = sscanf(kbuf, "%d %d %d %d %d %d", 151210d599adSMaya Erez &led_blink_time[WIL_LED_TIME_SLOW].on_ms, 151310d599adSMaya Erez &led_blink_time[WIL_LED_TIME_SLOW].off_ms, 151410d599adSMaya Erez &led_blink_time[WIL_LED_TIME_MED].on_ms, 151510d599adSMaya Erez &led_blink_time[WIL_LED_TIME_MED].off_ms, 151610d599adSMaya Erez &led_blink_time[WIL_LED_TIME_FAST].on_ms, 151710d599adSMaya Erez &led_blink_time[WIL_LED_TIME_FAST].off_ms); 151810d599adSMaya Erez kfree(kbuf); 151910d599adSMaya Erez 152010d599adSMaya Erez if (rc < 0) 152110d599adSMaya Erez return rc; 152210d599adSMaya Erez if (rc < 6) 152310d599adSMaya Erez return -EINVAL; 152410d599adSMaya Erez 152510d599adSMaya Erez return len; 152610d599adSMaya Erez } 152710d599adSMaya Erez 152810d599adSMaya Erez static ssize_t wil_read_led_blink_time(struct file *file, char __user *user_buf, 152910d599adSMaya Erez size_t count, loff_t *ppos) 153010d599adSMaya Erez { 153110d599adSMaya Erez static char text[400]; 153210d599adSMaya Erez 153310d599adSMaya Erez snprintf(text, sizeof(text), 153410d599adSMaya Erez "To set led blink on/off time variables write:\n" 153510d599adSMaya Erez "<blink_on_slow> <blink_off_slow> <blink_on_med> " 153610d599adSMaya Erez "<blink_off_med> <blink_on_fast> <blink_off_fast>\n" 153710d599adSMaya Erez "The current values are:\n" 153810d599adSMaya Erez "%d %d %d %d %d %d\n", 153910d599adSMaya Erez led_blink_time[WIL_LED_TIME_SLOW].on_ms, 154010d599adSMaya Erez led_blink_time[WIL_LED_TIME_SLOW].off_ms, 154110d599adSMaya Erez led_blink_time[WIL_LED_TIME_MED].on_ms, 154210d599adSMaya Erez led_blink_time[WIL_LED_TIME_MED].off_ms, 154310d599adSMaya Erez led_blink_time[WIL_LED_TIME_FAST].on_ms, 154410d599adSMaya Erez led_blink_time[WIL_LED_TIME_FAST].off_ms); 154510d599adSMaya Erez 154610d599adSMaya Erez return simple_read_from_buffer(user_buf, count, ppos, text, 154710d599adSMaya Erez sizeof(text)); 154810d599adSMaya Erez } 154910d599adSMaya Erez 155010d599adSMaya Erez static const struct file_operations fops_led_blink_time = { 155110d599adSMaya Erez .read = wil_read_led_blink_time, 155210d599adSMaya Erez .write = wil_write_led_blink_time, 155310d599adSMaya Erez .open = simple_open, 155410d599adSMaya Erez }; 155510d599adSMaya Erez 155612bace75SLior David /*---------FW capabilities------------*/ 155712bace75SLior David static int wil_fw_capabilities_debugfs_show(struct seq_file *s, void *data) 155812bace75SLior David { 155912bace75SLior David struct wil6210_priv *wil = s->private; 156012bace75SLior David 156112bace75SLior David seq_printf(s, "fw_capabilities : %*pb\n", WMI_FW_CAPABILITY_MAX, 156212bace75SLior David wil->fw_capabilities); 156312bace75SLior David 156412bace75SLior David return 0; 156512bace75SLior David } 156612bace75SLior David 156712bace75SLior David static int wil_fw_capabilities_seq_open(struct inode *inode, struct file *file) 156812bace75SLior David { 156912bace75SLior David return single_open(file, wil_fw_capabilities_debugfs_show, 157012bace75SLior David inode->i_private); 157112bace75SLior David } 157212bace75SLior David 157312bace75SLior David static const struct file_operations fops_fw_capabilities = { 157412bace75SLior David .open = wil_fw_capabilities_seq_open, 157512bace75SLior David .release = single_release, 157612bace75SLior David .read = seq_read, 157712bace75SLior David .llseek = seq_lseek, 157812bace75SLior David }; 157912bace75SLior David 158013cd9f75SLior David /*---------FW version------------*/ 158113cd9f75SLior David static int wil_fw_version_debugfs_show(struct seq_file *s, void *data) 158213cd9f75SLior David { 158313cd9f75SLior David struct wil6210_priv *wil = s->private; 158413cd9f75SLior David 158513cd9f75SLior David if (wil->fw_version[0]) 158613cd9f75SLior David seq_printf(s, "%s\n", wil->fw_version); 158713cd9f75SLior David else 158813cd9f75SLior David seq_puts(s, "N/A\n"); 158913cd9f75SLior David 159013cd9f75SLior David return 0; 159113cd9f75SLior David } 159213cd9f75SLior David 159313cd9f75SLior David static int wil_fw_version_seq_open(struct inode *inode, struct file *file) 159413cd9f75SLior David { 159513cd9f75SLior David return single_open(file, wil_fw_version_debugfs_show, 159613cd9f75SLior David inode->i_private); 159713cd9f75SLior David } 159813cd9f75SLior David 159913cd9f75SLior David static const struct file_operations fops_fw_version = { 160013cd9f75SLior David .open = wil_fw_version_seq_open, 160113cd9f75SLior David .release = single_release, 160213cd9f75SLior David .read = seq_read, 160313cd9f75SLior David .llseek = seq_lseek, 160413cd9f75SLior David }; 160513cd9f75SLior David 16062be7d22fSVladimir Kondratiev /*----------------*/ 1607b541d0a0SVladimir Kondratiev static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil, 1608b541d0a0SVladimir Kondratiev struct dentry *dbg) 1609b541d0a0SVladimir Kondratiev { 1610b541d0a0SVladimir Kondratiev int i; 1611b541d0a0SVladimir Kondratiev char name[32]; 1612b541d0a0SVladimir Kondratiev 1613b541d0a0SVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) { 1614349214c1SMaya Erez struct wil_blob_wrapper *wil_blob = &wil->blobs[i]; 1615349214c1SMaya Erez struct debugfs_blob_wrapper *blob = &wil_blob->blob; 1616b541d0a0SVladimir Kondratiev const struct fw_map *map = &fw_mapping[i]; 1617b541d0a0SVladimir Kondratiev 1618b541d0a0SVladimir Kondratiev if (!map->name) 1619b541d0a0SVladimir Kondratiev continue; 1620b541d0a0SVladimir Kondratiev 1621349214c1SMaya Erez wil_blob->wil = wil; 1622b541d0a0SVladimir Kondratiev blob->data = (void * __force)wil->csr + HOSTADDR(map->host); 1623b541d0a0SVladimir Kondratiev blob->size = map->to - map->from; 1624b541d0a0SVladimir Kondratiev snprintf(name, sizeof(name), "blob_%s", map->name); 1625349214c1SMaya Erez wil_debugfs_create_ioblob(name, S_IRUGO, dbg, wil_blob); 1626b541d0a0SVladimir Kondratiev } 1627b541d0a0SVladimir Kondratiev } 1628b541d0a0SVladimir Kondratiev 1629b7cde470SVladimir Kondratiev /* misc files */ 1630b7cde470SVladimir Kondratiev static const struct { 1631b7cde470SVladimir Kondratiev const char *name; 1632b7cde470SVladimir Kondratiev umode_t mode; 1633b7cde470SVladimir Kondratiev const struct file_operations *fops; 1634b7cde470SVladimir Kondratiev } dbg_files[] = { 1635b7cde470SVladimir Kondratiev {"mbox", S_IRUGO, &fops_mbox}, 1636b7cde470SVladimir Kondratiev {"vrings", S_IRUGO, &fops_vring}, 1637b7cde470SVladimir Kondratiev {"stations", S_IRUGO, &fops_sta}, 1638b7cde470SVladimir Kondratiev {"desc", S_IRUGO, &fops_txdesc}, 1639b7cde470SVladimir Kondratiev {"bf", S_IRUGO, &fops_bf}, 1640b7cde470SVladimir Kondratiev {"ssid", S_IRUGO | S_IWUSR, &fops_ssid}, 1641b7cde470SVladimir Kondratiev {"mem_val", S_IRUGO, &fops_memread}, 1642b7cde470SVladimir Kondratiev {"reset", S_IWUSR, &fops_reset}, 1643b7cde470SVladimir Kondratiev {"rxon", S_IWUSR, &fops_rxon}, 1644b7cde470SVladimir Kondratiev {"tx_mgmt", S_IWUSR, &fops_txmgmt}, 1645b7cde470SVladimir Kondratiev {"wmi_send", S_IWUSR, &fops_wmi}, 164649cb5dfbSVladimir Kondratiev {"back", S_IRUGO | S_IWUSR, &fops_back}, 1647dc16427bSVladimir Kondratiev {"pmccfg", S_IRUGO | S_IWUSR, &fops_pmccfg}, 1648dc16427bSVladimir Kondratiev {"pmcdata", S_IRUGO, &fops_pmcdata}, 1649b7cde470SVladimir Kondratiev {"temp", S_IRUGO, &fops_temp}, 1650b7cde470SVladimir Kondratiev {"freq", S_IRUGO, &fops_freq}, 1651b7cde470SVladimir Kondratiev {"link", S_IRUGO, &fops_link}, 1652b7cde470SVladimir Kondratiev {"info", S_IRUGO, &fops_info}, 1653c33407a8SVladimir Kondratiev {"recovery", S_IRUGO | S_IWUSR, &fops_recovery}, 165410d599adSMaya Erez {"led_cfg", S_IRUGO | S_IWUSR, &fops_led_cfg}, 165510d599adSMaya Erez {"led_blink_time", S_IRUGO | S_IWUSR, &fops_led_blink_time}, 165612bace75SLior David {"fw_capabilities", S_IRUGO, &fops_fw_capabilities}, 165713cd9f75SLior David {"fw_version", S_IRUGO, &fops_fw_version}, 1658b7cde470SVladimir Kondratiev }; 1659b7cde470SVladimir Kondratiev 1660b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_files(struct wil6210_priv *wil, 1661b7cde470SVladimir Kondratiev struct dentry *dbg) 1662b7cde470SVladimir Kondratiev { 1663b7cde470SVladimir Kondratiev int i; 1664b7cde470SVladimir Kondratiev 1665b7cde470SVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(dbg_files); i++) 1666b7cde470SVladimir Kondratiev debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg, 1667b7cde470SVladimir Kondratiev wil, dbg_files[i].fops); 1668b7cde470SVladimir Kondratiev } 1669b7cde470SVladimir Kondratiev 1670b7cde470SVladimir Kondratiev /* interrupt control blocks */ 1671b7cde470SVladimir Kondratiev static const struct { 1672b7cde470SVladimir Kondratiev const char *name; 1673b7cde470SVladimir Kondratiev u32 icr_off; 1674b7cde470SVladimir Kondratiev } dbg_icr[] = { 1675b7cde470SVladimir Kondratiev {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)}, 1676b7cde470SVladimir Kondratiev {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)}, 1677b7cde470SVladimir Kondratiev {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)}, 1678b7cde470SVladimir Kondratiev {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)}, 1679b7cde470SVladimir Kondratiev }; 1680b7cde470SVladimir Kondratiev 1681b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_isr(struct wil6210_priv *wil, 1682b7cde470SVladimir Kondratiev struct dentry *dbg) 1683b7cde470SVladimir Kondratiev { 1684b7cde470SVladimir Kondratiev int i; 1685b7cde470SVladimir Kondratiev 1686b7cde470SVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(dbg_icr); i++) 1687b7cde470SVladimir Kondratiev wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg, 1688b7cde470SVladimir Kondratiev dbg_icr[i].icr_off); 1689b7cde470SVladimir Kondratiev } 1690b7cde470SVladimir Kondratiev 1691b7cde470SVladimir Kondratiev #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \ 1692b7cde470SVladimir Kondratiev offsetof(struct wil6210_priv, name), type} 1693b7cde470SVladimir Kondratiev 1694b7cde470SVladimir Kondratiev /* fields in struct wil6210_priv */ 1695b7cde470SVladimir Kondratiev static const struct dbg_off dbg_wil_off[] = { 1696774974e5SVladimir Kondratiev WIL_FIELD(privacy, S_IRUGO, doff_u32), 16979419b6a2SVladimir Kondratiev WIL_FIELD(status[0], S_IRUGO | S_IWUSR, doff_ulong), 1698b7cde470SVladimir Kondratiev WIL_FIELD(hw_version, S_IRUGO, doff_x32), 1699c33407a8SVladimir Kondratiev WIL_FIELD(recovery_count, S_IRUGO, doff_u32), 170002beaf1aSVladimir Kondratiev WIL_FIELD(ap_isolate, S_IRUGO, doff_u32), 170174997a53SLior David WIL_FIELD(discovery_mode, S_IRUGO | S_IWUSR, doff_u8), 1702a351f2f5SLazar Alexei WIL_FIELD(chip_revision, S_IRUGO, doff_u8), 1703b7cde470SVladimir Kondratiev {}, 1704b7cde470SVladimir Kondratiev }; 1705b7cde470SVladimir Kondratiev 1706b7cde470SVladimir Kondratiev static const struct dbg_off dbg_wil_regs[] = { 1707b7cde470SVladimir Kondratiev {"RGF_MAC_MTRL_COUNTER_0", S_IRUGO, HOSTADDR(RGF_MAC_MTRL_COUNTER_0), 1708b7cde470SVladimir Kondratiev doff_io32}, 1709b7cde470SVladimir Kondratiev {"RGF_USER_USAGE_1", S_IRUGO, HOSTADDR(RGF_USER_USAGE_1), doff_io32}, 1710b7cde470SVladimir Kondratiev {}, 1711b7cde470SVladimir Kondratiev }; 1712b7cde470SVladimir Kondratiev 1713b7cde470SVladimir Kondratiev /* static parameters */ 1714b7cde470SVladimir Kondratiev static const struct dbg_off dbg_statics[] = { 1715b7cde470SVladimir Kondratiev {"desc_index", S_IRUGO | S_IWUSR, (ulong)&dbg_txdesc_index, doff_u32}, 1716b7cde470SVladimir Kondratiev {"vring_index", S_IRUGO | S_IWUSR, (ulong)&dbg_vring_index, doff_u32}, 1717b7cde470SVladimir Kondratiev {"mem_addr", S_IRUGO | S_IWUSR, (ulong)&mem_addr, doff_u32}, 17180436fd9aSVladimir Shulman {"vring_idle_trsh", S_IRUGO | S_IWUSR, (ulong)&vring_idle_trsh, 17190436fd9aSVladimir Shulman doff_u32}, 172010d599adSMaya Erez {"led_polarity", S_IRUGO | S_IWUSR, (ulong)&led_polarity, doff_u8}, 1721b7cde470SVladimir Kondratiev {}, 1722b7cde470SVladimir Kondratiev }; 1723b7cde470SVladimir Kondratiev 17242be7d22fSVladimir Kondratiev int wil6210_debugfs_init(struct wil6210_priv *wil) 17252be7d22fSVladimir Kondratiev { 17262be7d22fSVladimir Kondratiev struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME, 17272be7d22fSVladimir Kondratiev wil_to_wiphy(wil)->debugfsdir); 17282be7d22fSVladimir Kondratiev 17292be7d22fSVladimir Kondratiev if (IS_ERR_OR_NULL(dbg)) 17302be7d22fSVladimir Kondratiev return -ENODEV; 17312be7d22fSVladimir Kondratiev 1732dc16427bSVladimir Kondratiev wil_pmc_init(wil); 1733dc16427bSVladimir Kondratiev 1734b7cde470SVladimir Kondratiev wil6210_debugfs_init_files(wil, dbg); 1735b7cde470SVladimir Kondratiev wil6210_debugfs_init_isr(wil, dbg); 1736b541d0a0SVladimir Kondratiev wil6210_debugfs_init_blobs(wil, dbg); 1737b7cde470SVladimir Kondratiev wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off); 1738b7cde470SVladimir Kondratiev wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr, 1739b7cde470SVladimir Kondratiev dbg_wil_regs); 1740b7cde470SVladimir Kondratiev wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics); 1741b7cde470SVladimir Kondratiev 1742b7cde470SVladimir Kondratiev wil6210_debugfs_create_pseudo_ISR(wil, dbg); 1743b7cde470SVladimir Kondratiev 1744b7cde470SVladimir Kondratiev wil6210_debugfs_create_ITR_CNT(wil, dbg); 17452be7d22fSVladimir Kondratiev 17462be7d22fSVladimir Kondratiev return 0; 17472be7d22fSVladimir Kondratiev } 17482be7d22fSVladimir Kondratiev 17492be7d22fSVladimir Kondratiev void wil6210_debugfs_remove(struct wil6210_priv *wil) 17502be7d22fSVladimir Kondratiev { 17512be7d22fSVladimir Kondratiev debugfs_remove_recursive(wil->debug); 17522be7d22fSVladimir Kondratiev wil->debug = NULL; 1753dc16427bSVladimir Kondratiev 1754dc16427bSVladimir Kondratiev /* free pmc memory without sending command to fw, as it will 1755dc16427bSVladimir Kondratiev * be reset on the way down anyway 1756dc16427bSVladimir Kondratiev */ 1757dc16427bSVladimir Kondratiev wil_pmc_free(wil, false); 17582be7d22fSVladimir Kondratiev } 1759