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