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 return mt7615_mcu_rdd_send_pattern(dev); 11 } 12 13 DEFINE_DEBUGFS_ATTRIBUTE(fops_radar_pattern, NULL, 14 mt7615_radar_pattern_set, "%lld\n"); 15 16 static int 17 mt7615_scs_set(void *data, u64 val) 18 { 19 struct mt7615_dev *dev = data; 20 21 mt7615_mac_set_scs(dev, val); 22 23 return 0; 24 } 25 26 static int 27 mt7615_scs_get(void *data, u64 *val) 28 { 29 struct mt7615_dev *dev = data; 30 31 *val = dev->scs_en; 32 33 return 0; 34 } 35 36 DEFINE_DEBUGFS_ATTRIBUTE(fops_scs, mt7615_scs_get, 37 mt7615_scs_set, "%lld\n"); 38 39 static int 40 mt7615_ampdu_stat_read(struct seq_file *file, void *data) 41 { 42 struct mt7615_dev *dev = file->private; 43 int bound[7], i, range; 44 45 range = mt76_rr(dev, MT_AGG_ASRCR0); 46 for (i = 0; i < 4; i++) 47 bound[i] = MT_AGG_ASRCR_RANGE(range, i) + 1; 48 range = mt76_rr(dev, MT_AGG_ASRCR1); 49 for (i = 0; i < 3; i++) 50 bound[i + 4] = MT_AGG_ASRCR_RANGE(range, i) + 1; 51 52 seq_printf(file, "Length: %8d | ", bound[0]); 53 for (i = 0; i < ARRAY_SIZE(bound) - 1; i++) 54 seq_printf(file, "%3d -%3d | ", 55 bound[i], bound[i + 1]); 56 seq_puts(file, "\nCount: "); 57 for (i = 0; i < ARRAY_SIZE(bound); i++) 58 seq_printf(file, "%8d | ", dev->mt76.aggr_stats[i]); 59 seq_puts(file, "\n"); 60 61 return 0; 62 } 63 64 static int 65 mt7615_ampdu_stat_open(struct inode *inode, struct file *f) 66 { 67 return single_open(f, mt7615_ampdu_stat_read, inode->i_private); 68 } 69 70 static const struct file_operations fops_ampdu_stat = { 71 .open = mt7615_ampdu_stat_open, 72 .read = seq_read, 73 .llseek = seq_lseek, 74 .release = single_release, 75 }; 76 77 static int 78 mt7615_radio_read(struct seq_file *s, void *data) 79 { 80 struct mt7615_dev *dev = dev_get_drvdata(s->private); 81 82 seq_printf(s, "Sensitivity: ofdm=%d cck=%d\n", 83 dev->ofdm_sensitivity, dev->cck_sensitivity); 84 seq_printf(s, "False CCA: ofdm=%d cck=%d\n", 85 dev->false_cca_ofdm, dev->false_cca_cck); 86 87 return 0; 88 } 89 90 static int mt7615_read_temperature(struct seq_file *s, void *data) 91 { 92 struct mt7615_dev *dev = dev_get_drvdata(s->private); 93 int temp; 94 95 /* cpu */ 96 temp = mt7615_mcu_get_temperature(dev, 0); 97 seq_printf(s, "Temperature: %d\n", temp); 98 99 return 0; 100 } 101 102 static int 103 mt7615_queues_acq(struct seq_file *s, void *data) 104 { 105 struct mt7615_dev *dev = dev_get_drvdata(s->private); 106 int i; 107 108 for (i = 0; i < 16; i++) { 109 int j, acs = i / 4, index = i % 4; 110 u32 ctrl, val, qlen = 0; 111 112 val = mt76_rr(dev, MT_PLE_AC_QEMPTY(acs, index)); 113 ctrl = BIT(31) | BIT(15) | (acs << 8); 114 115 for (j = 0; j < 32; j++) { 116 if (val & BIT(j)) 117 continue; 118 119 mt76_wr(dev, MT_PLE_FL_Q0_CTRL, 120 ctrl | (j + (index << 5))); 121 qlen += mt76_get_field(dev, MT_PLE_FL_Q3_CTRL, 122 GENMASK(11, 0)); 123 } 124 seq_printf(s, "AC%d%d: queued=%d\n", acs, index, qlen); 125 } 126 127 return 0; 128 } 129 130 static int 131 mt7615_queues_read(struct seq_file *s, void *data) 132 { 133 struct mt7615_dev *dev = dev_get_drvdata(s->private); 134 static const struct { 135 char *queue; 136 int id; 137 } queue_map[] = { 138 { "PDMA0", MT_TXQ_BE }, 139 { "MCUQ", MT_TXQ_MCU }, 140 { "MCUFWQ", MT_TXQ_FWDL }, 141 }; 142 int i; 143 144 for (i = 0; i < ARRAY_SIZE(queue_map); i++) { 145 struct mt76_sw_queue *q = &dev->mt76.q_tx[queue_map[i].id]; 146 147 if (!q->q) 148 continue; 149 150 seq_printf(s, 151 "%s: queued=%d head=%d tail=%d\n", 152 queue_map[i].queue, q->q->queued, q->q->head, 153 q->q->tail); 154 } 155 156 return 0; 157 } 158 159 int mt7615_init_debugfs(struct mt7615_dev *dev) 160 { 161 struct dentry *dir; 162 163 dir = mt76_register_debugfs(&dev->mt76); 164 if (!dir) 165 return -ENOMEM; 166 167 debugfs_create_devm_seqfile(dev->mt76.dev, "queues", dir, 168 mt7615_queues_read); 169 debugfs_create_devm_seqfile(dev->mt76.dev, "acq", dir, 170 mt7615_queues_acq); 171 debugfs_create_file("ampdu_stat", 0400, dir, dev, &fops_ampdu_stat); 172 debugfs_create_file("scs", 0600, dir, dev, &fops_scs); 173 debugfs_create_devm_seqfile(dev->mt76.dev, "radio", dir, 174 mt7615_radio_read); 175 debugfs_create_u32("dfs_hw_pattern", 0400, dir, &dev->hw_pattern); 176 /* test pattern knobs */ 177 debugfs_create_u8("pattern_len", 0600, dir, 178 &dev->radar_pattern.n_pulses); 179 debugfs_create_u32("pulse_period", 0600, dir, 180 &dev->radar_pattern.period); 181 debugfs_create_u16("pulse_width", 0600, dir, 182 &dev->radar_pattern.width); 183 debugfs_create_u16("pulse_power", 0600, dir, 184 &dev->radar_pattern.power); 185 debugfs_create_file("radar_trigger", 0200, dir, dev, 186 &fops_radar_pattern); 187 debugfs_create_devm_seqfile(dev->mt76.dev, "temperature", dir, 188 mt7615_read_temperature); 189 190 return 0; 191 } 192