Skip to content

wifi: brcmfmac: pcie: don't let a missing D3 ACK abort suspend - #371

Merged
scottjones merged 2 commits into
omacom:integration/aurorafrom
malik-na:pr/brcmfmac-d3-recovery
Nov 14, 2026
Merged

scottjones merged 2 commits into
omacom:integration/aurorafrom
malik-na:pr/brcmfmac-d3-recovery

Conversation

@malik-na

@malik-na malik-na commented Nov 5, 2026

Copy link
Copy Markdown
Member

Stacked on #370. This branch contains #370's commit; please review only the second commit, "don't let a missing D3 ACK abort suspend". I'll rebase it once #370 lands.

On a MacBook Air (M1, 2020, J313) with BCM4378 and PCIe ASPM L1.1/L1.2 on the Wi-Fi link, the firmware does not acknowledge D3_INFORM on every 4th suspend. brcmf_pcie_pm_enter_D3() then returns -EIO and the system suspend is aborted. Nothing resets the firmware afterwards, so every later suspend fails the same way until the module is reloaded.

Change

  • Port upstream 6f88e6e ("wifi: brcmfmac: Improve D3 substate entering timeout handling"): a missing ACK is fatal only with WoWL armed, because otherwise nothing needs the dongle's state across the suspend.
  • Upstream relies on the device being powered off and re-probed on resume. In s2idle on Apple silicon the chip stays powered, so brcmf_pcie_pm_leave_D3() would find the interrupt mask still set, take the hot path, and carry on with firmware that did not acknowledge. The missed ACK is now recorded, and resume takes the cold path (remove and probe, reloading the firmware) instead.
  • The missed ACK is still logged at error level, so these recoveries stay visible.
  • Also: skip the wait when D3_INFORM could not be sent, and return early from both PM callbacks when a failed reload left no bus behind.

Testing

Suspend stress through maclab on a MacBook Air (M1, 2020, J313), using lab builds from this tree at b798f2b with the Mac's own config. Each ran 15 cycles of 25 s s2idle (woken by a timer) with Wi-Fi traffic in between, with ASPM L1.1/L1.2 on the Wi-Fi link (powersupersave, L1.2 timing as macOS programs it).

Kernel Job Result
unpatched 7.2.11-labb798f2b0-4585 j1105-104309-e433 D3 timeout on the 4th suspend, suspend aborted; omarchy-m-test regressed (failed systemd-suspend.service)
#370 only 7.2.11-lab428772f0-1559 j1105-104457-32c5 the same, on the 4th suspend
#370 + this 7.2.11-labc0e6d3fa-4ed7 j1105-104639-fa1b 15/15 suspends. D3 was not acknowledged on suspends 4, 8 and 12; each resumed through a firmware reload, and Wi-Fi reconnected by itself. omarchy-m-test 0 regressed

What remains visible in the passing run:

  • The "D3_INFORM not acknowledged, reloading firmware on resume" line, three times.
  • brcmf_msgbuf_delete_flowring: timed out waiting for txstatus on most suspends. It comes from the same firmware behaviour, and it predates this change.
  • After each reload, the next cycle's ping loss rose to 9-15% while the link came back.

The tested commits differ from this PR's commits only in the alignment of one continuation line in the #370 commit. checkpatch.pl --strict is clean on this commit.

Not tested:

  • WoWL armed (that path is unchanged and still returns -EIO);
  • a reload that fails on resume (the new early returns cover it, untested);
  • other brcmfmac chips and other Apple Silicon machines.

The root cause, the firmware missing the D3 handshake with L1 substates on, is not fixed here. Until it is, the M1 this was found on turns L1.1/L1.2 off only across suspend, from userspace. With that, it ran 15/15 on the installed kernel without a single reload.

🤖 Generated with Claude Code

…dler

