* [PATCH RFC 2/3] wifi: mt76: mt7996: steer MLO data frames to the link the peer is active on
2026-12-02 7:52 [PATCH RFC 0/3] wifi: mt76: mt7996: fix TX stalls of MLO clients that switch links Zichao-xu via B4 Relay
2026-12-02 7:52 ` [PATCH RFC 1/3] wifi: mt76: limit non-AQL frames queued for a sleeping station Zichao-xu via B4 Relay
@ 2026-12-02 7:52 ` Zichao-xu via B4 Relay
2026-12-02 7:52 ` [PATCH RFC 3/3] wifi: mt76: mt7996: wake a link that an MLO peer left with frames queued Zichao-xu via B4 Relay
2026-12-02 7:58 ` [PATCH RFC 0/3] wifi: mt76: mt7996: fix TX stalls of MLO clients that switch links Zichao-xu
3 siblings, 0 replies; 5+ messages in thread
From: Zichao-xu via B4 Relay @ 2026-12-02 7:52 UTC (permalink / raw)
To: linux-wireless
Cc: Felix Fietkau, Lorenzo Bianconi, Ryder Lee, Shayne Chen,
Sean Wang, linux-mediatek, Zichao-xu
From: Zichao-xu <xvzichao2333@gmail.com>
mt7996_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.
Signed-off-by: Zichao-xu <xvzichao2333@gmail.com>
---
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(-)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
index 6aa0767..d046fed 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
@@ -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;
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
index bcb4a89..14b8c27 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
@@ -977,21 +977,82 @@ mt7996_mcu_wed_rro_event(struct mt7996_dev *dev, struct sk_buff *skb)
}
}
+/*
+ * The TX scheduler takes the PS state of a peer from the wcid that the TXQs
+ * of the peer point at. The PS state that the firmware reports is per link,
+ * so point the TXQs of an MLO peer at the link it was recently active on,
+ * else at an awake link while it has one: the default link when it is awake,
+ * else the secondary link. A peer is then treated as asleep only while it
+ * dozes on all of its TX links, and then the TXQs point at the link it was
+ * last active on.
+ */
+static void
+mt7996_mcu_ps_update_txq_link(struct mt7996_dev *dev, struct ieee80211_sta *sta)
+{
+ struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
+ struct mt7996_sta_link *def, *sec;
+ struct mt76_wcid *target;
+ u8 rx_id;
+ int i;
+
+ if (!sta->mlo)
+ return;
+
+ def = mt7996_sta_link(msta, msta->deflink_id);
+ if (!def)
+ return;
+
+ target = &def->wcid;
+ sec = mt7996_sta_link(msta, msta->seclink_id);
+ rx_id = mt7996_sta_active_link(msta);
+ if (sec && sec != def && sec->wcid.link_valid &&
+ (rx_id == msta->seclink_id ||
+ (rx_id != msta->deflink_id &&
+ test_bit(MT_WCID_FLAG_PS, &def->wcid.flags) &&
+ (!test_bit(MT_WCID_FLAG_PS, &sec->wcid.flags) ||
+ READ_ONCE(msta->last_rx_link) == msta->seclink_id))))
+ target = &sec->wcid;
+
+ for (i = 0; i < ARRAY_SIZE(sta->txq); i++) {
+ struct mt76_txq *mtxq;
+
+ if (!sta->txq[i])
+ continue;
+
+ mtxq = (struct mt76_txq *)sta->txq[i]->drv_priv;
+ if (mtxq->wcid == target->idx)
+ continue;
+
+ WRITE_ONCE(mtxq->wcid, target->idx);
+ ieee80211_schedule_txq(mt76_phy_hw(&dev->mt76, target->phy_idx),
+ sta->txq[i]);
+ }
+
+ mt76_worker_schedule(&dev->mt76.tx_worker);
+}
+
static void
mt7996_mcu_ps_transition(struct mt7996_dev *dev, u16 wcid_idx, bool ps)
{
struct mt7996_sta_link *msta_link;
+ struct ieee80211_sta *sta;
struct mt76_wcid *wcid;
+ rcu_read_lock();
+
wcid = mt76_wcid_ptr(dev, wcid_idx);
- if (!wcid || !wcid_to_sta(wcid))
- return;
+ sta = wcid ? wcid_to_sta(wcid) : NULL;
+ if (!sta)
+ goto out;
msta_link = container_of(wcid, struct mt7996_sta_link, wcid);
if (ps && READ_ONCE(msta_link->twt.flowid_mask))
- return;
+ goto out;
mt76_sta_ps_transition(&dev->mt76, wcid, ps);
+ mt7996_mcu_ps_update_txq_link(dev, sta);
+out:
+ rcu_read_unlock();
}
static void
@@ -1065,6 +1126,7 @@ mt7996_mcu_rx_ps_sync(struct mt7996_dev *dev, struct sk_buff *skb)
ps = bitmap[i / 8] & BIT(i % 8);
mt76_sta_ps_transition(&dev->mt76, wcid, ps);
+ mt7996_mcu_ps_update_txq_link(dev, sta);
}
break;
}
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
index 94555a6..e7d8c3c 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
@@ -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)
--
Git-157)
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH RFC 3/3] wifi: mt76: mt7996: wake a link that an MLO peer left with frames queued
2026-12-02 7:52 [PATCH RFC 0/3] wifi: mt76: mt7996: fix TX stalls of MLO clients that switch links Zichao-xu via B4 Relay
2026-12-02 7:52 ` [PATCH RFC 1/3] wifi: mt76: limit non-AQL frames queued for a sleeping station Zichao-xu via B4 Relay
2026-12-02 7:52 ` [PATCH RFC 2/3] wifi: mt76: mt7996: steer MLO data frames to the link the peer is active on Zichao-xu via B4 Relay
@ 2026-12-02 7:52 ` Zichao-xu via B4 Relay
2026-12-02 7:58 ` [PATCH RFC 0/3] wifi: mt76: mt7996: fix TX stalls of MLO clients that switch links Zichao-xu
3 siblings, 0 replies; 5+ messages in thread
From: Zichao-xu via B4 Relay @ 2026-12-02 7:52 UTC (permalink / raw)
To: linux-wireless
Cc: Felix Fietkau, Lorenzo Bianconi, Ryder Lee, Shayne Chen,
Sean Wang, linux-mediatek, Zichao-xu
From: Zichao-xu <xvzichao2333@gmail.com>
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, 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.
Signed-off-by: Zichao-xu <xvzichao2333@gmail.com>
---
drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 63 ++++++++++++++++++++++
drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h | 1 +
2 files changed, 64 insertions(+)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
index d046fed..cad6430 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
@@ -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;
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
index e7d8c3c..48fa58d 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
@@ -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;
--
Git-157)
^ permalink raw reply related [flat|nested] 5+ messages in thread