Skip to content

thunderbolt/typec: pick the T8122 USB4 router policy by capability, enable the J615 (on #1490) - #2649

Closed
RyanTheTide wants to merge 7 commits into
stack/pr1490-154721f5from
j615usb4/t8122-usb4-by-capability
Closed

RyanTheTide wants to merge 7 commits into
stack/pr1490-154721f5from
j615usb4/t8122-usb4-by-capability

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #1490. The base branch stack/pr1490-154721f5 is #1490's head (154721f) copied unchanged, so this diff shows only the seven commits on top. Folding them into #1490 is fine with me if that is the cleaner path.

Problem
#1490 brings up the T8122 USB4 router on the 13-inch M3 Air (J613), but it only takes the T8122 path on apple,j613. Every other Mac with the same router falls back to the T8103 policy, which can't stop the router in the order the T8122 needs before sleep and shutdown.

Change

  • typec mux: a USB4/Thunderbolt switch can say in its description that the Type-C port driver has to stop it, before tasks freeze and at shutdown, ahead of the USB role and the PHY. Port drivers ask with typec_thunderbolt_switch_pd_ordered_stop().
  • thunderbolt/apple: take the T8122 policy whenever the device tree names the router's MxWrap cpu resource, and keep the T8103 fallback for trees without it. Macs that take it (shared t8122.dtsi): J433, J434, J504, J613, J615.
  • tipd: run the session stop for whichever port's switch asks for it, at suspend and at shutdown, on SPMI and now also on I2C ports. tipd_shutdown() does nothing for a variant that has no struct cd321x (plain TPS6598x on the I2C driver).
  • dts: the J615 gets the J613's PCIe-C tunnel description and aliases; the tunnel DARTs get their ATC CIO-PCIe power state.
  • tipd KUnit: the session stop against a self-stopping router, against one that asks for it, and a plain-port shutdown.

Testing

  • KUnit (arm64 QEMU, tipd + sn201202x + typec_mux): 165 run, 160 pass, 5 skipped (debugfs / OF_OVERLAY), 0 fail. checkpatch --strict clean.
  • apple-dart-pd-check.py against the fleet78 DTBs as baseline: 0 new findings (2 before the DART fix).
  • J615 (M3 Air 15") with a Thunderbolt cable to an M1 Pro, default command line, fleet78 plus this series (d93c785), DTB in the Stage 2 handoff, two one-shot boots:
    • T8122 policy selected from the DT on both ACIO instances; USB4 link up at boot both times, 10 Gb/s x2, XDomain host found, thunderbolt-net up.
    • s2idle with the link up: the port stops the session before the freezer (sn201202x 1-0a: USB4 session quiesced before freezer), the RTC wakes the system on time and the link is back 6 s after resume.
    • Reboot with the link up: clean, back on the default boot.
    • Peer unplug/replug while awake (the peer unbinds and rebinds its router): clean, link back in 15 s.
  • The J615's own ADT carries exactly the tunnel-DART and oe-fabric tunable lists that t8122-usb4.dtsi hard-codes (both ports).

Still to run

  • s2idle x3 with the link up and a poweroff on the e690d19 head (kernel built, waiting for a J615 slot).
  • J613 regression on this head; one I2C-PD T8122 Mac (J504 or J433) booting to a USB4 link with a clean shutdown; one J714s deep-sleep row.
  • Not fixed here: on the J615, a peer-side Type-C change while the J615 is in s2idle (peer reboot, peer router unbind) hangs the J615, with and without this series. It needs a change on the Type-C side of the sleeping port, not the router; it is followed up separately.
Details for reviewers
  • Why a switch capability and not a DT property on the PD node: whether the router needs a PD-ordered stop is a property of the router driver's policy (strict_power_cycle), and that policy is chosen from the DT cpu resource.
  • typec_thunderbolt_switch_pd_ordered_stop() reads under the switch's set_lock and returns false once the provider unbinds, like typec_thunderbolt_switch_is_live().
  • Review fixes in this push: I2C .shutdown + variant guard (dd986ff), session_pm_armed cleared when our own PREPARE fails, because the PM core skips our POST_SUSPEND then (dd986ff), tunnel DART power-domains (e690d19).
  • The tunables in t8122-usb4.dtsi stay hard-coded here; having the loader fill them from each Mac's ADT is thunderbolt: apple: enable the J613 USB4 host-to-host path #1490's to decide. On the J615 they match its ADT.
  • J615 evidence is from our own Linux captures (sysfs, dmesg, iperf3). thunderbolt-net on the same link: J615 to M1 Pro 8.1-8.8 Gbit/s, M1 Pro to J615 5.8-7.0 Gbit/s (MTU 1500).
  • Lab kernel for the rows: fleet78 + this series merged locally (3 conflicts with integration resolved in DT/header context only); the J615 Stage 2 for those boots is its default with only the DTB replaced.
  • The pre-existing J613 SWDF/SWUF gate in tps6598x_dr_set() is not part of this series.

Assisted-by: LLM (Claude:Opus 5.5)

Some USB4 routers must be stopped by the Type-C port driver, in a fixed
order ahead of the USB role and the PHY, before tasks freeze and at
shutdown. Others stop on their own. Let the provider say which it is in
its switch description, and give port drivers
typec_thunderbolt_switch_pd_ordered_stop() to ask, so they no longer have
to guess from the machine they run on.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The T8122 router policy (MxWrap RUN, explicit LSTX, strict firmware-ready
admission, witnessed power-off) was only taken on apple,j613. Every other
T8122 Mac with the same router - the 15-inch MacBook Air (J615), the
iMacs (J433/J434) and the MacBook Pro (J504) - fell back to the T8103
policy, which cannot start it.

What the policy needs is the router's MxWrap CPU block, which the device
tree names as the "cpu" resource. Take the T8122 policy whenever that
resource is described and keep the T8103 fallback otherwise (for example
an older loader's handoff tree without it).

The strict power cycle has to be stopped by the PD driver ahead of the
USB role and the PHY, so advertise that through the switch description
instead of letting the PD driver infer it from the machine.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The CD321x session stop before tasks freeze and at shutdown (ACIO, then
the USB role, then the PHY in safe mode) only ran on apple,j613. Run it
for whichever port's USB4/Thunderbolt switch asks for a port-driver stop
instead, and leave every other switch alone as before. The notifier is
registered for every CD321x and asks the switch on each suspend, because
the router may bind after the port.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The J615 (MacBook Air 15-inch, M3) has the J613's two ATC ports on the
same T8122 routers. Give it the PCIe-C tunnel description and aliases
the J613 already has, and drop its unused, disabled USB2 OTG node so
older loaders do not prune the shared ATC0 suppliers.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Cover the suspend notifier with a router that stops on its own (nothing
is sent to it) and with one that asks the port to stop it (SLEEP before
the freeze, WAKE after it).

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>

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

The approach is right. The T8122 policy is chosen when the ACIO node's reg-names includes "cpu" (apple.c:4652-4654), and otherwise the driver falls back to the T8103 policy, which is today's behaviour on every T8122 board. Lock order is unchanged: the pd_ordered_stop read under tps->lock matches typec_thunderbolt_switch_set(). The J615 includes, aliases and /delete-node/ mirror the J613, and both DTBs compile.

Before this can land:

  1. The J615 inherits #1490's failing DT check. scripts/dtc/apple-dart-pd-check.py on the J615 DTBs reports 4 new DARTs with no power-domains: /usb4-pcie-tunnel-{0,1}/iommu@{721008000,b21008000}, on t8122-j615 and -25g83. It's the check that fails #1490 for the J613. This PR has no CI because it targets a stack branch, so it will fail once retargeted. Fix in t8122-usb4.dtsi: give each tunnel DART its ATC CIO-PCIe power state.
  2. The J615 would run with the J613's tunables. The tunnel DART apple,tunable (t8122-usb4.dtsi:18,118) and apple,tunable-oe-fabric (:53,:153) are fixed values, and nothing re-reads them on the J615. The loader-copied aliases cover only the rc, fabric and debug tunables. Either have the loader fill these from each Mac's ADT, or confirm the J615's ADT matches. That's #1490's to fix, under checklist items 3 and 4. The header comment "J613 ADT PCIe-C windows" and the "m1n1 fills" comments also need updating.
  3. One non-T8122 sleep row, please. The new PM notifier (core.c:2649-2657) now registers on every CD321x and SN201202x, so it adds a tps->lock acquisition to PM_SUSPEND_PREPARE on every Mac. Add a J714s (M5) deep-sleep row to the J616s/J713 s2idle rows already listed.
  4. Nit: tipd_shutdown() (core.c:3948) now does container_of(tps, struct cd321x, tps) unconditionally. It's valid today, because the only caller is sn201202x_shutdown(). But a plain TPS6598x caller of the exported function would read out of bounds, so a comment or a variant check would help.

Order: #1490, the base, isn't ready to land first:

  • it's a draft and conflicts with integration;
  • its dt-checks fail;
  • its 8 commits carry Assisted-by trailers (checklist item 4);
  • its body describes 972cf33 rather than its head 154721f.

Folding this PR into #1490, as its body offers, is the clean path. The USB4 link row still waits on a Thunderbolt cable. J433, J434 and J504 also take the T8122 policy now; they'd log "PCIe-C tunnel disabled" and continue, but haven't booted it.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Blockers: 1 (in addition to the four points in the earlier review, which still stand on d93c785).

  1. The new switch capability covers sleep and shutdown, but only the SPMI port driver implements the shutdown half. pd_ordered_stop is documented as "stopped by the Type-C port driver, before tasks freeze and at shutdown" (include/linux/usb/typec_mux.h:246-248), and apple.c:4865 now sets it for every T8122 router whose ACIO node names cpu. That includes the shared t8122.dtsi:1597, so J433, J434 and J504 get it too. Those three boards use t8122-usbpd-i2c.dtsi, and the I2C driver has no .shutdown (drivers/usb/typec/tipd/i2c.c:117-126). tipd_shutdown() (core.c:3948) is reached only from sn201202x_shutdown() (spmi.c:1156). On those Macs the router now runs the strict power cycle, and apple_cio_shutdown() (apple.c:4893) stops ACIO at device_shutdown. Nothing parks the USB role and PHY ahead of it, which is the ordering the capability exists for. The reboot notifier only sends OFF (core.c:2703-2711). Either add .shutdown = tipd_shutdown-style handling to the I2C CD321x path (with the variant check the earlier nit asks for, since the I2C driver also binds plain TPS6598x parts), or keep the I2C boards on the T8103 policy until their port driver honours the whole contract. Also say in the commit message which Macs gain the strict policy and the PD-ordered sleep stop.

  2. The s2idle rows on the J615 had no USB4 link. With active false, cd321x_session_stop() returns right after the SLEEP set (core.c:2593-2594). So the role/PHY-SAFE part of the new path, and the shutdown path, have not run on hardware. They need the link row below.

Nit: cd321x_session_pm() drops session_pm_armed only in POST_SUSPEND (core.c:2640-2642). If our own PREPARE fails, the PM core skips our POST, so the flag stays set until the next PREPARE overwrites it. That's harmless today. Clearing it on the error path keeps the state obvious.

HW row: J615 with a Thunderbolt cable on this head: USB4 link up, thunderbolt-net ping, s2idle 3x with the link up (role/PHY quiesce lines in dmesg), then a poweroff and a reboot with the link up. Plus J613 regression and one I2C-PD T8122 Mac (J504 or J433) booting to a USB4 link and doing a clean shutdown. 0 AVC, 0 failed units, no new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

pd_ordered_stop asks the Type-C port driver to stop the USB4 session
before tasks freeze and at shutdown. Only the SPMI SN201202x driver had a
.shutdown, so on the T8122 Macs whose CD321x sits on I2C (J433, J434,
J504) the router took the strict power cycle at device_shutdown with the
USB role and PHY still owned by the port.

Give the I2C driver the same .shutdown. The I2C driver also binds plain
TPS6598x parts, which have no struct cd321x around them, so
tipd_shutdown() now returns early for a port whose variant does not
embed one, and a KUnit case covers that.

On a PREPARE that fails, the PM core skips our POST_SUSPEND: clear
session_pm_armed on that path too so the state stays obvious.

Macs that take the T8122 router policy (ACIO node names "cpu", shared
t8122.dtsi): J433, J434, J504, J613, J615; their ports get the
PD-ordered sleep and shutdown stop.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The PCIe-C tunnel DARTs probe as devices of their own and sit inside the
ATC's CIO-PCIe block, which their tunnel's root port already names. Give
each DART the same power state so it is never probed or read while that
block is off. apple-dart-pd-check.py reported both as new findings on
the J613 and J615 DTBs; it reports none now.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Thanks both. Pushed e690d19 (two commits on d93c785). Point by point:

Dj's review

  1. Tunnel DART power domains: fixed in e690d19. Each tunnel DART now names its ATC CIO-PCIe state, the same one its root port uses. apple-dart-pd-check.py with the fleet78 DTBs as baseline went from 2 new findings to 0 on the J613 and J615.
  2. J613 tunables on the J615: I compared them offline against the J615's own ADT. The tunnel-DART list and the oe-fabric list match exactly on both ports (9 and 6 entries). Having the loader fill them is still the better long-term answer, and that is thunderbolt: apple: enable the J613 USB4 host-to-host path #1490's call, along with the "J613 ADT" header and "m1n1 fills" comments in that file.
  3. Non-T8122 sleep row: still to run (J714s deep sleep). It's listed under "Still to run".
  4. tipd_shutdown() on a plain TPS6598x: it now returns early unless the variant embeds a struct cd321x, and a KUnit case covers it.

RyanTheTide's review

  1. I2C shutdown: the I2C driver now has a .shutdown that calls tipd_shutdown(), with the variant guard above. So J433/J434/J504 get the PD-ordered stop at shutdown too. The commit message lists the Macs that take the strict policy.
  2. A link row on the J615: done on d93c785 with a Thunderbolt cable to an M1 Pro, on the default command line. The link comes up at boot (10 Gb/s x2). s2idle with the link up runs the active path (USB4 session quiesced before freezer) and the link is back 6 s after resume. Reboot with the link up is clean. s2idle x3 and a poweroff on e690d19 are next, once the J615 is free.
    Nit: session_pm_armed is now cleared when our own PREPARE fails.

A separate finding from the same cable, not caused by this series and not fixed by it: if the peer changes the Type-C state while the J615 is in s2idle (peer reboot, or the peer unbinding its router), the J615 hangs. That happens on fleet78 without this series (2/2) and with it (1/1), even though here the session was already stopped before sleep. Plain s2idle with a stable link passes on both. I'm following that up on the J615's sleeping-port side.

Row details
  • Kernel: fleet78 + this series merged locally. The Stage 2 was the J615's default with only the DTB replaced; the structural DTB diff is the USB4 nodes only.
  • Peer harness: the M1 Pro unbinds and rebinds its own ACIO (tps6598x: USB4/Thunderbolt router bound again, reapplying the cable state). Awake, that is a clean hot-unplug/replug on the J615 in 15 s.
  • thunderbolt-net on the link: J615 to M1 Pro 8.06 Gbit/s (1 stream) / 8.22 (4 streams); M1 Pro to J615 5.94 / 6.99 (MTU 1500).

Assisted-by: LLM (Claude:Opus 5.5)

@satchlj

satchlj commented Nov 22, 2026

Copy link
Copy Markdown
Member

Claude Opus 5.5 on @satchlj's behalf. Thanks: folded into #1490 as a fast-forward to e690d19, your commits unchanged. The J613 link+replug regression row will be reported on #1490; the replug part is on Satya's hands-on list (he is away until Nov 23). This PR can be closed in favour of #1490 if you agree.

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

Pre-PR checklist review (§1–§6) at e690d19c5b2eaa8755de03adf72fd17d4f0c1ea8: 0 code, policy, attribution, or naming blockers in these 7 commits; holding only for CI (none runs on stack branch stack/pr1490-154721f5) and §5 hardware evidence on the live head.

Verified

  • §1 No model gating: Both of_machine_is_compatible("apple,j613") gates are gone (drivers/thunderbolt/apple.c:4652-4654 now selects apple_cio_t8122_hw from the DT "cpu" reg-name; drivers/usb/typec/tipd/core.c:2630-2632,3962-3965 now query typec_thunderbolt_switch_pd_ordered_stop()).
  • Locking & lifetime: typec_thunderbolt_switch_pd_ordered_stop() (drivers/usb/typec/mux.c:902-909) mirrors typec_thunderbolt_switch_is_live() under rwsem_read(&sw->sw_dev->set_lock) and returns false once the provider unregisters. cd321x_session_pm() clears session_pm_armed on both failed PM_SUSPEND_PREPARE and PM_POST_SUSPEND, and cd321x_stop_work() unregisters the PM notifier.
  • I2C shutdown & variant safety: tps6598x_shutdown_i2c() (drivers/usb/typec/tipd/i2c.c:97-100) routes through tipd_shutdown(), which guards container_of(tps, struct cd321x, tps) with tps->data->tps_struct_size < sizeof(struct cd321x) (core.c:3958-3960) so plain TPS6598x/TPS25750/TPS66993 bindings return safely while CD321x and SN201202x proceed. Also verified apple_cio_tbt_switch_set() (apple.c:3986-3987) returns 0 for TYPEC_THUNDERBOLT_SWITCH_OFF even if apple_cio_shutdown() ran first and set acio->removing = true.
  • DTS & DART power domains: t8122-j615.dts mirrors t8122-j613.dts (and t8122-j615-25g83.dts inherits it); t8122-usb4.dtsi:18,119 add power-domains = <&ps_atc{0,1}_cio_pcie>; to both tunnel DARTs.
  • §4 Attribution: All 7 commits carry human author/committer and human Signed-off-by: only, with zero AI trailers.

Non-blocking notes (for #1490 where this series is folded)

  • Since @satchlj has already fast-forward folded e690d19c into #1490, closing this PR in favour of #1490 once confirmed makes sense.
  • On #1490's base arch/arm64/boot/dts/apple/t8122-usb4.dtsi: note that usb4_1_pcie apple,tunable-oe-fabric (:157-158) lists <0xc 0x1 0x1> twice where usb4_0_pcie (:56-57) has <0x8 0x1 0x1> then <0xc 0x1 0x1> — worth double-checking against the ADT, alongside cleaning up the pre-existing m1n1 comments (:51,:152) and #1490's base commit trailers before #1490 merges.

Missing before approval (CI + §5 HW rows on live head e690d19c)

Existing J615 link rows were run on d93c785b (prior to dd986ff5 I2C .shutdown and e690d19c tunnel DART power-domains). Needed on e690d19c (or on #1490 after rebase onto integration/aurora with green CI):

  1. J615 (default cmdline, USB4 link up): s2idle x3 with active quiesce + clean poweroff + clean reboot; 0 SELinux denials, 0 failed units, 0 new kernel errors.
  2. J613 regression (USB4 link + suspend + shutdown).
  3. One I2C-PD T8122 Mac (J504 or J433/J434): USB4 link up + clean shutdown exercising the new tps6598x_shutdown_i2c() -> tipd_shutdown() path.
  4. One non-T8122 Mac (e.g. J714s deep sleep) covering the session_pm notifier now registered on every CD321x/SN201202x.

Assisted-by: LLM (Gemini 4 Neon)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Folded into #1490, which now carries these commits unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants