1 // SPDX-License-Identifier: ISC
2 
3 #include "mt7603.h"
4 
5 static int
mt7603_reset_read(struct seq_file * s,void * data)6 mt7603_reset_read(struct seq_file *s, void *data)
7 {
8 	struct mt7603_dev *dev = dev_get_drvdata(s->private);
9 	static const char * const reset_cause_str[] = {
10 		[RESET_CAUSE_TX_HANG] = "TX hang",
11 		[RESET_CAUSE_TX_BUSY] = "TX DMA busy stuck",
12 		[RESET_CAUSE_RX_BUSY] = "RX DMA busy stuck",
13 		[RESET_CAUSE_RX_PSE_BUSY] = "RX PSE busy stuck",
14 		[RESET_CAUSE_BEACON_STUCK] = "Beacon stuck",
15 		[RESET_CAUSE_MCU_HANG] = "MCU hang",
16 		[RESET_CAUSE_RESET_FAILED] = "PSE reset failed",
17 	};
18 	int i;
19 
20 	for (i = 0; i < ARRAY_SIZE(reset_cause_str); i++) {
21 		if (!reset_cause_str[i])
22 			continue;
23 
24 		seq_printf(s, "%20s: %u\n", reset_cause_str[i],
25 			   dev->reset_cause[i]);
26 	}
27 
28 	return 0;
29 }
30 
31 static int
mt7603_radio_read(struct seq_file * s,void * data)32 mt7603_radio_read(struct seq_file *s, void *data)
33 {
34 	struct mt7603_dev *dev = dev_get_drvdata(s->private);
35 
36 	seq_printf(s, "Sensitivity: %d\n", dev->sensitivity);
37 	seq_printf(s, "False CCA: ofdm=%d cck=%d\n",
38 		   dev->false_cca_ofdm, dev->false_cca_cck);
39 
40 	return 0;
41 }
42 
43 static int
mt7603_edcca_set(void * data,u64 val)44 mt7603_edcca_set(void *data, u64 val)
45 {
46 	struct mt7603_dev *dev = data;
47 
48 	mutex_lock(&dev->mt76.mutex);
49 
50 	dev->ed_monitor_enabled = !!val;
51 	dev->ed_monitor = dev->ed_monitor_enabled &&
52 			  dev->mt76.region == NL80211_DFS_ETSI;
53 	mt7603_init_edcca(dev);
54 
55 	mutex_unlock(&dev->mt76.mutex);
56 
57 	return 0;
58 }
59 
60 static int
mt7603_edcca_get(void * data,u64 * val)61 mt7603_edcca_get(void *data, u64 *val)
62 {
63 	struct mt7603_dev *dev = data;
64 
65 	*val = dev->ed_monitor_enabled;
66 	return 0;
67 }
68 
69 DEFINE_DEBUGFS_ATTRIBUTE(fops_edcca, mt7603_edcca_get,
70 			 mt7603_edcca_set, "%lld\n");
71 
72 static int
mt7603_ampdu_stat_show(struct seq_file * file,void * data)73 mt7603_ampdu_stat_show(struct seq_file *file, void *data)
74 {
75 	struct mt7603_dev *dev = file->private;
76 	int bound[3], i, range;
77 
78 	range = mt76_rr(dev, MT_AGG_ASRCR);
79 	for (i = 0; i < ARRAY_SIZE(bound); i++)
80 		bound[i] = MT_AGG_ASRCR_RANGE(range, i) + 1;
81 
82 	seq_printf(file, "Length: %8d | ", bound[0]);
83 	for (i = 0; i < ARRAY_SIZE(bound) - 1; i++)
84 		seq_printf(file, "%3d -%3d | ",
85 			   bound[i], bound[i + 1]);
86 	seq_puts(file, "\nCount:  ");
87 	for (i = 0; i < ARRAY_SIZE(bound); i++)
88 		seq_printf(file, "%8d | ", dev->mphy.aggr_stats[i]);
89 	seq_puts(file, "\n");
90 
91 	return 0;
92 }
93 
94 DEFINE_SHOW_ATTRIBUTE(mt7603_ampdu_stat);
95 
mt7603_init_debugfs(struct mt7603_dev * dev)96 void mt7603_init_debugfs(struct mt7603_dev *dev)
97 {
98 	struct dentry *dir;
99 
100 	dir = mt76_register_debugfs(&dev->mt76);
101 	if (!dir)
102 		return;
103 
104 	debugfs_create_file("ampdu_stat", 0400, dir, dev,
105 			     &mt7603_ampdu_stat_fops);
106 	debugfs_create_devm_seqfile(dev->mt76.dev, "xmit-queues", dir,
107 				    mt76_queues_read);
108 	debugfs_create_file("edcca", 0600, dir, dev, &fops_edcca);
109 	debugfs_create_u32("reset_test", 0600, dir, &dev->reset_test);
110 	debugfs_create_devm_seqfile(dev->mt76.dev, "reset", dir,
111 				    mt7603_reset_read);
112 	debugfs_create_devm_seqfile(dev->mt76.dev, "radio", dir,
113 				    mt7603_radio_read);
114 	debugfs_create_u8("sensitivity_limit", 0600, dir,
115 			    &dev->sensitivity_limit);
116 	debugfs_create_bool("dynamic_sensitivity", 0600, dir,
117 			    &dev->dynamic_sensitivity);
118 }
119