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