Skip to content

wifi: brcmfmac: pcie: guard D3 suspend IRQ and verify device presence before resume BAR0 read - #3951

Open
IronsideXXVI wants to merge 2 commits into
aurora-silicon:mainfrom
IronsideXXVI:j604-brcmfmac-d3-resume-bar0-guard
Open

IronsideXXVI wants to merge 2 commits into
aurora-silicon:mainfrom
IronsideXXVI:j604-brcmfmac-d3-resume-bar0-guard

Conversation

@IronsideXXVI

Copy link
Copy Markdown
Contributor

What: Guard brcmfmac PCIe D3 suspend/resume against spurious MSIs and absent-endpoint BAR0 reads in drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c:

  1. In brcmf_pcie_pm_enter_D3(), set devinfo->d3_suspended, drain any in-flight IRQ handler via synchronize_irq(devinfo->pdev->irq), and mask mailboxmask via brcmf_pcie_intr_disable() (leaving intmask intact for hot-resume detection).
  2. In brcmf_pcie_quick_check_isr(), return IRQ_NONE immediately while READ_ONCE(devinfo->d3_suspended) is true so replayed/spurious MSIs during suspend/resume do not read BAR0 while the link is down.
  3. In brcmf_pcie_pm_leave_D3(), verify pci_device_is_present(devinfo->pdev) before clearing d3_suspended or reading BAR0 + 0x2000 (intmask), returning -ENODEV cleanly (and notifying apple_radio_sleep_endpoint_resumed(dev, -ENODEV)) instead of triggering an asynchronous fabric SError when a host PCIe port fails to relink after deep sleep.

Tested:

  • Offline on aurora-silicon/linux main (bf2931e57045, branch j604-brcmfmac-d3-resume-bar0-guard, commit 80d19d66bb11):
    • scripts/checkpatch.pl --strict: 0 errors, 0 warnings, 0 checks (40 lines checked).
    • Clang 18.1.8 ARM64 LLVM=1 W=1: drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.o 0 warnings (728096 bytes).
  • Full-kernel release build (linux-aurora 7.3.0.aurora1-1.1685, commit 89d82de1c143): 0 compiler warnings in brcmfmac/pcie.c, ARM64 QEMU KUnit 202/202 passed.
  • Live Apple M4 MacBook Pro 14" (J604, T8132) hardware verification (linux-aurora 1.1685, boot b650c46a): 1/1 deep-sleep suspend/resume wake passed (rc=0, 0 SErrors, 0 kernel faults), alongside 0 PMP events (600 s idle window), 33.5 C idle thermal gate, and 1582.7 fps ProRes decode gate.

Risk: two-way door · brcmfmac PCIe (drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c, +16 / -0 lines) — s2idle D0 / WoWLAN early-return paths in brcmf_pcie_pm_enter_D3() and brcmf_pcie_pm_leave_D3() return before touching d3_suspended, normal deep-sleep wakes where pci_device_is_present() is true clear d3_suspended and proceed identically, and a plain revert restores prior behavior.

Not yet:

  • Full 10-cycle repeated deep-sleep soak on 1.1685 (queued next after the 1/1 deep-sleep wake pass), plus a hardware boot + deep-sleep/s2idle row at this exact main (bf2931e57045) head (80d19d66bb11) on T8132 and a second brcmfmac Mac.
Details and verification

Scope (j604-brcmfmac-d3-resume-bar0-guard, head 80d19d66bb11 on main bf2931e57045)

  • drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c (+16 / -0)
  • Sign-off: Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
  • scripts/checkpatch.pl --strict: 0 errors, 0 warnings, 0 checks (40 lines checked).
  • Clang 18.1.8 ARM64 LLVM=1 W=1: drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.o 0 warnings (728096 bytes).

