public inbox for linux-mediatek@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH v1 0/3] Trigger reset if firmware status is abnormal when
@ 2026-02-03  6:25 Chris Lu
  2026-02-03  6:25 ` [PATCH v1 1/3] Bluetooth: btmtk: improve mt79xx firmware setup retry flow Chris Lu
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Chris Lu @ 2026-02-03  6:25 UTC (permalink / raw)
  To: Marcel Holtmann, Johan Hedberg, Luiz Von Dentz
  Cc: Sean Wang, Will Lee, SS Wu, Steve Lee, linux-bluetooth,
	linux-kernel, linux-mediatek, Chris Lu

When the device unexpectedly restarts during previous firmware
download process, it can cause mt79xx firmware status to be
abnormal in the next attempt. In this case, a reset should be
performed to ensure everything starts afresh.

These changes include:
1. Optimizing the handling after the download function retry
   is exhausted, a reset should be performed.
2. Another download firmware command also needs to check status
   , and if an unexpected status occurs, trigger a reset.
3. Adding a flag "BTMTK_FIRMWARE_DL_RETRY": if download firmware
   process enters the reset mechanism, this flag will be set.
   After a successful setup, the flag will be cleared.
   If the flag is already set, no further reset attempts will be
   made to avoid endless reset retries.

Chris Lu (3):
  Bluetooth: btmtk: improve mt79xx firmware setup retry flow
  Bluetooth: btmtk: add status check in  mt79xx firmware setup
  Bluetooth: btmtk: Add reset mechanism if downloading firmware failed

 drivers/bluetooth/btmtk.c | 21 +++++++++++++++++++--
 drivers/bluetooth/btmtk.h |  1 +
 2 files changed, 20 insertions(+), 2 deletions(-)

-- 
2.45.2



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v1 1/3] Bluetooth: btmtk: improve mt79xx firmware setup retry flow
  2026-02-03  6:25 [PATCH v1 0/3] Trigger reset if firmware status is abnormal when Chris Lu
@ 2026-02-03  6:25 ` Chris Lu
  2026-02-03  6:25 ` [PATCH v1 2/3] Bluetooth: btmtk: add status check in mt79xx firmware setup Chris Lu
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Chris Lu @ 2026-02-03  6:25 UTC (permalink / raw)
  To: Marcel Holtmann, Johan Hedberg, Luiz Von Dentz
  Cc: Sean Wang, Will Lee, SS Wu, Steve Lee, linux-bluetooth,
	linux-kernel, linux-mediatek, Chris Lu

If retries are exhausted, driver should not do futher operation.
During mt79xx firmware download process, if the retry count reaches0,
driver will return an -EIO error and release the firmware resources.

Signed-off-by: Chris Lu <chris.lu@mediatek.com>
---
 drivers/bluetooth/btmtk.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/bluetooth/btmtk.c b/drivers/bluetooth/btmtk.c
index a8c520dc09e1..b0f87b04046e 100644
--- a/drivers/bluetooth/btmtk.c
+++ b/drivers/bluetooth/btmtk.c
@@ -205,6 +205,12 @@ int btmtk_setup_firmware_79xx(struct hci_dev *hdev, const char *fwname,
 				}
 			}
 
+			/* If retry exhausted goto err_release_fw */
+			if (retry == 0) {
+				err = -EIO;
+				goto err_release_fw;
+			}
+
 			fw_ptr += section_offset;
 			wmt_params.op = BTMTK_WMT_PATCH_DWNLD;
 			wmt_params.status = NULL;
-- 
2.45.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v1 2/3] Bluetooth: btmtk: add status check in mt79xx firmware setup
  2026-02-03  6:25 [PATCH v1 0/3] Trigger reset if firmware status is abnormal when Chris Lu
  2026-02-03  6:25 ` [PATCH v1 1/3] Bluetooth: btmtk: improve mt79xx firmware setup retry flow Chris Lu
