Repository navigation
wifi: brcmfmac: pcie: don't let a missing D3 ACK abort suspend - #371
Conversation
…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]>
|
[Joshua's agent] Review of the second commit, 8468760 (the first commit is #370), read offline against base b798f2b. This looks right to me.
Two optional notes:
|
scottjones
left a comment
There was a problem hiding this comment.
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.
-
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 = NULLbefore 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. -
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.
39d5f88
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_INFORMon every 4th suspend.brcmf_pcie_pm_enter_D3()then returns-EIOand the system suspend is aborted. Nothing resets the firmware afterwards, so every later suspend fails the same way until the module is reloaded.Change
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.D3_INFORMcould 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
b798f2bwith 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).7.2.11-labb798f2b0-4585j1105-104309-e433systemd-suspend.service)7.2.11-lab428772f0-1559j1105-104457-32c57.2.11-labc0e6d3fa-4ed7j1105-104639-fa1bWhat remains visible in the passing run:
brcmf_msgbuf_delete_flowring: timed out waiting for txstatuson most suspends. It comes from the same firmware behaviour, and it predates this change.The tested commits differ from this PR's commits only in the alignment of one continuation line in the #370 commit.
checkpatch.pl --strictis clean on this commit.Not tested:
-EIO);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