blob: 60ea0ec785c28240e7d9dea4360b028a13e7459b [file] [log] [blame]
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001/*
Lazar Alexeid3c6fa92017-02-09 13:57:36 +02002 * Copyright (c) 2012-2017 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"
Vladimir Kondratievdc164272015-04-30 16:25:09 +030027#include "pmc.h"
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080028
29/* Nasty hack. Better have per device instances */
30static u32 mem_addr;
31static u32 dbg_txdesc_index;
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +020032static u32 dbg_vring_index; /* 24+ for Rx, 0..23 for Tx */
Vladimir Shulman0436fd92015-02-15 14:02:34 +020033u32 vring_idle_trsh = 16; /* HW fetches up to 16 descriptors at once */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080034
Vladimir Kondratievb7cde472014-08-06 10:31:55 +030035enum dbg_off_type {
36 doff_u32 = 0,
37 doff_x32 = 1,
38 doff_ulong = 2,
39 doff_io32 = 3,
Lior David74997a52016-03-01 19:18:08 +020040 doff_u8 = 4
Vladimir Kondratievb7cde472014-08-06 10:31:55 +030041};
42
43/* offset to "wil" */
44struct dbg_off {
45 const char *name;
46 umode_t mode;
47 ulong off;
48 enum dbg_off_type type;
49};
50
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080051static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil,
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +020052 const char *name, struct vring *vring,
53 char _s, char _h)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080054{
55 void __iomem *x = wmi_addr(wil, vring->hwtail);
Vladimir Kondratiev995cdd02014-12-23 09:47:08 +020056 u32 v;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080057
58 seq_printf(s, "VRING %s = {\n", name);
Vladimir Kondratiev39c52ee2014-05-27 14:45:49 +030059 seq_printf(s, " pa = %pad\n", &vring->pa);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080060 seq_printf(s, " va = 0x%p\n", vring->va);
61 seq_printf(s, " size = %d\n", vring->size);
62 seq_printf(s, " swtail = %d\n", vring->swtail);
63 seq_printf(s, " swhead = %d\n", vring->swhead);
64 seq_printf(s, " hwtail = [0x%08x] -> ", vring->hwtail);
Vladimir Kondratiev995cdd02014-12-23 09:47:08 +020065 if (x) {
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +030066 v = readl(x);
Vladimir Kondratiev995cdd02014-12-23 09:47:08 +020067 seq_printf(s, "0x%08x = %d\n", v, v);
68 } else {
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030069 seq_puts(s, "???\n");
Vladimir Kondratiev995cdd02014-12-23 09:47:08 +020070 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080071
Hamad Kadmanyee5dfe02016-01-28 19:24:05 +020072 if (vring->va && (vring->size <= (1 << WIL_RING_SIZE_ORDER_MAX))) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080073 uint i;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030074
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080075 for (i = 0; i < vring->size; i++) {
76 volatile struct vring_tx_desc *d = &vring->va[i].tx;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030077
Hamad Kadmanyee5dfe02016-01-28 19:24:05 +020078 if ((i % 128) == 0 && (i != 0))
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030079 seq_puts(s, "\n");
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +020080 seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
81 _s : (vring->ctx[i].skb ? _h : 'h'));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080082 }
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030083 seq_puts(s, "\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080084 }
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030085 seq_puts(s, "}\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080086}
87
88static int wil_vring_debugfs_show(struct seq_file *s, void *data)
89{
90 uint i;
91 struct wil6210_priv *wil = s->private;
92
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +020093 wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_');
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080094
95 for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030096 struct vring *vring = &wil->vring_tx[i];
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +030097 struct vring_tx_data *txdata = &wil->vring_tx_data[i];
98
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080099 if (vring->va) {
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200100 int cid = wil->vring2cid_tid[i][0];
101 int tid = wil->vring2cid_tid[i][1];
Vladimir Kondratiev67c3e1b2014-06-16 19:37:04 +0300102 u32 swhead = vring->swhead;
103 u32 swtail = vring->swtail;
104 int used = (vring->size + swhead - swtail)
105 % vring->size;
106 int avail = vring->size - used - 1;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800107 char name[10];
Boris Sorochkin8f55cbe2015-02-15 14:02:35 +0200108 char sidle[10];
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +0300109 /* performance monitoring */
110 cycles_t now = get_cycles();
Chen Gangc20e7782014-12-24 23:08:44 +0800111 uint64_t idle = txdata->idle * 100;
112 uint64_t total = now - txdata->begin;
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +0300113
Boris Sorochkin8f55cbe2015-02-15 14:02:35 +0200114 if (total != 0) {
115 do_div(idle, total);
116 snprintf(sidle, sizeof(sidle), "%3d%%",
117 (int)idle);
118 } else {
119 snprintf(sidle, sizeof(sidle), "N/A");
120 }
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +0300121 txdata->begin = now;
122 txdata->idle = 0ULL;
123
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800124 snprintf(name, sizeof(name), "tx_%2d", i);
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200125
Vladimir Kondratiev41d6b092015-03-15 16:00:23 +0200126 if (cid < WIL6210_MAX_CID)
127 seq_printf(s,
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300128 "\n%pM CID %d TID %d 1x%s BACK([%u] %u TU A%s) [%3d|%3d] idle %s\n",
Vladimir Kondratiev41d6b092015-03-15 16:00:23 +0200129 wil->sta[cid].addr, cid, tid,
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300130 txdata->dot1x_open ? "+" : "-",
Vladimir Kondratiev41d6b092015-03-15 16:00:23 +0200131 txdata->agg_wsize,
132 txdata->agg_timeout,
133 txdata->agg_amsdu ? "+" : "-",
134 used, avail, sidle);
135 else
136 seq_printf(s,
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300137 "\nBroadcast 1x%s [%3d|%3d] idle %s\n",
138 txdata->dot1x_open ? "+" : "-",
Vladimir Kondratiev41d6b092015-03-15 16:00:23 +0200139 used, avail, sidle);
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +0300140
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +0200141 wil_print_vring(s, wil, name, vring, '_', 'H');
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800142 }
143 }
144
145 return 0;
146}
147
148static int wil_vring_seq_open(struct inode *inode, struct file *file)
149{
150 return single_open(file, wil_vring_debugfs_show, inode->i_private);
151}
152
153static const struct file_operations fops_vring = {
154 .open = wil_vring_seq_open,
155 .release = single_release,
156 .read = seq_read,
157 .llseek = seq_lseek,
158};
159
Andy Shevchenkoa202fbb2015-09-09 15:38:48 -0700160static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
161 const char *prefix)
162{
163 seq_hex_dump(s, prefix, DUMP_PREFIX_NONE, 16, 1, p, len, false);
164}
165
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800166static void wil_print_ring(struct seq_file *s, const char *prefix,
167 void __iomem *off)
168{
169 struct wil6210_priv *wil = s->private;
170 struct wil6210_mbox_ring r;
171 int rsize;
172 uint i;
173
Maya Erez349214c2016-04-26 14:41:41 +0300174 wil_halp_vote(wil);
175
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800176 wil_memcpy_fromio_32(&r, off, sizeof(r));
177 wil_mbox_ring_le2cpus(&r);
178 /*
179 * we just read memory block from NIC. This memory may be
180 * garbage. Check validity before using it.
181 */
182 rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
183
184 seq_printf(s, "ring %s = {\n", prefix);
185 seq_printf(s, " base = 0x%08x\n", r.base);
186 seq_printf(s, " size = 0x%04x bytes -> %d entries\n", r.size, rsize);
187 seq_printf(s, " tail = 0x%08x\n", r.tail);
188 seq_printf(s, " head = 0x%08x\n", r.head);
189 seq_printf(s, " entry size = %d\n", r.entry_size);
190
191 if (r.size % sizeof(struct wil6210_mbox_ring_desc)) {
192 seq_printf(s, " ??? size is not multiple of %zd, garbage?\n",
193 sizeof(struct wil6210_mbox_ring_desc));
194 goto out;
195 }
196
197 if (!wmi_addr(wil, r.base) ||
198 !wmi_addr(wil, r.tail) ||
199 !wmi_addr(wil, r.head)) {
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300200 seq_puts(s, " ??? pointers are garbage?\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800201 goto out;
202 }
203
204 for (i = 0; i < rsize; i++) {
205 struct wil6210_mbox_ring_desc d;
206 struct wil6210_mbox_hdr hdr;
207 size_t delta = i * sizeof(d);
208 void __iomem *x = wil->csr + HOSTADDR(r.base) + delta;
209
210 wil_memcpy_fromio_32(&d, x, sizeof(d));
211
212 seq_printf(s, " [%2x] %s %s%s 0x%08x", i,
213 d.sync ? "F" : "E",
214 (r.tail - r.base == delta) ? "t" : " ",
215 (r.head - r.base == delta) ? "h" : " ",
216 le32_to_cpu(d.addr));
217 if (0 == wmi_read_hdr(wil, d.addr, &hdr)) {
218 u16 len = le16_to_cpu(hdr.len);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300219
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800220 seq_printf(s, " -> %04x %04x %04x %02x\n",
221 le16_to_cpu(hdr.seq), len,
222 le16_to_cpu(hdr.type), hdr.flags);
223 if (len <= MAX_MBOXITEM_SIZE) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800224 unsigned char databuf[MAX_MBOXITEM_SIZE];
225 void __iomem *src = wmi_buffer(wil, d.addr) +
226 sizeof(struct wil6210_mbox_hdr);
227 /*
228 * No need to check @src for validity -
229 * we already validated @d.addr while
230 * reading header
231 */
232 wil_memcpy_fromio_32(databuf, src, len);
Andy Shevchenkoa202fbb2015-09-09 15:38:48 -0700233 wil_seq_hexdump(s, databuf, len, " : ");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800234 }
235 } else {
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300236 seq_puts(s, "\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800237 }
238 }
239 out:
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300240 seq_puts(s, "}\n");
Maya Erez349214c2016-04-26 14:41:41 +0300241 wil_halp_unvote(wil);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800242}
243
244static int wil_mbox_debugfs_show(struct seq_file *s, void *data)
245{
246 struct wil6210_priv *wil = s->private;
247
248 wil_print_ring(s, "tx", wil->csr + HOST_MBOX +
249 offsetof(struct wil6210_mbox_ctl, tx));
250 wil_print_ring(s, "rx", wil->csr + HOST_MBOX +
251 offsetof(struct wil6210_mbox_ctl, rx));
252
253 return 0;
254}
255
256static int wil_mbox_seq_open(struct inode *inode, struct file *file)
257{
258 return single_open(file, wil_mbox_debugfs_show, inode->i_private);
259}
260
261static const struct file_operations fops_mbox = {
262 .open = wil_mbox_seq_open,
263 .release = single_release,
264 .read = seq_read,
265 .llseek = seq_lseek,
266};
267
268static int wil_debugfs_iomem_x32_set(void *data, u64 val)
269{
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300270 writel(val, (void __iomem *)data);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800271 wmb(); /* make sure write propagated to HW */
272
273 return 0;
274}
275
276static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
277{
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300278 *val = readl((void __iomem *)data);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800279
280 return 0;
281}
282
283DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
284 wil_debugfs_iomem_x32_set, "0x%08llx\n");
285
286static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
Al Viro0ecc8332013-03-29 12:23:28 -0400287 umode_t mode,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800288 struct dentry *parent,
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300289 void *value)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800290{
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300291 return debugfs_create_file(name, mode, parent, value,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800292 &fops_iomem_x32);
293}
294
Vladimir Kondratiev3de6cf22014-06-16 19:37:02 +0300295static int wil_debugfs_ulong_set(void *data, u64 val)
296{
297 *(ulong *)data = val;
298 return 0;
299}
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300300
Vladimir Kondratiev3de6cf22014-06-16 19:37:02 +0300301static int wil_debugfs_ulong_get(void *data, u64 *val)
302{
303 *val = *(ulong *)data;
304 return 0;
305}
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300306
Vladimir Kondratiev3de6cf22014-06-16 19:37:02 +0300307DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
Vladimir Kondratiev8ea06182015-07-30 13:51:51 +0300308 wil_debugfs_ulong_set, "0x%llx\n");
Vladimir Kondratiev3de6cf22014-06-16 19:37:02 +0300309
310static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode,
311 struct dentry *parent,
312 ulong *value)
313{
314 return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong);
315}
316
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300317/**
318 * wil6210_debugfs_init_offset - create set of debugfs files
319 * @wil - driver's context, used for printing
320 * @dbg - directory on the debugfs, where files will be created
321 * @base - base address used in address calculation
322 * @tbl - table with file descriptions. Should be terminated with empty element.
323 *
324 * Creates files accordingly to the @tbl.
325 */
326static void wil6210_debugfs_init_offset(struct wil6210_priv *wil,
327 struct dentry *dbg, void *base,
328 const struct dbg_off * const tbl)
329{
330 int i;
331
332 for (i = 0; tbl[i].name; i++) {
Vladimir Kondratiev867fa0d2014-09-10 16:34:51 +0300333 struct dentry *f;
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300334
335 switch (tbl[i].type) {
336 case doff_u32:
337 f = debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg,
338 base + tbl[i].off);
339 break;
340 case doff_x32:
341 f = debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg,
342 base + tbl[i].off);
343 break;
344 case doff_ulong:
345 f = wil_debugfs_create_ulong(tbl[i].name, tbl[i].mode,
346 dbg, base + tbl[i].off);
347 break;
348 case doff_io32:
349 f = wil_debugfs_create_iomem_x32(tbl[i].name,
350 tbl[i].mode, dbg,
351 base + tbl[i].off);
352 break;
Lior David74997a52016-03-01 19:18:08 +0200353 case doff_u8:
354 f = debugfs_create_u8(tbl[i].name, tbl[i].mode, dbg,
355 base + tbl[i].off);
356 break;
Vladimir Kondratiev867fa0d2014-09-10 16:34:51 +0300357 default:
358 f = ERR_PTR(-EINVAL);
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300359 }
360 if (IS_ERR_OR_NULL(f))
361 wil_err(wil, "Create file \"%s\": err %ld\n",
362 tbl[i].name, PTR_ERR(f));
363 }
364}
365
366static const struct dbg_off isr_off[] = {
Maya Erezc2256ec2017-02-08 13:18:42 +0200367 {"ICC", 0644, offsetof(struct RGF_ICR, ICC), doff_io32},
368 {"ICR", 0644, offsetof(struct RGF_ICR, ICR), doff_io32},
369 {"ICM", 0644, offsetof(struct RGF_ICR, ICM), doff_io32},
370 {"ICS", 0244, offsetof(struct RGF_ICR, ICS), doff_io32},
371 {"IMV", 0644, offsetof(struct RGF_ICR, IMV), doff_io32},
372 {"IMS", 0244, offsetof(struct RGF_ICR, IMS), doff_io32},
373 {"IMC", 0244, offsetof(struct RGF_ICR, IMC), doff_io32},
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300374 {},
375};
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300376
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800377static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
378 const char *name,
379 struct dentry *parent, u32 off)
380{
381 struct dentry *d = debugfs_create_dir(name, parent);
382
383 if (IS_ERR_OR_NULL(d))
384 return -ENODEV;
385
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300386 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off,
387 isr_off);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800388
389 return 0;
390}
391
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300392static const struct dbg_off pseudo_isr_off[] = {
Maya Erezc2256ec2017-02-08 13:18:42 +0200393 {"CAUSE", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32},
394 {"MASK_SW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32},
395 {"MASK_FW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32},
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300396 {},
397};
398
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800399static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
400 struct dentry *parent)
401{
402 struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
403
404 if (IS_ERR_OR_NULL(d))
405 return -ENODEV;
406
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300407 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
408 pseudo_isr_off);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800409
410 return 0;
411}
412
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200413static const struct dbg_off lgc_itr_cnt_off[] = {
Maya Erezc2256ec2017-02-08 13:18:42 +0200414 {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32},
415 {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32},
416 {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32},
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300417 {},
418};
419
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200420static const struct dbg_off tx_itr_cnt_off[] = {
Maya Erezc2256ec2017-02-08 13:18:42 +0200421 {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_TRSH),
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200422 doff_io32},
Maya Erezc2256ec2017-02-08 13:18:42 +0200423 {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_DATA),
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200424 doff_io32},
Maya Erezc2256ec2017-02-08 13:18:42 +0200425 {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_CTL),
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200426 doff_io32},
Maya Erezc2256ec2017-02-08 13:18:42 +0200427 {"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_TRSH),
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200428 doff_io32},
Maya Erezc2256ec2017-02-08 13:18:42 +0200429 {"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_DATA),
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200430 doff_io32},
Maya Erezc2256ec2017-02-08 13:18:42 +0200431 {"IDL_CTL", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_CTL),
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200432 doff_io32},
433 {},
434};
435
436static const struct dbg_off rx_itr_cnt_off[] = {
Maya Erezc2256ec2017-02-08 13:18:42 +0200437 {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_TRSH),
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200438 doff_io32},
Maya Erezc2256ec2017-02-08 13:18:42 +0200439 {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_DATA),
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200440 doff_io32},
Maya Erezc2256ec2017-02-08 13:18:42 +0200441 {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_CTL),
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200442 doff_io32},
Maya Erezc2256ec2017-02-08 13:18:42 +0200443 {"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_TRSH),
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200444 doff_io32},
Maya Erezc2256ec2017-02-08 13:18:42 +0200445 {"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_DATA),
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200446 doff_io32},
Maya Erezc2256ec2017-02-08 13:18:42 +0200447 {"IDL_CTL", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_CTL),
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200448 doff_io32},
449 {},
450};
451
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800452static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
453 struct dentry *parent)
454{
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200455 struct dentry *d, *dtx, *drx;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800456
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200457 d = debugfs_create_dir("ITR_CNT", parent);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800458 if (IS_ERR_OR_NULL(d))
459 return -ENODEV;
460
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200461 dtx = debugfs_create_dir("TX", d);
462 drx = debugfs_create_dir("RX", d);
463 if (IS_ERR_OR_NULL(dtx) || IS_ERR_OR_NULL(drx))
464 return -ENODEV;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800465
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200466 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
467 lgc_itr_cnt_off);
468
469 wil6210_debugfs_init_offset(wil, dtx, (void * __force)wil->csr,
470 tx_itr_cnt_off);
471
472 wil6210_debugfs_init_offset(wil, drx, (void * __force)wil->csr,
473 rx_itr_cnt_off);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800474 return 0;
475}
476
477static int wil_memread_debugfs_show(struct seq_file *s, void *data)
478{
479 struct wil6210_priv *wil = s->private;
480 void __iomem *a = wmi_buffer(wil, cpu_to_le32(mem_addr));
481
482 if (a)
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300483 seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, readl(a));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800484 else
485 seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
486
487 return 0;
488}
489
490static int wil_memread_seq_open(struct inode *inode, struct file *file)
491{
492 return single_open(file, wil_memread_debugfs_show, inode->i_private);
493}
494
495static const struct file_operations fops_memread = {
496 .open = wil_memread_seq_open,
497 .release = single_release,
498 .read = seq_read,
499 .llseek = seq_lseek,
500};
501
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800502static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300503 size_t count, loff_t *ppos)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800504{
505 enum { max_count = 4096 };
Maya Erez349214c2016-04-26 14:41:41 +0300506 struct wil_blob_wrapper *wil_blob = file->private_data;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800507 loff_t pos = *ppos;
Maya Erez349214c2016-04-26 14:41:41 +0300508 size_t available = wil_blob->blob.size;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800509 void *buf;
510 size_t ret;
511
Maya Ereze3309bf2017-05-15 16:57:46 +0300512 if (test_bit(wil_status_suspending, wil_blob->wil->status) ||
513 test_bit(wil_status_suspended, wil_blob->wil->status))
514 return 0;
515
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800516 if (pos < 0)
517 return -EINVAL;
518
519 if (pos >= available || !count)
520 return 0;
521
522 if (count > available - pos)
523 count = available - pos;
524 if (count > max_count)
525 count = max_count;
526
527 buf = kmalloc(count, GFP_KERNEL);
528 if (!buf)
529 return -ENOMEM;
530
Maya Ereze6d8b242017-04-03 13:59:04 +0300531 wil_memcpy_fromio_32(buf, (const void __iomem *)
532 wil_blob->blob.data + pos, count);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800533
534 ret = copy_to_user(user_buf, buf, count);
535 kfree(buf);
536 if (ret == count)
537 return -EFAULT;
538
539 count -= ret;
540 *ppos = pos + count;
541
542 return count;
543}
544
545static const struct file_operations fops_ioblob = {
546 .read = wil_read_file_ioblob,
Wei Yongjun93ecbd62013-02-26 10:29:34 +0800547 .open = simple_open,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800548 .llseek = default_llseek,
549};
550
551static
552struct dentry *wil_debugfs_create_ioblob(const char *name,
Al Viro0ecc8332013-03-29 12:23:28 -0400553 umode_t mode,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800554 struct dentry *parent,
Maya Erez349214c2016-04-26 14:41:41 +0300555 struct wil_blob_wrapper *wil_blob)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800556{
Maya Erez349214c2016-04-26 14:41:41 +0300557 return debugfs_create_file(name, mode, parent, wil_blob, &fops_ioblob);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800558}
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300559
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800560/*---reset---*/
561static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
562 size_t len, loff_t *ppos)
563{
564 struct wil6210_priv *wil = file->private_data;
565 struct net_device *ndev = wil_to_ndev(wil);
566
567 /**
568 * BUG:
569 * this code does NOT sync device state with the rest of system
570 * use with care, debug only!!!
571 */
572 rtnl_lock();
573 dev_close(ndev);
574 ndev->flags &= ~IFF_UP;
575 rtnl_unlock();
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200576 wil_reset(wil, true);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800577
578 return len;
579}
580
581static const struct file_operations fops_reset = {
582 .write = wil_write_file_reset,
Wei Yongjun93ecbd62013-02-26 10:29:34 +0800583 .open = simple_open,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800584};
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300585
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300586/*---write channel 1..4 to rxon for it, 0 to rxoff---*/
587static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
588 size_t len, loff_t *ppos)
589{
590 struct wil6210_priv *wil = file->private_data;
591 int rc;
592 long channel;
593 bool on;
594
Al Viro16e5c1f2015-12-24 00:06:05 -0500595 char *kbuf = memdup_user_nul(buf, len);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300596
Al Viro16e5c1f2015-12-24 00:06:05 -0500597 if (IS_ERR(kbuf))
598 return PTR_ERR(kbuf);
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300599 rc = kstrtol(kbuf, 0, &channel);
600 kfree(kbuf);
601 if (rc)
602 return rc;
603
604 if ((channel < 0) || (channel > 4)) {
605 wil_err(wil, "Invalid channel %ld\n", channel);
606 return -EINVAL;
607 }
608 on = !!channel;
609
610 if (on) {
611 rc = wmi_set_channel(wil, (int)channel);
612 if (rc)
613 return rc;
614 }
615
616 rc = wmi_rxon(wil, on);
617 if (rc)
618 return rc;
619
620 return len;
621}
622
623static const struct file_operations fops_rxon = {
624 .write = wil_write_file_rxon,
625 .open = simple_open,
626};
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300627
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +0200628/* block ack control, write:
629 * - "add <ringid> <agg_size> <timeout>" to trigger ADDBA
630 * - "del_tx <ringid> <reason>" to trigger DELBA for Tx side
631 * - "del_rx <CID> <TID> <reason>" to trigger DELBA for Rx side
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200632 */
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +0200633static ssize_t wil_write_back(struct file *file, const char __user *buf,
634 size_t len, loff_t *ppos)
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200635{
636 struct wil6210_priv *wil = file->private_data;
637 int rc;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200638 char *kbuf = kmalloc(len + 1, GFP_KERNEL);
Colin Ian King2a19f772015-03-01 17:48:33 +0000639 char cmd[9];
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +0200640 int p1, p2, p3;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200641
642 if (!kbuf)
643 return -ENOMEM;
644
645 rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
646 if (rc != len) {
647 kfree(kbuf);
648 return rc >= 0 ? -EIO : rc;
649 }
650
651 kbuf[len] = '\0';
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +0200652 rc = sscanf(kbuf, "%8s %d %d %d", cmd, &p1, &p2, &p3);
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200653 kfree(kbuf);
654
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +0200655 if (rc < 0)
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200656 return rc;
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +0200657 if (rc < 2)
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200658 return -EINVAL;
659
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +0200660 if (0 == strcmp(cmd, "add")) {
661 if (rc < 3) {
662 wil_err(wil, "BACK: add require at least 2 params\n");
663 return -EINVAL;
664 }
665 if (rc < 4)
666 p3 = 0;
667 wmi_addba(wil, p1, p2, p3);
668 } else if (0 == strcmp(cmd, "del_tx")) {
669 if (rc < 3)
670 p2 = WLAN_REASON_QSTA_LEAVE_QBSS;
671 wmi_delba_tx(wil, p1, p2);
672 } else if (0 == strcmp(cmd, "del_rx")) {
673 if (rc < 3) {
674 wil_err(wil,
675 "BACK: del_rx require at least 2 params\n");
676 return -EINVAL;
677 }
678 if (rc < 4)
679 p3 = WLAN_REASON_QSTA_LEAVE_QBSS;
680 wmi_delba_rx(wil, mk_cidxtid(p1, p2), p3);
681 } else {
682 wil_err(wil, "BACK: Unrecognized command \"%s\"\n", cmd);
683 return -EINVAL;
684 }
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200685
686 return len;
687}
688
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +0200689static ssize_t wil_read_back(struct file *file, char __user *user_buf,
690 size_t count, loff_t *ppos)
691{
692 static const char text[] = "block ack control, write:\n"
693 " - \"add <ringid> <agg_size> <timeout>\" to trigger ADDBA\n"
694 "If missing, <timeout> defaults to 0\n"
695 " - \"del_tx <ringid> <reason>\" to trigger DELBA for Tx side\n"
696 " - \"del_rx <CID> <TID> <reason>\" to trigger DELBA for Rx side\n"
697 "If missing, <reason> set to \"STA_LEAVING\" (36)\n";
698
699 return simple_read_from_buffer(user_buf, count, ppos, text,
700 sizeof(text));
701}
702
703static const struct file_operations fops_back = {
704 .read = wil_read_back,
705 .write = wil_write_back,
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200706 .open = simple_open,
707};
708
Vladimir Kondratievdc164272015-04-30 16:25:09 +0300709/* pmc control, write:
710 * - "alloc <num descriptors> <descriptor_size>" to allocate PMC
711 * - "free" to release memory allocated for PMC
712 */
713static ssize_t wil_write_pmccfg(struct file *file, const char __user *buf,
714 size_t len, loff_t *ppos)
715{
716 struct wil6210_priv *wil = file->private_data;
717 int rc;
718 char *kbuf = kmalloc(len + 1, GFP_KERNEL);
719 char cmd[9];
720 int num_descs, desc_size;
721
722 if (!kbuf)
723 return -ENOMEM;
724
725 rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
726 if (rc != len) {
727 kfree(kbuf);
728 return rc >= 0 ? -EIO : rc;
729 }
730
731 kbuf[len] = '\0';
732 rc = sscanf(kbuf, "%8s %d %d", cmd, &num_descs, &desc_size);
733 kfree(kbuf);
734
735 if (rc < 0)
736 return rc;
737
738 if (rc < 1) {
739 wil_err(wil, "pmccfg: no params given\n");
740 return -EINVAL;
741 }
742
743 if (0 == strcmp(cmd, "alloc")) {
744 if (rc != 3) {
745 wil_err(wil, "pmccfg: alloc requires 2 params\n");
746 return -EINVAL;
747 }
748 wil_pmc_alloc(wil, num_descs, desc_size);
749 } else if (0 == strcmp(cmd, "free")) {
750 if (rc != 1) {
751 wil_err(wil, "pmccfg: free does not have any params\n");
752 return -EINVAL;
753 }
754 wil_pmc_free(wil, true);
755 } else {
756 wil_err(wil, "pmccfg: Unrecognized command \"%s\"\n", cmd);
757 return -EINVAL;
758 }
759
760 return len;
761}
762
763static ssize_t wil_read_pmccfg(struct file *file, char __user *user_buf,
764 size_t count, loff_t *ppos)
765{
766 struct wil6210_priv *wil = file->private_data;
767 char text[256];
768 char help[] = "pmc control, write:\n"
769 " - \"alloc <num descriptors> <descriptor_size>\" to allocate pmc\n"
770 " - \"free\" to free memory allocated for pmc\n";
771
772 sprintf(text, "Last command status: %d\n\n%s",
773 wil_pmc_last_cmd_status(wil),
774 help);
775
776 return simple_read_from_buffer(user_buf, count, ppos, text,
777 strlen(text) + 1);
778}
779
780static const struct file_operations fops_pmccfg = {
781 .read = wil_read_pmccfg,
782 .write = wil_write_pmccfg,
783 .open = simple_open,
784};
785
786static const struct file_operations fops_pmcdata = {
787 .open = simple_open,
788 .read = wil_pmc_read,
789 .llseek = wil_pmc_llseek,
790};
791
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300792/*---tx_mgmt---*/
793/* Write mgmt frame to this file to send it */
794static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
795 size_t len, loff_t *ppos)
796{
797 struct wil6210_priv *wil = file->private_data;
798 struct wiphy *wiphy = wil_to_wiphy(wil);
799 struct wireless_dev *wdev = wil_to_wdev(wil);
800 struct cfg80211_mgmt_tx_params params;
801 int rc;
Hamad Kadmany7194ff32017-08-09 09:04:56 +0300802 void *frame;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300803
Hamad Kadmany7194ff32017-08-09 09:04:56 +0300804 if (!len)
805 return -EINVAL;
806
807 frame = kmalloc(len, GFP_KERNEL);
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300808 if (!frame)
809 return -ENOMEM;
810
Lino Sanfilippo8e09b7d2014-11-28 02:47:19 +0100811 if (copy_from_user(frame, buf, len)) {
812 kfree(frame);
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300813 return -EIO;
Lino Sanfilippo8e09b7d2014-11-28 02:47:19 +0100814 }
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300815
816 params.buf = frame;
817 params.len = len;
818 params.chan = wdev->preset_chandef.chan;
819
820 rc = wil_cfg80211_mgmt_tx(wiphy, wdev, &params, NULL);
821
822 kfree(frame);
Lazar Alexei3190cc62017-02-23 14:34:14 +0200823 wil_info(wil, "-> %d\n", rc);
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300824
825 return len;
826}
827
828static const struct file_operations fops_txmgmt = {
829 .write = wil_write_file_txmgmt,
830 .open = simple_open,
831};
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800832
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300833/* Write WMI command (w/o mbox header) to this file to send it
834 * WMI starts from wil6210_mbox_hdr_wmi header
835 */
836static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
837 size_t len, loff_t *ppos)
838{
839 struct wil6210_priv *wil = file->private_data;
Lior Davidb874dde2016-03-01 19:18:09 +0200840 struct wmi_cmd_hdr *wmi;
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300841 void *cmd;
Lior Davidb874dde2016-03-01 19:18:09 +0200842 int cmdlen = len - sizeof(struct wmi_cmd_hdr);
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300843 u16 cmdid;
844 int rc, rc1;
845
Lior David69218a42016-03-21 22:01:11 +0200846 if (cmdlen < 0)
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300847 return -EINVAL;
848
849 wmi = kmalloc(len, GFP_KERNEL);
850 if (!wmi)
851 return -ENOMEM;
852
853 rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
Lino Sanfilippo8e09b7d2014-11-28 02:47:19 +0100854 if (rc < 0) {
855 kfree(wmi);
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300856 return rc;
Lino Sanfilippo8e09b7d2014-11-28 02:47:19 +0100857 }
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300858
Lior David69218a42016-03-21 22:01:11 +0200859 cmd = (cmdlen > 0) ? &wmi[1] : NULL;
Lior Davidb874dde2016-03-01 19:18:09 +0200860 cmdid = le16_to_cpu(wmi->command_id);
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300861
862 rc1 = wmi_send(wil, cmdid, cmd, cmdlen);
863 kfree(wmi);
864
Lazar Alexei3190cc62017-02-23 14:34:14 +0200865 wil_info(wil, "0x%04x[%d] -> %d\n", cmdid, cmdlen, rc1);
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300866
867 return rc;
868}
869
870static const struct file_operations fops_wmi = {
871 .write = wil_write_file_wmi,
872 .open = simple_open,
873};
874
Vladimir Kondratievc2366582014-03-17 15:34:08 +0200875static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
876{
877 int i = 0;
878 int len = skb_headlen(skb);
879 void *p = skb->data;
880 int nr_frags = skb_shinfo(skb)->nr_frags;
881
882 seq_printf(s, " len = %d\n", len);
883 wil_seq_hexdump(s, p, len, " : ");
884
885 if (nr_frags) {
886 seq_printf(s, " nr_frags = %d\n", nr_frags);
887 for (i = 0; i < nr_frags; i++) {
888 const struct skb_frag_struct *frag =
889 &skb_shinfo(skb)->frags[i];
890
891 len = skb_frag_size(frag);
892 p = skb_frag_address_safe(frag);
893 seq_printf(s, " [%2d] : len = %d\n", i, len);
894 wil_seq_hexdump(s, p, len, " : ");
895 }
896 }
897}
898
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200899/*---------Tx/Rx descriptor------------*/
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800900static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
901{
902 struct wil6210_priv *wil = s->private;
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200903 struct vring *vring;
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +0200904 bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300905
906 vring = tx ? &wil->vring_tx[dbg_vring_index] : &wil->vring_rx;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800907
908 if (!vring->va) {
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +0200909 if (tx)
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200910 seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index);
911 else
912 seq_puts(s, "No Rx VRING\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800913 return 0;
914 }
915
916 if (dbg_txdesc_index < vring->size) {
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200917 /* use struct vring_tx_desc for Rx as well,
918 * only field used, .dma.length, is the same
919 */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800920 volatile struct vring_tx_desc *d =
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300921 &vring->va[dbg_txdesc_index].tx;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800922 volatile u32 *u = (volatile u32 *)d;
Vladimir Kondratievf88f1132013-07-11 18:03:40 +0300923 struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800924
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +0200925 if (tx)
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200926 seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index,
927 dbg_txdesc_index);
928 else
929 seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800930 seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
931 u[0], u[1], u[2], u[3]);
932 seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
933 u[4], u[5], u[6], u[7]);
Vladimir Kondratiev39c52ee2014-05-27 14:45:49 +0300934 seq_printf(s, " SKB = 0x%p\n", skb);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800935
936 if (skb) {
Vladimir Kondratievc2366582014-03-17 15:34:08 +0200937 skb_get(skb);
938 wil_seq_print_skb(s, skb);
939 kfree_skb(skb);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800940 }
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300941 seq_puts(s, "}\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800942 } else {
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +0200943 if (tx)
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200944 seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
945 dbg_vring_index, dbg_txdesc_index,
946 vring->size);
947 else
948 seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
949 dbg_txdesc_index, vring->size);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800950 }
951
952 return 0;
953}
954
955static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
956{
957 return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
958}
959
960static const struct file_operations fops_txdesc = {
961 .open = wil_txdesc_seq_open,
962 .release = single_release,
963 .read = seq_read,
964 .llseek = seq_lseek,
965};
966
967/*---------beamforming------------*/
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +0300968static char *wil_bfstatus_str(u32 status)
969{
970 switch (status) {
971 case 0:
972 return "Failed";
973 case 1:
974 return "OK";
975 case 2:
976 return "Retrying";
977 default:
978 return "??";
979 }
980}
981
982static bool is_all_zeros(void * const x_, size_t sz)
983{
984 /* if reply is all-0, ignore this CID */
985 u32 *x = x_;
986 int n;
987
988 for (n = 0; n < sz / sizeof(*x); n++)
989 if (x[n])
990 return false;
991
992 return true;
993}
994
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800995static int wil_bf_debugfs_show(struct seq_file *s, void *data)
996{
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +0300997 int rc;
998 int i;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800999 struct wil6210_priv *wil = s->private;
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +03001000 struct wmi_notify_req_cmd cmd = {
1001 .interval_usec = 0,
1002 };
1003 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001004 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +03001005 struct wmi_notify_req_done_event evt;
1006 } __packed reply;
1007
1008 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1009 u32 status;
1010
1011 cmd.cid = i;
1012 rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd),
1013 WMI_NOTIFY_REQ_DONE_EVENTID, &reply,
1014 sizeof(reply), 20);
1015 /* if reply is all-0, ignore this CID */
1016 if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt)))
1017 continue;
1018
1019 status = le32_to_cpu(reply.evt.status);
1020 seq_printf(s, "CID %d {\n"
1021 " TSF = 0x%016llx\n"
1022 " TxMCS = %2d TxTpt = %4d\n"
1023 " SQI = %4d\n"
Dedy Lanskyb3f87382017-08-21 22:58:54 +03001024 " RSSI = %4d\n"
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +03001025 " Status = 0x%08x %s\n"
1026 " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
1027 " Goodput(rx:tx) %4d:%4d\n"
1028 "}\n",
1029 i,
1030 le64_to_cpu(reply.evt.tsf),
1031 le16_to_cpu(reply.evt.bf_mcs),
1032 le32_to_cpu(reply.evt.tx_tpt),
1033 reply.evt.sqi,
Dedy Lanskyb3f87382017-08-21 22:58:54 +03001034 reply.evt.rssi,
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +03001035 status, wil_bfstatus_str(status),
1036 le16_to_cpu(reply.evt.my_rx_sector),
1037 le16_to_cpu(reply.evt.my_tx_sector),
1038 le16_to_cpu(reply.evt.other_rx_sector),
1039 le16_to_cpu(reply.evt.other_tx_sector),
1040 le32_to_cpu(reply.evt.rx_goodput),
1041 le32_to_cpu(reply.evt.tx_goodput));
1042 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001043 return 0;
1044}
1045
1046static int wil_bf_seq_open(struct inode *inode, struct file *file)
1047{
1048 return single_open(file, wil_bf_debugfs_show, inode->i_private);
1049}
1050
1051static const struct file_operations fops_bf = {
1052 .open = wil_bf_seq_open,
1053 .release = single_release,
1054 .read = seq_read,
1055 .llseek = seq_lseek,
1056};
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001057
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001058/*---------SSID------------*/
1059static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf,
1060 size_t count, loff_t *ppos)
1061{
1062 struct wil6210_priv *wil = file->private_data;
1063 struct wireless_dev *wdev = wil_to_wdev(wil);
1064
1065 return simple_read_from_buffer(user_buf, count, ppos,
1066 wdev->ssid, wdev->ssid_len);
1067}
1068
1069static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf,
1070 size_t count, loff_t *ppos)
1071{
1072 struct wil6210_priv *wil = file->private_data;
1073 struct wireless_dev *wdev = wil_to_wdev(wil);
1074 struct net_device *ndev = wil_to_ndev(wil);
1075
1076 if (*ppos != 0) {
1077 wil_err(wil, "Unable to set SSID substring from [%d]\n",
1078 (int)*ppos);
1079 return -EINVAL;
1080 }
1081
1082 if (count > sizeof(wdev->ssid)) {
1083 wil_err(wil, "SSID too long, len = %d\n", (int)count);
1084 return -EINVAL;
1085 }
1086 if (netif_running(ndev)) {
1087 wil_err(wil, "Unable to change SSID on running interface\n");
1088 return -EINVAL;
1089 }
1090
1091 wdev->ssid_len = count;
1092 return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos,
1093 buf, count);
1094}
1095
1096static const struct file_operations fops_ssid = {
1097 .read = wil_read_file_ssid,
1098 .write = wil_write_file_ssid,
Wei Yongjun93ecbd62013-02-26 10:29:34 +08001099 .open = simple_open,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001100};
1101
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001102/*---------temp------------*/
1103static void print_temp(struct seq_file *s, const char *prefix, u32 t)
1104{
1105 switch (t) {
1106 case 0:
1107 case ~(u32)0:
1108 seq_printf(s, "%s N/A\n", prefix);
1109 break;
1110 default:
1111 seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
1112 break;
1113 }
1114}
1115
1116static int wil_temp_debugfs_show(struct seq_file *s, void *data)
1117{
1118 struct wil6210_priv *wil = s->private;
1119 u32 t_m, t_r;
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001120 int rc = wmi_get_temperature(wil, &t_m, &t_r);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001121
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001122 if (rc) {
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001123 seq_puts(s, "Failed\n");
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001124 return 0;
1125 }
1126
Vladimir Kondratievd45cff92014-06-16 19:37:12 +03001127 print_temp(s, "T_mac =", t_m);
1128 print_temp(s, "T_radio =", t_r);
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001129
1130 return 0;
1131}
1132
1133static int wil_temp_seq_open(struct inode *inode, struct file *file)
1134{
1135 return single_open(file, wil_temp_debugfs_show, inode->i_private);
1136}
1137
1138static const struct file_operations fops_temp = {
1139 .open = wil_temp_seq_open,
1140 .release = single_release,
1141 .read = seq_read,
1142 .llseek = seq_lseek,
1143};
1144
Vladimir Kondratiev9eb82d42014-06-16 19:37:13 +03001145/*---------freq------------*/
1146static int wil_freq_debugfs_show(struct seq_file *s, void *data)
1147{
1148 struct wil6210_priv *wil = s->private;
1149 struct wireless_dev *wdev = wil_to_wdev(wil);
1150 u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
1151
1152 seq_printf(s, "Freq = %d\n", freq);
1153
1154 return 0;
1155}
1156
1157static int wil_freq_seq_open(struct inode *inode, struct file *file)
1158{
1159 return single_open(file, wil_freq_debugfs_show, inode->i_private);
1160}
1161
1162static const struct file_operations fops_freq = {
1163 .open = wil_freq_seq_open,
1164 .release = single_release,
1165 .read = seq_read,
1166 .llseek = seq_lseek,
1167};
1168
1169/*---------link------------*/
1170static int wil_link_debugfs_show(struct seq_file *s, void *data)
1171{
1172 struct wil6210_priv *wil = s->private;
1173 struct station_info sinfo;
1174 int i, rc;
1175
1176 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1177 struct wil_sta_info *p = &wil->sta[i];
1178 char *status = "unknown";
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001179
Vladimir Kondratiev9eb82d42014-06-16 19:37:13 +03001180 switch (p->status) {
1181 case wil_sta_unused:
1182 status = "unused ";
1183 break;
1184 case wil_sta_conn_pending:
1185 status = "pending ";
1186 break;
1187 case wil_sta_connected:
1188 status = "connected";
1189 break;
1190 }
Vladimir Kondratiev230d8442015-04-30 16:25:10 +03001191 seq_printf(s, "[%d] %pM %s\n", i, p->addr, status);
Vladimir Kondratiev9eb82d42014-06-16 19:37:13 +03001192
1193 if (p->status == wil_sta_connected) {
1194 rc = wil_cid_fill_sinfo(wil, i, &sinfo);
1195 if (rc)
1196 return rc;
1197
1198 seq_printf(s, " Tx_mcs = %d\n", sinfo.txrate.mcs);
1199 seq_printf(s, " Rx_mcs = %d\n", sinfo.rxrate.mcs);
1200 seq_printf(s, " SQ = %d\n", sinfo.signal);
1201 }
1202 }
1203
1204 return 0;
1205}
1206
1207static int wil_link_seq_open(struct inode *inode, struct file *file)
1208{
1209 return single_open(file, wil_link_debugfs_show, inode->i_private);
1210}
1211
1212static const struct file_operations fops_link = {
1213 .open = wil_link_seq_open,
1214 .release = single_release,
1215 .read = seq_read,
1216 .llseek = seq_lseek,
1217};
1218
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +03001219/*---------info------------*/
1220static int wil_info_debugfs_show(struct seq_file *s, void *data)
1221{
Vladimir Kondratievbe299852014-06-16 19:37:22 +03001222 struct wil6210_priv *wil = s->private;
1223 struct net_device *ndev = wil_to_ndev(wil);
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +03001224 int is_ac = power_supply_is_system_supplied();
Vladimir Kondratievbe299852014-06-16 19:37:22 +03001225 int rx = atomic_xchg(&wil->isr_count_rx, 0);
1226 int tx = atomic_xchg(&wil->isr_count_tx, 0);
1227 static ulong rxf_old, txf_old;
1228 ulong rxf = ndev->stats.rx_packets;
1229 ulong txf = ndev->stats.tx_packets;
Vladimir Kondratiev55f8f682014-06-16 19:37:23 +03001230 unsigned int i;
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +03001231
1232 /* >0 : AC; 0 : battery; <0 : error */
1233 seq_printf(s, "AC powered : %d\n", is_ac);
Vladimir Kondratievbe299852014-06-16 19:37:22 +03001234 seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
1235 seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
1236 rxf_old = rxf;
1237 txf_old = txf;
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +03001238
Vladimir Kondratiev55f8f682014-06-16 19:37:23 +03001239#define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
1240 " " __stringify(x) : ""
1241
1242 for (i = 0; i < ndev->num_tx_queues; i++) {
1243 struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
1244 unsigned long state = txq->state;
1245
1246 seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
1247 CHECK_QSTATE(DRV_XOFF),
1248 CHECK_QSTATE(STACK_XOFF),
1249 CHECK_QSTATE(FROZEN)
1250 );
1251 }
1252#undef CHECK_QSTATE
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +03001253 return 0;
1254}
1255
1256static int wil_info_seq_open(struct inode *inode, struct file *file)
1257{
1258 return single_open(file, wil_info_debugfs_show, inode->i_private);
1259}
1260
1261static const struct file_operations fops_info = {
1262 .open = wil_info_seq_open,
1263 .release = single_release,
1264 .read = seq_read,
1265 .llseek = seq_lseek,
1266};
1267
Vladimir Kondratievc33407a2014-10-01 15:05:24 +03001268/*---------recovery------------*/
1269/* mode = [manual|auto]
1270 * state = [idle|pending|running]
1271 */
1272static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf,
1273 size_t count, loff_t *ppos)
1274{
1275 struct wil6210_priv *wil = file->private_data;
1276 char buf[80];
1277 int n;
1278 static const char * const sstate[] = {"idle", "pending", "running"};
1279
1280 n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n",
1281 no_fw_recovery ? "manual" : "auto",
1282 sstate[wil->recovery_state]);
1283
1284 n = min_t(int, n, sizeof(buf));
1285
1286 return simple_read_from_buffer(user_buf, count, ppos,
1287 buf, n);
1288}
1289
1290static ssize_t wil_write_file_recovery(struct file *file,
1291 const char __user *buf_,
1292 size_t count, loff_t *ppos)
1293{
1294 struct wil6210_priv *wil = file->private_data;
1295 static const char run_command[] = "run";
1296 char buf[sizeof(run_command) + 1]; /* to detect "runx" */
1297 ssize_t rc;
1298
1299 if (wil->recovery_state != fw_recovery_pending) {
1300 wil_err(wil, "No recovery pending\n");
1301 return -EINVAL;
1302 }
1303
1304 if (*ppos != 0) {
1305 wil_err(wil, "Offset [%d]\n", (int)*ppos);
1306 return -EINVAL;
1307 }
1308
1309 if (count > sizeof(buf)) {
1310 wil_err(wil, "Input too long, len = %d\n", (int)count);
1311 return -EINVAL;
1312 }
1313
1314 rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count);
1315 if (rc < 0)
1316 return rc;
1317
1318 buf[rc] = '\0';
1319 if (0 == strcmp(buf, run_command))
1320 wil_set_recovery_state(wil, fw_recovery_running);
1321 else
1322 wil_err(wil, "Bad recovery command \"%s\"\n", buf);
1323
1324 return rc;
1325}
1326
1327static const struct file_operations fops_recovery = {
1328 .read = wil_read_file_recovery,
1329 .write = wil_write_file_recovery,
1330 .open = simple_open,
1331};
1332
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001333/*---------Station matrix------------*/
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001334static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
1335{
1336 int i;
1337 u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
Vladimir Kondratiev91a8edc2015-07-30 13:52:01 +03001338 unsigned long long drop_dup = r->drop_dup, drop_old = r->drop_old;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001339
Vladimir Kondratiev56637e72014-12-23 09:47:06 +02001340 seq_printf(s, "([%2d] %3d TU) 0x%03x [", r->buf_size, r->timeout,
1341 r->head_seq_num);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001342 for (i = 0; i < r->buf_size; i++) {
1343 if (i == index)
1344 seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
1345 else
1346 seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
1347 }
Vladimir Kondratiev91a8edc2015-07-30 13:52:01 +03001348 seq_printf(s,
1349 "] total %llu drop %llu (dup %llu + old %llu) last 0x%03x\n",
1350 r->total, drop_dup + drop_old, drop_dup, drop_old,
1351 r->ssn_last_drop);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001352}
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001353
Vladimir Kondratiev58527422016-03-01 19:18:07 +02001354static void wil_print_rxtid_crypto(struct seq_file *s, int tid,
1355 struct wil_tid_crypto_rx *c)
1356{
1357 int i;
1358
1359 for (i = 0; i < 4; i++) {
1360 struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
1361
1362 if (cc->key_set)
1363 goto has_keys;
1364 }
1365 return;
1366
1367has_keys:
1368 if (tid < WIL_STA_TID_NUM)
1369 seq_printf(s, " [%2d] PN", tid);
1370 else
1371 seq_puts(s, " [GR] PN");
1372
1373 for (i = 0; i < 4; i++) {
1374 struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
1375
1376 seq_printf(s, " [%i%s]%6phN", i, cc->key_set ? "+" : "-",
1377 cc->pn);
1378 }
1379 seq_puts(s, "\n");
1380}
1381
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001382static int wil_sta_debugfs_show(struct seq_file *s, void *data)
Vladimir Kondratievbd332732014-12-23 09:47:24 +02001383__acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001384{
1385 struct wil6210_priv *wil = s->private;
Vladimir Kondratievc4a110d2015-06-09 14:11:18 +03001386 int i, tid, mcs;
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001387
1388 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1389 struct wil_sta_info *p = &wil->sta[i];
1390 char *status = "unknown";
Lior Davida7629792017-02-08 13:16:37 +02001391 u8 aid = 0;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001392
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001393 switch (p->status) {
1394 case wil_sta_unused:
1395 status = "unused ";
1396 break;
1397 case wil_sta_conn_pending:
1398 status = "pending ";
1399 break;
1400 case wil_sta_connected:
1401 status = "connected";
Lior Davida7629792017-02-08 13:16:37 +02001402 aid = p->aid;
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001403 break;
1404 }
Lior Davida7629792017-02-08 13:16:37 +02001405 seq_printf(s, "[%d] %pM %s AID %d\n", i, p->addr, status, aid);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001406
1407 if (p->status == wil_sta_connected) {
Vladimir Kondratievbd332732014-12-23 09:47:24 +02001408 spin_lock_bh(&p->tid_rx_lock);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001409 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1410 struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
Vladimir Kondratiev58527422016-03-01 19:18:07 +02001411 struct wil_tid_crypto_rx *c =
1412 &p->tid_crypto_rx[tid];
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001413
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001414 if (r) {
Vladimir Kondratiev58527422016-03-01 19:18:07 +02001415 seq_printf(s, " [%2d] ", tid);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001416 wil_print_rxtid(s, r);
1417 }
Vladimir Kondratiev58527422016-03-01 19:18:07 +02001418
1419 wil_print_rxtid_crypto(s, tid, c);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001420 }
Vladimir Kondratiev58527422016-03-01 19:18:07 +02001421 wil_print_rxtid_crypto(s, WIL_STA_TID_NUM,
1422 &p->group_crypto_rx);
Vladimir Kondratievbd332732014-12-23 09:47:24 +02001423 spin_unlock_bh(&p->tid_rx_lock);
Vladimir Kondratiev3b282bc2015-10-04 10:23:19 +03001424 seq_printf(s,
Vladimir Kondratiev58527422016-03-01 19:18:07 +02001425 "Rx invalid frame: non-data %lu, short %lu, large %lu, replay %lu\n",
Vladimir Kondratiev3b282bc2015-10-04 10:23:19 +03001426 p->stats.rx_non_data_frame,
1427 p->stats.rx_short_frame,
Vladimir Kondratiev58527422016-03-01 19:18:07 +02001428 p->stats.rx_large_frame,
1429 p->stats.rx_replay);
Vladimir Kondratiev3b282bc2015-10-04 10:23:19 +03001430
Vladimir Kondratievc4a110d2015-06-09 14:11:18 +03001431 seq_puts(s, "Rx/MCS:");
1432 for (mcs = 0; mcs < ARRAY_SIZE(p->stats.rx_per_mcs);
1433 mcs++)
1434 seq_printf(s, " %lld",
1435 p->stats.rx_per_mcs[mcs]);
1436 seq_puts(s, "\n");
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001437 }
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001438 }
1439
1440 return 0;
1441}
1442
1443static int wil_sta_seq_open(struct inode *inode, struct file *file)
1444{
1445 return single_open(file, wil_sta_debugfs_show, inode->i_private);
1446}
1447
1448static const struct file_operations fops_sta = {
1449 .open = wil_sta_seq_open,
1450 .release = single_release,
1451 .read = seq_read,
1452 .llseek = seq_lseek,
1453};
1454
Maya Erez10d599a2016-05-09 21:57:11 +03001455static ssize_t wil_read_file_led_cfg(struct file *file, char __user *user_buf,
1456 size_t count, loff_t *ppos)
1457{
1458 char buf[80];
1459 int n;
1460
1461 n = snprintf(buf, sizeof(buf),
1462 "led_id is set to %d, echo 1 to enable, 0 to disable\n",
1463 led_id);
1464
1465 n = min_t(int, n, sizeof(buf));
1466
1467 return simple_read_from_buffer(user_buf, count, ppos,
1468 buf, n);
1469}
1470
1471static ssize_t wil_write_file_led_cfg(struct file *file,
1472 const char __user *buf_,
1473 size_t count, loff_t *ppos)
1474{
1475 struct wil6210_priv *wil = file->private_data;
1476 int val;
1477 int rc;
1478
1479 rc = kstrtoint_from_user(buf_, count, 0, &val);
1480 if (rc) {
1481 wil_err(wil, "Invalid argument\n");
1482 return rc;
1483 }
1484
1485 wil_info(wil, "%s led %d\n", val ? "Enabling" : "Disabling", led_id);
1486 rc = wmi_led_cfg(wil, val);
1487 if (rc) {
1488 wil_info(wil, "%s led %d failed\n",
1489 val ? "Enabling" : "Disabling", led_id);
1490 return rc;
1491 }
1492
1493 return count;
1494}
1495
1496static const struct file_operations fops_led_cfg = {
1497 .read = wil_read_file_led_cfg,
1498 .write = wil_write_file_led_cfg,
1499 .open = simple_open,
1500};
1501
1502/* led_blink_time, write:
1503 * "<blink_on_slow> <blink_off_slow> <blink_on_med> <blink_off_med> <blink_on_fast> <blink_off_fast>
1504 */
1505static ssize_t wil_write_led_blink_time(struct file *file,
1506 const char __user *buf,
1507 size_t len, loff_t *ppos)
1508{
1509 int rc;
1510 char *kbuf = kmalloc(len + 1, GFP_KERNEL);
1511
1512 if (!kbuf)
1513 return -ENOMEM;
1514
1515 rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
1516 if (rc != len) {
1517 kfree(kbuf);
1518 return rc >= 0 ? -EIO : rc;
1519 }
1520
1521 kbuf[len] = '\0';
1522 rc = sscanf(kbuf, "%d %d %d %d %d %d",
1523 &led_blink_time[WIL_LED_TIME_SLOW].on_ms,
1524 &led_blink_time[WIL_LED_TIME_SLOW].off_ms,
1525 &led_blink_time[WIL_LED_TIME_MED].on_ms,
1526 &led_blink_time[WIL_LED_TIME_MED].off_ms,
1527 &led_blink_time[WIL_LED_TIME_FAST].on_ms,
1528 &led_blink_time[WIL_LED_TIME_FAST].off_ms);
1529 kfree(kbuf);
1530
1531 if (rc < 0)
1532 return rc;
1533 if (rc < 6)
1534 return -EINVAL;
1535
1536 return len;
1537}
1538
1539static ssize_t wil_read_led_blink_time(struct file *file, char __user *user_buf,
1540 size_t count, loff_t *ppos)
1541{
1542 static char text[400];
1543
1544 snprintf(text, sizeof(text),
1545 "To set led blink on/off time variables write:\n"
1546 "<blink_on_slow> <blink_off_slow> <blink_on_med> "
1547 "<blink_off_med> <blink_on_fast> <blink_off_fast>\n"
1548 "The current values are:\n"
1549 "%d %d %d %d %d %d\n",
1550 led_blink_time[WIL_LED_TIME_SLOW].on_ms,
1551 led_blink_time[WIL_LED_TIME_SLOW].off_ms,
1552 led_blink_time[WIL_LED_TIME_MED].on_ms,
1553 led_blink_time[WIL_LED_TIME_MED].off_ms,
1554 led_blink_time[WIL_LED_TIME_FAST].on_ms,
1555 led_blink_time[WIL_LED_TIME_FAST].off_ms);
1556
1557 return simple_read_from_buffer(user_buf, count, ppos, text,
1558 sizeof(text));
1559}
1560
1561static const struct file_operations fops_led_blink_time = {
1562 .read = wil_read_led_blink_time,
1563 .write = wil_write_led_blink_time,
1564 .open = simple_open,
1565};
1566
Lior David12bace72016-08-22 12:42:21 +03001567/*---------FW capabilities------------*/
1568static int wil_fw_capabilities_debugfs_show(struct seq_file *s, void *data)
1569{
1570 struct wil6210_priv *wil = s->private;
1571
1572 seq_printf(s, "fw_capabilities : %*pb\n", WMI_FW_CAPABILITY_MAX,
1573 wil->fw_capabilities);
1574
1575 return 0;
1576}
1577
1578static int wil_fw_capabilities_seq_open(struct inode *inode, struct file *file)
1579{
1580 return single_open(file, wil_fw_capabilities_debugfs_show,
1581 inode->i_private);
1582}
1583
1584static const struct file_operations fops_fw_capabilities = {
1585 .open = wil_fw_capabilities_seq_open,
1586 .release = single_release,
1587 .read = seq_read,
1588 .llseek = seq_lseek,
1589};
1590
Lior David13cd9f72016-08-22 12:42:22 +03001591/*---------FW version------------*/
1592static int wil_fw_version_debugfs_show(struct seq_file *s, void *data)
1593{
1594 struct wil6210_priv *wil = s->private;
1595
1596 if (wil->fw_version[0])
1597 seq_printf(s, "%s\n", wil->fw_version);
1598 else
1599 seq_puts(s, "N/A\n");
1600
1601 return 0;
1602}
1603
1604static int wil_fw_version_seq_open(struct inode *inode, struct file *file)
1605{
1606 return single_open(file, wil_fw_version_debugfs_show,
1607 inode->i_private);
1608}
1609
1610static const struct file_operations fops_fw_version = {
1611 .open = wil_fw_version_seq_open,
1612 .release = single_release,
1613 .read = seq_read,
1614 .llseek = seq_lseek,
1615};
1616
Maya Ereze3309bf2017-05-15 16:57:46 +03001617/*---------suspend_stats---------*/
1618static ssize_t wil_write_suspend_stats(struct file *file,
1619 const char __user *buf,
1620 size_t len, loff_t *ppos)
1621{
1622 struct wil6210_priv *wil = file->private_data;
1623
1624 memset(&wil->suspend_stats, 0, sizeof(wil->suspend_stats));
Maya Erez2f9f6422017-08-21 22:43:32 +03001625 wil->suspend_stats.min_suspend_time = ULONG_MAX;
1626 wil->suspend_stats.collection_start = ktime_get();
Maya Ereze3309bf2017-05-15 16:57:46 +03001627
1628 return len;
1629}
1630
1631static ssize_t wil_read_suspend_stats(struct file *file,
1632 char __user *user_buf,
1633 size_t count, loff_t *ppos)
1634{
1635 struct wil6210_priv *wil = file->private_data;
1636 static char text[400];
1637 int n;
Maya Erez2f9f6422017-08-21 22:43:32 +03001638 unsigned long long stats_collection_time =
1639 ktime_to_us(ktime_sub(ktime_get(),
1640 wil->suspend_stats.collection_start));
Maya Ereze3309bf2017-05-15 16:57:46 +03001641
1642 n = snprintf(text, sizeof(text),
1643 "Suspend statistics:\n"
1644 "successful suspends:%ld failed suspends:%ld\n"
1645 "successful resumes:%ld failed resumes:%ld\n"
Maya Erez2f9f6422017-08-21 22:43:32 +03001646 "rejected by host:%ld rejected by device:%ld\n"
1647 "total suspend time:%lld min suspend time:%lld\n"
1648 "max suspend time:%lld stats collection time: %lld\n",
Maya Ereze3309bf2017-05-15 16:57:46 +03001649 wil->suspend_stats.successful_suspends,
1650 wil->suspend_stats.failed_suspends,
1651 wil->suspend_stats.successful_resumes,
1652 wil->suspend_stats.failed_resumes,
1653 wil->suspend_stats.rejected_by_host,
Maya Erez2f9f6422017-08-21 22:43:32 +03001654 wil->suspend_stats.rejected_by_device,
1655 wil->suspend_stats.total_suspend_time,
1656 wil->suspend_stats.min_suspend_time,
1657 wil->suspend_stats.max_suspend_time,
1658 stats_collection_time);
Maya Ereze3309bf2017-05-15 16:57:46 +03001659
1660 n = min_t(int, n, sizeof(text));
1661
1662 return simple_read_from_buffer(user_buf, count, ppos, text, n);
1663}
1664
1665static const struct file_operations fops_suspend_stats = {
1666 .read = wil_read_suspend_stats,
1667 .write = wil_write_suspend_stats,
1668 .open = simple_open,
1669};
1670
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001671/*----------------*/
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +03001672static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
1673 struct dentry *dbg)
1674{
1675 int i;
1676 char name[32];
1677
1678 for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
Maya Erez349214c2016-04-26 14:41:41 +03001679 struct wil_blob_wrapper *wil_blob = &wil->blobs[i];
1680 struct debugfs_blob_wrapper *blob = &wil_blob->blob;
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +03001681 const struct fw_map *map = &fw_mapping[i];
1682
1683 if (!map->name)
1684 continue;
1685
Maya Erez349214c2016-04-26 14:41:41 +03001686 wil_blob->wil = wil;
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +03001687 blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
1688 blob->size = map->to - map->from;
1689 snprintf(name, sizeof(name), "blob_%s", map->name);
Maya Erezc2256ec2017-02-08 13:18:42 +02001690 wil_debugfs_create_ioblob(name, 0444, dbg, wil_blob);
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +03001691 }
1692}
1693
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001694/* misc files */
1695static const struct {
1696 const char *name;
1697 umode_t mode;
1698 const struct file_operations *fops;
1699} dbg_files[] = {
Maya Erezc2256ec2017-02-08 13:18:42 +02001700 {"mbox", 0444, &fops_mbox},
1701 {"vrings", 0444, &fops_vring},
1702 {"stations", 0444, &fops_sta},
1703 {"desc", 0444, &fops_txdesc},
1704 {"bf", 0444, &fops_bf},
1705 {"ssid", 0644, &fops_ssid},
1706 {"mem_val", 0644, &fops_memread},
1707 {"reset", 0244, &fops_reset},
1708 {"rxon", 0244, &fops_rxon},
1709 {"tx_mgmt", 0244, &fops_txmgmt},
1710 {"wmi_send", 0244, &fops_wmi},
1711 {"back", 0644, &fops_back},
1712 {"pmccfg", 0644, &fops_pmccfg},
1713 {"pmcdata", 0444, &fops_pmcdata},
1714 {"temp", 0444, &fops_temp},
1715 {"freq", 0444, &fops_freq},
1716 {"link", 0444, &fops_link},
1717 {"info", 0444, &fops_info},
1718 {"recovery", 0644, &fops_recovery},
1719 {"led_cfg", 0644, &fops_led_cfg},
1720 {"led_blink_time", 0644, &fops_led_blink_time},
1721 {"fw_capabilities", 0444, &fops_fw_capabilities},
1722 {"fw_version", 0444, &fops_fw_version},
Maya Ereze3309bf2017-05-15 16:57:46 +03001723 {"suspend_stats", 0644, &fops_suspend_stats},
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001724};
1725
1726static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
1727 struct dentry *dbg)
1728{
1729 int i;
1730
1731 for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
1732 debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
1733 wil, dbg_files[i].fops);
1734}
1735
1736/* interrupt control blocks */
1737static const struct {
1738 const char *name;
1739 u32 icr_off;
1740} dbg_icr[] = {
1741 {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)},
1742 {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)},
1743 {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)},
1744 {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)},
1745};
1746
1747static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
1748 struct dentry *dbg)
1749{
1750 int i;
1751
1752 for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
1753 wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
1754 dbg_icr[i].icr_off);
1755}
1756
1757#define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
1758 offsetof(struct wil6210_priv, name), type}
1759
1760/* fields in struct wil6210_priv */
1761static const struct dbg_off dbg_wil_off[] = {
Maya Erezc2256ec2017-02-08 13:18:42 +02001762 WIL_FIELD(privacy, 0444, doff_u32),
1763 WIL_FIELD(status[0], 0644, doff_ulong),
1764 WIL_FIELD(hw_version, 0444, doff_x32),
1765 WIL_FIELD(recovery_count, 0444, doff_u32),
1766 WIL_FIELD(ap_isolate, 0444, doff_u32),
1767 WIL_FIELD(discovery_mode, 0644, doff_u8),
1768 WIL_FIELD(chip_revision, 0444, doff_u8),
1769 WIL_FIELD(abft_len, 0644, doff_u8),
Maya Ereze3309bf2017-05-15 16:57:46 +03001770 WIL_FIELD(wakeup_trigger, 0644, doff_u8),
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001771 {},
1772};
1773
1774static const struct dbg_off dbg_wil_regs[] = {
Maya Erezc2256ec2017-02-08 13:18:42 +02001775 {"RGF_MAC_MTRL_COUNTER_0", 0444, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001776 doff_io32},
Maya Erezc2256ec2017-02-08 13:18:42 +02001777 {"RGF_USER_USAGE_1", 0444, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001778 {},
1779};
1780
1781/* static parameters */
1782static const struct dbg_off dbg_statics[] = {
Maya Erezc2256ec2017-02-08 13:18:42 +02001783 {"desc_index", 0644, (ulong)&dbg_txdesc_index, doff_u32},
1784 {"vring_index", 0644, (ulong)&dbg_vring_index, doff_u32},
1785 {"mem_addr", 0644, (ulong)&mem_addr, doff_u32},
1786 {"vring_idle_trsh", 0644, (ulong)&vring_idle_trsh,
Vladimir Shulman0436fd92015-02-15 14:02:34 +02001787 doff_u32},
Maya Erezc2256ec2017-02-08 13:18:42 +02001788 {"led_polarity", 0644, (ulong)&led_polarity, doff_u8},
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001789 {},
1790};
1791
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001792int wil6210_debugfs_init(struct wil6210_priv *wil)
1793{
1794 struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
1795 wil_to_wiphy(wil)->debugfsdir);
1796
1797 if (IS_ERR_OR_NULL(dbg))
1798 return -ENODEV;
1799
Vladimir Kondratievdc164272015-04-30 16:25:09 +03001800 wil_pmc_init(wil);
1801
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001802 wil6210_debugfs_init_files(wil, dbg);
1803 wil6210_debugfs_init_isr(wil, dbg);
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +03001804 wil6210_debugfs_init_blobs(wil, dbg);
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001805 wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
1806 wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
1807 dbg_wil_regs);
1808 wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
1809
1810 wil6210_debugfs_create_pseudo_ISR(wil, dbg);
1811
1812 wil6210_debugfs_create_ITR_CNT(wil, dbg);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001813
Maya Erez2f9f6422017-08-21 22:43:32 +03001814 wil->suspend_stats.collection_start = ktime_get();
1815
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001816 return 0;
1817}
1818
1819void wil6210_debugfs_remove(struct wil6210_priv *wil)
1820{
1821 debugfs_remove_recursive(wil->debug);
1822 wil->debug = NULL;
Vladimir Kondratievdc164272015-04-30 16:25:09 +03001823
1824 /* free pmc memory without sending command to fw, as it will
1825 * be reset on the way down anyway
1826 */
1827 wil_pmc_free(wil, false);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001828}