1 /* 2 * Copyright (c) 2012-2017 Qualcomm Atheros, Inc. 3 * Copyright (c) 2018-2019, 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_ring_index; /* 24+ for Rx, 0..23 for Tx */ 33 static u32 dbg_status_msg_index; 34 /* 0..wil->num_rx_status_rings-1 for Rx, wil->tx_sring_idx for Tx */ 35 static u32 dbg_sring_index; 36 37 enum dbg_off_type { 38 doff_u32 = 0, 39 doff_x32 = 1, 40 doff_ulong = 2, 41 doff_io32 = 3, 42 doff_u8 = 4 43 }; 44 45 /* offset to "wil" */ 46 struct dbg_off { 47 const char *name; 48 umode_t mode; 49 ulong off; 50 enum dbg_off_type type; 51 }; 52 53 static void wil_print_desc_edma(struct seq_file *s, struct wil6210_priv *wil, 54 struct wil_ring *ring, 55 char _s, char _h, int idx) 56 { 57 u8 num_of_descs; 58 bool has_skb = false; 59 60 if (ring->is_rx) { 61 struct wil_rx_enhanced_desc *rx_d = 62 (struct wil_rx_enhanced_desc *) 63 &ring->va[idx].rx.enhanced; 64 u16 buff_id = le16_to_cpu(rx_d->mac.buff_id); 65 66 if (wil->rx_buff_mgmt.buff_arr && 67 wil_val_in_range(buff_id, 0, wil->rx_buff_mgmt.size)) 68 has_skb = wil->rx_buff_mgmt.buff_arr[buff_id].skb; 69 seq_printf(s, "%c", (has_skb) ? _h : _s); 70 } else { 71 struct wil_tx_enhanced_desc *d = 72 (struct wil_tx_enhanced_desc *) 73 &ring->va[idx].tx.enhanced; 74 75 num_of_descs = (u8)d->mac.d[2]; 76 has_skb = ring->ctx && ring->ctx[idx].skb; 77 if (num_of_descs >= 1) 78 seq_printf(s, "%c", has_skb ? _h : _s); 79 else 80 /* num_of_descs == 0, it's a frag in a list of descs */ 81 seq_printf(s, "%c", has_skb ? 'h' : _s); 82 } 83 } 84 85 static void wil_print_ring(struct seq_file *s, struct wil6210_priv *wil, 86 const char *name, struct wil_ring *ring, 87 char _s, char _h) 88 { 89 void __iomem *x; 90 u32 v; 91 92 seq_printf(s, "RING %s = {\n", name); 93 seq_printf(s, " pa = %pad\n", &ring->pa); 94 seq_printf(s, " va = 0x%p\n", ring->va); 95 seq_printf(s, " size = %d\n", ring->size); 96 if (wil->use_enhanced_dma_hw && ring->is_rx) 97 seq_printf(s, " swtail = %u\n", *ring->edma_rx_swtail.va); 98 else 99 seq_printf(s, " swtail = %d\n", ring->swtail); 100 seq_printf(s, " swhead = %d\n", ring->swhead); 101 if (wil->use_enhanced_dma_hw) { 102 int ring_id = ring->is_rx ? 103 WIL_RX_DESC_RING_ID : ring - wil->ring_tx; 104 /* SUBQ_CONS is a table of 32 entries, one for each Q pair. 105 * lower 16bits are for even ring_id and upper 16bits are for 106 * odd ring_id 107 */ 108 x = wmi_addr(wil, RGF_DMA_SCM_SUBQ_CONS + 4 * (ring_id / 2)); 109 v = readl_relaxed(x); 110 111 v = (ring_id % 2 ? (v >> 16) : (v & 0xffff)); 112 seq_printf(s, " hwhead = %u\n", v); 113 } 114 seq_printf(s, " hwtail = [0x%08x] -> ", ring->hwtail); 115 x = wmi_addr(wil, ring->hwtail); 116 if (x) { 117 v = readl(x); 118 seq_printf(s, "0x%08x = %d\n", v, v); 119 } else { 120 seq_puts(s, "???\n"); 121 } 122 123 if (ring->va && (ring->size <= (1 << WIL_RING_SIZE_ORDER_MAX))) { 124 uint i; 125 126 for (i = 0; i < ring->size; i++) { 127 if ((i % 128) == 0 && i != 0) 128 seq_puts(s, "\n"); 129 if (wil->use_enhanced_dma_hw) { 130 wil_print_desc_edma(s, wil, ring, _s, _h, i); 131 } else { 132 volatile struct vring_tx_desc *d = 133 &ring->va[i].tx.legacy; 134 seq_printf(s, "%c", (d->dma.status & BIT(0)) ? 135 _s : (ring->ctx[i].skb ? _h : 'h')); 136 } 137 } 138 seq_puts(s, "\n"); 139 } 140 seq_puts(s, "}\n"); 141 } 142 143 static int ring_show(struct seq_file *s, void *data) 144 { 145 uint i; 146 struct wil6210_priv *wil = s->private; 147 148 wil_print_ring(s, wil, "rx", &wil->ring_rx, 'S', '_'); 149 150 for (i = 0; i < ARRAY_SIZE(wil->ring_tx); i++) { 151 struct wil_ring *ring = &wil->ring_tx[i]; 152 struct wil_ring_tx_data *txdata = &wil->ring_tx_data[i]; 153 154 if (ring->va) { 155 int cid = wil->ring2cid_tid[i][0]; 156 int tid = wil->ring2cid_tid[i][1]; 157 u32 swhead = ring->swhead; 158 u32 swtail = ring->swtail; 159 int used = (ring->size + swhead - swtail) 160 % ring->size; 161 int avail = ring->size - used - 1; 162 char name[10]; 163 char sidle[10]; 164 /* performance monitoring */ 165 cycles_t now = get_cycles(); 166 uint64_t idle = txdata->idle * 100; 167 uint64_t total = now - txdata->begin; 168 169 if (total != 0) { 170 do_div(idle, total); 171 snprintf(sidle, sizeof(sidle), "%3d%%", 172 (int)idle); 173 } else { 174 snprintf(sidle, sizeof(sidle), "N/A"); 175 } 176 txdata->begin = now; 177 txdata->idle = 0ULL; 178 179 snprintf(name, sizeof(name), "tx_%2d", i); 180 181 if (cid < wil->max_assoc_sta) 182 seq_printf(s, 183 "\n%pM CID %d TID %d 1x%s BACK([%u] %u TU A%s) [%3d|%3d] idle %s\n", 184 wil->sta[cid].addr, cid, tid, 185 txdata->dot1x_open ? "+" : "-", 186 txdata->agg_wsize, 187 txdata->agg_timeout, 188 txdata->agg_amsdu ? "+" : "-", 189 used, avail, sidle); 190 else 191 seq_printf(s, 192 "\nBroadcast 1x%s [%3d|%3d] idle %s\n", 193 txdata->dot1x_open ? "+" : "-", 194 used, avail, sidle); 195 196 wil_print_ring(s, wil, name, ring, '_', 'H'); 197 } 198 } 199 200 return 0; 201 } 202 DEFINE_SHOW_ATTRIBUTE(ring); 203 204 static void wil_print_sring(struct seq_file *s, struct wil6210_priv *wil, 205 struct wil_status_ring *sring) 206 { 207 void __iomem *x; 208 int sring_idx = sring - wil->srings; 209 u32 v; 210 211 seq_printf(s, "Status Ring %s [ %d ] = {\n", 212 sring->is_rx ? "RX" : "TX", sring_idx); 213 seq_printf(s, " pa = %pad\n", &sring->pa); 214 seq_printf(s, " va = 0x%pK\n", sring->va); 215 seq_printf(s, " size = %d\n", sring->size); 216 seq_printf(s, " elem_size = %zu\n", sring->elem_size); 217 seq_printf(s, " swhead = %d\n", sring->swhead); 218 if (wil->use_enhanced_dma_hw) { 219 /* COMPQ_PROD is a table of 32 entries, one for each Q pair. 220 * lower 16bits are for even ring_id and upper 16bits are for 221 * odd ring_id 222 */ 223 x = wmi_addr(wil, RGF_DMA_SCM_COMPQ_PROD + 4 * (sring_idx / 2)); 224 v = readl_relaxed(x); 225 226 v = (sring_idx % 2 ? (v >> 16) : (v & 0xffff)); 227 seq_printf(s, " hwhead = %u\n", v); 228 } 229 seq_printf(s, " hwtail = [0x%08x] -> ", sring->hwtail); 230 x = wmi_addr(wil, sring->hwtail); 231 if (x) { 232 v = readl_relaxed(x); 233 seq_printf(s, "0x%08x = %d\n", v, v); 234 } else { 235 seq_puts(s, "???\n"); 236 } 237 seq_printf(s, " desc_rdy_pol = %d\n", sring->desc_rdy_pol); 238 seq_printf(s, " invalid_buff_id_cnt = %d\n", 239 sring->invalid_buff_id_cnt); 240 241 if (sring->va && (sring->size <= (1 << WIL_RING_SIZE_ORDER_MAX))) { 242 uint i; 243 244 for (i = 0; i < sring->size; i++) { 245 u32 *sdword_0 = 246 (u32 *)(sring->va + (sring->elem_size * i)); 247 248 if ((i % 128) == 0 && i != 0) 249 seq_puts(s, "\n"); 250 if (i == sring->swhead) 251 seq_printf(s, "%c", (*sdword_0 & BIT(31)) ? 252 'X' : 'x'); 253 else 254 seq_printf(s, "%c", (*sdword_0 & BIT(31)) ? 255 '1' : '0'); 256 } 257 seq_puts(s, "\n"); 258 } 259 seq_puts(s, "}\n"); 260 } 261 262 static int srings_show(struct seq_file *s, void *data) 263 { 264 struct wil6210_priv *wil = s->private; 265 int i = 0; 266 267 for (i = 0; i < WIL6210_MAX_STATUS_RINGS; i++) 268 if (wil->srings[i].va) 269 wil_print_sring(s, wil, &wil->srings[i]); 270 271 return 0; 272 } 273 DEFINE_SHOW_ATTRIBUTE(srings); 274 275 static void wil_seq_hexdump(struct seq_file *s, void *p, int len, 276 const char *prefix) 277 { 278 seq_hex_dump(s, prefix, DUMP_PREFIX_NONE, 16, 1, p, len, false); 279 } 280 281 static void wil_print_mbox_ring(struct seq_file *s, const char *prefix, 282 void __iomem *off) 283 { 284 struct wil6210_priv *wil = s->private; 285 struct wil6210_mbox_ring r; 286 int rsize; 287 uint i; 288 289 wil_halp_vote(wil); 290 291 if (wil_mem_access_lock(wil)) { 292 wil_halp_unvote(wil); 293 return; 294 } 295 296 wil_memcpy_fromio_32(&r, off, sizeof(r)); 297 wil_mbox_ring_le2cpus(&r); 298 /* 299 * we just read memory block from NIC. This memory may be 300 * garbage. Check validity before using it. 301 */ 302 rsize = r.size / sizeof(struct wil6210_mbox_ring_desc); 303 304 seq_printf(s, "ring %s = {\n", prefix); 305 seq_printf(s, " base = 0x%08x\n", r.base); 306 seq_printf(s, " size = 0x%04x bytes -> %d entries\n", r.size, rsize); 307 seq_printf(s, " tail = 0x%08x\n", r.tail); 308 seq_printf(s, " head = 0x%08x\n", r.head); 309 seq_printf(s, " entry size = %d\n", r.entry_size); 310 311 if (r.size % sizeof(struct wil6210_mbox_ring_desc)) { 312 seq_printf(s, " ??? size is not multiple of %zd, garbage?\n", 313 sizeof(struct wil6210_mbox_ring_desc)); 314 goto out; 315 } 316 317 if (!wmi_addr(wil, r.base) || 318 !wmi_addr(wil, r.tail) || 319 !wmi_addr(wil, r.head)) { 320 seq_puts(s, " ??? pointers are garbage?\n"); 321 goto out; 322 } 323 324 for (i = 0; i < rsize; i++) { 325 struct wil6210_mbox_ring_desc d; 326 struct wil6210_mbox_hdr hdr; 327 size_t delta = i * sizeof(d); 328 void __iomem *x = wil->csr + HOSTADDR(r.base) + delta; 329 330 wil_memcpy_fromio_32(&d, x, sizeof(d)); 331 332 seq_printf(s, " [%2x] %s %s%s 0x%08x", i, 333 d.sync ? "F" : "E", 334 (r.tail - r.base == delta) ? "t" : " ", 335 (r.head - r.base == delta) ? "h" : " ", 336 le32_to_cpu(d.addr)); 337 if (0 == wmi_read_hdr(wil, d.addr, &hdr)) { 338 u16 len = le16_to_cpu(hdr.len); 339 340 seq_printf(s, " -> %04x %04x %04x %02x\n", 341 le16_to_cpu(hdr.seq), len, 342 le16_to_cpu(hdr.type), hdr.flags); 343 if (len <= MAX_MBOXITEM_SIZE) { 344 unsigned char databuf[MAX_MBOXITEM_SIZE]; 345 void __iomem *src = wmi_buffer(wil, d.addr) + 346 sizeof(struct wil6210_mbox_hdr); 347 /* 348 * No need to check @src for validity - 349 * we already validated @d.addr while 350 * reading header 351 */ 352 wil_memcpy_fromio_32(databuf, src, len); 353 wil_seq_hexdump(s, databuf, len, " : "); 354 } 355 } else { 356 seq_puts(s, "\n"); 357 } 358 } 359 out: 360 seq_puts(s, "}\n"); 361 wil_mem_access_unlock(wil); 362 wil_halp_unvote(wil); 363 } 364 365 static int mbox_show(struct seq_file *s, void *data) 366 { 367 struct wil6210_priv *wil = s->private; 368 int ret; 369 370 ret = wil_pm_runtime_get(wil); 371 if (ret < 0) 372 return ret; 373 374 wil_print_mbox_ring(s, "tx", wil->csr + HOST_MBOX + 375 offsetof(struct wil6210_mbox_ctl, tx)); 376 wil_print_mbox_ring(s, "rx", wil->csr + HOST_MBOX + 377 offsetof(struct wil6210_mbox_ctl, rx)); 378 379 wil_pm_runtime_put(wil); 380 381 return 0; 382 } 383 DEFINE_SHOW_ATTRIBUTE(mbox); 384 385 static int wil_debugfs_iomem_x32_set(void *data, u64 val) 386 { 387 struct wil_debugfs_iomem_data *d = (struct 388 wil_debugfs_iomem_data *)data; 389 struct wil6210_priv *wil = d->wil; 390 int ret; 391 392 ret = wil_pm_runtime_get(wil); 393 if (ret < 0) 394 return ret; 395 396 writel(val, (void __iomem *)d->offset); 397 wmb(); /* make sure write propagated to HW */ 398 399 wil_pm_runtime_put(wil); 400 401 return 0; 402 } 403 404 static int wil_debugfs_iomem_x32_get(void *data, u64 *val) 405 { 406 struct wil_debugfs_iomem_data *d = (struct 407 wil_debugfs_iomem_data *)data; 408 struct wil6210_priv *wil = d->wil; 409 int ret; 410 411 ret = wil_pm_runtime_get(wil); 412 if (ret < 0) 413 return ret; 414 415 *val = readl((void __iomem *)d->offset); 416 417 wil_pm_runtime_put(wil); 418 419 return 0; 420 } 421 422 DEFINE_DEBUGFS_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get, 423 wil_debugfs_iomem_x32_set, "0x%08llx\n"); 424 425 static void wil_debugfs_create_iomem_x32(const char *name, umode_t mode, 426 struct dentry *parent, void *value, 427 struct wil6210_priv *wil) 428 { 429 struct wil_debugfs_iomem_data *data = &wil->dbg_data.data_arr[ 430 wil->dbg_data.iomem_data_count]; 431 432 data->wil = wil; 433 data->offset = value; 434 435 debugfs_create_file_unsafe(name, mode, parent, data, &fops_iomem_x32); 436 wil->dbg_data.iomem_data_count++; 437 } 438 439 static int wil_debugfs_ulong_set(void *data, u64 val) 440 { 441 *(ulong *)data = val; 442 return 0; 443 } 444 445 static int wil_debugfs_ulong_get(void *data, u64 *val) 446 { 447 *val = *(ulong *)data; 448 return 0; 449 } 450 451 DEFINE_DEBUGFS_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get, 452 wil_debugfs_ulong_set, "0x%llx\n"); 453 454 /** 455 * wil6210_debugfs_init_offset - create set of debugfs files 456 * @wil - driver's context, used for printing 457 * @dbg - directory on the debugfs, where files will be created 458 * @base - base address used in address calculation 459 * @tbl - table with file descriptions. Should be terminated with empty element. 460 * 461 * Creates files accordingly to the @tbl. 462 */ 463 static void wil6210_debugfs_init_offset(struct wil6210_priv *wil, 464 struct dentry *dbg, void *base, 465 const struct dbg_off * const tbl) 466 { 467 int i; 468 469 for (i = 0; tbl[i].name; i++) { 470 switch (tbl[i].type) { 471 case doff_u32: 472 debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg, 473 base + tbl[i].off); 474 break; 475 case doff_x32: 476 debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg, 477 base + tbl[i].off); 478 break; 479 case doff_ulong: 480 debugfs_create_file_unsafe(tbl[i].name, tbl[i].mode, 481 dbg, base + tbl[i].off, 482 &wil_fops_ulong); 483 break; 484 case doff_io32: 485 wil_debugfs_create_iomem_x32(tbl[i].name, tbl[i].mode, 486 dbg, base + tbl[i].off, 487 wil); 488 break; 489 case doff_u8: 490 debugfs_create_u8(tbl[i].name, tbl[i].mode, dbg, 491 base + tbl[i].off); 492 break; 493 } 494 } 495 } 496 497 static const struct dbg_off isr_off[] = { 498 {"ICC", 0644, offsetof(struct RGF_ICR, ICC), doff_io32}, 499 {"ICR", 0644, offsetof(struct RGF_ICR, ICR), doff_io32}, 500 {"ICM", 0644, offsetof(struct RGF_ICR, ICM), doff_io32}, 501 {"ICS", 0244, offsetof(struct RGF_ICR, ICS), doff_io32}, 502 {"IMV", 0644, offsetof(struct RGF_ICR, IMV), doff_io32}, 503 {"IMS", 0244, offsetof(struct RGF_ICR, IMS), doff_io32}, 504 {"IMC", 0244, offsetof(struct RGF_ICR, IMC), doff_io32}, 505 {}, 506 }; 507 508 static void wil6210_debugfs_create_ISR(struct wil6210_priv *wil, 509 const char *name, struct dentry *parent, 510 u32 off) 511 { 512 struct dentry *d = debugfs_create_dir(name, parent); 513 514 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off, 515 isr_off); 516 } 517 518 static const struct dbg_off pseudo_isr_off[] = { 519 {"CAUSE", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32}, 520 {"MASK_SW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32}, 521 {"MASK_FW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32}, 522 {}, 523 }; 524 525 static void wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil, 526 struct dentry *parent) 527 { 528 struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent); 529 530 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr, 531 pseudo_isr_off); 532 } 533 534 static const struct dbg_off lgc_itr_cnt_off[] = { 535 {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32}, 536 {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32}, 537 {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32}, 538 {}, 539 }; 540 541 static const struct dbg_off tx_itr_cnt_off[] = { 542 {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_TRSH), 543 doff_io32}, 544 {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_DATA), 545 doff_io32}, 546 {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_CTL), 547 doff_io32}, 548 {"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_TRSH), 549 doff_io32}, 550 {"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_DATA), 551 doff_io32}, 552 {"IDL_CTL", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_CTL), 553 doff_io32}, 554 {}, 555 }; 556 557 static const struct dbg_off rx_itr_cnt_off[] = { 558 {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_TRSH), 559 doff_io32}, 560 {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_DATA), 561 doff_io32}, 562 {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_CTL), 563 doff_io32}, 564 {"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_TRSH), 565 doff_io32}, 566 {"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_DATA), 567 doff_io32}, 568 {"IDL_CTL", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_CTL), 569 doff_io32}, 570 {}, 571 }; 572 573 static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil, 574 struct dentry *parent) 575 { 576 struct dentry *d, *dtx, *drx; 577 578 d = debugfs_create_dir("ITR_CNT", parent); 579 580 dtx = debugfs_create_dir("TX", d); 581 drx = debugfs_create_dir("RX", d); 582 583 wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr, 584 lgc_itr_cnt_off); 585 586 wil6210_debugfs_init_offset(wil, dtx, (void * __force)wil->csr, 587 tx_itr_cnt_off); 588 589 wil6210_debugfs_init_offset(wil, drx, (void * __force)wil->csr, 590 rx_itr_cnt_off); 591 return 0; 592 } 593 594 static int memread_show(struct seq_file *s, void *data) 595 { 596 struct wil6210_priv *wil = s->private; 597 void __iomem *a; 598 int ret; 599 600 ret = wil_pm_runtime_get(wil); 601 if (ret < 0) 602 return ret; 603 604 ret = wil_mem_access_lock(wil); 605 if (ret) { 606 wil_pm_runtime_put(wil); 607 return ret; 608 } 609 610 a = wmi_buffer(wil, cpu_to_le32(mem_addr)); 611 612 if (a) 613 seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, readl(a)); 614 else 615 seq_printf(s, "[0x%08x] = INVALID\n", mem_addr); 616 617 wil_mem_access_unlock(wil); 618 wil_pm_runtime_put(wil); 619 620 return 0; 621 } 622 DEFINE_SHOW_ATTRIBUTE(memread); 623 624 static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf, 625 size_t count, loff_t *ppos) 626 { 627 enum { max_count = 4096 }; 628 struct wil_blob_wrapper *wil_blob = file->private_data; 629 struct wil6210_priv *wil = wil_blob->wil; 630 loff_t aligned_pos, pos = *ppos; 631 size_t available = wil_blob->blob.size; 632 void *buf; 633 size_t unaligned_bytes, aligned_count, ret; 634 int rc; 635 636 if (pos < 0) 637 return -EINVAL; 638 639 if (pos >= available || !count) 640 return 0; 641 642 if (count > available - pos) 643 count = available - pos; 644 if (count > max_count) 645 count = max_count; 646 647 /* set pos to 4 bytes aligned */ 648 unaligned_bytes = pos % 4; 649 aligned_pos = pos - unaligned_bytes; 650 aligned_count = count + unaligned_bytes; 651 652 buf = kmalloc(aligned_count, GFP_KERNEL); 653 if (!buf) 654 return -ENOMEM; 655 656 rc = wil_pm_runtime_get(wil); 657 if (rc < 0) { 658 kfree(buf); 659 return rc; 660 } 661 662 rc = wil_mem_access_lock(wil); 663 if (rc) { 664 kfree(buf); 665 wil_pm_runtime_put(wil); 666 return rc; 667 } 668 669 wil_memcpy_fromio_32(buf, (const void __iomem *) 670 wil_blob->blob.data + aligned_pos, aligned_count); 671 672 ret = copy_to_user(user_buf, buf + unaligned_bytes, count); 673 674 wil_mem_access_unlock(wil); 675 wil_pm_runtime_put(wil); 676 677 kfree(buf); 678 if (ret == count) 679 return -EFAULT; 680 681 count -= ret; 682 *ppos = pos + count; 683 684 return count; 685 } 686 687 static const struct file_operations fops_ioblob = { 688 .read = wil_read_file_ioblob, 689 .open = simple_open, 690 .llseek = default_llseek, 691 }; 692 693 static 694 struct dentry *wil_debugfs_create_ioblob(const char *name, 695 umode_t mode, 696 struct dentry *parent, 697 struct wil_blob_wrapper *wil_blob) 698 { 699 return debugfs_create_file(name, mode, parent, wil_blob, &fops_ioblob); 700 } 701 702 /*---write channel 1..4 to rxon for it, 0 to rxoff---*/ 703 static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf, 704 size_t len, loff_t *ppos) 705 { 706 struct wil6210_priv *wil = file->private_data; 707 int rc; 708 long channel; 709 bool on; 710 711 char *kbuf = memdup_user_nul(buf, len); 712 713 if (IS_ERR(kbuf)) 714 return PTR_ERR(kbuf); 715 rc = kstrtol(kbuf, 0, &channel); 716 kfree(kbuf); 717 if (rc) 718 return rc; 719 720 if ((channel < 0) || (channel > 4)) { 721 wil_err(wil, "Invalid channel %ld\n", channel); 722 return -EINVAL; 723 } 724 on = !!channel; 725 726 if (on) { 727 rc = wmi_set_channel(wil, (int)channel); 728 if (rc) 729 return rc; 730 } 731 732 rc = wmi_rxon(wil, on); 733 if (rc) 734 return rc; 735 736 return len; 737 } 738 739 static const struct file_operations fops_rxon = { 740 .write = wil_write_file_rxon, 741 .open = simple_open, 742 }; 743 744 static ssize_t wil_write_file_rbufcap(struct file *file, 745 const char __user *buf, 746 size_t count, loff_t *ppos) 747 { 748 struct wil6210_priv *wil = file->private_data; 749 int val; 750 int rc; 751 752 rc = kstrtoint_from_user(buf, count, 0, &val); 753 if (rc) { 754 wil_err(wil, "Invalid argument\n"); 755 return rc; 756 } 757 /* input value: negative to disable, 0 to use system default, 758 * 1..ring size to set descriptor threshold 759 */ 760 wil_info(wil, "%s RBUFCAP, descriptors threshold - %d\n", 761 val < 0 ? "Disabling" : "Enabling", val); 762 763 if (!wil->ring_rx.va || val > wil->ring_rx.size) { 764 wil_err(wil, "Invalid descriptors threshold, %d\n", val); 765 return -EINVAL; 766 } 767 768 rc = wmi_rbufcap_cfg(wil, val < 0 ? 0 : 1, val < 0 ? 0 : val); 769 if (rc) { 770 wil_err(wil, "RBUFCAP config failed: %d\n", rc); 771 return rc; 772 } 773 774 return count; 775 } 776 777 static const struct file_operations fops_rbufcap = { 778 .write = wil_write_file_rbufcap, 779 .open = simple_open, 780 }; 781 782 /* block ack control, write: 783 * - "add <ringid> <agg_size> <timeout>" to trigger ADDBA 784 * - "del_tx <ringid> <reason>" to trigger DELBA for Tx side 785 * - "del_rx <CID> <TID> <reason>" to trigger DELBA for Rx side 786 */ 787 static ssize_t wil_write_back(struct file *file, const char __user *buf, 788 size_t len, loff_t *ppos) 789 { 790 struct wil6210_priv *wil = file->private_data; 791 int rc; 792 char *kbuf = kmalloc(len + 1, GFP_KERNEL); 793 char cmd[9]; 794 int p1, p2, p3; 795 796 if (!kbuf) 797 return -ENOMEM; 798 799 rc = simple_write_to_buffer(kbuf, len, ppos, buf, len); 800 if (rc != len) { 801 kfree(kbuf); 802 return rc >= 0 ? -EIO : rc; 803 } 804 805 kbuf[len] = '\0'; 806 rc = sscanf(kbuf, "%8s %d %d %d", cmd, &p1, &p2, &p3); 807 kfree(kbuf); 808 809 if (rc < 0) 810 return rc; 811 if (rc < 2) 812 return -EINVAL; 813 814 if ((strcmp(cmd, "add") == 0) || 815 (strcmp(cmd, "del_tx") == 0)) { 816 struct wil_ring_tx_data *txdata; 817 818 if (p1 < 0 || p1 >= WIL6210_MAX_TX_RINGS) { 819 wil_err(wil, "BACK: invalid ring id %d\n", p1); 820 return -EINVAL; 821 } 822 txdata = &wil->ring_tx_data[p1]; 823 if (strcmp(cmd, "add") == 0) { 824 if (rc < 3) { 825 wil_err(wil, "BACK: add require at least 2 params\n"); 826 return -EINVAL; 827 } 828 if (rc < 4) 829 p3 = 0; 830 wmi_addba(wil, txdata->mid, p1, p2, p3); 831 } else { 832 if (rc < 3) 833 p2 = WLAN_REASON_QSTA_LEAVE_QBSS; 834 wmi_delba_tx(wil, txdata->mid, p1, p2); 835 } 836 } else if (strcmp(cmd, "del_rx") == 0) { 837 struct wil_sta_info *sta; 838 839 if (rc < 3) { 840 wil_err(wil, 841 "BACK: del_rx require at least 2 params\n"); 842 return -EINVAL; 843 } 844 if (p1 < 0 || p1 >= wil->max_assoc_sta) { 845 wil_err(wil, "BACK: invalid CID %d\n", p1); 846 return -EINVAL; 847 } 848 if (rc < 4) 849 p3 = WLAN_REASON_QSTA_LEAVE_QBSS; 850 sta = &wil->sta[p1]; 851 wmi_delba_rx(wil, sta->mid, p1, p2, p3); 852 } else { 853 wil_err(wil, "BACK: Unrecognized command \"%s\"\n", cmd); 854 return -EINVAL; 855 } 856 857 return len; 858 } 859 860 static ssize_t wil_read_back(struct file *file, char __user *user_buf, 861 size_t count, loff_t *ppos) 862 { 863 static const char text[] = "block ack control, write:\n" 864 " - \"add <ringid> <agg_size> <timeout>\" to trigger ADDBA\n" 865 "If missing, <timeout> defaults to 0\n" 866 " - \"del_tx <ringid> <reason>\" to trigger DELBA for Tx side\n" 867 " - \"del_rx <CID> <TID> <reason>\" to trigger DELBA for Rx side\n" 868 "If missing, <reason> set to \"STA_LEAVING\" (36)\n"; 869 870 return simple_read_from_buffer(user_buf, count, ppos, text, 871 sizeof(text)); 872 } 873 874 static const struct file_operations fops_back = { 875 .read = wil_read_back, 876 .write = wil_write_back, 877 .open = simple_open, 878 }; 879 880 /* pmc control, write: 881 * - "alloc <num descriptors> <descriptor_size>" to allocate PMC 882 * - "free" to release memory allocated for PMC 883 */ 884 static ssize_t wil_write_pmccfg(struct file *file, const char __user *buf, 885 size_t len, loff_t *ppos) 886 { 887 struct wil6210_priv *wil = file->private_data; 888 int rc; 889 char *kbuf = kmalloc(len + 1, GFP_KERNEL); 890 char cmd[9]; 891 int num_descs, desc_size; 892 893 if (!kbuf) 894 return -ENOMEM; 895 896 rc = simple_write_to_buffer(kbuf, len, ppos, buf, len); 897 if (rc != len) { 898 kfree(kbuf); 899 return rc >= 0 ? -EIO : rc; 900 } 901 902 kbuf[len] = '\0'; 903 rc = sscanf(kbuf, "%8s %d %d", cmd, &num_descs, &desc_size); 904 kfree(kbuf); 905 906 if (rc < 0) 907 return rc; 908 909 if (rc < 1) { 910 wil_err(wil, "pmccfg: no params given\n"); 911 return -EINVAL; 912 } 913 914 if (0 == strcmp(cmd, "alloc")) { 915 if (rc != 3) { 916 wil_err(wil, "pmccfg: alloc requires 2 params\n"); 917 return -EINVAL; 918 } 919 wil_pmc_alloc(wil, num_descs, desc_size); 920 } else if (0 == strcmp(cmd, "free")) { 921 if (rc != 1) { 922 wil_err(wil, "pmccfg: free does not have any params\n"); 923 return -EINVAL; 924 } 925 wil_pmc_free(wil, true); 926 } else { 927 wil_err(wil, "pmccfg: Unrecognized command \"%s\"\n", cmd); 928 return -EINVAL; 929 } 930 931 return len; 932 } 933 934 static ssize_t wil_read_pmccfg(struct file *file, char __user *user_buf, 935 size_t count, loff_t *ppos) 936 { 937 struct wil6210_priv *wil = file->private_data; 938 char text[256]; 939 char help[] = "pmc control, write:\n" 940 " - \"alloc <num descriptors> <descriptor_size>\" to allocate pmc\n" 941 " - \"free\" to free memory allocated for pmc\n"; 942 943 snprintf(text, sizeof(text), "Last command status: %d\n\n%s", 944 wil_pmc_last_cmd_status(wil), help); 945 946 return simple_read_from_buffer(user_buf, count, ppos, text, 947 strlen(text) + 1); 948 } 949 950 static const struct file_operations fops_pmccfg = { 951 .read = wil_read_pmccfg, 952 .write = wil_write_pmccfg, 953 .open = simple_open, 954 }; 955 956 static const struct file_operations fops_pmcdata = { 957 .open = simple_open, 958 .read = wil_pmc_read, 959 .llseek = wil_pmc_llseek, 960 }; 961 962 /*---tx_mgmt---*/ 963 /* Write mgmt frame to this file to send it */ 964 static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf, 965 size_t len, loff_t *ppos) 966 { 967 struct wil6210_priv *wil = file->private_data; 968 struct wiphy *wiphy = wil_to_wiphy(wil); 969 struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr; 970 struct cfg80211_mgmt_tx_params params; 971 int rc; 972 void *frame; 973 974 memset(¶ms, 0, sizeof(params)); 975 976 if (!len) 977 return -EINVAL; 978 979 frame = memdup_user(buf, len); 980 if (IS_ERR(frame)) 981 return PTR_ERR(frame); 982 983 params.buf = frame; 984 params.len = len; 985 986 rc = wil_cfg80211_mgmt_tx(wiphy, wdev, ¶ms, NULL); 987 988 kfree(frame); 989 wil_info(wil, "-> %d\n", rc); 990 991 return len; 992 } 993 994 static const struct file_operations fops_txmgmt = { 995 .write = wil_write_file_txmgmt, 996 .open = simple_open, 997 }; 998 999 /* Write WMI command (w/o mbox header) to this file to send it 1000 * WMI starts from wil6210_mbox_hdr_wmi header 1001 */ 1002 static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf, 1003 size_t len, loff_t *ppos) 1004 { 1005 struct wil6210_priv *wil = file->private_data; 1006 struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev); 1007 struct wmi_cmd_hdr *wmi; 1008 void *cmd; 1009 int cmdlen = len - sizeof(struct wmi_cmd_hdr); 1010 u16 cmdid; 1011 int rc, rc1; 1012 1013 if (cmdlen < 0) 1014 return -EINVAL; 1015 1016 wmi = kmalloc(len, GFP_KERNEL); 1017 if (!wmi) 1018 return -ENOMEM; 1019 1020 rc = simple_write_to_buffer(wmi, len, ppos, buf, len); 1021 if (rc < 0) { 1022 kfree(wmi); 1023 return rc; 1024 } 1025 1026 cmd = (cmdlen > 0) ? &wmi[1] : NULL; 1027 cmdid = le16_to_cpu(wmi->command_id); 1028 1029 rc1 = wmi_send(wil, cmdid, vif->mid, cmd, cmdlen); 1030 kfree(wmi); 1031 1032 wil_info(wil, "0x%04x[%d] -> %d\n", cmdid, cmdlen, rc1); 1033 1034 return rc; 1035 } 1036 1037 static const struct file_operations fops_wmi = { 1038 .write = wil_write_file_wmi, 1039 .open = simple_open, 1040 }; 1041 1042 static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb) 1043 { 1044 int i = 0; 1045 int len = skb_headlen(skb); 1046 void *p = skb->data; 1047 int nr_frags = skb_shinfo(skb)->nr_frags; 1048 1049 seq_printf(s, " len = %d\n", len); 1050 wil_seq_hexdump(s, p, len, " : "); 1051 1052 if (nr_frags) { 1053 seq_printf(s, " nr_frags = %d\n", nr_frags); 1054 for (i = 0; i < nr_frags; i++) { 1055 const struct skb_frag_struct *frag = 1056 &skb_shinfo(skb)->frags[i]; 1057 1058 len = skb_frag_size(frag); 1059 p = skb_frag_address_safe(frag); 1060 seq_printf(s, " [%2d] : len = %d\n", i, len); 1061 wil_seq_hexdump(s, p, len, " : "); 1062 } 1063 } 1064 } 1065 1066 /*---------Tx/Rx descriptor------------*/ 1067 static int txdesc_show(struct seq_file *s, void *data) 1068 { 1069 struct wil6210_priv *wil = s->private; 1070 struct wil_ring *ring; 1071 bool tx; 1072 int ring_idx = dbg_ring_index; 1073 int txdesc_idx = dbg_txdesc_index; 1074 volatile struct vring_tx_desc *d; 1075 volatile u32 *u; 1076 struct sk_buff *skb; 1077 1078 if (wil->use_enhanced_dma_hw) { 1079 /* RX ring index == 0 */ 1080 if (ring_idx >= WIL6210_MAX_TX_RINGS) { 1081 seq_printf(s, "invalid ring index %d\n", ring_idx); 1082 return 0; 1083 } 1084 tx = ring_idx > 0; /* desc ring 0 is reserved for RX */ 1085 } else { 1086 /* RX ring index == WIL6210_MAX_TX_RINGS */ 1087 if (ring_idx > WIL6210_MAX_TX_RINGS) { 1088 seq_printf(s, "invalid ring index %d\n", ring_idx); 1089 return 0; 1090 } 1091 tx = (ring_idx < WIL6210_MAX_TX_RINGS); 1092 } 1093 1094 ring = tx ? &wil->ring_tx[ring_idx] : &wil->ring_rx; 1095 1096 if (!ring->va) { 1097 if (tx) 1098 seq_printf(s, "No Tx[%2d] RING\n", ring_idx); 1099 else 1100 seq_puts(s, "No Rx RING\n"); 1101 return 0; 1102 } 1103 1104 if (txdesc_idx >= ring->size) { 1105 if (tx) 1106 seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n", 1107 ring_idx, txdesc_idx, ring->size); 1108 else 1109 seq_printf(s, "RxDesc index (%d) >= size (%d)\n", 1110 txdesc_idx, ring->size); 1111 return 0; 1112 } 1113 1114 /* use struct vring_tx_desc for Rx as well, 1115 * only field used, .dma.length, is the same 1116 */ 1117 d = &ring->va[txdesc_idx].tx.legacy; 1118 u = (volatile u32 *)d; 1119 skb = NULL; 1120 1121 if (wil->use_enhanced_dma_hw) { 1122 if (tx) { 1123 skb = ring->ctx ? ring->ctx[txdesc_idx].skb : NULL; 1124 } else if (wil->rx_buff_mgmt.buff_arr) { 1125 struct wil_rx_enhanced_desc *rx_d = 1126 (struct wil_rx_enhanced_desc *) 1127 &ring->va[txdesc_idx].rx.enhanced; 1128 u16 buff_id = le16_to_cpu(rx_d->mac.buff_id); 1129 1130 if (!wil_val_in_range(buff_id, 0, 1131 wil->rx_buff_mgmt.size)) 1132 seq_printf(s, "invalid buff_id %d\n", buff_id); 1133 else 1134 skb = wil->rx_buff_mgmt.buff_arr[buff_id].skb; 1135 } 1136 } else { 1137 skb = ring->ctx[txdesc_idx].skb; 1138 } 1139 if (tx) 1140 seq_printf(s, "Tx[%2d][%3d] = {\n", ring_idx, 1141 txdesc_idx); 1142 else 1143 seq_printf(s, "Rx[%3d] = {\n", txdesc_idx); 1144 seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n", 1145 u[0], u[1], u[2], u[3]); 1146 seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n", 1147 u[4], u[5], u[6], u[7]); 1148 seq_printf(s, " SKB = 0x%p\n", skb); 1149 1150 if (skb) { 1151 skb_get(skb); 1152 wil_seq_print_skb(s, skb); 1153 kfree_skb(skb); 1154 } 1155 seq_puts(s, "}\n"); 1156 1157 return 0; 1158 } 1159 DEFINE_SHOW_ATTRIBUTE(txdesc); 1160 1161 /*---------Tx/Rx status message------------*/ 1162 static int status_msg_show(struct seq_file *s, void *data) 1163 { 1164 struct wil6210_priv *wil = s->private; 1165 int sring_idx = dbg_sring_index; 1166 struct wil_status_ring *sring; 1167 bool tx; 1168 u32 status_msg_idx = dbg_status_msg_index; 1169 u32 *u; 1170 1171 if (sring_idx >= WIL6210_MAX_STATUS_RINGS) { 1172 seq_printf(s, "invalid status ring index %d\n", sring_idx); 1173 return 0; 1174 } 1175 1176 sring = &wil->srings[sring_idx]; 1177 tx = !sring->is_rx; 1178 1179 if (!sring->va) { 1180 seq_printf(s, "No %cX status ring\n", tx ? 'T' : 'R'); 1181 return 0; 1182 } 1183 1184 if (status_msg_idx >= sring->size) { 1185 seq_printf(s, "%cxDesc index (%d) >= size (%d)\n", 1186 tx ? 'T' : 'R', status_msg_idx, sring->size); 1187 return 0; 1188 } 1189 1190 u = sring->va + (sring->elem_size * status_msg_idx); 1191 1192 seq_printf(s, "%cx[%d][%3d] = {\n", 1193 tx ? 'T' : 'R', sring_idx, status_msg_idx); 1194 1195 seq_printf(s, " 0x%08x 0x%08x 0x%08x 0x%08x\n", 1196 u[0], u[1], u[2], u[3]); 1197 if (!tx && !wil->use_compressed_rx_status) 1198 seq_printf(s, " 0x%08x 0x%08x 0x%08x 0x%08x\n", 1199 u[4], u[5], u[6], u[7]); 1200 1201 seq_puts(s, "}\n"); 1202 1203 return 0; 1204 } 1205 DEFINE_SHOW_ATTRIBUTE(status_msg); 1206 1207 static int wil_print_rx_buff(struct seq_file *s, struct list_head *lh) 1208 { 1209 struct wil_rx_buff *it; 1210 int i = 0; 1211 1212 list_for_each_entry(it, lh, list) { 1213 if ((i % 16) == 0 && i != 0) 1214 seq_puts(s, "\n "); 1215 seq_printf(s, "[%4d] ", it->id); 1216 i++; 1217 } 1218 seq_printf(s, "\nNumber of buffers: %u\n", i); 1219 1220 return i; 1221 } 1222 1223 static int rx_buff_mgmt_show(struct seq_file *s, void *data) 1224 { 1225 struct wil6210_priv *wil = s->private; 1226 struct wil_rx_buff_mgmt *rbm = &wil->rx_buff_mgmt; 1227 int num_active; 1228 int num_free; 1229 1230 if (!rbm->buff_arr) 1231 return -EINVAL; 1232 1233 seq_printf(s, " size = %zu\n", rbm->size); 1234 seq_printf(s, " free_list_empty_cnt = %lu\n", 1235 rbm->free_list_empty_cnt); 1236 1237 /* Print active list */ 1238 seq_puts(s, " Active list:\n"); 1239 num_active = wil_print_rx_buff(s, &rbm->active); 1240 seq_puts(s, "\n Free list:\n"); 1241 num_free = wil_print_rx_buff(s, &rbm->free); 1242 1243 seq_printf(s, " Total number of buffers: %u\n", 1244 num_active + num_free); 1245 1246 return 0; 1247 } 1248 DEFINE_SHOW_ATTRIBUTE(rx_buff_mgmt); 1249 1250 /*---------beamforming------------*/ 1251 static char *wil_bfstatus_str(u32 status) 1252 { 1253 switch (status) { 1254 case 0: 1255 return "Failed"; 1256 case 1: 1257 return "OK"; 1258 case 2: 1259 return "Retrying"; 1260 default: 1261 return "??"; 1262 } 1263 } 1264 1265 static bool is_all_zeros(void * const x_, size_t sz) 1266 { 1267 /* if reply is all-0, ignore this CID */ 1268 u32 *x = x_; 1269 int n; 1270 1271 for (n = 0; n < sz / sizeof(*x); n++) 1272 if (x[n]) 1273 return false; 1274 1275 return true; 1276 } 1277 1278 static int bf_show(struct seq_file *s, void *data) 1279 { 1280 int rc; 1281 int i; 1282 struct wil6210_priv *wil = s->private; 1283 struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev); 1284 struct wmi_notify_req_cmd cmd = { 1285 .interval_usec = 0, 1286 }; 1287 struct { 1288 struct wmi_cmd_hdr wmi; 1289 struct wmi_notify_req_done_event evt; 1290 } __packed reply; 1291 1292 memset(&reply, 0, sizeof(reply)); 1293 1294 for (i = 0; i < wil->max_assoc_sta; i++) { 1295 u32 status; 1296 1297 cmd.cid = i; 1298 rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, vif->mid, 1299 &cmd, sizeof(cmd), 1300 WMI_NOTIFY_REQ_DONE_EVENTID, &reply, 1301 sizeof(reply), 20); 1302 /* if reply is all-0, ignore this CID */ 1303 if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt))) 1304 continue; 1305 1306 status = le32_to_cpu(reply.evt.status); 1307 seq_printf(s, "CID %d {\n" 1308 " TSF = 0x%016llx\n" 1309 " TxMCS = %2d TxTpt = %4d\n" 1310 " SQI = %4d\n" 1311 " RSSI = %4d\n" 1312 " Status = 0x%08x %s\n" 1313 " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n" 1314 " Goodput(rx:tx) %4d:%4d\n" 1315 "}\n", 1316 i, 1317 le64_to_cpu(reply.evt.tsf), 1318 le16_to_cpu(reply.evt.bf_mcs), 1319 le32_to_cpu(reply.evt.tx_tpt), 1320 reply.evt.sqi, 1321 reply.evt.rssi, 1322 status, wil_bfstatus_str(status), 1323 le16_to_cpu(reply.evt.my_rx_sector), 1324 le16_to_cpu(reply.evt.my_tx_sector), 1325 le16_to_cpu(reply.evt.other_rx_sector), 1326 le16_to_cpu(reply.evt.other_tx_sector), 1327 le32_to_cpu(reply.evt.rx_goodput), 1328 le32_to_cpu(reply.evt.tx_goodput)); 1329 } 1330 return 0; 1331 } 1332 DEFINE_SHOW_ATTRIBUTE(bf); 1333 1334 /*---------temp------------*/ 1335 static void print_temp(struct seq_file *s, const char *prefix, s32 t) 1336 { 1337 switch (t) { 1338 case 0: 1339 case ~(u32)0: 1340 seq_printf(s, "%s N/A\n", prefix); 1341 break; 1342 default: 1343 seq_printf(s, "%s %s%d.%03d\n", prefix, (t < 0 ? "-" : ""), 1344 abs(t / 1000), abs(t % 1000)); 1345 break; 1346 } 1347 } 1348 1349 static int temp_show(struct seq_file *s, void *data) 1350 { 1351 struct wil6210_priv *wil = s->private; 1352 s32 t_m, t_r; 1353 int rc = wmi_get_temperature(wil, &t_m, &t_r); 1354 1355 if (rc) { 1356 seq_puts(s, "Failed\n"); 1357 return 0; 1358 } 1359 1360 print_temp(s, "T_mac =", t_m); 1361 print_temp(s, "T_radio =", t_r); 1362 1363 return 0; 1364 } 1365 DEFINE_SHOW_ATTRIBUTE(temp); 1366 1367 /*---------freq------------*/ 1368 static int freq_show(struct seq_file *s, void *data) 1369 { 1370 struct wil6210_priv *wil = s->private; 1371 struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr; 1372 u32 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0; 1373 1374 seq_printf(s, "Freq = %d\n", freq); 1375 1376 return 0; 1377 } 1378 DEFINE_SHOW_ATTRIBUTE(freq); 1379 1380 /*---------link------------*/ 1381 static int link_show(struct seq_file *s, void *data) 1382 { 1383 struct wil6210_priv *wil = s->private; 1384 struct station_info *sinfo; 1385 int i, rc = 0; 1386 1387 sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL); 1388 if (!sinfo) 1389 return -ENOMEM; 1390 1391 for (i = 0; i < wil->max_assoc_sta; i++) { 1392 struct wil_sta_info *p = &wil->sta[i]; 1393 char *status = "unknown"; 1394 struct wil6210_vif *vif; 1395 u8 mid; 1396 1397 switch (p->status) { 1398 case wil_sta_unused: 1399 status = "unused "; 1400 break; 1401 case wil_sta_conn_pending: 1402 status = "pending "; 1403 break; 1404 case wil_sta_connected: 1405 status = "connected"; 1406 break; 1407 } 1408 mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX; 1409 seq_printf(s, "[%d][MID %d] %pM %s\n", 1410 i, mid, p->addr, status); 1411 1412 if (p->status != wil_sta_connected) 1413 continue; 1414 1415 vif = (mid < GET_MAX_VIFS(wil)) ? wil->vifs[mid] : NULL; 1416 if (vif) { 1417 rc = wil_cid_fill_sinfo(vif, i, sinfo); 1418 if (rc) 1419 goto out; 1420 1421 seq_printf(s, " Tx_mcs = %d\n", sinfo->txrate.mcs); 1422 seq_printf(s, " Rx_mcs = %d\n", sinfo->rxrate.mcs); 1423 seq_printf(s, " SQ = %d\n", sinfo->signal); 1424 } else { 1425 seq_puts(s, " INVALID MID\n"); 1426 } 1427 } 1428 1429 out: 1430 kfree(sinfo); 1431 return rc; 1432 } 1433 DEFINE_SHOW_ATTRIBUTE(link); 1434 1435 /*---------info------------*/ 1436 static int info_show(struct seq_file *s, void *data) 1437 { 1438 struct wil6210_priv *wil = s->private; 1439 struct net_device *ndev = wil->main_ndev; 1440 int is_ac = power_supply_is_system_supplied(); 1441 int rx = atomic_xchg(&wil->isr_count_rx, 0); 1442 int tx = atomic_xchg(&wil->isr_count_tx, 0); 1443 static ulong rxf_old, txf_old; 1444 ulong rxf = ndev->stats.rx_packets; 1445 ulong txf = ndev->stats.tx_packets; 1446 unsigned int i; 1447 1448 /* >0 : AC; 0 : battery; <0 : error */ 1449 seq_printf(s, "AC powered : %d\n", is_ac); 1450 seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old); 1451 seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old); 1452 rxf_old = rxf; 1453 txf_old = txf; 1454 1455 #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \ 1456 " " __stringify(x) : "" 1457 1458 for (i = 0; i < ndev->num_tx_queues; i++) { 1459 struct netdev_queue *txq = netdev_get_tx_queue(ndev, i); 1460 unsigned long state = txq->state; 1461 1462 seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state, 1463 CHECK_QSTATE(DRV_XOFF), 1464 CHECK_QSTATE(STACK_XOFF), 1465 CHECK_QSTATE(FROZEN) 1466 ); 1467 } 1468 #undef CHECK_QSTATE 1469 return 0; 1470 } 1471 DEFINE_SHOW_ATTRIBUTE(info); 1472 1473 /*---------recovery------------*/ 1474 /* mode = [manual|auto] 1475 * state = [idle|pending|running] 1476 */ 1477 static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf, 1478 size_t count, loff_t *ppos) 1479 { 1480 struct wil6210_priv *wil = file->private_data; 1481 char buf[80]; 1482 int n; 1483 static const char * const sstate[] = {"idle", "pending", "running"}; 1484 1485 n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n", 1486 no_fw_recovery ? "manual" : "auto", 1487 sstate[wil->recovery_state]); 1488 1489 n = min_t(int, n, sizeof(buf)); 1490 1491 return simple_read_from_buffer(user_buf, count, ppos, 1492 buf, n); 1493 } 1494 1495 static ssize_t wil_write_file_recovery(struct file *file, 1496 const char __user *buf_, 1497 size_t count, loff_t *ppos) 1498 { 1499 struct wil6210_priv *wil = file->private_data; 1500 static const char run_command[] = "run"; 1501 char buf[sizeof(run_command) + 1]; /* to detect "runx" */ 1502 ssize_t rc; 1503 1504 if (wil->recovery_state != fw_recovery_pending) { 1505 wil_err(wil, "No recovery pending\n"); 1506 return -EINVAL; 1507 } 1508 1509 if (*ppos != 0) { 1510 wil_err(wil, "Offset [%d]\n", (int)*ppos); 1511 return -EINVAL; 1512 } 1513 1514 if (count > sizeof(buf)) { 1515 wil_err(wil, "Input too long, len = %d\n", (int)count); 1516 return -EINVAL; 1517 } 1518 1519 rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count); 1520 if (rc < 0) 1521 return rc; 1522 1523 buf[rc] = '\0'; 1524 if (0 == strcmp(buf, run_command)) 1525 wil_set_recovery_state(wil, fw_recovery_running); 1526 else 1527 wil_err(wil, "Bad recovery command \"%s\"\n", buf); 1528 1529 return rc; 1530 } 1531 1532 static const struct file_operations fops_recovery = { 1533 .read = wil_read_file_recovery, 1534 .write = wil_write_file_recovery, 1535 .open = simple_open, 1536 }; 1537 1538 /*---------Station matrix------------*/ 1539 static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r) 1540 { 1541 int i; 1542 u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size; 1543 unsigned long long drop_dup = r->drop_dup, drop_old = r->drop_old; 1544 unsigned long long drop_dup_mcast = r->drop_dup_mcast; 1545 1546 seq_printf(s, "([%2d]) 0x%03x [", r->buf_size, r->head_seq_num); 1547 for (i = 0; i < r->buf_size; i++) { 1548 if (i == index) 1549 seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|'); 1550 else 1551 seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_'); 1552 } 1553 seq_printf(s, 1554 "] total %llu drop %llu (dup %llu + old %llu + dup mcast %llu) last 0x%03x\n", 1555 r->total, drop_dup + drop_old + drop_dup_mcast, drop_dup, 1556 drop_old, drop_dup_mcast, r->ssn_last_drop); 1557 } 1558 1559 static void wil_print_rxtid_crypto(struct seq_file *s, int tid, 1560 struct wil_tid_crypto_rx *c) 1561 { 1562 int i; 1563 1564 for (i = 0; i < 4; i++) { 1565 struct wil_tid_crypto_rx_single *cc = &c->key_id[i]; 1566 1567 if (cc->key_set) 1568 goto has_keys; 1569 } 1570 return; 1571 1572 has_keys: 1573 if (tid < WIL_STA_TID_NUM) 1574 seq_printf(s, " [%2d] PN", tid); 1575 else 1576 seq_puts(s, " [GR] PN"); 1577 1578 for (i = 0; i < 4; i++) { 1579 struct wil_tid_crypto_rx_single *cc = &c->key_id[i]; 1580 1581 seq_printf(s, " [%i%s]%6phN", i, cc->key_set ? "+" : "-", 1582 cc->pn); 1583 } 1584 seq_puts(s, "\n"); 1585 } 1586 1587 static int sta_show(struct seq_file *s, void *data) 1588 __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock) 1589 { 1590 struct wil6210_priv *wil = s->private; 1591 int i, tid, mcs; 1592 1593 for (i = 0; i < wil->max_assoc_sta; i++) { 1594 struct wil_sta_info *p = &wil->sta[i]; 1595 char *status = "unknown"; 1596 u8 aid = 0; 1597 u8 mid; 1598 bool sta_connected = false; 1599 1600 switch (p->status) { 1601 case wil_sta_unused: 1602 status = "unused "; 1603 break; 1604 case wil_sta_conn_pending: 1605 status = "pending "; 1606 break; 1607 case wil_sta_connected: 1608 status = "connected"; 1609 aid = p->aid; 1610 break; 1611 } 1612 mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX; 1613 if (mid < GET_MAX_VIFS(wil)) { 1614 struct wil6210_vif *vif = wil->vifs[mid]; 1615 1616 if (vif->wdev.iftype == NL80211_IFTYPE_STATION && 1617 p->status == wil_sta_connected) 1618 sta_connected = true; 1619 } 1620 /* print roam counter only for connected stations */ 1621 if (sta_connected) 1622 seq_printf(s, "[%d] %pM connected (roam counter %d) MID %d AID %d\n", 1623 i, p->addr, p->stats.ft_roams, mid, aid); 1624 else 1625 seq_printf(s, "[%d] %pM %s MID %d AID %d\n", i, 1626 p->addr, status, mid, aid); 1627 1628 if (p->status == wil_sta_connected) { 1629 spin_lock_bh(&p->tid_rx_lock); 1630 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) { 1631 struct wil_tid_ampdu_rx *r = p->tid_rx[tid]; 1632 struct wil_tid_crypto_rx *c = 1633 &p->tid_crypto_rx[tid]; 1634 1635 if (r) { 1636 seq_printf(s, " [%2d] ", tid); 1637 wil_print_rxtid(s, r); 1638 } 1639 1640 wil_print_rxtid_crypto(s, tid, c); 1641 } 1642 wil_print_rxtid_crypto(s, WIL_STA_TID_NUM, 1643 &p->group_crypto_rx); 1644 spin_unlock_bh(&p->tid_rx_lock); 1645 seq_printf(s, 1646 "Rx invalid frame: non-data %lu, short %lu, large %lu, replay %lu\n", 1647 p->stats.rx_non_data_frame, 1648 p->stats.rx_short_frame, 1649 p->stats.rx_large_frame, 1650 p->stats.rx_replay); 1651 seq_printf(s, 1652 "mic error %lu, key error %lu, amsdu error %lu, csum error %lu\n", 1653 p->stats.rx_mic_error, 1654 p->stats.rx_key_error, 1655 p->stats.rx_amsdu_error, 1656 p->stats.rx_csum_err); 1657 1658 seq_puts(s, "Rx/MCS:"); 1659 for (mcs = 0; mcs < ARRAY_SIZE(p->stats.rx_per_mcs); 1660 mcs++) 1661 seq_printf(s, " %lld", 1662 p->stats.rx_per_mcs[mcs]); 1663 seq_puts(s, "\n"); 1664 } 1665 } 1666 1667 return 0; 1668 } 1669 DEFINE_SHOW_ATTRIBUTE(sta); 1670 1671 static int mids_show(struct seq_file *s, void *data) 1672 { 1673 struct wil6210_priv *wil = s->private; 1674 struct wil6210_vif *vif; 1675 struct net_device *ndev; 1676 int i; 1677 1678 mutex_lock(&wil->vif_mutex); 1679 for (i = 0; i < GET_MAX_VIFS(wil); i++) { 1680 vif = wil->vifs[i]; 1681 1682 if (vif) { 1683 ndev = vif_to_ndev(vif); 1684 seq_printf(s, "[%d] %pM %s\n", i, ndev->dev_addr, 1685 ndev->name); 1686 } else { 1687 seq_printf(s, "[%d] unused\n", i); 1688 } 1689 } 1690 mutex_unlock(&wil->vif_mutex); 1691 1692 return 0; 1693 } 1694 DEFINE_SHOW_ATTRIBUTE(mids); 1695 1696 static int wil_tx_latency_debugfs_show(struct seq_file *s, void *data) 1697 __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock) 1698 { 1699 struct wil6210_priv *wil = s->private; 1700 int i, bin; 1701 1702 for (i = 0; i < wil->max_assoc_sta; i++) { 1703 struct wil_sta_info *p = &wil->sta[i]; 1704 char *status = "unknown"; 1705 u8 aid = 0; 1706 u8 mid; 1707 1708 if (!p->tx_latency_bins) 1709 continue; 1710 1711 switch (p->status) { 1712 case wil_sta_unused: 1713 status = "unused "; 1714 break; 1715 case wil_sta_conn_pending: 1716 status = "pending "; 1717 break; 1718 case wil_sta_connected: 1719 status = "connected"; 1720 aid = p->aid; 1721 break; 1722 } 1723 mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX; 1724 seq_printf(s, "[%d] %pM %s MID %d AID %d\n", i, p->addr, status, 1725 mid, aid); 1726 1727 if (p->status == wil_sta_connected) { 1728 u64 num_packets = 0; 1729 u64 tx_latency_avg = p->stats.tx_latency_total_us; 1730 1731 seq_puts(s, "Tx/Latency bin:"); 1732 for (bin = 0; bin < WIL_NUM_LATENCY_BINS; bin++) { 1733 seq_printf(s, " %lld", 1734 p->tx_latency_bins[bin]); 1735 num_packets += p->tx_latency_bins[bin]; 1736 } 1737 seq_puts(s, "\n"); 1738 if (!num_packets) 1739 continue; 1740 do_div(tx_latency_avg, num_packets); 1741 seq_printf(s, "Tx/Latency min/avg/max (us): %d/%lld/%d", 1742 p->stats.tx_latency_min_us, 1743 tx_latency_avg, 1744 p->stats.tx_latency_max_us); 1745 1746 seq_puts(s, "\n"); 1747 } 1748 } 1749 1750 return 0; 1751 } 1752 1753 static int wil_tx_latency_seq_open(struct inode *inode, struct file *file) 1754 { 1755 return single_open(file, wil_tx_latency_debugfs_show, 1756 inode->i_private); 1757 } 1758 1759 static ssize_t wil_tx_latency_write(struct file *file, const char __user *buf, 1760 size_t len, loff_t *ppos) 1761 { 1762 struct seq_file *s = file->private_data; 1763 struct wil6210_priv *wil = s->private; 1764 int val, rc, i; 1765 bool enable; 1766 1767 rc = kstrtoint_from_user(buf, len, 0, &val); 1768 if (rc) { 1769 wil_err(wil, "Invalid argument\n"); 1770 return rc; 1771 } 1772 if (val == 1) 1773 /* default resolution */ 1774 val = 500; 1775 if (val && (val < 50 || val > 1000)) { 1776 wil_err(wil, "Invalid resolution %d\n", val); 1777 return -EINVAL; 1778 } 1779 1780 enable = !!val; 1781 if (wil->tx_latency == enable) 1782 return len; 1783 1784 wil_info(wil, "%s TX latency measurements (resolution %dusec)\n", 1785 enable ? "Enabling" : "Disabling", val); 1786 1787 if (enable) { 1788 size_t sz = sizeof(u64) * WIL_NUM_LATENCY_BINS; 1789 1790 wil->tx_latency_res = val; 1791 for (i = 0; i < wil->max_assoc_sta; i++) { 1792 struct wil_sta_info *sta = &wil->sta[i]; 1793 1794 kfree(sta->tx_latency_bins); 1795 sta->tx_latency_bins = kzalloc(sz, GFP_KERNEL); 1796 if (!sta->tx_latency_bins) 1797 return -ENOMEM; 1798 sta->stats.tx_latency_min_us = U32_MAX; 1799 sta->stats.tx_latency_max_us = 0; 1800 sta->stats.tx_latency_total_us = 0; 1801 } 1802 } 1803 wil->tx_latency = enable; 1804 1805 return len; 1806 } 1807 1808 static const struct file_operations fops_tx_latency = { 1809 .open = wil_tx_latency_seq_open, 1810 .release = single_release, 1811 .read = seq_read, 1812 .write = wil_tx_latency_write, 1813 .llseek = seq_lseek, 1814 }; 1815 1816 static void wil_link_stats_print_basic(struct wil6210_vif *vif, 1817 struct seq_file *s, 1818 struct wmi_link_stats_basic *basic) 1819 { 1820 char per[5] = "?"; 1821 1822 if (basic->per_average != 0xff) 1823 snprintf(per, sizeof(per), "%d%%", basic->per_average); 1824 1825 seq_printf(s, "CID %d {\n" 1826 "\tTxMCS %d TxTpt %d\n" 1827 "\tGoodput(rx:tx) %d:%d\n" 1828 "\tRxBcastFrames %d\n" 1829 "\tRSSI %d SQI %d SNR %d PER %s\n" 1830 "\tRx RFC %d Ant num %d\n" 1831 "\tSectors(rx:tx) my %d:%d peer %d:%d\n" 1832 "}\n", 1833 basic->cid, 1834 basic->bf_mcs, le32_to_cpu(basic->tx_tpt), 1835 le32_to_cpu(basic->rx_goodput), 1836 le32_to_cpu(basic->tx_goodput), 1837 le32_to_cpu(basic->rx_bcast_frames), 1838 basic->rssi, basic->sqi, basic->snr, per, 1839 basic->selected_rfc, basic->rx_effective_ant_num, 1840 basic->my_rx_sector, basic->my_tx_sector, 1841 basic->other_rx_sector, basic->other_tx_sector); 1842 } 1843 1844 static void wil_link_stats_print_global(struct wil6210_priv *wil, 1845 struct seq_file *s, 1846 struct wmi_link_stats_global *global) 1847 { 1848 seq_printf(s, "Frames(rx:tx) %d:%d\n" 1849 "BA Frames(rx:tx) %d:%d\n" 1850 "Beacons %d\n" 1851 "Rx Errors (MIC:CRC) %d:%d\n" 1852 "Tx Errors (no ack) %d\n", 1853 le32_to_cpu(global->rx_frames), 1854 le32_to_cpu(global->tx_frames), 1855 le32_to_cpu(global->rx_ba_frames), 1856 le32_to_cpu(global->tx_ba_frames), 1857 le32_to_cpu(global->tx_beacons), 1858 le32_to_cpu(global->rx_mic_errors), 1859 le32_to_cpu(global->rx_crc_errors), 1860 le32_to_cpu(global->tx_fail_no_ack)); 1861 } 1862 1863 static void wil_link_stats_debugfs_show_vif(struct wil6210_vif *vif, 1864 struct seq_file *s) 1865 { 1866 struct wil6210_priv *wil = vif_to_wil(vif); 1867 struct wmi_link_stats_basic *stats; 1868 int i; 1869 1870 if (!vif->fw_stats_ready) { 1871 seq_puts(s, "no statistics\n"); 1872 return; 1873 } 1874 1875 seq_printf(s, "TSF %lld\n", vif->fw_stats_tsf); 1876 for (i = 0; i < wil->max_assoc_sta; i++) { 1877 if (wil->sta[i].status == wil_sta_unused) 1878 continue; 1879 if (wil->sta[i].mid != vif->mid) 1880 continue; 1881 1882 stats = &wil->sta[i].fw_stats_basic; 1883 wil_link_stats_print_basic(vif, s, stats); 1884 } 1885 } 1886 1887 static int wil_link_stats_debugfs_show(struct seq_file *s, void *data) 1888 { 1889 struct wil6210_priv *wil = s->private; 1890 struct wil6210_vif *vif; 1891 int i, rc; 1892 1893 rc = mutex_lock_interruptible(&wil->vif_mutex); 1894 if (rc) 1895 return rc; 1896 1897 /* iterate over all MIDs and show per-cid statistics. Then show the 1898 * global statistics 1899 */ 1900 for (i = 0; i < GET_MAX_VIFS(wil); i++) { 1901 vif = wil->vifs[i]; 1902 1903 seq_printf(s, "MID %d ", i); 1904 if (!vif) { 1905 seq_puts(s, "unused\n"); 1906 continue; 1907 } 1908 1909 wil_link_stats_debugfs_show_vif(vif, s); 1910 } 1911 1912 mutex_unlock(&wil->vif_mutex); 1913 1914 return 0; 1915 } 1916 1917 static int wil_link_stats_seq_open(struct inode *inode, struct file *file) 1918 { 1919 return single_open(file, wil_link_stats_debugfs_show, inode->i_private); 1920 } 1921 1922 static ssize_t wil_link_stats_write(struct file *file, const char __user *buf, 1923 size_t len, loff_t *ppos) 1924 { 1925 struct seq_file *s = file->private_data; 1926 struct wil6210_priv *wil = s->private; 1927 int cid, interval, rc, i; 1928 struct wil6210_vif *vif; 1929 char *kbuf = kmalloc(len + 1, GFP_KERNEL); 1930 1931 if (!kbuf) 1932 return -ENOMEM; 1933 1934 rc = simple_write_to_buffer(kbuf, len, ppos, buf, len); 1935 if (rc != len) { 1936 kfree(kbuf); 1937 return rc >= 0 ? -EIO : rc; 1938 } 1939 1940 kbuf[len] = '\0'; 1941 /* specify cid (use -1 for all cids) and snapshot interval in ms */ 1942 rc = sscanf(kbuf, "%d %d", &cid, &interval); 1943 kfree(kbuf); 1944 if (rc < 0) 1945 return rc; 1946 if (rc < 2 || interval < 0) 1947 return -EINVAL; 1948 1949 wil_info(wil, "request link statistics, cid %d interval %d\n", 1950 cid, interval); 1951 1952 rc = mutex_lock_interruptible(&wil->vif_mutex); 1953 if (rc) 1954 return rc; 1955 1956 for (i = 0; i < GET_MAX_VIFS(wil); i++) { 1957 vif = wil->vifs[i]; 1958 if (!vif) 1959 continue; 1960 1961 rc = wmi_link_stats_cfg(vif, WMI_LINK_STATS_TYPE_BASIC, 1962 (cid == -1 ? 0xff : cid), interval); 1963 if (rc) 1964 wil_err(wil, "link statistics failed for mid %d\n", i); 1965 } 1966 mutex_unlock(&wil->vif_mutex); 1967 1968 return len; 1969 } 1970 1971 static const struct file_operations fops_link_stats = { 1972 .open = wil_link_stats_seq_open, 1973 .release = single_release, 1974 .read = seq_read, 1975 .write = wil_link_stats_write, 1976 .llseek = seq_lseek, 1977 }; 1978 1979 static int 1980 wil_link_stats_global_debugfs_show(struct seq_file *s, void *data) 1981 { 1982 struct wil6210_priv *wil = s->private; 1983 1984 if (!wil->fw_stats_global.ready) 1985 return 0; 1986 1987 seq_printf(s, "TSF %lld\n", wil->fw_stats_global.tsf); 1988 wil_link_stats_print_global(wil, s, &wil->fw_stats_global.stats); 1989 1990 return 0; 1991 } 1992 1993 static int 1994 wil_link_stats_global_seq_open(struct inode *inode, struct file *file) 1995 { 1996 return single_open(file, wil_link_stats_global_debugfs_show, 1997 inode->i_private); 1998 } 1999 2000 static ssize_t 2001 wil_link_stats_global_write(struct file *file, const char __user *buf, 2002 size_t len, loff_t *ppos) 2003 { 2004 struct seq_file *s = file->private_data; 2005 struct wil6210_priv *wil = s->private; 2006 int interval, rc; 2007 struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev); 2008 2009 /* specify snapshot interval in ms */ 2010 rc = kstrtoint_from_user(buf, len, 0, &interval); 2011 if (rc || interval < 0) { 2012 wil_err(wil, "Invalid argument\n"); 2013 return -EINVAL; 2014 } 2015 2016 wil_info(wil, "request global link stats, interval %d\n", interval); 2017 2018 rc = wmi_link_stats_cfg(vif, WMI_LINK_STATS_TYPE_GLOBAL, 0, interval); 2019 if (rc) 2020 wil_err(wil, "global link stats failed %d\n", rc); 2021 2022 return rc ? rc : len; 2023 } 2024 2025 static const struct file_operations fops_link_stats_global = { 2026 .open = wil_link_stats_global_seq_open, 2027 .release = single_release, 2028 .read = seq_read, 2029 .write = wil_link_stats_global_write, 2030 .llseek = seq_lseek, 2031 }; 2032 2033 static ssize_t wil_read_file_led_cfg(struct file *file, char __user *user_buf, 2034 size_t count, loff_t *ppos) 2035 { 2036 char buf[80]; 2037 int n; 2038 2039 n = snprintf(buf, sizeof(buf), 2040 "led_id is set to %d, echo 1 to enable, 0 to disable\n", 2041 led_id); 2042 2043 n = min_t(int, n, sizeof(buf)); 2044 2045 return simple_read_from_buffer(user_buf, count, ppos, 2046 buf, n); 2047 } 2048 2049 static ssize_t wil_write_file_led_cfg(struct file *file, 2050 const char __user *buf_, 2051 size_t count, loff_t *ppos) 2052 { 2053 struct wil6210_priv *wil = file->private_data; 2054 int val; 2055 int rc; 2056 2057 rc = kstrtoint_from_user(buf_, count, 0, &val); 2058 if (rc) { 2059 wil_err(wil, "Invalid argument\n"); 2060 return rc; 2061 } 2062 2063 wil_info(wil, "%s led %d\n", val ? "Enabling" : "Disabling", led_id); 2064 rc = wmi_led_cfg(wil, val); 2065 if (rc) { 2066 wil_info(wil, "%s led %d failed\n", 2067 val ? "Enabling" : "Disabling", led_id); 2068 return rc; 2069 } 2070 2071 return count; 2072 } 2073 2074 static const struct file_operations fops_led_cfg = { 2075 .read = wil_read_file_led_cfg, 2076 .write = wil_write_file_led_cfg, 2077 .open = simple_open, 2078 }; 2079 2080 /* led_blink_time, write: 2081 * "<blink_on_slow> <blink_off_slow> <blink_on_med> <blink_off_med> <blink_on_fast> <blink_off_fast> 2082 */ 2083 static ssize_t wil_write_led_blink_time(struct file *file, 2084 const char __user *buf, 2085 size_t len, loff_t *ppos) 2086 { 2087 int rc; 2088 char *kbuf = kmalloc(len + 1, GFP_KERNEL); 2089 2090 if (!kbuf) 2091 return -ENOMEM; 2092 2093 rc = simple_write_to_buffer(kbuf, len, ppos, buf, len); 2094 if (rc != len) { 2095 kfree(kbuf); 2096 return rc >= 0 ? -EIO : rc; 2097 } 2098 2099 kbuf[len] = '\0'; 2100 rc = sscanf(kbuf, "%d %d %d %d %d %d", 2101 &led_blink_time[WIL_LED_TIME_SLOW].on_ms, 2102 &led_blink_time[WIL_LED_TIME_SLOW].off_ms, 2103 &led_blink_time[WIL_LED_TIME_MED].on_ms, 2104 &led_blink_time[WIL_LED_TIME_MED].off_ms, 2105 &led_blink_time[WIL_LED_TIME_FAST].on_ms, 2106 &led_blink_time[WIL_LED_TIME_FAST].off_ms); 2107 kfree(kbuf); 2108 2109 if (rc < 0) 2110 return rc; 2111 if (rc < 6) 2112 return -EINVAL; 2113 2114 return len; 2115 } 2116 2117 static ssize_t wil_read_led_blink_time(struct file *file, char __user *user_buf, 2118 size_t count, loff_t *ppos) 2119 { 2120 static char text[400]; 2121 2122 snprintf(text, sizeof(text), 2123 "To set led blink on/off time variables write:\n" 2124 "<blink_on_slow> <blink_off_slow> <blink_on_med> " 2125 "<blink_off_med> <blink_on_fast> <blink_off_fast>\n" 2126 "The current values are:\n" 2127 "%d %d %d %d %d %d\n", 2128 led_blink_time[WIL_LED_TIME_SLOW].on_ms, 2129 led_blink_time[WIL_LED_TIME_SLOW].off_ms, 2130 led_blink_time[WIL_LED_TIME_MED].on_ms, 2131 led_blink_time[WIL_LED_TIME_MED].off_ms, 2132 led_blink_time[WIL_LED_TIME_FAST].on_ms, 2133 led_blink_time[WIL_LED_TIME_FAST].off_ms); 2134 2135 return simple_read_from_buffer(user_buf, count, ppos, text, 2136 sizeof(text)); 2137 } 2138 2139 static const struct file_operations fops_led_blink_time = { 2140 .read = wil_read_led_blink_time, 2141 .write = wil_write_led_blink_time, 2142 .open = simple_open, 2143 }; 2144 2145 /*---------FW capabilities------------*/ 2146 static int wil_fw_capabilities_debugfs_show(struct seq_file *s, void *data) 2147 { 2148 struct wil6210_priv *wil = s->private; 2149 2150 seq_printf(s, "fw_capabilities : %*pb\n", WMI_FW_CAPABILITY_MAX, 2151 wil->fw_capabilities); 2152 2153 return 0; 2154 } 2155 2156 static int wil_fw_capabilities_seq_open(struct inode *inode, struct file *file) 2157 { 2158 return single_open(file, wil_fw_capabilities_debugfs_show, 2159 inode->i_private); 2160 } 2161 2162 static const struct file_operations fops_fw_capabilities = { 2163 .open = wil_fw_capabilities_seq_open, 2164 .release = single_release, 2165 .read = seq_read, 2166 .llseek = seq_lseek, 2167 }; 2168 2169 /*---------FW version------------*/ 2170 static int wil_fw_version_debugfs_show(struct seq_file *s, void *data) 2171 { 2172 struct wil6210_priv *wil = s->private; 2173 2174 if (wil->fw_version[0]) 2175 seq_printf(s, "%s\n", wil->fw_version); 2176 else 2177 seq_puts(s, "N/A\n"); 2178 2179 return 0; 2180 } 2181 2182 static int wil_fw_version_seq_open(struct inode *inode, struct file *file) 2183 { 2184 return single_open(file, wil_fw_version_debugfs_show, 2185 inode->i_private); 2186 } 2187 2188 static const struct file_operations fops_fw_version = { 2189 .open = wil_fw_version_seq_open, 2190 .release = single_release, 2191 .read = seq_read, 2192 .llseek = seq_lseek, 2193 }; 2194 2195 /*---------suspend_stats---------*/ 2196 static ssize_t wil_write_suspend_stats(struct file *file, 2197 const char __user *buf, 2198 size_t len, loff_t *ppos) 2199 { 2200 struct wil6210_priv *wil = file->private_data; 2201 2202 memset(&wil->suspend_stats, 0, sizeof(wil->suspend_stats)); 2203 2204 return len; 2205 } 2206 2207 static ssize_t wil_read_suspend_stats(struct file *file, 2208 char __user *user_buf, 2209 size_t count, loff_t *ppos) 2210 { 2211 struct wil6210_priv *wil = file->private_data; 2212 char *text; 2213 int n, ret, text_size = 500; 2214 2215 text = kmalloc(text_size, GFP_KERNEL); 2216 if (!text) 2217 return -ENOMEM; 2218 2219 n = snprintf(text, text_size, 2220 "Radio on suspend statistics:\n" 2221 "successful suspends:%ld failed suspends:%ld\n" 2222 "successful resumes:%ld failed resumes:%ld\n" 2223 "rejected by device:%ld\n" 2224 "Radio off suspend statistics:\n" 2225 "successful suspends:%ld failed suspends:%ld\n" 2226 "successful resumes:%ld failed resumes:%ld\n" 2227 "General statistics:\n" 2228 "rejected by host:%ld\n", 2229 wil->suspend_stats.r_on.successful_suspends, 2230 wil->suspend_stats.r_on.failed_suspends, 2231 wil->suspend_stats.r_on.successful_resumes, 2232 wil->suspend_stats.r_on.failed_resumes, 2233 wil->suspend_stats.rejected_by_device, 2234 wil->suspend_stats.r_off.successful_suspends, 2235 wil->suspend_stats.r_off.failed_suspends, 2236 wil->suspend_stats.r_off.successful_resumes, 2237 wil->suspend_stats.r_off.failed_resumes, 2238 wil->suspend_stats.rejected_by_host); 2239 2240 n = min_t(int, n, text_size); 2241 2242 ret = simple_read_from_buffer(user_buf, count, ppos, text, n); 2243 2244 kfree(text); 2245 2246 return ret; 2247 } 2248 2249 static const struct file_operations fops_suspend_stats = { 2250 .read = wil_read_suspend_stats, 2251 .write = wil_write_suspend_stats, 2252 .open = simple_open, 2253 }; 2254 2255 /*---------compressed_rx_status---------*/ 2256 static ssize_t wil_compressed_rx_status_write(struct file *file, 2257 const char __user *buf, 2258 size_t len, loff_t *ppos) 2259 { 2260 struct seq_file *s = file->private_data; 2261 struct wil6210_priv *wil = s->private; 2262 int compressed_rx_status; 2263 int rc; 2264 2265 rc = kstrtoint_from_user(buf, len, 0, &compressed_rx_status); 2266 if (rc) { 2267 wil_err(wil, "Invalid argument\n"); 2268 return rc; 2269 } 2270 2271 if (wil_has_active_ifaces(wil, true, false)) { 2272 wil_err(wil, "cannot change edma config after iface is up\n"); 2273 return -EPERM; 2274 } 2275 2276 wil_info(wil, "%sable compressed_rx_status\n", 2277 compressed_rx_status ? "En" : "Dis"); 2278 2279 wil->use_compressed_rx_status = compressed_rx_status; 2280 2281 return len; 2282 } 2283 2284 static int 2285 wil_compressed_rx_status_show(struct seq_file *s, void *data) 2286 { 2287 struct wil6210_priv *wil = s->private; 2288 2289 seq_printf(s, "%d\n", wil->use_compressed_rx_status); 2290 2291 return 0; 2292 } 2293 2294 static int 2295 wil_compressed_rx_status_seq_open(struct inode *inode, struct file *file) 2296 { 2297 return single_open(file, wil_compressed_rx_status_show, 2298 inode->i_private); 2299 } 2300 2301 static const struct file_operations fops_compressed_rx_status = { 2302 .open = wil_compressed_rx_status_seq_open, 2303 .release = single_release, 2304 .read = seq_read, 2305 .write = wil_compressed_rx_status_write, 2306 .llseek = seq_lseek, 2307 }; 2308 2309 /*----------------*/ 2310 static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil, 2311 struct dentry *dbg) 2312 { 2313 int i; 2314 char name[32]; 2315 2316 for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) { 2317 struct wil_blob_wrapper *wil_blob = &wil->blobs[i]; 2318 struct debugfs_blob_wrapper *blob = &wil_blob->blob; 2319 const struct fw_map *map = &fw_mapping[i]; 2320 2321 if (!map->name) 2322 continue; 2323 2324 wil_blob->wil = wil; 2325 blob->data = (void * __force)wil->csr + HOSTADDR(map->host); 2326 blob->size = map->to - map->from; 2327 snprintf(name, sizeof(name), "blob_%s", map->name); 2328 wil_debugfs_create_ioblob(name, 0444, dbg, wil_blob); 2329 } 2330 } 2331 2332 /* misc files */ 2333 static const struct { 2334 const char *name; 2335 umode_t mode; 2336 const struct file_operations *fops; 2337 } dbg_files[] = { 2338 {"mbox", 0444, &mbox_fops}, 2339 {"rings", 0444, &ring_fops}, 2340 {"stations", 0444, &sta_fops}, 2341 {"mids", 0444, &mids_fops}, 2342 {"desc", 0444, &txdesc_fops}, 2343 {"bf", 0444, &bf_fops}, 2344 {"mem_val", 0644, &memread_fops}, 2345 {"rxon", 0244, &fops_rxon}, 2346 {"tx_mgmt", 0244, &fops_txmgmt}, 2347 {"wmi_send", 0244, &fops_wmi}, 2348 {"back", 0644, &fops_back}, 2349 {"pmccfg", 0644, &fops_pmccfg}, 2350 {"pmcdata", 0444, &fops_pmcdata}, 2351 {"temp", 0444, &temp_fops}, 2352 {"freq", 0444, &freq_fops}, 2353 {"link", 0444, &link_fops}, 2354 {"info", 0444, &info_fops}, 2355 {"recovery", 0644, &fops_recovery}, 2356 {"led_cfg", 0644, &fops_led_cfg}, 2357 {"led_blink_time", 0644, &fops_led_blink_time}, 2358 {"fw_capabilities", 0444, &fops_fw_capabilities}, 2359 {"fw_version", 0444, &fops_fw_version}, 2360 {"suspend_stats", 0644, &fops_suspend_stats}, 2361 {"compressed_rx_status", 0644, &fops_compressed_rx_status}, 2362 {"srings", 0444, &srings_fops}, 2363 {"status_msg", 0444, &status_msg_fops}, 2364 {"rx_buff_mgmt", 0444, &rx_buff_mgmt_fops}, 2365 {"tx_latency", 0644, &fops_tx_latency}, 2366 {"link_stats", 0644, &fops_link_stats}, 2367 {"link_stats_global", 0644, &fops_link_stats_global}, 2368 {"rbufcap", 0244, &fops_rbufcap}, 2369 }; 2370 2371 static void wil6210_debugfs_init_files(struct wil6210_priv *wil, 2372 struct dentry *dbg) 2373 { 2374 int i; 2375 2376 for (i = 0; i < ARRAY_SIZE(dbg_files); i++) 2377 debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg, 2378 wil, dbg_files[i].fops); 2379 } 2380 2381 /* interrupt control blocks */ 2382 static const struct { 2383 const char *name; 2384 u32 icr_off; 2385 } dbg_icr[] = { 2386 {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)}, 2387 {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)}, 2388 {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)}, 2389 {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)}, 2390 }; 2391 2392 static void wil6210_debugfs_init_isr(struct wil6210_priv *wil, 2393 struct dentry *dbg) 2394 { 2395 int i; 2396 2397 for (i = 0; i < ARRAY_SIZE(dbg_icr); i++) 2398 wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg, 2399 dbg_icr[i].icr_off); 2400 } 2401 2402 #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \ 2403 offsetof(struct wil6210_priv, name), type} 2404 2405 /* fields in struct wil6210_priv */ 2406 static const struct dbg_off dbg_wil_off[] = { 2407 WIL_FIELD(status[0], 0644, doff_ulong), 2408 WIL_FIELD(hw_version, 0444, doff_x32), 2409 WIL_FIELD(recovery_count, 0444, doff_u32), 2410 WIL_FIELD(discovery_mode, 0644, doff_u8), 2411 WIL_FIELD(chip_revision, 0444, doff_u8), 2412 WIL_FIELD(abft_len, 0644, doff_u8), 2413 WIL_FIELD(wakeup_trigger, 0644, doff_u8), 2414 WIL_FIELD(ring_idle_trsh, 0644, doff_u32), 2415 WIL_FIELD(num_rx_status_rings, 0644, doff_u8), 2416 WIL_FIELD(rx_status_ring_order, 0644, doff_u32), 2417 WIL_FIELD(tx_status_ring_order, 0644, doff_u32), 2418 WIL_FIELD(rx_buff_id_count, 0644, doff_u32), 2419 WIL_FIELD(amsdu_en, 0644, doff_u8), 2420 {}, 2421 }; 2422 2423 static const struct dbg_off dbg_wil_regs[] = { 2424 {"RGF_MAC_MTRL_COUNTER_0", 0444, HOSTADDR(RGF_MAC_MTRL_COUNTER_0), 2425 doff_io32}, 2426 {"RGF_USER_USAGE_1", 0444, HOSTADDR(RGF_USER_USAGE_1), doff_io32}, 2427 {"RGF_USER_USAGE_2", 0444, HOSTADDR(RGF_USER_USAGE_2), doff_io32}, 2428 {}, 2429 }; 2430 2431 /* static parameters */ 2432 static const struct dbg_off dbg_statics[] = { 2433 {"desc_index", 0644, (ulong)&dbg_txdesc_index, doff_u32}, 2434 {"ring_index", 0644, (ulong)&dbg_ring_index, doff_u32}, 2435 {"mem_addr", 0644, (ulong)&mem_addr, doff_u32}, 2436 {"led_polarity", 0644, (ulong)&led_polarity, doff_u8}, 2437 {"status_index", 0644, (ulong)&dbg_status_msg_index, doff_u32}, 2438 {"sring_index", 0644, (ulong)&dbg_sring_index, doff_u32}, 2439 {"drop_if_ring_full", 0644, (ulong)&drop_if_ring_full, doff_u8}, 2440 {}, 2441 }; 2442 2443 static const int dbg_off_count = 4 * (ARRAY_SIZE(isr_off) - 1) + 2444 ARRAY_SIZE(dbg_wil_regs) - 1 + 2445 ARRAY_SIZE(pseudo_isr_off) - 1 + 2446 ARRAY_SIZE(lgc_itr_cnt_off) - 1 + 2447 ARRAY_SIZE(tx_itr_cnt_off) - 1 + 2448 ARRAY_SIZE(rx_itr_cnt_off) - 1; 2449 2450 int wil6210_debugfs_init(struct wil6210_priv *wil) 2451 { 2452 struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME, 2453 wil_to_wiphy(wil)->debugfsdir); 2454 if (IS_ERR_OR_NULL(dbg)) 2455 return -ENODEV; 2456 2457 wil->dbg_data.data_arr = kcalloc(dbg_off_count, 2458 sizeof(struct wil_debugfs_iomem_data), 2459 GFP_KERNEL); 2460 if (!wil->dbg_data.data_arr) { 2461 debugfs_remove_recursive(dbg); 2462 wil->debug = NULL; 2463 return -ENOMEM; 2464 } 2465 2466 wil->dbg_data.iomem_data_count = 0; 2467 2468 wil_pmc_init(wil); 2469 2470 wil6210_debugfs_init_files(wil, dbg); 2471 wil6210_debugfs_init_isr(wil, dbg); 2472 wil6210_debugfs_init_blobs(wil, dbg); 2473 wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off); 2474 wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr, 2475 dbg_wil_regs); 2476 wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics); 2477 2478 wil6210_debugfs_create_pseudo_ISR(wil, dbg); 2479 2480 wil6210_debugfs_create_ITR_CNT(wil, dbg); 2481 2482 return 0; 2483 } 2484 2485 void wil6210_debugfs_remove(struct wil6210_priv *wil) 2486 { 2487 int i; 2488 2489 debugfs_remove_recursive(wil->debug); 2490 wil->debug = NULL; 2491 2492 kfree(wil->dbg_data.data_arr); 2493 for (i = 0; i < wil->max_assoc_sta; i++) 2494 kfree(wil->sta[i].tx_latency_bins); 2495 2496 /* free pmc memory without sending command to fw, as it will 2497 * be reset on the way down anyway 2498 */ 2499 wil_pmc_free(wil, false); 2500 } 2501