1 // SPDX-License-Identifier: ISC 2 3 #include "mt7615.h" 4 5 static int 6 mt7615_radar_pattern_set(void *data, u64 val) 7 { 8 struct mt7615_dev *dev = data; 9 int err; 10 11 if (!mt7615_wait_for_mcu_init(dev)) 12 return 0; 13 14 mt7615_mutex_acquire(dev); 15 err = mt7615_mcu_rdd_send_pattern(dev); 16 mt7615_mutex_release(dev); 17 18 return err; 19 } 20 21 DEFINE_DEBUGFS_ATTRIBUTE(fops_radar_pattern, NULL, 22 mt7615_radar_pattern_set, "%lld\n"); 23 24 static int 25 mt7615_scs_set(void *data, u64 val) 26 { 27 struct mt7615_dev *dev = data; 28 struct mt7615_phy *ext_phy; 29 30 if (!mt7615_wait_for_mcu_init(dev)) 31 return 0; 32 33 mt7615_mac_set_scs(&dev->phy, val); 34 ext_phy = mt7615_ext_phy(dev); 35 if (ext_phy) 36 mt7615_mac_set_scs(ext_phy, val); 37 38 return 0; 39 } 40 41 static int 42 mt7615_scs_get(void *data, u64 *val) 43 { 44 struct mt7615_dev *dev = data; 45 46 *val = dev->phy.scs_en; 47 48 return 0; 49 } 50 51 DEFINE_DEBUGFS_ATTRIBUTE(fops_scs, mt7615_scs_get, 52 mt7615_scs_set, "%lld\n"); 53 54 static int 55 mt7615_pm_set(void *data, u64 val) 56 { 57 struct mt7615_dev *dev = data; 58 int ret = 0; 59 60 if (!mt7615_wait_for_mcu_init(dev)) 61 return 0; 62 63 if (!mt7615_firmware_offload(dev) || !mt76_is_mmio(&dev->mt76)) 64 return -EOPNOTSUPP; 65 66 mt7615_mutex_acquire(dev); 67 68 if (dev->phy.n_beacon_vif) { 69 ret = -EBUSY; 70 goto out; 71 } 72 73 dev->pm.enable = val; 74 out: 75 mt7615_mutex_release(dev); 76 77 return ret; 78 } 79 80 static int 81 mt7615_pm_get(void *data, u64 *val) 82 { 83 struct mt7615_dev *dev = data; 84 85 *val = dev->pm.enable; 86 87 return 0; 88 } 89 90 DEFINE_DEBUGFS_ATTRIBUTE(fops_pm, mt7615_pm_get, mt7615_pm_set, "%lld\n"); 91 92 static int 93 mt7615_pm_idle_timeout_set(void *data, u64 val) 94 { 95 struct mt7615_dev *dev = data; 96 97 dev->pm.idle_timeout = msecs_to_jiffies(val); 98 99 return 0; 100 } 101 102 static int 103 mt7615_pm_idle_timeout_get(void *data, u64 *val) 104 { 105 struct mt7615_dev *dev = data; 106 107 *val = jiffies_to_msecs(dev->pm.idle_timeout); 108 109 return 0; 110 } 111 112 DEFINE_DEBUGFS_ATTRIBUTE(fops_pm_idle_timeout, mt7615_pm_idle_timeout_get, 113 mt7615_pm_idle_timeout_set, "%lld\n"); 114 115 static int 116 mt7615_dbdc_set(void *data, u64 val) 117 { 118 struct mt7615_dev *dev = data; 119 120 if (!mt7615_wait_for_mcu_init(dev)) 121 return 0; 122 123 if (val) 124 mt7615_register_ext_phy(dev); 125 else 126 mt7615_unregister_ext_phy(dev); 127 128 return 0; 129 } 130 131 static int 132 mt7615_dbdc_get(void *data, u64 *val) 133 { 134 struct mt7615_dev *dev = data; 135 136 *val = !!mt7615_ext_phy(dev); 137 138 return 0; 139 } 140 141 DEFINE_DEBUGFS_ATTRIBUTE(fops_dbdc, mt7615_dbdc_get, 142 mt7615_dbdc_set, "%lld\n"); 143 144 static int 145 mt7615_fw_debug_set(void *data, u64 val) 146 { 147 struct mt7615_dev *dev = data; 148 149 if (!mt7615_wait_for_mcu_init(dev)) 150 return 0; 151 152 dev->fw_debug = val; 153 154 mt7615_mutex_acquire(dev); 155 mt7615_mcu_fw_log_2_host(dev, dev->fw_debug ? 2 : 0); 156 mt7615_mutex_release(dev); 157 158 return 0; 159 } 160 161 static int 162 mt7615_fw_debug_get(void *data, u64 *val) 163 { 164 struct mt7615_dev *dev = data; 165 166 *val = dev->fw_debug; 167 168 return 0; 169 } 170 171 DEFINE_DEBUGFS_ATTRIBUTE(fops_fw_debug, mt7615_fw_debug_get, 172 mt7615_fw_debug_set, "%lld\n"); 173 174 static int 175 mt7615_reset_test_set(void *data, u64 val) 176 { 177 struct mt7615_dev *dev = data; 178 struct sk_buff *skb; 179 180 if (!mt7615_wait_for_mcu_init(dev)) 181 return 0; 182 183 skb = alloc_skb(1, GFP_KERNEL); 184 if (!skb) 185 return -ENOMEM; 186 187 skb_put(skb, 1); 188 189 mt7615_mutex_acquire(dev); 190 mt76_tx_queue_skb_raw(dev, dev->mphy.q_tx[0], skb, 0); 191 mt7615_mutex_release(dev); 192 193 return 0; 194 } 195 196 DEFINE_DEBUGFS_ATTRIBUTE(fops_reset_test, NULL, 197 mt7615_reset_test_set, "%lld\n"); 198 199 static void 200 mt7615_ampdu_stat_read_phy(struct mt7615_phy *phy, 201 struct seq_file *file) 202 { 203 struct mt7615_dev *dev = file->private; 204 u32 reg = is_mt7663(&dev->mt76) ? MT_MIB_ARNG(0) : MT_AGG_ASRCR0; 205 bool ext_phy = phy != &dev->phy; 206 int bound[7], i, range; 207 208 if (!phy) 209 return; 210 211 range = mt76_rr(dev, reg); 212 for (i = 0; i < 4; i++) 213 bound[i] = MT_AGG_ASRCR_RANGE(range, i) + 1; 214 215 range = mt76_rr(dev, reg + 4); 216 for (i = 0; i < 3; i++) 217 bound[i + 4] = MT_AGG_ASRCR_RANGE(range, i) + 1; 218 219 seq_printf(file, "\nPhy %d\n", ext_phy); 220 221 seq_printf(file, "Length: %8d | ", bound[0]); 222 for (i = 0; i < ARRAY_SIZE(bound) - 1; i++) 223 seq_printf(file, "%3d -%3d | ", 224 bound[i], bound[i + 1]); 225 seq_puts(file, "\nCount: "); 226 227 range = ext_phy ? ARRAY_SIZE(dev->mt76.aggr_stats) / 2 : 0; 228 for (i = 0; i < ARRAY_SIZE(bound); i++) 229 seq_printf(file, "%8d | ", dev->mt76.aggr_stats[i + range]); 230 seq_puts(file, "\n"); 231 232 seq_printf(file, "BA miss count: %d\n", phy->mib.ba_miss_cnt); 233 seq_printf(file, "PER: %ld.%1ld%%\n", 234 phy->mib.aggr_per / 10, phy->mib.aggr_per % 10); 235 } 236 237 static int 238 mt7615_ampdu_stat_show(struct seq_file *file, void *data) 239 { 240 struct mt7615_dev *dev = file->private; 241 242 mt7615_mutex_acquire(dev); 243 244 mt7615_ampdu_stat_read_phy(&dev->phy, file); 245 mt7615_ampdu_stat_read_phy(mt7615_ext_phy(dev), file); 246 247 mt7615_mutex_release(dev); 248 249 return 0; 250 } 251 252 DEFINE_SHOW_ATTRIBUTE(mt7615_ampdu_stat); 253 254 static void 255 mt7615_radio_read_phy(struct mt7615_phy *phy, struct seq_file *s) 256 { 257 struct mt7615_dev *dev = dev_get_drvdata(s->private); 258 bool ext_phy = phy != &dev->phy; 259 260 if (!phy) 261 return; 262 263 seq_printf(s, "Radio %d sensitivity: ofdm=%d cck=%d\n", ext_phy, 264 phy->ofdm_sensitivity, phy->cck_sensitivity); 265 seq_printf(s, "Radio %d false CCA: ofdm=%d cck=%d\n", ext_phy, 266 phy->false_cca_ofdm, phy->false_cca_cck); 267 } 268 269 static int 270 mt7615_radio_read(struct seq_file *s, void *data) 271 { 272 struct mt7615_dev *dev = dev_get_drvdata(s->private); 273 274 mt7615_radio_read_phy(&dev->phy, s); 275 mt7615_radio_read_phy(mt7615_ext_phy(dev), s); 276 277 return 0; 278 } 279 280 static int mt7615_read_temperature(struct seq_file *s, void *data) 281 { 282 struct mt7615_dev *dev = dev_get_drvdata(s->private); 283 int temp; 284 285 if (!mt7615_wait_for_mcu_init(dev)) 286 return 0; 287 288 /* cpu */ 289 mt7615_mutex_acquire(dev); 290 temp = mt7615_mcu_get_temperature(dev, 0); 291 mt7615_mutex_release(dev); 292 293 seq_printf(s, "Temperature: %d\n", temp); 294 295 return 0; 296 } 297 298 static int 299 mt7615_queues_acq(struct seq_file *s, void *data) 300 { 301 struct mt7615_dev *dev = dev_get_drvdata(s->private); 302 int i; 303 304 mt7615_mutex_acquire(dev); 305 306 for (i = 0; i < 16; i++) { 307 int j, wmm_idx = i % MT7615_MAX_WMM_SETS; 308 int acs = i / MT7615_MAX_WMM_SETS; 309 u32 ctrl, val, qlen = 0; 310 311 val = mt76_rr(dev, MT_PLE_AC_QEMPTY(acs, wmm_idx)); 312 ctrl = BIT(31) | BIT(15) | (acs << 8); 313 314 for (j = 0; j < 32; j++) { 315 if (val & BIT(j)) 316 continue; 317 318 mt76_wr(dev, MT_PLE_FL_Q0_CTRL, 319 ctrl | (j + (wmm_idx << 5))); 320 qlen += mt76_get_field(dev, MT_PLE_FL_Q3_CTRL, 321 GENMASK(11, 0)); 322 } 323 seq_printf(s, "AC%d%d: queued=%d\n", wmm_idx, acs, qlen); 324 } 325 326 mt7615_mutex_release(dev); 327 328 return 0; 329 } 330 331 static int 332 mt7615_queues_read(struct seq_file *s, void *data) 333 { 334 struct mt7615_dev *dev = dev_get_drvdata(s->private); 335 struct { 336 struct mt76_queue *q; 337 char *queue; 338 } queue_map[] = { 339 { dev->mphy.q_tx[MT_TXQ_BE], "PDMA0" }, 340 { dev->mt76.q_mcu[MT_MCUQ_WM], "MCUQ" }, 341 { dev->mt76.q_mcu[MT_MCUQ_FWDL], "MCUFWQ" }, 342 }; 343 int i; 344 345 for (i = 0; i < ARRAY_SIZE(queue_map); i++) { 346 struct mt76_queue *q = queue_map[i].q; 347 348 seq_printf(s, 349 "%s: queued=%d head=%d tail=%d\n", 350 queue_map[i].queue, q->queued, q->head, 351 q->tail); 352 } 353 354 return 0; 355 } 356 357 static int 358 mt7615_rf_reg_set(void *data, u64 val) 359 { 360 struct mt7615_dev *dev = data; 361 362 mt7615_rf_wr(dev, dev->debugfs_rf_wf, dev->debugfs_rf_reg, val); 363 364 return 0; 365 } 366 367 static int 368 mt7615_rf_reg_get(void *data, u64 *val) 369 { 370 struct mt7615_dev *dev = data; 371 372 *val = mt7615_rf_rr(dev, dev->debugfs_rf_wf, dev->debugfs_rf_reg); 373 374 return 0; 375 } 376 377 DEFINE_DEBUGFS_ATTRIBUTE(fops_rf_reg, mt7615_rf_reg_get, mt7615_rf_reg_set, 378 "0x%08llx\n"); 379 380 static ssize_t 381 mt7615_ext_mac_addr_read(struct file *file, char __user *userbuf, 382 size_t count, loff_t *ppos) 383 { 384 struct mt7615_dev *dev = file->private_data; 385 char buf[32 * ((ETH_ALEN * 3) + 4) + 1]; 386 u8 addr[ETH_ALEN]; 387 int ofs = 0; 388 int i; 389 390 for (i = 0; i < 32; i++) { 391 if (!(dev->muar_mask & BIT(i))) 392 continue; 393 394 mt76_wr(dev, MT_WF_RMAC_MAR1, 395 FIELD_PREP(MT_WF_RMAC_MAR1_IDX, i * 2) | 396 MT_WF_RMAC_MAR1_START); 397 put_unaligned_le32(mt76_rr(dev, MT_WF_RMAC_MAR0), addr); 398 put_unaligned_le16((mt76_rr(dev, MT_WF_RMAC_MAR1) & 399 MT_WF_RMAC_MAR1_ADDR), addr + 4); 400 ofs += snprintf(buf + ofs, sizeof(buf) - ofs, "%d=%pM\n", i, addr); 401 } 402 403 return simple_read_from_buffer(userbuf, count, ppos, buf, ofs); 404 } 405 406 static ssize_t 407 mt7615_ext_mac_addr_write(struct file *file, const char __user *userbuf, 408 size_t count, loff_t *ppos) 409 { 410 struct mt7615_dev *dev = file->private_data; 411 unsigned long idx = 0; 412 u8 addr[ETH_ALEN]; 413 char buf[32]; 414 char *p; 415 416 if (count > sizeof(buf)) 417 return -EINVAL; 418 419 if (copy_from_user(buf, userbuf, count)) 420 return -EFAULT; 421 422 buf[sizeof(buf) - 1] = '\0'; 423 424 p = strchr(buf, '='); 425 if (p) { 426 *p = 0; 427 p++; 428 429 if (kstrtoul(buf, 0, &idx) || idx > 31) 430 return -EINVAL; 431 } else { 432 idx = 0; 433 p = buf; 434 } 435 436 if (!mac_pton(p, addr)) 437 return -EINVAL; 438 439 if (is_valid_ether_addr(addr)) { 440 dev->muar_mask |= BIT(idx); 441 } else { 442 memset(addr, 0, sizeof(addr)); 443 dev->muar_mask &= ~BIT(idx); 444 } 445 446 mt76_rmw_field(dev, MT_WF_RMAC_MORE(0), MT_WF_RMAC_MORE_MUAR_MODE, 1); 447 mt76_wr(dev, MT_WF_RMAC_MAR0, get_unaligned_le32(addr)); 448 mt76_wr(dev, MT_WF_RMAC_MAR1, 449 get_unaligned_le16(addr + 4) | 450 FIELD_PREP(MT_WF_RMAC_MAR1_IDX, idx * 2) | 451 MT_WF_RMAC_MAR1_START | 452 MT_WF_RMAC_MAR1_WRITE); 453 454 mt76_rmw_field(dev, MT_WF_RMAC_MORE(0), MT_WF_RMAC_MORE_MUAR_MODE, !!dev->muar_mask); 455 456 return count; 457 } 458 459 static const struct file_operations fops_ext_mac_addr = { 460 .open = simple_open, 461 .llseek = generic_file_llseek, 462 .read = mt7615_ext_mac_addr_read, 463 .write = mt7615_ext_mac_addr_write, 464 .owner = THIS_MODULE, 465 }; 466 467 static int 468 mt7663s_sched_quota_read(struct seq_file *s, void *data) 469 { 470 struct mt7615_dev *dev = dev_get_drvdata(s->private); 471 struct mt76_sdio *sdio = &dev->mt76.sdio; 472 473 seq_printf(s, "pse_data_quota\t%d\n", sdio->sched.pse_data_quota); 474 seq_printf(s, "ple_data_quota\t%d\n", sdio->sched.ple_data_quota); 475 seq_printf(s, "pse_mcu_quota\t%d\n", sdio->sched.pse_mcu_quota); 476 seq_printf(s, "sched_deficit\t%d\n", sdio->sched.deficit); 477 478 return 0; 479 } 480 481 int mt7615_init_debugfs(struct mt7615_dev *dev) 482 { 483 struct dentry *dir; 484 485 dir = mt76_register_debugfs(&dev->mt76); 486 if (!dir) 487 return -ENOMEM; 488 489 if (is_mt7615(&dev->mt76)) 490 debugfs_create_devm_seqfile(dev->mt76.dev, "xmit-queues", dir, 491 mt7615_queues_read); 492 else 493 debugfs_create_devm_seqfile(dev->mt76.dev, "xmit-queues", dir, 494 mt76_queues_read); 495 debugfs_create_devm_seqfile(dev->mt76.dev, "acq", dir, 496 mt7615_queues_acq); 497 debugfs_create_file("ampdu_stat", 0400, dir, dev, &mt7615_ampdu_stat_fops); 498 debugfs_create_file("scs", 0600, dir, dev, &fops_scs); 499 debugfs_create_file("dbdc", 0600, dir, dev, &fops_dbdc); 500 debugfs_create_file("fw_debug", 0600, dir, dev, &fops_fw_debug); 501 debugfs_create_file("runtime-pm", 0600, dir, dev, &fops_pm); 502 debugfs_create_file("idle-timeout", 0600, dir, dev, 503 &fops_pm_idle_timeout); 504 debugfs_create_devm_seqfile(dev->mt76.dev, "radio", dir, 505 mt7615_radio_read); 506 debugfs_create_u32("dfs_hw_pattern", 0400, dir, &dev->hw_pattern); 507 /* test pattern knobs */ 508 debugfs_create_u8("pattern_len", 0600, dir, 509 &dev->radar_pattern.n_pulses); 510 debugfs_create_u32("pulse_period", 0600, dir, 511 &dev->radar_pattern.period); 512 debugfs_create_u16("pulse_width", 0600, dir, 513 &dev->radar_pattern.width); 514 debugfs_create_u16("pulse_power", 0600, dir, 515 &dev->radar_pattern.power); 516 debugfs_create_file("radar_trigger", 0200, dir, dev, 517 &fops_radar_pattern); 518 debugfs_create_file("reset_test", 0200, dir, dev, 519 &fops_reset_test); 520 debugfs_create_devm_seqfile(dev->mt76.dev, "temperature", dir, 521 mt7615_read_temperature); 522 debugfs_create_file("ext_mac_addr", 0600, dir, dev, &fops_ext_mac_addr); 523 524 debugfs_create_u32("rf_wfidx", 0600, dir, &dev->debugfs_rf_wf); 525 debugfs_create_u32("rf_regidx", 0600, dir, &dev->debugfs_rf_reg); 526 debugfs_create_file_unsafe("rf_regval", 0600, dir, dev, 527 &fops_rf_reg); 528 if (mt76_is_sdio(&dev->mt76)) 529 debugfs_create_devm_seqfile(dev->mt76.dev, "sched-quota", dir, 530 mt7663s_sched_quota_read); 531 532 return 0; 533 } 534 EXPORT_SYMBOL_GPL(mt7615_init_debugfs); 535