Skip to content

M2 Mac mini USB-C on the default boot; keep USB4 links across dwc3 role swaps - #3040

Open
RyanTheTide wants to merge 2 commits into
integration/aurorafrom
m2mini-usbc-full/j473-usbc-default
Open

RyanTheTide wants to merge 2 commits into
integration/aurorafrom
m2mini-usbc-full/j473-usbc-default

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

Problem

On the M2 Mac mini (J473) with 27.2 firmware, both USB-C ports are dead on the default boot: no USB2, USB3, USB4 or role switch. The Type-C display routes of both ports sit on the primary DCP. That DCP refuses the 27.2 firmware, so it never registers them, and both CD321x port controllers wait for that mode switch forever (deferred probe pending).

Bringing the ports up exposes a second bug, which affects every Apple Type-C PHY generation except T8132. When dwc3 stops on a port in USB4 or Thunderbolt mode, the PHY powers off under the live link. dwc3 stops for a data-role swap as well as for a cable change. With a host-to-host USB4 peer, a partner that leaves and comes back during s2idle can come back with the roles swapped. At resume, dwc3 then goes from device to host and the PHY cycles off and back to USB4 within the same millisecond while the peer is still training the link. The link never trains again and the XDomain is lost. A partner event in the next s2idle then hangs the J473 (no wake, no reset; only a VDM reboot recovers it).

Change

  1. phy: apple: atc: when its USB host stops, leave a PHY that is in a CIO mode (USB4/Thunderbolt, last transition not failed) as it is, on every generation. Until now this only applied on T8132. The PIPE is still parked, and the Type-C mux still takes the mode down when the connection ends. This removes a generation check instead of adding one. The USB3 host model (tools/asahi/atc-usb3-tests.py) now runs the CIO cases on the T8103 sequence (used by T8112 and T600x) as well as on T8132, and has a mutation that restores the T8132-only condition.
  2. drm/apple: dcp: when a DCP refuses its firmware, disable its typec-routes child, as the three existing give-up paths already do. The connector graph lookup then skips those endpoints and the ports come up on the PHY mode switch alone, without DP alt mode on that DCP. This is selected by the device tree. It is a no-op where the DCP accepts its firmware.

Testing

