Skip to contentSkip to conversation

wifi: mt76: mt7996: name a new secondary link to the firmware first

PATCH New Felix Fietkau 1 participant 17 messages Nov 21

Subsystems (2)
lore
Share & tools
lore

Felix Fietkau

author maintainer
#0 lore raw

PATCH 1/17 wifi: mt76: mt7996: name a new secondary link to the firmware first

The driver sends no MLD setup when links only go away, so the firmware keeps the primary and secondary link of the last MLD setup. If a link of that pair goes from a station with three or more links, mt7996_mac_sta_remove_link() picks a secondary link outside the pair. Frames of odd TIDs then carry an MLD_ID that commit ce35ecffc96e ("wifi: mt76: mt7996: fix MLD ID in MAC TXD and HIF TXP") reports as a cause of a firmware busy loop when that link is in power save.

mt7996_mac_sta_init_link() and the path of mt7996_mac_sta_add_links() that takes back a kept link also pick the secondary link at once. When a station with one link gets a new link, that pick is the new link. Until mt7996_mac_sta_links_sync(), the firmware has no station record, key or link pair for it, but mt7996_tx_prepare_skb() already puts frames of odd TIDs on its WLAN_IDX. Both cases are reachable via mt7996_mac_sta_change_links() when mac80211 changes the link stations.

Pick the secondary link of a new station once all its links exist. For a link change, pick it in mt7996_mac_sta_links_sync(), after the MLD setup of a joining link, which names it, or at once for a station that is not connected, since the firmware holds no link pair for it. Until then, keep the TX on the remaining link of the pair, so the station sends both TID groups on one link. Keep the default link as the secondary link meanwhile, since the rollback of a failed add reads msta->link[] at the secondary link.

If the default link goes while it is also the secondary link, move the default link to another valid link of the station.

Fixes 53eadd11e927 ("wifi: mt76: mt7996: pick the secondary link from links with driver state")
Fixes 85cd5534a3f2 ("wifi: mt76: mt7996: use correct link_id when filling TXD and TXP")
---
 .../net/wireless/mediatek/mt76/mt7996/main.c  | 23 ++++++++++++++-----
 .../net/wireless/mediatek/mt76/mt7996/mcu.c   |  6 ++---
 .../wireless/mediatek/mt76/mt7996/mt7996.h    |  1 +
 3 files changed, 21 insertions(+), 9 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/main.c +17 -6
index 69f1da5eae1b..d323557898b6 100644
@@ -1249,6 +1249,8 @@ mt7996_sta_deflink_set(struct ieee80211_sta *sta, unsigned int link_id,
 	struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
 
 	msta->deflink_id = link_id;
+	if (msta->seclink_id == IEEE80211_LINK_UNSPECIFIED)
+		msta->seclink_id = link_id;
 	mt7996_sta_init_txq_wcid(sta, idx);
 }
 
@@ -1286,6 +1288,9 @@ mt7996_sta_deflink_release(struct mt7996_dev *dev, struct ieee80211_sta *sta,
 	if (msta->deflink_id != link_id)
 		return;
 
+	if (msta->seclink_id == link_id)
+		msta->seclink_id = mt7996_sta_seclink_get(dev, msta);
+
 	msta->deflink_id = IEEE80211_LINK_UNSPECIFIED;
 	if (msta->seclink_id == link_id)
 		return;
@@ -1298,8 +1303,7 @@ mt7996_sta_deflink_release(struct mt7996_dev *dev, struct ieee80211_sta *sta,
 				       msta_seclink->wcid.idx);
 }
 
