[PATCH 13/28] wifi: mt76: mt7925: support multi-link hybrid/EMLSR remain-on-channel
Emery Hsin
emery.hsin at mediatek.com
Mon Nov 9 19:12:29 PST 2026
Program the primary link first, then up to two more links, and select the
firmware channel-privilege request type from the negotiated links: HYBRID
for three links, MLSR otherwise. Add the roc_acquire_tlv cnm_func_mask and
extra_info fields and per-link band grants for the multi-link request.
Signed-off-by: Emery Hsin <emery.hsin at mediatek.com>
---
.../net/wireless/mediatek/mt76/mt7925/main.c | 59 ++++++-
.../net/wireless/mediatek/mt76/mt7925/mcu.c | 158 +++++++++++++-----
.../net/wireless/mediatek/mt76/mt7925/mcu.h | 4 +-
.../wireless/mediatek/mt76/mt7925/mt7925.h | 7 +
drivers/net/wireless/mediatek/mt76/mt792x.h | 2 +
5 files changed, 174 insertions(+), 56 deletions(-)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
index 702e4f01b0ed..50e3716b7385 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
@@ -637,6 +637,10 @@ static int mt7925_set_roc(struct mt792x_phy *phy,
return -EBUSY;
token = ++phy->roc_token_id;
+
+ /* plain ROC, see mt7925_set_mlo_roc() */
+ phy->roc_is_mlo = false;
+ phy->roc_mconf = mconf;
phy->roc_grant = false;
phy->roc_notify = type == MT7925_ROC_REQ_ROC;
@@ -662,16 +666,38 @@ static int mt7925_set_mlo_roc(struct mt792x_phy *phy,
u16 sel_links)
{
int err;
- u8 token;
- if (WARN_ON_ONCE(test_and_set_bit(MT76_STATE_ROC, &phy->mt76->state)))
- return -EBUSY;
+ /* The plain and MLO ROC share MT76_STATE_ROC. Clear it with test_and_clear
+ * so a concurrent mt7925_roc_work() self-no-ops before taking the mt792x
+ * mutex this caller holds, otherwise the cancel_work_sync() below would
+ * deadlock on it.
+ */
+ if (WARN_ON_ONCE(test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))) {
+ struct mt792x_bss_conf *old = phy->roc_mconf;
- token = ++phy->roc_token_id;
+ if (!phy->roc_is_mlo)
+ /* the ROC being taken over told mac80211 it is ready;
+ * notify expiry so its state machine can move on
+ */
+ ieee80211_remain_on_channel_expired(phy->mt76->hw);
+
+ timer_delete_sync(&phy->roc_timer);
+ cancel_work_sync(&phy->roc_work);
+ /* abort on the link the previous ROC was started on; using the
+ * new request's mconf would carry the wrong bss_idx
+ */
+ mt7925_mcu_abort_roc(phy, old, phy->roc_token_id);
+ }
+
+ set_bit(MT76_STATE_ROC, &phy->mt76->state);
+
+ phy->roc_is_mlo = true;
+ phy->roc_mconf = mconf;
phy->roc_grant = false;
phy->roc_notify = false;
- err = mt7925_mcu_set_mlo_roc(phy, mconf, sel_links, 5, token);
+ err = mt7925_mcu_set_mlo_roc(phy, mconf, sel_links, 5,
+ ++phy->roc_token_id);
if (err < 0) {
clear_bit(MT76_STATE_ROC, &phy->mt76->state);
goto out;
@@ -2236,6 +2262,7 @@ static void mt7925_mgd_prepare_tx(struct ieee80211_hw *hw,
{
struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
struct mt792x_dev *dev = mt792x_hw_dev(hw);
+ struct mt792x_bss_conf *mconf;
u16 duration = info->duration ? info->duration :
jiffies_to_msecs(HZ);
@@ -2246,9 +2273,14 @@ static void mt7925_mgd_prepare_tx(struct ieee80211_hw *hw,
duration = MT7925_P2P_GC_JOIN_CH_REQ_INTERVAL_MS;
mt792x_mutex_acquire(dev);
- mt7925_set_roc(mvif->phy, &mvif->bss_conf,
- mvif->bss_conf.mt76.ctx->def.chan, duration,
- MT7925_ROC_REQ_JOIN);
+
+ mconf = mt792x_vif_to_link(mvif, info->link_id);
+
+ /* an inactive MLO link may have no chanctx */
+ if (mconf->mt76.ctx)
+ mt7925_set_roc(mvif->phy, mconf, mconf->mt76.ctx->def.chan,
+ duration, MT7925_ROC_REQ_JOIN);
+
mt792x_mutex_release(dev);
}
@@ -2257,6 +2289,8 @@ static void mt7925_mgd_complete_tx(struct ieee80211_hw *hw,
struct ieee80211_prep_tx_info *info)
{
struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
+ struct mt792x_dev *dev = mt792x_hw_dev(hw);
+ struct mt792x_bss_conf *mconf;
if (info->was_assoc)
return;
@@ -2274,7 +2308,14 @@ static void mt7925_mgd_complete_tx(struct ieee80211_hw *hw,
return;
}
- mt7925_abort_roc(mvif->phy, &mvif->bss_conf);
+ /* abort on the link the ROC was started on; mt792x_vif_to_link needs
+ * the mt76 mutex, drop it before mt7925_abort_roc re-takes it
+ */
+ mt792x_mutex_acquire(dev);
+ mconf = mt792x_vif_to_link(mvif, info->link_id);
+ mt792x_mutex_release(dev);
+
+ mt7925_abort_roc(mvif->phy, mconf);
}
static void mt7925_vif_cfg_changed(struct ieee80211_hw *hw,
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
index 8323c821d4d8..76f638953f50 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
@@ -450,16 +450,30 @@ mt7925_mcu_connection_loss_event(struct mt792x_dev *dev, struct sk_buff *skb)
static void
mt7925_mcu_roc_iter(void *priv, u8 *mac, struct ieee80211_vif *vif)
{
- struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv;
+ struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
struct mt7925_roc_grant_tlv *grant = priv;
+ struct mt792x_bss_conf *mconf;
+ unsigned long valid_links;
+ unsigned int link_id;
- if (ieee80211_vif_is_mld(vif) && vif->type == NL80211_IFTYPE_STATION)
+ /* MLD STA: update band_idx of the granted link */
+ if (ieee80211_vif_is_mld(vif) && vif->type == NL80211_IFTYPE_STATION) {
+ valid_links = READ_ONCE(mvif->valid_links);
+ for_each_set_bit(link_id, &valid_links, IEEE80211_MLD_MAX_NUM_LINKS) {
+ /* RCU iterator, no mutex held */
+ mconf = rcu_dereference(mvif->link_conf[link_id]);
+ if (mconf && mconf->mt76.idx == grant->bss_idx) {
+ mconf->mt76.band_idx = grant->dbdcband;
+ break;
+ }
+ }
return;
+ }
- if (mvif->idx != grant->bss_idx)
+ if (mvif->bss_conf.mt76.idx != grant->bss_idx)
return;
- mvif->band_idx = grant->dbdcband;
+ mvif->bss_conf.mt76.band_idx = grant->dbdcband;
}
static void mt7925_mcu_roc_handle_grant(struct mt792x_dev *dev,
@@ -487,10 +501,12 @@ static void mt7925_mcu_roc_handle_grant(struct mt792x_dev *dev,
if (grant->reqtype == MT7925_ROC_REQ_ROC)
ieee80211_ready_on_channel(hw);
else if (grant->reqtype == MT7925_ROC_REQ_JOIN ||
- grant->reqtype == MT7925_ROC_REQ_GO_START_BSS)
+ grant->reqtype == MT7925_ROC_REQ_GO_START_BSS ||
+ dev->phy.roc_is_mlo)
+ /* MLO grants also carry the primary link band */
ieee80211_iterate_active_interfaces_atomic(hw,
- IEEE80211_IFACE_ITER_RESUME_ALL,
- mt7925_mcu_roc_iter, grant);
+ IEEE80211_IFACE_ITER_RESUME_ALL,
+ mt7925_mcu_roc_iter, grant);
dev->phy.roc_grant = true;
wake_up(&dev->phy.roc_wait);
}
@@ -558,6 +574,14 @@ mt7925_mcu_uni_roc_event(struct mt792x_dev *dev, struct sk_buff *skb)
mt7925_mcu_roc_handle_grant(dev, tlv);
break;
case UNI_EVENT_ROC_GRANT_SUB_LINK:
+ if (le16_to_cpu(tlv->len) <
+ sizeof(struct mt7925_roc_grant_tlv))
+ break;
+
+ /* per-link grant: only update the link band */
+ ieee80211_iterate_active_interfaces_atomic(dev->mt76.hw,
+ IEEE80211_IFACE_ITER_RESUME_ALL,
+ mt7925_mcu_roc_iter, tlv);
break;
}
}
@@ -1577,6 +1601,26 @@ int mt7925_mcu_add_key(struct mt76_dev *dev, struct ieee80211_vif *vif,
return mt76_mcu_skb_send_msg(dev, skb, mcu_cmd, true);
}
+static u8 mt7925_chandef_to_cw(const struct cfg80211_chan_def *chandef)
+{
+ static const u8 width_to_cw[] = {
+ [NL80211_CHAN_WIDTH_20_NOHT] = MT7925_CW_20_40MHZ,
+ [NL80211_CHAN_WIDTH_20] = MT7925_CW_20_40MHZ,
+ [NL80211_CHAN_WIDTH_40] = MT7925_CW_20_40MHZ,
+ [NL80211_CHAN_WIDTH_80] = MT7925_CW_80MHZ,
+ [NL80211_CHAN_WIDTH_160] = MT7925_CW_160MHZ,
+ [NL80211_CHAN_WIDTH_80P80] = MT7925_CW_80P80MHZ,
+ [NL80211_CHAN_WIDTH_5] = MT7925_CW_5MHZ,
+ [NL80211_CHAN_WIDTH_10] = MT7925_CW_10MHZ,
+ [NL80211_CHAN_WIDTH_320] = MT7925_CW_320MHZ,
+ };
+
+ if (chandef->width >= ARRAY_SIZE(width_to_cw))
+ return 0;
+
+ return width_to_cw[chandef->width];
+}
+
int mt7925_mcu_set_mlo_roc(struct mt792x_phy *phy, struct mt792x_bss_conf *mconf,
u16 sel_links, int duration, u8 token_id)
{
@@ -1599,33 +1643,51 @@ int mt7925_mcu_set_mlo_roc(struct mt792x_phy *phy, struct mt792x_bss_conf *mconf
u16 tag;
struct mt792x_bss_conf *mconf;
struct ieee80211_channel *chan;
- } links[2];
+ struct cfg80211_chan_def *chandef;
+ } links[3];
+ u16 rem_links;
+ u8 nlinks, max_links;
struct {
struct {
u8 rsv[4];
} __packed hdr;
- struct roc_acquire_tlv roc[2];
+ struct roc_acquire_tlv roc[3];
} __packed req = {
.roc[0].tag = cpu_to_le16(UNI_ROC_NUM),
.roc[0].len = cpu_to_le16(sizeof(struct roc_acquire_tlv)),
.roc[1].tag = cpu_to_le16(UNI_ROC_NUM),
- .roc[1].len = cpu_to_le16(sizeof(struct roc_acquire_tlv))
+ .roc[1].len = cpu_to_le16(sizeof(struct roc_acquire_tlv)),
+ .roc[2].tag = cpu_to_le16(UNI_ROC_NUM),
+ .roc[2].len = cpu_to_le16(sizeof(struct roc_acquire_tlv))
};
struct wiphy *wiphy = phy->mt76->hw->wiphy;
- if (!mconf || hweight16(vif->valid_links) < 2 ||
- hweight16(sel_links) != 2)
+ /* 2-link MLSR/EMLSR always; 3-link HYBRID only if the chip supports it */
+ max_links = (phy->chip_cap & BIT(MT792x_CHIP_CAP_MLO_HYBRID_EN)) ? 3 : 2;
+ nlinks = hweight16(sel_links);
+ if (!mconf || hweight16(vif->valid_links) < 2)
return -EPERM;
+ if (nlinks < 2)
+ return -EINVAL;
- for (i = 0; i < ARRAY_SIZE(links); i++) {
- links[i].id = i ? __ffs(~BIT(mconf->link_id) & sel_links) :
- mconf->link_id;
+ nlinks = min_t(u8, nlinks, max_links);
+
+ /* primary link first, then the remaining links one by one */
+ rem_links = sel_links & ~BIT(mconf->link_id);
+ for (i = 0; i < nlinks; i++) {
+ if (i == 0) {
+ links[i].id = mconf->link_id;
+ } else {
+ links[i].id = __ffs(rem_links);
+ rem_links &= ~BIT(links[i].id);
+ }
link_conf = mt792x_vif_to_bss_conf(vif, links[i].id);
if (WARN_ON_ONCE(!link_conf))
return -EPERM;
+ links[i].chandef = &link_conf->chanreq.oper;
links[i].chan = link_conf->chanreq.oper.chan;
if (WARN_ON_ONCE(!links[i].chan))
return -EPERM;
@@ -1638,18 +1700,38 @@ int mt7925_mcu_set_mlo_roc(struct mt792x_phy *phy, struct mt792x_bss_conf *mconf
}
if (!(wiphy->iftype_ext_capab[0].mld_capa_and_ops &
- IEEE80211_MLD_CAP_OP_MAX_SIMUL_LINKS))
- type = is_AG_band ? MT7925_ROC_REQ_MLSR_AG :
- MT7925_ROC_REQ_MLSR_AA;
- else
+ IEEE80211_MLD_CAP_OP_MAX_SIMUL_LINKS)) {
+ /* Three links use HYBRID. Otherwise use MLSR, since EMLSR_JOIN
+ * does not place two same-band links on separate DBDC bands.
+ */
+ if (nlinks == 3 &&
+ (phy->chip_cap & BIT(MT792x_CHIP_CAP_MLO_HYBRID_EN)))
+ type = MT7925_ROC_REQ_HYBRID;
+ else
+ type = is_AG_band ? MT7925_ROC_REQ_MLSR_AG :
+ MT7925_ROC_REQ_MLSR_AA;
+ } else {
type = MT7925_ROC_REQ_JOIN;
+ }
+
+ for (i = 0; i < nlinks; i++) {
+ struct cfg80211_chan_def *chandef = links[i].chandef;
+ u8 center_ch2 = 0;
+ u8 bw;
- for (i = 0; i < ARRAY_SIZE(links) && i < hweight16(vif->active_links); i++) {
if (WARN_ON_ONCE(!links[i].mconf || !links[i].chan))
continue;
chan = links[i].chan;
- center_ch = ieee80211_frequency_to_channel(chan->center_freq);
+ /* use the actual operating bandwidth / center, not a fixed
+ * 20 MHz assumption (aligns with gen4m CNM ch privilege req)
+ */
+ bw = mt7925_chandef_to_cw(chandef);
+ center_ch = ieee80211_frequency_to_channel(chandef->center_freq1);
+ if (chandef->center_freq2)
+ center_ch2 =
+ ieee80211_frequency_to_channel(chandef->center_freq2);
+
req.roc[i].len = cpu_to_le16(sizeof(struct roc_acquire_tlv));
req.roc[i].tag = cpu_to_le16(links[i].tag);
req.roc[i].tokenid = token_id;
@@ -1657,12 +1739,12 @@ int mt7925_mcu_set_mlo_roc(struct mt792x_phy *phy, struct mt792x_bss_conf *mconf
req.roc[i].maxinterval = cpu_to_le32(duration);
req.roc[i].bss_idx = links[i].mconf->mt76.idx;
req.roc[i].control_channel = chan->hw_value;
- req.roc[i].bw = CMD_CBW_20MHZ;
- req.roc[i].bw_from_ap = CMD_CBW_20MHZ;
+ req.roc[i].bw = bw;
+ req.roc[i].bw_from_ap = bw;
req.roc[i].center_chan = center_ch;
req.roc[i].center_chan_from_ap = center_ch;
- req.roc[i].center_chan2 = 0;
- req.roc[i].center_chan2_from_ap = 0;
+ req.roc[i].center_chan2 = center_ch2;
+ req.roc[i].center_chan2_from_ap = center_ch2;
/* STR enables DBDC on all bands; otherwise let firmware pick */
req.roc[i].dbdcband = type == MT7925_ROC_REQ_JOIN ?
@@ -1675,10 +1757,14 @@ int mt7925_mcu_set_mlo_roc(struct mt792x_phy *phy, struct mt792x_bss_conf *mconf
req.roc[i].sco = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
req.roc[i].band = ch_band[chan->band];
+
+ /* mark as a multi-link channel request */
+ req.roc[i].extra_info = BIT(MT7925_ROC_EXTRA_INFO_MULTI_LINK);
}
return mt76_mcu_send_msg(&mvif->phy->dev->mt76, MCU_UNI_CMD(ROC),
- &req, sizeof(req), true);
+ &req, sizeof(req.hdr) + nlinks * sizeof(req.roc[0]),
+ true);
}
/* CNM uses bw / center_chan to pick the band and to decide whether a request
@@ -1699,26 +1785,6 @@ mt7925_mcu_roc_chandef(struct mt792x_bss_conf *mconf,
cfg80211_chandef_create(chandef, chan, NL80211_CHAN_NO_HT);
}
-static u8 mt7925_chandef_to_cw(const struct cfg80211_chan_def *chandef)
-{
- static const u8 width_to_cw[] = {
- [NL80211_CHAN_WIDTH_20_NOHT] = MT7925_CW_20_40MHZ,
- [NL80211_CHAN_WIDTH_20] = MT7925_CW_20_40MHZ,
- [NL80211_CHAN_WIDTH_40] = MT7925_CW_20_40MHZ,
- [NL80211_CHAN_WIDTH_80] = MT7925_CW_80MHZ,
- [NL80211_CHAN_WIDTH_160] = MT7925_CW_160MHZ,
- [NL80211_CHAN_WIDTH_80P80] = MT7925_CW_80P80MHZ,
- [NL80211_CHAN_WIDTH_5] = MT7925_CW_5MHZ,
- [NL80211_CHAN_WIDTH_10] = MT7925_CW_10MHZ,
- [NL80211_CHAN_WIDTH_320] = MT7925_CW_320MHZ,
- };
-
- if (chandef->width >= ARRAY_SIZE(width_to_cw))
- return 0;
-
- return width_to_cw[chandef->width];
-}
-
int mt7925_mcu_set_roc(struct mt792x_phy *phy, struct mt792x_bss_conf *mconf,
struct ieee80211_channel *chan, int duration,
enum mt7925_roc_req type, u8 token_id)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.h b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.h
index 4a6a1226a317..e0f8230b05a4 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.h
@@ -628,7 +628,9 @@ struct roc_acquire_tlv {
u8 reqtype;
__le32 maxinterval;
u8 dbdcband;
- u8 rsv[3];
+ u8 cnm_func_mask;
+ u8 extra_info;
+ u8 rsv[1];
} __packed;
enum ENUM_CMD_TEST_CTRL_ACT {
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h b/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h
index 1c20b4ae7497..50745caadeeb 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h
@@ -79,6 +79,8 @@ enum mt7925_roc_req {
MT7925_ROC_REQ_DFS_CAC = 4,
MT7925_ROC_REQ_MLSR_AG = 10,
MT7925_ROC_REQ_MLSR_AA,
+ MT7925_ROC_REQ_HYBRID = 12, /* CH_REQ_TYPE_HYBRID_MLO_MLSR_JOIN, 3-link */
+ MT7925_ROC_REQ_EMLSR = 13, /* CH_REQ_TYPE_MLO_EMLSR_JOIN, needs FW support */
MT7925_ROC_REQ_NUM
};
@@ -86,6 +88,11 @@ enum mt7925_roc_req {
#define MT7925_P2P_CHNL_HOLD_TIME_MS 3000
#define MT7925_P2P_GC_JOIN_CH_REQ_INTERVAL_MS 4000
+/* roc_acquire_tlv extra_info bits */
+enum {
+ MT7925_ROC_EXTRA_INFO_MULTI_LINK, /* BIT(0): MLO channel request */
+ MT7925_ROC_EXTRA_INFO_EMLSR, /* BIT(1): unused by FW, kept for parity */
+};
enum {
UNI_EVENT_ROC_GRANT = 0,
UNI_EVENT_ROC_GRANT_SUB_LINK = 4,
diff --git a/drivers/net/wireless/mediatek/mt76/mt792x.h b/drivers/net/wireless/mediatek/mt76/mt792x.h
index 5a501e72baca..458f6f1fd6cd 100644
--- a/drivers/net/wireless/mediatek/mt76/mt792x.h
+++ b/drivers/net/wireless/mediatek/mt76/mt792x.h
@@ -274,6 +274,8 @@ struct mt792x_phy {
u8 roc_token_id;
bool roc_grant;
bool roc_notify; /* mac80211 expects the expiry of this ROC */
+ bool roc_is_mlo;
+ struct mt792x_bss_conf *roc_mconf;
};
struct mt792x_irq_map {
--
2.45.2
More information about the Linux-mediatek
mailing list