blob: 41861e63ac5917d3a02050b8cbcec3bd2e08c454 [file] [log] [blame]
developer05f3b2b2024-08-19 19:17:34 +08001From 8facea1f5154f7a3d246456e0e9e1d16872779a8 Mon Sep 17 00:00:00 2001
2From: Peter Chiu <chui-hao.chiu@mediatek.com>
3Date: Fri, 31 May 2024 10:55:03 +0800
4Subject: [PATCH 147/199] mtk: mt76: mt7996: add debugfs knob to set agc
5
6Add the following debugfs knob
7- /sys/kernel/debug/ieee80211/phy0/mt76/mlo_agc_tx
8- /sys/kernel/debug/ieee80211/phy0/mt76/mlo_agc_trig
9
10Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com>
11---
12 mt76_connac_mcu.h | 1 +
13 mt7996/mcu.h | 20 ++++++++
14 mt7996/mt7996.h | 1 +
15 mt7996/mtk_debugfs_i.c | 103 +++++++++++++++++++++++++++++++++++++++++
16 mt7996/mtk_mcu.c | 6 +++
17 5 files changed, 131 insertions(+)
18
19diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
20index d72337d4..f7b1f0d0 100644
21--- a/mt76_connac_mcu.h
22+++ b/mt76_connac_mcu.h
23@@ -1312,6 +1312,7 @@ enum {
24 MCU_UNI_CMD_THERMAL_CAL = 0x4c,
25 MCU_UNI_CMD_RRO = 0x57,
26 MCU_UNI_CMD_OFFCH_SCAN_CTRL = 0x58,
27+ MCU_UNI_CMD_MLO = 0x59,
28 MCU_UNI_CMD_PER_STA_INFO = 0x6d,
29 MCU_UNI_CMD_ALL_STA_INFO = 0x6e,
30 MCU_UNI_CMD_ASSERT_DUMP = 0x6f,
31diff --git a/mt7996/mcu.h b/mt7996/mcu.h
32index c39dcc3c..389aab63 100644
33--- a/mt7996/mcu.h
34+++ b/mt7996/mcu.h
35@@ -1157,6 +1157,26 @@ enum {
36 UNI_CMD_SCS_ENABLE,
37 };
38
39+enum {
40+ UNI_CMD_MLO_AGC_TX = 4,
41+ UNI_CMD_MLO_AGC_TRIG = 5,
42+};
43+
44+struct mt7996_mlo_agc_set {
45+ u8 rsv[4];
46+
47+ __le16 tag;
48+ __le16 len;
49+
50+ u8 mld_id;
51+ u8 link_id;
52+ u8 ac;
53+ u8 disp_pol;
54+ u8 ratio;
55+ u8 order;
56+ __le16 mgf;
57+} __packed;
58+
59 #define MT7996_PATCH_SEC GENMASK(31, 24)
60 #define MT7996_PATCH_SCRAMBLE_KEY GENMASK(15, 8)
61 #define MT7996_PATCH_AES_KEY GENMASK(7, 0)
62diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h
63index 96d8aae9..cb6a5753 100644
64--- a/mt7996/mt7996.h
65+++ b/mt7996/mt7996.h
66@@ -1324,6 +1324,7 @@ void mt7996_dump_bmac_txd_info(struct seq_file *s, struct mt7996_dev *dev,
67 __le32 *txd, bool is_hif_txd, bool dump_txp);
68 int mt7996_mtk_init_dev_debugfs_internal(struct mt7996_phy *phy, struct dentry *dir);
69 int mt7996_mtk_init_band_debugfs_internal(struct mt7996_phy *phy, struct dentry *dir);
70+int mt7996_mcu_mlo_agc(struct mt7996_dev *dev, const void *data, int len);
71 #endif
72
73 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
74diff --git a/mt7996/mtk_debugfs_i.c b/mt7996/mtk_debugfs_i.c
75index 839c3e31..852d1b12 100644
76--- a/mt7996/mtk_debugfs_i.c
77+++ b/mt7996/mtk_debugfs_i.c
78@@ -774,6 +774,106 @@ mt7996_agg_table_show(struct seq_file *s, void *data)
79 }
80 DEFINE_SHOW_ATTRIBUTE(mt7996_agg_table);
81
82+static ssize_t mt7996_mlo_agc_tx_set(struct file *file,
83+ const char __user *user_buf,
84+ size_t count, loff_t *ppos)
85+{
86+ struct mt7996_dev *dev = file->private_data;
87+ struct mt7996_mlo_agc_set req;
88+ char buf[100];
89+ int ret;
90+ u16 mgf;
91+
92+ memset(&req, 0, sizeof(req));
93+
94+ if (count >= sizeof(buf))
95+ return -EINVAL;
96+
97+ if (copy_from_user(buf, user_buf, count))
98+ return -EFAULT;
99+
100+ if (count && buf[count - 1] == '\n')
101+ buf[count - 1] = '\0';
102+ else
103+ buf[count] = '\0';
104+
105+ if (sscanf(buf, "%hhu %hhu %hhu %hhu %hu %hhu %hhu",
106+ &req.mld_id, &req.link_id, &req.ac, &req.disp_pol,
107+ &mgf, &req.ratio, &req.order) != 7) {
108+ dev_warn(dev->mt76.dev,
109+ "format: [MldRecIdx] [Link] [Ac] [DispPol] [MGF] [Ratio] [Order]\n");
110+ goto out;
111+ }
112+
113+ req.tag = cpu_to_le16(UNI_CMD_MLO_AGC_TX);
114+ req.len = cpu_to_le16(sizeof(req) - 4);
115+ req.mgf = cpu_to_le16(mgf);
116+
117+ ret = mt7996_mcu_mlo_agc(dev, &req, sizeof(req));
118+ if (ret)
119+ return -EFAULT;
120+
121+out:
122+ return count;
123+}
124+
125+static const struct file_operations fops_mlo_agc_tx = {
126+ .write = mt7996_mlo_agc_tx_set,
127+ .open = simple_open,
128+ .owner = THIS_MODULE,
129+ .llseek = default_llseek,
130+};
131+
132+static ssize_t mt7996_mlo_agc_trig_set(struct file *file,
133+ const char __user *user_buf,
134+ size_t count, loff_t *ppos)
135+{
136+ struct mt7996_dev *dev = file->private_data;
137+ struct mt7996_mlo_agc_set req;
138+ char buf[100];
139+ int ret;
140+ u16 mgf;
141+
142+ memset(&req, 0, sizeof(req));
143+
144+ if (count >= sizeof(buf))
145+ return -EINVAL;
146+
147+ if (copy_from_user(buf, user_buf, count))
148+ return -EFAULT;
149+
150+ if (count && buf[count - 1] == '\n')
151+ buf[count - 1] = '\0';
152+ else
153+ buf[count] = '\0';
154+
155+ if (sscanf(buf, "%hhu %hhu %hhu %hhu %hu %hhu",
156+ &req.mld_id, &req.link_id, &req.ac, &req.disp_pol,
157+ &mgf, &req.ratio) != 6) {
158+ dev_warn(dev->mt76.dev,
159+ "format: [MldRecIdx] [Link] [Ac] [DispPol] [MGF] [Ratio]\n");
160+ goto out;
161+ }
162+
163+ req.tag = cpu_to_le16(UNI_CMD_MLO_AGC_TRIG);
164+ req.len = cpu_to_le16(sizeof(req) - 4);
165+ req.mgf = cpu_to_le16(mgf);
166+
167+ ret = mt7996_mcu_mlo_agc(dev, &req, sizeof(req));
168+ if (ret)
169+ return -EFAULT;
170+
171+out:
172+ return count;
173+}
174+
175+static const struct file_operations fops_mlo_agc_trig = {
176+ .write = mt7996_mlo_agc_trig_set,
177+ .open = simple_open,
178+ .owner = THIS_MODULE,
179+ .llseek = default_llseek,
180+};
181+
182 int mt7996_mtk_init_dev_debugfs_internal(struct mt7996_phy *phy, struct dentry *dir)
183 {
184 struct mt7996_dev *dev = phy->dev;
185@@ -796,6 +896,9 @@ int mt7996_mtk_init_dev_debugfs_internal(struct mt7996_phy *phy, struct dentry *
186
187 /* MLO related Table */
188 debugfs_create_file("mat_table", 0400, dir, dev, &mt7996_mat_table_fops);
189+ debugfs_create_file("mlo_agc_tx", 0200, dir, dev, &fops_mlo_agc_tx);
190+ debugfs_create_file("mlo_agc_trig", 0200, dir, dev, &fops_mlo_agc_trig);
191+
192 return 0;
193 }
194
195diff --git a/mt7996/mtk_mcu.c b/mt7996/mtk_mcu.c
196index 809181e0..82e3f721 100644
197--- a/mt7996/mtk_mcu.c
198+++ b/mt7996/mtk_mcu.c
199@@ -1364,4 +1364,10 @@ int mt7996_mcu_thermal_debug(struct mt7996_dev *dev, u8 mode, u8 action)
200 return mt76_mcu_send_msg(&dev->mt76, MCU_WM_UNI_CMD(THERMAL_CAL), &req,
201 sizeof(req), true);
202 }
203+
204+int mt7996_mcu_mlo_agc(struct mt7996_dev *dev, const void *data, int len)
205+{
206+ return mt76_mcu_send_msg(&dev->mt76, MCU_WM_UNI_CMD(MLO), data,
207+ len, true);
208+}
209 #endif
210--
2112.18.0
212