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