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