Repository navigation
usb: bring up the J616s (T6040) tether port as a USB2 CDC device - #245
RyanTheTide wants to merge 10 commits into
Conversation
The explicit CDC-ACM debug-link handoff (usb_cdc_link_start) only covered the T8140 Gen1 SuperSpeed path, the T6050/T8152 USB2 path and the T8142 live-reuse case. The J616s (chip_id T6040, board 6, J616sAP) matched none, so a chainload or SPTM-virt boot that must preserve its inherited carrier never brought up a DWC3 device controller and the host saw no CDC port. Route the J616s ATC0 tether port through the same explicit USB2 device handoff the M5 (T6050) uses: usb_cdc_deferred_usb2() now also selects atc-phy,t6040 on this board (scoped to J616sAP so other T6040 J614s and T6041 M4 Max machines keep the generic gadget path), and usb_cdc_link_start dispatches T6040 to a new usb_t6040_init. usb_t6040_init mirrors usb_t6050_init but for the T6040 ADT: it resolves the DWC3 core (usb-drd0 reg 0), PIPEHANDLER (usb-drd0 reg 3), USB2 PHY (atc-phy0 reg 0) and the T8110 DART (dart-usb0 reg 1, mapper SID) by index and validates them by compatible and size, parks the dummy PIPE, and brings the USB2 device PHY up from the ADT's own tunable_USB2PHY_DFLT/DEV. The qualified high-speed path leaves the ATC PHY in its initial state and needs neither the event-counter bank the M5 writes nor the ACIO SuperSpeed PHY processor; a USB2-only or forced-full-speed link runs at full speed. SuperSpeed stays unqualified (it needs the CIO80 ACIOPHY processor brought to tunables-done).
Two problems kept the J616s tether gadget from enumerating after the USB2 CDC handoff: - T6040's PIPEHANDLER MUX_CTRL has no bit 6. Writing the M5's 0x42 reads back as 0x02, so the step-2 check failed every time. On this SoC the dummy USB2 route is 0x22, the value the generic port bring-up already writes. Program and check that instead, and say so on the console when the route doesn't latch. - The ADT USB2 PHY tunables leave the PHY's role bits (SIG[14:12]) in host mode. The controller then ran with no device pull-up and the host never saw a connect. Clear the host bits before forcing VBUS, as device mode needs. Tested on a J616s chainloaded over the KIS proxy with a macOS host on the debug port. The device enumerates as 1209:316d at 480 Mb/s within about 2 s of cdc_schedule(1000, 0), and proxy reads run at about 17 MB/s (KIS: 0.65 MB/s). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The high-speed DWC3 engine always advertised 512-byte bulk endpoints. That's invalid at full speed (USB 2.0 9.6.6 caps full-speed bulk packets at 64 bytes), so a host or hub limited to 12 Mb/s could not use the CDC device. The engine now picks the bulk packet size from the speed in DSTS at ConnectDone: 512 at high speed, 64 at full speed. It resizes the bulk endpoints with a DEPCFG modify and serves a matching configuration descriptor. The ZLP check follows the same size. At high speed the descriptor and endpoint setup are unchanged. USB2 CDC targets also accept one schedule flag, USB_CDC_USB2_FULL_SPEED (BIT(3)), which makes the controller advertise full speed. That lets the full-speed path be tested on a high-speed host. The proxy's flag range grows from 0-7 to 0-0xf to carry it; the T8140 state machine still rejects anything outside bits 0-2. Tested on a J616s with a macOS host. With the flag, the device enumerates at 12 Mb/s and proxy reads run at 1.10 MB/s with an exact 4 MiB write/readback. Without it, the same build enumerates at 480 Mb/s and runs as before (17.7 MB/s reads). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The harness now models DEPCFG resizes and the DSTS speed. It checks that a high-speed connect leaves the 512-byte bulk endpoints alone, that both full-speed DSTS encodings resize every bulk endpoint to 64 bytes and still re-arm SETUP, and that a later high-speed connect restores 512. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Hardware evidence for a09e30d (code identical to 11fcc66), J616s with a macOS host on the debug port. Host ioreg for the enumerated device: aura console on each run: Before the two T6040 fixes, the same flow stopped at step 2 ( 🤖 Generated with Claude Code |
The explicit USB2 CDC handoff for T6040 was gated on the chip id, board id and the J616sAP target. Select it by the tether port's hardware instead: any machine whose /arm-io/atc-phy0 is atc-phy,t6040 takes the deferred USB2 path, and usb_cdc_link_start() dispatches to usb_t6040_init() on the same compatible rather than on chip_id. usb_t6040_get_regs() still refuses a port whose DRD, DART, port numbers or register sizes do not match. On the J616s nothing changes: its atc-phy0 is atc-phy,t6040, so it takes the same path as before. Also fix the comment that called the J616s a Mac mini; it is the 16-inch MacBook Pro. Signed-off-by: Ryan <ryan@aurorasilicon.org>
On a USB2 connect at full speed the bulk endpoints are resized to 64 bytes. If a resize failed, the code only logged it and still recorded the new packet size, so the configuration descriptor could advertise a size the endpoints do not have. Stop the controller and report the link as failed instead, as the SuperSpeed path already does on a mode mismatch, and cover the case in the HS session harness. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
DjDeveloperr
left a comment
There was a problem hiding this comment.
Thanks, Ryan. The T6040 handoff itself reads well:
usb_t6040_get_regs()resolves everything from the ADT and checks it by compatible and size;- the MUX_CTRL 0x22 and USB2PHY SIG role fixes are backed by the J616s read-backs;
- the full-speed DEPCFG resize drops the link if it fails;
- the hardware rows at 480 and 12 Mb/s are clear.
Two things hold it.
1. Adding atc-phy,t6040 to usb_cdc_deferred_usb2() turns off the generic USB path on every M4 Pro and M4 Max. That predicate isn't only "use the explicit USB2 handoff". It also makes usb_init(), usb_iodev_init(), usb_phy_bringup() and usb_iodev_bringup() return early (src/usb.c:540, :587, :711, :786 at 456b58f). The comment above it says so: "Never run the older automatic gadget initialization on them, including when the explicit setup is refused." On T6050 that's deliberate. But src/kboot_atc.c:1205 notes that the J614c and J616c have the J614s's ATC, also atc-phy,t6040. On all of them, a boot without the debug carrier would lose the USB gadget and proxy that docs/j616s-bringup.md qualified at 480 Mb/s. If usb_t6040_get_regs() refuses a board's layout, that board has no USB device path at all.
Suggested shape: split the two meanings. Keep usb_cdc_deferred_usb2() as "never run the generic gadget" (T6050 only), and add a second predicate for "this port takes the explicit USB2 CDC handoff". usb_cdc_link_start() (:872) and usb2_target() in usb_cdc.c:22 would test the new predicate, which usb_atc0_phy_is_t6040() already gives you.
2. DCO. docs/licensing.md asks for a Signed-off-by on new contributions. 640d9ff, ea1e97c, 11fcc66 and a09e30d have none. 1d34eae and 456b58f have one.
Once both are in, the J616s CDC re-run on the new head can come after the merge, with a J614s or J616c boot showing the normal USB proxy still enumerates.
|
Blockers: 1 (beyond the open review).
Commits 640d9ff, ea1e97c, 11fcc66 and a09e30d carry HW row: on the new head, a J616s CDC run at flags 0 and 0x8 as in the table, then a flags-0 run in the same boot showing 480 Mb/s again. Plus a J614s or J616c boot without the debug carrier showing the generic USB proxy still enumerates at 480 Mb/s. Assisted-by: LLM (Claude:Opus 5.5) |
|
Still needed: split usb_cdc_deferred_usb2() so atc-phy,t6040 selects the explicit CDC handoff without turning off the generic gadget on M4 Pro/Max, and stop the full-speed request from leaking into later gadget inits; commits 640d9ff, ea1e97c, 11fcc66 and a09e30d need re-committing with a human Signed-off-by only (no Co-Authored-By). feat/sptm-hv is already on main, so retarget onto main and merge it (conflicts in docs/sptm-nv2-virt.md, proxyclient/tools/run_guest_sptm.py and tests/python/test_usb_hs_session.py). Then the J616s CDC runs at flags 0 and 0x8 on the new head, and a J614s or J616c boot without the debug carrier showing the generic proxy still at 480 Mb/s. |
There was a problem hiding this comment.
Formal §1–§6 pre-PR checklist re-review at head d33f3196fea7c393a11a7b2805f6cc7a3a04d3d0.
This PR touches Stage 1 (src/usb.c, src/usb_cdc.c, src/usb_dwc3.c, src/usb_dwc3_impl.inc, src/proxy.c are compiled unconditionally into every Stage 1 flavour via Makefile), and none of the previously requested changes from 456b58fd have landed yet (the only commit since is the automated github-actions[bot] policy commit d33f3196). In addition, a deeper audit of usb_t6040_init() turned up two T6040 PIPEHANDLER hardware bugs.
Blocking issues
-
§1 / §3 —
usb_cdc_deferred_usb2()still disables the generic USB gadget on everyatc-phy,t6040Mac (src/usb.c:174-188).
Addingatc-phy,t6040tousb_cdc_deferred_usb2()causesusb_init(),usb_iodev_init(),usb_phy_bringup(), andusb_iodev_bringup()to return early on every M4 Pro / M4 Max withatc-phy,t6040(J614s, J616s, J614c, J616c). On any normal boot without an inherited debug carrier (or any board whereusb_t6040_get_regs()rejects the layout), those Macs lose their 480 Mb/s USB gadget/proxy. Split "never run the generic gadget" (usb_cdc_deferred_usb2(), T6050 only) from "supports the explicit USB2 CDC handoff" (checked byusb2_target()insrc/usb_cdc.candusb_cdc_link_start()insrc/usb.c). -
§2 / §3 (new) —
usb_t6040_init()uses T6050/T8142PIPEHANDLER_MUX_CTRLbitmasks (0x73/0x70/0x03) on T6040's T8103-layout register (src/usb.c:254, 264, 280, 285-296).
T6040 uses the T8103MUX_CTRLlayout (CLKin bits[5:3]=0x38,DATAin bits[2:0]=0x07, combined mask0x3f, wherePIPEHANDLER_MUX_CTRL_DUMMYis(4 << 3) | 2 = 0x22andPIPEHANDLER_MUX_CTRL_USB3is1 << 3 = 0x08). Keeping T6050's[6:4]/[1:0]masks (0x73/0x70/0x03) causes two real bugs:read32(pipe + PIPEHANDLER_MUX_CTRL) & 0x73masks off bit 3 (0x08,USB3clock) and bit 2 (0x04). A native USB3 PIPE producer (0x08) withDWC3_RESET_N == 0reads back as0, silently bypassing the safety guard against touching an active/unknown PIPE producer.mask32(..., 0x70, 0),mask32(..., 3, 2), andmask32(..., 0x70, PIPEHANDLER_MUX_CTRL_DUMMY & 0x70)never clear bit 3 or bit 2. Any pre-existing bit 3 (0x08) survives intoMUX_CTRL(yielding0x2a, invalid CLK=5), and the readback check(read32(...) & 0x73) != PIPEHANDLER_MUX_CTRL_DUMMYmasks off bits3:2so it silently passes.
Use0x38/0x07/0x3f(matchingPIPEHANDLER_MUX_CTRL_CLK_T8103/DATA_T8103in open#479'ssrc/usb_atc_regs.h), and drop the unreachable0x42checks on T6040.
-
§3 (new) —
usb_t6040_init()reads DWC3 registers while DWC3 is held in reset whenmux == 0x22(src/usb.c:262-279).
if ((aon & PIPEHANDLER_AON_GEN_DWC3_RESET_N) || mux == 0x22)was copied fromusb_t6050_init(), where0x42is the parked dummy state and0x22is an older loader's released state. On T6040,0x22is the parked dummy state. If a prior stage leftDWC3_RESET_N == 0withmux == 0x22, this branch enters the retired-gadget check and readsregs.dwc + DWC3_GCTL/DCTL/DSTS/DEVTEN/DALEPENAwhile DWC3 is in reset (risking a bus error or reading zeroes and failingretiredon a cleanly parked port). Only inspect DWC3 registers whenaon & PIPEHANDLER_AON_GEN_DWC3_RESET_Nis set; whenDWC3_RESET_N == 0, acceptmux == 0 || mux == 2 || mux == PIPEHANDLER_MUX_CTRL_DUMMY. -
§2 / §3 — Global
usb_dwc3_usb2_full_speedleaks across subsequent gadget inits (src/usb_cdc.c:75,src/usb_dwc3.c:6,src/usb_dwc3_impl.inc:2001-2003).
Setting a sticky global inusb_cdc_schedule()without clearing it on consumption,usb_cdc_cancel(), orusb_cdc_cleanup()(note merged#478now resetsUSB_CDC_SCHEDULEDinusb_cdc_cleanup()) means any later HSusb_dwc3_init()— including generic gadget bring-up — inherits 12 Mb/s full speed. Pass the requested speed explicitly into the CDC init path (or consume/reset it strictly inside the explicit CDC start path) so it cannot leak. -
§4 — Attribution, DCO, and bot commit on PR branch.
- Missing human
Signed-off-by:on640d9ffb,ea1e97cd,11fcc66e,a09e30d3(and merge commit07dd30f9). - Forbidden AI
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>trailers inea1e97cd,11fcc66e,a09e30d3. - Bot commit
d33f3196(gfya, authored bygithub-actions[bot]) deletes.github/copilot-instructions.md,AGENTS.md,CLAUDE.md,GEMINI.mdand has no humanSigned-off-by:.
Rebase cleanly ontomainas human-authored commits with humanSigned-off-by:only and zero AI trailers in commits (keepingAssisted-by:at the end of the PR body, which is already fine).
- Missing human
-
Base branch & Live CI (
statusCheckRollupempty; zero passing checks ond33f3196).- This PR still targets
feat/sptm-hv(392 commits behindmain; conflicts withmainintests/python/test_usb_hs_session.py, and overlaps open#479insrc/usb.c/src/usb_cdc.c). - Because
build,test,format-check, andstage1-sizeonly trigger onpull_requesttargetingmain, none of them have ever run on this PR, and the two workflows that did trigger (aurora-agent-policyandesp-stage2-size) ended inaction_requiredon the bot pushd33f3196. - Retarget to
main, dropd33f3196, and get a full green CI run on the new head — especiallystage1-sizeacross all toolchains, since this PR adds ~300 lines to unconditional Stage 1 objects (usb.o,usb_dwc3_hs.o,usb_cdc.o,proxy.o). (Sharing the common ADT/PHY bring-up helper betweenusb_t6040_init()andusb_t6050_init()would also avoid duplicating ~140 lines into Stage 1.)
- This PR still targets
-
§5 — Hardware & Stage 1 evidence owed on the final
main-based head.- Current J616s hardware numbers are from stale SHA
a09e30d3(prior to1d34eaef,456b58fd, and the fixes above). - On the rebased final head, please record:
- J616s: cold + warm boot, both Type-C cable orientations,
flags=0(480 Mb/s),flags=0x8(12 Mb/s), and a follow-upflags=0verifying full-speed does not leak. - Other
atc-phy,t6040Mac (J614s or J616c): normal boot without the debug carrier proving the generic 480 Mb/s USB gadget/proxy still enumerates. - Stage 1 safety: green
stage1-sizeheadroom across toolchains + Stage 1 owner sign-off before merge (§3).
- J616s: cold + warm boot, both Type-C cable orientations,
- Current J616s hardware numbers are from stale SHA
Minor note (non-blocking)
- In
src/usb_dwc3_impl.inc:1666, ifusb_dwc3_ep_reconfigure_mps()fails on a generic USB2 port (onceusb_cdc_deferred_usb2()is split), callingusb_cdc_link_failed()mutatescdc.stateand logs a VDM recovery message meant for the explicit CDC handoff, and leavesdev->failed == false. Settingdev->failed = true(in addition to clearingRUN_STOP) and only callingusb_cdc_link_failed()when appropriate would keep the failure local to that controller.
(Clean-room §4 and naming §6 checks pass.)
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at d33f3196fea7
Blockers:
src/usb.c:148: addingatc-phy,t6040tousb_cdc_deferred_usb2()also makesusb_init()(:540),usb_iodev_init()(:587),usb_phy_bringup()(:711) andusb_iodev_bringup()(:786) return early. So everyatc-phy,t6040Mac (J614s, J616s, J614c, J616c) loses the generic USB gadget and proxy on a boot without the inherited debug carrier, which is the path qualified at 480 Mb/s on the J616s. Fix: keepusb_cdc_deferred_usb2()for T6050 only, and testusb_atc0_phy_is_t6040()(you already have it) inusb_cdc_link_start()andusb2_target()for the explicit handoff.- Commits:
ea1e97cd,11fcc66eanda09e30d3carry aCo-Authored-By:trailer naming an AI tool.640d9ffb,ea1e97cd,11fcc66e,a09e30d3and the merge07dd30f9have noSigned-off-by. The bot commitd33f3196("gfya") deletesAGENTS.md,CLAUDE.md,GEMINI.mdand.github/copilot-instructions.md. Fix: rebase ontomainas signed commits without the trailers or the bot commit. That also retargets the PR tomain, so build, test and stage1-size run for the first time.
Checked: no Apple material. The T6040 registers are resolved from the ADT and checked by compatible and size, the USB2 PHY tunables come from the ADT, and the J616s rows at 480 and 12 Mb/s are clear. This is Stage 1 code, so it needs a J616s row at the rebased head before it merges. This replaces my earlier reviews. Of the five points in the last one, only these two are shown. I've folded the other three below as questions.
Evidence
Read src/usb.c, src/usb_cdc.c and src/usb_dwc3_impl.inc at d33f3196. Questions, not blockers; please check them on the J616s when you re-run the row:
usb_t6040_init()masksMUX_CTRLwith the T6050 fields (& 0x73,mask32(..., 0x70, ...), :378, :409, :415). If the T6040 register uses the T8103 layout (clock in bits 5:3, data in 2:0, so0x22= dummy), bit 3 is neither read nor cleared there.- With
DWC3_RESET_Nclear andmux == 0x22(:386), the retired check reads DWC3 registers while the core is held in reset. usb_dwc3_usb2_full_speedis only set inusb_cdc_schedule()and never cleared on cancel or cleanup.
Superseded by the review at d33f319
|
Merge readiness at
Areas: none matched in CODEOWNERS Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
Revert the automated agent-policy bot commit d33f319 that deleted assistant instruction files on this PR branch. The policy workflow has since been updated (aura#475) to stop pushing to PR branches. Signed-off-by: Dj <43033058+DjDeveloperr@users.noreply.github.com>
There was a problem hiding this comment.
Verdict: FINISH, then merge at dff7d434
Blockers:
src/usb.c:148: prior Stage 1 review blocker remains unaddressed atdff7d434(Revert "gfya"only reverted the stray policy-bot commit). Addingatc-phy,t6040tousb_cdc_deferred_usb2()still causesusb_init(),usb_iodev_init(),usb_phy_bringup(), andusb_iodev_bringup()to return early, turning off the generic gadget on allatc-phy,t6040Macs, and the full-speed request leak into later gadget inits remains open.policyCI check is failing atdff7d434, earlier commits lack humanSigned-off-by, and the PR targets non-mainbasefeat/sptm-hv.- Missing exact-head hardware row (including Stage 1 size verification) and PR
Tested:/Risk:lines.
Checked:
- Commit history (
d33f3196,29a68eb5,dff7d434), CI status (3/4,policy=FAILURE), and prior review blockers onsrc/usb.c/ Stage 1 impact.
Evidence
- Head:
dff7d43427eb(base: feat/sptm-hv,mergeable: MERGEABLE,+420/-19).
|
Stage 1 disposition: preserve the generic gadget when there is no inherited debug carrier. Select the explicit CDC handoff from the ADT PHY capability and scope the full-speed request to that session. The carry-forward branch needs the author-signed series on main, then J616s explicit 480/12 Mb/s coverage and a second-family generic-gadget regression, including a real Stage 1 install row. |
|
Carried forward onto |
usb: bring up the J616s (T6040) tether port as a USB2 CDC device (carry-forward of #245)
Problem
The explicit CDC-ACM debug-link handoff (
usb_cdc_link_start) handled only three cases: theT8140 Gen1 SuperSpeed path, the T6050/T8152 USB2 path and the T8142 live-reuse case. The J616s
(
chip_idT6040, board 6,J616sAP) matched none of them. So on a chainload or SPTM-virtboot that has to keep its inherited carrier, aura never brought up a DWC3 device controller and
the host saw no CDC serial port. The generic auto-gadget path (
usb_init) can't cover this,because it is skipped while the debug carrier is live and would retire the inherited proxy.
Change
The J616s ATC0 tether port now goes through the same explicit USB2 device handoff as the M5
(T6050):
usb_cdc_deferred_usb2()also selectsatc-phy,t6040, the ATC0 PHY compatible.usb_cdc_link_startsends T6040 to a newusb_t6040_init. It resolves the DWC3 core,PIPEHANDLER, USB2 PHY and T8110 DART from the ADT by index and checks them by compatible and
size. It then parks the dummy PIPE and brings the USB2 device PHY up from the ADT's own
tunable_USB2PHY_DFLT/DEV.0x22, the value the generic port bring-up already writes.
without that there is no pull-up and the host never sees a connect.
which is invalid at 12 Mb/s. At ConnectDone it now takes the speed from DSTS. At full speed it
resizes the bulk endpoints to 64 bytes with a DEPCFG modify and serves a matching
configuration descriptor, and the ZLP check follows. High-speed setup is unchanged. USB2 CDC
targets accept one schedule flag,
USB_CDC_USB2_FULL_SPEED(BIT(3)), which advertises fullspeed so this path can be tested on a high-speed host. The proxy's flag range grows to 0-0xf,
and the T8140 state machine still rejects anything outside bits 0-2.
The T6040 path is now selected by the tether port's
atc-phy,t6040PHY compatible in the ADT instead of the chip id, board id andJ616sAPtarget (1d34eae); the J616s takes the same path as before, but a J616s CDC re-run on this head is still owed.Hardware results (J616s, macOS host on the debug port)
aura was chainloaded over the KIS proxy, then
cdc_schedule(1000, flags)was sent over KIS. Inevery row the device enumerated 2.1 s later as 1209:316d "Aurora Silicon / Generic CDC". The
first ACM port answered as the proxy primary (
iodev_whoami= USB0,cdc_status0x502).For comparison, the KIS carrier the handoff replaces reads at 0.65 MB/s on the same runs. Each
row was re-run from a fresh reboot.
SuperSpeed is not part of this change. On T6040 it needs the ACIO (CIO80) PHY processor
brought to firmware tunables-done. Until then the USB3 link never trains, and the host's
SuperSpeed port saw no connect during these runs.
Tests
tests/python/test_usb_hs_session.pynow covers the speed handling. A high-speed connectleaves the bulk endpoints alone. Both full-speed DSTS encodings resize every bulk endpoint to
64 and still re-arm SETUP. A later high-speed connect restores 512.
test_cdc_state,test_cdc_bulk,test_cdc_ss_desc,test_debugusb_proxy,test_usb_shutdown_retirement,test_usb_dma_reserve,test_usb_hs_session). The fulltests/pythonrun gives the same totals before and afterthe change.
CHAINLOADING=1 BUILDSTD=1 USE_CLANG=1builds clean, andclang-formatis clean on thechanged files.
test_usb_hs_session.pycovers the failed-resize case.Still to run