Skip to content

Bluetooth: hci_bcm4377: Fix resume stall and recover a dead controller - #167

Merged
RyanTheTide merged 3 commits into
aurora-silicon:aurora-wipfrom
rryan:bcm4377-reprobe
Oct 8, 2026
Merged

RyanTheTide merged 3 commits into
aurora-silicon:aurora-wipfrom
rryan:bcm4377-reprobe

Conversation

@rryan

@rryan rryan commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

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.
  • Every later command times out too. The controller was still dead 2 h later, with Powered: yes.
  • Late unexpected event for opcode … lines show replies arriving after the host gave up.
  • Not every resume hits it. It's also older than the Thunderbolt series: a kernel based on drm/apple: support independent dual dock DP streams on J414s #46 logged 315 timeouts over 11 suspends.
  • modprobe -r hci_bcm4377 && modprobe hci_bcm4377 recovers it.

Change

Adds an hdev->reset handler, which the HCI core calls on a command timeout. It recovers the way a module reload does: it rebinds the driver with device_reprobe(), so probe resets the function and boots the firmware again. btintel_pcie uses the same hook to recover by reprobing.

  • The work item and its pci_dev reference are allocated separately, because the reprobe frees bcm4377_data.
  • Timeouts during setup are ignored, so a failing probe can't loop.
  • Only one reprobe is queued at a time.

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

  • j416c, 7.1.12 based 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.
  • I haven't yet captured a wake in the log where the bug occurred and the reset handler fired, so that path isn't shown in a log yet.
  • checkpatch.pl --strict is clean, and hci_bcm4377.o builds with W=1 on this branch.

Tested with the help of Claude Code.


Update: root cause fixed (a30d9034bac, "Flush the sleep control writes"). bcm4377_suspend()/bcm4377_resume() write SLEEP_CONTROL and return without a read-back, so the posted write can still be in flight when the system enters s2idle, or when hci_resume_dev() starts sending commands. Reading the register back after both writes stops the stall:

  • Before: 1–2 of every 4 resumes stalled ~20 s (every resume command timed out; the session stays frozen because the PM_POST_SUSPEND notifier runs inside the suspend syscall).
  • After: 14/14 clean resumes on j416c, including 10 and 20 minute sleeps (8 on an instrumented kernel, 6 with only this patch). Firmware state read around sleep was unchanged (bootstage 0x2, rti_status 0x2), so the firmware was never lost.

The reprobe-on-timeout commit stays as a safety net. checkpatch --strict clean; hci_bcm4377.o builds with W=1 on aurora-wip.

…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)
@rryan

rryan commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

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)
@rryan rryan changed the title Bluetooth: hci_bcm4377: Rebind the driver when the controller stops responding Bluetooth: hci_bcm4377: Fix resume stall and recover a dead controller Oct 3, 2026
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)
@rryan

rryan commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Added Bluetooth: hci_bcm4377: Support remote wakeup.

The driver had no hdev->wakeup, so the HCI core never offered HCI_CONN_FLAG_REMOTE_WAKEUP (bluetoothd: Bad flag given (0x1) vs supported (0xe)) and suspend always disconnected. It now reports device_may_wakeup(); with wakeup enabled the firmware stays running, the function stays in D0, and its interrupt is armed for wakeup. With wakeup disabled, sleep behaves as before.

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 irq_set_wake support, which isn't in this PR: rryan@5dc581a87d6 on j416c-pr8. Without it, enable_irq_wake() fails and this falls back to a running controller that can't wake the system.

@RyanTheTide
RyanTheTide merged commit 883e58b into aurora-silicon:aurora-wip Oct 8, 2026
RyanTheTide added a commit that referenced this pull request Oct 8, 2026
Preserve the original review commits and retain subsequent published repairs where superseded.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
RyanTheTide added a commit that referenced this pull request Oct 8, 2026
Preserve the original review commits and retain subsequent published repairs where superseded.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
RyanTheTide added a commit that referenced this pull request Oct 8, 2026
[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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants