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 skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; 1056 1057 len = skb_frag_size(frag); 1058 p = skb_frag_address_safe(frag); 1059 seq_printf(s, " [%2d] : len = %d\n", i, len); 1060 wil_seq_hexdump(s, p, len, " : "); 1061 } 1062 } 1063 } 1064 1065 /*---------Tx/Rx descriptor------------*/ 1066 static int txdesc_show(struct seq_file *s, void *data) 1067 { 1068 struct wil6210_priv *wil = s->private; 1069 struct wil_ring *ring; 1070 bool tx; 1071 int ring_idx = dbg_ring_index; 1072 int txdesc_idx = dbg_txdesc_index; 1073 volatile struct vring_tx_desc *d; 1074 volatile u32 *u; 1075 struct sk_buff *skb; 1076 1077 if (wil->use_enhanced_dma_hw) { 1078 /* RX ring index == 0 */ 1079 if (ring_idx >= WIL6210_MAX_TX_RINGS) { 1080 seq_printf(s, "invalid ring index %d\n", ring_idx); 1081 return 0; 1082 } 1083 tx = ring_idx > 0; /* desc ring 0 is reserved for RX */ 1084 } else { 1085 /* RX ring index == WIL6210_MAX_TX_RINGS */ 1086 if (ring_idx > WIL6210_MAX_TX_RINGS) { 1087 seq_printf(s, "invalid ring index %d\n", ring_idx); 1088 return 0; 1089 } 1090 tx = (ring_idx < WIL6210_MAX_TX_RINGS); 1091 } 1092 1093 ring = tx ? &wil->ring_tx[ring_idx] : &wil->ring_rx; 1094 1095 if (!ring->va) { 1096 if (tx) 1097 seq_printf(s, "No Tx[%2d] RING\n", ring_idx); 1098 else 1099 seq_puts(s, "No Rx RING\n"); 1100 return 0; 1101 } 1102 1103 if (txdesc_idx >= ring->size) { 1104 if (tx) 1105 seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n", 1106 ring_idx, txdesc_idx, ring->size); 1107 else 1108 seq_printf(s, "RxDesc index (%d) >= size (%d)\n", 1109 txdesc_idx, ring->size); 1110 return 0; 1111 } 1112 1113 /* use struct vring_tx_desc for Rx as well, 1114 * only field used, .dma.length, is the same 1115 */ 1116 d = &ring->va[txdesc_idx].tx.legacy; 1117 u = (volatile u32 *)d; 1118 skb = NULL; 1119 1120 if (wil->use_enhanced_dma_hw) { 1121 if (tx) { 1122 skb = ring->ctx ? ring->ctx[txdesc_idx].skb : NULL; 1123 } else if (wil->rx_buff_mgmt.buff_arr) { 1124 struct wil_rx_enhanced_desc *rx_d = 1125 (struct wil_rx_enhanced_desc *) 1126 &ring->va[txdesc_idx].rx.enhanced; 1127 u16 buff_id = le16_to_cpu(rx_d->mac.buff_id); 1128 1129 if (!wil_val_in_range(buff_id, 0, 1130 wil->rx_buff_mgmt.size)) 1131 seq_printf(s, "invalid buff_id %d\n", buff_id); 1132 else 1133 skb = wil->rx_buff_mgmt.buff_arr[buff_id].skb; 1134 } 1135 } else { 1136 skb = ring->ctx[txdesc_idx].skb; 1137 } 1138 if (tx) 1139 seq_printf(s, "Tx[%2d][%3d] = {\n", ring_idx, 1140 txdesc_idx); 1141 else 1142 seq_printf(s, "Rx[%3d] = {\n", txdesc_idx); 1143 seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n", 1144 u[0], u[1], u[2], u[3]); 1145 seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n", 1146 u[4], u[5], u[6], u[7]); 1147 seq_printf(s, " SKB = 0x%p\n", skb); 1148 1149 if (skb) { 1150 skb_get(skb); 1151 wil_seq_print_skb(s, skb); 1152 kfree_skb(skb); 1153 } 1154 seq_puts(s, "}\n"); 1155 1156 return 0; 1157 } 1158 DEFINE_SHOW_ATTRIBUTE(txdesc); 1159 1160 /*---------Tx/Rx status message------------*/ 1161 static int status_msg_show(struct seq_file *s, void *data) 1162 { 1163 struct wil6210_priv *wil = s->private; 1164 int sring_idx = dbg_sring_index; 1165 struct wil_status_ring *sring; 1166 bool tx; 1167 u32 status_msg_idx = dbg_status_msg_index; 1168 u32 *u; 1169 1170 if (sring_idx >= WIL6210_MAX_STATUS_RINGS) { 1171 seq_printf(s, "invalid status ring index %d\n", sring_idx); 1172 return 0; 1173 } 1174 1175 sring = &wil->srings[sring_idx]; 1176 tx = !sring->is_rx; 1177 1178 if (!sring->va) { 1179 seq_printf(s, "No %cX status ring\n", tx ? 'T' : 'R'); 1180 return 0; 1181 } 1182 1183 if (status_msg_idx >= sring->size) { 1184 seq_printf(s, "%cxDesc index (%d) >= size (%d)\n", 1185 tx ? 'T' : 'R', status_msg_idx, sring->size); 1186 return 0; 1187 } 1188 1189 u = sring->va + (sring->elem_size * status_msg_idx); 1190 1191 seq_printf(s, "%cx[%d][%3d] = {\n", 1192 tx ? 'T' : 'R', sring_idx, status_msg_idx); 1193 1194 seq_printf(s, " 0x%08x 0x%08x 0x%08x 0x%08x\n", 1195 u[0], u[1], u[2], u[3]); 1196 if (!tx && !wil->use_compressed_rx_status) 1197 seq_printf(s, " 0x%08x 0x%08x 0x%08x 0x%08x\n", 1198 u[4], u[5], u[6], u[7]); 1199 1200 seq_puts(s, "}\n"); 1201 1202 return 0; 1203 } 1204 DEFINE_SHOW_ATTRIBUTE(status_msg); 1205 1206 static int wil_print_rx_buff(struct seq_file *s, struct list_head *lh) 1207 { 1208 struct wil_rx_buff *it; 1209 int i = 0; 1210 1211 list_for_each_entry(it, lh, list) { 1212 if ((i % 16) == 0 && i != 0) 1213 seq_puts(s, "\n "); 1214 seq_printf(s, "[%4d] ", it->id); 1215 i++; 1216 } 1217 seq_printf(s, "\nNumber of buffers: %u\n", i); 1218 1219 return i; 1220 } 1221 1222 static int rx_buff_mgmt_show(struct seq_file *s, void *data) 1223 { 1224 struct wil6210_priv *wil = s->private; 1225 struct wil_rx_buff_mgmt *rbm = &wil->rx_buff_mgmt; 1226 int num_active; 1227 int num_free; 1228 1229 if (!rbm->buff_arr) 1230 return -EINVAL; 1231 1232 seq_printf(s, " size = %zu\n", rbm->size); 1233 seq_printf(s, " free_list_empty_cnt = %lu\n", 1234 rbm->free_list_empty_cnt); 1235 1236 /* Print active list */ 1237 seq_puts(s, " Active list:\n"); 1238 num_active = wil_print_rx_buff(s, &rbm->active); 1239 seq_puts(s, "\n Free list:\n"); 1240 num_free = wil_print_rx_buff(s, &rbm->free); 1241 1242 seq_printf(s, " Total number of buffers: %u\n", 1243 num_active + num_free); 1244 1245 return 0; 1246 } 1247 DEFINE_SHOW_ATTRIBUTE(rx_buff_mgmt); 1248 1249 /*---------beamforming------------*/ 1250 static char *wil_bfstatus_str(u32 status) 1251 { 1252 switch (status) { 1253 case 0: 1254 return "Failed"; 1255 case 1: 1256 return "OK"; 1257 case 2: 1258 return "Retrying"; 1259 default: 1260 return "??"; 1261 } 1262 } 1263 1264 static bool is_all_zeros(void * const x_, size_t sz) 1265 { 1266 /* if reply is all-0, ignore this CID */ 1267 u32 *x = x_; 1268 int n; 1269 1270 for (n = 0; n < sz / sizeof(*x); n++) 1271 if (x[n]) 1272 return false; 1273 1274 return true; 1275 } 1276 1277 static int bf_show(struct seq_file *s, void *data) 1278 { 1279 int rc; 1280 int i; 1281 struct wil6210_priv *wil = s->private; 1282 struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev); 1283 struct wmi_notify_req_cmd cmd = { 1284 .interval_usec = 0, 1285 }; 1286 struct { 1287 struct wmi_cmd_hdr wmi; 1288 struct wmi_notify_req_done_event evt; 1289 } __packed reply; 1290 1291 memset(&reply, 0, sizeof(reply)); 1292 1293 for (i = 0; i < wil->max_assoc_sta; i++) { 1294 u32 status; 1295 1296 cmd.cid = i; 1297 rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, vif->mid, 1298 &cmd, sizeof(cmd), 1299 WMI_NOTIFY_REQ_DONE_EVENTID, &reply, 1300 sizeof(reply), WIL_WMI_CALL_GENERAL_TO_MS); 1301 /* if reply is all-0, ignore this CID */ 1302 if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt))) 1303 continue; 1304 1305 status = le32_to_cpu(reply.evt.status); 1306 seq_printf(s, "CID %d {\n" 1307 " TSF = 0x%016llx\n" 1308 " TxMCS = %2d TxTpt = %4d\n" 1309 " SQI = %4d\n" 1310 " RSSI = %4d\n" 1311 " Status = 0x%08x %s\n" 1312 " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n" 1313 " Goodput(rx:tx) %4d:%4d\n" 1314 "}\n", 1315 i, 1316 le64_to_cpu(reply.evt.tsf), 1317 le16_to_cpu(reply.evt.bf_mcs), 1318 le32_to_cpu(reply.evt.tx_tpt), 1319 reply.evt.sqi, 1320 reply.evt.rssi, 1321 status, wil_bfstatus_str(status), 1322 le16_to_cpu(reply.evt.my_rx_sector), 1323 le16_to_cpu(reply.evt.my_tx_sector), 1324 le16_to_cpu(reply.evt.other_rx_sector), 1325 le16_to_cpu(reply.evt.other_tx_sector), 1326 le32_to_cpu(reply.evt.rx_goodput), 1327 le32_to_cpu(reply.evt.tx_goodput)); 1328 } 1329 return 0; 1330 } 1331 DEFINE_SHOW_ATTRIBUTE(bf); 1332 1333 /*---------temp------------*/ 1334 static void print_temp(struct seq_file *s, const char *prefix, s32 t) 1335 { 1336 switch (t) { 1337 case 0: 1338 case WMI_INVALID_TEMPERATURE: 1339 seq_printf(s, "%s N/A\n", prefix); 1340 break; 1341 default: 1342 seq_printf(s, "%s %s%d.%03d\n", prefix, (t < 0 ? "-" : ""), 1343 abs(t / 1000), abs(t % 1000)); 1344 break; 1345 } 1346 } 1347 1348 static int temp_show(struct seq_file *s, void *data) 1349 { 1350 struct wil6210_priv *wil = s->private; 1351 int rc, i; 1352 1353 if (test_bit(WMI_FW_CAPABILITY_TEMPERATURE_ALL_RF, 1354 wil->fw_capabilities)) { 1355 struct wmi_temp_sense_all_done_event sense_all_evt; 1356 1357 wil_dbg_misc(wil, 1358 "WMI_FW_CAPABILITY_TEMPERATURE_ALL_RF is supported"); 1359 rc = wmi_get_all_temperatures(wil, &sense_all_evt); 1360 if (rc) { 1361 seq_puts(s, "Failed\n"); 1362 return 0; 1363 } 1364 print_temp(s, "T_mac =", 1365 le32_to_cpu(sense_all_evt.baseband_t1000)); 1366 seq_printf(s, "Connected RFs [0x%08x]\n", 1367 sense_all_evt.rf_bitmap); 1368 for (i = 0; i < WMI_MAX_XIF_PORTS_NUM; i++) { 1369 seq_printf(s, "RF[%d] = ", i); 1370 print_temp(s, "", 1371 le32_to_cpu(sense_all_evt.rf_t1000[i])); 1372 } 1373 } else { 1374 s32 t_m, t_r; 1375 1376 wil_dbg_misc(wil, 1377 "WMI_FW_CAPABILITY_TEMPERATURE_ALL_RF is not supported"); 1378 rc = wmi_get_temperature(wil, &t_m, &t_r); 1379 if (rc) { 1380 seq_puts(s, "Failed\n"); 1381 return 0; 1382 } 1383 print_temp(s, "T_mac =", t_m); 1384 print_temp(s, "T_radio =", t_r); 1385 } 1386 return 0; 1387 } 1388 DEFINE_SHOW_ATTRIBUTE(temp); 1389 1390 /*---------freq------------*/ 1391 static int freq_show(struct seq_file *s, void *data) 1392 { 1393 struct wil6210_priv *wil = s->private; 1394 struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr; 1395 u32 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0; 1396 1397 seq_printf(s, "Freq = %d\n", freq); 1398 1399 return 0; 1400 } 1401 DEFINE_SHOW_ATTRIBUTE(freq); 1402 1403 /*---------link------------*/ 1404 static int link_show(struct seq_file *s, void *data) 1405 { 1406 struct wil6210_priv *wil = s->private; 1407 struct station_info *sinfo; 1408 int i, rc = 0; 1409 1410 sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL); 1411 if (!sinfo) 1412 return -ENOMEM; 1413 1414 for (i = 0; i < wil->max_assoc_sta; i++) { 1415 struct wil_sta_info *p = &wil->sta[i]; 1416 char *status = "unknown"; 1417 struct wil6210_vif *vif; 1418 u8 mid; 1419 1420 switch (p->status) { 1421 case wil_sta_unused: 1422 status = "unused "; 1423 break; 1424 case wil_sta_conn_pending: 1425 status = "pending "; 1426 break; 1427 case wil_sta_connected: 1428 status = "connected"; 1429 break; 1430 } 1431 mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX; 1432 seq_printf(s, "[%d][MID %d] %pM %s\n", 1433 i, mid, p->addr, status); 1434 1435 if (p->status != wil_sta_connected) 1436 continue; 1437 1438 vif = (mid < GET_MAX_VIFS(wil)) ? wil->vifs[mid] : NULL; 1439 if (vif) { 1440 rc = wil_cid_fill_sinfo(vif, i, sinfo); 1441 if (rc) 1442 goto out; 1443 1444 seq_printf(s, " Tx_mcs = %d\n", sinfo->txrate.mcs); 1445 seq_printf(s, " Rx_mcs = %d\n", sinfo->rxrate.mcs); 1446 seq_printf(s, " SQ = %d\n", sinfo->signal); 1447 } else { 1448 seq_puts(s, " INVALID MID\n"); 1449 } 1450 } 1451 1452 out: 1453 kfree(sinfo); 1454 return rc; 1455 } 1456 DEFINE_SHOW_ATTRIBUTE(link); 1457 1458 /*---------info------------*/ 1459 static int info_show(struct seq_file *s, void *data) 1460 { 1461 struct wil6210_priv *wil = s->private; 1462 struct net_device *ndev = wil->main_ndev; 1463 int is_ac = power_supply_is_system_supplied(); 1464 int rx = atomic_xchg(&wil->isr_count_rx, 0); 1465 int tx = atomic_xchg(&wil->isr_count_tx, 0); 1466 static ulong rxf_old, txf_old; 1467 ulong rxf = ndev->stats.rx_packets; 1468 ulong txf = ndev->stats.tx_packets; 1469 unsigned int i; 1470 1471 /* >0 : AC; 0 : battery; <0 : error */ 1472 seq_printf(s, "AC powered : %d\n", is_ac); 1473 seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old); 1474 seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old); 1475 rxf_old = rxf; 1476 txf_old = txf; 1477 1478 #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \ 1479 " " __stringify(x) : "" 1480 1481 for (i = 0; i < ndev->num_tx_queues; i++) { 1482 struct netdev_queue *txq = netdev_get_tx_queue(ndev, i); 1483 unsigned long state = txq->state; 1484 1485 seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state, 1486 CHECK_QSTATE(DRV_XOFF), 1487 CHECK_QSTATE(STACK_XOFF), 1488 CHECK_QSTATE(FROZEN) 1489 ); 1490 } 1491 #undef CHECK_QSTATE 1492 return 0; 1493 } 1494 DEFINE_SHOW_ATTRIBUTE(info); 1495 1496 /*---------recovery------------*/ 1497 /* mode = [manual|auto] 1498 * state = [idle|pending|running] 1499 */ 1500 static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf, 1501 size_t count, loff_t *ppos) 1502 { 1503 struct wil6210_priv *wil = file->private_data; 1504 char buf[80]; 1505 int n; 1506 static const char * const sstate[] = {"idle", "pending", "running"}; 1507 1508 n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n", 1509 no_fw_recovery ? "manual" : "auto", 1510 sstate[wil->recovery_state]); 1511 1512 n = min_t(int, n, sizeof(buf)); 1513 1514 return simple_read_from_buffer(user_buf, count, ppos, 1515 buf, n); 1516 } 1517 1518 static ssize_t wil_write_file_recovery(struct file *file, 1519 const char __user *buf_, 1520 size_t count, loff_t *ppos) 1521 { 1522 struct wil6210_priv *wil = file->private_data; 1523 static const char run_command[] = "run"; 1524 char buf[sizeof(run_command) + 1]; /* to detect "runx" */ 1525 ssize_t rc; 1526 1527 if (wil->recovery_state != fw_recovery_pending) { 1528 wil_err(wil, "No recovery pending\n"); 1529 return -EINVAL; 1530 } 1531 1532 if (*ppos != 0) { 1533 wil_err(wil, "Offset [%d]\n", (int)*ppos); 1534 return -EINVAL; 1535 } 1536 1537 if (count > sizeof(buf)) { 1538 wil_err(wil, "Input too long, len = %d\n", (int)count); 1539 return -EINVAL; 1540 } 1541 1542 rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count); 1543 if (rc < 0) 1544 return rc; 1545 1546 buf[rc] = '\0'; 1547 if (0 == strcmp(buf, run_command)) 1548 wil_set_recovery_state(wil, fw_recovery_running); 1549 else 1550 wil_err(wil, "Bad recovery command \"%s\"\n", buf); 1551 1552 return rc; 1553 } 1554 1555 static const struct file_operations fops_recovery = { 1556 .read = wil_read_file_recovery, 1557 .write = wil_write_file_recovery, 1558 .open = simple_open, 1559 }; 1560 1561 /*---------Station matrix------------*/ 1562 static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r) 1563 { 1564 int i; 1565 u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size; 1566 unsigned long long drop_dup = r->drop_dup, drop_old = r->drop_old; 1567 unsigned long long drop_dup_mcast = r->drop_dup_mcast; 1568 1569 seq_printf(s, "([%2d]) 0x%03x [", r->buf_size, r->head_seq_num); 1570 for (i = 0; i < r->buf_size; i++) { 1571 if (i == index) 1572 seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|'); 1573 else 1574 seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_'); 1575 } 1576 seq_printf(s, 1577 "] total %llu drop %llu (dup %llu + old %llu + dup mcast %llu) last 0x%03x\n", 1578 r->total, drop_dup + drop_old + drop_dup_mcast, drop_dup, 1579 drop_old, drop_dup_mcast, r->ssn_last_drop); 1580 } 1581 1582 static void wil_print_rxtid_crypto(struct seq_file *s, int tid, 1583 struct wil_tid_crypto_rx *c) 1584 { 1585 int i; 1586 1587 for (i = 0; i < 4; i++) { 1588 struct wil_tid_crypto_rx_single *cc = &c->key_id[i]; 1589 1590 if (cc->key_set) 1591 goto has_keys; 1592 } 1593 return; 1594 1595 has_keys: 1596 if (tid < WIL_STA_TID_NUM) 1597 seq_printf(s, " [%2d] PN", tid); 1598 else 1599 seq_puts(s, " [GR] PN"); 1600 1601 for (i = 0; i < 4; i++) { 1602 struct wil_tid_crypto_rx_single *cc = &c->key_id[i]; 1603 1604 seq_printf(s, " [%i%s]%6phN", i, cc->key_set ? "+" : "-", 1605 cc->pn); 1606 } 1607 seq_puts(s, "\n"); 1608 } 1609 1610 static int sta_show(struct seq_file *s, void *data) 1611 __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock) 1612 { 1613 struct wil6210_priv *wil = s->private; 1614 int i, tid, mcs; 1615 1616 for (i = 0; i < wil->max_assoc_sta; i++) { 1617 struct wil_sta_info *p = &wil->sta[i]; 1618 char *status = "unknown"; 1619 u8 aid = 0; 1620 u8 mid; 1621 bool sta_connected = false; 1622 1623 switch (p->status) { 1624 case wil_sta_unused: 1625 status = "unused "; 1626 break; 1627 case wil_sta_conn_pending: 1628 status = "pending "; 1629 break; 1630 case wil_sta_connected: 1631 status = "connected"; 1632 aid = p->aid; 1633 break; 1634 } 1635 mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX; 1636 if (mid < GET_MAX_VIFS(wil)) { 1637 struct wil6210_vif *vif = wil->vifs[mid]; 1638 1639 if (vif->wdev.iftype == NL80211_IFTYPE_STATION && 1640 p->status == wil_sta_connected) 1641 sta_connected = true; 1642 } 1643 /* print roam counter only for connected stations */ 1644 if (sta_connected) 1645 seq_printf(s, "[%d] %pM connected (roam counter %d) MID %d AID %d\n", 1646 i, p->addr, p->stats.ft_roams, mid, aid); 1647 else 1648 seq_printf(s, "[%d] %pM %s MID %d AID %d\n", i, 1649 p->addr, status, mid, aid); 1650 1651 if (p->status == wil_sta_connected) { 1652 spin_lock_bh(&p->tid_rx_lock); 1653 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) { 1654 struct wil_tid_ampdu_rx *r = p->tid_rx[tid]; 1655 struct wil_tid_crypto_rx *c = 1656 &p->tid_crypto_rx[tid]; 1657 1658 if (r) { 1659 seq_printf(s, " [%2d] ", tid); 1660 wil_print_rxtid(s, r); 1661 } 1662 1663 wil_print_rxtid_crypto(s, tid, c); 1664 } 1665 wil_print_rxtid_crypto(s, WIL_STA_TID_NUM, 1666 &p->group_crypto_rx); 1667 spin_unlock_bh(&p->tid_rx_lock); 1668 seq_printf(s, 1669 "Rx invalid frame: non-data %lu, short %lu, large %lu, replay %lu\n", 1670 p->stats.rx_non_data_frame, 1671 p->stats.rx_short_frame, 1672 p->stats.rx_large_frame, 1673 p->stats.rx_replay); 1674 seq_printf(s, 1675 "mic error %lu, key error %lu, amsdu error %lu, csum error %lu\n", 1676 p->stats.rx_mic_error, 1677 p->stats.rx_key_error, 1678 p->stats.rx_amsdu_error, 1679 p->stats.rx_csum_err); 1680 1681 seq_puts(s, "Rx/MCS:"); 1682 for (mcs = 0; mcs < ARRAY_SIZE(p->stats.rx_per_mcs); 1683 mcs++) 1684 seq_printf(s, " %lld", 1685 p->stats.rx_per_mcs[mcs]); 1686 seq_puts(s, "\n"); 1687 } 1688 } 1689 1690 return 0; 1691 } 1692 DEFINE_SHOW_ATTRIBUTE(sta); 1693 1694 static int mids_show(struct seq_file *s, void *data) 1695 { 1696 struct wil6210_priv *wil = s->private; 1697 struct wil6210_vif *vif; 1698 struct net_device *ndev; 1699 int i; 1700 1701 mutex_lock(&wil->vif_mutex); 1702 for (i = 0; i < GET_MAX_VIFS(wil); i++) { 1703 vif = wil->vifs[i]; 1704 1705 if (vif) { 1706 ndev = vif_to_ndev(vif); 1707 seq_printf(s, "[%d] %pM %s\n", i, ndev->dev_addr, 1708 ndev->name); 1709 } else { 1710 seq_printf(s, "[%d] unused\n", i); 1711 } 1712 } 1713 mutex_unlock(&wil->vif_mutex); 1714 1715 return 0; 1716 } 1717 DEFINE_SHOW_ATTRIBUTE(mids); 1718 1719 static int wil_tx_latency_debugfs_show(struct seq_file *s, void *data) 1720 __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock) 1721 { 1722 struct wil6210_priv *wil = s->private; 1723 int i, bin; 1724 1725 for (i = 0; i < wil->max_assoc_sta; i++) { 1726 struct wil_sta_info *p = &wil->sta[i]; 1727 char *status = "unknown"; 1728 u8 aid = 0; 1729 u8 mid; 1730 1731 if (!p->tx_latency_bins) 1732 continue; 1733 1734 switch (p->status) { 1735 case wil_sta_unused: 1736 status = "unused "; 1737 break; 1738 case wil_sta_conn_pending: 1739 status = "pending "; 1740 break; 1741 case wil_sta_connected: 1742 status = "connected"; 1743 aid = p->aid; 1744 break; 1745 } 1746 mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX; 1747 seq_printf(s, "[%d] %pM %s MID %d AID %d\n", i, p->addr, status, 1748 mid, aid); 1749 1750 if (p->status == wil_sta_connected) { 1751 u64 num_packets = 0; 1752 u64 tx_latency_avg = p->stats.tx_latency_total_us; 1753 1754 seq_puts(s, "Tx/Latency bin:"); 1755 for (bin = 0; bin < WIL_NUM_LATENCY_BINS; bin++) { 1756 seq_printf(s, " %lld", 1757 p->tx_latency_bins[bin]); 1758 num_packets += p->tx_latency_bins[bin]; 1759 } 1760 seq_puts(s, "\n"); 1761 if (!num_packets) 1762 continue; 1763 do_div(tx_latency_avg, num_packets); 1764 seq_printf(s, "Tx/Latency min/avg/max (us): %d/%lld/%d", 1765 p->stats.tx_latency_min_us, 1766 tx_latency_avg, 1767 p->stats.tx_latency_max_us); 1768 1769 seq_puts(s, "\n"); 1770 } 1771 } 1772 1773 return 0; 1774 } 1775 1776 static int wil_tx_latency_seq_open(struct inode *inode, struct file *file) 1777 { 1778 return single_open(file, wil_tx_latency_debugfs_show, 1779 inode->i_private); 1780 } 1781 1782 static ssize_t wil_tx_latency_write(struct file *file, const char __user *buf, 1783 size_t len, loff_t *ppos) 1784 { 1785 struct seq_file *s = file->private_data; 1786 struct wil6210_priv *wil = s->private; 1787 int val, rc, i; 1788 bool enable; 1789 1790 rc = kstrtoint_from_user(buf, len, 0, &val); 1791 if (rc) { 1792 wil_err(wil, "Invalid argument\n"); 1793 return rc; 1794 } 1795 if (val == 1) 1796 /* default resolution */ 1797 val = 500; 1798 if (val && (val < 50 || val > 1000)) { 1799 wil_err(wil, "Invalid resolution %d\n", val); 1800 return -EINVAL; 1801 } 1802 1803 enable = !!val; 1804 if (wil->tx_latency == enable) 1805 return len; 1806 1807 wil_info(wil, "%s TX latency measurements (resolution %dusec)\n", 1808 enable ? "Enabling" : "Disabling", val); 1809 1810 if (enable) { 1811 size_t sz = sizeof(u64) * WIL_NUM_LATENCY_BINS; 1812 1813 wil->tx_latency_res = val; 1814 for (i = 0; i < wil->max_assoc_sta; i++) { 1815 struct wil_sta_info *sta = &wil->sta[i]; 1816 1817 kfree(sta->tx_latency_bins); 1818 sta->tx_latency_bins = kzalloc(sz, GFP_KERNEL); 1819 if (!sta->tx_latency_bins) 1820 return -ENOMEM; 1821 sta->stats.tx_latency_min_us = U32_MAX; 1822 sta->stats.tx_latency_max_us = 0; 1823 sta->stats.tx_latency_total_us = 0; 1824 } 1825 } 1826 wil->tx_latency = enable; 1827 1828 return len; 1829 } 1830 1831 static const struct file_operations fops_tx_latency = { 1832 .open = wil_tx_latency_seq_open, 1833 .release = single_release, 1834 .read = seq_read, 1835 .write = wil_tx_latency_write, 1836 .llseek = seq_lseek, 1837 }; 1838 1839 static void wil_link_stats_print_basic(struct wil6210_vif *vif, 1840 struct seq_file *s, 1841 struct wmi_link_stats_basic *basic) 1842 { 1843 char per[5] = "?"; 1844 1845 if (basic->per_average != 0xff) 1846 snprintf(per, sizeof(per), "%d%%", basic->per_average); 1847 1848 seq_printf(s, "CID %d {\n" 1849 "\tTxMCS %d TxTpt %d\n" 1850 "\tGoodput(rx:tx) %d:%d\n" 1851 "\tRxBcastFrames %d\n" 1852 "\tRSSI %d SQI %d SNR %d PER %s\n" 1853 "\tRx RFC %d Ant num %d\n" 1854 "\tSectors(rx:tx) my %d:%d peer %d:%d\n" 1855 "}\n", 1856 basic->cid, 1857 basic->bf_mcs, le32_to_cpu(basic->tx_tpt), 1858 le32_to_cpu(basic->rx_goodput), 1859 le32_to_cpu(basic->tx_goodput), 1860 le32_to_cpu(basic->rx_bcast_frames), 1861 basic->rssi, basic->sqi, basic->snr, per, 1862 basic->selected_rfc, basic->rx_effective_ant_num, 1863 basic->my_rx_sector, basic->my_tx_sector, 1864 basic->other_rx_sector, basic->other_tx_sector); 1865 } 1866 1867 static void wil_link_stats_print_global(struct wil6210_priv *wil, 1868 struct seq_file *s, 1869 struct wmi_link_stats_global *global) 1870 { 1871 seq_printf(s, "Frames(rx:tx) %d:%d\n" 1872 "BA Frames(rx:tx) %d:%d\n" 1873 "Beacons %d\n" 1874 "Rx Errors (MIC:CRC) %d:%d\n" 1875 "Tx Errors (no ack) %d\n", 1876 le32_to_cpu(global->rx_frames), 1877 le32_to_cpu(global->tx_frames), 1878 le32_to_cpu(global->rx_ba_frames), 1879 le32_to_cpu(global->tx_ba_frames), 1880 le32_to_cpu(global->tx_beacons), 1881 le32_to_cpu(global->rx_mic_errors), 1882 le32_to_cpu(global->rx_crc_errors), 1883 le32_to_cpu(global->tx_fail_no_ack)); 1884 } 1885 1886 static void wil_link_stats_debugfs_show_vif(struct wil6210_vif *vif, 1887 struct seq_file *s) 1888 { 1889 struct wil6210_priv *wil = vif_to_wil(vif); 1890 struct wmi_link_stats_basic *stats; 1891 int i; 1892 1893 if (!vif->fw_stats_ready) { 1894 seq_puts(s, "no statistics\n"); 1895 return; 1896 } 1897 1898 seq_printf(s, "TSF %lld\n", vif->fw_stats_tsf); 1899 for (i = 0; i < wil->max_assoc_sta; i++) { 1900 if (wil->sta[i].status == wil_sta_unused) 1901 continue; 1902 if (wil->sta[i].mid != vif->mid) 1903 continue; 1904 1905 stats = &wil->sta[i].fw_stats_basic; 1906 wil_link_stats_print_basic(vif, s, stats); 1907 } 1908 } 1909 1910 static int wil_link_stats_debugfs_show(struct seq_file *s, void *data) 1911 { 1912 struct wil6210_priv *wil = s->private; 1913 struct wil6210_vif *vif; 1914 int i, rc; 1915 1916 rc = mutex_lock_interruptible(&wil->vif_mutex); 1917 if (rc) 1918 return rc; 1919 1920 /* iterate over all MIDs and show per-cid statistics. Then show the 1921 * global statistics 1922 */ 1923 for (i = 0; i < GET_MAX_VIFS(wil); i++) { 1924 vif = wil->vifs[i]; 1925 1926 seq_printf(s, "MID %d ", i); 1927 if (!vif) { 1928 seq_puts(s, "unused\n"); 1929 continue; 1930 } 1931 1932 wil_link_stats_debugfs_show_vif(vif, s); 1933 } 1934 1935 mutex_unlock(&wil->vif_mutex); 1936 1937 return 0; 1938 } 1939 1940 static int wil_link_stats_seq_open(struct inode *inode, struct file *file) 1941 { 1942 return single_open(file, wil_link_stats_debugfs_show, inode->i_private); 1943 } 1944 1945 static ssize_t wil_link_stats_write(struct file *file, const char __user *buf, 1946 size_t len, loff_t *ppos) 1947 { 1948 struct seq_file *s = file->private_data; 1949 struct wil6210_priv *wil = s->private; 1950 int cid, interval, rc, i; 1951 struct wil6210_vif *vif; 1952 char *kbuf = kmalloc(len + 1, GFP_KERNEL); 1953 1954 if (!kbuf) 1955 return -ENOMEM; 1956 1957 rc = simple_write_to_buffer(kbuf, len, ppos, buf, len); 1958 if (rc != len) { 1959 kfree(kbuf); 1960 return rc >= 0 ? -EIO : rc; 1961 } 1962 1963 kbuf[len] = '\0'; 1964 /* specify cid (use -1 for all cids) and snapshot interval in ms */ 1965 rc = sscanf(kbuf, "%d %d", &cid, &interval); 1966 kfree(kbuf); 1967 if (rc < 0) 1968 return rc; 1969 if (rc < 2 || interval < 0) 1970 return -EINVAL; 1971 1972 wil_info(wil, "request link statistics, cid %d interval %d\n", 1973 cid, interval); 1974 1975 rc = mutex_lock_interruptible(&wil->vif_mutex); 1976 if (rc) 1977 return rc; 1978 1979 for (i = 0; i < GET_MAX_VIFS(wil); i++) { 1980 vif = wil->vifs[i]; 1981 if (!vif) 1982 continue; 1983 1984 rc = wmi_link_stats_cfg(vif, WMI_LINK_STATS_TYPE_BASIC, 1985 (cid == -1 ? 0xff : cid), interval); 1986 if (rc) 1987 wil_err(wil, "link statistics failed for mid %d\n", i); 1988 } 1989 mutex_unlock(&wil->vif_mutex); 1990 1991 return len; 1992 } 1993 1994 static const struct file_operations fops_link_stats = { 1995 .open = wil_link_stats_seq_open, 1996 .release = single_release, 1997 .read = seq_read, 1998 .write = wil_link_stats_write, 1999 .llseek = seq_lseek, 2000 }; 2001 2002 static int 2003 wil_link_stats_global_debugfs_show(struct seq_file *s, void *data) 2004 { 2005 struct wil6210_priv *wil = s->private; 2006 2007 if (!wil->fw_stats_global.ready) 2008 return 0; 2009 2010 seq_printf(s, "TSF %lld\n", wil->fw_stats_global.tsf); 2011 wil_link_stats_print_global(wil, s, &wil->fw_stats_global.stats); 2012 2013 return 0; 2014 } 2015 2016 static int 2017 wil_link_stats_global_seq_open(struct inode *inode, struct file *file) 2018 { 2019 return single_open(file, wil_link_stats_global_debugfs_show, 2020 inode->i_private); 2021 } 2022 2023 static ssize_t 2024 wil_link_stats_global_write(struct file *file, const char __user *buf, 2025 size_t len, loff_t *ppos) 2026 { 2027 struct seq_file *s = file->private_data; 2028 struct wil6210_priv *wil = s->private; 2029 int interval, rc; 2030 struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev); 2031 2032 /* specify snapshot interval in ms */ 2033 rc = kstrtoint_from_user(buf, len, 0, &interval); 2034 if (rc || interval < 0) { 2035 wil_err(wil, "Invalid argument\n"); 2036 return -EINVAL; 2037 } 2038 2039 wil_info(wil, "request global link stats, interval %d\n", interval); 2040 2041 rc = wmi_link_stats_cfg(vif, WMI_LINK_STATS_TYPE_GLOBAL, 0, interval); 2042 if (rc) 2043 wil_err(wil, "global link stats failed %d\n", rc); 2044 2045 return rc ? rc : len; 2046 } 2047 2048 static const struct file_operations fops_link_stats_global = { 2049 .open = wil_link_stats_global_seq_open, 2050 .release = single_release, 2051 .read = seq_read, 2052 .write = wil_link_stats_global_write, 2053 .llseek = seq_lseek, 2054 }; 2055 2056 static ssize_t wil_read_file_led_cfg(struct file *file, char __user *user_buf, 2057 size_t count, loff_t *ppos) 2058 { 2059 char buf[80]; 2060 int n; 2061 2062 n = snprintf(buf, sizeof(buf), 2063 "led_id is set to %d, echo 1 to enable, 0 to disable\n", 2064 led_id); 2065 2066 n = min_t(int, n, sizeof(buf)); 2067 2068 return simple_read_from_buffer(user_buf, count, ppos, 2069 buf, n); 2070 } 2071 2072 static ssize_t wil_write_file_led_cfg(struct file *file, 2073 const char __user *buf_, 2074 size_t count, loff_t *ppos) 2075 { 2076 struct wil6210_priv *wil = file->private_data; 2077 int val; 2078 int rc; 2079 2080 rc = kstrtoint_from_user(buf_, count, 0, &val); 2081 if (rc) { 2082 wil_err(wil, "Invalid argument\n"); 2083 return rc; 2084 } 2085 2086 wil_info(wil, "%s led %d\n", val ? "Enabling" : "Disabling", led_id); 2087 rc = wmi_led_cfg(wil, val); 2088 if (rc) { 2089 wil_info(wil, "%s led %d failed\n", 2090 val ? "Enabling" : "Disabling", led_id); 2091 return rc; 2092 } 2093 2094 return count; 2095 } 2096 2097 static const struct file_operations fops_led_cfg = { 2098 .read = wil_read_file_led_cfg, 2099 .write = wil_write_file_led_cfg, 2100 .open = simple_open, 2101 }; 2102 2103 /* led_blink_time, write: 2104 * "<blink_on_slow> <blink_off_slow> <blink_on_med> <blink_off_med> <blink_on_fast> <blink_off_fast> 2105 */ 2106 static ssize_t wil_write_led_blink_time(struct file *file, 2107 const char __user *buf, 2108 size_t len, loff_t *ppos) 2109 { 2110 int rc; 2111 char *kbuf = kmalloc(len + 1, GFP_KERNEL); 2112 2113 if (!kbuf) 2114 return -ENOMEM; 2115 2116 rc = simple_write_to_buffer(kbuf, len, ppos, buf, len); 2117 if (rc != len) { 2118 kfree(kbuf); 2119 return rc >= 0 ? -EIO : rc; 2120 } 2121 2122 kbuf[len] = '\0'; 2123 rc = sscanf(kbuf, "%d %d %d %d %d %d", 2124 &led_blink_time[WIL_LED_TIME_SLOW].on_ms, 2125 &led_blink_time[WIL_LED_TIME_SLOW].off_ms, 2126 &led_blink_time[WIL_LED_TIME_MED].on_ms, 2127 &led_blink_time[WIL_LED_TIME_MED].off_ms, 2128 &led_blink_time[WIL_LED_TIME_FAST].on_ms, 2129 &led_blink_time[WIL_LED_TIME_FAST].off_ms); 2130 kfree(kbuf); 2131 2132 if (rc < 0) 2133 return rc; 2134 if (rc < 6) 2135 return -EINVAL; 2136 2137 return len; 2138 } 2139 2140 static ssize_t wil_read_led_blink_time(struct file *file, char __user *user_buf, 2141 size_t count, loff_t *ppos) 2142 { 2143 static char text[400]; 2144 2145 snprintf(text, sizeof(text), 2146 "To set led blink on/off time variables write:\n" 2147 "<blink_on_slow> <blink_off_slow> <blink_on_med> " 2148 "<blink_off_med> <blink_on_fast> <blink_off_fast>\n" 2149 "The current values are:\n" 2150 "%d %d %d %d %d %d\n", 2151 led_blink_time[WIL_LED_TIME_SLOW].on_ms, 2152 led_blink_time[WIL_LED_TIME_SLOW].off_ms, 2153 led_blink_time[WIL_LED_TIME_MED].on_ms, 2154 led_blink_time[WIL_LED_TIME_MED].off_ms, 2155 led_blink_time[WIL_LED_TIME_FAST].on_ms, 2156 led_blink_time[WIL_LED_TIME_FAST].off_ms); 2157 2158 return simple_read_from_buffer(user_buf, count, ppos, text, 2159 sizeof(text)); 2160 } 2161 2162 static const struct file_operations fops_led_blink_time = { 2163 .read = wil_read_led_blink_time, 2164 .write = wil_write_led_blink_time, 2165 .open = simple_open, 2166 }; 2167 2168 /*---------FW capabilities------------*/ 2169 static int wil_fw_capabilities_debugfs_show(struct seq_file *s, void *data) 2170 { 2171 struct wil6210_priv *wil = s->private; 2172 2173 seq_printf(s, "fw_capabilities : %*pb\n", WMI_FW_CAPABILITY_MAX, 2174 wil->fw_capabilities); 2175 2176 return 0; 2177 } 2178 2179 static int wil_fw_capabilities_seq_open(struct inode *inode, struct file *file) 2180 { 2181 return single_open(file, wil_fw_capabilities_debugfs_show, 2182 inode->i_private); 2183 } 2184 2185 static const struct file_operations fops_fw_capabilities = { 2186 .open = wil_fw_capabilities_seq_open, 2187 .release = single_release, 2188 .read = seq_read, 2189 .llseek = seq_lseek, 2190 }; 2191 2192 /*---------FW version------------*/ 2193 static int wil_fw_version_debugfs_show(struct seq_file *s, void *data) 2194 { 2195 struct wil6210_priv *wil = s->private; 2196 2197 if (wil->fw_version[0]) 2198 seq_printf(s, "%s\n", wil->fw_version); 2199 else 2200 seq_puts(s, "N/A\n"); 2201 2202 return 0; 2203 } 2204 2205 static int wil_fw_version_seq_open(struct inode *inode, struct file *file) 2206 { 2207 return single_open(file, wil_fw_version_debugfs_show, 2208 inode->i_private); 2209 } 2210 2211 static const struct file_operations fops_fw_version = { 2212 .open = wil_fw_version_seq_open, 2213 .release = single_release, 2214 .read = seq_read, 2215 .llseek = seq_lseek, 2216 }; 2217 2218 /*---------suspend_stats---------*/ 2219 static ssize_t wil_write_suspend_stats(struct file *file, 2220 const char __user *buf, 2221 size_t len, loff_t *ppos) 2222 { 2223 struct wil6210_priv *wil = file->private_data; 2224 2225 memset(&wil->suspend_stats, 0, sizeof(wil->suspend_stats)); 2226 2227 return len; 2228 } 2229 2230 static ssize_t wil_read_suspend_stats(struct file *file, 2231 char __user *user_buf, 2232 size_t count, loff_t *ppos) 2233 { 2234 struct wil6210_priv *wil = file->private_data; 2235 char *text; 2236 int n, ret, text_size = 500; 2237 2238 text = kmalloc(text_size, GFP_KERNEL); 2239 if (!text) 2240 return -ENOMEM; 2241 2242 n = snprintf(text, text_size, 2243 "Radio on suspend statistics:\n" 2244 "successful suspends:%ld failed suspends:%ld\n" 2245 "successful resumes:%ld failed resumes:%ld\n" 2246 "rejected by device:%ld\n" 2247 "Radio off suspend statistics:\n" 2248 "successful suspends:%ld failed suspends:%ld\n" 2249 "successful resumes:%ld failed resumes:%ld\n" 2250 "General statistics:\n" 2251 "rejected by host:%ld\n", 2252 wil->suspend_stats.r_on.successful_suspends, 2253 wil->suspend_stats.r_on.failed_suspends, 2254 wil->suspend_stats.r_on.successful_resumes, 2255 wil->suspend_stats.r_on.failed_resumes, 2256 wil->suspend_stats.rejected_by_device, 2257 wil->suspend_stats.r_off.successful_suspends, 2258 wil->suspend_stats.r_off.failed_suspends, 2259 wil->suspend_stats.r_off.successful_resumes, 2260 wil->suspend_stats.r_off.failed_resumes, 2261 wil->suspend_stats.rejected_by_host); 2262 2263 n = min_t(int, n, text_size); 2264 2265 ret = simple_read_from_buffer(user_buf, count, ppos, text, n); 2266 2267 kfree(text); 2268 2269 return ret; 2270 } 2271 2272 static const struct file_operations fops_suspend_stats = { 2273 .read = wil_read_suspend_stats, 2274 .write = wil_write_suspend_stats, 2275 .open = simple_open, 2276 }; 2277 2278 /*---------compressed_rx_status---------*/ 2279 static ssize_t wil_compressed_rx_status_write(struct file *file, 2280 const char __user *buf, 2281 size_t len, loff_t *ppos) 2282 { 2283 struct seq_file *s = file->private_data; 2284 struct wil6210_priv *wil = s->private; 2285 int compressed_rx_status; 2286 int rc; 2287 2288 rc = kstrtoint_from_user(buf, len, 0, &compressed_rx_status); 2289 if (rc) { 2290 wil_err(wil, "Invalid argument\n"); 2291 return rc; 2292 } 2293 2294 if (wil_has_active_ifaces(wil, true, false)) { 2295 wil_err(wil, "cannot change edma config after iface is up\n"); 2296 return -EPERM; 2297 } 2298 2299 wil_info(wil, "%sable compressed_rx_status\n", 2300 compressed_rx_status ? "En" : "Dis"); 2301 2302 wil->use_compressed_rx_status = compressed_rx_status; 2303 2304 return len; 2305 } 2306 2307 static int 2308 wil_compressed_rx_status_show(struct seq_file *s, void *data) 2309 { 2310 struct wil6210_priv *wil = s->private; 2311 2312 seq_printf(s, "%d\n", wil->use_compressed_rx_status); 2313 2314 return 0; 2315 } 2316 2317 static int 2318 wil_compressed_rx_status_seq_open(struct inode *inode, struct file *file) 2319 { 2320 return single_open(file, wil_compressed_rx_status_show, 2321 inode->i_private); 2322 } 2323 2324 static const struct file_operations fops_compressed_rx_status = { 2325 .open = wil_compressed_rx_status_seq_open, 2326 .release = single_release, 2327 .read = seq_read, 2328 .write = wil_compressed_rx_status_write, 2329 .llseek = seq_lseek, 2330 }; 2331 2332 /*----------------*/ 2333 static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil, 2334 struct dentry *dbg) 2335 { 2336 int i; 2337 char name[32]; 2338 2339 for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) { 2340 struct wil_blob_wrapper *wil_blob = &wil->blobs[i]; 2341 struct debugfs_blob_wrapper *blob = &wil_blob->blob; 2342 const struct fw_map *map = &fw_mapping[i]; 2343 2344 if (!map->name) 2345 continue; 2346 2347 wil_blob->wil = wil; 2348 blob->data = (void * __force)wil->csr + HOSTADDR(map->host); 2349 blob->size = map->to - map->from; 2350 snprintf(name, sizeof(name), "blob_%s", map->name); 2351 wil_debugfs_create_ioblob(name, 0444, dbg, wil_blob); 2352 } 2353 } 2354 2355 /* misc files */ 2356 static const struct { 2357 const char *name; 2358 umode_t mode; 2359 const struct file_operations *fops; 2360 } dbg_files[] = { 2361 {"mbox", 0444, &mbox_fops}, 2362 {"rings", 0444, &ring_fops}, 2363 {"stations", 0444, &sta_fops}, 2364 {"mids", 0444, &mids_fops}, 2365 {"desc", 0444, &txdesc_fops}, 2366 {"bf", 0444, &bf_fops}, 2367 {"mem_val", 0644, &memread_fops}, 2368 {"rxon", 0244, &fops_rxon}, 2369 {"tx_mgmt", 0244, &fops_txmgmt}, 2370 {"wmi_send", 0244, &fops_wmi}, 2371 {"back", 0644, &fops_back}, 2372 {"pmccfg", 0644, &fops_pmccfg}, 2373 {"pmcdata", 0444, &fops_pmcdata}, 2374 {"temp", 0444, &temp_fops}, 2375 {"freq", 0444, &freq_fops}, 2376 {"link", 0444, &link_fops}, 2377 {"info", 0444, &info_fops}, 2378 {"recovery", 0644, &fops_recovery}, 2379 {"led_cfg", 0644, &fops_led_cfg}, 2380 {"led_blink_time", 0644, &fops_led_blink_time}, 2381 {"fw_capabilities", 0444, &fops_fw_capabilities}, 2382 {"fw_version", 0444, &fops_fw_version}, 2383 {"suspend_stats", 0644, &fops_suspend_stats}, 2384 {"compressed_rx_status", 0644, &fops_compressed_rx_status}, 2385 {"srings", 0444, &srings_fops}, 2386 {"status_msg", 0444, &status_msg_fops}, 2387 {"rx_buff_mgmt", 0444, &rx_buff_mgmt_fops}, 2388 {"tx_latency", 0644, &fops_tx_latency}, 2389 {"link_stats", 0644, &fops_link_stats}, 2390 {"link_stats_global", 0644, &fops_link_stats_global}, 2391 {"rbufcap", 0244, &fops_rbufcap}, 2392 }; 2393 2394 static void wil6210_debugfs_init_files(struct wil6210_priv *wil, 2395 struct dentry *dbg) 2396 { 2397 int i; 2398 2399 for (i = 0; i < ARRAY_SIZE(dbg_files); i++) 2400 debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg, 2401 wil, dbg_files[i].fops); 2402 } 2403 2404 /* interrupt control blocks */ 2405 static const struct { 2406 const char *name; 2407 u32 icr_off; 2408 } dbg_icr[] = { 2409 {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)}, 2410 {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)}, 2411 {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)}, 2412 {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)}, 2413 }; 2414 2415 static void wil6210_debugfs_init_isr(struct wil6210_priv *wil, 2416 struct dentry *dbg) 2417 { 2418 int i; 2419 2420 for (i = 0; i < ARRAY_SIZE(dbg_icr); i++) 2421 wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg, 2422 dbg_icr[i].icr_off); 2423 } 2424 2425 #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \ 2426 offsetof(struct wil6210_priv, name), type} 2427 2428 /* fields in struct wil6210_priv */ 2429 static const struct dbg_off dbg_wil_off[] = { 2430 WIL_FIELD(status[0], 0644, doff_ulong), 2431 WIL_FIELD(hw_version, 0444, doff_x32), 2432 WIL_FIELD(recovery_count, 0444, doff_u32), 2433 WIL_FIELD(discovery_mode, 0644, doff_u8), 2434 WIL_FIELD(chip_revision, 0444, doff_u8), 2435 WIL_FIELD(abft_len, 0644, doff_u8), 2436 WIL_FIELD(wakeup_trigger, 0644, doff_u8), 2437 WIL_FIELD(ring_idle_trsh, 0644, doff_u32), 2438 WIL_FIELD(num_rx_status_rings, 0644, doff_u8), 2439 WIL_FIELD(rx_status_ring_order, 0644, doff_u32), 2440 WIL_FIELD(tx_status_ring_order, 0644, doff_u32), 2441 WIL_FIELD(rx_buff_id_count, 0644, doff_u32), 2442 WIL_FIELD(amsdu_en, 0644, doff_u8), 2443 {}, 2444 }; 2445 2446 static const struct dbg_off dbg_wil_regs[] = { 2447 {"RGF_MAC_MTRL_COUNTER_0", 0444, HOSTADDR(RGF_MAC_MTRL_COUNTER_0), 2448 doff_io32}, 2449 {"RGF_USER_USAGE_1", 0444, HOSTADDR(RGF_USER_USAGE_1), doff_io32}, 2450 {"RGF_USER_USAGE_2", 0444, HOSTADDR(RGF_USER_USAGE_2), doff_io32}, 2451 {}, 2452 }; 2453 2454 /* static parameters */ 2455 static const struct dbg_off dbg_statics[] = { 2456 {"desc_index", 0644, (ulong)&dbg_txdesc_index, doff_u32}, 2457 {"ring_index", 0644, (ulong)&dbg_ring_index, doff_u32}, 2458 {"mem_addr", 0644, (ulong)&mem_addr, doff_u32}, 2459 {"led_polarity", 0644, (ulong)&led_polarity, doff_u8}, 2460 {"status_index", 0644, (ulong)&dbg_status_msg_index, doff_u32}, 2461 {"sring_index", 0644, (ulong)&dbg_sring_index, doff_u32}, 2462 {"drop_if_ring_full", 0644, (ulong)&drop_if_ring_full, doff_u8}, 2463 {}, 2464 }; 2465 2466 static const int dbg_off_count = 4 * (ARRAY_SIZE(isr_off) - 1) + 2467 ARRAY_SIZE(dbg_wil_regs) - 1 + 2468 ARRAY_SIZE(pseudo_isr_off) - 1 + 2469 ARRAY_SIZE(lgc_itr_cnt_off) - 1 + 2470 ARRAY_SIZE(tx_itr_cnt_off) - 1 + 2471 ARRAY_SIZE(rx_itr_cnt_off) - 1; 2472 2473 int wil6210_debugfs_init(struct wil6210_priv *wil) 2474 { 2475 struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME, 2476 wil_to_wiphy(wil)->debugfsdir); 2477 if (IS_ERR_OR_NULL(dbg)) 2478 return -ENODEV; 2479 2480 wil->dbg_data.data_arr = kcalloc(dbg_off_count, 2481 sizeof(struct wil_debugfs_iomem_data), 2482 GFP_KERNEL); 2483 if (!wil->dbg_data.data_arr) { 2484 debugfs_remove_recursive(dbg); 2485 wil->debug = NULL; 2486 return -ENOMEM; 2487 } 2488 2489 wil->dbg_data.iomem_data_count = 0; 2490 2491 wil_pmc_init(wil); 2492 2493 wil6210_debugfs_init_files(wil, dbg); 2494 wil6210_debugfs_init_isr(wil, dbg); 2495 wil6210_debugfs_init_blobs(wil, dbg); 2496 wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off); 2497 wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr, 2498 dbg_wil_regs); 2499 wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics); 2500 2501 wil6210_debugfs_create_pseudo_ISR(wil, dbg); 2502 2503 wil6210_debugfs_create_ITR_CNT(wil, dbg); 2504 2505 return 0; 2506 } 2507 2508 void wil6210_debugfs_remove(struct wil6210_priv *wil) 2509 { 2510 int i; 2511 2512 debugfs_remove_recursive(wil->debug); 2513 wil->debug = NULL; 2514 2515 kfree(wil->dbg_data.data_arr); 2516 for (i = 0; i < wil->max_assoc_sta; i++) 2517 kfree(wil->sta[i].tx_latency_bins); 2518 2519 /* free pmc memory without sending command to fw, as it will 2520 * be reset on the way down anyway 2521 */ 2522 wil_pmc_free(wil, false); 2523 } 2524