1 // SPDX-License-Identifier: ISC
2 /* Copyright (C) 2020 MediaTek Inc. */
4 #include <linux/relay.h>
10 #define FW_BIN_LOG_MAGIC 0x44e98caf
12 /** global debugfs **/
22 mt7915_implicit_txbf_set(void *data, u64 val)
24 struct mt7915_dev *dev = data;
26 if (test_bit(MT76_STATE_RUNNING, &dev->mphy.state))
31 return mt7915_mcu_set_txbf(dev, MT_BF_TYPE_UPDATE);
35 mt7915_implicit_txbf_get(void *data, u64 *val)
37 struct mt7915_dev *dev = data;
44 DEFINE_DEBUGFS_ATTRIBUTE(fops_implicit_txbf, mt7915_implicit_txbf_get,
45 mt7915_implicit_txbf_set, "%lld\n");
47 /* test knob of system layer 1/2 error recovery */
48 static int mt7915_ser_trigger_set(void *data, u64 val)
51 SER_SET_RECOVER_L1 = 1,
56 struct mt7915_dev *dev = data;
60 case SER_SET_RECOVER_L1:
61 case SER_SET_RECOVER_L2:
62 ret = mt7915_mcu_set_ser(dev, SER_ENABLE, BIT(val), 0);
66 return mt7915_mcu_set_ser(dev, SER_RECOVER, val, 0);
74 DEFINE_DEBUGFS_ATTRIBUTE(fops_ser_trigger, NULL,
75 mt7915_ser_trigger_set, "%lld\n");
78 mt7915_radar_trigger(void *data, u64 val)
80 struct mt7915_dev *dev = data;
85 return mt76_connac_mcu_rdd_cmd(&dev->mt76, RDD_RADAR_EMULATE,
89 DEFINE_DEBUGFS_ATTRIBUTE(fops_radar_trigger, NULL,
90 mt7915_radar_trigger, "%lld\n");
93 mt7915_muru_debug_set(void *data, u64 val)
95 struct mt7915_dev *dev = data;
97 dev->muru_debug = val;
98 mt7915_mcu_muru_debug_set(dev, dev->muru_debug);
104 mt7915_muru_debug_get(void *data, u64 *val)
106 struct mt7915_dev *dev = data;
108 *val = dev->muru_debug;
113 DEFINE_DEBUGFS_ATTRIBUTE(fops_muru_debug, mt7915_muru_debug_get,
114 mt7915_muru_debug_set, "%lld\n");
116 static int mt7915_muru_stats_show(struct seq_file *file, void *data)
118 struct mt7915_phy *phy = file->private;
119 struct mt7915_dev *dev = phy->dev;
120 struct mt7915_mcu_muru_stats mu_stats = {};
121 static const char * const dl_non_he_type[] = {
122 "CCK", "OFDM", "HT MIX", "HT GF",
123 "VHT SU", "VHT 2MU", "VHT 3MU", "VHT 4MU"
125 static const char * const dl_he_type[] = {
126 "HE SU", "HE EXT", "HE 2MU", "HE 3MU", "HE 4MU",
127 "HE 2RU", "HE 3RU", "HE 4RU", "HE 5-8RU", "HE 9-16RU",
130 static const char * const ul_he_type[] = {
131 "HE 2MU", "HE 3MU", "HE 4MU", "HE SU", "HE 2RU",
132 "HE 3RU", "HE 4RU", "HE 5-8RU", "HE 9-16RU", "HE >16RU"
135 u64 total_ppdu_cnt, sub_total_cnt;
137 if (!dev->muru_debug) {
138 seq_puts(file, "Please enable muru_debug first.\n");
142 mutex_lock(&dev->mt76.mutex);
144 ret = mt7915_mcu_muru_debug_get(phy, &mu_stats);
149 seq_puts(file, "[Non-HE]\nDownlink\nData Type: ");
151 for (i = 0; i < 5; i++)
152 seq_printf(file, "%8s | ", dl_non_he_type[i]);
154 #define __dl_u32(s) le32_to_cpu(mu_stats.dl.s)
155 seq_puts(file, "\nTotal Count:");
156 seq_printf(file, "%8u | %8u | %8u | %8u | %8u | ",
161 __dl_u32(vht_su_cnt));
163 seq_puts(file, "\nDownlink MU-MIMO\nData Type: ");
165 for (i = 5; i < 8; i++)
166 seq_printf(file, "%8s | ", dl_non_he_type[i]);
168 seq_puts(file, "\nTotal Count:");
169 seq_printf(file, "%8u | %8u | %8u | ",
170 __dl_u32(vht_2mu_cnt),
171 __dl_u32(vht_3mu_cnt),
172 __dl_u32(vht_4mu_cnt));
174 sub_total_cnt = __dl_u32(vht_2mu_cnt) +
175 __dl_u32(vht_3mu_cnt) +
176 __dl_u32(vht_4mu_cnt);
178 seq_printf(file, "\nTotal non-HE MU-MIMO DL PPDU count: %lld",
181 total_ppdu_cnt = sub_total_cnt +
184 __dl_u32(htmix_cnt) +
186 __dl_u32(vht_su_cnt);
188 seq_printf(file, "\nAll non-HE DL PPDU count: %lld", total_ppdu_cnt);
191 seq_puts(file, "\n\n[HE]\nDownlink\nData Type: ");
193 for (i = 0; i < 2; i++)
194 seq_printf(file, "%8s | ", dl_he_type[i]);
196 seq_puts(file, "\nTotal Count:");
197 seq_printf(file, "%8u | %8u | ",
199 __dl_u32(he_ext_su_cnt));
201 seq_puts(file, "\nDownlink MU-MIMO\nData Type: ");
203 for (i = 2; i < 5; i++)
204 seq_printf(file, "%8s | ", dl_he_type[i]);
206 seq_puts(file, "\nTotal Count:");
207 seq_printf(file, "%8u | %8u | %8u | ",
208 __dl_u32(he_2mu_cnt),
209 __dl_u32(he_3mu_cnt),
210 __dl_u32(he_4mu_cnt));
212 seq_puts(file, "\nDownlink OFDMA\nData Type: ");
214 for (i = 5; i < 11; i++)
215 seq_printf(file, "%8s | ", dl_he_type[i]);
217 seq_puts(file, "\nTotal Count:");
218 seq_printf(file, "%8u | %8u | %8u | %8u | %9u | %8u | ",
219 __dl_u32(he_2ru_cnt),
220 __dl_u32(he_3ru_cnt),
221 __dl_u32(he_4ru_cnt),
222 __dl_u32(he_5to8ru_cnt),
223 __dl_u32(he_9to16ru_cnt),
224 __dl_u32(he_gtr16ru_cnt));
226 sub_total_cnt = __dl_u32(he_2mu_cnt) +
227 __dl_u32(he_3mu_cnt) +
228 __dl_u32(he_4mu_cnt);
229 total_ppdu_cnt = sub_total_cnt;
231 seq_printf(file, "\nTotal HE MU-MIMO DL PPDU count: %lld",
234 sub_total_cnt = __dl_u32(he_2ru_cnt) +
235 __dl_u32(he_3ru_cnt) +
236 __dl_u32(he_4ru_cnt) +
237 __dl_u32(he_5to8ru_cnt) +
238 __dl_u32(he_9to16ru_cnt) +
239 __dl_u32(he_gtr16ru_cnt);
240 total_ppdu_cnt += sub_total_cnt;
242 seq_printf(file, "\nTotal HE OFDMA DL PPDU count: %lld",
245 total_ppdu_cnt += __dl_u32(he_su_cnt) +
246 __dl_u32(he_ext_su_cnt);
248 seq_printf(file, "\nAll HE DL PPDU count: %lld", total_ppdu_cnt);
252 seq_puts(file, "\n\nUplink");
253 seq_puts(file, "\nTrigger-based Uplink MU-MIMO\nData Type: ");
255 for (i = 0; i < 3; i++)
256 seq_printf(file, "%8s | ", ul_he_type[i]);
258 #define __ul_u32(s) le32_to_cpu(mu_stats.ul.s)
259 seq_puts(file, "\nTotal Count:");
260 seq_printf(file, "%8u | %8u | %8u | ",
261 __ul_u32(hetrig_2mu_cnt),
262 __ul_u32(hetrig_3mu_cnt),
263 __ul_u32(hetrig_4mu_cnt));
265 seq_puts(file, "\nTrigger-based Uplink OFDMA\nData Type: ");
267 for (i = 3; i < 10; i++)
268 seq_printf(file, "%8s | ", ul_he_type[i]);
270 seq_puts(file, "\nTotal Count:");
271 seq_printf(file, "%8u | %8u | %8u | %8u | %8u | %9u | %7u | ",
272 __ul_u32(hetrig_su_cnt),
273 __ul_u32(hetrig_2ru_cnt),
274 __ul_u32(hetrig_3ru_cnt),
275 __ul_u32(hetrig_4ru_cnt),
276 __ul_u32(hetrig_5to8ru_cnt),
277 __ul_u32(hetrig_9to16ru_cnt),
278 __ul_u32(hetrig_gtr16ru_cnt));
280 sub_total_cnt = __ul_u32(hetrig_2mu_cnt) +
281 __ul_u32(hetrig_3mu_cnt) +
282 __ul_u32(hetrig_4mu_cnt);
283 total_ppdu_cnt = sub_total_cnt;
285 seq_printf(file, "\nTotal HE MU-MIMO UL TB PPDU count: %lld",
288 sub_total_cnt = __ul_u32(hetrig_2ru_cnt) +
289 __ul_u32(hetrig_3ru_cnt) +
290 __ul_u32(hetrig_4ru_cnt) +
291 __ul_u32(hetrig_5to8ru_cnt) +
292 __ul_u32(hetrig_9to16ru_cnt) +
293 __ul_u32(hetrig_gtr16ru_cnt);
294 total_ppdu_cnt += sub_total_cnt;
296 seq_printf(file, "\nTotal HE OFDMA UL TB PPDU count: %lld",
299 total_ppdu_cnt += __ul_u32(hetrig_su_cnt);
301 seq_printf(file, "\nAll HE UL TB PPDU count: %lld\n", total_ppdu_cnt);
305 mutex_unlock(&dev->mt76.mutex);
309 DEFINE_SHOW_ATTRIBUTE(mt7915_muru_stats);
312 mt7915_rdd_monitor(struct seq_file *s, void *data)
314 struct mt7915_dev *dev = dev_get_drvdata(s->private);
315 struct cfg80211_chan_def *chandef = &dev->rdd2_chandef;
319 mutex_lock(&dev->mt76.mutex);
321 if (!cfg80211_chandef_valid(chandef)) {
326 if (!dev->rdd2_phy) {
327 seq_puts(s, "not running\n");
331 switch (chandef->width) {
332 case NL80211_CHAN_WIDTH_40:
335 case NL80211_CHAN_WIDTH_80:
338 case NL80211_CHAN_WIDTH_160:
341 case NL80211_CHAN_WIDTH_80P80:
349 seq_printf(s, "channel %d (%d MHz) width %s MHz center1: %d MHz\n",
350 chandef->chan->hw_value, chandef->chan->center_freq,
351 bw, chandef->center_freq1);
353 mutex_unlock(&dev->mt76.mutex);
359 mt7915_fw_debug_wm_set(void *data, u64 val)
361 struct mt7915_dev *dev = data;
372 dev->fw_debug_wm = val ? MCU_FW_LOG_TO_HOST : 0;
374 if (dev->fw_debug_bin)
377 val = dev->fw_debug_wm;
379 tx = dev->fw_debug_wm || (dev->fw_debug_bin & BIT(1));
380 rx = dev->fw_debug_wm || (dev->fw_debug_bin & BIT(2));
381 en = dev->fw_debug_wm || (dev->fw_debug_bin & BIT(0));
383 ret = mt7915_mcu_fw_log_2_host(dev, MCU_FW_LOG_WM, val);
387 for (debug = DEBUG_TXCMD; debug <= DEBUG_RPT_RX; debug++) {
388 if (debug == DEBUG_RPT_RX)
393 ret = mt7915_mcu_fw_dbg_ctrl(dev, debug, val);
398 /* WM CPU info record control */
399 mt76_clear(dev, MT_CPU_UTIL_CTRL, BIT(0));
400 mt76_wr(dev, MT_DIC_CMD_REG_CMD, BIT(2) | BIT(13) | !dev->fw_debug_wm);
401 mt76_wr(dev, MT_MCU_WM_CIRQ_IRQ_MASK_CLR_ADDR, BIT(5));
402 mt76_wr(dev, MT_MCU_WM_CIRQ_IRQ_SOFT_ADDR, BIT(5));
408 mt7915_fw_debug_wm_get(void *data, u64 *val)
410 struct mt7915_dev *dev = data;
412 *val = dev->fw_debug_wm;
417 DEFINE_DEBUGFS_ATTRIBUTE(fops_fw_debug_wm, mt7915_fw_debug_wm_get,
418 mt7915_fw_debug_wm_set, "%lld\n");
421 mt7915_fw_debug_wa_set(void *data, u64 val)
423 struct mt7915_dev *dev = data;
426 dev->fw_debug_wa = val ? MCU_FW_LOG_TO_HOST : 0;
428 ret = mt7915_mcu_fw_log_2_host(dev, MCU_FW_LOG_WA, dev->fw_debug_wa);
432 return mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(SET), MCU_WA_PARAM_PDMA_RX,
433 !!dev->fw_debug_wa, 0);
437 mt7915_fw_debug_wa_get(void *data, u64 *val)
439 struct mt7915_dev *dev = data;
441 *val = dev->fw_debug_wa;
446 DEFINE_DEBUGFS_ATTRIBUTE(fops_fw_debug_wa, mt7915_fw_debug_wa_get,
447 mt7915_fw_debug_wa_set, "%lld\n");
449 static struct dentry *
450 create_buf_file_cb(const char *filename, struct dentry *parent, umode_t mode,
451 struct rchan_buf *buf, int *is_global)
455 f = debugfs_create_file("fwlog_data", mode, parent, buf,
456 &relay_file_operations);
466 remove_buf_file_cb(struct dentry *f)
474 mt7915_fw_debug_bin_set(void *data, u64 val)
476 static struct rchan_callbacks relay_cb = {
477 .create_buf_file = create_buf_file_cb,
478 .remove_buf_file = remove_buf_file_cb,
480 struct mt7915_dev *dev = data;
482 if (!dev->relay_fwlog)
483 dev->relay_fwlog = relay_open("fwlog_data", dev->debugfs_dir,
484 1500, 512, &relay_cb, NULL);
485 if (!dev->relay_fwlog)
488 dev->fw_debug_bin = val;
490 relay_reset(dev->relay_fwlog);
492 return mt7915_fw_debug_wm_set(dev, dev->fw_debug_wm);
496 mt7915_fw_debug_bin_get(void *data, u64 *val)
498 struct mt7915_dev *dev = data;
500 *val = dev->fw_debug_bin;
505 DEFINE_DEBUGFS_ATTRIBUTE(fops_fw_debug_bin, mt7915_fw_debug_bin_get,
506 mt7915_fw_debug_bin_set, "%lld\n");
509 mt7915_fw_util_wm_show(struct seq_file *file, void *data)
511 struct mt7915_dev *dev = file->private;
513 if (dev->fw_debug_wm) {
514 seq_printf(file, "Busy: %u%% Peak busy: %u%%\n",
515 mt76_rr(dev, MT_CPU_UTIL_BUSY_PCT),
516 mt76_rr(dev, MT_CPU_UTIL_PEAK_BUSY_PCT));
517 seq_printf(file, "Idle count: %u Peak idle count: %u\n",
518 mt76_rr(dev, MT_CPU_UTIL_IDLE_CNT),
519 mt76_rr(dev, MT_CPU_UTIL_PEAK_IDLE_CNT));
525 DEFINE_SHOW_ATTRIBUTE(mt7915_fw_util_wm);
528 mt7915_fw_util_wa_show(struct seq_file *file, void *data)
530 struct mt7915_dev *dev = file->private;
532 if (dev->fw_debug_wa)
533 return mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(QUERY),
534 MCU_WA_PARAM_CPU_UTIL, 0, 0);
539 DEFINE_SHOW_ATTRIBUTE(mt7915_fw_util_wa);
542 mt7915_ampdu_stat_read_phy(struct mt7915_phy *phy,
543 struct seq_file *file)
545 struct mt7915_dev *dev = phy->dev;
546 bool ext_phy = phy != &dev->phy;
547 int bound[15], range[4], i, n;
550 for (i = 0; i < ARRAY_SIZE(range); i++)
551 range[i] = mt76_rr(dev, MT_MIB_ARNG(phy->band_idx, i));
553 for (i = 0; i < ARRAY_SIZE(bound); i++)
554 bound[i] = MT_MIB_ARNCR_RANGE(range[i / 4], i % 4) + 1;
556 seq_printf(file, "\nPhy %d, Phy band %d\n", ext_phy, phy->band_idx);
558 seq_printf(file, "Length: %8d | ", bound[0]);
559 for (i = 0; i < ARRAY_SIZE(bound) - 1; i++)
560 seq_printf(file, "%3d -%3d | ",
561 bound[i] + 1, bound[i + 1]);
563 seq_puts(file, "\nCount: ");
564 n = phy->band_idx ? ARRAY_SIZE(dev->mt76.aggr_stats) / 2 : 0;
565 for (i = 0; i < ARRAY_SIZE(bound); i++)
566 seq_printf(file, "%8d | ", dev->mt76.aggr_stats[i + n]);
567 seq_puts(file, "\n");
569 seq_printf(file, "BA miss count: %d\n", phy->mib.ba_miss_cnt);
573 mt7915_txbf_stat_read_phy(struct mt7915_phy *phy, struct seq_file *s)
575 static const char * const bw[] = {
576 "BW20", "BW40", "BW80", "BW160"
578 struct mib_stats *mib = &phy->mib;
580 /* Tx Beamformer monitor */
581 seq_puts(s, "\nTx Beamformer applied PPDU counts: ");
583 seq_printf(s, "iBF: %d, eBF: %d\n",
584 mib->tx_bf_ibf_ppdu_cnt,
585 mib->tx_bf_ebf_ppdu_cnt);
587 /* Tx Beamformer Rx feedback monitor */
588 seq_puts(s, "Tx Beamformer Rx feedback statistics: ");
590 seq_printf(s, "All: %d, HE: %d, VHT: %d, HT: %d, ",
591 mib->tx_bf_rx_fb_all_cnt,
592 mib->tx_bf_rx_fb_he_cnt,
593 mib->tx_bf_rx_fb_vht_cnt,
594 mib->tx_bf_rx_fb_ht_cnt);
596 seq_printf(s, "%s, NC: %d, NR: %d\n",
597 bw[mib->tx_bf_rx_fb_bw],
598 mib->tx_bf_rx_fb_nc_cnt,
599 mib->tx_bf_rx_fb_nr_cnt);
601 /* Tx Beamformee Rx NDPA & Tx feedback report */
602 seq_printf(s, "Tx Beamformee successful feedback frames: %d\n",
603 mib->tx_bf_fb_cpl_cnt);
604 seq_printf(s, "Tx Beamformee feedback triggered counts: %d\n",
605 mib->tx_bf_fb_trig_cnt);
607 /* Tx SU & MU counters */
608 seq_printf(s, "Tx multi-user Beamforming counts: %d\n",
610 seq_printf(s, "Tx multi-user MPDU counts: %d\n", mib->tx_mu_mpdu_cnt);
611 seq_printf(s, "Tx multi-user successful MPDU counts: %d\n",
612 mib->tx_mu_acked_mpdu_cnt);
613 seq_printf(s, "Tx single-user successful MPDU counts: %d\n",
614 mib->tx_su_acked_mpdu_cnt);
620 mt7915_tx_stats_show(struct seq_file *file, void *data)
622 struct mt7915_phy *phy = file->private;
623 struct mt7915_dev *dev = phy->dev;
624 struct mib_stats *mib = &phy->mib;
627 mutex_lock(&dev->mt76.mutex);
629 mt7915_ampdu_stat_read_phy(phy, file);
630 mt7915_mac_update_stats(phy);
631 mt7915_txbf_stat_read_phy(phy, file);
634 seq_puts(file, "Tx MSDU statistics:\n");
635 for (i = 0; i < ARRAY_SIZE(mib->tx_amsdu); i++) {
636 seq_printf(file, "AMSDU pack count of %d MSDU in TXD: %8d ",
637 i + 1, mib->tx_amsdu[i]);
638 if (mib->tx_amsdu_cnt)
639 seq_printf(file, "(%3d%%)\n",
640 mib->tx_amsdu[i] * 100 / mib->tx_amsdu_cnt);
642 seq_puts(file, "\n");
645 mutex_unlock(&dev->mt76.mutex);
650 DEFINE_SHOW_ATTRIBUTE(mt7915_tx_stats);
653 mt7915_hw_queue_read(struct seq_file *s, u32 size,
654 const struct hw_queue_map *map)
656 struct mt7915_phy *phy = s->private;
657 struct mt7915_dev *dev = phy->dev;
660 val = mt76_rr(dev, MT_FL_Q_EMPTY);
661 for (i = 0; i < size; i++) {
662 u32 ctrl, head, tail, queued;
664 if (val & BIT(map[i].index))
667 ctrl = BIT(31) | (map[i].pid << 10) | (map[i].qid << 24);
668 mt76_wr(dev, MT_FL_Q0_CTRL, ctrl);
670 head = mt76_get_field(dev, MT_FL_Q2_CTRL,
672 tail = mt76_get_field(dev, MT_FL_Q2_CTRL,
674 queued = mt76_get_field(dev, MT_FL_Q3_CTRL,
677 seq_printf(s, "\t%s: ", map[i].name);
678 seq_printf(s, "queued:0x%03x head:0x%03x tail:0x%03x\n",
684 mt7915_sta_hw_queue_read(void *data, struct ieee80211_sta *sta)
686 struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
687 struct mt7915_dev *dev = msta->vif->phy->dev;
688 struct seq_file *s = data;
691 for (ac = 0; ac < 4; ac++) {
693 u32 idx = msta->wcid.idx >> 5;
694 u8 offs = msta->wcid.idx & GENMASK(4, 0);
696 ctrl = BIT(31) | BIT(11) | (ac << 24);
697 val = mt76_rr(dev, MT_PLE_AC_QEMPTY(ac, idx));
702 mt76_wr(dev, MT_FL_Q0_CTRL, ctrl | msta->wcid.idx);
703 qlen = mt76_get_field(dev, MT_FL_Q3_CTRL,
705 seq_printf(s, "\tSTA %pM wcid %d: AC%d%d queued:%d\n",
706 sta->addr, msta->wcid.idx,
707 msta->vif->mt76.wmm_idx, ac, qlen);
712 mt7915_hw_queues_show(struct seq_file *file, void *data)
714 struct mt7915_phy *phy = file->private;
715 struct mt7915_dev *dev = phy->dev;
716 static const struct hw_queue_map ple_queue_map[] = {
717 { "CPU_Q0", 0, 1, MT_CTX0 },
718 { "CPU_Q1", 1, 1, MT_CTX0 + 1 },
719 { "CPU_Q2", 2, 1, MT_CTX0 + 2 },
720 { "CPU_Q3", 3, 1, MT_CTX0 + 3 },
721 { "ALTX_Q0", 8, 2, MT_LMAC_ALTX0 },
722 { "BMC_Q0", 9, 2, MT_LMAC_BMC0 },
723 { "BCN_Q0", 10, 2, MT_LMAC_BCN0 },
724 { "PSMP_Q0", 11, 2, MT_LMAC_PSMP0 },
725 { "ALTX_Q1", 12, 2, MT_LMAC_ALTX0 + 4 },
726 { "BMC_Q1", 13, 2, MT_LMAC_BMC0 + 4 },
727 { "BCN_Q1", 14, 2, MT_LMAC_BCN0 + 4 },
728 { "PSMP_Q1", 15, 2, MT_LMAC_PSMP0 + 4 },
730 static const struct hw_queue_map pse_queue_map[] = {
731 { "CPU Q0", 0, 1, MT_CTX0 },
732 { "CPU Q1", 1, 1, MT_CTX0 + 1 },
733 { "CPU Q2", 2, 1, MT_CTX0 + 2 },
734 { "CPU Q3", 3, 1, MT_CTX0 + 3 },
735 { "HIF_Q0", 8, 0, MT_HIF0 },
736 { "HIF_Q1", 9, 0, MT_HIF0 + 1 },
737 { "HIF_Q2", 10, 0, MT_HIF0 + 2 },
738 { "HIF_Q3", 11, 0, MT_HIF0 + 3 },
739 { "HIF_Q4", 12, 0, MT_HIF0 + 4 },
740 { "HIF_Q5", 13, 0, MT_HIF0 + 5 },
741 { "LMAC_Q", 16, 2, 0 },
742 { "MDP_TXQ", 17, 2, 1 },
743 { "MDP_RXQ", 18, 2, 2 },
744 { "SEC_TXQ", 19, 2, 3 },
745 { "SEC_RXQ", 20, 2, 4 },
750 val = mt76_rr(dev, MT_PLE_FREEPG_CNT);
751 head = mt76_get_field(dev, MT_PLE_FREEPG_HEAD_TAIL, GENMASK(11, 0));
752 tail = mt76_get_field(dev, MT_PLE_FREEPG_HEAD_TAIL, GENMASK(27, 16));
753 seq_puts(file, "PLE page info:\n");
755 "\tTotal free page: 0x%08x head: 0x%03x tail: 0x%03x\n",
758 val = mt76_rr(dev, MT_PLE_PG_HIF_GROUP);
759 head = mt76_get_field(dev, MT_PLE_HIF_PG_INFO, GENMASK(11, 0));
760 tail = mt76_get_field(dev, MT_PLE_HIF_PG_INFO, GENMASK(27, 16));
761 seq_printf(file, "\tHIF free page: 0x%03x res: 0x%03x used: 0x%03x\n",
764 seq_puts(file, "PLE non-empty queue info:\n");
765 mt7915_hw_queue_read(file, ARRAY_SIZE(ple_queue_map),
768 /* iterate per-sta ple queue */
769 ieee80211_iterate_stations_atomic(phy->mt76->hw,
770 mt7915_sta_hw_queue_read, file);
772 seq_puts(file, "PSE non-empty queue info:\n");
773 mt7915_hw_queue_read(file, ARRAY_SIZE(pse_queue_map),
779 DEFINE_SHOW_ATTRIBUTE(mt7915_hw_queues);
782 mt7915_xmit_queues_show(struct seq_file *file, void *data)
784 struct mt7915_phy *phy = file->private;
785 struct mt7915_dev *dev = phy->dev;
787 struct mt76_queue *q;
790 { phy->mt76->q_tx[MT_TXQ_BE], " MAIN" },
791 { dev->mt76.q_mcu[MT_MCUQ_WM], " MCUWM" },
792 { dev->mt76.q_mcu[MT_MCUQ_WA], " MCUWA" },
793 { dev->mt76.q_mcu[MT_MCUQ_FWDL], "MCUFWDL" },
797 seq_puts(file, " queue | hw-queued | head | tail |\n");
798 for (i = 0; i < ARRAY_SIZE(queue_map); i++) {
799 struct mt76_queue *q = queue_map[i].q;
804 seq_printf(file, " %s | %9d | %9d | %9d |\n",
805 queue_map[i].queue, q->queued, q->head,
812 DEFINE_SHOW_ATTRIBUTE(mt7915_xmit_queues);
815 mt7915_rate_txpower_show(struct seq_file *file, void *data)
817 static const char * const sku_group_name[] = {
818 "CCK", "OFDM", "HT20", "HT40",
819 "VHT20", "VHT40", "VHT80", "VHT160",
820 "RU26", "RU52", "RU106", "RU242/SU20",
821 "RU484/SU40", "RU996/SU80", "RU2x996/SU160"
823 struct mt7915_phy *phy = file->private;
824 s8 txpower[MT7915_SKU_RATE_NUM], *buf;
827 seq_printf(file, "\nBand %d\n", phy != &phy->dev->phy);
828 mt7915_mcu_get_txpower_sku(phy, txpower, sizeof(txpower));
829 for (i = 0, buf = txpower; i < ARRAY_SIZE(mt7915_sku_group_len); i++) {
830 u8 mcs_num = mt7915_sku_group_len[i];
832 if (i >= SKU_VHT_BW20 && i <= SKU_VHT_BW160)
835 mt76_seq_puts_array(file, sku_group_name[i], buf, mcs_num);
836 buf += mt7915_sku_group_len[i];
842 DEFINE_SHOW_ATTRIBUTE(mt7915_rate_txpower);
845 mt7915_twt_stats(struct seq_file *s, void *data)
847 struct mt7915_dev *dev = dev_get_drvdata(s->private);
848 struct mt7915_twt_flow *iter;
852 seq_puts(s, " wcid | id | flags | exp | mantissa");
853 seq_puts(s, " | duration | tsf |\n");
854 list_for_each_entry_rcu(iter, &dev->twt_list, list)
856 "%9d | %8d | %5c%c%c%c | %8d | %8d | %8d | %14lld |\n",
857 iter->wcid, iter->id,
858 iter->sched ? 's' : 'u',
859 iter->protection ? 'p' : '-',
860 iter->trigger ? 't' : '-',
861 iter->flowtype ? '-' : 'a',
862 iter->exp, iter->mantissa,
863 iter->duration, iter->tsf);
870 int mt7915_init_debugfs(struct mt7915_phy *phy)
872 struct mt7915_dev *dev = phy->dev;
873 bool ext_phy = phy != &dev->phy;
876 dir = mt76_register_debugfs_fops(phy->mt76, NULL);
879 debugfs_create_file("muru_debug", 0600, dir, dev, &fops_muru_debug);
880 debugfs_create_file("muru_stats", 0400, dir, phy,
881 &mt7915_muru_stats_fops);
882 debugfs_create_file("hw-queues", 0400, dir, phy,
883 &mt7915_hw_queues_fops);
884 debugfs_create_file("xmit-queues", 0400, dir, phy,
885 &mt7915_xmit_queues_fops);
886 debugfs_create_file("tx_stats", 0400, dir, phy, &mt7915_tx_stats_fops);
887 debugfs_create_file("fw_debug_wm", 0600, dir, dev, &fops_fw_debug_wm);
888 debugfs_create_file("fw_debug_wa", 0600, dir, dev, &fops_fw_debug_wa);
889 debugfs_create_file("fw_debug_bin", 0600, dir, dev, &fops_fw_debug_bin);
890 debugfs_create_file("fw_util_wm", 0400, dir, dev,
891 &mt7915_fw_util_wm_fops);
892 debugfs_create_file("fw_util_wa", 0400, dir, dev,
893 &mt7915_fw_util_wa_fops);
894 debugfs_create_file("implicit_txbf", 0600, dir, dev,
895 &fops_implicit_txbf);
896 debugfs_create_file("txpower_sku", 0400, dir, phy,
897 &mt7915_rate_txpower_fops);
898 debugfs_create_devm_seqfile(dev->mt76.dev, "twt_stats", dir,
900 debugfs_create_file("ser_trigger", 0200, dir, dev, &fops_ser_trigger);
901 if (!dev->dbdc_support || phy->band_idx) {
902 debugfs_create_u32("dfs_hw_pattern", 0400, dir,
904 debugfs_create_file("radar_trigger", 0200, dir, dev,
905 &fops_radar_trigger);
906 debugfs_create_devm_seqfile(dev->mt76.dev, "rdd_monitor", dir,
911 dev->debugfs_dir = dir;
917 mt7915_debugfs_write_fwlog(struct mt7915_dev *dev, const void *hdr, int hdrlen,
918 const void *data, int len)
920 static DEFINE_SPINLOCK(lock);
924 spin_lock_irqsave(&lock, flags);
925 dest = relay_reserve(dev->relay_fwlog, hdrlen + len + 4);
927 *(u32 *)dest = hdrlen + len;
931 memcpy(dest, hdr, hdrlen);
935 memcpy(dest, data, len);
936 relay_flush(dev->relay_fwlog);
938 spin_unlock_irqrestore(&lock, flags);
941 void mt7915_debugfs_rx_fw_monitor(struct mt7915_dev *dev, const void *data, int len)
949 .magic = cpu_to_le32(FW_BIN_LOG_MAGIC),
950 .msg_type = cpu_to_le16(PKT_TYPE_RX_FW_MONITOR),
953 if (!dev->relay_fwlog)
956 hdr.timestamp = cpu_to_le32(mt76_rr(dev, MT_LPON_FRCR(0)));
957 hdr.len = *(__le16 *)data;
958 mt7915_debugfs_write_fwlog(dev, &hdr, sizeof(hdr), data, len);
961 bool mt7915_debugfs_rx_log(struct mt7915_dev *dev, const void *data, int len)
963 if (get_unaligned_le32(data) != FW_BIN_LOG_MAGIC)
966 if (dev->relay_fwlog)
967 mt7915_debugfs_write_fwlog(dev, NULL, 0, data, len);
972 #ifdef CONFIG_MAC80211_DEBUGFS
973 /** per-station debugfs **/
975 static ssize_t mt7915_sta_fixed_rate_set(struct file *file,
976 const char __user *user_buf,
977 size_t count, loff_t *ppos)
979 struct ieee80211_sta *sta = file->private_data;
980 struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
981 struct mt7915_dev *dev = msta->vif->phy->dev;
982 struct ieee80211_vif *vif;
983 struct sta_phy phy = {};
989 if (count >= sizeof(buf))
992 if (copy_from_user(buf, user_buf, count))
995 if (count && buf[count - 1] == '\n')
996 buf[count - 1] = '\0';
1000 /* mode - cck: 0, ofdm: 1, ht: 2, gf: 3, vht: 4, he_su: 8, he_er: 9
1001 * bw - bw20: 0, bw40: 1, bw80: 2, bw160: 3
1002 * nss - vht: 1~4, he: 1~4, others: ignore
1003 * mcs - cck: 0~4, ofdm: 0~7, ht: 0~32, vht: 0~9, he_su: 0~11, he_er: 0~2
1004 * gi - (ht/vht) lgi: 0, sgi: 1; (he) 0.8us: 0, 1.6us: 1, 3.2us: 2
1005 * ldpc - off: 0, on: 1
1006 * stbc - off: 0, on: 1
1007 * he_ltf - 1xltf: 0, 2xltf: 1, 4xltf: 2
1009 if (sscanf(buf, "%hhu %hhu %hhu %hhu %hhu %hhu %hhu %hhu",
1010 &phy.type, &phy.bw, &phy.nss, &phy.mcs, &gi,
1011 &phy.ldpc, &phy.stbc, &he_ltf) != 8) {
1012 dev_warn(dev->mt76.dev,
1013 "format: Mode BW NSS MCS (HE)GI LDPC STBC HE_LTF\n");
1014 field = RATE_PARAM_AUTO;
1018 phy.ldpc = (phy.bw || phy.ldpc) * GENMASK(2, 0);
1019 for (i = 0; i <= phy.bw; i++) {
1020 phy.sgi |= gi << (i << sta->he_cap.has_he);
1021 phy.he_ltf |= he_ltf << (i << sta->he_cap.has_he);
1023 field = RATE_PARAM_FIXED;
1026 vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);
1027 ret = mt7915_mcu_set_fixed_rate_ctrl(dev, vif, sta, &phy, field);
1034 static const struct file_operations fops_fixed_rate = {
1035 .write = mt7915_sta_fixed_rate_set,
1036 .open = simple_open,
1037 .owner = THIS_MODULE,
1038 .llseek = default_llseek,
1042 mt7915_queues_show(struct seq_file *s, void *data)
1044 struct ieee80211_sta *sta = s->private;
1046 mt7915_sta_hw_queue_read(s, sta);
1051 DEFINE_SHOW_ATTRIBUTE(mt7915_queues);
1053 void mt7915_sta_add_debugfs(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1054 struct ieee80211_sta *sta, struct dentry *dir)
1056 debugfs_create_file("fixed_rate", 0600, dir, sta, &fops_fixed_rate);
1057 debugfs_create_file("hw-queues", 0400, dir, sta, &mt7915_queues_fops);