1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 2 /* Copyright(c) 2018-2019 Realtek Corporation 3 */ 4 5 #include <linux/debugfs.h> 6 #include <linux/seq_file.h> 7 #include "main.h" 8 #include "coex.h" 9 #include "sec.h" 10 #include "fw.h" 11 #include "debug.h" 12 #include "phy.h" 13 14 #ifdef CONFIG_RTW88_DEBUGFS 15 16 struct rtw_debugfs_priv { 17 struct rtw_dev *rtwdev; 18 int (*cb_read)(struct seq_file *m, void *v); 19 ssize_t (*cb_write)(struct file *filp, const char __user *buffer, 20 size_t count, loff_t *loff); 21 union { 22 u32 cb_data; 23 u8 *buf; 24 struct { 25 u32 page_offset; 26 u32 page_num; 27 } rsvd_page; 28 struct { 29 u8 rf_path; 30 u32 rf_addr; 31 u32 rf_mask; 32 }; 33 struct { 34 u32 addr; 35 u32 len; 36 } read_reg; 37 }; 38 }; 39 40 static int rtw_debugfs_single_show(struct seq_file *m, void *v) 41 { 42 struct rtw_debugfs_priv *debugfs_priv = m->private; 43 44 return debugfs_priv->cb_read(m, v); 45 } 46 47 static ssize_t rtw_debugfs_common_write(struct file *filp, 48 const char __user *buffer, 49 size_t count, loff_t *loff) 50 { 51 struct rtw_debugfs_priv *debugfs_priv = filp->private_data; 52 53 return debugfs_priv->cb_write(filp, buffer, count, loff); 54 } 55 56 static ssize_t rtw_debugfs_single_write(struct file *filp, 57 const char __user *buffer, 58 size_t count, loff_t *loff) 59 { 60 struct seq_file *seqpriv = (struct seq_file *)filp->private_data; 61 struct rtw_debugfs_priv *debugfs_priv = seqpriv->private; 62 63 return debugfs_priv->cb_write(filp, buffer, count, loff); 64 } 65 66 static int rtw_debugfs_single_open_rw(struct inode *inode, struct file *filp) 67 { 68 return single_open(filp, rtw_debugfs_single_show, inode->i_private); 69 } 70 71 static int rtw_debugfs_close(struct inode *inode, struct file *filp) 72 { 73 return 0; 74 } 75 76 static const struct file_operations file_ops_single_r = { 77 .owner = THIS_MODULE, 78 .open = rtw_debugfs_single_open_rw, 79 .read = seq_read, 80 .llseek = seq_lseek, 81 .release = single_release, 82 }; 83 84 static const struct file_operations file_ops_single_rw = { 85 .owner = THIS_MODULE, 86 .open = rtw_debugfs_single_open_rw, 87 .release = single_release, 88 .read = seq_read, 89 .llseek = seq_lseek, 90 .write = rtw_debugfs_single_write, 91 }; 92 93 static const struct file_operations file_ops_common_write = { 94 .owner = THIS_MODULE, 95 .write = rtw_debugfs_common_write, 96 .open = simple_open, 97 .release = rtw_debugfs_close, 98 }; 99 100 static int rtw_debugfs_get_read_reg(struct seq_file *m, void *v) 101 { 102 struct rtw_debugfs_priv *debugfs_priv = m->private; 103 struct rtw_dev *rtwdev = debugfs_priv->rtwdev; 104 u32 val, len, addr; 105 106 len = debugfs_priv->read_reg.len; 107 addr = debugfs_priv->read_reg.addr; 108 switch (len) { 109 case 1: 110 val = rtw_read8(rtwdev, addr); 111 seq_printf(m, "reg 0x%03x: 0x%02x\n", addr, val); 112 break; 113 case 2: 114 val = rtw_read16(rtwdev, addr); 115 seq_printf(m, "reg 0x%03x: 0x%04x\n", addr, val); 116 break; 117 case 4: 118 val = rtw_read32(rtwdev, addr); 119 seq_printf(m, "reg 0x%03x: 0x%08x\n", addr, val); 120 break; 121 } 122 return 0; 123 } 124 125 static int rtw_debugfs_get_rf_read(struct seq_file *m, void *v) 126 { 127 struct rtw_debugfs_priv *debugfs_priv = m->private; 128 struct rtw_dev *rtwdev = debugfs_priv->rtwdev; 129 u32 val, addr, mask; 130 u8 path; 131 132 path = debugfs_priv->rf_path; 133 addr = debugfs_priv->rf_addr; 134 mask = debugfs_priv->rf_mask; 135 136 val = rtw_read_rf(rtwdev, path, addr, mask); 137 138 seq_printf(m, "rf_read path:%d addr:0x%08x mask:0x%08x val=0x%08x\n", 139 path, addr, mask, val); 140 141 return 0; 142 } 143 144 static int rtw_debugfs_copy_from_user(char tmp[], int size, 145 const char __user *buffer, size_t count, 146 int num) 147 { 148 int tmp_len; 149 150 memset(tmp, 0, size); 151 152 if (count < num) 153 return -EFAULT; 154 155 tmp_len = (count > size - 1 ? size - 1 : count); 156 157 if (!buffer || copy_from_user(tmp, buffer, tmp_len)) 158 return count; 159 160 tmp[tmp_len] = '\0'; 161 162 return 0; 163 } 164 165 static ssize_t rtw_debugfs_set_read_reg(struct file *filp, 166 const char __user *buffer, 167 size_t count, loff_t *loff) 168 { 169 struct seq_file *seqpriv = (struct seq_file *)filp->private_data; 170 struct rtw_debugfs_priv *debugfs_priv = seqpriv->private; 171 struct rtw_dev *rtwdev = debugfs_priv->rtwdev; 172 char tmp[32 + 1]; 173 u32 addr, len; 174 int num; 175 176 rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 2); 177 178 num = sscanf(tmp, "%x %x", &addr, &len); 179 180 if (num != 2) 181 return count; 182 183 if (len != 1 && len != 2 && len != 4) { 184 rtw_warn(rtwdev, "read reg setting wrong len\n"); 185 return -EINVAL; 186 } 187 debugfs_priv->read_reg.addr = addr; 188 debugfs_priv->read_reg.len = len; 189 190 return count; 191 } 192 193 static int rtw_debugfs_get_dump_cam(struct seq_file *m, void *v) 194 { 195 struct rtw_debugfs_priv *debugfs_priv = m->private; 196 struct rtw_dev *rtwdev = debugfs_priv->rtwdev; 197 u32 val, command; 198 u32 hw_key_idx = debugfs_priv->cb_data << RTW_SEC_CAM_ENTRY_SHIFT; 199 u32 read_cmd = RTW_SEC_CMD_POLLING; 200 int i; 201 202 seq_printf(m, "cam entry%d\n", debugfs_priv->cb_data); 203 seq_puts(m, "0x0 0x1 0x2 0x3 "); 204 seq_puts(m, "0x4 0x5\n"); 205 mutex_lock(&rtwdev->mutex); 206 for (i = 0; i <= 5; i++) { 207 command = read_cmd | (hw_key_idx + i); 208 rtw_write32(rtwdev, RTW_SEC_CMD_REG, command); 209 val = rtw_read32(rtwdev, RTW_SEC_READ_REG); 210 seq_printf(m, "%8.8x", val); 211 if (i < 2) 212 seq_puts(m, " "); 213 } 214 seq_puts(m, "\n"); 215 mutex_unlock(&rtwdev->mutex); 216 return 0; 217 } 218 219 static int rtw_debugfs_get_rsvd_page(struct seq_file *m, void *v) 220 { 221 struct rtw_debugfs_priv *debugfs_priv = m->private; 222 struct rtw_dev *rtwdev = debugfs_priv->rtwdev; 223 u8 page_size = rtwdev->chip->page_size; 224 u32 buf_size = debugfs_priv->rsvd_page.page_num * page_size; 225 u32 offset = debugfs_priv->rsvd_page.page_offset * page_size; 226 u8 *buf; 227 int i; 228 int ret; 229 230 buf = vzalloc(buf_size); 231 if (!buf) 232 return -ENOMEM; 233 234 ret = rtw_fw_dump_fifo(rtwdev, RTW_FW_FIFO_SEL_RSVD_PAGE, offset, 235 buf_size, (u32 *)buf); 236 if (ret) { 237 rtw_err(rtwdev, "failed to dump rsvd page\n"); 238 vfree(buf); 239 return ret; 240 } 241 242 for (i = 0 ; i < buf_size ; i += 8) { 243 if (i % page_size == 0) 244 seq_printf(m, "PAGE %d\n", (i + offset) / page_size); 245 seq_printf(m, "%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n", 246 *(buf + i), *(buf + i + 1), 247 *(buf + i + 2), *(buf + i + 3), 248 *(buf + i + 4), *(buf + i + 5), 249 *(buf + i + 6), *(buf + i + 7)); 250 } 251 vfree(buf); 252 253 return 0; 254 } 255 256 static ssize_t rtw_debugfs_set_rsvd_page(struct file *filp, 257 const char __user *buffer, 258 size_t count, loff_t *loff) 259 { 260 struct seq_file *seqpriv = (struct seq_file *)filp->private_data; 261 struct rtw_debugfs_priv *debugfs_priv = seqpriv->private; 262 struct rtw_dev *rtwdev = debugfs_priv->rtwdev; 263 char tmp[32 + 1]; 264 u32 offset, page_num; 265 int num; 266 267 rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 2); 268 269 num = sscanf(tmp, "%d %d", &offset, &page_num); 270 271 if (num != 2) { 272 rtw_warn(rtwdev, "invalid arguments\n"); 273 return num; 274 } 275 276 debugfs_priv->rsvd_page.page_offset = offset; 277 debugfs_priv->rsvd_page.page_num = page_num; 278 279 return count; 280 } 281 282 static ssize_t rtw_debugfs_set_single_input(struct file *filp, 283 const char __user *buffer, 284 size_t count, loff_t *loff) 285 { 286 struct seq_file *seqpriv = (struct seq_file *)filp->private_data; 287 struct rtw_debugfs_priv *debugfs_priv = seqpriv->private; 288 struct rtw_dev *rtwdev = debugfs_priv->rtwdev; 289 char tmp[32 + 1]; 290 u32 input; 291 int num; 292 293 rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 1); 294 295 num = kstrtoint(tmp, 0, &input); 296 297 if (num) { 298 rtw_warn(rtwdev, "kstrtoint failed\n"); 299 return num; 300 } 301 302 debugfs_priv->cb_data = input; 303 304 return count; 305 } 306 307 static ssize_t rtw_debugfs_set_write_reg(struct file *filp, 308 const char __user *buffer, 309 size_t count, loff_t *loff) 310 { 311 struct rtw_debugfs_priv *debugfs_priv = filp->private_data; 312 struct rtw_dev *rtwdev = debugfs_priv->rtwdev; 313 char tmp[32 + 1]; 314 u32 addr, val, len; 315 int num; 316 317 rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 3); 318 319 /* write BB/MAC register */ 320 num = sscanf(tmp, "%x %x %x", &addr, &val, &len); 321 322 if (num != 3) 323 return count; 324 325 switch (len) { 326 case 1: 327 rtw_dbg(rtwdev, RTW_DBG_DEBUGFS, 328 "reg write8 0x%03x: 0x%08x\n", addr, val); 329 rtw_write8(rtwdev, addr, (u8)val); 330 break; 331 case 2: 332 rtw_dbg(rtwdev, RTW_DBG_DEBUGFS, 333 "reg write16 0x%03x: 0x%08x\n", addr, val); 334 rtw_write16(rtwdev, addr, (u16)val); 335 break; 336 case 4: 337 rtw_dbg(rtwdev, RTW_DBG_DEBUGFS, 338 "reg write32 0x%03x: 0x%08x\n", addr, val); 339 rtw_write32(rtwdev, addr, (u32)val); 340 break; 341 default: 342 rtw_dbg(rtwdev, RTW_DBG_DEBUGFS, 343 "error write length = %d\n", len); 344 break; 345 } 346 347 return count; 348 } 349 350 static ssize_t rtw_debugfs_set_h2c(struct file *filp, 351 const char __user *buffer, 352 size_t count, loff_t *loff) 353 { 354 struct rtw_debugfs_priv *debugfs_priv = filp->private_data; 355 struct rtw_dev *rtwdev = debugfs_priv->rtwdev; 356 char tmp[32 + 1]; 357 u8 param[8]; 358 int num; 359 360 rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 3); 361 362 num = sscanf(tmp, "%hhx,%hhx,%hhx,%hhx,%hhx,%hhx,%hhx,%hhx", 363 ¶m[0], ¶m[1], ¶m[2], ¶m[3], 364 ¶m[4], ¶m[5], ¶m[6], ¶m[7]); 365 if (num != 8) { 366 rtw_info(rtwdev, "invalid H2C command format for debug\n"); 367 return -EINVAL; 368 } 369 370 rtw_fw_h2c_cmd_dbg(rtwdev, param); 371 372 return count; 373 } 374 375 static ssize_t rtw_debugfs_set_rf_write(struct file *filp, 376 const char __user *buffer, 377 size_t count, loff_t *loff) 378 { 379 struct rtw_debugfs_priv *debugfs_priv = filp->private_data; 380 struct rtw_dev *rtwdev = debugfs_priv->rtwdev; 381 char tmp[32 + 1]; 382 u32 path, addr, mask, val; 383 int num; 384 385 rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 4); 386 387 num = sscanf(tmp, "%x %x %x %x", &path, &addr, &mask, &val); 388 389 if (num != 4) { 390 rtw_warn(rtwdev, "invalid args, [path] [addr] [mask] [val]\n"); 391 return count; 392 } 393 394 rtw_write_rf(rtwdev, path, addr, mask, val); 395 rtw_dbg(rtwdev, RTW_DBG_DEBUGFS, 396 "write_rf path:%d addr:0x%08x mask:0x%08x, val:0x%08x\n", 397 path, addr, mask, val); 398 399 return count; 400 } 401 402 static ssize_t rtw_debugfs_set_rf_read(struct file *filp, 403 const char __user *buffer, 404 size_t count, loff_t *loff) 405 { 406 struct seq_file *seqpriv = (struct seq_file *)filp->private_data; 407 struct rtw_debugfs_priv *debugfs_priv = seqpriv->private; 408 struct rtw_dev *rtwdev = debugfs_priv->rtwdev; 409 char tmp[32 + 1]; 410 u32 path, addr, mask; 411 int num; 412 413 rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 3); 414 415 num = sscanf(tmp, "%x %x %x", &path, &addr, &mask); 416 417 if (num != 3) { 418 rtw_warn(rtwdev, "invalid args, [path] [addr] [mask] [val]\n"); 419 return count; 420 } 421 422 debugfs_priv->rf_path = path; 423 debugfs_priv->rf_addr = addr; 424 debugfs_priv->rf_mask = mask; 425 426 return count; 427 } 428 429 static int rtw_debug_get_mac_page(struct seq_file *m, void *v) 430 { 431 struct rtw_debugfs_priv *debugfs_priv = m->private; 432 struct rtw_dev *rtwdev = debugfs_priv->rtwdev; 433 u32 page = debugfs_priv->cb_data; 434 int i, n; 435 int max = 0xff; 436 437 rtw_read32(rtwdev, debugfs_priv->cb_data); 438 for (n = 0; n <= max; ) { 439 seq_printf(m, "\n%8.8x ", n + page); 440 for (i = 0; i < 4 && n <= max; i++, n += 4) 441 seq_printf(m, "%8.8x ", 442 rtw_read32(rtwdev, (page | n))); 443 } 444 seq_puts(m, "\n"); 445 return 0; 446 } 447 448 static int rtw_debug_get_bb_page(struct seq_file *m, void *v) 449 { 450 struct rtw_debugfs_priv *debugfs_priv = m->private; 451 struct rtw_dev *rtwdev = debugfs_priv->rtwdev; 452 u32 page = debugfs_priv->cb_data; 453 int i, n; 454 int max = 0xff; 455 456 rtw_read32(rtwdev, debugfs_priv->cb_data); 457 for (n = 0; n <= max; ) { 458 seq_printf(m, "\n%8.8x ", n + page); 459 for (i = 0; i < 4 && n <= max; i++, n += 4) 460 seq_printf(m, "%8.8x ", 461 rtw_read32(rtwdev, (page | n))); 462 } 463 seq_puts(m, "\n"); 464 return 0; 465 } 466 467 static int rtw_debug_get_rf_dump(struct seq_file *m, void *v) 468 { 469 struct rtw_debugfs_priv *debugfs_priv = m->private; 470 struct rtw_dev *rtwdev = debugfs_priv->rtwdev; 471 u32 addr, offset, data; 472 u8 path; 473 474 for (path = 0; path < rtwdev->hal.rf_path_num; path++) { 475 seq_printf(m, "RF path:%d\n", path); 476 for (addr = 0; addr < 0x100; addr += 4) { 477 seq_printf(m, "%8.8x ", addr); 478 for (offset = 0; offset < 4; offset++) { 479 data = rtw_read_rf(rtwdev, path, addr + offset, 480 0xffffffff); 481 seq_printf(m, "%8.8x ", data); 482 } 483 seq_puts(m, "\n"); 484 } 485 seq_puts(m, "\n"); 486 } 487 488 return 0; 489 } 490 491 static void rtw_print_cck_rate_txt(struct seq_file *m, u8 rate) 492 { 493 static const char * const 494 cck_rate[] = {"1M", "2M", "5.5M", "11M"}; 495 u8 idx = rate - DESC_RATE1M; 496 497 seq_printf(m, " CCK_%-5s", cck_rate[idx]); 498 } 499 500 static void rtw_print_ofdm_rate_txt(struct seq_file *m, u8 rate) 501 { 502 static const char * const 503 ofdm_rate[] = {"6M", "9M", "12M", "18M", "24M", "36M", "48M", "54M"}; 504 u8 idx = rate - DESC_RATE6M; 505 506 seq_printf(m, " OFDM_%-4s", ofdm_rate[idx]); 507 } 508 509 static void rtw_print_ht_rate_txt(struct seq_file *m, u8 rate) 510 { 511 u8 mcs_n = rate - DESC_RATEMCS0; 512 513 seq_printf(m, " MCS%-6u", mcs_n); 514 } 515 516 static void rtw_print_vht_rate_txt(struct seq_file *m, u8 rate) 517 { 518 u8 idx = rate - DESC_RATEVHT1SS_MCS0; 519 u8 n_ss, mcs_n; 520 521 /* n spatial stream */ 522 n_ss = 1 + idx / 10; 523 /* MCS n */ 524 mcs_n = idx % 10; 525 seq_printf(m, " VHT%uSMCS%u", n_ss, mcs_n); 526 } 527 528 static void rtw_print_rate(struct seq_file *m, u8 rate) 529 { 530 switch (rate) { 531 case DESC_RATE1M...DESC_RATE11M: 532 rtw_print_cck_rate_txt(m, rate); 533 break; 534 case DESC_RATE6M...DESC_RATE54M: 535 rtw_print_ofdm_rate_txt(m, rate); 536 break; 537 case DESC_RATEMCS0...DESC_RATEMCS15: 538 rtw_print_ht_rate_txt(m, rate); 539 break; 540 case DESC_RATEVHT1SS_MCS0...DESC_RATEVHT2SS_MCS9: 541 rtw_print_vht_rate_txt(m, rate); 542 break; 543 default: 544 seq_printf(m, " Unknown rate=0x%x\n", rate); 545 break; 546 } 547 } 548 549 #define case_REGD(src) \ 550 case RTW_REGD_##src: return #src 551 552 static const char *rtw_get_regd_string(u8 regd) 553 { 554 switch (regd) { 555 case_REGD(FCC); 556 case_REGD(MKK); 557 case_REGD(ETSI); 558 case_REGD(IC); 559 case_REGD(KCC); 560 case_REGD(ACMA); 561 case_REGD(CHILE); 562 case_REGD(UKRAINE); 563 case_REGD(MEXICO); 564 case_REGD(CN); 565 case_REGD(WW); 566 default: 567 return "Unknown"; 568 } 569 } 570 571 static int rtw_debugfs_get_tx_pwr_tbl(struct seq_file *m, void *v) 572 { 573 struct rtw_debugfs_priv *debugfs_priv = m->private; 574 struct rtw_dev *rtwdev = debugfs_priv->rtwdev; 575 struct rtw_hal *hal = &rtwdev->hal; 576 u8 path, rate; 577 struct rtw_power_params pwr_param = {0}; 578 u8 bw = hal->current_band_width; 579 u8 ch = hal->current_channel; 580 u8 regd = rtwdev->regd.txpwr_regd; 581 582 seq_printf(m, "regulatory: %s\n", rtw_get_regd_string(regd)); 583 seq_printf(m, "%-4s %-10s %-3s%6s %-4s %4s (%-4s %-4s) %-4s\n", 584 "path", "rate", "pwr", "", "base", "", "byr", "lmt", "rem"); 585 586 mutex_lock(&hal->tx_power_mutex); 587 for (path = RF_PATH_A; path <= RF_PATH_B; path++) { 588 /* there is no CCK rates used in 5G */ 589 if (hal->current_band_type == RTW_BAND_5G) 590 rate = DESC_RATE6M; 591 else 592 rate = DESC_RATE1M; 593 594 /* now, not support vht 3ss and vht 4ss*/ 595 for (; rate <= DESC_RATEVHT2SS_MCS9; rate++) { 596 /* now, not support ht 3ss and ht 4ss*/ 597 if (rate > DESC_RATEMCS15 && 598 rate < DESC_RATEVHT1SS_MCS0) 599 continue; 600 601 rtw_get_tx_power_params(rtwdev, path, rate, bw, 602 ch, regd, &pwr_param); 603 604 seq_printf(m, "%4c ", path + 'A'); 605 rtw_print_rate(m, rate); 606 seq_printf(m, " %3u(0x%02x) %4u %4d (%4d %4d) %4d\n", 607 hal->tx_pwr_tbl[path][rate], 608 hal->tx_pwr_tbl[path][rate], 609 pwr_param.pwr_base, 610 min_t(s8, pwr_param.pwr_offset, 611 pwr_param.pwr_limit), 612 pwr_param.pwr_offset, pwr_param.pwr_limit, 613 pwr_param.pwr_remnant); 614 } 615 } 616 617 mutex_unlock(&hal->tx_power_mutex); 618 619 return 0; 620 } 621 622 void rtw_debugfs_get_simple_phy_info(struct seq_file *m) 623 { 624 struct rtw_debugfs_priv *debugfs_priv = m->private; 625 struct rtw_dev *rtwdev = debugfs_priv->rtwdev; 626 struct rtw_hal *hal = &rtwdev->hal; 627 struct rtw_dm_info *dm_info = &rtwdev->dm_info; 628 struct rtw_traffic_stats *stats = &rtwdev->stats; 629 630 seq_printf(m, "%-40s = %ddBm/ %d\n", "RSSI/ STA Channel", 631 dm_info->rssi[RF_PATH_A] - 100, hal->current_channel); 632 633 seq_printf(m, "TP {Tx, Rx} = {%u, %u}Mbps\n", 634 stats->tx_throughput, stats->rx_throughput); 635 636 seq_puts(m, "[Tx Rate] = "); 637 rtw_print_rate(m, dm_info->tx_rate); 638 seq_printf(m, "(0x%x)\n", dm_info->tx_rate); 639 640 seq_puts(m, "[Rx Rate] = "); 641 rtw_print_rate(m, dm_info->curr_rx_rate); 642 seq_printf(m, "(0x%x)\n", dm_info->curr_rx_rate); 643 } 644 645 static int rtw_debugfs_get_phy_info(struct seq_file *m, void *v) 646 { 647 struct rtw_debugfs_priv *debugfs_priv = m->private; 648 struct rtw_dev *rtwdev = debugfs_priv->rtwdev; 649 struct rtw_dm_info *dm_info = &rtwdev->dm_info; 650 struct rtw_traffic_stats *stats = &rtwdev->stats; 651 struct rtw_pkt_count *last_cnt = &dm_info->last_pkt_count; 652 struct rtw_efuse *efuse = &rtwdev->efuse; 653 struct ewma_evm *ewma_evm = dm_info->ewma_evm; 654 struct ewma_snr *ewma_snr = dm_info->ewma_snr; 655 u8 ss, rate_id; 656 657 seq_puts(m, "==========[Common Info]========\n"); 658 seq_printf(m, "Is link = %c\n", rtw_is_assoc(rtwdev) ? 'Y' : 'N'); 659 seq_printf(m, "Current CH(fc) = %u\n", rtwdev->hal.current_channel); 660 seq_printf(m, "Current BW = %u\n", rtwdev->hal.current_band_width); 661 seq_printf(m, "Current IGI = 0x%x\n", dm_info->igi_history[0]); 662 seq_printf(m, "TP {Tx, Rx} = {%u, %u}Mbps\n\n", 663 stats->tx_throughput, stats->rx_throughput); 664 665 seq_puts(m, "==========[Tx Phy Info]========\n"); 666 seq_puts(m, "[Tx Rate] = "); 667 rtw_print_rate(m, dm_info->tx_rate); 668 seq_printf(m, "(0x%x)\n\n", dm_info->tx_rate); 669 670 seq_puts(m, "==========[Rx Phy Info]========\n"); 671 seq_printf(m, "[Rx Beacon Count] = %u\n", last_cnt->num_bcn_pkt); 672 seq_puts(m, "[Rx Rate] = "); 673 rtw_print_rate(m, dm_info->curr_rx_rate); 674 seq_printf(m, "(0x%x)\n", dm_info->curr_rx_rate); 675 676 seq_puts(m, "[Rx Rate Count]:\n"); 677 seq_printf(m, " * CCK = {%u, %u, %u, %u}\n", 678 last_cnt->num_qry_pkt[DESC_RATE1M], 679 last_cnt->num_qry_pkt[DESC_RATE2M], 680 last_cnt->num_qry_pkt[DESC_RATE5_5M], 681 last_cnt->num_qry_pkt[DESC_RATE11M]); 682 683 seq_printf(m, " * OFDM = {%u, %u, %u, %u, %u, %u, %u, %u}\n", 684 last_cnt->num_qry_pkt[DESC_RATE6M], 685 last_cnt->num_qry_pkt[DESC_RATE9M], 686 last_cnt->num_qry_pkt[DESC_RATE12M], 687 last_cnt->num_qry_pkt[DESC_RATE18M], 688 last_cnt->num_qry_pkt[DESC_RATE24M], 689 last_cnt->num_qry_pkt[DESC_RATE36M], 690 last_cnt->num_qry_pkt[DESC_RATE48M], 691 last_cnt->num_qry_pkt[DESC_RATE54M]); 692 693 for (ss = 0; ss < efuse->hw_cap.nss; ss++) { 694 rate_id = DESC_RATEMCS0 + ss * 8; 695 seq_printf(m, " * HT_MCS[%u:%u] = {%u, %u, %u, %u, %u, %u, %u, %u}\n", 696 ss * 8, ss * 8 + 7, 697 last_cnt->num_qry_pkt[rate_id], 698 last_cnt->num_qry_pkt[rate_id + 1], 699 last_cnt->num_qry_pkt[rate_id + 2], 700 last_cnt->num_qry_pkt[rate_id + 3], 701 last_cnt->num_qry_pkt[rate_id + 4], 702 last_cnt->num_qry_pkt[rate_id + 5], 703 last_cnt->num_qry_pkt[rate_id + 6], 704 last_cnt->num_qry_pkt[rate_id + 7]); 705 } 706 707 for (ss = 0; ss < efuse->hw_cap.nss; ss++) { 708 rate_id = DESC_RATEVHT1SS_MCS0 + ss * 10; 709 seq_printf(m, " * VHT_MCS-%uss MCS[0:9] = {%u, %u, %u, %u, %u, %u, %u, %u, %u, %u}\n", 710 ss + 1, 711 last_cnt->num_qry_pkt[rate_id], 712 last_cnt->num_qry_pkt[rate_id + 1], 713 last_cnt->num_qry_pkt[rate_id + 2], 714 last_cnt->num_qry_pkt[rate_id + 3], 715 last_cnt->num_qry_pkt[rate_id + 4], 716 last_cnt->num_qry_pkt[rate_id + 5], 717 last_cnt->num_qry_pkt[rate_id + 6], 718 last_cnt->num_qry_pkt[rate_id + 7], 719 last_cnt->num_qry_pkt[rate_id + 8], 720 last_cnt->num_qry_pkt[rate_id + 9]); 721 } 722 723 seq_printf(m, "[RSSI(dBm)] = {%d, %d}\n", 724 dm_info->rssi[RF_PATH_A] - 100, 725 dm_info->rssi[RF_PATH_B] - 100); 726 seq_printf(m, "[Rx EVM(dB)] = {-%d, -%d}\n", 727 dm_info->rx_evm_dbm[RF_PATH_A], 728 dm_info->rx_evm_dbm[RF_PATH_B]); 729 seq_printf(m, "[Rx SNR] = {%d, %d}\n", 730 dm_info->rx_snr[RF_PATH_A], 731 dm_info->rx_snr[RF_PATH_B]); 732 seq_printf(m, "[CFO_tail(KHz)] = {%d, %d}\n", 733 dm_info->cfo_tail[RF_PATH_A], 734 dm_info->cfo_tail[RF_PATH_B]); 735 736 if (dm_info->curr_rx_rate >= DESC_RATE11M) { 737 seq_puts(m, "[Rx Average Status]:\n"); 738 seq_printf(m, " * OFDM, EVM: {-%d}, SNR: {%d}\n", 739 (u8)ewma_evm_read(&ewma_evm[RTW_EVM_OFDM]), 740 (u8)ewma_snr_read(&ewma_snr[RTW_SNR_OFDM_A])); 741 seq_printf(m, " * 1SS, EVM: {-%d}, SNR: {%d}\n", 742 (u8)ewma_evm_read(&ewma_evm[RTW_EVM_1SS]), 743 (u8)ewma_snr_read(&ewma_snr[RTW_SNR_1SS_A])); 744 seq_printf(m, " * 2SS, EVM: {-%d, -%d}, SNR: {%d, %d}\n", 745 (u8)ewma_evm_read(&ewma_evm[RTW_EVM_2SS_A]), 746 (u8)ewma_evm_read(&ewma_evm[RTW_EVM_2SS_B]), 747 (u8)ewma_snr_read(&ewma_snr[RTW_SNR_2SS_A]), 748 (u8)ewma_snr_read(&ewma_snr[RTW_SNR_2SS_B])); 749 } 750 751 seq_puts(m, "[Rx Counter]:\n"); 752 seq_printf(m, " * CCA (CCK, OFDM, Total) = (%u, %u, %u)\n", 753 dm_info->cck_cca_cnt, 754 dm_info->ofdm_cca_cnt, 755 dm_info->total_cca_cnt); 756 seq_printf(m, " * False Alarm (CCK, OFDM, Total) = (%u, %u, %u)\n", 757 dm_info->cck_fa_cnt, 758 dm_info->ofdm_fa_cnt, 759 dm_info->total_fa_cnt); 760 seq_printf(m, " * CCK cnt (ok, err) = (%u, %u)\n", 761 dm_info->cck_ok_cnt, dm_info->cck_err_cnt); 762 seq_printf(m, " * OFDM cnt (ok, err) = (%u, %u)\n", 763 dm_info->ofdm_ok_cnt, dm_info->ofdm_err_cnt); 764 seq_printf(m, " * HT cnt (ok, err) = (%u, %u)\n", 765 dm_info->ht_ok_cnt, dm_info->ht_err_cnt); 766 seq_printf(m, " * VHT cnt (ok, err) = (%u, %u)\n", 767 dm_info->vht_ok_cnt, dm_info->vht_err_cnt); 768 769 return 0; 770 } 771 772 static int rtw_debugfs_get_coex_info(struct seq_file *m, void *v) 773 { 774 struct rtw_debugfs_priv *debugfs_priv = m->private; 775 struct rtw_dev *rtwdev = debugfs_priv->rtwdev; 776 777 rtw_coex_display_coex_info(rtwdev, m); 778 779 return 0; 780 } 781 782 static ssize_t rtw_debugfs_set_coex_enable(struct file *filp, 783 const char __user *buffer, 784 size_t count, loff_t *loff) 785 { 786 struct seq_file *seqpriv = (struct seq_file *)filp->private_data; 787 struct rtw_debugfs_priv *debugfs_priv = seqpriv->private; 788 struct rtw_dev *rtwdev = debugfs_priv->rtwdev; 789 struct rtw_coex *coex = &rtwdev->coex; 790 char tmp[32 + 1]; 791 bool enable; 792 int ret; 793 794 rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 1); 795 796 ret = kstrtobool(tmp, &enable); 797 if (ret) { 798 rtw_warn(rtwdev, "invalid arguments\n"); 799 return ret; 800 } 801 802 mutex_lock(&rtwdev->mutex); 803 coex->manual_control = enable == 0; 804 mutex_unlock(&rtwdev->mutex); 805 806 return count; 807 } 808 809 static int rtw_debugfs_get_coex_enable(struct seq_file *m, void *v) 810 { 811 struct rtw_debugfs_priv *debugfs_priv = m->private; 812 struct rtw_dev *rtwdev = debugfs_priv->rtwdev; 813 struct rtw_coex *coex = &rtwdev->coex; 814 815 seq_printf(m, "coex mechanism %s\n", 816 coex->manual_control ? "disabled" : "enabled"); 817 818 return 0; 819 } 820 821 #define rtw_debug_impl_mac(page, addr) \ 822 static struct rtw_debugfs_priv rtw_debug_priv_mac_ ##page = { \ 823 .cb_read = rtw_debug_get_mac_page, \ 824 .cb_data = addr, \ 825 } 826 827 rtw_debug_impl_mac(0, 0x0000); 828 rtw_debug_impl_mac(1, 0x0100); 829 rtw_debug_impl_mac(2, 0x0200); 830 rtw_debug_impl_mac(3, 0x0300); 831 rtw_debug_impl_mac(4, 0x0400); 832 rtw_debug_impl_mac(5, 0x0500); 833 rtw_debug_impl_mac(6, 0x0600); 834 rtw_debug_impl_mac(7, 0x0700); 835 rtw_debug_impl_mac(10, 0x1000); 836 rtw_debug_impl_mac(11, 0x1100); 837 rtw_debug_impl_mac(12, 0x1200); 838 rtw_debug_impl_mac(13, 0x1300); 839 rtw_debug_impl_mac(14, 0x1400); 840 rtw_debug_impl_mac(15, 0x1500); 841 rtw_debug_impl_mac(16, 0x1600); 842 rtw_debug_impl_mac(17, 0x1700); 843 844 #define rtw_debug_impl_bb(page, addr) \ 845 static struct rtw_debugfs_priv rtw_debug_priv_bb_ ##page = { \ 846 .cb_read = rtw_debug_get_bb_page, \ 847 .cb_data = addr, \ 848 } 849 850 rtw_debug_impl_bb(8, 0x0800); 851 rtw_debug_impl_bb(9, 0x0900); 852 rtw_debug_impl_bb(a, 0x0a00); 853 rtw_debug_impl_bb(b, 0x0b00); 854 rtw_debug_impl_bb(c, 0x0c00); 855 rtw_debug_impl_bb(d, 0x0d00); 856 rtw_debug_impl_bb(e, 0x0e00); 857 rtw_debug_impl_bb(f, 0x0f00); 858 rtw_debug_impl_bb(18, 0x1800); 859 rtw_debug_impl_bb(19, 0x1900); 860 rtw_debug_impl_bb(1a, 0x1a00); 861 rtw_debug_impl_bb(1b, 0x1b00); 862 rtw_debug_impl_bb(1c, 0x1c00); 863 rtw_debug_impl_bb(1d, 0x1d00); 864 rtw_debug_impl_bb(1e, 0x1e00); 865 rtw_debug_impl_bb(1f, 0x1f00); 866 rtw_debug_impl_bb(2c, 0x2c00); 867 rtw_debug_impl_bb(2d, 0x2d00); 868 rtw_debug_impl_bb(40, 0x4000); 869 rtw_debug_impl_bb(41, 0x4100); 870 871 static struct rtw_debugfs_priv rtw_debug_priv_rf_dump = { 872 .cb_read = rtw_debug_get_rf_dump, 873 }; 874 875 static struct rtw_debugfs_priv rtw_debug_priv_tx_pwr_tbl = { 876 .cb_read = rtw_debugfs_get_tx_pwr_tbl, 877 }; 878 879 static struct rtw_debugfs_priv rtw_debug_priv_write_reg = { 880 .cb_write = rtw_debugfs_set_write_reg, 881 }; 882 883 static struct rtw_debugfs_priv rtw_debug_priv_h2c = { 884 .cb_write = rtw_debugfs_set_h2c, 885 }; 886 887 static struct rtw_debugfs_priv rtw_debug_priv_rf_write = { 888 .cb_write = rtw_debugfs_set_rf_write, 889 }; 890 891 static struct rtw_debugfs_priv rtw_debug_priv_rf_read = { 892 .cb_write = rtw_debugfs_set_rf_read, 893 .cb_read = rtw_debugfs_get_rf_read, 894 }; 895 896 static struct rtw_debugfs_priv rtw_debug_priv_read_reg = { 897 .cb_write = rtw_debugfs_set_read_reg, 898 .cb_read = rtw_debugfs_get_read_reg, 899 }; 900 901 static struct rtw_debugfs_priv rtw_debug_priv_dump_cam = { 902 .cb_write = rtw_debugfs_set_single_input, 903 .cb_read = rtw_debugfs_get_dump_cam, 904 }; 905 906 static struct rtw_debugfs_priv rtw_debug_priv_rsvd_page = { 907 .cb_write = rtw_debugfs_set_rsvd_page, 908 .cb_read = rtw_debugfs_get_rsvd_page, 909 }; 910 911 static struct rtw_debugfs_priv rtw_debug_priv_phy_info = { 912 .cb_read = rtw_debugfs_get_phy_info, 913 }; 914 915 static struct rtw_debugfs_priv rtw_debug_priv_coex_enable = { 916 .cb_write = rtw_debugfs_set_coex_enable, 917 .cb_read = rtw_debugfs_get_coex_enable, 918 }; 919 920 static struct rtw_debugfs_priv rtw_debug_priv_coex_info = { 921 .cb_read = rtw_debugfs_get_coex_info, 922 }; 923 924 #define rtw_debugfs_add_core(name, mode, fopname, parent) \ 925 do { \ 926 rtw_debug_priv_ ##name.rtwdev = rtwdev; \ 927 if (!debugfs_create_file(#name, mode, \ 928 parent, &rtw_debug_priv_ ##name,\ 929 &file_ops_ ##fopname)) \ 930 pr_debug("Unable to initialize debugfs:%s\n", \ 931 #name); \ 932 } while (0) 933 934 #define rtw_debugfs_add_w(name) \ 935 rtw_debugfs_add_core(name, S_IFREG | 0222, common_write, debugfs_topdir) 936 #define rtw_debugfs_add_rw(name) \ 937 rtw_debugfs_add_core(name, S_IFREG | 0666, single_rw, debugfs_topdir) 938 #define rtw_debugfs_add_r(name) \ 939 rtw_debugfs_add_core(name, S_IFREG | 0444, single_r, debugfs_topdir) 940 941 void rtw_debugfs_init(struct rtw_dev *rtwdev) 942 { 943 struct dentry *debugfs_topdir; 944 945 debugfs_topdir = debugfs_create_dir("rtw88", 946 rtwdev->hw->wiphy->debugfsdir); 947 rtw_debugfs_add_w(write_reg); 948 rtw_debugfs_add_rw(read_reg); 949 rtw_debugfs_add_w(rf_write); 950 rtw_debugfs_add_rw(rf_read); 951 rtw_debugfs_add_rw(dump_cam); 952 rtw_debugfs_add_rw(rsvd_page); 953 rtw_debugfs_add_r(phy_info); 954 rtw_debugfs_add_r(coex_info); 955 rtw_debugfs_add_rw(coex_enable); 956 rtw_debugfs_add_w(h2c); 957 rtw_debugfs_add_r(mac_0); 958 rtw_debugfs_add_r(mac_1); 959 rtw_debugfs_add_r(mac_2); 960 rtw_debugfs_add_r(mac_3); 961 rtw_debugfs_add_r(mac_4); 962 rtw_debugfs_add_r(mac_5); 963 rtw_debugfs_add_r(mac_6); 964 rtw_debugfs_add_r(mac_7); 965 rtw_debugfs_add_r(bb_8); 966 rtw_debugfs_add_r(bb_9); 967 rtw_debugfs_add_r(bb_a); 968 rtw_debugfs_add_r(bb_b); 969 rtw_debugfs_add_r(bb_c); 970 rtw_debugfs_add_r(bb_d); 971 rtw_debugfs_add_r(bb_e); 972 rtw_debugfs_add_r(bb_f); 973 rtw_debugfs_add_r(mac_10); 974 rtw_debugfs_add_r(mac_11); 975 rtw_debugfs_add_r(mac_12); 976 rtw_debugfs_add_r(mac_13); 977 rtw_debugfs_add_r(mac_14); 978 rtw_debugfs_add_r(mac_15); 979 rtw_debugfs_add_r(mac_16); 980 rtw_debugfs_add_r(mac_17); 981 rtw_debugfs_add_r(bb_18); 982 rtw_debugfs_add_r(bb_19); 983 rtw_debugfs_add_r(bb_1a); 984 rtw_debugfs_add_r(bb_1b); 985 rtw_debugfs_add_r(bb_1c); 986 rtw_debugfs_add_r(bb_1d); 987 rtw_debugfs_add_r(bb_1e); 988 rtw_debugfs_add_r(bb_1f); 989 if (rtwdev->chip->id == RTW_CHIP_TYPE_8822C) { 990 rtw_debugfs_add_r(bb_2c); 991 rtw_debugfs_add_r(bb_2d); 992 rtw_debugfs_add_r(bb_40); 993 rtw_debugfs_add_r(bb_41); 994 } 995 rtw_debugfs_add_r(rf_dump); 996 rtw_debugfs_add_r(tx_pwr_tbl); 997 } 998 999 #endif /* CONFIG_RTW88_DEBUGFS */ 1000 1001 #ifdef CONFIG_RTW88_DEBUG 1002 1003 void __rtw_dbg(struct rtw_dev *rtwdev, enum rtw_debug_mask mask, 1004 const char *fmt, ...) 1005 { 1006 struct va_format vaf = { 1007 .fmt = fmt, 1008 }; 1009 va_list args; 1010 1011 va_start(args, fmt); 1012 vaf.va = &args; 1013 1014 if (rtw_debug_mask & mask) 1015 dev_printk(KERN_DEBUG, rtwdev->dev, "%pV", &vaf); 1016 1017 va_end(args); 1018 } 1019 EXPORT_SYMBOL(__rtw_dbg); 1020 1021 #endif /* CONFIG_RTW88_DEBUG */ 1022