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