12be7d22fSVladimir Kondratiev /* 2a351f2f5SLazar Alexei * Copyright (c) 2012-2017 Qualcomm Atheros, Inc. 30439a5e0SDedy Lansky * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved. 42be7d22fSVladimir Kondratiev * 52be7d22fSVladimir Kondratiev * Permission to use, copy, modify, and/or distribute this software for any 62be7d22fSVladimir Kondratiev * purpose with or without fee is hereby granted, provided that the above 72be7d22fSVladimir Kondratiev * copyright notice and this permission notice appear in all copies. 82be7d22fSVladimir Kondratiev * 92be7d22fSVladimir Kondratiev * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 102be7d22fSVladimir Kondratiev * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 112be7d22fSVladimir Kondratiev * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 122be7d22fSVladimir Kondratiev * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 132be7d22fSVladimir Kondratiev * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 142be7d22fSVladimir Kondratiev * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 152be7d22fSVladimir Kondratiev * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 162be7d22fSVladimir Kondratiev */ 172be7d22fSVladimir Kondratiev 182be7d22fSVladimir Kondratiev #include <linux/module.h> 192be7d22fSVladimir Kondratiev #include <linux/debugfs.h> 202be7d22fSVladimir Kondratiev #include <linux/seq_file.h> 212be7d22fSVladimir Kondratiev #include <linux/pci.h> 222be7d22fSVladimir Kondratiev #include <linux/rtnetlink.h> 2384bb29b7SVladimir Kondratiev #include <linux/power_supply.h> 242be7d22fSVladimir Kondratiev #include "wil6210.h" 2536345ac3SVladimir Kondratiev #include "wmi.h" 262be7d22fSVladimir Kondratiev #include "txrx.h" 27dc16427bSVladimir Kondratiev #include "pmc.h" 282be7d22fSVladimir Kondratiev 292be7d22fSVladimir Kondratiev /* Nasty hack. Better have per device instances */ 302be7d22fSVladimir Kondratiev static u32 mem_addr; 312be7d22fSVladimir Kondratiev static u32 dbg_txdesc_index; 3210590c6aSGidon Studinski static u32 dbg_ring_index; /* 24+ for Rx, 0..23 for Tx */ 33d98b8539SMaya Erez static u32 dbg_status_msg_index; 34d98b8539SMaya Erez /* 0..wil->num_rx_status_rings-1 for Rx, wil->tx_sring_idx for Tx */ 35d98b8539SMaya Erez static u32 dbg_sring_index; 362be7d22fSVladimir Kondratiev 37b7cde470SVladimir Kondratiev enum dbg_off_type { 38b7cde470SVladimir Kondratiev doff_u32 = 0, 39b7cde470SVladimir Kondratiev doff_x32 = 1, 40b7cde470SVladimir Kondratiev doff_ulong = 2, 41b7cde470SVladimir Kondratiev doff_io32 = 3, 4274997a53SLior David doff_u8 = 4 43b7cde470SVladimir Kondratiev }; 44b7cde470SVladimir Kondratiev 45b7cde470SVladimir Kondratiev /* offset to "wil" */ 46b7cde470SVladimir Kondratiev struct dbg_off { 47b7cde470SVladimir Kondratiev const char *name; 48b7cde470SVladimir Kondratiev umode_t mode; 49b7cde470SVladimir Kondratiev ulong off; 50b7cde470SVladimir Kondratiev enum dbg_off_type type; 51b7cde470SVladimir Kondratiev }; 52b7cde470SVladimir Kondratiev 53d98b8539SMaya Erez static void wil_print_desc_edma(struct seq_file *s, struct wil6210_priv *wil, 54d98b8539SMaya Erez struct wil_ring *ring, 55d98b8539SMaya Erez char _s, char _h, int idx) 56d98b8539SMaya Erez { 57d98b8539SMaya Erez u8 num_of_descs; 58d98b8539SMaya Erez bool has_skb = false; 59d98b8539SMaya Erez 60d98b8539SMaya Erez if (ring->is_rx) { 61d98b8539SMaya Erez struct wil_rx_enhanced_desc *rx_d = 62d98b8539SMaya Erez (struct wil_rx_enhanced_desc *) 63d98b8539SMaya Erez &ring->va[idx].rx.enhanced; 64d98b8539SMaya Erez u16 buff_id = le16_to_cpu(rx_d->mac.buff_id); 65d98b8539SMaya Erez 669a874d04SDedy Lansky if (wil->rx_buff_mgmt.buff_arr && 679a874d04SDedy Lansky wil_val_in_range(buff_id, 0, wil->rx_buff_mgmt.size)) 68d98b8539SMaya Erez has_skb = wil->rx_buff_mgmt.buff_arr[buff_id].skb; 69d98b8539SMaya Erez seq_printf(s, "%c", (has_skb) ? _h : _s); 70d98b8539SMaya Erez } else { 71d98b8539SMaya Erez struct wil_tx_enhanced_desc *d = 72d98b8539SMaya Erez (struct wil_tx_enhanced_desc *) 73d98b8539SMaya Erez &ring->va[idx].tx.enhanced; 74d98b8539SMaya Erez 75d98b8539SMaya Erez num_of_descs = (u8)d->mac.d[2]; 769a874d04SDedy Lansky has_skb = ring->ctx && ring->ctx[idx].skb; 77d98b8539SMaya Erez if (num_of_descs >= 1) 789a874d04SDedy Lansky seq_printf(s, "%c", has_skb ? _h : _s); 79d98b8539SMaya Erez else 80d98b8539SMaya Erez /* num_of_descs == 0, it's a frag in a list of descs */ 81d98b8539SMaya Erez seq_printf(s, "%c", has_skb ? 'h' : _s); 82d98b8539SMaya Erez } 83d98b8539SMaya Erez } 84d98b8539SMaya Erez 8510590c6aSGidon Studinski static void wil_print_ring(struct seq_file *s, struct wil6210_priv *wil, 8610590c6aSGidon Studinski const char *name, struct wil_ring *ring, 8759f7c0a9SVladimir Kondratiev char _s, char _h) 882be7d22fSVladimir Kondratiev { 899a874d04SDedy Lansky void __iomem *x; 90995cdd0eSVladimir Kondratiev u32 v; 912be7d22fSVladimir Kondratiev 9210590c6aSGidon Studinski seq_printf(s, "RING %s = {\n", name); 9310590c6aSGidon Studinski seq_printf(s, " pa = %pad\n", &ring->pa); 9410590c6aSGidon Studinski seq_printf(s, " va = 0x%p\n", ring->va); 9510590c6aSGidon Studinski seq_printf(s, " size = %d\n", ring->size); 96d98b8539SMaya Erez if (wil->use_enhanced_dma_hw && ring->is_rx) 97d98b8539SMaya Erez seq_printf(s, " swtail = %u\n", *ring->edma_rx_swtail.va); 98d98b8539SMaya Erez else 9910590c6aSGidon Studinski seq_printf(s, " swtail = %d\n", ring->swtail); 10010590c6aSGidon Studinski seq_printf(s, " swhead = %d\n", ring->swhead); 1019a874d04SDedy Lansky if (wil->use_enhanced_dma_hw) { 1029a874d04SDedy Lansky int ring_id = ring->is_rx ? 1039a874d04SDedy Lansky WIL_RX_DESC_RING_ID : ring - wil->ring_tx; 1049a874d04SDedy Lansky /* SUBQ_CONS is a table of 32 entries, one for each Q pair. 1059a874d04SDedy Lansky * lower 16bits are for even ring_id and upper 16bits are for 1069a874d04SDedy Lansky * odd ring_id 1079a874d04SDedy Lansky */ 1089a874d04SDedy Lansky x = wmi_addr(wil, RGF_DMA_SCM_SUBQ_CONS + 4 * (ring_id / 2)); 1099a874d04SDedy Lansky v = readl_relaxed(x); 1109a874d04SDedy Lansky 1119a874d04SDedy Lansky v = (ring_id % 2 ? (v >> 16) : (v & 0xffff)); 1129a874d04SDedy Lansky seq_printf(s, " hwhead = %u\n", v); 1139a874d04SDedy Lansky } 11410590c6aSGidon Studinski seq_printf(s, " hwtail = [0x%08x] -> ", ring->hwtail); 1159a874d04SDedy Lansky x = wmi_addr(wil, ring->hwtail); 116995cdd0eSVladimir Kondratiev if (x) { 117b9eeb512SVladimir Kondratiev v = readl(x); 118995cdd0eSVladimir Kondratiev seq_printf(s, "0x%08x = %d\n", v, v); 119995cdd0eSVladimir Kondratiev } else { 1208fe59627SVladimir Kondratiev seq_puts(s, "???\n"); 121995cdd0eSVladimir Kondratiev } 1222be7d22fSVladimir Kondratiev 12310590c6aSGidon Studinski if (ring->va && (ring->size <= (1 << WIL_RING_SIZE_ORDER_MAX))) { 1242be7d22fSVladimir Kondratiev uint i; 1258fe59627SVladimir Kondratiev 12610590c6aSGidon Studinski for (i = 0; i < ring->size; i++) { 127d98b8539SMaya Erez if ((i % 128) == 0 && i != 0) 128d98b8539SMaya Erez seq_puts(s, "\n"); 129d98b8539SMaya Erez if (wil->use_enhanced_dma_hw) { 130d98b8539SMaya Erez wil_print_desc_edma(s, wil, ring, _s, _h, i); 131d98b8539SMaya Erez } else { 13210590c6aSGidon Studinski volatile struct vring_tx_desc *d = 13310590c6aSGidon Studinski &ring->va[i].tx.legacy; 13459f7c0a9SVladimir Kondratiev seq_printf(s, "%c", (d->dma.status & BIT(0)) ? 13510590c6aSGidon Studinski _s : (ring->ctx[i].skb ? _h : 'h')); 1362be7d22fSVladimir Kondratiev } 137d98b8539SMaya Erez } 1388fe59627SVladimir Kondratiev seq_puts(s, "\n"); 1392be7d22fSVladimir Kondratiev } 1408fe59627SVladimir Kondratiev seq_puts(s, "}\n"); 1412be7d22fSVladimir Kondratiev } 1422be7d22fSVladimir Kondratiev 143986b8348SYangtao Li static int ring_show(struct seq_file *s, void *data) 1442be7d22fSVladimir Kondratiev { 1452be7d22fSVladimir Kondratiev uint i; 1462be7d22fSVladimir Kondratiev struct wil6210_priv *wil = s->private; 1472be7d22fSVladimir Kondratiev 14810590c6aSGidon Studinski wil_print_ring(s, wil, "rx", &wil->ring_rx, 'S', '_'); 1492be7d22fSVladimir Kondratiev 15010590c6aSGidon Studinski for (i = 0; i < ARRAY_SIZE(wil->ring_tx); i++) { 15110590c6aSGidon Studinski struct wil_ring *ring = &wil->ring_tx[i]; 15210590c6aSGidon Studinski struct wil_ring_tx_data *txdata = &wil->ring_tx_data[i]; 1537c0acf86SVladimir Kondratiev 15410590c6aSGidon Studinski if (ring->va) { 15510590c6aSGidon Studinski int cid = wil->ring2cid_tid[i][0]; 15610590c6aSGidon Studinski int tid = wil->ring2cid_tid[i][1]; 15710590c6aSGidon Studinski u32 swhead = ring->swhead; 15810590c6aSGidon Studinski u32 swtail = ring->swtail; 15910590c6aSGidon Studinski int used = (ring->size + swhead - swtail) 16010590c6aSGidon Studinski % ring->size; 16110590c6aSGidon Studinski int avail = ring->size - used - 1; 1622be7d22fSVladimir Kondratiev char name[10]; 1638f55cbecSBoris Sorochkin char sidle[10]; 1647c0acf86SVladimir Kondratiev /* performance monitoring */ 1657c0acf86SVladimir Kondratiev cycles_t now = get_cycles(); 166c20e7789SChen Gang uint64_t idle = txdata->idle * 100; 167c20e7789SChen Gang uint64_t total = now - txdata->begin; 1687c0acf86SVladimir Kondratiev 1698f55cbecSBoris Sorochkin if (total != 0) { 170e48b1790SVladimir Kondratiev do_div(idle, total); 1718f55cbecSBoris Sorochkin snprintf(sidle, sizeof(sidle), "%3d%%", 1728f55cbecSBoris Sorochkin (int)idle); 1738f55cbecSBoris Sorochkin } else { 1748f55cbecSBoris Sorochkin snprintf(sidle, sizeof(sidle), "N/A"); 1758f55cbecSBoris Sorochkin } 1767c0acf86SVladimir Kondratiev txdata->begin = now; 1777c0acf86SVladimir Kondratiev txdata->idle = 0ULL; 1787c0acf86SVladimir Kondratiev 1792be7d22fSVladimir Kondratiev snprintf(name, sizeof(name), "tx_%2d", i); 1803df2cd36SVladimir Kondratiev 181*ddf7afddSAhmad Masri if (cid < wil->max_assoc_sta) 1823277213fSVladimir Kondratiev seq_printf(s, 183230d8442SVladimir Kondratiev "\n%pM CID %d TID %d 1x%s BACK([%u] %u TU A%s) [%3d|%3d] idle %s\n", 1843277213fSVladimir Kondratiev wil->sta[cid].addr, cid, tid, 185230d8442SVladimir Kondratiev txdata->dot1x_open ? "+" : "-", 18641d6b093SVladimir Kondratiev txdata->agg_wsize, 18741d6b093SVladimir Kondratiev txdata->agg_timeout, 188cbcf5866SVladimir Kondratiev txdata->agg_amsdu ? "+" : "-", 1898f55cbecSBoris Sorochkin used, avail, sidle); 19041d6b093SVladimir Kondratiev else 19141d6b093SVladimir Kondratiev seq_printf(s, 192230d8442SVladimir Kondratiev "\nBroadcast 1x%s [%3d|%3d] idle %s\n", 193230d8442SVladimir Kondratiev txdata->dot1x_open ? "+" : "-", 19441d6b093SVladimir Kondratiev used, avail, sidle); 1957c0acf86SVladimir Kondratiev 19610590c6aSGidon Studinski wil_print_ring(s, wil, name, ring, '_', 'H'); 1972be7d22fSVladimir Kondratiev } 1982be7d22fSVladimir Kondratiev } 1992be7d22fSVladimir Kondratiev 2002be7d22fSVladimir Kondratiev return 0; 2012be7d22fSVladimir Kondratiev } 202986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(ring); 2032be7d22fSVladimir Kondratiev 204d98b8539SMaya Erez static void wil_print_sring(struct seq_file *s, struct wil6210_priv *wil, 205d98b8539SMaya Erez struct wil_status_ring *sring) 206d98b8539SMaya Erez { 2079a874d04SDedy Lansky void __iomem *x; 208d98b8539SMaya Erez int sring_idx = sring - wil->srings; 209d98b8539SMaya Erez u32 v; 210d98b8539SMaya Erez 211d98b8539SMaya Erez seq_printf(s, "Status Ring %s [ %d ] = {\n", 212d98b8539SMaya Erez sring->is_rx ? "RX" : "TX", sring_idx); 213d98b8539SMaya Erez seq_printf(s, " pa = %pad\n", &sring->pa); 214d98b8539SMaya Erez seq_printf(s, " va = 0x%pK\n", sring->va); 215d98b8539SMaya Erez seq_printf(s, " size = %d\n", sring->size); 216d98b8539SMaya Erez seq_printf(s, " elem_size = %zu\n", sring->elem_size); 217d98b8539SMaya Erez seq_printf(s, " swhead = %d\n", sring->swhead); 2189a874d04SDedy Lansky if (wil->use_enhanced_dma_hw) { 2199a874d04SDedy Lansky /* COMPQ_PROD is a table of 32 entries, one for each Q pair. 2209a874d04SDedy Lansky * lower 16bits are for even ring_id and upper 16bits are for 2219a874d04SDedy Lansky * odd ring_id 2229a874d04SDedy Lansky */ 2239a874d04SDedy Lansky x = wmi_addr(wil, RGF_DMA_SCM_COMPQ_PROD + 4 * (sring_idx / 2)); 2249a874d04SDedy Lansky v = readl_relaxed(x); 2259a874d04SDedy Lansky 2269a874d04SDedy Lansky v = (sring_idx % 2 ? (v >> 16) : (v & 0xffff)); 2279a874d04SDedy Lansky seq_printf(s, " hwhead = %u\n", v); 2289a874d04SDedy Lansky } 229d98b8539SMaya Erez seq_printf(s, " hwtail = [0x%08x] -> ", sring->hwtail); 2309a874d04SDedy Lansky x = wmi_addr(wil, sring->hwtail); 231d98b8539SMaya Erez if (x) { 232d98b8539SMaya Erez v = readl_relaxed(x); 233d98b8539SMaya Erez seq_printf(s, "0x%08x = %d\n", v, v); 234d98b8539SMaya Erez } else { 235d98b8539SMaya Erez seq_puts(s, "???\n"); 236d98b8539SMaya Erez } 237d98b8539SMaya Erez seq_printf(s, " desc_rdy_pol = %d\n", sring->desc_rdy_pol); 238b4a967b7SMaya Erez seq_printf(s, " invalid_buff_id_cnt = %d\n", 239b4a967b7SMaya Erez sring->invalid_buff_id_cnt); 240d98b8539SMaya Erez 241d98b8539SMaya Erez if (sring->va && (sring->size <= (1 << WIL_RING_SIZE_ORDER_MAX))) { 242d98b8539SMaya Erez uint i; 243d98b8539SMaya Erez 244d98b8539SMaya Erez for (i = 0; i < sring->size; i++) { 245d98b8539SMaya Erez u32 *sdword_0 = 246d98b8539SMaya Erez (u32 *)(sring->va + (sring->elem_size * i)); 247d98b8539SMaya Erez 248d98b8539SMaya Erez if ((i % 128) == 0 && i != 0) 249d98b8539SMaya Erez seq_puts(s, "\n"); 250d98b8539SMaya Erez if (i == sring->swhead) 251d98b8539SMaya Erez seq_printf(s, "%c", (*sdword_0 & BIT(31)) ? 252d98b8539SMaya Erez 'X' : 'x'); 253d98b8539SMaya Erez else 254d98b8539SMaya Erez seq_printf(s, "%c", (*sdword_0 & BIT(31)) ? 255d98b8539SMaya Erez '1' : '0'); 256d98b8539SMaya Erez } 257d98b8539SMaya Erez seq_puts(s, "\n"); 258d98b8539SMaya Erez } 259d98b8539SMaya Erez seq_puts(s, "}\n"); 260d98b8539SMaya Erez } 261d98b8539SMaya Erez 262986b8348SYangtao Li static int srings_show(struct seq_file *s, void *data) 263d98b8539SMaya Erez { 264d98b8539SMaya Erez struct wil6210_priv *wil = s->private; 265d98b8539SMaya Erez int i = 0; 266d98b8539SMaya Erez 267d98b8539SMaya Erez for (i = 0; i < WIL6210_MAX_STATUS_RINGS; i++) 268d98b8539SMaya Erez if (wil->srings[i].va) 269d98b8539SMaya Erez wil_print_sring(s, wil, &wil->srings[i]); 270d98b8539SMaya Erez 271d98b8539SMaya Erez return 0; 272d98b8539SMaya Erez } 273986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(srings); 274d98b8539SMaya Erez 275a202fbbfSAndy Shevchenko static void wil_seq_hexdump(struct seq_file *s, void *p, int len, 276a202fbbfSAndy Shevchenko const char *prefix) 277a202fbbfSAndy Shevchenko { 278a202fbbfSAndy Shevchenko seq_hex_dump(s, prefix, DUMP_PREFIX_NONE, 16, 1, p, len, false); 279a202fbbfSAndy Shevchenko } 280a202fbbfSAndy Shevchenko 28110590c6aSGidon Studinski static void wil_print_mbox_ring(struct seq_file *s, const char *prefix, 2822be7d22fSVladimir Kondratiev void __iomem *off) 2832be7d22fSVladimir Kondratiev { 2842be7d22fSVladimir Kondratiev struct wil6210_priv *wil = s->private; 2852be7d22fSVladimir Kondratiev struct wil6210_mbox_ring r; 2862be7d22fSVladimir Kondratiev int rsize; 2872be7d22fSVladimir Kondratiev uint i; 2882be7d22fSVladimir Kondratiev 289349214c1SMaya Erez wil_halp_vote(wil); 290349214c1SMaya Erez 291a0618945SAhmad Masri if (wil_mem_access_lock(wil)) { 292a0618945SAhmad Masri wil_halp_unvote(wil); 293a0618945SAhmad Masri return; 294a0618945SAhmad Masri } 295a0618945SAhmad Masri 2962be7d22fSVladimir Kondratiev wil_memcpy_fromio_32(&r, off, sizeof(r)); 2972be7d22fSVladimir Kondratiev wil_mbox_ring_le2cpus(&r); 2982be7d22fSVladimir Kondratiev /* 2992be7d22fSVladimir Kondratiev * we just read memory block from NIC. This memory may be 3002be7d22fSVladimir Kondratiev * garbage. Check validity before using it. 3012be7d22fSVladimir Kondratiev */ 3022be7d22fSVladimir Kondratiev rsize = r.size / sizeof(struct wil6210_mbox_ring_desc); 3032be7d22fSVladimir Kondratiev 3042be7d22fSVladimir Kondratiev seq_printf(s, "ring %s = {\n", prefix); 3052be7d22fSVladimir Kondratiev seq_printf(s, " base = 0x%08x\n", r.base); 3062be7d22fSVladimir Kondratiev seq_printf(s, " size = 0x%04x bytes -> %d entries\n", r.size, rsize); 3072be7d22fSVladimir Kondratiev seq_printf(s, " tail = 0x%08x\n", r.tail); 3082be7d22fSVladimir Kondratiev seq_printf(s, " head = 0x%08x\n", r.head); 3092be7d22fSVladimir Kondratiev seq_printf(s, " entry size = %d\n", r.entry_size); 3102be7d22fSVladimir Kondratiev 3112be7d22fSVladimir Kondratiev if (r.size % sizeof(struct wil6210_mbox_ring_desc)) { 3122be7d22fSVladimir Kondratiev seq_printf(s, " ??? size is not multiple of %zd, garbage?\n", 3132be7d22fSVladimir Kondratiev sizeof(struct wil6210_mbox_ring_desc)); 3142be7d22fSVladimir Kondratiev goto out; 3152be7d22fSVladimir Kondratiev } 3162be7d22fSVladimir Kondratiev 3172be7d22fSVladimir Kondratiev if (!wmi_addr(wil, r.base) || 3182be7d22fSVladimir Kondratiev !wmi_addr(wil, r.tail) || 3192be7d22fSVladimir Kondratiev !wmi_addr(wil, r.head)) { 3208fe59627SVladimir Kondratiev seq_puts(s, " ??? pointers are garbage?\n"); 3212be7d22fSVladimir Kondratiev goto out; 3222be7d22fSVladimir Kondratiev } 3232be7d22fSVladimir Kondratiev 3242be7d22fSVladimir Kondratiev for (i = 0; i < rsize; i++) { 3252be7d22fSVladimir Kondratiev struct wil6210_mbox_ring_desc d; 3262be7d22fSVladimir Kondratiev struct wil6210_mbox_hdr hdr; 3272be7d22fSVladimir Kondratiev size_t delta = i * sizeof(d); 3282be7d22fSVladimir Kondratiev void __iomem *x = wil->csr + HOSTADDR(r.base) + delta; 3292be7d22fSVladimir Kondratiev 3302be7d22fSVladimir Kondratiev wil_memcpy_fromio_32(&d, x, sizeof(d)); 3312be7d22fSVladimir Kondratiev 3322be7d22fSVladimir Kondratiev seq_printf(s, " [%2x] %s %s%s 0x%08x", i, 3332be7d22fSVladimir Kondratiev d.sync ? "F" : "E", 3342be7d22fSVladimir Kondratiev (r.tail - r.base == delta) ? "t" : " ", 3352be7d22fSVladimir Kondratiev (r.head - r.base == delta) ? "h" : " ", 3362be7d22fSVladimir Kondratiev le32_to_cpu(d.addr)); 3372be7d22fSVladimir Kondratiev if (0 == wmi_read_hdr(wil, d.addr, &hdr)) { 3382be7d22fSVladimir Kondratiev u16 len = le16_to_cpu(hdr.len); 3398fe59627SVladimir Kondratiev 3402be7d22fSVladimir Kondratiev seq_printf(s, " -> %04x %04x %04x %02x\n", 3412be7d22fSVladimir Kondratiev le16_to_cpu(hdr.seq), len, 3422be7d22fSVladimir Kondratiev le16_to_cpu(hdr.type), hdr.flags); 3432be7d22fSVladimir Kondratiev if (len <= MAX_MBOXITEM_SIZE) { 3442be7d22fSVladimir Kondratiev unsigned char databuf[MAX_MBOXITEM_SIZE]; 3452be7d22fSVladimir Kondratiev void __iomem *src = wmi_buffer(wil, d.addr) + 3462be7d22fSVladimir Kondratiev sizeof(struct wil6210_mbox_hdr); 3472be7d22fSVladimir Kondratiev /* 3482be7d22fSVladimir Kondratiev * No need to check @src for validity - 3492be7d22fSVladimir Kondratiev * we already validated @d.addr while 3502be7d22fSVladimir Kondratiev * reading header 3512be7d22fSVladimir Kondratiev */ 3522be7d22fSVladimir Kondratiev wil_memcpy_fromio_32(databuf, src, len); 353a202fbbfSAndy Shevchenko wil_seq_hexdump(s, databuf, len, " : "); 3542be7d22fSVladimir Kondratiev } 3552be7d22fSVladimir Kondratiev } else { 3568fe59627SVladimir Kondratiev seq_puts(s, "\n"); 3572be7d22fSVladimir Kondratiev } 3582be7d22fSVladimir Kondratiev } 3592be7d22fSVladimir Kondratiev out: 3608fe59627SVladimir Kondratiev seq_puts(s, "}\n"); 361a0618945SAhmad Masri wil_mem_access_unlock(wil); 362349214c1SMaya Erez wil_halp_unvote(wil); 3632be7d22fSVladimir Kondratiev } 3642be7d22fSVladimir Kondratiev 365986b8348SYangtao Li static int mbox_show(struct seq_file *s, void *data) 3662be7d22fSVladimir Kondratiev { 3672be7d22fSVladimir Kondratiev struct wil6210_priv *wil = s->private; 36894162666SLazar Alexei int ret; 36994162666SLazar Alexei 37094162666SLazar Alexei ret = wil_pm_runtime_get(wil); 37194162666SLazar Alexei if (ret < 0) 37294162666SLazar Alexei return ret; 3732be7d22fSVladimir Kondratiev 37410590c6aSGidon Studinski wil_print_mbox_ring(s, "tx", wil->csr + HOST_MBOX + 3752be7d22fSVladimir Kondratiev offsetof(struct wil6210_mbox_ctl, tx)); 37610590c6aSGidon Studinski wil_print_mbox_ring(s, "rx", wil->csr + HOST_MBOX + 3772be7d22fSVladimir Kondratiev offsetof(struct wil6210_mbox_ctl, rx)); 3782be7d22fSVladimir Kondratiev 37994162666SLazar Alexei wil_pm_runtime_put(wil); 38094162666SLazar Alexei 3812be7d22fSVladimir Kondratiev return 0; 3822be7d22fSVladimir Kondratiev } 383986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(mbox); 3842be7d22fSVladimir Kondratiev 3852be7d22fSVladimir Kondratiev static int wil_debugfs_iomem_x32_set(void *data, u64 val) 3862be7d22fSVladimir Kondratiev { 38794162666SLazar Alexei struct wil_debugfs_iomem_data *d = (struct 38894162666SLazar Alexei wil_debugfs_iomem_data *)data; 38994162666SLazar Alexei struct wil6210_priv *wil = d->wil; 39094162666SLazar Alexei int ret; 39194162666SLazar Alexei 39294162666SLazar Alexei ret = wil_pm_runtime_get(wil); 39394162666SLazar Alexei if (ret < 0) 39494162666SLazar Alexei return ret; 39594162666SLazar Alexei 39694162666SLazar Alexei writel(val, (void __iomem *)d->offset); 3972be7d22fSVladimir Kondratiev wmb(); /* make sure write propagated to HW */ 3982be7d22fSVladimir Kondratiev 39994162666SLazar Alexei wil_pm_runtime_put(wil); 40094162666SLazar Alexei 4012be7d22fSVladimir Kondratiev return 0; 4022be7d22fSVladimir Kondratiev } 4032be7d22fSVladimir Kondratiev 4042be7d22fSVladimir Kondratiev static int wil_debugfs_iomem_x32_get(void *data, u64 *val) 4052be7d22fSVladimir Kondratiev { 40694162666SLazar Alexei struct wil_debugfs_iomem_data *d = (struct 40794162666SLazar Alexei wil_debugfs_iomem_data *)data; 40894162666SLazar Alexei struct wil6210_priv *wil = d->wil; 40994162666SLazar Alexei int ret; 41094162666SLazar Alexei 41194162666SLazar Alexei ret = wil_pm_runtime_get(wil); 41294162666SLazar Alexei if (ret < 0) 41394162666SLazar Alexei return ret; 41494162666SLazar Alexei 41594162666SLazar Alexei *val = readl((void __iomem *)d->offset); 41694162666SLazar Alexei 41794162666SLazar Alexei wil_pm_runtime_put(wil); 4182be7d22fSVladimir Kondratiev 4192be7d22fSVladimir Kondratiev return 0; 4202be7d22fSVladimir Kondratiev } 4212be7d22fSVladimir Kondratiev 422f9dca154SYueHaibing DEFINE_DEBUGFS_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get, 4232be7d22fSVladimir Kondratiev wil_debugfs_iomem_x32_set, "0x%08llx\n"); 4242be7d22fSVladimir Kondratiev 4252be7d22fSVladimir Kondratiev static struct dentry *wil_debugfs_create_iomem_x32(const char *name, 4260ecc833bSAl Viro umode_t mode, 4272be7d22fSVladimir Kondratiev struct dentry *parent, 42894162666SLazar Alexei void *value, 42994162666SLazar Alexei struct wil6210_priv *wil) 4302be7d22fSVladimir Kondratiev { 43194162666SLazar Alexei struct dentry *file; 43294162666SLazar Alexei struct wil_debugfs_iomem_data *data = &wil->dbg_data.data_arr[ 43394162666SLazar Alexei wil->dbg_data.iomem_data_count]; 43494162666SLazar Alexei 43594162666SLazar Alexei data->wil = wil; 43694162666SLazar Alexei data->offset = value; 43794162666SLazar Alexei 438f9dca154SYueHaibing file = debugfs_create_file_unsafe(name, mode, parent, data, 439f9dca154SYueHaibing &fops_iomem_x32); 44094162666SLazar Alexei if (!IS_ERR_OR_NULL(file)) 44194162666SLazar Alexei wil->dbg_data.iomem_data_count++; 44294162666SLazar Alexei 44394162666SLazar Alexei return file; 4442be7d22fSVladimir Kondratiev } 4452be7d22fSVladimir Kondratiev 4463de6cf20SVladimir Kondratiev static int wil_debugfs_ulong_set(void *data, u64 val) 4473de6cf20SVladimir Kondratiev { 4483de6cf20SVladimir Kondratiev *(ulong *)data = val; 4493de6cf20SVladimir Kondratiev return 0; 4503de6cf20SVladimir Kondratiev } 4518fe59627SVladimir Kondratiev 4523de6cf20SVladimir Kondratiev static int wil_debugfs_ulong_get(void *data, u64 *val) 4533de6cf20SVladimir Kondratiev { 4543de6cf20SVladimir Kondratiev *val = *(ulong *)data; 4553de6cf20SVladimir Kondratiev return 0; 4563de6cf20SVladimir Kondratiev } 4578fe59627SVladimir Kondratiev 458f9dca154SYueHaibing DEFINE_DEBUGFS_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get, 4598ea06188SVladimir Kondratiev wil_debugfs_ulong_set, "0x%llx\n"); 4603de6cf20SVladimir Kondratiev 4613de6cf20SVladimir Kondratiev static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode, 4623de6cf20SVladimir Kondratiev struct dentry *parent, 4633de6cf20SVladimir Kondratiev ulong *value) 4643de6cf20SVladimir Kondratiev { 465f9dca154SYueHaibing return debugfs_create_file_unsafe(name, mode, parent, value, 466f9dca154SYueHaibing &wil_fops_ulong); 4673de6cf20SVladimir Kondratiev } 4683de6cf20SVladimir Kondratiev 469b7cde470SVladimir Kondratiev /** 470b7cde470SVladimir Kondratiev * wil6210_debugfs_init_offset - create set of debugfs files 471b7cde470SVladimir Kondratiev * @wil - driver's context, used for printing 472b7cde470SVladimir Kondratiev * @dbg - directory on the debugfs, where files will be created 473b7cde470SVladimir Kondratiev * @base - base address used in address calculation 474b7cde470SVladimir Kondratiev * @tbl - table with file descriptions. Should be terminated with empty element. 475b7cde470SVladimir Kondratiev * 476b7cde470SVladimir Kondratiev * Creates files accordingly to the @tbl. 477b7cde470SVladimir Kondratiev */ 478b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_offset(struct wil6210_priv *wil, 479b7cde470SVladimir Kondratiev struct dentry *dbg, void *base, 480b7cde470SVladimir Kondratiev const struct dbg_off * const tbl) 481b7cde470SVladimir Kondratiev { 482b7cde470SVladimir Kondratiev int i; 483b7cde470SVladimir Kondratiev 484b7cde470SVladimir Kondratiev for (i = 0; tbl[i].name; i++) { 485867fa0d4SVladimir Kondratiev struct dentry *f; 486b7cde470SVladimir Kondratiev 487b7cde470SVladimir Kondratiev switch (tbl[i].type) { 488b7cde470SVladimir Kondratiev case doff_u32: 489b7cde470SVladimir Kondratiev f = debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg, 490b7cde470SVladimir Kondratiev base + tbl[i].off); 491b7cde470SVladimir Kondratiev break; 492b7cde470SVladimir Kondratiev case doff_x32: 493b7cde470SVladimir Kondratiev f = debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg, 494b7cde470SVladimir Kondratiev base + tbl[i].off); 495b7cde470SVladimir Kondratiev break; 496b7cde470SVladimir Kondratiev case doff_ulong: 497b7cde470SVladimir Kondratiev f = wil_debugfs_create_ulong(tbl[i].name, tbl[i].mode, 498b7cde470SVladimir Kondratiev dbg, base + tbl[i].off); 499b7cde470SVladimir Kondratiev break; 500b7cde470SVladimir Kondratiev case doff_io32: 501b7cde470SVladimir Kondratiev f = wil_debugfs_create_iomem_x32(tbl[i].name, 502b7cde470SVladimir Kondratiev tbl[i].mode, dbg, 50394162666SLazar Alexei base + tbl[i].off, 50494162666SLazar Alexei wil); 505b7cde470SVladimir Kondratiev break; 50674997a53SLior David case doff_u8: 50774997a53SLior David f = debugfs_create_u8(tbl[i].name, tbl[i].mode, dbg, 50874997a53SLior David base + tbl[i].off); 50974997a53SLior David break; 510867fa0d4SVladimir Kondratiev default: 511867fa0d4SVladimir Kondratiev f = ERR_PTR(-EINVAL); 512b7cde470SVladimir Kondratiev } 513b7cde470SVladimir Kondratiev if (IS_ERR_OR_NULL(f)) 514b7cde470SVladimir Kondratiev wil_err(wil, "Create file \"%s\": err %ld\n", 515b7cde470SVladimir Kondratiev tbl[i].name, PTR_ERR(f)); 516b7cde470SVladimir Kondratiev } 517b7cde470SVladimir Kondratiev } 518b7cde470SVladimir Kondratiev 519b7cde470SVladimir Kondratiev static const struct dbg_off isr_off[] = { 52078484c44SMaya Erez {"ICC", 0644, offsetof(struct RGF_ICR, ICC), doff_io32}, 52178484c44SMaya Erez {"ICR", 0644, offsetof(struct RGF_ICR, ICR), doff_io32}, 52278484c44SMaya Erez {"ICM", 0644, offsetof(struct RGF_ICR, ICM), doff_io32}, 52378484c44SMaya Erez {"ICS", 0244, offsetof(struct RGF_ICR, ICS), doff_io32}, 52478484c44SMaya Erez {"IMV", 0644, offsetof(struct RGF_ICR, IMV), doff_io32}, 52578484c44SMaya Erez {"IMS", 0244, offsetof(struct RGF_ICR, IMS), doff_io32}, 52678484c44SMaya Erez {"IMC", 0244, offsetof(struct RGF_ICR, IMC), doff_io32}, 527b7cde470SVladimir Kondratiev {}, 528b7cde470SVladimir Kondratiev }; 5298fe59627SVladimir Kondratiev 5302be7d22fSVladimir Kondratiev static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil, 5312be7d22fSVladimir Kondratiev const char *name, 5322be7d22fSVladimir Kondratiev struct dentry *parent, u32 off) 5332be7d22fSVladimir Kondratiev { 5342be7d22fSVladimir Kondratiev struct dentry *d = debugfs_create_dir(name, parent); 5352be7d22fSVladimir Kondratiev 5362be7d22fSVladimir Kondratiev if (IS_ERR_OR_NULL(d)) 5372be7d22fSVladimir Kondratiev return -ENODEV; 5382be7d22fSVladimir Kondratiev 539b7cde470SVladimir Kondratiev wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off, 540b7cde470SVladimir Kondratiev isr_off); 5412be7d22fSVladimir Kondratiev 5422be7d22fSVladimir Kondratiev return 0; 5432be7d22fSVladimir Kondratiev } 5442be7d22fSVladimir Kondratiev 545b7cde470SVladimir Kondratiev static const struct dbg_off pseudo_isr_off[] = { 54678484c44SMaya Erez {"CAUSE", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32}, 54778484c44SMaya Erez {"MASK_SW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32}, 54878484c44SMaya Erez {"MASK_FW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32}, 549b7cde470SVladimir Kondratiev {}, 550b7cde470SVladimir Kondratiev }; 551b7cde470SVladimir Kondratiev 5522be7d22fSVladimir Kondratiev static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil, 5532be7d22fSVladimir Kondratiev struct dentry *parent) 5542be7d22fSVladimir Kondratiev { 5552be7d22fSVladimir Kondratiev struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent); 5562be7d22fSVladimir Kondratiev 5572be7d22fSVladimir Kondratiev if (IS_ERR_OR_NULL(d)) 5582be7d22fSVladimir Kondratiev return -ENODEV; 5592be7d22fSVladimir Kondratiev 560b7cde470SVladimir Kondratiev wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr, 561b7cde470SVladimir Kondratiev pseudo_isr_off); 5622be7d22fSVladimir Kondratiev 5632be7d22fSVladimir Kondratiev return 0; 5642be7d22fSVladimir Kondratiev } 5652be7d22fSVladimir Kondratiev 56678366f69SVladimir Kondratiev static const struct dbg_off lgc_itr_cnt_off[] = { 56778484c44SMaya Erez {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32}, 56878484c44SMaya Erez {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32}, 56978484c44SMaya Erez {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32}, 570b7cde470SVladimir Kondratiev {}, 571b7cde470SVladimir Kondratiev }; 572b7cde470SVladimir Kondratiev 57378366f69SVladimir Kondratiev static const struct dbg_off tx_itr_cnt_off[] = { 57478484c44SMaya Erez {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_TRSH), 57578366f69SVladimir Kondratiev doff_io32}, 57678484c44SMaya Erez {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_DATA), 57778366f69SVladimir Kondratiev doff_io32}, 57878484c44SMaya Erez {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_CTL), 57978366f69SVladimir Kondratiev doff_io32}, 58078484c44SMaya Erez {"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_TRSH), 58178366f69SVladimir Kondratiev doff_io32}, 58278484c44SMaya Erez {"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_DATA), 58378366f69SVladimir Kondratiev doff_io32}, 58478484c44SMaya Erez {"IDL_CTL", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_CTL), 58578366f69SVladimir Kondratiev doff_io32}, 58678366f69SVladimir Kondratiev {}, 58778366f69SVladimir Kondratiev }; 58878366f69SVladimir Kondratiev 58978366f69SVladimir Kondratiev static const struct dbg_off rx_itr_cnt_off[] = { 59078484c44SMaya Erez {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_TRSH), 59178366f69SVladimir Kondratiev doff_io32}, 59278484c44SMaya Erez {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_DATA), 59378366f69SVladimir Kondratiev doff_io32}, 59478484c44SMaya Erez {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_CTL), 59578366f69SVladimir Kondratiev doff_io32}, 59678484c44SMaya Erez {"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_TRSH), 59778366f69SVladimir Kondratiev doff_io32}, 59878484c44SMaya Erez {"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_DATA), 59978366f69SVladimir Kondratiev doff_io32}, 60078484c44SMaya Erez {"IDL_CTL", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_CTL), 60178366f69SVladimir Kondratiev doff_io32}, 60278366f69SVladimir Kondratiev {}, 60378366f69SVladimir Kondratiev }; 60478366f69SVladimir Kondratiev 6052be7d22fSVladimir Kondratiev static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil, 6062be7d22fSVladimir Kondratiev struct dentry *parent) 6072be7d22fSVladimir Kondratiev { 60878366f69SVladimir Kondratiev struct dentry *d, *dtx, *drx; 6092be7d22fSVladimir Kondratiev 61078366f69SVladimir Kondratiev d = debugfs_create_dir("ITR_CNT", parent); 6112be7d22fSVladimir Kondratiev if (IS_ERR_OR_NULL(d)) 6122be7d22fSVladimir Kondratiev return -ENODEV; 6132be7d22fSVladimir Kondratiev 61478366f69SVladimir Kondratiev dtx = debugfs_create_dir("TX", d); 61578366f69SVladimir Kondratiev drx = debugfs_create_dir("RX", d); 61678366f69SVladimir Kondratiev if (IS_ERR_OR_NULL(dtx) || IS_ERR_OR_NULL(drx)) 61778366f69SVladimir Kondratiev return -ENODEV; 6182be7d22fSVladimir Kondratiev 61978366f69SVladimir Kondratiev wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr, 62078366f69SVladimir Kondratiev lgc_itr_cnt_off); 62178366f69SVladimir Kondratiev 62278366f69SVladimir Kondratiev wil6210_debugfs_init_offset(wil, dtx, (void * __force)wil->csr, 62378366f69SVladimir Kondratiev tx_itr_cnt_off); 62478366f69SVladimir Kondratiev 62578366f69SVladimir Kondratiev wil6210_debugfs_init_offset(wil, drx, (void * __force)wil->csr, 62678366f69SVladimir Kondratiev rx_itr_cnt_off); 6272be7d22fSVladimir Kondratiev return 0; 6282be7d22fSVladimir Kondratiev } 6292be7d22fSVladimir Kondratiev 630986b8348SYangtao Li static int memread_show(struct seq_file *s, void *data) 6312be7d22fSVladimir Kondratiev { 6322be7d22fSVladimir Kondratiev struct wil6210_priv *wil = s->private; 63394162666SLazar Alexei void __iomem *a; 63494162666SLazar Alexei int ret; 63594162666SLazar Alexei 63694162666SLazar Alexei ret = wil_pm_runtime_get(wil); 63794162666SLazar Alexei if (ret < 0) 63894162666SLazar Alexei return ret; 63994162666SLazar Alexei 640a0618945SAhmad Masri ret = wil_mem_access_lock(wil); 641a0618945SAhmad Masri if (ret) { 642a0618945SAhmad Masri wil_pm_runtime_put(wil); 643a0618945SAhmad Masri return ret; 644a0618945SAhmad Masri } 645a0618945SAhmad Masri 64694162666SLazar Alexei a = wmi_buffer(wil, cpu_to_le32(mem_addr)); 6472be7d22fSVladimir Kondratiev 6482be7d22fSVladimir Kondratiev if (a) 649b9eeb512SVladimir Kondratiev seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, readl(a)); 6502be7d22fSVladimir Kondratiev else 6512be7d22fSVladimir Kondratiev seq_printf(s, "[0x%08x] = INVALID\n", mem_addr); 6522be7d22fSVladimir Kondratiev 653a0618945SAhmad Masri wil_mem_access_unlock(wil); 65494162666SLazar Alexei wil_pm_runtime_put(wil); 65594162666SLazar Alexei 6562be7d22fSVladimir Kondratiev return 0; 6572be7d22fSVladimir Kondratiev } 658986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(memread); 6592be7d22fSVladimir Kondratiev 6602be7d22fSVladimir Kondratiev static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf, 6612be7d22fSVladimir Kondratiev size_t count, loff_t *ppos) 6622be7d22fSVladimir Kondratiev { 6632be7d22fSVladimir Kondratiev enum { max_count = 4096 }; 664349214c1SMaya Erez struct wil_blob_wrapper *wil_blob = file->private_data; 66594162666SLazar Alexei struct wil6210_priv *wil = wil_blob->wil; 66684ec040dSAhmad Masri loff_t aligned_pos, pos = *ppos; 667349214c1SMaya Erez size_t available = wil_blob->blob.size; 6682be7d22fSVladimir Kondratiev void *buf; 66984ec040dSAhmad Masri size_t unaligned_bytes, aligned_count, ret; 67094162666SLazar Alexei int rc; 6712be7d22fSVladimir Kondratiev 6722be7d22fSVladimir Kondratiev if (pos < 0) 6732be7d22fSVladimir Kondratiev return -EINVAL; 6742be7d22fSVladimir Kondratiev 6752be7d22fSVladimir Kondratiev if (pos >= available || !count) 6762be7d22fSVladimir Kondratiev return 0; 6772be7d22fSVladimir Kondratiev 6782be7d22fSVladimir Kondratiev if (count > available - pos) 6792be7d22fSVladimir Kondratiev count = available - pos; 6802be7d22fSVladimir Kondratiev if (count > max_count) 6812be7d22fSVladimir Kondratiev count = max_count; 6822be7d22fSVladimir Kondratiev 68384ec040dSAhmad Masri /* set pos to 4 bytes aligned */ 68484ec040dSAhmad Masri unaligned_bytes = pos % 4; 68584ec040dSAhmad Masri aligned_pos = pos - unaligned_bytes; 68684ec040dSAhmad Masri aligned_count = count + unaligned_bytes; 68784ec040dSAhmad Masri 68884ec040dSAhmad Masri buf = kmalloc(aligned_count, GFP_KERNEL); 6892be7d22fSVladimir Kondratiev if (!buf) 6902be7d22fSVladimir Kondratiev return -ENOMEM; 6912be7d22fSVladimir Kondratiev 69294162666SLazar Alexei rc = wil_pm_runtime_get(wil); 69394162666SLazar Alexei if (rc < 0) { 69494162666SLazar Alexei kfree(buf); 69594162666SLazar Alexei return rc; 69694162666SLazar Alexei } 69794162666SLazar Alexei 698a0618945SAhmad Masri rc = wil_mem_access_lock(wil); 699a0618945SAhmad Masri if (rc) { 700a0618945SAhmad Masri kfree(buf); 701a0618945SAhmad Masri wil_pm_runtime_put(wil); 702a0618945SAhmad Masri return rc; 703a0618945SAhmad Masri } 704a0618945SAhmad Masri 705bd50e268SMaya Erez wil_memcpy_fromio_32(buf, (const void __iomem *) 70684ec040dSAhmad Masri wil_blob->blob.data + aligned_pos, aligned_count); 7072be7d22fSVladimir Kondratiev 70884ec040dSAhmad Masri ret = copy_to_user(user_buf, buf + unaligned_bytes, count); 70994162666SLazar Alexei 710a0618945SAhmad Masri wil_mem_access_unlock(wil); 71194162666SLazar Alexei wil_pm_runtime_put(wil); 71294162666SLazar Alexei 7132be7d22fSVladimir Kondratiev kfree(buf); 7142be7d22fSVladimir Kondratiev if (ret == count) 7152be7d22fSVladimir Kondratiev return -EFAULT; 7162be7d22fSVladimir Kondratiev 7172be7d22fSVladimir Kondratiev count -= ret; 7182be7d22fSVladimir Kondratiev *ppos = pos + count; 7192be7d22fSVladimir Kondratiev 7202be7d22fSVladimir Kondratiev return count; 7212be7d22fSVladimir Kondratiev } 7222be7d22fSVladimir Kondratiev 7232be7d22fSVladimir Kondratiev static const struct file_operations fops_ioblob = { 7242be7d22fSVladimir Kondratiev .read = wil_read_file_ioblob, 72593ecbd64SWei Yongjun .open = simple_open, 7262be7d22fSVladimir Kondratiev .llseek = default_llseek, 7272be7d22fSVladimir Kondratiev }; 7282be7d22fSVladimir Kondratiev 7292be7d22fSVladimir Kondratiev static 7302be7d22fSVladimir Kondratiev struct dentry *wil_debugfs_create_ioblob(const char *name, 7310ecc833bSAl Viro umode_t mode, 7322be7d22fSVladimir Kondratiev struct dentry *parent, 733349214c1SMaya Erez struct wil_blob_wrapper *wil_blob) 7342be7d22fSVladimir Kondratiev { 735349214c1SMaya Erez return debugfs_create_file(name, mode, parent, wil_blob, &fops_ioblob); 7362be7d22fSVladimir Kondratiev } 7378fe59627SVladimir Kondratiev 7380b39aaf2SVladimir Kondratiev /*---write channel 1..4 to rxon for it, 0 to rxoff---*/ 7390b39aaf2SVladimir Kondratiev static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf, 7400b39aaf2SVladimir Kondratiev size_t len, loff_t *ppos) 7410b39aaf2SVladimir Kondratiev { 7420b39aaf2SVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 7430b39aaf2SVladimir Kondratiev int rc; 7440b39aaf2SVladimir Kondratiev long channel; 7450b39aaf2SVladimir Kondratiev bool on; 7460b39aaf2SVladimir Kondratiev 74716e5c1fcSAl Viro char *kbuf = memdup_user_nul(buf, len); 7488fe59627SVladimir Kondratiev 74916e5c1fcSAl Viro if (IS_ERR(kbuf)) 75016e5c1fcSAl Viro return PTR_ERR(kbuf); 7510b39aaf2SVladimir Kondratiev rc = kstrtol(kbuf, 0, &channel); 7520b39aaf2SVladimir Kondratiev kfree(kbuf); 7530b39aaf2SVladimir Kondratiev if (rc) 7540b39aaf2SVladimir Kondratiev return rc; 7550b39aaf2SVladimir Kondratiev 7560b39aaf2SVladimir Kondratiev if ((channel < 0) || (channel > 4)) { 7570b39aaf2SVladimir Kondratiev wil_err(wil, "Invalid channel %ld\n", channel); 7580b39aaf2SVladimir Kondratiev return -EINVAL; 7590b39aaf2SVladimir Kondratiev } 7600b39aaf2SVladimir Kondratiev on = !!channel; 7610b39aaf2SVladimir Kondratiev 7620b39aaf2SVladimir Kondratiev if (on) { 7630b39aaf2SVladimir Kondratiev rc = wmi_set_channel(wil, (int)channel); 7640b39aaf2SVladimir Kondratiev if (rc) 7650b39aaf2SVladimir Kondratiev return rc; 7660b39aaf2SVladimir Kondratiev } 7670b39aaf2SVladimir Kondratiev 7680b39aaf2SVladimir Kondratiev rc = wmi_rxon(wil, on); 7690b39aaf2SVladimir Kondratiev if (rc) 7700b39aaf2SVladimir Kondratiev return rc; 7710b39aaf2SVladimir Kondratiev 7720b39aaf2SVladimir Kondratiev return len; 7730b39aaf2SVladimir Kondratiev } 7740b39aaf2SVladimir Kondratiev 7750b39aaf2SVladimir Kondratiev static const struct file_operations fops_rxon = { 7760b39aaf2SVladimir Kondratiev .write = wil_write_file_rxon, 7770b39aaf2SVladimir Kondratiev .open = simple_open, 7780b39aaf2SVladimir Kondratiev }; 7798fe59627SVladimir Kondratiev 78049cb5dfbSVladimir Kondratiev /* block ack control, write: 78149cb5dfbSVladimir Kondratiev * - "add <ringid> <agg_size> <timeout>" to trigger ADDBA 78249cb5dfbSVladimir Kondratiev * - "del_tx <ringid> <reason>" to trigger DELBA for Tx side 78349cb5dfbSVladimir Kondratiev * - "del_rx <CID> <TID> <reason>" to trigger DELBA for Rx side 7843277213fSVladimir Kondratiev */ 78549cb5dfbSVladimir Kondratiev static ssize_t wil_write_back(struct file *file, const char __user *buf, 7863277213fSVladimir Kondratiev size_t len, loff_t *ppos) 7873277213fSVladimir Kondratiev { 7883277213fSVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 7893277213fSVladimir Kondratiev int rc; 7903277213fSVladimir Kondratiev char *kbuf = kmalloc(len + 1, GFP_KERNEL); 7912a19f776SColin Ian King char cmd[9]; 79249cb5dfbSVladimir Kondratiev int p1, p2, p3; 7933277213fSVladimir Kondratiev 7943277213fSVladimir Kondratiev if (!kbuf) 7953277213fSVladimir Kondratiev return -ENOMEM; 7963277213fSVladimir Kondratiev 7973277213fSVladimir Kondratiev rc = simple_write_to_buffer(kbuf, len, ppos, buf, len); 7983277213fSVladimir Kondratiev if (rc != len) { 7993277213fSVladimir Kondratiev kfree(kbuf); 8003277213fSVladimir Kondratiev return rc >= 0 ? -EIO : rc; 8013277213fSVladimir Kondratiev } 8023277213fSVladimir Kondratiev 8033277213fSVladimir Kondratiev kbuf[len] = '\0'; 80449cb5dfbSVladimir Kondratiev rc = sscanf(kbuf, "%8s %d %d %d", cmd, &p1, &p2, &p3); 8053277213fSVladimir Kondratiev kfree(kbuf); 8063277213fSVladimir Kondratiev 80749cb5dfbSVladimir Kondratiev if (rc < 0) 8083277213fSVladimir Kondratiev return rc; 80949cb5dfbSVladimir Kondratiev if (rc < 2) 8103277213fSVladimir Kondratiev return -EINVAL; 8113277213fSVladimir Kondratiev 812e00243faSLior David if ((strcmp(cmd, "add") == 0) || 813e00243faSLior David (strcmp(cmd, "del_tx") == 0)) { 81410590c6aSGidon Studinski struct wil_ring_tx_data *txdata; 815e00243faSLior David 816e00243faSLior David if (p1 < 0 || p1 >= WIL6210_MAX_TX_RINGS) { 817e00243faSLior David wil_err(wil, "BACK: invalid ring id %d\n", p1); 818e00243faSLior David return -EINVAL; 819e00243faSLior David } 82010590c6aSGidon Studinski txdata = &wil->ring_tx_data[p1]; 821e00243faSLior David if (strcmp(cmd, "add") == 0) { 82249cb5dfbSVladimir Kondratiev if (rc < 3) { 82349cb5dfbSVladimir Kondratiev wil_err(wil, "BACK: add require at least 2 params\n"); 82449cb5dfbSVladimir Kondratiev return -EINVAL; 82549cb5dfbSVladimir Kondratiev } 82649cb5dfbSVladimir Kondratiev if (rc < 4) 82749cb5dfbSVladimir Kondratiev p3 = 0; 828e00243faSLior David wmi_addba(wil, txdata->mid, p1, p2, p3); 829e00243faSLior David } else { 83049cb5dfbSVladimir Kondratiev if (rc < 3) 83149cb5dfbSVladimir Kondratiev p2 = WLAN_REASON_QSTA_LEAVE_QBSS; 832e00243faSLior David wmi_delba_tx(wil, txdata->mid, p1, p2); 833e00243faSLior David } 834e00243faSLior David } else if (strcmp(cmd, "del_rx") == 0) { 835e00243faSLior David struct wil_sta_info *sta; 836e00243faSLior David 83749cb5dfbSVladimir Kondratiev if (rc < 3) { 83849cb5dfbSVladimir Kondratiev wil_err(wil, 83949cb5dfbSVladimir Kondratiev "BACK: del_rx require at least 2 params\n"); 84049cb5dfbSVladimir Kondratiev return -EINVAL; 84149cb5dfbSVladimir Kondratiev } 842*ddf7afddSAhmad Masri if (p1 < 0 || p1 >= wil->max_assoc_sta) { 843e00243faSLior David wil_err(wil, "BACK: invalid CID %d\n", p1); 844e00243faSLior David return -EINVAL; 845e00243faSLior David } 84649cb5dfbSVladimir Kondratiev if (rc < 4) 84749cb5dfbSVladimir Kondratiev p3 = WLAN_REASON_QSTA_LEAVE_QBSS; 848e00243faSLior David sta = &wil->sta[p1]; 849bf0353a6SAhmad Masri wmi_delba_rx(wil, sta->mid, p1, p2, p3); 85049cb5dfbSVladimir Kondratiev } else { 85149cb5dfbSVladimir Kondratiev wil_err(wil, "BACK: Unrecognized command \"%s\"\n", cmd); 85249cb5dfbSVladimir Kondratiev return -EINVAL; 85349cb5dfbSVladimir Kondratiev } 8543277213fSVladimir Kondratiev 8553277213fSVladimir Kondratiev return len; 8563277213fSVladimir Kondratiev } 8573277213fSVladimir Kondratiev 85849cb5dfbSVladimir Kondratiev static ssize_t wil_read_back(struct file *file, char __user *user_buf, 85949cb5dfbSVladimir Kondratiev size_t count, loff_t *ppos) 86049cb5dfbSVladimir Kondratiev { 86149cb5dfbSVladimir Kondratiev static const char text[] = "block ack control, write:\n" 86249cb5dfbSVladimir Kondratiev " - \"add <ringid> <agg_size> <timeout>\" to trigger ADDBA\n" 86349cb5dfbSVladimir Kondratiev "If missing, <timeout> defaults to 0\n" 86449cb5dfbSVladimir Kondratiev " - \"del_tx <ringid> <reason>\" to trigger DELBA for Tx side\n" 86549cb5dfbSVladimir Kondratiev " - \"del_rx <CID> <TID> <reason>\" to trigger DELBA for Rx side\n" 86649cb5dfbSVladimir Kondratiev "If missing, <reason> set to \"STA_LEAVING\" (36)\n"; 86749cb5dfbSVladimir Kondratiev 86849cb5dfbSVladimir Kondratiev return simple_read_from_buffer(user_buf, count, ppos, text, 86949cb5dfbSVladimir Kondratiev sizeof(text)); 87049cb5dfbSVladimir Kondratiev } 87149cb5dfbSVladimir Kondratiev 87249cb5dfbSVladimir Kondratiev static const struct file_operations fops_back = { 87349cb5dfbSVladimir Kondratiev .read = wil_read_back, 87449cb5dfbSVladimir Kondratiev .write = wil_write_back, 8753277213fSVladimir Kondratiev .open = simple_open, 8763277213fSVladimir Kondratiev }; 8773277213fSVladimir Kondratiev 878dc16427bSVladimir Kondratiev /* pmc control, write: 879dc16427bSVladimir Kondratiev * - "alloc <num descriptors> <descriptor_size>" to allocate PMC 880dc16427bSVladimir Kondratiev * - "free" to release memory allocated for PMC 881dc16427bSVladimir Kondratiev */ 882dc16427bSVladimir Kondratiev static ssize_t wil_write_pmccfg(struct file *file, const char __user *buf, 883dc16427bSVladimir Kondratiev size_t len, loff_t *ppos) 884dc16427bSVladimir Kondratiev { 885dc16427bSVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 886dc16427bSVladimir Kondratiev int rc; 887dc16427bSVladimir Kondratiev char *kbuf = kmalloc(len + 1, GFP_KERNEL); 888dc16427bSVladimir Kondratiev char cmd[9]; 889dc16427bSVladimir Kondratiev int num_descs, desc_size; 890dc16427bSVladimir Kondratiev 891dc16427bSVladimir Kondratiev if (!kbuf) 892dc16427bSVladimir Kondratiev return -ENOMEM; 893dc16427bSVladimir Kondratiev 894dc16427bSVladimir Kondratiev rc = simple_write_to_buffer(kbuf, len, ppos, buf, len); 895dc16427bSVladimir Kondratiev if (rc != len) { 896dc16427bSVladimir Kondratiev kfree(kbuf); 897dc16427bSVladimir Kondratiev return rc >= 0 ? -EIO : rc; 898dc16427bSVladimir Kondratiev } 899dc16427bSVladimir Kondratiev 900dc16427bSVladimir Kondratiev kbuf[len] = '\0'; 901dc16427bSVladimir Kondratiev rc = sscanf(kbuf, "%8s %d %d", cmd, &num_descs, &desc_size); 902dc16427bSVladimir Kondratiev kfree(kbuf); 903dc16427bSVladimir Kondratiev 904dc16427bSVladimir Kondratiev if (rc < 0) 905dc16427bSVladimir Kondratiev return rc; 906dc16427bSVladimir Kondratiev 907dc16427bSVladimir Kondratiev if (rc < 1) { 908dc16427bSVladimir Kondratiev wil_err(wil, "pmccfg: no params given\n"); 909dc16427bSVladimir Kondratiev return -EINVAL; 910dc16427bSVladimir Kondratiev } 911dc16427bSVladimir Kondratiev 912dc16427bSVladimir Kondratiev if (0 == strcmp(cmd, "alloc")) { 913dc16427bSVladimir Kondratiev if (rc != 3) { 914dc16427bSVladimir Kondratiev wil_err(wil, "pmccfg: alloc requires 2 params\n"); 915dc16427bSVladimir Kondratiev return -EINVAL; 916dc16427bSVladimir Kondratiev } 917dc16427bSVladimir Kondratiev wil_pmc_alloc(wil, num_descs, desc_size); 918dc16427bSVladimir Kondratiev } else if (0 == strcmp(cmd, "free")) { 919dc16427bSVladimir Kondratiev if (rc != 1) { 920dc16427bSVladimir Kondratiev wil_err(wil, "pmccfg: free does not have any params\n"); 921dc16427bSVladimir Kondratiev return -EINVAL; 922dc16427bSVladimir Kondratiev } 923dc16427bSVladimir Kondratiev wil_pmc_free(wil, true); 924dc16427bSVladimir Kondratiev } else { 925dc16427bSVladimir Kondratiev wil_err(wil, "pmccfg: Unrecognized command \"%s\"\n", cmd); 926dc16427bSVladimir Kondratiev return -EINVAL; 927dc16427bSVladimir Kondratiev } 928dc16427bSVladimir Kondratiev 929dc16427bSVladimir Kondratiev return len; 930dc16427bSVladimir Kondratiev } 931dc16427bSVladimir Kondratiev 932dc16427bSVladimir Kondratiev static ssize_t wil_read_pmccfg(struct file *file, char __user *user_buf, 933dc16427bSVladimir Kondratiev size_t count, loff_t *ppos) 934dc16427bSVladimir Kondratiev { 935dc16427bSVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 936dc16427bSVladimir Kondratiev char text[256]; 937dc16427bSVladimir Kondratiev char help[] = "pmc control, write:\n" 938dc16427bSVladimir Kondratiev " - \"alloc <num descriptors> <descriptor_size>\" to allocate pmc\n" 939dc16427bSVladimir Kondratiev " - \"free\" to free memory allocated for pmc\n"; 940dc16427bSVladimir Kondratiev 941dc16427bSVladimir Kondratiev sprintf(text, "Last command status: %d\n\n%s", 942dc16427bSVladimir Kondratiev wil_pmc_last_cmd_status(wil), 943dc16427bSVladimir Kondratiev help); 944dc16427bSVladimir Kondratiev 945dc16427bSVladimir Kondratiev return simple_read_from_buffer(user_buf, count, ppos, text, 946dc16427bSVladimir Kondratiev strlen(text) + 1); 947dc16427bSVladimir Kondratiev } 948dc16427bSVladimir Kondratiev 949dc16427bSVladimir Kondratiev static const struct file_operations fops_pmccfg = { 950dc16427bSVladimir Kondratiev .read = wil_read_pmccfg, 951dc16427bSVladimir Kondratiev .write = wil_write_pmccfg, 952dc16427bSVladimir Kondratiev .open = simple_open, 953dc16427bSVladimir Kondratiev }; 954dc16427bSVladimir Kondratiev 955dc16427bSVladimir Kondratiev static const struct file_operations fops_pmcdata = { 956dc16427bSVladimir Kondratiev .open = simple_open, 957dc16427bSVladimir Kondratiev .read = wil_pmc_read, 958dc16427bSVladimir Kondratiev .llseek = wil_pmc_llseek, 959dc16427bSVladimir Kondratiev }; 960dc16427bSVladimir Kondratiev 9610b39aaf2SVladimir Kondratiev /*---tx_mgmt---*/ 9620b39aaf2SVladimir Kondratiev /* Write mgmt frame to this file to send it */ 9630b39aaf2SVladimir Kondratiev static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf, 9640b39aaf2SVladimir Kondratiev size_t len, loff_t *ppos) 9650b39aaf2SVladimir Kondratiev { 9660b39aaf2SVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 9670b39aaf2SVladimir Kondratiev struct wiphy *wiphy = wil_to_wiphy(wil); 968e00243faSLior David struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr; 9690b39aaf2SVladimir Kondratiev struct cfg80211_mgmt_tx_params params; 9700b39aaf2SVladimir Kondratiev int rc; 9719a492909SGeliang Tang void *frame; 9728fe59627SVladimir Kondratiev 973ac0e541aSAlexei Avshalom Lazar memset(¶ms, 0, sizeof(params)); 974ac0e541aSAlexei Avshalom Lazar 9756641525cSHamad Kadmany if (!len) 9766641525cSHamad Kadmany return -EINVAL; 9776641525cSHamad Kadmany 9789a492909SGeliang Tang frame = memdup_user(buf, len); 9799a492909SGeliang Tang if (IS_ERR(frame)) 9809a492909SGeliang Tang return PTR_ERR(frame); 9810b39aaf2SVladimir Kondratiev 9820b39aaf2SVladimir Kondratiev params.buf = frame; 9830b39aaf2SVladimir Kondratiev params.len = len; 9840b39aaf2SVladimir Kondratiev 9850b39aaf2SVladimir Kondratiev rc = wil_cfg80211_mgmt_tx(wiphy, wdev, ¶ms, NULL); 9860b39aaf2SVladimir Kondratiev 9870b39aaf2SVladimir Kondratiev kfree(frame); 988af3db60aSLazar Alexei wil_info(wil, "-> %d\n", rc); 9890b39aaf2SVladimir Kondratiev 9900b39aaf2SVladimir Kondratiev return len; 9910b39aaf2SVladimir Kondratiev } 9920b39aaf2SVladimir Kondratiev 9930b39aaf2SVladimir Kondratiev static const struct file_operations fops_txmgmt = { 9940b39aaf2SVladimir Kondratiev .write = wil_write_file_txmgmt, 9950b39aaf2SVladimir Kondratiev .open = simple_open, 9960b39aaf2SVladimir Kondratiev }; 9972be7d22fSVladimir Kondratiev 998ff974e40SVladimir Kondratiev /* Write WMI command (w/o mbox header) to this file to send it 999ff974e40SVladimir Kondratiev * WMI starts from wil6210_mbox_hdr_wmi header 1000ff974e40SVladimir Kondratiev */ 1001ff974e40SVladimir Kondratiev static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf, 1002ff974e40SVladimir Kondratiev size_t len, loff_t *ppos) 1003ff974e40SVladimir Kondratiev { 1004ff974e40SVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 1005e00243faSLior David struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev); 1006b874ddecSLior David struct wmi_cmd_hdr *wmi; 1007ff974e40SVladimir Kondratiev void *cmd; 1008b874ddecSLior David int cmdlen = len - sizeof(struct wmi_cmd_hdr); 1009ff974e40SVladimir Kondratiev u16 cmdid; 1010ff974e40SVladimir Kondratiev int rc, rc1; 1011ff974e40SVladimir Kondratiev 101269218a48SLior David if (cmdlen < 0) 1013ff974e40SVladimir Kondratiev return -EINVAL; 1014ff974e40SVladimir Kondratiev 1015ff974e40SVladimir Kondratiev wmi = kmalloc(len, GFP_KERNEL); 1016ff974e40SVladimir Kondratiev if (!wmi) 1017ff974e40SVladimir Kondratiev return -ENOMEM; 1018ff974e40SVladimir Kondratiev 1019ff974e40SVladimir Kondratiev rc = simple_write_to_buffer(wmi, len, ppos, buf, len); 10208e09b7d2SLino Sanfilippo if (rc < 0) { 10218e09b7d2SLino Sanfilippo kfree(wmi); 1022ff974e40SVladimir Kondratiev return rc; 10238e09b7d2SLino Sanfilippo } 1024ff974e40SVladimir Kondratiev 102569218a48SLior David cmd = (cmdlen > 0) ? &wmi[1] : NULL; 1026b874ddecSLior David cmdid = le16_to_cpu(wmi->command_id); 1027ff974e40SVladimir Kondratiev 1028e00243faSLior David rc1 = wmi_send(wil, cmdid, vif->mid, cmd, cmdlen); 1029ff974e40SVladimir Kondratiev kfree(wmi); 1030ff974e40SVladimir Kondratiev 1031af3db60aSLazar Alexei wil_info(wil, "0x%04x[%d] -> %d\n", cmdid, cmdlen, rc1); 1032ff974e40SVladimir Kondratiev 1033ff974e40SVladimir Kondratiev return rc; 1034ff974e40SVladimir Kondratiev } 1035ff974e40SVladimir Kondratiev 1036ff974e40SVladimir Kondratiev static const struct file_operations fops_wmi = { 1037ff974e40SVladimir Kondratiev .write = wil_write_file_wmi, 1038ff974e40SVladimir Kondratiev .open = simple_open, 1039ff974e40SVladimir Kondratiev }; 1040ff974e40SVladimir Kondratiev 1041c236658fSVladimir Kondratiev static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb) 1042c236658fSVladimir Kondratiev { 1043c236658fSVladimir Kondratiev int i = 0; 1044c236658fSVladimir Kondratiev int len = skb_headlen(skb); 1045c236658fSVladimir Kondratiev void *p = skb->data; 1046c236658fSVladimir Kondratiev int nr_frags = skb_shinfo(skb)->nr_frags; 1047c236658fSVladimir Kondratiev 1048c236658fSVladimir Kondratiev seq_printf(s, " len = %d\n", len); 1049c236658fSVladimir Kondratiev wil_seq_hexdump(s, p, len, " : "); 1050c236658fSVladimir Kondratiev 1051c236658fSVladimir Kondratiev if (nr_frags) { 1052c236658fSVladimir Kondratiev seq_printf(s, " nr_frags = %d\n", nr_frags); 1053c236658fSVladimir Kondratiev for (i = 0; i < nr_frags; i++) { 1054c236658fSVladimir Kondratiev const struct skb_frag_struct *frag = 1055c236658fSVladimir Kondratiev &skb_shinfo(skb)->frags[i]; 1056c236658fSVladimir Kondratiev 1057c236658fSVladimir Kondratiev len = skb_frag_size(frag); 1058c236658fSVladimir Kondratiev p = skb_frag_address_safe(frag); 1059c236658fSVladimir Kondratiev seq_printf(s, " [%2d] : len = %d\n", i, len); 1060c236658fSVladimir Kondratiev wil_seq_hexdump(s, p, len, " : "); 1061c236658fSVladimir Kondratiev } 1062c236658fSVladimir Kondratiev } 1063c236658fSVladimir Kondratiev } 1064c236658fSVladimir Kondratiev 10653a85543eSVladimir Kondratiev /*---------Tx/Rx descriptor------------*/ 1066986b8348SYangtao Li static int txdesc_show(struct seq_file *s, void *data) 10672be7d22fSVladimir Kondratiev { 10682be7d22fSVladimir Kondratiev struct wil6210_priv *wil = s->private; 106910590c6aSGidon Studinski struct wil_ring *ring; 1070d98b8539SMaya Erez bool tx; 1071d98b8539SMaya Erez int ring_idx = dbg_ring_index; 1072d98b8539SMaya Erez int txdesc_idx = dbg_txdesc_index; 1073d98b8539SMaya Erez volatile struct vring_tx_desc *d; 1074d98b8539SMaya Erez volatile u32 *u; 1075d98b8539SMaya Erez struct sk_buff *skb; 10768fe59627SVladimir Kondratiev 1077d98b8539SMaya Erez if (wil->use_enhanced_dma_hw) { 1078d98b8539SMaya Erez /* RX ring index == 0 */ 1079d98b8539SMaya Erez if (ring_idx >= WIL6210_MAX_TX_RINGS) { 1080d98b8539SMaya Erez seq_printf(s, "invalid ring index %d\n", ring_idx); 1081d98b8539SMaya Erez return 0; 1082d98b8539SMaya Erez } 1083d98b8539SMaya Erez tx = ring_idx > 0; /* desc ring 0 is reserved for RX */ 1084d98b8539SMaya Erez } else { 1085d98b8539SMaya Erez /* RX ring index == WIL6210_MAX_TX_RINGS */ 1086d98b8539SMaya Erez if (ring_idx > WIL6210_MAX_TX_RINGS) { 1087d98b8539SMaya Erez seq_printf(s, "invalid ring index %d\n", ring_idx); 1088d98b8539SMaya Erez return 0; 1089d98b8539SMaya Erez } 1090d98b8539SMaya Erez tx = (ring_idx < WIL6210_MAX_TX_RINGS); 1091d98b8539SMaya Erez } 1092d98b8539SMaya Erez 1093d98b8539SMaya Erez ring = tx ? &wil->ring_tx[ring_idx] : &wil->ring_rx; 10942be7d22fSVladimir Kondratiev 109510590c6aSGidon Studinski if (!ring->va) { 1096af31cb5aSVladimir Kondratiev if (tx) 1097d98b8539SMaya Erez seq_printf(s, "No Tx[%2d] RING\n", ring_idx); 10983a85543eSVladimir Kondratiev else 1099d98b8539SMaya Erez seq_puts(s, "No Rx RING\n"); 11002be7d22fSVladimir Kondratiev return 0; 11012be7d22fSVladimir Kondratiev } 11022be7d22fSVladimir Kondratiev 1103d98b8539SMaya Erez if (txdesc_idx >= ring->size) { 1104d98b8539SMaya Erez if (tx) 1105d98b8539SMaya Erez seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n", 1106d98b8539SMaya Erez ring_idx, txdesc_idx, ring->size); 1107d98b8539SMaya Erez else 1108d98b8539SMaya Erez seq_printf(s, "RxDesc index (%d) >= size (%d)\n", 1109d98b8539SMaya Erez txdesc_idx, ring->size); 1110d98b8539SMaya Erez return 0; 1111d98b8539SMaya Erez } 1112d98b8539SMaya Erez 11133a85543eSVladimir Kondratiev /* use struct vring_tx_desc for Rx as well, 11143a85543eSVladimir Kondratiev * only field used, .dma.length, is the same 11153a85543eSVladimir Kondratiev */ 1116d98b8539SMaya Erez d = &ring->va[txdesc_idx].tx.legacy; 1117d98b8539SMaya Erez u = (volatile u32 *)d; 1118d98b8539SMaya Erez skb = NULL; 11192be7d22fSVladimir Kondratiev 1120d98b8539SMaya Erez if (wil->use_enhanced_dma_hw) { 1121d98b8539SMaya Erez if (tx) { 11229a874d04SDedy Lansky skb = ring->ctx ? ring->ctx[txdesc_idx].skb : NULL; 11239a874d04SDedy Lansky } else if (wil->rx_buff_mgmt.buff_arr) { 1124d98b8539SMaya Erez struct wil_rx_enhanced_desc *rx_d = 1125d98b8539SMaya Erez (struct wil_rx_enhanced_desc *) 1126d98b8539SMaya Erez &ring->va[txdesc_idx].rx.enhanced; 1127d98b8539SMaya Erez u16 buff_id = le16_to_cpu(rx_d->mac.buff_id); 1128d98b8539SMaya Erez 1129d98b8539SMaya Erez if (!wil_val_in_range(buff_id, 0, 11309a874d04SDedy Lansky wil->rx_buff_mgmt.size)) 1131d98b8539SMaya Erez seq_printf(s, "invalid buff_id %d\n", buff_id); 11329a874d04SDedy Lansky else 1133d98b8539SMaya Erez skb = wil->rx_buff_mgmt.buff_arr[buff_id].skb; 1134d98b8539SMaya Erez } 1135d98b8539SMaya Erez } else { 1136d98b8539SMaya Erez skb = ring->ctx[txdesc_idx].skb; 1137d98b8539SMaya Erez } 1138af31cb5aSVladimir Kondratiev if (tx) 1139d98b8539SMaya Erez seq_printf(s, "Tx[%2d][%3d] = {\n", ring_idx, 1140d98b8539SMaya Erez txdesc_idx); 11413a85543eSVladimir Kondratiev else 1142d98b8539SMaya Erez seq_printf(s, "Rx[%3d] = {\n", txdesc_idx); 11432be7d22fSVladimir Kondratiev seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n", 11442be7d22fSVladimir Kondratiev u[0], u[1], u[2], u[3]); 11452be7d22fSVladimir Kondratiev seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n", 11462be7d22fSVladimir Kondratiev u[4], u[5], u[6], u[7]); 114739c52ee8SVladimir Kondratiev seq_printf(s, " SKB = 0x%p\n", skb); 11482be7d22fSVladimir Kondratiev 11492be7d22fSVladimir Kondratiev if (skb) { 1150c236658fSVladimir Kondratiev skb_get(skb); 1151c236658fSVladimir Kondratiev wil_seq_print_skb(s, skb); 1152c236658fSVladimir Kondratiev kfree_skb(skb); 11532be7d22fSVladimir Kondratiev } 11548fe59627SVladimir Kondratiev seq_puts(s, "}\n"); 11552be7d22fSVladimir Kondratiev 11562be7d22fSVladimir Kondratiev return 0; 11572be7d22fSVladimir Kondratiev } 1158986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(txdesc); 11592be7d22fSVladimir Kondratiev 1160d98b8539SMaya Erez /*---------Tx/Rx status message------------*/ 1161986b8348SYangtao Li static int status_msg_show(struct seq_file *s, void *data) 1162d98b8539SMaya Erez { 1163d98b8539SMaya Erez struct wil6210_priv *wil = s->private; 1164d98b8539SMaya Erez int sring_idx = dbg_sring_index; 1165d98b8539SMaya Erez struct wil_status_ring *sring; 11669a874d04SDedy Lansky bool tx; 1167d98b8539SMaya Erez u32 status_msg_idx = dbg_status_msg_index; 1168d98b8539SMaya Erez u32 *u; 1169d98b8539SMaya Erez 1170d98b8539SMaya Erez if (sring_idx >= WIL6210_MAX_STATUS_RINGS) { 1171d98b8539SMaya Erez seq_printf(s, "invalid status ring index %d\n", sring_idx); 1172d98b8539SMaya Erez return 0; 1173d98b8539SMaya Erez } 1174d98b8539SMaya Erez 1175d98b8539SMaya Erez sring = &wil->srings[sring_idx]; 11769a874d04SDedy Lansky tx = !sring->is_rx; 1177d98b8539SMaya Erez 1178d98b8539SMaya Erez if (!sring->va) { 1179d98b8539SMaya Erez seq_printf(s, "No %cX status ring\n", tx ? 'T' : 'R'); 1180d98b8539SMaya Erez return 0; 1181d98b8539SMaya Erez } 1182d98b8539SMaya Erez 1183d98b8539SMaya Erez if (status_msg_idx >= sring->size) { 1184d98b8539SMaya Erez seq_printf(s, "%cxDesc index (%d) >= size (%d)\n", 1185d98b8539SMaya Erez tx ? 'T' : 'R', status_msg_idx, sring->size); 1186d98b8539SMaya Erez return 0; 1187d98b8539SMaya Erez } 1188d98b8539SMaya Erez 1189d98b8539SMaya Erez u = sring->va + (sring->elem_size * status_msg_idx); 1190d98b8539SMaya Erez 1191d98b8539SMaya Erez seq_printf(s, "%cx[%d][%3d] = {\n", 1192d98b8539SMaya Erez tx ? 'T' : 'R', sring_idx, status_msg_idx); 1193d98b8539SMaya Erez 1194d98b8539SMaya Erez seq_printf(s, " 0x%08x 0x%08x 0x%08x 0x%08x\n", 1195d98b8539SMaya Erez u[0], u[1], u[2], u[3]); 1196d98b8539SMaya Erez if (!tx && !wil->use_compressed_rx_status) 1197d98b8539SMaya Erez seq_printf(s, " 0x%08x 0x%08x 0x%08x 0x%08x\n", 1198d98b8539SMaya Erez u[4], u[5], u[6], u[7]); 1199d98b8539SMaya Erez 1200d98b8539SMaya Erez seq_puts(s, "}\n"); 1201d98b8539SMaya Erez 1202d98b8539SMaya Erez return 0; 1203d98b8539SMaya Erez } 1204986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(status_msg); 1205d98b8539SMaya Erez 1206d98b8539SMaya Erez static int wil_print_rx_buff(struct seq_file *s, struct list_head *lh) 1207d98b8539SMaya Erez { 1208d98b8539SMaya Erez struct wil_rx_buff *it; 1209d98b8539SMaya Erez int i = 0; 1210d98b8539SMaya Erez 1211d98b8539SMaya Erez list_for_each_entry(it, lh, list) { 1212d98b8539SMaya Erez if ((i % 16) == 0 && i != 0) 1213d98b8539SMaya Erez seq_puts(s, "\n "); 1214d98b8539SMaya Erez seq_printf(s, "[%4d] ", it->id); 1215d98b8539SMaya Erez i++; 1216d98b8539SMaya Erez } 1217d98b8539SMaya Erez seq_printf(s, "\nNumber of buffers: %u\n", i); 1218d98b8539SMaya Erez 1219d98b8539SMaya Erez return i; 1220d98b8539SMaya Erez } 1221d98b8539SMaya Erez 1222986b8348SYangtao Li static int rx_buff_mgmt_show(struct seq_file *s, void *data) 1223d98b8539SMaya Erez { 1224d98b8539SMaya Erez struct wil6210_priv *wil = s->private; 1225d98b8539SMaya Erez struct wil_rx_buff_mgmt *rbm = &wil->rx_buff_mgmt; 1226d98b8539SMaya Erez int num_active; 1227d98b8539SMaya Erez int num_free; 1228d98b8539SMaya Erez 12294405b632SDedy Lansky if (!rbm->buff_arr) 12304405b632SDedy Lansky return -EINVAL; 12314405b632SDedy Lansky 1232d98b8539SMaya Erez seq_printf(s, " size = %zu\n", rbm->size); 1233d98b8539SMaya Erez seq_printf(s, " free_list_empty_cnt = %lu\n", 1234d98b8539SMaya Erez rbm->free_list_empty_cnt); 1235d98b8539SMaya Erez 1236d98b8539SMaya Erez /* Print active list */ 1237d98b8539SMaya Erez seq_puts(s, " Active list:\n"); 1238d98b8539SMaya Erez num_active = wil_print_rx_buff(s, &rbm->active); 1239d98b8539SMaya Erez seq_puts(s, "\n Free list:\n"); 1240d98b8539SMaya Erez num_free = wil_print_rx_buff(s, &rbm->free); 1241d98b8539SMaya Erez 1242d98b8539SMaya Erez seq_printf(s, " Total number of buffers: %u\n", 1243d98b8539SMaya Erez num_active + num_free); 1244d98b8539SMaya Erez 1245d98b8539SMaya Erez return 0; 1246d98b8539SMaya Erez } 1247986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(rx_buff_mgmt); 1248d98b8539SMaya Erez 12492be7d22fSVladimir Kondratiev /*---------beamforming------------*/ 125036345ac3SVladimir Kondratiev static char *wil_bfstatus_str(u32 status) 125136345ac3SVladimir Kondratiev { 125236345ac3SVladimir Kondratiev switch (status) { 125336345ac3SVladimir Kondratiev case 0: 125436345ac3SVladimir Kondratiev return "Failed"; 125536345ac3SVladimir Kondratiev case 1: 125636345ac3SVladimir Kondratiev return "OK"; 125736345ac3SVladimir Kondratiev case 2: 125836345ac3SVladimir Kondratiev return "Retrying"; 125936345ac3SVladimir Kondratiev default: 126036345ac3SVladimir Kondratiev return "??"; 126136345ac3SVladimir Kondratiev } 126236345ac3SVladimir Kondratiev } 126336345ac3SVladimir Kondratiev 126436345ac3SVladimir Kondratiev static bool is_all_zeros(void * const x_, size_t sz) 126536345ac3SVladimir Kondratiev { 126636345ac3SVladimir Kondratiev /* if reply is all-0, ignore this CID */ 126736345ac3SVladimir Kondratiev u32 *x = x_; 126836345ac3SVladimir Kondratiev int n; 126936345ac3SVladimir Kondratiev 127036345ac3SVladimir Kondratiev for (n = 0; n < sz / sizeof(*x); n++) 127136345ac3SVladimir Kondratiev if (x[n]) 127236345ac3SVladimir Kondratiev return false; 127336345ac3SVladimir Kondratiev 127436345ac3SVladimir Kondratiev return true; 127536345ac3SVladimir Kondratiev } 127636345ac3SVladimir Kondratiev 1277986b8348SYangtao Li static int bf_show(struct seq_file *s, void *data) 12782be7d22fSVladimir Kondratiev { 127936345ac3SVladimir Kondratiev int rc; 128036345ac3SVladimir Kondratiev int i; 12812be7d22fSVladimir Kondratiev struct wil6210_priv *wil = s->private; 1282e00243faSLior David struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev); 128336345ac3SVladimir Kondratiev struct wmi_notify_req_cmd cmd = { 128436345ac3SVladimir Kondratiev .interval_usec = 0, 128536345ac3SVladimir Kondratiev }; 128636345ac3SVladimir Kondratiev struct { 1287b874ddecSLior David struct wmi_cmd_hdr wmi; 128836345ac3SVladimir Kondratiev struct wmi_notify_req_done_event evt; 128936345ac3SVladimir Kondratiev } __packed reply; 129036345ac3SVladimir Kondratiev 1291807b0860SAlexei Avshalom Lazar memset(&reply, 0, sizeof(reply)); 1292807b0860SAlexei Avshalom Lazar 1293*ddf7afddSAhmad Masri for (i = 0; i < wil->max_assoc_sta; i++) { 129436345ac3SVladimir Kondratiev u32 status; 129536345ac3SVladimir Kondratiev 129636345ac3SVladimir Kondratiev cmd.cid = i; 1297e00243faSLior David rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, vif->mid, 1298e00243faSLior David &cmd, sizeof(cmd), 129936345ac3SVladimir Kondratiev WMI_NOTIFY_REQ_DONE_EVENTID, &reply, 130036345ac3SVladimir Kondratiev sizeof(reply), 20); 130136345ac3SVladimir Kondratiev /* if reply is all-0, ignore this CID */ 130236345ac3SVladimir Kondratiev if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt))) 130336345ac3SVladimir Kondratiev continue; 130436345ac3SVladimir Kondratiev 130536345ac3SVladimir Kondratiev status = le32_to_cpu(reply.evt.status); 130636345ac3SVladimir Kondratiev seq_printf(s, "CID %d {\n" 130736345ac3SVladimir Kondratiev " TSF = 0x%016llx\n" 130836345ac3SVladimir Kondratiev " TxMCS = %2d TxTpt = %4d\n" 130936345ac3SVladimir Kondratiev " SQI = %4d\n" 131030868f5dSDedy Lansky " RSSI = %4d\n" 131136345ac3SVladimir Kondratiev " Status = 0x%08x %s\n" 131236345ac3SVladimir Kondratiev " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n" 131336345ac3SVladimir Kondratiev " Goodput(rx:tx) %4d:%4d\n" 131436345ac3SVladimir Kondratiev "}\n", 131536345ac3SVladimir Kondratiev i, 131636345ac3SVladimir Kondratiev le64_to_cpu(reply.evt.tsf), 131736345ac3SVladimir Kondratiev le16_to_cpu(reply.evt.bf_mcs), 131836345ac3SVladimir Kondratiev le32_to_cpu(reply.evt.tx_tpt), 131936345ac3SVladimir Kondratiev reply.evt.sqi, 132030868f5dSDedy Lansky reply.evt.rssi, 132136345ac3SVladimir Kondratiev status, wil_bfstatus_str(status), 132236345ac3SVladimir Kondratiev le16_to_cpu(reply.evt.my_rx_sector), 132336345ac3SVladimir Kondratiev le16_to_cpu(reply.evt.my_tx_sector), 132436345ac3SVladimir Kondratiev le16_to_cpu(reply.evt.other_rx_sector), 132536345ac3SVladimir Kondratiev le16_to_cpu(reply.evt.other_tx_sector), 132636345ac3SVladimir Kondratiev le32_to_cpu(reply.evt.rx_goodput), 132736345ac3SVladimir Kondratiev le32_to_cpu(reply.evt.tx_goodput)); 132836345ac3SVladimir Kondratiev } 13292be7d22fSVladimir Kondratiev return 0; 13302be7d22fSVladimir Kondratiev } 1331986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(bf); 13328fe59627SVladimir Kondratiev 13331a2780e0SVladimir Kondratiev /*---------temp------------*/ 13346d9eb7ebSDedy Lansky static void print_temp(struct seq_file *s, const char *prefix, s32 t) 13351a2780e0SVladimir Kondratiev { 13361a2780e0SVladimir Kondratiev switch (t) { 13371a2780e0SVladimir Kondratiev case 0: 13381a2780e0SVladimir Kondratiev case ~(u32)0: 13391a2780e0SVladimir Kondratiev seq_printf(s, "%s N/A\n", prefix); 13401a2780e0SVladimir Kondratiev break; 13411a2780e0SVladimir Kondratiev default: 13426d9eb7ebSDedy Lansky seq_printf(s, "%s %s%d.%03d\n", prefix, (t < 0 ? "-" : ""), 13436d9eb7ebSDedy Lansky abs(t / 1000), abs(t % 1000)); 13441a2780e0SVladimir Kondratiev break; 13451a2780e0SVladimir Kondratiev } 13461a2780e0SVladimir Kondratiev } 13471a2780e0SVladimir Kondratiev 1348986b8348SYangtao Li static int temp_show(struct seq_file *s, void *data) 13491a2780e0SVladimir Kondratiev { 13501a2780e0SVladimir Kondratiev struct wil6210_priv *wil = s->private; 13516d9eb7ebSDedy Lansky s32 t_m, t_r; 13521a2780e0SVladimir Kondratiev int rc = wmi_get_temperature(wil, &t_m, &t_r); 13538fe59627SVladimir Kondratiev 13541a2780e0SVladimir Kondratiev if (rc) { 13558fe59627SVladimir Kondratiev seq_puts(s, "Failed\n"); 13561a2780e0SVladimir Kondratiev return 0; 13571a2780e0SVladimir Kondratiev } 13581a2780e0SVladimir Kondratiev 1359d45cff9fSVladimir Kondratiev print_temp(s, "T_mac =", t_m); 1360d45cff9fSVladimir Kondratiev print_temp(s, "T_radio =", t_r); 13611a2780e0SVladimir Kondratiev 13621a2780e0SVladimir Kondratiev return 0; 13631a2780e0SVladimir Kondratiev } 1364986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(temp); 13651a2780e0SVladimir Kondratiev 13669eb82d43SVladimir Kondratiev /*---------freq------------*/ 1367986b8348SYangtao Li static int freq_show(struct seq_file *s, void *data) 13689eb82d43SVladimir Kondratiev { 13699eb82d43SVladimir Kondratiev struct wil6210_priv *wil = s->private; 1370e00243faSLior David struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr; 13719cf0a0b4SAlexei Avshalom Lazar u32 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0; 13729eb82d43SVladimir Kondratiev 13739eb82d43SVladimir Kondratiev seq_printf(s, "Freq = %d\n", freq); 13749eb82d43SVladimir Kondratiev 13759eb82d43SVladimir Kondratiev return 0; 13769eb82d43SVladimir Kondratiev } 1377986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(freq); 13789eb82d43SVladimir Kondratiev 13799eb82d43SVladimir Kondratiev /*---------link------------*/ 1380986b8348SYangtao Li static int link_show(struct seq_file *s, void *data) 13819eb82d43SVladimir Kondratiev { 13829eb82d43SVladimir Kondratiev struct wil6210_priv *wil = s->private; 138341bd3d58SToke Høiland-Jørgensen struct station_info *sinfo; 138441bd3d58SToke Høiland-Jørgensen int i, rc = 0; 138541bd3d58SToke Høiland-Jørgensen 138641bd3d58SToke Høiland-Jørgensen sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL); 138741bd3d58SToke Høiland-Jørgensen if (!sinfo) 138841bd3d58SToke Høiland-Jørgensen return -ENOMEM; 13899eb82d43SVladimir Kondratiev 1390*ddf7afddSAhmad Masri for (i = 0; i < wil->max_assoc_sta; i++) { 13919eb82d43SVladimir Kondratiev struct wil_sta_info *p = &wil->sta[i]; 13929eb82d43SVladimir Kondratiev char *status = "unknown"; 13935bd60982SLior David struct wil6210_vif *vif; 13945bd60982SLior David u8 mid; 13958fe59627SVladimir Kondratiev 13969eb82d43SVladimir Kondratiev switch (p->status) { 13979eb82d43SVladimir Kondratiev case wil_sta_unused: 13989eb82d43SVladimir Kondratiev status = "unused "; 13999eb82d43SVladimir Kondratiev break; 14009eb82d43SVladimir Kondratiev case wil_sta_conn_pending: 14019eb82d43SVladimir Kondratiev status = "pending "; 14029eb82d43SVladimir Kondratiev break; 14039eb82d43SVladimir Kondratiev case wil_sta_connected: 14049eb82d43SVladimir Kondratiev status = "connected"; 14059eb82d43SVladimir Kondratiev break; 14069eb82d43SVladimir Kondratiev } 14075bd60982SLior David mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX; 14085bd60982SLior David seq_printf(s, "[%d][MID %d] %pM %s\n", 14095bd60982SLior David i, mid, p->addr, status); 14109eb82d43SVladimir Kondratiev 14115bd60982SLior David if (p->status != wil_sta_connected) 14125bd60982SLior David continue; 14135bd60982SLior David 1414e4a29bddSAhmad Masri vif = (mid < GET_MAX_VIFS(wil)) ? wil->vifs[mid] : NULL; 14155bd60982SLior David if (vif) { 141641bd3d58SToke Høiland-Jørgensen rc = wil_cid_fill_sinfo(vif, i, sinfo); 14179eb82d43SVladimir Kondratiev if (rc) 141841bd3d58SToke Høiland-Jørgensen goto out; 14199eb82d43SVladimir Kondratiev 142041bd3d58SToke Høiland-Jørgensen seq_printf(s, " Tx_mcs = %d\n", sinfo->txrate.mcs); 142141bd3d58SToke Høiland-Jørgensen seq_printf(s, " Rx_mcs = %d\n", sinfo->rxrate.mcs); 142241bd3d58SToke Høiland-Jørgensen seq_printf(s, " SQ = %d\n", sinfo->signal); 14235bd60982SLior David } else { 14245bd60982SLior David seq_puts(s, " INVALID MID\n"); 14259eb82d43SVladimir Kondratiev } 14269eb82d43SVladimir Kondratiev } 14279eb82d43SVladimir Kondratiev 142841bd3d58SToke Høiland-Jørgensen out: 142941bd3d58SToke Høiland-Jørgensen kfree(sinfo); 143041bd3d58SToke Høiland-Jørgensen return rc; 14319eb82d43SVladimir Kondratiev } 1432986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(link); 14339eb82d43SVladimir Kondratiev 143484bb29b7SVladimir Kondratiev /*---------info------------*/ 1435986b8348SYangtao Li static int info_show(struct seq_file *s, void *data) 143684bb29b7SVladimir Kondratiev { 1437be299858SVladimir Kondratiev struct wil6210_priv *wil = s->private; 1438e00243faSLior David struct net_device *ndev = wil->main_ndev; 143984bb29b7SVladimir Kondratiev int is_ac = power_supply_is_system_supplied(); 1440be299858SVladimir Kondratiev int rx = atomic_xchg(&wil->isr_count_rx, 0); 1441be299858SVladimir Kondratiev int tx = atomic_xchg(&wil->isr_count_tx, 0); 1442be299858SVladimir Kondratiev static ulong rxf_old, txf_old; 1443be299858SVladimir Kondratiev ulong rxf = ndev->stats.rx_packets; 1444be299858SVladimir Kondratiev ulong txf = ndev->stats.tx_packets; 144555f8f680SVladimir Kondratiev unsigned int i; 144684bb29b7SVladimir Kondratiev 144784bb29b7SVladimir Kondratiev /* >0 : AC; 0 : battery; <0 : error */ 144884bb29b7SVladimir Kondratiev seq_printf(s, "AC powered : %d\n", is_ac); 1449be299858SVladimir Kondratiev seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old); 1450be299858SVladimir Kondratiev seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old); 1451be299858SVladimir Kondratiev rxf_old = rxf; 1452be299858SVladimir Kondratiev txf_old = txf; 145384bb29b7SVladimir Kondratiev 145455f8f680SVladimir Kondratiev #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \ 145555f8f680SVladimir Kondratiev " " __stringify(x) : "" 145655f8f680SVladimir Kondratiev 145755f8f680SVladimir Kondratiev for (i = 0; i < ndev->num_tx_queues; i++) { 145855f8f680SVladimir Kondratiev struct netdev_queue *txq = netdev_get_tx_queue(ndev, i); 145955f8f680SVladimir Kondratiev unsigned long state = txq->state; 146055f8f680SVladimir Kondratiev 146155f8f680SVladimir Kondratiev seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state, 146255f8f680SVladimir Kondratiev CHECK_QSTATE(DRV_XOFF), 146355f8f680SVladimir Kondratiev CHECK_QSTATE(STACK_XOFF), 146455f8f680SVladimir Kondratiev CHECK_QSTATE(FROZEN) 146555f8f680SVladimir Kondratiev ); 146655f8f680SVladimir Kondratiev } 146755f8f680SVladimir Kondratiev #undef CHECK_QSTATE 146884bb29b7SVladimir Kondratiev return 0; 146984bb29b7SVladimir Kondratiev } 1470986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(info); 147184bb29b7SVladimir Kondratiev 1472c33407a8SVladimir Kondratiev /*---------recovery------------*/ 1473c33407a8SVladimir Kondratiev /* mode = [manual|auto] 1474c33407a8SVladimir Kondratiev * state = [idle|pending|running] 1475c33407a8SVladimir Kondratiev */ 1476c33407a8SVladimir Kondratiev static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf, 1477c33407a8SVladimir Kondratiev size_t count, loff_t *ppos) 1478c33407a8SVladimir Kondratiev { 1479c33407a8SVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 1480c33407a8SVladimir Kondratiev char buf[80]; 1481c33407a8SVladimir Kondratiev int n; 1482c33407a8SVladimir Kondratiev static const char * const sstate[] = {"idle", "pending", "running"}; 1483c33407a8SVladimir Kondratiev 1484c33407a8SVladimir Kondratiev n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n", 1485c33407a8SVladimir Kondratiev no_fw_recovery ? "manual" : "auto", 1486c33407a8SVladimir Kondratiev sstate[wil->recovery_state]); 1487c33407a8SVladimir Kondratiev 1488c33407a8SVladimir Kondratiev n = min_t(int, n, sizeof(buf)); 1489c33407a8SVladimir Kondratiev 1490c33407a8SVladimir Kondratiev return simple_read_from_buffer(user_buf, count, ppos, 1491c33407a8SVladimir Kondratiev buf, n); 1492c33407a8SVladimir Kondratiev } 1493c33407a8SVladimir Kondratiev 1494c33407a8SVladimir Kondratiev static ssize_t wil_write_file_recovery(struct file *file, 1495c33407a8SVladimir Kondratiev const char __user *buf_, 1496c33407a8SVladimir Kondratiev size_t count, loff_t *ppos) 1497c33407a8SVladimir Kondratiev { 1498c33407a8SVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 1499c33407a8SVladimir Kondratiev static const char run_command[] = "run"; 1500c33407a8SVladimir Kondratiev char buf[sizeof(run_command) + 1]; /* to detect "runx" */ 1501c33407a8SVladimir Kondratiev ssize_t rc; 1502c33407a8SVladimir Kondratiev 1503c33407a8SVladimir Kondratiev if (wil->recovery_state != fw_recovery_pending) { 1504c33407a8SVladimir Kondratiev wil_err(wil, "No recovery pending\n"); 1505c33407a8SVladimir Kondratiev return -EINVAL; 1506c33407a8SVladimir Kondratiev } 1507c33407a8SVladimir Kondratiev 1508c33407a8SVladimir Kondratiev if (*ppos != 0) { 1509c33407a8SVladimir Kondratiev wil_err(wil, "Offset [%d]\n", (int)*ppos); 1510c33407a8SVladimir Kondratiev return -EINVAL; 1511c33407a8SVladimir Kondratiev } 1512c33407a8SVladimir Kondratiev 1513c33407a8SVladimir Kondratiev if (count > sizeof(buf)) { 1514c33407a8SVladimir Kondratiev wil_err(wil, "Input too long, len = %d\n", (int)count); 1515c33407a8SVladimir Kondratiev return -EINVAL; 1516c33407a8SVladimir Kondratiev } 1517c33407a8SVladimir Kondratiev 1518c33407a8SVladimir Kondratiev rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count); 1519c33407a8SVladimir Kondratiev if (rc < 0) 1520c33407a8SVladimir Kondratiev return rc; 1521c33407a8SVladimir Kondratiev 1522c33407a8SVladimir Kondratiev buf[rc] = '\0'; 1523c33407a8SVladimir Kondratiev if (0 == strcmp(buf, run_command)) 1524c33407a8SVladimir Kondratiev wil_set_recovery_state(wil, fw_recovery_running); 1525c33407a8SVladimir Kondratiev else 1526c33407a8SVladimir Kondratiev wil_err(wil, "Bad recovery command \"%s\"\n", buf); 1527c33407a8SVladimir Kondratiev 1528c33407a8SVladimir Kondratiev return rc; 1529c33407a8SVladimir Kondratiev } 1530c33407a8SVladimir Kondratiev 1531c33407a8SVladimir Kondratiev static const struct file_operations fops_recovery = { 1532c33407a8SVladimir Kondratiev .read = wil_read_file_recovery, 1533c33407a8SVladimir Kondratiev .write = wil_write_file_recovery, 1534c33407a8SVladimir Kondratiev .open = simple_open, 1535c33407a8SVladimir Kondratiev }; 1536c33407a8SVladimir Kondratiev 15373df2cd36SVladimir Kondratiev /*---------Station matrix------------*/ 1538b4490f42SVladimir Kondratiev static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r) 1539b4490f42SVladimir Kondratiev { 1540b4490f42SVladimir Kondratiev int i; 1541b4490f42SVladimir Kondratiev u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size; 154291a8edccSVladimir Kondratiev unsigned long long drop_dup = r->drop_dup, drop_old = r->drop_old; 15431bd82ee0SDedy Lansky unsigned long long drop_dup_mcast = r->drop_dup_mcast; 15448fe59627SVladimir Kondratiev 154537f8d26dSDedy Lansky seq_printf(s, "([%2d]) 0x%03x [", r->buf_size, r->head_seq_num); 1546b4490f42SVladimir Kondratiev for (i = 0; i < r->buf_size; i++) { 1547b4490f42SVladimir Kondratiev if (i == index) 1548b4490f42SVladimir Kondratiev seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|'); 1549b4490f42SVladimir Kondratiev else 1550b4490f42SVladimir Kondratiev seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_'); 1551b4490f42SVladimir Kondratiev } 155291a8edccSVladimir Kondratiev seq_printf(s, 15531bd82ee0SDedy Lansky "] total %llu drop %llu (dup %llu + old %llu + dup mcast %llu) last 0x%03x\n", 15541bd82ee0SDedy Lansky r->total, drop_dup + drop_old + drop_dup_mcast, drop_dup, 15551bd82ee0SDedy Lansky drop_old, drop_dup_mcast, r->ssn_last_drop); 1556b4490f42SVladimir Kondratiev } 15573df2cd36SVladimir Kondratiev 155858527421SVladimir Kondratiev static void wil_print_rxtid_crypto(struct seq_file *s, int tid, 155958527421SVladimir Kondratiev struct wil_tid_crypto_rx *c) 156058527421SVladimir Kondratiev { 156158527421SVladimir Kondratiev int i; 156258527421SVladimir Kondratiev 156358527421SVladimir Kondratiev for (i = 0; i < 4; i++) { 156458527421SVladimir Kondratiev struct wil_tid_crypto_rx_single *cc = &c->key_id[i]; 156558527421SVladimir Kondratiev 156658527421SVladimir Kondratiev if (cc->key_set) 156758527421SVladimir Kondratiev goto has_keys; 156858527421SVladimir Kondratiev } 156958527421SVladimir Kondratiev return; 157058527421SVladimir Kondratiev 157158527421SVladimir Kondratiev has_keys: 157258527421SVladimir Kondratiev if (tid < WIL_STA_TID_NUM) 157358527421SVladimir Kondratiev seq_printf(s, " [%2d] PN", tid); 157458527421SVladimir Kondratiev else 157558527421SVladimir Kondratiev seq_puts(s, " [GR] PN"); 157658527421SVladimir Kondratiev 157758527421SVladimir Kondratiev for (i = 0; i < 4; i++) { 157858527421SVladimir Kondratiev struct wil_tid_crypto_rx_single *cc = &c->key_id[i]; 157958527421SVladimir Kondratiev 158058527421SVladimir Kondratiev seq_printf(s, " [%i%s]%6phN", i, cc->key_set ? "+" : "-", 158158527421SVladimir Kondratiev cc->pn); 158258527421SVladimir Kondratiev } 158358527421SVladimir Kondratiev seq_puts(s, "\n"); 158458527421SVladimir Kondratiev } 158558527421SVladimir Kondratiev 1586986b8348SYangtao Li static int sta_show(struct seq_file *s, void *data) 1587bd33273bSVladimir Kondratiev __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock) 15883df2cd36SVladimir Kondratiev { 15893df2cd36SVladimir Kondratiev struct wil6210_priv *wil = s->private; 1590c4a110d8SVladimir Kondratiev int i, tid, mcs; 15913df2cd36SVladimir Kondratiev 1592*ddf7afddSAhmad Masri for (i = 0; i < wil->max_assoc_sta; i++) { 15933df2cd36SVladimir Kondratiev struct wil_sta_info *p = &wil->sta[i]; 15943df2cd36SVladimir Kondratiev char *status = "unknown"; 15959d865ee2SLior David u8 aid = 0; 15965bd60982SLior David u8 mid; 1597b9010f10SAhmad Masri bool sta_connected = false; 15988fe59627SVladimir Kondratiev 15993df2cd36SVladimir Kondratiev switch (p->status) { 16003df2cd36SVladimir Kondratiev case wil_sta_unused: 16013df2cd36SVladimir Kondratiev status = "unused "; 16023df2cd36SVladimir Kondratiev break; 16033df2cd36SVladimir Kondratiev case wil_sta_conn_pending: 16043df2cd36SVladimir Kondratiev status = "pending "; 16053df2cd36SVladimir Kondratiev break; 16063df2cd36SVladimir Kondratiev case wil_sta_connected: 16073df2cd36SVladimir Kondratiev status = "connected"; 16089d865ee2SLior David aid = p->aid; 16093df2cd36SVladimir Kondratiev break; 16103df2cd36SVladimir Kondratiev } 16115bd60982SLior David mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX; 1612e4a29bddSAhmad Masri if (mid < GET_MAX_VIFS(wil)) { 1613b9010f10SAhmad Masri struct wil6210_vif *vif = wil->vifs[mid]; 1614b9010f10SAhmad Masri 1615b9010f10SAhmad Masri if (vif->wdev.iftype == NL80211_IFTYPE_STATION && 1616b9010f10SAhmad Masri p->status == wil_sta_connected) 1617b9010f10SAhmad Masri sta_connected = true; 1618b9010f10SAhmad Masri } 1619b9010f10SAhmad Masri /* print roam counter only for connected stations */ 1620b9010f10SAhmad Masri if (sta_connected) 1621b9010f10SAhmad Masri seq_printf(s, "[%d] %pM connected (roam counter %d) MID %d AID %d\n", 1622b9010f10SAhmad Masri i, p->addr, p->stats.ft_roams, mid, aid); 1623b9010f10SAhmad Masri else 1624b9010f10SAhmad Masri seq_printf(s, "[%d] %pM %s MID %d AID %d\n", i, 1625b9010f10SAhmad Masri p->addr, status, mid, aid); 1626b4490f42SVladimir Kondratiev 1627b4490f42SVladimir Kondratiev if (p->status == wil_sta_connected) { 1628bd33273bSVladimir Kondratiev spin_lock_bh(&p->tid_rx_lock); 1629b4490f42SVladimir Kondratiev for (tid = 0; tid < WIL_STA_TID_NUM; tid++) { 1630b4490f42SVladimir Kondratiev struct wil_tid_ampdu_rx *r = p->tid_rx[tid]; 163158527421SVladimir Kondratiev struct wil_tid_crypto_rx *c = 163258527421SVladimir Kondratiev &p->tid_crypto_rx[tid]; 16338fe59627SVladimir Kondratiev 1634b4490f42SVladimir Kondratiev if (r) { 1635b4490f42SVladimir Kondratiev seq_printf(s, " [%2d] ", tid); 1636b4490f42SVladimir Kondratiev wil_print_rxtid(s, r); 1637b4490f42SVladimir Kondratiev } 163858527421SVladimir Kondratiev 163958527421SVladimir Kondratiev wil_print_rxtid_crypto(s, tid, c); 1640b4490f42SVladimir Kondratiev } 164158527421SVladimir Kondratiev wil_print_rxtid_crypto(s, WIL_STA_TID_NUM, 164258527421SVladimir Kondratiev &p->group_crypto_rx); 1643bd33273bSVladimir Kondratiev spin_unlock_bh(&p->tid_rx_lock); 16443b282bc6SVladimir Kondratiev seq_printf(s, 164558527421SVladimir Kondratiev "Rx invalid frame: non-data %lu, short %lu, large %lu, replay %lu\n", 16463b282bc6SVladimir Kondratiev p->stats.rx_non_data_frame, 16473b282bc6SVladimir Kondratiev p->stats.rx_short_frame, 164858527421SVladimir Kondratiev p->stats.rx_large_frame, 164958527421SVladimir Kondratiev p->stats.rx_replay); 1650d98b8539SMaya Erez seq_printf(s, 16510b853210SMaya Erez "mic error %lu, key error %lu, amsdu error %lu, csum error %lu\n", 1652d98b8539SMaya Erez p->stats.rx_mic_error, 1653d98b8539SMaya Erez p->stats.rx_key_error, 16540b853210SMaya Erez p->stats.rx_amsdu_error, 16550b853210SMaya Erez p->stats.rx_csum_err); 1656d98b8539SMaya Erez 1657c4a110d8SVladimir Kondratiev seq_puts(s, "Rx/MCS:"); 1658c4a110d8SVladimir Kondratiev for (mcs = 0; mcs < ARRAY_SIZE(p->stats.rx_per_mcs); 1659c4a110d8SVladimir Kondratiev mcs++) 1660c4a110d8SVladimir Kondratiev seq_printf(s, " %lld", 1661c4a110d8SVladimir Kondratiev p->stats.rx_per_mcs[mcs]); 1662c4a110d8SVladimir Kondratiev seq_puts(s, "\n"); 1663b4490f42SVladimir Kondratiev } 16643df2cd36SVladimir Kondratiev } 16653df2cd36SVladimir Kondratiev 16663df2cd36SVladimir Kondratiev return 0; 16673df2cd36SVladimir Kondratiev } 1668986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(sta); 16693df2cd36SVladimir Kondratiev 1670986b8348SYangtao Li static int mids_show(struct seq_file *s, void *data) 16713a3b745fSLior David { 16723a3b745fSLior David struct wil6210_priv *wil = s->private; 16733a3b745fSLior David struct wil6210_vif *vif; 16743a3b745fSLior David struct net_device *ndev; 16753a3b745fSLior David int i; 16763a3b745fSLior David 16773a3b745fSLior David mutex_lock(&wil->vif_mutex); 1678e4a29bddSAhmad Masri for (i = 0; i < GET_MAX_VIFS(wil); i++) { 16793a3b745fSLior David vif = wil->vifs[i]; 16803a3b745fSLior David 16813a3b745fSLior David if (vif) { 16823a3b745fSLior David ndev = vif_to_ndev(vif); 16833a3b745fSLior David seq_printf(s, "[%d] %pM %s\n", i, ndev->dev_addr, 16843a3b745fSLior David ndev->name); 16853a3b745fSLior David } else { 16863a3b745fSLior David seq_printf(s, "[%d] unused\n", i); 16873a3b745fSLior David } 16883a3b745fSLior David } 16893a3b745fSLior David mutex_unlock(&wil->vif_mutex); 16903a3b745fSLior David 16913a3b745fSLior David return 0; 16923a3b745fSLior David } 1693986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(mids); 16943a3b745fSLior David 1695a24a3d6aSDedy Lansky static int wil_tx_latency_debugfs_show(struct seq_file *s, void *data) 1696a24a3d6aSDedy Lansky __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock) 1697a24a3d6aSDedy Lansky { 1698a24a3d6aSDedy Lansky struct wil6210_priv *wil = s->private; 1699a24a3d6aSDedy Lansky int i, bin; 1700a24a3d6aSDedy Lansky 1701*ddf7afddSAhmad Masri for (i = 0; i < wil->max_assoc_sta; i++) { 1702a24a3d6aSDedy Lansky struct wil_sta_info *p = &wil->sta[i]; 1703a24a3d6aSDedy Lansky char *status = "unknown"; 1704a24a3d6aSDedy Lansky u8 aid = 0; 1705a24a3d6aSDedy Lansky u8 mid; 1706a24a3d6aSDedy Lansky 1707a24a3d6aSDedy Lansky if (!p->tx_latency_bins) 1708a24a3d6aSDedy Lansky continue; 1709a24a3d6aSDedy Lansky 1710a24a3d6aSDedy Lansky switch (p->status) { 1711a24a3d6aSDedy Lansky case wil_sta_unused: 1712a24a3d6aSDedy Lansky status = "unused "; 1713a24a3d6aSDedy Lansky break; 1714a24a3d6aSDedy Lansky case wil_sta_conn_pending: 1715a24a3d6aSDedy Lansky status = "pending "; 1716a24a3d6aSDedy Lansky break; 1717a24a3d6aSDedy Lansky case wil_sta_connected: 1718a24a3d6aSDedy Lansky status = "connected"; 1719a24a3d6aSDedy Lansky aid = p->aid; 1720a24a3d6aSDedy Lansky break; 1721a24a3d6aSDedy Lansky } 1722a24a3d6aSDedy Lansky mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX; 1723a24a3d6aSDedy Lansky seq_printf(s, "[%d] %pM %s MID %d AID %d\n", i, p->addr, status, 1724a24a3d6aSDedy Lansky mid, aid); 1725a24a3d6aSDedy Lansky 1726a24a3d6aSDedy Lansky if (p->status == wil_sta_connected) { 1727a24a3d6aSDedy Lansky u64 num_packets = 0; 1728a24a3d6aSDedy Lansky u64 tx_latency_avg = p->stats.tx_latency_total_us; 1729a24a3d6aSDedy Lansky 1730a24a3d6aSDedy Lansky seq_puts(s, "Tx/Latency bin:"); 1731a24a3d6aSDedy Lansky for (bin = 0; bin < WIL_NUM_LATENCY_BINS; bin++) { 1732a24a3d6aSDedy Lansky seq_printf(s, " %lld", 1733a24a3d6aSDedy Lansky p->tx_latency_bins[bin]); 1734a24a3d6aSDedy Lansky num_packets += p->tx_latency_bins[bin]; 1735a24a3d6aSDedy Lansky } 1736a24a3d6aSDedy Lansky seq_puts(s, "\n"); 1737a24a3d6aSDedy Lansky if (!num_packets) 1738a24a3d6aSDedy Lansky continue; 1739a24a3d6aSDedy Lansky do_div(tx_latency_avg, num_packets); 1740a24a3d6aSDedy Lansky seq_printf(s, "Tx/Latency min/avg/max (us): %d/%lld/%d", 1741a24a3d6aSDedy Lansky p->stats.tx_latency_min_us, 1742a24a3d6aSDedy Lansky tx_latency_avg, 1743a24a3d6aSDedy Lansky p->stats.tx_latency_max_us); 1744a24a3d6aSDedy Lansky 1745a24a3d6aSDedy Lansky seq_puts(s, "\n"); 1746a24a3d6aSDedy Lansky } 1747a24a3d6aSDedy Lansky } 1748a24a3d6aSDedy Lansky 1749a24a3d6aSDedy Lansky return 0; 1750a24a3d6aSDedy Lansky } 1751a24a3d6aSDedy Lansky 1752a24a3d6aSDedy Lansky static int wil_tx_latency_seq_open(struct inode *inode, struct file *file) 1753a24a3d6aSDedy Lansky { 1754a24a3d6aSDedy Lansky return single_open(file, wil_tx_latency_debugfs_show, 1755a24a3d6aSDedy Lansky inode->i_private); 1756a24a3d6aSDedy Lansky } 1757a24a3d6aSDedy Lansky 1758a24a3d6aSDedy Lansky static ssize_t wil_tx_latency_write(struct file *file, const char __user *buf, 1759a24a3d6aSDedy Lansky size_t len, loff_t *ppos) 1760a24a3d6aSDedy Lansky { 1761a24a3d6aSDedy Lansky struct seq_file *s = file->private_data; 1762a24a3d6aSDedy Lansky struct wil6210_priv *wil = s->private; 1763a24a3d6aSDedy Lansky int val, rc, i; 1764a24a3d6aSDedy Lansky bool enable; 1765a24a3d6aSDedy Lansky 1766a24a3d6aSDedy Lansky rc = kstrtoint_from_user(buf, len, 0, &val); 1767a24a3d6aSDedy Lansky if (rc) { 1768a24a3d6aSDedy Lansky wil_err(wil, "Invalid argument\n"); 1769a24a3d6aSDedy Lansky return rc; 1770a24a3d6aSDedy Lansky } 1771a24a3d6aSDedy Lansky if (val == 1) 1772a24a3d6aSDedy Lansky /* default resolution */ 1773a24a3d6aSDedy Lansky val = 500; 1774a24a3d6aSDedy Lansky if (val && (val < 50 || val > 1000)) { 1775a24a3d6aSDedy Lansky wil_err(wil, "Invalid resolution %d\n", val); 1776a24a3d6aSDedy Lansky return -EINVAL; 1777a24a3d6aSDedy Lansky } 1778a24a3d6aSDedy Lansky 1779a24a3d6aSDedy Lansky enable = !!val; 1780a24a3d6aSDedy Lansky if (wil->tx_latency == enable) 1781a24a3d6aSDedy Lansky return len; 1782a24a3d6aSDedy Lansky 1783a24a3d6aSDedy Lansky wil_info(wil, "%s TX latency measurements (resolution %dusec)\n", 1784a24a3d6aSDedy Lansky enable ? "Enabling" : "Disabling", val); 1785a24a3d6aSDedy Lansky 1786a24a3d6aSDedy Lansky if (enable) { 1787a24a3d6aSDedy Lansky size_t sz = sizeof(u64) * WIL_NUM_LATENCY_BINS; 1788a24a3d6aSDedy Lansky 1789a24a3d6aSDedy Lansky wil->tx_latency_res = val; 1790*ddf7afddSAhmad Masri for (i = 0; i < wil->max_assoc_sta; i++) { 1791a24a3d6aSDedy Lansky struct wil_sta_info *sta = &wil->sta[i]; 1792a24a3d6aSDedy Lansky 1793a24a3d6aSDedy Lansky kfree(sta->tx_latency_bins); 1794a24a3d6aSDedy Lansky sta->tx_latency_bins = kzalloc(sz, GFP_KERNEL); 1795a24a3d6aSDedy Lansky if (!sta->tx_latency_bins) 1796a24a3d6aSDedy Lansky return -ENOMEM; 1797a24a3d6aSDedy Lansky sta->stats.tx_latency_min_us = U32_MAX; 1798a24a3d6aSDedy Lansky sta->stats.tx_latency_max_us = 0; 1799a24a3d6aSDedy Lansky sta->stats.tx_latency_total_us = 0; 1800a24a3d6aSDedy Lansky } 1801a24a3d6aSDedy Lansky } 1802a24a3d6aSDedy Lansky wil->tx_latency = enable; 1803a24a3d6aSDedy Lansky 1804a24a3d6aSDedy Lansky return len; 1805a24a3d6aSDedy Lansky } 1806a24a3d6aSDedy Lansky 1807a24a3d6aSDedy Lansky static const struct file_operations fops_tx_latency = { 1808a24a3d6aSDedy Lansky .open = wil_tx_latency_seq_open, 1809a24a3d6aSDedy Lansky .release = single_release, 1810a24a3d6aSDedy Lansky .read = seq_read, 1811a24a3d6aSDedy Lansky .write = wil_tx_latency_write, 1812a24a3d6aSDedy Lansky .llseek = seq_lseek, 1813a24a3d6aSDedy Lansky }; 1814a24a3d6aSDedy Lansky 18150c936b3cSDedy Lansky static void wil_link_stats_print_basic(struct wil6210_vif *vif, 18160c936b3cSDedy Lansky struct seq_file *s, 18170c936b3cSDedy Lansky struct wmi_link_stats_basic *basic) 18180c936b3cSDedy Lansky { 18190c936b3cSDedy Lansky char per[5] = "?"; 18200c936b3cSDedy Lansky 18210c936b3cSDedy Lansky if (basic->per_average != 0xff) 18220c936b3cSDedy Lansky snprintf(per, sizeof(per), "%d%%", basic->per_average); 18230c936b3cSDedy Lansky 18240c936b3cSDedy Lansky seq_printf(s, "CID %d {\n" 18250c936b3cSDedy Lansky "\tTxMCS %d TxTpt %d\n" 18260c936b3cSDedy Lansky "\tGoodput(rx:tx) %d:%d\n" 18270c936b3cSDedy Lansky "\tRxBcastFrames %d\n" 18280c936b3cSDedy Lansky "\tRSSI %d SQI %d SNR %d PER %s\n" 18290c936b3cSDedy Lansky "\tRx RFC %d Ant num %d\n" 18300c936b3cSDedy Lansky "\tSectors(rx:tx) my %d:%d peer %d:%d\n" 18310c936b3cSDedy Lansky "}\n", 18320c936b3cSDedy Lansky basic->cid, 18330c936b3cSDedy Lansky basic->bf_mcs, le32_to_cpu(basic->tx_tpt), 18340c936b3cSDedy Lansky le32_to_cpu(basic->rx_goodput), 18350c936b3cSDedy Lansky le32_to_cpu(basic->tx_goodput), 18360c936b3cSDedy Lansky le32_to_cpu(basic->rx_bcast_frames), 18370c936b3cSDedy Lansky basic->rssi, basic->sqi, basic->snr, per, 18380c936b3cSDedy Lansky basic->selected_rfc, basic->rx_effective_ant_num, 18390c936b3cSDedy Lansky basic->my_rx_sector, basic->my_tx_sector, 18400c936b3cSDedy Lansky basic->other_rx_sector, basic->other_tx_sector); 18410c936b3cSDedy Lansky } 18420c936b3cSDedy Lansky 18430c936b3cSDedy Lansky static void wil_link_stats_print_global(struct wil6210_priv *wil, 18440c936b3cSDedy Lansky struct seq_file *s, 18450c936b3cSDedy Lansky struct wmi_link_stats_global *global) 18460c936b3cSDedy Lansky { 18470c936b3cSDedy Lansky seq_printf(s, "Frames(rx:tx) %d:%d\n" 18480c936b3cSDedy Lansky "BA Frames(rx:tx) %d:%d\n" 18490c936b3cSDedy Lansky "Beacons %d\n" 18500c936b3cSDedy Lansky "Rx Errors (MIC:CRC) %d:%d\n" 18510c936b3cSDedy Lansky "Tx Errors (no ack) %d\n", 18520c936b3cSDedy Lansky le32_to_cpu(global->rx_frames), 18530c936b3cSDedy Lansky le32_to_cpu(global->tx_frames), 18540c936b3cSDedy Lansky le32_to_cpu(global->rx_ba_frames), 18550c936b3cSDedy Lansky le32_to_cpu(global->tx_ba_frames), 18560c936b3cSDedy Lansky le32_to_cpu(global->tx_beacons), 18570c936b3cSDedy Lansky le32_to_cpu(global->rx_mic_errors), 18580c936b3cSDedy Lansky le32_to_cpu(global->rx_crc_errors), 18590c936b3cSDedy Lansky le32_to_cpu(global->tx_fail_no_ack)); 18600c936b3cSDedy Lansky } 18610c936b3cSDedy Lansky 18620c936b3cSDedy Lansky static void wil_link_stats_debugfs_show_vif(struct wil6210_vif *vif, 18630c936b3cSDedy Lansky struct seq_file *s) 18640c936b3cSDedy Lansky { 18650c936b3cSDedy Lansky struct wil6210_priv *wil = vif_to_wil(vif); 18660c936b3cSDedy Lansky struct wmi_link_stats_basic *stats; 18670c936b3cSDedy Lansky int i; 18680c936b3cSDedy Lansky 18690c936b3cSDedy Lansky if (!vif->fw_stats_ready) { 18700c936b3cSDedy Lansky seq_puts(s, "no statistics\n"); 18710c936b3cSDedy Lansky return; 18720c936b3cSDedy Lansky } 18730c936b3cSDedy Lansky 18740c936b3cSDedy Lansky seq_printf(s, "TSF %lld\n", vif->fw_stats_tsf); 1875*ddf7afddSAhmad Masri for (i = 0; i < wil->max_assoc_sta; i++) { 18760c936b3cSDedy Lansky if (wil->sta[i].status == wil_sta_unused) 18770c936b3cSDedy Lansky continue; 18780c936b3cSDedy Lansky if (wil->sta[i].mid != vif->mid) 18790c936b3cSDedy Lansky continue; 18800c936b3cSDedy Lansky 18810c936b3cSDedy Lansky stats = &wil->sta[i].fw_stats_basic; 18820c936b3cSDedy Lansky wil_link_stats_print_basic(vif, s, stats); 18830c936b3cSDedy Lansky } 18840c936b3cSDedy Lansky } 18850c936b3cSDedy Lansky 18860c936b3cSDedy Lansky static int wil_link_stats_debugfs_show(struct seq_file *s, void *data) 18870c936b3cSDedy Lansky { 18880c936b3cSDedy Lansky struct wil6210_priv *wil = s->private; 18890c936b3cSDedy Lansky struct wil6210_vif *vif; 18900c936b3cSDedy Lansky int i, rc; 18910c936b3cSDedy Lansky 18920c936b3cSDedy Lansky rc = mutex_lock_interruptible(&wil->vif_mutex); 18930c936b3cSDedy Lansky if (rc) 18940c936b3cSDedy Lansky return rc; 18950c936b3cSDedy Lansky 18960c936b3cSDedy Lansky /* iterate over all MIDs and show per-cid statistics. Then show the 18970c936b3cSDedy Lansky * global statistics 18980c936b3cSDedy Lansky */ 1899e4a29bddSAhmad Masri for (i = 0; i < GET_MAX_VIFS(wil); i++) { 19000c936b3cSDedy Lansky vif = wil->vifs[i]; 19010c936b3cSDedy Lansky 19020c936b3cSDedy Lansky seq_printf(s, "MID %d ", i); 19030c936b3cSDedy Lansky if (!vif) { 19040c936b3cSDedy Lansky seq_puts(s, "unused\n"); 19050c936b3cSDedy Lansky continue; 19060c936b3cSDedy Lansky } 19070c936b3cSDedy Lansky 19080c936b3cSDedy Lansky wil_link_stats_debugfs_show_vif(vif, s); 19090c936b3cSDedy Lansky } 19100c936b3cSDedy Lansky 19110c936b3cSDedy Lansky mutex_unlock(&wil->vif_mutex); 19120c936b3cSDedy Lansky 19130c936b3cSDedy Lansky return 0; 19140c936b3cSDedy Lansky } 19150c936b3cSDedy Lansky 19160c936b3cSDedy Lansky static int wil_link_stats_seq_open(struct inode *inode, struct file *file) 19170c936b3cSDedy Lansky { 19180c936b3cSDedy Lansky return single_open(file, wil_link_stats_debugfs_show, inode->i_private); 19190c936b3cSDedy Lansky } 19200c936b3cSDedy Lansky 19210c936b3cSDedy Lansky static ssize_t wil_link_stats_write(struct file *file, const char __user *buf, 19220c936b3cSDedy Lansky size_t len, loff_t *ppos) 19230c936b3cSDedy Lansky { 19240c936b3cSDedy Lansky struct seq_file *s = file->private_data; 19250c936b3cSDedy Lansky struct wil6210_priv *wil = s->private; 19260c936b3cSDedy Lansky int cid, interval, rc, i; 19270c936b3cSDedy Lansky struct wil6210_vif *vif; 19280c936b3cSDedy Lansky char *kbuf = kmalloc(len + 1, GFP_KERNEL); 19290c936b3cSDedy Lansky 19300c936b3cSDedy Lansky if (!kbuf) 19310c936b3cSDedy Lansky return -ENOMEM; 19320c936b3cSDedy Lansky 19330c936b3cSDedy Lansky rc = simple_write_to_buffer(kbuf, len, ppos, buf, len); 19340c936b3cSDedy Lansky if (rc != len) { 19350c936b3cSDedy Lansky kfree(kbuf); 19360c936b3cSDedy Lansky return rc >= 0 ? -EIO : rc; 19370c936b3cSDedy Lansky } 19380c936b3cSDedy Lansky 19390c936b3cSDedy Lansky kbuf[len] = '\0'; 19400c936b3cSDedy Lansky /* specify cid (use -1 for all cids) and snapshot interval in ms */ 19410c936b3cSDedy Lansky rc = sscanf(kbuf, "%d %d", &cid, &interval); 19420c936b3cSDedy Lansky kfree(kbuf); 19430c936b3cSDedy Lansky if (rc < 0) 19440c936b3cSDedy Lansky return rc; 19450c936b3cSDedy Lansky if (rc < 2 || interval < 0) 19460c936b3cSDedy Lansky return -EINVAL; 19470c936b3cSDedy Lansky 19480c936b3cSDedy Lansky wil_info(wil, "request link statistics, cid %d interval %d\n", 19490c936b3cSDedy Lansky cid, interval); 19500c936b3cSDedy Lansky 19510c936b3cSDedy Lansky rc = mutex_lock_interruptible(&wil->vif_mutex); 19520c936b3cSDedy Lansky if (rc) 19530c936b3cSDedy Lansky return rc; 19540c936b3cSDedy Lansky 1955e4a29bddSAhmad Masri for (i = 0; i < GET_MAX_VIFS(wil); i++) { 19560c936b3cSDedy Lansky vif = wil->vifs[i]; 19570c936b3cSDedy Lansky if (!vif) 19580c936b3cSDedy Lansky continue; 19590c936b3cSDedy Lansky 19600c936b3cSDedy Lansky rc = wmi_link_stats_cfg(vif, WMI_LINK_STATS_TYPE_BASIC, 19610c936b3cSDedy Lansky (cid == -1 ? 0xff : cid), interval); 19620c936b3cSDedy Lansky if (rc) 19630c936b3cSDedy Lansky wil_err(wil, "link statistics failed for mid %d\n", i); 19640c936b3cSDedy Lansky } 19650c936b3cSDedy Lansky mutex_unlock(&wil->vif_mutex); 19660c936b3cSDedy Lansky 19670c936b3cSDedy Lansky return len; 19680c936b3cSDedy Lansky } 19690c936b3cSDedy Lansky 19700c936b3cSDedy Lansky static const struct file_operations fops_link_stats = { 19710c936b3cSDedy Lansky .open = wil_link_stats_seq_open, 19720c936b3cSDedy Lansky .release = single_release, 19730c936b3cSDedy Lansky .read = seq_read, 19740c936b3cSDedy Lansky .write = wil_link_stats_write, 19750c936b3cSDedy Lansky .llseek = seq_lseek, 19760c936b3cSDedy Lansky }; 19770c936b3cSDedy Lansky 19780c936b3cSDedy Lansky static int 19790c936b3cSDedy Lansky wil_link_stats_global_debugfs_show(struct seq_file *s, void *data) 19800c936b3cSDedy Lansky { 19810c936b3cSDedy Lansky struct wil6210_priv *wil = s->private; 19820c936b3cSDedy Lansky 19830c936b3cSDedy Lansky if (!wil->fw_stats_global.ready) 19840c936b3cSDedy Lansky return 0; 19850c936b3cSDedy Lansky 19860c936b3cSDedy Lansky seq_printf(s, "TSF %lld\n", wil->fw_stats_global.tsf); 19870c936b3cSDedy Lansky wil_link_stats_print_global(wil, s, &wil->fw_stats_global.stats); 19880c936b3cSDedy Lansky 19890c936b3cSDedy Lansky return 0; 19900c936b3cSDedy Lansky } 19910c936b3cSDedy Lansky 19920c936b3cSDedy Lansky static int 19930c936b3cSDedy Lansky wil_link_stats_global_seq_open(struct inode *inode, struct file *file) 19940c936b3cSDedy Lansky { 19950c936b3cSDedy Lansky return single_open(file, wil_link_stats_global_debugfs_show, 19960c936b3cSDedy Lansky inode->i_private); 19970c936b3cSDedy Lansky } 19980c936b3cSDedy Lansky 19990c936b3cSDedy Lansky static ssize_t 20000c936b3cSDedy Lansky wil_link_stats_global_write(struct file *file, const char __user *buf, 20010c936b3cSDedy Lansky size_t len, loff_t *ppos) 20020c936b3cSDedy Lansky { 20030c936b3cSDedy Lansky struct seq_file *s = file->private_data; 20040c936b3cSDedy Lansky struct wil6210_priv *wil = s->private; 20050c936b3cSDedy Lansky int interval, rc; 20060c936b3cSDedy Lansky struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev); 20070c936b3cSDedy Lansky 20080c936b3cSDedy Lansky /* specify snapshot interval in ms */ 20090c936b3cSDedy Lansky rc = kstrtoint_from_user(buf, len, 0, &interval); 20100c936b3cSDedy Lansky if (rc || interval < 0) { 20110c936b3cSDedy Lansky wil_err(wil, "Invalid argument\n"); 20120c936b3cSDedy Lansky return -EINVAL; 20130c936b3cSDedy Lansky } 20140c936b3cSDedy Lansky 20150c936b3cSDedy Lansky wil_info(wil, "request global link stats, interval %d\n", interval); 20160c936b3cSDedy Lansky 20170c936b3cSDedy Lansky rc = wmi_link_stats_cfg(vif, WMI_LINK_STATS_TYPE_GLOBAL, 0, interval); 20180c936b3cSDedy Lansky if (rc) 20190c936b3cSDedy Lansky wil_err(wil, "global link stats failed %d\n", rc); 20200c936b3cSDedy Lansky 20210c936b3cSDedy Lansky return rc ? rc : len; 20220c936b3cSDedy Lansky } 20230c936b3cSDedy Lansky 20240c936b3cSDedy Lansky static const struct file_operations fops_link_stats_global = { 20250c936b3cSDedy Lansky .open = wil_link_stats_global_seq_open, 20260c936b3cSDedy Lansky .release = single_release, 20270c936b3cSDedy Lansky .read = seq_read, 20280c936b3cSDedy Lansky .write = wil_link_stats_global_write, 20290c936b3cSDedy Lansky .llseek = seq_lseek, 20300c936b3cSDedy Lansky }; 20310c936b3cSDedy Lansky 203210d599adSMaya Erez static ssize_t wil_read_file_led_cfg(struct file *file, char __user *user_buf, 203310d599adSMaya Erez size_t count, loff_t *ppos) 203410d599adSMaya Erez { 203510d599adSMaya Erez char buf[80]; 203610d599adSMaya Erez int n; 203710d599adSMaya Erez 203810d599adSMaya Erez n = snprintf(buf, sizeof(buf), 203910d599adSMaya Erez "led_id is set to %d, echo 1 to enable, 0 to disable\n", 204010d599adSMaya Erez led_id); 204110d599adSMaya Erez 204210d599adSMaya Erez n = min_t(int, n, sizeof(buf)); 204310d599adSMaya Erez 204410d599adSMaya Erez return simple_read_from_buffer(user_buf, count, ppos, 204510d599adSMaya Erez buf, n); 204610d599adSMaya Erez } 204710d599adSMaya Erez 204810d599adSMaya Erez static ssize_t wil_write_file_led_cfg(struct file *file, 204910d599adSMaya Erez const char __user *buf_, 205010d599adSMaya Erez size_t count, loff_t *ppos) 205110d599adSMaya Erez { 205210d599adSMaya Erez struct wil6210_priv *wil = file->private_data; 205310d599adSMaya Erez int val; 205410d599adSMaya Erez int rc; 205510d599adSMaya Erez 205610d599adSMaya Erez rc = kstrtoint_from_user(buf_, count, 0, &val); 205710d599adSMaya Erez if (rc) { 205810d599adSMaya Erez wil_err(wil, "Invalid argument\n"); 205910d599adSMaya Erez return rc; 206010d599adSMaya Erez } 206110d599adSMaya Erez 206210d599adSMaya Erez wil_info(wil, "%s led %d\n", val ? "Enabling" : "Disabling", led_id); 206310d599adSMaya Erez rc = wmi_led_cfg(wil, val); 206410d599adSMaya Erez if (rc) { 206510d599adSMaya Erez wil_info(wil, "%s led %d failed\n", 206610d599adSMaya Erez val ? "Enabling" : "Disabling", led_id); 206710d599adSMaya Erez return rc; 206810d599adSMaya Erez } 206910d599adSMaya Erez 207010d599adSMaya Erez return count; 207110d599adSMaya Erez } 207210d599adSMaya Erez 207310d599adSMaya Erez static const struct file_operations fops_led_cfg = { 207410d599adSMaya Erez .read = wil_read_file_led_cfg, 207510d599adSMaya Erez .write = wil_write_file_led_cfg, 207610d599adSMaya Erez .open = simple_open, 207710d599adSMaya Erez }; 207810d599adSMaya Erez 207910d599adSMaya Erez /* led_blink_time, write: 208010d599adSMaya Erez * "<blink_on_slow> <blink_off_slow> <blink_on_med> <blink_off_med> <blink_on_fast> <blink_off_fast> 208110d599adSMaya Erez */ 208210d599adSMaya Erez static ssize_t wil_write_led_blink_time(struct file *file, 208310d599adSMaya Erez const char __user *buf, 208410d599adSMaya Erez size_t len, loff_t *ppos) 208510d599adSMaya Erez { 208610d599adSMaya Erez int rc; 208710d599adSMaya Erez char *kbuf = kmalloc(len + 1, GFP_KERNEL); 208810d599adSMaya Erez 208910d599adSMaya Erez if (!kbuf) 209010d599adSMaya Erez return -ENOMEM; 209110d599adSMaya Erez 209210d599adSMaya Erez rc = simple_write_to_buffer(kbuf, len, ppos, buf, len); 209310d599adSMaya Erez if (rc != len) { 209410d599adSMaya Erez kfree(kbuf); 209510d599adSMaya Erez return rc >= 0 ? -EIO : rc; 209610d599adSMaya Erez } 209710d599adSMaya Erez 209810d599adSMaya Erez kbuf[len] = '\0'; 209910d599adSMaya Erez rc = sscanf(kbuf, "%d %d %d %d %d %d", 210010d599adSMaya Erez &led_blink_time[WIL_LED_TIME_SLOW].on_ms, 210110d599adSMaya Erez &led_blink_time[WIL_LED_TIME_SLOW].off_ms, 210210d599adSMaya Erez &led_blink_time[WIL_LED_TIME_MED].on_ms, 210310d599adSMaya Erez &led_blink_time[WIL_LED_TIME_MED].off_ms, 210410d599adSMaya Erez &led_blink_time[WIL_LED_TIME_FAST].on_ms, 210510d599adSMaya Erez &led_blink_time[WIL_LED_TIME_FAST].off_ms); 210610d599adSMaya Erez kfree(kbuf); 210710d599adSMaya Erez 210810d599adSMaya Erez if (rc < 0) 210910d599adSMaya Erez return rc; 211010d599adSMaya Erez if (rc < 6) 211110d599adSMaya Erez return -EINVAL; 211210d599adSMaya Erez 211310d599adSMaya Erez return len; 211410d599adSMaya Erez } 211510d599adSMaya Erez 211610d599adSMaya Erez static ssize_t wil_read_led_blink_time(struct file *file, char __user *user_buf, 211710d599adSMaya Erez size_t count, loff_t *ppos) 211810d599adSMaya Erez { 211910d599adSMaya Erez static char text[400]; 212010d599adSMaya Erez 212110d599adSMaya Erez snprintf(text, sizeof(text), 212210d599adSMaya Erez "To set led blink on/off time variables write:\n" 212310d599adSMaya Erez "<blink_on_slow> <blink_off_slow> <blink_on_med> " 212410d599adSMaya Erez "<blink_off_med> <blink_on_fast> <blink_off_fast>\n" 212510d599adSMaya Erez "The current values are:\n" 212610d599adSMaya Erez "%d %d %d %d %d %d\n", 212710d599adSMaya Erez led_blink_time[WIL_LED_TIME_SLOW].on_ms, 212810d599adSMaya Erez led_blink_time[WIL_LED_TIME_SLOW].off_ms, 212910d599adSMaya Erez led_blink_time[WIL_LED_TIME_MED].on_ms, 213010d599adSMaya Erez led_blink_time[WIL_LED_TIME_MED].off_ms, 213110d599adSMaya Erez led_blink_time[WIL_LED_TIME_FAST].on_ms, 213210d599adSMaya Erez led_blink_time[WIL_LED_TIME_FAST].off_ms); 213310d599adSMaya Erez 213410d599adSMaya Erez return simple_read_from_buffer(user_buf, count, ppos, text, 213510d599adSMaya Erez sizeof(text)); 213610d599adSMaya Erez } 213710d599adSMaya Erez 213810d599adSMaya Erez static const struct file_operations fops_led_blink_time = { 213910d599adSMaya Erez .read = wil_read_led_blink_time, 214010d599adSMaya Erez .write = wil_write_led_blink_time, 214110d599adSMaya Erez .open = simple_open, 214210d599adSMaya Erez }; 214310d599adSMaya Erez 214412bace75SLior David /*---------FW capabilities------------*/ 214512bace75SLior David static int wil_fw_capabilities_debugfs_show(struct seq_file *s, void *data) 214612bace75SLior David { 214712bace75SLior David struct wil6210_priv *wil = s->private; 214812bace75SLior David 214912bace75SLior David seq_printf(s, "fw_capabilities : %*pb\n", WMI_FW_CAPABILITY_MAX, 215012bace75SLior David wil->fw_capabilities); 215112bace75SLior David 215212bace75SLior David return 0; 215312bace75SLior David } 215412bace75SLior David 215512bace75SLior David static int wil_fw_capabilities_seq_open(struct inode *inode, struct file *file) 215612bace75SLior David { 215712bace75SLior David return single_open(file, wil_fw_capabilities_debugfs_show, 215812bace75SLior David inode->i_private); 215912bace75SLior David } 216012bace75SLior David 216112bace75SLior David static const struct file_operations fops_fw_capabilities = { 216212bace75SLior David .open = wil_fw_capabilities_seq_open, 216312bace75SLior David .release = single_release, 216412bace75SLior David .read = seq_read, 216512bace75SLior David .llseek = seq_lseek, 216612bace75SLior David }; 216712bace75SLior David 216813cd9f75SLior David /*---------FW version------------*/ 216913cd9f75SLior David static int wil_fw_version_debugfs_show(struct seq_file *s, void *data) 217013cd9f75SLior David { 217113cd9f75SLior David struct wil6210_priv *wil = s->private; 217213cd9f75SLior David 217313cd9f75SLior David if (wil->fw_version[0]) 217413cd9f75SLior David seq_printf(s, "%s\n", wil->fw_version); 217513cd9f75SLior David else 217613cd9f75SLior David seq_puts(s, "N/A\n"); 217713cd9f75SLior David 217813cd9f75SLior David return 0; 217913cd9f75SLior David } 218013cd9f75SLior David 218113cd9f75SLior David static int wil_fw_version_seq_open(struct inode *inode, struct file *file) 218213cd9f75SLior David { 218313cd9f75SLior David return single_open(file, wil_fw_version_debugfs_show, 218413cd9f75SLior David inode->i_private); 218513cd9f75SLior David } 218613cd9f75SLior David 218713cd9f75SLior David static const struct file_operations fops_fw_version = { 218813cd9f75SLior David .open = wil_fw_version_seq_open, 218913cd9f75SLior David .release = single_release, 219013cd9f75SLior David .read = seq_read, 219113cd9f75SLior David .llseek = seq_lseek, 219213cd9f75SLior David }; 219313cd9f75SLior David 2194fe9ee51eSMaya Erez /*---------suspend_stats---------*/ 2195fe9ee51eSMaya Erez static ssize_t wil_write_suspend_stats(struct file *file, 2196fe9ee51eSMaya Erez const char __user *buf, 2197fe9ee51eSMaya Erez size_t len, loff_t *ppos) 2198fe9ee51eSMaya Erez { 2199fe9ee51eSMaya Erez struct wil6210_priv *wil = file->private_data; 2200fe9ee51eSMaya Erez 2201fe9ee51eSMaya Erez memset(&wil->suspend_stats, 0, sizeof(wil->suspend_stats)); 2202fe9ee51eSMaya Erez 2203fe9ee51eSMaya Erez return len; 2204fe9ee51eSMaya Erez } 2205fe9ee51eSMaya Erez 2206fe9ee51eSMaya Erez static ssize_t wil_read_suspend_stats(struct file *file, 2207fe9ee51eSMaya Erez char __user *user_buf, 2208fe9ee51eSMaya Erez size_t count, loff_t *ppos) 2209fe9ee51eSMaya Erez { 2210fe9ee51eSMaya Erez struct wil6210_priv *wil = file->private_data; 2211bd8bdc6cSLazar Alexei char *text; 2212bd8bdc6cSLazar Alexei int n, ret, text_size = 500; 2213fe9ee51eSMaya Erez 2214bd8bdc6cSLazar Alexei text = kmalloc(text_size, GFP_KERNEL); 2215bd8bdc6cSLazar Alexei if (!text) 2216bd8bdc6cSLazar Alexei return -ENOMEM; 2217bd8bdc6cSLazar Alexei 2218bd8bdc6cSLazar Alexei n = snprintf(text, text_size, 2219bd8bdc6cSLazar Alexei "Radio on suspend statistics:\n" 2220fe9ee51eSMaya Erez "successful suspends:%ld failed suspends:%ld\n" 2221fe9ee51eSMaya Erez "successful resumes:%ld failed resumes:%ld\n" 2222bd8bdc6cSLazar Alexei "rejected by device:%ld\n" 2223bd8bdc6cSLazar Alexei "Radio off suspend statistics:\n" 2224bd8bdc6cSLazar Alexei "successful suspends:%ld failed suspends:%ld\n" 2225bd8bdc6cSLazar Alexei "successful resumes:%ld failed resumes:%ld\n" 2226bd8bdc6cSLazar Alexei "General statistics:\n" 2227bd8bdc6cSLazar Alexei "rejected by host:%ld\n", 2228bd8bdc6cSLazar Alexei wil->suspend_stats.r_on.successful_suspends, 2229bd8bdc6cSLazar Alexei wil->suspend_stats.r_on.failed_suspends, 2230bd8bdc6cSLazar Alexei wil->suspend_stats.r_on.successful_resumes, 2231bd8bdc6cSLazar Alexei wil->suspend_stats.r_on.failed_resumes, 2232bd8bdc6cSLazar Alexei wil->suspend_stats.rejected_by_device, 2233bd8bdc6cSLazar Alexei wil->suspend_stats.r_off.successful_suspends, 2234bd8bdc6cSLazar Alexei wil->suspend_stats.r_off.failed_suspends, 2235bd8bdc6cSLazar Alexei wil->suspend_stats.r_off.successful_resumes, 2236bd8bdc6cSLazar Alexei wil->suspend_stats.r_off.failed_resumes, 2237bd8bdc6cSLazar Alexei wil->suspend_stats.rejected_by_host); 2238fe9ee51eSMaya Erez 2239bd8bdc6cSLazar Alexei n = min_t(int, n, text_size); 2240fe9ee51eSMaya Erez 2241bd8bdc6cSLazar Alexei ret = simple_read_from_buffer(user_buf, count, ppos, text, n); 2242bd8bdc6cSLazar Alexei 2243bd8bdc6cSLazar Alexei kfree(text); 2244bd8bdc6cSLazar Alexei 2245bd8bdc6cSLazar Alexei return ret; 2246fe9ee51eSMaya Erez } 2247fe9ee51eSMaya Erez 2248fe9ee51eSMaya Erez static const struct file_operations fops_suspend_stats = { 2249fe9ee51eSMaya Erez .read = wil_read_suspend_stats, 2250fe9ee51eSMaya Erez .write = wil_write_suspend_stats, 2251fe9ee51eSMaya Erez .open = simple_open, 2252fe9ee51eSMaya Erez }; 2253fe9ee51eSMaya Erez 225496c93589SGidon Studinski /*---------compressed_rx_status---------*/ 225596c93589SGidon Studinski static ssize_t wil_compressed_rx_status_write(struct file *file, 225696c93589SGidon Studinski const char __user *buf, 225796c93589SGidon Studinski size_t len, loff_t *ppos) 225896c93589SGidon Studinski { 225996c93589SGidon Studinski struct seq_file *s = file->private_data; 226096c93589SGidon Studinski struct wil6210_priv *wil = s->private; 226196c93589SGidon Studinski int compressed_rx_status; 226296c93589SGidon Studinski int rc; 226396c93589SGidon Studinski 226496c93589SGidon Studinski rc = kstrtoint_from_user(buf, len, 0, &compressed_rx_status); 226596c93589SGidon Studinski if (rc) { 226696c93589SGidon Studinski wil_err(wil, "Invalid argument\n"); 226796c93589SGidon Studinski return rc; 226896c93589SGidon Studinski } 226996c93589SGidon Studinski 227096c93589SGidon Studinski if (wil_has_active_ifaces(wil, true, false)) { 227196c93589SGidon Studinski wil_err(wil, "cannot change edma config after iface is up\n"); 227296c93589SGidon Studinski return -EPERM; 227396c93589SGidon Studinski } 227496c93589SGidon Studinski 227596c93589SGidon Studinski wil_info(wil, "%sable compressed_rx_status\n", 227696c93589SGidon Studinski compressed_rx_status ? "En" : "Dis"); 227796c93589SGidon Studinski 227896c93589SGidon Studinski wil->use_compressed_rx_status = compressed_rx_status; 227996c93589SGidon Studinski 228096c93589SGidon Studinski return len; 228196c93589SGidon Studinski } 228296c93589SGidon Studinski 228396c93589SGidon Studinski static int 228496c93589SGidon Studinski wil_compressed_rx_status_show(struct seq_file *s, void *data) 228596c93589SGidon Studinski { 228696c93589SGidon Studinski struct wil6210_priv *wil = s->private; 228796c93589SGidon Studinski 228896c93589SGidon Studinski seq_printf(s, "%d\n", wil->use_compressed_rx_status); 228996c93589SGidon Studinski 229096c93589SGidon Studinski return 0; 229196c93589SGidon Studinski } 229296c93589SGidon Studinski 229396c93589SGidon Studinski static int 229496c93589SGidon Studinski wil_compressed_rx_status_seq_open(struct inode *inode, struct file *file) 229596c93589SGidon Studinski { 229696c93589SGidon Studinski return single_open(file, wil_compressed_rx_status_show, 229796c93589SGidon Studinski inode->i_private); 229896c93589SGidon Studinski } 229996c93589SGidon Studinski 230096c93589SGidon Studinski static const struct file_operations fops_compressed_rx_status = { 230196c93589SGidon Studinski .open = wil_compressed_rx_status_seq_open, 230296c93589SGidon Studinski .release = single_release, 230396c93589SGidon Studinski .read = seq_read, 230496c93589SGidon Studinski .write = wil_compressed_rx_status_write, 230596c93589SGidon Studinski .llseek = seq_lseek, 230696c93589SGidon Studinski }; 230796c93589SGidon Studinski 23082be7d22fSVladimir Kondratiev /*----------------*/ 2309b541d0a0SVladimir Kondratiev static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil, 2310b541d0a0SVladimir Kondratiev struct dentry *dbg) 2311b541d0a0SVladimir Kondratiev { 2312b541d0a0SVladimir Kondratiev int i; 2313b541d0a0SVladimir Kondratiev char name[32]; 2314b541d0a0SVladimir Kondratiev 2315b541d0a0SVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) { 2316349214c1SMaya Erez struct wil_blob_wrapper *wil_blob = &wil->blobs[i]; 2317349214c1SMaya Erez struct debugfs_blob_wrapper *blob = &wil_blob->blob; 2318b541d0a0SVladimir Kondratiev const struct fw_map *map = &fw_mapping[i]; 2319b541d0a0SVladimir Kondratiev 2320b541d0a0SVladimir Kondratiev if (!map->name) 2321b541d0a0SVladimir Kondratiev continue; 2322b541d0a0SVladimir Kondratiev 2323349214c1SMaya Erez wil_blob->wil = wil; 2324b541d0a0SVladimir Kondratiev blob->data = (void * __force)wil->csr + HOSTADDR(map->host); 2325b541d0a0SVladimir Kondratiev blob->size = map->to - map->from; 2326b541d0a0SVladimir Kondratiev snprintf(name, sizeof(name), "blob_%s", map->name); 232778484c44SMaya Erez wil_debugfs_create_ioblob(name, 0444, dbg, wil_blob); 2328b541d0a0SVladimir Kondratiev } 2329b541d0a0SVladimir Kondratiev } 2330b541d0a0SVladimir Kondratiev 2331b7cde470SVladimir Kondratiev /* misc files */ 2332b7cde470SVladimir Kondratiev static const struct { 2333b7cde470SVladimir Kondratiev const char *name; 2334b7cde470SVladimir Kondratiev umode_t mode; 2335b7cde470SVladimir Kondratiev const struct file_operations *fops; 2336b7cde470SVladimir Kondratiev } dbg_files[] = { 2337986b8348SYangtao Li {"mbox", 0444, &mbox_fops}, 2338986b8348SYangtao Li {"rings", 0444, &ring_fops}, 2339986b8348SYangtao Li {"stations", 0444, &sta_fops}, 2340986b8348SYangtao Li {"mids", 0444, &mids_fops}, 2341986b8348SYangtao Li {"desc", 0444, &txdesc_fops}, 2342986b8348SYangtao Li {"bf", 0444, &bf_fops}, 2343986b8348SYangtao Li {"mem_val", 0644, &memread_fops}, 234478484c44SMaya Erez {"rxon", 0244, &fops_rxon}, 234578484c44SMaya Erez {"tx_mgmt", 0244, &fops_txmgmt}, 234678484c44SMaya Erez {"wmi_send", 0244, &fops_wmi}, 234778484c44SMaya Erez {"back", 0644, &fops_back}, 234878484c44SMaya Erez {"pmccfg", 0644, &fops_pmccfg}, 234978484c44SMaya Erez {"pmcdata", 0444, &fops_pmcdata}, 2350986b8348SYangtao Li {"temp", 0444, &temp_fops}, 2351986b8348SYangtao Li {"freq", 0444, &freq_fops}, 2352986b8348SYangtao Li {"link", 0444, &link_fops}, 2353986b8348SYangtao Li {"info", 0444, &info_fops}, 235478484c44SMaya Erez {"recovery", 0644, &fops_recovery}, 235578484c44SMaya Erez {"led_cfg", 0644, &fops_led_cfg}, 235678484c44SMaya Erez {"led_blink_time", 0644, &fops_led_blink_time}, 235778484c44SMaya Erez {"fw_capabilities", 0444, &fops_fw_capabilities}, 235878484c44SMaya Erez {"fw_version", 0444, &fops_fw_version}, 2359fe9ee51eSMaya Erez {"suspend_stats", 0644, &fops_suspend_stats}, 236096c93589SGidon Studinski {"compressed_rx_status", 0644, &fops_compressed_rx_status}, 2361986b8348SYangtao Li {"srings", 0444, &srings_fops}, 2362986b8348SYangtao Li {"status_msg", 0444, &status_msg_fops}, 2363986b8348SYangtao Li {"rx_buff_mgmt", 0444, &rx_buff_mgmt_fops}, 2364a24a3d6aSDedy Lansky {"tx_latency", 0644, &fops_tx_latency}, 23650c936b3cSDedy Lansky {"link_stats", 0644, &fops_link_stats}, 23660c936b3cSDedy Lansky {"link_stats_global", 0644, &fops_link_stats_global}, 2367b7cde470SVladimir Kondratiev }; 2368b7cde470SVladimir Kondratiev 2369b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_files(struct wil6210_priv *wil, 2370b7cde470SVladimir Kondratiev struct dentry *dbg) 2371b7cde470SVladimir Kondratiev { 2372b7cde470SVladimir Kondratiev int i; 2373b7cde470SVladimir Kondratiev 2374b7cde470SVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(dbg_files); i++) 2375b7cde470SVladimir Kondratiev debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg, 2376b7cde470SVladimir Kondratiev wil, dbg_files[i].fops); 2377b7cde470SVladimir Kondratiev } 2378b7cde470SVladimir Kondratiev 2379b7cde470SVladimir Kondratiev /* interrupt control blocks */ 2380b7cde470SVladimir Kondratiev static const struct { 2381b7cde470SVladimir Kondratiev const char *name; 2382b7cde470SVladimir Kondratiev u32 icr_off; 2383b7cde470SVladimir Kondratiev } dbg_icr[] = { 2384b7cde470SVladimir Kondratiev {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)}, 2385b7cde470SVladimir Kondratiev {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)}, 2386b7cde470SVladimir Kondratiev {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)}, 2387b7cde470SVladimir Kondratiev {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)}, 2388b7cde470SVladimir Kondratiev }; 2389b7cde470SVladimir Kondratiev 2390b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_isr(struct wil6210_priv *wil, 2391b7cde470SVladimir Kondratiev struct dentry *dbg) 2392b7cde470SVladimir Kondratiev { 2393b7cde470SVladimir Kondratiev int i; 2394b7cde470SVladimir Kondratiev 2395b7cde470SVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(dbg_icr); i++) 2396b7cde470SVladimir Kondratiev wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg, 2397b7cde470SVladimir Kondratiev dbg_icr[i].icr_off); 2398b7cde470SVladimir Kondratiev } 2399b7cde470SVladimir Kondratiev 2400b7cde470SVladimir Kondratiev #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \ 2401b7cde470SVladimir Kondratiev offsetof(struct wil6210_priv, name), type} 2402b7cde470SVladimir Kondratiev 2403b7cde470SVladimir Kondratiev /* fields in struct wil6210_priv */ 2404b7cde470SVladimir Kondratiev static const struct dbg_off dbg_wil_off[] = { 240578484c44SMaya Erez WIL_FIELD(status[0], 0644, doff_ulong), 240678484c44SMaya Erez WIL_FIELD(hw_version, 0444, doff_x32), 240778484c44SMaya Erez WIL_FIELD(recovery_count, 0444, doff_u32), 240878484c44SMaya Erez WIL_FIELD(discovery_mode, 0644, doff_u8), 240978484c44SMaya Erez WIL_FIELD(chip_revision, 0444, doff_u8), 241078484c44SMaya Erez WIL_FIELD(abft_len, 0644, doff_u8), 2411fe9ee51eSMaya Erez WIL_FIELD(wakeup_trigger, 0644, doff_u8), 241210590c6aSGidon Studinski WIL_FIELD(ring_idle_trsh, 0644, doff_u32), 241396c93589SGidon Studinski WIL_FIELD(num_rx_status_rings, 0644, doff_u8), 241496c93589SGidon Studinski WIL_FIELD(rx_status_ring_order, 0644, doff_u32), 241596c93589SGidon Studinski WIL_FIELD(tx_status_ring_order, 0644, doff_u32), 241696c93589SGidon Studinski WIL_FIELD(rx_buff_id_count, 0644, doff_u32), 24177be13fc3SGidon Studinski WIL_FIELD(amsdu_en, 0644, doff_u8), 2418b7cde470SVladimir Kondratiev {}, 2419b7cde470SVladimir Kondratiev }; 2420b7cde470SVladimir Kondratiev 2421b7cde470SVladimir Kondratiev static const struct dbg_off dbg_wil_regs[] = { 242278484c44SMaya Erez {"RGF_MAC_MTRL_COUNTER_0", 0444, HOSTADDR(RGF_MAC_MTRL_COUNTER_0), 2423b7cde470SVladimir Kondratiev doff_io32}, 242478484c44SMaya Erez {"RGF_USER_USAGE_1", 0444, HOSTADDR(RGF_USER_USAGE_1), doff_io32}, 24258454e72aSAhmad Masri {"RGF_USER_USAGE_2", 0444, HOSTADDR(RGF_USER_USAGE_2), doff_io32}, 2426b7cde470SVladimir Kondratiev {}, 2427b7cde470SVladimir Kondratiev }; 2428b7cde470SVladimir Kondratiev 2429b7cde470SVladimir Kondratiev /* static parameters */ 2430b7cde470SVladimir Kondratiev static const struct dbg_off dbg_statics[] = { 243178484c44SMaya Erez {"desc_index", 0644, (ulong)&dbg_txdesc_index, doff_u32}, 243210590c6aSGidon Studinski {"ring_index", 0644, (ulong)&dbg_ring_index, doff_u32}, 243378484c44SMaya Erez {"mem_addr", 0644, (ulong)&mem_addr, doff_u32}, 243478484c44SMaya Erez {"led_polarity", 0644, (ulong)&led_polarity, doff_u8}, 2435d98b8539SMaya Erez {"status_index", 0644, (ulong)&dbg_status_msg_index, doff_u32}, 2436d98b8539SMaya Erez {"sring_index", 0644, (ulong)&dbg_sring_index, doff_u32}, 24370439a5e0SDedy Lansky {"drop_if_ring_full", 0644, (ulong)&drop_if_ring_full, doff_u8}, 2438b7cde470SVladimir Kondratiev {}, 2439b7cde470SVladimir Kondratiev }; 2440b7cde470SVladimir Kondratiev 244194162666SLazar Alexei static const int dbg_off_count = 4 * (ARRAY_SIZE(isr_off) - 1) + 244294162666SLazar Alexei ARRAY_SIZE(dbg_wil_regs) - 1 + 244394162666SLazar Alexei ARRAY_SIZE(pseudo_isr_off) - 1 + 244494162666SLazar Alexei ARRAY_SIZE(lgc_itr_cnt_off) - 1 + 244594162666SLazar Alexei ARRAY_SIZE(tx_itr_cnt_off) - 1 + 244694162666SLazar Alexei ARRAY_SIZE(rx_itr_cnt_off) - 1; 244794162666SLazar Alexei 24482be7d22fSVladimir Kondratiev int wil6210_debugfs_init(struct wil6210_priv *wil) 24492be7d22fSVladimir Kondratiev { 24502be7d22fSVladimir Kondratiev struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME, 24512be7d22fSVladimir Kondratiev wil_to_wiphy(wil)->debugfsdir); 24522be7d22fSVladimir Kondratiev if (IS_ERR_OR_NULL(dbg)) 24532be7d22fSVladimir Kondratiev return -ENODEV; 24542be7d22fSVladimir Kondratiev 245594162666SLazar Alexei wil->dbg_data.data_arr = kcalloc(dbg_off_count, 245694162666SLazar Alexei sizeof(struct wil_debugfs_iomem_data), 245794162666SLazar Alexei GFP_KERNEL); 245894162666SLazar Alexei if (!wil->dbg_data.data_arr) { 245994162666SLazar Alexei debugfs_remove_recursive(dbg); 246094162666SLazar Alexei wil->debug = NULL; 246194162666SLazar Alexei return -ENOMEM; 246294162666SLazar Alexei } 246394162666SLazar Alexei 246494162666SLazar Alexei wil->dbg_data.iomem_data_count = 0; 246594162666SLazar Alexei 2466dc16427bSVladimir Kondratiev wil_pmc_init(wil); 2467dc16427bSVladimir Kondratiev 2468b7cde470SVladimir Kondratiev wil6210_debugfs_init_files(wil, dbg); 2469b7cde470SVladimir Kondratiev wil6210_debugfs_init_isr(wil, dbg); 2470b541d0a0SVladimir Kondratiev wil6210_debugfs_init_blobs(wil, dbg); 2471b7cde470SVladimir Kondratiev wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off); 2472b7cde470SVladimir Kondratiev wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr, 2473b7cde470SVladimir Kondratiev dbg_wil_regs); 2474b7cde470SVladimir Kondratiev wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics); 2475b7cde470SVladimir Kondratiev 2476b7cde470SVladimir Kondratiev wil6210_debugfs_create_pseudo_ISR(wil, dbg); 2477b7cde470SVladimir Kondratiev 2478b7cde470SVladimir Kondratiev wil6210_debugfs_create_ITR_CNT(wil, dbg); 24792be7d22fSVladimir Kondratiev 24802be7d22fSVladimir Kondratiev return 0; 24812be7d22fSVladimir Kondratiev } 24822be7d22fSVladimir Kondratiev 24832be7d22fSVladimir Kondratiev void wil6210_debugfs_remove(struct wil6210_priv *wil) 24842be7d22fSVladimir Kondratiev { 2485a24a3d6aSDedy Lansky int i; 2486a24a3d6aSDedy Lansky 24872be7d22fSVladimir Kondratiev debugfs_remove_recursive(wil->debug); 24882be7d22fSVladimir Kondratiev wil->debug = NULL; 2489dc16427bSVladimir Kondratiev 249094162666SLazar Alexei kfree(wil->dbg_data.data_arr); 2491*ddf7afddSAhmad Masri for (i = 0; i < wil->max_assoc_sta; i++) 2492a24a3d6aSDedy Lansky kfree(wil->sta[i].tx_latency_bins); 249394162666SLazar Alexei 2494dc16427bSVladimir Kondratiev /* free pmc memory without sending command to fw, as it will 2495dc16427bSVladimir Kondratiev * be reset on the way down anyway 2496dc16427bSVladimir Kondratiev */ 2497dc16427bSVladimir Kondratiev wil_pmc_free(wil, false); 24982be7d22fSVladimir Kondratiev } 2499