blob: 97002bb2992fd4a9335e3a2a140febf191edb962 [file] [log] [blame]
developer2cbf2fb2022-11-16 12:20:48 +08001From b3325580c9d1f3503582323e0787de7f28d49b58 Mon Sep 17 00:00:00 2001
developer29f66b32022-07-12 15:23:20 +08002From: Howard Hsu <howard-yh.hsu@mediatek.com>
3Date: Fri, 24 Jun 2022 11:15:45 +0800
developerb81e95d2022-11-08 10:16:29 +08004Subject: [PATCH 1120/1128] mt76: mt7915: add vendor subcmd EDCCA ctrl
developer29f66b32022-07-12 15:23:20 +08005
6Change-Id: I92dabf8be9c5a7ecec78f35325bc5645af8d15ab
7---
developer27b55252022-09-05 19:09:45 +08008 mt76_connac_mcu.h | 1 +
9 mt7915/main.c | 3 +++
10 mt7915/mcu.c | 38 ++++++++++++++++++++++++++++
developerb81e95d2022-11-08 10:16:29 +080011 mt7915/mcu.h | 13 ++++++++++
developer27b55252022-09-05 19:09:45 +080012 mt7915/mt7915.h | 2 ++
13 mt7915/vendor.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++
14 mt7915/vendor.h | 19 ++++++++++++++
developerb81e95d2022-11-08 10:16:29 +080015 7 files changed, 139 insertions(+)
developer29f66b32022-07-12 15:23:20 +080016
17diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
developer2cbf2fb2022-11-16 12:20:48 +080018index a31b85f0..bceb6799 100644
developer29f66b32022-07-12 15:23:20 +080019--- a/mt76_connac_mcu.h
20+++ b/mt76_connac_mcu.h
developer2cbf2fb2022-11-16 12:20:48 +080021@@ -1163,6 +1163,7 @@ enum {
developer29f66b32022-07-12 15:23:20 +080022 MCU_EXT_CMD_SMESH_CTRL = 0xae,
23 MCU_EXT_CMD_RX_STAT_USER_CTRL = 0xb3,
24 MCU_EXT_CMD_CERT_CFG = 0xb7,
25+ MCU_EXT_CMD_EDCCA = 0xba,
26 MCU_EXT_CMD_CSI_CTRL = 0xc2,
developerb81e95d2022-11-08 10:16:29 +080027 MCU_EXT_CMD_IPI_HIST_SCAN = 0xc5,
developer29f66b32022-07-12 15:23:20 +080028 };
developer29f66b32022-07-12 15:23:20 +080029diff --git a/mt7915/main.c b/mt7915/main.c
developer2cbf2fb2022-11-16 12:20:48 +080030index 1864f241..2b4e122b 100644
developer29f66b32022-07-12 15:23:20 +080031--- a/mt7915/main.c
32+++ b/mt7915/main.c
developer2cbf2fb2022-11-16 12:20:48 +080033@@ -455,6 +455,9 @@ static int mt7915_config(struct ieee80211_hw *hw, u32 changed)
developer29f66b32022-07-12 15:23:20 +080034 mutex_unlock(&dev->mt76.mutex);
35 }
36 #endif
37+ ret = mt7915_mcu_set_edcca(phy, EDCCA_CTRL_SET_EN, NULL, 0);
38+ if (ret)
39+ return ret;
40 ieee80211_stop_queues(hw);
41 ret = mt7915_set_channel(phy);
42 if (ret)
43diff --git a/mt7915/mcu.c b/mt7915/mcu.c
developer2cbf2fb2022-11-16 12:20:48 +080044index e03ec9e3..8fc40c5a 100644
developer29f66b32022-07-12 15:23:20 +080045--- a/mt7915/mcu.c
46+++ b/mt7915/mcu.c
developer2cbf2fb2022-11-16 12:20:48 +080047@@ -4282,3 +4282,41 @@ int mt7915_mcu_ipi_hist_scan(struct mt7915_phy *phy, void *data, u8 mode, bool w
developerb81e95d2022-11-08 10:16:29 +080048
49 return 0;
developer29f66b32022-07-12 15:23:20 +080050 }
51+
52+int mt7915_mcu_set_edcca(struct mt7915_phy *phy, int mode, u8 *value,
53+ 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+ .region = dev->mt76.region,
74+ .thres_compensation = compensation,
75+ };
76+
77+ if (ch_band[chandef->chan->band] != 2)
78+ return 0;
79+
80+ if (mode == EDCCA_CTRL_SET_EN) {
81+ if (!value)
82+ req.setting[0] = EDCCA_MODE_AUTO;
83+ else
84+ req.setting[0] = value[0];
85+ }
86+
87+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(EDCCA), &req, sizeof(req), true);
88+}
89diff --git a/mt7915/mcu.h b/mt7915/mcu.h
developer2cbf2fb2022-11-16 12:20:48 +080090index 0a79fe04..2ca2c005 100644
developer29f66b32022-07-12 15:23:20 +080091--- a/mt7915/mcu.h
92+++ b/mt7915/mcu.h
developer2cbf2fb2022-11-16 12:20:48 +080093@@ -836,6 +836,19 @@ enum {
developerb81e95d2022-11-08 10:16:29 +080094 MURU_DL_INIT,
95 MURU_UL_INIT,
developer29f66b32022-07-12 15:23:20 +080096 };
developerb81e95d2022-11-08 10:16:29 +080097+
developer29f66b32022-07-12 15:23:20 +080098+enum {
99+ EDCCA_CTRL_SET_EN = 0,
100+ EDCCA_CTRL_SET_THERS,
101+ EDCCA_CTRL_GET_EN,
102+ EDCCA_CTRL_GET_THERS,
103+ EDCCA_CTRL_NUM,
104+};
105+
106+enum {
107+ EDCCA_MODE_FORCE_DISABLE,
108+ EDCCA_MODE_AUTO,
109+};
110 #endif
developer2cbf2fb2022-11-16 12:20:48 +0800111
112 #endif
developer29f66b32022-07-12 15:23:20 +0800113diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developer2cbf2fb2022-11-16 12:20:48 +0800114index 5023cfcb..1cfa6f03 100644
developer29f66b32022-07-12 15:23:20 +0800115--- a/mt7915/mt7915.h
116+++ b/mt7915/mt7915.h
developer2cbf2fb2022-11-16 12:20:48 +0800117@@ -747,6 +747,8 @@ void mt7915_vendor_amnt_fill_rx(struct mt7915_phy *phy, struct sk_buff *skb);
developer29f66b32022-07-12 15:23:20 +0800118 int mt7915_vendor_amnt_sta_remove(struct mt7915_phy *phy,
119 struct ieee80211_sta *sta);
120 #endif
121+int mt7915_mcu_set_edcca(struct mt7915_phy *phy, int mode, u8 *value,
122+ s8 compensation);
123
developerb81e95d2022-11-08 10:16:29 +0800124 int mt7915_mcu_ipi_hist_ctrl(struct mt7915_phy *phy, void *data, u8 cmd, bool wait_resp);
125 int mt7915_mcu_ipi_hist_scan(struct mt7915_phy *phy, void *data, u8 mode, bool wait_resp);
developer29f66b32022-07-12 15:23:20 +0800126diff --git a/mt7915/vendor.c b/mt7915/vendor.c
developer2cbf2fb2022-11-16 12:20:48 +0800127index 77d71e48..5a28a554 100644
developer29f66b32022-07-12 15:23:20 +0800128--- a/mt7915/vendor.c
129+++ b/mt7915/vendor.c
130@@ -62,6 +62,17 @@ phy_capa_dump_policy[NUM_MTK_VENDOR_ATTRS_PHY_CAPA_DUMP] = {
131 [MTK_VENDOR_ATTR_PHY_CAPA_DUMP_MAX_SUPPORTED_STA] = { .type = NLA_U16 },
132 };
133
134+static const struct nla_policy
135+edcca_ctrl_policy[NUM_MTK_VENDOR_ATTRS_EDCCA_CTRL] = {
136+ [MTK_VENDOR_ATTR_EDCCA_CTRL_MODE] = { .type = NLA_U8 },
137+ [MTK_VENDOR_ATTR_EDCCA_CTRL_PRI20_VAL] = { .type = NLA_U8 },
138+ [MTK_VENDOR_ATTR_EDCCA_CTRL_SEC20_VAL] = { .type = NLA_U8 },
139+ [MTK_VENDOR_ATTR_EDCCA_CTRL_SEC40_VAL] = { .type = NLA_U8 },
140+ [MTK_VENDOR_ATTR_EDCCA_CTRL_SEC80_VAL] = { .type = NLA_U8 },
141+ [MTK_VENDOR_ATTR_EDCCA_CTRL_COMPENSATE] = { .type = NLA_S8 },
142+};
143+
144+
145 struct csi_null_tone {
146 u8 start;
147 u8 end;
148@@ -1015,6 +1026,47 @@ mt7915_vendor_phy_capa_ctrl_dump(struct wiphy *wiphy, struct wireless_dev *wdev,
149 return len;
150 }
151
152+static int mt7915_vendor_edcca_ctrl(struct wiphy *wiphy,
153+ struct wireless_dev *wdev,
154+ const void *data,
155+ int data_len)
156+{
157+ struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
158+ struct mt7915_phy *phy = mt7915_hw_phy(hw);
159+ struct nlattr *tb[NUM_MTK_VENDOR_ATTRS_EDCCA_CTRL];
160+ int err;
161+ u8 edcca_mode;
162+ s8 edcca_compensation;
163+
164+ err = nla_parse(tb, MTK_VENDOR_ATTR_EDCCA_CTRL_MAX, data, data_len,
165+ edcca_ctrl_policy, NULL);
166+ if (err)
167+ return err;
168+
169+ if (!tb[MTK_VENDOR_ATTR_EDCCA_CTRL_MODE])
170+ return -EINVAL;
171+
172+ edcca_mode = nla_get_u8(tb[MTK_VENDOR_ATTR_EDCCA_CTRL_MODE]);
173+ if (edcca_mode == EDCCA_CTRL_SET_EN) {
174+ u8 edcca_value[3] = {0};
175+ if (!tb[MTK_VENDOR_ATTR_EDCCA_CTRL_PRI20_VAL] ||
176+ !tb[MTK_VENDOR_ATTR_EDCCA_CTRL_COMPENSATE]) {
177+ return -EINVAL;
178+ }
179+ edcca_value[0] =
180+ nla_get_u8(tb[MTK_VENDOR_ATTR_EDCCA_CTRL_PRI20_VAL]);
181+ edcca_compensation =
182+ nla_get_s8(tb[MTK_VENDOR_ATTR_EDCCA_CTRL_COMPENSATE]);
183+
184+ err = mt7915_mcu_set_edcca(phy, edcca_mode, edcca_value,
185+ edcca_compensation);
186+ if (err)
187+ return err;
188+ }
189+ return 0;
190+}
191+
192+
193 static const struct wiphy_vendor_command mt7915_vendor_commands[] = {
194 {
195 .info = {
196@@ -1083,6 +1135,17 @@ static const struct wiphy_vendor_command mt7915_vendor_commands[] = {
197 .dumpit = mt7915_vendor_phy_capa_ctrl_dump,
198 .policy = phy_capa_ctrl_policy,
199 .maxattr = MTK_VENDOR_ATTR_PHY_CAPA_CTRL_MAX,
200+ },
201+ {
202+ .info = {
203+ .vendor_id = MTK_NL80211_VENDOR_ID,
204+ .subcmd = MTK_NL80211_VENDOR_SUBCMD_EDCCA_CTRL,
205+ },
206+ .flags = WIPHY_VENDOR_CMD_NEED_NETDEV |
207+ WIPHY_VENDOR_CMD_NEED_RUNNING,
208+ .doit = mt7915_vendor_edcca_ctrl,
209+ .policy = edcca_ctrl_policy,
210+ .maxattr = MTK_VENDOR_ATTR_EDCCA_CTRL_MAX,
211 }
212 };
213
214diff --git a/mt7915/vendor.h b/mt7915/vendor.h
developer2cbf2fb2022-11-16 12:20:48 +0800215index 719b851f..83c41bc1 100644
developer29f66b32022-07-12 15:23:20 +0800216--- a/mt7915/vendor.h
217+++ b/mt7915/vendor.h
218@@ -10,8 +10,27 @@ enum mtk_nl80211_vendor_subcmds {
219 MTK_NL80211_VENDOR_SUBCMD_WIRELESS_CTRL = 0xc4,
220 MTK_NL80211_VENDOR_SUBCMD_HEMU_CTRL = 0xc5,
221 MTK_NL80211_VENDOR_SUBCMD_PHY_CAPA_CTRL = 0xc6,
222+ MTK_NL80211_VENDOR_SUBCMD_EDCCA_CTRL = 0xc7,
223 };
224
225+
226+enum mtk_vendor_attr_edcca_ctrl {
227+ MTK_VENDOR_ATTR_EDCCA_THRESHOLD_INVALID = 0,
228+
229+ MTK_VENDOR_ATTR_EDCCA_CTRL_MODE,
230+ MTK_VENDOR_ATTR_EDCCA_CTRL_PRI20_VAL,
231+ MTK_VENDOR_ATTR_EDCCA_CTRL_SEC20_VAL,
232+ MTK_VENDOR_ATTR_EDCCA_CTRL_SEC40_VAL,
233+ MTK_VENDOR_ATTR_EDCCA_CTRL_SEC80_VAL,
234+ MTK_VENDOR_ATTR_EDCCA_CTRL_COMPENSATE,
235+
236+ /* keep last */
237+ NUM_MTK_VENDOR_ATTRS_EDCCA_CTRL,
238+ MTK_VENDOR_ATTR_EDCCA_CTRL_MAX =
239+ NUM_MTK_VENDOR_ATTRS_EDCCA_CTRL - 1
240+};
241+
242+
243 enum mtk_capi_control_changed {
244 CAPI_RFEATURE_CHANGED = BIT(16),
245 CAPI_WIRELESS_CHANGED = BIT(17),
246--
developerb81e95d2022-11-08 10:16:29 +08002472.18.0
developer29f66b32022-07-12 15:23:20 +0800248