blob: b1c6a7293390a4364450c778b1ed24b156a2c77d [file] [log] [blame]
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001/*
Vladimir Kondratiev02525a72014-08-06 10:31:51 +03002 * Copyright (c) 2012-2014 Qualcomm Atheros, Inc.
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08003 *
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>
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +030022#include <linux/power_supply.h>
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080023
24#include "wil6210.h"
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +030025#include "wmi.h"
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080026#include "txrx.h"
27
28/* Nasty hack. Better have per device instances */
29static u32 mem_addr;
30static u32 dbg_txdesc_index;
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +020031static u32 dbg_vring_index; /* 24+ for Rx, 0..23 for Tx */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080032
Vladimir Kondratievb7cde472014-08-06 10:31:55 +030033enum dbg_off_type {
34 doff_u32 = 0,
35 doff_x32 = 1,
36 doff_ulong = 2,
37 doff_io32 = 3,
38};
39
40/* offset to "wil" */
41struct dbg_off {
42 const char *name;
43 umode_t mode;
44 ulong off;
45 enum dbg_off_type type;
46};
47
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080048static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil,
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +020049 const char *name, struct vring *vring,
50 char _s, char _h)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080051{
52 void __iomem *x = wmi_addr(wil, vring->hwtail);
53
54 seq_printf(s, "VRING %s = {\n", name);
Vladimir Kondratiev39c52ee2014-05-27 14:45:49 +030055 seq_printf(s, " pa = %pad\n", &vring->pa);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080056 seq_printf(s, " va = 0x%p\n", vring->va);
57 seq_printf(s, " size = %d\n", vring->size);
58 seq_printf(s, " swtail = %d\n", vring->swtail);
59 seq_printf(s, " swhead = %d\n", vring->swhead);
60 seq_printf(s, " hwtail = [0x%08x] -> ", vring->hwtail);
61 if (x)
62 seq_printf(s, "0x%08x\n", ioread32(x));
63 else
64 seq_printf(s, "???\n");
65
66 if (vring->va && (vring->size < 1025)) {
67 uint i;
68 for (i = 0; i < vring->size; i++) {
69 volatile struct vring_tx_desc *d = &vring->va[i].tx;
70 if ((i % 64) == 0 && (i != 0))
71 seq_printf(s, "\n");
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +020072 seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
73 _s : (vring->ctx[i].skb ? _h : 'h'));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080074 }
75 seq_printf(s, "\n");
76 }
77 seq_printf(s, "}\n");
78}
79
80static int wil_vring_debugfs_show(struct seq_file *s, void *data)
81{
82 uint i;
83 struct wil6210_priv *wil = s->private;
84
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +020085 wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_');
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080086
87 for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
88 struct vring *vring = &(wil->vring_tx[i]);
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +030089 struct vring_tx_data *txdata = &wil->vring_tx_data[i];
90
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080091 if (vring->va) {
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +020092 int cid = wil->vring2cid_tid[i][0];
93 int tid = wil->vring2cid_tid[i][1];
Vladimir Kondratiev67c3e1b2014-06-16 19:37:04 +030094 u32 swhead = vring->swhead;
95 u32 swtail = vring->swtail;
96 int used = (vring->size + swhead - swtail)
97 % vring->size;
98 int avail = vring->size - used - 1;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080099 char name[10];
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +0300100 /* performance monitoring */
101 cycles_t now = get_cycles();
Vladimir Kondratieve48b1792014-06-20 10:05:07 +0300102 cycles_t idle = txdata->idle * 100;
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +0300103 cycles_t total = now - txdata->begin;
104
Vladimir Kondratieve48b1792014-06-20 10:05:07 +0300105 do_div(idle, total);
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +0300106 txdata->begin = now;
107 txdata->idle = 0ULL;
108
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800109 snprintf(name, sizeof(name), "tx_%2d", i);
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200110
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +0300111 seq_printf(s, "\n%pM CID %d TID %d [%3d|%3d] idle %3d%%\n",
112 wil->sta[cid].addr, cid, tid, used, avail,
Vladimir Kondratieve48b1792014-06-20 10:05:07 +0300113 (int)idle);
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +0300114
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +0200115 wil_print_vring(s, wil, name, vring, '_', 'H');
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800116 }
117 }
118
119 return 0;
120}
121
122static int wil_vring_seq_open(struct inode *inode, struct file *file)
123{
124 return single_open(file, wil_vring_debugfs_show, inode->i_private);
125}
126
127static const struct file_operations fops_vring = {
128 .open = wil_vring_seq_open,
129 .release = single_release,
130 .read = seq_read,
131 .llseek = seq_lseek,
132};
133
134static void wil_print_ring(struct seq_file *s, const char *prefix,
135 void __iomem *off)
136{
137 struct wil6210_priv *wil = s->private;
138 struct wil6210_mbox_ring r;
139 int rsize;
140 uint i;
141
142 wil_memcpy_fromio_32(&r, off, sizeof(r));
143 wil_mbox_ring_le2cpus(&r);
144 /*
145 * we just read memory block from NIC. This memory may be
146 * garbage. Check validity before using it.
147 */
148 rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
149
150 seq_printf(s, "ring %s = {\n", prefix);
151 seq_printf(s, " base = 0x%08x\n", r.base);
152 seq_printf(s, " size = 0x%04x bytes -> %d entries\n", r.size, rsize);
153 seq_printf(s, " tail = 0x%08x\n", r.tail);
154 seq_printf(s, " head = 0x%08x\n", r.head);
155 seq_printf(s, " entry size = %d\n", r.entry_size);
156
157 if (r.size % sizeof(struct wil6210_mbox_ring_desc)) {
158 seq_printf(s, " ??? size is not multiple of %zd, garbage?\n",
159 sizeof(struct wil6210_mbox_ring_desc));
160 goto out;
161 }
162
163 if (!wmi_addr(wil, r.base) ||
164 !wmi_addr(wil, r.tail) ||
165 !wmi_addr(wil, r.head)) {
166 seq_printf(s, " ??? pointers are garbage?\n");
167 goto out;
168 }
169
170 for (i = 0; i < rsize; i++) {
171 struct wil6210_mbox_ring_desc d;
172 struct wil6210_mbox_hdr hdr;
173 size_t delta = i * sizeof(d);
174 void __iomem *x = wil->csr + HOSTADDR(r.base) + delta;
175
176 wil_memcpy_fromio_32(&d, x, sizeof(d));
177
178 seq_printf(s, " [%2x] %s %s%s 0x%08x", i,
179 d.sync ? "F" : "E",
180 (r.tail - r.base == delta) ? "t" : " ",
181 (r.head - r.base == delta) ? "h" : " ",
182 le32_to_cpu(d.addr));
183 if (0 == wmi_read_hdr(wil, d.addr, &hdr)) {
184 u16 len = le16_to_cpu(hdr.len);
185 seq_printf(s, " -> %04x %04x %04x %02x\n",
186 le16_to_cpu(hdr.seq), len,
187 le16_to_cpu(hdr.type), hdr.flags);
188 if (len <= MAX_MBOXITEM_SIZE) {
189 int n = 0;
Larry Finger5d216082013-07-20 21:46:48 -0500190 char printbuf[16 * 3 + 2];
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800191 unsigned char databuf[MAX_MBOXITEM_SIZE];
192 void __iomem *src = wmi_buffer(wil, d.addr) +
193 sizeof(struct wil6210_mbox_hdr);
194 /*
195 * No need to check @src for validity -
196 * we already validated @d.addr while
197 * reading header
198 */
199 wil_memcpy_fromio_32(databuf, src, len);
200 while (n < len) {
201 int l = min(len - n, 16);
202 hex_dump_to_buffer(databuf + n, l,
203 16, 1, printbuf,
204 sizeof(printbuf),
205 false);
206 seq_printf(s, " : %s\n", printbuf);
207 n += l;
208 }
209 }
210 } else {
211 seq_printf(s, "\n");
212 }
213 }
214 out:
215 seq_printf(s, "}\n");
216}
217
218static int wil_mbox_debugfs_show(struct seq_file *s, void *data)
219{
220 struct wil6210_priv *wil = s->private;
221
222 wil_print_ring(s, "tx", wil->csr + HOST_MBOX +
223 offsetof(struct wil6210_mbox_ctl, tx));
224 wil_print_ring(s, "rx", wil->csr + HOST_MBOX +
225 offsetof(struct wil6210_mbox_ctl, rx));
226
227 return 0;
228}
229
230static int wil_mbox_seq_open(struct inode *inode, struct file *file)
231{
232 return single_open(file, wil_mbox_debugfs_show, inode->i_private);
233}
234
235static const struct file_operations fops_mbox = {
236 .open = wil_mbox_seq_open,
237 .release = single_release,
238 .read = seq_read,
239 .llseek = seq_lseek,
240};
241
242static int wil_debugfs_iomem_x32_set(void *data, u64 val)
243{
244 iowrite32(val, (void __iomem *)data);
245 wmb(); /* make sure write propagated to HW */
246
247 return 0;
248}
249
250static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
251{
252 *val = ioread32((void __iomem *)data);
253
254 return 0;
255}
256
257DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
258 wil_debugfs_iomem_x32_set, "0x%08llx\n");
259
260static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
Al Viro0ecc8332013-03-29 12:23:28 -0400261 umode_t mode,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800262 struct dentry *parent,
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300263 void *value)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800264{
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300265 return debugfs_create_file(name, mode, parent, value,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800266 &fops_iomem_x32);
267}
268
Vladimir Kondratiev3de6cf22014-06-16 19:37:02 +0300269static int wil_debugfs_ulong_set(void *data, u64 val)
270{
271 *(ulong *)data = val;
272 return 0;
273}
274static int wil_debugfs_ulong_get(void *data, u64 *val)
275{
276 *val = *(ulong *)data;
277 return 0;
278}
279DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
280 wil_debugfs_ulong_set, "%llu\n");
281
282static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode,
283 struct dentry *parent,
284 ulong *value)
285{
286 return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong);
287}
288
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300289/**
290 * wil6210_debugfs_init_offset - create set of debugfs files
291 * @wil - driver's context, used for printing
292 * @dbg - directory on the debugfs, where files will be created
293 * @base - base address used in address calculation
294 * @tbl - table with file descriptions. Should be terminated with empty element.
295 *
296 * Creates files accordingly to the @tbl.
297 */
298static void wil6210_debugfs_init_offset(struct wil6210_priv *wil,
299 struct dentry *dbg, void *base,
300 const struct dbg_off * const tbl)
301{
302 int i;
303
304 for (i = 0; tbl[i].name; i++) {
305 struct dentry *f = NULL;
306
307 switch (tbl[i].type) {
308 case doff_u32:
309 f = debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg,
310 base + tbl[i].off);
311 break;
312 case doff_x32:
313 f = debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg,
314 base + tbl[i].off);
315 break;
316 case doff_ulong:
317 f = wil_debugfs_create_ulong(tbl[i].name, tbl[i].mode,
318 dbg, base + tbl[i].off);
319 break;
320 case doff_io32:
321 f = wil_debugfs_create_iomem_x32(tbl[i].name,
322 tbl[i].mode, dbg,
323 base + tbl[i].off);
324 break;
325 }
326 if (IS_ERR_OR_NULL(f))
327 wil_err(wil, "Create file \"%s\": err %ld\n",
328 tbl[i].name, PTR_ERR(f));
329 }
330}
331
332static const struct dbg_off isr_off[] = {
333 {"ICC", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICC), doff_io32},
334 {"ICR", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICR), doff_io32},
335 {"ICM", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICM), doff_io32},
336 {"ICS", S_IWUSR, offsetof(struct RGF_ICR, ICS), doff_io32},
337 {"IMV", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, IMV), doff_io32},
338 {"IMS", S_IWUSR, offsetof(struct RGF_ICR, IMS), doff_io32},
339 {"IMC", S_IWUSR, offsetof(struct RGF_ICR, IMC), doff_io32},
340 {},
341};
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800342static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
343 const char *name,
344 struct dentry *parent, u32 off)
345{
346 struct dentry *d = debugfs_create_dir(name, parent);
347
348 if (IS_ERR_OR_NULL(d))
349 return -ENODEV;
350
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300351 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off,
352 isr_off);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800353
354 return 0;
355}
356
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300357static const struct dbg_off pseudo_isr_off[] = {
358 {"CAUSE", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32},
359 {"MASK_SW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32},
360 {"MASK_FW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32},
361 {},
362};
363
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800364static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
365 struct dentry *parent)
366{
367 struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
368
369 if (IS_ERR_OR_NULL(d))
370 return -ENODEV;
371
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300372 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
373 pseudo_isr_off);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800374
375 return 0;
376}
377
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300378static const struct dbg_off itr_cnt_off[] = {
379 {"TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32},
380 {"DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32},
381 {"CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32},
382 {},
383};
384
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800385static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
386 struct dentry *parent)
387{
388 struct dentry *d = debugfs_create_dir("ITR_CNT", parent);
389
390 if (IS_ERR_OR_NULL(d))
391 return -ENODEV;
392
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300393 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
394 itr_cnt_off);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800395
396 return 0;
397}
398
399static int wil_memread_debugfs_show(struct seq_file *s, void *data)
400{
401 struct wil6210_priv *wil = s->private;
402 void __iomem *a = wmi_buffer(wil, cpu_to_le32(mem_addr));
403
404 if (a)
405 seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, ioread32(a));
406 else
407 seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
408
409 return 0;
410}
411
412static int wil_memread_seq_open(struct inode *inode, struct file *file)
413{
414 return single_open(file, wil_memread_debugfs_show, inode->i_private);
415}
416
417static const struct file_operations fops_memread = {
418 .open = wil_memread_seq_open,
419 .release = single_release,
420 .read = seq_read,
421 .llseek = seq_lseek,
422};
423
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800424static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
425 size_t count, loff_t *ppos)
426{
427 enum { max_count = 4096 };
428 struct debugfs_blob_wrapper *blob = file->private_data;
429 loff_t pos = *ppos;
430 size_t available = blob->size;
431 void *buf;
432 size_t ret;
433
434 if (pos < 0)
435 return -EINVAL;
436
437 if (pos >= available || !count)
438 return 0;
439
440 if (count > available - pos)
441 count = available - pos;
442 if (count > max_count)
443 count = max_count;
444
445 buf = kmalloc(count, GFP_KERNEL);
446 if (!buf)
447 return -ENOMEM;
448
449 wil_memcpy_fromio_32(buf, (const volatile void __iomem *)blob->data +
450 pos, count);
451
452 ret = copy_to_user(user_buf, buf, count);
453 kfree(buf);
454 if (ret == count)
455 return -EFAULT;
456
457 count -= ret;
458 *ppos = pos + count;
459
460 return count;
461}
462
463static const struct file_operations fops_ioblob = {
464 .read = wil_read_file_ioblob,
Wei Yongjun93ecbd62013-02-26 10:29:34 +0800465 .open = simple_open,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800466 .llseek = default_llseek,
467};
468
469static
470struct dentry *wil_debugfs_create_ioblob(const char *name,
Al Viro0ecc8332013-03-29 12:23:28 -0400471 umode_t mode,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800472 struct dentry *parent,
473 struct debugfs_blob_wrapper *blob)
474{
475 return debugfs_create_file(name, mode, parent, blob, &fops_ioblob);
476}
477/*---reset---*/
478static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
479 size_t len, loff_t *ppos)
480{
481 struct wil6210_priv *wil = file->private_data;
482 struct net_device *ndev = wil_to_ndev(wil);
483
484 /**
485 * BUG:
486 * this code does NOT sync device state with the rest of system
487 * use with care, debug only!!!
488 */
489 rtnl_lock();
490 dev_close(ndev);
491 ndev->flags &= ~IFF_UP;
492 rtnl_unlock();
493 wil_reset(wil);
494
495 return len;
496}
497
498static const struct file_operations fops_reset = {
499 .write = wil_write_file_reset,
Wei Yongjun93ecbd62013-02-26 10:29:34 +0800500 .open = simple_open,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800501};
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300502/*---write channel 1..4 to rxon for it, 0 to rxoff---*/
503static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
504 size_t len, loff_t *ppos)
505{
506 struct wil6210_priv *wil = file->private_data;
507 int rc;
508 long channel;
509 bool on;
510
511 char *kbuf = kmalloc(len + 1, GFP_KERNEL);
512 if (!kbuf)
513 return -ENOMEM;
Vladimir Kondratiev359ee622014-07-14 09:49:40 +0300514 if (copy_from_user(kbuf, buf, len)) {
515 kfree(kbuf);
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300516 return -EIO;
Vladimir Kondratiev359ee622014-07-14 09:49:40 +0300517 }
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300518
519 kbuf[len] = '\0';
520 rc = kstrtol(kbuf, 0, &channel);
521 kfree(kbuf);
522 if (rc)
523 return rc;
524
525 if ((channel < 0) || (channel > 4)) {
526 wil_err(wil, "Invalid channel %ld\n", channel);
527 return -EINVAL;
528 }
529 on = !!channel;
530
531 if (on) {
532 rc = wmi_set_channel(wil, (int)channel);
533 if (rc)
534 return rc;
535 }
536
537 rc = wmi_rxon(wil, on);
538 if (rc)
539 return rc;
540
541 return len;
542}
543
544static const struct file_operations fops_rxon = {
545 .write = wil_write_file_rxon,
546 .open = simple_open,
547};
548/*---tx_mgmt---*/
549/* Write mgmt frame to this file to send it */
550static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
551 size_t len, loff_t *ppos)
552{
553 struct wil6210_priv *wil = file->private_data;
554 struct wiphy *wiphy = wil_to_wiphy(wil);
555 struct wireless_dev *wdev = wil_to_wdev(wil);
556 struct cfg80211_mgmt_tx_params params;
557 int rc;
558
559 void *frame = kmalloc(len, GFP_KERNEL);
560 if (!frame)
561 return -ENOMEM;
562
563 if (copy_from_user(frame, buf, len))
564 return -EIO;
565
566 params.buf = frame;
567 params.len = len;
568 params.chan = wdev->preset_chandef.chan;
569
570 rc = wil_cfg80211_mgmt_tx(wiphy, wdev, &params, NULL);
571
572 kfree(frame);
573 wil_info(wil, "%s() -> %d\n", __func__, rc);
574
575 return len;
576}
577
578static const struct file_operations fops_txmgmt = {
579 .write = wil_write_file_txmgmt,
580 .open = simple_open,
581};
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800582
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300583/* Write WMI command (w/o mbox header) to this file to send it
584 * WMI starts from wil6210_mbox_hdr_wmi header
585 */
586static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
587 size_t len, loff_t *ppos)
588{
589 struct wil6210_priv *wil = file->private_data;
590 struct wil6210_mbox_hdr_wmi *wmi;
591 void *cmd;
592 int cmdlen = len - sizeof(struct wil6210_mbox_hdr_wmi);
593 u16 cmdid;
594 int rc, rc1;
595
596 if (cmdlen <= 0)
597 return -EINVAL;
598
599 wmi = kmalloc(len, GFP_KERNEL);
600 if (!wmi)
601 return -ENOMEM;
602
603 rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
604 if (rc < 0)
605 return rc;
606
607 cmd = &wmi[1];
608 cmdid = le16_to_cpu(wmi->id);
609
610 rc1 = wmi_send(wil, cmdid, cmd, cmdlen);
611 kfree(wmi);
612
613 wil_info(wil, "%s(0x%04x[%d]) -> %d\n", __func__, cmdid, cmdlen, rc1);
614
615 return rc;
616}
617
618static const struct file_operations fops_wmi = {
619 .write = wil_write_file_wmi,
620 .open = simple_open,
621};
622
Vladimir Kondratievc2366582014-03-17 15:34:08 +0200623static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
624 const char *prefix)
625{
626 char printbuf[16 * 3 + 2];
627 int i = 0;
628 while (i < len) {
629 int l = min(len - i, 16);
630 hex_dump_to_buffer(p + i, l, 16, 1, printbuf,
631 sizeof(printbuf), false);
632 seq_printf(s, "%s%s\n", prefix, printbuf);
633 i += l;
634 }
635}
636
637static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
638{
639 int i = 0;
640 int len = skb_headlen(skb);
641 void *p = skb->data;
642 int nr_frags = skb_shinfo(skb)->nr_frags;
643
644 seq_printf(s, " len = %d\n", len);
645 wil_seq_hexdump(s, p, len, " : ");
646
647 if (nr_frags) {
648 seq_printf(s, " nr_frags = %d\n", nr_frags);
649 for (i = 0; i < nr_frags; i++) {
650 const struct skb_frag_struct *frag =
651 &skb_shinfo(skb)->frags[i];
652
653 len = skb_frag_size(frag);
654 p = skb_frag_address_safe(frag);
655 seq_printf(s, " [%2d] : len = %d\n", i, len);
656 wil_seq_hexdump(s, p, len, " : ");
657 }
658 }
659}
660
Vladimir Kondratiev3a85543e2014-02-27 16:20:41 +0200661/*---------Tx/Rx descriptor------------*/
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800662static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
663{
664 struct wil6210_priv *wil = s->private;
Vladimir Kondratiev3a85543e2014-02-27 16:20:41 +0200665 struct vring *vring;
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +0200666 bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS);
667 if (tx)
Vladimir Kondratiev3a85543e2014-02-27 16:20:41 +0200668 vring = &(wil->vring_tx[dbg_vring_index]);
669 else
670 vring = &wil->vring_rx;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800671
672 if (!vring->va) {
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +0200673 if (tx)
Vladimir Kondratiev3a85543e2014-02-27 16:20:41 +0200674 seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index);
675 else
676 seq_puts(s, "No Rx VRING\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800677 return 0;
678 }
679
680 if (dbg_txdesc_index < vring->size) {
Vladimir Kondratiev3a85543e2014-02-27 16:20:41 +0200681 /* use struct vring_tx_desc for Rx as well,
682 * only field used, .dma.length, is the same
683 */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800684 volatile struct vring_tx_desc *d =
685 &(vring->va[dbg_txdesc_index].tx);
686 volatile u32 *u = (volatile u32 *)d;
Vladimir Kondratievf88f1132013-07-11 18:03:40 +0300687 struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800688
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +0200689 if (tx)
Vladimir Kondratiev3a85543e2014-02-27 16:20:41 +0200690 seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index,
691 dbg_txdesc_index);
692 else
693 seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800694 seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
695 u[0], u[1], u[2], u[3]);
696 seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
697 u[4], u[5], u[6], u[7]);
Vladimir Kondratiev39c52ee2014-05-27 14:45:49 +0300698 seq_printf(s, " SKB = 0x%p\n", skb);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800699
700 if (skb) {
Vladimir Kondratievc2366582014-03-17 15:34:08 +0200701 skb_get(skb);
702 wil_seq_print_skb(s, skb);
703 kfree_skb(skb);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800704 }
705 seq_printf(s, "}\n");
706 } else {
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +0200707 if (tx)
Vladimir Kondratiev3a85543e2014-02-27 16:20:41 +0200708 seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
709 dbg_vring_index, dbg_txdesc_index,
710 vring->size);
711 else
712 seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
713 dbg_txdesc_index, vring->size);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800714 }
715
716 return 0;
717}
718
719static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
720{
721 return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
722}
723
724static const struct file_operations fops_txdesc = {
725 .open = wil_txdesc_seq_open,
726 .release = single_release,
727 .read = seq_read,
728 .llseek = seq_lseek,
729};
730
731/*---------beamforming------------*/
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +0300732static char *wil_bfstatus_str(u32 status)
733{
734 switch (status) {
735 case 0:
736 return "Failed";
737 case 1:
738 return "OK";
739 case 2:
740 return "Retrying";
741 default:
742 return "??";
743 }
744}
745
746static bool is_all_zeros(void * const x_, size_t sz)
747{
748 /* if reply is all-0, ignore this CID */
749 u32 *x = x_;
750 int n;
751
752 for (n = 0; n < sz / sizeof(*x); n++)
753 if (x[n])
754 return false;
755
756 return true;
757}
758
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800759static int wil_bf_debugfs_show(struct seq_file *s, void *data)
760{
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +0300761 int rc;
762 int i;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800763 struct wil6210_priv *wil = s->private;
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +0300764 struct wmi_notify_req_cmd cmd = {
765 .interval_usec = 0,
766 };
767 struct {
768 struct wil6210_mbox_hdr_wmi wmi;
769 struct wmi_notify_req_done_event evt;
770 } __packed reply;
771
772 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
773 u32 status;
774
775 cmd.cid = i;
776 rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd),
777 WMI_NOTIFY_REQ_DONE_EVENTID, &reply,
778 sizeof(reply), 20);
779 /* if reply is all-0, ignore this CID */
780 if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt)))
781 continue;
782
783 status = le32_to_cpu(reply.evt.status);
784 seq_printf(s, "CID %d {\n"
785 " TSF = 0x%016llx\n"
786 " TxMCS = %2d TxTpt = %4d\n"
787 " SQI = %4d\n"
788 " Status = 0x%08x %s\n"
789 " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
790 " Goodput(rx:tx) %4d:%4d\n"
791 "}\n",
792 i,
793 le64_to_cpu(reply.evt.tsf),
794 le16_to_cpu(reply.evt.bf_mcs),
795 le32_to_cpu(reply.evt.tx_tpt),
796 reply.evt.sqi,
797 status, wil_bfstatus_str(status),
798 le16_to_cpu(reply.evt.my_rx_sector),
799 le16_to_cpu(reply.evt.my_tx_sector),
800 le16_to_cpu(reply.evt.other_rx_sector),
801 le16_to_cpu(reply.evt.other_tx_sector),
802 le32_to_cpu(reply.evt.rx_goodput),
803 le32_to_cpu(reply.evt.tx_goodput));
804 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800805 return 0;
806}
807
808static int wil_bf_seq_open(struct inode *inode, struct file *file)
809{
810 return single_open(file, wil_bf_debugfs_show, inode->i_private);
811}
812
813static const struct file_operations fops_bf = {
814 .open = wil_bf_seq_open,
815 .release = single_release,
816 .read = seq_read,
817 .llseek = seq_lseek,
818};
819/*---------SSID------------*/
820static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf,
821 size_t count, loff_t *ppos)
822{
823 struct wil6210_priv *wil = file->private_data;
824 struct wireless_dev *wdev = wil_to_wdev(wil);
825
826 return simple_read_from_buffer(user_buf, count, ppos,
827 wdev->ssid, wdev->ssid_len);
828}
829
830static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf,
831 size_t count, loff_t *ppos)
832{
833 struct wil6210_priv *wil = file->private_data;
834 struct wireless_dev *wdev = wil_to_wdev(wil);
835 struct net_device *ndev = wil_to_ndev(wil);
836
837 if (*ppos != 0) {
838 wil_err(wil, "Unable to set SSID substring from [%d]\n",
839 (int)*ppos);
840 return -EINVAL;
841 }
842
843 if (count > sizeof(wdev->ssid)) {
844 wil_err(wil, "SSID too long, len = %d\n", (int)count);
845 return -EINVAL;
846 }
847 if (netif_running(ndev)) {
848 wil_err(wil, "Unable to change SSID on running interface\n");
849 return -EINVAL;
850 }
851
852 wdev->ssid_len = count;
853 return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos,
854 buf, count);
855}
856
857static const struct file_operations fops_ssid = {
858 .read = wil_read_file_ssid,
859 .write = wil_write_file_ssid,
Wei Yongjun93ecbd62013-02-26 10:29:34 +0800860 .open = simple_open,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800861};
862
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +0200863/*---------temp------------*/
864static void print_temp(struct seq_file *s, const char *prefix, u32 t)
865{
866 switch (t) {
867 case 0:
868 case ~(u32)0:
869 seq_printf(s, "%s N/A\n", prefix);
870 break;
871 default:
872 seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
873 break;
874 }
875}
876
877static int wil_temp_debugfs_show(struct seq_file *s, void *data)
878{
879 struct wil6210_priv *wil = s->private;
880 u32 t_m, t_r;
881
882 int rc = wmi_get_temperature(wil, &t_m, &t_r);
883 if (rc) {
884 seq_printf(s, "Failed\n");
885 return 0;
886 }
887
Vladimir Kondratievd45cff92014-06-16 19:37:12 +0300888 print_temp(s, "T_mac =", t_m);
889 print_temp(s, "T_radio =", t_r);
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +0200890
891 return 0;
892}
893
894static int wil_temp_seq_open(struct inode *inode, struct file *file)
895{
896 return single_open(file, wil_temp_debugfs_show, inode->i_private);
897}
898
899static const struct file_operations fops_temp = {
900 .open = wil_temp_seq_open,
901 .release = single_release,
902 .read = seq_read,
903 .llseek = seq_lseek,
904};
905
Vladimir Kondratiev9eb82d42014-06-16 19:37:13 +0300906/*---------freq------------*/
907static int wil_freq_debugfs_show(struct seq_file *s, void *data)
908{
909 struct wil6210_priv *wil = s->private;
910 struct wireless_dev *wdev = wil_to_wdev(wil);
911 u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
912
913 seq_printf(s, "Freq = %d\n", freq);
914
915 return 0;
916}
917
918static int wil_freq_seq_open(struct inode *inode, struct file *file)
919{
920 return single_open(file, wil_freq_debugfs_show, inode->i_private);
921}
922
923static const struct file_operations fops_freq = {
924 .open = wil_freq_seq_open,
925 .release = single_release,
926 .read = seq_read,
927 .llseek = seq_lseek,
928};
929
930/*---------link------------*/
931static int wil_link_debugfs_show(struct seq_file *s, void *data)
932{
933 struct wil6210_priv *wil = s->private;
934 struct station_info sinfo;
935 int i, rc;
936
937 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
938 struct wil_sta_info *p = &wil->sta[i];
939 char *status = "unknown";
940 switch (p->status) {
941 case wil_sta_unused:
942 status = "unused ";
943 break;
944 case wil_sta_conn_pending:
945 status = "pending ";
946 break;
947 case wil_sta_connected:
948 status = "connected";
949 break;
950 }
951 seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
952 (p->data_port_open ? " data_port_open" : ""));
953
954 if (p->status == wil_sta_connected) {
955 rc = wil_cid_fill_sinfo(wil, i, &sinfo);
956 if (rc)
957 return rc;
958
959 seq_printf(s, " Tx_mcs = %d\n", sinfo.txrate.mcs);
960 seq_printf(s, " Rx_mcs = %d\n", sinfo.rxrate.mcs);
961 seq_printf(s, " SQ = %d\n", sinfo.signal);
962 }
963 }
964
965 return 0;
966}
967
968static int wil_link_seq_open(struct inode *inode, struct file *file)
969{
970 return single_open(file, wil_link_debugfs_show, inode->i_private);
971}
972
973static const struct file_operations fops_link = {
974 .open = wil_link_seq_open,
975 .release = single_release,
976 .read = seq_read,
977 .llseek = seq_lseek,
978};
979
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +0300980/*---------info------------*/
981static int wil_info_debugfs_show(struct seq_file *s, void *data)
982{
Vladimir Kondratievbe299852014-06-16 19:37:22 +0300983 struct wil6210_priv *wil = s->private;
984 struct net_device *ndev = wil_to_ndev(wil);
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +0300985 int is_ac = power_supply_is_system_supplied();
Vladimir Kondratievbe299852014-06-16 19:37:22 +0300986 int rx = atomic_xchg(&wil->isr_count_rx, 0);
987 int tx = atomic_xchg(&wil->isr_count_tx, 0);
988 static ulong rxf_old, txf_old;
989 ulong rxf = ndev->stats.rx_packets;
990 ulong txf = ndev->stats.tx_packets;
Vladimir Kondratiev55f8f682014-06-16 19:37:23 +0300991 unsigned int i;
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +0300992
993 /* >0 : AC; 0 : battery; <0 : error */
994 seq_printf(s, "AC powered : %d\n", is_ac);
Vladimir Kondratievbe299852014-06-16 19:37:22 +0300995 seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
996 seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
997 rxf_old = rxf;
998 txf_old = txf;
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +0300999
Vladimir Kondratiev55f8f682014-06-16 19:37:23 +03001000
1001#define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
1002 " " __stringify(x) : ""
1003
1004 for (i = 0; i < ndev->num_tx_queues; i++) {
1005 struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
1006 unsigned long state = txq->state;
1007
1008 seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
1009 CHECK_QSTATE(DRV_XOFF),
1010 CHECK_QSTATE(STACK_XOFF),
1011 CHECK_QSTATE(FROZEN)
1012 );
1013 }
1014#undef CHECK_QSTATE
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +03001015 return 0;
1016}
1017
1018static int wil_info_seq_open(struct inode *inode, struct file *file)
1019{
1020 return single_open(file, wil_info_debugfs_show, inode->i_private);
1021}
1022
1023static const struct file_operations fops_info = {
1024 .open = wil_info_seq_open,
1025 .release = single_release,
1026 .read = seq_read,
1027 .llseek = seq_lseek,
1028};
1029
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001030/*---------Station matrix------------*/
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001031static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
1032{
1033 int i;
1034 u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
1035 seq_printf(s, "0x%03x [", r->head_seq_num);
1036 for (i = 0; i < r->buf_size; i++) {
1037 if (i == index)
1038 seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
1039 else
1040 seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
1041 }
Vladimir Kondratievd5b1c322014-06-16 19:37:07 +03001042 seq_printf(s, "] last drop 0x%03x\n", r->ssn_last_drop);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001043}
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001044
1045static int wil_sta_debugfs_show(struct seq_file *s, void *data)
1046{
1047 struct wil6210_priv *wil = s->private;
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001048 int i, tid;
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001049
1050 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1051 struct wil_sta_info *p = &wil->sta[i];
1052 char *status = "unknown";
1053 switch (p->status) {
1054 case wil_sta_unused:
1055 status = "unused ";
1056 break;
1057 case wil_sta_conn_pending:
1058 status = "pending ";
1059 break;
1060 case wil_sta_connected:
1061 status = "connected";
1062 break;
1063 }
Vladimir Kondratieve58c9f72014-03-17 15:34:06 +02001064 seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
1065 (p->data_port_open ? " data_port_open" : ""));
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001066
1067 if (p->status == wil_sta_connected) {
1068 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1069 struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
1070 if (r) {
1071 seq_printf(s, "[%2d] ", tid);
1072 wil_print_rxtid(s, r);
1073 }
1074 }
1075 }
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001076 }
1077
1078 return 0;
1079}
1080
1081static int wil_sta_seq_open(struct inode *inode, struct file *file)
1082{
1083 return single_open(file, wil_sta_debugfs_show, inode->i_private);
1084}
1085
1086static const struct file_operations fops_sta = {
1087 .open = wil_sta_seq_open,
1088 .release = single_release,
1089 .read = seq_read,
1090 .llseek = seq_lseek,
1091};
1092
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001093/*----------------*/
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +03001094static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
1095 struct dentry *dbg)
1096{
1097 int i;
1098 char name[32];
1099
1100 for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
1101 struct debugfs_blob_wrapper *blob = &wil->blobs[i];
1102 const struct fw_map *map = &fw_mapping[i];
1103
1104 if (!map->name)
1105 continue;
1106
1107 blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
1108 blob->size = map->to - map->from;
1109 snprintf(name, sizeof(name), "blob_%s", map->name);
1110 wil_debugfs_create_ioblob(name, S_IRUGO, dbg, blob);
1111 }
1112}
1113
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001114/* misc files */
1115static const struct {
1116 const char *name;
1117 umode_t mode;
1118 const struct file_operations *fops;
1119} dbg_files[] = {
1120 {"mbox", S_IRUGO, &fops_mbox},
1121 {"vrings", S_IRUGO, &fops_vring},
1122 {"stations", S_IRUGO, &fops_sta},
1123 {"desc", S_IRUGO, &fops_txdesc},
1124 {"bf", S_IRUGO, &fops_bf},
1125 {"ssid", S_IRUGO | S_IWUSR, &fops_ssid},
1126 {"mem_val", S_IRUGO, &fops_memread},
1127 {"reset", S_IWUSR, &fops_reset},
1128 {"rxon", S_IWUSR, &fops_rxon},
1129 {"tx_mgmt", S_IWUSR, &fops_txmgmt},
1130 {"wmi_send", S_IWUSR, &fops_wmi},
1131 {"temp", S_IRUGO, &fops_temp},
1132 {"freq", S_IRUGO, &fops_freq},
1133 {"link", S_IRUGO, &fops_link},
1134 {"info", S_IRUGO, &fops_info},
1135};
1136
1137static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
1138 struct dentry *dbg)
1139{
1140 int i;
1141
1142 for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
1143 debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
1144 wil, dbg_files[i].fops);
1145}
1146
1147/* interrupt control blocks */
1148static const struct {
1149 const char *name;
1150 u32 icr_off;
1151} dbg_icr[] = {
1152 {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)},
1153 {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)},
1154 {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)},
1155 {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)},
1156};
1157
1158static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
1159 struct dentry *dbg)
1160{
1161 int i;
1162
1163 for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
1164 wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
1165 dbg_icr[i].icr_off);
1166}
1167
1168#define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
1169 offsetof(struct wil6210_priv, name), type}
1170
1171/* fields in struct wil6210_priv */
1172static const struct dbg_off dbg_wil_off[] = {
1173 WIL_FIELD(secure_pcp, S_IRUGO | S_IWUSR, doff_u32),
1174 WIL_FIELD(status, S_IRUGO | S_IWUSR, doff_ulong),
1175 WIL_FIELD(fw_version, S_IRUGO, doff_u32),
1176 WIL_FIELD(hw_version, S_IRUGO, doff_x32),
1177 {},
1178};
1179
1180static const struct dbg_off dbg_wil_regs[] = {
1181 {"RGF_MAC_MTRL_COUNTER_0", S_IRUGO, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
1182 doff_io32},
1183 {"RGF_USER_USAGE_1", S_IRUGO, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
1184 {},
1185};
1186
1187/* static parameters */
1188static const struct dbg_off dbg_statics[] = {
1189 {"desc_index", S_IRUGO | S_IWUSR, (ulong)&dbg_txdesc_index, doff_u32},
1190 {"vring_index", S_IRUGO | S_IWUSR, (ulong)&dbg_vring_index, doff_u32},
1191 {"mem_addr", S_IRUGO | S_IWUSR, (ulong)&mem_addr, doff_u32},
1192 {},
1193};
1194
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001195int wil6210_debugfs_init(struct wil6210_priv *wil)
1196{
1197 struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
1198 wil_to_wiphy(wil)->debugfsdir);
1199
1200 if (IS_ERR_OR_NULL(dbg))
1201 return -ENODEV;
1202
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001203 wil6210_debugfs_init_files(wil, dbg);
1204 wil6210_debugfs_init_isr(wil, dbg);
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +03001205 wil6210_debugfs_init_blobs(wil, dbg);
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001206 wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
1207 wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
1208 dbg_wil_regs);
1209 wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
1210
1211 wil6210_debugfs_create_pseudo_ISR(wil, dbg);
1212
1213 wil6210_debugfs_create_ITR_CNT(wil, dbg);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001214
1215 return 0;
1216}
1217
1218void wil6210_debugfs_remove(struct wil6210_priv *wil)
1219{
1220 debugfs_remove_recursive(wil->debug);
1221 wil->debug = NULL;
1222}