developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 1 | From ec2f469639d9c5119fb6f1592df8407f3f45a8fe Mon Sep 17 00:00:00 2001 |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2 | From: Shayne Chen <shayne.chen@mediatek.com> |
| 3 | Date: Thu, 21 Apr 2022 15:43:19 +0800 |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 4 | Subject: [PATCH 1112/1116] mt76: testmode: additional supports |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 5 | |
| 6 | Signed-off-by: Shayne Chen <shayne.chen@mediatek.com> |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 7 | Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 8 | --- |
developer | f7a3ca3 | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 9 | dma.c | 3 +- |
| 10 | mac80211.c | 12 + |
| 11 | mt76.h | 108 ++++- |
| 12 | mt76_connac_mcu.c | 4 + |
| 13 | mt76_connac_mcu.h | 2 + |
| 14 | mt7915/init.c | 2 +- |
developer | 3f78457 | 2023-01-31 15:21:28 +0800 | [diff] [blame] | 15 | mt7915/mac.c | 39 +- |
developer | f7a3ca3 | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 16 | mt7915/main.c | 2 +- |
| 17 | mt7915/mcu.c | 10 +- |
| 18 | mt7915/mcu.h | 28 +- |
| 19 | mt7915/mmio.c | 2 + |
| 20 | mt7915/mt7915.h | 14 +- |
| 21 | mt7915/regs.h | 3 + |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 22 | mt7915/testmode.c | 1177 ++++++++++++++++++++++++++++++++++++++++++--- |
developer | f7a3ca3 | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 23 | mt7915/testmode.h | 278 +++++++++++ |
| 24 | testmode.c | 275 +++++++++-- |
| 25 | testmode.h | 75 +++ |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 26 | tools/fields.c | 80 +++ |
developer | f7a3ca3 | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 27 | tx.c | 3 +- |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 28 | 19 files changed, 1969 insertions(+), 148 deletions(-) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 29 | |
| 30 | diff --git a/dma.c b/dma.c |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 31 | index e3fa4f3..a6bb373 100644 |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 32 | --- a/dma.c |
| 33 | +++ b/dma.c |
developer | 60a3d66 | 2023-02-07 15:24:34 +0800 | [diff] [blame] | 34 | @@ -566,8 +566,7 @@ free: |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 35 | if (mt76_is_testmode_skb(dev, skb, &hw)) { |
| 36 | struct mt76_phy *phy = hw->priv; |
| 37 | |
| 38 | - if (tx_info.skb == phy->test.tx_skb) |
| 39 | - phy->test.tx_done--; |
| 40 | + phy->test.tx_done--; |
| 41 | } |
| 42 | #endif |
| 43 | |
| 44 | diff --git a/mac80211.c b/mac80211.c |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 45 | index 00e7b4f..2a66b1d 100644 |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 46 | --- a/mac80211.c |
| 47 | +++ b/mac80211.c |
developer | 60a3d66 | 2023-02-07 15:24:34 +0800 | [diff] [blame] | 48 | @@ -56,6 +56,13 @@ static const struct ieee80211_channel mt76_channels_5ghz[] = { |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 49 | CHAN5G(60, 5300), |
| 50 | CHAN5G(64, 5320), |
| 51 | |
| 52 | + CHAN5G(68, 5340), |
| 53 | + CHAN5G(80, 5400), |
| 54 | + CHAN5G(84, 5420), |
| 55 | + CHAN5G(88, 5440), |
| 56 | + CHAN5G(92, 5460), |
| 57 | + CHAN5G(96, 5480), |
| 58 | + |
| 59 | CHAN5G(100, 5500), |
| 60 | CHAN5G(104, 5520), |
| 61 | CHAN5G(108, 5540), |
developer | 60a3d66 | 2023-02-07 15:24:34 +0800 | [diff] [blame] | 62 | @@ -76,6 +83,11 @@ static const struct ieee80211_channel mt76_channels_5ghz[] = { |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 63 | CHAN5G(165, 5825), |
| 64 | CHAN5G(169, 5845), |
| 65 | CHAN5G(173, 5865), |
| 66 | + |
| 67 | + CHAN5G(184, 4920), |
| 68 | + CHAN5G(188, 4940), |
| 69 | + CHAN5G(192, 4960), |
| 70 | + CHAN5G(196, 4980), |
| 71 | }; |
| 72 | |
| 73 | static const struct ieee80211_channel mt76_channels_6ghz[] = { |
| 74 | diff --git a/mt76.h b/mt76.h |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 75 | index 25ad0f6..cde5226 100644 |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 76 | --- a/mt76.h |
| 77 | +++ b/mt76.h |
developer | 60a3d66 | 2023-02-07 15:24:34 +0800 | [diff] [blame] | 78 | @@ -641,6 +641,21 @@ struct mt76_testmode_ops { |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 79 | int (*set_params)(struct mt76_phy *phy, struct nlattr **tb, |
| 80 | enum mt76_testmode_state new_state); |
| 81 | int (*dump_stats)(struct mt76_phy *phy, struct sk_buff *msg); |
| 82 | + int (*set_eeprom)(struct mt76_phy *phy, u32 offset, u8 *val, u8 action); |
| 83 | +}; |
| 84 | + |
| 85 | +struct mt76_testmode_entry_data { |
| 86 | + struct sk_buff *tx_skb; |
| 87 | + |
| 88 | + u16 tx_mpdu_len; |
| 89 | + u8 tx_rate_idx; |
| 90 | + u8 tx_rate_nss; |
| 91 | + u8 tx_rate_ldpc; |
| 92 | + |
| 93 | + u8 addr[3][ETH_ALEN]; |
| 94 | + u8 aid; |
| 95 | + u8 ru_alloc; |
| 96 | + u8 ru_idx; |
| 97 | }; |
| 98 | |
| 99 | #define MT_TM_FW_RX_COUNT BIT(0) |
developer | 60a3d66 | 2023-02-07 15:24:34 +0800 | [diff] [blame] | 100 | @@ -649,16 +664,11 @@ struct mt76_testmode_data { |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 101 | enum mt76_testmode_state state; |
| 102 | |
| 103 | u32 param_set[DIV_ROUND_UP(NUM_MT76_TM_ATTRS, 32)]; |
| 104 | - struct sk_buff *tx_skb; |
| 105 | |
| 106 | u32 tx_count; |
| 107 | - u16 tx_mpdu_len; |
| 108 | |
| 109 | u8 tx_rate_mode; |
| 110 | - u8 tx_rate_idx; |
| 111 | - u8 tx_rate_nss; |
| 112 | u8 tx_rate_sgi; |
| 113 | - u8 tx_rate_ldpc; |
| 114 | u8 tx_rate_stbc; |
| 115 | u8 tx_ltf; |
| 116 | |
developer | 60a3d66 | 2023-02-07 15:24:34 +0800 | [diff] [blame] | 117 | @@ -674,10 +684,37 @@ struct mt76_testmode_data { |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 118 | u8 tx_power[4]; |
| 119 | u8 tx_power_control; |
| 120 | |
| 121 | - u8 addr[3][ETH_ALEN]; |
| 122 | + struct list_head tm_entry_list; |
| 123 | + struct mt76_wcid *cur_entry; |
| 124 | + u8 entry_num; |
| 125 | + union { |
| 126 | + struct mt76_testmode_entry_data ed; |
| 127 | + struct { |
| 128 | + /* must be the same as mt76_testmode_entry_data */ |
| 129 | + struct sk_buff *tx_skb; |
| 130 | + |
| 131 | + u16 tx_mpdu_len; |
| 132 | + u8 tx_rate_idx; |
| 133 | + u8 tx_rate_nss; |
| 134 | + u8 tx_rate_ldpc; |
| 135 | + |
| 136 | + u8 addr[3][ETH_ALEN]; |
| 137 | + u8 aid; |
| 138 | + u8 ru_alloc; |
| 139 | + u8 ru_idx; |
| 140 | + }; |
| 141 | + }; |
| 142 | |
| 143 | u8 flag; |
| 144 | |
| 145 | + struct { |
| 146 | + u8 type; |
| 147 | + u8 enable; |
| 148 | + } cfg; |
| 149 | + |
| 150 | + u8 txbf_act; |
| 151 | + u16 txbf_param[8]; |
| 152 | + |
| 153 | u32 tx_pending; |
| 154 | u32 tx_queued; |
| 155 | u16 tx_queued_limit; |
developer | 60a3d66 | 2023-02-07 15:24:34 +0800 | [diff] [blame] | 156 | @@ -1141,6 +1178,59 @@ static inline bool mt76_testmode_enabled(struct mt76_phy *phy) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 157 | #endif |
| 158 | } |
| 159 | |
| 160 | +#ifdef CONFIG_NL80211_TESTMODE |
| 161 | +static inline struct mt76_wcid * |
| 162 | +mt76_testmode_first_entry(struct mt76_phy *phy) |
| 163 | +{ |
| 164 | + if (list_empty(&phy->test.tm_entry_list) && !phy->test.aid) |
| 165 | + return &phy->dev->global_wcid; |
| 166 | + |
| 167 | + return list_first_entry(&phy->test.tm_entry_list, |
| 168 | + typeof(struct mt76_wcid), |
| 169 | + list); |
| 170 | +} |
| 171 | + |
| 172 | +static inline struct mt76_testmode_entry_data * |
| 173 | +mt76_testmode_entry_data(struct mt76_phy *phy, struct mt76_wcid *wcid) |
| 174 | +{ |
| 175 | + if (!wcid) |
| 176 | + return NULL; |
| 177 | + if (wcid == &phy->dev->global_wcid) |
| 178 | + return &phy->test.ed; |
| 179 | + |
| 180 | + return (struct mt76_testmode_entry_data *)((u8 *)wcid + |
| 181 | + phy->hw->sta_data_size); |
| 182 | +} |
| 183 | + |
| 184 | +#define mt76_tm_for_each_entry(phy, wcid, ed) \ |
| 185 | + for (wcid = mt76_testmode_first_entry(phy), \ |
| 186 | + ed = mt76_testmode_entry_data(phy, wcid); \ |
| 187 | + ((phy->test.aid && \ |
| 188 | + !list_entry_is_head(wcid, &phy->test.tm_entry_list, list)) || \ |
| 189 | + (!phy->test.aid && wcid == &phy->dev->global_wcid)) && ed; \ |
| 190 | + wcid = list_next_entry(wcid, list), \ |
| 191 | + ed = mt76_testmode_entry_data(phy, wcid)) |
| 192 | +#endif |
| 193 | + |
| 194 | +static inline bool __mt76_is_testmode_skb(struct mt76_phy *phy, |
| 195 | + struct sk_buff *skb) |
| 196 | +{ |
| 197 | +#ifdef CONFIG_NL80211_TESTMODE |
| 198 | + struct mt76_testmode_entry_data *ed = &phy->test.ed; |
| 199 | + struct mt76_wcid *wcid; |
| 200 | + |
| 201 | + if (skb == ed->tx_skb) |
| 202 | + return true; |
| 203 | + |
| 204 | + mt76_tm_for_each_entry(phy, wcid, ed) |
| 205 | + if (skb == ed->tx_skb) |
| 206 | + return true; |
| 207 | + return false; |
| 208 | +#else |
| 209 | + return false; |
| 210 | +#endif |
| 211 | +} |
| 212 | + |
| 213 | static inline bool mt76_is_testmode_skb(struct mt76_dev *dev, |
| 214 | struct sk_buff *skb, |
| 215 | struct ieee80211_hw **hw) |
developer | 60a3d66 | 2023-02-07 15:24:34 +0800 | [diff] [blame] | 216 | @@ -1151,7 +1241,8 @@ static inline bool mt76_is_testmode_skb(struct mt76_dev *dev, |
developer | f7a3ca3 | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 217 | for (i = 0; i < ARRAY_SIZE(dev->phys); i++) { |
| 218 | struct mt76_phy *phy = dev->phys[i]; |
| 219 | |
| 220 | - if (phy && skb == phy->test.tx_skb) { |
| 221 | + if (phy && mt76_testmode_enabled(phy) && |
| 222 | + __mt76_is_testmode_skb(phy, skb)) { |
| 223 | *hw = dev->phys[i]->hw; |
| 224 | return true; |
| 225 | } |
developer | 60a3d66 | 2023-02-07 15:24:34 +0800 | [diff] [blame] | 226 | @@ -1253,7 +1344,8 @@ int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 227 | int mt76_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *skb, |
| 228 | struct netlink_callback *cb, void *data, int len); |
| 229 | int mt76_testmode_set_state(struct mt76_phy *phy, enum mt76_testmode_state state); |
| 230 | -int mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len); |
| 231 | +int mt76_testmode_init_skb(struct mt76_phy *phy, u32 len, |
| 232 | + struct sk_buff **tx_skb, u8 (*addr)[ETH_ALEN]); |
| 233 | |
| 234 | static inline void mt76_testmode_reset(struct mt76_phy *phy, bool disable) |
| 235 | { |
| 236 | diff --git a/mt76_connac_mcu.c b/mt76_connac_mcu.c |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 237 | index 2fefac6..b6c2ccf 100644 |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 238 | --- a/mt76_connac_mcu.c |
| 239 | +++ b/mt76_connac_mcu.c |
developer | 3609d78 | 2022-11-29 18:07:22 +0800 | [diff] [blame] | 240 | @@ -394,6 +394,7 @@ void mt76_connac_mcu_sta_basic_tlv(struct sk_buff *skb, |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 241 | switch (vif->type) { |
| 242 | case NL80211_IFTYPE_MESH_POINT: |
| 243 | case NL80211_IFTYPE_AP: |
| 244 | + case NL80211_IFTYPE_MONITOR: |
| 245 | if (vif->p2p) |
| 246 | conn_type = CONNECTION_P2P_GC; |
| 247 | else |
developer | 3609d78 | 2022-11-29 18:07:22 +0800 | [diff] [blame] | 248 | @@ -575,6 +576,9 @@ void mt76_connac_mcu_wtbl_generic_tlv(struct mt76_dev *dev, |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 249 | rx->rca2 = 1; |
| 250 | rx->rv = 1; |
| 251 | |
| 252 | + if (vif->type == NL80211_IFTYPE_MONITOR) |
| 253 | + rx->rca1 = 0; |
| 254 | + |
| 255 | if (!is_connac_v1(dev)) |
| 256 | return; |
| 257 | |
| 258 | diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 259 | index 1a14656..f616bce 100644 |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 260 | --- a/mt76_connac_mcu.h |
| 261 | +++ b/mt76_connac_mcu.h |
developer | 60a3d66 | 2023-02-07 15:24:34 +0800 | [diff] [blame] | 262 | @@ -999,6 +999,7 @@ enum { |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 263 | MCU_EXT_EVENT_FW_LOG_2_HOST = 0x13, |
| 264 | MCU_EXT_EVENT_THERMAL_PROTECT = 0x22, |
| 265 | MCU_EXT_EVENT_ASSERT_DUMP = 0x23, |
| 266 | + MCU_EXT_EVENT_BF_STATUS_READ = 0x35, |
| 267 | MCU_EXT_EVENT_RDD_REPORT = 0x3a, |
| 268 | MCU_EXT_EVENT_CSA_NOTIFY = 0x4f, |
| 269 | MCU_EXT_EVENT_BCC_NOTIFY = 0x75, |
developer | 60a3d66 | 2023-02-07 15:24:34 +0800 | [diff] [blame] | 270 | @@ -1200,6 +1201,7 @@ enum { |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 271 | MCU_EXT_CMD_PHY_STAT_INFO = 0xad, |
| 272 | /* for vendor csi and air monitor */ |
| 273 | MCU_EXT_CMD_SMESH_CTRL = 0xae, |
| 274 | + MCU_EXT_CMD_RX_STAT_USER_CTRL = 0xb3, |
| 275 | MCU_EXT_CMD_CERT_CFG = 0xb7, |
| 276 | MCU_EXT_CMD_CSI_CTRL = 0xc2, |
| 277 | }; |
| 278 | diff --git a/mt7915/init.c b/mt7915/init.c |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 279 | index 3897ac4..0a13a83 100644 |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 280 | --- a/mt7915/init.c |
| 281 | +++ b/mt7915/init.c |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 282 | @@ -683,7 +683,7 @@ static void mt7915_init_work(struct work_struct *work) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 283 | struct mt7915_dev *dev = container_of(work, struct mt7915_dev, |
| 284 | init_work); |
| 285 | |
| 286 | - mt7915_mcu_set_eeprom(dev); |
| 287 | + mt7915_mcu_set_eeprom(dev, dev->flash_mode); |
| 288 | mt7915_mac_init(dev); |
| 289 | mt7915_init_txpower(dev, &dev->mphy.sband_2g.sband); |
| 290 | mt7915_init_txpower(dev, &dev->mphy.sband_5g.sband); |
| 291 | diff --git a/mt7915/mac.c b/mt7915/mac.c |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 292 | index de2bdba..1460a32 100644 |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 293 | --- a/mt7915/mac.c |
| 294 | +++ b/mt7915/mac.c |
developer | 60a3d66 | 2023-02-07 15:24:34 +0800 | [diff] [blame] | 295 | @@ -627,16 +627,38 @@ mt7915_mac_write_txwi_tm(struct mt7915_phy *phy, __le32 *txwi, |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 296 | { |
| 297 | #ifdef CONFIG_NL80211_TESTMODE |
| 298 | struct mt76_testmode_data *td = &phy->mt76->test; |
| 299 | + struct mt76_testmode_entry_data *ed; |
| 300 | + struct mt76_wcid *wcid; |
| 301 | const struct ieee80211_rate *r; |
| 302 | - u8 bw, mode, nss = td->tx_rate_nss; |
| 303 | - u8 rate_idx = td->tx_rate_idx; |
| 304 | + u8 bw, mode, nss, rate_idx, ldpc; |
| 305 | u16 rateval = 0; |
| 306 | u32 val; |
| 307 | bool cck = false; |
| 308 | int band; |
| 309 | |
| 310 | - if (skb != phy->mt76->test.tx_skb) |
| 311 | + txwi[3] &= ~cpu_to_le32(MT_TXD3_SN_VALID); |
| 312 | + txwi[7] |= cpu_to_le32(FIELD_PREP(MT_TXD7_SPE_IDX, |
| 313 | + phy->test.spe_idx)); |
| 314 | + |
| 315 | + if (td->tx_rate_mode == MT76_TM_TX_MODE_HE_MU) { |
| 316 | + txwi[1] |= cpu_to_le32(BIT(18)); |
| 317 | + txwi[2] = 0; |
| 318 | + txwi[3] &= ~cpu_to_le32(MT_TXD3_NO_ACK); |
| 319 | + le32p_replace_bits(&txwi[3], 0x1f, MT_TXD3_REM_TX_COUNT); |
| 320 | + |
developer | f7a3ca3 | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 321 | return; |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 322 | + } |
| 323 | + |
| 324 | + mt76_tm_for_each_entry(phy->mt76, wcid, ed) |
| 325 | + if (ed->tx_skb == skb) |
| 326 | + break; |
| 327 | + |
| 328 | + if (!ed) |
developer | f7a3ca3 | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 329 | + return; |
| 330 | + |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 331 | + nss = ed->tx_rate_nss; |
| 332 | + rate_idx = ed->tx_rate_idx; |
| 333 | + ldpc = ed->tx_rate_ldpc; |
developer | f7a3ca3 | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 334 | |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 335 | switch (td->tx_rate_mode) { |
| 336 | case MT76_TM_TX_MODE_HT: |
developer | 60a3d66 | 2023-02-07 15:24:34 +0800 | [diff] [blame] | 337 | @@ -667,7 +689,7 @@ mt7915_mac_write_txwi_tm(struct mt7915_phy *phy, __le32 *txwi, |
developer | 3f78457 | 2023-01-31 15:21:28 +0800 | [diff] [blame] | 338 | rate_idx += 4; |
| 339 | |
| 340 | r = &phy->mt76->hw->wiphy->bands[band]->bitrates[rate_idx]; |
| 341 | - val = cck ? r->hw_value_short : r->hw_value; |
| 342 | + val = r->hw_value; |
| 343 | |
| 344 | mode = val >> 8; |
| 345 | rate_idx = val & 0xff; |
developer | 60a3d66 | 2023-02-07 15:24:34 +0800 | [diff] [blame] | 346 | @@ -726,13 +748,14 @@ mt7915_mac_write_txwi_tm(struct mt7915_phy *phy, __le32 *txwi, |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 347 | if (mode >= MT_PHY_TYPE_HE_SU) |
| 348 | val |= FIELD_PREP(MT_TXD6_HELTF, td->tx_ltf); |
| 349 | |
| 350 | - if (td->tx_rate_ldpc || (bw > 0 && mode >= MT_PHY_TYPE_HE_SU)) |
| 351 | + if (ldpc || (bw > 0 && mode >= MT_PHY_TYPE_HE_SU)) |
| 352 | val |= MT_TXD6_LDPC; |
| 353 | |
developer | f7a3ca3 | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 354 | txwi[3] &= ~cpu_to_le32(MT_TXD3_SN_VALID); |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 355 | + if (phy->test.bf_en) |
| 356 | + val |= MT_TXD6_TX_IBF | MT_TXD6_TX_EBF; |
| 357 | + |
| 358 | txwi[6] |= cpu_to_le32(val); |
| 359 | - txwi[7] |= cpu_to_le32(FIELD_PREP(MT_TXD7_SPE_IDX, |
| 360 | - phy->test.spe_idx)); |
| 361 | #endif |
| 362 | } |
| 363 | |
developer | 60a3d66 | 2023-02-07 15:24:34 +0800 | [diff] [blame] | 364 | @@ -1479,7 +1502,7 @@ mt7915_mac_restart(struct mt7915_dev *dev) |
developer | 047bc18 | 2022-11-16 12:20:48 +0800 | [diff] [blame] | 365 | goto out; |
| 366 | |
| 367 | /* set the necessary init items */ |
| 368 | - ret = mt7915_mcu_set_eeprom(dev); |
| 369 | + ret = mt7915_mcu_set_eeprom(dev, dev->flash_mode); |
| 370 | if (ret) |
| 371 | goto out; |
| 372 | |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 373 | diff --git a/mt7915/main.c b/mt7915/main.c |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 374 | index f0cbfbe..651887c 100644 |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 375 | --- a/mt7915/main.c |
| 376 | +++ b/mt7915/main.c |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 377 | @@ -238,7 +238,7 @@ static int mt7915_add_interface(struct ieee80211_hw *hw, |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 378 | mvif->phy = phy; |
developer | 17bb0a8 | 2022-12-13 15:52:04 +0800 | [diff] [blame] | 379 | mvif->mt76.band_idx = phy->mt76->band_idx; |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 380 | |
| 381 | - mvif->mt76.wmm_idx = vif->type != NL80211_IFTYPE_AP; |
| 382 | + mvif->mt76.wmm_idx = (vif->type != NL80211_IFTYPE_AP && vif->type != NL80211_IFTYPE_MONITOR); |
| 383 | if (ext_phy) |
| 384 | mvif->mt76.wmm_idx += 2; |
| 385 | |
| 386 | diff --git a/mt7915/mcu.c b/mt7915/mcu.c |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 387 | index 62d83bf..0e5ed14 100644 |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 388 | --- a/mt7915/mcu.c |
| 389 | +++ b/mt7915/mcu.c |
developer | 17bb0a8 | 2022-12-13 15:52:04 +0800 | [diff] [blame] | 390 | @@ -383,6 +383,11 @@ mt7915_mcu_rx_ext_event(struct mt7915_dev *dev, struct sk_buff *skb) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 391 | case MCU_EXT_EVENT_BCC_NOTIFY: |
| 392 | mt7915_mcu_rx_bcc_notify(dev, skb); |
| 393 | break; |
| 394 | +#ifdef CONFIG_NL80211_TESTMODE |
| 395 | + case MCU_EXT_EVENT_BF_STATUS_READ: |
| 396 | + mt7915_tm_txbf_status_read(dev, skb); |
| 397 | + break; |
| 398 | +#endif |
| 399 | default: |
| 400 | break; |
| 401 | } |
developer | 17bb0a8 | 2022-12-13 15:52:04 +0800 | [diff] [blame] | 402 | @@ -414,6 +419,7 @@ void mt7915_mcu_rx_event(struct mt7915_dev *dev, struct sk_buff *skb) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 403 | rxd->ext_eid == MCU_EXT_EVENT_ASSERT_DUMP || |
| 404 | rxd->ext_eid == MCU_EXT_EVENT_PS_SYNC || |
| 405 | rxd->ext_eid == MCU_EXT_EVENT_BCC_NOTIFY || |
| 406 | + rxd->ext_eid == MCU_EXT_EVENT_BF_STATUS_READ || |
| 407 | !rxd->seq) |
| 408 | mt7915_mcu_rx_unsolicited_event(dev, skb); |
| 409 | else |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 410 | @@ -2848,14 +2854,14 @@ static int mt7915_mcu_set_eeprom_flash(struct mt7915_dev *dev) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 411 | return 0; |
| 412 | } |
| 413 | |
| 414 | -int mt7915_mcu_set_eeprom(struct mt7915_dev *dev) |
| 415 | +int mt7915_mcu_set_eeprom(struct mt7915_dev *dev, bool flash_mode) |
| 416 | { |
| 417 | struct mt7915_mcu_eeprom req = { |
| 418 | .buffer_mode = EE_MODE_EFUSE, |
| 419 | .format = EE_FORMAT_WHOLE, |
| 420 | }; |
| 421 | |
| 422 | - if (dev->flash_mode) |
| 423 | + if (flash_mode) |
| 424 | return mt7915_mcu_set_eeprom_flash(dev); |
| 425 | |
| 426 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(EFUSE_BUFFER_MODE), |
| 427 | diff --git a/mt7915/mcu.h b/mt7915/mcu.h |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 428 | index a4b7ef8..1671d56 100644 |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 429 | --- a/mt7915/mcu.h |
| 430 | +++ b/mt7915/mcu.h |
developer | 7c3a508 | 2022-06-24 13:40:42 +0800 | [diff] [blame] | 431 | @@ -8,10 +8,15 @@ |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 432 | |
| 433 | enum { |
| 434 | MCU_ATE_SET_TRX = 0x1, |
| 435 | + MCU_ATE_SET_TSSI = 0x5, |
| 436 | + MCU_ATE_SET_DPD = 0x6, |
| 437 | + MCU_ATE_SET_RATE_POWER_OFFSET = 0x7, |
| 438 | + MCU_ATE_SET_THERMAL_COMP = 0x8, |
| 439 | MCU_ATE_SET_FREQ_OFFSET = 0xa, |
| 440 | MCU_ATE_SET_PHY_COUNT = 0x11, |
| 441 | MCU_ATE_SET_SLOT_TIME = 0x13, |
| 442 | MCU_ATE_CLEAN_TXQUEUE = 0x1c, |
| 443 | + MCU_ATE_SET_MU_RX_AID = 0x1e, |
| 444 | }; |
| 445 | |
developer | 7c3a508 | 2022-06-24 13:40:42 +0800 | [diff] [blame] | 446 | struct mt7915_mcu_thermal_ctrl { |
developer | 60a3d66 | 2023-02-07 15:24:34 +0800 | [diff] [blame] | 447 | @@ -472,6 +477,12 @@ enum { |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 448 | |
| 449 | enum { |
| 450 | MT_BF_SOUNDING_ON = 1, |
| 451 | + MT_BF_DATA_PACKET_APPLY = 2, |
| 452 | + MT_BF_PFMU_TAG_READ = 5, |
| 453 | + MT_BF_PFMU_TAG_WRITE = 6, |
| 454 | + MT_BF_PHASE_CAL = 14, |
| 455 | + MT_BF_IBF_PHASE_COMP = 15, |
| 456 | + MT_BF_PROFILE_WRITE_ALL = 17, |
| 457 | MT_BF_TYPE_UPDATE = 20, |
| 458 | MT_BF_MODULE_UPDATE = 25 |
| 459 | }; |
developer | 60a3d66 | 2023-02-07 15:24:34 +0800 | [diff] [blame] | 460 | @@ -718,10 +729,19 @@ struct mt7915_muru { |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 461 | #define MURU_OFDMA_SCH_TYPE_UL BIT(1) |
| 462 | |
developer | 7c3a508 | 2022-06-24 13:40:42 +0800 | [diff] [blame] | 463 | /* Common Config */ |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 464 | -#define MURU_COMM_PPDU_FMT BIT(0) |
| 465 | -#define MURU_COMM_SCH_TYPE BIT(1) |
| 466 | -#define MURU_COMM_SET (MURU_COMM_PPDU_FMT | MURU_COMM_SCH_TYPE) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 467 | -/* DL&UL User config*/ |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 468 | +/* #define MURU_COMM_PPDU_FMT BIT(0) */ |
| 469 | +/* #define MURU_COMM_SCH_TYPE BIT(1) */ |
| 470 | +/* #define MURU_COMM_SET (MURU_COMM_PPDU_FMT | MURU_COMM_SCH_TYPE) */ |
developer | 7c3a508 | 2022-06-24 13:40:42 +0800 | [diff] [blame] | 471 | +#define MURU_COMM_PPDU_FMT BIT(0) |
| 472 | +#define MURU_COMM_SCH_TYPE BIT(1) |
| 473 | +#define MURU_COMM_BAND BIT(2) |
| 474 | +#define MURU_COMM_WMM BIT(3) |
| 475 | +#define MURU_COMM_SPE_IDX BIT(4) |
| 476 | +#define MURU_COMM_PROC_TYPE BIT(5) |
| 477 | +#define MURU_COMM_SET (MURU_COMM_PPDU_FMT | MURU_COMM_BAND | \ |
| 478 | + MURU_COMM_WMM | MURU_COMM_SPE_IDX) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 479 | + |
| 480 | +/* DL&UL User config */ |
| 481 | #define MURU_USER_CNT BIT(4) |
| 482 | |
| 483 | enum { |
| 484 | diff --git a/mt7915/mmio.c b/mt7915/mmio.c |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 485 | index 6d8455d..9a666d0 100644 |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 486 | --- a/mt7915/mmio.c |
| 487 | +++ b/mt7915/mmio.c |
developer | 60a3d66 | 2023-02-07 15:24:34 +0800 | [diff] [blame] | 488 | @@ -134,6 +134,7 @@ static const u32 mt7915_offs[] = { |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 489 | [ARB_DRNGR0] = 0x194, |
| 490 | [ARB_SCR] = 0x080, |
| 491 | [RMAC_MIB_AIRTIME14] = 0x3b8, |
| 492 | + [AGG_AALCR0] = 0x048, |
| 493 | [AGG_AWSCR0] = 0x05c, |
| 494 | [AGG_PCR0] = 0x06c, |
| 495 | [AGG_ACR0] = 0x084, |
developer | 60a3d66 | 2023-02-07 15:24:34 +0800 | [diff] [blame] | 496 | @@ -209,6 +210,7 @@ static const u32 mt7916_offs[] = { |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 497 | [ARB_DRNGR0] = 0x1e0, |
| 498 | [ARB_SCR] = 0x000, |
| 499 | [RMAC_MIB_AIRTIME14] = 0x0398, |
| 500 | + [AGG_AALCR0] = 0x028, |
| 501 | [AGG_AWSCR0] = 0x030, |
| 502 | [AGG_PCR0] = 0x040, |
| 503 | [AGG_ACR0] = 0x054, |
| 504 | diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 505 | index 8b292c3..9d9c5fc 100644 |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 506 | --- a/mt7915/mt7915.h |
| 507 | +++ b/mt7915/mt7915.h |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 508 | @@ -323,6 +323,9 @@ struct mt7915_phy { |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 509 | u8 last_snr; |
| 510 | |
| 511 | u8 spe_idx; |
| 512 | + |
| 513 | + bool bf_en; |
| 514 | + bool bf_ever_en; |
| 515 | } test; |
| 516 | #endif |
| 517 | |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 518 | @@ -422,6 +425,14 @@ struct mt7915_dev { |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 519 | void __iomem *dcm; |
| 520 | void __iomem *sku; |
| 521 | |
| 522 | +#ifdef CONFIG_NL80211_TESTMODE |
| 523 | + struct { |
| 524 | + void *txbf_phase_cal; |
| 525 | + void *txbf_pfmu_data; |
| 526 | + void *txbf_pfmu_tag; |
| 527 | + } test; |
| 528 | +#endif |
| 529 | + |
| 530 | #ifdef MTK_DEBUG |
| 531 | u16 wlan_idx; |
| 532 | struct { |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 533 | @@ -592,7 +603,7 @@ int mt7915_mcu_set_fixed_rate_ctrl(struct mt7915_dev *dev, |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 534 | struct ieee80211_vif *vif, |
| 535 | struct ieee80211_sta *sta, |
| 536 | void *data, u32 field); |
| 537 | -int mt7915_mcu_set_eeprom(struct mt7915_dev *dev); |
| 538 | +int mt7915_mcu_set_eeprom(struct mt7915_dev *dev, bool flash_mode); |
| 539 | int mt7915_mcu_get_eeprom(struct mt7915_dev *dev, u32 offset); |
| 540 | int mt7915_mcu_get_eeprom_free_block(struct mt7915_dev *dev, u8 *block_num); |
| 541 | int mt7915_mcu_set_mac(struct mt7915_dev *dev, int band, bool enable, |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 542 | @@ -630,6 +641,7 @@ int mt7915_mcu_fw_log_2_host(struct mt7915_dev *dev, u8 type, u8 ctrl); |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 543 | int mt7915_mcu_fw_dbg_ctrl(struct mt7915_dev *dev, u32 module, u8 level); |
| 544 | void mt7915_mcu_rx_event(struct mt7915_dev *dev, struct sk_buff *skb); |
| 545 | void mt7915_mcu_exit(struct mt7915_dev *dev); |
| 546 | +int mt7915_tm_txbf_status_read(struct mt7915_dev *dev, struct sk_buff *skb); |
| 547 | |
| 548 | static inline u16 mt7915_wtbl_size(struct mt7915_dev *dev) |
| 549 | { |
| 550 | diff --git a/mt7915/regs.h b/mt7915/regs.h |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 551 | index d6a05f1..e876848 100644 |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 552 | --- a/mt7915/regs.h |
| 553 | +++ b/mt7915/regs.h |
developer | 3609d78 | 2022-11-29 18:07:22 +0800 | [diff] [blame] | 554 | @@ -62,6 +62,7 @@ enum offs_rev { |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 555 | ARB_DRNGR0, |
| 556 | ARB_SCR, |
| 557 | RMAC_MIB_AIRTIME14, |
| 558 | + AGG_AALCR0, |
| 559 | AGG_AWSCR0, |
| 560 | AGG_PCR0, |
| 561 | AGG_ACR0, |
developer | 3609d78 | 2022-11-29 18:07:22 +0800 | [diff] [blame] | 562 | @@ -482,6 +483,8 @@ enum offs_rev { |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 563 | #define MT_WF_AGG_BASE(_band) ((_band) ? 0x820f2000 : 0x820e2000) |
| 564 | #define MT_WF_AGG(_band, ofs) (MT_WF_AGG_BASE(_band) + (ofs)) |
| 565 | |
| 566 | +#define MT_AGG_AALCR0(_band, _n) MT_WF_AGG(_band, (__OFFS(AGG_AALCR0) + \ |
| 567 | + (_n) * 4)) |
| 568 | #define MT_AGG_AWSCR0(_band, _n) MT_WF_AGG(_band, (__OFFS(AGG_AWSCR0) + \ |
| 569 | (_n) * 4)) |
| 570 | #define MT_AGG_PCR0(_band, _n) MT_WF_AGG(_band, (__OFFS(AGG_PCR0) + \ |
| 571 | diff --git a/mt7915/testmode.c b/mt7915/testmode.c |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 572 | index 4693919..9317a8e 100644 |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 573 | --- a/mt7915/testmode.c |
| 574 | +++ b/mt7915/testmode.c |
| 575 | @@ -9,6 +9,9 @@ |
| 576 | enum { |
| 577 | TM_CHANGED_TXPOWER, |
| 578 | TM_CHANGED_FREQ_OFFSET, |
| 579 | + TM_CHANGED_AID, |
| 580 | + TM_CHANGED_CFG, |
| 581 | + TM_CHANGED_TXBF_ACT, |
| 582 | |
| 583 | /* must be last */ |
| 584 | NUM_TM_CHANGED |
| 585 | @@ -17,6 +20,9 @@ enum { |
| 586 | static const u8 tm_change_map[] = { |
| 587 | [TM_CHANGED_TXPOWER] = MT76_TM_ATTR_TX_POWER, |
| 588 | [TM_CHANGED_FREQ_OFFSET] = MT76_TM_ATTR_FREQ_OFFSET, |
| 589 | + [TM_CHANGED_AID] = MT76_TM_ATTR_AID, |
| 590 | + [TM_CHANGED_CFG] = MT76_TM_ATTR_CFG, |
| 591 | + [TM_CHANGED_TXBF_ACT] = MT76_TM_ATTR_TXBF_ACT, |
| 592 | }; |
| 593 | |
| 594 | struct reg_band { |
| 595 | @@ -33,6 +39,38 @@ struct reg_band { |
| 596 | #define TM_REG_MAX_ID 20 |
| 597 | static struct reg_band reg_backup_list[TM_REG_MAX_ID]; |
| 598 | |
| 599 | +static void mt7915_tm_update_entry(struct mt7915_phy *phy); |
| 600 | + |
| 601 | +static u8 mt7915_tm_chan_bw(enum nl80211_chan_width width) |
| 602 | +{ |
| 603 | + static const u8 width_to_bw[] = { |
| 604 | + [NL80211_CHAN_WIDTH_40] = TM_CBW_40MHZ, |
| 605 | + [NL80211_CHAN_WIDTH_80] = TM_CBW_80MHZ, |
| 606 | + [NL80211_CHAN_WIDTH_80P80] = TM_CBW_8080MHZ, |
| 607 | + [NL80211_CHAN_WIDTH_160] = TM_CBW_160MHZ, |
| 608 | + [NL80211_CHAN_WIDTH_5] = TM_CBW_5MHZ, |
| 609 | + [NL80211_CHAN_WIDTH_10] = TM_CBW_10MHZ, |
| 610 | + [NL80211_CHAN_WIDTH_20] = TM_CBW_20MHZ, |
| 611 | + [NL80211_CHAN_WIDTH_20_NOHT] = TM_CBW_20MHZ, |
| 612 | + }; |
| 613 | + |
| 614 | + if (width >= ARRAY_SIZE(width_to_bw)) |
| 615 | + return 0; |
| 616 | + |
| 617 | + return width_to_bw[width]; |
| 618 | +} |
| 619 | + |
| 620 | +static void |
| 621 | +mt7915_tm_update_channel(struct mt7915_phy *phy) |
| 622 | +{ |
| 623 | + mutex_unlock(&phy->dev->mt76.mutex); |
| 624 | + mt7915_set_channel(phy); |
| 625 | + mutex_lock(&phy->dev->mt76.mutex); |
| 626 | + |
| 627 | + mt7915_mcu_set_chan_info(phy, MCU_EXT_CMD(SET_RX_PATH)); |
| 628 | + |
| 629 | + mt7915_tm_update_entry(phy); |
| 630 | +} |
| 631 | |
| 632 | static int |
| 633 | mt7915_tm_set_tx_power(struct mt7915_phy *phy) |
| 634 | @@ -119,18 +157,28 @@ mt7915_tm_set_trx(struct mt7915_phy *phy, int type, bool en) |
| 635 | } |
| 636 | |
| 637 | static int |
| 638 | -mt7915_tm_clean_hwq(struct mt7915_phy *phy, u8 wcid) |
| 639 | +mt7915_tm_clean_hwq(struct mt7915_phy *phy) |
| 640 | { |
| 641 | + struct mt76_testmode_entry_data *ed; |
| 642 | + struct mt76_wcid *wcid; |
| 643 | struct mt7915_dev *dev = phy->dev; |
| 644 | struct mt7915_tm_cmd req = { |
| 645 | .testmode_en = 1, |
| 646 | .param_idx = MCU_ATE_CLEAN_TXQUEUE, |
| 647 | - .param.clean.wcid = wcid, |
developer | 17bb0a8 | 2022-12-13 15:52:04 +0800 | [diff] [blame] | 648 | .param.clean.band = phy->mt76->band_idx, |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 649 | }; |
| 650 | |
| 651 | - return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(ATE_CTRL), &req, |
| 652 | - sizeof(req), false); |
| 653 | + mt76_tm_for_each_entry(phy->mt76, wcid, ed) { |
| 654 | + int ret; |
| 655 | + |
| 656 | + req.param.clean.wcid = wcid->idx; |
| 657 | + ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(ATE_CTRL), |
| 658 | + &req, sizeof(req), false); |
| 659 | + if (ret) |
| 660 | + return ret; |
| 661 | + } |
| 662 | + |
| 663 | + return 0; |
| 664 | } |
| 665 | |
| 666 | static int |
developer | 17bb0a8 | 2022-12-13 15:52:04 +0800 | [diff] [blame] | 667 | @@ -141,7 +189,7 @@ mt7915_tm_set_phy_count(struct mt7915_phy *phy, u8 control) |
| 668 | .testmode_en = 1, |
| 669 | .param_idx = MCU_ATE_SET_PHY_COUNT, |
| 670 | .param.cfg.enable = control, |
| 671 | - .param.cfg.band = phy != &dev->phy, |
| 672 | + .param.cfg.band = phy->mt76->band_idx, |
| 673 | }; |
| 674 | |
| 675 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(ATE_CTRL), &req, |
developer | 7c3a508 | 2022-06-24 13:40:42 +0800 | [diff] [blame] | 676 | @@ -182,12 +230,738 @@ mt7915_tm_set_tam_arb(struct mt7915_phy *phy, bool enable, bool mu) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 677 | return mt7915_mcu_set_muru_ctrl(dev, MURU_SET_ARB_OP_MODE, op_mode); |
| 678 | } |
| 679 | |
| 680 | +static int |
| 681 | +mt7915_tm_set_cfg(struct mt7915_phy *phy) |
| 682 | +{ |
| 683 | + static const u8 cfg_cmd[] = { |
| 684 | + [MT76_TM_CFG_TSSI] = MCU_ATE_SET_TSSI, |
| 685 | + [MT76_TM_CFG_DPD] = MCU_ATE_SET_DPD, |
| 686 | + [MT76_TM_CFG_RATE_POWER_OFFSET] = MCU_ATE_SET_RATE_POWER_OFFSET, |
| 687 | + [MT76_TM_CFG_THERMAL_COMP] = MCU_ATE_SET_THERMAL_COMP, |
| 688 | + }; |
| 689 | + struct mt76_testmode_data *td = &phy->mt76->test; |
| 690 | + struct mt7915_dev *dev = phy->dev; |
| 691 | + struct mt7915_tm_cmd req = { |
| 692 | + .testmode_en = !(phy->mt76->test.state == MT76_TM_STATE_OFF), |
| 693 | + .param_idx = cfg_cmd[td->cfg.type], |
| 694 | + .param.cfg.enable = td->cfg.enable, |
developer | 17bb0a8 | 2022-12-13 15:52:04 +0800 | [diff] [blame] | 695 | + .param.cfg.band = phy->mt76->band_idx, |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 696 | + }; |
| 697 | + |
| 698 | + return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(ATE_CTRL), &req, |
| 699 | + sizeof(req), false); |
| 700 | +} |
| 701 | + |
| 702 | +static int |
| 703 | +mt7915_tm_add_txbf(struct mt7915_phy *phy, struct ieee80211_vif *vif, |
| 704 | + struct ieee80211_sta *sta, u8 pfmu_idx, u8 nr, |
| 705 | + u8 nc, bool ebf) |
| 706 | +{ |
| 707 | + struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 708 | + struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv; |
| 709 | + struct mt7915_dev *dev = phy->dev; |
| 710 | + struct sk_buff *skb; |
| 711 | + struct sta_rec_bf *bf; |
| 712 | + struct tlv *tlv; |
| 713 | + u8 ndp_rate; |
| 714 | + |
| 715 | + if (nr == 1) |
| 716 | + ndp_rate = 8; |
| 717 | + else if (nr == 2) |
| 718 | + ndp_rate = 16; |
| 719 | + else |
| 720 | + ndp_rate = 24; |
| 721 | + |
| 722 | + skb = mt76_connac_mcu_alloc_sta_req(&dev->mt76, &mvif->mt76, |
| 723 | + &msta->wcid); |
| 724 | + if (IS_ERR(skb)) |
| 725 | + return PTR_ERR(skb); |
| 726 | + |
| 727 | + tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_BF, sizeof(*bf)); |
| 728 | + bf = (struct sta_rec_bf *)tlv; |
| 729 | + |
| 730 | + bf->pfmu = cpu_to_le16(pfmu_idx); |
| 731 | + bf->sounding_phy = 1; |
| 732 | + bf->bf_cap = ebf; |
| 733 | + bf->ncol = nc; |
| 734 | + bf->nrow = nr; |
| 735 | + bf->ndp_rate = ndp_rate; |
| 736 | + bf->ibf_timeout = 0xff; |
| 737 | + bf->tx_mode = MT_PHY_TYPE_HT; |
| 738 | + |
| 739 | + if (ebf) { |
| 740 | + bf->mem[0].row = 0; |
| 741 | + bf->mem[1].row = 1; |
| 742 | + bf->mem[2].row = 2; |
| 743 | + bf->mem[3].row = 3; |
| 744 | + } else { |
| 745 | + bf->mem[0].row = 4; |
| 746 | + bf->mem[1].row = 5; |
| 747 | + bf->mem[2].row = 6; |
| 748 | + bf->mem[3].row = 7; |
| 749 | + } |
| 750 | + |
| 751 | + return mt76_mcu_skb_send_msg(&dev->mt76, skb, |
| 752 | + MCU_EXT_CMD(STA_REC_UPDATE), true); |
| 753 | +} |
| 754 | + |
| 755 | +static int |
| 756 | +mt7915_tm_entry_add(struct mt7915_phy *phy, u8 aid) |
| 757 | +{ |
| 758 | + struct mt76_testmode_data *td = &phy->mt76->test; |
| 759 | + struct mt76_testmode_entry_data *ed; |
| 760 | + struct ieee80211_sband_iftype_data *sdata; |
| 761 | + struct ieee80211_supported_band *sband; |
| 762 | + struct ieee80211_sta *sta; |
| 763 | + struct mt7915_sta *msta; |
| 764 | + int tid, ret; |
| 765 | + |
| 766 | + if (td->entry_num >= MT76_TM_MAX_ENTRY_NUM) |
| 767 | + return -EINVAL; |
| 768 | + |
| 769 | + sta = kzalloc(sizeof(*sta) + phy->mt76->hw->sta_data_size + |
| 770 | + sizeof(*ed), GFP_KERNEL); |
| 771 | + if (!sta) |
| 772 | + return -ENOMEM; |
| 773 | + |
| 774 | + msta = (struct mt7915_sta *)sta->drv_priv; |
| 775 | + ed = mt76_testmode_entry_data(phy->mt76, &msta->wcid); |
| 776 | + memcpy(ed, &td->ed, sizeof(*ed)); |
| 777 | + |
| 778 | + if (phy->mt76->chandef.chan->band == NL80211_BAND_5GHZ) { |
| 779 | + sband = &phy->mt76->sband_5g.sband; |
| 780 | + sdata = phy->iftype[NL80211_BAND_5GHZ]; |
| 781 | + } else if (phy->mt76->chandef.chan->band == NL80211_BAND_6GHZ) { |
| 782 | + sband = &phy->mt76->sband_6g.sband; |
| 783 | + sdata = phy->iftype[NL80211_BAND_6GHZ]; |
| 784 | + } else { |
| 785 | + sband = &phy->mt76->sband_2g.sband; |
| 786 | + sdata = phy->iftype[NL80211_BAND_2GHZ]; |
| 787 | + } |
| 788 | + |
| 789 | + memcpy(sta->addr, ed->addr[0], ETH_ALEN); |
| 790 | + if (phy->test.bf_en) { |
| 791 | + u8 addr[ETH_ALEN] = {0x00, 0x11, 0x11, 0x11, 0x11, 0x11}; |
| 792 | + |
| 793 | + memcpy(sta->addr, addr, ETH_ALEN); |
| 794 | + } |
| 795 | + |
| 796 | + if (td->tx_rate_mode >= MT76_TM_TX_MODE_HT) |
developer | 17bb0a8 | 2022-12-13 15:52:04 +0800 | [diff] [blame] | 797 | + memcpy(&sta->deflink.ht_cap, &sband->ht_cap, sizeof(sta->deflink.ht_cap)); |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 798 | + if (td->tx_rate_mode >= MT76_TM_TX_MODE_VHT) |
developer | 17bb0a8 | 2022-12-13 15:52:04 +0800 | [diff] [blame] | 799 | + memcpy(&sta->deflink.vht_cap, &sband->vht_cap, sizeof(sta->deflink.vht_cap)); |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 800 | + if (td->tx_rate_mode >= MT76_TM_TX_MODE_HE_SU) |
developer | 17bb0a8 | 2022-12-13 15:52:04 +0800 | [diff] [blame] | 801 | + memcpy(&sta->deflink.he_cap, &sdata[NL80211_IFTYPE_STATION].he_cap, |
| 802 | + sizeof(sta->deflink.he_cap)); |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 803 | + sta->aid = aid; |
| 804 | + sta->wme = 1; |
| 805 | + |
| 806 | + ret = mt7915_mac_sta_add(&phy->dev->mt76, phy->monitor_vif, sta); |
| 807 | + if (ret) { |
| 808 | + kfree(sta); |
| 809 | + return ret; |
| 810 | + } |
| 811 | + |
| 812 | + /* prevent from starting tx ba session */ |
| 813 | + for (tid = 0; tid < 8; tid++) |
| 814 | + set_bit(tid, &msta->ampdu_state); |
| 815 | + |
| 816 | + list_add_tail(&msta->wcid.list, &td->tm_entry_list); |
| 817 | + td->entry_num++; |
| 818 | + |
| 819 | + return 0; |
| 820 | +} |
| 821 | + |
| 822 | +static void |
| 823 | +mt7915_tm_entry_remove(struct mt7915_phy *phy, u8 aid) |
| 824 | +{ |
| 825 | + struct mt76_testmode_data *td = &phy->mt76->test; |
| 826 | + struct mt76_wcid *wcid, *tmp; |
| 827 | + |
| 828 | + if (list_empty(&td->tm_entry_list)) |
| 829 | + return; |
| 830 | + |
| 831 | + list_for_each_entry_safe(wcid, tmp, &td->tm_entry_list, list) { |
| 832 | + struct mt76_testmode_entry_data *ed; |
| 833 | + struct mt7915_dev *dev = phy->dev; |
| 834 | + struct ieee80211_sta *sta; |
| 835 | + |
| 836 | + ed = mt76_testmode_entry_data(phy->mt76, wcid); |
| 837 | + if (aid && ed->aid != aid) |
| 838 | + continue; |
| 839 | + |
| 840 | + sta = wcid_to_sta(wcid); |
| 841 | + mt7915_mac_sta_remove(&dev->mt76, phy->monitor_vif, sta); |
| 842 | + mt76_wcid_mask_clear(dev->mt76.wcid_mask, wcid->idx); |
| 843 | + |
| 844 | + list_del_init(&wcid->list); |
| 845 | + kfree(sta); |
| 846 | + phy->mt76->test.entry_num--; |
| 847 | + } |
| 848 | +} |
| 849 | + |
| 850 | +static int |
| 851 | +mt7915_tm_set_entry(struct mt7915_phy *phy) |
| 852 | +{ |
| 853 | + struct mt76_testmode_data *td = &phy->mt76->test; |
| 854 | + struct mt76_testmode_entry_data *ed; |
| 855 | + struct mt76_wcid *wcid; |
| 856 | + |
| 857 | + if (!td->aid) { |
| 858 | + if (td->state > MT76_TM_STATE_IDLE) |
| 859 | + mt76_testmode_set_state(phy->mt76, MT76_TM_STATE_IDLE); |
| 860 | + mt7915_tm_entry_remove(phy, td->aid); |
| 861 | + return 0; |
| 862 | + } |
| 863 | + |
| 864 | + mt76_tm_for_each_entry(phy->mt76, wcid, ed) { |
| 865 | + if (ed->aid == td->aid) { |
| 866 | + struct sk_buff *skb; |
| 867 | + |
| 868 | + local_bh_disable(); |
| 869 | + skb = ed->tx_skb; |
| 870 | + memcpy(ed, &td->ed, sizeof(*ed)); |
| 871 | + ed->tx_skb = skb; |
| 872 | + local_bh_enable(); |
| 873 | + |
| 874 | + return 0; |
| 875 | + } |
| 876 | + } |
| 877 | + |
| 878 | + return mt7915_tm_entry_add(phy, td->aid); |
| 879 | +} |
| 880 | + |
| 881 | +static void |
| 882 | +mt7915_tm_update_entry(struct mt7915_phy *phy) |
| 883 | +{ |
| 884 | + struct mt76_testmode_data *td = &phy->mt76->test; |
| 885 | + struct mt76_testmode_entry_data *ed, tmp; |
| 886 | + struct mt76_wcid *wcid, *last; |
| 887 | + |
| 888 | + if (!td->aid || phy->test.bf_en) |
| 889 | + return; |
| 890 | + |
| 891 | + memcpy(&tmp, &td->ed, sizeof(tmp)); |
| 892 | + last = list_last_entry(&td->tm_entry_list, |
| 893 | + struct mt76_wcid, list); |
| 894 | + |
| 895 | + mt76_tm_for_each_entry(phy->mt76, wcid, ed) { |
| 896 | + memcpy(&td->ed, ed, sizeof(td->ed)); |
| 897 | + mt7915_tm_entry_remove(phy, td->aid); |
| 898 | + mt7915_tm_entry_add(phy, td->aid); |
| 899 | + if (wcid == last) |
| 900 | + break; |
| 901 | + } |
| 902 | + |
| 903 | + memcpy(&td->ed, &tmp, sizeof(td->ed)); |
| 904 | +} |
| 905 | + |
| 906 | +static int |
| 907 | +mt7915_tm_txbf_init(struct mt7915_phy *phy, u16 *val) |
| 908 | +{ |
| 909 | + struct mt76_testmode_data *td = &phy->mt76->test; |
| 910 | + struct mt7915_dev *dev = phy->dev; |
| 911 | + bool enable = val[0]; |
| 912 | + void *phase_cal, *pfmu_data, *pfmu_tag; |
| 913 | + u8 addr[ETH_ALEN] = {0x00, 0x22, 0x22, 0x22, 0x22, 0x22}; |
| 914 | + |
| 915 | + if (!enable) { |
| 916 | + phy->test.bf_en = 0; |
| 917 | + return 0; |
| 918 | + } |
| 919 | + |
| 920 | + if (!dev->test.txbf_phase_cal) { |
| 921 | + phase_cal = devm_kzalloc(dev->mt76.dev, |
| 922 | + sizeof(struct mt7915_tm_txbf_phase) * |
| 923 | + MAX_PHASE_GROUP_NUM, |
| 924 | + GFP_KERNEL); |
| 925 | + if (!phase_cal) |
| 926 | + return -ENOMEM; |
| 927 | + |
| 928 | + dev->test.txbf_phase_cal = phase_cal; |
| 929 | + } |
| 930 | + |
| 931 | + if (!dev->test.txbf_pfmu_data) { |
| 932 | + pfmu_data = devm_kzalloc(dev->mt76.dev, 512, GFP_KERNEL); |
| 933 | + if (!pfmu_data) |
| 934 | + return -ENOMEM; |
| 935 | + |
| 936 | + dev->test.txbf_pfmu_data = pfmu_data; |
| 937 | + } |
| 938 | + |
| 939 | + if (!dev->test.txbf_pfmu_tag) { |
| 940 | + pfmu_tag = devm_kzalloc(dev->mt76.dev, |
| 941 | + sizeof(struct mt7915_tm_pfmu_tag), GFP_KERNEL); |
| 942 | + if (!pfmu_tag) |
| 943 | + return -ENOMEM; |
| 944 | + |
| 945 | + dev->test.txbf_pfmu_tag = pfmu_tag; |
| 946 | + } |
| 947 | + |
| 948 | + memcpy(phy->monitor_vif->addr, addr, ETH_ALEN); |
| 949 | + mt7915_mcu_add_dev_info(phy, phy->monitor_vif, true); |
| 950 | + |
| 951 | + td->tx_rate_mode = MT76_TM_TX_MODE_HT; |
| 952 | + td->tx_mpdu_len = 1024; |
| 953 | + td->tx_rate_sgi = 0; |
| 954 | + td->tx_ipg = 100; |
| 955 | + phy->test.bf_en = 1; |
| 956 | + |
| 957 | + return mt7915_tm_set_trx(phy, TM_MAC_TX, true); |
| 958 | +} |
| 959 | + |
| 960 | +static int |
| 961 | +mt7915_tm_txbf_phase_comp(struct mt7915_phy *phy, u16 *val) |
| 962 | +{ |
| 963 | + struct mt7915_dev *dev = phy->dev; |
| 964 | + struct { |
| 965 | + u8 category; |
| 966 | + u8 wlan_idx_lo; |
| 967 | + u8 bw; |
| 968 | + u8 jp_band; |
| 969 | + u8 dbdc_idx; |
| 970 | + bool read_from_e2p; |
| 971 | + bool disable; |
| 972 | + u8 wlan_idx_hi; |
| 973 | + u8 buf[40]; |
| 974 | + } __packed req = { |
| 975 | + .category = MT_BF_IBF_PHASE_COMP, |
| 976 | + .bw = val[0], |
| 977 | + .jp_band = (val[2] == 1) ? 1 : 0, |
developer | 17bb0a8 | 2022-12-13 15:52:04 +0800 | [diff] [blame] | 978 | + .dbdc_idx = phy->mt76->band_idx, |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 979 | + .read_from_e2p = val[3], |
| 980 | + .disable = val[4], |
| 981 | + }; |
| 982 | + struct mt7915_tm_txbf_phase *phase = |
| 983 | + (struct mt7915_tm_txbf_phase *)dev->test.txbf_phase_cal; |
| 984 | + |
| 985 | + wait_event_timeout(dev->mt76.tx_wait, phase[val[2]].status != 0, HZ); |
| 986 | + memcpy(req.buf, &phase[val[2]].phase, sizeof(req.buf)); |
| 987 | + |
| 988 | + pr_info("ibf cal process: phase comp info\n"); |
| 989 | + print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 1, |
| 990 | + &req, sizeof(req), 0); |
| 991 | + |
| 992 | + return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(TXBF_ACTION), &req, |
| 993 | + sizeof(req), true); |
| 994 | +} |
| 995 | + |
| 996 | +static int |
| 997 | +mt7915_tm_txbf_profile_tag_read(struct mt7915_phy *phy, u8 pfmu_idx) |
| 998 | +{ |
| 999 | + struct mt7915_dev *dev = phy->dev; |
| 1000 | + struct { |
| 1001 | + u8 format_id; |
| 1002 | + u8 pfmu_idx; |
| 1003 | + bool bfer; |
| 1004 | + u8 dbdc_idx; |
| 1005 | + } __packed req = { |
| 1006 | + .format_id = MT_BF_PFMU_TAG_READ, |
| 1007 | + .pfmu_idx = pfmu_idx, |
| 1008 | + .bfer = 1, |
| 1009 | + .dbdc_idx = phy != &dev->phy, |
| 1010 | + }; |
| 1011 | + struct mt7915_tm_pfmu_tag *tag = phy->dev->test.txbf_pfmu_tag; |
| 1012 | + |
| 1013 | + tag->t1.pfmu_idx = 0; |
| 1014 | + |
| 1015 | + return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(TXBF_ACTION), &req, |
| 1016 | + sizeof(req), true); |
| 1017 | +} |
| 1018 | + |
| 1019 | +static int |
| 1020 | +mt7915_tm_txbf_profile_tag_write(struct mt7915_phy *phy, u8 pfmu_idx, |
| 1021 | + struct mt7915_tm_pfmu_tag *tag) |
| 1022 | +{ |
| 1023 | + struct mt7915_dev *dev = phy->dev; |
| 1024 | + struct { |
| 1025 | + u8 format_id; |
| 1026 | + u8 pfmu_idx; |
| 1027 | + bool bfer; |
| 1028 | + u8 dbdc_idx; |
| 1029 | + u8 buf[64]; |
| 1030 | + } __packed req = { |
| 1031 | + .format_id = MT_BF_PFMU_TAG_WRITE, |
| 1032 | + .pfmu_idx = pfmu_idx, |
| 1033 | + .bfer = 1, |
| 1034 | + .dbdc_idx = phy != &dev->phy, |
| 1035 | + }; |
| 1036 | + |
| 1037 | + memcpy(req.buf, tag, sizeof(*tag)); |
| 1038 | + wait_event_timeout(dev->mt76.tx_wait, tag->t1.pfmu_idx != 0, HZ); |
| 1039 | + |
| 1040 | + return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(TXBF_ACTION), &req, |
| 1041 | + sizeof(req), false); |
| 1042 | +} |
| 1043 | + |
| 1044 | +static int |
| 1045 | +mt7915_tm_txbf_apply_tx(struct mt7915_phy *phy, u16 wlan_idx, bool ebf, |
| 1046 | + bool ibf, bool phase_cal) |
| 1047 | +{ |
| 1048 | +#define to_wcid_lo(id) FIELD_GET(GENMASK(7, 0), (u16)id) |
| 1049 | +#define to_wcid_hi(id) FIELD_GET(GENMASK(9, 8), (u16)id) |
| 1050 | + struct mt7915_dev *dev = phy->dev; |
| 1051 | + struct { |
| 1052 | + u8 category; |
| 1053 | + u8 wlan_idx_lo; |
| 1054 | + bool ebf; |
| 1055 | + bool ibf; |
| 1056 | + bool mu_txbf; |
| 1057 | + bool phase_cal; |
| 1058 | + u8 wlan_idx_hi; |
| 1059 | + u8 _rsv; |
| 1060 | + } __packed req = { |
| 1061 | + .category = MT_BF_DATA_PACKET_APPLY, |
| 1062 | + .wlan_idx_lo = to_wcid_lo(wlan_idx), |
| 1063 | + .ebf = ebf, |
| 1064 | + .ibf = ibf, |
| 1065 | + .phase_cal = phase_cal, |
| 1066 | + .wlan_idx_hi = to_wcid_hi(wlan_idx), |
| 1067 | + }; |
| 1068 | + |
| 1069 | + return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(TXBF_ACTION), &req, |
| 1070 | + sizeof(req), false); |
| 1071 | +} |
| 1072 | + |
| 1073 | +static int mt7915_tm_txbf_set_rate(struct mt7915_phy *phy, |
| 1074 | + struct mt76_wcid *wcid) |
| 1075 | +{ |
| 1076 | + struct mt7915_dev *dev = phy->dev; |
| 1077 | + struct mt76_testmode_entry_data *ed = mt76_testmode_entry_data(phy->mt76, wcid); |
| 1078 | + struct ieee80211_sta *sta = wcid_to_sta(wcid); |
| 1079 | + struct sta_phy rate = {}; |
| 1080 | + |
| 1081 | + if (!sta) |
| 1082 | + return 0; |
| 1083 | + |
| 1084 | + rate.type = MT_PHY_TYPE_HT; |
| 1085 | + rate.bw = mt7915_tm_chan_bw(phy->mt76->chandef.width); |
| 1086 | + rate.nss = ed->tx_rate_nss; |
| 1087 | + rate.mcs = ed->tx_rate_idx; |
| 1088 | + rate.ldpc = (rate.bw || ed->tx_rate_ldpc) * GENMASK(2, 0); |
| 1089 | + |
| 1090 | + return mt7915_mcu_set_fixed_rate_ctrl(dev, phy->monitor_vif, sta, |
| 1091 | + &rate, RATE_PARAM_FIXED); |
| 1092 | +} |
| 1093 | + |
| 1094 | +static int |
| 1095 | +mt7915_tm_txbf_set_tx(struct mt7915_phy *phy, u16 *val) |
| 1096 | +{ |
| 1097 | + bool bf_on = val[0], update = val[3]; |
| 1098 | + /* u16 wlan_idx = val[2]; */ |
| 1099 | + struct mt7915_tm_pfmu_tag *tag = phy->dev->test.txbf_pfmu_tag; |
| 1100 | + struct mt76_testmode_data *td = &phy->mt76->test; |
| 1101 | + struct mt76_wcid *wcid; |
| 1102 | + |
| 1103 | + if (bf_on) { |
| 1104 | + mt7915_tm_set_trx(phy, TM_MAC_RX_RXV, false); |
| 1105 | + mt7915_tm_txbf_profile_tag_read(phy, 2); |
| 1106 | + tag->t1.invalid_prof = false; |
| 1107 | + mt7915_tm_txbf_profile_tag_write(phy, 2, tag); |
| 1108 | + |
| 1109 | + phy->test.bf_ever_en = true; |
| 1110 | + |
| 1111 | + if (update) |
| 1112 | + mt7915_tm_txbf_apply_tx(phy, 1, 0, 1, 1); |
| 1113 | + } else { |
| 1114 | + if (!phy->test.bf_ever_en) { |
| 1115 | + if (update) |
| 1116 | + mt7915_tm_txbf_apply_tx(phy, 1, 0, 0, 0); |
| 1117 | + } else { |
| 1118 | + phy->test.bf_ever_en = false; |
| 1119 | + |
| 1120 | + mt7915_tm_txbf_profile_tag_read(phy, 2); |
| 1121 | + tag->t1.invalid_prof = true; |
| 1122 | + mt7915_tm_txbf_profile_tag_write(phy, 2, tag); |
| 1123 | + } |
| 1124 | + } |
| 1125 | + |
| 1126 | + wcid = list_first_entry(&td->tm_entry_list, struct mt76_wcid, list); |
| 1127 | + mt7915_tm_txbf_set_rate(phy, wcid); |
| 1128 | + |
| 1129 | + return 0; |
| 1130 | +} |
| 1131 | + |
| 1132 | +static int |
| 1133 | +mt7915_tm_txbf_profile_update(struct mt7915_phy *phy, u16 *val, bool ebf) |
| 1134 | +{ |
| 1135 | + static const u8 mode_to_lm[] = { |
| 1136 | + [MT76_TM_TX_MODE_CCK] = 0, |
| 1137 | + [MT76_TM_TX_MODE_OFDM] = 0, |
| 1138 | + [MT76_TM_TX_MODE_HT] = 1, |
| 1139 | + [MT76_TM_TX_MODE_VHT] = 2, |
| 1140 | + [MT76_TM_TX_MODE_HE_SU] = 3, |
| 1141 | + [MT76_TM_TX_MODE_HE_EXT_SU] = 3, |
| 1142 | + [MT76_TM_TX_MODE_HE_TB] = 3, |
| 1143 | + [MT76_TM_TX_MODE_HE_MU] = 3, |
| 1144 | + }; |
| 1145 | + struct mt76_testmode_data *td = &phy->mt76->test; |
| 1146 | + struct mt76_wcid *wcid; |
| 1147 | + struct ieee80211_vif *vif = phy->monitor_vif; |
| 1148 | + struct mt7915_tm_pfmu_tag *tag = phy->dev->test.txbf_pfmu_tag; |
| 1149 | + u8 pfmu_idx = val[0], nc = val[2], nr; |
| 1150 | + int ret; |
| 1151 | + |
| 1152 | + if (td->tx_antenna_mask == 3) |
| 1153 | + nr = 1; |
| 1154 | + else if (td->tx_antenna_mask == 7) |
| 1155 | + nr = 2; |
| 1156 | + else |
| 1157 | + nr = 3; |
| 1158 | + |
| 1159 | + memset(tag, 0, sizeof(*tag)); |
| 1160 | + tag->t1.pfmu_idx = pfmu_idx; |
| 1161 | + tag->t1.ebf = ebf; |
| 1162 | + tag->t1.nr = nr; |
| 1163 | + tag->t1.nc = nc; |
| 1164 | + tag->t1.invalid_prof = true; |
| 1165 | + |
| 1166 | + tag->t1.snr_sts4 = 0xc0; |
| 1167 | + tag->t1.snr_sts5 = 0xff; |
| 1168 | + tag->t1.snr_sts6 = 0xff; |
| 1169 | + tag->t1.snr_sts7 = 0xff; |
| 1170 | + |
| 1171 | + if (ebf) { |
| 1172 | + tag->t1.row_id1 = 0; |
| 1173 | + tag->t1.row_id2 = 1; |
| 1174 | + tag->t1.row_id3 = 2; |
| 1175 | + tag->t1.row_id4 = 3; |
| 1176 | + tag->t1.lm = mode_to_lm[MT76_TM_TX_MODE_HT]; |
| 1177 | + } else { |
| 1178 | + tag->t1.row_id1 = 4; |
| 1179 | + tag->t1.row_id2 = 5; |
| 1180 | + tag->t1.row_id3 = 6; |
| 1181 | + tag->t1.row_id4 = 7; |
| 1182 | + tag->t1.lm = mode_to_lm[MT76_TM_TX_MODE_OFDM]; |
| 1183 | + |
| 1184 | + tag->t2.ibf_timeout = 0xff; |
| 1185 | + tag->t2.ibf_nr = nr; |
| 1186 | + } |
| 1187 | + |
| 1188 | + ret = mt7915_tm_txbf_profile_tag_write(phy, pfmu_idx, tag); |
| 1189 | + if (ret) |
| 1190 | + return ret; |
| 1191 | + |
| 1192 | + wcid = list_first_entry(&td->tm_entry_list, struct mt76_wcid, list); |
| 1193 | + ret = mt7915_tm_add_txbf(phy, vif, wcid_to_sta(wcid), pfmu_idx, nr, nc, ebf); |
| 1194 | + if (ret) |
| 1195 | + return ret; |
| 1196 | + |
| 1197 | + if (!ebf) |
| 1198 | + return mt7915_tm_txbf_apply_tx(phy, 1, false, true, true); |
| 1199 | + |
| 1200 | + return 0; |
| 1201 | +} |
| 1202 | + |
| 1203 | +static int |
| 1204 | +mt7915_tm_txbf_phase_cal(struct mt7915_phy *phy, u16 *val) |
| 1205 | +{ |
| 1206 | +#define GROUP_L 0 |
| 1207 | +#define GROUP_M 1 |
| 1208 | +#define GROUP_H 2 |
| 1209 | + struct mt7915_dev *dev = phy->dev; |
| 1210 | + struct { |
| 1211 | + u8 category; |
| 1212 | + u8 group_l_m_n; |
| 1213 | + u8 group; |
| 1214 | + bool sx2; |
| 1215 | + u8 cal_type; |
| 1216 | + u8 lna_gain_level; |
| 1217 | + u8 _rsv[2]; |
| 1218 | + } __packed req = { |
| 1219 | + .category = MT_BF_PHASE_CAL, |
| 1220 | + .group = val[0], |
| 1221 | + .group_l_m_n = val[1], |
| 1222 | + .sx2 = val[2], |
| 1223 | + .cal_type = val[3], |
| 1224 | + .lna_gain_level = 0, /* for test purpose */ |
| 1225 | + }; |
| 1226 | + struct mt7915_tm_txbf_phase *phase = |
| 1227 | + (struct mt7915_tm_txbf_phase *)dev->test.txbf_phase_cal; |
| 1228 | + |
| 1229 | + phase[req.group].status = 0; |
| 1230 | + |
| 1231 | + return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(TXBF_ACTION), &req, |
| 1232 | + sizeof(req), true); |
| 1233 | +} |
| 1234 | + |
| 1235 | +int mt7915_tm_txbf_status_read(struct mt7915_dev *dev, struct sk_buff *skb) |
| 1236 | +{ |
| 1237 | +#define BF_PFMU_TAG 16 |
| 1238 | +#define BF_CAL_PHASE 21 |
| 1239 | + u8 format_id; |
| 1240 | + |
developer | 7c3a508 | 2022-06-24 13:40:42 +0800 | [diff] [blame] | 1241 | + skb_pull(skb, sizeof(struct mt76_connac2_mcu_rxd)); |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 1242 | + format_id = *(u8 *)skb->data; |
| 1243 | + |
| 1244 | + if (format_id == BF_PFMU_TAG) { |
| 1245 | + struct mt7915_tm_pfmu_tag *tag = dev->test.txbf_pfmu_tag; |
| 1246 | + |
| 1247 | + skb_pull(skb, 8); |
| 1248 | + memcpy(tag, skb->data, sizeof(struct mt7915_tm_pfmu_tag)); |
| 1249 | + } else if (format_id == BF_CAL_PHASE) { |
| 1250 | + struct mt7915_tm_ibf_cal_info *cal; |
| 1251 | + struct mt7915_tm_txbf_phase *phase = |
| 1252 | + (struct mt7915_tm_txbf_phase *)dev->test.txbf_phase_cal; |
| 1253 | + |
| 1254 | + cal = (struct mt7915_tm_ibf_cal_info *)skb->data; |
| 1255 | + switch (cal->cal_type) { |
| 1256 | + case IBF_PHASE_CAL_NORMAL: |
| 1257 | + case IBF_PHASE_CAL_NORMAL_INSTRUMENT: |
| 1258 | + if (cal->group_l_m_n != GROUP_M) |
| 1259 | + break; |
| 1260 | + phase = &phase[cal->group]; |
| 1261 | + memcpy(&phase->phase, cal->buf + 16, sizeof(phase->phase)); |
| 1262 | + phase->status = cal->status; |
| 1263 | + break; |
| 1264 | + case IBF_PHASE_CAL_VERIFY: |
| 1265 | + case IBF_PHASE_CAL_VERIFY_INSTRUMENT: |
| 1266 | + break; |
| 1267 | + default: |
| 1268 | + break; |
| 1269 | + } |
| 1270 | + } |
| 1271 | + |
| 1272 | + wake_up(&dev->mt76.tx_wait); |
| 1273 | + |
| 1274 | + return 0; |
| 1275 | +} |
| 1276 | + |
| 1277 | +static int |
| 1278 | +mt7915_tm_txbf_profile_update_all(struct mt7915_phy *phy, u16 *val) |
| 1279 | +{ |
| 1280 | + struct mt76_testmode_data *td = &phy->mt76->test; |
| 1281 | + u16 pfmu_idx = val[0]; |
| 1282 | + u16 subc_id = val[1]; |
| 1283 | + u16 angle11 = val[2]; |
| 1284 | + u16 angle21 = val[3]; |
| 1285 | + u16 angle31 = val[4]; |
| 1286 | + u16 angle41 = val[5]; |
| 1287 | + s16 phi11 = 0, phi21 = 0, phi31 = 0; |
| 1288 | + struct mt7915_tm_pfmu_data *pfmu_data; |
| 1289 | + |
| 1290 | + if (subc_id > 63) |
| 1291 | + return -EINVAL; |
| 1292 | + |
| 1293 | + if (td->tx_antenna_mask == 2) { |
| 1294 | + phi11 = (s16)(angle21 - angle11); |
| 1295 | + } else if (td->tx_antenna_mask == 3) { |
| 1296 | + phi11 = (s16)(angle31 - angle11); |
| 1297 | + phi21 = (s16)(angle31 - angle21); |
| 1298 | + } else { |
| 1299 | + phi11 = (s16)(angle41 - angle11); |
| 1300 | + phi21 = (s16)(angle41 - angle21); |
| 1301 | + phi31 = (s16)(angle41 - angle31); |
| 1302 | + } |
| 1303 | + |
| 1304 | + pfmu_data = (struct mt7915_tm_pfmu_data *)phy->dev->test.txbf_pfmu_data; |
| 1305 | + pfmu_data = &pfmu_data[subc_id]; |
| 1306 | + |
| 1307 | + if (subc_id < 32) |
| 1308 | + pfmu_data->subc_idx = cpu_to_le16(subc_id + 224); |
| 1309 | + else |
| 1310 | + pfmu_data->subc_idx = cpu_to_le16(subc_id - 32); |
| 1311 | + pfmu_data->phi11 = cpu_to_le16(phi11); |
| 1312 | + pfmu_data->phi21 = cpu_to_le16(phi21); |
| 1313 | + pfmu_data->phi31 = cpu_to_le16(phi31); |
| 1314 | + |
| 1315 | + if (subc_id == 63) { |
| 1316 | + struct mt7915_dev *dev = phy->dev; |
| 1317 | + struct { |
| 1318 | + u8 format_id; |
| 1319 | + u8 pfmu_idx; |
| 1320 | + u8 dbdc_idx; |
| 1321 | + u8 _rsv; |
| 1322 | + u8 buf[512]; |
| 1323 | + } __packed req = { |
| 1324 | + .format_id = MT_BF_PROFILE_WRITE_ALL, |
| 1325 | + .pfmu_idx = pfmu_idx, |
| 1326 | + .dbdc_idx = phy != &dev->phy, |
| 1327 | + }; |
| 1328 | + |
| 1329 | + memcpy(req.buf, dev->test.txbf_pfmu_data, 512); |
| 1330 | + |
| 1331 | + return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(TXBF_ACTION), |
| 1332 | + &req, sizeof(req), true); |
| 1333 | + } |
| 1334 | + |
| 1335 | + return 0; |
| 1336 | +} |
| 1337 | + |
| 1338 | +static int |
| 1339 | +mt7915_tm_txbf_e2p_update(struct mt7915_phy *phy) |
| 1340 | +{ |
| 1341 | + struct mt7915_tm_txbf_phase *phase, *p; |
| 1342 | + struct mt7915_dev *dev = phy->dev; |
| 1343 | + u8 *eeprom = dev->mt76.eeprom.data; |
| 1344 | + u16 offset; |
| 1345 | + bool is_7976; |
| 1346 | + int i; |
| 1347 | + |
| 1348 | + is_7976 = mt7915_check_adie(dev, false) || is_mt7916(&dev->mt76); |
| 1349 | + offset = is_7976 ? 0x60a : 0x651; |
| 1350 | + |
| 1351 | + phase = (struct mt7915_tm_txbf_phase *)dev->test.txbf_phase_cal; |
| 1352 | + for (i = 0; i < MAX_PHASE_GROUP_NUM; i++) { |
| 1353 | + p = &phase[i]; |
| 1354 | + |
| 1355 | + if (!p->status) |
| 1356 | + continue; |
| 1357 | + |
| 1358 | + /* copy phase cal data to eeprom */ |
| 1359 | + memcpy(eeprom + offset + i * sizeof(p->phase), &p->phase, |
| 1360 | + sizeof(p->phase)); |
| 1361 | + } |
| 1362 | + |
| 1363 | + return 0; |
| 1364 | +} |
| 1365 | + |
| 1366 | +static int |
| 1367 | +mt7915_tm_set_txbf(struct mt7915_phy *phy) |
| 1368 | +{ |
| 1369 | + struct mt76_testmode_data *td = &phy->mt76->test; |
| 1370 | + u16 *val = td->txbf_param; |
| 1371 | + |
| 1372 | + pr_info("ibf cal process: act = %u, val = %u, %u, %u, %u, %u\n", |
| 1373 | + td->txbf_act, val[0], val[1], val[2], val[3], val[4]); |
| 1374 | + |
| 1375 | + switch (td->txbf_act) { |
| 1376 | + case MT76_TM_TXBF_ACT_INIT: |
| 1377 | + return mt7915_tm_txbf_init(phy, val); |
| 1378 | + case MT76_TM_TXBF_ACT_UPDATE_CH: |
| 1379 | + mt7915_tm_update_channel(phy); |
| 1380 | + break; |
| 1381 | + case MT76_TM_TXBF_ACT_PHASE_COMP: |
| 1382 | + return mt7915_tm_txbf_phase_comp(phy, val); |
| 1383 | + case MT76_TM_TXBF_ACT_TX_PREP: |
| 1384 | + return mt7915_tm_txbf_set_tx(phy, val); |
| 1385 | + case MT76_TM_TXBF_ACT_IBF_PROF_UPDATE: |
| 1386 | + return mt7915_tm_txbf_profile_update(phy, val, false); |
| 1387 | + case MT76_TM_TXBF_ACT_EBF_PROF_UPDATE: |
| 1388 | + return mt7915_tm_txbf_profile_update(phy, val, true); |
| 1389 | + case MT76_TM_TXBF_ACT_PHASE_CAL: |
| 1390 | + return mt7915_tm_txbf_phase_cal(phy, val); |
| 1391 | + case MT76_TM_TXBF_ACT_PROF_UPDATE_ALL: |
| 1392 | + return mt7915_tm_txbf_profile_update_all(phy, val); |
| 1393 | + case MT76_TM_TXBF_ACT_E2P_UPDATE: |
| 1394 | + return mt7915_tm_txbf_e2p_update(phy); |
| 1395 | + default: |
| 1396 | + break; |
| 1397 | + }; |
| 1398 | + |
| 1399 | + return 0; |
| 1400 | +} |
| 1401 | + |
| 1402 | static int |
developer | 7c3a508 | 2022-06-24 13:40:42 +0800 | [diff] [blame] | 1403 | mt7915_tm_set_wmm_qid(struct mt7915_phy *phy, u8 qid, u8 aifs, u8 cw_min, |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 1404 | - u16 cw_max, u16 txop) |
| 1405 | + u16 cw_max, u16 txop, u8 tx_cmd) |
| 1406 | { |
developer | 7c3a508 | 2022-06-24 13:40:42 +0800 | [diff] [blame] | 1407 | struct mt7915_vif *mvif = (struct mt7915_vif *)phy->monitor_vif->drv_priv; |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 1408 | - struct mt7915_mcu_tx req = { .total = 1 }; |
| 1409 | + struct mt7915_mcu_tx req = { |
| 1410 | + .valid = true, |
| 1411 | + .mode = tx_cmd, |
| 1412 | + .total = 1, |
| 1413 | + }; |
| 1414 | struct edca *e = &req.edca[0]; |
| 1415 | |
developer | 7c3a508 | 2022-06-24 13:40:42 +0800 | [diff] [blame] | 1416 | e->queue = qid + mvif->mt76.wmm_idx * MT76_CONNAC_MAX_WMM_SETS; |
developer | 17bb0a8 | 2022-12-13 15:52:04 +0800 | [diff] [blame] | 1417 | @@ -263,7 +1037,8 @@ done: |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 1418 | |
developer | 7c3a508 | 2022-06-24 13:40:42 +0800 | [diff] [blame] | 1419 | return mt7915_tm_set_wmm_qid(phy, |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 1420 | mt76_connac_lmac_mapping(IEEE80211_AC_BE), |
| 1421 | - aifsn, cw, cw, 0); |
| 1422 | + aifsn, cw, cw, 0, |
| 1423 | + mode == MT76_TM_TX_MODE_HE_MU); |
| 1424 | } |
| 1425 | |
| 1426 | static int |
developer | 17bb0a8 | 2022-12-13 15:52:04 +0800 | [diff] [blame] | 1427 | @@ -339,7 +1114,7 @@ mt7915_tm_set_tx_len(struct mt7915_phy *phy, u32 tx_time) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 1428 | bitrate = cfg80211_calculate_bitrate(&rate); |
| 1429 | tx_len = bitrate * tx_time / 10 / 8; |
| 1430 | |
| 1431 | - ret = mt76_testmode_alloc_skb(phy->mt76, tx_len); |
| 1432 | + ret = mt76_testmode_init_skb(phy->mt76, tx_len, &td->tx_skb, td->addr); |
| 1433 | if (ret) |
| 1434 | return ret; |
| 1435 | |
developer | 17bb0a8 | 2022-12-13 15:52:04 +0800 | [diff] [blame] | 1436 | @@ -458,64 +1233,227 @@ mt7915_tm_init(struct mt7915_phy *phy, bool en) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 1437 | |
| 1438 | phy->mt76->test.flag |= MT_TM_FW_RX_COUNT; |
| 1439 | |
| 1440 | - if (!en) |
| 1441 | + if (!en) { |
| 1442 | mt7915_tm_set_tam_arb(phy, en, 0); |
| 1443 | + |
| 1444 | + phy->mt76->test.aid = 0; |
| 1445 | + phy->mt76->test.tx_mpdu_len = 0; |
| 1446 | + phy->test.bf_en = 0; |
| 1447 | + mt7915_tm_set_entry(phy); |
| 1448 | + } |
| 1449 | +} |
| 1450 | + |
| 1451 | +static bool |
| 1452 | +mt7915_tm_check_skb(struct mt7915_phy *phy) |
| 1453 | +{ |
| 1454 | + struct mt76_testmode_entry_data *ed; |
| 1455 | + struct mt76_wcid *wcid; |
| 1456 | + |
| 1457 | + mt76_tm_for_each_entry(phy->mt76, wcid, ed) { |
| 1458 | + struct ieee80211_tx_info *info; |
| 1459 | + |
| 1460 | + if (!ed->tx_skb) |
| 1461 | + return false; |
| 1462 | + |
| 1463 | + info = IEEE80211_SKB_CB(ed->tx_skb); |
| 1464 | + info->control.vif = phy->monitor_vif; |
| 1465 | + } |
| 1466 | + |
| 1467 | + return true; |
| 1468 | +} |
| 1469 | + |
| 1470 | +static int |
| 1471 | +mt7915_tm_set_ba(struct mt7915_phy *phy) |
| 1472 | +{ |
| 1473 | + struct mt7915_dev *dev = phy->dev; |
| 1474 | + struct mt76_testmode_data *td = &phy->mt76->test; |
| 1475 | + struct mt76_wcid *wcid; |
| 1476 | + struct ieee80211_vif *vif = phy->monitor_vif; |
| 1477 | + struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 1478 | + struct ieee80211_ampdu_params params = { .buf_size = 256 }; |
| 1479 | + |
| 1480 | + list_for_each_entry(wcid, &td->tm_entry_list, list) { |
| 1481 | + int tid, ret; |
| 1482 | + |
| 1483 | + params.sta = wcid_to_sta(wcid); |
| 1484 | + for (tid = 0; tid < 8; tid++) { |
| 1485 | + params.tid = tid; |
| 1486 | + ret = mt7915_mcu_add_tx_ba(phy->dev, ¶ms, true); |
| 1487 | + if (ret) |
| 1488 | + return ret; |
| 1489 | + } |
| 1490 | + } |
| 1491 | + |
| 1492 | + mt76_wr(dev, MT_AGG_AALCR0(mvif->mt76.band_idx, mvif->mt76.wmm_idx), |
| 1493 | + 0x01010101); |
| 1494 | + |
| 1495 | + return 0; |
| 1496 | +} |
| 1497 | + |
| 1498 | +static int |
| 1499 | +mt7915_tm_set_muru_cfg(struct mt7915_phy *phy, struct mt7915_tm_muru *muru) |
| 1500 | +{ |
| 1501 | +/* #define MURU_SET_MANUAL_CFG 100 */ |
| 1502 | + struct mt7915_dev *dev = phy->dev; |
| 1503 | + struct { |
| 1504 | + __le32 cmd; |
| 1505 | + struct mt7915_tm_muru muru; |
| 1506 | + } __packed req = { |
| 1507 | + .cmd = cpu_to_le32(MURU_SET_MANUAL_CFG), |
| 1508 | + }; |
| 1509 | + |
| 1510 | + memcpy(&req.muru, muru, sizeof(struct mt7915_tm_muru)); |
| 1511 | + |
| 1512 | + return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(MURU_CTRL), &req, |
| 1513 | + sizeof(req), false); |
| 1514 | +} |
| 1515 | + |
| 1516 | +static int |
| 1517 | +mt7915_tm_set_muru_dl(struct mt7915_phy *phy) |
| 1518 | +{ |
| 1519 | + struct mt76_testmode_data *td = &phy->mt76->test; |
| 1520 | + struct mt76_testmode_entry_data *ed; |
| 1521 | + struct mt76_wcid *wcid; |
| 1522 | + struct cfg80211_chan_def *chandef = &phy->mt76->chandef; |
| 1523 | + struct ieee80211_vif *vif = phy->monitor_vif; |
| 1524 | + struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 1525 | + struct mt7915_tm_muru muru = {}; |
| 1526 | + struct mt7915_tm_muru_comm *comm = &muru.comm; |
| 1527 | + struct mt7915_tm_muru_dl *dl = &muru.dl; |
| 1528 | + int i; |
| 1529 | + |
| 1530 | + comm->ppdu_format = MURU_PPDU_HE_MU; |
| 1531 | + comm->band = mvif->mt76.band_idx; |
| 1532 | + comm->wmm_idx = mvif->mt76.wmm_idx; |
| 1533 | + comm->spe_idx = phy->test.spe_idx; |
| 1534 | + |
| 1535 | + dl->bw = mt7915_tm_chan_bw(chandef->width); |
| 1536 | + dl->gi = td->tx_rate_sgi;; |
| 1537 | + dl->ltf = td->tx_ltf; |
| 1538 | + dl->tx_mode = MT_PHY_TYPE_HE_MU; |
| 1539 | + |
| 1540 | + for (i = 0; i < sizeof(dl->ru); i++) |
| 1541 | + dl->ru[i] = 0x71; |
| 1542 | + |
| 1543 | + mt76_tm_for_each_entry(phy->mt76, wcid, ed) { |
| 1544 | + struct mt7915_tm_muru_dl_usr *dl_usr = &dl->usr[dl->user_num]; |
| 1545 | + |
| 1546 | + dl_usr->wlan_idx = cpu_to_le16(wcid->idx); |
| 1547 | + dl_usr->ru_alloc_seg = ed->aid < 8 ? 0 : 1; |
| 1548 | + dl_usr->ru_idx = ed->ru_idx; |
| 1549 | + dl_usr->mcs = ed->tx_rate_idx; |
| 1550 | + dl_usr->nss = ed->tx_rate_nss - 1; |
| 1551 | + dl_usr->ldpc = ed->tx_rate_ldpc; |
| 1552 | + dl->ru[dl->user_num] = ed->ru_alloc; |
| 1553 | + |
| 1554 | + dl->user_num++; |
| 1555 | + } |
| 1556 | + |
| 1557 | + muru.cfg_comm = cpu_to_le32(MURU_COMM_SET); |
| 1558 | + muru.cfg_dl = cpu_to_le32(MURU_DL_SET); |
| 1559 | + |
| 1560 | + return mt7915_tm_set_muru_cfg(phy, &muru); |
| 1561 | +} |
| 1562 | + |
| 1563 | +static int |
| 1564 | +mt7915_tm_set_muru_pkt_cnt(struct mt7915_phy *phy, bool enable, u32 tx_count) |
| 1565 | +{ |
| 1566 | +#define MURU_SET_TX_PKT_CNT 105 |
| 1567 | +#define MURU_SET_TX_EN 106 |
| 1568 | + struct mt7915_dev *dev = phy->dev; |
| 1569 | + struct { |
| 1570 | + __le32 cmd; |
| 1571 | + u8 band; |
| 1572 | + u8 enable; |
| 1573 | + u8 _rsv[2]; |
| 1574 | + __le32 tx_count; |
| 1575 | + } __packed req = { |
developer | 17bb0a8 | 2022-12-13 15:52:04 +0800 | [diff] [blame] | 1576 | + .band = phy->mt76->band_idx, |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 1577 | + .enable = enable, |
| 1578 | + .tx_count = enable ? cpu_to_le32(tx_count) : 0, |
| 1579 | + }; |
| 1580 | + int ret; |
| 1581 | + |
| 1582 | + req.cmd = enable ? cpu_to_le32(MURU_SET_TX_PKT_CNT) : |
| 1583 | + cpu_to_le32(MURU_SET_TX_EN); |
| 1584 | + |
| 1585 | + ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(MURU_CTRL), &req, |
| 1586 | + sizeof(req), false); |
| 1587 | + if (ret) |
| 1588 | + return ret; |
| 1589 | + |
| 1590 | + req.cmd = enable ? cpu_to_le32(MURU_SET_TX_EN) : |
| 1591 | + cpu_to_le32(MURU_SET_TX_PKT_CNT); |
| 1592 | + |
| 1593 | + return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(MURU_CTRL), &req, |
| 1594 | + sizeof(req), false); |
| 1595 | } |
| 1596 | |
| 1597 | static void |
| 1598 | -mt7915_tm_update_channel(struct mt7915_phy *phy) |
| 1599 | +mt7915_tm_tx_frames_mu(struct mt7915_phy *phy, bool enable) |
| 1600 | { |
| 1601 | - mutex_unlock(&phy->dev->mt76.mutex); |
| 1602 | - mt7915_set_channel(phy); |
| 1603 | - mutex_lock(&phy->dev->mt76.mutex); |
| 1604 | + struct mt76_testmode_data *td = &phy->mt76->test; |
| 1605 | |
| 1606 | - mt7915_mcu_set_chan_info(phy, MCU_EXT_CMD(SET_RX_PATH)); |
| 1607 | + if (enable) { |
| 1608 | + struct mt7915_dev *dev = phy->dev; |
| 1609 | + |
| 1610 | + mt7915_tm_set_ba(phy); |
| 1611 | + mt7915_tm_set_muru_dl(phy); |
| 1612 | + mt76_rr(dev, MT_MIB_DR8(phy != &dev->phy)); |
| 1613 | + } else { |
| 1614 | + /* set to zero for counting real tx free num */ |
| 1615 | + td->tx_done = 0; |
| 1616 | + } |
| 1617 | + |
| 1618 | + mt7915_tm_set_muru_pkt_cnt(phy, enable, td->tx_count); |
| 1619 | + usleep_range(100000, 200000); |
| 1620 | } |
| 1621 | |
| 1622 | static void |
developer | 072c561 | 2022-07-15 18:30:03 +0800 | [diff] [blame] | 1623 | mt7915_tm_set_tx_frames(struct mt7915_phy *phy, bool en) |
| 1624 | { |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 1625 | struct mt76_testmode_data *td = &phy->mt76->test; |
| 1626 | - struct mt7915_dev *dev = phy->dev; |
| 1627 | - struct ieee80211_tx_info *info; |
| 1628 | - u8 duty_cycle = td->tx_duty_cycle; |
| 1629 | - u32 tx_time = td->tx_time; |
| 1630 | - u32 ipg = td->tx_ipg; |
| 1631 | |
| 1632 | mt7915_tm_set_trx(phy, TM_MAC_RX_RXV, false); |
| 1633 | - mt7915_tm_clean_hwq(phy, dev->mt76.global_wcid.idx); |
| 1634 | + mt7915_tm_set_trx(phy, TM_MAC_TX, false); |
| 1635 | |
| 1636 | if (en) { |
| 1637 | - mt7915_tm_update_channel(phy); |
| 1638 | + u32 tx_time = td->tx_time, ipg = td->tx_ipg; |
| 1639 | + u8 duty_cycle = td->tx_duty_cycle; |
| 1640 | + |
| 1641 | + if (!phy->test.bf_en) |
| 1642 | + mt7915_tm_update_channel(phy); |
| 1643 | |
developer | 072c561 | 2022-07-15 18:30:03 +0800 | [diff] [blame] | 1644 | if (td->tx_spe_idx) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 1645 | phy->test.spe_idx = td->tx_spe_idx; |
developer | 072c561 | 2022-07-15 18:30:03 +0800 | [diff] [blame] | 1646 | else |
| 1647 | phy->test.spe_idx = mt76_connac_spe_idx(td->tx_antenna_mask); |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 1648 | - } |
| 1649 | |
| 1650 | - mt7915_tm_set_tam_arb(phy, en, |
| 1651 | - td->tx_rate_mode == MT76_TM_TX_MODE_HE_MU); |
| 1652 | + /* if all three params are set, duty_cycle will be ignored */ |
| 1653 | + if (duty_cycle && tx_time && !ipg) { |
| 1654 | + ipg = tx_time * 100 / duty_cycle - tx_time; |
| 1655 | + } else if (duty_cycle && !tx_time && ipg) { |
| 1656 | + if (duty_cycle < 100) |
| 1657 | + tx_time = duty_cycle * ipg / (100 - duty_cycle); |
| 1658 | + } |
| 1659 | |
| 1660 | - /* if all three params are set, duty_cycle will be ignored */ |
| 1661 | - if (duty_cycle && tx_time && !ipg) { |
| 1662 | - ipg = tx_time * 100 / duty_cycle - tx_time; |
| 1663 | - } else if (duty_cycle && !tx_time && ipg) { |
| 1664 | - if (duty_cycle < 100) |
| 1665 | - tx_time = duty_cycle * ipg / (100 - duty_cycle); |
| 1666 | - } |
| 1667 | + mt7915_tm_set_ipg_params(phy, ipg, td->tx_rate_mode); |
| 1668 | + mt7915_tm_set_tx_len(phy, tx_time); |
| 1669 | |
| 1670 | - mt7915_tm_set_ipg_params(phy, ipg, td->tx_rate_mode); |
| 1671 | - mt7915_tm_set_tx_len(phy, tx_time); |
| 1672 | + if (ipg) |
| 1673 | + td->tx_queued_limit = MT76_TM_TIMEOUT * 1000000 / ipg / 2; |
| 1674 | |
| 1675 | - if (ipg) |
| 1676 | - td->tx_queued_limit = MT76_TM_TIMEOUT * 1000000 / ipg / 2; |
| 1677 | + if (!mt7915_tm_check_skb(phy)) |
| 1678 | + return; |
| 1679 | + } else { |
| 1680 | + mt7915_tm_clean_hwq(phy); |
| 1681 | + } |
| 1682 | |
| 1683 | - if (!en || !td->tx_skb) |
| 1684 | - return; |
| 1685 | + mt7915_tm_set_tam_arb(phy, en, |
| 1686 | + td->tx_rate_mode == MT76_TM_TX_MODE_HE_MU); |
| 1687 | |
| 1688 | - info = IEEE80211_SKB_CB(td->tx_skb); |
| 1689 | - info->control.vif = phy->monitor_vif; |
| 1690 | + if (td->tx_rate_mode == MT76_TM_TX_MODE_HE_MU) |
| 1691 | + mt7915_tm_tx_frames_mu(phy, en); |
| 1692 | |
| 1693 | mt7915_tm_set_trx(phy, TM_MAC_TX, en); |
| 1694 | } |
developer | 17bb0a8 | 2022-12-13 15:52:04 +0800 | [diff] [blame] | 1695 | @@ -544,10 +1482,6 @@ mt7915_tm_get_rx_stats(struct mt7915_phy *phy, bool clear) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 1696 | return ret; |
| 1697 | |
| 1698 | rs_band = (struct mt7915_tm_rx_stat_band *)skb->data; |
| 1699 | - /* pr_info("mdrdy_cnt = %d\n", le32_to_cpu(rs_band->mdrdy_cnt)); */ |
| 1700 | - /* pr_info("fcs_err = %d\n", le16_to_cpu(rs_band->fcs_err)); */ |
| 1701 | - /* pr_info("len_mismatch = %d\n", le16_to_cpu(rs_band->len_mismatch)); */ |
| 1702 | - /* pr_info("fcs_ok = %d\n", le16_to_cpu(rs_band->fcs_succ)); */ |
| 1703 | |
| 1704 | if (!clear) { |
developer | f7a3ca3 | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 1705 | enum mt76_rxq_id q = req.band ? MT_RXQ_BAND1 : MT_RXQ_MAIN; |
developer | 17bb0a8 | 2022-12-13 15:52:04 +0800 | [diff] [blame] | 1706 | @@ -562,13 +1496,61 @@ mt7915_tm_get_rx_stats(struct mt7915_phy *phy, bool clear) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 1707 | return 0; |
| 1708 | } |
| 1709 | |
| 1710 | +static int |
| 1711 | +mt7915_tm_set_rx_user_idx(struct mt7915_phy *phy, u8 aid) |
| 1712 | +{ |
| 1713 | + struct mt7915_dev *dev = phy->dev; |
| 1714 | + struct mt76_wcid *wcid = NULL; |
| 1715 | + struct mt76_testmode_entry_data *ed; |
| 1716 | + struct { |
| 1717 | + u8 band; |
| 1718 | + u8 _rsv; |
| 1719 | + __le16 wlan_idx; |
| 1720 | + } __packed req = { |
developer | 17bb0a8 | 2022-12-13 15:52:04 +0800 | [diff] [blame] | 1721 | + .band = phy->mt76->band_idx, |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 1722 | + }; |
| 1723 | + |
| 1724 | + mt76_tm_for_each_entry(phy->mt76, wcid, ed) |
| 1725 | + if (ed->aid == aid) |
| 1726 | + break; |
| 1727 | + |
| 1728 | + if (!wcid) |
| 1729 | + return -EINVAL; |
| 1730 | + |
| 1731 | + req.wlan_idx = cpu_to_le16(wcid->idx); |
| 1732 | + |
| 1733 | + return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(RX_STAT_USER_CTRL), |
| 1734 | + &req, sizeof(req), false); |
| 1735 | +} |
| 1736 | + |
| 1737 | +static int |
| 1738 | +mt7915_tm_set_muru_aid(struct mt7915_phy *phy, u16 aid) |
| 1739 | +{ |
| 1740 | + struct mt7915_dev *dev = phy->dev; |
| 1741 | + struct mt7915_tm_cmd req = { |
| 1742 | + .testmode_en = 1, |
| 1743 | + .param_idx = MCU_ATE_SET_MU_RX_AID, |
developer | 17bb0a8 | 2022-12-13 15:52:04 +0800 | [diff] [blame] | 1744 | + .param.rx_aid.band = cpu_to_le32(phy->mt76->band_idx), |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 1745 | + .param.rx_aid.aid = cpu_to_le16(aid), |
| 1746 | + }; |
| 1747 | + |
| 1748 | + return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(ATE_CTRL), &req, |
| 1749 | + sizeof(req), false); |
| 1750 | +} |
| 1751 | + |
| 1752 | static void |
| 1753 | mt7915_tm_set_rx_frames(struct mt7915_phy *phy, bool en) |
| 1754 | { |
| 1755 | + struct mt76_testmode_data *td = &phy->mt76->test; |
| 1756 | + |
| 1757 | + mt7915_tm_set_trx(phy, TM_MAC_TX, false); |
| 1758 | mt7915_tm_set_trx(phy, TM_MAC_RX_RXV, false); |
| 1759 | |
| 1760 | if (en) { |
| 1761 | - mt7915_tm_update_channel(phy); |
| 1762 | + if (!phy->test.bf_en) |
| 1763 | + mt7915_tm_update_channel(phy); |
| 1764 | + if (td->aid) |
| 1765 | + mt7915_tm_set_rx_user_idx(phy, td->aid); |
| 1766 | |
| 1767 | /* read-clear */ |
| 1768 | mt7915_tm_get_rx_stats(phy, true); |
developer | 17bb0a8 | 2022-12-13 15:52:04 +0800 | [diff] [blame] | 1769 | @@ -576,9 +1558,12 @@ mt7915_tm_set_rx_frames(struct mt7915_phy *phy, bool en) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 1770 | /* clear fw count */ |
| 1771 | mt7915_tm_set_phy_count(phy, 0); |
| 1772 | mt7915_tm_set_phy_count(phy, 1); |
| 1773 | - |
| 1774 | - mt7915_tm_set_trx(phy, TM_MAC_RX_RXV, en); |
| 1775 | } |
| 1776 | + |
| 1777 | + if (td->tx_rate_mode == MT76_TM_TX_MODE_HE_MU) |
| 1778 | + mt7915_tm_set_muru_aid(phy, en ? td->aid : 0xf800); |
| 1779 | + |
| 1780 | + mt7915_tm_set_trx(phy, TM_MAC_RX_RXV, en); |
| 1781 | } |
| 1782 | |
| 1783 | static int |
developer | 17bb0a8 | 2022-12-13 15:52:04 +0800 | [diff] [blame] | 1784 | @@ -617,34 +1602,7 @@ mt7915_tm_set_tx_cont(struct mt7915_phy *phy, bool en) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 1785 | tx_cont->tx_ant = td->tx_antenna_mask; |
developer | 17bb0a8 | 2022-12-13 15:52:04 +0800 | [diff] [blame] | 1786 | tx_cont->band = band; |
developer | 3609d78 | 2022-11-29 18:07:22 +0800 | [diff] [blame] | 1787 | |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 1788 | - switch (chandef->width) { |
| 1789 | - case NL80211_CHAN_WIDTH_40: |
| 1790 | - tx_cont->bw = CMD_CBW_40MHZ; |
| 1791 | - break; |
| 1792 | - case NL80211_CHAN_WIDTH_80: |
| 1793 | - tx_cont->bw = CMD_CBW_80MHZ; |
| 1794 | - break; |
| 1795 | - case NL80211_CHAN_WIDTH_80P80: |
| 1796 | - tx_cont->bw = CMD_CBW_8080MHZ; |
| 1797 | - break; |
| 1798 | - case NL80211_CHAN_WIDTH_160: |
| 1799 | - tx_cont->bw = CMD_CBW_160MHZ; |
| 1800 | - break; |
| 1801 | - case NL80211_CHAN_WIDTH_5: |
| 1802 | - tx_cont->bw = CMD_CBW_5MHZ; |
| 1803 | - break; |
| 1804 | - case NL80211_CHAN_WIDTH_10: |
| 1805 | - tx_cont->bw = CMD_CBW_10MHZ; |
| 1806 | - break; |
| 1807 | - case NL80211_CHAN_WIDTH_20: |
| 1808 | - tx_cont->bw = CMD_CBW_20MHZ; |
| 1809 | - break; |
| 1810 | - case NL80211_CHAN_WIDTH_20_NOHT: |
| 1811 | - tx_cont->bw = CMD_CBW_20MHZ; |
| 1812 | - break; |
| 1813 | - default: |
| 1814 | - return -EINVAL; |
| 1815 | - } |
| 1816 | + tx_cont->bw = mt7915_tm_chan_bw(chandef->width); |
| 1817 | |
| 1818 | if (!en) { |
developer | 17bb0a8 | 2022-12-13 15:52:04 +0800 | [diff] [blame] | 1819 | req.op.rf.param.func_data = cpu_to_le32(band); |
| 1820 | @@ -728,6 +1686,12 @@ mt7915_tm_update_params(struct mt7915_phy *phy, u32 changed) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 1821 | mt7915_tm_set_freq_offset(phy, en, en ? td->freq_offset : 0); |
| 1822 | if (changed & BIT(TM_CHANGED_TXPOWER)) |
| 1823 | mt7915_tm_set_tx_power(phy); |
| 1824 | + if (changed & BIT(TM_CHANGED_AID)) |
| 1825 | + mt7915_tm_set_entry(phy); |
| 1826 | + if (changed & BIT(TM_CHANGED_CFG)) |
| 1827 | + mt7915_tm_set_cfg(phy); |
| 1828 | + if (changed & BIT(TM_CHANGED_TXBF_ACT)) |
| 1829 | + mt7915_tm_set_txbf(phy); |
| 1830 | } |
| 1831 | |
| 1832 | static int |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 1833 | @@ -737,6 +1701,11 @@ mt7915_tm_set_state(struct mt76_phy *mphy, enum mt76_testmode_state state) |
| 1834 | struct mt7915_phy *phy = mphy->priv; |
| 1835 | enum mt76_testmode_state prev_state = td->state; |
| 1836 | |
| 1837 | + if (!phy->monitor_vif) { |
| 1838 | + dev_err(phy->dev->mt76.dev, "Please make sure monitor interface is up\n"); |
| 1839 | + return -ENOTCONN; |
| 1840 | + } |
| 1841 | + |
| 1842 | mphy->test.state = state; |
| 1843 | |
| 1844 | if (prev_state == MT76_TM_STATE_TX_FRAMES || |
| 1845 | @@ -807,6 +1776,7 @@ static int |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 1846 | mt7915_tm_dump_stats(struct mt76_phy *mphy, struct sk_buff *msg) |
| 1847 | { |
| 1848 | struct mt7915_phy *phy = mphy->priv; |
| 1849 | + struct mt7915_dev *dev = phy->dev; |
| 1850 | void *rx, *rssi; |
| 1851 | int i; |
| 1852 | |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 1853 | @@ -852,11 +1822,68 @@ mt7915_tm_dump_stats(struct mt76_phy *mphy, struct sk_buff *msg) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 1854 | |
| 1855 | nla_nest_end(msg, rx); |
| 1856 | |
| 1857 | + if (mphy->test.tx_rate_mode == MT76_TM_TX_MODE_HE_MU) |
| 1858 | + mphy->test.tx_done += mt76_rr(dev, MT_MIB_DR8(phy != &dev->phy)); |
| 1859 | + |
| 1860 | return mt7915_tm_get_rx_stats(phy, false); |
| 1861 | } |
| 1862 | |
| 1863 | +static int |
| 1864 | +mt7915_tm_write_back_to_efuse(struct mt7915_dev *dev) |
| 1865 | +{ |
| 1866 | + struct mt7915_mcu_eeprom_info req = {}; |
| 1867 | + u8 *eeprom = dev->mt76.eeprom.data; |
| 1868 | + int i, ret = -EINVAL; |
| 1869 | + |
| 1870 | + /* prevent from damaging chip id in efuse */ |
| 1871 | + if (mt76_chip(&dev->mt76) != get_unaligned_le16(eeprom)) |
| 1872 | + goto out; |
| 1873 | + |
| 1874 | + for (i = 0; i < mt7915_eeprom_size(dev); i += MT76_TM_EEPROM_BLOCK_SIZE) { |
| 1875 | + req.addr = cpu_to_le32(i); |
| 1876 | + memcpy(&req.data, eeprom + i, MT76_TM_EEPROM_BLOCK_SIZE); |
| 1877 | + |
| 1878 | + ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(EFUSE_ACCESS), |
| 1879 | + &req, sizeof(req), true); |
| 1880 | + if (ret) |
| 1881 | + return ret; |
| 1882 | + } |
| 1883 | + |
| 1884 | +out: |
| 1885 | + return ret; |
| 1886 | +} |
| 1887 | + |
| 1888 | +static int |
| 1889 | +mt7915_tm_set_eeprom(struct mt76_phy *mphy, u32 offset, u8 *val, u8 action) |
| 1890 | +{ |
| 1891 | + struct mt7915_phy *phy = mphy->priv; |
| 1892 | + struct mt7915_dev *dev = phy->dev; |
| 1893 | + u8 *eeprom = dev->mt76.eeprom.data; |
| 1894 | + int ret = 0; |
| 1895 | + |
| 1896 | + if (offset >= mt7915_eeprom_size(dev)) |
| 1897 | + return -EINVAL; |
| 1898 | + |
| 1899 | + switch (action) { |
| 1900 | + case MT76_TM_EEPROM_ACTION_UPDATE_DATA: |
| 1901 | + memcpy(eeprom + offset, val, MT76_TM_EEPROM_BLOCK_SIZE); |
| 1902 | + break; |
| 1903 | + case MT76_TM_EEPROM_ACTION_UPDATE_BUFFER_MODE: |
| 1904 | + ret = mt7915_mcu_set_eeprom(dev, true); |
| 1905 | + break; |
| 1906 | + case MT76_TM_EEPROM_ACTION_WRITE_TO_EFUSE: |
| 1907 | + ret = mt7915_tm_write_back_to_efuse(dev); |
| 1908 | + break; |
| 1909 | + default: |
| 1910 | + break; |
| 1911 | + } |
| 1912 | + |
| 1913 | + return ret; |
| 1914 | +} |
| 1915 | + |
| 1916 | const struct mt76_testmode_ops mt7915_testmode_ops = { |
| 1917 | .set_state = mt7915_tm_set_state, |
| 1918 | .set_params = mt7915_tm_set_params, |
| 1919 | .dump_stats = mt7915_tm_dump_stats, |
| 1920 | + .set_eeprom = mt7915_tm_set_eeprom, |
| 1921 | }; |
| 1922 | diff --git a/mt7915/testmode.h b/mt7915/testmode.h |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 1923 | index a1c54c8..01b08e9 100644 |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 1924 | --- a/mt7915/testmode.h |
| 1925 | +++ b/mt7915/testmode.h |
| 1926 | @@ -4,6 +4,8 @@ |
| 1927 | #ifndef __MT7915_TESTMODE_H |
| 1928 | #define __MT7915_TESTMODE_H |
| 1929 | |
| 1930 | +#include "mcu.h" |
| 1931 | + |
| 1932 | struct mt7915_tm_trx { |
| 1933 | u8 type; |
| 1934 | u8 enable; |
| 1935 | @@ -39,6 +41,11 @@ struct mt7915_tm_cfg { |
| 1936 | u8 _rsv[2]; |
| 1937 | }; |
| 1938 | |
| 1939 | +struct mt7915_tm_mu_rx_aid { |
| 1940 | + __le32 band; |
| 1941 | + __le16 aid; |
| 1942 | +}; |
| 1943 | + |
| 1944 | struct mt7915_tm_cmd { |
| 1945 | u8 testmode_en; |
| 1946 | u8 param_idx; |
| 1947 | @@ -50,6 +57,7 @@ struct mt7915_tm_cmd { |
| 1948 | struct mt7915_tm_slot_time slot; |
| 1949 | struct mt7915_tm_clean_txq clean; |
| 1950 | struct mt7915_tm_cfg cfg; |
| 1951 | + struct mt7915_tm_mu_rx_aid rx_aid; |
| 1952 | u8 test[72]; |
| 1953 | } param; |
| 1954 | } __packed; |
| 1955 | @@ -109,6 +117,16 @@ enum { |
| 1956 | TAM_ARB_OP_MODE_FORCE_SU = 5, |
| 1957 | }; |
| 1958 | |
| 1959 | +enum { |
| 1960 | + TM_CBW_20MHZ, |
| 1961 | + TM_CBW_40MHZ, |
| 1962 | + TM_CBW_80MHZ, |
| 1963 | + TM_CBW_10MHZ, |
| 1964 | + TM_CBW_5MHZ, |
| 1965 | + TM_CBW_160MHZ, |
| 1966 | + TM_CBW_8080MHZ, |
| 1967 | +}; |
| 1968 | + |
| 1969 | struct mt7915_tm_rx_stat_band { |
| 1970 | u8 category; |
| 1971 | |
| 1972 | @@ -130,4 +148,264 @@ struct mt7915_tm_rx_stat_band { |
| 1973 | __le16 mdrdy_cnt_ofdm; |
| 1974 | }; |
| 1975 | |
| 1976 | +struct mt7915_tm_muru_comm { |
| 1977 | + u8 ppdu_format; |
| 1978 | + u8 sch_type; |
| 1979 | + u8 band; |
| 1980 | + u8 wmm_idx; |
| 1981 | + u8 spe_idx; |
| 1982 | + u8 proc_type; |
| 1983 | +}; |
| 1984 | + |
| 1985 | +struct mt7915_tm_muru_dl_usr { |
| 1986 | + __le16 wlan_idx; |
| 1987 | + u8 ru_alloc_seg; |
| 1988 | + u8 ru_idx; |
| 1989 | + u8 ldpc; |
| 1990 | + u8 nss; |
| 1991 | + u8 mcs; |
| 1992 | + u8 mu_group_idx; |
| 1993 | + u8 vht_groud_id; |
| 1994 | + u8 vht_up; |
| 1995 | + u8 he_start_stream; |
| 1996 | + u8 he_mu_spatial; |
| 1997 | + u8 ack_policy; |
| 1998 | + __le16 tx_power_alpha; |
| 1999 | +}; |
| 2000 | + |
| 2001 | +struct mt7915_tm_muru_dl { |
| 2002 | + u8 user_num; |
| 2003 | + u8 tx_mode; |
| 2004 | + u8 bw; |
| 2005 | + u8 gi; |
| 2006 | + u8 ltf; |
| 2007 | + /* sigB */ |
| 2008 | + u8 mcs; |
| 2009 | + u8 dcm; |
| 2010 | + u8 cmprs; |
| 2011 | + |
| 2012 | + u8 tx_power; |
| 2013 | + u8 ru[8]; |
| 2014 | + u8 c26[2]; |
| 2015 | + u8 ack_policy; |
| 2016 | + |
| 2017 | + struct mt7915_tm_muru_dl_usr usr[16]; |
| 2018 | +}; |
| 2019 | + |
| 2020 | +struct mt7915_tm_muru_ul_usr { |
| 2021 | + __le16 wlan_idx; |
| 2022 | + u8 ru_alloc; |
| 2023 | + u8 ru_idx; |
| 2024 | + u8 ldpc; |
| 2025 | + u8 nss; |
| 2026 | + u8 mcs; |
| 2027 | + u8 target_rssi; |
| 2028 | + __le32 trig_pkt_size; |
| 2029 | +}; |
| 2030 | + |
| 2031 | +struct mt7915_tm_muru_ul { |
| 2032 | + u8 user_num; |
| 2033 | + |
| 2034 | + /* UL TX */ |
| 2035 | + u8 trig_type; |
| 2036 | + __le16 trig_cnt; |
| 2037 | + __le16 trig_intv; |
| 2038 | + u8 bw; |
| 2039 | + u8 gi_ltf; |
| 2040 | + __le16 ul_len; |
| 2041 | + u8 pad; |
| 2042 | + u8 trig_ta[ETH_ALEN]; |
| 2043 | + u8 ru[8]; |
| 2044 | + u8 c26[2]; |
| 2045 | + |
| 2046 | + struct mt7915_tm_muru_ul_usr usr[16]; |
| 2047 | + /* HE TB RX Debug */ |
| 2048 | + __le32 rx_hetb_nonsf_en_bitmap; |
| 2049 | + __le32 rx_hetb_cfg[2]; |
| 2050 | + |
| 2051 | + /* DL TX */ |
| 2052 | + u8 ba_type; |
| 2053 | +}; |
| 2054 | + |
| 2055 | +struct mt7915_tm_muru { |
| 2056 | + __le32 cfg_comm; |
| 2057 | + __le32 cfg_dl; |
| 2058 | + __le32 cfg_ul; |
| 2059 | + |
| 2060 | + struct mt7915_tm_muru_comm comm; |
| 2061 | + struct mt7915_tm_muru_dl dl; |
| 2062 | + struct mt7915_tm_muru_ul ul; |
| 2063 | +}; |
| 2064 | + |
| 2065 | +#define MURU_PPDU_HE_MU BIT(3) |
| 2066 | + |
| 2067 | +/* Common Config */ |
| 2068 | +/* #define MURU_COMM_PPDU_FMT BIT(0) */ |
| 2069 | +/* #define MURU_COMM_SCH_TYPE BIT(1) */ |
| 2070 | +/* #define MURU_COMM_BAND BIT(2) */ |
| 2071 | +/* #define MURU_COMM_WMM BIT(3) */ |
| 2072 | +/* #define MURU_COMM_SPE_IDX BIT(4) */ |
| 2073 | +/* #define MURU_COMM_PROC_TYPE BIT(5) */ |
| 2074 | +/* #define MURU_COMM_SET (MURU_COMM_PPDU_FMT | MURU_COMM_BAND | \ */ |
| 2075 | +/* MURU_COMM_WMM | MURU_COMM_SPE_IDX) */ |
| 2076 | +/* DL Config */ |
| 2077 | +#define MURU_DL_BW BIT(0) |
| 2078 | +#define MURU_DL_GI BIT(1) |
| 2079 | +#define MURU_DL_TX_MODE BIT(2) |
| 2080 | +#define MURU_DL_TONE_PLAN BIT(3) |
| 2081 | +#define MURU_DL_USER_CNT BIT(4) |
| 2082 | +#define MURU_DL_LTF BIT(5) |
| 2083 | +#define MURU_DL_SIGB_MCS BIT(6) |
| 2084 | +#define MURU_DL_SIGB_DCM BIT(7) |
| 2085 | +#define MURU_DL_SIGB_CMPRS BIT(8) |
| 2086 | +#define MURU_DL_ACK_POLICY BIT(9) |
| 2087 | +#define MURU_DL_TXPOWER BIT(10) |
| 2088 | +/* DL Per User Config */ |
| 2089 | +#define MURU_DL_USER_WLAN_ID BIT(16) |
| 2090 | +#define MURU_DL_USER_COD BIT(17) |
| 2091 | +#define MURU_DL_USER_MCS BIT(18) |
| 2092 | +#define MURU_DL_USER_NSS BIT(19) |
| 2093 | +#define MURU_DL_USER_RU_ALLOC BIT(20) |
| 2094 | +#define MURU_DL_USER_MUMIMO_GRP BIT(21) |
| 2095 | +#define MURU_DL_USER_MUMIMO_VHT BIT(22) |
| 2096 | +#define MURU_DL_USER_ACK_POLICY BIT(23) |
| 2097 | +#define MURU_DL_USER_MUMIMO_HE BIT(24) |
| 2098 | +#define MURU_DL_USER_PWR_ALPHA BIT(25) |
| 2099 | +#define MURU_DL_SET (GENMASK(7, 0) | GENMASK(20, 16) | BIT(25)) |
| 2100 | + |
| 2101 | +#define MAX_PHASE_GROUP_NUM 9 |
| 2102 | + |
| 2103 | +struct mt7915_tm_txbf_phase { |
| 2104 | + u8 status; |
| 2105 | + struct { |
| 2106 | + u8 r0_uh; |
| 2107 | + u8 r0_h; |
| 2108 | + u8 r0_m; |
| 2109 | + u8 r0_l; |
| 2110 | + u8 r0_ul; |
| 2111 | + u8 r1_uh; |
| 2112 | + u8 r1_h; |
| 2113 | + u8 r1_m; |
| 2114 | + u8 r1_l; |
| 2115 | + u8 r1_ul; |
| 2116 | + u8 r2_uh; |
| 2117 | + u8 r2_h; |
| 2118 | + u8 r2_m; |
| 2119 | + u8 r2_l; |
| 2120 | + u8 r2_ul; |
| 2121 | + u8 r3_uh; |
| 2122 | + u8 r3_h; |
| 2123 | + u8 r3_m; |
| 2124 | + u8 r3_l; |
| 2125 | + u8 r3_ul; |
| 2126 | + u8 r2_uh_sx2; |
| 2127 | + u8 r2_h_sx2; |
| 2128 | + u8 r2_m_sx2; |
| 2129 | + u8 r2_l_sx2; |
| 2130 | + u8 r2_ul_sx2; |
| 2131 | + u8 r3_uh_sx2; |
| 2132 | + u8 r3_h_sx2; |
| 2133 | + u8 r3_m_sx2; |
| 2134 | + u8 r3_l_sx2; |
| 2135 | + u8 r3_ul_sx2; |
| 2136 | + u8 m_t0_h; |
| 2137 | + u8 m_t1_h; |
| 2138 | + u8 m_t2_h; |
| 2139 | + u8 m_t2_h_sx2; |
| 2140 | + u8 r0_reserved; |
| 2141 | + u8 r1_reserved; |
| 2142 | + u8 r2_reserved; |
| 2143 | + u8 r3_reserved; |
| 2144 | + u8 r2_sx2_reserved; |
| 2145 | + u8 r3_sx2_reserved; |
| 2146 | + } phase; |
| 2147 | +}; |
| 2148 | + |
| 2149 | +struct mt7915_tm_pfmu_tag1 { |
| 2150 | + __le32 pfmu_idx:10; |
| 2151 | + __le32 ebf:1; |
| 2152 | + __le32 data_bw:2; |
| 2153 | + __le32 lm:2; |
| 2154 | + __le32 is_mu:1; |
| 2155 | + __le32 nr:3, nc:3; |
| 2156 | + __le32 codebook:2; |
| 2157 | + __le32 ngroup:2; |
| 2158 | + __le32 _rsv:2; |
| 2159 | + __le32 invalid_prof:1; |
| 2160 | + __le32 rmsd:3; |
| 2161 | + |
| 2162 | + __le32 col_id1:6, row_id1:10; |
| 2163 | + __le32 col_id2:6, row_id2:10; |
| 2164 | + __le32 col_id3:6, row_id3:10; |
| 2165 | + __le32 col_id4:6, row_id4:10; |
| 2166 | + |
| 2167 | + __le32 ru_start_id:7; |
| 2168 | + __le32 _rsv1:1; |
| 2169 | + __le32 ru_end_id:7; |
| 2170 | + __le32 _rsv2:1; |
| 2171 | + __le32 mob_cal_en:1; |
| 2172 | + __le32 _rsv3:15; |
| 2173 | + |
| 2174 | + __le32 snr_sts0:8, snr_sts1:8, snr_sts2:8, snr_sts3:8; |
| 2175 | + __le32 snr_sts4:8, snr_sts5:8, snr_sts6:8, snr_sts7:8; |
| 2176 | + |
| 2177 | + __le32 _rsv4; |
| 2178 | +} __packed; |
| 2179 | + |
| 2180 | +struct mt7915_tm_pfmu_tag2 { |
| 2181 | + __le32 smart_ant:24; |
| 2182 | + __le32 se_idx:5; |
| 2183 | + __le32 _rsv:3; |
| 2184 | + |
| 2185 | + __le32 _rsv1:8; |
| 2186 | + __le32 rmsd_thres:3; |
| 2187 | + __le32 _rsv2:5; |
| 2188 | + __le32 ibf_timeout:8; |
| 2189 | + __le32 _rsv3:8; |
| 2190 | + |
| 2191 | + __le32 _rsv4:16; |
| 2192 | + __le32 ibf_data_bw:2; |
| 2193 | + __le32 ibf_nc:3; |
| 2194 | + __le32 ibf_nr:3; |
| 2195 | + __le32 ibf_ru:8; |
| 2196 | + |
| 2197 | + __le32 mob_delta_t:8; |
| 2198 | + __le32 mob_lq_result:7; |
| 2199 | + __le32 _rsv5:1; |
| 2200 | + __le32 _rsv6:16; |
| 2201 | + |
| 2202 | + __le32 _rsv7; |
| 2203 | +} __packed; |
| 2204 | + |
| 2205 | +struct mt7915_tm_pfmu_tag { |
| 2206 | + struct mt7915_tm_pfmu_tag1 t1; |
| 2207 | + struct mt7915_tm_pfmu_tag2 t2; |
| 2208 | +}; |
| 2209 | + |
| 2210 | +struct mt7915_tm_pfmu_data { |
| 2211 | + __le16 subc_idx; |
| 2212 | + __le16 phi11; |
| 2213 | + __le16 phi21; |
| 2214 | + __le16 phi31; |
| 2215 | +}; |
| 2216 | + |
| 2217 | +struct mt7915_tm_ibf_cal_info { |
| 2218 | + u8 format_id; |
| 2219 | + u8 group_l_m_n; |
| 2220 | + u8 group; |
| 2221 | + bool sx2; |
| 2222 | + u8 status; |
| 2223 | + u8 cal_type; |
| 2224 | + u8 _rsv[2]; |
| 2225 | + u8 buf[1000]; |
| 2226 | +} __packed; |
| 2227 | + |
| 2228 | +enum { |
| 2229 | + IBF_PHASE_CAL_UNSPEC, |
| 2230 | + IBF_PHASE_CAL_NORMAL, |
| 2231 | + IBF_PHASE_CAL_VERIFY, |
| 2232 | + IBF_PHASE_CAL_NORMAL_INSTRUMENT, |
| 2233 | + IBF_PHASE_CAL_VERIFY_INSTRUMENT, |
| 2234 | +}; |
| 2235 | + |
| 2236 | #endif |
| 2237 | diff --git a/testmode.c b/testmode.c |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 2238 | index 1d0d5d3..7a9ed54 100644 |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2239 | --- a/testmode.c |
| 2240 | +++ b/testmode.c |
developer | 072c561 | 2022-07-15 18:30:03 +0800 | [diff] [blame] | 2241 | @@ -27,28 +27,16 @@ const struct nla_policy mt76_tm_policy[NUM_MT76_TM_ATTRS] = { |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2242 | }; |
| 2243 | EXPORT_SYMBOL_GPL(mt76_tm_policy); |
| 2244 | |
| 2245 | -void mt76_testmode_tx_pending(struct mt76_phy *phy) |
| 2246 | +static void |
| 2247 | +mt76_testmode_queue_tx(struct mt76_phy *phy, struct mt76_wcid *wcid, |
developer | f79ad45 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 2248 | + struct sk_buff *skb, struct mt76_queue *q, int qid, |
| 2249 | + u16 limit) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2250 | { |
| 2251 | struct mt76_testmode_data *td = &phy->test; |
| 2252 | struct mt76_dev *dev = phy->dev; |
| 2253 | - struct mt76_wcid *wcid = &dev->global_wcid; |
| 2254 | - struct sk_buff *skb = td->tx_skb; |
| 2255 | - struct mt76_queue *q; |
| 2256 | - u16 tx_queued_limit; |
| 2257 | - int qid; |
| 2258 | - |
| 2259 | - if (!skb || !td->tx_pending) |
| 2260 | - return; |
| 2261 | + u16 count = limit; |
| 2262 | |
| 2263 | - qid = skb_get_queue_mapping(skb); |
| 2264 | - q = phy->q_tx[qid]; |
| 2265 | - |
| 2266 | - tx_queued_limit = td->tx_queued_limit ? td->tx_queued_limit : 1000; |
| 2267 | - |
| 2268 | - spin_lock_bh(&q->lock); |
| 2269 | - |
| 2270 | - while (td->tx_pending > 0 && |
| 2271 | - td->tx_queued - td->tx_done < tx_queued_limit && |
| 2272 | + while (td->tx_pending > 0 && count && |
| 2273 | q->queued < q->ndesc / 2) { |
| 2274 | int ret; |
| 2275 | |
developer | 072c561 | 2022-07-15 18:30:03 +0800 | [diff] [blame] | 2276 | @@ -57,13 +45,65 @@ void mt76_testmode_tx_pending(struct mt76_phy *phy) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2277 | if (ret < 0) |
| 2278 | break; |
| 2279 | |
| 2280 | + count--; |
| 2281 | td->tx_pending--; |
| 2282 | td->tx_queued++; |
| 2283 | + |
| 2284 | + if (td->tx_rate_mode != MT76_TM_TX_MODE_HE_MU) |
| 2285 | + if (td->tx_queued - td->tx_done >= limit) |
| 2286 | + break; |
| 2287 | } |
| 2288 | |
| 2289 | dev->queue_ops->kick(dev, q); |
| 2290 | +} |
| 2291 | + |
| 2292 | +void mt76_testmode_tx_pending(struct mt76_phy *phy) |
| 2293 | +{ |
| 2294 | + struct mt76_testmode_data *td = &phy->test; |
| 2295 | + struct mt76_testmode_entry_data *ed; |
| 2296 | + struct mt76_queue *q; |
| 2297 | + int qid; |
| 2298 | + u16 tx_queued_limit; |
| 2299 | + u32 remain; |
| 2300 | + bool is_mu; |
| 2301 | + |
| 2302 | + if (!td->tx_pending) |
| 2303 | + return; |
| 2304 | + |
| 2305 | + /* tx_queued_limit = td->tx_queued_limit ?: 100; */ |
| 2306 | + tx_queued_limit = 100; |
| 2307 | + |
| 2308 | + if (!td->aid) { |
| 2309 | + qid = skb_get_queue_mapping(td->tx_skb); |
| 2310 | + q = phy->q_tx[qid]; |
| 2311 | + spin_lock_bh(&q->lock); |
| 2312 | + mt76_testmode_queue_tx(phy, &phy->dev->global_wcid, |
developer | f79ad45 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 2313 | + td->tx_skb, q, qid, tx_queued_limit); |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2314 | + spin_unlock_bh(&q->lock); |
| 2315 | + |
| 2316 | + return; |
| 2317 | + } |
| 2318 | + |
| 2319 | + is_mu = td->tx_rate_mode == MT76_TM_TX_MODE_HE_MU; |
| 2320 | + ed = mt76_testmode_entry_data(phy, td->cur_entry); |
| 2321 | + qid = skb_get_queue_mapping(ed->tx_skb); |
| 2322 | + q = phy->q_tx[qid]; |
| 2323 | + |
| 2324 | + spin_lock_bh(&q->lock); |
| 2325 | + |
| 2326 | + remain = is_mu ? 1 : (td->tx_pending % td->tx_count) ?: td->tx_count; |
| 2327 | + if (remain < tx_queued_limit) |
| 2328 | + tx_queued_limit = remain; |
| 2329 | + |
developer | f79ad45 | 2022-07-12 11:37:54 +0800 | [diff] [blame] | 2330 | + mt76_testmode_queue_tx(phy, td->cur_entry, ed->tx_skb, q, qid, tx_queued_limit); |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2331 | + |
| 2332 | + if (td->tx_pending % td->tx_count == 0 || is_mu) |
| 2333 | + td->cur_entry = list_next_entry(td->cur_entry, list); |
| 2334 | |
| 2335 | spin_unlock_bh(&q->lock); |
| 2336 | + |
| 2337 | + if (is_mu && td->tx_pending) |
| 2338 | + mt76_worker_schedule(&phy->dev->tx_worker); |
| 2339 | } |
| 2340 | |
| 2341 | static u32 |
developer | 072c561 | 2022-07-15 18:30:03 +0800 | [diff] [blame] | 2342 | @@ -89,15 +129,31 @@ mt76_testmode_max_mpdu_len(struct mt76_phy *phy, u8 tx_rate_mode) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2343 | } |
| 2344 | |
| 2345 | static void |
| 2346 | -mt76_testmode_free_skb(struct mt76_phy *phy) |
| 2347 | +mt76_testmode_free_skb(struct sk_buff **tx_skb) |
| 2348 | +{ |
| 2349 | + if (!(*tx_skb)) |
| 2350 | + return; |
| 2351 | + |
| 2352 | + dev_kfree_skb(*tx_skb); |
| 2353 | + *tx_skb = NULL; |
| 2354 | +} |
| 2355 | + |
| 2356 | +static void |
| 2357 | +mt76_testmode_free_skb_all(struct mt76_phy *phy) |
| 2358 | { |
| 2359 | struct mt76_testmode_data *td = &phy->test; |
| 2360 | + struct mt76_testmode_entry_data *ed = &td->ed; |
| 2361 | + struct mt76_wcid *wcid; |
| 2362 | + |
| 2363 | + mt76_testmode_free_skb(&ed->tx_skb); |
| 2364 | |
| 2365 | - dev_kfree_skb(td->tx_skb); |
| 2366 | - td->tx_skb = NULL; |
| 2367 | + mt76_tm_for_each_entry(phy, wcid, ed) |
| 2368 | + mt76_testmode_free_skb(&ed->tx_skb); |
| 2369 | } |
| 2370 | |
| 2371 | -int mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len) |
| 2372 | +static int |
| 2373 | +mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len, |
| 2374 | + struct sk_buff **tx_skb, u8 (*addr)[ETH_ALEN]) |
| 2375 | { |
| 2376 | #define MT_TXP_MAX_LEN 4095 |
| 2377 | u16 fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA | |
developer | f7a3ca3 | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 2378 | @@ -118,7 +174,8 @@ int mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2379 | nfrags = len / MT_TXP_MAX_LEN; |
| 2380 | head_len = nfrags ? MT_TXP_MAX_LEN : len; |
| 2381 | |
| 2382 | - if (len > IEEE80211_MAX_FRAME_LEN) |
| 2383 | + if (len > IEEE80211_MAX_FRAME_LEN || |
| 2384 | + td->tx_rate_mode == MT76_TM_TX_MODE_HE_MU) |
| 2385 | fc |= IEEE80211_STYPE_QOS_DATA; |
| 2386 | |
| 2387 | head = alloc_skb(head_len, GFP_KERNEL); |
developer | f7a3ca3 | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 2388 | @@ -127,9 +184,9 @@ int mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2389 | |
developer | 072c561 | 2022-07-15 18:30:03 +0800 | [diff] [blame] | 2390 | hdr = __skb_put_zero(head, sizeof(*hdr)); |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2391 | hdr->frame_control = cpu_to_le16(fc); |
| 2392 | - memcpy(hdr->addr1, td->addr[0], ETH_ALEN); |
| 2393 | - memcpy(hdr->addr2, td->addr[1], ETH_ALEN); |
| 2394 | - memcpy(hdr->addr3, td->addr[2], ETH_ALEN); |
| 2395 | + memcpy(hdr->addr1, addr[0], ETH_ALEN); |
| 2396 | + memcpy(hdr->addr2, addr[1], ETH_ALEN); |
| 2397 | + memcpy(hdr->addr3, addr[2], ETH_ALEN); |
| 2398 | skb_set_queue_mapping(head, IEEE80211_AC_BE); |
developer | 072c561 | 2022-07-15 18:30:03 +0800 | [diff] [blame] | 2399 | get_random_bytes(__skb_put(head, head_len - sizeof(*hdr)), |
| 2400 | head_len - sizeof(*hdr)); |
developer | f7a3ca3 | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 2401 | @@ -153,7 +210,7 @@ int mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2402 | |
| 2403 | frag = alloc_skb(frag_len, GFP_KERNEL); |
| 2404 | if (!frag) { |
| 2405 | - mt76_testmode_free_skb(phy); |
| 2406 | + mt76_testmode_free_skb(tx_skb); |
| 2407 | dev_kfree_skb(head); |
| 2408 | return -ENOMEM; |
| 2409 | } |
developer | f7a3ca3 | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 2410 | @@ -166,15 +223,14 @@ int mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2411 | frag_tail = &(*frag_tail)->next; |
| 2412 | } |
| 2413 | |
| 2414 | - mt76_testmode_free_skb(phy); |
| 2415 | - td->tx_skb = head; |
| 2416 | + mt76_testmode_free_skb(tx_skb); |
| 2417 | + *tx_skb = head; |
| 2418 | |
| 2419 | return 0; |
| 2420 | } |
| 2421 | -EXPORT_SYMBOL(mt76_testmode_alloc_skb); |
| 2422 | |
| 2423 | -static int |
| 2424 | -mt76_testmode_tx_init(struct mt76_phy *phy) |
| 2425 | +int mt76_testmode_init_skb(struct mt76_phy *phy, u32 len, |
| 2426 | + struct sk_buff **tx_skb, u8 (*addr)[ETH_ALEN]) |
| 2427 | { |
| 2428 | struct mt76_testmode_data *td = &phy->test; |
| 2429 | struct ieee80211_tx_info *info; |
developer | f7a3ca3 | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 2430 | @@ -182,7 +238,7 @@ mt76_testmode_tx_init(struct mt76_phy *phy) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2431 | u8 max_nss = hweight8(phy->antenna_mask); |
| 2432 | int ret; |
| 2433 | |
| 2434 | - ret = mt76_testmode_alloc_skb(phy, td->tx_mpdu_len); |
| 2435 | + ret = mt76_testmode_alloc_skb(phy, len, tx_skb, addr); |
| 2436 | if (ret) |
| 2437 | return ret; |
| 2438 | |
developer | f7a3ca3 | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 2439 | @@ -192,7 +248,7 @@ mt76_testmode_tx_init(struct mt76_phy *phy) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2440 | if (td->tx_antenna_mask) |
| 2441 | max_nss = min_t(u8, max_nss, hweight8(td->tx_antenna_mask)); |
| 2442 | |
| 2443 | - info = IEEE80211_SKB_CB(td->tx_skb); |
| 2444 | + info = IEEE80211_SKB_CB(*tx_skb); |
| 2445 | rate = &info->control.rates[0]; |
| 2446 | rate->count = 1; |
| 2447 | rate->idx = td->tx_rate_idx; |
developer | f7a3ca3 | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 2448 | @@ -264,6 +320,25 @@ mt76_testmode_tx_init(struct mt76_phy *phy) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2449 | out: |
| 2450 | return 0; |
| 2451 | } |
| 2452 | +EXPORT_SYMBOL(mt76_testmode_init_skb); |
| 2453 | + |
| 2454 | +static int |
| 2455 | +mt76_testmode_tx_init(struct mt76_phy *phy) |
| 2456 | +{ |
| 2457 | + struct mt76_testmode_entry_data *ed; |
| 2458 | + struct mt76_wcid *wcid; |
| 2459 | + |
| 2460 | + mt76_tm_for_each_entry(phy, wcid, ed) { |
| 2461 | + int ret; |
| 2462 | + |
| 2463 | + ret = mt76_testmode_init_skb(phy, ed->tx_mpdu_len, |
| 2464 | + &ed->tx_skb, ed->addr); |
| 2465 | + if (ret) |
| 2466 | + return ret; |
| 2467 | + } |
| 2468 | + |
| 2469 | + return 0; |
| 2470 | +} |
| 2471 | |
| 2472 | static void |
| 2473 | mt76_testmode_tx_start(struct mt76_phy *phy) |
developer | f7a3ca3 | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 2474 | @@ -274,6 +349,14 @@ mt76_testmode_tx_start(struct mt76_phy *phy) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2475 | td->tx_queued = 0; |
| 2476 | td->tx_done = 0; |
| 2477 | td->tx_pending = td->tx_count; |
| 2478 | + if (td->tx_rate_mode == MT76_TM_TX_MODE_HE_MU) |
| 2479 | + td->tx_pending = 1; |
| 2480 | + if (td->entry_num) { |
| 2481 | + td->tx_pending *= td->entry_num; |
| 2482 | + td->cur_entry = list_first_entry(&td->tm_entry_list, |
| 2483 | + struct mt76_wcid, list); |
| 2484 | + } |
| 2485 | + |
| 2486 | mt76_worker_schedule(&dev->tx_worker); |
| 2487 | } |
| 2488 | |
developer | f7a3ca3 | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 2489 | @@ -292,7 +375,7 @@ mt76_testmode_tx_stop(struct mt76_phy *phy) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2490 | wait_event_timeout(dev->tx_wait, td->tx_done == td->tx_queued, |
| 2491 | MT76_TM_TIMEOUT * HZ); |
| 2492 | |
| 2493 | - mt76_testmode_free_skb(phy); |
| 2494 | + mt76_testmode_free_skb_all(phy); |
| 2495 | } |
| 2496 | |
| 2497 | static inline void |
developer | f7a3ca3 | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 2498 | @@ -323,6 +406,8 @@ mt76_testmode_init_defaults(struct mt76_phy *phy) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2499 | memcpy(td->addr[0], phy->macaddr, ETH_ALEN); |
| 2500 | memcpy(td->addr[1], phy->macaddr, ETH_ALEN); |
| 2501 | memcpy(td->addr[2], phy->macaddr, ETH_ALEN); |
| 2502 | + |
| 2503 | + INIT_LIST_HEAD(&phy->test.tm_entry_list); |
| 2504 | } |
| 2505 | |
| 2506 | static int |
developer | f7a3ca3 | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 2507 | @@ -332,8 +417,12 @@ __mt76_testmode_set_state(struct mt76_phy *phy, enum mt76_testmode_state state) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2508 | struct mt76_dev *dev = phy->dev; |
| 2509 | int err; |
| 2510 | |
| 2511 | - if (prev_state == MT76_TM_STATE_TX_FRAMES) |
| 2512 | + if (prev_state == MT76_TM_STATE_TX_FRAMES) { |
| 2513 | + /* MU needs to clean hwq for free done event */ |
| 2514 | + if (phy->test.tx_rate_mode == MT76_TM_TX_MODE_HE_MU) |
| 2515 | + dev->test_ops->set_state(phy, MT76_TM_STATE_IDLE); |
| 2516 | mt76_testmode_tx_stop(phy); |
| 2517 | + } |
| 2518 | |
| 2519 | if (state == MT76_TM_STATE_TX_FRAMES) { |
| 2520 | err = mt76_testmode_tx_init(phy); |
developer | f7a3ca3 | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 2521 | @@ -403,6 +492,44 @@ mt76_tm_get_u8(struct nlattr *attr, u8 *dest, u8 min, u8 max) |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2522 | return 0; |
| 2523 | } |
| 2524 | |
| 2525 | +static int |
| 2526 | +mt76_testmode_set_eeprom(struct mt76_phy *phy, struct nlattr **tb) |
| 2527 | +{ |
| 2528 | + struct mt76_dev *dev = phy->dev; |
| 2529 | + u8 action, val[MT76_TM_EEPROM_BLOCK_SIZE]; |
| 2530 | + u32 offset = 0; |
| 2531 | + int err = -EINVAL; |
| 2532 | + |
| 2533 | + if (!dev->test_ops->set_eeprom) |
| 2534 | + return -EOPNOTSUPP; |
| 2535 | + |
| 2536 | + if (mt76_tm_get_u8(tb[MT76_TM_ATTR_EEPROM_ACTION], &action, |
| 2537 | + 0, MT76_TM_EEPROM_ACTION_MAX)) |
| 2538 | + goto out; |
| 2539 | + |
| 2540 | + if (tb[MT76_TM_ATTR_EEPROM_OFFSET]) { |
| 2541 | + struct nlattr *cur; |
| 2542 | + int rem, idx = 0; |
| 2543 | + |
| 2544 | + offset = nla_get_u32(tb[MT76_TM_ATTR_EEPROM_OFFSET]); |
| 2545 | + if (!!(offset % MT76_TM_EEPROM_BLOCK_SIZE) || |
| 2546 | + !tb[MT76_TM_ATTR_EEPROM_VAL]) |
| 2547 | + goto out; |
| 2548 | + |
| 2549 | + nla_for_each_nested(cur, tb[MT76_TM_ATTR_EEPROM_VAL], rem) { |
| 2550 | + if (nla_len(cur) != 1 || idx >= ARRAY_SIZE(val)) |
| 2551 | + goto out; |
| 2552 | + |
| 2553 | + val[idx++] = nla_get_u8(cur); |
| 2554 | + } |
| 2555 | + } |
| 2556 | + |
| 2557 | + err = dev->test_ops->set_eeprom(phy, offset, val, action); |
| 2558 | + |
| 2559 | +out: |
| 2560 | + return err; |
| 2561 | +} |
| 2562 | + |
| 2563 | int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 2564 | void *data, int len) |
| 2565 | { |
developer | f7a3ca3 | 2022-09-01 14:44:55 +0800 | [diff] [blame] | 2566 | @@ -426,6 +553,11 @@ int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2567 | |
| 2568 | mutex_lock(&dev->mutex); |
| 2569 | |
| 2570 | + if (tb[MT76_TM_ATTR_EEPROM_ACTION]) { |
| 2571 | + err = mt76_testmode_set_eeprom(phy, tb); |
| 2572 | + goto out; |
| 2573 | + } |
| 2574 | + |
| 2575 | if (tb[MT76_TM_ATTR_RESET]) { |
| 2576 | mt76_testmode_set_state(phy, MT76_TM_STATE_OFF); |
| 2577 | memset(td, 0, sizeof(*td)); |
developer | 28b11e2 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 2578 | @@ -452,7 +584,10 @@ int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2579 | mt76_tm_get_u8(tb[MT76_TM_ATTR_TX_DUTY_CYCLE], |
| 2580 | &td->tx_duty_cycle, 0, 99) || |
| 2581 | mt76_tm_get_u8(tb[MT76_TM_ATTR_TX_POWER_CONTROL], |
| 2582 | - &td->tx_power_control, 0, 1)) |
| 2583 | + &td->tx_power_control, 0, 1) || |
| 2584 | + mt76_tm_get_u8(tb[MT76_TM_ATTR_AID], &td->aid, 0, 16) || |
| 2585 | + mt76_tm_get_u8(tb[MT76_TM_ATTR_RU_ALLOC], &td->ru_alloc, 0, 0xff) || |
| 2586 | + mt76_tm_get_u8(tb[MT76_TM_ATTR_RU_IDX], &td->ru_idx, 0, 68)) |
| 2587 | goto out; |
| 2588 | |
| 2589 | if (tb[MT76_TM_ATTR_TX_LENGTH]) { |
developer | 28b11e2 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 2590 | @@ -484,8 +619,7 @@ int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2591 | |
| 2592 | if (tb[MT76_TM_ATTR_TX_POWER]) { |
| 2593 | struct nlattr *cur; |
| 2594 | - int idx = 0; |
| 2595 | - int rem; |
| 2596 | + int rem, idx = 0; |
| 2597 | |
| 2598 | nla_for_each_nested(cur, tb[MT76_TM_ATTR_TX_POWER], rem) { |
| 2599 | if (nla_len(cur) != 1 || |
developer | 28b11e2 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 2600 | @@ -505,11 +639,45 @@ int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2601 | if (nla_len(cur) != ETH_ALEN || idx >= 3) |
| 2602 | goto out; |
| 2603 | |
| 2604 | - memcpy(td->addr[idx], nla_data(cur), ETH_ALEN); |
| 2605 | + memcpy(td->addr[idx++], nla_data(cur), ETH_ALEN); |
| 2606 | + } |
| 2607 | + } |
| 2608 | + |
| 2609 | + if (tb[MT76_TM_ATTR_CFG]) { |
| 2610 | + struct nlattr *cur; |
| 2611 | + int rem, idx = 0; |
| 2612 | + |
| 2613 | + nla_for_each_nested(cur, tb[MT76_TM_ATTR_CFG], rem) { |
| 2614 | + if (nla_len(cur) != 1 || idx >= 2) |
| 2615 | + goto out; |
| 2616 | + |
| 2617 | + if (idx == 0) |
| 2618 | + td->cfg.type = nla_get_u8(cur); |
| 2619 | + else |
| 2620 | + td->cfg.enable = nla_get_u8(cur); |
| 2621 | idx++; |
| 2622 | } |
| 2623 | } |
| 2624 | |
| 2625 | + if (tb[MT76_TM_ATTR_TXBF_ACT]) { |
| 2626 | + struct nlattr *cur; |
| 2627 | + int rem, idx = 0; |
| 2628 | + |
| 2629 | + if (!tb[MT76_TM_ATTR_TXBF_PARAM] || |
| 2630 | + mt76_tm_get_u8(tb[MT76_TM_ATTR_TXBF_ACT], &td->txbf_act, |
| 2631 | + 0, MT76_TM_TXBF_ACT_MAX)) |
| 2632 | + goto out; |
| 2633 | + |
| 2634 | + memset(td->txbf_param, 0, sizeof(td->txbf_param)); |
| 2635 | + nla_for_each_nested(cur, tb[MT76_TM_ATTR_TXBF_PARAM], rem) { |
| 2636 | + if (nla_len(cur) != 2 || |
| 2637 | + idx >= ARRAY_SIZE(td->txbf_param)) |
| 2638 | + goto out; |
| 2639 | + |
| 2640 | + td->txbf_param[idx++] = nla_get_u16(cur); |
| 2641 | + } |
| 2642 | + } |
| 2643 | + |
| 2644 | if (dev->test_ops->set_params) { |
| 2645 | err = dev->test_ops->set_params(phy, tb, state); |
| 2646 | if (err) |
developer | 28b11e2 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 2647 | @@ -574,6 +742,7 @@ int mt76_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *msg, |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2648 | struct mt76_phy *phy = hw->priv; |
| 2649 | struct mt76_dev *dev = phy->dev; |
| 2650 | struct mt76_testmode_data *td = &phy->test; |
| 2651 | + struct mt76_testmode_entry_data *ed = &td->ed; |
| 2652 | struct nlattr *tb[NUM_MT76_TM_ATTRS] = {}; |
| 2653 | int err = 0; |
| 2654 | void *a; |
developer | 28b11e2 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 2655 | @@ -606,6 +775,19 @@ int mt76_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *msg, |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2656 | goto out; |
| 2657 | } |
| 2658 | |
| 2659 | + if (tb[MT76_TM_ATTR_AID]) { |
| 2660 | + struct mt76_wcid *wcid; |
| 2661 | + u8 aid; |
| 2662 | + |
| 2663 | + err = mt76_tm_get_u8(tb[MT76_TM_ATTR_AID], &aid, 1, 16); |
| 2664 | + if (err) |
| 2665 | + goto out; |
| 2666 | + |
| 2667 | + mt76_tm_for_each_entry(phy, wcid, ed) |
| 2668 | + if (ed->aid == aid) |
| 2669 | + ed = mt76_testmode_entry_data(phy, wcid); |
| 2670 | + } |
| 2671 | + |
| 2672 | mt76_testmode_init_defaults(phy); |
| 2673 | |
| 2674 | err = -EMSGSIZE; |
developer | 28b11e2 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 2675 | @@ -618,12 +800,8 @@ int mt76_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *msg, |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2676 | goto out; |
| 2677 | |
| 2678 | if (nla_put_u32(msg, MT76_TM_ATTR_TX_COUNT, td->tx_count) || |
| 2679 | - nla_put_u32(msg, MT76_TM_ATTR_TX_LENGTH, td->tx_mpdu_len) || |
| 2680 | nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_MODE, td->tx_rate_mode) || |
| 2681 | - nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_NSS, td->tx_rate_nss) || |
| 2682 | - nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_IDX, td->tx_rate_idx) || |
| 2683 | nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_SGI, td->tx_rate_sgi) || |
| 2684 | - nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_LDPC, td->tx_rate_ldpc) || |
| 2685 | nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_STBC, td->tx_rate_stbc) || |
| 2686 | (mt76_testmode_param_present(td, MT76_TM_ATTR_TX_LTF) && |
| 2687 | nla_put_u8(msg, MT76_TM_ATTR_TX_LTF, td->tx_ltf)) || |
developer | 28b11e2 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 2688 | @@ -643,6 +821,15 @@ int mt76_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *msg, |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2689 | nla_put_u8(msg, MT76_TM_ATTR_FREQ_OFFSET, td->freq_offset))) |
| 2690 | goto out; |
| 2691 | |
| 2692 | + if (nla_put_u32(msg, MT76_TM_ATTR_TX_LENGTH, ed->tx_mpdu_len) || |
| 2693 | + nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_NSS, ed->tx_rate_nss) || |
| 2694 | + nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_IDX, ed->tx_rate_idx) || |
| 2695 | + nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_LDPC, ed->tx_rate_ldpc) || |
| 2696 | + nla_put_u8(msg, MT76_TM_ATTR_AID, ed->aid) || |
| 2697 | + nla_put_u8(msg, MT76_TM_ATTR_RU_ALLOC, ed->ru_alloc) || |
| 2698 | + nla_put_u8(msg, MT76_TM_ATTR_RU_IDX, ed->ru_idx)) |
| 2699 | + goto out; |
| 2700 | + |
| 2701 | if (mt76_testmode_param_present(td, MT76_TM_ATTR_TX_POWER)) { |
| 2702 | a = nla_nest_start(msg, MT76_TM_ATTR_TX_POWER); |
| 2703 | if (!a) |
| 2704 | diff --git a/testmode.h b/testmode.h |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 2705 | index 8961326..57949f2 100644 |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2706 | --- a/testmode.h |
| 2707 | +++ b/testmode.h |
| 2708 | @@ -6,6 +6,8 @@ |
| 2709 | #define __MT76_TESTMODE_H |
| 2710 | |
| 2711 | #define MT76_TM_TIMEOUT 10 |
| 2712 | +#define MT76_TM_MAX_ENTRY_NUM 16 |
| 2713 | +#define MT76_TM_EEPROM_BLOCK_SIZE 16 |
| 2714 | |
| 2715 | /** |
| 2716 | * enum mt76_testmode_attr - testmode attributes inside NL80211_ATTR_TESTDATA |
| 2717 | @@ -47,6 +49,15 @@ |
| 2718 | * @MT76_TM_ATTR_DRV_DATA: driver specific netlink attrs (nested) |
| 2719 | * |
| 2720 | * @MT76_TM_ATTR_MAC_ADDRS: array of nested MAC addresses (nested) |
| 2721 | + * |
| 2722 | + * @MT76_TM_ATTR_EEPROM_ACTION: eeprom setting actions |
| 2723 | + * (u8, see &enum mt76_testmode_eeprom_action) |
| 2724 | + * @MT76_TM_ATTR_EEPROM_OFFSET: offset of eeprom data block for writing (u32) |
| 2725 | + * @MT76_TM_ATTR_EEPROM_VAL: values for writing into a 16-byte data block |
| 2726 | + * (nested, u8 attrs) |
| 2727 | + * |
| 2728 | + * @MT76_TM_ATTR_CFG: config testmode rf feature (nested, see &mt76_testmode_cfg) |
| 2729 | + * |
| 2730 | */ |
| 2731 | enum mt76_testmode_attr { |
| 2732 | MT76_TM_ATTR_UNSPEC, |
| 2733 | @@ -84,6 +95,17 @@ enum mt76_testmode_attr { |
| 2734 | MT76_TM_ATTR_DRV_DATA, |
| 2735 | |
| 2736 | MT76_TM_ATTR_MAC_ADDRS, |
| 2737 | + MT76_TM_ATTR_AID, |
| 2738 | + MT76_TM_ATTR_RU_ALLOC, |
| 2739 | + MT76_TM_ATTR_RU_IDX, |
| 2740 | + |
| 2741 | + MT76_TM_ATTR_EEPROM_ACTION, |
| 2742 | + MT76_TM_ATTR_EEPROM_OFFSET, |
| 2743 | + MT76_TM_ATTR_EEPROM_VAL, |
| 2744 | + |
| 2745 | + MT76_TM_ATTR_CFG, |
| 2746 | + MT76_TM_ATTR_TXBF_ACT, |
| 2747 | + MT76_TM_ATTR_TXBF_PARAM, |
| 2748 | |
| 2749 | /* keep last */ |
| 2750 | NUM_MT76_TM_ATTRS, |
| 2751 | @@ -198,4 +220,57 @@ enum mt76_testmode_tx_mode { |
| 2752 | |
| 2753 | extern const struct nla_policy mt76_tm_policy[NUM_MT76_TM_ATTRS]; |
| 2754 | |
| 2755 | +/** |
| 2756 | + * enum mt76_testmode_eeprom_action - eeprom setting actions |
| 2757 | + * |
| 2758 | + * @MT76_TM_EEPROM_ACTION_UPDATE_DATA: update rf values to specific |
| 2759 | + * eeprom data block |
| 2760 | + * @MT76_TM_EEPROM_ACTION_UPDATE_BUFFER_MODE: send updated eeprom data to fw |
| 2761 | + * @MT76_TM_EEPROM_ACTION_WRITE_TO_EFUSE: write eeprom data back to efuse |
| 2762 | + */ |
| 2763 | +enum mt76_testmode_eeprom_action { |
| 2764 | + MT76_TM_EEPROM_ACTION_UPDATE_DATA, |
| 2765 | + MT76_TM_EEPROM_ACTION_UPDATE_BUFFER_MODE, |
| 2766 | + MT76_TM_EEPROM_ACTION_WRITE_TO_EFUSE, |
| 2767 | + |
| 2768 | + /* keep last */ |
| 2769 | + NUM_MT76_TM_EEPROM_ACTION, |
| 2770 | + MT76_TM_EEPROM_ACTION_MAX = NUM_MT76_TM_EEPROM_ACTION - 1, |
| 2771 | +}; |
| 2772 | + |
| 2773 | +/** |
| 2774 | + * enum mt76_testmode_cfg - packet tx phy mode |
| 2775 | + * |
| 2776 | + * @MT76_TM_EEPROM_ACTION_UPDATE_DATA: update rf values to specific |
| 2777 | + * eeprom data block |
| 2778 | + * @MT76_TM_EEPROM_ACTION_UPDATE_BUFFER_MODE: send updated eeprom data to fw |
| 2779 | + * @MT76_TM_EEPROM_ACTION_WRITE_TO_EFUSE: write eeprom data back to efuse |
| 2780 | + */ |
| 2781 | +enum mt76_testmode_cfg { |
| 2782 | + MT76_TM_CFG_TSSI, |
| 2783 | + MT76_TM_CFG_DPD, |
| 2784 | + MT76_TM_CFG_RATE_POWER_OFFSET, |
| 2785 | + MT76_TM_CFG_THERMAL_COMP, |
| 2786 | + |
| 2787 | + /* keep last */ |
| 2788 | + NUM_MT76_TM_CFG, |
| 2789 | + MT76_TM_CFG_MAX = NUM_MT76_TM_CFG - 1, |
| 2790 | +}; |
| 2791 | + |
| 2792 | +enum mt76_testmode_txbf_act { |
| 2793 | + MT76_TM_TXBF_ACT_INIT, |
| 2794 | + MT76_TM_TXBF_ACT_UPDATE_CH, |
| 2795 | + MT76_TM_TXBF_ACT_PHASE_COMP, |
| 2796 | + MT76_TM_TXBF_ACT_TX_PREP, |
| 2797 | + MT76_TM_TXBF_ACT_IBF_PROF_UPDATE, |
| 2798 | + MT76_TM_TXBF_ACT_EBF_PROF_UPDATE, |
| 2799 | + MT76_TM_TXBF_ACT_PHASE_CAL, |
| 2800 | + MT76_TM_TXBF_ACT_PROF_UPDATE_ALL, |
| 2801 | + MT76_TM_TXBF_ACT_E2P_UPDATE, |
| 2802 | + |
| 2803 | + /* keep last */ |
| 2804 | + NUM_MT76_TM_TXBF_ACT, |
| 2805 | + MT76_TM_TXBF_ACT_MAX = NUM_MT76_TM_TXBF_ACT - 1, |
| 2806 | +}; |
| 2807 | + |
| 2808 | #endif |
| 2809 | diff --git a/tools/fields.c b/tools/fields.c |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 2810 | index e3f6908..6e36ab2 100644 |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2811 | --- a/tools/fields.c |
| 2812 | +++ b/tools/fields.c |
| 2813 | @@ -10,6 +10,7 @@ static const char * const testmode_state[] = { |
| 2814 | [MT76_TM_STATE_IDLE] = "idle", |
| 2815 | [MT76_TM_STATE_TX_FRAMES] = "tx_frames", |
| 2816 | [MT76_TM_STATE_RX_FRAMES] = "rx_frames", |
| 2817 | + [MT76_TM_STATE_TX_CONT] = "tx_cont", |
| 2818 | }; |
| 2819 | |
| 2820 | static const char * const testmode_tx_mode[] = { |
| 2821 | @@ -201,6 +202,63 @@ static void print_extra_stats(const struct tm_field *field, struct nlattr **tb) |
| 2822 | printf("%srx_per=%.02f%%\n", prefix, 100 * failed / total); |
| 2823 | } |
| 2824 | |
| 2825 | +static bool parse_mac(const struct tm_field *field, int idx, |
| 2826 | + struct nl_msg *msg, const char *val) |
| 2827 | +{ |
| 2828 | +#define ETH_ALEN 6 |
| 2829 | + bool ret = true; |
| 2830 | + char *str, *cur, *ap; |
| 2831 | + void *a; |
| 2832 | + |
| 2833 | + ap = str = strdup(val); |
| 2834 | + |
| 2835 | + a = nla_nest_start(msg, idx); |
| 2836 | + |
| 2837 | + idx = 0; |
| 2838 | + while ((cur = strsep(&ap, ",")) != NULL) { |
| 2839 | + unsigned char addr[ETH_ALEN]; |
| 2840 | + char *val, *tmp = cur; |
| 2841 | + int i = 0; |
| 2842 | + |
| 2843 | + while ((val = strsep(&tmp, ":")) != NULL) { |
| 2844 | + if (i >= ETH_ALEN) |
| 2845 | + break; |
| 2846 | + |
| 2847 | + addr[i++] = strtoul(val, NULL, 16); |
| 2848 | + } |
| 2849 | + |
| 2850 | + nla_put(msg, idx, ETH_ALEN, addr); |
| 2851 | + |
| 2852 | + idx++; |
| 2853 | + } |
| 2854 | + |
| 2855 | + nla_nest_end(msg, a); |
| 2856 | + |
| 2857 | + free(str); |
| 2858 | + |
| 2859 | + return ret; |
| 2860 | +} |
| 2861 | + |
| 2862 | +static void print_mac(const struct tm_field *field, struct nlattr *attr) |
| 2863 | +{ |
| 2864 | +#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] |
| 2865 | +#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x" |
| 2866 | + unsigned char addr[3][6]; |
| 2867 | + struct nlattr *cur; |
| 2868 | + int idx = 0; |
| 2869 | + int rem; |
| 2870 | + |
| 2871 | + nla_for_each_nested(cur, attr, rem) { |
| 2872 | + if (nla_len(cur) != 6) |
| 2873 | + continue; |
| 2874 | + memcpy(addr[idx++], nla_data(cur), 6); |
| 2875 | + } |
| 2876 | + |
| 2877 | + printf("" MACSTR "," MACSTR "," MACSTR "", |
| 2878 | + MAC2STR(addr[0]), MAC2STR(addr[1]), MAC2STR(addr[2])); |
| 2879 | + |
| 2880 | + return; |
| 2881 | +} |
| 2882 | |
| 2883 | #define FIELD_GENERIC(_field, _name, ...) \ |
| 2884 | [FIELD_NAME(_field)] = { \ |
| 2885 | @@ -250,6 +308,13 @@ static void print_extra_stats(const struct tm_field *field, struct nlattr **tb) |
| 2886 | ##__VA_ARGS__ \ |
| 2887 | ) |
| 2888 | |
| 2889 | +#define FIELD_MAC(_field, _name) \ |
| 2890 | + [FIELD_NAME(_field)] = { \ |
| 2891 | + .name = _name, \ |
| 2892 | + .parse = parse_mac, \ |
| 2893 | + .print = print_mac \ |
| 2894 | + } |
| 2895 | + |
| 2896 | #define FIELD_NAME(_field) MT76_TM_RX_ATTR_##_field |
| 2897 | static const struct tm_field rx_fields[NUM_MT76_TM_RX_ATTRS] = { |
| 2898 | FIELD_RO(s32, FREQ_OFFSET, "freq_offset"), |
| 2899 | @@ -300,10 +365,18 @@ static const struct tm_field testdata_fields[NUM_MT76_TM_ATTRS] = { |
| 2900 | FIELD(u8, TX_RATE_LDPC, "tx_rate_ldpc"), |
| 2901 | FIELD(u8, TX_RATE_STBC, "tx_rate_stbc"), |
| 2902 | FIELD(u8, TX_LTF, "tx_ltf"), |
| 2903 | + FIELD(u8, TX_DUTY_CYCLE, "tx_duty_cycle"), |
| 2904 | + FIELD(u32, TX_IPG, "tx_ipg"), |
| 2905 | + FIELD(u32, TX_TIME, "tx_time"), |
| 2906 | FIELD(u8, TX_POWER_CONTROL, "tx_power_control"), |
| 2907 | FIELD_ARRAY(u8, TX_POWER, "tx_power"), |
| 2908 | FIELD(u8, TX_ANTENNA, "tx_antenna"), |
| 2909 | + FIELD(u8, TX_SPE_IDX, "tx_spe_idx"), |
| 2910 | FIELD(u32, FREQ_OFFSET, "freq_offset"), |
| 2911 | + FIELD(u8, AID, "aid"), |
| 2912 | + FIELD(u8, RU_ALLOC, "ru_alloc"), |
| 2913 | + FIELD(u8, RU_IDX, "ru_idx"), |
| 2914 | + FIELD_MAC(MAC_ADDRS, "mac_addrs"), |
| 2915 | FIELD_NESTED_RO(STATS, stats, "", |
| 2916 | .print_extra = print_extra_stats), |
| 2917 | }; |
| 2918 | @@ -322,9 +395,16 @@ static struct nla_policy testdata_policy[NUM_MT76_TM_ATTRS] = { |
| 2919 | [MT76_TM_ATTR_TX_RATE_LDPC] = { .type = NLA_U8 }, |
| 2920 | [MT76_TM_ATTR_TX_RATE_STBC] = { .type = NLA_U8 }, |
| 2921 | [MT76_TM_ATTR_TX_LTF] = { .type = NLA_U8 }, |
| 2922 | + [MT76_TM_ATTR_TX_DUTY_CYCLE] = { .type = NLA_U8 }, |
| 2923 | + [MT76_TM_ATTR_TX_IPG] = { .type = NLA_U32 }, |
| 2924 | + [MT76_TM_ATTR_TX_TIME] = { .type = NLA_U32 }, |
| 2925 | [MT76_TM_ATTR_TX_POWER_CONTROL] = { .type = NLA_U8 }, |
| 2926 | [MT76_TM_ATTR_TX_ANTENNA] = { .type = NLA_U8 }, |
| 2927 | + [MT76_TM_ATTR_TX_SPE_IDX] = { .type = NLA_U8 }, |
| 2928 | [MT76_TM_ATTR_FREQ_OFFSET] = { .type = NLA_U32 }, |
| 2929 | + [MT76_TM_ATTR_AID] = { .type = NLA_U8 }, |
| 2930 | + [MT76_TM_ATTR_RU_ALLOC] = { .type = NLA_U8 }, |
| 2931 | + [MT76_TM_ATTR_RU_IDX] = { .type = NLA_U8 }, |
| 2932 | [MT76_TM_ATTR_STATS] = { .type = NLA_NESTED }, |
| 2933 | }; |
| 2934 | |
| 2935 | diff --git a/tx.c b/tx.c |
developer | bb6ddff | 2023-03-08 17:22:32 +0800 | [diff] [blame^] | 2936 | index 1f309d0..6d55566 100644 |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2937 | --- a/tx.c |
| 2938 | +++ b/tx.c |
developer | 17bb0a8 | 2022-12-13 15:52:04 +0800 | [diff] [blame] | 2939 | @@ -250,8 +250,7 @@ void __mt76_tx_complete_skb(struct mt76_dev *dev, u16 wcid_idx, struct sk_buff * |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2940 | if (mt76_is_testmode_skb(dev, skb, &hw)) { |
| 2941 | struct mt76_phy *phy = hw->priv; |
| 2942 | |
| 2943 | - if (skb == phy->test.tx_skb) |
| 2944 | - phy->test.tx_done++; |
| 2945 | + phy->test.tx_done++; |
| 2946 | if (phy->test.tx_queued == phy->test.tx_done) |
| 2947 | wake_up(&dev->tx_wait); |
| 2948 | |
| 2949 | -- |
developer | 3f78457 | 2023-01-31 15:21:28 +0800 | [diff] [blame] | 2950 | 2.18.0 |
developer | 6caa5e2 | 2022-06-16 13:33:13 +0800 | [diff] [blame] | 2951 | |