Received: from nbd.name (nbd.name [46.4.11.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBF1648C8B9 for ; Wed, 7 Oct 2026 11:24:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.4.11.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791372285; cv=none; b=aGRkzWmqv5PIDTJB4IhdziQizk+kyftodSsL1ue+lgvGP/6yuImXIiooEUKKI7j+XDOCu+QTpfoeaYecro7kCD2m3eynGCBDMNZtco58O9e8wLHQuTRyu+tMyGfjwg8mVaS+VAjC3EGR+9RSnWH9d7LCfI1ALtJrASR8gGgZFDo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791372285; c=relaxed/simple; bh=B8M69wVJnOP3DgXRKiHGA1aNC80d8UrHKwZXPNs4sm0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QvHUbHU0aAy2wGqlUZXhCJC7S+SO0QuCV8eja833RmItlk2C16WkpEpXh08bZG18pOXbKhWy3aZw3c3YckfMljIbnLg4Li0LqYT1qSe9PuW0d5NmMciN5Pxw/mxa0abK2oRsvYB36dncmnk3Et0R0EwsNtCgnWtt0svVp3B5m4E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nbd.name; spf=pass smtp.mailfrom=nbd.name; dkim=pass (1024-bit key) header.d=nbd.name header.i=@nbd.name header.b=keIh7+LV; arc=none smtp.client-ip=46.4.11.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nbd.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nbd.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nbd.name header.i=@nbd.name header.b="keIh7+LV" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nbd.name; s=20160729; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=JR9ztBLVKOE2VRxf6Kdz7Kim+VHLSIWkkUT5lp5ES2k=; b=keIh7+LVtcPv6Lxfmh3yRfbtT1 u7G2rf2yyR7vyNJBhagL77QCqP3s4HGIHwdNWayQgYjVY322mmvn7Ai+ISN+MbkTbHu+GcnnGI9ei lny/a+eCSc+ul9yPC3mn7ros7jKIXZj1fskhpYi9dIxYvNH+GvH47OloywOi2EU6iZys=; Received: from p200300cadf12010000000000000005bb.dip0.t-ipconnect.de ([2003:ca:df12:100::5bb] helo=localhost.localdomain) by ds12 with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1xEPl1-00HY5A-2v for linux-wireless@vger.kernel.org; Wed, 07 Oct 2026 13:24:23 +0200 From: Felix Fietkau To: linux-wireless@vger.kernel.org Subject: [PATCH mt76-next 7/9] wifi: mt76: scan all radios of a request at the same time Date: Wed, 7 Oct 2026 13:24:17 +0200 Message-ID: <20261007112419.1277594-7-nbd@nbd.name> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261007112419.1277594-1-nbd@nbd.name> References: <20261007112419.1277594-1-nbd@nbd.name> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: John Crispin A device with several radios on one wiphy has one scan state for the whole device, and mt76_hw_scan() picks the radio from the band of the first channel. A scan therefore covers one radio, and mac80211 visits the bands one after another. Run the scan on every radio that has a channel in the request, and let each radio visit only its own channels. Report the scan as complete once all radios are done, and as aborted if any of them aborted. Build the probe request from the IEs of the band of the channel and the common IEs, because a request can now hold the IEs of several bands. A driver can now set SINGLE_SCAN_ON_ALL_BANDS to scan all of its radios in parallel with one request. Signed-off-by: John Crispin Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/channel.c | 12 +- drivers/net/wireless/mediatek/mt76/mac80211.c | 4 +- drivers/net/wireless/mediatek/mt76/mt76.h | 27 ++- drivers/net/wireless/mediatek/mt76/scan.c | 215 ++++++++++++------ 4 files changed, 173 insertions(+), 85 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/channel.c b/drivers/net/wireless/mediatek/mt76/channel.c index 75f0db3bc4f0..192276cf19fd 100644 --- a/drivers/net/wireless/mediatek/mt76/channel.c +++ b/drivers/net/wireless/mediatek/mt76/channel.c @@ -41,7 +41,7 @@ int mt76_add_chanctx(struct ieee80211_hw *hw, if (WARN_ON_ONCE(!phy)) return ret; - if (dev->scan.phy == phy) + if (mt76_phy_scanning(phy)) mt76_abort_scan(dev); mutex_lock(&dev->mutex); @@ -66,7 +66,7 @@ void mt76_remove_chanctx(struct ieee80211_hw *hw, if (WARN_ON_ONCE(!phy)) return; - if (dev->scan.phy == phy) + if (mt76_phy_scanning(phy)) mt76_abort_scan(dev); mutex_lock(&dev->mutex); @@ -114,7 +114,7 @@ int mt76_assign_vif_chanctx(struct ieee80211_hw *hw, bool mlink_alloc = false; int ret = 0; - if (dev->scan.vif == vif && dev->scan.phy == phy) + if (dev->scan.vif == vif && mt76_phy_scanning(phy)) mt76_abort_scan(dev); mutex_lock(&dev->mutex); @@ -161,7 +161,7 @@ void mt76_unassign_vif_chanctx(struct ieee80211_hw *hw, struct mt76_phy *phy = ctx->phy; struct mt76_dev *dev = phy->dev; - if (dev->scan.vif == vif && dev->scan.phy == phy) + if (dev->scan.vif == vif && mt76_phy_scanning(phy)) mt76_abort_scan(dev); mutex_lock(&dev->mutex); @@ -209,7 +209,7 @@ int mt76_switch_vif_chanctx(struct ieee80211_hw *hw, continue; if (phy->chanctx != new_ctx) { - if (dev->scan.phy == phy) + if (mt76_phy_scanning(phy)) mt76_abort_scan(dev); cancel_delayed_work_sync(&phy->mac_work); @@ -376,7 +376,7 @@ int mt76_remain_on_channel(struct ieee80211_hw *hw, struct ieee80211_vif *vif, mutex_lock(&dev->mutex); - if (phy->roc_vif || dev->scan.phy == phy || + if (phy->roc_vif || mt76_phy_scanning(phy) || test_bit(MT76_MCU_RESET, &dev->phy.state) || test_bit(MT76_RESTART, &dev->phy.state)) { ret = -EBUSY; diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c index 2584c0e2a2c9..c9762082f473 100644 --- a/drivers/net/wireless/mediatek/mt76/mac80211.c +++ b/drivers/net/wireless/mediatek/mt76/mac80211.c @@ -432,6 +432,7 @@ mt76_phy_init(struct mt76_phy *phy, struct ieee80211_hw *hw) INIT_LIST_HEAD(&phy->tx_list); spin_lock_init(&phy->tx_lock); INIT_DELAYED_WORK(&phy->roc_work, mt76_roc_complete_work); + INIT_DELAYED_WORK(&phy->scan_work, mt76_scan_work); if ((void *)phy != hw->priv) return 0; @@ -729,7 +730,6 @@ mt76_alloc_device(struct device *pdev, unsigned int size, INIT_LIST_HEAD(&dev->txwi_cache); INIT_LIST_HEAD(&dev->rxwi_cache); dev->token_size = dev->drv->token_size; - INIT_DELAYED_WORK(&dev->scan_work, mt76_scan_work); spin_lock_init(&dev->scan_lock); for (i = 0; i < ARRAY_SIZE(dev->q_rx); i++) @@ -2338,7 +2338,7 @@ void mt76_rx_beacon(struct mt76_phy *phy, struct sk_buff *skb) .bssid = hdr->addr3, }; - mt76_scan_rx_beacon(phy->dev, phy->chandef.chan); + mt76_scan_rx_beacon(phy, phy->chandef.chan); if (!phy->num_sta) return; diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h index 09b9507250f9..9e851dea71d9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76.h +++ b/drivers/net/wireless/mediatek/mt76/mt76.h @@ -877,6 +877,15 @@ struct mt76_phy { struct ieee80211_vif *roc_vif; struct mt76_vif_link *roc_link; + struct delayed_work scan_work; + struct { + struct ieee80211_channel *chan; + struct mt76_vif_link *mlink; + int chan_idx; + bool beacon_wait; + bool beacon_received; + } scan; + struct mt76_chanctx *chanctx; struct mt76_channel_state *chan_state; @@ -1013,17 +1022,12 @@ struct mt76_dev { u32 rxfilter; - struct delayed_work scan_work; spinlock_t scan_lock; struct { - struct cfg80211_scan_request *req; - struct ieee80211_channel *chan; + struct ieee80211_scan_request *req; struct ieee80211_vif *vif; - struct mt76_vif_link *mlink; - struct mt76_phy *phy; - int chan_idx; - bool beacon_wait; - bool beacon_received; + unsigned long phy_mask; + bool aborted; } scan; #ifdef CONFIG_NL80211_TESTMODE @@ -1396,6 +1400,11 @@ mt76_phy_hw(struct mt76_dev *dev, u8 phy_idx) return mt76_dev_phy(dev, phy_idx)->hw; } +static inline bool mt76_phy_scanning(struct mt76_phy *phy) +{ + return test_bit(phy->band_idx, &phy->dev->scan.phy_mask); +} + static inline u8 * mt76_get_txwi_ptr(struct mt76_dev *dev, struct mt76_txwi_cache *t) { @@ -1623,7 +1632,7 @@ int mt76_get_rate(struct mt76_dev *dev, int mt76_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_scan_request *hw_req); void mt76_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif); -void mt76_scan_rx_beacon(struct mt76_dev *dev, struct ieee80211_channel *chan); +void mt76_scan_rx_beacon(struct mt76_phy *phy, struct ieee80211_channel *chan); void mt76_rx_beacon(struct mt76_phy *phy, struct sk_buff *skb); void mt76_beacon_mon_check(struct mt76_phy *phy); void mt76_sw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, diff --git a/drivers/net/wireless/mediatek/mt76/scan.c b/drivers/net/wireless/mediatek/mt76/scan.c index 4a5cdb4efc61..ada7a8984971 100644 --- a/drivers/net/wireless/mediatek/mt76/scan.c +++ b/drivers/net/wireless/mediatek/mt76/scan.c @@ -4,16 +4,26 @@ */ #include "mt76.h" -static void mt76_scan_complete(struct mt76_dev *dev, bool abort) +static struct mt76_phy * +mt76_scan_chan_phy(struct ieee80211_hw *hw, struct ieee80211_channel *chan) { - struct mt76_phy *phy = dev->scan.phy; - struct cfg80211_scan_info info = { - .aborted = abort, - }; + struct mt76_phy *phy = hw->priv; + + if (hw->wiphy->n_radio > 1) + return phy->dev->band_phys[chan->band]; + + return phy; +} + +static void mt76_scan_phy_complete(struct mt76_phy *phy, bool abort) +{ + struct mt76_dev *dev = phy->dev; + struct cfg80211_scan_info info = {}; + struct ieee80211_hw *hw = phy->hw; lockdep_assert_held(&dev->mutex); - if (!phy) + if (!mt76_phy_scanning(phy)) return; clear_bit(MT76_SCANNING, &phy->state); @@ -37,39 +47,64 @@ static void mt76_scan_complete(struct mt76_dev *dev, bool abort) */ phy->offchannel = false; } - mt76_put_vif_phy_link(phy, dev->scan.vif, dev->scan.mlink); + mt76_put_vif_phy_link(phy, dev->scan.vif, phy->scan.mlink); + memset(&phy->scan, 0, sizeof(phy->scan)); + + clear_bit(phy->band_idx, &dev->scan.phy_mask); + if (abort) + dev->scan.aborted = true; + + if (dev->scan.phy_mask) + return; + + info.aborted = dev->scan.aborted; memset(&dev->scan, 0, sizeof(dev->scan)); - ieee80211_scan_completed(phy->hw, &info); + ieee80211_scan_completed(hw, &info); } void mt76_abort_scan(struct mt76_dev *dev) { - spin_lock_bh(&dev->scan_lock); - dev->scan.beacon_wait = false; - spin_unlock_bh(&dev->scan_lock); + struct mt76_phy *phy; + int i; - cancel_delayed_work_sync(&dev->scan_work); + for (i = 0; i < ARRAY_SIZE(dev->phys); i++) { + phy = dev->phys[i]; + if (!phy) + continue; + + spin_lock_bh(&dev->scan_lock); + phy->scan.beacon_wait = false; + spin_unlock_bh(&dev->scan_lock); + + cancel_delayed_work_sync(&phy->scan_work); + } mutex_lock(&dev->mutex); - mt76_scan_complete(dev, true); + for (i = 0; i < ARRAY_SIZE(dev->phys); i++) { + phy = dev->phys[i]; + if (phy) + mt76_scan_phy_complete(phy, true); + } mutex_unlock(&dev->mutex); } EXPORT_SYMBOL_GPL(mt76_abort_scan); static void -mt76_scan_send_probe(struct mt76_dev *dev, struct cfg80211_ssid *ssid) +mt76_scan_send_probe(struct mt76_phy *phy, struct cfg80211_ssid *ssid) { - struct cfg80211_scan_request *req = dev->scan.req; + struct mt76_dev *dev = phy->dev; + struct cfg80211_scan_request *req = &dev->scan.req->req; + struct ieee80211_scan_ies *ies = &dev->scan.req->ies; struct ieee80211_vif *vif = dev->scan.vif; - struct mt76_vif_link *mvif = dev->scan.mlink; - enum nl80211_band band = dev->scan.chan->band; - struct mt76_phy *phy = dev->scan.phy; + struct mt76_vif_link *mvif = phy->scan.mlink; + enum nl80211_band band = phy->scan.chan->band; struct ieee80211_tx_info *info; struct sk_buff *skb; u8 link_id; skb = ieee80211_probereq_get(phy->hw, vif->addr, ssid->ssid, - ssid->ssid_len, req->ie_len); + ssid->ssid_len, + ies->len[band] + ies->common_ie_len); if (!skb) return; @@ -80,8 +115,10 @@ mt76_scan_send_probe(struct mt76_dev *dev, struct cfg80211_ssid *ssid) ether_addr_copy(hdr->addr3, req->bssid); } - if (req->ie_len) - skb_put_data(skb, req->ie, req->ie_len); + if (ies->len[band]) + skb_put_data(skb, ies->ies[band], ies->len[band]); + if (ies->common_ie_len) + skb_put_data(skb, ies->common_ies, ies->common_ie_len); skb->priority = 7; skb_set_queue_mapping(skb, IEEE80211_AC_VO); @@ -106,65 +143,77 @@ mt76_scan_send_probe(struct mt76_dev *dev, struct cfg80211_ssid *ssid) rcu_read_unlock(); } -void mt76_scan_rx_beacon(struct mt76_dev *dev, struct ieee80211_channel *chan) +void mt76_scan_rx_beacon(struct mt76_phy *phy, struct ieee80211_channel *chan) { - struct mt76_phy *phy; + struct mt76_dev *dev = phy->dev; spin_lock(&dev->scan_lock); - if (!dev->scan.beacon_wait || dev->scan.beacon_received || - dev->scan.chan != chan) + if (!phy->scan.beacon_wait || phy->scan.beacon_received || + phy->scan.chan != chan) goto out; - phy = dev->scan.phy; - if (!phy) - goto out; - - dev->scan.beacon_received = true; - ieee80211_queue_delayed_work(phy->hw, &dev->scan_work, 0); + phy->scan.beacon_received = true; + ieee80211_queue_delayed_work(phy->hw, &phy->scan_work, 0); out: spin_unlock(&dev->scan_lock); } -void mt76_scan_work(struct work_struct *work) +static int mt76_scan_next_chan_idx(struct mt76_phy *phy) { - struct mt76_dev *dev = container_of(work, struct mt76_dev, - scan_work.work); - struct cfg80211_scan_request *req = dev->scan.req; - struct cfg80211_chan_def chandef = {}; - struct mt76_phy *phy = dev->scan.phy; - int duration = HZ / 9; /* ~110 ms */ - bool beacon_rx, offchannel = true; + struct cfg80211_scan_request *req = &phy->dev->scan.req->req; int i; - if (!phy || !req) + for (i = phy->scan.chan_idx; i < req->n_channels; i++) + if (mt76_scan_chan_phy(phy->hw, req->channels[i]) == phy) + return i; + + return -1; +} + +void mt76_scan_work(struct work_struct *work) +{ + struct mt76_phy *phy = container_of(work, struct mt76_phy, + scan_work.work); + struct mt76_dev *dev = phy->dev; + struct cfg80211_scan_request *req; + struct cfg80211_chan_def chandef = {}; + int duration = HZ / 9; /* ~110 ms */ + bool beacon_rx, offchannel = true; + int i, idx; + + if (!dev->scan.req || !mt76_phy_scanning(phy)) return; + req = &dev->scan.req->req; + spin_lock_bh(&dev->scan_lock); - beacon_rx = dev->scan.beacon_wait && dev->scan.beacon_received; - dev->scan.beacon_wait = false; + beacon_rx = phy->scan.beacon_wait && phy->scan.beacon_received; + phy->scan.beacon_wait = false; spin_unlock_bh(&dev->scan_lock); if (beacon_rx) goto probe; - if (dev->scan.chan_idx >= req->n_channels) { + idx = mt76_scan_next_chan_idx(phy); + if (idx < 0) { mutex_lock(&dev->mutex); - mt76_scan_complete(dev, false); + mt76_scan_phy_complete(phy, false); mutex_unlock(&dev->mutex); return; } - if (dev->scan.chan && phy->num_sta && phy->offchannel) { - dev->scan.chan = NULL; + if (phy->scan.chan && phy->num_sta && phy->offchannel) { + phy->scan.chan = NULL; mt76_set_channel(phy, &phy->main_chandef, false); mt76_offchannel_notify(phy, false); goto out; } - dev->scan.chan = req->channels[dev->scan.chan_idx++]; - offchannel = mt76_offchannel_chandef(phy, dev->scan.chan, &chandef); + phy->scan.chan = req->channels[idx]; + phy->scan.chan_idx = idx + 1; + offchannel = mt76_offchannel_chandef(phy, phy->scan.chan, &chandef); if (offchannel) mt76_offchannel_notify(phy, true); @@ -175,8 +224,8 @@ void mt76_scan_work(struct work_struct *work) if (chandef.chan->flags & (IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_RADAR)) { spin_lock_bh(&dev->scan_lock); - dev->scan.beacon_received = false; - dev->scan.beacon_wait = true; + phy->scan.beacon_received = false; + phy->scan.beacon_wait = true; spin_unlock_bh(&dev->scan_lock); goto out; } @@ -186,16 +235,16 @@ void mt76_scan_work(struct work_struct *work) duration = HZ / 16; /* ~60 ms */ local_bh_disable(); for (i = 0; i < req->n_ssids; i++) - mt76_scan_send_probe(dev, &req->ssids[i]); + mt76_scan_send_probe(phy, &req->ssids[i]); local_bh_enable(); out: - if (dev->scan.chan && phy->offchannel) + if (phy->scan.chan && phy->offchannel) duration = max_t(int, duration, msecs_to_jiffies(req->duration + (req->duration >> 5))); - ieee80211_queue_delayed_work(dev->phy.hw, &dev->scan_work, duration); + ieee80211_queue_delayed_work(phy->hw, &phy->scan_work, duration); } int mt76_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, @@ -203,37 +252,67 @@ int mt76_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, { struct mt76_phy *phy = hw->priv; struct mt76_dev *dev = phy->dev; + unsigned long phy_mask = 0; struct mt76_vif_link *mlink; - int ret = 0; + int i, ret = 0; - if (hw->wiphy->n_radio > 1) { - phy = dev->band_phys[req->req.channels[0]->band]; + for (i = 0; i < req->req.n_channels; i++) { + phy = mt76_scan_chan_phy(hw, req->req.channels[i]); if (!phy) return -EINVAL; + + phy_mask |= BIT(phy->band_idx); } mutex_lock(&dev->mutex); - if (dev->scan.req || phy->roc_vif || - test_bit(MT76_MCU_RESET, &dev->phy.state) || + if (dev->scan.req || test_bit(MT76_MCU_RESET, &dev->phy.state) || test_bit(MT76_RESTART, &dev->phy.state)) { ret = -EBUSY; goto out; } - mlink = mt76_get_vif_phy_link(phy, vif); - if (IS_ERR(mlink)) { - ret = PTR_ERR(mlink); - goto out; + for_each_set_bit(i, &phy_mask, ARRAY_SIZE(dev->phys)) { + if (dev->phys[i]->roc_vif) { + ret = -EBUSY; + goto out; + } } - memset(&dev->scan, 0, sizeof(dev->scan)); - dev->scan.req = &req->req; + for_each_set_bit(i, &phy_mask, ARRAY_SIZE(dev->phys)) { + phy = dev->phys[i]; + mlink = mt76_get_vif_phy_link(phy, vif); + if (IS_ERR(mlink)) { + ret = PTR_ERR(mlink); + goto put_links; + } + + memset(&phy->scan, 0, sizeof(phy->scan)); + phy->scan.mlink = mlink; + } + + dev->scan.req = req; dev->scan.vif = vif; - dev->scan.phy = phy; - dev->scan.mlink = mlink; - set_bit(MT76_SCANNING, &phy->state); - ieee80211_queue_delayed_work(dev->phy.hw, &dev->scan_work, 0); + dev->scan.phy_mask = phy_mask; + dev->scan.aborted = false; + + for_each_set_bit(i, &phy_mask, ARRAY_SIZE(dev->phys)) { + phy = dev->phys[i]; + set_bit(MT76_SCANNING, &phy->state); + ieee80211_queue_delayed_work(phy->hw, &phy->scan_work, 0); + } + + goto out; + +put_links: + for_each_set_bit(i, &phy_mask, ARRAY_SIZE(dev->phys)) { + phy = dev->phys[i]; + if (!phy->scan.mlink) + break; + + mt76_put_vif_phy_link(phy, vif, phy->scan.mlink); + phy->scan.mlink = NULL; + } out: mutex_unlock(&dev->mutex); -- 2.47.3