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 */
45 enum dbg_off_type type;
48 static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil,
49 const char *name, struct vring *vring,
52 void __iomem *x = wmi_addr(wil, vring->hwtail);
54 seq_printf(s, "VRING %s = {\n", name);
55 seq_printf(s, " pa = %pad\n", &vring->pa);
56 seq_printf(s, " va = 0x%p\n", vring->va);
57 seq_printf(s, " size = %d\n", vring->size);
58 seq_printf(s, " swtail = %d\n", vring->swtail);
59 seq_printf(s, " swhead = %d\n", vring->swhead);
60 seq_printf(s, " hwtail = [0x%08x] -> ", vring->hwtail);
62 seq_printf(s, "0x%08x\n", ioread32(x));
66 if (vring->va && (vring->size < 1025)) {
69 for (i = 0; i < vring->size; i++) {
70 volatile struct vring_tx_desc *d = &vring->va[i].tx;
72 if ((i % 64) == 0 && (i != 0))
74 seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
75 _s : (vring->ctx[i].skb ? _h : 'h'));
82 static int wil_vring_debugfs_show(struct seq_file *s, void *data)
85 struct wil6210_priv *wil = s->private;
87 wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_');
89 for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
90 struct vring *vring = &wil->vring_tx[i];
91 struct vring_tx_data *txdata = &wil->vring_tx_data[i];
94 int cid = wil->vring2cid_tid[i][0];
95 int tid = wil->vring2cid_tid[i][1];
96 u32 swhead = vring->swhead;
97 u32 swtail = vring->swtail;
98 int used = (vring->size + swhead - swtail)
100 int avail = vring->size - used - 1;
102 /* performance monitoring */
103 cycles_t now = get_cycles();
104 cycles_t idle = txdata->idle * 100;
105 cycles_t total = now - txdata->begin;
111 snprintf(name, sizeof(name), "tx_%2d", i);
113 seq_printf(s, "\n%pM CID %d TID %d [%3d|%3d] idle %3d%%\n",
114 wil->sta[cid].addr, cid, tid, used, avail,
117 wil_print_vring(s, wil, name, vring, '_', 'H');
124 static int wil_vring_seq_open(struct inode *inode, struct file *file)
126 return single_open(file, wil_vring_debugfs_show, inode->i_private);
129 static const struct file_operations fops_vring = {
130 .open = wil_vring_seq_open,
131 .release = single_release,
136 static void wil_print_ring(struct seq_file *s, const char *prefix,
139 struct wil6210_priv *wil = s->private;
140 struct wil6210_mbox_ring r;
144 wil_memcpy_fromio_32(&r, off, sizeof(r));
145 wil_mbox_ring_le2cpus(&r);
147 * we just read memory block from NIC. This memory may be
148 * garbage. Check validity before using it.
150 rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
152 seq_printf(s, "ring %s = {\n", prefix);
153 seq_printf(s, " base = 0x%08x\n", r.base);
154 seq_printf(s, " size = 0x%04x bytes -> %d entries\n", r.size, rsize);
155 seq_printf(s, " tail = 0x%08x\n", r.tail);
156 seq_printf(s, " head = 0x%08x\n", r.head);
157 seq_printf(s, " entry size = %d\n", r.entry_size);
159 if (r.size % sizeof(struct wil6210_mbox_ring_desc)) {
160 seq_printf(s, " ??? size is not multiple of %zd, garbage?\n",
161 sizeof(struct wil6210_mbox_ring_desc));
165 if (!wmi_addr(wil, r.base) ||
166 !wmi_addr(wil, r.tail) ||
167 !wmi_addr(wil, r.head)) {
168 seq_puts(s, " ??? pointers are garbage?\n");
172 for (i = 0; i < rsize; i++) {
173 struct wil6210_mbox_ring_desc d;
174 struct wil6210_mbox_hdr hdr;
175 size_t delta = i * sizeof(d);
176 void __iomem *x = wil->csr + HOSTADDR(r.base) + delta;
178 wil_memcpy_fromio_32(&d, x, sizeof(d));
180 seq_printf(s, " [%2x] %s %s%s 0x%08x", i,
182 (r.tail - r.base == delta) ? "t" : " ",
183 (r.head - r.base == delta) ? "h" : " ",
184 le32_to_cpu(d.addr));
185 if (0 == wmi_read_hdr(wil, d.addr, &hdr)) {
186 u16 len = le16_to_cpu(hdr.len);
188 seq_printf(s, " -> %04x %04x %04x %02x\n",
189 le16_to_cpu(hdr.seq), len,
190 le16_to_cpu(hdr.type), hdr.flags);
191 if (len <= MAX_MBOXITEM_SIZE) {
193 char printbuf[16 * 3 + 2];
194 unsigned char databuf[MAX_MBOXITEM_SIZE];
195 void __iomem *src = wmi_buffer(wil, d.addr) +
196 sizeof(struct wil6210_mbox_hdr);
198 * No need to check @src for validity -
199 * we already validated @d.addr while
202 wil_memcpy_fromio_32(databuf, src, len);
204 int l = min(len - n, 16);
206 hex_dump_to_buffer(databuf + n, l,
210 seq_printf(s, " : %s\n", printbuf);
222 static int wil_mbox_debugfs_show(struct seq_file *s, void *data)
224 struct wil6210_priv *wil = s->private;
226 wil_print_ring(s, "tx", wil->csr + HOST_MBOX +
227 offsetof(struct wil6210_mbox_ctl, tx));
228 wil_print_ring(s, "rx", wil->csr + HOST_MBOX +
229 offsetof(struct wil6210_mbox_ctl, rx));
234 static int wil_mbox_seq_open(struct inode *inode, struct file *file)
236 return single_open(file, wil_mbox_debugfs_show, inode->i_private);
239 static const struct file_operations fops_mbox = {
240 .open = wil_mbox_seq_open,
241 .release = single_release,
246 static int wil_debugfs_iomem_x32_set(void *data, u64 val)
248 iowrite32(val, (void __iomem *)data);
249 wmb(); /* make sure write propagated to HW */
254 static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
256 *val = ioread32((void __iomem *)data);
261 DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
262 wil_debugfs_iomem_x32_set, "0x%08llx\n");
264 static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
266 struct dentry *parent,
269 return debugfs_create_file(name, mode, parent, value,
273 static int wil_debugfs_ulong_set(void *data, u64 val)
275 *(ulong *)data = val;
279 static int wil_debugfs_ulong_get(void *data, u64 *val)
281 *val = *(ulong *)data;
285 DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
286 wil_debugfs_ulong_set, "%llu\n");
288 static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode,
289 struct dentry *parent,
292 return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong);
296 * wil6210_debugfs_init_offset - create set of debugfs files
297 * @wil - driver's context, used for printing
298 * @dbg - directory on the debugfs, where files will be created
299 * @base - base address used in address calculation
300 * @tbl - table with file descriptions. Should be terminated with empty element.
302 * Creates files accordingly to the @tbl.
304 static void wil6210_debugfs_init_offset(struct wil6210_priv *wil,
305 struct dentry *dbg, void *base,
306 const struct dbg_off * const tbl)
310 for (i = 0; tbl[i].name; i++) {
313 switch (tbl[i].type) {
315 f = debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg,
319 f = debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg,
323 f = wil_debugfs_create_ulong(tbl[i].name, tbl[i].mode,
324 dbg, base + tbl[i].off);
327 f = wil_debugfs_create_iomem_x32(tbl[i].name,
332 f = ERR_PTR(-EINVAL);
334 if (IS_ERR_OR_NULL(f))
335 wil_err(wil, "Create file \"%s\": err %ld\n",
336 tbl[i].name, PTR_ERR(f));
340 static const struct dbg_off isr_off[] = {
341 {"ICC", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICC), doff_io32},
342 {"ICR", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICR), doff_io32},
343 {"ICM", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICM), doff_io32},
344 {"ICS", S_IWUSR, offsetof(struct RGF_ICR, ICS), doff_io32},
345 {"IMV", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, IMV), doff_io32},
346 {"IMS", S_IWUSR, offsetof(struct RGF_ICR, IMS), doff_io32},
347 {"IMC", S_IWUSR, offsetof(struct RGF_ICR, IMC), doff_io32},
351 static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
353 struct dentry *parent, u32 off)
355 struct dentry *d = debugfs_create_dir(name, parent);
357 if (IS_ERR_OR_NULL(d))
360 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off,
366 static const struct dbg_off pseudo_isr_off[] = {
367 {"CAUSE", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32},
368 {"MASK_SW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32},
369 {"MASK_FW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32},
373 static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
374 struct dentry *parent)
376 struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
378 if (IS_ERR_OR_NULL(d))
381 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
387 static const struct dbg_off itr_cnt_off[] = {
388 {"TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32},
389 {"DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32},
390 {"CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32},
394 static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
395 struct dentry *parent)
397 struct dentry *d = debugfs_create_dir("ITR_CNT", parent);
399 if (IS_ERR_OR_NULL(d))
402 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
408 static int wil_memread_debugfs_show(struct seq_file *s, void *data)
410 struct wil6210_priv *wil = s->private;
411 void __iomem *a = wmi_buffer(wil, cpu_to_le32(mem_addr));
414 seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, ioread32(a));
416 seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
421 static int wil_memread_seq_open(struct inode *inode, struct file *file)
423 return single_open(file, wil_memread_debugfs_show, inode->i_private);
426 static const struct file_operations fops_memread = {
427 .open = wil_memread_seq_open,
428 .release = single_release,
433 static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
434 size_t count, loff_t *ppos)
436 enum { max_count = 4096 };
437 struct debugfs_blob_wrapper *blob = file->private_data;
439 size_t available = blob->size;
446 if (pos >= available || !count)
449 if (count > available - pos)
450 count = available - pos;
451 if (count > max_count)
454 buf = kmalloc(count, GFP_KERNEL);
458 wil_memcpy_fromio_32(buf, (const volatile void __iomem *)blob->data +
461 ret = copy_to_user(user_buf, buf, count);
472 static const struct file_operations fops_ioblob = {
473 .read = wil_read_file_ioblob,
475 .llseek = default_llseek,
479 struct dentry *wil_debugfs_create_ioblob(const char *name,
481 struct dentry *parent,
482 struct debugfs_blob_wrapper *blob)
484 return debugfs_create_file(name, mode, parent, blob, &fops_ioblob);
488 static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
489 size_t len, loff_t *ppos)
491 struct wil6210_priv *wil = file->private_data;
492 struct net_device *ndev = wil_to_ndev(wil);
496 * this code does NOT sync device state with the rest of system
497 * use with care, debug only!!!
501 ndev->flags &= ~IFF_UP;
508 static const struct file_operations fops_reset = {
509 .write = wil_write_file_reset,
513 /*---write channel 1..4 to rxon for it, 0 to rxoff---*/
514 static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
515 size_t len, loff_t *ppos)
517 struct wil6210_priv *wil = file->private_data;
522 char *kbuf = kmalloc(len + 1, GFP_KERNEL);
526 if (copy_from_user(kbuf, buf, len)) {
532 rc = kstrtol(kbuf, 0, &channel);
537 if ((channel < 0) || (channel > 4)) {
538 wil_err(wil, "Invalid channel %ld\n", channel);
544 rc = wmi_set_channel(wil, (int)channel);
549 rc = wmi_rxon(wil, on);
556 static const struct file_operations fops_rxon = {
557 .write = wil_write_file_rxon,
562 /* Write mgmt frame to this file to send it */
563 static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
564 size_t len, loff_t *ppos)
566 struct wil6210_priv *wil = file->private_data;
567 struct wiphy *wiphy = wil_to_wiphy(wil);
568 struct wireless_dev *wdev = wil_to_wdev(wil);
569 struct cfg80211_mgmt_tx_params params;
571 void *frame = kmalloc(len, GFP_KERNEL);
576 if (copy_from_user(frame, buf, len)) {
583 params.chan = wdev->preset_chandef.chan;
585 rc = wil_cfg80211_mgmt_tx(wiphy, wdev, ¶ms, NULL);
588 wil_info(wil, "%s() -> %d\n", __func__, rc);
593 static const struct file_operations fops_txmgmt = {
594 .write = wil_write_file_txmgmt,
598 /* Write WMI command (w/o mbox header) to this file to send it
599 * WMI starts from wil6210_mbox_hdr_wmi header
601 static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
602 size_t len, loff_t *ppos)
604 struct wil6210_priv *wil = file->private_data;
605 struct wil6210_mbox_hdr_wmi *wmi;
607 int cmdlen = len - sizeof(struct wil6210_mbox_hdr_wmi);
614 wmi = kmalloc(len, GFP_KERNEL);
618 rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
625 cmdid = le16_to_cpu(wmi->id);
627 rc1 = wmi_send(wil, cmdid, cmd, cmdlen);
630 wil_info(wil, "%s(0x%04x[%d]) -> %d\n", __func__, cmdid, cmdlen, rc1);
635 static const struct file_operations fops_wmi = {
636 .write = wil_write_file_wmi,
640 static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
643 char printbuf[16 * 3 + 2];
647 int l = min(len - i, 16);
649 hex_dump_to_buffer(p + i, l, 16, 1, printbuf,
650 sizeof(printbuf), false);
651 seq_printf(s, "%s%s\n", prefix, printbuf);
656 static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
659 int len = skb_headlen(skb);
661 int nr_frags = skb_shinfo(skb)->nr_frags;
663 seq_printf(s, " len = %d\n", len);
664 wil_seq_hexdump(s, p, len, " : ");
667 seq_printf(s, " nr_frags = %d\n", nr_frags);
668 for (i = 0; i < nr_frags; i++) {
669 const struct skb_frag_struct *frag =
670 &skb_shinfo(skb)->frags[i];
672 len = skb_frag_size(frag);
673 p = skb_frag_address_safe(frag);
674 seq_printf(s, " [%2d] : len = %d\n", i, len);
675 wil_seq_hexdump(s, p, len, " : ");
680 /*---------Tx/Rx descriptor------------*/
681 static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
683 struct wil6210_priv *wil = s->private;
685 bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS);
687 vring = tx ? &wil->vring_tx[dbg_vring_index] : &wil->vring_rx;
691 seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index);
693 seq_puts(s, "No Rx VRING\n");
697 if (dbg_txdesc_index < vring->size) {
698 /* use struct vring_tx_desc for Rx as well,
699 * only field used, .dma.length, is the same
701 volatile struct vring_tx_desc *d =
702 &vring->va[dbg_txdesc_index].tx;
703 volatile u32 *u = (volatile u32 *)d;
704 struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb;
707 seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index,
710 seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
711 seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
712 u[0], u[1], u[2], u[3]);
713 seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
714 u[4], u[5], u[6], u[7]);
715 seq_printf(s, " SKB = 0x%p\n", skb);
719 wil_seq_print_skb(s, skb);
725 seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
726 dbg_vring_index, dbg_txdesc_index,
729 seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
730 dbg_txdesc_index, vring->size);
736 static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
738 return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
741 static const struct file_operations fops_txdesc = {
742 .open = wil_txdesc_seq_open,
743 .release = single_release,
748 /*---------beamforming------------*/
749 static char *wil_bfstatus_str(u32 status)
763 static bool is_all_zeros(void * const x_, size_t sz)
765 /* if reply is all-0, ignore this CID */
769 for (n = 0; n < sz / sizeof(*x); n++)
776 static int wil_bf_debugfs_show(struct seq_file *s, void *data)
780 struct wil6210_priv *wil = s->private;
781 struct wmi_notify_req_cmd cmd = {
785 struct wil6210_mbox_hdr_wmi wmi;
786 struct wmi_notify_req_done_event evt;
789 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
793 rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd),
794 WMI_NOTIFY_REQ_DONE_EVENTID, &reply,
796 /* if reply is all-0, ignore this CID */
797 if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt)))
800 status = le32_to_cpu(reply.evt.status);
801 seq_printf(s, "CID %d {\n"
803 " TxMCS = %2d TxTpt = %4d\n"
805 " Status = 0x%08x %s\n"
806 " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
807 " Goodput(rx:tx) %4d:%4d\n"
810 le64_to_cpu(reply.evt.tsf),
811 le16_to_cpu(reply.evt.bf_mcs),
812 le32_to_cpu(reply.evt.tx_tpt),
814 status, wil_bfstatus_str(status),
815 le16_to_cpu(reply.evt.my_rx_sector),
816 le16_to_cpu(reply.evt.my_tx_sector),
817 le16_to_cpu(reply.evt.other_rx_sector),
818 le16_to_cpu(reply.evt.other_tx_sector),
819 le32_to_cpu(reply.evt.rx_goodput),
820 le32_to_cpu(reply.evt.tx_goodput));
825 static int wil_bf_seq_open(struct inode *inode, struct file *file)
827 return single_open(file, wil_bf_debugfs_show, inode->i_private);
830 static const struct file_operations fops_bf = {
831 .open = wil_bf_seq_open,
832 .release = single_release,
837 /*---------SSID------------*/
838 static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf,
839 size_t count, loff_t *ppos)
841 struct wil6210_priv *wil = file->private_data;
842 struct wireless_dev *wdev = wil_to_wdev(wil);
844 return simple_read_from_buffer(user_buf, count, ppos,
845 wdev->ssid, wdev->ssid_len);
848 static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf,
849 size_t count, loff_t *ppos)
851 struct wil6210_priv *wil = file->private_data;
852 struct wireless_dev *wdev = wil_to_wdev(wil);
853 struct net_device *ndev = wil_to_ndev(wil);
856 wil_err(wil, "Unable to set SSID substring from [%d]\n",
861 if (count > sizeof(wdev->ssid)) {
862 wil_err(wil, "SSID too long, len = %d\n", (int)count);
865 if (netif_running(ndev)) {
866 wil_err(wil, "Unable to change SSID on running interface\n");
870 wdev->ssid_len = count;
871 return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos,
875 static const struct file_operations fops_ssid = {
876 .read = wil_read_file_ssid,
877 .write = wil_write_file_ssid,
881 /*---------temp------------*/
882 static void print_temp(struct seq_file *s, const char *prefix, u32 t)
887 seq_printf(s, "%s N/A\n", prefix);
890 seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
895 static int wil_temp_debugfs_show(struct seq_file *s, void *data)
897 struct wil6210_priv *wil = s->private;
899 int rc = wmi_get_temperature(wil, &t_m, &t_r);
902 seq_puts(s, "Failed\n");
906 print_temp(s, "T_mac =", t_m);
907 print_temp(s, "T_radio =", t_r);
912 static int wil_temp_seq_open(struct inode *inode, struct file *file)
914 return single_open(file, wil_temp_debugfs_show, inode->i_private);
917 static const struct file_operations fops_temp = {
918 .open = wil_temp_seq_open,
919 .release = single_release,
924 /*---------freq------------*/
925 static int wil_freq_debugfs_show(struct seq_file *s, void *data)
927 struct wil6210_priv *wil = s->private;
928 struct wireless_dev *wdev = wil_to_wdev(wil);
929 u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
931 seq_printf(s, "Freq = %d\n", freq);
936 static int wil_freq_seq_open(struct inode *inode, struct file *file)
938 return single_open(file, wil_freq_debugfs_show, inode->i_private);
941 static const struct file_operations fops_freq = {
942 .open = wil_freq_seq_open,
943 .release = single_release,
948 /*---------link------------*/
949 static int wil_link_debugfs_show(struct seq_file *s, void *data)
951 struct wil6210_priv *wil = s->private;
952 struct station_info sinfo;
955 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
956 struct wil_sta_info *p = &wil->sta[i];
957 char *status = "unknown";
963 case wil_sta_conn_pending:
966 case wil_sta_connected:
967 status = "connected";
970 seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
971 (p->data_port_open ? " data_port_open" : ""));
973 if (p->status == wil_sta_connected) {
974 rc = wil_cid_fill_sinfo(wil, i, &sinfo);
978 seq_printf(s, " Tx_mcs = %d\n", sinfo.txrate.mcs);
979 seq_printf(s, " Rx_mcs = %d\n", sinfo.rxrate.mcs);
980 seq_printf(s, " SQ = %d\n", sinfo.signal);
987 static int wil_link_seq_open(struct inode *inode, struct file *file)
989 return single_open(file, wil_link_debugfs_show, inode->i_private);
992 static const struct file_operations fops_link = {
993 .open = wil_link_seq_open,
994 .release = single_release,
999 /*---------info------------*/
1000 static int wil_info_debugfs_show(struct seq_file *s, void *data)
1002 struct wil6210_priv *wil = s->private;
1003 struct net_device *ndev = wil_to_ndev(wil);
1004 int is_ac = power_supply_is_system_supplied();
1005 int rx = atomic_xchg(&wil->isr_count_rx, 0);
1006 int tx = atomic_xchg(&wil->isr_count_tx, 0);
1007 static ulong rxf_old, txf_old;
1008 ulong rxf = ndev->stats.rx_packets;
1009 ulong txf = ndev->stats.tx_packets;
1012 /* >0 : AC; 0 : battery; <0 : error */
1013 seq_printf(s, "AC powered : %d\n", is_ac);
1014 seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
1015 seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
1019 #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
1020 " " __stringify(x) : ""
1022 for (i = 0; i < ndev->num_tx_queues; i++) {
1023 struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
1024 unsigned long state = txq->state;
1026 seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
1027 CHECK_QSTATE(DRV_XOFF),
1028 CHECK_QSTATE(STACK_XOFF),
1029 CHECK_QSTATE(FROZEN)
1036 static int wil_info_seq_open(struct inode *inode, struct file *file)
1038 return single_open(file, wil_info_debugfs_show, inode->i_private);
1041 static const struct file_operations fops_info = {
1042 .open = wil_info_seq_open,
1043 .release = single_release,
1045 .llseek = seq_lseek,
1048 /*---------recovery------------*/
1049 /* mode = [manual|auto]
1050 * state = [idle|pending|running]
1052 static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf,
1053 size_t count, loff_t *ppos)
1055 struct wil6210_priv *wil = file->private_data;
1058 static const char * const sstate[] = {"idle", "pending", "running"};
1060 n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n",
1061 no_fw_recovery ? "manual" : "auto",
1062 sstate[wil->recovery_state]);
1064 n = min_t(int, n, sizeof(buf));
1066 return simple_read_from_buffer(user_buf, count, ppos,
1070 static ssize_t wil_write_file_recovery(struct file *file,
1071 const char __user *buf_,
1072 size_t count, loff_t *ppos)
1074 struct wil6210_priv *wil = file->private_data;
1075 static const char run_command[] = "run";
1076 char buf[sizeof(run_command) + 1]; /* to detect "runx" */
1079 if (wil->recovery_state != fw_recovery_pending) {
1080 wil_err(wil, "No recovery pending\n");
1085 wil_err(wil, "Offset [%d]\n", (int)*ppos);
1089 if (count > sizeof(buf)) {
1090 wil_err(wil, "Input too long, len = %d\n", (int)count);
1094 rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count);
1099 if (0 == strcmp(buf, run_command))
1100 wil_set_recovery_state(wil, fw_recovery_running);
1102 wil_err(wil, "Bad recovery command \"%s\"\n", buf);
1107 static const struct file_operations fops_recovery = {
1108 .read = wil_read_file_recovery,
1109 .write = wil_write_file_recovery,
1110 .open = simple_open,
1113 /*---------Station matrix------------*/
1114 static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
1117 u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
1119 seq_printf(s, "0x%03x [", r->head_seq_num);
1120 for (i = 0; i < r->buf_size; i++) {
1122 seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
1124 seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
1126 seq_printf(s, "] last drop 0x%03x\n", r->ssn_last_drop);
1129 static int wil_sta_debugfs_show(struct seq_file *s, void *data)
1131 struct wil6210_priv *wil = s->private;
1133 unsigned long flags;
1135 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1136 struct wil_sta_info *p = &wil->sta[i];
1137 char *status = "unknown";
1139 switch (p->status) {
1140 case wil_sta_unused:
1143 case wil_sta_conn_pending:
1144 status = "pending ";
1146 case wil_sta_connected:
1147 status = "connected";
1150 seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
1151 (p->data_port_open ? " data_port_open" : ""));
1153 if (p->status == wil_sta_connected) {
1154 spin_lock_irqsave(&p->tid_rx_lock, flags);
1155 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1156 struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
1159 seq_printf(s, "[%2d] ", tid);
1160 wil_print_rxtid(s, r);
1163 spin_unlock_irqrestore(&p->tid_rx_lock, flags);
1170 static int wil_sta_seq_open(struct inode *inode, struct file *file)
1172 return single_open(file, wil_sta_debugfs_show, inode->i_private);
1175 static const struct file_operations fops_sta = {
1176 .open = wil_sta_seq_open,
1177 .release = single_release,
1179 .llseek = seq_lseek,
1182 /*----------------*/
1183 static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
1189 for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
1190 struct debugfs_blob_wrapper *blob = &wil->blobs[i];
1191 const struct fw_map *map = &fw_mapping[i];
1196 blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
1197 blob->size = map->to - map->from;
1198 snprintf(name, sizeof(name), "blob_%s", map->name);
1199 wil_debugfs_create_ioblob(name, S_IRUGO, dbg, blob);
1204 static const struct {
1207 const struct file_operations *fops;
1209 {"mbox", S_IRUGO, &fops_mbox},
1210 {"vrings", S_IRUGO, &fops_vring},
1211 {"stations", S_IRUGO, &fops_sta},
1212 {"desc", S_IRUGO, &fops_txdesc},
1213 {"bf", S_IRUGO, &fops_bf},
1214 {"ssid", S_IRUGO | S_IWUSR, &fops_ssid},
1215 {"mem_val", S_IRUGO, &fops_memread},
1216 {"reset", S_IWUSR, &fops_reset},
1217 {"rxon", S_IWUSR, &fops_rxon},
1218 {"tx_mgmt", S_IWUSR, &fops_txmgmt},
1219 {"wmi_send", S_IWUSR, &fops_wmi},
1220 {"temp", S_IRUGO, &fops_temp},
1221 {"freq", S_IRUGO, &fops_freq},
1222 {"link", S_IRUGO, &fops_link},
1223 {"info", S_IRUGO, &fops_info},
1224 {"recovery", S_IRUGO | S_IWUSR, &fops_recovery},
1227 static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
1232 for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
1233 debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
1234 wil, dbg_files[i].fops);
1237 /* interrupt control blocks */
1238 static const struct {
1242 {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)},
1243 {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)},
1244 {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)},
1245 {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)},
1248 static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
1253 for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
1254 wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
1255 dbg_icr[i].icr_off);
1258 #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
1259 offsetof(struct wil6210_priv, name), type}
1261 /* fields in struct wil6210_priv */
1262 static const struct dbg_off dbg_wil_off[] = {
1263 WIL_FIELD(secure_pcp, S_IRUGO | S_IWUSR, doff_u32),
1264 WIL_FIELD(status, S_IRUGO | S_IWUSR, doff_ulong),
1265 WIL_FIELD(fw_version, S_IRUGO, doff_u32),
1266 WIL_FIELD(hw_version, S_IRUGO, doff_x32),
1267 WIL_FIELD(recovery_count, S_IRUGO, doff_u32),
1271 static const struct dbg_off dbg_wil_regs[] = {
1272 {"RGF_MAC_MTRL_COUNTER_0", S_IRUGO, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
1274 {"RGF_USER_USAGE_1", S_IRUGO, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
1278 /* static parameters */
1279 static const struct dbg_off dbg_statics[] = {
1280 {"desc_index", S_IRUGO | S_IWUSR, (ulong)&dbg_txdesc_index, doff_u32},
1281 {"vring_index", S_IRUGO | S_IWUSR, (ulong)&dbg_vring_index, doff_u32},
1282 {"mem_addr", S_IRUGO | S_IWUSR, (ulong)&mem_addr, doff_u32},
1286 int wil6210_debugfs_init(struct wil6210_priv *wil)
1288 struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
1289 wil_to_wiphy(wil)->debugfsdir);
1291 if (IS_ERR_OR_NULL(dbg))
1294 wil6210_debugfs_init_files(wil, dbg);
1295 wil6210_debugfs_init_isr(wil, dbg);
1296 wil6210_debugfs_init_blobs(wil, dbg);
1297 wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
1298 wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
1300 wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
1302 wil6210_debugfs_create_pseudo_ISR(wil, dbg);
1304 wil6210_debugfs_create_ITR_CNT(wil, dbg);
1309 void wil6210_debugfs_remove(struct wil6210_priv *wil)
1311 debugfs_remove_recursive(wil->debug);