From: JB Tsai <jb.tsai@mediatek.com>
To: <nbd@nbd.name>, <lorenzo@kernel.org>
Cc: <linux-wireless@vger.kernel.org>,
<linux-mediatek@lists.infradead.org>, <Sean.Wang@mediatek.com>,
<James-LY.Huang@mediatek.com>, <jb.tsai@mediatek.com>,
james-ly huang <james-ly.huang@mediatek.com>
Subject: [PATCH 3/9] wifi: mt76: mt7925: give every P2P interface a BMC wcid of its own
Date: Wed, 4 Nov 2026 17:23:38 +0800 [thread overview]
Message-ID: <20261104092344.1932406-3-jb.tsai@mediatek.com> (raw)
In-Reply-To: <20261104092344.1932406-1-jb.tsai@mediatek.com>
From: james-ly huang <james-ly.huang@mediatek.com>
Give every P2P interface (P2P device, GO, GC) a BMC wcid of its own,
kept for its whole interface lifetime:
- group keys are installed on the BMC wcid as well;
- add_bss_info reports the BMC wcid as the bss's basic bmc_tx_wlan_idx.
Signed-off-by: james-ly huang <james-ly.huang@mediatek.com>
---
drivers/net/wireless/mediatek/mt76/mt76.h | 1 +
.../wireless/mediatek/mt76/mt76_connac_mcu.c | 3 +-
.../net/wireless/mediatek/mt76/mt7925/main.c | 27 +++++++-
.../net/wireless/mediatek/mt76/mt7925/mcu.c | 4 +-
.../net/wireless/mediatek/mt76/mt7925/p2p.c | 66 +++++++++++++++++++
.../net/wireless/mediatek/mt76/mt7925/p2p.h | 6 ++
drivers/net/wireless/mediatek/mt76/mt792x.h | 2 +
.../net/wireless/mediatek/mt76/mt792x_core.c | 11 ++++
8 files changed, 117 insertions(+), 3 deletions(-)
diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
index 477d33a0022d..ab606e47e96f 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -835,6 +835,7 @@ struct mt76_vif_link {
u8 basic_rates_idx;
u8 mcast_rates_idx;
u8 beacon_rates_idx;
+ u8 bmc_wcid; /* 0: bmc shares the vif wcid */
bool offchannel;
unsigned long beacon_mon_last;
u16 beacon_mon_interval;
diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
index ad53bb60d5cd..f4cd42bcc80e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
@@ -1240,7 +1240,8 @@ int mt76_connac_mcu_uni_add_dev(struct mt76_phy *phy,
.band_idx = mvif->band_idx,
.wmm_idx = mvif->wmm_idx,
.active = enable,
- .bmc_tx_wlan_idx = cpu_to_le16(wcid->idx),
+ .bmc_tx_wlan_idx = cpu_to_le16(mvif->bmc_wcid ?:
+ wcid->idx),
.sta_idx = cpu_to_le16(wcid->idx),
.conn_state = 1,
.link_idx = mvif->link_idx,
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
index ffbc6b954632..3fa6c48c6549 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
@@ -8,6 +8,7 @@
#include <linux/ctype.h>
#include <net/ipv6.h>
#include "mt7925.h"
+#include "p2p.h"
#include "regd.h"
#include "mcu.h"
#include "mac.h"
@@ -437,10 +438,18 @@ static int mt7925_mac_link_bss_add(struct mt792x_dev *dev,
rcu_assign_pointer(dev->mt76.wcid[idx], &mlink->wcid);
+ if (vif->p2p || vif->type == NL80211_IFTYPE_P2P_DEVICE) {
+ ret = mt7925_p2p_bmc_add(dev, mconf);
+ if (ret)
+ goto out;
+ }
+
ret = mt76_connac_mcu_uni_add_dev(&dev->mphy, link_conf, &mconf->mt76,
&mlink->wcid, true);
- if (ret)
+ if (ret) {
+ mt7925_p2p_bmc_remove(dev, mconf);
goto out;
+ }
if (vif->txq) {
mtxq = (struct mt76_txq *)vif->txq->drv_priv;
@@ -493,8 +502,13 @@ mt7925_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
struct mt792x_dev *dev = mt792x_hw_dev(hw);
struct mt792x_bss_conf *mconf;
+ mt792x_remove_interface(hw, vif);
+
mt792x_mutex_acquire(dev);
+ /* the p2p device owns a BMC wcid for its whole life time */
+ mt7925_p2p_bmc_remove(dev, mt792x_link_conf_to_mconf(&vif->bss_conf));
+
if (dev->nan_vif == vif)
dev->nan_vif = NULL;
@@ -720,6 +734,17 @@ static int mt7925_set_link_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
if (err)
goto out;
+ /* group keys protect the frames that now go out on the dedicated BMC
+ * entry, so they have to be installed on that wcid as well
+ */
+ if (!sta && mconf->bmc_valid) {
+ err = mt7925_mcu_add_key(&dev->mt76, vif, &mconf->bmc.bip,
+ key, MCU_UNI_CMD(STA_REC_UPDATE),
+ &mconf->bmc.wcid, cmd, msta);
+ if (err)
+ goto out;
+ }
+
if (key->cipher == WLAN_CIPHER_SUITE_WEP104 ||
key->cipher == WLAN_CIPHER_SUITE_WEP40)
err = mt7925_mcu_add_key(&dev->mt76, vif, &mvif->wep_sta->deflink.bip,
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
index 50f5f57b740e..3eadea1bb453 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
@@ -3223,7 +3223,9 @@ int mt7925_mcu_add_bss_info(struct mt792x_phy *phy,
}
return mt7925_mcu_add_bss_info_sta(phy, ctx, link_conf, link_sta,
- mlink_bc->wcid.idx, mlink->wcid.idx, enable);
+ mconf->bmc_valid ? mconf->bmc.wcid.idx :
+ mlink_bc->wcid.idx,
+ mlink->wcid.idx, enable);
}
int mt7925_mcu_set_dbdc(struct mt76_phy *phy, bool enable)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/p2p.c b/drivers/net/wireless/mediatek/mt76/mt7925/p2p.c
index 5dad902a0446..4e41ba9beca1 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/p2p.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/p2p.c
@@ -361,3 +361,69 @@ mt7925_p2p_rx_drop_chan_mismatch(struct mt792x_dev *dev, struct sk_buff *skb)
return false;
}
+/* ------------------------------------------------------------------ */
+/* BMC wcid bookkeeping */
+/* ------------------------------------------------------------------ */
+
+/* The BMC entry itself is set up by the firmware from the
+ * bmc_tx_wlan_idx of the BSS_INFO_BASIC tlv, so the driver
+ * only has to reserve the index and keep a wcid around for it.
+ */
+int mt7925_p2p_bmc_add(struct mt792x_dev *dev,
+ struct mt792x_bss_conf *mconf)
+{
+ struct mt792x_link_sta *mbmc = &mconf->bmc;
+ int idx;
+
+ if (mconf->bmc_valid)
+ return 0;
+
+ idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT792x_WTBL_STA - 1);
+ if (idx < 0)
+ return -ENOSPC;
+
+ memset(mbmc, 0, sizeof(*mbmc));
+ INIT_LIST_HEAD(&mbmc->wcid.poll_list);
+ mbmc->wcid.idx = idx;
+ mbmc->wcid.phy_idx = 0;
+ mbmc->wcid.hw_key_idx = -1;
+ mbmc->wcid.hw_key_idx2 = -1;
+ mbmc->wcid.tx_info |= MT_WCID_TX_INFO_SET;
+ mbmc->wcid.link_id = mconf->link_id;
+ mt76_wcid_init(&mbmc->wcid, 0);
+
+ rcu_assign_pointer(dev->mt76.wcid[idx], &mbmc->wcid);
+ mt7925_mac_wtbl_update(dev, idx, MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
+ mconf->mt76.bmc_wcid = idx;
+ mconf->bmc_valid = true;
+
+ dev_info(dev->mt76.dev,
+ "[James] p2p bss%d BMC wcid=%d (bss default wcid=%d)\n",
+ mconf->mt76.idx, idx, mconf->vif->sta.deflink.wcid.idx);
+
+ return 0;
+}
+
+void mt7925_p2p_bmc_remove(struct mt792x_dev *dev,
+ struct mt792x_bss_conf *mconf)
+{
+ struct mt76_wcid *wcid = &mconf->bmc.wcid;
+
+ if (!mconf->bmc_valid)
+ return;
+
+ mconf->bmc_valid = false;
+ mconf->mt76.bmc_wcid = 0;
+
+ mt76_connac_free_pending_tx_skbs(&dev->pm, wcid);
+ rcu_assign_pointer(dev->mt76.wcid[wcid->idx], NULL);
+
+ spin_lock_bh(&dev->mt76.sta_poll_lock);
+ if (!list_empty(&wcid->poll_list))
+ list_del_init(&wcid->poll_list);
+ spin_unlock_bh(&dev->mt76.sta_poll_lock);
+
+ mt76_wcid_cleanup(&dev->mt76, wcid);
+ mt76_wcid_mask_clear(dev->mt76.wcid_mask, wcid->idx);
+}
+
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/p2p.h b/drivers/net/wireless/mediatek/mt76/mt7925/p2p.h
index b005eebbfdca..25b6c57749a2 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/p2p.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/p2p.h
@@ -38,6 +38,7 @@ static inline bool mt7925_is_p2p_go_probe_resp(struct sk_buff *skb)
return ieee80211_is_probe_resp(mgmt->frame_control);
}
+
/* TX/RX path overrides, BMC wcid bookkeeping and the P2P-only MCU event
* handlers.
*/
@@ -46,4 +47,9 @@ bool mt7925_p2p_rx_drop_chan_mismatch(struct mt792x_dev *dev,
void mt7925_p2p_txwi_override(struct mt76_dev *dev, __le32 *txwi,
struct sk_buff *skb);
+int mt7925_p2p_bmc_add(struct mt792x_dev *dev,
+ struct mt792x_bss_conf *mconf);
+void mt7925_p2p_bmc_remove(struct mt792x_dev *dev,
+ struct mt792x_bss_conf *mconf);
+
#endif /* __MT7925_P2P_H */
diff --git a/drivers/net/wireless/mediatek/mt76/mt792x.h b/drivers/net/wireless/mediatek/mt76/mt792x.h
index a7d71e007da0..66c8722220cc 100644
--- a/drivers/net/wireless/mediatek/mt76/mt792x.h
+++ b/drivers/net/wireless/mediatek/mt76/mt792x.h
@@ -163,6 +163,8 @@ struct mt792x_bss_conf {
struct ewma_rssi rssi;
struct ieee80211_tx_queue_params queue_params[IEEE80211_NUM_ACS];
unsigned int link_id;
+ struct mt792x_link_sta bmc;
+ bool bmc_valid;
};
struct mt792x_nan_conf {
diff --git a/drivers/net/wireless/mediatek/mt76/mt792x_core.c b/drivers/net/wireless/mediatek/mt76/mt792x_core.c
index dbea3c2e626f..fa29af8fff49 100644
--- a/drivers/net/wireless/mediatek/mt76/mt792x_core.c
+++ b/drivers/net/wireless/mediatek/mt76/mt792x_core.c
@@ -4,6 +4,7 @@
#include <linux/module.h>
#include <linux/firmware.h>
#include <linux/slab.h>
+#include <linux/etherdevice.h>
#include "mt792x.h"
#include "dma.h"
@@ -188,10 +189,20 @@ void mt792x_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
}
if (vif && !control->sta) {
+ struct mt792x_bss_conf *mconf;
struct mt792x_vif *mvif;
+ const u8 *da;
mvif = (struct mt792x_vif *)vif->drv_priv;
+ mconf = &mvif->bss_conf;
wcid = &mvif->sta.deflink.wcid;
+
+ da = (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) ?
+ skb->data :
+ ((struct ieee80211_hdr *)skb->data)->addr1;
+
+ if (mconf->bmc_valid && is_multicast_ether_addr(da))
+ wcid = &mconf->bmc.wcid;
}
if (vif && control->sta && ieee80211_vif_is_mld(vif) &&
--
2.45.2
next prev parent reply other threads:[~2026-11-04 9:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 9:23 [PATCH 1/9] wifi: mt76: mt7925: drop P2P mgmt frames received on foreign channel JB Tsai
2026-11-04 9:23 ` [PATCH 2/9] wifi: mt76: mt7925: bound P2P off-channel mgmt TX lifetime JB Tsai
2026-11-04 9:23 ` JB Tsai [this message]
2026-11-04 9:23 ` [PATCH 4/9] wifi: mt76: mt7925: harden the ROC channel-grant handshake JB Tsai
2026-11-04 9:23 ` [PATCH 5/9] wifi: mt76: mt7925: describe the real chandef in ROC requests JB Tsai
2026-11-04 9:23 ` [PATCH 6/9] wifi: mt76: mt7925: request the channel before programming a GO BSS JB Tsai
2026-11-04 9:23 ` [PATCH 7/9] wifi: mt76: mt7925: inject the deauth for an aging-timeout SAP event JB Tsai
2026-11-06 0:34 ` kernel test robot
2026-11-04 9:23 ` [PATCH 8/9] wifi: mt76: mt7925: track BSS absence and drop stale GO probe responses JB Tsai
2026-11-04 9:23 ` [PATCH 9/9] wifi: mt76: mt7925: send the common scan IEs and size the request JB Tsai
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=20261104092344.1932406-3-jb.tsai@mediatek.com \
--to=jb.tsai@mediatek.com \
--cc=James-LY.Huang@mediatek.com \
--cc=Sean.Wang@mediatek.com \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-wireless@vger.kernel.org \
--cc=lorenzo@kernel.org \
--cc=nbd@nbd.name \
/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