Skip to contentSkip to conversation

Bluetooth: hci_qca: Reprobe QCA6390 after hibernation

PATCH In review Nikolay Bryskin 3 participants 4 messages Oct 17 – Oct 25

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Bluetooth: hci_qca: Reprobe QCA6390 after hibernation

Without a way to power-cycle the SoC (no BT_EN GPIO and no power sequencer, e.g. the ACPI-enumerated QCA6390 on the Dell XPS 13 9310), HCI_QUIRK_NON_PERSISTENT_SETUP is not set and hdev->setup() runs only once, at probe, on the assumption that the SoC keeps its firmware.

Hibernation breaks that assumption: the platform powers the SoC off, and after the image is restored it is back in its ROM state. The driver's resume callback, shared with suspend-to-idle via SIMPLE_DEV_PM_OPS(), only clears QCA_SUSPENDING, so the first command times out and the controller stays unusable. Error recovery and power-cycling the adapter from userspace don't help either, because none of them run setup again:

Bluetooth: hci0: Opcode 0x0c01 failed: -110
Bluetooth: hci0: command 0x0c01 tx timeout
Bluetooth: hci0: crash the soc to collect controller dump
Bluetooth: hci0: Opcode 0x0c05 failed: -110
Bluetooth: hci0: Frame reassembly failed (-84)
...
Bluetooth: hci0: Opcode 0x0c03 failed: -110

Give the restore phase its own callback which, in this configuration, rebinds the driver so that probe downloads the firmware again. The rebind is done from a work item on system_freezable_wq, as it can't run from within a PM callback and it frees the qca_serdev the callback works on. All other sleep transitions keep their existing callbacks.

Rebinding works here because the SoC is in its ROM state after the restore. Rebinding while it still runs the downloaded firmware fails the same way a warm reboot used to before commit 7e7bbddd029b ("Bluetooth: hci_qca: Fix qca6390 enable failure after warm reboot"), which this patch doesn't change.

Tested on a Dell XPS 13 9310 (DLB16390): Bluetooth comes back about a second after resuming from hibernation, with no command timeouts. Suspend-to-idle is unaffected.

Fixes e5d6468fe9d8 ("Bluetooth: hci_qca: Add support for Qualcomm Bluetooth SoC QCA6390")
Assisted-by LLM
---
 drivers/bluetooth/hci_qca.c | 58 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 57 insertions(+), 1 deletion(-)
drivers/bluetooth/hci_qca.c +57 -1
index 7089e9b639b2..7bca14d364b9 100644
@@ -2775,7 +2775,63 @@ static int __maybe_unused qca_resume(struct device *dev)
 	return 0;
 }
 
