wifi: mt76: mt7996: fix TX stalls of MLO clients that switch links
Subsystems (2)
cover wifi: mt76: mt7996: fix TX stalls of MLO clients that switch links
Hi,
On a Banana Pi BPI-R4 with the tri-band MT7996 NIC, running a single AP MLD (2.4 + 5 + 6 GHz links), MLO clients regularly stop receiving anything while they keep sending: the backlog of the station in mac80211 grows to hundreds of frames, the head fid of its AC queue in the PLE (hw-queues debugfs) does not move, and only a disassociation recovers. While the station is stuck, its backlog can also fill the UDP send buffer of dnsmasq, which breaks DNS for the whole LAN, as reported in openwrt/mt76 #1195.
Base: openwrt/mt76 master 10be1829 (2026-11-27), firmware build 20260721 (WM/WA/DSP), clients: two phones with 2.4 + 5 GHz MLO links, one of them an iPhone using eMLSR. Without these patches (and with earlier attempts that only looked at the PS state) a station got stuck 12 times in 7 days, detected and recovered by a userspace watchdog that disassociates the station once its TX counter stops moving with a backlog.
I found two ways for frames to get stuck on a link the client does not receive on:
1. The data frames of an MLO peer are mapped to a link by TID parity, so some of them go to a link the client is not active on (patch 2).
2. When the client moves to another link, frames already queued for the old link stay there (patch 3).
In both cases the stuck frames count against MT_MAX_NON_AQL_PKT, which is shared by all links of the peer, so TX to the peer stops on every link.
The per-link PS state reported through PS_SYNC does not tell which link the client is on: for these clients it toggles on both links together, also on the link the client never sends anything on. (mac80211 does not see the PS state of MLD peers at all, see openwrt/mt76 #1196.) So patch 2 uses the link of the last unicast RX instead.
Testing so far: with patches 1 and 2 the board ran 21 hours with one stall, the case fixed by patch 3. Patch 3 has only been running since today, hence RFC. I will follow up with results after a few days.
Questions for MediaTek:
- Is the firmware expected to keep holding the frames of a link while an eMLSR client dozes there but is active on another link? Is there a firmware mechanism to move such frames to another link, or to flush the queue of one link, that the driver should use instead of patch 3?
- Is the PS state that PS_SYNC reports for an MLD peer meant to be per link?
- Is STA_REC_PS_LEAVE valid for any peer on MT7996 firmware, or only for the 4-address case it is used for today?
---
Zichao-xu (3):
wifi: mt76: limit non-AQL frames queued for a sleeping station
wifi: mt76: mt7996: steer MLO data frames to the link the peer is active on
wifi: mt76: mt7996: wake a link that an MLO peer left with frames queued
drivers/net/wireless/mediatek/mt76/mt76.h | 1 + drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 111 +++++++++++++++++++++ drivers/net/wireless/mediatek/mt76/mt7996/mcu.c | 68 ++++++++++++- drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h | 18 ++++ drivers/net/wireless/mediatek/mt76/tx.c | 9 ++ 5 files changed, 204 insertions(+), 3 deletions(-)
---
base: openwrt/mt76 10be1829783cff271f5e81111258387a72b5192b (master, 2026-11-27)
change-id: 20261202-rfc-1e223d88d444
Best regards,
Signature · 1 line
Zichao-xu <[email protected]>
RFC PATCH 1/3 wifi: mt76: limit non-AQL frames queued for a sleeping station
Frames without an airtime estimate, such as those of an MLO station, get past the AQL check in mt76_txq_send_burst() while the station is in power save. They stay in the firmware until the station wakes up and count against MT_MAX_NON_AQL_PKT meanwhile. That limit is shared by all links of an MLO station, so frames parked on a link the station dozes on can use it up and stop TX to the station on its other links as well.
Only queue up to MT_MAX_PS_NON_AQL_PKT (4) such frames while the station is in power save.
--- drivers/net/wireless/mediatek/mt76/mt76.h | 1 + drivers/net/wireless/mediatek/mt76/tx.c | 9 +++++++++ 2 files changed, 10 insertions(+)
drivers/net/wireless/mediatek/mt76/mt76.h +1 -0
@@ -30,6 +30,7 @@#define MT_SKB_HEAD_LEN 256#define MT_MAX_NON_AQL_PKT 16 +#define MT_MAX_PS_NON_AQL_PKT 4#define MT_TXQ_FREE_THR 32#define MT76_TOKEN_FREE_THR 64
drivers/net/wireless/mediatek/mt76/tx.c +9 -0
@@ -550,6 +550,15 @@ mt76_txq_send_burst(struct mt76_phy *phy, struct mt76_queue *q,return 0 ;if (ieee80211_txq_aql_pending (phy->hw, txq))return 0 ; +/* +* Frames without an airtime estimate (e.g. those of an MLO +* peer) get past the AQL check above. They stay in the +* firmware until the peer wakes up and count against the +* non-AQL limit of the peer meanwhile, so only park a few. +*/ +if (atomic_read (&mt76_wcid_primary (wcid)->non_aql_packets) >= +MT_MAX_PS_NON_AQL_PKT ) +return 0 ; } if (atomic_read(&mt76_wcid_primary(wcid)->non_aql_packets) >=
Signature · 1 line
Git-157)
RFC PATCH 2/3 wifi: mt76: mt7996: steer MLO data frames to the link the peer is active on
In reply to Zichao-xumt7996_tx_prepare_skb() maps the data frames of an MLO peer to a link by TID parity: odd TIDs go to the secondary link, even TIDs to the default link. The firmware only releases the frames of a link while the peer receives on that link, but an eMLSR peer only receives on the link it is currently active on, and an MLO peer may doze on one link for as long as it likes while it is active on another one. Frames mapped to the other link then stay in its LMAC queue.
Seen on MT7996 with a phone associated on 2.4 GHz + 5 GHz: the phone was active on 2.4 GHz (unicast RX 20 ms before) and had not sent anything on 5 GHz for 13 s, while all of its TXQs pointed at the 5 GHz wcid. 41 frames sat in the AC3 PLE queue of the 5 GHz wcid with the head fid unchanged over 2 s, 42 non-AQL frames were pending, and the backlog in mac80211 grew to 595 frames until the station was disconnected.
The per-link PS state reported through PS_SYNC does not help to pick the
link: for such a peer both links toggled together (26900 transitions on each link in 54 minutes), including on the link the peer did not send anything on.
Record the link and time of the last unicast frame received from an MLO peer, and steer its data frames to that link if the peer was active on it within the last 2 s. Without recent RX, do not steer a frame to a dozing link while the other link is awake, and if the peer dozes on both links, use the link it was last active on.
The TX scheduler takes the PS state of a peer from the wcid its TXQs point at, so on every PS transition also point the TXQs of an MLO peer at the same link.
--- drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 48 +++++++++++++++ drivers/net/wireless/mediatek/mt76/mt7996/mcu.c | 68 +++++++++++++++++++++- drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h | 17 ++++++ 3 files changed, 130 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +48 -0
@@ -497,6 +497,10 @@ mt7996_mac_fill_rx(struct mt7996_dev *dev, enum mt76_rxq_id q, wcid); msta = msta_link->sta;mt76_wcid_add_poll (&dev->mt76, &msta_link->wcid); +if (msta && unicast) { +WRITE_ONCE (msta->last_rx_link, msta_link->wcid.link_id); +WRITE_ONCE (msta->last_rx_jiffies, jiffies); + } } status->freq = mphy->chandef.chan->center_freq;
@@ -1055,6 +1059,49 @@ mt7996_tx_use_mgmt(struct mt7996_dev *dev, struct sk_buff *skb)return false; } +/* +* The firmware holds the frames of a link until the peer receives on that +* link. An eMLSR peer only receives on the link it is active on, and an MLO +* peer may doze on one link for as long as it likes while it is active on +* another one, so frames steered to the other link get stuck in its LMAC +* queue. +* +* The per-link PS state reported by the firmware for an MLO peer toggles on +* all links together, so prefer the link the peer was recently active on. +* Without recent RX, do not steer to a dozing link while the other one is +* awake, and if the peer dozes on both links, use the link it was last +* active on. +*/ +static u8 +mt7996_tx_awake_link (struct mt7996_sta *msta,u8 link_id) +{ +struct mt7996_sta_link *link, *alt; +u8 alt_id, rx_id; + + alt_id = link_id == msta->deflink_id ? msta->seclink_id : + msta->deflink_id; +if (alt_id ==IEEE80211_LINK_UNSPECIFIED || alt_id == link_id) +return link_id; + + alt =mt7996_sta_link (msta, alt_id); +if (!alt || !alt->wcid.link_valid) +return link_id; + + rx_id =mt7996_sta_active_link (msta); +if (rx_id == link_id || rx_id == alt_id) +return rx_id; + + link =mt7996_sta_link (msta, link_id); +if (!link || !test_bit (MT_WCID_FLAG_PS , &link->wcid.flags)) +return link_id; + +if (test_bit (MT_WCID_FLAG_PS , &alt->wcid.flags) && +READ_ONCE (msta->last_rx_link) != alt_id) +return link_id; + +return alt_id; +} + int mt7996_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, enum mt76_txq_id qid, struct mt76_wcid *wcid, struct ieee80211_sta *sta,
@@ -1087,6 +1134,7 @@ int mt7996_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,u8 tid = tx_info->skb->priority &IEEE80211_QOS_CTL_TID_MASK ; link_id = (tid %2 ) ? msta->seclink_id : msta->deflink_id; + link_id =mt7996_tx_awake_link (msta, link_id); }else if (is_8023) {/* mac80211 does not set the MLO link of an 802.3 frame */ link_id =IEEE80211_LINK_UNSPECIFIED ;
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +65 -3
92 lines not on this page · raw message
drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +17 -0
@@ -326,6 +326,9 @@ struct mt7996_sta {struct mt7996_sta_link __rcu *link[IEEE80211_MLD_MAX_NUM_LINKS ];u8 deflink_id;u8 seclink_id; +/* link and time of the last unicast frame received from the peer */ +u8 last_rx_link; +unsigned long last_rx_jiffies;u8 conn_state;u16 peer_mld_links;u16 fw_mld_idx;
@@ -749,6 +752,20 @@ mt7996_sta_link(struct mt7996_sta *msta, u8 link_id)return rcu_dereference (msta->link[link_id]); } +#define MT7996_RX_LINK_TIMEOUT (2 * HZ) + +/* link that an MLO peer sent its last unicast frame on, if done recently */ +static inline u8 +mt7996_sta_active_link (struct mt7996_sta *msta) +{ +unsigned long t =READ_ONCE (msta->last_rx_jiffies); + +if (!t ||time_after (jiffies, t +MT7996_RX_LINK_TIMEOUT )) +return IEEE80211_LINK_UNSPECIFIED ; + +return READ_ONCE (msta->last_rx_link); +} +static inline struct mt7996_sta_link *mt7996_sta_link_protected (struct mt7996_dev *dev,struct mt7996_sta *msta,u8 link_id)
Signature · 1 line
Git-157)
RFC PATCH 3/3 wifi: mt76: mt7996: wake a link that an MLO peer left with frames queued
In reply to Zichao-xuAn MLO peer that moves to another link can leave frames in the LMAC queue of the link it left, and the firmware holds them for as long as it considers the peer dozing there. They count against the non-AQL limit shared by all links of the peer, so the peer stops being served on every link, including the one it is active on.
Seen on MT7996 with the previous patch applied: the peer was active on 5 GHz (unicast RX 70 ms before) and all of its TXQs pointed at the 5 GHz wcid, but 36 frames were left in the AC3 PLE queue of its 2.4 GHz wcid (head fid unchanged over 2 s, no RX on 2.4 GHz for 25 s). 37 non-AQL frames were pending, so nothing was sent to the peer on 5 GHz either, and the backlog in mac80211 grew until the station was disconnected.
From mac_work, look for MLO peer links that are in PS while the peer was recently active on another link and at least MT_MAX_NON_AQL_PKT / 2 non-AQL frames are pending, and send STA_REC_PS_LEAVE for such a link, at most once per second per link, so that the firmware sends or drops the frames held there. mt7996_mcu_ps_leave() is already used to work around a missed PS exit of 4-address peers.
--- drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 63 ++++++++++++++++++++++ drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h | 1 + 2 files changed, 64 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +63 -0
@@ -3179,6 +3179,68 @@ void mt7996_mac_sta_rc_work(struct work_struct *work)mutex_unlock (&dev->mt76.mutex); } +/* +* An MLO peer that moves to another link can leave frames in the LMAC queue +* of the link it left, and the firmware holds them for as long as it +* considers the peer dozing there. They count against the non-AQL limit +* shared by all links of the peer, so the peer stops being served on every +* link. Ask the firmware to wake the left link, so those frames are sent or +* fail. +*/ +static void +mt7996_mac_mlo_ps_leave_check (struct mt7996_phy *phy) +{ +struct mt7996_dev *dev = phy->dev; +int i; + +lockdep_assert_held (&dev->mt76.mutex); + +for (i =0 ; i <mt7996_wtbl_size (dev); i++) { +struct mt7996_sta_link *msta_link; +struct mt7996_vif_link *link; +struct ieee80211_sta *sta; +struct mt7996_sta *msta; +struct mt76_wcid *wcid; +u8 link_id, rx_id; + + wcid =mt76_dereference (dev->mt76.wcid[i], &dev->mt76); +if (!wcid || wcid->phy_idx != phy->mt76->band_idx || + !test_bit (MT_WCID_FLAG_PS , &wcid->flags)) +continue ; + + sta =wcid_to_sta (wcid); +if (!sta || !sta->mlo) +continue ; + + msta_link = container_of(wcid, struct mt7996_sta_link, wcid); + msta = msta_link->sta; + link_id = wcid->link_id; +if (!msta || !msta->vif || + link_id >=IEEE80211_MLD_MAX_NUM_LINKS ) +continue ; + + rx_id =mt7996_sta_active_link (msta); +if (rx_id ==IEEE80211_LINK_UNSPECIFIED || rx_id == link_id) +continue ; + +if (atomic_read (&mt76_wcid_primary (wcid)->non_aql_packets) < +MT_MAX_NON_AQL_PKT /2 ) +continue ; + +if (time_before (jiffies, msta->ps_leave_jiffies[link_id] +HZ )) +continue ; + + link = (struct mt7996_vif_link *) +mt76_dereference (msta->vif->mt76.link[link_id], + &dev->mt76); +if (!link) +continue ; + + msta->ps_leave_jiffies[link_id] = jiffies; +mt7996_mcu_ps_leave (dev, link, msta_link); + } +} +void mt7996_mac_work (struct work_struct *work) {struct mt7996_phy *phy;
@@ -3191,6 +3253,7 @@ void mt7996_mac_work(struct work_struct *work)mutex_lock (&mphy->dev->mutex);mt76_update_survey (mphy); +mt7996_mac_mlo_ps_leave_check (phy);if (++mphy->mac_work_count ==5 ) { mphy->mac_work_count =0 ;
drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +1 -0
@@ -329,6 +329,7 @@ struct mt7996_sta {/* link and time of the last unicast frame received from the peer */ u8 last_rx_link;unsigned long last_rx_jiffies; +unsigned long ps_leave_jiffies[IEEE80211_MLD_MAX_NUM_LINKS ];u8 conn_state;u16 peer_mld_links;u16 fw_mld_idx;
Signature · 1 line
Git-157)
Quoted 3 lines · Zichao-xu
On a Banana Pi BPI-R4 with the tri-band MT7996 NIC, running a single AP MLD (2.4 + 5 + 6 GHz links), MLO clients regularly stop receiving anything while they keep sending: [...]
Adding Stanley and Peter, who have been working on MLO and PS handling in mt7996.
Peter, patch 3 reuses mt7996_mcu_ps_leave() from your 4-address fix ("wifi: mt76: mt7996: leave PS when a 4-address connection is established"). I would appreciate your view on whether STA_REC_PS_LEAVE is the right way to release frames that the firmware holds on a link an MLO peer has left, or whether the firmware offers a better mechanism.