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