blob: e58ee254f13186f965160d29f3c8efb3de77aa83 [file] [log] [blame]
developer60a3d662023-02-07 15:24:34 +08001From b9f5dab1bd609a933fab9d7e962a3db1d6e91c29 Mon Sep 17 00:00:00 2001
developere2cfb522022-12-08 18:09:45 +08002From: Howard Hsu <howard-yh.hsu@mediatek.com>
3Date: Fri, 24 Jun 2022 11:15:45 +0800
developer60a3d662023-02-07 15:24:34 +08004Subject: [PATCH 1121/1133] mt76: mt7915: add vendor subcmd EDCCA ctrl
developere2cfb522022-12-08 18:09:45 +08005 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 +-
developeraa5b1b22022-12-13 17:05:25 +080014 mt7915/vendor.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++
developere2cfb522022-12-08 18:09:45 +080015 mt7915/vendor.h | 33 ++++++++++++
developeraa5b1b22022-12-13 17:05:25 +080016 7 files changed, 264 insertions(+), 1 deletion(-)
developere2cfb522022-12-08 18:09:45 +080017
18diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
developer60a3d662023-02-07 15:24:34 +080019index 5cef308a..65863a0d 100644
developere2cfb522022-12-08 18:09:45 +080020--- a/mt76_connac_mcu.h
21+++ b/mt76_connac_mcu.h
developer60a3d662023-02-07 15:24:34 +080022@@ -1205,6 +1205,7 @@ enum {
developere2cfb522022-12-08 18:09:45 +080023 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
developer60a3d662023-02-07 15:24:34 +080031index c32df9b1..96236f4c 100644
developere2cfb522022-12-08 18:09:45 +080032--- a/mt7915/main.c
33+++ b/mt7915/main.c
developerc5ce7502022-12-19 11:33:22 +080034@@ -479,6 +479,9 @@ static int mt7915_config(struct ieee80211_hw *hw, u32 changed)
developere2cfb522022-12-08 18:09:45 +080035 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
developer60a3d662023-02-07 15:24:34 +080045index 28698d37..46f29021 100644
developere2cfb522022-12-08 18:09:45 +080046--- a/mt7915/mcu.c
47+++ b/mt7915/mcu.c
developer60a3d662023-02-07 15:24:34 +080048@@ -4622,3 +4622,75 @@ int mt7915_mcu_ipi_hist_scan(struct mt7915_phy *phy, void *data, u8 mode, bool w
developere2cfb522022-12-08 18:09:45 +080049
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 = {
developeraa5b1b22022-12-13 17:05:25 +080070+ .band_idx = phy->mt76->band_idx,
developere2cfb522022-12-08 18:09:45 +080071+ .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 = {
developeraa5b1b22022-12-13 17:05:25 +0800104+ .band_idx = phy->mt76->band_idx,
developere2cfb522022-12-08 18:09:45 +0800105+ .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
developer60a3d662023-02-07 15:24:34 +0800125index 5c5c92fc..c87fe8e8 100644
developere2cfb522022-12-08 18:09:45 +0800126--- a/mt7915/mcu.h
127+++ b/mt7915/mcu.h
developer60a3d662023-02-07 15:24:34 +0800128@@ -1058,6 +1058,27 @@ enum {
developere2cfb522022-12-08 18:09:45 +0800129 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
developer60a3d662023-02-07 15:24:34 +0800157index 9d98633c..8418c7dc 100644
developere2cfb522022-12-08 18:09:45 +0800158--- a/mt7915/mt7915.h
159+++ b/mt7915/mt7915.h
developer60a3d662023-02-07 15:24:34 +0800160@@ -762,7 +762,8 @@ void mt7915_vendor_amnt_fill_rx(struct mt7915_phy *phy, struct sk_buff *skb);
developere2cfb522022-12-08 18:09:45 +0800161 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
developer60a3d662023-02-07 15:24:34 +0800171index 77d71e48..2484e25f 100644
developere2cfb522022-12-08 18:09:45 +0800172--- 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;
developeraa5b1b22022-12-13 17:05:25 +0800199@@ -1015,6 +1033,108 @@ mt7915_vendor_phy_capa_ctrl_dump(struct wiphy *wiphy, struct wireless_dev *wdev,
developere2cfb522022-12-08 18:09:45 +0800200 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);
developere2cfb522022-12-08 18:09:45 +0800269+ struct nlattr *tb[NUM_MTK_VENDOR_ATTRS_EDCCA_CTRL];
developere2cfb522022-12-08 18:09:45 +0800270+ int len = EDCCA_THRES_NUM;
271+ int err;
272+ u8 edcca_mode;
273+ s8 value[EDCCA_THRES_NUM];
274+
275+ if (*storage == 1)
276+ return -ENOENT;
277+ *storage = 1;
278+
279+ err = nla_parse(tb, MTK_VENDOR_ATTR_EDCCA_CTRL_MAX, data, data_len,
280+ edcca_ctrl_policy, NULL);
281+ if (err)
282+ return err;
283+
284+ if (!tb[MTK_VENDOR_ATTR_EDCCA_CTRL_MODE])
285+ return -EINVAL;
286+
287+ edcca_mode = nla_get_u8(tb[MTK_VENDOR_ATTR_EDCCA_CTRL_MODE]);
288+ if (edcca_mode == EDCCA_CTRL_GET_EN || edcca_mode == EDCCA_CTRL_GET_THERS) {
289+ err = mt7915_mcu_get_edcca(phy, edcca_mode, value);
290+ } else {
291+ return -EINVAL;
292+ }
293+
294+ if (err)
295+ return err;
296+
297+ if (nla_put_u8(skb, MTK_VENDOR_ATTR_EDCCA_DUMP_PRI20_VAL, value[0]) ||
298+ nla_put_u8(skb, MTK_VENDOR_ATTR_EDCCA_DUMP_SEC40_VAL, value[1]) ||
299+ nla_put_u8(skb, MTK_VENDOR_ATTR_EDCCA_DUMP_SEC80_VAL, value[2]))
300+ return -ENOMEM;
301+
302+ return len;
303+}
304+
305 static const struct wiphy_vendor_command mt7915_vendor_commands[] = {
306 {
307 .info = {
developeraa5b1b22022-12-13 17:05:25 +0800308@@ -1083,6 +1203,18 @@ static const struct wiphy_vendor_command mt7915_vendor_commands[] = {
developere2cfb522022-12-08 18:09:45 +0800309 .dumpit = mt7915_vendor_phy_capa_ctrl_dump,
310 .policy = phy_capa_ctrl_policy,
311 .maxattr = MTK_VENDOR_ATTR_PHY_CAPA_CTRL_MAX,
312+ },
313+ {
314+ .info = {
315+ .vendor_id = MTK_NL80211_VENDOR_ID,
316+ .subcmd = MTK_NL80211_VENDOR_SUBCMD_EDCCA_CTRL,
317+ },
318+ .flags = WIPHY_VENDOR_CMD_NEED_NETDEV |
319+ WIPHY_VENDOR_CMD_NEED_RUNNING,
320+ .doit = mt7915_vendor_edcca_ctrl,
321+ .dumpit = mt7915_vendor_edcca_ctrl_dump,
322+ .policy = edcca_ctrl_policy,
323+ .maxattr = MTK_VENDOR_ATTR_EDCCA_CTRL_MAX,
324 }
325 };
326
327diff --git a/mt7915/vendor.h b/mt7915/vendor.h
developer60a3d662023-02-07 15:24:34 +0800328index 719b851f..72319717 100644
developere2cfb522022-12-08 18:09:45 +0800329--- a/mt7915/vendor.h
330+++ b/mt7915/vendor.h
331@@ -2,6 +2,7 @@
332 #define __MT7915_VENDOR_H
333
334 #define MTK_NL80211_VENDOR_ID 0x0ce7
335+#define EDCCA_THRES_NUM 3
336
337 enum mtk_nl80211_vendor_subcmds {
338 MTK_NL80211_VENDOR_SUBCMD_AMNT_CTRL = 0xae,
339@@ -10,6 +11,38 @@ enum mtk_nl80211_vendor_subcmds {
340 MTK_NL80211_VENDOR_SUBCMD_WIRELESS_CTRL = 0xc4,
341 MTK_NL80211_VENDOR_SUBCMD_HEMU_CTRL = 0xc5,
342 MTK_NL80211_VENDOR_SUBCMD_PHY_CAPA_CTRL = 0xc6,
343+ MTK_NL80211_VENDOR_SUBCMD_EDCCA_CTRL = 0xc7,
344+};
345+
346+
347+enum mtk_vendor_attr_edcca_ctrl {
348+ MTK_VENDOR_ATTR_EDCCA_THRESHOLD_INVALID = 0,
349+
350+ MTK_VENDOR_ATTR_EDCCA_CTRL_MODE,
351+ MTK_VENDOR_ATTR_EDCCA_CTRL_PRI20_VAL,
352+ MTK_VENDOR_ATTR_EDCCA_CTRL_SEC20_VAL,
353+ MTK_VENDOR_ATTR_EDCCA_CTRL_SEC40_VAL,
354+ MTK_VENDOR_ATTR_EDCCA_CTRL_SEC80_VAL,
355+ MTK_VENDOR_ATTR_EDCCA_CTRL_COMPENSATE,
356+
357+ /* keep last */
358+ NUM_MTK_VENDOR_ATTRS_EDCCA_CTRL,
359+ MTK_VENDOR_ATTR_EDCCA_CTRL_MAX =
360+ NUM_MTK_VENDOR_ATTRS_EDCCA_CTRL - 1
361+};
362+
363+enum mtk_vendor_attr_edcca_dump {
364+ MTK_VENDOR_ATTR_EDCCA_DUMP_UNSPEC = 0,
365+
366+ MTK_VENDOR_ATTR_EDCCA_DUMP_MODE,
367+ MTK_VENDOR_ATTR_EDCCA_DUMP_PRI20_VAL,
368+ MTK_VENDOR_ATTR_EDCCA_DUMP_SEC40_VAL,
369+ MTK_VENDOR_ATTR_EDCCA_DUMP_SEC80_VAL,
370+
371+ /* keep last */
372+ NUM_MTK_VENDOR_ATTRS_EDCCA_DUMP,
373+ MTK_VENDOR_ATTR_EDCCA_DUMP_MAX =
374+ NUM_MTK_VENDOR_ATTRS_EDCCA_DUMP - 1
375 };
376
377 enum mtk_capi_control_changed {
378--
developer60a3d662023-02-07 15:24:34 +08003792.18.0
developere2cfb522022-12-08 18:09:45 +0800380