wifi: mt76: fix multi-radio on-channel scanning
Subsystems (2)
Felix Fietkau
maintainerPATCH 1/11 wifi: mt76: fix multi-radio on-channel scanning
From: Chad Monroe <[email protected]>
avoid unnecessary channel switch when performing an on-channel scan using a multi-radio device.
--- drivers/net/wireless/mediatek/mt76/scan.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/net/wireless/mediatek/mt76/scan.c +12 -5
@@ -16,7 +16,7 @@ static void mt76_scan_complete(struct mt76_dev *dev, bool abort)clear_bit (MT76_SCANNING , &phy->state); -if (dev->scan.chan && phy->main_chandef.chan && +if (dev->scan.chan && phy->main_chandef.chan && phy->offchannel && !test_bit (MT76_MCU_RESET , &dev->phy.state))mt76_set_channel (phy, &phy->main_chandef, false);mt76_put_vif_phy_link (phy, dev->scan.vif, dev->scan.mlink);
@@ -87,6 +87,7 @@ void mt76_scan_work(struct work_struct *work)struct cfg80211_chan_def chandef = {};struct mt76_phy *phy = dev->scan.phy;int duration =HZ /9 ;/* ~110 ms */ +bool offchannel = true;int i;if (dev->scan.chan_idx >= req->n_channels) {
@@ -94,7 +95,7 @@ void mt76_scan_work(struct work_struct *work)return ; } -if (dev->scan.chan && phy->num_sta) { +if (dev->scan.chan && phy->num_sta && phy->offchannel) { dev->scan.chan =NULL ;mt76_set_channel (phy, &phy->main_chandef, false); goto out;
@@ -102,20 +103,26 @@ void mt76_scan_work(struct work_struct *work) dev->scan.chan = req->channels[dev->scan.chan_idx++];cfg80211_chandef_create (&chandef, dev->scan.chan,NL80211_CHAN_HT20 ); -mt76_set_channel (phy, &chandef, true); +if (phy->main_chandef.chan == dev->scan.chan) { + chandef = phy->main_chandef; + offchannel = false; + } + +mt76_set_channel (phy, &chandef, offchannel);if (!req->n_ssids || chandef.chan->flags & (IEEE80211_CHAN_NO_IR |IEEE80211_CHAN_RADAR )) goto out; - duration =HZ /16 ;/* ~60 ms */ +if (phy->offchannel) + duration =HZ /16 ;/* ~60 ms */ local_bh_disable ();for (i =0 ; i < req->n_ssids; i++)mt76_scan_send_probe (dev, &req->ssids[i]);local_bh_enable (); out: -if (dev->scan.chan) +if (dev->scan.chan && phy->offchannel) duration =max_t (int, duration,msecs_to_jiffies (req->duration + (req->duration >>5 )));
Signature · 1 line
2.51.0
Felix Fietkau
maintainerPATCH 2/11 wifi: mt76: support upgrading passive scans to active
From: Chad Monroe <[email protected]>
On channels with NO_IR or RADAR flags, wait for beacon before sending probe requests. Allows active scanning and WPS on restricted channels if another AP is already present.
--- drivers/net/wireless/mediatek/mt76/mac80211.c | 1 + drivers/net/wireless/mediatek/mt76/mt76.h | 4 ++ .../net/wireless/mediatek/mt76/mt7996/mac.c | 3 ++ drivers/net/wireless/mediatek/mt76/scan.c | 51 +++++++++++++++++-- 4 files changed, 56 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +1 -0
@@ -726,6 +726,7 @@ mt76_alloc_device(struct device *pdev, unsigned int size,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++)skb_queue_head_init (&dev->rx_skb[i]);
drivers/net/wireless/mediatek/mt76/mt76.h +4 -0
@@ -1006,6 +1006,7 @@ struct mt76_dev {u32 rxfilter;struct delayed_work scan_work; +spinlock_t scan_lock;struct {struct cfg80211_scan_request *req;struct ieee80211_channel *chan;
@@ -1013,6 +1014,8 @@ struct mt76_dev {struct mt76_vif_link *mlink;struct mt76_phy *phy;int chan_idx; +bool beacon_wait; +bool beacon_received; } scan;#ifdef CONFIG_NL80211_TESTMODE
@@ -1600,6 +1603,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_sw_scan (struct ieee80211_hw *hw,struct ieee80211_vif *vif,const u8 *mac); void mt76_sw_scan_complete(struct ieee80211_hw *hw,
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +3 -0
@@ -515,6 +515,9 @@ mt7996_mac_fill_rx(struct mt7996_dev *dev, enum mt76_rxq_id q, qos_ctl =FIELD_GET (MT_RXD10_QOS_CTL , v2); seq_ctrl =FIELD_GET (MT_RXD10_SEQ_CTRL , v2); +if (ieee80211_is_beacon (fc)) +mt76_scan_rx_beacon (&dev->mt76, mphy->chandef.chan); + rxd +=4 ;if ((u8 *)rxd - skb->data >= skb->len)return -EINVAL ;
drivers/net/wireless/mediatek/mt76/scan.c +48 -3
79 lines not on this page · raw message
Signature · 1 line
2.51.0
Felix Fietkau
maintainerPATCH 3/11 wifi: mt76: add offchannel check to mt76_roc_complete
In reply to Felix Fietkaumt76_roc_complete() unconditionally calls __mt76_set_channel() to restore the operating channel. The scan equivalent mt76_scan_complete() checks phy->offchannel first, skipping the restore if the phy is already back on-channel.
Without this check, ROC completion performs a redundant full hardware channel switch when something has already moved the phy back.
--- drivers/net/wireless/mediatek/mt76/channel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/channel.c +1 -1
@@ -324,7 +324,7 @@ void mt76_roc_complete(struct mt76_phy *phy)if (mlink) mlink->mvif->roc_phy =NULL ; -if (phy->main_chandef.chan && +if (phy->main_chandef.chan && phy->offchannel && !test_bit (MT76_MCU_RESET , &dev->phy.state))__mt76_set_channel (phy, &phy->main_chandef, false);mt76_put_vif_phy_link (phy, phy->roc_vif, phy->roc_link);
Signature · 1 line
2.51.0
Felix Fietkau
maintainerPATCH 4/11 wifi: mt76: check chanctx before restoring channel after ROC
In reply to Felix Fietkaumt76_remove_chanctx() sets phy->chanctx to NULL but does not clear phy->main_chandef. If ROC is later performed on that phy, completion tries to restore the stale main_chandef channel, programming the hardware to sit on a channel with no active context.
Add a chanctx check to avoid restoring a channel when no context is active.
--- drivers/net/wireless/mediatek/mt76/channel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/channel.c +1 -1
@@ -324,7 +324,7 @@ void mt76_roc_complete(struct mt76_phy *phy)if (mlink) mlink->mvif->roc_phy =NULL ; -if (phy->main_chandef.chan && phy->offchannel && +if (phy->chanctx && phy->main_chandef.chan && phy->offchannel && !test_bit (MT76_MCU_RESET , &dev->phy.state))__mt76_set_channel (phy, &phy->main_chandef, false);mt76_put_vif_phy_link (phy, phy->roc_vif, phy->roc_link);
Signature · 1 line
2.51.0
Felix Fietkau
maintainerPATCH 5/11 wifi: mt76: abort ROC on chanctx changes
In reply to Felix Fietkaumt76_change_chanctx() calls mt76_phy_update_channel() which switches the hardware channel. If ROC is active on the same phy, this switches away from the ROC channel and clears offchannel, but leaves ROC state intact. Mac80211 still thinks the phy is on the ROC channel.
Abort any active ROC before proceeding, matching the pattern already used in add, remove, assign, unassign, and switch chanctx functions.
--- drivers/net/wireless/mediatek/mt76/channel.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/wireless/mediatek/mt76/channel.c +3 -0
@@ -88,6 +88,9 @@ void mt76_change_chanctx(struct ieee80211_hw *hw, IEEE80211_CHANCTX_CHANGE_RADAR)))return ; +if (phy->roc_vif) +mt76_abort_roc (phy); +cancel_delayed_work_sync (&phy->mac_work);mutex_lock (&dev->mutex);
Signature · 1 line
2.51.0
Felix Fietkau
maintainerPATCH 6/11 wifi: mt76: optimize ROC for same-channel case
In reply to Felix Fietkaumt76_remain_on_channel() always creates an HT20 chandef and goes offchannel, even when the ROC channel matches the operating channel. This unnecessarily narrows bandwidth and triggers beacon stop/restart.
When the ROC channel matches the current operating channel, preserve the full chandef and skip the offchannel transition, matching the optimization already present in the scan code.
Extract the shared same-channel detection into mt76_offchannel_chandef() and use it in both ROC and scan paths.
--- drivers/net/wireless/mediatek/mt76/channel.c | 4 ++-- drivers/net/wireless/mediatek/mt76/mt76.h | 12 ++++++++++++ drivers/net/wireless/mediatek/mt76/scan.c | 6 +----- 3 files changed, 15 insertions(+), 7 deletions(-)
drivers/net/wireless/mediatek/mt76/channel.c +2 -2
@@ -392,8 +392,8 @@ int mt76_remain_on_channel(struct ieee80211_hw *hw, struct ieee80211_vif *vif, mlink->mvif->roc_phy = phy; phy->roc_vif = vif; phy->roc_link = mlink; -cfg80211_chandef_create (&chandef, chan,NL80211_CHAN_HT20 ); - ret =__mt76_set_channel (phy, &chandef, true); + ret =__mt76_set_channel (phy, &chandef, +mt76_offchannel_chandef (phy, chan, &chandef));if (ret) { mlink->mvif->roc_phy =NULL ; phy->roc_vif =NULL ;
drivers/net/wireless/mediatek/mt76/mt76.h +12 -0
@@ -1793,6 +1793,18 @@ void mt76_queue_tx_complete(struct mt76_dev *dev, struct mt76_queue *q, struct mt76_queue_entry *e);int __mt76_set_channel (struct mt76_phy *phy,struct cfg80211_chan_def *chandef,bool offchannel); + +static inline bool +mt76_offchannel_chandef (struct mt76_phy *phy,struct ieee80211_channel *chan, +struct cfg80211_chan_def *chandef) +{ +cfg80211_chandef_create (chandef, chan,NL80211_CHAN_HT20 ); +if (phy->main_chandef.chan != chan) +return true; + + *chandef = phy->main_chandef; +return false; +}int mt76_set_channel (struct mt76_phy *phy,struct cfg80211_chan_def *chandef,bool offchannel);void mt76_scan_work (struct work_struct *work);
drivers/net/wireless/mediatek/mt76/scan.c +1 -5
@@ -139,11 +139,7 @@ void mt76_scan_work(struct work_struct *work) } dev->scan.chan = req->channels[dev->scan.chan_idx++]; -cfg80211_chandef_create (&chandef, dev->scan.chan,NL80211_CHAN_HT20 ); -if (phy->main_chandef.chan == dev->scan.chan) { - chandef = phy->main_chandef; - offchannel = false; - } + offchannel =mt76_offchannel_chandef (phy, dev->scan.chan, &chandef);mt76_set_channel (phy, &chandef, offchannel);
Signature · 1 line
2.51.0
Felix Fietkau
maintainerPATCH 7/11 wifi: mt76: send nullfunc PS frames on offchannel transitions
In reply to Felix FietkauSince mt76 uses chanctx, mac80211 does not send nullfunc power save notifications when the driver goes offchannel for scan or ROC. Add mt76_offchannel_notify() to send nullfunc PM=1 before going offchannel and PM=0 after returning, so that the AP can buffer frames during the absence.
For MLO, iterate all vif links on the phy and set IEEE80211_TX_CTRL_MLO_LINK so that the driver's tx_prepare_skb resolves the correct per-link wcid.
--- drivers/net/wireless/mediatek/mt76/channel.c | 12 ++- drivers/net/wireless/mediatek/mt76/mac80211.c | 101 ++++++++++++++++++ drivers/net/wireless/mediatek/mt76/mt76.h | 1 + drivers/net/wireless/mediatek/mt76/scan.c | 7 +- 4 files changed, 117 insertions(+), 4 deletions(-)
drivers/net/wireless/mediatek/mt76/channel.c +9 -3
@@ -328,8 +328,10 @@ void mt76_roc_complete(struct mt76_phy *phy)if (mlink) mlink->mvif->roc_phy =NULL ;if (phy->chanctx && phy->main_chandef.chan && phy->offchannel && - !test_bit (MT76_MCU_RESET , &dev->phy.state)) + !test_bit (MT76_MCU_RESET , &dev->phy.state)) {__mt76_set_channel (phy, &phy->main_chandef, false); +mt76_offchannel_notify (phy, false); + }mt76_put_vif_phy_link (phy, phy->roc_vif, phy->roc_link); phy->roc_vif =NULL ; phy->roc_link =NULL ;
@@ -367,6 +369,7 @@ int mt76_remain_on_channel(struct ieee80211_hw *hw, struct ieee80211_vif *vif,struct mt76_phy *phy = hw->priv;struct mt76_dev *dev = phy->dev;struct mt76_vif_link *mlink; +bool offchannel;int ret =0 ; phy = dev->band_phys[chan->band];
@@ -392,8 +395,11 @@ int mt76_remain_on_channel(struct ieee80211_hw *hw, struct ieee80211_vif *vif, mlink->mvif->roc_phy = phy; phy->roc_vif = vif; phy->roc_link = mlink; - ret =__mt76_set_channel (phy, &chandef, -mt76_offchannel_chandef (phy, chan, &chandef)); + + offchannel =mt76_offchannel_chandef (phy, chan, &chandef); +if (offchannel) +mt76_offchannel_notify (phy, true); + ret =__mt76_set_channel (phy, &chandef, offchannel);if (ret) { mlink->mvif->roc_phy =NULL ; phy->roc_vif =NULL ;
drivers/net/wireless/mediatek/mt76/mac80211.c +101 -0
104 lines not on this page · raw message
drivers/net/wireless/mediatek/mt76/mt76.h +1 -0
@@ -1816,6 +1816,7 @@ struct mt76_vif_link *mt76_get_vif_phy_link(struct mt76_phy *phy, struct ieee80211_vif *vif);void mt76_put_vif_phy_link (struct mt76_phy *phy,struct ieee80211_vif *vif,struct mt76_vif_link *mlink); +void mt76_offchannel_notify (struct mt76_phy *phy,bool offchannel);/* usb */ static inline bool mt76u_urb_error (struct urb *urb)
drivers/net/wireless/mediatek/mt76/scan.c +6 -1
@@ -17,8 +17,10 @@ static void mt76_scan_complete(struct mt76_dev *dev, bool abort)clear_bit (MT76_SCANNING , &phy->state);if (dev->scan.chan && phy->main_chandef.chan && phy->offchannel && - !test_bit (MT76_MCU_RESET , &dev->phy.state)) + !test_bit (MT76_MCU_RESET , &dev->phy.state)) {mt76_set_channel (phy, &phy->main_chandef, false); +mt76_offchannel_notify (phy, false); + }mt76_put_vif_phy_link (phy, dev->scan.vif, dev->scan.mlink);memset (&dev->scan,0 ,sizeof (dev->scan));if (!test_bit (MT76_MCU_RESET , &dev->phy.state))
@@ -135,12 +137,15 @@ void mt76_scan_work(struct work_struct *work)if (dev->scan.chan && phy->num_sta && phy->offchannel) { dev->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); +if (offchannel) +mt76_offchannel_notify (phy, true);mt76_set_channel (phy, &chandef, offchannel);if (!req->n_ssids)
Signature · 1 line
2.51.0
Felix Fietkau
maintainerPATCH 8/11 wifi: mt76: flush pending TX before channel switch
In reply to Felix Fietkaumt76_tx() queues frames on wcid->tx_pending for async processing by tx_worker. In __mt76_set_channel(), the worker gets disabled before it may have run, and the subsequent wait only checks DMA ring queues, not the software pending list. This means frames like nullfunc PS frames from mt76_offchannel_notify() may never be transmitted on the correct channel.
Fix this by running mt76_txq_schedule_pending() synchronously after disabling the tx_worker but before setting MT76_RESET, which would otherwise cause mt76_txq_schedule_pending_wcid() to bail out.
--- drivers/net/wireless/mediatek/mt76/mac80211.c | 5 +++-- drivers/net/wireless/mediatek/mt76/mt76.h | 1 + drivers/net/wireless/mediatek/mt76/tx.c | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +3 -2
@@ -1031,9 +1031,10 @@ int __mt76_set_channel(struct mt76_phy *phy, struct cfg80211_chan_def *chandef,int timeout =HZ /5 ;int ret; -set_bit (MT76_RESET , &phy->state); -mt76_worker_disable (&dev->tx_worker); +mt76_txq_schedule_pending (phy); + +set_bit (MT76_RESET , &phy->state);wait_event_timeout (dev->tx_wait, !mt76_has_tx_pending (phy), timeout);mt76_update_survey (phy);
drivers/net/wireless/mediatek/mt76/mt76.h +1 -0
@@ -1525,6 +1525,7 @@ void mt76_stop_tx_queues(struct mt76_phy *phy, struct ieee80211_sta *sta,void mt76_tx_check_agg_ssn (struct ieee80211_sta *sta,struct sk_buff *skb);void mt76_txq_schedule (struct mt76_phy *phy,enum mt76_txq_id qid);void mt76_txq_schedule_all (struct mt76_phy *phy); +void mt76_txq_schedule_pending (struct mt76_phy *phy);void mt76_tx_worker_run (struct mt76_dev *dev);void mt76_tx_worker (struct mt76_worker *w); void mt76_release_buffered_frames(struct ieee80211_hw *hw,
drivers/net/wireless/mediatek/mt76/tx.c +1 -1
@@ -660,7 +660,7 @@ mt76_txq_schedule_pending_wcid(struct mt76_phy *phy, struct mt76_wcid *wcid,return ret; } -static void mt76_txq_schedule_pending (struct mt76_phy *phy) +void mt76_txq_schedule_pending (struct mt76_phy *phy) {LIST_HEAD (tx_list);int ret =0 ;
Signature · 1 line
2.51.0
Felix Fietkau
maintainerPATCH 9/11 wifi: mt76: route nullfunc frames to PSD/ALTX queue
In reply to Felix Fietkauieee80211_is_data() returns true for nullfunc/QoS-nullfunc frames, so they bypass the PSD queue routing and go through the regular VO data queue. This means firmware processes them through the normal TID queue instead of the ALTX queue, which doesn't guarantee immediate transmission.
Use ieee80211_is_data_present() instead, which returns false for both management frames and nullfunc/QoS-nullfunc (no payload), routing them to MT_TXQ_PSD. Firmware maps PSD to the ALTX queue, which transmits immediately without PS buffering.
This only affects frames from the mt76_tx() pending path. Regular mac80211 TXQ scheduling is unchanged.
--- drivers/net/wireless/mediatek/mt76/tx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/tx.c +1 -1
@@ -632,7 +632,7 @@ mt76_txq_schedule_pending_wcid(struct mt76_phy *phy, struct mt76_wcid *wcid,if ((dev->drv->drv_flags &MT_DRV_HW_MGMT_TXQ ) && !(info->flags &IEEE80211_TX_CTL_HW_80211_ENCAP ) && - !ieee80211_is_data (hdr->frame_control) && + !ieee80211_is_data_present (hdr->frame_control) && (!ieee80211_is_bufferable_mmpdu (skb) ||ieee80211_is_deauth (hdr->frame_control) || head == &wcid->tx_offchannel))
Signature · 1 line
2.51.0
Felix Fietkau
maintainerPATCH 10/11 wifi: mt76: wait for firmware TX completion of mgmt frames before channel switch
In reply to Felix FietkauAfter flushing software-pending frames to DMA, mt76_has_tx_pending() only checks DMA ring q->queued. For token-based drivers, q->queued is decremented at DMA consumption, but firmware may not have transmitted the frame yet. Waiting for all tokens is not feasible because data frames may be stuck in firmware powersave/aggregation queues.
Track PSD queue tokens (firmware ALTX) per phy using an atomic counter. These frames are sent by firmware immediately without PS buffering, so the counter reliably reaches zero after transmission.
Increment the counter in mt76_token_consume() and decrement it in mt76_token_release(), only for PSD queue tokens. Include the counter in mt76_has_tx_pending() so channel switch waits for firmware TX completion of management and nullfunc frames.
mt7615 (uses mt76_token_get/put) and non-token drivers are unaffected as they never call mt76_token_consume/release.
--- drivers/net/wireless/mediatek/mt76/dma.c | 2 ++ drivers/net/wireless/mediatek/mt76/mac80211.c | 3 +++ drivers/net/wireless/mediatek/mt76/mt76.h | 3 +++ .../net/wireless/mediatek/mt76/mt76_connac_mac.c | 6 ++++++ drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 6 ++++++ drivers/net/wireless/mediatek/mt76/tx.c | 14 +++++++++++++- 6 files changed, 33 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/dma.c +2 -0
@@ -666,6 +666,8 @@ mt76_dma_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q,if (!t) goto free_skb; + t->phy_idx = phy->band_idx; + t->qid = qid; txwi =mt76_get_txwi_ptr (dev, t); skb->prev = skb->next =NULL ;
drivers/net/wireless/mediatek/mt76/mac80211.c +3 -0
@@ -971,6 +971,9 @@ bool mt76_has_tx_pending(struct mt76_phy *phy)return true; } +if (atomic_read (&phy->mgmt_tx_pending)) +return true; +return false; }EXPORT_SYMBOL_GPL (mt76_has_tx_pending);
drivers/net/wireless/mediatek/mt76/mt76.h +3 -0
@@ -453,6 +453,7 @@ struct mt76_txwi_cache { };u8 qid; +u8 phy_idx; };struct mt76_rx_tid {
@@ -863,6 +864,8 @@ struct mt76_phy {struct list_head tx_list;struct mt76_queue *q_tx[__MT_TXQ_MAX]; +atomic_t mgmt_tx_pending; +struct cfg80211_chan_def chandef;struct cfg80211_chan_def main_chandef;bool offchannel;
drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c +6 -0
@@ -1209,5 +1209,11 @@ void mt76_connac2_tx_token_put(struct mt76_dev *dev) }spin_unlock_bh (&dev->token_lock);idr_destroy (&dev->token); + +for (id =0 ; id < __MT_MAX_BAND; id++) { +struct mt76_phy *phy = dev->phys[id]; +if (phy) +atomic_set (&phy->mgmt_tx_pending,0 ); + } }EXPORT_SYMBOL_GPL (mt76_connac2_tx_token_put);
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +6 -0
@@ -2215,6 +2215,12 @@ void mt7996_tx_token_put(struct mt7996_dev *dev) }spin_unlock_bh (&dev->mt76.token_lock);idr_destroy (&dev->mt76.token); + +for (id =0 ; id < __MT_MAX_BAND; id++) { +struct mt76_phy *phy = dev->mt76.phys[id]; +if (phy) +atomic_set (&phy->mgmt_tx_pending,0 ); + } } static int
drivers/net/wireless/mediatek/mt76/tx.c +13 -1
@@ -866,9 +866,15 @@ int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi) token =idr_alloc (&dev->token, *ptxwi, dev->token_start, dev->token_start + dev->token_size,GFP_ATOMIC ); -if (token >= dev->token_start) +if (token >= dev->token_start) { dev->token_count++; +if ((*ptxwi)->qid ==MT_TXQ_PSD ) { +struct mt76_phy *mphy =mt76_dev_phy (dev, (*ptxwi)->phy_idx); +atomic_inc (&mphy->mgmt_tx_pending); + } + } +#ifdef CONFIG_NET_MEDIATEK_SOC_WED if (mtk_wed_device_active (&dev->mmio.wed) && token >= dev->mmio.wed.wlan.token_start)
@@ -913,6 +919,12 @@ mt76_token_release(struct mt76_dev *dev, int token, bool *wake)if (txwi) { dev->token_count--; +if (txwi->qid ==MT_TXQ_PSD ) { +struct mt76_phy *mphy =mt76_dev_phy (dev, txwi->phy_idx); +if (atomic_dec_and_test (&mphy->mgmt_tx_pending)) +wake_up (&dev->tx_wait); + } +#ifdef CONFIG_NET_MEDIATEK_SOC_WED if (mtk_wed_device_active(&dev->mmio.wed) && token >= dev->mmio.wed.wlan.token_start &&
Signature · 1 line
2.51.0
Felix Fietkau
maintainerPATCH 11/11 wifi: mt76: add per-link beacon monitoring for MLO
In reply to Felix FietkauWith chanctx drivers using hardware scan or remain-on-channel, mac80211 does not know when the radio goes off-channel, which breaks its software beacon loss detection.
Implement per-link beacon monitoring in the driver. Track the last beacon timestamp per link and check for beacon loss periodically from the mac_work handler.
Beacon monitoring is initialized on association and on late link activation, and cleared on disassociation. The beacon_mon_last timestamp is reset when returning from offchannel and after channel switches to prevent false beacon loss detection.
--- drivers/net/wireless/mediatek/mt76/channel.c | 2 + drivers/net/wireless/mediatek/mt76/mac80211.c | 109 +++++++++++++++++- drivers/net/wireless/mediatek/mt76/mt76.h | 5 + .../net/wireless/mediatek/mt76/mt7996/mac.c | 6 +- .../net/wireless/mediatek/mt76/mt7996/main.c | 32 +++++ drivers/net/wireless/mediatek/mt76/scan.c | 1 - 6 files changed, 150 insertions(+), 5 deletions(-)
drivers/net/wireless/mediatek/mt76/channel.c +2 -0
@@ -257,6 +257,8 @@ int mt76_switch_vif_chanctx(struct ieee80211_hw *hw,continue ; mlink->ctx = vifs->new_ctx; +if (mlink->beacon_mon_interval) +WRITE_ONCE (mlink->beacon_mon_last, jiffies); } out:
drivers/net/wireless/mediatek/mt76/mac80211.c +108 -1
125 lines not on this page · raw message
drivers/net/wireless/mediatek/mt76/mt76.h +5 -0
@@ -367,6 +367,7 @@ enum mt76_wcid_flags { };#define MT76_N_WCIDS 1088 +#define MT76_BEACON_MON_MAX_MISS 7/* stored in ieee80211_tx_info::hw_queue */ #define MT_TX_HW_QUEUE_PHY GENMASK(3, 2)
@@ -836,6 +837,8 @@ struct mt76_vif_link {u8 mcast_rates_idx;u8 beacon_rates_idx;bool offchannel; +unsigned long beacon_mon_last; +u16 beacon_mon_interval;struct ieee80211_chanctx_conf *ctx;struct mt76_wcid *wcid;struct mt76_vif_data *mvif;
@@ -1608,6 +1611,8 @@ 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_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,const u8 *mac); void mt76_sw_scan_complete(struct ieee80211_hw *hw,
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +3 -3
@@ -515,9 +515,6 @@ mt7996_mac_fill_rx(struct mt7996_dev *dev, enum mt76_rxq_id q, qos_ctl =FIELD_GET (MT_RXD10_QOS_CTL , v2); seq_ctrl =FIELD_GET (MT_RXD10_SEQ_CTRL , v2); -if (ieee80211_is_beacon (fc)) -mt76_scan_rx_beacon (&dev->mt76, mphy->chandef.chan); - rxd +=4 ;if ((u8 *)rxd - skb->data >= skb->len)return -EINVAL ;
@@ -664,6 +661,8 @@ mt7996_mac_fill_rx(struct mt7996_dev *dev, enum mt76_rxq_id q, hdr =mt76_skb_get_hdr (skb); fc = hdr->frame_control; +if (ieee80211_is_beacon (fc)) +mt76_rx_beacon (mphy, skb);if (ieee80211_is_data_qos (fc)) {u8 *qos =ieee80211_get_qos_ctl (hdr);
@@ -2944,6 +2943,7 @@ void mt7996_mac_work(struct work_struct *work)mutex_unlock (&mphy->dev->mutex); +mt76_beacon_mon_check (mphy);mt76_tx_status_check (mphy->dev, false); ieee80211_queue_delayed_work(mphy->hw, &mphy->mac_work,
drivers/net/wireless/mediatek/mt76/mt7996/main.c +32 -0
@@ -376,6 +376,17 @@ int mt7996_vif_link_add(struct mt76_phy *mphy, struct ieee80211_vif *vif, mvif->mt76.deflink_id = link_conf->link_id; } +if (vif->type ==NL80211_IFTYPE_STATION ) { + vif->driver_flags |=IEEE80211_VIF_BEACON_FILTER ; + +if (vif->cfg.assoc && link_conf->beacon_int) { + mlink->beacon_mon_interval = +msecs_to_jiffies (ieee80211_tu_to_usec ( + link_conf->beacon_int) /1000 ); +WRITE_ONCE (mlink->beacon_mon_last, jiffies); + } + } +return 0 ; }
@@ -831,6 +842,13 @@ mt7996_vif_cfg_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,if (!link)continue ; +if (vif->type ==NL80211_IFTYPE_STATION ) { + link->mt76.beacon_mon_interval = +msecs_to_jiffies (ieee80211_tu_to_usec ( + link_conf->beacon_int) /1000 ); +WRITE_ONCE (link->mt76.beacon_mon_last, jiffies); + } +if (!link->phy)continue ;
@@ -843,6 +861,20 @@ mt7996_vif_cfg_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif, } } +if ((changed &BSS_CHANGED_ASSOC ) && !vif->cfg.assoc && + vif->type ==NL80211_IFTYPE_STATION ) { +struct ieee80211_bss_conf *link_conf; +unsigned long link_id; + +for_each_vif_active_link (vif, link_conf, link_id) { +struct mt7996_vif_link *link; + + link =mt7996_vif_link (dev, vif, link_id); +if (link) + link->mt76.beacon_mon_interval =0 ; + } + } +mutex_unlock (&dev->mt76.mutex); }
drivers/net/wireless/mediatek/mt76/scan.c +0 -1
@@ -105,7 +105,6 @@ void mt76_scan_rx_beacon(struct mt76_dev *dev, struct ieee80211_channel *chan) out:spin_unlock (&dev->scan_lock); } -EXPORT_SYMBOL_GPL (mt76_scan_rx_beacon);void mt76_scan_work (struct work_struct *work) {
Signature · 1 line
2.51.0