2 * Copyright (c) 2012 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>
26 /* Nasty hack. Better have per device instances */
28 static u32 dbg_txdesc_index;
29 static u32 dbg_vring_index; /* 24+ for Rx, 0..23 for Tx */
31 static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil,
32 const char *name, struct vring *vring,
35 void __iomem *x = wmi_addr(wil, vring->hwtail);
37 seq_printf(s, "VRING %s = {\n", name);
38 seq_printf(s, " pa = %pad\n", &vring->pa);
39 seq_printf(s, " va = 0x%p\n", vring->va);
40 seq_printf(s, " size = %d\n", vring->size);
41 seq_printf(s, " swtail = %d\n", vring->swtail);
42 seq_printf(s, " swhead = %d\n", vring->swhead);
43 seq_printf(s, " hwtail = [0x%08x] -> ", vring->hwtail);
45 seq_printf(s, "0x%08x\n", ioread32(x));
47 seq_printf(s, "???\n");
49 if (vring->va && (vring->size < 1025)) {
51 for (i = 0; i < vring->size; i++) {
52 volatile struct vring_tx_desc *d = &vring->va[i].tx;
53 if ((i % 64) == 0 && (i != 0))
55 seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
56 _s : (vring->ctx[i].skb ? _h : 'h'));
63 static int wil_vring_debugfs_show(struct seq_file *s, void *data)
66 struct wil6210_priv *wil = s->private;
68 wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_');
70 for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
71 struct vring *vring = &(wil->vring_tx[i]);
73 int cid = wil->vring2cid_tid[i][0];
74 int tid = wil->vring2cid_tid[i][1];
76 snprintf(name, sizeof(name), "tx_%2d", i);
78 seq_printf(s, "\n%pM CID %d TID %d\n",
79 wil->sta[cid].addr, cid, tid);
80 wil_print_vring(s, wil, name, vring, '_', 'H');
87 static int wil_vring_seq_open(struct inode *inode, struct file *file)
89 return single_open(file, wil_vring_debugfs_show, inode->i_private);
92 static const struct file_operations fops_vring = {
93 .open = wil_vring_seq_open,
94 .release = single_release,
99 static void wil_print_ring(struct seq_file *s, const char *prefix,
102 struct wil6210_priv *wil = s->private;
103 struct wil6210_mbox_ring r;
107 wil_memcpy_fromio_32(&r, off, sizeof(r));
108 wil_mbox_ring_le2cpus(&r);
110 * we just read memory block from NIC. This memory may be
111 * garbage. Check validity before using it.
113 rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
115 seq_printf(s, "ring %s = {\n", prefix);
116 seq_printf(s, " base = 0x%08x\n", r.base);
117 seq_printf(s, " size = 0x%04x bytes -> %d entries\n", r.size, rsize);
118 seq_printf(s, " tail = 0x%08x\n", r.tail);
119 seq_printf(s, " head = 0x%08x\n", r.head);
120 seq_printf(s, " entry size = %d\n", r.entry_size);
122 if (r.size % sizeof(struct wil6210_mbox_ring_desc)) {
123 seq_printf(s, " ??? size is not multiple of %zd, garbage?\n",
124 sizeof(struct wil6210_mbox_ring_desc));
128 if (!wmi_addr(wil, r.base) ||
129 !wmi_addr(wil, r.tail) ||
130 !wmi_addr(wil, r.head)) {
131 seq_printf(s, " ??? pointers are garbage?\n");
135 for (i = 0; i < rsize; i++) {
136 struct wil6210_mbox_ring_desc d;
137 struct wil6210_mbox_hdr hdr;
138 size_t delta = i * sizeof(d);
139 void __iomem *x = wil->csr + HOSTADDR(r.base) + delta;
141 wil_memcpy_fromio_32(&d, x, sizeof(d));
143 seq_printf(s, " [%2x] %s %s%s 0x%08x", i,
145 (r.tail - r.base == delta) ? "t" : " ",
146 (r.head - r.base == delta) ? "h" : " ",
147 le32_to_cpu(d.addr));
148 if (0 == wmi_read_hdr(wil, d.addr, &hdr)) {
149 u16 len = le16_to_cpu(hdr.len);
150 seq_printf(s, " -> %04x %04x %04x %02x\n",
151 le16_to_cpu(hdr.seq), len,
152 le16_to_cpu(hdr.type), hdr.flags);
153 if (len <= MAX_MBOXITEM_SIZE) {
155 char printbuf[16 * 3 + 2];
156 unsigned char databuf[MAX_MBOXITEM_SIZE];
157 void __iomem *src = wmi_buffer(wil, d.addr) +
158 sizeof(struct wil6210_mbox_hdr);
160 * No need to check @src for validity -
161 * we already validated @d.addr while
164 wil_memcpy_fromio_32(databuf, src, len);
166 int l = min(len - n, 16);
167 hex_dump_to_buffer(databuf + n, l,
171 seq_printf(s, " : %s\n", printbuf);
180 seq_printf(s, "}\n");
183 static int wil_mbox_debugfs_show(struct seq_file *s, void *data)
185 struct wil6210_priv *wil = s->private;
187 wil_print_ring(s, "tx", wil->csr + HOST_MBOX +
188 offsetof(struct wil6210_mbox_ctl, tx));
189 wil_print_ring(s, "rx", wil->csr + HOST_MBOX +
190 offsetof(struct wil6210_mbox_ctl, rx));
195 static int wil_mbox_seq_open(struct inode *inode, struct file *file)
197 return single_open(file, wil_mbox_debugfs_show, inode->i_private);
200 static const struct file_operations fops_mbox = {
201 .open = wil_mbox_seq_open,
202 .release = single_release,
207 static int wil_debugfs_iomem_x32_set(void *data, u64 val)
209 iowrite32(val, (void __iomem *)data);
210 wmb(); /* make sure write propagated to HW */
215 static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
217 *val = ioread32((void __iomem *)data);
222 DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
223 wil_debugfs_iomem_x32_set, "0x%08llx\n");
225 static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
227 struct dentry *parent,
230 return debugfs_create_file(name, mode, parent, (void * __force)value,
234 static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
236 struct dentry *parent, u32 off)
238 struct dentry *d = debugfs_create_dir(name, parent);
240 if (IS_ERR_OR_NULL(d))
243 wil_debugfs_create_iomem_x32("ICC", S_IRUGO | S_IWUSR, d,
245 wil_debugfs_create_iomem_x32("ICR", S_IRUGO | S_IWUSR, d,
247 wil_debugfs_create_iomem_x32("ICM", S_IRUGO | S_IWUSR, d,
249 wil_debugfs_create_iomem_x32("ICS", S_IWUSR, d,
250 wil->csr + off + 12);
251 wil_debugfs_create_iomem_x32("IMV", S_IRUGO | S_IWUSR, d,
252 wil->csr + off + 16);
253 wil_debugfs_create_iomem_x32("IMS", S_IWUSR, d,
254 wil->csr + off + 20);
255 wil_debugfs_create_iomem_x32("IMC", S_IWUSR, d,
256 wil->csr + off + 24);
261 static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
262 struct dentry *parent)
264 struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
266 if (IS_ERR_OR_NULL(d))
269 wil_debugfs_create_iomem_x32("CAUSE", S_IRUGO, d, wil->csr +
270 HOSTADDR(RGF_DMA_PSEUDO_CAUSE));
271 wil_debugfs_create_iomem_x32("MASK_SW", S_IRUGO, d, wil->csr +
272 HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW));
273 wil_debugfs_create_iomem_x32("MASK_FW", S_IRUGO, d, wil->csr +
274 HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW));
279 static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
280 struct dentry *parent)
282 struct dentry *d = debugfs_create_dir("ITR_CNT", parent);
284 if (IS_ERR_OR_NULL(d))
287 wil_debugfs_create_iomem_x32("TRSH", S_IRUGO, d, wil->csr +
288 HOSTADDR(RGF_DMA_ITR_CNT_TRSH));
289 wil_debugfs_create_iomem_x32("DATA", S_IRUGO, d, wil->csr +
290 HOSTADDR(RGF_DMA_ITR_CNT_DATA));
291 wil_debugfs_create_iomem_x32("CTL", S_IRUGO, d, wil->csr +
292 HOSTADDR(RGF_DMA_ITR_CNT_CRL));
297 static int wil_memread_debugfs_show(struct seq_file *s, void *data)
299 struct wil6210_priv *wil = s->private;
300 void __iomem *a = wmi_buffer(wil, cpu_to_le32(mem_addr));
303 seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, ioread32(a));
305 seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
310 static int wil_memread_seq_open(struct inode *inode, struct file *file)
312 return single_open(file, wil_memread_debugfs_show, inode->i_private);
315 static const struct file_operations fops_memread = {
316 .open = wil_memread_seq_open,
317 .release = single_release,
322 static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
323 size_t count, loff_t *ppos)
325 enum { max_count = 4096 };
326 struct debugfs_blob_wrapper *blob = file->private_data;
328 size_t available = blob->size;
335 if (pos >= available || !count)
338 if (count > available - pos)
339 count = available - pos;
340 if (count > max_count)
343 buf = kmalloc(count, GFP_KERNEL);
347 wil_memcpy_fromio_32(buf, (const volatile void __iomem *)blob->data +
350 ret = copy_to_user(user_buf, buf, count);
361 static const struct file_operations fops_ioblob = {
362 .read = wil_read_file_ioblob,
364 .llseek = default_llseek,
368 struct dentry *wil_debugfs_create_ioblob(const char *name,
370 struct dentry *parent,
371 struct debugfs_blob_wrapper *blob)
373 return debugfs_create_file(name, mode, parent, blob, &fops_ioblob);
376 static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
377 size_t len, loff_t *ppos)
379 struct wil6210_priv *wil = file->private_data;
380 struct net_device *ndev = wil_to_ndev(wil);
384 * this code does NOT sync device state with the rest of system
385 * use with care, debug only!!!
389 ndev->flags &= ~IFF_UP;
396 static const struct file_operations fops_reset = {
397 .write = wil_write_file_reset,
401 static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
404 char printbuf[16 * 3 + 2];
407 int l = min(len - i, 16);
408 hex_dump_to_buffer(p + i, l, 16, 1, printbuf,
409 sizeof(printbuf), false);
410 seq_printf(s, "%s%s\n", prefix, printbuf);
415 static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
418 int len = skb_headlen(skb);
420 int nr_frags = skb_shinfo(skb)->nr_frags;
422 seq_printf(s, " len = %d\n", len);
423 wil_seq_hexdump(s, p, len, " : ");
426 seq_printf(s, " nr_frags = %d\n", nr_frags);
427 for (i = 0; i < nr_frags; i++) {
428 const struct skb_frag_struct *frag =
429 &skb_shinfo(skb)->frags[i];
431 len = skb_frag_size(frag);
432 p = skb_frag_address_safe(frag);
433 seq_printf(s, " [%2d] : len = %d\n", i, len);
434 wil_seq_hexdump(s, p, len, " : ");
439 /*---------Tx/Rx descriptor------------*/
440 static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
442 struct wil6210_priv *wil = s->private;
444 bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS);
446 vring = &(wil->vring_tx[dbg_vring_index]);
448 vring = &wil->vring_rx;
452 seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index);
454 seq_puts(s, "No Rx VRING\n");
458 if (dbg_txdesc_index < vring->size) {
459 /* use struct vring_tx_desc for Rx as well,
460 * only field used, .dma.length, is the same
462 volatile struct vring_tx_desc *d =
463 &(vring->va[dbg_txdesc_index].tx);
464 volatile u32 *u = (volatile u32 *)d;
465 struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb;
468 seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index,
471 seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
472 seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
473 u[0], u[1], u[2], u[3]);
474 seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
475 u[4], u[5], u[6], u[7]);
476 seq_printf(s, " SKB = 0x%p\n", skb);
480 wil_seq_print_skb(s, skb);
483 seq_printf(s, "}\n");
486 seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
487 dbg_vring_index, dbg_txdesc_index,
490 seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
491 dbg_txdesc_index, vring->size);
497 static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
499 return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
502 static const struct file_operations fops_txdesc = {
503 .open = wil_txdesc_seq_open,
504 .release = single_release,
509 /*---------beamforming------------*/
510 static int wil_bf_debugfs_show(struct seq_file *s, void *data)
512 struct wil6210_priv *wil = s->private;
516 "Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n",
517 wil->stats.tsf, wil->stats.bf_mcs,
518 wil->stats.my_rx_sector, wil->stats.my_tx_sector,
519 wil->stats.peer_rx_sector, wil->stats.peer_tx_sector);
523 static int wil_bf_seq_open(struct inode *inode, struct file *file)
525 return single_open(file, wil_bf_debugfs_show, inode->i_private);
528 static const struct file_operations fops_bf = {
529 .open = wil_bf_seq_open,
530 .release = single_release,
534 /*---------SSID------------*/
535 static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf,
536 size_t count, loff_t *ppos)
538 struct wil6210_priv *wil = file->private_data;
539 struct wireless_dev *wdev = wil_to_wdev(wil);
541 return simple_read_from_buffer(user_buf, count, ppos,
542 wdev->ssid, wdev->ssid_len);
545 static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf,
546 size_t count, loff_t *ppos)
548 struct wil6210_priv *wil = file->private_data;
549 struct wireless_dev *wdev = wil_to_wdev(wil);
550 struct net_device *ndev = wil_to_ndev(wil);
553 wil_err(wil, "Unable to set SSID substring from [%d]\n",
558 if (count > sizeof(wdev->ssid)) {
559 wil_err(wil, "SSID too long, len = %d\n", (int)count);
562 if (netif_running(ndev)) {
563 wil_err(wil, "Unable to change SSID on running interface\n");
567 wdev->ssid_len = count;
568 return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos,
572 static const struct file_operations fops_ssid = {
573 .read = wil_read_file_ssid,
574 .write = wil_write_file_ssid,
578 /*---------temp------------*/
579 static void print_temp(struct seq_file *s, const char *prefix, u32 t)
584 seq_printf(s, "%s N/A\n", prefix);
587 seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
592 static int wil_temp_debugfs_show(struct seq_file *s, void *data)
594 struct wil6210_priv *wil = s->private;
597 int rc = wmi_get_temperature(wil, &t_m, &t_r);
599 seq_printf(s, "Failed\n");
603 print_temp(s, "MAC temperature :", t_m);
604 print_temp(s, "Radio temperature :", t_r);
609 static int wil_temp_seq_open(struct inode *inode, struct file *file)
611 return single_open(file, wil_temp_debugfs_show, inode->i_private);
614 static const struct file_operations fops_temp = {
615 .open = wil_temp_seq_open,
616 .release = single_release,
621 /*---------Station matrix------------*/
622 static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
625 u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
626 seq_printf(s, "0x%03x [", r->head_seq_num);
627 for (i = 0; i < r->buf_size; i++) {
629 seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
631 seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
636 static int wil_sta_debugfs_show(struct seq_file *s, void *data)
638 struct wil6210_priv *wil = s->private;
641 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
642 struct wil_sta_info *p = &wil->sta[i];
643 char *status = "unknown";
648 case wil_sta_conn_pending:
651 case wil_sta_connected:
652 status = "connected";
655 seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
656 (p->data_port_open ? " data_port_open" : ""));
658 if (p->status == wil_sta_connected) {
659 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
660 struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
662 seq_printf(s, "[%2d] ", tid);
663 wil_print_rxtid(s, r);
672 static int wil_sta_seq_open(struct inode *inode, struct file *file)
674 return single_open(file, wil_sta_debugfs_show, inode->i_private);
677 static const struct file_operations fops_sta = {
678 .open = wil_sta_seq_open,
679 .release = single_release,
685 int wil6210_debugfs_init(struct wil6210_priv *wil)
687 struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
688 wil_to_wiphy(wil)->debugfsdir);
690 if (IS_ERR_OR_NULL(dbg))
693 debugfs_create_file("mbox", S_IRUGO, dbg, wil, &fops_mbox);
694 debugfs_create_file("vrings", S_IRUGO, dbg, wil, &fops_vring);
695 debugfs_create_file("stations", S_IRUGO, dbg, wil, &fops_sta);
696 debugfs_create_file("desc", S_IRUGO, dbg, wil, &fops_txdesc);
697 debugfs_create_u32("desc_index", S_IRUGO | S_IWUSR, dbg,
699 debugfs_create_u32("vring_index", S_IRUGO | S_IWUSR, dbg,
702 debugfs_create_file("bf", S_IRUGO, dbg, wil, &fops_bf);
703 debugfs_create_file("ssid", S_IRUGO | S_IWUSR, dbg, wil, &fops_ssid);
704 debugfs_create_u32("secure_pcp", S_IRUGO | S_IWUSR, dbg,
707 wil6210_debugfs_create_ISR(wil, "USER_ICR", dbg,
708 HOSTADDR(RGF_USER_USER_ICR));
709 wil6210_debugfs_create_ISR(wil, "DMA_EP_TX_ICR", dbg,
710 HOSTADDR(RGF_DMA_EP_TX_ICR));
711 wil6210_debugfs_create_ISR(wil, "DMA_EP_RX_ICR", dbg,
712 HOSTADDR(RGF_DMA_EP_RX_ICR));
713 wil6210_debugfs_create_ISR(wil, "DMA_EP_MISC_ICR", dbg,
714 HOSTADDR(RGF_DMA_EP_MISC_ICR));
715 wil6210_debugfs_create_pseudo_ISR(wil, dbg);
716 wil6210_debugfs_create_ITR_CNT(wil, dbg);
718 debugfs_create_u32("mem_addr", S_IRUGO | S_IWUSR, dbg, &mem_addr);
719 debugfs_create_file("mem_val", S_IRUGO, dbg, wil, &fops_memread);
721 debugfs_create_file("reset", S_IWUSR, dbg, wil, &fops_reset);
722 debugfs_create_file("temp", S_IRUGO, dbg, wil, &fops_temp);
724 wil->rgf_blob.data = (void * __force)wil->csr + 0;
725 wil->rgf_blob.size = 0xa000;
726 wil_debugfs_create_ioblob("blob_rgf", S_IRUGO, dbg, &wil->rgf_blob);
728 wil->fw_code_blob.data = (void * __force)wil->csr + 0x40000;
729 wil->fw_code_blob.size = 0x40000;
730 wil_debugfs_create_ioblob("blob_fw_code", S_IRUGO, dbg,
733 wil->fw_data_blob.data = (void * __force)wil->csr + 0x80000;
734 wil->fw_data_blob.size = 0x8000;
735 wil_debugfs_create_ioblob("blob_fw_data", S_IRUGO, dbg,
738 wil->fw_peri_blob.data = (void * __force)wil->csr + 0x88000;
739 wil->fw_peri_blob.size = 0x18000;
740 wil_debugfs_create_ioblob("blob_fw_peri", S_IRUGO, dbg,
743 wil->uc_code_blob.data = (void * __force)wil->csr + 0xa0000;
744 wil->uc_code_blob.size = 0x10000;
745 wil_debugfs_create_ioblob("blob_uc_code", S_IRUGO, dbg,
748 wil->uc_data_blob.data = (void * __force)wil->csr + 0xb0000;
749 wil->uc_data_blob.size = 0x4000;
750 wil_debugfs_create_ioblob("blob_uc_data", S_IRUGO, dbg,
756 void wil6210_debugfs_remove(struct wil6210_priv *wil)
758 debugfs_remove_recursive(wil->debug);