-static u8
-mt7996_sta_seclink_get(struct mt7996_dev *dev, struct mt7996_sta *msta)
+u8 mt7996_sta_seclink_get(struct mt7996_dev *dev, struct mt7996_sta *msta)
 {
 	struct mt7996_sta_link *msta_link;
 	unsigned int link_id;
@@ -1375,7 +1379,6 @@ mt7996_mac_sta_init_link(struct mt7996_dev *dev,
 	ewma_signal_init(&msta_link->wcid.rssi);
 
 	rcu_assign_pointer(msta->link[link_id], msta_link);
-	msta->seclink_id = mt7996_sta_seclink_get(dev, msta);
 
 	mt7996_mac_wtbl_update(dev, idx, MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
 
@@ -1416,7 +1419,9 @@ void mt7996_mac_sta_remove_link(struct mt7996_dev *dev,
 
 		mt7996_sta_deflink_release(dev, sta, link_id);
 		msta_link->wcid.link_valid = false;
-		msta->seclink_id = mt7996_sta_seclink_get(dev, msta);
+		/* the firmware keeps the link pair of its last MLD setup */
+		if (msta->seclink_id == link_id)
+			msta->seclink_id = msta->deflink_id;
 	}
 
 	if (flush) {
@@ -1495,7 +1500,6 @@ mt7996_mac_sta_add_links(struct mt7996_dev *dev, struct ieee80211_vif *vif,
 			if (msta->deflink_id == IEEE80211_LINK_UNSPECIFIED)
 				mt7996_sta_deflink_set(sta, link_id,
 						       msta_link->wcid.idx);
-			msta->seclink_id = mt7996_sta_seclink_get(dev, msta);
 			returned |= BIT(link_id);
 			continue;
 		}
@@ -1559,6 +1563,8 @@ mt7996_mac_sta_add(struct mt7996_dev *dev, struct ieee80211_vif *vif,
 	msta->ba_rx_mask = 0;
 	msta->vif = mvif;
 	err = mt7996_mac_sta_add_links(dev, vif, sta, links);
+	if (!err)
+		msta->seclink_id = mt7996_sta_seclink_get(dev, msta);
 
 	mutex_unlock(&dev->mt76.mutex);
 
@@ -1812,8 +1818,10 @@ mt7996_mac_sta_links_sync(struct mt7996_dev *dev, struct ieee80211_vif *vif,
 	unsigned int link_id;
 	int err;
 
-	if (msta->conn_state == CONN_STATE_DISCONNECT)
+	if (msta->conn_state == CONN_STATE_DISCONNECT) {
+		msta->seclink_id = mt7996_sta_seclink_get(dev, msta);
 		return 0;
+	}
 
 	links &= mt7996_mac_sta_links(dev, vif, sta);
 	for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) {
@@ -1886,6 +1894,9 @@ mt7996_mac_sta_links_sync(struct mt7996_dev *dev, struct ieee80211_vif *vif,
 			return err;
 	}
 
+	if (joined)
+		msta->seclink_id = mt7996_sta_seclink_get(dev, msta);
+
 	return mt7996_mac_sta_links_ba_add(dev, vif, sta, new_links | resumed);
 }
 
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +3 -3
index d82a1f659366..0eeac9084de7 100644
@@ -2815,11 +2815,11 @@ mt7996_mcu_sta_mld_setup_tlv(struct mt7996_dev *dev, struct sk_buff *skb,
 {
 	unsigned long links = mt7996_mcu_sta_mld_setup_links(dev, vif, sta);
 	struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
+	u8 seclink_id = mt7996_sta_seclink_get(dev, msta);
 	unsigned int nlinks = hweight16(links);
 	struct mld_setup_link *mld_setup_link;
 	struct sta_rec_mld_setup *mld_setup;
 	struct mt7996_sta_link *msta_link;
-	u8 seclink_id = msta->deflink_id;
 	unsigned int link_id;
 	struct tlv *tlv;
 
@@ -2840,8 +2840,8 @@ mt7996_mcu_sta_mld_setup_tlv(struct mt7996_dev *dev, struct sk_buff *skb,
 		mld_setup->setup_wcid = cpu_to_le16(msta->fw_mld_idx);
 	mld_setup->primary_id = mld_setup->setup_wcid;
 
-	if (links & BIT(msta->seclink_id))
-		seclink_id = msta->seclink_id;
+	if (!(links & BIT(seclink_id)))
+		seclink_id = msta->deflink_id;
 	msta_link = mt7996_sta_link_protected(dev, msta, seclink_id);
 	mld_setup->seconed_id = cpu_to_le16(msta_link->wcid.idx);
 	mld_setup->link_num = nlinks;
drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +1 -0
index c50fd3c15728..5ee8bf12f73b 100644
@@ -941,6 +941,7 @@ void mt7996_mac_sta_remove_link(struct mt7996_dev *dev,
 				unsigned int link_id, bool flush);
 u16 mt7996_mac_sta_links(struct mt7996_dev *dev, struct ieee80211_vif *vif,
 			 struct ieee80211_sta *sta);
+u8 mt7996_sta_seclink_get(struct mt7996_dev *dev, struct mt7996_sta *msta);
 void mt7996_mac_add_twt_setup(struct ieee80211_hw *hw,
 			      struct ieee80211_sta *sta,
 			      struct ieee80211_twt_setup *twt);
Signature · 1 line
2.47.3
author maintainer
#1 lore raw

PATCH 2/17 wifi: mt76: add a helper to point the TXQs of a station at a wcid

The TXQs of a station name the wcid that the TX scheduler sends their frames on. mt76_sta_add() sets it when the station is added. mt7996 adds its stations without mt76_sta_add() and sets it with a loop of its own whenever it sets the default link of a station.

Move that loop into the core, so that other drivers can use it for the same purpose, and use it in mt76_sta_add() too.

---
 drivers/net/wireless/mediatek/mt76/mac80211.c  | 11 +----------
 drivers/net/wireless/mediatek/mt76/mt76.h      | 16 ++++++++++++++++
 .../net/wireless/mediatek/mt76/mt7996/main.c   | 18 +-----------------
 3 files changed, 18 insertions(+), 27 deletions(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +1 -10
index b8a568e0ae27..db604ffde216 100644
@@ -1758,7 +1758,6 @@ mt76_sta_add(struct mt76_phy *phy, struct ieee80211_vif *vif,
 	struct mt76_wcid *published;
 	bool registered;
 	int ret;
-	int i;
 
 	mutex_lock(&dev->mutex);
 
@@ -1772,15 +1771,7 @@ mt76_sta_add(struct mt76_phy *phy, struct ieee80211_vif *vif,
 	if (ret)
 		goto out;
 
-	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;
-		mtxq->wcid = wcid->idx;
-	}
+	mt76_sta_txq_wcid_set(sta, wcid->idx);
 
 	published = rcu_dereference_protected(dev->wcid[wcid->idx],
 					      lockdep_is_held(&dev->mutex));
drivers/net/wireless/mediatek/mt76/mt76.h +16 -0
index ddada6834170..d82d22c14c9f 100644
@@ -1449,6 +1449,22 @@ mtxq_to_txq(struct mt76_txq *mtxq)
 	return container_of(ptr, struct ieee80211_txq, drv_priv);
 }
 
+static inline void
+mt76_sta_txq_wcid_set(struct ieee80211_sta *sta, u16 idx)
+{
+	int i;
+
+	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;
+		mtxq->wcid = idx;
+	}
+}
+
 /* peer-wide state uses the wcid of the primary link */
 static inline struct mt76_wcid *
 mt76_wcid_primary(struct mt76_wcid *wcid)
drivers/net/wireless/mediatek/mt76/mt7996/main.c +1 -17
index d323557898b6..253603d25662 100644
@@ -1226,22 +1226,6 @@ mt7996_post_channel_switch(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 	return ret;
 }
 
-static void
-mt7996_sta_init_txq_wcid(struct ieee80211_sta *sta, int idx)
-{
-	int i;
-
-	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;
-		mtxq->wcid = idx;
-	}
-}
-
 static void
 mt7996_sta_deflink_set(struct ieee80211_sta *sta, unsigned int link_id,
 		       int idx)
@@ -1251,7 +1235,7 @@ mt7996_sta_deflink_set(struct ieee80211_sta *sta, unsigned int link_id,
 	msta->deflink_id = link_id;
 	if (msta->seclink_id == IEEE80211_LINK_UNSPECIFIED)
 		msta->seclink_id = link_id;
-	mt7996_sta_init_txq_wcid(sta, idx);
+	mt76_sta_txq_wcid_set(sta, idx);
 }
 
 static void
Signature · 1 line
2.47.3
author maintainer
#2 lore raw

PATCH 3/17 wifi: mt76: mt7925: move the default link to a remaining link

In reply to Felix Fietkau

mt7925_change_sta_links() can remove the default link of an MLD station, but no remaining link takes its place. The TXQs of the station keep the index of the removed wcid, so mt76_txq_schedule_list() skips them. The data of the station stays queued until another wcid takes the index, and then goes out on that wcid.

Make a remaining link the default link before the old one goes. Send the TXQs and the frames without a link on it. Keep def_wcid on the embedded wcid, which holds the RX PN, reorder and aggregation state, like mt7996_sta_deflink_release(). Take the primary of STA_REC_MLD and of a link add from the default link. After a move, that is no longer the embedded wcid.

Also drop a frame whose link the driver no longer holds. A frame without a link can now look up the default link while that link goes.

This is currently not reachable. On a station interface, mt7925_can_activate_links() keeps the default link active, and an AP MLD has one link, because mt7925_change_vif_links() fails its second ADD_LINK. Found by inspection.

---
 .../net/wireless/mediatek/mt76/mt7925/main.c  | 46 +++++++++++++------
 .../net/wireless/mediatek/mt76/mt7925/mcu.c   | 31 ++++++++-----
 drivers/net/wireless/mediatek/mt76/mt792x.h   |  3 +-
 .../net/wireless/mediatek/mt76/mt792x_core.c  |  6 +++
 4 files changed, 59 insertions(+), 27 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +33 -13
index fa5628c06b04..534f412579b1 100644
@@ -1134,7 +1134,8 @@ static int mt7925_mac_link_sta_add(struct mt76_dev *mdev,
 			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
 
 	link_conf = mt792x_vif_to_bss_conf(vif, link_id);
-	is_secondary_link_sta = ieee80211_vif_is_mld(vif) && link_sta != mlink->pri_link;
+	is_secondary_link_sta = ieee80211_vif_is_mld(vif) &&
+				msta->deflink_id != IEEE80211_LINK_UNSPECIFIED;
 
 	/* NAN_DATA (NDI) peers skip association - fill link_sta caps
 	 * from sband and push BSS_INFO with correct phymode + RLM.
@@ -1172,22 +1173,18 @@ static int mt7925_mac_link_sta_add(struct mt76_dev *mdev,
 		if (ret)
 			goto out_pm;
 	} else {
+		struct ieee80211_link_sta *pri_link_sta;
 		struct mt792x_link_sta *pri_mlink;
-		struct mt76_wcid *pri_wcid;
 
-		/* alternative lookup via def_wcid */
-		pri_wcid = mlink->wcid.def_wcid;
-
-		pri_mlink = pri_wcid ?
-			    container_of(pri_wcid, struct mt792x_link_sta, wcid) :
-			    NULL;
-
-		if (WARN_ON_ONCE(!pri_mlink)) {
+		pri_link_sta = mt792x_sta_to_link_sta(vif, link_sta->sta,
+						      msta->deflink_id);
+		pri_mlink = mt792x_sta_to_link(msta, msta->deflink_id);
+		if (WARN_ON_ONCE(!pri_link_sta || !pri_mlink)) {
 			ret = -EINVAL;
 			goto out_pm;
 		}
 
-		ret = mt7925_mcu_sta_update(dev, mlink->pri_link, vif,
+		ret = mt7925_mcu_sta_update(dev, pri_link_sta, vif,
 					    pri_mlink, true,
 					    MT76_STA_INFO_STATE_ASSOC, mlink);
 		if (ret)
@@ -1286,7 +1283,6 @@ mt7925_mac_sta_add_links(struct mt792x_dev *dev, struct ieee80211_vif *vif,
 		}
 
 		mlink->sta = msta;
-		mlink->pri_link = &sta->deflink;
 		mlink->wcid.def_wcid = &msta->deflink.wcid;
 
 		link_sta = mt792x_sta_to_link_sta(vif, sta, link_id);
@@ -1327,6 +1323,7 @@ int mt7925_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
 
 	if (ieee80211_vif_is_mld(vif)) {
 		msta->deflink_id = IEEE80211_LINK_UNSPECIFIED;
+		msta->seclink_id = IEEE80211_LINK_UNSPECIFIED;
 
 		err = mt7925_mac_sta_add_links(dev, vif, sta, sta->valid_links);
 	} else {
@@ -1545,11 +1542,32 @@ static void mt7925_mac_link_sta_remove(struct mt76_dev *mdev,
 	mt76_connac_power_save_sched(&dev->mphy, &dev->pm);
 }
 
+static void
+mt7925_mac_sta_deflink_move(struct ieee80211_sta *sta, unsigned long links)
+{
+	struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
+	struct mt792x_link_sta *mlink;
+	unsigned int link_id;
+
+	/* prefer the secondary of the firmware's MLD record, so that the TXDs
+	 * keep naming a link of its pair until a link add sends a new record
+	 */
+	if (links & BIT(msta->seclink_id))
+		link_id = msta->seclink_id;
+	else
+		link_id = __ffs(links);
+
+	mlink = mt792x_sta_to_link(msta, link_id);
+	msta->deflink_id = link_id;
+	mt76_sta_txq_wcid_set(sta, mlink->wcid.idx);
+}
+
 static int
 mt7925_mac_sta_remove_links(struct mt792x_dev *dev, struct ieee80211_vif *vif,
 			    struct ieee80211_sta *sta, unsigned long old_links)
 {
 	struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
+	unsigned long links = msta->valid_links & ~old_links;
 	struct mt76_dev *mdev = &dev->mt76;
 	unsigned int link_id;
 
@@ -1593,6 +1611,9 @@ mt7925_mac_sta_remove_links(struct mt792x_dev *dev, struct ieee80211_vif *vif,
 					link_sta, false);
 	}
 
+	if (links && (old_links & BIT(msta->deflink_id)))
+		mt7925_mac_sta_deflink_move(sta, links);
+
 	for_each_set_bit(link_id, &old_links, IEEE80211_MLD_MAX_NUM_LINKS) {
 		struct ieee80211_link_sta *link_sta;
 		struct mt792x_link_sta *mlink;
@@ -1608,7 +1629,6 @@ mt7925_mac_sta_remove_links(struct mt792x_dev *dev, struct ieee80211_vif *vif,
 
 		msta->valid_links &= ~BIT(link_id);
 		mlink->sta = NULL;
-		mlink->pri_link = NULL;
 
 		mt7925_mac_link_sta_remove(&dev->mt76, vif, link_sta, mlink);
 
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +19 -12
index 5df5a315c4b9..a8faf76b5d0d 100644
@@ -2227,24 +2227,28 @@ mt7925_mcu_sta_mld_tlv(struct sk_buff *skb,
 {
 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
 	struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
+	struct mt792x_link_sta *mlink_pri = NULL;
+	struct mt792x_bss_conf *mconf_pri = NULL;
 	struct mt792x_dev *dev = mvif->phy->dev;
 	unsigned long valid = msta->valid_links;
-	struct mt792x_bss_conf *mconf_pri;
 	struct sta_rec_mld *mld;
 	unsigned int link_id;
 	struct tlv *tlv;
 	u8 max_links;
 	u8 cnt = 0;
 
-	/* Primary link always uses driver's deflink WCID. */
-	mconf_pri = (msta->deflink_id != IEEE80211_LINK_UNSPECIFIED) ?
-		    mt792x_vif_to_link(mvif, msta->deflink_id) : NULL;
+	if (msta->deflink_id != IEEE80211_LINK_UNSPECIFIED) {
+		mlink_pri = mt792x_sta_to_link(msta, msta->deflink_id);
+		mconf_pri = mt792x_vif_to_link(mvif, msta->deflink_id);
+	}
 
 	/* If caller is operating on deflink, reuse its mconf as primary. */
-	if (!mconf_pri && mlink == &msta->deflink)
+	if (!mlink_pri && mlink == &msta->deflink) {
+		mlink_pri = mlink;
 		mconf_pri = mconf;
+	}
 
-	if (!mconf_pri) {
+	if (!mlink_pri) {
 		dev_warn_ratelimited(dev->mt76.dev,
 				     "mt7925: MLD_TLV_LINK skip (no primary mconf) sta=%pM\n",
 			sta->addr);
@@ -2255,19 +2259,20 @@ mt7925_mcu_sta_mld_tlv(struct sk_buff *skb,
 	mld = (struct sta_rec_mld *)tlv;
 	memcpy(mld->mac_addr, sta->addr, ETH_ALEN);
 
-	mld->primary_id = cpu_to_le16(msta->deflink.wcid.idx);
-	mld->wlan_id = cpu_to_le16(msta->deflink.wcid.idx);
+	mld->primary_id = cpu_to_le16(mlink_pri->wcid.idx);
+	mld->wlan_id = cpu_to_le16(mlink_pri->wcid.idx);
 
 	/* Always encode primary link first. */
-	mld->link[cnt].wlan_id = cpu_to_le16(msta->deflink.wcid.idx);
+	mld->link[cnt].wlan_id = cpu_to_le16(mlink_pri->wcid.idx);
 	mld->link[cnt++].bss_idx = mconf_pri->mt76.idx;
 
 	max_links = ARRAY_SIZE(mld->link);
 
 	/* A link being added is not set in msta->valid_links yet */
-	if (pending && pending != &msta->deflink)
+	if (pending && pending != mlink_pri)
 		valid |= BIT(pending->wcid.link_id);
 
+	msta->seclink_id = IEEE80211_LINK_UNSPECIFIED;
 	for_each_set_bit(link_id, &valid, IEEE80211_MLD_MAX_NUM_LINKS) {
 		struct mt792x_link_sta *mlink_sec;
 		struct mt792x_bss_conf *mconf_sec;
@@ -2281,7 +2286,7 @@ mt7925_mcu_sta_mld_tlv(struct sk_buff *skb,
 		mlink_sec = mt792x_sta_to_link(msta, link_id);
 		if (!mlink_sec && pending && link_id == pending->wcid.link_id)
 			mlink_sec = pending;
-		if (!mlink_sec || mlink_sec == &msta->deflink)
+		if (!mlink_sec || mlink_sec == mlink_pri)
 			continue;
 
 		mconf_sec = rcu_dereference_protected(mvif->link_conf[link_id],
@@ -2289,8 +2294,10 @@ mt7925_mcu_sta_mld_tlv(struct sk_buff *skb,
 		if (!mconf_sec)
 			continue;
 
-		if (cnt == 1)
+		if (cnt == 1) {
 			mld->secondary_id = cpu_to_le16(mlink_sec->wcid.idx);
+			msta->seclink_id = link_id;
+		}
 
 		mld->link[cnt].wlan_id = cpu_to_le16(mlink_sec->wcid.idx);
 		mld->link[cnt++].bss_idx = mconf_sec->mt76.idx;
drivers/net/wireless/mediatek/mt76/mt792x.h +1 -2
index e37d901575e5..10175875e76b 100644
@@ -125,8 +125,6 @@ struct mt792x_link_sta {
 	struct mt76_connac_sta_key_conf bip;
 
 	struct mt792x_sta *sta;
-
-	struct ieee80211_link_sta *pri_link;
 };
 
 struct mt792x_sta_nan_sched {
@@ -152,6 +150,7 @@ struct mt792x_sta {
 
 	u16 valid_links;
 	u8 deflink_id;
+	u8 seclink_id;
 
 	/* NAN peer schedule */
 	struct mt792x_sta_nan_sched nan_sched;
drivers/net/wireless/mediatek/mt76/mt792x_core.c +6 -0
index 5743c5437863..8dbc5e84cd48 100644
@@ -195,7 +195,13 @@ void mt792x_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
 		link_id = u32_get_bits(info->control.flags,
 				       IEEE80211_TX_CTRL_MLO_LINK);
 		sta = (struct mt792x_sta *)control->sta->drv_priv;
+		if (link_id >= IEEE80211_LINK_UNSPECIFIED)
+			link_id = sta->deflink_id;
 		mlink = mt792x_sta_to_link(sta, link_id);
+		if (!mlink) {
+			ieee80211_free_txskb(hw, skb);
+			return;
+		}
 		wcid = &mlink->wcid;
 	}
 
Signature · 1 line
2.47.3
author maintainer
#3 lore raw

PATCH 4/17 wifi: mt76: mt7925: keep the deflink wcid index until station removal

In reply to Felix Fietkau

Since mt7925_change_sta_links() was added, the driver frees the WLAN index of msta->deflink.wcid, the wcid in drv_priv, when the link of msta->deflink goes. A failed add of that link to a station that stays frees its new index the same way. __mt76_sta_remove() frees the index again when the station goes, also when another wcid holds it by then. The next allocation then gives that WTBL entry to a second wcid. Reachable when mac80211 deactivates the only link of a TDLS peer on an MLD interface, since user space removes the peer later.

Leave the index of msta->deflink.wcid to __mt76_sta_remove(), which then frees it once. The link removal still unpublishes and cleans up the wcid, so no live pointer refers to the reserved index. This costs one index for each station whose deflink link went, until the station goes. mt7996 likewise keeps the index of a removed station link until the station goes.

If a station loses every driver link and stays, the next link add takes msta->deflink again. Give it the kept index then, and keep that index when the add fails. The first add of a station still frees its index on failure, since mac80211 removes nothing after a failed station add.

Fixes 43aa4033eb18 ("wifi: mt76: mt7925: add mt7925_change_sta_links")
Fixes 75e2d6bfd9ac ("wifi: mt76: mt7925: unwind WCID setup on link STA add failure")
Fixes 9fc83205a62e ("wifi: mt76: mt7925: host-only unwind published links on add failure")
---
 .../net/wireless/mediatek/mt76/mt7925/main.c  | 30 +++++++++++++++----
 drivers/net/wireless/mediatek/mt76/mt792x.h   |  1 +
 2 files changed, 26 insertions(+), 5 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +25 -5
index 534f412579b1..5a185d7422f0 100644
@@ -1078,6 +1078,12 @@ mt7925_get_rates_table(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 
 static void mt7925_nan_sta_wcids_init(struct mt792x_sta *msta);
 
+static bool
+mt7925_sta_link_idx_kept(struct mt792x_sta *msta, struct mt792x_link_sta *mlink)
+{
+	return mlink == &msta->deflink && msta->deflink_idx_kept;
+}
+
 static int mt7925_mac_link_sta_add(struct mt76_dev *mdev,
 				   struct ieee80211_vif *vif,
 				   struct ieee80211_link_sta *link_sta,
@@ -1100,7 +1106,10 @@ static int mt7925_mac_link_sta_add(struct mt76_dev *mdev,
 	if (WARN_ON_ONCE(!mlink))
 		return -EINVAL;
 
-	idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT792x_WTBL_STA - 1);
+	if (mt7925_sta_link_idx_kept(msta, mlink))
+		idx = mlink->wcid.idx;
+	else
+		idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT792x_WTBL_STA - 1);
 	if (idx < 0)
 		return -ENOSPC;
 
@@ -1213,7 +1222,8 @@ static int mt7925_mac_link_sta_add(struct mt76_dev *mdev,
 
 		rcu_assign_pointer(dev->mt76.wcid[idx], NULL);
 		mt76_wcid_cleanup(mdev, wcid);
-		mt76_wcid_mask_clear(mdev->wcid_mask, wcid->idx);
+		if (!mt7925_sta_link_idx_kept(msta, mlink))
+			mt76_wcid_mask_clear(mdev->wcid_mask, wcid->idx);
 	}
 	return ret;
 }
@@ -1250,7 +1260,8 @@ mt7925_mac_sta_unwind_links_host(struct mt792x_dev *dev,
 		idx = mlink->wcid.idx;
 		rcu_assign_pointer(dev->mt76.wcid[idx], NULL);
 		mt76_wcid_cleanup(&dev->mt76, &mlink->wcid);
-		mt76_wcid_mask_clear(dev->mt76.wcid_mask, idx);
+		if (!mt7925_sta_link_idx_kept(msta, mlink))
+			mt76_wcid_mask_clear(dev->mt76.wcid_mask, idx);
 
 		if (mlink != &msta->deflink)
 			kfree_rcu(mlink, rcu_head);
@@ -1293,8 +1304,10 @@ mt7925_mac_sta_add_links(struct mt792x_dev *dev, struct ieee80211_vif *vif,
 			break;
 		}
 
-		if (is_deflink)
+		if (is_deflink) {
 			msta->deflink_id = link_id;
+			mt76_sta_txq_wcid_set(sta, mlink->wcid.idx);
+		}
 
 		rcu_assign_pointer(msta->link[link_id], mlink);
 		msta->valid_links |= BIT(link_id);
@@ -1321,6 +1334,8 @@ int mt7925_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
 	if (vif->type == NL80211_IFTYPE_STATION)
 		mvif->wep_sta = msta;
 
+	msta->deflink_idx_kept = false;
+
 	if (ieee80211_vif_is_mld(vif)) {
 		msta->deflink_id = IEEE80211_LINK_UNSPECIFIED;
 		msta->seclink_id = IEEE80211_LINK_UNSPECIFIED;
@@ -1497,6 +1512,7 @@ static void mt7925_mac_link_sta_remove(struct mt76_dev *mdev,
 				       struct ieee80211_link_sta *link_sta,
 				       struct mt792x_link_sta *mlink)
 {
+	struct mt792x_sta *msta = (struct mt792x_sta *)link_sta->sta->drv_priv;
 	struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
 	struct mt76_wcid *wcid = &mlink->wcid;
 	struct ieee80211_bss_conf *link_conf;
@@ -1534,7 +1550,11 @@ static void mt7925_mac_link_sta_remove(struct mt76_dev *mdev,
 
 	rcu_assign_pointer(dev->mt76.wcid[idx], NULL);
 	mt76_wcid_cleanup(mdev, wcid);
-	mt76_wcid_mask_clear(mdev->wcid_mask, idx);
+	/* __mt76_sta_remove() frees the index of the embedded wcid */
+	if (mlink == &msta->deflink)
+		msta->deflink_idx_kept = true;
+	else
+		mt76_wcid_mask_clear(mdev->wcid_mask, idx);
 
 	if (vif->type == NL80211_IFTYPE_NAN || vif->type == NL80211_IFTYPE_NAN_DATA)
 		mt7925_nan_peer_wcids_free(mdev, vif, link_sta->sta);
drivers/net/wireless/mediatek/mt76/mt792x.h +1 -0
index 10175875e76b..b142be13ab78 100644
@@ -151,6 +151,7 @@ struct mt792x_sta {
 	u16 valid_links;
 	u8 deflink_id;
 	u8 seclink_id;
+	bool deflink_idx_kept;
 
 	/* NAN peer schedule */
 	struct mt792x_sta_nan_sched nan_sched;
Signature · 1 line
2.47.3
author maintainer
#4 lore raw

PATCH 5/17 wifi: mt76: mt792x: look up the TX links under RCU

In reply to Felix Fietkau

mt792x_sta_to_link() and mt792x_vif_to_link() dereference the link pointers with rcu_dereference_protected() and the mt76 mutex as its condition. mt792x_tx() and mt7925_mac_write_txwi() call them on the TX path, which holds an RCU read section but not the mutex. With CONFIG_PROVE_RCU, the first frame sent on an MLO connection thus gives a "suspicious rcu_dereference_protected() usage" warning.

Look the links up with rcu_dereference() on the TX path, matching mt7996_sta_link(). Hold the read section of mt792x_tx() from the lookup until the frame is queued, like mt7996_tx().

Fixes ebb1406813c6 ("wifi: mt76: mt7925: add link handling to txwi")
---
 .../net/wireless/mediatek/mt76/mt7925/mac.c   |  4 +-
 drivers/net/wireless/mediatek/mt76/mt792x.h   | 46 ++++++++++++++-----
 .../net/wireless/mediatek/mt76/mt792x_core.c  | 12 +++--
 3 files changed, 44 insertions(+), 18 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/mac.c +2 -2
index ca54d71db4c7..a99a2c497458 100644
@@ -804,8 +804,8 @@ mt7925_mac_write_txwi(struct mt76_dev *dev, __le32 *txwi,
 					 BSS_CHANGED_FILS_DISCOVERY));
 	struct mt792x_bss_conf *mconf;
 
-	mconf = vif ? mt792x_vif_to_link((struct mt792x_vif *)vif->drv_priv,
-					 wcid->link_id) : NULL;
+	mconf = vif ? mt792x_vif_to_link_rcu((struct mt792x_vif *)vif->drv_priv,
+					     wcid->link_id) : NULL;
 	mvif = mconf ? (struct mt76_vif_link *)&mconf->mt76 : NULL;
 
 	if (mvif) {
drivers/net/wireless/mediatek/mt76/mt792x.h +35 -11

72 lines not on this page · raw message

drivers/net/wireless/mediatek/mt76/mt792x_core.c +7 -5
index 8dbc5e84cd48..5babfc00dee1 100644
@@ -189,6 +189,8 @@ void mt792x_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
 		}
 	}
 
+	rcu_read_lock();
+
 	if (control->sta) {
 		struct mt792x_link_sta *mlink;
 		struct mt792x_sta *sta;
@@ -197,10 +199,10 @@ void mt792x_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
 		sta = (struct mt792x_sta *)control->sta->drv_priv;
 		if (link_id >= IEEE80211_LINK_UNSPECIFIED)
 			link_id = sta->deflink_id;
-		mlink = mt792x_sta_to_link(sta, link_id);
+		mlink = mt792x_sta_to_link_rcu(sta, link_id);
 		if (!mlink) {
 			ieee80211_free_txskb(hw, skb);
-			return;
+			goto unlock;
 		}
 		wcid = &mlink->wcid;
 	}
@@ -229,7 +231,6 @@ void mt792x_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
 		struct ieee80211_bss_conf *conf;
 
 		link_id = wcid->link_id;
-		rcu_read_lock();
 		conf = rcu_dereference(vif->link_conf[link_id]);
 		memcpy(hdr->addr2, conf->addr, ETH_ALEN);
 
@@ -238,13 +239,12 @@ void mt792x_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
 
 		if (vif->type == NL80211_IFTYPE_STATION)
 			memcpy(hdr->addr3, conf->bssid, ETH_ALEN);
-		rcu_read_unlock();
 	}
 
 	if (mt76_connac_pm_ref(mphy, &dev->pm)) {
 		mt76_tx(mphy, control->sta, wcid, skb);
 		mt76_connac_pm_unref(mphy, &dev->pm);
-		return;
+		goto unlock;
 	}
 
 	qid = skb_get_queue_mapping(skb);
@@ -254,6 +254,8 @@ void mt792x_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
 	}
 
 	mt76_connac_pm_queue_skb(hw, &dev->pm, wcid, skb);
+unlock:
+	rcu_read_unlock();
 }
 EXPORT_SYMBOL_GPL(mt792x_tx);
 
Signature · 1 line
2.47.3
author maintainer
#5 lore raw

PATCH 6/17 wifi: mt76: mt7925: read the links under RCU in the IPv6 notifier

In reply to Felix Fietkau

mt7925_ipv6_addr_change() runs from the inet6addr notifier of mac80211, an atomic notifier chain, so it holds RCU but neither the wiphy lock nor dev->mt76.mutex. Still it reads vif->link_conf[] with mt792x_vif_to_bss_conf() and the driver link with mt792x_link_conf_to_mconf(), whose checks name those locks. When mac80211 removes the links at a disassociation, it clears vif->link_conf[] before drv_change_vif_links() updates mvif->valid_links. An address change in that window makes mt792x_vif_to_bss_conf() return NULL, which __mt7925_ipv6_addr_change() dereferences.

Read both links with the RCU accessors and skip a link that mac80211 already removed, like mt7925_vif_connect_iter(). The driver frees a removed link after a grace period, so the read section of the notifier keeps it valid. For a non-MLD interface, vif->link_conf[0] holds &vif->bss_conf, except while mac80211 adds the first MLD links; the notifier then skips it.

Fixes 9f8f587cab69 ("wifi: mt76: mt7925: add link handling in the mt7925_ipv6_addr_change")
---
 drivers/net/wireless/mediatek/mt76/mt7925/main.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +7 -2
index 5a185d7422f0..b78823e161ee 100644
@@ -2082,7 +2082,9 @@ static void __mt7925_ipv6_addr_change(struct ieee80211_hw *hw,
 				      struct ieee80211_bss_conf *link_conf,
 				      struct inet6_dev *idev)
 {
-	struct mt792x_bss_conf *mconf = mt792x_link_conf_to_mconf(link_conf);
+	struct mt792x_vif *mvif = (struct mt792x_vif *)link_conf->vif->drv_priv;
+	struct mt792x_bss_conf *mconf =
+		mt792x_vif_to_link_rcu(mvif, link_conf->link_id);
 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
 	struct inet6_ifaddr *ifa;
 	struct sk_buff *skb;
@@ -2147,7 +2149,10 @@ static void mt7925_ipv6_addr_change(struct ieee80211_hw *hw,
 		return;
 
 	for_each_set_bit(i, &valid, IEEE80211_MLD_MAX_NUM_LINKS) {
-		bss_conf = mt792x_vif_to_bss_conf(vif, i);
+		bss_conf = rcu_dereference(vif->link_conf[i]);
+		if (!bss_conf)
+			continue;
+
 		__mt7925_ipv6_addr_change(hw, bss_conf, idev);
 	}
 }
Signature · 1 line
2.47.3
author maintainer
#6 lore raw

PATCH 7/17 wifi: mt76: mt7925: abort a ROC on the BSS that requested it

In reply to Felix Fietkau

mt7925_start_ap() requests the channel on the BSS of the link that it starts. mt7925_roc_work() aborts an expired request only on the default BSS of each running interface. If the request of a non-default link of an AP MLD expires before mt7925_start_ap() aborts it, the firmware gets no abort for that BSS. The comment in mt7925_start_ap() notes that the firmware then asserts.

Record the BSS of each request, and abort on it as well.

This is currently not reachable, because mt7925_change_vif_links() fails the second ADD_LINK of an AP MLD. Found by inspection.

---
 drivers/net/wireless/mediatek/mt76/mt7925/main.c | 16 +++++++++-------
 drivers/net/wireless/mediatek/mt76/mt792x.h      |  1 +
 2 files changed, 10 insertions(+), 7 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +9 -7
index b78823e161ee..ec4f3db23c07 100644
@@ -547,10 +547,9 @@ static void mt7925_roc_iter(void *priv, u8 *mac,
 	*bss_mask |= BIT_ULL(mvif->bss_conf.mt76.idx);
 }
 
-static void mt7925_roc_abort_all(struct mt792x_phy *phy, u8 token)
+static void mt7925_roc_abort_all(struct mt792x_phy *phy, u8 token, u8 bss_idx)
 {
-	u64 bss_mask = 0;
-	u8 bss_idx;
+	u64 bss_mask = BIT_ULL(bss_idx);
 
 	ieee80211_iterate_active_interfaces_atomic(phy->mt76->hw,
 						   IEEE80211_IFACE_ITER_RESUME_ALL,
@@ -574,19 +573,20 @@ void mt7925_roc_abort_sync(struct mt792x_dev *dev)
 
 	cancel_work(&phy->roc_work);
 
-	mt7925_roc_abort_all(phy, phy->roc_token_id);
+	mt7925_roc_abort_all(phy, phy->roc_token_id, phy->roc_bss_idx);
 }
 EXPORT_SYMBOL_GPL(mt7925_roc_abort_sync);
 
 void mt7925_roc_work(struct work_struct *work)
 {
 	struct mt792x_phy *phy;
-	u8 token;
+	u8 token, bss_idx;
 
 	phy = (struct mt792x_phy *)container_of(work, struct mt792x_phy,
 						roc_work);
 
 	token = phy->roc_token_id;
+	bss_idx = phy->roc_bss_idx;
 
 	if (!test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
 		return;
@@ -595,7 +595,7 @@ void mt7925_roc_work(struct work_struct *work)
 	ieee80211_remain_on_channel_expired(phy->mt76->hw);
 
 	mt792x_mutex_acquire(phy->dev);
-	mt7925_roc_abort_all(phy, token);
+	mt7925_roc_abort_all(phy, token, bss_idx);
 	mt792x_mutex_release(phy->dev);
 }
 
@@ -631,7 +631,7 @@ static void mt7925_roc_stale_reclaim(struct mt792x_phy *phy)
 	if (!test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
 		return;
 
-	mt7925_roc_abort_all(phy, token);
+	mt7925_roc_abort_all(phy, token, phy->roc_bss_idx);
 
 	if (phy->roc_notify)
 		ieee80211_remain_on_channel_expired(phy->mt76->hw);
@@ -652,6 +652,7 @@ static int mt7925_set_roc(struct mt792x_phy *phy,
 		return -EBUSY;
 
 	token = ++phy->roc_token_id;
+	phy->roc_bss_idx = mconf->mt76.idx;
 	phy->roc_grant = false;
 	phy->roc_notify = type == MT7925_ROC_REQ_ROC;
 
@@ -683,6 +684,7 @@ static int mt7925_set_mlo_roc(struct mt792x_phy *phy,
 		return -EBUSY;
 
 	token = ++phy->roc_token_id;
+	phy->roc_bss_idx = mconf->mt76.idx;
 	phy->roc_grant = false;
 	phy->roc_notify = false;
 
drivers/net/wireless/mediatek/mt76/mt792x.h +1 -0
index 3604f02a5376..07c5e67db8cd 100644
@@ -305,6 +305,7 @@ struct mt792x_phy {
 	u8 roc_token_id;
 	bool roc_grant;
 	bool roc_notify; /* mac80211 expects the expiry of this ROC */
+	u8 roc_bss_idx;
 };
 
 struct mt792x_irq_map {
Signature · 1 line
2.47.3
author maintainer
#7 lore raw

PATCH 8/17 wifi: mt76: mt7925: take the link conf of a removed link from old[]

In reply to Felix Fietkau

mt7925_change_vif_links() deactivates a removed link through mt792x_mac_link_bss_remove(), which looks up the link conf in vif->link_conf[]. ieee80211_vif_update_links() clears that entry before it calls the driver. If an AP MLD removes a non-default link while another link stays, the lookup returns NULL, and mt76_connac_mcu_uni_add_dev() dereferences it. When a non-AP MLD disassociates, mac80211 removes all links, so the DEV_INFO deactivation of a non-default link carries the MLD address of vif->bss_conf.

Take the link conf of a removed link from old[], as the .change_vif_links text in include/net/mac80211.h describes: "The @old array contains pointers to the old bss_conf structures that were already removed, in case they're needed." The DEV_INFO deactivation then carries the link address of its activation. Whether the firmware reads that address at a deactivation is not known.

The NULL dereference is currently not reachable, because mt7925_change_vif_links() fails the second ADD_LINK of an AP MLD. Found by inspection.

---
 .../net/wireless/mediatek/mt76/mt7925/main.c  | 15 ++++++-----
 drivers/net/wireless/mediatek/mt76/mt792x.h   |  4 +++
 .../net/wireless/mediatek/mt76/mt792x_core.c  | 25 +++++++++++++------
 3 files changed, 30 insertions(+), 14 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +9 -6
index ec4f3db23c07..27a622beb147 100644
@@ -2550,14 +2550,15 @@ static void mt7925_link_info_changed(struct ieee80211_hw *hw,
 
 static void
 mt7925_vif_link_remove(struct mt792x_dev *dev, struct mt792x_vif *mvif,
-		       unsigned int link_id, struct mt792x_bss_conf *mconf,
+		       unsigned int link_id, struct ieee80211_bss_conf *link_conf,
+		       struct mt792x_bss_conf *mconf,
 		       struct mt792x_link_sta *mlink, bool bss_remove)
 {
 	rcu_assign_pointer(mvif->link_conf[link_id], NULL);
 	rcu_assign_pointer(mvif->sta.link[link_id], NULL);
 
 	if (bss_remove)
-		mt792x_mac_link_bss_remove(dev, mconf, mlink);
+		__mt792x_mac_link_bss_remove(dev, link_conf, mconf, mlink);
 
 	if (mconf != &mvif->bss_conf) {
 		mt7925_p2p_bmc_remove(dev, mconf);
@@ -2596,8 +2597,8 @@ mt7925_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 		if (!mconf || !mlink)
 			continue;
 
-		mt7925_vif_link_remove(dev, mvif, link_id, mconf, mlink,
-				       mconf != &mvif->bss_conf);
+		mt7925_vif_link_remove(dev, mvif, link_id, old[link_id], mconf,
+				       mlink, mconf != &mvif->bss_conf);
 	}
 
 	for_each_set_bit(link_id, &add, IEEE80211_MLD_MAX_NUM_LINKS) {
@@ -2671,8 +2672,10 @@ mt7925_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 
 free:
 	for_each_set_bit(link_id, &add, IEEE80211_MLD_MAX_NUM_LINKS)
-		mt7925_vif_link_remove(dev, mvif, link_id, mconfs[link_id],
-				       mlinks[link_id], added & BIT(link_id));
+		mt7925_vif_link_remove(dev, mvif, link_id,
+				       mt792x_vif_to_bss_conf(vif, link_id),
+				       mconfs[link_id], mlinks[link_id],
+				       added & BIT(link_id));
 	goto out;
 
 free_unpublished:
drivers/net/wireless/mediatek/mt76/mt792x.h +4 -0
index 07c5e67db8cd..260abdc978f8 100644
@@ -661,6 +661,10 @@ mt792x_get_mac80211_ops(struct device *dev,
 int mt792x_init_wcid(struct mt792x_dev *dev);
 int mt792x_mcu_drv_pmctrl(struct mt792x_dev *dev);
 int mt792x_mcu_fw_pmctrl(struct mt792x_dev *dev);
+void __mt792x_mac_link_bss_remove(struct mt792x_dev *dev,
+				  struct ieee80211_bss_conf *link_conf,
+				  struct mt792x_bss_conf *mconf,
+				  struct mt792x_link_sta *mlink);
 void mt792x_mac_link_bss_remove(struct mt792x_dev *dev,
 				struct mt792x_bss_conf *mconf,
 				struct mt792x_link_sta *mlink);
drivers/net/wireless/mediatek/mt76/mt792x_core.c +17 -8
index 5babfc00dee1..6a9c0e92cd1a 100644
@@ -281,17 +281,13 @@ void mt792x_stop(struct ieee80211_hw *hw, bool suspend)
 }
 EXPORT_SYMBOL_GPL(mt792x_stop);
 
-void mt792x_mac_link_bss_remove(struct mt792x_dev *dev,
-				struct mt792x_bss_conf *mconf,
-				struct mt792x_link_sta *mlink)
+void __mt792x_mac_link_bss_remove(struct mt792x_dev *dev,
+				  struct ieee80211_bss_conf *link_conf,
+				  struct mt792x_bss_conf *mconf,
+				  struct mt792x_link_sta *mlink)
 {
-	struct ieee80211_vif *vif = container_of((void *)mconf->vif,
-						 struct ieee80211_vif, drv_priv);
-	struct ieee80211_bss_conf *link_conf;
 	int idx = mlink->wcid.idx;
 
-	link_conf = mt792x_vif_to_bss_conf(vif, mconf->link_id);
-
 	mt76_connac_free_pending_tx_skbs(&dev->pm, &mlink->wcid);
 	mt76_connac_mcu_uni_add_dev(&dev->mphy, link_conf, &mconf->mt76,
 				    &mlink->wcid, false);
@@ -308,6 +304,19 @@ void mt792x_mac_link_bss_remove(struct mt792x_dev *dev,
 
 	mt76_wcid_cleanup(&dev->mt76, &mlink->wcid);
 }
+EXPORT_SYMBOL_GPL(__mt792x_mac_link_bss_remove);
+
+void mt792x_mac_link_bss_remove(struct mt792x_dev *dev,
+				struct mt792x_bss_conf *mconf,
+				struct mt792x_link_sta *mlink)
+{
+	struct ieee80211_vif *vif = container_of((void *)mconf->vif,
+						 struct ieee80211_vif, drv_priv);
+
+	__mt792x_mac_link_bss_remove(dev,
+				     mt792x_vif_to_bss_conf(vif, mconf->link_id),
+				     mconf, mlink);
+}
 EXPORT_SYMBOL_GPL(mt792x_mac_link_bss_remove);
 
 void mt792x_remove_interface(struct ieee80211_hw *hw,
Signature · 1 line
2.47.3
author maintainer
#8 lore raw

PATCH 9/17 wifi: mt76: mt7925: send the MLO ROC only for a station vif

In reply to Felix Fietkau

The MLO ROC asks the firmware for channel time on the links of an MLSR non-AP MLD. mt7925_change_vif_links() also sends it for an AP MLD. mac80211 adds an AP link without a channel, so the second ADD_LINK of an AP MLD hits WARN_ON_ONCE(!links[i].chan) in mt7925_mcu_set_mlo_roc(). The ROC then fails, and with it the ADD_LINK, so an AP MLD cannot get a second link.

Only send the MLO ROC for a station interface, which includes a P2P client. Check the type before mt7925_mac_set_links() looks up the link conf of the default link, which an AP MLD can remove while other links stay. An mt7925 AP MLD can then add more than one link. Whether the firmware runs such an AP MLD correctly is untested.

Fixes 69acd6d910b0 ("wifi: mt76: mt7925: add mt7925_change_vif_links")
Cc <[email protected]> # enables untested AP MLD links
---
 drivers/net/wireless/mediatek/mt76/mt7925/main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +4 -2
index 27a622beb147..d99d86bf5be8 100644
@@ -1446,7 +1446,8 @@ int mt7925_mac_sta_event(struct mt76_dev *mdev, struct ieee80211_vif *vif,
 
 			link_sta = mt792x_sta_to_link_sta(vif, sta,
 							  msta->deflink_id);
-			mt7925_mac_set_links(mdev, vif);
+			if (vif->type == NL80211_IFTYPE_STATION)
+				mt7925_mac_set_links(mdev, vif);
 		}
 
 		mt7925_mac_link_sta_assoc(mdev, vif, link_sta);
@@ -2644,7 +2645,8 @@ mt7925_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 
 		added |= BIT(link_id);
 
-		if (mconf != &mvif->bss_conf) {
+		if (mconf != &mvif->bss_conf &&
+		    vif->type == NL80211_IFTYPE_STATION) {
 			err = mt7925_set_mlo_roc(phy, &mvif->bss_conf,
 						 vif->active_links);
 			if (err < 0)
Signature · 1 line
2.47.3
author maintainer
#9 lore raw

PATCH 10/17 wifi: mt76: mt7996: send the Beacon rate table again after a full reset

In reply to Felix Fietkau

mt7996_get_rates_table() sends the Beacon fixed-rate table entry only when the rate differs from phy->beacon_rate. A full reset reloads the firmware, which then holds its default entry. The reset keeps phy->beacon_rate, so the Beacon update of the restart sends no entry. Beacons then go out without the duplicate TX mode on all paths, at lower power, after every full reset.

Forget the Beacon rate of each phy at a full reset, like omac_mask and rxfilter, so that the restart sends the entry again.

Fixes 254ab81f3b82 ("wifi: mt76: connac: add beacon duplicate TX mode support for mt7996")
---
 drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +1 -0
index f4c4ca10527a..7873b87c74d7 100644
@@ -2527,6 +2527,7 @@ mt7996_mac_full_reset(struct mt7996_dev *dev)
 	mt7996_for_each_phy(dev, phy) {
 		phy->omac_mask = 0;
 		phy->rxfilter |= MT_WF_RFCR_DROP_OTHER_UC;
+		phy->beacon_rate = -1;
 	}
 	dev->mld_idx_mask = 0;
 	dev->mld_remap_idx_mask = 0;
Signature · 1 line
2.47.3
author maintainer
#10 lore raw

PATCH 11/17 wifi: mt76: mt7996: restore the operating channel after an L1 SER

In reply to Felix Fietkau

Since commit b36d55610215 ("wifi: mt76: abort scan/roc on hw restart"), the L1 SER aborts a running ROC or scan with MT76_MCU_RESET set. Neither the completion nor the rest of the recovery then sets a channel, so the firmware stays on the off-channel in its scan state. In that state the firmware keeps the station queues of the band stopped until the next channel switch. A ROC or scan that ends between the SER interrupt and the reset work has the same effect. A scan of a DFS operating channel also leaves radar detection off, since only the channel set that the aborted completion skips would start it again.

After the recovery, switch each band that the firmware still holds in the scan state back to its operating channel. Also switch back a band whose DFS state the aborted scan left stale. Count a scan switch as soon as it is sent, since the firmware can act on a switch whose answer the reset loses.

Fixes b36d55610215 ("wifi: mt76: abort scan/roc on hw restart")
---
 drivers/net/wireless/mediatek/mt76/mac80211.c |  1 +
 .../net/wireless/mediatek/mt76/mt7996/mac.c   | 46 +++++++++++++++++--
 .../net/wireless/mediatek/mt76/mt7996/mcu.c   | 17 ++++++-
 .../wireless/mediatek/mt76/mt7996/mt7996.h    |  1 +
 4 files changed, 58 insertions(+), 7 deletions(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +1 -0
index db604ffde216..77116d9f4125 100644
@@ -1179,6 +1179,7 @@ int __mt76_set_channel(struct mt76_phy *phy, struct cfg80211_chan_def *chandef,
 
 	return ret;
 }
+EXPORT_SYMBOL_GPL(__mt76_set_channel);
 
 int mt76_set_channel(struct mt76_phy *phy, struct cfg80211_chan_def *chandef,
 		     bool offchannel)
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +41 -5

74 lines not on this page · raw message

drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +15 -2
index 0eeac9084de7..e4f52cb81470 100644
@@ -4394,6 +4394,8 @@ int mt7996_mcu_set_chan_info(struct mt7996_phy *phy, u16 tag)
 	struct cfg80211_chan_def *chandef = &phy->mt76->chandef;
 	int freq1 = chandef->center_freq1;
 	u8 band_idx = phy->mt76->band_idx;
+	bool scan;
+	int ret;
 	struct {
 		/* fixed field */
 		u8 __rsv[4];
@@ -4448,8 +4450,19 @@ int mt7996_mcu_set_chan_info(struct mt7996_phy *phy, u16 tag)
 		req.center_ch2 = ieee80211_frequency_to_channel(freq2);
 	}
 
-	return mt76_mcu_send_msg(&dev->mt76, MCU_WMWA_UNI_CMD(CHANNEL_SWITCH),
-				 &req, sizeof(req), true);
+	/* the firmware stops the station queues of the band at a scan switch
+	 * and starts them again only at a normal or DFS switch
+	 */
+	scan = req.switch_reason == CH_SWITCH_SCAN_BYPASS_DPD;
+	if (tag == UNI_CHANNEL_SWITCH && scan)
+		phy->fw_offchannel = true;
+
+	ret = mt76_mcu_send_msg(&dev->mt76, MCU_WMWA_UNI_CMD(CHANNEL_SWITCH),
+				&req, sizeof(req), true);
+	if (!ret && tag == UNI_CHANNEL_SWITCH && !scan)
+		phy->fw_offchannel = false;
+
+	return ret;
 }
 
 int mt7996_mcu_set_punct(struct mt7996_phy *phy)
drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +1 -0
index 5ee8bf12f73b..1e01e6075193 100644
@@ -421,6 +421,7 @@ struct mt7996_phy {
 	bool counter_reset;
 	bool rdd_tx_paused;
 	bool offchan_bcn_stopped;
+	bool fw_offchannel;
 };
 
 struct mt7996_dev {
Signature · 1 line
2.47.3
author maintainer
#11 lore raw

PATCH 12/17 wifi: mt76: reset the DFS state of a phy at a full reset

In reply to Felix Fietkau

mt76_reset_device() keeps phy->dfs_state, while the firmware loaded by the full reset runs no radar detector until the driver starts it. The channel set of the reconfig on the same channel then finds the DFS state unchanged and sends no RDD command. An AP on a DFS channel thus transmits without radar detection after the reset.

Set the DFS state to unknown at a full reset, as a channel change does. The reconfig then starts the radar detector again. A CAC across the reset still has no radar detection from the reset to the reconfig. mac80211 gives the driver no way to abort that CAC.

Fixes 8a55712d124f ("wifi: mt76: mt7915: enable full system reset support")
Fixes 27015b6fbcca ("wifi: mt76: mt7996: enable full system reset support")
---
 drivers/net/wireless/mediatek/mt76/mac80211.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/wireless/mediatek/mt76/mac80211.c +1 -0
index 77116d9f4125..4c4e9b7bc57a 100644
@@ -908,6 +908,7 @@ static void mt76_reset_phy(struct mt76_phy *phy)
 
 	phy->num_sta = 0;
 	phy->chanctx = NULL;
+	phy->dfs_state = MT_DFS_STATE_UNKNOWN;
 	mt76_roc_complete(phy);
 }
 
Signature · 1 line
2.47.3
author maintainer
#12 lore raw

PATCH 13/17 wifi: mt76: mt7996: abort a background CAC at a full reset

In reply to Felix Fietkau

A full reset reloads the firmware, which then runs no background radar chain, and nothing tells cfg80211. A background CAC in progress thus goes on without radar detection, and cfg80211 marks its channel available when the CAC time ends.

Report the CAC aborted to cfg80211 after the firmware reload. cfg80211 then stops the chain through the driver, which clears dev->rdd2_phy, and user space can start a new CAC. A restart of the chain would leave a gap without radar detection in the CAC.

Fixes 27015b6fbcca ("wifi: mt76: mt7996: enable full system reset support")
---
 drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +3 -0
index 62f3ac2b2cd2..cf8d57b7b5bb 100644
@@ -2555,6 +2555,9 @@ mt7996_mac_full_reset(struct mt7996_dev *dev)
 	if (i == 10)
 		dev_err(dev->mt76.dev, "chip full reset failed\n");
 
+	if (dev->rdd2_phy)
+		cfg80211_background_cac_abort(dev->rdd2_phy->mt76->hw->wiphy);
+
 	mt7996_for_each_phy(dev, phy) {
 		phy->omac_mask = 0;
 		phy->rxfilter |= MT_WF_RFCR_DROP_OTHER_UC;
Signature · 1 line
2.47.3
author maintainer
#13 lore raw

PATCH 14/17 wifi: mt76: mt7915: abort a background CAC at a full reset

In reply to Felix Fietkau

A full reset reloads the firmware, which then runs no background radar chain, and nothing tells cfg80211. A background CAC in progress thus goes on without radar detection, and cfg80211 marks its channel available when the CAC time ends.

Report the CAC aborted to cfg80211 after the firmware reload. cfg80211 then stops the chain through the driver, which clears dev->rdd2_phy, and user space can start a new CAC. A restart of the chain would leave a gap without radar detection in the CAC.

Fixes 8a55712d124f ("wifi: mt76: mt7915: enable full system reset support")
---
 drivers/net/wireless/mediatek/mt76/mt7915/mac.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7915/mac.c +3 -0
index 0c03199a55a4..5d1b5abc8fff 100644
@@ -1466,6 +1466,9 @@ mt7915_mac_full_reset(struct mt7915_dev *dev)
 	if (i == 10)
 		dev_err(dev->mt76.dev, "chip full reset failed\n");
 
+	if (dev->rdd2_phy)
+		cfg80211_background_cac_abort(dev->rdd2_phy->mt76->hw->wiphy);
+
 	dev->phy.omac_mask = 0;
 	if (phy2)
 		phy2->omac_mask = 0;
Signature · 1 line
2.47.3
author maintainer
#14 lore raw

PATCH 15/17 wifi: mt76: mt7996: clear the airtime counts with the WTBL counters

In reply to Felix Fietkau

mt7996_mac_sta_poll() reports the airtime of a link as the difference between the ADM counters of its WTBL entry and msta_link->airtime_ac[]. The driver clears the counters when it sets up or removes a link, but keeps airtime_ac[]. A link that the driver uses again thus starts with stale values: msta->deflink after a full reset, when the restart adds each station again on its old drv_priv, and a link that mt7996_mac_sta_change_links() removes and later adds back. The first poll then gives a u32 difference that wraps, and ieee80211_sta_register_airtime() adds up to about 2^32 microseconds to the airtime of the station.

Clear airtime_ac[] whenever the driver clears the counters of a link.

Fixes 27015b6fbcca ("wifi: mt76: mt7996: enable full system reset support")
Fixes f520eceacd24 ("wifi: mt76: mt7996: Add mt7996_mac_sta_change_links callback")
---
 drivers/net/wireless/mediatek/mt76/mt7996/mac.c  | 16 ++++++++++------
 drivers/net/wireless/mediatek/mt76/mt7996/main.c |  8 +++-----
 .../net/wireless/mediatek/mt76/mt7996/mt7996.h   |  2 ++
 3 files changed, 15 insertions(+), 11 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +10 -6
index cf8d57b7b5bb..229f797f4302 100644
@@ -64,6 +64,14 @@ bool mt7996_mac_wtbl_update(struct mt7996_dev *dev, int idx, u32 mask)
 			 0, 5000);
 }
 
+void mt7996_sta_link_airtime_clear(struct mt7996_dev *dev,
+				   struct mt7996_sta_link *msta_link)
+{
+	mt7996_mac_wtbl_update(dev, msta_link->wcid.idx,
+			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
+	memset(msta_link->airtime_ac, 0, sizeof(msta_link->airtime_ac));
+}
+
 u32 mt7996_mac_wtbl_lmac_addr(struct mt7996_dev *dev, u16 wcid, u8 dw)
 {
 	mt76_wr(dev, MT_WTBLON_TOP_WDUCR,
@@ -135,12 +143,8 @@ static void mt7996_mac_sta_poll(struct mt7996_dev *dev)
 			addr += 8;
 		}
 
-		if (clear) {
-			mt7996_mac_wtbl_update(dev, idx,
-					       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
-			memset(msta_link->airtime_ac, 0,
-			       sizeof(msta_link->airtime_ac));
-		}
+		if (clear)
+			mt7996_sta_link_airtime_clear(dev, msta_link);
 
 		if (!wcid->sta)
 			continue;
drivers/net/wireless/mediatek/mt76/mt7996/main.c +3 -5
index 253603d25662..e883a58844e9 100644
@@ -450,8 +450,7 @@ int mt7996_vif_link_add(struct mt76_phy *mphy, struct ieee80211_vif *vif,
 	msta_link->wcid.tx_info |= MT_WCID_TX_INFO_SET;
 	mt76_wcid_init(&msta_link->wcid, band_idx);
 
-	mt7996_mac_wtbl_update(dev, idx,
-			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
+	mt7996_sta_link_airtime_clear(dev, msta_link);
 
 	if (vif->type != NL80211_IFTYPE_AP &&
 	    (!mlink->omac_idx || mlink->omac_idx > 3))
@@ -1364,7 +1363,7 @@ mt7996_mac_sta_init_link(struct mt7996_dev *dev,
 
 	rcu_assign_pointer(msta->link[link_id], msta_link);
 
-	mt7996_mac_wtbl_update(dev, idx, MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
+	mt7996_sta_link_airtime_clear(dev, msta_link);
 
 	rcu_assign_pointer(dev->mt76.wcid[idx], &msta_link->wcid);
 	mt76_wcid_init(&msta_link->wcid, phy->mt76->band_idx);
@@ -1398,8 +1397,7 @@ void mt7996_mac_sta_remove_link(struct mt7996_dev *dev,
 	mt76_wcid_cleanup(&dev->mt76, &msta_link->wcid);
 
 	if (msta_link->wcid.link_valid) {
-		mt7996_mac_wtbl_update(dev, msta_link->wcid.idx,
-				       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
+		mt7996_sta_link_airtime_clear(dev, msta_link);
 
 		mt7996_sta_deflink_release(dev, sta, link_id);
 		msta_link->wcid.link_valid = false;
drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +2 -0
index 1e01e6075193..a9d265c90234 100644
@@ -917,6 +917,8 @@ static inline bool mt7996_has_ext_eeprom(struct mt7996_dev *dev)
 void mt7996_mac_init(struct mt7996_dev *dev);
 u32 mt7996_mac_wtbl_lmac_addr(struct mt7996_dev *dev, u16 wcid, u8 dw);
 bool mt7996_mac_wtbl_update(struct mt7996_dev *dev, int idx, u32 mask);
+void mt7996_sta_link_airtime_clear(struct mt7996_dev *dev,
+				   struct mt7996_sta_link *msta_link);
 void mt7996_mac_reset_counters(struct mt7996_phy *phy);
 void mt7996_mac_cca_stats_reset(struct mt7996_phy *phy);
 void mt7996_mac_enable_nf(struct mt7996_dev *dev, u8 band);
Signature · 1 line
2.47.3
author maintainer
#15 lore raw

PATCH 16/17 wifi: mt76: mt7996: drop the host WTBL write of a fixed GI

In reply to Felix Fietkau

mt7996_mcu_add_rate_ctrl_fixed() writes the GI of a fixed rate into DW7 of the station's LMAC WTBL entry. On mt7996 the GI fields are in DW6, and DW7 holds the BA window sizes. The write thus replaces the BA window size of TID 3, or of TIDs 6 and 7 for an HE station, and sets no GI.

Leave the GI to the firmware: the RATE_PARAM_FIXED_GI command already writes the GI fields of DW6 with a masked update.

Fixes 005c3f5914a8 ("wifi: mt76: mt7996: support more options for mt7996_set_bitrate_mask()")
---
 drivers/net/wireless/mediatek/mt76/mt7996/mcu.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +1 -14
index e4f52cb81470..ef48cad39d5e 100644
@@ -2395,7 +2395,7 @@ mt7996_mcu_add_rate_ctrl_fixed(struct mt7996_dev *dev, struct mt7996_sta *msta,
 	struct mt7996_vif_link *link;
 	struct sta_phy_uni phy = {};
 	struct ieee80211_sta *sta;
-	int ret, nrates = 0, idx;
+	int ret, nrates = 0;
 	enum nl80211_band band;
 	struct mt76_phy *mphy;
 	bool has_he;
@@ -2438,7 +2438,6 @@ mt7996_mcu_add_rate_ctrl_fixed(struct mt7996_dev *dev, struct mt7996_sta *msta,
 	band = mphy->chandef.chan->band;
 	has_he = link_sta->he_cap.has_he;
 	mask = link->bitrate_mask;
-	idx = msta_link->wcid.idx;
 
 	if (has_he) {
 		__sta_phy_bitrate_mask_check(he_mcs, he_gi, 0, 1);
@@ -2473,18 +2472,6 @@ mt7996_mcu_add_rate_ctrl_fixed(struct mt7996_dev *dev, struct mt7996_sta *msta,
 	/* fixed GI */
 	if (mask.control[band].gi != NL80211_TXRATE_DEFAULT_GI ||
 	    mask.control[band].he_gi != GENMASK(7, 0)) {
-		u32 addr;
-
-		/* firmware updates only TXCMD but doesn't take WTBL into
-		 * account, so driver should update here to reflect the
-		 * actual txrate hardware sends out.
-		 */
-		addr = mt7996_mac_wtbl_lmac_addr(dev, idx, 7);
-		if (has_he)
-			mt76_rmw_field(dev, addr, GENMASK(31, 24), phy.sgi);
-		else
-			mt76_rmw_field(dev, addr, GENMASK(15, 12), phy.sgi);
-
 		ret = mt7996_mcu_set_fixed_field(dev, msta, &phy, link_id,
 						 RATE_PARAM_FIXED_GI);
 		if (ret)
Signature · 1 line
2.47.3
author maintainer
#16 lore raw

PATCH 17/17 wifi: mt76: mt7925: don't reset the USB device on probe

In reply to Felix Fietkau

mt7925u_probe() resets the whole USB device. On MT7925 modules that expose Bluetooth on the same device, this also hits the interfaces that btusb drives. btusb has no pre_reset/post_reset handlers, so the reset unbinds it while it sets up the controller.

Drop the reset, like mt7921u does. mt7925u_probe() still resets the Wi-Fi subsystem with mt792xu_wfsys_reset() if the firmware is running.

Fixes c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips")
---
 drivers/net/wireless/mediatek/mt76/mt7925/usb.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/usb.c +0 -3
index ee5306c29427..b1f6ef35fffb 100644
@@ -190,7 +190,6 @@ static int mt7925u_probe(struct usb_interface *usb_intf,
 		.write_copy = mt792xu_copy,
 		.type = MT76_BUS_USB,
 	};
-	struct usb_device *udev = interface_to_usbdev(usb_intf);
 	struct ieee80211_ops *ops;
 	struct ieee80211_hw *hw;
 	struct mt792x_dev *dev;
@@ -214,8 +213,6 @@ static int mt7925u_probe(struct usb_interface *usb_intf,
 	dev->hif_ops = &hif_ops;
 	mt792xu_reset_work_init(dev);
 
-	usb_reset_device(udev);
-
 	usb_set_intfdata(usb_intf, dev);
 
 	ret = __mt76u_init(mdev, usb_intf, &bus_ops);
Signature · 1 line
2.47.3