Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: hci_ll: download the init script at the operating speed
@ 2026-11-22  5:12 EMCP333 via B4 Relay
  2026-11-22  9:31 ` bluez.test.bot
  0 siblings, 1 reply; 2+ messages in thread
From: EMCP333 via B4 Relay @ 2026-11-22  5:12 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz
  Cc: linux-bluetooth, linux-kernel, EMCP333

From: EMCP333 <emcp@enser.io>

ll_setup() downloads the TI init script at the 115200 init speed and only
then moves both ends to max-speed. TI's own user-mode init manager does
it the other way round: HCI_VS_Update_UART_HCI_Baudrate first, then the
script at speed. For a WL18xx script (TIInit_12.8.32.bts, 293 commands)
that is the difference between ~6 s and under 1 s.

The length of that window is not only a boot-time cost. On a Tegra Note 7
(WL18xx on a Tegra 114 hsuart, max-speed 3000000) the 6 s download
overlaps the WLAN core's bring-up on the same chip, and one script
command -- 0xfd82, the first after the PHY post patch -- then gets no
answer. Every cold boot logs

    command 0xfd82 tx timeout
    download firmware failed, retrying...

and the retry, with WLAN up and idle, passes. Bluetooth is ready ~35 s
after boot. With the WLAN driver blacklisted the same command answers
first time in ~140 ms. With this change the script completes 0.86 s
after hci_uart loads, with no retry, on two cold boots; the controller
then runs at 3 Mbaud and scans, and WLAN is unaffected.

Send the speed change after every BT_EN toggle, because that resets the
controller to its ROM default. If the speed change or a download at
speed fails, the remaining attempts fall back to the previous order:
script at the init speed, then the speed change. Setups whose max-speed
equals the init speed are unchanged.

Tested on the Tegra Note 7 on a next-20260422-based kernel. Not tested:
the fallback path, and controllers other than WL18xx.

The code and this changelog were prepared with the help of an AI coding
assistant. The submitter has reviewed both and takes responsibility for
them.

Signed-off-by: EMCP333 <emcp@enser.io>
---
 drivers/bluetooth/hci_ll.c | 71 ++++++++++++++++++++++++++++++++--------------
 1 file changed, 50 insertions(+), 21 deletions(-)

diff --git a/drivers/bluetooth/hci_ll.c b/drivers/bluetooth/hci_ll.c
index 3c9d98eebc..8dffe5f219 100644
--- a/drivers/bluetooth/hci_ll.c
+++ b/drivers/bluetooth/hci_ll.c
@@ -608,11 +608,27 @@ static int ll_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
 	return PTR_ERR_OR_ZERO(skb);
 }
 
+/* Ask the controller to move to @speed, then follow it on the host side. */
+static int ll_set_oper_speed(struct hci_uart *hu, u32 speed)
+{
+	__le32 speed_le = cpu_to_le32(speed);
+	struct sk_buff *skb;
+
+	skb = __hci_cmd_sync(hu->hdev, HCI_VS_UPDATE_UART_HCI_BAUDRATE,
+			     sizeof(speed_le), &speed_le, HCI_INIT_TIMEOUT);
+	if (IS_ERR(skb))
+		return PTR_ERR(skb);
+	kfree_skb(skb);
+	serdev_device_set_baudrate(hu->serdev, speed);
+	return 0;
+}
+
 static int ll_setup(struct hci_uart *hu)
 {
 	int err, retry = 3;
 	struct ll_device *lldev;
 	struct serdev_device *serdev = hu->serdev;
+	bool at_speed;
 	u32 speed;
 
 	if (!serdev)
@@ -624,6 +640,23 @@ static int ll_setup(struct hci_uart *hu)
 
 	serdev_device_set_flow_control(serdev, true);
 
+	/* Operational speed if any */
+	if (hu->oper_speed)
+		speed = hu->oper_speed;
+	else if (hu->proto->oper_speed)
+		speed = hu->proto->oper_speed;
+	else
+		speed = 0;
+
+	/*
+	 * Download the init script at the operating speed, as TI's own
+	 * user-mode init manager does. At the init speed a WL18xx script
+	 * takes ~6 s, long enough to overlap the WLAN core's bring-up on the
+	 * same chip. If anything fails at speed, the remaining attempts use
+	 * the init speed.
+	 */
+	at_speed = speed && speed != hu->init_speed;
+
 	do {
 		/* Reset the Bluetooth device */
 		gpiod_set_value_cansleep(lldev->enable_gpio, 0);
@@ -636,12 +669,26 @@ static int ll_setup(struct hci_uart *hu)
 			return err;
 		}
 
+		/* BT_EN just reset the controller to its ROM default speed */
+		serdev_device_set_baudrate(serdev, hu->init_speed);
+		if (at_speed) {
+			err = ll_set_oper_speed(hu, speed);
+			if (err) {
+				bt_dev_warn(hu->hdev, "speed change before download failed (%d)",
+					    err);
+				at_speed = false;
+				serdev_device_set_baudrate(serdev, hu->init_speed);
+			}
+		}
+
 		err = download_firmware(lldev);
 		if (!err)
 			break;
 
 		/* Toggle BT_EN and retry */
-		bt_dev_err(hu->hdev, "download firmware failed, retrying...");
+		bt_dev_err(hu->hdev, "download firmware failed%s, retrying...",
+			   at_speed ? " at operating speed" : "");
+		at_speed = false;
 	} while (retry--);
 
 	if (err)
@@ -663,26 +710,8 @@ static int ll_setup(struct hci_uart *hu)
 		hci_set_quirk(hu->hdev,
 			      HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN);
 
-	/* Operational speed if any */
-	if (hu->oper_speed)
-		speed = hu->oper_speed;
-	else if (hu->proto->oper_speed)
-		speed = hu->proto->oper_speed;
-	else
-		speed = 0;
-
-	if (speed) {
-		__le32 speed_le = cpu_to_le32(speed);
-		struct sk_buff *skb;
-
-		skb = __hci_cmd_sync(hu->hdev, HCI_VS_UPDATE_UART_HCI_BAUDRATE,
-				     sizeof(speed_le), &speed_le,
-				     HCI_INIT_TIMEOUT);
-		if (!IS_ERR(skb)) {
-			kfree_skb(skb);
-			serdev_device_set_baudrate(serdev, speed);
-		}
-	}
+	if (speed && !at_speed)
+		ll_set_oper_speed(hu, speed);
 
 	return 0;
 }

---
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
change-id: 20261122-b4-hci-ll-oper-speed-e0346b764fff

Best regards,
--  
EMCP333 <emcp@enser.io>



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

* RE: Bluetooth: hci_ll: download the init script at the operating speed
  2026-11-22  5:12 [PATCH] Bluetooth: hci_ll: download the init script at the operating speed EMCP333 via B4 Relay
@ 2026-11-22  9:31 ` bluez.test.bot
  0 siblings, 0 replies; 2+ messages in thread
From: bluez.test.bot @ 2026-11-22  9:31 UTC (permalink / raw)
  To: linux-bluetooth, emcp

[-- Attachment #1: Type: text/plain, Size: 1218 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/series/1218434/

---Test result---

Test Summary:
CheckPatch                    PASS      0.42 seconds
VerifyFixes                   PASS      0.06 seconds
VerifySignedoff               PASS      0.05 seconds
GitLint                       FAIL      0.16 seconds
SubjectPrefix                 PASS      0.05 seconds
BuildKernel                   PASS      20.00 seconds
CheckAllWarning               PASS      23.75 seconds
CheckSparse                   PASS      25.57 seconds
BuildKernel32                 PASS      20.98 seconds
CheckKernelLLVM               PASS      22.81 seconds
TestRunnerSetup               PASS      495.77 seconds
IncrementalBuild              PASS      19.37 seconds

Details
##############################
Test: GitLint - FAIL
Desc: Run gitlint
Output:
Bluetooth: hci_ll: download the init script at the operating speed

50: B2 Line has trailing whitespace: "--  "


https://github.com/bluez/bluetooth-next/pull/1178

---
Regards,
Linux Bluetooth


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

end of thread, other threads:[~2026-11-22  9:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22  5:12 [PATCH] Bluetooth: hci_ll: download the init script at the operating speed EMCP333 via B4 Relay
2026-11-22  9:31 ` bluez.test.bot

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