Skip to content

PCI: apple: disable L1SS around deep sleep and enable J313 CLKREQ - #3494

Merged
RyanTheTide merged 2 commits into
mainfrom
feat/t8103-pcie-l1ss-sleep
Nov 28, 2026
Merged

RyanTheTide merged 2 commits into
mainfrom
feat/t8103-pcie-l1ss-sleep

Conversation

@erikwb

@erikwb erikwb commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

What: Disable PCIe L1 PM Substates (L1SS) around deep sleep on conventional Apple PCIe reinit hosts in drivers/pci/controller/pcie-apple.c and enable supports-clkreq on J313 port00 (arch/arm64/boot/dts/apple/t8103-j313.dts) so J313 negotiates PCIe ASPM L1.1/L1.2 and Clock PM without hitting a watchdog reset on deep sleep entry. This is part 1 of the split requested on #3221 (driver-local + J313 DT only; zero PCI core changes).

Tested: J313 (M1, T8103) at a90a2bfab82d (default kernel command line, pcie_aspm policy default): 00:00.0/01:00.0 negotiate ASPM L1, ClockPM+, PCI-PM_L1.1/L1.2+, ASPM_L1.1/L1.2+, T_PwrOn=6us; 1x s2idle and 2x deep S2R cycles pass with full L1SS/ASPM/ClockPM restoration, Wi-Fi recovery (0% packet loss), and zero Oops/BUG/WARN/SError. Host test suites (pciec-policy-tests.py, radio-{pm,sleep-fence,sleep-power,sleep-snapshot}-tests.py, binding-lifetime-tests.py), ARCH=arm64 LLVM=1 W=1 CONFIG_PCIE_APPLE=m builds (CONFIG_PCIEASPM=y and =n), W=1 CHECK_DTBS=y, and checkpatch.pl --strict all pass.

Risk: two-way door · affects J313 (enables supports-clkreq on port00, enabling Clock PM and L1SS) and conventional Apple PCIe reinit hosts during deep sleep (drivers/pci/controller/pcie-apple.c only; tunneled, managed-SID, PIODMA-supplier, and root-bus-only hosts are untouched).

Not yet: Other T8103 Macs (J274/J293/J456/J457) intentionally remain without supports-clkreq pending per-board verification; shared PCI core ASPM sleep suppression and deferred D0 PCI-PM recheck are split into the follow-up PR stacked on this branch.

Details

