Repository navigation
usb: bring up the J616s (T6040) tether port as a USB2 CDC device (carry-forward of #245) - #573
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). (cherry picked from commit 640d9ff) Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
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). (cherry picked from commit ea1e97c) Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.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). (cherry picked from commit 11fcc66) Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.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. (cherry picked from commit a09e30d) Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
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> (cherry picked from commit 1d34eae) Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
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> (cherry picked from commit 456b58f) Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
Adding atc-phy,t6040 to usb_cdc_deferred_usb2() made usb_init(), usb_iodev_init(), usb_phy_bringup() and usb_iodev_bringup() return early, so every atc-phy,t6040 Mac lost the generic gadget and proxy on a boot without the inherited debug carrier. Keep the deferral for the T6050 PHY only. The explicit USB2 CDC handoff (usb2_target(), usb_cdc_link_start()) selects usb_t6040_init() by the ATC0 PHY compatible, and refuses while a generic gadget owns USB0. The full-speed request set by usb_cdc_schedule() is now cleared on cancel and cleanup, so it cannot leak into a later gadget initialization. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
There was a problem hiding this comment.
Verdict: FINISH at fc4d6c6
Checked: T6040 keeps the generic gadget and uses the PHY compatible for the explicit CDC handoff. Cancel and cleanup clear the full-speed flag.
Blocker: The flag is global and set when scheduling, before the explicit handoff owns the gadget. usb2_failed leaves it set, including when usb_cdc_link_start refuses because USB0 is already owned. The shared high-speed initializer reads the flag. Scope speed to the explicit initialization, or consume and clear the flag on success and all failure exits. Add a refused-start case and retain the 480/12 Mb/s and carrier-less generic-gadget rows on J616s.
usb_cdc_schedule() sets the global full-speed request before the explicit handoff owns the gadget, and only usb_dwc3_init() reads it. Clear it right after usb_cdc_link_start() returns, so neither a successful start nor a refused one (USB0 already owned by the generic gadget) leaves it set for a later high-speed initialization. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
There was a problem hiding this comment.
Verdict: MERGE at cf2cd31 after the integration gates below.
Checked: The shared full-speed flag now clears immediately after usb_cdc_link_start returns and before either the refused-start exit or downstream routing. The ordering test covers the refused exit, and cancel and cleanup retain their clears. Source approval. Keep hosted CI, the exact J616s 480/12 Mb/s and carrier-less checks, the second-family regression and owner-authorized Stage 1 evidence.
|
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. |
|
J616s row at
Fix direction: keep the generic gadget off USB0 on T6040 while the inherited DockChannel/KIS carrier is in use (for example, also skip in |
On the J616s (T6040), a proxy window opened on the inherited DockChannel (KIS) carrier brought the generic gadget up on USB0 through uartproxy_wait_stage1(). usb_cdc_link_start() refuses while USB0 is owned, so cdc_schedule() failed at step 1 (cdc_status 0x103) and the explicit 480 and 12 Mb/s handoff never started. Skip the generic bring-up in that window when the ATC0 PHY is the T6040 one and a DockChannel host is present: the carrier is the window's transport. Window boots without that carrier still bring the generic gadget up. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
There was a problem hiding this comment.
Verdict: HOLD at 96724fd1 pending build and transport validation.
Blockers: Confirm the normal and debug proxy build configurations link, since the new call is unguarded in uartproxy.c and the helper implementation is compiled only with DEBUGUSB_PROXY. Confirm the J616s carrier-present 480/12 Mb/s CDC handoff and a carrier-less generic-gadget window in the owner-authorized row.
Checked: The generic initialization branch remains reachable when no DockChannel host has been seen. The new source assertion checks placement of the skip but does not exercise the transport state.
The installed Stage 1 leaves the T6040 PIPE released (mux 0x22) with the DWC3 still held in reset (aon 0). usb_t6040_init() then read the DWC3's registers to prove it stopped, which a core in reset can't answer, and refused the explicit CDC handoff at step 2 (J616s row 2026-11-30, 0x203: 'T6040 PIPE consumer is not retired (aon=0 mux=22)'). A core held in reset produces nothing, so accept that state as it is. A core out of reset must still prove it is stopped, and T6050 is unchanged. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
There was a problem hiding this comment.
Verdict: FINISH at 926f9aa4.
Blockers: Guard the dockchannel_uart_host_seen() call in uartproxy_wait_stage1() with the same DEBUGUSB_PROXY condition as the implementation, or provide an explicit false stub for normal builds. The call is unconditional in this function and the header declares it in every flavour, while the definition only exists in debug builds. The new reset change leaves that dependency in place. Please verify links for both production and debug flavours. The six focused host tests check source structure and do not exercise linking.
Checked: The reset-held T6040 path now skips DWC3 register reads in the reported mux state. A core out of reset still needs to pass the stopped-device checks. All six focused source tests passed locally. Re-run the J616s carrier-present 480 and 12 Mb/s cases and the carrier-less gadget case at the resulting head. Keep the second-family regression and owner Stage 1 validation tracked in the PR.
There was a problem hiding this comment.
Verdict: FINISH at 926f9aa48406
Blockers:
- Broken link on all non-
DEBUGUSB_PROXYbuilds (src/uartproxy.c:100):uartproxy_run()callsdockchannel_uart_host_seen()unconditionally (} else if (usb_cdc_t6040_usb2() && dockchannel_uart_host_seen()) {), butdockchannel_uart_host_seen()is only compiled under#ifdef DEBUGUSB_PROXY(src/dockchannel_uart.c:285-291, declared/* DEBUGUSB_PROXY builds only. */insrc/dockchannel_uart.h:26-27). This brokebuild,gcc,ESP stage 2 vital size,clang-macos,fedora, andalarmat96724fd1and remains unfixed at926f9aa48406. Guard the call insrc/uartproxy.cwith#ifdef DEBUGUSB_PROXY(matching the pattern used elsewhere) or provide astatic inline bool dockchannel_uart_host_seen(void) { return false; }#elsestub insrc/dockchannel_uart.h. - Exact-head hardware verification & CI: Once the link fix is pushed and hosted CI finishes green across all build flavours, post the exact-head J616s carrier-present (
480and12 Mb/sCDC handoff) and carrier-less generic-gadget hardware rows (plus second-family regression and owner-authorized Stage 1 row as noted in the PR body).
Checked:
- Verified
926f9aa48406(src/usb.c:405-428andtests/python/test_usb_t6040_generic_gadget.py): accepting!(aon & PIPEHANDLER_AON_GEN_DWC3_RESET_N) && mux == 0x22as already retired before readingregs.dwc + DWC3_GCTLavoids reading registers of a DWC3 held in reset while still requiring the full stopped-device register proof wheneverDWC3_RESET_Nis deasserted, and still rejecting unknown PIPE producers (muxnot in{0, 2, 0x42}). - Verified
src/dockchannel_uart.h,src/dockchannel_uart.c,Makefile, andsrc/uartproxy.cat926f9aa48406.
Evidence
src/uartproxy.c:100: unguarded call} else if (usb_cdc_t6040_usb2() && dockchannel_uart_host_seen()) {compiles in all builds, including non-DEBUGUSB_PROXY(SECBOOT_FLAVOUR=secure, release, gcc, clang-macos, fedora, alarm).src/dockchannel_uart.c:285-291:dockchannel_uart_host_seen()is inside#ifdef DEBUGUSB_PROXY, andsrc/dockchannel_uart.h:26-27only declares a prototype with no#elseinline stub.- Non-blocking nit: in
src/usb.c:407,else if ((aon & PIPEHANDLER_AON_GEN_DWC3_RESET_N) || mux == 0x22)can simplify toelse if (aon & PIPEHANDLER_AON_GEN_DWC3_RESET_N)now that!(aon & PIPEHANDLER_AON_GEN_DWC3_RESET_N) && mux == 0x22is handled by the precedingif.
dockchannel_uart_host_seen() exists in DEBUGUSB_PROXY builds only, so the T6040 carrier check in uartproxy_wait_stage1() failed to link a release ESP Stage 2 (ld.lld: undefined symbol: dockchannel_uart_host_seen). Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
|
Fix for the 0x203 refusal in the second J616s row, plus a link fix:
Tested: the new host test fails before the fix and passes after; full host pytest passes (1472). clang builds pass for release ESP Stage 2 (with and without DEBUGUSB_PROXY), SPTM_VIRT/AURACTL and default Stage 1. fedora:44 |
There was a problem hiding this comment.
Verdict: MERGE at 575abc32 after hosted checks and transport validation.
Blockers: Keep the exact-head J616s 480 and 12 Mb/s carrier-present runs, the carrier-less generic gadget check, the second-family regression and owner Stage 1 validation.
Checked: The new guard removes the debug-only helper call from the normal build. I preprocessed the branch with and without DEBUGUSB_PROXY and checked that both variants retain the T8140 scheduling branch and generic USB fallback. All six focused source tests passed at this head. The earlier reset-held T6040 fix is unchanged.
|
J616s (M4 Pro, T6040) row at 575abc3: explicit CDC FAIL (step 1), carrier-less boot OK. Two fixes needed; both tested on the J616s as local builds (not pushed). Tested: J616s, one-shot aura-try of the Stage 2 with only the aura head swapped onto the live a98f3d09 tail, booted by a VDM
926f9aa works: with the step-1 refusal out of the way the console shows
@@ usb_dwc3_cdc_start_bulk_out_xfer
#if !USB_DWC3_SUPERSPEED
memset(dev->endpoints[endpoint_number].xfer_buffer, 0xaa, XFER_SIZE);
-#endif
- usb_dwc3_start_bulk_transfer(dev, endpoint_number, XFER_SIZE);
+ usb_dwc3_start_bulk_transfer(dev, endpoint_number,
+ dev->bulk_mps == CDC_FS_BULK_PACKET_SIZE ? CDC_FS_BULK_PACKET_SIZE
+ : XFER_SIZE);
+#else
+ usb_dwc3_start_bulk_transfer(dev, endpoint_number, XFER_SIZE);
+#endif
@@ usb_dwc3_cdc_copy_bulk_out_progress (!USB_DWC3_SUPERSPEED)
- if (remaining > XFER_SIZE)
+ if (remaining > dev->endpoints[ep].transfer_length)
return false;
- size_t bytes = XFER_SIZE - remaining;
+ size_t bytes = dev->endpoints[ep].transfer_length - remaining;Not mergeable at 575abc3. Once both fixes are on the branch, re-run hs/fs/plain at the new head with the same kit. |
There was a problem hiding this comment.
Verdict: FINISH at 575abc32. This supersedes my earlier code approval.
Blockers: Include the generated build configuration in uartproxy.c so the carrier guard is active in an actual debug build. Verify the helper reference in the debug object and its absence in the release object. Resolve the full-speed bulk OUT stall with a packet-sized transfer and account against the programmed transfer length, then repeat high-speed, full-speed and carrier-less J616s checks at the pushed head.
Checked: My earlier isolated preprocessor check supplied the debug macro directly and missed that this translation unit does not include the generated configuration. The J616s receipt confirms the real debug build still refuses the handoff. It also shows the full-speed stall after enumeration when the Linux host sends a full 64-byte request without a terminating short packet. The local fixes are promising. Please put both on the branch and post the exact-head results.
Found on the J616s row of 575abc3 (2026-11-30): - uartproxy.c did not include build_cfg.h, so the DEBUGUSB_PROXY guard around the T6040 carrier-window skip was always false. The debug build started the generic gadget on USB0 again and the explicit CDC handoff refused at step 1 (0x103). - At full speed a 64-byte proxy request is one full packet and Linux cdc_acm sends no ZLP after it, so a 16 KiB OUT TRB never completed and the first NOP got no reply. Arm one packet per OUT TRB at full speed and count received bytes from the armed length. With both, the J616s hs (480 Mb/s) and fs (12 Mb/s) legs pass. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
|
Pushed 8a4afbe with both fixes from the J616s row:
Tested: on the J616s, hs passes at 480 Mb/s ("released PIPE with the DWC3 held in reset; already retired", status 0x502) and fs passes at 12 Mb/s (NOP on the first try). Plain boot passed at 575abc3, and the carrier-less path is unchanged. These legs ran on a local build whose |
There was a problem hiding this comment.
Verdict: MERGE at 8a4afbe9 after remaining validation.
Checked: The generated configuration include now makes the carrier guard effective in actual debug builds. Full-speed USB2 OUT arms one packet and uses the programmed transfer length to bound the residual count. High-speed and SuperSpeed retain the original transfer size. All eight focused tests passed. I verified the saved J616s logs show successful NOP and 1 MiB reads at 480 and 12 Mb/s. The author reports matching disassembly for the exercised objects and a carrier-less pass at the preceding head.
Blockers: Hosted CI, second-family generic gadget and owner Stage 1 validation remain. Include the carrier-less evidence or source-equivalence record for this head in the merge evidence.
|
Merging at |
|
Known-gap issue for the two receipts REVIEW6 noted (a second-family generic gadget row, and an owner-installed Stage 1): #581 |
This carries #245 forward onto
mainas signed commits. The stalefeat/sptm-hvbase, the policy-botgfyacommit and the AI co-author trailers are gone, and nothing was force-pushed. On top, one commit fixes the two open review points.What it does: it brings up the J616s (T6040) tether port as a USB2 CDC device, at 480 Mb/s or at 12 Mb/s for full-speed hosts, through the explicit session-scoped CDC handoff. The T6040 handoff is selected by the ATC0 PHY compatible (
atc-phy,t6040) from the ADT, not by board.Review fixes (
fc4d6c60):src/usb.c:148:usb_cdc_deferred_usb2()is T6050-only again.usb_init(),usb_iodev_init(),usb_phy_bringup()andusb_iodev_bringup()therefore no longer return early onatc-phy,t6040Macs, and the generic gadget and proxy stay up on a boot without the inherited debug carrier. The explicit handoff testsusb_cdc_t6040_usb2()(the ATC0 PHY compatible) inusb2_target()andusb_cdc_link_start(), and refuses while a generic gadget owns USB0.usb_dwc3_usb2_full_speed) is cleared inusb_cdc_cancel()andusb_cdc_cleanup(), so it can't leak into a later gadget init.Tested: USB/CDC host suites: 38 passed plus 3 new cases in
test_usb_t6040_generic_gadget.py, which fail on the old code. The 10test_t6041_atc_usb2_deviceerrors are main's and are fixed by #570.clang-formatis clean. Clangtools/stage1_size.shpasses all flavours (Stage 1 headroom 94,696 B). ESP Stage 2 links. The earlier J616s 480 and 12 Mb/s rows were taken on the series before this fix. A J616s row of this head (explicit 480/12 Mb/s plus the generic gadget on a carrier-less boot) is queued behind the J616s's current holder.Risk: two-way door. It is Stage 1 USB code on T6040 Macs (J614s, J616s, J614c, J616c): the explicit CDC session, and the generic gadget being restored to main's behaviour. Other families keep main's path.
Not yet: the J616s row at this head, a second-family generic-gadget regression, and an installed Stage 1 row (owner 1TR).
Revert:
git revert -m 1 <merge commit>Supersedes #245.