From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B0C3606A32C for ; Wed, 2 Dec 2026 07:52:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=3kH2mMtR; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JEyB3Wp1 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:Cc:To:In-Reply-To:References:Message-Id: Content-Type:MIME-Version:Subject:Date:From:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=5IBTk9Vzs8lsXTDLurrTkyIsMwArulg6j3V/TenZ8Uo=; b=3kH2mMtRLX1GU3Rajvw0lRUrfU zTogup2Wb7aC2zTond3ZGF0VPKMyH7e1yNkcji5CnU7f2X32sgQ8KUjt3ESmVIaZUlIt7PvrajAn0 afqrpJlJVQZQ/Rx0PM7Imdt6cgwQ6+iyePHrhKs5ooWtu/D3d4AWgBaPDfHxJ+Vgbrv6aYqQ8ZbDQ 9xZla2SskusTY8VfUI5c6zIj7VZOAquLCklSU+OV2um4UOqgC7P6Z+O0GGlSh2jz1MByz7THvKYhe WrfgHGoZx9pOqbodGrIDSq3umCoBxe/EWdrEpM9n+9+Pi3wpaMIqGy8UsuiuMlNAJFxi3j/K5wyFG IdfNmu1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYf8s-0000000AZZC-0zTA; Wed, 02 Dec 2026 07:52:42 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYf8o-0000000AZWH-1kxG for linux-mediatek@lists.infradead.org; Wed, 02 Dec 2026 07:52:38 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 362D360600; Wed, 2 Dec 2026 07:52:37 +0000 (UTC) Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796197957; b=Wlzhkdevsy8sSrozz63TtrRIIDbz8W0s6vQawT6EPwFAciLA9yGAy0s/8riRNGRm9F8e KJc37ipmniZCFpjmjZppn8ncfH948h65KFkJWspNINH+uMuWcx66GvlRHGfaGI7trQE29 mRM3k9U+3Wiexuo/QDJ3mU7266zL3YXNyOxh+NzW1iU0H5Mtn44bkFXhfW3mDuGHxJJHa 14QnpDMY99H4R7Dx379873Gsc2ss7VwyPy5D1dU93lDOD2xBLphqpzlrdkGsQsCf9ME1q yAUY1T93jbsxxcv3MgO6rubwz1d5DDkH1BZSQzs7O/BHBLG86j4gdhrYpoSAfzr8ncQ== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796197957; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=5IBTk9Vzs8lsXTDLurrTkyIsMwArulg6j3V/TenZ8Uo=; b=LtLdAURBLK+IIn2mI4ocAR0njhiRDOjBRP6ywehgPLT9uJfG0bt8/0z3UzcbHSp8dcvN rtY5ScS9VDU2qyi71S/nQgJgkWGD+80AIMcImqMYQwgGqpoXVKrtgqV1iz+OoXAFHZz+9 Kh0FOVB9a1Q7WleS6C7MhAvRJ9gge/aWChNXWWSBgnKQLVO3ZwqCgLA4jCbJ5KnRonJuw f+cLzOtIjubQR5+IFuPHaFyK1pBW8oBRlWfmW6Pa4oqKfL1vrOafazPvB5Ans09AjIdeQ x2TJNhcbWQ81c6QDrgRdvouk3XntceUq3K+JzwzxvHHYEFQ1keRBIazvKlPi2hgBiyg== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id F004A1F00929; Wed, 2 Dec 2026 07:52:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796197957; bh=5IBTk9Vzs8lsXTDLurrTkyIsMwArulg6j3V/TenZ8Uo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=JEyB3Wp1OQR45eRdZsfd1O2Sehl6xzUCo5SSYJg4StGBLtdEpAGKqh0PSu9q8cH6o MjJw2wRrQAi81jLzmDKrXAK3CcB8IPQqhycos6R+FcKkjvgxwzWI/1f6r/m1MYf3Oa fu4QSVsGIoRhGfhrF8jUd0FtkgDjFQ/ht2wJwEYMlxrWcB9+SvcqW43vSgvAHSJAPJ 7TRNyE0VGUTsWhytV0OTKJr181aYvtlWdDM31eHCDYsFaJS5l6HlLRjbAfsj0ePluo kZsQo7/hkvgWZYrd/RjMtrbPWa7d6YYRq3ijt0154MgFfmM1md0/bY7zr2k/uW+hF1 Y22rc5TylK63A== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 7C7CF4F2EB; Wed, 2 Dec 2026 07:52:35 +0000 (UTC) From: Zichao-xu via B4 Relay Date: Wed, 02 Dec 2026 16:52:35 +0900 Subject: [PATCH RFC 2/3] wifi: mt76: mt7996: steer MLO data frames to the link the peer is active on X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261202-rfc-v1-2-eff86f0bf9e6@gmail.com> References: <20261202-rfc-v1-0-eff86f0bf9e6@gmail.com> In-Reply-To: <20261202-rfc-v1-0-eff86f0bf9e6@gmail.com> To: linux-wireless@vger.kernel.org Cc: Felix Fietkau , Lorenzo Bianconi , Ryder Lee , Shayne Chen , Sean Wang , linux-mediatek@lists.infradead.org, Zichao-xu X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796197954; l=9038; i=xvzichao2333@gmail.com; s=20261202; h=from:subject:message-id; bh=zuy+xwUFz6xf/eoAehy7zzMx2eDhrcZIFGKwmJb/H7A=; b=JPZmIix2XRyMxUTWAmep+HVJZ3cqbyPYZ+GryNIa7RNVXzEj4k5FDM1DYMCmFKz+HhTf6jECn JMVSylo5mYQB3iyUA6wOCt3Zl3tuZnRBz0mw+qbJAFfpmy+IUgBQgxu X-Developer-Key: i=xvzichao2333@gmail.com; a=ed25519; pk=4y2PCqVVaZTmU/wzky/gd6WColWnjFznkFN8fXd+GMI= X-Endpoint-Received: by B4 Relay for xvzichao2333@gmail.com/20261202 with auth_id=1717 X-Original-From: Zichao-xu Content-Transfer-Encoding: 7bit X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: xvzichao2333@gmail.com Sender: "Linux-mediatek" X-Spam-Status: No, score=-16.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, FREEMAIL_REPLYTO_END_DIGIT,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 From: Zichao-xu 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 --- 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)