treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / net / wireless / mediatek / mt76 / mt7615 / debugfs.c
blobf6b75f832e6a13e594a68840e525af71e9ee1290
1 // SPDX-License-Identifier: ISC
3 #include "mt7615.h"
5 static int
6 mt7615_radar_pattern_set(void *data, u64 val)
8 struct mt7615_dev *dev = data;
10 return mt7615_mcu_rdd_send_pattern(dev);
13 DEFINE_DEBUGFS_ATTRIBUTE(fops_radar_pattern, NULL,
14 mt7615_radar_pattern_set, "%lld\n");
16 static int
17 mt7615_scs_set(void *data, u64 val)
19 struct mt7615_dev *dev = data;
21 mt7615_mac_set_scs(dev, val);
23 return 0;
26 static int
27 mt7615_scs_get(void *data, u64 *val)
29 struct mt7615_dev *dev = data;
31 *val = dev->scs_en;
33 return 0;
36 DEFINE_DEBUGFS_ATTRIBUTE(fops_scs, mt7615_scs_get,
37 mt7615_scs_set, "%lld\n");
39 static int
40 mt7615_ampdu_stat_read(struct seq_file *file, void *data)
42 struct mt7615_dev *dev = file->private;
43 int bound[7], i, range;
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;
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");
61 return 0;
64 static int
65 mt7615_ampdu_stat_open(struct inode *inode, struct file *f)
67 return single_open(f, mt7615_ampdu_stat_read, inode->i_private);
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,
77 static int
78 mt7615_radio_read(struct seq_file *s, void *data)
80 struct mt7615_dev *dev = dev_get_drvdata(s->private);
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);
87 return 0;
90 static int mt7615_read_temperature(struct seq_file *s, void *data)
92 struct mt7615_dev *dev = dev_get_drvdata(s->private);
93 int temp;
95 /* cpu */
96 temp = mt7615_mcu_get_temperature(dev, 0);
97 seq_printf(s, "Temperature: %d\n", temp);
99 return 0;
102 static int
103 mt7615_queues_acq(struct seq_file *s, void *data)
105 struct mt7615_dev *dev = dev_get_drvdata(s->private);
106 int i;
108 for (i = 0; i < 16; i++) {
109 int j, acs = i / 4, index = i % 4;
110 u32 ctrl, val, qlen = 0;
112 val = mt76_rr(dev, MT_PLE_AC_QEMPTY(acs, index));
113 ctrl = BIT(31) | BIT(15) | (acs << 8);
115 for (j = 0; j < 32; j++) {
116 if (val & BIT(j))
117 continue;
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));
124 seq_printf(s, "AC%d%d: queued=%d\n", acs, index, qlen);
127 return 0;
130 static int
131 mt7615_queues_read(struct seq_file *s, void *data)
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 },
142 int i;
144 for (i = 0; i < ARRAY_SIZE(queue_map); i++) {
145 struct mt76_sw_queue *q = &dev->mt76.q_tx[queue_map[i].id];
147 if (!q->q)
148 continue;
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);
156 return 0;
159 int mt7615_init_debugfs(struct mt7615_dev *dev)
161 struct dentry *dir;
163 dir = mt76_register_debugfs(&dev->mt76);
164 if (!dir)
165 return -ENOMEM;
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);
190 return 0;