blob: 470e6e47c36617fba2d0554d008d4339487b24cd [file] [log] [blame]
developer05f3b2b2024-08-19 19:17:34 +08001From d2bc22b6da2b5bbc7d4c441a1a6b8c55c3fc7462 Mon Sep 17 00:00:00 2001
developer6caa5e22022-06-16 13:33:13 +08002From: Shayne Chen <shayne.chen@mediatek.com>
3Date: Thu, 21 Apr 2022 15:43:19 +0800
developer05f3b2b2024-08-19 19:17:34 +08004Subject: [PATCH 1008/1052] wifi: mt76: testmode: additional supports
developer6caa5e22022-06-16 13:33:13 +08005
6Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
developerbb6ddff2023-03-08 17:22:32 +08007Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
developer6caa5e22022-06-16 13:33:13 +08008---
developerf7a3ca32022-09-01 14:44:55 +08009 dma.c | 3 +-
10 mac80211.c | 12 +
developerdad89a32024-04-29 14:17:17 +080011 mt76.h | 119 ++++-
developerf7a3ca32022-09-01 14:44:55 +080012 mt76_connac_mcu.c | 4 +
13 mt76_connac_mcu.h | 2 +
developerc9333e12023-04-06 18:07:42 +080014 mt7915/eeprom.c | 2 +-
developerf7a3ca32022-09-01 14:44:55 +080015 mt7915/init.c | 2 +-
developerbd9fa1e2023-10-16 11:04:00 +080016 mt7915/mac.c | 40 +-
developerf7a3ca32022-09-01 14:44:55 +080017 mt7915/main.c | 2 +-
developer692ed9b2023-06-19 12:03:50 +080018 mt7915/mcu.c | 22 +-
developer1475cf22023-05-05 13:45:43 +080019 mt7915/mcu.h | 29 +-
developerf7a3ca32022-09-01 14:44:55 +080020 mt7915/mmio.c | 2 +
developerbd9fa1e2023-10-16 11:04:00 +080021 mt7915/mt7915.h | 17 +-
developerf7a3ca32022-09-01 14:44:55 +080022 mt7915/regs.h | 3 +
developer70180b02023-11-14 17:01:47 +080023 mt7915/testmode.c | 1244 ++++++++++++++++++++++++++++++++++++++++++---
developerbd9fa1e2023-10-16 11:04:00 +080024 mt7915/testmode.h | 278 ++++++++++
developer1a173672023-12-21 14:49:33 +080025 testmode.c | 289 +++++++++--
developerbd9fa1e2023-10-16 11:04:00 +080026 testmode.h | 79 +++
27 tools/fields.c | 90 +++-
developerf7a3ca32022-09-01 14:44:55 +080028 tx.c | 3 +-
developerdad89a32024-04-29 14:17:17 +080029 20 files changed, 2073 insertions(+), 169 deletions(-)
developer6caa5e22022-06-16 13:33:13 +080030
31diff --git a/dma.c b/dma.c
developer05f3b2b2024-08-19 19:17:34 +080032index ccdd5646..bc8afcff 100644
developer6caa5e22022-06-16 13:33:13 +080033--- a/dma.c
34+++ b/dma.c
developera46f6132024-03-26 14:09:54 +080035@@ -614,8 +614,7 @@ free:
developer6caa5e22022-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
developer05f3b2b2024-08-19 19:17:34 +080046index 9ebb2746..d6b70374 100644
developer6caa5e22022-06-16 13:33:13 +080047--- a/mac80211.c
48+++ b/mac80211.c
developer8effbd32023-04-17 15:57:28 +080049@@ -55,6 +55,13 @@ static const struct ieee80211_channel mt76_channels_5ghz[] = {
developer6caa5e22022-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),
developer47efbdb2023-06-29 20:33:22 +080063@@ -76,6 +83,11 @@ static const struct ieee80211_channel mt76_channels_5ghz[] = {
developer6caa5e22022-06-16 13:33:13 +080064 CHAN5G(169, 5845),
65 CHAN5G(173, 5865),
developer47efbdb2023-06-29 20:33:22 +080066 CHAN5G(177, 5885),
developer6caa5e22022-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
developer05f3b2b2024-08-19 19:17:34 +080076index 329e4d7a..62205051 100644
developer6caa5e22022-06-16 13:33:13 +080077--- a/mt76.h
78+++ b/mt76.h
developera46f6132024-03-26 14:09:54 +080079@@ -707,6 +707,21 @@ struct mt76_testmode_ops {
developer6caa5e22022-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)
developera46f6132024-03-26 14:09:54 +0800101@@ -715,16 +730,13 @@ struct mt76_testmode_data {
developer6caa5e22022-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;
developerbd9fa1e2023-10-16 11:04:00 +0800106+
107+ u8 sku_en;
developer6caa5e22022-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
developera46f6132024-03-26 14:09:54 +0800120@@ -740,10 +752,37 @@ struct mt76_testmode_data {
developer6caa5e22022-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;
developerdad89a32024-04-29 14:17:17 +0800159@@ -1348,6 +1387,68 @@ static inline bool mt76_testmode_enabled(struct mt76_phy *phy)
developer6caa5e22022-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+
developerdad89a32024-04-29 14:17:17 +0800175+static inline struct mt76_wcid *
176+mt76_testmode_next_entry(struct mt76_phy *phy, struct mt76_wcid *wcid)
177+{
178+ if (wcid == &phy->dev->global_wcid)
179+ return NULL;
180+
181+ return list_next_entry(wcid, list);
182+}
183+
developer6caa5e22022-06-16 13:33:13 +0800184+static inline struct mt76_testmode_entry_data *
185+mt76_testmode_entry_data(struct mt76_phy *phy, struct mt76_wcid *wcid)
186+{
187+ if (!wcid)
188+ return NULL;
189+ if (wcid == &phy->dev->global_wcid)
190+ return &phy->test.ed;
191+
192+ return (struct mt76_testmode_entry_data *)((u8 *)wcid +
193+ phy->hw->sta_data_size);
194+}
195+
developerdad89a32024-04-29 14:17:17 +0800196+#define mt76_tm_for_each_entry(phy, wcid, ed) \
197+ for (wcid = mt76_testmode_first_entry(phy), \
198+ ed = mt76_testmode_entry_data(phy, wcid); \
199+ ((phy->test.aid && \
developer6caa5e22022-06-16 13:33:13 +0800200+ !list_entry_is_head(wcid, &phy->test.tm_entry_list, list)) || \
201+ (!phy->test.aid && wcid == &phy->dev->global_wcid)) && ed; \
developerdad89a32024-04-29 14:17:17 +0800202+ wcid = mt76_testmode_next_entry(phy, wcid), \
developer6caa5e22022-06-16 13:33:13 +0800203+ ed = mt76_testmode_entry_data(phy, wcid))
204+#endif
205+
206+static inline bool __mt76_is_testmode_skb(struct mt76_phy *phy,
207+ struct sk_buff *skb)
208+{
209+#ifdef CONFIG_NL80211_TESTMODE
210+ struct mt76_testmode_entry_data *ed = &phy->test.ed;
211+ struct mt76_wcid *wcid;
212+
213+ if (skb == ed->tx_skb)
214+ return true;
215+
216+ mt76_tm_for_each_entry(phy, wcid, ed)
217+ if (skb == ed->tx_skb)
218+ return true;
219+ return false;
220+#else
221+ return false;
222+#endif
223+}
224+
225 static inline bool mt76_is_testmode_skb(struct mt76_dev *dev,
226 struct sk_buff *skb,
227 struct ieee80211_hw **hw)
developerdad89a32024-04-29 14:17:17 +0800228@@ -1358,7 +1459,8 @@ static inline bool mt76_is_testmode_skb(struct mt76_dev *dev,
developerf7a3ca32022-09-01 14:44:55 +0800229 for (i = 0; i < ARRAY_SIZE(dev->phys); i++) {
230 struct mt76_phy *phy = dev->phys[i];
231
232- if (phy && skb == phy->test.tx_skb) {
233+ if (phy && mt76_testmode_enabled(phy) &&
234+ __mt76_is_testmode_skb(phy, skb)) {
235 *hw = dev->phys[i]->hw;
236 return true;
237 }
developerdad89a32024-04-29 14:17:17 +0800238@@ -1460,7 +1562,8 @@ int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
developer6caa5e22022-06-16 13:33:13 +0800239 int mt76_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *skb,
240 struct netlink_callback *cb, void *data, int len);
241 int mt76_testmode_set_state(struct mt76_phy *phy, enum mt76_testmode_state state);
242-int mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len);
243+int mt76_testmode_init_skb(struct mt76_phy *phy, u32 len,
244+ struct sk_buff **tx_skb, u8 (*addr)[ETH_ALEN]);
245
246 static inline void mt76_testmode_reset(struct mt76_phy *phy, bool disable)
247 {
248diff --git a/mt76_connac_mcu.c b/mt76_connac_mcu.c
developer05f3b2b2024-08-19 19:17:34 +0800249index 4e84f8d2..2acd7efb 100644
developer6caa5e22022-06-16 13:33:13 +0800250--- a/mt76_connac_mcu.c
251+++ b/mt76_connac_mcu.c
developerdc9eeae2024-04-08 14:36:46 +0800252@@ -407,6 +407,7 @@ void mt76_connac_mcu_sta_basic_tlv(struct mt76_dev *dev, struct sk_buff *skb,
developer6caa5e22022-06-16 13:33:13 +0800253 switch (vif->type) {
254 case NL80211_IFTYPE_MESH_POINT:
255 case NL80211_IFTYPE_AP:
256+ case NL80211_IFTYPE_MONITOR:
developer7af0f762023-05-22 15:16:16 +0800257 if (vif->p2p && !is_mt7921(dev))
developer6caa5e22022-06-16 13:33:13 +0800258 conn_type = CONNECTION_P2P_GC;
259 else
developerdc9eeae2024-04-08 14:36:46 +0800260@@ -588,6 +589,9 @@ void mt76_connac_mcu_wtbl_generic_tlv(struct mt76_dev *dev,
developer6caa5e22022-06-16 13:33:13 +0800261 rx->rca2 = 1;
262 rx->rv = 1;
263
264+ if (vif->type == NL80211_IFTYPE_MONITOR)
265+ rx->rca1 = 0;
266+
267 if (!is_connac_v1(dev))
268 return;
269
270diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
developer05f3b2b2024-08-19 19:17:34 +0800271index f5edeef6..152b4aaa 100644
developer6caa5e22022-06-16 13:33:13 +0800272--- a/mt76_connac_mcu.h
273+++ b/mt76_connac_mcu.h
developer05f3b2b2024-08-19 19:17:34 +0800274@@ -1024,6 +1024,7 @@ enum {
developer6caa5e22022-06-16 13:33:13 +0800275 MCU_EXT_EVENT_FW_LOG_2_HOST = 0x13,
276 MCU_EXT_EVENT_THERMAL_PROTECT = 0x22,
277 MCU_EXT_EVENT_ASSERT_DUMP = 0x23,
278+ MCU_EXT_EVENT_BF_STATUS_READ = 0x35,
279 MCU_EXT_EVENT_RDD_REPORT = 0x3a,
280 MCU_EXT_EVENT_CSA_NOTIFY = 0x4f,
developer753619c2024-02-22 13:42:45 +0800281 MCU_EXT_EVENT_BSS_ACQ_PKT_CNT = 0x52,
developer05f3b2b2024-08-19 19:17:34 +0800282@@ -1248,6 +1249,7 @@ enum {
developer6caa5e22022-06-16 13:33:13 +0800283 MCU_EXT_CMD_PHY_STAT_INFO = 0xad,
284 /* for vendor csi and air monitor */
285 MCU_EXT_CMD_SMESH_CTRL = 0xae,
286+ MCU_EXT_CMD_RX_STAT_USER_CTRL = 0xb3,
developerdad89a32024-04-29 14:17:17 +0800287 MCU_EXT_CMD_SET_QOS_MAP = 0xb4,
developer6caa5e22022-06-16 13:33:13 +0800288 MCU_EXT_CMD_CERT_CFG = 0xb7,
289 MCU_EXT_CMD_CSI_CTRL = 0xc2,
developerc9333e12023-04-06 18:07:42 +0800290diff --git a/mt7915/eeprom.c b/mt7915/eeprom.c
developer05f3b2b2024-08-19 19:17:34 +0800291index bfdbc15a..f4876fe9 100644
developerc9333e12023-04-06 18:07:42 +0800292--- a/mt7915/eeprom.c
293+++ b/mt7915/eeprom.c
developera46f6132024-03-26 14:09:54 +0800294@@ -142,7 +142,7 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev)
developerc9333e12023-04-06 18:07:42 +0800295 /* read eeprom data from efuse */
296 block_num = DIV_ROUND_UP(eeprom_size, eeprom_blk_size);
297 for (i = 0; i < block_num; i++) {
298- ret = mt7915_mcu_get_eeprom(dev, i * eeprom_blk_size);
299+ ret = mt7915_mcu_get_eeprom(dev, i * eeprom_blk_size, NULL);
300 if (ret < 0)
301 return ret;
302 }
developer6caa5e22022-06-16 13:33:13 +0800303diff --git a/mt7915/init.c b/mt7915/init.c
developer05f3b2b2024-08-19 19:17:34 +0800304index 18c6ef7e..0c58ab7b 100644
developer6caa5e22022-06-16 13:33:13 +0800305--- a/mt7915/init.c
306+++ b/mt7915/init.c
developer05f3b2b2024-08-19 19:17:34 +0800307@@ -700,7 +700,7 @@ static void mt7915_init_work(struct work_struct *work)
developer6caa5e22022-06-16 13:33:13 +0800308 struct mt7915_dev *dev = container_of(work, struct mt7915_dev,
309 init_work);
310
311- mt7915_mcu_set_eeprom(dev);
312+ mt7915_mcu_set_eeprom(dev, dev->flash_mode);
313 mt7915_mac_init(dev);
developerc8796032023-08-09 10:28:15 +0800314 mt7915_txbf_init(dev);
315 }
developer6caa5e22022-06-16 13:33:13 +0800316diff --git a/mt7915/mac.c b/mt7915/mac.c
developer05f3b2b2024-08-19 19:17:34 +0800317index 4177d6a3..b05e1630 100644
developer6caa5e22022-06-16 13:33:13 +0800318--- a/mt7915/mac.c
319+++ b/mt7915/mac.c
developera46f6132024-03-26 14:09:54 +0800320@@ -586,6 +586,7 @@ mt7915_mac_fill_rx_vector(struct mt7915_dev *dev, struct sk_buff *skb)
developerbd9fa1e2023-10-16 11:04:00 +0800321 wb_rssi = le32_to_cpu(rxv[9]);
322
323 phy->test.last_rcpi[i] = rcpi & 0xff;
324+ phy->test.last_rssi[i] = to_rssi(GENMASK(7, 0), rcpi);
325 phy->test.last_ib_rssi[i] = ib_rssi & 0xff;
326 phy->test.last_wb_rssi[i] = wb_rssi & 0xff;
327 }
developera46f6132024-03-26 14:09:54 +0800328@@ -611,16 +612,38 @@ mt7915_mac_write_txwi_tm(struct mt7915_phy *phy, __le32 *txwi,
developer6caa5e22022-06-16 13:33:13 +0800329 {
330 #ifdef CONFIG_NL80211_TESTMODE
331 struct mt76_testmode_data *td = &phy->mt76->test;
332+ struct mt76_testmode_entry_data *ed;
333+ struct mt76_wcid *wcid;
334 const struct ieee80211_rate *r;
335- u8 bw, mode, nss = td->tx_rate_nss;
336- u8 rate_idx = td->tx_rate_idx;
337+ u8 bw, mode, nss, rate_idx, ldpc;
338 u16 rateval = 0;
339 u32 val;
340 bool cck = false;
341 int band;
342
343- if (skb != phy->mt76->test.tx_skb)
344+ txwi[3] &= ~cpu_to_le32(MT_TXD3_SN_VALID);
345+ txwi[7] |= cpu_to_le32(FIELD_PREP(MT_TXD7_SPE_IDX,
346+ phy->test.spe_idx));
347+
348+ if (td->tx_rate_mode == MT76_TM_TX_MODE_HE_MU) {
349+ txwi[1] |= cpu_to_le32(BIT(18));
350+ txwi[2] = 0;
351+ txwi[3] &= ~cpu_to_le32(MT_TXD3_NO_ACK);
352+ le32p_replace_bits(&txwi[3], 0x1f, MT_TXD3_REM_TX_COUNT);
353+
developerf7a3ca32022-09-01 14:44:55 +0800354 return;
developer6caa5e22022-06-16 13:33:13 +0800355+ }
356+
357+ mt76_tm_for_each_entry(phy->mt76, wcid, ed)
358+ if (ed->tx_skb == skb)
359+ break;
360+
361+ if (!ed)
developerf7a3ca32022-09-01 14:44:55 +0800362+ return;
363+
developer6caa5e22022-06-16 13:33:13 +0800364+ nss = ed->tx_rate_nss;
365+ rate_idx = ed->tx_rate_idx;
366+ ldpc = ed->tx_rate_ldpc;
developerf7a3ca32022-09-01 14:44:55 +0800367
developer6caa5e22022-06-16 13:33:13 +0800368 switch (td->tx_rate_mode) {
369 case MT76_TM_TX_MODE_HT:
developera46f6132024-03-26 14:09:54 +0800370@@ -651,7 +674,7 @@ mt7915_mac_write_txwi_tm(struct mt7915_phy *phy, __le32 *txwi,
developer3f784572023-01-31 15:21:28 +0800371 rate_idx += 4;
372
373 r = &phy->mt76->hw->wiphy->bands[band]->bitrates[rate_idx];
374- val = cck ? r->hw_value_short : r->hw_value;
375+ val = r->hw_value;
376
377 mode = val >> 8;
378 rate_idx = val & 0xff;
developera46f6132024-03-26 14:09:54 +0800379@@ -710,13 +733,14 @@ mt7915_mac_write_txwi_tm(struct mt7915_phy *phy, __le32 *txwi,
developer6caa5e22022-06-16 13:33:13 +0800380 if (mode >= MT_PHY_TYPE_HE_SU)
381 val |= FIELD_PREP(MT_TXD6_HELTF, td->tx_ltf);
382
383- if (td->tx_rate_ldpc || (bw > 0 && mode >= MT_PHY_TYPE_HE_SU))
384+ if (ldpc || (bw > 0 && mode >= MT_PHY_TYPE_HE_SU))
385 val |= MT_TXD6_LDPC;
386
developerf7a3ca32022-09-01 14:44:55 +0800387 txwi[3] &= ~cpu_to_le32(MT_TXD3_SN_VALID);
developer6caa5e22022-06-16 13:33:13 +0800388+ if (phy->test.bf_en)
389+ val |= MT_TXD6_TX_IBF | MT_TXD6_TX_EBF;
390+
391 txwi[6] |= cpu_to_le32(val);
392- txwi[7] |= cpu_to_le32(FIELD_PREP(MT_TXD7_SPE_IDX,
393- phy->test.spe_idx));
394 #endif
395 }
396
developera20cdc22024-05-31 18:57:31 +0800397@@ -1379,7 +1403,7 @@ mt7915_mac_restart(struct mt7915_dev *dev)
developer047bc182022-11-16 12:20:48 +0800398 goto out;
399
400 /* set the necessary init items */
401- ret = mt7915_mcu_set_eeprom(dev);
402+ ret = mt7915_mcu_set_eeprom(dev, dev->flash_mode);
403 if (ret)
404 goto out;
405
developer6caa5e22022-06-16 13:33:13 +0800406diff --git a/mt7915/main.c b/mt7915/main.c
developer05f3b2b2024-08-19 19:17:34 +0800407index 09e1a83b..2e566710 100644
developer6caa5e22022-06-16 13:33:13 +0800408--- a/mt7915/main.c
409+++ b/mt7915/main.c
developerc5ce7502022-12-19 11:33:22 +0800410@@ -238,7 +238,7 @@ static int mt7915_add_interface(struct ieee80211_hw *hw,
developer6caa5e22022-06-16 13:33:13 +0800411 mvif->phy = phy;
developer17bb0a82022-12-13 15:52:04 +0800412 mvif->mt76.band_idx = phy->mt76->band_idx;
developer6caa5e22022-06-16 13:33:13 +0800413
414- mvif->mt76.wmm_idx = vif->type != NL80211_IFTYPE_AP;
415+ mvif->mt76.wmm_idx = (vif->type != NL80211_IFTYPE_AP && vif->type != NL80211_IFTYPE_MONITOR);
416 if (ext_phy)
417 mvif->mt76.wmm_idx += 2;
418
419diff --git a/mt7915/mcu.c b/mt7915/mcu.c
developer05f3b2b2024-08-19 19:17:34 +0800420index cd5363c6..b5177e30 100644
developer6caa5e22022-06-16 13:33:13 +0800421--- a/mt7915/mcu.c
422+++ b/mt7915/mcu.c
developer753619c2024-02-22 13:42:45 +0800423@@ -478,6 +478,11 @@ mt7915_mcu_rx_ext_event(struct mt7915_dev *dev, struct sk_buff *skb)
developer6caa5e22022-06-16 13:33:13 +0800424 case MCU_EXT_EVENT_BCC_NOTIFY:
425 mt7915_mcu_rx_bcc_notify(dev, skb);
426 break;
427+#ifdef CONFIG_NL80211_TESTMODE
428+ case MCU_EXT_EVENT_BF_STATUS_READ:
429+ mt7915_tm_txbf_status_read(dev, skb);
430+ break;
431+#endif
developer753619c2024-02-22 13:42:45 +0800432 case MCU_EXT_EVENT_BSS_ACQ_PKT_CNT:
433 mt7915_mcu_rx_bss_acq_pkt_cnt(dev, skb);
developer6caa5e22022-06-16 13:33:13 +0800434 break;
developer753619c2024-02-22 13:42:45 +0800435@@ -512,6 +517,7 @@ void mt7915_mcu_rx_event(struct mt7915_dev *dev, struct sk_buff *skb)
developer47efbdb2023-06-29 20:33:22 +0800436 rxd->ext_eid == MCU_EXT_EVENT_ASSERT_DUMP ||
437 rxd->ext_eid == MCU_EXT_EVENT_PS_SYNC ||
438 rxd->ext_eid == MCU_EXT_EVENT_BCC_NOTIFY ||
439+ rxd->ext_eid == MCU_EXT_EVENT_BF_STATUS_READ ||
440 !rxd->seq) &&
441 !(rxd->eid == MCU_CMD_EXT_CID &&
442 rxd->ext_eid == MCU_EXT_EVENT_WA_TX_STAT))
developer753619c2024-02-22 13:42:45 +0800443@@ -2853,7 +2859,8 @@ int mt7915_mcu_set_chan_info(struct mt7915_phy *phy, int cmd)
developer692ed9b2023-06-19 12:03:50 +0800444 }
445 #endif
446
447- if (mt76_connac_spe_idx(phy->mt76->antenna_mask))
448+ if (mt76_connac_spe_idx(phy->mt76->antenna_mask) &&
449+ !mt76_testmode_enabled(phy->mt76))
450 req.tx_path_num = fls(phy->mt76->antenna_mask);
451
developerbddc9db2023-09-11 13:34:36 +0800452 if (phy->mt76->hw->conf.flags & IEEE80211_CONF_MONITOR)
developer753619c2024-02-22 13:42:45 +0800453@@ -2921,21 +2928,21 @@ static int mt7915_mcu_set_eeprom_flash(struct mt7915_dev *dev)
developer6caa5e22022-06-16 13:33:13 +0800454 return 0;
455 }
456
457-int mt7915_mcu_set_eeprom(struct mt7915_dev *dev)
458+int mt7915_mcu_set_eeprom(struct mt7915_dev *dev, bool flash_mode)
459 {
460 struct mt7915_mcu_eeprom req = {
461 .buffer_mode = EE_MODE_EFUSE,
462 .format = EE_FORMAT_WHOLE,
463 };
464
465- if (dev->flash_mode)
466+ if (flash_mode)
467 return mt7915_mcu_set_eeprom_flash(dev);
468
469 return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(EFUSE_BUFFER_MODE),
developerc9333e12023-04-06 18:07:42 +0800470 &req, sizeof(req), true);
471 }
472
473-int mt7915_mcu_get_eeprom(struct mt7915_dev *dev, u32 offset)
474+int mt7915_mcu_get_eeprom(struct mt7915_dev *dev, u32 offset, u8 *read_buf)
475 {
476 struct mt7915_mcu_eeprom_info req = {
477 .addr = cpu_to_le32(round_down(offset,
developer753619c2024-02-22 13:42:45 +0800478@@ -2944,7 +2951,7 @@ int mt7915_mcu_get_eeprom(struct mt7915_dev *dev, u32 offset)
developerc9333e12023-04-06 18:07:42 +0800479 struct mt7915_mcu_eeprom_info *res;
480 struct sk_buff *skb;
481 int ret;
482- u8 *buf;
483+ u8 *buf = read_buf;
484
485 ret = mt76_mcu_send_and_get_msg(&dev->mt76,
486 MCU_EXT_QUERY(EFUSE_ACCESS),
developer753619c2024-02-22 13:42:45 +0800487@@ -2953,8 +2960,11 @@ int mt7915_mcu_get_eeprom(struct mt7915_dev *dev, u32 offset)
developerc9333e12023-04-06 18:07:42 +0800488 return ret;
489
490 res = (struct mt7915_mcu_eeprom_info *)skb->data;
491- buf = dev->mt76.eeprom.data + le32_to_cpu(res->addr);
492+
493+ if (!buf)
494+ buf = dev->mt76.eeprom.data + le32_to_cpu(res->addr);
495 memcpy(buf, res->data, MT7915_EEPROM_BLOCK_SIZE);
496+
497 dev_kfree_skb(skb);
498
499 return 0;
developer6caa5e22022-06-16 13:33:13 +0800500diff --git a/mt7915/mcu.h b/mt7915/mcu.h
developer05f3b2b2024-08-19 19:17:34 +0800501index 7653b5e2..c791c7fa 100644
developer6caa5e22022-06-16 13:33:13 +0800502--- a/mt7915/mcu.h
503+++ b/mt7915/mcu.h
developer7c3a5082022-06-24 13:40:42 +0800504@@ -8,10 +8,15 @@
developer6caa5e22022-06-16 13:33:13 +0800505
506 enum {
507 MCU_ATE_SET_TRX = 0x1,
508+ MCU_ATE_SET_TSSI = 0x5,
509+ MCU_ATE_SET_DPD = 0x6,
510+ MCU_ATE_SET_RATE_POWER_OFFSET = 0x7,
511+ MCU_ATE_SET_THERMAL_COMP = 0x8,
512 MCU_ATE_SET_FREQ_OFFSET = 0xa,
513 MCU_ATE_SET_PHY_COUNT = 0x11,
514 MCU_ATE_SET_SLOT_TIME = 0x13,
515 MCU_ATE_CLEAN_TXQUEUE = 0x1c,
516+ MCU_ATE_SET_MU_RX_AID = 0x1e,
517 };
518
developer7c3a5082022-06-24 13:40:42 +0800519 struct mt7915_mcu_thermal_ctrl {
developer753619c2024-02-22 13:42:45 +0800520@@ -542,6 +547,12 @@ enum {
developer6caa5e22022-06-16 13:33:13 +0800521
522 enum {
523 MT_BF_SOUNDING_ON = 1,
524+ MT_BF_DATA_PACKET_APPLY = 2,
525+ MT_BF_PFMU_TAG_READ = 5,
526+ MT_BF_PFMU_TAG_WRITE = 6,
527+ MT_BF_PHASE_CAL = 14,
528+ MT_BF_IBF_PHASE_COMP = 15,
529+ MT_BF_PROFILE_WRITE_ALL = 17,
530 MT_BF_TYPE_UPDATE = 20,
531 MT_BF_MODULE_UPDATE = 25
532 };
developer753619c2024-02-22 13:42:45 +0800533@@ -787,10 +798,20 @@ struct mt7915_muru {
developer6caa5e22022-06-16 13:33:13 +0800534 #define MURU_OFDMA_SCH_TYPE_UL BIT(1)
535
developer7c3a5082022-06-24 13:40:42 +0800536 /* Common Config */
developer6caa5e22022-06-16 13:33:13 +0800537-#define MURU_COMM_PPDU_FMT BIT(0)
538-#define MURU_COMM_SCH_TYPE BIT(1)
539-#define MURU_COMM_SET (MURU_COMM_PPDU_FMT | MURU_COMM_SCH_TYPE)
developer6caa5e22022-06-16 13:33:13 +0800540-/* DL&UL User config*/
developer6caa5e22022-06-16 13:33:13 +0800541+/* #define MURU_COMM_PPDU_FMT BIT(0) */
542+/* #define MURU_COMM_SCH_TYPE BIT(1) */
543+/* #define MURU_COMM_SET (MURU_COMM_PPDU_FMT | MURU_COMM_SCH_TYPE) */
developer7c3a5082022-06-24 13:40:42 +0800544+#define MURU_COMM_PPDU_FMT BIT(0)
545+#define MURU_COMM_SCH_TYPE BIT(1)
546+#define MURU_COMM_BAND BIT(2)
547+#define MURU_COMM_WMM BIT(3)
548+#define MURU_COMM_SPE_IDX BIT(4)
549+#define MURU_COMM_PROC_TYPE BIT(5)
developer1475cf22023-05-05 13:45:43 +0800550+#define MURU_COMM_SET (MURU_COMM_PPDU_FMT | MURU_COMM_SCH_TYPE)
551+#define MURU_COMM_SET_TM (MURU_COMM_PPDU_FMT | MURU_COMM_BAND | \
552+ MURU_COMM_WMM | MURU_COMM_SPE_IDX)
developer6caa5e22022-06-16 13:33:13 +0800553+
554+/* DL&UL User config */
555 #define MURU_USER_CNT BIT(4)
556
557 enum {
558diff --git a/mt7915/mmio.c b/mt7915/mmio.c
developer05f3b2b2024-08-19 19:17:34 +0800559index 02b4714c..730cd338 100644
developer6caa5e22022-06-16 13:33:13 +0800560--- a/mt7915/mmio.c
561+++ b/mt7915/mmio.c
developer60a3d662023-02-07 15:24:34 +0800562@@ -134,6 +134,7 @@ static const u32 mt7915_offs[] = {
developer6caa5e22022-06-16 13:33:13 +0800563 [ARB_DRNGR0] = 0x194,
564 [ARB_SCR] = 0x080,
565 [RMAC_MIB_AIRTIME14] = 0x3b8,
566+ [AGG_AALCR0] = 0x048,
567 [AGG_AWSCR0] = 0x05c,
568 [AGG_PCR0] = 0x06c,
569 [AGG_ACR0] = 0x084,
developer60a3d662023-02-07 15:24:34 +0800570@@ -209,6 +210,7 @@ static const u32 mt7916_offs[] = {
developer6caa5e22022-06-16 13:33:13 +0800571 [ARB_DRNGR0] = 0x1e0,
572 [ARB_SCR] = 0x000,
573 [RMAC_MIB_AIRTIME14] = 0x0398,
574+ [AGG_AALCR0] = 0x028,
575 [AGG_AWSCR0] = 0x030,
576 [AGG_PCR0] = 0x040,
577 [AGG_ACR0] = 0x054,
578diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developer05f3b2b2024-08-19 19:17:34 +0800579index cf49ac86..bc77a61a 100644
developer6caa5e22022-06-16 13:33:13 +0800580--- a/mt7915/mt7915.h
581+++ b/mt7915/mt7915.h
developer05f3b2b2024-08-19 19:17:34 +0800582@@ -317,11 +317,15 @@ struct mt7915_phy {
developerbd9fa1e2023-10-16 11:04:00 +0800583
584 s32 last_freq_offset;
585 u8 last_rcpi[4];
586+ s8 last_rssi[4];
587 s8 last_ib_rssi[4];
588 s8 last_wb_rssi[4];
developer6caa5e22022-06-16 13:33:13 +0800589 u8 last_snr;
590
591 u8 spe_idx;
592+
593+ bool bf_en;
594+ bool bf_ever_en;
595 } test;
596 #endif
597
developer05f3b2b2024-08-19 19:17:34 +0800598@@ -438,6 +442,14 @@ struct mt7915_dev {
developer6caa5e22022-06-16 13:33:13 +0800599 void __iomem *dcm;
600 void __iomem *sku;
601
602+#ifdef CONFIG_NL80211_TESTMODE
603+ struct {
604+ void *txbf_phase_cal;
605+ void *txbf_pfmu_data;
606+ void *txbf_pfmu_tag;
607+ } test;
608+#endif
609+
610 #ifdef MTK_DEBUG
611 u16 wlan_idx;
612 struct {
developer05f3b2b2024-08-19 19:17:34 +0800613@@ -618,8 +630,8 @@ int mt7915_mcu_set_fixed_rate_ctrl(struct mt7915_dev *dev,
developer6caa5e22022-06-16 13:33:13 +0800614 struct ieee80211_vif *vif,
615 struct ieee80211_sta *sta,
616 void *data, u32 field);
617-int mt7915_mcu_set_eeprom(struct mt7915_dev *dev);
developerc9333e12023-04-06 18:07:42 +0800618-int mt7915_mcu_get_eeprom(struct mt7915_dev *dev, u32 offset);
developer6caa5e22022-06-16 13:33:13 +0800619+int mt7915_mcu_set_eeprom(struct mt7915_dev *dev, bool flash_mode);
developerc9333e12023-04-06 18:07:42 +0800620+int mt7915_mcu_get_eeprom(struct mt7915_dev *dev, u32 offset, u8 *read_buf);
developer6caa5e22022-06-16 13:33:13 +0800621 int mt7915_mcu_get_eeprom_free_block(struct mt7915_dev *dev, u8 *block_num);
622 int mt7915_mcu_set_mac(struct mt7915_dev *dev, int band, bool enable,
developerc9333e12023-04-06 18:07:42 +0800623 bool hdr_trans);
developer05f3b2b2024-08-19 19:17:34 +0800624@@ -658,6 +670,7 @@ int mt7915_mcu_fw_log_2_host(struct mt7915_dev *dev, u8 type, u8 ctrl);
developer6caa5e22022-06-16 13:33:13 +0800625 int mt7915_mcu_fw_dbg_ctrl(struct mt7915_dev *dev, u32 module, u8 level);
626 void mt7915_mcu_rx_event(struct mt7915_dev *dev, struct sk_buff *skb);
627 void mt7915_mcu_exit(struct mt7915_dev *dev);
628+int mt7915_tm_txbf_status_read(struct mt7915_dev *dev, struct sk_buff *skb);
developer753619c2024-02-22 13:42:45 +0800629 void mt7915_mcu_wmm_pbc_work(struct work_struct *work);
developer6caa5e22022-06-16 13:33:13 +0800630
developer05f3b2b2024-08-19 19:17:34 +0800631 static inline u16 mt7915_wtbl_size(struct mt7915_dev *dev)
developer6caa5e22022-06-16 13:33:13 +0800632diff --git a/mt7915/regs.h b/mt7915/regs.h
developer05f3b2b2024-08-19 19:17:34 +0800633index 8bb6a9f2..1236da91 100644
developer6caa5e22022-06-16 13:33:13 +0800634--- a/mt7915/regs.h
635+++ b/mt7915/regs.h
developer3609d782022-11-29 18:07:22 +0800636@@ -62,6 +62,7 @@ enum offs_rev {
developer6caa5e22022-06-16 13:33:13 +0800637 ARB_DRNGR0,
638 ARB_SCR,
639 RMAC_MIB_AIRTIME14,
640+ AGG_AALCR0,
641 AGG_AWSCR0,
642 AGG_PCR0,
643 AGG_ACR0,
developerbd9fa1e2023-10-16 11:04:00 +0800644@@ -486,6 +487,8 @@ enum offs_rev {
developer6caa5e22022-06-16 13:33:13 +0800645 #define MT_WF_AGG_BASE(_band) ((_band) ? 0x820f2000 : 0x820e2000)
646 #define MT_WF_AGG(_band, ofs) (MT_WF_AGG_BASE(_band) + (ofs))
647
648+#define MT_AGG_AALCR0(_band, _n) MT_WF_AGG(_band, (__OFFS(AGG_AALCR0) + \
developer692ed9b2023-06-19 12:03:50 +0800649+ (_n) * 4))
developer6caa5e22022-06-16 13:33:13 +0800650 #define MT_AGG_AWSCR0(_band, _n) MT_WF_AGG(_band, (__OFFS(AGG_AWSCR0) + \
651 (_n) * 4))
652 #define MT_AGG_PCR0(_band, _n) MT_WF_AGG(_band, (__OFFS(AGG_PCR0) + \
653diff --git a/mt7915/testmode.c b/mt7915/testmode.c
developer05f3b2b2024-08-19 19:17:34 +0800654index 46939191..32dc85cd 100644
developer6caa5e22022-06-16 13:33:13 +0800655--- a/mt7915/testmode.c
656+++ b/mt7915/testmode.c
developerbd9fa1e2023-10-16 11:04:00 +0800657@@ -9,6 +9,10 @@
developer6caa5e22022-06-16 13:33:13 +0800658 enum {
659 TM_CHANGED_TXPOWER,
660 TM_CHANGED_FREQ_OFFSET,
developerbd9fa1e2023-10-16 11:04:00 +0800661+ TM_CHANGED_SKU_EN,
developer6caa5e22022-06-16 13:33:13 +0800662+ TM_CHANGED_AID,
663+ TM_CHANGED_CFG,
664+ TM_CHANGED_TXBF_ACT,
665
666 /* must be last */
667 NUM_TM_CHANGED
developerbd9fa1e2023-10-16 11:04:00 +0800668@@ -17,6 +21,10 @@ enum {
developer6caa5e22022-06-16 13:33:13 +0800669 static const u8 tm_change_map[] = {
670 [TM_CHANGED_TXPOWER] = MT76_TM_ATTR_TX_POWER,
671 [TM_CHANGED_FREQ_OFFSET] = MT76_TM_ATTR_FREQ_OFFSET,
developerbd9fa1e2023-10-16 11:04:00 +0800672+ [TM_CHANGED_SKU_EN] = MT76_TM_ATTR_SKU_EN,
developer6caa5e22022-06-16 13:33:13 +0800673+ [TM_CHANGED_AID] = MT76_TM_ATTR_AID,
674+ [TM_CHANGED_CFG] = MT76_TM_ATTR_CFG,
675+ [TM_CHANGED_TXBF_ACT] = MT76_TM_ATTR_TXBF_ACT,
676 };
677
678 struct reg_band {
developerbd9fa1e2023-10-16 11:04:00 +0800679@@ -33,6 +41,57 @@ struct reg_band {
developer6caa5e22022-06-16 13:33:13 +0800680 #define TM_REG_MAX_ID 20
681 static struct reg_band reg_backup_list[TM_REG_MAX_ID];
682
683+static void mt7915_tm_update_entry(struct mt7915_phy *phy);
684+
685+static u8 mt7915_tm_chan_bw(enum nl80211_chan_width width)
686+{
687+ static const u8 width_to_bw[] = {
688+ [NL80211_CHAN_WIDTH_40] = TM_CBW_40MHZ,
689+ [NL80211_CHAN_WIDTH_80] = TM_CBW_80MHZ,
690+ [NL80211_CHAN_WIDTH_80P80] = TM_CBW_8080MHZ,
691+ [NL80211_CHAN_WIDTH_160] = TM_CBW_160MHZ,
692+ [NL80211_CHAN_WIDTH_5] = TM_CBW_5MHZ,
693+ [NL80211_CHAN_WIDTH_10] = TM_CBW_10MHZ,
694+ [NL80211_CHAN_WIDTH_20] = TM_CBW_20MHZ,
695+ [NL80211_CHAN_WIDTH_20_NOHT] = TM_CBW_20MHZ,
696+ };
697+
698+ if (width >= ARRAY_SIZE(width_to_bw))
699+ return 0;
700+
701+ return width_to_bw[width];
702+}
703+
developer692ed9b2023-06-19 12:03:50 +0800704+static int
705+mt7915_tm_check_antenna(struct mt7915_phy *phy)
706+{
707+ struct mt76_testmode_data *td = &phy->mt76->test;
708+ struct mt7915_dev *dev = phy->dev;
709+ u8 band_idx = phy->mt76->band_idx;
710+ u32 chainmask = phy->mt76->chainmask;
711+
712+ chainmask = chainmask >> (dev->chainshift * band_idx);
713+ if (td->tx_antenna_mask & ~chainmask) {
714+ dev_err(dev->mt76.dev,
715+ "tx antenna mask %d exceeds hardware limitation (chainmask %d)\n",
716+ td->tx_antenna_mask, chainmask);
717+ return -EINVAL;
718+ }
719+
720+ return 0;
721+}
722+
developer6caa5e22022-06-16 13:33:13 +0800723+static void
724+mt7915_tm_update_channel(struct mt7915_phy *phy)
725+{
726+ mutex_unlock(&phy->dev->mt76.mutex);
727+ mt7915_set_channel(phy);
728+ mutex_lock(&phy->dev->mt76.mutex);
729+
730+ mt7915_mcu_set_chan_info(phy, MCU_EXT_CMD(SET_RX_PATH));
731+
732+ mt7915_tm_update_entry(phy);
733+}
734
735 static int
736 mt7915_tm_set_tx_power(struct mt7915_phy *phy)
developerbd9fa1e2023-10-16 11:04:00 +0800737@@ -119,18 +178,28 @@ mt7915_tm_set_trx(struct mt7915_phy *phy, int type, bool en)
developer6caa5e22022-06-16 13:33:13 +0800738 }
739
740 static int
741-mt7915_tm_clean_hwq(struct mt7915_phy *phy, u8 wcid)
742+mt7915_tm_clean_hwq(struct mt7915_phy *phy)
743 {
744+ struct mt76_testmode_entry_data *ed;
745+ struct mt76_wcid *wcid;
746 struct mt7915_dev *dev = phy->dev;
747 struct mt7915_tm_cmd req = {
748 .testmode_en = 1,
749 .param_idx = MCU_ATE_CLEAN_TXQUEUE,
750- .param.clean.wcid = wcid,
developer17bb0a82022-12-13 15:52:04 +0800751 .param.clean.band = phy->mt76->band_idx,
developer6caa5e22022-06-16 13:33:13 +0800752 };
753
754- return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(ATE_CTRL), &req,
755- sizeof(req), false);
756+ mt76_tm_for_each_entry(phy->mt76, wcid, ed) {
757+ int ret;
758+
759+ req.param.clean.wcid = wcid->idx;
760+ ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(ATE_CTRL),
761+ &req, sizeof(req), false);
762+ if (ret)
763+ return ret;
764+ }
765+
766+ return 0;
767 }
768
769 static int
developerbd9fa1e2023-10-16 11:04:00 +0800770@@ -141,7 +210,7 @@ mt7915_tm_set_phy_count(struct mt7915_phy *phy, u8 control)
developer17bb0a82022-12-13 15:52:04 +0800771 .testmode_en = 1,
772 .param_idx = MCU_ATE_SET_PHY_COUNT,
773 .param.cfg.enable = control,
774- .param.cfg.band = phy != &dev->phy,
775+ .param.cfg.band = phy->mt76->band_idx,
776 };
777
778 return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(ATE_CTRL), &req,
developerbd9fa1e2023-10-16 11:04:00 +0800779@@ -182,12 +251,739 @@ mt7915_tm_set_tam_arb(struct mt7915_phy *phy, bool enable, bool mu)
developer6caa5e22022-06-16 13:33:13 +0800780 return mt7915_mcu_set_muru_ctrl(dev, MURU_SET_ARB_OP_MODE, op_mode);
781 }
782
783+static int
784+mt7915_tm_set_cfg(struct mt7915_phy *phy)
785+{
786+ static const u8 cfg_cmd[] = {
787+ [MT76_TM_CFG_TSSI] = MCU_ATE_SET_TSSI,
788+ [MT76_TM_CFG_DPD] = MCU_ATE_SET_DPD,
789+ [MT76_TM_CFG_RATE_POWER_OFFSET] = MCU_ATE_SET_RATE_POWER_OFFSET,
790+ [MT76_TM_CFG_THERMAL_COMP] = MCU_ATE_SET_THERMAL_COMP,
791+ };
792+ struct mt76_testmode_data *td = &phy->mt76->test;
793+ struct mt7915_dev *dev = phy->dev;
794+ struct mt7915_tm_cmd req = {
795+ .testmode_en = !(phy->mt76->test.state == MT76_TM_STATE_OFF),
796+ .param_idx = cfg_cmd[td->cfg.type],
797+ .param.cfg.enable = td->cfg.enable,
developer17bb0a82022-12-13 15:52:04 +0800798+ .param.cfg.band = phy->mt76->band_idx,
developer6caa5e22022-06-16 13:33:13 +0800799+ };
800+
801+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(ATE_CTRL), &req,
802+ sizeof(req), false);
803+}
804+
805+static int
806+mt7915_tm_add_txbf(struct mt7915_phy *phy, struct ieee80211_vif *vif,
807+ struct ieee80211_sta *sta, u8 pfmu_idx, u8 nr,
808+ u8 nc, bool ebf)
809+{
810+ struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
811+ struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
812+ struct mt7915_dev *dev = phy->dev;
813+ struct sk_buff *skb;
814+ struct sta_rec_bf *bf;
815+ struct tlv *tlv;
816+ u8 ndp_rate;
817+
818+ if (nr == 1)
819+ ndp_rate = 8;
820+ else if (nr == 2)
821+ ndp_rate = 16;
822+ else
823+ ndp_rate = 24;
824+
825+ skb = mt76_connac_mcu_alloc_sta_req(&dev->mt76, &mvif->mt76,
826+ &msta->wcid);
827+ if (IS_ERR(skb))
828+ return PTR_ERR(skb);
829+
830+ tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_BF, sizeof(*bf));
831+ bf = (struct sta_rec_bf *)tlv;
832+
833+ bf->pfmu = cpu_to_le16(pfmu_idx);
834+ bf->sounding_phy = 1;
835+ bf->bf_cap = ebf;
836+ bf->ncol = nc;
837+ bf->nrow = nr;
838+ bf->ndp_rate = ndp_rate;
839+ bf->ibf_timeout = 0xff;
840+ bf->tx_mode = MT_PHY_TYPE_HT;
841+
842+ if (ebf) {
843+ bf->mem[0].row = 0;
844+ bf->mem[1].row = 1;
845+ bf->mem[2].row = 2;
846+ bf->mem[3].row = 3;
847+ } else {
848+ bf->mem[0].row = 4;
849+ bf->mem[1].row = 5;
850+ bf->mem[2].row = 6;
851+ bf->mem[3].row = 7;
852+ }
853+
854+ return mt76_mcu_skb_send_msg(&dev->mt76, skb,
855+ MCU_EXT_CMD(STA_REC_UPDATE), true);
856+}
857+
858+static int
859+mt7915_tm_entry_add(struct mt7915_phy *phy, u8 aid)
860+{
861+ struct mt76_testmode_data *td = &phy->mt76->test;
862+ struct mt76_testmode_entry_data *ed;
863+ struct ieee80211_sband_iftype_data *sdata;
864+ struct ieee80211_supported_band *sband;
865+ struct ieee80211_sta *sta;
866+ struct mt7915_sta *msta;
867+ int tid, ret;
868+
869+ if (td->entry_num >= MT76_TM_MAX_ENTRY_NUM)
870+ return -EINVAL;
871+
872+ sta = kzalloc(sizeof(*sta) + phy->mt76->hw->sta_data_size +
873+ sizeof(*ed), GFP_KERNEL);
874+ if (!sta)
875+ return -ENOMEM;
876+
877+ msta = (struct mt7915_sta *)sta->drv_priv;
878+ ed = mt76_testmode_entry_data(phy->mt76, &msta->wcid);
879+ memcpy(ed, &td->ed, sizeof(*ed));
880+
881+ if (phy->mt76->chandef.chan->band == NL80211_BAND_5GHZ) {
882+ sband = &phy->mt76->sband_5g.sband;
883+ sdata = phy->iftype[NL80211_BAND_5GHZ];
884+ } else if (phy->mt76->chandef.chan->band == NL80211_BAND_6GHZ) {
885+ sband = &phy->mt76->sband_6g.sband;
886+ sdata = phy->iftype[NL80211_BAND_6GHZ];
887+ } else {
888+ sband = &phy->mt76->sband_2g.sband;
889+ sdata = phy->iftype[NL80211_BAND_2GHZ];
890+ }
891+
892+ memcpy(sta->addr, ed->addr[0], ETH_ALEN);
893+ if (phy->test.bf_en) {
894+ u8 addr[ETH_ALEN] = {0x00, 0x11, 0x11, 0x11, 0x11, 0x11};
895+
896+ memcpy(sta->addr, addr, ETH_ALEN);
897+ }
898+
899+ if (td->tx_rate_mode >= MT76_TM_TX_MODE_HT)
developer17bb0a82022-12-13 15:52:04 +0800900+ memcpy(&sta->deflink.ht_cap, &sband->ht_cap, sizeof(sta->deflink.ht_cap));
developer6caa5e22022-06-16 13:33:13 +0800901+ if (td->tx_rate_mode >= MT76_TM_TX_MODE_VHT)
developer17bb0a82022-12-13 15:52:04 +0800902+ memcpy(&sta->deflink.vht_cap, &sband->vht_cap, sizeof(sta->deflink.vht_cap));
developer6caa5e22022-06-16 13:33:13 +0800903+ if (td->tx_rate_mode >= MT76_TM_TX_MODE_HE_SU)
developer17bb0a82022-12-13 15:52:04 +0800904+ memcpy(&sta->deflink.he_cap, &sdata[NL80211_IFTYPE_STATION].he_cap,
905+ sizeof(sta->deflink.he_cap));
developer6caa5e22022-06-16 13:33:13 +0800906+ sta->aid = aid;
907+ sta->wme = 1;
908+
909+ ret = mt7915_mac_sta_add(&phy->dev->mt76, phy->monitor_vif, sta);
910+ if (ret) {
911+ kfree(sta);
912+ return ret;
913+ }
914+
915+ /* prevent from starting tx ba session */
916+ for (tid = 0; tid < 8; tid++)
developer47efbdb2023-06-29 20:33:22 +0800917+ set_bit(tid, &msta->wcid.ampdu_state);
developer6caa5e22022-06-16 13:33:13 +0800918+
919+ list_add_tail(&msta->wcid.list, &td->tm_entry_list);
920+ td->entry_num++;
921+
922+ return 0;
923+}
924+
925+static void
926+mt7915_tm_entry_remove(struct mt7915_phy *phy, u8 aid)
927+{
928+ struct mt76_testmode_data *td = &phy->mt76->test;
929+ struct mt76_wcid *wcid, *tmp;
930+
931+ if (list_empty(&td->tm_entry_list))
932+ return;
933+
934+ list_for_each_entry_safe(wcid, tmp, &td->tm_entry_list, list) {
935+ struct mt76_testmode_entry_data *ed;
936+ struct mt7915_dev *dev = phy->dev;
937+ struct ieee80211_sta *sta;
938+
939+ ed = mt76_testmode_entry_data(phy->mt76, wcid);
940+ if (aid && ed->aid != aid)
941+ continue;
942+
943+ sta = wcid_to_sta(wcid);
944+ mt7915_mac_sta_remove(&dev->mt76, phy->monitor_vif, sta);
945+ mt76_wcid_mask_clear(dev->mt76.wcid_mask, wcid->idx);
946+
947+ list_del_init(&wcid->list);
948+ kfree(sta);
949+ phy->mt76->test.entry_num--;
950+ }
951+}
952+
953+static int
954+mt7915_tm_set_entry(struct mt7915_phy *phy)
955+{
956+ struct mt76_testmode_data *td = &phy->mt76->test;
957+ struct mt76_testmode_entry_data *ed;
958+ struct mt76_wcid *wcid;
959+
960+ if (!td->aid) {
961+ if (td->state > MT76_TM_STATE_IDLE)
962+ mt76_testmode_set_state(phy->mt76, MT76_TM_STATE_IDLE);
963+ mt7915_tm_entry_remove(phy, td->aid);
964+ return 0;
965+ }
966+
967+ mt76_tm_for_each_entry(phy->mt76, wcid, ed) {
968+ if (ed->aid == td->aid) {
969+ struct sk_buff *skb;
970+
971+ local_bh_disable();
972+ skb = ed->tx_skb;
973+ memcpy(ed, &td->ed, sizeof(*ed));
974+ ed->tx_skb = skb;
975+ local_bh_enable();
976+
977+ return 0;
978+ }
979+ }
980+
981+ return mt7915_tm_entry_add(phy, td->aid);
982+}
983+
984+static void
985+mt7915_tm_update_entry(struct mt7915_phy *phy)
986+{
987+ struct mt76_testmode_data *td = &phy->mt76->test;
988+ struct mt76_testmode_entry_data *ed, tmp;
989+ struct mt76_wcid *wcid, *last;
990+
991+ if (!td->aid || phy->test.bf_en)
992+ return;
993+
994+ memcpy(&tmp, &td->ed, sizeof(tmp));
995+ last = list_last_entry(&td->tm_entry_list,
996+ struct mt76_wcid, list);
997+
998+ mt76_tm_for_each_entry(phy->mt76, wcid, ed) {
999+ memcpy(&td->ed, ed, sizeof(td->ed));
1000+ mt7915_tm_entry_remove(phy, td->aid);
1001+ mt7915_tm_entry_add(phy, td->aid);
1002+ if (wcid == last)
1003+ break;
1004+ }
1005+
1006+ memcpy(&td->ed, &tmp, sizeof(td->ed));
1007+}
1008+
1009+static int
1010+mt7915_tm_txbf_init(struct mt7915_phy *phy, u16 *val)
1011+{
1012+ struct mt76_testmode_data *td = &phy->mt76->test;
1013+ struct mt7915_dev *dev = phy->dev;
1014+ bool enable = val[0];
1015+ void *phase_cal, *pfmu_data, *pfmu_tag;
1016+ u8 addr[ETH_ALEN] = {0x00, 0x22, 0x22, 0x22, 0x22, 0x22};
1017+
1018+ if (!enable) {
1019+ phy->test.bf_en = 0;
1020+ return 0;
1021+ }
1022+
1023+ if (!dev->test.txbf_phase_cal) {
1024+ phase_cal = devm_kzalloc(dev->mt76.dev,
1025+ sizeof(struct mt7915_tm_txbf_phase) *
1026+ MAX_PHASE_GROUP_NUM,
1027+ GFP_KERNEL);
1028+ if (!phase_cal)
1029+ return -ENOMEM;
1030+
1031+ dev->test.txbf_phase_cal = phase_cal;
1032+ }
1033+
1034+ if (!dev->test.txbf_pfmu_data) {
1035+ pfmu_data = devm_kzalloc(dev->mt76.dev, 512, GFP_KERNEL);
1036+ if (!pfmu_data)
1037+ return -ENOMEM;
1038+
1039+ dev->test.txbf_pfmu_data = pfmu_data;
1040+ }
1041+
1042+ if (!dev->test.txbf_pfmu_tag) {
1043+ pfmu_tag = devm_kzalloc(dev->mt76.dev,
1044+ sizeof(struct mt7915_tm_pfmu_tag), GFP_KERNEL);
1045+ if (!pfmu_tag)
1046+ return -ENOMEM;
1047+
1048+ dev->test.txbf_pfmu_tag = pfmu_tag;
1049+ }
1050+
1051+ memcpy(phy->monitor_vif->addr, addr, ETH_ALEN);
1052+ mt7915_mcu_add_dev_info(phy, phy->monitor_vif, true);
1053+
1054+ td->tx_rate_mode = MT76_TM_TX_MODE_HT;
1055+ td->tx_mpdu_len = 1024;
1056+ td->tx_rate_sgi = 0;
1057+ td->tx_ipg = 100;
1058+ phy->test.bf_en = 1;
1059+
1060+ return mt7915_tm_set_trx(phy, TM_MAC_TX, true);
1061+}
1062+
1063+static int
1064+mt7915_tm_txbf_phase_comp(struct mt7915_phy *phy, u16 *val)
1065+{
1066+ struct mt7915_dev *dev = phy->dev;
1067+ struct {
1068+ u8 category;
1069+ u8 wlan_idx_lo;
1070+ u8 bw;
1071+ u8 jp_band;
1072+ u8 dbdc_idx;
1073+ bool read_from_e2p;
1074+ bool disable;
1075+ u8 wlan_idx_hi;
1076+ u8 buf[40];
1077+ } __packed req = {
1078+ .category = MT_BF_IBF_PHASE_COMP,
1079+ .bw = val[0],
1080+ .jp_band = (val[2] == 1) ? 1 : 0,
developer17bb0a82022-12-13 15:52:04 +08001081+ .dbdc_idx = phy->mt76->band_idx,
developer6caa5e22022-06-16 13:33:13 +08001082+ .read_from_e2p = val[3],
1083+ .disable = val[4],
1084+ };
1085+ struct mt7915_tm_txbf_phase *phase =
1086+ (struct mt7915_tm_txbf_phase *)dev->test.txbf_phase_cal;
1087+
1088+ wait_event_timeout(dev->mt76.tx_wait, phase[val[2]].status != 0, HZ);
1089+ memcpy(req.buf, &phase[val[2]].phase, sizeof(req.buf));
1090+
1091+ pr_info("ibf cal process: phase comp info\n");
1092+ print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 1,
1093+ &req, sizeof(req), 0);
1094+
1095+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(TXBF_ACTION), &req,
1096+ sizeof(req), true);
1097+}
1098+
1099+static int
1100+mt7915_tm_txbf_profile_tag_read(struct mt7915_phy *phy, u8 pfmu_idx)
1101+{
1102+ struct mt7915_dev *dev = phy->dev;
1103+ struct {
1104+ u8 format_id;
1105+ u8 pfmu_idx;
1106+ bool bfer;
1107+ u8 dbdc_idx;
1108+ } __packed req = {
1109+ .format_id = MT_BF_PFMU_TAG_READ,
1110+ .pfmu_idx = pfmu_idx,
1111+ .bfer = 1,
1112+ .dbdc_idx = phy != &dev->phy,
1113+ };
1114+ struct mt7915_tm_pfmu_tag *tag = phy->dev->test.txbf_pfmu_tag;
1115+
1116+ tag->t1.pfmu_idx = 0;
1117+
1118+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(TXBF_ACTION), &req,
1119+ sizeof(req), true);
1120+}
1121+
1122+static int
1123+mt7915_tm_txbf_profile_tag_write(struct mt7915_phy *phy, u8 pfmu_idx,
1124+ struct mt7915_tm_pfmu_tag *tag)
1125+{
1126+ struct mt7915_dev *dev = phy->dev;
1127+ struct {
1128+ u8 format_id;
1129+ u8 pfmu_idx;
1130+ bool bfer;
1131+ u8 dbdc_idx;
1132+ u8 buf[64];
1133+ } __packed req = {
1134+ .format_id = MT_BF_PFMU_TAG_WRITE,
1135+ .pfmu_idx = pfmu_idx,
1136+ .bfer = 1,
1137+ .dbdc_idx = phy != &dev->phy,
1138+ };
1139+
1140+ memcpy(req.buf, tag, sizeof(*tag));
1141+ wait_event_timeout(dev->mt76.tx_wait, tag->t1.pfmu_idx != 0, HZ);
1142+
1143+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(TXBF_ACTION), &req,
1144+ sizeof(req), false);
1145+}
1146+
1147+static int
1148+mt7915_tm_txbf_apply_tx(struct mt7915_phy *phy, u16 wlan_idx, bool ebf,
1149+ bool ibf, bool phase_cal)
1150+{
1151+#define to_wcid_lo(id) FIELD_GET(GENMASK(7, 0), (u16)id)
1152+#define to_wcid_hi(id) FIELD_GET(GENMASK(9, 8), (u16)id)
1153+ struct mt7915_dev *dev = phy->dev;
1154+ struct {
1155+ u8 category;
1156+ u8 wlan_idx_lo;
1157+ bool ebf;
1158+ bool ibf;
1159+ bool mu_txbf;
1160+ bool phase_cal;
1161+ u8 wlan_idx_hi;
1162+ u8 _rsv;
1163+ } __packed req = {
1164+ .category = MT_BF_DATA_PACKET_APPLY,
1165+ .wlan_idx_lo = to_wcid_lo(wlan_idx),
1166+ .ebf = ebf,
1167+ .ibf = ibf,
1168+ .phase_cal = phase_cal,
1169+ .wlan_idx_hi = to_wcid_hi(wlan_idx),
1170+ };
1171+
1172+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(TXBF_ACTION), &req,
1173+ sizeof(req), false);
1174+}
1175+
1176+static int mt7915_tm_txbf_set_rate(struct mt7915_phy *phy,
1177+ struct mt76_wcid *wcid)
1178+{
1179+ struct mt7915_dev *dev = phy->dev;
1180+ struct mt76_testmode_entry_data *ed = mt76_testmode_entry_data(phy->mt76, wcid);
1181+ struct ieee80211_sta *sta = wcid_to_sta(wcid);
1182+ struct sta_phy rate = {};
1183+
1184+ if (!sta)
1185+ return 0;
1186+
1187+ rate.type = MT_PHY_TYPE_HT;
1188+ rate.bw = mt7915_tm_chan_bw(phy->mt76->chandef.width);
1189+ rate.nss = ed->tx_rate_nss;
1190+ rate.mcs = ed->tx_rate_idx;
1191+ rate.ldpc = (rate.bw || ed->tx_rate_ldpc) * GENMASK(2, 0);
1192+
1193+ return mt7915_mcu_set_fixed_rate_ctrl(dev, phy->monitor_vif, sta,
1194+ &rate, RATE_PARAM_FIXED);
1195+}
1196+
1197+static int
1198+mt7915_tm_txbf_set_tx(struct mt7915_phy *phy, u16 *val)
1199+{
1200+ bool bf_on = val[0], update = val[3];
1201+ /* u16 wlan_idx = val[2]; */
1202+ struct mt7915_tm_pfmu_tag *tag = phy->dev->test.txbf_pfmu_tag;
1203+ struct mt76_testmode_data *td = &phy->mt76->test;
1204+ struct mt76_wcid *wcid;
1205+
1206+ if (bf_on) {
1207+ mt7915_tm_set_trx(phy, TM_MAC_RX_RXV, false);
1208+ mt7915_tm_txbf_profile_tag_read(phy, 2);
1209+ tag->t1.invalid_prof = false;
1210+ mt7915_tm_txbf_profile_tag_write(phy, 2, tag);
1211+
1212+ phy->test.bf_ever_en = true;
1213+
1214+ if (update)
1215+ mt7915_tm_txbf_apply_tx(phy, 1, 0, 1, 1);
1216+ } else {
1217+ if (!phy->test.bf_ever_en) {
1218+ if (update)
1219+ mt7915_tm_txbf_apply_tx(phy, 1, 0, 0, 0);
1220+ } else {
1221+ phy->test.bf_ever_en = false;
1222+
1223+ mt7915_tm_txbf_profile_tag_read(phy, 2);
1224+ tag->t1.invalid_prof = true;
1225+ mt7915_tm_txbf_profile_tag_write(phy, 2, tag);
1226+ }
1227+ }
1228+
1229+ wcid = list_first_entry(&td->tm_entry_list, struct mt76_wcid, list);
1230+ mt7915_tm_txbf_set_rate(phy, wcid);
1231+
1232+ return 0;
1233+}
1234+
1235+static int
1236+mt7915_tm_txbf_profile_update(struct mt7915_phy *phy, u16 *val, bool ebf)
1237+{
1238+ static const u8 mode_to_lm[] = {
1239+ [MT76_TM_TX_MODE_CCK] = 0,
1240+ [MT76_TM_TX_MODE_OFDM] = 0,
1241+ [MT76_TM_TX_MODE_HT] = 1,
1242+ [MT76_TM_TX_MODE_VHT] = 2,
1243+ [MT76_TM_TX_MODE_HE_SU] = 3,
1244+ [MT76_TM_TX_MODE_HE_EXT_SU] = 3,
1245+ [MT76_TM_TX_MODE_HE_TB] = 3,
1246+ [MT76_TM_TX_MODE_HE_MU] = 3,
1247+ };
1248+ struct mt76_testmode_data *td = &phy->mt76->test;
1249+ struct mt76_wcid *wcid;
1250+ struct ieee80211_vif *vif = phy->monitor_vif;
1251+ struct mt7915_tm_pfmu_tag *tag = phy->dev->test.txbf_pfmu_tag;
1252+ u8 pfmu_idx = val[0], nc = val[2], nr;
1253+ int ret;
1254+
1255+ if (td->tx_antenna_mask == 3)
1256+ nr = 1;
1257+ else if (td->tx_antenna_mask == 7)
1258+ nr = 2;
1259+ else
1260+ nr = 3;
1261+
1262+ memset(tag, 0, sizeof(*tag));
1263+ tag->t1.pfmu_idx = pfmu_idx;
1264+ tag->t1.ebf = ebf;
1265+ tag->t1.nr = nr;
1266+ tag->t1.nc = nc;
1267+ tag->t1.invalid_prof = true;
1268+
1269+ tag->t1.snr_sts4 = 0xc0;
1270+ tag->t1.snr_sts5 = 0xff;
1271+ tag->t1.snr_sts6 = 0xff;
1272+ tag->t1.snr_sts7 = 0xff;
1273+
1274+ if (ebf) {
1275+ tag->t1.row_id1 = 0;
1276+ tag->t1.row_id2 = 1;
1277+ tag->t1.row_id3 = 2;
1278+ tag->t1.row_id4 = 3;
1279+ tag->t1.lm = mode_to_lm[MT76_TM_TX_MODE_HT];
1280+ } else {
1281+ tag->t1.row_id1 = 4;
1282+ tag->t1.row_id2 = 5;
1283+ tag->t1.row_id3 = 6;
1284+ tag->t1.row_id4 = 7;
1285+ tag->t1.lm = mode_to_lm[MT76_TM_TX_MODE_OFDM];
1286+
1287+ tag->t2.ibf_timeout = 0xff;
1288+ tag->t2.ibf_nr = nr;
1289+ }
1290+
1291+ ret = mt7915_tm_txbf_profile_tag_write(phy, pfmu_idx, tag);
1292+ if (ret)
1293+ return ret;
1294+
1295+ wcid = list_first_entry(&td->tm_entry_list, struct mt76_wcid, list);
1296+ ret = mt7915_tm_add_txbf(phy, vif, wcid_to_sta(wcid), pfmu_idx, nr, nc, ebf);
1297+ if (ret)
1298+ return ret;
1299+
1300+ if (!ebf)
1301+ return mt7915_tm_txbf_apply_tx(phy, 1, false, true, true);
1302+
1303+ return 0;
1304+}
1305+
1306+static int
1307+mt7915_tm_txbf_phase_cal(struct mt7915_phy *phy, u16 *val)
1308+{
1309+#define GROUP_L 0
1310+#define GROUP_M 1
1311+#define GROUP_H 2
1312+ struct mt7915_dev *dev = phy->dev;
1313+ struct {
1314+ u8 category;
1315+ u8 group_l_m_n;
1316+ u8 group;
1317+ bool sx2;
1318+ u8 cal_type;
1319+ u8 lna_gain_level;
1320+ u8 _rsv[2];
1321+ } __packed req = {
1322+ .category = MT_BF_PHASE_CAL,
1323+ .group = val[0],
1324+ .group_l_m_n = val[1],
1325+ .sx2 = val[2],
1326+ .cal_type = val[3],
1327+ .lna_gain_level = 0, /* for test purpose */
1328+ };
1329+ struct mt7915_tm_txbf_phase *phase =
1330+ (struct mt7915_tm_txbf_phase *)dev->test.txbf_phase_cal;
1331+
1332+ phase[req.group].status = 0;
1333+
1334+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(TXBF_ACTION), &req,
1335+ sizeof(req), true);
1336+}
1337+
1338+int mt7915_tm_txbf_status_read(struct mt7915_dev *dev, struct sk_buff *skb)
1339+{
1340+#define BF_PFMU_TAG 16
1341+#define BF_CAL_PHASE 21
1342+ u8 format_id;
1343+
developer7c3a5082022-06-24 13:40:42 +08001344+ skb_pull(skb, sizeof(struct mt76_connac2_mcu_rxd));
developer6caa5e22022-06-16 13:33:13 +08001345+ format_id = *(u8 *)skb->data;
1346+
1347+ if (format_id == BF_PFMU_TAG) {
1348+ struct mt7915_tm_pfmu_tag *tag = dev->test.txbf_pfmu_tag;
1349+
1350+ skb_pull(skb, 8);
1351+ memcpy(tag, skb->data, sizeof(struct mt7915_tm_pfmu_tag));
1352+ } else if (format_id == BF_CAL_PHASE) {
1353+ struct mt7915_tm_ibf_cal_info *cal;
1354+ struct mt7915_tm_txbf_phase *phase =
1355+ (struct mt7915_tm_txbf_phase *)dev->test.txbf_phase_cal;
1356+
1357+ cal = (struct mt7915_tm_ibf_cal_info *)skb->data;
1358+ switch (cal->cal_type) {
1359+ case IBF_PHASE_CAL_NORMAL:
1360+ case IBF_PHASE_CAL_NORMAL_INSTRUMENT:
1361+ if (cal->group_l_m_n != GROUP_M)
1362+ break;
1363+ phase = &phase[cal->group];
1364+ memcpy(&phase->phase, cal->buf + 16, sizeof(phase->phase));
1365+ phase->status = cal->status;
1366+ break;
1367+ case IBF_PHASE_CAL_VERIFY:
1368+ case IBF_PHASE_CAL_VERIFY_INSTRUMENT:
1369+ break;
1370+ default:
1371+ break;
1372+ }
1373+ }
1374+
1375+ wake_up(&dev->mt76.tx_wait);
1376+
1377+ return 0;
1378+}
1379+
1380+static int
1381+mt7915_tm_txbf_profile_update_all(struct mt7915_phy *phy, u16 *val)
1382+{
1383+ struct mt76_testmode_data *td = &phy->mt76->test;
developerf0fd7052023-08-14 20:23:42 +08001384+ u8 nss = hweight8(td->tx_antenna_mask);
developer6caa5e22022-06-16 13:33:13 +08001385+ u16 pfmu_idx = val[0];
1386+ u16 subc_id = val[1];
1387+ u16 angle11 = val[2];
1388+ u16 angle21 = val[3];
1389+ u16 angle31 = val[4];
1390+ u16 angle41 = val[5];
1391+ s16 phi11 = 0, phi21 = 0, phi31 = 0;
1392+ struct mt7915_tm_pfmu_data *pfmu_data;
1393+
1394+ if (subc_id > 63)
1395+ return -EINVAL;
1396+
developerf0fd7052023-08-14 20:23:42 +08001397+ if (nss == 2) {
developer6caa5e22022-06-16 13:33:13 +08001398+ phi11 = (s16)(angle21 - angle11);
developerf0fd7052023-08-14 20:23:42 +08001399+ } else if (nss == 3) {
developer6caa5e22022-06-16 13:33:13 +08001400+ phi11 = (s16)(angle31 - angle11);
1401+ phi21 = (s16)(angle31 - angle21);
1402+ } else {
1403+ phi11 = (s16)(angle41 - angle11);
1404+ phi21 = (s16)(angle41 - angle21);
1405+ phi31 = (s16)(angle41 - angle31);
1406+ }
1407+
1408+ pfmu_data = (struct mt7915_tm_pfmu_data *)phy->dev->test.txbf_pfmu_data;
1409+ pfmu_data = &pfmu_data[subc_id];
1410+
1411+ if (subc_id < 32)
1412+ pfmu_data->subc_idx = cpu_to_le16(subc_id + 224);
1413+ else
1414+ pfmu_data->subc_idx = cpu_to_le16(subc_id - 32);
1415+ pfmu_data->phi11 = cpu_to_le16(phi11);
1416+ pfmu_data->phi21 = cpu_to_le16(phi21);
1417+ pfmu_data->phi31 = cpu_to_le16(phi31);
1418+
1419+ if (subc_id == 63) {
1420+ struct mt7915_dev *dev = phy->dev;
1421+ struct {
1422+ u8 format_id;
1423+ u8 pfmu_idx;
1424+ u8 dbdc_idx;
1425+ u8 _rsv;
1426+ u8 buf[512];
1427+ } __packed req = {
1428+ .format_id = MT_BF_PROFILE_WRITE_ALL,
1429+ .pfmu_idx = pfmu_idx,
1430+ .dbdc_idx = phy != &dev->phy,
1431+ };
1432+
1433+ memcpy(req.buf, dev->test.txbf_pfmu_data, 512);
1434+
1435+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(TXBF_ACTION),
1436+ &req, sizeof(req), true);
1437+ }
1438+
1439+ return 0;
1440+}
1441+
1442+static int
1443+mt7915_tm_txbf_e2p_update(struct mt7915_phy *phy)
1444+{
1445+ struct mt7915_tm_txbf_phase *phase, *p;
1446+ struct mt7915_dev *dev = phy->dev;
1447+ u8 *eeprom = dev->mt76.eeprom.data;
1448+ u16 offset;
1449+ bool is_7976;
1450+ int i;
1451+
1452+ is_7976 = mt7915_check_adie(dev, false) || is_mt7916(&dev->mt76);
1453+ offset = is_7976 ? 0x60a : 0x651;
1454+
1455+ phase = (struct mt7915_tm_txbf_phase *)dev->test.txbf_phase_cal;
1456+ for (i = 0; i < MAX_PHASE_GROUP_NUM; i++) {
1457+ p = &phase[i];
1458+
1459+ if (!p->status)
1460+ continue;
1461+
1462+ /* copy phase cal data to eeprom */
1463+ memcpy(eeprom + offset + i * sizeof(p->phase), &p->phase,
1464+ sizeof(p->phase));
1465+ }
1466+
1467+ return 0;
1468+}
1469+
1470+static int
1471+mt7915_tm_set_txbf(struct mt7915_phy *phy)
1472+{
1473+ struct mt76_testmode_data *td = &phy->mt76->test;
1474+ u16 *val = td->txbf_param;
1475+
1476+ pr_info("ibf cal process: act = %u, val = %u, %u, %u, %u, %u\n",
1477+ td->txbf_act, val[0], val[1], val[2], val[3], val[4]);
1478+
1479+ switch (td->txbf_act) {
1480+ case MT76_TM_TXBF_ACT_INIT:
1481+ return mt7915_tm_txbf_init(phy, val);
1482+ case MT76_TM_TXBF_ACT_UPDATE_CH:
1483+ mt7915_tm_update_channel(phy);
1484+ break;
1485+ case MT76_TM_TXBF_ACT_PHASE_COMP:
1486+ return mt7915_tm_txbf_phase_comp(phy, val);
1487+ case MT76_TM_TXBF_ACT_TX_PREP:
1488+ return mt7915_tm_txbf_set_tx(phy, val);
1489+ case MT76_TM_TXBF_ACT_IBF_PROF_UPDATE:
1490+ return mt7915_tm_txbf_profile_update(phy, val, false);
1491+ case MT76_TM_TXBF_ACT_EBF_PROF_UPDATE:
1492+ return mt7915_tm_txbf_profile_update(phy, val, true);
1493+ case MT76_TM_TXBF_ACT_PHASE_CAL:
1494+ return mt7915_tm_txbf_phase_cal(phy, val);
1495+ case MT76_TM_TXBF_ACT_PROF_UPDATE_ALL:
1496+ return mt7915_tm_txbf_profile_update_all(phy, val);
1497+ case MT76_TM_TXBF_ACT_E2P_UPDATE:
1498+ return mt7915_tm_txbf_e2p_update(phy);
1499+ default:
1500+ break;
1501+ };
1502+
1503+ return 0;
1504+}
1505+
1506 static int
developer7c3a5082022-06-24 13:40:42 +08001507 mt7915_tm_set_wmm_qid(struct mt7915_phy *phy, u8 qid, u8 aifs, u8 cw_min,
developer6caa5e22022-06-16 13:33:13 +08001508- u16 cw_max, u16 txop)
1509+ u16 cw_max, u16 txop, u8 tx_cmd)
1510 {
developer7c3a5082022-06-24 13:40:42 +08001511 struct mt7915_vif *mvif = (struct mt7915_vif *)phy->monitor_vif->drv_priv;
developer6caa5e22022-06-16 13:33:13 +08001512- struct mt7915_mcu_tx req = { .total = 1 };
1513+ struct mt7915_mcu_tx req = {
1514+ .valid = true,
1515+ .mode = tx_cmd,
1516+ .total = 1,
1517+ };
1518 struct edca *e = &req.edca[0];
1519
developer7c3a5082022-06-24 13:40:42 +08001520 e->queue = qid + mvif->mt76.wmm_idx * MT76_CONNAC_MAX_WMM_SETS;
developerbd9fa1e2023-10-16 11:04:00 +08001521@@ -263,7 +1059,8 @@ done:
developer6caa5e22022-06-16 13:33:13 +08001522
developer7c3a5082022-06-24 13:40:42 +08001523 return mt7915_tm_set_wmm_qid(phy,
developer6caa5e22022-06-16 13:33:13 +08001524 mt76_connac_lmac_mapping(IEEE80211_AC_BE),
1525- aifsn, cw, cw, 0);
1526+ aifsn, cw, cw, 0,
1527+ mode == MT76_TM_TX_MODE_HE_MU);
1528 }
1529
1530 static int
developerbd9fa1e2023-10-16 11:04:00 +08001531@@ -339,7 +1136,7 @@ mt7915_tm_set_tx_len(struct mt7915_phy *phy, u32 tx_time)
developer6caa5e22022-06-16 13:33:13 +08001532 bitrate = cfg80211_calculate_bitrate(&rate);
1533 tx_len = bitrate * tx_time / 10 / 8;
1534
1535- ret = mt76_testmode_alloc_skb(phy->mt76, tx_len);
1536+ ret = mt76_testmode_init_skb(phy->mt76, tx_len, &td->tx_skb, td->addr);
1537 if (ret)
1538 return ret;
1539
developer70180b02023-11-14 17:01:47 +08001540@@ -447,7 +1244,9 @@ mt7915_tm_init(struct mt7915_phy *phy, bool en)
1541 if (!test_bit(MT76_STATE_RUNNING, &phy->mt76->state))
1542 return;
1543
1544- mt7915_mcu_set_sku_en(phy, !en);
1545+ phy->sku_limit_en = !en;
1546+ phy->sku_path_en = !en;
1547+ mt7915_mcu_set_sku_en(phy);
1548
1549 mt7915_tm_mode_ctrl(dev, en);
1550 mt7915_tm_reg_backup_restore(phy);
1551@@ -458,64 +1257,227 @@ mt7915_tm_init(struct mt7915_phy *phy, bool en)
developer6caa5e22022-06-16 13:33:13 +08001552
1553 phy->mt76->test.flag |= MT_TM_FW_RX_COUNT;
1554
1555- if (!en)
1556+ if (!en) {
1557 mt7915_tm_set_tam_arb(phy, en, 0);
1558+
1559+ phy->mt76->test.aid = 0;
1560+ phy->mt76->test.tx_mpdu_len = 0;
1561+ phy->test.bf_en = 0;
1562+ mt7915_tm_set_entry(phy);
1563+ }
1564+}
1565+
1566+static bool
1567+mt7915_tm_check_skb(struct mt7915_phy *phy)
1568+{
1569+ struct mt76_testmode_entry_data *ed;
1570+ struct mt76_wcid *wcid;
1571+
1572+ mt76_tm_for_each_entry(phy->mt76, wcid, ed) {
1573+ struct ieee80211_tx_info *info;
1574+
1575+ if (!ed->tx_skb)
1576+ return false;
1577+
1578+ info = IEEE80211_SKB_CB(ed->tx_skb);
1579+ info->control.vif = phy->monitor_vif;
1580+ }
1581+
1582+ return true;
1583+}
1584+
1585+static int
1586+mt7915_tm_set_ba(struct mt7915_phy *phy)
1587+{
1588+ struct mt7915_dev *dev = phy->dev;
1589+ struct mt76_testmode_data *td = &phy->mt76->test;
1590+ struct mt76_wcid *wcid;
1591+ struct ieee80211_vif *vif = phy->monitor_vif;
1592+ struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
1593+ struct ieee80211_ampdu_params params = { .buf_size = 256 };
1594+
1595+ list_for_each_entry(wcid, &td->tm_entry_list, list) {
1596+ int tid, ret;
1597+
1598+ params.sta = wcid_to_sta(wcid);
1599+ for (tid = 0; tid < 8; tid++) {
1600+ params.tid = tid;
1601+ ret = mt7915_mcu_add_tx_ba(phy->dev, &params, true);
1602+ if (ret)
1603+ return ret;
1604+ }
1605+ }
1606+
1607+ mt76_wr(dev, MT_AGG_AALCR0(mvif->mt76.band_idx, mvif->mt76.wmm_idx),
1608+ 0x01010101);
1609+
1610+ return 0;
1611+}
1612+
1613+static int
1614+mt7915_tm_set_muru_cfg(struct mt7915_phy *phy, struct mt7915_tm_muru *muru)
1615+{
1616+/* #define MURU_SET_MANUAL_CFG 100 */
1617+ struct mt7915_dev *dev = phy->dev;
1618+ struct {
1619+ __le32 cmd;
1620+ struct mt7915_tm_muru muru;
1621+ } __packed req = {
1622+ .cmd = cpu_to_le32(MURU_SET_MANUAL_CFG),
1623+ };
1624+
1625+ memcpy(&req.muru, muru, sizeof(struct mt7915_tm_muru));
1626+
1627+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(MURU_CTRL), &req,
1628+ sizeof(req), false);
1629+}
1630+
1631+static int
1632+mt7915_tm_set_muru_dl(struct mt7915_phy *phy)
1633+{
1634+ struct mt76_testmode_data *td = &phy->mt76->test;
1635+ struct mt76_testmode_entry_data *ed;
1636+ struct mt76_wcid *wcid;
1637+ struct cfg80211_chan_def *chandef = &phy->mt76->chandef;
1638+ struct ieee80211_vif *vif = phy->monitor_vif;
1639+ struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
1640+ struct mt7915_tm_muru muru = {};
1641+ struct mt7915_tm_muru_comm *comm = &muru.comm;
1642+ struct mt7915_tm_muru_dl *dl = &muru.dl;
1643+ int i;
1644+
1645+ comm->ppdu_format = MURU_PPDU_HE_MU;
1646+ comm->band = mvif->mt76.band_idx;
1647+ comm->wmm_idx = mvif->mt76.wmm_idx;
1648+ comm->spe_idx = phy->test.spe_idx;
1649+
1650+ dl->bw = mt7915_tm_chan_bw(chandef->width);
developer692ed9b2023-06-19 12:03:50 +08001651+ dl->gi = td->tx_rate_sgi;
developer6caa5e22022-06-16 13:33:13 +08001652+ dl->ltf = td->tx_ltf;
1653+ dl->tx_mode = MT_PHY_TYPE_HE_MU;
1654+
1655+ for (i = 0; i < sizeof(dl->ru); i++)
1656+ dl->ru[i] = 0x71;
1657+
1658+ mt76_tm_for_each_entry(phy->mt76, wcid, ed) {
1659+ struct mt7915_tm_muru_dl_usr *dl_usr = &dl->usr[dl->user_num];
1660+
1661+ dl_usr->wlan_idx = cpu_to_le16(wcid->idx);
1662+ dl_usr->ru_alloc_seg = ed->aid < 8 ? 0 : 1;
1663+ dl_usr->ru_idx = ed->ru_idx;
1664+ dl_usr->mcs = ed->tx_rate_idx;
1665+ dl_usr->nss = ed->tx_rate_nss - 1;
1666+ dl_usr->ldpc = ed->tx_rate_ldpc;
1667+ dl->ru[dl->user_num] = ed->ru_alloc;
1668+
1669+ dl->user_num++;
1670+ }
1671+
developer1475cf22023-05-05 13:45:43 +08001672+ muru.cfg_comm = cpu_to_le32(MURU_COMM_SET_TM);
developer6caa5e22022-06-16 13:33:13 +08001673+ muru.cfg_dl = cpu_to_le32(MURU_DL_SET);
1674+
1675+ return mt7915_tm_set_muru_cfg(phy, &muru);
1676+}
1677+
1678+static int
1679+mt7915_tm_set_muru_pkt_cnt(struct mt7915_phy *phy, bool enable, u32 tx_count)
1680+{
1681+#define MURU_SET_TX_PKT_CNT 105
1682+#define MURU_SET_TX_EN 106
1683+ struct mt7915_dev *dev = phy->dev;
1684+ struct {
1685+ __le32 cmd;
1686+ u8 band;
1687+ u8 enable;
1688+ u8 _rsv[2];
1689+ __le32 tx_count;
1690+ } __packed req = {
developer17bb0a82022-12-13 15:52:04 +08001691+ .band = phy->mt76->band_idx,
developer6caa5e22022-06-16 13:33:13 +08001692+ .enable = enable,
1693+ .tx_count = enable ? cpu_to_le32(tx_count) : 0,
1694+ };
1695+ int ret;
1696+
1697+ req.cmd = enable ? cpu_to_le32(MURU_SET_TX_PKT_CNT) :
1698+ cpu_to_le32(MURU_SET_TX_EN);
1699+
1700+ ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(MURU_CTRL), &req,
1701+ sizeof(req), false);
1702+ if (ret)
1703+ return ret;
1704+
1705+ req.cmd = enable ? cpu_to_le32(MURU_SET_TX_EN) :
1706+ cpu_to_le32(MURU_SET_TX_PKT_CNT);
1707+
1708+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(MURU_CTRL), &req,
1709+ sizeof(req), false);
1710 }
1711
1712 static void
1713-mt7915_tm_update_channel(struct mt7915_phy *phy)
1714+mt7915_tm_tx_frames_mu(struct mt7915_phy *phy, bool enable)
1715 {
1716- mutex_unlock(&phy->dev->mt76.mutex);
1717- mt7915_set_channel(phy);
1718- mutex_lock(&phy->dev->mt76.mutex);
1719+ struct mt76_testmode_data *td = &phy->mt76->test;
1720
1721- mt7915_mcu_set_chan_info(phy, MCU_EXT_CMD(SET_RX_PATH));
1722+ if (enable) {
1723+ struct mt7915_dev *dev = phy->dev;
1724+
1725+ mt7915_tm_set_ba(phy);
1726+ mt7915_tm_set_muru_dl(phy);
1727+ mt76_rr(dev, MT_MIB_DR8(phy != &dev->phy));
1728+ } else {
1729+ /* set to zero for counting real tx free num */
1730+ td->tx_done = 0;
1731+ }
1732+
1733+ mt7915_tm_set_muru_pkt_cnt(phy, enable, td->tx_count);
1734+ usleep_range(100000, 200000);
1735 }
1736
1737 static void
developer072c5612022-07-15 18:30:03 +08001738 mt7915_tm_set_tx_frames(struct mt7915_phy *phy, bool en)
1739 {
developer6caa5e22022-06-16 13:33:13 +08001740 struct mt76_testmode_data *td = &phy->mt76->test;
1741- struct mt7915_dev *dev = phy->dev;
1742- struct ieee80211_tx_info *info;
1743- u8 duty_cycle = td->tx_duty_cycle;
1744- u32 tx_time = td->tx_time;
1745- u32 ipg = td->tx_ipg;
1746
1747 mt7915_tm_set_trx(phy, TM_MAC_RX_RXV, false);
1748- mt7915_tm_clean_hwq(phy, dev->mt76.global_wcid.idx);
1749+ mt7915_tm_set_trx(phy, TM_MAC_TX, false);
1750
1751 if (en) {
1752- mt7915_tm_update_channel(phy);
1753+ u32 tx_time = td->tx_time, ipg = td->tx_ipg;
1754+ u8 duty_cycle = td->tx_duty_cycle;
1755+
1756+ if (!phy->test.bf_en)
1757+ mt7915_tm_update_channel(phy);
1758
developer072c5612022-07-15 18:30:03 +08001759 if (td->tx_spe_idx)
developer6caa5e22022-06-16 13:33:13 +08001760 phy->test.spe_idx = td->tx_spe_idx;
developer072c5612022-07-15 18:30:03 +08001761 else
1762 phy->test.spe_idx = mt76_connac_spe_idx(td->tx_antenna_mask);
developer6caa5e22022-06-16 13:33:13 +08001763- }
1764
1765- mt7915_tm_set_tam_arb(phy, en,
1766- td->tx_rate_mode == MT76_TM_TX_MODE_HE_MU);
1767+ /* if all three params are set, duty_cycle will be ignored */
1768+ if (duty_cycle && tx_time && !ipg) {
1769+ ipg = tx_time * 100 / duty_cycle - tx_time;
1770+ } else if (duty_cycle && !tx_time && ipg) {
1771+ if (duty_cycle < 100)
1772+ tx_time = duty_cycle * ipg / (100 - duty_cycle);
1773+ }
1774
1775- /* if all three params are set, duty_cycle will be ignored */
1776- if (duty_cycle && tx_time && !ipg) {
1777- ipg = tx_time * 100 / duty_cycle - tx_time;
1778- } else if (duty_cycle && !tx_time && ipg) {
1779- if (duty_cycle < 100)
1780- tx_time = duty_cycle * ipg / (100 - duty_cycle);
1781- }
1782+ mt7915_tm_set_ipg_params(phy, ipg, td->tx_rate_mode);
1783+ mt7915_tm_set_tx_len(phy, tx_time);
1784
1785- mt7915_tm_set_ipg_params(phy, ipg, td->tx_rate_mode);
1786- mt7915_tm_set_tx_len(phy, tx_time);
1787+ if (ipg)
1788+ td->tx_queued_limit = MT76_TM_TIMEOUT * 1000000 / ipg / 2;
1789
1790- if (ipg)
1791- td->tx_queued_limit = MT76_TM_TIMEOUT * 1000000 / ipg / 2;
1792+ if (!mt7915_tm_check_skb(phy))
1793+ return;
1794+ } else {
1795+ mt7915_tm_clean_hwq(phy);
1796+ }
1797
1798- if (!en || !td->tx_skb)
1799- return;
1800+ mt7915_tm_set_tam_arb(phy, en,
1801+ td->tx_rate_mode == MT76_TM_TX_MODE_HE_MU);
1802
1803- info = IEEE80211_SKB_CB(td->tx_skb);
1804- info->control.vif = phy->monitor_vif;
1805+ if (td->tx_rate_mode == MT76_TM_TX_MODE_HE_MU)
1806+ mt7915_tm_tx_frames_mu(phy, en);
1807
1808 mt7915_tm_set_trx(phy, TM_MAC_TX, en);
1809 }
developer70180b02023-11-14 17:01:47 +08001810@@ -544,10 +1506,6 @@ mt7915_tm_get_rx_stats(struct mt7915_phy *phy, bool clear)
developer6caa5e22022-06-16 13:33:13 +08001811 return ret;
1812
1813 rs_band = (struct mt7915_tm_rx_stat_band *)skb->data;
1814- /* pr_info("mdrdy_cnt = %d\n", le32_to_cpu(rs_band->mdrdy_cnt)); */
1815- /* pr_info("fcs_err = %d\n", le16_to_cpu(rs_band->fcs_err)); */
1816- /* pr_info("len_mismatch = %d\n", le16_to_cpu(rs_band->len_mismatch)); */
1817- /* pr_info("fcs_ok = %d\n", le16_to_cpu(rs_band->fcs_succ)); */
1818
1819 if (!clear) {
developerf7a3ca32022-09-01 14:44:55 +08001820 enum mt76_rxq_id q = req.band ? MT_RXQ_BAND1 : MT_RXQ_MAIN;
developer70180b02023-11-14 17:01:47 +08001821@@ -562,13 +1520,61 @@ mt7915_tm_get_rx_stats(struct mt7915_phy *phy, bool clear)
developer6caa5e22022-06-16 13:33:13 +08001822 return 0;
1823 }
1824
1825+static int
1826+mt7915_tm_set_rx_user_idx(struct mt7915_phy *phy, u8 aid)
1827+{
1828+ struct mt7915_dev *dev = phy->dev;
1829+ struct mt76_wcid *wcid = NULL;
1830+ struct mt76_testmode_entry_data *ed;
1831+ struct {
1832+ u8 band;
1833+ u8 _rsv;
1834+ __le16 wlan_idx;
1835+ } __packed req = {
developer17bb0a82022-12-13 15:52:04 +08001836+ .band = phy->mt76->band_idx,
developer6caa5e22022-06-16 13:33:13 +08001837+ };
1838+
1839+ mt76_tm_for_each_entry(phy->mt76, wcid, ed)
1840+ if (ed->aid == aid)
1841+ break;
1842+
1843+ if (!wcid)
1844+ return -EINVAL;
1845+
1846+ req.wlan_idx = cpu_to_le16(wcid->idx);
1847+
1848+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(RX_STAT_USER_CTRL),
1849+ &req, sizeof(req), false);
1850+}
1851+
1852+static int
1853+mt7915_tm_set_muru_aid(struct mt7915_phy *phy, u16 aid)
1854+{
1855+ struct mt7915_dev *dev = phy->dev;
1856+ struct mt7915_tm_cmd req = {
1857+ .testmode_en = 1,
1858+ .param_idx = MCU_ATE_SET_MU_RX_AID,
developer17bb0a82022-12-13 15:52:04 +08001859+ .param.rx_aid.band = cpu_to_le32(phy->mt76->band_idx),
developer6caa5e22022-06-16 13:33:13 +08001860+ .param.rx_aid.aid = cpu_to_le16(aid),
1861+ };
1862+
1863+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(ATE_CTRL), &req,
1864+ sizeof(req), false);
1865+}
1866+
1867 static void
1868 mt7915_tm_set_rx_frames(struct mt7915_phy *phy, bool en)
1869 {
1870+ struct mt76_testmode_data *td = &phy->mt76->test;
1871+
1872+ mt7915_tm_set_trx(phy, TM_MAC_TX, false);
1873 mt7915_tm_set_trx(phy, TM_MAC_RX_RXV, false);
1874
1875 if (en) {
1876- mt7915_tm_update_channel(phy);
1877+ if (!phy->test.bf_en)
1878+ mt7915_tm_update_channel(phy);
1879+ if (td->aid)
1880+ mt7915_tm_set_rx_user_idx(phy, td->aid);
1881
1882 /* read-clear */
1883 mt7915_tm_get_rx_stats(phy, true);
developer70180b02023-11-14 17:01:47 +08001884@@ -576,9 +1582,12 @@ mt7915_tm_set_rx_frames(struct mt7915_phy *phy, bool en)
developer6caa5e22022-06-16 13:33:13 +08001885 /* clear fw count */
1886 mt7915_tm_set_phy_count(phy, 0);
1887 mt7915_tm_set_phy_count(phy, 1);
1888-
1889- mt7915_tm_set_trx(phy, TM_MAC_RX_RXV, en);
1890 }
1891+
1892+ if (td->tx_rate_mode == MT76_TM_TX_MODE_HE_MU)
1893+ mt7915_tm_set_muru_aid(phy, en ? td->aid : 0xf800);
1894+
1895+ mt7915_tm_set_trx(phy, TM_MAC_RX_RXV, en);
1896 }
1897
1898 static int
developer70180b02023-11-14 17:01:47 +08001899@@ -617,34 +1626,7 @@ mt7915_tm_set_tx_cont(struct mt7915_phy *phy, bool en)
developer6caa5e22022-06-16 13:33:13 +08001900 tx_cont->tx_ant = td->tx_antenna_mask;
developer17bb0a82022-12-13 15:52:04 +08001901 tx_cont->band = band;
developer3609d782022-11-29 18:07:22 +08001902
developer6caa5e22022-06-16 13:33:13 +08001903- switch (chandef->width) {
1904- case NL80211_CHAN_WIDTH_40:
1905- tx_cont->bw = CMD_CBW_40MHZ;
1906- break;
1907- case NL80211_CHAN_WIDTH_80:
1908- tx_cont->bw = CMD_CBW_80MHZ;
1909- break;
1910- case NL80211_CHAN_WIDTH_80P80:
1911- tx_cont->bw = CMD_CBW_8080MHZ;
1912- break;
1913- case NL80211_CHAN_WIDTH_160:
1914- tx_cont->bw = CMD_CBW_160MHZ;
1915- break;
1916- case NL80211_CHAN_WIDTH_5:
1917- tx_cont->bw = CMD_CBW_5MHZ;
1918- break;
1919- case NL80211_CHAN_WIDTH_10:
1920- tx_cont->bw = CMD_CBW_10MHZ;
1921- break;
1922- case NL80211_CHAN_WIDTH_20:
1923- tx_cont->bw = CMD_CBW_20MHZ;
1924- break;
1925- case NL80211_CHAN_WIDTH_20_NOHT:
1926- tx_cont->bw = CMD_CBW_20MHZ;
1927- break;
1928- default:
1929- return -EINVAL;
1930- }
1931+ tx_cont->bw = mt7915_tm_chan_bw(chandef->width);
1932
1933 if (!en) {
developer17bb0a82022-12-13 15:52:04 +08001934 req.op.rf.param.func_data = cpu_to_le32(band);
developer70180b02023-11-14 17:01:47 +08001935@@ -728,6 +1710,18 @@ mt7915_tm_update_params(struct mt7915_phy *phy, u32 changed)
developer6caa5e22022-06-16 13:33:13 +08001936 mt7915_tm_set_freq_offset(phy, en, en ? td->freq_offset : 0);
1937 if (changed & BIT(TM_CHANGED_TXPOWER))
1938 mt7915_tm_set_tx_power(phy);
developerbd9fa1e2023-10-16 11:04:00 +08001939+ if (changed & BIT(TM_CHANGED_SKU_EN)) {
developer70180b02023-11-14 17:01:47 +08001940+ phy->sku_limit_en = td->sku_en;
1941+ phy->sku_path_en = td->sku_en;
1942+ mt7915_mcu_set_sku_en(phy);
developerbd9fa1e2023-10-16 11:04:00 +08001943+ mt7915_mcu_set_txpower_sku(phy);
1944+ }
developer6caa5e22022-06-16 13:33:13 +08001945+ if (changed & BIT(TM_CHANGED_AID))
1946+ mt7915_tm_set_entry(phy);
1947+ if (changed & BIT(TM_CHANGED_CFG))
1948+ mt7915_tm_set_cfg(phy);
1949+ if (changed & BIT(TM_CHANGED_TXBF_ACT))
1950+ mt7915_tm_set_txbf(phy);
1951 }
1952
1953 static int
developer70180b02023-11-14 17:01:47 +08001954@@ -737,6 +1731,11 @@ mt7915_tm_set_state(struct mt76_phy *mphy, enum mt76_testmode_state state)
developerbb6ddff2023-03-08 17:22:32 +08001955 struct mt7915_phy *phy = mphy->priv;
1956 enum mt76_testmode_state prev_state = td->state;
1957
1958+ if (!phy->monitor_vif) {
1959+ dev_err(phy->dev->mt76.dev, "Please make sure monitor interface is up\n");
1960+ return -ENOTCONN;
1961+ }
1962+
1963 mphy->test.state = state;
1964
1965 if (prev_state == MT76_TM_STATE_TX_FRAMES ||
developer70180b02023-11-14 17:01:47 +08001966@@ -757,7 +1756,7 @@ mt7915_tm_set_state(struct mt76_phy *mphy, enum mt76_testmode_state state)
developer692ed9b2023-06-19 12:03:50 +08001967 (state == MT76_TM_STATE_OFF &&
1968 prev_state == MT76_TM_STATE_IDLE)) {
1969 u32 changed = 0;
1970- int i;
1971+ int i, ret;
1972
1973 for (i = 0; i < ARRAY_SIZE(tm_change_map); i++) {
1974 u16 cur = tm_change_map[i];
developer70180b02023-11-14 17:01:47 +08001975@@ -766,6 +1765,10 @@ mt7915_tm_set_state(struct mt76_phy *mphy, enum mt76_testmode_state state)
developer692ed9b2023-06-19 12:03:50 +08001976 changed |= BIT(i);
1977 }
1978
1979+ ret = mt7915_tm_check_antenna(phy);
1980+ if (ret)
1981+ return ret;
1982+
1983 mt7915_tm_update_params(phy, changed);
1984 }
1985
developer70180b02023-11-14 17:01:47 +08001986@@ -778,10 +1781,8 @@ mt7915_tm_set_params(struct mt76_phy *mphy, struct nlattr **tb,
developer692ed9b2023-06-19 12:03:50 +08001987 {
1988 struct mt76_testmode_data *td = &mphy->test;
1989 struct mt7915_phy *phy = mphy->priv;
1990- struct mt7915_dev *dev = phy->dev;
1991- u32 chainmask = mphy->chainmask, changed = 0;
1992- bool ext_phy = phy != &dev->phy;
1993- int i;
1994+ u32 changed = 0;
1995+ int i, ret;
1996
1997 BUILD_BUG_ON(NUM_TM_CHANGED >= 32);
1998
developer70180b02023-11-14 17:01:47 +08001999@@ -789,9 +1790,9 @@ mt7915_tm_set_params(struct mt76_phy *mphy, struct nlattr **tb,
developer692ed9b2023-06-19 12:03:50 +08002000 td->state == MT76_TM_STATE_OFF)
2001 return 0;
2002
2003- chainmask = ext_phy ? chainmask >> dev->chainshift : chainmask;
2004- if (td->tx_antenna_mask > chainmask)
2005- return -EINVAL;
2006+ ret = mt7915_tm_check_antenna(phy);
2007+ if (ret)
2008+ return ret;
2009
2010 for (i = 0; i < ARRAY_SIZE(tm_change_map); i++) {
2011 if (tb[tm_change_map[i]])
developer70180b02023-11-14 17:01:47 +08002012@@ -807,6 +1808,7 @@ static int
developer6caa5e22022-06-16 13:33:13 +08002013 mt7915_tm_dump_stats(struct mt76_phy *mphy, struct sk_buff *msg)
2014 {
2015 struct mt7915_phy *phy = mphy->priv;
2016+ struct mt7915_dev *dev = phy->dev;
2017 void *rx, *rssi;
2018 int i;
2019
developer70180b02023-11-14 17:01:47 +08002020@@ -827,6 +1829,16 @@ mt7915_tm_dump_stats(struct mt76_phy *mphy, struct sk_buff *msg)
developerbd9fa1e2023-10-16 11:04:00 +08002021
2022 nla_nest_end(msg, rssi);
2023
2024+ rssi = nla_nest_start(msg, MT76_TM_RX_ATTR_RSSI);
2025+ if (!rssi)
2026+ return -ENOMEM;
2027+
2028+ for (i = 0; i < ARRAY_SIZE(phy->test.last_rssi); i++)
2029+ if (nla_put_s8(msg, i, phy->test.last_rssi[i]))
2030+ return -ENOMEM;
2031+
2032+ nla_nest_end(msg, rssi);
2033+
2034 rssi = nla_nest_start(msg, MT76_TM_RX_ATTR_IB_RSSI);
2035 if (!rssi)
2036 return -ENOMEM;
developer70180b02023-11-14 17:01:47 +08002037@@ -852,11 +1864,75 @@ mt7915_tm_dump_stats(struct mt76_phy *mphy, struct sk_buff *msg)
developer6caa5e22022-06-16 13:33:13 +08002038
2039 nla_nest_end(msg, rx);
2040
2041+ if (mphy->test.tx_rate_mode == MT76_TM_TX_MODE_HE_MU)
2042+ mphy->test.tx_done += mt76_rr(dev, MT_MIB_DR8(phy != &dev->phy));
2043+
2044 return mt7915_tm_get_rx_stats(phy, false);
2045 }
2046
2047+static int
2048+mt7915_tm_write_back_to_efuse(struct mt7915_dev *dev)
2049+{
2050+ struct mt7915_mcu_eeprom_info req = {};
developerc9333e12023-04-06 18:07:42 +08002051+ u8 read_buf[MT76_TM_EEPROM_BLOCK_SIZE], *eeprom = dev->mt76.eeprom.data;
developer6caa5e22022-06-16 13:33:13 +08002052+ int i, ret = -EINVAL;
2053+
2054+ /* prevent from damaging chip id in efuse */
2055+ if (mt76_chip(&dev->mt76) != get_unaligned_le16(eeprom))
2056+ goto out;
2057+
2058+ for (i = 0; i < mt7915_eeprom_size(dev); i += MT76_TM_EEPROM_BLOCK_SIZE) {
2059+ req.addr = cpu_to_le32(i);
developerc9333e12023-04-06 18:07:42 +08002060+ memcpy(req.data, eeprom + i, MT76_TM_EEPROM_BLOCK_SIZE);
2061+
2062+ ret = mt7915_mcu_get_eeprom(dev, i, read_buf);
2063+ if (ret < 0)
2064+ return ret;
2065+
2066+ if (!memcmp(req.data, read_buf, MT76_TM_EEPROM_BLOCK_SIZE))
2067+ continue;
developer6caa5e22022-06-16 13:33:13 +08002068+
2069+ ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(EFUSE_ACCESS),
2070+ &req, sizeof(req), true);
2071+ if (ret)
2072+ return ret;
2073+ }
2074+
2075+out:
2076+ return ret;
2077+}
2078+
2079+static int
2080+mt7915_tm_set_eeprom(struct mt76_phy *mphy, u32 offset, u8 *val, u8 action)
2081+{
2082+ struct mt7915_phy *phy = mphy->priv;
2083+ struct mt7915_dev *dev = phy->dev;
2084+ u8 *eeprom = dev->mt76.eeprom.data;
2085+ int ret = 0;
2086+
2087+ if (offset >= mt7915_eeprom_size(dev))
2088+ return -EINVAL;
2089+
2090+ switch (action) {
2091+ case MT76_TM_EEPROM_ACTION_UPDATE_DATA:
2092+ memcpy(eeprom + offset, val, MT76_TM_EEPROM_BLOCK_SIZE);
2093+ break;
2094+ case MT76_TM_EEPROM_ACTION_UPDATE_BUFFER_MODE:
2095+ ret = mt7915_mcu_set_eeprom(dev, true);
2096+ break;
2097+ case MT76_TM_EEPROM_ACTION_WRITE_TO_EFUSE:
2098+ ret = mt7915_tm_write_back_to_efuse(dev);
2099+ break;
2100+ default:
2101+ break;
2102+ }
2103+
2104+ return ret;
2105+}
2106+
2107 const struct mt76_testmode_ops mt7915_testmode_ops = {
2108 .set_state = mt7915_tm_set_state,
2109 .set_params = mt7915_tm_set_params,
2110 .dump_stats = mt7915_tm_dump_stats,
2111+ .set_eeprom = mt7915_tm_set_eeprom,
2112 };
2113diff --git a/mt7915/testmode.h b/mt7915/testmode.h
developer05f3b2b2024-08-19 19:17:34 +08002114index a1c54c89..eb0e0432 100644
developer6caa5e22022-06-16 13:33:13 +08002115--- a/mt7915/testmode.h
2116+++ b/mt7915/testmode.h
2117@@ -4,6 +4,8 @@
2118 #ifndef __MT7915_TESTMODE_H
2119 #define __MT7915_TESTMODE_H
2120
2121+#include "mcu.h"
2122+
2123 struct mt7915_tm_trx {
2124 u8 type;
2125 u8 enable;
2126@@ -39,6 +41,11 @@ struct mt7915_tm_cfg {
2127 u8 _rsv[2];
2128 };
2129
2130+struct mt7915_tm_mu_rx_aid {
2131+ __le32 band;
2132+ __le16 aid;
2133+};
2134+
2135 struct mt7915_tm_cmd {
2136 u8 testmode_en;
2137 u8 param_idx;
2138@@ -50,6 +57,7 @@ struct mt7915_tm_cmd {
2139 struct mt7915_tm_slot_time slot;
2140 struct mt7915_tm_clean_txq clean;
2141 struct mt7915_tm_cfg cfg;
2142+ struct mt7915_tm_mu_rx_aid rx_aid;
2143 u8 test[72];
2144 } param;
2145 } __packed;
2146@@ -109,6 +117,16 @@ enum {
2147 TAM_ARB_OP_MODE_FORCE_SU = 5,
2148 };
2149
2150+enum {
2151+ TM_CBW_20MHZ,
2152+ TM_CBW_40MHZ,
2153+ TM_CBW_80MHZ,
2154+ TM_CBW_10MHZ,
2155+ TM_CBW_5MHZ,
2156+ TM_CBW_160MHZ,
2157+ TM_CBW_8080MHZ,
2158+};
2159+
2160 struct mt7915_tm_rx_stat_band {
2161 u8 category;
2162
2163@@ -130,4 +148,264 @@ struct mt7915_tm_rx_stat_band {
2164 __le16 mdrdy_cnt_ofdm;
2165 };
2166
2167+struct mt7915_tm_muru_comm {
2168+ u8 ppdu_format;
2169+ u8 sch_type;
2170+ u8 band;
2171+ u8 wmm_idx;
2172+ u8 spe_idx;
2173+ u8 proc_type;
2174+};
2175+
2176+struct mt7915_tm_muru_dl_usr {
2177+ __le16 wlan_idx;
2178+ u8 ru_alloc_seg;
2179+ u8 ru_idx;
2180+ u8 ldpc;
2181+ u8 nss;
2182+ u8 mcs;
2183+ u8 mu_group_idx;
2184+ u8 vht_groud_id;
2185+ u8 vht_up;
2186+ u8 he_start_stream;
2187+ u8 he_mu_spatial;
2188+ u8 ack_policy;
2189+ __le16 tx_power_alpha;
2190+};
2191+
2192+struct mt7915_tm_muru_dl {
2193+ u8 user_num;
2194+ u8 tx_mode;
2195+ u8 bw;
2196+ u8 gi;
2197+ u8 ltf;
2198+ /* sigB */
2199+ u8 mcs;
2200+ u8 dcm;
2201+ u8 cmprs;
2202+
2203+ u8 tx_power;
2204+ u8 ru[8];
2205+ u8 c26[2];
2206+ u8 ack_policy;
2207+
2208+ struct mt7915_tm_muru_dl_usr usr[16];
2209+};
2210+
2211+struct mt7915_tm_muru_ul_usr {
2212+ __le16 wlan_idx;
2213+ u8 ru_alloc;
2214+ u8 ru_idx;
2215+ u8 ldpc;
2216+ u8 nss;
2217+ u8 mcs;
2218+ u8 target_rssi;
2219+ __le32 trig_pkt_size;
2220+};
2221+
2222+struct mt7915_tm_muru_ul {
2223+ u8 user_num;
2224+
2225+ /* UL TX */
2226+ u8 trig_type;
2227+ __le16 trig_cnt;
2228+ __le16 trig_intv;
2229+ u8 bw;
2230+ u8 gi_ltf;
2231+ __le16 ul_len;
2232+ u8 pad;
2233+ u8 trig_ta[ETH_ALEN];
2234+ u8 ru[8];
2235+ u8 c26[2];
2236+
2237+ struct mt7915_tm_muru_ul_usr usr[16];
2238+ /* HE TB RX Debug */
2239+ __le32 rx_hetb_nonsf_en_bitmap;
2240+ __le32 rx_hetb_cfg[2];
2241+
2242+ /* DL TX */
2243+ u8 ba_type;
2244+};
2245+
2246+struct mt7915_tm_muru {
2247+ __le32 cfg_comm;
2248+ __le32 cfg_dl;
2249+ __le32 cfg_ul;
2250+
2251+ struct mt7915_tm_muru_comm comm;
2252+ struct mt7915_tm_muru_dl dl;
2253+ struct mt7915_tm_muru_ul ul;
2254+};
2255+
2256+#define MURU_PPDU_HE_MU BIT(3)
2257+
2258+/* Common Config */
2259+/* #define MURU_COMM_PPDU_FMT BIT(0) */
2260+/* #define MURU_COMM_SCH_TYPE BIT(1) */
developer692ed9b2023-06-19 12:03:50 +08002261+/* #define MURU_COMM_BAND BIT(2) */
2262+/* #define MURU_COMM_WMM BIT(3) */
developer6caa5e22022-06-16 13:33:13 +08002263+/* #define MURU_COMM_SPE_IDX BIT(4) */
2264+/* #define MURU_COMM_PROC_TYPE BIT(5) */
2265+/* #define MURU_COMM_SET (MURU_COMM_PPDU_FMT | MURU_COMM_BAND | \ */
developer692ed9b2023-06-19 12:03:50 +08002266+/* MURU_COMM_WMM | MURU_COMM_SPE_IDX) */
developer6caa5e22022-06-16 13:33:13 +08002267+/* DL Config */
2268+#define MURU_DL_BW BIT(0)
2269+#define MURU_DL_GI BIT(1)
2270+#define MURU_DL_TX_MODE BIT(2)
2271+#define MURU_DL_TONE_PLAN BIT(3)
2272+#define MURU_DL_USER_CNT BIT(4)
2273+#define MURU_DL_LTF BIT(5)
2274+#define MURU_DL_SIGB_MCS BIT(6)
2275+#define MURU_DL_SIGB_DCM BIT(7)
2276+#define MURU_DL_SIGB_CMPRS BIT(8)
2277+#define MURU_DL_ACK_POLICY BIT(9)
2278+#define MURU_DL_TXPOWER BIT(10)
2279+/* DL Per User Config */
2280+#define MURU_DL_USER_WLAN_ID BIT(16)
2281+#define MURU_DL_USER_COD BIT(17)
2282+#define MURU_DL_USER_MCS BIT(18)
2283+#define MURU_DL_USER_NSS BIT(19)
2284+#define MURU_DL_USER_RU_ALLOC BIT(20)
2285+#define MURU_DL_USER_MUMIMO_GRP BIT(21)
2286+#define MURU_DL_USER_MUMIMO_VHT BIT(22)
2287+#define MURU_DL_USER_ACK_POLICY BIT(23)
2288+#define MURU_DL_USER_MUMIMO_HE BIT(24)
2289+#define MURU_DL_USER_PWR_ALPHA BIT(25)
2290+#define MURU_DL_SET (GENMASK(7, 0) | GENMASK(20, 16) | BIT(25))
2291+
2292+#define MAX_PHASE_GROUP_NUM 9
2293+
2294+struct mt7915_tm_txbf_phase {
2295+ u8 status;
2296+ struct {
2297+ u8 r0_uh;
2298+ u8 r0_h;
2299+ u8 r0_m;
2300+ u8 r0_l;
2301+ u8 r0_ul;
2302+ u8 r1_uh;
2303+ u8 r1_h;
2304+ u8 r1_m;
2305+ u8 r1_l;
2306+ u8 r1_ul;
2307+ u8 r2_uh;
2308+ u8 r2_h;
2309+ u8 r2_m;
2310+ u8 r2_l;
2311+ u8 r2_ul;
2312+ u8 r3_uh;
2313+ u8 r3_h;
2314+ u8 r3_m;
2315+ u8 r3_l;
2316+ u8 r3_ul;
2317+ u8 r2_uh_sx2;
2318+ u8 r2_h_sx2;
2319+ u8 r2_m_sx2;
2320+ u8 r2_l_sx2;
2321+ u8 r2_ul_sx2;
2322+ u8 r3_uh_sx2;
2323+ u8 r3_h_sx2;
2324+ u8 r3_m_sx2;
2325+ u8 r3_l_sx2;
2326+ u8 r3_ul_sx2;
2327+ u8 m_t0_h;
2328+ u8 m_t1_h;
2329+ u8 m_t2_h;
2330+ u8 m_t2_h_sx2;
2331+ u8 r0_reserved;
2332+ u8 r1_reserved;
2333+ u8 r2_reserved;
2334+ u8 r3_reserved;
2335+ u8 r2_sx2_reserved;
2336+ u8 r3_sx2_reserved;
2337+ } phase;
2338+};
2339+
2340+struct mt7915_tm_pfmu_tag1 {
2341+ __le32 pfmu_idx:10;
2342+ __le32 ebf:1;
2343+ __le32 data_bw:2;
2344+ __le32 lm:2;
2345+ __le32 is_mu:1;
2346+ __le32 nr:3, nc:3;
2347+ __le32 codebook:2;
2348+ __le32 ngroup:2;
2349+ __le32 _rsv:2;
2350+ __le32 invalid_prof:1;
2351+ __le32 rmsd:3;
2352+
2353+ __le32 col_id1:6, row_id1:10;
2354+ __le32 col_id2:6, row_id2:10;
2355+ __le32 col_id3:6, row_id3:10;
2356+ __le32 col_id4:6, row_id4:10;
2357+
2358+ __le32 ru_start_id:7;
2359+ __le32 _rsv1:1;
2360+ __le32 ru_end_id:7;
2361+ __le32 _rsv2:1;
2362+ __le32 mob_cal_en:1;
2363+ __le32 _rsv3:15;
2364+
2365+ __le32 snr_sts0:8, snr_sts1:8, snr_sts2:8, snr_sts3:8;
2366+ __le32 snr_sts4:8, snr_sts5:8, snr_sts6:8, snr_sts7:8;
2367+
2368+ __le32 _rsv4;
2369+} __packed;
2370+
2371+struct mt7915_tm_pfmu_tag2 {
2372+ __le32 smart_ant:24;
2373+ __le32 se_idx:5;
2374+ __le32 _rsv:3;
2375+
2376+ __le32 _rsv1:8;
2377+ __le32 rmsd_thres:3;
2378+ __le32 _rsv2:5;
2379+ __le32 ibf_timeout:8;
2380+ __le32 _rsv3:8;
2381+
2382+ __le32 _rsv4:16;
2383+ __le32 ibf_data_bw:2;
2384+ __le32 ibf_nc:3;
2385+ __le32 ibf_nr:3;
2386+ __le32 ibf_ru:8;
2387+
2388+ __le32 mob_delta_t:8;
2389+ __le32 mob_lq_result:7;
2390+ __le32 _rsv5:1;
2391+ __le32 _rsv6:16;
2392+
2393+ __le32 _rsv7;
2394+} __packed;
2395+
2396+struct mt7915_tm_pfmu_tag {
2397+ struct mt7915_tm_pfmu_tag1 t1;
2398+ struct mt7915_tm_pfmu_tag2 t2;
2399+};
2400+
2401+struct mt7915_tm_pfmu_data {
2402+ __le16 subc_idx;
2403+ __le16 phi11;
2404+ __le16 phi21;
2405+ __le16 phi31;
2406+};
2407+
2408+struct mt7915_tm_ibf_cal_info {
2409+ u8 format_id;
2410+ u8 group_l_m_n;
2411+ u8 group;
2412+ bool sx2;
2413+ u8 status;
2414+ u8 cal_type;
2415+ u8 _rsv[2];
2416+ u8 buf[1000];
2417+} __packed;
2418+
2419+enum {
2420+ IBF_PHASE_CAL_UNSPEC,
2421+ IBF_PHASE_CAL_NORMAL,
2422+ IBF_PHASE_CAL_VERIFY,
2423+ IBF_PHASE_CAL_NORMAL_INSTRUMENT,
2424+ IBF_PHASE_CAL_VERIFY_INSTRUMENT,
2425+};
2426+
2427 #endif
2428diff --git a/testmode.c b/testmode.c
developer05f3b2b2024-08-19 19:17:34 +08002429index 9e05b862..75870478 100644
developer6caa5e22022-06-16 13:33:13 +08002430--- a/testmode.c
2431+++ b/testmode.c
developerbd9fa1e2023-10-16 11:04:00 +08002432@@ -8,6 +8,7 @@ const struct nla_policy mt76_tm_policy[NUM_MT76_TM_ATTRS] = {
2433 [MT76_TM_ATTR_RESET] = { .type = NLA_FLAG },
2434 [MT76_TM_ATTR_STATE] = { .type = NLA_U8 },
2435 [MT76_TM_ATTR_TX_COUNT] = { .type = NLA_U32 },
2436+ [MT76_TM_ATTR_SKU_EN] = { .type = NLA_U8 },
2437 [MT76_TM_ATTR_TX_LENGTH] = { .type = NLA_U32 },
2438 [MT76_TM_ATTR_TX_RATE_MODE] = { .type = NLA_U8 },
2439 [MT76_TM_ATTR_TX_RATE_NSS] = { .type = NLA_U8 },
2440@@ -28,28 +29,16 @@ const struct nla_policy mt76_tm_policy[NUM_MT76_TM_ATTRS] = {
developer6caa5e22022-06-16 13:33:13 +08002441 };
2442 EXPORT_SYMBOL_GPL(mt76_tm_policy);
2443
2444-void mt76_testmode_tx_pending(struct mt76_phy *phy)
2445+static void
2446+mt76_testmode_queue_tx(struct mt76_phy *phy, struct mt76_wcid *wcid,
developerf79ad452022-07-12 11:37:54 +08002447+ struct sk_buff *skb, struct mt76_queue *q, int qid,
2448+ u16 limit)
developer6caa5e22022-06-16 13:33:13 +08002449 {
2450 struct mt76_testmode_data *td = &phy->test;
2451 struct mt76_dev *dev = phy->dev;
2452- struct mt76_wcid *wcid = &dev->global_wcid;
2453- struct sk_buff *skb = td->tx_skb;
2454- struct mt76_queue *q;
2455- u16 tx_queued_limit;
2456- int qid;
2457-
2458- if (!skb || !td->tx_pending)
2459- return;
2460+ u16 count = limit;
2461
2462- qid = skb_get_queue_mapping(skb);
2463- q = phy->q_tx[qid];
2464-
2465- tx_queued_limit = td->tx_queued_limit ? td->tx_queued_limit : 1000;
2466-
2467- spin_lock_bh(&q->lock);
2468-
2469- while (td->tx_pending > 0 &&
2470- td->tx_queued - td->tx_done < tx_queued_limit &&
2471+ while (td->tx_pending > 0 && count &&
2472 q->queued < q->ndesc / 2) {
2473 int ret;
2474
developerbd9fa1e2023-10-16 11:04:00 +08002475@@ -58,13 +47,68 @@ void mt76_testmode_tx_pending(struct mt76_phy *phy)
developer6caa5e22022-06-16 13:33:13 +08002476 if (ret < 0)
2477 break;
2478
developer15c355d2023-03-21 17:28:34 +08002479- td->tx_pending--;
developer6caa5e22022-06-16 13:33:13 +08002480+ count--;
developer15c355d2023-03-21 17:28:34 +08002481+
2482+ /* tx_count == UINT_MAX for continuous tx */
2483+ if (td->tx_count != UINT_MAX)
2484+ td->tx_pending--;
developer6caa5e22022-06-16 13:33:13 +08002485 td->tx_queued++;
2486+
2487+ if (td->tx_rate_mode != MT76_TM_TX_MODE_HE_MU)
developer692ed9b2023-06-19 12:03:50 +08002488+ if (td->tx_queued - td->tx_done >= limit)
2489+ break;
developer6caa5e22022-06-16 13:33:13 +08002490 }
2491
2492 dev->queue_ops->kick(dev, q);
2493+}
2494+
2495+void mt76_testmode_tx_pending(struct mt76_phy *phy)
2496+{
2497+ struct mt76_testmode_data *td = &phy->test;
2498+ struct mt76_testmode_entry_data *ed;
2499+ struct mt76_queue *q;
2500+ int qid;
2501+ u16 tx_queued_limit;
2502+ u32 remain;
2503+ bool is_mu;
2504+
2505+ if (!td->tx_pending)
2506+ return;
2507+
2508+ /* tx_queued_limit = td->tx_queued_limit ?: 100; */
2509+ tx_queued_limit = 100;
2510+
2511+ if (!td->aid) {
2512+ qid = skb_get_queue_mapping(td->tx_skb);
2513+ q = phy->q_tx[qid];
2514+ spin_lock_bh(&q->lock);
2515+ mt76_testmode_queue_tx(phy, &phy->dev->global_wcid,
developer692ed9b2023-06-19 12:03:50 +08002516+ td->tx_skb, q, qid, tx_queued_limit);
developer6caa5e22022-06-16 13:33:13 +08002517+ spin_unlock_bh(&q->lock);
2518+
2519+ return;
2520+ }
2521+
2522+ is_mu = td->tx_rate_mode == MT76_TM_TX_MODE_HE_MU;
2523+ ed = mt76_testmode_entry_data(phy, td->cur_entry);
2524+ qid = skb_get_queue_mapping(ed->tx_skb);
2525+ q = phy->q_tx[qid];
2526+
2527+ spin_lock_bh(&q->lock);
2528+
2529+ remain = is_mu ? 1 : (td->tx_pending % td->tx_count) ?: td->tx_count;
2530+ if (remain < tx_queued_limit)
2531+ tx_queued_limit = remain;
2532+
developerf79ad452022-07-12 11:37:54 +08002533+ mt76_testmode_queue_tx(phy, td->cur_entry, ed->tx_skb, q, qid, tx_queued_limit);
developer6caa5e22022-06-16 13:33:13 +08002534+
developer692ed9b2023-06-19 12:03:50 +08002535+ if ((td->tx_count != UINT_MAX && td->tx_pending % td->tx_count == 0) || is_mu)
developer6caa5e22022-06-16 13:33:13 +08002536+ td->cur_entry = list_next_entry(td->cur_entry, list);
2537
2538 spin_unlock_bh(&q->lock);
2539+
2540+ if (is_mu && td->tx_pending)
2541+ mt76_worker_schedule(&phy->dev->tx_worker);
2542 }
2543
2544 static u32
developerbd9fa1e2023-10-16 11:04:00 +08002545@@ -90,15 +134,31 @@ mt76_testmode_max_mpdu_len(struct mt76_phy *phy, u8 tx_rate_mode)
developer6caa5e22022-06-16 13:33:13 +08002546 }
2547
2548 static void
2549-mt76_testmode_free_skb(struct mt76_phy *phy)
2550+mt76_testmode_free_skb(struct sk_buff **tx_skb)
2551+{
2552+ if (!(*tx_skb))
2553+ return;
2554+
2555+ dev_kfree_skb(*tx_skb);
2556+ *tx_skb = NULL;
2557+}
2558+
2559+static void
2560+mt76_testmode_free_skb_all(struct mt76_phy *phy)
2561 {
2562 struct mt76_testmode_data *td = &phy->test;
2563+ struct mt76_testmode_entry_data *ed = &td->ed;
2564+ struct mt76_wcid *wcid;
2565+
2566+ mt76_testmode_free_skb(&ed->tx_skb);
2567
2568- dev_kfree_skb(td->tx_skb);
2569- td->tx_skb = NULL;
2570+ mt76_tm_for_each_entry(phy, wcid, ed)
2571+ mt76_testmode_free_skb(&ed->tx_skb);
2572 }
2573
2574-int mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len)
2575+static int
2576+mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len,
2577+ struct sk_buff **tx_skb, u8 (*addr)[ETH_ALEN])
2578 {
2579 #define MT_TXP_MAX_LEN 4095
2580 u16 fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA |
developerbd9fa1e2023-10-16 11:04:00 +08002581@@ -119,7 +179,8 @@ int mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len)
developer6caa5e22022-06-16 13:33:13 +08002582 nfrags = len / MT_TXP_MAX_LEN;
2583 head_len = nfrags ? MT_TXP_MAX_LEN : len;
2584
2585- if (len > IEEE80211_MAX_FRAME_LEN)
2586+ if (len > IEEE80211_MAX_FRAME_LEN ||
2587+ td->tx_rate_mode == MT76_TM_TX_MODE_HE_MU)
2588 fc |= IEEE80211_STYPE_QOS_DATA;
2589
2590 head = alloc_skb(head_len, GFP_KERNEL);
developerbd9fa1e2023-10-16 11:04:00 +08002591@@ -128,9 +189,9 @@ int mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len)
developer6caa5e22022-06-16 13:33:13 +08002592
developer072c5612022-07-15 18:30:03 +08002593 hdr = __skb_put_zero(head, sizeof(*hdr));
developer6caa5e22022-06-16 13:33:13 +08002594 hdr->frame_control = cpu_to_le16(fc);
2595- memcpy(hdr->addr1, td->addr[0], ETH_ALEN);
2596- memcpy(hdr->addr2, td->addr[1], ETH_ALEN);
2597- memcpy(hdr->addr3, td->addr[2], ETH_ALEN);
2598+ memcpy(hdr->addr1, addr[0], ETH_ALEN);
2599+ memcpy(hdr->addr2, addr[1], ETH_ALEN);
2600+ memcpy(hdr->addr3, addr[2], ETH_ALEN);
2601 skb_set_queue_mapping(head, IEEE80211_AC_BE);
developer072c5612022-07-15 18:30:03 +08002602 get_random_bytes(__skb_put(head, head_len - sizeof(*hdr)),
2603 head_len - sizeof(*hdr));
developerbd9fa1e2023-10-16 11:04:00 +08002604@@ -154,7 +215,7 @@ int mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len)
developer6caa5e22022-06-16 13:33:13 +08002605
2606 frag = alloc_skb(frag_len, GFP_KERNEL);
2607 if (!frag) {
2608- mt76_testmode_free_skb(phy);
2609+ mt76_testmode_free_skb(tx_skb);
2610 dev_kfree_skb(head);
2611 return -ENOMEM;
2612 }
developer1a173672023-12-21 14:49:33 +08002613@@ -167,23 +228,22 @@ int mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len)
developer6caa5e22022-06-16 13:33:13 +08002614 frag_tail = &(*frag_tail)->next;
2615 }
2616
2617- mt76_testmode_free_skb(phy);
2618- td->tx_skb = head;
2619+ mt76_testmode_free_skb(tx_skb);
2620+ *tx_skb = head;
2621
2622 return 0;
2623 }
2624-EXPORT_SYMBOL(mt76_testmode_alloc_skb);
2625
2626-static int
2627-mt76_testmode_tx_init(struct mt76_phy *phy)
2628+int mt76_testmode_init_skb(struct mt76_phy *phy, u32 len,
2629+ struct sk_buff **tx_skb, u8 (*addr)[ETH_ALEN])
2630 {
2631 struct mt76_testmode_data *td = &phy->test;
2632 struct ieee80211_tx_info *info;
developer1a173672023-12-21 14:49:33 +08002633 struct ieee80211_tx_rate *rate;
2634- u8 max_nss = hweight8(phy->antenna_mask);
2635+ u8 max_nss = hweight8(phy->chainmask);
developer6caa5e22022-06-16 13:33:13 +08002636 int ret;
2637
2638- ret = mt76_testmode_alloc_skb(phy, td->tx_mpdu_len);
2639+ ret = mt76_testmode_alloc_skb(phy, len, tx_skb, addr);
2640 if (ret)
2641 return ret;
2642
developerbd9fa1e2023-10-16 11:04:00 +08002643@@ -193,7 +253,7 @@ mt76_testmode_tx_init(struct mt76_phy *phy)
developer6caa5e22022-06-16 13:33:13 +08002644 if (td->tx_antenna_mask)
2645 max_nss = min_t(u8, max_nss, hweight8(td->tx_antenna_mask));
2646
2647- info = IEEE80211_SKB_CB(td->tx_skb);
2648+ info = IEEE80211_SKB_CB(*tx_skb);
2649 rate = &info->control.rates[0];
2650 rate->count = 1;
2651 rate->idx = td->tx_rate_idx;
developerbd9fa1e2023-10-16 11:04:00 +08002652@@ -265,6 +325,25 @@ mt76_testmode_tx_init(struct mt76_phy *phy)
developer6caa5e22022-06-16 13:33:13 +08002653 out:
2654 return 0;
2655 }
2656+EXPORT_SYMBOL(mt76_testmode_init_skb);
2657+
2658+static int
2659+mt76_testmode_tx_init(struct mt76_phy *phy)
2660+{
2661+ struct mt76_testmode_entry_data *ed;
2662+ struct mt76_wcid *wcid;
2663+
2664+ mt76_tm_for_each_entry(phy, wcid, ed) {
2665+ int ret;
2666+
2667+ ret = mt76_testmode_init_skb(phy, ed->tx_mpdu_len,
2668+ &ed->tx_skb, ed->addr);
2669+ if (ret)
2670+ return ret;
2671+ }
2672+
2673+ return 0;
2674+}
2675
2676 static void
2677 mt76_testmode_tx_start(struct mt76_phy *phy)
developerbd9fa1e2023-10-16 11:04:00 +08002678@@ -275,6 +354,14 @@ mt76_testmode_tx_start(struct mt76_phy *phy)
developer6caa5e22022-06-16 13:33:13 +08002679 td->tx_queued = 0;
2680 td->tx_done = 0;
2681 td->tx_pending = td->tx_count;
2682+ if (td->tx_rate_mode == MT76_TM_TX_MODE_HE_MU)
2683+ td->tx_pending = 1;
2684+ if (td->entry_num) {
2685+ td->tx_pending *= td->entry_num;
2686+ td->cur_entry = list_first_entry(&td->tm_entry_list,
2687+ struct mt76_wcid, list);
2688+ }
2689+
2690 mt76_worker_schedule(&dev->tx_worker);
2691 }
2692
developerbd9fa1e2023-10-16 11:04:00 +08002693@@ -293,7 +380,7 @@ mt76_testmode_tx_stop(struct mt76_phy *phy)
developer6caa5e22022-06-16 13:33:13 +08002694 wait_event_timeout(dev->tx_wait, td->tx_done == td->tx_queued,
2695 MT76_TM_TIMEOUT * HZ);
2696
2697- mt76_testmode_free_skb(phy);
2698+ mt76_testmode_free_skb_all(phy);
2699 }
2700
2701 static inline void
developerbd9fa1e2023-10-16 11:04:00 +08002702@@ -324,6 +411,8 @@ mt76_testmode_init_defaults(struct mt76_phy *phy)
developer6caa5e22022-06-16 13:33:13 +08002703 memcpy(td->addr[0], phy->macaddr, ETH_ALEN);
2704 memcpy(td->addr[1], phy->macaddr, ETH_ALEN);
2705 memcpy(td->addr[2], phy->macaddr, ETH_ALEN);
2706+
2707+ INIT_LIST_HEAD(&phy->test.tm_entry_list);
2708 }
2709
2710 static int
developerbd9fa1e2023-10-16 11:04:00 +08002711@@ -333,8 +422,12 @@ __mt76_testmode_set_state(struct mt76_phy *phy, enum mt76_testmode_state state)
developer6caa5e22022-06-16 13:33:13 +08002712 struct mt76_dev *dev = phy->dev;
2713 int err;
2714
2715- if (prev_state == MT76_TM_STATE_TX_FRAMES)
2716+ if (prev_state == MT76_TM_STATE_TX_FRAMES) {
2717+ /* MU needs to clean hwq for free done event */
2718+ if (phy->test.tx_rate_mode == MT76_TM_TX_MODE_HE_MU)
2719+ dev->test_ops->set_state(phy, MT76_TM_STATE_IDLE);
2720 mt76_testmode_tx_stop(phy);
2721+ }
2722
2723 if (state == MT76_TM_STATE_TX_FRAMES) {
2724 err = mt76_testmode_tx_init(phy);
developerbd9fa1e2023-10-16 11:04:00 +08002725@@ -404,6 +497,44 @@ mt76_tm_get_u8(struct nlattr *attr, u8 *dest, u8 min, u8 max)
developer6caa5e22022-06-16 13:33:13 +08002726 return 0;
2727 }
2728
2729+static int
2730+mt76_testmode_set_eeprom(struct mt76_phy *phy, struct nlattr **tb)
2731+{
2732+ struct mt76_dev *dev = phy->dev;
2733+ u8 action, val[MT76_TM_EEPROM_BLOCK_SIZE];
2734+ u32 offset = 0;
2735+ int err = -EINVAL;
2736+
2737+ if (!dev->test_ops->set_eeprom)
2738+ return -EOPNOTSUPP;
2739+
2740+ if (mt76_tm_get_u8(tb[MT76_TM_ATTR_EEPROM_ACTION], &action,
2741+ 0, MT76_TM_EEPROM_ACTION_MAX))
2742+ goto out;
2743+
2744+ if (tb[MT76_TM_ATTR_EEPROM_OFFSET]) {
2745+ struct nlattr *cur;
2746+ int rem, idx = 0;
2747+
2748+ offset = nla_get_u32(tb[MT76_TM_ATTR_EEPROM_OFFSET]);
2749+ if (!!(offset % MT76_TM_EEPROM_BLOCK_SIZE) ||
2750+ !tb[MT76_TM_ATTR_EEPROM_VAL])
2751+ goto out;
2752+
2753+ nla_for_each_nested(cur, tb[MT76_TM_ATTR_EEPROM_VAL], rem) {
2754+ if (nla_len(cur) != 1 || idx >= ARRAY_SIZE(val))
2755+ goto out;
2756+
2757+ val[idx++] = nla_get_u8(cur);
2758+ }
2759+ }
2760+
2761+ err = dev->test_ops->set_eeprom(phy, offset, val, action);
2762+
2763+out:
2764+ return err;
2765+}
2766+
2767 int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2768 void *data, int len)
2769 {
developerbd9fa1e2023-10-16 11:04:00 +08002770@@ -427,6 +558,11 @@ int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
developer6caa5e22022-06-16 13:33:13 +08002771
2772 mutex_lock(&dev->mutex);
2773
2774+ if (tb[MT76_TM_ATTR_EEPROM_ACTION]) {
2775+ err = mt76_testmode_set_eeprom(phy, tb);
2776+ goto out;
2777+ }
2778+
2779 if (tb[MT76_TM_ATTR_RESET]) {
2780 mt76_testmode_set_state(phy, MT76_TM_STATE_OFF);
2781 memset(td, 0, sizeof(*td));
developerbd9fa1e2023-10-16 11:04:00 +08002782@@ -434,6 +570,9 @@ int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2783
2784 mt76_testmode_init_defaults(phy);
2785
2786+ if (tb[MT76_TM_ATTR_SKU_EN])
2787+ td->sku_en = nla_get_u8(tb[MT76_TM_ATTR_SKU_EN]);
2788+
2789 if (tb[MT76_TM_ATTR_TX_COUNT])
2790 td->tx_count = nla_get_u32(tb[MT76_TM_ATTR_TX_COUNT]);
2791
2792@@ -453,7 +592,10 @@ int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
developer6caa5e22022-06-16 13:33:13 +08002793 mt76_tm_get_u8(tb[MT76_TM_ATTR_TX_DUTY_CYCLE],
2794 &td->tx_duty_cycle, 0, 99) ||
2795 mt76_tm_get_u8(tb[MT76_TM_ATTR_TX_POWER_CONTROL],
2796- &td->tx_power_control, 0, 1))
2797+ &td->tx_power_control, 0, 1) ||
2798+ mt76_tm_get_u8(tb[MT76_TM_ATTR_AID], &td->aid, 0, 16) ||
2799+ mt76_tm_get_u8(tb[MT76_TM_ATTR_RU_ALLOC], &td->ru_alloc, 0, 0xff) ||
2800+ mt76_tm_get_u8(tb[MT76_TM_ATTR_RU_IDX], &td->ru_idx, 0, 68))
2801 goto out;
2802
2803 if (tb[MT76_TM_ATTR_TX_LENGTH]) {
developerbd9fa1e2023-10-16 11:04:00 +08002804@@ -485,8 +627,7 @@ int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
developer6caa5e22022-06-16 13:33:13 +08002805
2806 if (tb[MT76_TM_ATTR_TX_POWER]) {
2807 struct nlattr *cur;
2808- int idx = 0;
2809- int rem;
2810+ int rem, idx = 0;
2811
2812 nla_for_each_nested(cur, tb[MT76_TM_ATTR_TX_POWER], rem) {
2813 if (nla_len(cur) != 1 ||
developerbd9fa1e2023-10-16 11:04:00 +08002814@@ -506,11 +647,45 @@ int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
developer6caa5e22022-06-16 13:33:13 +08002815 if (nla_len(cur) != ETH_ALEN || idx >= 3)
2816 goto out;
2817
2818- memcpy(td->addr[idx], nla_data(cur), ETH_ALEN);
2819+ memcpy(td->addr[idx++], nla_data(cur), ETH_ALEN);
2820+ }
2821+ }
2822+
2823+ if (tb[MT76_TM_ATTR_CFG]) {
2824+ struct nlattr *cur;
2825+ int rem, idx = 0;
2826+
2827+ nla_for_each_nested(cur, tb[MT76_TM_ATTR_CFG], rem) {
2828+ if (nla_len(cur) != 1 || idx >= 2)
2829+ goto out;
2830+
2831+ if (idx == 0)
2832+ td->cfg.type = nla_get_u8(cur);
2833+ else
2834+ td->cfg.enable = nla_get_u8(cur);
2835 idx++;
2836 }
2837 }
2838
2839+ if (tb[MT76_TM_ATTR_TXBF_ACT]) {
2840+ struct nlattr *cur;
2841+ int rem, idx = 0;
2842+
2843+ if (!tb[MT76_TM_ATTR_TXBF_PARAM] ||
2844+ mt76_tm_get_u8(tb[MT76_TM_ATTR_TXBF_ACT], &td->txbf_act,
developer692ed9b2023-06-19 12:03:50 +08002845+ 0, MT76_TM_TXBF_ACT_MAX))
developer6caa5e22022-06-16 13:33:13 +08002846+ goto out;
2847+
2848+ memset(td->txbf_param, 0, sizeof(td->txbf_param));
2849+ nla_for_each_nested(cur, tb[MT76_TM_ATTR_TXBF_PARAM], rem) {
2850+ if (nla_len(cur) != 2 ||
2851+ idx >= ARRAY_SIZE(td->txbf_param))
2852+ goto out;
2853+
2854+ td->txbf_param[idx++] = nla_get_u16(cur);
2855+ }
2856+ }
2857+
2858 if (dev->test_ops->set_params) {
2859 err = dev->test_ops->set_params(phy, tb, state);
2860 if (err)
developerbd9fa1e2023-10-16 11:04:00 +08002861@@ -575,6 +750,7 @@ int mt76_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *msg,
developer6caa5e22022-06-16 13:33:13 +08002862 struct mt76_phy *phy = hw->priv;
2863 struct mt76_dev *dev = phy->dev;
2864 struct mt76_testmode_data *td = &phy->test;
2865+ struct mt76_testmode_entry_data *ed = &td->ed;
2866 struct nlattr *tb[NUM_MT76_TM_ATTRS] = {};
2867 int err = 0;
2868 void *a;
developerbd9fa1e2023-10-16 11:04:00 +08002869@@ -607,6 +783,19 @@ int mt76_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *msg,
developer6caa5e22022-06-16 13:33:13 +08002870 goto out;
2871 }
2872
2873+ if (tb[MT76_TM_ATTR_AID]) {
2874+ struct mt76_wcid *wcid;
2875+ u8 aid;
2876+
2877+ err = mt76_tm_get_u8(tb[MT76_TM_ATTR_AID], &aid, 1, 16);
2878+ if (err)
2879+ goto out;
2880+
2881+ mt76_tm_for_each_entry(phy, wcid, ed)
2882+ if (ed->aid == aid)
2883+ ed = mt76_testmode_entry_data(phy, wcid);
2884+ }
2885+
2886 mt76_testmode_init_defaults(phy);
2887
2888 err = -EMSGSIZE;
developerbd9fa1e2023-10-16 11:04:00 +08002889@@ -619,12 +808,9 @@ int mt76_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *msg,
developer6caa5e22022-06-16 13:33:13 +08002890 goto out;
2891
2892 if (nla_put_u32(msg, MT76_TM_ATTR_TX_COUNT, td->tx_count) ||
2893- nla_put_u32(msg, MT76_TM_ATTR_TX_LENGTH, td->tx_mpdu_len) ||
developerbd9fa1e2023-10-16 11:04:00 +08002894+ nla_put_u8(msg, MT76_TM_ATTR_SKU_EN, td->sku_en) ||
developer6caa5e22022-06-16 13:33:13 +08002895 nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_MODE, td->tx_rate_mode) ||
2896- nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_NSS, td->tx_rate_nss) ||
2897- nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_IDX, td->tx_rate_idx) ||
2898 nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_SGI, td->tx_rate_sgi) ||
2899- nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_LDPC, td->tx_rate_ldpc) ||
2900 nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_STBC, td->tx_rate_stbc) ||
2901 (mt76_testmode_param_present(td, MT76_TM_ATTR_TX_LTF) &&
2902 nla_put_u8(msg, MT76_TM_ATTR_TX_LTF, td->tx_ltf)) ||
developerbd9fa1e2023-10-16 11:04:00 +08002903@@ -641,7 +827,16 @@ int mt76_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *msg,
developer692ed9b2023-06-19 12:03:50 +08002904 (mt76_testmode_param_present(td, MT76_TM_ATTR_TX_POWER_CONTROL) &&
2905 nla_put_u8(msg, MT76_TM_ATTR_TX_POWER_CONTROL, td->tx_power_control)) ||
2906 (mt76_testmode_param_present(td, MT76_TM_ATTR_FREQ_OFFSET) &&
2907- nla_put_u8(msg, MT76_TM_ATTR_FREQ_OFFSET, td->freq_offset)))
2908+ nla_put_u32(msg, MT76_TM_ATTR_FREQ_OFFSET, td->freq_offset)))
2909+ goto out;
2910+
developer6caa5e22022-06-16 13:33:13 +08002911+ if (nla_put_u32(msg, MT76_TM_ATTR_TX_LENGTH, ed->tx_mpdu_len) ||
2912+ nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_NSS, ed->tx_rate_nss) ||
2913+ nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_IDX, ed->tx_rate_idx) ||
2914+ nla_put_u8(msg, MT76_TM_ATTR_TX_RATE_LDPC, ed->tx_rate_ldpc) ||
2915+ nla_put_u8(msg, MT76_TM_ATTR_AID, ed->aid) ||
2916+ nla_put_u8(msg, MT76_TM_ATTR_RU_ALLOC, ed->ru_alloc) ||
2917+ nla_put_u8(msg, MT76_TM_ATTR_RU_IDX, ed->ru_idx))
developer692ed9b2023-06-19 12:03:50 +08002918 goto out;
2919
developer6caa5e22022-06-16 13:33:13 +08002920 if (mt76_testmode_param_present(td, MT76_TM_ATTR_TX_POWER)) {
developer6caa5e22022-06-16 13:33:13 +08002921diff --git a/testmode.h b/testmode.h
developer05f3b2b2024-08-19 19:17:34 +08002922index 89613266..7a686250 100644
developer6caa5e22022-06-16 13:33:13 +08002923--- a/testmode.h
2924+++ b/testmode.h
2925@@ -6,6 +6,8 @@
2926 #define __MT76_TESTMODE_H
2927
2928 #define MT76_TM_TIMEOUT 10
2929+#define MT76_TM_MAX_ENTRY_NUM 16
2930+#define MT76_TM_EEPROM_BLOCK_SIZE 16
2931
2932 /**
2933 * enum mt76_testmode_attr - testmode attributes inside NL80211_ATTR_TESTDATA
developerbd9fa1e2023-10-16 11:04:00 +08002934@@ -18,6 +20,7 @@
2935 * @MT76_TM_ATTR_MTD_PART: mtd partition used for eeprom data (string)
2936 * @MT76_TM_ATTR_MTD_OFFSET: offset of eeprom data within the partition (u32)
2937 *
2938+ * @MT76_TM_ATTR_SKU_EN: config txpower sku is enabled or disabled in testmode (u8)
2939 * @MT76_TM_ATTR_TX_COUNT: configured number of frames to send when setting
2940 * state to MT76_TM_STATE_TX_FRAMES (u32)
2941 * @MT76_TM_ATTR_TX_PENDING: pending frames during MT76_TM_STATE_TX_FRAMES (u32)
2942@@ -47,6 +50,15 @@
developer6caa5e22022-06-16 13:33:13 +08002943 * @MT76_TM_ATTR_DRV_DATA: driver specific netlink attrs (nested)
2944 *
2945 * @MT76_TM_ATTR_MAC_ADDRS: array of nested MAC addresses (nested)
2946+ *
2947+ * @MT76_TM_ATTR_EEPROM_ACTION: eeprom setting actions
developer692ed9b2023-06-19 12:03:50 +08002948+ * (u8, see &enum mt76_testmode_eeprom_action)
developer6caa5e22022-06-16 13:33:13 +08002949+ * @MT76_TM_ATTR_EEPROM_OFFSET: offset of eeprom data block for writing (u32)
2950+ * @MT76_TM_ATTR_EEPROM_VAL: values for writing into a 16-byte data block
developer692ed9b2023-06-19 12:03:50 +08002951+ * (nested, u8 attrs)
developer6caa5e22022-06-16 13:33:13 +08002952+ *
2953+ * @MT76_TM_ATTR_CFG: config testmode rf feature (nested, see &mt76_testmode_cfg)
2954+ *
2955 */
2956 enum mt76_testmode_attr {
2957 MT76_TM_ATTR_UNSPEC,
developerbd9fa1e2023-10-16 11:04:00 +08002958@@ -57,6 +69,7 @@ enum mt76_testmode_attr {
2959 MT76_TM_ATTR_MTD_PART,
2960 MT76_TM_ATTR_MTD_OFFSET,
2961
2962+ MT76_TM_ATTR_SKU_EN,
2963 MT76_TM_ATTR_TX_COUNT,
2964 MT76_TM_ATTR_TX_LENGTH,
2965 MT76_TM_ATTR_TX_RATE_MODE,
2966@@ -84,6 +97,17 @@ enum mt76_testmode_attr {
developer6caa5e22022-06-16 13:33:13 +08002967 MT76_TM_ATTR_DRV_DATA,
2968
2969 MT76_TM_ATTR_MAC_ADDRS,
2970+ MT76_TM_ATTR_AID,
2971+ MT76_TM_ATTR_RU_ALLOC,
2972+ MT76_TM_ATTR_RU_IDX,
2973+
2974+ MT76_TM_ATTR_EEPROM_ACTION,
2975+ MT76_TM_ATTR_EEPROM_OFFSET,
2976+ MT76_TM_ATTR_EEPROM_VAL,
2977+
2978+ MT76_TM_ATTR_CFG,
2979+ MT76_TM_ATTR_TXBF_ACT,
2980+ MT76_TM_ATTR_TXBF_PARAM,
2981
2982 /* keep last */
2983 NUM_MT76_TM_ATTRS,
developerbd9fa1e2023-10-16 11:04:00 +08002984@@ -128,6 +152,7 @@ enum mt76_testmode_stats_attr {
2985 *
2986 * @MT76_TM_RX_ATTR_FREQ_OFFSET: frequency offset (s32)
2987 * @MT76_TM_RX_ATTR_RCPI: received channel power indicator (array, u8)
2988+ * @MT76_TM_RX_ATTR_RSSI: received signal strength indicator (array, s8)
2989 * @MT76_TM_RX_ATTR_IB_RSSI: internal inband RSSI (array, s8)
2990 * @MT76_TM_RX_ATTR_WB_RSSI: internal wideband RSSI (array, s8)
2991 * @MT76_TM_RX_ATTR_SNR: signal-to-noise ratio (u8)
2992@@ -137,6 +162,7 @@ enum mt76_testmode_rx_attr {
2993
2994 MT76_TM_RX_ATTR_FREQ_OFFSET,
2995 MT76_TM_RX_ATTR_RCPI,
2996+ MT76_TM_RX_ATTR_RSSI,
2997 MT76_TM_RX_ATTR_IB_RSSI,
2998 MT76_TM_RX_ATTR_WB_RSSI,
2999 MT76_TM_RX_ATTR_SNR,
3000@@ -198,4 +224,57 @@ enum mt76_testmode_tx_mode {
developer6caa5e22022-06-16 13:33:13 +08003001
3002 extern const struct nla_policy mt76_tm_policy[NUM_MT76_TM_ATTRS];
3003
3004+/**
3005+ * enum mt76_testmode_eeprom_action - eeprom setting actions
3006+ *
3007+ * @MT76_TM_EEPROM_ACTION_UPDATE_DATA: update rf values to specific
developer692ed9b2023-06-19 12:03:50 +08003008+ * eeprom data block
developer6caa5e22022-06-16 13:33:13 +08003009+ * @MT76_TM_EEPROM_ACTION_UPDATE_BUFFER_MODE: send updated eeprom data to fw
3010+ * @MT76_TM_EEPROM_ACTION_WRITE_TO_EFUSE: write eeprom data back to efuse
3011+ */
3012+enum mt76_testmode_eeprom_action {
3013+ MT76_TM_EEPROM_ACTION_UPDATE_DATA,
3014+ MT76_TM_EEPROM_ACTION_UPDATE_BUFFER_MODE,
3015+ MT76_TM_EEPROM_ACTION_WRITE_TO_EFUSE,
3016+
3017+ /* keep last */
3018+ NUM_MT76_TM_EEPROM_ACTION,
3019+ MT76_TM_EEPROM_ACTION_MAX = NUM_MT76_TM_EEPROM_ACTION - 1,
3020+};
3021+
3022+/**
3023+ * enum mt76_testmode_cfg - packet tx phy mode
3024+ *
3025+ * @MT76_TM_EEPROM_ACTION_UPDATE_DATA: update rf values to specific
developer692ed9b2023-06-19 12:03:50 +08003026+ * eeprom data block
developer6caa5e22022-06-16 13:33:13 +08003027+ * @MT76_TM_EEPROM_ACTION_UPDATE_BUFFER_MODE: send updated eeprom data to fw
3028+ * @MT76_TM_EEPROM_ACTION_WRITE_TO_EFUSE: write eeprom data back to efuse
3029+ */
3030+enum mt76_testmode_cfg {
3031+ MT76_TM_CFG_TSSI,
3032+ MT76_TM_CFG_DPD,
3033+ MT76_TM_CFG_RATE_POWER_OFFSET,
3034+ MT76_TM_CFG_THERMAL_COMP,
3035+
3036+ /* keep last */
3037+ NUM_MT76_TM_CFG,
3038+ MT76_TM_CFG_MAX = NUM_MT76_TM_CFG - 1,
3039+};
3040+
3041+enum mt76_testmode_txbf_act {
3042+ MT76_TM_TXBF_ACT_INIT,
3043+ MT76_TM_TXBF_ACT_UPDATE_CH,
3044+ MT76_TM_TXBF_ACT_PHASE_COMP,
3045+ MT76_TM_TXBF_ACT_TX_PREP,
3046+ MT76_TM_TXBF_ACT_IBF_PROF_UPDATE,
3047+ MT76_TM_TXBF_ACT_EBF_PROF_UPDATE,
3048+ MT76_TM_TXBF_ACT_PHASE_CAL,
3049+ MT76_TM_TXBF_ACT_PROF_UPDATE_ALL,
3050+ MT76_TM_TXBF_ACT_E2P_UPDATE,
3051+
3052+ /* keep last */
3053+ NUM_MT76_TM_TXBF_ACT,
3054+ MT76_TM_TXBF_ACT_MAX = NUM_MT76_TM_TXBF_ACT - 1,
3055+};
3056+
3057 #endif
3058diff --git a/tools/fields.c b/tools/fields.c
developer05f3b2b2024-08-19 19:17:34 +08003059index e3f69089..406ba77c 100644
developer6caa5e22022-06-16 13:33:13 +08003060--- a/tools/fields.c
3061+++ b/tools/fields.c
3062@@ -10,6 +10,7 @@ static const char * const testmode_state[] = {
3063 [MT76_TM_STATE_IDLE] = "idle",
3064 [MT76_TM_STATE_TX_FRAMES] = "tx_frames",
3065 [MT76_TM_STATE_RX_FRAMES] = "rx_frames",
3066+ [MT76_TM_STATE_TX_CONT] = "tx_cont",
3067 };
3068
3069 static const char * const testmode_tx_mode[] = {
developerbd9fa1e2023-10-16 11:04:00 +08003070@@ -65,7 +66,7 @@ static bool parse_u8(const struct tm_field *field, int idx,
3071
3072 static void print_u8(const struct tm_field *field, struct nlattr *attr)
3073 {
3074- printf("%d", nla_get_u8(attr));
3075+ printf("%u", nla_get_u8(attr));
3076 }
3077
3078 static void print_s8(const struct tm_field *field, struct nlattr *attr)
developer15c355d2023-03-21 17:28:34 +08003079@@ -86,12 +87,12 @@ static void print_s32(const struct tm_field *field, struct nlattr *attr)
3080
3081 static void print_u32(const struct tm_field *field, struct nlattr *attr)
3082 {
3083- printf("%d", nla_get_u32(attr));
3084+ printf("%u", nla_get_u32(attr));
3085 }
3086
3087 static void print_u64(const struct tm_field *field, struct nlattr *attr)
3088 {
3089- printf("%lld", (unsigned long long)nla_get_u64(attr));
3090+ printf("%llu", (unsigned long long)nla_get_u64(attr));
3091 }
3092
3093 static bool parse_flag(const struct tm_field *field, int idx,
developer6caa5e22022-06-16 13:33:13 +08003094@@ -201,6 +202,63 @@ static void print_extra_stats(const struct tm_field *field, struct nlattr **tb)
3095 printf("%srx_per=%.02f%%\n", prefix, 100 * failed / total);
3096 }
3097
3098+static bool parse_mac(const struct tm_field *field, int idx,
3099+ struct nl_msg *msg, const char *val)
3100+{
3101+#define ETH_ALEN 6
3102+ bool ret = true;
3103+ char *str, *cur, *ap;
3104+ void *a;
3105+
3106+ ap = str = strdup(val);
3107+
3108+ a = nla_nest_start(msg, idx);
3109+
3110+ idx = 0;
3111+ while ((cur = strsep(&ap, ",")) != NULL) {
3112+ unsigned char addr[ETH_ALEN];
3113+ char *val, *tmp = cur;
3114+ int i = 0;
3115+
3116+ while ((val = strsep(&tmp, ":")) != NULL) {
3117+ if (i >= ETH_ALEN)
3118+ break;
3119+
3120+ addr[i++] = strtoul(val, NULL, 16);
3121+ }
3122+
3123+ nla_put(msg, idx, ETH_ALEN, addr);
3124+
3125+ idx++;
3126+ }
3127+
3128+ nla_nest_end(msg, a);
3129+
3130+ free(str);
3131+
3132+ return ret;
3133+}
3134+
3135+static void print_mac(const struct tm_field *field, struct nlattr *attr)
3136+{
3137+#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
3138+#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
3139+ unsigned char addr[3][6];
3140+ struct nlattr *cur;
3141+ int idx = 0;
3142+ int rem;
3143+
3144+ nla_for_each_nested(cur, attr, rem) {
3145+ if (nla_len(cur) != 6)
3146+ continue;
3147+ memcpy(addr[idx++], nla_data(cur), 6);
3148+ }
3149+
3150+ printf("" MACSTR "," MACSTR "," MACSTR "",
3151+ MAC2STR(addr[0]), MAC2STR(addr[1]), MAC2STR(addr[2]));
3152+
3153+ return;
3154+}
3155
3156 #define FIELD_GENERIC(_field, _name, ...) \
3157 [FIELD_NAME(_field)] = { \
developerbd9fa1e2023-10-16 11:04:00 +08003158@@ -250,10 +308,18 @@ static void print_extra_stats(const struct tm_field *field, struct nlattr **tb)
developer6caa5e22022-06-16 13:33:13 +08003159 ##__VA_ARGS__ \
3160 )
3161
3162+#define FIELD_MAC(_field, _name) \
3163+ [FIELD_NAME(_field)] = { \
3164+ .name = _name, \
3165+ .parse = parse_mac, \
3166+ .print = print_mac \
3167+ }
3168+
3169 #define FIELD_NAME(_field) MT76_TM_RX_ATTR_##_field
3170 static const struct tm_field rx_fields[NUM_MT76_TM_RX_ATTRS] = {
3171 FIELD_RO(s32, FREQ_OFFSET, "freq_offset"),
developerbd9fa1e2023-10-16 11:04:00 +08003172 FIELD_ARRAY_RO(u8, RCPI, "rcpi"),
3173+ FIELD_ARRAY_RO(s8, RSSI, "rssi"),
3174 FIELD_ARRAY_RO(s8, IB_RSSI, "ib_rssi"),
3175 FIELD_ARRAY_RO(s8, WB_RSSI, "wb_rssi"),
3176 FIELD_RO(s8, SNR, "snr"),
3177@@ -261,6 +327,7 @@ static const struct tm_field rx_fields[NUM_MT76_TM_RX_ATTRS] = {
3178 static struct nla_policy rx_policy[NUM_MT76_TM_RX_ATTRS] = {
3179 [MT76_TM_RX_ATTR_FREQ_OFFSET] = { .type = NLA_U32 },
3180 [MT76_TM_RX_ATTR_RCPI] = { .type = NLA_NESTED },
3181+ [MT76_TM_RX_ATTR_RSSI] = { .type = NLA_NESTED },
3182 [MT76_TM_RX_ATTR_IB_RSSI] = { .type = NLA_NESTED },
3183 [MT76_TM_RX_ATTR_WB_RSSI] = { .type = NLA_NESTED },
3184 [MT76_TM_RX_ATTR_SNR] = { .type = NLA_U8 },
3185@@ -291,6 +358,7 @@ static const struct tm_field testdata_fields[NUM_MT76_TM_ATTRS] = {
3186 FIELD_ENUM(STATE, "state", testmode_state),
3187 FIELD_RO(string, MTD_PART, "mtd_part"),
3188 FIELD_RO(u32, MTD_OFFSET, "mtd_offset"),
3189+ FIELD(u8, SKU_EN, "sku_en"),
3190 FIELD(u32, TX_COUNT, "tx_count"),
3191 FIELD(u32, TX_LENGTH, "tx_length"),
3192 FIELD_ENUM(TX_RATE_MODE, "tx_rate_mode", testmode_tx_mode),
3193@@ -300,10 +368,18 @@ static const struct tm_field testdata_fields[NUM_MT76_TM_ATTRS] = {
developer6caa5e22022-06-16 13:33:13 +08003194 FIELD(u8, TX_RATE_LDPC, "tx_rate_ldpc"),
3195 FIELD(u8, TX_RATE_STBC, "tx_rate_stbc"),
3196 FIELD(u8, TX_LTF, "tx_ltf"),
3197+ FIELD(u8, TX_DUTY_CYCLE, "tx_duty_cycle"),
3198+ FIELD(u32, TX_IPG, "tx_ipg"),
3199+ FIELD(u32, TX_TIME, "tx_time"),
3200 FIELD(u8, TX_POWER_CONTROL, "tx_power_control"),
3201 FIELD_ARRAY(u8, TX_POWER, "tx_power"),
3202 FIELD(u8, TX_ANTENNA, "tx_antenna"),
3203+ FIELD(u8, TX_SPE_IDX, "tx_spe_idx"),
3204 FIELD(u32, FREQ_OFFSET, "freq_offset"),
3205+ FIELD(u8, AID, "aid"),
3206+ FIELD(u8, RU_ALLOC, "ru_alloc"),
3207+ FIELD(u8, RU_IDX, "ru_idx"),
3208+ FIELD_MAC(MAC_ADDRS, "mac_addrs"),
3209 FIELD_NESTED_RO(STATS, stats, "",
3210 .print_extra = print_extra_stats),
3211 };
developerbd9fa1e2023-10-16 11:04:00 +08003212@@ -313,6 +389,7 @@ static struct nla_policy testdata_policy[NUM_MT76_TM_ATTRS] = {
3213 [MT76_TM_ATTR_STATE] = { .type = NLA_U8 },
3214 [MT76_TM_ATTR_MTD_PART] = { .type = NLA_STRING },
3215 [MT76_TM_ATTR_MTD_OFFSET] = { .type = NLA_U32 },
3216+ [MT76_TM_ATTR_SKU_EN] = { .type = NLA_U8 },
3217 [MT76_TM_ATTR_TX_COUNT] = { .type = NLA_U32 },
3218 [MT76_TM_ATTR_TX_LENGTH] = { .type = NLA_U32 },
3219 [MT76_TM_ATTR_TX_RATE_MODE] = { .type = NLA_U8 },
3220@@ -322,9 +399,16 @@ static struct nla_policy testdata_policy[NUM_MT76_TM_ATTRS] = {
developer6caa5e22022-06-16 13:33:13 +08003221 [MT76_TM_ATTR_TX_RATE_LDPC] = { .type = NLA_U8 },
3222 [MT76_TM_ATTR_TX_RATE_STBC] = { .type = NLA_U8 },
3223 [MT76_TM_ATTR_TX_LTF] = { .type = NLA_U8 },
3224+ [MT76_TM_ATTR_TX_DUTY_CYCLE] = { .type = NLA_U8 },
3225+ [MT76_TM_ATTR_TX_IPG] = { .type = NLA_U32 },
3226+ [MT76_TM_ATTR_TX_TIME] = { .type = NLA_U32 },
3227 [MT76_TM_ATTR_TX_POWER_CONTROL] = { .type = NLA_U8 },
3228 [MT76_TM_ATTR_TX_ANTENNA] = { .type = NLA_U8 },
3229+ [MT76_TM_ATTR_TX_SPE_IDX] = { .type = NLA_U8 },
3230 [MT76_TM_ATTR_FREQ_OFFSET] = { .type = NLA_U32 },
3231+ [MT76_TM_ATTR_AID] = { .type = NLA_U8 },
3232+ [MT76_TM_ATTR_RU_ALLOC] = { .type = NLA_U8 },
3233+ [MT76_TM_ATTR_RU_IDX] = { .type = NLA_U8 },
3234 [MT76_TM_ATTR_STATS] = { .type = NLA_NESTED },
3235 };
3236
3237diff --git a/tx.c b/tx.c
developer05f3b2b2024-08-19 19:17:34 +08003238index 0fdf7d83..db0d4df5 100644
developer6caa5e22022-06-16 13:33:13 +08003239--- a/tx.c
3240+++ b/tx.c
developer47efbdb2023-06-29 20:33:22 +08003241@@ -259,8 +259,7 @@ void __mt76_tx_complete_skb(struct mt76_dev *dev, u16 wcid_idx, struct sk_buff *
developer6caa5e22022-06-16 13:33:13 +08003242 if (mt76_is_testmode_skb(dev, skb, &hw)) {
3243 struct mt76_phy *phy = hw->priv;
3244
3245- if (skb == phy->test.tx_skb)
3246- phy->test.tx_done++;
3247+ phy->test.tx_done++;
3248 if (phy->test.tx_queued == phy->test.tx_done)
3249 wake_up(&dev->tx_wait);
3250
3251--
developerbd9fa1e2023-10-16 11:04:00 +080032522.18.0
developer6caa5e22022-06-16 13:33:13 +08003253