Skip to content

phy: apple: t6040: USB3 on every replug and flip (stop the PHY coprocessor on detach) - #410

Merged
RyanTheTide merged 2 commits into
aurora-silicon:integration/aurorafrom
jgoyvaerts:m4pro/usb-t6040-replug
Oct 24, 2026
Merged

RyanTheTide merged 2 commits into
aurora-silicon:integration/aurorafrom
jgoyvaerts:m4pro/usb-t6040-replug

Conversation

@jgoyvaerts

Copy link
Copy Markdown
Contributor

Follow-up to #403. With #403, the first USB3 attach of a boot comes up at SuperSpeed, but every replug or cable flip after it falls back to USB2: the PHY coprocessor tunes the PHY only on its first boot. Keeping it running, idling it in its RTKit session, or restarting it on the next attach all failed (the firmware never acknowledges a resume from idle).

macOS stops the coprocessor on every detach and boots it again on attach (AppleT6040TypeCPhy shutdownACIO and RTBuddy::setPowerState(0) in the disassembly; the ACIOPHY IOP goes Running -> Sleep -> Running across an unplug and replug, observed live). Two commits:

  • phy: apple: t6040: stop the PHY coprocessor on detach, as macOS does. On detach: the BIST handshake that takes the USB link side down, both TX lanes and then the common block powered down, Power Down on the application endpoint, RTKit AP and IOP to idle (waiting up to 10 ms for the CPU to idle), MXWrap STOP, then the CFG block to sleep. The RTKit state is reset after the stop, so every attach takes the boot path the first one already uses (new HELLO, then the PHY is tuned). The bring-up fallback stops a coprocessor that was started but did not come up, so the next attach can start it again; a PHY that did not wake only goes back to sleep.
  • soc: apple: rtkit: drop apple_rtkit_resume_idle(). Its only user was this PHY.

Hardware tested on: Apple MacBook Pro (16-inch, M4 Pro, 2024), J616s / T6040, macOS 26.6.2 firmware, booted by our own loader.

How tested: our daily kernel 7.3.0-m4.12 (integration/aurora 1aa2857509d + this series): a USB 3.2 Gen 1 stick plugged into each of the three USB-C ports in both orientations, 6 of 6 attaches at SuperSpeed (5000M), each with "USB3 PHY tuned ... coprocessor started" on the lane of that orientation, and no warnings. The same two commits gave 6 of 6 on our earlier kernels since 2026-10-23 (7.3.0-m4.6 on). After review, three changes were built but not booted: a PHY that does not wake now goes straight back to sleep without touching the coprocessor block, the file header describes the stop/boot design, and a log variable that only ever said "started" is gone. The normal attach and detach path is unchanged.

Not tested / limits: USB3 across a system suspend with a device attached, 10 Gbps, DisplayPort alt mode and device mode. The mailbox outbox enable that macOS clears before the stop stays as iBoot left it (the generic ASC mailbox driver never clears it).

Base: integration/aurora (1aa2857509d). Built at every commit with W=1 (CONFIG_PHY_APPLE_T6040_USB2=m): no warnings; checkpatch --strict clean.

🤖 Generated with Claude Code

Every replug or flip fell back to USB2: the coprocessor tuned the PHY on
the first attach of a boot only. Keeping it running, idling it in its
RTKit session, or restarting it at the next attach all failed.

macOS stops it on every detach (AppleT6040TypeCPhy shutdownACIO and
RTBuddy::setPowerState(0), from the disassembly; the ACIOPHY IOP state
goes Running -> Sleep -> Running across an unplug and replug, observed
live):
 - partA: the BIST handshake that takes the USB link side down, both TX
   lanes powered down, then the common block (bias override off, clamp,
   sleep);
 - Power Down on the application endpoint;
 - RTKit AP then IOP to idle, wait up to 10 ms for the CPU to idle,
   then MXWrap STOP;
 - partB: the CFG block to sleep, the AHB clock released first, ending
   with the S2R FSM enable cleared.
The next attach runs the CPU again and the firmware boots with a new
HELLO, then tunes the PHY.

Do the same. Reset the RTKit state after the stop, so every attach is
the boot path the first one already uses, and drop the resume from idle.
The bring-up fallback stops a coprocessor that was started but did not
come up, so the next attach can start it again; when the PHY itself did
not wake, it only puts the PHY back to sleep and leaves the coprocessor
block alone.

