USB gadget: speed auto-negotiation, robust host reset/suspend handling (fixes ITX Llama boot detection)#671
Open
danifunker wants to merge 2 commits into
Conversation
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.
Summary
This PR makes the DWC2 USB gadget stack resilient to real-world host behavior
— full-speed-only hosts/hubs, warm reboots, and BIOS-time enumeration. The
headline features are USB speed auto-negotiation for the MSD gadget and rework
of suspend/reset handling so the device survives a host warm reboot, which
enables boot detection on the ITX Llama (and other PC BIOSes that enumerate
during POST). Addresses issue #591.
USB Auto-Negotiation
The MSD gadget previously presented a fixed high-speed configuration (512-byte
bulk packets) regardless of what the host actually negotiated, which breaks
against full-speed-only hosts/hubs.
the DWC2 device status register (DSTS.ENUMSPD, new DWHCI_DEV_STS definitions
in dwhci.h).
lets gadgets adapt their EP parameters when the negotiated speed differs from
the configured one.
per-instance copy (m_ConfigurationDescriptor) whose bulk wMaxPacketSize is
rewritten to 64 (FS) / 512 (HS) on enumeration, and the EP hardware is updated
live via the new CDWUSBGadgetEndpoint::SetMaxPacketSize() (rewrites MPS in
the IN/OUT EP control register).
accepts nLength >= SIZE_CBW, because hosts may pad the CBW to the packet
boundary.
Robust suspend/reset handling (ITX Llama boot detection)
A PC BIOS enumerating during POST/warm reboot exposed several windows where
the gadget went deaf or crashed:
fired a PnP event leading to full EP teardown and core re-init, leaving the
device unresponsive for >100 ms — a host that resets and enumerates inside
that window gets hardware ACKs but the software never sees ENUMDONE/SETUP. Now
we only abort in-flight transfers, enter StateSuspended, and let the next USB
reset re-initialize the EPs at IRQ level.
Otherwise the next SETUP completes against the old transfer and is dropped
with a wrong length (host reset storms, warm reboots).
behavior), closing the window between ENUMDONE and OnActivate() where a fast
host's first SETUP was ACKed by the core but dropped with length 0.
OnActivate() is now idempotent via the new IsTransferActive() guard.
unexpected length is logged, dropped, and EP0 is re-armed cleanly.
processing instead of tripping a state assert.
Diagnostics
Added always-on LOGNOTE traces for suspend, bus reset (with state),
enumeration done (with negotiated speed), and every EP0 SETUP request — to
diagnose hosts that bounce between speeds or reset repeatedly (issue #591).
Testing