Merge tag 'nfc-next-3.16-2' of git://git.kernel.org/pub/scm/linux/kernel/git/sameo...
[pandora-kernel.git] / drivers / net / wireless / ath / wil6210 / debugfs.c
1 /*
2  * Copyright (c) 2012 Qualcomm Atheros, Inc.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #include <linux/module.h>
18 #include <linux/debugfs.h>
19 #include <linux/seq_file.h>
20 #include <linux/pci.h>
21 #include <linux/rtnetlink.h>
22
23 #include "wil6210.h"
24 #include "txrx.h"
25
26 /* Nasty hack. Better have per device instances */
27 static u32 mem_addr;
28 static u32 dbg_txdesc_index;
29 static u32 dbg_vring_index; /* 24+ for Rx, 0..23 for Tx */
30
31 static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil,
32                             const char *name, struct vring *vring,
33                             char _s, char _h)
34 {
35         void __iomem *x = wmi_addr(wil, vring->hwtail);
36
37         seq_printf(s, "VRING %s = {\n", name);
38         seq_printf(s, "  pa     = %pad\n", &vring->pa);
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");
55                         seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
56                                         _s : (vring->ctx[i].skb ? _h : 'h'));
57                 }
58                 seq_printf(s, "\n");
59         }
60         seq_printf(s, "}\n");
61 }
62
63 static int wil_vring_debugfs_show(struct seq_file *s, void *data)
64 {
65         uint i;
66         struct wil6210_priv *wil = s->private;
67
68         wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_');
69
70         for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
71                 struct vring *vring = &(wil->vring_tx[i]);
72                 if (vring->va) {
73                         int cid = wil->vring2cid_tid[i][0];
74                         int tid = wil->vring2cid_tid[i][1];
75                         char name[10];
76                         snprintf(name, sizeof(name), "tx_%2d", i);
77
78                         seq_printf(s, "\n%pM CID %d TID %d\n",
79                                    wil->sta[cid].addr, cid, tid);
80                         wil_print_vring(s, wil, name, vring, '_', 'H');
81                 }
82         }
83
84         return 0;
85 }
86
87 static int wil_vring_seq_open(struct inode *inode, struct file *file)
88 {
89         return single_open(file, wil_vring_debugfs_show, inode->i_private);
90 }
91
92 static const struct file_operations fops_vring = {
93         .open           = wil_vring_seq_open,
94         .release        = single_release,
95         .read           = seq_read,
96         .llseek         = seq_lseek,
97 };
98
99 static void wil_print_ring(struct seq_file *s, const char *prefix,
100                            void __iomem *off)
101 {
102         struct wil6210_priv *wil = s->private;
103         struct wil6210_mbox_ring r;
104         int rsize;
105         uint i;
106
107         wil_memcpy_fromio_32(&r, off, sizeof(r));
108         wil_mbox_ring_le2cpus(&r);
109         /*
110          * we just read memory block from NIC. This memory may be
111          * garbage. Check validity before using it.
112          */
113         rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
114
115         seq_printf(s, "ring %s = {\n", prefix);
116         seq_printf(s, "  base = 0x%08x\n", r.base);
117         seq_printf(s, "  size = 0x%04x bytes -> %d entries\n", r.size, rsize);
118         seq_printf(s, "  tail = 0x%08x\n", r.tail);
119         seq_printf(s, "  head = 0x%08x\n", r.head);
120         seq_printf(s, "  entry size = %d\n", r.entry_size);
121
122         if (r.size % sizeof(struct wil6210_mbox_ring_desc)) {
123                 seq_printf(s, "  ??? size is not multiple of %zd, garbage?\n",
124                            sizeof(struct wil6210_mbox_ring_desc));
125                 goto out;
126         }
127
128         if (!wmi_addr(wil, r.base) ||
129             !wmi_addr(wil, r.tail) ||
130             !wmi_addr(wil, r.head)) {
131                 seq_printf(s, "  ??? pointers are garbage?\n");
132                 goto out;
133         }
134
135         for (i = 0; i < rsize; i++) {
136                 struct wil6210_mbox_ring_desc d;
137                 struct wil6210_mbox_hdr hdr;
138                 size_t delta = i * sizeof(d);
139                 void __iomem *x = wil->csr + HOSTADDR(r.base) + delta;
140
141                 wil_memcpy_fromio_32(&d, x, sizeof(d));
142
143                 seq_printf(s, "  [%2x] %s %s%s 0x%08x", i,
144                            d.sync ? "F" : "E",
145                            (r.tail - r.base == delta) ? "t" : " ",
146                            (r.head - r.base == delta) ? "h" : " ",
147                            le32_to_cpu(d.addr));
148                 if (0 == wmi_read_hdr(wil, d.addr, &hdr)) {
149                         u16 len = le16_to_cpu(hdr.len);
150                         seq_printf(s, " -> %04x %04x %04x %02x\n",
151                                    le16_to_cpu(hdr.seq), len,
152                                    le16_to_cpu(hdr.type), hdr.flags);
153                         if (len <= MAX_MBOXITEM_SIZE) {
154                                 int n = 0;
155                                 char printbuf[16 * 3 + 2];
156                                 unsigned char databuf[MAX_MBOXITEM_SIZE];
157                                 void __iomem *src = wmi_buffer(wil, d.addr) +
158                                         sizeof(struct wil6210_mbox_hdr);
159                                 /*
160                                  * No need to check @src for validity -
161                                  * we already validated @d.addr while
162                                  * reading header
163                                  */
164                                 wil_memcpy_fromio_32(databuf, src, len);
165                                 while (n < len) {
166                                         int l = min(len - n, 16);
167                                         hex_dump_to_buffer(databuf + n, l,
168                                                            16, 1, printbuf,
169                                                            sizeof(printbuf),
170                                                            false);
171                                         seq_printf(s, "      : %s\n", printbuf);
172                                         n += l;
173                                 }
174                         }
175                 } else {
176                         seq_printf(s, "\n");
177                 }
178         }
179  out:
180         seq_printf(s, "}\n");
181 }
182
183 static int wil_mbox_debugfs_show(struct seq_file *s, void *data)
184 {
185         struct wil6210_priv *wil = s->private;
186
187         wil_print_ring(s, "tx", wil->csr + HOST_MBOX +
188                        offsetof(struct wil6210_mbox_ctl, tx));
189         wil_print_ring(s, "rx", wil->csr + HOST_MBOX +
190                        offsetof(struct wil6210_mbox_ctl, rx));
191
192         return 0;
193 }
194
195 static int wil_mbox_seq_open(struct inode *inode, struct file *file)
196 {
197         return single_open(file, wil_mbox_debugfs_show, inode->i_private);
198 }
199
200 static const struct file_operations fops_mbox = {
201         .open           = wil_mbox_seq_open,
202         .release        = single_release,
203         .read           = seq_read,
204         .llseek         = seq_lseek,
205 };
206
207 static int wil_debugfs_iomem_x32_set(void *data, u64 val)
208 {
209         iowrite32(val, (void __iomem *)data);
210         wmb(); /* make sure write propagated to HW */
211
212         return 0;
213 }
214
215 static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
216 {
217         *val = ioread32((void __iomem *)data);
218
219         return 0;
220 }
221
222 DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
223                         wil_debugfs_iomem_x32_set, "0x%08llx\n");
224
225 static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
226                                                    umode_t mode,
227                                                    struct dentry *parent,
228                                                    void __iomem *value)
229 {
230         return debugfs_create_file(name, mode, parent, (void * __force)value,
231                                    &fops_iomem_x32);
232 }
233
234 static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
235                                       const char *name,
236                                       struct dentry *parent, u32 off)
237 {
238         struct dentry *d = debugfs_create_dir(name, parent);
239
240         if (IS_ERR_OR_NULL(d))
241                 return -ENODEV;
242
243         wil_debugfs_create_iomem_x32("ICC", S_IRUGO | S_IWUSR, d,
244                                      wil->csr + off);
245         wil_debugfs_create_iomem_x32("ICR", S_IRUGO | S_IWUSR, d,
246                                      wil->csr + off + 4);
247         wil_debugfs_create_iomem_x32("ICM", S_IRUGO | S_IWUSR, d,
248                                      wil->csr + off + 8);
249         wil_debugfs_create_iomem_x32("ICS", S_IWUSR, d,
250                                      wil->csr + off + 12);
251         wil_debugfs_create_iomem_x32("IMV", S_IRUGO | S_IWUSR, d,
252                                      wil->csr + off + 16);
253         wil_debugfs_create_iomem_x32("IMS", S_IWUSR, d,
254                                      wil->csr + off + 20);
255         wil_debugfs_create_iomem_x32("IMC", S_IWUSR, d,
256                                      wil->csr + off + 24);
257
258         return 0;
259 }
260
261 static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
262                                              struct dentry *parent)
263 {
264         struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
265
266         if (IS_ERR_OR_NULL(d))
267                 return -ENODEV;
268
269         wil_debugfs_create_iomem_x32("CAUSE", S_IRUGO, d, wil->csr +
270                                      HOSTADDR(RGF_DMA_PSEUDO_CAUSE));
271         wil_debugfs_create_iomem_x32("MASK_SW", S_IRUGO, d, wil->csr +
272                                      HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW));
273         wil_debugfs_create_iomem_x32("MASK_FW", S_IRUGO, d, wil->csr +
274                                      HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW));
275
276         return 0;
277 }
278
279 static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
280                                           struct dentry *parent)
281 {
282         struct dentry *d = debugfs_create_dir("ITR_CNT", parent);
283
284         if (IS_ERR_OR_NULL(d))
285                 return -ENODEV;
286
287         wil_debugfs_create_iomem_x32("TRSH", S_IRUGO, d, wil->csr +
288                                      HOSTADDR(RGF_DMA_ITR_CNT_TRSH));
289         wil_debugfs_create_iomem_x32("DATA", S_IRUGO, d, wil->csr +
290                                      HOSTADDR(RGF_DMA_ITR_CNT_DATA));
291         wil_debugfs_create_iomem_x32("CTL", S_IRUGO, d, wil->csr +
292                                      HOSTADDR(RGF_DMA_ITR_CNT_CRL));
293
294         return 0;
295 }
296
297 static int wil_memread_debugfs_show(struct seq_file *s, void *data)
298 {
299         struct wil6210_priv *wil = s->private;
300         void __iomem *a = wmi_buffer(wil, cpu_to_le32(mem_addr));
301
302         if (a)
303                 seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, ioread32(a));
304         else
305                 seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
306
307         return 0;
308 }
309
310 static int wil_memread_seq_open(struct inode *inode, struct file *file)
311 {
312         return single_open(file, wil_memread_debugfs_show, inode->i_private);
313 }
314
315 static const struct file_operations fops_memread = {
316         .open           = wil_memread_seq_open,
317         .release        = single_release,
318         .read           = seq_read,
319         .llseek         = seq_lseek,
320 };
321
322 static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
323                                 size_t count, loff_t *ppos)
324 {
325         enum { max_count = 4096 };
326         struct debugfs_blob_wrapper *blob = file->private_data;
327         loff_t pos = *ppos;
328         size_t available = blob->size;
329         void *buf;
330         size_t ret;
331
332         if (pos < 0)
333                 return -EINVAL;
334
335         if (pos >= available || !count)
336                 return 0;
337
338         if (count > available - pos)
339                 count = available - pos;
340         if (count > max_count)
341                 count = max_count;
342
343         buf = kmalloc(count, GFP_KERNEL);
344         if (!buf)
345                 return -ENOMEM;
346
347         wil_memcpy_fromio_32(buf, (const volatile void __iomem *)blob->data +
348                              pos, count);
349
350         ret = copy_to_user(user_buf, buf, count);
351         kfree(buf);
352         if (ret == count)
353                 return -EFAULT;
354
355         count -= ret;
356         *ppos = pos + count;
357
358         return count;
359 }
360
361 static const struct file_operations fops_ioblob = {
362         .read =         wil_read_file_ioblob,
363         .open =         simple_open,
364         .llseek =       default_llseek,
365 };
366
367 static
368 struct dentry *wil_debugfs_create_ioblob(const char *name,
369                                          umode_t mode,
370                                          struct dentry *parent,
371                                          struct debugfs_blob_wrapper *blob)
372 {
373         return debugfs_create_file(name, mode, parent, blob, &fops_ioblob);
374 }
375 /*---reset---*/
376 static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
377                                     size_t len, loff_t *ppos)
378 {
379         struct wil6210_priv *wil = file->private_data;
380         struct net_device *ndev = wil_to_ndev(wil);
381
382         /**
383          * BUG:
384          * this code does NOT sync device state with the rest of system
385          * use with care, debug only!!!
386          */
387         rtnl_lock();
388         dev_close(ndev);
389         ndev->flags &= ~IFF_UP;
390         rtnl_unlock();
391         wil_reset(wil);
392
393         return len;
394 }
395
396 static const struct file_operations fops_reset = {
397         .write = wil_write_file_reset,
398         .open  = simple_open,
399 };
400
401 static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
402                             const char *prefix)
403 {
404         char printbuf[16 * 3 + 2];
405         int i = 0;
406         while (i < len) {
407                 int l = min(len - i, 16);
408                 hex_dump_to_buffer(p + i, l, 16, 1, printbuf,
409                                    sizeof(printbuf), false);
410                 seq_printf(s, "%s%s\n", prefix, printbuf);
411                 i += l;
412         }
413 }
414
415 static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
416 {
417         int i = 0;
418         int len = skb_headlen(skb);
419         void *p = skb->data;
420         int nr_frags = skb_shinfo(skb)->nr_frags;
421
422         seq_printf(s, "    len = %d\n", len);
423         wil_seq_hexdump(s, p, len, "      : ");
424
425         if (nr_frags) {
426                 seq_printf(s, "    nr_frags = %d\n", nr_frags);
427                 for (i = 0; i < nr_frags; i++) {
428                         const struct skb_frag_struct *frag =
429                                         &skb_shinfo(skb)->frags[i];
430
431                         len = skb_frag_size(frag);
432                         p = skb_frag_address_safe(frag);
433                         seq_printf(s, "    [%2d] : len = %d\n", i, len);
434                         wil_seq_hexdump(s, p, len, "      : ");
435                 }
436         }
437 }
438
439 /*---------Tx/Rx descriptor------------*/
440 static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
441 {
442         struct wil6210_priv *wil = s->private;
443         struct vring *vring;
444         bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS);
445         if (tx)
446                 vring = &(wil->vring_tx[dbg_vring_index]);
447         else
448                 vring = &wil->vring_rx;
449
450         if (!vring->va) {
451                 if (tx)
452                         seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index);
453                 else
454                         seq_puts(s, "No Rx VRING\n");
455                 return 0;
456         }
457
458         if (dbg_txdesc_index < vring->size) {
459                 /* use struct vring_tx_desc for Rx as well,
460                  * only field used, .dma.length, is the same
461                  */
462                 volatile struct vring_tx_desc *d =
463                                 &(vring->va[dbg_txdesc_index].tx);
464                 volatile u32 *u = (volatile u32 *)d;
465                 struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb;
466
467                 if (tx)
468                         seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index,
469                                    dbg_txdesc_index);
470                 else
471                         seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
472                 seq_printf(s, "  MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
473                            u[0], u[1], u[2], u[3]);
474                 seq_printf(s, "  DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
475                            u[4], u[5], u[6], u[7]);
476                 seq_printf(s, "  SKB = 0x%p\n", skb);
477
478                 if (skb) {
479                         skb_get(skb);
480                         wil_seq_print_skb(s, skb);
481                         kfree_skb(skb);
482                 }
483                 seq_printf(s, "}\n");
484         } else {
485                 if (tx)
486                         seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
487                                    dbg_vring_index, dbg_txdesc_index,
488                                    vring->size);
489                 else
490                         seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
491                                    dbg_txdesc_index, vring->size);
492         }
493
494         return 0;
495 }
496
497 static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
498 {
499         return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
500 }
501
502 static const struct file_operations fops_txdesc = {
503         .open           = wil_txdesc_seq_open,
504         .release        = single_release,
505         .read           = seq_read,
506         .llseek         = seq_lseek,
507 };
508
509 /*---------beamforming------------*/
510 static int wil_bf_debugfs_show(struct seq_file *s, void *data)
511 {
512         struct wil6210_priv *wil = s->private;
513         seq_printf(s,
514                    "TSF : 0x%016llx\n"
515                    "TxMCS : %d\n"
516                    "Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n",
517                    wil->stats.tsf, wil->stats.bf_mcs,
518                    wil->stats.my_rx_sector, wil->stats.my_tx_sector,
519                    wil->stats.peer_rx_sector, wil->stats.peer_tx_sector);
520         return 0;
521 }
522
523 static int wil_bf_seq_open(struct inode *inode, struct file *file)
524 {
525         return single_open(file, wil_bf_debugfs_show, inode->i_private);
526 }
527
528 static const struct file_operations fops_bf = {
529         .open           = wil_bf_seq_open,
530         .release        = single_release,
531         .read           = seq_read,
532         .llseek         = seq_lseek,
533 };
534 /*---------SSID------------*/
535 static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf,
536                                   size_t count, loff_t *ppos)
537 {
538         struct wil6210_priv *wil = file->private_data;
539         struct wireless_dev *wdev = wil_to_wdev(wil);
540
541         return simple_read_from_buffer(user_buf, count, ppos,
542                                        wdev->ssid, wdev->ssid_len);
543 }
544
545 static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf,
546                                    size_t count, loff_t *ppos)
547 {
548         struct wil6210_priv *wil = file->private_data;
549         struct wireless_dev *wdev = wil_to_wdev(wil);
550         struct net_device *ndev = wil_to_ndev(wil);
551
552         if (*ppos != 0) {
553                 wil_err(wil, "Unable to set SSID substring from [%d]\n",
554                         (int)*ppos);
555                 return -EINVAL;
556         }
557
558         if (count > sizeof(wdev->ssid)) {
559                 wil_err(wil, "SSID too long, len = %d\n", (int)count);
560                 return -EINVAL;
561         }
562         if (netif_running(ndev)) {
563                 wil_err(wil, "Unable to change SSID on running interface\n");
564                 return -EINVAL;
565         }
566
567         wdev->ssid_len = count;
568         return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos,
569                                       buf, count);
570 }
571
572 static const struct file_operations fops_ssid = {
573         .read = wil_read_file_ssid,
574         .write = wil_write_file_ssid,
575         .open  = simple_open,
576 };
577
578 /*---------temp------------*/
579 static void print_temp(struct seq_file *s, const char *prefix, u32 t)
580 {
581         switch (t) {
582         case 0:
583         case ~(u32)0:
584                 seq_printf(s, "%s N/A\n", prefix);
585         break;
586         default:
587                 seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
588                 break;
589         }
590 }
591
592 static int wil_temp_debugfs_show(struct seq_file *s, void *data)
593 {
594         struct wil6210_priv *wil = s->private;
595         u32 t_m, t_r;
596
597         int rc = wmi_get_temperature(wil, &t_m, &t_r);
598         if (rc) {
599                 seq_printf(s, "Failed\n");
600                 return 0;
601         }
602
603         print_temp(s, "MAC temperature   :", t_m);
604         print_temp(s, "Radio temperature :", t_r);
605
606         return 0;
607 }
608
609 static int wil_temp_seq_open(struct inode *inode, struct file *file)
610 {
611         return single_open(file, wil_temp_debugfs_show, inode->i_private);
612 }
613
614 static const struct file_operations fops_temp = {
615         .open           = wil_temp_seq_open,
616         .release        = single_release,
617         .read           = seq_read,
618         .llseek         = seq_lseek,
619 };
620
621 /*---------Station matrix------------*/
622 static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
623 {
624         int i;
625         u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
626         seq_printf(s, "0x%03x [", r->head_seq_num);
627         for (i = 0; i < r->buf_size; i++) {
628                 if (i == index)
629                         seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
630                 else
631                         seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
632         }
633         seq_puts(s, "]\n");
634 }
635
636 static int wil_sta_debugfs_show(struct seq_file *s, void *data)
637 {
638         struct wil6210_priv *wil = s->private;
639         int i, tid;
640
641         for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
642                 struct wil_sta_info *p = &wil->sta[i];
643                 char *status = "unknown";
644                 switch (p->status) {
645                 case wil_sta_unused:
646                         status = "unused   ";
647                         break;
648                 case wil_sta_conn_pending:
649                         status = "pending  ";
650                         break;
651                 case wil_sta_connected:
652                         status = "connected";
653                         break;
654                 }
655                 seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
656                            (p->data_port_open ? " data_port_open" : ""));
657
658                 if (p->status == wil_sta_connected) {
659                         for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
660                                 struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
661                                 if (r) {
662                                         seq_printf(s, "[%2d] ", tid);
663                                         wil_print_rxtid(s, r);
664                                 }
665                         }
666                 }
667         }
668
669         return 0;
670 }
671
672 static int wil_sta_seq_open(struct inode *inode, struct file *file)
673 {
674         return single_open(file, wil_sta_debugfs_show, inode->i_private);
675 }
676
677 static const struct file_operations fops_sta = {
678         .open           = wil_sta_seq_open,
679         .release        = single_release,
680         .read           = seq_read,
681         .llseek         = seq_lseek,
682 };
683
684 /*----------------*/
685 int wil6210_debugfs_init(struct wil6210_priv *wil)
686 {
687         struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
688                         wil_to_wiphy(wil)->debugfsdir);
689
690         if (IS_ERR_OR_NULL(dbg))
691                 return -ENODEV;
692
693         debugfs_create_file("mbox", S_IRUGO, dbg, wil, &fops_mbox);
694         debugfs_create_file("vrings", S_IRUGO, dbg, wil, &fops_vring);
695         debugfs_create_file("stations", S_IRUGO, dbg, wil, &fops_sta);
696         debugfs_create_file("desc", S_IRUGO, dbg, wil, &fops_txdesc);
697         debugfs_create_u32("desc_index", S_IRUGO | S_IWUSR, dbg,
698                            &dbg_txdesc_index);
699         debugfs_create_u32("vring_index", S_IRUGO | S_IWUSR, dbg,
700                            &dbg_vring_index);
701
702         debugfs_create_file("bf", S_IRUGO, dbg, wil, &fops_bf);
703         debugfs_create_file("ssid", S_IRUGO | S_IWUSR, dbg, wil, &fops_ssid);
704         debugfs_create_u32("secure_pcp", S_IRUGO | S_IWUSR, dbg,
705                            &wil->secure_pcp);
706
707         wil6210_debugfs_create_ISR(wil, "USER_ICR", dbg,
708                                    HOSTADDR(RGF_USER_USER_ICR));
709         wil6210_debugfs_create_ISR(wil, "DMA_EP_TX_ICR", dbg,
710                                    HOSTADDR(RGF_DMA_EP_TX_ICR));
711         wil6210_debugfs_create_ISR(wil, "DMA_EP_RX_ICR", dbg,
712                                    HOSTADDR(RGF_DMA_EP_RX_ICR));
713         wil6210_debugfs_create_ISR(wil, "DMA_EP_MISC_ICR", dbg,
714                                    HOSTADDR(RGF_DMA_EP_MISC_ICR));
715         wil6210_debugfs_create_pseudo_ISR(wil, dbg);
716         wil6210_debugfs_create_ITR_CNT(wil, dbg);
717
718         debugfs_create_u32("mem_addr", S_IRUGO | S_IWUSR, dbg, &mem_addr);
719         debugfs_create_file("mem_val", S_IRUGO, dbg, wil, &fops_memread);
720
721         debugfs_create_file("reset", S_IWUSR, dbg, wil, &fops_reset);
722         debugfs_create_file("temp", S_IRUGO, dbg, wil, &fops_temp);
723
724         wil->rgf_blob.data = (void * __force)wil->csr + 0;
725         wil->rgf_blob.size = 0xa000;
726         wil_debugfs_create_ioblob("blob_rgf", S_IRUGO, dbg, &wil->rgf_blob);
727
728         wil->fw_code_blob.data = (void * __force)wil->csr + 0x40000;
729         wil->fw_code_blob.size = 0x40000;
730         wil_debugfs_create_ioblob("blob_fw_code", S_IRUGO, dbg,
731                                   &wil->fw_code_blob);
732
733         wil->fw_data_blob.data = (void * __force)wil->csr + 0x80000;
734         wil->fw_data_blob.size = 0x8000;
735         wil_debugfs_create_ioblob("blob_fw_data", S_IRUGO, dbg,
736                                   &wil->fw_data_blob);
737
738         wil->fw_peri_blob.data = (void * __force)wil->csr + 0x88000;
739         wil->fw_peri_blob.size = 0x18000;
740         wil_debugfs_create_ioblob("blob_fw_peri", S_IRUGO, dbg,
741                                   &wil->fw_peri_blob);
742
743         wil->uc_code_blob.data = (void * __force)wil->csr + 0xa0000;
744         wil->uc_code_blob.size = 0x10000;
745         wil_debugfs_create_ioblob("blob_uc_code", S_IRUGO, dbg,
746                                   &wil->uc_code_blob);
747
748         wil->uc_data_blob.data = (void * __force)wil->csr + 0xb0000;
749         wil->uc_data_blob.size = 0x4000;
750         wil_debugfs_create_ioblob("blob_uc_data", S_IRUGO, dbg,
751                                   &wil->uc_data_blob);
752
753         return 0;
754 }
755
756 void wil6210_debugfs_remove(struct wil6210_priv *wil)
757 {
758         debugfs_remove_recursive(wil->debug);
759         wil->debug = NULL;
760 }