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;
30 static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil,
31 const char *name, struct vring *vring)
33 void __iomem *x = wmi_addr(wil, vring->hwtail);
35 seq_printf(s, "VRING %s = {\n", name);
36 seq_printf(s, " pa = 0x%016llx\n", (unsigned long long)vring->pa);
37 seq_printf(s, " va = 0x%p\n", vring->va);
38 seq_printf(s, " size = %d\n", vring->size);
39 seq_printf(s, " swtail = %d\n", vring->swtail);
40 seq_printf(s, " swhead = %d\n", vring->swhead);
41 seq_printf(s, " hwtail = [0x%08x] -> ", vring->hwtail);
43 seq_printf(s, "0x%08x\n", ioread32(x));
45 seq_printf(s, "???\n");
47 if (vring->va && (vring->size < 1025)) {
49 for (i = 0; i < vring->size; i++) {
50 volatile struct vring_tx_desc *d = &vring->va[i].tx;
51 if ((i % 64) == 0 && (i != 0))
53 seq_printf(s, "%s", (d->dma.status & BIT(0)) ?
54 "S" : (vring->ctx[i] ? "H" : "h"));
61 static int wil_vring_debugfs_show(struct seq_file *s, void *data)
64 struct wil6210_priv *wil = s->private;
66 wil_print_vring(s, wil, "rx", &wil->vring_rx);
68 for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
69 struct vring *vring = &(wil->vring_tx[i]);
72 snprintf(name, sizeof(name), "tx_%2d", i);
73 wil_print_vring(s, wil, name, vring);
80 static int wil_vring_seq_open(struct inode *inode, struct file *file)
82 return single_open(file, wil_vring_debugfs_show, inode->i_private);
85 static const struct file_operations fops_vring = {
86 .open = wil_vring_seq_open,
87 .release = single_release,
92 static void wil_print_ring(struct seq_file *s, const char *prefix,
95 struct wil6210_priv *wil = s->private;
96 struct wil6210_mbox_ring r;
100 wil_memcpy_fromio_32(&r, off, sizeof(r));
101 wil_mbox_ring_le2cpus(&r);
103 * we just read memory block from NIC. This memory may be
104 * garbage. Check validity before using it.
106 rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
108 seq_printf(s, "ring %s = {\n", prefix);
109 seq_printf(s, " base = 0x%08x\n", r.base);
110 seq_printf(s, " size = 0x%04x bytes -> %d entries\n", r.size, rsize);
111 seq_printf(s, " tail = 0x%08x\n", r.tail);
112 seq_printf(s, " head = 0x%08x\n", r.head);
113 seq_printf(s, " entry size = %d\n", r.entry_size);
115 if (r.size % sizeof(struct wil6210_mbox_ring_desc)) {
116 seq_printf(s, " ??? size is not multiple of %zd, garbage?\n",
117 sizeof(struct wil6210_mbox_ring_desc));
121 if (!wmi_addr(wil, r.base) ||
122 !wmi_addr(wil, r.tail) ||
123 !wmi_addr(wil, r.head)) {
124 seq_printf(s, " ??? pointers are garbage?\n");
128 for (i = 0; i < rsize; i++) {
129 struct wil6210_mbox_ring_desc d;
130 struct wil6210_mbox_hdr hdr;
131 size_t delta = i * sizeof(d);
132 void __iomem *x = wil->csr + HOSTADDR(r.base) + delta;
134 wil_memcpy_fromio_32(&d, x, sizeof(d));
136 seq_printf(s, " [%2x] %s %s%s 0x%08x", i,
138 (r.tail - r.base == delta) ? "t" : " ",
139 (r.head - r.base == delta) ? "h" : " ",
140 le32_to_cpu(d.addr));
141 if (0 == wmi_read_hdr(wil, d.addr, &hdr)) {
142 u16 len = le16_to_cpu(hdr.len);
143 seq_printf(s, " -> %04x %04x %04x %02x\n",
144 le16_to_cpu(hdr.seq), len,
145 le16_to_cpu(hdr.type), hdr.flags);
146 if (len <= MAX_MBOXITEM_SIZE) {
148 unsigned char printbuf[16 * 3 + 2];
149 unsigned char databuf[MAX_MBOXITEM_SIZE];
150 void __iomem *src = wmi_buffer(wil, d.addr) +
151 sizeof(struct wil6210_mbox_hdr);
153 * No need to check @src for validity -
154 * we already validated @d.addr while
157 wil_memcpy_fromio_32(databuf, src, len);
159 int l = min(len - n, 16);
160 hex_dump_to_buffer(databuf + n, l,
164 seq_printf(s, " : %s\n", printbuf);
173 seq_printf(s, "}\n");
176 static int wil_mbox_debugfs_show(struct seq_file *s, void *data)
178 struct wil6210_priv *wil = s->private;
180 wil_print_ring(s, "tx", wil->csr + HOST_MBOX +
181 offsetof(struct wil6210_mbox_ctl, tx));
182 wil_print_ring(s, "rx", wil->csr + HOST_MBOX +
183 offsetof(struct wil6210_mbox_ctl, rx));
188 static int wil_mbox_seq_open(struct inode *inode, struct file *file)
190 return single_open(file, wil_mbox_debugfs_show, inode->i_private);
193 static const struct file_operations fops_mbox = {
194 .open = wil_mbox_seq_open,
195 .release = single_release,
200 static int wil_debugfs_iomem_x32_set(void *data, u64 val)
202 iowrite32(val, (void __iomem *)data);
203 wmb(); /* make sure write propagated to HW */
208 static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
210 *val = ioread32((void __iomem *)data);
215 DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
216 wil_debugfs_iomem_x32_set, "0x%08llx\n");
218 static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
220 struct dentry *parent,
223 return debugfs_create_file(name, mode, parent, (void * __force)value,
227 static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
229 struct dentry *parent, u32 off)
231 struct dentry *d = debugfs_create_dir(name, parent);
233 if (IS_ERR_OR_NULL(d))
236 wil_debugfs_create_iomem_x32("ICC", S_IRUGO | S_IWUSR, d,
238 wil_debugfs_create_iomem_x32("ICR", S_IRUGO | S_IWUSR, d,
240 wil_debugfs_create_iomem_x32("ICM", S_IRUGO | S_IWUSR, d,
242 wil_debugfs_create_iomem_x32("ICS", S_IWUSR, d,
243 wil->csr + off + 12);
244 wil_debugfs_create_iomem_x32("IMV", S_IRUGO | S_IWUSR, d,
245 wil->csr + off + 16);
246 wil_debugfs_create_iomem_x32("IMS", S_IWUSR, d,
247 wil->csr + off + 20);
248 wil_debugfs_create_iomem_x32("IMC", S_IWUSR, d,
249 wil->csr + off + 24);
254 static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
255 struct dentry *parent)
257 struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
259 if (IS_ERR_OR_NULL(d))
262 wil_debugfs_create_iomem_x32("CAUSE", S_IRUGO, d, wil->csr +
263 HOSTADDR(RGF_DMA_PSEUDO_CAUSE));
264 wil_debugfs_create_iomem_x32("MASK_SW", S_IRUGO, d, wil->csr +
265 HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW));
266 wil_debugfs_create_iomem_x32("MASK_FW", S_IRUGO, d, wil->csr +
267 HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW));
272 static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
273 struct dentry *parent)
275 struct dentry *d = debugfs_create_dir("ITR_CNT", parent);
277 if (IS_ERR_OR_NULL(d))
280 wil_debugfs_create_iomem_x32("TRSH", S_IRUGO, d, wil->csr +
281 HOSTADDR(RGF_DMA_ITR_CNT_TRSH));
282 wil_debugfs_create_iomem_x32("DATA", S_IRUGO, d, wil->csr +
283 HOSTADDR(RGF_DMA_ITR_CNT_DATA));
284 wil_debugfs_create_iomem_x32("CTL", S_IRUGO, d, wil->csr +
285 HOSTADDR(RGF_DMA_ITR_CNT_CRL));
290 static int wil_memread_debugfs_show(struct seq_file *s, void *data)
292 struct wil6210_priv *wil = s->private;
293 void __iomem *a = wmi_buffer(wil, cpu_to_le32(mem_addr));
296 seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, ioread32(a));
298 seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
303 static int wil_memread_seq_open(struct inode *inode, struct file *file)
305 return single_open(file, wil_memread_debugfs_show, inode->i_private);
308 static const struct file_operations fops_memread = {
309 .open = wil_memread_seq_open,
310 .release = single_release,
315 static int wil_default_open(struct inode *inode, struct file *file)
317 if (inode->i_private)
318 file->private_data = inode->i_private;
323 static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
324 size_t count, loff_t *ppos)
326 enum { max_count = 4096 };
327 struct debugfs_blob_wrapper *blob = file->private_data;
329 size_t available = blob->size;
336 if (pos >= available || !count)
339 if (count > available - pos)
340 count = available - pos;
341 if (count > max_count)
344 buf = kmalloc(count, GFP_KERNEL);
348 wil_memcpy_fromio_32(buf, (const volatile void __iomem *)blob->data +
351 ret = copy_to_user(user_buf, buf, count);
362 static const struct file_operations fops_ioblob = {
363 .read = wil_read_file_ioblob,
364 .open = wil_default_open,
365 .llseek = default_llseek,
369 struct dentry *wil_debugfs_create_ioblob(const char *name,
371 struct dentry *parent,
372 struct debugfs_blob_wrapper *blob)
374 return debugfs_create_file(name, mode, parent, blob, &fops_ioblob);
377 static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
378 size_t len, loff_t *ppos)
380 struct wil6210_priv *wil = file->private_data;
381 struct net_device *ndev = wil_to_ndev(wil);
385 * this code does NOT sync device state with the rest of system
386 * use with care, debug only!!!
390 ndev->flags &= ~IFF_UP;
397 static const struct file_operations fops_reset = {
398 .write = wil_write_file_reset,
399 .open = wil_default_open,
401 /*---------Tx descriptor------------*/
403 static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
405 struct wil6210_priv *wil = s->private;
406 struct vring *vring = &(wil->vring_tx[0]);
409 seq_printf(s, "No Tx VRING\n");
413 if (dbg_txdesc_index < vring->size) {
414 volatile struct vring_tx_desc *d =
415 &(vring->va[dbg_txdesc_index].tx);
416 volatile u32 *u = (volatile u32 *)d;
417 struct sk_buff *skb = vring->ctx[dbg_txdesc_index];
419 seq_printf(s, "Tx[%3d] = {\n", dbg_txdesc_index);
420 seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
421 u[0], u[1], u[2], u[3]);
422 seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
423 u[4], u[5], u[6], u[7]);
424 seq_printf(s, " SKB = %p\n", skb);
427 unsigned char printbuf[16 * 3 + 2];
429 int len = skb_headlen(skb);
432 seq_printf(s, " len = %d\n", len);
435 int l = min(len - i, 16);
436 hex_dump_to_buffer(p + i, l, 16, 1, printbuf,
437 sizeof(printbuf), false);
438 seq_printf(s, " : %s\n", printbuf);
442 seq_printf(s, "}\n");
444 seq_printf(s, "TxDesc index (%d) >= size (%d)\n",
445 dbg_txdesc_index, vring->size);
451 static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
453 return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
456 static const struct file_operations fops_txdesc = {
457 .open = wil_txdesc_seq_open,
458 .release = single_release,
463 /*---------beamforming------------*/
464 static int wil_bf_debugfs_show(struct seq_file *s, void *data)
466 struct wil6210_priv *wil = s->private;
470 "Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n",
471 wil->stats.tsf, wil->stats.bf_mcs,
472 wil->stats.my_rx_sector, wil->stats.my_tx_sector,
473 wil->stats.peer_rx_sector, wil->stats.peer_tx_sector);
477 static int wil_bf_seq_open(struct inode *inode, struct file *file)
479 return single_open(file, wil_bf_debugfs_show, inode->i_private);
482 static const struct file_operations fops_bf = {
483 .open = wil_bf_seq_open,
484 .release = single_release,
488 /*---------SSID------------*/
489 static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf,
490 size_t count, loff_t *ppos)
492 struct wil6210_priv *wil = file->private_data;
493 struct wireless_dev *wdev = wil_to_wdev(wil);
495 return simple_read_from_buffer(user_buf, count, ppos,
496 wdev->ssid, wdev->ssid_len);
499 static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf,
500 size_t count, loff_t *ppos)
502 struct wil6210_priv *wil = file->private_data;
503 struct wireless_dev *wdev = wil_to_wdev(wil);
504 struct net_device *ndev = wil_to_ndev(wil);
507 wil_err(wil, "Unable to set SSID substring from [%d]\n",
512 if (count > sizeof(wdev->ssid)) {
513 wil_err(wil, "SSID too long, len = %d\n", (int)count);
516 if (netif_running(ndev)) {
517 wil_err(wil, "Unable to change SSID on running interface\n");
521 wdev->ssid_len = count;
522 return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos,
526 static const struct file_operations fops_ssid = {
527 .read = wil_read_file_ssid,
528 .write = wil_write_file_ssid,
529 .open = wil_default_open,
533 int wil6210_debugfs_init(struct wil6210_priv *wil)
535 struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
536 wil_to_wiphy(wil)->debugfsdir);
538 if (IS_ERR_OR_NULL(dbg))
541 debugfs_create_file("mbox", S_IRUGO, dbg, wil, &fops_mbox);
542 debugfs_create_file("vrings", S_IRUGO, dbg, wil, &fops_vring);
543 debugfs_create_file("txdesc", S_IRUGO, dbg, wil, &fops_txdesc);
544 debugfs_create_u32("txdesc_index", S_IRUGO | S_IWUSR, dbg,
546 debugfs_create_file("bf", S_IRUGO, dbg, wil, &fops_bf);
547 debugfs_create_file("ssid", S_IRUGO | S_IWUSR, dbg, wil, &fops_ssid);
548 debugfs_create_u32("secure_pcp", S_IRUGO | S_IWUSR, dbg,
551 wil6210_debugfs_create_ISR(wil, "USER_ICR", dbg,
552 HOSTADDR(RGF_USER_USER_ICR));
553 wil6210_debugfs_create_ISR(wil, "DMA_EP_TX_ICR", dbg,
554 HOSTADDR(RGF_DMA_EP_TX_ICR));
555 wil6210_debugfs_create_ISR(wil, "DMA_EP_RX_ICR", dbg,
556 HOSTADDR(RGF_DMA_EP_RX_ICR));
557 wil6210_debugfs_create_ISR(wil, "DMA_EP_MISC_ICR", dbg,
558 HOSTADDR(RGF_DMA_EP_MISC_ICR));
559 wil6210_debugfs_create_pseudo_ISR(wil, dbg);
560 wil6210_debugfs_create_ITR_CNT(wil, dbg);
562 debugfs_create_u32("mem_addr", S_IRUGO | S_IWUSR, dbg, &mem_addr);
563 debugfs_create_file("mem_val", S_IRUGO, dbg, wil, &fops_memread);
565 debugfs_create_file("reset", S_IWUSR, dbg, wil, &fops_reset);
567 wil->rgf_blob.data = (void * __force)wil->csr + 0;
568 wil->rgf_blob.size = 0xa000;
569 wil_debugfs_create_ioblob("blob_rgf", S_IRUGO, dbg, &wil->rgf_blob);
571 wil->fw_code_blob.data = (void * __force)wil->csr + 0x40000;
572 wil->fw_code_blob.size = 0x40000;
573 wil_debugfs_create_ioblob("blob_fw_code", S_IRUGO, dbg,
576 wil->fw_data_blob.data = (void * __force)wil->csr + 0x80000;
577 wil->fw_data_blob.size = 0x8000;
578 wil_debugfs_create_ioblob("blob_fw_data", S_IRUGO, dbg,
581 wil->fw_peri_blob.data = (void * __force)wil->csr + 0x88000;
582 wil->fw_peri_blob.size = 0x18000;
583 wil_debugfs_create_ioblob("blob_fw_peri", S_IRUGO, dbg,
586 wil->uc_code_blob.data = (void * __force)wil->csr + 0xa0000;
587 wil->uc_code_blob.size = 0x10000;
588 wil_debugfs_create_ioblob("blob_uc_code", S_IRUGO, dbg,
591 wil->uc_data_blob.data = (void * __force)wil->csr + 0xb0000;
592 wil->uc_data_blob.size = 0x4000;
593 wil_debugfs_create_ioblob("blob_uc_data", S_IRUGO, dbg,
599 void wil6210_debugfs_remove(struct wil6210_priv *wil)
601 debugfs_remove_recursive(wil->debug);