blob: 7d42880b376a8e1274d6e12a718ed53547d09ece [file] [log] [blame]
developer9bc8ec12022-11-18 16:01:14 +08001From 5f2097d8515e59239f365b2a9f73e7f6e580149d Mon Sep 17 00:00:00 2001
developer27b55252022-09-05 19:09:45 +08002From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
developerb81e95d2022-11-08 10:16:29 +08003Date: Fri, 28 Oct 2022 10:15:56 +0800
developer9bc8ec12022-11-18 16:01:14 +08004Subject: [PATCH] mt76: mt7915: add vendor subcmd three wire (PTA) ctrl
developer27b55252022-09-05 19:09:45 +08005
developerb81e95d2022-11-08 10:16:29 +08006Change-Id: Ic1044698f294455594a0c6254f55326fdab90580
developer27b55252022-09-05 19:09:45 +08007Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
8---
9 mt76_connac_mcu.h | 2 +-
developer29344f12022-10-17 12:01:44 +080010 mt7915/mcu.c | 50 ++++++++++++++++++++++-------------------------
developer27b55252022-09-05 19:09:45 +080011 mt7915/mcu.h | 29 +++++++++++++++++++++++++++
12 mt7915/mt7915.h | 1 +
developer9bc8ec12022-11-18 16:01:14 +080013 mt7915/vendor.c | 44 ++++++++++++++++++++++++++++++++++++++++-
14 mt7915/vendor.h | 14 +++++++++++++
15 6 files changed, 111 insertions(+), 29 deletions(-)
developer27b55252022-09-05 19:09:45 +080016
17diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
developer2cbf2fb2022-11-16 12:20:48 +080018index bceb6799..86a8688e 100644
developer27b55252022-09-05 19:09:45 +080019--- a/mt76_connac_mcu.h
20+++ b/mt76_connac_mcu.h
developer2cbf2fb2022-11-16 12:20:48 +080021@@ -1162,7 +1162,7 @@ enum {
developer27b55252022-09-05 19:09:45 +080022 /* for vendor csi and air monitor */
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_SET_CFG = 0xb7,
27 MCU_EXT_CMD_EDCCA = 0xba,
28 MCU_EXT_CMD_CSI_CTRL = 0xc2,
developerb81e95d2022-11-08 10:16:29 +080029 MCU_EXT_CMD_IPI_HIST_SCAN = 0xc5,
developer27b55252022-09-05 19:09:45 +080030diff --git a/mt7915/mcu.c b/mt7915/mcu.c
developer9bc8ec12022-11-18 16:01:14 +080031index a6c84c2f..3caa5996 100644
developer27b55252022-09-05 19:09:45 +080032--- a/mt7915/mcu.c
33+++ b/mt7915/mcu.c
developer2cbf2fb2022-11-16 12:20:48 +080034@@ -3964,37 +3964,33 @@ void mt7915_mcu_set_dynalgo(struct mt7915_phy *phy, u8 enable)
developer27b55252022-09-05 19:09:45 +080035 &req, sizeof(req), false);
36 }
37
38-void mt7915_mcu_set_cert(struct mt7915_phy *phy, u8 type)
39+int mt7915_mcu_set_cfg(struct mt7915_phy *phy, u8 cfg_info, u8 type)
40 {
41-#define CFGINFO_CERT_CFG 4
42 struct mt7915_dev *dev = phy->dev;
43- struct {
44- struct basic_info{
45- u8 dbdc_idx;
46- u8 rsv[3];
47- __le32 tlv_num;
48- u8 tlv_buf[0];
49- } hdr;
50- struct cert_cfg{
51- __le16 tag;
52- __le16 length;
53- u8 cert_program;
54- u8 rsv[3];
55- } tlv;
56- } req = {
57- .hdr = {
58- .dbdc_idx = phy != &dev->phy,
59- .tlv_num = cpu_to_le32(1),
60- },
61- .tlv = {
62- .tag = cpu_to_le16(CFGINFO_CERT_CFG),
63- .length = cpu_to_le16(sizeof(struct cert_cfg)),
64- .cert_program = type, /* 1: CAPI Enable */
65- }
66+ struct cfg_basic_info req = {
67+ .dbdc_idx = phy != &dev->phy,
68+ .tlv_num = cpu_to_le32(1),
69 };
developer27b55252022-09-05 19:09:45 +080070+ int tlv_len;
71+
72+ switch (cfg_info) {
73+ case CFGINFO_CERT_CFG:
74+ tlv_len = sizeof(struct cert_cfg);
75+ req.cert.tag = cpu_to_le16(cfg_info);
76+ req.cert.length = cpu_to_le16(tlv_len);
77+ req.cert.cert_program = type;
78+ break;
79+ case CFGINFO_3WIRE_EN_CFG:
80+ tlv_len = sizeof(struct three_wire_cfg);
81+ req.three_wire.tag = cpu_to_le16(cfg_info);
82+ req.three_wire.length = cpu_to_le16(tlv_len);
83+ req.three_wire.three_wire_en = type;
84+ break;
85+ default:
86+ return -EOPNOTSUPP;
87+ }
88
89- mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(CERT_CFG),
90- &req, sizeof(req), false);
91+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(SET_CFG), &req, sizeof(req), false);
92 }
93
94 void mt7915_mcu_set_bypass_smthint(struct mt7915_phy *phy, u8 val)
95diff --git a/mt7915/mcu.h b/mt7915/mcu.h
developer9bc8ec12022-11-18 16:01:14 +080096index b608cb6a..2172d491 100644
developer27b55252022-09-05 19:09:45 +080097--- a/mt7915/mcu.h
98+++ b/mt7915/mcu.h
developer2cbf2fb2022-11-16 12:20:48 +080099@@ -625,6 +625,35 @@ struct mt7915_mcu_rdd_ipi_scan {
developerb81e95d2022-11-08 10:16:29 +0800100 u8 tx_assert_time; /* unit: us */
101 } __packed;
developer27b55252022-09-05 19:09:45 +0800102
103+struct cert_cfg {
104+ __le16 tag;
105+ __le16 length;
106+ u8 cert_program;
107+ u8 rsv[3];
108+} __packed;
109+
110+struct three_wire_cfg {
111+ __le16 tag;
112+ __le16 length;
113+ u8 three_wire_en;
114+ u8 rsv[3];
115+} __packed;
116+
117+struct cfg_basic_info {
118+ u8 dbdc_idx;
119+ u8 rsv[3];
120+ __le32 tlv_num;
121+ union {
122+ struct cert_cfg cert;
123+ struct three_wire_cfg three_wire;
124+ };
125+} __packed;
126+
127+enum {
128+ CFGINFO_CERT_CFG = 4,
129+ CFGINFO_3WIRE_EN_CFG = 10,
130+};
131+
132 /* MURU */
133 #define OFDMA_DL BIT(0)
134 #define OFDMA_UL BIT(1)
135diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developer9bc8ec12022-11-18 16:01:14 +0800136index d979950f..28a2f684 100644
developer27b55252022-09-05 19:09:45 +0800137--- a/mt7915/mt7915.h
138+++ b/mt7915/mt7915.h
developer2cbf2fb2022-11-16 12:20:48 +0800139@@ -749,6 +749,7 @@ void mt7915_mcu_set_mimo(struct mt7915_phy *phy, u8 direction);
developer27b55252022-09-05 19:09:45 +0800140 void mt7915_mcu_set_dynalgo(struct mt7915_phy *phy, u8 enable);
141 int mt7915_mcu_set_mu_edca(struct mt7915_phy *phy, u8 val);
142 void mt7915_mcu_set_cert(struct mt7915_phy *phy, u8 type);
143+int mt7915_mcu_set_cfg(struct mt7915_phy *phy, u8 cfg_info, u8 type);
144 void mt7915_mcu_set_bypass_smthint(struct mt7915_phy *phy, u8 val);
145 void mt7915_vendor_register(struct mt7915_phy *phy);
146 int mt7915_mcu_set_csi(struct mt7915_phy *phy, u8 mode,
147diff --git a/mt7915/vendor.c b/mt7915/vendor.c
developer9bc8ec12022-11-18 16:01:14 +0800148index b95a1582..84e088c9 100644
developer27b55252022-09-05 19:09:45 +0800149--- a/mt7915/vendor.c
150+++ b/mt7915/vendor.c
151@@ -40,6 +40,11 @@ hemu_ctrl_policy[NUM_MTK_VENDOR_ATTRS_HEMU_CTRL] = {
152 [MTK_VENDOR_ATTR_HEMU_CTRL_DUMP] = {.type = NLA_U8 },
153 };
154
155+static const struct nla_policy
156+three_wire_ctrl_policy[NUM_MTK_VENDOR_ATTRS_3WIRE_CTRL] = {
157+ [MTK_VENDOR_ATTR_3WIRE_CTRL_MODE] = {.type = NLA_U8 },
158+};
159+
160 static const struct nla_policy
161 rfeature_ctrl_policy[NUM_MTK_VENDOR_ATTRS_RFEATURE_CTRL] = {
162 [MTK_VENDOR_ATTR_RFEATURE_CTRL_HE_GI] = {.type = NLA_U8 },
developer9bc8ec12022-11-18 16:01:14 +0800163@@ -971,7 +976,7 @@ static int mt7915_vendor_wireless_ctrl(struct wiphy *wiphy,
developer27b55252022-09-05 19:09:45 +0800164 mt7915_set_wireless_vif, &val32);
165 } else if (tb[MTK_VENDOR_ATTR_WIRELESS_CTRL_CERT]) {
166 val8 = nla_get_u8(tb[MTK_VENDOR_ATTR_WIRELESS_CTRL_CERT]);
167- mt7915_mcu_set_cert(phy, val8); /* Cert Enable for OMI */
168+ mt7915_mcu_set_cfg(phy, CFGINFO_CERT_CFG, val8); /* Cert Enable for OMI */
169 mt7915_mcu_set_bypass_smthint(phy, val8); /* Cert bypass smooth interpolation */
170 }
171
developer9bc8ec12022-11-18 16:01:14 +0800172@@ -1117,6 +1122,7 @@ static int mt7915_vendor_edcca_ctrl(struct wiphy *wiphy,
developer27b55252022-09-05 19:09:45 +0800173 return 0;
174 }
175
developer9bc8ec12022-11-18 16:01:14 +0800176+
177 static int
178 mt7915_vendor_edcca_ctrl_dump(struct wiphy *wiphy, struct wireless_dev *wdev,
179 struct sk_buff *skb, const void *data, int data_len,
180@@ -1164,6 +1170,31 @@ mt7915_vendor_edcca_ctrl_dump(struct wiphy *wiphy, struct wireless_dev *wdev,
181 return len;
182 }
183
developer27b55252022-09-05 19:09:45 +0800184+static int mt7915_vendor_3wire_ctrl(struct wiphy *wiphy,
185+ struct wireless_dev *wdev,
186+ const void *data,
187+ int data_len)
188+{
189+ struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
190+ struct mt7915_phy *phy = mt7915_hw_phy(hw);
191+ struct nlattr *tb[NUM_MTK_VENDOR_ATTRS_3WIRE_CTRL];
192+ int err;
193+ u8 three_wire_mode;
194+
195+ err = nla_parse(tb, MTK_VENDOR_ATTR_3WIRE_CTRL_MAX, data, data_len,
196+ three_wire_ctrl_policy, NULL);
197+ if (err)
198+ return err;
199+
200+ if (!tb[MTK_VENDOR_ATTR_3WIRE_CTRL_MODE])
201+ return -EINVAL;
202+
203+ three_wire_mode = nla_get_u8(tb[MTK_VENDOR_ATTR_3WIRE_CTRL_MODE]);
204+
205+ return mt7915_mcu_set_cfg(phy, CFGINFO_3WIRE_EN_CFG, three_wire_mode);
206+}
207+
developer9bc8ec12022-11-18 16:01:14 +0800208+
developer27b55252022-09-05 19:09:45 +0800209 static const struct wiphy_vendor_command mt7915_vendor_commands[] = {
210 {
developer9bc8ec12022-11-18 16:01:14 +0800211 .info = {
212@@ -1245,6 +1276,17 @@ static const struct wiphy_vendor_command mt7915_vendor_commands[] = {
213 .dumpit = mt7915_vendor_edcca_ctrl_dump,
developer27b55252022-09-05 19:09:45 +0800214 .policy = edcca_ctrl_policy,
215 .maxattr = MTK_VENDOR_ATTR_EDCCA_CTRL_MAX,
216+ },
217+ {
218+ .info = {
219+ .vendor_id = MTK_NL80211_VENDOR_ID,
220+ .subcmd = MTK_NL80211_VENDOR_SUBCMD_3WIRE_CTRL,
221+ },
222+ .flags = WIPHY_VENDOR_CMD_NEED_NETDEV |
223+ WIPHY_VENDOR_CMD_NEED_RUNNING,
224+ .doit = mt7915_vendor_3wire_ctrl,
225+ .policy = three_wire_ctrl_policy,
226+ .maxattr = MTK_VENDOR_ATTR_3WIRE_CTRL_MAX,
227 }
228 };
229
230diff --git a/mt7915/vendor.h b/mt7915/vendor.h
developer9bc8ec12022-11-18 16:01:14 +0800231index c19ffe72..d96e5c23 100644
developer27b55252022-09-05 19:09:45 +0800232--- a/mt7915/vendor.h
233+++ b/mt7915/vendor.h
developer9bc8ec12022-11-18 16:01:14 +0800234@@ -12,6 +12,7 @@ enum mtk_nl80211_vendor_subcmds {
developer27b55252022-09-05 19:09:45 +0800235 MTK_NL80211_VENDOR_SUBCMD_HEMU_CTRL = 0xc5,
236 MTK_NL80211_VENDOR_SUBCMD_PHY_CAPA_CTRL = 0xc6,
237 MTK_NL80211_VENDOR_SUBCMD_EDCCA_CTRL = 0xc7,
238+ MTK_NL80211_VENDOR_SUBCMD_3WIRE_CTRL = 0xc8
239 };
240
241
developer9bc8ec12022-11-18 16:01:14 +0800242@@ -31,6 +32,7 @@ enum mtk_vendor_attr_edcca_ctrl {
developer27b55252022-09-05 19:09:45 +0800243 NUM_MTK_VENDOR_ATTRS_EDCCA_CTRL - 1
244 };
245
developer9bc8ec12022-11-18 16:01:14 +0800246+
247 enum mtk_vendor_attr_edcca_dump {
248 MTK_VENDOR_ATTR_EDCCA_DUMP_UNSPEC = 0,
249
250@@ -45,6 +47,18 @@ enum mtk_vendor_attr_edcca_dump {
251 NUM_MTK_VENDOR_ATTRS_EDCCA_DUMP - 1
252 };
253
developer27b55252022-09-05 19:09:45 +0800254+enum mtk_vendor_attr_3wire_ctrl {
255+ MTK_VENDOR_ATTR_3WIRE_CTRL_UNSPEC,
256+
257+ MTK_VENDOR_ATTR_3WIRE_CTRL_MODE,
258+
259+ /* keep last */
260+ NUM_MTK_VENDOR_ATTRS_3WIRE_CTRL,
261+ MTK_VENDOR_ATTR_3WIRE_CTRL_MAX =
262+ NUM_MTK_VENDOR_ATTRS_3WIRE_CTRL - 1
263+};
264+
developer9bc8ec12022-11-18 16:01:14 +0800265+
developer27b55252022-09-05 19:09:45 +0800266 enum mtk_capi_control_changed {
267 CAPI_RFEATURE_CHANGED = BIT(16),
developer9bc8ec12022-11-18 16:01:14 +0800268 CAPI_WIRELESS_CHANGED = BIT(17),
developer27b55252022-09-05 19:09:45 +0800269--
developerb81e95d2022-11-08 10:16:29 +08002702.18.0
developer27b55252022-09-05 19:09:45 +0800271