developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 1 | From 516fcbdf41f48d71d814caaffb9e50b88778cd17 Mon Sep 17 00:00:00 2001 |
| 2 | From: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
| 3 | Date: Tue, 30 Aug 2022 15:29:38 +0800 |
| 4 | Subject: [PATCH] mt76: mt7915: add vendor subcmd three wire (PTA) ctrl |
| 5 | |
| 6 | Change-Id: Ie092d63af9a1e06bef36fc5a5bac40fdab73dba5 |
| 7 | Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
| 8 | --- |
| 9 | mt76_connac_mcu.h | 2 +- |
| 10 | mt7915/mcu.c | 51 ++++++++++++++++++++++------------------------- |
| 11 | mt7915/mcu.h | 29 +++++++++++++++++++++++++++ |
| 12 | mt7915/mt7915.h | 1 + |
| 13 | mt7915/vendor.c | 42 +++++++++++++++++++++++++++++++++++++- |
| 14 | mt7915/vendor.h | 12 +++++++++++ |
| 15 | 6 files changed, 108 insertions(+), 29 deletions(-) |
| 16 | |
| 17 | diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h |
| 18 | index 2162a4a..b777d95 100644 |
| 19 | --- a/mt76_connac_mcu.h |
| 20 | +++ b/mt76_connac_mcu.h |
| 21 | @@ -1147,7 +1147,7 @@ enum { |
| 22 | /* 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, |
| 29 | }; |
| 30 | diff --git a/mt7915/mcu.c b/mt7915/mcu.c |
| 31 | index 1f45d1a..6931f2a 100644 |
| 32 | --- a/mt7915/mcu.c |
| 33 | +++ b/mt7915/mcu.c |
| 34 | @@ -4017,37 +4017,34 @@ void mt7915_mcu_set_dynalgo(struct mt7915_phy *phy, u8 enable) |
| 35 | &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 | }; |
| 70 | + struct sk_buff *skb; |
| 71 | + int tlv_len; |
| 72 | + |
| 73 | + switch (cfg_info) { |
| 74 | + case CFGINFO_CERT_CFG: |
| 75 | + tlv_len = sizeof(struct cert_cfg); |
| 76 | + req.cert.tag = cpu_to_le16(cfg_info); |
| 77 | + req.cert.length = cpu_to_le16(tlv_len); |
| 78 | + req.cert.cert_program = type; |
| 79 | + break; |
| 80 | + case CFGINFO_3WIRE_EN_CFG: |
| 81 | + tlv_len = sizeof(struct three_wire_cfg); |
| 82 | + req.three_wire.tag = cpu_to_le16(cfg_info); |
| 83 | + req.three_wire.length = cpu_to_le16(tlv_len); |
| 84 | + req.three_wire.three_wire_en = type; |
| 85 | + break; |
| 86 | + default: |
| 87 | + return -EOPNOTSUPP; |
| 88 | + } |
| 89 | |
| 90 | - mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(CERT_CFG), |
| 91 | - &req, sizeof(req), false); |
| 92 | + return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(SET_CFG), &req, sizeof(req), false); |
| 93 | } |
| 94 | |
| 95 | void mt7915_mcu_set_bypass_smthint(struct mt7915_phy *phy, u8 val) |
| 96 | diff --git a/mt7915/mcu.h b/mt7915/mcu.h |
| 97 | index b8a433e..9d0fac4 100644 |
| 98 | --- a/mt7915/mcu.h |
| 99 | +++ b/mt7915/mcu.h |
| 100 | @@ -576,6 +576,35 @@ struct csi_data { |
| 101 | }; |
| 102 | #endif |
| 103 | |
| 104 | +struct cert_cfg { |
| 105 | + __le16 tag; |
| 106 | + __le16 length; |
| 107 | + u8 cert_program; |
| 108 | + u8 rsv[3]; |
| 109 | +} __packed; |
| 110 | + |
| 111 | +struct three_wire_cfg { |
| 112 | + __le16 tag; |
| 113 | + __le16 length; |
| 114 | + u8 three_wire_en; |
| 115 | + u8 rsv[3]; |
| 116 | +} __packed; |
| 117 | + |
| 118 | +struct cfg_basic_info { |
| 119 | + u8 dbdc_idx; |
| 120 | + u8 rsv[3]; |
| 121 | + __le32 tlv_num; |
| 122 | + union { |
| 123 | + struct cert_cfg cert; |
| 124 | + struct three_wire_cfg three_wire; |
| 125 | + }; |
| 126 | +} __packed; |
| 127 | + |
| 128 | +enum { |
| 129 | + CFGINFO_CERT_CFG = 4, |
| 130 | + CFGINFO_3WIRE_EN_CFG = 10, |
| 131 | +}; |
| 132 | + |
| 133 | /* MURU */ |
| 134 | #define OFDMA_DL BIT(0) |
| 135 | #define OFDMA_UL BIT(1) |
| 136 | diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
| 137 | index 78f0b18..e8ac75e 100644 |
| 138 | --- a/mt7915/mt7915.h |
| 139 | +++ b/mt7915/mt7915.h |
| 140 | @@ -727,6 +727,7 @@ void mt7915_mcu_set_mimo(struct mt7915_phy *phy, u8 direction); |
| 141 | void mt7915_mcu_set_dynalgo(struct mt7915_phy *phy, u8 enable); |
| 142 | int mt7915_mcu_set_mu_edca(struct mt7915_phy *phy, u8 val); |
| 143 | void mt7915_mcu_set_cert(struct mt7915_phy *phy, u8 type); |
| 144 | +int mt7915_mcu_set_cfg(struct mt7915_phy *phy, u8 cfg_info, u8 type); |
| 145 | void mt7915_mcu_set_bypass_smthint(struct mt7915_phy *phy, u8 val); |
| 146 | void mt7915_vendor_register(struct mt7915_phy *phy); |
| 147 | int mt7915_mcu_set_csi(struct mt7915_phy *phy, u8 mode, |
| 148 | diff --git a/mt7915/vendor.c b/mt7915/vendor.c |
| 149 | index 7acb330..7f67c0d 100644 |
| 150 | --- a/mt7915/vendor.c |
| 151 | +++ b/mt7915/vendor.c |
| 152 | @@ -40,6 +40,11 @@ hemu_ctrl_policy[NUM_MTK_VENDOR_ATTRS_HEMU_CTRL] = { |
| 153 | [MTK_VENDOR_ATTR_HEMU_CTRL_DUMP] = {.type = NLA_U8 }, |
| 154 | }; |
| 155 | |
| 156 | +static const struct nla_policy |
| 157 | +three_wire_ctrl_policy[NUM_MTK_VENDOR_ATTRS_3WIRE_CTRL] = { |
| 158 | + [MTK_VENDOR_ATTR_3WIRE_CTRL_MODE] = {.type = NLA_U8 }, |
| 159 | +}; |
| 160 | + |
| 161 | static const struct nla_policy |
| 162 | rfeature_ctrl_policy[NUM_MTK_VENDOR_ATTRS_RFEATURE_CTRL] = { |
| 163 | [MTK_VENDOR_ATTR_RFEATURE_CTRL_HE_GI] = {.type = NLA_U8 }, |
| 164 | @@ -964,7 +969,7 @@ static int mt7915_vendor_wireless_ctrl(struct wiphy *wiphy, |
| 165 | mt7915_set_wireless_vif, &val32); |
| 166 | } else if (tb[MTK_VENDOR_ATTR_WIRELESS_CTRL_CERT]) { |
| 167 | val8 = nla_get_u8(tb[MTK_VENDOR_ATTR_WIRELESS_CTRL_CERT]); |
| 168 | - mt7915_mcu_set_cert(phy, val8); /* Cert Enable for OMI */ |
| 169 | + mt7915_mcu_set_cfg(phy, CFGINFO_CERT_CFG, val8); /* Cert Enable for OMI */ |
| 170 | mt7915_mcu_set_bypass_smthint(phy, val8); /* Cert bypass smooth interpolation */ |
| 171 | } |
| 172 | |
| 173 | @@ -1091,6 +1096,30 @@ static int mt7915_vendor_edcca_ctrl(struct wiphy *wiphy, |
| 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | +static int mt7915_vendor_3wire_ctrl(struct wiphy *wiphy, |
| 178 | + struct wireless_dev *wdev, |
| 179 | + const void *data, |
| 180 | + int data_len) |
| 181 | +{ |
| 182 | + struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); |
| 183 | + struct mt7915_phy *phy = mt7915_hw_phy(hw); |
| 184 | + struct nlattr *tb[NUM_MTK_VENDOR_ATTRS_3WIRE_CTRL]; |
| 185 | + int err; |
| 186 | + u8 three_wire_mode; |
| 187 | + |
| 188 | + err = nla_parse(tb, MTK_VENDOR_ATTR_3WIRE_CTRL_MAX, data, data_len, |
| 189 | + three_wire_ctrl_policy, NULL); |
| 190 | + if (err) |
| 191 | + return err; |
| 192 | + |
| 193 | + if (!tb[MTK_VENDOR_ATTR_3WIRE_CTRL_MODE]) |
| 194 | + return -EINVAL; |
| 195 | + |
| 196 | + three_wire_mode = nla_get_u8(tb[MTK_VENDOR_ATTR_3WIRE_CTRL_MODE]); |
| 197 | + |
| 198 | + return mt7915_mcu_set_cfg(phy, CFGINFO_3WIRE_EN_CFG, three_wire_mode); |
| 199 | +} |
| 200 | + |
| 201 | |
| 202 | static const struct wiphy_vendor_command mt7915_vendor_commands[] = { |
| 203 | { |
| 204 | @@ -1172,6 +1201,17 @@ static const struct wiphy_vendor_command mt7915_vendor_commands[] = { |
| 205 | .doit = mt7915_vendor_edcca_ctrl, |
| 206 | .policy = edcca_ctrl_policy, |
| 207 | .maxattr = MTK_VENDOR_ATTR_EDCCA_CTRL_MAX, |
| 208 | + }, |
| 209 | + { |
| 210 | + .info = { |
| 211 | + .vendor_id = MTK_NL80211_VENDOR_ID, |
| 212 | + .subcmd = MTK_NL80211_VENDOR_SUBCMD_3WIRE_CTRL, |
| 213 | + }, |
| 214 | + .flags = WIPHY_VENDOR_CMD_NEED_NETDEV | |
| 215 | + WIPHY_VENDOR_CMD_NEED_RUNNING, |
| 216 | + .doit = mt7915_vendor_3wire_ctrl, |
| 217 | + .policy = three_wire_ctrl_policy, |
| 218 | + .maxattr = MTK_VENDOR_ATTR_3WIRE_CTRL_MAX, |
| 219 | } |
| 220 | }; |
| 221 | |
| 222 | diff --git a/mt7915/vendor.h b/mt7915/vendor.h |
| 223 | index 57f52f3..e0c5fd9 100644 |
| 224 | --- a/mt7915/vendor.h |
| 225 | +++ b/mt7915/vendor.h |
| 226 | @@ -11,6 +11,7 @@ enum mtk_nl80211_vendor_subcmds { |
| 227 | MTK_NL80211_VENDOR_SUBCMD_HEMU_CTRL = 0xc5, |
| 228 | MTK_NL80211_VENDOR_SUBCMD_PHY_CAPA_CTRL = 0xc6, |
| 229 | MTK_NL80211_VENDOR_SUBCMD_EDCCA_CTRL = 0xc7, |
| 230 | + MTK_NL80211_VENDOR_SUBCMD_3WIRE_CTRL = 0xc8 |
| 231 | }; |
| 232 | |
| 233 | |
| 234 | @@ -30,6 +31,17 @@ enum mtk_vendor_attr_edcca_ctrl { |
| 235 | NUM_MTK_VENDOR_ATTRS_EDCCA_CTRL - 1 |
| 236 | }; |
| 237 | |
| 238 | +enum mtk_vendor_attr_3wire_ctrl { |
| 239 | + MTK_VENDOR_ATTR_3WIRE_CTRL_UNSPEC, |
| 240 | + |
| 241 | + MTK_VENDOR_ATTR_3WIRE_CTRL_MODE, |
| 242 | + |
| 243 | + /* keep last */ |
| 244 | + NUM_MTK_VENDOR_ATTRS_3WIRE_CTRL, |
| 245 | + MTK_VENDOR_ATTR_3WIRE_CTRL_MAX = |
| 246 | + NUM_MTK_VENDOR_ATTRS_3WIRE_CTRL - 1 |
| 247 | +}; |
| 248 | + |
| 249 | |
| 250 | enum mtk_capi_control_changed { |
| 251 | CAPI_RFEATURE_CHANGED = BIT(16), |
| 252 | -- |
| 253 | 2.18.0 |
| 254 | |