Repository navigation
phy: apple: t6040: USB3 on every replug and flip (stop the PHY coprocessor on detach) - #410
Conversation
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
|
Tested on a second J616s (MacBook Pro 16" M4 Pro, 48 GB; macOS 26.6.2 stub installed from Recovery, so Kernel: 7.1.12-m4.27 = 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).
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: The same sequence appears on all three PHYs ( Not tested yet: s2idle with nothing attached and then a replug (would show whether an attached device matters), and your post-review head. |
|
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. |
… 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]>
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]>
… 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]>
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:
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/aurora1aa2857509d+ 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