2 * Copyright (c) 2012-2014 Qualcomm Atheros, Inc.
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.
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.
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>
28 /* Nasty hack. Better have per device instances */
30 static u32 dbg_txdesc_index;
31 static u32 dbg_vring_index; /* 24+ for Rx, 0..23 for Tx */
32 u32 vring_idle_trsh = 16; /* HW fetches up to 16 descriptors at once */
46 enum dbg_off_type type;
49 static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil,
50 const char *name, struct vring *vring,
53 void __iomem *x = wmi_addr(wil, vring->hwtail);
56 seq_printf(s, "VRING %s = {\n", name);
57 seq_printf(s, " pa = %pad\n", &vring->pa);
58 seq_printf(s, " va = 0x%p\n", vring->va);
59 seq_printf(s, " size = %d\n", vring->size);
60 seq_printf(s, " swtail = %d\n", vring->swtail);
61 seq_printf(s, " swhead = %d\n", vring->swhead);
62 seq_printf(s, " hwtail = [0x%08x] -> ", vring->hwtail);
65 seq_printf(s, "0x%08x = %d\n", v, v);
70 if (vring->va && (vring->size < 1025)) {
73 for (i = 0; i < vring->size; i++) {
74 volatile struct vring_tx_desc *d = &vring->va[i].tx;
76 if ((i % 64) == 0 && (i != 0))
78 seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
79 _s : (vring->ctx[i].skb ? _h : 'h'));
86 static int wil_vring_debugfs_show(struct seq_file *s, void *data)
89 struct wil6210_priv *wil = s->private;
91 wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_');
93 for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
94 struct vring *vring = &wil->vring_tx[i];
95 struct vring_tx_data *txdata = &wil->vring_tx_data[i];
98 int cid = wil->vring2cid_tid[i][0];
99 int tid = wil->vring2cid_tid[i][1];
100 u32 swhead = vring->swhead;
101 u32 swtail = vring->swtail;
102 int used = (vring->size + swhead - swtail)
104 int avail = vring->size - used - 1;
107 /* performance monitoring */
108 cycles_t now = get_cycles();
109 uint64_t idle = txdata->idle * 100;
110 uint64_t total = now - txdata->begin;
114 snprintf(sidle, sizeof(sidle), "%3d%%",
117 snprintf(sidle, sizeof(sidle), "N/A");
122 snprintf(name, sizeof(name), "tx_%2d", i);
124 if (cid < WIL6210_MAX_CID)
126 "\n%pM CID %d TID %d BACK([%u] %u TU A%s) [%3d|%3d] idle %s\n",
127 wil->sta[cid].addr, cid, tid,
130 txdata->agg_amsdu ? "+" : "-",
134 "\nBroadcast [%3d|%3d] idle %s\n",
137 wil_print_vring(s, wil, name, vring, '_', 'H');
144 static int wil_vring_seq_open(struct inode *inode, struct file *file)
146 return single_open(file, wil_vring_debugfs_show, inode->i_private);
149 static const struct file_operations fops_vring = {
150 .open = wil_vring_seq_open,
151 .release = single_release,
156 static void wil_print_ring(struct seq_file *s, const char *prefix,
159 struct wil6210_priv *wil = s->private;
160 struct wil6210_mbox_ring r;
164 wil_memcpy_fromio_32(&r, off, sizeof(r));
165 wil_mbox_ring_le2cpus(&r);
167 * we just read memory block from NIC. This memory may be
168 * garbage. Check validity before using it.
170 rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
172 seq_printf(s, "ring %s = {\n", prefix);
173 seq_printf(s, " base = 0x%08x\n", r.base);
174 seq_printf(s, " size = 0x%04x bytes -> %d entries\n", r.size, rsize);
175 seq_printf(s, " tail = 0x%08x\n", r.tail);
176 seq_printf(s, " head = 0x%08x\n", r.head);
177 seq_printf(s, " entry size = %d\n", r.entry_size);
179 if (r.size % sizeof(struct wil6210_mbox_ring_desc)) {
180 seq_printf(s, " ??? size is not multiple of %zd, garbage?\n",
181 sizeof(struct wil6210_mbox_ring_desc));
185 if (!wmi_addr(wil, r.base) ||
186 !wmi_addr(wil, r.tail) ||
187 !wmi_addr(wil, r.head)) {
188 seq_puts(s, " ??? pointers are garbage?\n");
192 for (i = 0; i < rsize; i++) {
193 struct wil6210_mbox_ring_desc d;
194 struct wil6210_mbox_hdr hdr;
195 size_t delta = i * sizeof(d);
196 void __iomem *x = wil->csr + HOSTADDR(r.base) + delta;
198 wil_memcpy_fromio_32(&d, x, sizeof(d));
200 seq_printf(s, " [%2x] %s %s%s 0x%08x", i,
202 (r.tail - r.base == delta) ? "t" : " ",
203 (r.head - r.base == delta) ? "h" : " ",
204 le32_to_cpu(d.addr));
205 if (0 == wmi_read_hdr(wil, d.addr, &hdr)) {
206 u16 len = le16_to_cpu(hdr.len);
208 seq_printf(s, " -> %04x %04x %04x %02x\n",
209 le16_to_cpu(hdr.seq), len,
210 le16_to_cpu(hdr.type), hdr.flags);
211 if (len <= MAX_MBOXITEM_SIZE) {
213 char printbuf[16 * 3 + 2];
214 unsigned char databuf[MAX_MBOXITEM_SIZE];
215 void __iomem *src = wmi_buffer(wil, d.addr) +
216 sizeof(struct wil6210_mbox_hdr);
218 * No need to check @src for validity -
219 * we already validated @d.addr while
222 wil_memcpy_fromio_32(databuf, src, len);
224 int l = min(len - n, 16);
226 hex_dump_to_buffer(databuf + n, l,
230 seq_printf(s, " : %s\n", printbuf);
242 static int wil_mbox_debugfs_show(struct seq_file *s, void *data)
244 struct wil6210_priv *wil = s->private;
246 wil_print_ring(s, "tx", wil->csr + HOST_MBOX +
247 offsetof(struct wil6210_mbox_ctl, tx));
248 wil_print_ring(s, "rx", wil->csr + HOST_MBOX +
249 offsetof(struct wil6210_mbox_ctl, rx));
254 static int wil_mbox_seq_open(struct inode *inode, struct file *file)
256 return single_open(file, wil_mbox_debugfs_show, inode->i_private);
259 static const struct file_operations fops_mbox = {
260 .open = wil_mbox_seq_open,
261 .release = single_release,
266 static int wil_debugfs_iomem_x32_set(void *data, u64 val)
268 iowrite32(val, (void __iomem *)data);
269 wmb(); /* make sure write propagated to HW */
274 static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
276 *val = ioread32((void __iomem *)data);
281 DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
282 wil_debugfs_iomem_x32_set, "0x%08llx\n");
284 static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
286 struct dentry *parent,
289 return debugfs_create_file(name, mode, parent, value,
293 static int wil_debugfs_ulong_set(void *data, u64 val)
295 *(ulong *)data = val;
299 static int wil_debugfs_ulong_get(void *data, u64 *val)
301 *val = *(ulong *)data;
305 DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
306 wil_debugfs_ulong_set, "%llu\n");
308 static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode,
309 struct dentry *parent,
312 return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong);
316 * wil6210_debugfs_init_offset - create set of debugfs files
317 * @wil - driver's context, used for printing
318 * @dbg - directory on the debugfs, where files will be created
319 * @base - base address used in address calculation
320 * @tbl - table with file descriptions. Should be terminated with empty element.
322 * Creates files accordingly to the @tbl.
324 static void wil6210_debugfs_init_offset(struct wil6210_priv *wil,
325 struct dentry *dbg, void *base,
326 const struct dbg_off * const tbl)
330 for (i = 0; tbl[i].name; i++) {
333 switch (tbl[i].type) {
335 f = debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg,
339 f = debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg,
343 f = wil_debugfs_create_ulong(tbl[i].name, tbl[i].mode,
344 dbg, base + tbl[i].off);
347 f = wil_debugfs_create_iomem_x32(tbl[i].name,
352 f = ERR_PTR(-EINVAL);
354 if (IS_ERR_OR_NULL(f))
355 wil_err(wil, "Create file \"%s\": err %ld\n",
356 tbl[i].name, PTR_ERR(f));
360 static const struct dbg_off isr_off[] = {
361 {"ICC", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICC), doff_io32},
362 {"ICR", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICR), doff_io32},
363 {"ICM", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICM), doff_io32},
364 {"ICS", S_IWUSR, offsetof(struct RGF_ICR, ICS), doff_io32},
365 {"IMV", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, IMV), doff_io32},
366 {"IMS", S_IWUSR, offsetof(struct RGF_ICR, IMS), doff_io32},
367 {"IMC", S_IWUSR, offsetof(struct RGF_ICR, IMC), doff_io32},
371 static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
373 struct dentry *parent, u32 off)
375 struct dentry *d = debugfs_create_dir(name, parent);
377 if (IS_ERR_OR_NULL(d))
380 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off,
386 static const struct dbg_off pseudo_isr_off[] = {
387 {"CAUSE", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32},
388 {"MASK_SW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32},
389 {"MASK_FW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32},
393 static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
394 struct dentry *parent)
396 struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
398 if (IS_ERR_OR_NULL(d))
401 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
407 static const struct dbg_off lgc_itr_cnt_off[] = {
408 {"TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32},
409 {"DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32},
410 {"CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32},
414 static const struct dbg_off tx_itr_cnt_off[] = {
415 {"TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_CNT_TRSH),
417 {"DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_CNT_DATA),
419 {"CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_CNT_CTL),
421 {"IDL_TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_TRSH),
423 {"IDL_DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_DATA),
425 {"IDL_CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_CTL),
430 static const struct dbg_off rx_itr_cnt_off[] = {
431 {"TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_CNT_TRSH),
433 {"DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_CNT_DATA),
435 {"CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_CNT_CTL),
437 {"IDL_TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_TRSH),
439 {"IDL_DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_DATA),
441 {"IDL_CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_CTL),
446 static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
447 struct dentry *parent)
449 struct dentry *d, *dtx, *drx;
451 d = debugfs_create_dir("ITR_CNT", parent);
452 if (IS_ERR_OR_NULL(d))
455 dtx = debugfs_create_dir("TX", d);
456 drx = debugfs_create_dir("RX", d);
457 if (IS_ERR_OR_NULL(dtx) || IS_ERR_OR_NULL(drx))
460 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
463 wil6210_debugfs_init_offset(wil, dtx, (void * __force)wil->csr,
466 wil6210_debugfs_init_offset(wil, drx, (void * __force)wil->csr,
471 static int wil_memread_debugfs_show(struct seq_file *s, void *data)
473 struct wil6210_priv *wil = s->private;
474 void __iomem *a = wmi_buffer(wil, cpu_to_le32(mem_addr));
477 seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, ioread32(a));
479 seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
484 static int wil_memread_seq_open(struct inode *inode, struct file *file)
486 return single_open(file, wil_memread_debugfs_show, inode->i_private);
489 static const struct file_operations fops_memread = {
490 .open = wil_memread_seq_open,
491 .release = single_release,
496 static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
497 size_t count, loff_t *ppos)
499 enum { max_count = 4096 };
500 struct debugfs_blob_wrapper *blob = file->private_data;
502 size_t available = blob->size;
509 if (pos >= available || !count)
512 if (count > available - pos)
513 count = available - pos;
514 if (count > max_count)
517 buf = kmalloc(count, GFP_KERNEL);
521 wil_memcpy_fromio_32(buf, (const volatile void __iomem *)blob->data +
524 ret = copy_to_user(user_buf, buf, count);
535 static const struct file_operations fops_ioblob = {
536 .read = wil_read_file_ioblob,
538 .llseek = default_llseek,
542 struct dentry *wil_debugfs_create_ioblob(const char *name,
544 struct dentry *parent,
545 struct debugfs_blob_wrapper *blob)
547 return debugfs_create_file(name, mode, parent, blob, &fops_ioblob);
551 static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
552 size_t len, loff_t *ppos)
554 struct wil6210_priv *wil = file->private_data;
555 struct net_device *ndev = wil_to_ndev(wil);
559 * this code does NOT sync device state with the rest of system
560 * use with care, debug only!!!
564 ndev->flags &= ~IFF_UP;
566 wil_reset(wil, true);
571 static const struct file_operations fops_reset = {
572 .write = wil_write_file_reset,
576 /*---write channel 1..4 to rxon for it, 0 to rxoff---*/
577 static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
578 size_t len, loff_t *ppos)
580 struct wil6210_priv *wil = file->private_data;
585 char *kbuf = kmalloc(len + 1, GFP_KERNEL);
589 if (copy_from_user(kbuf, buf, len)) {
595 rc = kstrtol(kbuf, 0, &channel);
600 if ((channel < 0) || (channel > 4)) {
601 wil_err(wil, "Invalid channel %ld\n", channel);
607 rc = wmi_set_channel(wil, (int)channel);
612 rc = wmi_rxon(wil, on);
619 static const struct file_operations fops_rxon = {
620 .write = wil_write_file_rxon,
624 /* block ack control, write:
625 * - "add <ringid> <agg_size> <timeout>" to trigger ADDBA
626 * - "del_tx <ringid> <reason>" to trigger DELBA for Tx side
627 * - "del_rx <CID> <TID> <reason>" to trigger DELBA for Rx side
629 static ssize_t wil_write_back(struct file *file, const char __user *buf,
630 size_t len, loff_t *ppos)
632 struct wil6210_priv *wil = file->private_data;
634 char *kbuf = kmalloc(len + 1, GFP_KERNEL);
641 rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
644 return rc >= 0 ? -EIO : rc;
648 rc = sscanf(kbuf, "%8s %d %d %d", cmd, &p1, &p2, &p3);
656 if (0 == strcmp(cmd, "add")) {
658 wil_err(wil, "BACK: add require at least 2 params\n");
663 wmi_addba(wil, p1, p2, p3);
664 } else if (0 == strcmp(cmd, "del_tx")) {
666 p2 = WLAN_REASON_QSTA_LEAVE_QBSS;
667 wmi_delba_tx(wil, p1, p2);
668 } else if (0 == strcmp(cmd, "del_rx")) {
671 "BACK: del_rx require at least 2 params\n");
675 p3 = WLAN_REASON_QSTA_LEAVE_QBSS;
676 wmi_delba_rx(wil, mk_cidxtid(p1, p2), p3);
678 wil_err(wil, "BACK: Unrecognized command \"%s\"\n", cmd);
685 static ssize_t wil_read_back(struct file *file, char __user *user_buf,
686 size_t count, loff_t *ppos)
688 static const char text[] = "block ack control, write:\n"
689 " - \"add <ringid> <agg_size> <timeout>\" to trigger ADDBA\n"
690 "If missing, <timeout> defaults to 0\n"
691 " - \"del_tx <ringid> <reason>\" to trigger DELBA for Tx side\n"
692 " - \"del_rx <CID> <TID> <reason>\" to trigger DELBA for Rx side\n"
693 "If missing, <reason> set to \"STA_LEAVING\" (36)\n";
695 return simple_read_from_buffer(user_buf, count, ppos, text,
699 static const struct file_operations fops_back = {
700 .read = wil_read_back,
701 .write = wil_write_back,
706 /* Write mgmt frame to this file to send it */
707 static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
708 size_t len, loff_t *ppos)
710 struct wil6210_priv *wil = file->private_data;
711 struct wiphy *wiphy = wil_to_wiphy(wil);
712 struct wireless_dev *wdev = wil_to_wdev(wil);
713 struct cfg80211_mgmt_tx_params params;
715 void *frame = kmalloc(len, GFP_KERNEL);
720 if (copy_from_user(frame, buf, len)) {
727 params.chan = wdev->preset_chandef.chan;
729 rc = wil_cfg80211_mgmt_tx(wiphy, wdev, ¶ms, NULL);
732 wil_info(wil, "%s() -> %d\n", __func__, rc);
737 static const struct file_operations fops_txmgmt = {
738 .write = wil_write_file_txmgmt,
742 /* Write WMI command (w/o mbox header) to this file to send it
743 * WMI starts from wil6210_mbox_hdr_wmi header
745 static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
746 size_t len, loff_t *ppos)
748 struct wil6210_priv *wil = file->private_data;
749 struct wil6210_mbox_hdr_wmi *wmi;
751 int cmdlen = len - sizeof(struct wil6210_mbox_hdr_wmi);
758 wmi = kmalloc(len, GFP_KERNEL);
762 rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
769 cmdid = le16_to_cpu(wmi->id);
771 rc1 = wmi_send(wil, cmdid, cmd, cmdlen);
774 wil_info(wil, "%s(0x%04x[%d]) -> %d\n", __func__, cmdid, cmdlen, rc1);
779 static const struct file_operations fops_wmi = {
780 .write = wil_write_file_wmi,
784 static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
787 char printbuf[16 * 3 + 2];
791 int l = min(len - i, 16);
793 hex_dump_to_buffer(p + i, l, 16, 1, printbuf,
794 sizeof(printbuf), false);
795 seq_printf(s, "%s%s\n", prefix, printbuf);
800 static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
803 int len = skb_headlen(skb);
805 int nr_frags = skb_shinfo(skb)->nr_frags;
807 seq_printf(s, " len = %d\n", len);
808 wil_seq_hexdump(s, p, len, " : ");
811 seq_printf(s, " nr_frags = %d\n", nr_frags);
812 for (i = 0; i < nr_frags; i++) {
813 const struct skb_frag_struct *frag =
814 &skb_shinfo(skb)->frags[i];
816 len = skb_frag_size(frag);
817 p = skb_frag_address_safe(frag);
818 seq_printf(s, " [%2d] : len = %d\n", i, len);
819 wil_seq_hexdump(s, p, len, " : ");
824 /*---------Tx/Rx descriptor------------*/
825 static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
827 struct wil6210_priv *wil = s->private;
829 bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS);
831 vring = tx ? &wil->vring_tx[dbg_vring_index] : &wil->vring_rx;
835 seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index);
837 seq_puts(s, "No Rx VRING\n");
841 if (dbg_txdesc_index < vring->size) {
842 /* use struct vring_tx_desc for Rx as well,
843 * only field used, .dma.length, is the same
845 volatile struct vring_tx_desc *d =
846 &vring->va[dbg_txdesc_index].tx;
847 volatile u32 *u = (volatile u32 *)d;
848 struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb;
851 seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index,
854 seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
855 seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
856 u[0], u[1], u[2], u[3]);
857 seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
858 u[4], u[5], u[6], u[7]);
859 seq_printf(s, " SKB = 0x%p\n", skb);
863 wil_seq_print_skb(s, skb);
869 seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
870 dbg_vring_index, dbg_txdesc_index,
873 seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
874 dbg_txdesc_index, vring->size);
880 static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
882 return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
885 static const struct file_operations fops_txdesc = {
886 .open = wil_txdesc_seq_open,
887 .release = single_release,
892 /*---------beamforming------------*/
893 static char *wil_bfstatus_str(u32 status)
907 static bool is_all_zeros(void * const x_, size_t sz)
909 /* if reply is all-0, ignore this CID */
913 for (n = 0; n < sz / sizeof(*x); n++)
920 static int wil_bf_debugfs_show(struct seq_file *s, void *data)
924 struct wil6210_priv *wil = s->private;
925 struct wmi_notify_req_cmd cmd = {
929 struct wil6210_mbox_hdr_wmi wmi;
930 struct wmi_notify_req_done_event evt;
933 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
937 rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd),
938 WMI_NOTIFY_REQ_DONE_EVENTID, &reply,
940 /* if reply is all-0, ignore this CID */
941 if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt)))
944 status = le32_to_cpu(reply.evt.status);
945 seq_printf(s, "CID %d {\n"
947 " TxMCS = %2d TxTpt = %4d\n"
949 " Status = 0x%08x %s\n"
950 " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
951 " Goodput(rx:tx) %4d:%4d\n"
954 le64_to_cpu(reply.evt.tsf),
955 le16_to_cpu(reply.evt.bf_mcs),
956 le32_to_cpu(reply.evt.tx_tpt),
958 status, wil_bfstatus_str(status),
959 le16_to_cpu(reply.evt.my_rx_sector),
960 le16_to_cpu(reply.evt.my_tx_sector),
961 le16_to_cpu(reply.evt.other_rx_sector),
962 le16_to_cpu(reply.evt.other_tx_sector),
963 le32_to_cpu(reply.evt.rx_goodput),
964 le32_to_cpu(reply.evt.tx_goodput));
969 static int wil_bf_seq_open(struct inode *inode, struct file *file)
971 return single_open(file, wil_bf_debugfs_show, inode->i_private);
974 static const struct file_operations fops_bf = {
975 .open = wil_bf_seq_open,
976 .release = single_release,
981 /*---------SSID------------*/
982 static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf,
983 size_t count, loff_t *ppos)
985 struct wil6210_priv *wil = file->private_data;
986 struct wireless_dev *wdev = wil_to_wdev(wil);
988 return simple_read_from_buffer(user_buf, count, ppos,
989 wdev->ssid, wdev->ssid_len);
992 static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf,
993 size_t count, loff_t *ppos)
995 struct wil6210_priv *wil = file->private_data;
996 struct wireless_dev *wdev = wil_to_wdev(wil);
997 struct net_device *ndev = wil_to_ndev(wil);
1000 wil_err(wil, "Unable to set SSID substring from [%d]\n",
1005 if (count > sizeof(wdev->ssid)) {
1006 wil_err(wil, "SSID too long, len = %d\n", (int)count);
1009 if (netif_running(ndev)) {
1010 wil_err(wil, "Unable to change SSID on running interface\n");
1014 wdev->ssid_len = count;
1015 return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos,
1019 static const struct file_operations fops_ssid = {
1020 .read = wil_read_file_ssid,
1021 .write = wil_write_file_ssid,
1022 .open = simple_open,
1025 /*---------temp------------*/
1026 static void print_temp(struct seq_file *s, const char *prefix, u32 t)
1031 seq_printf(s, "%s N/A\n", prefix);
1034 seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
1039 static int wil_temp_debugfs_show(struct seq_file *s, void *data)
1041 struct wil6210_priv *wil = s->private;
1043 int rc = wmi_get_temperature(wil, &t_m, &t_r);
1046 seq_puts(s, "Failed\n");
1050 print_temp(s, "T_mac =", t_m);
1051 print_temp(s, "T_radio =", t_r);
1056 static int wil_temp_seq_open(struct inode *inode, struct file *file)
1058 return single_open(file, wil_temp_debugfs_show, inode->i_private);
1061 static const struct file_operations fops_temp = {
1062 .open = wil_temp_seq_open,
1063 .release = single_release,
1065 .llseek = seq_lseek,
1068 /*---------freq------------*/
1069 static int wil_freq_debugfs_show(struct seq_file *s, void *data)
1071 struct wil6210_priv *wil = s->private;
1072 struct wireless_dev *wdev = wil_to_wdev(wil);
1073 u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
1075 seq_printf(s, "Freq = %d\n", freq);
1080 static int wil_freq_seq_open(struct inode *inode, struct file *file)
1082 return single_open(file, wil_freq_debugfs_show, inode->i_private);
1085 static const struct file_operations fops_freq = {
1086 .open = wil_freq_seq_open,
1087 .release = single_release,
1089 .llseek = seq_lseek,
1092 /*---------link------------*/
1093 static int wil_link_debugfs_show(struct seq_file *s, void *data)
1095 struct wil6210_priv *wil = s->private;
1096 struct station_info sinfo;
1099 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1100 struct wil_sta_info *p = &wil->sta[i];
1101 char *status = "unknown";
1103 switch (p->status) {
1104 case wil_sta_unused:
1107 case wil_sta_conn_pending:
1108 status = "pending ";
1110 case wil_sta_connected:
1111 status = "connected";
1114 seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
1115 (p->data_port_open ? " data_port_open" : ""));
1117 if (p->status == wil_sta_connected) {
1118 rc = wil_cid_fill_sinfo(wil, i, &sinfo);
1122 seq_printf(s, " Tx_mcs = %d\n", sinfo.txrate.mcs);
1123 seq_printf(s, " Rx_mcs = %d\n", sinfo.rxrate.mcs);
1124 seq_printf(s, " SQ = %d\n", sinfo.signal);
1131 static int wil_link_seq_open(struct inode *inode, struct file *file)
1133 return single_open(file, wil_link_debugfs_show, inode->i_private);
1136 static const struct file_operations fops_link = {
1137 .open = wil_link_seq_open,
1138 .release = single_release,
1140 .llseek = seq_lseek,
1143 /*---------info------------*/
1144 static int wil_info_debugfs_show(struct seq_file *s, void *data)
1146 struct wil6210_priv *wil = s->private;
1147 struct net_device *ndev = wil_to_ndev(wil);
1148 int is_ac = power_supply_is_system_supplied();
1149 int rx = atomic_xchg(&wil->isr_count_rx, 0);
1150 int tx = atomic_xchg(&wil->isr_count_tx, 0);
1151 static ulong rxf_old, txf_old;
1152 ulong rxf = ndev->stats.rx_packets;
1153 ulong txf = ndev->stats.tx_packets;
1156 /* >0 : AC; 0 : battery; <0 : error */
1157 seq_printf(s, "AC powered : %d\n", is_ac);
1158 seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
1159 seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
1163 #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
1164 " " __stringify(x) : ""
1166 for (i = 0; i < ndev->num_tx_queues; i++) {
1167 struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
1168 unsigned long state = txq->state;
1170 seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
1171 CHECK_QSTATE(DRV_XOFF),
1172 CHECK_QSTATE(STACK_XOFF),
1173 CHECK_QSTATE(FROZEN)
1180 static int wil_info_seq_open(struct inode *inode, struct file *file)
1182 return single_open(file, wil_info_debugfs_show, inode->i_private);
1185 static const struct file_operations fops_info = {
1186 .open = wil_info_seq_open,
1187 .release = single_release,
1189 .llseek = seq_lseek,
1192 /*---------recovery------------*/
1193 /* mode = [manual|auto]
1194 * state = [idle|pending|running]
1196 static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf,
1197 size_t count, loff_t *ppos)
1199 struct wil6210_priv *wil = file->private_data;
1202 static const char * const sstate[] = {"idle", "pending", "running"};
1204 n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n",
1205 no_fw_recovery ? "manual" : "auto",
1206 sstate[wil->recovery_state]);
1208 n = min_t(int, n, sizeof(buf));
1210 return simple_read_from_buffer(user_buf, count, ppos,
1214 static ssize_t wil_write_file_recovery(struct file *file,
1215 const char __user *buf_,
1216 size_t count, loff_t *ppos)
1218 struct wil6210_priv *wil = file->private_data;
1219 static const char run_command[] = "run";
1220 char buf[sizeof(run_command) + 1]; /* to detect "runx" */
1223 if (wil->recovery_state != fw_recovery_pending) {
1224 wil_err(wil, "No recovery pending\n");
1229 wil_err(wil, "Offset [%d]\n", (int)*ppos);
1233 if (count > sizeof(buf)) {
1234 wil_err(wil, "Input too long, len = %d\n", (int)count);
1238 rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count);
1243 if (0 == strcmp(buf, run_command))
1244 wil_set_recovery_state(wil, fw_recovery_running);
1246 wil_err(wil, "Bad recovery command \"%s\"\n", buf);
1251 static const struct file_operations fops_recovery = {
1252 .read = wil_read_file_recovery,
1253 .write = wil_write_file_recovery,
1254 .open = simple_open,
1257 /*---------Station matrix------------*/
1258 static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
1261 u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
1263 seq_printf(s, "([%2d] %3d TU) 0x%03x [", r->buf_size, r->timeout,
1265 for (i = 0; i < r->buf_size; i++) {
1267 seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
1269 seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
1271 seq_printf(s, "] last drop 0x%03x\n", r->ssn_last_drop);
1274 static int wil_sta_debugfs_show(struct seq_file *s, void *data)
1275 __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
1277 struct wil6210_priv *wil = s->private;
1280 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1281 struct wil_sta_info *p = &wil->sta[i];
1282 char *status = "unknown";
1284 switch (p->status) {
1285 case wil_sta_unused:
1288 case wil_sta_conn_pending:
1289 status = "pending ";
1291 case wil_sta_connected:
1292 status = "connected";
1295 seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
1296 (p->data_port_open ? " data_port_open" : ""));
1298 if (p->status == wil_sta_connected) {
1299 spin_lock_bh(&p->tid_rx_lock);
1300 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1301 struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
1304 seq_printf(s, "[%2d] ", tid);
1305 wil_print_rxtid(s, r);
1308 spin_unlock_bh(&p->tid_rx_lock);
1315 static int wil_sta_seq_open(struct inode *inode, struct file *file)
1317 return single_open(file, wil_sta_debugfs_show, inode->i_private);
1320 static const struct file_operations fops_sta = {
1321 .open = wil_sta_seq_open,
1322 .release = single_release,
1324 .llseek = seq_lseek,
1327 /*----------------*/
1328 static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
1334 for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
1335 struct debugfs_blob_wrapper *blob = &wil->blobs[i];
1336 const struct fw_map *map = &fw_mapping[i];
1341 blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
1342 blob->size = map->to - map->from;
1343 snprintf(name, sizeof(name), "blob_%s", map->name);
1344 wil_debugfs_create_ioblob(name, S_IRUGO, dbg, blob);
1349 static const struct {
1352 const struct file_operations *fops;
1354 {"mbox", S_IRUGO, &fops_mbox},
1355 {"vrings", S_IRUGO, &fops_vring},
1356 {"stations", S_IRUGO, &fops_sta},
1357 {"desc", S_IRUGO, &fops_txdesc},
1358 {"bf", S_IRUGO, &fops_bf},
1359 {"ssid", S_IRUGO | S_IWUSR, &fops_ssid},
1360 {"mem_val", S_IRUGO, &fops_memread},
1361 {"reset", S_IWUSR, &fops_reset},
1362 {"rxon", S_IWUSR, &fops_rxon},
1363 {"tx_mgmt", S_IWUSR, &fops_txmgmt},
1364 {"wmi_send", S_IWUSR, &fops_wmi},
1365 {"back", S_IRUGO | S_IWUSR, &fops_back},
1366 {"temp", S_IRUGO, &fops_temp},
1367 {"freq", S_IRUGO, &fops_freq},
1368 {"link", S_IRUGO, &fops_link},
1369 {"info", S_IRUGO, &fops_info},
1370 {"recovery", S_IRUGO | S_IWUSR, &fops_recovery},
1373 static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
1378 for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
1379 debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
1380 wil, dbg_files[i].fops);
1383 /* interrupt control blocks */
1384 static const struct {
1388 {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)},
1389 {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)},
1390 {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)},
1391 {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)},
1394 static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
1399 for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
1400 wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
1401 dbg_icr[i].icr_off);
1404 #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
1405 offsetof(struct wil6210_priv, name), type}
1407 /* fields in struct wil6210_priv */
1408 static const struct dbg_off dbg_wil_off[] = {
1409 WIL_FIELD(privacy, S_IRUGO, doff_u32),
1410 WIL_FIELD(status[0], S_IRUGO | S_IWUSR, doff_ulong),
1411 WIL_FIELD(fw_version, S_IRUGO, doff_u32),
1412 WIL_FIELD(hw_version, S_IRUGO, doff_x32),
1413 WIL_FIELD(recovery_count, S_IRUGO, doff_u32),
1414 WIL_FIELD(ap_isolate, S_IRUGO, doff_u32),
1418 static const struct dbg_off dbg_wil_regs[] = {
1419 {"RGF_MAC_MTRL_COUNTER_0", S_IRUGO, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
1421 {"RGF_USER_USAGE_1", S_IRUGO, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
1425 /* static parameters */
1426 static const struct dbg_off dbg_statics[] = {
1427 {"desc_index", S_IRUGO | S_IWUSR, (ulong)&dbg_txdesc_index, doff_u32},
1428 {"vring_index", S_IRUGO | S_IWUSR, (ulong)&dbg_vring_index, doff_u32},
1429 {"mem_addr", S_IRUGO | S_IWUSR, (ulong)&mem_addr, doff_u32},
1430 {"vring_idle_trsh", S_IRUGO | S_IWUSR, (ulong)&vring_idle_trsh,
1435 int wil6210_debugfs_init(struct wil6210_priv *wil)
1437 struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
1438 wil_to_wiphy(wil)->debugfsdir);
1440 if (IS_ERR_OR_NULL(dbg))
1443 wil6210_debugfs_init_files(wil, dbg);
1444 wil6210_debugfs_init_isr(wil, dbg);
1445 wil6210_debugfs_init_blobs(wil, dbg);
1446 wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
1447 wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
1449 wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
1451 wil6210_debugfs_create_pseudo_ISR(wil, dbg);
1453 wil6210_debugfs_create_ITR_CNT(wil, dbg);
1458 void wil6210_debugfs_remove(struct wil6210_priv *wil)
1460 debugfs_remove_recursive(wil->debug);