wil6210: fix double definition of 'ctx'
[deliverable/linux.git] / drivers / net / wireless / ath / wil6210 / debugfs.c
CommitLineData
2be7d22f
VK
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>
84bb29b7 22#include <linux/power_supply.h>
2be7d22f
VK
23
24#include "wil6210.h"
25#include "txrx.h"
26
27/* Nasty hack. Better have per device instances */
28static u32 mem_addr;
29static u32 dbg_txdesc_index;
af31cb5a 30static u32 dbg_vring_index; /* 24+ for Rx, 0..23 for Tx */
2be7d22f
VK
31
32static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil,
59f7c0a9
VK
33 const char *name, struct vring *vring,
34 char _s, char _h)
2be7d22f
VK
35{
36 void __iomem *x = wmi_addr(wil, vring->hwtail);
37
38 seq_printf(s, "VRING %s = {\n", name);
39c52ee8 39 seq_printf(s, " pa = %pad\n", &vring->pa);
2be7d22f
VK
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");
59f7c0a9
VK
56 seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
57 _s : (vring->ctx[i].skb ? _h : 'h'));
2be7d22f
VK
58 }
59 seq_printf(s, "\n");
60 }
61 seq_printf(s, "}\n");
62}
63
64static int wil_vring_debugfs_show(struct seq_file *s, void *data)
65{
66 uint i;
67 struct wil6210_priv *wil = s->private;
68
59f7c0a9 69 wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_');
2be7d22f
VK
70
71 for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
72 struct vring *vring = &(wil->vring_tx[i]);
7c0acf86
VK
73 struct vring_tx_data *txdata = &wil->vring_tx_data[i];
74
2be7d22f 75 if (vring->va) {
3df2cd36
VK
76 int cid = wil->vring2cid_tid[i][0];
77 int tid = wil->vring2cid_tid[i][1];
67c3e1b4
VK
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;
2be7d22f 83 char name[10];
7c0acf86
VK
84 /* performance monitoring */
85 cycles_t now = get_cycles();
e48b1790 86 cycles_t idle = txdata->idle * 100;
7c0acf86
VK
87 cycles_t total = now - txdata->begin;
88
e48b1790 89 do_div(idle, total);
7c0acf86
VK
90 txdata->begin = now;
91 txdata->idle = 0ULL;
92
2be7d22f 93 snprintf(name, sizeof(name), "tx_%2d", i);
3df2cd36 94
7c0acf86
VK
95 seq_printf(s, "\n%pM CID %d TID %d [%3d|%3d] idle %3d%%\n",
96 wil->sta[cid].addr, cid, tid, used, avail,
e48b1790 97 (int)idle);
7c0acf86 98
59f7c0a9 99 wil_print_vring(s, wil, name, vring, '_', 'H');
2be7d22f
VK
100 }
101 }
102
103 return 0;
104}
105
106static 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
111static 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
118static 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;
5d21608a 174 char printbuf[16 * 3 + 2];
2be7d22f
VK
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
202static 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
214static 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
219static 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
226static 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
234static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
235{
236 *val = ioread32((void __iomem *)data);
237
238 return 0;
239}
240
241DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
242 wil_debugfs_iomem_x32_set, "0x%08llx\n");
243
244static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
0ecc833b 245 umode_t mode,
2be7d22f
VK
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
3de6cf20
VK
253static int wil_debugfs_ulong_set(void *data, u64 val)
254{
255 *(ulong *)data = val;
256 return 0;
257}
258static int wil_debugfs_ulong_get(void *data, u64 *val)
259{
260 *val = *(ulong *)data;
261 return 0;
262}
263DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
264 wil_debugfs_ulong_set, "%llu\n");
265
266static 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
2be7d22f
VK
273static 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
300static 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
318static 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
4b63261c 326 wil_debugfs_create_iomem_x32("TRSH", S_IRUGO | S_IWUSR, d, wil->csr +
2be7d22f 327 HOSTADDR(RGF_DMA_ITR_CNT_TRSH));
4b63261c 328 wil_debugfs_create_iomem_x32("DATA", S_IRUGO | S_IWUSR, d, wil->csr +
2be7d22f 329 HOSTADDR(RGF_DMA_ITR_CNT_DATA));
4b63261c 330 wil_debugfs_create_iomem_x32("CTL", S_IRUGO | S_IWUSR, d, wil->csr +
2be7d22f
VK
331 HOSTADDR(RGF_DMA_ITR_CNT_CRL));
332
333 return 0;
334}
335
336static 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
349static 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
354static 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
2be7d22f
VK
361static 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
400static const struct file_operations fops_ioblob = {
401 .read = wil_read_file_ioblob,
93ecbd64 402 .open = simple_open,
2be7d22f
VK
403 .llseek = default_llseek,
404};
405
406static
407struct dentry *wil_debugfs_create_ioblob(const char *name,
0ecc833b 408 umode_t mode,
2be7d22f
VK
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---*/
415static 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
435static const struct file_operations fops_reset = {
436 .write = wil_write_file_reset,
93ecbd64 437 .open = simple_open,
2be7d22f 438};
0b39aaf2
VK
439/*---write channel 1..4 to rxon for it, 0 to rxoff---*/
440static 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 return -EIO;
453
454 kbuf[len] = '\0';
455 rc = kstrtol(kbuf, 0, &channel);
456 kfree(kbuf);
457 if (rc)
458 return rc;
459
460 if ((channel < 0) || (channel > 4)) {
461 wil_err(wil, "Invalid channel %ld\n", channel);
462 return -EINVAL;
463 }
464 on = !!channel;
465
466 if (on) {
467 rc = wmi_set_channel(wil, (int)channel);
468 if (rc)
469 return rc;
470 }
471
472 rc = wmi_rxon(wil, on);
473 if (rc)
474 return rc;
475
476 return len;
477}
478
479static const struct file_operations fops_rxon = {
480 .write = wil_write_file_rxon,
481 .open = simple_open,
482};
483/*---tx_mgmt---*/
484/* Write mgmt frame to this file to send it */
485static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
486 size_t len, loff_t *ppos)
487{
488 struct wil6210_priv *wil = file->private_data;
489 struct wiphy *wiphy = wil_to_wiphy(wil);
490 struct wireless_dev *wdev = wil_to_wdev(wil);
491 struct cfg80211_mgmt_tx_params params;
492 int rc;
493
494 void *frame = kmalloc(len, GFP_KERNEL);
495 if (!frame)
496 return -ENOMEM;
497
498 if (copy_from_user(frame, buf, len))
499 return -EIO;
500
501 params.buf = frame;
502 params.len = len;
503 params.chan = wdev->preset_chandef.chan;
504
505 rc = wil_cfg80211_mgmt_tx(wiphy, wdev, &params, NULL);
506
507 kfree(frame);
508 wil_info(wil, "%s() -> %d\n", __func__, rc);
509
510 return len;
511}
512
513static const struct file_operations fops_txmgmt = {
514 .write = wil_write_file_txmgmt,
515 .open = simple_open,
516};
2be7d22f 517
ff974e40
VK
518/* Write WMI command (w/o mbox header) to this file to send it
519 * WMI starts from wil6210_mbox_hdr_wmi header
520 */
521static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
522 size_t len, loff_t *ppos)
523{
524 struct wil6210_priv *wil = file->private_data;
525 struct wil6210_mbox_hdr_wmi *wmi;
526 void *cmd;
527 int cmdlen = len - sizeof(struct wil6210_mbox_hdr_wmi);
528 u16 cmdid;
529 int rc, rc1;
530
531 if (cmdlen <= 0)
532 return -EINVAL;
533
534 wmi = kmalloc(len, GFP_KERNEL);
535 if (!wmi)
536 return -ENOMEM;
537
538 rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
539 if (rc < 0)
540 return rc;
541
542 cmd = &wmi[1];
543 cmdid = le16_to_cpu(wmi->id);
544
545 rc1 = wmi_send(wil, cmdid, cmd, cmdlen);
546 kfree(wmi);
547
548 wil_info(wil, "%s(0x%04x[%d]) -> %d\n", __func__, cmdid, cmdlen, rc1);
549
550 return rc;
551}
552
553static const struct file_operations fops_wmi = {
554 .write = wil_write_file_wmi,
555 .open = simple_open,
556};
557
c236658f
VK
558static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
559 const char *prefix)
560{
561 char printbuf[16 * 3 + 2];
562 int i = 0;
563 while (i < len) {
564 int l = min(len - i, 16);
565 hex_dump_to_buffer(p + i, l, 16, 1, printbuf,
566 sizeof(printbuf), false);
567 seq_printf(s, "%s%s\n", prefix, printbuf);
568 i += l;
569 }
570}
571
572static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
573{
574 int i = 0;
575 int len = skb_headlen(skb);
576 void *p = skb->data;
577 int nr_frags = skb_shinfo(skb)->nr_frags;
578
579 seq_printf(s, " len = %d\n", len);
580 wil_seq_hexdump(s, p, len, " : ");
581
582 if (nr_frags) {
583 seq_printf(s, " nr_frags = %d\n", nr_frags);
584 for (i = 0; i < nr_frags; i++) {
585 const struct skb_frag_struct *frag =
586 &skb_shinfo(skb)->frags[i];
587
588 len = skb_frag_size(frag);
589 p = skb_frag_address_safe(frag);
590 seq_printf(s, " [%2d] : len = %d\n", i, len);
591 wil_seq_hexdump(s, p, len, " : ");
592 }
593 }
594}
595
3a85543e 596/*---------Tx/Rx descriptor------------*/
2be7d22f
VK
597static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
598{
599 struct wil6210_priv *wil = s->private;
3a85543e 600 struct vring *vring;
af31cb5a
VK
601 bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS);
602 if (tx)
3a85543e
VK
603 vring = &(wil->vring_tx[dbg_vring_index]);
604 else
605 vring = &wil->vring_rx;
2be7d22f
VK
606
607 if (!vring->va) {
af31cb5a 608 if (tx)
3a85543e
VK
609 seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index);
610 else
611 seq_puts(s, "No Rx VRING\n");
2be7d22f
VK
612 return 0;
613 }
614
615 if (dbg_txdesc_index < vring->size) {
3a85543e
VK
616 /* use struct vring_tx_desc for Rx as well,
617 * only field used, .dma.length, is the same
618 */
2be7d22f
VK
619 volatile struct vring_tx_desc *d =
620 &(vring->va[dbg_txdesc_index].tx);
621 volatile u32 *u = (volatile u32 *)d;
f88f113a 622 struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb;
2be7d22f 623
af31cb5a 624 if (tx)
3a85543e
VK
625 seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index,
626 dbg_txdesc_index);
627 else
628 seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
2be7d22f
VK
629 seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
630 u[0], u[1], u[2], u[3]);
631 seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
632 u[4], u[5], u[6], u[7]);
39c52ee8 633 seq_printf(s, " SKB = 0x%p\n", skb);
2be7d22f
VK
634
635 if (skb) {
c236658f
VK
636 skb_get(skb);
637 wil_seq_print_skb(s, skb);
638 kfree_skb(skb);
2be7d22f
VK
639 }
640 seq_printf(s, "}\n");
641 } else {
af31cb5a 642 if (tx)
3a85543e
VK
643 seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
644 dbg_vring_index, dbg_txdesc_index,
645 vring->size);
646 else
647 seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
648 dbg_txdesc_index, vring->size);
2be7d22f
VK
649 }
650
651 return 0;
652}
653
654static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
655{
656 return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
657}
658
659static const struct file_operations fops_txdesc = {
660 .open = wil_txdesc_seq_open,
661 .release = single_release,
662 .read = seq_read,
663 .llseek = seq_lseek,
664};
665
666/*---------beamforming------------*/
667static int wil_bf_debugfs_show(struct seq_file *s, void *data)
668{
669 struct wil6210_priv *wil = s->private;
670 seq_printf(s,
671 "TSF : 0x%016llx\n"
672 "TxMCS : %d\n"
673 "Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n",
674 wil->stats.tsf, wil->stats.bf_mcs,
675 wil->stats.my_rx_sector, wil->stats.my_tx_sector,
676 wil->stats.peer_rx_sector, wil->stats.peer_tx_sector);
677 return 0;
678}
679
680static int wil_bf_seq_open(struct inode *inode, struct file *file)
681{
682 return single_open(file, wil_bf_debugfs_show, inode->i_private);
683}
684
685static const struct file_operations fops_bf = {
686 .open = wil_bf_seq_open,
687 .release = single_release,
688 .read = seq_read,
689 .llseek = seq_lseek,
690};
691/*---------SSID------------*/
692static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf,
693 size_t count, loff_t *ppos)
694{
695 struct wil6210_priv *wil = file->private_data;
696 struct wireless_dev *wdev = wil_to_wdev(wil);
697
698 return simple_read_from_buffer(user_buf, count, ppos,
699 wdev->ssid, wdev->ssid_len);
700}
701
702static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf,
703 size_t count, loff_t *ppos)
704{
705 struct wil6210_priv *wil = file->private_data;
706 struct wireless_dev *wdev = wil_to_wdev(wil);
707 struct net_device *ndev = wil_to_ndev(wil);
708
709 if (*ppos != 0) {
710 wil_err(wil, "Unable to set SSID substring from [%d]\n",
711 (int)*ppos);
712 return -EINVAL;
713 }
714
715 if (count > sizeof(wdev->ssid)) {
716 wil_err(wil, "SSID too long, len = %d\n", (int)count);
717 return -EINVAL;
718 }
719 if (netif_running(ndev)) {
720 wil_err(wil, "Unable to change SSID on running interface\n");
721 return -EINVAL;
722 }
723
724 wdev->ssid_len = count;
725 return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos,
726 buf, count);
727}
728
729static const struct file_operations fops_ssid = {
730 .read = wil_read_file_ssid,
731 .write = wil_write_file_ssid,
93ecbd64 732 .open = simple_open,
2be7d22f
VK
733};
734
1a2780e0
VK
735/*---------temp------------*/
736static void print_temp(struct seq_file *s, const char *prefix, u32 t)
737{
738 switch (t) {
739 case 0:
740 case ~(u32)0:
741 seq_printf(s, "%s N/A\n", prefix);
742 break;
743 default:
744 seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
745 break;
746 }
747}
748
749static int wil_temp_debugfs_show(struct seq_file *s, void *data)
750{
751 struct wil6210_priv *wil = s->private;
752 u32 t_m, t_r;
753
754 int rc = wmi_get_temperature(wil, &t_m, &t_r);
755 if (rc) {
756 seq_printf(s, "Failed\n");
757 return 0;
758 }
759
d45cff9f
VK
760 print_temp(s, "T_mac =", t_m);
761 print_temp(s, "T_radio =", t_r);
1a2780e0
VK
762
763 return 0;
764}
765
766static int wil_temp_seq_open(struct inode *inode, struct file *file)
767{
768 return single_open(file, wil_temp_debugfs_show, inode->i_private);
769}
770
771static const struct file_operations fops_temp = {
772 .open = wil_temp_seq_open,
773 .release = single_release,
774 .read = seq_read,
775 .llseek = seq_lseek,
776};
777
9eb82d43
VK
778/*---------freq------------*/
779static int wil_freq_debugfs_show(struct seq_file *s, void *data)
780{
781 struct wil6210_priv *wil = s->private;
782 struct wireless_dev *wdev = wil_to_wdev(wil);
783 u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
784
785 seq_printf(s, "Freq = %d\n", freq);
786
787 return 0;
788}
789
790static int wil_freq_seq_open(struct inode *inode, struct file *file)
791{
792 return single_open(file, wil_freq_debugfs_show, inode->i_private);
793}
794
795static const struct file_operations fops_freq = {
796 .open = wil_freq_seq_open,
797 .release = single_release,
798 .read = seq_read,
799 .llseek = seq_lseek,
800};
801
802/*---------link------------*/
803static int wil_link_debugfs_show(struct seq_file *s, void *data)
804{
805 struct wil6210_priv *wil = s->private;
806 struct station_info sinfo;
807 int i, rc;
808
809 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
810 struct wil_sta_info *p = &wil->sta[i];
811 char *status = "unknown";
812 switch (p->status) {
813 case wil_sta_unused:
814 status = "unused ";
815 break;
816 case wil_sta_conn_pending:
817 status = "pending ";
818 break;
819 case wil_sta_connected:
820 status = "connected";
821 break;
822 }
823 seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
824 (p->data_port_open ? " data_port_open" : ""));
825
826 if (p->status == wil_sta_connected) {
827 rc = wil_cid_fill_sinfo(wil, i, &sinfo);
828 if (rc)
829 return rc;
830
831 seq_printf(s, " Tx_mcs = %d\n", sinfo.txrate.mcs);
832 seq_printf(s, " Rx_mcs = %d\n", sinfo.rxrate.mcs);
833 seq_printf(s, " SQ = %d\n", sinfo.signal);
834 }
835 }
836
837 return 0;
838}
839
840static int wil_link_seq_open(struct inode *inode, struct file *file)
841{
842 return single_open(file, wil_link_debugfs_show, inode->i_private);
843}
844
845static const struct file_operations fops_link = {
846 .open = wil_link_seq_open,
847 .release = single_release,
848 .read = seq_read,
849 .llseek = seq_lseek,
850};
851
84bb29b7
VK
852/*---------info------------*/
853static int wil_info_debugfs_show(struct seq_file *s, void *data)
854{
be299858
VK
855 struct wil6210_priv *wil = s->private;
856 struct net_device *ndev = wil_to_ndev(wil);
84bb29b7 857 int is_ac = power_supply_is_system_supplied();
be299858
VK
858 int rx = atomic_xchg(&wil->isr_count_rx, 0);
859 int tx = atomic_xchg(&wil->isr_count_tx, 0);
860 static ulong rxf_old, txf_old;
861 ulong rxf = ndev->stats.rx_packets;
862 ulong txf = ndev->stats.tx_packets;
55f8f680 863 unsigned int i;
84bb29b7
VK
864
865 /* >0 : AC; 0 : battery; <0 : error */
866 seq_printf(s, "AC powered : %d\n", is_ac);
be299858
VK
867 seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
868 seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
869 rxf_old = rxf;
870 txf_old = txf;
84bb29b7 871
55f8f680
VK
872
873#define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
874 " " __stringify(x) : ""
875
876 for (i = 0; i < ndev->num_tx_queues; i++) {
877 struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
878 unsigned long state = txq->state;
879
880 seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
881 CHECK_QSTATE(DRV_XOFF),
882 CHECK_QSTATE(STACK_XOFF),
883 CHECK_QSTATE(FROZEN)
884 );
885 }
886#undef CHECK_QSTATE
84bb29b7
VK
887 return 0;
888}
889
890static int wil_info_seq_open(struct inode *inode, struct file *file)
891{
892 return single_open(file, wil_info_debugfs_show, inode->i_private);
893}
894
895static const struct file_operations fops_info = {
896 .open = wil_info_seq_open,
897 .release = single_release,
898 .read = seq_read,
899 .llseek = seq_lseek,
900};
901
3df2cd36 902/*---------Station matrix------------*/
b4490f42
VK
903static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
904{
905 int i;
906 u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
907 seq_printf(s, "0x%03x [", r->head_seq_num);
908 for (i = 0; i < r->buf_size; i++) {
909 if (i == index)
910 seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
911 else
912 seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
913 }
d5b1c32f 914 seq_printf(s, "] last drop 0x%03x\n", r->ssn_last_drop);
b4490f42 915}
3df2cd36
VK
916
917static int wil_sta_debugfs_show(struct seq_file *s, void *data)
918{
919 struct wil6210_priv *wil = s->private;
b4490f42 920 int i, tid;
3df2cd36
VK
921
922 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
923 struct wil_sta_info *p = &wil->sta[i];
924 char *status = "unknown";
925 switch (p->status) {
926 case wil_sta_unused:
927 status = "unused ";
928 break;
929 case wil_sta_conn_pending:
930 status = "pending ";
931 break;
932 case wil_sta_connected:
933 status = "connected";
934 break;
935 }
e58c9f70
VK
936 seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
937 (p->data_port_open ? " data_port_open" : ""));
b4490f42
VK
938
939 if (p->status == wil_sta_connected) {
940 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
941 struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
942 if (r) {
943 seq_printf(s, "[%2d] ", tid);
944 wil_print_rxtid(s, r);
945 }
946 }
947 }
3df2cd36
VK
948 }
949
950 return 0;
951}
952
953static int wil_sta_seq_open(struct inode *inode, struct file *file)
954{
955 return single_open(file, wil_sta_debugfs_show, inode->i_private);
956}
957
958static const struct file_operations fops_sta = {
959 .open = wil_sta_seq_open,
960 .release = single_release,
961 .read = seq_read,
962 .llseek = seq_lseek,
963};
964
2be7d22f
VK
965/*----------------*/
966int wil6210_debugfs_init(struct wil6210_priv *wil)
967{
968 struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
969 wil_to_wiphy(wil)->debugfsdir);
970
971 if (IS_ERR_OR_NULL(dbg))
972 return -ENODEV;
973
974 debugfs_create_file("mbox", S_IRUGO, dbg, wil, &fops_mbox);
975 debugfs_create_file("vrings", S_IRUGO, dbg, wil, &fops_vring);
3df2cd36 976 debugfs_create_file("stations", S_IRUGO, dbg, wil, &fops_sta);
3a85543e
VK
977 debugfs_create_file("desc", S_IRUGO, dbg, wil, &fops_txdesc);
978 debugfs_create_u32("desc_index", S_IRUGO | S_IWUSR, dbg,
2be7d22f 979 &dbg_txdesc_index);
3a85543e
VK
980 debugfs_create_u32("vring_index", S_IRUGO | S_IWUSR, dbg,
981 &dbg_vring_index);
982
2be7d22f
VK
983 debugfs_create_file("bf", S_IRUGO, dbg, wil, &fops_bf);
984 debugfs_create_file("ssid", S_IRUGO | S_IWUSR, dbg, wil, &fops_ssid);
985 debugfs_create_u32("secure_pcp", S_IRUGO | S_IWUSR, dbg,
986 &wil->secure_pcp);
3de6cf20
VK
987 wil_debugfs_create_ulong("status", S_IRUGO | S_IWUSR, dbg,
988 &wil->status);
6f55007d
VK
989 debugfs_create_u32("fw_version", S_IRUGO, dbg, &wil->fw_version);
990 debugfs_create_x32("hw_version", S_IRUGO, dbg, &wil->hw_version);
2be7d22f
VK
991
992 wil6210_debugfs_create_ISR(wil, "USER_ICR", dbg,
993 HOSTADDR(RGF_USER_USER_ICR));
994 wil6210_debugfs_create_ISR(wil, "DMA_EP_TX_ICR", dbg,
995 HOSTADDR(RGF_DMA_EP_TX_ICR));
996 wil6210_debugfs_create_ISR(wil, "DMA_EP_RX_ICR", dbg,
997 HOSTADDR(RGF_DMA_EP_RX_ICR));
998 wil6210_debugfs_create_ISR(wil, "DMA_EP_MISC_ICR", dbg,
999 HOSTADDR(RGF_DMA_EP_MISC_ICR));
1000 wil6210_debugfs_create_pseudo_ISR(wil, dbg);
1001 wil6210_debugfs_create_ITR_CNT(wil, dbg);
1002
1003 debugfs_create_u32("mem_addr", S_IRUGO | S_IWUSR, dbg, &mem_addr);
1004 debugfs_create_file("mem_val", S_IRUGO, dbg, wil, &fops_memread);
1005
1006 debugfs_create_file("reset", S_IWUSR, dbg, wil, &fops_reset);
0b39aaf2
VK
1007 debugfs_create_file("rxon", S_IWUSR, dbg, wil, &fops_rxon);
1008 debugfs_create_file("tx_mgmt", S_IWUSR, dbg, wil, &fops_txmgmt);
ff974e40 1009 debugfs_create_file("wmi_send", S_IWUSR, dbg, wil, &fops_wmi);
1a2780e0 1010 debugfs_create_file("temp", S_IRUGO, dbg, wil, &fops_temp);
9eb82d43
VK
1011 debugfs_create_file("freq", S_IRUGO, dbg, wil, &fops_freq);
1012 debugfs_create_file("link", S_IRUGO, dbg, wil, &fops_link);
84bb29b7 1013 debugfs_create_file("info", S_IRUGO, dbg, wil, &fops_info);
2be7d22f
VK
1014
1015 wil->rgf_blob.data = (void * __force)wil->csr + 0;
1016 wil->rgf_blob.size = 0xa000;
1017 wil_debugfs_create_ioblob("blob_rgf", S_IRUGO, dbg, &wil->rgf_blob);
1018
1019 wil->fw_code_blob.data = (void * __force)wil->csr + 0x40000;
1020 wil->fw_code_blob.size = 0x40000;
1021 wil_debugfs_create_ioblob("blob_fw_code", S_IRUGO, dbg,
1022 &wil->fw_code_blob);
1023
1024 wil->fw_data_blob.data = (void * __force)wil->csr + 0x80000;
1025 wil->fw_data_blob.size = 0x8000;
1026 wil_debugfs_create_ioblob("blob_fw_data", S_IRUGO, dbg,
1027 &wil->fw_data_blob);
1028
1029 wil->fw_peri_blob.data = (void * __force)wil->csr + 0x88000;
1030 wil->fw_peri_blob.size = 0x18000;
1031 wil_debugfs_create_ioblob("blob_fw_peri", S_IRUGO, dbg,
1032 &wil->fw_peri_blob);
1033
1034 wil->uc_code_blob.data = (void * __force)wil->csr + 0xa0000;
1035 wil->uc_code_blob.size = 0x10000;
1036 wil_debugfs_create_ioblob("blob_uc_code", S_IRUGO, dbg,
1037 &wil->uc_code_blob);
1038
1039 wil->uc_data_blob.data = (void * __force)wil->csr + 0xb0000;
1040 wil->uc_data_blob.size = 0x4000;
1041 wil_debugfs_create_ioblob("blob_uc_data", S_IRUGO, dbg,
1042 &wil->uc_data_blob);
1043
1044 return 0;
1045}
1046
1047void wil6210_debugfs_remove(struct wil6210_priv *wil)
1048{
1049 debugfs_remove_recursive(wil->debug);
1050 wil->debug = NULL;
1051}
This page took 0.173107 seconds and 5 git commands to generate.