J473, production Stage 2, default kernel command line, one-shot trial boots, J616s (M4 Pro) as the USB4 host-to-host peer on port 0, a USB-C-to-HDMI adapter on port 1.

  • USB-C bring-up (dcp commit, row f1, on integration/aurora 110861f + the same patch): both CD321x bind and nothing is left deferred. Both Type-C ports register (PD, DP and TBT altmodes). USB4 host-to-host runs at 20 Gb/s x 2 lanes, with TCP throughput of 10.5 to 12.8 Gbit/s each way. DP alt mode is entered on port 1 (no picture yet: the primary DCP is still refused, which is drm/apple: adopt a DCP handed over running (M2 Mac mini HDMI on 27.2) #2853 job). Real PD unplug/replug passed 5/5 on each port. The USB-A ports and a 27.2 IPSW USB stick are unchanged (SuperSpeed, full unzip -t clean, 410 MB/s O_DIRECT). 0 oops, 0 DART faults.

  • Peer churn in s2idle (atc commit). In each row the peer drops its port for 5 s inside each 20 s s2idle, so the link drops and trains again while the J473 sleeps:

    kernel cycles port 0 came back as host XDomain kept after the flip hangs
    dcp commit without the atc fix (rows s4b2, s5, s6, s7, s8; s6-s8 with the diagnostic variants below) 19 5 0 of 5 5 (each in the sleep after the flip)
    integration/aurora 0f111a0 + both commits (row s10) 12 6 6 of 6 0

    On s10: 13/13 host discoveries (boot plus every resume), no port restart on either side, 0 Oops/BUG/WARN/DART. With dynamic debug on, the role swap now logs PIPE park: mode=5 pipe=2 followed by mode=5 pipe=0: the PHY stays in USB4. Before the fix the same swap logged mode=0.

  • An idle peer was already fine before the fix (20/20 30 s s2idle).

  • M2 Air (J413, same T8112, 13.5 firmware), dcp commit: all 3 Type-C ports, both dwc3 bound, nothing deferred, USB-C DP alt to an external monitor connected, 3/3 s2idle, 0 oops/WARN/DART. Here the DCP accepts its firmware, so the new path does not run.

  • Host: tools/asahi/atc-usb3-tests.py: 38/38 cases pass. --mutations: 56/56 killed, including the one that restores the T8132-only condition, so the old code fails the new model. checkpatch --strict: 0/0/0 on both commits.

Still to run

  • One functional row (USB4 iperf, PD replug, USB-A) on the J473 with this exact head. The rows above ran on 0f111a0 (s10) and 110861f (f1). This branch is rebased onto 5746ef8 with no conflicts.
  • Regression rows for the atc commit on the other non-T8132 generations with a USB4/Thunderbolt peer or dock: J413 (T8112), J615 (T8122), M1 Pro (T6000). No row has been run on a dock with PCIe/DP tunnels; the change should keep those tunnels up when dwc3 stops, as it already does on T8132.
Mechanism and evidence detail
  • In the failing resumes, the dwc3 device-to-host swap ran atcphy_usb3_power_off(). On a non-T8132 PHY that called atcphy_configure(APPLE_ATCPHY_MODE_OFF) under the live USB4 link, and the host start then reconfigured the PHY to USB4 (atcphy_usb2_init() on mode OFF). The whole sequence took 0.3 ms with no Type-C event involved.
  • The peer's ACIO had trained to CL0 during the J473's sleep. Its next training step timed out about 6 s after the J473 resumed, its connection manager restarted the port (peer link lost with the cable attached, restarting the port (1/3)), and the link never trained again. The J473 kept a new, never-answered XDomain.
  • Hangs by entry state across all rows before the fix: port 0 host with no XDomain 6 hang / 7; device with no XDomain 0/4; with an XDomain 0/40+. Halting the port 0 xHC in s2idle did not avoid the hang (row s7), and a kernel without the s2idle control-channel retention of thunderbolt: preserve direct XDomain discovery across s2idle on awake Apple routers #2767 still hung (row s6). So neither is the cause.
  • Two local attempts at the thunderbolt side were tried and dropped: re-checking an undiscovered XDomain, and treating a silent one as gone. Restarting the port from the connection manager re-flips the roles and fought the peer's own discovery (row s9). The fix is in the PHY, where the link was being dropped.
  • dcp commit mechanism: a disabled route node makes fwnode_graph_devcon_matches() skip its endpoints, so tipd gets the atcphy mux only. A newer appledrm loaded in the same boot cannot get the routes back; that needs a reboot. A late mux bind in the typec core was considered and rejected: it regressed non-tipd typec users.
  • The original T8132 condition comes from b1be3a0 ("keep a T8132 CIO link when its USB host stops"). Its reasoning (the Type-C mux owns the CIO mode) holds on every generation.

Assisted-by: LLM (Claude:Opus 5.5)

…neration

The PHY returns to its off mode when the dwc3 host or device on the port
stops, except in a CIO mode (USB4 or Thunderbolt) on T8132, where the
Type-C mux owns the mode and takes it down when the connection ends.
Other generations power the PHY off under a live CIO link instead.

dwc3 stops for every data role swap, not only for a cable change. On the
M2 Mac mini (J473) with a host-to-host USB4 peer, a partner that leaves
and comes back during s2idle can come back with the data roles swapped.
At resume dwc3 goes from device to host, which takes the PHY off and
back to USB4 within the same millisecond, while the peer is still
training the link. The peer times out, the link never trains again,
and the XDomain is gone until the next replug or sleep. A partner event
in the next s2idle then stops the J473 for good (5 of 6 such sleeps
hung on the bench).

Nothing about this is specific to T8132: the router owns the lanes in a
CIO mode on every generation, and the PIPE is parked before the check
either way. Drop the generation from the condition. The Type-C mux
still takes a CIO mode down on a real disconnect, an ordinary USB mode
still ends with its host, and a CIO mode whose last transition failed
is still taken down.

Extend the USB3 host model: the CIO cases now run on the T8103 sequence
(which T8112 and T600x use) as well as on T8132, and a mutation that
restores the T8132-only condition is caught.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
…re is refused

A display processor whose firmware-compat is not supported fails its
probe with -ENODEV and never registers the Type-C display routes under
its node. The USB-C port controllers that name such a route as their
mode switch then wait for it for good: fwnode_typec_mux_get() keeps
returning -EPROBE_DEFER, so the port is never registered and USB2,
USB3, USB4 and the role switch stay down on every port the processor
routes, not only DP alt mode.

On the M2 Mac mini (J473) the routes of both USB-C ports sit on the
primary DCP, which refuses the 27.2 firmware: both CD321x stay in
"deferred probe pending" and neither USB-C port works at all.

The firmware cannot change before the next boot, so disable the routes
in the device tree on this refusal, as the processor failure paths that
already give up for good do (dcp_native_routes_error(),
dcp_ext_give_up(), dcp_platform_probe_t8132_ext()). The connector's
graph lookup then skips the disabled route endpoints
(fwnode_graph_devcon_matches()), the port takes the PHY mode switch
alone, and the ports come up without DP alt mode on that processor.

The routes stay disabled for the rest of the boot: a driver that
would accept the firmware gets them back after a reboot, not by
loading a newer module in the same boot.

Selected by what the device tree describes (a typec-routes child of the
refusing processor); a processor without one is unchanged.

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.

Formal adversarial §1–§6 pre-PR review at live head a9654421c21282bc4d092fa9d7b1bf04514c00c2 (against integration/aurora 5746ef8a5afd, MERGEABLE/CLEAN, CI 2/2 SUCCESS: Apple DRM KUnit / kunit, Host tests / host-tests).

Code, policy, and CI are clean; posting COMMENT rather than APPROVE solely because exact-head §5 hardware rows and cross-generation USB4/TBT regression rows remain listed under Still to run.

Checklist Audit (§1–§6)

  • §1 No model gating: Pass. Commit 1 (f1effbd17a55) removes the ATCPHY_GENERATION_T8132 generation check in atcphy_usb3_power_off() rather than adding a gate, and commit 2 (a9654421c212) is driven purely by DT typec-routes presence when dcp_check_firmware_version() returns DCP_FIRMWARE_UNKNOWN.
  • §2 Production-ready / Code review: Pass.
    • drivers/phy/apple/atc.c: Returning 0 in atcphy_usb3_power_off() when atcphy_mode_is_cio(atcphy->mode) && !atcphy->mode_dirty runs strictly after host_active = false, usb3_port_off = false, atcphy_park_pipehandler(atcphy, true), and t8103_usb3_retry = false. Leaving the PHY in a clean CIO mode preserves runtime PM ownership (atcphy_rpm_busy() stays true), lets atcphy_usb2_init() + atcphy_usb3_route() restore USB2 and re-route PIPE across role swaps without tearing down the live router link, still tears down failed CIO transitions (mode_dirty), and still lets atcphy_mux_switch(APPLE_ATCPHY_MODE_OFF) power down on real disconnect. tools/asahi/atc-usb3-tests.py cleanly extends CIO coverage to ATCPHY_GENERATION_T8103 and adds mutation usb-stop-keeps-cio-t8132-only.
    • drivers/gpu/drm/apple/dcp.c: Calling dcp_typec_routes_disable_dev(dev) on DCP_FIRMWARE_UNKNOWN matches the existing permanent give-up paths (dcp_native_routes_error(), dcp_ext_give_up(), dcp_platform_probe_t8132_ext()).
    • Non-blocking note: Other permanent -ENODEV probe refusals in dcp_platform_probe_pipe() (e.g., unsupported apple,t8140-dcpext handoff, missing IOMMU domain, or missing apple,bw-scratch) still return -ENODEV without calling dcp_typec_routes_disable_dev(dev); fine to keep this commit narrowly scoped to DCP_FIRMWARE_UNKNOWN, just worth keeping in mind if any of those ever carry typec-routes.
  • §3 Safety: Pass. No hardcoded limits or Stage-1 changes; default command line throughout.
  • §4 Clean-room & attribution: Pass. Both commits (f1effbd17a55, a9654421c212) carry human author/committer (Ryan Murray <ryan@aurorasilicon.org>) and human Signed-off-by: only, with zero AI commit trailers; Assisted-by: disclosed in the PR body.
  • §5 Evidence (remaining before APPROVE): Strong pre-rebase evidence on J473 (rows f1 on 110861f4 and s10 on 0f111a0d: 12 cycles, 6/6 role flips kept XDomain, 0 hangs vs 5/5 hangs before) and J413 (dcp commit). To convert to APPROVE, please attach:
    1. An exact-head (a9654421c212) J473 default-cmdline functional + §5 regression row (0 SELinux denials, 0 failed units, 0 new kernel errors).
    2. At least one non-T8132 regression row exercising the atc commit with a live USB4/Thunderbolt peer or dock (e.g., J413 T8112, J615 T8122, or M1 Pro T6000) to confirm disconnect/replug and tunnel/link stability on other generations.
  • §6 Naming: Pass.

Assisted-by: LLM (Gemini 4 Neon)

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.

2 participants