brcmf_pcie_quick_check_isr() masks the dongle with
brcmf_pcie_intr_disable() whenever mailboxint reads non-zero.  Since
commit f04be34 ("wifi: brcmfmac: Do not service msgbuf IRQs until
ready in MSI mode") that helper also clears irq_ready, and the threaded
handler services the rings only while irq_ready is set.  The thread
therefore skips brcmf_proto_msgbuf_rx_trigger() for exactly the
interrupts the hard handler caught with mailboxint still set, and then
sets irq_ready again on its way out.

In MSI mode the firmware clears mailboxint itself, so whether the hard
handler sees it set is a race.  When it does, completions that arrived
with that interrupt stay in the D2H rings until a later interrupt.  On
firmware that sends mailbox data over the control ring (no
BRCMF_PCIE_SHARED_USE_MAILBOX) that includes the D3 ACK, and ioctl
responses: brcmf_msgbuf_query_dcmd_len() and brcmf_pcie_pm_enter_D3()
then time out, the latter aborting system suspend.  On a MacBook Air (M1)
with BCM4378 this became frequent with PCIe ASPM L1.2 enabled.  In INTx
mode the hard handler always clears irq_ready first, so the rings are
never serviced at all.

Let the hard handler mask the dongle without touching irq_ready, and let
the thread unmask without setting it, so irq_ready is controlled only by
the code that sets the rings up and tears them down.

Fixes: f04be34 ("wifi: brcmfmac: Do not service msgbuf IRQs until ready in MSI mode")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Naeem Malik <[email protected]>
When the firmware does not acknowledge D3_INFORM, brcmf_pcie_pm_enter_D3()
returns -EIO and the system suspend is aborted.  Nothing resets the
firmware afterwards, so every later suspend fails the same way until the
module is reloaded.

Port the upstream change that treats the timeout as fatal only with WoWL
armed, since otherwise nothing needs the dongle's state across the
suspend.  Upstream relies on the device being powered off and re-probed
on resume.  When the chip stays powered instead (as in s2idle on Apple
silicon), brcmf_pcie_pm_leave_D3() finds the interrupt mask still set and
takes the hot path, carrying on with firmware that did not acknowledge.
Record the missed ACK and take the cold path (remove and probe, reloading
the firmware) on resume.  The missed ACK is logged at error level, as
before, so these recoveries stay visible.

Also skip the wait when D3_INFORM could not be sent, and return early
from both callbacks when a failed reload left no bus behind.

Link: https://git.kernel.org/torvalds/c/6f88e6ebdc1a
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Naeem Malik <[email protected]>
@joshuaswarren

Copy link
Copy Markdown

[Joshua's agent] Review of the second commit, 8468760 (the first commit is #370), read offline against base b798f2b. This looks right to me.

  • The WoWL branch matches upstream 6f88e6e line for line.
  • Adding d3_ack_missed to force the cold path on s2idle, where the chip stays powered, is the extension this needs. Without it, the old intmask != 0 hot-path test would resume on dead firmware.
  • The flag's lifetime is safe, because the cold path frees devinfo and re-probes it.
  • The NULL drvdata guards are needed after a failed reload.

Two optional notes:

  1. With WoWL armed, the same firmware miss still returns -EIO (pcie.c:3092-3096). The PR says that path is unchanged and untested, which matches upstream.
  2. The new skip-the-wait branch turns a failed D3_INFORM send into continue-and-reload. If a suspend arrives while an earlier reload's async firmware load is still running, leave_D3's cold path can call brcmf_pcie_remove() during that load. That hazard already exists in the cold path; this change makes it a little easier to reach. I haven't traced it fully.

Merge order: #370 first, then #371 rebases to one commit.

@scottjones scottjones left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, thanks Naeem. Not letting a missed D3 ACK abort suspend is the right call, and the change holds up.

I reviewed 8468760 on top of #370's 3a936ed. The WoWL branch matches upstream 6f88e6e. Keeping the missed ACK at error level rather than upstream's debug level makes sense here, since every one of these is now a firmware reload.

The d3_ack_missed flag is needed on Apple Silicon. In s2idle the chip keeps power, so without the flag leave_D3 would see intmask set and hot-resume firmware that never acknowledged D3. The flag can't go stale, because the cold path frees devinfo and probe allocates a fresh one. Ioctls issued while the cold path tears the interface down fail fast because the bus is still DOWN, so I don't see a resume hang. It also doesn't make the mailboxmask-before-irq_ready ordering from #370 any worse: it adds no new intr_enable call, and it sends the missed-ACK case to the cold path rather than the hot path.

It builds clean with the shipped omarchy-pkgs config plus asahi.config (compile-check --per-commit, no new W=1 warnings), and check-commits and checkpatch are clean. The brcmfmac host suites pass, but none of them touch the D3 paths, so the maclab run in the description is the only test of this change.

Two follow-ups. Both are optional, neither blocks the merge, and a separate PR is fine. The first is the one I think is worth doing.

  1. This PR now sends running firmware down the cold path. Before, a missed ACK aborted the suspend, so leave_D3 only went cold when the chip had lost power or D0_INFORM failed to send. Now it goes cold on every missed ACK, which was 3 of 15 cycles in your run. leave_D3 sets devinfo->ci to NULL before brcmf_pcie_remove(), so remove skips both intr_disable and the chip reset, and frees the rings while the dongle can still DMA into them. The impact is low: bus mastering goes off a few calls later in pci_disable_device(), probe resets the chip within milliseconds, and the shipped config uses strict DART invalidation, so a late write should fault rather than land in freed memory. Booting with iommu.strict=0 would remove that last protection. The simplest fix is to skip brcmf_chip_detach(ci); ci = NULL before remove when d3_ack_missed is set, since the chip still has power. Then remove's own intr_disable and reset run, and probe attaches again anyway.

  2. The new NULL checks only cover a reload that fails before probe sets drvdata. That covers the realistic failures: a wedged chip fails in chip_attach before drvdata is set, and an async setup failure goes through device_release_driver(), which clears it. What's left is brcmf_pcie_probe failing after dev_set_drvdata(), which in practice means an allocation failure. Then the fail_brcmf and fail_bus paths free bus but leave drvdata pointing at it. leave_D3 calls probe directly rather than through the driver core, so nothing clears it, and the next suspend or an unbind would use freed memory. This was already true before the PR. Clearing drvdata in probe's failure path would make the guards hold for every failure.

The race with an async firmware load that was already raised here is real but rare, and the old cold path has it too.

@scottjones
scottjones added this pull request to the merge queue Nov 14, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to invalid changes in the merge commit Nov 14, 2026
@scottjones
scottjones added this pull request to the merge queue Nov 14, 2026
Merged via the queue into omacom:integration/aurora with commit 39d5f88 Nov 14, 2026
25 of 27 checks passed
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.

3 participants