Commit | Line | Data |
---|---|---|
2be7d22f VK |
1 | /* |
2 | * Copyright (c) 2012 Qualcomm Atheros, Inc. | |
3 | * | |
4 | * Permission to use, copy, modify, and/or distribute this software for any | |
5 | * purpose with or without fee is hereby granted, provided that the above | |
6 | * copyright notice and this permission notice appear in all copies. | |
7 | * | |
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
15 | */ | |
16 | ||
17 | #include <linux/module.h> | |
18 | #include <linux/debugfs.h> | |
19 | #include <linux/seq_file.h> | |
20 | #include <linux/pci.h> | |
21 | #include <linux/rtnetlink.h> | |
22 | ||
23 | #include "wil6210.h" | |
24 | #include "txrx.h" | |
25 | ||
26 | /* Nasty hack. Better have per device instances */ | |
27 | static u32 mem_addr; | |
28 | static u32 dbg_txdesc_index; | |
af31cb5a | 29 | static u32 dbg_vring_index; /* 24+ for Rx, 0..23 for Tx */ |
2be7d22f VK |
30 | |
31 | static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil, | |
59f7c0a9 VK |
32 | const char *name, struct vring *vring, |
33 | char _s, char _h) | |
2be7d22f VK |
34 | { |
35 | void __iomem *x = wmi_addr(wil, vring->hwtail); | |
36 | ||
37 | seq_printf(s, "VRING %s = {\n", name); | |
39c52ee8 | 38 | seq_printf(s, " pa = %pad\n", &vring->pa); |
2be7d22f VK |
39 | seq_printf(s, " va = 0x%p\n", vring->va); |
40 | seq_printf(s, " size = %d\n", vring->size); | |
41 | seq_printf(s, " swtail = %d\n", vring->swtail); | |
42 | seq_printf(s, " swhead = %d\n", vring->swhead); | |
43 | seq_printf(s, " hwtail = [0x%08x] -> ", vring->hwtail); | |
44 | if (x) | |
45 | seq_printf(s, "0x%08x\n", ioread32(x)); | |
46 | else | |
47 | seq_printf(s, "???\n"); | |
48 | ||
49 | if (vring->va && (vring->size < 1025)) { | |
50 | uint i; | |
51 | for (i = 0; i < vring->size; i++) { | |
52 | volatile struct vring_tx_desc *d = &vring->va[i].tx; | |
53 | if ((i % 64) == 0 && (i != 0)) | |
54 | seq_printf(s, "\n"); | |
59f7c0a9 VK |
55 | seq_printf(s, "%c", (d->dma.status & BIT(0)) ? |
56 | _s : (vring->ctx[i].skb ? _h : 'h')); | |
2be7d22f VK |
57 | } |
58 | seq_printf(s, "\n"); | |
59 | } | |
60 | seq_printf(s, "}\n"); | |
61 | } | |
62 | ||
63 | static int wil_vring_debugfs_show(struct seq_file *s, void *data) | |
64 | { | |
65 | uint i; | |
66 | struct wil6210_priv *wil = s->private; | |
67 | ||
59f7c0a9 | 68 | wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_'); |
2be7d22f VK |
69 | |
70 | for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) { | |
71 | struct vring *vring = &(wil->vring_tx[i]); | |
72 | if (vring->va) { | |
3df2cd36 VK |
73 | int cid = wil->vring2cid_tid[i][0]; |
74 | int tid = wil->vring2cid_tid[i][1]; | |
2be7d22f VK |
75 | char name[10]; |
76 | snprintf(name, sizeof(name), "tx_%2d", i); | |
3df2cd36 VK |
77 | |
78 | seq_printf(s, "\n%pM CID %d TID %d\n", | |
79 | wil->sta[cid].addr, cid, tid); | |
59f7c0a9 | 80 | wil_print_vring(s, wil, name, vring, '_', 'H'); |
2be7d22f VK |
81 | } |
82 | } | |
83 | ||
84 | return 0; | |
85 | } | |
86 | ||
87 | static int wil_vring_seq_open(struct inode *inode, struct file *file) | |
88 | { | |
89 | return single_open(file, wil_vring_debugfs_show, inode->i_private); | |
90 | } | |
91 | ||
92 | static const struct file_operations fops_vring = { | |
93 | .open = wil_vring_seq_open, | |
94 | .release = single_release, | |
95 | .read = seq_read, | |
96 | .llseek = seq_lseek, | |
97 | }; | |
98 | ||
99 | static void wil_print_ring(struct seq_file *s, const char *prefix, | |
100 | void __iomem *off) | |
101 | { | |
102 | struct wil6210_priv *wil = s->private; | |
103 | struct wil6210_mbox_ring r; | |
104 | int rsize; | |
105 | uint i; | |
106 | ||
107 | wil_memcpy_fromio_32(&r, off, sizeof(r)); | |
108 | wil_mbox_ring_le2cpus(&r); | |
109 | /* | |
110 | * we just read memory block from NIC. This memory may be | |
111 | * garbage. Check validity before using it. | |
112 | */ | |
113 | rsize = r.size / sizeof(struct wil6210_mbox_ring_desc); | |
114 | ||
115 | seq_printf(s, "ring %s = {\n", prefix); | |
116 | seq_printf(s, " base = 0x%08x\n", r.base); | |
117 | seq_printf(s, " size = 0x%04x bytes -> %d entries\n", r.size, rsize); | |
118 | seq_printf(s, " tail = 0x%08x\n", r.tail); | |
119 | seq_printf(s, " head = 0x%08x\n", r.head); | |
120 | seq_printf(s, " entry size = %d\n", r.entry_size); | |
121 | ||
122 | if (r.size % sizeof(struct wil6210_mbox_ring_desc)) { | |
123 | seq_printf(s, " ??? size is not multiple of %zd, garbage?\n", | |
124 | sizeof(struct wil6210_mbox_ring_desc)); | |
125 | goto out; | |
126 | } | |
127 | ||
128 | if (!wmi_addr(wil, r.base) || | |
129 | !wmi_addr(wil, r.tail) || | |
130 | !wmi_addr(wil, r.head)) { | |
131 | seq_printf(s, " ??? pointers are garbage?\n"); | |
132 | goto out; | |
133 | } | |
134 | ||
135 | for (i = 0; i < rsize; i++) { | |
136 | struct wil6210_mbox_ring_desc d; | |
137 | struct wil6210_mbox_hdr hdr; | |
138 | size_t delta = i * sizeof(d); | |
139 | void __iomem *x = wil->csr + HOSTADDR(r.base) + delta; | |
140 | ||
141 | wil_memcpy_fromio_32(&d, x, sizeof(d)); | |
142 | ||
143 | seq_printf(s, " [%2x] %s %s%s 0x%08x", i, | |
144 | d.sync ? "F" : "E", | |
145 | (r.tail - r.base == delta) ? "t" : " ", | |
146 | (r.head - r.base == delta) ? "h" : " ", | |
147 | le32_to_cpu(d.addr)); | |
148 | if (0 == wmi_read_hdr(wil, d.addr, &hdr)) { | |
149 | u16 len = le16_to_cpu(hdr.len); | |
150 | seq_printf(s, " -> %04x %04x %04x %02x\n", | |
151 | le16_to_cpu(hdr.seq), len, | |
152 | le16_to_cpu(hdr.type), hdr.flags); | |
153 | if (len <= MAX_MBOXITEM_SIZE) { | |
154 | int n = 0; | |
5d21608a | 155 | char printbuf[16 * 3 + 2]; |
2be7d22f VK |
156 | unsigned char databuf[MAX_MBOXITEM_SIZE]; |
157 | void __iomem *src = wmi_buffer(wil, d.addr) + | |
158 | sizeof(struct wil6210_mbox_hdr); | |
159 | /* | |
160 | * No need to check @src for validity - | |
161 | * we already validated @d.addr while | |
162 | * reading header | |
163 | */ | |
164 | wil_memcpy_fromio_32(databuf, src, len); | |
165 | while (n < len) { | |
166 | int l = min(len - n, 16); | |
167 | hex_dump_to_buffer(databuf + n, l, | |
168 | 16, 1, printbuf, | |
169 | sizeof(printbuf), | |
170 | false); | |
171 | seq_printf(s, " : %s\n", printbuf); | |
172 | n += l; | |
173 | } | |
174 | } | |
175 | } else { | |
176 | seq_printf(s, "\n"); | |
177 | } | |
178 | } | |
179 | out: | |
180 | seq_printf(s, "}\n"); | |
181 | } | |
182 | ||
183 | static int wil_mbox_debugfs_show(struct seq_file *s, void *data) | |
184 | { | |
185 | struct wil6210_priv *wil = s->private; | |
186 | ||
187 | wil_print_ring(s, "tx", wil->csr + HOST_MBOX + | |
188 | offsetof(struct wil6210_mbox_ctl, tx)); | |
189 | wil_print_ring(s, "rx", wil->csr + HOST_MBOX + | |
190 | offsetof(struct wil6210_mbox_ctl, rx)); | |
191 | ||
192 | return 0; | |
193 | } | |
194 | ||
195 | static int wil_mbox_seq_open(struct inode *inode, struct file *file) | |
196 | { | |
197 | return single_open(file, wil_mbox_debugfs_show, inode->i_private); | |
198 | } | |
199 | ||
200 | static const struct file_operations fops_mbox = { | |
201 | .open = wil_mbox_seq_open, | |
202 | .release = single_release, | |
203 | .read = seq_read, | |
204 | .llseek = seq_lseek, | |
205 | }; | |
206 | ||
207 | static int wil_debugfs_iomem_x32_set(void *data, u64 val) | |
208 | { | |
209 | iowrite32(val, (void __iomem *)data); | |
210 | wmb(); /* make sure write propagated to HW */ | |
211 | ||
212 | return 0; | |
213 | } | |
214 | ||
215 | static int wil_debugfs_iomem_x32_get(void *data, u64 *val) | |
216 | { | |
217 | *val = ioread32((void __iomem *)data); | |
218 | ||
219 | return 0; | |
220 | } | |
221 | ||
222 | DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get, | |
223 | wil_debugfs_iomem_x32_set, "0x%08llx\n"); | |
224 | ||
225 | static struct dentry *wil_debugfs_create_iomem_x32(const char *name, | |
0ecc833b | 226 | umode_t mode, |
2be7d22f VK |
227 | struct dentry *parent, |
228 | void __iomem *value) | |
229 | { | |
230 | return debugfs_create_file(name, mode, parent, (void * __force)value, | |
231 | &fops_iomem_x32); | |
232 | } | |
233 | ||
3de6cf20 VK |
234 | static int wil_debugfs_ulong_set(void *data, u64 val) |
235 | { | |
236 | *(ulong *)data = val; | |
237 | return 0; | |
238 | } | |
239 | static int wil_debugfs_ulong_get(void *data, u64 *val) | |
240 | { | |
241 | *val = *(ulong *)data; | |
242 | return 0; | |
243 | } | |
244 | DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get, | |
245 | wil_debugfs_ulong_set, "%llu\n"); | |
246 | ||
247 | static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode, | |
248 | struct dentry *parent, | |
249 | ulong *value) | |
250 | { | |
251 | return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong); | |
252 | } | |
253 | ||
2be7d22f VK |
254 | static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil, |
255 | const char *name, | |
256 | struct dentry *parent, u32 off) | |
257 | { | |
258 | struct dentry *d = debugfs_create_dir(name, parent); | |
259 | ||
260 | if (IS_ERR_OR_NULL(d)) | |
261 | return -ENODEV; | |
262 | ||
263 | wil_debugfs_create_iomem_x32("ICC", S_IRUGO | S_IWUSR, d, | |
264 | wil->csr + off); | |
265 | wil_debugfs_create_iomem_x32("ICR", S_IRUGO | S_IWUSR, d, | |
266 | wil->csr + off + 4); | |
267 | wil_debugfs_create_iomem_x32("ICM", S_IRUGO | S_IWUSR, d, | |
268 | wil->csr + off + 8); | |
269 | wil_debugfs_create_iomem_x32("ICS", S_IWUSR, d, | |
270 | wil->csr + off + 12); | |
271 | wil_debugfs_create_iomem_x32("IMV", S_IRUGO | S_IWUSR, d, | |
272 | wil->csr + off + 16); | |
273 | wil_debugfs_create_iomem_x32("IMS", S_IWUSR, d, | |
274 | wil->csr + off + 20); | |
275 | wil_debugfs_create_iomem_x32("IMC", S_IWUSR, d, | |
276 | wil->csr + off + 24); | |
277 | ||
278 | return 0; | |
279 | } | |
280 | ||
281 | static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil, | |
282 | struct dentry *parent) | |
283 | { | |
284 | struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent); | |
285 | ||
286 | if (IS_ERR_OR_NULL(d)) | |
287 | return -ENODEV; | |
288 | ||
289 | wil_debugfs_create_iomem_x32("CAUSE", S_IRUGO, d, wil->csr + | |
290 | HOSTADDR(RGF_DMA_PSEUDO_CAUSE)); | |
291 | wil_debugfs_create_iomem_x32("MASK_SW", S_IRUGO, d, wil->csr + | |
292 | HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW)); | |
293 | wil_debugfs_create_iomem_x32("MASK_FW", S_IRUGO, d, wil->csr + | |
294 | HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW)); | |
295 | ||
296 | return 0; | |
297 | } | |
298 | ||
299 | static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil, | |
300 | struct dentry *parent) | |
301 | { | |
302 | struct dentry *d = debugfs_create_dir("ITR_CNT", parent); | |
303 | ||
304 | if (IS_ERR_OR_NULL(d)) | |
305 | return -ENODEV; | |
306 | ||
307 | wil_debugfs_create_iomem_x32("TRSH", S_IRUGO, d, wil->csr + | |
308 | HOSTADDR(RGF_DMA_ITR_CNT_TRSH)); | |
309 | wil_debugfs_create_iomem_x32("DATA", S_IRUGO, d, wil->csr + | |
310 | HOSTADDR(RGF_DMA_ITR_CNT_DATA)); | |
311 | wil_debugfs_create_iomem_x32("CTL", S_IRUGO, d, wil->csr + | |
312 | HOSTADDR(RGF_DMA_ITR_CNT_CRL)); | |
313 | ||
314 | return 0; | |
315 | } | |
316 | ||
317 | static int wil_memread_debugfs_show(struct seq_file *s, void *data) | |
318 | { | |
319 | struct wil6210_priv *wil = s->private; | |
320 | void __iomem *a = wmi_buffer(wil, cpu_to_le32(mem_addr)); | |
321 | ||
322 | if (a) | |
323 | seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, ioread32(a)); | |
324 | else | |
325 | seq_printf(s, "[0x%08x] = INVALID\n", mem_addr); | |
326 | ||
327 | return 0; | |
328 | } | |
329 | ||
330 | static int wil_memread_seq_open(struct inode *inode, struct file *file) | |
331 | { | |
332 | return single_open(file, wil_memread_debugfs_show, inode->i_private); | |
333 | } | |
334 | ||
335 | static const struct file_operations fops_memread = { | |
336 | .open = wil_memread_seq_open, | |
337 | .release = single_release, | |
338 | .read = seq_read, | |
339 | .llseek = seq_lseek, | |
340 | }; | |
341 | ||
2be7d22f VK |
342 | static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf, |
343 | size_t count, loff_t *ppos) | |
344 | { | |
345 | enum { max_count = 4096 }; | |
346 | struct debugfs_blob_wrapper *blob = file->private_data; | |
347 | loff_t pos = *ppos; | |
348 | size_t available = blob->size; | |
349 | void *buf; | |
350 | size_t ret; | |
351 | ||
352 | if (pos < 0) | |
353 | return -EINVAL; | |
354 | ||
355 | if (pos >= available || !count) | |
356 | return 0; | |
357 | ||
358 | if (count > available - pos) | |
359 | count = available - pos; | |
360 | if (count > max_count) | |
361 | count = max_count; | |
362 | ||
363 | buf = kmalloc(count, GFP_KERNEL); | |
364 | if (!buf) | |
365 | return -ENOMEM; | |
366 | ||
367 | wil_memcpy_fromio_32(buf, (const volatile void __iomem *)blob->data + | |
368 | pos, count); | |
369 | ||
370 | ret = copy_to_user(user_buf, buf, count); | |
371 | kfree(buf); | |
372 | if (ret == count) | |
373 | return -EFAULT; | |
374 | ||
375 | count -= ret; | |
376 | *ppos = pos + count; | |
377 | ||
378 | return count; | |
379 | } | |
380 | ||
381 | static const struct file_operations fops_ioblob = { | |
382 | .read = wil_read_file_ioblob, | |
93ecbd64 | 383 | .open = simple_open, |
2be7d22f VK |
384 | .llseek = default_llseek, |
385 | }; | |
386 | ||
387 | static | |
388 | struct dentry *wil_debugfs_create_ioblob(const char *name, | |
0ecc833b | 389 | umode_t mode, |
2be7d22f VK |
390 | struct dentry *parent, |
391 | struct debugfs_blob_wrapper *blob) | |
392 | { | |
393 | return debugfs_create_file(name, mode, parent, blob, &fops_ioblob); | |
394 | } | |
395 | /*---reset---*/ | |
396 | static ssize_t wil_write_file_reset(struct file *file, const char __user *buf, | |
397 | size_t len, loff_t *ppos) | |
398 | { | |
399 | struct wil6210_priv *wil = file->private_data; | |
400 | struct net_device *ndev = wil_to_ndev(wil); | |
401 | ||
402 | /** | |
403 | * BUG: | |
404 | * this code does NOT sync device state with the rest of system | |
405 | * use with care, debug only!!! | |
406 | */ | |
407 | rtnl_lock(); | |
408 | dev_close(ndev); | |
409 | ndev->flags &= ~IFF_UP; | |
410 | rtnl_unlock(); | |
411 | wil_reset(wil); | |
412 | ||
413 | return len; | |
414 | } | |
415 | ||
416 | static const struct file_operations fops_reset = { | |
417 | .write = wil_write_file_reset, | |
93ecbd64 | 418 | .open = simple_open, |
2be7d22f | 419 | }; |
0b39aaf2 VK |
420 | /*---write channel 1..4 to rxon for it, 0 to rxoff---*/ |
421 | static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf, | |
422 | size_t len, loff_t *ppos) | |
423 | { | |
424 | struct wil6210_priv *wil = file->private_data; | |
425 | int rc; | |
426 | long channel; | |
427 | bool on; | |
428 | ||
429 | char *kbuf = kmalloc(len + 1, GFP_KERNEL); | |
430 | if (!kbuf) | |
431 | return -ENOMEM; | |
432 | if (copy_from_user(kbuf, buf, len)) | |
433 | return -EIO; | |
434 | ||
435 | kbuf[len] = '\0'; | |
436 | rc = kstrtol(kbuf, 0, &channel); | |
437 | kfree(kbuf); | |
438 | if (rc) | |
439 | return rc; | |
440 | ||
441 | if ((channel < 0) || (channel > 4)) { | |
442 | wil_err(wil, "Invalid channel %ld\n", channel); | |
443 | return -EINVAL; | |
444 | } | |
445 | on = !!channel; | |
446 | ||
447 | if (on) { | |
448 | rc = wmi_set_channel(wil, (int)channel); | |
449 | if (rc) | |
450 | return rc; | |
451 | } | |
452 | ||
453 | rc = wmi_rxon(wil, on); | |
454 | if (rc) | |
455 | return rc; | |
456 | ||
457 | return len; | |
458 | } | |
459 | ||
460 | static const struct file_operations fops_rxon = { | |
461 | .write = wil_write_file_rxon, | |
462 | .open = simple_open, | |
463 | }; | |
464 | /*---tx_mgmt---*/ | |
465 | /* Write mgmt frame to this file to send it */ | |
466 | static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf, | |
467 | size_t len, loff_t *ppos) | |
468 | { | |
469 | struct wil6210_priv *wil = file->private_data; | |
470 | struct wiphy *wiphy = wil_to_wiphy(wil); | |
471 | struct wireless_dev *wdev = wil_to_wdev(wil); | |
472 | struct cfg80211_mgmt_tx_params params; | |
473 | int rc; | |
474 | ||
475 | void *frame = kmalloc(len, GFP_KERNEL); | |
476 | if (!frame) | |
477 | return -ENOMEM; | |
478 | ||
479 | if (copy_from_user(frame, buf, len)) | |
480 | return -EIO; | |
481 | ||
482 | params.buf = frame; | |
483 | params.len = len; | |
484 | params.chan = wdev->preset_chandef.chan; | |
485 | ||
486 | rc = wil_cfg80211_mgmt_tx(wiphy, wdev, ¶ms, NULL); | |
487 | ||
488 | kfree(frame); | |
489 | wil_info(wil, "%s() -> %d\n", __func__, rc); | |
490 | ||
491 | return len; | |
492 | } | |
493 | ||
494 | static const struct file_operations fops_txmgmt = { | |
495 | .write = wil_write_file_txmgmt, | |
496 | .open = simple_open, | |
497 | }; | |
2be7d22f | 498 | |
c236658f VK |
499 | static void wil_seq_hexdump(struct seq_file *s, void *p, int len, |
500 | const char *prefix) | |
501 | { | |
502 | char printbuf[16 * 3 + 2]; | |
503 | int i = 0; | |
504 | while (i < len) { | |
505 | int l = min(len - i, 16); | |
506 | hex_dump_to_buffer(p + i, l, 16, 1, printbuf, | |
507 | sizeof(printbuf), false); | |
508 | seq_printf(s, "%s%s\n", prefix, printbuf); | |
509 | i += l; | |
510 | } | |
511 | } | |
512 | ||
513 | static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb) | |
514 | { | |
515 | int i = 0; | |
516 | int len = skb_headlen(skb); | |
517 | void *p = skb->data; | |
518 | int nr_frags = skb_shinfo(skb)->nr_frags; | |
519 | ||
520 | seq_printf(s, " len = %d\n", len); | |
521 | wil_seq_hexdump(s, p, len, " : "); | |
522 | ||
523 | if (nr_frags) { | |
524 | seq_printf(s, " nr_frags = %d\n", nr_frags); | |
525 | for (i = 0; i < nr_frags; i++) { | |
526 | const struct skb_frag_struct *frag = | |
527 | &skb_shinfo(skb)->frags[i]; | |
528 | ||
529 | len = skb_frag_size(frag); | |
530 | p = skb_frag_address_safe(frag); | |
531 | seq_printf(s, " [%2d] : len = %d\n", i, len); | |
532 | wil_seq_hexdump(s, p, len, " : "); | |
533 | } | |
534 | } | |
535 | } | |
536 | ||
3a85543e | 537 | /*---------Tx/Rx descriptor------------*/ |
2be7d22f VK |
538 | static int wil_txdesc_debugfs_show(struct seq_file *s, void *data) |
539 | { | |
540 | struct wil6210_priv *wil = s->private; | |
3a85543e | 541 | struct vring *vring; |
af31cb5a VK |
542 | bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS); |
543 | if (tx) | |
3a85543e VK |
544 | vring = &(wil->vring_tx[dbg_vring_index]); |
545 | else | |
546 | vring = &wil->vring_rx; | |
2be7d22f VK |
547 | |
548 | if (!vring->va) { | |
af31cb5a | 549 | if (tx) |
3a85543e VK |
550 | seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index); |
551 | else | |
552 | seq_puts(s, "No Rx VRING\n"); | |
2be7d22f VK |
553 | return 0; |
554 | } | |
555 | ||
556 | if (dbg_txdesc_index < vring->size) { | |
3a85543e VK |
557 | /* use struct vring_tx_desc for Rx as well, |
558 | * only field used, .dma.length, is the same | |
559 | */ | |
2be7d22f VK |
560 | volatile struct vring_tx_desc *d = |
561 | &(vring->va[dbg_txdesc_index].tx); | |
562 | volatile u32 *u = (volatile u32 *)d; | |
f88f113a | 563 | struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb; |
2be7d22f | 564 | |
af31cb5a | 565 | if (tx) |
3a85543e VK |
566 | seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index, |
567 | dbg_txdesc_index); | |
568 | else | |
569 | seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index); | |
2be7d22f VK |
570 | seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n", |
571 | u[0], u[1], u[2], u[3]); | |
572 | seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n", | |
573 | u[4], u[5], u[6], u[7]); | |
39c52ee8 | 574 | seq_printf(s, " SKB = 0x%p\n", skb); |
2be7d22f VK |
575 | |
576 | if (skb) { | |
c236658f VK |
577 | skb_get(skb); |
578 | wil_seq_print_skb(s, skb); | |
579 | kfree_skb(skb); | |
2be7d22f VK |
580 | } |
581 | seq_printf(s, "}\n"); | |
582 | } else { | |
af31cb5a | 583 | if (tx) |
3a85543e VK |
584 | seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n", |
585 | dbg_vring_index, dbg_txdesc_index, | |
586 | vring->size); | |
587 | else | |
588 | seq_printf(s, "RxDesc index (%d) >= size (%d)\n", | |
589 | dbg_txdesc_index, vring->size); | |
2be7d22f VK |
590 | } |
591 | ||
592 | return 0; | |
593 | } | |
594 | ||
595 | static int wil_txdesc_seq_open(struct inode *inode, struct file *file) | |
596 | { | |
597 | return single_open(file, wil_txdesc_debugfs_show, inode->i_private); | |
598 | } | |
599 | ||
600 | static const struct file_operations fops_txdesc = { | |
601 | .open = wil_txdesc_seq_open, | |
602 | .release = single_release, | |
603 | .read = seq_read, | |
604 | .llseek = seq_lseek, | |
605 | }; | |
606 | ||
607 | /*---------beamforming------------*/ | |
608 | static int wil_bf_debugfs_show(struct seq_file *s, void *data) | |
609 | { | |
610 | struct wil6210_priv *wil = s->private; | |
611 | seq_printf(s, | |
612 | "TSF : 0x%016llx\n" | |
613 | "TxMCS : %d\n" | |
614 | "Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n", | |
615 | wil->stats.tsf, wil->stats.bf_mcs, | |
616 | wil->stats.my_rx_sector, wil->stats.my_tx_sector, | |
617 | wil->stats.peer_rx_sector, wil->stats.peer_tx_sector); | |
618 | return 0; | |
619 | } | |
620 | ||
621 | static int wil_bf_seq_open(struct inode *inode, struct file *file) | |
622 | { | |
623 | return single_open(file, wil_bf_debugfs_show, inode->i_private); | |
624 | } | |
625 | ||
626 | static const struct file_operations fops_bf = { | |
627 | .open = wil_bf_seq_open, | |
628 | .release = single_release, | |
629 | .read = seq_read, | |
630 | .llseek = seq_lseek, | |
631 | }; | |
632 | /*---------SSID------------*/ | |
633 | static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf, | |
634 | size_t count, loff_t *ppos) | |
635 | { | |
636 | struct wil6210_priv *wil = file->private_data; | |
637 | struct wireless_dev *wdev = wil_to_wdev(wil); | |
638 | ||
639 | return simple_read_from_buffer(user_buf, count, ppos, | |
640 | wdev->ssid, wdev->ssid_len); | |
641 | } | |
642 | ||
643 | static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf, | |
644 | size_t count, loff_t *ppos) | |
645 | { | |
646 | struct wil6210_priv *wil = file->private_data; | |
647 | struct wireless_dev *wdev = wil_to_wdev(wil); | |
648 | struct net_device *ndev = wil_to_ndev(wil); | |
649 | ||
650 | if (*ppos != 0) { | |
651 | wil_err(wil, "Unable to set SSID substring from [%d]\n", | |
652 | (int)*ppos); | |
653 | return -EINVAL; | |
654 | } | |
655 | ||
656 | if (count > sizeof(wdev->ssid)) { | |
657 | wil_err(wil, "SSID too long, len = %d\n", (int)count); | |
658 | return -EINVAL; | |
659 | } | |
660 | if (netif_running(ndev)) { | |
661 | wil_err(wil, "Unable to change SSID on running interface\n"); | |
662 | return -EINVAL; | |
663 | } | |
664 | ||
665 | wdev->ssid_len = count; | |
666 | return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos, | |
667 | buf, count); | |
668 | } | |
669 | ||
670 | static const struct file_operations fops_ssid = { | |
671 | .read = wil_read_file_ssid, | |
672 | .write = wil_write_file_ssid, | |
93ecbd64 | 673 | .open = simple_open, |
2be7d22f VK |
674 | }; |
675 | ||
1a2780e0 VK |
676 | /*---------temp------------*/ |
677 | static void print_temp(struct seq_file *s, const char *prefix, u32 t) | |
678 | { | |
679 | switch (t) { | |
680 | case 0: | |
681 | case ~(u32)0: | |
682 | seq_printf(s, "%s N/A\n", prefix); | |
683 | break; | |
684 | default: | |
685 | seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000); | |
686 | break; | |
687 | } | |
688 | } | |
689 | ||
690 | static int wil_temp_debugfs_show(struct seq_file *s, void *data) | |
691 | { | |
692 | struct wil6210_priv *wil = s->private; | |
693 | u32 t_m, t_r; | |
694 | ||
695 | int rc = wmi_get_temperature(wil, &t_m, &t_r); | |
696 | if (rc) { | |
697 | seq_printf(s, "Failed\n"); | |
698 | return 0; | |
699 | } | |
700 | ||
701 | print_temp(s, "MAC temperature :", t_m); | |
702 | print_temp(s, "Radio temperature :", t_r); | |
703 | ||
704 | return 0; | |
705 | } | |
706 | ||
707 | static int wil_temp_seq_open(struct inode *inode, struct file *file) | |
708 | { | |
709 | return single_open(file, wil_temp_debugfs_show, inode->i_private); | |
710 | } | |
711 | ||
712 | static const struct file_operations fops_temp = { | |
713 | .open = wil_temp_seq_open, | |
714 | .release = single_release, | |
715 | .read = seq_read, | |
716 | .llseek = seq_lseek, | |
717 | }; | |
718 | ||
3df2cd36 | 719 | /*---------Station matrix------------*/ |
b4490f42 VK |
720 | static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r) |
721 | { | |
722 | int i; | |
723 | u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size; | |
724 | seq_printf(s, "0x%03x [", r->head_seq_num); | |
725 | for (i = 0; i < r->buf_size; i++) { | |
726 | if (i == index) | |
727 | seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|'); | |
728 | else | |
729 | seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_'); | |
730 | } | |
731 | seq_puts(s, "]\n"); | |
732 | } | |
3df2cd36 VK |
733 | |
734 | static int wil_sta_debugfs_show(struct seq_file *s, void *data) | |
735 | { | |
736 | struct wil6210_priv *wil = s->private; | |
b4490f42 | 737 | int i, tid; |
3df2cd36 VK |
738 | |
739 | for (i = 0; i < ARRAY_SIZE(wil->sta); i++) { | |
740 | struct wil_sta_info *p = &wil->sta[i]; | |
741 | char *status = "unknown"; | |
742 | switch (p->status) { | |
743 | case wil_sta_unused: | |
744 | status = "unused "; | |
745 | break; | |
746 | case wil_sta_conn_pending: | |
747 | status = "pending "; | |
748 | break; | |
749 | case wil_sta_connected: | |
750 | status = "connected"; | |
751 | break; | |
752 | } | |
e58c9f70 VK |
753 | seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status, |
754 | (p->data_port_open ? " data_port_open" : "")); | |
b4490f42 VK |
755 | |
756 | if (p->status == wil_sta_connected) { | |
757 | for (tid = 0; tid < WIL_STA_TID_NUM; tid++) { | |
758 | struct wil_tid_ampdu_rx *r = p->tid_rx[tid]; | |
759 | if (r) { | |
760 | seq_printf(s, "[%2d] ", tid); | |
761 | wil_print_rxtid(s, r); | |
762 | } | |
763 | } | |
764 | } | |
3df2cd36 VK |
765 | } |
766 | ||
767 | return 0; | |
768 | } | |
769 | ||
770 | static int wil_sta_seq_open(struct inode *inode, struct file *file) | |
771 | { | |
772 | return single_open(file, wil_sta_debugfs_show, inode->i_private); | |
773 | } | |
774 | ||
775 | static const struct file_operations fops_sta = { | |
776 | .open = wil_sta_seq_open, | |
777 | .release = single_release, | |
778 | .read = seq_read, | |
779 | .llseek = seq_lseek, | |
780 | }; | |
781 | ||
2be7d22f VK |
782 | /*----------------*/ |
783 | int wil6210_debugfs_init(struct wil6210_priv *wil) | |
784 | { | |
785 | struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME, | |
786 | wil_to_wiphy(wil)->debugfsdir); | |
787 | ||
788 | if (IS_ERR_OR_NULL(dbg)) | |
789 | return -ENODEV; | |
790 | ||
791 | debugfs_create_file("mbox", S_IRUGO, dbg, wil, &fops_mbox); | |
792 | debugfs_create_file("vrings", S_IRUGO, dbg, wil, &fops_vring); | |
3df2cd36 | 793 | debugfs_create_file("stations", S_IRUGO, dbg, wil, &fops_sta); |
3a85543e VK |
794 | debugfs_create_file("desc", S_IRUGO, dbg, wil, &fops_txdesc); |
795 | debugfs_create_u32("desc_index", S_IRUGO | S_IWUSR, dbg, | |
2be7d22f | 796 | &dbg_txdesc_index); |
3a85543e VK |
797 | debugfs_create_u32("vring_index", S_IRUGO | S_IWUSR, dbg, |
798 | &dbg_vring_index); | |
799 | ||
2be7d22f VK |
800 | debugfs_create_file("bf", S_IRUGO, dbg, wil, &fops_bf); |
801 | debugfs_create_file("ssid", S_IRUGO | S_IWUSR, dbg, wil, &fops_ssid); | |
802 | debugfs_create_u32("secure_pcp", S_IRUGO | S_IWUSR, dbg, | |
803 | &wil->secure_pcp); | |
3de6cf20 VK |
804 | wil_debugfs_create_ulong("status", S_IRUGO | S_IWUSR, dbg, |
805 | &wil->status); | |
2be7d22f VK |
806 | |
807 | wil6210_debugfs_create_ISR(wil, "USER_ICR", dbg, | |
808 | HOSTADDR(RGF_USER_USER_ICR)); | |
809 | wil6210_debugfs_create_ISR(wil, "DMA_EP_TX_ICR", dbg, | |
810 | HOSTADDR(RGF_DMA_EP_TX_ICR)); | |
811 | wil6210_debugfs_create_ISR(wil, "DMA_EP_RX_ICR", dbg, | |
812 | HOSTADDR(RGF_DMA_EP_RX_ICR)); | |
813 | wil6210_debugfs_create_ISR(wil, "DMA_EP_MISC_ICR", dbg, | |
814 | HOSTADDR(RGF_DMA_EP_MISC_ICR)); | |
815 | wil6210_debugfs_create_pseudo_ISR(wil, dbg); | |
816 | wil6210_debugfs_create_ITR_CNT(wil, dbg); | |
817 | ||
818 | debugfs_create_u32("mem_addr", S_IRUGO | S_IWUSR, dbg, &mem_addr); | |
819 | debugfs_create_file("mem_val", S_IRUGO, dbg, wil, &fops_memread); | |
820 | ||
821 | debugfs_create_file("reset", S_IWUSR, dbg, wil, &fops_reset); | |
0b39aaf2 VK |
822 | debugfs_create_file("rxon", S_IWUSR, dbg, wil, &fops_rxon); |
823 | debugfs_create_file("tx_mgmt", S_IWUSR, dbg, wil, &fops_txmgmt); | |
1a2780e0 | 824 | debugfs_create_file("temp", S_IRUGO, dbg, wil, &fops_temp); |
2be7d22f VK |
825 | |
826 | wil->rgf_blob.data = (void * __force)wil->csr + 0; | |
827 | wil->rgf_blob.size = 0xa000; | |
828 | wil_debugfs_create_ioblob("blob_rgf", S_IRUGO, dbg, &wil->rgf_blob); | |
829 | ||
830 | wil->fw_code_blob.data = (void * __force)wil->csr + 0x40000; | |
831 | wil->fw_code_blob.size = 0x40000; | |
832 | wil_debugfs_create_ioblob("blob_fw_code", S_IRUGO, dbg, | |
833 | &wil->fw_code_blob); | |
834 | ||
835 | wil->fw_data_blob.data = (void * __force)wil->csr + 0x80000; | |
836 | wil->fw_data_blob.size = 0x8000; | |
837 | wil_debugfs_create_ioblob("blob_fw_data", S_IRUGO, dbg, | |
838 | &wil->fw_data_blob); | |
839 | ||
840 | wil->fw_peri_blob.data = (void * __force)wil->csr + 0x88000; | |
841 | wil->fw_peri_blob.size = 0x18000; | |
842 | wil_debugfs_create_ioblob("blob_fw_peri", S_IRUGO, dbg, | |
843 | &wil->fw_peri_blob); | |
844 | ||
845 | wil->uc_code_blob.data = (void * __force)wil->csr + 0xa0000; | |
846 | wil->uc_code_blob.size = 0x10000; | |
847 | wil_debugfs_create_ioblob("blob_uc_code", S_IRUGO, dbg, | |
848 | &wil->uc_code_blob); | |
849 | ||
850 | wil->uc_data_blob.data = (void * __force)wil->csr + 0xb0000; | |
851 | wil->uc_data_blob.size = 0x4000; | |
852 | wil_debugfs_create_ioblob("blob_uc_data", S_IRUGO, dbg, | |
853 | &wil->uc_data_blob); | |
854 | ||
855 | return 0; | |
856 | } | |
857 | ||
858 | void wil6210_debugfs_remove(struct wil6210_priv *wil) | |
859 | { | |
860 | debugfs_remove_recursive(wil->debug); | |
861 | wil->debug = NULL; | |
862 | } |