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