2 * Copyright (c) 2012-2017 Qualcomm Atheros, Inc.
3 * Copyright (c) 2018, The Linux Foundation. All rights reserved.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <linux/module.h>
19 #include <linux/debugfs.h>
20 #include <linux/seq_file.h>
21 #include <linux/pci.h>
22 #include <linux/rtnetlink.h>
23 #include <linux/power_supply.h>
29 /* Nasty hack. Better have per device instances */
31 static u32 dbg_txdesc_index;
32 static u32 dbg_vring_index; /* 24+ for Rx, 0..23 for Tx */
47 enum dbg_off_type type;
50 static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil,
51 const char *name, struct vring *vring,
54 void __iomem *x = wmi_addr(wil, vring->hwtail);
57 seq_printf(s, "VRING %s = {\n", name);
58 seq_printf(s, " pa = %pad\n", &vring->pa);
59 seq_printf(s, " va = 0x%p\n", vring->va);
60 seq_printf(s, " size = %d\n", vring->size);
61 seq_printf(s, " swtail = %d\n", vring->swtail);
62 seq_printf(s, " swhead = %d\n", vring->swhead);
63 seq_printf(s, " hwtail = [0x%08x] -> ", vring->hwtail);
66 seq_printf(s, "0x%08x = %d\n", v, v);
71 if (vring->va && (vring->size <= (1 << WIL_RING_SIZE_ORDER_MAX))) {
74 for (i = 0; i < vring->size; i++) {
75 volatile struct vring_tx_desc *d = &vring->va[i].tx;
77 if ((i % 128) == 0 && (i != 0))
79 seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
80 _s : (vring->ctx[i].skb ? _h : 'h'));
87 static int wil_vring_debugfs_show(struct seq_file *s, void *data)
90 struct wil6210_priv *wil = s->private;
92 wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_');
94 for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
95 struct vring *vring = &wil->vring_tx[i];
96 struct vring_tx_data *txdata = &wil->vring_tx_data[i];
99 int cid = wil->vring2cid_tid[i][0];
100 int tid = wil->vring2cid_tid[i][1];
101 u32 swhead = vring->swhead;
102 u32 swtail = vring->swtail;
103 int used = (vring->size + swhead - swtail)
105 int avail = vring->size - used - 1;
108 /* performance monitoring */
109 cycles_t now = get_cycles();
110 uint64_t idle = txdata->idle * 100;
111 uint64_t total = now - txdata->begin;
115 snprintf(sidle, sizeof(sidle), "%3d%%",
118 snprintf(sidle, sizeof(sidle), "N/A");
123 snprintf(name, sizeof(name), "tx_%2d", i);
125 if (cid < WIL6210_MAX_CID)
127 "\n%pM CID %d TID %d 1x%s BACK([%u] %u TU A%s) [%3d|%3d] idle %s\n",
128 wil->sta[cid].addr, cid, tid,
129 txdata->dot1x_open ? "+" : "-",
132 txdata->agg_amsdu ? "+" : "-",
136 "\nBroadcast 1x%s [%3d|%3d] idle %s\n",
137 txdata->dot1x_open ? "+" : "-",
140 wil_print_vring(s, wil, name, vring, '_', 'H');
147 static int wil_vring_seq_open(struct inode *inode, struct file *file)
149 return single_open(file, wil_vring_debugfs_show, inode->i_private);
152 static const struct file_operations fops_vring = {
153 .open = wil_vring_seq_open,
154 .release = single_release,
159 static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
162 seq_hex_dump(s, prefix, DUMP_PREFIX_NONE, 16, 1, p, len, false);
165 static void wil_print_ring(struct seq_file *s, const char *prefix,
168 struct wil6210_priv *wil = s->private;
169 struct wil6210_mbox_ring r;
175 wil_memcpy_fromio_32(&r, off, sizeof(r));
176 wil_mbox_ring_le2cpus(&r);
178 * we just read memory block from NIC. This memory may be
179 * garbage. Check validity before using it.
181 rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
183 seq_printf(s, "ring %s = {\n", prefix);
184 seq_printf(s, " base = 0x%08x\n", r.base);
185 seq_printf(s, " size = 0x%04x bytes -> %d entries\n", r.size, rsize);
186 seq_printf(s, " tail = 0x%08x\n", r.tail);
187 seq_printf(s, " head = 0x%08x\n", r.head);
188 seq_printf(s, " entry size = %d\n", r.entry_size);
190 if (r.size % sizeof(struct wil6210_mbox_ring_desc)) {
191 seq_printf(s, " ??? size is not multiple of %zd, garbage?\n",
192 sizeof(struct wil6210_mbox_ring_desc));
196 if (!wmi_addr(wil, r.base) ||
197 !wmi_addr(wil, r.tail) ||
198 !wmi_addr(wil, r.head)) {
199 seq_puts(s, " ??? pointers are garbage?\n");
203 for (i = 0; i < rsize; i++) {
204 struct wil6210_mbox_ring_desc d;
205 struct wil6210_mbox_hdr hdr;
206 size_t delta = i * sizeof(d);
207 void __iomem *x = wil->csr + HOSTADDR(r.base) + delta;
209 wil_memcpy_fromio_32(&d, x, sizeof(d));
211 seq_printf(s, " [%2x] %s %s%s 0x%08x", i,
213 (r.tail - r.base == delta) ? "t" : " ",
214 (r.head - r.base == delta) ? "h" : " ",
215 le32_to_cpu(d.addr));
216 if (0 == wmi_read_hdr(wil, d.addr, &hdr)) {
217 u16 len = le16_to_cpu(hdr.len);
219 seq_printf(s, " -> %04x %04x %04x %02x\n",
220 le16_to_cpu(hdr.seq), len,
221 le16_to_cpu(hdr.type), hdr.flags);
222 if (len <= MAX_MBOXITEM_SIZE) {
223 unsigned char databuf[MAX_MBOXITEM_SIZE];
224 void __iomem *src = wmi_buffer(wil, d.addr) +
225 sizeof(struct wil6210_mbox_hdr);
227 * No need to check @src for validity -
228 * we already validated @d.addr while
231 wil_memcpy_fromio_32(databuf, src, len);
232 wil_seq_hexdump(s, databuf, len, " : ");
240 wil_halp_unvote(wil);
243 static int wil_mbox_debugfs_show(struct seq_file *s, void *data)
245 struct wil6210_priv *wil = s->private;
248 ret = wil_pm_runtime_get(wil);
252 wil_print_ring(s, "tx", wil->csr + HOST_MBOX +
253 offsetof(struct wil6210_mbox_ctl, tx));
254 wil_print_ring(s, "rx", wil->csr + HOST_MBOX +
255 offsetof(struct wil6210_mbox_ctl, rx));
257 wil_pm_runtime_put(wil);
262 static int wil_mbox_seq_open(struct inode *inode, struct file *file)
264 return single_open(file, wil_mbox_debugfs_show, inode->i_private);
267 static const struct file_operations fops_mbox = {
268 .open = wil_mbox_seq_open,
269 .release = single_release,
274 static int wil_debugfs_iomem_x32_set(void *data, u64 val)
276 struct wil_debugfs_iomem_data *d = (struct
277 wil_debugfs_iomem_data *)data;
278 struct wil6210_priv *wil = d->wil;
281 ret = wil_pm_runtime_get(wil);
285 writel(val, (void __iomem *)d->offset);
286 wmb(); /* make sure write propagated to HW */
288 wil_pm_runtime_put(wil);
293 static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
295 struct wil_debugfs_iomem_data *d = (struct
296 wil_debugfs_iomem_data *)data;
297 struct wil6210_priv *wil = d->wil;
300 ret = wil_pm_runtime_get(wil);
304 *val = readl((void __iomem *)d->offset);
306 wil_pm_runtime_put(wil);
311 DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
312 wil_debugfs_iomem_x32_set, "0x%08llx\n");
314 static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
316 struct dentry *parent,
318 struct wil6210_priv *wil)
321 struct wil_debugfs_iomem_data *data = &wil->dbg_data.data_arr[
322 wil->dbg_data.iomem_data_count];
325 data->offset = value;
327 file = debugfs_create_file(name, mode, parent, data, &fops_iomem_x32);
328 if (!IS_ERR_OR_NULL(file))
329 wil->dbg_data.iomem_data_count++;
334 static int wil_debugfs_ulong_set(void *data, u64 val)
336 *(ulong *)data = val;
340 static int wil_debugfs_ulong_get(void *data, u64 *val)
342 *val = *(ulong *)data;
346 DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
347 wil_debugfs_ulong_set, "0x%llx\n");
349 static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode,
350 struct dentry *parent,
353 return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong);
357 * wil6210_debugfs_init_offset - create set of debugfs files
358 * @wil - driver's context, used for printing
359 * @dbg - directory on the debugfs, where files will be created
360 * @base - base address used in address calculation
361 * @tbl - table with file descriptions. Should be terminated with empty element.
363 * Creates files accordingly to the @tbl.
365 static void wil6210_debugfs_init_offset(struct wil6210_priv *wil,
366 struct dentry *dbg, void *base,
367 const struct dbg_off * const tbl)
371 for (i = 0; tbl[i].name; i++) {
374 switch (tbl[i].type) {
376 f = debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg,
380 f = debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg,
384 f = wil_debugfs_create_ulong(tbl[i].name, tbl[i].mode,
385 dbg, base + tbl[i].off);
388 f = wil_debugfs_create_iomem_x32(tbl[i].name,
394 f = debugfs_create_u8(tbl[i].name, tbl[i].mode, dbg,
398 f = ERR_PTR(-EINVAL);
400 if (IS_ERR_OR_NULL(f))
401 wil_err(wil, "Create file \"%s\": err %ld\n",
402 tbl[i].name, PTR_ERR(f));
406 static const struct dbg_off isr_off[] = {
407 {"ICC", 0644, offsetof(struct RGF_ICR, ICC), doff_io32},
408 {"ICR", 0644, offsetof(struct RGF_ICR, ICR), doff_io32},
409 {"ICM", 0644, offsetof(struct RGF_ICR, ICM), doff_io32},
410 {"ICS", 0244, offsetof(struct RGF_ICR, ICS), doff_io32},
411 {"IMV", 0644, offsetof(struct RGF_ICR, IMV), doff_io32},
412 {"IMS", 0244, offsetof(struct RGF_ICR, IMS), doff_io32},
413 {"IMC", 0244, offsetof(struct RGF_ICR, IMC), doff_io32},
417 static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
419 struct dentry *parent, u32 off)
421 struct dentry *d = debugfs_create_dir(name, parent);
423 if (IS_ERR_OR_NULL(d))
426 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off,
432 static const struct dbg_off pseudo_isr_off[] = {
433 {"CAUSE", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32},
434 {"MASK_SW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32},
435 {"MASK_FW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32},
439 static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
440 struct dentry *parent)
442 struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
444 if (IS_ERR_OR_NULL(d))
447 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
453 static const struct dbg_off lgc_itr_cnt_off[] = {
454 {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32},
455 {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32},
456 {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32},
460 static const struct dbg_off tx_itr_cnt_off[] = {
461 {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_TRSH),
463 {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_DATA),
465 {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_CTL),
467 {"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_TRSH),
469 {"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_DATA),
471 {"IDL_CTL", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_CTL),
476 static const struct dbg_off rx_itr_cnt_off[] = {
477 {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_TRSH),
479 {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_DATA),
481 {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_CTL),
483 {"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_TRSH),
485 {"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_DATA),
487 {"IDL_CTL", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_CTL),
492 static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
493 struct dentry *parent)
495 struct dentry *d, *dtx, *drx;
497 d = debugfs_create_dir("ITR_CNT", parent);
498 if (IS_ERR_OR_NULL(d))
501 dtx = debugfs_create_dir("TX", d);
502 drx = debugfs_create_dir("RX", d);
503 if (IS_ERR_OR_NULL(dtx) || IS_ERR_OR_NULL(drx))
506 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
509 wil6210_debugfs_init_offset(wil, dtx, (void * __force)wil->csr,
512 wil6210_debugfs_init_offset(wil, drx, (void * __force)wil->csr,
517 static int wil_memread_debugfs_show(struct seq_file *s, void *data)
519 struct wil6210_priv *wil = s->private;
523 ret = wil_pm_runtime_get(wil);
527 a = wmi_buffer(wil, cpu_to_le32(mem_addr));
530 seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, readl(a));
532 seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
534 wil_pm_runtime_put(wil);
539 static int wil_memread_seq_open(struct inode *inode, struct file *file)
541 return single_open(file, wil_memread_debugfs_show, inode->i_private);
544 static const struct file_operations fops_memread = {
545 .open = wil_memread_seq_open,
546 .release = single_release,
551 static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
552 size_t count, loff_t *ppos)
554 enum { max_count = 4096 };
555 struct wil_blob_wrapper *wil_blob = file->private_data;
556 struct wil6210_priv *wil = wil_blob->wil;
558 size_t available = wil_blob->blob.size;
563 if (test_bit(wil_status_suspending, wil_blob->wil->status) ||
564 test_bit(wil_status_suspended, wil_blob->wil->status))
570 if (pos >= available || !count)
573 if (count > available - pos)
574 count = available - pos;
575 if (count > max_count)
578 buf = kmalloc(count, GFP_KERNEL);
582 rc = wil_pm_runtime_get(wil);
588 wil_memcpy_fromio_32(buf, (const void __iomem *)
589 wil_blob->blob.data + pos, count);
591 ret = copy_to_user(user_buf, buf, count);
593 wil_pm_runtime_put(wil);
605 static const struct file_operations fops_ioblob = {
606 .read = wil_read_file_ioblob,
608 .llseek = default_llseek,
612 struct dentry *wil_debugfs_create_ioblob(const char *name,
614 struct dentry *parent,
615 struct wil_blob_wrapper *wil_blob)
617 return debugfs_create_file(name, mode, parent, wil_blob, &fops_ioblob);
621 static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
622 size_t len, loff_t *ppos)
624 struct wil6210_priv *wil = file->private_data;
625 struct net_device *ndev = wil->main_ndev;
629 * this code does NOT sync device state with the rest of system
630 * use with care, debug only!!!
634 ndev->flags &= ~IFF_UP;
636 wil_reset(wil, true);
641 static const struct file_operations fops_reset = {
642 .write = wil_write_file_reset,
646 /*---write channel 1..4 to rxon for it, 0 to rxoff---*/
647 static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
648 size_t len, loff_t *ppos)
650 struct wil6210_priv *wil = file->private_data;
655 char *kbuf = memdup_user_nul(buf, len);
658 return PTR_ERR(kbuf);
659 rc = kstrtol(kbuf, 0, &channel);
664 if ((channel < 0) || (channel > 4)) {
665 wil_err(wil, "Invalid channel %ld\n", channel);
671 rc = wmi_set_channel(wil, (int)channel);
676 rc = wmi_rxon(wil, on);
683 static const struct file_operations fops_rxon = {
684 .write = wil_write_file_rxon,
688 /* block ack control, write:
689 * - "add <ringid> <agg_size> <timeout>" to trigger ADDBA
690 * - "del_tx <ringid> <reason>" to trigger DELBA for Tx side
691 * - "del_rx <CID> <TID> <reason>" to trigger DELBA for Rx side
693 static ssize_t wil_write_back(struct file *file, const char __user *buf,
694 size_t len, loff_t *ppos)
696 struct wil6210_priv *wil = file->private_data;
698 char *kbuf = kmalloc(len + 1, GFP_KERNEL);
705 rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
708 return rc >= 0 ? -EIO : rc;
712 rc = sscanf(kbuf, "%8s %d %d %d", cmd, &p1, &p2, &p3);
720 if ((strcmp(cmd, "add") == 0) ||
721 (strcmp(cmd, "del_tx") == 0)) {
722 struct vring_tx_data *txdata;
724 if (p1 < 0 || p1 >= WIL6210_MAX_TX_RINGS) {
725 wil_err(wil, "BACK: invalid ring id %d\n", p1);
728 txdata = &wil->vring_tx_data[p1];
729 if (strcmp(cmd, "add") == 0) {
731 wil_err(wil, "BACK: add require at least 2 params\n");
736 wmi_addba(wil, txdata->mid, p1, p2, p3);
739 p2 = WLAN_REASON_QSTA_LEAVE_QBSS;
740 wmi_delba_tx(wil, txdata->mid, p1, p2);
742 } else if (strcmp(cmd, "del_rx") == 0) {
743 struct wil_sta_info *sta;
747 "BACK: del_rx require at least 2 params\n");
750 if (p1 < 0 || p1 >= WIL6210_MAX_CID) {
751 wil_err(wil, "BACK: invalid CID %d\n", p1);
755 p3 = WLAN_REASON_QSTA_LEAVE_QBSS;
757 wmi_delba_rx(wil, sta->mid, mk_cidxtid(p1, p2), p3);
759 wil_err(wil, "BACK: Unrecognized command \"%s\"\n", cmd);
766 static ssize_t wil_read_back(struct file *file, char __user *user_buf,
767 size_t count, loff_t *ppos)
769 static const char text[] = "block ack control, write:\n"
770 " - \"add <ringid> <agg_size> <timeout>\" to trigger ADDBA\n"
771 "If missing, <timeout> defaults to 0\n"
772 " - \"del_tx <ringid> <reason>\" to trigger DELBA for Tx side\n"
773 " - \"del_rx <CID> <TID> <reason>\" to trigger DELBA for Rx side\n"
774 "If missing, <reason> set to \"STA_LEAVING\" (36)\n";
776 return simple_read_from_buffer(user_buf, count, ppos, text,
780 static const struct file_operations fops_back = {
781 .read = wil_read_back,
782 .write = wil_write_back,
786 /* pmc control, write:
787 * - "alloc <num descriptors> <descriptor_size>" to allocate PMC
788 * - "free" to release memory allocated for PMC
790 static ssize_t wil_write_pmccfg(struct file *file, const char __user *buf,
791 size_t len, loff_t *ppos)
793 struct wil6210_priv *wil = file->private_data;
795 char *kbuf = kmalloc(len + 1, GFP_KERNEL);
797 int num_descs, desc_size;
802 rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
805 return rc >= 0 ? -EIO : rc;
809 rc = sscanf(kbuf, "%8s %d %d", cmd, &num_descs, &desc_size);
816 wil_err(wil, "pmccfg: no params given\n");
820 if (0 == strcmp(cmd, "alloc")) {
822 wil_err(wil, "pmccfg: alloc requires 2 params\n");
825 wil_pmc_alloc(wil, num_descs, desc_size);
826 } else if (0 == strcmp(cmd, "free")) {
828 wil_err(wil, "pmccfg: free does not have any params\n");
831 wil_pmc_free(wil, true);
833 wil_err(wil, "pmccfg: Unrecognized command \"%s\"\n", cmd);
840 static ssize_t wil_read_pmccfg(struct file *file, char __user *user_buf,
841 size_t count, loff_t *ppos)
843 struct wil6210_priv *wil = file->private_data;
845 char help[] = "pmc control, write:\n"
846 " - \"alloc <num descriptors> <descriptor_size>\" to allocate pmc\n"
847 " - \"free\" to free memory allocated for pmc\n";
849 sprintf(text, "Last command status: %d\n\n%s",
850 wil_pmc_last_cmd_status(wil),
853 return simple_read_from_buffer(user_buf, count, ppos, text,
857 static const struct file_operations fops_pmccfg = {
858 .read = wil_read_pmccfg,
859 .write = wil_write_pmccfg,
863 static const struct file_operations fops_pmcdata = {
865 .read = wil_pmc_read,
866 .llseek = wil_pmc_llseek,
870 /* Write mgmt frame to this file to send it */
871 static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
872 size_t len, loff_t *ppos)
874 struct wil6210_priv *wil = file->private_data;
875 struct wiphy *wiphy = wil_to_wiphy(wil);
876 struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr;
877 struct cfg80211_mgmt_tx_params params;
884 frame = memdup_user(buf, len);
886 return PTR_ERR(frame);
891 rc = wil_cfg80211_mgmt_tx(wiphy, wdev, ¶ms, NULL);
894 wil_info(wil, "-> %d\n", rc);
899 static const struct file_operations fops_txmgmt = {
900 .write = wil_write_file_txmgmt,
904 /* Write WMI command (w/o mbox header) to this file to send it
905 * WMI starts from wil6210_mbox_hdr_wmi header
907 static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
908 size_t len, loff_t *ppos)
910 struct wil6210_priv *wil = file->private_data;
911 struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
912 struct wmi_cmd_hdr *wmi;
914 int cmdlen = len - sizeof(struct wmi_cmd_hdr);
921 wmi = kmalloc(len, GFP_KERNEL);
925 rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
931 cmd = (cmdlen > 0) ? &wmi[1] : NULL;
932 cmdid = le16_to_cpu(wmi->command_id);
934 rc1 = wmi_send(wil, cmdid, vif->mid, cmd, cmdlen);
937 wil_info(wil, "0x%04x[%d] -> %d\n", cmdid, cmdlen, rc1);
942 static const struct file_operations fops_wmi = {
943 .write = wil_write_file_wmi,
947 static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
950 int len = skb_headlen(skb);
952 int nr_frags = skb_shinfo(skb)->nr_frags;
954 seq_printf(s, " len = %d\n", len);
955 wil_seq_hexdump(s, p, len, " : ");
958 seq_printf(s, " nr_frags = %d\n", nr_frags);
959 for (i = 0; i < nr_frags; i++) {
960 const struct skb_frag_struct *frag =
961 &skb_shinfo(skb)->frags[i];
963 len = skb_frag_size(frag);
964 p = skb_frag_address_safe(frag);
965 seq_printf(s, " [%2d] : len = %d\n", i, len);
966 wil_seq_hexdump(s, p, len, " : ");
971 /*---------Tx/Rx descriptor------------*/
972 static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
974 struct wil6210_priv *wil = s->private;
976 bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS);
978 vring = tx ? &wil->vring_tx[dbg_vring_index] : &wil->vring_rx;
982 seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index);
984 seq_puts(s, "No Rx VRING\n");
988 if (dbg_txdesc_index < vring->size) {
989 /* use struct vring_tx_desc for Rx as well,
990 * only field used, .dma.length, is the same
992 volatile struct vring_tx_desc *d =
993 &vring->va[dbg_txdesc_index].tx;
994 volatile u32 *u = (volatile u32 *)d;
995 struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb;
998 seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index,
1001 seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
1002 seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
1003 u[0], u[1], u[2], u[3]);
1004 seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
1005 u[4], u[5], u[6], u[7]);
1006 seq_printf(s, " SKB = 0x%p\n", skb);
1010 wil_seq_print_skb(s, skb);
1016 seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
1017 dbg_vring_index, dbg_txdesc_index,
1020 seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
1021 dbg_txdesc_index, vring->size);
1027 static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
1029 return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
1032 static const struct file_operations fops_txdesc = {
1033 .open = wil_txdesc_seq_open,
1034 .release = single_release,
1036 .llseek = seq_lseek,
1039 /*---------beamforming------------*/
1040 static char *wil_bfstatus_str(u32 status)
1054 static bool is_all_zeros(void * const x_, size_t sz)
1056 /* if reply is all-0, ignore this CID */
1060 for (n = 0; n < sz / sizeof(*x); n++)
1067 static int wil_bf_debugfs_show(struct seq_file *s, void *data)
1071 struct wil6210_priv *wil = s->private;
1072 struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
1073 struct wmi_notify_req_cmd cmd = {
1077 struct wmi_cmd_hdr wmi;
1078 struct wmi_notify_req_done_event evt;
1081 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1085 rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, vif->mid,
1087 WMI_NOTIFY_REQ_DONE_EVENTID, &reply,
1089 /* if reply is all-0, ignore this CID */
1090 if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt)))
1093 status = le32_to_cpu(reply.evt.status);
1094 seq_printf(s, "CID %d {\n"
1095 " TSF = 0x%016llx\n"
1096 " TxMCS = %2d TxTpt = %4d\n"
1099 " Status = 0x%08x %s\n"
1100 " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
1101 " Goodput(rx:tx) %4d:%4d\n"
1104 le64_to_cpu(reply.evt.tsf),
1105 le16_to_cpu(reply.evt.bf_mcs),
1106 le32_to_cpu(reply.evt.tx_tpt),
1109 status, wil_bfstatus_str(status),
1110 le16_to_cpu(reply.evt.my_rx_sector),
1111 le16_to_cpu(reply.evt.my_tx_sector),
1112 le16_to_cpu(reply.evt.other_rx_sector),
1113 le16_to_cpu(reply.evt.other_tx_sector),
1114 le32_to_cpu(reply.evt.rx_goodput),
1115 le32_to_cpu(reply.evt.tx_goodput));
1120 static int wil_bf_seq_open(struct inode *inode, struct file *file)
1122 return single_open(file, wil_bf_debugfs_show, inode->i_private);
1125 static const struct file_operations fops_bf = {
1126 .open = wil_bf_seq_open,
1127 .release = single_release,
1129 .llseek = seq_lseek,
1132 /*---------temp------------*/
1133 static void print_temp(struct seq_file *s, const char *prefix, u32 t)
1138 seq_printf(s, "%s N/A\n", prefix);
1141 seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
1146 static int wil_temp_debugfs_show(struct seq_file *s, void *data)
1148 struct wil6210_priv *wil = s->private;
1150 int rc = wmi_get_temperature(wil, &t_m, &t_r);
1153 seq_puts(s, "Failed\n");
1157 print_temp(s, "T_mac =", t_m);
1158 print_temp(s, "T_radio =", t_r);
1163 static int wil_temp_seq_open(struct inode *inode, struct file *file)
1165 return single_open(file, wil_temp_debugfs_show, inode->i_private);
1168 static const struct file_operations fops_temp = {
1169 .open = wil_temp_seq_open,
1170 .release = single_release,
1172 .llseek = seq_lseek,
1175 /*---------freq------------*/
1176 static int wil_freq_debugfs_show(struct seq_file *s, void *data)
1178 struct wil6210_priv *wil = s->private;
1179 struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr;
1180 u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
1182 seq_printf(s, "Freq = %d\n", freq);
1187 static int wil_freq_seq_open(struct inode *inode, struct file *file)
1189 return single_open(file, wil_freq_debugfs_show, inode->i_private);
1192 static const struct file_operations fops_freq = {
1193 .open = wil_freq_seq_open,
1194 .release = single_release,
1196 .llseek = seq_lseek,
1199 /*---------link------------*/
1200 static int wil_link_debugfs_show(struct seq_file *s, void *data)
1202 struct wil6210_priv *wil = s->private;
1203 struct station_info sinfo;
1206 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1207 struct wil_sta_info *p = &wil->sta[i];
1208 char *status = "unknown";
1209 struct wil6210_vif *vif;
1212 switch (p->status) {
1213 case wil_sta_unused:
1216 case wil_sta_conn_pending:
1217 status = "pending ";
1219 case wil_sta_connected:
1220 status = "connected";
1223 mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
1224 seq_printf(s, "[%d][MID %d] %pM %s\n",
1225 i, mid, p->addr, status);
1227 if (p->status != wil_sta_connected)
1230 vif = (mid < wil->max_vifs) ? wil->vifs[mid] : NULL;
1232 rc = wil_cid_fill_sinfo(vif, i, &sinfo);
1236 seq_printf(s, " Tx_mcs = %d\n", sinfo.txrate.mcs);
1237 seq_printf(s, " Rx_mcs = %d\n", sinfo.rxrate.mcs);
1238 seq_printf(s, " SQ = %d\n", sinfo.signal);
1240 seq_puts(s, " INVALID MID\n");
1247 static int wil_link_seq_open(struct inode *inode, struct file *file)
1249 return single_open(file, wil_link_debugfs_show, inode->i_private);
1252 static const struct file_operations fops_link = {
1253 .open = wil_link_seq_open,
1254 .release = single_release,
1256 .llseek = seq_lseek,
1259 /*---------info------------*/
1260 static int wil_info_debugfs_show(struct seq_file *s, void *data)
1262 struct wil6210_priv *wil = s->private;
1263 struct net_device *ndev = wil->main_ndev;
1264 int is_ac = power_supply_is_system_supplied();
1265 int rx = atomic_xchg(&wil->isr_count_rx, 0);
1266 int tx = atomic_xchg(&wil->isr_count_tx, 0);
1267 static ulong rxf_old, txf_old;
1268 ulong rxf = ndev->stats.rx_packets;
1269 ulong txf = ndev->stats.tx_packets;
1272 /* >0 : AC; 0 : battery; <0 : error */
1273 seq_printf(s, "AC powered : %d\n", is_ac);
1274 seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
1275 seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
1279 #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
1280 " " __stringify(x) : ""
1282 for (i = 0; i < ndev->num_tx_queues; i++) {
1283 struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
1284 unsigned long state = txq->state;
1286 seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
1287 CHECK_QSTATE(DRV_XOFF),
1288 CHECK_QSTATE(STACK_XOFF),
1289 CHECK_QSTATE(FROZEN)
1296 static int wil_info_seq_open(struct inode *inode, struct file *file)
1298 return single_open(file, wil_info_debugfs_show, inode->i_private);
1301 static const struct file_operations fops_info = {
1302 .open = wil_info_seq_open,
1303 .release = single_release,
1305 .llseek = seq_lseek,
1308 /*---------recovery------------*/
1309 /* mode = [manual|auto]
1310 * state = [idle|pending|running]
1312 static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf,
1313 size_t count, loff_t *ppos)
1315 struct wil6210_priv *wil = file->private_data;
1318 static const char * const sstate[] = {"idle", "pending", "running"};
1320 n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n",
1321 no_fw_recovery ? "manual" : "auto",
1322 sstate[wil->recovery_state]);
1324 n = min_t(int, n, sizeof(buf));
1326 return simple_read_from_buffer(user_buf, count, ppos,
1330 static ssize_t wil_write_file_recovery(struct file *file,
1331 const char __user *buf_,
1332 size_t count, loff_t *ppos)
1334 struct wil6210_priv *wil = file->private_data;
1335 static const char run_command[] = "run";
1336 char buf[sizeof(run_command) + 1]; /* to detect "runx" */
1339 if (wil->recovery_state != fw_recovery_pending) {
1340 wil_err(wil, "No recovery pending\n");
1345 wil_err(wil, "Offset [%d]\n", (int)*ppos);
1349 if (count > sizeof(buf)) {
1350 wil_err(wil, "Input too long, len = %d\n", (int)count);
1354 rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count);
1359 if (0 == strcmp(buf, run_command))
1360 wil_set_recovery_state(wil, fw_recovery_running);
1362 wil_err(wil, "Bad recovery command \"%s\"\n", buf);
1367 static const struct file_operations fops_recovery = {
1368 .read = wil_read_file_recovery,
1369 .write = wil_write_file_recovery,
1370 .open = simple_open,
1373 /*---------Station matrix------------*/
1374 static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
1377 u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
1378 unsigned long long drop_dup = r->drop_dup, drop_old = r->drop_old;
1380 seq_printf(s, "([%2d] %3d TU) 0x%03x [", r->buf_size, r->timeout,
1382 for (i = 0; i < r->buf_size; i++) {
1384 seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
1386 seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
1389 "] total %llu drop %llu (dup %llu + old %llu) last 0x%03x\n",
1390 r->total, drop_dup + drop_old, drop_dup, drop_old,
1394 static void wil_print_rxtid_crypto(struct seq_file *s, int tid,
1395 struct wil_tid_crypto_rx *c)
1399 for (i = 0; i < 4; i++) {
1400 struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
1408 if (tid < WIL_STA_TID_NUM)
1409 seq_printf(s, " [%2d] PN", tid);
1411 seq_puts(s, " [GR] PN");
1413 for (i = 0; i < 4; i++) {
1414 struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
1416 seq_printf(s, " [%i%s]%6phN", i, cc->key_set ? "+" : "-",
1422 static int wil_sta_debugfs_show(struct seq_file *s, void *data)
1423 __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
1425 struct wil6210_priv *wil = s->private;
1428 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1429 struct wil_sta_info *p = &wil->sta[i];
1430 char *status = "unknown";
1434 switch (p->status) {
1435 case wil_sta_unused:
1438 case wil_sta_conn_pending:
1439 status = "pending ";
1441 case wil_sta_connected:
1442 status = "connected";
1446 mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
1447 seq_printf(s, "[%d] %pM %s MID %d AID %d\n", i, p->addr, status,
1450 if (p->status == wil_sta_connected) {
1451 spin_lock_bh(&p->tid_rx_lock);
1452 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1453 struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
1454 struct wil_tid_crypto_rx *c =
1455 &p->tid_crypto_rx[tid];
1458 seq_printf(s, " [%2d] ", tid);
1459 wil_print_rxtid(s, r);
1462 wil_print_rxtid_crypto(s, tid, c);
1464 wil_print_rxtid_crypto(s, WIL_STA_TID_NUM,
1465 &p->group_crypto_rx);
1466 spin_unlock_bh(&p->tid_rx_lock);
1468 "Rx invalid frame: non-data %lu, short %lu, large %lu, replay %lu\n",
1469 p->stats.rx_non_data_frame,
1470 p->stats.rx_short_frame,
1471 p->stats.rx_large_frame,
1472 p->stats.rx_replay);
1474 seq_puts(s, "Rx/MCS:");
1475 for (mcs = 0; mcs < ARRAY_SIZE(p->stats.rx_per_mcs);
1477 seq_printf(s, " %lld",
1478 p->stats.rx_per_mcs[mcs]);
1486 static int wil_sta_seq_open(struct inode *inode, struct file *file)
1488 return single_open(file, wil_sta_debugfs_show, inode->i_private);
1491 static const struct file_operations fops_sta = {
1492 .open = wil_sta_seq_open,
1493 .release = single_release,
1495 .llseek = seq_lseek,
1498 static int wil_mids_debugfs_show(struct seq_file *s, void *data)
1500 struct wil6210_priv *wil = s->private;
1501 struct wil6210_vif *vif;
1502 struct net_device *ndev;
1505 mutex_lock(&wil->vif_mutex);
1506 for (i = 0; i < wil->max_vifs; i++) {
1510 ndev = vif_to_ndev(vif);
1511 seq_printf(s, "[%d] %pM %s\n", i, ndev->dev_addr,
1514 seq_printf(s, "[%d] unused\n", i);
1517 mutex_unlock(&wil->vif_mutex);
1522 static int wil_mids_seq_open(struct inode *inode, struct file *file)
1524 return single_open(file, wil_mids_debugfs_show, inode->i_private);
1527 static const struct file_operations fops_mids = {
1528 .open = wil_mids_seq_open,
1529 .release = single_release,
1531 .llseek = seq_lseek,
1534 static ssize_t wil_read_file_led_cfg(struct file *file, char __user *user_buf,
1535 size_t count, loff_t *ppos)
1540 n = snprintf(buf, sizeof(buf),
1541 "led_id is set to %d, echo 1 to enable, 0 to disable\n",
1544 n = min_t(int, n, sizeof(buf));
1546 return simple_read_from_buffer(user_buf, count, ppos,
1550 static ssize_t wil_write_file_led_cfg(struct file *file,
1551 const char __user *buf_,
1552 size_t count, loff_t *ppos)
1554 struct wil6210_priv *wil = file->private_data;
1558 rc = kstrtoint_from_user(buf_, count, 0, &val);
1560 wil_err(wil, "Invalid argument\n");
1564 wil_info(wil, "%s led %d\n", val ? "Enabling" : "Disabling", led_id);
1565 rc = wmi_led_cfg(wil, val);
1567 wil_info(wil, "%s led %d failed\n",
1568 val ? "Enabling" : "Disabling", led_id);
1575 static const struct file_operations fops_led_cfg = {
1576 .read = wil_read_file_led_cfg,
1577 .write = wil_write_file_led_cfg,
1578 .open = simple_open,
1581 /* led_blink_time, write:
1582 * "<blink_on_slow> <blink_off_slow> <blink_on_med> <blink_off_med> <blink_on_fast> <blink_off_fast>
1584 static ssize_t wil_write_led_blink_time(struct file *file,
1585 const char __user *buf,
1586 size_t len, loff_t *ppos)
1589 char *kbuf = kmalloc(len + 1, GFP_KERNEL);
1594 rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
1597 return rc >= 0 ? -EIO : rc;
1601 rc = sscanf(kbuf, "%d %d %d %d %d %d",
1602 &led_blink_time[WIL_LED_TIME_SLOW].on_ms,
1603 &led_blink_time[WIL_LED_TIME_SLOW].off_ms,
1604 &led_blink_time[WIL_LED_TIME_MED].on_ms,
1605 &led_blink_time[WIL_LED_TIME_MED].off_ms,
1606 &led_blink_time[WIL_LED_TIME_FAST].on_ms,
1607 &led_blink_time[WIL_LED_TIME_FAST].off_ms);
1618 static ssize_t wil_read_led_blink_time(struct file *file, char __user *user_buf,
1619 size_t count, loff_t *ppos)
1621 static char text[400];
1623 snprintf(text, sizeof(text),
1624 "To set led blink on/off time variables write:\n"
1625 "<blink_on_slow> <blink_off_slow> <blink_on_med> "
1626 "<blink_off_med> <blink_on_fast> <blink_off_fast>\n"
1627 "The current values are:\n"
1628 "%d %d %d %d %d %d\n",
1629 led_blink_time[WIL_LED_TIME_SLOW].on_ms,
1630 led_blink_time[WIL_LED_TIME_SLOW].off_ms,
1631 led_blink_time[WIL_LED_TIME_MED].on_ms,
1632 led_blink_time[WIL_LED_TIME_MED].off_ms,
1633 led_blink_time[WIL_LED_TIME_FAST].on_ms,
1634 led_blink_time[WIL_LED_TIME_FAST].off_ms);
1636 return simple_read_from_buffer(user_buf, count, ppos, text,
1640 static const struct file_operations fops_led_blink_time = {
1641 .read = wil_read_led_blink_time,
1642 .write = wil_write_led_blink_time,
1643 .open = simple_open,
1646 /*---------FW capabilities------------*/
1647 static int wil_fw_capabilities_debugfs_show(struct seq_file *s, void *data)
1649 struct wil6210_priv *wil = s->private;
1651 seq_printf(s, "fw_capabilities : %*pb\n", WMI_FW_CAPABILITY_MAX,
1652 wil->fw_capabilities);
1657 static int wil_fw_capabilities_seq_open(struct inode *inode, struct file *file)
1659 return single_open(file, wil_fw_capabilities_debugfs_show,
1663 static const struct file_operations fops_fw_capabilities = {
1664 .open = wil_fw_capabilities_seq_open,
1665 .release = single_release,
1667 .llseek = seq_lseek,
1670 /*---------FW version------------*/
1671 static int wil_fw_version_debugfs_show(struct seq_file *s, void *data)
1673 struct wil6210_priv *wil = s->private;
1675 if (wil->fw_version[0])
1676 seq_printf(s, "%s\n", wil->fw_version);
1678 seq_puts(s, "N/A\n");
1683 static int wil_fw_version_seq_open(struct inode *inode, struct file *file)
1685 return single_open(file, wil_fw_version_debugfs_show,
1689 static const struct file_operations fops_fw_version = {
1690 .open = wil_fw_version_seq_open,
1691 .release = single_release,
1693 .llseek = seq_lseek,
1696 /*---------suspend_stats---------*/
1697 static ssize_t wil_write_suspend_stats(struct file *file,
1698 const char __user *buf,
1699 size_t len, loff_t *ppos)
1701 struct wil6210_priv *wil = file->private_data;
1703 memset(&wil->suspend_stats, 0, sizeof(wil->suspend_stats));
1708 static ssize_t wil_read_suspend_stats(struct file *file,
1709 char __user *user_buf,
1710 size_t count, loff_t *ppos)
1712 struct wil6210_priv *wil = file->private_data;
1714 int n, ret, text_size = 500;
1716 text = kmalloc(text_size, GFP_KERNEL);
1720 n = snprintf(text, text_size,
1721 "Radio on suspend statistics:\n"
1722 "successful suspends:%ld failed suspends:%ld\n"
1723 "successful resumes:%ld failed resumes:%ld\n"
1724 "rejected by device:%ld\n"
1725 "Radio off suspend statistics:\n"
1726 "successful suspends:%ld failed suspends:%ld\n"
1727 "successful resumes:%ld failed resumes:%ld\n"
1728 "General statistics:\n"
1729 "rejected by host:%ld\n",
1730 wil->suspend_stats.r_on.successful_suspends,
1731 wil->suspend_stats.r_on.failed_suspends,
1732 wil->suspend_stats.r_on.successful_resumes,
1733 wil->suspend_stats.r_on.failed_resumes,
1734 wil->suspend_stats.rejected_by_device,
1735 wil->suspend_stats.r_off.successful_suspends,
1736 wil->suspend_stats.r_off.failed_suspends,
1737 wil->suspend_stats.r_off.successful_resumes,
1738 wil->suspend_stats.r_off.failed_resumes,
1739 wil->suspend_stats.rejected_by_host);
1741 n = min_t(int, n, text_size);
1743 ret = simple_read_from_buffer(user_buf, count, ppos, text, n);
1750 static const struct file_operations fops_suspend_stats = {
1751 .read = wil_read_suspend_stats,
1752 .write = wil_write_suspend_stats,
1753 .open = simple_open,
1756 /*----------------*/
1757 static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
1763 for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
1764 struct wil_blob_wrapper *wil_blob = &wil->blobs[i];
1765 struct debugfs_blob_wrapper *blob = &wil_blob->blob;
1766 const struct fw_map *map = &fw_mapping[i];
1771 wil_blob->wil = wil;
1772 blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
1773 blob->size = map->to - map->from;
1774 snprintf(name, sizeof(name), "blob_%s", map->name);
1775 wil_debugfs_create_ioblob(name, 0444, dbg, wil_blob);
1780 static const struct {
1783 const struct file_operations *fops;
1785 {"mbox", 0444, &fops_mbox},
1786 {"vrings", 0444, &fops_vring},
1787 {"stations", 0444, &fops_sta},
1788 {"mids", 0444, &fops_mids},
1789 {"desc", 0444, &fops_txdesc},
1790 {"bf", 0444, &fops_bf},
1791 {"mem_val", 0644, &fops_memread},
1792 {"reset", 0244, &fops_reset},
1793 {"rxon", 0244, &fops_rxon},
1794 {"tx_mgmt", 0244, &fops_txmgmt},
1795 {"wmi_send", 0244, &fops_wmi},
1796 {"back", 0644, &fops_back},
1797 {"pmccfg", 0644, &fops_pmccfg},
1798 {"pmcdata", 0444, &fops_pmcdata},
1799 {"temp", 0444, &fops_temp},
1800 {"freq", 0444, &fops_freq},
1801 {"link", 0444, &fops_link},
1802 {"info", 0444, &fops_info},
1803 {"recovery", 0644, &fops_recovery},
1804 {"led_cfg", 0644, &fops_led_cfg},
1805 {"led_blink_time", 0644, &fops_led_blink_time},
1806 {"fw_capabilities", 0444, &fops_fw_capabilities},
1807 {"fw_version", 0444, &fops_fw_version},
1808 {"suspend_stats", 0644, &fops_suspend_stats},
1811 static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
1816 for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
1817 debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
1818 wil, dbg_files[i].fops);
1821 /* interrupt control blocks */
1822 static const struct {
1826 {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)},
1827 {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)},
1828 {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)},
1829 {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)},
1832 static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
1837 for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
1838 wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
1839 dbg_icr[i].icr_off);
1842 #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
1843 offsetof(struct wil6210_priv, name), type}
1845 /* fields in struct wil6210_priv */
1846 static const struct dbg_off dbg_wil_off[] = {
1847 WIL_FIELD(status[0], 0644, doff_ulong),
1848 WIL_FIELD(hw_version, 0444, doff_x32),
1849 WIL_FIELD(recovery_count, 0444, doff_u32),
1850 WIL_FIELD(discovery_mode, 0644, doff_u8),
1851 WIL_FIELD(chip_revision, 0444, doff_u8),
1852 WIL_FIELD(abft_len, 0644, doff_u8),
1853 WIL_FIELD(wakeup_trigger, 0644, doff_u8),
1854 WIL_FIELD(vring_idle_trsh, 0644, doff_u32),
1858 static const struct dbg_off dbg_wil_regs[] = {
1859 {"RGF_MAC_MTRL_COUNTER_0", 0444, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
1861 {"RGF_USER_USAGE_1", 0444, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
1865 /* static parameters */
1866 static const struct dbg_off dbg_statics[] = {
1867 {"desc_index", 0644, (ulong)&dbg_txdesc_index, doff_u32},
1868 {"vring_index", 0644, (ulong)&dbg_vring_index, doff_u32},
1869 {"mem_addr", 0644, (ulong)&mem_addr, doff_u32},
1870 {"led_polarity", 0644, (ulong)&led_polarity, doff_u8},
1874 static const int dbg_off_count = 4 * (ARRAY_SIZE(isr_off) - 1) +
1875 ARRAY_SIZE(dbg_wil_regs) - 1 +
1876 ARRAY_SIZE(pseudo_isr_off) - 1 +
1877 ARRAY_SIZE(lgc_itr_cnt_off) - 1 +
1878 ARRAY_SIZE(tx_itr_cnt_off) - 1 +
1879 ARRAY_SIZE(rx_itr_cnt_off) - 1;
1881 int wil6210_debugfs_init(struct wil6210_priv *wil)
1883 struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
1884 wil_to_wiphy(wil)->debugfsdir);
1885 if (IS_ERR_OR_NULL(dbg))
1888 wil->dbg_data.data_arr = kcalloc(dbg_off_count,
1889 sizeof(struct wil_debugfs_iomem_data),
1891 if (!wil->dbg_data.data_arr) {
1892 debugfs_remove_recursive(dbg);
1897 wil->dbg_data.iomem_data_count = 0;
1901 wil6210_debugfs_init_files(wil, dbg);
1902 wil6210_debugfs_init_isr(wil, dbg);
1903 wil6210_debugfs_init_blobs(wil, dbg);
1904 wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
1905 wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
1907 wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
1909 wil6210_debugfs_create_pseudo_ISR(wil, dbg);
1911 wil6210_debugfs_create_ITR_CNT(wil, dbg);
1916 void wil6210_debugfs_remove(struct wil6210_priv *wil)
1918 debugfs_remove_recursive(wil->debug);
1921 kfree(wil->dbg_data.data_arr);
1923 /* free pmc memory without sending command to fw, as it will
1924 * be reset on the way down anyway
1926 wil_pmc_free(wil, false);