Skip to content

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

Merged
DjDeveloperr merged 3 commits into
mainfrom
fix/t8132-apcie-deep-sleep
Dec 3, 2026
Merged

DjDeveloperr merged 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

DjDeveloperr commented Dec 3, 2026 •

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…, DTB 0bf95ef5430f53d8…, boot_id=cd32b8bc-004e-4a1b-b5fa-5d8464b07b4a, default s2idle [deep], pm_test=none): PASS (3/3).

Exact commits / DTB provenance on this boot (single J773g generation):

  • aurora-silicon/linux#4176 @ 40959794ea75b7b3e62fc84954e7237978f6ee37 (PCI: apple: set the T8132 ports up again after a deep sleep — J773g row only; shared T8132 reset table, J713 deep still owed)
  • aurora-silicon/linux#4007 @ c77edccad38852032d62f9d0b2b542c1d3f515f4 (t8132-apcie-port2: keep pcie0 sleep tunable register banks)
  • aurora-silicon/linux#3882 @ 491e031bb6808aa5d1568f71cf16c32cc15cfb22 (merged as 0c4c91bb7cc3)
  • aurora-silicon/linux#4031 @ 2fdae383ffa704b568a2c2302e995807538e7bb4 (merged as 9f672f0d9c85)
  • Correction on aurora-silicon/linux#4164: the booted boot3 DTB (0bf95ef5430f53d8…) was built from the earlier revision that included clkreq-gpios on pci@0,0, NOT 5a30f0960eab (which omitted clkreq-gpios). #4164 has since been updated to 0bc1cc98c029 to include clkreq-gpios on pci@0,0; an exact-head J773g DTB row at #4164 0bc1cc98c029 is queued next.

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 earlier rev, 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: KUnit dcp-topology apple-dart jpeg mt7932
Review ok approved by satchlj
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.

@RyanTheTide

Copy link
Copy Markdown
Contributor

J713 (MacBook Air 13" M4, T8132, firmware 27.2) exact-head row at 40959794: PASS, no regression

Build: this head 40959794ea75 (merge base = main e7109a0e77bd) with our nightly kernel config, minus DRM_APPLE_DISPLAY_KUNIT_TEST (needed because of main's current #3410 modpost break with SND=m). Booted with aura main 70d844e3 Stage 2 composed with this tree's own t8132-j713.dtb and U-Boot 5c0d5fe1, default command line, as one aura-try trial plus a one-shot GRUB entry (trial guard and fleet dead-man armed; saved default unchanged). Baseline = the same procedure on main e7109a0e, run on this J713 an hour earlier (linux#4155 comment 7374247896).

main e7109a0e (baseline) this PR 40959794
boot clean, 3/3 DCPs, Wi-Fi, GPU fw 26B123 accepted same
GPU smoke (vkcube 300) PASS PASS
s2idle (rtcwake -d rtc1 -m freeze -s 20, rtc1 = apple-pmu-rtc) PASS, 21 s PASS, 21 s
deep x3 (rtcwake -d rtc1 -m mem -s 20) 3/3 same boot, 0.32 s resume 3/3 same boot, 0.32 s resume; each wake logs pcie-apple 1cb0000000.pcie: native radio power-loss recovery complete; PCI devices 3 before/after; 0 DART faults/errors
after each deep panel on, Wi-Fi, BT, 8 input devices, 2 UDCs, 3 Type-C partners same
kernel err / WARN / Oops 3 / 0 / 0 3 / 0 / 0 (two DCP init lines, plus apple-sleep ... 302600000.gpu stop reported 1; physical sleep completed after sleeping)

The only failed unit, on both, is speakerguardd-v2-switchtest (speaker self-check on a non-fleet kernel). VDM recovery from a second Mac was armed throughout and wasn't needed. The J713 is back on its saved fleet94 and Stage 2.

@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.

Reviewed 40959794ea75:

  • Shared apple_pcie_t8132_port_regs matches the previous 19 entries in pcie-apple-radio.c verbatim (offsets, values, order).
  • apple_pcie_t8132_sleep_probe() cleanly gates on t8132_sleep && !managed_sids && !list_empty(&pcie->ports) with devres-grouped all-or-nothing rollback (including apple_dart_clear_host_resumes() + device_link_remove()), leaving managed-radio T8132 boards and non-T8132 hosts untouched.
  • apple_pcie_t8132_resume_noirq() sits ahead of adopt_link, restores the port DART before releasing PERST#, handles refused sleeps cleanly, and isolates a failed port via link_failed without clobbering saved state or other ports.
  • apple-build, host-tests (including t8132-apcie-sleep-tests.py), pr-text, and readiness are green with 3/3 J773g deep-sleep verification at head.

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

Copy link
Copy Markdown
Contributor Author

Checked on the merge of 40959794 with main c5bdd6820568 (tree 29cc93f164d2). The merge is clean, and nothing that landed on main since the merge base touches apple-dart.c, pcie-apple.c, pcie-apple-radio.c, dart.h or sleep.c. The two merges after that (#4183, #4070) don't either; with them the merge is still clean, but the tree built and tested here doesn't have them (they change the scaler driver, afk.c and dcp.c only).

  • W=1 (clang 23.1.3, arm64): apple-dart.o, pcie-apple.o (it includes pcie-apple-radio.c) and sleep.o, 0 warnings.
  • Host tests in the Ubuntu 24.04 CI toolchain image, every job that reads these files: 114/114, then 24/24 for dart-sleep-power and the jobs that read sleep.c. All tests named in the body are in these.
  • Hosted KUnit at this head: KUnit asahi passed. KUnit dcp-topology apple-dart jpeg mt7932 was still running on its runner (since 11:31Z), so this merge doesn't wait for it (hosted CI override, Dj). Its result at this head is not known here.
  • The apple-dart KUnit cases were built (arm64, W=1, 0 warnings) but not run. UML can't run them: apple-dart.c needs arm64 headers, and with those stubbed UML's MMIO emulation rejects the tests' register banks, so cases fail and the run crashes for that reason; that run is void. The runtime evidence is the J773g 3/3 deep row at this head.

Rows at this head: J773g 3/3 deep, J713 boot + s2idle + 3/3 deep without a regression. The J713 row closes the "one J713 deep-sleep cycle" item under Not yet. Still not covered: Wi-Fi/Bluetooth working after a J773g wake, a J773g without clkreq-gpios, s2idle on the J773g (read from the code: every new path needs a firmware sleep), and a wake where one port doesn't train.

The J773g's default stays s2idle after this merge: its PCIe sleep windows come with #4007, which lands last.

@DjDeveloperr
DjDeveloperr merged commit 65ce0ad into main Dec 3, 2026
15 of 16 checks passed
@DjDeveloperr
DjDeveloperr deleted the fix/t8132-apcie-deep-sleep branch December 3, 2026 11:52
DjDeveloperr added a commit that referenced this pull request Dec 3, 2026
#3809 is in main now, and #4176 added apple_dart_clear_host_resumes() and
apple_dart_host_restart() to main. Both sides add the same
apple_dart_clear_host_resumes(); keep one copy, and
apple_dart_is_host_resumed() from this branch, in
include/linux/soc/apple/dart.h and drivers/iommu/apple-dart.c.

Signed-off-by: DjDeveloperr <hey@djdev.me>
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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants