1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /* Copyright(c) 2018-2019 Realtek Corporation
5 #include <linux/debugfs.h>
6 #include <linux/seq_file.h>
17 #ifdef CONFIG_RTW88_DEBUGFS
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);
46 static const char * const rtw_dm_cap_strs[] = {
47 [RTW_DM_CAP_NA] = "NA",
48 [RTW_DM_CAP_TXGAPK] = "TXGAPK",
51 static int rtw_debugfs_single_show(struct seq_file *m, void *v)
53 struct rtw_debugfs_priv *debugfs_priv = m->private;
55 return debugfs_priv->cb_read(m, v);
58 static ssize_t rtw_debugfs_common_write(struct file *filp,
59 const char __user *buffer,
60 size_t count, loff_t *loff)
62 struct rtw_debugfs_priv *debugfs_priv = filp->private_data;
64 return debugfs_priv->cb_write(filp, buffer, count, loff);
67 static ssize_t rtw_debugfs_single_write(struct file *filp,
68 const char __user *buffer,
69 size_t count, loff_t *loff)
71 struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
72 struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
74 return debugfs_priv->cb_write(filp, buffer, count, loff);
77 static int rtw_debugfs_single_open_rw(struct inode *inode, struct file *filp)
79 return single_open(filp, rtw_debugfs_single_show, inode->i_private);
82 static int rtw_debugfs_close(struct inode *inode, struct file *filp)
87 static const struct file_operations file_ops_single_r = {
89 .open = rtw_debugfs_single_open_rw,
92 .release = single_release,
95 static const struct file_operations file_ops_single_rw = {
97 .open = rtw_debugfs_single_open_rw,
98 .release = single_release,
101 .write = rtw_debugfs_single_write,
104 static const struct file_operations file_ops_common_write = {
105 .owner = THIS_MODULE,
106 .write = rtw_debugfs_common_write,
108 .release = rtw_debugfs_close,
111 static int rtw_debugfs_get_read_reg(struct seq_file *m, void *v)
113 struct rtw_debugfs_priv *debugfs_priv = m->private;
114 struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
117 len = debugfs_priv->read_reg.len;
118 addr = debugfs_priv->read_reg.addr;
121 val = rtw_read8(rtwdev, addr);
122 seq_printf(m, "reg 0x%03x: 0x%02x\n", addr, val);
125 val = rtw_read16(rtwdev, addr);
126 seq_printf(m, "reg 0x%03x: 0x%04x\n", addr, val);
129 val = rtw_read32(rtwdev, addr);
130 seq_printf(m, "reg 0x%03x: 0x%08x\n", addr, val);
136 static int rtw_debugfs_get_rf_read(struct seq_file *m, void *v)
138 struct rtw_debugfs_priv *debugfs_priv = m->private;
139 struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
143 path = debugfs_priv->rf_path;
144 addr = debugfs_priv->rf_addr;
145 mask = debugfs_priv->rf_mask;
147 val = rtw_read_rf(rtwdev, path, addr, mask);
149 seq_printf(m, "rf_read path:%d addr:0x%08x mask:0x%08x val=0x%08x\n",
150 path, addr, mask, val);
155 static int rtw_debugfs_get_fix_rate(struct seq_file *m, void *v)
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;
162 if (fix_rate >= DESC_RATE_MAX) {
163 seq_printf(m, "Fix rate disabled, fix_rate = %u\n", fix_rate);
167 seq_printf(m, "Data frames fixed at desc rate %u\n", fix_rate);
171 static int rtw_debugfs_copy_from_user(char tmp[], int size,
172 const char __user *buffer, size_t count,
177 memset(tmp, 0, size);
182 tmp_len = (count > size - 1 ? size - 1 : count);
184 if (!buffer || copy_from_user(tmp, buffer, tmp_len))
192 static ssize_t rtw_debugfs_set_read_reg(struct file *filp,
193 const char __user *buffer,
194 size_t count, loff_t *loff)
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;
203 rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 2);
205 num = sscanf(tmp, "%x %x", &addr, &len);
210 if (len != 1 && len != 2 && len != 4) {
211 rtw_warn(rtwdev, "read reg setting wrong len\n");
214 debugfs_priv->read_reg.addr = addr;
215 debugfs_priv->read_reg.len = len;
220 static int rtw_debugfs_get_dump_cam(struct seq_file *m, void *v)
222 struct rtw_debugfs_priv *debugfs_priv = m->private;
223 struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
225 u32 hw_key_idx = debugfs_priv->cb_data << RTW_SEC_CAM_ENTRY_SHIFT;
226 u32 read_cmd = RTW_SEC_CMD_POLLING;
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);
242 mutex_unlock(&rtwdev->mutex);
246 static int rtw_debugfs_get_rsvd_page(struct seq_file *m, void *v)
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;
257 buf = vzalloc(buf_size);
261 ret = rtw_fw_dump_fifo(rtwdev, RTW_FW_FIFO_SEL_RSVD_PAGE, offset,
262 buf_size, (u32 *)buf);
264 rtw_err(rtwdev, "failed to dump rsvd page\n");
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);
279 static ssize_t rtw_debugfs_set_rsvd_page(struct file *filp,
280 const char __user *buffer,
281 size_t count, loff_t *loff)
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;
287 u32 offset, page_num;
290 rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 2);
292 num = sscanf(tmp, "%d %d", &offset, &page_num);
295 rtw_warn(rtwdev, "invalid arguments\n");
299 debugfs_priv->rsvd_page.page_offset = offset;
300 debugfs_priv->rsvd_page.page_num = page_num;
305 static ssize_t rtw_debugfs_set_single_input(struct file *filp,
306 const char __user *buffer,
307 size_t count, loff_t *loff)
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;
316 rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 1);
318 num = kstrtoint(tmp, 0, &input);
321 rtw_warn(rtwdev, "kstrtoint failed\n");
325 debugfs_priv->cb_data = input;
330 static ssize_t rtw_debugfs_set_write_reg(struct file *filp,
331 const char __user *buffer,
332 size_t count, loff_t *loff)
334 struct rtw_debugfs_priv *debugfs_priv = filp->private_data;
335 struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
340 rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 3);
342 /* write BB/MAC register */
343 num = sscanf(tmp, "%x %x %x", &addr, &val, &len);
350 rtw_dbg(rtwdev, RTW_DBG_DEBUGFS,
351 "reg write8 0x%03x: 0x%08x\n", addr, val);
352 rtw_write8(rtwdev, addr, (u8)val);
355 rtw_dbg(rtwdev, RTW_DBG_DEBUGFS,
356 "reg write16 0x%03x: 0x%08x\n", addr, val);
357 rtw_write16(rtwdev, addr, (u16)val);
360 rtw_dbg(rtwdev, RTW_DBG_DEBUGFS,
361 "reg write32 0x%03x: 0x%08x\n", addr, val);
362 rtw_write32(rtwdev, addr, (u32)val);
365 rtw_dbg(rtwdev, RTW_DBG_DEBUGFS,
366 "error write length = %d\n", len);
373 static ssize_t rtw_debugfs_set_h2c(struct file *filp,
374 const char __user *buffer,
375 size_t count, loff_t *loff)
377 struct rtw_debugfs_priv *debugfs_priv = filp->private_data;
378 struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
383 rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 3);
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]);
389 rtw_warn(rtwdev, "invalid H2C command format for debug\n");
393 rtw_fw_h2c_cmd_dbg(rtwdev, param);
398 static ssize_t rtw_debugfs_set_rf_write(struct file *filp,
399 const char __user *buffer,
400 size_t count, loff_t *loff)
402 struct rtw_debugfs_priv *debugfs_priv = filp->private_data;
403 struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
405 u32 path, addr, mask, val;
408 rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 4);
410 num = sscanf(tmp, "%x %x %x %x", &path, &addr, &mask, &val);
413 rtw_warn(rtwdev, "invalid args, [path] [addr] [mask] [val]\n");
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);
425 static ssize_t rtw_debugfs_set_rf_read(struct file *filp,
426 const char __user *buffer,
427 size_t count, loff_t *loff)
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;
433 u32 path, addr, mask;
436 rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 3);
438 num = sscanf(tmp, "%x %x %x", &path, &addr, &mask);
441 rtw_warn(rtwdev, "invalid args, [path] [addr] [mask] [val]\n");
445 debugfs_priv->rf_path = path;
446 debugfs_priv->rf_addr = addr;
447 debugfs_priv->rf_mask = mask;
452 static ssize_t rtw_debugfs_set_fix_rate(struct file *filp,
453 const char __user *buffer,
454 size_t count, loff_t *loff)
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;
464 rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 1);
466 ret = kstrtou8(tmp, 0, &fix_rate);
468 rtw_warn(rtwdev, "invalid args, [rate]\n");
472 dm_info->fix_rate = fix_rate;
477 static int rtw_debug_get_mac_page(struct seq_file *m, void *v)
479 struct rtw_debugfs_priv *debugfs_priv = m->private;
480 struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
481 u32 page = debugfs_priv->cb_data;
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)));
496 static int rtw_debug_get_bb_page(struct seq_file *m, void *v)
498 struct rtw_debugfs_priv *debugfs_priv = m->private;
499 struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
500 u32 page = debugfs_priv->cb_data;
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)));
515 static int rtw_debug_get_rf_dump(struct seq_file *m, void *v)
517 struct rtw_debugfs_priv *debugfs_priv = m->private;
518 struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
519 u32 addr, offset, data;
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,
529 seq_printf(m, "%8.8x ", data);
539 static void rtw_print_cck_rate_txt(struct seq_file *m, u8 rate)
541 static const char * const
542 cck_rate[] = {"1M", "2M", "5.5M", "11M"};
543 u8 idx = rate - DESC_RATE1M;
545 seq_printf(m, " CCK_%-5s", cck_rate[idx]);
548 static void rtw_print_ofdm_rate_txt(struct seq_file *m, u8 rate)
550 static const char * const
551 ofdm_rate[] = {"6M", "9M", "12M", "18M", "24M", "36M", "48M", "54M"};
552 u8 idx = rate - DESC_RATE6M;
554 seq_printf(m, " OFDM_%-4s", ofdm_rate[idx]);
557 static void rtw_print_ht_rate_txt(struct seq_file *m, u8 rate)
559 u8 mcs_n = rate - DESC_RATEMCS0;
561 seq_printf(m, " MCS%-6u", mcs_n);
564 static void rtw_print_vht_rate_txt(struct seq_file *m, u8 rate)
566 u8 idx = rate - DESC_RATEVHT1SS_MCS0;
569 /* n spatial stream */
573 seq_printf(m, " VHT%uSMCS%u", n_ss, mcs_n);
576 static void rtw_print_rate(struct seq_file *m, u8 rate)
579 case DESC_RATE1M...DESC_RATE11M:
580 rtw_print_cck_rate_txt(m, rate);
582 case DESC_RATE6M...DESC_RATE54M:
583 rtw_print_ofdm_rate_txt(m, rate);
585 case DESC_RATEMCS0...DESC_RATEMCS15:
586 rtw_print_ht_rate_txt(m, rate);
588 case DESC_RATEVHT1SS_MCS0...DESC_RATEVHT2SS_MCS9:
589 rtw_print_vht_rate_txt(m, rate);
592 seq_printf(m, " Unknown rate=0x%x\n", rate);
597 #define case_REGD(src) \
598 case RTW_REGD_##src: return #src
600 static const char *rtw_get_regd_string(u8 regd)
619 static int rtw_debugfs_get_tx_pwr_tbl(struct seq_file *m, void *v)
621 struct rtw_debugfs_priv *debugfs_priv = m->private;
622 struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
623 struct rtw_hal *hal = &rtwdev->hal;
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);
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");
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)
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)
651 rtw_get_tx_power_params(rtwdev, path, rate, bw,
652 ch, regd, &pwr_param);
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],
660 min3(pwr_param.pwr_offset,
663 pwr_param.pwr_offset, pwr_param.pwr_limit,
665 pwr_param.pwr_remnant);
669 mutex_unlock(&hal->tx_power_mutex);
674 void rtw_debugfs_get_simple_phy_info(struct seq_file *m)
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;
682 seq_printf(m, "%-40s = %ddBm/ %d\n", "RSSI/ STA Channel",
683 dm_info->rssi[RF_PATH_A] - 100, hal->current_channel);
685 seq_printf(m, "TP {Tx, Rx} = {%u, %u}Mbps\n",
686 stats->tx_throughput, stats->rx_throughput);
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);
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);
697 static int rtw_debugfs_get_phy_info(struct seq_file *m, void *v)
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;
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 ?
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);
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);
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]);
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]);
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",
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]);
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",
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]);
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]);
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]));
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",
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);
826 static int rtw_debugfs_get_coex_info(struct seq_file *m, void *v)
828 struct rtw_debugfs_priv *debugfs_priv = m->private;
829 struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
831 rtw_coex_display_coex_info(rtwdev, m);
836 static ssize_t rtw_debugfs_set_coex_enable(struct file *filp,
837 const char __user *buffer,
838 size_t count, loff_t *loff)
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;
848 rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 1);
850 ret = kstrtobool(tmp, &enable);
852 rtw_warn(rtwdev, "invalid arguments\n");
856 mutex_lock(&rtwdev->mutex);
857 coex->manual_control = !enable;
858 mutex_unlock(&rtwdev->mutex);
863 static int rtw_debugfs_get_coex_enable(struct seq_file *m, void *v)
865 struct rtw_debugfs_priv *debugfs_priv = m->private;
866 struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
867 struct rtw_coex *coex = &rtwdev->coex;
869 seq_printf(m, "coex mechanism %s\n",
870 coex->manual_control ? "disabled" : "enabled");
875 static ssize_t rtw_debugfs_set_edcca_enable(struct file *filp,
876 const char __user *buffer,
877 size_t count, loff_t *loff)
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;
885 err = kstrtobool_from_user(buffer, count, &input);
889 rtw_edcca_enabled = input;
890 rtw_phy_adaptivity_set_mode(rtwdev);
895 static int rtw_debugfs_get_edcca_enable(struct seq_file *m, void *v)
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;
901 seq_printf(m, "EDCCA %s: EDCCA mode %d\n",
902 rtw_edcca_enabled ? "enabled" : "disabled",
903 dm_info->edcca_mode);
907 static ssize_t rtw_debugfs_set_fw_crash(struct file *filp,
908 const char __user *buffer,
909 size_t count, loff_t *loff)
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;
918 rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 1);
920 ret = kstrtobool(tmp, &input);
927 if (test_bit(RTW_FLAG_RESTARTING, rtwdev->flags))
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);
939 static int rtw_debugfs_get_fw_crash(struct seq_file *m, void *v)
941 struct rtw_debugfs_priv *debugfs_priv = m->private;
942 struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
944 seq_printf(m, "%d\n",
945 test_bit(RTW_FLAG_RESTART_TRIGGERING, rtwdev->flags) ||
946 test_bit(RTW_FLAG_RESTARTING, rtwdev->flags));
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)
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;
960 err = kstrtobool_from_user(buffer, count, &input);
965 set_bit(RTW_FLAG_FORCE_LOWEST_RATE, rtwdev->flags);
967 clear_bit(RTW_FLAG_FORCE_LOWEST_RATE, rtwdev->flags);
972 static int rtw_debugfs_get_force_lowest_basic_rate(struct seq_file *m, void *v)
974 struct rtw_debugfs_priv *debugfs_priv = m->private;
975 struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
977 seq_printf(m, "force lowest basic rate: %d\n",
978 test_bit(RTW_FLAG_FORCE_LOWEST_RATE, rtwdev->flags));
983 static ssize_t rtw_debugfs_set_dm_cap(struct file *filp,
984 const char __user *buffer,
985 size_t count, loff_t *loff)
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;
994 if (kstrtoint_from_user(buffer, count, 10, &bit))
1000 if (bit >= RTW_DM_CAP_NUM) {
1001 rtw_warn(rtwdev, "unknown DM CAP %d\n", bit);
1006 dm_info->dm_flags &= ~BIT(bit);
1008 dm_info->dm_flags |= BIT(bit);
1010 debugfs_priv->dm_cap.bit = bit;
1015 static void dump_gapk_status(struct rtw_dev *rtwdev, struct seq_file *m)
1017 struct rtw_dm_info *dm_info = &rtwdev->dm_info;
1018 struct rtw_gapk_info *txgapk = &rtwdev->dm_info.gapk;
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]);
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);
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);
1037 static int rtw_debugfs_get_dm_cap(struct seq_file *m, void *v)
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;
1044 switch (debugfs_priv->dm_cap.bit) {
1045 case RTW_DM_CAP_TXGAPK:
1046 dump_gapk_status(rtwdev, m);
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]);
1056 debugfs_priv->dm_cap.bit = RTW_DM_CAP_NA;
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, \
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);
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, \
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);
1110 static struct rtw_debugfs_priv rtw_debug_priv_rf_dump = {
1111 .cb_read = rtw_debug_get_rf_dump,
1114 static struct rtw_debugfs_priv rtw_debug_priv_tx_pwr_tbl = {
1115 .cb_read = rtw_debugfs_get_tx_pwr_tbl,
1118 static struct rtw_debugfs_priv rtw_debug_priv_write_reg = {
1119 .cb_write = rtw_debugfs_set_write_reg,
1122 static struct rtw_debugfs_priv rtw_debug_priv_h2c = {
1123 .cb_write = rtw_debugfs_set_h2c,
1126 static struct rtw_debugfs_priv rtw_debug_priv_rf_write = {
1127 .cb_write = rtw_debugfs_set_rf_write,
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,
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,
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,
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,
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,
1155 static struct rtw_debugfs_priv rtw_debug_priv_phy_info = {
1156 .cb_read = rtw_debugfs_get_phy_info,
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,
1164 static struct rtw_debugfs_priv rtw_debug_priv_coex_info = {
1165 .cb_read = rtw_debugfs_get_coex_info,
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,
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,
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,
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,
1188 #define rtw_debugfs_add_core(name, mode, fopname, parent) \
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", \
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)
1205 void rtw_debugfs_init(struct rtw_dev *rtwdev)
1207 struct dentry *debugfs_topdir;
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);
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);
1268 #endif /* CONFIG_RTW88_DEBUGFS */
1270 #ifdef CONFIG_RTW88_DEBUG
1272 void __rtw_dbg(struct rtw_dev *rtwdev, enum rtw_debug_mask mask,
1273 const char *fmt, ...)
1275 struct va_format vaf = {
1280 va_start(args, fmt);
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, vaf.fmt, args);
1292 EXPORT_SYMBOL(__rtw_dbg);
1294 #endif /* CONFIG_RTW88_DEBUG */