blob: 7f7995866ef5aeacab99bdc08ee0eafe51c8fc25 [file] [log] [blame]
developer887da632022-10-28 09:35:38 +08001From 50c497714418693f8e2c4e8d90f4f86dbb41aa44 Mon Sep 17 00:00:00 2001
developerbfbd31a2022-06-28 13:53:07 +08002From: Howard Hsu <howard-yh.hsu@mediatek.com>
3Date: Fri, 24 Jun 2022 11:15:45 +0800
developer887da632022-10-28 09:35:38 +08004Subject: [PATCH 1120/1128] mt76: mt7915: add vendor subcmd EDCCA ctrl
developerbfbd31a2022-06-28 13:53:07 +08005
6Change-Id: I92dabf8be9c5a7ecec78f35325bc5645af8d15ab
7---
developer071927d2022-08-31 20:39:29 +08008 mt76_connac_mcu.h | 1 +
9 mt7915/main.c | 3 +++
10 mt7915/mcu.c | 38 ++++++++++++++++++++++++++++
developer887da632022-10-28 09:35:38 +080011 mt7915/mcu.h | 13 ++++++++++
developer071927d2022-08-31 20:39:29 +080012 mt7915/mt7915.h | 2 ++
13 mt7915/vendor.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++
14 mt7915/vendor.h | 19 ++++++++++++++
developer887da632022-10-28 09:35:38 +080015 7 files changed, 139 insertions(+)
developerbfbd31a2022-06-28 13:53:07 +080016
17diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
developer887da632022-10-28 09:35:38 +080018index d7ea781..1738773 100644
developerbfbd31a2022-06-28 13:53:07 +080019--- a/mt76_connac_mcu.h
20+++ b/mt76_connac_mcu.h
developer887da632022-10-28 09:35:38 +080021@@ -1158,6 +1158,7 @@ enum {
developerbfbd31a2022-06-28 13:53:07 +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,
developer887da632022-10-28 09:35:38 +080027 MCU_EXT_CMD_IPI_HIST_SCAN = 0xc5,
developerbfbd31a2022-06-28 13:53:07 +080028 };
developerbfbd31a2022-06-28 13:53:07 +080029diff --git a/mt7915/main.c b/mt7915/main.c
developer887da632022-10-28 09:35:38 +080030index fdbf1ee..80f4d9d 100644
developerbfbd31a2022-06-28 13:53:07 +080031--- a/mt7915/main.c
32+++ b/mt7915/main.c
33@@ -456,6 +456,9 @@ static int mt7915_config(struct ieee80211_hw *hw, u32 changed)
34 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
developer887da632022-10-28 09:35:38 +080044index 8edd155..2c2575e 100644
developerbfbd31a2022-06-28 13:53:07 +080045--- a/mt7915/mcu.c
46+++ b/mt7915/mcu.c
developer887da632022-10-28 09:35:38 +080047@@ -4336,3 +4336,41 @@ int mt7915_mcu_ipi_hist_scan(struct mt7915_phy *phy, void *data, u8 mode, bool w
48
49 return 0;
developerbfbd31a2022-06-28 13:53:07 +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
developer887da632022-10-28 09:35:38 +080090index 14cb04b..481ef4d 100644
developerbfbd31a2022-06-28 13:53:07 +080091--- a/mt7915/mcu.h
92+++ b/mt7915/mcu.h
developer887da632022-10-28 09:35:38 +080093@@ -834,4 +834,17 @@ enum {
94 MURU_DL_INIT,
95 MURU_UL_INIT,
developerbfbd31a2022-06-28 13:53:07 +080096 };
developer887da632022-10-28 09:35:38 +080097+
developerbfbd31a2022-06-28 13:53:07 +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
111diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developer887da632022-10-28 09:35:38 +0800112index b440a34..53773fa 100644
developerbfbd31a2022-06-28 13:53:07 +0800113--- a/mt7915/mt7915.h
114+++ b/mt7915/mt7915.h
developer887da632022-10-28 09:35:38 +0800115@@ -726,6 +726,8 @@ void mt7915_vendor_amnt_fill_rx(struct mt7915_phy *phy, struct sk_buff *skb);
developerbfbd31a2022-06-28 13:53:07 +0800116 int mt7915_vendor_amnt_sta_remove(struct mt7915_phy *phy,
117 struct ieee80211_sta *sta);
118 #endif
119+int mt7915_mcu_set_edcca(struct mt7915_phy *phy, int mode, u8 *value,
120+ s8 compensation);
121
developer887da632022-10-28 09:35:38 +0800122 int mt7915_mcu_ipi_hist_ctrl(struct mt7915_phy *phy, void *data, u8 cmd, bool wait_resp);
123 int mt7915_mcu_ipi_hist_scan(struct mt7915_phy *phy, void *data, u8 mode, bool wait_resp);
developerbfbd31a2022-06-28 13:53:07 +0800124diff --git a/mt7915/vendor.c b/mt7915/vendor.c
developer887da632022-10-28 09:35:38 +0800125index 77d71e4..5a28a55 100644
developerbfbd31a2022-06-28 13:53:07 +0800126--- a/mt7915/vendor.c
127+++ b/mt7915/vendor.c
128@@ -62,6 +62,17 @@ phy_capa_dump_policy[NUM_MTK_VENDOR_ATTRS_PHY_CAPA_DUMP] = {
129 [MTK_VENDOR_ATTR_PHY_CAPA_DUMP_MAX_SUPPORTED_STA] = { .type = NLA_U16 },
130 };
131
132+static const struct nla_policy
133+edcca_ctrl_policy[NUM_MTK_VENDOR_ATTRS_EDCCA_CTRL] = {
134+ [MTK_VENDOR_ATTR_EDCCA_CTRL_MODE] = { .type = NLA_U8 },
135+ [MTK_VENDOR_ATTR_EDCCA_CTRL_PRI20_VAL] = { .type = NLA_U8 },
136+ [MTK_VENDOR_ATTR_EDCCA_CTRL_SEC20_VAL] = { .type = NLA_U8 },
137+ [MTK_VENDOR_ATTR_EDCCA_CTRL_SEC40_VAL] = { .type = NLA_U8 },
138+ [MTK_VENDOR_ATTR_EDCCA_CTRL_SEC80_VAL] = { .type = NLA_U8 },
139+ [MTK_VENDOR_ATTR_EDCCA_CTRL_COMPENSATE] = { .type = NLA_S8 },
140+};
141+
142+
143 struct csi_null_tone {
144 u8 start;
145 u8 end;
146@@ -1015,6 +1026,47 @@ mt7915_vendor_phy_capa_ctrl_dump(struct wiphy *wiphy, struct wireless_dev *wdev,
147 return len;
148 }
149
150+static int mt7915_vendor_edcca_ctrl(struct wiphy *wiphy,
151+ struct wireless_dev *wdev,
152+ const void *data,
153+ int data_len)
154+{
155+ struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
156+ struct mt7915_phy *phy = mt7915_hw_phy(hw);
157+ struct nlattr *tb[NUM_MTK_VENDOR_ATTRS_EDCCA_CTRL];
158+ int err;
159+ u8 edcca_mode;
160+ s8 edcca_compensation;
161+
162+ err = nla_parse(tb, MTK_VENDOR_ATTR_EDCCA_CTRL_MAX, data, data_len,
163+ edcca_ctrl_policy, NULL);
164+ if (err)
165+ return err;
166+
167+ if (!tb[MTK_VENDOR_ATTR_EDCCA_CTRL_MODE])
168+ return -EINVAL;
169+
170+ edcca_mode = nla_get_u8(tb[MTK_VENDOR_ATTR_EDCCA_CTRL_MODE]);
171+ if (edcca_mode == EDCCA_CTRL_SET_EN) {
172+ u8 edcca_value[3] = {0};
173+ if (!tb[MTK_VENDOR_ATTR_EDCCA_CTRL_PRI20_VAL] ||
174+ !tb[MTK_VENDOR_ATTR_EDCCA_CTRL_COMPENSATE]) {
175+ return -EINVAL;
176+ }
177+ edcca_value[0] =
178+ nla_get_u8(tb[MTK_VENDOR_ATTR_EDCCA_CTRL_PRI20_VAL]);
179+ edcca_compensation =
180+ nla_get_s8(tb[MTK_VENDOR_ATTR_EDCCA_CTRL_COMPENSATE]);
181+
182+ err = mt7915_mcu_set_edcca(phy, edcca_mode, edcca_value,
183+ edcca_compensation);
184+ if (err)
185+ return err;
186+ }
187+ return 0;
188+}
189+
190+
191 static const struct wiphy_vendor_command mt7915_vendor_commands[] = {
192 {
193 .info = {
194@@ -1083,6 +1135,17 @@ static const struct wiphy_vendor_command mt7915_vendor_commands[] = {
195 .dumpit = mt7915_vendor_phy_capa_ctrl_dump,
196 .policy = phy_capa_ctrl_policy,
197 .maxattr = MTK_VENDOR_ATTR_PHY_CAPA_CTRL_MAX,
198+ },
199+ {
200+ .info = {
201+ .vendor_id = MTK_NL80211_VENDOR_ID,
202+ .subcmd = MTK_NL80211_VENDOR_SUBCMD_EDCCA_CTRL,
203+ },
204+ .flags = WIPHY_VENDOR_CMD_NEED_NETDEV |
205+ WIPHY_VENDOR_CMD_NEED_RUNNING,
206+ .doit = mt7915_vendor_edcca_ctrl,
207+ .policy = edcca_ctrl_policy,
208+ .maxattr = MTK_VENDOR_ATTR_EDCCA_CTRL_MAX,
209 }
210 };
211
212diff --git a/mt7915/vendor.h b/mt7915/vendor.h
developer887da632022-10-28 09:35:38 +0800213index 719b851..83c41bc 100644
developerbfbd31a2022-06-28 13:53:07 +0800214--- a/mt7915/vendor.h
215+++ b/mt7915/vendor.h
216@@ -10,8 +10,27 @@ enum mtk_nl80211_vendor_subcmds {
217 MTK_NL80211_VENDOR_SUBCMD_WIRELESS_CTRL = 0xc4,
218 MTK_NL80211_VENDOR_SUBCMD_HEMU_CTRL = 0xc5,
219 MTK_NL80211_VENDOR_SUBCMD_PHY_CAPA_CTRL = 0xc6,
220+ MTK_NL80211_VENDOR_SUBCMD_EDCCA_CTRL = 0xc7,
221 };
222
223+
224+enum mtk_vendor_attr_edcca_ctrl {
225+ MTK_VENDOR_ATTR_EDCCA_THRESHOLD_INVALID = 0,
226+
227+ MTK_VENDOR_ATTR_EDCCA_CTRL_MODE,
228+ MTK_VENDOR_ATTR_EDCCA_CTRL_PRI20_VAL,
229+ MTK_VENDOR_ATTR_EDCCA_CTRL_SEC20_VAL,
230+ MTK_VENDOR_ATTR_EDCCA_CTRL_SEC40_VAL,
231+ MTK_VENDOR_ATTR_EDCCA_CTRL_SEC80_VAL,
232+ MTK_VENDOR_ATTR_EDCCA_CTRL_COMPENSATE,
233+
234+ /* keep last */
235+ NUM_MTK_VENDOR_ATTRS_EDCCA_CTRL,
236+ MTK_VENDOR_ATTR_EDCCA_CTRL_MAX =
237+ NUM_MTK_VENDOR_ATTRS_EDCCA_CTRL - 1
238+};
239+
240+
241 enum mtk_capi_control_changed {
242 CAPI_RFEATURE_CHANGED = BIT(16),
243 CAPI_WIRELESS_CHANGED = BIT(17),
244--
developer887da632022-10-28 09:35:38 +08002452.18.0
developerbfbd31a2022-06-28 13:53:07 +0800246