1 /* 2 * Copyright (c) 2012-2017 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 #include <linux/power_supply.h> 23 #include "wil6210.h" 24 #include "wmi.h" 25 #include "txrx.h" 26 #include "pmc.h" 27 28 /* Nasty hack. Better have per device instances */ 29 static u32 mem_addr; 30 static u32 dbg_txdesc_index; 31 static u32 dbg_vring_index; /* 24+ for Rx, 0..23 for Tx */ 32 33 enum dbg_off_type { 34 doff_u32 = 0, 35 doff_x32 = 1, 36 doff_ulong = 2, 37 doff_io32 = 3, 38 doff_u8 = 4 39 }; 40 41 /* offset to "wil" */ 42 struct dbg_off { 43 const char *name; 44 umode_t mode; 45 ulong off; 46 enum dbg_off_type type; 47 }; 48 49 static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil, 50 const char *name, struct vring *vring, 51 char _s, char _h) 52 { 53 void __iomem *x = wmi_addr(wil, vring->hwtail); 54 u32 v; 55 56 seq_printf(s, "VRING %s = {\n", name); 57 seq_printf(s, " pa = %pad\n", &vring->pa); 58 seq_printf(s, " va = 0x%p\n", vring->va); 59 seq_printf(s, " size = %d\n", vring->size); 60 seq_printf(s, " swtail = %d\n", vring->swtail); 61 seq_printf(s, " swhead = %d\n", vring->swhead); 62 seq_printf(s, " hwtail = [0x%08x] -> ", vring->hwtail); 63 if (x) { 64 v = readl(x); 65 seq_printf(s, "0x%08x = %d\n", v, v); 66 } else { 67 seq_puts(s, "???\n"); 68 } 69 70 if (vring->va && (vring->size <= (1 << WIL_RING_SIZE_ORDER_MAX))) { 71 uint i; 72 73 for (i = 0; i < vring->size; i++) { 74 volatile struct vring_tx_desc *d = &vring->va[i].tx; 75 76 if ((i % 128) == 0 && (i != 0)) 77 seq_puts(s, "\n"); 78 seq_printf(s, "%c", (d->dma.status & BIT(0)) ? 79 _s : (vring->ctx[i].skb ? _h : 'h')); 80 } 81 seq_puts(s, "\n"); 82 } 83 seq_puts(s, "}\n"); 84 } 85 86 static int wil_vring_debugfs_show(struct seq_file *s, void *data) 87 { 88 uint i; 89 struct wil6210_priv *wil = s->private; 90 91 wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_'); 92 93 for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) { 94 struct vring *vring = &wil->vring_tx[i]; 95 struct vring_tx_data *txdata = &wil->vring_tx_data[i]; 96 97 if (vring->va) { 98 int cid = wil->vring2cid_tid[i][0]; 99 int tid = wil->vring2cid_tid[i][1]; 100 u32 swhead = vring->swhead; 101 u32 swtail = vring->swtail; 102 int used = (vring->size + swhead - swtail) 103 % vring->size; 104 int avail = vring->size - used - 1; 105 char name[10]; 106 char sidle[10]; 107 /* performance monitoring */ 108 cycles_t now = get_cycles(); 109 uint64_t idle = txdata->idle * 100; 110 uint64_t total = now - txdata->begin; 111 112 if (total != 0) { 113 do_div(idle, total); 114 snprintf(sidle, sizeof(sidle), "%3d%%", 115 (int)idle); 116 } else { 117 snprintf(sidle, sizeof(sidle), "N/A"); 118 } 119 txdata->begin = now; 120 txdata->idle = 0ULL; 121 122 snprintf(name, sizeof(name), "tx_%2d", i); 123 124 if (cid < WIL6210_MAX_CID) 125 seq_printf(s, 126 "\n%pM CID %d TID %d 1x%s BACK([%u] %u TU A%s) [%3d|%3d] idle %s\n", 127 wil->sta[cid].addr, cid, tid, 128 txdata->dot1x_open ? "+" : "-", 129 txdata->agg_wsize, 130 txdata->agg_timeout, 131 txdata->agg_amsdu ? "+" : "-", 132 used, avail, sidle); 133 else 134 seq_printf(s, 135 "\nBroadcast 1x%s [%3d|%3d] idle %s\n", 136 txdata->dot1x_open ? "+" : "-", 137 used, avail, sidle); 138 139 wil_print_vring(s, wil, name, vring, '_', 'H'); 140 } 141 } 142 143 return 0; 144 } 145 146 static int wil_vring_seq_open(struct inode *inode, struct file *file) 147 { 148 return single_open(file, wil_vring_debugfs_show, inode->i_private); 149 } 150 151 static const struct file_operations fops_vring = { 152 .open = wil_vring_seq_open, 153 .release = single_release, 154 .read = seq_read, 155 .llseek = seq_lseek, 156 }; 157 158 static void wil_seq_hexdump(struct seq_file *s, void *p, int len, 159 const char *prefix) 160 { 161 seq_hex_dump(s, prefix, DUMP_PREFIX_NONE, 16, 1, p, len, false); 162 } 163 164 static void wil_print_ring(struct seq_file *s, const char *prefix, 165 void __iomem *off) 166 { 167 struct wil6210_priv *wil = s->private; 168 struct wil6210_mbox_ring r; 169 int rsize; 170 uint i; 171 172 wil_halp_vote(wil); 173 174 wil_memcpy_fromio_32(&r, off, sizeof(r)); 175 wil_mbox_ring_le2cpus(&r); 176 /* 177 * we just read memory block from NIC. This memory may be 178 * garbage. Check validity before using it. 179 */ 180 rsize = r.size / sizeof(struct wil6210_mbox_ring_desc); 181 182 seq_printf(s, "ring %s = {\n", prefix); 183 seq_printf(s, " base = 0x%08x\n", r.base); 184 seq_printf(s, " size = 0x%04x bytes -> %d entries\n", r.size, rsize); 185 seq_printf(s, " tail = 0x%08x\n", r.tail); 186 seq_printf(s, " head = 0x%08x\n", r.head); 187 seq_printf(s, " entry size = %d\n", r.entry_size); 188 189 if (r.size % sizeof(struct wil6210_mbox_ring_desc)) { 190 seq_printf(s, " ??? size is not multiple of %zd, garbage?\n", 191 sizeof(struct wil6210_mbox_ring_desc)); 192 goto out; 193 } 194 195 if (!wmi_addr(wil, r.base) || 196 !wmi_addr(wil, r.tail) || 197 !wmi_addr(wil, r.head)) { 198 seq_puts(s, " ??? pointers are garbage?\n"); 199 goto out; 200 } 201 202 for (i = 0; i < rsize; i++) { 203 struct wil6210_mbox_ring_desc d; 204 struct wil6210_mbox_hdr hdr; 205 size_t delta = i * sizeof(d); 206 void __iomem *x = wil->csr + HOSTADDR(r.base) + delta; 207 208 wil_memcpy_fromio_32(&d, x, sizeof(d)); 209 210 seq_printf(s, " [%2x] %s %s%s 0x%08x", i, 211 d.sync ? "F" : "E", 212 (r.tail - r.base == delta) ? "t" : " ", 213 (r.head - r.base == delta) ? "h" : " ", 214 le32_to_cpu(d.addr)); 215 if (0 == wmi_read_hdr(wil, d.addr, &hdr)) { 216 u16 len = le16_to_cpu(hdr.len); 217 218 seq_printf(s, " -> %04x %04x %04x %02x\n", 219 le16_to_cpu(hdr.seq), len, 220 le16_to_cpu(hdr.type), hdr.flags); 221 if (len <= MAX_MBOXITEM_SIZE) { 222 unsigned char databuf[MAX_MBOXITEM_SIZE]; 223 void __iomem *src = wmi_buffer(wil, d.addr) + 224 sizeof(struct wil6210_mbox_hdr); 225 /* 226 * No need to check @src for validity - 227 * we already validated @d.addr while 228 * reading header 229 */ 230 wil_memcpy_fromio_32(databuf, src, len); 231 wil_seq_hexdump(s, databuf, len, " : "); 232 } 233 } else { 234 seq_puts(s, "\n"); 235 } 236 } 237 out: 238 seq_puts(s, "}\n"); 239 wil_halp_unvote(wil); 240 } 241 242 static int wil_mbox_debugfs_show(struct seq_file *s, void *data) 243 { 244 struct wil6210_priv *wil = s->private; 245 int ret; 246 247 ret = wil_pm_runtime_get(wil); 248 if (ret < 0) 249 return ret; 250 251 wil_print_ring(s, "tx", wil->csr + HOST_MBOX + 252 offsetof(struct wil6210_mbox_ctl, tx)); 253 wil_print_ring(s, "rx", wil->csr + HOST_MBOX + 254 offsetof(struct wil6210_mbox_ctl, rx)); 255 256 wil_pm_runtime_put(wil); 257 258 return 0; 259 } 260 261 static int wil_mbox_seq_open(struct inode *inode, struct file *file) 262 { 263 return single_open(file, wil_mbox_debugfs_show, inode->i_private); 264 } 265 266 static const struct file_operations fops_mbox = { 267 .open = wil_mbox_seq_open, 268 .release = single_release, 269 .read = seq_read, 270 .llseek = seq_lseek, 271 }; 272 273 static int wil_debugfs_iomem_x32_set(void *data, u64 val) 274 { 275 struct wil_debugfs_iomem_data *d = (struct 276 wil_debugfs_iomem_data *)data; 277 struct wil6210_priv *wil = d->wil; 278 int ret; 279 280 ret = wil_pm_runtime_get(wil); 281 if (ret < 0) 282 return ret; 283 284 writel(val, (void __iomem *)d->offset); 285 wmb(); /* make sure write propagated to HW */ 286 287 wil_pm_runtime_put(wil); 288 289 return 0; 290 } 291 292 static int wil_debugfs_iomem_x32_get(void *data, u64 *val) 293 { 294 struct wil_debugfs_iomem_data *d = (struct 295 wil_debugfs_iomem_data *)data; 296 struct wil6210_priv *wil = d->wil; 297 int ret; 298 299 ret = wil_pm_runtime_get(wil); 300 if (ret < 0) 301 return ret; 302 303 *val = readl((void __iomem *)d->offset); 304 305 wil_pm_runtime_put(wil); 306 307 return 0; 308 } 309 310 DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get, 311 wil_debugfs_iomem_x32_set, "0x%08llx\n"); 312 313 static struct dentry *wil_debugfs_create_iomem_x32(const char *name, 314 umode_t mode, 315 struct dentry *parent, 316 void *value, 317 struct wil6210_priv *wil) 318 { 319 struct dentry *file; 320 struct wil_debugfs_iomem_data *data = &wil->dbg_data.data_arr[ 321 wil->dbg_data.iomem_data_count]; 322 323 data->wil = wil; 324 data->offset = value; 325 326 file = debugfs_create_file(name, mode, parent, data, &fops_iomem_x32); 327 if (!IS_ERR_OR_NULL(file)) 328 wil->dbg_data.iomem_data_count++; 329 330 return file; 331 } 332 333 static int wil_debugfs_ulong_set(void *data, u64 val) 334 { 335 *(ulong *)data = val; 336 return 0; 337 } 338 339 static int wil_debugfs_ulong_get(void *data, u64 *val) 340 { 341 *val = *(ulong *)data; 342 return 0; 343 } 344 345 DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get, 346 wil_debugfs_ulong_set, "0x%llx\n"); 347 348 static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode, 349 struct dentry *parent, 350 ulong *value) 351 { 352 return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong); 353 } 354 355 /** 356 * wil6210_debugfs_init_offset - create set of debugfs files 357 * @wil - driver's context, used for printing 358 * @dbg - directory on the debugfs, where files will be created 359 * @base - base address used in address calculation 360 * @tbl - table with file descriptions. Should be terminated with empty element. 361 * 362 * Creates files accordingly to the @tbl. 363 */ 364 static void wil6210_debugfs_init_offset(struct wil6210_priv *wil, 365 struct dentry *dbg, void *base, 366 const struct dbg_off * const tbl) 367 { 368 int i; 369 370 for (i = 0; tbl[i].name; i++) { 371 struct dentry *f; 372 373 switch (tbl[i].type) { 374 case doff_u32: 375 f = debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg, 376 base + tbl[i].off); 377 break; 378 case doff_x32: 379 f = debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg, 380 base + tbl[i].off); 381 break; 382 case doff_ulong: 383 f = wil_debugfs_create_ulong(tbl[i].name, tbl[i].mode, 384 dbg, base + tbl[i].off); 385 break; 386 case doff_io32: 387 f = wil_debugfs_create_iomem_x32(tbl[i].name, 388 tbl[i].mode, dbg, 389 base + tbl[i].off, 390 wil); 391 break; 392 case doff_u8: 393 f = debugfs_create_u8(tbl[i].name, tbl[i].mode, dbg, 394 base + tbl[i].off); 395 break; 396 default: 397 f = ERR_PTR(-EINVAL); 398 } 399 if (IS_ERR_OR_NULL(f)) 400 wil_err(wil, "Create file \"%s\": err %ld\n", 401 tbl[i].name, PTR_ERR(f)); 402 } 403 } 404 405 static const struct dbg_off isr_off[] = { 406 {"ICC", 0644, offsetof(struct RGF_ICR, ICC), doff_io32}, 407 {"ICR", 0644, offsetof(struct RGF_ICR, ICR), doff_io32}, 408 {"ICM", 0644, offsetof(struct RGF_ICR, ICM), doff_io32}, 409 {"ICS", 0244, offsetof(struct RGF_ICR, ICS), doff_io32}, 410 {"IMV", 0644, offsetof(struct RGF_ICR, IMV), doff_io32}, 411 {"IMS", 0244, offsetof(struct RGF_ICR, IMS), doff_io32}, 412 {"IMC", 0244, offsetof(struct RGF_ICR, IMC), doff_io32}, 413 {}, 414 }; 415 416 static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil, 417 const char *name, 418 struct dentry *parent, u32 off) 419 { 420 struct dentry *d = debugfs_create_dir(name, parent); 421 422 if (IS_ERR_OR_NULL(d)) 423 return -ENODEV; 424 425 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off, 426 isr_off); 427 428 return 0; 429 } 430 431 static const struct dbg_off pseudo_isr_off[] = { 432 {"CAUSE", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32}, 433 {"MASK_SW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32}, 434 {"MASK_FW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32}, 435 {}, 436 }; 437 438 static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil, 439 struct dentry *parent) 440 { 441 struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent); 442 443 if (IS_ERR_OR_NULL(d)) 444 return -ENODEV; 445 446 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr, 447 pseudo_isr_off); 448 449 return 0; 450 } 451 452 static const struct dbg_off lgc_itr_cnt_off[] = { 453 {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32}, 454 {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32}, 455 {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32}, 456 {}, 457 }; 458 459 static const struct dbg_off tx_itr_cnt_off[] = { 460 {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_TRSH), 461 doff_io32}, 462 {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_DATA), 463 doff_io32}, 464 {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_CTL), 465 doff_io32}, 466 {"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_TRSH), 467 doff_io32}, 468 {"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_DATA), 469 doff_io32}, 470 {"IDL_CTL", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_CTL), 471 doff_io32}, 472 {}, 473 }; 474 475 static const struct dbg_off rx_itr_cnt_off[] = { 476 {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_TRSH), 477 doff_io32}, 478 {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_DATA), 479 doff_io32}, 480 {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_CTL), 481 doff_io32}, 482 {"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_TRSH), 483 doff_io32}, 484 {"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_DATA), 485 doff_io32}, 486 {"IDL_CTL", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_CTL), 487 doff_io32}, 488 {}, 489 }; 490 491 static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil, 492 struct dentry *parent) 493 { 494 struct dentry *d, *dtx, *drx; 495 496 d = debugfs_create_dir("ITR_CNT", parent); 497 if (IS_ERR_OR_NULL(d)) 498 return -ENODEV; 499 500 dtx = debugfs_create_dir("TX", d); 501 drx = debugfs_create_dir("RX", d); 502 if (IS_ERR_OR_NULL(dtx) || IS_ERR_OR_NULL(drx)) 503 return -ENODEV; 504 505 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr, 506 lgc_itr_cnt_off); 507 508 wil6210_debugfs_init_offset(wil, dtx, (void * __force)wil->csr, 509 tx_itr_cnt_off); 510 511 wil6210_debugfs_init_offset(wil, drx, (void * __force)wil->csr, 512 rx_itr_cnt_off); 513 return 0; 514 } 515 516 static int wil_memread_debugfs_show(struct seq_file *s, void *data) 517 { 518 struct wil6210_priv *wil = s->private; 519 void __iomem *a; 520 int ret; 521 522 ret = wil_pm_runtime_get(wil); 523 if (ret < 0) 524 return ret; 525 526 a = wmi_buffer(wil, cpu_to_le32(mem_addr)); 527 528 if (a) 529 seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, readl(a)); 530 else 531 seq_printf(s, "[0x%08x] = INVALID\n", mem_addr); 532 533 wil_pm_runtime_put(wil); 534 535 return 0; 536 } 537 538 static int wil_memread_seq_open(struct inode *inode, struct file *file) 539 { 540 return single_open(file, wil_memread_debugfs_show, inode->i_private); 541 } 542 543 static const struct file_operations fops_memread = { 544 .open = wil_memread_seq_open, 545 .release = single_release, 546 .read = seq_read, 547 .llseek = seq_lseek, 548 }; 549 550 static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf, 551 size_t count, loff_t *ppos) 552 { 553 enum { max_count = 4096 }; 554 struct wil_blob_wrapper *wil_blob = file->private_data; 555 struct wil6210_priv *wil = wil_blob->wil; 556 loff_t pos = *ppos; 557 size_t available = wil_blob->blob.size; 558 void *buf; 559 size_t ret; 560 int rc; 561 562 if (test_bit(wil_status_suspending, wil_blob->wil->status) || 563 test_bit(wil_status_suspended, wil_blob->wil->status)) 564 return 0; 565 566 if (pos < 0) 567 return -EINVAL; 568 569 if (pos >= available || !count) 570 return 0; 571 572 if (count > available - pos) 573 count = available - pos; 574 if (count > max_count) 575 count = max_count; 576 577 buf = kmalloc(count, GFP_KERNEL); 578 if (!buf) 579 return -ENOMEM; 580 581 rc = wil_pm_runtime_get(wil); 582 if (rc < 0) { 583 kfree(buf); 584 return rc; 585 } 586 587 wil_memcpy_fromio_32(buf, (const void __iomem *) 588 wil_blob->blob.data + pos, count); 589 590 ret = copy_to_user(user_buf, buf, count); 591 592 wil_pm_runtime_put(wil); 593 594 kfree(buf); 595 if (ret == count) 596 return -EFAULT; 597 598 count -= ret; 599 *ppos = pos + count; 600 601 return count; 602 } 603 604 static const struct file_operations fops_ioblob = { 605 .read = wil_read_file_ioblob, 606 .open = simple_open, 607 .llseek = default_llseek, 608 }; 609 610 static 611 struct dentry *wil_debugfs_create_ioblob(const char *name, 612 umode_t mode, 613 struct dentry *parent, 614 struct wil_blob_wrapper *wil_blob) 615 { 616 return debugfs_create_file(name, mode, parent, wil_blob, &fops_ioblob); 617 } 618 619 /*---reset---*/ 620 static ssize_t wil_write_file_reset(struct file *file, const char __user *buf, 621 size_t len, loff_t *ppos) 622 { 623 struct wil6210_priv *wil = file->private_data; 624 struct net_device *ndev = wil_to_ndev(wil); 625 626 /** 627 * BUG: 628 * this code does NOT sync device state with the rest of system 629 * use with care, debug only!!! 630 */ 631 rtnl_lock(); 632 dev_close(ndev); 633 ndev->flags &= ~IFF_UP; 634 rtnl_unlock(); 635 wil_reset(wil, true); 636 637 return len; 638 } 639 640 static const struct file_operations fops_reset = { 641 .write = wil_write_file_reset, 642 .open = simple_open, 643 }; 644 645 /*---write channel 1..4 to rxon for it, 0 to rxoff---*/ 646 static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf, 647 size_t len, loff_t *ppos) 648 { 649 struct wil6210_priv *wil = file->private_data; 650 int rc; 651 long channel; 652 bool on; 653 654 char *kbuf = memdup_user_nul(buf, len); 655 656 if (IS_ERR(kbuf)) 657 return PTR_ERR(kbuf); 658 rc = kstrtol(kbuf, 0, &channel); 659 kfree(kbuf); 660 if (rc) 661 return rc; 662 663 if ((channel < 0) || (channel > 4)) { 664 wil_err(wil, "Invalid channel %ld\n", channel); 665 return -EINVAL; 666 } 667 on = !!channel; 668 669 if (on) { 670 rc = wmi_set_channel(wil, (int)channel); 671 if (rc) 672 return rc; 673 } 674 675 rc = wmi_rxon(wil, on); 676 if (rc) 677 return rc; 678 679 return len; 680 } 681 682 static const struct file_operations fops_rxon = { 683 .write = wil_write_file_rxon, 684 .open = simple_open, 685 }; 686 687 /* block ack control, write: 688 * - "add <ringid> <agg_size> <timeout>" to trigger ADDBA 689 * - "del_tx <ringid> <reason>" to trigger DELBA for Tx side 690 * - "del_rx <CID> <TID> <reason>" to trigger DELBA for Rx side 691 */ 692 static ssize_t wil_write_back(struct file *file, const char __user *buf, 693 size_t len, loff_t *ppos) 694 { 695 struct wil6210_priv *wil = file->private_data; 696 int rc; 697 char *kbuf = kmalloc(len + 1, GFP_KERNEL); 698 char cmd[9]; 699 int p1, p2, p3; 700 701 if (!kbuf) 702 return -ENOMEM; 703 704 rc = simple_write_to_buffer(kbuf, len, ppos, buf, len); 705 if (rc != len) { 706 kfree(kbuf); 707 return rc >= 0 ? -EIO : rc; 708 } 709 710 kbuf[len] = '\0'; 711 rc = sscanf(kbuf, "%8s %d %d %d", cmd, &p1, &p2, &p3); 712 kfree(kbuf); 713 714 if (rc < 0) 715 return rc; 716 if (rc < 2) 717 return -EINVAL; 718 719 if (0 == strcmp(cmd, "add")) { 720 if (rc < 3) { 721 wil_err(wil, "BACK: add require at least 2 params\n"); 722 return -EINVAL; 723 } 724 if (rc < 4) 725 p3 = 0; 726 wmi_addba(wil, p1, p2, p3); 727 } else if (0 == strcmp(cmd, "del_tx")) { 728 if (rc < 3) 729 p2 = WLAN_REASON_QSTA_LEAVE_QBSS; 730 wmi_delba_tx(wil, p1, p2); 731 } else if (0 == strcmp(cmd, "del_rx")) { 732 if (rc < 3) { 733 wil_err(wil, 734 "BACK: del_rx require at least 2 params\n"); 735 return -EINVAL; 736 } 737 if (rc < 4) 738 p3 = WLAN_REASON_QSTA_LEAVE_QBSS; 739 wmi_delba_rx(wil, mk_cidxtid(p1, p2), p3); 740 } else { 741 wil_err(wil, "BACK: Unrecognized command \"%s\"\n", cmd); 742 return -EINVAL; 743 } 744 745 return len; 746 } 747 748 static ssize_t wil_read_back(struct file *file, char __user *user_buf, 749 size_t count, loff_t *ppos) 750 { 751 static const char text[] = "block ack control, write:\n" 752 " - \"add <ringid> <agg_size> <timeout>\" to trigger ADDBA\n" 753 "If missing, <timeout> defaults to 0\n" 754 " - \"del_tx <ringid> <reason>\" to trigger DELBA for Tx side\n" 755 " - \"del_rx <CID> <TID> <reason>\" to trigger DELBA for Rx side\n" 756 "If missing, <reason> set to \"STA_LEAVING\" (36)\n"; 757 758 return simple_read_from_buffer(user_buf, count, ppos, text, 759 sizeof(text)); 760 } 761 762 static const struct file_operations fops_back = { 763 .read = wil_read_back, 764 .write = wil_write_back, 765 .open = simple_open, 766 }; 767 768 /* pmc control, write: 769 * - "alloc <num descriptors> <descriptor_size>" to allocate PMC 770 * - "free" to release memory allocated for PMC 771 */ 772 static ssize_t wil_write_pmccfg(struct file *file, const char __user *buf, 773 size_t len, loff_t *ppos) 774 { 775 struct wil6210_priv *wil = file->private_data; 776 int rc; 777 char *kbuf = kmalloc(len + 1, GFP_KERNEL); 778 char cmd[9]; 779 int num_descs, desc_size; 780 781 if (!kbuf) 782 return -ENOMEM; 783 784 rc = simple_write_to_buffer(kbuf, len, ppos, buf, len); 785 if (rc != len) { 786 kfree(kbuf); 787 return rc >= 0 ? -EIO : rc; 788 } 789 790 kbuf[len] = '\0'; 791 rc = sscanf(kbuf, "%8s %d %d", cmd, &num_descs, &desc_size); 792 kfree(kbuf); 793 794 if (rc < 0) 795 return rc; 796 797 if (rc < 1) { 798 wil_err(wil, "pmccfg: no params given\n"); 799 return -EINVAL; 800 } 801 802 if (0 == strcmp(cmd, "alloc")) { 803 if (rc != 3) { 804 wil_err(wil, "pmccfg: alloc requires 2 params\n"); 805 return -EINVAL; 806 } 807 wil_pmc_alloc(wil, num_descs, desc_size); 808 } else if (0 == strcmp(cmd, "free")) { 809 if (rc != 1) { 810 wil_err(wil, "pmccfg: free does not have any params\n"); 811 return -EINVAL; 812 } 813 wil_pmc_free(wil, true); 814 } else { 815 wil_err(wil, "pmccfg: Unrecognized command \"%s\"\n", cmd); 816 return -EINVAL; 817 } 818 819 return len; 820 } 821 822 static ssize_t wil_read_pmccfg(struct file *file, char __user *user_buf, 823 size_t count, loff_t *ppos) 824 { 825 struct wil6210_priv *wil = file->private_data; 826 char text[256]; 827 char help[] = "pmc control, write:\n" 828 " - \"alloc <num descriptors> <descriptor_size>\" to allocate pmc\n" 829 " - \"free\" to free memory allocated for pmc\n"; 830 831 sprintf(text, "Last command status: %d\n\n%s", 832 wil_pmc_last_cmd_status(wil), 833 help); 834 835 return simple_read_from_buffer(user_buf, count, ppos, text, 836 strlen(text) + 1); 837 } 838 839 static const struct file_operations fops_pmccfg = { 840 .read = wil_read_pmccfg, 841 .write = wil_write_pmccfg, 842 .open = simple_open, 843 }; 844 845 static const struct file_operations fops_pmcdata = { 846 .open = simple_open, 847 .read = wil_pmc_read, 848 .llseek = wil_pmc_llseek, 849 }; 850 851 /*---tx_mgmt---*/ 852 /* Write mgmt frame to this file to send it */ 853 static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf, 854 size_t len, loff_t *ppos) 855 { 856 struct wil6210_priv *wil = file->private_data; 857 struct wiphy *wiphy = wil_to_wiphy(wil); 858 struct wireless_dev *wdev = wil_to_wdev(wil); 859 struct cfg80211_mgmt_tx_params params; 860 int rc; 861 void *frame; 862 863 if (!len) 864 return -EINVAL; 865 866 frame = memdup_user(buf, len); 867 if (IS_ERR(frame)) 868 return PTR_ERR(frame); 869 870 params.buf = frame; 871 params.len = len; 872 params.chan = wdev->preset_chandef.chan; 873 874 rc = wil_cfg80211_mgmt_tx(wiphy, wdev, ¶ms, NULL); 875 876 kfree(frame); 877 wil_info(wil, "-> %d\n", rc); 878 879 return len; 880 } 881 882 static const struct file_operations fops_txmgmt = { 883 .write = wil_write_file_txmgmt, 884 .open = simple_open, 885 }; 886 887 /* Write WMI command (w/o mbox header) to this file to send it 888 * WMI starts from wil6210_mbox_hdr_wmi header 889 */ 890 static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf, 891 size_t len, loff_t *ppos) 892 { 893 struct wil6210_priv *wil = file->private_data; 894 struct wmi_cmd_hdr *wmi; 895 void *cmd; 896 int cmdlen = len - sizeof(struct wmi_cmd_hdr); 897 u16 cmdid; 898 int rc, rc1; 899 900 if (cmdlen < 0) 901 return -EINVAL; 902 903 wmi = kmalloc(len, GFP_KERNEL); 904 if (!wmi) 905 return -ENOMEM; 906 907 rc = simple_write_to_buffer(wmi, len, ppos, buf, len); 908 if (rc < 0) { 909 kfree(wmi); 910 return rc; 911 } 912 913 cmd = (cmdlen > 0) ? &wmi[1] : NULL; 914 cmdid = le16_to_cpu(wmi->command_id); 915 916 rc1 = wmi_send(wil, cmdid, cmd, cmdlen); 917 kfree(wmi); 918 919 wil_info(wil, "0x%04x[%d] -> %d\n", cmdid, cmdlen, rc1); 920 921 return rc; 922 } 923 924 static const struct file_operations fops_wmi = { 925 .write = wil_write_file_wmi, 926 .open = simple_open, 927 }; 928 929 static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb) 930 { 931 int i = 0; 932 int len = skb_headlen(skb); 933 void *p = skb->data; 934 int nr_frags = skb_shinfo(skb)->nr_frags; 935 936 seq_printf(s, " len = %d\n", len); 937 wil_seq_hexdump(s, p, len, " : "); 938 939 if (nr_frags) { 940 seq_printf(s, " nr_frags = %d\n", nr_frags); 941 for (i = 0; i < nr_frags; i++) { 942 const struct skb_frag_struct *frag = 943 &skb_shinfo(skb)->frags[i]; 944 945 len = skb_frag_size(frag); 946 p = skb_frag_address_safe(frag); 947 seq_printf(s, " [%2d] : len = %d\n", i, len); 948 wil_seq_hexdump(s, p, len, " : "); 949 } 950 } 951 } 952 953 /*---------Tx/Rx descriptor------------*/ 954 static int wil_txdesc_debugfs_show(struct seq_file *s, void *data) 955 { 956 struct wil6210_priv *wil = s->private; 957 struct vring *vring; 958 bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS); 959 960 vring = tx ? &wil->vring_tx[dbg_vring_index] : &wil->vring_rx; 961 962 if (!vring->va) { 963 if (tx) 964 seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index); 965 else 966 seq_puts(s, "No Rx VRING\n"); 967 return 0; 968 } 969 970 if (dbg_txdesc_index < vring->size) { 971 /* use struct vring_tx_desc for Rx as well, 972 * only field used, .dma.length, is the same 973 */ 974 volatile struct vring_tx_desc *d = 975 &vring->va[dbg_txdesc_index].tx; 976 volatile u32 *u = (volatile u32 *)d; 977 struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb; 978 979 if (tx) 980 seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index, 981 dbg_txdesc_index); 982 else 983 seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index); 984 seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n", 985 u[0], u[1], u[2], u[3]); 986 seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n", 987 u[4], u[5], u[6], u[7]); 988 seq_printf(s, " SKB = 0x%p\n", skb); 989 990 if (skb) { 991 skb_get(skb); 992 wil_seq_print_skb(s, skb); 993 kfree_skb(skb); 994 } 995 seq_puts(s, "}\n"); 996 } else { 997 if (tx) 998 seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n", 999 dbg_vring_index, dbg_txdesc_index, 1000 vring->size); 1001 else 1002 seq_printf(s, "RxDesc index (%d) >= size (%d)\n", 1003 dbg_txdesc_index, vring->size); 1004 } 1005 1006 return 0; 1007 } 1008 1009 static int wil_txdesc_seq_open(struct inode *inode, struct file *file) 1010 { 1011 return single_open(file, wil_txdesc_debugfs_show, inode->i_private); 1012 } 1013 1014 static const struct file_operations fops_txdesc = { 1015 .open = wil_txdesc_seq_open, 1016 .release = single_release, 1017 .read = seq_read, 1018 .llseek = seq_lseek, 1019 }; 1020 1021 /*---------beamforming------------*/ 1022 static char *wil_bfstatus_str(u32 status) 1023 { 1024 switch (status) { 1025 case 0: 1026 return "Failed"; 1027 case 1: 1028 return "OK"; 1029 case 2: 1030 return "Retrying"; 1031 default: 1032 return "??"; 1033 } 1034 } 1035 1036 static bool is_all_zeros(void * const x_, size_t sz) 1037 { 1038 /* if reply is all-0, ignore this CID */ 1039 u32 *x = x_; 1040 int n; 1041 1042 for (n = 0; n < sz / sizeof(*x); n++) 1043 if (x[n]) 1044 return false; 1045 1046 return true; 1047 } 1048 1049 static int wil_bf_debugfs_show(struct seq_file *s, void *data) 1050 { 1051 int rc; 1052 int i; 1053 struct wil6210_priv *wil = s->private; 1054 struct wmi_notify_req_cmd cmd = { 1055 .interval_usec = 0, 1056 }; 1057 struct { 1058 struct wmi_cmd_hdr wmi; 1059 struct wmi_notify_req_done_event evt; 1060 } __packed reply; 1061 1062 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) { 1063 u32 status; 1064 1065 cmd.cid = i; 1066 rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd), 1067 WMI_NOTIFY_REQ_DONE_EVENTID, &reply, 1068 sizeof(reply), 20); 1069 /* if reply is all-0, ignore this CID */ 1070 if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt))) 1071 continue; 1072 1073 status = le32_to_cpu(reply.evt.status); 1074 seq_printf(s, "CID %d {\n" 1075 " TSF = 0x%016llx\n" 1076 " TxMCS = %2d TxTpt = %4d\n" 1077 " SQI = %4d\n" 1078 " RSSI = %4d\n" 1079 " Status = 0x%08x %s\n" 1080 " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n" 1081 " Goodput(rx:tx) %4d:%4d\n" 1082 "}\n", 1083 i, 1084 le64_to_cpu(reply.evt.tsf), 1085 le16_to_cpu(reply.evt.bf_mcs), 1086 le32_to_cpu(reply.evt.tx_tpt), 1087 reply.evt.sqi, 1088 reply.evt.rssi, 1089 status, wil_bfstatus_str(status), 1090 le16_to_cpu(reply.evt.my_rx_sector), 1091 le16_to_cpu(reply.evt.my_tx_sector), 1092 le16_to_cpu(reply.evt.other_rx_sector), 1093 le16_to_cpu(reply.evt.other_tx_sector), 1094 le32_to_cpu(reply.evt.rx_goodput), 1095 le32_to_cpu(reply.evt.tx_goodput)); 1096 } 1097 return 0; 1098 } 1099 1100 static int wil_bf_seq_open(struct inode *inode, struct file *file) 1101 { 1102 return single_open(file, wil_bf_debugfs_show, inode->i_private); 1103 } 1104 1105 static const struct file_operations fops_bf = { 1106 .open = wil_bf_seq_open, 1107 .release = single_release, 1108 .read = seq_read, 1109 .llseek = seq_lseek, 1110 }; 1111 1112 /*---------temp------------*/ 1113 static void print_temp(struct seq_file *s, const char *prefix, u32 t) 1114 { 1115 switch (t) { 1116 case 0: 1117 case ~(u32)0: 1118 seq_printf(s, "%s N/A\n", prefix); 1119 break; 1120 default: 1121 seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000); 1122 break; 1123 } 1124 } 1125 1126 static int wil_temp_debugfs_show(struct seq_file *s, void *data) 1127 { 1128 struct wil6210_priv *wil = s->private; 1129 u32 t_m, t_r; 1130 int rc = wmi_get_temperature(wil, &t_m, &t_r); 1131 1132 if (rc) { 1133 seq_puts(s, "Failed\n"); 1134 return 0; 1135 } 1136 1137 print_temp(s, "T_mac =", t_m); 1138 print_temp(s, "T_radio =", t_r); 1139 1140 return 0; 1141 } 1142 1143 static int wil_temp_seq_open(struct inode *inode, struct file *file) 1144 { 1145 return single_open(file, wil_temp_debugfs_show, inode->i_private); 1146 } 1147 1148 static const struct file_operations fops_temp = { 1149 .open = wil_temp_seq_open, 1150 .release = single_release, 1151 .read = seq_read, 1152 .llseek = seq_lseek, 1153 }; 1154 1155 /*---------freq------------*/ 1156 static int wil_freq_debugfs_show(struct seq_file *s, void *data) 1157 { 1158 struct wil6210_priv *wil = s->private; 1159 struct wireless_dev *wdev = wil_to_wdev(wil); 1160 u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0; 1161 1162 seq_printf(s, "Freq = %d\n", freq); 1163 1164 return 0; 1165 } 1166 1167 static int wil_freq_seq_open(struct inode *inode, struct file *file) 1168 { 1169 return single_open(file, wil_freq_debugfs_show, inode->i_private); 1170 } 1171 1172 static const struct file_operations fops_freq = { 1173 .open = wil_freq_seq_open, 1174 .release = single_release, 1175 .read = seq_read, 1176 .llseek = seq_lseek, 1177 }; 1178 1179 /*---------link------------*/ 1180 static int wil_link_debugfs_show(struct seq_file *s, void *data) 1181 { 1182 struct wil6210_priv *wil = s->private; 1183 struct station_info sinfo; 1184 int i, rc; 1185 1186 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) { 1187 struct wil_sta_info *p = &wil->sta[i]; 1188 char *status = "unknown"; 1189 1190 switch (p->status) { 1191 case wil_sta_unused: 1192 status = "unused "; 1193 break; 1194 case wil_sta_conn_pending: 1195 status = "pending "; 1196 break; 1197 case wil_sta_connected: 1198 status = "connected"; 1199 break; 1200 } 1201 seq_printf(s, "[%d] %pM %s\n", i, p->addr, status); 1202 1203 if (p->status == wil_sta_connected) { 1204 rc = wil_cid_fill_sinfo(wil, i, &sinfo); 1205 if (rc) 1206 return rc; 1207 1208 seq_printf(s, " Tx_mcs = %d\n", sinfo.txrate.mcs); 1209 seq_printf(s, " Rx_mcs = %d\n", sinfo.rxrate.mcs); 1210 seq_printf(s, " SQ = %d\n", sinfo.signal); 1211 } 1212 } 1213 1214 return 0; 1215 } 1216 1217 static int wil_link_seq_open(struct inode *inode, struct file *file) 1218 { 1219 return single_open(file, wil_link_debugfs_show, inode->i_private); 1220 } 1221 1222 static const struct file_operations fops_link = { 1223 .open = wil_link_seq_open, 1224 .release = single_release, 1225 .read = seq_read, 1226 .llseek = seq_lseek, 1227 }; 1228 1229 /*---------info------------*/ 1230 static int wil_info_debugfs_show(struct seq_file *s, void *data) 1231 { 1232 struct wil6210_priv *wil = s->private; 1233 struct net_device *ndev = wil_to_ndev(wil); 1234 int is_ac = power_supply_is_system_supplied(); 1235 int rx = atomic_xchg(&wil->isr_count_rx, 0); 1236 int tx = atomic_xchg(&wil->isr_count_tx, 0); 1237 static ulong rxf_old, txf_old; 1238 ulong rxf = ndev->stats.rx_packets; 1239 ulong txf = ndev->stats.tx_packets; 1240 unsigned int i; 1241 1242 /* >0 : AC; 0 : battery; <0 : error */ 1243 seq_printf(s, "AC powered : %d\n", is_ac); 1244 seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old); 1245 seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old); 1246 rxf_old = rxf; 1247 txf_old = txf; 1248 1249 #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \ 1250 " " __stringify(x) : "" 1251 1252 for (i = 0; i < ndev->num_tx_queues; i++) { 1253 struct netdev_queue *txq = netdev_get_tx_queue(ndev, i); 1254 unsigned long state = txq->state; 1255 1256 seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state, 1257 CHECK_QSTATE(DRV_XOFF), 1258 CHECK_QSTATE(STACK_XOFF), 1259 CHECK_QSTATE(FROZEN) 1260 ); 1261 } 1262 #undef CHECK_QSTATE 1263 return 0; 1264 } 1265 1266 static int wil_info_seq_open(struct inode *inode, struct file *file) 1267 { 1268 return single_open(file, wil_info_debugfs_show, inode->i_private); 1269 } 1270 1271 static const struct file_operations fops_info = { 1272 .open = wil_info_seq_open, 1273 .release = single_release, 1274 .read = seq_read, 1275 .llseek = seq_lseek, 1276 }; 1277 1278 /*---------recovery------------*/ 1279 /* mode = [manual|auto] 1280 * state = [idle|pending|running] 1281 */ 1282 static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf, 1283 size_t count, loff_t *ppos) 1284 { 1285 struct wil6210_priv *wil = file->private_data; 1286 char buf[80]; 1287 int n; 1288 static const char * const sstate[] = {"idle", "pending", "running"}; 1289 1290 n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n", 1291 no_fw_recovery ? "manual" : "auto", 1292 sstate[wil->recovery_state]); 1293 1294 n = min_t(int, n, sizeof(buf)); 1295 1296 return simple_read_from_buffer(user_buf, count, ppos, 1297 buf, n); 1298 } 1299 1300 static ssize_t wil_write_file_recovery(struct file *file, 1301 const char __user *buf_, 1302 size_t count, loff_t *ppos) 1303 { 1304 struct wil6210_priv *wil = file->private_data; 1305 static const char run_command[] = "run"; 1306 char buf[sizeof(run_command) + 1]; /* to detect "runx" */ 1307 ssize_t rc; 1308 1309 if (wil->recovery_state != fw_recovery_pending) { 1310 wil_err(wil, "No recovery pending\n"); 1311 return -EINVAL; 1312 } 1313 1314 if (*ppos != 0) { 1315 wil_err(wil, "Offset [%d]\n", (int)*ppos); 1316 return -EINVAL; 1317 } 1318 1319 if (count > sizeof(buf)) { 1320 wil_err(wil, "Input too long, len = %d\n", (int)count); 1321 return -EINVAL; 1322 } 1323 1324 rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count); 1325 if (rc < 0) 1326 return rc; 1327 1328 buf[rc] = '\0'; 1329 if (0 == strcmp(buf, run_command)) 1330 wil_set_recovery_state(wil, fw_recovery_running); 1331 else 1332 wil_err(wil, "Bad recovery command \"%s\"\n", buf); 1333 1334 return rc; 1335 } 1336 1337 static const struct file_operations fops_recovery = { 1338 .read = wil_read_file_recovery, 1339 .write = wil_write_file_recovery, 1340 .open = simple_open, 1341 }; 1342 1343 /*---------Station matrix------------*/ 1344 static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r) 1345 { 1346 int i; 1347 u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size; 1348 unsigned long long drop_dup = r->drop_dup, drop_old = r->drop_old; 1349 1350 seq_printf(s, "([%2d] %3d TU) 0x%03x [", r->buf_size, r->timeout, 1351 r->head_seq_num); 1352 for (i = 0; i < r->buf_size; i++) { 1353 if (i == index) 1354 seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|'); 1355 else 1356 seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_'); 1357 } 1358 seq_printf(s, 1359 "] total %llu drop %llu (dup %llu + old %llu) last 0x%03x\n", 1360 r->total, drop_dup + drop_old, drop_dup, drop_old, 1361 r->ssn_last_drop); 1362 } 1363 1364 static void wil_print_rxtid_crypto(struct seq_file *s, int tid, 1365 struct wil_tid_crypto_rx *c) 1366 { 1367 int i; 1368 1369 for (i = 0; i < 4; i++) { 1370 struct wil_tid_crypto_rx_single *cc = &c->key_id[i]; 1371 1372 if (cc->key_set) 1373 goto has_keys; 1374 } 1375 return; 1376 1377 has_keys: 1378 if (tid < WIL_STA_TID_NUM) 1379 seq_printf(s, " [%2d] PN", tid); 1380 else 1381 seq_puts(s, " [GR] PN"); 1382 1383 for (i = 0; i < 4; i++) { 1384 struct wil_tid_crypto_rx_single *cc = &c->key_id[i]; 1385 1386 seq_printf(s, " [%i%s]%6phN", i, cc->key_set ? "+" : "-", 1387 cc->pn); 1388 } 1389 seq_puts(s, "\n"); 1390 } 1391 1392 static int wil_sta_debugfs_show(struct seq_file *s, void *data) 1393 __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock) 1394 { 1395 struct wil6210_priv *wil = s->private; 1396 int i, tid, mcs; 1397 1398 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) { 1399 struct wil_sta_info *p = &wil->sta[i]; 1400 char *status = "unknown"; 1401 u8 aid = 0; 1402 1403 switch (p->status) { 1404 case wil_sta_unused: 1405 status = "unused "; 1406 break; 1407 case wil_sta_conn_pending: 1408 status = "pending "; 1409 break; 1410 case wil_sta_connected: 1411 status = "connected"; 1412 aid = p->aid; 1413 break; 1414 } 1415 seq_printf(s, "[%d] %pM %s AID %d\n", i, p->addr, status, aid); 1416 1417 if (p->status == wil_sta_connected) { 1418 spin_lock_bh(&p->tid_rx_lock); 1419 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) { 1420 struct wil_tid_ampdu_rx *r = p->tid_rx[tid]; 1421 struct wil_tid_crypto_rx *c = 1422 &p->tid_crypto_rx[tid]; 1423 1424 if (r) { 1425 seq_printf(s, " [%2d] ", tid); 1426 wil_print_rxtid(s, r); 1427 } 1428 1429 wil_print_rxtid_crypto(s, tid, c); 1430 } 1431 wil_print_rxtid_crypto(s, WIL_STA_TID_NUM, 1432 &p->group_crypto_rx); 1433 spin_unlock_bh(&p->tid_rx_lock); 1434 seq_printf(s, 1435 "Rx invalid frame: non-data %lu, short %lu, large %lu, replay %lu\n", 1436 p->stats.rx_non_data_frame, 1437 p->stats.rx_short_frame, 1438 p->stats.rx_large_frame, 1439 p->stats.rx_replay); 1440 1441 seq_puts(s, "Rx/MCS:"); 1442 for (mcs = 0; mcs < ARRAY_SIZE(p->stats.rx_per_mcs); 1443 mcs++) 1444 seq_printf(s, " %lld", 1445 p->stats.rx_per_mcs[mcs]); 1446 seq_puts(s, "\n"); 1447 } 1448 } 1449 1450 return 0; 1451 } 1452 1453 static int wil_sta_seq_open(struct inode *inode, struct file *file) 1454 { 1455 return single_open(file, wil_sta_debugfs_show, inode->i_private); 1456 } 1457 1458 static const struct file_operations fops_sta = { 1459 .open = wil_sta_seq_open, 1460 .release = single_release, 1461 .read = seq_read, 1462 .llseek = seq_lseek, 1463 }; 1464 1465 static ssize_t wil_read_file_led_cfg(struct file *file, char __user *user_buf, 1466 size_t count, loff_t *ppos) 1467 { 1468 char buf[80]; 1469 int n; 1470 1471 n = snprintf(buf, sizeof(buf), 1472 "led_id is set to %d, echo 1 to enable, 0 to disable\n", 1473 led_id); 1474 1475 n = min_t(int, n, sizeof(buf)); 1476 1477 return simple_read_from_buffer(user_buf, count, ppos, 1478 buf, n); 1479 } 1480 1481 static ssize_t wil_write_file_led_cfg(struct file *file, 1482 const char __user *buf_, 1483 size_t count, loff_t *ppos) 1484 { 1485 struct wil6210_priv *wil = file->private_data; 1486 int val; 1487 int rc; 1488 1489 rc = kstrtoint_from_user(buf_, count, 0, &val); 1490 if (rc) { 1491 wil_err(wil, "Invalid argument\n"); 1492 return rc; 1493 } 1494 1495 wil_info(wil, "%s led %d\n", val ? "Enabling" : "Disabling", led_id); 1496 rc = wmi_led_cfg(wil, val); 1497 if (rc) { 1498 wil_info(wil, "%s led %d failed\n", 1499 val ? "Enabling" : "Disabling", led_id); 1500 return rc; 1501 } 1502 1503 return count; 1504 } 1505 1506 static const struct file_operations fops_led_cfg = { 1507 .read = wil_read_file_led_cfg, 1508 .write = wil_write_file_led_cfg, 1509 .open = simple_open, 1510 }; 1511 1512 /* led_blink_time, write: 1513 * "<blink_on_slow> <blink_off_slow> <blink_on_med> <blink_off_med> <blink_on_fast> <blink_off_fast> 1514 */ 1515 static ssize_t wil_write_led_blink_time(struct file *file, 1516 const char __user *buf, 1517 size_t len, loff_t *ppos) 1518 { 1519 int rc; 1520 char *kbuf = kmalloc(len + 1, GFP_KERNEL); 1521 1522 if (!kbuf) 1523 return -ENOMEM; 1524 1525 rc = simple_write_to_buffer(kbuf, len, ppos, buf, len); 1526 if (rc != len) { 1527 kfree(kbuf); 1528 return rc >= 0 ? -EIO : rc; 1529 } 1530 1531 kbuf[len] = '\0'; 1532 rc = sscanf(kbuf, "%d %d %d %d %d %d", 1533 &led_blink_time[WIL_LED_TIME_SLOW].on_ms, 1534 &led_blink_time[WIL_LED_TIME_SLOW].off_ms, 1535 &led_blink_time[WIL_LED_TIME_MED].on_ms, 1536 &led_blink_time[WIL_LED_TIME_MED].off_ms, 1537 &led_blink_time[WIL_LED_TIME_FAST].on_ms, 1538 &led_blink_time[WIL_LED_TIME_FAST].off_ms); 1539 kfree(kbuf); 1540 1541 if (rc < 0) 1542 return rc; 1543 if (rc < 6) 1544 return -EINVAL; 1545 1546 return len; 1547 } 1548 1549 static ssize_t wil_read_led_blink_time(struct file *file, char __user *user_buf, 1550 size_t count, loff_t *ppos) 1551 { 1552 static char text[400]; 1553 1554 snprintf(text, sizeof(text), 1555 "To set led blink on/off time variables write:\n" 1556 "<blink_on_slow> <blink_off_slow> <blink_on_med> " 1557 "<blink_off_med> <blink_on_fast> <blink_off_fast>\n" 1558 "The current values are:\n" 1559 "%d %d %d %d %d %d\n", 1560 led_blink_time[WIL_LED_TIME_SLOW].on_ms, 1561 led_blink_time[WIL_LED_TIME_SLOW].off_ms, 1562 led_blink_time[WIL_LED_TIME_MED].on_ms, 1563 led_blink_time[WIL_LED_TIME_MED].off_ms, 1564 led_blink_time[WIL_LED_TIME_FAST].on_ms, 1565 led_blink_time[WIL_LED_TIME_FAST].off_ms); 1566 1567 return simple_read_from_buffer(user_buf, count, ppos, text, 1568 sizeof(text)); 1569 } 1570 1571 static const struct file_operations fops_led_blink_time = { 1572 .read = wil_read_led_blink_time, 1573 .write = wil_write_led_blink_time, 1574 .open = simple_open, 1575 }; 1576 1577 /*---------FW capabilities------------*/ 1578 static int wil_fw_capabilities_debugfs_show(struct seq_file *s, void *data) 1579 { 1580 struct wil6210_priv *wil = s->private; 1581 1582 seq_printf(s, "fw_capabilities : %*pb\n", WMI_FW_CAPABILITY_MAX, 1583 wil->fw_capabilities); 1584 1585 return 0; 1586 } 1587 1588 static int wil_fw_capabilities_seq_open(struct inode *inode, struct file *file) 1589 { 1590 return single_open(file, wil_fw_capabilities_debugfs_show, 1591 inode->i_private); 1592 } 1593 1594 static const struct file_operations fops_fw_capabilities = { 1595 .open = wil_fw_capabilities_seq_open, 1596 .release = single_release, 1597 .read = seq_read, 1598 .llseek = seq_lseek, 1599 }; 1600 1601 /*---------FW version------------*/ 1602 static int wil_fw_version_debugfs_show(struct seq_file *s, void *data) 1603 { 1604 struct wil6210_priv *wil = s->private; 1605 1606 if (wil->fw_version[0]) 1607 seq_printf(s, "%s\n", wil->fw_version); 1608 else 1609 seq_puts(s, "N/A\n"); 1610 1611 return 0; 1612 } 1613 1614 static int wil_fw_version_seq_open(struct inode *inode, struct file *file) 1615 { 1616 return single_open(file, wil_fw_version_debugfs_show, 1617 inode->i_private); 1618 } 1619 1620 static const struct file_operations fops_fw_version = { 1621 .open = wil_fw_version_seq_open, 1622 .release = single_release, 1623 .read = seq_read, 1624 .llseek = seq_lseek, 1625 }; 1626 1627 /*---------suspend_stats---------*/ 1628 static ssize_t wil_write_suspend_stats(struct file *file, 1629 const char __user *buf, 1630 size_t len, loff_t *ppos) 1631 { 1632 struct wil6210_priv *wil = file->private_data; 1633 1634 memset(&wil->suspend_stats, 0, sizeof(wil->suspend_stats)); 1635 1636 return len; 1637 } 1638 1639 static ssize_t wil_read_suspend_stats(struct file *file, 1640 char __user *user_buf, 1641 size_t count, loff_t *ppos) 1642 { 1643 struct wil6210_priv *wil = file->private_data; 1644 char *text; 1645 int n, ret, text_size = 500; 1646 1647 text = kmalloc(text_size, GFP_KERNEL); 1648 if (!text) 1649 return -ENOMEM; 1650 1651 n = snprintf(text, text_size, 1652 "Radio on suspend statistics:\n" 1653 "successful suspends:%ld failed suspends:%ld\n" 1654 "successful resumes:%ld failed resumes:%ld\n" 1655 "rejected by device:%ld\n" 1656 "Radio off suspend statistics:\n" 1657 "successful suspends:%ld failed suspends:%ld\n" 1658 "successful resumes:%ld failed resumes:%ld\n" 1659 "General statistics:\n" 1660 "rejected by host:%ld\n", 1661 wil->suspend_stats.r_on.successful_suspends, 1662 wil->suspend_stats.r_on.failed_suspends, 1663 wil->suspend_stats.r_on.successful_resumes, 1664 wil->suspend_stats.r_on.failed_resumes, 1665 wil->suspend_stats.rejected_by_device, 1666 wil->suspend_stats.r_off.successful_suspends, 1667 wil->suspend_stats.r_off.failed_suspends, 1668 wil->suspend_stats.r_off.successful_resumes, 1669 wil->suspend_stats.r_off.failed_resumes, 1670 wil->suspend_stats.rejected_by_host); 1671 1672 n = min_t(int, n, text_size); 1673 1674 ret = simple_read_from_buffer(user_buf, count, ppos, text, n); 1675 1676 kfree(text); 1677 1678 return ret; 1679 } 1680 1681 static const struct file_operations fops_suspend_stats = { 1682 .read = wil_read_suspend_stats, 1683 .write = wil_write_suspend_stats, 1684 .open = simple_open, 1685 }; 1686 1687 /*----------------*/ 1688 static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil, 1689 struct dentry *dbg) 1690 { 1691 int i; 1692 char name[32]; 1693 1694 for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) { 1695 struct wil_blob_wrapper *wil_blob = &wil->blobs[i]; 1696 struct debugfs_blob_wrapper *blob = &wil_blob->blob; 1697 const struct fw_map *map = &fw_mapping[i]; 1698 1699 if (!map->name) 1700 continue; 1701 1702 wil_blob->wil = wil; 1703 blob->data = (void * __force)wil->csr + HOSTADDR(map->host); 1704 blob->size = map->to - map->from; 1705 snprintf(name, sizeof(name), "blob_%s", map->name); 1706 wil_debugfs_create_ioblob(name, 0444, dbg, wil_blob); 1707 } 1708 } 1709 1710 /* misc files */ 1711 static const struct { 1712 const char *name; 1713 umode_t mode; 1714 const struct file_operations *fops; 1715 } dbg_files[] = { 1716 {"mbox", 0444, &fops_mbox}, 1717 {"vrings", 0444, &fops_vring}, 1718 {"stations", 0444, &fops_sta}, 1719 {"desc", 0444, &fops_txdesc}, 1720 {"bf", 0444, &fops_bf}, 1721 {"mem_val", 0644, &fops_memread}, 1722 {"reset", 0244, &fops_reset}, 1723 {"rxon", 0244, &fops_rxon}, 1724 {"tx_mgmt", 0244, &fops_txmgmt}, 1725 {"wmi_send", 0244, &fops_wmi}, 1726 {"back", 0644, &fops_back}, 1727 {"pmccfg", 0644, &fops_pmccfg}, 1728 {"pmcdata", 0444, &fops_pmcdata}, 1729 {"temp", 0444, &fops_temp}, 1730 {"freq", 0444, &fops_freq}, 1731 {"link", 0444, &fops_link}, 1732 {"info", 0444, &fops_info}, 1733 {"recovery", 0644, &fops_recovery}, 1734 {"led_cfg", 0644, &fops_led_cfg}, 1735 {"led_blink_time", 0644, &fops_led_blink_time}, 1736 {"fw_capabilities", 0444, &fops_fw_capabilities}, 1737 {"fw_version", 0444, &fops_fw_version}, 1738 {"suspend_stats", 0644, &fops_suspend_stats}, 1739 }; 1740 1741 static void wil6210_debugfs_init_files(struct wil6210_priv *wil, 1742 struct dentry *dbg) 1743 { 1744 int i; 1745 1746 for (i = 0; i < ARRAY_SIZE(dbg_files); i++) 1747 debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg, 1748 wil, dbg_files[i].fops); 1749 } 1750 1751 /* interrupt control blocks */ 1752 static const struct { 1753 const char *name; 1754 u32 icr_off; 1755 } dbg_icr[] = { 1756 {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)}, 1757 {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)}, 1758 {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)}, 1759 {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)}, 1760 }; 1761 1762 static void wil6210_debugfs_init_isr(struct wil6210_priv *wil, 1763 struct dentry *dbg) 1764 { 1765 int i; 1766 1767 for (i = 0; i < ARRAY_SIZE(dbg_icr); i++) 1768 wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg, 1769 dbg_icr[i].icr_off); 1770 } 1771 1772 #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \ 1773 offsetof(struct wil6210_priv, name), type} 1774 1775 /* fields in struct wil6210_priv */ 1776 static const struct dbg_off dbg_wil_off[] = { 1777 WIL_FIELD(privacy, 0444, doff_u32), 1778 WIL_FIELD(status[0], 0644, doff_ulong), 1779 WIL_FIELD(hw_version, 0444, doff_x32), 1780 WIL_FIELD(recovery_count, 0444, doff_u32), 1781 WIL_FIELD(ap_isolate, 0444, doff_u32), 1782 WIL_FIELD(discovery_mode, 0644, doff_u8), 1783 WIL_FIELD(chip_revision, 0444, doff_u8), 1784 WIL_FIELD(abft_len, 0644, doff_u8), 1785 WIL_FIELD(wakeup_trigger, 0644, doff_u8), 1786 WIL_FIELD(vring_idle_trsh, 0644, doff_u32), 1787 {}, 1788 }; 1789 1790 static const struct dbg_off dbg_wil_regs[] = { 1791 {"RGF_MAC_MTRL_COUNTER_0", 0444, HOSTADDR(RGF_MAC_MTRL_COUNTER_0), 1792 doff_io32}, 1793 {"RGF_USER_USAGE_1", 0444, HOSTADDR(RGF_USER_USAGE_1), doff_io32}, 1794 {}, 1795 }; 1796 1797 /* static parameters */ 1798 static const struct dbg_off dbg_statics[] = { 1799 {"desc_index", 0644, (ulong)&dbg_txdesc_index, doff_u32}, 1800 {"vring_index", 0644, (ulong)&dbg_vring_index, doff_u32}, 1801 {"mem_addr", 0644, (ulong)&mem_addr, doff_u32}, 1802 {"led_polarity", 0644, (ulong)&led_polarity, doff_u8}, 1803 {}, 1804 }; 1805 1806 static const int dbg_off_count = 4 * (ARRAY_SIZE(isr_off) - 1) + 1807 ARRAY_SIZE(dbg_wil_regs) - 1 + 1808 ARRAY_SIZE(pseudo_isr_off) - 1 + 1809 ARRAY_SIZE(lgc_itr_cnt_off) - 1 + 1810 ARRAY_SIZE(tx_itr_cnt_off) - 1 + 1811 ARRAY_SIZE(rx_itr_cnt_off) - 1; 1812 1813 int wil6210_debugfs_init(struct wil6210_priv *wil) 1814 { 1815 struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME, 1816 wil_to_wiphy(wil)->debugfsdir); 1817 if (IS_ERR_OR_NULL(dbg)) 1818 return -ENODEV; 1819 1820 wil->dbg_data.data_arr = kcalloc(dbg_off_count, 1821 sizeof(struct wil_debugfs_iomem_data), 1822 GFP_KERNEL); 1823 if (!wil->dbg_data.data_arr) { 1824 debugfs_remove_recursive(dbg); 1825 wil->debug = NULL; 1826 return -ENOMEM; 1827 } 1828 1829 wil->dbg_data.iomem_data_count = 0; 1830 1831 wil_pmc_init(wil); 1832 1833 wil6210_debugfs_init_files(wil, dbg); 1834 wil6210_debugfs_init_isr(wil, dbg); 1835 wil6210_debugfs_init_blobs(wil, dbg); 1836 wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off); 1837 wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr, 1838 dbg_wil_regs); 1839 wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics); 1840 1841 wil6210_debugfs_create_pseudo_ISR(wil, dbg); 1842 1843 wil6210_debugfs_create_ITR_CNT(wil, dbg); 1844 1845 return 0; 1846 } 1847 1848 void wil6210_debugfs_remove(struct wil6210_priv *wil) 1849 { 1850 debugfs_remove_recursive(wil->debug); 1851 wil->debug = NULL; 1852 1853 kfree(wil->dbg_data.data_arr); 1854 1855 /* free pmc memory without sending command to fw, as it will 1856 * be reset on the way down anyway 1857 */ 1858 wil_pmc_free(wil, false); 1859 } 1860