Repository navigation
PCI: apple: disable L1SS around deep sleep and enable J313 CLKREQ - #3494
Conversation
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
left a comment
There was a problem hiding this comment.
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.cand the J313 dts only, with no PCI core changes. The ASPM-core rationale is in the commit message. The dts change is limited to J313port00, so the other T8103 boards keep their current behaviour. - Relative to
main, the new code only runs whenapple_pcie_s2r_reinit()is true and the target isdeep. 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()unwindsapple_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
mainat 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.
|
|
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
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]>
What: Disable PCIe L1 PM Substates (L1SS) around deep sleep on conventional Apple PCIe reinit hosts in
drivers/pci/controller/pcie-apple.cand enablesupports-clkreqon J313port00(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_aspmpolicydefault):00:00.0/01:00.0negotiate ASPM L1,ClockPM+,PCI-PM_L1.1/L1.2+,ASPM_L1.1/L1.2+,T_PwrOn=6us; 1xs2idleand 2xdeepS2R 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=1W=1CONFIG_PCIE_APPLE=mbuilds (CONFIG_PCIEASPM=yand=n),W=1 CHECK_DTBS=y, andcheckpatch.pl --strictall pass.Risk: two-way door · affects J313 (enables
supports-clkreqonport00, enabling Clock PM and L1SS) and conventional Apple PCIe reinit hosts duringdeepsleep (drivers/pci/controller/pcie-apple.conly; 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-clkreqpending 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()pci_disable_link_state()mutates persistentlink->aspm_disablepolicy state and requires a matchingpci_enable_link_state_locked()caller, which cannot cleanly restore a link whoseCONFIG_PCIEASPM=nor firmware-inherited L1SS state was not enabled by the ASPM core, and does not save/restorePCI_L1SS_CTL2/PCI_L1SS_CTL1timing fields across a full controller power-loss reinit (PWREN/PERST#cycle).drivers/pci/controller/pcie-apple.ctherefore handles deep-sleep L1SS teardown and restoration locally on conventional reinit hosts (apple_pcie_s2r_reinit(pcie)whenpm_suspend_target_stateis neitherPM_SUSPEND_TO_IDLEnorPM_SUSPEND_ON):.prepare(), pins runtime PM on all L1SS links and drains in-flight runtime-PM transitions viapm_runtime_barrier()outside PCI locks (repeating in a bounded 8-pass loop if hotplug enumerates a new L1SS link while locks are dropped, returning-EBUSYon exhaustion), then holdspci_lock_rescan_remove()continuously into the clear walk.PCI_L1SS_CTL1child-first, then restores Link Control ASPM; rolls back all earlier links on partial error..suspend(), re-walks all attached L1SS links underpci_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..complete(), restores savedPCI_L1SS_CTL2andPCI_L1SS_CTL1timing fields (clearing live enable bits first, masking PCI-PM L1.1/L1.2 when either end is not inPCI_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.supports-clkreq;strictly toarch/arm64/boot/dts/apple/t8103-j313.dts&port00, matching the board's ADTclkreqwiring.Evidence
Commits
4f3e0d247ff0PCI: apple: disable L1SS around deep sleep on reinit hostsa90a2bfab82darm64: dts: apple: t8103-j313: enable CLKREQ on PCIe port00J313 (M1, T8103) hardware verification at
a90a2bfab82droot=UUID=... rw rootflags=subvol=root plymouth.ignore-serial-consoles user4k=on loglevel=4 console=tty0),pcie_aspmpolicy[default].pci 0000:01:00.0: ASPM: default states L1 ASPM-L1.1 ASPM-L1.2 PCI-PM-L1.1 PCI-PM-L1.2lspci -vvvpre-sleep, post-s2idle(rtcwake -d rtc1 -m freeze -s 8), post-deepmux: apple-display-crossbar: replace the T602x selector fields instead of OR-ing them #1, and post-deepdrm/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=6us01: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=6us01:00.1:LnkCtl: ASPM L1 Enabled; RCB 64 bytes, LnkDisable- CommClk+deepcycles (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
a90a2bfab82dARCH=arm64 LLVM=1W=1drivers/pci/controller/pcie-apple.o+ fullvmlinux+modules+modpostwithCONFIG_PCIE_APPLE=min bothCONFIG_PCIEASPM=yandCONFIG_PCIEASPM=n: 0 warnings, 0 errors.W=1 CHECK_DTBS=yonapple/{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.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.