Linux wireless drivers development
 help / color / mirror / Atom feed
From: Felix Fietkau <nbd@nbd.name>
To: linux-wireless@vger.kernel.org
Subject: [PATCH mt76-next 19/20] wifi: mt76: mt792x: flush frames that still wait for the TX worker
Date: Thu, 19 Nov 2026 13:43:51 +0100	[thread overview]
Message-ID: <20261119124352.1842164-19-nbd@nbd.name> (raw)
In-Reply-To: <20261119124352.1842164-1-nbd@nbd.name>

mt792x_flush() waits for the hardware queues alone, but since
commit 0335c034e726 ("wifi: mt76: fix race condition related to
checking tx queue fill status"), a frame can also wait on the pending
list of its wcid until the TX worker moves it to a hardware queue. The
flush can thus return before a frame that mac80211 flushes reaches the
hardware. At a disconnection, the join ROC of the departure then ends
before the Deauthentication goes out.

Also flush the frames on the pending lists, as __mt76_set_channel()
does before a channel change, or drop them if mac80211 asks to drop
frames. Hold the mutex for it, since a chip reset parks the TX worker
under the mutex. A USB disconnect parks the worker without the mutex,
so leave the worker alone while MT76_RESET is set, and set the bit
under the mutex.

Fixes: 0335c034e726 ("wifi: mt76: fix race condition related to checking tx queue fill status")
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
 drivers/net/wireless/mediatek/mt76/mt76.h     |  1 +
 .../net/wireless/mediatek/mt76/mt792x_core.c  | 16 ++++++++++++++
 .../net/wireless/mediatek/mt76/mt792x_usb.c   |  2 ++
 drivers/net/wireless/mediatek/mt76/tx.c       | 21 +++++++++++++++++++
 4 files changed, 40 insertions(+)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
index 2a39729142af..548632fe884a 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -1568,6 +1568,7 @@ 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_txq_purge_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,
diff --git a/drivers/net/wireless/mediatek/mt76/mt792x_core.c b/drivers/net/wireless/mediatek/mt76/mt792x_core.c
index a835c8d89618..2d39f18f4d43 100644
--- a/drivers/net/wireless/mediatek/mt76/mt792x_core.c
+++ b/drivers/net/wireless/mediatek/mt76/mt792x_core.c
@@ -435,9 +435,25 @@ void mt792x_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 		  u32 queues, bool drop)
 {
 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
+	bool park;
+
+	mt792x_mutex_acquire(dev);
+
+	park = !test_bit(MT76_RESET, &dev->mphy.state);
+	if (park) {
+		mt76_worker_disable(&dev->mt76.tx_worker);
+		if (drop)
+			mt76_txq_purge_pending(&dev->mphy);
+		mt76_txq_schedule_pending(&dev->mphy);
+	}
 
 	wait_event_timeout(dev->mt76.tx_wait,
 			   !mt76_has_tx_pending(&dev->mphy), HZ / 2);
+
+	if (park)
+		mt76_worker_enable(&dev->mt76.tx_worker);
+
+	mt792x_mutex_release(dev);
 }
 EXPORT_SYMBOL_GPL(mt792x_flush);
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt792x_usb.c b/drivers/net/wireless/mediatek/mt76/mt792x_usb.c
index 5e19e64a9a00..feedb66d4b6e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt792x_usb.c
+++ b/drivers/net/wireless/mediatek/mt76/mt792x_usb.c
@@ -501,7 +501,9 @@ void mt792xu_disconnect(struct usb_interface *usb_intf)
 	if (!dev)
 		return;
 
+	mutex_lock(&dev->mt76.mutex);
 	set_bit(MT76_RESET, &dev->mphy.state);
+	mutex_unlock(&dev->mt76.mutex);
 	clear_bit(MT76_STATE_RUNNING, &dev->mphy.state);
 
 	cancel_work_sync(&dev->init_work);
diff --git a/drivers/net/wireless/mediatek/mt76/tx.c b/drivers/net/wireless/mediatek/mt76/tx.c
index 2d74958893c5..72d1021a940f 100644
--- a/drivers/net/wireless/mediatek/mt76/tx.c
+++ b/drivers/net/wireless/mediatek/mt76/tx.c
@@ -804,6 +804,27 @@ void mt76_txq_schedule_pending(struct mt76_phy *phy)
 	rcu_read_unlock();
 	local_bh_enable();
 }
+EXPORT_SYMBOL_GPL(mt76_txq_schedule_pending);
+
+void mt76_txq_purge_pending(struct mt76_phy *phy)
+{
+	struct mt76_dev *dev = phy->dev;
+	struct sk_buff_head list;
+	struct mt76_wcid *wcid;
+
+	__skb_queue_head_init(&list);
+
+	spin_lock_bh(&dev->tx_lock);
+	list_for_each_entry(wcid, &phy->tx_list, tx_list) {
+		spin_lock(&wcid->tx_pending.lock);
+		skb_queue_splice_tail_init(&wcid->tx_pending, &list);
+		spin_unlock(&wcid->tx_pending.lock);
+	}
+	spin_unlock_bh(&dev->tx_lock);
+
+	ieee80211_purge_tx_queue(phy->hw, &list);
+}
+EXPORT_SYMBOL_GPL(mt76_txq_purge_pending);
 
 void mt76_txq_schedule_all(struct mt76_phy *phy)
 {
-- 
2.47.3


  parent reply	other threads:[~2026-11-19 12:44 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 12:43 [PATCH mt76-next 01/20] wifi: mt76: mt7921: skip the ND offload update of a vif not in the driver Felix Fietkau
2026-11-19 12:43 ` [PATCH mt76-next 02/20] wifi: mt76: mt7925: " Felix Fietkau
2026-11-19 12:43 ` [PATCH mt76-next 03/20] wifi: mt76: take the remaining wcids off the phy tx_list at reset Felix Fietkau
2026-11-19 12:43 ` [PATCH mt76-next 04/20] wifi: mt76: take the remaining wcids off sta_poll_list " Felix Fietkau
2026-11-19 12:43 ` [PATCH mt76-next 05/20] wifi: mt76: mt7915: take the remaining stations off sta_rc_list " Felix Fietkau
2026-11-19 12:43 ` [PATCH mt76-next 06/20] wifi: mt76: mt7996: list only published links on sta_rc_list Felix Fietkau
2026-11-19 12:43 ` [PATCH mt76-next 07/20] wifi: mt76: mt7996: take the remaining links off sta_rc_list at reset Felix Fietkau
2026-11-19 12:43 ` [PATCH mt76-next 08/20] wifi: mt76: mt7915: take the TWT flows of a removed station off twt_list Felix Fietkau
2026-11-19 12:43 ` [PATCH mt76-next 09/20] wifi: mt76: mt7996: " Felix Fietkau
2026-11-19 12:43 ` [PATCH mt76-next 10/20] wifi: mt76: mt7915: drop the TWT agreements at a full reset Felix Fietkau
2026-11-19 12:43 ` [PATCH mt76-next 11/20] wifi: mt76: mt7996: " Felix Fietkau
2026-11-19 12:43 ` [PATCH mt76-next 12/20] wifi: mt76: mt7915: read twt_list under the mutex in twt_stats Felix Fietkau
2026-11-19 12:43 ` [PATCH mt76-next 13/20] wifi: mt76: mt7996: " Felix Fietkau
2026-11-19 12:43 ` [PATCH mt76-next 14/20] wifi: mt76: mt7915: publish the global wcid again after a full reset Felix Fietkau
2026-11-19 12:43 ` [PATCH mt76-next 15/20] wifi: mt76: mt7996: " Felix Fietkau
2026-11-19 12:43 ` [PATCH mt76-next 16/20] wifi: mt76: mt7925: keep the antenna mask across a firmware reload Felix Fietkau
2026-11-19 12:43 ` [PATCH mt76-next 17/20] wifi: mt76: mt7925: remove mt7925_mcu_del_dev() Felix Fietkau
2026-11-19 12:43 ` [PATCH mt76-next 18/20] wifi: mt76: mt7921: keep the antenna mask across a firmware reload Felix Fietkau
2026-11-19 12:43 ` Felix Fietkau [this message]
2026-11-19 12:43 ` [PATCH mt76-next 20/20] wifi: mt76: mt7925: send the deauth of an MLD station on its AC queue Felix Fietkau

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=20261119124352.1842164-19-nbd@nbd.name \
    --to=nbd@nbd.name \
    --cc=linux-wireless@vger.kernel.org \
    /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