1 // SPDX-License-Identifier: ISC 2 /* Copyright (C) 2020 MediaTek Inc. */ 3 4 #include "mt7915.h" 5 #include "eeprom.h" 6 #include "mcu.h" 7 8 /** global debugfs **/ 9 10 static int 11 mt7915_implicit_txbf_set(void *data, u64 val) 12 { 13 struct mt7915_dev *dev = data; 14 15 if (test_bit(MT76_STATE_RUNNING, &dev->mphy.state)) 16 return -EBUSY; 17 18 dev->ibf = !!val; 19 20 return mt7915_mcu_set_txbf(dev, MT_BF_TYPE_UPDATE); 21 } 22 23 static int 24 mt7915_implicit_txbf_get(void *data, u64 *val) 25 { 26 struct mt7915_dev *dev = data; 27 28 *val = dev->ibf; 29 30 return 0; 31 } 32 33 DEFINE_DEBUGFS_ATTRIBUTE(fops_implicit_txbf, mt7915_implicit_txbf_get, 34 mt7915_implicit_txbf_set, "%lld\n"); 35 36 /* test knob of system layer 1/2 error recovery */ 37 static int mt7915_ser_trigger_set(void *data, u64 val) 38 { 39 enum { 40 SER_SET_RECOVER_L1 = 1, 41 SER_SET_RECOVER_L2, 42 SER_ENABLE = 2, 43 SER_RECOVER 44 }; 45 struct mt7915_dev *dev = data; 46 int ret = 0; 47 48 switch (val) { 49 case SER_SET_RECOVER_L1: 50 case SER_SET_RECOVER_L2: 51 ret = mt7915_mcu_set_ser(dev, SER_ENABLE, BIT(val), 0); 52 if (ret) 53 return ret; 54 55 return mt7915_mcu_set_ser(dev, SER_RECOVER, val, 0); 56 default: 57 break; 58 } 59 60 return ret; 61 } 62 63 DEFINE_DEBUGFS_ATTRIBUTE(fops_ser_trigger, NULL, 64 mt7915_ser_trigger_set, "%lld\n"); 65 66 static int 67 mt7915_radar_trigger(void *data, u64 val) 68 { 69 struct mt7915_dev *dev = data; 70 71 return mt7915_mcu_rdd_cmd(dev, RDD_RADAR_EMULATE, 1, 0, 0); 72 } 73 74 DEFINE_DEBUGFS_ATTRIBUTE(fops_radar_trigger, NULL, 75 mt7915_radar_trigger, "%lld\n"); 76 77 static int 78 mt7915_fw_debug_set(void *data, u64 val) 79 { 80 struct mt7915_dev *dev = data; 81 enum { 82 DEBUG_TXCMD = 62, 83 DEBUG_CMD_RPT_TX, 84 DEBUG_CMD_RPT_TRIG, 85 DEBUG_SPL, 86 DEBUG_RPT_RX, 87 } debug; 88 89 dev->fw_debug = !!val; 90 91 mt7915_mcu_fw_log_2_host(dev, dev->fw_debug ? 2 : 0); 92 93 for (debug = DEBUG_TXCMD; debug <= DEBUG_RPT_RX; debug++) 94 mt7915_mcu_fw_dbg_ctrl(dev, debug, dev->fw_debug); 95 96 return 0; 97 } 98 99 static int 100 mt7915_fw_debug_get(void *data, u64 *val) 101 { 102 struct mt7915_dev *dev = data; 103 104 *val = dev->fw_debug; 105 106 return 0; 107 } 108 109 DEFINE_DEBUGFS_ATTRIBUTE(fops_fw_debug, mt7915_fw_debug_get, 110 mt7915_fw_debug_set, "%lld\n"); 111 112 static void 113 mt7915_ampdu_stat_read_phy(struct mt7915_phy *phy, 114 struct seq_file *file) 115 { 116 struct mt7915_dev *dev = file->private; 117 bool ext_phy = phy != &dev->phy; 118 int bound[15], range[4], i, n; 119 120 if (!phy) 121 return; 122 123 /* Tx ampdu stat */ 124 for (i = 0; i < ARRAY_SIZE(range); i++) 125 range[i] = mt76_rr(dev, MT_MIB_ARNG(ext_phy, i)); 126 127 for (i = 0; i < ARRAY_SIZE(bound); i++) 128 bound[i] = MT_MIB_ARNCR_RANGE(range[i / 4], i % 4) + 1; 129 130 seq_printf(file, "\nPhy %d\n", ext_phy); 131 132 seq_printf(file, "Length: %8d | ", bound[0]); 133 for (i = 0; i < ARRAY_SIZE(bound) - 1; i++) 134 seq_printf(file, "%3d -%3d | ", 135 bound[i] + 1, bound[i + 1]); 136 137 seq_puts(file, "\nCount: "); 138 n = ext_phy ? ARRAY_SIZE(dev->mt76.aggr_stats) / 2 : 0; 139 for (i = 0; i < ARRAY_SIZE(bound); i++) 140 seq_printf(file, "%8d | ", dev->mt76.aggr_stats[i + n]); 141 seq_puts(file, "\n"); 142 143 seq_printf(file, "BA miss count: %d\n", phy->mib.ba_miss_cnt); 144 } 145 146 static void 147 mt7915_txbf_stat_read_phy(struct mt7915_phy *phy, struct seq_file *s) 148 { 149 struct mt7915_dev *dev = s->private; 150 bool ext_phy = phy != &dev->phy; 151 static const char * const bw[] = { 152 "BW20", "BW40", "BW80", "BW160" 153 }; 154 int cnt; 155 156 if (!phy) 157 return; 158 159 /* Tx Beamformer monitor */ 160 seq_puts(s, "\nTx Beamformer applied PPDU counts: "); 161 162 cnt = mt76_rr(dev, MT_ETBF_TX_APP_CNT(ext_phy)); 163 seq_printf(s, "iBF: %ld, eBF: %ld\n", 164 FIELD_GET(MT_ETBF_TX_IBF_CNT, cnt), 165 FIELD_GET(MT_ETBF_TX_EBF_CNT, cnt)); 166 167 /* Tx Beamformer Rx feedback monitor */ 168 seq_puts(s, "Tx Beamformer Rx feedback statistics: "); 169 170 cnt = mt76_rr(dev, MT_ETBF_RX_FB_CNT(ext_phy)); 171 seq_printf(s, "All: %ld, HE: %ld, VHT: %ld, HT: %ld, ", 172 FIELD_GET(MT_ETBF_RX_FB_ALL, cnt), 173 FIELD_GET(MT_ETBF_RX_FB_HE, cnt), 174 FIELD_GET(MT_ETBF_RX_FB_VHT, cnt), 175 FIELD_GET(MT_ETBF_RX_FB_HT, cnt)); 176 cnt = mt76_rr(dev, MT_ETBF_RX_FB_CONT(ext_phy)); 177 seq_printf(s, "%s, NC: %ld, NR: %ld\n", 178 bw[FIELD_GET(MT_ETBF_RX_FB_BW, cnt)], 179 FIELD_GET(MT_ETBF_RX_FB_NC, cnt), 180 FIELD_GET(MT_ETBF_RX_FB_NR, cnt)); 181 182 /* Tx Beamformee Rx NDPA & Tx feedback report */ 183 cnt = mt76_rr(dev, MT_ETBF_TX_NDP_BFRP(ext_phy)); 184 seq_printf(s, "Tx Beamformee successful feedback frames: %ld\n", 185 FIELD_GET(MT_ETBF_TX_FB_CPL, cnt)); 186 seq_printf(s, "Tx Beamformee feedback triggered counts: %ld\n", 187 FIELD_GET(MT_ETBF_TX_FB_TRI, cnt)); 188 189 /* Tx SU & MU counters */ 190 cnt = mt76_rr(dev, MT_MIB_SDR34(ext_phy)); 191 seq_printf(s, "Tx multi-user Beamforming counts: %ld\n", 192 FIELD_GET(MT_MIB_MU_BF_TX_CNT, cnt)); 193 cnt = mt76_rr(dev, MT_MIB_DR8(ext_phy)); 194 seq_printf(s, "Tx multi-user MPDU counts: %d\n", cnt); 195 cnt = mt76_rr(dev, MT_MIB_DR9(ext_phy)); 196 seq_printf(s, "Tx multi-user successful MPDU counts: %d\n", cnt); 197 cnt = mt76_rr(dev, MT_MIB_DR11(ext_phy)); 198 seq_printf(s, "Tx single-user successful MPDU counts: %d\n", cnt); 199 200 seq_puts(s, "\n"); 201 } 202 203 static int 204 mt7915_tx_stats_show(struct seq_file *file, void *data) 205 { 206 struct mt7915_dev *dev = file->private; 207 int stat[8], i, n; 208 209 mt7915_ampdu_stat_read_phy(&dev->phy, file); 210 mt7915_txbf_stat_read_phy(&dev->phy, file); 211 212 mt7915_ampdu_stat_read_phy(mt7915_ext_phy(dev), file); 213 mt7915_txbf_stat_read_phy(mt7915_ext_phy(dev), file); 214 215 /* Tx amsdu info */ 216 seq_puts(file, "Tx MSDU statistics:\n"); 217 for (i = 0, n = 0; i < ARRAY_SIZE(stat); i++) { 218 stat[i] = mt76_rr(dev, MT_PLE_AMSDU_PACK_MSDU_CNT(i)); 219 n += stat[i]; 220 } 221 222 for (i = 0; i < ARRAY_SIZE(stat); i++) { 223 seq_printf(file, "AMSDU pack count of %d MSDU in TXD: 0x%x ", 224 i + 1, stat[i]); 225 if (n != 0) 226 seq_printf(file, "(%d%%)\n", stat[i] * 100 / n); 227 else 228 seq_puts(file, "\n"); 229 } 230 231 return 0; 232 } 233 234 DEFINE_SHOW_ATTRIBUTE(mt7915_tx_stats); 235 236 static int 237 mt7915_queues_acq(struct seq_file *s, void *data) 238 { 239 struct mt7915_dev *dev = dev_get_drvdata(s->private); 240 int i; 241 242 for (i = 0; i < 16; i++) { 243 int j, acs = i / 4, index = i % 4; 244 u32 ctrl, val, qlen = 0; 245 246 val = mt76_rr(dev, MT_PLE_AC_QEMPTY(acs, index)); 247 ctrl = BIT(31) | BIT(15) | (acs << 8); 248 249 for (j = 0; j < 32; j++) { 250 if (val & BIT(j)) 251 continue; 252 253 mt76_wr(dev, MT_PLE_FL_Q0_CTRL, 254 ctrl | (j + (index << 5))); 255 qlen += mt76_get_field(dev, MT_PLE_FL_Q3_CTRL, 256 GENMASK(11, 0)); 257 } 258 seq_printf(s, "AC%d%d: queued=%d\n", acs, index, qlen); 259 } 260 261 return 0; 262 } 263 264 static int 265 mt7915_queues_read(struct seq_file *s, void *data) 266 { 267 struct mt7915_dev *dev = dev_get_drvdata(s->private); 268 struct mt76_phy *mphy_ext = dev->mt76.phy2; 269 struct mt76_queue *ext_q = mphy_ext ? mphy_ext->q_tx[MT_TXQ_BE] : NULL; 270 struct { 271 struct mt76_queue *q; 272 char *queue; 273 } queue_map[] = { 274 { dev->mphy.q_tx[MT_TXQ_BE], "WFDMA0" }, 275 { ext_q, "WFDMA1" }, 276 { dev->mphy.q_tx[MT_TXQ_BE], "WFDMA0" }, 277 { dev->mt76.q_mcu[MT_MCUQ_WM], "MCUWM" }, 278 { dev->mt76.q_mcu[MT_MCUQ_WA], "MCUWA" }, 279 { dev->mt76.q_mcu[MT_MCUQ_FWDL], "MCUFWQ" }, 280 }; 281 int i; 282 283 for (i = 0; i < ARRAY_SIZE(queue_map); i++) { 284 struct mt76_queue *q = queue_map[i].q; 285 286 if (!q) 287 continue; 288 289 seq_printf(s, 290 "%s: queued=%d head=%d tail=%d\n", 291 queue_map[i].queue, q->queued, q->head, 292 q->tail); 293 } 294 295 return 0; 296 } 297 298 static void 299 mt7915_puts_rate_txpower(struct seq_file *s, struct mt7915_phy *phy) 300 { 301 static const char * const sku_group_name[] = { 302 "CCK", "OFDM", "HT20", "HT40", 303 "VHT20", "VHT40", "VHT80", "VHT160", 304 "RU26", "RU52", "RU106", "RU242/SU20", 305 "RU484/SU40", "RU996/SU80", "RU2x996/SU160" 306 }; 307 s8 txpower[MT7915_SKU_RATE_NUM], *buf; 308 int i; 309 310 if (!phy) 311 return; 312 313 seq_printf(s, "\nBand %d\n", phy != &phy->dev->phy); 314 315 mt7915_mcu_get_txpower_sku(phy, txpower, sizeof(txpower)); 316 for (i = 0, buf = txpower; i < ARRAY_SIZE(mt7915_sku_group_len); i++) { 317 u8 mcs_num = mt7915_sku_group_len[i]; 318 319 if (i >= SKU_VHT_BW20 && i <= SKU_VHT_BW160) 320 mcs_num = 10; 321 322 mt76_seq_puts_array(s, sku_group_name[i], buf, mcs_num); 323 buf += mt7915_sku_group_len[i]; 324 } 325 } 326 327 static int 328 mt7915_read_rate_txpower(struct seq_file *s, void *data) 329 { 330 struct mt7915_dev *dev = dev_get_drvdata(s->private); 331 332 mt7915_puts_rate_txpower(s, &dev->phy); 333 mt7915_puts_rate_txpower(s, mt7915_ext_phy(dev)); 334 335 return 0; 336 } 337 338 int mt7915_init_debugfs(struct mt7915_dev *dev) 339 { 340 struct dentry *dir; 341 342 dir = mt76_register_debugfs(&dev->mt76); 343 if (!dir) 344 return -ENOMEM; 345 346 debugfs_create_devm_seqfile(dev->mt76.dev, "queues", dir, 347 mt7915_queues_read); 348 debugfs_create_devm_seqfile(dev->mt76.dev, "acq", dir, 349 mt7915_queues_acq); 350 debugfs_create_file("tx_stats", 0400, dir, dev, &mt7915_tx_stats_fops); 351 debugfs_create_file("fw_debug", 0600, dir, dev, &fops_fw_debug); 352 debugfs_create_file("implicit_txbf", 0600, dir, dev, 353 &fops_implicit_txbf); 354 debugfs_create_u32("dfs_hw_pattern", 0400, dir, &dev->hw_pattern); 355 /* test knobs */ 356 debugfs_create_file("radar_trigger", 0200, dir, dev, 357 &fops_radar_trigger); 358 debugfs_create_file("ser_trigger", 0200, dir, dev, &fops_ser_trigger); 359 debugfs_create_devm_seqfile(dev->mt76.dev, "txpower_sku", dir, 360 mt7915_read_rate_txpower); 361 362 return 0; 363 } 364 365 #ifdef CONFIG_MAC80211_DEBUGFS 366 /** per-station debugfs **/ 367 368 /* usage: <tx mode> <ldpc> <stbc> <bw> <gi> <nss> <mcs> */ 369 static int mt7915_sta_fixed_rate_set(void *data, u64 rate) 370 { 371 struct ieee80211_sta *sta = data; 372 struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv; 373 374 return mt7915_mcu_set_fixed_rate(msta->vif->phy->dev, sta, rate); 375 } 376 377 DEFINE_DEBUGFS_ATTRIBUTE(fops_fixed_rate, NULL, 378 mt7915_sta_fixed_rate_set, "%llx\n"); 379 380 static int 381 mt7915_sta_stats_show(struct seq_file *s, void *data) 382 { 383 struct ieee80211_sta *sta = s->private; 384 struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv; 385 struct mt7915_sta_stats *stats = &msta->stats; 386 struct rate_info *rate = &stats->prob_rate; 387 static const char * const bw[] = { 388 "BW20", "BW5", "BW10", "BW40", 389 "BW80", "BW160", "BW_HE_RU" 390 }; 391 392 if (!rate->legacy && !rate->flags) 393 return 0; 394 395 seq_puts(s, "Probing rate - "); 396 if (rate->flags & RATE_INFO_FLAGS_MCS) 397 seq_puts(s, "HT "); 398 else if (rate->flags & RATE_INFO_FLAGS_VHT_MCS) 399 seq_puts(s, "VHT "); 400 else if (rate->flags & RATE_INFO_FLAGS_HE_MCS) 401 seq_puts(s, "HE "); 402 else 403 seq_printf(s, "Bitrate %d\n", rate->legacy); 404 405 if (rate->flags) { 406 seq_printf(s, "%s NSS%d MCS%d ", 407 bw[rate->bw], rate->nss, rate->mcs); 408 409 if (rate->flags & RATE_INFO_FLAGS_SHORT_GI) 410 seq_puts(s, "SGI "); 411 else if (rate->he_gi) 412 seq_puts(s, "HE GI "); 413 414 if (rate->he_dcm) 415 seq_puts(s, "DCM "); 416 } 417 418 seq_printf(s, "\nPPDU PER: %ld.%1ld%%\n", 419 stats->per / 10, stats->per % 10); 420 421 return 0; 422 } 423 424 DEFINE_SHOW_ATTRIBUTE(mt7915_sta_stats); 425 426 void mt7915_sta_add_debugfs(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 427 struct ieee80211_sta *sta, struct dentry *dir) 428 { 429 debugfs_create_file("fixed_rate", 0600, dir, sta, &fops_fixed_rate); 430 debugfs_create_file("stats", 0400, dir, sta, &mt7915_sta_stats_fops); 431 } 432 #endif 433