Skip to content

thunderbolt: apple: request USB4 Gen4 wherever the host router has it (T6040/T6041 TB5) - #2301

Draft
RyanTheTide wants to merge 1 commit into
integration/aurorafrom
m4fam/t604x-usb4-gen4
Draft

RyanTheTide wants to merge 1 commit into
integration/aurorafrom
m4fam/t604x-usb4-gen4

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The M4 Pro and M4 Max (T6040/T6041) Thunderbolt ports are Thunderbolt 5 / USB4 v2 ports, but the driver only asked the T6050 router for Gen4. On T6040 a Gen4 (80 Gb/s) cable was always described to the router as a 20 Gb/s cable (cable word 0x11), so no T6040 link could get past Gen3, whatever the partner. The choice was made by SoC (gen4_cable / gen4_link_recovery in the T6050 description only).

Change

Gen4 is now selected by what the host router reports about itself: USB4 v2 lane adapters set the Gen4 bit in the Supported Link Speeds field of LANE_ADP_CS_0; USB4 v1 routers leave it clear. The J616s (T6040) router reports it (its lane adapter target speed is 0xe = Gen2|Gen3|Gen4; the M2's is 0xc).

  • The Type-C switch records a Gen4 cable as Gen4 for every router.
  • Every place the cable word is written (first start and the two wake paths in apple-cio-sleep.c) goes through apple_nhi_cable_info(): a router without the Gen4 bit gets the 20 Gb/s word, exactly as before.
  • Gen4 link recovery is requested on every Apple host; the core (tb_switch_gen4_link_recovery()) returns early unless the link trained at Gen4.
  • gen4_cable and gen4_link_recovery are removed from apple_cio_hw. No chip list is left.

Net effect: T6050 unchanged (0x801), USB4 v1 routers unchanged (0x11), T6040/T6041 send 0x801 on a Gen4 cable.

Asymmetric 120/40 is not forced: the core already gates it on the lane adapters' asym capability and a Gen4 link, and only DP tunnel bandwidth triggers it, which is off on T6040 today. T6050 keeps QUIRK_NO_ASYM for its documented mid-transition drop; T6040 gets one only if a Gen4 row shows the same.

Testing

Still to run

  1. J616s USB4 partner row (needs the Thunderbolt cable to the M2 plugged back in): the lab cable to the M2 is a Gen4 (80G passive) cable and the M2 is Gen3, so this row checks the fallback directly. Expect cable word 0x801 in the debug log, the M2 XDomain still at 2 x 20.0 Gb/s each way, iperf3 >= 18 Gbit/s both ways, no new Dead End / link state / config timeout lines, across 3 partner hotplugs and one s2idle cycle. A drop to 10 Gb/s would mean the T6040 firmware reads the Gen4 word differently from T6050.
  2. Gen4 row (community): an M4 Pro/Max with a Thunderbolt 5 dock or a second M4 Pro/Max or M5 Pro/Max Mac and an 80 Gb/s cable. Expect rx_speed/tx_speed 40.0 Gb/s x 2 lanes.
Why the speed cannot be forced past what the link supports

The cable word only tells the router firmware what the cable carries. Link speed is negotiated by the two routers in lane initialisation from each end's supported speeds; Linux never sets a target speed (tb_xdomain_link_state_change() keeps the current target speed and only changes width) and reads the result back from LANE_ADP_CS_1 (tb_port_get_link_generation()). A Gen4 cable carries Gen3. The open question is only how the T6040 firmware reads the vendor Gen4 cable bit, which row 1 answers on the existing lab link.

Assisted-by: LLM (Claude:Opus 5.5)

The M4 Pro and M4 Max (T6040, T6041) ports are Thunderbolt 5 / USB4 v2
ports, but only the T6050 description asked its router for Gen4: the
cable word for a Gen4 cable said Gen4 (0x801) on T6050 and 20 Gb/s (0x11)
everywhere else, so T6040 links never got past Gen3, whatever the cable
and the partner.

Whether a host router can run Gen4 is in its own config space: USB4 v2
lane adapters report Gen4 in the Supported Link Speeds field of
LANE_ADP_CS_0, USB4 v1 routers leave that bit clear. The J616s (T6040)
host router reports it: its lane adapter target speed is 0xe (Gen2, Gen3
and Gen4) where the M2's is 0xc.

Select Gen4 by that bit instead of by SoC:

- The Type-C switch records a Gen4 cable as Gen4 for every router.
- When the cable word is written (first start, and the wakes in
  apple-cio-sleep.c), a router whose lane adapters do not report Gen4
  gets the 20 Gb/s word it got before.
- Gen4 link recovery is requested on every Apple host. The core only
  touches links that trained at Gen4, so nothing changes on Gen2/Gen3
  links.

T6050 keeps the word it had. USB4 v1 routers keep the 20 Gb/s word
(0x11). T6040/T6041 now send 0x801 on a Gen4 cable. The speed itself is
still negotiated by the two routers: a Gen3 partner on a Gen4 cable is
expected to train Gen3. Asymmetric links are left as they were: allowed
by the core capability checks, and only reached through DP tunnels,
which are off on T6040; T6050 keeps QUIRK_NO_ASYM for its documented
link drop.

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

Copy link
Copy Markdown
Contributor Author

Blockers: 2.

Selecting the cable word from the router's own Supported Link Speeds is the right direction. QUIRK_GEN4_LINK_RECOVERY on every host is safe: tb_switch_gen4_link_recovery() returns early when tb_port_get_link_generation(up) < 4 (drivers/thunderbolt/switch.c:3225-3227). Checked at fab82c8.

  1. drivers/thunderbolt/apple.c:2583-2598 returns false when every lane-adapter read fails (continue on error), and apple_nhi_cable_info() then silently writes the 20 Gb/s word. The function is called again on every wake (apple-cio-sleep.c:64, :297), before the router has trained. A transient config read failure there turns a T6050 Gen4 link into 20 Gb/s with only a dev_dbg line. Before this change the word was written without any read. The capability is fixed for the router, so read it once at NHI probe, cache it in struct apple_nhi, and use the cached value in the three writers. If no lane adapter could be read at probe, warn instead of guessing.
  2. The PR claims T6050 is unchanged, but nothing shows the T6050 lane adapters report the Gen4 bit in LANE_ADP_CS_0. The only number given, "target speed 0xe" on the J616s, comes from LANE_ADP_CS_1, not the CS_0 field the code tests. If T6050 leaves CS_0 bit 17 clear, every M5 Pro/Max Gen4 link drops to Gen3. On T6040, 0x801 has never been written to the router: row 1 in "Still to run" (which you can do with the lab cable) is what proves T6040 firmware accepts the word and still trains Gen3 against the M2. Merge only with both rows: log the raw CS_0 value once at probe on each SoC.
  3. Nit: the dev_dbg at apple.c:3962 now prints 0x801 on M1/M2 for a Gen4 cable even though 0x11 is what gets written. Log the word after apple_nhi_cable_info(), or say "requested".

HW row: on head: J616s plus the M2 over the 80G passive cable. The debug log shows CS_0 with Gen4, cable word 0x801, XDomain 2 x 20 Gb/s, iperf3 >= 18 Gbit/s both ways, 3 hotplugs and 1 s2idle with no link-state, config-timeout or Dead End lines. The M2 end of the same run logs 0x11 written. One T6050 owner row with a TB5 partner still at 40 Gb/s x 2. 0 AVC, 0 failed units.

Assisted-by: LLM (Claude:Opus 5.5)

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.

1 participant