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