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);
55 seq_printf(s, "VRING %s = {\n", name);
56 seq_printf(s, " pa = %pad\n", &vring->pa);
57 seq_printf(s, " va = 0x%p\n", vring->va);
58 seq_printf(s, " size = %d\n", vring->size);
59 seq_printf(s, " swtail = %d\n", vring->swtail);
60 seq_printf(s, " swhead = %d\n", vring->swhead);
61 seq_printf(s, " hwtail = [0x%08x] -> ", vring->hwtail);
64 seq_printf(s, "0x%08x = %d\n", v, v);
69 if (vring->va && (vring->size < 1025)) {
72 for (i = 0; i < vring->size; i++) {
73 volatile struct vring_tx_desc *d = &vring->va[i].tx;
75 if ((i % 64) == 0 && (i != 0))
77 seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
78 _s : (vring->ctx[i].skb ? _h : 'h'));
85 static int wil_vring_debugfs_show(struct seq_file *s, void *data)
88 struct wil6210_priv *wil = s->private;
90 wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_');
92 for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
93 struct vring *vring = &wil->vring_tx[i];
94 struct vring_tx_data *txdata = &wil->vring_tx_data[i];
97 int cid = wil->vring2cid_tid[i][0];
98 int tid = wil->vring2cid_tid[i][1];
99 u32 swhead = vring->swhead;
100 u32 swtail = vring->swtail;
101 int used = (vring->size + swhead - swtail)
103 int avail = vring->size - used - 1;
105 /* performance monitoring */
106 cycles_t now = get_cycles();
107 uint64_t idle = txdata->idle * 100;
108 uint64_t total = now - txdata->begin;
114 snprintf(name, sizeof(name), "tx_%2d", i);
117 "\n%pM CID %d TID %d BACK([%d] %d TU) [%3d|%3d] idle %3d%%\n",
118 wil->sta[cid].addr, cid, tid,
119 txdata->agg_wsize, txdata->agg_timeout,
120 used, avail, (int)idle);
122 wil_print_vring(s, wil, name, vring, '_', 'H');
129 static int wil_vring_seq_open(struct inode *inode, struct file *file)
131 return single_open(file, wil_vring_debugfs_show, inode->i_private);
134 static const struct file_operations fops_vring = {
135 .open = wil_vring_seq_open,
136 .release = single_release,
141 static void wil_print_ring(struct seq_file *s, const char *prefix,
144 struct wil6210_priv *wil = s->private;
145 struct wil6210_mbox_ring r;
149 wil_memcpy_fromio_32(&r, off, sizeof(r));
150 wil_mbox_ring_le2cpus(&r);
152 * we just read memory block from NIC. This memory may be
153 * garbage. Check validity before using it.
155 rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
157 seq_printf(s, "ring %s = {\n", prefix);
158 seq_printf(s, " base = 0x%08x\n", r.base);
159 seq_printf(s, " size = 0x%04x bytes -> %d entries\n", r.size, rsize);
160 seq_printf(s, " tail = 0x%08x\n", r.tail);
161 seq_printf(s, " head = 0x%08x\n", r.head);
162 seq_printf(s, " entry size = %d\n", r.entry_size);
164 if (r.size % sizeof(struct wil6210_mbox_ring_desc)) {
165 seq_printf(s, " ??? size is not multiple of %zd, garbage?\n",
166 sizeof(struct wil6210_mbox_ring_desc));
170 if (!wmi_addr(wil, r.base) ||
171 !wmi_addr(wil, r.tail) ||
172 !wmi_addr(wil, r.head)) {
173 seq_puts(s, " ??? pointers are garbage?\n");
177 for (i = 0; i < rsize; i++) {
178 struct wil6210_mbox_ring_desc d;
179 struct wil6210_mbox_hdr hdr;
180 size_t delta = i * sizeof(d);
181 void __iomem *x = wil->csr + HOSTADDR(r.base) + delta;
183 wil_memcpy_fromio_32(&d, x, sizeof(d));
185 seq_printf(s, " [%2x] %s %s%s 0x%08x", i,
187 (r.tail - r.base == delta) ? "t" : " ",
188 (r.head - r.base == delta) ? "h" : " ",
189 le32_to_cpu(d.addr));
190 if (0 == wmi_read_hdr(wil, d.addr, &hdr)) {
191 u16 len = le16_to_cpu(hdr.len);
193 seq_printf(s, " -> %04x %04x %04x %02x\n",
194 le16_to_cpu(hdr.seq), len,
195 le16_to_cpu(hdr.type), hdr.flags);
196 if (len <= MAX_MBOXITEM_SIZE) {
198 char printbuf[16 * 3 + 2];
199 unsigned char databuf[MAX_MBOXITEM_SIZE];
200 void __iomem *src = wmi_buffer(wil, d.addr) +
201 sizeof(struct wil6210_mbox_hdr);
203 * No need to check @src for validity -
204 * we already validated @d.addr while
207 wil_memcpy_fromio_32(databuf, src, len);
209 int l = min(len - n, 16);
211 hex_dump_to_buffer(databuf + n, l,
215 seq_printf(s, " : %s\n", printbuf);
227 static int wil_mbox_debugfs_show(struct seq_file *s, void *data)
229 struct wil6210_priv *wil = s->private;
231 wil_print_ring(s, "tx", wil->csr + HOST_MBOX +
232 offsetof(struct wil6210_mbox_ctl, tx));
233 wil_print_ring(s, "rx", wil->csr + HOST_MBOX +
234 offsetof(struct wil6210_mbox_ctl, rx));
239 static int wil_mbox_seq_open(struct inode *inode, struct file *file)
241 return single_open(file, wil_mbox_debugfs_show, inode->i_private);
244 static const struct file_operations fops_mbox = {
245 .open = wil_mbox_seq_open,
246 .release = single_release,
251 static int wil_debugfs_iomem_x32_set(void *data, u64 val)
253 iowrite32(val, (void __iomem *)data);
254 wmb(); /* make sure write propagated to HW */
259 static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
261 *val = ioread32((void __iomem *)data);
266 DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
267 wil_debugfs_iomem_x32_set, "0x%08llx\n");
269 static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
271 struct dentry *parent,
274 return debugfs_create_file(name, mode, parent, value,
278 static int wil_debugfs_ulong_set(void *data, u64 val)
280 *(ulong *)data = val;
284 static int wil_debugfs_ulong_get(void *data, u64 *val)
286 *val = *(ulong *)data;
290 DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
291 wil_debugfs_ulong_set, "%llu\n");
293 static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode,
294 struct dentry *parent,
297 return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong);
301 * wil6210_debugfs_init_offset - create set of debugfs files
302 * @wil - driver's context, used for printing
303 * @dbg - directory on the debugfs, where files will be created
304 * @base - base address used in address calculation
305 * @tbl - table with file descriptions. Should be terminated with empty element.
307 * Creates files accordingly to the @tbl.
309 static void wil6210_debugfs_init_offset(struct wil6210_priv *wil,
310 struct dentry *dbg, void *base,
311 const struct dbg_off * const tbl)
315 for (i = 0; tbl[i].name; i++) {
318 switch (tbl[i].type) {
320 f = debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg,
324 f = debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg,
328 f = wil_debugfs_create_ulong(tbl[i].name, tbl[i].mode,
329 dbg, base + tbl[i].off);
332 f = wil_debugfs_create_iomem_x32(tbl[i].name,
337 f = ERR_PTR(-EINVAL);
339 if (IS_ERR_OR_NULL(f))
340 wil_err(wil, "Create file \"%s\": err %ld\n",
341 tbl[i].name, PTR_ERR(f));
345 static const struct dbg_off isr_off[] = {
346 {"ICC", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICC), doff_io32},
347 {"ICR", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICR), doff_io32},
348 {"ICM", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICM), doff_io32},
349 {"ICS", S_IWUSR, offsetof(struct RGF_ICR, ICS), doff_io32},
350 {"IMV", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, IMV), doff_io32},
351 {"IMS", S_IWUSR, offsetof(struct RGF_ICR, IMS), doff_io32},
352 {"IMC", S_IWUSR, offsetof(struct RGF_ICR, IMC), doff_io32},
356 static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
358 struct dentry *parent, u32 off)
360 struct dentry *d = debugfs_create_dir(name, parent);
362 if (IS_ERR_OR_NULL(d))
365 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off,
371 static const struct dbg_off pseudo_isr_off[] = {
372 {"CAUSE", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32},
373 {"MASK_SW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32},
374 {"MASK_FW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32},
378 static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
379 struct dentry *parent)
381 struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
383 if (IS_ERR_OR_NULL(d))
386 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
392 static const struct dbg_off itr_cnt_off[] = {
393 {"TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32},
394 {"DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32},
395 {"CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32},
399 static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
400 struct dentry *parent)
402 struct dentry *d = debugfs_create_dir("ITR_CNT", parent);
404 if (IS_ERR_OR_NULL(d))
407 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
413 static int wil_memread_debugfs_show(struct seq_file *s, void *data)
415 struct wil6210_priv *wil = s->private;
416 void __iomem *a = wmi_buffer(wil, cpu_to_le32(mem_addr));
419 seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, ioread32(a));
421 seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
426 static int wil_memread_seq_open(struct inode *inode, struct file *file)
428 return single_open(file, wil_memread_debugfs_show, inode->i_private);
431 static const struct file_operations fops_memread = {
432 .open = wil_memread_seq_open,
433 .release = single_release,
438 static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
439 size_t count, loff_t *ppos)
441 enum { max_count = 4096 };
442 struct debugfs_blob_wrapper *blob = file->private_data;
444 size_t available = blob->size;
451 if (pos >= available || !count)
454 if (count > available - pos)
455 count = available - pos;
456 if (count > max_count)
459 buf = kmalloc(count, GFP_KERNEL);
463 wil_memcpy_fromio_32(buf, (const volatile void __iomem *)blob->data +
466 ret = copy_to_user(user_buf, buf, count);
477 static const struct file_operations fops_ioblob = {
478 .read = wil_read_file_ioblob,
480 .llseek = default_llseek,
484 struct dentry *wil_debugfs_create_ioblob(const char *name,
486 struct dentry *parent,
487 struct debugfs_blob_wrapper *blob)
489 return debugfs_create_file(name, mode, parent, blob, &fops_ioblob);
493 static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
494 size_t len, loff_t *ppos)
496 struct wil6210_priv *wil = file->private_data;
497 struct net_device *ndev = wil_to_ndev(wil);
501 * this code does NOT sync device state with the rest of system
502 * use with care, debug only!!!
506 ndev->flags &= ~IFF_UP;
513 static const struct file_operations fops_reset = {
514 .write = wil_write_file_reset,
518 /*---write channel 1..4 to rxon for it, 0 to rxoff---*/
519 static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
520 size_t len, loff_t *ppos)
522 struct wil6210_priv *wil = file->private_data;
527 char *kbuf = kmalloc(len + 1, GFP_KERNEL);
531 if (copy_from_user(kbuf, buf, len)) {
537 rc = kstrtol(kbuf, 0, &channel);
542 if ((channel < 0) || (channel > 4)) {
543 wil_err(wil, "Invalid channel %ld\n", channel);
549 rc = wmi_set_channel(wil, (int)channel);
554 rc = wmi_rxon(wil, on);
561 static const struct file_operations fops_rxon = {
562 .write = wil_write_file_rxon,
566 /* block ack for vring 0
567 * write 0 to it to trigger DELBA
568 * write positive agg_wsize to trigger ADDBA
570 static ssize_t wil_write_addba(struct file *file, const char __user *buf,
571 size_t len, loff_t *ppos)
573 struct wil6210_priv *wil = file->private_data;
576 char *kbuf = kmalloc(len + 1, GFP_KERNEL);
581 rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
584 return rc >= 0 ? -EIO : rc;
588 rc = kstrtouint(kbuf, 0, &agg_wsize);
594 if (!wil->vring_tx[0].va)
598 wmi_addba(wil, 0, agg_wsize, 0);
600 wmi_delba(wil, 0, 0);
605 static const struct file_operations fops_addba = {
606 .write = wil_write_addba,
611 /* Write mgmt frame to this file to send it */
612 static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
613 size_t len, loff_t *ppos)
615 struct wil6210_priv *wil = file->private_data;
616 struct wiphy *wiphy = wil_to_wiphy(wil);
617 struct wireless_dev *wdev = wil_to_wdev(wil);
618 struct cfg80211_mgmt_tx_params params;
620 void *frame = kmalloc(len, GFP_KERNEL);
625 if (copy_from_user(frame, buf, len)) {
632 params.chan = wdev->preset_chandef.chan;
634 rc = wil_cfg80211_mgmt_tx(wiphy, wdev, ¶ms, NULL);
637 wil_info(wil, "%s() -> %d\n", __func__, rc);
642 static const struct file_operations fops_txmgmt = {
643 .write = wil_write_file_txmgmt,
647 /* Write WMI command (w/o mbox header) to this file to send it
648 * WMI starts from wil6210_mbox_hdr_wmi header
650 static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
651 size_t len, loff_t *ppos)
653 struct wil6210_priv *wil = file->private_data;
654 struct wil6210_mbox_hdr_wmi *wmi;
656 int cmdlen = len - sizeof(struct wil6210_mbox_hdr_wmi);
663 wmi = kmalloc(len, GFP_KERNEL);
667 rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
674 cmdid = le16_to_cpu(wmi->id);
676 rc1 = wmi_send(wil, cmdid, cmd, cmdlen);
679 wil_info(wil, "%s(0x%04x[%d]) -> %d\n", __func__, cmdid, cmdlen, rc1);
684 static const struct file_operations fops_wmi = {
685 .write = wil_write_file_wmi,
689 static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
692 char printbuf[16 * 3 + 2];
696 int l = min(len - i, 16);
698 hex_dump_to_buffer(p + i, l, 16, 1, printbuf,
699 sizeof(printbuf), false);
700 seq_printf(s, "%s%s\n", prefix, printbuf);
705 static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
708 int len = skb_headlen(skb);
710 int nr_frags = skb_shinfo(skb)->nr_frags;
712 seq_printf(s, " len = %d\n", len);
713 wil_seq_hexdump(s, p, len, " : ");
716 seq_printf(s, " nr_frags = %d\n", nr_frags);
717 for (i = 0; i < nr_frags; i++) {
718 const struct skb_frag_struct *frag =
719 &skb_shinfo(skb)->frags[i];
721 len = skb_frag_size(frag);
722 p = skb_frag_address_safe(frag);
723 seq_printf(s, " [%2d] : len = %d\n", i, len);
724 wil_seq_hexdump(s, p, len, " : ");
729 /*---------Tx/Rx descriptor------------*/
730 static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
732 struct wil6210_priv *wil = s->private;
734 bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS);
736 vring = tx ? &wil->vring_tx[dbg_vring_index] : &wil->vring_rx;
740 seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index);
742 seq_puts(s, "No Rx VRING\n");
746 if (dbg_txdesc_index < vring->size) {
747 /* use struct vring_tx_desc for Rx as well,
748 * only field used, .dma.length, is the same
750 volatile struct vring_tx_desc *d =
751 &vring->va[dbg_txdesc_index].tx;
752 volatile u32 *u = (volatile u32 *)d;
753 struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb;
756 seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index,
759 seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
760 seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
761 u[0], u[1], u[2], u[3]);
762 seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
763 u[4], u[5], u[6], u[7]);
764 seq_printf(s, " SKB = 0x%p\n", skb);
768 wil_seq_print_skb(s, skb);
774 seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
775 dbg_vring_index, dbg_txdesc_index,
778 seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
779 dbg_txdesc_index, vring->size);
785 static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
787 return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
790 static const struct file_operations fops_txdesc = {
791 .open = wil_txdesc_seq_open,
792 .release = single_release,
797 /*---------beamforming------------*/
798 static char *wil_bfstatus_str(u32 status)
812 static bool is_all_zeros(void * const x_, size_t sz)
814 /* if reply is all-0, ignore this CID */
818 for (n = 0; n < sz / sizeof(*x); n++)
825 static int wil_bf_debugfs_show(struct seq_file *s, void *data)
829 struct wil6210_priv *wil = s->private;
830 struct wmi_notify_req_cmd cmd = {
834 struct wil6210_mbox_hdr_wmi wmi;
835 struct wmi_notify_req_done_event evt;
838 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
842 rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd),
843 WMI_NOTIFY_REQ_DONE_EVENTID, &reply,
845 /* if reply is all-0, ignore this CID */
846 if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt)))
849 status = le32_to_cpu(reply.evt.status);
850 seq_printf(s, "CID %d {\n"
852 " TxMCS = %2d TxTpt = %4d\n"
854 " Status = 0x%08x %s\n"
855 " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
856 " Goodput(rx:tx) %4d:%4d\n"
859 le64_to_cpu(reply.evt.tsf),
860 le16_to_cpu(reply.evt.bf_mcs),
861 le32_to_cpu(reply.evt.tx_tpt),
863 status, wil_bfstatus_str(status),
864 le16_to_cpu(reply.evt.my_rx_sector),
865 le16_to_cpu(reply.evt.my_tx_sector),
866 le16_to_cpu(reply.evt.other_rx_sector),
867 le16_to_cpu(reply.evt.other_tx_sector),
868 le32_to_cpu(reply.evt.rx_goodput),
869 le32_to_cpu(reply.evt.tx_goodput));
874 static int wil_bf_seq_open(struct inode *inode, struct file *file)
876 return single_open(file, wil_bf_debugfs_show, inode->i_private);
879 static const struct file_operations fops_bf = {
880 .open = wil_bf_seq_open,
881 .release = single_release,
886 /*---------SSID------------*/
887 static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf,
888 size_t count, loff_t *ppos)
890 struct wil6210_priv *wil = file->private_data;
891 struct wireless_dev *wdev = wil_to_wdev(wil);
893 return simple_read_from_buffer(user_buf, count, ppos,
894 wdev->ssid, wdev->ssid_len);
897 static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf,
898 size_t count, loff_t *ppos)
900 struct wil6210_priv *wil = file->private_data;
901 struct wireless_dev *wdev = wil_to_wdev(wil);
902 struct net_device *ndev = wil_to_ndev(wil);
905 wil_err(wil, "Unable to set SSID substring from [%d]\n",
910 if (count > sizeof(wdev->ssid)) {
911 wil_err(wil, "SSID too long, len = %d\n", (int)count);
914 if (netif_running(ndev)) {
915 wil_err(wil, "Unable to change SSID on running interface\n");
919 wdev->ssid_len = count;
920 return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos,
924 static const struct file_operations fops_ssid = {
925 .read = wil_read_file_ssid,
926 .write = wil_write_file_ssid,
930 /*---------temp------------*/
931 static void print_temp(struct seq_file *s, const char *prefix, u32 t)
936 seq_printf(s, "%s N/A\n", prefix);
939 seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
944 static int wil_temp_debugfs_show(struct seq_file *s, void *data)
946 struct wil6210_priv *wil = s->private;
948 int rc = wmi_get_temperature(wil, &t_m, &t_r);
951 seq_puts(s, "Failed\n");
955 print_temp(s, "T_mac =", t_m);
956 print_temp(s, "T_radio =", t_r);
961 static int wil_temp_seq_open(struct inode *inode, struct file *file)
963 return single_open(file, wil_temp_debugfs_show, inode->i_private);
966 static const struct file_operations fops_temp = {
967 .open = wil_temp_seq_open,
968 .release = single_release,
973 /*---------freq------------*/
974 static int wil_freq_debugfs_show(struct seq_file *s, void *data)
976 struct wil6210_priv *wil = s->private;
977 struct wireless_dev *wdev = wil_to_wdev(wil);
978 u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
980 seq_printf(s, "Freq = %d\n", freq);
985 static int wil_freq_seq_open(struct inode *inode, struct file *file)
987 return single_open(file, wil_freq_debugfs_show, inode->i_private);
990 static const struct file_operations fops_freq = {
991 .open = wil_freq_seq_open,
992 .release = single_release,
997 /*---------link------------*/
998 static int wil_link_debugfs_show(struct seq_file *s, void *data)
1000 struct wil6210_priv *wil = s->private;
1001 struct station_info sinfo;
1004 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1005 struct wil_sta_info *p = &wil->sta[i];
1006 char *status = "unknown";
1008 switch (p->status) {
1009 case wil_sta_unused:
1012 case wil_sta_conn_pending:
1013 status = "pending ";
1015 case wil_sta_connected:
1016 status = "connected";
1019 seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
1020 (p->data_port_open ? " data_port_open" : ""));
1022 if (p->status == wil_sta_connected) {
1023 rc = wil_cid_fill_sinfo(wil, i, &sinfo);
1027 seq_printf(s, " Tx_mcs = %d\n", sinfo.txrate.mcs);
1028 seq_printf(s, " Rx_mcs = %d\n", sinfo.rxrate.mcs);
1029 seq_printf(s, " SQ = %d\n", sinfo.signal);
1036 static int wil_link_seq_open(struct inode *inode, struct file *file)
1038 return single_open(file, wil_link_debugfs_show, inode->i_private);
1041 static const struct file_operations fops_link = {
1042 .open = wil_link_seq_open,
1043 .release = single_release,
1045 .llseek = seq_lseek,
1048 /*---------info------------*/
1049 static int wil_info_debugfs_show(struct seq_file *s, void *data)
1051 struct wil6210_priv *wil = s->private;
1052 struct net_device *ndev = wil_to_ndev(wil);
1053 int is_ac = power_supply_is_system_supplied();
1054 int rx = atomic_xchg(&wil->isr_count_rx, 0);
1055 int tx = atomic_xchg(&wil->isr_count_tx, 0);
1056 static ulong rxf_old, txf_old;
1057 ulong rxf = ndev->stats.rx_packets;
1058 ulong txf = ndev->stats.tx_packets;
1061 /* >0 : AC; 0 : battery; <0 : error */
1062 seq_printf(s, "AC powered : %d\n", is_ac);
1063 seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
1064 seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
1068 #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
1069 " " __stringify(x) : ""
1071 for (i = 0; i < ndev->num_tx_queues; i++) {
1072 struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
1073 unsigned long state = txq->state;
1075 seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
1076 CHECK_QSTATE(DRV_XOFF),
1077 CHECK_QSTATE(STACK_XOFF),
1078 CHECK_QSTATE(FROZEN)
1085 static int wil_info_seq_open(struct inode *inode, struct file *file)
1087 return single_open(file, wil_info_debugfs_show, inode->i_private);
1090 static const struct file_operations fops_info = {
1091 .open = wil_info_seq_open,
1092 .release = single_release,
1094 .llseek = seq_lseek,
1097 /*---------recovery------------*/
1098 /* mode = [manual|auto]
1099 * state = [idle|pending|running]
1101 static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf,
1102 size_t count, loff_t *ppos)
1104 struct wil6210_priv *wil = file->private_data;
1107 static const char * const sstate[] = {"idle", "pending", "running"};
1109 n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n",
1110 no_fw_recovery ? "manual" : "auto",
1111 sstate[wil->recovery_state]);
1113 n = min_t(int, n, sizeof(buf));
1115 return simple_read_from_buffer(user_buf, count, ppos,
1119 static ssize_t wil_write_file_recovery(struct file *file,
1120 const char __user *buf_,
1121 size_t count, loff_t *ppos)
1123 struct wil6210_priv *wil = file->private_data;
1124 static const char run_command[] = "run";
1125 char buf[sizeof(run_command) + 1]; /* to detect "runx" */
1128 if (wil->recovery_state != fw_recovery_pending) {
1129 wil_err(wil, "No recovery pending\n");
1134 wil_err(wil, "Offset [%d]\n", (int)*ppos);
1138 if (count > sizeof(buf)) {
1139 wil_err(wil, "Input too long, len = %d\n", (int)count);
1143 rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count);
1148 if (0 == strcmp(buf, run_command))
1149 wil_set_recovery_state(wil, fw_recovery_running);
1151 wil_err(wil, "Bad recovery command \"%s\"\n", buf);
1156 static const struct file_operations fops_recovery = {
1157 .read = wil_read_file_recovery,
1158 .write = wil_write_file_recovery,
1159 .open = simple_open,
1162 /*---------Station matrix------------*/
1163 static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
1166 u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
1168 seq_printf(s, "([%2d] %3d TU) 0x%03x [", r->buf_size, r->timeout,
1170 for (i = 0; i < r->buf_size; i++) {
1172 seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
1174 seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
1176 seq_printf(s, "] last drop 0x%03x\n", r->ssn_last_drop);
1179 static int wil_sta_debugfs_show(struct seq_file *s, void *data)
1181 struct wil6210_priv *wil = s->private;
1183 unsigned long flags;
1185 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1186 struct wil_sta_info *p = &wil->sta[i];
1187 char *status = "unknown";
1189 switch (p->status) {
1190 case wil_sta_unused:
1193 case wil_sta_conn_pending:
1194 status = "pending ";
1196 case wil_sta_connected:
1197 status = "connected";
1200 seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
1201 (p->data_port_open ? " data_port_open" : ""));
1203 if (p->status == wil_sta_connected) {
1204 spin_lock_irqsave(&p->tid_rx_lock, flags);
1205 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1206 struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
1209 seq_printf(s, "[%2d] ", tid);
1210 wil_print_rxtid(s, r);
1213 spin_unlock_irqrestore(&p->tid_rx_lock, flags);
1220 static int wil_sta_seq_open(struct inode *inode, struct file *file)
1222 return single_open(file, wil_sta_debugfs_show, inode->i_private);
1225 static const struct file_operations fops_sta = {
1226 .open = wil_sta_seq_open,
1227 .release = single_release,
1229 .llseek = seq_lseek,
1232 /*----------------*/
1233 static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
1239 for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
1240 struct debugfs_blob_wrapper *blob = &wil->blobs[i];
1241 const struct fw_map *map = &fw_mapping[i];
1246 blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
1247 blob->size = map->to - map->from;
1248 snprintf(name, sizeof(name), "blob_%s", map->name);
1249 wil_debugfs_create_ioblob(name, S_IRUGO, dbg, blob);
1254 static const struct {
1257 const struct file_operations *fops;
1259 {"mbox", S_IRUGO, &fops_mbox},
1260 {"vrings", S_IRUGO, &fops_vring},
1261 {"stations", S_IRUGO, &fops_sta},
1262 {"desc", S_IRUGO, &fops_txdesc},
1263 {"bf", S_IRUGO, &fops_bf},
1264 {"ssid", S_IRUGO | S_IWUSR, &fops_ssid},
1265 {"mem_val", S_IRUGO, &fops_memread},
1266 {"reset", S_IWUSR, &fops_reset},
1267 {"rxon", S_IWUSR, &fops_rxon},
1268 {"tx_mgmt", S_IWUSR, &fops_txmgmt},
1269 {"wmi_send", S_IWUSR, &fops_wmi},
1270 {"addba", S_IWUSR, &fops_addba},
1271 {"temp", S_IRUGO, &fops_temp},
1272 {"freq", S_IRUGO, &fops_freq},
1273 {"link", S_IRUGO, &fops_link},
1274 {"info", S_IRUGO, &fops_info},
1275 {"recovery", S_IRUGO | S_IWUSR, &fops_recovery},
1278 static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
1283 for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
1284 debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
1285 wil, dbg_files[i].fops);
1288 /* interrupt control blocks */
1289 static const struct {
1293 {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)},
1294 {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)},
1295 {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)},
1296 {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)},
1299 static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
1304 for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
1305 wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
1306 dbg_icr[i].icr_off);
1309 #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
1310 offsetof(struct wil6210_priv, name), type}
1312 /* fields in struct wil6210_priv */
1313 static const struct dbg_off dbg_wil_off[] = {
1314 WIL_FIELD(secure_pcp, S_IRUGO | S_IWUSR, doff_u32),
1315 WIL_FIELD(status, S_IRUGO | S_IWUSR, doff_ulong),
1316 WIL_FIELD(fw_version, S_IRUGO, doff_u32),
1317 WIL_FIELD(hw_version, S_IRUGO, doff_x32),
1318 WIL_FIELD(recovery_count, S_IRUGO, doff_u32),
1322 static const struct dbg_off dbg_wil_regs[] = {
1323 {"RGF_MAC_MTRL_COUNTER_0", S_IRUGO, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
1325 {"RGF_USER_USAGE_1", S_IRUGO, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
1329 /* static parameters */
1330 static const struct dbg_off dbg_statics[] = {
1331 {"desc_index", S_IRUGO | S_IWUSR, (ulong)&dbg_txdesc_index, doff_u32},
1332 {"vring_index", S_IRUGO | S_IWUSR, (ulong)&dbg_vring_index, doff_u32},
1333 {"mem_addr", S_IRUGO | S_IWUSR, (ulong)&mem_addr, doff_u32},
1337 int wil6210_debugfs_init(struct wil6210_priv *wil)
1339 struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
1340 wil_to_wiphy(wil)->debugfsdir);
1342 if (IS_ERR_OR_NULL(dbg))
1345 wil6210_debugfs_init_files(wil, dbg);
1346 wil6210_debugfs_init_isr(wil, dbg);
1347 wil6210_debugfs_init_blobs(wil, dbg);
1348 wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
1349 wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
1351 wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
1353 wil6210_debugfs_create_pseudo_ISR(wil, dbg);
1355 wil6210_debugfs_create_ITR_CNT(wil, dbg);
1360 void wil6210_debugfs_remove(struct wil6210_priv *wil)
1362 debugfs_remove_recursive(wil->debug);