wil6210: print debug info when starting AP
[deliverable/linux.git] / drivers / net / wireless / ath / wil6210 / debugfs.c
CommitLineData
2be7d22f
VK
1/*
2 * Copyright (c) 2012 Qualcomm Atheros, Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include <linux/module.h>
18#include <linux/debugfs.h>
19#include <linux/seq_file.h>
20#include <linux/pci.h>
21#include <linux/rtnetlink.h>
22
23#include "wil6210.h"
24#include "txrx.h"
25
26/* Nasty hack. Better have per device instances */
27static u32 mem_addr;
28static u32 dbg_txdesc_index;
af31cb5a 29static u32 dbg_vring_index; /* 24+ for Rx, 0..23 for Tx */
2be7d22f
VK
30
31static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil,
59f7c0a9
VK
32 const char *name, struct vring *vring,
33 char _s, char _h)
2be7d22f
VK
34{
35 void __iomem *x = wmi_addr(wil, vring->hwtail);
36
37 seq_printf(s, "VRING %s = {\n", name);
39c52ee8 38 seq_printf(s, " pa = %pad\n", &vring->pa);
2be7d22f
VK
39 seq_printf(s, " va = 0x%p\n", vring->va);
40 seq_printf(s, " size = %d\n", vring->size);
41 seq_printf(s, " swtail = %d\n", vring->swtail);
42 seq_printf(s, " swhead = %d\n", vring->swhead);
43 seq_printf(s, " hwtail = [0x%08x] -> ", vring->hwtail);
44 if (x)
45 seq_printf(s, "0x%08x\n", ioread32(x));
46 else
47 seq_printf(s, "???\n");
48
49 if (vring->va && (vring->size < 1025)) {
50 uint i;
51 for (i = 0; i < vring->size; i++) {
52 volatile struct vring_tx_desc *d = &vring->va[i].tx;
53 if ((i % 64) == 0 && (i != 0))
54 seq_printf(s, "\n");
59f7c0a9
VK
55 seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
56 _s : (vring->ctx[i].skb ? _h : 'h'));
2be7d22f
VK
57 }
58 seq_printf(s, "\n");
59 }
60 seq_printf(s, "}\n");
61}
62
63static int wil_vring_debugfs_show(struct seq_file *s, void *data)
64{
65 uint i;
66 struct wil6210_priv *wil = s->private;
67
59f7c0a9 68 wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_');
2be7d22f
VK
69
70 for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
71 struct vring *vring = &(wil->vring_tx[i]);
72 if (vring->va) {
3df2cd36
VK
73 int cid = wil->vring2cid_tid[i][0];
74 int tid = wil->vring2cid_tid[i][1];
2be7d22f
VK
75 char name[10];
76 snprintf(name, sizeof(name), "tx_%2d", i);
3df2cd36
VK
77
78 seq_printf(s, "\n%pM CID %d TID %d\n",
79 wil->sta[cid].addr, cid, tid);
59f7c0a9 80 wil_print_vring(s, wil, name, vring, '_', 'H');
2be7d22f
VK
81 }
82 }
83
84 return 0;
85}
86
87static 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
92static 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
99static 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;
5d21608a 155 char printbuf[16 * 3 + 2];
2be7d22f
VK
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
183static 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
195static 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
200static 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
207static 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
215static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
216{
217 *val = ioread32((void __iomem *)data);
218
219 return 0;
220}
221
222DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
223 wil_debugfs_iomem_x32_set, "0x%08llx\n");
224
225static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
0ecc833b 226 umode_t mode,
2be7d22f
VK
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
234static 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
261static 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
279static 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
297static 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
310static 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
315static 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
2be7d22f
VK
322static 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
361static const struct file_operations fops_ioblob = {
362 .read = wil_read_file_ioblob,
93ecbd64 363 .open = simple_open,
2be7d22f
VK
364 .llseek = default_llseek,
365};
366
367static
368struct dentry *wil_debugfs_create_ioblob(const char *name,
0ecc833b 369 umode_t mode,
2be7d22f
VK
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---*/
376static 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
396static const struct file_operations fops_reset = {
397 .write = wil_write_file_reset,
93ecbd64 398 .open = simple_open,
2be7d22f 399};
0b39aaf2
VK
400/*---write channel 1..4 to rxon for it, 0 to rxoff---*/
401static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
402 size_t len, loff_t *ppos)
403{
404 struct wil6210_priv *wil = file->private_data;
405 int rc;
406 long channel;
407 bool on;
408
409 char *kbuf = kmalloc(len + 1, GFP_KERNEL);
410 if (!kbuf)
411 return -ENOMEM;
412 if (copy_from_user(kbuf, buf, len))
413 return -EIO;
414
415 kbuf[len] = '\0';
416 rc = kstrtol(kbuf, 0, &channel);
417 kfree(kbuf);
418 if (rc)
419 return rc;
420
421 if ((channel < 0) || (channel > 4)) {
422 wil_err(wil, "Invalid channel %ld\n", channel);
423 return -EINVAL;
424 }
425 on = !!channel;
426
427 if (on) {
428 rc = wmi_set_channel(wil, (int)channel);
429 if (rc)
430 return rc;
431 }
432
433 rc = wmi_rxon(wil, on);
434 if (rc)
435 return rc;
436
437 return len;
438}
439
440static const struct file_operations fops_rxon = {
441 .write = wil_write_file_rxon,
442 .open = simple_open,
443};
444/*---tx_mgmt---*/
445/* Write mgmt frame to this file to send it */
446static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
447 size_t len, loff_t *ppos)
448{
449 struct wil6210_priv *wil = file->private_data;
450 struct wiphy *wiphy = wil_to_wiphy(wil);
451 struct wireless_dev *wdev = wil_to_wdev(wil);
452 struct cfg80211_mgmt_tx_params params;
453 int rc;
454
455 void *frame = kmalloc(len, GFP_KERNEL);
456 if (!frame)
457 return -ENOMEM;
458
459 if (copy_from_user(frame, buf, len))
460 return -EIO;
461
462 params.buf = frame;
463 params.len = len;
464 params.chan = wdev->preset_chandef.chan;
465
466 rc = wil_cfg80211_mgmt_tx(wiphy, wdev, &params, NULL);
467
468 kfree(frame);
469 wil_info(wil, "%s() -> %d\n", __func__, rc);
470
471 return len;
472}
473
474static const struct file_operations fops_txmgmt = {
475 .write = wil_write_file_txmgmt,
476 .open = simple_open,
477};
2be7d22f 478
c236658f
VK
479static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
480 const char *prefix)
481{
482 char printbuf[16 * 3 + 2];
483 int i = 0;
484 while (i < len) {
485 int l = min(len - i, 16);
486 hex_dump_to_buffer(p + i, l, 16, 1, printbuf,
487 sizeof(printbuf), false);
488 seq_printf(s, "%s%s\n", prefix, printbuf);
489 i += l;
490 }
491}
492
493static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
494{
495 int i = 0;
496 int len = skb_headlen(skb);
497 void *p = skb->data;
498 int nr_frags = skb_shinfo(skb)->nr_frags;
499
500 seq_printf(s, " len = %d\n", len);
501 wil_seq_hexdump(s, p, len, " : ");
502
503 if (nr_frags) {
504 seq_printf(s, " nr_frags = %d\n", nr_frags);
505 for (i = 0; i < nr_frags; i++) {
506 const struct skb_frag_struct *frag =
507 &skb_shinfo(skb)->frags[i];
508
509 len = skb_frag_size(frag);
510 p = skb_frag_address_safe(frag);
511 seq_printf(s, " [%2d] : len = %d\n", i, len);
512 wil_seq_hexdump(s, p, len, " : ");
513 }
514 }
515}
516
3a85543e 517/*---------Tx/Rx descriptor------------*/
2be7d22f
VK
518static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
519{
520 struct wil6210_priv *wil = s->private;
3a85543e 521 struct vring *vring;
af31cb5a
VK
522 bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS);
523 if (tx)
3a85543e
VK
524 vring = &(wil->vring_tx[dbg_vring_index]);
525 else
526 vring = &wil->vring_rx;
2be7d22f
VK
527
528 if (!vring->va) {
af31cb5a 529 if (tx)
3a85543e
VK
530 seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index);
531 else
532 seq_puts(s, "No Rx VRING\n");
2be7d22f
VK
533 return 0;
534 }
535
536 if (dbg_txdesc_index < vring->size) {
3a85543e
VK
537 /* use struct vring_tx_desc for Rx as well,
538 * only field used, .dma.length, is the same
539 */
2be7d22f
VK
540 volatile struct vring_tx_desc *d =
541 &(vring->va[dbg_txdesc_index].tx);
542 volatile u32 *u = (volatile u32 *)d;
f88f113a 543 struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb;
2be7d22f 544
af31cb5a 545 if (tx)
3a85543e
VK
546 seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index,
547 dbg_txdesc_index);
548 else
549 seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
2be7d22f
VK
550 seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
551 u[0], u[1], u[2], u[3]);
552 seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
553 u[4], u[5], u[6], u[7]);
39c52ee8 554 seq_printf(s, " SKB = 0x%p\n", skb);
2be7d22f
VK
555
556 if (skb) {
c236658f
VK
557 skb_get(skb);
558 wil_seq_print_skb(s, skb);
559 kfree_skb(skb);
2be7d22f
VK
560 }
561 seq_printf(s, "}\n");
562 } else {
af31cb5a 563 if (tx)
3a85543e
VK
564 seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
565 dbg_vring_index, dbg_txdesc_index,
566 vring->size);
567 else
568 seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
569 dbg_txdesc_index, vring->size);
2be7d22f
VK
570 }
571
572 return 0;
573}
574
575static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
576{
577 return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
578}
579
580static const struct file_operations fops_txdesc = {
581 .open = wil_txdesc_seq_open,
582 .release = single_release,
583 .read = seq_read,
584 .llseek = seq_lseek,
585};
586
587/*---------beamforming------------*/
588static int wil_bf_debugfs_show(struct seq_file *s, void *data)
589{
590 struct wil6210_priv *wil = s->private;
591 seq_printf(s,
592 "TSF : 0x%016llx\n"
593 "TxMCS : %d\n"
594 "Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n",
595 wil->stats.tsf, wil->stats.bf_mcs,
596 wil->stats.my_rx_sector, wil->stats.my_tx_sector,
597 wil->stats.peer_rx_sector, wil->stats.peer_tx_sector);
598 return 0;
599}
600
601static int wil_bf_seq_open(struct inode *inode, struct file *file)
602{
603 return single_open(file, wil_bf_debugfs_show, inode->i_private);
604}
605
606static const struct file_operations fops_bf = {
607 .open = wil_bf_seq_open,
608 .release = single_release,
609 .read = seq_read,
610 .llseek = seq_lseek,
611};
612/*---------SSID------------*/
613static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf,
614 size_t count, loff_t *ppos)
615{
616 struct wil6210_priv *wil = file->private_data;
617 struct wireless_dev *wdev = wil_to_wdev(wil);
618
619 return simple_read_from_buffer(user_buf, count, ppos,
620 wdev->ssid, wdev->ssid_len);
621}
622
623static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf,
624 size_t count, loff_t *ppos)
625{
626 struct wil6210_priv *wil = file->private_data;
627 struct wireless_dev *wdev = wil_to_wdev(wil);
628 struct net_device *ndev = wil_to_ndev(wil);
629
630 if (*ppos != 0) {
631 wil_err(wil, "Unable to set SSID substring from [%d]\n",
632 (int)*ppos);
633 return -EINVAL;
634 }
635
636 if (count > sizeof(wdev->ssid)) {
637 wil_err(wil, "SSID too long, len = %d\n", (int)count);
638 return -EINVAL;
639 }
640 if (netif_running(ndev)) {
641 wil_err(wil, "Unable to change SSID on running interface\n");
642 return -EINVAL;
643 }
644
645 wdev->ssid_len = count;
646 return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos,
647 buf, count);
648}
649
650static const struct file_operations fops_ssid = {
651 .read = wil_read_file_ssid,
652 .write = wil_write_file_ssid,
93ecbd64 653 .open = simple_open,
2be7d22f
VK
654};
655
1a2780e0
VK
656/*---------temp------------*/
657static void print_temp(struct seq_file *s, const char *prefix, u32 t)
658{
659 switch (t) {
660 case 0:
661 case ~(u32)0:
662 seq_printf(s, "%s N/A\n", prefix);
663 break;
664 default:
665 seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
666 break;
667 }
668}
669
670static int wil_temp_debugfs_show(struct seq_file *s, void *data)
671{
672 struct wil6210_priv *wil = s->private;
673 u32 t_m, t_r;
674
675 int rc = wmi_get_temperature(wil, &t_m, &t_r);
676 if (rc) {
677 seq_printf(s, "Failed\n");
678 return 0;
679 }
680
681 print_temp(s, "MAC temperature :", t_m);
682 print_temp(s, "Radio temperature :", t_r);
683
684 return 0;
685}
686
687static int wil_temp_seq_open(struct inode *inode, struct file *file)
688{
689 return single_open(file, wil_temp_debugfs_show, inode->i_private);
690}
691
692static const struct file_operations fops_temp = {
693 .open = wil_temp_seq_open,
694 .release = single_release,
695 .read = seq_read,
696 .llseek = seq_lseek,
697};
698
3df2cd36 699/*---------Station matrix------------*/
b4490f42
VK
700static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
701{
702 int i;
703 u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
704 seq_printf(s, "0x%03x [", r->head_seq_num);
705 for (i = 0; i < r->buf_size; i++) {
706 if (i == index)
707 seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
708 else
709 seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
710 }
711 seq_puts(s, "]\n");
712}
3df2cd36
VK
713
714static int wil_sta_debugfs_show(struct seq_file *s, void *data)
715{
716 struct wil6210_priv *wil = s->private;
b4490f42 717 int i, tid;
3df2cd36
VK
718
719 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
720 struct wil_sta_info *p = &wil->sta[i];
721 char *status = "unknown";
722 switch (p->status) {
723 case wil_sta_unused:
724 status = "unused ";
725 break;
726 case wil_sta_conn_pending:
727 status = "pending ";
728 break;
729 case wil_sta_connected:
730 status = "connected";
731 break;
732 }
e58c9f70
VK
733 seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
734 (p->data_port_open ? " data_port_open" : ""));
b4490f42
VK
735
736 if (p->status == wil_sta_connected) {
737 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
738 struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
739 if (r) {
740 seq_printf(s, "[%2d] ", tid);
741 wil_print_rxtid(s, r);
742 }
743 }
744 }
3df2cd36
VK
745 }
746
747 return 0;
748}
749
750static int wil_sta_seq_open(struct inode *inode, struct file *file)
751{
752 return single_open(file, wil_sta_debugfs_show, inode->i_private);
753}
754
755static const struct file_operations fops_sta = {
756 .open = wil_sta_seq_open,
757 .release = single_release,
758 .read = seq_read,
759 .llseek = seq_lseek,
760};
761
2be7d22f
VK
762/*----------------*/
763int wil6210_debugfs_init(struct wil6210_priv *wil)
764{
765 struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
766 wil_to_wiphy(wil)->debugfsdir);
767
768 if (IS_ERR_OR_NULL(dbg))
769 return -ENODEV;
770
771 debugfs_create_file("mbox", S_IRUGO, dbg, wil, &fops_mbox);
772 debugfs_create_file("vrings", S_IRUGO, dbg, wil, &fops_vring);
3df2cd36 773 debugfs_create_file("stations", S_IRUGO, dbg, wil, &fops_sta);
3a85543e
VK
774 debugfs_create_file("desc", S_IRUGO, dbg, wil, &fops_txdesc);
775 debugfs_create_u32("desc_index", S_IRUGO | S_IWUSR, dbg,
2be7d22f 776 &dbg_txdesc_index);
3a85543e
VK
777 debugfs_create_u32("vring_index", S_IRUGO | S_IWUSR, dbg,
778 &dbg_vring_index);
779
2be7d22f
VK
780 debugfs_create_file("bf", S_IRUGO, dbg, wil, &fops_bf);
781 debugfs_create_file("ssid", S_IRUGO | S_IWUSR, dbg, wil, &fops_ssid);
782 debugfs_create_u32("secure_pcp", S_IRUGO | S_IWUSR, dbg,
783 &wil->secure_pcp);
784
785 wil6210_debugfs_create_ISR(wil, "USER_ICR", dbg,
786 HOSTADDR(RGF_USER_USER_ICR));
787 wil6210_debugfs_create_ISR(wil, "DMA_EP_TX_ICR", dbg,
788 HOSTADDR(RGF_DMA_EP_TX_ICR));
789 wil6210_debugfs_create_ISR(wil, "DMA_EP_RX_ICR", dbg,
790 HOSTADDR(RGF_DMA_EP_RX_ICR));
791 wil6210_debugfs_create_ISR(wil, "DMA_EP_MISC_ICR", dbg,
792 HOSTADDR(RGF_DMA_EP_MISC_ICR));
793 wil6210_debugfs_create_pseudo_ISR(wil, dbg);
794 wil6210_debugfs_create_ITR_CNT(wil, dbg);
795
796 debugfs_create_u32("mem_addr", S_IRUGO | S_IWUSR, dbg, &mem_addr);
797 debugfs_create_file("mem_val", S_IRUGO, dbg, wil, &fops_memread);
798
799 debugfs_create_file("reset", S_IWUSR, dbg, wil, &fops_reset);
0b39aaf2
VK
800 debugfs_create_file("rxon", S_IWUSR, dbg, wil, &fops_rxon);
801 debugfs_create_file("tx_mgmt", S_IWUSR, dbg, wil, &fops_txmgmt);
1a2780e0 802 debugfs_create_file("temp", S_IRUGO, dbg, wil, &fops_temp);
2be7d22f
VK
803
804 wil->rgf_blob.data = (void * __force)wil->csr + 0;
805 wil->rgf_blob.size = 0xa000;
806 wil_debugfs_create_ioblob("blob_rgf", S_IRUGO, dbg, &wil->rgf_blob);
807
808 wil->fw_code_blob.data = (void * __force)wil->csr + 0x40000;
809 wil->fw_code_blob.size = 0x40000;
810 wil_debugfs_create_ioblob("blob_fw_code", S_IRUGO, dbg,
811 &wil->fw_code_blob);
812
813 wil->fw_data_blob.data = (void * __force)wil->csr + 0x80000;
814 wil->fw_data_blob.size = 0x8000;
815 wil_debugfs_create_ioblob("blob_fw_data", S_IRUGO, dbg,
816 &wil->fw_data_blob);
817
818 wil->fw_peri_blob.data = (void * __force)wil->csr + 0x88000;
819 wil->fw_peri_blob.size = 0x18000;
820 wil_debugfs_create_ioblob("blob_fw_peri", S_IRUGO, dbg,
821 &wil->fw_peri_blob);
822
823 wil->uc_code_blob.data = (void * __force)wil->csr + 0xa0000;
824 wil->uc_code_blob.size = 0x10000;
825 wil_debugfs_create_ioblob("blob_uc_code", S_IRUGO, dbg,
826 &wil->uc_code_blob);
827
828 wil->uc_data_blob.data = (void * __force)wil->csr + 0xb0000;
829 wil->uc_data_blob.size = 0x4000;
830 wil_debugfs_create_ioblob("blob_uc_data", S_IRUGO, dbg,
831 &wil->uc_data_blob);
832
833 return 0;
834}
835
836void wil6210_debugfs_remove(struct wil6210_priv *wil)
837{
838 debugfs_remove_recursive(wil->debug);
839 wil->debug = NULL;
840}
This page took 0.167415 seconds and 5 git commands to generate.