Skip to content

usb: typec: tipd: replug a CD321x port that kept an attach across a reboot - #3587

Merged
RyanTheTide merged 1 commit into
aurora-silicon:mainfrom
muness:fix/cd321x-kept-attach-at-boot
Nov 30, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:mainfrom
muness:fix/cd321x-kept-attach-at-boot

Conversation

@muness

@muness muness commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

What: On a J414c (M2 Max) with a Thunderbolt dock, a reboot after the dock was plugged in while Linux ran usually leaves the dock dead: no USB4 link, no displays, no USB, no charging, until the cable is pulled and plugged back. The port's CD321x reports no plug although the dock is still attached, and keeps bits 2 and 3 of its attach state (register 0x7e, byte 7). At the probe, replug such a port through the existing replug work, as pulling the cable does.
Tested: J414c M2 Max (T6021) at dde9bcb (main 1bd9c26 + this commit), -46 userspace, stock Aura b17, Surface TB4 dock with two displays. After a physical replug and a menu reboot the dock's port came up with no plug and attach state 0x3d; the probe replugged it, and the dock was back 12 s into the boot with both displays, 26 USB devices and charging. Two more replug-and-reboot cycles came up with the dock present, and the replug did not run. 0 failed units, Touch ID restored.
Risk: two-way door · Macs with CD321x port controllers (M1 and M2 families). It acts only on a port that reports no plug with both attach-state bits set. Only the J414c is tested.
Not yet: other CD321x Macs.

Details
  • Which docks get stuck: a dock attached at boot survives the reboot, and so does a dock replugged with DISC. A dock plugged in while Linux runs usually doesn't. Skipping the USB4 session close before the reboot (b3d63e0) does not change that, so it is not the cause.
  • The condition: no plug, and both bits 2 (kept attach) and 3 (attach completed with the OS running) set. Empty ports read 0x08. With bit 2 alone, a test build also replugged an empty port reading 0x04; requiring both bits leaves it alone.
  • The replug: unlocked, DISC for 5 s, locked again, through tipd_replug_work. The probe queues it under tipd_ports_lock with the check tipd_replug_request() uses, so it cannot race the port's removal.
  • The key: the board number reversed, as the J716c's is ("617J" in cd321x_inherited_boards), taken from the machine's compatible: apple,j414c gives "414J". The key travels with the queued replug only. tipd_replug_key() and tipd_replug_supported() are unchanged, so the other users of the replug (debugfs, dwc3-apple after a sleep) still need a key from the DT.
  • Related: usb: typec: tipd: idle at shutdown, recover a busy controller, native display HPD keyed on a DT property #2398 (idle at shutdown, recover a busy controller at probe) handles a controller left mid-command; it and this are compatible.
  • Credit: the replug work is DjDeveloperr's (d5d1f33), and the inherited-connection renegotiation with the J716c key is Roberto Dantas's (1a774ee).
Evidence

Reboots on the J414c with the dock left attached (first-seen time of thunderbolt 0-1 in the next boot):

Session before the reboot Restart Next boot
dock attached at boot menu reboot dock at 6 s
dock plugged in while running menu reboot, --force, emergency restart dock missing until replugged (repeatedly)
dock plugged in while running, USB4 session close skipped menu reboot dock missing
dock plugged in while running, this change at boot menu reboot attach state 0x3d, replugged at 2.4 s, dock at 12.3 s

Controller state read in a stuck boot: dock port status 0x10000000 (no plug), attach state 0x3d; empty ports 0x08. A DISC replug from the running system brought the dock back with nothing touched (attach state 0x39 after).

The same code on the J414c sleep stack: one more recovery (0x3d, dock at 12.4 s).

The boots of this kernel log an SIO crash when DisplayPort audio starts, as main without this change does on Aura b17 (see #3569).

…eboot

On a J414c (M2 Max) with a Thunderbolt dock, every reboot after the dock
was plugged in while Linux ran leaves the dock dead: no USB4 link, no
displays, no USB and no charging, until the cable is pulled and plugged
back. The port's CD321x reports no plug after the warm reset although the
dock is still attached. Bits 2 and 3 of byte 7 of register 0x7e stay set
(0x3d on the dock's port; empty ports read 0x08).

A dock attached at boot survives the same reboot, and so does a dock
replugged with "DISC". Skipping the USB4 session close before the reboot
(b3d63e0) does not change the outcome.

At the probe, replug a CD321x port that reports no plug with both bits
set, as pulling the cable does: unlocked, "DISC" for 5 s, locked again,
through the existing replug work. The key is the board number reversed,
as the J716c's is, taken from the machine's compatible. Other users of the
replug (debugfs, dwc3-apple after a sleep) still need a key from the DT.

Signed-off-by: Muness Castle <[email protected]>
@muness
muness requested review from a team as code owners November 29, 2026 01:46
@muness
muness requested review from Acelogic and maralcbr November 29, 2026 01:46

@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: MERGE at dde9bcb2 once the fork PR's CI workflows are approved and pass.

Blockers: none in code (await fork CI workflow approval and green checks).

Checked: Full 2-file diff (drivers/usb/typec/tipd/core.c, drivers/usb/typec/tipd/tps6598x.h), cd321x_board_key() bounds and NUL safety, cd321x_replug_kept_attach() condition/locking/lifecycle ordering in tipd_init(), tipd_replug_work() unlock/DISC/relock error handling, commit Signed-off-by, and exact-head J414c (T6021 M2 Max) reboot recovery proof.

Evidence
  • Condition and scope (drivers/usb/typec/tipd/core.c:79-108):
    • Strictly scoped to apple,cd321x ports that are on tipd_ports (skipping non-role-switch/MagSafe ports), report no plug (!(status & TPS_STATUS_PLUG_PRESENT)), and have both CD321X_ATTACH_STATE_KEPT (bit 2) and CD321X_ATTACH_STATE_DONE (bit 3) set in register 0x7e byte 7 (leaving empty ports at 0x08/0x04 and attached ports untouched).
    • cd321x_board_key() checks !strncmp(s, "apple,j", 7) followed by short-circuited isdigit(s[7..9]) (no out-of-bounds read on short compatibles) and leaves tipd_replug_key()/tipd_replug_supported() unchanged for debugfs and dwc3-apple.
    • Runs at probe right after tipd_port_list_add() (before tipd_debugfs_register() and tps->data->ready()), guarded by tipd_ports_lock, so tipd_port_list_del() cancels replug_work cleanly on teardown. If LOCK fails on any controller whose key differs, tipd_replug_work() skips DISC, relocks, and logs a warning without crashing.
  • Verification at dde9bcb2 (J414c M2 Max / T6021, Surface TB4 dock + 2 displays): After physical replug + menu reboot, stuck port (status 0x10000000, attach state 0x3d) replugged at 2.4 s and recovered the dock at 12.3 s (both displays, 26 USB devices, charging); 2 further replug-and-reboot cycles with the dock present did not spuriously replug; 0 failed units, Touch ID restored. Commit carries valid human Signed-off-by.
  • Non-blocking nit: Clearing tps->kept_attach_replug = false; inside the initial mutex_lock(&tps->lock) section immediately after copying kept_attach_key (instead of after the msleep + relock loop at core.c:3811) would keep all accesses to kept_attach_replug locked under tps->lock during the work execution.

@RyanTheTide

Copy link
Copy Markdown
Contributor

code-owner ping <@422957901716652033> / @DjDeveloperr: merge train at dde9bcb2. App approved (NEON-PR-REVIEW2). The probe-time replug runs on every apple,cd321x Mac, so beyond the reporting board I need one more family at this head showing it stays idle on normal ports (J413 or J316s: cold boot with and without a device attached, the ports enumerate as before, no spurious replug in dmesg). Merges under the 6-point rule after that and green CI, unless you object.

@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) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 29, 2026
@github-actions

Copy link
Copy Markdown

Merge readiness at dde9bcb2: not ready yet

Check Detail
CI at head ok no CI for this change (the hardware row is the gate)
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 dde9bcb2
Conflicts ok none
PR text ok Risk: two-way · Macs with CD321x port controllers (M1 and M2 families). It acts only on a port that reports no plug with both attach-state bits set. Only the J414c is tested.

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

dde9bcb J316s (M1 Pro, T6000) PASS: combined guarded one-shot 7.3.0-aurora-peer1+ on main 498d53fd (tipd/core.c and tps6598x.h byte-identical to dde9bcb22b0e, default cmdline, saved Stage 2 unchanged); all 4 CD321x ports (5-0038/3a/3b/3f, port0..port3, port0-partner, port1-partner) enumerated cleanly with 0 spurious replugs, s2idle 1/1 (rtc1), Enforcing, 0 AVC, 0 failed units; restored saved 7.3.0-aurora-edge.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging under the 6-point rule (Ryan 09:29, permanent), at dde9bcb2. (1) The review App approved at this head. (2) Full CI is green. (3/4) Rows: J414c-(T6021,-author)-+-J316s-(T6000)-exact-head-(PEER-ROWS-peer1). (5) There's no blocking review. (6) Dj was pinged here 1362 min ago with no objection. Revert: git revert -m 1 <merge>.

@RyanTheTide
RyanTheTide merged commit 94104a6 into aurora-silicon:main Nov 30, 2026
1 check passed
@RyanTheTide

Copy link
Copy Markdown
Contributor

Merged, thank you @muness. Your J414c (M2 Max) replug run and our J316s (M1 Pro) row at dde9bcb2 covered it, and all four CD321x ports came up with no spurious replugs.

@muness
muness deleted the fix/cd321x-kept-attach-at-boot branch November 30, 2026 01:22
RyanTheTide added a commit to jgoyvaerts/linux that referenced this pull request Nov 30, 2026
…it() harness

aurora-silicon#3587 made tipd_init() call cd321x_replug_kept_attach(). The
probe-transaction-rollback case extracts tipd_init() from tipd/core.c
but has no stub for the new call, so it fails to build and the
apple-dcp host test is red on main since 94104a6. Stub it like the
neighbouring tipd_port_list_add().

Signed-off-by: Ryan Murray <[email protected]>
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) 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.

2 participants