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