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 16/16] wifi: mt76: mt7996: stop resets before the hw is unregistered
Date: Thu, 26 Nov 2026 19:23:25 +0100	[thread overview]
Message-ID: <20261126182325.2516607-16-nbd@nbd.name> (raw)
In-Reply-To: <20261126182325.2516607-1-nbd@nbd.name>

recovery.hw_init_done stays set while mt7996_unregister_device()
unregisters the hw. The MCU timeout path, the interrupt tasklet and
debugfs can thus queue reset_work or dump_work after the cancel, for
example on an MCU timeout in ieee80211_unregister_hw(). The work then
runs from destroy_workqueue() in mt76_free_device() and calls
ieee80211_restart_hw() on the unregistered hw.

Clear the flag before the hw is unregistered, as
mt7925e_unregister_device() does. Test the flag and queue the work
under dev->mt76.lock, and set and clear it under the same lock, so that
the cancels after the clear catch every queued work.

Also make the recovery flags plain bools, since the reset work writes
them without a lock and a bitfield write can undo another.

Fixes: 27015b6fbcca ("wifi: mt76: mt7996: enable full system reset support")
Fixes: d2b860454ea2 ("wifi: mt76: mt7996: reset device after MCU message timeout")
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
 drivers/net/wireless/mediatek/mt76/mt7996/init.c   | 10 +++++++++-
 drivers/net/wireless/mediatek/mt76/mt7996/mac.c    | 10 +++++++---
 drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h |  6 +++---
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/init.c b/drivers/net/wireless/mediatek/mt76/mt7996/init.c
index 18eab0eaaaad..dd7755f3258b 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/init.c
@@ -1743,6 +1743,13 @@ void mt7996_set_stream_he_eht_caps(struct mt7996_phy *phy)
 						NL80211_BAND_6GHZ);
 }
 
+static void mt7996_set_hw_init_done(struct mt7996_dev *dev, bool done)
+{
+	spin_lock_bh(&dev->mt76.lock);
+	dev->recovery.hw_init_done = done;
+	spin_unlock_bh(&dev->mt76.lock);
+}
+
 int mt7996_register_device(struct mt7996_dev *dev)
 {
 	struct ieee80211_hw *hw = mt76_hw(dev);
@@ -1792,7 +1799,7 @@ int mt7996_register_device(struct mt7996_dev *dev)
 
 	ieee80211_queue_work(mt76_hw(dev), &dev->init_work);
 
-	dev->recovery.hw_init_done = true;
+	mt7996_set_hw_init_done(dev, true);
 
 	ret = mt7996_init_debugfs(dev);
 	if (ret)
@@ -1814,6 +1821,7 @@ void mt7996_unregister_device(struct mt7996_dev *dev)
 {
 	int i;
 
+	mt7996_set_hw_init_done(dev, false);
 	cancel_work_sync(&dev->dump_work);
 	cancel_work_sync(&dev->wed_rro.work);
 	cancel_work_sync(&dev->reset_work);
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
index ec4c8118d679..1a9e2a2db7a5 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
@@ -2889,11 +2889,13 @@ void mt7996_mac_dump_work(struct work_struct *work)
 
 void mt7996_reset(struct mt7996_dev *dev)
 {
+	spin_lock_bh(&dev->mt76.lock);
+
 	if (!dev->recovery.hw_init_done)
-		return;
+		goto out;
 
 	if (dev->recovery.hw_full_reset)
-		return;
+		goto out;
 
 	/* wm/wa exception: do full recovery */
 	if (READ_ONCE(dev->recovery.state) & MT_MCU_CMD_WDT_MASK) {
@@ -2904,7 +2906,7 @@ void mt7996_reset(struct mt7996_dev *dev)
 
 		mt7996_irq_disable(dev, MT_INT_MCU_CMD);
 		queue_work(dev->mt76.wq, &dev->dump_work);
-		return;
+		goto out;
 	}
 
 	if (READ_ONCE(dev->recovery.state) & MT_MCU_CMD_STOP_DMA) {
@@ -2914,6 +2916,8 @@ void mt7996_reset(struct mt7996_dev *dev)
 
 	queue_work(dev->mt76.wq, &dev->reset_work);
 	wake_up(&dev->reset_wait);
+out:
+	spin_unlock_bh(&dev->mt76.lock);
 }
 
 void mt7996_mac_update_stats(struct mt7996_phy *phy)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
index 1354bd82808c..86c718d6ec82 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
@@ -468,9 +468,9 @@ struct mt7996_dev {
 		u32 state;
 		u32 wa_reset_count;
 		u32 wm_reset_count;
-		bool hw_full_reset:1;
-		bool hw_init_done:1;
-		bool restart:1;
+		bool hw_full_reset;
+		bool hw_init_done;
+		bool restart;
 	} recovery;
 
 	/* protects coredump data */
-- 
2.47.3


      parent reply	other threads:[~2026-11-26 18:23 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 18:23 [PATCH mt76-next 01/16] wifi: mt76: keep the Null frame of an AP on its AC queue Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 02/16] wifi: mt76: mt7996: limit the HE and EHT maps of a peer to its rx_nss Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 03/16] wifi: mt76: mt7915: send the current SM power save mode in STA_REC_HT Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 04/16] wifi: mt76: mt7996: take the HE caps of the band of each link Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 05/16] wifi: mt76: mt7915: count the WA TX statistics from an unsolicited event Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 06/16] wifi: mt76: keep an RX replay counter per group key id and TID Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 07/16] wifi: mt76: mt7996: check the RX PN of group addressed frames Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 08/16] wifi: mt76: mt7615: " Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 09/16] wifi: mt76: mt7615: reset the group RX PN counters at WoWLAN resume Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 10/16] wifi: mt76: mt7915: check the RX PN of group addressed frames Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 11/16] wifi: mt76: mt792x: " Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 12/16] wifi: mt76: mt792x: reset the group RX PN counters at WoWLAN resume Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 13/16] wifi: mt76: mt7603: check the RX PN of group addressed frames Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 14/16] wifi: mt76: mt76x02: find no station for the group wcid of a vif Felix Fietkau
2026-11-26 18:23 ` [PATCH mt76-next 15/16] wifi: mt76: mt7915: stop resets before the hw is unregistered Felix Fietkau
2026-11-26 18:23 ` Felix Fietkau [this message]

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=20261126182325.2516607-16-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