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 10 if (!mt7615_wait_for_mcu_init(dev)) 11 return 0; 12 13 return mt7615_mcu_rdd_send_pattern(dev); 14 } 15 16 DEFINE_DEBUGFS_ATTRIBUTE(fops_radar_pattern, NULL, 17 mt7615_radar_pattern_set, "%lld\n"); 18 19 static int 20 mt7615_scs_set(void *data, u64 val) 21 { 22 struct mt7615_dev *dev = data; 23 24 if (!mt7615_wait_for_mcu_init(dev)) 25 return 0; 26 27 mt7615_mac_set_scs(dev, val); 28 29 return 0; 30 } 31 32 static int 33 mt7615_scs_get(void *data, u64 *val) 34 { 35 struct mt7615_dev *dev = data; 36 37 *val = dev->scs_en; 38 39 return 0; 40 } 41 42 DEFINE_DEBUGFS_ATTRIBUTE(fops_scs, mt7615_scs_get, 43 mt7615_scs_set, "%lld\n"); 44 45 static int 46 mt7615_dbdc_set(void *data, u64 val) 47 { 48 struct mt7615_dev *dev = data; 49 50 if (!mt7615_wait_for_mcu_init(dev)) 51 return 0; 52 53 if (val) 54 mt7615_register_ext_phy(dev); 55 else 56 mt7615_unregister_ext_phy(dev); 57 58 return 0; 59 } 60 61 static int 62 mt7615_dbdc_get(void *data, u64 *val) 63 { 64 struct mt7615_dev *dev = data; 65 66 *val = !!mt7615_ext_phy(dev); 67 68 return 0; 69 } 70 71 DEFINE_DEBUGFS_ATTRIBUTE(fops_dbdc, mt7615_dbdc_get, 72 mt7615_dbdc_set, "%lld\n"); 73 74 static int 75 mt7615_fw_debug_set(void *data, u64 val) 76 { 77 struct mt7615_dev *dev = data; 78 79 if (!mt7615_wait_for_mcu_init(dev)) 80 return 0; 81 82 dev->fw_debug = val; 83 mt7615_mcu_fw_log_2_host(dev, dev->fw_debug ? 2 : 0); 84 85 return 0; 86 } 87 88 static int 89 mt7615_fw_debug_get(void *data, u64 *val) 90 { 91 struct mt7615_dev *dev = data; 92 93 *val = dev->fw_debug; 94 95 return 0; 96 } 97 98 DEFINE_DEBUGFS_ATTRIBUTE(fops_fw_debug, mt7615_fw_debug_get, 99 mt7615_fw_debug_set, "%lld\n"); 100 101 static int 102 mt7615_reset_test_set(void *data, u64 val) 103 { 104 struct mt7615_dev *dev = data; 105 struct sk_buff *skb; 106 107 if (!mt7615_wait_for_mcu_init(dev)) 108 return 0; 109 110 skb = alloc_skb(1, GFP_KERNEL); 111 if (!skb) 112 return -ENOMEM; 113 114 skb_put(skb, 1); 115 mt76_tx_queue_skb_raw(dev, 0, skb, 0); 116 117 return 0; 118 } 119 120 DEFINE_DEBUGFS_ATTRIBUTE(fops_reset_test, NULL, 121 mt7615_reset_test_set, "%lld\n"); 122 123 static int 124 mt7615_ampdu_stat_read(struct seq_file *file, void *data) 125 { 126 struct mt7615_dev *dev = file->private; 127 int bound[7], i, range; 128 129 range = mt76_rr(dev, MT_AGG_ASRCR0); 130 for (i = 0; i < 4; i++) 131 bound[i] = MT_AGG_ASRCR_RANGE(range, i) + 1; 132 range = mt76_rr(dev, MT_AGG_ASRCR1); 133 for (i = 0; i < 3; i++) 134 bound[i + 4] = MT_AGG_ASRCR_RANGE(range, i) + 1; 135 136 seq_printf(file, "Length: %8d | ", bound[0]); 137 for (i = 0; i < ARRAY_SIZE(bound) - 1; i++) 138 seq_printf(file, "%3d -%3d | ", 139 bound[i], bound[i + 1]); 140 seq_puts(file, "\nCount: "); 141 for (i = 0; i < ARRAY_SIZE(bound); i++) 142 seq_printf(file, "%8d | ", dev->mt76.aggr_stats[i]); 143 seq_puts(file, "\n"); 144 145 return 0; 146 } 147 148 static int 149 mt7615_ampdu_stat_open(struct inode *inode, struct file *f) 150 { 151 return single_open(f, mt7615_ampdu_stat_read, inode->i_private); 152 } 153 154 static const struct file_operations fops_ampdu_stat = { 155 .open = mt7615_ampdu_stat_open, 156 .read = seq_read, 157 .llseek = seq_lseek, 158 .release = single_release, 159 }; 160 161 static void 162 mt7615_radio_read_phy(struct mt7615_phy *phy, struct seq_file *s) 163 { 164 struct mt7615_dev *dev = dev_get_drvdata(s->private); 165 bool ext_phy = phy != &dev->phy; 166 167 if (!phy) 168 return; 169 170 seq_printf(s, "Radio %d sensitivity: ofdm=%d cck=%d\n", ext_phy, 171 phy->ofdm_sensitivity, phy->cck_sensitivity); 172 seq_printf(s, "Radio %d false CCA: ofdm=%d cck=%d\n", ext_phy, 173 phy->false_cca_ofdm, phy->false_cca_cck); 174 } 175 176 static int 177 mt7615_radio_read(struct seq_file *s, void *data) 178 { 179 struct mt7615_dev *dev = dev_get_drvdata(s->private); 180 181 mt7615_radio_read_phy(&dev->phy, s); 182 mt7615_radio_read_phy(mt7615_ext_phy(dev), s); 183 184 return 0; 185 } 186 187 static int mt7615_read_temperature(struct seq_file *s, void *data) 188 { 189 struct mt7615_dev *dev = dev_get_drvdata(s->private); 190 int temp; 191 192 if (!mt7615_wait_for_mcu_init(dev)) 193 return 0; 194 195 /* cpu */ 196 temp = mt7615_mcu_get_temperature(dev, 0); 197 seq_printf(s, "Temperature: %d\n", temp); 198 199 return 0; 200 } 201 202 static int 203 mt7615_queues_acq(struct seq_file *s, void *data) 204 { 205 struct mt7615_dev *dev = dev_get_drvdata(s->private); 206 int i; 207 208 for (i = 0; i < 16; i++) { 209 int j, acs = i / 4, index = i % 4; 210 u32 ctrl, val, qlen = 0; 211 212 val = mt76_rr(dev, MT_PLE_AC_QEMPTY(acs, index)); 213 ctrl = BIT(31) | BIT(15) | (acs << 8); 214 215 for (j = 0; j < 32; j++) { 216 if (val & BIT(j)) 217 continue; 218 219 mt76_wr(dev, MT_PLE_FL_Q0_CTRL, 220 ctrl | (j + (index << 5))); 221 qlen += mt76_get_field(dev, MT_PLE_FL_Q3_CTRL, 222 GENMASK(11, 0)); 223 } 224 seq_printf(s, "AC%d%d: queued=%d\n", acs, index, qlen); 225 } 226 227 return 0; 228 } 229 230 static int 231 mt7615_queues_read(struct seq_file *s, void *data) 232 { 233 struct mt7615_dev *dev = dev_get_drvdata(s->private); 234 static const struct { 235 char *queue; 236 int id; 237 } queue_map[] = { 238 { "PDMA0", MT_TXQ_BE }, 239 { "MCUQ", MT_TXQ_MCU }, 240 { "MCUFWQ", MT_TXQ_FWDL }, 241 }; 242 int i; 243 244 for (i = 0; i < ARRAY_SIZE(queue_map); i++) { 245 struct mt76_sw_queue *q = &dev->mt76.q_tx[queue_map[i].id]; 246 247 if (!q->q) 248 continue; 249 250 seq_printf(s, 251 "%s: queued=%d head=%d tail=%d\n", 252 queue_map[i].queue, q->q->queued, q->q->head, 253 q->q->tail); 254 } 255 256 return 0; 257 } 258 259 int mt7615_init_debugfs(struct mt7615_dev *dev) 260 { 261 struct dentry *dir; 262 263 dir = mt76_register_debugfs(&dev->mt76); 264 if (!dir) 265 return -ENOMEM; 266 267 if (is_mt7615(&dev->mt76)) 268 debugfs_create_devm_seqfile(dev->mt76.dev, "queues", dir, 269 mt7615_queues_read); 270 else 271 debugfs_create_devm_seqfile(dev->mt76.dev, "queues", dir, 272 mt76_queues_read); 273 debugfs_create_devm_seqfile(dev->mt76.dev, "acq", dir, 274 mt7615_queues_acq); 275 debugfs_create_file("ampdu_stat", 0400, dir, dev, &fops_ampdu_stat); 276 debugfs_create_file("scs", 0600, dir, dev, &fops_scs); 277 debugfs_create_file("dbdc", 0600, dir, dev, &fops_dbdc); 278 debugfs_create_file("fw_debug", 0600, dir, dev, &fops_fw_debug); 279 debugfs_create_devm_seqfile(dev->mt76.dev, "radio", dir, 280 mt7615_radio_read); 281 debugfs_create_u32("dfs_hw_pattern", 0400, dir, &dev->hw_pattern); 282 /* test pattern knobs */ 283 debugfs_create_u8("pattern_len", 0600, dir, 284 &dev->radar_pattern.n_pulses); 285 debugfs_create_u32("pulse_period", 0600, dir, 286 &dev->radar_pattern.period); 287 debugfs_create_u16("pulse_width", 0600, dir, 288 &dev->radar_pattern.width); 289 debugfs_create_u16("pulse_power", 0600, dir, 290 &dev->radar_pattern.power); 291 debugfs_create_file("radar_trigger", 0200, dir, dev, 292 &fops_radar_pattern); 293 debugfs_create_file("reset_test", 0200, dir, dev, 294 &fops_reset_test); 295 debugfs_create_devm_seqfile(dev->mt76.dev, "temperature", dir, 296 mt7615_read_temperature); 297 298 return 0; 299 } 300