macOS also clears the mailbox outbox enable before the stop and sets it
again before the run. The generic ASC mailbox driver never clears it,
so it stays as iBoot left it.

Fixes: 1b66b0c ("phy: apple: t6040: idle the PHY coprocessor between attaches")
Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
Its only user, the T6040 PHY, now stops its coprocessor on detach and
boots it again on attach, as macOS does. Its firmware never acknowledged
a resume from idle.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
@fbalazsy

Copy link
Copy Markdown
Contributor

Tested on a second J616s (MacBook Pro 16" M4 Pro, 48 GB; macOS 26.6.2 stub installed from Recovery, so os-fw-version is mBoot-18000.161.10.701.1; own m4-loader rev 15 build).

Kernel: 7.1.12-m4.27 = jgoyvaerts/linux m4/aurora (7e0e24f72) + this PR's two commits as of 2026-10-22 (801614668, 527a79663), i.e. before your review changes. t6040_usb3_firmware_power_down() is identical to the one at 244f347d7.

Devices: a USB-C dock (VIA VL813 hub, RTL8153 Ethernet, card reader), a LaCie Rugged USB-C HDD (UAS, 5 Gbps), a Chrontel CH7213 USB-C-to-DP cable (billboard only, no DP alt mode).

Test Result
First attach on each of the three ports pass: SuperSpeed (5000M), "USB3 PHY tuned … coprocessor started" on lane 0 or 1
Detach + reattach before any system sleep (dock, DP cable; two ports) pass: back at SuperSpeed, no warnings
s2idle with devices attached on all three ports (two cycles, 32 s and 10 s, woken by the keyboard) pass: no disconnect, devices stay at 5000M, LaCie reads 130 MB/s before and 141 MB/s after
Replug after those sleeps: LaCie on all three ports, both orientations (6 attaches), plus the dock and DP cable fail: 0 of 6 at SuperSpeed, every port falls back to USB2 until reboot

The first detach on each port after the sleeps already fails to stop the coprocessor: Power Down is not acknowledged and the idle times out. Every attach after that sees a coprocessor that is still running and does not tune the PHY:

[5537.088] phy-apple-t6040-usb2 38aa90000.phy: USB3: no Power Down acknowledge: -110
[5538.112] phy-apple-t6040-usb2 38aa90000.phy: USB3: PHY coprocessor idle failed: -62
[5538.112] phy-apple-t6040-usb2 38aa90000.phy: USB3 PHY asleep: uc 0xc81 -> 0x0, cfg 0x4/0x100
[5541.800] phy-apple-t6040-usb2 38aa90000.phy: USB3: the running PHY coprocessor did not tune the PHY (uc 0x881 -> 0x881, idle 0xa0003, status 0x48)
[5543.328] phy-apple-t6040-usb2 38aa90000.phy: USB3 PHY bring-up failed (-110), USB2 only
[5555.872] phy-apple-t6040-usb2 38aa90000.phy: RTKit: Failed to send management message: -110

The same sequence appears on all three PHYs (382a90000, 38aa90000, 392a90000). Nothing PHY-related is logged during suspend or resume itself, so the coprocessor appears to stop answering its mailbox across s2idle, and the detach path then can't stop it.

Not tested yet: s2idle with nothing attached and then a replug (would show whether an attached device matters), and your post-review head.

@RyanTheTide
RyanTheTide merged commit bee7a84 into aurora-silicon:integration/aurora Oct 24, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

Tested on my J616s over the tether and merged, thanks.

The gate build on integration/aurora 1aa2857 with this PR, using our shipping config (Fedora asahi base, asahi.config, olddefconfig), builds Image, modules and dtbs clean with no new warnings.

On the machine the same PHY and RTKit code boots with m4test unchanged (14 pass, GPU skipped). A USB3 hub on the left front port comes up at 5 Gbps and its USB2 half at 480 with a 2.4 GHz dongle behind it, so the USB2 host tunable still applies at power on. No PHY, dwc3 or xHCI errors.

I also ran three software detach and attach cycles by unbinding and rebinding that port's PD controller. Every detach puts the coprocessor to sleep, every attach gets a fresh RTKit HELLO and retunes, and the hub comes back at 5 Gbps with USB2 working.

Still open is a real replug and flip test by hand on each port, which I'll do on the machine. The replug after s2idle that @fbalazsy reported (no Power Down ack, every port back on USB2) isn't covered by this and is worth a follow-up. It's no worse than before, since without this every replug fell back to USB2.

@jgoyvaerts
jgoyvaerts deleted the m4pro/usb-t6040-replug branch October 24, 2026 16:14
freber added a commit to freber/linux that referenced this pull request Nov 22, 2026
… range

Two gaps in the host tests that the rest of this series leans on.

The nine unit tests in m3/t8122_knobs.rs have never run. No file in
tools/asahi includes the module. It does not compile on its own either,
because it takes its default InitData version from m3_firmware, which
needs the kernel crate. pstate_cap_accepts_one_to_five_only, the test
that pins the range of asahi.t8122_pstate_cap, is one of them. Include
the module in tools/asahi/m3-runtime-tests.rs, the suite the kernel CI
already runs, with a stand-in for that one constant. The stand-in's
value is checked by defaults_are_the_plan_baseline, so it cannot drift
from m3_firmware without a failing test.

Policy in m3_thermal_policy.rs moves the runtime cap between the safe
cap and the ceiling. The cap_tests from aurora-silicon#410 drive it with a ceiling of
5 over a safe cap of 2. Nothing covers ceilings 6 to 8, or the check
that finds a firmware ignoring the cap. Add tests for the rules as
they are, for ceilings 6 to 8 above a safe cap of 5 and for ceilings 1
to 5:

- the cap starts at the safe cap and rises one state per 2 s on cool
  readings, never above the ceiling;
- between cool and hot it holds;
- hot lowers one state per fresh reading, at most every 500 ms, never
  below the safe cap;
- critical, no reading, a failed, stale, implausible (including the
  -2.849 C an unpowered SMC GPU key reads) or stuck reading returns to
  the safe cap at once, with the previous cap tolerated for 1 s;
- after a fallback the cap climbs again at the same pace;
- hold never leaves the safe cap;
- a ceiling equal to the safe cap never moves;
- a firmware that stays above a lowered cap is found after 20 checks
  spanning at least 3 s.

Three mutations of Policy (critical keeps the cap, the 3 s span dropped,
the raise not bounded by the ceiling) each fail one to three of the new
tests.

No driver code changes.

Link: omacom/linux-aurora#317
Link: omacom/linux-aurora#410
Signed-off-by: Fredrik Silfver <[email protected]>
freber added a commit to freber/linux that referenced this pull request Nov 22, 2026
The thermal limit moves the runtime cap only inside
Config::check_pstate. That runs after a job only in two conditions,
which a ceiling above the safe cap makes matter.

First, the job thread runs the check only when asahi.m3_retire_mmio has
bit 2 (the performance-state register read). The parameter is
root-writable at runtime, so writing 0 to 3 stops both the thermal limit
and the check that the firmware stays within the runtime cap. Once the
ceiling is above the safe cap, the runtime cap is the only thing that
keeps the firmware below the ceiling. A frozen governor would leave it
at whatever state it last allowed. Add Policy::above_safe()
(host-testable), Governor::enforces() (the limit is on or holding and
the ceiling is above the safe cap) and Config::pstate_check_required().
Run the after-job check when bit 2 is set or the check is required. Bit
2 is the T8122 default, so this forces only what runs by default. The
first retirement of a module load at which the check runs although bit 2
is clear logs one line, so a write that leaves bit 2 out is not silently
overridden.

Second, the check runs only at a retirement with no later batch in
flight. The T8122 default pipeline depth is 2. A render batch of the
same VM is published behind the running one while its passes fit the
4000 us budget. So one client that keeps submitting short passes, with
no other client rendering (a still or blanked screen, offscreen work),
can keep the check from running at all, at 90 C too. While the ceiling
is above the safe cap, pipeline_slot() now refuses a slot behind batches
in flight once the last check is 500 ms or more old
(Policy::overlap_allowed, CHECK_EVERY_NS), so the pipeline drains and
the existing checked retirement runs. The sensor is read every 500 ms
while busy, so more frequent checks would see no newer reading. The
longest time between checks is then 500 ms plus the run time of the
batches in flight. Every firmware-visible action stays where it runs
today, after the last batch has retired and the pipes are idle. The
other way, moving the cap on a pipelined retirement, would be a Globals
store with a later batch running on the GPU, which has never been done
on this firmware.

With aurora-silicon#410 the T8122 safe cap is 2, so both already apply to boots that
set asahi.t8122_pstate_cap to 3 to 5 with the thermal limit on or
holding. Those boots now drain the pipeline once per 500 ms under
sustained pipelined load. With the ceiling at the safe cap nothing
changes, since overlap_allowed() returns true before reading the clock.

New tests in m3_thermal_policy.rs simulate a client that keeps the
pipeline full (depth 1 to 4, batches of 0.1 to 50 ms). Without the bound
it is checked once, at boot, so 90 C leaves the cap at 8. With it the
longest gap between checks is within 500 ms plus the batches in flight,
the cap falls from 8 to the safe cap within that time of a critical
reading, a firmware that ignores the cap in hold mode is found. With the
ceiling at the safe cap, the publication order is identical to today's.
Three mutations of the bound each fail two to four of them.

Link: omacom/linux-aurora#317
Link: omacom/linux-aurora#410
Signed-off-by: Fredrik Silfver <[email protected]>
freber added a commit to freber/linux that referenced this pull request Nov 22, 2026
… limit

asahi.t8122_pstate_cap refuses anything above 5 (PSTATE_CAP_MAX in
t8122_knobs.rs). The stated reason is that J613 and J615 had no SoC die
temperature zone, so there was no temperature feedback above the
driver's no-feedback limit. Both boards have one now (macsmc_soc_die).
The rest of the path already exists. The firmware always gets the whole
eight-state table. With the thermal limit on, PstatePolicy::new already
makes the cap the ceiling, so only the knob range keeps the governor
below 6.

Accept 6 to 8, as the thermal limit's ceiling only. With aurora-silicon#410 below
this, the runtime cap of every T8122 boot starts at state 2 and falls
back to it, whatever the ceiling.

- asahi.m3_thermal=on (the default). The ceiling is the cap. The runtime
  cap starts at 2 and rises one state per 2 s only on usable, cool
  readings of the SoC die zone. No zone, or a failed, stale,
  implausible, stuck or critical reading, puts it back to 2 at once.
  These are the governor's existing rules.
- asahi.m3_thermal=hold. 6 to 8 are lowered to 5, with one boot line.
  The firmware gets 5 and the runtime cap stays at 2.
- asahi.m3_thermal=off. 6 to 8 are lowered to 5, with one boot line.
  aurora-silicon#410's fixed cap without the limit then gives the firmware 2. These
  values were refused before in every mode (ENODEV, no GPU for that
  boot). A cap left on the command line from a ranging boot while the
  thermal limit is switched off should not cost the GPU.

Values of 0, 9 and up are refused as before.

Whether the zone is usable can only be decided at runtime. On a J615 the
GPU firmware starts about 1.6 s into boot from the initramfs. The
macsmc_soc_die zone appears at about 7.6 s, when macsmc_hwmon registers
it. A probe-time zone check would refuse every boot, so the zone
condition is the governor's existing rule that only a usable reading
raises the runtime cap. The line the governor logs for a usable reading
now ends in "the runtime cap may rise above 2 up to N (MHz)" while the
ceiling is above the safe cap, so the boot log shows when the higher
states became possible. It is one line per change of the reading's
source, as before.

pstate_cap_use() in t8122_knobs.rs states the rules above in plain code
that the host tests drive. PstatePolicy::new gets the lowered ceiling
from admitted_cap(). Contents::select refuses the start if what
PstatePolicy::new computed is ever more than pstate_cap_use() allows, so
the two cannot drift apart silently. A host test checks that they are
equal for every cap and mode. Const assertions tie the no-feedback limit
(5) and the fallback (2) to the two constants of m3_thermal_policy.rs
that PstatePolicy::new uses. The boot lines name the case (lowered,
ranging or held) and the knob's value, which asahi.m3_max_pstate can
still lower later. When that parameter is given they say so and point to
the "firmware highest state" line, which has the result.
tools/aurora-sep/M3-GPU.md gets a paragraph on caps 6 to 8.

Tested on a J615 (15-inch M3 MacBook Air) with this series and aurora-silicon#410 on
bed544b (the 7.2 line), asahi.t8122_pstate_cap=8 and the thermal limit
at its defaults. On a cool die the runtime cap rose from 2 to 8 within
10 s of boot. Under GPU load the die passed 80 C within about 2 s at
state 8 and the cap fell back to 2 one state per 500 ms. A 600 s GPU
load and a 300 s combined CPU and GPU load ran without asahi errors,
faults or timeouts.

Link: omacom/linux-aurora#317
Link: omacom/linux-aurora#410
Signed-off-by: Fredrik Silfver <[email protected]>
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