usbdev: re-assert soft connect in cdcecm/cdcncm disconnect()#19371
usbdev: re-assert soft connect in cdcecm/cdcncm disconnect()#19371ricardgb wants to merge 2 commits into
Conversation
The USB device controller drivers invoke CLASS_DISCONNECT() on every USB bus reset, and a bus reset is the first step of normal host enumeration. Every other class driver (cdcacm, usbmsc, rndis) re-asserts DEV_CONNECT() at the end of its disconnect() handler so that the device remains attached; cdcecm and cdcncm did not, so on controllers that soft-disconnect around bus reset (e.g. rp2040, which drops the pull-up in its bus-reset handler) a standalone CDC-ECM or CDC-NCM device is left soft-disconnected by the first bus reset and never enumerates on the host. Mirror the cdcacm behavior and perform the soft connect in the disconnect() methods, unless part of a composite device (composite.c already re-connects in its own disconnect handler). Fixes the standalone CDC-ECM case of issue apache#15880. Validated on raspberrypi-pico (RP2040): with this change a standalone CONFIG_NET_CDCECM device that previously never appeared on the host enumerates via cdc_ether and pings with 0% loss. cdcncm has the identical defect and receives the identical fix. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AHJRvWeBMTHwzpwjaUg4HW
linguini1
left a comment
There was a problem hiding this comment.
Could you include some logs to verify your test claims?
|
Sure — here are before/after logs. Setup: CDC-ECM — without the fix (baseline)After the board is flashed and reboots into NuttX, the device never enumerates: CDC-ECM — with the fixCDC-NCM — with the fixSame one-liner in The NCM interface comes up Disclosure: these logs, and the fix and its validation, were produced by an AI agent (Claude Code, operated and directed by me) and reviewed by me before posting. |
|
please fix: |
| { | ||
| uinfo("\n"); | ||
|
|
||
| /* Perform the soft connect function so that we will we can be |
There was a problem hiding this comment.
| /* Perform the soft connect function so that we will we can be | |
| /* Perform the soft connect function so that we can be |
Co-authored-by: Xiang Xiao <xiaoxiang781216@gmail.com>
are you happy for me to squash your suggestion into my commit and re-sign both |
yes. |
Summary
USB device controller drivers invoke
CLASS_DISCONNECT()on every USB bus reset, and a bus reset is the first step of normal host enumeration. Every other class driver (cdcacm,usbmsc,rndis) re-assertsDEV_CONNECT()at the end of itsdisconnect()handler ("perform the soft connect function so that we can be re-enumerated"), so on controllers that soft-disconnect around bus reset the pull-up glitch is microseconds long and invisible to the host.cdcecm_disconnect()andcdcncm_disconnect()did not, so the first bus reset of enumeration leaves a standalone CDC-ECM or CDC-NCM device soft-disconnected and it never appears on the host. On RP2040,rp2040_usbintr_busreset()explicitly drops the pull-up, so a standalone device never enumerates at all.This mirrors the cdcacm behavior and performs the soft connect in both
disconnect()methods, unless part of a composite device (composite.calready re-connects in its own disconnect handler).Addresses the standalone CDC-ECM case of #15880 (root-cause analysis in this comment).
Impact
Standalone (non-composite) CDC-ECM and CDC-NCM devices become able to enumerate on controllers that call
CLASS_DISCONNECT()on bus reset. Composite configurations are unaffected (the added call is guarded by!CONFIG_CDCECM_COMPOSITE/!CONFIG_CDCNCM_COMPOSITE). Other class drivers are unaffected; this makes cdcecm/cdcncm consistent with the existing cdcacm/usbmsc/rndis convention.Testing
Validated on raspberrypi-pico (RP2040, arm-none-eabi-gcc 13.2, no new warnings):
CONFIG_NET_CDCECM): before this change the device never appears on a Linux host (no enumeration at all); with this change it enumerates viacdc_etherand ICMP ping across the link runs at 0% loss (~0.5 ms RTT).CONFIG_NET_CDCNCM): before this change the device never attaches; with this change it enumerates and binds the hostcdc_ncmdriver. (Full NCM datapath on RP2040 is blocked by a separate, pre-existing interrupt-IN endpoint delivery issue that also affects other classes on this controller; under separate investigation.)Disclosure
This root-cause analysis, patch, and hardware validation were performed by an AI agent (Claude Code, operated and directed by the submitter), and the result was reviewed by the submitter before posting.
🤖 Generated with Claude Code
https://claude.ai/code/session_01AHJRvWeBMTHwzpwjaUg4HW