Repository navigation
Bluetooth: hci_bcm4377: Fix resume stall and recover a dead controller - #167
Conversation
…esponding After some suspend-to-idle cycles on a BCM4388 (MacBook Pro 16" M2 Max), the controller no longer answers HCI commands. hci_resume_dev() times out on Set Event Mask (0x0c01), followed by Write Scan Enable, LE address resolution and scan parameter commands. Every later command times out as well, until the module is reloaded, which recovers it. Install an hdev->reset handler, which the HCI core calls on a command timeout, and recover the same way: rebind the driver with device_reprobe(), so probe resets the function and boots the firmware again. The work and its device reference are allocated separately because the reprobe frees bcm4377_data. Timeouts during setup are left alone, as are timeouts while a reprobe is already queued. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: RJ Skerry-Ryan <[email protected]> (cherry picked from commit 37e9742)
|
This seems like a hack and maybe there is a better solution. It works well for me on my M2 Max. |
bcm4377_suspend() and bcm4377_resume() write SLEEP_CONTROL and return without reading anything back, so the PCIe write can still be posted when the system enters suspend-to-idle, or when hci_resume_dev() starts sending commands. On a BCM4388 (MacBook Pro 16" M2 Max) about a quarter to half of all resumes then left the controller unresponsive: every resume command timed out, stalling resume by about 20 s. Read the register back after both writes. With a read-back in place, 8 of 8 resumes succeeded, including 10 and 20 minute sleeps. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: RJ Skerry-Ryan <[email protected]> (cherry picked from commit 4d662f9)
The driver has no hdev->wakeup callback, so the HCI core never offers HCI_CONN_FLAG_REMOTE_WAKEUP: bluetoothd's attempt to allow wakeup for a paired mouse fails with "Bad flag given (0x1) vs supported (0xe)", and suspend always disconnects without programming a wake filter. Report device_may_wakeup() as the wakeup state. When wakeup is enabled, keep the firmware running and the function in D0 through system sleep, and arm the interrupt for wakeup, so that a connection attempt or advertisement from a wake-allowed device wakes the system. Otherwise quiesce the firmware as before. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: RJ Skerry-Ryan <[email protected]> (cherry picked from commit 8f373b9)
|
Added The driver had no Tested on j416c: moving a paired MX Master 3S wakes the machine from s2idle, with no resume stall. Waking also needs the AIC/PCIe MSI |
Preserve the original review commits and retain subsequent published repairs where superseded. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Preserve the original review commits and retain subsequent published repairs where superseded. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
[follow-up to #167] Bluetooth: hci_bcm4377: drain recovery work before module exit Original contributor commits are preserved. Conflict resolutions retain the audited shared driver APIs and their integrated review fixes. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
After some suspend-to-idle cycles, the BCM4388 Bluetooth controller (MacBook Pro 16" M2 Max, j416c) stops answering HCI commands. Bluetooth devices can't reconnect until the module is reloaded.
What happens
hci_resume_dev()times out on its resume sequence: Set Event Mask (0x0c01), Write Scan Enable (0x0c1a), LE address resolution (0x202d) and scan parameters (0x2041), each with-110.Powered: yes.unexpected event for opcode …lines show replies arriving after the host gave up.modprobe -r hci_bcm4377 && modprobe hci_bcm4377recovers it.Change
Adds an
hdev->resethandler, which the HCI core calls on a command timeout. It recovers the way a module reload does: it rebinds the driver withdevice_reprobe(), so probe resets the function and boots the firmware again.btintel_pcieuses the same hook to recover by reprobing.pci_devreference are allocated separately, because the reprobe freesbcm4377_data.This recovers the controller; it doesn't prevent the failure. Why the firmware stops answering after some resumes is still unknown. A side effect: any single command timeout now causes a short Bluetooth reconnect.
Testing
7.1.12based on Thunderbolt: M1/M2 Pro display, M1 PCIe and resume recovery #8 plus this patch. Bluetooth mouse (MX Master 3S) connected across several s2idle cycles; after resume it reconnects on movement with no manual reload.checkpatch.pl --strictis clean, andhci_bcm4377.obuilds withW=1on this branch.Tested with the help of Claude Code.
Update: root cause fixed (
a30d9034bac, "Flush the sleep control writes").bcm4377_suspend()/bcm4377_resume()writeSLEEP_CONTROLand return without a read-back, so the posted write can still be in flight when the system enters s2idle, or whenhci_resume_dev()starts sending commands. Reading the register back after both writes stops the stall:PM_POST_SUSPENDnotifier runs inside the suspend syscall).bootstage 0x2,rti_status 0x2), so the firmware was never lost.The reprobe-on-timeout commit stays as a safety net. checkpatch
--strictclean;hci_bcm4377.obuilds withW=1onaurora-wip.