public inbox for linux-bluetooth@vger.kernel.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; 6+ 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] 6+ 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  7:48   ` Trigger reset if firmware status is abnormal when bluez.test.bot
  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, 1 reply; 6+ 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] 6+ 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; 6+ 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] 6+ 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; 6+ 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] 6+ messages in thread

* RE: Trigger reset if firmware status is abnormal when
  2026-02-03  6:25 ` [PATCH v1 1/3] Bluetooth: btmtk: improve mt79xx firmware setup retry flow Chris Lu
@ 2026-02-03  7:48   ` bluez.test.bot
  0 siblings, 0 replies; 6+ messages in thread
From: bluez.test.bot @ 2026-02-03  7:48 UTC (permalink / raw)
  To: linux-bluetooth, chris.lu

[-- Attachment #1: Type: text/plain, Size: 5245 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1050104

---Test result---

Test Summary:
CheckPatch                    PENDING   0.34 seconds
GitLint                       PENDING   0.29 seconds
SubjectPrefix                 PASS      0.35 seconds
BuildKernel                   PASS      28.39 seconds
CheckAllWarning               PASS      29.50 seconds
CheckSparse                   WARNING   33.43 seconds
BuildKernel32                 PASS      26.24 seconds
TestRunnerSetup               PASS      569.51 seconds
TestRunner_l2cap-tester       PASS      29.22 seconds
TestRunner_iso-tester         FAIL      85.43 seconds
TestRunner_bnep-tester        PASS      6.51 seconds
TestRunner_mgmt-tester        FAIL      115.40 seconds
TestRunner_rfcomm-tester      PASS      9.87 seconds
TestRunner_sco-tester         FAIL      14.96 seconds
TestRunner_ioctl-tester       PASS      10.51 seconds
TestRunner_mesh-tester        FAIL      12.47 seconds
TestRunner_smp-tester         PASS      8.77 seconds
TestRunner_userchan-tester    PASS      6.84 seconds
IncrementalBuild              PENDING   0.76 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: CheckSparse - WARNING
Desc: Run sparse tool with linux kernel
Output:
drivers/bluetooth/btmtk.c:1507:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1508:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1509:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1510:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1511:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1511:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1512:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1513:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1514:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1515:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1516:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1517:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1507:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1508:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1509:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1510:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1511:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1511:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1512:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1513:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1514:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1515:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1516:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1517:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1507:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1508:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1509:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1510:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1511:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1511:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1512:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1513:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1514:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1515:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1516:1: error: bad constant expressiondrivers/bluetooth/btmtk.c:1517:1: error: bad constant expression
##############################
Test: TestRunner_iso-tester - FAIL
Desc: Run iso-tester with test-runner
Output:
BUG: KASAN: slab-use-after-free in le_read_features_complete+0x7e/0x2b0
Total: 141, Passed: 141 (100.0%), Failed: 0, Not Run: 0
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 494, Passed: 489 (99.0%), Failed: 1, Not Run: 4

Failed Test Cases
Read Exp Feature - Success                           Failed       0.108 seconds
##############################
Test: TestRunner_sco-tester - FAIL
Desc: Run sco-tester with test-runner
Output:
WARNING: possible circular locking dependency detected
BUG: sleeping function called from invalid context at net/core/sock.c:3782
Total: 30, Passed: 30 (100.0%), Failed: 0, Not Run: 0
##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner
Output:
Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0

Failed Test Cases
Mesh - Send cancel - 1                               Timed out    2.624 seconds
Mesh - Send cancel - 2                               Timed out    1.992 seconds
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:



---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 6+ 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; 6+ 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] 6+ messages in thread

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

Thread overview: 6+ 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  7:48   ` Trigger reset if firmware status is abnormal when bluez.test.bot
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