wifi: mt76: mt7925: fix up MLO link lifetime and error handling
Subsystems (2)
cover wifi: mt76: mt7925: fix up MLO link lifetime and error handling
From: Sean Wang <[email protected]>
Hi,
This series fix up MLO link STA lifetime and error handling in mt7925.
The current add path may expose partially initialized links and does not reliably release host resources when firmware commands fail (e.g. MCU timeouts). In addition, several helpers internally look up mlink, creating implicit dependencies on driver state and making the code harder to reason about and maintain.
Switch link STA handling to RCU lifetime, align WCID publish/teardown ordering, pass mlink explicitly to helpers, and add host-side unwind logic to release resources when link add fails.
Sean
Sean Wang (19):
wifi: mt76: mt7925: pass mlink to sta_amsdu_tlv()
wifi: mt76: mt7925: pass WCID indices to bss_basic_tlv()
wifi: mt76: mt7925: pass mlink and mconf to sta_mld_tlv()
wifi: mt76: mt7925: pass mlink to mcu_sta_update()
wifi: mt76: mt7925: resolve primary mlink via def_wcid
wifi: mt76: mt7925: pass mlink to mac_link_sta_remove()
wifi: mt76: mt7925: pass mlink to sta_hdr_trans_tlv()
wifi: mt76: mt7925: validate mlink in sta_hdr_trans_tlv()
wifi: mt76: mt7925: pass mlink to wtbl_update_hdr_trans()
wifi: mt76: mt7925: pass mlink to set_link_key()
wifi: mt76: mt7925: resolve link after acquiring mt76 mutex
wifi: mt76: mt7925: pass mconf and mlink to wtbl_update_hdr_trans()
wifi: mt76: mt7925: make WCID cleanup unconditional in
sta_remove_links()
wifi: mt76: mt7925: unwind WCID setup on link STA add failure
wifi: mt76: mt7925: drop WCID reinit after publish
wifi: mt76: mt7925: move WCID teardown into link_sta_remove()
wifi: mt76: mt7925: switch link STA allocation to RCU lifetime
wifi: mt76: mt7925: publish msta->link after successful link add
wifi: mt76: mt7925: host-only unwind published links on add failure
.../net/wireless/mediatek/mt76/mt7925/mac.c | 3 +- .../net/wireless/mediatek/mt76/mt7925/main.c | 221 +++++++++++++----- .../net/wireless/mediatek/mt76/mt7925/mcu.c | 180 +++++++------- .../net/wireless/mediatek/mt76/mt7925/mcu.h | 7 + .../wireless/mediatek/mt76/mt7925/mt7925.h | 8 +- drivers/net/wireless/mediatek/mt76/mt792x.h | 1 + 6 files changed, 280 insertions(+), 140 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/19 wifi: mt76: mt7925: pass mlink to sta_amsdu_tlv()
From: Sean Wang <[email protected]>
Drop the mt792x_sta_to_link() lookup in mt7925_mcu_sta_amsdu_tlv() and pass mlink from the caller instead. The link context is already known so the lookup is redundant.
This makes link ownership explicit and keeps the helper lookup-free.
No functional change intended.
--- drivers/net/wireless/mediatek/mt76/mt7925/mcu.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +6 -5
@@ -1726,10 +1726,9 @@ mt7925_mcu_sta_vht_tlv(struct sk_buff *skb, struct ieee80211_link_sta *link_sta)static void mt7925_mcu_sta_amsdu_tlv (struct sk_buff *skb,struct ieee80211_vif *vif, -struct ieee80211_link_sta *link_sta) +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_link_sta *mlink;struct sta_rec_amsdu *amsdu;struct tlv *tlv;
@@ -1745,7 +1744,6 @@ mt7925_mcu_sta_amsdu_tlv(struct sk_buff *skb, amsdu->max_amsdu_num =8 ; amsdu->amsdu_en = true; - mlink =mt792x_sta_to_link (msta, link_sta->link_id); mlink->wcid.amsdu = true;switch (link_sta->agg.max_amsdu_len) {
@@ -1966,6 +1964,7 @@ mt7925_mcu_sta_cmd(struct mt76_phy *phy,struct mt792x_vif *mvif = (struct mt792x_vif *)info->vif->drv_priv;struct mt76_dev *dev = phy->dev;struct mt792x_bss_conf *mconf; +struct mt792x_link_sta *mlink;struct sk_buff *skb;int conn_state;
@@ -1980,6 +1979,8 @@ mt7925_mcu_sta_cmd(struct mt76_phy *phy,CONN_STATE_DISCONNECT ;if (info->enable && info->link_sta) { + mlink = container_of(info->wcid, struct mt792x_link_sta, wcid); +mt76_connac_mcu_sta_basic_tlv (dev, skb, info->link_conf, info->link_sta, conn_state, info->newly);
@@ -1987,7 +1988,7 @@ mt7925_mcu_sta_cmd(struct mt76_phy *phy,mt7925_mcu_sta_ht_tlv (skb, info->link_sta);mt7925_mcu_sta_vht_tlv (skb, info->link_sta);mt76_connac_mcu_sta_uapsd (skb, info->vif, info->link_sta->sta); -mt7925_mcu_sta_amsdu_tlv (skb, info->vif, info->link_sta); +mt7925_mcu_sta_amsdu_tlv (skb, info->vif, info->link_sta, mlink);mt7925_mcu_sta_he_tlv (skb, info->link_sta);mt7925_mcu_sta_he_6g_tlv (skb, info->link_sta);mt7925_mcu_sta_eht_tlv (skb, info->link_sta);
Signature · 1 line
2.43.0
PATCH 2/19 wifi: mt76: mt7925: pass WCID indices to bss_basic_tlv()
In reply to Sean WangFrom: Sean Wang <[email protected]>
Drop the mt792x_sta_to_link() lookup in mt7925_mcu_bss_basic_tlv() and pass the resolved WCID indices from the caller instead. The link context is already known, so the lookup is redundant.
This makes link ownership explicit and keeps the helper lookup-free.
No functional change intended.
--- .../net/wireless/mediatek/mt76/mt7925/main.c | 34 +++++++--- .../net/wireless/mediatek/mt76/mt7925/mcu.c | 68 ++++++++++++------- .../net/wireless/mediatek/mt76/mt7925/mcu.h | 7 ++ 3 files changed, 73 insertions(+), 36 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +23 -11
@@ -850,20 +850,22 @@ mt7925_get_rates_table(struct ieee80211_hw *hw, struct ieee80211_vif *vif,static int mt7925_mac_link_sta_add (struct mt76_dev *mdev,struct ieee80211_vif *vif, -struct ieee80211_link_sta *link_sta) +struct ieee80211_link_sta *link_sta, +struct mt792x_link_sta *mlink) { struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;struct ieee80211_bss_conf *link_conf;struct mt792x_bss_conf *mconf;u8 link_id = link_sta->link_id; -struct mt792x_link_sta *mlink;struct mt792x_sta *msta;struct mt76_wcid *wcid;int ret, idx; msta = (struct mt792x_sta *)link_sta->sta->drv_priv; - mlink =mt792x_sta_to_link (msta, link_id); + +if (WARN_ON_ONCE (!mlink)) +return -EINVAL ; idx =mt76_wcid_alloc (dev->mt76.wcid_mask, MT792x_WTBL_STA -1 );if (idx <0 )
@@ -898,12 +900,21 @@ static int mt7925_mac_link_sta_add(struct mt76_dev *mdev,/* should update bss info before STA add */ if (vif->type ==NL80211_IFTYPE_STATION && !link_sta->sta->tdls) { -if (ieee80211_vif_is_mld (vif)) -mt7925_mcu_add_bss_info (&dev->phy, mconf->mt76.ctx, - link_conf, link_sta, link_sta != mlink->pri_link); -else -mt7925_mcu_add_bss_info (&dev->phy, mconf->mt76.ctx, - link_conf, link_sta, false); +struct mt792x_link_sta *mlink_bc; + + mlink_bc =mt792x_sta_to_link (&mvif->sta, mconf->link_id); + +if (ieee80211_vif_is_mld (vif)) { +mt7925_mcu_add_bss_info_sta (&dev->phy, mconf->mt76.ctx, + link_conf, link_sta, + mlink_bc->wcid.idx, mlink->wcid.idx, + link_sta != mlink->pri_link); + }else { +mt7925_mcu_add_bss_info_sta (&dev->phy, mconf->mt76.ctx, + link_conf, link_sta, + mlink_bc->wcid.idx, mlink->wcid.idx, + false); + } } if (ieee80211_vif_is_mld(vif) &&
@@ -965,7 +976,7 @@ mt7925_mac_sta_add_links(struct mt792x_dev *dev, struct ieee80211_vif *vif, mlink->wcid.def_wcid = &msta->deflink.wcid; link_sta =mt792x_sta_to_link_sta (vif, sta, link_id); -mt7925_mac_link_sta_add (&dev->mt76, vif, link_sta); +mt7925_mac_link_sta_add (&dev->mt76, vif, link_sta, mlink); }return err;
@@ -989,7 +1000,8 @@ int mt7925_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif, err =mt7925_mac_sta_add_links (dev, vif, sta, sta->valid_links); }else { - err =mt7925_mac_link_sta_add (mdev, vif, &sta->deflink); + err =mt7925_mac_link_sta_add (mdev, vif, &sta->deflink, + &msta->deflink); }return err;
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +43 -25
110 lines not on this page · raw message
drivers/net/wireless/mediatek/mt76/mt7925/mcu.h +7 -0
@@ -693,6 +693,13 @@ int mt7925_mcu_add_bss_info(struct mt792x_phy *phy,struct ieee80211_bss_conf *link_conf, struct ieee80211_link_sta *link_sta, int enable); +int mt7925_mcu_add_bss_info_sta (struct mt792x_phy *phy, +struct ieee80211_chanctx_conf *ctx, +struct ieee80211_bss_conf *link_conf, +struct ieee80211_link_sta *link_sta, +u16 bmc_tx_wlan_idx, +u16 sta_wlan_idx, +int enable);int mt7925_mcu_set_timing (struct mt792x_phy *phy,struct ieee80211_bss_conf *link_conf);int mt7925_mcu_set_deep_sleep (struct mt792x_dev *dev,bool enable);
Signature · 1 line
2.43.0
PATCH 3/19 wifi: mt76: mt7925: pass mlink and mconf to sta_mld_tlv()
In reply to Sean WangFrom: Sean Wang <[email protected]>
Drop the mt792x_sta_to_link() lookup in mt7925_mcu_sta_mld_tlv() and pass mlink and mconf from the caller instead. The link context is already known at the call site, making the lookup redundant.
This keeps the helper lookup-free and makes MLD link selection explicit.
No functional change intended.
--- .../net/wireless/mediatek/mt76/mt7925/mcu.c | 53 +++++++++++++------ 1 file changed, 36 insertions(+), 17 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +36 -17
@@ -1914,36 +1914,53 @@ mt7925_mcu_sta_eht_mld_tlv(struct sk_buff *skb,static void mt7925_mcu_sta_mld_tlv (struct sk_buff *skb, -struct ieee80211_vif *vif,struct ieee80211_sta *sta) +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +struct mt792x_bss_conf *mconf, +struct mt792x_link_sta *mlink) {struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv; -unsigned long valid = mvif->valid_links; -struct mt792x_bss_conf *mconf; -struct mt792x_link_sta *mlink; +struct mt792x_dev *dev = mvif->phy->dev; +struct mt792x_bss_conf *mconf_pri;struct sta_rec_mld *mld;struct tlv *tlv; -int i, cnt =0 ; +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 caller is operating on deflink, reuse its mconf as primary. */ +if (!mconf_pri && mlink == &msta->deflink) + mconf_pri = mconf; + +if (!mconf_pri) { +dev_warn_ratelimited (dev->mt76.dev, +"mt7925: MLD_TLV_LINK skip (no primary mconf) sta=%pM\n" , + sta->addr); +return ; + } tlv =mt76_connac_mcu_add_tlv (skb,STA_REC_MLD ,sizeof (*mld)); 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->link_num =min_t (u8,hweight16 (mvif->valid_links),2 ); -for_each_set_bit (i, &valid,IEEE80211_MLD_MAX_NUM_LINKS ) { -if (cnt == mld->link_num) -break ; +/* Always encode primary link first. */ + mld->link[cnt].wlan_id =cpu_to_le16 (msta->deflink.wcid.idx); + mld->link[cnt++].bss_idx = mconf_pri->mt76.idx; - mconf =mt792x_vif_to_link (mvif, i); - mlink =mt792x_sta_to_link (msta, i); +/* Optionally encode the currently-updated secondary link. */ +if (mlink && mlink != &msta->deflink && mconf) { + mld->secondary_id =cpu_to_le16 (mlink->wcid.idx); mld->link[cnt].wlan_id =cpu_to_le16 (mlink->wcid.idx); mld->link[cnt++].bss_idx = mconf->mt76.idx; - -if (mlink != &msta->deflink) - mld->secondary_id =cpu_to_le16 (mlink->wcid.idx); } + + mld->link_num = cnt; } static void
@@ -1969,6 +1986,7 @@ mt7925_mcu_sta_cmd(struct mt76_phy *phy,int conn_state; mconf =mt792x_vif_to_link (mvif, info->wcid->link_id); + mlink = container_of(info->wcid, struct mt792x_link_sta, wcid); skb =__mt76_connac_mcu_alloc_sta_req (dev, &mconf->mt76, info->wcid,MT7925_STA_UPDATE_MAX_SIZE );
@@ -1979,8 +1997,6 @@ mt7925_mcu_sta_cmd(struct mt76_phy *phy,CONN_STATE_DISCONNECT ;if (info->enable && info->link_sta) { - mlink = container_of(info->wcid, struct mt792x_link_sta, wcid); -mt76_connac_mcu_sta_basic_tlv (dev, skb, info->link_conf, info->link_sta, conn_state, info->newly);
@@ -1999,7 +2015,10 @@ mt7925_mcu_sta_cmd(struct mt76_phy *phy, info->state);if (info->state !=MT76_STA_INFO_STATE_NONE ) { -mt7925_mcu_sta_mld_tlv (skb, info->vif, info->link_sta->sta); +mt7925_mcu_sta_mld_tlv (skb, info->vif, + info->link_sta->sta, + mconf, mlink); +mt7925_mcu_sta_eht_mld_tlv (skb, info->vif, info->link_sta->sta); } }
Signature · 1 line
2.43.0
PATCH 4/19 wifi: mt76: mt7925: pass mlink to mcu_sta_update()
In reply to Sean WangFrom: Sean Wang <[email protected]>
Drop the mt792x_sta_to_link() lookup in mt7925_mcu_sta_update() and pass the resolved mlink from the caller instead. The link context is already known at the call site, making the lookup redundant.
This keeps the helper lookup-free and makes WCID selection explicit.
No functional change intended.
--- .../net/wireless/mediatek/mt76/mt7925/mac.c | 3 ++- .../net/wireless/mediatek/mt76/mt7925/main.c | 27 +++++++++++++------ .../net/wireless/mediatek/mt76/mt7925/mcu.c | 12 +++------ .../wireless/mediatek/mt76/mt7925/mt7925.h | 4 ++- 4 files changed, 28 insertions(+), 18 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/mac.c +2 -1
@@ -1285,7 +1285,8 @@ mt7925_vif_connect_iter(void *priv, u8 *mac,if (vif->type ==NL80211_IFTYPE_AP ) {mt76_connac_mcu_uni_add_bss (dev->phy.mt76, vif, &mvif->sta.deflink.wcid, true,NULL ); -mt7925_mcu_sta_update (dev,NULL , vif, true, +mt7925_mcu_sta_update (dev,NULL , vif, + &mvif->sta.deflink, true,MT76_STA_INFO_STATE_NONE );mt7925_mcu_uni_add_beacon_offload (dev, hw, vif, true); }
drivers/net/wireless/mediatek/mt76/mt7925/main.c +19 -8
@@ -919,23 +919,31 @@ static int mt7925_mac_link_sta_add(struct mt76_dev *mdev,if (ieee80211_vif_is_mld (vif) && link_sta == mlink->pri_link) { - ret =mt7925_mcu_sta_update (dev, link_sta, vif, true, + ret =mt7925_mcu_sta_update (dev, link_sta, vif, + mlink, true,MT76_STA_INFO_STATE_NONE );if (ret)return ret; }else if (ieee80211_vif_is_mld (vif) && link_sta != mlink->pri_link) { +struct mt792x_link_sta *pri_mlink; + + pri_mlink =mt792x_sta_to_link (msta, mlink->pri_link->link_id); + ret =mt7925_mcu_sta_update (dev, mlink->pri_link, vif, - true,MT76_STA_INFO_STATE_ASSOC ); + pri_mlink, true, +MT76_STA_INFO_STATE_ASSOC );if (ret)return ret; - ret =mt7925_mcu_sta_update (dev, link_sta, vif, true, + ret =mt7925_mcu_sta_update (dev, link_sta, vif, + mlink, true,MT76_STA_INFO_STATE_ASSOC );if (ret)return ret; }else { - ret =mt7925_mcu_sta_update (dev, link_sta, vif, true, + ret =mt7925_mcu_sta_update (dev, link_sta, vif, + mlink, true,MT76_STA_INFO_STATE_NONE );if (ret)return ret;
@@ -1075,7 +1083,8 @@ static void mt7925_mac_link_sta_assoc(struct mt76_dev *mdev, MT_WTBL_UPDATE_ADM_COUNT_CLEAR);memset (mlink->airtime_ac,0 ,sizeof (mlink->airtime_ac)); -mt7925_mcu_sta_update (dev, link_sta, vif, true,MT76_STA_INFO_STATE_ASSOC ); +mt7925_mcu_sta_update (dev, link_sta, vif, mlink, true, +MT76_STA_INFO_STATE_ASSOC );mt792x_mutex_release (dev); }
@@ -1119,7 +1128,7 @@ static void mt7925_mac_link_sta_remove(struct mt76_dev *mdev,mt76_connac_free_pending_tx_skbs (&dev->pm, &mlink->wcid);mt76_connac_pm_wake (&dev->mphy, &dev->pm); -mt7925_mcu_sta_update (dev, link_sta, vif, false, +mt7925_mcu_sta_update (dev, link_sta, vif, mlink, false,MT76_STA_INFO_STATE_NONE );mt7925_mac_wtbl_update (dev, mlink->wcid.idx,MT_WTBL_UPDATE_ADM_COUNT_CLEAR );
@@ -1744,7 +1753,8 @@ mt7925_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,if (err) goto out; - err =mt7925_mcu_sta_update (dev,NULL , vif, true, + err =mt7925_mcu_sta_update (dev,NULL , vif, + &mvif->sta.deflink, true,MT76_STA_INFO_STATE_NONE ); out:mt792x_mutex_release (dev);
@@ -1887,7 +1897,8 @@ static void mt7925_vif_cfg_changed(struct ieee80211_hw *hw,mt792x_mutex_acquire (dev);if (changed &BSS_CHANGED_ASSOC ) { -mt7925_mcu_sta_update (dev,NULL , vif, true, +mt7925_mcu_sta_update (dev,NULL , vif, + &mvif->sta.deflink, true,MT76_STA_INFO_STATE_ASSOC );mt7925_mcu_set_beacon_filter (dev, vif, vif->cfg.assoc);
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +4 -8
@@ -2036,7 +2036,9 @@ mt7925_mcu_sta_cmd(struct mt76_phy *phy,int mt7925_mcu_sta_update (struct mt792x_dev *dev,struct ieee80211_link_sta *link_sta, -struct ieee80211_vif *vif,bool enable, +struct ieee80211_vif *vif, +struct mt792x_link_sta *mlink, +bool enable,enum mt76_sta_info_state state) {struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
@@ -2051,14 +2053,8 @@ int mt7925_mcu_sta_update(struct mt792x_dev *dev, .offload_fw = true, .rcpi = to_rcpi(rssi), }; -struct mt792x_sta *msta; -struct mt792x_link_sta *mlink; -if (link_sta) { - msta = (struct mt792x_sta *)link_sta->sta->drv_priv; - mlink =mt792x_sta_to_link (msta, link_sta->link_id); - } - info.wcid = link_sta ? &mlink->wcid : &mvif->sta.deflink.wcid; + info.wcid = &mlink->wcid; info.newly = state !=MT76_STA_INFO_STATE_ASSOC ;return mt7925_mcu_sta_cmd (&dev->mphy, &info);
drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h +3 -1
@@ -250,7 +250,9 @@ int mt7925_mcu_set_bss_pm(struct mt792x_dev *dev, bool enable);int mt7925_mcu_sta_update (struct mt792x_dev *dev,struct ieee80211_link_sta *link_sta, -struct ieee80211_vif *vif,bool enable, +struct ieee80211_vif *vif, +struct mt792x_link_sta *mlink, +bool enable,enum mt76_sta_info_state state);int mt7925_mcu_set_chan_info (struct mt792x_phy *phy,u16 tag);int mt7925_mcu_set_tx (struct mt792x_dev *dev,struct ieee80211_bss_conf *bss_conf);
Signature · 1 line
2.43.0
PATCH 5/19 wifi: mt76: mt7925: resolve primary mlink via def_wcid
In reply to Sean WangFrom: Sean Wang <[email protected]>
Use mlink->wcid.def_wcid to obtain the primary mlink in mt7925_mac_link_sta_add() instead of calling mt792x_sta_to_link().
The primary link context is already carried by the WCID, so the extra lookup is redundant. This makes the add path follow the existing WCID association directly.
No functional change intended.
--- drivers/net/wireless/mediatek/mt76/mt7925/main.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +10 -1
@@ -927,8 +927,17 @@ static int mt7925_mac_link_sta_add(struct mt76_dev *mdev, }else if (ieee80211_vif_is_mld (vif) && link_sta != mlink->pri_link) {struct mt792x_link_sta *pri_mlink; +struct mt76_wcid *pri_wcid; - pri_mlink =mt792x_sta_to_link (msta, mlink->pri_link->link_id); +/* 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)) +return -EINVAL ; ret = mt7925_mcu_sta_update(dev, mlink->pri_link, vif, pri_mlink, true,
Signature · 1 line
2.43.0
PATCH 6/19 wifi: mt76: mt7925: pass mlink to mac_link_sta_remove()
In reply to Sean WangFrom: Sean Wang <[email protected]>
Drop the mt792x_sta_to_link() lookup in mt7925_mac_link_sta_remove() and pass mlink from mt7925_mac_sta_remove_links() instead. The link is already resolved there, making the extra lookup redundant.
This keeps the remove helper lookup-free and avoids hidden dependence on msta->link[link_id] during teardown.
No functional change intended.
--- drivers/net/wireless/mediatek/mt76/mt7925/main.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +3 -7
@@ -1121,16 +1121,12 @@ EXPORT_SYMBOL_GPL(mt7925_mac_sta_event);static void mt7925_mac_link_sta_remove (struct mt76_dev *mdev,struct ieee80211_vif *vif, -struct ieee80211_link_sta *link_sta) +struct ieee80211_link_sta *link_sta, +struct mt792x_link_sta *mlink) { struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);struct ieee80211_bss_conf *link_conf;u8 link_id = link_sta->link_id; -struct mt792x_link_sta *mlink; -struct mt792x_sta *msta; - - msta = (struct mt792x_sta *)link_sta->sta->drv_priv; - mlink =mt792x_sta_to_link (msta, link_id);mt7925_roc_abort_sync (dev);
@@ -1213,7 +1209,7 @@ mt7925_mac_sta_remove_links(struct mt792x_dev *dev, struct ieee80211_vif *vif,if (!mlink)continue ; -mt7925_mac_link_sta_remove (&dev->mt76, vif, link_sta); +mt7925_mac_link_sta_remove (&dev->mt76, vif, link_sta, mlink); wcid = &mlink->wcid;rcu_assign_pointer (msta->link[link_id],NULL );
Signature · 1 line
2.43.0
PATCH 7/19 wifi: mt76: mt7925: pass mlink to sta_hdr_trans_tlv()
In reply to Sean WangFrom: Sean Wang <[email protected]>
Drop the mt792x_sta_to_link() lookup in mt7925_mcu_sta_hdr_trans_tlv() and pass the resolved mlink from the caller instead. The link is already known at the call site, making the lookup redundant.
This keeps the helper lookup-free and makes WCID selection explicit.
No functional change intended.
--- .../net/wireless/mediatek/mt76/mt7925/mcu.c | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +11 -13
@@ -1066,9 +1066,9 @@ EXPORT_SYMBOL_GPL(mt7925_run_firmware);static void mt7925_mcu_sta_hdr_trans_tlv (struct sk_buff *skb,struct ieee80211_vif *vif, -struct ieee80211_link_sta *link_sta) +struct ieee80211_link_sta *link_sta, +struct mt792x_link_sta *mlink) { -struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;struct sta_rec_hdr_trans *hdr_trans;struct mt76_wcid *wcid;struct tlv *tlv;
@@ -1082,15 +1082,7 @@ mt7925_mcu_sta_hdr_trans_tlv(struct sk_buff *skb,else hdr_trans->from_ds = true; -if (link_sta) { -struct mt792x_sta *msta = (struct mt792x_sta *)link_sta->sta->drv_priv; -struct mt792x_link_sta *mlink; - - mlink =mt792x_sta_to_link (msta, link_sta->link_id); - wcid = &mlink->wcid; - }else { - wcid = &mvif->sta.deflink.wcid; - } + wcid = &mlink->wcid;if (!wcid)return ;
@@ -1127,7 +1119,10 @@ int mt7925_mcu_wtbl_update_hdr_trans(struct mt792x_dev *dev,return PTR_ERR (skb);/* starec hdr trans */ -mt7925_mcu_sta_hdr_trans_tlv (skb, vif, link_sta); +if (!link_sta) + mlink = &mvif->sta.deflink; + +mt7925_mcu_sta_hdr_trans_tlv (skb, vif, link_sta, mlink);return mt76_mcu_skb_send_msg (&dev->mt76, skb,MCU_WMWA_UNI_CMD (STA_REC_UPDATE ), true); }
@@ -2028,7 +2023,10 @@ mt7925_mcu_sta_cmd(struct mt76_phy *phy,mt76_connac_mcu_add_tlv (skb,STA_REC_MLD_OFF ,sizeof (struct tlv )); }else { -mt7925_mcu_sta_hdr_trans_tlv (skb, info->vif, info->link_sta); +if (!info->link_sta) + mlink = &mvif->sta.deflink; + +mt7925_mcu_sta_hdr_trans_tlv (skb, info->vif, info->link_sta, mlink); }return mt76_mcu_skb_send_msg (dev, skb, info->cmd, true);
Signature · 1 line
2.43.0
PATCH 8/19 wifi: mt76: mt7925: validate mlink in sta_hdr_trans_tlv()
In reply to Sean WangFrom: Sean Wang <[email protected]>
Replace the dead wcid NULL check in mt7925_mcu_sta_hdr_trans_tlv() with a WARN_ON_ONCE() guard on mlink before dereferencing mlink->wcid.
wcid is always derived from mlink, so mlink is the only meaningful object to validate here.
--- drivers/net/wireless/mediatek/mt76/mt7925/mcu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +3 -3
@@ -1082,11 +1082,11 @@ mt7925_mcu_sta_hdr_trans_tlv(struct sk_buff *skb,else hdr_trans->from_ds = true; - wcid = &mlink->wcid; - -if (!wcid) +if (WARN_ON_ONCE (!mlink))return ; + wcid = &mlink->wcid; + hdr_trans->dis_rx_hdr_tran = !test_bit (MT_WCID_FLAG_HDR_TRANS , &wcid->flags);if (test_bit (MT_WCID_FLAG_4ADDR , &wcid->flags)) { hdr_trans->to_ds = true;
Signature · 1 line
2.43.0
PATCH 9/19 wifi: mt76: mt7925: pass mlink to wtbl_update_hdr_trans()
In reply to Sean WangFrom: Sean Wang <[email protected]>
Drop the mt792x_sta_to_link() lookup in mt7925_mcu_wtbl_update_hdr_trans() and pass the resolved mlink from the caller instead. The link context is already known at the call site, making the lookup redundant.
This keeps the helper lookup-free and makes link ownership explicit.
No functional change intended.
--- drivers/net/wireless/mediatek/mt76/mt7925/main.c | 2 +- drivers/net/wireless/mediatek/mt76/mt7925/mcu.c | 8 ++------ drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h | 1 + 3 files changed, 4 insertions(+), 7 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +1 -1
@@ -1598,7 +1598,7 @@ static void mt7925_sta_set_decap_offload(struct ieee80211_hw *hw,if (!mlink->wcid.sta)continue ; -mt7925_mcu_wtbl_update_hdr_trans (dev, vif, sta, i); +mt7925_mcu_wtbl_update_hdr_trans (dev, vif, sta, mlink, i); }mt792x_mutex_release (dev);
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +2 -6
@@ -1097,18 +1097,14 @@ mt7925_mcu_sta_hdr_trans_tlv(struct sk_buff *skb,int mt7925_mcu_wtbl_update_hdr_trans (struct mt792x_dev *dev,struct ieee80211_vif *vif,struct ieee80211_sta *sta, +struct mt792x_link_sta *mlink,int link_id) { -struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;struct ieee80211_link_sta *link_sta = sta ? &sta->deflink :NULL ; -struct mt792x_link_sta *mlink; +struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;struct mt792x_bss_conf *mconf; -struct mt792x_sta *msta;struct sk_buff *skb; - msta = sta ? (struct mt792x_sta *)sta->drv_priv : &mvif->sta; - - mlink =mt792x_sta_to_link (msta, link_id); link_sta =mt792x_sta_to_link_sta (vif, sta, link_id); mconf =mt792x_vif_to_link (mvif, link_id);
drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h +1 -0
@@ -371,6 +371,7 @@ int mt7925_mcu_set_rts_thresh(struct mt792x_phy *phy, u32 val);int mt7925_mcu_wtbl_update_hdr_trans (struct mt792x_dev *dev,struct ieee80211_vif *vif,struct ieee80211_sta *sta, +struct mt792x_link_sta *mlink,int link_id);int mt7925_mcu_wf_rf_pin_ctrl (struct mt792x_phy *phy);
Signature · 1 line
2.43.0
PATCH 10/19 wifi: mt76: mt7925: pass mlink to set_link_key()
In reply to Sean WangFrom: Sean Wang <[email protected]>
Drop the mt792x_sta_to_link() lookup in mt7925_set_link_key() and pass the resolved mlink from the caller instead. The link context is already known at the call site, making the lookup redundant.
This keeps the helper lookup-free and makes link ownership explicit.
No functional change intended.
--- drivers/net/wireless/mediatek/mt76/mt7925/main.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +9 -5
@@ -594,7 +594,8 @@ static int mt7925_cancel_remain_on_channel(struct ieee80211_hw *hw,static int mt7925_set_link_key (struct ieee80211_hw *hw,enum set_key_cmd cmd,struct ieee80211_vif *vif,struct ieee80211_sta *sta, -struct ieee80211_key_conf *key,int link_id) +struct ieee80211_key_conf *key,int link_id, +struct mt792x_link_sta *mlink) {struct mt792x_dev *dev =mt792x_hw_dev (hw);struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
@@ -603,7 +604,6 @@ static int mt7925_set_link_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,struct ieee80211_bss_conf *link_conf;struct ieee80211_link_sta *link_sta;int idx = key->keyidx, err =0 ; -struct mt792x_link_sta *mlink;struct mt792x_bss_conf *mconf;struct mt76_wcid *wcid;u8 *wcid_keyidx;
@@ -611,7 +611,6 @@ static int mt7925_set_link_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, link_conf =mt792x_vif_to_bss_conf (vif, link_id); link_sta = sta ?mt792x_sta_to_link_sta (vif, sta, link_id) :NULL ; mconf =mt792x_vif_to_link (mvif, link_id); - mlink =mt792x_sta_to_link (msta, link_id); wcid = &mlink->wcid; wcid_keyidx = &wcid->hw_key_idx;
@@ -679,6 +678,7 @@ static int mt7925_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;struct mt792x_sta *msta = sta ? (struct mt792x_sta *)sta->drv_priv : &mvif->sta; +struct mt792x_link_sta *mlink;int err;/* The hardware does not support per-STA RX GTK, fallback
@@ -700,12 +700,16 @@ static int mt7925_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, add = key->link_id !=-1 ?BIT (key->link_id) : msta->valid_links;for_each_set_bit (link_id, &add,IEEE80211_MLD_MAX_NUM_LINKS ) { - err =mt7925_set_link_key (hw, cmd, vif, sta, key, link_id); + mlink =mt792x_sta_to_link (msta, link_id); + err =mt7925_set_link_key (hw, cmd, vif, sta, key, link_id, + mlink);if (err <0 )break ; } }else { - err =mt7925_set_link_key (hw, cmd, vif, sta, key, vif->bss_conf.link_id); + mlink =mt792x_sta_to_link (msta, vif->bss_conf.link_id); + err =mt7925_set_link_key (hw, cmd, vif, sta, key, + vif->bss_conf.link_id, mlink); }mt792x_mutex_release (dev);
Signature · 1 line
2.43.0
PATCH 11/19 wifi: mt76: mt7925: resolve link after acquiring mt76 mutex
In reply to Sean WangFrom: Sean Wang <[email protected]>
mt792x_sta_to_link() uses rcu_dereference_protected() and therefore expects mt76.mutex to be held. Move the lookup after mt792x_mutex_acquire() to make the locking explicit and correct.
--- drivers/net/wireless/mediatek/mt76/mt7925/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +2 -2
@@ -1071,11 +1071,11 @@ static void mt7925_mac_link_sta_assoc(struct mt76_dev *mdev,struct mt792x_link_sta *mlink;struct mt792x_sta *msta; +mt792x_mutex_acquire (dev); + msta = (struct mt792x_sta *)link_sta->sta->drv_priv; mlink =mt792x_sta_to_link (msta, link_sta->link_id); -mt792x_mutex_acquire (dev); -if (ieee80211_vif_is_mld (vif)) { link_conf =mt792x_vif_to_bss_conf (vif, msta->deflink_id); }else {
Signature · 1 line
2.43.0
PATCH 12/19 wifi: mt76: mt7925: pass mconf and mlink to wtbl_update_hdr_trans()
In reply to Sean WangFrom: Sean Wang <[email protected]>
Drop the mt792x_vif_to_link() lookup in mt7925_mcu_wtbl_update_hdr_trans() and pass the resolved mconf and mlink from the caller instead. The link context is already known at the call site, making the lookup redundant.
This keeps the helper lookup-free and makes link ownership explicit.
No functional change intended.
--- .../net/wireless/mediatek/mt76/mt7925/main.c | 4 +++- .../net/wireless/mediatek/mt76/mt7925/mcu.c | 20 ++++--------------- .../wireless/mediatek/mt76/mt7925/mt7925.h | 5 ++--- 3 files changed, 9 insertions(+), 20 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +3 -1
@@ -1590,8 +1590,10 @@ static void mt7925_sta_set_decap_offload(struct ieee80211_hw *hw, valid =ieee80211_vif_is_mld (vif) ? mvif->valid_links :BIT (0 );for_each_set_bit (i, &valid,IEEE80211_MLD_MAX_NUM_LINKS ) { +struct mt792x_bss_conf *mconf;struct mt792x_link_sta *mlink; + mconf =mt792x_vif_to_link (mvif, i); mlink =mt792x_sta_to_link (msta, i);if (enabled)
@@ -1602,7 +1604,7 @@ static void mt7925_sta_set_decap_offload(struct ieee80211_hw *hw,if (!mlink->wcid.sta)continue ; -mt7925_mcu_wtbl_update_hdr_trans (dev, vif, sta, mlink, i); +mt7925_mcu_wtbl_update_hdr_trans (dev, vif, mconf, mlink); }mt792x_mutex_release (dev);
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +4 -16
@@ -1066,7 +1066,6 @@ EXPORT_SYMBOL_GPL(mt7925_run_firmware);static void mt7925_mcu_sta_hdr_trans_tlv (struct sk_buff *skb,struct ieee80211_vif *vif, -struct ieee80211_link_sta *link_sta,struct mt792x_link_sta *mlink) {struct sta_rec_hdr_trans *hdr_trans;
@@ -1096,29 +1095,18 @@ mt7925_mcu_sta_hdr_trans_tlv(struct sk_buff *skb,int mt7925_mcu_wtbl_update_hdr_trans (struct mt792x_dev *dev,struct ieee80211_vif *vif, -struct ieee80211_sta *sta, -struct mt792x_link_sta *mlink, -int link_id) +struct mt792x_bss_conf *mconf, +struct mt792x_link_sta *mlink) { -struct ieee80211_link_sta *link_sta = sta ? &sta->deflink :NULL ; -struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; -struct mt792x_bss_conf *mconf;struct sk_buff *skb; - link_sta =mt792x_sta_to_link_sta (vif, sta, link_id); - mconf =mt792x_vif_to_link (mvif, link_id); - skb =__mt76_connac_mcu_alloc_sta_req (&dev->mt76, &mconf->mt76, &mlink->wcid,MT7925_STA_UPDATE_MAX_SIZE );if (IS_ERR (skb))return PTR_ERR (skb); -/* starec hdr trans */ -if (!link_sta) - mlink = &mvif->sta.deflink; - -mt7925_mcu_sta_hdr_trans_tlv (skb, vif, link_sta, mlink); +mt7925_mcu_sta_hdr_trans_tlv (skb, vif, mlink);return mt76_mcu_skb_send_msg (&dev->mt76, skb,MCU_WMWA_UNI_CMD (STA_REC_UPDATE ), true); }
@@ -2022,7 +2010,7 @@ mt7925_mcu_sta_cmd(struct mt76_phy *phy,if (!info->link_sta) mlink = &mvif->sta.deflink; -mt7925_mcu_sta_hdr_trans_tlv (skb, info->vif, info->link_sta, mlink); +mt7925_mcu_sta_hdr_trans_tlv (skb, info->vif, mlink); }return mt76_mcu_skb_send_msg (dev, skb, info->cmd, true);
drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h +2 -3
@@ -370,9 +370,8 @@ int mt7925_mcu_add_key(struct mt76_dev *dev, struct ieee80211_vif *vif,int mt7925_mcu_set_rts_thresh (struct mt792x_phy *phy,u32 val);int mt7925_mcu_wtbl_update_hdr_trans (struct mt792x_dev *dev,struct ieee80211_vif *vif, -struct ieee80211_sta *sta, -struct mt792x_link_sta *mlink, -int link_id); +struct mt792x_bss_conf *mconf, +struct mt792x_link_sta *mlink);int mt7925_mcu_wf_rf_pin_ctrl (struct mt792x_phy *phy); int mt7925_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
Signature · 1 line
2.43.0
PATCH 13/19 wifi: mt76: mt7925: make WCID cleanup unconditional in sta_remove_links()
In reply to Sean WangFrom: Sean Wang <[email protected]>
Drop the dead pri_link check in mt7925_mac_sta_remove_links() and perform WCID cleanup unconditionally.
mlink->pri_link is already cleared before the test, making the branch ineffective. This matches the actual teardown behaviour and simplifies the remove path.
No functional change intended.
--- drivers/net/wireless/mediatek/mt76/mt7925/main.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +2 -4
@@ -1221,10 +1221,8 @@ mt7925_mac_sta_remove_links(struct mt792x_dev *dev, struct ieee80211_vif *vif, mlink->sta =NULL ; mlink->pri_link =NULL ; -if (link_sta != mlink->pri_link) { -mt76_wcid_cleanup (mdev, wcid); -mt76_wcid_mask_clear (mdev->wcid_mask, wcid->idx); - } +mt76_wcid_cleanup (mdev, wcid); +mt76_wcid_mask_clear (mdev->wcid_mask, wcid->idx);if (msta->deflink_id == link_id) msta->deflink_id =IEEE80211_LINK_UNSPECIFIED ;
Signature · 1 line
2.43.0
PATCH 14/19 wifi: mt76: mt7925: unwind WCID setup on link STA add failure
In reply to Sean WangFrom: Sean Wang <[email protected]>
Undo the published WCID state when mt7925_mac_link_sta_add() fails after WCID setup.
The add path can fail after dev->mt76.wcid[] is published, so the error path must clear the partial host-side WCID state to avoid leaving stale entries behind.
No functional change intended.
--- .../net/wireless/mediatek/mt76/mt7925/main.c | 53 +++++++++++++------ 1 file changed, 38 insertions(+), 15 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +38 -15
@@ -862,8 +862,10 @@ static int mt7925_mac_link_sta_add(struct mt76_dev *mdev,struct ieee80211_bss_conf *link_conf;struct mt792x_bss_conf *mconf;u8 link_id = link_sta->link_id; +bool wcid_published = false;struct mt792x_sta *msta;struct mt76_wcid *wcid; +bool pm_woken = false;int ret, idx; msta = (struct mt792x_sta *)link_sta->sta->drv_priv;
@@ -888,6 +890,7 @@ static int mt7925_mac_link_sta_add(struct mt76_dev *mdev, wcid = &mlink->wcid;ewma_signal_init (&wcid->rssi);rcu_assign_pointer (dev->mt76.wcid[wcid->idx], wcid); + wcid_published = true;mt76_wcid_init (wcid,0 );ewma_avg_signal_init (&mlink->avg_ack_signal); memset(mlink->airtime_ac, 0,
@@ -895,7 +898,8 @@ static int mt7925_mac_link_sta_add(struct mt76_dev *mdev, ret =mt76_connac_pm_wake (&dev->mphy, &dev->pm);if (ret) -return ret; + goto out_wcid; + pm_woken = true;mt7925_mac_wtbl_update (dev, idx,MT_WTBL_UPDATE_ADM_COUNT_CLEAR );
@@ -909,15 +913,19 @@ static int mt7925_mac_link_sta_add(struct mt76_dev *mdev, mlink_bc =mt792x_sta_to_link (&mvif->sta, mconf->link_id);if (ieee80211_vif_is_mld (vif)) { -mt7925_mcu_add_bss_info_sta (&dev->phy, mconf->mt76.ctx, - link_conf, link_sta, - mlink_bc->wcid.idx, mlink->wcid.idx, - link_sta != mlink->pri_link); + ret =mt7925_mcu_add_bss_info_sta (&dev->phy, mconf->mt76.ctx, + link_conf, link_sta, + mlink_bc->wcid.idx, mlink->wcid.idx, + link_sta != mlink->pri_link); +if (ret) + goto out_pm; }else { -mt7925_mcu_add_bss_info_sta (&dev->phy, mconf->mt76.ctx, - link_conf, link_sta, - mlink_bc->wcid.idx, mlink->wcid.idx, - false); + ret =mt7925_mcu_add_bss_info_sta (&dev->phy, mconf->mt76.ctx, + link_conf, link_sta, + mlink_bc->wcid.idx, mlink->wcid.idx, + false); +if (ret) + goto out_pm; } }
@@ -927,7 +935,7 @@ static int mt7925_mac_link_sta_add(struct mt76_dev *mdev, mlink, true, MT76_STA_INFO_STATE_NONE);if (ret) -return ret; + goto out_pm; }else if (ieee80211_vif_is_mld (vif) && link_sta != mlink->pri_link) {struct mt792x_link_sta *pri_mlink;
@@ -940,31 +948,46 @@ static int mt7925_mac_link_sta_add(struct mt76_dev *mdev, container_of(pri_wcid, struct mt792x_link_sta, wcid) : NULL; -if (WARN_ON_ONCE (!pri_mlink)) -return -EINVAL ; +if (WARN_ON_ONCE (!pri_mlink)) { + ret = -EINVAL ; + goto out_pm; + } ret =mt7925_mcu_sta_update (dev, mlink->pri_link, vif, pri_mlink, true,MT76_STA_INFO_STATE_ASSOC );if (ret) -return ret; + goto out_pm; ret =mt7925_mcu_sta_update (dev, link_sta, vif, mlink, true,MT76_STA_INFO_STATE_ASSOC );if (ret) -return ret; + goto out_pm; }else { ret =mt7925_mcu_sta_update (dev, link_sta, vif, mlink, true,MT76_STA_INFO_STATE_NONE );if (ret) -return ret; + goto out_pm; }mt76_connac_power_save_sched (&dev->mphy, &dev->pm);return 0 ; + +out_pm: +if (pm_woken) +mt76_connac_power_save_sched (&dev->mphy, &dev->pm); +out_wcid: +if (wcid_published) { +u16 idx = wcid->idx; + +rcu_assign_pointer (dev->mt76.wcid[idx],NULL ); +mt76_wcid_cleanup (mdev, wcid); +mt76_wcid_mask_clear (mdev->wcid_mask, wcid->idx); + } +return ret; } static int
Signature · 1 line
2.43.0
PATCH 15/19 wifi: mt76: mt7925: drop WCID reinit after publish
In reply to Sean WangFrom: Sean Wang <[email protected]>
Remove the redundant mt76_wcid_init() call after publishing the WCID in mt7925_mac_link_sta_add().
WCID is already initialized before publication, so reinitializing it afterward is unnecessary and makes the setup ordering less clear.
No functional change intended.
--- drivers/net/wireless/mediatek/mt76/mt7925/main.c | 1 - 1 file changed, 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +0 -1
@@ -891,7 +891,6 @@ static int mt7925_mac_link_sta_add(struct mt76_dev *mdev,ewma_signal_init (&wcid->rssi);rcu_assign_pointer (dev->mt76.wcid[wcid->idx], wcid); wcid_published = true; -mt76_wcid_init (wcid,0 );ewma_avg_signal_init (&mlink->avg_ack_signal);memset (mlink->airtime_ac,0 ,sizeof (msta->deflink.airtime_ac));
Signature · 1 line
2.43.0
PATCH 16/19 wifi: mt76: mt7925: move WCID teardown into link_sta_remove()
In reply to Sean WangFrom: Sean Wang <[email protected]>
Move WCID teardown into mt7925_mac_link_sta_remove() to mirror the dev->mt76.wcid[] publish done during link add.
This clears the published WCID before the rest of teardown, so WCID lookups no longer expose a link that is being removed.
No functional change intended.
--- drivers/net/wireless/mediatek/mt76/mt7925/main.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +8 -8
@@ -1151,12 +1151,14 @@ static void mt7925_mac_link_sta_remove(struct mt76_dev *mdev, struct mt792x_link_sta *mlink) { struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76); +struct mt76_wcid *wcid = &mlink->wcid;struct ieee80211_bss_conf *link_conf;u8 link_id = link_sta->link_id; +u16 idx = wcid->idx;mt7925_roc_abort_sync (dev); -mt76_connac_free_pending_tx_skbs (&dev->pm, &mlink->wcid); +mt76_connac_free_pending_tx_skbs (&dev->pm, wcid);mt76_connac_pm_wake (&dev->mphy, &dev->pm); mt7925_mcu_sta_update(dev, link_sta, vif, mlink, false,
@@ -1183,6 +1185,10 @@ static void mt7925_mac_link_sta_remove(struct mt76_dev *mdev,list_del_init (&mlink->wcid.poll_list);spin_unlock_bh (&mdev->sta_poll_lock); +rcu_assign_pointer (dev->mt76.wcid[idx],NULL ); +mt76_wcid_cleanup (mdev, wcid); +mt76_wcid_mask_clear (mdev->wcid_mask, idx); +mt76_connac_power_save_sched (&dev->mphy, &dev->pm); }
@@ -1191,8 +1197,6 @@ 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; -struct mt76_dev *mdev = &dev->mt76; -struct mt76_wcid *wcid;unsigned int link_id;/* clean up bss before starec */
@@ -1235,16 +1239,12 @@ mt7925_mac_sta_remove_links(struct mt792x_dev *dev, struct ieee80211_vif *vif,if (!mlink)continue ; -mt7925_mac_link_sta_remove (&dev->mt76, vif, link_sta, mlink); - - wcid = &mlink->wcid;rcu_assign_pointer (msta->link[link_id],NULL ); msta->valid_links &= ~BIT (link_id); mlink->sta =NULL ; mlink->pri_link =NULL ; -mt76_wcid_cleanup (mdev, wcid); -mt76_wcid_mask_clear (mdev->wcid_mask, wcid->idx); +mt7925_mac_link_sta_remove (&dev->mt76, vif, link_sta, mlink);if (msta->deflink_id == link_id) msta->deflink_id =IEEE80211_LINK_UNSPECIFIED ;
Signature · 1 line
2.43.0
PATCH 17/19 wifi: mt76: mt7925: switch link STA allocation to RCU lifetime
In reply to Sean WangFrom: Sean Wang <[email protected]>
Allocate mt792x_link_sta with kzalloc() and free it with kfree_rcu() instead of devm-managed memory.
msta->link[] is published via RCU, so the link STA must remain valid until readers have quiesced after teardown. Manage the object lifetime with kfree_rcu() to match its RCU-visible publication.
--- drivers/net/wireless/mediatek/mt76/mt7925/main.c | 10 +++++++--- drivers/net/wireless/mediatek/mt76/mt792x.h | 1 + 2 files changed, 8 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +7 -3
@@ -1005,7 +1005,7 @@ mt7925_mac_sta_add_links(struct mt792x_dev *dev, struct ieee80211_vif *vif, mlink = &msta->deflink; msta->deflink_id = link_id; }else { - mlink =devm_kzalloc (dev->mt76.dev,sizeof (*mlink),GFP_KERNEL ); + mlink =kzalloc (sizeof (*mlink),GFP_KERNEL );if (!mlink) { err = -ENOMEM ;break ;
@@ -1197,6 +1197,7 @@ 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; +struct mt76_dev *mdev = &dev->mt76;unsigned int link_id;/* clean up bss before starec */
@@ -1235,17 +1236,20 @@ mt7925_mac_sta_remove_links(struct mt792x_dev *dev, struct ieee80211_vif *vif,if (!link_sta)continue ; - mlink =mt792x_sta_to_link (msta, link_id); + mlink =rcu_replace_pointer (msta->link[link_id],NULL , +lockdep_is_held (&mdev->mutex));if (!mlink)continue ; -rcu_assign_pointer (msta->link[link_id],NULL ); msta->valid_links &= ~BIT (link_id); mlink->sta =NULL ; mlink->pri_link =NULL ;mt7925_mac_link_sta_remove (&dev->mt76, vif, link_sta, mlink); +if (mlink != &msta->deflink) +kfree_rcu (mlink, rcu_head); +if (msta->deflink_id == link_id) msta->deflink_id =IEEE80211_LINK_UNSPECIFIED ; }
drivers/net/wireless/mediatek/mt76/mt792x.h +1 -0
@@ -97,6 +97,7 @@ DECLARE_EWMA(avg_signal, 10, 8)struct mt792x_link_sta {struct mt76_wcid wcid;/* must be first */ +struct rcu_head rcu_head;u32 airtime_ac[8 ];
Signature · 1 line
2.43.0
PATCH 18/19 wifi: mt76: mt7925: publish msta->link after successful link add
In reply to Sean WangFrom: Sean Wang <[email protected]>
Move the msta->link[link_id] publication until after mt7925_mac_link_sta_add() succeeds.
msta->link[] is RCU-visible, so publishing it before setup completes can expose a link whose add path later fails. Publish it only after success to avoid partially initialized link state becoming visible.
--- .../net/wireless/mediatek/mt76/mt7925/main.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +14 -4
@@ -1000,10 +1000,11 @@ mt7925_mac_sta_add_links(struct mt792x_dev *dev, struct ieee80211_vif *vif,for_each_set_bit (link_id, &new_links,IEEE80211_MLD_MAX_NUM_LINKS ) {struct ieee80211_link_sta *link_sta;struct mt792x_link_sta *mlink; +bool is_deflink = false;if (msta->deflink_id ==IEEE80211_LINK_UNSPECIFIED ) { mlink = &msta->deflink; - msta->deflink_id = link_id; + is_deflink = true; }else { mlink =kzalloc (sizeof (*mlink),GFP_KERNEL );if (!mlink) {
@@ -1012,14 +1013,23 @@ mt7925_mac_sta_add_links(struct mt792x_dev *dev, struct ieee80211_vif *vif, } } - msta->valid_links |=BIT (link_id); -rcu_assign_pointer (msta->link[link_id], mlink); 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); -mt7925_mac_link_sta_add (&dev->mt76, vif, link_sta, mlink); + err =mt7925_mac_link_sta_add (&dev->mt76, vif, link_sta, mlink); +if (err) { +if (!is_deflink) +kfree_rcu (mlink, rcu_head); +break ; + } + +if (is_deflink) + msta->deflink_id = link_id; + +rcu_assign_pointer (msta->link[link_id], mlink); + msta->valid_links |=BIT (link_id); }return err;
Signature · 1 line
2.43.0
PATCH 19/19 wifi: mt76: mt7925: host-only unwind published links on add failure
In reply to Sean WangFrom: Sean Wang <[email protected]>
Release host link resources when mt7925_mac_sta_add_links() fails after partial success.
msta->link[] and dev->mt76.wcid[] may already be published, so unwind the host state to avoid leaving stale links behind.
--- .../net/wireless/mediatek/mt76/mt7925/main.c | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +45 -0
@@ -989,11 +989,51 @@ static int mt7925_mac_link_sta_add(struct mt76_dev *mdev,return ret; } +/* +* Host-only unwind for sta_add_links() failures. +* +* If add_links fail due to MCU/firmware timeouts; calling the full remove +* path would send more firmware commands and may hang again. So only rollback +* host-published state here (msta->link/valid_links, dev->mt76.wcid[idx]) and +* free mlink objects (RCU-safe). Firmware state is left for reset/recovery. +*/ +static void +mt7925_mac_sta_unwind_links_host (struct mt792x_dev *dev, +struct ieee80211_sta *sta, +unsigned long links) +{ +struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv; +unsigned int link_id; + +for_each_set_bit (link_id, &links,IEEE80211_MLD_MAX_NUM_LINKS ) { +struct mt792x_link_sta *mlink; +u16 idx; + + mlink =rcu_replace_pointer (msta->link[link_id],NULL , +lockdep_is_held (&dev->mt76.mutex)); +if (!mlink) +continue ; + + msta->valid_links &= ~BIT (link_id); +if (msta->deflink_id == link_id) + msta->deflink_id =IEEE80211_LINK_UNSPECIFIED ; + + 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 (mlink != &msta->deflink) +kfree_rcu (mlink, rcu_head); + } +} +static int mt7925_mac_sta_add_links (struct mt792x_dev *dev,struct ieee80211_vif *vif,struct ieee80211_sta *sta,unsigned long new_links) {struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv; +unsigned long added_links =0 ;unsigned int link_id;int err =0 ;
@@ -1030,8 +1070,13 @@ mt7925_mac_sta_add_links(struct mt792x_dev *dev, struct ieee80211_vif *vif,rcu_assign_pointer (msta->link[link_id], mlink); msta->valid_links |=BIT (link_id); + + added_links |=BIT (link_id); } +if (err && added_links) +mt7925_mac_sta_unwind_links_host (dev, sta, added_links); +return err; }
Signature · 1 line
2.43.0
kernel test robot
build botRe: [PATCH 02/19] wifi: mt76: mt7925: pass WCID indices to bss_basic_tlv()
In reply to Sean Wangkernel test robot noticed the following build warnings:
Hi Sean,
kernel test robot noticed the following build warnings:
[auto build test WARNING on wireless-next/main]
[also build test WARNING on wireless/main linus/master v7.0-rc2 next-20260306] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Sean-Wang/wifi-mt76-mt7925-pass-mlink-to-sta_amsdu_tlv/20260307-073047 base: https://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git main patch link: https://lore.kernel.org/r/20260306232238.2039675-3-sean.wang%40kernel.org patch subject: [PATCH 02/19] wifi: mt76: mt7925: pass WCID indices to bss_basic_tlv() config: x86_64-rhel-9.4 (https://download.01.org/0day-ci/archive/20260307/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260307/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c: In function 'mt7925_mcu_add_bss_info':
>> drivers/net/wireless/mediatek/mt76/mt7925/mcu.c:2867:13: warning: variable 'sta_wlan_idx' set but not used [-Wunused-but-set-variable]
2867 | u16 sta_wlan_idx;
| ^~~~~~~~~~~~vim +/sta_wlan_idx +2867 drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
2856
2857 int mt7925_mcu_add_bss_info(struct mt792x_phy *phy,
2858 struct ieee80211_chanctx_conf *ctx,
2859 struct ieee80211_bss_conf *link_conf,
2860 struct ieee80211_link_sta *link_sta,
2861 int enable)
2862 {
2863 struct mt792x_vif *mvif = (struct mt792x_vif *)link_conf->vif->drv_priv;
2864 struct mt792x_bss_conf *mconf = mt792x_link_conf_to_mconf(link_conf);
2865 struct mt792x_link_sta *mlink_bc;
2866 struct mt792x_link_sta *mlink;
> 2867 u16 sta_wlan_idx; 2868
2869 sta_wlan_idx = mvif->sta.deflink.wcid.idx;
2870
2871 mlink_bc = mt792x_sta_to_link(&mvif->sta, mconf->link_id);
2872
2873 if (link_sta) {
2874 struct mt792x_sta *msta = (void *)link_sta->sta->drv_priv;
2875
2876 mlink = mt792x_sta_to_link(msta, link_sta->link_id);
2877 if (WARN_ON(!mlink))
2878 return -1;
2879 } else {
2880 mlink = &mconf->vif->sta.deflink;
2881 }
2882
2883 return mt7925_mcu_add_bss_info_sta(phy, ctx, link_conf, link_sta,
2884 mlink_bc->wcid.idx, mlink->wcid.idx, enable);
2885 }
2886
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH 02/19] wifi: mt76: mt7925: pass WCID indices to bss_basic_tlv()
In reply to Sean Wangkernel test robot noticed the following build warnings:
Hi Sean,
kernel test robot noticed the following build warnings:
[auto build test WARNING on wireless-next/main]
[also build test WARNING on wireless/main linus/master v7.0-rc2 next-20260306] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Sean-Wang/wifi-mt76-mt7925-pass-mlink-to-sta_amsdu_tlv/20260307-073047 base: https://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git main patch link: https://lore.kernel.org/r/20260306232238.2039675-3-sean.wang%40kernel.org patch subject: [PATCH 02/19] wifi: mt76: mt7925: pass WCID indices to bss_basic_tlv() config: arc-allyesconfig (https://download.01.org/0day-ci/archive/20260308/[email protected]/config) compiler: arc-linux-gcc (GCC) 15.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260308/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c: In function 'mt7925_mcu_add_bss_info':
>> drivers/net/wireless/mediatek/mt76/mt7925/mcu.c:2867:13: warning: variable 'sta_wlan_idx' set but not used [-Wunused-but-set-variable]
2867 | u16 sta_wlan_idx;
| ^~~~~~~~~~~~vim +/sta_wlan_idx +2867 drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
2856
2857 int mt7925_mcu_add_bss_info(struct mt792x_phy *phy,
2858 struct ieee80211_chanctx_conf *ctx,
2859 struct ieee80211_bss_conf *link_conf,
2860 struct ieee80211_link_sta *link_sta,
2861 int enable)
2862 {
2863 struct mt792x_vif *mvif = (struct mt792x_vif *)link_conf->vif->drv_priv;
2864 struct mt792x_bss_conf *mconf = mt792x_link_conf_to_mconf(link_conf);
2865 struct mt792x_link_sta *mlink_bc;
2866 struct mt792x_link_sta *mlink;
> 2867 u16 sta_wlan_idx; 2868
2869 sta_wlan_idx = mvif->sta.deflink.wcid.idx;
2870
2871 mlink_bc = mt792x_sta_to_link(&mvif->sta, mconf->link_id);
2872
2873 if (link_sta) {
2874 struct mt792x_sta *msta = (void *)link_sta->sta->drv_priv;
2875
2876 mlink = mt792x_sta_to_link(msta, link_sta->link_id);
2877 if (WARN_ON(!mlink))
2878 return -1;
2879 } else {
2880 mlink = &mconf->vif->sta.deflink;
2881 }
2882
2883 return mt7925_mcu_add_bss_info_sta(phy, ctx, link_conf, link_sta,
2884 mlink_bc->wcid.idx, mlink->wcid.idx, enable);
2885 }
2886
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki