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 A%s) [%3d|%3d] idle %3d%%\n",
118 wil
->sta
[cid
].addr
, cid
, tid
,
119 txdata
->agg_wsize
, txdata
->agg_timeout
,
120 txdata
->agg_amsdu
? "+" : "-",
121 used
, avail
, (int)idle
);
123 wil_print_vring(s
, wil
, name
, vring
, '_', 'H');
130 static int wil_vring_seq_open(struct inode
*inode
, struct file
*file
)
132 return single_open(file
, wil_vring_debugfs_show
, inode
->i_private
);
135 static const struct file_operations fops_vring
= {
136 .open
= wil_vring_seq_open
,
137 .release
= single_release
,
142 static void wil_print_ring(struct seq_file
*s
, const char *prefix
,
145 struct wil6210_priv
*wil
= s
->private;
146 struct wil6210_mbox_ring r
;
150 wil_memcpy_fromio_32(&r
, off
, sizeof(r
));
151 wil_mbox_ring_le2cpus(&r
);
153 * we just read memory block from NIC. This memory may be
154 * garbage. Check validity before using it.
156 rsize
= r
.size
/ sizeof(struct wil6210_mbox_ring_desc
);
158 seq_printf(s
, "ring %s = {\n", prefix
);
159 seq_printf(s
, " base = 0x%08x\n", r
.base
);
160 seq_printf(s
, " size = 0x%04x bytes -> %d entries\n", r
.size
, rsize
);
161 seq_printf(s
, " tail = 0x%08x\n", r
.tail
);
162 seq_printf(s
, " head = 0x%08x\n", r
.head
);
163 seq_printf(s
, " entry size = %d\n", r
.entry_size
);
165 if (r
.size
% sizeof(struct wil6210_mbox_ring_desc
)) {
166 seq_printf(s
, " ??? size is not multiple of %zd, garbage?\n",
167 sizeof(struct wil6210_mbox_ring_desc
));
171 if (!wmi_addr(wil
, r
.base
) ||
172 !wmi_addr(wil
, r
.tail
) ||
173 !wmi_addr(wil
, r
.head
)) {
174 seq_puts(s
, " ??? pointers are garbage?\n");
178 for (i
= 0; i
< rsize
; i
++) {
179 struct wil6210_mbox_ring_desc d
;
180 struct wil6210_mbox_hdr hdr
;
181 size_t delta
= i
* sizeof(d
);
182 void __iomem
*x
= wil
->csr
+ HOSTADDR(r
.base
) + delta
;
184 wil_memcpy_fromio_32(&d
, x
, sizeof(d
));
186 seq_printf(s
, " [%2x] %s %s%s 0x%08x", i
,
188 (r
.tail
- r
.base
== delta
) ? "t" : " ",
189 (r
.head
- r
.base
== delta
) ? "h" : " ",
190 le32_to_cpu(d
.addr
));
191 if (0 == wmi_read_hdr(wil
, d
.addr
, &hdr
)) {
192 u16 len
= le16_to_cpu(hdr
.len
);
194 seq_printf(s
, " -> %04x %04x %04x %02x\n",
195 le16_to_cpu(hdr
.seq
), len
,
196 le16_to_cpu(hdr
.type
), hdr
.flags
);
197 if (len
<= MAX_MBOXITEM_SIZE
) {
199 char printbuf
[16 * 3 + 2];
200 unsigned char databuf
[MAX_MBOXITEM_SIZE
];
201 void __iomem
*src
= wmi_buffer(wil
, d
.addr
) +
202 sizeof(struct wil6210_mbox_hdr
);
204 * No need to check @src for validity -
205 * we already validated @d.addr while
208 wil_memcpy_fromio_32(databuf
, src
, len
);
210 int l
= min(len
- n
, 16);
212 hex_dump_to_buffer(databuf
+ n
, l
,
216 seq_printf(s
, " : %s\n", printbuf
);
228 static int wil_mbox_debugfs_show(struct seq_file
*s
, void *data
)
230 struct wil6210_priv
*wil
= s
->private;
232 wil_print_ring(s
, "tx", wil
->csr
+ HOST_MBOX
+
233 offsetof(struct wil6210_mbox_ctl
, tx
));
234 wil_print_ring(s
, "rx", wil
->csr
+ HOST_MBOX
+
235 offsetof(struct wil6210_mbox_ctl
, rx
));
240 static int wil_mbox_seq_open(struct inode
*inode
, struct file
*file
)
242 return single_open(file
, wil_mbox_debugfs_show
, inode
->i_private
);
245 static const struct file_operations fops_mbox
= {
246 .open
= wil_mbox_seq_open
,
247 .release
= single_release
,
252 static int wil_debugfs_iomem_x32_set(void *data
, u64 val
)
254 iowrite32(val
, (void __iomem
*)data
);
255 wmb(); /* make sure write propagated to HW */
260 static int wil_debugfs_iomem_x32_get(void *data
, u64
*val
)
262 *val
= ioread32((void __iomem
*)data
);
267 DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32
, wil_debugfs_iomem_x32_get
,
268 wil_debugfs_iomem_x32_set
, "0x%08llx\n");
270 static struct dentry
*wil_debugfs_create_iomem_x32(const char *name
,
272 struct dentry
*parent
,
275 return debugfs_create_file(name
, mode
, parent
, value
,
279 static int wil_debugfs_ulong_set(void *data
, u64 val
)
281 *(ulong
*)data
= val
;
285 static int wil_debugfs_ulong_get(void *data
, u64
*val
)
287 *val
= *(ulong
*)data
;
291 DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong
, wil_debugfs_ulong_get
,
292 wil_debugfs_ulong_set
, "%llu\n");
294 static struct dentry
*wil_debugfs_create_ulong(const char *name
, umode_t mode
,
295 struct dentry
*parent
,
298 return debugfs_create_file(name
, mode
, parent
, value
, &wil_fops_ulong
);
302 * wil6210_debugfs_init_offset - create set of debugfs files
303 * @wil - driver's context, used for printing
304 * @dbg - directory on the debugfs, where files will be created
305 * @base - base address used in address calculation
306 * @tbl - table with file descriptions. Should be terminated with empty element.
308 * Creates files accordingly to the @tbl.
310 static void wil6210_debugfs_init_offset(struct wil6210_priv
*wil
,
311 struct dentry
*dbg
, void *base
,
312 const struct dbg_off
* const tbl
)
316 for (i
= 0; tbl
[i
].name
; i
++) {
319 switch (tbl
[i
].type
) {
321 f
= debugfs_create_u32(tbl
[i
].name
, tbl
[i
].mode
, dbg
,
325 f
= debugfs_create_x32(tbl
[i
].name
, tbl
[i
].mode
, dbg
,
329 f
= wil_debugfs_create_ulong(tbl
[i
].name
, tbl
[i
].mode
,
330 dbg
, base
+ tbl
[i
].off
);
333 f
= wil_debugfs_create_iomem_x32(tbl
[i
].name
,
338 f
= ERR_PTR(-EINVAL
);
340 if (IS_ERR_OR_NULL(f
))
341 wil_err(wil
, "Create file \"%s\": err %ld\n",
342 tbl
[i
].name
, PTR_ERR(f
));
346 static const struct dbg_off isr_off
[] = {
347 {"ICC", S_IRUGO
| S_IWUSR
, offsetof(struct RGF_ICR
, ICC
), doff_io32
},
348 {"ICR", S_IRUGO
| S_IWUSR
, offsetof(struct RGF_ICR
, ICR
), doff_io32
},
349 {"ICM", S_IRUGO
| S_IWUSR
, offsetof(struct RGF_ICR
, ICM
), doff_io32
},
350 {"ICS", S_IWUSR
, offsetof(struct RGF_ICR
, ICS
), doff_io32
},
351 {"IMV", S_IRUGO
| S_IWUSR
, offsetof(struct RGF_ICR
, IMV
), doff_io32
},
352 {"IMS", S_IWUSR
, offsetof(struct RGF_ICR
, IMS
), doff_io32
},
353 {"IMC", S_IWUSR
, offsetof(struct RGF_ICR
, IMC
), doff_io32
},
357 static int wil6210_debugfs_create_ISR(struct wil6210_priv
*wil
,
359 struct dentry
*parent
, u32 off
)
361 struct dentry
*d
= debugfs_create_dir(name
, parent
);
363 if (IS_ERR_OR_NULL(d
))
366 wil6210_debugfs_init_offset(wil
, d
, (void * __force
)wil
->csr
+ off
,
372 static const struct dbg_off pseudo_isr_off
[] = {
373 {"CAUSE", S_IRUGO
, HOSTADDR(RGF_DMA_PSEUDO_CAUSE
), doff_io32
},
374 {"MASK_SW", S_IRUGO
, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW
), doff_io32
},
375 {"MASK_FW", S_IRUGO
, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW
), doff_io32
},
379 static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv
*wil
,
380 struct dentry
*parent
)
382 struct dentry
*d
= debugfs_create_dir("PSEUDO_ISR", parent
);
384 if (IS_ERR_OR_NULL(d
))
387 wil6210_debugfs_init_offset(wil
, d
, (void * __force
)wil
->csr
,
393 static const struct dbg_off lgc_itr_cnt_off
[] = {
394 {"TRSH", S_IRUGO
| S_IWUSR
, HOSTADDR(RGF_DMA_ITR_CNT_TRSH
), doff_io32
},
395 {"DATA", S_IRUGO
| S_IWUSR
, HOSTADDR(RGF_DMA_ITR_CNT_DATA
), doff_io32
},
396 {"CTL", S_IRUGO
| S_IWUSR
, HOSTADDR(RGF_DMA_ITR_CNT_CRL
), doff_io32
},
400 static const struct dbg_off tx_itr_cnt_off
[] = {
401 {"TRSH", S_IRUGO
| S_IWUSR
, HOSTADDR(RGF_DMA_ITR_TX_CNT_TRSH
),
403 {"DATA", S_IRUGO
| S_IWUSR
, HOSTADDR(RGF_DMA_ITR_TX_CNT_DATA
),
405 {"CTL", S_IRUGO
| S_IWUSR
, HOSTADDR(RGF_DMA_ITR_TX_CNT_CTL
),
407 {"IDL_TRSH", S_IRUGO
| S_IWUSR
, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_TRSH
),
409 {"IDL_DATA", S_IRUGO
| S_IWUSR
, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_DATA
),
411 {"IDL_CTL", S_IRUGO
| S_IWUSR
, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_CTL
),
416 static const struct dbg_off rx_itr_cnt_off
[] = {
417 {"TRSH", S_IRUGO
| S_IWUSR
, HOSTADDR(RGF_DMA_ITR_RX_CNT_TRSH
),
419 {"DATA", S_IRUGO
| S_IWUSR
, HOSTADDR(RGF_DMA_ITR_RX_CNT_DATA
),
421 {"CTL", S_IRUGO
| S_IWUSR
, HOSTADDR(RGF_DMA_ITR_RX_CNT_CTL
),
423 {"IDL_TRSH", S_IRUGO
| S_IWUSR
, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_TRSH
),
425 {"IDL_DATA", S_IRUGO
| S_IWUSR
, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_DATA
),
427 {"IDL_CTL", S_IRUGO
| S_IWUSR
, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_CTL
),
432 static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv
*wil
,
433 struct dentry
*parent
)
435 struct dentry
*d
, *dtx
, *drx
;
437 d
= debugfs_create_dir("ITR_CNT", parent
);
438 if (IS_ERR_OR_NULL(d
))
441 dtx
= debugfs_create_dir("TX", d
);
442 drx
= debugfs_create_dir("RX", d
);
443 if (IS_ERR_OR_NULL(dtx
) || IS_ERR_OR_NULL(drx
))
446 wil6210_debugfs_init_offset(wil
, d
, (void * __force
)wil
->csr
,
449 wil6210_debugfs_init_offset(wil
, dtx
, (void * __force
)wil
->csr
,
452 wil6210_debugfs_init_offset(wil
, drx
, (void * __force
)wil
->csr
,
457 static int wil_memread_debugfs_show(struct seq_file
*s
, void *data
)
459 struct wil6210_priv
*wil
= s
->private;
460 void __iomem
*a
= wmi_buffer(wil
, cpu_to_le32(mem_addr
));
463 seq_printf(s
, "[0x%08x] = 0x%08x\n", mem_addr
, ioread32(a
));
465 seq_printf(s
, "[0x%08x] = INVALID\n", mem_addr
);
470 static int wil_memread_seq_open(struct inode
*inode
, struct file
*file
)
472 return single_open(file
, wil_memread_debugfs_show
, inode
->i_private
);
475 static const struct file_operations fops_memread
= {
476 .open
= wil_memread_seq_open
,
477 .release
= single_release
,
482 static ssize_t
wil_read_file_ioblob(struct file
*file
, char __user
*user_buf
,
483 size_t count
, loff_t
*ppos
)
485 enum { max_count
= 4096 };
486 struct debugfs_blob_wrapper
*blob
= file
->private_data
;
488 size_t available
= blob
->size
;
495 if (pos
>= available
|| !count
)
498 if (count
> available
- pos
)
499 count
= available
- pos
;
500 if (count
> max_count
)
503 buf
= kmalloc(count
, GFP_KERNEL
);
507 wil_memcpy_fromio_32(buf
, (const volatile void __iomem
*)blob
->data
+
510 ret
= copy_to_user(user_buf
, buf
, count
);
521 static const struct file_operations fops_ioblob
= {
522 .read
= wil_read_file_ioblob
,
524 .llseek
= default_llseek
,
528 struct dentry
*wil_debugfs_create_ioblob(const char *name
,
530 struct dentry
*parent
,
531 struct debugfs_blob_wrapper
*blob
)
533 return debugfs_create_file(name
, mode
, parent
, blob
, &fops_ioblob
);
537 static ssize_t
wil_write_file_reset(struct file
*file
, const char __user
*buf
,
538 size_t len
, loff_t
*ppos
)
540 struct wil6210_priv
*wil
= file
->private_data
;
541 struct net_device
*ndev
= wil_to_ndev(wil
);
545 * this code does NOT sync device state with the rest of system
546 * use with care, debug only!!!
550 ndev
->flags
&= ~IFF_UP
;
552 wil_reset(wil
, true);
557 static const struct file_operations fops_reset
= {
558 .write
= wil_write_file_reset
,
562 /*---write channel 1..4 to rxon for it, 0 to rxoff---*/
563 static ssize_t
wil_write_file_rxon(struct file
*file
, const char __user
*buf
,
564 size_t len
, loff_t
*ppos
)
566 struct wil6210_priv
*wil
= file
->private_data
;
571 char *kbuf
= kmalloc(len
+ 1, GFP_KERNEL
);
575 if (copy_from_user(kbuf
, buf
, len
)) {
581 rc
= kstrtol(kbuf
, 0, &channel
);
586 if ((channel
< 0) || (channel
> 4)) {
587 wil_err(wil
, "Invalid channel %ld\n", channel
);
593 rc
= wmi_set_channel(wil
, (int)channel
);
598 rc
= wmi_rxon(wil
, on
);
605 static const struct file_operations fops_rxon
= {
606 .write
= wil_write_file_rxon
,
610 /* block ack control, write:
611 * - "add <ringid> <agg_size> <timeout>" to trigger ADDBA
612 * - "del_tx <ringid> <reason>" to trigger DELBA for Tx side
613 * - "del_rx <CID> <TID> <reason>" to trigger DELBA for Rx side
615 static ssize_t
wil_write_back(struct file
*file
, const char __user
*buf
,
616 size_t len
, loff_t
*ppos
)
618 struct wil6210_priv
*wil
= file
->private_data
;
620 char *kbuf
= kmalloc(len
+ 1, GFP_KERNEL
);
627 rc
= simple_write_to_buffer(kbuf
, len
, ppos
, buf
, len
);
630 return rc
>= 0 ? -EIO
: rc
;
634 rc
= sscanf(kbuf
, "%8s %d %d %d", cmd
, &p1
, &p2
, &p3
);
642 if (0 == strcmp(cmd
, "add")) {
644 wil_err(wil
, "BACK: add require at least 2 params\n");
649 wmi_addba(wil
, p1
, p2
, p3
);
650 } else if (0 == strcmp(cmd
, "del_tx")) {
652 p2
= WLAN_REASON_QSTA_LEAVE_QBSS
;
653 wmi_delba_tx(wil
, p1
, p2
);
654 } else if (0 == strcmp(cmd
, "del_rx")) {
657 "BACK: del_rx require at least 2 params\n");
661 p3
= WLAN_REASON_QSTA_LEAVE_QBSS
;
662 wmi_delba_rx(wil
, mk_cidxtid(p1
, p2
), p3
);
664 wil_err(wil
, "BACK: Unrecognized command \"%s\"\n", cmd
);
671 static ssize_t
wil_read_back(struct file
*file
, char __user
*user_buf
,
672 size_t count
, loff_t
*ppos
)
674 static const char text
[] = "block ack control, write:\n"
675 " - \"add <ringid> <agg_size> <timeout>\" to trigger ADDBA\n"
676 "If missing, <timeout> defaults to 0\n"
677 " - \"del_tx <ringid> <reason>\" to trigger DELBA for Tx side\n"
678 " - \"del_rx <CID> <TID> <reason>\" to trigger DELBA for Rx side\n"
679 "If missing, <reason> set to \"STA_LEAVING\" (36)\n";
681 return simple_read_from_buffer(user_buf
, count
, ppos
, text
,
685 static const struct file_operations fops_back
= {
686 .read
= wil_read_back
,
687 .write
= wil_write_back
,
692 /* Write mgmt frame to this file to send it */
693 static ssize_t
wil_write_file_txmgmt(struct file
*file
, const char __user
*buf
,
694 size_t len
, loff_t
*ppos
)
696 struct wil6210_priv
*wil
= file
->private_data
;
697 struct wiphy
*wiphy
= wil_to_wiphy(wil
);
698 struct wireless_dev
*wdev
= wil_to_wdev(wil
);
699 struct cfg80211_mgmt_tx_params params
;
701 void *frame
= kmalloc(len
, GFP_KERNEL
);
706 if (copy_from_user(frame
, buf
, len
)) {
713 params
.chan
= wdev
->preset_chandef
.chan
;
715 rc
= wil_cfg80211_mgmt_tx(wiphy
, wdev
, ¶ms
, NULL
);
718 wil_info(wil
, "%s() -> %d\n", __func__
, rc
);
723 static const struct file_operations fops_txmgmt
= {
724 .write
= wil_write_file_txmgmt
,
728 /* Write WMI command (w/o mbox header) to this file to send it
729 * WMI starts from wil6210_mbox_hdr_wmi header
731 static ssize_t
wil_write_file_wmi(struct file
*file
, const char __user
*buf
,
732 size_t len
, loff_t
*ppos
)
734 struct wil6210_priv
*wil
= file
->private_data
;
735 struct wil6210_mbox_hdr_wmi
*wmi
;
737 int cmdlen
= len
- sizeof(struct wil6210_mbox_hdr_wmi
);
744 wmi
= kmalloc(len
, GFP_KERNEL
);
748 rc
= simple_write_to_buffer(wmi
, len
, ppos
, buf
, len
);
755 cmdid
= le16_to_cpu(wmi
->id
);
757 rc1
= wmi_send(wil
, cmdid
, cmd
, cmdlen
);
760 wil_info(wil
, "%s(0x%04x[%d]) -> %d\n", __func__
, cmdid
, cmdlen
, rc1
);
765 static const struct file_operations fops_wmi
= {
766 .write
= wil_write_file_wmi
,
770 static void wil_seq_hexdump(struct seq_file
*s
, void *p
, int len
,
773 char printbuf
[16 * 3 + 2];
777 int l
= min(len
- i
, 16);
779 hex_dump_to_buffer(p
+ i
, l
, 16, 1, printbuf
,
780 sizeof(printbuf
), false);
781 seq_printf(s
, "%s%s\n", prefix
, printbuf
);
786 static void wil_seq_print_skb(struct seq_file
*s
, struct sk_buff
*skb
)
789 int len
= skb_headlen(skb
);
791 int nr_frags
= skb_shinfo(skb
)->nr_frags
;
793 seq_printf(s
, " len = %d\n", len
);
794 wil_seq_hexdump(s
, p
, len
, " : ");
797 seq_printf(s
, " nr_frags = %d\n", nr_frags
);
798 for (i
= 0; i
< nr_frags
; i
++) {
799 const struct skb_frag_struct
*frag
=
800 &skb_shinfo(skb
)->frags
[i
];
802 len
= skb_frag_size(frag
);
803 p
= skb_frag_address_safe(frag
);
804 seq_printf(s
, " [%2d] : len = %d\n", i
, len
);
805 wil_seq_hexdump(s
, p
, len
, " : ");
810 /*---------Tx/Rx descriptor------------*/
811 static int wil_txdesc_debugfs_show(struct seq_file
*s
, void *data
)
813 struct wil6210_priv
*wil
= s
->private;
815 bool tx
= (dbg_vring_index
< WIL6210_MAX_TX_RINGS
);
817 vring
= tx
? &wil
->vring_tx
[dbg_vring_index
] : &wil
->vring_rx
;
821 seq_printf(s
, "No Tx[%2d] VRING\n", dbg_vring_index
);
823 seq_puts(s
, "No Rx VRING\n");
827 if (dbg_txdesc_index
< vring
->size
) {
828 /* use struct vring_tx_desc for Rx as well,
829 * only field used, .dma.length, is the same
831 volatile struct vring_tx_desc
*d
=
832 &vring
->va
[dbg_txdesc_index
].tx
;
833 volatile u32
*u
= (volatile u32
*)d
;
834 struct sk_buff
*skb
= vring
->ctx
[dbg_txdesc_index
].skb
;
837 seq_printf(s
, "Tx[%2d][%3d] = {\n", dbg_vring_index
,
840 seq_printf(s
, "Rx[%3d] = {\n", dbg_txdesc_index
);
841 seq_printf(s
, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
842 u
[0], u
[1], u
[2], u
[3]);
843 seq_printf(s
, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
844 u
[4], u
[5], u
[6], u
[7]);
845 seq_printf(s
, " SKB = 0x%p\n", skb
);
849 wil_seq_print_skb(s
, skb
);
855 seq_printf(s
, "[%2d] TxDesc index (%d) >= size (%d)\n",
856 dbg_vring_index
, dbg_txdesc_index
,
859 seq_printf(s
, "RxDesc index (%d) >= size (%d)\n",
860 dbg_txdesc_index
, vring
->size
);
866 static int wil_txdesc_seq_open(struct inode
*inode
, struct file
*file
)
868 return single_open(file
, wil_txdesc_debugfs_show
, inode
->i_private
);
871 static const struct file_operations fops_txdesc
= {
872 .open
= wil_txdesc_seq_open
,
873 .release
= single_release
,
878 /*---------beamforming------------*/
879 static char *wil_bfstatus_str(u32 status
)
893 static bool is_all_zeros(void * const x_
, size_t sz
)
895 /* if reply is all-0, ignore this CID */
899 for (n
= 0; n
< sz
/ sizeof(*x
); n
++)
906 static int wil_bf_debugfs_show(struct seq_file
*s
, void *data
)
910 struct wil6210_priv
*wil
= s
->private;
911 struct wmi_notify_req_cmd cmd
= {
915 struct wil6210_mbox_hdr_wmi wmi
;
916 struct wmi_notify_req_done_event evt
;
919 for (i
= 0; i
< ARRAY_SIZE(wil
->sta
); i
++) {
923 rc
= wmi_call(wil
, WMI_NOTIFY_REQ_CMDID
, &cmd
, sizeof(cmd
),
924 WMI_NOTIFY_REQ_DONE_EVENTID
, &reply
,
926 /* if reply is all-0, ignore this CID */
927 if (rc
|| is_all_zeros(&reply
.evt
, sizeof(reply
.evt
)))
930 status
= le32_to_cpu(reply
.evt
.status
);
931 seq_printf(s
, "CID %d {\n"
933 " TxMCS = %2d TxTpt = %4d\n"
935 " Status = 0x%08x %s\n"
936 " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
937 " Goodput(rx:tx) %4d:%4d\n"
940 le64_to_cpu(reply
.evt
.tsf
),
941 le16_to_cpu(reply
.evt
.bf_mcs
),
942 le32_to_cpu(reply
.evt
.tx_tpt
),
944 status
, wil_bfstatus_str(status
),
945 le16_to_cpu(reply
.evt
.my_rx_sector
),
946 le16_to_cpu(reply
.evt
.my_tx_sector
),
947 le16_to_cpu(reply
.evt
.other_rx_sector
),
948 le16_to_cpu(reply
.evt
.other_tx_sector
),
949 le32_to_cpu(reply
.evt
.rx_goodput
),
950 le32_to_cpu(reply
.evt
.tx_goodput
));
955 static int wil_bf_seq_open(struct inode
*inode
, struct file
*file
)
957 return single_open(file
, wil_bf_debugfs_show
, inode
->i_private
);
960 static const struct file_operations fops_bf
= {
961 .open
= wil_bf_seq_open
,
962 .release
= single_release
,
967 /*---------SSID------------*/
968 static ssize_t
wil_read_file_ssid(struct file
*file
, char __user
*user_buf
,
969 size_t count
, loff_t
*ppos
)
971 struct wil6210_priv
*wil
= file
->private_data
;
972 struct wireless_dev
*wdev
= wil_to_wdev(wil
);
974 return simple_read_from_buffer(user_buf
, count
, ppos
,
975 wdev
->ssid
, wdev
->ssid_len
);
978 static ssize_t
wil_write_file_ssid(struct file
*file
, const char __user
*buf
,
979 size_t count
, loff_t
*ppos
)
981 struct wil6210_priv
*wil
= file
->private_data
;
982 struct wireless_dev
*wdev
= wil_to_wdev(wil
);
983 struct net_device
*ndev
= wil_to_ndev(wil
);
986 wil_err(wil
, "Unable to set SSID substring from [%d]\n",
991 if (count
> sizeof(wdev
->ssid
)) {
992 wil_err(wil
, "SSID too long, len = %d\n", (int)count
);
995 if (netif_running(ndev
)) {
996 wil_err(wil
, "Unable to change SSID on running interface\n");
1000 wdev
->ssid_len
= count
;
1001 return simple_write_to_buffer(wdev
->ssid
, wdev
->ssid_len
, ppos
,
1005 static const struct file_operations fops_ssid
= {
1006 .read
= wil_read_file_ssid
,
1007 .write
= wil_write_file_ssid
,
1008 .open
= simple_open
,
1011 /*---------temp------------*/
1012 static void print_temp(struct seq_file
*s
, const char *prefix
, u32 t
)
1017 seq_printf(s
, "%s N/A\n", prefix
);
1020 seq_printf(s
, "%s %d.%03d\n", prefix
, t
/ 1000, t
% 1000);
1025 static int wil_temp_debugfs_show(struct seq_file
*s
, void *data
)
1027 struct wil6210_priv
*wil
= s
->private;
1029 int rc
= wmi_get_temperature(wil
, &t_m
, &t_r
);
1032 seq_puts(s
, "Failed\n");
1036 print_temp(s
, "T_mac =", t_m
);
1037 print_temp(s
, "T_radio =", t_r
);
1042 static int wil_temp_seq_open(struct inode
*inode
, struct file
*file
)
1044 return single_open(file
, wil_temp_debugfs_show
, inode
->i_private
);
1047 static const struct file_operations fops_temp
= {
1048 .open
= wil_temp_seq_open
,
1049 .release
= single_release
,
1051 .llseek
= seq_lseek
,
1054 /*---------freq------------*/
1055 static int wil_freq_debugfs_show(struct seq_file
*s
, void *data
)
1057 struct wil6210_priv
*wil
= s
->private;
1058 struct wireless_dev
*wdev
= wil_to_wdev(wil
);
1059 u16 freq
= wdev
->chandef
.chan
? wdev
->chandef
.chan
->center_freq
: 0;
1061 seq_printf(s
, "Freq = %d\n", freq
);
1066 static int wil_freq_seq_open(struct inode
*inode
, struct file
*file
)
1068 return single_open(file
, wil_freq_debugfs_show
, inode
->i_private
);
1071 static const struct file_operations fops_freq
= {
1072 .open
= wil_freq_seq_open
,
1073 .release
= single_release
,
1075 .llseek
= seq_lseek
,
1078 /*---------link------------*/
1079 static int wil_link_debugfs_show(struct seq_file
*s
, void *data
)
1081 struct wil6210_priv
*wil
= s
->private;
1082 struct station_info sinfo
;
1085 for (i
= 0; i
< ARRAY_SIZE(wil
->sta
); i
++) {
1086 struct wil_sta_info
*p
= &wil
->sta
[i
];
1087 char *status
= "unknown";
1089 switch (p
->status
) {
1090 case wil_sta_unused
:
1093 case wil_sta_conn_pending
:
1094 status
= "pending ";
1096 case wil_sta_connected
:
1097 status
= "connected";
1100 seq_printf(s
, "[%d] %pM %s%s\n", i
, p
->addr
, status
,
1101 (p
->data_port_open
? " data_port_open" : ""));
1103 if (p
->status
== wil_sta_connected
) {
1104 rc
= wil_cid_fill_sinfo(wil
, i
, &sinfo
);
1108 seq_printf(s
, " Tx_mcs = %d\n", sinfo
.txrate
.mcs
);
1109 seq_printf(s
, " Rx_mcs = %d\n", sinfo
.rxrate
.mcs
);
1110 seq_printf(s
, " SQ = %d\n", sinfo
.signal
);
1117 static int wil_link_seq_open(struct inode
*inode
, struct file
*file
)
1119 return single_open(file
, wil_link_debugfs_show
, inode
->i_private
);
1122 static const struct file_operations fops_link
= {
1123 .open
= wil_link_seq_open
,
1124 .release
= single_release
,
1126 .llseek
= seq_lseek
,
1129 /*---------info------------*/
1130 static int wil_info_debugfs_show(struct seq_file
*s
, void *data
)
1132 struct wil6210_priv
*wil
= s
->private;
1133 struct net_device
*ndev
= wil_to_ndev(wil
);
1134 int is_ac
= power_supply_is_system_supplied();
1135 int rx
= atomic_xchg(&wil
->isr_count_rx
, 0);
1136 int tx
= atomic_xchg(&wil
->isr_count_tx
, 0);
1137 static ulong rxf_old
, txf_old
;
1138 ulong rxf
= ndev
->stats
.rx_packets
;
1139 ulong txf
= ndev
->stats
.tx_packets
;
1142 /* >0 : AC; 0 : battery; <0 : error */
1143 seq_printf(s
, "AC powered : %d\n", is_ac
);
1144 seq_printf(s
, "Rx irqs:packets : %8d : %8ld\n", rx
, rxf
- rxf_old
);
1145 seq_printf(s
, "Tx irqs:packets : %8d : %8ld\n", tx
, txf
- txf_old
);
1149 #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
1150 " " __stringify(x) : ""
1152 for (i
= 0; i
< ndev
->num_tx_queues
; i
++) {
1153 struct netdev_queue
*txq
= netdev_get_tx_queue(ndev
, i
);
1154 unsigned long state
= txq
->state
;
1156 seq_printf(s
, "Tx queue[%i] state : 0x%lx%s%s%s\n", i
, state
,
1157 CHECK_QSTATE(DRV_XOFF
),
1158 CHECK_QSTATE(STACK_XOFF
),
1159 CHECK_QSTATE(FROZEN
)
1166 static int wil_info_seq_open(struct inode
*inode
, struct file
*file
)
1168 return single_open(file
, wil_info_debugfs_show
, inode
->i_private
);
1171 static const struct file_operations fops_info
= {
1172 .open
= wil_info_seq_open
,
1173 .release
= single_release
,
1175 .llseek
= seq_lseek
,
1178 /*---------recovery------------*/
1179 /* mode = [manual|auto]
1180 * state = [idle|pending|running]
1182 static ssize_t
wil_read_file_recovery(struct file
*file
, char __user
*user_buf
,
1183 size_t count
, loff_t
*ppos
)
1185 struct wil6210_priv
*wil
= file
->private_data
;
1188 static const char * const sstate
[] = {"idle", "pending", "running"};
1190 n
= snprintf(buf
, sizeof(buf
), "mode = %s\nstate = %s\n",
1191 no_fw_recovery
? "manual" : "auto",
1192 sstate
[wil
->recovery_state
]);
1194 n
= min_t(int, n
, sizeof(buf
));
1196 return simple_read_from_buffer(user_buf
, count
, ppos
,
1200 static ssize_t
wil_write_file_recovery(struct file
*file
,
1201 const char __user
*buf_
,
1202 size_t count
, loff_t
*ppos
)
1204 struct wil6210_priv
*wil
= file
->private_data
;
1205 static const char run_command
[] = "run";
1206 char buf
[sizeof(run_command
) + 1]; /* to detect "runx" */
1209 if (wil
->recovery_state
!= fw_recovery_pending
) {
1210 wil_err(wil
, "No recovery pending\n");
1215 wil_err(wil
, "Offset [%d]\n", (int)*ppos
);
1219 if (count
> sizeof(buf
)) {
1220 wil_err(wil
, "Input too long, len = %d\n", (int)count
);
1224 rc
= simple_write_to_buffer(buf
, sizeof(buf
) - 1, ppos
, buf_
, count
);
1229 if (0 == strcmp(buf
, run_command
))
1230 wil_set_recovery_state(wil
, fw_recovery_running
);
1232 wil_err(wil
, "Bad recovery command \"%s\"\n", buf
);
1237 static const struct file_operations fops_recovery
= {
1238 .read
= wil_read_file_recovery
,
1239 .write
= wil_write_file_recovery
,
1240 .open
= simple_open
,
1243 /*---------Station matrix------------*/
1244 static void wil_print_rxtid(struct seq_file
*s
, struct wil_tid_ampdu_rx
*r
)
1247 u16 index
= ((r
->head_seq_num
- r
->ssn
) & 0xfff) % r
->buf_size
;
1249 seq_printf(s
, "([%2d] %3d TU) 0x%03x [", r
->buf_size
, r
->timeout
,
1251 for (i
= 0; i
< r
->buf_size
; i
++) {
1253 seq_printf(s
, "%c", r
->reorder_buf
[i
] ? 'O' : '|');
1255 seq_printf(s
, "%c", r
->reorder_buf
[i
] ? '*' : '_');
1257 seq_printf(s
, "] last drop 0x%03x\n", r
->ssn_last_drop
);
1260 static int wil_sta_debugfs_show(struct seq_file
*s
, void *data
)
1261 __acquires(&p
->tid_rx_lock
) __releases(&p
->tid_rx_lock
)
1263 struct wil6210_priv
*wil
= s
->private;
1266 for (i
= 0; i
< ARRAY_SIZE(wil
->sta
); i
++) {
1267 struct wil_sta_info
*p
= &wil
->sta
[i
];
1268 char *status
= "unknown";
1270 switch (p
->status
) {
1271 case wil_sta_unused
:
1274 case wil_sta_conn_pending
:
1275 status
= "pending ";
1277 case wil_sta_connected
:
1278 status
= "connected";
1281 seq_printf(s
, "[%d] %pM %s%s\n", i
, p
->addr
, status
,
1282 (p
->data_port_open
? " data_port_open" : ""));
1284 if (p
->status
== wil_sta_connected
) {
1285 spin_lock_bh(&p
->tid_rx_lock
);
1286 for (tid
= 0; tid
< WIL_STA_TID_NUM
; tid
++) {
1287 struct wil_tid_ampdu_rx
*r
= p
->tid_rx
[tid
];
1290 seq_printf(s
, "[%2d] ", tid
);
1291 wil_print_rxtid(s
, r
);
1294 spin_unlock_bh(&p
->tid_rx_lock
);
1301 static int wil_sta_seq_open(struct inode
*inode
, struct file
*file
)
1303 return single_open(file
, wil_sta_debugfs_show
, inode
->i_private
);
1306 static const struct file_operations fops_sta
= {
1307 .open
= wil_sta_seq_open
,
1308 .release
= single_release
,
1310 .llseek
= seq_lseek
,
1313 /*----------------*/
1314 static void wil6210_debugfs_init_blobs(struct wil6210_priv
*wil
,
1320 for (i
= 0; i
< ARRAY_SIZE(fw_mapping
); i
++) {
1321 struct debugfs_blob_wrapper
*blob
= &wil
->blobs
[i
];
1322 const struct fw_map
*map
= &fw_mapping
[i
];
1327 blob
->data
= (void * __force
)wil
->csr
+ HOSTADDR(map
->host
);
1328 blob
->size
= map
->to
- map
->from
;
1329 snprintf(name
, sizeof(name
), "blob_%s", map
->name
);
1330 wil_debugfs_create_ioblob(name
, S_IRUGO
, dbg
, blob
);
1335 static const struct {
1338 const struct file_operations
*fops
;
1340 {"mbox", S_IRUGO
, &fops_mbox
},
1341 {"vrings", S_IRUGO
, &fops_vring
},
1342 {"stations", S_IRUGO
, &fops_sta
},
1343 {"desc", S_IRUGO
, &fops_txdesc
},
1344 {"bf", S_IRUGO
, &fops_bf
},
1345 {"ssid", S_IRUGO
| S_IWUSR
, &fops_ssid
},
1346 {"mem_val", S_IRUGO
, &fops_memread
},
1347 {"reset", S_IWUSR
, &fops_reset
},
1348 {"rxon", S_IWUSR
, &fops_rxon
},
1349 {"tx_mgmt", S_IWUSR
, &fops_txmgmt
},
1350 {"wmi_send", S_IWUSR
, &fops_wmi
},
1351 {"back", S_IRUGO
| S_IWUSR
, &fops_back
},
1352 {"temp", S_IRUGO
, &fops_temp
},
1353 {"freq", S_IRUGO
, &fops_freq
},
1354 {"link", S_IRUGO
, &fops_link
},
1355 {"info", S_IRUGO
, &fops_info
},
1356 {"recovery", S_IRUGO
| S_IWUSR
, &fops_recovery
},
1359 static void wil6210_debugfs_init_files(struct wil6210_priv
*wil
,
1364 for (i
= 0; i
< ARRAY_SIZE(dbg_files
); i
++)
1365 debugfs_create_file(dbg_files
[i
].name
, dbg_files
[i
].mode
, dbg
,
1366 wil
, dbg_files
[i
].fops
);
1369 /* interrupt control blocks */
1370 static const struct {
1374 {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR
)},
1375 {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR
)},
1376 {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR
)},
1377 {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR
)},
1380 static void wil6210_debugfs_init_isr(struct wil6210_priv
*wil
,
1385 for (i
= 0; i
< ARRAY_SIZE(dbg_icr
); i
++)
1386 wil6210_debugfs_create_ISR(wil
, dbg_icr
[i
].name
, dbg
,
1387 dbg_icr
[i
].icr_off
);
1390 #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
1391 offsetof(struct wil6210_priv, name), type}
1393 /* fields in struct wil6210_priv */
1394 static const struct dbg_off dbg_wil_off
[] = {
1395 WIL_FIELD(secure_pcp
, S_IRUGO
| S_IWUSR
, doff_u32
),
1396 WIL_FIELD(status
[0], S_IRUGO
| S_IWUSR
, doff_ulong
),
1397 WIL_FIELD(fw_version
, S_IRUGO
, doff_u32
),
1398 WIL_FIELD(hw_version
, S_IRUGO
, doff_x32
),
1399 WIL_FIELD(recovery_count
, S_IRUGO
, doff_u32
),
1403 static const struct dbg_off dbg_wil_regs
[] = {
1404 {"RGF_MAC_MTRL_COUNTER_0", S_IRUGO
, HOSTADDR(RGF_MAC_MTRL_COUNTER_0
),
1406 {"RGF_USER_USAGE_1", S_IRUGO
, HOSTADDR(RGF_USER_USAGE_1
), doff_io32
},
1410 /* static parameters */
1411 static const struct dbg_off dbg_statics
[] = {
1412 {"desc_index", S_IRUGO
| S_IWUSR
, (ulong
)&dbg_txdesc_index
, doff_u32
},
1413 {"vring_index", S_IRUGO
| S_IWUSR
, (ulong
)&dbg_vring_index
, doff_u32
},
1414 {"mem_addr", S_IRUGO
| S_IWUSR
, (ulong
)&mem_addr
, doff_u32
},
1418 int wil6210_debugfs_init(struct wil6210_priv
*wil
)
1420 struct dentry
*dbg
= wil
->debug
= debugfs_create_dir(WIL_NAME
,
1421 wil_to_wiphy(wil
)->debugfsdir
);
1423 if (IS_ERR_OR_NULL(dbg
))
1426 wil6210_debugfs_init_files(wil
, dbg
);
1427 wil6210_debugfs_init_isr(wil
, dbg
);
1428 wil6210_debugfs_init_blobs(wil
, dbg
);
1429 wil6210_debugfs_init_offset(wil
, dbg
, wil
, dbg_wil_off
);
1430 wil6210_debugfs_init_offset(wil
, dbg
, (void * __force
)wil
->csr
,
1432 wil6210_debugfs_init_offset(wil
, dbg
, NULL
, dbg_statics
);
1434 wil6210_debugfs_create_pseudo_ISR(wil
, dbg
);
1436 wil6210_debugfs_create_ITR_CNT(wil
, dbg
);
1441 void wil6210_debugfs_remove(struct wil6210_priv
*wil
)
1443 debugfs_remove_recursive(wil
->debug
);