Skip to content

PCI: apple: set the T8132 ports up again after a deep sleep (J773g wake reset) - #4176

Open
DjDeveloperr wants to merge 3 commits into
mainfrom
fix/t8132-apcie-deep-sleep
Open

DjDeveloperr wants to merge 3 commits into
mainfrom
fix/t8132-apcie-deep-sleep

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

What: The J773g (M4 Mac mini) resets on its first deep-sleep wake. Nothing sets its two APCIe ports up again, so the port DARTs' own resume reads them without a clock and takes an SError. The T8132 host without the managed radio now owns its ports across a deep sleep: it saves them in the noirq suspend and brings ports, DARTs and links back in the noirq resume. This is the driver half of the hooks #2763 added to sleep.c.

Tested: J773g (M4 Mac mini, 27.2) at 40959794: 3/3 deep sleeps, same boot, both ports and both port DARTs back after each, Ethernet link up at 1 Gb/s after each, no SError. Run as this head's driver change on the J773g test stack, see Evidence. Wi-Fi/Bluetooth were not driver-bound. Plus compile (W=1) and host tests.

Risk: two-way · J773g (T8132 without apple,managed-sids). The other T8132 Macs share one reset table with it, values unchanged.

Not yet: the J773g's Wi-Fi/Bluetooth working after a wake (its test rootfs had no radio firmware, so only their config space was read); the J773g without clkreq-gpios, as in main's DT; one J713 deep-sleep cycle for the shared reset table; a wake on hardware where one port doesn't train.

Details

The fault. On main the wake gets 15 ms into dpm_resume_noirq and takes Asynchronous SError Interrupt (esr 0xbe000000); the newest device callback is 490000000.iommu, the radio port's DART. sleep.c already stops both ports before it lowers APCIe and has apple_sleep_apcie_ports_owned() and apple_sleep_apcie_port_up() for a host that brings them back. No host called them.

What the host does. Per port, in this order: PERST# asserted and CLKREQ# back to an input; the reset values; the loader's apple,tunable-port; the port's clock and its two reference clock requests; ready; the clock gating it had before; the root port's tunables and link limits; RID-to-SID and MSI routes; the port's DART; the root port's config space; PERST# released; link training; interrupts. The DART is restored before anything behind the port can reach it.

Where the values come from. The reset values are the ones the managed radio's recovery already writes (#3629), now shared instead of copied. The link's width and speed limits are the ones the loader programmed, read back in the suspend: the DT has neither num-lanes nor max-link-speed for these ports. Timeouts and delays are the existing ones of the same file, PCIE_T_PVPERL_MS, PCIE_RESET_CONFIG_WAIT_MS, and the 500 ms the managed radio's link gets.

All ports or none. The probe first checks every port (PHY block, atomic PERST#, optional CLKREQ#, tunables), then claims the DARTs, then tells apple-sleep. Any failure gives everything back and the host behaves as before. Giving a DART back needs apple_dart_clear_host_resumes(), the same helper #3809 adds (same text, so either order merges).

A port that doesn't come back is lost until a restart: PERST# asserted, LTSSM stopped, link_failed set, its functions marked disconnected, config space (also the root port's) and its interrupt closed. apple-sleep isn't told it's up, so the next sleep doesn't stop it. Later sleeps neither save over its last good copy nor touch it. It isn't retried: by then the functions' saved config space and their firmware are gone, so a retrained link would be no use to their drivers. The other ports come back normally.

Other hosts. The new paths need t8132_sleep in the host's data, which only apple,t8132-pcie has, and no apple,managed-sids. Every T8132 board includes t8132-jxxx.dtsi, which sets that property, and only t8132-j773g.dts deletes it. J713, J715 and J604 leave the new probe at its first check. t8132_hw is otherwise t602x_hw, and nothing compares against the latter's address. The resume hook is keyed on a flag only the new suspend path sets, and comes before the adopted-link hosts' block; a host test checks that.

With other changes

Evidence

J773g, 27.2, kernel 7.3.0-j773g-ship1 #3: the J773g test stack (which also has #3809 and #4007) with exactly this head's change to pcie-apple.c and pcie-apple-radio.c, compared line by line. Without this change the same stack resets on its first wake.

port 0 (radio) port 2 (Ethernet)
Deep sleeps 1, 2, 3 DART restored, link restored, 3/3 DART restored, link restored, 3/3
Port's wake time 0.31 s 0.31 s
LnkSta before, after 1, after 3 5 GT/s x1 each time 2.5 GT/s x1 each time
Endpoint after the third wake 14e4:4434 and 14e4:5f72 readable, no driver bound (no firmware on this rootfs) tg3: link up at 1000 Mb/s after each wake
Loader properties on the port apple,tunable-{port,rc,rc-gen3,rc-gen4}, clkreq-gpios none of these

Boot object resumes 0 -> 3, suspend_stats 3 success / 0 fail, same boot_id, 0 SError/Call trace/BUG/WARNING.

Host tests (tools/asahi):

  • New t8132-apcie-sleep-tests.py, the production functions on two modelled ports: 3 good cycles; a refused sleep; either port failing at each of its five waits, followed by a second sleep; a DART that can't be restored; PERST# that can't be driven. Negative controls by hand, all caught: saving over the good copy, no PERST# on failure, no link_failed, no DART restore, reporting a failed port as up, no reachable resume hook.
  • radio-sleep-power (now reads the shared table), radio-sleep-snapshot, radio-sleep-fence, radio-pm, pcie-adopted-clkpm, pcie-apple-msi-slice, pciec-policy, dart-sleep-writer, dart-sleep-snapshot, dart-sleep-power, apple-dart-range, apple-dart-isp-host, apple-dart-dapf, apple-dart-attach-undo, apple-dart-tlb-stall: pass.

Build: pcie-apple.o W=1 clean (aarch64 gcc 16.2.0), apple-dart.o clean; sleep.o is not touched. A full Image of this change on the J773g's test stack links with every exported symbol of that kernel.

The shared table's 19 entries were compared with the managed radio's old ones: same values, same order.

checkpatch.pl --strict: 0 errors on each commit; the driver commits 0/0/0, the test file 1 check and 3 warnings (its stub list macro, MAINTAINERS).

apple_dart_set_host_resumes() leaves a DART's restore after a deep sleep
to the PCIe host that clocks it. A host that claimed one port's DART and
then can't claim the next one's has to give the first one back, or
nothing restores it: the DART's own resume skips it for good.

Add the opposite call. Nothing uses it yet.

Signed-off-by: DjDeveloperr <hey@djdev.me>
The managed radio's recovery has the T8132 port's reset values inside
its own function. A host that sets its ports up itself after a deep
sleep writes the same ones: move them out, in the same order and with
the same values. No functional change.

Signed-off-by: DjDeveloperr <hey@djdev.me>
A T8132 host without the managed radio contract, as the J773g's with its
Wi-Fi/Bluetooth and Ethernet ports, has nothing that brings its ports
back after a deep sleep. apple-sleep can stop them and knows about a
host that owns them, but no host says so. The port DARTs, clocked by
their ports, are then read by their own noirq resume without a clock:
the J773g takes an SError in the resume of iommu@490000000, 15 ms into
the wake, and resets.

Take the ports over: save what only their registers hold in the noirq
suspend, and in the noirq resume write the reset values, the loader's
tunables and link limits, the clocks, the RID-to-SID and MSI routes,
then the port's DART and the root port's config space, and train the
link, each before anything that depends on it. The link's width and
speed limits are the ones the loader left. apple-sleep learns about
every port that is back, so that the next sleep stops only those.

The host takes the ports over only once every port has what its recovery
needs, and gives back what it claimed otherwise.

A port that doesn't come back is lost until a restart: its endpoint goes
back into reset, its functions are marked disconnected, its config space
and interrupt stay closed, and the next sleeps neither save over the
last good copy nor touch it. The other ports are not affected.

Hosts with apple,managed-sids (J713, J715, J604) return from the new
probe first and keep their own recovery.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J773g (Apple M4 Mac mini, Mac16,10, T8132, G16G B0, os-fw 27.2 / 26B123) committed deep x3 row on 7.3.0-j773g-ship1 #3 (Image b46c1c9933d001d8…, boot_id=cd32b8bc-004e-4a1b-b5fa-5d8464b07b4a, default s2idle [deep], pm_test=none): PASS (3/3).

Exact PR heads covered on this boot:

  • aurora-silicon/linux#4176 @ 40959794ea75b7b3e62fc84954e7237978f6ee37 (PCI: apple: set the T8132 ports up again after a deep sleep)
  • aurora-silicon/linux#4007 @ c77edccad38852032d62f9d0b2b542c1d3f515f4 (t8132-apcie-port2: keep pcie0 sleep tunable register banks)
  • aurora-silicon/linux#3882 @ 491e031bb6808aa5d1568f71cf16c32cc15cfb22 (soc: apple: clpc: enable on-time idle sampling on T8132)
  • aurora-silicon/linux#4031 @ 2fdae383ffa704b568a2c2302e995807538e7bb4 (t8132: connect the external display pipes' PMC enables on every M4 Mac)
  • aurora-silicon/linux#4164 @ 5a30f0960eab269cf8c6aa56d5d3ba2fc306045b (t8132-j773g: wire display-power for deep sleep)

Verified results:

  • Committed deep sleep (3/3): suspend_stats/success=3, fail=0, last_failed_errno=0, boot_id unchanged across all 3 cycles (RTCWAKE rc=0 x3, apple-sleep: back from sleep, boot object resumes 0 -> 1 -> 2 -> 3, 302600000.gpu stop reported 1; physical sleep completed, 135 of 224 AP pins changed by the sleep, all put back, 0 SError / Call trace / BUG / Oops / WARNING).
  • PCIe & DART recovery (PCI: apple: set the T8132 ports up again after a deep sleep (J773g wake reset) #4176, arm64: dts: apple: t8132-apcie-port2: keep pcie0 sleep tunable register banks #4007): Boot logged pcie-apple 1cb0000000.pcie: T8132 multi-port deep sleep recovery registered. Every wake restored both DARTs and links in order: 490000000.iommu: restored after its host came back -> port 0: link restored after deep sleep; 492000000.iommu: restored after its host came back -> port 2: link restored after deep sleep. LnkSta unchanged pre-sleep = post-wake-1 = post-wake-3 (00:00.0 5GT/s x1, 00:02.0 2.5GT/s x1). Config space readable post-3 wakes (01:00.0 443414e4, 01:00.1 5f7214e4, 02:00.0 168214e4); end0 (tg3) returned 1000 Mbps full duplex after all 3 wakes. DT properties under /soc/pcie@1cb0000000: pci@0,0 has apple,tunable-{port,rc,rc-gen3,rc-gen4}, clkreq-gpios, reset-gpios; pci@2,0 has reset-gpios. (Note: brcmfmac/hci_bcm4377 returned -ENOENT at boot for absent firmware blobs on this rootfs, pre-sleep.)
  • External displays & PMC (arm64: dts: apple: t8132-j773g: wire display-power for deep sleep #4164, arm64: dts: apple: t8132: connect the external display pipes' PMC enables on every M4 Mac #4031): Both external DCPs (286e00000.dcp, 48ae00000.dcp) bound with 0 no apple,display-power warnings, returned RTKit: sleep return: ASC control 0x0, setting RUN across all 3 wakes, and restored card1-DP-3: status=connected enabled=enabled (3840x2160@60). Both pmc-dispext0-interface and pmc-dispext1-interface remained on in pm_genpd_summary after all 3 wakes (resume_early ran 3x, 0 errors).
  • GPU & CLPC (soc: apple: clpc: enable on-time idle sampling on T8132 #3882): aurora-g16 returned in 7653 / 9117 / 3879 us back to limit=S10. Post-wake-3 gpubench-vk passed (compute.light d=4 40.11 us, compute.uber d=4 486.40 us, crc=9963f56c valid=true); /sys/kernel/debug/aurora-g16/stats: health: failed 0 errno 0 degraded 0, jobs 43565 recoveries 0 hang_kills 0, sensor_errors 0; 0 CLPC errors in dmesg.
  • Type-C VDM routes: m5 (1-0a 0x731d3115) and neo (1-0c 0x73213102) both active post-wake-3.

@DjDeveloperr
DjDeveloperr marked this pull request as ready for review December 3, 2026 10:16
@DjDeveloperr
DjDeveloperr requested review from a team as code owners December 3, 2026 10:16
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) area:platform Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (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 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

Merge readiness at 40959794: not ready yet

Check Detail
CI at head running running: apple-build, host-tests, pr-text / pr-text, KUnit plan
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok in the PR body at 40959794
Conflicts ok none
PR text ok Risk: two-way · J773g (T8132 without apple,managed-sids). The other T8132 Macs share one reset table with it, values unchanged.

Areas: area:gpu, area:platform

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

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:platform Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant