Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1 | /* |
Hamad Kadmany | ee5dfe0 | 2016-01-28 19:24:05 +0200 | [diff] [blame^] | 2 | * Copyright (c) 2012-2016 Qualcomm Atheros, Inc. |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/debugfs.h> |
| 19 | #include <linux/seq_file.h> |
| 20 | #include <linux/pci.h> |
| 21 | #include <linux/rtnetlink.h> |
Vladimir Kondratiev | 84bb29b | 2014-06-16 19:37:21 +0300 | [diff] [blame] | 22 | #include <linux/power_supply.h> |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 23 | |
| 24 | #include "wil6210.h" |
Vladimir Kondratiev | 36345ac | 2014-08-06 10:31:56 +0300 | [diff] [blame] | 25 | #include "wmi.h" |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 26 | #include "txrx.h" |
Vladimir Kondratiev | dc16427 | 2015-04-30 16:25:09 +0300 | [diff] [blame] | 27 | #include "pmc.h" |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 28 | |
| 29 | /* Nasty hack. Better have per device instances */ |
| 30 | static u32 mem_addr; |
| 31 | static u32 dbg_txdesc_index; |
Vladimir Kondratiev | af31cb5 | 2014-03-02 11:20:50 +0200 | [diff] [blame] | 32 | static u32 dbg_vring_index; /* 24+ for Rx, 0..23 for Tx */ |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 33 | u32 vring_idle_trsh = 16; /* HW fetches up to 16 descriptors at once */ |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 34 | |
Vladimir Kondratiev | b7cde47 | 2014-08-06 10:31:55 +0300 | [diff] [blame] | 35 | enum dbg_off_type { |
| 36 | doff_u32 = 0, |
| 37 | doff_x32 = 1, |
| 38 | doff_ulong = 2, |
| 39 | doff_io32 = 3, |
| 40 | }; |
| 41 | |
| 42 | /* offset to "wil" */ |
| 43 | struct dbg_off { |
| 44 | const char *name; |
| 45 | umode_t mode; |
| 46 | ulong off; |
| 47 | enum dbg_off_type type; |
| 48 | }; |
| 49 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 50 | static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil, |
Vladimir Kondratiev | 59f7c0a | 2014-02-27 16:20:42 +0200 | [diff] [blame] | 51 | const char *name, struct vring *vring, |
| 52 | char _s, char _h) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 53 | { |
| 54 | void __iomem *x = wmi_addr(wil, vring->hwtail); |
Vladimir Kondratiev | 995cdd0 | 2014-12-23 09:47:08 +0200 | [diff] [blame] | 55 | u32 v; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 56 | |
| 57 | seq_printf(s, "VRING %s = {\n", name); |
Vladimir Kondratiev | 39c52ee | 2014-05-27 14:45:49 +0300 | [diff] [blame] | 58 | seq_printf(s, " pa = %pad\n", &vring->pa); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 59 | seq_printf(s, " va = 0x%p\n", vring->va); |
| 60 | seq_printf(s, " size = %d\n", vring->size); |
| 61 | seq_printf(s, " swtail = %d\n", vring->swtail); |
| 62 | seq_printf(s, " swhead = %d\n", vring->swhead); |
| 63 | seq_printf(s, " hwtail = [0x%08x] -> ", vring->hwtail); |
Vladimir Kondratiev | 995cdd0 | 2014-12-23 09:47:08 +0200 | [diff] [blame] | 64 | if (x) { |
Vladimir Kondratiev | b9eeb51 | 2015-07-30 13:52:03 +0300 | [diff] [blame] | 65 | v = readl(x); |
Vladimir Kondratiev | 995cdd0 | 2014-12-23 09:47:08 +0200 | [diff] [blame] | 66 | seq_printf(s, "0x%08x = %d\n", v, v); |
| 67 | } else { |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 68 | seq_puts(s, "???\n"); |
Vladimir Kondratiev | 995cdd0 | 2014-12-23 09:47:08 +0200 | [diff] [blame] | 69 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 70 | |
Hamad Kadmany | ee5dfe0 | 2016-01-28 19:24:05 +0200 | [diff] [blame^] | 71 | if (vring->va && (vring->size <= (1 << WIL_RING_SIZE_ORDER_MAX))) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 72 | uint i; |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 73 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 74 | for (i = 0; i < vring->size; i++) { |
| 75 | volatile struct vring_tx_desc *d = &vring->va[i].tx; |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 76 | |
Hamad Kadmany | ee5dfe0 | 2016-01-28 19:24:05 +0200 | [diff] [blame^] | 77 | if ((i % 128) == 0 && (i != 0)) |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 78 | seq_puts(s, "\n"); |
Vladimir Kondratiev | 59f7c0a | 2014-02-27 16:20:42 +0200 | [diff] [blame] | 79 | seq_printf(s, "%c", (d->dma.status & BIT(0)) ? |
| 80 | _s : (vring->ctx[i].skb ? _h : 'h')); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 81 | } |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 82 | seq_puts(s, "\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 83 | } |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 84 | seq_puts(s, "}\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | static int wil_vring_debugfs_show(struct seq_file *s, void *data) |
| 88 | { |
| 89 | uint i; |
| 90 | struct wil6210_priv *wil = s->private; |
| 91 | |
Vladimir Kondratiev | 59f7c0a | 2014-02-27 16:20:42 +0200 | [diff] [blame] | 92 | wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_'); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 93 | |
| 94 | for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) { |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 95 | struct vring *vring = &wil->vring_tx[i]; |
Vladimir Kondratiev | 7c0acf8 | 2014-06-16 19:37:05 +0300 | [diff] [blame] | 96 | struct vring_tx_data *txdata = &wil->vring_tx_data[i]; |
| 97 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 98 | if (vring->va) { |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 99 | int cid = wil->vring2cid_tid[i][0]; |
| 100 | int tid = wil->vring2cid_tid[i][1]; |
Vladimir Kondratiev | 67c3e1b | 2014-06-16 19:37:04 +0300 | [diff] [blame] | 101 | u32 swhead = vring->swhead; |
| 102 | u32 swtail = vring->swtail; |
| 103 | int used = (vring->size + swhead - swtail) |
| 104 | % vring->size; |
| 105 | int avail = vring->size - used - 1; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 106 | char name[10]; |
Boris Sorochkin | 8f55cbe | 2015-02-15 14:02:35 +0200 | [diff] [blame] | 107 | char sidle[10]; |
Vladimir Kondratiev | 7c0acf8 | 2014-06-16 19:37:05 +0300 | [diff] [blame] | 108 | /* performance monitoring */ |
| 109 | cycles_t now = get_cycles(); |
Chen Gang | c20e778 | 2014-12-24 23:08:44 +0800 | [diff] [blame] | 110 | uint64_t idle = txdata->idle * 100; |
| 111 | uint64_t total = now - txdata->begin; |
Vladimir Kondratiev | 7c0acf8 | 2014-06-16 19:37:05 +0300 | [diff] [blame] | 112 | |
Boris Sorochkin | 8f55cbe | 2015-02-15 14:02:35 +0200 | [diff] [blame] | 113 | if (total != 0) { |
| 114 | do_div(idle, total); |
| 115 | snprintf(sidle, sizeof(sidle), "%3d%%", |
| 116 | (int)idle); |
| 117 | } else { |
| 118 | snprintf(sidle, sizeof(sidle), "N/A"); |
| 119 | } |
Vladimir Kondratiev | 7c0acf8 | 2014-06-16 19:37:05 +0300 | [diff] [blame] | 120 | txdata->begin = now; |
| 121 | txdata->idle = 0ULL; |
| 122 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 123 | snprintf(name, sizeof(name), "tx_%2d", i); |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 124 | |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 125 | if (cid < WIL6210_MAX_CID) |
| 126 | seq_printf(s, |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 127 | "\n%pM CID %d TID %d 1x%s BACK([%u] %u TU A%s) [%3d|%3d] idle %s\n", |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 128 | wil->sta[cid].addr, cid, tid, |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 129 | txdata->dot1x_open ? "+" : "-", |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 130 | txdata->agg_wsize, |
| 131 | txdata->agg_timeout, |
| 132 | txdata->agg_amsdu ? "+" : "-", |
| 133 | used, avail, sidle); |
| 134 | else |
| 135 | seq_printf(s, |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 136 | "\nBroadcast 1x%s [%3d|%3d] idle %s\n", |
| 137 | txdata->dot1x_open ? "+" : "-", |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 138 | used, avail, sidle); |
Vladimir Kondratiev | 7c0acf8 | 2014-06-16 19:37:05 +0300 | [diff] [blame] | 139 | |
Vladimir Kondratiev | 59f7c0a | 2014-02-27 16:20:42 +0200 | [diff] [blame] | 140 | wil_print_vring(s, wil, name, vring, '_', 'H'); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 141 | } |
| 142 | } |
| 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | static int wil_vring_seq_open(struct inode *inode, struct file *file) |
| 148 | { |
| 149 | return single_open(file, wil_vring_debugfs_show, inode->i_private); |
| 150 | } |
| 151 | |
| 152 | static const struct file_operations fops_vring = { |
| 153 | .open = wil_vring_seq_open, |
| 154 | .release = single_release, |
| 155 | .read = seq_read, |
| 156 | .llseek = seq_lseek, |
| 157 | }; |
| 158 | |
Andy Shevchenko | a202fbb | 2015-09-09 15:38:48 -0700 | [diff] [blame] | 159 | static void wil_seq_hexdump(struct seq_file *s, void *p, int len, |
| 160 | const char *prefix) |
| 161 | { |
| 162 | seq_hex_dump(s, prefix, DUMP_PREFIX_NONE, 16, 1, p, len, false); |
| 163 | } |
| 164 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 165 | static void wil_print_ring(struct seq_file *s, const char *prefix, |
| 166 | void __iomem *off) |
| 167 | { |
| 168 | struct wil6210_priv *wil = s->private; |
| 169 | struct wil6210_mbox_ring r; |
| 170 | int rsize; |
| 171 | uint i; |
| 172 | |
| 173 | wil_memcpy_fromio_32(&r, off, sizeof(r)); |
| 174 | wil_mbox_ring_le2cpus(&r); |
| 175 | /* |
| 176 | * we just read memory block from NIC. This memory may be |
| 177 | * garbage. Check validity before using it. |
| 178 | */ |
| 179 | rsize = r.size / sizeof(struct wil6210_mbox_ring_desc); |
| 180 | |
| 181 | seq_printf(s, "ring %s = {\n", prefix); |
| 182 | seq_printf(s, " base = 0x%08x\n", r.base); |
| 183 | seq_printf(s, " size = 0x%04x bytes -> %d entries\n", r.size, rsize); |
| 184 | seq_printf(s, " tail = 0x%08x\n", r.tail); |
| 185 | seq_printf(s, " head = 0x%08x\n", r.head); |
| 186 | seq_printf(s, " entry size = %d\n", r.entry_size); |
| 187 | |
| 188 | if (r.size % sizeof(struct wil6210_mbox_ring_desc)) { |
| 189 | seq_printf(s, " ??? size is not multiple of %zd, garbage?\n", |
| 190 | sizeof(struct wil6210_mbox_ring_desc)); |
| 191 | goto out; |
| 192 | } |
| 193 | |
| 194 | if (!wmi_addr(wil, r.base) || |
| 195 | !wmi_addr(wil, r.tail) || |
| 196 | !wmi_addr(wil, r.head)) { |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 197 | seq_puts(s, " ??? pointers are garbage?\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 198 | goto out; |
| 199 | } |
| 200 | |
| 201 | for (i = 0; i < rsize; i++) { |
| 202 | struct wil6210_mbox_ring_desc d; |
| 203 | struct wil6210_mbox_hdr hdr; |
| 204 | size_t delta = i * sizeof(d); |
| 205 | void __iomem *x = wil->csr + HOSTADDR(r.base) + delta; |
| 206 | |
| 207 | wil_memcpy_fromio_32(&d, x, sizeof(d)); |
| 208 | |
| 209 | seq_printf(s, " [%2x] %s %s%s 0x%08x", i, |
| 210 | d.sync ? "F" : "E", |
| 211 | (r.tail - r.base == delta) ? "t" : " ", |
| 212 | (r.head - r.base == delta) ? "h" : " ", |
| 213 | le32_to_cpu(d.addr)); |
| 214 | if (0 == wmi_read_hdr(wil, d.addr, &hdr)) { |
| 215 | u16 len = le16_to_cpu(hdr.len); |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 216 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 217 | seq_printf(s, " -> %04x %04x %04x %02x\n", |
| 218 | le16_to_cpu(hdr.seq), len, |
| 219 | le16_to_cpu(hdr.type), hdr.flags); |
| 220 | if (len <= MAX_MBOXITEM_SIZE) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 221 | unsigned char databuf[MAX_MBOXITEM_SIZE]; |
| 222 | void __iomem *src = wmi_buffer(wil, d.addr) + |
| 223 | sizeof(struct wil6210_mbox_hdr); |
| 224 | /* |
| 225 | * No need to check @src for validity - |
| 226 | * we already validated @d.addr while |
| 227 | * reading header |
| 228 | */ |
| 229 | wil_memcpy_fromio_32(databuf, src, len); |
Andy Shevchenko | a202fbb | 2015-09-09 15:38:48 -0700 | [diff] [blame] | 230 | wil_seq_hexdump(s, databuf, len, " : "); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 231 | } |
| 232 | } else { |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 233 | seq_puts(s, "\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 234 | } |
| 235 | } |
| 236 | out: |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 237 | seq_puts(s, "}\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | static int wil_mbox_debugfs_show(struct seq_file *s, void *data) |
| 241 | { |
| 242 | struct wil6210_priv *wil = s->private; |
| 243 | |
| 244 | wil_print_ring(s, "tx", wil->csr + HOST_MBOX + |
| 245 | offsetof(struct wil6210_mbox_ctl, tx)); |
| 246 | wil_print_ring(s, "rx", wil->csr + HOST_MBOX + |
| 247 | offsetof(struct wil6210_mbox_ctl, rx)); |
| 248 | |
| 249 | return 0; |
| 250 | } |
| 251 | |
| 252 | static int wil_mbox_seq_open(struct inode *inode, struct file *file) |
| 253 | { |
| 254 | return single_open(file, wil_mbox_debugfs_show, inode->i_private); |
| 255 | } |
| 256 | |
| 257 | static const struct file_operations fops_mbox = { |
| 258 | .open = wil_mbox_seq_open, |
| 259 | .release = single_release, |
| 260 | .read = seq_read, |
| 261 | .llseek = seq_lseek, |
| 262 | }; |
| 263 | |
| 264 | static int wil_debugfs_iomem_x32_set(void *data, u64 val) |
| 265 | { |
Vladimir Kondratiev | b9eeb51 | 2015-07-30 13:52:03 +0300 | [diff] [blame] | 266 | writel(val, (void __iomem *)data); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 267 | wmb(); /* make sure write propagated to HW */ |
| 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | static int wil_debugfs_iomem_x32_get(void *data, u64 *val) |
| 273 | { |
Vladimir Kondratiev | b9eeb51 | 2015-07-30 13:52:03 +0300 | [diff] [blame] | 274 | *val = readl((void __iomem *)data); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 275 | |
| 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get, |
| 280 | wil_debugfs_iomem_x32_set, "0x%08llx\n"); |
| 281 | |
| 282 | static struct dentry *wil_debugfs_create_iomem_x32(const char *name, |
Al Viro | 0ecc833 | 2013-03-29 12:23:28 -0400 | [diff] [blame] | 283 | umode_t mode, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 284 | struct dentry *parent, |
Vladimir Kondratiev | b7cde47 | 2014-08-06 10:31:55 +0300 | [diff] [blame] | 285 | void *value) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 286 | { |
Vladimir Kondratiev | b7cde47 | 2014-08-06 10:31:55 +0300 | [diff] [blame] | 287 | return debugfs_create_file(name, mode, parent, value, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 288 | &fops_iomem_x32); |
| 289 | } |
| 290 | |
Vladimir Kondratiev | 3de6cf2 | 2014-06-16 19:37:02 +0300 | [diff] [blame] | 291 | static int wil_debugfs_ulong_set(void *data, u64 val) |
| 292 | { |
| 293 | *(ulong *)data = val; |
| 294 | return 0; |
| 295 | } |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 296 | |
Vladimir Kondratiev | 3de6cf2 | 2014-06-16 19:37:02 +0300 | [diff] [blame] | 297 | static int wil_debugfs_ulong_get(void *data, u64 *val) |
| 298 | { |
| 299 | *val = *(ulong *)data; |
| 300 | return 0; |
| 301 | } |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 302 | |
Vladimir Kondratiev | 3de6cf2 | 2014-06-16 19:37:02 +0300 | [diff] [blame] | 303 | DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get, |
Vladimir Kondratiev | 8ea0618 | 2015-07-30 13:51:51 +0300 | [diff] [blame] | 304 | wil_debugfs_ulong_set, "0x%llx\n"); |
Vladimir Kondratiev | 3de6cf2 | 2014-06-16 19:37:02 +0300 | [diff] [blame] | 305 | |
| 306 | static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode, |
| 307 | struct dentry *parent, |
| 308 | ulong *value) |
| 309 | { |
| 310 | return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong); |
| 311 | } |
| 312 | |
Vladimir Kondratiev | b7cde47 | 2014-08-06 10:31:55 +0300 | [diff] [blame] | 313 | /** |
| 314 | * wil6210_debugfs_init_offset - create set of debugfs files |
| 315 | * @wil - driver's context, used for printing |
| 316 | * @dbg - directory on the debugfs, where files will be created |
| 317 | * @base - base address used in address calculation |
| 318 | * @tbl - table with file descriptions. Should be terminated with empty element. |
| 319 | * |
| 320 | * Creates files accordingly to the @tbl. |
| 321 | */ |
| 322 | static void wil6210_debugfs_init_offset(struct wil6210_priv *wil, |
| 323 | struct dentry *dbg, void *base, |
| 324 | const struct dbg_off * const tbl) |
| 325 | { |
| 326 | int i; |
| 327 | |
| 328 | for (i = 0; tbl[i].name; i++) { |
Vladimir Kondratiev | 867fa0d | 2014-09-10 16:34:51 +0300 | [diff] [blame] | 329 | struct dentry *f; |
Vladimir Kondratiev | b7cde47 | 2014-08-06 10:31:55 +0300 | [diff] [blame] | 330 | |
| 331 | switch (tbl[i].type) { |
| 332 | case doff_u32: |
| 333 | f = debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg, |
| 334 | base + tbl[i].off); |
| 335 | break; |
| 336 | case doff_x32: |
| 337 | f = debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg, |
| 338 | base + tbl[i].off); |
| 339 | break; |
| 340 | case doff_ulong: |
| 341 | f = wil_debugfs_create_ulong(tbl[i].name, tbl[i].mode, |
| 342 | dbg, base + tbl[i].off); |
| 343 | break; |
| 344 | case doff_io32: |
| 345 | f = wil_debugfs_create_iomem_x32(tbl[i].name, |
| 346 | tbl[i].mode, dbg, |
| 347 | base + tbl[i].off); |
| 348 | break; |
Vladimir Kondratiev | 867fa0d | 2014-09-10 16:34:51 +0300 | [diff] [blame] | 349 | default: |
| 350 | f = ERR_PTR(-EINVAL); |
Vladimir Kondratiev | b7cde47 | 2014-08-06 10:31:55 +0300 | [diff] [blame] | 351 | } |
| 352 | if (IS_ERR_OR_NULL(f)) |
| 353 | wil_err(wil, "Create file \"%s\": err %ld\n", |
| 354 | tbl[i].name, PTR_ERR(f)); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | static const struct dbg_off isr_off[] = { |
| 359 | {"ICC", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICC), doff_io32}, |
| 360 | {"ICR", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICR), doff_io32}, |
| 361 | {"ICM", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICM), doff_io32}, |
| 362 | {"ICS", S_IWUSR, offsetof(struct RGF_ICR, ICS), doff_io32}, |
| 363 | {"IMV", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, IMV), doff_io32}, |
| 364 | {"IMS", S_IWUSR, offsetof(struct RGF_ICR, IMS), doff_io32}, |
| 365 | {"IMC", S_IWUSR, offsetof(struct RGF_ICR, IMC), doff_io32}, |
| 366 | {}, |
| 367 | }; |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 368 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 369 | static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil, |
| 370 | const char *name, |
| 371 | struct dentry *parent, u32 off) |
| 372 | { |
| 373 | struct dentry *d = debugfs_create_dir(name, parent); |
| 374 | |
| 375 | if (IS_ERR_OR_NULL(d)) |
| 376 | return -ENODEV; |
| 377 | |
Vladimir Kondratiev | b7cde47 | 2014-08-06 10:31:55 +0300 | [diff] [blame] | 378 | wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off, |
| 379 | isr_off); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 380 | |
| 381 | return 0; |
| 382 | } |
| 383 | |
Vladimir Kondratiev | b7cde47 | 2014-08-06 10:31:55 +0300 | [diff] [blame] | 384 | static const struct dbg_off pseudo_isr_off[] = { |
| 385 | {"CAUSE", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32}, |
| 386 | {"MASK_SW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32}, |
| 387 | {"MASK_FW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32}, |
| 388 | {}, |
| 389 | }; |
| 390 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 391 | static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil, |
| 392 | struct dentry *parent) |
| 393 | { |
| 394 | struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent); |
| 395 | |
| 396 | if (IS_ERR_OR_NULL(d)) |
| 397 | return -ENODEV; |
| 398 | |
Vladimir Kondratiev | b7cde47 | 2014-08-06 10:31:55 +0300 | [diff] [blame] | 399 | wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr, |
| 400 | pseudo_isr_off); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 401 | |
| 402 | return 0; |
| 403 | } |
| 404 | |
Vladimir Kondratiev | 78366f6 | 2014-12-23 09:47:19 +0200 | [diff] [blame] | 405 | static const struct dbg_off lgc_itr_cnt_off[] = { |
Vladimir Kondratiev | b7cde47 | 2014-08-06 10:31:55 +0300 | [diff] [blame] | 406 | {"TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32}, |
| 407 | {"DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32}, |
| 408 | {"CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32}, |
| 409 | {}, |
| 410 | }; |
| 411 | |
Vladimir Kondratiev | 78366f6 | 2014-12-23 09:47:19 +0200 | [diff] [blame] | 412 | static const struct dbg_off tx_itr_cnt_off[] = { |
| 413 | {"TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_CNT_TRSH), |
| 414 | doff_io32}, |
| 415 | {"DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_CNT_DATA), |
| 416 | doff_io32}, |
| 417 | {"CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_CNT_CTL), |
| 418 | doff_io32}, |
| 419 | {"IDL_TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_TRSH), |
| 420 | doff_io32}, |
| 421 | {"IDL_DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_DATA), |
| 422 | doff_io32}, |
| 423 | {"IDL_CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_CTL), |
| 424 | doff_io32}, |
| 425 | {}, |
| 426 | }; |
| 427 | |
| 428 | static const struct dbg_off rx_itr_cnt_off[] = { |
| 429 | {"TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_CNT_TRSH), |
| 430 | doff_io32}, |
| 431 | {"DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_CNT_DATA), |
| 432 | doff_io32}, |
| 433 | {"CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_CNT_CTL), |
| 434 | doff_io32}, |
| 435 | {"IDL_TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_TRSH), |
| 436 | doff_io32}, |
| 437 | {"IDL_DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_DATA), |
| 438 | doff_io32}, |
| 439 | {"IDL_CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_CTL), |
| 440 | doff_io32}, |
| 441 | {}, |
| 442 | }; |
| 443 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 444 | static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil, |
| 445 | struct dentry *parent) |
| 446 | { |
Vladimir Kondratiev | 78366f6 | 2014-12-23 09:47:19 +0200 | [diff] [blame] | 447 | struct dentry *d, *dtx, *drx; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 448 | |
Vladimir Kondratiev | 78366f6 | 2014-12-23 09:47:19 +0200 | [diff] [blame] | 449 | d = debugfs_create_dir("ITR_CNT", parent); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 450 | if (IS_ERR_OR_NULL(d)) |
| 451 | return -ENODEV; |
| 452 | |
Vladimir Kondratiev | 78366f6 | 2014-12-23 09:47:19 +0200 | [diff] [blame] | 453 | dtx = debugfs_create_dir("TX", d); |
| 454 | drx = debugfs_create_dir("RX", d); |
| 455 | if (IS_ERR_OR_NULL(dtx) || IS_ERR_OR_NULL(drx)) |
| 456 | return -ENODEV; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 457 | |
Vladimir Kondratiev | 78366f6 | 2014-12-23 09:47:19 +0200 | [diff] [blame] | 458 | wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr, |
| 459 | lgc_itr_cnt_off); |
| 460 | |
| 461 | wil6210_debugfs_init_offset(wil, dtx, (void * __force)wil->csr, |
| 462 | tx_itr_cnt_off); |
| 463 | |
| 464 | wil6210_debugfs_init_offset(wil, drx, (void * __force)wil->csr, |
| 465 | rx_itr_cnt_off); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | static int wil_memread_debugfs_show(struct seq_file *s, void *data) |
| 470 | { |
| 471 | struct wil6210_priv *wil = s->private; |
| 472 | void __iomem *a = wmi_buffer(wil, cpu_to_le32(mem_addr)); |
| 473 | |
| 474 | if (a) |
Vladimir Kondratiev | b9eeb51 | 2015-07-30 13:52:03 +0300 | [diff] [blame] | 475 | seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, readl(a)); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 476 | else |
| 477 | seq_printf(s, "[0x%08x] = INVALID\n", mem_addr); |
| 478 | |
| 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | static int wil_memread_seq_open(struct inode *inode, struct file *file) |
| 483 | { |
| 484 | return single_open(file, wil_memread_debugfs_show, inode->i_private); |
| 485 | } |
| 486 | |
| 487 | static const struct file_operations fops_memread = { |
| 488 | .open = wil_memread_seq_open, |
| 489 | .release = single_release, |
| 490 | .read = seq_read, |
| 491 | .llseek = seq_lseek, |
| 492 | }; |
| 493 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 494 | static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf, |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 495 | size_t count, loff_t *ppos) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 496 | { |
| 497 | enum { max_count = 4096 }; |
| 498 | struct debugfs_blob_wrapper *blob = file->private_data; |
| 499 | loff_t pos = *ppos; |
| 500 | size_t available = blob->size; |
| 501 | void *buf; |
| 502 | size_t ret; |
| 503 | |
| 504 | if (pos < 0) |
| 505 | return -EINVAL; |
| 506 | |
| 507 | if (pos >= available || !count) |
| 508 | return 0; |
| 509 | |
| 510 | if (count > available - pos) |
| 511 | count = available - pos; |
| 512 | if (count > max_count) |
| 513 | count = max_count; |
| 514 | |
| 515 | buf = kmalloc(count, GFP_KERNEL); |
| 516 | if (!buf) |
| 517 | return -ENOMEM; |
| 518 | |
| 519 | wil_memcpy_fromio_32(buf, (const volatile void __iomem *)blob->data + |
| 520 | pos, count); |
| 521 | |
| 522 | ret = copy_to_user(user_buf, buf, count); |
| 523 | kfree(buf); |
| 524 | if (ret == count) |
| 525 | return -EFAULT; |
| 526 | |
| 527 | count -= ret; |
| 528 | *ppos = pos + count; |
| 529 | |
| 530 | return count; |
| 531 | } |
| 532 | |
| 533 | static const struct file_operations fops_ioblob = { |
| 534 | .read = wil_read_file_ioblob, |
Wei Yongjun | 93ecbd6 | 2013-02-26 10:29:34 +0800 | [diff] [blame] | 535 | .open = simple_open, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 536 | .llseek = default_llseek, |
| 537 | }; |
| 538 | |
| 539 | static |
| 540 | struct dentry *wil_debugfs_create_ioblob(const char *name, |
Al Viro | 0ecc833 | 2013-03-29 12:23:28 -0400 | [diff] [blame] | 541 | umode_t mode, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 542 | struct dentry *parent, |
| 543 | struct debugfs_blob_wrapper *blob) |
| 544 | { |
| 545 | return debugfs_create_file(name, mode, parent, blob, &fops_ioblob); |
| 546 | } |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 547 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 548 | /*---reset---*/ |
| 549 | static ssize_t wil_write_file_reset(struct file *file, const char __user *buf, |
| 550 | size_t len, loff_t *ppos) |
| 551 | { |
| 552 | struct wil6210_priv *wil = file->private_data; |
| 553 | struct net_device *ndev = wil_to_ndev(wil); |
| 554 | |
| 555 | /** |
| 556 | * BUG: |
| 557 | * this code does NOT sync device state with the rest of system |
| 558 | * use with care, debug only!!! |
| 559 | */ |
| 560 | rtnl_lock(); |
| 561 | dev_close(ndev); |
| 562 | ndev->flags &= ~IFF_UP; |
| 563 | rtnl_unlock(); |
Vladimir Kondratiev | 2cd0f02 | 2015-02-15 14:02:30 +0200 | [diff] [blame] | 564 | wil_reset(wil, true); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 565 | |
| 566 | return len; |
| 567 | } |
| 568 | |
| 569 | static const struct file_operations fops_reset = { |
| 570 | .write = wil_write_file_reset, |
Wei Yongjun | 93ecbd6 | 2013-02-26 10:29:34 +0800 | [diff] [blame] | 571 | .open = simple_open, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 572 | }; |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 573 | |
Vladimir Kondratiev | 0b39aaf | 2014-06-16 19:36:59 +0300 | [diff] [blame] | 574 | /*---write channel 1..4 to rxon for it, 0 to rxoff---*/ |
| 575 | static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf, |
| 576 | size_t len, loff_t *ppos) |
| 577 | { |
| 578 | struct wil6210_priv *wil = file->private_data; |
| 579 | int rc; |
| 580 | long channel; |
| 581 | bool on; |
| 582 | |
| 583 | char *kbuf = kmalloc(len + 1, GFP_KERNEL); |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 584 | |
Vladimir Kondratiev | 0b39aaf | 2014-06-16 19:36:59 +0300 | [diff] [blame] | 585 | if (!kbuf) |
| 586 | return -ENOMEM; |
Vladimir Kondratiev | 359ee62 | 2014-07-14 09:49:40 +0300 | [diff] [blame] | 587 | if (copy_from_user(kbuf, buf, len)) { |
| 588 | kfree(kbuf); |
Vladimir Kondratiev | 0b39aaf | 2014-06-16 19:36:59 +0300 | [diff] [blame] | 589 | return -EIO; |
Vladimir Kondratiev | 359ee62 | 2014-07-14 09:49:40 +0300 | [diff] [blame] | 590 | } |
Vladimir Kondratiev | 0b39aaf | 2014-06-16 19:36:59 +0300 | [diff] [blame] | 591 | |
| 592 | kbuf[len] = '\0'; |
| 593 | rc = kstrtol(kbuf, 0, &channel); |
| 594 | kfree(kbuf); |
| 595 | if (rc) |
| 596 | return rc; |
| 597 | |
| 598 | if ((channel < 0) || (channel > 4)) { |
| 599 | wil_err(wil, "Invalid channel %ld\n", channel); |
| 600 | return -EINVAL; |
| 601 | } |
| 602 | on = !!channel; |
| 603 | |
| 604 | if (on) { |
| 605 | rc = wmi_set_channel(wil, (int)channel); |
| 606 | if (rc) |
| 607 | return rc; |
| 608 | } |
| 609 | |
| 610 | rc = wmi_rxon(wil, on); |
| 611 | if (rc) |
| 612 | return rc; |
| 613 | |
| 614 | return len; |
| 615 | } |
| 616 | |
| 617 | static const struct file_operations fops_rxon = { |
| 618 | .write = wil_write_file_rxon, |
| 619 | .open = simple_open, |
| 620 | }; |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 621 | |
Vladimir Kondratiev | 49cb5df | 2014-12-23 09:47:16 +0200 | [diff] [blame] | 622 | /* block ack control, write: |
| 623 | * - "add <ringid> <agg_size> <timeout>" to trigger ADDBA |
| 624 | * - "del_tx <ringid> <reason>" to trigger DELBA for Tx side |
| 625 | * - "del_rx <CID> <TID> <reason>" to trigger DELBA for Rx side |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 626 | */ |
Vladimir Kondratiev | 49cb5df | 2014-12-23 09:47:16 +0200 | [diff] [blame] | 627 | static ssize_t wil_write_back(struct file *file, const char __user *buf, |
| 628 | size_t len, loff_t *ppos) |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 629 | { |
| 630 | struct wil6210_priv *wil = file->private_data; |
| 631 | int rc; |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 632 | char *kbuf = kmalloc(len + 1, GFP_KERNEL); |
Colin Ian King | 2a19f77 | 2015-03-01 17:48:33 +0000 | [diff] [blame] | 633 | char cmd[9]; |
Vladimir Kondratiev | 49cb5df | 2014-12-23 09:47:16 +0200 | [diff] [blame] | 634 | int p1, p2, p3; |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 635 | |
| 636 | if (!kbuf) |
| 637 | return -ENOMEM; |
| 638 | |
| 639 | rc = simple_write_to_buffer(kbuf, len, ppos, buf, len); |
| 640 | if (rc != len) { |
| 641 | kfree(kbuf); |
| 642 | return rc >= 0 ? -EIO : rc; |
| 643 | } |
| 644 | |
| 645 | kbuf[len] = '\0'; |
Vladimir Kondratiev | 49cb5df | 2014-12-23 09:47:16 +0200 | [diff] [blame] | 646 | rc = sscanf(kbuf, "%8s %d %d %d", cmd, &p1, &p2, &p3); |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 647 | kfree(kbuf); |
| 648 | |
Vladimir Kondratiev | 49cb5df | 2014-12-23 09:47:16 +0200 | [diff] [blame] | 649 | if (rc < 0) |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 650 | return rc; |
Vladimir Kondratiev | 49cb5df | 2014-12-23 09:47:16 +0200 | [diff] [blame] | 651 | if (rc < 2) |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 652 | return -EINVAL; |
| 653 | |
Vladimir Kondratiev | 49cb5df | 2014-12-23 09:47:16 +0200 | [diff] [blame] | 654 | if (0 == strcmp(cmd, "add")) { |
| 655 | if (rc < 3) { |
| 656 | wil_err(wil, "BACK: add require at least 2 params\n"); |
| 657 | return -EINVAL; |
| 658 | } |
| 659 | if (rc < 4) |
| 660 | p3 = 0; |
| 661 | wmi_addba(wil, p1, p2, p3); |
| 662 | } else if (0 == strcmp(cmd, "del_tx")) { |
| 663 | if (rc < 3) |
| 664 | p2 = WLAN_REASON_QSTA_LEAVE_QBSS; |
| 665 | wmi_delba_tx(wil, p1, p2); |
| 666 | } else if (0 == strcmp(cmd, "del_rx")) { |
| 667 | if (rc < 3) { |
| 668 | wil_err(wil, |
| 669 | "BACK: del_rx require at least 2 params\n"); |
| 670 | return -EINVAL; |
| 671 | } |
| 672 | if (rc < 4) |
| 673 | p3 = WLAN_REASON_QSTA_LEAVE_QBSS; |
| 674 | wmi_delba_rx(wil, mk_cidxtid(p1, p2), p3); |
| 675 | } else { |
| 676 | wil_err(wil, "BACK: Unrecognized command \"%s\"\n", cmd); |
| 677 | return -EINVAL; |
| 678 | } |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 679 | |
| 680 | return len; |
| 681 | } |
| 682 | |
Vladimir Kondratiev | 49cb5df | 2014-12-23 09:47:16 +0200 | [diff] [blame] | 683 | static ssize_t wil_read_back(struct file *file, char __user *user_buf, |
| 684 | size_t count, loff_t *ppos) |
| 685 | { |
| 686 | static const char text[] = "block ack control, write:\n" |
| 687 | " - \"add <ringid> <agg_size> <timeout>\" to trigger ADDBA\n" |
| 688 | "If missing, <timeout> defaults to 0\n" |
| 689 | " - \"del_tx <ringid> <reason>\" to trigger DELBA for Tx side\n" |
| 690 | " - \"del_rx <CID> <TID> <reason>\" to trigger DELBA for Rx side\n" |
| 691 | "If missing, <reason> set to \"STA_LEAVING\" (36)\n"; |
| 692 | |
| 693 | return simple_read_from_buffer(user_buf, count, ppos, text, |
| 694 | sizeof(text)); |
| 695 | } |
| 696 | |
| 697 | static const struct file_operations fops_back = { |
| 698 | .read = wil_read_back, |
| 699 | .write = wil_write_back, |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 700 | .open = simple_open, |
| 701 | }; |
| 702 | |
Vladimir Kondratiev | dc16427 | 2015-04-30 16:25:09 +0300 | [diff] [blame] | 703 | /* pmc control, write: |
| 704 | * - "alloc <num descriptors> <descriptor_size>" to allocate PMC |
| 705 | * - "free" to release memory allocated for PMC |
| 706 | */ |
| 707 | static ssize_t wil_write_pmccfg(struct file *file, const char __user *buf, |
| 708 | size_t len, loff_t *ppos) |
| 709 | { |
| 710 | struct wil6210_priv *wil = file->private_data; |
| 711 | int rc; |
| 712 | char *kbuf = kmalloc(len + 1, GFP_KERNEL); |
| 713 | char cmd[9]; |
| 714 | int num_descs, desc_size; |
| 715 | |
| 716 | if (!kbuf) |
| 717 | return -ENOMEM; |
| 718 | |
| 719 | rc = simple_write_to_buffer(kbuf, len, ppos, buf, len); |
| 720 | if (rc != len) { |
| 721 | kfree(kbuf); |
| 722 | return rc >= 0 ? -EIO : rc; |
| 723 | } |
| 724 | |
| 725 | kbuf[len] = '\0'; |
| 726 | rc = sscanf(kbuf, "%8s %d %d", cmd, &num_descs, &desc_size); |
| 727 | kfree(kbuf); |
| 728 | |
| 729 | if (rc < 0) |
| 730 | return rc; |
| 731 | |
| 732 | if (rc < 1) { |
| 733 | wil_err(wil, "pmccfg: no params given\n"); |
| 734 | return -EINVAL; |
| 735 | } |
| 736 | |
| 737 | if (0 == strcmp(cmd, "alloc")) { |
| 738 | if (rc != 3) { |
| 739 | wil_err(wil, "pmccfg: alloc requires 2 params\n"); |
| 740 | return -EINVAL; |
| 741 | } |
| 742 | wil_pmc_alloc(wil, num_descs, desc_size); |
| 743 | } else if (0 == strcmp(cmd, "free")) { |
| 744 | if (rc != 1) { |
| 745 | wil_err(wil, "pmccfg: free does not have any params\n"); |
| 746 | return -EINVAL; |
| 747 | } |
| 748 | wil_pmc_free(wil, true); |
| 749 | } else { |
| 750 | wil_err(wil, "pmccfg: Unrecognized command \"%s\"\n", cmd); |
| 751 | return -EINVAL; |
| 752 | } |
| 753 | |
| 754 | return len; |
| 755 | } |
| 756 | |
| 757 | static ssize_t wil_read_pmccfg(struct file *file, char __user *user_buf, |
| 758 | size_t count, loff_t *ppos) |
| 759 | { |
| 760 | struct wil6210_priv *wil = file->private_data; |
| 761 | char text[256]; |
| 762 | char help[] = "pmc control, write:\n" |
| 763 | " - \"alloc <num descriptors> <descriptor_size>\" to allocate pmc\n" |
| 764 | " - \"free\" to free memory allocated for pmc\n"; |
| 765 | |
| 766 | sprintf(text, "Last command status: %d\n\n%s", |
| 767 | wil_pmc_last_cmd_status(wil), |
| 768 | help); |
| 769 | |
| 770 | return simple_read_from_buffer(user_buf, count, ppos, text, |
| 771 | strlen(text) + 1); |
| 772 | } |
| 773 | |
| 774 | static const struct file_operations fops_pmccfg = { |
| 775 | .read = wil_read_pmccfg, |
| 776 | .write = wil_write_pmccfg, |
| 777 | .open = simple_open, |
| 778 | }; |
| 779 | |
| 780 | static const struct file_operations fops_pmcdata = { |
| 781 | .open = simple_open, |
| 782 | .read = wil_pmc_read, |
| 783 | .llseek = wil_pmc_llseek, |
| 784 | }; |
| 785 | |
Vladimir Kondratiev | 0b39aaf | 2014-06-16 19:36:59 +0300 | [diff] [blame] | 786 | /*---tx_mgmt---*/ |
| 787 | /* Write mgmt frame to this file to send it */ |
| 788 | static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf, |
| 789 | size_t len, loff_t *ppos) |
| 790 | { |
| 791 | struct wil6210_priv *wil = file->private_data; |
| 792 | struct wiphy *wiphy = wil_to_wiphy(wil); |
| 793 | struct wireless_dev *wdev = wil_to_wdev(wil); |
| 794 | struct cfg80211_mgmt_tx_params params; |
| 795 | int rc; |
Vladimir Kondratiev | 0b39aaf | 2014-06-16 19:36:59 +0300 | [diff] [blame] | 796 | void *frame = kmalloc(len, GFP_KERNEL); |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 797 | |
Vladimir Kondratiev | 0b39aaf | 2014-06-16 19:36:59 +0300 | [diff] [blame] | 798 | if (!frame) |
| 799 | return -ENOMEM; |
| 800 | |
Lino Sanfilippo | 8e09b7d | 2014-11-28 02:47:19 +0100 | [diff] [blame] | 801 | if (copy_from_user(frame, buf, len)) { |
| 802 | kfree(frame); |
Vladimir Kondratiev | 0b39aaf | 2014-06-16 19:36:59 +0300 | [diff] [blame] | 803 | return -EIO; |
Lino Sanfilippo | 8e09b7d | 2014-11-28 02:47:19 +0100 | [diff] [blame] | 804 | } |
Vladimir Kondratiev | 0b39aaf | 2014-06-16 19:36:59 +0300 | [diff] [blame] | 805 | |
| 806 | params.buf = frame; |
| 807 | params.len = len; |
| 808 | params.chan = wdev->preset_chandef.chan; |
| 809 | |
| 810 | rc = wil_cfg80211_mgmt_tx(wiphy, wdev, ¶ms, NULL); |
| 811 | |
| 812 | kfree(frame); |
| 813 | wil_info(wil, "%s() -> %d\n", __func__, rc); |
| 814 | |
| 815 | return len; |
| 816 | } |
| 817 | |
| 818 | static const struct file_operations fops_txmgmt = { |
| 819 | .write = wil_write_file_txmgmt, |
| 820 | .open = simple_open, |
| 821 | }; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 822 | |
Vladimir Kondratiev | ff974e4 | 2014-06-16 19:37:08 +0300 | [diff] [blame] | 823 | /* Write WMI command (w/o mbox header) to this file to send it |
| 824 | * WMI starts from wil6210_mbox_hdr_wmi header |
| 825 | */ |
| 826 | static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf, |
| 827 | size_t len, loff_t *ppos) |
| 828 | { |
| 829 | struct wil6210_priv *wil = file->private_data; |
| 830 | struct wil6210_mbox_hdr_wmi *wmi; |
| 831 | void *cmd; |
| 832 | int cmdlen = len - sizeof(struct wil6210_mbox_hdr_wmi); |
| 833 | u16 cmdid; |
| 834 | int rc, rc1; |
| 835 | |
| 836 | if (cmdlen <= 0) |
| 837 | return -EINVAL; |
| 838 | |
| 839 | wmi = kmalloc(len, GFP_KERNEL); |
| 840 | if (!wmi) |
| 841 | return -ENOMEM; |
| 842 | |
| 843 | rc = simple_write_to_buffer(wmi, len, ppos, buf, len); |
Lino Sanfilippo | 8e09b7d | 2014-11-28 02:47:19 +0100 | [diff] [blame] | 844 | if (rc < 0) { |
| 845 | kfree(wmi); |
Vladimir Kondratiev | ff974e4 | 2014-06-16 19:37:08 +0300 | [diff] [blame] | 846 | return rc; |
Lino Sanfilippo | 8e09b7d | 2014-11-28 02:47:19 +0100 | [diff] [blame] | 847 | } |
Vladimir Kondratiev | ff974e4 | 2014-06-16 19:37:08 +0300 | [diff] [blame] | 848 | |
| 849 | cmd = &wmi[1]; |
| 850 | cmdid = le16_to_cpu(wmi->id); |
| 851 | |
| 852 | rc1 = wmi_send(wil, cmdid, cmd, cmdlen); |
| 853 | kfree(wmi); |
| 854 | |
| 855 | wil_info(wil, "%s(0x%04x[%d]) -> %d\n", __func__, cmdid, cmdlen, rc1); |
| 856 | |
| 857 | return rc; |
| 858 | } |
| 859 | |
| 860 | static const struct file_operations fops_wmi = { |
| 861 | .write = wil_write_file_wmi, |
| 862 | .open = simple_open, |
| 863 | }; |
| 864 | |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 865 | static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb) |
| 866 | { |
| 867 | int i = 0; |
| 868 | int len = skb_headlen(skb); |
| 869 | void *p = skb->data; |
| 870 | int nr_frags = skb_shinfo(skb)->nr_frags; |
| 871 | |
| 872 | seq_printf(s, " len = %d\n", len); |
| 873 | wil_seq_hexdump(s, p, len, " : "); |
| 874 | |
| 875 | if (nr_frags) { |
| 876 | seq_printf(s, " nr_frags = %d\n", nr_frags); |
| 877 | for (i = 0; i < nr_frags; i++) { |
| 878 | const struct skb_frag_struct *frag = |
| 879 | &skb_shinfo(skb)->frags[i]; |
| 880 | |
| 881 | len = skb_frag_size(frag); |
| 882 | p = skb_frag_address_safe(frag); |
| 883 | seq_printf(s, " [%2d] : len = %d\n", i, len); |
| 884 | wil_seq_hexdump(s, p, len, " : "); |
| 885 | } |
| 886 | } |
| 887 | } |
| 888 | |
Vladimir Kondratiev | 3a85543e | 2014-02-27 16:20:41 +0200 | [diff] [blame] | 889 | /*---------Tx/Rx descriptor------------*/ |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 890 | static int wil_txdesc_debugfs_show(struct seq_file *s, void *data) |
| 891 | { |
| 892 | struct wil6210_priv *wil = s->private; |
Vladimir Kondratiev | 3a85543e | 2014-02-27 16:20:41 +0200 | [diff] [blame] | 893 | struct vring *vring; |
Vladimir Kondratiev | af31cb5 | 2014-03-02 11:20:50 +0200 | [diff] [blame] | 894 | bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS); |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 895 | |
| 896 | vring = tx ? &wil->vring_tx[dbg_vring_index] : &wil->vring_rx; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 897 | |
| 898 | if (!vring->va) { |
Vladimir Kondratiev | af31cb5 | 2014-03-02 11:20:50 +0200 | [diff] [blame] | 899 | if (tx) |
Vladimir Kondratiev | 3a85543e | 2014-02-27 16:20:41 +0200 | [diff] [blame] | 900 | seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index); |
| 901 | else |
| 902 | seq_puts(s, "No Rx VRING\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 903 | return 0; |
| 904 | } |
| 905 | |
| 906 | if (dbg_txdesc_index < vring->size) { |
Vladimir Kondratiev | 3a85543e | 2014-02-27 16:20:41 +0200 | [diff] [blame] | 907 | /* use struct vring_tx_desc for Rx as well, |
| 908 | * only field used, .dma.length, is the same |
| 909 | */ |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 910 | volatile struct vring_tx_desc *d = |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 911 | &vring->va[dbg_txdesc_index].tx; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 912 | volatile u32 *u = (volatile u32 *)d; |
Vladimir Kondratiev | f88f113 | 2013-07-11 18:03:40 +0300 | [diff] [blame] | 913 | struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 914 | |
Vladimir Kondratiev | af31cb5 | 2014-03-02 11:20:50 +0200 | [diff] [blame] | 915 | if (tx) |
Vladimir Kondratiev | 3a85543e | 2014-02-27 16:20:41 +0200 | [diff] [blame] | 916 | seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index, |
| 917 | dbg_txdesc_index); |
| 918 | else |
| 919 | seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 920 | seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n", |
| 921 | u[0], u[1], u[2], u[3]); |
| 922 | seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n", |
| 923 | u[4], u[5], u[6], u[7]); |
Vladimir Kondratiev | 39c52ee | 2014-05-27 14:45:49 +0300 | [diff] [blame] | 924 | seq_printf(s, " SKB = 0x%p\n", skb); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 925 | |
| 926 | if (skb) { |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 927 | skb_get(skb); |
| 928 | wil_seq_print_skb(s, skb); |
| 929 | kfree_skb(skb); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 930 | } |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 931 | seq_puts(s, "}\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 932 | } else { |
Vladimir Kondratiev | af31cb5 | 2014-03-02 11:20:50 +0200 | [diff] [blame] | 933 | if (tx) |
Vladimir Kondratiev | 3a85543e | 2014-02-27 16:20:41 +0200 | [diff] [blame] | 934 | seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n", |
| 935 | dbg_vring_index, dbg_txdesc_index, |
| 936 | vring->size); |
| 937 | else |
| 938 | seq_printf(s, "RxDesc index (%d) >= size (%d)\n", |
| 939 | dbg_txdesc_index, vring->size); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | return 0; |
| 943 | } |
| 944 | |
| 945 | static int wil_txdesc_seq_open(struct inode *inode, struct file *file) |
| 946 | { |
| 947 | return single_open(file, wil_txdesc_debugfs_show, inode->i_private); |
| 948 | } |
| 949 | |
| 950 | static const struct file_operations fops_txdesc = { |
| 951 | .open = wil_txdesc_seq_open, |
| 952 | .release = single_release, |
| 953 | .read = seq_read, |
| 954 | .llseek = seq_lseek, |
| 955 | }; |
| 956 | |
| 957 | /*---------beamforming------------*/ |
Vladimir Kondratiev | 36345ac | 2014-08-06 10:31:56 +0300 | [diff] [blame] | 958 | static char *wil_bfstatus_str(u32 status) |
| 959 | { |
| 960 | switch (status) { |
| 961 | case 0: |
| 962 | return "Failed"; |
| 963 | case 1: |
| 964 | return "OK"; |
| 965 | case 2: |
| 966 | return "Retrying"; |
| 967 | default: |
| 968 | return "??"; |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | static bool is_all_zeros(void * const x_, size_t sz) |
| 973 | { |
| 974 | /* if reply is all-0, ignore this CID */ |
| 975 | u32 *x = x_; |
| 976 | int n; |
| 977 | |
| 978 | for (n = 0; n < sz / sizeof(*x); n++) |
| 979 | if (x[n]) |
| 980 | return false; |
| 981 | |
| 982 | return true; |
| 983 | } |
| 984 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 985 | static int wil_bf_debugfs_show(struct seq_file *s, void *data) |
| 986 | { |
Vladimir Kondratiev | 36345ac | 2014-08-06 10:31:56 +0300 | [diff] [blame] | 987 | int rc; |
| 988 | int i; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 989 | struct wil6210_priv *wil = s->private; |
Vladimir Kondratiev | 36345ac | 2014-08-06 10:31:56 +0300 | [diff] [blame] | 990 | struct wmi_notify_req_cmd cmd = { |
| 991 | .interval_usec = 0, |
| 992 | }; |
| 993 | struct { |
| 994 | struct wil6210_mbox_hdr_wmi wmi; |
| 995 | struct wmi_notify_req_done_event evt; |
| 996 | } __packed reply; |
| 997 | |
| 998 | for (i = 0; i < ARRAY_SIZE(wil->sta); i++) { |
| 999 | u32 status; |
| 1000 | |
| 1001 | cmd.cid = i; |
| 1002 | rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd), |
| 1003 | WMI_NOTIFY_REQ_DONE_EVENTID, &reply, |
| 1004 | sizeof(reply), 20); |
| 1005 | /* if reply is all-0, ignore this CID */ |
| 1006 | if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt))) |
| 1007 | continue; |
| 1008 | |
| 1009 | status = le32_to_cpu(reply.evt.status); |
| 1010 | seq_printf(s, "CID %d {\n" |
| 1011 | " TSF = 0x%016llx\n" |
| 1012 | " TxMCS = %2d TxTpt = %4d\n" |
| 1013 | " SQI = %4d\n" |
| 1014 | " Status = 0x%08x %s\n" |
| 1015 | " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n" |
| 1016 | " Goodput(rx:tx) %4d:%4d\n" |
| 1017 | "}\n", |
| 1018 | i, |
| 1019 | le64_to_cpu(reply.evt.tsf), |
| 1020 | le16_to_cpu(reply.evt.bf_mcs), |
| 1021 | le32_to_cpu(reply.evt.tx_tpt), |
| 1022 | reply.evt.sqi, |
| 1023 | status, wil_bfstatus_str(status), |
| 1024 | le16_to_cpu(reply.evt.my_rx_sector), |
| 1025 | le16_to_cpu(reply.evt.my_tx_sector), |
| 1026 | le16_to_cpu(reply.evt.other_rx_sector), |
| 1027 | le16_to_cpu(reply.evt.other_tx_sector), |
| 1028 | le32_to_cpu(reply.evt.rx_goodput), |
| 1029 | le32_to_cpu(reply.evt.tx_goodput)); |
| 1030 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1031 | return 0; |
| 1032 | } |
| 1033 | |
| 1034 | static int wil_bf_seq_open(struct inode *inode, struct file *file) |
| 1035 | { |
| 1036 | return single_open(file, wil_bf_debugfs_show, inode->i_private); |
| 1037 | } |
| 1038 | |
| 1039 | static const struct file_operations fops_bf = { |
| 1040 | .open = wil_bf_seq_open, |
| 1041 | .release = single_release, |
| 1042 | .read = seq_read, |
| 1043 | .llseek = seq_lseek, |
| 1044 | }; |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 1045 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1046 | /*---------SSID------------*/ |
| 1047 | static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf, |
| 1048 | size_t count, loff_t *ppos) |
| 1049 | { |
| 1050 | struct wil6210_priv *wil = file->private_data; |
| 1051 | struct wireless_dev *wdev = wil_to_wdev(wil); |
| 1052 | |
| 1053 | return simple_read_from_buffer(user_buf, count, ppos, |
| 1054 | wdev->ssid, wdev->ssid_len); |
| 1055 | } |
| 1056 | |
| 1057 | static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf, |
| 1058 | size_t count, loff_t *ppos) |
| 1059 | { |
| 1060 | struct wil6210_priv *wil = file->private_data; |
| 1061 | struct wireless_dev *wdev = wil_to_wdev(wil); |
| 1062 | struct net_device *ndev = wil_to_ndev(wil); |
| 1063 | |
| 1064 | if (*ppos != 0) { |
| 1065 | wil_err(wil, "Unable to set SSID substring from [%d]\n", |
| 1066 | (int)*ppos); |
| 1067 | return -EINVAL; |
| 1068 | } |
| 1069 | |
| 1070 | if (count > sizeof(wdev->ssid)) { |
| 1071 | wil_err(wil, "SSID too long, len = %d\n", (int)count); |
| 1072 | return -EINVAL; |
| 1073 | } |
| 1074 | if (netif_running(ndev)) { |
| 1075 | wil_err(wil, "Unable to change SSID on running interface\n"); |
| 1076 | return -EINVAL; |
| 1077 | } |
| 1078 | |
| 1079 | wdev->ssid_len = count; |
| 1080 | return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos, |
| 1081 | buf, count); |
| 1082 | } |
| 1083 | |
| 1084 | static const struct file_operations fops_ssid = { |
| 1085 | .read = wil_read_file_ssid, |
| 1086 | .write = wil_write_file_ssid, |
Wei Yongjun | 93ecbd6 | 2013-02-26 10:29:34 +0800 | [diff] [blame] | 1087 | .open = simple_open, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1088 | }; |
| 1089 | |
Vladimir Kondratiev | 1a2780e | 2013-03-13 14:12:51 +0200 | [diff] [blame] | 1090 | /*---------temp------------*/ |
| 1091 | static void print_temp(struct seq_file *s, const char *prefix, u32 t) |
| 1092 | { |
| 1093 | switch (t) { |
| 1094 | case 0: |
| 1095 | case ~(u32)0: |
| 1096 | seq_printf(s, "%s N/A\n", prefix); |
| 1097 | break; |
| 1098 | default: |
| 1099 | seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000); |
| 1100 | break; |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | static int wil_temp_debugfs_show(struct seq_file *s, void *data) |
| 1105 | { |
| 1106 | struct wil6210_priv *wil = s->private; |
| 1107 | u32 t_m, t_r; |
Vladimir Kondratiev | 1a2780e | 2013-03-13 14:12:51 +0200 | [diff] [blame] | 1108 | int rc = wmi_get_temperature(wil, &t_m, &t_r); |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 1109 | |
Vladimir Kondratiev | 1a2780e | 2013-03-13 14:12:51 +0200 | [diff] [blame] | 1110 | if (rc) { |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 1111 | seq_puts(s, "Failed\n"); |
Vladimir Kondratiev | 1a2780e | 2013-03-13 14:12:51 +0200 | [diff] [blame] | 1112 | return 0; |
| 1113 | } |
| 1114 | |
Vladimir Kondratiev | d45cff9 | 2014-06-16 19:37:12 +0300 | [diff] [blame] | 1115 | print_temp(s, "T_mac =", t_m); |
| 1116 | print_temp(s, "T_radio =", t_r); |
Vladimir Kondratiev | 1a2780e | 2013-03-13 14:12:51 +0200 | [diff] [blame] | 1117 | |
| 1118 | return 0; |
| 1119 | } |
| 1120 | |
| 1121 | static int wil_temp_seq_open(struct inode *inode, struct file *file) |
| 1122 | { |
| 1123 | return single_open(file, wil_temp_debugfs_show, inode->i_private); |
| 1124 | } |
| 1125 | |
| 1126 | static const struct file_operations fops_temp = { |
| 1127 | .open = wil_temp_seq_open, |
| 1128 | .release = single_release, |
| 1129 | .read = seq_read, |
| 1130 | .llseek = seq_lseek, |
| 1131 | }; |
| 1132 | |
Vladimir Kondratiev | 9eb82d4 | 2014-06-16 19:37:13 +0300 | [diff] [blame] | 1133 | /*---------freq------------*/ |
| 1134 | static int wil_freq_debugfs_show(struct seq_file *s, void *data) |
| 1135 | { |
| 1136 | struct wil6210_priv *wil = s->private; |
| 1137 | struct wireless_dev *wdev = wil_to_wdev(wil); |
| 1138 | u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0; |
| 1139 | |
| 1140 | seq_printf(s, "Freq = %d\n", freq); |
| 1141 | |
| 1142 | return 0; |
| 1143 | } |
| 1144 | |
| 1145 | static int wil_freq_seq_open(struct inode *inode, struct file *file) |
| 1146 | { |
| 1147 | return single_open(file, wil_freq_debugfs_show, inode->i_private); |
| 1148 | } |
| 1149 | |
| 1150 | static const struct file_operations fops_freq = { |
| 1151 | .open = wil_freq_seq_open, |
| 1152 | .release = single_release, |
| 1153 | .read = seq_read, |
| 1154 | .llseek = seq_lseek, |
| 1155 | }; |
| 1156 | |
| 1157 | /*---------link------------*/ |
| 1158 | static int wil_link_debugfs_show(struct seq_file *s, void *data) |
| 1159 | { |
| 1160 | struct wil6210_priv *wil = s->private; |
| 1161 | struct station_info sinfo; |
| 1162 | int i, rc; |
| 1163 | |
| 1164 | for (i = 0; i < ARRAY_SIZE(wil->sta); i++) { |
| 1165 | struct wil_sta_info *p = &wil->sta[i]; |
| 1166 | char *status = "unknown"; |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 1167 | |
Vladimir Kondratiev | 9eb82d4 | 2014-06-16 19:37:13 +0300 | [diff] [blame] | 1168 | switch (p->status) { |
| 1169 | case wil_sta_unused: |
| 1170 | status = "unused "; |
| 1171 | break; |
| 1172 | case wil_sta_conn_pending: |
| 1173 | status = "pending "; |
| 1174 | break; |
| 1175 | case wil_sta_connected: |
| 1176 | status = "connected"; |
| 1177 | break; |
| 1178 | } |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 1179 | seq_printf(s, "[%d] %pM %s\n", i, p->addr, status); |
Vladimir Kondratiev | 9eb82d4 | 2014-06-16 19:37:13 +0300 | [diff] [blame] | 1180 | |
| 1181 | if (p->status == wil_sta_connected) { |
| 1182 | rc = wil_cid_fill_sinfo(wil, i, &sinfo); |
| 1183 | if (rc) |
| 1184 | return rc; |
| 1185 | |
| 1186 | seq_printf(s, " Tx_mcs = %d\n", sinfo.txrate.mcs); |
| 1187 | seq_printf(s, " Rx_mcs = %d\n", sinfo.rxrate.mcs); |
| 1188 | seq_printf(s, " SQ = %d\n", sinfo.signal); |
| 1189 | } |
| 1190 | } |
| 1191 | |
| 1192 | return 0; |
| 1193 | } |
| 1194 | |
| 1195 | static int wil_link_seq_open(struct inode *inode, struct file *file) |
| 1196 | { |
| 1197 | return single_open(file, wil_link_debugfs_show, inode->i_private); |
| 1198 | } |
| 1199 | |
| 1200 | static const struct file_operations fops_link = { |
| 1201 | .open = wil_link_seq_open, |
| 1202 | .release = single_release, |
| 1203 | .read = seq_read, |
| 1204 | .llseek = seq_lseek, |
| 1205 | }; |
| 1206 | |
Vladimir Kondratiev | 84bb29b | 2014-06-16 19:37:21 +0300 | [diff] [blame] | 1207 | /*---------info------------*/ |
| 1208 | static int wil_info_debugfs_show(struct seq_file *s, void *data) |
| 1209 | { |
Vladimir Kondratiev | be29985 | 2014-06-16 19:37:22 +0300 | [diff] [blame] | 1210 | struct wil6210_priv *wil = s->private; |
| 1211 | struct net_device *ndev = wil_to_ndev(wil); |
Vladimir Kondratiev | 84bb29b | 2014-06-16 19:37:21 +0300 | [diff] [blame] | 1212 | int is_ac = power_supply_is_system_supplied(); |
Vladimir Kondratiev | be29985 | 2014-06-16 19:37:22 +0300 | [diff] [blame] | 1213 | int rx = atomic_xchg(&wil->isr_count_rx, 0); |
| 1214 | int tx = atomic_xchg(&wil->isr_count_tx, 0); |
| 1215 | static ulong rxf_old, txf_old; |
| 1216 | ulong rxf = ndev->stats.rx_packets; |
| 1217 | ulong txf = ndev->stats.tx_packets; |
Vladimir Kondratiev | 55f8f68 | 2014-06-16 19:37:23 +0300 | [diff] [blame] | 1218 | unsigned int i; |
Vladimir Kondratiev | 84bb29b | 2014-06-16 19:37:21 +0300 | [diff] [blame] | 1219 | |
| 1220 | /* >0 : AC; 0 : battery; <0 : error */ |
| 1221 | seq_printf(s, "AC powered : %d\n", is_ac); |
Vladimir Kondratiev | be29985 | 2014-06-16 19:37:22 +0300 | [diff] [blame] | 1222 | seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old); |
| 1223 | seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old); |
| 1224 | rxf_old = rxf; |
| 1225 | txf_old = txf; |
Vladimir Kondratiev | 84bb29b | 2014-06-16 19:37:21 +0300 | [diff] [blame] | 1226 | |
Vladimir Kondratiev | 55f8f68 | 2014-06-16 19:37:23 +0300 | [diff] [blame] | 1227 | #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \ |
| 1228 | " " __stringify(x) : "" |
| 1229 | |
| 1230 | for (i = 0; i < ndev->num_tx_queues; i++) { |
| 1231 | struct netdev_queue *txq = netdev_get_tx_queue(ndev, i); |
| 1232 | unsigned long state = txq->state; |
| 1233 | |
| 1234 | seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state, |
| 1235 | CHECK_QSTATE(DRV_XOFF), |
| 1236 | CHECK_QSTATE(STACK_XOFF), |
| 1237 | CHECK_QSTATE(FROZEN) |
| 1238 | ); |
| 1239 | } |
| 1240 | #undef CHECK_QSTATE |
Vladimir Kondratiev | 84bb29b | 2014-06-16 19:37:21 +0300 | [diff] [blame] | 1241 | return 0; |
| 1242 | } |
| 1243 | |
| 1244 | static int wil_info_seq_open(struct inode *inode, struct file *file) |
| 1245 | { |
| 1246 | return single_open(file, wil_info_debugfs_show, inode->i_private); |
| 1247 | } |
| 1248 | |
| 1249 | static const struct file_operations fops_info = { |
| 1250 | .open = wil_info_seq_open, |
| 1251 | .release = single_release, |
| 1252 | .read = seq_read, |
| 1253 | .llseek = seq_lseek, |
| 1254 | }; |
| 1255 | |
Vladimir Kondratiev | c33407a | 2014-10-01 15:05:24 +0300 | [diff] [blame] | 1256 | /*---------recovery------------*/ |
| 1257 | /* mode = [manual|auto] |
| 1258 | * state = [idle|pending|running] |
| 1259 | */ |
| 1260 | static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf, |
| 1261 | size_t count, loff_t *ppos) |
| 1262 | { |
| 1263 | struct wil6210_priv *wil = file->private_data; |
| 1264 | char buf[80]; |
| 1265 | int n; |
| 1266 | static const char * const sstate[] = {"idle", "pending", "running"}; |
| 1267 | |
| 1268 | n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n", |
| 1269 | no_fw_recovery ? "manual" : "auto", |
| 1270 | sstate[wil->recovery_state]); |
| 1271 | |
| 1272 | n = min_t(int, n, sizeof(buf)); |
| 1273 | |
| 1274 | return simple_read_from_buffer(user_buf, count, ppos, |
| 1275 | buf, n); |
| 1276 | } |
| 1277 | |
| 1278 | static ssize_t wil_write_file_recovery(struct file *file, |
| 1279 | const char __user *buf_, |
| 1280 | size_t count, loff_t *ppos) |
| 1281 | { |
| 1282 | struct wil6210_priv *wil = file->private_data; |
| 1283 | static const char run_command[] = "run"; |
| 1284 | char buf[sizeof(run_command) + 1]; /* to detect "runx" */ |
| 1285 | ssize_t rc; |
| 1286 | |
| 1287 | if (wil->recovery_state != fw_recovery_pending) { |
| 1288 | wil_err(wil, "No recovery pending\n"); |
| 1289 | return -EINVAL; |
| 1290 | } |
| 1291 | |
| 1292 | if (*ppos != 0) { |
| 1293 | wil_err(wil, "Offset [%d]\n", (int)*ppos); |
| 1294 | return -EINVAL; |
| 1295 | } |
| 1296 | |
| 1297 | if (count > sizeof(buf)) { |
| 1298 | wil_err(wil, "Input too long, len = %d\n", (int)count); |
| 1299 | return -EINVAL; |
| 1300 | } |
| 1301 | |
| 1302 | rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count); |
| 1303 | if (rc < 0) |
| 1304 | return rc; |
| 1305 | |
| 1306 | buf[rc] = '\0'; |
| 1307 | if (0 == strcmp(buf, run_command)) |
| 1308 | wil_set_recovery_state(wil, fw_recovery_running); |
| 1309 | else |
| 1310 | wil_err(wil, "Bad recovery command \"%s\"\n", buf); |
| 1311 | |
| 1312 | return rc; |
| 1313 | } |
| 1314 | |
| 1315 | static const struct file_operations fops_recovery = { |
| 1316 | .read = wil_read_file_recovery, |
| 1317 | .write = wil_write_file_recovery, |
| 1318 | .open = simple_open, |
| 1319 | }; |
| 1320 | |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 1321 | /*---------Station matrix------------*/ |
Vladimir Kondratiev | b4490f4 | 2014-02-27 16:20:44 +0200 | [diff] [blame] | 1322 | static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r) |
| 1323 | { |
| 1324 | int i; |
| 1325 | u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size; |
Vladimir Kondratiev | 91a8edc | 2015-07-30 13:52:01 +0300 | [diff] [blame] | 1326 | unsigned long long drop_dup = r->drop_dup, drop_old = r->drop_old; |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 1327 | |
Vladimir Kondratiev | 56637e7 | 2014-12-23 09:47:06 +0200 | [diff] [blame] | 1328 | seq_printf(s, "([%2d] %3d TU) 0x%03x [", r->buf_size, r->timeout, |
| 1329 | r->head_seq_num); |
Vladimir Kondratiev | b4490f4 | 2014-02-27 16:20:44 +0200 | [diff] [blame] | 1330 | for (i = 0; i < r->buf_size; i++) { |
| 1331 | if (i == index) |
| 1332 | seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|'); |
| 1333 | else |
| 1334 | seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_'); |
| 1335 | } |
Vladimir Kondratiev | 91a8edc | 2015-07-30 13:52:01 +0300 | [diff] [blame] | 1336 | seq_printf(s, |
| 1337 | "] total %llu drop %llu (dup %llu + old %llu) last 0x%03x\n", |
| 1338 | r->total, drop_dup + drop_old, drop_dup, drop_old, |
| 1339 | r->ssn_last_drop); |
Vladimir Kondratiev | b4490f4 | 2014-02-27 16:20:44 +0200 | [diff] [blame] | 1340 | } |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 1341 | |
| 1342 | static int wil_sta_debugfs_show(struct seq_file *s, void *data) |
Vladimir Kondratiev | bd33273 | 2014-12-23 09:47:24 +0200 | [diff] [blame] | 1343 | __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock) |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 1344 | { |
| 1345 | struct wil6210_priv *wil = s->private; |
Vladimir Kondratiev | c4a110d | 2015-06-09 14:11:18 +0300 | [diff] [blame] | 1346 | int i, tid, mcs; |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 1347 | |
| 1348 | for (i = 0; i < ARRAY_SIZE(wil->sta); i++) { |
| 1349 | struct wil_sta_info *p = &wil->sta[i]; |
| 1350 | char *status = "unknown"; |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 1351 | |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 1352 | switch (p->status) { |
| 1353 | case wil_sta_unused: |
| 1354 | status = "unused "; |
| 1355 | break; |
| 1356 | case wil_sta_conn_pending: |
| 1357 | status = "pending "; |
| 1358 | break; |
| 1359 | case wil_sta_connected: |
| 1360 | status = "connected"; |
| 1361 | break; |
| 1362 | } |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 1363 | seq_printf(s, "[%d] %pM %s\n", i, p->addr, status); |
Vladimir Kondratiev | b4490f4 | 2014-02-27 16:20:44 +0200 | [diff] [blame] | 1364 | |
| 1365 | if (p->status == wil_sta_connected) { |
Vladimir Kondratiev | bd33273 | 2014-12-23 09:47:24 +0200 | [diff] [blame] | 1366 | spin_lock_bh(&p->tid_rx_lock); |
Vladimir Kondratiev | b4490f4 | 2014-02-27 16:20:44 +0200 | [diff] [blame] | 1367 | for (tid = 0; tid < WIL_STA_TID_NUM; tid++) { |
| 1368 | struct wil_tid_ampdu_rx *r = p->tid_rx[tid]; |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 1369 | |
Vladimir Kondratiev | b4490f4 | 2014-02-27 16:20:44 +0200 | [diff] [blame] | 1370 | if (r) { |
| 1371 | seq_printf(s, "[%2d] ", tid); |
| 1372 | wil_print_rxtid(s, r); |
| 1373 | } |
| 1374 | } |
Vladimir Kondratiev | bd33273 | 2014-12-23 09:47:24 +0200 | [diff] [blame] | 1375 | spin_unlock_bh(&p->tid_rx_lock); |
Vladimir Kondratiev | 3b282bc | 2015-10-04 10:23:19 +0300 | [diff] [blame] | 1376 | seq_printf(s, |
| 1377 | "Rx invalid frame: non-data %lu, short %lu, large %lu\n", |
| 1378 | p->stats.rx_non_data_frame, |
| 1379 | p->stats.rx_short_frame, |
| 1380 | p->stats.rx_large_frame); |
| 1381 | |
Vladimir Kondratiev | c4a110d | 2015-06-09 14:11:18 +0300 | [diff] [blame] | 1382 | seq_puts(s, "Rx/MCS:"); |
| 1383 | for (mcs = 0; mcs < ARRAY_SIZE(p->stats.rx_per_mcs); |
| 1384 | mcs++) |
| 1385 | seq_printf(s, " %lld", |
| 1386 | p->stats.rx_per_mcs[mcs]); |
| 1387 | seq_puts(s, "\n"); |
Vladimir Kondratiev | b4490f4 | 2014-02-27 16:20:44 +0200 | [diff] [blame] | 1388 | } |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | return 0; |
| 1392 | } |
| 1393 | |
| 1394 | static int wil_sta_seq_open(struct inode *inode, struct file *file) |
| 1395 | { |
| 1396 | return single_open(file, wil_sta_debugfs_show, inode->i_private); |
| 1397 | } |
| 1398 | |
| 1399 | static const struct file_operations fops_sta = { |
| 1400 | .open = wil_sta_seq_open, |
| 1401 | .release = single_release, |
| 1402 | .read = seq_read, |
| 1403 | .llseek = seq_lseek, |
| 1404 | }; |
| 1405 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1406 | /*----------------*/ |
Vladimir Kondratiev | b541d0a | 2014-07-14 09:49:41 +0300 | [diff] [blame] | 1407 | static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil, |
| 1408 | struct dentry *dbg) |
| 1409 | { |
| 1410 | int i; |
| 1411 | char name[32]; |
| 1412 | |
| 1413 | for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) { |
| 1414 | struct debugfs_blob_wrapper *blob = &wil->blobs[i]; |
| 1415 | const struct fw_map *map = &fw_mapping[i]; |
| 1416 | |
| 1417 | if (!map->name) |
| 1418 | continue; |
| 1419 | |
| 1420 | blob->data = (void * __force)wil->csr + HOSTADDR(map->host); |
| 1421 | blob->size = map->to - map->from; |
| 1422 | snprintf(name, sizeof(name), "blob_%s", map->name); |
| 1423 | wil_debugfs_create_ioblob(name, S_IRUGO, dbg, blob); |
| 1424 | } |
| 1425 | } |
| 1426 | |
Vladimir Kondratiev | b7cde47 | 2014-08-06 10:31:55 +0300 | [diff] [blame] | 1427 | /* misc files */ |
| 1428 | static const struct { |
| 1429 | const char *name; |
| 1430 | umode_t mode; |
| 1431 | const struct file_operations *fops; |
| 1432 | } dbg_files[] = { |
| 1433 | {"mbox", S_IRUGO, &fops_mbox}, |
| 1434 | {"vrings", S_IRUGO, &fops_vring}, |
| 1435 | {"stations", S_IRUGO, &fops_sta}, |
| 1436 | {"desc", S_IRUGO, &fops_txdesc}, |
| 1437 | {"bf", S_IRUGO, &fops_bf}, |
| 1438 | {"ssid", S_IRUGO | S_IWUSR, &fops_ssid}, |
| 1439 | {"mem_val", S_IRUGO, &fops_memread}, |
| 1440 | {"reset", S_IWUSR, &fops_reset}, |
| 1441 | {"rxon", S_IWUSR, &fops_rxon}, |
| 1442 | {"tx_mgmt", S_IWUSR, &fops_txmgmt}, |
| 1443 | {"wmi_send", S_IWUSR, &fops_wmi}, |
Vladimir Kondratiev | 49cb5df | 2014-12-23 09:47:16 +0200 | [diff] [blame] | 1444 | {"back", S_IRUGO | S_IWUSR, &fops_back}, |
Vladimir Kondratiev | dc16427 | 2015-04-30 16:25:09 +0300 | [diff] [blame] | 1445 | {"pmccfg", S_IRUGO | S_IWUSR, &fops_pmccfg}, |
| 1446 | {"pmcdata", S_IRUGO, &fops_pmcdata}, |
Vladimir Kondratiev | b7cde47 | 2014-08-06 10:31:55 +0300 | [diff] [blame] | 1447 | {"temp", S_IRUGO, &fops_temp}, |
| 1448 | {"freq", S_IRUGO, &fops_freq}, |
| 1449 | {"link", S_IRUGO, &fops_link}, |
| 1450 | {"info", S_IRUGO, &fops_info}, |
Vladimir Kondratiev | c33407a | 2014-10-01 15:05:24 +0300 | [diff] [blame] | 1451 | {"recovery", S_IRUGO | S_IWUSR, &fops_recovery}, |
Vladimir Kondratiev | b7cde47 | 2014-08-06 10:31:55 +0300 | [diff] [blame] | 1452 | }; |
| 1453 | |
| 1454 | static void wil6210_debugfs_init_files(struct wil6210_priv *wil, |
| 1455 | struct dentry *dbg) |
| 1456 | { |
| 1457 | int i; |
| 1458 | |
| 1459 | for (i = 0; i < ARRAY_SIZE(dbg_files); i++) |
| 1460 | debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg, |
| 1461 | wil, dbg_files[i].fops); |
| 1462 | } |
| 1463 | |
| 1464 | /* interrupt control blocks */ |
| 1465 | static const struct { |
| 1466 | const char *name; |
| 1467 | u32 icr_off; |
| 1468 | } dbg_icr[] = { |
| 1469 | {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)}, |
| 1470 | {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)}, |
| 1471 | {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)}, |
| 1472 | {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)}, |
| 1473 | }; |
| 1474 | |
| 1475 | static void wil6210_debugfs_init_isr(struct wil6210_priv *wil, |
| 1476 | struct dentry *dbg) |
| 1477 | { |
| 1478 | int i; |
| 1479 | |
| 1480 | for (i = 0; i < ARRAY_SIZE(dbg_icr); i++) |
| 1481 | wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg, |
| 1482 | dbg_icr[i].icr_off); |
| 1483 | } |
| 1484 | |
| 1485 | #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \ |
| 1486 | offsetof(struct wil6210_priv, name), type} |
| 1487 | |
| 1488 | /* fields in struct wil6210_priv */ |
| 1489 | static const struct dbg_off dbg_wil_off[] = { |
Vladimir Kondratiev | 774974e | 2015-02-15 14:02:36 +0200 | [diff] [blame] | 1490 | WIL_FIELD(privacy, S_IRUGO, doff_u32), |
Vladimir Kondratiev | 9419b6a | 2014-12-23 09:47:14 +0200 | [diff] [blame] | 1491 | WIL_FIELD(status[0], S_IRUGO | S_IWUSR, doff_ulong), |
Vladimir Kondratiev | b7cde47 | 2014-08-06 10:31:55 +0300 | [diff] [blame] | 1492 | WIL_FIELD(fw_version, S_IRUGO, doff_u32), |
| 1493 | WIL_FIELD(hw_version, S_IRUGO, doff_x32), |
Vladimir Kondratiev | c33407a | 2014-10-01 15:05:24 +0300 | [diff] [blame] | 1494 | WIL_FIELD(recovery_count, S_IRUGO, doff_u32), |
Vladimir Kondratiev | 02beaf1 | 2015-03-08 15:42:03 +0200 | [diff] [blame] | 1495 | WIL_FIELD(ap_isolate, S_IRUGO, doff_u32), |
Vladimir Kondratiev | b7cde47 | 2014-08-06 10:31:55 +0300 | [diff] [blame] | 1496 | {}, |
| 1497 | }; |
| 1498 | |
| 1499 | static const struct dbg_off dbg_wil_regs[] = { |
| 1500 | {"RGF_MAC_MTRL_COUNTER_0", S_IRUGO, HOSTADDR(RGF_MAC_MTRL_COUNTER_0), |
| 1501 | doff_io32}, |
| 1502 | {"RGF_USER_USAGE_1", S_IRUGO, HOSTADDR(RGF_USER_USAGE_1), doff_io32}, |
| 1503 | {}, |
| 1504 | }; |
| 1505 | |
| 1506 | /* static parameters */ |
| 1507 | static const struct dbg_off dbg_statics[] = { |
| 1508 | {"desc_index", S_IRUGO | S_IWUSR, (ulong)&dbg_txdesc_index, doff_u32}, |
| 1509 | {"vring_index", S_IRUGO | S_IWUSR, (ulong)&dbg_vring_index, doff_u32}, |
| 1510 | {"mem_addr", S_IRUGO | S_IWUSR, (ulong)&mem_addr, doff_u32}, |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 1511 | {"vring_idle_trsh", S_IRUGO | S_IWUSR, (ulong)&vring_idle_trsh, |
| 1512 | doff_u32}, |
Vladimir Kondratiev | b7cde47 | 2014-08-06 10:31:55 +0300 | [diff] [blame] | 1513 | {}, |
| 1514 | }; |
| 1515 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1516 | int wil6210_debugfs_init(struct wil6210_priv *wil) |
| 1517 | { |
| 1518 | struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME, |
| 1519 | wil_to_wiphy(wil)->debugfsdir); |
| 1520 | |
| 1521 | if (IS_ERR_OR_NULL(dbg)) |
| 1522 | return -ENODEV; |
| 1523 | |
Vladimir Kondratiev | dc16427 | 2015-04-30 16:25:09 +0300 | [diff] [blame] | 1524 | wil_pmc_init(wil); |
| 1525 | |
Vladimir Kondratiev | b7cde47 | 2014-08-06 10:31:55 +0300 | [diff] [blame] | 1526 | wil6210_debugfs_init_files(wil, dbg); |
| 1527 | wil6210_debugfs_init_isr(wil, dbg); |
Vladimir Kondratiev | b541d0a | 2014-07-14 09:49:41 +0300 | [diff] [blame] | 1528 | wil6210_debugfs_init_blobs(wil, dbg); |
Vladimir Kondratiev | b7cde47 | 2014-08-06 10:31:55 +0300 | [diff] [blame] | 1529 | wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off); |
| 1530 | wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr, |
| 1531 | dbg_wil_regs); |
| 1532 | wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics); |
| 1533 | |
| 1534 | wil6210_debugfs_create_pseudo_ISR(wil, dbg); |
| 1535 | |
| 1536 | wil6210_debugfs_create_ITR_CNT(wil, dbg); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1537 | |
| 1538 | return 0; |
| 1539 | } |
| 1540 | |
| 1541 | void wil6210_debugfs_remove(struct wil6210_priv *wil) |
| 1542 | { |
| 1543 | debugfs_remove_recursive(wil->debug); |
| 1544 | wil->debug = NULL; |
Vladimir Kondratiev | dc16427 | 2015-04-30 16:25:09 +0300 | [diff] [blame] | 1545 | |
| 1546 | /* free pmc memory without sending command to fw, as it will |
| 1547 | * be reset on the way down anyway |
| 1548 | */ |
| 1549 | wil_pmc_free(wil, false); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1550 | } |