blob: 45a808139f6ebd11fed85466bbdf4256aca39b69 [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#include "wil6210.h"
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +030024#include "wmi.h"
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080025#include "txrx.h"
Vladimir Kondratievdc164272015-04-30 16:25:09 +030026#include "pmc.h"
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080027
28/* Nasty hack. Better have per device instances */
29static u32 mem_addr;
30static u32 dbg_txdesc_index;
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +020031static u32 dbg_vring_index; /* 24+ for Rx, 0..23 for Tx */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080032
Vladimir Kondratievb7cde472014-08-06 10:31:55 +030033enum dbg_off_type {
34 doff_u32 = 0,
35 doff_x32 = 1,
36 doff_ulong = 2,
37 doff_io32 = 3,
Lior David74997a52016-03-01 19:18:08 +020038 doff_u8 = 4
Vladimir Kondratievb7cde472014-08-06 10:31:55 +030039};
40
41/* offset to "wil" */
42struct dbg_off {
43 const char *name;
44 umode_t mode;
45 ulong off;
46 enum dbg_off_type type;
47};
48
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080049static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil,
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +020050 const char *name, struct vring *vring,
51 char _s, char _h)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080052{
53 void __iomem *x = wmi_addr(wil, vring->hwtail);
Vladimir Kondratiev995cdd02014-12-23 09:47:08 +020054 u32 v;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080055
56 seq_printf(s, "VRING %s = {\n", name);
Vladimir Kondratiev39c52ee2014-05-27 14:45:49 +030057 seq_printf(s, " pa = %pad\n", &vring->pa);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080058 seq_printf(s, " va = 0x%p\n", vring->va);
59 seq_printf(s, " size = %d\n", vring->size);
60 seq_printf(s, " swtail = %d\n", vring->swtail);
61 seq_printf(s, " swhead = %d\n", vring->swhead);
62 seq_printf(s, " hwtail = [0x%08x] -> ", vring->hwtail);
Vladimir Kondratiev995cdd02014-12-23 09:47:08 +020063 if (x) {
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +030064 v = readl(x);
Vladimir Kondratiev995cdd02014-12-23 09:47:08 +020065 seq_printf(s, "0x%08x = %d\n", v, v);
66 } else {
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030067 seq_puts(s, "???\n");
Vladimir Kondratiev995cdd02014-12-23 09:47:08 +020068 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080069
Hamad Kadmanyee5dfe02016-01-28 19:24:05 +020070 if (vring->va && (vring->size <= (1 << WIL_RING_SIZE_ORDER_MAX))) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080071 uint i;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030072
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080073 for (i = 0; i < vring->size; i++) {
74 volatile struct vring_tx_desc *d = &vring->va[i].tx;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030075
Hamad Kadmanyee5dfe02016-01-28 19:24:05 +020076 if ((i % 128) == 0 && (i != 0))
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030077 seq_puts(s, "\n");
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +020078 seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
79 _s : (vring->ctx[i].skb ? _h : 'h'));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080080 }
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030081 seq_puts(s, "\n");
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}
85
86static int wil_vring_debugfs_show(struct seq_file *s, void *data)
87{
88 uint i;
89 struct wil6210_priv *wil = s->private;
90
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +020091 wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_');
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080092
93 for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030094 struct vring *vring = &wil->vring_tx[i];
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +030095 struct vring_tx_data *txdata = &wil->vring_tx_data[i];
96
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080097 if (vring->va) {
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +020098 int cid = wil->vring2cid_tid[i][0];
99 int tid = wil->vring2cid_tid[i][1];
Vladimir Kondratiev67c3e1b2014-06-16 19:37:04 +0300100 u32 swhead = vring->swhead;
101 u32 swtail = vring->swtail;
102 int used = (vring->size + swhead - swtail)
103 % vring->size;
104 int avail = vring->size - used - 1;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800105 char name[10];
Boris Sorochkin8f55cbe2015-02-15 14:02:35 +0200106 char sidle[10];
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +0300107 /* performance monitoring */
108 cycles_t now = get_cycles();
Chen Gangc20e7782014-12-24 23:08:44 +0800109 uint64_t idle = txdata->idle * 100;
110 uint64_t total = now - txdata->begin;
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +0300111
Boris Sorochkin8f55cbe2015-02-15 14:02:35 +0200112 if (total != 0) {
113 do_div(idle, total);
114 snprintf(sidle, sizeof(sidle), "%3d%%",
115 (int)idle);
116 } else {
117 snprintf(sidle, sizeof(sidle), "N/A");
118 }
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +0300119 txdata->begin = now;
120 txdata->idle = 0ULL;
121
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800122 snprintf(name, sizeof(name), "tx_%2d", i);
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200123
Vladimir Kondratiev41d6b092015-03-15 16:00:23 +0200124 if (cid < WIL6210_MAX_CID)
125 seq_printf(s,
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300126 "\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 +0200127 wil->sta[cid].addr, cid, tid,
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300128 txdata->dot1x_open ? "+" : "-",
Vladimir Kondratiev41d6b092015-03-15 16:00:23 +0200129 txdata->agg_wsize,
130 txdata->agg_timeout,
131 txdata->agg_amsdu ? "+" : "-",
132 used, avail, sidle);
133 else
134 seq_printf(s,
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300135 "\nBroadcast 1x%s [%3d|%3d] idle %s\n",
136 txdata->dot1x_open ? "+" : "-",
Vladimir Kondratiev41d6b092015-03-15 16:00:23 +0200137 used, avail, sidle);
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +0300138
Vladimir Kondratiev59f7c0a2014-02-27 16:20:42 +0200139 wil_print_vring(s, wil, name, vring, '_', 'H');
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800140 }
141 }
142
143 return 0;
144}
145
146static int wil_vring_seq_open(struct inode *inode, struct file *file)
147{
148 return single_open(file, wil_vring_debugfs_show, inode->i_private);
149}
150
151static const struct file_operations fops_vring = {
152 .open = wil_vring_seq_open,
153 .release = single_release,
154 .read = seq_read,
155 .llseek = seq_lseek,
156};
157
Andy Shevchenkoa202fbb2015-09-09 15:38:48 -0700158static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
159 const char *prefix)
160{
161 seq_hex_dump(s, prefix, DUMP_PREFIX_NONE, 16, 1, p, len, false);
162}
163
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800164static void wil_print_ring(struct seq_file *s, const char *prefix,
165 void __iomem *off)
166{
167 struct wil6210_priv *wil = s->private;
168 struct wil6210_mbox_ring r;
169 int rsize;
170 uint i;
171
Maya Erez349214c2016-04-26 14:41:41 +0300172 wil_halp_vote(wil);
173
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800174 wil_memcpy_fromio_32(&r, off, sizeof(r));
175 wil_mbox_ring_le2cpus(&r);
176 /*
177 * we just read memory block from NIC. This memory may be
178 * garbage. Check validity before using it.
179 */
180 rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
181
182 seq_printf(s, "ring %s = {\n", prefix);
183 seq_printf(s, " base = 0x%08x\n", r.base);
184 seq_printf(s, " size = 0x%04x bytes -> %d entries\n", r.size, rsize);
185 seq_printf(s, " tail = 0x%08x\n", r.tail);
186 seq_printf(s, " head = 0x%08x\n", r.head);
187 seq_printf(s, " entry size = %d\n", r.entry_size);
188
189 if (r.size % sizeof(struct wil6210_mbox_ring_desc)) {
190 seq_printf(s, " ??? size is not multiple of %zd, garbage?\n",
191 sizeof(struct wil6210_mbox_ring_desc));
192 goto out;
193 }
194
195 if (!wmi_addr(wil, r.base) ||
196 !wmi_addr(wil, r.tail) ||
197 !wmi_addr(wil, r.head)) {
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300198 seq_puts(s, " ??? pointers are garbage?\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800199 goto out;
200 }
201
202 for (i = 0; i < rsize; i++) {
203 struct wil6210_mbox_ring_desc d;
204 struct wil6210_mbox_hdr hdr;
205 size_t delta = i * sizeof(d);
206 void __iomem *x = wil->csr + HOSTADDR(r.base) + delta;
207
208 wil_memcpy_fromio_32(&d, x, sizeof(d));
209
210 seq_printf(s, " [%2x] %s %s%s 0x%08x", i,
211 d.sync ? "F" : "E",
212 (r.tail - r.base == delta) ? "t" : " ",
213 (r.head - r.base == delta) ? "h" : " ",
214 le32_to_cpu(d.addr));
215 if (0 == wmi_read_hdr(wil, d.addr, &hdr)) {
216 u16 len = le16_to_cpu(hdr.len);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300217
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800218 seq_printf(s, " -> %04x %04x %04x %02x\n",
219 le16_to_cpu(hdr.seq), len,
220 le16_to_cpu(hdr.type), hdr.flags);
221 if (len <= MAX_MBOXITEM_SIZE) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800222 unsigned char databuf[MAX_MBOXITEM_SIZE];
223 void __iomem *src = wmi_buffer(wil, d.addr) +
224 sizeof(struct wil6210_mbox_hdr);
225 /*
226 * No need to check @src for validity -
227 * we already validated @d.addr while
228 * reading header
229 */
230 wil_memcpy_fromio_32(databuf, src, len);
Andy Shevchenkoa202fbb2015-09-09 15:38:48 -0700231 wil_seq_hexdump(s, databuf, len, " : ");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800232 }
233 } else {
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300234 seq_puts(s, "\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800235 }
236 }
237 out:
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300238 seq_puts(s, "}\n");
Maya Erez349214c2016-04-26 14:41:41 +0300239 wil_halp_unvote(wil);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800240}
241
242static int wil_mbox_debugfs_show(struct seq_file *s, void *data)
243{
244 struct wil6210_priv *wil = s->private;
245
246 wil_print_ring(s, "tx", wil->csr + HOST_MBOX +
247 offsetof(struct wil6210_mbox_ctl, tx));
248 wil_print_ring(s, "rx", wil->csr + HOST_MBOX +
249 offsetof(struct wil6210_mbox_ctl, rx));
250
251 return 0;
252}
253
254static int wil_mbox_seq_open(struct inode *inode, struct file *file)
255{
256 return single_open(file, wil_mbox_debugfs_show, inode->i_private);
257}
258
259static const struct file_operations fops_mbox = {
260 .open = wil_mbox_seq_open,
261 .release = single_release,
262 .read = seq_read,
263 .llseek = seq_lseek,
264};
265
266static int wil_debugfs_iomem_x32_set(void *data, u64 val)
267{
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300268 writel(val, (void __iomem *)data);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800269 wmb(); /* make sure write propagated to HW */
270
271 return 0;
272}
273
274static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
275{
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300276 *val = readl((void __iomem *)data);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800277
278 return 0;
279}
280
281DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
282 wil_debugfs_iomem_x32_set, "0x%08llx\n");
283
284static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
Al Viro0ecc8332013-03-29 12:23:28 -0400285 umode_t mode,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800286 struct dentry *parent,
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300287 void *value)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800288{
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300289 return debugfs_create_file(name, mode, parent, value,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800290 &fops_iomem_x32);
291}
292
Vladimir Kondratiev3de6cf22014-06-16 19:37:02 +0300293static int wil_debugfs_ulong_set(void *data, u64 val)
294{
295 *(ulong *)data = val;
296 return 0;
297}
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300298
Vladimir Kondratiev3de6cf22014-06-16 19:37:02 +0300299static int wil_debugfs_ulong_get(void *data, u64 *val)
300{
301 *val = *(ulong *)data;
302 return 0;
303}
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300304
Vladimir Kondratiev3de6cf22014-06-16 19:37:02 +0300305DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
Vladimir Kondratiev8ea06182015-07-30 13:51:51 +0300306 wil_debugfs_ulong_set, "0x%llx\n");
Vladimir Kondratiev3de6cf22014-06-16 19:37:02 +0300307
308static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode,
309 struct dentry *parent,
310 ulong *value)
311{
312 return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong);
313}
314
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300315/**
316 * wil6210_debugfs_init_offset - create set of debugfs files
317 * @wil - driver's context, used for printing
318 * @dbg - directory on the debugfs, where files will be created
319 * @base - base address used in address calculation
320 * @tbl - table with file descriptions. Should be terminated with empty element.
321 *
322 * Creates files accordingly to the @tbl.
323 */
324static void wil6210_debugfs_init_offset(struct wil6210_priv *wil,
325 struct dentry *dbg, void *base,
326 const struct dbg_off * const tbl)
327{
328 int i;
329
330 for (i = 0; tbl[i].name; i++) {
Vladimir Kondratiev867fa0d2014-09-10 16:34:51 +0300331 struct dentry *f;
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300332
333 switch (tbl[i].type) {
334 case doff_u32:
335 f = debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg,
336 base + tbl[i].off);
337 break;
338 case doff_x32:
339 f = debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg,
340 base + tbl[i].off);
341 break;
342 case doff_ulong:
343 f = wil_debugfs_create_ulong(tbl[i].name, tbl[i].mode,
344 dbg, base + tbl[i].off);
345 break;
346 case doff_io32:
347 f = wil_debugfs_create_iomem_x32(tbl[i].name,
348 tbl[i].mode, dbg,
349 base + tbl[i].off);
350 break;
Lior David74997a52016-03-01 19:18:08 +0200351 case doff_u8:
352 f = debugfs_create_u8(tbl[i].name, tbl[i].mode, dbg,
353 base + tbl[i].off);
354 break;
Vladimir Kondratiev867fa0d2014-09-10 16:34:51 +0300355 default:
356 f = ERR_PTR(-EINVAL);
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300357 }
358 if (IS_ERR_OR_NULL(f))
359 wil_err(wil, "Create file \"%s\": err %ld\n",
360 tbl[i].name, PTR_ERR(f));
361 }
362}
363
364static const struct dbg_off isr_off[] = {
Maya Erezc2256ec2017-02-08 13:18:42 +0200365 {"ICC", 0644, offsetof(struct RGF_ICR, ICC), doff_io32},
366 {"ICR", 0644, offsetof(struct RGF_ICR, ICR), doff_io32},
367 {"ICM", 0644, offsetof(struct RGF_ICR, ICM), doff_io32},
368 {"ICS", 0244, offsetof(struct RGF_ICR, ICS), doff_io32},
369 {"IMV", 0644, offsetof(struct RGF_ICR, IMV), doff_io32},
370 {"IMS", 0244, offsetof(struct RGF_ICR, IMS), doff_io32},
371 {"IMC", 0244, offsetof(struct RGF_ICR, IMC), doff_io32},
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300372 {},
373};
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300374
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800375static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
376 const char *name,
377 struct dentry *parent, u32 off)
378{
379 struct dentry *d = debugfs_create_dir(name, parent);
380
381 if (IS_ERR_OR_NULL(d))
382 return -ENODEV;
383
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300384 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off,
385 isr_off);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800386
387 return 0;
388}
389
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300390static const struct dbg_off pseudo_isr_off[] = {
Maya Erezc2256ec2017-02-08 13:18:42 +0200391 {"CAUSE", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32},
392 {"MASK_SW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32},
393 {"MASK_FW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32},
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300394 {},
395};
396
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800397static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
398 struct dentry *parent)
399{
400 struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
401
402 if (IS_ERR_OR_NULL(d))
403 return -ENODEV;
404
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300405 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
406 pseudo_isr_off);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800407
408 return 0;
409}
410
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200411static const struct dbg_off lgc_itr_cnt_off[] = {
Maya Erezc2256ec2017-02-08 13:18:42 +0200412 {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32},
413 {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32},
414 {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32},
Vladimir Kondratievb7cde472014-08-06 10:31:55 +0300415 {},
416};
417
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200418static const struct dbg_off tx_itr_cnt_off[] = {
Maya Erezc2256ec2017-02-08 13:18:42 +0200419 {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_TRSH),
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200420 doff_io32},
Maya Erezc2256ec2017-02-08 13:18:42 +0200421 {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_DATA),
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200422 doff_io32},
Maya Erezc2256ec2017-02-08 13:18:42 +0200423 {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_CTL),
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200424 doff_io32},
Maya Erezc2256ec2017-02-08 13:18:42 +0200425 {"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_TRSH),
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200426 doff_io32},
Maya Erezc2256ec2017-02-08 13:18:42 +0200427 {"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_DATA),
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200428 doff_io32},
Maya Erezc2256ec2017-02-08 13:18:42 +0200429 {"IDL_CTL", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_CTL),
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200430 doff_io32},
431 {},
432};
433
434static const struct dbg_off rx_itr_cnt_off[] = {
Maya Erezc2256ec2017-02-08 13:18:42 +0200435 {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_TRSH),
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200436 doff_io32},
Maya Erezc2256ec2017-02-08 13:18:42 +0200437 {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_DATA),
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200438 doff_io32},
Maya Erezc2256ec2017-02-08 13:18:42 +0200439 {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_CTL),
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200440 doff_io32},
Maya Erezc2256ec2017-02-08 13:18:42 +0200441 {"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_TRSH),
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200442 doff_io32},
Maya Erezc2256ec2017-02-08 13:18:42 +0200443 {"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_DATA),
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200444 doff_io32},
Maya Erezc2256ec2017-02-08 13:18:42 +0200445 {"IDL_CTL", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_CTL),
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200446 doff_io32},
447 {},
448};
449
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800450static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
451 struct dentry *parent)
452{
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200453 struct dentry *d, *dtx, *drx;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800454
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200455 d = debugfs_create_dir("ITR_CNT", parent);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800456 if (IS_ERR_OR_NULL(d))
457 return -ENODEV;
458
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200459 dtx = debugfs_create_dir("TX", d);
460 drx = debugfs_create_dir("RX", d);
461 if (IS_ERR_OR_NULL(dtx) || IS_ERR_OR_NULL(drx))
462 return -ENODEV;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800463
Vladimir Kondratiev78366f62014-12-23 09:47:19 +0200464 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
465 lgc_itr_cnt_off);
466
467 wil6210_debugfs_init_offset(wil, dtx, (void * __force)wil->csr,
468 tx_itr_cnt_off);
469
470 wil6210_debugfs_init_offset(wil, drx, (void * __force)wil->csr,
471 rx_itr_cnt_off);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800472 return 0;
473}
474
475static int wil_memread_debugfs_show(struct seq_file *s, void *data)
476{
477 struct wil6210_priv *wil = s->private;
478 void __iomem *a = wmi_buffer(wil, cpu_to_le32(mem_addr));
479
480 if (a)
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300481 seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, readl(a));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800482 else
483 seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
484
485 return 0;
486}
487
488static int wil_memread_seq_open(struct inode *inode, struct file *file)
489{
490 return single_open(file, wil_memread_debugfs_show, inode->i_private);
491}
492
493static const struct file_operations fops_memread = {
494 .open = wil_memread_seq_open,
495 .release = single_release,
496 .read = seq_read,
497 .llseek = seq_lseek,
498};
499
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800500static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300501 size_t count, loff_t *ppos)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800502{
503 enum { max_count = 4096 };
Maya Erez349214c2016-04-26 14:41:41 +0300504 struct wil_blob_wrapper *wil_blob = file->private_data;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800505 loff_t pos = *ppos;
Maya Erez349214c2016-04-26 14:41:41 +0300506 size_t available = wil_blob->blob.size;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800507 void *buf;
508 size_t ret;
509
Maya Ereze3309bf2017-05-15 16:57:46 +0300510 if (test_bit(wil_status_suspending, wil_blob->wil->status) ||
511 test_bit(wil_status_suspended, wil_blob->wil->status))
512 return 0;
513
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800514 if (pos < 0)
515 return -EINVAL;
516
517 if (pos >= available || !count)
518 return 0;
519
520 if (count > available - pos)
521 count = available - pos;
522 if (count > max_count)
523 count = max_count;
524
525 buf = kmalloc(count, GFP_KERNEL);
526 if (!buf)
527 return -ENOMEM;
528
Maya Ereze6d8b242017-04-03 13:59:04 +0300529 wil_memcpy_fromio_32(buf, (const void __iomem *)
530 wil_blob->blob.data + pos, count);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800531
532 ret = copy_to_user(user_buf, buf, count);
533 kfree(buf);
534 if (ret == count)
535 return -EFAULT;
536
537 count -= ret;
538 *ppos = pos + count;
539
540 return count;
541}
542
543static const struct file_operations fops_ioblob = {
544 .read = wil_read_file_ioblob,
Wei Yongjun93ecbd62013-02-26 10:29:34 +0800545 .open = simple_open,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800546 .llseek = default_llseek,
547};
548
549static
550struct dentry *wil_debugfs_create_ioblob(const char *name,
Al Viro0ecc8332013-03-29 12:23:28 -0400551 umode_t mode,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800552 struct dentry *parent,
Maya Erez349214c2016-04-26 14:41:41 +0300553 struct wil_blob_wrapper *wil_blob)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800554{
Maya Erez349214c2016-04-26 14:41:41 +0300555 return debugfs_create_file(name, mode, parent, wil_blob, &fops_ioblob);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800556}
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300557
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800558/*---reset---*/
559static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
560 size_t len, loff_t *ppos)
561{
562 struct wil6210_priv *wil = file->private_data;
563 struct net_device *ndev = wil_to_ndev(wil);
564
565 /**
566 * BUG:
567 * this code does NOT sync device state with the rest of system
568 * use with care, debug only!!!
569 */
570 rtnl_lock();
571 dev_close(ndev);
572 ndev->flags &= ~IFF_UP;
573 rtnl_unlock();
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200574 wil_reset(wil, true);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800575
576 return len;
577}
578
579static const struct file_operations fops_reset = {
580 .write = wil_write_file_reset,
Wei Yongjun93ecbd62013-02-26 10:29:34 +0800581 .open = simple_open,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800582};
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300583
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300584/*---write channel 1..4 to rxon for it, 0 to rxoff---*/
585static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
586 size_t len, loff_t *ppos)
587{
588 struct wil6210_priv *wil = file->private_data;
589 int rc;
590 long channel;
591 bool on;
592
Al Viro16e5c1f2015-12-24 00:06:05 -0500593 char *kbuf = memdup_user_nul(buf, len);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300594
Al Viro16e5c1f2015-12-24 00:06:05 -0500595 if (IS_ERR(kbuf))
596 return PTR_ERR(kbuf);
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300597 rc = kstrtol(kbuf, 0, &channel);
598 kfree(kbuf);
599 if (rc)
600 return rc;
601
602 if ((channel < 0) || (channel > 4)) {
603 wil_err(wil, "Invalid channel %ld\n", channel);
604 return -EINVAL;
605 }
606 on = !!channel;
607
608 if (on) {
609 rc = wmi_set_channel(wil, (int)channel);
610 if (rc)
611 return rc;
612 }
613
614 rc = wmi_rxon(wil, on);
615 if (rc)
616 return rc;
617
618 return len;
619}
620
621static const struct file_operations fops_rxon = {
622 .write = wil_write_file_rxon,
623 .open = simple_open,
624};
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300625
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +0200626/* block ack control, write:
627 * - "add <ringid> <agg_size> <timeout>" to trigger ADDBA
628 * - "del_tx <ringid> <reason>" to trigger DELBA for Tx side
629 * - "del_rx <CID> <TID> <reason>" to trigger DELBA for Rx side
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200630 */
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +0200631static ssize_t wil_write_back(struct file *file, const char __user *buf,
632 size_t len, loff_t *ppos)
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200633{
634 struct wil6210_priv *wil = file->private_data;
635 int rc;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200636 char *kbuf = kmalloc(len + 1, GFP_KERNEL);
Colin Ian King2a19f772015-03-01 17:48:33 +0000637 char cmd[9];
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +0200638 int p1, p2, p3;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200639
640 if (!kbuf)
641 return -ENOMEM;
642
643 rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
644 if (rc != len) {
645 kfree(kbuf);
646 return rc >= 0 ? -EIO : rc;
647 }
648
649 kbuf[len] = '\0';
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +0200650 rc = sscanf(kbuf, "%8s %d %d %d", cmd, &p1, &p2, &p3);
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200651 kfree(kbuf);
652
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +0200653 if (rc < 0)
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200654 return rc;
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +0200655 if (rc < 2)
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200656 return -EINVAL;
657
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +0200658 if (0 == strcmp(cmd, "add")) {
659 if (rc < 3) {
660 wil_err(wil, "BACK: add require at least 2 params\n");
661 return -EINVAL;
662 }
663 if (rc < 4)
664 p3 = 0;
665 wmi_addba(wil, p1, p2, p3);
666 } else if (0 == strcmp(cmd, "del_tx")) {
667 if (rc < 3)
668 p2 = WLAN_REASON_QSTA_LEAVE_QBSS;
669 wmi_delba_tx(wil, p1, p2);
670 } else if (0 == strcmp(cmd, "del_rx")) {
671 if (rc < 3) {
672 wil_err(wil,
673 "BACK: del_rx require at least 2 params\n");
674 return -EINVAL;
675 }
676 if (rc < 4)
677 p3 = WLAN_REASON_QSTA_LEAVE_QBSS;
678 wmi_delba_rx(wil, mk_cidxtid(p1, p2), p3);
679 } else {
680 wil_err(wil, "BACK: Unrecognized command \"%s\"\n", cmd);
681 return -EINVAL;
682 }
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200683
684 return len;
685}
686
Vladimir Kondratiev49cb5df2014-12-23 09:47:16 +0200687static ssize_t wil_read_back(struct file *file, char __user *user_buf,
688 size_t count, loff_t *ppos)
689{
690 static const char text[] = "block ack control, write:\n"
691 " - \"add <ringid> <agg_size> <timeout>\" to trigger ADDBA\n"
692 "If missing, <timeout> defaults to 0\n"
693 " - \"del_tx <ringid> <reason>\" to trigger DELBA for Tx side\n"
694 " - \"del_rx <CID> <TID> <reason>\" to trigger DELBA for Rx side\n"
695 "If missing, <reason> set to \"STA_LEAVING\" (36)\n";
696
697 return simple_read_from_buffer(user_buf, count, ppos, text,
698 sizeof(text));
699}
700
701static const struct file_operations fops_back = {
702 .read = wil_read_back,
703 .write = wil_write_back,
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200704 .open = simple_open,
705};
706
Vladimir Kondratievdc164272015-04-30 16:25:09 +0300707/* pmc control, write:
708 * - "alloc <num descriptors> <descriptor_size>" to allocate PMC
709 * - "free" to release memory allocated for PMC
710 */
711static ssize_t wil_write_pmccfg(struct file *file, const char __user *buf,
712 size_t len, loff_t *ppos)
713{
714 struct wil6210_priv *wil = file->private_data;
715 int rc;
716 char *kbuf = kmalloc(len + 1, GFP_KERNEL);
717 char cmd[9];
718 int num_descs, desc_size;
719
720 if (!kbuf)
721 return -ENOMEM;
722
723 rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
724 if (rc != len) {
725 kfree(kbuf);
726 return rc >= 0 ? -EIO : rc;
727 }
728
729 kbuf[len] = '\0';
730 rc = sscanf(kbuf, "%8s %d %d", cmd, &num_descs, &desc_size);
731 kfree(kbuf);
732
733 if (rc < 0)
734 return rc;
735
736 if (rc < 1) {
737 wil_err(wil, "pmccfg: no params given\n");
738 return -EINVAL;
739 }
740
741 if (0 == strcmp(cmd, "alloc")) {
742 if (rc != 3) {
743 wil_err(wil, "pmccfg: alloc requires 2 params\n");
744 return -EINVAL;
745 }
746 wil_pmc_alloc(wil, num_descs, desc_size);
747 } else if (0 == strcmp(cmd, "free")) {
748 if (rc != 1) {
749 wil_err(wil, "pmccfg: free does not have any params\n");
750 return -EINVAL;
751 }
752 wil_pmc_free(wil, true);
753 } else {
754 wil_err(wil, "pmccfg: Unrecognized command \"%s\"\n", cmd);
755 return -EINVAL;
756 }
757
758 return len;
759}
760
761static ssize_t wil_read_pmccfg(struct file *file, char __user *user_buf,
762 size_t count, loff_t *ppos)
763{
764 struct wil6210_priv *wil = file->private_data;
765 char text[256];
766 char help[] = "pmc control, write:\n"
767 " - \"alloc <num descriptors> <descriptor_size>\" to allocate pmc\n"
768 " - \"free\" to free memory allocated for pmc\n";
769
770 sprintf(text, "Last command status: %d\n\n%s",
771 wil_pmc_last_cmd_status(wil),
772 help);
773
774 return simple_read_from_buffer(user_buf, count, ppos, text,
775 strlen(text) + 1);
776}
777
778static const struct file_operations fops_pmccfg = {
779 .read = wil_read_pmccfg,
780 .write = wil_write_pmccfg,
781 .open = simple_open,
782};
783
784static const struct file_operations fops_pmcdata = {
785 .open = simple_open,
786 .read = wil_pmc_read,
787 .llseek = wil_pmc_llseek,
788};
789
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300790/*---tx_mgmt---*/
791/* Write mgmt frame to this file to send it */
792static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
793 size_t len, loff_t *ppos)
794{
795 struct wil6210_priv *wil = file->private_data;
796 struct wiphy *wiphy = wil_to_wiphy(wil);
797 struct wireless_dev *wdev = wil_to_wdev(wil);
798 struct cfg80211_mgmt_tx_params params;
799 int rc;
Hamad Kadmany7194ff32017-08-09 09:04:56 +0300800 void *frame;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300801
Hamad Kadmany7194ff32017-08-09 09:04:56 +0300802 if (!len)
803 return -EINVAL;
804
805 frame = kmalloc(len, GFP_KERNEL);
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300806 if (!frame)
807 return -ENOMEM;
808
Lino Sanfilippo8e09b7d2014-11-28 02:47:19 +0100809 if (copy_from_user(frame, buf, len)) {
810 kfree(frame);
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300811 return -EIO;
Lino Sanfilippo8e09b7d2014-11-28 02:47:19 +0100812 }
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300813
814 params.buf = frame;
815 params.len = len;
816 params.chan = wdev->preset_chandef.chan;
817
818 rc = wil_cfg80211_mgmt_tx(wiphy, wdev, &params, NULL);
819
820 kfree(frame);
Lazar Alexei3190cc62017-02-23 14:34:14 +0200821 wil_info(wil, "-> %d\n", rc);
Vladimir Kondratiev0b39aaf2014-06-16 19:36:59 +0300822
823 return len;
824}
825
826static const struct file_operations fops_txmgmt = {
827 .write = wil_write_file_txmgmt,
828 .open = simple_open,
829};
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800830
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300831/* Write WMI command (w/o mbox header) to this file to send it
832 * WMI starts from wil6210_mbox_hdr_wmi header
833 */
834static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
835 size_t len, loff_t *ppos)
836{
837 struct wil6210_priv *wil = file->private_data;
Lior Davidb874dde2016-03-01 19:18:09 +0200838 struct wmi_cmd_hdr *wmi;
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300839 void *cmd;
Lior Davidb874dde2016-03-01 19:18:09 +0200840 int cmdlen = len - sizeof(struct wmi_cmd_hdr);
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300841 u16 cmdid;
842 int rc, rc1;
843
Lior David69218a42016-03-21 22:01:11 +0200844 if (cmdlen < 0)
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300845 return -EINVAL;
846
847 wmi = kmalloc(len, GFP_KERNEL);
848 if (!wmi)
849 return -ENOMEM;
850
851 rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
Lino Sanfilippo8e09b7d2014-11-28 02:47:19 +0100852 if (rc < 0) {
853 kfree(wmi);
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300854 return rc;
Lino Sanfilippo8e09b7d2014-11-28 02:47:19 +0100855 }
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300856
Lior David69218a42016-03-21 22:01:11 +0200857 cmd = (cmdlen > 0) ? &wmi[1] : NULL;
Lior Davidb874dde2016-03-01 19:18:09 +0200858 cmdid = le16_to_cpu(wmi->command_id);
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300859
860 rc1 = wmi_send(wil, cmdid, cmd, cmdlen);
861 kfree(wmi);
862
Lazar Alexei3190cc62017-02-23 14:34:14 +0200863 wil_info(wil, "0x%04x[%d] -> %d\n", cmdid, cmdlen, rc1);
Vladimir Kondratievff974e42014-06-16 19:37:08 +0300864
865 return rc;
866}
867
868static const struct file_operations fops_wmi = {
869 .write = wil_write_file_wmi,
870 .open = simple_open,
871};
872
Vladimir Kondratievc2366582014-03-17 15:34:08 +0200873static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
874{
875 int i = 0;
876 int len = skb_headlen(skb);
877 void *p = skb->data;
878 int nr_frags = skb_shinfo(skb)->nr_frags;
879
880 seq_printf(s, " len = %d\n", len);
881 wil_seq_hexdump(s, p, len, " : ");
882
883 if (nr_frags) {
884 seq_printf(s, " nr_frags = %d\n", nr_frags);
885 for (i = 0; i < nr_frags; i++) {
886 const struct skb_frag_struct *frag =
887 &skb_shinfo(skb)->frags[i];
888
889 len = skb_frag_size(frag);
890 p = skb_frag_address_safe(frag);
891 seq_printf(s, " [%2d] : len = %d\n", i, len);
892 wil_seq_hexdump(s, p, len, " : ");
893 }
894 }
895}
896
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200897/*---------Tx/Rx descriptor------------*/
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800898static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
899{
900 struct wil6210_priv *wil = s->private;
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200901 struct vring *vring;
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +0200902 bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300903
904 vring = tx ? &wil->vring_tx[dbg_vring_index] : &wil->vring_rx;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800905
906 if (!vring->va) {
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +0200907 if (tx)
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200908 seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index);
909 else
910 seq_puts(s, "No Rx VRING\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800911 return 0;
912 }
913
914 if (dbg_txdesc_index < vring->size) {
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200915 /* use struct vring_tx_desc for Rx as well,
916 * only field used, .dma.length, is the same
917 */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800918 volatile struct vring_tx_desc *d =
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300919 &vring->va[dbg_txdesc_index].tx;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800920 volatile u32 *u = (volatile u32 *)d;
Vladimir Kondratievf88f1132013-07-11 18:03:40 +0300921 struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800922
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +0200923 if (tx)
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200924 seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index,
925 dbg_txdesc_index);
926 else
927 seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800928 seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
929 u[0], u[1], u[2], u[3]);
930 seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
931 u[4], u[5], u[6], u[7]);
Vladimir Kondratiev39c52ee2014-05-27 14:45:49 +0300932 seq_printf(s, " SKB = 0x%p\n", skb);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800933
934 if (skb) {
Vladimir Kondratievc2366582014-03-17 15:34:08 +0200935 skb_get(skb);
936 wil_seq_print_skb(s, skb);
937 kfree_skb(skb);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800938 }
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300939 seq_puts(s, "}\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800940 } else {
Vladimir Kondratievaf31cb52014-03-02 11:20:50 +0200941 if (tx)
Vladimir Kondratiev3a855432014-02-27 16:20:41 +0200942 seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
943 dbg_vring_index, dbg_txdesc_index,
944 vring->size);
945 else
946 seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
947 dbg_txdesc_index, vring->size);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800948 }
949
950 return 0;
951}
952
953static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
954{
955 return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
956}
957
958static const struct file_operations fops_txdesc = {
959 .open = wil_txdesc_seq_open,
960 .release = single_release,
961 .read = seq_read,
962 .llseek = seq_lseek,
963};
964
965/*---------beamforming------------*/
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +0300966static char *wil_bfstatus_str(u32 status)
967{
968 switch (status) {
969 case 0:
970 return "Failed";
971 case 1:
972 return "OK";
973 case 2:
974 return "Retrying";
975 default:
976 return "??";
977 }
978}
979
980static bool is_all_zeros(void * const x_, size_t sz)
981{
982 /* if reply is all-0, ignore this CID */
983 u32 *x = x_;
984 int n;
985
986 for (n = 0; n < sz / sizeof(*x); n++)
987 if (x[n])
988 return false;
989
990 return true;
991}
992
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800993static int wil_bf_debugfs_show(struct seq_file *s, void *data)
994{
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +0300995 int rc;
996 int i;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800997 struct wil6210_priv *wil = s->private;
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +0300998 struct wmi_notify_req_cmd cmd = {
999 .interval_usec = 0,
1000 };
1001 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001002 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +03001003 struct wmi_notify_req_done_event evt;
1004 } __packed reply;
1005
1006 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1007 u32 status;
1008
1009 cmd.cid = i;
1010 rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd),
1011 WMI_NOTIFY_REQ_DONE_EVENTID, &reply,
1012 sizeof(reply), 20);
1013 /* if reply is all-0, ignore this CID */
1014 if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt)))
1015 continue;
1016
1017 status = le32_to_cpu(reply.evt.status);
1018 seq_printf(s, "CID %d {\n"
1019 " TSF = 0x%016llx\n"
1020 " TxMCS = %2d TxTpt = %4d\n"
1021 " SQI = %4d\n"
Dedy Lanskyb3f87382017-08-21 22:58:54 +03001022 " RSSI = %4d\n"
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +03001023 " Status = 0x%08x %s\n"
1024 " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
1025 " Goodput(rx:tx) %4d:%4d\n"
1026 "}\n",
1027 i,
1028 le64_to_cpu(reply.evt.tsf),
1029 le16_to_cpu(reply.evt.bf_mcs),
1030 le32_to_cpu(reply.evt.tx_tpt),
1031 reply.evt.sqi,
Dedy Lanskyb3f87382017-08-21 22:58:54 +03001032 reply.evt.rssi,
Vladimir Kondratiev36345ac2014-08-06 10:31:56 +03001033 status, wil_bfstatus_str(status),
1034 le16_to_cpu(reply.evt.my_rx_sector),
1035 le16_to_cpu(reply.evt.my_tx_sector),
1036 le16_to_cpu(reply.evt.other_rx_sector),
1037 le16_to_cpu(reply.evt.other_tx_sector),
1038 le32_to_cpu(reply.evt.rx_goodput),
1039 le32_to_cpu(reply.evt.tx_goodput));
1040 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001041 return 0;
1042}
1043
1044static int wil_bf_seq_open(struct inode *inode, struct file *file)
1045{
1046 return single_open(file, wil_bf_debugfs_show, inode->i_private);
1047}
1048
1049static const struct file_operations fops_bf = {
1050 .open = wil_bf_seq_open,
1051 .release = single_release,
1052 .read = seq_read,
1053 .llseek = seq_lseek,
1054};
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001055
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001056/*---------SSID------------*/
1057static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf,
1058 size_t count, loff_t *ppos)
1059{
1060 struct wil6210_priv *wil = file->private_data;
1061 struct wireless_dev *wdev = wil_to_wdev(wil);
1062
1063 return simple_read_from_buffer(user_buf, count, ppos,
1064 wdev->ssid, wdev->ssid_len);
1065}
1066
1067static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf,
1068 size_t count, loff_t *ppos)
1069{
1070 struct wil6210_priv *wil = file->private_data;
1071 struct wireless_dev *wdev = wil_to_wdev(wil);
1072 struct net_device *ndev = wil_to_ndev(wil);
1073
1074 if (*ppos != 0) {
1075 wil_err(wil, "Unable to set SSID substring from [%d]\n",
1076 (int)*ppos);
1077 return -EINVAL;
1078 }
1079
1080 if (count > sizeof(wdev->ssid)) {
1081 wil_err(wil, "SSID too long, len = %d\n", (int)count);
1082 return -EINVAL;
1083 }
1084 if (netif_running(ndev)) {
1085 wil_err(wil, "Unable to change SSID on running interface\n");
1086 return -EINVAL;
1087 }
1088
1089 wdev->ssid_len = count;
1090 return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos,
1091 buf, count);
1092}
1093
1094static const struct file_operations fops_ssid = {
1095 .read = wil_read_file_ssid,
1096 .write = wil_write_file_ssid,
Wei Yongjun93ecbd62013-02-26 10:29:34 +08001097 .open = simple_open,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001098};
1099
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001100/*---------temp------------*/
1101static void print_temp(struct seq_file *s, const char *prefix, u32 t)
1102{
1103 switch (t) {
1104 case 0:
1105 case ~(u32)0:
1106 seq_printf(s, "%s N/A\n", prefix);
1107 break;
1108 default:
1109 seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
1110 break;
1111 }
1112}
1113
1114static int wil_temp_debugfs_show(struct seq_file *s, void *data)
1115{
1116 struct wil6210_priv *wil = s->private;
1117 u32 t_m, t_r;
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001118 int rc = wmi_get_temperature(wil, &t_m, &t_r);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001119
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001120 if (rc) {
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001121 seq_puts(s, "Failed\n");
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001122 return 0;
1123 }
1124
Vladimir Kondratievd45cff92014-06-16 19:37:12 +03001125 print_temp(s, "T_mac =", t_m);
1126 print_temp(s, "T_radio =", t_r);
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001127
1128 return 0;
1129}
1130
1131static int wil_temp_seq_open(struct inode *inode, struct file *file)
1132{
1133 return single_open(file, wil_temp_debugfs_show, inode->i_private);
1134}
1135
1136static const struct file_operations fops_temp = {
1137 .open = wil_temp_seq_open,
1138 .release = single_release,
1139 .read = seq_read,
1140 .llseek = seq_lseek,
1141};
1142
Vladimir Kondratiev9eb82d42014-06-16 19:37:13 +03001143/*---------freq------------*/
1144static int wil_freq_debugfs_show(struct seq_file *s, void *data)
1145{
1146 struct wil6210_priv *wil = s->private;
1147 struct wireless_dev *wdev = wil_to_wdev(wil);
1148 u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
1149
1150 seq_printf(s, "Freq = %d\n", freq);
1151
1152 return 0;
1153}
1154
1155static int wil_freq_seq_open(struct inode *inode, struct file *file)
1156{
1157 return single_open(file, wil_freq_debugfs_show, inode->i_private);
1158}
1159
1160static const struct file_operations fops_freq = {
1161 .open = wil_freq_seq_open,
1162 .release = single_release,
1163 .read = seq_read,
1164 .llseek = seq_lseek,
1165};
1166
1167/*---------link------------*/
1168static int wil_link_debugfs_show(struct seq_file *s, void *data)
1169{
1170 struct wil6210_priv *wil = s->private;
1171 struct station_info sinfo;
1172 int i, rc;
1173
1174 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1175 struct wil_sta_info *p = &wil->sta[i];
1176 char *status = "unknown";
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001177
Vladimir Kondratiev9eb82d42014-06-16 19:37:13 +03001178 switch (p->status) {
1179 case wil_sta_unused:
1180 status = "unused ";
1181 break;
1182 case wil_sta_conn_pending:
1183 status = "pending ";
1184 break;
1185 case wil_sta_connected:
1186 status = "connected";
1187 break;
1188 }
Vladimir Kondratiev230d8442015-04-30 16:25:10 +03001189 seq_printf(s, "[%d] %pM %s\n", i, p->addr, status);
Vladimir Kondratiev9eb82d42014-06-16 19:37:13 +03001190
1191 if (p->status == wil_sta_connected) {
1192 rc = wil_cid_fill_sinfo(wil, i, &sinfo);
1193 if (rc)
1194 return rc;
1195
1196 seq_printf(s, " Tx_mcs = %d\n", sinfo.txrate.mcs);
1197 seq_printf(s, " Rx_mcs = %d\n", sinfo.rxrate.mcs);
1198 seq_printf(s, " SQ = %d\n", sinfo.signal);
1199 }
1200 }
1201
1202 return 0;
1203}
1204
1205static int wil_link_seq_open(struct inode *inode, struct file *file)
1206{
1207 return single_open(file, wil_link_debugfs_show, inode->i_private);
1208}
1209
1210static const struct file_operations fops_link = {
1211 .open = wil_link_seq_open,
1212 .release = single_release,
1213 .read = seq_read,
1214 .llseek = seq_lseek,
1215};
1216
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +03001217/*---------info------------*/
1218static int wil_info_debugfs_show(struct seq_file *s, void *data)
1219{
Vladimir Kondratievbe299852014-06-16 19:37:22 +03001220 struct wil6210_priv *wil = s->private;
1221 struct net_device *ndev = wil_to_ndev(wil);
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +03001222 int is_ac = power_supply_is_system_supplied();
Vladimir Kondratievbe299852014-06-16 19:37:22 +03001223 int rx = atomic_xchg(&wil->isr_count_rx, 0);
1224 int tx = atomic_xchg(&wil->isr_count_tx, 0);
1225 static ulong rxf_old, txf_old;
1226 ulong rxf = ndev->stats.rx_packets;
1227 ulong txf = ndev->stats.tx_packets;
Vladimir Kondratiev55f8f682014-06-16 19:37:23 +03001228 unsigned int i;
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +03001229
1230 /* >0 : AC; 0 : battery; <0 : error */
1231 seq_printf(s, "AC powered : %d\n", is_ac);
Vladimir Kondratievbe299852014-06-16 19:37:22 +03001232 seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
1233 seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
1234 rxf_old = rxf;
1235 txf_old = txf;
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +03001236
Vladimir Kondratiev55f8f682014-06-16 19:37:23 +03001237#define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
1238 " " __stringify(x) : ""
1239
1240 for (i = 0; i < ndev->num_tx_queues; i++) {
1241 struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
1242 unsigned long state = txq->state;
1243
1244 seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
1245 CHECK_QSTATE(DRV_XOFF),
1246 CHECK_QSTATE(STACK_XOFF),
1247 CHECK_QSTATE(FROZEN)
1248 );
1249 }
1250#undef CHECK_QSTATE
Vladimir Kondratiev84bb29b2014-06-16 19:37:21 +03001251 return 0;
1252}
1253
1254static int wil_info_seq_open(struct inode *inode, struct file *file)
1255{
1256 return single_open(file, wil_info_debugfs_show, inode->i_private);
1257}
1258
1259static const struct file_operations fops_info = {
1260 .open = wil_info_seq_open,
1261 .release = single_release,
1262 .read = seq_read,
1263 .llseek = seq_lseek,
1264};
1265
Vladimir Kondratievc33407a2014-10-01 15:05:24 +03001266/*---------recovery------------*/
1267/* mode = [manual|auto]
1268 * state = [idle|pending|running]
1269 */
1270static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf,
1271 size_t count, loff_t *ppos)
1272{
1273 struct wil6210_priv *wil = file->private_data;
1274 char buf[80];
1275 int n;
1276 static const char * const sstate[] = {"idle", "pending", "running"};
1277
1278 n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n",
1279 no_fw_recovery ? "manual" : "auto",
1280 sstate[wil->recovery_state]);
1281
1282 n = min_t(int, n, sizeof(buf));
1283
1284 return simple_read_from_buffer(user_buf, count, ppos,
1285 buf, n);
1286}
1287
1288static ssize_t wil_write_file_recovery(struct file *file,
1289 const char __user *buf_,
1290 size_t count, loff_t *ppos)
1291{
1292 struct wil6210_priv *wil = file->private_data;
1293 static const char run_command[] = "run";
1294 char buf[sizeof(run_command) + 1]; /* to detect "runx" */
1295 ssize_t rc;
1296
1297 if (wil->recovery_state != fw_recovery_pending) {
1298 wil_err(wil, "No recovery pending\n");
1299 return -EINVAL;
1300 }
1301
1302 if (*ppos != 0) {
1303 wil_err(wil, "Offset [%d]\n", (int)*ppos);
1304 return -EINVAL;
1305 }
1306
1307 if (count > sizeof(buf)) {
1308 wil_err(wil, "Input too long, len = %d\n", (int)count);
1309 return -EINVAL;
1310 }
1311
1312 rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count);
1313 if (rc < 0)
1314 return rc;
1315
1316 buf[rc] = '\0';
1317 if (0 == strcmp(buf, run_command))
1318 wil_set_recovery_state(wil, fw_recovery_running);
1319 else
1320 wil_err(wil, "Bad recovery command \"%s\"\n", buf);
1321
1322 return rc;
1323}
1324
1325static const struct file_operations fops_recovery = {
1326 .read = wil_read_file_recovery,
1327 .write = wil_write_file_recovery,
1328 .open = simple_open,
1329};
1330
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001331/*---------Station matrix------------*/
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001332static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
1333{
1334 int i;
1335 u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
Vladimir Kondratiev91a8edc2015-07-30 13:52:01 +03001336 unsigned long long drop_dup = r->drop_dup, drop_old = r->drop_old;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001337
Vladimir Kondratiev56637e72014-12-23 09:47:06 +02001338 seq_printf(s, "([%2d] %3d TU) 0x%03x [", r->buf_size, r->timeout,
1339 r->head_seq_num);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001340 for (i = 0; i < r->buf_size; i++) {
1341 if (i == index)
1342 seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
1343 else
1344 seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
1345 }
Vladimir Kondratiev91a8edc2015-07-30 13:52:01 +03001346 seq_printf(s,
1347 "] total %llu drop %llu (dup %llu + old %llu) last 0x%03x\n",
1348 r->total, drop_dup + drop_old, drop_dup, drop_old,
1349 r->ssn_last_drop);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001350}
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001351
Vladimir Kondratiev58527422016-03-01 19:18:07 +02001352static void wil_print_rxtid_crypto(struct seq_file *s, int tid,
1353 struct wil_tid_crypto_rx *c)
1354{
1355 int i;
1356
1357 for (i = 0; i < 4; i++) {
1358 struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
1359
1360 if (cc->key_set)
1361 goto has_keys;
1362 }
1363 return;
1364
1365has_keys:
1366 if (tid < WIL_STA_TID_NUM)
1367 seq_printf(s, " [%2d] PN", tid);
1368 else
1369 seq_puts(s, " [GR] PN");
1370
1371 for (i = 0; i < 4; i++) {
1372 struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
1373
1374 seq_printf(s, " [%i%s]%6phN", i, cc->key_set ? "+" : "-",
1375 cc->pn);
1376 }
1377 seq_puts(s, "\n");
1378}
1379
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001380static int wil_sta_debugfs_show(struct seq_file *s, void *data)
Vladimir Kondratievbd332732014-12-23 09:47:24 +02001381__acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001382{
1383 struct wil6210_priv *wil = s->private;
Vladimir Kondratievc4a110d2015-06-09 14:11:18 +03001384 int i, tid, mcs;
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001385
1386 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1387 struct wil_sta_info *p = &wil->sta[i];
1388 char *status = "unknown";
Lior Davida7629792017-02-08 13:16:37 +02001389 u8 aid = 0;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001390
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001391 switch (p->status) {
1392 case wil_sta_unused:
1393 status = "unused ";
1394 break;
1395 case wil_sta_conn_pending:
1396 status = "pending ";
1397 break;
1398 case wil_sta_connected:
1399 status = "connected";
Lior Davida7629792017-02-08 13:16:37 +02001400 aid = p->aid;
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001401 break;
1402 }
Lior Davida7629792017-02-08 13:16:37 +02001403 seq_printf(s, "[%d] %pM %s AID %d\n", i, p->addr, status, aid);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001404
1405 if (p->status == wil_sta_connected) {
Vladimir Kondratievbd332732014-12-23 09:47:24 +02001406 spin_lock_bh(&p->tid_rx_lock);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001407 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1408 struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
Vladimir Kondratiev58527422016-03-01 19:18:07 +02001409 struct wil_tid_crypto_rx *c =
1410 &p->tid_crypto_rx[tid];
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001411
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001412 if (r) {
Vladimir Kondratiev58527422016-03-01 19:18:07 +02001413 seq_printf(s, " [%2d] ", tid);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001414 wil_print_rxtid(s, r);
1415 }
Vladimir Kondratiev58527422016-03-01 19:18:07 +02001416
1417 wil_print_rxtid_crypto(s, tid, c);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001418 }
Vladimir Kondratiev58527422016-03-01 19:18:07 +02001419 wil_print_rxtid_crypto(s, WIL_STA_TID_NUM,
1420 &p->group_crypto_rx);
Vladimir Kondratievbd332732014-12-23 09:47:24 +02001421 spin_unlock_bh(&p->tid_rx_lock);
Vladimir Kondratiev3b282bc2015-10-04 10:23:19 +03001422 seq_printf(s,
Vladimir Kondratiev58527422016-03-01 19:18:07 +02001423 "Rx invalid frame: non-data %lu, short %lu, large %lu, replay %lu\n",
Vladimir Kondratiev3b282bc2015-10-04 10:23:19 +03001424 p->stats.rx_non_data_frame,
1425 p->stats.rx_short_frame,
Vladimir Kondratiev58527422016-03-01 19:18:07 +02001426 p->stats.rx_large_frame,
1427 p->stats.rx_replay);
Vladimir Kondratiev3b282bc2015-10-04 10:23:19 +03001428
Vladimir Kondratievc4a110d2015-06-09 14:11:18 +03001429 seq_puts(s, "Rx/MCS:");
1430 for (mcs = 0; mcs < ARRAY_SIZE(p->stats.rx_per_mcs);
1431 mcs++)
1432 seq_printf(s, " %lld",
1433 p->stats.rx_per_mcs[mcs]);
1434 seq_puts(s, "\n");
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001435 }
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001436 }
1437
1438 return 0;
1439}
1440
1441static int wil_sta_seq_open(struct inode *inode, struct file *file)
1442{
1443 return single_open(file, wil_sta_debugfs_show, inode->i_private);
1444}
1445
1446static const struct file_operations fops_sta = {
1447 .open = wil_sta_seq_open,
1448 .release = single_release,
1449 .read = seq_read,
1450 .llseek = seq_lseek,
1451};
1452
Maya Erez10d599a2016-05-09 21:57:11 +03001453static ssize_t wil_read_file_led_cfg(struct file *file, char __user *user_buf,
1454 size_t count, loff_t *ppos)
1455{
1456 char buf[80];
1457 int n;
1458
1459 n = snprintf(buf, sizeof(buf),
1460 "led_id is set to %d, echo 1 to enable, 0 to disable\n",
1461 led_id);
1462
1463 n = min_t(int, n, sizeof(buf));
1464
1465 return simple_read_from_buffer(user_buf, count, ppos,
1466 buf, n);
1467}
1468
1469static ssize_t wil_write_file_led_cfg(struct file *file,
1470 const char __user *buf_,
1471 size_t count, loff_t *ppos)
1472{
1473 struct wil6210_priv *wil = file->private_data;
1474 int val;
1475 int rc;
1476
1477 rc = kstrtoint_from_user(buf_, count, 0, &val);
1478 if (rc) {
1479 wil_err(wil, "Invalid argument\n");
1480 return rc;
1481 }
1482
1483 wil_info(wil, "%s led %d\n", val ? "Enabling" : "Disabling", led_id);
1484 rc = wmi_led_cfg(wil, val);
1485 if (rc) {
1486 wil_info(wil, "%s led %d failed\n",
1487 val ? "Enabling" : "Disabling", led_id);
1488 return rc;
1489 }
1490
1491 return count;
1492}
1493
1494static const struct file_operations fops_led_cfg = {
1495 .read = wil_read_file_led_cfg,
1496 .write = wil_write_file_led_cfg,
1497 .open = simple_open,
1498};
1499
1500/* led_blink_time, write:
1501 * "<blink_on_slow> <blink_off_slow> <blink_on_med> <blink_off_med> <blink_on_fast> <blink_off_fast>
1502 */
1503static ssize_t wil_write_led_blink_time(struct file *file,
1504 const char __user *buf,
1505 size_t len, loff_t *ppos)
1506{
1507 int rc;
1508 char *kbuf = kmalloc(len + 1, GFP_KERNEL);
1509
1510 if (!kbuf)
1511 return -ENOMEM;
1512
1513 rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
1514 if (rc != len) {
1515 kfree(kbuf);
1516 return rc >= 0 ? -EIO : rc;
1517 }
1518
1519 kbuf[len] = '\0';
1520 rc = sscanf(kbuf, "%d %d %d %d %d %d",
1521 &led_blink_time[WIL_LED_TIME_SLOW].on_ms,
1522 &led_blink_time[WIL_LED_TIME_SLOW].off_ms,
1523 &led_blink_time[WIL_LED_TIME_MED].on_ms,
1524 &led_blink_time[WIL_LED_TIME_MED].off_ms,
1525 &led_blink_time[WIL_LED_TIME_FAST].on_ms,
1526 &led_blink_time[WIL_LED_TIME_FAST].off_ms);
1527 kfree(kbuf);
1528
1529 if (rc < 0)
1530 return rc;
1531 if (rc < 6)
1532 return -EINVAL;
1533
1534 return len;
1535}
1536
1537static ssize_t wil_read_led_blink_time(struct file *file, char __user *user_buf,
1538 size_t count, loff_t *ppos)
1539{
1540 static char text[400];
1541
1542 snprintf(text, sizeof(text),
1543 "To set led blink on/off time variables write:\n"
1544 "<blink_on_slow> <blink_off_slow> <blink_on_med> "
1545 "<blink_off_med> <blink_on_fast> <blink_off_fast>\n"
1546 "The current values are:\n"
1547 "%d %d %d %d %d %d\n",
1548 led_blink_time[WIL_LED_TIME_SLOW].on_ms,
1549 led_blink_time[WIL_LED_TIME_SLOW].off_ms,
1550 led_blink_time[WIL_LED_TIME_MED].on_ms,
1551 led_blink_time[WIL_LED_TIME_MED].off_ms,
1552 led_blink_time[WIL_LED_TIME_FAST].on_ms,
1553 led_blink_time[WIL_LED_TIME_FAST].off_ms);
1554
1555 return simple_read_from_buffer(user_buf, count, ppos, text,
1556 sizeof(text));
1557}
1558
1559static const struct file_operations fops_led_blink_time = {
1560 .read = wil_read_led_blink_time,
1561 .write = wil_write_led_blink_time,
1562 .open = simple_open,
1563};
1564
Lior David12bace72016-08-22 12:42:21 +03001565/*---------FW capabilities------------*/
1566static int wil_fw_capabilities_debugfs_show(struct seq_file *s, void *data)
1567{
1568 struct wil6210_priv *wil = s->private;
1569
1570 seq_printf(s, "fw_capabilities : %*pb\n", WMI_FW_CAPABILITY_MAX,
1571 wil->fw_capabilities);
1572
1573 return 0;
1574}
1575
1576static int wil_fw_capabilities_seq_open(struct inode *inode, struct file *file)
1577{
1578 return single_open(file, wil_fw_capabilities_debugfs_show,
1579 inode->i_private);
1580}
1581
1582static const struct file_operations fops_fw_capabilities = {
1583 .open = wil_fw_capabilities_seq_open,
1584 .release = single_release,
1585 .read = seq_read,
1586 .llseek = seq_lseek,
1587};
1588
Lior David13cd9f72016-08-22 12:42:22 +03001589/*---------FW version------------*/
1590static int wil_fw_version_debugfs_show(struct seq_file *s, void *data)
1591{
1592 struct wil6210_priv *wil = s->private;
1593
1594 if (wil->fw_version[0])
1595 seq_printf(s, "%s\n", wil->fw_version);
1596 else
1597 seq_puts(s, "N/A\n");
1598
1599 return 0;
1600}
1601
1602static int wil_fw_version_seq_open(struct inode *inode, struct file *file)
1603{
1604 return single_open(file, wil_fw_version_debugfs_show,
1605 inode->i_private);
1606}
1607
1608static const struct file_operations fops_fw_version = {
1609 .open = wil_fw_version_seq_open,
1610 .release = single_release,
1611 .read = seq_read,
1612 .llseek = seq_lseek,
1613};
1614
Maya Ereze3309bf2017-05-15 16:57:46 +03001615/*---------suspend_stats---------*/
1616static ssize_t wil_write_suspend_stats(struct file *file,
1617 const char __user *buf,
1618 size_t len, loff_t *ppos)
1619{
1620 struct wil6210_priv *wil = file->private_data;
1621
1622 memset(&wil->suspend_stats, 0, sizeof(wil->suspend_stats));
Maya Erez2f9f6422017-08-21 22:43:32 +03001623 wil->suspend_stats.min_suspend_time = ULONG_MAX;
1624 wil->suspend_stats.collection_start = ktime_get();
Maya Ereze3309bf2017-05-15 16:57:46 +03001625
1626 return len;
1627}
1628
1629static ssize_t wil_read_suspend_stats(struct file *file,
1630 char __user *user_buf,
1631 size_t count, loff_t *ppos)
1632{
1633 struct wil6210_priv *wil = file->private_data;
1634 static char text[400];
1635 int n;
Maya Erez2f9f6422017-08-21 22:43:32 +03001636 unsigned long long stats_collection_time =
1637 ktime_to_us(ktime_sub(ktime_get(),
1638 wil->suspend_stats.collection_start));
Maya Ereze3309bf2017-05-15 16:57:46 +03001639
1640 n = snprintf(text, sizeof(text),
1641 "Suspend statistics:\n"
1642 "successful suspends:%ld failed suspends:%ld\n"
1643 "successful resumes:%ld failed resumes:%ld\n"
Maya Erez2f9f6422017-08-21 22:43:32 +03001644 "rejected by host:%ld rejected by device:%ld\n"
1645 "total suspend time:%lld min suspend time:%lld\n"
1646 "max suspend time:%lld stats collection time: %lld\n",
Maya Ereze3309bf2017-05-15 16:57:46 +03001647 wil->suspend_stats.successful_suspends,
1648 wil->suspend_stats.failed_suspends,
1649 wil->suspend_stats.successful_resumes,
1650 wil->suspend_stats.failed_resumes,
1651 wil->suspend_stats.rejected_by_host,
Maya Erez2f9f6422017-08-21 22:43:32 +03001652 wil->suspend_stats.rejected_by_device,
1653 wil->suspend_stats.total_suspend_time,
1654 wil->suspend_stats.min_suspend_time,
1655 wil->suspend_stats.max_suspend_time,
1656 stats_collection_time);
Maya Ereze3309bf2017-05-15 16:57:46 +03001657
1658 n = min_t(int, n, sizeof(text));
1659
1660 return simple_read_from_buffer(user_buf, count, ppos, text, n);
1661}
1662
1663static const struct file_operations fops_suspend_stats = {
1664 .read = wil_read_suspend_stats,
1665 .write = wil_write_suspend_stats,
1666 .open = simple_open,
1667};
1668
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001669/*----------------*/
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +03001670static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
1671 struct dentry *dbg)
1672{
1673 int i;
1674 char name[32];
1675
1676 for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
Maya Erez349214c2016-04-26 14:41:41 +03001677 struct wil_blob_wrapper *wil_blob = &wil->blobs[i];
1678 struct debugfs_blob_wrapper *blob = &wil_blob->blob;
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +03001679 const struct fw_map *map = &fw_mapping[i];
1680
1681 if (!map->name)
1682 continue;
1683
Maya Erez349214c2016-04-26 14:41:41 +03001684 wil_blob->wil = wil;
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +03001685 blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
1686 blob->size = map->to - map->from;
1687 snprintf(name, sizeof(name), "blob_%s", map->name);
Maya Erezc2256ec2017-02-08 13:18:42 +02001688 wil_debugfs_create_ioblob(name, 0444, dbg, wil_blob);
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +03001689 }
1690}
1691
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001692/* misc files */
1693static const struct {
1694 const char *name;
1695 umode_t mode;
1696 const struct file_operations *fops;
1697} dbg_files[] = {
Maya Erezc2256ec2017-02-08 13:18:42 +02001698 {"mbox", 0444, &fops_mbox},
1699 {"vrings", 0444, &fops_vring},
1700 {"stations", 0444, &fops_sta},
1701 {"desc", 0444, &fops_txdesc},
1702 {"bf", 0444, &fops_bf},
1703 {"ssid", 0644, &fops_ssid},
1704 {"mem_val", 0644, &fops_memread},
1705 {"reset", 0244, &fops_reset},
1706 {"rxon", 0244, &fops_rxon},
1707 {"tx_mgmt", 0244, &fops_txmgmt},
1708 {"wmi_send", 0244, &fops_wmi},
1709 {"back", 0644, &fops_back},
1710 {"pmccfg", 0644, &fops_pmccfg},
1711 {"pmcdata", 0444, &fops_pmcdata},
1712 {"temp", 0444, &fops_temp},
1713 {"freq", 0444, &fops_freq},
1714 {"link", 0444, &fops_link},
1715 {"info", 0444, &fops_info},
1716 {"recovery", 0644, &fops_recovery},
1717 {"led_cfg", 0644, &fops_led_cfg},
1718 {"led_blink_time", 0644, &fops_led_blink_time},
1719 {"fw_capabilities", 0444, &fops_fw_capabilities},
1720 {"fw_version", 0444, &fops_fw_version},
Maya Ereze3309bf2017-05-15 16:57:46 +03001721 {"suspend_stats", 0644, &fops_suspend_stats},
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001722};
1723
1724static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
1725 struct dentry *dbg)
1726{
1727 int i;
1728
1729 for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
1730 debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
1731 wil, dbg_files[i].fops);
1732}
1733
1734/* interrupt control blocks */
1735static const struct {
1736 const char *name;
1737 u32 icr_off;
1738} dbg_icr[] = {
1739 {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)},
1740 {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)},
1741 {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)},
1742 {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)},
1743};
1744
1745static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
1746 struct dentry *dbg)
1747{
1748 int i;
1749
1750 for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
1751 wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
1752 dbg_icr[i].icr_off);
1753}
1754
1755#define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
1756 offsetof(struct wil6210_priv, name), type}
1757
1758/* fields in struct wil6210_priv */
1759static const struct dbg_off dbg_wil_off[] = {
Maya Erezc2256ec2017-02-08 13:18:42 +02001760 WIL_FIELD(privacy, 0444, doff_u32),
1761 WIL_FIELD(status[0], 0644, doff_ulong),
1762 WIL_FIELD(hw_version, 0444, doff_x32),
1763 WIL_FIELD(recovery_count, 0444, doff_u32),
1764 WIL_FIELD(ap_isolate, 0444, doff_u32),
1765 WIL_FIELD(discovery_mode, 0644, doff_u8),
1766 WIL_FIELD(chip_revision, 0444, doff_u8),
1767 WIL_FIELD(abft_len, 0644, doff_u8),
Maya Ereze3309bf2017-05-15 16:57:46 +03001768 WIL_FIELD(wakeup_trigger, 0644, doff_u8),
Gidon Studinski1c9a1932017-08-21 22:55:15 +03001769 WIL_FIELD(vring_idle_trsh, 0644, doff_u32),
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001770 {},
1771};
1772
1773static const struct dbg_off dbg_wil_regs[] = {
Maya Erezc2256ec2017-02-08 13:18:42 +02001774 {"RGF_MAC_MTRL_COUNTER_0", 0444, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001775 doff_io32},
Maya Erezc2256ec2017-02-08 13:18:42 +02001776 {"RGF_USER_USAGE_1", 0444, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001777 {},
1778};
1779
1780/* static parameters */
1781static const struct dbg_off dbg_statics[] = {
Maya Erezc2256ec2017-02-08 13:18:42 +02001782 {"desc_index", 0644, (ulong)&dbg_txdesc_index, doff_u32},
1783 {"vring_index", 0644, (ulong)&dbg_vring_index, doff_u32},
1784 {"mem_addr", 0644, (ulong)&mem_addr, doff_u32},
Maya Erezc2256ec2017-02-08 13:18:42 +02001785 {"led_polarity", 0644, (ulong)&led_polarity, doff_u8},
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001786 {},
1787};
1788
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001789int wil6210_debugfs_init(struct wil6210_priv *wil)
1790{
1791 struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
1792 wil_to_wiphy(wil)->debugfsdir);
1793
1794 if (IS_ERR_OR_NULL(dbg))
1795 return -ENODEV;
1796
Vladimir Kondratievdc164272015-04-30 16:25:09 +03001797 wil_pmc_init(wil);
1798
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001799 wil6210_debugfs_init_files(wil, dbg);
1800 wil6210_debugfs_init_isr(wil, dbg);
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +03001801 wil6210_debugfs_init_blobs(wil, dbg);
Vladimir Kondratievb7cde472014-08-06 10:31:55 +03001802 wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
1803 wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
1804 dbg_wil_regs);
1805 wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
1806
1807 wil6210_debugfs_create_pseudo_ISR(wil, dbg);
1808
1809 wil6210_debugfs_create_ITR_CNT(wil, dbg);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001810
Maya Erez2f9f6422017-08-21 22:43:32 +03001811 wil->suspend_stats.collection_start = ktime_get();
1812
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001813 return 0;
1814}
1815
1816void wil6210_debugfs_remove(struct wil6210_priv *wil)
1817{
1818 debugfs_remove_recursive(wil->debug);
1819 wil->debug = NULL;
Vladimir Kondratievdc164272015-04-30 16:25:09 +03001820
1821 /* free pmc memory without sending command to fw, as it will
1822 * be reset on the way down anyway
1823 */
1824 wil_pmc_free(wil, false);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001825}