-static SIMPLE_DEV_PM_OPS(qca_pm_ops, qca_suspend, qca_resume);
+struct qca_reprobe {
+	struct work_struct work;
+	struct device *dev;
+};
+
+static void qca_reprobe_work(struct work_struct *work)
+{
+	struct qca_reprobe *reprobe = container_of(work, struct qca_reprobe,
+						   work);
+	int ret;
+
+	ret = device_reprobe(reprobe->dev);
+	if (ret && ret != -EPROBE_DEFER)
+		dev_err(reprobe->dev, "Failed to reprobe device (error %d)\n",
+			ret);
+
+	put_device(reprobe->dev);
+	kfree(reprobe);
+}
+
+static int __maybe_unused qca_restore(struct device *dev)
+{
+	struct serdev_device *serdev = to_serdev_device(dev);
+	struct qca_serdev *qcadev = serdev_device_get_drvdata(serdev);
+	struct hci_uart *hu = &qcadev->serdev_hu;
+	struct qca_reprobe *reprobe;
+
+	qca_resume(dev);
+
+	/* Without power control hdev->setup() runs only once, at probe, as
+	 * the SoC is expected to keep its firmware. Hibernation powers the
+	 * SoC off, so rebind the driver to download the firmware again. The
+	 * rebind can't run from a PM callback, and qcadev is gone once it
+	 * does, so it gets a work item of its own.
+	 */
+	if (hci_test_quirk(hu->hdev, HCI_QUIRK_NON_PERSISTENT_SETUP))
+		return 0;
+
+	reprobe = kzalloc_obj(*reprobe);
+	if (!reprobe)
+		return -ENOMEM;
+
+	INIT_WORK(&reprobe->work, qca_reprobe_work);
+	reprobe->dev = get_device(dev);
+	queue_work(system_freezable_wq, &reprobe->work);
+
+	return 0;
+}
+
+static const struct dev_pm_ops qca_pm_ops = {
+	.suspend = pm_sleep_ptr(qca_suspend),
+	.resume = pm_sleep_ptr(qca_resume),
+	.freeze = pm_sleep_ptr(qca_suspend),
+	.thaw = pm_sleep_ptr(qca_resume),
+	.poweroff = pm_sleep_ptr(qca_suspend),
+	.restore = pm_sleep_ptr(qca_restore),
+};
 
 #ifdef CONFIG_OF
 static const struct of_device_id qca_bluetooth_of_match[] = {
Signature · 1 line
2.56.0
#1 lore raw

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/1188025/

---Test result---

Test Summary:

CheckPatch                    PASS      0.65 seconds
VerifyFixes                   PASS      0.07 seconds
VerifySignedoff               PASS      0.07 seconds
GitLint                       PASS      6.18 seconds
SubjectPrefix                 PASS      0.26 seconds
BuildKernel                   PASS      30.00 seconds
CheckAllWarning               PASS      34.61 seconds
CheckSparse                   PASS      37.13 seconds
BuildKernel32                 PASS      30.04 seconds
CheckKernelLLVM               PASS      34.22 seconds
TestRunnerSetup               PASS      719.60 seconds
IncrementalBuild              PASS      27.51 seconds

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

---
Regards,
Linux Bluetooth

#2 lore raw
In reply to Nikolay Bryskin

Hi Nikolay,

Quoted 4 lines · Nikolay Bryskin
drivers/bluetooth/hci_qca.c +4 -0
+static void qca_reprobe_work(struct work_struct *work)
+{
+	struct qca_reprobe *reprobe = container_of(work, struct qca_reprobe,
+						   work);

drivers/bluetooth/hci_qca.c static int __maybe_unused qca_resume(struct device *dev) · line 2796

Quoted 10 lines
drivers/bluetooth/hci_qca.c +10 -0
+	int ret;
+
+	ret = device_reprobe(reprobe->dev);
+	if (ret && ret != -EPROBE_DEFER)
+		dev_err(reprobe->dev, "Failed to reprobe device (error %d)\n",
+			ret);
+
+	put_device(reprobe->dev);
+	kfree(reprobe);
+}

This is the pattern hci_h5 and iwlwifi use today, and it has the same two problems, which the series at [1] addresses with a driver core helper, device_schedule_reprobe():

- qca_reprobe_work() lives in hci_uart.ko and nothing pins the module. The work runs from thaw for the whole re-probe, firmware download included, and an rmmod of hci_uart in that time frees the text it is executing as well as the lock class key INIT_WORK() placed in module data. On a lockdep kernel the latter ends in an oops; we reproduced that with the equivalent iwlwifi work.

- device_reprobe() runs whatever is bound by then, so an unbind between thaw and the work starting is undone.

With the helper the work item goes away entirely, and qca_restore() becomes:

static int __maybe_unused qca_restore(struct device *dev)

{
	struct serdev_device *serdev = to_serdev_device(dev);
	struct qca_serdev *qcadev = serdev_device_get_drvdata(serdev);
	struct hci_uart *hu = &qcadev->serdev_hu;

	qca_resume(dev);

	if (hci_test_quirk(hu->hdev, HCI_QUIRK_NON_PERSISTENT_SETUP))
		return 0;

	return device_schedule_reprobe(dev, 0);
}

It may be called from .restore with the device lock held, runs on system_freezable_wq as yours does, and its request is cancelled if the device is unbound, removed or its module unloaded before it runs.

Would you be fine basing your patch on it once it has landed?

[1] https://lore.kernel.org/all/[email protected]/

Cheers,

Daniel

#3 lore raw

Hi Daniel,

Quoted 1 line · Daniel Golle

Would you be fine basing your patch on it once it has landed?

Yes, thanks for the review. I'll send v2 on top of device_schedule_reprobe() once it has landed, with qca_restore() as you suggest.

I tried the combination in the meantime: v4 1/4 plus hci_qca converted as above, on 7.2.11 on a Dell XPS 13 9310 (QCA6390 on UART, no BT_EN GPIO). After resume from hibernation the reprobe ran, the firmware was downloaded again and Bluetooth worked; s2idle suspend did not trigger a reprobe. I've replied to 1/4 with a Tested-by.

Nikolay