Merge tag 'for-v3.17' of git://git.infradead.org/battery-2.6
[deliverable/linux.git] / drivers / net / wireless / ath / wil6210 / debugfs.c
1 /*
2 * Copyright (c) 2012 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 "txrx.h"
26
27 /* Nasty hack. Better have per device instances */
28 static u32 mem_addr;
29 static u32 dbg_txdesc_index;
30 static u32 dbg_vring_index; /* 24+ for Rx, 0..23 for Tx */
31
32 static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil,
33 const char *name, struct vring *vring,
34 char _s, char _h)
35 {
36 void __iomem *x = wmi_addr(wil, vring->hwtail);
37
38 seq_printf(s, "VRING %s = {\n", name);
39 seq_printf(s, " pa = %pad\n", &vring->pa);
40 seq_printf(s, " va = 0x%p\n", vring->va);
41 seq_printf(s, " size = %d\n", vring->size);
42 seq_printf(s, " swtail = %d\n", vring->swtail);
43 seq_printf(s, " swhead = %d\n", vring->swhead);
44 seq_printf(s, " hwtail = [0x%08x] -> ", vring->hwtail);
45 if (x)
46 seq_printf(s, "0x%08x\n", ioread32(x));
47 else
48 seq_printf(s, "???\n");
49
50 if (vring->va && (vring->size < 1025)) {
51 uint i;
52 for (i = 0; i < vring->size; i++) {
53 volatile struct vring_tx_desc *d = &vring->va[i].tx;
54 if ((i % 64) == 0 && (i != 0))
55 seq_printf(s, "\n");
56 seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
57 _s : (vring->ctx[i].skb ? _h : 'h'));
58 }
59 seq_printf(s, "\n");
60 }
61 seq_printf(s, "}\n");
62 }
63
64 static int wil_vring_debugfs_show(struct seq_file *s, void *data)
65 {
66 uint i;
67 struct wil6210_priv *wil = s->private;
68
69 wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_');
70
71 for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
72 struct vring *vring = &(wil->vring_tx[i]);
73 struct vring_tx_data *txdata = &wil->vring_tx_data[i];
74
75 if (vring->va) {
76 int cid = wil->vring2cid_tid[i][0];
77 int tid = wil->vring2cid_tid[i][1];
78 u32 swhead = vring->swhead;
79 u32 swtail = vring->swtail;
80 int used = (vring->size + swhead - swtail)
81 % vring->size;
82 int avail = vring->size - used - 1;
83 char name[10];
84 /* performance monitoring */
85 cycles_t now = get_cycles();
86 cycles_t idle = txdata->idle * 100;
87 cycles_t total = now - txdata->begin;
88
89 do_div(idle, total);
90 txdata->begin = now;
91 txdata->idle = 0ULL;
92
93 snprintf(name, sizeof(name), "tx_%2d", i);
94
95 seq_printf(s, "\n%pM CID %d TID %d [%3d|%3d] idle %3d%%\n",
96 wil->sta[cid].addr, cid, tid, used, avail,
97 (int)idle);
98
99 wil_print_vring(s, wil, name, vring, '_', 'H');
100 }
101 }
102
103 return 0;
104 }
105
106 static int wil_vring_seq_open(struct inode *inode, struct file *file)
107 {
108 return single_open(file, wil_vring_debugfs_show, inode->i_private);
109 }
110
111 static const struct file_operations fops_vring = {
112 .open = wil_vring_seq_open,
113 .release = single_release,
114 .read = seq_read,
115 .llseek = seq_lseek,
116 };
117
118 static void wil_print_ring(struct seq_file *s, const char *prefix,
119 void __iomem *off)
120 {
121 struct wil6210_priv *wil = s->private;
122 struct wil6210_mbox_ring r;
123 int rsize;
124 uint i;
125
126 wil_memcpy_fromio_32(&r, off, sizeof(r));
127 wil_mbox_ring_le2cpus(&r);
128 /*
129 * we just read memory block from NIC. This memory may be
130 * garbage. Check validity before using it.
131 */
132 rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
133
134 seq_printf(s, "ring %s = {\n", prefix);
135 seq_printf(s, " base = 0x%08x\n", r.base);
136 seq_printf(s, " size = 0x%04x bytes -> %d entries\n", r.size, rsize);
137 seq_printf(s, " tail = 0x%08x\n", r.tail);
138 seq_printf(s, " head = 0x%08x\n", r.head);
139 seq_printf(s, " entry size = %d\n", r.entry_size);
140
141 if (r.size % sizeof(struct wil6210_mbox_ring_desc)) {
142 seq_printf(s, " ??? size is not multiple of %zd, garbage?\n",
143 sizeof(struct wil6210_mbox_ring_desc));
144 goto out;
145 }
146
147 if (!wmi_addr(wil, r.base) ||
148 !wmi_addr(wil, r.tail) ||
149 !wmi_addr(wil, r.head)) {
150 seq_printf(s, " ??? pointers are garbage?\n");
151 goto out;
152 }
153
154 for (i = 0; i < rsize; i++) {
155 struct wil6210_mbox_ring_desc d;
156 struct wil6210_mbox_hdr hdr;
157 size_t delta = i * sizeof(d);
158 void __iomem *x = wil->csr + HOSTADDR(r.base) + delta;
159
160 wil_memcpy_fromio_32(&d, x, sizeof(d));
161
162 seq_printf(s, " [%2x] %s %s%s 0x%08x", i,
163 d.sync ? "F" : "E",
164 (r.tail - r.base == delta) ? "t" : " ",
165 (r.head - r.base == delta) ? "h" : " ",
166 le32_to_cpu(d.addr));
167 if (0 == wmi_read_hdr(wil, d.addr, &hdr)) {
168 u16 len = le16_to_cpu(hdr.len);
169 seq_printf(s, " -> %04x %04x %04x %02x\n",
170 le16_to_cpu(hdr.seq), len,
171 le16_to_cpu(hdr.type), hdr.flags);
172 if (len <= MAX_MBOXITEM_SIZE) {
173 int n = 0;
174 char printbuf[16 * 3 + 2];
175 unsigned char databuf[MAX_MBOXITEM_SIZE];
176 void __iomem *src = wmi_buffer(wil, d.addr) +
177 sizeof(struct wil6210_mbox_hdr);
178 /*
179 * No need to check @src for validity -
180 * we already validated @d.addr while
181 * reading header
182 */
183 wil_memcpy_fromio_32(databuf, src, len);
184 while (n < len) {
185 int l = min(len - n, 16);
186 hex_dump_to_buffer(databuf + n, l,
187 16, 1, printbuf,
188 sizeof(printbuf),
189 false);
190 seq_printf(s, " : %s\n", printbuf);
191 n += l;
192 }
193 }
194 } else {
195 seq_printf(s, "\n");
196 }
197 }
198 out:
199 seq_printf(s, "}\n");
200 }
201
202 static int wil_mbox_debugfs_show(struct seq_file *s, void *data)
203 {
204 struct wil6210_priv *wil = s->private;
205
206 wil_print_ring(s, "tx", wil->csr + HOST_MBOX +
207 offsetof(struct wil6210_mbox_ctl, tx));
208 wil_print_ring(s, "rx", wil->csr + HOST_MBOX +
209 offsetof(struct wil6210_mbox_ctl, rx));
210
211 return 0;
212 }
213
214 static int wil_mbox_seq_open(struct inode *inode, struct file *file)
215 {
216 return single_open(file, wil_mbox_debugfs_show, inode->i_private);
217 }
218
219 static const struct file_operations fops_mbox = {
220 .open = wil_mbox_seq_open,
221 .release = single_release,
222 .read = seq_read,
223 .llseek = seq_lseek,
224 };
225
226 static int wil_debugfs_iomem_x32_set(void *data, u64 val)
227 {
228 iowrite32(val, (void __iomem *)data);
229 wmb(); /* make sure write propagated to HW */
230
231 return 0;
232 }
233
234 static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
235 {
236 *val = ioread32((void __iomem *)data);
237
238 return 0;
239 }
240
241 DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
242 wil_debugfs_iomem_x32_set, "0x%08llx\n");
243
244 static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
245 umode_t mode,
246 struct dentry *parent,
247 void __iomem *value)
248 {
249 return debugfs_create_file(name, mode, parent, (void * __force)value,
250 &fops_iomem_x32);
251 }
252
253 static int wil_debugfs_ulong_set(void *data, u64 val)
254 {
255 *(ulong *)data = val;
256 return 0;
257 }
258 static int wil_debugfs_ulong_get(void *data, u64 *val)
259 {
260 *val = *(ulong *)data;
261 return 0;
262 }
263 DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
264 wil_debugfs_ulong_set, "%llu\n");
265
266 static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode,
267 struct dentry *parent,
268 ulong *value)
269 {
270 return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong);
271 }
272
273 static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
274 const char *name,
275 struct dentry *parent, u32 off)
276 {
277 struct dentry *d = debugfs_create_dir(name, parent);
278
279 if (IS_ERR_OR_NULL(d))
280 return -ENODEV;
281
282 wil_debugfs_create_iomem_x32("ICC", S_IRUGO | S_IWUSR, d,
283 wil->csr + off);
284 wil_debugfs_create_iomem_x32("ICR", S_IRUGO | S_IWUSR, d,
285 wil->csr + off + 4);
286 wil_debugfs_create_iomem_x32("ICM", S_IRUGO | S_IWUSR, d,
287 wil->csr + off + 8);
288 wil_debugfs_create_iomem_x32("ICS", S_IWUSR, d,
289 wil->csr + off + 12);
290 wil_debugfs_create_iomem_x32("IMV", S_IRUGO | S_IWUSR, d,
291 wil->csr + off + 16);
292 wil_debugfs_create_iomem_x32("IMS", S_IWUSR, d,
293 wil->csr + off + 20);
294 wil_debugfs_create_iomem_x32("IMC", S_IWUSR, d,
295 wil->csr + off + 24);
296
297 return 0;
298 }
299
300 static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
301 struct dentry *parent)
302 {
303 struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
304
305 if (IS_ERR_OR_NULL(d))
306 return -ENODEV;
307
308 wil_debugfs_create_iomem_x32("CAUSE", S_IRUGO, d, wil->csr +
309 HOSTADDR(RGF_DMA_PSEUDO_CAUSE));
310 wil_debugfs_create_iomem_x32("MASK_SW", S_IRUGO, d, wil->csr +
311 HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW));
312 wil_debugfs_create_iomem_x32("MASK_FW", S_IRUGO, d, wil->csr +
313 HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW));
314
315 return 0;
316 }
317
318 static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
319 struct dentry *parent)
320 {
321 struct dentry *d = debugfs_create_dir("ITR_CNT", parent);
322
323 if (IS_ERR_OR_NULL(d))
324 return -ENODEV;
325
326 wil_debugfs_create_iomem_x32("TRSH", S_IRUGO | S_IWUSR, d, wil->csr +
327 HOSTADDR(RGF_DMA_ITR_CNT_TRSH));
328 wil_debugfs_create_iomem_x32("DATA", S_IRUGO | S_IWUSR, d, wil->csr +
329 HOSTADDR(RGF_DMA_ITR_CNT_DATA));
330 wil_debugfs_create_iomem_x32("CTL", S_IRUGO | S_IWUSR, d, wil->csr +
331 HOSTADDR(RGF_DMA_ITR_CNT_CRL));
332
333 return 0;
334 }
335
336 static int wil_memread_debugfs_show(struct seq_file *s, void *data)
337 {
338 struct wil6210_priv *wil = s->private;
339 void __iomem *a = wmi_buffer(wil, cpu_to_le32(mem_addr));
340
341 if (a)
342 seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, ioread32(a));
343 else
344 seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
345
346 return 0;
347 }
348
349 static int wil_memread_seq_open(struct inode *inode, struct file *file)
350 {
351 return single_open(file, wil_memread_debugfs_show, inode->i_private);
352 }
353
354 static const struct file_operations fops_memread = {
355 .open = wil_memread_seq_open,
356 .release = single_release,
357 .read = seq_read,
358 .llseek = seq_lseek,
359 };
360
361 static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
362 size_t count, loff_t *ppos)
363 {
364 enum { max_count = 4096 };
365 struct debugfs_blob_wrapper *blob = file->private_data;
366 loff_t pos = *ppos;
367 size_t available = blob->size;
368 void *buf;
369 size_t ret;
370
371 if (pos < 0)
372 return -EINVAL;
373
374 if (pos >= available || !count)
375 return 0;
376
377 if (count > available - pos)
378 count = available - pos;
379 if (count > max_count)
380 count = max_count;
381
382 buf = kmalloc(count, GFP_KERNEL);
383 if (!buf)
384 return -ENOMEM;
385
386 wil_memcpy_fromio_32(buf, (const volatile void __iomem *)blob->data +
387 pos, count);
388
389 ret = copy_to_user(user_buf, buf, count);
390 kfree(buf);
391 if (ret == count)
392 return -EFAULT;
393
394 count -= ret;
395 *ppos = pos + count;
396
397 return count;
398 }
399
400 static const struct file_operations fops_ioblob = {
401 .read = wil_read_file_ioblob,
402 .open = simple_open,
403 .llseek = default_llseek,
404 };
405
406 static
407 struct dentry *wil_debugfs_create_ioblob(const char *name,
408 umode_t mode,
409 struct dentry *parent,
410 struct debugfs_blob_wrapper *blob)
411 {
412 return debugfs_create_file(name, mode, parent, blob, &fops_ioblob);
413 }
414 /*---reset---*/
415 static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
416 size_t len, loff_t *ppos)
417 {
418 struct wil6210_priv *wil = file->private_data;
419 struct net_device *ndev = wil_to_ndev(wil);
420
421 /**
422 * BUG:
423 * this code does NOT sync device state with the rest of system
424 * use with care, debug only!!!
425 */
426 rtnl_lock();
427 dev_close(ndev);
428 ndev->flags &= ~IFF_UP;
429 rtnl_unlock();
430 wil_reset(wil);
431
432 return len;
433 }
434
435 static const struct file_operations fops_reset = {
436 .write = wil_write_file_reset,
437 .open = simple_open,
438 };
439 /*---write channel 1..4 to rxon for it, 0 to rxoff---*/
440 static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
441 size_t len, loff_t *ppos)
442 {
443 struct wil6210_priv *wil = file->private_data;
444 int rc;
445 long channel;
446 bool on;
447
448 char *kbuf = kmalloc(len + 1, GFP_KERNEL);
449 if (!kbuf)
450 return -ENOMEM;
451 if (copy_from_user(kbuf, buf, len)) {
452 kfree(kbuf);
453 return -EIO;
454 }
455
456 kbuf[len] = '\0';
457 rc = kstrtol(kbuf, 0, &channel);
458 kfree(kbuf);
459 if (rc)
460 return rc;
461
462 if ((channel < 0) || (channel > 4)) {
463 wil_err(wil, "Invalid channel %ld\n", channel);
464 return -EINVAL;
465 }
466 on = !!channel;
467
468 if (on) {
469 rc = wmi_set_channel(wil, (int)channel);
470 if (rc)
471 return rc;
472 }
473
474 rc = wmi_rxon(wil, on);
475 if (rc)
476 return rc;
477
478 return len;
479 }
480
481 static const struct file_operations fops_rxon = {
482 .write = wil_write_file_rxon,
483 .open = simple_open,
484 };
485 /*---tx_mgmt---*/
486 /* Write mgmt frame to this file to send it */
487 static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
488 size_t len, loff_t *ppos)
489 {
490 struct wil6210_priv *wil = file->private_data;
491 struct wiphy *wiphy = wil_to_wiphy(wil);
492 struct wireless_dev *wdev = wil_to_wdev(wil);
493 struct cfg80211_mgmt_tx_params params;
494 int rc;
495
496 void *frame = kmalloc(len, GFP_KERNEL);
497 if (!frame)
498 return -ENOMEM;
499
500 if (copy_from_user(frame, buf, len))
501 return -EIO;
502
503 params.buf = frame;
504 params.len = len;
505 params.chan = wdev->preset_chandef.chan;
506
507 rc = wil_cfg80211_mgmt_tx(wiphy, wdev, &params, NULL);
508
509 kfree(frame);
510 wil_info(wil, "%s() -> %d\n", __func__, rc);
511
512 return len;
513 }
514
515 static const struct file_operations fops_txmgmt = {
516 .write = wil_write_file_txmgmt,
517 .open = simple_open,
518 };
519
520 /* Write WMI command (w/o mbox header) to this file to send it
521 * WMI starts from wil6210_mbox_hdr_wmi header
522 */
523 static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
524 size_t len, loff_t *ppos)
525 {
526 struct wil6210_priv *wil = file->private_data;
527 struct wil6210_mbox_hdr_wmi *wmi;
528 void *cmd;
529 int cmdlen = len - sizeof(struct wil6210_mbox_hdr_wmi);
530 u16 cmdid;
531 int rc, rc1;
532
533 if (cmdlen <= 0)
534 return -EINVAL;
535
536 wmi = kmalloc(len, GFP_KERNEL);
537 if (!wmi)
538 return -ENOMEM;
539
540 rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
541 if (rc < 0)
542 return rc;
543
544 cmd = &wmi[1];
545 cmdid = le16_to_cpu(wmi->id);
546
547 rc1 = wmi_send(wil, cmdid, cmd, cmdlen);
548 kfree(wmi);
549
550 wil_info(wil, "%s(0x%04x[%d]) -> %d\n", __func__, cmdid, cmdlen, rc1);
551
552 return rc;
553 }
554
555 static const struct file_operations fops_wmi = {
556 .write = wil_write_file_wmi,
557 .open = simple_open,
558 };
559
560 static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
561 const char *prefix)
562 {
563 char printbuf[16 * 3 + 2];
564 int i = 0;
565 while (i < len) {
566 int l = min(len - i, 16);
567 hex_dump_to_buffer(p + i, l, 16, 1, printbuf,
568 sizeof(printbuf), false);
569 seq_printf(s, "%s%s\n", prefix, printbuf);
570 i += l;
571 }
572 }
573
574 static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
575 {
576 int i = 0;
577 int len = skb_headlen(skb);
578 void *p = skb->data;
579 int nr_frags = skb_shinfo(skb)->nr_frags;
580
581 seq_printf(s, " len = %d\n", len);
582 wil_seq_hexdump(s, p, len, " : ");
583
584 if (nr_frags) {
585 seq_printf(s, " nr_frags = %d\n", nr_frags);
586 for (i = 0; i < nr_frags; i++) {
587 const struct skb_frag_struct *frag =
588 &skb_shinfo(skb)->frags[i];
589
590 len = skb_frag_size(frag);
591 p = skb_frag_address_safe(frag);
592 seq_printf(s, " [%2d] : len = %d\n", i, len);
593 wil_seq_hexdump(s, p, len, " : ");
594 }
595 }
596 }
597
598 /*---------Tx/Rx descriptor------------*/
599 static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
600 {
601 struct wil6210_priv *wil = s->private;
602 struct vring *vring;
603 bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS);
604 if (tx)
605 vring = &(wil->vring_tx[dbg_vring_index]);
606 else
607 vring = &wil->vring_rx;
608
609 if (!vring->va) {
610 if (tx)
611 seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index);
612 else
613 seq_puts(s, "No Rx VRING\n");
614 return 0;
615 }
616
617 if (dbg_txdesc_index < vring->size) {
618 /* use struct vring_tx_desc for Rx as well,
619 * only field used, .dma.length, is the same
620 */
621 volatile struct vring_tx_desc *d =
622 &(vring->va[dbg_txdesc_index].tx);
623 volatile u32 *u = (volatile u32 *)d;
624 struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb;
625
626 if (tx)
627 seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index,
628 dbg_txdesc_index);
629 else
630 seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
631 seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
632 u[0], u[1], u[2], u[3]);
633 seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
634 u[4], u[5], u[6], u[7]);
635 seq_printf(s, " SKB = 0x%p\n", skb);
636
637 if (skb) {
638 skb_get(skb);
639 wil_seq_print_skb(s, skb);
640 kfree_skb(skb);
641 }
642 seq_printf(s, "}\n");
643 } else {
644 if (tx)
645 seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
646 dbg_vring_index, dbg_txdesc_index,
647 vring->size);
648 else
649 seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
650 dbg_txdesc_index, vring->size);
651 }
652
653 return 0;
654 }
655
656 static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
657 {
658 return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
659 }
660
661 static const struct file_operations fops_txdesc = {
662 .open = wil_txdesc_seq_open,
663 .release = single_release,
664 .read = seq_read,
665 .llseek = seq_lseek,
666 };
667
668 /*---------beamforming------------*/
669 static int wil_bf_debugfs_show(struct seq_file *s, void *data)
670 {
671 struct wil6210_priv *wil = s->private;
672 seq_printf(s,
673 "TSF : 0x%016llx\n"
674 "TxMCS : %d\n"
675 "Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n",
676 wil->stats.tsf, wil->stats.bf_mcs,
677 wil->stats.my_rx_sector, wil->stats.my_tx_sector,
678 wil->stats.peer_rx_sector, wil->stats.peer_tx_sector);
679 return 0;
680 }
681
682 static int wil_bf_seq_open(struct inode *inode, struct file *file)
683 {
684 return single_open(file, wil_bf_debugfs_show, inode->i_private);
685 }
686
687 static const struct file_operations fops_bf = {
688 .open = wil_bf_seq_open,
689 .release = single_release,
690 .read = seq_read,
691 .llseek = seq_lseek,
692 };
693 /*---------SSID------------*/
694 static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf,
695 size_t count, loff_t *ppos)
696 {
697 struct wil6210_priv *wil = file->private_data;
698 struct wireless_dev *wdev = wil_to_wdev(wil);
699
700 return simple_read_from_buffer(user_buf, count, ppos,
701 wdev->ssid, wdev->ssid_len);
702 }
703
704 static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf,
705 size_t count, loff_t *ppos)
706 {
707 struct wil6210_priv *wil = file->private_data;
708 struct wireless_dev *wdev = wil_to_wdev(wil);
709 struct net_device *ndev = wil_to_ndev(wil);
710
711 if (*ppos != 0) {
712 wil_err(wil, "Unable to set SSID substring from [%d]\n",
713 (int)*ppos);
714 return -EINVAL;
715 }
716
717 if (count > sizeof(wdev->ssid)) {
718 wil_err(wil, "SSID too long, len = %d\n", (int)count);
719 return -EINVAL;
720 }
721 if (netif_running(ndev)) {
722 wil_err(wil, "Unable to change SSID on running interface\n");
723 return -EINVAL;
724 }
725
726 wdev->ssid_len = count;
727 return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos,
728 buf, count);
729 }
730
731 static const struct file_operations fops_ssid = {
732 .read = wil_read_file_ssid,
733 .write = wil_write_file_ssid,
734 .open = simple_open,
735 };
736
737 /*---------temp------------*/
738 static void print_temp(struct seq_file *s, const char *prefix, u32 t)
739 {
740 switch (t) {
741 case 0:
742 case ~(u32)0:
743 seq_printf(s, "%s N/A\n", prefix);
744 break;
745 default:
746 seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
747 break;
748 }
749 }
750
751 static int wil_temp_debugfs_show(struct seq_file *s, void *data)
752 {
753 struct wil6210_priv *wil = s->private;
754 u32 t_m, t_r;
755
756 int rc = wmi_get_temperature(wil, &t_m, &t_r);
757 if (rc) {
758 seq_printf(s, "Failed\n");
759 return 0;
760 }
761
762 print_temp(s, "T_mac =", t_m);
763 print_temp(s, "T_radio =", t_r);
764
765 return 0;
766 }
767
768 static int wil_temp_seq_open(struct inode *inode, struct file *file)
769 {
770 return single_open(file, wil_temp_debugfs_show, inode->i_private);
771 }
772
773 static const struct file_operations fops_temp = {
774 .open = wil_temp_seq_open,
775 .release = single_release,
776 .read = seq_read,
777 .llseek = seq_lseek,
778 };
779
780 /*---------freq------------*/
781 static int wil_freq_debugfs_show(struct seq_file *s, void *data)
782 {
783 struct wil6210_priv *wil = s->private;
784 struct wireless_dev *wdev = wil_to_wdev(wil);
785 u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
786
787 seq_printf(s, "Freq = %d\n", freq);
788
789 return 0;
790 }
791
792 static int wil_freq_seq_open(struct inode *inode, struct file *file)
793 {
794 return single_open(file, wil_freq_debugfs_show, inode->i_private);
795 }
796
797 static const struct file_operations fops_freq = {
798 .open = wil_freq_seq_open,
799 .release = single_release,
800 .read = seq_read,
801 .llseek = seq_lseek,
802 };
803
804 /*---------link------------*/
805 static int wil_link_debugfs_show(struct seq_file *s, void *data)
806 {
807 struct wil6210_priv *wil = s->private;
808 struct station_info sinfo;
809 int i, rc;
810
811 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
812 struct wil_sta_info *p = &wil->sta[i];
813 char *status = "unknown";
814 switch (p->status) {
815 case wil_sta_unused:
816 status = "unused ";
817 break;
818 case wil_sta_conn_pending:
819 status = "pending ";
820 break;
821 case wil_sta_connected:
822 status = "connected";
823 break;
824 }
825 seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
826 (p->data_port_open ? " data_port_open" : ""));
827
828 if (p->status == wil_sta_connected) {
829 rc = wil_cid_fill_sinfo(wil, i, &sinfo);
830 if (rc)
831 return rc;
832
833 seq_printf(s, " Tx_mcs = %d\n", sinfo.txrate.mcs);
834 seq_printf(s, " Rx_mcs = %d\n", sinfo.rxrate.mcs);
835 seq_printf(s, " SQ = %d\n", sinfo.signal);
836 }
837 }
838
839 return 0;
840 }
841
842 static int wil_link_seq_open(struct inode *inode, struct file *file)
843 {
844 return single_open(file, wil_link_debugfs_show, inode->i_private);
845 }
846
847 static const struct file_operations fops_link = {
848 .open = wil_link_seq_open,
849 .release = single_release,
850 .read = seq_read,
851 .llseek = seq_lseek,
852 };
853
854 /*---------info------------*/
855 static int wil_info_debugfs_show(struct seq_file *s, void *data)
856 {
857 struct wil6210_priv *wil = s->private;
858 struct net_device *ndev = wil_to_ndev(wil);
859 int is_ac = power_supply_is_system_supplied();
860 int rx = atomic_xchg(&wil->isr_count_rx, 0);
861 int tx = atomic_xchg(&wil->isr_count_tx, 0);
862 static ulong rxf_old, txf_old;
863 ulong rxf = ndev->stats.rx_packets;
864 ulong txf = ndev->stats.tx_packets;
865 unsigned int i;
866
867 /* >0 : AC; 0 : battery; <0 : error */
868 seq_printf(s, "AC powered : %d\n", is_ac);
869 seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
870 seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
871 rxf_old = rxf;
872 txf_old = txf;
873
874
875 #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
876 " " __stringify(x) : ""
877
878 for (i = 0; i < ndev->num_tx_queues; i++) {
879 struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
880 unsigned long state = txq->state;
881
882 seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
883 CHECK_QSTATE(DRV_XOFF),
884 CHECK_QSTATE(STACK_XOFF),
885 CHECK_QSTATE(FROZEN)
886 );
887 }
888 #undef CHECK_QSTATE
889 return 0;
890 }
891
892 static int wil_info_seq_open(struct inode *inode, struct file *file)
893 {
894 return single_open(file, wil_info_debugfs_show, inode->i_private);
895 }
896
897 static const struct file_operations fops_info = {
898 .open = wil_info_seq_open,
899 .release = single_release,
900 .read = seq_read,
901 .llseek = seq_lseek,
902 };
903
904 /*---------Station matrix------------*/
905 static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
906 {
907 int i;
908 u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
909 seq_printf(s, "0x%03x [", r->head_seq_num);
910 for (i = 0; i < r->buf_size; i++) {
911 if (i == index)
912 seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
913 else
914 seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
915 }
916 seq_printf(s, "] last drop 0x%03x\n", r->ssn_last_drop);
917 }
918
919 static int wil_sta_debugfs_show(struct seq_file *s, void *data)
920 {
921 struct wil6210_priv *wil = s->private;
922 int i, tid;
923
924 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
925 struct wil_sta_info *p = &wil->sta[i];
926 char *status = "unknown";
927 switch (p->status) {
928 case wil_sta_unused:
929 status = "unused ";
930 break;
931 case wil_sta_conn_pending:
932 status = "pending ";
933 break;
934 case wil_sta_connected:
935 status = "connected";
936 break;
937 }
938 seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
939 (p->data_port_open ? " data_port_open" : ""));
940
941 if (p->status == wil_sta_connected) {
942 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
943 struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
944 if (r) {
945 seq_printf(s, "[%2d] ", tid);
946 wil_print_rxtid(s, r);
947 }
948 }
949 }
950 }
951
952 return 0;
953 }
954
955 static int wil_sta_seq_open(struct inode *inode, struct file *file)
956 {
957 return single_open(file, wil_sta_debugfs_show, inode->i_private);
958 }
959
960 static const struct file_operations fops_sta = {
961 .open = wil_sta_seq_open,
962 .release = single_release,
963 .read = seq_read,
964 .llseek = seq_lseek,
965 };
966
967 /*----------------*/
968 static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
969 struct dentry *dbg)
970 {
971 int i;
972 char name[32];
973
974 for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
975 struct debugfs_blob_wrapper *blob = &wil->blobs[i];
976 const struct fw_map *map = &fw_mapping[i];
977
978 if (!map->name)
979 continue;
980
981 blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
982 blob->size = map->to - map->from;
983 snprintf(name, sizeof(name), "blob_%s", map->name);
984 wil_debugfs_create_ioblob(name, S_IRUGO, dbg, blob);
985 }
986 }
987
988 int wil6210_debugfs_init(struct wil6210_priv *wil)
989 {
990 struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
991 wil_to_wiphy(wil)->debugfsdir);
992
993 if (IS_ERR_OR_NULL(dbg))
994 return -ENODEV;
995
996 debugfs_create_file("mbox", S_IRUGO, dbg, wil, &fops_mbox);
997 debugfs_create_file("vrings", S_IRUGO, dbg, wil, &fops_vring);
998 debugfs_create_file("stations", S_IRUGO, dbg, wil, &fops_sta);
999 debugfs_create_file("desc", S_IRUGO, dbg, wil, &fops_txdesc);
1000 debugfs_create_u32("desc_index", S_IRUGO | S_IWUSR, dbg,
1001 &dbg_txdesc_index);
1002 debugfs_create_u32("vring_index", S_IRUGO | S_IWUSR, dbg,
1003 &dbg_vring_index);
1004
1005 debugfs_create_file("bf", S_IRUGO, dbg, wil, &fops_bf);
1006 debugfs_create_file("ssid", S_IRUGO | S_IWUSR, dbg, wil, &fops_ssid);
1007 debugfs_create_u32("secure_pcp", S_IRUGO | S_IWUSR, dbg,
1008 &wil->secure_pcp);
1009 wil_debugfs_create_ulong("status", S_IRUGO | S_IWUSR, dbg,
1010 &wil->status);
1011 debugfs_create_u32("fw_version", S_IRUGO, dbg, &wil->fw_version);
1012 debugfs_create_x32("hw_version", S_IRUGO, dbg, &wil->hw_version);
1013
1014 wil6210_debugfs_create_ISR(wil, "USER_ICR", dbg,
1015 HOSTADDR(RGF_USER_USER_ICR));
1016 wil6210_debugfs_create_ISR(wil, "DMA_EP_TX_ICR", dbg,
1017 HOSTADDR(RGF_DMA_EP_TX_ICR));
1018 wil6210_debugfs_create_ISR(wil, "DMA_EP_RX_ICR", dbg,
1019 HOSTADDR(RGF_DMA_EP_RX_ICR));
1020 wil6210_debugfs_create_ISR(wil, "DMA_EP_MISC_ICR", dbg,
1021 HOSTADDR(RGF_DMA_EP_MISC_ICR));
1022 wil6210_debugfs_create_pseudo_ISR(wil, dbg);
1023 wil6210_debugfs_create_ITR_CNT(wil, dbg);
1024
1025 wil_debugfs_create_iomem_x32("RGF_USER_USAGE_1", S_IRUGO, dbg,
1026 wil->csr +
1027 HOSTADDR(RGF_USER_USAGE_1));
1028 debugfs_create_u32("mem_addr", S_IRUGO | S_IWUSR, dbg, &mem_addr);
1029 debugfs_create_file("mem_val", S_IRUGO, dbg, wil, &fops_memread);
1030
1031 debugfs_create_file("reset", S_IWUSR, dbg, wil, &fops_reset);
1032 debugfs_create_file("rxon", S_IWUSR, dbg, wil, &fops_rxon);
1033 debugfs_create_file("tx_mgmt", S_IWUSR, dbg, wil, &fops_txmgmt);
1034 debugfs_create_file("wmi_send", S_IWUSR, dbg, wil, &fops_wmi);
1035 debugfs_create_file("temp", S_IRUGO, dbg, wil, &fops_temp);
1036 debugfs_create_file("freq", S_IRUGO, dbg, wil, &fops_freq);
1037 debugfs_create_file("link", S_IRUGO, dbg, wil, &fops_link);
1038 debugfs_create_file("info", S_IRUGO, dbg, wil, &fops_info);
1039
1040 wil6210_debugfs_init_blobs(wil, dbg);
1041
1042 return 0;
1043 }
1044
1045 void wil6210_debugfs_remove(struct wil6210_priv *wil)
1046 {
1047 debugfs_remove_recursive(wil->debug);
1048 wil->debug = NULL;
1049 }
This page took 0.051935 seconds and 6 git commands to generate.