2022-06-16 09:47:01

by Stephan Gerhold

[permalink] [raw]
Subject: [PATCH v2] Bluetooth: btqcomsmd: Fix command timeout after setting BD address

On most devices using the btqcomsmd driver (e.g. the DragonBoard 410c
and other devices based on the Qualcomm MSM8916/MSM8909/... SoCs)
the Bluetooth firmware seems to become unresponsive for a while after
setting the BD address. On recent kernel versions (at least 5.17+)
this often causes timeouts for subsequent commands, e.g. the HCI reset
sent by the Bluetooth core during initialization:

Bluetooth: hci0: Opcode 0x c03 failed: -110

Unfortunately this behavior does not seem to be documented anywhere.
Experimentation suggests that the minimum necessary delay to avoid
the problem is ~150us. However, to be sure add a sleep for > 1ms
in case it is a bit longer on other firmware versions.

Older kernel versions are likely also affected, although perhaps with
slightly different errors or less probability. Side effects can easily
hide the issue in most cases, e.g. unrelated incoming interrupts that
cause the necessary delay.

Fixes: 1511cc750c3d ("Bluetooth: Introduce Qualcomm WCNSS SMD based HCI driver")
Signed-off-by: Stephan Gerhold <[email protected]>
---
I tested this using a script that reboots repeatedly and checks for the
error. With this patch, BT shows up successfully for 100+ consecutive
boots. Without this patch it usually fails after 1-5 boots (or even
always on some boards).

Changes in v2:
- Clarify commit message: Add affected devices and kernel versions

v1: https://lore.kernel.org/linux-bluetooth/[email protected]/
---
drivers/bluetooth/btqcomsmd.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/bluetooth/btqcomsmd.c b/drivers/bluetooth/btqcomsmd.c
index 2acb719e596f..11c7e04bf394 100644
--- a/drivers/bluetooth/btqcomsmd.c
+++ b/drivers/bluetooth/btqcomsmd.c
@@ -122,6 +122,21 @@ static int btqcomsmd_setup(struct hci_dev *hdev)
return 0;
}

+static int btqcomsmd_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
+{
+ int ret;
+
+ ret = qca_set_bdaddr_rome(hdev, bdaddr);
+ if (ret)
+ return ret;
+
+ /* The firmware stops responding for a while after setting the bdaddr,
+ * causing timeouts for subsequent commands. Sleep a bit to avoid this.
+ */
+ usleep_range(1000, 10000);
+ return 0;
+}
+
static int btqcomsmd_probe(struct platform_device *pdev)
{
struct btqcomsmd *btq;
@@ -162,7 +177,7 @@ static int btqcomsmd_probe(struct platform_device *pdev)
hdev->close = btqcomsmd_close;
hdev->send = btqcomsmd_send;
hdev->setup = btqcomsmd_setup;
- hdev->set_bdaddr = qca_set_bdaddr_rome;
+ hdev->set_bdaddr = btqcomsmd_set_bdaddr;

ret = hci_register_dev(hdev);
if (ret < 0)
--
2.30.2


2022-06-16 10:10:36

by bluez.test.bot

[permalink] [raw]
Subject: RE: [v2] Bluetooth: btqcomsmd: Fix command timeout after setting BD address

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=650946

---Test result---

Test Summary:
CheckPatch PASS 0.90 seconds
GitLint FAIL 0.47 seconds
SubjectPrefix PASS 0.35 seconds
BuildKernel PASS 36.72 seconds
BuildKernel32 PASS 33.63 seconds
Incremental Build with patchesPASS 45.84 seconds
TestRunner: Setup PASS 577.07 seconds
TestRunner: l2cap-tester PASS 19.73 seconds
TestRunner: bnep-tester PASS 6.61 seconds
TestRunner: mgmt-tester PASS 118.63 seconds
TestRunner: rfcomm-tester PASS 11.13 seconds
TestRunner: sco-tester PASS 10.79 seconds
TestRunner: smp-tester PASS 10.38 seconds
TestRunner: userchan-tester PASS 7.18 seconds

Details
##############################
Test: GitLint - FAIL - 0.47 seconds
Run gitlint with rule in .gitlint
[v2] Bluetooth: btqcomsmd: Fix command timeout after setting BD address
32: B1 Line exceeds max length (101>80): "v1: https://lore.kernel.org/linux-bluetooth/[email protected]/"




---
Regards,
Linux Bluetooth