Why this is driver-local and does not use pci_disable_link_state() / pci_enable_link_state_locked()

  1. pci_disable_link_state() mutates persistent link->aspm_disable policy state and requires a matching pci_enable_link_state_locked() caller, which cannot cleanly restore a link whose CONFIG_PCIEASPM=n or firmware-inherited L1SS state was not enabled by the ASPM core, and does not save/restore PCI_L1SS_CTL2 / PCI_L1SS_CTL1 timing fields across a full controller power-loss reinit (PWREN/PERST# cycle).
  2. drivers/pci/controller/pcie-apple.c therefore handles deep-sleep L1SS teardown and restoration locally on conventional reinit hosts (apple_pcie_s2r_reinit(pcie) when pm_suspend_target_state is neither PM_SUSPEND_TO_IDLE nor PM_SUSPEND_ON):
    • In .prepare(), pins runtime PM on all L1SS links and drains in-flight runtime-PM transitions via pm_runtime_barrier() outside PCI locks (repeating in a bounded 8-pass loop if hotplug enumerates a new L1SS link while locks are dropped, returning -EBUSY on exhaustion), then holds pci_lock_rescan_remove() continuously into the clear walk.
    • Disables ASPM downstream-first before clearing PCI_L1SS_CTL1 child-first, then restores Link Control ASPM; rolls back all earlier links on partial error.
    • In .suspend(), re-walks all attached L1SS links under pci_lock_rescan_remove() to catch any L1SS bits replayed between .prepare() and .suspend(), restoring Link Control ASPM on write failure and propagating config read errors.
    • In .complete(), restores saved PCI_L1SS_CTL2 and PCI_L1SS_CTL1 timing fields (clearing live enable bits first, masking PCI-PM L1.1/L1.2 when either end is not in PCI_D0, preserving live resume-time Link Control ASPM policy, unwinding child-first on partial enable failure, and retrying a one-shot Link Control restore failure on both parent and downstream functions) before releasing the runtime-PM pins.
    • Cleans up saved records and runtime-PM pins on remove/cleanup paths.
  3. The DT commit adds supports-clkreq; strictly to arch/arm64/boot/dts/apple/t8103-j313.dts &port00, matching the board's ADT clkreq wiring.
Evidence

Commits

  • 4f3e0d247ff0 PCI: apple: disable L1SS around deep sleep on reinit hosts
  • a90a2bfab82d arm64: dts: apple: t8103-j313: enable CLKREQ on PCIe port00

J313 (M1, T8103) hardware verification at a90a2bfab82d

  • Command line: default (root=UUID=... rw rootflags=subvol=root plymouth.ignore-serial-consoles user4k=on loglevel=4 console=tty0), pcie_aspm policy [default].
  • Boot log:
    • pci 0000:01:00.0: ASPM: default states L1 ASPM-L1.1 ASPM-L1.2 PCI-PM-L1.1 PCI-PM-L1.2
  • lspci -vvv pre-sleep, post-s2idle (rtcwake -d rtc1 -m freeze -s 8), post-deep mux: apple-display-crossbar: replace the T602x selector fields instead of OR-ing them #1, and post-deep drm/apple: release a stale DPTX link before borrowing a Type-C route #2 (rtcwake -d rtc1 -m mem -s 8):
    • 00:00.0: LnkCtl: ASPM L1 Enabled; RCB 64 bytes, LnkDisable- CommClk+, L1SubCtl1: PCI-PM_L1.2+ PCI-PM_L1.1+ ASPM_L1.2+ ASPM_L1.1+, L1SubCtl2: T_PwrOn=6us
    • 01:00.0: LnkCtl: ASPM L1 Enabled; ... ClockPM+, L1SubCtl1: PCI-PM_L1.2+ PCI-PM_L1.1+ ASPM_L1.2+ ASPM_L1.1+, L1SubCtl2: T_PwrOn=6us
    • 01:00.1: LnkCtl: ASPM L1 Enabled; RCB 64 bytes, LnkDisable- CommClk+
  • Deep sleep link reinit logged cleanly on both deep cycles (S2R: /soc/pcie@690000000/pci@0,0 lost its link, setting it up again -> link back, PWREN and PERST# cycled as at probe); Wi-Fi gateway ping 0% loss after every cycle (2.5-5.3 ms); zero Oops/BUG/WARNING/SError/L1SS restore warnings.

Build, DTB, lint, and host tests at a90a2bfab82d

  • ARCH=arm64 LLVM=1 W=1 drivers/pci/controller/pcie-apple.o + full vmlinux + modules + modpost with CONFIG_PCIE_APPLE=m in both CONFIG_PCIEASPM=y and CONFIG_PCIEASPM=n: 0 warnings, 0 errors.
  • W=1 CHECK_DTBS=y on apple/{t8103-j313,t8103-j274,t8103-j293,t8103-j456,t8103-j457,t6050-j716c}.dtb: clean (0 new warnings on PCIe/CLKREQ).
  • ./scripts/checkpatch.pl --strict --git 61e791b30687..a90a2bfab82d: 0 errors, 0 warnings, 0 checks; git diff --check: clean.
  • Host test suites: tools/asahi/pciec-policy-tests.py (43/43 positive + negative controls), radio-pm-tests.py, radio-sleep-fence-tests.py, radio-sleep-power-tests.py, radio-sleep-snapshot-tests.py, binding-lifetime-tests.py (3/3): all PASS.

On conventional Apple PCIe hosts whose links are reinitialized after
deep sleep (apple_pcie_s2r_reinit()), leaving PCI-PM/ASPM L1.1/L1.2
substates enabled while endpoints enter D3hot lets the link drop into
L1.2 (CLKREQ# deasserted) ahead of the sleep commit, causing a WDT2
reset during deep sleep on T8103.

Clear L1SS per physical link in apple_pcie_prepare() for non-s2idle
sleeps (after clearing ASPM across all downstream functions and the
root port in PCIe spec order, with checked config accesses and full
unwind on failure), re-check in apple_pcie_suspend() before
suspend_noirq in case a D3hot endpoint was runtime-resumed during
pci_pm_suspend() and replayed saved L1SS bits, and restore the saved
L1SS configuration in apple_pcie_complete() after wake. Leave s2idle
untouched.

Why pci_disable_link_state() / pci_enable_link_state_locked() are not
used directly for this temporary sleep window: in
drivers/pci/pcie/aspm.c, __pci_disable_link_state() sets bits in
link->aspm_disable persistently (pcie_config_aspm_link() masks against
~link->aspm_disable), while __pci_enable_link_state() neither clears
link->aspm_disable nor preserves link->aspm_default (it overwrites
link->aspm_default = pci_calc_aspm_enable_mask(state), clobbering
prior DT, policy, and sysfs settings). In addition, pci_walk_bus()
already holds pci_bus_sem for read, and unmanaged links
(pcie_aspm=off, absent link_state, or CONFIG_PCIEASPM=n) still need
checked hardware teardown and restore.

During restoration, hold pci_lock_rescan_remove(), verify the saved
link endpoints are still attached and not disconnected before touching
config space, clear live L1SS enable bits before writing CTL2 and saved
timing fields, mask PCI-PM L1.1/L1.2 whenever either end of the link is
not in PCI_D0, and unwind L1SS child-first on any partial enable write
failure so parent and child never end up asymmetric.

Save each link's original PCI_EXP_LNKCTL (root port and all downstream
functions) in struct apple_pcie_hib_l1ss before clearing ASPM so a
one-shot failure on the ASPM restore write does not leave rollback
rereading the cleared Link Control register and dropping ASPM. Merge
the saved ASPM bits only when unwinding a failed prepare() via
apple_pcie_hib_restore_l1ss(pcie, true); normal completion in
apple_pcie_complete() restores L1SS while preserving whatever ASPM
configuration the PCI core selected during resume.

Wire the production L1SS helpers into tools/asahi/pciec-policy-tests.py
and test s2idle bypass, suspend replay re-clear, normal completion ASPM
preservation, live CTL1 clear before timing writes, D3hot PCI-PM
masking, topology locking and removed-link skipping, one-shot ASPM and
child CTL1 failure unwinds, and negative controls.

Signed-off-by: Erik Bourget <[email protected]>
Enable supports-clkreq on J313 port00 (matching pci-bridge0's
function-clkreq GPIO in the J313 ADT) so PCIe Clock PM and L1.1/L1.2
substates activate by default on the BCM4378 Wi-Fi/BT link.

Measured on J313 (M1 MacBook Air, T8103): saves 167 mW Screen-ON
(118 mW Clock PM + 49 mW L1SS) and 292-330 mW combined with Wi-Fi
power save at DPMS-OFF, while deep sleep resumes cleanly with L1SS
restored.

Keep supports-clkreq scoped to t8103-j313.dts for now so other T8103
boards (J274, J293, J456, J457) remain untouched until matching ADT
function-clkreq evidence or board verification is available.

Signed-off-by: Erik Bourget <[email protected]>

@RyanTheTide RyanTheTide 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 at a90a2bf: approve. Merge once CI is green and one regression row from a second Mac generation is in (requested below).

Blockers: none.

Checked:

  • The split matches what #3221's review asked for: pcie-apple.c and the J313 dts only, with no PCI core changes. The ASPM-core rationale is in the commit message. The dts change is limited to J313 port00, so the other T8103 boards keep their current behaviour.
  • Relative to main, the new code only runs when apple_pcie_s2r_reinit() is true and the target is deep. A Mac with no L1SS-enabled link pins nothing in .prepare(), and .suspend() and .complete() find empty lists, so on the boards this PR does not enable it should do nothing. However, it runs in the deep-sleep path of every non-tunneled host, which is why I'm asking for a row from a second generation.
  • On error, .prepare() unwinds apple_radio_prepare() and releases the pinned runtime PM. After 8 hotplug retries it returns -EBUSY, which aborts the sleep instead of entering it with L1SS still enabled.

Regression row: we'll run our M1 Pro (T6000, deep sleep, no supports-clkreq) at this head: default cmdline, 1x s2idle + 2x deep, Wi-Fi after resume, 0 new warn/err. That proves the change does nothing on boards without CLKREQ.

Evidence
  • Diff checked against main at fetch time: 2 commits, drivers/pci/controller/pcie-apple.c +688/-4, t8103-j313.dts +4, tools/asahi/pciec-policy-tests.py.
  • Gate: apple_pcie_s2r_reinit() = !tunneled && !managed_sids && !piodma_supplier && !root_bus_only.
  • Author's J313 row is in the PR body.

@RyanTheTide

Copy link
Copy Markdown
Contributor

a90a2bfab82d J316s (M1 Pro, T6000, no supports-clkreq no-op proof; combined guarded one-shot 7.3.0-aurora-pr3468-3494+ with byte-identical PR files on exact default fleet89 cmdline) PASS: tools/asahi/pciec-policy-tests.py PASS (all policy + negative controls); pcie-apple 590000000.pcie probed cleanly; lspci -vv ASPM/L1SS state across 00:00.0/00:01.0/01:00.0 (BCM4387)/01:00.1/02:00.0 (GL9755) (ASPM L1 Enabled, L1SubCtl1 all -) 0-byte diff vs fleet89 baseline and 0-byte diff across s2idle 2/2 (15s /dev/rtc1; mem_sleep=[s2idle], deep not exposed on T6000); Wi-Fi 10.1.1.1 ping 3/3 (0% loss) pre-sleep and after each resume; Borealis VK api.smoke 8/8 pre/post; Enforcing, 0 AVC denials, 0 failed systemd units (systemctl --failed empty), 0 new pcie-apple/PCI warnings or errors; cleanly restored to saved 7.3.0-aurora-fleet89.

@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) area:platform Area from CODEOWNERS (bot) door:two-way Revertible or not, from Merge risk (bot) labels Nov 28, 2026
@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Merge readiness at a90a2bfa: not ready yet

Check Detail
CI at head running running: KUnit macsmc, KUnit clpc, KUnit apple-spmi-nvmem, KUnit trusted-keys
Review ok approved by RyanTheTide
Requested changes ok none
Hardware row at head ok in the PR body at a90a2bfa
Conflicts ok none
PR text ok Risk: two-way · affects J313 (enables supports-clkreq on port00, enabling Clock PM and L1SS) and conventional Apple PCIe reinit hosts during deep sleep (drivers/pci/controller/pcie-apple.c only; tunneled, managed-SID, PIODMA-supplier, and root-bus-only hosts are untouched).

Areas: area:gpu, area:platform

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

@RyanTheTide
RyanTheTide merged commit d95848a into main Nov 28, 2026
22 of 23 checks passed
@RyanTheTide
RyanTheTide deleted the feat/t8103-pcie-l1ss-sleep branch November 28, 2026 15:58
erikwb added a commit that referenced this pull request Nov 28, 2026
Forward-merge main (62675fa, including merged #3494) into
feat/pci-aspm-l1ss-sleep-core (b886f11 -> HEAD) with zero conflicts.
All eight PR-modified files under drivers/pci/, include/linux/pci.h,
and tools/asahi/pciec-policy-tests.py remain byte-identical to
a90a2bf..b886f11.

Signed-off-by: Erik Bourget <[email protected]>
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:platform Area from CODEOWNERS (bot) door:two-way Revertible or not, from Merge risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants