All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felix Fietkau <nbd@nbd.name>
To: linux-wireless@vger.kernel.org
Subject: [PATCH mt76-next 08/20] wifi: mt76: mt7996: reset after an MCU reset lost a state command
Date: Tue, 24 Nov 2026 09:42:57 +0100	[thread overview]
Message-ID: <20261124084309.1981968-8-nbd@nbd.name> (raw)
In-Reply-To: <20261124084309.1981968-1-nbd@nbd.name>

An L1 SER sets MT76_MCU_RESET, which ends each command wait and refuses
each new command. The firmware can have run a command that it took
just before the recovery. The state that a cut or refused command sets
is thus unknown or missing. mt7996_mcu_parse_response() starts a full
reset only for a timeout with the bit clear.

Start a full reset where the core reports such a command, unless one is
already queued. The firmware load frees every record, and mac80211 sets
up each key, station and BSS again. Leave out a beacon template, as the
L1 work uploads each template again, and the L1 trigger of a WED reset,
as the pending reset that refuses it takes its place.

Fixes: 98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices")
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
 .../net/wireless/mediatek/mt76/mt7996/mac.c   | 12 +++++++
 .../net/wireless/mediatek/mt76/mt7996/mcu.c   | 35 ++++++++++++++-----
 .../net/wireless/mediatek/mt76/mt7996/mcu.h   |  5 +++
 .../wireless/mediatek/mt76/mt7996/mt7996.h    |  1 +
 4 files changed, 44 insertions(+), 9 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
index d724ac425b42..e507bfd34372 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
@@ -2615,6 +2615,18 @@ mt7996_mac_full_reset(struct mt7996_dev *dev)
 	ieee80211_restart_hw(mt76_hw(dev));
 }
 
+/* MT76_MCU_RESET keeps every command from the firmware until the reload */
+void mt7996_mac_full_reset_queue(struct mt7996_dev *dev)
+{
+	lockdep_assert_held(&dev->mt76.lock);
+
+	set_bit(MT76_MCU_RESET, &dev->mphy.state);
+	dev->recovery.restart = true;
+	wake_up(&dev->mt76.mcu.wait);
+	queue_work(dev->mt76.wq, &dev->reset_work);
+	wake_up(&dev->reset_wait);
+}
+
 void mt7996_mac_reset_work(struct work_struct *work)
 {
 	unsigned long bcn_restored = 0;
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
index 52465006a40b..fc56ce723de5 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.c
@@ -215,6 +215,21 @@ mt7996_mcu_set_sta_ht_mcs(struct ieee80211_link_sta *link_sta,
 		ht_mcs[nss] = link_sta->ht_cap.mcs.rx_mask[nss] & mask[nss];
 }
 
+/* only the firmware load gives a known state again */
+static void
+mt7996_mcu_cmd_lost(struct mt76_dev *mdev, int cmd)
+{
+	struct mt7996_dev *dev = container_of(mdev, struct mt7996_dev, mt76);
+
+	if (cmd & (MT7996_MCU_CMD_BCN_TEMPLATE | MT7996_MCU_CMD_L1_TRIGGER))
+		return;
+
+	spin_lock_bh(&dev->mt76.lock);
+	if (dev->recovery.hw_init_done && !dev->recovery.restart)
+		mt7996_mac_full_reset_queue(dev);
+	spin_unlock_bh(&dev->mt76.lock);
+}
+
 static int
 mt7996_mcu_parse_response(struct mt76_dev *mdev, int cmd,
 			  struct sk_buff *skb, int seq)
@@ -230,12 +245,10 @@ mt7996_mcu_parse_response(struct mt76_dev *mdev, int cmd,
 		dev_err(mdev->dev, "Message %08x (seq %d) timeout\n",
 			cmd, seq);
 
-		if (!test_and_set_bit(MT76_MCU_RESET, &dev->mphy.state)) {
-			dev->recovery.restart = true;
-			wake_up(&dev->mt76.mcu.wait);
-			queue_work(dev->mt76.wq, &dev->reset_work);
-			wake_up(&dev->reset_wait);
-		}
+		spin_lock_bh(&dev->mt76.lock);
+		if (!test_and_set_bit(MT76_MCU_RESET, &dev->mphy.state))
+			mt7996_mac_full_reset_queue(dev);
+		spin_unlock_bh(&dev->mt76.lock);
 
 		return -ETIMEDOUT;
 	}
@@ -3444,7 +3457,8 @@ int mt7996_mcu_add_beacon(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 out:
 	dev_kfree_skb(skb);
 	ret = mt76_mcu_skb_send_msg(&dev->mt76, rskb,
-				    MCU_WMWA_UNI_CMD(BSS_INFO_UPDATE), true);
+				    MCU_WMWA_UNI_CMD(BSS_INFO_UPDATE) |
+				    MT7996_MCU_CMD_BCN_TEMPLATE, true);
 	link->csa_bcn_uploaded = !ret && enabled && link_conf->csa_active;
 
 	return ret;
@@ -4044,6 +4058,7 @@ int mt7996_mcu_init(struct mt7996_dev *dev)
 		.headroom = sizeof(struct mt76_connac2_mcu_txd), /* reuse */
 		.mcu_skb_send_msg = mt7996_mcu_send_message,
 		.mcu_parse_response = mt7996_mcu_parse_response,
+		.mcu_cmd_lost = mt7996_mcu_cmd_lost,
 	};
 
 	dev->mt76.mcu_ops = &mt7996_mcu_ops;
@@ -5114,6 +5129,7 @@ int mt7996_mcu_set_ser(struct mt7996_dev *dev, u8 action, u8 val, u8 band)
 		.tag = cpu_to_le16(action),
 		.len = cpu_to_le16(sizeof(req) - 4),
 	};
+	int cmd = MCU_WM_UNI_CMD(SER);
 
 	switch (action) {
 	case UNI_CMD_SER_SET:
@@ -5122,13 +5138,14 @@ int mt7996_mcu_set_ser(struct mt7996_dev *dev, u8 action, u8 val, u8 band)
 	case UNI_CMD_SER_TRIGGER:
 		req.trigger.method = val;
 		req.trigger.band = band;
+		if (val == UNI_CMD_SER_SET_RECOVER_FROM_ETH)
+			cmd |= MT7996_MCU_CMD_L1_TRIGGER;
 		break;
 	default:
 		return -EINVAL;
 	}
 
-	return mt76_mcu_send_msg(&dev->mt76, MCU_WM_UNI_CMD(SER),
-				 &req, sizeof(req), false);
+	return mt76_mcu_send_msg(&dev->mt76, cmd, &req, sizeof(req), false);
 }
 
 int mt7996_mcu_set_txbf(struct mt7996_dev *dev, u8 action)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h
index 2fdf82394355..a97fbcce1d47 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h
@@ -30,6 +30,11 @@ struct mt7996_mcu_uni_event {
 	__le32 status; /* 0: success, others: fail */
 } __packed;
 
+/* host flag: an L1 SER frees every template and the L1 work uploads it again */
+#define MT7996_MCU_CMD_BCN_TEMPLATE		BIT(22)
+/* host flag: the pending reset that refuses an L1 trigger takes its place */
+#define MT7996_MCU_CMD_L1_TRIGGER		BIT(23)
+
 struct mt7996_mcu_thermal_ctrl {
 	u8 ctrl_id;
 	u8 band_idx;
diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
index a9d265c90234..f5bca533c3e1 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
@@ -735,6 +735,7 @@ int mt7996_init_tx_queues(struct mt7996_phy *phy, int idx,
 void mt7996_init_txpower(struct mt7996_phy *phy);
 int mt7996_txbf_init(struct mt7996_dev *dev);
 void mt7996_reset(struct mt7996_dev *dev);
+void mt7996_mac_full_reset_queue(struct mt7996_dev *dev);
 int mt7996_run(struct mt7996_phy *phy);
 int mt7996_mcu_init(struct mt7996_dev *dev);
 int mt7996_mcu_init_firmware(struct mt7996_dev *dev);
-- 
2.47.3


  parent reply	other threads:[~2026-11-24  8:43 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24  8:42 [PATCH mt76-next 01/20] wifi: mt76: mt7915: dump the firmware memory of mt7916 Felix Fietkau
2026-11-24  8:42 ` [PATCH mt76-next 02/20] wifi: mt76: mt7915: set the LED GPIO mux " Felix Fietkau
2026-11-24  8:53   ` Lorenzo Bianconi
2026-11-24  8:42 ` [PATCH mt76-next 03/20] wifi: mt76: fail an MCU command started during an MCU reset Felix Fietkau
2026-11-24  8:54   ` Lorenzo Bianconi
2026-11-24  8:42 ` [PATCH mt76-next 04/20] wifi: mt76: mark an MCU command that only reads Felix Fietkau
2026-11-24  8:42 ` [PATCH mt76-next 05/20] wifi: mt76: retry only an MCU command that reads Felix Fietkau
2026-11-24  8:42 ` [PATCH mt76-next 06/20] wifi: mt76: report an MCU command whose outcome is unknown Felix Fietkau
2026-11-24  8:42 ` [PATCH mt76-next 07/20] wifi: mt76: mt7996: mark the MCU commands that only read Felix Fietkau
2026-11-24  8:42 ` Felix Fietkau [this message]
2026-11-24  8:42 ` [PATCH mt76-next 09/20] wifi: mt76: mt7915: " Felix Fietkau
2026-11-24  8:42 ` [PATCH mt76-next 10/20] wifi: mt76: mt7915: hold the device mutex in the rate control work Felix Fietkau
2026-11-24  8:56   ` Lorenzo Bianconi
2026-11-24  8:43 ` [PATCH mt76-next 11/20] wifi: mt76: mt7915: hold the device mutex in the station and regd updates Felix Fietkau
2026-11-24  8:58   ` Lorenzo Bianconi
2026-11-24  8:43 ` [PATCH mt76-next 12/20] wifi: mt76: mt7915: reset after an MCU reset lost a state command Felix Fietkau
2026-11-24  8:43 ` [PATCH mt76-next 13/20] wifi: mt76: mt7996: clear the PS state of stations at a reset Felix Fietkau
2026-11-24  8:43 ` [PATCH mt76-next 14/20] wifi: mt76: mt7996: apply the PS sync bitmap to MLD stations alone Felix Fietkau
2026-11-24  8:43 ` [PATCH mt76-next 15/20] wifi: mt76: mt7996: keep the TWT state out of the PS flag Felix Fietkau
2026-11-24  8:43 ` [PATCH mt76-next 16/20] wifi: mt76: mt7996: read the TSF twice against the firmware's latch Felix Fietkau
2026-11-24  8:43 ` [PATCH mt76-next 17/20] wifi: mt76: mt7996: check a TSF write " Felix Fietkau
2026-11-24  8:43 ` [PATCH mt76-next 18/20] wifi: mt76: mt7915: keep the TWT state out of the PS flag Felix Fietkau
2026-11-24  8:43 ` [PATCH mt76-next 19/20] wifi: mt76: mt7915: clear the PS flag of a station at a reset Felix Fietkau
2026-11-24  8:43 ` [PATCH mt76-next 20/20] wifi: mt76: mt7996: set the default link again when a link is reused Felix Fietkau
2026-11-24  8:53 ` [PATCH mt76-next 01/20] wifi: mt76: mt7915: dump the firmware memory of mt7916 Lorenzo Bianconi

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=20261124084309.1981968-8-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.