xref: /linux/drivers/net/wireless/mediatek/mt76/mt7603/debugfs.c (revision 17cfcb68af3bc7d5e8ae08779b1853310a2949f3)
1 // SPDX-License-Identifier: ISC
2 
3 #include "mt7603.h"
4 
5 static int
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
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
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
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 void mt7603_init_debugfs(struct mt7603_dev *dev)
73 {
74 	struct dentry *dir;
75 
76 	dir = mt76_register_debugfs(&dev->mt76);
77 	if (!dir)
78 		return;
79 
80 	debugfs_create_file("edcca", 0600, dir, dev, &fops_edcca);
81 	debugfs_create_u32("reset_test", 0600, dir, &dev->reset_test);
82 	debugfs_create_devm_seqfile(dev->mt76.dev, "reset", dir,
83 				    mt7603_reset_read);
84 	debugfs_create_devm_seqfile(dev->mt76.dev, "radio", dir,
85 				    mt7603_radio_read);
86 }
87