Linux wireless drivers development
 help / color / mirror / Atom feed
From: Zichao-xu via B4 Relay <devnull+xvzichao2333.gmail.com@kernel.org>
To: linux-wireless@vger.kernel.org
Cc: Felix Fietkau <nbd@nbd.name>,
	Lorenzo Bianconi <lorenzo@kernel.org>,
	 Ryder Lee <ryder.lee@mediatek.com>,
	Shayne Chen <shayne.chen@mediatek.com>,
	 Sean Wang <sean.wang@mediatek.com>,
	linux-mediatek@lists.infradead.org,
	 Zichao-xu <xvzichao2333@gmail.com>
Subject: [PATCH RFC 2/3] wifi: mt76: mt7996: steer MLO data frames to the link the peer is active on
Date: Wed, 02 Dec 2026 16:52:35 +0900	[thread overview]
Message-ID: <20261202-rfc-v1-2-eff86f0bf9e6@gmail.com> (raw)
In-Reply-To: <20261202-rfc-v1-0-eff86f0bf9e6@gmail.com>

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)



  parent reply	other threads:[~2026-12-02  7:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202-rfc-v1-2-eff86f0bf9e6@gmail.com \
    --to=devnull+xvzichao2333.gmail.com@kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=nbd@nbd.name \
    --cc=ryder.lee@mediatek.com \
    --cc=sean.wang@mediatek.com \
    --cc=shayne.chen@mediatek.com \
    --cc=xvzichao2333@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox