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