From: Felix Fietkau <nbd@nbd.name>
To: linux-wireless@vger.kernel.org
Subject: [PATCH mt76-next 04/17] wifi: mt76: mt7925: keep the deflink wcid index until station removal
Date: Sat, 21 Nov 2026 13:09:13 +0100 [thread overview]
Message-ID: <20261121120926.3603979-4-nbd@nbd.name> (raw)
In-Reply-To: <20261121120926.3603979-1-nbd@nbd.name>
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")
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
.../net/wireless/mediatek/mt76/mt7925/main.c | 30 +++++++++++++++----
drivers/net/wireless/mediatek/mt76/mt792x.h | 1 +
2 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
index 534f412579b1..5a185d7422f0 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
@@ -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);
diff --git a/drivers/net/wireless/mediatek/mt76/mt792x.h b/drivers/net/wireless/mediatek/mt76/mt792x.h
index 10175875e76b..b142be13ab78 100644
--- a/drivers/net/wireless/mediatek/mt76/mt792x.h
+++ b/drivers/net/wireless/mediatek/mt76/mt792x.h
@@ -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;
--
2.47.3
next prev parent reply other threads:[~2026-11-21 12:09 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 12:09 [PATCH mt76-next 01/17] wifi: mt76: mt7996: name a new secondary link to the firmware first Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 02/17] wifi: mt76: add a helper to point the TXQs of a station at a wcid Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 03/17] wifi: mt76: mt7925: move the default link to a remaining link Felix Fietkau
2026-11-21 12:09 ` Felix Fietkau [this message]
2026-11-21 12:09 ` [PATCH mt76-next 05/17] wifi: mt76: mt792x: look up the TX links under RCU Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 06/17] wifi: mt76: mt7925: read the links under RCU in the IPv6 notifier Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 07/17] wifi: mt76: mt7925: abort a ROC on the BSS that requested it Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 08/17] wifi: mt76: mt7925: take the link conf of a removed link from old[] Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 09/17] wifi: mt76: mt7925: send the MLO ROC only for a station vif Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 10/17] wifi: mt76: mt7996: send the Beacon rate table again after a full reset Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 11/17] wifi: mt76: mt7996: restore the operating channel after an L1 SER Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 12/17] wifi: mt76: reset the DFS state of a phy at a full reset Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 13/17] wifi: mt76: mt7996: abort a background CAC " Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 14/17] wifi: mt76: mt7915: " Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 15/17] wifi: mt76: mt7996: clear the airtime counts with the WTBL counters Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 16/17] wifi: mt76: mt7996: drop the host WTBL write of a fixed GI Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 17/17] wifi: mt76: mt7925: don't reset the USB device on probe Felix Fietkau
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=20261121120926.3603979-4-nbd@nbd.name \
--to=nbd@nbd.name \
--cc=linux-wireless@vger.kernel.org \
/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