blob: 940b8352649e2cce6b1c250898f89da095ab417e [file] [log] [blame]
developer6a1998b2022-12-08 18:09:45 +08001From c33574d98607b2ff23a683fb30a8de2ebbc9c8f2 Mon Sep 17 00:00:00 2001
2From: Howard Hsu <howard-yh.hsu@mediatek.com>
3Date: Fri, 24 Jun 2022 11:15:45 +0800
4Subject: [PATCH 1121/1128] mt76: mt7915: add vendor subcmd EDCCA ctrl
5 enable/threshold/compensation
6
7Change-Id: I06a3f94d5e444be894200e2b6588d76ed38d09d0
8---
9 mt76_connac_mcu.h | 1 +
10 mt7915/main.c | 3 ++
11 mt7915/mcu.c | 72 +++++++++++++++++++++++++
12 mt7915/mcu.h | 21 ++++++++
13 mt7915/mt7915.h | 3 +-
14 mt7915/vendor.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++
15 mt7915/vendor.h | 33 ++++++++++++
16 7 files changed, 266 insertions(+), 1 deletion(-)
17
18diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
19index c353341e..9339b711 100644
20--- a/mt76_connac_mcu.h
21+++ b/mt76_connac_mcu.h
22@@ -1189,6 +1189,7 @@ enum {
23 MCU_EXT_CMD_SMESH_CTRL = 0xae,
24 MCU_EXT_CMD_RX_STAT_USER_CTRL = 0xb3,
25 MCU_EXT_CMD_CERT_CFG = 0xb7,
26+ MCU_EXT_CMD_EDCCA = 0xba,
27 MCU_EXT_CMD_CSI_CTRL = 0xc2,
28 MCU_EXT_CMD_IPI_HIST_SCAN = 0xc5,
29 };
30diff --git a/mt7915/main.c b/mt7915/main.c
31index 9180689e..83b97d23 100644
32--- a/mt7915/main.c
33+++ b/mt7915/main.c
34@@ -454,6 +454,9 @@ static int mt7915_config(struct ieee80211_hw *hw, u32 changed)
35 mutex_unlock(&dev->mt76.mutex);
36 }
37 #endif
38+ ret = mt7915_mcu_set_edcca(phy, EDCCA_CTRL_SET_EN, NULL, 0);
39+ if (ret)
40+ return ret;
41 ieee80211_stop_queues(hw);
42 ret = mt7915_set_channel(phy);
43 if (ret)
44diff --git a/mt7915/mcu.c b/mt7915/mcu.c
45index 97b1cf3b..cd6f3292 100644
46--- a/mt7915/mcu.c
47+++ b/mt7915/mcu.c
48@@ -4552,3 +4552,75 @@ int mt7915_mcu_ipi_hist_scan(struct mt7915_phy *phy, void *data, u8 mode, bool w
49
50 return 0;
51 }
52+
53+int mt7915_mcu_set_edcca(struct mt7915_phy *phy, int mode, u8 *value, s8 compensation)
54+{
55+ static const u8 ch_band[] = {
56+ [NL80211_BAND_2GHZ] = 0,
57+ [NL80211_BAND_5GHZ] = 1,
58+ [NL80211_BAND_6GHZ] = 2,
59+ };
60+ struct mt7915_dev *dev = phy->dev;
61+ struct cfg80211_chan_def *chandef = &phy->mt76->chandef;
62+ struct {
63+ u8 band_idx;
64+ u8 cmd_idx;
65+ u8 setting[3];
66+ bool record_in_fw;
67+ u8 region;
68+ s8 thres_compensation;
69+ } __packed req = {
70+ .band_idx = phy->band_idx,
71+ .cmd_idx = mode,
72+ .record_in_fw = false,
73+ .thres_compensation = compensation,
74+ };
75+
76+ if (ch_band[chandef->chan->band] == 2 && dev->mt76.region == NL80211_DFS_FCC)
77+ req.region = dev->mt76.region;
78+
79+ if (mode == EDCCA_CTRL_SET_EN) {
80+ req.setting[0] = (!value)? EDCCA_MODE_AUTO: value[0];
81+ } else if (mode == EDCCA_CTRL_SET_THERS) {
82+ req.setting[0] = value[0];
83+ req.setting[1] = value[1];
84+ req.setting[2] = value[2];
85+ } else {
86+ return -EINVAL;
87+ }
88+
89+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(EDCCA), &req, sizeof(req), true);
90+}
91+
92+
93+int mt7915_mcu_get_edcca(struct mt7915_phy *phy, u8 mode, s8 *value)
94+{
95+ struct mt7915_dev *dev = phy->dev;
96+ struct {
97+ u8 band_idx;
98+ u8 cmd_idx;
99+ u8 setting[3];
100+ bool record_in_fw;
101+ u8 region;
102+ s8 thres_compensation;
103+ } __packed req = {
104+ .band_idx = phy->band_idx,
105+ .cmd_idx = mode,
106+ .record_in_fw = false,
107+ };
108+ struct sk_buff *skb;
109+ int ret;
110+ struct mt7915_mcu_edcca_info *res;
111+
112+ ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_CMD(EDCCA), &req, sizeof(req),
113+ true, &skb);
114+ if (ret)
115+ return ret;
116+
117+ res = (struct mt7915_mcu_edcca_info *)skb->data;
118+ *value++ = res->info[0];
119+ *value++ = res->info[1];
120+ *value = res->info[2];
121+
122+ return 0;
123+}
124diff --git a/mt7915/mcu.h b/mt7915/mcu.h
125index 300b7834..de265d15 100644
126--- a/mt7915/mcu.h
127+++ b/mt7915/mcu.h
128@@ -866,6 +866,27 @@ enum {
129 MURU_DL_INIT,
130 MURU_UL_INIT,
131 };
132+
133+enum {
134+ EDCCA_CTRL_SET_EN = 0,
135+ EDCCA_CTRL_SET_THERS,
136+ EDCCA_CTRL_GET_EN,
137+ EDCCA_CTRL_GET_THERS,
138+ EDCCA_CTRL_NUM,
139+};
140+
141+enum {
142+ EDCCA_MODE_FORCE_DISABLE,
143+ EDCCA_MODE_AUTO,
144+};
145+
146+struct mt7915_mcu_edcca_info {
147+ u8 cmd_idx;
148+ u8 band_idx;
149+ u8 info[3];
150+ u8 fginit;
151+ u8 rsv[2];
152+};
153 #endif
154
155 #endif
156diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
157index 69f1b6b4..aaab5f7a 100644
158--- a/mt7915/mt7915.h
159+++ b/mt7915/mt7915.h
160@@ -754,7 +754,8 @@ void mt7915_vendor_amnt_fill_rx(struct mt7915_phy *phy, struct sk_buff *skb);
161 int mt7915_vendor_amnt_sta_remove(struct mt7915_phy *phy,
162 struct ieee80211_sta *sta);
163 #endif
164-
165+int mt7915_mcu_set_edcca(struct mt7915_phy *phy, int mode, u8 *value, s8 compensation);
166+int mt7915_mcu_get_edcca(struct mt7915_phy *phy, u8 mode, s8 *value);
167 int mt7915_mcu_ipi_hist_ctrl(struct mt7915_phy *phy, void *data, u8 cmd, bool wait_resp);
168 int mt7915_mcu_ipi_hist_scan(struct mt7915_phy *phy, void *data, u8 mode, bool wait_resp);
169
170diff --git a/mt7915/vendor.c b/mt7915/vendor.c
171index 77d71e48..cd5c3b83 100644
172--- a/mt7915/vendor.c
173+++ b/mt7915/vendor.c
174@@ -62,6 +62,24 @@ phy_capa_dump_policy[NUM_MTK_VENDOR_ATTRS_PHY_CAPA_DUMP] = {
175 [MTK_VENDOR_ATTR_PHY_CAPA_DUMP_MAX_SUPPORTED_STA] = { .type = NLA_U16 },
176 };
177
178+static const struct nla_policy
179+edcca_ctrl_policy[NUM_MTK_VENDOR_ATTRS_EDCCA_CTRL] = {
180+ [MTK_VENDOR_ATTR_EDCCA_CTRL_MODE] = { .type = NLA_U8 },
181+ [MTK_VENDOR_ATTR_EDCCA_CTRL_PRI20_VAL] = { .type = NLA_U8 },
182+ [MTK_VENDOR_ATTR_EDCCA_CTRL_SEC20_VAL] = { .type = NLA_U8 },
183+ [MTK_VENDOR_ATTR_EDCCA_CTRL_SEC40_VAL] = { .type = NLA_U8 },
184+ [MTK_VENDOR_ATTR_EDCCA_CTRL_SEC80_VAL] = { .type = NLA_U8 },
185+ [MTK_VENDOR_ATTR_EDCCA_CTRL_COMPENSATE] = { .type = NLA_S8 },
186+};
187+
188+static const struct nla_policy
189+edcca_dump_policy[NUM_MTK_VENDOR_ATTRS_EDCCA_DUMP] = {
190+ [MTK_VENDOR_ATTR_EDCCA_DUMP_MODE] = { .type = NLA_U8 },
191+ [MTK_VENDOR_ATTR_EDCCA_DUMP_PRI20_VAL] = { .type = NLA_U8 },
192+ [MTK_VENDOR_ATTR_EDCCA_DUMP_SEC40_VAL] = { .type = NLA_U8 },
193+ [MTK_VENDOR_ATTR_EDCCA_DUMP_SEC80_VAL] = { .type = NLA_U8 },
194+};
195+
196 struct csi_null_tone {
197 u8 start;
198 u8 end;
199@@ -1015,6 +1033,110 @@ mt7915_vendor_phy_capa_ctrl_dump(struct wiphy *wiphy, struct wireless_dev *wdev,
200 return len;
201 }
202
203+static int mt7915_vendor_edcca_ctrl(struct wiphy *wiphy,
204+ struct wireless_dev *wdev,
205+ const void *data,
206+ int data_len)
207+{
208+ struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
209+ struct mt7915_phy *phy = mt7915_hw_phy(hw);
210+ struct nlattr *tb[NUM_MTK_VENDOR_ATTRS_EDCCA_CTRL];
211+ int err;
212+ u8 edcca_mode;
213+ s8 edcca_compensation;
214+ u8 edcca_value[EDCCA_THRES_NUM] = {0};
215+
216+ err = nla_parse(tb, MTK_VENDOR_ATTR_EDCCA_CTRL_MAX, data, data_len,
217+ edcca_ctrl_policy, NULL);
218+ if (err)
219+ return err;
220+
221+ if (!tb[MTK_VENDOR_ATTR_EDCCA_CTRL_MODE])
222+ return -EINVAL;
223+
224+ edcca_mode = nla_get_u8(tb[MTK_VENDOR_ATTR_EDCCA_CTRL_MODE]);
225+ if (edcca_mode == EDCCA_CTRL_SET_EN) {
226+ if (!tb[MTK_VENDOR_ATTR_EDCCA_CTRL_PRI20_VAL] ||
227+ !tb[MTK_VENDOR_ATTR_EDCCA_CTRL_COMPENSATE]) {
228+ return -EINVAL;
229+ }
230+ edcca_value[0] =
231+ nla_get_u8(tb[MTK_VENDOR_ATTR_EDCCA_CTRL_PRI20_VAL]);
232+ edcca_compensation =
233+ nla_get_s8(tb[MTK_VENDOR_ATTR_EDCCA_CTRL_COMPENSATE]);
234+
235+ err = mt7915_mcu_set_edcca(phy, edcca_mode, edcca_value,
236+ edcca_compensation);
237+ if (err)
238+ return err;
239+ } else if (edcca_mode == EDCCA_CTRL_SET_THERS) {
240+ if (!tb[MTK_VENDOR_ATTR_EDCCA_CTRL_PRI20_VAL] ||
241+ !tb[MTK_VENDOR_ATTR_EDCCA_CTRL_SEC40_VAL] ||
242+ !tb[MTK_VENDOR_ATTR_EDCCA_CTRL_SEC80_VAL]) {
243+ return -EINVAL;
244+ }
245+ edcca_value[0] =
246+ nla_get_u8(tb[MTK_VENDOR_ATTR_EDCCA_CTRL_PRI20_VAL]);
247+ edcca_value[1] =
248+ nla_get_u8(tb[MTK_VENDOR_ATTR_EDCCA_CTRL_SEC40_VAL]);
249+ edcca_value[2] =
250+ nla_get_u8(tb[MTK_VENDOR_ATTR_EDCCA_CTRL_SEC80_VAL]);
251+ err = mt7915_mcu_set_edcca(phy, edcca_mode, edcca_value,
252+ edcca_compensation);
253+ if (err)
254+ return err;
255+ } else {
256+ return -EINVAL;
257+ }
258+
259+ return 0;
260+}
261+
262+static int
263+mt7915_vendor_edcca_ctrl_dump(struct wiphy *wiphy, struct wireless_dev *wdev,
264+ struct sk_buff *skb, const void *data, int data_len,
265+ unsigned long *storage)
266+{
267+ struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
268+ struct mt7915_phy *phy = mt7915_hw_phy(hw);
269+ struct mt7915_dev *dev = phy->dev;
270+ struct nlattr *tb[NUM_MTK_VENDOR_ATTRS_EDCCA_CTRL];
271+ void *a;
272+ int len = EDCCA_THRES_NUM;
273+ int err;
274+ u8 edcca_mode;
275+ s8 value[EDCCA_THRES_NUM];
276+
277+ if (*storage == 1)
278+ return -ENOENT;
279+ *storage = 1;
280+
281+ err = nla_parse(tb, MTK_VENDOR_ATTR_EDCCA_CTRL_MAX, data, data_len,
282+ edcca_ctrl_policy, NULL);
283+ if (err)
284+ return err;
285+
286+ if (!tb[MTK_VENDOR_ATTR_EDCCA_CTRL_MODE])
287+ return -EINVAL;
288+
289+ edcca_mode = nla_get_u8(tb[MTK_VENDOR_ATTR_EDCCA_CTRL_MODE]);
290+ if (edcca_mode == EDCCA_CTRL_GET_EN || edcca_mode == EDCCA_CTRL_GET_THERS) {
291+ err = mt7915_mcu_get_edcca(phy, edcca_mode, value);
292+ } else {
293+ return -EINVAL;
294+ }
295+
296+ if (err)
297+ return err;
298+
299+ if (nla_put_u8(skb, MTK_VENDOR_ATTR_EDCCA_DUMP_PRI20_VAL, value[0]) ||
300+ nla_put_u8(skb, MTK_VENDOR_ATTR_EDCCA_DUMP_SEC40_VAL, value[1]) ||
301+ nla_put_u8(skb, MTK_VENDOR_ATTR_EDCCA_DUMP_SEC80_VAL, value[2]))
302+ return -ENOMEM;
303+
304+ return len;
305+}
306+
307 static const struct wiphy_vendor_command mt7915_vendor_commands[] = {
308 {
309 .info = {
310@@ -1083,6 +1205,18 @@ static const struct wiphy_vendor_command mt7915_vendor_commands[] = {
311 .dumpit = mt7915_vendor_phy_capa_ctrl_dump,
312 .policy = phy_capa_ctrl_policy,
313 .maxattr = MTK_VENDOR_ATTR_PHY_CAPA_CTRL_MAX,
314+ },
315+ {
316+ .info = {
317+ .vendor_id = MTK_NL80211_VENDOR_ID,
318+ .subcmd = MTK_NL80211_VENDOR_SUBCMD_EDCCA_CTRL,
319+ },
320+ .flags = WIPHY_VENDOR_CMD_NEED_NETDEV |
321+ WIPHY_VENDOR_CMD_NEED_RUNNING,
322+ .doit = mt7915_vendor_edcca_ctrl,
323+ .dumpit = mt7915_vendor_edcca_ctrl_dump,
324+ .policy = edcca_ctrl_policy,
325+ .maxattr = MTK_VENDOR_ATTR_EDCCA_CTRL_MAX,
326 }
327 };
328
329diff --git a/mt7915/vendor.h b/mt7915/vendor.h
330index 719b851f..72319717 100644
331--- a/mt7915/vendor.h
332+++ b/mt7915/vendor.h
333@@ -2,6 +2,7 @@
334 #define __MT7915_VENDOR_H
335
336 #define MTK_NL80211_VENDOR_ID 0x0ce7
337+#define EDCCA_THRES_NUM 3
338
339 enum mtk_nl80211_vendor_subcmds {
340 MTK_NL80211_VENDOR_SUBCMD_AMNT_CTRL = 0xae,
341@@ -10,6 +11,38 @@ enum mtk_nl80211_vendor_subcmds {
342 MTK_NL80211_VENDOR_SUBCMD_WIRELESS_CTRL = 0xc4,
343 MTK_NL80211_VENDOR_SUBCMD_HEMU_CTRL = 0xc5,
344 MTK_NL80211_VENDOR_SUBCMD_PHY_CAPA_CTRL = 0xc6,
345+ MTK_NL80211_VENDOR_SUBCMD_EDCCA_CTRL = 0xc7,
346+};
347+
348+
349+enum mtk_vendor_attr_edcca_ctrl {
350+ MTK_VENDOR_ATTR_EDCCA_THRESHOLD_INVALID = 0,
351+
352+ MTK_VENDOR_ATTR_EDCCA_CTRL_MODE,
353+ MTK_VENDOR_ATTR_EDCCA_CTRL_PRI20_VAL,
354+ MTK_VENDOR_ATTR_EDCCA_CTRL_SEC20_VAL,
355+ MTK_VENDOR_ATTR_EDCCA_CTRL_SEC40_VAL,
356+ MTK_VENDOR_ATTR_EDCCA_CTRL_SEC80_VAL,
357+ MTK_VENDOR_ATTR_EDCCA_CTRL_COMPENSATE,
358+
359+ /* keep last */
360+ NUM_MTK_VENDOR_ATTRS_EDCCA_CTRL,
361+ MTK_VENDOR_ATTR_EDCCA_CTRL_MAX =
362+ NUM_MTK_VENDOR_ATTRS_EDCCA_CTRL - 1
363+};
364+
365+enum mtk_vendor_attr_edcca_dump {
366+ MTK_VENDOR_ATTR_EDCCA_DUMP_UNSPEC = 0,
367+
368+ MTK_VENDOR_ATTR_EDCCA_DUMP_MODE,
369+ MTK_VENDOR_ATTR_EDCCA_DUMP_PRI20_VAL,
370+ MTK_VENDOR_ATTR_EDCCA_DUMP_SEC40_VAL,
371+ MTK_VENDOR_ATTR_EDCCA_DUMP_SEC80_VAL,
372+
373+ /* keep last */
374+ NUM_MTK_VENDOR_ATTRS_EDCCA_DUMP,
375+ MTK_VENDOR_ATTR_EDCCA_DUMP_MAX =
376+ NUM_MTK_VENDOR_ATTRS_EDCCA_DUMP - 1
377 };
378
379 enum mtk_capi_control_changed {
380--
3812.36.1
382