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