blob: cd991fa1cc3f329626d87d593e5f9e92431e6cd1 [file] [log] [blame]
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001/*
Vladimir Kondratiev02525a72014-08-06 10:31:51 +03002 * Copyright (c) 2012-2014 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"
27
28/* Nasty hack. Better have per device instances */
29static u32 mem_addr;
30static u32 dbg_txdesc_index;
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +020031static u32 dbg_vring_index; /* 24+ for Rx, 0..23 for Tx */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080032
Vladimir Kondratievb7cde472014-08-06 10:31:55 +030033enum dbg_off_type {
34 doff_u32 = 0,
35 doff_x32 = 1,
36 doff_ulong = 2,
37 doff_io32 = 3,
38};
39
40/* offset to "wil" */
41struct dbg_off {
42 const char *name;
43 umode_t mode;
44 ulong off;
45 enum dbg_off_type type;
46};
47
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080048static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil,
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +020049 const char *name, struct vring *vring,
50 char _s, char _h)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080051{
52 void __iomem *x = wmi_addr(wil, vring->hwtail);
53
54 seq_printf(s, "VRING %s = {\n", name);
Vladimir Kondratiev39c52ee2014-05-27 14:45:49 +030055 seq_printf(s, " pa = %pad\n", &vring->pa);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080056 seq_printf(s, " va = 0x%p\n", vring->va);
57 seq_printf(s, " size = %d\n", vring->size);
58 seq_printf(s, " swtail = %d\n", vring->swtail);
59 seq_printf(s, " swhead = %d\n", vring->swhead);
60 seq_printf(s, " hwtail = [0x%08x] -> ", vring->hwtail);
61 if (x)
62 seq_printf(s, "0x%08x\n", ioread32(x));
63 else
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030064 seq_puts(s, "???\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080065
66 if (vring->va && (vring->size < 1025)) {
67 uint i;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030068
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080069 for (i = 0; i < vring->size; i++) {
70 volatile struct vring_tx_desc *d = &vring->va[i].tx;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030071
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080072 if ((i % 64) == 0 && (i != 0))
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030073 seq_puts(s, "\n");
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +020074 seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
75 _s : (vring->ctx[i].skb ? _h : 'h'));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080076 }
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030077 seq_puts(s, "\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080078 }
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030079 seq_puts(s, "}\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080080}
81
82static int wil_vring_debugfs_show(struct seq_file *s, void *data)
83{
84 uint i;
85 struct wil6210_priv *wil = s->private;
86
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +020087 wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_');
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080088
89 for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030090 struct vring *vring = &wil->vring_tx[i];
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +030091 struct vring_tx_data *txdata = &wil->vring_tx_data[i];
92
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080093 if (vring->va) {
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +020094 int cid = wil->vring2cid_tid[i][0];
95 int tid = wil->vring2cid_tid[i][1];
Vladimir Kondratiev67c3e1b2014-06-16 19:37:04 +030096 u32 swhead = vring->swhead;
97 u32 swtail = vring->swtail;
98 int used = (vring->size + swhead - swtail)
99 % vring->size;
100 int avail = vring->size - used - 1;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800101 char name[10];
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +0300102 /* performance monitoring */
103 cycles_t now = get_cycles();
Chen Gangc20e7782014-12-24 23:08:44 +0800104 uint64_t idle = txdata->idle * 100;
105 uint64_t total = now - txdata->begin;
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +0300106
Vladimir Kondratieve48b1792014-06-20 10:05:07 +0300107 do_div(idle, total);
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +0300108 txdata->begin = now;
109 txdata->idle = 0ULL;
110
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800111 snprintf(name, sizeof(name), "tx_%2d", i);
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200112
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +0300113 seq_printf(s, "\n%pM CID %d TID %d [%3d|%3d] idle %3d%%\n",
114 wil->sta[cid].addr, cid, tid, used, avail,
Vladimir Kondratieve48b1792014-06-20 10:05:07 +0300115 (int)idle);
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +0300116
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +0200117 wil_print_vring(s, wil, name, vring, '_', 'H');
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800118 }
119 }
120
121 return 0;
122}
123
124static int wil_vring_seq_open(struct inode *inode, struct file *file)
125{
126 return single_open(file, wil_vring_debugfs_show, inode->i_private);
127}
128
129static const struct file_operations fops_vring = {
130 .open = wil_vring_seq_open,
131 .release = single_release,
132 .read = seq_read,
133 .llseek = seq_lseek,
134};
135
136static void wil_print_ring(struct seq_file *s, const char *prefix,
137 void __iomem *off)
138{
139 struct wil6210_priv *wil = s->private;
140 struct wil6210_mbox_ring r;
141 int rsize;
142 uint i;
143
144 wil_memcpy_fromio_32(&r, off, sizeof(r));
145 wil_mbox_ring_le2cpus(&r);
146 /*
147 * we just read memory block from NIC. This memory may be
148 * garbage. Check validity before using it.
149 */
150 rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
151
152 seq_printf(s, "ring %s = {\n", prefix);
153 seq_printf(s, " base = 0x%08x\n", r.base);
154 seq_printf(s, " size = 0x%04x bytes -> %d entries\n", r.size, rsize);
155 seq_printf(s, " tail = 0x%08x\n", r.tail);
156 seq_printf(s, " head = 0x%08x\n", r.head);
157 seq_printf(s, " entry size = %d\n", r.entry_size);
158
159 if (r.size % sizeof(struct wil6210_mbox_ring_desc)) {
160 seq_printf(s, " ??? size is not multiple of %zd, garbage?\n",
161 sizeof(struct wil6210_mbox_ring_desc));
162 goto out;
163 }
164
165 if (!wmi_addr(wil, r.base) ||
166 !wmi_addr(wil, r.tail) ||
167 !wmi_addr(wil, r.head)) {
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300168 seq_puts(s, " ??? pointers are garbage?\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800169 goto out;
170 }
171
172 for (i = 0; i < rsize; i++) {
173 struct wil6210_mbox_ring_desc d;
174 struct wil6210_mbox_hdr hdr;
175 size_t delta = i * sizeof(d);
176 void __iomem *x = wil->csr + HOSTADDR(r.base) + delta;
177
178 wil_memcpy_fromio_32(&d, x, sizeof(d));
179
180 seq_printf(s, " [%2x] %s %s%s 0x%08x", i,
181 d.sync ? "F" : "E",
182 (r.tail - r.base == delta) ? "t" : " ",
183 (r.head - r.base == delta) ? "h" : " ",
184 le32_to_cpu(d.addr));
185 if (0 == wmi_read_hdr(wil, d.addr, &hdr)) {
186 u16 len = le16_to_cpu(hdr.len);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300187
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800188 seq_printf(s, " -> %04x %04x %04x %02x\n",
189 le16_to_cpu(hdr.seq), len,
190 le16_to_cpu(hdr.type), hdr.flags);
191 if (len <= MAX_MBOXITEM_SIZE) {
192 int n = 0;
Larry Finger5d216082013-07-20 21:46:48 -0500193 char printbuf[16 * 3 + 2];
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800194 unsigned char databuf[MAX_MBOXITEM_SIZE];
195 void __iomem *src = wmi_buffer(wil, d.addr) +
196 sizeof(struct wil6210_mbox_hdr);
197 /*
198 * No need to check @src for validity -
199 * we already validated @d.addr while
200 * reading header
201 */
202 wil_memcpy_fromio_32(databuf, src, len);
203 while (n < len) {
204 int l = min(len - n, 16);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300205
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800206 hex_dump_to_buffer(databuf + n, l,
207 16, 1, printbuf,
208 sizeof(printbuf),
209 false);
210 seq_printf(s, " : %s\n", printbuf);
211 n += l;
212 }
213 }
214 } else {
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300215 seq_puts(s, "\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800216 }
217 }
218 out:
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300219 seq_puts(s, "}\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800220}
221
222static int wil_mbox_debugfs_show(struct seq_file *s, void *data)
223{
224 struct wil6210_priv *wil = s->private;
225
226 wil_print_ring(s, "tx", wil->csr + HOST_MBOX +
227 offsetof(struct wil6210_mbox_ctl, tx));
228 wil_print_ring(s, "rx", wil->csr + HOST_MBOX +
229 offsetof(struct wil6210_mbox_ctl, rx));
230
231 return 0;
232}
233
234static int wil_mbox_seq_open(struct inode *inode, struct file *file)
235{
236 return single_open(file, wil_mbox_debugfs_show, inode->i_private);
237}
238
239static const struct file_operations fops_mbox = {
240 .open = wil_mbox_seq_open,
241 .release = single_release,
242 .read = seq_read,
243 .llseek = seq_lseek,
244};
245
246static int wil_debugfs_iomem_x32_set(void *data, u64 val)
247{
248 iowrite32(val, (void __iomem *)data);
249 wmb(); /* make sure write propagated to HW */
250
251 return 0;
252}
253
254static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
255{
256 *val = ioread32((void __iomem *)data);
257
258 return 0;
259}
260
261DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
262 wil_debugfs_iomem_x32_set, "0x%08llx\n");
263
264static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
Al Viro0ecc8332013-03-29 12:23:28 -0400265 umode_t mode,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800266 struct dentry *parent,
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300267 void *value)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800268{
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300269 return debugfs_create_file(name, mode, parent, value,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800270 &fops_iomem_x32);
271}
272
Vladimir Kondratiev3de6cf22014-06-16 19:37:02 +0300273static int wil_debugfs_ulong_set(void *data, u64 val)
274{
275 *(ulong *)data = val;
276 return 0;
277}
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300278
Vladimir Kondratiev3de6cf22014-06-16 19:37:02 +0300279static int wil_debugfs_ulong_get(void *data, u64 *val)
280{
281 *val = *(ulong *)data;
282 return 0;
283}
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300284
Vladimir Kondratiev3de6cf22014-06-16 19:37:02 +0300285DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
286 wil_debugfs_ulong_set, "%llu\n");
287
288static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode,
289 struct dentry *parent,
290 ulong *value)
291{
292 return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong);
293}
294
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300295/**
296 * wil6210_debugfs_init_offset - create set of debugfs files
297 * @wil - driver's context, used for printing
298 * @dbg - directory on the debugfs, where files will be created
299 * @base - base address used in address calculation
300 * @tbl - table with file descriptions. Should be terminated with empty element.
301 *
302 * Creates files accordingly to the @tbl.
303 */
304static void wil6210_debugfs_init_offset(struct wil6210_priv *wil,
305 struct dentry *dbg, void *base,
306 const struct dbg_off * const tbl)
307{
308 int i;
309
310 for (i = 0; tbl[i].name; i++) {
Vladimir Kondratiev867fa0d2014-09-10 16:34:51 +0300311 struct dentry *f;
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300312
313 switch (tbl[i].type) {
314 case doff_u32:
315 f = debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg,
316 base + tbl[i].off);
317 break;
318 case doff_x32:
319 f = debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg,
320 base + tbl[i].off);
321 break;
322 case doff_ulong:
323 f = wil_debugfs_create_ulong(tbl[i].name, tbl[i].mode,
324 dbg, base + tbl[i].off);
325 break;
326 case doff_io32:
327 f = wil_debugfs_create_iomem_x32(tbl[i].name,
328 tbl[i].mode, dbg,
329 base + tbl[i].off);
330 break;
Vladimir Kondratiev867fa0d2014-09-10 16:34:51 +0300331 default:
332 f = ERR_PTR(-EINVAL);
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300333 }
334 if (IS_ERR_OR_NULL(f))
335 wil_err(wil, "Create file \"%s\": err %ld\n",
336 tbl[i].name, PTR_ERR(f));
337 }
338}
339
340static const struct dbg_off isr_off[] = {
341 {"ICC", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICC), doff_io32},
342 {"ICR", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICR), doff_io32},
343 {"ICM", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICM), doff_io32},
344 {"ICS", S_IWUSR, offsetof(struct RGF_ICR, ICS), doff_io32},
345 {"IMV", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, IMV), doff_io32},
346 {"IMS", S_IWUSR, offsetof(struct RGF_ICR, IMS), doff_io32},
347 {"IMC", S_IWUSR, offsetof(struct RGF_ICR, IMC), doff_io32},
348 {},
349};
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300350
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800351static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
352 const char *name,
353 struct dentry *parent, u32 off)
354{
355 struct dentry *d = debugfs_create_dir(name, parent);
356
357 if (IS_ERR_OR_NULL(d))
358 return -ENODEV;
359
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300360 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off,
361 isr_off);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800362
363 return 0;
364}
365
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300366static const struct dbg_off pseudo_isr_off[] = {
367 {"CAUSE", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32},
368 {"MASK_SW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32},
369 {"MASK_FW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32},
370 {},
371};
372
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800373static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
374 struct dentry *parent)
375{
376 struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
377
378 if (IS_ERR_OR_NULL(d))
379 return -ENODEV;
380
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300381 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
382 pseudo_isr_off);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800383
384 return 0;
385}
386
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300387static const struct dbg_off itr_cnt_off[] = {
388 {"TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32},
389 {"DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32},
390 {"CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32},
391 {},
392};
393
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800394static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
395 struct dentry *parent)
396{
397 struct dentry *d = debugfs_create_dir("ITR_CNT", parent);
398
399 if (IS_ERR_OR_NULL(d))
400 return -ENODEV;
401
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300402 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
403 itr_cnt_off);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800404
405 return 0;
406}
407
408static int wil_memread_debugfs_show(struct seq_file *s, void *data)
409{
410 struct wil6210_priv *wil = s->private;
411 void __iomem *a = wmi_buffer(wil, cpu_to_le32(mem_addr));
412
413 if (a)
414 seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, ioread32(a));
415 else
416 seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
417
418 return 0;
419}
420
421static int wil_memread_seq_open(struct inode *inode, struct file *file)
422{
423 return single_open(file, wil_memread_debugfs_show, inode->i_private);
424}
425
426static const struct file_operations fops_memread = {
427 .open = wil_memread_seq_open,
428 .release = single_release,
429 .read = seq_read,
430 .llseek = seq_lseek,
431};
432
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800433static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300434 size_t count, loff_t *ppos)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800435{
436 enum { max_count = 4096 };
437 struct debugfs_blob_wrapper *blob = file->private_data;
438 loff_t pos = *ppos;
439 size_t available = blob->size;
440 void *buf;
441 size_t ret;
442
443 if (pos < 0)
444 return -EINVAL;
445
446 if (pos >= available || !count)
447 return 0;
448
449 if (count > available - pos)
450 count = available - pos;
451 if (count > max_count)
452 count = max_count;
453
454 buf = kmalloc(count, GFP_KERNEL);
455 if (!buf)
456 return -ENOMEM;
457
458 wil_memcpy_fromio_32(buf, (const volatile void __iomem *)blob->data +
459 pos, count);
460
461 ret = copy_to_user(user_buf, buf, count);
462 kfree(buf);
463 if (ret == count)
464 return -EFAULT;
465
466 count -= ret;
467 *ppos = pos + count;
468
469 return count;
470}
471
472static const struct file_operations fops_ioblob = {
473 .read = wil_read_file_ioblob,
Wei Yongjun93ecbd62013-02-26 10:29:34 +0800474 .open = simple_open,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800475 .llseek = default_llseek,
476};
477
478static
479struct dentry *wil_debugfs_create_ioblob(const char *name,
Al Viro0ecc8332013-03-29 12:23:28 -0400480 umode_t mode,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800481 struct dentry *parent,
482 struct debugfs_blob_wrapper *blob)
483{
484 return debugfs_create_file(name, mode, parent, blob, &fops_ioblob);
485}
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300486
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800487/*---reset---*/
488static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
489 size_t len, loff_t *ppos)
490{
491 struct wil6210_priv *wil = file->private_data;
492 struct net_device *ndev = wil_to_ndev(wil);
493
494 /**
495 * BUG:
496 * this code does NOT sync device state with the rest of system
497 * use with care, debug only!!!
498 */
499 rtnl_lock();
500 dev_close(ndev);
501 ndev->flags &= ~IFF_UP;
502 rtnl_unlock();
503 wil_reset(wil);
504
505 return len;
506}
507
508static const struct file_operations fops_reset = {
509 .write = wil_write_file_reset,
Wei Yongjun93ecbd62013-02-26 10:29:34 +0800510 .open = simple_open,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800511};
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300512
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300513/*---write channel 1..4 to rxon for it, 0 to rxoff---*/
514static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
515 size_t len, loff_t *ppos)
516{
517 struct wil6210_priv *wil = file->private_data;
518 int rc;
519 long channel;
520 bool on;
521
522 char *kbuf = kmalloc(len + 1, GFP_KERNEL);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300523
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300524 if (!kbuf)
525 return -ENOMEM;
Vladimir Kondratiev359ee622014-07-14 09:49:40 +0300526 if (copy_from_user(kbuf, buf, len)) {
527 kfree(kbuf);
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300528 return -EIO;
Vladimir Kondratiev359ee622014-07-14 09:49:40 +0300529 }
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300530
531 kbuf[len] = '\0';
532 rc = kstrtol(kbuf, 0, &channel);
533 kfree(kbuf);
534 if (rc)
535 return rc;
536
537 if ((channel < 0) || (channel > 4)) {
538 wil_err(wil, "Invalid channel %ld\n", channel);
539 return -EINVAL;
540 }
541 on = !!channel;
542
543 if (on) {
544 rc = wmi_set_channel(wil, (int)channel);
545 if (rc)
546 return rc;
547 }
548
549 rc = wmi_rxon(wil, on);
550 if (rc)
551 return rc;
552
553 return len;
554}
555
556static const struct file_operations fops_rxon = {
557 .write = wil_write_file_rxon,
558 .open = simple_open,
559};
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300560
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300561/*---tx_mgmt---*/
562/* Write mgmt frame to this file to send it */
563static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
564 size_t len, loff_t *ppos)
565{
566 struct wil6210_priv *wil = file->private_data;
567 struct wiphy *wiphy = wil_to_wiphy(wil);
568 struct wireless_dev *wdev = wil_to_wdev(wil);
569 struct cfg80211_mgmt_tx_params params;
570 int rc;
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300571 void *frame = kmalloc(len, GFP_KERNEL);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300572
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300573 if (!frame)
574 return -ENOMEM;
575
Lino Sanfilippo8e09b7d2014-11-28 02:47:19 +0100576 if (copy_from_user(frame, buf, len)) {
577 kfree(frame);
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300578 return -EIO;
Lino Sanfilippo8e09b7d2014-11-28 02:47:19 +0100579 }
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300580
581 params.buf = frame;
582 params.len = len;
583 params.chan = wdev->preset_chandef.chan;
584
585 rc = wil_cfg80211_mgmt_tx(wiphy, wdev, &params, NULL);
586
587 kfree(frame);
588 wil_info(wil, "%s() -> %d\n", __func__, rc);
589
590 return len;
591}
592
593static const struct file_operations fops_txmgmt = {
594 .write = wil_write_file_txmgmt,
595 .open = simple_open,
596};
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800597
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300598/* Write WMI command (w/o mbox header) to this file to send it
599 * WMI starts from wil6210_mbox_hdr_wmi header
600 */
601static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
602 size_t len, loff_t *ppos)
603{
604 struct wil6210_priv *wil = file->private_data;
605 struct wil6210_mbox_hdr_wmi *wmi;
606 void *cmd;
607 int cmdlen = len - sizeof(struct wil6210_mbox_hdr_wmi);
608 u16 cmdid;
609 int rc, rc1;
610
611 if (cmdlen <= 0)
612 return -EINVAL;
613
614 wmi = kmalloc(len, GFP_KERNEL);
615 if (!wmi)
616 return -ENOMEM;
617
618 rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
Lino Sanfilippo8e09b7d2014-11-28 02:47:19 +0100619 if (rc < 0) {
620 kfree(wmi);
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300621 return rc;
Lino Sanfilippo8e09b7d2014-11-28 02:47:19 +0100622 }
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300623
624 cmd = &wmi[1];
625 cmdid = le16_to_cpu(wmi->id);
626
627 rc1 = wmi_send(wil, cmdid, cmd, cmdlen);
628 kfree(wmi);
629
630 wil_info(wil, "%s(0x%04x[%d]) -> %d\n", __func__, cmdid, cmdlen, rc1);
631
632 return rc;
633}
634
635static const struct file_operations fops_wmi = {
636 .write = wil_write_file_wmi,
637 .open = simple_open,
638};
639
Vladimir Kondratievc2366582014-03-17 15:34:08 +0200640static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
641 const char *prefix)
642{
643 char printbuf[16 * 3 + 2];
644 int i = 0;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300645
Vladimir Kondratievc2366582014-03-17 15:34:08 +0200646 while (i < len) {
647 int l = min(len - i, 16);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300648
Vladimir Kondratievc2366582014-03-17 15:34:08 +0200649 hex_dump_to_buffer(p + i, l, 16, 1, printbuf,
650 sizeof(printbuf), false);
651 seq_printf(s, "%s%s\n", prefix, printbuf);
652 i += l;
653 }
654}
655
656static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
657{
658 int i = 0;
659 int len = skb_headlen(skb);
660 void *p = skb->data;
661 int nr_frags = skb_shinfo(skb)->nr_frags;
662
663 seq_printf(s, " len = %d\n", len);
664 wil_seq_hexdump(s, p, len, " : ");
665
666 if (nr_frags) {
667 seq_printf(s, " nr_frags = %d\n", nr_frags);
668 for (i = 0; i < nr_frags; i++) {
669 const struct skb_frag_struct *frag =
670 &skb_shinfo(skb)->frags[i];
671
672 len = skb_frag_size(frag);
673 p = skb_frag_address_safe(frag);
674 seq_printf(s, " [%2d] : len = %d\n", i, len);
675 wil_seq_hexdump(s, p, len, " : ");
676 }
677 }
678}
679
Vladimir Kondratiev3a85543e2014-02-27 16:20:41 +0200680/*---------Tx/Rx descriptor------------*/
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800681static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
682{
683 struct wil6210_priv *wil = s->private;
Vladimir Kondratiev3a85543e2014-02-27 16:20:41 +0200684 struct vring *vring;
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +0200685 bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300686
687 vring = tx ? &wil->vring_tx[dbg_vring_index] : &wil->vring_rx;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800688
689 if (!vring->va) {
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +0200690 if (tx)
Vladimir Kondratiev3a85543e2014-02-27 16:20:41 +0200691 seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index);
692 else
693 seq_puts(s, "No Rx VRING\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800694 return 0;
695 }
696
697 if (dbg_txdesc_index < vring->size) {
Vladimir Kondratiev3a85543e2014-02-27 16:20:41 +0200698 /* use struct vring_tx_desc for Rx as well,
699 * only field used, .dma.length, is the same
700 */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800701 volatile struct vring_tx_desc *d =
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300702 &vring->va[dbg_txdesc_index].tx;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800703 volatile u32 *u = (volatile u32 *)d;
Vladimir Kondratievf88f1132013-07-11 18:03:40 +0300704 struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800705
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +0200706 if (tx)
Vladimir Kondratiev3a85543e2014-02-27 16:20:41 +0200707 seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index,
708 dbg_txdesc_index);
709 else
710 seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800711 seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
712 u[0], u[1], u[2], u[3]);
713 seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
714 u[4], u[5], u[6], u[7]);
Vladimir Kondratiev39c52ee2014-05-27 14:45:49 +0300715 seq_printf(s, " SKB = 0x%p\n", skb);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800716
717 if (skb) {
Vladimir Kondratievc2366582014-03-17 15:34:08 +0200718 skb_get(skb);
719 wil_seq_print_skb(s, skb);
720 kfree_skb(skb);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800721 }
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300722 seq_puts(s, "}\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800723 } else {
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +0200724 if (tx)
Vladimir Kondratiev3a85543e2014-02-27 16:20:41 +0200725 seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
726 dbg_vring_index, dbg_txdesc_index,
727 vring->size);
728 else
729 seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
730 dbg_txdesc_index, vring->size);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800731 }
732
733 return 0;
734}
735
736static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
737{
738 return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
739}
740
741static const struct file_operations fops_txdesc = {
742 .open = wil_txdesc_seq_open,
743 .release = single_release,
744 .read = seq_read,
745 .llseek = seq_lseek,
746};
747
748/*---------beamforming------------*/
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +0300749static char *wil_bfstatus_str(u32 status)
750{
751 switch (status) {
752 case 0:
753 return "Failed";
754 case 1:
755 return "OK";
756 case 2:
757 return "Retrying";
758 default:
759 return "??";
760 }
761}
762
763static bool is_all_zeros(void * const x_, size_t sz)
764{
765 /* if reply is all-0, ignore this CID */
766 u32 *x = x_;
767 int n;
768
769 for (n = 0; n < sz / sizeof(*x); n++)
770 if (x[n])
771 return false;
772
773 return true;
774}
775
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800776static int wil_bf_debugfs_show(struct seq_file *s, void *data)
777{
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +0300778 int rc;
779 int i;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800780 struct wil6210_priv *wil = s->private;
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +0300781 struct wmi_notify_req_cmd cmd = {
782 .interval_usec = 0,
783 };
784 struct {
785 struct wil6210_mbox_hdr_wmi wmi;
786 struct wmi_notify_req_done_event evt;
787 } __packed reply;
788
789 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
790 u32 status;
791
792 cmd.cid = i;
793 rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd),
794 WMI_NOTIFY_REQ_DONE_EVENTID, &reply,
795 sizeof(reply), 20);
796 /* if reply is all-0, ignore this CID */
797 if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt)))
798 continue;
799
800 status = le32_to_cpu(reply.evt.status);
801 seq_printf(s, "CID %d {\n"
802 " TSF = 0x%016llx\n"
803 " TxMCS = %2d TxTpt = %4d\n"
804 " SQI = %4d\n"
805 " Status = 0x%08x %s\n"
806 " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
807 " Goodput(rx:tx) %4d:%4d\n"
808 "}\n",
809 i,
810 le64_to_cpu(reply.evt.tsf),
811 le16_to_cpu(reply.evt.bf_mcs),
812 le32_to_cpu(reply.evt.tx_tpt),
813 reply.evt.sqi,
814 status, wil_bfstatus_str(status),
815 le16_to_cpu(reply.evt.my_rx_sector),
816 le16_to_cpu(reply.evt.my_tx_sector),
817 le16_to_cpu(reply.evt.other_rx_sector),
818 le16_to_cpu(reply.evt.other_tx_sector),
819 le32_to_cpu(reply.evt.rx_goodput),
820 le32_to_cpu(reply.evt.tx_goodput));
821 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800822 return 0;
823}
824
825static int wil_bf_seq_open(struct inode *inode, struct file *file)
826{
827 return single_open(file, wil_bf_debugfs_show, inode->i_private);
828}
829
830static const struct file_operations fops_bf = {
831 .open = wil_bf_seq_open,
832 .release = single_release,
833 .read = seq_read,
834 .llseek = seq_lseek,
835};
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300836
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800837/*---------SSID------------*/
838static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf,
839 size_t count, loff_t *ppos)
840{
841 struct wil6210_priv *wil = file->private_data;
842 struct wireless_dev *wdev = wil_to_wdev(wil);
843
844 return simple_read_from_buffer(user_buf, count, ppos,
845 wdev->ssid, wdev->ssid_len);
846}
847
848static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf,
849 size_t count, loff_t *ppos)
850{
851 struct wil6210_priv *wil = file->private_data;
852 struct wireless_dev *wdev = wil_to_wdev(wil);
853 struct net_device *ndev = wil_to_ndev(wil);
854
855 if (*ppos != 0) {
856 wil_err(wil, "Unable to set SSID substring from [%d]\n",
857 (int)*ppos);
858 return -EINVAL;
859 }
860
861 if (count > sizeof(wdev->ssid)) {
862 wil_err(wil, "SSID too long, len = %d\n", (int)count);
863 return -EINVAL;
864 }
865 if (netif_running(ndev)) {
866 wil_err(wil, "Unable to change SSID on running interface\n");
867 return -EINVAL;
868 }
869
870 wdev->ssid_len = count;
871 return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos,
872 buf, count);
873}
874
875static const struct file_operations fops_ssid = {
876 .read = wil_read_file_ssid,
877 .write = wil_write_file_ssid,
Wei Yongjun93ecbd62013-02-26 10:29:34 +0800878 .open = simple_open,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800879};
880
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +0200881/*---------temp------------*/
882static void print_temp(struct seq_file *s, const char *prefix, u32 t)
883{
884 switch (t) {
885 case 0:
886 case ~(u32)0:
887 seq_printf(s, "%s N/A\n", prefix);
888 break;
889 default:
890 seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
891 break;
892 }
893}
894
895static int wil_temp_debugfs_show(struct seq_file *s, void *data)
896{
897 struct wil6210_priv *wil = s->private;
898 u32 t_m, t_r;
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +0200899 int rc = wmi_get_temperature(wil, &t_m, &t_r);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300900
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +0200901 if (rc) {
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300902 seq_puts(s, "Failed\n");
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +0200903 return 0;
904 }
905
Vladimir Kondratievd45cff92014-06-16 19:37:12 +0300906 print_temp(s, "T_mac =", t_m);
907 print_temp(s, "T_radio =", t_r);
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +0200908
909 return 0;
910}
911
912static int wil_temp_seq_open(struct inode *inode, struct file *file)
913{
914 return single_open(file, wil_temp_debugfs_show, inode->i_private);
915}
916
917static const struct file_operations fops_temp = {
918 .open = wil_temp_seq_open,
919 .release = single_release,
920 .read = seq_read,
921 .llseek = seq_lseek,
922};
923
Vladimir Kondratiev9eb82d42014-06-16 19:37:13 +0300924/*---------freq------------*/
925static int wil_freq_debugfs_show(struct seq_file *s, void *data)
926{
927 struct wil6210_priv *wil = s->private;
928 struct wireless_dev *wdev = wil_to_wdev(wil);
929 u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
930
931 seq_printf(s, "Freq = %d\n", freq);
932
933 return 0;
934}
935
936static int wil_freq_seq_open(struct inode *inode, struct file *file)
937{
938 return single_open(file, wil_freq_debugfs_show, inode->i_private);
939}
940
941static const struct file_operations fops_freq = {
942 .open = wil_freq_seq_open,
943 .release = single_release,
944 .read = seq_read,
945 .llseek = seq_lseek,
946};
947
948/*---------link------------*/
949static int wil_link_debugfs_show(struct seq_file *s, void *data)
950{
951 struct wil6210_priv *wil = s->private;
952 struct station_info sinfo;
953 int i, rc;
954
955 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
956 struct wil_sta_info *p = &wil->sta[i];
957 char *status = "unknown";
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300958
Vladimir Kondratiev9eb82d42014-06-16 19:37:13 +0300959 switch (p->status) {
960 case wil_sta_unused:
961 status = "unused ";
962 break;
963 case wil_sta_conn_pending:
964 status = "pending ";
965 break;
966 case wil_sta_connected:
967 status = "connected";
968 break;
969 }
970 seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
971 (p->data_port_open ? " data_port_open" : ""));
972
973 if (p->status == wil_sta_connected) {
974 rc = wil_cid_fill_sinfo(wil, i, &sinfo);
975 if (rc)
976 return rc;
977
978 seq_printf(s, " Tx_mcs = %d\n", sinfo.txrate.mcs);
979 seq_printf(s, " Rx_mcs = %d\n", sinfo.rxrate.mcs);
980 seq_printf(s, " SQ = %d\n", sinfo.signal);
981 }
982 }
983
984 return 0;
985}
986
987static int wil_link_seq_open(struct inode *inode, struct file *file)
988{
989 return single_open(file, wil_link_debugfs_show, inode->i_private);
990}
991
992static const struct file_operations fops_link = {
993 .open = wil_link_seq_open,
994 .release = single_release,
995 .read = seq_read,
996 .llseek = seq_lseek,
997};
998
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +0300999/*---------info------------*/
1000static int wil_info_debugfs_show(struct seq_file *s, void *data)
1001{
Vladimir Kondratievbe299852014-06-16 19:37:22 +03001002 struct wil6210_priv *wil = s->private;
1003 struct net_device *ndev = wil_to_ndev(wil);
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +03001004 int is_ac = power_supply_is_system_supplied();
Vladimir Kondratievbe299852014-06-16 19:37:22 +03001005 int rx = atomic_xchg(&wil->isr_count_rx, 0);
1006 int tx = atomic_xchg(&wil->isr_count_tx, 0);
1007 static ulong rxf_old, txf_old;
1008 ulong rxf = ndev->stats.rx_packets;
1009 ulong txf = ndev->stats.tx_packets;
Vladimir Kondratiev55f8f682014-06-16 19:37:23 +03001010 unsigned int i;
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +03001011
1012 /* >0 : AC; 0 : battery; <0 : error */
1013 seq_printf(s, "AC powered : %d\n", is_ac);
Vladimir Kondratievbe299852014-06-16 19:37:22 +03001014 seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
1015 seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
1016 rxf_old = rxf;
1017 txf_old = txf;
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +03001018
Vladimir Kondratiev55f8f682014-06-16 19:37:23 +03001019#define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
1020 " " __stringify(x) : ""
1021
1022 for (i = 0; i < ndev->num_tx_queues; i++) {
1023 struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
1024 unsigned long state = txq->state;
1025
1026 seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
1027 CHECK_QSTATE(DRV_XOFF),
1028 CHECK_QSTATE(STACK_XOFF),
1029 CHECK_QSTATE(FROZEN)
1030 );
1031 }
1032#undef CHECK_QSTATE
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +03001033 return 0;
1034}
1035
1036static int wil_info_seq_open(struct inode *inode, struct file *file)
1037{
1038 return single_open(file, wil_info_debugfs_show, inode->i_private);
1039}
1040
1041static const struct file_operations fops_info = {
1042 .open = wil_info_seq_open,
1043 .release = single_release,
1044 .read = seq_read,
1045 .llseek = seq_lseek,
1046};
1047
Vladimir Kondratievc33407a2014-10-01 15:05:24 +03001048/*---------recovery------------*/
1049/* mode = [manual|auto]
1050 * state = [idle|pending|running]
1051 */
1052static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf,
1053 size_t count, loff_t *ppos)
1054{
1055 struct wil6210_priv *wil = file->private_data;
1056 char buf[80];
1057 int n;
1058 static const char * const sstate[] = {"idle", "pending", "running"};
1059
1060 n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n",
1061 no_fw_recovery ? "manual" : "auto",
1062 sstate[wil->recovery_state]);
1063
1064 n = min_t(int, n, sizeof(buf));
1065
1066 return simple_read_from_buffer(user_buf, count, ppos,
1067 buf, n);
1068}
1069
1070static ssize_t wil_write_file_recovery(struct file *file,
1071 const char __user *buf_,
1072 size_t count, loff_t *ppos)
1073{
1074 struct wil6210_priv *wil = file->private_data;
1075 static const char run_command[] = "run";
1076 char buf[sizeof(run_command) + 1]; /* to detect "runx" */
1077 ssize_t rc;
1078
1079 if (wil->recovery_state != fw_recovery_pending) {
1080 wil_err(wil, "No recovery pending\n");
1081 return -EINVAL;
1082 }
1083
1084 if (*ppos != 0) {
1085 wil_err(wil, "Offset [%d]\n", (int)*ppos);
1086 return -EINVAL;
1087 }
1088
1089 if (count > sizeof(buf)) {
1090 wil_err(wil, "Input too long, len = %d\n", (int)count);
1091 return -EINVAL;
1092 }
1093
1094 rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count);
1095 if (rc < 0)
1096 return rc;
1097
1098 buf[rc] = '\0';
1099 if (0 == strcmp(buf, run_command))
1100 wil_set_recovery_state(wil, fw_recovery_running);
1101 else
1102 wil_err(wil, "Bad recovery command \"%s\"\n", buf);
1103
1104 return rc;
1105}
1106
1107static const struct file_operations fops_recovery = {
1108 .read = wil_read_file_recovery,
1109 .write = wil_write_file_recovery,
1110 .open = simple_open,
1111};
1112
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001113/*---------Station matrix------------*/
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001114static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
1115{
1116 int i;
1117 u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001118
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001119 seq_printf(s, "0x%03x [", r->head_seq_num);
1120 for (i = 0; i < r->buf_size; i++) {
1121 if (i == index)
1122 seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
1123 else
1124 seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
1125 }
Vladimir Kondratievd5b1c322014-06-16 19:37:07 +03001126 seq_printf(s, "] last drop 0x%03x\n", r->ssn_last_drop);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001127}
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001128
1129static int wil_sta_debugfs_show(struct seq_file *s, void *data)
1130{
1131 struct wil6210_priv *wil = s->private;
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001132 int i, tid;
Dedy Lanskyec81b5a2014-09-10 16:34:42 +03001133 unsigned long flags;
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001134
1135 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1136 struct wil_sta_info *p = &wil->sta[i];
1137 char *status = "unknown";
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001138
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001139 switch (p->status) {
1140 case wil_sta_unused:
1141 status = "unused ";
1142 break;
1143 case wil_sta_conn_pending:
1144 status = "pending ";
1145 break;
1146 case wil_sta_connected:
1147 status = "connected";
1148 break;
1149 }
Vladimir Kondratieve58c9f72014-03-17 15:34:06 +02001150 seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
1151 (p->data_port_open ? " data_port_open" : ""));
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001152
1153 if (p->status == wil_sta_connected) {
Dedy Lanskyec81b5a2014-09-10 16:34:42 +03001154 spin_lock_irqsave(&p->tid_rx_lock, flags);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001155 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1156 struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001157
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001158 if (r) {
1159 seq_printf(s, "[%2d] ", tid);
1160 wil_print_rxtid(s, r);
1161 }
1162 }
Dedy Lanskyec81b5a2014-09-10 16:34:42 +03001163 spin_unlock_irqrestore(&p->tid_rx_lock, flags);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001164 }
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001165 }
1166
1167 return 0;
1168}
1169
1170static int wil_sta_seq_open(struct inode *inode, struct file *file)
1171{
1172 return single_open(file, wil_sta_debugfs_show, inode->i_private);
1173}
1174
1175static const struct file_operations fops_sta = {
1176 .open = wil_sta_seq_open,
1177 .release = single_release,
1178 .read = seq_read,
1179 .llseek = seq_lseek,
1180};
1181
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001182/*----------------*/
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +03001183static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
1184 struct dentry *dbg)
1185{
1186 int i;
1187 char name[32];
1188
1189 for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
1190 struct debugfs_blob_wrapper *blob = &wil->blobs[i];
1191 const struct fw_map *map = &fw_mapping[i];
1192
1193 if (!map->name)
1194 continue;
1195
1196 blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
1197 blob->size = map->to - map->from;
1198 snprintf(name, sizeof(name), "blob_%s", map->name);
1199 wil_debugfs_create_ioblob(name, S_IRUGO, dbg, blob);
1200 }
1201}
1202
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001203/* misc files */
1204static const struct {
1205 const char *name;
1206 umode_t mode;
1207 const struct file_operations *fops;
1208} dbg_files[] = {
1209 {"mbox", S_IRUGO, &fops_mbox},
1210 {"vrings", S_IRUGO, &fops_vring},
1211 {"stations", S_IRUGO, &fops_sta},
1212 {"desc", S_IRUGO, &fops_txdesc},
1213 {"bf", S_IRUGO, &fops_bf},
1214 {"ssid", S_IRUGO | S_IWUSR, &fops_ssid},
1215 {"mem_val", S_IRUGO, &fops_memread},
1216 {"reset", S_IWUSR, &fops_reset},
1217 {"rxon", S_IWUSR, &fops_rxon},
1218 {"tx_mgmt", S_IWUSR, &fops_txmgmt},
1219 {"wmi_send", S_IWUSR, &fops_wmi},
1220 {"temp", S_IRUGO, &fops_temp},
1221 {"freq", S_IRUGO, &fops_freq},
1222 {"link", S_IRUGO, &fops_link},
1223 {"info", S_IRUGO, &fops_info},
Vladimir Kondratievc33407a2014-10-01 15:05:24 +03001224 {"recovery", S_IRUGO | S_IWUSR, &fops_recovery},
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001225};
1226
1227static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
1228 struct dentry *dbg)
1229{
1230 int i;
1231
1232 for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
1233 debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
1234 wil, dbg_files[i].fops);
1235}
1236
1237/* interrupt control blocks */
1238static const struct {
1239 const char *name;
1240 u32 icr_off;
1241} dbg_icr[] = {
1242 {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)},
1243 {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)},
1244 {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)},
1245 {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)},
1246};
1247
1248static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
1249 struct dentry *dbg)
1250{
1251 int i;
1252
1253 for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
1254 wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
1255 dbg_icr[i].icr_off);
1256}
1257
1258#define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
1259 offsetof(struct wil6210_priv, name), type}
1260
1261/* fields in struct wil6210_priv */
1262static const struct dbg_off dbg_wil_off[] = {
1263 WIL_FIELD(secure_pcp, S_IRUGO | S_IWUSR, doff_u32),
1264 WIL_FIELD(status, S_IRUGO | S_IWUSR, doff_ulong),
1265 WIL_FIELD(fw_version, S_IRUGO, doff_u32),
1266 WIL_FIELD(hw_version, S_IRUGO, doff_x32),
Vladimir Kondratievc33407a2014-10-01 15:05:24 +03001267 WIL_FIELD(recovery_count, S_IRUGO, doff_u32),
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001268 {},
1269};
1270
1271static const struct dbg_off dbg_wil_regs[] = {
1272 {"RGF_MAC_MTRL_COUNTER_0", S_IRUGO, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
1273 doff_io32},
1274 {"RGF_USER_USAGE_1", S_IRUGO, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
1275 {},
1276};
1277
1278/* static parameters */
1279static const struct dbg_off dbg_statics[] = {
1280 {"desc_index", S_IRUGO | S_IWUSR, (ulong)&dbg_txdesc_index, doff_u32},
1281 {"vring_index", S_IRUGO | S_IWUSR, (ulong)&dbg_vring_index, doff_u32},
1282 {"mem_addr", S_IRUGO | S_IWUSR, (ulong)&mem_addr, doff_u32},
1283 {},
1284};
1285
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001286int wil6210_debugfs_init(struct wil6210_priv *wil)
1287{
1288 struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
1289 wil_to_wiphy(wil)->debugfsdir);
1290
1291 if (IS_ERR_OR_NULL(dbg))
1292 return -ENODEV;
1293
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001294 wil6210_debugfs_init_files(wil, dbg);
1295 wil6210_debugfs_init_isr(wil, dbg);
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +03001296 wil6210_debugfs_init_blobs(wil, dbg);
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001297 wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
1298 wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
1299 dbg_wil_regs);
1300 wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
1301
1302 wil6210_debugfs_create_pseudo_ISR(wil, dbg);
1303
1304 wil6210_debugfs_create_ITR_CNT(wil, dbg);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001305
1306 return 0;
1307}
1308
1309void wil6210_debugfs_remove(struct wil6210_priv *wil)
1310{
1311 debugfs_remove_recursive(wil->debug);
1312 wil->debug = NULL;
1313}