Mechanism summary

  • On Apple Silicon, an MMIO read to a downstream PCIe BAR whose link failed to retrain triggers an asynchronous fabric SError (fatal on the host).
  • During deep-sleep D3 transitions, guarding brcmf_pcie_quick_check_isr() with d3_suspended, draining in-flight IRQs via synchronize_irq() and masking mailboxmask in pm_enter_D3(), and verifying pci_device_is_present() before clearing d3_suspended or reading intmask (BAR0 + 0x2000) in pm_leave_D3() ensures an unlinked endpoint degrades cleanly to -ENODEV without faulting the fabric.

@IronsideXXVI
IronsideXXVI requested review from a team as code owners December 2, 2026 14:58
@github-actions github-actions Bot added area:wireless Area from CODEOWNERS (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Merge readiness at d2dcb0af: not ready yet

Check Detail
CI at head ok 1 check passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head no no line with the head SHA d2dcb0af, a Mac and a result in the PR body or a comment
Conflicts ok none
PR text ok Risk: two-way · brcmfmac PCIe (drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c, +16 / -0 lines) — s2idle D0 / WoWLAN early-return paths in brcmfpciepmenterD3() and brcmfpciepmleaveD3() return before touching d3suspended, normal deep-sleep wakes where pcideviceispresent() is true clear d3suspended and proceed identically, and a plain revert restores prior behavior.

Areas: area:gpu, area:wireless

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verdict: FINISH, then merge at 80d19d6

Blockers:

  1. Wait for the approved Actions CI runs (host-tests, pr-text, readiness) to complete green at 80d19d66bb11.
  2. Post an exact-head 80d19d66bb11 hardware deep-sleep + s2idle row (and a second brcmfmac Mac control row, per merge policy §1/§3 — currently listed under Not yet).

Checked:

  • Audited the full 16-line diff in drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c at 80d19d66bb11: no code blockers found.
  • Setting d3_suspended before synchronize_irq() and brcmf_pcie_intr_disable() in brcmf_pcie_pm_enter_D3() (after the WoWLAN and s2idle_d0 early returns) drains any in-flight ISR and blocks spurious MSIs from reading BAR0 in brcmf_pcie_quick_check_isr() while the link is down.
  • Checking pci_device_is_present() in brcmf_pcie_pm_leave_D3() before clearing d3_suspended or reading intmask avoids an asynchronous fabric SError on a failed relink and cleanly reports -ENODEV to apple_radio_sleep_endpoint_resumed(). On hot resume, brcmf_pcie_intr_enable() restores irq_ready and unmasks interrupts; on cold reprobe, a fresh devinfo starts with d3_suspended = false.
  • Non-blocking note: clearing d3_suspended = false after confirming intmask != 0 (just before brcmf_pcie_intr_enable()) would also keep d3_suspended set if pm_leave_D3() takes the apple_radio_sleep_owned() -EUCLEAN early return without reprobing.

@github-actions github-actions Bot added the changes-requested A reviewer requested changes (bot) label Dec 2, 2026
@satchlj

satchlj commented Dec 2, 2026

Copy link
Copy Markdown
Member

Host tests (46908912600) failed on brcmf-suspend-tests.py and brcmfmac-sleep-lifetime-tests.py, which extract brcmf_pcie_pm_enter_D3() / brcmf_pcie_pm_leave_D3() from pcie.c:

  • struct bcmrf_pciedev_info / struct brcmf_pciedev_info stub is missing bool d3_suspended (and irq_allocated if not already present)
  • missing stubs for synchronize_irq(), brcmf_pcie_intr_disable(), and pci_device_is_present()

Updating those two host test harnesses (and covering pci_device_is_present() == false returning -ENODEV without touching BAR0) will make host-tests green.

@github-actions github-actions Bot added the ci-failing A check failed at the PR head (bot) label Dec 2, 2026
… before resume BAR0 read

If the PCIe host port fails to relink after deep sleep, reading
BAR0 + 0x2000 (intmask) in brcmf_pcie_pm_leave_D3() or handling a
replayed/spurious MSI in brcmf_pcie_quick_check_isr() while the link is
down triggers an asynchronous fabric SError on Apple Silicon.

- In brcmf_pcie_pm_enter_D3(), set devinfo->d3_suspended, drain any
  in-flight IRQ handler via synchronize_irq(), and mask mailboxmask
  via brcmf_pcie_intr_disable() while leaving intmask intact for
  hot-resume detection.
- Short-circuit brcmf_pcie_quick_check_isr() while d3_suspended is set.
- In brcmf_pcie_pm_leave_D3(), verify pci_device_is_present() before
  reading BAR0 + 0x2000 (intmask), returning -ENODEV cleanly (and
  reporting -ENODEV to apple_radio_sleep_endpoint_resumed()) if the
  endpoint is absent, and clear d3_suspended only on hot resume right
  before brcmf_pcie_intr_enable() so -ENODEV and owned-sleep -EUCLEAN
  early returns keep d3_suspended armed.
- Update the brcmf-suspend-tests.py and brcmfmac-sleep-lifetime-tests.c
  host test harnesses with the new fields/stubs and add controls and
  mutations covering D3 ISR gating, absent-endpoint -ENODEV without BAR0
  reads, and owned-sleep -EUCLEAN retention of d3_suspended.

Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
@IronsideXXVI
IronsideXXVI force-pushed the j604-brcmfmac-d3-resume-bar0-guard branch from 80d19d6 to f61003b Compare December 2, 2026 16:02
@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

Thanks for catching both host-test harness failures and for the review note on d3_suspended placement! Pushed updated head f61003b58813:

  • Updated drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c to clear WRITE_ONCE(devinfo->d3_suspended, false) right before brcmf_pcie_intr_enable(devinfo) on hot resume, so both the absent-endpoint -ENODEV path and the owned-sleep -EUCLEAN early return keep d3_suspended set.
  • Updated tools/asahi/brcmfmac-sleep-lifetime-tests.c with struct pci_dev, pdev/d3_suspended/irq_allocated fields, WRITE_ONCE, synchronize_irq(), and brcmf_pcie_intr_disable().
  • Updated tools/asahi/brcmf-suspend-tests.py (and registered the new mutations in tools/asahi/run-host-tests.py) with d3_suspended, synchronize_irq(), brcmf_pcie_intr_disable(), pci_device_is_present(), brcmf_pcie_quick_check_isr() extraction, and controls/mutations (d3-absent-bar0, d3-isr-guard, d3-euclean-clear) verifying:
    • D3 suspend sets d3_suspended before synchronize_irq(), masks interrupts, and short-circuits brcmf_pcie_quick_check_isr() without reading BAR0 (cleared on hot resume).
    • pci_device_is_present() == false on D3 resume returns -ENODEV with zero BAR0 reads, reports -ENODEV to apple_radio_sleep_endpoint_resumed(), and keeps d3_suspended set.
    • Owned-sleep -EUCLEAN early return without reprobing keeps d3_suspended set.

Local verification at f61003b58813:

  • scripts/checkpatch.pl --strict: 0 errors, 0 warnings, 0 checks (259 lines checked)
  • Clang 18.1.8 ARM64 LLVM=1 W=1: drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.o — 0 warnings, 0 errors
  • python3 -I tools/asahi/brcmf-suspend-tests.py: 53/53 controls passed
  • python3 -I tools/asahi/brcmfmac-sleep-lifetime-tests.py: production + 5/5 mutations passed
  • python3 -I tools/asahi/run-host-tests.py --only brcmf: 93/93 passed (including all 16 brcmf-suspend-tests mutations)

@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) needs-hw-row No hardware row at the PR head (bot) and removed changes-requested A reviewer requested changes (bot) ci-failing A check failed at the PR head (bot) labels Dec 2, 2026
@satchlj

