wil6210: fix race condition between BACK event and Rx data
[deliverable/linux.git] / drivers / net / wireless / ath / wil6210 / debugfs.c
1 /*
2 * Copyright (c) 2012-2014 Qualcomm Atheros, Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #include <linux/module.h>
18 #include <linux/debugfs.h>
19 #include <linux/seq_file.h>
20 #include <linux/pci.h>
21 #include <linux/rtnetlink.h>
22 #include <linux/power_supply.h>
23
24 #include "wil6210.h"
25 #include "wmi.h"
26 #include "txrx.h"
27
28 /* Nasty hack. Better have per device instances */
29 static u32 mem_addr;
30 static u32 dbg_txdesc_index;
31 static u32 dbg_vring_index; /* 24+ for Rx, 0..23 for Tx */
32
33 enum 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" */
41 struct dbg_off {
42 const char *name;
43 umode_t mode;
44 ulong off;
45 enum dbg_off_type type;
46 };
47
48 static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil,
49 const char *name, struct vring *vring,
50 char _s, char _h)
51 {
52 void __iomem *x = wmi_addr(wil, vring->hwtail);
53
54 seq_printf(s, "VRING %s = {\n", name);
55 seq_printf(s, " pa = %pad\n", &vring->pa);
56 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
64 seq_puts(s, "???\n");
65
66 if (vring->va && (vring->size < 1025)) {
67 uint i;
68
69 for (i = 0; i < vring->size; i++) {
70 volatile struct vring_tx_desc *d = &vring->va[i].tx;
71
72 if ((i % 64) == 0 && (i != 0))
73 seq_puts(s, "\n");
74 seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
75 _s : (vring->ctx[i].skb ? _h : 'h'));
76 }
77 seq_puts(s, "\n");
78 }
79 seq_puts(s, "}\n");
80 }
81
82 static int wil_vring_debugfs_show(struct seq_file *s, void *data)
83 {
84 uint i;
85 struct wil6210_priv *wil = s->private;
86
87 wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_');
88
89 for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
90 struct vring *vring = &wil->vring_tx[i];
91 struct vring_tx_data *txdata = &wil->vring_tx_data[i];
92
93 if (vring->va) {
94 int cid = wil->vring2cid_tid[i][0];
95 int tid = wil->vring2cid_tid[i][1];
96 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;
101 char name[10];
102 /* performance monitoring */
103 cycles_t now = get_cycles();
104 cycles_t idle = txdata->idle * 100;
105 cycles_t total = now - txdata->begin;
106
107 do_div(idle, total);
108 txdata->begin = now;
109 txdata->idle = 0ULL;
110
111 snprintf(name, sizeof(name), "tx_%2d", i);
112
113 seq_printf(s, "\n%pM CID %d TID %d [%3d|%3d] idle %3d%%\n",
114 wil->sta[cid].addr, cid, tid, used, avail,
115 (int)idle);
116
117 wil_print_vring(s, wil, name, vring, '_', 'H');
118 }
119 }
120
121 return 0;
122 }
123
124 static 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
129 static 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
136 static 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)) {
168 seq_puts(s, " ??? pointers are garbage?\n");
169 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);
187
188 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;
193 char printbuf[16 * 3 + 2];
194 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);
205
206 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 {
215 seq_puts(s, "\n");
216 }
217 }
218 out:
219 seq_puts(s, "}\n");
220 }
221
222 static 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
234 static 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
239 static 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
246 static 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
254 static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
255 {
256 *val = ioread32((void __iomem *)data);
257
258 return 0;
259 }
260
261 DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
262 wil_debugfs_iomem_x32_set, "0x%08llx\n");
263
264 static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
265 umode_t mode,
266 struct dentry *parent,
267 void *value)
268 {
269 return debugfs_create_file(name, mode, parent, value,
270 &fops_iomem_x32);
271 }
272
273 static int wil_debugfs_ulong_set(void *data, u64 val)
274 {
275 *(ulong *)data = val;
276 return 0;
277 }
278
279 static int wil_debugfs_ulong_get(void *data, u64 *val)
280 {
281 *val = *(ulong *)data;
282 return 0;
283 }
284
285 DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
286 wil_debugfs_ulong_set, "%llu\n");
287
288 static 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
295 /**
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 */
304 static 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++) {
311 struct dentry *f = NULL;
312
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;
331 }
332 if (IS_ERR_OR_NULL(f))
333 wil_err(wil, "Create file \"%s\": err %ld\n",
334 tbl[i].name, PTR_ERR(f));
335 }
336 }
337
338 static const struct dbg_off isr_off[] = {
339 {"ICC", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICC), doff_io32},
340 {"ICR", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICR), doff_io32},
341 {"ICM", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICM), doff_io32},
342 {"ICS", S_IWUSR, offsetof(struct RGF_ICR, ICS), doff_io32},
343 {"IMV", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, IMV), doff_io32},
344 {"IMS", S_IWUSR, offsetof(struct RGF_ICR, IMS), doff_io32},
345 {"IMC", S_IWUSR, offsetof(struct RGF_ICR, IMC), doff_io32},
346 {},
347 };
348
349 static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
350 const char *name,
351 struct dentry *parent, u32 off)
352 {
353 struct dentry *d = debugfs_create_dir(name, parent);
354
355 if (IS_ERR_OR_NULL(d))
356 return -ENODEV;
357
358 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off,
359 isr_off);
360
361 return 0;
362 }
363
364 static const struct dbg_off pseudo_isr_off[] = {
365 {"CAUSE", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32},
366 {"MASK_SW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32},
367 {"MASK_FW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32},
368 {},
369 };
370
371 static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
372 struct dentry *parent)
373 {
374 struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
375
376 if (IS_ERR_OR_NULL(d))
377 return -ENODEV;
378
379 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
380 pseudo_isr_off);
381
382 return 0;
383 }
384
385 static const struct dbg_off itr_cnt_off[] = {
386 {"TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32},
387 {"DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32},
388 {"CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32},
389 {},
390 };
391
392 static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
393 struct dentry *parent)
394 {
395 struct dentry *d = debugfs_create_dir("ITR_CNT", parent);
396
397 if (IS_ERR_OR_NULL(d))
398 return -ENODEV;
399
400 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
401 itr_cnt_off);
402
403 return 0;
404 }
405
406 static int wil_memread_debugfs_show(struct seq_file *s, void *data)
407 {
408 struct wil6210_priv *wil = s->private;
409 void __iomem *a = wmi_buffer(wil, cpu_to_le32(mem_addr));
410
411 if (a)
412 seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, ioread32(a));
413 else
414 seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
415
416 return 0;
417 }
418
419 static int wil_memread_seq_open(struct inode *inode, struct file *file)
420 {
421 return single_open(file, wil_memread_debugfs_show, inode->i_private);
422 }
423
424 static const struct file_operations fops_memread = {
425 .open = wil_memread_seq_open,
426 .release = single_release,
427 .read = seq_read,
428 .llseek = seq_lseek,
429 };
430
431 static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
432 size_t count, loff_t *ppos)
433 {
434 enum { max_count = 4096 };
435 struct debugfs_blob_wrapper *blob = file->private_data;
436 loff_t pos = *ppos;
437 size_t available = blob->size;
438 void *buf;
439 size_t ret;
440
441 if (pos < 0)
442 return -EINVAL;
443
444 if (pos >= available || !count)
445 return 0;
446
447 if (count > available - pos)
448 count = available - pos;
449 if (count > max_count)
450 count = max_count;
451
452 buf = kmalloc(count, GFP_KERNEL);
453 if (!buf)
454 return -ENOMEM;
455
456 wil_memcpy_fromio_32(buf, (const volatile void __iomem *)blob->data +
457 pos, count);
458
459 ret = copy_to_user(user_buf, buf, count);
460 kfree(buf);
461 if (ret == count)
462 return -EFAULT;
463
464 count -= ret;
465 *ppos = pos + count;
466
467 return count;
468 }
469
470 static const struct file_operations fops_ioblob = {
471 .read = wil_read_file_ioblob,
472 .open = simple_open,
473 .llseek = default_llseek,
474 };
475
476 static
477 struct dentry *wil_debugfs_create_ioblob(const char *name,
478 umode_t mode,
479 struct dentry *parent,
480 struct debugfs_blob_wrapper *blob)
481 {
482 return debugfs_create_file(name, mode, parent, blob, &fops_ioblob);
483 }
484
485 /*---reset---*/
486 static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
487 size_t len, loff_t *ppos)
488 {
489 struct wil6210_priv *wil = file->private_data;
490 struct net_device *ndev = wil_to_ndev(wil);
491
492 /**
493 * BUG:
494 * this code does NOT sync device state with the rest of system
495 * use with care, debug only!!!
496 */
497 rtnl_lock();
498 dev_close(ndev);
499 ndev->flags &= ~IFF_UP;
500 rtnl_unlock();
501 wil_reset(wil);
502
503 return len;
504 }
505
506 static const struct file_operations fops_reset = {
507 .write = wil_write_file_reset,
508 .open = simple_open,
509 };
510
511 /*---write channel 1..4 to rxon for it, 0 to rxoff---*/
512 static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
513 size_t len, loff_t *ppos)
514 {
515 struct wil6210_priv *wil = file->private_data;
516 int rc;
517 long channel;
518 bool on;
519
520 char *kbuf = kmalloc(len + 1, GFP_KERNEL);
521
522 if (!kbuf)
523 return -ENOMEM;
524 if (copy_from_user(kbuf, buf, len)) {
525 kfree(kbuf);
526 return -EIO;
527 }
528
529 kbuf[len] = '\0';
530 rc = kstrtol(kbuf, 0, &channel);
531 kfree(kbuf);
532 if (rc)
533 return rc;
534
535 if ((channel < 0) || (channel > 4)) {
536 wil_err(wil, "Invalid channel %ld\n", channel);
537 return -EINVAL;
538 }
539 on = !!channel;
540
541 if (on) {
542 rc = wmi_set_channel(wil, (int)channel);
543 if (rc)
544 return rc;
545 }
546
547 rc = wmi_rxon(wil, on);
548 if (rc)
549 return rc;
550
551 return len;
552 }
553
554 static const struct file_operations fops_rxon = {
555 .write = wil_write_file_rxon,
556 .open = simple_open,
557 };
558
559 /*---tx_mgmt---*/
560 /* Write mgmt frame to this file to send it */
561 static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
562 size_t len, loff_t *ppos)
563 {
564 struct wil6210_priv *wil = file->private_data;
565 struct wiphy *wiphy = wil_to_wiphy(wil);
566 struct wireless_dev *wdev = wil_to_wdev(wil);
567 struct cfg80211_mgmt_tx_params params;
568 int rc;
569 void *frame = kmalloc(len, GFP_KERNEL);
570
571 if (!frame)
572 return -ENOMEM;
573
574 if (copy_from_user(frame, buf, len))
575 return -EIO;
576
577 params.buf = frame;
578 params.len = len;
579 params.chan = wdev->preset_chandef.chan;
580
581 rc = wil_cfg80211_mgmt_tx(wiphy, wdev, &params, NULL);
582
583 kfree(frame);
584 wil_info(wil, "%s() -> %d\n", __func__, rc);
585
586 return len;
587 }
588
589 static const struct file_operations fops_txmgmt = {
590 .write = wil_write_file_txmgmt,
591 .open = simple_open,
592 };
593
594 /* Write WMI command (w/o mbox header) to this file to send it
595 * WMI starts from wil6210_mbox_hdr_wmi header
596 */
597 static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
598 size_t len, loff_t *ppos)
599 {
600 struct wil6210_priv *wil = file->private_data;
601 struct wil6210_mbox_hdr_wmi *wmi;
602 void *cmd;
603 int cmdlen = len - sizeof(struct wil6210_mbox_hdr_wmi);
604 u16 cmdid;
605 int rc, rc1;
606
607 if (cmdlen <= 0)
608 return -EINVAL;
609
610 wmi = kmalloc(len, GFP_KERNEL);
611 if (!wmi)
612 return -ENOMEM;
613
614 rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
615 if (rc < 0)
616 return rc;
617
618 cmd = &wmi[1];
619 cmdid = le16_to_cpu(wmi->id);
620
621 rc1 = wmi_send(wil, cmdid, cmd, cmdlen);
622 kfree(wmi);
623
624 wil_info(wil, "%s(0x%04x[%d]) -> %d\n", __func__, cmdid, cmdlen, rc1);
625
626 return rc;
627 }
628
629 static const struct file_operations fops_wmi = {
630 .write = wil_write_file_wmi,
631 .open = simple_open,
632 };
633
634 static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
635 const char *prefix)
636 {
637 char printbuf[16 * 3 + 2];
638 int i = 0;
639
640 while (i < len) {
641 int l = min(len - i, 16);
642
643 hex_dump_to_buffer(p + i, l, 16, 1, printbuf,
644 sizeof(printbuf), false);
645 seq_printf(s, "%s%s\n", prefix, printbuf);
646 i += l;
647 }
648 }
649
650 static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
651 {
652 int i = 0;
653 int len = skb_headlen(skb);
654 void *p = skb->data;
655 int nr_frags = skb_shinfo(skb)->nr_frags;
656
657 seq_printf(s, " len = %d\n", len);
658 wil_seq_hexdump(s, p, len, " : ");
659
660 if (nr_frags) {
661 seq_printf(s, " nr_frags = %d\n", nr_frags);
662 for (i = 0; i < nr_frags; i++) {
663 const struct skb_frag_struct *frag =
664 &skb_shinfo(skb)->frags[i];
665
666 len = skb_frag_size(frag);
667 p = skb_frag_address_safe(frag);
668 seq_printf(s, " [%2d] : len = %d\n", i, len);
669 wil_seq_hexdump(s, p, len, " : ");
670 }
671 }
672 }
673
674 /*---------Tx/Rx descriptor------------*/
675 static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
676 {
677 struct wil6210_priv *wil = s->private;
678 struct vring *vring;
679 bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS);
680
681 vring = tx ? &wil->vring_tx[dbg_vring_index] : &wil->vring_rx;
682
683 if (!vring->va) {
684 if (tx)
685 seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index);
686 else
687 seq_puts(s, "No Rx VRING\n");
688 return 0;
689 }
690
691 if (dbg_txdesc_index < vring->size) {
692 /* use struct vring_tx_desc for Rx as well,
693 * only field used, .dma.length, is the same
694 */
695 volatile struct vring_tx_desc *d =
696 &vring->va[dbg_txdesc_index].tx;
697 volatile u32 *u = (volatile u32 *)d;
698 struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb;
699
700 if (tx)
701 seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index,
702 dbg_txdesc_index);
703 else
704 seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
705 seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
706 u[0], u[1], u[2], u[3]);
707 seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
708 u[4], u[5], u[6], u[7]);
709 seq_printf(s, " SKB = 0x%p\n", skb);
710
711 if (skb) {
712 skb_get(skb);
713 wil_seq_print_skb(s, skb);
714 kfree_skb(skb);
715 }
716 seq_puts(s, "}\n");
717 } else {
718 if (tx)
719 seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
720 dbg_vring_index, dbg_txdesc_index,
721 vring->size);
722 else
723 seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
724 dbg_txdesc_index, vring->size);
725 }
726
727 return 0;
728 }
729
730 static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
731 {
732 return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
733 }
734
735 static const struct file_operations fops_txdesc = {
736 .open = wil_txdesc_seq_open,
737 .release = single_release,
738 .read = seq_read,
739 .llseek = seq_lseek,
740 };
741
742 /*---------beamforming------------*/
743 static char *wil_bfstatus_str(u32 status)
744 {
745 switch (status) {
746 case 0:
747 return "Failed";
748 case 1:
749 return "OK";
750 case 2:
751 return "Retrying";
752 default:
753 return "??";
754 }
755 }
756
757 static bool is_all_zeros(void * const x_, size_t sz)
758 {
759 /* if reply is all-0, ignore this CID */
760 u32 *x = x_;
761 int n;
762
763 for (n = 0; n < sz / sizeof(*x); n++)
764 if (x[n])
765 return false;
766
767 return true;
768 }
769
770 static int wil_bf_debugfs_show(struct seq_file *s, void *data)
771 {
772 int rc;
773 int i;
774 struct wil6210_priv *wil = s->private;
775 struct wmi_notify_req_cmd cmd = {
776 .interval_usec = 0,
777 };
778 struct {
779 struct wil6210_mbox_hdr_wmi wmi;
780 struct wmi_notify_req_done_event evt;
781 } __packed reply;
782
783 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
784 u32 status;
785
786 cmd.cid = i;
787 rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd),
788 WMI_NOTIFY_REQ_DONE_EVENTID, &reply,
789 sizeof(reply), 20);
790 /* if reply is all-0, ignore this CID */
791 if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt)))
792 continue;
793
794 status = le32_to_cpu(reply.evt.status);
795 seq_printf(s, "CID %d {\n"
796 " TSF = 0x%016llx\n"
797 " TxMCS = %2d TxTpt = %4d\n"
798 " SQI = %4d\n"
799 " Status = 0x%08x %s\n"
800 " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
801 " Goodput(rx:tx) %4d:%4d\n"
802 "}\n",
803 i,
804 le64_to_cpu(reply.evt.tsf),
805 le16_to_cpu(reply.evt.bf_mcs),
806 le32_to_cpu(reply.evt.tx_tpt),
807 reply.evt.sqi,
808 status, wil_bfstatus_str(status),
809 le16_to_cpu(reply.evt.my_rx_sector),
810 le16_to_cpu(reply.evt.my_tx_sector),
811 le16_to_cpu(reply.evt.other_rx_sector),
812 le16_to_cpu(reply.evt.other_tx_sector),
813 le32_to_cpu(reply.evt.rx_goodput),
814 le32_to_cpu(reply.evt.tx_goodput));
815 }
816 return 0;
817 }
818
819 static int wil_bf_seq_open(struct inode *inode, struct file *file)
820 {
821 return single_open(file, wil_bf_debugfs_show, inode->i_private);
822 }
823
824 static const struct file_operations fops_bf = {
825 .open = wil_bf_seq_open,
826 .release = single_release,
827 .read = seq_read,
828 .llseek = seq_lseek,
829 };
830
831 /*---------SSID------------*/
832 static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf,
833 size_t count, loff_t *ppos)
834 {
835 struct wil6210_priv *wil = file->private_data;
836 struct wireless_dev *wdev = wil_to_wdev(wil);
837
838 return simple_read_from_buffer(user_buf, count, ppos,
839 wdev->ssid, wdev->ssid_len);
840 }
841
842 static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf,
843 size_t count, loff_t *ppos)
844 {
845 struct wil6210_priv *wil = file->private_data;
846 struct wireless_dev *wdev = wil_to_wdev(wil);
847 struct net_device *ndev = wil_to_ndev(wil);
848
849 if (*ppos != 0) {
850 wil_err(wil, "Unable to set SSID substring from [%d]\n",
851 (int)*ppos);
852 return -EINVAL;
853 }
854
855 if (count > sizeof(wdev->ssid)) {
856 wil_err(wil, "SSID too long, len = %d\n", (int)count);
857 return -EINVAL;
858 }
859 if (netif_running(ndev)) {
860 wil_err(wil, "Unable to change SSID on running interface\n");
861 return -EINVAL;
862 }
863
864 wdev->ssid_len = count;
865 return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos,
866 buf, count);
867 }
868
869 static const struct file_operations fops_ssid = {
870 .read = wil_read_file_ssid,
871 .write = wil_write_file_ssid,
872 .open = simple_open,
873 };
874
875 /*---------temp------------*/
876 static void print_temp(struct seq_file *s, const char *prefix, u32 t)
877 {
878 switch (t) {
879 case 0:
880 case ~(u32)0:
881 seq_printf(s, "%s N/A\n", prefix);
882 break;
883 default:
884 seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
885 break;
886 }
887 }
888
889 static int wil_temp_debugfs_show(struct seq_file *s, void *data)
890 {
891 struct wil6210_priv *wil = s->private;
892 u32 t_m, t_r;
893 int rc = wmi_get_temperature(wil, &t_m, &t_r);
894
895 if (rc) {
896 seq_puts(s, "Failed\n");
897 return 0;
898 }
899
900 print_temp(s, "T_mac =", t_m);
901 print_temp(s, "T_radio =", t_r);
902
903 return 0;
904 }
905
906 static int wil_temp_seq_open(struct inode *inode, struct file *file)
907 {
908 return single_open(file, wil_temp_debugfs_show, inode->i_private);
909 }
910
911 static const struct file_operations fops_temp = {
912 .open = wil_temp_seq_open,
913 .release = single_release,
914 .read = seq_read,
915 .llseek = seq_lseek,
916 };
917
918 /*---------freq------------*/
919 static int wil_freq_debugfs_show(struct seq_file *s, void *data)
920 {
921 struct wil6210_priv *wil = s->private;
922 struct wireless_dev *wdev = wil_to_wdev(wil);
923 u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
924
925 seq_printf(s, "Freq = %d\n", freq);
926
927 return 0;
928 }
929
930 static int wil_freq_seq_open(struct inode *inode, struct file *file)
931 {
932 return single_open(file, wil_freq_debugfs_show, inode->i_private);
933 }
934
935 static const struct file_operations fops_freq = {
936 .open = wil_freq_seq_open,
937 .release = single_release,
938 .read = seq_read,
939 .llseek = seq_lseek,
940 };
941
942 /*---------link------------*/
943 static int wil_link_debugfs_show(struct seq_file *s, void *data)
944 {
945 struct wil6210_priv *wil = s->private;
946 struct station_info sinfo;
947 int i, rc;
948
949 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
950 struct wil_sta_info *p = &wil->sta[i];
951 char *status = "unknown";
952
953 switch (p->status) {
954 case wil_sta_unused:
955 status = "unused ";
956 break;
957 case wil_sta_conn_pending:
958 status = "pending ";
959 break;
960 case wil_sta_connected:
961 status = "connected";
962 break;
963 }
964 seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
965 (p->data_port_open ? " data_port_open" : ""));
966
967 if (p->status == wil_sta_connected) {
968 rc = wil_cid_fill_sinfo(wil, i, &sinfo);
969 if (rc)
970 return rc;
971
972 seq_printf(s, " Tx_mcs = %d\n", sinfo.txrate.mcs);
973 seq_printf(s, " Rx_mcs = %d\n", sinfo.rxrate.mcs);
974 seq_printf(s, " SQ = %d\n", sinfo.signal);
975 }
976 }
977
978 return 0;
979 }
980
981 static int wil_link_seq_open(struct inode *inode, struct file *file)
982 {
983 return single_open(file, wil_link_debugfs_show, inode->i_private);
984 }
985
986 static const struct file_operations fops_link = {
987 .open = wil_link_seq_open,
988 .release = single_release,
989 .read = seq_read,
990 .llseek = seq_lseek,
991 };
992
993 /*---------info------------*/
994 static int wil_info_debugfs_show(struct seq_file *s, void *data)
995 {
996 struct wil6210_priv *wil = s->private;
997 struct net_device *ndev = wil_to_ndev(wil);
998 int is_ac = power_supply_is_system_supplied();
999 int rx = atomic_xchg(&wil->isr_count_rx, 0);
1000 int tx = atomic_xchg(&wil->isr_count_tx, 0);
1001 static ulong rxf_old, txf_old;
1002 ulong rxf = ndev->stats.rx_packets;
1003 ulong txf = ndev->stats.tx_packets;
1004 unsigned int i;
1005
1006 /* >0 : AC; 0 : battery; <0 : error */
1007 seq_printf(s, "AC powered : %d\n", is_ac);
1008 seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
1009 seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
1010 rxf_old = rxf;
1011 txf_old = txf;
1012
1013 #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
1014 " " __stringify(x) : ""
1015
1016 for (i = 0; i < ndev->num_tx_queues; i++) {
1017 struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
1018 unsigned long state = txq->state;
1019
1020 seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
1021 CHECK_QSTATE(DRV_XOFF),
1022 CHECK_QSTATE(STACK_XOFF),
1023 CHECK_QSTATE(FROZEN)
1024 );
1025 }
1026 #undef CHECK_QSTATE
1027 return 0;
1028 }
1029
1030 static int wil_info_seq_open(struct inode *inode, struct file *file)
1031 {
1032 return single_open(file, wil_info_debugfs_show, inode->i_private);
1033 }
1034
1035 static const struct file_operations fops_info = {
1036 .open = wil_info_seq_open,
1037 .release = single_release,
1038 .read = seq_read,
1039 .llseek = seq_lseek,
1040 };
1041
1042 /*---------Station matrix------------*/
1043 static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
1044 {
1045 int i;
1046 u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
1047
1048 seq_printf(s, "0x%03x [", r->head_seq_num);
1049 for (i = 0; i < r->buf_size; i++) {
1050 if (i == index)
1051 seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
1052 else
1053 seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
1054 }
1055 seq_printf(s, "] last drop 0x%03x\n", r->ssn_last_drop);
1056 }
1057
1058 static int wil_sta_debugfs_show(struct seq_file *s, void *data)
1059 {
1060 struct wil6210_priv *wil = s->private;
1061 int i, tid;
1062 unsigned long flags;
1063
1064 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1065 struct wil_sta_info *p = &wil->sta[i];
1066 char *status = "unknown";
1067
1068 switch (p->status) {
1069 case wil_sta_unused:
1070 status = "unused ";
1071 break;
1072 case wil_sta_conn_pending:
1073 status = "pending ";
1074 break;
1075 case wil_sta_connected:
1076 status = "connected";
1077 break;
1078 }
1079 seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
1080 (p->data_port_open ? " data_port_open" : ""));
1081
1082 if (p->status == wil_sta_connected) {
1083 spin_lock_irqsave(&p->tid_rx_lock, flags);
1084 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1085 struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
1086
1087 if (r) {
1088 seq_printf(s, "[%2d] ", tid);
1089 wil_print_rxtid(s, r);
1090 }
1091 }
1092 spin_unlock_irqrestore(&p->tid_rx_lock, flags);
1093 }
1094 }
1095
1096 return 0;
1097 }
1098
1099 static int wil_sta_seq_open(struct inode *inode, struct file *file)
1100 {
1101 return single_open(file, wil_sta_debugfs_show, inode->i_private);
1102 }
1103
1104 static const struct file_operations fops_sta = {
1105 .open = wil_sta_seq_open,
1106 .release = single_release,
1107 .read = seq_read,
1108 .llseek = seq_lseek,
1109 };
1110
1111 /*----------------*/
1112 static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
1113 struct dentry *dbg)
1114 {
1115 int i;
1116 char name[32];
1117
1118 for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
1119 struct debugfs_blob_wrapper *blob = &wil->blobs[i];
1120 const struct fw_map *map = &fw_mapping[i];
1121
1122 if (!map->name)
1123 continue;
1124
1125 blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
1126 blob->size = map->to - map->from;
1127 snprintf(name, sizeof(name), "blob_%s", map->name);
1128 wil_debugfs_create_ioblob(name, S_IRUGO, dbg, blob);
1129 }
1130 }
1131
1132 /* misc files */
1133 static const struct {
1134 const char *name;
1135 umode_t mode;
1136 const struct file_operations *fops;
1137 } dbg_files[] = {
1138 {"mbox", S_IRUGO, &fops_mbox},
1139 {"vrings", S_IRUGO, &fops_vring},
1140 {"stations", S_IRUGO, &fops_sta},
1141 {"desc", S_IRUGO, &fops_txdesc},
1142 {"bf", S_IRUGO, &fops_bf},
1143 {"ssid", S_IRUGO | S_IWUSR, &fops_ssid},
1144 {"mem_val", S_IRUGO, &fops_memread},
1145 {"reset", S_IWUSR, &fops_reset},
1146 {"rxon", S_IWUSR, &fops_rxon},
1147 {"tx_mgmt", S_IWUSR, &fops_txmgmt},
1148 {"wmi_send", S_IWUSR, &fops_wmi},
1149 {"temp", S_IRUGO, &fops_temp},
1150 {"freq", S_IRUGO, &fops_freq},
1151 {"link", S_IRUGO, &fops_link},
1152 {"info", S_IRUGO, &fops_info},
1153 };
1154
1155 static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
1156 struct dentry *dbg)
1157 {
1158 int i;
1159
1160 for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
1161 debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
1162 wil, dbg_files[i].fops);
1163 }
1164
1165 /* interrupt control blocks */
1166 static const struct {
1167 const char *name;
1168 u32 icr_off;
1169 } dbg_icr[] = {
1170 {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)},
1171 {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)},
1172 {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)},
1173 {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)},
1174 };
1175
1176 static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
1177 struct dentry *dbg)
1178 {
1179 int i;
1180
1181 for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
1182 wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
1183 dbg_icr[i].icr_off);
1184 }
1185
1186 #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
1187 offsetof(struct wil6210_priv, name), type}
1188
1189 /* fields in struct wil6210_priv */
1190 static const struct dbg_off dbg_wil_off[] = {
1191 WIL_FIELD(secure_pcp, S_IRUGO | S_IWUSR, doff_u32),
1192 WIL_FIELD(status, S_IRUGO | S_IWUSR, doff_ulong),
1193 WIL_FIELD(fw_version, S_IRUGO, doff_u32),
1194 WIL_FIELD(hw_version, S_IRUGO, doff_x32),
1195 {},
1196 };
1197
1198 static const struct dbg_off dbg_wil_regs[] = {
1199 {"RGF_MAC_MTRL_COUNTER_0", S_IRUGO, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
1200 doff_io32},
1201 {"RGF_USER_USAGE_1", S_IRUGO, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
1202 {},
1203 };
1204
1205 /* static parameters */
1206 static const struct dbg_off dbg_statics[] = {
1207 {"desc_index", S_IRUGO | S_IWUSR, (ulong)&dbg_txdesc_index, doff_u32},
1208 {"vring_index", S_IRUGO | S_IWUSR, (ulong)&dbg_vring_index, doff_u32},
1209 {"mem_addr", S_IRUGO | S_IWUSR, (ulong)&mem_addr, doff_u32},
1210 {},
1211 };
1212
1213 int wil6210_debugfs_init(struct wil6210_priv *wil)
1214 {
1215 struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
1216 wil_to_wiphy(wil)->debugfsdir);
1217
1218 if (IS_ERR_OR_NULL(dbg))
1219 return -ENODEV;
1220
1221 wil6210_debugfs_init_files(wil, dbg);
1222 wil6210_debugfs_init_isr(wil, dbg);
1223 wil6210_debugfs_init_blobs(wil, dbg);
1224 wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
1225 wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
1226 dbg_wil_regs);
1227 wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
1228
1229 wil6210_debugfs_create_pseudo_ISR(wil, dbg);
1230
1231 wil6210_debugfs_create_ITR_CNT(wil, dbg);
1232
1233 return 0;
1234 }
1235
1236 void wil6210_debugfs_remove(struct wil6210_priv *wil)
1237 {
1238 debugfs_remove_recursive(wil->debug);
1239 wil->debug = NULL;
1240 }
This page took 0.055484 seconds and 6 git commands to generate.