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 181ddf7afddSAhmad 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 425ce564170SGreg Kroah-Hartman static void wil_debugfs_create_iomem_x32(const char *name, umode_t mode, 426ce564170SGreg Kroah-Hartman struct dentry *parent, void *value, 42794162666SLazar Alexei struct wil6210_priv *wil) 4282be7d22fSVladimir Kondratiev { 42994162666SLazar Alexei struct wil_debugfs_iomem_data *data = &wil->dbg_data.data_arr[ 43094162666SLazar Alexei wil->dbg_data.iomem_data_count]; 43194162666SLazar Alexei 43294162666SLazar Alexei data->wil = wil; 43394162666SLazar Alexei data->offset = value; 43494162666SLazar Alexei 435ce564170SGreg Kroah-Hartman debugfs_create_file_unsafe(name, mode, parent, data, &fops_iomem_x32); 43694162666SLazar Alexei wil->dbg_data.iomem_data_count++; 4372be7d22fSVladimir Kondratiev } 4382be7d22fSVladimir Kondratiev 4393de6cf20SVladimir Kondratiev static int wil_debugfs_ulong_set(void *data, u64 val) 4403de6cf20SVladimir Kondratiev { 4413de6cf20SVladimir Kondratiev *(ulong *)data = val; 4423de6cf20SVladimir Kondratiev return 0; 4433de6cf20SVladimir Kondratiev } 4448fe59627SVladimir Kondratiev 4453de6cf20SVladimir Kondratiev static int wil_debugfs_ulong_get(void *data, u64 *val) 4463de6cf20SVladimir Kondratiev { 4473de6cf20SVladimir Kondratiev *val = *(ulong *)data; 4483de6cf20SVladimir Kondratiev return 0; 4493de6cf20SVladimir Kondratiev } 4508fe59627SVladimir Kondratiev 451f9dca154SYueHaibing DEFINE_DEBUGFS_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get, 4528ea06188SVladimir Kondratiev wil_debugfs_ulong_set, "0x%llx\n"); 4533de6cf20SVladimir Kondratiev 454b7cde470SVladimir Kondratiev /** 455b7cde470SVladimir Kondratiev * wil6210_debugfs_init_offset - create set of debugfs files 456b7cde470SVladimir Kondratiev * @wil - driver's context, used for printing 457b7cde470SVladimir Kondratiev * @dbg - directory on the debugfs, where files will be created 458b7cde470SVladimir Kondratiev * @base - base address used in address calculation 459b7cde470SVladimir Kondratiev * @tbl - table with file descriptions. Should be terminated with empty element. 460b7cde470SVladimir Kondratiev * 461b7cde470SVladimir Kondratiev * Creates files accordingly to the @tbl. 462b7cde470SVladimir Kondratiev */ 463b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_offset(struct wil6210_priv *wil, 464b7cde470SVladimir Kondratiev struct dentry *dbg, void *base, 465b7cde470SVladimir Kondratiev const struct dbg_off * const tbl) 466b7cde470SVladimir Kondratiev { 467b7cde470SVladimir Kondratiev int i; 468b7cde470SVladimir Kondratiev 469b7cde470SVladimir Kondratiev for (i = 0; tbl[i].name; i++) { 470b7cde470SVladimir Kondratiev switch (tbl[i].type) { 471b7cde470SVladimir Kondratiev case doff_u32: 472ce564170SGreg Kroah-Hartman debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg, 473b7cde470SVladimir Kondratiev base + tbl[i].off); 474b7cde470SVladimir Kondratiev break; 475b7cde470SVladimir Kondratiev case doff_x32: 476ce564170SGreg Kroah-Hartman debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg, 477b7cde470SVladimir Kondratiev base + tbl[i].off); 478b7cde470SVladimir Kondratiev break; 479b7cde470SVladimir Kondratiev case doff_ulong: 480ce564170SGreg Kroah-Hartman debugfs_create_file_unsafe(tbl[i].name, tbl[i].mode, 481ce564170SGreg Kroah-Hartman dbg, base + tbl[i].off, 482ce564170SGreg Kroah-Hartman &wil_fops_ulong); 483b7cde470SVladimir Kondratiev break; 484b7cde470SVladimir Kondratiev case doff_io32: 485ce564170SGreg Kroah-Hartman wil_debugfs_create_iomem_x32(tbl[i].name, tbl[i].mode, 486ce564170SGreg Kroah-Hartman dbg, base + tbl[i].off, 48794162666SLazar Alexei wil); 488b7cde470SVladimir Kondratiev break; 48974997a53SLior David case doff_u8: 490ce564170SGreg Kroah-Hartman debugfs_create_u8(tbl[i].name, tbl[i].mode, dbg, 49174997a53SLior David base + tbl[i].off); 49274997a53SLior David break; 493b7cde470SVladimir Kondratiev } 494b7cde470SVladimir Kondratiev } 495b7cde470SVladimir Kondratiev } 496b7cde470SVladimir Kondratiev 497b7cde470SVladimir Kondratiev static const struct dbg_off isr_off[] = { 49878484c44SMaya Erez {"ICC", 0644, offsetof(struct RGF_ICR, ICC), doff_io32}, 49978484c44SMaya Erez {"ICR", 0644, offsetof(struct RGF_ICR, ICR), doff_io32}, 50078484c44SMaya Erez {"ICM", 0644, offsetof(struct RGF_ICR, ICM), doff_io32}, 50178484c44SMaya Erez {"ICS", 0244, offsetof(struct RGF_ICR, ICS), doff_io32}, 50278484c44SMaya Erez {"IMV", 0644, offsetof(struct RGF_ICR, IMV), doff_io32}, 50378484c44SMaya Erez {"IMS", 0244, offsetof(struct RGF_ICR, IMS), doff_io32}, 50478484c44SMaya Erez {"IMC", 0244, offsetof(struct RGF_ICR, IMC), doff_io32}, 505b7cde470SVladimir Kondratiev {}, 506b7cde470SVladimir Kondratiev }; 5078fe59627SVladimir Kondratiev 508ce564170SGreg Kroah-Hartman static void wil6210_debugfs_create_ISR(struct wil6210_priv *wil, 509ce564170SGreg Kroah-Hartman const char *name, struct dentry *parent, 510ce564170SGreg Kroah-Hartman u32 off) 5112be7d22fSVladimir Kondratiev { 5122be7d22fSVladimir Kondratiev struct dentry *d = debugfs_create_dir(name, parent); 5132be7d22fSVladimir Kondratiev 514b7cde470SVladimir Kondratiev wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off, 515b7cde470SVladimir Kondratiev isr_off); 5162be7d22fSVladimir Kondratiev } 5172be7d22fSVladimir Kondratiev 518b7cde470SVladimir Kondratiev static const struct dbg_off pseudo_isr_off[] = { 51978484c44SMaya Erez {"CAUSE", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32}, 52078484c44SMaya Erez {"MASK_SW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32}, 52178484c44SMaya Erez {"MASK_FW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32}, 522b7cde470SVladimir Kondratiev {}, 523b7cde470SVladimir Kondratiev }; 524b7cde470SVladimir Kondratiev 525ce564170SGreg Kroah-Hartman static void wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil, 5262be7d22fSVladimir Kondratiev struct dentry *parent) 5272be7d22fSVladimir Kondratiev { 5282be7d22fSVladimir Kondratiev struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent); 5292be7d22fSVladimir Kondratiev 530b7cde470SVladimir Kondratiev wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr, 531b7cde470SVladimir Kondratiev pseudo_isr_off); 5322be7d22fSVladimir Kondratiev } 5332be7d22fSVladimir Kondratiev 53478366f69SVladimir Kondratiev static const struct dbg_off lgc_itr_cnt_off[] = { 53578484c44SMaya Erez {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32}, 53678484c44SMaya Erez {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32}, 53778484c44SMaya Erez {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32}, 538b7cde470SVladimir Kondratiev {}, 539b7cde470SVladimir Kondratiev }; 540b7cde470SVladimir Kondratiev 54178366f69SVladimir Kondratiev static const struct dbg_off tx_itr_cnt_off[] = { 54278484c44SMaya Erez {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_TRSH), 54378366f69SVladimir Kondratiev doff_io32}, 54478484c44SMaya Erez {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_DATA), 54578366f69SVladimir Kondratiev doff_io32}, 54678484c44SMaya Erez {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_CTL), 54778366f69SVladimir Kondratiev doff_io32}, 54878484c44SMaya Erez {"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_TRSH), 54978366f69SVladimir Kondratiev doff_io32}, 55078484c44SMaya Erez {"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_DATA), 55178366f69SVladimir Kondratiev doff_io32}, 55278484c44SMaya Erez {"IDL_CTL", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_CTL), 55378366f69SVladimir Kondratiev doff_io32}, 55478366f69SVladimir Kondratiev {}, 55578366f69SVladimir Kondratiev }; 55678366f69SVladimir Kondratiev 55778366f69SVladimir Kondratiev static const struct dbg_off rx_itr_cnt_off[] = { 55878484c44SMaya Erez {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_TRSH), 55978366f69SVladimir Kondratiev doff_io32}, 56078484c44SMaya Erez {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_DATA), 56178366f69SVladimir Kondratiev doff_io32}, 56278484c44SMaya Erez {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_CTL), 56378366f69SVladimir Kondratiev doff_io32}, 56478484c44SMaya Erez {"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_TRSH), 56578366f69SVladimir Kondratiev doff_io32}, 56678484c44SMaya Erez {"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_DATA), 56778366f69SVladimir Kondratiev doff_io32}, 56878484c44SMaya Erez {"IDL_CTL", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_CTL), 56978366f69SVladimir Kondratiev doff_io32}, 57078366f69SVladimir Kondratiev {}, 57178366f69SVladimir Kondratiev }; 57278366f69SVladimir Kondratiev 5732be7d22fSVladimir Kondratiev static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil, 5742be7d22fSVladimir Kondratiev struct dentry *parent) 5752be7d22fSVladimir Kondratiev { 57678366f69SVladimir Kondratiev struct dentry *d, *dtx, *drx; 5772be7d22fSVladimir Kondratiev 57878366f69SVladimir Kondratiev d = debugfs_create_dir("ITR_CNT", parent); 5792be7d22fSVladimir Kondratiev 58078366f69SVladimir Kondratiev dtx = debugfs_create_dir("TX", d); 58178366f69SVladimir Kondratiev drx = debugfs_create_dir("RX", d); 5822be7d22fSVladimir Kondratiev 58378366f69SVladimir Kondratiev wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr, 58478366f69SVladimir Kondratiev lgc_itr_cnt_off); 58578366f69SVladimir Kondratiev 58678366f69SVladimir Kondratiev wil6210_debugfs_init_offset(wil, dtx, (void * __force)wil->csr, 58778366f69SVladimir Kondratiev tx_itr_cnt_off); 58878366f69SVladimir Kondratiev 58978366f69SVladimir Kondratiev wil6210_debugfs_init_offset(wil, drx, (void * __force)wil->csr, 59078366f69SVladimir Kondratiev rx_itr_cnt_off); 5912be7d22fSVladimir Kondratiev return 0; 5922be7d22fSVladimir Kondratiev } 5932be7d22fSVladimir Kondratiev 594986b8348SYangtao Li static int memread_show(struct seq_file *s, void *data) 5952be7d22fSVladimir Kondratiev { 5962be7d22fSVladimir Kondratiev struct wil6210_priv *wil = s->private; 59794162666SLazar Alexei void __iomem *a; 59894162666SLazar Alexei int ret; 59994162666SLazar Alexei 60094162666SLazar Alexei ret = wil_pm_runtime_get(wil); 60194162666SLazar Alexei if (ret < 0) 60294162666SLazar Alexei return ret; 60394162666SLazar Alexei 604a0618945SAhmad Masri ret = wil_mem_access_lock(wil); 605a0618945SAhmad Masri if (ret) { 606a0618945SAhmad Masri wil_pm_runtime_put(wil); 607a0618945SAhmad Masri return ret; 608a0618945SAhmad Masri } 609a0618945SAhmad Masri 61094162666SLazar Alexei a = wmi_buffer(wil, cpu_to_le32(mem_addr)); 6112be7d22fSVladimir Kondratiev 6122be7d22fSVladimir Kondratiev if (a) 613b9eeb512SVladimir Kondratiev seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, readl(a)); 6142be7d22fSVladimir Kondratiev else 6152be7d22fSVladimir Kondratiev seq_printf(s, "[0x%08x] = INVALID\n", mem_addr); 6162be7d22fSVladimir Kondratiev 617a0618945SAhmad Masri wil_mem_access_unlock(wil); 61894162666SLazar Alexei wil_pm_runtime_put(wil); 61994162666SLazar Alexei 6202be7d22fSVladimir Kondratiev return 0; 6212be7d22fSVladimir Kondratiev } 622986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(memread); 6232be7d22fSVladimir Kondratiev 6242be7d22fSVladimir Kondratiev static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf, 6252be7d22fSVladimir Kondratiev size_t count, loff_t *ppos) 6262be7d22fSVladimir Kondratiev { 6272be7d22fSVladimir Kondratiev enum { max_count = 4096 }; 628349214c1SMaya Erez struct wil_blob_wrapper *wil_blob = file->private_data; 62994162666SLazar Alexei struct wil6210_priv *wil = wil_blob->wil; 63084ec040dSAhmad Masri loff_t aligned_pos, pos = *ppos; 631349214c1SMaya Erez size_t available = wil_blob->blob.size; 6322be7d22fSVladimir Kondratiev void *buf; 63384ec040dSAhmad Masri size_t unaligned_bytes, aligned_count, ret; 63494162666SLazar Alexei int rc; 6352be7d22fSVladimir Kondratiev 6362be7d22fSVladimir Kondratiev if (pos < 0) 6372be7d22fSVladimir Kondratiev return -EINVAL; 6382be7d22fSVladimir Kondratiev 6392be7d22fSVladimir Kondratiev if (pos >= available || !count) 6402be7d22fSVladimir Kondratiev return 0; 6412be7d22fSVladimir Kondratiev 6422be7d22fSVladimir Kondratiev if (count > available - pos) 6432be7d22fSVladimir Kondratiev count = available - pos; 6442be7d22fSVladimir Kondratiev if (count > max_count) 6452be7d22fSVladimir Kondratiev count = max_count; 6462be7d22fSVladimir Kondratiev 64784ec040dSAhmad Masri /* set pos to 4 bytes aligned */ 64884ec040dSAhmad Masri unaligned_bytes = pos % 4; 64984ec040dSAhmad Masri aligned_pos = pos - unaligned_bytes; 65084ec040dSAhmad Masri aligned_count = count + unaligned_bytes; 65184ec040dSAhmad Masri 65284ec040dSAhmad Masri buf = kmalloc(aligned_count, GFP_KERNEL); 6532be7d22fSVladimir Kondratiev if (!buf) 6542be7d22fSVladimir Kondratiev return -ENOMEM; 6552be7d22fSVladimir Kondratiev 65694162666SLazar Alexei rc = wil_pm_runtime_get(wil); 65794162666SLazar Alexei if (rc < 0) { 65894162666SLazar Alexei kfree(buf); 65994162666SLazar Alexei return rc; 66094162666SLazar Alexei } 66194162666SLazar Alexei 662a0618945SAhmad Masri rc = wil_mem_access_lock(wil); 663a0618945SAhmad Masri if (rc) { 664a0618945SAhmad Masri kfree(buf); 665a0618945SAhmad Masri wil_pm_runtime_put(wil); 666a0618945SAhmad Masri return rc; 667a0618945SAhmad Masri } 668a0618945SAhmad Masri 669bd50e268SMaya Erez wil_memcpy_fromio_32(buf, (const void __iomem *) 67084ec040dSAhmad Masri wil_blob->blob.data + aligned_pos, aligned_count); 6712be7d22fSVladimir Kondratiev 67284ec040dSAhmad Masri ret = copy_to_user(user_buf, buf + unaligned_bytes, count); 67394162666SLazar Alexei 674a0618945SAhmad Masri wil_mem_access_unlock(wil); 67594162666SLazar Alexei wil_pm_runtime_put(wil); 67694162666SLazar Alexei 6772be7d22fSVladimir Kondratiev kfree(buf); 6782be7d22fSVladimir Kondratiev if (ret == count) 6792be7d22fSVladimir Kondratiev return -EFAULT; 6802be7d22fSVladimir Kondratiev 6812be7d22fSVladimir Kondratiev count -= ret; 6822be7d22fSVladimir Kondratiev *ppos = pos + count; 6832be7d22fSVladimir Kondratiev 6842be7d22fSVladimir Kondratiev return count; 6852be7d22fSVladimir Kondratiev } 6862be7d22fSVladimir Kondratiev 6872be7d22fSVladimir Kondratiev static const struct file_operations fops_ioblob = { 6882be7d22fSVladimir Kondratiev .read = wil_read_file_ioblob, 68993ecbd64SWei Yongjun .open = simple_open, 6902be7d22fSVladimir Kondratiev .llseek = default_llseek, 6912be7d22fSVladimir Kondratiev }; 6922be7d22fSVladimir Kondratiev 6932be7d22fSVladimir Kondratiev static 6942be7d22fSVladimir Kondratiev struct dentry *wil_debugfs_create_ioblob(const char *name, 6950ecc833bSAl Viro umode_t mode, 6962be7d22fSVladimir Kondratiev struct dentry *parent, 697349214c1SMaya Erez struct wil_blob_wrapper *wil_blob) 6982be7d22fSVladimir Kondratiev { 699349214c1SMaya Erez return debugfs_create_file(name, mode, parent, wil_blob, &fops_ioblob); 7002be7d22fSVladimir Kondratiev } 7018fe59627SVladimir Kondratiev 7020b39aaf2SVladimir Kondratiev /*---write channel 1..4 to rxon for it, 0 to rxoff---*/ 7030b39aaf2SVladimir Kondratiev static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf, 7040b39aaf2SVladimir Kondratiev size_t len, loff_t *ppos) 7050b39aaf2SVladimir Kondratiev { 7060b39aaf2SVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 7070b39aaf2SVladimir Kondratiev int rc; 7080b39aaf2SVladimir Kondratiev long channel; 7090b39aaf2SVladimir Kondratiev bool on; 7100b39aaf2SVladimir Kondratiev 71116e5c1fcSAl Viro char *kbuf = memdup_user_nul(buf, len); 7128fe59627SVladimir Kondratiev 71316e5c1fcSAl Viro if (IS_ERR(kbuf)) 71416e5c1fcSAl Viro return PTR_ERR(kbuf); 7150b39aaf2SVladimir Kondratiev rc = kstrtol(kbuf, 0, &channel); 7160b39aaf2SVladimir Kondratiev kfree(kbuf); 7170b39aaf2SVladimir Kondratiev if (rc) 7180b39aaf2SVladimir Kondratiev return rc; 7190b39aaf2SVladimir Kondratiev 7200b39aaf2SVladimir Kondratiev if ((channel < 0) || (channel > 4)) { 7210b39aaf2SVladimir Kondratiev wil_err(wil, "Invalid channel %ld\n", channel); 7220b39aaf2SVladimir Kondratiev return -EINVAL; 7230b39aaf2SVladimir Kondratiev } 7240b39aaf2SVladimir Kondratiev on = !!channel; 7250b39aaf2SVladimir Kondratiev 7260b39aaf2SVladimir Kondratiev if (on) { 7270b39aaf2SVladimir Kondratiev rc = wmi_set_channel(wil, (int)channel); 7280b39aaf2SVladimir Kondratiev if (rc) 7290b39aaf2SVladimir Kondratiev return rc; 7300b39aaf2SVladimir Kondratiev } 7310b39aaf2SVladimir Kondratiev 7320b39aaf2SVladimir Kondratiev rc = wmi_rxon(wil, on); 7330b39aaf2SVladimir Kondratiev if (rc) 7340b39aaf2SVladimir Kondratiev return rc; 7350b39aaf2SVladimir Kondratiev 7360b39aaf2SVladimir Kondratiev return len; 7370b39aaf2SVladimir Kondratiev } 7380b39aaf2SVladimir Kondratiev 7390b39aaf2SVladimir Kondratiev static const struct file_operations fops_rxon = { 7400b39aaf2SVladimir Kondratiev .write = wil_write_file_rxon, 7410b39aaf2SVladimir Kondratiev .open = simple_open, 7420b39aaf2SVladimir Kondratiev }; 7438fe59627SVladimir Kondratiev 744*c5b3a658SAlexei Avshalom Lazar static ssize_t wil_write_file_rbufcap(struct file *file, 745*c5b3a658SAlexei Avshalom Lazar const char __user *buf, 746*c5b3a658SAlexei Avshalom Lazar size_t count, loff_t *ppos) 747*c5b3a658SAlexei Avshalom Lazar { 748*c5b3a658SAlexei Avshalom Lazar struct wil6210_priv *wil = file->private_data; 749*c5b3a658SAlexei Avshalom Lazar int val; 750*c5b3a658SAlexei Avshalom Lazar int rc; 751*c5b3a658SAlexei Avshalom Lazar 752*c5b3a658SAlexei Avshalom Lazar rc = kstrtoint_from_user(buf, count, 0, &val); 753*c5b3a658SAlexei Avshalom Lazar if (rc) { 754*c5b3a658SAlexei Avshalom Lazar wil_err(wil, "Invalid argument\n"); 755*c5b3a658SAlexei Avshalom Lazar return rc; 756*c5b3a658SAlexei Avshalom Lazar } 757*c5b3a658SAlexei Avshalom Lazar /* input value: negative to disable, 0 to use system default, 758*c5b3a658SAlexei Avshalom Lazar * 1..ring size to set descriptor threshold 759*c5b3a658SAlexei Avshalom Lazar */ 760*c5b3a658SAlexei Avshalom Lazar wil_info(wil, "%s RBUFCAP, descriptors threshold - %d\n", 761*c5b3a658SAlexei Avshalom Lazar val < 0 ? "Disabling" : "Enabling", val); 762*c5b3a658SAlexei Avshalom Lazar 763*c5b3a658SAlexei Avshalom Lazar if (!wil->ring_rx.va || val > wil->ring_rx.size) { 764*c5b3a658SAlexei Avshalom Lazar wil_err(wil, "Invalid descriptors threshold, %d\n", val); 765*c5b3a658SAlexei Avshalom Lazar return -EINVAL; 766*c5b3a658SAlexei Avshalom Lazar } 767*c5b3a658SAlexei Avshalom Lazar 768*c5b3a658SAlexei Avshalom Lazar rc = wmi_rbufcap_cfg(wil, val < 0 ? 0 : 1, val < 0 ? 0 : val); 769*c5b3a658SAlexei Avshalom Lazar if (rc) { 770*c5b3a658SAlexei Avshalom Lazar wil_err(wil, "RBUFCAP config failed: %d\n", rc); 771*c5b3a658SAlexei Avshalom Lazar return rc; 772*c5b3a658SAlexei Avshalom Lazar } 773*c5b3a658SAlexei Avshalom Lazar 774*c5b3a658SAlexei Avshalom Lazar return count; 775*c5b3a658SAlexei Avshalom Lazar } 776*c5b3a658SAlexei Avshalom Lazar 777*c5b3a658SAlexei Avshalom Lazar static const struct file_operations fops_rbufcap = { 778*c5b3a658SAlexei Avshalom Lazar .write = wil_write_file_rbufcap, 779*c5b3a658SAlexei Avshalom Lazar .open = simple_open, 780*c5b3a658SAlexei Avshalom Lazar }; 781*c5b3a658SAlexei Avshalom Lazar 78249cb5dfbSVladimir Kondratiev /* block ack control, write: 78349cb5dfbSVladimir Kondratiev * - "add <ringid> <agg_size> <timeout>" to trigger ADDBA 78449cb5dfbSVladimir Kondratiev * - "del_tx <ringid> <reason>" to trigger DELBA for Tx side 78549cb5dfbSVladimir Kondratiev * - "del_rx <CID> <TID> <reason>" to trigger DELBA for Rx side 7863277213fSVladimir Kondratiev */ 78749cb5dfbSVladimir Kondratiev static ssize_t wil_write_back(struct file *file, const char __user *buf, 7883277213fSVladimir Kondratiev size_t len, loff_t *ppos) 7893277213fSVladimir Kondratiev { 7903277213fSVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 7913277213fSVladimir Kondratiev int rc; 7923277213fSVladimir Kondratiev char *kbuf = kmalloc(len + 1, GFP_KERNEL); 7932a19f776SColin Ian King char cmd[9]; 79449cb5dfbSVladimir Kondratiev int p1, p2, p3; 7953277213fSVladimir Kondratiev 7963277213fSVladimir Kondratiev if (!kbuf) 7973277213fSVladimir Kondratiev return -ENOMEM; 7983277213fSVladimir Kondratiev 7993277213fSVladimir Kondratiev rc = simple_write_to_buffer(kbuf, len, ppos, buf, len); 8003277213fSVladimir Kondratiev if (rc != len) { 8013277213fSVladimir Kondratiev kfree(kbuf); 8023277213fSVladimir Kondratiev return rc >= 0 ? -EIO : rc; 8033277213fSVladimir Kondratiev } 8043277213fSVladimir Kondratiev 8053277213fSVladimir Kondratiev kbuf[len] = '\0'; 80649cb5dfbSVladimir Kondratiev rc = sscanf(kbuf, "%8s %d %d %d", cmd, &p1, &p2, &p3); 8073277213fSVladimir Kondratiev kfree(kbuf); 8083277213fSVladimir Kondratiev 80949cb5dfbSVladimir Kondratiev if (rc < 0) 8103277213fSVladimir Kondratiev return rc; 81149cb5dfbSVladimir Kondratiev if (rc < 2) 8123277213fSVladimir Kondratiev return -EINVAL; 8133277213fSVladimir Kondratiev 814e00243faSLior David if ((strcmp(cmd, "add") == 0) || 815e00243faSLior David (strcmp(cmd, "del_tx") == 0)) { 81610590c6aSGidon Studinski struct wil_ring_tx_data *txdata; 817e00243faSLior David 818e00243faSLior David if (p1 < 0 || p1 >= WIL6210_MAX_TX_RINGS) { 819e00243faSLior David wil_err(wil, "BACK: invalid ring id %d\n", p1); 820e00243faSLior David return -EINVAL; 821e00243faSLior David } 82210590c6aSGidon Studinski txdata = &wil->ring_tx_data[p1]; 823e00243faSLior David if (strcmp(cmd, "add") == 0) { 82449cb5dfbSVladimir Kondratiev if (rc < 3) { 82549cb5dfbSVladimir Kondratiev wil_err(wil, "BACK: add require at least 2 params\n"); 82649cb5dfbSVladimir Kondratiev return -EINVAL; 82749cb5dfbSVladimir Kondratiev } 82849cb5dfbSVladimir Kondratiev if (rc < 4) 82949cb5dfbSVladimir Kondratiev p3 = 0; 830e00243faSLior David wmi_addba(wil, txdata->mid, p1, p2, p3); 831e00243faSLior David } else { 83249cb5dfbSVladimir Kondratiev if (rc < 3) 83349cb5dfbSVladimir Kondratiev p2 = WLAN_REASON_QSTA_LEAVE_QBSS; 834e00243faSLior David wmi_delba_tx(wil, txdata->mid, p1, p2); 835e00243faSLior David } 836e00243faSLior David } else if (strcmp(cmd, "del_rx") == 0) { 837e00243faSLior David struct wil_sta_info *sta; 838e00243faSLior David 83949cb5dfbSVladimir Kondratiev if (rc < 3) { 84049cb5dfbSVladimir Kondratiev wil_err(wil, 84149cb5dfbSVladimir Kondratiev "BACK: del_rx require at least 2 params\n"); 84249cb5dfbSVladimir Kondratiev return -EINVAL; 84349cb5dfbSVladimir Kondratiev } 844ddf7afddSAhmad Masri if (p1 < 0 || p1 >= wil->max_assoc_sta) { 845e00243faSLior David wil_err(wil, "BACK: invalid CID %d\n", p1); 846e00243faSLior David return -EINVAL; 847e00243faSLior David } 84849cb5dfbSVladimir Kondratiev if (rc < 4) 84949cb5dfbSVladimir Kondratiev p3 = WLAN_REASON_QSTA_LEAVE_QBSS; 850e00243faSLior David sta = &wil->sta[p1]; 851bf0353a6SAhmad Masri wmi_delba_rx(wil, sta->mid, p1, p2, p3); 85249cb5dfbSVladimir Kondratiev } else { 85349cb5dfbSVladimir Kondratiev wil_err(wil, "BACK: Unrecognized command \"%s\"\n", cmd); 85449cb5dfbSVladimir Kondratiev return -EINVAL; 85549cb5dfbSVladimir Kondratiev } 8563277213fSVladimir Kondratiev 8573277213fSVladimir Kondratiev return len; 8583277213fSVladimir Kondratiev } 8593277213fSVladimir Kondratiev 86049cb5dfbSVladimir Kondratiev static ssize_t wil_read_back(struct file *file, char __user *user_buf, 86149cb5dfbSVladimir Kondratiev size_t count, loff_t *ppos) 86249cb5dfbSVladimir Kondratiev { 86349cb5dfbSVladimir Kondratiev static const char text[] = "block ack control, write:\n" 86449cb5dfbSVladimir Kondratiev " - \"add <ringid> <agg_size> <timeout>\" to trigger ADDBA\n" 86549cb5dfbSVladimir Kondratiev "If missing, <timeout> defaults to 0\n" 86649cb5dfbSVladimir Kondratiev " - \"del_tx <ringid> <reason>\" to trigger DELBA for Tx side\n" 86749cb5dfbSVladimir Kondratiev " - \"del_rx <CID> <TID> <reason>\" to trigger DELBA for Rx side\n" 86849cb5dfbSVladimir Kondratiev "If missing, <reason> set to \"STA_LEAVING\" (36)\n"; 86949cb5dfbSVladimir Kondratiev 87049cb5dfbSVladimir Kondratiev return simple_read_from_buffer(user_buf, count, ppos, text, 87149cb5dfbSVladimir Kondratiev sizeof(text)); 87249cb5dfbSVladimir Kondratiev } 87349cb5dfbSVladimir Kondratiev 87449cb5dfbSVladimir Kondratiev static const struct file_operations fops_back = { 87549cb5dfbSVladimir Kondratiev .read = wil_read_back, 87649cb5dfbSVladimir Kondratiev .write = wil_write_back, 8773277213fSVladimir Kondratiev .open = simple_open, 8783277213fSVladimir Kondratiev }; 8793277213fSVladimir Kondratiev 880dc16427bSVladimir Kondratiev /* pmc control, write: 881dc16427bSVladimir Kondratiev * - "alloc <num descriptors> <descriptor_size>" to allocate PMC 882dc16427bSVladimir Kondratiev * - "free" to release memory allocated for PMC 883dc16427bSVladimir Kondratiev */ 884dc16427bSVladimir Kondratiev static ssize_t wil_write_pmccfg(struct file *file, const char __user *buf, 885dc16427bSVladimir Kondratiev size_t len, loff_t *ppos) 886dc16427bSVladimir Kondratiev { 887dc16427bSVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 888dc16427bSVladimir Kondratiev int rc; 889dc16427bSVladimir Kondratiev char *kbuf = kmalloc(len + 1, GFP_KERNEL); 890dc16427bSVladimir Kondratiev char cmd[9]; 891dc16427bSVladimir Kondratiev int num_descs, desc_size; 892dc16427bSVladimir Kondratiev 893dc16427bSVladimir Kondratiev if (!kbuf) 894dc16427bSVladimir Kondratiev return -ENOMEM; 895dc16427bSVladimir Kondratiev 896dc16427bSVladimir Kondratiev rc = simple_write_to_buffer(kbuf, len, ppos, buf, len); 897dc16427bSVladimir Kondratiev if (rc != len) { 898dc16427bSVladimir Kondratiev kfree(kbuf); 899dc16427bSVladimir Kondratiev return rc >= 0 ? -EIO : rc; 900dc16427bSVladimir Kondratiev } 901dc16427bSVladimir Kondratiev 902dc16427bSVladimir Kondratiev kbuf[len] = '\0'; 903dc16427bSVladimir Kondratiev rc = sscanf(kbuf, "%8s %d %d", cmd, &num_descs, &desc_size); 904dc16427bSVladimir Kondratiev kfree(kbuf); 905dc16427bSVladimir Kondratiev 906dc16427bSVladimir Kondratiev if (rc < 0) 907dc16427bSVladimir Kondratiev return rc; 908dc16427bSVladimir Kondratiev 909dc16427bSVladimir Kondratiev if (rc < 1) { 910dc16427bSVladimir Kondratiev wil_err(wil, "pmccfg: no params given\n"); 911dc16427bSVladimir Kondratiev return -EINVAL; 912dc16427bSVladimir Kondratiev } 913dc16427bSVladimir Kondratiev 914dc16427bSVladimir Kondratiev if (0 == strcmp(cmd, "alloc")) { 915dc16427bSVladimir Kondratiev if (rc != 3) { 916dc16427bSVladimir Kondratiev wil_err(wil, "pmccfg: alloc requires 2 params\n"); 917dc16427bSVladimir Kondratiev return -EINVAL; 918dc16427bSVladimir Kondratiev } 919dc16427bSVladimir Kondratiev wil_pmc_alloc(wil, num_descs, desc_size); 920dc16427bSVladimir Kondratiev } else if (0 == strcmp(cmd, "free")) { 921dc16427bSVladimir Kondratiev if (rc != 1) { 922dc16427bSVladimir Kondratiev wil_err(wil, "pmccfg: free does not have any params\n"); 923dc16427bSVladimir Kondratiev return -EINVAL; 924dc16427bSVladimir Kondratiev } 925dc16427bSVladimir Kondratiev wil_pmc_free(wil, true); 926dc16427bSVladimir Kondratiev } else { 927dc16427bSVladimir Kondratiev wil_err(wil, "pmccfg: Unrecognized command \"%s\"\n", cmd); 928dc16427bSVladimir Kondratiev return -EINVAL; 929dc16427bSVladimir Kondratiev } 930dc16427bSVladimir Kondratiev 931dc16427bSVladimir Kondratiev return len; 932dc16427bSVladimir Kondratiev } 933dc16427bSVladimir Kondratiev 934dc16427bSVladimir Kondratiev static ssize_t wil_read_pmccfg(struct file *file, char __user *user_buf, 935dc16427bSVladimir Kondratiev size_t count, loff_t *ppos) 936dc16427bSVladimir Kondratiev { 937dc16427bSVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 938dc16427bSVladimir Kondratiev char text[256]; 939dc16427bSVladimir Kondratiev char help[] = "pmc control, write:\n" 940dc16427bSVladimir Kondratiev " - \"alloc <num descriptors> <descriptor_size>\" to allocate pmc\n" 941dc16427bSVladimir Kondratiev " - \"free\" to free memory allocated for pmc\n"; 942dc16427bSVladimir Kondratiev 943dc16427bSVladimir Kondratiev sprintf(text, "Last command status: %d\n\n%s", 944dc16427bSVladimir Kondratiev wil_pmc_last_cmd_status(wil), 945dc16427bSVladimir Kondratiev help); 946dc16427bSVladimir Kondratiev 947dc16427bSVladimir Kondratiev return simple_read_from_buffer(user_buf, count, ppos, text, 948dc16427bSVladimir Kondratiev strlen(text) + 1); 949dc16427bSVladimir Kondratiev } 950dc16427bSVladimir Kondratiev 951dc16427bSVladimir Kondratiev static const struct file_operations fops_pmccfg = { 952dc16427bSVladimir Kondratiev .read = wil_read_pmccfg, 953dc16427bSVladimir Kondratiev .write = wil_write_pmccfg, 954dc16427bSVladimir Kondratiev .open = simple_open, 955dc16427bSVladimir Kondratiev }; 956dc16427bSVladimir Kondratiev 957dc16427bSVladimir Kondratiev static const struct file_operations fops_pmcdata = { 958dc16427bSVladimir Kondratiev .open = simple_open, 959dc16427bSVladimir Kondratiev .read = wil_pmc_read, 960dc16427bSVladimir Kondratiev .llseek = wil_pmc_llseek, 961dc16427bSVladimir Kondratiev }; 962dc16427bSVladimir Kondratiev 9630b39aaf2SVladimir Kondratiev /*---tx_mgmt---*/ 9640b39aaf2SVladimir Kondratiev /* Write mgmt frame to this file to send it */ 9650b39aaf2SVladimir Kondratiev static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf, 9660b39aaf2SVladimir Kondratiev size_t len, loff_t *ppos) 9670b39aaf2SVladimir Kondratiev { 9680b39aaf2SVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 9690b39aaf2SVladimir Kondratiev struct wiphy *wiphy = wil_to_wiphy(wil); 970e00243faSLior David struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr; 9710b39aaf2SVladimir Kondratiev struct cfg80211_mgmt_tx_params params; 9720b39aaf2SVladimir Kondratiev int rc; 9739a492909SGeliang Tang void *frame; 9748fe59627SVladimir Kondratiev 975ac0e541aSAlexei Avshalom Lazar memset(¶ms, 0, sizeof(params)); 976ac0e541aSAlexei Avshalom Lazar 9776641525cSHamad Kadmany if (!len) 9786641525cSHamad Kadmany return -EINVAL; 9796641525cSHamad Kadmany 9809a492909SGeliang Tang frame = memdup_user(buf, len); 9819a492909SGeliang Tang if (IS_ERR(frame)) 9829a492909SGeliang Tang return PTR_ERR(frame); 9830b39aaf2SVladimir Kondratiev 9840b39aaf2SVladimir Kondratiev params.buf = frame; 9850b39aaf2SVladimir Kondratiev params.len = len; 9860b39aaf2SVladimir Kondratiev 9870b39aaf2SVladimir Kondratiev rc = wil_cfg80211_mgmt_tx(wiphy, wdev, ¶ms, NULL); 9880b39aaf2SVladimir Kondratiev 9890b39aaf2SVladimir Kondratiev kfree(frame); 990af3db60aSLazar Alexei wil_info(wil, "-> %d\n", rc); 9910b39aaf2SVladimir Kondratiev 9920b39aaf2SVladimir Kondratiev return len; 9930b39aaf2SVladimir Kondratiev } 9940b39aaf2SVladimir Kondratiev 9950b39aaf2SVladimir Kondratiev static const struct file_operations fops_txmgmt = { 9960b39aaf2SVladimir Kondratiev .write = wil_write_file_txmgmt, 9970b39aaf2SVladimir Kondratiev .open = simple_open, 9980b39aaf2SVladimir Kondratiev }; 9992be7d22fSVladimir Kondratiev 1000ff974e40SVladimir Kondratiev /* Write WMI command (w/o mbox header) to this file to send it 1001ff974e40SVladimir Kondratiev * WMI starts from wil6210_mbox_hdr_wmi header 1002ff974e40SVladimir Kondratiev */ 1003ff974e40SVladimir Kondratiev static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf, 1004ff974e40SVladimir Kondratiev size_t len, loff_t *ppos) 1005ff974e40SVladimir Kondratiev { 1006ff974e40SVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 1007e00243faSLior David struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev); 1008b874ddecSLior David struct wmi_cmd_hdr *wmi; 1009ff974e40SVladimir Kondratiev void *cmd; 1010b874ddecSLior David int cmdlen = len - sizeof(struct wmi_cmd_hdr); 1011ff974e40SVladimir Kondratiev u16 cmdid; 1012ff974e40SVladimir Kondratiev int rc, rc1; 1013ff974e40SVladimir Kondratiev 101469218a48SLior David if (cmdlen < 0) 1015ff974e40SVladimir Kondratiev return -EINVAL; 1016ff974e40SVladimir Kondratiev 1017ff974e40SVladimir Kondratiev wmi = kmalloc(len, GFP_KERNEL); 1018ff974e40SVladimir Kondratiev if (!wmi) 1019ff974e40SVladimir Kondratiev return -ENOMEM; 1020ff974e40SVladimir Kondratiev 1021ff974e40SVladimir Kondratiev rc = simple_write_to_buffer(wmi, len, ppos, buf, len); 10228e09b7d2SLino Sanfilippo if (rc < 0) { 10238e09b7d2SLino Sanfilippo kfree(wmi); 1024ff974e40SVladimir Kondratiev return rc; 10258e09b7d2SLino Sanfilippo } 1026ff974e40SVladimir Kondratiev 102769218a48SLior David cmd = (cmdlen > 0) ? &wmi[1] : NULL; 1028b874ddecSLior David cmdid = le16_to_cpu(wmi->command_id); 1029ff974e40SVladimir Kondratiev 1030e00243faSLior David rc1 = wmi_send(wil, cmdid, vif->mid, cmd, cmdlen); 1031ff974e40SVladimir Kondratiev kfree(wmi); 1032ff974e40SVladimir Kondratiev 1033af3db60aSLazar Alexei wil_info(wil, "0x%04x[%d] -> %d\n", cmdid, cmdlen, rc1); 1034ff974e40SVladimir Kondratiev 1035ff974e40SVladimir Kondratiev return rc; 1036ff974e40SVladimir Kondratiev } 1037ff974e40SVladimir Kondratiev 1038ff974e40SVladimir Kondratiev static const struct file_operations fops_wmi = { 1039ff974e40SVladimir Kondratiev .write = wil_write_file_wmi, 1040ff974e40SVladimir Kondratiev .open = simple_open, 1041ff974e40SVladimir Kondratiev }; 1042ff974e40SVladimir Kondratiev 1043c236658fSVladimir Kondratiev static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb) 1044c236658fSVladimir Kondratiev { 1045c236658fSVladimir Kondratiev int i = 0; 1046c236658fSVladimir Kondratiev int len = skb_headlen(skb); 1047c236658fSVladimir Kondratiev void *p = skb->data; 1048c236658fSVladimir Kondratiev int nr_frags = skb_shinfo(skb)->nr_frags; 1049c236658fSVladimir Kondratiev 1050c236658fSVladimir Kondratiev seq_printf(s, " len = %d\n", len); 1051c236658fSVladimir Kondratiev wil_seq_hexdump(s, p, len, " : "); 1052c236658fSVladimir Kondratiev 1053c236658fSVladimir Kondratiev if (nr_frags) { 1054c236658fSVladimir Kondratiev seq_printf(s, " nr_frags = %d\n", nr_frags); 1055c236658fSVladimir Kondratiev for (i = 0; i < nr_frags; i++) { 1056c236658fSVladimir Kondratiev const struct skb_frag_struct *frag = 1057c236658fSVladimir Kondratiev &skb_shinfo(skb)->frags[i]; 1058c236658fSVladimir Kondratiev 1059c236658fSVladimir Kondratiev len = skb_frag_size(frag); 1060c236658fSVladimir Kondratiev p = skb_frag_address_safe(frag); 1061c236658fSVladimir Kondratiev seq_printf(s, " [%2d] : len = %d\n", i, len); 1062c236658fSVladimir Kondratiev wil_seq_hexdump(s, p, len, " : "); 1063c236658fSVladimir Kondratiev } 1064c236658fSVladimir Kondratiev } 1065c236658fSVladimir Kondratiev } 1066c236658fSVladimir Kondratiev 10673a85543eSVladimir Kondratiev /*---------Tx/Rx descriptor------------*/ 1068986b8348SYangtao Li static int txdesc_show(struct seq_file *s, void *data) 10692be7d22fSVladimir Kondratiev { 10702be7d22fSVladimir Kondratiev struct wil6210_priv *wil = s->private; 107110590c6aSGidon Studinski struct wil_ring *ring; 1072d98b8539SMaya Erez bool tx; 1073d98b8539SMaya Erez int ring_idx = dbg_ring_index; 1074d98b8539SMaya Erez int txdesc_idx = dbg_txdesc_index; 1075d98b8539SMaya Erez volatile struct vring_tx_desc *d; 1076d98b8539SMaya Erez volatile u32 *u; 1077d98b8539SMaya Erez struct sk_buff *skb; 10788fe59627SVladimir Kondratiev 1079d98b8539SMaya Erez if (wil->use_enhanced_dma_hw) { 1080d98b8539SMaya Erez /* RX ring index == 0 */ 1081d98b8539SMaya Erez if (ring_idx >= WIL6210_MAX_TX_RINGS) { 1082d98b8539SMaya Erez seq_printf(s, "invalid ring index %d\n", ring_idx); 1083d98b8539SMaya Erez return 0; 1084d98b8539SMaya Erez } 1085d98b8539SMaya Erez tx = ring_idx > 0; /* desc ring 0 is reserved for RX */ 1086d98b8539SMaya Erez } else { 1087d98b8539SMaya Erez /* RX ring index == WIL6210_MAX_TX_RINGS */ 1088d98b8539SMaya Erez if (ring_idx > WIL6210_MAX_TX_RINGS) { 1089d98b8539SMaya Erez seq_printf(s, "invalid ring index %d\n", ring_idx); 1090d98b8539SMaya Erez return 0; 1091d98b8539SMaya Erez } 1092d98b8539SMaya Erez tx = (ring_idx < WIL6210_MAX_TX_RINGS); 1093d98b8539SMaya Erez } 1094d98b8539SMaya Erez 1095d98b8539SMaya Erez ring = tx ? &wil->ring_tx[ring_idx] : &wil->ring_rx; 10962be7d22fSVladimir Kondratiev 109710590c6aSGidon Studinski if (!ring->va) { 1098af31cb5aSVladimir Kondratiev if (tx) 1099d98b8539SMaya Erez seq_printf(s, "No Tx[%2d] RING\n", ring_idx); 11003a85543eSVladimir Kondratiev else 1101d98b8539SMaya Erez seq_puts(s, "No Rx RING\n"); 11022be7d22fSVladimir Kondratiev return 0; 11032be7d22fSVladimir Kondratiev } 11042be7d22fSVladimir Kondratiev 1105d98b8539SMaya Erez if (txdesc_idx >= ring->size) { 1106d98b8539SMaya Erez if (tx) 1107d98b8539SMaya Erez seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n", 1108d98b8539SMaya Erez ring_idx, txdesc_idx, ring->size); 1109d98b8539SMaya Erez else 1110d98b8539SMaya Erez seq_printf(s, "RxDesc index (%d) >= size (%d)\n", 1111d98b8539SMaya Erez txdesc_idx, ring->size); 1112d98b8539SMaya Erez return 0; 1113d98b8539SMaya Erez } 1114d98b8539SMaya Erez 11153a85543eSVladimir Kondratiev /* use struct vring_tx_desc for Rx as well, 11163a85543eSVladimir Kondratiev * only field used, .dma.length, is the same 11173a85543eSVladimir Kondratiev */ 1118d98b8539SMaya Erez d = &ring->va[txdesc_idx].tx.legacy; 1119d98b8539SMaya Erez u = (volatile u32 *)d; 1120d98b8539SMaya Erez skb = NULL; 11212be7d22fSVladimir Kondratiev 1122d98b8539SMaya Erez if (wil->use_enhanced_dma_hw) { 1123d98b8539SMaya Erez if (tx) { 11249a874d04SDedy Lansky skb = ring->ctx ? ring->ctx[txdesc_idx].skb : NULL; 11259a874d04SDedy Lansky } else if (wil->rx_buff_mgmt.buff_arr) { 1126d98b8539SMaya Erez struct wil_rx_enhanced_desc *rx_d = 1127d98b8539SMaya Erez (struct wil_rx_enhanced_desc *) 1128d98b8539SMaya Erez &ring->va[txdesc_idx].rx.enhanced; 1129d98b8539SMaya Erez u16 buff_id = le16_to_cpu(rx_d->mac.buff_id); 1130d98b8539SMaya Erez 1131d98b8539SMaya Erez if (!wil_val_in_range(buff_id, 0, 11329a874d04SDedy Lansky wil->rx_buff_mgmt.size)) 1133d98b8539SMaya Erez seq_printf(s, "invalid buff_id %d\n", buff_id); 11349a874d04SDedy Lansky else 1135d98b8539SMaya Erez skb = wil->rx_buff_mgmt.buff_arr[buff_id].skb; 1136d98b8539SMaya Erez } 1137d98b8539SMaya Erez } else { 1138d98b8539SMaya Erez skb = ring->ctx[txdesc_idx].skb; 1139d98b8539SMaya Erez } 1140af31cb5aSVladimir Kondratiev if (tx) 1141d98b8539SMaya Erez seq_printf(s, "Tx[%2d][%3d] = {\n", ring_idx, 1142d98b8539SMaya Erez txdesc_idx); 11433a85543eSVladimir Kondratiev else 1144d98b8539SMaya Erez seq_printf(s, "Rx[%3d] = {\n", txdesc_idx); 11452be7d22fSVladimir Kondratiev seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n", 11462be7d22fSVladimir Kondratiev u[0], u[1], u[2], u[3]); 11472be7d22fSVladimir Kondratiev seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n", 11482be7d22fSVladimir Kondratiev u[4], u[5], u[6], u[7]); 114939c52ee8SVladimir Kondratiev seq_printf(s, " SKB = 0x%p\n", skb); 11502be7d22fSVladimir Kondratiev 11512be7d22fSVladimir Kondratiev if (skb) { 1152c236658fSVladimir Kondratiev skb_get(skb); 1153c236658fSVladimir Kondratiev wil_seq_print_skb(s, skb); 1154c236658fSVladimir Kondratiev kfree_skb(skb); 11552be7d22fSVladimir Kondratiev } 11568fe59627SVladimir Kondratiev seq_puts(s, "}\n"); 11572be7d22fSVladimir Kondratiev 11582be7d22fSVladimir Kondratiev return 0; 11592be7d22fSVladimir Kondratiev } 1160986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(txdesc); 11612be7d22fSVladimir Kondratiev 1162d98b8539SMaya Erez /*---------Tx/Rx status message------------*/ 1163986b8348SYangtao Li static int status_msg_show(struct seq_file *s, void *data) 1164d98b8539SMaya Erez { 1165d98b8539SMaya Erez struct wil6210_priv *wil = s->private; 1166d98b8539SMaya Erez int sring_idx = dbg_sring_index; 1167d98b8539SMaya Erez struct wil_status_ring *sring; 11689a874d04SDedy Lansky bool tx; 1169d98b8539SMaya Erez u32 status_msg_idx = dbg_status_msg_index; 1170d98b8539SMaya Erez u32 *u; 1171d98b8539SMaya Erez 1172d98b8539SMaya Erez if (sring_idx >= WIL6210_MAX_STATUS_RINGS) { 1173d98b8539SMaya Erez seq_printf(s, "invalid status ring index %d\n", sring_idx); 1174d98b8539SMaya Erez return 0; 1175d98b8539SMaya Erez } 1176d98b8539SMaya Erez 1177d98b8539SMaya Erez sring = &wil->srings[sring_idx]; 11789a874d04SDedy Lansky tx = !sring->is_rx; 1179d98b8539SMaya Erez 1180d98b8539SMaya Erez if (!sring->va) { 1181d98b8539SMaya Erez seq_printf(s, "No %cX status ring\n", tx ? 'T' : 'R'); 1182d98b8539SMaya Erez return 0; 1183d98b8539SMaya Erez } 1184d98b8539SMaya Erez 1185d98b8539SMaya Erez if (status_msg_idx >= sring->size) { 1186d98b8539SMaya Erez seq_printf(s, "%cxDesc index (%d) >= size (%d)\n", 1187d98b8539SMaya Erez tx ? 'T' : 'R', status_msg_idx, sring->size); 1188d98b8539SMaya Erez return 0; 1189d98b8539SMaya Erez } 1190d98b8539SMaya Erez 1191d98b8539SMaya Erez u = sring->va + (sring->elem_size * status_msg_idx); 1192d98b8539SMaya Erez 1193d98b8539SMaya Erez seq_printf(s, "%cx[%d][%3d] = {\n", 1194d98b8539SMaya Erez tx ? 'T' : 'R', sring_idx, status_msg_idx); 1195d98b8539SMaya Erez 1196d98b8539SMaya Erez seq_printf(s, " 0x%08x 0x%08x 0x%08x 0x%08x\n", 1197d98b8539SMaya Erez u[0], u[1], u[2], u[3]); 1198d98b8539SMaya Erez if (!tx && !wil->use_compressed_rx_status) 1199d98b8539SMaya Erez seq_printf(s, " 0x%08x 0x%08x 0x%08x 0x%08x\n", 1200d98b8539SMaya Erez u[4], u[5], u[6], u[7]); 1201d98b8539SMaya Erez 1202d98b8539SMaya Erez seq_puts(s, "}\n"); 1203d98b8539SMaya Erez 1204d98b8539SMaya Erez return 0; 1205d98b8539SMaya Erez } 1206986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(status_msg); 1207d98b8539SMaya Erez 1208d98b8539SMaya Erez static int wil_print_rx_buff(struct seq_file *s, struct list_head *lh) 1209d98b8539SMaya Erez { 1210d98b8539SMaya Erez struct wil_rx_buff *it; 1211d98b8539SMaya Erez int i = 0; 1212d98b8539SMaya Erez 1213d98b8539SMaya Erez list_for_each_entry(it, lh, list) { 1214d98b8539SMaya Erez if ((i % 16) == 0 && i != 0) 1215d98b8539SMaya Erez seq_puts(s, "\n "); 1216d98b8539SMaya Erez seq_printf(s, "[%4d] ", it->id); 1217d98b8539SMaya Erez i++; 1218d98b8539SMaya Erez } 1219d98b8539SMaya Erez seq_printf(s, "\nNumber of buffers: %u\n", i); 1220d98b8539SMaya Erez 1221d98b8539SMaya Erez return i; 1222d98b8539SMaya Erez } 1223d98b8539SMaya Erez 1224986b8348SYangtao Li static int rx_buff_mgmt_show(struct seq_file *s, void *data) 1225d98b8539SMaya Erez { 1226d98b8539SMaya Erez struct wil6210_priv *wil = s->private; 1227d98b8539SMaya Erez struct wil_rx_buff_mgmt *rbm = &wil->rx_buff_mgmt; 1228d98b8539SMaya Erez int num_active; 1229d98b8539SMaya Erez int num_free; 1230d98b8539SMaya Erez 12314405b632SDedy Lansky if (!rbm->buff_arr) 12324405b632SDedy Lansky return -EINVAL; 12334405b632SDedy Lansky 1234d98b8539SMaya Erez seq_printf(s, " size = %zu\n", rbm->size); 1235d98b8539SMaya Erez seq_printf(s, " free_list_empty_cnt = %lu\n", 1236d98b8539SMaya Erez rbm->free_list_empty_cnt); 1237d98b8539SMaya Erez 1238d98b8539SMaya Erez /* Print active list */ 1239d98b8539SMaya Erez seq_puts(s, " Active list:\n"); 1240d98b8539SMaya Erez num_active = wil_print_rx_buff(s, &rbm->active); 1241d98b8539SMaya Erez seq_puts(s, "\n Free list:\n"); 1242d98b8539SMaya Erez num_free = wil_print_rx_buff(s, &rbm->free); 1243d98b8539SMaya Erez 1244d98b8539SMaya Erez seq_printf(s, " Total number of buffers: %u\n", 1245d98b8539SMaya Erez num_active + num_free); 1246d98b8539SMaya Erez 1247d98b8539SMaya Erez return 0; 1248d98b8539SMaya Erez } 1249986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(rx_buff_mgmt); 1250d98b8539SMaya Erez 12512be7d22fSVladimir Kondratiev /*---------beamforming------------*/ 125236345ac3SVladimir Kondratiev static char *wil_bfstatus_str(u32 status) 125336345ac3SVladimir Kondratiev { 125436345ac3SVladimir Kondratiev switch (status) { 125536345ac3SVladimir Kondratiev case 0: 125636345ac3SVladimir Kondratiev return "Failed"; 125736345ac3SVladimir Kondratiev case 1: 125836345ac3SVladimir Kondratiev return "OK"; 125936345ac3SVladimir Kondratiev case 2: 126036345ac3SVladimir Kondratiev return "Retrying"; 126136345ac3SVladimir Kondratiev default: 126236345ac3SVladimir Kondratiev return "??"; 126336345ac3SVladimir Kondratiev } 126436345ac3SVladimir Kondratiev } 126536345ac3SVladimir Kondratiev 126636345ac3SVladimir Kondratiev static bool is_all_zeros(void * const x_, size_t sz) 126736345ac3SVladimir Kondratiev { 126836345ac3SVladimir Kondratiev /* if reply is all-0, ignore this CID */ 126936345ac3SVladimir Kondratiev u32 *x = x_; 127036345ac3SVladimir Kondratiev int n; 127136345ac3SVladimir Kondratiev 127236345ac3SVladimir Kondratiev for (n = 0; n < sz / sizeof(*x); n++) 127336345ac3SVladimir Kondratiev if (x[n]) 127436345ac3SVladimir Kondratiev return false; 127536345ac3SVladimir Kondratiev 127636345ac3SVladimir Kondratiev return true; 127736345ac3SVladimir Kondratiev } 127836345ac3SVladimir Kondratiev 1279986b8348SYangtao Li static int bf_show(struct seq_file *s, void *data) 12802be7d22fSVladimir Kondratiev { 128136345ac3SVladimir Kondratiev int rc; 128236345ac3SVladimir Kondratiev int i; 12832be7d22fSVladimir Kondratiev struct wil6210_priv *wil = s->private; 1284e00243faSLior David struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev); 128536345ac3SVladimir Kondratiev struct wmi_notify_req_cmd cmd = { 128636345ac3SVladimir Kondratiev .interval_usec = 0, 128736345ac3SVladimir Kondratiev }; 128836345ac3SVladimir Kondratiev struct { 1289b874ddecSLior David struct wmi_cmd_hdr wmi; 129036345ac3SVladimir Kondratiev struct wmi_notify_req_done_event evt; 129136345ac3SVladimir Kondratiev } __packed reply; 129236345ac3SVladimir Kondratiev 1293807b0860SAlexei Avshalom Lazar memset(&reply, 0, sizeof(reply)); 1294807b0860SAlexei Avshalom Lazar 1295ddf7afddSAhmad Masri for (i = 0; i < wil->max_assoc_sta; i++) { 129636345ac3SVladimir Kondratiev u32 status; 129736345ac3SVladimir Kondratiev 129836345ac3SVladimir Kondratiev cmd.cid = i; 1299e00243faSLior David rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, vif->mid, 1300e00243faSLior David &cmd, sizeof(cmd), 130136345ac3SVladimir Kondratiev WMI_NOTIFY_REQ_DONE_EVENTID, &reply, 130236345ac3SVladimir Kondratiev sizeof(reply), 20); 130336345ac3SVladimir Kondratiev /* if reply is all-0, ignore this CID */ 130436345ac3SVladimir Kondratiev if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt))) 130536345ac3SVladimir Kondratiev continue; 130636345ac3SVladimir Kondratiev 130736345ac3SVladimir Kondratiev status = le32_to_cpu(reply.evt.status); 130836345ac3SVladimir Kondratiev seq_printf(s, "CID %d {\n" 130936345ac3SVladimir Kondratiev " TSF = 0x%016llx\n" 131036345ac3SVladimir Kondratiev " TxMCS = %2d TxTpt = %4d\n" 131136345ac3SVladimir Kondratiev " SQI = %4d\n" 131230868f5dSDedy Lansky " RSSI = %4d\n" 131336345ac3SVladimir Kondratiev " Status = 0x%08x %s\n" 131436345ac3SVladimir Kondratiev " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n" 131536345ac3SVladimir Kondratiev " Goodput(rx:tx) %4d:%4d\n" 131636345ac3SVladimir Kondratiev "}\n", 131736345ac3SVladimir Kondratiev i, 131836345ac3SVladimir Kondratiev le64_to_cpu(reply.evt.tsf), 131936345ac3SVladimir Kondratiev le16_to_cpu(reply.evt.bf_mcs), 132036345ac3SVladimir Kondratiev le32_to_cpu(reply.evt.tx_tpt), 132136345ac3SVladimir Kondratiev reply.evt.sqi, 132230868f5dSDedy Lansky reply.evt.rssi, 132336345ac3SVladimir Kondratiev status, wil_bfstatus_str(status), 132436345ac3SVladimir Kondratiev le16_to_cpu(reply.evt.my_rx_sector), 132536345ac3SVladimir Kondratiev le16_to_cpu(reply.evt.my_tx_sector), 132636345ac3SVladimir Kondratiev le16_to_cpu(reply.evt.other_rx_sector), 132736345ac3SVladimir Kondratiev le16_to_cpu(reply.evt.other_tx_sector), 132836345ac3SVladimir Kondratiev le32_to_cpu(reply.evt.rx_goodput), 132936345ac3SVladimir Kondratiev le32_to_cpu(reply.evt.tx_goodput)); 133036345ac3SVladimir Kondratiev } 13312be7d22fSVladimir Kondratiev return 0; 13322be7d22fSVladimir Kondratiev } 1333986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(bf); 13348fe59627SVladimir Kondratiev 13351a2780e0SVladimir Kondratiev /*---------temp------------*/ 13366d9eb7ebSDedy Lansky static void print_temp(struct seq_file *s, const char *prefix, s32 t) 13371a2780e0SVladimir Kondratiev { 13381a2780e0SVladimir Kondratiev switch (t) { 13391a2780e0SVladimir Kondratiev case 0: 13401a2780e0SVladimir Kondratiev case ~(u32)0: 13411a2780e0SVladimir Kondratiev seq_printf(s, "%s N/A\n", prefix); 13421a2780e0SVladimir Kondratiev break; 13431a2780e0SVladimir Kondratiev default: 13446d9eb7ebSDedy Lansky seq_printf(s, "%s %s%d.%03d\n", prefix, (t < 0 ? "-" : ""), 13456d9eb7ebSDedy Lansky abs(t / 1000), abs(t % 1000)); 13461a2780e0SVladimir Kondratiev break; 13471a2780e0SVladimir Kondratiev } 13481a2780e0SVladimir Kondratiev } 13491a2780e0SVladimir Kondratiev 1350986b8348SYangtao Li static int temp_show(struct seq_file *s, void *data) 13511a2780e0SVladimir Kondratiev { 13521a2780e0SVladimir Kondratiev struct wil6210_priv *wil = s->private; 13536d9eb7ebSDedy Lansky s32 t_m, t_r; 13541a2780e0SVladimir Kondratiev int rc = wmi_get_temperature(wil, &t_m, &t_r); 13558fe59627SVladimir Kondratiev 13561a2780e0SVladimir Kondratiev if (rc) { 13578fe59627SVladimir Kondratiev seq_puts(s, "Failed\n"); 13581a2780e0SVladimir Kondratiev return 0; 13591a2780e0SVladimir Kondratiev } 13601a2780e0SVladimir Kondratiev 1361d45cff9fSVladimir Kondratiev print_temp(s, "T_mac =", t_m); 1362d45cff9fSVladimir Kondratiev print_temp(s, "T_radio =", t_r); 13631a2780e0SVladimir Kondratiev 13641a2780e0SVladimir Kondratiev return 0; 13651a2780e0SVladimir Kondratiev } 1366986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(temp); 13671a2780e0SVladimir Kondratiev 13689eb82d43SVladimir Kondratiev /*---------freq------------*/ 1369986b8348SYangtao Li static int freq_show(struct seq_file *s, void *data) 13709eb82d43SVladimir Kondratiev { 13719eb82d43SVladimir Kondratiev struct wil6210_priv *wil = s->private; 1372e00243faSLior David struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr; 13739cf0a0b4SAlexei Avshalom Lazar u32 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0; 13749eb82d43SVladimir Kondratiev 13759eb82d43SVladimir Kondratiev seq_printf(s, "Freq = %d\n", freq); 13769eb82d43SVladimir Kondratiev 13779eb82d43SVladimir Kondratiev return 0; 13789eb82d43SVladimir Kondratiev } 1379986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(freq); 13809eb82d43SVladimir Kondratiev 13819eb82d43SVladimir Kondratiev /*---------link------------*/ 1382986b8348SYangtao Li static int link_show(struct seq_file *s, void *data) 13839eb82d43SVladimir Kondratiev { 13849eb82d43SVladimir Kondratiev struct wil6210_priv *wil = s->private; 138541bd3d58SToke Høiland-Jørgensen struct station_info *sinfo; 138641bd3d58SToke Høiland-Jørgensen int i, rc = 0; 138741bd3d58SToke Høiland-Jørgensen 138841bd3d58SToke Høiland-Jørgensen sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL); 138941bd3d58SToke Høiland-Jørgensen if (!sinfo) 139041bd3d58SToke Høiland-Jørgensen return -ENOMEM; 13919eb82d43SVladimir Kondratiev 1392ddf7afddSAhmad Masri for (i = 0; i < wil->max_assoc_sta; i++) { 13939eb82d43SVladimir Kondratiev struct wil_sta_info *p = &wil->sta[i]; 13949eb82d43SVladimir Kondratiev char *status = "unknown"; 13955bd60982SLior David struct wil6210_vif *vif; 13965bd60982SLior David u8 mid; 13978fe59627SVladimir Kondratiev 13989eb82d43SVladimir Kondratiev switch (p->status) { 13999eb82d43SVladimir Kondratiev case wil_sta_unused: 14009eb82d43SVladimir Kondratiev status = "unused "; 14019eb82d43SVladimir Kondratiev break; 14029eb82d43SVladimir Kondratiev case wil_sta_conn_pending: 14039eb82d43SVladimir Kondratiev status = "pending "; 14049eb82d43SVladimir Kondratiev break; 14059eb82d43SVladimir Kondratiev case wil_sta_connected: 14069eb82d43SVladimir Kondratiev status = "connected"; 14079eb82d43SVladimir Kondratiev break; 14089eb82d43SVladimir Kondratiev } 14095bd60982SLior David mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX; 14105bd60982SLior David seq_printf(s, "[%d][MID %d] %pM %s\n", 14115bd60982SLior David i, mid, p->addr, status); 14129eb82d43SVladimir Kondratiev 14135bd60982SLior David if (p->status != wil_sta_connected) 14145bd60982SLior David continue; 14155bd60982SLior David 1416e4a29bddSAhmad Masri vif = (mid < GET_MAX_VIFS(wil)) ? wil->vifs[mid] : NULL; 14175bd60982SLior David if (vif) { 141841bd3d58SToke Høiland-Jørgensen rc = wil_cid_fill_sinfo(vif, i, sinfo); 14199eb82d43SVladimir Kondratiev if (rc) 142041bd3d58SToke Høiland-Jørgensen goto out; 14219eb82d43SVladimir Kondratiev 142241bd3d58SToke Høiland-Jørgensen seq_printf(s, " Tx_mcs = %d\n", sinfo->txrate.mcs); 142341bd3d58SToke Høiland-Jørgensen seq_printf(s, " Rx_mcs = %d\n", sinfo->rxrate.mcs); 142441bd3d58SToke Høiland-Jørgensen seq_printf(s, " SQ = %d\n", sinfo->signal); 14255bd60982SLior David } else { 14265bd60982SLior David seq_puts(s, " INVALID MID\n"); 14279eb82d43SVladimir Kondratiev } 14289eb82d43SVladimir Kondratiev } 14299eb82d43SVladimir Kondratiev 143041bd3d58SToke Høiland-Jørgensen out: 143141bd3d58SToke Høiland-Jørgensen kfree(sinfo); 143241bd3d58SToke Høiland-Jørgensen return rc; 14339eb82d43SVladimir Kondratiev } 1434986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(link); 14359eb82d43SVladimir Kondratiev 143684bb29b7SVladimir Kondratiev /*---------info------------*/ 1437986b8348SYangtao Li static int info_show(struct seq_file *s, void *data) 143884bb29b7SVladimir Kondratiev { 1439be299858SVladimir Kondratiev struct wil6210_priv *wil = s->private; 1440e00243faSLior David struct net_device *ndev = wil->main_ndev; 144184bb29b7SVladimir Kondratiev int is_ac = power_supply_is_system_supplied(); 1442be299858SVladimir Kondratiev int rx = atomic_xchg(&wil->isr_count_rx, 0); 1443be299858SVladimir Kondratiev int tx = atomic_xchg(&wil->isr_count_tx, 0); 1444be299858SVladimir Kondratiev static ulong rxf_old, txf_old; 1445be299858SVladimir Kondratiev ulong rxf = ndev->stats.rx_packets; 1446be299858SVladimir Kondratiev ulong txf = ndev->stats.tx_packets; 144755f8f680SVladimir Kondratiev unsigned int i; 144884bb29b7SVladimir Kondratiev 144984bb29b7SVladimir Kondratiev /* >0 : AC; 0 : battery; <0 : error */ 145084bb29b7SVladimir Kondratiev seq_printf(s, "AC powered : %d\n", is_ac); 1451be299858SVladimir Kondratiev seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old); 1452be299858SVladimir Kondratiev seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old); 1453be299858SVladimir Kondratiev rxf_old = rxf; 1454be299858SVladimir Kondratiev txf_old = txf; 145584bb29b7SVladimir Kondratiev 145655f8f680SVladimir Kondratiev #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \ 145755f8f680SVladimir Kondratiev " " __stringify(x) : "" 145855f8f680SVladimir Kondratiev 145955f8f680SVladimir Kondratiev for (i = 0; i < ndev->num_tx_queues; i++) { 146055f8f680SVladimir Kondratiev struct netdev_queue *txq = netdev_get_tx_queue(ndev, i); 146155f8f680SVladimir Kondratiev unsigned long state = txq->state; 146255f8f680SVladimir Kondratiev 146355f8f680SVladimir Kondratiev seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state, 146455f8f680SVladimir Kondratiev CHECK_QSTATE(DRV_XOFF), 146555f8f680SVladimir Kondratiev CHECK_QSTATE(STACK_XOFF), 146655f8f680SVladimir Kondratiev CHECK_QSTATE(FROZEN) 146755f8f680SVladimir Kondratiev ); 146855f8f680SVladimir Kondratiev } 146955f8f680SVladimir Kondratiev #undef CHECK_QSTATE 147084bb29b7SVladimir Kondratiev return 0; 147184bb29b7SVladimir Kondratiev } 1472986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(info); 147384bb29b7SVladimir Kondratiev 1474c33407a8SVladimir Kondratiev /*---------recovery------------*/ 1475c33407a8SVladimir Kondratiev /* mode = [manual|auto] 1476c33407a8SVladimir Kondratiev * state = [idle|pending|running] 1477c33407a8SVladimir Kondratiev */ 1478c33407a8SVladimir Kondratiev static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf, 1479c33407a8SVladimir Kondratiev size_t count, loff_t *ppos) 1480c33407a8SVladimir Kondratiev { 1481c33407a8SVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 1482c33407a8SVladimir Kondratiev char buf[80]; 1483c33407a8SVladimir Kondratiev int n; 1484c33407a8SVladimir Kondratiev static const char * const sstate[] = {"idle", "pending", "running"}; 1485c33407a8SVladimir Kondratiev 1486c33407a8SVladimir Kondratiev n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n", 1487c33407a8SVladimir Kondratiev no_fw_recovery ? "manual" : "auto", 1488c33407a8SVladimir Kondratiev sstate[wil->recovery_state]); 1489c33407a8SVladimir Kondratiev 1490c33407a8SVladimir Kondratiev n = min_t(int, n, sizeof(buf)); 1491c33407a8SVladimir Kondratiev 1492c33407a8SVladimir Kondratiev return simple_read_from_buffer(user_buf, count, ppos, 1493c33407a8SVladimir Kondratiev buf, n); 1494c33407a8SVladimir Kondratiev } 1495c33407a8SVladimir Kondratiev 1496c33407a8SVladimir Kondratiev static ssize_t wil_write_file_recovery(struct file *file, 1497c33407a8SVladimir Kondratiev const char __user *buf_, 1498c33407a8SVladimir Kondratiev size_t count, loff_t *ppos) 1499c33407a8SVladimir Kondratiev { 1500c33407a8SVladimir Kondratiev struct wil6210_priv *wil = file->private_data; 1501c33407a8SVladimir Kondratiev static const char run_command[] = "run"; 1502c33407a8SVladimir Kondratiev char buf[sizeof(run_command) + 1]; /* to detect "runx" */ 1503c33407a8SVladimir Kondratiev ssize_t rc; 1504c33407a8SVladimir Kondratiev 1505c33407a8SVladimir Kondratiev if (wil->recovery_state != fw_recovery_pending) { 1506c33407a8SVladimir Kondratiev wil_err(wil, "No recovery pending\n"); 1507c33407a8SVladimir Kondratiev return -EINVAL; 1508c33407a8SVladimir Kondratiev } 1509c33407a8SVladimir Kondratiev 1510c33407a8SVladimir Kondratiev if (*ppos != 0) { 1511c33407a8SVladimir Kondratiev wil_err(wil, "Offset [%d]\n", (int)*ppos); 1512c33407a8SVladimir Kondratiev return -EINVAL; 1513c33407a8SVladimir Kondratiev } 1514c33407a8SVladimir Kondratiev 1515c33407a8SVladimir Kondratiev if (count > sizeof(buf)) { 1516c33407a8SVladimir Kondratiev wil_err(wil, "Input too long, len = %d\n", (int)count); 1517c33407a8SVladimir Kondratiev return -EINVAL; 1518c33407a8SVladimir Kondratiev } 1519c33407a8SVladimir Kondratiev 1520c33407a8SVladimir Kondratiev rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count); 1521c33407a8SVladimir Kondratiev if (rc < 0) 1522c33407a8SVladimir Kondratiev return rc; 1523c33407a8SVladimir Kondratiev 1524c33407a8SVladimir Kondratiev buf[rc] = '\0'; 1525c33407a8SVladimir Kondratiev if (0 == strcmp(buf, run_command)) 1526c33407a8SVladimir Kondratiev wil_set_recovery_state(wil, fw_recovery_running); 1527c33407a8SVladimir Kondratiev else 1528c33407a8SVladimir Kondratiev wil_err(wil, "Bad recovery command \"%s\"\n", buf); 1529c33407a8SVladimir Kondratiev 1530c33407a8SVladimir Kondratiev return rc; 1531c33407a8SVladimir Kondratiev } 1532c33407a8SVladimir Kondratiev 1533c33407a8SVladimir Kondratiev static const struct file_operations fops_recovery = { 1534c33407a8SVladimir Kondratiev .read = wil_read_file_recovery, 1535c33407a8SVladimir Kondratiev .write = wil_write_file_recovery, 1536c33407a8SVladimir Kondratiev .open = simple_open, 1537c33407a8SVladimir Kondratiev }; 1538c33407a8SVladimir Kondratiev 15393df2cd36SVladimir Kondratiev /*---------Station matrix------------*/ 1540b4490f42SVladimir Kondratiev static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r) 1541b4490f42SVladimir Kondratiev { 1542b4490f42SVladimir Kondratiev int i; 1543b4490f42SVladimir Kondratiev u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size; 154491a8edccSVladimir Kondratiev unsigned long long drop_dup = r->drop_dup, drop_old = r->drop_old; 15451bd82ee0SDedy Lansky unsigned long long drop_dup_mcast = r->drop_dup_mcast; 15468fe59627SVladimir Kondratiev 154737f8d26dSDedy Lansky seq_printf(s, "([%2d]) 0x%03x [", r->buf_size, r->head_seq_num); 1548b4490f42SVladimir Kondratiev for (i = 0; i < r->buf_size; i++) { 1549b4490f42SVladimir Kondratiev if (i == index) 1550b4490f42SVladimir Kondratiev seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|'); 1551b4490f42SVladimir Kondratiev else 1552b4490f42SVladimir Kondratiev seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_'); 1553b4490f42SVladimir Kondratiev } 155491a8edccSVladimir Kondratiev seq_printf(s, 15551bd82ee0SDedy Lansky "] total %llu drop %llu (dup %llu + old %llu + dup mcast %llu) last 0x%03x\n", 15561bd82ee0SDedy Lansky r->total, drop_dup + drop_old + drop_dup_mcast, drop_dup, 15571bd82ee0SDedy Lansky drop_old, drop_dup_mcast, r->ssn_last_drop); 1558b4490f42SVladimir Kondratiev } 15593df2cd36SVladimir Kondratiev 156058527421SVladimir Kondratiev static void wil_print_rxtid_crypto(struct seq_file *s, int tid, 156158527421SVladimir Kondratiev struct wil_tid_crypto_rx *c) 156258527421SVladimir Kondratiev { 156358527421SVladimir Kondratiev int i; 156458527421SVladimir Kondratiev 156558527421SVladimir Kondratiev for (i = 0; i < 4; i++) { 156658527421SVladimir Kondratiev struct wil_tid_crypto_rx_single *cc = &c->key_id[i]; 156758527421SVladimir Kondratiev 156858527421SVladimir Kondratiev if (cc->key_set) 156958527421SVladimir Kondratiev goto has_keys; 157058527421SVladimir Kondratiev } 157158527421SVladimir Kondratiev return; 157258527421SVladimir Kondratiev 157358527421SVladimir Kondratiev has_keys: 157458527421SVladimir Kondratiev if (tid < WIL_STA_TID_NUM) 157558527421SVladimir Kondratiev seq_printf(s, " [%2d] PN", tid); 157658527421SVladimir Kondratiev else 157758527421SVladimir Kondratiev seq_puts(s, " [GR] PN"); 157858527421SVladimir Kondratiev 157958527421SVladimir Kondratiev for (i = 0; i < 4; i++) { 158058527421SVladimir Kondratiev struct wil_tid_crypto_rx_single *cc = &c->key_id[i]; 158158527421SVladimir Kondratiev 158258527421SVladimir Kondratiev seq_printf(s, " [%i%s]%6phN", i, cc->key_set ? "+" : "-", 158358527421SVladimir Kondratiev cc->pn); 158458527421SVladimir Kondratiev } 158558527421SVladimir Kondratiev seq_puts(s, "\n"); 158658527421SVladimir Kondratiev } 158758527421SVladimir Kondratiev 1588986b8348SYangtao Li static int sta_show(struct seq_file *s, void *data) 1589bd33273bSVladimir Kondratiev __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock) 15903df2cd36SVladimir Kondratiev { 15913df2cd36SVladimir Kondratiev struct wil6210_priv *wil = s->private; 1592c4a110d8SVladimir Kondratiev int i, tid, mcs; 15933df2cd36SVladimir Kondratiev 1594ddf7afddSAhmad Masri for (i = 0; i < wil->max_assoc_sta; i++) { 15953df2cd36SVladimir Kondratiev struct wil_sta_info *p = &wil->sta[i]; 15963df2cd36SVladimir Kondratiev char *status = "unknown"; 15979d865ee2SLior David u8 aid = 0; 15985bd60982SLior David u8 mid; 1599b9010f10SAhmad Masri bool sta_connected = false; 16008fe59627SVladimir Kondratiev 16013df2cd36SVladimir Kondratiev switch (p->status) { 16023df2cd36SVladimir Kondratiev case wil_sta_unused: 16033df2cd36SVladimir Kondratiev status = "unused "; 16043df2cd36SVladimir Kondratiev break; 16053df2cd36SVladimir Kondratiev case wil_sta_conn_pending: 16063df2cd36SVladimir Kondratiev status = "pending "; 16073df2cd36SVladimir Kondratiev break; 16083df2cd36SVladimir Kondratiev case wil_sta_connected: 16093df2cd36SVladimir Kondratiev status = "connected"; 16109d865ee2SLior David aid = p->aid; 16113df2cd36SVladimir Kondratiev break; 16123df2cd36SVladimir Kondratiev } 16135bd60982SLior David mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX; 1614e4a29bddSAhmad Masri if (mid < GET_MAX_VIFS(wil)) { 1615b9010f10SAhmad Masri struct wil6210_vif *vif = wil->vifs[mid]; 1616b9010f10SAhmad Masri 1617b9010f10SAhmad Masri if (vif->wdev.iftype == NL80211_IFTYPE_STATION && 1618b9010f10SAhmad Masri p->status == wil_sta_connected) 1619b9010f10SAhmad Masri sta_connected = true; 1620b9010f10SAhmad Masri } 1621b9010f10SAhmad Masri /* print roam counter only for connected stations */ 1622b9010f10SAhmad Masri if (sta_connected) 1623b9010f10SAhmad Masri seq_printf(s, "[%d] %pM connected (roam counter %d) MID %d AID %d\n", 1624b9010f10SAhmad Masri i, p->addr, p->stats.ft_roams, mid, aid); 1625b9010f10SAhmad Masri else 1626b9010f10SAhmad Masri seq_printf(s, "[%d] %pM %s MID %d AID %d\n", i, 1627b9010f10SAhmad Masri p->addr, status, mid, aid); 1628b4490f42SVladimir Kondratiev 1629b4490f42SVladimir Kondratiev if (p->status == wil_sta_connected) { 1630bd33273bSVladimir Kondratiev spin_lock_bh(&p->tid_rx_lock); 1631b4490f42SVladimir Kondratiev for (tid = 0; tid < WIL_STA_TID_NUM; tid++) { 1632b4490f42SVladimir Kondratiev struct wil_tid_ampdu_rx *r = p->tid_rx[tid]; 163358527421SVladimir Kondratiev struct wil_tid_crypto_rx *c = 163458527421SVladimir Kondratiev &p->tid_crypto_rx[tid]; 16358fe59627SVladimir Kondratiev 1636b4490f42SVladimir Kondratiev if (r) { 1637b4490f42SVladimir Kondratiev seq_printf(s, " [%2d] ", tid); 1638b4490f42SVladimir Kondratiev wil_print_rxtid(s, r); 1639b4490f42SVladimir Kondratiev } 164058527421SVladimir Kondratiev 164158527421SVladimir Kondratiev wil_print_rxtid_crypto(s, tid, c); 1642b4490f42SVladimir Kondratiev } 164358527421SVladimir Kondratiev wil_print_rxtid_crypto(s, WIL_STA_TID_NUM, 164458527421SVladimir Kondratiev &p->group_crypto_rx); 1645bd33273bSVladimir Kondratiev spin_unlock_bh(&p->tid_rx_lock); 16463b282bc6SVladimir Kondratiev seq_printf(s, 164758527421SVladimir Kondratiev "Rx invalid frame: non-data %lu, short %lu, large %lu, replay %lu\n", 16483b282bc6SVladimir Kondratiev p->stats.rx_non_data_frame, 16493b282bc6SVladimir Kondratiev p->stats.rx_short_frame, 165058527421SVladimir Kondratiev p->stats.rx_large_frame, 165158527421SVladimir Kondratiev p->stats.rx_replay); 1652d98b8539SMaya Erez seq_printf(s, 16530b853210SMaya Erez "mic error %lu, key error %lu, amsdu error %lu, csum error %lu\n", 1654d98b8539SMaya Erez p->stats.rx_mic_error, 1655d98b8539SMaya Erez p->stats.rx_key_error, 16560b853210SMaya Erez p->stats.rx_amsdu_error, 16570b853210SMaya Erez p->stats.rx_csum_err); 1658d98b8539SMaya Erez 1659c4a110d8SVladimir Kondratiev seq_puts(s, "Rx/MCS:"); 1660c4a110d8SVladimir Kondratiev for (mcs = 0; mcs < ARRAY_SIZE(p->stats.rx_per_mcs); 1661c4a110d8SVladimir Kondratiev mcs++) 1662c4a110d8SVladimir Kondratiev seq_printf(s, " %lld", 1663c4a110d8SVladimir Kondratiev p->stats.rx_per_mcs[mcs]); 1664c4a110d8SVladimir Kondratiev seq_puts(s, "\n"); 1665b4490f42SVladimir Kondratiev } 16663df2cd36SVladimir Kondratiev } 16673df2cd36SVladimir Kondratiev 16683df2cd36SVladimir Kondratiev return 0; 16693df2cd36SVladimir Kondratiev } 1670986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(sta); 16713df2cd36SVladimir Kondratiev 1672986b8348SYangtao Li static int mids_show(struct seq_file *s, void *data) 16733a3b745fSLior David { 16743a3b745fSLior David struct wil6210_priv *wil = s->private; 16753a3b745fSLior David struct wil6210_vif *vif; 16763a3b745fSLior David struct net_device *ndev; 16773a3b745fSLior David int i; 16783a3b745fSLior David 16793a3b745fSLior David mutex_lock(&wil->vif_mutex); 1680e4a29bddSAhmad Masri for (i = 0; i < GET_MAX_VIFS(wil); i++) { 16813a3b745fSLior David vif = wil->vifs[i]; 16823a3b745fSLior David 16833a3b745fSLior David if (vif) { 16843a3b745fSLior David ndev = vif_to_ndev(vif); 16853a3b745fSLior David seq_printf(s, "[%d] %pM %s\n", i, ndev->dev_addr, 16863a3b745fSLior David ndev->name); 16873a3b745fSLior David } else { 16883a3b745fSLior David seq_printf(s, "[%d] unused\n", i); 16893a3b745fSLior David } 16903a3b745fSLior David } 16913a3b745fSLior David mutex_unlock(&wil->vif_mutex); 16923a3b745fSLior David 16933a3b745fSLior David return 0; 16943a3b745fSLior David } 1695986b8348SYangtao Li DEFINE_SHOW_ATTRIBUTE(mids); 16963a3b745fSLior David 1697a24a3d6aSDedy Lansky static int wil_tx_latency_debugfs_show(struct seq_file *s, void *data) 1698a24a3d6aSDedy Lansky __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock) 1699a24a3d6aSDedy Lansky { 1700a24a3d6aSDedy Lansky struct wil6210_priv *wil = s->private; 1701a24a3d6aSDedy Lansky int i, bin; 1702a24a3d6aSDedy Lansky 1703ddf7afddSAhmad Masri for (i = 0; i < wil->max_assoc_sta; i++) { 1704a24a3d6aSDedy Lansky struct wil_sta_info *p = &wil->sta[i]; 1705a24a3d6aSDedy Lansky char *status = "unknown"; 1706a24a3d6aSDedy Lansky u8 aid = 0; 1707a24a3d6aSDedy Lansky u8 mid; 1708a24a3d6aSDedy Lansky 1709a24a3d6aSDedy Lansky if (!p->tx_latency_bins) 1710a24a3d6aSDedy Lansky continue; 1711a24a3d6aSDedy Lansky 1712a24a3d6aSDedy Lansky switch (p->status) { 1713a24a3d6aSDedy Lansky case wil_sta_unused: 1714a24a3d6aSDedy Lansky status = "unused "; 1715a24a3d6aSDedy Lansky break; 1716a24a3d6aSDedy Lansky case wil_sta_conn_pending: 1717a24a3d6aSDedy Lansky status = "pending "; 1718a24a3d6aSDedy Lansky break; 1719a24a3d6aSDedy Lansky case wil_sta_connected: 1720a24a3d6aSDedy Lansky status = "connected"; 1721a24a3d6aSDedy Lansky aid = p->aid; 1722a24a3d6aSDedy Lansky break; 1723a24a3d6aSDedy Lansky } 1724a24a3d6aSDedy Lansky mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX; 1725a24a3d6aSDedy Lansky seq_printf(s, "[%d] %pM %s MID %d AID %d\n", i, p->addr, status, 1726a24a3d6aSDedy Lansky mid, aid); 1727a24a3d6aSDedy Lansky 1728a24a3d6aSDedy Lansky if (p->status == wil_sta_connected) { 1729a24a3d6aSDedy Lansky u64 num_packets = 0; 1730a24a3d6aSDedy Lansky u64 tx_latency_avg = p->stats.tx_latency_total_us; 1731a24a3d6aSDedy Lansky 1732a24a3d6aSDedy Lansky seq_puts(s, "Tx/Latency bin:"); 1733a24a3d6aSDedy Lansky for (bin = 0; bin < WIL_NUM_LATENCY_BINS; bin++) { 1734a24a3d6aSDedy Lansky seq_printf(s, " %lld", 1735a24a3d6aSDedy Lansky p->tx_latency_bins[bin]); 1736a24a3d6aSDedy Lansky num_packets += p->tx_latency_bins[bin]; 1737a24a3d6aSDedy Lansky } 1738a24a3d6aSDedy Lansky seq_puts(s, "\n"); 1739a24a3d6aSDedy Lansky if (!num_packets) 1740a24a3d6aSDedy Lansky continue; 1741a24a3d6aSDedy Lansky do_div(tx_latency_avg, num_packets); 1742a24a3d6aSDedy Lansky seq_printf(s, "Tx/Latency min/avg/max (us): %d/%lld/%d", 1743a24a3d6aSDedy Lansky p->stats.tx_latency_min_us, 1744a24a3d6aSDedy Lansky tx_latency_avg, 1745a24a3d6aSDedy Lansky p->stats.tx_latency_max_us); 1746a24a3d6aSDedy Lansky 1747a24a3d6aSDedy Lansky seq_puts(s, "\n"); 1748a24a3d6aSDedy Lansky } 1749a24a3d6aSDedy Lansky } 1750a24a3d6aSDedy Lansky 1751a24a3d6aSDedy Lansky return 0; 1752a24a3d6aSDedy Lansky } 1753a24a3d6aSDedy Lansky 1754a24a3d6aSDedy Lansky static int wil_tx_latency_seq_open(struct inode *inode, struct file *file) 1755a24a3d6aSDedy Lansky { 1756a24a3d6aSDedy Lansky return single_open(file, wil_tx_latency_debugfs_show, 1757a24a3d6aSDedy Lansky inode->i_private); 1758a24a3d6aSDedy Lansky } 1759a24a3d6aSDedy Lansky 1760a24a3d6aSDedy Lansky static ssize_t wil_tx_latency_write(struct file *file, const char __user *buf, 1761a24a3d6aSDedy Lansky size_t len, loff_t *ppos) 1762a24a3d6aSDedy Lansky { 1763a24a3d6aSDedy Lansky struct seq_file *s = file->private_data; 1764a24a3d6aSDedy Lansky struct wil6210_priv *wil = s->private; 1765a24a3d6aSDedy Lansky int val, rc, i; 1766a24a3d6aSDedy Lansky bool enable; 1767a24a3d6aSDedy Lansky 1768a24a3d6aSDedy Lansky rc = kstrtoint_from_user(buf, len, 0, &val); 1769a24a3d6aSDedy Lansky if (rc) { 1770a24a3d6aSDedy Lansky wil_err(wil, "Invalid argument\n"); 1771a24a3d6aSDedy Lansky return rc; 1772a24a3d6aSDedy Lansky } 1773a24a3d6aSDedy Lansky if (val == 1) 1774a24a3d6aSDedy Lansky /* default resolution */ 1775a24a3d6aSDedy Lansky val = 500; 1776a24a3d6aSDedy Lansky if (val && (val < 50 || val > 1000)) { 1777a24a3d6aSDedy Lansky wil_err(wil, "Invalid resolution %d\n", val); 1778a24a3d6aSDedy Lansky return -EINVAL; 1779a24a3d6aSDedy Lansky } 1780a24a3d6aSDedy Lansky 1781a24a3d6aSDedy Lansky enable = !!val; 1782a24a3d6aSDedy Lansky if (wil->tx_latency == enable) 1783a24a3d6aSDedy Lansky return len; 1784a24a3d6aSDedy Lansky 1785a24a3d6aSDedy Lansky wil_info(wil, "%s TX latency measurements (resolution %dusec)\n", 1786a24a3d6aSDedy Lansky enable ? "Enabling" : "Disabling", val); 1787a24a3d6aSDedy Lansky 1788a24a3d6aSDedy Lansky if (enable) { 1789a24a3d6aSDedy Lansky size_t sz = sizeof(u64) * WIL_NUM_LATENCY_BINS; 1790a24a3d6aSDedy Lansky 1791a24a3d6aSDedy Lansky wil->tx_latency_res = val; 1792ddf7afddSAhmad Masri for (i = 0; i < wil->max_assoc_sta; i++) { 1793a24a3d6aSDedy Lansky struct wil_sta_info *sta = &wil->sta[i]; 1794a24a3d6aSDedy Lansky 1795a24a3d6aSDedy Lansky kfree(sta->tx_latency_bins); 1796a24a3d6aSDedy Lansky sta->tx_latency_bins = kzalloc(sz, GFP_KERNEL); 1797a24a3d6aSDedy Lansky if (!sta->tx_latency_bins) 1798a24a3d6aSDedy Lansky return -ENOMEM; 1799a24a3d6aSDedy Lansky sta->stats.tx_latency_min_us = U32_MAX; 1800a24a3d6aSDedy Lansky sta->stats.tx_latency_max_us = 0; 1801a24a3d6aSDedy Lansky sta->stats.tx_latency_total_us = 0; 1802a24a3d6aSDedy Lansky } 1803a24a3d6aSDedy Lansky } 1804a24a3d6aSDedy Lansky wil->tx_latency = enable; 1805a24a3d6aSDedy Lansky 1806a24a3d6aSDedy Lansky return len; 1807a24a3d6aSDedy Lansky } 1808a24a3d6aSDedy Lansky 1809a24a3d6aSDedy Lansky static const struct file_operations fops_tx_latency = { 1810a24a3d6aSDedy Lansky .open = wil_tx_latency_seq_open, 1811a24a3d6aSDedy Lansky .release = single_release, 1812a24a3d6aSDedy Lansky .read = seq_read, 1813a24a3d6aSDedy Lansky .write = wil_tx_latency_write, 1814a24a3d6aSDedy Lansky .llseek = seq_lseek, 1815a24a3d6aSDedy Lansky }; 1816a24a3d6aSDedy Lansky 18170c936b3cSDedy Lansky static void wil_link_stats_print_basic(struct wil6210_vif *vif, 18180c936b3cSDedy Lansky struct seq_file *s, 18190c936b3cSDedy Lansky struct wmi_link_stats_basic *basic) 18200c936b3cSDedy Lansky { 18210c936b3cSDedy Lansky char per[5] = "?"; 18220c936b3cSDedy Lansky 18230c936b3cSDedy Lansky if (basic->per_average != 0xff) 18240c936b3cSDedy Lansky snprintf(per, sizeof(per), "%d%%", basic->per_average); 18250c936b3cSDedy Lansky 18260c936b3cSDedy Lansky seq_printf(s, "CID %d {\n" 18270c936b3cSDedy Lansky "\tTxMCS %d TxTpt %d\n" 18280c936b3cSDedy Lansky "\tGoodput(rx:tx) %d:%d\n" 18290c936b3cSDedy Lansky "\tRxBcastFrames %d\n" 18300c936b3cSDedy Lansky "\tRSSI %d SQI %d SNR %d PER %s\n" 18310c936b3cSDedy Lansky "\tRx RFC %d Ant num %d\n" 18320c936b3cSDedy Lansky "\tSectors(rx:tx) my %d:%d peer %d:%d\n" 18330c936b3cSDedy Lansky "}\n", 18340c936b3cSDedy Lansky basic->cid, 18350c936b3cSDedy Lansky basic->bf_mcs, le32_to_cpu(basic->tx_tpt), 18360c936b3cSDedy Lansky le32_to_cpu(basic->rx_goodput), 18370c936b3cSDedy Lansky le32_to_cpu(basic->tx_goodput), 18380c936b3cSDedy Lansky le32_to_cpu(basic->rx_bcast_frames), 18390c936b3cSDedy Lansky basic->rssi, basic->sqi, basic->snr, per, 18400c936b3cSDedy Lansky basic->selected_rfc, basic->rx_effective_ant_num, 18410c936b3cSDedy Lansky basic->my_rx_sector, basic->my_tx_sector, 18420c936b3cSDedy Lansky basic->other_rx_sector, basic->other_tx_sector); 18430c936b3cSDedy Lansky } 18440c936b3cSDedy Lansky 18450c936b3cSDedy Lansky static void wil_link_stats_print_global(struct wil6210_priv *wil, 18460c936b3cSDedy Lansky struct seq_file *s, 18470c936b3cSDedy Lansky struct wmi_link_stats_global *global) 18480c936b3cSDedy Lansky { 18490c936b3cSDedy Lansky seq_printf(s, "Frames(rx:tx) %d:%d\n" 18500c936b3cSDedy Lansky "BA Frames(rx:tx) %d:%d\n" 18510c936b3cSDedy Lansky "Beacons %d\n" 18520c936b3cSDedy Lansky "Rx Errors (MIC:CRC) %d:%d\n" 18530c936b3cSDedy Lansky "Tx Errors (no ack) %d\n", 18540c936b3cSDedy Lansky le32_to_cpu(global->rx_frames), 18550c936b3cSDedy Lansky le32_to_cpu(global->tx_frames), 18560c936b3cSDedy Lansky le32_to_cpu(global->rx_ba_frames), 18570c936b3cSDedy Lansky le32_to_cpu(global->tx_ba_frames), 18580c936b3cSDedy Lansky le32_to_cpu(global->tx_beacons), 18590c936b3cSDedy Lansky le32_to_cpu(global->rx_mic_errors), 18600c936b3cSDedy Lansky le32_to_cpu(global->rx_crc_errors), 18610c936b3cSDedy Lansky le32_to_cpu(global->tx_fail_no_ack)); 18620c936b3cSDedy Lansky } 18630c936b3cSDedy Lansky 18640c936b3cSDedy Lansky static void wil_link_stats_debugfs_show_vif(struct wil6210_vif *vif, 18650c936b3cSDedy Lansky struct seq_file *s) 18660c936b3cSDedy Lansky { 18670c936b3cSDedy Lansky struct wil6210_priv *wil = vif_to_wil(vif); 18680c936b3cSDedy Lansky struct wmi_link_stats_basic *stats; 18690c936b3cSDedy Lansky int i; 18700c936b3cSDedy Lansky 18710c936b3cSDedy Lansky if (!vif->fw_stats_ready) { 18720c936b3cSDedy Lansky seq_puts(s, "no statistics\n"); 18730c936b3cSDedy Lansky return; 18740c936b3cSDedy Lansky } 18750c936b3cSDedy Lansky 18760c936b3cSDedy Lansky seq_printf(s, "TSF %lld\n", vif->fw_stats_tsf); 1877ddf7afddSAhmad Masri for (i = 0; i < wil->max_assoc_sta; i++) { 18780c936b3cSDedy Lansky if (wil->sta[i].status == wil_sta_unused) 18790c936b3cSDedy Lansky continue; 18800c936b3cSDedy Lansky if (wil->sta[i].mid != vif->mid) 18810c936b3cSDedy Lansky continue; 18820c936b3cSDedy Lansky 18830c936b3cSDedy Lansky stats = &wil->sta[i].fw_stats_basic; 18840c936b3cSDedy Lansky wil_link_stats_print_basic(vif, s, stats); 18850c936b3cSDedy Lansky } 18860c936b3cSDedy Lansky } 18870c936b3cSDedy Lansky 18880c936b3cSDedy Lansky static int wil_link_stats_debugfs_show(struct seq_file *s, void *data) 18890c936b3cSDedy Lansky { 18900c936b3cSDedy Lansky struct wil6210_priv *wil = s->private; 18910c936b3cSDedy Lansky struct wil6210_vif *vif; 18920c936b3cSDedy Lansky int i, rc; 18930c936b3cSDedy Lansky 18940c936b3cSDedy Lansky rc = mutex_lock_interruptible(&wil->vif_mutex); 18950c936b3cSDedy Lansky if (rc) 18960c936b3cSDedy Lansky return rc; 18970c936b3cSDedy Lansky 18980c936b3cSDedy Lansky /* iterate over all MIDs and show per-cid statistics. Then show the 18990c936b3cSDedy Lansky * global statistics 19000c936b3cSDedy Lansky */ 1901e4a29bddSAhmad Masri for (i = 0; i < GET_MAX_VIFS(wil); i++) { 19020c936b3cSDedy Lansky vif = wil->vifs[i]; 19030c936b3cSDedy Lansky 19040c936b3cSDedy Lansky seq_printf(s, "MID %d ", i); 19050c936b3cSDedy Lansky if (!vif) { 19060c936b3cSDedy Lansky seq_puts(s, "unused\n"); 19070c936b3cSDedy Lansky continue; 19080c936b3cSDedy Lansky } 19090c936b3cSDedy Lansky 19100c936b3cSDedy Lansky wil_link_stats_debugfs_show_vif(vif, s); 19110c936b3cSDedy Lansky } 19120c936b3cSDedy Lansky 19130c936b3cSDedy Lansky mutex_unlock(&wil->vif_mutex); 19140c936b3cSDedy Lansky 19150c936b3cSDedy Lansky return 0; 19160c936b3cSDedy Lansky } 19170c936b3cSDedy Lansky 19180c936b3cSDedy Lansky static int wil_link_stats_seq_open(struct inode *inode, struct file *file) 19190c936b3cSDedy Lansky { 19200c936b3cSDedy Lansky return single_open(file, wil_link_stats_debugfs_show, inode->i_private); 19210c936b3cSDedy Lansky } 19220c936b3cSDedy Lansky 19230c936b3cSDedy Lansky static ssize_t wil_link_stats_write(struct file *file, const char __user *buf, 19240c936b3cSDedy Lansky size_t len, loff_t *ppos) 19250c936b3cSDedy Lansky { 19260c936b3cSDedy Lansky struct seq_file *s = file->private_data; 19270c936b3cSDedy Lansky struct wil6210_priv *wil = s->private; 19280c936b3cSDedy Lansky int cid, interval, rc, i; 19290c936b3cSDedy Lansky struct wil6210_vif *vif; 19300c936b3cSDedy Lansky char *kbuf = kmalloc(len + 1, GFP_KERNEL); 19310c936b3cSDedy Lansky 19320c936b3cSDedy Lansky if (!kbuf) 19330c936b3cSDedy Lansky return -ENOMEM; 19340c936b3cSDedy Lansky 19350c936b3cSDedy Lansky rc = simple_write_to_buffer(kbuf, len, ppos, buf, len); 19360c936b3cSDedy Lansky if (rc != len) { 19370c936b3cSDedy Lansky kfree(kbuf); 19380c936b3cSDedy Lansky return rc >= 0 ? -EIO : rc; 19390c936b3cSDedy Lansky } 19400c936b3cSDedy Lansky 19410c936b3cSDedy Lansky kbuf[len] = '\0'; 19420c936b3cSDedy Lansky /* specify cid (use -1 for all cids) and snapshot interval in ms */ 19430c936b3cSDedy Lansky rc = sscanf(kbuf, "%d %d", &cid, &interval); 19440c936b3cSDedy Lansky kfree(kbuf); 19450c936b3cSDedy Lansky if (rc < 0) 19460c936b3cSDedy Lansky return rc; 19470c936b3cSDedy Lansky if (rc < 2 || interval < 0) 19480c936b3cSDedy Lansky return -EINVAL; 19490c936b3cSDedy Lansky 19500c936b3cSDedy Lansky wil_info(wil, "request link statistics, cid %d interval %d\n", 19510c936b3cSDedy Lansky cid, interval); 19520c936b3cSDedy Lansky 19530c936b3cSDedy Lansky rc = mutex_lock_interruptible(&wil->vif_mutex); 19540c936b3cSDedy Lansky if (rc) 19550c936b3cSDedy Lansky return rc; 19560c936b3cSDedy Lansky 1957e4a29bddSAhmad Masri for (i = 0; i < GET_MAX_VIFS(wil); i++) { 19580c936b3cSDedy Lansky vif = wil->vifs[i]; 19590c936b3cSDedy Lansky if (!vif) 19600c936b3cSDedy Lansky continue; 19610c936b3cSDedy Lansky 19620c936b3cSDedy Lansky rc = wmi_link_stats_cfg(vif, WMI_LINK_STATS_TYPE_BASIC, 19630c936b3cSDedy Lansky (cid == -1 ? 0xff : cid), interval); 19640c936b3cSDedy Lansky if (rc) 19650c936b3cSDedy Lansky wil_err(wil, "link statistics failed for mid %d\n", i); 19660c936b3cSDedy Lansky } 19670c936b3cSDedy Lansky mutex_unlock(&wil->vif_mutex); 19680c936b3cSDedy Lansky 19690c936b3cSDedy Lansky return len; 19700c936b3cSDedy Lansky } 19710c936b3cSDedy Lansky 19720c936b3cSDedy Lansky static const struct file_operations fops_link_stats = { 19730c936b3cSDedy Lansky .open = wil_link_stats_seq_open, 19740c936b3cSDedy Lansky .release = single_release, 19750c936b3cSDedy Lansky .read = seq_read, 19760c936b3cSDedy Lansky .write = wil_link_stats_write, 19770c936b3cSDedy Lansky .llseek = seq_lseek, 19780c936b3cSDedy Lansky }; 19790c936b3cSDedy Lansky 19800c936b3cSDedy Lansky static int 19810c936b3cSDedy Lansky wil_link_stats_global_debugfs_show(struct seq_file *s, void *data) 19820c936b3cSDedy Lansky { 19830c936b3cSDedy Lansky struct wil6210_priv *wil = s->private; 19840c936b3cSDedy Lansky 19850c936b3cSDedy Lansky if (!wil->fw_stats_global.ready) 19860c936b3cSDedy Lansky return 0; 19870c936b3cSDedy Lansky 19880c936b3cSDedy Lansky seq_printf(s, "TSF %lld\n", wil->fw_stats_global.tsf); 19890c936b3cSDedy Lansky wil_link_stats_print_global(wil, s, &wil->fw_stats_global.stats); 19900c936b3cSDedy Lansky 19910c936b3cSDedy Lansky return 0; 19920c936b3cSDedy Lansky } 19930c936b3cSDedy Lansky 19940c936b3cSDedy Lansky static int 19950c936b3cSDedy Lansky wil_link_stats_global_seq_open(struct inode *inode, struct file *file) 19960c936b3cSDedy Lansky { 19970c936b3cSDedy Lansky return single_open(file, wil_link_stats_global_debugfs_show, 19980c936b3cSDedy Lansky inode->i_private); 19990c936b3cSDedy Lansky } 20000c936b3cSDedy Lansky 20010c936b3cSDedy Lansky static ssize_t 20020c936b3cSDedy Lansky wil_link_stats_global_write(struct file *file, const char __user *buf, 20030c936b3cSDedy Lansky size_t len, loff_t *ppos) 20040c936b3cSDedy Lansky { 20050c936b3cSDedy Lansky struct seq_file *s = file->private_data; 20060c936b3cSDedy Lansky struct wil6210_priv *wil = s->private; 20070c936b3cSDedy Lansky int interval, rc; 20080c936b3cSDedy Lansky struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev); 20090c936b3cSDedy Lansky 20100c936b3cSDedy Lansky /* specify snapshot interval in ms */ 20110c936b3cSDedy Lansky rc = kstrtoint_from_user(buf, len, 0, &interval); 20120c936b3cSDedy Lansky if (rc || interval < 0) { 20130c936b3cSDedy Lansky wil_err(wil, "Invalid argument\n"); 20140c936b3cSDedy Lansky return -EINVAL; 20150c936b3cSDedy Lansky } 20160c936b3cSDedy Lansky 20170c936b3cSDedy Lansky wil_info(wil, "request global link stats, interval %d\n", interval); 20180c936b3cSDedy Lansky 20190c936b3cSDedy Lansky rc = wmi_link_stats_cfg(vif, WMI_LINK_STATS_TYPE_GLOBAL, 0, interval); 20200c936b3cSDedy Lansky if (rc) 20210c936b3cSDedy Lansky wil_err(wil, "global link stats failed %d\n", rc); 20220c936b3cSDedy Lansky 20230c936b3cSDedy Lansky return rc ? rc : len; 20240c936b3cSDedy Lansky } 20250c936b3cSDedy Lansky 20260c936b3cSDedy Lansky static const struct file_operations fops_link_stats_global = { 20270c936b3cSDedy Lansky .open = wil_link_stats_global_seq_open, 20280c936b3cSDedy Lansky .release = single_release, 20290c936b3cSDedy Lansky .read = seq_read, 20300c936b3cSDedy Lansky .write = wil_link_stats_global_write, 20310c936b3cSDedy Lansky .llseek = seq_lseek, 20320c936b3cSDedy Lansky }; 20330c936b3cSDedy Lansky 203410d599adSMaya Erez static ssize_t wil_read_file_led_cfg(struct file *file, char __user *user_buf, 203510d599adSMaya Erez size_t count, loff_t *ppos) 203610d599adSMaya Erez { 203710d599adSMaya Erez char buf[80]; 203810d599adSMaya Erez int n; 203910d599adSMaya Erez 204010d599adSMaya Erez n = snprintf(buf, sizeof(buf), 204110d599adSMaya Erez "led_id is set to %d, echo 1 to enable, 0 to disable\n", 204210d599adSMaya Erez led_id); 204310d599adSMaya Erez 204410d599adSMaya Erez n = min_t(int, n, sizeof(buf)); 204510d599adSMaya Erez 204610d599adSMaya Erez return simple_read_from_buffer(user_buf, count, ppos, 204710d599adSMaya Erez buf, n); 204810d599adSMaya Erez } 204910d599adSMaya Erez 205010d599adSMaya Erez static ssize_t wil_write_file_led_cfg(struct file *file, 205110d599adSMaya Erez const char __user *buf_, 205210d599adSMaya Erez size_t count, loff_t *ppos) 205310d599adSMaya Erez { 205410d599adSMaya Erez struct wil6210_priv *wil = file->private_data; 205510d599adSMaya Erez int val; 205610d599adSMaya Erez int rc; 205710d599adSMaya Erez 205810d599adSMaya Erez rc = kstrtoint_from_user(buf_, count, 0, &val); 205910d599adSMaya Erez if (rc) { 206010d599adSMaya Erez wil_err(wil, "Invalid argument\n"); 206110d599adSMaya Erez return rc; 206210d599adSMaya Erez } 206310d599adSMaya Erez 206410d599adSMaya Erez wil_info(wil, "%s led %d\n", val ? "Enabling" : "Disabling", led_id); 206510d599adSMaya Erez rc = wmi_led_cfg(wil, val); 206610d599adSMaya Erez if (rc) { 206710d599adSMaya Erez wil_info(wil, "%s led %d failed\n", 206810d599adSMaya Erez val ? "Enabling" : "Disabling", led_id); 206910d599adSMaya Erez return rc; 207010d599adSMaya Erez } 207110d599adSMaya Erez 207210d599adSMaya Erez return count; 207310d599adSMaya Erez } 207410d599adSMaya Erez 207510d599adSMaya Erez static const struct file_operations fops_led_cfg = { 207610d599adSMaya Erez .read = wil_read_file_led_cfg, 207710d599adSMaya Erez .write = wil_write_file_led_cfg, 207810d599adSMaya Erez .open = simple_open, 207910d599adSMaya Erez }; 208010d599adSMaya Erez 208110d599adSMaya Erez /* led_blink_time, write: 208210d599adSMaya Erez * "<blink_on_slow> <blink_off_slow> <blink_on_med> <blink_off_med> <blink_on_fast> <blink_off_fast> 208310d599adSMaya Erez */ 208410d599adSMaya Erez static ssize_t wil_write_led_blink_time(struct file *file, 208510d599adSMaya Erez const char __user *buf, 208610d599adSMaya Erez size_t len, loff_t *ppos) 208710d599adSMaya Erez { 208810d599adSMaya Erez int rc; 208910d599adSMaya Erez char *kbuf = kmalloc(len + 1, GFP_KERNEL); 209010d599adSMaya Erez 209110d599adSMaya Erez if (!kbuf) 209210d599adSMaya Erez return -ENOMEM; 209310d599adSMaya Erez 209410d599adSMaya Erez rc = simple_write_to_buffer(kbuf, len, ppos, buf, len); 209510d599adSMaya Erez if (rc != len) { 209610d599adSMaya Erez kfree(kbuf); 209710d599adSMaya Erez return rc >= 0 ? -EIO : rc; 209810d599adSMaya Erez } 209910d599adSMaya Erez 210010d599adSMaya Erez kbuf[len] = '\0'; 210110d599adSMaya Erez rc = sscanf(kbuf, "%d %d %d %d %d %d", 210210d599adSMaya Erez &led_blink_time[WIL_LED_TIME_SLOW].on_ms, 210310d599adSMaya Erez &led_blink_time[WIL_LED_TIME_SLOW].off_ms, 210410d599adSMaya Erez &led_blink_time[WIL_LED_TIME_MED].on_ms, 210510d599adSMaya Erez &led_blink_time[WIL_LED_TIME_MED].off_ms, 210610d599adSMaya Erez &led_blink_time[WIL_LED_TIME_FAST].on_ms, 210710d599adSMaya Erez &led_blink_time[WIL_LED_TIME_FAST].off_ms); 210810d599adSMaya Erez kfree(kbuf); 210910d599adSMaya Erez 211010d599adSMaya Erez if (rc < 0) 211110d599adSMaya Erez return rc; 211210d599adSMaya Erez if (rc < 6) 211310d599adSMaya Erez return -EINVAL; 211410d599adSMaya Erez 211510d599adSMaya Erez return len; 211610d599adSMaya Erez } 211710d599adSMaya Erez 211810d599adSMaya Erez static ssize_t wil_read_led_blink_time(struct file *file, char __user *user_buf, 211910d599adSMaya Erez size_t count, loff_t *ppos) 212010d599adSMaya Erez { 212110d599adSMaya Erez static char text[400]; 212210d599adSMaya Erez 212310d599adSMaya Erez snprintf(text, sizeof(text), 212410d599adSMaya Erez "To set led blink on/off time variables write:\n" 212510d599adSMaya Erez "<blink_on_slow> <blink_off_slow> <blink_on_med> " 212610d599adSMaya Erez "<blink_off_med> <blink_on_fast> <blink_off_fast>\n" 212710d599adSMaya Erez "The current values are:\n" 212810d599adSMaya Erez "%d %d %d %d %d %d\n", 212910d599adSMaya Erez led_blink_time[WIL_LED_TIME_SLOW].on_ms, 213010d599adSMaya Erez led_blink_time[WIL_LED_TIME_SLOW].off_ms, 213110d599adSMaya Erez led_blink_time[WIL_LED_TIME_MED].on_ms, 213210d599adSMaya Erez led_blink_time[WIL_LED_TIME_MED].off_ms, 213310d599adSMaya Erez led_blink_time[WIL_LED_TIME_FAST].on_ms, 213410d599adSMaya Erez led_blink_time[WIL_LED_TIME_FAST].off_ms); 213510d599adSMaya Erez 213610d599adSMaya Erez return simple_read_from_buffer(user_buf, count, ppos, text, 213710d599adSMaya Erez sizeof(text)); 213810d599adSMaya Erez } 213910d599adSMaya Erez 214010d599adSMaya Erez static const struct file_operations fops_led_blink_time = { 214110d599adSMaya Erez .read = wil_read_led_blink_time, 214210d599adSMaya Erez .write = wil_write_led_blink_time, 214310d599adSMaya Erez .open = simple_open, 214410d599adSMaya Erez }; 214510d599adSMaya Erez 214612bace75SLior David /*---------FW capabilities------------*/ 214712bace75SLior David static int wil_fw_capabilities_debugfs_show(struct seq_file *s, void *data) 214812bace75SLior David { 214912bace75SLior David struct wil6210_priv *wil = s->private; 215012bace75SLior David 215112bace75SLior David seq_printf(s, "fw_capabilities : %*pb\n", WMI_FW_CAPABILITY_MAX, 215212bace75SLior David wil->fw_capabilities); 215312bace75SLior David 215412bace75SLior David return 0; 215512bace75SLior David } 215612bace75SLior David 215712bace75SLior David static int wil_fw_capabilities_seq_open(struct inode *inode, struct file *file) 215812bace75SLior David { 215912bace75SLior David return single_open(file, wil_fw_capabilities_debugfs_show, 216012bace75SLior David inode->i_private); 216112bace75SLior David } 216212bace75SLior David 216312bace75SLior David static const struct file_operations fops_fw_capabilities = { 216412bace75SLior David .open = wil_fw_capabilities_seq_open, 216512bace75SLior David .release = single_release, 216612bace75SLior David .read = seq_read, 216712bace75SLior David .llseek = seq_lseek, 216812bace75SLior David }; 216912bace75SLior David 217013cd9f75SLior David /*---------FW version------------*/ 217113cd9f75SLior David static int wil_fw_version_debugfs_show(struct seq_file *s, void *data) 217213cd9f75SLior David { 217313cd9f75SLior David struct wil6210_priv *wil = s->private; 217413cd9f75SLior David 217513cd9f75SLior David if (wil->fw_version[0]) 217613cd9f75SLior David seq_printf(s, "%s\n", wil->fw_version); 217713cd9f75SLior David else 217813cd9f75SLior David seq_puts(s, "N/A\n"); 217913cd9f75SLior David 218013cd9f75SLior David return 0; 218113cd9f75SLior David } 218213cd9f75SLior David 218313cd9f75SLior David static int wil_fw_version_seq_open(struct inode *inode, struct file *file) 218413cd9f75SLior David { 218513cd9f75SLior David return single_open(file, wil_fw_version_debugfs_show, 218613cd9f75SLior David inode->i_private); 218713cd9f75SLior David } 218813cd9f75SLior David 218913cd9f75SLior David static const struct file_operations fops_fw_version = { 219013cd9f75SLior David .open = wil_fw_version_seq_open, 219113cd9f75SLior David .release = single_release, 219213cd9f75SLior David .read = seq_read, 219313cd9f75SLior David .llseek = seq_lseek, 219413cd9f75SLior David }; 219513cd9f75SLior David 2196fe9ee51eSMaya Erez /*---------suspend_stats---------*/ 2197fe9ee51eSMaya Erez static ssize_t wil_write_suspend_stats(struct file *file, 2198fe9ee51eSMaya Erez const char __user *buf, 2199fe9ee51eSMaya Erez size_t len, loff_t *ppos) 2200fe9ee51eSMaya Erez { 2201fe9ee51eSMaya Erez struct wil6210_priv *wil = file->private_data; 2202fe9ee51eSMaya Erez 2203fe9ee51eSMaya Erez memset(&wil->suspend_stats, 0, sizeof(wil->suspend_stats)); 2204fe9ee51eSMaya Erez 2205fe9ee51eSMaya Erez return len; 2206fe9ee51eSMaya Erez } 2207fe9ee51eSMaya Erez 2208fe9ee51eSMaya Erez static ssize_t wil_read_suspend_stats(struct file *file, 2209fe9ee51eSMaya Erez char __user *user_buf, 2210fe9ee51eSMaya Erez size_t count, loff_t *ppos) 2211fe9ee51eSMaya Erez { 2212fe9ee51eSMaya Erez struct wil6210_priv *wil = file->private_data; 2213bd8bdc6cSLazar Alexei char *text; 2214bd8bdc6cSLazar Alexei int n, ret, text_size = 500; 2215fe9ee51eSMaya Erez 2216bd8bdc6cSLazar Alexei text = kmalloc(text_size, GFP_KERNEL); 2217bd8bdc6cSLazar Alexei if (!text) 2218bd8bdc6cSLazar Alexei return -ENOMEM; 2219bd8bdc6cSLazar Alexei 2220bd8bdc6cSLazar Alexei n = snprintf(text, text_size, 2221bd8bdc6cSLazar Alexei "Radio on suspend statistics:\n" 2222fe9ee51eSMaya Erez "successful suspends:%ld failed suspends:%ld\n" 2223fe9ee51eSMaya Erez "successful resumes:%ld failed resumes:%ld\n" 2224bd8bdc6cSLazar Alexei "rejected by device:%ld\n" 2225bd8bdc6cSLazar Alexei "Radio off suspend statistics:\n" 2226bd8bdc6cSLazar Alexei "successful suspends:%ld failed suspends:%ld\n" 2227bd8bdc6cSLazar Alexei "successful resumes:%ld failed resumes:%ld\n" 2228bd8bdc6cSLazar Alexei "General statistics:\n" 2229bd8bdc6cSLazar Alexei "rejected by host:%ld\n", 2230bd8bdc6cSLazar Alexei wil->suspend_stats.r_on.successful_suspends, 2231bd8bdc6cSLazar Alexei wil->suspend_stats.r_on.failed_suspends, 2232bd8bdc6cSLazar Alexei wil->suspend_stats.r_on.successful_resumes, 2233bd8bdc6cSLazar Alexei wil->suspend_stats.r_on.failed_resumes, 2234bd8bdc6cSLazar Alexei wil->suspend_stats.rejected_by_device, 2235bd8bdc6cSLazar Alexei wil->suspend_stats.r_off.successful_suspends, 2236bd8bdc6cSLazar Alexei wil->suspend_stats.r_off.failed_suspends, 2237bd8bdc6cSLazar Alexei wil->suspend_stats.r_off.successful_resumes, 2238bd8bdc6cSLazar Alexei wil->suspend_stats.r_off.failed_resumes, 2239bd8bdc6cSLazar Alexei wil->suspend_stats.rejected_by_host); 2240fe9ee51eSMaya Erez 2241bd8bdc6cSLazar Alexei n = min_t(int, n, text_size); 2242fe9ee51eSMaya Erez 2243bd8bdc6cSLazar Alexei ret = simple_read_from_buffer(user_buf, count, ppos, text, n); 2244bd8bdc6cSLazar Alexei 2245bd8bdc6cSLazar Alexei kfree(text); 2246bd8bdc6cSLazar Alexei 2247bd8bdc6cSLazar Alexei return ret; 2248fe9ee51eSMaya Erez } 2249fe9ee51eSMaya Erez 2250fe9ee51eSMaya Erez static const struct file_operations fops_suspend_stats = { 2251fe9ee51eSMaya Erez .read = wil_read_suspend_stats, 2252fe9ee51eSMaya Erez .write = wil_write_suspend_stats, 2253fe9ee51eSMaya Erez .open = simple_open, 2254fe9ee51eSMaya Erez }; 2255fe9ee51eSMaya Erez 225696c93589SGidon Studinski /*---------compressed_rx_status---------*/ 225796c93589SGidon Studinski static ssize_t wil_compressed_rx_status_write(struct file *file, 225896c93589SGidon Studinski const char __user *buf, 225996c93589SGidon Studinski size_t len, loff_t *ppos) 226096c93589SGidon Studinski { 226196c93589SGidon Studinski struct seq_file *s = file->private_data; 226296c93589SGidon Studinski struct wil6210_priv *wil = s->private; 226396c93589SGidon Studinski int compressed_rx_status; 226496c93589SGidon Studinski int rc; 226596c93589SGidon Studinski 226696c93589SGidon Studinski rc = kstrtoint_from_user(buf, len, 0, &compressed_rx_status); 226796c93589SGidon Studinski if (rc) { 226896c93589SGidon Studinski wil_err(wil, "Invalid argument\n"); 226996c93589SGidon Studinski return rc; 227096c93589SGidon Studinski } 227196c93589SGidon Studinski 227296c93589SGidon Studinski if (wil_has_active_ifaces(wil, true, false)) { 227396c93589SGidon Studinski wil_err(wil, "cannot change edma config after iface is up\n"); 227496c93589SGidon Studinski return -EPERM; 227596c93589SGidon Studinski } 227696c93589SGidon Studinski 227796c93589SGidon Studinski wil_info(wil, "%sable compressed_rx_status\n", 227896c93589SGidon Studinski compressed_rx_status ? "En" : "Dis"); 227996c93589SGidon Studinski 228096c93589SGidon Studinski wil->use_compressed_rx_status = compressed_rx_status; 228196c93589SGidon Studinski 228296c93589SGidon Studinski return len; 228396c93589SGidon Studinski } 228496c93589SGidon Studinski 228596c93589SGidon Studinski static int 228696c93589SGidon Studinski wil_compressed_rx_status_show(struct seq_file *s, void *data) 228796c93589SGidon Studinski { 228896c93589SGidon Studinski struct wil6210_priv *wil = s->private; 228996c93589SGidon Studinski 229096c93589SGidon Studinski seq_printf(s, "%d\n", wil->use_compressed_rx_status); 229196c93589SGidon Studinski 229296c93589SGidon Studinski return 0; 229396c93589SGidon Studinski } 229496c93589SGidon Studinski 229596c93589SGidon Studinski static int 229696c93589SGidon Studinski wil_compressed_rx_status_seq_open(struct inode *inode, struct file *file) 229796c93589SGidon Studinski { 229896c93589SGidon Studinski return single_open(file, wil_compressed_rx_status_show, 229996c93589SGidon Studinski inode->i_private); 230096c93589SGidon Studinski } 230196c93589SGidon Studinski 230296c93589SGidon Studinski static const struct file_operations fops_compressed_rx_status = { 230396c93589SGidon Studinski .open = wil_compressed_rx_status_seq_open, 230496c93589SGidon Studinski .release = single_release, 230596c93589SGidon Studinski .read = seq_read, 230696c93589SGidon Studinski .write = wil_compressed_rx_status_write, 230796c93589SGidon Studinski .llseek = seq_lseek, 230896c93589SGidon Studinski }; 230996c93589SGidon Studinski 23102be7d22fSVladimir Kondratiev /*----------------*/ 2311b541d0a0SVladimir Kondratiev static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil, 2312b541d0a0SVladimir Kondratiev struct dentry *dbg) 2313b541d0a0SVladimir Kondratiev { 2314b541d0a0SVladimir Kondratiev int i; 2315b541d0a0SVladimir Kondratiev char name[32]; 2316b541d0a0SVladimir Kondratiev 2317b541d0a0SVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) { 2318349214c1SMaya Erez struct wil_blob_wrapper *wil_blob = &wil->blobs[i]; 2319349214c1SMaya Erez struct debugfs_blob_wrapper *blob = &wil_blob->blob; 2320b541d0a0SVladimir Kondratiev const struct fw_map *map = &fw_mapping[i]; 2321b541d0a0SVladimir Kondratiev 2322b541d0a0SVladimir Kondratiev if (!map->name) 2323b541d0a0SVladimir Kondratiev continue; 2324b541d0a0SVladimir Kondratiev 2325349214c1SMaya Erez wil_blob->wil = wil; 2326b541d0a0SVladimir Kondratiev blob->data = (void * __force)wil->csr + HOSTADDR(map->host); 2327b541d0a0SVladimir Kondratiev blob->size = map->to - map->from; 2328b541d0a0SVladimir Kondratiev snprintf(name, sizeof(name), "blob_%s", map->name); 232978484c44SMaya Erez wil_debugfs_create_ioblob(name, 0444, dbg, wil_blob); 2330b541d0a0SVladimir Kondratiev } 2331b541d0a0SVladimir Kondratiev } 2332b541d0a0SVladimir Kondratiev 2333b7cde470SVladimir Kondratiev /* misc files */ 2334b7cde470SVladimir Kondratiev static const struct { 2335b7cde470SVladimir Kondratiev const char *name; 2336b7cde470SVladimir Kondratiev umode_t mode; 2337b7cde470SVladimir Kondratiev const struct file_operations *fops; 2338b7cde470SVladimir Kondratiev } dbg_files[] = { 2339986b8348SYangtao Li {"mbox", 0444, &mbox_fops}, 2340986b8348SYangtao Li {"rings", 0444, &ring_fops}, 2341986b8348SYangtao Li {"stations", 0444, &sta_fops}, 2342986b8348SYangtao Li {"mids", 0444, &mids_fops}, 2343986b8348SYangtao Li {"desc", 0444, &txdesc_fops}, 2344986b8348SYangtao Li {"bf", 0444, &bf_fops}, 2345986b8348SYangtao Li {"mem_val", 0644, &memread_fops}, 234678484c44SMaya Erez {"rxon", 0244, &fops_rxon}, 234778484c44SMaya Erez {"tx_mgmt", 0244, &fops_txmgmt}, 234878484c44SMaya Erez {"wmi_send", 0244, &fops_wmi}, 234978484c44SMaya Erez {"back", 0644, &fops_back}, 235078484c44SMaya Erez {"pmccfg", 0644, &fops_pmccfg}, 235178484c44SMaya Erez {"pmcdata", 0444, &fops_pmcdata}, 2352986b8348SYangtao Li {"temp", 0444, &temp_fops}, 2353986b8348SYangtao Li {"freq", 0444, &freq_fops}, 2354986b8348SYangtao Li {"link", 0444, &link_fops}, 2355986b8348SYangtao Li {"info", 0444, &info_fops}, 235678484c44SMaya Erez {"recovery", 0644, &fops_recovery}, 235778484c44SMaya Erez {"led_cfg", 0644, &fops_led_cfg}, 235878484c44SMaya Erez {"led_blink_time", 0644, &fops_led_blink_time}, 235978484c44SMaya Erez {"fw_capabilities", 0444, &fops_fw_capabilities}, 236078484c44SMaya Erez {"fw_version", 0444, &fops_fw_version}, 2361fe9ee51eSMaya Erez {"suspend_stats", 0644, &fops_suspend_stats}, 236296c93589SGidon Studinski {"compressed_rx_status", 0644, &fops_compressed_rx_status}, 2363986b8348SYangtao Li {"srings", 0444, &srings_fops}, 2364986b8348SYangtao Li {"status_msg", 0444, &status_msg_fops}, 2365986b8348SYangtao Li {"rx_buff_mgmt", 0444, &rx_buff_mgmt_fops}, 2366a24a3d6aSDedy Lansky {"tx_latency", 0644, &fops_tx_latency}, 23670c936b3cSDedy Lansky {"link_stats", 0644, &fops_link_stats}, 23680c936b3cSDedy Lansky {"link_stats_global", 0644, &fops_link_stats_global}, 2369*c5b3a658SAlexei Avshalom Lazar {"rbufcap", 0244, &fops_rbufcap}, 2370b7cde470SVladimir Kondratiev }; 2371b7cde470SVladimir Kondratiev 2372b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_files(struct wil6210_priv *wil, 2373b7cde470SVladimir Kondratiev struct dentry *dbg) 2374b7cde470SVladimir Kondratiev { 2375b7cde470SVladimir Kondratiev int i; 2376b7cde470SVladimir Kondratiev 2377b7cde470SVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(dbg_files); i++) 2378b7cde470SVladimir Kondratiev debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg, 2379b7cde470SVladimir Kondratiev wil, dbg_files[i].fops); 2380b7cde470SVladimir Kondratiev } 2381b7cde470SVladimir Kondratiev 2382b7cde470SVladimir Kondratiev /* interrupt control blocks */ 2383b7cde470SVladimir Kondratiev static const struct { 2384b7cde470SVladimir Kondratiev const char *name; 2385b7cde470SVladimir Kondratiev u32 icr_off; 2386b7cde470SVladimir Kondratiev } dbg_icr[] = { 2387b7cde470SVladimir Kondratiev {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)}, 2388b7cde470SVladimir Kondratiev {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)}, 2389b7cde470SVladimir Kondratiev {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)}, 2390b7cde470SVladimir Kondratiev {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)}, 2391b7cde470SVladimir Kondratiev }; 2392b7cde470SVladimir Kondratiev 2393b7cde470SVladimir Kondratiev static void wil6210_debugfs_init_isr(struct wil6210_priv *wil, 2394b7cde470SVladimir Kondratiev struct dentry *dbg) 2395b7cde470SVladimir Kondratiev { 2396b7cde470SVladimir Kondratiev int i; 2397b7cde470SVladimir Kondratiev 2398b7cde470SVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(dbg_icr); i++) 2399b7cde470SVladimir Kondratiev wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg, 2400b7cde470SVladimir Kondratiev dbg_icr[i].icr_off); 2401b7cde470SVladimir Kondratiev } 2402b7cde470SVladimir Kondratiev 2403b7cde470SVladimir Kondratiev #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \ 2404b7cde470SVladimir Kondratiev offsetof(struct wil6210_priv, name), type} 2405b7cde470SVladimir Kondratiev 2406b7cde470SVladimir Kondratiev /* fields in struct wil6210_priv */ 2407b7cde470SVladimir Kondratiev static const struct dbg_off dbg_wil_off[] = { 240878484c44SMaya Erez WIL_FIELD(status[0], 0644, doff_ulong), 240978484c44SMaya Erez WIL_FIELD(hw_version, 0444, doff_x32), 241078484c44SMaya Erez WIL_FIELD(recovery_count, 0444, doff_u32), 241178484c44SMaya Erez WIL_FIELD(discovery_mode, 0644, doff_u8), 241278484c44SMaya Erez WIL_FIELD(chip_revision, 0444, doff_u8), 241378484c44SMaya Erez WIL_FIELD(abft_len, 0644, doff_u8), 2414fe9ee51eSMaya Erez WIL_FIELD(wakeup_trigger, 0644, doff_u8), 241510590c6aSGidon Studinski WIL_FIELD(ring_idle_trsh, 0644, doff_u32), 241696c93589SGidon Studinski WIL_FIELD(num_rx_status_rings, 0644, doff_u8), 241796c93589SGidon Studinski WIL_FIELD(rx_status_ring_order, 0644, doff_u32), 241896c93589SGidon Studinski WIL_FIELD(tx_status_ring_order, 0644, doff_u32), 241996c93589SGidon Studinski WIL_FIELD(rx_buff_id_count, 0644, doff_u32), 24207be13fc3SGidon Studinski WIL_FIELD(amsdu_en, 0644, doff_u8), 2421b7cde470SVladimir Kondratiev {}, 2422b7cde470SVladimir Kondratiev }; 2423b7cde470SVladimir Kondratiev 2424b7cde470SVladimir Kondratiev static const struct dbg_off dbg_wil_regs[] = { 242578484c44SMaya Erez {"RGF_MAC_MTRL_COUNTER_0", 0444, HOSTADDR(RGF_MAC_MTRL_COUNTER_0), 2426b7cde470SVladimir Kondratiev doff_io32}, 242778484c44SMaya Erez {"RGF_USER_USAGE_1", 0444, HOSTADDR(RGF_USER_USAGE_1), doff_io32}, 24288454e72aSAhmad Masri {"RGF_USER_USAGE_2", 0444, HOSTADDR(RGF_USER_USAGE_2), doff_io32}, 2429b7cde470SVladimir Kondratiev {}, 2430b7cde470SVladimir Kondratiev }; 2431b7cde470SVladimir Kondratiev 2432b7cde470SVladimir Kondratiev /* static parameters */ 2433b7cde470SVladimir Kondratiev static const struct dbg_off dbg_statics[] = { 243478484c44SMaya Erez {"desc_index", 0644, (ulong)&dbg_txdesc_index, doff_u32}, 243510590c6aSGidon Studinski {"ring_index", 0644, (ulong)&dbg_ring_index, doff_u32}, 243678484c44SMaya Erez {"mem_addr", 0644, (ulong)&mem_addr, doff_u32}, 243778484c44SMaya Erez {"led_polarity", 0644, (ulong)&led_polarity, doff_u8}, 2438d98b8539SMaya Erez {"status_index", 0644, (ulong)&dbg_status_msg_index, doff_u32}, 2439d98b8539SMaya Erez {"sring_index", 0644, (ulong)&dbg_sring_index, doff_u32}, 24400439a5e0SDedy Lansky {"drop_if_ring_full", 0644, (ulong)&drop_if_ring_full, doff_u8}, 2441b7cde470SVladimir Kondratiev {}, 2442b7cde470SVladimir Kondratiev }; 2443b7cde470SVladimir Kondratiev 244494162666SLazar Alexei static const int dbg_off_count = 4 * (ARRAY_SIZE(isr_off) - 1) + 244594162666SLazar Alexei ARRAY_SIZE(dbg_wil_regs) - 1 + 244694162666SLazar Alexei ARRAY_SIZE(pseudo_isr_off) - 1 + 244794162666SLazar Alexei ARRAY_SIZE(lgc_itr_cnt_off) - 1 + 244894162666SLazar Alexei ARRAY_SIZE(tx_itr_cnt_off) - 1 + 244994162666SLazar Alexei ARRAY_SIZE(rx_itr_cnt_off) - 1; 245094162666SLazar Alexei 24512be7d22fSVladimir Kondratiev int wil6210_debugfs_init(struct wil6210_priv *wil) 24522be7d22fSVladimir Kondratiev { 24532be7d22fSVladimir Kondratiev struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME, 24542be7d22fSVladimir Kondratiev wil_to_wiphy(wil)->debugfsdir); 24552be7d22fSVladimir Kondratiev if (IS_ERR_OR_NULL(dbg)) 24562be7d22fSVladimir Kondratiev return -ENODEV; 24572be7d22fSVladimir Kondratiev 245894162666SLazar Alexei wil->dbg_data.data_arr = kcalloc(dbg_off_count, 245994162666SLazar Alexei sizeof(struct wil_debugfs_iomem_data), 246094162666SLazar Alexei GFP_KERNEL); 246194162666SLazar Alexei if (!wil->dbg_data.data_arr) { 246294162666SLazar Alexei debugfs_remove_recursive(dbg); 246394162666SLazar Alexei wil->debug = NULL; 246494162666SLazar Alexei return -ENOMEM; 246594162666SLazar Alexei } 246694162666SLazar Alexei 246794162666SLazar Alexei wil->dbg_data.iomem_data_count = 0; 246894162666SLazar Alexei 2469dc16427bSVladimir Kondratiev wil_pmc_init(wil); 2470dc16427bSVladimir Kondratiev 2471b7cde470SVladimir Kondratiev wil6210_debugfs_init_files(wil, dbg); 2472b7cde470SVladimir Kondratiev wil6210_debugfs_init_isr(wil, dbg); 2473b541d0a0SVladimir Kondratiev wil6210_debugfs_init_blobs(wil, dbg); 2474b7cde470SVladimir Kondratiev wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off); 2475b7cde470SVladimir Kondratiev wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr, 2476b7cde470SVladimir Kondratiev dbg_wil_regs); 2477b7cde470SVladimir Kondratiev wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics); 2478b7cde470SVladimir Kondratiev 2479b7cde470SVladimir Kondratiev wil6210_debugfs_create_pseudo_ISR(wil, dbg); 2480b7cde470SVladimir Kondratiev 2481b7cde470SVladimir Kondratiev wil6210_debugfs_create_ITR_CNT(wil, dbg); 24822be7d22fSVladimir Kondratiev 24832be7d22fSVladimir Kondratiev return 0; 24842be7d22fSVladimir Kondratiev } 24852be7d22fSVladimir Kondratiev 24862be7d22fSVladimir Kondratiev void wil6210_debugfs_remove(struct wil6210_priv *wil) 24872be7d22fSVladimir Kondratiev { 2488a24a3d6aSDedy Lansky int i; 2489a24a3d6aSDedy Lansky 24902be7d22fSVladimir Kondratiev debugfs_remove_recursive(wil->debug); 24912be7d22fSVladimir Kondratiev wil->debug = NULL; 2492dc16427bSVladimir Kondratiev 249394162666SLazar Alexei kfree(wil->dbg_data.data_arr); 2494ddf7afddSAhmad Masri for (i = 0; i < wil->max_assoc_sta; i++) 2495a24a3d6aSDedy Lansky kfree(wil->sta[i].tx_latency_bins); 249694162666SLazar Alexei 2497dc16427bSVladimir Kondratiev /* free pmc memory without sending command to fw, as it will 2498dc16427bSVladimir Kondratiev * be reset on the way down anyway 2499dc16427bSVladimir Kondratiev */ 2500dc16427bSVladimir Kondratiev wil_pmc_free(wil, false); 25012be7d22fSVladimir Kondratiev } 2502