[PATCH 19/28] wifi: mt76: mt7925: publish every link before sending any STA_REC

Emery Hsin emery.hsin at mediatek.com
Mon Nov 9 19:12:35 PST 2026


The MLD setup TLV is built from msta->link[], so a STA_REC sent while
later links are missing carries a partial MLD. Publish every link first,
then program them primary first. A single link to MLD upgrade re-adds the
primary with a new wcid on the reused deflink storage.

Signed-off-by: Emery Hsin <emery.hsin at mediatek.com>
---
 .../net/wireless/mediatek/mt76/mt7925/main.c  | 60 +++++++++++++++++--
 1 file changed, 56 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
index b497e904d4b5..a93df77da269 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
@@ -1212,6 +1212,9 @@ mt7925_mac_sta_add_links(struct mt792x_dev *dev, struct ieee80211_vif *vif,
 	unsigned int link_id;
 	int err = 0;
 
+	/* Publish every link before sending any STAREC, so the MLD setup TLV
+	 * describes the whole MLD.
+	 */
 	for_each_set_bit(link_id, &new_links, IEEE80211_MLD_MAX_NUM_LINKS) {
 		struct ieee80211_link_sta *link_sta;
 		struct mt792x_link_sta *mlink;
@@ -1220,6 +1223,26 @@ mt7925_mac_sta_add_links(struct mt792x_dev *dev, struct ieee80211_vif *vif,
 		if (msta->deflink_id == IEEE80211_LINK_UNSPECIFIED) {
 			mlink = &msta->deflink;
 			is_deflink = true;
+		} else if (link_id == msta->deflink_id &&
+			   rcu_access_pointer(msta->link[link_id]) ==
+			   &msta->deflink) {
+			/* Single link to MLD upgrade: re-add the primary with
+			 * a new wcid so it binds to the granted band. This runs
+			 * from the AUTHORIZE transition before mac80211 sets
+			 * WLAN_STA_AUTHORIZED, so no data is being sent on this
+			 * sta and reusing the deflink storage is safe.
+			 */
+			link_sta = mt792x_sta_to_link_sta(vif, sta, link_id);
+			if (mt7925_mcu_sta_update(dev, link_sta, vif,
+						  &msta->deflink, false,
+						  MT76_STA_INFO_STATE_NONE))
+				dev_dbg(dev->mt76.dev,
+					"failed to tear down the old STA_REC\n");
+			mt7925_mac_link_sta_free_wcid(&dev->mt76,
+						      &msta->deflink);
+			synchronize_rcu();
+			mlink = &msta->deflink;
+			is_deflink = true;
 		} else {
 			mlink = kzalloc_obj(*mlink);
 			if (!mlink) {
@@ -1236,8 +1259,17 @@ mt7925_mac_sta_add_links(struct mt792x_dev *dev, struct ieee80211_vif *vif,
 		err = mt7925_mac_link_sta_alloc(&dev->mt76, vif, link_sta,
 						mlink);
 		if (err) {
-			if (!is_deflink)
+			if (!is_deflink) {
 				kfree(mlink);
+			} else if (link_id == msta->deflink_id) {
+				/* the upgrade path above already freed the
+				 * deflink wcid, so unpublish it here instead
+				 * of freeing the shared wcid a second time
+				 */
+				rcu_assign_pointer(msta->link[link_id], NULL);
+				msta->valid_links &= ~BIT(link_id);
+				msta->deflink_id = IEEE80211_LINK_UNSPECIFIED;
+			}
 			break;
 		}
 
@@ -1246,13 +1278,33 @@ mt7925_mac_sta_add_links(struct mt792x_dev *dev, struct ieee80211_vif *vif,
 		if (is_deflink)
 			msta->deflink_id = link_id;
 
-		/* published into msta->link[]; let the unwind path free it */
 		added_links |= BIT(link_id);
+	}
+
+	/* Configure the primary link first, it anchors the MLD. */
+	if (!err && msta->deflink_id != IEEE80211_LINK_UNSPECIFIED &&
+	    (added_links & BIT(msta->deflink_id))) {
+		struct mt792x_link_sta *mlink =
+			mt792x_sta_to_link(msta, msta->deflink_id);
+		struct ieee80211_link_sta *link_sta =
+			mt792x_sta_to_link_sta(vif, sta, msta->deflink_id);
+
+		err = mt7925_mac_link_sta_add(&dev->mt76, vif, link_sta, mlink);
+	}
+	for_each_set_bit(link_id, &added_links,
+			 IEEE80211_MLD_MAX_NUM_LINKS) {
+		struct ieee80211_link_sta *link_sta;
+		struct mt792x_link_sta *mlink;
 
-		err = mt7925_mac_link_sta_add(&dev->mt76, vif, link_sta,
-					      mlink);
 		if (err)
 			break;
+		if (link_id == msta->deflink_id)
+			continue;
+
+		mlink = mt792x_sta_to_link(msta, link_id);
+		link_sta = mt792x_sta_to_link_sta(vif, sta, link_id);
+		err = mt7925_mac_link_sta_add(&dev->mt76, vif, link_sta,
+					      mlink);
 	}
 
 	if (err && added_links)
-- 
2.45.2




More information about the Linux-mediatek mailing list