Skip to content

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

Merged
RyanTheTide merged 2 commits into
mainfrom
m4fam/t604x-usb4-gen4
Dec 1, 2026
Merged

RyanTheTide merged 2 commits into
mainfrom
m4fam/t604x-usb4-gen4

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What

M4 Pro/Max (T6040/T6041) Thunderbolt 5 ports never got past Gen3: the driver asked only the T6050 router for Gen4. This picks the Gen4 cable word from the host router's own Supported Link Speeds (LANE_ADP_CS_0) instead of a SoC flag. The router capability is read once at probe and cached in struct apple_nhi, so a failed read around a wake can no longer silently drop a Gen4 router to the 20 Gb/s word.

Tested

Risk

two-way: shared Apple USB4 code. T6050 should be unchanged (it reports Gen4 in LANE_ADP_CS_0 and keeps 0x801). USB4 v1 routers (M1/M2/M3) keep 0x11. Revert = back to the SoC flag.

Not yet

  • Row at 2791740 on the J616s (Gen4 + Gen3 partner) and a K114s (T6050) regression row with the EG02: next lab window.
Original description (problem, change, follow-up rows)

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.

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 <[email protected]>
@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)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

J616s row: an RX 7900 XTX in a Thunderbolt 5 eGPU enclosure works over PCIe-C on the M4 Pro (left front port)

Kernel: main 844781f + #2069 (the T6040 PCIe-C driver and shared DT) + #3512's J616s DT change (byte-identical J616s DTB) + #2301 (USB4 Gen4 cable word), on the J616s fleet configuration and the default command line. The DTB was loaded as a one-shot Stage 2 trial. MacBook Pro 14" M4 Pro (J616s), AOOSTAR EG02 (Intel JHL9480, TB5) with a Sapphire RX 7900 XTX, 2026-11-28/29.

  • Without thunderbolt: apple: request USB4 Gen4 wherever the host router has it (T6040/T6041 TB5) #2301 the link never forms. The router gets the 20 Gb/s cable word (0x13), sends no Gen4 broadcast and logs SBX disconnected!, then goes Dead End and restarts. That happened 3 of 3 times, and the enclosure only showed up as USB2. The host router's lane adapters do advertise Gen4 (LANE_ADP_CS_0 supported speeds 0xe).
  • With thunderbolt: apple: request USB4 Gen4 wherever the host router has it (T6040/T6041 TB5) #2301: the cable word is 0x803, Gen4 trains, and the enclosure comes up as TBT5 at 2 x 40 Gb/s. PCIe-C tunnel 1 cold-initializes and links up. The JHL9480, the Navi switch and the 7900 XTX enumerate at 0001:05:00.0. BAR0 is 256 MB: there is no room for the 32 GB resizable BAR, so it falls back to 256 MB. MSI works.
  • amdgpu from main binds: PSP 13.0.0, SMU 13.0.0, DCN 3.2 + DMUB, 24 GB VRAM. radeonsi's clear readback is exact, and RADV NAVI31 works.
  • PCIe throughput through the tunnel (amdgpu SDMA benchmark, 1024 x 64 MiB): host to VRAM 48.2 Gb/s (6.03 GB/s), VRAM to host 49.6 Gb/s (6.20 GB/s).
  • Benchmarks at 1920x1080: vkmark gives 20954 on the 7900 XTX and 14115 on the M4 Pro's own GPU. glmark2 (GL) gives 7950 on the 7900 XTX and 15046 on the M4 Pro. GL shows a flat ~0.1 ms per-frame floor; see Not yet.
  • Display: the 7900 XTX's HDMI drives Weston. FurMark GL 1920x1080 ran fullscreen for 150 s at avg 338 FPS (min 282), 100 % GPU, about 340 W, junction 85 C. The capture card recorded the HDMI output.
  • Over the whole session: no Gen4 link errors, no DART faults, no PCIe-C errors.

Not yet: s2idle and a bound hot-unplug with the eGPU on this Mac. The GL per-frame latency floor needs a look (Vulkan is unaffected). Stopping GDM while mutter drove the eGPU outputs left DMUB failing (Error queueing DMUB command), and loading amdgpu after GDM was stopped avoided it. That is a display-stack follow-up, not this PR.

Evidence

Lab trace traces/gpu/20261128-j616s-egpu/ (README): plug logs before and after #2301, enumeration, bind, benchmarks, throughput, the HDMI capture frames and clip. The Mac was restored to its saved default afterwards: saved kernel booted, no one-shot pending, SELinux enforcing, 0 failed units, boot images unchanged.

@RyanTheTide
RyanTheTide marked this pull request as ready for review November 28, 2026 13:09
@RyanTheTide
RyanTheTide requested review from a team as code owners November 28, 2026 13:09

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH, then merge at fab82c82

Blockers:

  1. drivers/thunderbolt/apple.c:2583-2598: the prior review blocker remains unaddressed at fab82c82. apple_nhi_host_gen4() still re-reads LANE_ADP_CS_0 across every wake (drivers/thunderbolt/apple-cio-sleep.c:64, :297) and returns false on read failure, silently downgrading a Gen4 host router to the 20 Gb/s cable word (0x11). Cache the host router's Gen4 capability once in struct apple_nhi during apple_nhi_probe(), use the cached flag in apple_nhi_cable_info(), and warn if no lane adapter could be read at probe.
  2. PR description is missing Tested: and Risk: (two-way / one-way) lines, which will fail the queued pr-text / pr-text check. Update the PR body to include both.
  3. Wait for pr-text / pr-text and readiness / readiness CI to finish green after updating, and record a Gen3-partner / T6050 regression check once the cached probe path is in place (the 2026-11-28 J616s TB5 eGPU row already proved LANE_ADP_CS_0 0xe, cable word 0x803, and 2 x 40 Gb/s Gen4 link bring-up on T6040).

Checked: no Apple material, no AI attribution, human DCO Signed-off-by, removes the SoC-gated gen4_cable and gen4_link_recovery fields from apple_cio_hw in favor of LANE_ADP_CS_0_SUPPORTED_SPEED_GEN4 capability probing, QUIRK_GEN4_LINK_RECOVERY is safe on non-Gen4 routers (core returns early when link generation < 4), branch is MERGEABLE against main.

Evidence
  • Full diff (+68/-19 across 3 files: drivers/thunderbolt/apple.c, drivers/thunderbolt/apple-cio-sleep.c, drivers/thunderbolt/tb_regs.h) is unchanged at fab82c82 since the 2026-11-21 review comment.
  • The 2026-11-28 J616s row (AOOSTAR EG02 JHL9480 TB5 + RX 7900 XTX) confirmed LANE_ADP_CS_0 advertises Gen4 (0xe) on T6040 and that cable word 0x803 brings up a 2 x 40 Gb/s TB5 PCIe-C tunnel (48.2 / 49.6 Gb/s SDMA), answering the T6040 firmware question; caching host_gen4 at probe and updating the PR body (Tested: / Risk:) are the remaining items.
  • Non-blocking nit: dev_dbg in apple_cio_tbt_switch_set() logs the requested target_cable_info (0x801) even on Gen3 hosts where apple_nhi_cable_info() later downgrades it to 0x11.

apple_nhi_host_gen4() read LANE_ADP_CS_0 of the host lane adapters every
time a cable word was written, which includes both wake paths, and took a
failed read for "no Gen4". A read that fails around a wake then hands a
Gen4 cable on a Gen4 router the 20 Gb/s word, and the link comes back at
Gen3 with nothing in the log.

Supported Link Speeds is a property of the router silicon, so read it
once at probe, right before the first cable word, keep it in struct
apple_nhi and use the kept value from then on. Warn when none of the host
lane adapters could be read at probe, since Gen4 cables are then limited
to the 20 Gb/s word.

Also say "requested" in the USB4 cable debug line: the word logged there
is the one asked for, apple_nhi_cable_info() may still lower it.

Signed-off-by: Ryan Murray <[email protected]>

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The probe reads capability after lane unlock and before the first cable write. Both wake paths use the cached result. Unreadable adapters warn and fall back without a SoC gate. Source blocker resolved. Keep exact-head Gen4, Gen3 partner and T6050 rows and hosted CI before landing.

@github-actions github-actions Bot added area:usb Area from CODEOWNERS (bot) blast:m1 Macs affected, from Merge risk (bot) blast:m2 Macs affected, from Merge risk (bot) blast:m3 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 28, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

J616s row at 2791740 (cache-at-probe head): PASS.

  • EG02 (TB5, JHL9480) + RX 7900 XTX: lane init 0x803, Gen4 training completed, 0-1 TBT5 rx/tx 40.0 Gb/s x 2, gen 4; bridge + GPU enumerated behind the tunnel.
  • Gen3 partner on the same boot (M2 mini over USB4): 20.0 Gb/s x 2, unchanged.
  • No "no host lane adapter readable" warning, no oops/WARN, 0 failed units, SELinux enforcing.
How

One-shot of the same kernel and DT as the 11-28 row (main 844781f + #2069 + #3512 DT), with thunderbolt.ko and thunderbolt_apple.ko rebuilt with 2791740 on top and signed (modules + initramfs). Fleet default restored and verified afterwards. Still owed: K114s (T6050) regression row at the next K114s window with the enclosure.

@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Merge readiness at 27917409: not ready yet

Check Detail
CI at head ok 57 checks passed
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok in the PR body at 27917409
Conflicts ok none
PR text ok Risk: two-way · shared Apple USB4 code. T6050 should be unchanged (it reports Gen4 in LANE_ADP_CS_0 and keeps 0x801). USB4 v1 routers (M1/M2/M3) keep 0x11. Revert = back to the SoC flag.

Areas: area:usb

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

T6050 regression row (K114s, M5 Pro) at exact head 2791740: PASS.

  • Kernel: K114s bridge4 7.3.0-k114sstack3 (Image sha256 91e50e1b...), one-shot; the Apple NHI module is this PR's head built on that tree (build id 4311125e, verified loaded from /sys/module).
  • Partner: AOOSTAR EG02 (Intel JHL9480 TB5) with an RX 7900 XTX on USB-C Right, same unit and cable as the J616s row.
  • Link: 0-1 TBT5, 40 Gb/s x2, "Gen4 training completed"; no "no readable lane adapter" warning.
  • PCIe tunnel up, JHL9480 bridges + GPU + HDMI audio enumerated, amdgpu bound, radeonsi offscreen readback exact.
  • Restored to the saved default afterwards.

Unrelated to this PR, found in the same window: with the enclosure attached at boot, its internal PCIe link (JHL9480 downstream port to the GPU) trains at 8 GT/s and caps tunnel DMA at ~24-26 Gb/s; a hot-plug or a USB4 port restart retrains it at 16 GT/s (48-50 Gb/s). Tracked separately.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Closing and reopening to retrigger CI on the new aurora-buildbox runners (linux#3572 merged); no code change. Same head 2791740.

@RyanTheTide RyanTheTide reopened this Nov 29, 2026
@github-actions github-actions Bot removed the ci-failing A check failed at the PR head (bot) label Dec 1, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Merging at 279174093f28 (B2 merge train, 12-01 merge bar). Approval at this head: aurora-silicon-review[bot]. Row: the hardware row at 2791740 that the readiness check found (PR body or comment). CI: linux train L3 = main 429e7e1 + 28 approved PRs (candidate 45c2fa4b): Apple driver compile pass, Apple DTBs W=1 pass, planned KUnit dcp-fabric/dcp-topology/dcp-display/macsmc/spi-hid-apple/mt7932/asahi/sep pass; ave failed to build only because of #3153 (unused static helper under -Werror; #3153 held out) and passes with #3153 reverted from the candidate; host tests apple-dcp and apple-scaler-recovery pass. The rest of the hosted run is queued behind the backlog. Revert: git revert -m 1 <merge commit>.

@RyanTheTide
RyanTheTide merged commit ffac423 into main Dec 1, 2026
86 of 115 checks passed
@RyanTheTide
RyanTheTide deleted the m4fam/t604x-usb4-gen4 branch December 1, 2026 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:usb Area from CODEOWNERS (bot) blast:m1 Macs affected, from Merge risk (bot) blast:m2 Macs affected, from Merge risk (bot) blast:m3 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant