blob: a8098b406cc03d12ee054ceea166df611af125ff [file] [log] [blame]
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001/*
Hamad Kadmanyee5dfe02016-01-28 19:24:05 +02002 * Copyright (c) 2012-2016 Qualcomm Atheros, Inc.
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08003 *
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 Kondratiev84bb29b2014-06-16 19:37:21 +030022#include <linux/power_supply.h>
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080023
24#include "wil6210.h"
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +030025#include "wmi.h"
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080026#include "txrx.h"
Vladimir Kondratievdc164272015-04-30 16:25:09 +030027#include "pmc.h"
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080028
29/* Nasty hack. Better have per device instances */
30static u32 mem_addr;
31static u32 dbg_txdesc_index;
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +020032static u32 dbg_vring_index; /* 24+ for Rx, 0..23 for Tx */
Vladimir Shulman0436fd92015-02-15 14:02:34 +020033u32 vring_idle_trsh = 16; /* HW fetches up to 16 descriptors at once */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080034
Vladimir Kondratievb7cde472014-08-06 10:31:55 +030035enum dbg_off_type {
36 doff_u32 = 0,
37 doff_x32 = 1,
38 doff_ulong = 2,
39 doff_io32 = 3,
Lior David74997a52016-03-01 19:18:08 +020040 doff_u8 = 4
Vladimir Kondratievb7cde472014-08-06 10:31:55 +030041};
42
43/* offset to "wil" */
44struct dbg_off {
45 const char *name;
46 umode_t mode;
47 ulong off;
48 enum dbg_off_type type;
49};
50
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080051static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil,
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +020052 const char *name, struct vring *vring,
53 char _s, char _h)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080054{
55 void __iomem *x = wmi_addr(wil, vring->hwtail);
Vladimir Kondratiev995cdd02014-12-23 09:47:08 +020056 u32 v;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080057
58 seq_printf(s, "VRING %s = {\n", name);
Vladimir Kondratiev39c52ee2014-05-27 14:45:49 +030059 seq_printf(s, " pa = %pad\n", &vring->pa);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080060 seq_printf(s, " va = 0x%p\n", vring->va);
61 seq_printf(s, " size = %d\n", vring->size);
62 seq_printf(s, " swtail = %d\n", vring->swtail);
63 seq_printf(s, " swhead = %d\n", vring->swhead);
64 seq_printf(s, " hwtail = [0x%08x] -> ", vring->hwtail);
Vladimir Kondratiev995cdd02014-12-23 09:47:08 +020065 if (x) {
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +030066 v = readl(x);
Vladimir Kondratiev995cdd02014-12-23 09:47:08 +020067 seq_printf(s, "0x%08x = %d\n", v, v);
68 } else {
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030069 seq_puts(s, "???\n");
Vladimir Kondratiev995cdd02014-12-23 09:47:08 +020070 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080071
Hamad Kadmanyee5dfe02016-01-28 19:24:05 +020072 if (vring->va && (vring->size <= (1 << WIL_RING_SIZE_ORDER_MAX))) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080073 uint i;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030074
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080075 for (i = 0; i < vring->size; i++) {
76 volatile struct vring_tx_desc *d = &vring->va[i].tx;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030077
Hamad Kadmanyee5dfe02016-01-28 19:24:05 +020078 if ((i % 128) == 0 && (i != 0))
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030079 seq_puts(s, "\n");
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +020080 seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
81 _s : (vring->ctx[i].skb ? _h : 'h'));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080082 }
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030083 seq_puts(s, "\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080084 }
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030085 seq_puts(s, "}\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080086}
87
88static int wil_vring_debugfs_show(struct seq_file *s, void *data)
89{
90 uint i;
91 struct wil6210_priv *wil = s->private;
92
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +020093 wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_');
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080094
95 for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030096 struct vring *vring = &wil->vring_tx[i];
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +030097 struct vring_tx_data *txdata = &wil->vring_tx_data[i];
98
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080099 if (vring->va) {
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200100 int cid = wil->vring2cid_tid[i][0];
101 int tid = wil->vring2cid_tid[i][1];
Vladimir Kondratiev67c3e1b2014-06-16 19:37:04 +0300102 u32 swhead = vring->swhead;
103 u32 swtail = vring->swtail;
104 int used = (vring->size + swhead - swtail)
105 % vring->size;
106 int avail = vring->size - used - 1;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800107 char name[10];
Boris Sorochkin8f55cbe2015-02-15 14:02:35 +0200108 char sidle[10];
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +0300109 /* performance monitoring */
110 cycles_t now = get_cycles();
Chen Gangc20e7782014-12-24 23:08:44 +0800111 uint64_t idle = txdata->idle * 100;
112 uint64_t total = now - txdata->begin;
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +0300113
Boris Sorochkin8f55cbe2015-02-15 14:02:35 +0200114 if (total != 0) {
115 do_div(idle, total);
116 snprintf(sidle, sizeof(sidle), "%3d%%",
117 (int)idle);
118 } else {
119 snprintf(sidle, sizeof(sidle), "N/A");
120 }
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +0300121 txdata->begin = now;
122 txdata->idle = 0ULL;
123
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800124 snprintf(name, sizeof(name), "tx_%2d", i);
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200125
Vladimir Kondratiev41d6b092015-03-15 16:00:23 +0200126 if (cid < WIL6210_MAX_CID)
127 seq_printf(s,
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300128 "\n%pM CID %d TID %d 1x%s BACK([%u] %u TU A%s) [%3d|%3d] idle %s\n",
Vladimir Kondratiev41d6b092015-03-15 16:00:23 +0200129 wil->sta[cid].addr, cid, tid,
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300130 txdata->dot1x_open ? "+" : "-",
Vladimir Kondratiev41d6b092015-03-15 16:00:23 +0200131 txdata->agg_wsize,
132 txdata->agg_timeout,
133 txdata->agg_amsdu ? "+" : "-",
134 used, avail, sidle);
135 else
136 seq_printf(s,
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300137 "\nBroadcast 1x%s [%3d|%3d] idle %s\n",
138 txdata->dot1x_open ? "+" : "-",
Vladimir Kondratiev41d6b092015-03-15 16:00:23 +0200139 used, avail, sidle);
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +0300140
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +0200141 wil_print_vring(s, wil, name, vring, '_', 'H');
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800142 }
143 }
144
145 return 0;
146}
147
148static int wil_vring_seq_open(struct inode *inode, struct file *file)
149{
150 return single_open(file, wil_vring_debugfs_show, inode->i_private);
151}
152
153static const struct file_operations fops_vring = {
154 .open = wil_vring_seq_open,
155 .release = single_release,
156 .read = seq_read,
157 .llseek = seq_lseek,
158};
159
Andy Shevchenkoa202fbb2015-09-09 15:38:48 -0700160static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
161 const char *prefix)
162{
163 seq_hex_dump(s, prefix, DUMP_PREFIX_NONE, 16, 1, p, len, false);
164}
165
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800166static void wil_print_ring(struct seq_file *s, const char *prefix,
167 void __iomem *off)
168{
169 struct wil6210_priv *wil = s->private;
170 struct wil6210_mbox_ring r;
171 int rsize;
172 uint i;
173
Maya Erez349214c2016-04-26 14:41:41 +0300174 wil_halp_vote(wil);
175
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800176 wil_memcpy_fromio_32(&r, off, sizeof(r));
177 wil_mbox_ring_le2cpus(&r);
178 /*
179 * we just read memory block from NIC. This memory may be
180 * garbage. Check validity before using it.
181 */
182 rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
183
184 seq_printf(s, "ring %s = {\n", prefix);
185 seq_printf(s, " base = 0x%08x\n", r.base);
186 seq_printf(s, " size = 0x%04x bytes -> %d entries\n", r.size, rsize);
187 seq_printf(s, " tail = 0x%08x\n", r.tail);
188 seq_printf(s, " head = 0x%08x\n", r.head);
189 seq_printf(s, " entry size = %d\n", r.entry_size);
190
191 if (r.size % sizeof(struct wil6210_mbox_ring_desc)) {
192 seq_printf(s, " ??? size is not multiple of %zd, garbage?\n",
193 sizeof(struct wil6210_mbox_ring_desc));
194 goto out;
195 }
196
197 if (!wmi_addr(wil, r.base) ||
198 !wmi_addr(wil, r.tail) ||
199 !wmi_addr(wil, r.head)) {
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300200 seq_puts(s, " ??? pointers are garbage?\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800201 goto out;
202 }
203
204 for (i = 0; i < rsize; i++) {
205 struct wil6210_mbox_ring_desc d;
206 struct wil6210_mbox_hdr hdr;
207 size_t delta = i * sizeof(d);
208 void __iomem *x = wil->csr + HOSTADDR(r.base) + delta;
209
210 wil_memcpy_fromio_32(&d, x, sizeof(d));
211
212 seq_printf(s, " [%2x] %s %s%s 0x%08x", i,
213 d.sync ? "F" : "E",
214 (r.tail - r.base == delta) ? "t" : " ",
215 (r.head - r.base == delta) ? "h" : " ",
216 le32_to_cpu(d.addr));
217 if (0 == wmi_read_hdr(wil, d.addr, &hdr)) {
218 u16 len = le16_to_cpu(hdr.len);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300219
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800220 seq_printf(s, " -> %04x %04x %04x %02x\n",
221 le16_to_cpu(hdr.seq), len,
222 le16_to_cpu(hdr.type), hdr.flags);
223 if (len <= MAX_MBOXITEM_SIZE) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800224 unsigned char databuf[MAX_MBOXITEM_SIZE];
225 void __iomem *src = wmi_buffer(wil, d.addr) +
226 sizeof(struct wil6210_mbox_hdr);
227 /*
228 * No need to check @src for validity -
229 * we already validated @d.addr while
230 * reading header
231 */
232 wil_memcpy_fromio_32(databuf, src, len);
Andy Shevchenkoa202fbb2015-09-09 15:38:48 -0700233 wil_seq_hexdump(s, databuf, len, " : ");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800234 }
235 } else {
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300236 seq_puts(s, "\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800237 }
238 }
239 out:
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300240 seq_puts(s, "}\n");
Maya Erez349214c2016-04-26 14:41:41 +0300241 wil_halp_unvote(wil);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800242}
243
244static int wil_mbox_debugfs_show(struct seq_file *s, void *data)
245{
246 struct wil6210_priv *wil = s->private;
247
248 wil_print_ring(s, "tx", wil->csr + HOST_MBOX +
249 offsetof(struct wil6210_mbox_ctl, tx));
250 wil_print_ring(s, "rx", wil->csr + HOST_MBOX +
251 offsetof(struct wil6210_mbox_ctl, rx));
252
253 return 0;
254}
255
256static int wil_mbox_seq_open(struct inode *inode, struct file *file)
257{
258 return single_open(file, wil_mbox_debugfs_show, inode->i_private);
259}
260
261static const struct file_operations fops_mbox = {
262 .open = wil_mbox_seq_open,
263 .release = single_release,
264 .read = seq_read,
265 .llseek = seq_lseek,
266};
267
268static int wil_debugfs_iomem_x32_set(void *data, u64 val)
269{
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300270 writel(val, (void __iomem *)data);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800271 wmb(); /* make sure write propagated to HW */
272
273 return 0;
274}
275
276static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
277{
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300278 *val = readl((void __iomem *)data);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800279
280 return 0;
281}
282
283DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
284 wil_debugfs_iomem_x32_set, "0x%08llx\n");
285
286static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
Al Viro0ecc8332013-03-29 12:23:28 -0400287 umode_t mode,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800288 struct dentry *parent,
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300289 void *value)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800290{
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300291 return debugfs_create_file(name, mode, parent, value,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800292 &fops_iomem_x32);
293}
294
Vladimir Kondratiev3de6cf22014-06-16 19:37:02 +0300295static int wil_debugfs_ulong_set(void *data, u64 val)
296{
297 *(ulong *)data = val;
298 return 0;
299}
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300300
Vladimir Kondratiev3de6cf22014-06-16 19:37:02 +0300301static int wil_debugfs_ulong_get(void *data, u64 *val)
302{
303 *val = *(ulong *)data;
304 return 0;
305}
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300306
Vladimir Kondratiev3de6cf22014-06-16 19:37:02 +0300307DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
Vladimir Kondratiev8ea06182015-07-30 13:51:51 +0300308 wil_debugfs_ulong_set, "0x%llx\n");
Vladimir Kondratiev3de6cf22014-06-16 19:37:02 +0300309
310static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode,
311 struct dentry *parent,
312 ulong *value)
313{
314 return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong);
315}
316
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300317/**
318 * wil6210_debugfs_init_offset - create set of debugfs files
319 * @wil - driver's context, used for printing
320 * @dbg - directory on the debugfs, where files will be created
321 * @base - base address used in address calculation
322 * @tbl - table with file descriptions. Should be terminated with empty element.
323 *
324 * Creates files accordingly to the @tbl.
325 */
326static void wil6210_debugfs_init_offset(struct wil6210_priv *wil,
327 struct dentry *dbg, void *base,
328 const struct dbg_off * const tbl)
329{
330 int i;
331
332 for (i = 0; tbl[i].name; i++) {
Vladimir Kondratiev867fa0d2014-09-10 16:34:51 +0300333 struct dentry *f;
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300334
335 switch (tbl[i].type) {
336 case doff_u32:
337 f = debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg,
338 base + tbl[i].off);
339 break;
340 case doff_x32:
341 f = debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg,
342 base + tbl[i].off);
343 break;
344 case doff_ulong:
345 f = wil_debugfs_create_ulong(tbl[i].name, tbl[i].mode,
346 dbg, base + tbl[i].off);
347 break;
348 case doff_io32:
349 f = wil_debugfs_create_iomem_x32(tbl[i].name,
350 tbl[i].mode, dbg,
351 base + tbl[i].off);
352 break;
Lior David74997a52016-03-01 19:18:08 +0200353 case doff_u8:
354 f = debugfs_create_u8(tbl[i].name, tbl[i].mode, dbg,
355 base + tbl[i].off);
356 break;
Vladimir Kondratiev867fa0d2014-09-10 16:34:51 +0300357 default:
358 f = ERR_PTR(-EINVAL);
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300359 }
360 if (IS_ERR_OR_NULL(f))
361 wil_err(wil, "Create file \"%s\": err %ld\n",
362 tbl[i].name, PTR_ERR(f));
363 }
364}
365
366static const struct dbg_off isr_off[] = {
367 {"ICC", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICC), doff_io32},
368 {"ICR", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICR), doff_io32},
369 {"ICM", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICM), doff_io32},
370 {"ICS", S_IWUSR, offsetof(struct RGF_ICR, ICS), doff_io32},
371 {"IMV", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, IMV), doff_io32},
372 {"IMS", S_IWUSR, offsetof(struct RGF_ICR, IMS), doff_io32},
373 {"IMC", S_IWUSR, offsetof(struct RGF_ICR, IMC), doff_io32},
374 {},
375};
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300376
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800377static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
378 const char *name,
379 struct dentry *parent, u32 off)
380{
381 struct dentry *d = debugfs_create_dir(name, parent);
382
383 if (IS_ERR_OR_NULL(d))
384 return -ENODEV;
385
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300386 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off,
387 isr_off);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800388
389 return 0;
390}
391
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300392static const struct dbg_off pseudo_isr_off[] = {
393 {"CAUSE", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32},
394 {"MASK_SW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32},
395 {"MASK_FW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32},
396 {},
397};
398
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800399static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
400 struct dentry *parent)
401{
402 struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
403
404 if (IS_ERR_OR_NULL(d))
405 return -ENODEV;
406
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300407 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
408 pseudo_isr_off);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800409
410 return 0;
411}
412
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200413static const struct dbg_off lgc_itr_cnt_off[] = {
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300414 {"TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32},
415 {"DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32},
416 {"CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32},
417 {},
418};
419
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200420static const struct dbg_off tx_itr_cnt_off[] = {
421 {"TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_CNT_TRSH),
422 doff_io32},
423 {"DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_CNT_DATA),
424 doff_io32},
425 {"CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_CNT_CTL),
426 doff_io32},
427 {"IDL_TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_TRSH),
428 doff_io32},
429 {"IDL_DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_DATA),
430 doff_io32},
431 {"IDL_CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_CTL),
432 doff_io32},
433 {},
434};
435
436static const struct dbg_off rx_itr_cnt_off[] = {
437 {"TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_CNT_TRSH),
438 doff_io32},
439 {"DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_CNT_DATA),
440 doff_io32},
441 {"CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_CNT_CTL),
442 doff_io32},
443 {"IDL_TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_TRSH),
444 doff_io32},
445 {"IDL_DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_DATA),
446 doff_io32},
447 {"IDL_CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_CTL),
448 doff_io32},
449 {},
450};
451
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800452static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
453 struct dentry *parent)
454{
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200455 struct dentry *d, *dtx, *drx;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800456
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200457 d = debugfs_create_dir("ITR_CNT", parent);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800458 if (IS_ERR_OR_NULL(d))
459 return -ENODEV;
460
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200461 dtx = debugfs_create_dir("TX", d);
462 drx = debugfs_create_dir("RX", d);
463 if (IS_ERR_OR_NULL(dtx) || IS_ERR_OR_NULL(drx))
464 return -ENODEV;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800465
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200466 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
467 lgc_itr_cnt_off);
468
469 wil6210_debugfs_init_offset(wil, dtx, (void * __force)wil->csr,
470 tx_itr_cnt_off);
471
472 wil6210_debugfs_init_offset(wil, drx, (void * __force)wil->csr,
473 rx_itr_cnt_off);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800474 return 0;
475}
476
477static int wil_memread_debugfs_show(struct seq_file *s, void *data)
478{
479 struct wil6210_priv *wil = s->private;
480 void __iomem *a = wmi_buffer(wil, cpu_to_le32(mem_addr));
481
482 if (a)
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300483 seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, readl(a));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800484 else
485 seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
486
487 return 0;
488}
489
490static int wil_memread_seq_open(struct inode *inode, struct file *file)
491{
492 return single_open(file, wil_memread_debugfs_show, inode->i_private);
493}
494
495static const struct file_operations fops_memread = {
496 .open = wil_memread_seq_open,
497 .release = single_release,
498 .read = seq_read,
499 .llseek = seq_lseek,
500};
501
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800502static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300503 size_t count, loff_t *ppos)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800504{
505 enum { max_count = 4096 };
Maya Erez349214c2016-04-26 14:41:41 +0300506 struct wil_blob_wrapper *wil_blob = file->private_data;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800507 loff_t pos = *ppos;
Maya Erez349214c2016-04-26 14:41:41 +0300508 size_t available = wil_blob->blob.size;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800509 void *buf;
510 size_t ret;
511
512 if (pos < 0)
513 return -EINVAL;
514
515 if (pos >= available || !count)
516 return 0;
517
518 if (count > available - pos)
519 count = available - pos;
520 if (count > max_count)
521 count = max_count;
522
523 buf = kmalloc(count, GFP_KERNEL);
524 if (!buf)
525 return -ENOMEM;
526
Maya Erez349214c2016-04-26 14:41:41 +0300527 wil_memcpy_fromio_halp_vote(wil_blob->wil, buf,
528 (const volatile void __iomem *)
529 wil_blob->blob.data + pos, count);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800530
531 ret = copy_to_user(user_buf, buf, count);
532 kfree(buf);
533 if (ret == count)
534 return -EFAULT;
535
536 count -= ret;
537 *ppos = pos + count;
538
539 return count;
540}
541
542static const struct file_operations fops_ioblob = {
543 .read = wil_read_file_ioblob,
Wei Yongjun93ecbd62013-02-26 10:29:34 +0800544 .open = simple_open,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800545 .llseek = default_llseek,
546};
547
548static
549struct dentry *wil_debugfs_create_ioblob(const char *name,
Al Viro0ecc8332013-03-29 12:23:28 -0400550 umode_t mode,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800551 struct dentry *parent,
Maya Erez349214c2016-04-26 14:41:41 +0300552 struct wil_blob_wrapper *wil_blob)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800553{
Maya Erez349214c2016-04-26 14:41:41 +0300554 return debugfs_create_file(name, mode, parent, wil_blob, &fops_ioblob);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800555}
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300556
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800557/*---reset---*/
558static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
559 size_t len, loff_t *ppos)
560{
561 struct wil6210_priv *wil = file->private_data;
562 struct net_device *ndev = wil_to_ndev(wil);
563
564 /**
565 * BUG:
566 * this code does NOT sync device state with the rest of system
567 * use with care, debug only!!!
568 */
569 rtnl_lock();
570 dev_close(ndev);
571 ndev->flags &= ~IFF_UP;
572 rtnl_unlock();
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200573 wil_reset(wil, true);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800574
575 return len;
576}
577
578static const struct file_operations fops_reset = {
579 .write = wil_write_file_reset,
Wei Yongjun93ecbd62013-02-26 10:29:34 +0800580 .open = simple_open,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800581};
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300582
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300583/*---write channel 1..4 to rxon for it, 0 to rxoff---*/
584static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
585 size_t len, loff_t *ppos)
586{
587 struct wil6210_priv *wil = file->private_data;
588 int rc;
589 long channel;
590 bool on;
591
Al Viro16e5c1f2015-12-24 00:06:05 -0500592 char *kbuf = memdup_user_nul(buf, len);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300593
Al Viro16e5c1f2015-12-24 00:06:05 -0500594 if (IS_ERR(kbuf))
595 return PTR_ERR(kbuf);
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300596 rc = kstrtol(kbuf, 0, &channel);
597 kfree(kbuf);
598 if (rc)
599 return rc;
600
601 if ((channel < 0) || (channel > 4)) {
602 wil_err(wil, "Invalid channel %ld\n", channel);
603 return -EINVAL;
604 }
605 on = !!channel;
606
607 if (on) {
608 rc = wmi_set_channel(wil, (int)channel);
609 if (rc)
610 return rc;
611 }
612
613 rc = wmi_rxon(wil, on);
614 if (rc)
615 return rc;
616
617 return len;
618}
619
620static const struct file_operations fops_rxon = {
621 .write = wil_write_file_rxon,
622 .open = simple_open,
623};
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300624
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +0200625/* block ack control, write:
626 * - "add <ringid> <agg_size> <timeout>" to trigger ADDBA
627 * - "del_tx <ringid> <reason>" to trigger DELBA for Tx side
628 * - "del_rx <CID> <TID> <reason>" to trigger DELBA for Rx side
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200629 */
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +0200630static ssize_t wil_write_back(struct file *file, const char __user *buf,
631 size_t len, loff_t *ppos)
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200632{
633 struct wil6210_priv *wil = file->private_data;
634 int rc;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200635 char *kbuf = kmalloc(len + 1, GFP_KERNEL);
Colin Ian King2a19f772015-03-01 17:48:33 +0000636 char cmd[9];
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +0200637 int p1, p2, p3;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200638
639 if (!kbuf)
640 return -ENOMEM;
641
642 rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
643 if (rc != len) {
644 kfree(kbuf);
645 return rc >= 0 ? -EIO : rc;
646 }
647
648 kbuf[len] = '\0';
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +0200649 rc = sscanf(kbuf, "%8s %d %d %d", cmd, &p1, &p2, &p3);
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200650 kfree(kbuf);
651
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +0200652 if (rc < 0)
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200653 return rc;
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +0200654 if (rc < 2)
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200655 return -EINVAL;
656
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +0200657 if (0 == strcmp(cmd, "add")) {
658 if (rc < 3) {
659 wil_err(wil, "BACK: add require at least 2 params\n");
660 return -EINVAL;
661 }
662 if (rc < 4)
663 p3 = 0;
664 wmi_addba(wil, p1, p2, p3);
665 } else if (0 == strcmp(cmd, "del_tx")) {
666 if (rc < 3)
667 p2 = WLAN_REASON_QSTA_LEAVE_QBSS;
668 wmi_delba_tx(wil, p1, p2);
669 } else if (0 == strcmp(cmd, "del_rx")) {
670 if (rc < 3) {
671 wil_err(wil,
672 "BACK: del_rx require at least 2 params\n");
673 return -EINVAL;
674 }
675 if (rc < 4)
676 p3 = WLAN_REASON_QSTA_LEAVE_QBSS;
677 wmi_delba_rx(wil, mk_cidxtid(p1, p2), p3);
678 } else {
679 wil_err(wil, "BACK: Unrecognized command \"%s\"\n", cmd);
680 return -EINVAL;
681 }
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200682
683 return len;
684}
685
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +0200686static ssize_t wil_read_back(struct file *file, char __user *user_buf,
687 size_t count, loff_t *ppos)
688{
689 static const char text[] = "block ack control, write:\n"
690 " - \"add <ringid> <agg_size> <timeout>\" to trigger ADDBA\n"
691 "If missing, <timeout> defaults to 0\n"
692 " - \"del_tx <ringid> <reason>\" to trigger DELBA for Tx side\n"
693 " - \"del_rx <CID> <TID> <reason>\" to trigger DELBA for Rx side\n"
694 "If missing, <reason> set to \"STA_LEAVING\" (36)\n";
695
696 return simple_read_from_buffer(user_buf, count, ppos, text,
697 sizeof(text));
698}
699
700static const struct file_operations fops_back = {
701 .read = wil_read_back,
702 .write = wil_write_back,
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200703 .open = simple_open,
704};
705
Vladimir Kondratievdc164272015-04-30 16:25:09 +0300706/* pmc control, write:
707 * - "alloc <num descriptors> <descriptor_size>" to allocate PMC
708 * - "free" to release memory allocated for PMC
709 */
710static ssize_t wil_write_pmccfg(struct file *file, const char __user *buf,
711 size_t len, loff_t *ppos)
712{
713 struct wil6210_priv *wil = file->private_data;
714 int rc;
715 char *kbuf = kmalloc(len + 1, GFP_KERNEL);
716 char cmd[9];
717 int num_descs, desc_size;
718
719 if (!kbuf)
720 return -ENOMEM;
721
722 rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
723 if (rc != len) {
724 kfree(kbuf);
725 return rc >= 0 ? -EIO : rc;
726 }
727
728 kbuf[len] = '\0';
729 rc = sscanf(kbuf, "%8s %d %d", cmd, &num_descs, &desc_size);
730 kfree(kbuf);
731
732 if (rc < 0)
733 return rc;
734
735 if (rc < 1) {
736 wil_err(wil, "pmccfg: no params given\n");
737 return -EINVAL;
738 }
739
740 if (0 == strcmp(cmd, "alloc")) {
741 if (rc != 3) {
742 wil_err(wil, "pmccfg: alloc requires 2 params\n");
743 return -EINVAL;
744 }
745 wil_pmc_alloc(wil, num_descs, desc_size);
746 } else if (0 == strcmp(cmd, "free")) {
747 if (rc != 1) {
748 wil_err(wil, "pmccfg: free does not have any params\n");
749 return -EINVAL;
750 }
751 wil_pmc_free(wil, true);
752 } else {
753 wil_err(wil, "pmccfg: Unrecognized command \"%s\"\n", cmd);
754 return -EINVAL;
755 }
756
757 return len;
758}
759
760static ssize_t wil_read_pmccfg(struct file *file, char __user *user_buf,
761 size_t count, loff_t *ppos)
762{
763 struct wil6210_priv *wil = file->private_data;
764 char text[256];
765 char help[] = "pmc control, write:\n"
766 " - \"alloc <num descriptors> <descriptor_size>\" to allocate pmc\n"
767 " - \"free\" to free memory allocated for pmc\n";
768
769 sprintf(text, "Last command status: %d\n\n%s",
770 wil_pmc_last_cmd_status(wil),
771 help);
772
773 return simple_read_from_buffer(user_buf, count, ppos, text,
774 strlen(text) + 1);
775}
776
777static const struct file_operations fops_pmccfg = {
778 .read = wil_read_pmccfg,
779 .write = wil_write_pmccfg,
780 .open = simple_open,
781};
782
783static const struct file_operations fops_pmcdata = {
784 .open = simple_open,
785 .read = wil_pmc_read,
786 .llseek = wil_pmc_llseek,
787};
788
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300789/*---tx_mgmt---*/
790/* Write mgmt frame to this file to send it */
791static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
792 size_t len, loff_t *ppos)
793{
794 struct wil6210_priv *wil = file->private_data;
795 struct wiphy *wiphy = wil_to_wiphy(wil);
796 struct wireless_dev *wdev = wil_to_wdev(wil);
797 struct cfg80211_mgmt_tx_params params;
798 int rc;
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300799 void *frame = kmalloc(len, GFP_KERNEL);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300800
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300801 if (!frame)
802 return -ENOMEM;
803
Lino Sanfilippo8e09b7d2014-11-28 02:47:19 +0100804 if (copy_from_user(frame, buf, len)) {
805 kfree(frame);
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300806 return -EIO;
Lino Sanfilippo8e09b7d2014-11-28 02:47:19 +0100807 }
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300808
809 params.buf = frame;
810 params.len = len;
811 params.chan = wdev->preset_chandef.chan;
812
813 rc = wil_cfg80211_mgmt_tx(wiphy, wdev, &params, NULL);
814
815 kfree(frame);
816 wil_info(wil, "%s() -> %d\n", __func__, rc);
817
818 return len;
819}
820
821static const struct file_operations fops_txmgmt = {
822 .write = wil_write_file_txmgmt,
823 .open = simple_open,
824};
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800825
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300826/* Write WMI command (w/o mbox header) to this file to send it
827 * WMI starts from wil6210_mbox_hdr_wmi header
828 */
829static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
830 size_t len, loff_t *ppos)
831{
832 struct wil6210_priv *wil = file->private_data;
Lior Davidb874dde2016-03-01 19:18:09 +0200833 struct wmi_cmd_hdr *wmi;
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300834 void *cmd;
Lior Davidb874dde2016-03-01 19:18:09 +0200835 int cmdlen = len - sizeof(struct wmi_cmd_hdr);
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300836 u16 cmdid;
837 int rc, rc1;
838
Lior David69218a42016-03-21 22:01:11 +0200839 if (cmdlen < 0)
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300840 return -EINVAL;
841
842 wmi = kmalloc(len, GFP_KERNEL);
843 if (!wmi)
844 return -ENOMEM;
845
846 rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
Lino Sanfilippo8e09b7d2014-11-28 02:47:19 +0100847 if (rc < 0) {
848 kfree(wmi);
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300849 return rc;
Lino Sanfilippo8e09b7d2014-11-28 02:47:19 +0100850 }
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300851
Lior David69218a42016-03-21 22:01:11 +0200852 cmd = (cmdlen > 0) ? &wmi[1] : NULL;
Lior Davidb874dde2016-03-01 19:18:09 +0200853 cmdid = le16_to_cpu(wmi->command_id);
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300854
855 rc1 = wmi_send(wil, cmdid, cmd, cmdlen);
856 kfree(wmi);
857
858 wil_info(wil, "%s(0x%04x[%d]) -> %d\n", __func__, cmdid, cmdlen, rc1);
859
860 return rc;
861}
862
863static const struct file_operations fops_wmi = {
864 .write = wil_write_file_wmi,
865 .open = simple_open,
866};
867
Vladimir Kondratievc2366582014-03-17 15:34:08 +0200868static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
869{
870 int i = 0;
871 int len = skb_headlen(skb);
872 void *p = skb->data;
873 int nr_frags = skb_shinfo(skb)->nr_frags;
874
875 seq_printf(s, " len = %d\n", len);
876 wil_seq_hexdump(s, p, len, " : ");
877
878 if (nr_frags) {
879 seq_printf(s, " nr_frags = %d\n", nr_frags);
880 for (i = 0; i < nr_frags; i++) {
881 const struct skb_frag_struct *frag =
882 &skb_shinfo(skb)->frags[i];
883
884 len = skb_frag_size(frag);
885 p = skb_frag_address_safe(frag);
886 seq_printf(s, " [%2d] : len = %d\n", i, len);
887 wil_seq_hexdump(s, p, len, " : ");
888 }
889 }
890}
891
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200892/*---------Tx/Rx descriptor------------*/
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800893static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
894{
895 struct wil6210_priv *wil = s->private;
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200896 struct vring *vring;
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +0200897 bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300898
899 vring = tx ? &wil->vring_tx[dbg_vring_index] : &wil->vring_rx;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800900
901 if (!vring->va) {
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +0200902 if (tx)
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200903 seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index);
904 else
905 seq_puts(s, "No Rx VRING\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800906 return 0;
907 }
908
909 if (dbg_txdesc_index < vring->size) {
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200910 /* use struct vring_tx_desc for Rx as well,
911 * only field used, .dma.length, is the same
912 */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800913 volatile struct vring_tx_desc *d =
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300914 &vring->va[dbg_txdesc_index].tx;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800915 volatile u32 *u = (volatile u32 *)d;
Vladimir Kondratievf88f1132013-07-11 18:03:40 +0300916 struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800917
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +0200918 if (tx)
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200919 seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index,
920 dbg_txdesc_index);
921 else
922 seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800923 seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
924 u[0], u[1], u[2], u[3]);
925 seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
926 u[4], u[5], u[6], u[7]);
Vladimir Kondratiev39c52ee2014-05-27 14:45:49 +0300927 seq_printf(s, " SKB = 0x%p\n", skb);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800928
929 if (skb) {
Vladimir Kondratievc2366582014-03-17 15:34:08 +0200930 skb_get(skb);
931 wil_seq_print_skb(s, skb);
932 kfree_skb(skb);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800933 }
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300934 seq_puts(s, "}\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800935 } else {
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +0200936 if (tx)
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200937 seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
938 dbg_vring_index, dbg_txdesc_index,
939 vring->size);
940 else
941 seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
942 dbg_txdesc_index, vring->size);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800943 }
944
945 return 0;
946}
947
948static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
949{
950 return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
951}
952
953static const struct file_operations fops_txdesc = {
954 .open = wil_txdesc_seq_open,
955 .release = single_release,
956 .read = seq_read,
957 .llseek = seq_lseek,
958};
959
960/*---------beamforming------------*/
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +0300961static char *wil_bfstatus_str(u32 status)
962{
963 switch (status) {
964 case 0:
965 return "Failed";
966 case 1:
967 return "OK";
968 case 2:
969 return "Retrying";
970 default:
971 return "??";
972 }
973}
974
975static bool is_all_zeros(void * const x_, size_t sz)
976{
977 /* if reply is all-0, ignore this CID */
978 u32 *x = x_;
979 int n;
980
981 for (n = 0; n < sz / sizeof(*x); n++)
982 if (x[n])
983 return false;
984
985 return true;
986}
987
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800988static int wil_bf_debugfs_show(struct seq_file *s, void *data)
989{
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +0300990 int rc;
991 int i;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800992 struct wil6210_priv *wil = s->private;
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +0300993 struct wmi_notify_req_cmd cmd = {
994 .interval_usec = 0,
995 };
996 struct {
Lior Davidb874dde2016-03-01 19:18:09 +0200997 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +0300998 struct wmi_notify_req_done_event evt;
999 } __packed reply;
1000
1001 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1002 u32 status;
1003
1004 cmd.cid = i;
1005 rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd),
1006 WMI_NOTIFY_REQ_DONE_EVENTID, &reply,
1007 sizeof(reply), 20);
1008 /* if reply is all-0, ignore this CID */
1009 if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt)))
1010 continue;
1011
1012 status = le32_to_cpu(reply.evt.status);
1013 seq_printf(s, "CID %d {\n"
1014 " TSF = 0x%016llx\n"
1015 " TxMCS = %2d TxTpt = %4d\n"
1016 " SQI = %4d\n"
1017 " Status = 0x%08x %s\n"
1018 " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
1019 " Goodput(rx:tx) %4d:%4d\n"
1020 "}\n",
1021 i,
1022 le64_to_cpu(reply.evt.tsf),
1023 le16_to_cpu(reply.evt.bf_mcs),
1024 le32_to_cpu(reply.evt.tx_tpt),
1025 reply.evt.sqi,
1026 status, wil_bfstatus_str(status),
1027 le16_to_cpu(reply.evt.my_rx_sector),
1028 le16_to_cpu(reply.evt.my_tx_sector),
1029 le16_to_cpu(reply.evt.other_rx_sector),
1030 le16_to_cpu(reply.evt.other_tx_sector),
1031 le32_to_cpu(reply.evt.rx_goodput),
1032 le32_to_cpu(reply.evt.tx_goodput));
1033 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001034 return 0;
1035}
1036
1037static int wil_bf_seq_open(struct inode *inode, struct file *file)
1038{
1039 return single_open(file, wil_bf_debugfs_show, inode->i_private);
1040}
1041
1042static const struct file_operations fops_bf = {
1043 .open = wil_bf_seq_open,
1044 .release = single_release,
1045 .read = seq_read,
1046 .llseek = seq_lseek,
1047};
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001048
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001049/*---------SSID------------*/
1050static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf,
1051 size_t count, loff_t *ppos)
1052{
1053 struct wil6210_priv *wil = file->private_data;
1054 struct wireless_dev *wdev = wil_to_wdev(wil);
1055
1056 return simple_read_from_buffer(user_buf, count, ppos,
1057 wdev->ssid, wdev->ssid_len);
1058}
1059
1060static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf,
1061 size_t count, loff_t *ppos)
1062{
1063 struct wil6210_priv *wil = file->private_data;
1064 struct wireless_dev *wdev = wil_to_wdev(wil);
1065 struct net_device *ndev = wil_to_ndev(wil);
1066
1067 if (*ppos != 0) {
1068 wil_err(wil, "Unable to set SSID substring from [%d]\n",
1069 (int)*ppos);
1070 return -EINVAL;
1071 }
1072
1073 if (count > sizeof(wdev->ssid)) {
1074 wil_err(wil, "SSID too long, len = %d\n", (int)count);
1075 return -EINVAL;
1076 }
1077 if (netif_running(ndev)) {
1078 wil_err(wil, "Unable to change SSID on running interface\n");
1079 return -EINVAL;
1080 }
1081
1082 wdev->ssid_len = count;
1083 return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos,
1084 buf, count);
1085}
1086
1087static const struct file_operations fops_ssid = {
1088 .read = wil_read_file_ssid,
1089 .write = wil_write_file_ssid,
Wei Yongjun93ecbd62013-02-26 10:29:34 +08001090 .open = simple_open,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001091};
1092
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001093/*---------temp------------*/
1094static void print_temp(struct seq_file *s, const char *prefix, u32 t)
1095{
1096 switch (t) {
1097 case 0:
1098 case ~(u32)0:
1099 seq_printf(s, "%s N/A\n", prefix);
1100 break;
1101 default:
1102 seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
1103 break;
1104 }
1105}
1106
1107static int wil_temp_debugfs_show(struct seq_file *s, void *data)
1108{
1109 struct wil6210_priv *wil = s->private;
1110 u32 t_m, t_r;
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001111 int rc = wmi_get_temperature(wil, &t_m, &t_r);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001112
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001113 if (rc) {
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001114 seq_puts(s, "Failed\n");
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001115 return 0;
1116 }
1117
Vladimir Kondratievd45cff92014-06-16 19:37:12 +03001118 print_temp(s, "T_mac =", t_m);
1119 print_temp(s, "T_radio =", t_r);
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001120
1121 return 0;
1122}
1123
1124static int wil_temp_seq_open(struct inode *inode, struct file *file)
1125{
1126 return single_open(file, wil_temp_debugfs_show, inode->i_private);
1127}
1128
1129static const struct file_operations fops_temp = {
1130 .open = wil_temp_seq_open,
1131 .release = single_release,
1132 .read = seq_read,
1133 .llseek = seq_lseek,
1134};
1135
Vladimir Kondratiev9eb82d42014-06-16 19:37:13 +03001136/*---------freq------------*/
1137static int wil_freq_debugfs_show(struct seq_file *s, void *data)
1138{
1139 struct wil6210_priv *wil = s->private;
1140 struct wireless_dev *wdev = wil_to_wdev(wil);
1141 u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
1142
1143 seq_printf(s, "Freq = %d\n", freq);
1144
1145 return 0;
1146}
1147
1148static int wil_freq_seq_open(struct inode *inode, struct file *file)
1149{
1150 return single_open(file, wil_freq_debugfs_show, inode->i_private);
1151}
1152
1153static const struct file_operations fops_freq = {
1154 .open = wil_freq_seq_open,
1155 .release = single_release,
1156 .read = seq_read,
1157 .llseek = seq_lseek,
1158};
1159
1160/*---------link------------*/
1161static int wil_link_debugfs_show(struct seq_file *s, void *data)
1162{
1163 struct wil6210_priv *wil = s->private;
1164 struct station_info sinfo;
1165 int i, rc;
1166
1167 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1168 struct wil_sta_info *p = &wil->sta[i];
1169 char *status = "unknown";
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001170
Vladimir Kondratiev9eb82d42014-06-16 19:37:13 +03001171 switch (p->status) {
1172 case wil_sta_unused:
1173 status = "unused ";
1174 break;
1175 case wil_sta_conn_pending:
1176 status = "pending ";
1177 break;
1178 case wil_sta_connected:
1179 status = "connected";
1180 break;
1181 }
Vladimir Kondratiev230d8442015-04-30 16:25:10 +03001182 seq_printf(s, "[%d] %pM %s\n", i, p->addr, status);
Vladimir Kondratiev9eb82d42014-06-16 19:37:13 +03001183
1184 if (p->status == wil_sta_connected) {
1185 rc = wil_cid_fill_sinfo(wil, i, &sinfo);
1186 if (rc)
1187 return rc;
1188
1189 seq_printf(s, " Tx_mcs = %d\n", sinfo.txrate.mcs);
1190 seq_printf(s, " Rx_mcs = %d\n", sinfo.rxrate.mcs);
1191 seq_printf(s, " SQ = %d\n", sinfo.signal);
1192 }
1193 }
1194
1195 return 0;
1196}
1197
1198static int wil_link_seq_open(struct inode *inode, struct file *file)
1199{
1200 return single_open(file, wil_link_debugfs_show, inode->i_private);
1201}
1202
1203static const struct file_operations fops_link = {
1204 .open = wil_link_seq_open,
1205 .release = single_release,
1206 .read = seq_read,
1207 .llseek = seq_lseek,
1208};
1209
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +03001210/*---------info------------*/
1211static int wil_info_debugfs_show(struct seq_file *s, void *data)
1212{
Vladimir Kondratievbe299852014-06-16 19:37:22 +03001213 struct wil6210_priv *wil = s->private;
1214 struct net_device *ndev = wil_to_ndev(wil);
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +03001215 int is_ac = power_supply_is_system_supplied();
Vladimir Kondratievbe299852014-06-16 19:37:22 +03001216 int rx = atomic_xchg(&wil->isr_count_rx, 0);
1217 int tx = atomic_xchg(&wil->isr_count_tx, 0);
1218 static ulong rxf_old, txf_old;
1219 ulong rxf = ndev->stats.rx_packets;
1220 ulong txf = ndev->stats.tx_packets;
Vladimir Kondratiev55f8f682014-06-16 19:37:23 +03001221 unsigned int i;
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +03001222
1223 /* >0 : AC; 0 : battery; <0 : error */
1224 seq_printf(s, "AC powered : %d\n", is_ac);
Vladimir Kondratievbe299852014-06-16 19:37:22 +03001225 seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
1226 seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
1227 rxf_old = rxf;
1228 txf_old = txf;
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +03001229
Vladimir Kondratiev55f8f682014-06-16 19:37:23 +03001230#define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
1231 " " __stringify(x) : ""
1232
1233 for (i = 0; i < ndev->num_tx_queues; i++) {
1234 struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
1235 unsigned long state = txq->state;
1236
1237 seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
1238 CHECK_QSTATE(DRV_XOFF),
1239 CHECK_QSTATE(STACK_XOFF),
1240 CHECK_QSTATE(FROZEN)
1241 );
1242 }
1243#undef CHECK_QSTATE
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +03001244 return 0;
1245}
1246
1247static int wil_info_seq_open(struct inode *inode, struct file *file)
1248{
1249 return single_open(file, wil_info_debugfs_show, inode->i_private);
1250}
1251
1252static const struct file_operations fops_info = {
1253 .open = wil_info_seq_open,
1254 .release = single_release,
1255 .read = seq_read,
1256 .llseek = seq_lseek,
1257};
1258
Vladimir Kondratievc33407a2014-10-01 15:05:24 +03001259/*---------recovery------------*/
1260/* mode = [manual|auto]
1261 * state = [idle|pending|running]
1262 */
1263static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf,
1264 size_t count, loff_t *ppos)
1265{
1266 struct wil6210_priv *wil = file->private_data;
1267 char buf[80];
1268 int n;
1269 static const char * const sstate[] = {"idle", "pending", "running"};
1270
1271 n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n",
1272 no_fw_recovery ? "manual" : "auto",
1273 sstate[wil->recovery_state]);
1274
1275 n = min_t(int, n, sizeof(buf));
1276
1277 return simple_read_from_buffer(user_buf, count, ppos,
1278 buf, n);
1279}
1280
1281static ssize_t wil_write_file_recovery(struct file *file,
1282 const char __user *buf_,
1283 size_t count, loff_t *ppos)
1284{
1285 struct wil6210_priv *wil = file->private_data;
1286 static const char run_command[] = "run";
1287 char buf[sizeof(run_command) + 1]; /* to detect "runx" */
1288 ssize_t rc;
1289
1290 if (wil->recovery_state != fw_recovery_pending) {
1291 wil_err(wil, "No recovery pending\n");
1292 return -EINVAL;
1293 }
1294
1295 if (*ppos != 0) {
1296 wil_err(wil, "Offset [%d]\n", (int)*ppos);
1297 return -EINVAL;
1298 }
1299
1300 if (count > sizeof(buf)) {
1301 wil_err(wil, "Input too long, len = %d\n", (int)count);
1302 return -EINVAL;
1303 }
1304
1305 rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count);
1306 if (rc < 0)
1307 return rc;
1308
1309 buf[rc] = '\0';
1310 if (0 == strcmp(buf, run_command))
1311 wil_set_recovery_state(wil, fw_recovery_running);
1312 else
1313 wil_err(wil, "Bad recovery command \"%s\"\n", buf);
1314
1315 return rc;
1316}
1317
1318static const struct file_operations fops_recovery = {
1319 .read = wil_read_file_recovery,
1320 .write = wil_write_file_recovery,
1321 .open = simple_open,
1322};
1323
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001324/*---------Station matrix------------*/
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001325static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
1326{
1327 int i;
1328 u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
Vladimir Kondratiev91a8edc2015-07-30 13:52:01 +03001329 unsigned long long drop_dup = r->drop_dup, drop_old = r->drop_old;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001330
Vladimir Kondratiev56637e72014-12-23 09:47:06 +02001331 seq_printf(s, "([%2d] %3d TU) 0x%03x [", r->buf_size, r->timeout,
1332 r->head_seq_num);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001333 for (i = 0; i < r->buf_size; i++) {
1334 if (i == index)
1335 seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
1336 else
1337 seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
1338 }
Vladimir Kondratiev91a8edc2015-07-30 13:52:01 +03001339 seq_printf(s,
1340 "] total %llu drop %llu (dup %llu + old %llu) last 0x%03x\n",
1341 r->total, drop_dup + drop_old, drop_dup, drop_old,
1342 r->ssn_last_drop);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001343}
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001344
Vladimir Kondratiev58527422016-03-01 19:18:07 +02001345static void wil_print_rxtid_crypto(struct seq_file *s, int tid,
1346 struct wil_tid_crypto_rx *c)
1347{
1348 int i;
1349
1350 for (i = 0; i < 4; i++) {
1351 struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
1352
1353 if (cc->key_set)
1354 goto has_keys;
1355 }
1356 return;
1357
1358has_keys:
1359 if (tid < WIL_STA_TID_NUM)
1360 seq_printf(s, " [%2d] PN", tid);
1361 else
1362 seq_puts(s, " [GR] PN");
1363
1364 for (i = 0; i < 4; i++) {
1365 struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
1366
1367 seq_printf(s, " [%i%s]%6phN", i, cc->key_set ? "+" : "-",
1368 cc->pn);
1369 }
1370 seq_puts(s, "\n");
1371}
1372
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001373static int wil_sta_debugfs_show(struct seq_file *s, void *data)
Vladimir Kondratievbd332732014-12-23 09:47:24 +02001374__acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001375{
1376 struct wil6210_priv *wil = s->private;
Vladimir Kondratievc4a110d2015-06-09 14:11:18 +03001377 int i, tid, mcs;
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001378
1379 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1380 struct wil_sta_info *p = &wil->sta[i];
1381 char *status = "unknown";
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001382
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001383 switch (p->status) {
1384 case wil_sta_unused:
1385 status = "unused ";
1386 break;
1387 case wil_sta_conn_pending:
1388 status = "pending ";
1389 break;
1390 case wil_sta_connected:
1391 status = "connected";
1392 break;
1393 }
Vladimir Kondratiev230d8442015-04-30 16:25:10 +03001394 seq_printf(s, "[%d] %pM %s\n", i, p->addr, status);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001395
1396 if (p->status == wil_sta_connected) {
Vladimir Kondratievbd332732014-12-23 09:47:24 +02001397 spin_lock_bh(&p->tid_rx_lock);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001398 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1399 struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
Vladimir Kondratiev58527422016-03-01 19:18:07 +02001400 struct wil_tid_crypto_rx *c =
1401 &p->tid_crypto_rx[tid];
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001402
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001403 if (r) {
Vladimir Kondratiev58527422016-03-01 19:18:07 +02001404 seq_printf(s, " [%2d] ", tid);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001405 wil_print_rxtid(s, r);
1406 }
Vladimir Kondratiev58527422016-03-01 19:18:07 +02001407
1408 wil_print_rxtid_crypto(s, tid, c);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001409 }
Vladimir Kondratiev58527422016-03-01 19:18:07 +02001410 wil_print_rxtid_crypto(s, WIL_STA_TID_NUM,
1411 &p->group_crypto_rx);
Vladimir Kondratievbd332732014-12-23 09:47:24 +02001412 spin_unlock_bh(&p->tid_rx_lock);
Vladimir Kondratiev3b282bc2015-10-04 10:23:19 +03001413 seq_printf(s,
Vladimir Kondratiev58527422016-03-01 19:18:07 +02001414 "Rx invalid frame: non-data %lu, short %lu, large %lu, replay %lu\n",
Vladimir Kondratiev3b282bc2015-10-04 10:23:19 +03001415 p->stats.rx_non_data_frame,
1416 p->stats.rx_short_frame,
Vladimir Kondratiev58527422016-03-01 19:18:07 +02001417 p->stats.rx_large_frame,
1418 p->stats.rx_replay);
Vladimir Kondratiev3b282bc2015-10-04 10:23:19 +03001419
Vladimir Kondratievc4a110d2015-06-09 14:11:18 +03001420 seq_puts(s, "Rx/MCS:");
1421 for (mcs = 0; mcs < ARRAY_SIZE(p->stats.rx_per_mcs);
1422 mcs++)
1423 seq_printf(s, " %lld",
1424 p->stats.rx_per_mcs[mcs]);
1425 seq_puts(s, "\n");
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001426 }
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001427 }
1428
1429 return 0;
1430}
1431
1432static int wil_sta_seq_open(struct inode *inode, struct file *file)
1433{
1434 return single_open(file, wil_sta_debugfs_show, inode->i_private);
1435}
1436
1437static const struct file_operations fops_sta = {
1438 .open = wil_sta_seq_open,
1439 .release = single_release,
1440 .read = seq_read,
1441 .llseek = seq_lseek,
1442};
1443
Maya Erez10d599a2016-05-09 21:57:11 +03001444static ssize_t wil_read_file_led_cfg(struct file *file, char __user *user_buf,
1445 size_t count, loff_t *ppos)
1446{
1447 char buf[80];
1448 int n;
1449
1450 n = snprintf(buf, sizeof(buf),
1451 "led_id is set to %d, echo 1 to enable, 0 to disable\n",
1452 led_id);
1453
1454 n = min_t(int, n, sizeof(buf));
1455
1456 return simple_read_from_buffer(user_buf, count, ppos,
1457 buf, n);
1458}
1459
1460static ssize_t wil_write_file_led_cfg(struct file *file,
1461 const char __user *buf_,
1462 size_t count, loff_t *ppos)
1463{
1464 struct wil6210_priv *wil = file->private_data;
1465 int val;
1466 int rc;
1467
1468 rc = kstrtoint_from_user(buf_, count, 0, &val);
1469 if (rc) {
1470 wil_err(wil, "Invalid argument\n");
1471 return rc;
1472 }
1473
1474 wil_info(wil, "%s led %d\n", val ? "Enabling" : "Disabling", led_id);
1475 rc = wmi_led_cfg(wil, val);
1476 if (rc) {
1477 wil_info(wil, "%s led %d failed\n",
1478 val ? "Enabling" : "Disabling", led_id);
1479 return rc;
1480 }
1481
1482 return count;
1483}
1484
1485static const struct file_operations fops_led_cfg = {
1486 .read = wil_read_file_led_cfg,
1487 .write = wil_write_file_led_cfg,
1488 .open = simple_open,
1489};
1490
1491/* led_blink_time, write:
1492 * "<blink_on_slow> <blink_off_slow> <blink_on_med> <blink_off_med> <blink_on_fast> <blink_off_fast>
1493 */
1494static ssize_t wil_write_led_blink_time(struct file *file,
1495 const char __user *buf,
1496 size_t len, loff_t *ppos)
1497{
1498 int rc;
1499 char *kbuf = kmalloc(len + 1, GFP_KERNEL);
1500
1501 if (!kbuf)
1502 return -ENOMEM;
1503
1504 rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
1505 if (rc != len) {
1506 kfree(kbuf);
1507 return rc >= 0 ? -EIO : rc;
1508 }
1509
1510 kbuf[len] = '\0';
1511 rc = sscanf(kbuf, "%d %d %d %d %d %d",
1512 &led_blink_time[WIL_LED_TIME_SLOW].on_ms,
1513 &led_blink_time[WIL_LED_TIME_SLOW].off_ms,
1514 &led_blink_time[WIL_LED_TIME_MED].on_ms,
1515 &led_blink_time[WIL_LED_TIME_MED].off_ms,
1516 &led_blink_time[WIL_LED_TIME_FAST].on_ms,
1517 &led_blink_time[WIL_LED_TIME_FAST].off_ms);
1518 kfree(kbuf);
1519
1520 if (rc < 0)
1521 return rc;
1522 if (rc < 6)
1523 return -EINVAL;
1524
1525 return len;
1526}
1527
1528static ssize_t wil_read_led_blink_time(struct file *file, char __user *user_buf,
1529 size_t count, loff_t *ppos)
1530{
1531 static char text[400];
1532
1533 snprintf(text, sizeof(text),
1534 "To set led blink on/off time variables write:\n"
1535 "<blink_on_slow> <blink_off_slow> <blink_on_med> "
1536 "<blink_off_med> <blink_on_fast> <blink_off_fast>\n"
1537 "The current values are:\n"
1538 "%d %d %d %d %d %d\n",
1539 led_blink_time[WIL_LED_TIME_SLOW].on_ms,
1540 led_blink_time[WIL_LED_TIME_SLOW].off_ms,
1541 led_blink_time[WIL_LED_TIME_MED].on_ms,
1542 led_blink_time[WIL_LED_TIME_MED].off_ms,
1543 led_blink_time[WIL_LED_TIME_FAST].on_ms,
1544 led_blink_time[WIL_LED_TIME_FAST].off_ms);
1545
1546 return simple_read_from_buffer(user_buf, count, ppos, text,
1547 sizeof(text));
1548}
1549
1550static const struct file_operations fops_led_blink_time = {
1551 .read = wil_read_led_blink_time,
1552 .write = wil_write_led_blink_time,
1553 .open = simple_open,
1554};
1555
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001556/*----------------*/
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +03001557static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
1558 struct dentry *dbg)
1559{
1560 int i;
1561 char name[32];
1562
1563 for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
Maya Erez349214c2016-04-26 14:41:41 +03001564 struct wil_blob_wrapper *wil_blob = &wil->blobs[i];
1565 struct debugfs_blob_wrapper *blob = &wil_blob->blob;
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +03001566 const struct fw_map *map = &fw_mapping[i];
1567
1568 if (!map->name)
1569 continue;
1570
Maya Erez349214c2016-04-26 14:41:41 +03001571 wil_blob->wil = wil;
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +03001572 blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
1573 blob->size = map->to - map->from;
1574 snprintf(name, sizeof(name), "blob_%s", map->name);
Maya Erez349214c2016-04-26 14:41:41 +03001575 wil_debugfs_create_ioblob(name, S_IRUGO, dbg, wil_blob);
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +03001576 }
1577}
1578
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001579/* misc files */
1580static const struct {
1581 const char *name;
1582 umode_t mode;
1583 const struct file_operations *fops;
1584} dbg_files[] = {
1585 {"mbox", S_IRUGO, &fops_mbox},
1586 {"vrings", S_IRUGO, &fops_vring},
1587 {"stations", S_IRUGO, &fops_sta},
1588 {"desc", S_IRUGO, &fops_txdesc},
1589 {"bf", S_IRUGO, &fops_bf},
1590 {"ssid", S_IRUGO | S_IWUSR, &fops_ssid},
1591 {"mem_val", S_IRUGO, &fops_memread},
1592 {"reset", S_IWUSR, &fops_reset},
1593 {"rxon", S_IWUSR, &fops_rxon},
1594 {"tx_mgmt", S_IWUSR, &fops_txmgmt},
1595 {"wmi_send", S_IWUSR, &fops_wmi},
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +02001596 {"back", S_IRUGO | S_IWUSR, &fops_back},
Vladimir Kondratievdc164272015-04-30 16:25:09 +03001597 {"pmccfg", S_IRUGO | S_IWUSR, &fops_pmccfg},
1598 {"pmcdata", S_IRUGO, &fops_pmcdata},
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001599 {"temp", S_IRUGO, &fops_temp},
1600 {"freq", S_IRUGO, &fops_freq},
1601 {"link", S_IRUGO, &fops_link},
1602 {"info", S_IRUGO, &fops_info},
Vladimir Kondratievc33407a2014-10-01 15:05:24 +03001603 {"recovery", S_IRUGO | S_IWUSR, &fops_recovery},
Maya Erez10d599a2016-05-09 21:57:11 +03001604 {"led_cfg", S_IRUGO | S_IWUSR, &fops_led_cfg},
1605 {"led_blink_time", S_IRUGO | S_IWUSR, &fops_led_blink_time},
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001606};
1607
1608static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
1609 struct dentry *dbg)
1610{
1611 int i;
1612
1613 for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
1614 debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
1615 wil, dbg_files[i].fops);
1616}
1617
1618/* interrupt control blocks */
1619static const struct {
1620 const char *name;
1621 u32 icr_off;
1622} dbg_icr[] = {
1623 {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)},
1624 {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)},
1625 {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)},
1626 {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)},
1627};
1628
1629static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
1630 struct dentry *dbg)
1631{
1632 int i;
1633
1634 for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
1635 wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
1636 dbg_icr[i].icr_off);
1637}
1638
1639#define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
1640 offsetof(struct wil6210_priv, name), type}
1641
1642/* fields in struct wil6210_priv */
1643static const struct dbg_off dbg_wil_off[] = {
Vladimir Kondratiev774974e2015-02-15 14:02:36 +02001644 WIL_FIELD(privacy, S_IRUGO, doff_u32),
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +02001645 WIL_FIELD(status[0], S_IRUGO | S_IWUSR, doff_ulong),
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001646 WIL_FIELD(fw_version, S_IRUGO, doff_u32),
1647 WIL_FIELD(hw_version, S_IRUGO, doff_x32),
Vladimir Kondratievc33407a2014-10-01 15:05:24 +03001648 WIL_FIELD(recovery_count, S_IRUGO, doff_u32),
Vladimir Kondratiev02beaf12015-03-08 15:42:03 +02001649 WIL_FIELD(ap_isolate, S_IRUGO, doff_u32),
Lior David74997a52016-03-01 19:18:08 +02001650 WIL_FIELD(discovery_mode, S_IRUGO | S_IWUSR, doff_u8),
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001651 {},
1652};
1653
1654static const struct dbg_off dbg_wil_regs[] = {
1655 {"RGF_MAC_MTRL_COUNTER_0", S_IRUGO, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
1656 doff_io32},
1657 {"RGF_USER_USAGE_1", S_IRUGO, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
1658 {},
1659};
1660
1661/* static parameters */
1662static const struct dbg_off dbg_statics[] = {
1663 {"desc_index", S_IRUGO | S_IWUSR, (ulong)&dbg_txdesc_index, doff_u32},
1664 {"vring_index", S_IRUGO | S_IWUSR, (ulong)&dbg_vring_index, doff_u32},
1665 {"mem_addr", S_IRUGO | S_IWUSR, (ulong)&mem_addr, doff_u32},
Vladimir Shulman0436fd92015-02-15 14:02:34 +02001666 {"vring_idle_trsh", S_IRUGO | S_IWUSR, (ulong)&vring_idle_trsh,
1667 doff_u32},
Maya Erez10d599a2016-05-09 21:57:11 +03001668 {"led_polarity", S_IRUGO | S_IWUSR, (ulong)&led_polarity, doff_u8},
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001669 {},
1670};
1671
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001672int wil6210_debugfs_init(struct wil6210_priv *wil)
1673{
1674 struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
1675 wil_to_wiphy(wil)->debugfsdir);
1676
1677 if (IS_ERR_OR_NULL(dbg))
1678 return -ENODEV;
1679
Vladimir Kondratievdc164272015-04-30 16:25:09 +03001680 wil_pmc_init(wil);
1681
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001682 wil6210_debugfs_init_files(wil, dbg);
1683 wil6210_debugfs_init_isr(wil, dbg);
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +03001684 wil6210_debugfs_init_blobs(wil, dbg);
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001685 wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
1686 wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
1687 dbg_wil_regs);
1688 wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
1689
1690 wil6210_debugfs_create_pseudo_ISR(wil, dbg);
1691
1692 wil6210_debugfs_create_ITR_CNT(wil, dbg);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001693
1694 return 0;
1695}
1696
1697void wil6210_debugfs_remove(struct wil6210_priv *wil)
1698{
1699 debugfs_remove_recursive(wil->debug);
1700 wil->debug = NULL;
Vladimir Kondratievdc164272015-04-30 16:25:09 +03001701
1702 /* free pmc memory without sending command to fw, as it will
1703 * be reset on the way down anyway
1704 */
1705 wil_pmc_free(wil, false);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001706}