blob: ca61e6ed6ced7caf902a967f9d0f4aab29138a0d [file] [log] [blame]
developere35b8e42023-10-16 11:04:00 +08001From 555abaed13e0426eb3295c7f7b02de57320a63e6 Mon Sep 17 00:00:00 2001
developer42b63282022-06-16 13:33:13 +08002From: Shayne Chen <shayne.chen@mediatek.com>
3Date: Thu, 21 Apr 2022 15:43:19 +0800
developer2a209692023-08-14 20:23:42 +08004Subject: [PATCH] wifi: mt76: testmode: additional supports
developer42b63282022-06-16 13:33:13 +08005
6Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
developerf8871e82023-03-08 17:22:32 +08007Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
developer42b63282022-06-16 13:33:13 +08008---
developer4df64ba2022-09-01 14:44:55 +08009 dma.c | 3 +-
10 mac80211.c | 12 +
developere35b8e42023-10-16 11:04:00 +080011 mt76.h | 110 +++-
developer4df64ba2022-09-01 14:44:55 +080012 mt76_connac_mcu.c | 4 +
13 mt76_connac_mcu.h | 2 +
developerae9afc02023-04-06 18:07:42 +080014 mt7915/eeprom.c | 2 +-
developer4df64ba2022-09-01 14:44:55 +080015 mt7915/init.c | 2 +-
developere35b8e42023-10-16 11:04:00 +080016 mt7915/mac.c | 40 +-
developer4df64ba2022-09-01 14:44:55 +080017 mt7915/main.c | 2 +-
developer281084d2023-06-19 12:03:50 +080018 mt7915/mcu.c | 22 +-
developerc07d01e2023-05-05 13:45:43 +080019 mt7915/mcu.h | 29 +-
developer4df64ba2022-09-01 14:44:55 +080020 mt7915/mmio.c | 2 +
developere35b8e42023-10-16 11:04:00 +080021 mt7915/mt7915.h | 17 +-
developer4df64ba2022-09-01 14:44:55 +080022 mt7915/regs.h | 3 +
developere35b8e42023-10-16 11:04:00 +080023 mt7915/testmode.c | 1238 ++++++++++++++++++++++++++++++++++++++++++---
24 mt7915/testmode.h | 278 ++++++++++
25 testmode.c | 287 +++++++++--
26 testmode.h | 79 +++
27 tools/fields.c | 90 +++-
developer4df64ba2022-09-01 14:44:55 +080028 tx.c | 3 +-
developere35b8e42023-10-16 11:04:00 +080029 20 files changed, 2058 insertions(+), 167 deletions(-)
developer42b63282022-06-16 13:33:13 +080030
31diff --git a/dma.c b/dma.c
developere35b8e42023-10-16 11:04:00 +080032index 24b44e7..8049830 100644
developer42b63282022-06-16 13:33:13 +080033--- a/dma.c
34+++ b/dma.c
developere35b8e42023-10-16 11:04:00 +080035@@ -576,8 +576,7 @@ free:
developer42b63282022-06-16 13:33:13 +080036 if (mt76_is_testmode_skb(dev, skb, &hw)) {
37 struct mt76_phy *phy = hw->priv;
38
39- if (tx_info.skb == phy->test.tx_skb)
40- phy->test.tx_done--;
41+ phy->test.tx_done--;
42 }
43 #endif
44
45diff --git a/mac80211.c b/mac80211.c
developere35b8e42023-10-16 11:04:00 +080046index 430ed1c..fccf26d 100644
developer42b63282022-06-16 13:33:13 +080047--- a/mac80211.c
48+++ b/mac80211.c
developera43cc482023-04-17 15:57:28 +080049@@ -55,6 +55,13 @@ static const struct ieee80211_channel mt76_channels_5ghz[] = {
developer42b63282022-06-16 13:33:13 +080050 CHAN5G(60, 5300),
51 CHAN5G(64, 5320),
52
53+ CHAN5G(68, 5340),
54+ CHAN5G(80, 5400),
55+ CHAN5G(84, 5420),
56+ CHAN5G(88, 5440),
57+ CHAN5G(92, 5460),
58+ CHAN5G(96, 5480),
59+
60 CHAN5G(100, 5500),
61 CHAN5G(104, 5520),
62 CHAN5G(108, 5540),
developer004e50c2023-06-29 20:33:22 +080063@@ -76,6 +83,11 @@ static const struct ieee80211_channel mt76_channels_5ghz[] = {
developer42b63282022-06-16 13:33:13 +080064 CHAN5G(169, 5845),
65 CHAN5G(173, 5865),
developer004e50c2023-06-29 20:33:22 +080066 CHAN5G(177, 5885),
developer42b63282022-06-16 13:33:13 +080067+
68+ CHAN5G(184, 4920),
69+ CHAN5G(188, 4940),
70+ CHAN5G(192, 4960),
71+ CHAN5G(196, 4980),
72 };
73
74 static const struct ieee80211_channel mt76_channels_6ghz[] = {
75diff --git a/mt76.h b/mt76.h
developere35b8e42023-10-16 11:04:00 +080076index d66f4d0..597488d 100644
developer42b63282022-06-16 13:33:13 +080077--- a/mt76.h
78+++ b/mt76.h
developere35b8e42023-10-16 11:04:00 +080079@@ -670,6 +670,21 @@ struct mt76_testmode_ops {
developer42b63282022-06-16 13:33:13 +080080 int (*set_params)(struct mt76_phy *phy, struct nlattr **tb,
81 enum mt76_testmode_state new_state);
82 int (*dump_stats)(struct mt76_phy *phy, struct sk_buff *msg);
83+ int (*set_eeprom)(struct mt76_phy *phy, u32 offset, u8 *val, u8 action);
84+};
85+
86+struct mt76_testmode_entry_data {
87+ struct sk_buff *tx_skb;
88+
89+ u16 tx_mpdu_len;
90+ u8 tx_rate_idx;
91+ u8 tx_rate_nss;
92+ u8 tx_rate_ldpc;
93+
94+ u8 addr[3][ETH_ALEN];
95+ u8 aid;
96+ u8 ru_alloc;
97+ u8 ru_idx;
98 };
99
100 #define MT_TM_FW_RX_COUNT BIT(0)
developere35b8e42023-10-16 11:04:00 +0800101@@ -678,16 +693,13 @@ struct mt76_testmode_data {
developer42b63282022-06-16 13:33:13 +0800102 enum mt76_testmode_state state;
103
104 u32 param_set[DIV_ROUND_UP(NUM_MT76_TM_ATTRS, 32)];
105- struct sk_buff *tx_skb;
developere35b8e42023-10-16 11:04:00 +0800106+
107+ u8 sku_en;
developer42b63282022-06-16 13:33:13 +0800108
109 u32 tx_count;
110- u16 tx_mpdu_len;
111
112 u8 tx_rate_mode;
113- u8 tx_rate_idx;
114- u8 tx_rate_nss;
115 u8 tx_rate_sgi;
116- u8 tx_rate_ldpc;
117 u8 tx_rate_stbc;
118 u8 tx_ltf;
119
developere35b8e42023-10-16 11:04:00 +0800120@@ -703,10 +715,37 @@ struct mt76_testmode_data {
developer42b63282022-06-16 13:33:13 +0800121 u8 tx_power[4];
122 u8 tx_power_control;
123
124- u8 addr[3][ETH_ALEN];
125+ struct list_head tm_entry_list;
126+ struct mt76_wcid *cur_entry;
127+ u8 entry_num;
128+ union {
129+ struct mt76_testmode_entry_data ed;
130+ struct {
131+ /* must be the same as mt76_testmode_entry_data */
132+ struct sk_buff *tx_skb;
133+
134+ u16 tx_mpdu_len;
135+ u8 tx_rate_idx;
136+ u8 tx_rate_nss;
137+ u8 tx_rate_ldpc;
138+
139+ u8 addr[3][ETH_ALEN];
140+ u8 aid;
141+ u8 ru_alloc;
142+ u8 ru_idx;
143+ };
144+ };
145
146 u8 flag;
147
148+ struct {
149+ u8 type;
150+ u8 enable;
151+ } cfg;
152+
153+ u8 txbf_act;
154+ u16 txbf_param[8];
155+
156 u32 tx_pending;
157 u32 tx_queued;
158 u16 tx_queued_limit;
developere35b8e42023-10-16 11:04:00 +0800159@@ -1276,6 +1315,59 @@ static inline bool mt76_testmode_enabled(struct mt76_phy *phy)
developer42b63282022-06-16 13:33:13 +0800160 #endif
161 }
162
163+#ifdef CONFIG_NL80211_TESTMODE
164+static inline struct mt76_wcid *
165+mt76_testmode_first_entry(struct mt76_phy *phy)
166+{
167+ if (list_empty(&phy->test.tm_entry_list) && !phy->test.aid)
168+ return &phy->dev->global_wcid;
169+
170+ return list_first_entry(&phy->test.tm_entry_list,
171+ typeof(struct mt76_wcid),
172+ list);
173+}
174+
175+static inline struct mt76_testmode_entry_data *
176+mt76_testmode_entry_data(struct mt76_phy *phy, struct mt76_wcid *wcid)
177+{
178+ if (!wcid)
179+ return NULL;
180+ if (wcid == &phy->dev->global_wcid)
181+ return &phy->test.ed;
182+
183+ return (struct mt76_testmode_entry_data *)((u8 *)wcid +
184+ phy->hw->sta_data_size);
185+}
186+
187+#define mt76_tm_for_each_entry(phy, wcid, ed) \
188+ for (wcid = mt76_testmode_first_entry(phy), \
189+ ed = mt76_testmode_entry_data(phy, wcid); \
190+ ((phy->test.aid && \
191+ !list_entry_is_head(wcid, &phy->test.tm_entry_list, list)) || \
192+ (!phy->test.aid && wcid == &phy->dev->global_wcid)) && ed; \
193+ wcid = list_next_entry(wcid, list), \
194+ ed = mt76_testmode_entry_data(phy, wcid))
195+#endif
196+
197+static inline bool __mt76_is_testmode_skb(struct mt76_phy *phy,
198+ struct sk_buff *skb)
199+{
200+#ifdef CONFIG_NL80211_TESTMODE
201+ struct mt76_testmode_entry_data *ed = &phy->test.ed;
202+ struct mt76_wcid *wcid;
203+
204+ if (skb == ed->tx_skb)
205+ return true;
206+
207+ mt76_tm_for_each_entry(phy, wcid, ed)
208+ if (skb == ed->tx_skb)
209+ return true;
210+ return false;
211+#else
212+ return false;
213+#endif
214+}
215+
216 static inline bool mt76_is_testmode_skb(struct mt76_dev *dev,
217 struct sk_buff *skb,
218 struct ieee80211_hw **hw)
developere35b8e42023-10-16 11:04:00 +0800219@@ -1286,7 +1378,8 @@ static inline bool mt76_is_testmode_skb(struct mt76_dev *dev,
developer4df64ba2022-09-01 14:44:55 +0800220 for (i = 0; i < ARRAY_SIZE(dev->phys); i++) {
221 struct mt76_phy *phy = dev->phys[i];
222
223- if (phy && skb == phy->test.tx_skb) {
224+ if (phy && mt76_testmode_enabled(phy) &&
225+ __mt76_is_testmode_skb(phy, skb)) {
226 *hw = dev->phys[i]->hw;
227 return true;
228 }
developere35b8e42023-10-16 11:04:00 +0800229@@ -1388,7 +1481,8 @@ int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
developer42b63282022-06-16 13:33:13 +0800230 int mt76_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *skb,
231 struct netlink_callback *cb, void *data, int len);
232 int mt76_testmode_set_state(struct mt76_phy *phy, enum mt76_testmode_state state);
233-int mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len);
234+int mt76_testmode_init_skb(struct mt76_phy *phy, u32 len,
235+ struct sk_buff **tx_skb, u8 (*addr)[ETH_ALEN]);
236
237 static inline void mt76_testmode_reset(struct mt76_phy *phy, bool disable)
238 {
239diff --git a/mt76_connac_mcu.c b/mt76_connac_mcu.c
developere35b8e42023-10-16 11:04:00 +0800240index f06a81d..60e159c 100644
developer42b63282022-06-16 13:33:13 +0800241--- a/mt76_connac_mcu.c
242+++ b/mt76_connac_mcu.c
developere35b8e42023-10-16 11:04:00 +0800243@@ -396,6 +396,7 @@ void mt76_connac_mcu_sta_basic_tlv(struct mt76_dev *dev, struct sk_buff *skb,
developer42b63282022-06-16 13:33:13 +0800244 switch (vif->type) {
245 case NL80211_IFTYPE_MESH_POINT:
246 case NL80211_IFTYPE_AP:
247+ case NL80211_IFTYPE_MONITOR:
developerad9333b2023-05-22 15:16:16 +0800248 if (vif->p2p && !is_mt7921(dev))
developer42b63282022-06-16 13:33:13 +0800249 conn_type = CONNECTION_P2P_GC;
250 else
developere35b8e42023-10-16 11:04:00 +0800251@@ -577,6 +578,9 @@ void mt76_connac_mcu_wtbl_generic_tlv(struct mt76_dev *dev,
developer42b63282022-06-16 13:33:13 +0800252 rx->rca2 = 1;
253 rx->rv = 1;
254
255+ if (vif->type == NL80211_IFTYPE_MONITOR)
256+ rx->rca1 = 0;
257+
258 if (!is_connac_v1(dev))
259 return;
260
261diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
developere35b8e42023-10-16 11:04:00 +0800262index cb68141..7a7dbf4 100644
developer42b63282022-06-16 13:33:13 +0800263--- a/mt76_connac_mcu.h
264+++ b/mt76_connac_mcu.h
developere35b8e42023-10-16 11:04:00 +0800265@@ -1002,6 +1002,7 @@ enum {
developer42b63282022-06-16 13:33:13 +0800266 MCU_EXT_EVENT_FW_LOG_2_HOST = 0x13,
267 MCU_EXT_EVENT_THERMAL_PROTECT = 0x22,
268 MCU_EXT_EVENT_ASSERT_DUMP = 0x23,
269+ MCU_EXT_EVENT_BF_STATUS_READ = 0x35,
270 MCU_EXT_EVENT_RDD_REPORT = 0x3a,
271 MCU_EXT_EVENT_CSA_NOTIFY = 0x4f,
developer004e50c2023-06-29 20:33:22 +0800272 MCU_EXT_EVENT_WA_TX_STAT = 0x74,
developere35b8e42023-10-16 11:04:00 +0800273@@ -1211,6 +1212,7 @@ enum {
developer42b63282022-06-16 13:33:13 +0800274 MCU_EXT_CMD_PHY_STAT_INFO = 0xad,
275 /* for vendor csi and air monitor */
276 MCU_EXT_CMD_SMESH_CTRL = 0xae,
277+ MCU_EXT_CMD_RX_STAT_USER_CTRL = 0xb3,
278 MCU_EXT_CMD_CERT_CFG = 0xb7,
279 MCU_EXT_CMD_CSI_CTRL = 0xc2,
280 };
developerae9afc02023-04-06 18:07:42 +0800281diff --git a/mt7915/eeprom.c b/mt7915/eeprom.c
developere35b8e42023-10-16 11:04:00 +0800282index 76be730..f5ab331 100644
developerae9afc02023-04-06 18:07:42 +0800283--- a/mt7915/eeprom.c
284+++ b/mt7915/eeprom.c
developerad9333b2023-05-22 15:16:16 +0800285@@ -131,7 +131,7 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev)
developerae9afc02023-04-06 18:07:42 +0800286 /* read eeprom data from efuse */
287 block_num = DIV_ROUND_UP(eeprom_size, eeprom_blk_size);
288 for (i = 0; i < block_num; i++) {
289- ret = mt7915_mcu_get_eeprom(dev, i * eeprom_blk_size);
290+ ret = mt7915_mcu_get_eeprom(dev, i * eeprom_blk_size, NULL);
291 if (ret < 0)
292 return ret;
293 }
developer42b63282022-06-16 13:33:13 +0800294diff --git a/mt7915/init.c b/mt7915/init.c
developere35b8e42023-10-16 11:04:00 +0800295index 607d881..d908a58 100644
developer42b63282022-06-16 13:33:13 +0800296--- a/mt7915/init.c
297+++ b/mt7915/init.c
developere35b8e42023-10-16 11:04:00 +0800298@@ -725,7 +725,7 @@ static void mt7915_init_work(struct work_struct *work)
developer42b63282022-06-16 13:33:13 +0800299 struct mt7915_dev *dev = container_of(work, struct mt7915_dev,
300 init_work);
301
302- mt7915_mcu_set_eeprom(dev);
303+ mt7915_mcu_set_eeprom(dev, dev->flash_mode);
304 mt7915_mac_init(dev);
developer2b96a9e2023-08-09 10:28:15 +0800305 mt7915_txbf_init(dev);
306 }
developer42b63282022-06-16 13:33:13 +0800307diff --git a/mt7915/mac.c b/mt7915/mac.c
developere35b8e42023-10-16 11:04:00 +0800308index f1c78ec..06a5fb1 100644
developer42b63282022-06-16 13:33:13 +0800309--- a/mt7915/mac.c
310+++ b/mt7915/mac.c
developere35b8e42023-10-16 11:04:00 +0800311@@ -579,6 +579,7 @@ mt7915_mac_fill_rx_vector(struct mt7915_dev *dev, struct sk_buff *skb)
312 wb_rssi = le32_to_cpu(rxv[9]);
313
314 phy->test.last_rcpi[i] = rcpi & 0xff;
315+ phy->test.last_rssi[i] = to_rssi(GENMASK(7, 0), rcpi);
316 phy->test.last_ib_rssi[i] = ib_rssi & 0xff;
317 phy->test.last_wb_rssi[i] = wb_rssi & 0xff;
318 }
319@@ -604,16 +605,38 @@ mt7915_mac_write_txwi_tm(struct mt7915_phy *phy, __le32 *txwi,
developer42b63282022-06-16 13:33:13 +0800320 {
321 #ifdef CONFIG_NL80211_TESTMODE
322 struct mt76_testmode_data *td = &phy->mt76->test;
323+ struct mt76_testmode_entry_data *ed;
324+ struct mt76_wcid *wcid;
325 const struct ieee80211_rate *r;
326- u8 bw, mode, nss = td->tx_rate_nss;
327- u8 rate_idx = td->tx_rate_idx;
328+ u8 bw, mode, nss, rate_idx, ldpc;
329 u16 rateval = 0;
330 u32 val;
331 bool cck = false;
332 int band;
333
334- if (skb != phy->mt76->test.tx_skb)
335+ txwi[3] &= ~cpu_to_le32(MT_TXD3_SN_VALID);
336+ txwi[7] |= cpu_to_le32(FIELD_PREP(MT_TXD7_SPE_IDX,
337+ phy->test.spe_idx));
338+
339+ if (td->tx_rate_mode == MT76_TM_TX_MODE_HE_MU) {
340+ txwi[1] |= cpu_to_le32(BIT(18));
341+ txwi[2] = 0;
342+ txwi[3] &= ~cpu_to_le32(MT_TXD3_NO_ACK);
343+ le32p_replace_bits(&txwi[3], 0x1f, MT_TXD3_REM_TX_COUNT);
344+
developer4df64ba2022-09-01 14:44:55 +0800345 return;
developer42b63282022-06-16 13:33:13 +0800346+ }
347+
348+ mt76_tm_for_each_entry(phy->mt76, wcid, ed)
349+ if (ed->tx_skb == skb)
350+ break;
351+
352+ if (!ed)
developer4df64ba2022-09-01 14:44:55 +0800353+ return;
354+
developer42b63282022-06-16 13:33:13 +0800355+ nss = ed->tx_rate_nss;
356+ rate_idx = ed->tx_rate_idx;
357+ ldpc = ed->tx_rate_ldpc;
developer4df64ba2022-09-01 14:44:55 +0800358
developer42b63282022-06-16 13:33:13 +0800359 switch (td->tx_rate_mode) {
360 case MT76_TM_TX_MODE_HT:
developere35b8e42023-10-16 11:04:00 +0800361@@ -644,7 +667,7 @@ mt7915_mac_write_txwi_tm(struct mt7915_phy *phy, __le32 *txwi,
developercf3c4c72023-01-31 15:21:28 +0800362 rate_idx += 4;
363
364 r = &phy->mt76->hw->wiphy->bands[band]->bitrates[rate_idx];
365- val = cck ? r->hw_value_short : r->hw_value;
366+ val = r->hw_value;
367
368 mode = val >> 8;
369 rate_idx = val & 0xff;
developere35b8e42023-10-16 11:04:00 +0800370@@ -703,13 +726,14 @@ mt7915_mac_write_txwi_tm(struct mt7915_phy *phy, __le32 *txwi,
developer42b63282022-06-16 13:33:13 +0800371 if (mode >= MT_PHY_TYPE_HE_SU)
372 val |= FIELD_PREP(MT_TXD6_HELTF, td->tx_ltf);
373
374- if (td->tx_rate_ldpc || (bw > 0 && mode >= MT_PHY_TYPE_HE_SU))
375+ if (ldpc || (bw > 0 && mode >= MT_PHY_TYPE_HE_SU))
376 val |= MT_TXD6_LDPC;
377
developer4df64ba2022-09-01 14:44:55 +0800378 txwi[3] &= ~cpu_to_le32(MT_TXD3_SN_VALID);
developer42b63282022-06-16 13:33:13 +0800379+ if (phy->test.bf_en)
380+ val |= MT_TXD6_TX_IBF | MT_TXD6_TX_EBF;
381+
382 txwi[6] |= cpu_to_le32(val);
383- txwi[7] |= cpu_to_le32(FIELD_PREP(MT_TXD7_SPE_IDX,
384- phy->test.spe_idx));
385 #endif
386 }
387
developere35b8e42023-10-16 11:04:00 +0800388@@ -1415,7 +1439,7 @@ mt7915_mac_restart(struct mt7915_dev *dev)
developer2cbf2fb2022-11-16 12:20:48 +0800389 goto out;
390
391 /* set the necessary init items */
392- ret = mt7915_mcu_set_eeprom(dev);
393+ ret = mt7915_mcu_set_eeprom(dev, dev->flash_mode);
394 if (ret)
395 goto out;
396
developer42b63282022-06-16 13:33:13 +0800397diff --git a/mt7915/main.c b/mt7915/main.c
developere35b8e42023-10-16 11:04:00 +0800398index ce5dcb3..3b18c95 100644
developer42b63282022-06-16 13:33:13 +0800399--- a/mt7915/main.c
400+++ b/mt7915/main.c
developer2aa1e642022-12-19 11:33:22 +0800401@@ -238,7 +238,7 @@ static int mt7915_add_interface(struct ieee80211_hw *hw,
developer42b63282022-06-16 13:33:13 +0800402 mvif->phy = phy;
developer2458e702022-12-13 15:52:04 +0800403 mvif->mt76.band_idx = phy->mt76->band_idx;
developer42b63282022-06-16 13:33:13 +0800404
405- mvif->mt76.wmm_idx = vif->type != NL80211_IFTYPE_AP;
406+ mvif->mt76.wmm_idx = (vif->type != NL80211_IFTYPE_AP && vif->type != NL80211_IFTYPE_MONITOR);
407 if (ext_phy)
408 mvif->mt76.wmm_idx += 2;
409
410diff --git a/mt7915/mcu.c b/mt7915/mcu.c
developere35b8e42023-10-16 11:04:00 +0800411index 7b3c70e..0d1e09c 100644
developer42b63282022-06-16 13:33:13 +0800412--- a/mt7915/mcu.c
413+++ b/mt7915/mcu.c
developere35b8e42023-10-16 11:04:00 +0800414@@ -391,6 +391,11 @@ mt7915_mcu_rx_ext_event(struct mt7915_dev *dev, struct sk_buff *skb)
developer42b63282022-06-16 13:33:13 +0800415 case MCU_EXT_EVENT_BCC_NOTIFY:
416 mt7915_mcu_rx_bcc_notify(dev, skb);
417 break;
418+#ifdef CONFIG_NL80211_TESTMODE
419+ case MCU_EXT_EVENT_BF_STATUS_READ:
420+ mt7915_tm_txbf_status_read(dev, skb);
421+ break;
422+#endif
423 default:
424 break;
425 }
developere35b8e42023-10-16 11:04:00 +0800426@@ -422,6 +427,7 @@ void mt7915_mcu_rx_event(struct mt7915_dev *dev, struct sk_buff *skb)
developer004e50c2023-06-29 20:33:22 +0800427 rxd->ext_eid == MCU_EXT_EVENT_ASSERT_DUMP ||
428 rxd->ext_eid == MCU_EXT_EVENT_PS_SYNC ||
429 rxd->ext_eid == MCU_EXT_EVENT_BCC_NOTIFY ||
430+ rxd->ext_eid == MCU_EXT_EVENT_BF_STATUS_READ ||
431 !rxd->seq) &&
432 !(rxd->eid == MCU_CMD_EXT_CID &&
433 rxd->ext_eid == MCU_EXT_EVENT_WA_TX_STAT))
developere35b8e42023-10-16 11:04:00 +0800434@@ -2764,7 +2770,8 @@ int mt7915_mcu_set_chan_info(struct mt7915_phy *phy, int cmd)
developer281084d2023-06-19 12:03:50 +0800435 }
436 #endif
437
438- if (mt76_connac_spe_idx(phy->mt76->antenna_mask))
439+ if (mt76_connac_spe_idx(phy->mt76->antenna_mask) &&
440+ !mt76_testmode_enabled(phy->mt76))
441 req.tx_path_num = fls(phy->mt76->antenna_mask);
442
developerdfb50982023-09-11 13:34:36 +0800443 if (phy->mt76->hw->conf.flags & IEEE80211_CONF_MONITOR)
444@@ -2832,21 +2839,21 @@ static int mt7915_mcu_set_eeprom_flash(struct mt7915_dev *dev)
developer42b63282022-06-16 13:33:13 +0800445 return 0;
446 }
447
448-int mt7915_mcu_set_eeprom(struct mt7915_dev *dev)
449+int mt7915_mcu_set_eeprom(struct mt7915_dev *dev, bool flash_mode)
450 {
451 struct mt7915_mcu_eeprom req = {
452 .buffer_mode = EE_MODE_EFUSE,
453 .format = EE_FORMAT_WHOLE,
454 };
455
456- if (dev->flash_mode)
457+ if (flash_mode)
458 return mt7915_mcu_set_eeprom_flash(dev);
459
460 return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(EFUSE_BUFFER_MODE),
developerae9afc02023-04-06 18:07:42 +0800461 &req, sizeof(req), true);
462 }
463
464-int mt7915_mcu_get_eeprom(struct mt7915_dev *dev, u32 offset)
465+int mt7915_mcu_get_eeprom(struct mt7915_dev *dev, u32 offset, u8 *read_buf)
466 {
467 struct mt7915_mcu_eeprom_info req = {
468 .addr = cpu_to_le32(round_down(offset,
developerdfb50982023-09-11 13:34:36 +0800469@@ -2855,7 +2862,7 @@ int mt7915_mcu_get_eeprom(struct mt7915_dev *dev, u32 offset)
developerae9afc02023-04-06 18:07:42 +0800470 struct mt7915_mcu_eeprom_info *res;
471 struct sk_buff *skb;
472 int ret;
473- u8 *buf;
474+ u8 *buf = read_buf;
475
476 ret = mt76_mcu_send_and_get_msg(&dev->mt76,
477 MCU_EXT_QUERY(EFUSE_ACCESS),
developerdfb50982023-09-11 13:34:36 +0800478@@ -2864,8 +2871,11 @@ int mt7915_mcu_get_eeprom(struct mt7915_dev *dev, u32 offset)
developerae9afc02023-04-06 18:07:42 +0800479 return ret;
480
481 res = (struct mt7915_mcu_eeprom_info *)skb->data;
482- buf = dev->mt76.eeprom.data + le32_to_cpu(res->addr);
483+
484+ if (!buf)
485+ buf = dev->mt76.eeprom.data + le32_to_cpu(res->addr);
486 memcpy(buf, res->data, MT7915_EEPROM_BLOCK_SIZE);
487+
488 dev_kfree_skb(skb);
489
490 return 0;
developer42b63282022-06-16 13:33:13 +0800491diff --git a/mt7915/mcu.h b/mt7915/mcu.h
developere35b8e42023-10-16 11:04:00 +0800492index c15b4b7..9982735 100644
developer42b63282022-06-16 13:33:13 +0800493--- a/mt7915/mcu.h
494+++ b/mt7915/mcu.h
developeraace7f52022-06-24 13:40:42 +0800495@@ -8,10 +8,15 @@
developer42b63282022-06-16 13:33:13 +0800496
497 enum {
498 MCU_ATE_SET_TRX = 0x1,
499+ MCU_ATE_SET_TSSI = 0x5,
500+ MCU_ATE_SET_DPD = 0x6,
501+ MCU_ATE_SET_RATE_POWER_OFFSET = 0x7,
502+ MCU_ATE_SET_THERMAL_COMP = 0x8,
503 MCU_ATE_SET_FREQ_OFFSET = 0xa,
504 MCU_ATE_SET_PHY_COUNT = 0x11,
505 MCU_ATE_SET_SLOT_TIME = 0x13,
506 MCU_ATE_CLEAN_TXQUEUE = 0x1c,
507+ MCU_ATE_SET_MU_RX_AID = 0x1e,
508 };
509
developeraace7f52022-06-24 13:40:42 +0800510 struct mt7915_mcu_thermal_ctrl {
developerc07d01e2023-05-05 13:45:43 +0800511@@ -527,6 +532,12 @@ enum {
developer42b63282022-06-16 13:33:13 +0800512
513 enum {
514 MT_BF_SOUNDING_ON = 1,
515+ MT_BF_DATA_PACKET_APPLY = 2,
516+ MT_BF_PFMU_TAG_READ = 5,
517+ MT_BF_PFMU_TAG_WRITE = 6,
518+ MT_BF_PHASE_CAL = 14,
519+ MT_BF_IBF_PHASE_COMP = 15,
520+ MT_BF_PROFILE_WRITE_ALL = 17,
521 MT_BF_TYPE_UPDATE = 20,
522 MT_BF_MODULE_UPDATE = 25
523 };
developerc07d01e2023-05-05 13:45:43 +0800524@@ -775,10 +786,20 @@ struct mt7915_muru {
developer42b63282022-06-16 13:33:13 +0800525 #define MURU_OFDMA_SCH_TYPE_UL BIT(1)
526
developeraace7f52022-06-24 13:40:42 +0800527 /* Common Config */
developer42b63282022-06-16 13:33:13 +0800528-#define MURU_COMM_PPDU_FMT BIT(0)
529-#define MURU_COMM_SCH_TYPE BIT(1)
530-#define MURU_COMM_SET (MURU_COMM_PPDU_FMT | MURU_COMM_SCH_TYPE)
developer42b63282022-06-16 13:33:13 +0800531-/* DL&UL User config*/
developer42b63282022-06-16 13:33:13 +0800532+/* #define MURU_COMM_PPDU_FMT BIT(0) */
533+/* #define MURU_COMM_SCH_TYPE BIT(1) */
534+/* #define MURU_COMM_SET (MURU_COMM_PPDU_FMT | MURU_COMM_SCH_TYPE) */
developeraace7f52022-06-24 13:40:42 +0800535+#define MURU_COMM_PPDU_FMT BIT(0)
536+#define MURU_COMM_SCH_TYPE BIT(1)
537+#define MURU_COMM_BAND BIT(2)
538+#define MURU_COMM_WMM BIT(3)
539+#define MURU_COMM_SPE_IDX BIT(4)
540+#define MURU_COMM_PROC_TYPE BIT(5)
developerc07d01e2023-05-05 13:45:43 +0800541+#define MURU_COMM_SET (MURU_COMM_PPDU_FMT | MURU_COMM_SCH_TYPE)
542+#define MURU_COMM_SET_TM (MURU_COMM_PPDU_FMT | MURU_COMM_BAND | \
543+ MURU_COMM_WMM | MURU_COMM_SPE_IDX)
developer42b63282022-06-16 13:33:13 +0800544+
545+/* DL&UL User config */
546 #define MURU_USER_CNT BIT(4)
547
548 enum {
549diff --git a/mt7915/mmio.c b/mt7915/mmio.c
developere35b8e42023-10-16 11:04:00 +0800550index 10c2c7d..87a5c5c 100644
developer42b63282022-06-16 13:33:13 +0800551--- a/mt7915/mmio.c
552+++ b/mt7915/mmio.c
developerf3f5d9b2023-02-07 15:24:34 +0800553@@ -134,6 +134,7 @@ static const u32 mt7915_offs[] = {
developer42b63282022-06-16 13:33:13 +0800554 [ARB_DRNGR0] = 0x194,
555 [ARB_SCR] = 0x080,
556 [RMAC_MIB_AIRTIME14] = 0x3b8,
557+ [AGG_AALCR0] = 0x048,
558 [AGG_AWSCR0] = 0x05c,
559 [AGG_PCR0] = 0x06c,
560 [AGG_ACR0] = 0x084,
developerf3f5d9b2023-02-07 15:24:34 +0800561@@ -209,6 +210,7 @@ static const u32 mt7916_offs[] = {
developer42b63282022-06-16 13:33:13 +0800562 [ARB_DRNGR0] = 0x1e0,
563 [ARB_SCR] = 0x000,
564 [RMAC_MIB_AIRTIME14] = 0x0398,
565+ [AGG_AALCR0] = 0x028,
566 [AGG_AWSCR0] = 0x030,
567 [AGG_PCR0] = 0x040,
568 [AGG_ACR0] = 0x054,
569diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developere35b8e42023-10-16 11:04:00 +0800570index ab3c8f7..b91af94 100644
developer42b63282022-06-16 13:33:13 +0800571--- a/mt7915/mt7915.h
572+++ b/mt7915/mt7915.h
developere35b8e42023-10-16 11:04:00 +0800573@@ -267,11 +267,15 @@ struct mt7915_phy {
574
575 s32 last_freq_offset;
576 u8 last_rcpi[4];
577+ s8 last_rssi[4];
578 s8 last_ib_rssi[4];
579 s8 last_wb_rssi[4];
developer42b63282022-06-16 13:33:13 +0800580 u8 last_snr;
581
582 u8 spe_idx;
583+
584+ bool bf_en;
585+ bool bf_ever_en;
586 } test;
587 #endif
588
developere35b8e42023-10-16 11:04:00 +0800589@@ -371,6 +375,14 @@ struct mt7915_dev {
developer42b63282022-06-16 13:33:13 +0800590 void __iomem *dcm;
591 void __iomem *sku;
592
593+#ifdef CONFIG_NL80211_TESTMODE
594+ struct {
595+ void *txbf_phase_cal;
596+ void *txbf_pfmu_data;
597+ void *txbf_pfmu_tag;
598+ } test;
599+#endif
600+
601 #ifdef MTK_DEBUG
602 u16 wlan_idx;
603 struct {
developere35b8e42023-10-16 11:04:00 +0800604@@ -542,8 +554,8 @@ int mt7915_mcu_set_fixed_rate_ctrl(struct mt7915_dev *dev,
developer42b63282022-06-16 13:33:13 +0800605 struct ieee80211_vif *vif,
606 struct ieee80211_sta *sta,
607 void *data, u32 field);
608-int mt7915_mcu_set_eeprom(struct mt7915_dev *dev);
developerae9afc02023-04-06 18:07:42 +0800609-int mt7915_mcu_get_eeprom(struct mt7915_dev *dev, u32 offset);
developer42b63282022-06-16 13:33:13 +0800610+int mt7915_mcu_set_eeprom(struct mt7915_dev *dev, bool flash_mode);
developerae9afc02023-04-06 18:07:42 +0800611+int mt7915_mcu_get_eeprom(struct mt7915_dev *dev, u32 offset, u8 *read_buf);
developer42b63282022-06-16 13:33:13 +0800612 int mt7915_mcu_get_eeprom_free_block(struct mt7915_dev *dev, u8 *block_num);
613 int mt7915_mcu_set_mac(struct mt7915_dev *dev, int band, bool enable,
developerae9afc02023-04-06 18:07:42 +0800614 bool hdr_trans);
developere35b8e42023-10-16 11:04:00 +0800615@@ -582,6 +594,7 @@ int mt7915_mcu_fw_log_2_host(struct mt7915_dev *dev, u8 type, u8 ctrl);
developer42b63282022-06-16 13:33:13 +0800616 int mt7915_mcu_fw_dbg_ctrl(struct mt7915_dev *dev, u32 module, u8 level);
617 void mt7915_mcu_rx_event(struct mt7915_dev *dev, struct sk_buff *skb);
618 void mt7915_mcu_exit(struct mt7915_dev *dev);
619+int mt7915_tm_txbf_status_read(struct mt7915_dev *dev, struct sk_buff *skb);
620
621 static inline u16 mt7915_wtbl_size(struct mt7915_dev *dev)
622 {
623diff --git a/mt7915/regs.h b/mt7915/regs.h
developere35b8e42023-10-16 11:04:00 +0800624index 2a9e50b..6783797 100644
developer42b63282022-06-16 13:33:13 +0800625--- a/mt7915/regs.h
626+++ b/mt7915/regs.h
developer3d5faf22022-11-29 18:07:22 +0800627@@ -62,6 +62,7 @@ enum offs_rev {
developer42b63282022-06-16 13:33:13 +0800628 ARB_DRNGR0,
629 ARB_SCR,
630 RMAC_MIB_AIRTIME14,
631+ AGG_AALCR0,
632 AGG_AWSCR0,
633 AGG_PCR0,
634 AGG_ACR0,
developere35b8e42023-10-16 11:04:00 +0800635@@ -486,6 +487,8 @@ enum offs_rev {
developer42b63282022-06-16 13:33:13 +0800636 #define MT_WF_AGG_BASE(_band) ((_band) ? 0x820f2000 : 0x820e2000)
637 #define MT_WF_AGG(_band, ofs) (MT_WF_AGG_BASE(_band) + (ofs))
638
639+#define MT_AGG_AALCR0(_band, _n) MT_WF_AGG(_band, (__OFFS(AGG_AALCR0) + \
developer281084d2023-06-19 12:03:50 +0800640+ (_n) * 4))
developer42b63282022-06-16 13:33:13 +0800641 #define MT_AGG_AWSCR0(_band, _n) MT_WF_AGG(_band, (__OFFS(AGG_AWSCR0) + \
642 (_n) * 4))
643 #define MT_AGG_PCR0(_band, _n) MT_WF_AGG(_band, (__OFFS(AGG_PCR0) + \
644diff --git a/mt7915/testmode.c b/mt7915/testmode.c
developere35b8e42023-10-16 11:04:00 +0800645index 4693919..8367204 100644
developer42b63282022-06-16 13:33:13 +0800646--- a/mt7915/testmode.c
647+++ b/mt7915/testmode.c
developere35b8e42023-10-16 11:04:00 +0800648@@ -9,6 +9,10 @@
developer42b63282022-06-16 13:33:13 +0800649 enum {
650 TM_CHANGED_TXPOWER,
651 TM_CHANGED_FREQ_OFFSET,
developere35b8e42023-10-16 11:04:00 +0800652+ TM_CHANGED_SKU_EN,
developer42b63282022-06-16 13:33:13 +0800653+ TM_CHANGED_AID,
654+ TM_CHANGED_CFG,
655+ TM_CHANGED_TXBF_ACT,
656
657 /* must be last */
658 NUM_TM_CHANGED
developere35b8e42023-10-16 11:04:00 +0800659@@ -17,6 +21,10 @@ enum {
developer42b63282022-06-16 13:33:13 +0800660 static const u8 tm_change_map[] = {
661 [TM_CHANGED_TXPOWER] = MT76_TM_ATTR_TX_POWER,
662 [TM_CHANGED_FREQ_OFFSET] = MT76_TM_ATTR_FREQ_OFFSET,
developere35b8e42023-10-16 11:04:00 +0800663+ [TM_CHANGED_SKU_EN] = MT76_TM_ATTR_SKU_EN,
developer42b63282022-06-16 13:33:13 +0800664+ [TM_CHANGED_AID] = MT76_TM_ATTR_AID,
665+ [TM_CHANGED_CFG] = MT76_TM_ATTR_CFG,
666+ [TM_CHANGED_TXBF_ACT] = MT76_TM_ATTR_TXBF_ACT,
667 };
668
669 struct reg_band {
developere35b8e42023-10-16 11:04:00 +0800670@@ -33,6 +41,57 @@ struct reg_band {
developer42b63282022-06-16 13:33:13 +0800671 #define TM_REG_MAX_ID 20
672 static struct reg_band reg_backup_list[TM_REG_MAX_ID];
673
674+static void mt7915_tm_update_entry(struct mt7915_phy *phy);
675+
676+static u8 mt7915_tm_chan_bw(enum nl80211_chan_width width)
677+{
678+ static const u8 width_to_bw[] = {
679+ [NL80211_CHAN_WIDTH_40] = TM_CBW_40MHZ,
680+ [NL80211_CHAN_WIDTH_80] = TM_CBW_80MHZ,
681+ [NL80211_CHAN_WIDTH_80P80] = TM_CBW_8080MHZ,
682+ [NL80211_CHAN_WIDTH_160] = TM_CBW_160MHZ,
683+ [NL80211_CHAN_WIDTH_5] = TM_CBW_5MHZ,
684+ [NL80211_CHAN_WIDTH_10] = TM_CBW_10MHZ,
685+ [NL80211_CHAN_WIDTH_20] = TM_CBW_20MHZ,
686+ [NL80211_CHAN_WIDTH_20_NOHT] = TM_CBW_20MHZ,
687+ };
688+
689+ if (width >= ARRAY_SIZE(width_to_bw))
690+ return 0;
691+
692+ return width_to_bw[width];
693+}
694+
developer281084d2023-06-19 12:03:50 +0800695+static int
696+mt7915_tm_check_antenna(struct mt7915_phy *phy)
697+{
698+ struct mt76_testmode_data *td = &phy->mt76->test;
699+ struct mt7915_dev *dev = phy->dev;
700+ u8 band_idx = phy->mt76->band_idx;
701+ u32 chainmask = phy->mt76->chainmask;
702+
703+ chainmask = chainmask >> (dev->chainshift * band_idx);
704+ if (td->tx_antenna_mask & ~chainmask) {
705+ dev_err(dev->mt76.dev,
706+ "tx antenna mask %d exceeds hardware limitation (chainmask %d)\n",
707+ td->tx_antenna_mask, chainmask);
708+ return -EINVAL;
709+ }
710+
711+ return 0;
712+}
713+
developer42b63282022-06-16 13:33:13 +0800714+static void
715+mt7915_tm_update_channel(struct mt7915_phy *phy)
716+{
717+ mutex_unlock(&phy->dev->mt76.mutex);
718+ mt7915_set_channel(phy);
719+ mutex_lock(&phy->dev->mt76.mutex);
720+
721+ mt7915_mcu_set_chan_info(phy, MCU_EXT_CMD(SET_RX_PATH));
722+
723+ mt7915_tm_update_entry(phy);
724+}
725
726 static int
727 mt7915_tm_set_tx_power(struct mt7915_phy *phy)
developere35b8e42023-10-16 11:04:00 +0800728@@ -119,18 +178,28 @@ mt7915_tm_set_trx(struct mt7915_phy *phy, int type, bool en)
developer42b63282022-06-16 13:33:13 +0800729 }
730
731 static int
732-mt7915_tm_clean_hwq(struct mt7915_phy *phy, u8 wcid)
733+mt7915_tm_clean_hwq(struct mt7915_phy *phy)
734 {
735+ struct mt76_testmode_entry_data *ed;
736+ struct mt76_wcid *wcid;
737 struct mt7915_dev *dev = phy->dev;
738 struct mt7915_tm_cmd req = {
739 .testmode_en = 1,
740 .param_idx = MCU_ATE_CLEAN_TXQUEUE,
741- .param.clean.wcid = wcid,
developer2458e702022-12-13 15:52:04 +0800742 .param.clean.band = phy->mt76->band_idx,
developer42b63282022-06-16 13:33:13 +0800743 };
744
745- return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(ATE_CTRL), &req,
746- sizeof(req), false);
747+ mt76_tm_for_each_entry(phy->mt76, wcid, ed) {
748+ int ret;
749+
750+ req.param.clean.wcid = wcid->idx;
751+ ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(ATE_CTRL),
752+ &req, sizeof(req), false);
753+ if (ret)
754+ return ret;
755+ }
756+
757+ return 0;
758 }
759
760 static int
developere35b8e42023-10-16 11:04:00 +0800761@@ -141,7 +210,7 @@ mt7915_tm_set_phy_count(struct mt7915_phy *phy, u8 control)
developer2458e702022-12-13 15:52:04 +0800762 .testmode_en = 1,
763 .param_idx = MCU_ATE_SET_PHY_COUNT,
764 .param.cfg.enable = control,
765- .param.cfg.band = phy != &dev->phy,
766+ .param.cfg.band = phy->mt76->band_idx,
767 };
768
769 return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(ATE_CTRL), &req,
developere35b8e42023-10-16 11:04:00 +0800770@@ -182,12 +251,739 @@ mt7915_tm_set_tam_arb(struct mt7915_phy *phy, bool enable, bool mu)
developer42b63282022-06-16 13:33:13 +0800771 return mt7915_mcu_set_muru_ctrl(dev, MURU_SET_ARB_OP_MODE, op_mode);
772 }
773
774+static int
775+mt7915_tm_set_cfg(struct mt7915_phy *phy)
776+{
777+ static const u8 cfg_cmd[] = {
778+ [MT76_TM_CFG_TSSI] = MCU_ATE_SET_TSSI,
779+ [MT76_TM_CFG_DPD] = MCU_ATE_SET_DPD,
780+ [MT76_TM_CFG_RATE_POWER_OFFSET] = MCU_ATE_SET_RATE_POWER_OFFSET,
781+ [MT76_TM_CFG_THERMAL_COMP] = MCU_ATE_SET_THERMAL_COMP,
782+ };
783+ struct mt76_testmode_data *td = &phy->mt76->test;
784+ struct mt7915_dev *dev = phy->dev;
785+ struct mt7915_tm_cmd req = {
786+ .testmode_en = !(phy->mt76->test.state == MT76_TM_STATE_OFF),
787+ .param_idx = cfg_cmd[td->cfg.type],
788+ .param.cfg.enable = td->cfg.enable,
developer2458e702022-12-13 15:52:04 +0800789+ .param.cfg.band = phy->mt76->band_idx,
developer42b63282022-06-16 13:33:13 +0800790+ };
791+
792+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(ATE_CTRL), &req,
793+ sizeof(req), false);
794+}
795+
796+static int
797+mt7915_tm_add_txbf(struct mt7915_phy *phy, struct ieee80211_vif *vif,
798+ struct ieee80211_sta *sta, u8 pfmu_idx, u8 nr,
799+ u8 nc, bool ebf)
800+{
801+ struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
802+ struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
803+ struct mt7915_dev *dev = phy->dev;
804+ struct sk_buff *skb;
805+ struct sta_rec_bf *bf;
806+ struct tlv *tlv;
807+ u8 ndp_rate;
808+
809+ if (nr == 1)
810+ ndp_rate = 8;
811+ else if (nr == 2)
812+ ndp_rate = 16;
813+ else
814+ ndp_rate = 24;
815+
816+ skb = mt76_connac_mcu_alloc_sta_req(&dev->mt76, &mvif->mt76,
817+ &msta->wcid);
818+ if (IS_ERR(skb))
819+ return PTR_ERR(skb);
820+
821+ tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_BF, sizeof(*bf));
822+ bf = (struct sta_rec_bf *)tlv;
823+
824+ bf->pfmu = cpu_to_le16(pfmu_idx);
825+ bf->sounding_phy = 1;
826+ bf->bf_cap = ebf;
827+ bf->ncol = nc;
828+ bf->nrow = nr;
829+ bf->ndp_rate = ndp_rate;
830+ bf->ibf_timeout = 0xff;
831+ bf->tx_mode = MT_PHY_TYPE_HT;
832+
833+ if (ebf) {
834+ bf->mem[0].row = 0;
835+ bf->mem[1].row = 1;
836+ bf->mem[2].row = 2;
837+ bf->mem[3].row = 3;
838+ } else {
839+ bf->mem[0].row = 4;
840+ bf->mem[1].row = 5;
841+ bf->mem[2].row = 6;
842+ bf->mem[3].row = 7;
843+ }
844+
845+ return mt76_mcu_skb_send_msg(&dev->mt76, skb,
846+ MCU_EXT_CMD(STA_REC_UPDATE), true);
847+}
848+
849+static int
850+mt7915_tm_entry_add(struct mt7915_phy *phy, u8 aid)
851+{
852+ struct mt76_testmode_data *td = &phy->mt76->test;
853+ struct mt76_testmode_entry_data *ed;
854+ struct ieee80211_sband_iftype_data *sdata;
855+ struct ieee80211_supported_band *sband;
856+ struct ieee80211_sta *sta;
857+ struct mt7915_sta *msta;
858+ int tid, ret;
859+
860+ if (td->entry_num >= MT76_TM_MAX_ENTRY_NUM)
861+ return -EINVAL;
862+
863+ sta = kzalloc(sizeof(*sta) + phy->mt76->hw->sta_data_size +
864+ sizeof(*ed), GFP_KERNEL);
865+ if (!sta)
866+ return -ENOMEM;
867+
868+ msta = (struct mt7915_sta *)sta->drv_priv;
869+ ed = mt76_testmode_entry_data(phy->mt76, &msta->wcid);
870+ memcpy(ed, &td->ed, sizeof(*ed));
871+
872+ if (phy->mt76->chandef.chan->band == NL80211_BAND_5GHZ) {
873+ sband = &phy->mt76->sband_5g.sband;
874+ sdata = phy->iftype[NL80211_BAND_5GHZ];
875+ } else if (phy->mt76->chandef.chan->band == NL80211_BAND_6GHZ) {
876+ sband = &phy->mt76->sband_6g.sband;
877+ sdata = phy->iftype[NL80211_BAND_6GHZ];
878+ } else {
879+ sband = &phy->mt76->sband_2g.sband;
880+ sdata = phy->iftype[NL80211_BAND_2GHZ];
881+ }
882+
883+ memcpy(sta->addr, ed->addr[0], ETH_ALEN);
884+ if (phy->test.bf_en) {
885+ u8 addr[ETH_ALEN] = {0x00, 0x11, 0x11, 0x11, 0x11, 0x11};
886+
887+ memcpy(sta->addr, addr, ETH_ALEN);
888+ }
889+
890+ if (td->tx_rate_mode >= MT76_TM_TX_MODE_HT)
developer2458e702022-12-13 15:52:04 +0800891+ memcpy(&sta->deflink.ht_cap, &sband->ht_cap, sizeof(sta->deflink.ht_cap));
developer42b63282022-06-16 13:33:13 +0800892+ if (td->tx_rate_mode >= MT76_TM_TX_MODE_VHT)
developer2458e702022-12-13 15:52:04 +0800893+ memcpy(&sta->deflink.vht_cap, &sband->vht_cap, sizeof(sta->deflink.vht_cap));
developer42b63282022-06-16 13:33:13 +0800894+ if (td->tx_rate_mode >= MT76_TM_TX_MODE_HE_SU)
developer2458e702022-12-13 15:52:04 +0800895+ memcpy(&sta->deflink.he_cap, &sdata[NL80211_IFTYPE_STATION].he_cap,
896+ sizeof(sta->deflink.he_cap));
developer42b63282022-06-16 13:33:13 +0800897+ sta->aid = aid;
898+ sta->wme = 1;
899+
900+ ret = mt7915_mac_sta_add(&phy->dev->mt76, phy->monitor_vif, sta);
901+ if (ret) {
902+ kfree(sta);
903+ return ret;
904+ }
905+
906+ /* prevent from starting tx ba session */
907+ for (tid = 0; tid < 8; tid++)
developer004e50c2023-06-29 20:33:22 +0800908+ set_bit(tid, &msta->wcid.ampdu_state);
developer42b63282022-06-16 13:33:13 +0800909+
910+ list_add_tail(&msta->wcid.list, &td->tm_entry_list);
911+ td->entry_num++;
912+
913+ return 0;
914+}
915+
916+static void
917+mt7915_tm_entry_remove(struct mt7915_phy *phy, u8 aid)
918+{
919+ struct mt76_testmode_data *td = &phy->mt76->test;
920+ struct mt76_wcid *wcid, *tmp;
921+
922+ if (list_empty(&td->tm_entry_list))
923+ return;
924+
925+ list_for_each_entry_safe(wcid, tmp, &td->tm_entry_list, list) {
926+ struct mt76_testmode_entry_data *ed;
927+ struct mt7915_dev *dev = phy->dev;
928+ struct ieee80211_sta *sta;
929+
930+ ed = mt76_testmode_entry_data(phy->mt76, wcid);
931+ if (aid && ed->aid != aid)
932+ continue;
933+
934+ sta = wcid_to_sta(wcid);
935+ mt7915_mac_sta_remove(&dev->mt76, phy->monitor_vif, sta);
936+ mt76_wcid_mask_clear(dev->mt76.wcid_mask, wcid->idx);
937+
938+ list_del_init(&wcid->list);
939+ kfree(sta);
940+ phy->mt76->test.entry_num--;
941+ }
942+}
943+
944+static int
945+mt7915_tm_set_entry(struct mt7915_phy *phy)
946+{
947+ struct mt76_testmode_data *td = &phy->mt76->test;
948+ struct mt76_testmode_entry_data *ed;
949+ struct mt76_wcid *wcid;
950+
951+ if (!td->aid) {
952+ if (td->state > MT76_TM_STATE_IDLE)
953+ mt76_testmode_set_state(phy->mt76, MT76_TM_STATE_IDLE);
954+ mt7915_tm_entry_remove(phy, td->aid);
955+ return 0;
956+ }
957+
958+ mt76_tm_for_each_entry(phy->mt76, wcid, ed) {
959+ if (ed->aid == td->aid) {
960+ struct sk_buff *skb;
961+
962+ local_bh_disable();
963+ skb = ed->tx_skb;
964+ memcpy(ed, &td->ed, sizeof(*ed));
965+ ed->tx_skb = skb;
966+ local_bh_enable();
967+
968+ return 0;
969+ }
970+ }
971+
972+ return mt7915_tm_entry_add(phy, td->aid);
973+}
974+
975+static void
976+mt7915_tm_update_entry(struct mt7915_phy *phy)
977+{
978+ struct mt76_testmode_data *td = &phy->mt76->test;
979+ struct mt76_testmode_entry_data *ed, tmp;
980+ struct mt76_wcid *wcid, *last;
981+
982+ if (!td->aid || phy->test.bf_en)
983+ return;
984+
985+ memcpy(&tmp, &td->ed, sizeof(tmp));
986+ last = list_last_entry(&td->tm_entry_list,
987+ struct mt76_wcid, list);
988+
989+ mt76_tm_for_each_entry(phy->mt76, wcid, ed) {
990+ memcpy(&td->ed, ed, sizeof(td->ed));
991+ mt7915_tm_entry_remove(phy, td->aid);
992+ mt7915_tm_entry_add(phy, td->aid);
993+ if (wcid == last)
994+ break;
995+ }
996+
997+ memcpy(&td->ed, &tmp, sizeof(td->ed));
998+}
999+
1000+static int
1001+mt7915_tm_txbf_init(struct mt7915_phy *phy, u16 *val)
1002+{
1003+ struct mt76_testmode_data *td = &phy->mt76->test;
1004+ struct mt7915_dev *dev = phy->dev;
1005+ bool enable = val[0];
1006+ void *phase_cal, *pfmu_data, *pfmu_tag;
1007+ u8 addr[ETH_ALEN] = {0x00, 0x22, 0x22, 0x22, 0x22, 0x22};
1008+
1009+ if (!enable) {
1010+ phy->test.bf_en = 0;
1011+ return 0;
1012+ }
1013+
1014+ if (!dev->test.txbf_phase_cal) {
1015+ phase_cal = devm_kzalloc(dev->mt76.dev,
1016+ sizeof(struct mt7915_tm_txbf_phase) *
1017+ MAX_PHASE_GROUP_NUM,
1018+ GFP_KERNEL);
1019+ if (!phase_cal)
1020+ return -ENOMEM;
1021+
1022+ dev->test.txbf_phase_cal = phase_cal;
1023+ }
1024+
1025+ if (!dev->test.txbf_pfmu_data) {
1026+ pfmu_data = devm_kzalloc(dev->mt76.dev, 512, GFP_KERNEL);
1027+ if (!pfmu_data)
1028+ return -ENOMEM;
1029+
1030+ dev->test.txbf_pfmu_data = pfmu_data;
1031+ }
1032+
1033+ if (!dev->test.txbf_pfmu_tag) {
1034+ pfmu_tag = devm_kzalloc(dev->mt76.dev,
1035+ sizeof(struct mt7915_tm_pfmu_tag), GFP_KERNEL);
1036+ if (!pfmu_tag)
1037+ return -ENOMEM;
1038+
1039+ dev->test.txbf_pfmu_tag = pfmu_tag;
1040+ }
1041+
1042+ memcpy(phy->monitor_vif->addr, addr, ETH_ALEN);
1043+ mt7915_mcu_add_dev_info(phy, phy->monitor_vif, true);
1044+
1045+ td->tx_rate_mode = MT76_TM_TX_MODE_HT;
1046+ td->tx_mpdu_len = 1024;
1047+ td->tx_rate_sgi = 0;
1048+ td->tx_ipg = 100;
1049+ phy->test.bf_en = 1;
1050+
1051+ return mt7915_tm_set_trx(phy, TM_MAC_TX, true);
1052+}
1053+
1054+static int
1055+mt7915_tm_txbf_phase_comp(struct mt7915_phy *phy, u16 *val)
1056+{
1057+ struct mt7915_dev *dev = phy->dev;
1058+ struct {
1059+ u8 category;
1060+ u8 wlan_idx_lo;
1061+ u8 bw;
1062+ u8 jp_band;
1063+ u8 dbdc_idx;
1064+ bool read_from_e2p;
1065+ bool disable;
1066+ u8 wlan_idx_hi;
1067+ u8 buf[40];
1068+ } __packed req = {
1069+ .category = MT_BF_IBF_PHASE_COMP,
1070+ .bw = val[0],
1071+ .jp_band = (val[2] == 1) ? 1 : 0,
developer2458e702022-12-13 15:52:04 +08001072+ .dbdc_idx = phy->mt76->band_idx,
developer42b63282022-06-16 13:33:13 +08001073+ .read_from_e2p = val[3],
1074+ .disable = val[4],
1075+ };
1076+ struct mt7915_tm_txbf_phase *phase =
1077+ (struct mt7915_tm_txbf_phase *)dev->test.txbf_phase_cal;
1078+
1079+ wait_event_timeout(dev->mt76.tx_wait, phase[val[2]].status != 0, HZ);
1080+ memcpy(req.buf, &phase[val[2]].phase, sizeof(req.buf));
1081+
1082+ pr_info("ibf cal process: phase comp info\n");
1083+ print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 1,
1084+ &req, sizeof(req), 0);
1085+
1086+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(TXBF_ACTION), &req,
1087+ sizeof(req), true);
1088+}
1089+
1090+static int
1091+mt7915_tm_txbf_profile_tag_read(struct mt7915_phy *phy, u8 pfmu_idx)
1092+{
1093+ struct mt7915_dev *dev = phy->dev;
1094+ struct {
1095+ u8 format_id;
1096+ u8 pfmu_idx;
1097+ bool bfer;
1098+ u8 dbdc_idx;
1099+ } __packed req = {
1100+ .format_id = MT_BF_PFMU_TAG_READ,
1101+ .pfmu_idx = pfmu_idx,
1102+ .bfer = 1,
1103+ .dbdc_idx = phy != &dev->phy,
1104+ };
1105+ struct mt7915_tm_pfmu_tag *tag = phy->dev->test.txbf_pfmu_tag;
1106+
1107+ tag->t1.pfmu_idx = 0;
1108+
1109+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(TXBF_ACTION), &req,
1110+ sizeof(req), true);
1111+}
1112+
1113+static int
1114+mt7915_tm_txbf_profile_tag_write(struct mt7915_phy *phy, u8 pfmu_idx,
1115+ struct mt7915_tm_pfmu_tag *tag)
1116+{
1117+ struct mt7915_dev *dev = phy->dev;
1118+ struct {
1119+ u8 format_id;
1120+ u8 pfmu_idx;
1121+ bool bfer;
1122+ u8 dbdc_idx;
1123+ u8 buf[64];
1124+ } __packed req = {
1125+ .format_id = MT_BF_PFMU_TAG_WRITE,
1126+ .pfmu_idx = pfmu_idx,
1127+ .bfer = 1,
1128+ .dbdc_idx = phy != &dev->phy,
1129+ };
1130+
1131+ memcpy(req.buf, tag, sizeof(*tag));
1132+ wait_event_timeout(dev->mt76.tx_wait, tag->t1.pfmu_idx != 0, HZ);
1133+
1134+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(TXBF_ACTION), &req,
1135+ sizeof(req), false);
1136+}
1137+
1138+static int
1139+mt7915_tm_txbf_apply_tx(struct mt7915_phy *phy, u16 wlan_idx, bool ebf,
1140+ bool ibf, bool phase_cal)
1141+{
1142+#define to_wcid_lo(id) FIELD_GET(GENMASK(7, 0), (u16)id)
1143+#define to_wcid_hi(id) FIELD_GET(GENMASK(9, 8), (u16)id)
1144+ struct mt7915_dev *dev = phy->dev;
1145+ struct {
1146+ u8 category;
1147+ u8 wlan_idx_lo;
1148+ bool ebf;
1149+ bool ibf;
1150+ bool mu_txbf;
1151+ bool phase_cal;
1152+ u8 wlan_idx_hi;
1153+ u8 _rsv;
1154+ } __packed req = {
1155+ .category = MT_BF_DATA_PACKET_APPLY,
1156+ .wlan_idx_lo = to_wcid_lo(wlan_idx),
1157+ .ebf = ebf,
1158+ .ibf = ibf,
1159+ .phase_cal = phase_cal,
1160+ .wlan_idx_hi = to_wcid_hi(wlan_idx),
1161+ };
1162+
1163+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(TXBF_ACTION), &req,
1164+ sizeof(req), false);
1165+}
1166+
1167+static int mt7915_tm_txbf_set_rate(struct mt7915_phy *phy,
1168+ struct mt76_wcid *wcid)
1169+{
1170+ struct mt7915_dev *dev = phy->dev;
1171+ struct mt76_testmode_entry_data *ed = mt76_testmode_entry_data(phy->mt76, wcid);
1172+ struct ieee80211_sta *sta = wcid_to_sta(wcid);
1173+ struct sta_phy rate = {};
1174+
1175+ if (!sta)
1176+ return 0;
1177+
1178+ rate.type = MT_PHY_TYPE_HT;
1179+ rate.bw = mt7915_tm_chan_bw(phy->mt76->chandef.width);
1180+ rate.nss = ed->tx_rate_nss;
1181+ rate.mcs = ed->tx_rate_idx;
1182+ rate.ldpc = (rate.bw || ed->tx_rate_ldpc) * GENMASK(2, 0);
1183+
1184+ return mt7915_mcu_set_fixed_rate_ctrl(dev, phy->monitor_vif, sta,
1185+ &rate, RATE_PARAM_FIXED);
1186+}
1187+
1188+static int
1189+mt7915_tm_txbf_set_tx(struct mt7915_phy *phy, u16 *val)
1190+{
1191+ bool bf_on = val[0], update = val[3];
1192+ /* u16 wlan_idx = val[2]; */
1193+ struct mt7915_tm_pfmu_tag *tag = phy->dev->test.txbf_pfmu_tag;
1194+ struct mt76_testmode_data *td = &phy->mt76->test;
1195+ struct mt76_wcid *wcid;
1196+
1197+ if (bf_on) {
1198+ mt7915_tm_set_trx(phy, TM_MAC_RX_RXV, false);
1199+ mt7915_tm_txbf_profile_tag_read(phy, 2);
1200+ tag->t1.invalid_prof = false;
1201+ mt7915_tm_txbf_profile_tag_write(phy, 2, tag);
1202+
1203+ phy->test.bf_ever_en = true;
1204+
1205+ if (update)
1206+ mt7915_tm_txbf_apply_tx(phy, 1, 0, 1, 1);
1207+ } else {
1208+ if (!phy->test.bf_ever_en) {
1209+ if (update)
1210+ mt7915_tm_txbf_apply_tx(phy, 1, 0, 0, 0);
1211+ } else {
1212+ phy->test.bf_ever_en = false;
1213+
1214+ mt7915_tm_txbf_profile_tag_read(phy, 2);
1215+ tag->t1.invalid_prof = true;
1216+ mt7915_tm_txbf_profile_tag_write(phy, 2, tag);
1217+ }
1218+ }
1219+
1220+ wcid = list_first_entry(&td->tm_entry_list, struct mt76_wcid, list);
1221+ mt7915_tm_txbf_set_rate(phy, wcid);
1222+
1223+ return 0;
1224+}
1225+
1226+static int
1227+mt7915_tm_txbf_profile_update(struct mt7915_phy *phy, u16 *val, bool ebf)
1228+{
1229+ static const u8 mode_to_lm[] = {
1230+ [MT76_TM_TX_MODE_CCK] = 0,
1231+ [MT76_TM_TX_MODE_OFDM] = 0,
1232+ [MT76_TM_TX_MODE_HT] = 1,
1233+ [MT76_TM_TX_MODE_VHT] = 2,
1234+ [MT76_TM_TX_MODE_HE_SU] = 3,
1235+ [MT76_TM_TX_MODE_HE_EXT_SU] = 3,
1236+ [MT76_TM_TX_MODE_HE_TB] = 3,
1237+ [MT76_TM_TX_MODE_HE_MU] = 3,
1238+ };
1239+ struct mt76_testmode_data *td = &phy->mt76->test;
1240+ struct mt76_wcid *wcid;
1241+ struct ieee80211_vif *vif = phy->monitor_vif;
1242+ struct mt7915_tm_pfmu_tag *tag = phy->dev->test.txbf_pfmu_tag;
1243+ u8 pfmu_idx = val[0], nc = val[2], nr;
1244+ int ret;
1245+
1246+ if (td->tx_antenna_mask == 3)
1247+ nr = 1;
1248+ else if (td->tx_antenna_mask == 7)
1249+ nr = 2;
1250+ else
1251+ nr = 3;
1252+
1253+ memset(tag, 0, sizeof(*tag));
1254+ tag->t1.pfmu_idx = pfmu_idx;
1255+ tag->t1.ebf = ebf;
1256+ tag->t1.nr = nr;
1257+ tag->t1.nc = nc;
1258+ tag->t1.invalid_prof = true;
1259+
1260+ tag->t1.snr_sts4 = 0xc0;
1261+ tag->t1.snr_sts5 = 0xff;
1262+ tag->t1.snr_sts6 = 0xff;
1263+ tag->t1.snr_sts7 = 0xff;
1264+
1265+ if (ebf) {
1266+ tag->t1.row_id1 = 0;
1267+ tag->t1.row_id2 = 1;
1268+ tag->t1.row_id3 = 2;
1269+ tag->t1.row_id4 = 3;
1270+ tag->t1.lm = mode_to_lm[MT76_TM_TX_MODE_HT];
1271+ } else {
1272+ tag->t1.row_id1 = 4;
1273+ tag->t1.row_id2 = 5;
1274+ tag->t1.row_id3 = 6;
1275+ tag->t1.row_id4 = 7;
1276+ tag->t1.lm = mode_to_lm[MT76_TM_TX_MODE_OFDM];
1277+
1278+ tag->t2.ibf_timeout = 0xff;
1279+ tag->t2.ibf_nr = nr;
1280+ }
1281+
1282+ ret = mt7915_tm_txbf_profile_tag_write(phy, pfmu_idx, tag);
1283+ if (ret)
1284+ return ret;
1285+
1286+ wcid = list_first_entry(&td->tm_entry_list, struct mt76_wcid, list);
1287+ ret = mt7915_tm_add_txbf(phy, vif, wcid_to_sta(wcid), pfmu_idx, nr, nc, ebf);
1288+ if (ret)
1289+ return ret;
1290+
1291+ if (!ebf)
1292+ return mt7915_tm_txbf_apply_tx(phy, 1, false, true, true);
1293+
1294+ return 0;
1295+}
1296+
1297+static int
1298+mt7915_tm_txbf_phase_cal(struct mt7915_phy *phy, u16 *val)
1299+{
1300+#define GROUP_L 0
1301+#define GROUP_M 1
1302+#define GROUP_H 2
1303+ struct mt7915_dev *dev = phy->dev;
1304+ struct {
1305+ u8 category;
1306+ u8 group_l_m_n;
1307+ u8 group;
1308+ bool sx2;
1309+ u8 cal_type;
1310+ u8 lna_gain_level;
1311+ u8 _rsv[2];
1312+ } __packed req = {
1313+ .category = MT_BF_PHASE_CAL,
1314+ .group = val[0],
1315+ .group_l_m_n = val[1],
1316+ .sx2 = val[2],
1317+ .cal_type = val[3],
1318+ .lna_gain_level = 0, /* for test purpose */
1319+ };
1320+ struct mt7915_tm_txbf_phase *phase =
1321+ (struct mt7915_tm_txbf_phase *)dev->test.txbf_phase_cal;
1322+
1323+ phase[req.group].status = 0;
1324+
1325+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(TXBF_ACTION), &req,
1326+ sizeof(req), true);
1327+}
1328+
1329+int mt7915_tm_txbf_status_read(struct mt7915_dev *dev, struct sk_buff *skb)
1330+{
1331+#define BF_PFMU_TAG 16
1332+#define BF_CAL_PHASE 21
1333+ u8 format_id;
1334+
developeraace7f52022-06-24 13:40:42 +08001335+ skb_pull(skb, sizeof(struct mt76_connac2_mcu_rxd));
developer42b63282022-06-16 13:33:13 +08001336+ format_id = *(u8 *)skb->data;
1337+
1338+ if (format_id == BF_PFMU_TAG) {
1339+ struct mt7915_tm_pfmu_tag *tag = dev->test.txbf_pfmu_tag;
1340+
1341+ skb_pull(skb, 8);
1342+ memcpy(tag, skb->data, sizeof(struct mt7915_tm_pfmu_tag));
1343+ } else if (format_id == BF_CAL_PHASE) {
1344+ struct mt7915_tm_ibf_cal_info *cal;
1345+ struct mt7915_tm_txbf_phase *phase =
1346+ (struct mt7915_tm_txbf_phase *)dev->test.txbf_phase_cal;
1347+
1348+ cal = (struct mt7915_tm_ibf_cal_info *)skb->data;
1349+ switch (cal->cal_type) {
1350+ case IBF_PHASE_CAL_NORMAL:
1351+ case IBF_PHASE_CAL_NORMAL_INSTRUMENT:
1352+ if (cal->group_l_m_n != GROUP_M)
1353+ break;
1354+ phase = &phase[cal->group];
1355+ memcpy(&phase->phase, cal->buf + 16, sizeof(phase->phase));
1356+ phase->status = cal->status;
1357+ break;
1358+ case IBF_PHASE_CAL_VERIFY:
1359+ case IBF_PHASE_CAL_VERIFY_INSTRUMENT:
1360+ break;
1361+ default:
1362+ break;
1363+ }
1364+ }
1365+
1366+ wake_up(&dev->mt76.tx_wait);
1367+
1368+ return 0;
1369+}
1370+
1371+static int
1372+mt7915_tm_txbf_profile_update_all(struct mt7915_phy *phy, u16 *val)
1373+{
1374+ struct mt76_testmode_data *td = &phy->mt76->test;
developer2a209692023-08-14 20:23:42 +08001375+ u8 nss = hweight8(td->tx_antenna_mask);
developer42b63282022-06-16 13:33:13 +08001376+ u16 pfmu_idx = val[0];
1377+ u16 subc_id = val[1];
1378+ u16 angle11 = val[2];
1379+ u16 angle21 = val[3];
1380+ u16 angle31 = val[4];
1381+ u16 angle41 = val[5];
1382+ s16 phi11 = 0, phi21 = 0, phi31 = 0;
1383+ struct mt7915_tm_pfmu_data *pfmu_data;
1384+
1385+ if (subc_id > 63)
1386+ return -EINVAL;
1387+
developer2a209692023-08-14 20:23:42 +08001388+ if (nss == 2) {
developer42b63282022-06-16 13:33:13 +08001389+ phi11 = (s16)(angle21 - angle11);
developer2a209692023-08-14 20:23:42 +08001390+ } else if (nss == 3) {
developer42b63282022-06-16 13:33:13 +08001391+ phi11 = (s16)(angle31 - angle11);
1392+ phi21 = (s16)(angle31 - angle21);
1393+ } else {
1394+ phi11 = (s16)(angle41 - angle11);
1395+ phi21 = (s16)(angle41 - angle21);
1396+ phi31 = (s16)(angle41 - angle31);
1397+ }
1398+
1399+ pfmu_data = (struct mt7915_tm_pfmu_data *)phy->dev->test.txbf_pfmu_data;
1400+ pfmu_data = &pfmu_data[subc_id];
1401+
1402+ if (subc_id < 32)
1403+ pfmu_data->subc_idx = cpu_to_le16(subc_id + 224);
1404+ else
1405+ pfmu_data->subc_idx = cpu_to_le16(subc_id - 32);
1406+ pfmu_data->phi11 = cpu_to_le16(phi11);
1407+ pfmu_data->phi21 = cpu_to_le16(phi21);
1408+ pfmu_data->phi31 = cpu_to_le16(phi31);
1409+
1410+ if (subc_id == 63) {
1411+ struct mt7915_dev *dev = phy->dev;
1412+ struct {
1413+ u8 format_id;
1414+ u8 pfmu_idx;
1415+ u8 dbdc_idx;
1416+ u8 _rsv;
1417+ u8 buf[512];
1418+ } __packed req = {
1419+ .format_id = MT_BF_PROFILE_WRITE_ALL,
1420+ .pfmu_idx = pfmu_idx,
1421+ .dbdc_idx = phy != &dev->phy,
1422+ };
1423+
1424+ memcpy(req.buf, dev->test.txbf_pfmu_data, 512);
1425+
1426+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(TXBF_ACTION),
1427+ &req, sizeof(req), true);
1428+ }
1429+
1430+ return 0;
1431+}
1432+
1433+static int
1434+mt7915_tm_txbf_e2p_update(struct mt7915_phy *phy)
1435+{
1436+ struct mt7915_tm_txbf_phase *phase, *p;
1437+ struct mt7915_dev *dev = phy->dev;
1438+ u8 *eeprom = dev->mt76.eeprom.data;
1439+ u16 offset;
1440+ bool is_7976;
1441+ int i;
1442+
1443+ is_7976 = mt7915_check_adie(dev, false) || is_mt7916(&dev->mt76);
1444+ offset = is_7976 ? 0x60a : 0x651;
1445+
1446+ phase = (struct mt7915_tm_txbf_phase *)dev->test.txbf_phase_cal;
1447+ for (i = 0; i < MAX_PHASE_GROUP_NUM; i++) {
1448+ p = &phase[i];
1449+
1450+ if (!p->status)
1451+ continue;
1452+
1453+ /* copy phase cal data to eeprom */
1454+ memcpy(eeprom + offset + i * sizeof(p->phase), &p->phase,
1455+ sizeof(p->phase));
1456+ }
1457+
1458+ return 0;
1459+}
1460+
1461+static int
1462+mt7915_tm_set_txbf(struct mt7915_phy *phy)
1463+{
1464+ struct mt76_testmode_data *td = &phy->mt76->test;
1465+ u16 *val = td->txbf_param;
1466+
1467+ pr_info("ibf cal process: act = %u, val = %u, %u, %u, %u, %u\n",
1468+ td->txbf_act, val[0], val[1], val[2], val[3], val[4]);
1469+
1470+ switch (td->txbf_act) {
1471+ case MT76_TM_TXBF_ACT_INIT:
1472+ return mt7915_tm_txbf_init(phy, val);
1473+ case MT76_TM_TXBF_ACT_UPDATE_CH:
1474+ mt7915_tm_update_channel(phy);
1475+ break;
1476+ case MT76_TM_TXBF_ACT_PHASE_COMP:
1477+ return mt7915_tm_txbf_phase_comp(phy, val);
1478+ case MT76_TM_TXBF_ACT_TX_PREP:
1479+ return mt7915_tm_txbf_set_tx(phy, val);
1480+ case MT76_TM_TXBF_ACT_IBF_PROF_UPDATE:
1481+ return mt7915_tm_txbf_profile_update(phy, val, false);
1482+ case MT76_TM_TXBF_ACT_EBF_PROF_UPDATE:
1483+ return mt7915_tm_txbf_profile_update(phy, val, true);
1484+ case MT76_TM_TXBF_ACT_PHASE_CAL:
1485+ return mt7915_tm_txbf_phase_cal(phy, val);
1486+ case MT76_TM_TXBF_ACT_PROF_UPDATE_ALL:
1487+ return mt7915_tm_txbf_profile_update_all(phy, val);
1488+ case MT76_TM_TXBF_ACT_E2P_UPDATE:
1489+ return mt7915_tm_txbf_e2p_update(phy);
1490+ default:
1491+ break;
1492+ };
1493+
1494+ return 0;
1495+}
1496+
1497 static int
developeraace7f52022-06-24 13:40:42 +08001498 mt7915_tm_set_wmm_qid(struct mt7915_phy *phy, u8 qid, u8 aifs, u8 cw_min,
developer42b63282022-06-16 13:33:13 +08001499- u16 cw_max, u16 txop)
1500+ u16 cw_max, u16 txop, u8 tx_cmd)
1501 {
developeraace7f52022-06-24 13:40:42 +08001502 struct mt7915_vif *mvif = (struct mt7915_vif *)phy->monitor_vif->drv_priv;
developer42b63282022-06-16 13:33:13 +08001503- struct mt7915_mcu_tx req = { .total = 1 };
1504+ struct mt7915_mcu_tx req = {
1505+ .valid = true,
1506+ .mode = tx_cmd,
1507+ .total = 1,
1508+ };
1509 struct edca *e = &req.edca[0];
1510
developeraace7f52022-06-24 13:40:42 +08001511 e->queue = qid + mvif->mt76.wmm_idx * MT76_CONNAC_MAX_WMM_SETS;
developere35b8e42023-10-16 11:04:00 +08001512@@ -263,7 +1059,8 @@ done:
developer42b63282022-06-16 13:33:13 +08001513
developeraace7f52022-06-24 13:40:42 +08001514 return mt7915_tm_set_wmm_qid(phy,
developer42b63282022-06-16 13:33:13 +08001515 mt76_connac_lmac_mapping(IEEE80211_AC_BE),
1516- aifsn, cw, cw, 0);
1517+ aifsn, cw, cw, 0,
1518+ mode == MT76_TM_TX_MODE_HE_MU);
1519 }
1520
1521 static int
developere35b8e42023-10-16 11:04:00 +08001522@@ -339,7 +1136,7 @@ mt7915_tm_set_tx_len(struct mt7915_phy *phy, u32 tx_time)
developer42b63282022-06-16 13:33:13 +08001523 bitrate = cfg80211_calculate_bitrate(&rate);
1524 tx_len = bitrate * tx_time / 10 / 8;
1525
1526- ret = mt76_testmode_alloc_skb(phy->mt76, tx_len);
1527+ ret = mt76_testmode_init_skb(phy->mt76, tx_len, &td->tx_skb, td->addr);
1528 if (ret)
1529 return ret;
1530
developere35b8e42023-10-16 11:04:00 +08001531@@ -458,64 +1255,227 @@ mt7915_tm_init(struct mt7915_phy *phy, bool en)
developer42b63282022-06-16 13:33:13 +08001532
1533 phy->mt76->test.flag |= MT_TM_FW_RX_COUNT;
1534
1535- if (!en)
1536+ if (!en) {
1537 mt7915_tm_set_tam_arb(phy, en, 0);
1538+
1539+ phy->mt76->test.aid = 0;
1540+ phy->mt76->test.tx_mpdu_len = 0;
1541+ phy->test.bf_en = 0;
1542+ mt7915_tm_set_entry(phy);
1543+ }
1544+}
1545+
1546+static bool
1547+mt7915_tm_check_skb(struct mt7915_phy *phy)
1548+{
1549+ struct mt76_testmode_entry_data *ed;
1550+ struct mt76_wcid *wcid;
1551+
1552+ mt76_tm_for_each_entry(phy->mt76, wcid, ed) {
1553+ struct ieee80211_tx_info *info;
1554+
1555+ if (!ed->tx_skb)
1556+ return false;
1557+
1558+ info = IEEE80211_SKB_CB(ed->tx_skb);
1559+ info->control.vif = phy->monitor_vif;
1560+ }
1561+
1562+ return true;
1563+}
1564+
1565+static int
1566+mt7915_tm_set_ba(struct mt7915_phy *phy)
1567+{
1568+ struct mt7915_dev *dev = phy->dev;
1569+ struct mt76_testmode_data *td = &phy->mt76->test;
1570+ struct mt76_wcid *wcid;
1571+ struct ieee80211_vif *vif = phy->monitor_vif;
1572+ struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
1573+ struct ieee80211_ampdu_params params = { .buf_size = 256 };
1574+
1575+ list_for_each_entry(wcid, &td->tm_entry_list, list) {
1576+ int tid, ret;
1577+
1578+ params.sta = wcid_to_sta(wcid);
1579+ for (tid = 0; tid < 8; tid++) {
1580+ params.tid = tid;
1581+ ret = mt7915_mcu_add_tx_ba(phy->dev, &params, true);
1582+ if (ret)
1583+ return ret;
1584+ }
1585+ }
1586+
1587+ mt76_wr(dev, MT_AGG_AALCR0(mvif->mt76.band_idx, mvif->mt76.wmm_idx),
1588+ 0x01010101);
1589+
1590+ return 0;
1591+}
1592+
1593+static int
1594+mt7915_tm_set_muru_cfg(struct mt7915_phy *phy, struct mt7915_tm_muru *muru)
1595+{
1596+/* #define MURU_SET_MANUAL_CFG 100 */
1597+ struct mt7915_dev *dev = phy->dev;
1598+ struct {
1599+ __le32 cmd;
1600+ struct mt7915_tm_muru muru;
1601+ } __packed req = {
1602+ .cmd = cpu_to_le32(MURU_SET_MANUAL_CFG),
1603+ };
1604+
1605+ memcpy(&req.muru, muru, sizeof(struct mt7915_tm_muru));
1606+
1607+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(MURU_CTRL), &req,
1608+ sizeof(req), false);
1609+}
1610+
1611+static int
1612+mt7915_tm_set_muru_dl(struct mt7915_phy *phy)
1613+{
1614+ struct mt76_testmode_data *td = &phy->mt76->test;
1615+ struct mt76_testmode_entry_data *ed;
1616+ struct mt76_wcid *wcid;
1617+ struct cfg80211_chan_def *chandef = &phy->mt76->chandef;
1618+ struct ieee80211_vif *vif = phy->monitor_vif;
1619+ struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
1620+ struct mt7915_tm_muru muru = {};
1621+ struct mt7915_tm_muru_comm *comm = &muru.comm;
1622+ struct mt7915_tm_muru_dl *dl = &muru.dl;
1623+ int i;
1624+
1625+ comm->ppdu_format = MURU_PPDU_HE_MU;
1626+ comm->band = mvif->mt76.band_idx;
1627+ comm->wmm_idx = mvif->mt76.wmm_idx;
1628+ comm->spe_idx = phy->test.spe_idx;
1629+
1630+ dl->bw = mt7915_tm_chan_bw(chandef->width);
developer281084d2023-06-19 12:03:50 +08001631+ dl->gi = td->tx_rate_sgi;
developer42b63282022-06-16 13:33:13 +08001632+ dl->ltf = td->tx_ltf;
1633+ dl->tx_mode = MT_PHY_TYPE_HE_MU;
1634+
1635+ for (i = 0; i < sizeof(dl->ru); i++)
1636+ dl->ru[i] = 0x71;
1637+
1638+ mt76_tm_for_each_entry(phy->mt76, wcid, ed) {
1639+ struct mt7915_tm_muru_dl_usr *dl_usr = &dl->usr[dl->user_num];
1640+
1641+ dl_usr->wlan_idx = cpu_to_le16(wcid->idx);
1642+ dl_usr->ru_alloc_seg = ed->aid < 8 ? 0 : 1;
1643+ dl_usr->ru_idx = ed->ru_idx;
1644+ dl_usr->mcs = ed->tx_rate_idx;
1645+ dl_usr->nss = ed->tx_rate_nss - 1;
1646+ dl_usr->ldpc = ed->tx_rate_ldpc;
1647+ dl->ru[dl->user_num] = ed->ru_alloc;
1648+
1649+ dl->user_num++;
1650+ }
1651+
developerc07d01e2023-05-05 13:45:43 +08001652+ muru.cfg_comm = cpu_to_le32(MURU_COMM_SET_TM);
developer42b63282022-06-16 13:33:13 +08001653+ muru.cfg_dl = cpu_to_le32(MURU_DL_SET);
1654+
1655+ return mt7915_tm_set_muru_cfg(phy, &muru);
1656+}
1657+
1658+static int
1659+mt7915_tm_set_muru_pkt_cnt(struct mt7915_phy *phy, bool enable, u32 tx_count)
1660+{
1661+#define MURU_SET_TX_PKT_CNT 105
1662+#define MURU_SET_TX_EN 106
1663+ struct mt7915_dev *dev = phy->dev;
1664+ struct {
1665+ __le32 cmd;
1666+ u8 band;
1667+ u8 enable;
1668+ u8 _rsv[2];
1669+ __le32 tx_count;
1670+ } __packed req = {
developer2458e702022-12-13 15:52:04 +08001671+ .band = phy->mt76->band_idx,
developer42b63282022-06-16 13:33:13 +08001672+ .enable = enable,
1673+ .tx_count = enable ? cpu_to_le32(tx_count) : 0,
1674+ };
1675+ int ret;
1676+
1677+ req.cmd = enable ? cpu_to_le32(MURU_SET_TX_PKT_CNT) :
1678+ cpu_to_le32(MURU_SET_TX_EN);
1679+
1680+ ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(MURU_CTRL), &req,
1681+ sizeof(req), false);
1682+ if (ret)
1683+ return ret;
1684+
1685+ req.cmd = enable ? cpu_to_le32(MURU_SET_TX_EN) :
1686+ cpu_to_le32(MURU_SET_TX_PKT_CNT);
1687+
1688+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(MURU_CTRL), &req,
1689+ sizeof(req), false);
1690 }
1691
1692 static void
1693-mt7915_tm_update_channel(struct mt7915_phy *phy)
1694+mt7915_tm_tx_frames_mu(struct mt7915_phy *phy, bool enable)
1695 {
1696- mutex_unlock(&phy->dev->mt76.mutex);
1697- mt7915_set_channel(phy);
1698- mutex_lock(&phy->dev->mt76.mutex);
1699+ struct mt76_testmode_data *td = &phy->mt76->test;
1700
1701- mt7915_mcu_set_chan_info(phy, MCU_EXT_CMD(SET_RX_PATH));
1702+ if (enable) {
1703+ struct mt7915_dev *dev = phy->dev;
1704+
1705+ mt7915_tm_set_ba(phy);
1706+ mt7915_tm_set_muru_dl(phy);
1707+ mt76_rr(dev, MT_MIB_DR8(phy != &dev->phy));
1708+ } else {
1709+ /* set to zero for counting real tx free num */
1710+ td->tx_done = 0;
1711+ }
1712+
1713+ mt7915_tm_set_muru_pkt_cnt(phy, enable, td->tx_count);
1714+ usleep_range(100000, 200000);
1715 }
1716
1717 static void
developerd4975692022-07-15 18:30:03 +08001718 mt7915_tm_set_tx_frames(struct mt7915_phy *phy, bool en)
1719 {
developer42b63282022-06-16 13:33:13 +08001720 struct mt76_testmode_data *td = &phy->mt76->test;
1721- struct mt7915_dev *dev = phy->dev;
1722- struct ieee80211_tx_info *info;
1723- u8 duty_cycle = td->tx_duty_cycle;
1724- u32 tx_time = td->tx_time;
1725- u32 ipg = td->tx_ipg;
1726
1727 mt7915_tm_set_trx(phy, TM_MAC_RX_RXV, false);
1728- mt7915_tm_clean_hwq(phy, dev->mt76.global_wcid.idx);
1729+ mt7915_tm_set_trx(phy, TM_MAC_TX, false);
1730
1731 if (en) {
1732- mt7915_tm_update_channel(phy);
1733+ u32 tx_time = td->tx_time, ipg = td->tx_ipg;
1734+ u8 duty_cycle = td->tx_duty_cycle;
1735+
1736+ if (!phy->test.bf_en)
1737+ mt7915_tm_update_channel(phy);
1738
developerd4975692022-07-15 18:30:03 +08001739 if (td->tx_spe_idx)
developer42b63282022-06-16 13:33:13 +08001740 phy->test.spe_idx = td->tx_spe_idx;
developerd4975692022-07-15 18:30:03 +08001741 else
1742 phy->test.spe_idx = mt76_connac_spe_idx(td->tx_antenna_mask);
developer42b63282022-06-16 13:33:13 +08001743- }
1744
1745- mt7915_tm_set_tam_arb(phy, en,
1746- td->tx_rate_mode == MT76_TM_TX_MODE_HE_MU);
1747+ /* if all three params are set, duty_cycle will be ignored */
1748+ if (duty_cycle && tx_time && !ipg) {
1749+ ipg = tx_time * 100 / duty_cycle - tx_time;
1750+ } else if (duty_cycle && !tx_time && ipg) {
1751+ if (duty_cycle < 100)
1752+ tx_time = duty_cycle * ipg / (100 - duty_cycle);
1753+ }
1754
1755- /* if all three params are set, duty_cycle will be ignored */
1756- if (duty_cycle && tx_time && !ipg) {
1757- ipg = tx_time * 100 / duty_cycle - tx_time;
1758- } else if (duty_cycle && !tx_time && ipg) {
1759- if (duty_cycle < 100)
1760- tx_time = duty_cycle * ipg / (100 - duty_cycle);
1761- }
1762+ mt7915_tm_set_ipg_params(phy, ipg, td->tx_rate_mode);
1763+ mt7915_tm_set_tx_len(phy, tx_time);
1764
1765- mt7915_tm_set_ipg_params(phy, ipg, td->tx_rate_mode);
1766- mt7915_tm_set_tx_len(phy, tx_time);
1767+ if (ipg)
1768+ td->tx_queued_limit = MT76_TM_TIMEOUT * 1000000 / ipg / 2;
1769
1770- if (ipg)
1771- td->tx_queued_limit = MT76_TM_TIMEOUT * 1000000 / ipg / 2;
1772+ if (!mt7915_tm_check_skb(phy))
1773+ return;
1774+ } else {
1775+ mt7915_tm_clean_hwq(phy);
1776+ }
1777
1778- if (!en || !td->tx_skb)
1779- return;
1780+ mt7915_tm_set_tam_arb(phy, en,
1781+ td->tx_rate_mode == MT76_TM_TX_MODE_HE_MU);
1782
1783- info = IEEE80211_SKB_CB(td->tx_skb);
1784- info->control.vif = phy->monitor_vif;
1785+ if (td->tx_rate_mode == MT76_TM_TX_MODE_HE_MU)
1786+ mt7915_tm_tx_frames_mu(phy, en);
1787
1788 mt7915_tm_set_trx(phy, TM_MAC_TX, en);
1789 }
developere35b8e42023-10-16 11:04:00 +08001790@@ -544,10 +1504,6 @@ mt7915_tm_get_rx_stats(struct mt7915_phy *phy, bool clear)
developer42b63282022-06-16 13:33:13 +08001791 return ret;
1792
1793 rs_band = (struct mt7915_tm_rx_stat_band *)skb->data;
1794- /* pr_info("mdrdy_cnt = %d\n", le32_to_cpu(rs_band->mdrdy_cnt)); */
1795- /* pr_info("fcs_err = %d\n", le16_to_cpu(rs_band->fcs_err)); */
1796- /* pr_info("len_mismatch = %d\n", le16_to_cpu(rs_band->len_mismatch)); */
1797- /* pr_info("fcs_ok = %d\n", le16_to_cpu(rs_band->fcs_succ)); */
1798
1799 if (!clear) {
developer4df64ba2022-09-01 14:44:55 +08001800 enum mt76_rxq_id q = req.band ? MT_RXQ_BAND1 : MT_RXQ_MAIN;
developere35b8e42023-10-16 11:04:00 +08001801@@ -562,13 +1518,61 @@ mt7915_tm_get_rx_stats(struct mt7915_phy *phy, bool clear)
developer42b63282022-06-16 13:33:13 +08001802 return 0;
1803 }
1804
1805+static int
1806+mt7915_tm_set_rx_user_idx(struct mt7915_phy *phy, u8 aid)
1807+{
1808+ struct mt7915_dev *dev = phy->dev;
1809+ struct mt76_wcid *wcid = NULL;
1810+ struct mt76_testmode_entry_data *ed;
1811+ struct {
1812+ u8 band;
1813+ u8 _rsv;
1814+ __le16 wlan_idx;
1815+ } __packed req = {
developer2458e702022-12-13 15:52:04 +08001816+ .band = phy->mt76->band_idx,
developer42b63282022-06-16 13:33:13 +08001817+ };
1818+
1819+ mt76_tm_for_each_entry(phy->mt76, wcid, ed)
1820+ if (ed->aid == aid)
1821+ break;
1822+
1823+ if (!wcid)
1824+ return -EINVAL;
1825+
1826+ req.wlan_idx = cpu_to_le16(wcid->idx);
1827+
1828+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(RX_STAT_USER_CTRL),
1829+ &req, sizeof(req), false);
1830+}
1831+
1832+static int
1833+mt7915_tm_set_muru_aid(struct mt7915_phy *phy, u16 aid)
1834+{
1835+ struct mt7915_dev *dev = phy->dev;
1836+ struct mt7915_tm_cmd req = {
1837+ .testmode_en = 1,
1838+ .param_idx = MCU_ATE_SET_MU_RX_AID,
developer2458e702022-12-13 15:52:04 +08001839+ .param.rx_aid.band = cpu_to_le32(phy->mt76->band_idx),
developer42b63282022-06-16 13:33:13 +08001840+ .param.rx_aid.aid = cpu_to_le16(aid),
1841+ };
1842+
1843+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(ATE_CTRL), &req,
1844+ sizeof(req), false);
1845+}
1846+
1847 static void
1848 mt7915_tm_set_rx_frames(struct mt7915_phy *phy, bool en)
1849 {
1850+ struct mt76_testmode_data *td = &phy->mt76->test;
1851+
1852+ mt7915_tm_set_trx(phy, TM_MAC_TX, false);
1853 mt7915_tm_set_trx(phy, TM_MAC_RX_RXV, false);
1854
1855 if (en) {
1856- mt7915_tm_update_channel(phy);
1857+ if (!phy->test.bf_en)
1858+ mt7915_tm_update_channel(phy);
1859+ if (td->aid)
1860+ mt7915_tm_set_rx_user_idx(phy, td->aid);
1861
1862 /* read-clear */
1863 mt7915_tm_get_rx_stats(phy, true);
developere35b8e42023-10-16 11:04:00 +08001864@@ -576,9 +1580,12 @@ mt7915_tm_set_rx_frames(struct mt7915_phy *phy, bool en)
developer42b63282022-06-16 13:33:13 +08001865 /* clear fw count */
1866 mt7915_tm_set_phy_count(phy, 0);
1867 mt7915_tm_set_phy_count(phy, 1);
1868-
1869- mt7915_tm_set_trx(phy, TM_MAC_RX_RXV, en);
1870 }
1871+
1872+ if (td->tx_rate_mode == MT76_TM_TX_MODE_HE_MU)
1873+ mt7915_tm_set_muru_aid(phy, en ? td->aid : 0xf800);
1874+
1875+ mt7915_tm_set_trx(phy, TM_MAC_RX_RXV, en);
1876 }
1877
1878 static int
developere35b8e42023-10-16 11:04:00 +08001879@@ -617,34 +1624,7 @@ mt7915_tm_set_tx_cont(struct mt7915_phy *phy, bool en)
developer42b63282022-06-16 13:33:13 +08001880 tx_cont->tx_ant = td->tx_antenna_mask;
developer2458e702022-12-13 15:52:04 +08001881 tx_cont->band = band;
developer3d5faf22022-11-29 18:07:22 +08001882
developer42b63282022-06-16 13:33:13 +08001883- switch (chandef->width) {
1884- case NL80211_CHAN_WIDTH_40:
1885- tx_cont->bw = CMD_CBW_40MHZ;
1886- break;
1887- case NL80211_CHAN_WIDTH_80:
1888- tx_cont->bw = CMD_CBW_80MHZ;
1889- break;
1890- case NL80211_CHAN_WIDTH_80P80:
1891- tx_cont->bw = CMD_CBW_8080MHZ;
1892- break;
1893- case NL80211_CHAN_WIDTH_160:
1894- tx_cont->bw = CMD_CBW_160MHZ;
1895- break;
1896- case NL80211_CHAN_WIDTH_5:
1897- tx_cont->bw = CMD_CBW_5MHZ;
1898- break;
1899- case NL80211_CHAN_WIDTH_10:
1900- tx_cont->bw = CMD_CBW_10MHZ;
1901- break;
1902- case NL80211_CHAN_WIDTH_20:
1903- tx_cont->bw = CMD_CBW_20MHZ;
1904- break;
1905- case NL80211_CHAN_WIDTH_20_NOHT:
1906- tx_cont->bw = CMD_CBW_20MHZ;
1907- break;
1908- default:
1909- return -EINVAL;
1910- }
1911+ tx_cont->bw = mt7915_tm_chan_bw(chandef->width);
1912
1913 if (!en) {
developer2458e702022-12-13 15:52:04 +08001914 req.op.rf.param.func_data = cpu_to_le32(band);
developere35b8e42023-10-16 11:04:00 +08001915@@ -728,6 +1708,16 @@ mt7915_tm_update_params(struct mt7915_phy *phy, u32 changed)
developer42b63282022-06-16 13:33:13 +08001916 mt7915_tm_set_freq_offset(phy, en, en ? td->freq_offset : 0);
1917 if (changed & BIT(TM_CHANGED_TXPOWER))
1918 mt7915_tm_set_tx_power(phy);
developere35b8e42023-10-16 11:04:00 +08001919+ if (changed & BIT(TM_CHANGED_SKU_EN)) {
1920+ mt7915_mcu_set_sku_en(phy, td->sku_en);
1921+ mt7915_mcu_set_txpower_sku(phy);
1922+ }
developer42b63282022-06-16 13:33:13 +08001923+ if (changed & BIT(TM_CHANGED_AID))
1924+ mt7915_tm_set_entry(phy);
1925+ if (changed & BIT(TM_CHANGED_CFG))
1926+ mt7915_tm_set_cfg(phy);
1927+ if (changed & BIT(TM_CHANGED_TXBF_ACT))
1928+ mt7915_tm_set_txbf(phy);
1929 }
1930
1931 static int
developere35b8e42023-10-16 11:04:00 +08001932@@ -737,6 +1727,11 @@ mt7915_tm_set_state(struct mt76_phy *mphy, enum mt76_testmode_state state)
developerf8871e82023-03-08 17:22:32 +08001933 struct mt7915_phy *phy = mphy->priv;
1934 enum mt76_testmode_state prev_state = td->state;
1935
1936+ if (!phy->monitor_vif) {
1937+ dev_err(phy->dev->mt76.dev, "Please make sure monitor interface is up\n");
1938+ return -ENOTCONN;
1939+ }
1940+
1941 mphy->test.state = state;
1942
1943 if (prev_state == MT76_TM_STATE_TX_FRAMES ||
developere35b8e42023-10-16 11:04:00 +08001944@@ -757,7 +1752,7 @@ mt7915_tm_set_state(struct mt76_phy *mphy, enum mt76_testmode_state state)
developer281084d2023-06-19 12:03:50 +08001945 (state == MT76_TM_STATE_OFF &&
1946 prev_state == MT76_TM_STATE_IDLE)) {
1947 u32 changed = 0;
1948- int i;
1949+ int i, ret;
1950
1951 for (i = 0; i < ARRAY_SIZE(tm_change_map); i++) {
1952 u16 cur = tm_change_map[i];
developere35b8e42023-10-16 11:04:00 +08001953@@ -766,6 +1761,10 @@ mt7915_tm_set_state(struct mt76_phy *mphy, enum mt76_testmode_state state)
developer281084d2023-06-19 12:03:50 +08001954 changed |= BIT(i);
1955 }
1956
1957+ ret = mt7915_tm_check_antenna(phy);
1958+ if (ret)
1959+ return ret;
1960+
1961 mt7915_tm_update_params(phy, changed);
1962 }
1963
developere35b8e42023-10-16 11:04:00 +08001964@@ -778,10 +1777,8 @@ mt7915_tm_set_params(struct mt76_phy *mphy, struct nlattr **tb,
developer281084d2023-06-19 12:03:50 +08001965 {
1966 struct mt76_testmode_data *td = &mphy->test;
1967 struct mt7915_phy *phy = mphy->priv;
1968- struct mt7915_dev *dev = phy->dev;
1969- u32 chainmask = mphy->chainmask, changed = 0;
1970- bool ext_phy = phy != &dev->phy;
1971- int i;
1972+ u32 changed = 0;
1973+ int i, ret;
1974
1975 BUILD_BUG_ON(NUM_TM_CHANGED >= 32);
1976
developere35b8e42023-10-16 11:04:00 +08001977@@ -789,9 +1786,9 @@ mt7915_tm_set_params(struct mt76_phy *mphy, struct nlattr **tb,
developer281084d2023-06-19 12:03:50 +08001978 td->state == MT76_TM_STATE_OFF)
1979 return 0;
1980
1981- chainmask = ext_phy ? chainmask >> dev->chainshift : chainmask;
1982- if (td->tx_antenna_mask > chainmask)
1983- return -EINVAL;
1984+ ret = mt7915_tm_check_antenna(phy);
1985+ if (ret)
1986+ return ret;
1987
1988 for (i = 0; i < ARRAY_SIZE(tm_change_map); i++) {
1989 if (tb[tm_change_map[i]])
developere35b8e42023-10-16 11:04:00 +08001990@@ -807,6 +1804,7 @@ static int
developer42b63282022-06-16 13:33:13 +08001991 mt7915_tm_dump_stats(struct mt76_phy *mphy, struct sk_buff *msg)
1992 {
1993 struct mt7915_phy *phy = mphy->priv;
1994+ struct mt7915_dev *dev = phy->dev;
1995 void *rx, *rssi;
1996 int i;
1997
developere35b8e42023-10-16 11:04:00 +08001998@@ -827,6 +1825,16 @@ mt7915_tm_dump_stats(struct mt76_phy *mphy, struct sk_buff *msg)
1999
2000 nla_nest_end(msg, rssi);
2001
2002+ rssi = nla_nest_start(msg, MT76_TM_RX_ATTR_RSSI);
2003+ if (!rssi)
2004+ return -ENOMEM;
2005+
2006+ for (i = 0; i < ARRAY_SIZE(phy->test.last_rssi); i++)
2007+ if (nla_put_s8(msg, i, phy->test.last_rssi[i]))
2008+ return -ENOMEM;
2009+
2010+ nla_nest_end(msg, rssi);
2011+
2012 rssi = nla_nest_start(msg, MT76_TM_RX_ATTR_IB_RSSI);
2013 if (!rssi)
2014 return -ENOMEM;
2015@@ -852,11 +1860,75 @@ mt7915_tm_dump_stats(struct mt76_phy *mphy, struct sk_buff *msg)
developer42b63282022-06-16 13:33:13 +08002016
2017 nla_nest_end(msg, rx);
2018
2019+ if (mphy->test.tx_rate_mode == MT76_TM_TX_MODE_HE_MU)
2020+ mphy->test.tx_done += mt76_rr(dev, MT_MIB_DR8(phy != &dev->phy));
2021+
2022 return mt7915_tm_get_rx_stats(phy, false);
2023 }
2024
2025+static int
2026+mt7915_tm_write_back_to_efuse(struct mt7915_dev *dev)
2027+{
2028+ struct mt7915_mcu_eeprom_info req = {};
developerae9afc02023-04-06 18:07:42 +08002029+ u8 read_buf[MT76_TM_EEPROM_BLOCK_SIZE], *eeprom = dev->mt76.eeprom.data;
developer42b63282022-06-16 13:33:13 +08002030+ int i, ret = -EINVAL;
2031+
2032+ /* prevent from damaging chip id in efuse */
2033+ if (mt76_chip(&dev->mt76) != get_unaligned_le16(eeprom))
2034+ goto out;
2035+
2036+ for (i = 0; i < mt7915_eeprom_size(dev); i += MT76_TM_EEPROM_BLOCK_SIZE) {
2037+ req.addr = cpu_to_le32(i);
developerae9afc02023-04-06 18:07:42 +08002038+ memcpy(req.data, eeprom + i, MT76_TM_EEPROM_BLOCK_SIZE);
2039+
2040+ ret = mt7915_mcu_get_eeprom(dev, i, read_buf);
2041+ if (ret < 0)
2042+ return ret;
2043+
2044+ if (!memcmp(req.data, read_buf, MT76_TM_EEPROM_BLOCK_SIZE))
2045+ continue;
developer42b63282022-06-16 13:33:13 +08002046+
2047+ ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(EFUSE_ACCESS),
2048+ &req, sizeof(req), true);
2049+ if (ret)
2050+ return ret;
2051+ }
2052+
2053+out:
2054+ return ret;
2055+}
2056+
2057+static int
2058+mt7915_tm_set_eeprom(struct mt76_phy *mphy, u32 offset, u8 *val, u8 action)
2059+{
2060+ struct mt7915_phy *phy = mphy->priv;
2061+ struct mt7915_dev *dev = phy->dev;
2062+ u8 *eeprom = dev->mt76.eeprom.data;
2063+ int ret = 0;
2064+
2065+ if (offset >= mt7915_eeprom_size(dev))
2066+ return -EINVAL;
2067+
2068+ switch (action) {
2069+ case MT76_TM_EEPROM_ACTION_UPDATE_DATA:
2070+ memcpy(eeprom + offset, val, MT76_TM_EEPROM_BLOCK_SIZE);
2071+ break;
2072+ case MT76_TM_EEPROM_ACTION_UPDATE_BUFFER_MODE:
2073+ ret = mt7915_mcu_set_eeprom(dev, true);
2074+ break;
2075+ case MT76_TM_EEPROM_ACTION_WRITE_TO_EFUSE:
2076+ ret = mt7915_tm_write_back_to_efuse(dev);
2077+ break;
2078+ default:
2079+ break;
2080+ }
2081+
2082+ return ret;
2083+}
2084+
2085 const struct mt76_testmode_ops mt7915_testmode_ops = {
2086 .set_state = mt7915_tm_set_state,
2087 .set_params = mt7915_tm_set_params,
2088 .dump_stats = mt7915_tm_dump_stats,
2089+ .set_eeprom = mt7915_tm_set_eeprom,
2090 };
2091diff --git a/mt7915/testmode.h b/mt7915/testmode.h
developere35b8e42023-10-16 11:04:00 +08002092index a1c54c8..eb0e043 100644
developer42b63282022-06-16 13:33:13 +08002093--- a/mt7915/testmode.h
2094+++ b/mt7915/testmode.h
2095@@ -4,6 +4,8 @@
2096 #ifndef __MT7915_TESTMODE_H
2097 #define __MT7915_TESTMODE_H
2098
2099+#include "mcu.h"
2100+
2101 struct mt7915_tm_trx {
2102 u8 type;
2103 u8 enable;
2104@@ -39,6 +41,11 @@ struct mt7915_tm_cfg {
2105 u8 _rsv[2];
2106 };
2107
2108+struct mt7915_tm_mu_rx_aid {
2109+ __le32 band;
2110+ __le16 aid;
2111+};
2112+
2113 struct mt7915_tm_cmd {
2114 u8 testmode_en;
2115 u8 param_idx;
2116@@ -50,6 +57,7 @@ struct mt7915_tm_cmd {
2117 struct mt7915_tm_slot_time slot;
2118 struct mt7915_tm_clean_txq clean;
2119 struct mt7915_tm_cfg cfg;
2120+ struct mt7915_tm_mu_rx_aid rx_aid;
2121 u8 test[72];
2122 } param;
2123 } __packed;
2124@@ -109,6 +117,16 @@ enum {
2125 TAM_ARB_OP_MODE_FORCE_SU = 5,
2126 };
2127
2128+enum {
2129+ TM_CBW_20MHZ,
2130+ TM_CBW_40MHZ,
2131+ TM_CBW_80MHZ,
2132+ TM_CBW_10MHZ,
2133+ TM_CBW_5MHZ,
2134+ TM_CBW_160MHZ,
2135+ TM_CBW_8080MHZ,
2136+};
2137+
2138 struct mt7915_tm_rx_stat_band {
2139 u8 category;
2140
2141@@ -130,4 +148,264 @@ struct mt7915_tm_rx_stat_band {
2142 __le16 mdrdy_cnt_ofdm;
2143 };
2144
2145+struct mt7915_tm_muru_comm {
2146+ u8 ppdu_format;
2147+ u8 sch_type;
2148+ u8 band;
2149+ u8 wmm_idx;
2150+ u8 spe_idx;
2151+ u8 proc_type;
2152+};
2153+
2154+struct mt7915_tm_muru_dl_usr {
2155+ __le16 wlan_idx;
2156+ u8 ru_alloc_seg;
2157+ u8 ru_idx;
2158+ u8 ldpc;
2159+ u8 nss;
2160+ u8 mcs;
2161+ u8 mu_group_idx;
2162+ u8 vht_groud_id;
2163+ u8 vht_up;
2164+ u8 he_start_stream;
2165+ u8 he_mu_spatial;
2166+ u8 ack_policy;
2167+ __le16 tx_power_alpha;
2168+};
2169+
2170+struct mt7915_tm_muru_dl {
2171+ u8 user_num;
2172+ u8 tx_mode;
2173+ u8 bw;
2174+ u8 gi;
2175+ u8 ltf;
2176+ /* sigB */
2177+ u8 mcs;
2178+ u8 dcm;
2179+ u8 cmprs;
2180+
2181+ u8 tx_power;
2182+ u8 ru[8];
2183+ u8 c26[2];
2184+ u8 ack_policy;
2185+
2186+ struct mt7915_tm_muru_dl_usr usr[16];
2187+};
2188+
2189+struct mt7915_tm_muru_ul_usr {
2190+ __le16 wlan_idx;
2191+ u8 ru_alloc;
2192+ u8 ru_idx;
2193+ u8 ldpc;
2194+ u8 nss;
2195+ u8 mcs;
2196+ u8 target_rssi;
2197+ __le32 trig_pkt_size;
2198+};
2199+
2200+struct mt7915_tm_muru_ul {
2201+ u8 user_num;
2202+
2203+ /* UL TX */
2204+ u8 trig_type;
2205+ __le16 trig_cnt;
2206+ __le16 trig_intv;
2207+ u8 bw;
2208+ u8 gi_ltf;
2209+ __le16 ul_len;
2210+ u8 pad;
2211+ u8 trig_ta[ETH_ALEN];
2212+ u8 ru[8];
2213+ u8 c26[2];
2214+
2215+ struct mt7915_tm_muru_ul_usr usr[16];
2216+ /* HE TB RX Debug */
2217+ __le32 rx_hetb_nonsf_en_bitmap;
2218+ __le32 rx_hetb_cfg[2];
2219+
2220+ /* DL TX */
2221+ u8 ba_type;
2222+};
2223+
2224+struct mt7915_tm_muru {
2225+ __le32 cfg_comm;
2226+ __le32 cfg_dl;
2227+ __le32 cfg_ul;
2228+
2229+ struct mt7915_tm_muru_comm comm;
2230+ struct mt7915_tm_muru_dl dl;
2231+ struct mt7915_tm_muru_ul ul;
2232+};
2233+
2234+#define MURU_PPDU_HE_MU BIT(3)
2235+
2236+/* Common Config */
2237+/* #define MURU_COMM_PPDU_FMT BIT(0) */
2238+/* #define MURU_COMM_SCH_TYPE BIT(1) */
developer281084d2023-06-19 12:03:50 +08002239+/* #define MURU_COMM_BAND BIT(2) */
2240+/* #define MURU_COMM_WMM BIT(3) */
developer42b63282022-06-16 13:33:13 +08002241+/* #define MURU_COMM_SPE_IDX BIT(4) */
2242+/* #define MURU_COMM_PROC_TYPE BIT(5) */
2243+/* #define MURU_COMM_SET (MURU_COMM_PPDU_FMT | MURU_COMM_BAND | \ */
developer281084d2023-06-19 12:03:50 +08002244+/* MURU_COMM_WMM | MURU_COMM_SPE_IDX) */
developer42b63282022-06-16 13:33:13 +08002245+/* DL Config */
2246+#define MURU_DL_BW BIT(0)
2247+#define MURU_DL_GI BIT(1)
2248+#define MURU_DL_TX_MODE BIT(2)
2249+#define MURU_DL_TONE_PLAN BIT(3)
2250+#define MURU_DL_USER_CNT BIT(4)
2251+#define MURU_DL_LTF BIT(5)
2252+#define MURU_DL_SIGB_MCS BIT(6)
2253+#define MURU_DL_SIGB_DCM BIT(7)
2254+#define MURU_DL_SIGB_CMPRS BIT(8)
2255+#define MURU_DL_ACK_POLICY BIT(9)
2256+#define MURU_DL_TXPOWER BIT(10)
2257+/* DL Per User Config */
2258+#define MURU_DL_USER_WLAN_ID BIT(16)
2259+#define MURU_DL_USER_COD BIT(17)
2260+#define MURU_DL_USER_MCS BIT(18)
2261+#define MURU_DL_USER_NSS BIT(19)
2262+#define MURU_DL_USER_RU_ALLOC BIT(20)
2263+#define MURU_DL_USER_MUMIMO_GRP BIT(21)
2264+#define MURU_DL_USER_MUMIMO_VHT BIT(22)
2265+#define MURU_DL_USER_ACK_POLICY BIT(23)
2266+#define MURU_DL_USER_MUMIMO_HE BIT(24)
2267+#define MURU_DL_USER_PWR_ALPHA BIT(25)
2268+#define MURU_DL_SET (GENMASK(7, 0) | GENMASK(20, 16) | BIT(25))
2269+
2270+#define MAX_PHASE_GROUP_NUM 9
2271+
2272+struct mt7915_tm_txbf_phase {
2273+ u8 status;
2274+ struct {
2275+ u8 r0_uh;
2276+ u8 r0_h;
2277+ u8 r0_m;
2278+ u8 r0_l;
2279+ u8 r0_ul;
2280+ u8 r1_uh;
2281+ u8 r1_h;
2282+ u8 r1_m;
2283+ u8 r1_l;
2284+ u8 r1_ul;
2285+ u8 r2_uh;
2286+ u8 r2_h;
2287+ u8 r2_m;
2288+ u8 r2_l;
2289+ u8 r2_ul;
2290+ u8 r3_uh;
2291+ u8 r3_h;
2292+ u8 r3_m;
2293+ u8 r3_l;
2294+ u8 r3_ul;
2295+ u8 r2_uh_sx2;
2296+ u8 r2_h_sx2;
2297+ u8 r2_m_sx2;
2298+ u8 r2_l_sx2;
2299+ u8 r2_ul_sx2;
2300+ u8 r3_uh_sx2;
2301+ u8 r3_h_sx2;
2302+ u8 r3_m_sx2;
2303+ u8 r3_l_sx2;
2304+ u8 r3_ul_sx2;
2305+ u8 m_t0_h;
2306+ u8 m_t1_h;
2307+ u8 m_t2_h;
2308+ u8 m_t2_h_sx2;
2309+ u8 r0_reserved;
2310+ u8 r1_reserved;
2311+ u8 r2_reserved;
2312+ u8 r3_reserved;
2313+ u8 r2_sx2_reserved;
2314+ u8 r3_sx2_reserved;
2315+ } phase;
2316+};
2317+
2318+struct mt7915_tm_pfmu_tag1 {
2319+ __le32 pfmu_idx:10;
2320+ __le32 ebf:1;
2321+ __le32 data_bw:2;
2322+ __le32 lm:2;
2323+ __le32 is_mu:1;
2324+ __le32 nr:3, nc:3;
2325+ __le32 codebook:2;
2326+ __le32 ngroup:2;
2327+ __le32 _rsv:2;
2328+ __le32 invalid_prof:1;
2329+ __le32 rmsd:3;
2330+
2331+ __le32 col_id1:6, row_id1:10;
2332+ __le32 col_id2:6, row_id2:10;
2333+ __le32 col_id3:6, row_id3:10;
2334+ __le32 col_id4:6, row_id4:10;
2335+
2336+ __le32 ru_start_id:7;
2337+ __le32 _rsv1:1;
2338+ __le32 ru_end_id:7;
2339+ __le32 _rsv2:1;
2340+ __le32 mob_cal_en:1;
2341+ __le32 _rsv3:15;
2342+
2343+ __le32 snr_sts0:8, snr_sts1:8, snr_sts2:8, snr_sts3:8;
2344+ __le32 snr_sts4:8, snr_sts5:8, snr_sts6:8, snr_sts7:8;
2345+
2346+ __le32 _rsv4;
2347+} __packed;
2348+
2349+struct mt7915_tm_pfmu_tag2 {
2350+ __le32 smart_ant:24;
2351+ __le32 se_idx:5;
2352+ __le32 _rsv:3;
2353+
2354+ __le32 _rsv1:8;
2355+ __le32 rmsd_thres:3;
2356+ __le32 _rsv2:5;
2357+ __le32 ibf_timeout:8;
2358+ __le32 _rsv3:8;
2359+
2360+ __le32 _rsv4:16;
2361+ __le32 ibf_data_bw:2;
2362+ __le32 ibf_nc:3;
2363+ __le32 ibf_nr:3;
2364+ __le32 ibf_ru:8;
2365+
2366+ __le32 mob_delta_t:8;
2367+ __le32 mob_lq_result:7;
2368+ __le32 _rsv5:1;
2369+ __le32 _rsv6:16;
2370+
2371+ __le32 _rsv7;
2372+} __packed;
2373+
2374+struct mt7915_tm_pfmu_tag {
2375+ struct mt7915_tm_pfmu_tag1 t1;
2376+ struct mt7915_tm_pfmu_tag2 t2;
2377+};
2378+
2379+struct mt7915_tm_pfmu_data {
2380+ __le16 subc_idx;
2381+ __le16 phi11;
2382+ __le16 phi21;
2383+ __le16 phi31;
2384+};
2385+
2386+struct mt7915_tm_ibf_cal_info {
2387+ u8 format_id;
2388+ u8 group_l_m_n;
2389+ u8 group;
2390+ bool sx2;
2391+ u8 status;
2392+ u8 cal_type;
2393+ u8 _rsv[2];
2394+ u8 buf[1000];
2395+} __packed;
2396+
2397+enum {
2398+ IBF_PHASE_CAL_UNSPEC,
2399+ IBF_PHASE_CAL_NORMAL,
2400+ IBF_PHASE_CAL_VERIFY,
2401+ IBF_PHASE_CAL_NORMAL_INSTRUMENT,
2402+ IBF_PHASE_CAL_VERIFY_INSTRUMENT,
2403+};
2404+
2405 #endif
2406diff --git a/testmode.c b/testmode.c
developere35b8e42023-10-16 11:04:00 +08002407index 1b37392..b39fef4 100644
developer42b63282022-06-16 13:33:13 +08002408--- a/testmode.c
2409+++ b/testmode.c
developere35b8e42023-10-16 11:04:00 +08002410@@ -8,6 +8,7 @@ const struct nla_policy mt76_tm_policy[NUM_MT76_TM_ATTRS] = {
2411 [MT76_TM_ATTR_RESET] = { .type = NLA_FLAG },
2412 [MT76_TM_ATTR_STATE] = { .type = NLA_U8 },
2413 [MT76_TM_ATTR_TX_COUNT] = { .type = NLA_U32 },
2414+ [MT76_TM_ATTR_SKU_EN] = { .type = NLA_U8 },
2415 [MT76_TM_ATTR_TX_LENGTH] = { .type = NLA_U32 },
2416 [MT76_TM_ATTR_TX_RATE_MODE] = { .type = NLA_U8 },
2417 [MT76_TM_ATTR_TX_RATE_NSS] = { .type = NLA_U8 },
2418@@ -28,28 +29,16 @@ const struct nla_policy mt76_tm_policy[NUM_MT76_TM_ATTRS] = {
developer42b63282022-06-16 13:33:13 +08002419 };
2420 EXPORT_SYMBOL_GPL(mt76_tm_policy);
2421
2422-void mt76_testmode_tx_pending(struct mt76_phy *phy)
2423+static void
2424+mt76_testmode_queue_tx(struct mt76_phy *phy, struct mt76_wcid *wcid,
developer3262bf82022-07-12 11:37:54 +08002425+ struct sk_buff *skb, struct mt76_queue *q, int qid,
2426+ u16 limit)
developer42b63282022-06-16 13:33:13 +08002427 {
2428 struct mt76_testmode_data *td = &phy->test;
2429 struct mt76_dev *dev = phy->dev;
2430- struct mt76_wcid *wcid = &dev->global_wcid;
2431- struct sk_buff *skb = td->tx_skb;
2432- struct mt76_queue *q;
2433- u16 tx_queued_limit;
2434- int qid;
2435-
2436- if (!skb || !td->tx_pending)
2437- return;
2438+ u16 count = limit;
2439
2440- qid = skb_get_queue_mapping(skb);
2441- q = phy->q_tx[qid];
2442-
2443- tx_queued_limit = td->tx_queued_limit ? td->tx_queued_limit : 1000;
2444-
2445- spin_lock_bh(&q->lock);
2446-
2447- while (td->tx_pending > 0 &&
2448- td->tx_queued - td->tx_done < tx_queued_limit &&
2449+ while (td->tx_pending > 0 && count &&
2450 q->queued < q->ndesc / 2) {
2451 int ret;
2452
developere35b8e42023-10-16 11:04:00 +08002453@@ -58,13 +47,68 @@ void mt76_testmode_tx_pending(struct mt76_phy *phy)
developer42b63282022-06-16 13:33:13 +08002454 if (ret < 0)
2455 break;
2456
developer51e40422023-03-21 17:28:34 +08002457- td->tx_pending--;
developer42b63282022-06-16 13:33:13 +08002458+ count--;
developer51e40422023-03-21 17:28:34 +08002459+
2460+ /* tx_count == UINT_MAX for continuous tx */
2461+ if (td->tx_count != UINT_MAX)
2462+ td->tx_pending--;
developer42b63282022-06-16 13:33:13 +08002463 td->tx_queued++;
2464+
2465+ if (td->tx_rate_mode != MT76_TM_TX_MODE_HE_MU)
developer281084d2023-06-19 12:03:50 +08002466+ if (td->tx_queued - td->tx_done >= limit)
2467+ break;
developer42b63282022-06-16 13:33:13 +08002468 }
2469
2470 dev->queue_ops->kick(dev, q);
2471+}
2472+
2473+void mt76_testmode_tx_pending(struct mt76_phy *phy)
2474+{
2475+ struct mt76_testmode_data *td = &phy->test;
2476+ struct mt76_testmode_entry_data *ed;
2477+ struct mt76_queue *q;
2478+ int qid;
2479+ u16 tx_queued_limit;
2480+ u32 remain;
2481+ bool is_mu;
2482+
2483+ if (!td->tx_pending)
2484+ return;
2485+
2486+ /* tx_queued_limit = td->tx_queued_limit ?: 100; */
2487+ tx_queued_limit = 100;
2488+
2489+ if (!td->aid) {
2490+ qid = skb_get_queue_mapping(td->tx_skb);
2491+ q = phy->q_tx[qid];
2492+ spin_lock_bh(&q->lock);
2493+ mt76_testmode_queue_tx(phy, &phy->dev->global_wcid,
developer281084d2023-06-19 12:03:50 +08002494+ td->tx_skb, q, qid, tx_queued_limit);
developer42b63282022-06-16 13:33:13 +08002495+ spin_unlock_bh(&q->lock);
2496+
2497+ return;
2498+ }
2499+
2500+ is_mu = td->tx_rate_mode == MT76_TM_TX_MODE_HE_MU;
2501+ ed = mt76_testmode_entry_data(phy, td->cur_entry);
2502+ qid = skb_get_queue_mapping(ed->tx_skb);
2503+ q = phy->q_tx[qid];
2504+
2505+ spin_lock_bh(&q->lock);
2506+
2507+ remain = is_mu ? 1 : (td->tx_pending % td->tx_count) ?: td->tx_count;
2508+ if (remain < tx_queued_limit)
2509+ tx_queued_limit = remain;
2510+
developer3262bf82022-07-12 11:37:54 +08002511+ mt76_testmode_queue_tx(phy, td->cur_entry, ed->tx_skb, q, qid, tx_queued_limit);
developer42b63282022-06-16 13:33:13 +08002512+
developer281084d2023-06-19 12:03:50 +08002513+ if ((td->tx_count != UINT_MAX && td->tx_pending % td->tx_count == 0) || is_mu)
developer42b63282022-06-16 13:33:13 +08002514+ td->cur_entry = list_next_entry(td->cur_entry, list);
2515
2516 spin_unlock_bh(&q->lock);
2517+
2518+ if (is_mu && td->tx_pending)
2519+ mt76_worker_schedule(&phy->dev->tx_worker);
2520 }
2521
2522 static u32
developere35b8e42023-10-16 11:04:00 +08002523@@ -90,15 +134,31 @@ mt76_testmode_max_mpdu_len(struct mt76_phy *phy, u8 tx_rate_mode)
developer42b63282022-06-16 13:33:13 +08002524 }
2525
2526 static void
2527-mt76_testmode_free_skb(struct mt76_phy *phy)
2528+mt76_testmode_free_skb(struct sk_buff **tx_skb)
2529+{
2530+ if (!(*tx_skb))
2531+ return;
2532+
2533+ dev_kfree_skb(*tx_skb);
2534+ *tx_skb = NULL;
2535+}
2536+
2537+static void
2538+mt76_testmode_free_skb_all(struct mt76_phy *phy)
2539 {
2540 struct mt76_testmode_data *td = &phy->test;
2541+ struct mt76_testmode_entry_data *ed = &td->ed;
2542+ struct mt76_wcid *wcid;
2543+
2544+ mt76_testmode_free_skb(&ed->tx_skb);
2545
2546- dev_kfree_skb(td->tx_skb);
2547- td->tx_skb = NULL;
2548+ mt76_tm_for_each_entry(phy, wcid, ed)
2549+ mt76_testmode_free_skb(&ed->tx_skb);
2550 }
2551
2552-int mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len)
2553+static int
2554+mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len,
2555+ struct sk_buff **tx_skb, u8 (*addr)[ETH_ALEN])
2556 {
2557 #define MT_TXP_MAX_LEN 4095
2558 u16 fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA |
developere35b8e42023-10-16 11:04:00 +08002559@@ -119,7 +179,8 @@ int mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len)
developer42b63282022-06-16 13:33:13 +08002560 nfrags = len / MT_TXP_MAX_LEN;
2561 head_len = nfrags ? MT_TXP_MAX_LEN : len;
2562
2563- if (len > IEEE80211_MAX_FRAME_LEN)
2564+ if (len > IEEE80211_MAX_FRAME_LEN ||
2565+ td->tx_rate_mode == MT76_TM_TX_MODE_HE_MU)
2566 fc |= IEEE80211_STYPE_QOS_DATA;
2567
2568 head = alloc_skb(head_len, GFP_KERNEL);
developere35b8e42023-10-16 11:04:00 +08002569@@ -128,9 +189,9 @@ int mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len)
developer42b63282022-06-16 13:33:13 +08002570
developerd4975692022-07-15 18:30:03 +08002571 hdr = __skb_put_zero(head, sizeof(*hdr));
developer42b63282022-06-16 13:33:13 +08002572 hdr->frame_control = cpu_to_le16(fc);
2573- memcpy(hdr->addr1, td->addr[0], ETH_ALEN);
2574- memcpy(hdr->addr2, td->addr[1], ETH_ALEN);
2575- memcpy(hdr->addr3, td->addr[2], ETH_ALEN);
2576+ memcpy(hdr->addr1, addr[0], ETH_ALEN);
2577+ memcpy(hdr->addr2, addr[1], ETH_ALEN);
2578+ memcpy(hdr->addr3, addr[2], ETH_ALEN);
2579 skb_set_queue_mapping(head, IEEE80211_AC_BE);
developerd4975692022-07-15 18:30:03 +08002580 get_random_bytes(__skb_put(head, head_len - sizeof(*hdr)),
2581 head_len - sizeof(*hdr));
developere35b8e42023-10-16 11:04:00 +08002582@@ -154,7 +215,7 @@ int mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len)
developer42b63282022-06-16 13:33:13 +08002583
2584 frag = alloc_skb(frag_len, GFP_KERNEL);
2585 if (!frag) {
2586- mt76_testmode_free_skb(phy);
2587+ mt76_testmode_free_skb(tx_skb);
2588 dev_kfree_skb(head);
2589 return -ENOMEM;
2590 }
developere35b8e42023-10-16 11:04:00 +08002591@@ -167,15 +228,14 @@ int mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len)
developer42b63282022-06-16 13:33:13 +08002592 frag_tail = &(*frag_tail)->next;
2593 }
2594
2595- mt76_testmode_free_skb(phy);
2596- td->tx_skb = head;
2597+ mt76_testmode_free_skb(tx_skb);
2598+ *tx_skb = head;
2599
2600 return 0;
2601 }
2602-EXPORT_SYMBOL(mt76_testmode_alloc_skb);
2603
2604-static int
2605-mt76_testmode_tx_init(struct mt76_phy *phy)
2606+int mt76_testmode_init_skb(struct mt76_phy *phy, u32 len,
2607+ struct sk_buff **tx_skb, u8 (*addr)[ETH_ALEN])
2608 {
2609 struct mt76_testmode_data *td = &phy->test;
2610 struct ieee80211_tx_info *info;
developere35b8e42023-10-16 11:04:00 +08002611@@ -183,7 +243,7 @@ mt76_testmode_tx_init(struct mt76_phy *phy)
developer42b63282022-06-16 13:33:13 +08002612 u8 max_nss = hweight8(phy->antenna_mask);
2613 int ret;
2614
2615- ret = mt76_testmode_alloc_skb(phy, td->tx_mpdu_len);
2616+ ret = mt76_testmode_alloc_skb(phy, len, tx_skb, addr);
2617 if (ret)
2618 return ret;
2619
developere35b8e42023-10-16 11:04:00 +08002620@@ -193,7 +253,7 @@ mt76_testmode_tx_init(struct mt76_phy *phy)
developer42b63282022-06-16 13:33:13 +08002621 if (td->tx_antenna_mask)
2622 max_nss = min_t(u8, max_nss, hweight8(td->tx_antenna_mask));
2623
2624- info = IEEE80211_SKB_CB(td->tx_skb);
2625+ info = IEEE80211_SKB_CB(*tx_skb);
2626 rate = &info->control.rates[0];
2627 rate->count = 1;
2628 rate->idx = td->tx_rate_idx;
developere35b8e42023-10-16 11:04:00 +08002629@@ -265,6 +325,25 @@ mt76_testmode_tx_init(struct mt76_phy *phy)
developer42b63282022-06-16 13:33:13 +08002630 out:
2631 return 0;
2632 }
2633+EXPORT_SYMBOL(mt76_testmode_init_skb);
2634+
2635+static int
2636+mt76_testmode_tx_init(struct mt76_phy *phy)
2637+{
2638+ struct mt76_testmode_entry_data *ed;
2639+ struct mt76_wcid *wcid;
2640+
2641+ mt76_tm_for_each_entry(phy, wcid, ed) {
2642+ int ret;
2643+
2644+ ret = mt76_testmode_init_skb(phy, ed->tx_mpdu_len,
2645+ &ed->tx_skb, ed->addr);
2646+ if (ret)
2647+ return ret;
2648+ }
2649+
2650+ return 0;
2651+}
2652
2653 static void
2654 mt76_testmode_tx_start(struct mt76_phy *phy)
developere35b8e42023-10-16 11:04:00 +08002655@@ -275,6 +354,14 @@ mt76_testmode_tx_start(struct mt76_phy *phy)
developer42b63282022-06-16 13:33:13 +08002656 td->tx_queued = 0;
2657 td->tx_done = 0;
2658 td->tx_pending = td->tx_count;
2659+ if (td->tx_rate_mode == MT76_TM_TX_MODE_HE_MU)
2660+ td->tx_pending = 1;
2661+ if (td->entry_num) {
2662+ td->tx_pending *= td->entry_num;
2663+ td->cur_entry = list_first_entry(&td->tm_entry_list,
2664+ struct mt76_wcid, list);
2665+ }
2666+
2667 mt76_worker_schedule(&dev->tx_worker);
2668 }
2669
developere35b8e42023-10-16 11:04:00 +08002670@@ -293,7 +380,7 @@ mt76_testmode_tx_stop(struct mt76_phy *phy)
developer42b63282022-06-16 13:33:13 +08002671 wait_event_timeout(dev->tx_wait, td->tx_done == td->tx_queued,
2672 MT76_TM_TIMEOUT * HZ);
2673
2674- mt76_testmode_free_skb(phy);
2675+ mt76_testmode_free_skb_all(phy);
2676 }
2677
2678 static inline void
developere35b8e42023-10-16 11:04:00 +08002679@@ -324,6 +411,8 @@ mt76_testmode_init_defaults(struct mt76_phy *phy)
developer42b63282022-06-16 13:33:13 +08002680 memcpy(td->addr[0], phy->macaddr, ETH_ALEN);
2681 memcpy(td->addr[1], phy->macaddr, ETH_ALEN);
2682 memcpy(td->addr[2], phy->macaddr, ETH_ALEN);
2683+
2684+ INIT_LIST_HEAD(&phy->test.tm_entry_list);
2685 }
2686
2687 static int
developere35b8e42023-10-16 11:04:00 +08002688@@ -333,8 +422,12 @@ __mt76_testmode_set_state(struct mt76_phy *phy, enum mt76_testmode_state state)
developer42b63282022-06-16 13:33:13 +08002689 struct mt76_dev *dev = phy->dev;
2690 int err;
2691
2692- if (prev_state == MT76_TM_STATE_TX_FRAMES)
2693+ if (prev_state == MT76_TM_STATE_TX_FRAMES) {
2694+ /* MU needs to clean hwq for free done event */
2695+ if (phy->test.tx_rate_mode == MT76_TM_TX_MODE_HE_MU)
2696+ dev->test_ops->set_state(phy, MT76_TM_STATE_IDLE);
2697 mt76_testmode_tx_stop(phy);
2698+ }
2699
2700 if (state == MT76_TM_STATE_TX_FRAMES) {
2701 err = mt76_testmode_tx_init(phy);
developere35b8e42023-10-16 11:04:00 +08002702@@ -404,6 +497,44 @@ mt76_tm_get_u8(struct nlattr *attr, u8 *dest, u8 min, u8 max)
developer42b63282022-06-16 13:33:13 +08002703 return 0;
2704 }
2705
2706+static int
2707+mt76_testmode_set_eeprom(struct mt76_phy *phy, struct nlattr **tb)
2708+{
2709+ struct mt76_dev *dev = phy->dev;
2710+ u8 action, val[MT76_TM_EEPROM_BLOCK_SIZE];
2711+ u32 offset = 0;
2712+ int err = -EINVAL;
2713+
2714+ if (!dev->test_ops->set_eeprom)
2715+ return -EOPNOTSUPP;
2716+
2717+ if (mt76_tm_get_u8(tb[MT76_TM_ATTR_EEPROM_ACTION], &action,
2718+ 0, MT76_TM_EEPROM_ACTION_MAX))
2719+ goto out;
2720+
2721+ if (tb[MT76_TM_ATTR_EEPROM_OFFSET]) {
2722+ struct nlattr *cur;
2723+ int rem, idx = 0;
2724+
2725+ offset = nla_get_u32(tb[MT76_TM_ATTR_EEPROM_OFFSET]);
2726+ if (!!(offset % MT76_TM_EEPROM_BLOCK_SIZE) ||
2727+ !tb[MT76_TM_ATTR_EEPROM_VAL])
2728+ goto out;
2729+
2730+ nla_for_each_nested(cur, tb[MT76_TM_ATTR_EEPROM_VAL], rem) {
2731+ if (nla_len(cur) != 1 || idx >= ARRAY_SIZE(val))
2732+ goto out;
2733+
2734+ val[idx++] = nla_get_u8(cur);
2735+ }
2736+ }
2737+
2738+ err = dev->test_ops->set_eeprom(phy, offset, val, action);
2739+
2740+out:
2741+ return err;
2742+}
2743+
2744 int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2745 void *data, int len)
2746 {
developere35b8e42023-10-16 11:04:00 +08002747@@ -427,6 +558,11 @@ int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
developer42b63282022-06-16 13:33:13 +08002748
2749 mutex_lock(&dev->mutex);
2750
2751+ if (tb[MT76_TM_ATTR_EEPROM_ACTION]) {
2752+ err = mt76_testmode_set_eeprom(phy, tb);
2753+ goto out;
2754+ }
2755+
2756 if (tb[MT76_TM_ATTR_RESET]) {
2757 mt76_testmode_set_state(phy, MT76_TM_STATE_OFF);
2758 memset(td, 0, sizeof(*td));
developere35b8e42023-10-16 11:04:00 +08002759@@ -434,6 +570,9 @@ int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2760
2761 mt76_testmode_init_defaults(phy);
2762
2763+ if (tb[MT76_TM_ATTR_SKU_EN])
2764+ td->sku_en = nla_get_u8(tb[MT76_TM_ATTR_SKU_EN]);
2765+
2766 if (tb[MT76_TM_ATTR_TX_COUNT])
2767 td->tx_count = nla_get_u32(tb[MT76_TM_ATTR_TX_COUNT]);
2768
2769@@ -453,7 +592,10 @@ int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
developer42b63282022-06-16 13:33:13 +08002770 mt76_tm_get_u8(tb[MT76_TM_ATTR_TX_DUTY_CYCLE],
2771 &td->tx_duty_cycle, 0, 99) ||
2772 mt76_tm_get_u8(tb[MT76_TM_ATTR_TX_POWER_CONTROL],
2773- &td->tx_power_control, 0, 1))
2774+ &td->tx_power_control, 0, 1) ||
2775+ mt76_tm_get_u8(tb[MT76_TM_ATTR_AID], &td->aid, 0, 16) ||
2776+ mt76_tm_get_u8(tb[MT76_TM_ATTR_RU_ALLOC], &td->ru_alloc, 0, 0xff) ||
2777+ mt76_tm_get_u8(tb[MT76_TM_ATTR_RU_IDX], &td->ru_idx, 0, 68))
2778 goto out;
2779
2780 if (tb[MT76_TM_ATTR_TX_LENGTH]) {
developere35b8e42023-10-16 11:04:00 +08002781@@ -485,8 +627,7 @@ int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
developer42b63282022-06-16 13:33:13 +08002782
2783 if (tb[MT76_TM_ATTR_TX_POWER]) {
2784 struct nlattr *cur;
2785- int idx = 0;
2786- int rem;
2787+ int rem, idx = 0;
2788
2789 nla_for_each_nested(cur, tb[MT76_TM_ATTR_TX_POWER], rem) {
2790 if (nla_len(cur) != 1 ||
developere35b8e42023-10-16 11:04:00 +08002791@@ -506,11 +647,45 @@ int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
developer42b63282022-06-16 13:33:13 +08002792 if (nla_len(cur) != ETH_ALEN || idx >= 3)
2793 goto out;
2794
2795- memcpy(td->addr[idx], nla_data(cur), ETH_ALEN);
2796+ memcpy(td->addr[idx++], nla_data(cur), ETH_ALEN);
2797+ }
2798+ }
2799+
2800+ if (tb[MT76_TM_ATTR_CFG]) {
2801+ struct nlattr *cur;
2802+ int rem, idx = 0;
2803+
2804+ nla_for_each_nested(cur, tb[MT76_TM_ATTR_CFG], rem) {
2805+ if (nla_len(cur) != 1 || idx >= 2)
2806+ goto out;
2807+
2808+ if (idx == 0)
2809+ td->cfg.type = nla_get_u8(cur);
2810+ else
2811+ td->cfg.enable = nla_get_u8(cur);
2812 idx++;
2813 }
2814 }
2815
2816+ if (tb[MT76_TM_ATTR_TXBF_ACT]) {
2817+ struct nlattr *cur;
2818+ int rem, idx = 0;
2819+
2820+ if (!tb[MT76_TM_ATTR_TXBF_PARAM] ||
2821+ mt76_tm_get_u8(tb[MT76_TM_ATTR_TXBF_ACT], &td->txbf_act,
developer281084d2023-06-19 12:03:50 +08002822+ 0, MT76_TM_TXBF_ACT_MAX))
developer42b63282022-06-16 13:33:13 +08002823+ goto out;
2824+
2825+ memset(td->txbf_param, 0, sizeof(td->txbf_param));
2826+ nla_for_each_nested(cur, tb[MT76_TM_ATTR_TXBF_PARAM], rem) {
2827+ if (nla_len(cur) != 2 ||
2828+ idx >= ARRAY_SIZE(td->txbf_param))
2829+ goto out;
2830+
2831+ td->txbf_param[idx++] = nla_get_u16(cur);
2832+ }
2833+ }
2834+
2835 if (dev->test_ops->set_params) {
2836 err = dev->test_ops->set_params(phy, tb, state);
2837 if (err)
developere35b8e42023-10-16 11:04:00 +08002838@@ -575,6 +750,7 @@ int mt76_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *msg,
developer42b63282022-06-16 13:33:13 +08002839 struct mt76_phy *phy = hw->priv;
2840 struct mt76_dev *dev = phy->dev;
2841 struct mt76_testmode_data *td = &phy->test;
2842+ struct mt76_testmode_entry_data *ed = &td->ed;
2843 struct nlattr *tb[NUM_MT76_TM_ATTRS] = {};
2844 int err = 0;
2845 void *a;
developere35b8e42023-10-16 11:04:00 +08002846@@ -607,6 +783,19 @@ int mt76_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *msg,
developer42b63282022-06-16 13:33:13 +08002847 goto out;
2848 }
2849
2850+ if (tb[MT76_TM_ATTR_AID]) {
2851+ struct mt76_wcid *wcid;
2852+ u8 aid;
2853+
2854+ err = mt76_tm_get_u8(tb[MT76_TM_ATTR_AID], &aid, 1, 16);
2855+ if (err)
2856+ goto out;
2857+
2858+ mt76_tm_for_each_entry(phy, wcid, ed)
2859+ if (ed->aid == aid)
2860+ ed = mt76_testmode_entry_data(phy, wcid);
2861+ }
2862+
2863 mt76_testmode_init_defaults(phy);
2864
2865 err = -EMSGSIZE;
developere35b8e42023-10-16 11:04:00 +08002866@@ -619,12 +808,9 @@ int mt76_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *msg,
developer42b63282022-06-16 13:33:13 +08002867 goto out;
2868
2869 if (nla_put_u32(msg, MT76_TM_ATTR_TX_COUNT, td->tx_count) ||
2870- nla_put_u32(msg, MT76_TM_ATTR_TX_LENGTH, td->tx_mpdu_len) ||
developere35b8e42023-10-16 11:04:00 +08002871+ nla_put_u8(msg, MT76_TM_ATTR_SKU_EN, td->sku_en) ||
developer42b63282022-06-16 13:33:13 +08002872 nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_MODE, td->tx_rate_mode) ||
2873- nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_NSS, td->tx_rate_nss) ||
2874- nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_IDX, td->tx_rate_idx) ||
2875 nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_SGI, td->tx_rate_sgi) ||
2876- nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_LDPC, td->tx_rate_ldpc) ||
2877 nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_STBC, td->tx_rate_stbc) ||
2878 (mt76_testmode_param_present(td, MT76_TM_ATTR_TX_LTF) &&
2879 nla_put_u8(msg, MT76_TM_ATTR_TX_LTF, td->tx_ltf)) ||
developere35b8e42023-10-16 11:04:00 +08002880@@ -641,7 +827,16 @@ int mt76_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *msg,
developer281084d2023-06-19 12:03:50 +08002881 (mt76_testmode_param_present(td, MT76_TM_ATTR_TX_POWER_CONTROL) &&
2882 nla_put_u8(msg, MT76_TM_ATTR_TX_POWER_CONTROL, td->tx_power_control)) ||
2883 (mt76_testmode_param_present(td, MT76_TM_ATTR_FREQ_OFFSET) &&
2884- nla_put_u8(msg, MT76_TM_ATTR_FREQ_OFFSET, td->freq_offset)))
2885+ nla_put_u32(msg, MT76_TM_ATTR_FREQ_OFFSET, td->freq_offset)))
2886+ goto out;
2887+
developer42b63282022-06-16 13:33:13 +08002888+ if (nla_put_u32(msg, MT76_TM_ATTR_TX_LENGTH, ed->tx_mpdu_len) ||
2889+ nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_NSS, ed->tx_rate_nss) ||
2890+ nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_IDX, ed->tx_rate_idx) ||
2891+ nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_LDPC, ed->tx_rate_ldpc) ||
2892+ nla_put_u8(msg, MT76_TM_ATTR_AID, ed->aid) ||
2893+ nla_put_u8(msg, MT76_TM_ATTR_RU_ALLOC, ed->ru_alloc) ||
2894+ nla_put_u8(msg, MT76_TM_ATTR_RU_IDX, ed->ru_idx))
developer281084d2023-06-19 12:03:50 +08002895 goto out;
2896
developer42b63282022-06-16 13:33:13 +08002897 if (mt76_testmode_param_present(td, MT76_TM_ATTR_TX_POWER)) {
developer42b63282022-06-16 13:33:13 +08002898diff --git a/testmode.h b/testmode.h
developere35b8e42023-10-16 11:04:00 +08002899index 8961326..7a68625 100644
developer42b63282022-06-16 13:33:13 +08002900--- a/testmode.h
2901+++ b/testmode.h
2902@@ -6,6 +6,8 @@
2903 #define __MT76_TESTMODE_H
2904
2905 #define MT76_TM_TIMEOUT 10
2906+#define MT76_TM_MAX_ENTRY_NUM 16
2907+#define MT76_TM_EEPROM_BLOCK_SIZE 16
2908
2909 /**
2910 * enum mt76_testmode_attr - testmode attributes inside NL80211_ATTR_TESTDATA
developere35b8e42023-10-16 11:04:00 +08002911@@ -18,6 +20,7 @@
2912 * @MT76_TM_ATTR_MTD_PART: mtd partition used for eeprom data (string)
2913 * @MT76_TM_ATTR_MTD_OFFSET: offset of eeprom data within the partition (u32)
2914 *
2915+ * @MT76_TM_ATTR_SKU_EN: config txpower sku is enabled or disabled in testmode (u8)
2916 * @MT76_TM_ATTR_TX_COUNT: configured number of frames to send when setting
2917 * state to MT76_TM_STATE_TX_FRAMES (u32)
2918 * @MT76_TM_ATTR_TX_PENDING: pending frames during MT76_TM_STATE_TX_FRAMES (u32)
2919@@ -47,6 +50,15 @@
developer42b63282022-06-16 13:33:13 +08002920 * @MT76_TM_ATTR_DRV_DATA: driver specific netlink attrs (nested)
2921 *
2922 * @MT76_TM_ATTR_MAC_ADDRS: array of nested MAC addresses (nested)
2923+ *
2924+ * @MT76_TM_ATTR_EEPROM_ACTION: eeprom setting actions
developer281084d2023-06-19 12:03:50 +08002925+ * (u8, see &enum mt76_testmode_eeprom_action)
developer42b63282022-06-16 13:33:13 +08002926+ * @MT76_TM_ATTR_EEPROM_OFFSET: offset of eeprom data block for writing (u32)
2927+ * @MT76_TM_ATTR_EEPROM_VAL: values for writing into a 16-byte data block
developer281084d2023-06-19 12:03:50 +08002928+ * (nested, u8 attrs)
developer42b63282022-06-16 13:33:13 +08002929+ *
2930+ * @MT76_TM_ATTR_CFG: config testmode rf feature (nested, see &mt76_testmode_cfg)
2931+ *
2932 */
2933 enum mt76_testmode_attr {
2934 MT76_TM_ATTR_UNSPEC,
developere35b8e42023-10-16 11:04:00 +08002935@@ -57,6 +69,7 @@ enum mt76_testmode_attr {
2936 MT76_TM_ATTR_MTD_PART,
2937 MT76_TM_ATTR_MTD_OFFSET,
2938
2939+ MT76_TM_ATTR_SKU_EN,
2940 MT76_TM_ATTR_TX_COUNT,
2941 MT76_TM_ATTR_TX_LENGTH,
2942 MT76_TM_ATTR_TX_RATE_MODE,
2943@@ -84,6 +97,17 @@ enum mt76_testmode_attr {
developer42b63282022-06-16 13:33:13 +08002944 MT76_TM_ATTR_DRV_DATA,
2945
2946 MT76_TM_ATTR_MAC_ADDRS,
2947+ MT76_TM_ATTR_AID,
2948+ MT76_TM_ATTR_RU_ALLOC,
2949+ MT76_TM_ATTR_RU_IDX,
2950+
2951+ MT76_TM_ATTR_EEPROM_ACTION,
2952+ MT76_TM_ATTR_EEPROM_OFFSET,
2953+ MT76_TM_ATTR_EEPROM_VAL,
2954+
2955+ MT76_TM_ATTR_CFG,
2956+ MT76_TM_ATTR_TXBF_ACT,
2957+ MT76_TM_ATTR_TXBF_PARAM,
2958
2959 /* keep last */
2960 NUM_MT76_TM_ATTRS,
developere35b8e42023-10-16 11:04:00 +08002961@@ -128,6 +152,7 @@ enum mt76_testmode_stats_attr {
2962 *
2963 * @MT76_TM_RX_ATTR_FREQ_OFFSET: frequency offset (s32)
2964 * @MT76_TM_RX_ATTR_RCPI: received channel power indicator (array, u8)
2965+ * @MT76_TM_RX_ATTR_RSSI: received signal strength indicator (array, s8)
2966 * @MT76_TM_RX_ATTR_IB_RSSI: internal inband RSSI (array, s8)
2967 * @MT76_TM_RX_ATTR_WB_RSSI: internal wideband RSSI (array, s8)
2968 * @MT76_TM_RX_ATTR_SNR: signal-to-noise ratio (u8)
2969@@ -137,6 +162,7 @@ enum mt76_testmode_rx_attr {
2970
2971 MT76_TM_RX_ATTR_FREQ_OFFSET,
2972 MT76_TM_RX_ATTR_RCPI,
2973+ MT76_TM_RX_ATTR_RSSI,
2974 MT76_TM_RX_ATTR_IB_RSSI,
2975 MT76_TM_RX_ATTR_WB_RSSI,
2976 MT76_TM_RX_ATTR_SNR,
2977@@ -198,4 +224,57 @@ enum mt76_testmode_tx_mode {
developer42b63282022-06-16 13:33:13 +08002978
2979 extern const struct nla_policy mt76_tm_policy[NUM_MT76_TM_ATTRS];
2980
2981+/**
2982+ * enum mt76_testmode_eeprom_action - eeprom setting actions
2983+ *
2984+ * @MT76_TM_EEPROM_ACTION_UPDATE_DATA: update rf values to specific
developer281084d2023-06-19 12:03:50 +08002985+ * eeprom data block
developer42b63282022-06-16 13:33:13 +08002986+ * @MT76_TM_EEPROM_ACTION_UPDATE_BUFFER_MODE: send updated eeprom data to fw
2987+ * @MT76_TM_EEPROM_ACTION_WRITE_TO_EFUSE: write eeprom data back to efuse
2988+ */
2989+enum mt76_testmode_eeprom_action {
2990+ MT76_TM_EEPROM_ACTION_UPDATE_DATA,
2991+ MT76_TM_EEPROM_ACTION_UPDATE_BUFFER_MODE,
2992+ MT76_TM_EEPROM_ACTION_WRITE_TO_EFUSE,
2993+
2994+ /* keep last */
2995+ NUM_MT76_TM_EEPROM_ACTION,
2996+ MT76_TM_EEPROM_ACTION_MAX = NUM_MT76_TM_EEPROM_ACTION - 1,
2997+};
2998+
2999+/**
3000+ * enum mt76_testmode_cfg - packet tx phy mode
3001+ *
3002+ * @MT76_TM_EEPROM_ACTION_UPDATE_DATA: update rf values to specific
developer281084d2023-06-19 12:03:50 +08003003+ * eeprom data block
developer42b63282022-06-16 13:33:13 +08003004+ * @MT76_TM_EEPROM_ACTION_UPDATE_BUFFER_MODE: send updated eeprom data to fw
3005+ * @MT76_TM_EEPROM_ACTION_WRITE_TO_EFUSE: write eeprom data back to efuse
3006+ */
3007+enum mt76_testmode_cfg {
3008+ MT76_TM_CFG_TSSI,
3009+ MT76_TM_CFG_DPD,
3010+ MT76_TM_CFG_RATE_POWER_OFFSET,
3011+ MT76_TM_CFG_THERMAL_COMP,
3012+
3013+ /* keep last */
3014+ NUM_MT76_TM_CFG,
3015+ MT76_TM_CFG_MAX = NUM_MT76_TM_CFG - 1,
3016+};
3017+
3018+enum mt76_testmode_txbf_act {
3019+ MT76_TM_TXBF_ACT_INIT,
3020+ MT76_TM_TXBF_ACT_UPDATE_CH,
3021+ MT76_TM_TXBF_ACT_PHASE_COMP,
3022+ MT76_TM_TXBF_ACT_TX_PREP,
3023+ MT76_TM_TXBF_ACT_IBF_PROF_UPDATE,
3024+ MT76_TM_TXBF_ACT_EBF_PROF_UPDATE,
3025+ MT76_TM_TXBF_ACT_PHASE_CAL,
3026+ MT76_TM_TXBF_ACT_PROF_UPDATE_ALL,
3027+ MT76_TM_TXBF_ACT_E2P_UPDATE,
3028+
3029+ /* keep last */
3030+ NUM_MT76_TM_TXBF_ACT,
3031+ MT76_TM_TXBF_ACT_MAX = NUM_MT76_TM_TXBF_ACT - 1,
3032+};
3033+
3034 #endif
3035diff --git a/tools/fields.c b/tools/fields.c
developere35b8e42023-10-16 11:04:00 +08003036index e3f6908..406ba77 100644
developer42b63282022-06-16 13:33:13 +08003037--- a/tools/fields.c
3038+++ b/tools/fields.c
3039@@ -10,6 +10,7 @@ static const char * const testmode_state[] = {
3040 [MT76_TM_STATE_IDLE] = "idle",
3041 [MT76_TM_STATE_TX_FRAMES] = "tx_frames",
3042 [MT76_TM_STATE_RX_FRAMES] = "rx_frames",
3043+ [MT76_TM_STATE_TX_CONT] = "tx_cont",
3044 };
3045
3046 static const char * const testmode_tx_mode[] = {
developere35b8e42023-10-16 11:04:00 +08003047@@ -65,7 +66,7 @@ static bool parse_u8(const struct tm_field *field, int idx,
3048
3049 static void print_u8(const struct tm_field *field, struct nlattr *attr)
3050 {
3051- printf("%d", nla_get_u8(attr));
3052+ printf("%u", nla_get_u8(attr));
3053 }
3054
3055 static void print_s8(const struct tm_field *field, struct nlattr *attr)
developer51e40422023-03-21 17:28:34 +08003056@@ -86,12 +87,12 @@ static void print_s32(const struct tm_field *field, struct nlattr *attr)
3057
3058 static void print_u32(const struct tm_field *field, struct nlattr *attr)
3059 {
3060- printf("%d", nla_get_u32(attr));
3061+ printf("%u", nla_get_u32(attr));
3062 }
3063
3064 static void print_u64(const struct tm_field *field, struct nlattr *attr)
3065 {
3066- printf("%lld", (unsigned long long)nla_get_u64(attr));
3067+ printf("%llu", (unsigned long long)nla_get_u64(attr));
3068 }
3069
3070 static bool parse_flag(const struct tm_field *field, int idx,
developer42b63282022-06-16 13:33:13 +08003071@@ -201,6 +202,63 @@ static void print_extra_stats(const struct tm_field *field, struct nlattr **tb)
3072 printf("%srx_per=%.02f%%\n", prefix, 100 * failed / total);
3073 }
3074
3075+static bool parse_mac(const struct tm_field *field, int idx,
3076+ struct nl_msg *msg, const char *val)
3077+{
3078+#define ETH_ALEN 6
3079+ bool ret = true;
3080+ char *str, *cur, *ap;
3081+ void *a;
3082+
3083+ ap = str = strdup(val);
3084+
3085+ a = nla_nest_start(msg, idx);
3086+
3087+ idx = 0;
3088+ while ((cur = strsep(&ap, ",")) != NULL) {
3089+ unsigned char addr[ETH_ALEN];
3090+ char *val, *tmp = cur;
3091+ int i = 0;
3092+
3093+ while ((val = strsep(&tmp, ":")) != NULL) {
3094+ if (i >= ETH_ALEN)
3095+ break;
3096+
3097+ addr[i++] = strtoul(val, NULL, 16);
3098+ }
3099+
3100+ nla_put(msg, idx, ETH_ALEN, addr);
3101+
3102+ idx++;
3103+ }
3104+
3105+ nla_nest_end(msg, a);
3106+
3107+ free(str);
3108+
3109+ return ret;
3110+}
3111+
3112+static void print_mac(const struct tm_field *field, struct nlattr *attr)
3113+{
3114+#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
3115+#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
3116+ unsigned char addr[3][6];
3117+ struct nlattr *cur;
3118+ int idx = 0;
3119+ int rem;
3120+
3121+ nla_for_each_nested(cur, attr, rem) {
3122+ if (nla_len(cur) != 6)
3123+ continue;
3124+ memcpy(addr[idx++], nla_data(cur), 6);
3125+ }
3126+
3127+ printf("" MACSTR "," MACSTR "," MACSTR "",
3128+ MAC2STR(addr[0]), MAC2STR(addr[1]), MAC2STR(addr[2]));
3129+
3130+ return;
3131+}
3132
3133 #define FIELD_GENERIC(_field, _name, ...) \
3134 [FIELD_NAME(_field)] = { \
developere35b8e42023-10-16 11:04:00 +08003135@@ -250,10 +308,18 @@ static void print_extra_stats(const struct tm_field *field, struct nlattr **tb)
developer42b63282022-06-16 13:33:13 +08003136 ##__VA_ARGS__ \
3137 )
3138
3139+#define FIELD_MAC(_field, _name) \
3140+ [FIELD_NAME(_field)] = { \
3141+ .name = _name, \
3142+ .parse = parse_mac, \
3143+ .print = print_mac \
3144+ }
3145+
3146 #define FIELD_NAME(_field) MT76_TM_RX_ATTR_##_field
3147 static const struct tm_field rx_fields[NUM_MT76_TM_RX_ATTRS] = {
3148 FIELD_RO(s32, FREQ_OFFSET, "freq_offset"),
developere35b8e42023-10-16 11:04:00 +08003149 FIELD_ARRAY_RO(u8, RCPI, "rcpi"),
3150+ FIELD_ARRAY_RO(s8, RSSI, "rssi"),
3151 FIELD_ARRAY_RO(s8, IB_RSSI, "ib_rssi"),
3152 FIELD_ARRAY_RO(s8, WB_RSSI, "wb_rssi"),
3153 FIELD_RO(s8, SNR, "snr"),
3154@@ -261,6 +327,7 @@ static const struct tm_field rx_fields[NUM_MT76_TM_RX_ATTRS] = {
3155 static struct nla_policy rx_policy[NUM_MT76_TM_RX_ATTRS] = {
3156 [MT76_TM_RX_ATTR_FREQ_OFFSET] = { .type = NLA_U32 },
3157 [MT76_TM_RX_ATTR_RCPI] = { .type = NLA_NESTED },
3158+ [MT76_TM_RX_ATTR_RSSI] = { .type = NLA_NESTED },
3159 [MT76_TM_RX_ATTR_IB_RSSI] = { .type = NLA_NESTED },
3160 [MT76_TM_RX_ATTR_WB_RSSI] = { .type = NLA_NESTED },
3161 [MT76_TM_RX_ATTR_SNR] = { .type = NLA_U8 },
3162@@ -291,6 +358,7 @@ static const struct tm_field testdata_fields[NUM_MT76_TM_ATTRS] = {
3163 FIELD_ENUM(STATE, "state", testmode_state),
3164 FIELD_RO(string, MTD_PART, "mtd_part"),
3165 FIELD_RO(u32, MTD_OFFSET, "mtd_offset"),
3166+ FIELD(u8, SKU_EN, "sku_en"),
3167 FIELD(u32, TX_COUNT, "tx_count"),
3168 FIELD(u32, TX_LENGTH, "tx_length"),
3169 FIELD_ENUM(TX_RATE_MODE, "tx_rate_mode", testmode_tx_mode),
3170@@ -300,10 +368,18 @@ static const struct tm_field testdata_fields[NUM_MT76_TM_ATTRS] = {
developer42b63282022-06-16 13:33:13 +08003171 FIELD(u8, TX_RATE_LDPC, "tx_rate_ldpc"),
3172 FIELD(u8, TX_RATE_STBC, "tx_rate_stbc"),
3173 FIELD(u8, TX_LTF, "tx_ltf"),
3174+ FIELD(u8, TX_DUTY_CYCLE, "tx_duty_cycle"),
3175+ FIELD(u32, TX_IPG, "tx_ipg"),
3176+ FIELD(u32, TX_TIME, "tx_time"),
3177 FIELD(u8, TX_POWER_CONTROL, "tx_power_control"),
3178 FIELD_ARRAY(u8, TX_POWER, "tx_power"),
3179 FIELD(u8, TX_ANTENNA, "tx_antenna"),
3180+ FIELD(u8, TX_SPE_IDX, "tx_spe_idx"),
3181 FIELD(u32, FREQ_OFFSET, "freq_offset"),
3182+ FIELD(u8, AID, "aid"),
3183+ FIELD(u8, RU_ALLOC, "ru_alloc"),
3184+ FIELD(u8, RU_IDX, "ru_idx"),
3185+ FIELD_MAC(MAC_ADDRS, "mac_addrs"),
3186 FIELD_NESTED_RO(STATS, stats, "",
3187 .print_extra = print_extra_stats),
3188 };
developere35b8e42023-10-16 11:04:00 +08003189@@ -313,6 +389,7 @@ static struct nla_policy testdata_policy[NUM_MT76_TM_ATTRS] = {
3190 [MT76_TM_ATTR_STATE] = { .type = NLA_U8 },
3191 [MT76_TM_ATTR_MTD_PART] = { .type = NLA_STRING },
3192 [MT76_TM_ATTR_MTD_OFFSET] = { .type = NLA_U32 },
3193+ [MT76_TM_ATTR_SKU_EN] = { .type = NLA_U8 },
3194 [MT76_TM_ATTR_TX_COUNT] = { .type = NLA_U32 },
3195 [MT76_TM_ATTR_TX_LENGTH] = { .type = NLA_U32 },
3196 [MT76_TM_ATTR_TX_RATE_MODE] = { .type = NLA_U8 },
3197@@ -322,9 +399,16 @@ static struct nla_policy testdata_policy[NUM_MT76_TM_ATTRS] = {
developer42b63282022-06-16 13:33:13 +08003198 [MT76_TM_ATTR_TX_RATE_LDPC] = { .type = NLA_U8 },
3199 [MT76_TM_ATTR_TX_RATE_STBC] = { .type = NLA_U8 },
3200 [MT76_TM_ATTR_TX_LTF] = { .type = NLA_U8 },
3201+ [MT76_TM_ATTR_TX_DUTY_CYCLE] = { .type = NLA_U8 },
3202+ [MT76_TM_ATTR_TX_IPG] = { .type = NLA_U32 },
3203+ [MT76_TM_ATTR_TX_TIME] = { .type = NLA_U32 },
3204 [MT76_TM_ATTR_TX_POWER_CONTROL] = { .type = NLA_U8 },
3205 [MT76_TM_ATTR_TX_ANTENNA] = { .type = NLA_U8 },
3206+ [MT76_TM_ATTR_TX_SPE_IDX] = { .type = NLA_U8 },
3207 [MT76_TM_ATTR_FREQ_OFFSET] = { .type = NLA_U32 },
3208+ [MT76_TM_ATTR_AID] = { .type = NLA_U8 },
3209+ [MT76_TM_ATTR_RU_ALLOC] = { .type = NLA_U8 },
3210+ [MT76_TM_ATTR_RU_IDX] = { .type = NLA_U8 },
3211 [MT76_TM_ATTR_STATS] = { .type = NLA_NESTED },
3212 };
3213
3214diff --git a/tx.c b/tx.c
developere35b8e42023-10-16 11:04:00 +08003215index 1809b03..f1dd9f6 100644
developer42b63282022-06-16 13:33:13 +08003216--- a/tx.c
3217+++ b/tx.c
developer004e50c2023-06-29 20:33:22 +08003218@@ -259,8 +259,7 @@ void __mt76_tx_complete_skb(struct mt76_dev *dev, u16 wcid_idx, struct sk_buff *
developer42b63282022-06-16 13:33:13 +08003219 if (mt76_is_testmode_skb(dev, skb, &hw)) {
3220 struct mt76_phy *phy = hw->priv;
3221
3222- if (skb == phy->test.tx_skb)
3223- phy->test.tx_done++;
3224+ phy->test.tx_done++;
3225 if (phy->test.tx_queued == phy->test.tx_done)
3226 wake_up(&dev->tx_wait);
3227
3228--
developere35b8e42023-10-16 11:04:00 +080032292.18.0
developer42b63282022-06-16 13:33:13 +08003230