@ 2026-02-03  6:25 ` Chris Lu
  2026-02-03  6:25 ` [PATCH v1 3/3] Bluetooth: btmtk: Add reset mechanism if downloading firmware failed Chris Lu
  2026-02-11 19:40 ` [PATCH v1 0/3] Trigger reset if firmware status is abnormal when patchwork-bot+bluetooth
  3 siblings, 0 replies; 5+ messages in thread
From: Chris Lu @ 2026-02-03  6:25 UTC (permalink / raw)
  To: Marcel Holtmann, Johan Hedberg, Luiz Von Dentz
  Cc: Sean Wang, Will Lee, SS Wu, Steve Lee, linux-bluetooth,
	linux-kernel, linux-mediatek, Chris Lu

To prevent abnormal controller states, it is necessary to check
status in another part of the mt79xx firmware setup. During this
process, receiving the 'BTMTK_WMT_PATCH_PROGRESS' status is unexpected.
If this occurs, it should be treated as an error, and driver must be
prevented from continuing execution.

Signed-off-by: Chris Lu <chris.lu@mediatek.com>
---
 drivers/bluetooth/btmtk.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/bluetooth/btmtk.c b/drivers/bluetooth/btmtk.c
index b0f87b04046e..67db5a48c3e4 100644
--- a/drivers/bluetooth/btmtk.c
+++ b/drivers/bluetooth/btmtk.c
@@ -213,7 +213,6 @@ int btmtk_setup_firmware_79xx(struct hci_dev *hdev, const char *fwname,
 
 			fw_ptr += section_offset;
 			wmt_params.op = BTMTK_WMT_PATCH_DWNLD;
-			wmt_params.status = NULL;
 
 			while (dl_size > 0) {
 				dlen = min_t(int, 250, dl_size);
@@ -231,7 +230,14 @@ int btmtk_setup_firmware_79xx(struct hci_dev *hdev, const char *fwname,
 				wmt_params.data = fw_ptr;
 
 				err = wmt_cmd_sync(hdev, &wmt_params);
-				if (err < 0) {
+				/* Status BTMTK_WMT_PATCH_PROGRESS indicates firmware is
+				 * in process of being downloaded, which is not expected to
+				 * occur here.
+				 */
+				if (status == BTMTK_WMT_PATCH_PROGRESS) {
+					err = -EIO;
+					goto err_release_fw;
+				} else if (err < 0) {
 					bt_dev_err(hdev, "Failed to send wmt patch dwnld (%d)",
 						   err);
 					goto err_release_fw;
-- 
2.45.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v1 3/3] Bluetooth: btmtk: Add reset mechanism if downloading firmware failed
  2026-02-03  6:25 [PATCH v1 0/3] Trigger reset if firmware status is abnormal when Chris Lu
  2026-02-03  6:25 ` [PATCH v1 1/3] Bluetooth: btmtk: improve mt79xx firmware setup retry flow Chris Lu
  2026-02-03  6:25 ` [PATCH v1 2/3] Bluetooth: btmtk: add status check in mt79xx firmware setup Chris Lu
@ 2026-02-03  6:25 ` Chris Lu
  2026-02-11 19:40 ` [PATCH v1 0/3] Trigger reset if firmware status is abnormal when patchwork-bot+bluetooth
  3 siblings, 0 replies; 5+ messages in thread
From: Chris Lu @ 2026-02-03  6:25 UTC (permalink / raw)
  To: Marcel Holtmann, Johan Hedberg, Luiz Von Dentz
  Cc: Sean Wang, Will Lee, SS Wu, Steve Lee, linux-bluetooth,
	linux-kernel, linux-mediatek, Chris Lu

Add a new flag 'BTMTK_FIRMWARE_DL_RETRY'.
If an error occurs during mt79xx firmware download process, this flag
will be set and cleared after a reset. If the flag is already set and
firmware still cannot be loaded successfully after a reset, no further
reset attempts will be made. In other words, if there is a problem during
firmware download, only one reset will be attempted.

Signed-off-by: Chris Lu <chris.lu@mediatek.com>
---
 drivers/bluetooth/btmtk.c | 6 ++++++
 drivers/bluetooth/btmtk.h | 1 +
 2 files changed, 7 insertions(+)

diff --git a/drivers/bluetooth/btmtk.c b/drivers/bluetooth/btmtk.c
index 67db5a48c3e4..14e2f4100806 100644
--- a/drivers/bluetooth/btmtk.c
+++ b/drivers/bluetooth/btmtk.c
@@ -1344,6 +1344,9 @@ int btmtk_usb_setup(struct hci_dev *hdev)
 		err = btmtk_setup_firmware_79xx(hdev, fw_bin_name,
 						btmtk_usb_hci_wmt_sync);
 		if (err < 0) {
+			/* retry once if setup firmware error */
+			if (!test_and_set_bit(BTMTK_FIRMWARE_DL_RETRY, &btmtk_data->flags))
+				btmtk_reset_sync(hdev);
 			bt_dev_err(hdev, "Failed to set up firmware (%d)", err);
 			return err;
 		}
@@ -1371,6 +1374,9 @@ int btmtk_usb_setup(struct hci_dev *hdev)
 		hci_set_msft_opcode(hdev, 0xFD30);
 		hci_set_aosp_capable(hdev);
 
+		/* Clear BTMTK_FIRMWARE_DL_RETRY if setup successfully */
+		test_and_clear_bit(BTMTK_FIRMWARE_DL_RETRY, &btmtk_data->flags);
+
 		/* Set up ISO interface after protocol enabled */
 		if (test_bit(BTMTK_ISOPKT_OVER_INTR, &btmtk_data->flags)) {
 			if (!btmtk_usb_isointf_init(hdev))
diff --git a/drivers/bluetooth/btmtk.h b/drivers/bluetooth/btmtk.h
index 5df7c3296624..b9df2b8f0627 100644
--- a/drivers/bluetooth/btmtk.h
+++ b/drivers/bluetooth/btmtk.h
@@ -147,6 +147,7 @@ enum {
 	BTMTK_HW_RESET_ACTIVE,
 	BTMTK_ISOPKT_OVER_INTR,
 	BTMTK_ISOPKT_RUNNING,
+	BTMTK_FIRMWARE_DL_RETRY,
 };
 
 typedef int (*btmtk_reset_sync_func_t)(struct hci_dev *, void *);
-- 
2.45.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 0/3] Trigger reset if firmware status is abnormal when
  2026-02-03  6:25 [PATCH v1 0/3] Trigger reset if firmware status is abnormal when Chris Lu
                   ` (2 preceding siblings ...)
  2026-02-03  6:25 ` [PATCH v1 3/3] Bluetooth: btmtk: Add reset mechanism if downloading firmware failed Chris Lu
@ 2026-02-11 19:40 ` patchwork-bot+bluetooth
  3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+bluetooth @ 2026-02-11 19:40 UTC (permalink / raw)
  To: Chris Lu
  Cc: marcel, johan.hedberg, luiz.dentz, sean.wang, will-cy.Lee, ss.wu,
	steve.lee, linux-bluetooth, linux-kernel, linux-mediatek

Hello:

This series was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Tue, 3 Feb 2026 14:25:07 +0800 you wrote:
> When the device unexpectedly restarts during previous firmware
> download process, it can cause mt79xx firmware status to be
> abnormal in the next attempt. In this case, a reset should be
> performed to ensure everything starts afresh.
> 
> These changes include:
> 1. Optimizing the handling after the download function retry
>    is exhausted, a reset should be performed.
> 2. Another download firmware command also needs to check status
>    , and if an unexpected status occurs, trigger a reset.
> 3. Adding a flag "BTMTK_FIRMWARE_DL_RETRY": if download firmware
>    process enters the reset mechanism, this flag will be set.
>    After a successful setup, the flag will be cleared.
>    If the flag is already set, no further reset attempts will be
>    made to avoid endless reset retries.
> 
> [...]

Here is the summary with links:
  - [v1,1/3] Bluetooth: btmtk: improve mt79xx firmware setup retry flow
    https://git.kernel.org/bluetooth/bluetooth-next/c/9cc9fc9bff32
  - [v1,2/3] Bluetooth: btmtk: add status check in mt79xx firmware setup
    https://git.kernel.org/bluetooth/bluetooth-next/c/458b6d8b0108
  - [v1,3/3] Bluetooth: btmtk: Add reset mechanism if downloading firmware failed
    https://git.kernel.org/bluetooth/bluetooth-next/c/73130272a121

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-02-11 19:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-03  6:25 [PATCH v1 0/3] Trigger reset if firmware status is abnormal when Chris Lu
2026-02-03  6:25 ` [PATCH v1 1/3] Bluetooth: btmtk: improve mt79xx firmware setup retry flow Chris Lu
2026-02-03  6:25 ` [PATCH v1 2/3] Bluetooth: btmtk: add status check in mt79xx firmware setup Chris Lu
2026-02-03  6:25 ` [PATCH v1 3/3] Bluetooth: btmtk: Add reset mechanism if downloading firmware failed Chris Lu
2026-02-11 19:40 ` [PATCH v1 0/3] Trigger reset if firmware status is abnormal when patchwork-bot+bluetooth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox