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>
27 /* Nasty hack. Better have per device instances */
29 static u32 dbg_txdesc_index
;
30 static u32 dbg_vring_index
; /* 24+ for Rx, 0..23 for Tx */
44 enum dbg_off_type type
;
47 static void wil_print_vring(struct seq_file
*s
, struct wil6210_priv
*wil
,
48 const char *name
, struct vring
*vring
,
51 void __iomem
*x
= wmi_addr(wil
, vring
->hwtail
);
53 seq_printf(s
, "VRING %s = {\n", name
);
54 seq_printf(s
, " pa = %pad\n", &vring
->pa
);
55 seq_printf(s
, " va = 0x%p\n", vring
->va
);
56 seq_printf(s
, " size = %d\n", vring
->size
);
57 seq_printf(s
, " swtail = %d\n", vring
->swtail
);
58 seq_printf(s
, " swhead = %d\n", vring
->swhead
);
59 seq_printf(s
, " hwtail = [0x%08x] -> ", vring
->hwtail
);
61 seq_printf(s
, "0x%08x\n", ioread32(x
));
63 seq_printf(s
, "???\n");
65 if (vring
->va
&& (vring
->size
< 1025)) {
67 for (i
= 0; i
< vring
->size
; i
++) {
68 volatile struct vring_tx_desc
*d
= &vring
->va
[i
].tx
;
69 if ((i
% 64) == 0 && (i
!= 0))
71 seq_printf(s
, "%c", (d
->dma
.status
& BIT(0)) ?
72 _s
: (vring
->ctx
[i
].skb
? _h
: 'h'));
79 static int wil_vring_debugfs_show(struct seq_file
*s
, void *data
)
82 struct wil6210_priv
*wil
= s
->private;
84 wil_print_vring(s
, wil
, "rx", &wil
->vring_rx
, 'S', '_');
86 for (i
= 0; i
< ARRAY_SIZE(wil
->vring_tx
); i
++) {
87 struct vring
*vring
= &(wil
->vring_tx
[i
]);
88 struct vring_tx_data
*txdata
= &wil
->vring_tx_data
[i
];
91 int cid
= wil
->vring2cid_tid
[i
][0];
92 int tid
= wil
->vring2cid_tid
[i
][1];
93 u32 swhead
= vring
->swhead
;
94 u32 swtail
= vring
->swtail
;
95 int used
= (vring
->size
+ swhead
- swtail
)
97 int avail
= vring
->size
- used
- 1;
99 /* performance monitoring */
100 cycles_t now
= get_cycles();
101 cycles_t idle
= txdata
->idle
* 100;
102 cycles_t total
= now
- txdata
->begin
;
108 snprintf(name
, sizeof(name
), "tx_%2d", i
);
110 seq_printf(s
, "\n%pM CID %d TID %d [%3d|%3d] idle %3d%%\n",
111 wil
->sta
[cid
].addr
, cid
, tid
, used
, avail
,
114 wil_print_vring(s
, wil
, name
, vring
, '_', 'H');
121 static int wil_vring_seq_open(struct inode
*inode
, struct file
*file
)
123 return single_open(file
, wil_vring_debugfs_show
, inode
->i_private
);
126 static const struct file_operations fops_vring
= {
127 .open
= wil_vring_seq_open
,
128 .release
= single_release
,
133 static void wil_print_ring(struct seq_file
*s
, const char *prefix
,
136 struct wil6210_priv
*wil
= s
->private;
137 struct wil6210_mbox_ring r
;
141 wil_memcpy_fromio_32(&r
, off
, sizeof(r
));
142 wil_mbox_ring_le2cpus(&r
);
144 * we just read memory block from NIC. This memory may be
145 * garbage. Check validity before using it.
147 rsize
= r
.size
/ sizeof(struct wil6210_mbox_ring_desc
);
149 seq_printf(s
, "ring %s = {\n", prefix
);
150 seq_printf(s
, " base = 0x%08x\n", r
.base
);
151 seq_printf(s
, " size = 0x%04x bytes -> %d entries\n", r
.size
, rsize
);
152 seq_printf(s
, " tail = 0x%08x\n", r
.tail
);
153 seq_printf(s
, " head = 0x%08x\n", r
.head
);
154 seq_printf(s
, " entry size = %d\n", r
.entry_size
);
156 if (r
.size
% sizeof(struct wil6210_mbox_ring_desc
)) {
157 seq_printf(s
, " ??? size is not multiple of %zd, garbage?\n",
158 sizeof(struct wil6210_mbox_ring_desc
));
162 if (!wmi_addr(wil
, r
.base
) ||
163 !wmi_addr(wil
, r
.tail
) ||
164 !wmi_addr(wil
, r
.head
)) {
165 seq_printf(s
, " ??? pointers are garbage?\n");
169 for (i
= 0; i
< rsize
; i
++) {
170 struct wil6210_mbox_ring_desc d
;
171 struct wil6210_mbox_hdr hdr
;
172 size_t delta
= i
* sizeof(d
);
173 void __iomem
*x
= wil
->csr
+ HOSTADDR(r
.base
) + delta
;
175 wil_memcpy_fromio_32(&d
, x
, sizeof(d
));
177 seq_printf(s
, " [%2x] %s %s%s 0x%08x", i
,
179 (r
.tail
- r
.base
== delta
) ? "t" : " ",
180 (r
.head
- r
.base
== delta
) ? "h" : " ",
181 le32_to_cpu(d
.addr
));
182 if (0 == wmi_read_hdr(wil
, d
.addr
, &hdr
)) {
183 u16 len
= le16_to_cpu(hdr
.len
);
184 seq_printf(s
, " -> %04x %04x %04x %02x\n",
185 le16_to_cpu(hdr
.seq
), len
,
186 le16_to_cpu(hdr
.type
), hdr
.flags
);
187 if (len
<= MAX_MBOXITEM_SIZE
) {
189 char printbuf
[16 * 3 + 2];
190 unsigned char databuf
[MAX_MBOXITEM_SIZE
];
191 void __iomem
*src
= wmi_buffer(wil
, d
.addr
) +
192 sizeof(struct wil6210_mbox_hdr
);
194 * No need to check @src for validity -
195 * we already validated @d.addr while
198 wil_memcpy_fromio_32(databuf
, src
, len
);
200 int l
= min(len
- n
, 16);
201 hex_dump_to_buffer(databuf
+ n
, l
,
205 seq_printf(s
, " : %s\n", printbuf
);
214 seq_printf(s
, "}\n");
217 static int wil_mbox_debugfs_show(struct seq_file
*s
, void *data
)
219 struct wil6210_priv
*wil
= s
->private;
221 wil_print_ring(s
, "tx", wil
->csr
+ HOST_MBOX
+
222 offsetof(struct wil6210_mbox_ctl
, tx
));
223 wil_print_ring(s
, "rx", wil
->csr
+ HOST_MBOX
+
224 offsetof(struct wil6210_mbox_ctl
, rx
));
229 static int wil_mbox_seq_open(struct inode
*inode
, struct file
*file
)
231 return single_open(file
, wil_mbox_debugfs_show
, inode
->i_private
);
234 static const struct file_operations fops_mbox
= {
235 .open
= wil_mbox_seq_open
,
236 .release
= single_release
,
241 static int wil_debugfs_iomem_x32_set(void *data
, u64 val
)
243 iowrite32(val
, (void __iomem
*)data
);
244 wmb(); /* make sure write propagated to HW */
249 static int wil_debugfs_iomem_x32_get(void *data
, u64
*val
)
251 *val
= ioread32((void __iomem
*)data
);
256 DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32
, wil_debugfs_iomem_x32_get
,
257 wil_debugfs_iomem_x32_set
, "0x%08llx\n");
259 static struct dentry
*wil_debugfs_create_iomem_x32(const char *name
,
261 struct dentry
*parent
,
264 return debugfs_create_file(name
, mode
, parent
, value
,
268 static int wil_debugfs_ulong_set(void *data
, u64 val
)
270 *(ulong
*)data
= val
;
273 static int wil_debugfs_ulong_get(void *data
, u64
*val
)
275 *val
= *(ulong
*)data
;
278 DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong
, wil_debugfs_ulong_get
,
279 wil_debugfs_ulong_set
, "%llu\n");
281 static struct dentry
*wil_debugfs_create_ulong(const char *name
, umode_t mode
,
282 struct dentry
*parent
,
285 return debugfs_create_file(name
, mode
, parent
, value
, &wil_fops_ulong
);
289 * wil6210_debugfs_init_offset - create set of debugfs files
290 * @wil - driver's context, used for printing
291 * @dbg - directory on the debugfs, where files will be created
292 * @base - base address used in address calculation
293 * @tbl - table with file descriptions. Should be terminated with empty element.
295 * Creates files accordingly to the @tbl.
297 static void wil6210_debugfs_init_offset(struct wil6210_priv
*wil
,
298 struct dentry
*dbg
, void *base
,
299 const struct dbg_off
* const tbl
)
303 for (i
= 0; tbl
[i
].name
; i
++) {
304 struct dentry
*f
= NULL
;
306 switch (tbl
[i
].type
) {
308 f
= debugfs_create_u32(tbl
[i
].name
, tbl
[i
].mode
, dbg
,
312 f
= debugfs_create_x32(tbl
[i
].name
, tbl
[i
].mode
, dbg
,
316 f
= wil_debugfs_create_ulong(tbl
[i
].name
, tbl
[i
].mode
,
317 dbg
, base
+ tbl
[i
].off
);
320 f
= wil_debugfs_create_iomem_x32(tbl
[i
].name
,
325 if (IS_ERR_OR_NULL(f
))
326 wil_err(wil
, "Create file \"%s\": err %ld\n",
327 tbl
[i
].name
, PTR_ERR(f
));
331 static const struct dbg_off isr_off
[] = {
332 {"ICC", S_IRUGO
| S_IWUSR
, offsetof(struct RGF_ICR
, ICC
), doff_io32
},
333 {"ICR", S_IRUGO
| S_IWUSR
, offsetof(struct RGF_ICR
, ICR
), doff_io32
},
334 {"ICM", S_IRUGO
| S_IWUSR
, offsetof(struct RGF_ICR
, ICM
), doff_io32
},
335 {"ICS", S_IWUSR
, offsetof(struct RGF_ICR
, ICS
), doff_io32
},
336 {"IMV", S_IRUGO
| S_IWUSR
, offsetof(struct RGF_ICR
, IMV
), doff_io32
},
337 {"IMS", S_IWUSR
, offsetof(struct RGF_ICR
, IMS
), doff_io32
},
338 {"IMC", S_IWUSR
, offsetof(struct RGF_ICR
, IMC
), doff_io32
},
341 static int wil6210_debugfs_create_ISR(struct wil6210_priv
*wil
,
343 struct dentry
*parent
, u32 off
)
345 struct dentry
*d
= debugfs_create_dir(name
, parent
);
347 if (IS_ERR_OR_NULL(d
))
350 wil6210_debugfs_init_offset(wil
, d
, (void * __force
)wil
->csr
+ off
,
356 static const struct dbg_off pseudo_isr_off
[] = {
357 {"CAUSE", S_IRUGO
, HOSTADDR(RGF_DMA_PSEUDO_CAUSE
), doff_io32
},
358 {"MASK_SW", S_IRUGO
, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW
), doff_io32
},
359 {"MASK_FW", S_IRUGO
, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW
), doff_io32
},
363 static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv
*wil
,
364 struct dentry
*parent
)
366 struct dentry
*d
= debugfs_create_dir("PSEUDO_ISR", parent
);
368 if (IS_ERR_OR_NULL(d
))
371 wil6210_debugfs_init_offset(wil
, d
, (void * __force
)wil
->csr
,
377 static const struct dbg_off itr_cnt_off
[] = {
378 {"TRSH", S_IRUGO
| S_IWUSR
, HOSTADDR(RGF_DMA_ITR_CNT_TRSH
), doff_io32
},
379 {"DATA", S_IRUGO
| S_IWUSR
, HOSTADDR(RGF_DMA_ITR_CNT_DATA
), doff_io32
},
380 {"CTL", S_IRUGO
| S_IWUSR
, HOSTADDR(RGF_DMA_ITR_CNT_CRL
), doff_io32
},
384 static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv
*wil
,
385 struct dentry
*parent
)
387 struct dentry
*d
= debugfs_create_dir("ITR_CNT", parent
);
389 if (IS_ERR_OR_NULL(d
))
392 wil6210_debugfs_init_offset(wil
, d
, (void * __force
)wil
->csr
,
398 static int wil_memread_debugfs_show(struct seq_file
*s
, void *data
)
400 struct wil6210_priv
*wil
= s
->private;
401 void __iomem
*a
= wmi_buffer(wil
, cpu_to_le32(mem_addr
));
404 seq_printf(s
, "[0x%08x] = 0x%08x\n", mem_addr
, ioread32(a
));
406 seq_printf(s
, "[0x%08x] = INVALID\n", mem_addr
);
411 static int wil_memread_seq_open(struct inode
*inode
, struct file
*file
)
413 return single_open(file
, wil_memread_debugfs_show
, inode
->i_private
);
416 static const struct file_operations fops_memread
= {
417 .open
= wil_memread_seq_open
,
418 .release
= single_release
,
423 static ssize_t
wil_read_file_ioblob(struct file
*file
, char __user
*user_buf
,
424 size_t count
, loff_t
*ppos
)
426 enum { max_count
= 4096 };
427 struct debugfs_blob_wrapper
*blob
= file
->private_data
;
429 size_t available
= blob
->size
;
436 if (pos
>= available
|| !count
)
439 if (count
> available
- pos
)
440 count
= available
- pos
;
441 if (count
> max_count
)
444 buf
= kmalloc(count
, GFP_KERNEL
);
448 wil_memcpy_fromio_32(buf
, (const volatile void __iomem
*)blob
->data
+
451 ret
= copy_to_user(user_buf
, buf
, count
);
462 static const struct file_operations fops_ioblob
= {
463 .read
= wil_read_file_ioblob
,
465 .llseek
= default_llseek
,
469 struct dentry
*wil_debugfs_create_ioblob(const char *name
,
471 struct dentry
*parent
,
472 struct debugfs_blob_wrapper
*blob
)
474 return debugfs_create_file(name
, mode
, parent
, blob
, &fops_ioblob
);
477 static ssize_t
wil_write_file_reset(struct file
*file
, const char __user
*buf
,
478 size_t len
, loff_t
*ppos
)
480 struct wil6210_priv
*wil
= file
->private_data
;
481 struct net_device
*ndev
= wil_to_ndev(wil
);
485 * this code does NOT sync device state with the rest of system
486 * use with care, debug only!!!
490 ndev
->flags
&= ~IFF_UP
;
497 static const struct file_operations fops_reset
= {
498 .write
= wil_write_file_reset
,
501 /*---write channel 1..4 to rxon for it, 0 to rxoff---*/
502 static ssize_t
wil_write_file_rxon(struct file
*file
, const char __user
*buf
,
503 size_t len
, loff_t
*ppos
)
505 struct wil6210_priv
*wil
= file
->private_data
;
510 char *kbuf
= kmalloc(len
+ 1, GFP_KERNEL
);
513 if (copy_from_user(kbuf
, buf
, len
)) {
519 rc
= kstrtol(kbuf
, 0, &channel
);
524 if ((channel
< 0) || (channel
> 4)) {
525 wil_err(wil
, "Invalid channel %ld\n", channel
);
531 rc
= wmi_set_channel(wil
, (int)channel
);
536 rc
= wmi_rxon(wil
, on
);
543 static const struct file_operations fops_rxon
= {
544 .write
= wil_write_file_rxon
,
548 /* Write mgmt frame to this file to send it */
549 static ssize_t
wil_write_file_txmgmt(struct file
*file
, const char __user
*buf
,
550 size_t len
, loff_t
*ppos
)
552 struct wil6210_priv
*wil
= file
->private_data
;
553 struct wiphy
*wiphy
= wil_to_wiphy(wil
);
554 struct wireless_dev
*wdev
= wil_to_wdev(wil
);
555 struct cfg80211_mgmt_tx_params params
;
558 void *frame
= kmalloc(len
, GFP_KERNEL
);
562 if (copy_from_user(frame
, buf
, len
))
567 params
.chan
= wdev
->preset_chandef
.chan
;
569 rc
= wil_cfg80211_mgmt_tx(wiphy
, wdev
, ¶ms
, NULL
);
572 wil_info(wil
, "%s() -> %d\n", __func__
, rc
);
577 static const struct file_operations fops_txmgmt
= {
578 .write
= wil_write_file_txmgmt
,
582 /* Write WMI command (w/o mbox header) to this file to send it
583 * WMI starts from wil6210_mbox_hdr_wmi header
585 static ssize_t
wil_write_file_wmi(struct file
*file
, const char __user
*buf
,
586 size_t len
, loff_t
*ppos
)
588 struct wil6210_priv
*wil
= file
->private_data
;
589 struct wil6210_mbox_hdr_wmi
*wmi
;
591 int cmdlen
= len
- sizeof(struct wil6210_mbox_hdr_wmi
);
598 wmi
= kmalloc(len
, GFP_KERNEL
);
602 rc
= simple_write_to_buffer(wmi
, len
, ppos
, buf
, len
);
607 cmdid
= le16_to_cpu(wmi
->id
);
609 rc1
= wmi_send(wil
, cmdid
, cmd
, cmdlen
);
612 wil_info(wil
, "%s(0x%04x[%d]) -> %d\n", __func__
, cmdid
, cmdlen
, rc1
);
617 static const struct file_operations fops_wmi
= {
618 .write
= wil_write_file_wmi
,
622 static void wil_seq_hexdump(struct seq_file
*s
, void *p
, int len
,
625 char printbuf
[16 * 3 + 2];
628 int l
= min(len
- i
, 16);
629 hex_dump_to_buffer(p
+ i
, l
, 16, 1, printbuf
,
630 sizeof(printbuf
), false);
631 seq_printf(s
, "%s%s\n", prefix
, printbuf
);
636 static void wil_seq_print_skb(struct seq_file
*s
, struct sk_buff
*skb
)
639 int len
= skb_headlen(skb
);
641 int nr_frags
= skb_shinfo(skb
)->nr_frags
;
643 seq_printf(s
, " len = %d\n", len
);
644 wil_seq_hexdump(s
, p
, len
, " : ");
647 seq_printf(s
, " nr_frags = %d\n", nr_frags
);
648 for (i
= 0; i
< nr_frags
; i
++) {
649 const struct skb_frag_struct
*frag
=
650 &skb_shinfo(skb
)->frags
[i
];
652 len
= skb_frag_size(frag
);
653 p
= skb_frag_address_safe(frag
);
654 seq_printf(s
, " [%2d] : len = %d\n", i
, len
);
655 wil_seq_hexdump(s
, p
, len
, " : ");
660 /*---------Tx/Rx descriptor------------*/
661 static int wil_txdesc_debugfs_show(struct seq_file
*s
, void *data
)
663 struct wil6210_priv
*wil
= s
->private;
665 bool tx
= (dbg_vring_index
< WIL6210_MAX_TX_RINGS
);
667 vring
= &(wil
->vring_tx
[dbg_vring_index
]);
669 vring
= &wil
->vring_rx
;
673 seq_printf(s
, "No Tx[%2d] VRING\n", dbg_vring_index
);
675 seq_puts(s
, "No Rx VRING\n");
679 if (dbg_txdesc_index
< vring
->size
) {
680 /* use struct vring_tx_desc for Rx as well,
681 * only field used, .dma.length, is the same
683 volatile struct vring_tx_desc
*d
=
684 &(vring
->va
[dbg_txdesc_index
].tx
);
685 volatile u32
*u
= (volatile u32
*)d
;
686 struct sk_buff
*skb
= vring
->ctx
[dbg_txdesc_index
].skb
;
689 seq_printf(s
, "Tx[%2d][%3d] = {\n", dbg_vring_index
,
692 seq_printf(s
, "Rx[%3d] = {\n", dbg_txdesc_index
);
693 seq_printf(s
, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
694 u
[0], u
[1], u
[2], u
[3]);
695 seq_printf(s
, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
696 u
[4], u
[5], u
[6], u
[7]);
697 seq_printf(s
, " SKB = 0x%p\n", skb
);
701 wil_seq_print_skb(s
, skb
);
704 seq_printf(s
, "}\n");
707 seq_printf(s
, "[%2d] TxDesc index (%d) >= size (%d)\n",
708 dbg_vring_index
, dbg_txdesc_index
,
711 seq_printf(s
, "RxDesc index (%d) >= size (%d)\n",
712 dbg_txdesc_index
, vring
->size
);
718 static int wil_txdesc_seq_open(struct inode
*inode
, struct file
*file
)
720 return single_open(file
, wil_txdesc_debugfs_show
, inode
->i_private
);
723 static const struct file_operations fops_txdesc
= {
724 .open
= wil_txdesc_seq_open
,
725 .release
= single_release
,
730 /*---------beamforming------------*/
731 static int wil_bf_debugfs_show(struct seq_file
*s
, void *data
)
733 struct wil6210_priv
*wil
= s
->private;
737 "Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n",
738 wil
->stats
.tsf
, wil
->stats
.bf_mcs
,
739 wil
->stats
.my_rx_sector
, wil
->stats
.my_tx_sector
,
740 wil
->stats
.peer_rx_sector
, wil
->stats
.peer_tx_sector
);
744 static int wil_bf_seq_open(struct inode
*inode
, struct file
*file
)
746 return single_open(file
, wil_bf_debugfs_show
, inode
->i_private
);
749 static const struct file_operations fops_bf
= {
750 .open
= wil_bf_seq_open
,
751 .release
= single_release
,
755 /*---------SSID------------*/
756 static ssize_t
wil_read_file_ssid(struct file
*file
, char __user
*user_buf
,
757 size_t count
, loff_t
*ppos
)
759 struct wil6210_priv
*wil
= file
->private_data
;
760 struct wireless_dev
*wdev
= wil_to_wdev(wil
);
762 return simple_read_from_buffer(user_buf
, count
, ppos
,
763 wdev
->ssid
, wdev
->ssid_len
);
766 static ssize_t
wil_write_file_ssid(struct file
*file
, const char __user
*buf
,
767 size_t count
, loff_t
*ppos
)
769 struct wil6210_priv
*wil
= file
->private_data
;
770 struct wireless_dev
*wdev
= wil_to_wdev(wil
);
771 struct net_device
*ndev
= wil_to_ndev(wil
);
774 wil_err(wil
, "Unable to set SSID substring from [%d]\n",
779 if (count
> sizeof(wdev
->ssid
)) {
780 wil_err(wil
, "SSID too long, len = %d\n", (int)count
);
783 if (netif_running(ndev
)) {
784 wil_err(wil
, "Unable to change SSID on running interface\n");
788 wdev
->ssid_len
= count
;
789 return simple_write_to_buffer(wdev
->ssid
, wdev
->ssid_len
, ppos
,
793 static const struct file_operations fops_ssid
= {
794 .read
= wil_read_file_ssid
,
795 .write
= wil_write_file_ssid
,
799 /*---------temp------------*/
800 static void print_temp(struct seq_file
*s
, const char *prefix
, u32 t
)
805 seq_printf(s
, "%s N/A\n", prefix
);
808 seq_printf(s
, "%s %d.%03d\n", prefix
, t
/ 1000, t
% 1000);
813 static int wil_temp_debugfs_show(struct seq_file
*s
, void *data
)
815 struct wil6210_priv
*wil
= s
->private;
818 int rc
= wmi_get_temperature(wil
, &t_m
, &t_r
);
820 seq_printf(s
, "Failed\n");
824 print_temp(s
, "T_mac =", t_m
);
825 print_temp(s
, "T_radio =", t_r
);
830 static int wil_temp_seq_open(struct inode
*inode
, struct file
*file
)
832 return single_open(file
, wil_temp_debugfs_show
, inode
->i_private
);
835 static const struct file_operations fops_temp
= {
836 .open
= wil_temp_seq_open
,
837 .release
= single_release
,
842 /*---------freq------------*/
843 static int wil_freq_debugfs_show(struct seq_file
*s
, void *data
)
845 struct wil6210_priv
*wil
= s
->private;
846 struct wireless_dev
*wdev
= wil_to_wdev(wil
);
847 u16 freq
= wdev
->chandef
.chan
? wdev
->chandef
.chan
->center_freq
: 0;
849 seq_printf(s
, "Freq = %d\n", freq
);
854 static int wil_freq_seq_open(struct inode
*inode
, struct file
*file
)
856 return single_open(file
, wil_freq_debugfs_show
, inode
->i_private
);
859 static const struct file_operations fops_freq
= {
860 .open
= wil_freq_seq_open
,
861 .release
= single_release
,
866 /*---------link------------*/
867 static int wil_link_debugfs_show(struct seq_file
*s
, void *data
)
869 struct wil6210_priv
*wil
= s
->private;
870 struct station_info sinfo
;
873 for (i
= 0; i
< ARRAY_SIZE(wil
->sta
); i
++) {
874 struct wil_sta_info
*p
= &wil
->sta
[i
];
875 char *status
= "unknown";
880 case wil_sta_conn_pending
:
883 case wil_sta_connected
:
884 status
= "connected";
887 seq_printf(s
, "[%d] %pM %s%s\n", i
, p
->addr
, status
,
888 (p
->data_port_open
? " data_port_open" : ""));
890 if (p
->status
== wil_sta_connected
) {
891 rc
= wil_cid_fill_sinfo(wil
, i
, &sinfo
);
895 seq_printf(s
, " Tx_mcs = %d\n", sinfo
.txrate
.mcs
);
896 seq_printf(s
, " Rx_mcs = %d\n", sinfo
.rxrate
.mcs
);
897 seq_printf(s
, " SQ = %d\n", sinfo
.signal
);
904 static int wil_link_seq_open(struct inode
*inode
, struct file
*file
)
906 return single_open(file
, wil_link_debugfs_show
, inode
->i_private
);
909 static const struct file_operations fops_link
= {
910 .open
= wil_link_seq_open
,
911 .release
= single_release
,
916 /*---------info------------*/
917 static int wil_info_debugfs_show(struct seq_file
*s
, void *data
)
919 struct wil6210_priv
*wil
= s
->private;
920 struct net_device
*ndev
= wil_to_ndev(wil
);
921 int is_ac
= power_supply_is_system_supplied();
922 int rx
= atomic_xchg(&wil
->isr_count_rx
, 0);
923 int tx
= atomic_xchg(&wil
->isr_count_tx
, 0);
924 static ulong rxf_old
, txf_old
;
925 ulong rxf
= ndev
->stats
.rx_packets
;
926 ulong txf
= ndev
->stats
.tx_packets
;
929 /* >0 : AC; 0 : battery; <0 : error */
930 seq_printf(s
, "AC powered : %d\n", is_ac
);
931 seq_printf(s
, "Rx irqs:packets : %8d : %8ld\n", rx
, rxf
- rxf_old
);
932 seq_printf(s
, "Tx irqs:packets : %8d : %8ld\n", tx
, txf
- txf_old
);
937 #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
938 " " __stringify(x) : ""
940 for (i
= 0; i
< ndev
->num_tx_queues
; i
++) {
941 struct netdev_queue
*txq
= netdev_get_tx_queue(ndev
, i
);
942 unsigned long state
= txq
->state
;
944 seq_printf(s
, "Tx queue[%i] state : 0x%lx%s%s%s\n", i
, state
,
945 CHECK_QSTATE(DRV_XOFF
),
946 CHECK_QSTATE(STACK_XOFF
),
954 static int wil_info_seq_open(struct inode
*inode
, struct file
*file
)
956 return single_open(file
, wil_info_debugfs_show
, inode
->i_private
);
959 static const struct file_operations fops_info
= {
960 .open
= wil_info_seq_open
,
961 .release
= single_release
,
966 /*---------Station matrix------------*/
967 static void wil_print_rxtid(struct seq_file
*s
, struct wil_tid_ampdu_rx
*r
)
970 u16 index
= ((r
->head_seq_num
- r
->ssn
) & 0xfff) % r
->buf_size
;
971 seq_printf(s
, "0x%03x [", r
->head_seq_num
);
972 for (i
= 0; i
< r
->buf_size
; i
++) {
974 seq_printf(s
, "%c", r
->reorder_buf
[i
] ? 'O' : '|');
976 seq_printf(s
, "%c", r
->reorder_buf
[i
] ? '*' : '_');
978 seq_printf(s
, "] last drop 0x%03x\n", r
->ssn_last_drop
);
981 static int wil_sta_debugfs_show(struct seq_file
*s
, void *data
)
983 struct wil6210_priv
*wil
= s
->private;
986 for (i
= 0; i
< ARRAY_SIZE(wil
->sta
); i
++) {
987 struct wil_sta_info
*p
= &wil
->sta
[i
];
988 char *status
= "unknown";
993 case wil_sta_conn_pending
:
996 case wil_sta_connected
:
997 status
= "connected";
1000 seq_printf(s
, "[%d] %pM %s%s\n", i
, p
->addr
, status
,
1001 (p
->data_port_open
? " data_port_open" : ""));
1003 if (p
->status
== wil_sta_connected
) {
1004 for (tid
= 0; tid
< WIL_STA_TID_NUM
; tid
++) {
1005 struct wil_tid_ampdu_rx
*r
= p
->tid_rx
[tid
];
1007 seq_printf(s
, "[%2d] ", tid
);
1008 wil_print_rxtid(s
, r
);
1017 static int wil_sta_seq_open(struct inode
*inode
, struct file
*file
)
1019 return single_open(file
, wil_sta_debugfs_show
, inode
->i_private
);
1022 static const struct file_operations fops_sta
= {
1023 .open
= wil_sta_seq_open
,
1024 .release
= single_release
,
1026 .llseek
= seq_lseek
,
1029 /*----------------*/
1030 static void wil6210_debugfs_init_blobs(struct wil6210_priv
*wil
,
1036 for (i
= 0; i
< ARRAY_SIZE(fw_mapping
); i
++) {
1037 struct debugfs_blob_wrapper
*blob
= &wil
->blobs
[i
];
1038 const struct fw_map
*map
= &fw_mapping
[i
];
1043 blob
->data
= (void * __force
)wil
->csr
+ HOSTADDR(map
->host
);
1044 blob
->size
= map
->to
- map
->from
;
1045 snprintf(name
, sizeof(name
), "blob_%s", map
->name
);
1046 wil_debugfs_create_ioblob(name
, S_IRUGO
, dbg
, blob
);
1051 static const struct {
1054 const struct file_operations
*fops
;
1056 {"mbox", S_IRUGO
, &fops_mbox
},
1057 {"vrings", S_IRUGO
, &fops_vring
},
1058 {"stations", S_IRUGO
, &fops_sta
},
1059 {"desc", S_IRUGO
, &fops_txdesc
},
1060 {"bf", S_IRUGO
, &fops_bf
},
1061 {"ssid", S_IRUGO
| S_IWUSR
, &fops_ssid
},
1062 {"mem_val", S_IRUGO
, &fops_memread
},
1063 {"reset", S_IWUSR
, &fops_reset
},
1064 {"rxon", S_IWUSR
, &fops_rxon
},
1065 {"tx_mgmt", S_IWUSR
, &fops_txmgmt
},
1066 {"wmi_send", S_IWUSR
, &fops_wmi
},
1067 {"temp", S_IRUGO
, &fops_temp
},
1068 {"freq", S_IRUGO
, &fops_freq
},
1069 {"link", S_IRUGO
, &fops_link
},
1070 {"info", S_IRUGO
, &fops_info
},
1073 static void wil6210_debugfs_init_files(struct wil6210_priv
*wil
,
1078 for (i
= 0; i
< ARRAY_SIZE(dbg_files
); i
++)
1079 debugfs_create_file(dbg_files
[i
].name
, dbg_files
[i
].mode
, dbg
,
1080 wil
, dbg_files
[i
].fops
);
1083 /* interrupt control blocks */
1084 static const struct {
1088 {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR
)},
1089 {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR
)},
1090 {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR
)},
1091 {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR
)},
1094 static void wil6210_debugfs_init_isr(struct wil6210_priv
*wil
,
1099 for (i
= 0; i
< ARRAY_SIZE(dbg_icr
); i
++)
1100 wil6210_debugfs_create_ISR(wil
, dbg_icr
[i
].name
, dbg
,
1101 dbg_icr
[i
].icr_off
);
1104 #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
1105 offsetof(struct wil6210_priv, name), type}
1107 /* fields in struct wil6210_priv */
1108 static const struct dbg_off dbg_wil_off
[] = {
1109 WIL_FIELD(secure_pcp
, S_IRUGO
| S_IWUSR
, doff_u32
),
1110 WIL_FIELD(status
, S_IRUGO
| S_IWUSR
, doff_ulong
),
1111 WIL_FIELD(fw_version
, S_IRUGO
, doff_u32
),
1112 WIL_FIELD(hw_version
, S_IRUGO
, doff_x32
),
1116 static const struct dbg_off dbg_wil_regs
[] = {
1117 {"RGF_MAC_MTRL_COUNTER_0", S_IRUGO
, HOSTADDR(RGF_MAC_MTRL_COUNTER_0
),
1119 {"RGF_USER_USAGE_1", S_IRUGO
, HOSTADDR(RGF_USER_USAGE_1
), doff_io32
},
1123 /* static parameters */
1124 static const struct dbg_off dbg_statics
[] = {
1125 {"desc_index", S_IRUGO
| S_IWUSR
, (ulong
)&dbg_txdesc_index
, doff_u32
},
1126 {"vring_index", S_IRUGO
| S_IWUSR
, (ulong
)&dbg_vring_index
, doff_u32
},
1127 {"mem_addr", S_IRUGO
| S_IWUSR
, (ulong
)&mem_addr
, doff_u32
},
1131 int wil6210_debugfs_init(struct wil6210_priv
*wil
)
1133 struct dentry
*dbg
= wil
->debug
= debugfs_create_dir(WIL_NAME
,
1134 wil_to_wiphy(wil
)->debugfsdir
);
1136 if (IS_ERR_OR_NULL(dbg
))
1139 wil6210_debugfs_init_files(wil
, dbg
);
1140 wil6210_debugfs_init_isr(wil
, dbg
);
1141 wil6210_debugfs_init_blobs(wil
, dbg
);
1142 wil6210_debugfs_init_offset(wil
, dbg
, wil
, dbg_wil_off
);
1143 wil6210_debugfs_init_offset(wil
, dbg
, (void * __force
)wil
->csr
,
1145 wil6210_debugfs_init_offset(wil
, dbg
, NULL
, dbg_statics
);
1147 wil6210_debugfs_create_pseudo_ISR(wil
, dbg
);
1149 wil6210_debugfs_create_ITR_CNT(wil
, dbg
);
1154 void wil6210_debugfs_remove(struct wil6210_priv
*wil
)
1156 debugfs_remove_recursive(wil
->debug
);