blob: 729e774ee96d5ff973e16b9ceeda52c0d3f040ee [file] [log] [blame]
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001/*
2 * Copyright (c) 2012 Qualcomm Atheros, Inc.
3 *
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.
7 *
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.
15 */
16
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
23#include "wil6210.h"
24#include "txrx.h"
25
26/* Nasty hack. Better have per device instances */
27static u32 mem_addr;
28static u32 dbg_txdesc_index;
Vladimir Kondratiev3a85543e2014-02-27 16:20:41 +020029static u32 dbg_vring_index; /* 25 for Rx, 0..24 for Tx */
30#define WIL_DBG_VRING_INDEX_RX (WIL6210_MAX_TX_RINGS + 1)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080031
32static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil,
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +020033 const char *name, struct vring *vring,
34 char _s, char _h)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080035{
36 void __iomem *x = wmi_addr(wil, vring->hwtail);
37
38 seq_printf(s, "VRING %s = {\n", name);
39 seq_printf(s, " pa = 0x%016llx\n", (unsigned long long)vring->pa);
40 seq_printf(s, " va = 0x%p\n", vring->va);
41 seq_printf(s, " size = %d\n", vring->size);
42 seq_printf(s, " swtail = %d\n", vring->swtail);
43 seq_printf(s, " swhead = %d\n", vring->swhead);
44 seq_printf(s, " hwtail = [0x%08x] -> ", vring->hwtail);
45 if (x)
46 seq_printf(s, "0x%08x\n", ioread32(x));
47 else
48 seq_printf(s, "???\n");
49
50 if (vring->va && (vring->size < 1025)) {
51 uint i;
52 for (i = 0; i < vring->size; i++) {
53 volatile struct vring_tx_desc *d = &vring->va[i].tx;
54 if ((i % 64) == 0 && (i != 0))
55 seq_printf(s, "\n");
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +020056 seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
57 _s : (vring->ctx[i].skb ? _h : 'h'));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080058 }
59 seq_printf(s, "\n");
60 }
61 seq_printf(s, "}\n");
62}
63
64static int wil_vring_debugfs_show(struct seq_file *s, void *data)
65{
66 uint i;
67 struct wil6210_priv *wil = s->private;
68
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +020069 wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_');
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080070
71 for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
72 struct vring *vring = &(wil->vring_tx[i]);
73 if (vring->va) {
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +020074 int cid = wil->vring2cid_tid[i][0];
75 int tid = wil->vring2cid_tid[i][1];
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080076 char name[10];
77 snprintf(name, sizeof(name), "tx_%2d", i);
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +020078
79 seq_printf(s, "\n%pM CID %d TID %d\n",
80 wil->sta[cid].addr, cid, tid);
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +020081 wil_print_vring(s, wil, name, vring, '_', 'H');
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080082 }
83 }
84
85 return 0;
86}
87
88static int wil_vring_seq_open(struct inode *inode, struct file *file)
89{
90 return single_open(file, wil_vring_debugfs_show, inode->i_private);
91}
92
93static const struct file_operations fops_vring = {
94 .open = wil_vring_seq_open,
95 .release = single_release,
96 .read = seq_read,
97 .llseek = seq_lseek,
98};
99
100static void wil_print_ring(struct seq_file *s, const char *prefix,
101 void __iomem *off)
102{
103 struct wil6210_priv *wil = s->private;
104 struct wil6210_mbox_ring r;
105 int rsize;
106 uint i;
107
108 wil_memcpy_fromio_32(&r, off, sizeof(r));
109 wil_mbox_ring_le2cpus(&r);
110 /*
111 * we just read memory block from NIC. This memory may be
112 * garbage. Check validity before using it.
113 */
114 rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
115
116 seq_printf(s, "ring %s = {\n", prefix);
117 seq_printf(s, " base = 0x%08x\n", r.base);
118 seq_printf(s, " size = 0x%04x bytes -> %d entries\n", r.size, rsize);
119 seq_printf(s, " tail = 0x%08x\n", r.tail);
120 seq_printf(s, " head = 0x%08x\n", r.head);
121 seq_printf(s, " entry size = %d\n", r.entry_size);
122
123 if (r.size % sizeof(struct wil6210_mbox_ring_desc)) {
124 seq_printf(s, " ??? size is not multiple of %zd, garbage?\n",
125 sizeof(struct wil6210_mbox_ring_desc));
126 goto out;
127 }
128
129 if (!wmi_addr(wil, r.base) ||
130 !wmi_addr(wil, r.tail) ||
131 !wmi_addr(wil, r.head)) {
132 seq_printf(s, " ??? pointers are garbage?\n");
133 goto out;
134 }
135
136 for (i = 0; i < rsize; i++) {
137 struct wil6210_mbox_ring_desc d;
138 struct wil6210_mbox_hdr hdr;
139 size_t delta = i * sizeof(d);
140 void __iomem *x = wil->csr + HOSTADDR(r.base) + delta;
141
142 wil_memcpy_fromio_32(&d, x, sizeof(d));
143
144 seq_printf(s, " [%2x] %s %s%s 0x%08x", i,
145 d.sync ? "F" : "E",
146 (r.tail - r.base == delta) ? "t" : " ",
147 (r.head - r.base == delta) ? "h" : " ",
148 le32_to_cpu(d.addr));
149 if (0 == wmi_read_hdr(wil, d.addr, &hdr)) {
150 u16 len = le16_to_cpu(hdr.len);
151 seq_printf(s, " -> %04x %04x %04x %02x\n",
152 le16_to_cpu(hdr.seq), len,
153 le16_to_cpu(hdr.type), hdr.flags);
154 if (len <= MAX_MBOXITEM_SIZE) {
155 int n = 0;
Larry Finger5d216082013-07-20 21:46:48 -0500156 char printbuf[16 * 3 + 2];
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800157 unsigned char databuf[MAX_MBOXITEM_SIZE];
158 void __iomem *src = wmi_buffer(wil, d.addr) +
159 sizeof(struct wil6210_mbox_hdr);
160 /*
161 * No need to check @src for validity -
162 * we already validated @d.addr while
163 * reading header
164 */
165 wil_memcpy_fromio_32(databuf, src, len);
166 while (n < len) {
167 int l = min(len - n, 16);
168 hex_dump_to_buffer(databuf + n, l,
169 16, 1, printbuf,
170 sizeof(printbuf),
171 false);
172 seq_printf(s, " : %s\n", printbuf);
173 n += l;
174 }
175 }
176 } else {
177 seq_printf(s, "\n");
178 }
179 }
180 out:
181 seq_printf(s, "}\n");
182}
183
184static int wil_mbox_debugfs_show(struct seq_file *s, void *data)
185{
186 struct wil6210_priv *wil = s->private;
187
188 wil_print_ring(s, "tx", wil->csr + HOST_MBOX +
189 offsetof(struct wil6210_mbox_ctl, tx));
190 wil_print_ring(s, "rx", wil->csr + HOST_MBOX +
191 offsetof(struct wil6210_mbox_ctl, rx));
192
193 return 0;
194}
195
196static int wil_mbox_seq_open(struct inode *inode, struct file *file)
197{
198 return single_open(file, wil_mbox_debugfs_show, inode->i_private);
199}
200
201static const struct file_operations fops_mbox = {
202 .open = wil_mbox_seq_open,
203 .release = single_release,
204 .read = seq_read,
205 .llseek = seq_lseek,
206};
207
208static int wil_debugfs_iomem_x32_set(void *data, u64 val)
209{
210 iowrite32(val, (void __iomem *)data);
211 wmb(); /* make sure write propagated to HW */
212
213 return 0;
214}
215
216static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
217{
218 *val = ioread32((void __iomem *)data);
219
220 return 0;
221}
222
223DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
224 wil_debugfs_iomem_x32_set, "0x%08llx\n");
225
226static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
Al Viro0ecc8332013-03-29 12:23:28 -0400227 umode_t mode,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800228 struct dentry *parent,
229 void __iomem *value)
230{
231 return debugfs_create_file(name, mode, parent, (void * __force)value,
232 &fops_iomem_x32);
233}
234
235static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
236 const char *name,
237 struct dentry *parent, u32 off)
238{
239 struct dentry *d = debugfs_create_dir(name, parent);
240
241 if (IS_ERR_OR_NULL(d))
242 return -ENODEV;
243
244 wil_debugfs_create_iomem_x32("ICC", S_IRUGO | S_IWUSR, d,
245 wil->csr + off);
246 wil_debugfs_create_iomem_x32("ICR", S_IRUGO | S_IWUSR, d,
247 wil->csr + off + 4);
248 wil_debugfs_create_iomem_x32("ICM", S_IRUGO | S_IWUSR, d,
249 wil->csr + off + 8);
250 wil_debugfs_create_iomem_x32("ICS", S_IWUSR, d,
251 wil->csr + off + 12);
252 wil_debugfs_create_iomem_x32("IMV", S_IRUGO | S_IWUSR, d,
253 wil->csr + off + 16);
254 wil_debugfs_create_iomem_x32("IMS", S_IWUSR, d,
255 wil->csr + off + 20);
256 wil_debugfs_create_iomem_x32("IMC", S_IWUSR, d,
257 wil->csr + off + 24);
258
259 return 0;
260}
261
262static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
263 struct dentry *parent)
264{
265 struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
266
267 if (IS_ERR_OR_NULL(d))
268 return -ENODEV;
269
270 wil_debugfs_create_iomem_x32("CAUSE", S_IRUGO, d, wil->csr +
271 HOSTADDR(RGF_DMA_PSEUDO_CAUSE));
272 wil_debugfs_create_iomem_x32("MASK_SW", S_IRUGO, d, wil->csr +
273 HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW));
274 wil_debugfs_create_iomem_x32("MASK_FW", S_IRUGO, d, wil->csr +
275 HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW));
276
277 return 0;
278}
279
280static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
281 struct dentry *parent)
282{
283 struct dentry *d = debugfs_create_dir("ITR_CNT", parent);
284
285 if (IS_ERR_OR_NULL(d))
286 return -ENODEV;
287
288 wil_debugfs_create_iomem_x32("TRSH", S_IRUGO, d, wil->csr +
289 HOSTADDR(RGF_DMA_ITR_CNT_TRSH));
290 wil_debugfs_create_iomem_x32("DATA", S_IRUGO, d, wil->csr +
291 HOSTADDR(RGF_DMA_ITR_CNT_DATA));
292 wil_debugfs_create_iomem_x32("CTL", S_IRUGO, d, wil->csr +
293 HOSTADDR(RGF_DMA_ITR_CNT_CRL));
294
295 return 0;
296}
297
298static int wil_memread_debugfs_show(struct seq_file *s, void *data)
299{
300 struct wil6210_priv *wil = s->private;
301 void __iomem *a = wmi_buffer(wil, cpu_to_le32(mem_addr));
302
303 if (a)
304 seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, ioread32(a));
305 else
306 seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
307
308 return 0;
309}
310
311static int wil_memread_seq_open(struct inode *inode, struct file *file)
312{
313 return single_open(file, wil_memread_debugfs_show, inode->i_private);
314}
315
316static const struct file_operations fops_memread = {
317 .open = wil_memread_seq_open,
318 .release = single_release,
319 .read = seq_read,
320 .llseek = seq_lseek,
321};
322
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800323static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
324 size_t count, loff_t *ppos)
325{
326 enum { max_count = 4096 };
327 struct debugfs_blob_wrapper *blob = file->private_data;
328 loff_t pos = *ppos;
329 size_t available = blob->size;
330 void *buf;
331 size_t ret;
332
333 if (pos < 0)
334 return -EINVAL;
335
336 if (pos >= available || !count)
337 return 0;
338
339 if (count > available - pos)
340 count = available - pos;
341 if (count > max_count)
342 count = max_count;
343
344 buf = kmalloc(count, GFP_KERNEL);
345 if (!buf)
346 return -ENOMEM;
347
348 wil_memcpy_fromio_32(buf, (const volatile void __iomem *)blob->data +
349 pos, count);
350
351 ret = copy_to_user(user_buf, buf, count);
352 kfree(buf);
353 if (ret == count)
354 return -EFAULT;
355
356 count -= ret;
357 *ppos = pos + count;
358
359 return count;
360}
361
362static const struct file_operations fops_ioblob = {
363 .read = wil_read_file_ioblob,
Wei Yongjun93ecbd62013-02-26 10:29:34 +0800364 .open = simple_open,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800365 .llseek = default_llseek,
366};
367
368static
369struct dentry *wil_debugfs_create_ioblob(const char *name,
Al Viro0ecc8332013-03-29 12:23:28 -0400370 umode_t mode,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800371 struct dentry *parent,
372 struct debugfs_blob_wrapper *blob)
373{
374 return debugfs_create_file(name, mode, parent, blob, &fops_ioblob);
375}
376/*---reset---*/
377static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
378 size_t len, loff_t *ppos)
379{
380 struct wil6210_priv *wil = file->private_data;
381 struct net_device *ndev = wil_to_ndev(wil);
382
383 /**
384 * BUG:
385 * this code does NOT sync device state with the rest of system
386 * use with care, debug only!!!
387 */
388 rtnl_lock();
389 dev_close(ndev);
390 ndev->flags &= ~IFF_UP;
391 rtnl_unlock();
392 wil_reset(wil);
393
394 return len;
395}
396
397static const struct file_operations fops_reset = {
398 .write = wil_write_file_reset,
Wei Yongjun93ecbd62013-02-26 10:29:34 +0800399 .open = simple_open,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800400};
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800401
Vladimir Kondratiev3a85543e2014-02-27 16:20:41 +0200402/*---------Tx/Rx descriptor------------*/
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800403static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
404{
405 struct wil6210_priv *wil = s->private;
Vladimir Kondratiev3a85543e2014-02-27 16:20:41 +0200406 struct vring *vring;
407 if (dbg_vring_index <= WIL6210_MAX_TX_RINGS)
408 vring = &(wil->vring_tx[dbg_vring_index]);
409 else
410 vring = &wil->vring_rx;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800411
412 if (!vring->va) {
Vladimir Kondratiev3a85543e2014-02-27 16:20:41 +0200413 if (dbg_vring_index <= WIL6210_MAX_TX_RINGS)
414 seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index);
415 else
416 seq_puts(s, "No Rx VRING\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800417 return 0;
418 }
419
420 if (dbg_txdesc_index < vring->size) {
Vladimir Kondratiev3a85543e2014-02-27 16:20:41 +0200421 /* use struct vring_tx_desc for Rx as well,
422 * only field used, .dma.length, is the same
423 */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800424 volatile struct vring_tx_desc *d =
425 &(vring->va[dbg_txdesc_index].tx);
426 volatile u32 *u = (volatile u32 *)d;
Vladimir Kondratievf88f1132013-07-11 18:03:40 +0300427 struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800428
Vladimir Kondratiev3a85543e2014-02-27 16:20:41 +0200429 if (dbg_vring_index <= WIL6210_MAX_TX_RINGS)
430 seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index,
431 dbg_txdesc_index);
432 else
433 seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800434 seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
435 u[0], u[1], u[2], u[3]);
436 seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
437 u[4], u[5], u[6], u[7]);
438 seq_printf(s, " SKB = %p\n", skb);
439
440 if (skb) {
Larry Finger5d216082013-07-20 21:46:48 -0500441 char printbuf[16 * 3 + 2];
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800442 int i = 0;
Vladimir Kondratiev7e5944442013-05-12 14:43:32 +0300443 int len = le16_to_cpu(d->dma.length);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800444 void *p = skb->data;
445
Vladimir Kondratiev7e5944442013-05-12 14:43:32 +0300446 if (len != skb_headlen(skb)) {
447 seq_printf(s, "!!! len: desc = %d skb = %d\n",
448 len, skb_headlen(skb));
449 len = min_t(int, len, skb_headlen(skb));
450 }
451
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800452 seq_printf(s, " len = %d\n", len);
453
454 while (i < len) {
455 int l = min(len - i, 16);
456 hex_dump_to_buffer(p + i, l, 16, 1, printbuf,
457 sizeof(printbuf), false);
458 seq_printf(s, " : %s\n", printbuf);
459 i += l;
460 }
461 }
462 seq_printf(s, "}\n");
463 } else {
Vladimir Kondratiev3a85543e2014-02-27 16:20:41 +0200464 if (dbg_vring_index <= WIL6210_MAX_TX_RINGS)
465 seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
466 dbg_vring_index, dbg_txdesc_index,
467 vring->size);
468 else
469 seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
470 dbg_txdesc_index, vring->size);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800471 }
472
473 return 0;
474}
475
476static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
477{
478 return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
479}
480
481static const struct file_operations fops_txdesc = {
482 .open = wil_txdesc_seq_open,
483 .release = single_release,
484 .read = seq_read,
485 .llseek = seq_lseek,
486};
487
488/*---------beamforming------------*/
489static int wil_bf_debugfs_show(struct seq_file *s, void *data)
490{
491 struct wil6210_priv *wil = s->private;
492 seq_printf(s,
493 "TSF : 0x%016llx\n"
494 "TxMCS : %d\n"
495 "Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n",
496 wil->stats.tsf, wil->stats.bf_mcs,
497 wil->stats.my_rx_sector, wil->stats.my_tx_sector,
498 wil->stats.peer_rx_sector, wil->stats.peer_tx_sector);
499 return 0;
500}
501
502static int wil_bf_seq_open(struct inode *inode, struct file *file)
503{
504 return single_open(file, wil_bf_debugfs_show, inode->i_private);
505}
506
507static const struct file_operations fops_bf = {
508 .open = wil_bf_seq_open,
509 .release = single_release,
510 .read = seq_read,
511 .llseek = seq_lseek,
512};
513/*---------SSID------------*/
514static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf,
515 size_t count, loff_t *ppos)
516{
517 struct wil6210_priv *wil = file->private_data;
518 struct wireless_dev *wdev = wil_to_wdev(wil);
519
520 return simple_read_from_buffer(user_buf, count, ppos,
521 wdev->ssid, wdev->ssid_len);
522}
523
524static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf,
525 size_t count, loff_t *ppos)
526{
527 struct wil6210_priv *wil = file->private_data;
528 struct wireless_dev *wdev = wil_to_wdev(wil);
529 struct net_device *ndev = wil_to_ndev(wil);
530
531 if (*ppos != 0) {
532 wil_err(wil, "Unable to set SSID substring from [%d]\n",
533 (int)*ppos);
534 return -EINVAL;
535 }
536
537 if (count > sizeof(wdev->ssid)) {
538 wil_err(wil, "SSID too long, len = %d\n", (int)count);
539 return -EINVAL;
540 }
541 if (netif_running(ndev)) {
542 wil_err(wil, "Unable to change SSID on running interface\n");
543 return -EINVAL;
544 }
545
546 wdev->ssid_len = count;
547 return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos,
548 buf, count);
549}
550
551static const struct file_operations fops_ssid = {
552 .read = wil_read_file_ssid,
553 .write = wil_write_file_ssid,
Wei Yongjun93ecbd62013-02-26 10:29:34 +0800554 .open = simple_open,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800555};
556
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +0200557/*---------temp------------*/
558static void print_temp(struct seq_file *s, const char *prefix, u32 t)
559{
560 switch (t) {
561 case 0:
562 case ~(u32)0:
563 seq_printf(s, "%s N/A\n", prefix);
564 break;
565 default:
566 seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
567 break;
568 }
569}
570
571static int wil_temp_debugfs_show(struct seq_file *s, void *data)
572{
573 struct wil6210_priv *wil = s->private;
574 u32 t_m, t_r;
575
576 int rc = wmi_get_temperature(wil, &t_m, &t_r);
577 if (rc) {
578 seq_printf(s, "Failed\n");
579 return 0;
580 }
581
582 print_temp(s, "MAC temperature :", t_m);
583 print_temp(s, "Radio temperature :", t_r);
584
585 return 0;
586}
587
588static int wil_temp_seq_open(struct inode *inode, struct file *file)
589{
590 return single_open(file, wil_temp_debugfs_show, inode->i_private);
591}
592
593static const struct file_operations fops_temp = {
594 .open = wil_temp_seq_open,
595 .release = single_release,
596 .read = seq_read,
597 .llseek = seq_lseek,
598};
599
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200600/*---------Station matrix------------*/
Vladimir Kondratievb4490f42014-02-27 16:20:44 +0200601static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
602{
603 int i;
604 u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
605 seq_printf(s, "0x%03x [", r->head_seq_num);
606 for (i = 0; i < r->buf_size; i++) {
607 if (i == index)
608 seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
609 else
610 seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
611 }
612 seq_puts(s, "]\n");
613}
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200614
615static int wil_sta_debugfs_show(struct seq_file *s, void *data)
616{
617 struct wil6210_priv *wil = s->private;
Vladimir Kondratievb4490f42014-02-27 16:20:44 +0200618 int i, tid;
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200619
620 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
621 struct wil_sta_info *p = &wil->sta[i];
622 char *status = "unknown";
623 switch (p->status) {
624 case wil_sta_unused:
625 status = "unused ";
626 break;
627 case wil_sta_conn_pending:
628 status = "pending ";
629 break;
630 case wil_sta_connected:
631 status = "connected";
632 break;
633 }
634 seq_printf(s, "[%d] %pM %s\n", i, p->addr, status);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +0200635
636 if (p->status == wil_sta_connected) {
637 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
638 struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
639 if (r) {
640 seq_printf(s, "[%2d] ", tid);
641 wil_print_rxtid(s, r);
642 }
643 }
644 }
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200645 }
646
647 return 0;
648}
649
650static int wil_sta_seq_open(struct inode *inode, struct file *file)
651{
652 return single_open(file, wil_sta_debugfs_show, inode->i_private);
653}
654
655static const struct file_operations fops_sta = {
656 .open = wil_sta_seq_open,
657 .release = single_release,
658 .read = seq_read,
659 .llseek = seq_lseek,
660};
661
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800662/*----------------*/
663int wil6210_debugfs_init(struct wil6210_priv *wil)
664{
665 struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
666 wil_to_wiphy(wil)->debugfsdir);
667
668 if (IS_ERR_OR_NULL(dbg))
669 return -ENODEV;
670
671 debugfs_create_file("mbox", S_IRUGO, dbg, wil, &fops_mbox);
672 debugfs_create_file("vrings", S_IRUGO, dbg, wil, &fops_vring);
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200673 debugfs_create_file("stations", S_IRUGO, dbg, wil, &fops_sta);
Vladimir Kondratiev3a85543e2014-02-27 16:20:41 +0200674 debugfs_create_file("desc", S_IRUGO, dbg, wil, &fops_txdesc);
675 debugfs_create_u32("desc_index", S_IRUGO | S_IWUSR, dbg,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800676 &dbg_txdesc_index);
Vladimir Kondratiev3a85543e2014-02-27 16:20:41 +0200677 debugfs_create_u32("vring_index", S_IRUGO | S_IWUSR, dbg,
678 &dbg_vring_index);
679
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800680 debugfs_create_file("bf", S_IRUGO, dbg, wil, &fops_bf);
681 debugfs_create_file("ssid", S_IRUGO | S_IWUSR, dbg, wil, &fops_ssid);
682 debugfs_create_u32("secure_pcp", S_IRUGO | S_IWUSR, dbg,
683 &wil->secure_pcp);
684
685 wil6210_debugfs_create_ISR(wil, "USER_ICR", dbg,
686 HOSTADDR(RGF_USER_USER_ICR));
687 wil6210_debugfs_create_ISR(wil, "DMA_EP_TX_ICR", dbg,
688 HOSTADDR(RGF_DMA_EP_TX_ICR));
689 wil6210_debugfs_create_ISR(wil, "DMA_EP_RX_ICR", dbg,
690 HOSTADDR(RGF_DMA_EP_RX_ICR));
691 wil6210_debugfs_create_ISR(wil, "DMA_EP_MISC_ICR", dbg,
692 HOSTADDR(RGF_DMA_EP_MISC_ICR));
693 wil6210_debugfs_create_pseudo_ISR(wil, dbg);
694 wil6210_debugfs_create_ITR_CNT(wil, dbg);
695
696 debugfs_create_u32("mem_addr", S_IRUGO | S_IWUSR, dbg, &mem_addr);
697 debugfs_create_file("mem_val", S_IRUGO, dbg, wil, &fops_memread);
698
699 debugfs_create_file("reset", S_IWUSR, dbg, wil, &fops_reset);
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +0200700 debugfs_create_file("temp", S_IRUGO, dbg, wil, &fops_temp);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800701
702 wil->rgf_blob.data = (void * __force)wil->csr + 0;
703 wil->rgf_blob.size = 0xa000;
704 wil_debugfs_create_ioblob("blob_rgf", S_IRUGO, dbg, &wil->rgf_blob);
705
706 wil->fw_code_blob.data = (void * __force)wil->csr + 0x40000;
707 wil->fw_code_blob.size = 0x40000;
708 wil_debugfs_create_ioblob("blob_fw_code", S_IRUGO, dbg,
709 &wil->fw_code_blob);
710
711 wil->fw_data_blob.data = (void * __force)wil->csr + 0x80000;
712 wil->fw_data_blob.size = 0x8000;
713 wil_debugfs_create_ioblob("blob_fw_data", S_IRUGO, dbg,
714 &wil->fw_data_blob);
715
716 wil->fw_peri_blob.data = (void * __force)wil->csr + 0x88000;
717 wil->fw_peri_blob.size = 0x18000;
718 wil_debugfs_create_ioblob("blob_fw_peri", S_IRUGO, dbg,
719 &wil->fw_peri_blob);
720
721 wil->uc_code_blob.data = (void * __force)wil->csr + 0xa0000;
722 wil->uc_code_blob.size = 0x10000;
723 wil_debugfs_create_ioblob("blob_uc_code", S_IRUGO, dbg,
724 &wil->uc_code_blob);
725
726 wil->uc_data_blob.data = (void * __force)wil->csr + 0xb0000;
727 wil->uc_data_blob.size = 0x4000;
728 wil_debugfs_create_ioblob("blob_uc_data", S_IRUGO, dbg,
729 &wil->uc_data_blob);
730
731 return 0;
732}
733
734void wil6210_debugfs_remove(struct wil6210_priv *wil)
735{
736 debugfs_remove_recursive(wil->debug);
737 wil->debug = NULL;
738}