satchlj commented Dec 2, 2026

Copy link
Copy Markdown
Member

Code, updated d3_suspended placement, and new brcmf-suspend-tests / brcmfmac-sleep-lifetime-tests controls + mutations at f61003b58813 look clean, and host-tests / pr-text / readiness are all green. Ready to approve once an exact-head hardware row at f61003b58813 is posted.

@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

Quick J604 (Mac16,1, M4 MacBook Pro 14", T8132, OS FW 27.2 / 26B123) soak update:

  • On our integrated J604 kernel (linux-aurora-next 1.1686, head 1e959da5e66c, carrying commit 89d82de1c143), a full 10/10 deep-sleep (10x 600 s rtcwake -m mem) + 10/10 s2idle (10x 300 s) soak passed with 10/10 Wi-Fi recovery (1.35 s median on deep wake, 1.3 s on s2idle), 0 SErrors, 0 L2C/kernel/GPU faults, and 0 resets.
  • For full transparency: that soak was on our integrated kernel (which still had the initial d3_suspended placement before the intmask read, alongside soc: apple: sleep: fix APCIe auto-PM teardown and BUSY-latch lowering #3950's sleep.c change and a pcie-apple.c relink guard), not yet a standalone build at exact head f61003b58813 (which moves d3_suspended = false right before brcmf_pcie_intr_enable()). I will run and post a standalone exact-head f61003b58813 deep-sleep + s2idle row on J604 next to clear the exact-head requirement.

@github-actions github-actions Bot added merge-conflict Conflicts with the base branch (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Dec 2, 2026
@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

Forward-merged main (b924bf47f0c9, including 9b4f6882dd11 BCM4378 s2idle ASPM L1 suppression) into j604-brcmfmac-d3-resume-bar0-guard (d2dcb0af97d9, no force-push) to clear the merge conflicts in tools/asahi/brcmf-suspend-tests.py and tools/asahi/run-host-tests.py. drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c merged cleanly with no functional changes.

Local verification at d2dcb0af97d9:

  • scripts/checkpatch.pl --strict on diff vs main: 0 errors, 0 warnings, 0 checks (259 lines checked)
  • Clang 18.1.8 ARM64 LLVM=1 W=1: drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.o — 0 warnings, 0 errors
  • python3 -I tools/asahi/brcmf-suspend-tests.py: 58/58 controls passed
  • python3 -I tools/asahi/brcmfmac-sleep-lifetime-tests.py: production + 5/5 mutations passed
  • python3 -I tools/asahi/run-host-tests.py --only brcmf-suspend: 19/19 passed (including both s2idle-l1-* and d3-* mutations)
  • python3 -I tools/asahi/run-host-tests.py --only brcmfmac-sleep-lifetime: 1/1 passed

Next: standalone exact-head hardware row at d2dcb0af97d9 on J604.

@github-actions github-actions Bot removed the merge-conflict Conflicts with the base branch (bot) label Dec 2, 2026
@github-actions github-actions Bot added the needs-hw-row No hardware row at the PR head (bot) label Dec 2, 2026

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict: the code is fine at d2dcb0af97d9. Merge once the two hardware results below are in. I'm not approving yet only because they are missing.

Forward merge: clean. The pcie.c change is line for line the one at f61003b5, and nothing from main is removed. The branch tree is exactly b924bf47 plus the four PR files. The BCM4378 s2idle L1 suppression (prepare/complete/remove) is intact. The result also merges cleanly into main 5fe340ac (tree 42a56ca0); later main commits don't touch these files.

Still needed (blocking):

  1. J604 deep sleep + s2idle on this head, with Wi-Fi back after each wake and one modprobe -r brcmfmac / modprobe brcmfmac at the end. The 10/10 soak is good support, but it ran the earlier flag placement next to other sleep changes.
  2. A second brcmfmac Mac of another generation, same steps. Best is an M1 with the BCM4378 (T8103, where deep sleep is offered); a T6040 MacBook Pro also works. Please enable dyndbg for brcmf_pcie_pm_* or note whether the wake was a hot resume or a reprobe.

Not blocking, a follow-up is fine (main faults at the first wake in these cases, so nothing here is a regression):

  • After an absent-device wake the driver stays bound, and the next step still touches the dead link. s2idle masks over BAR0 (pcie.c:3593) and its wake marks the bus up while the ISR is still gated. Deep sleep sends HOST_D3_INFORM (:3659). modprobe -r runs brcmf_pcie_reset_device(). An early return in brcmf_pcie_pm_enter_D3() while d3_suspended is set would cover both sleeps (keep the last good saved config: a fresh pci_save_state() would store all-ones).
  • brcmf_pcie_reset() reuses the same devinfo, so clear d3_suspended in brcmf_pcie_request_irq(). Otherwise a reset after a failed wake comes back with its interrupts ignored.
  • On the J713, a reported -ENODEV ends in apple_radio_terminal() (a panic), as -EUCLEAN already does. The "degrades cleanly" wording holds for the other boards.
  • The PR body still describes 80d19d66 (flag cleared before the intmask read); update it with the new result.
What I ran and read

Run on the merge tree 42a56ca0 (no hardware):

  • arm64 clang W=1 of drivers/net/wireless/broadcom/brcm80211/brcmfmac/ (BRCMDBG=y): 0 warnings.
  • checkpatch.pl --strict: 0/0/0 on the commit and on the net diff.
  • run-host-tests.py --only brcm 95/95, --only bcm4377 13/13, in the CI container image.

Read:

  • BCM4378/4387/4388 (and 4355/4364/4377) all set fw_seed, so s2idle keeps the function in D0 and returns before the new code; WoWLAN too. Only deep sleep and hibernation use it.
  • Suspend order is right: flag, drain, then mask, so no thread can unmask afterwards. intmask and mailboxmask are separate registers in both layouts. A failed D0_INFORM still goes through remove/probe with a fresh devinfo.
  • The presence check is one config read, which the PCI core already does in its noirq resume.

Hosted Host tests and pr-text are waiting for approval at this head.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: MERGE at d2dcb0a

Checked: D3 entry guards new IRQ arrivals before draining in-flight handlers, then masks interrupts while BAR access is still valid. Resume checks presence before the first BAR read and restores IRQ admission on the successful retained path. The D0 s2idle return paths remain separate. I ran the exact production-backed host suite and all 58 controls passed.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving at d2dcb0af97d9. The code is the same as in my review of this head, where only the rows were missing, and I found nothing that has to change. My follow-up notes there still stand and don't block this.

What I checked again

  • Suspend sets the flag, waits for the running handler, then masks the dongle, so nothing can unmask afterwards. A suspend that fails after that goes through the hot resume, which clears the flag.
  • Resume checks the device before its first register read. The flag is cleared only on a hot resume; a reprobe starts with new state.
  • s2idle (device left in D0) and WoWLAN return before the new code, so only deep sleep and hibernation use it.
  • It merges cleanly on main dc4d6f065001 and brcmfmac/pcie.o compiles there (arm64, GCC, W=1, no warnings).

Rows still owed before merge

  1. J604: deep sleep and s2idle at this head, Wi-Fi back after each wake, one module reload at the end.
  2. A second generation. Our J516s (M3 Pro, T6030) and J773g (M4 mini, T8132) both drive a BCM4388 with brcmfmac, and this head is in our next kernel for them. J516s can be the second generation if its deep sleep wakes; J773g adds the suspend/resume path with pm_test=devices. An M1 (BCM4378) or a T6040 MacBook Pro row counts as well.

Please update the PR body: it still describes the older flag placement.

@github-actions github-actions Bot removed the needs-review No approving review from Core or Omarchy Mac yet (bot) label Dec 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) area:wireless Area from CODEOWNERS (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants