dwc2 gadget: a SETUP during a control write's data stage is taken as the data, and ep0 stops (buffer DMA)
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 12/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- Active
- Stack technique
- c
- Domaine
- operating-systems
Piste de recherche
Start by reading dwc2_hsotg_epint() and dwc2_hsotg_handle_outdone() in drivers/usb/dwc2/gadget.c, then the linked linux-usb thread for the register reading, and compare with the DOEPCTL/DOEPINT dump in the report. The reproducer at github.com/aki-kuramoto/dwc2-ep0-setup-repro (raw_gadget, ep0-only, delayed data stage) is the way to see the failure. Done means a SETUP arriving during a control write's data stage is handled as a new setup rather than completing the transfer.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Describe the bug
With the USB-C port in device mode (dwc2, buffer DMA), when a SETUP
arrives while ep0 waits for the data stage of a control write, the data
stage completes with the 8 bytes of that SETUP, the SETUP itself is
never processed, and ep0 answers no further SETUP until the gadget is
disconnected. Every control transfer from the host then times out; the
other endpoints go on working.
The code involved (drivers/usb/dwc2/gadget.c, dwc2_hsotg_epint() and
dwc2_hsotg_handle_outdone()) is the same in mainline, so I reported it
upstream on linux-usb, with the register dumps and a reading of the code:
I am opening this issue so that Raspberry Pi users who meet it can find
the report, and in case a fix can be picked up here. Discussion of the
fix itself is probably best kept on linux-usb.
Steps to reproduce the behaviour
Reproducer: https://github.com/aki-kuramoto/dwc2-ep0-setup-repro
- On the Pi:
dtoverlay=dwc2,dr_mode=peripheral, and theraw_gadget
module built for the running kernel (it is not in the Raspberry Pi
OS kernel; it builds as an external module from the same source). - Build and run the gadget:
cc -O2 -Wall -o gadget gadget.c && ./gadget
It is a vendor-specific device (1209:0001) with ep0 only, and it
queues the data stage of the first vendor control write 2 s late. - Connect the Pi's USB-C port to a host and run one of the hosts
(Linux:host_linux.c, Windows:host_windows.c, macOS:host.m).
The host sends a control write with a 500 ms timeout, gives up, and
3 s later sends the next one while that data stage is queued.
The gadget prints:
control write, setup 41 01 01 00 00 00 10 00
data stage SHORT, the bytes received: 41 01 02 00 00 00 10 00
and every following control write times out on the host. With no delay
(./gadget fe980000.usb 0), all of them go through.
Device (s)
Raspberry Pi 400
System
$ cat /etc/rpi-issue
Raspberry Pi reference 2026-10-06
Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, b2cd98a9ee08a31ef7d0110ed09f2492bbd972ec, stage2
$ vcgencmd version
Sep 14 2026 14:49:30
Copyright (c) 2012 Broadcom
version a86983925695a7e63166327d7c002d64040ed31d (clean) (release) (start)
$ uname -a
Linux pi400 6.18.50+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.18.50-1+rpt1 (2026-09-11) aarch64 GNU/Linux
(The kernel is raspberrypi/linux cff533aec2fa601846766b32ff57204e0a61bed7.)
dwc2 debugfs: params: g_dma 1, g_dma_desc 0; hw_params:
dma_desc_enable 0, snpsid 0x4f54280a.
Logs
ep0 registers (/sys/kernel/debug/usb/fe980000.usb/regdump) before the
first control write and after the stall:
register before after
DOEPCTL(0) 0x80028000 0x00028000
DOEPTSIZ(0) 0x00080008 0x00080008
DOEPDMA(0) 0xf7577800 0xfb018808
DOEPINT(0) 0x00000000 0x00002010
DIEPCTL(0) 0x00008000 0x80028000
DIEPTSIZ(0) 0x00000000 0x00080000
GRXSTSR 0x00ac0080
On a Linux host, for each control write after the first:
usb 1-1: usbfs: USBDEVFS_CONTROL failed cmd host_linux rqt 65 rq 1 len 16 ret -110
Additional context
Seen with Linux (Ubuntu 26.04.1), Windows 10 and macOS 26 hosts. I first
met it with no delay on the gadget, with heavy bulk traffic and frequent
control writes, now and then, as if the host had sent a SETUP again
during the data stage.
English is not my first language. I used an LLM to help me write this
and to read the dwc2 code; the tests and the register dumps were run on
the hardware described.
- Langage dominant
- C
- Étoiles
- 13.4k
- Forks
- 5.5k
- Merge moyen
- 1 j 8 h
- PR mergées (30 j)
- 37
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de raspberrypi/linux
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
raspberrypi/linux#7822 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
raspberrypi/linux#7415 · 2 commentaires · 1 réaction ·
Les mainteneurs répondent en général sous 1 jour
-
rp1-cfe doesn't forward V4L2_EVENT_SOURCE_CHANGE event from csi-2 sensor driver to userspace appOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
raspberrypi/linux#7399 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Documentation update requiredOuverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 82/100
raspberrypi/linux#7357 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
raspberrypi/linux#7054 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de raspberrypi/linux
Issues similaires
-
CF_CFDP_S_SendFileData computes the file checksum from the SB buffer after CFE_SB_TransmitBufferOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
needs triage
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
389ds/389-ds-base#8251 ·
Les mainteneurs répondent en général sous 1 jour
-
ColumnDecimal::Append(Int128) stores a value outside the Decimal(P, S) range with no error: cut to 32/64 bits, or with too many digitsPeut-être pris @RUSHIT305 l’a pris aujourd’hui. Ouvertebug data-types
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
ClickHouse/clickhouse-cpp#645 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
ROCm/hrx-system#3628 ·
Les mainteneurs répondent en général sous 1 jour