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