blob: 07733c3fa7cdbf5d4de4874040c50ecc85399f21 [file] [log] [blame]
developer663dccd2023-04-28 11:35:16 +08001From 80765449e32eba36051daeb29824cc011aecd85d Mon Sep 17 00:00:00 2001
developer1557f6c2023-04-13 18:48:23 +08002From: Benjamin Lin <benjamin-jw.lin@mediatek.com>
3Date: Fri, 24 Mar 2023 18:01:27 +0800
developer663dccd2023-04-28 11:35:16 +08004Subject: [PATCH] wifi: mt76: fix incorrect HE TX GI report
developer1557f6c2023-04-13 18:48:23 +08005
6Change GI reporting source from static capability to rate-tuning module.
7
8Signed-off-by: Benjamin Lin <benjamin-jw.lin@mediatek.com>
9---
10 mt76.h | 4 ++
11 mt7915/init.c | 4 ++
developer663dccd2023-04-28 11:35:16 +080012 mt7915/mac.c | 60 ++++++++++------
13 mt7915/main.c | 7 ++
14 mt7915/mcu.c | 183 ++++++++++++++++++++++++++++++++++++++++++++++++
15 mt7915/mcu.h | 58 +++++++++++++++
16 mt7915/mt7915.h | 6 ++
17 7 files changed, 302 insertions(+), 20 deletions(-)
developer1557f6c2023-04-13 18:48:23 +080018
19diff --git a/mt76.h b/mt76.h
developer663dccd2023-04-28 11:35:16 +080020index 183b0fc5..11d49363 100644
developer1557f6c2023-04-13 18:48:23 +080021--- a/mt76.h
22+++ b/mt76.h
23@@ -254,12 +254,16 @@ struct mt76_queue_ops {
24 void (*reset_q)(struct mt76_dev *dev, struct mt76_queue *q);
25 };
26
27+#define MT_PHY_TYPE_LEGACY GENMASK(2, 0)
28+#define MT_PHY_TYPE_EXT GENMASK(7, 3)
29+
30 enum mt76_phy_type {
31 MT_PHY_TYPE_CCK,
32 MT_PHY_TYPE_OFDM,
33 MT_PHY_TYPE_HT,
34 MT_PHY_TYPE_HT_GF,
35 MT_PHY_TYPE_VHT,
36+ MT_PHY_TYPE_HE_REMAP,
37 MT_PHY_TYPE_HE_SU = 8,
38 MT_PHY_TYPE_HE_EXT_SU,
39 MT_PHY_TYPE_HE_TB,
40diff --git a/mt7915/init.c b/mt7915/init.c
developer663dccd2023-04-28 11:35:16 +080041index b88c3827..611a82b6 100644
developer1557f6c2023-04-13 18:48:23 +080042--- a/mt7915/init.c
43+++ b/mt7915/init.c
44@@ -644,6 +644,8 @@ mt7915_register_ext_phy(struct mt7915_dev *dev, struct mt7915_phy *phy)
45 struct mt76_phy *mphy = phy->mt76;
46 int ret;
47
48+ INIT_LIST_HEAD(&phy->stats_list);
49+ spin_lock_init(&phy->stats_lock);
50 INIT_DELAYED_WORK(&mphy->mac_work, mt7915_mac_work);
51
52 mt7915_eeprom_parse_hw_cap(dev, phy);
53@@ -1197,6 +1199,8 @@ int mt7915_register_device(struct mt7915_dev *dev)
54 dev->phy.dev = dev;
55 dev->phy.mt76 = &dev->mt76.phy;
56 dev->mt76.phy.priv = &dev->phy;
57+ INIT_LIST_HEAD(&dev->phy.stats_list);
58+ spin_lock_init(&dev->phy.stats_lock);
59 INIT_WORK(&dev->rc_work, mt7915_mac_sta_rc_work);
60 INIT_DELAYED_WORK(&dev->mphy.mac_work, mt7915_mac_work);
61 INIT_LIST_HEAD(&dev->sta_rc_list);
62diff --git a/mt7915/mac.c b/mt7915/mac.c
developer663dccd2023-04-28 11:35:16 +080063index f1fdcfde..8e30070b 100644
developer1557f6c2023-04-13 18:48:23 +080064--- a/mt7915/mac.c
65+++ b/mt7915/mac.c
66@@ -177,15 +177,7 @@ static void mt7915_mac_sta_poll(struct mt7915_dev *dev)
67 rx_cur);
68 }
69
70- /*
71- * We don't support reading GI info from txs packets.
72- * For accurate tx status reporting and AQL improvement,
73- * we need to make sure that flags match so polling GI
74- * from per-sta counters directly.
75- */
76 rate = &msta->wcid.rate;
77- addr = mt7915_mac_wtbl_lmac_addr(dev, idx, 7);
78- val = mt76_rr(dev, addr);
79
80 switch (rate->bw) {
81 case RATE_INFO_BW_160:
82@@ -202,18 +194,6 @@ static void mt7915_mac_sta_poll(struct mt7915_dev *dev)
83 break;
84 }
85
86- if (rate->flags & RATE_INFO_FLAGS_HE_MCS) {
87- u8 offs = 24 + 2 * bw;
88-
89- rate->he_gi = (val & (0x3 << offs)) >> offs;
90- } else if (rate->flags &
91- (RATE_INFO_FLAGS_VHT_MCS | RATE_INFO_FLAGS_MCS)) {
92- if (val & BIT(12 + bw))
93- rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
94- else
95- rate->flags &= ~RATE_INFO_FLAGS_SHORT_GI;
96- }
97-
98 /* get signal strength of resp frames (CTS/BA/ACK) */
99 addr = mt7915_mac_wtbl_lmac_addr(dev, idx, 30);
100 val = mt76_rr(dev, addr);
101@@ -982,6 +962,7 @@ mt7915_mac_tx_free(struct mt7915_dev *dev, void *data, int len)
102 if (info & MT_TX_FREE_PAIR) {
103 struct mt7915_sta *msta;
104 struct mt76_wcid *wcid;
105+ struct mt7915_phy *phy;
106 u16 idx;
107
108 idx = FIELD_GET(MT_TX_FREE_WLAN_ID, info);
109@@ -991,10 +972,17 @@ mt7915_mac_tx_free(struct mt7915_dev *dev, void *data, int len)
110 continue;
111
112 msta = container_of(wcid, struct mt7915_sta, wcid);
113+ phy = msta->vif->phy;
114 spin_lock_bh(&dev->sta_poll_lock);
115 if (list_empty(&msta->poll_list))
116 list_add_tail(&msta->poll_list, &dev->sta_poll_list);
117 spin_unlock_bh(&dev->sta_poll_lock);
118+
119+ spin_lock_bh(&phy->stats_lock);
120+ if (list_empty(&msta->stats_list))
121+ list_add_tail(&msta->stats_list, &phy->stats_list);
122+ spin_unlock_bh(&phy->stats_lock);
123+
124 continue;
125 }
126
developer663dccd2023-04-28 11:35:16 +0800127@@ -1055,6 +1043,7 @@ mt7915_mac_tx_free_v0(struct mt7915_dev *dev, void *data, int len)
128 static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data)
129 {
130 struct mt7915_sta *msta = NULL;
131+ struct mt7915_phy *phy;
132 struct mt76_wcid *wcid;
133 __le32 *txs_data = data;
134 u16 wcidx;
135@@ -1090,6 +1079,11 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data)
136 list_add_tail(&msta->poll_list, &dev->sta_poll_list);
137 spin_unlock_bh(&dev->sta_poll_lock);
138
139+ phy = msta->vif->phy;
140+ spin_lock_bh(&phy->stats_lock);
141+ if (list_empty(&msta->stats_list))
142+ list_add_tail(&msta->stats_list, &phy->stats_list);
143+ spin_unlock_bh(&phy->stats_lock);
144 out:
145 rcu_read_unlock();
146 }
147@@ -2016,6 +2010,27 @@ static void mt7915_mac_severe_check(struct mt7915_phy *phy)
developer1557f6c2023-04-13 18:48:23 +0800148 phy->trb_ts = trb;
149 }
150
151+static void mt7915_mac_sta_stats_work(struct mt7915_phy *phy)
152+{
153+ struct mt7915_sta *sta;
154+ LIST_HEAD(list);
155+
156+ spin_lock_bh(&phy->stats_lock);
157+ list_splice_init(&phy->stats_list, &list);
158+
159+ while (!list_empty(&list)) {
160+ sta = list_first_entry(&list, struct mt7915_sta, stats_list);
161+ list_del_init(&sta->stats_list);
162+ spin_unlock_bh(&phy->stats_lock);
163+
164+ mt7915_mcu_get_tx_rate(phy, sta->wcid.idx);
165+
166+ spin_lock_bh(&phy->stats_lock);
167+ }
168+
169+ spin_unlock_bh(&phy->stats_lock);
170+}
171+
172 void mt7915_mac_sta_rc_work(struct work_struct *work)
173 {
174 struct mt7915_dev *dev = container_of(work, struct mt7915_dev, rc_work);
developer663dccd2023-04-28 11:35:16 +0800175@@ -2071,6 +2086,11 @@ void mt7915_mac_work(struct work_struct *work)
developer1557f6c2023-04-13 18:48:23 +0800176 mt7915_mac_severe_check(phy);
177 }
178
179+ if (++phy->stats_work_count == 10) {
180+ phy->stats_work_count = 0;
181+ mt7915_mac_sta_stats_work(phy);
182+ }
183+
184 mutex_unlock(&mphy->dev->mutex);
185
186 mt76_tx_status_check(mphy->dev, false);
187diff --git a/mt7915/main.c b/mt7915/main.c
developer663dccd2023-04-28 11:35:16 +0800188index ea1d4e6a..870b7b23 100644
developer1557f6c2023-04-13 18:48:23 +0800189--- a/mt7915/main.c
190+++ b/mt7915/main.c
191@@ -684,6 +684,7 @@ int mt7915_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
192
193 INIT_LIST_HEAD(&msta->rc_list);
194 INIT_LIST_HEAD(&msta->poll_list);
195+ INIT_LIST_HEAD(&msta->stats_list);
196 msta->vif = mvif;
197 msta->wcid.sta = 1;
198 msta->wcid.idx = idx;
199@@ -708,6 +709,7 @@ void mt7915_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
200 {
201 struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76);
202 struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
203+ struct mt7915_phy *phy = msta->vif->phy;
204 int i;
205
206 mt7915_mcu_add_sta(dev, vif, sta, false);
207@@ -724,6 +726,11 @@ void mt7915_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
208 if (!list_empty(&msta->rc_list))
209 list_del_init(&msta->rc_list);
210 spin_unlock_bh(&dev->sta_poll_lock);
211+
212+ spin_lock_bh(&phy->stats_lock);
213+ if (!list_empty(&msta->stats_list))
214+ list_del_init(&msta->stats_list);
215+ spin_unlock_bh(&phy->stats_lock);
216 }
217
218 static void mt7915_tx(struct ieee80211_hw *hw,
219diff --git a/mt7915/mcu.c b/mt7915/mcu.c
developer663dccd2023-04-28 11:35:16 +0800220index 2a5ad033..512a9d5f 100644
developer1557f6c2023-04-13 18:48:23 +0800221--- a/mt7915/mcu.c
222+++ b/mt7915/mcu.c
developer663dccd2023-04-28 11:35:16 +0800223@@ -3752,6 +3752,189 @@ out:
developer1557f6c2023-04-13 18:48:23 +0800224 return ret;
225 }
226
227+static int
developer663dccd2023-04-28 11:35:16 +0800228+mt7915_mcu_parse_tx_gi(struct mt76_dev *dev, u8 mode, u8 gi, u8 bw,
229+ struct rate_info *rate)
developer1557f6c2023-04-13 18:48:23 +0800230+{
developer1557f6c2023-04-13 18:48:23 +0800231+ /* Legacy drivers only use 3 bits for PHY mode. For backward
232+ * compatibility, HE and newer PHY mode indices are remapped
233+ * to the extended bits.
234+ */
235+ if (u8_get_bits(mode, MT_PHY_TYPE_LEGACY) == MT_PHY_TYPE_HE_REMAP)
236+ mode = u8_get_bits(mode, MT_PHY_TYPE_EXT);
237+
238+ switch (mode) {
239+ case MT_PHY_TYPE_CCK:
240+ case MT_PHY_TYPE_OFDM:
241+ break;
242+ case MT_PHY_TYPE_HT:
243+ case MT_PHY_TYPE_HT_GF:
244+ case MT_PHY_TYPE_VHT:
245+ if (gi)
246+ rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
247+ break;
248+ case MT_PHY_TYPE_HE_SU:
249+ case MT_PHY_TYPE_HE_EXT_SU:
250+ case MT_PHY_TYPE_HE_TB:
251+ case MT_PHY_TYPE_HE_MU:
developer663dccd2023-04-28 11:35:16 +0800252+ if (!is_mt7915(dev)) {
253+ switch (bw) {
254+ case MCU_PHY_BW_20:
255+ gi = u8_get_bits(gi, HE_GI_BW_20);
256+ break;
257+ case MCU_PHY_BW_40:
258+ gi = u8_get_bits(gi, HE_GI_BW_40);
259+ break;
260+ case MCU_PHY_BW_80:
261+ gi = u8_get_bits(gi, HE_GI_BW_80);
262+ break;
263+ case MCU_PHY_BW_160:
264+ gi = u8_get_bits(gi, HE_GI_BW_160);
265+ break;
266+ default:
267+ return -EINVAL;
268+ }
developer1557f6c2023-04-13 18:48:23 +0800269+ }
270+
271+ if (gi > NL80211_RATE_INFO_HE_GI_3_2)
272+ return -EINVAL;
273+
274+ rate->he_gi = gi;
275+ break;
276+ default:
277+ return -EINVAL;
278+ }
279+
280+ return 0;
281+}
282+
developer663dccd2023-04-28 11:35:16 +0800283+int mt7915_mcu_get_tx_rate_v1(struct mt7915_phy *phy, u16 wcidx)
developer1557f6c2023-04-13 18:48:23 +0800284+{
285+ struct ieee80211_tx_status status = {};
developer663dccd2023-04-28 11:35:16 +0800286+ struct mt7915_mcu_ra_info_v1 *rate;
developer1557f6c2023-04-13 18:48:23 +0800287+ struct mt7915_dev *dev = phy->dev;
288+ struct mt76_phy *mphy = phy->mt76;
developer1557f6c2023-04-13 18:48:23 +0800289+ struct mt76_wcid *wcid;
290+ struct sk_buff *skb;
291+ int ret;
292+
293+ struct {
developer663dccd2023-04-28 11:35:16 +0800294+ __le32 category;
295+ u8 wcidx_lo;
296+ u8 band;
297+ u8 wcidx_hi;
298+ u8 rsv[5];
299+ } req = {
300+ .category = cpu_to_le32(MCU_GET_TX_RATE),
301+ .wcidx_lo = to_wcid_lo(wcidx),
302+ .band = mphy->band_idx,
303+ .wcidx_hi = to_wcid_hi(wcidx)
304+ };
305+
306+ ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_QUERY(GET_TX_STAT),
307+ &req, sizeof(req), true, &skb);
308+ if (ret)
309+ return ret;
310+
311+ rate = (struct mt7915_mcu_ra_info_v1 *)skb->data;
312+ if ((rate->wcidx_hi << 8 | rate->wcidx_lo) != wcidx) {
313+ ret = -EINVAL;
314+ goto out;
315+ }
316+
317+ rcu_read_lock();
318+ wcid = rcu_dereference(dev->mt76.wcid[wcidx]);
319+ if (!wcid) {
320+ ret = -EINVAL;
321+ goto unlock;
322+ }
323+
324+ ret = mt7915_mcu_parse_tx_gi(mphy->dev, rate->mode, rate->gi,
325+ rate->bw, &wcid->rate);
326+ if (ret)
327+ goto unlock;
328+
329+ status.sta = wcid_to_sta(wcid);
330+ if (!status.sta) {
331+ ret = -EINVAL;
332+ goto unlock;
333+ }
334+ status.rate = &wcid->rate;
335+ ieee80211_tx_status_ext(mphy->hw, &status);
336+unlock:
337+ rcu_read_unlock();
338+out:
339+ dev_kfree_skb(skb);
340+
341+ return ret;
342+}
343+
344+int mt7915_mcu_get_tx_rate_v2(struct mt7915_phy *phy, u16 wcidx)
345+{
346+ struct ieee80211_tx_status status = {};
347+ struct mt7915_mcu_ra_info_v2 *rate;
348+ struct mt7915_dev *dev = phy->dev;
349+ struct mt76_phy *mphy = phy->mt76;
350+ struct mt76_wcid *wcid;
351+ struct sk_buff *skb;
352+ int ret;
353+
354+ struct {
developer1557f6c2023-04-13 18:48:23 +0800355+ u8 category;
356+ u8 band;
357+ __le16 wcidx;
358+ } req = {
359+ .category = MCU_GET_TX_RATE,
360+ .band = mphy->band_idx,
361+ .wcidx = cpu_to_le16(wcidx)
362+ };
363+
364+ ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_QUERY(GET_TX_STAT),
365+ &req, sizeof(req), true, &skb);
366+ if (ret)
367+ return ret;
368+
developer663dccd2023-04-28 11:35:16 +0800369+ rate = (struct mt7915_mcu_ra_info_v2 *)skb->data;
developer1557f6c2023-04-13 18:48:23 +0800370+ if (le16_to_cpu(rate->wcidx) != wcidx) {
371+ ret = -EINVAL;
372+ goto out;
373+ }
374+
375+ rcu_read_lock();
376+ wcid = rcu_dereference(dev->mt76.wcid[wcidx]);
377+ if (!wcid) {
378+ ret = -EINVAL;
379+ goto unlock;
380+ }
381+
developer663dccd2023-04-28 11:35:16 +0800382+ ret = mt7915_mcu_parse_tx_gi(mphy->dev, rate->mode, rate->gi,
383+ rate->bw, &wcid->rate);
developer1557f6c2023-04-13 18:48:23 +0800384+ if (ret)
385+ goto unlock;
386+
387+ status.sta = wcid_to_sta(wcid);
388+ if (!status.sta) {
389+ ret = -EINVAL;
390+ goto unlock;
391+ }
392+ status.rate = &wcid->rate;
393+ ieee80211_tx_status_ext(mphy->hw, &status);
394+unlock:
395+ rcu_read_unlock();
396+out:
397+ dev_kfree_skb(skb);
398+
399+ return ret;
400+}
401+
developer663dccd2023-04-28 11:35:16 +0800402+int mt7915_mcu_get_tx_rate(struct mt7915_phy *phy, u16 wcidx)
403+{
404+ if (is_mt7915(&phy->dev->mt76))
405+ return mt7915_mcu_get_tx_rate_v1(phy, wcidx);
406+ else
407+ return mt7915_mcu_get_tx_rate_v2(phy, wcidx);
408+}
409+
developer1557f6c2023-04-13 18:48:23 +0800410 int mt7915_mcu_update_bss_color(struct mt7915_dev *dev, struct ieee80211_vif *vif,
411 struct cfg80211_he_bss_color *he_bss_color)
412 {
413diff --git a/mt7915/mcu.h b/mt7915/mcu.h
developer663dccd2023-04-28 11:35:16 +0800414index 1592b5d6..aebacc7d 100644
developer1557f6c2023-04-13 18:48:23 +0800415--- a/mt7915/mcu.h
416+++ b/mt7915/mcu.h
developer663dccd2023-04-28 11:35:16 +0800417@@ -152,6 +152,61 @@ struct mt7915_mcu_eeprom_info {
developer1557f6c2023-04-13 18:48:23 +0800418 u8 data[16];
419 } __packed;
420
421+enum {
422+ MCU_PHY_BW_20 = 0,
423+ MCU_PHY_BW_40,
424+ MCU_PHY_BW_80,
425+ MCU_PHY_BW_160,
426+ MCU_PHY_BW_10,
427+ MCU_PHY_BW_5,
428+ MCU_PHY_BW_8080,
429+ MCU_PHY_BW_320,
430+ MCU_PHY_BW_NUM
431+};
432+
433+#define HE_GI_BW_20 GENMASK(1, 0)
434+#define HE_GI_BW_40 GENMASK(3, 2)
435+#define HE_GI_BW_80 GENMASK(5, 4)
436+#define HE_GI_BW_160 GENMASK(7, 6)
437+
developer663dccd2023-04-28 11:35:16 +0800438+struct mt7915_mcu_ra_info_v1 {
439+ u8 wcidx_lo;
440+ u8 band;
441+ u8 wcidx_hi;
442+ u8 rsv1[46];
443+
444+ u8 mode;
445+ u8 flags;
446+ u8 stbc;
447+ u8 gi;
448+ u8 bw;
449+ u8 ldpc;
450+ u8 mcs;
451+ u8 nss;
452+ u8 ltf;
453+
454+ u8 rsv2[8];
455+};
456+
457+struct mt7915_mcu_ra_info_v2 {
developer1557f6c2023-04-13 18:48:23 +0800458+ u8 category;
459+ u8 rsv1;
460+ __le16 num;
461+ __le16 wcidx;
462+
463+ u8 mode;
464+ u8 flags;
465+ u8 stbc;
466+ u8 gi;
467+ u8 bw;
468+ u8 ldpc;
469+ u8 mcs;
470+ u8 nss;
471+ u8 ltf;
472+
473+ u8 rsv2;
474+};
475+
476 struct mt7915_mcu_phy_rx_info {
477 u8 category;
478 u8 rate;
developer663dccd2023-04-28 11:35:16 +0800479@@ -527,4 +582,7 @@ mt7915_get_power_bound(struct mt7915_phy *phy, s8 txpower)
developer1557f6c2023-04-13 18:48:23 +0800480 return txpower;
481 }
482
483+enum {
484+ MCU_GET_TX_RATE = 4
485+};
486 #endif
487diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developer663dccd2023-04-28 11:35:16 +0800488index 6c401080..891d21ea 100644
developer1557f6c2023-04-13 18:48:23 +0800489--- a/mt7915/mt7915.h
490+++ b/mt7915/mt7915.h
491@@ -131,6 +131,7 @@ struct mt7915_sta {
492
493 struct list_head poll_list;
494 struct list_head rc_list;
495+ struct list_head stats_list;
496 u32 airtime_ac[8];
497
498 int ack_signal;
499@@ -280,6 +281,10 @@ struct mt7915_phy {
500 struct mib_stats mib;
501 struct mt76_channel_state state_ts;
502
503+ u8 stats_work_count;
504+ struct list_head stats_list;
505+ spinlock_t stats_lock;
506+
507 #ifdef CONFIG_NL80211_TESTMODE
508 struct {
509 u32 *reg_backup;
510@@ -553,6 +558,7 @@ int mt7915_mcu_get_chan_mib_info(struct mt7915_phy *phy, bool chan_switch);
511 int mt7915_mcu_get_temperature(struct mt7915_phy *phy);
512 int mt7915_mcu_set_thermal_throttling(struct mt7915_phy *phy, u8 state);
513 int mt7915_mcu_set_thermal_protect(struct mt7915_phy *phy);
514+int mt7915_mcu_get_tx_rate(struct mt7915_phy *phy, u16 wcidx);
515 int mt7915_mcu_get_rx_rate(struct mt7915_phy *phy, struct ieee80211_vif *vif,
516 struct ieee80211_sta *sta, struct rate_info *rate);
517 int mt7915_mcu_rdd_background_enable(struct mt7915_phy *phy,
518--
5192.18.0
520