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