blob: 4fb33750505cb34c2deff4255f001552aadf2c2a [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 Kondratievaf31cb52014-03-02 11:20:50 +020029static u32 dbg_vring_index; /* 24+ for Rx, 0..23 for Tx */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080030
31static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil,
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +020032 const char *name, struct vring *vring,
33 char _s, char _h)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080034{
35 void __iomem *x = wmi_addr(wil, vring->hwtail);
36
37 seq_printf(s, "VRING %s = {\n", name);
Vladimir Kondratiev39c52ee2014-05-27 14:45:49 +030038 seq_printf(s, " pa = %pad\n", &vring->pa);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080039 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);
44 if (x)
45 seq_printf(s, "0x%08x\n", ioread32(x));
46 else
47 seq_printf(s, "???\n");
48
49 if (vring->va && (vring->size < 1025)) {
50 uint i;
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))
54 seq_printf(s, "\n");
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +020055 seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
56 _s : (vring->ctx[i].skb ? _h : 'h'));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080057 }
58 seq_printf(s, "\n");
59 }
60 seq_printf(s, "}\n");
61}
62
63static int wil_vring_debugfs_show(struct seq_file *s, void *data)
64{
65 uint i;
66 struct wil6210_priv *wil = s->private;
67
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +020068 wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_');
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080069
70 for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
71 struct vring *vring = &(wil->vring_tx[i]);
72 if (vring->va) {
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +020073 int cid = wil->vring2cid_tid[i][0];
74 int tid = wil->vring2cid_tid[i][1];
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080075 char name[10];
76 snprintf(name, sizeof(name), "tx_%2d", i);
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +020077
78 seq_printf(s, "\n%pM CID %d TID %d\n",
79 wil->sta[cid].addr, cid, tid);
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +020080 wil_print_vring(s, wil, name, vring, '_', 'H');
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080081 }
82 }
83
84 return 0;
85}
86
87static int wil_vring_seq_open(struct inode *inode, struct file *file)
88{
89 return single_open(file, wil_vring_debugfs_show, inode->i_private);
90}
91
92static const struct file_operations fops_vring = {
93 .open = wil_vring_seq_open,
94 .release = single_release,
95 .read = seq_read,
96 .llseek = seq_lseek,
97};
98
99static void wil_print_ring(struct seq_file *s, const char *prefix,
100 void __iomem *off)
101{
102 struct wil6210_priv *wil = s->private;
103 struct wil6210_mbox_ring r;
104 int rsize;
105 uint i;
106
107 wil_memcpy_fromio_32(&r, off, sizeof(r));
108 wil_mbox_ring_le2cpus(&r);
109 /*
110 * we just read memory block from NIC. This memory may be
111 * garbage. Check validity before using it.
112 */
113 rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
114
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);
121
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));
125 goto out;
126 }
127
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");
132 goto out;
133 }
134
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;
140
141 wil_memcpy_fromio_32(&d, x, sizeof(d));
142
143 seq_printf(s, " [%2x] %s %s%s 0x%08x", i,
144 d.sync ? "F" : "E",
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) {
154 int n = 0;
Larry Finger5d216082013-07-20 21:46:48 -0500155 char printbuf[16 * 3 + 2];
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800156 unsigned char databuf[MAX_MBOXITEM_SIZE];
157 void __iomem *src = wmi_buffer(wil, d.addr) +
158 sizeof(struct wil6210_mbox_hdr);
159 /*
160 * No need to check @src for validity -
161 * we already validated @d.addr while
162 * reading header
163 */
164 wil_memcpy_fromio_32(databuf, src, len);
165 while (n < len) {
166 int l = min(len - n, 16);
167 hex_dump_to_buffer(databuf + n, l,
168 16, 1, printbuf,
169 sizeof(printbuf),
170 false);
171 seq_printf(s, " : %s\n", printbuf);
172 n += l;
173 }
174 }
175 } else {
176 seq_printf(s, "\n");
177 }
178 }
179 out:
180 seq_printf(s, "}\n");
181}
182
183static int wil_mbox_debugfs_show(struct seq_file *s, void *data)
184{
185 struct wil6210_priv *wil = s->private;
186
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));
191
192 return 0;
193}
194
195static int wil_mbox_seq_open(struct inode *inode, struct file *file)
196{
197 return single_open(file, wil_mbox_debugfs_show, inode->i_private);
198}
199
200static const struct file_operations fops_mbox = {
201 .open = wil_mbox_seq_open,
202 .release = single_release,
203 .read = seq_read,
204 .llseek = seq_lseek,
205};
206
207static int wil_debugfs_iomem_x32_set(void *data, u64 val)
208{
209 iowrite32(val, (void __iomem *)data);
210 wmb(); /* make sure write propagated to HW */
211
212 return 0;
213}
214
215static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
216{
217 *val = ioread32((void __iomem *)data);
218
219 return 0;
220}
221
222DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
223 wil_debugfs_iomem_x32_set, "0x%08llx\n");
224
225static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
Al Viro0ecc8332013-03-29 12:23:28 -0400226 umode_t mode,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800227 struct dentry *parent,
228 void __iomem *value)
229{
230 return debugfs_create_file(name, mode, parent, (void * __force)value,
231 &fops_iomem_x32);
232}
233
Vladimir Kondratiev3de6cf22014-06-16 19:37:02 +0300234static int wil_debugfs_ulong_set(void *data, u64 val)
235{
236 *(ulong *)data = val;
237 return 0;
238}
239static int wil_debugfs_ulong_get(void *data, u64 *val)
240{
241 *val = *(ulong *)data;
242 return 0;
243}
244DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
245 wil_debugfs_ulong_set, "%llu\n");
246
247static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode,
248 struct dentry *parent,
249 ulong *value)
250{
251 return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong);
252}
253
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800254static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
255 const char *name,
256 struct dentry *parent, u32 off)
257{
258 struct dentry *d = debugfs_create_dir(name, parent);
259
260 if (IS_ERR_OR_NULL(d))
261 return -ENODEV;
262
263 wil_debugfs_create_iomem_x32("ICC", S_IRUGO | S_IWUSR, d,
264 wil->csr + off);
265 wil_debugfs_create_iomem_x32("ICR", S_IRUGO | S_IWUSR, d,
266 wil->csr + off + 4);
267 wil_debugfs_create_iomem_x32("ICM", S_IRUGO | S_IWUSR, d,
268 wil->csr + off + 8);
269 wil_debugfs_create_iomem_x32("ICS", S_IWUSR, d,
270 wil->csr + off + 12);
271 wil_debugfs_create_iomem_x32("IMV", S_IRUGO | S_IWUSR, d,
272 wil->csr + off + 16);
273 wil_debugfs_create_iomem_x32("IMS", S_IWUSR, d,
274 wil->csr + off + 20);
275 wil_debugfs_create_iomem_x32("IMC", S_IWUSR, d,
276 wil->csr + off + 24);
277
278 return 0;
279}
280
281static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
282 struct dentry *parent)
283{
284 struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
285
286 if (IS_ERR_OR_NULL(d))
287 return -ENODEV;
288
289 wil_debugfs_create_iomem_x32("CAUSE", S_IRUGO, d, wil->csr +
290 HOSTADDR(RGF_DMA_PSEUDO_CAUSE));
291 wil_debugfs_create_iomem_x32("MASK_SW", S_IRUGO, d, wil->csr +
292 HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW));
293 wil_debugfs_create_iomem_x32("MASK_FW", S_IRUGO, d, wil->csr +
294 HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW));
295
296 return 0;
297}
298
299static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
300 struct dentry *parent)
301{
302 struct dentry *d = debugfs_create_dir("ITR_CNT", parent);
303
304 if (IS_ERR_OR_NULL(d))
305 return -ENODEV;
306
307 wil_debugfs_create_iomem_x32("TRSH", S_IRUGO, d, wil->csr +
308 HOSTADDR(RGF_DMA_ITR_CNT_TRSH));
309 wil_debugfs_create_iomem_x32("DATA", S_IRUGO, d, wil->csr +
310 HOSTADDR(RGF_DMA_ITR_CNT_DATA));
311 wil_debugfs_create_iomem_x32("CTL", S_IRUGO, d, wil->csr +
312 HOSTADDR(RGF_DMA_ITR_CNT_CRL));
313
314 return 0;
315}
316
317static int wil_memread_debugfs_show(struct seq_file *s, void *data)
318{
319 struct wil6210_priv *wil = s->private;
320 void __iomem *a = wmi_buffer(wil, cpu_to_le32(mem_addr));
321
322 if (a)
323 seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, ioread32(a));
324 else
325 seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
326
327 return 0;
328}
329
330static int wil_memread_seq_open(struct inode *inode, struct file *file)
331{
332 return single_open(file, wil_memread_debugfs_show, inode->i_private);
333}
334
335static const struct file_operations fops_memread = {
336 .open = wil_memread_seq_open,
337 .release = single_release,
338 .read = seq_read,
339 .llseek = seq_lseek,
340};
341
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800342static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
343 size_t count, loff_t *ppos)
344{
345 enum { max_count = 4096 };
346 struct debugfs_blob_wrapper *blob = file->private_data;
347 loff_t pos = *ppos;
348 size_t available = blob->size;
349 void *buf;
350 size_t ret;
351
352 if (pos < 0)
353 return -EINVAL;
354
355 if (pos >= available || !count)
356 return 0;
357
358 if (count > available - pos)
359 count = available - pos;
360 if (count > max_count)
361 count = max_count;
362
363 buf = kmalloc(count, GFP_KERNEL);
364 if (!buf)
365 return -ENOMEM;
366
367 wil_memcpy_fromio_32(buf, (const volatile void __iomem *)blob->data +
368 pos, count);
369
370 ret = copy_to_user(user_buf, buf, count);
371 kfree(buf);
372 if (ret == count)
373 return -EFAULT;
374
375 count -= ret;
376 *ppos = pos + count;
377
378 return count;
379}
380
381static const struct file_operations fops_ioblob = {
382 .read = wil_read_file_ioblob,
Wei Yongjun93ecbd62013-02-26 10:29:34 +0800383 .open = simple_open,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800384 .llseek = default_llseek,
385};
386
387static
388struct dentry *wil_debugfs_create_ioblob(const char *name,
Al Viro0ecc8332013-03-29 12:23:28 -0400389 umode_t mode,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800390 struct dentry *parent,
391 struct debugfs_blob_wrapper *blob)
392{
393 return debugfs_create_file(name, mode, parent, blob, &fops_ioblob);
394}
395/*---reset---*/
396static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
397 size_t len, loff_t *ppos)
398{
399 struct wil6210_priv *wil = file->private_data;
400 struct net_device *ndev = wil_to_ndev(wil);
401
402 /**
403 * BUG:
404 * this code does NOT sync device state with the rest of system
405 * use with care, debug only!!!
406 */
407 rtnl_lock();
408 dev_close(ndev);
409 ndev->flags &= ~IFF_UP;
410 rtnl_unlock();
411 wil_reset(wil);
412
413 return len;
414}
415
416static const struct file_operations fops_reset = {
417 .write = wil_write_file_reset,
Wei Yongjun93ecbd62013-02-26 10:29:34 +0800418 .open = simple_open,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800419};
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300420/*---write channel 1..4 to rxon for it, 0 to rxoff---*/
421static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
422 size_t len, loff_t *ppos)
423{
424 struct wil6210_priv *wil = file->private_data;
425 int rc;
426 long channel;
427 bool on;
428
429 char *kbuf = kmalloc(len + 1, GFP_KERNEL);
430 if (!kbuf)
431 return -ENOMEM;
432 if (copy_from_user(kbuf, buf, len))
433 return -EIO;
434
435 kbuf[len] = '\0';
436 rc = kstrtol(kbuf, 0, &channel);
437 kfree(kbuf);
438 if (rc)
439 return rc;
440
441 if ((channel < 0) || (channel > 4)) {
442 wil_err(wil, "Invalid channel %ld\n", channel);
443 return -EINVAL;
444 }
445 on = !!channel;
446
447 if (on) {
448 rc = wmi_set_channel(wil, (int)channel);
449 if (rc)
450 return rc;
451 }
452
453 rc = wmi_rxon(wil, on);
454 if (rc)
455 return rc;
456
457 return len;
458}
459
460static const struct file_operations fops_rxon = {
461 .write = wil_write_file_rxon,
462 .open = simple_open,
463};
464/*---tx_mgmt---*/
465/* Write mgmt frame to this file to send it */
466static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
467 size_t len, loff_t *ppos)
468{
469 struct wil6210_priv *wil = file->private_data;
470 struct wiphy *wiphy = wil_to_wiphy(wil);
471 struct wireless_dev *wdev = wil_to_wdev(wil);
472 struct cfg80211_mgmt_tx_params params;
473 int rc;
474
475 void *frame = kmalloc(len, GFP_KERNEL);
476 if (!frame)
477 return -ENOMEM;
478
479 if (copy_from_user(frame, buf, len))
480 return -EIO;
481
482 params.buf = frame;
483 params.len = len;
484 params.chan = wdev->preset_chandef.chan;
485
486 rc = wil_cfg80211_mgmt_tx(wiphy, wdev, &params, NULL);
487
488 kfree(frame);
489 wil_info(wil, "%s() -> %d\n", __func__, rc);
490
491 return len;
492}
493
494static const struct file_operations fops_txmgmt = {
495 .write = wil_write_file_txmgmt,
496 .open = simple_open,
497};
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800498
Vladimir Kondratievc2366582014-03-17 15:34:08 +0200499static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
500 const char *prefix)
501{
502 char printbuf[16 * 3 + 2];
503 int i = 0;
504 while (i < len) {
505 int l = min(len - i, 16);
506 hex_dump_to_buffer(p + i, l, 16, 1, printbuf,
507 sizeof(printbuf), false);
508 seq_printf(s, "%s%s\n", prefix, printbuf);
509 i += l;
510 }
511}
512
513static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
514{
515 int i = 0;
516 int len = skb_headlen(skb);
517 void *p = skb->data;
518 int nr_frags = skb_shinfo(skb)->nr_frags;
519
520 seq_printf(s, " len = %d\n", len);
521 wil_seq_hexdump(s, p, len, " : ");
522
523 if (nr_frags) {
524 seq_printf(s, " nr_frags = %d\n", nr_frags);
525 for (i = 0; i < nr_frags; i++) {
526 const struct skb_frag_struct *frag =
527 &skb_shinfo(skb)->frags[i];
528
529 len = skb_frag_size(frag);
530 p = skb_frag_address_safe(frag);
531 seq_printf(s, " [%2d] : len = %d\n", i, len);
532 wil_seq_hexdump(s, p, len, " : ");
533 }
534 }
535}
536
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200537/*---------Tx/Rx descriptor------------*/
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800538static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
539{
540 struct wil6210_priv *wil = s->private;
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200541 struct vring *vring;
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +0200542 bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS);
543 if (tx)
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200544 vring = &(wil->vring_tx[dbg_vring_index]);
545 else
546 vring = &wil->vring_rx;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800547
548 if (!vring->va) {
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +0200549 if (tx)
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200550 seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index);
551 else
552 seq_puts(s, "No Rx VRING\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800553 return 0;
554 }
555
556 if (dbg_txdesc_index < vring->size) {
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200557 /* use struct vring_tx_desc for Rx as well,
558 * only field used, .dma.length, is the same
559 */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800560 volatile struct vring_tx_desc *d =
561 &(vring->va[dbg_txdesc_index].tx);
562 volatile u32 *u = (volatile u32 *)d;
Vladimir Kondratievf88f1132013-07-11 18:03:40 +0300563 struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800564
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +0200565 if (tx)
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200566 seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index,
567 dbg_txdesc_index);
568 else
569 seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800570 seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
571 u[0], u[1], u[2], u[3]);
572 seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
573 u[4], u[5], u[6], u[7]);
Vladimir Kondratiev39c52ee2014-05-27 14:45:49 +0300574 seq_printf(s, " SKB = 0x%p\n", skb);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800575
576 if (skb) {
Vladimir Kondratievc2366582014-03-17 15:34:08 +0200577 skb_get(skb);
578 wil_seq_print_skb(s, skb);
579 kfree_skb(skb);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800580 }
581 seq_printf(s, "}\n");
582 } else {
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +0200583 if (tx)
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200584 seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
585 dbg_vring_index, dbg_txdesc_index,
586 vring->size);
587 else
588 seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
589 dbg_txdesc_index, vring->size);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800590 }
591
592 return 0;
593}
594
595static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
596{
597 return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
598}
599
600static const struct file_operations fops_txdesc = {
601 .open = wil_txdesc_seq_open,
602 .release = single_release,
603 .read = seq_read,
604 .llseek = seq_lseek,
605};
606
607/*---------beamforming------------*/
608static int wil_bf_debugfs_show(struct seq_file *s, void *data)
609{
610 struct wil6210_priv *wil = s->private;
611 seq_printf(s,
612 "TSF : 0x%016llx\n"
613 "TxMCS : %d\n"
614 "Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n",
615 wil->stats.tsf, wil->stats.bf_mcs,
616 wil->stats.my_rx_sector, wil->stats.my_tx_sector,
617 wil->stats.peer_rx_sector, wil->stats.peer_tx_sector);
618 return 0;
619}
620
621static int wil_bf_seq_open(struct inode *inode, struct file *file)
622{
623 return single_open(file, wil_bf_debugfs_show, inode->i_private);
624}
625
626static const struct file_operations fops_bf = {
627 .open = wil_bf_seq_open,
628 .release = single_release,
629 .read = seq_read,
630 .llseek = seq_lseek,
631};
632/*---------SSID------------*/
633static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf,
634 size_t count, loff_t *ppos)
635{
636 struct wil6210_priv *wil = file->private_data;
637 struct wireless_dev *wdev = wil_to_wdev(wil);
638
639 return simple_read_from_buffer(user_buf, count, ppos,
640 wdev->ssid, wdev->ssid_len);
641}
642
643static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf,
644 size_t count, loff_t *ppos)
645{
646 struct wil6210_priv *wil = file->private_data;
647 struct wireless_dev *wdev = wil_to_wdev(wil);
648 struct net_device *ndev = wil_to_ndev(wil);
649
650 if (*ppos != 0) {
651 wil_err(wil, "Unable to set SSID substring from [%d]\n",
652 (int)*ppos);
653 return -EINVAL;
654 }
655
656 if (count > sizeof(wdev->ssid)) {
657 wil_err(wil, "SSID too long, len = %d\n", (int)count);
658 return -EINVAL;
659 }
660 if (netif_running(ndev)) {
661 wil_err(wil, "Unable to change SSID on running interface\n");
662 return -EINVAL;
663 }
664
665 wdev->ssid_len = count;
666 return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos,
667 buf, count);
668}
669
670static const struct file_operations fops_ssid = {
671 .read = wil_read_file_ssid,
672 .write = wil_write_file_ssid,
Wei Yongjun93ecbd62013-02-26 10:29:34 +0800673 .open = simple_open,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800674};
675
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +0200676/*---------temp------------*/
677static void print_temp(struct seq_file *s, const char *prefix, u32 t)
678{
679 switch (t) {
680 case 0:
681 case ~(u32)0:
682 seq_printf(s, "%s N/A\n", prefix);
683 break;
684 default:
685 seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
686 break;
687 }
688}
689
690static int wil_temp_debugfs_show(struct seq_file *s, void *data)
691{
692 struct wil6210_priv *wil = s->private;
693 u32 t_m, t_r;
694
695 int rc = wmi_get_temperature(wil, &t_m, &t_r);
696 if (rc) {
697 seq_printf(s, "Failed\n");
698 return 0;
699 }
700
701 print_temp(s, "MAC temperature :", t_m);
702 print_temp(s, "Radio temperature :", t_r);
703
704 return 0;
705}
706
707static int wil_temp_seq_open(struct inode *inode, struct file *file)
708{
709 return single_open(file, wil_temp_debugfs_show, inode->i_private);
710}
711
712static const struct file_operations fops_temp = {
713 .open = wil_temp_seq_open,
714 .release = single_release,
715 .read = seq_read,
716 .llseek = seq_lseek,
717};
718
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200719/*---------Station matrix------------*/
Vladimir Kondratievb4490f42014-02-27 16:20:44 +0200720static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
721{
722 int i;
723 u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
724 seq_printf(s, "0x%03x [", r->head_seq_num);
725 for (i = 0; i < r->buf_size; i++) {
726 if (i == index)
727 seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
728 else
729 seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
730 }
731 seq_puts(s, "]\n");
732}
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200733
734static int wil_sta_debugfs_show(struct seq_file *s, void *data)
735{
736 struct wil6210_priv *wil = s->private;
Vladimir Kondratievb4490f42014-02-27 16:20:44 +0200737 int i, tid;
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200738
739 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
740 struct wil_sta_info *p = &wil->sta[i];
741 char *status = "unknown";
742 switch (p->status) {
743 case wil_sta_unused:
744 status = "unused ";
745 break;
746 case wil_sta_conn_pending:
747 status = "pending ";
748 break;
749 case wil_sta_connected:
750 status = "connected";
751 break;
752 }
Vladimir Kondratieve58c9f72014-03-17 15:34:06 +0200753 seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
754 (p->data_port_open ? " data_port_open" : ""));
Vladimir Kondratievb4490f42014-02-27 16:20:44 +0200755
756 if (p->status == wil_sta_connected) {
757 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
758 struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
759 if (r) {
760 seq_printf(s, "[%2d] ", tid);
761 wil_print_rxtid(s, r);
762 }
763 }
764 }
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200765 }
766
767 return 0;
768}
769
770static int wil_sta_seq_open(struct inode *inode, struct file *file)
771{
772 return single_open(file, wil_sta_debugfs_show, inode->i_private);
773}
774
775static const struct file_operations fops_sta = {
776 .open = wil_sta_seq_open,
777 .release = single_release,
778 .read = seq_read,
779 .llseek = seq_lseek,
780};
781
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800782/*----------------*/
783int wil6210_debugfs_init(struct wil6210_priv *wil)
784{
785 struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
786 wil_to_wiphy(wil)->debugfsdir);
787
788 if (IS_ERR_OR_NULL(dbg))
789 return -ENODEV;
790
791 debugfs_create_file("mbox", S_IRUGO, dbg, wil, &fops_mbox);
792 debugfs_create_file("vrings", S_IRUGO, dbg, wil, &fops_vring);
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200793 debugfs_create_file("stations", S_IRUGO, dbg, wil, &fops_sta);
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200794 debugfs_create_file("desc", S_IRUGO, dbg, wil, &fops_txdesc);
795 debugfs_create_u32("desc_index", S_IRUGO | S_IWUSR, dbg,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800796 &dbg_txdesc_index);
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200797 debugfs_create_u32("vring_index", S_IRUGO | S_IWUSR, dbg,
798 &dbg_vring_index);
799
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800800 debugfs_create_file("bf", S_IRUGO, dbg, wil, &fops_bf);
801 debugfs_create_file("ssid", S_IRUGO | S_IWUSR, dbg, wil, &fops_ssid);
802 debugfs_create_u32("secure_pcp", S_IRUGO | S_IWUSR, dbg,
803 &wil->secure_pcp);
Vladimir Kondratiev3de6cf22014-06-16 19:37:02 +0300804 wil_debugfs_create_ulong("status", S_IRUGO | S_IWUSR, dbg,
805 &wil->status);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800806
807 wil6210_debugfs_create_ISR(wil, "USER_ICR", dbg,
808 HOSTADDR(RGF_USER_USER_ICR));
809 wil6210_debugfs_create_ISR(wil, "DMA_EP_TX_ICR", dbg,
810 HOSTADDR(RGF_DMA_EP_TX_ICR));
811 wil6210_debugfs_create_ISR(wil, "DMA_EP_RX_ICR", dbg,
812 HOSTADDR(RGF_DMA_EP_RX_ICR));
813 wil6210_debugfs_create_ISR(wil, "DMA_EP_MISC_ICR", dbg,
814 HOSTADDR(RGF_DMA_EP_MISC_ICR));
815 wil6210_debugfs_create_pseudo_ISR(wil, dbg);
816 wil6210_debugfs_create_ITR_CNT(wil, dbg);
817
818 debugfs_create_u32("mem_addr", S_IRUGO | S_IWUSR, dbg, &mem_addr);
819 debugfs_create_file("mem_val", S_IRUGO, dbg, wil, &fops_memread);
820
821 debugfs_create_file("reset", S_IWUSR, dbg, wil, &fops_reset);
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300822 debugfs_create_file("rxon", S_IWUSR, dbg, wil, &fops_rxon);
823 debugfs_create_file("tx_mgmt", S_IWUSR, dbg, wil, &fops_txmgmt);
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +0200824 debugfs_create_file("temp", S_IRUGO, dbg, wil, &fops_temp);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800825
826 wil->rgf_blob.data = (void * __force)wil->csr + 0;
827 wil->rgf_blob.size = 0xa000;
828 wil_debugfs_create_ioblob("blob_rgf", S_IRUGO, dbg, &wil->rgf_blob);
829
830 wil->fw_code_blob.data = (void * __force)wil->csr + 0x40000;
831 wil->fw_code_blob.size = 0x40000;
832 wil_debugfs_create_ioblob("blob_fw_code", S_IRUGO, dbg,
833 &wil->fw_code_blob);
834
835 wil->fw_data_blob.data = (void * __force)wil->csr + 0x80000;
836 wil->fw_data_blob.size = 0x8000;
837 wil_debugfs_create_ioblob("blob_fw_data", S_IRUGO, dbg,
838 &wil->fw_data_blob);
839
840 wil->fw_peri_blob.data = (void * __force)wil->csr + 0x88000;
841 wil->fw_peri_blob.size = 0x18000;
842 wil_debugfs_create_ioblob("blob_fw_peri", S_IRUGO, dbg,
843 &wil->fw_peri_blob);
844
845 wil->uc_code_blob.data = (void * __force)wil->csr + 0xa0000;
846 wil->uc_code_blob.size = 0x10000;
847 wil_debugfs_create_ioblob("blob_uc_code", S_IRUGO, dbg,
848 &wil->uc_code_blob);
849
850 wil->uc_data_blob.data = (void * __force)wil->csr + 0xb0000;
851 wil->uc_data_blob.size = 0x4000;
852 wil_debugfs_create_ioblob("blob_uc_data", S_IRUGO, dbg,
853 &wil->uc_data_blob);
854
855 return 0;
856}
857
858void wil6210_debugfs_remove(struct wil6210_priv *wil)
859{
860 debugfs_remove_recursive(wil->debug);
861 wil->debug = NULL;
862}