Skip to content

wifi: brcmfmac: pcie: suppress ASPM L1 across s2idle on BCM4378 - #3970

Merged
DjDeveloperr merged 1 commit into
mainfrom
fix/bcm4378-s2idle-aspm-l1
Dec 2, 2026
Merged

DjDeveloperr merged 1 commit into
mainfrom
fix/bcm4378-s2idle-aspm-l1

Conversation

@sithglan

@sithglan sithglan commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What: Suppress PCIe ASPM L1 (and its L1SS substates) temporarily from brcmf_pcie_pm_prepare() through brcmf_pcie_pm_complete() on Apple-seeded BCM4378 (0x4425, M1 / T8103) s2idle sleeps via new pcie_aspm_sleep_disable() / pcie_aspm_sleep_restore() helpers in drivers/pci/pcie/aspm.c, fixing hard SoC resets on macOS 27.2 (26B123) BCM4378 firmware (18.20.511.0.7.8.207) while keeping runtime ASPM L1/L1SS/CLKPM power savings intact while awake.

Tested: J313 (MacBook Air M1, T8103, 27.2 26B123 firmware 18.20.511.0.7.8.207) exact-head 9b4f6882dd11 (7.3.0-j313-s2idle+, boot_id=4de5c0e5-7b1f-4ab3-a818-ed96b0706136): PASS — 10/10 real s2idle cycles via /dev/rtc1 (suspend_stats/success 0 -> 10, fail=0, zero manual sysfs workarounds), all 6 PCIe link PM flags (clkpm, l1_aspm, l1_1_aspm, l1_1_pcipm, l1_2_aspm, l1_2_pcipm) restored to 1 on 0000:01:00.{0,1} after every wake, wld0 up (3/3 gateway ping, 0% loss, 10.0 ms avg), 0 kernel BUG/Oops/WARN/AER/IOMMU/brcmfmac errors.

  • Pre-fix reproducer & isolation on J313 (7.3.0+, 9177b2d4, 27.2 firmware):
    • Reset on cycles 2–6 under both real s2idle and synchronous pm_test=devices (pm_async=0) whenever l1_aspm=1 (even with clkpm=0 and L1SS=0).
    • Passed 10/10 with brcmfmac unbound, 15/15 pm_test=devices and 10/10 real s2idle with l1_aspm=0 (clkpm=1), and 10/10 real s2idle with l1_aspm toggled only across sleep.
    • Cross-check on Mac mini M1 (J274, 7.3.0+, older May 2023 BCM4378 firmware 18.20.383.15.7.8.150): passed 10/10 real s2idle with wld0 connected and l1_aspm=1, confirming the trigger is specific to newer (27.2) BCM4378 firmware.
  • Host tests & style:
    • tools/asahi/run-host-tests.py --only brcmf-suspend: 16/16 PASS (including new s2idle-l1-prepare and s2idle-l1-complete mutations).
    • tools/asahi/run-host-tests.py --only pciec-policy: 1/1 PASS (all ASPM/L1SS policy + mutation checks).
    • ./scripts/checkpatch.pl --strict --git HEAD: 0 errors, 0 warnings, 0 checks.

Risk: two-way · Scoped strictly to PM_SUSPEND_TO_IDLE on Apple-seeded BCM4378 (0x4425) via link->aspm_sleep_disable (PCIE_LINK_STATE_L1), orthogonal to PCIE_LINK_STATE_L1SS deep-sleep suppression and preserving user aspm_disable/sysfs overrides; easily revertible.

Not yet: Live-tested on J293 (M1 MBP 13", also T8103 + BCM4378 on 27.2) or hibernation (PM_SUSPEND_MEM/disk, where brcmf_pcie_pm_prepare() is a no-op).

On Apple M1 (T8103) systems running macOS 27.2 (26B123) BCM4378 firmware
(18.20.511.0.7.8.207), allowing the BCM4378 PCIe link into ASPM L1 across
s2idle causes a hard SoC reset during synchronous device suspend/resume
(reproducible even under pm_test=devices and pm_async=0) while the radio
transitions through MPC with the function kept in D0. Disabling ASPM L1
permanently would forfeit runtime L1/L1SS power savings while awake.

Add pcie_aspm_sleep_disable() and pcie_aspm_sleep_restore() in the PCIe
ASPM core to temporarily mask ASPM states via link->aspm_sleep_disable
without altering link->aspm_disable, link->aspm_default, or sysfs
overrides. Also extend the L1SS restore/sync sleep-suppression checks so
suppressing PCIE_LINK_STATE_L1 consistently suppresses L1SS as well, and
update saved LNKCTL state across all downstream functions on the link.

Use these helpers from brcmf_pcie_pm_prepare() and brcmf_pcie_pm_complete()
for Apple-seeded BCM4378 s2idle sleeps so ASPM L1 (and L1SS) are cleared
before wiphy_suspend() / brcmf_pcie_s2idle_sleep() and restored cleanly
after brcmf_pcie_pm_leave_D3() / wiphy_resume(), keeping runtime ASPM
L1/L1SS/CLKPM savings intact while awake and leaving non-BCM4378 chips
and deeper sleeps unchanged.

Extend brcmf-suspend-tests with prepare/complete coverage and two
mutations (s2idle-l1-prepare, s2idle-l1-complete).

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
@sithglan
sithglan requested review from a team and DjDeveloperr as code owners December 2, 2026 17:25
@github-actions github-actions Bot added 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) 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 9b4f6882: ready to merge

Check Detail
CI at head ok no CI for this change (the hardware row is the gate)
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok in the PR body at 9b4f6882
Conflicts ok none
PR text ok Risk: two-way · Scoped strictly to PMSUSPENDTOIDLE on Apple-seeded BCM4378 (0x4425) via link->aspmsleepdisable (PCIELINKSTATEL1), orthogonal to PCIELINKSTATEL1SS deep-sleep suppression and preserving user aspmdisable/sysfs overrides; easily revertible.

Areas: area:gpu, area:wireless
Merge: gh pr merge 3970 --merge (Owners and Core through the bypass: add --admin).

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

@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. I read the whole change against main 2f5b01a, and it looks right.

What I checked:

  • Gating. prepare() acts only for an Apple-seeded BCM4378 (fwseed and device 0x4425) entering s2idle. Every other brcmfmac PCIe chip returns early, as do S3 and hibernation (where pm_suspend_target_state isn't PM_SUSPEND_TO_IDLE), and none of them touch ASPM. complete() acts only when prepare() set the flag.
  • Restore. Once prepare() succeeds, complete() runs on every path: a normal wake, a failed suspend callback and an aborted suspend. So L1 always comes back. remove() restores it too if the driver is unbound in between. If prepare() fails, the mask is rolled back and there's nothing to restore.
  • Fit with the existing s2idle path. The function stays in D0. brcmf_pcie_s2idle_sleep() saves config space after L1 is already off, so pci_restore_state() at resume writes L1 off and complete() turns it back on. The controller's L1SS sleep begin/end owns only the L1SS bit of aspm_sleep_disable. The new checks treat a suppressed L1 as suppressing L1SS too, so neither side can re-enable the other's state early. brcmfmac doesn't use runtime PM, so there's no interaction there.
  • Locking. The helpers take pci_bus_sem (read), then aspm_lock, then aspm_l1ss_hw_lock. That's the documented order, and it's the same pattern pci_disable_link_state() uses from probe. prepare() and complete() run in process context, so sleeping there is fine.
  • Non-wireless hunks. These are drivers/pci/pcie/aspm.c, include/linux/pci.h and the tools/asahi tests. There's no GPU code; the area:gpu label comes from the tools/asahi CODEOWNERS entry.

Local checks on the merge with main 2f5b01a (merge tree f0368f50), on an x86_64 build host:

  • arm64 LLVM (clang 23.1.3) make W=1 drivers/pci/pcie/aspm.o drivers/net/wireless/broadcom/brcm80211/brcmfmac/: rc 0, 0 warnings, 0 errors. All 36 brcmfmac objects and aspm.o were rebuilt with the W=1 flags.
  • scripts/checkpatch.pl --strict --git 9b4f6882dd11: 0 errors, 0 warnings, 0 checks.
  • tools/asahi/run-host-tests.py --only brcmf-suspend: 16/16 pass. --only pciec-policy: 1/1 pass.
  • Hosted CI hasn't run at this head yet (0 workflow runs).

Notes, none blocking:

  1. pci_update_aspm_saved_state() now runs on every function on the link instead of only function 0. That reaches every multi-function link, which means the Wi-Fi/Bluetooth combo on every Mac, not just BCM4378. I think the change is right: the code already writes LNKCTL on every function, so every saved copy should follow. But it makes this shared PCIe code, so it needs an s2idle row on one other generation before merge, as well as the T8103 row.
  2. The gate keys on the chip, not the firmware. So BCM4378 machines on older firmware, like the J274, also lose L1 during s2idle. That costs a little sleep power, which is fine for this fix.
  3. Small: the helpers' kernel-doc could say that they may sleep and must not be called with pci_bus_sem held.
  4. Small: aspm_sleep_disable is a bitmask, not a count. If the Bluetooth function on the same link ever used these helpers too, one restore would undo the other's suppression. With one user that's fine.

Hardware: the exact-head J313 row in the description covers the board. A J293 row at this head and a second-generation row are being lined up.

@joshuaswarren

Copy link
Copy Markdown
Contributor

J293 (13-inch MacBook Pro M1, T8103, 27.2 firmware) exact-head verification, kernel-only one-shot of 9b4f688 built on aarch64 with aurora_defconfig (release 7.3.0-lab-s2idle, boot_id 40493a79-…):

  • 1/1 s2idle cycle PASS: entered s2idle cleanly, slept 13m5s, woke on macsmc-input (key tap), 'PM: resume devices took 0.495 seconds', suspend_stats success 0→1, fail=0. Same boot_id across the cycle — resumed, no hard reset (the pre-fix failure mode on this box was a dead box needing VDM reset).
  • ASPM restored post-wake: LnkCtl 'ASPM L1 Enabled' on both 0000:01:00.0 (BCM4378) and 0000:01:00.1; L1 substates idle on the active link.
  • Wi-Fi functional post-wake: wlan0 re-associated to the AP, ssh/network recovered, nmcli shows connected.
  • Boot checks: root btrfs mounted, initramfs built from this tree's modules, 55 apple/brcm modules loaded.
  • Note: WoWLAN magic-packet bursts and wired-NIC traffic did not wake it; the input-event wake worked. That's a wake-source delivery matter, not the ASPM path this PR fixes — the hard-reset-on-sleep failure is gone.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) ready-to-merge Meets the merge policy: merge it (bot) labels Dec 2, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor

PASS J714s (M5 Pro, T6050) linux#3970 head 9b4f688 in composite b6002784 (main c2f1583 + #3410 465d7cf + #3334 7be3a9c + #3717 99fc90d + #3970 9b4f688, 7.3.0-m5-comp-3410-3970): Wi-Fi (wlp1s0f0, 3/3 0%-loss ping to gateway & Mini), BT (hci0 Powered: yes), and lspci -vv LnkCtl (ASPM Disabled, RCB 64B, LnkDisable- CommClk-) + L1SubCtl1 on 01:00.0/1/2 identical across pre-sleep, after-sleep-1, and after-sleep-2 (2x rtcwake -m mem -s 20), 0 faults/Oops/WARN/BUG, clean stock handback (b2c723cd).

@github-actions github-actions Bot added the ready-to-merge Meets the merge policy: merge it (bot) label Dec 2, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor

J773g (T8132 / M4 mini, BCM4388 control) exact-head 9b4f6882dd11 (9b4f6882dd11816017c8665a2440dac8db88523a): PASS (composite 7.3.0-j773g-comp-3410-3334 on main c2f1583e + #3410 + #3334 + #3717 + #3970 + #3799, merge tree 2d03eb2c7dbd, boot_id=edc6e272-ea87-4529-819a-b7d752dbe77f, panic=10, WDT 178 s).

  • s2idle (rtcwake -d /dev/rtc1 -m freeze -s 5): suspend_stats/success 0 -> 1, fail=0, DP-3 (3840x2160) and plasmalogin restored cleanly.
  • PCIe lspci -vv LnkCtl / LnkSta before vs after s2idle: Byte-identical across all 5 functions (00:00.0 ASPM L1 Enabled, 5GT/s x1, 00:02.0 ASPM L1 Enabled, 2.5GT/s x1, 01:00.0 BCM4388 Wi-Fi ASPM L1 Enabled, 5GT/s x1, 01:00.1 BCM4388 BT ASPM L1 Enabled, 5GT/s x1, 02:00.0 BCM57762 GbE ASPM L1 Enabled, 2.5GT/s x1).
  • Network / Wi-Fi: end0 wired GbE UP,LOWER_UP before and after; 01:00.0 is BCM4388 (non-4378 control; brcm/brcmfmac4388c2-pcie.bin not installed on rootfs).
  • Deep sleep (mem): Skipped (J773g OS FW 27.2 refuses mem deep sleep: apple-sleep 380700000.sleep-controller: no PCIe tunables for ANS: suspend-to-RAM with it stopped will be refused and 48ae00000.dcp: no firmware stop for a deep sleep).
  • Health: 0 DART faults, 0 WARN/BUG/Oops/SError, 0 failed systemd units.

@DjDeveloperr
DjDeveloperr merged commit 662680a into main Dec 2, 2026
1 check passed
@DjDeveloperr
DjDeveloperr deleted the fix/bcm4378-s2idle-aspm-l1 branch December 2, 2026 19:49
@DjDeveloperr

Copy link
Copy Markdown
Contributor

Post-merge host tests on merge commit 662680a (PR head 9b4f688; no hosted Host tests ran on this PR), in the aurora-linux-host-tests:ubuntu2404 container:

  • tools/asahi/run-host-tests.py --only brcmf-suspend: 16/16 passed. The base run passes 55 controls, and the new s2idle-l1-prepare and s2idle-l1-complete mutants are killed.
  • tools/asahi/run-host-tests.py --only pciec-policy: 1/1 passed (94 PASS lines, including 88 negative controls, 0 FAIL).

The 20 commits on main since the merge (up to ccb3d8b) don't touch these tests, the PR's kernel files, or their run-host-tests.py entries.

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) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants