gk7205v200: flip dwc3 to host before unbinding xhci (otg) - #114
Merged
Conversation
Booting the otg profile with /etc/usbmode = device made S72usbmode's
`usb-mode device` log, on every single boot:
xhci-hcd xhci-hcd.0.auto: Host not halted after 16000 microseconds.
xhci-hcd xhci-hcd.0.auto: Host controller not halted, aborting reset.
dwc3_core_init() leaves GCTL.PRTCAPDIR = OTG(3) and this 4.9 dwc3 never
moves off OTG on its own. xhci-hcd binds and registers both buses on top
of that anyway, but it is not actually driving the port -- so unbinding
straight from OTG asks xhci_halt() to halt a host that was never really
running, and it times out.
The gadget composed regardless, so this was cosmetic in practice, but it
left the host controller un-halted: exactly the live-DMA-engine state the
unbind is there to avoid.
Flip the controller to host before unbinding, so the already-bound xHCI
is genuinely running and the unbind halts cleanly. A switch from host is
already in that state, so only boot pays for the extra flip.
Measured on gk7205v200 (Xiongmai IPC_GK7205V200_50H20AI_S38): 5/5 cold
boots warned before, 0/5 after. Runtime host<->device round trips stay
clean and still take ~0.35s, with no reboot and no majestic restart.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
PR Summary by Qodogk7205v200: Ensure DWC3 host mode before xHCI unbind on OTG boot
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTo customize comments, go to the Qodo configuration screen, or learn more in the docs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Booting the
otgprofile with/etc/usbmode=devicemadeS72usbmode'susb-mode devicelog, on every boot:Cause
dwc3_core_init()leavesGCTL.PRTCAPDIR = OTG(3), and this 4.9 dwc3 never moves off OTG on its own — the same factS72usbmode's header already documents.xhci-hcdbinds and registers both buses on top of that anyway, but it is not actually driving the port. Unbinding straight from OTG therefore asksxhci_halt()to halt a host that was never really running, and it times out.The gadget composed regardless, so this was cosmetic in practice — but it left the host controller un-halted, which is precisely the live-DMA-engine state the unbind exists to avoid.
This is not a probe/timing race. Confirmed by whiting out
S72usbmodeand rebooting so nothing touched the controller:Then
echo host > modefollowed by a manual unbind → still 0 warnings. That isolates the trigger to unbind-while-OTG.Fix
Flip the controller to host before unbinding, so the already-bound xHCI is genuinely running and the unbind halts cleanly. A runtime switch from host is already in that state, so only boot pays for the extra flip.
Testing
On a gk7205v200 (Xiongmai
IPC_GK7205V200_50H20AI_S38) runninggk7205v200_otg_generic:All 5 boots come up
role=device, gadget bound to10030000.dwc3,/dev/video0present. Two runtimehost↔deviceround trips stay clean, still ~0.35s, with no reboot and no majestic restart.Note for reviewers
An earlier attempt treated this as a probe race and polled for xHCI to settle before unbinding. It changed nothing — the wait succeeded and the halt still failed — which is what refuted the race hypothesis. That approach is deliberately not in this PR.
Relatedly, do not gate such a wait on "every root hub has its hub interface driver bound": on this SoC the USB3 root hub never gets a driver (
hub 2-0:1.0: hub can't support USB3.0), so that condition can never be satisfied.🤖 Generated with Claude Code