USB OTG Initialization Issue with dwc2 Driver and g_mass_storage Gadget on Raspberry Pi CM3
Describe the bug
I’m experiencing issues with the USB OTG functionality on my Raspberry Pi Compute Module 3 (CM3). The problem seems to be related to the dwc2 driver and the g_mass_storage gadget. Upon boot, I see the following errors in the kernel log:
[ 3.546076] dwc2 3f980000.usb: 256 invalid for host_nperio_tx_fifo_size. Check HW configuration. [ 3.557306] dwc2 3f980000.usb: 512 invalid for host_perio_tx_fifo_size. Check HW configuration. [ 3.568522] dwc2 3f980000.usb: EPs: 8, dedicated fifos, 4080 entries in SPRAM ... [ 3.609244] g_mass_storage gadget: Mass Storage Gadget, version: 2009/09/11 [ 3.617616] g_mass_storage gadget: userspace failed to provide iSerialNumber [ 3.626124] g_mass_storage gadget: g_mass_storage ready [ 3.632785] dwc2 3f980000.usb: bound driver g_mass_storage [ 3.817578] dwc2 3f980000.usb: new device is high-speed [ 3.846967] dwc2 3f980000.usb: new address 46 [ 3.869133] g_mass_storage gadget: high-speed config #1: Linux File-Backed Storage ... [ 63.435425] WARNING: CPU: 0 PID: 0 at /home/qpc/builds/resinio/amber-etcher-kernel/build/tmp/work-shared/raspberrypi-cm3/kernel-source/drivers/usb/dwc2/gadget.c:195 dwc2_hsotg_init_fifo+0x1b0/0x1b8 [dwc2] [ 63.456926] Modules linked in: g_mass_storage usb_f_mass_storage libcomposite dwc2
Steps to reproduce the behaviour
- Set up a Raspberry Pi Compute Module 3 with the following configuration in /boot/config.txt: dtoverlay=dwc2
-
Connect the PI via USB OTG to a Computer to mount the eMMC flash drive. - Observe the kernel log for errors related to dwc2 and g_mass_storage.
Device (s)
Raspberry Pi CM3
System
2024-03-15-raspios-bookworm-arm64-lite.img
Others not possible due to no boot.
Logs
[ 0.000000] PID hash table entries: 4096 (order: 2, 16384 bytes) [ 0.000000] Dentry cache hash table entries: 131072 (order: 7, 524288 bytes) [ 0.000000] Inode-cache hash table entries: 65536 (order: 6, 262144 bytes) [ 0.000000] Memory: 989008K/1021952K available (7168K kernel code, 488K rwdata, 2116K rodata, 3072K init, 778K bss, 24752K reserved, 8192K cma-reserved) [ 0.000000] Virtual kernel memory layout: [ 0.000000] vector : 0xffff0000 - 0xffff1000 ( 4 kB) [ 0.000000] fixmap : 0xffc00000 - 0xfff00000 (3072 kB) [ 0.000000] vmalloc : 0xbe800000 - 0xff800000 (1040 MB) [ 0.000000] lowmem : 0x80000000 - 0xbe600000 ( 998 MB) [ 0.000000] modules : 0x7f000000 - 0x80000000 ( 16 MB) [ 0.000000] .text : 0x80008000 - 0x80800000 (8160 kB) [ 0.000000] .init : 0x80b00000 - 0x80e00000 (3072 kB) [ 0.000000] .data : 0x80e00000 - 0x80e7a1c4 ( 489 kB) [ 0.000000] .bss : 0x80e7c000 - 0x80f3e8d4 ( 779 kB) [ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1 [ 0.000000] Hierarchical RCU implementation. [ 0.000000] Build-time adjustment of leaf fanout to 32. [ 0.000000] NR_IRQS:16 nr_irqs:16 16 [ 0.000000] Failed to get local register map. FIQ is disabled for cpus > 1 [ 0.000000] arm_arch_timer: Architected cp15 timer(s) running at 19.20MHz (phys). [ 0.000000] clocksource: arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0x46d987e47, max_idle_ns: 440795202767 ns [ 0.000006] sched_clock: 56 bits at 19MHz, resolution 52ns, wraps every 4398046511078ns [ 0.000022] Switching to timer-based delay loop, resolution 52ns [ 0.000269] Console: colour dummy device 80x30 [ 0.001161] console [tty1] enabled [ 0.001203] Calibrating delay loop (skipped), value calculated using timer frequency.. 38.40 BogoMIPS (lpj=192000) [ 0.001269] pid_max: default: 32768 minimum: 301 [ 0.001595] Mount-cache hash table entries: 2048 (order: 1, 8192 bytes) [ 0.001636] Mountpoint-cache hash table entries: 2048 (order: 1, 8192 bytes) [ 0.002523] Disabling cpuset control group subsystem [ 0.002684] CPU: Testing write buffer coherency: ok [ 0.002748] ftrace: allocating 22526 entries in 67 pages [ 0.052085] CPU0: thread -1, cpu 0, socket 0, mpidr 80000000 [ 0.052165] Setting up static identity map for 0x100000 - 0x100034 [ 0.053981] CPU1: thread -1, cpu 1, socket 0, mpidr 80000001 [ 0.054611] CPU2: thread -1, cpu 2, socket 0, mpidr 80000002 [ 0.055220] CPU3: thread -1, cpu 3, socket 0, mpidr 80000003 [ 0.055305] Brought up 4 CPUs [ 0.055415] SMP: Total of 4 processors activated (153.60 BogoMIPS). [ 0.055444] CPU: All CPU(s) started in HYP mode. [ 0.055470] CPU: Virtualization extensions available. [ 0.056280] devtmpfs: initialized [ 0.069412] VFP support v0.3: implementor 41 architecture 3 part 40 variant 3 rev 4 [ 0.069745] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns [ 0.069807] futex hash table entries: 1024 (order: 4, 65536 bytes) [ 0.070393] pinctrl core: initialized pinctrl subsystem [ 0.071334] NET: Registered protocol family 16 [ 0.073496] DMA: preallocated 1024 KiB pool for atomic coherent allocations [ 0.082374] hw-breakpoint: found 5 (+1 reserved) breakpoint and 4 watchpoint registers. [ 0.082422] hw-breakpoint: maximum watchpoint size is 8 bytes. [ 0.082615] Serial: AMBA PL011 UART driver [ 0.084521] bcm2835-mbox 3f00b880.mailbox: mailbox enabled [ 0.152886] bcm2835-dma 3f007000.dma: DMA legacy API manager at be80d000, dmachans=0x1 [ 0.154793] SCSI subsystem initialized [ 0.154976] usbcore: registered new interface driver usbfs [ 0.155081] usbcore: registered new interface driver hub [ 0.155197] usbcore: registered new device driver usb [ 0.161869] raspberrypi-firmware soc:firmware: Attached to firmware from 2018-11-04 16:32 [ 0.163246] clocksource: Switched to clocksource arch_sys_counter [ 0.210536] VFS: Disk quotas dquot_6.6.0 [ 0.210646] VFS: Dquot-cache hash table entries: 1024 (order 0, 4096 bytes) [ 0.210866] FS-Cache: Loaded [ 0.211138] CacheFiles: Loaded [ 0.223360] NET: Registered protocol family 2 [ 0.224259] TCP established hash table entries: 8192 (order: 3, 32768 bytes) [ 0.224397] TCP bind hash table entries: 8192 (order: 4, 65536 bytes) [ 0.224607] TCP: Hash tables configured (established 8192 bind 8192) [ 0.224723] UDP hash table entries: 512 (order: 2, 16384 bytes) [ 0.224790] UDP-Lite hash table entries: 512 (order: 2, 16384 bytes) [ 0.225021] NET: Registered protocol family 1 [ 0.225445] RPC: Registered named UNIX socket transport module. [ 0.225476] RPC: Registered udp transport module. [ 0.225504] RPC: Registered tcp transport module. [ 0.225531] RPC: Registered tcp NFSv4.1 backchannel transport module. [ 0.393996] hw perfevents: enabled with armv7_cortex_a7 PMU driver, 7 counters available [ 0.396508] workingset: timestamp_bits=14 max_order=18 bucket_order=4 [ 0.412167] squashfs: version 4.0 (2009/01/31) Phillip Lougher [ 0.412650] FS-Cache: Netfs 'nfs' registered for caching [ 0.413587] NFS: Registering the id_resolver key type [ 0.413641] Key type id_resolver registered [ 0.413669] Key type id_legacy registered [ 0.415943] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 251) [ 0.416099] io scheduler noop registered [ 0.416128] io scheduler deadline registered [ 0.416421] io scheduler cfq registered (default) [ 0.422266] BCM2708FB: allocated DMA memory fdd10000 [ 0.422319] BCM2708FB: allocated DMA channel 0 @ be80d000 [ 0.427445] Console: switching to colour frame buffer device 82x26 [ 0.506273] bcm2835-rng 3f104000.rng: hwrng registered [ 0.507728] vc-cma: Videocore CMA driver [ 0.509034] vc-cma: vc_cma_base = 0x00000000 [ 0.510379] vc-cma: vc_cma_size = 0x00000000 (0 MiB) [ 0.511708] vc-cma: vc_cma_initial = 0x00000000 (0 MiB) [ 0.513156] vc-mem: phys_addr:0x00000000 mem_base=0x3f000000 mem_size:0x3f600000(1014 MiB) [ 0.516167] vc-sm: Videocore shared memory driver [ 0.532009] brd: module loaded [ 0.542136] loop: module loaded [ 0.543390] Loading iSCSI transport class v2.0-870. [ 0.545129] usbcore: registered new interface driver smsc95xx [ 0.546394] dwc_otg: version 3.00a 10-AUG-2012 (platform bus) [ 0.547970] usbcore: registered new interface driver usb-storage [ 0.549397] mousedev: PS/2 mouse device common for all mice [ 0.551248] bcm2835-wdt 3f100000.watchdog: Broadcom BCM2835 watchdog timer [ 0.552809] bcm2835-cpufreq: min=600000 max=1200000 [ 0.554511] sdhci: Secure Digital Host Controller Interface driver [ 0.555835] sdhci: Copyright(c) Pierre Ossman [ 0.557439] sdhost-bcm2835 3f202000.mmc: could not get clk, deferring probe [ 0.559004] sdhci-pltfm: SDHCI platform and OF driver helper [ 0.560790] ledtrig-cpu: registered to indicate activity on CPUs [ 0.562257] hidraw: raw HID events driver (C) Jiri Kosina [ 0.563826] usbcore: registered new interface driver usbhid [ 0.565255] usbhid: USB HID core driver [ 0.567496] vchiq: vchiq_init_state: slot_zero = 0xbdd80000, is_master = 0 [ 0.570240] [vc_sm_connected_init]: start [ 0.573703] vc_vchi_sm_init: failed to open VCHI service (-1) [ 0.573802] [vc_sm_connected_init]: failed to initialize shared memory service [ 0.576725] [vc_sm_connected_init]: end - returning -1 [ 0.578594] Initializing XFRM netlink socket [ 0.580149] NET: Registered protocol family 17 [ 0.581763] Key type dns_resolver registered [ 0.583620] Registering SWP/SWPB emulation handler [ 0.585839] registered taskstats version 1 [ 0.592753] 3f201000.serial: ttyAMA0 at MMIO 0x3f201000 (irq = 87, base_baud = 0) is a PL011 rev2 [ 1.388816] console [ttyAMA0] enabled [ 1.395647] sdhost: log_buf @ bdd01000 (fdd01000) [ 1.473276] mmc0: sdhost-bcm2835 loaded - DMA enabled (>1) [ 1.480333] of_cfs_init [ 1.484482] of_cfs_init: OK [ 1.504127] Freeing unused kernel memory: 3072K [ 3.331740] mmc0: new high speed MMC card at address 0001 [ 3.339298] mmcblk0: mmc0:0001 DG4008 7.28 GiB [ 3.345370] mmcblk0boot0: mmc0:0001 DG4008 partition 1 4.00 MiB [ 3.352856] mmcblk0boot1: mmc0:0001 DG4008 partition 2 4.00 MiB [ 3.360323] mmcblk0rpmb: mmc0:0001 DG4008 partition 3 4.00 MiB [ 3.371764] mmcblk0: p1 p2 [ 3.429258] 3f980000.usb supply vusb_d not found, using dummy regulator [ 3.437319] 3f980000.usb supply vusb_a not found, using dummy regulator [ 3.546076] dwc2 3f980000.usb: 256 invalid for host_nperio_tx_fifo_size. Check HW configuration. [ 3.557306] dwc2 3f980000.usb: 512 invalid for host_perio_tx_fifo_size. Check HW configuration. [ 3.568522] dwc2 3f980000.usb: EPs: 8, dedicated fifos, 4080 entries in SPRAM [ 3.587765] Mass Storage Function, version: 2009/09/11 [ 3.594326] LUN: removable file: (no medium) [ 3.600063] LUN: file: /dev/mmcblk0 [ 3.604902] Number of LUNs=1 [ 3.609244] g_mass_storage gadget: Mass Storage Gadget, version: 2009/09/11 [ 3.617616] g_mass_storage gadget: userspace failed to provide iSerialNumber [ 3.626124] g_mass_storage gadget: g_mass_storage ready [ 3.632785] dwc2 3f980000.usb: bound driver g_mass_storage [ 3.817578] dwc2 3f980000.usb: new device is high-speed [ 3.846967] dwc2 3f980000.usb: new address 46 [ 3.869133] g_mass_storage gadget: high-speed config #1: Linux File-Backed Storage [ 5.028074] dwc2 3f980000.usb: dwc2_hsotg_ep_sethalt(ep bbce0090 ep1in, 1) [ 5.153293] dwc2 3f980000.usb: dwc2_hsotg_ep_sethalt(ep bbce0090 ep1in, 1) [ 5.161692] dwc2 3f980000.usb: dwc2_hsotg_start_req: ep1 is stalled [ 5.169780] dwc2 3f980000.usb: dwc2_hsotg_ep_sethalt(ep bbce0090 ep1in, 0) [ 5.178666] dwc2 3f980000.usb: dwc2_hsotg_ep_sethalt(ep bbce0090 ep1in, 1) [ 5.303275] dwc2 3f980000.usb: dwc2_hsotg_ep_sethalt(ep bbce0090 ep1in, 1) [ 5.311408] dwc2 3f980000.usb: dwc2_hsotg_start_req: ep1 is stalled [ 5.319192] dwc2 3f980000.usb: dwc2_hsotg_ep_sethalt(ep bbce0090 ep1in, 0) [ 5.327930] dwc2 3f980000.usb: dwc2_hsotg_ep_sethalt(ep bbce0090 ep1in, 1) [ 5.453274] dwc2 3f980000.usb: dwc2_hsotg_ep_sethalt(ep bbce0090 ep1in, 1) [ 5.461303] dwc2 3f980000.usb: dwc2_hsotg_start_req: ep1 is stalled [ 5.468960] dwc2 3f980000.usb: dwc2_hsotg_ep_sethalt(ep bbce0090 ep1in, 0) [ 5.641760] random: fast init done [ 15.656524] random: crng init done [ 63.429663] ------------[ cut here ]------------ [ 63.435425] WARNING: CPU: 0 PID: 0 at /home/qpc/builds/resinio/amber-etcher-kernel/build/tmp/work-shared/raspberrypi-cm3/kernel-source/drivers/usb/dwc2/gadget.c:195 dwc2_hsotg_init_fifo+0x1b0/0x1b8 [dwc2] [ 63.456926] Modules linked in: g_mass_storage usb_f_mass_storage libcomposite dwc2
Additional context
Suggested Fix:
I have a similar issue on a raspberry pi 5
dwc2_hsotg_ep_start_req: ep1 is stalled
An duploading the boot file is very slow
I have a raspberry pi zero and the composite gadget to create a usb disk that the other computer mounts when it's plugged in. With one device it works and mounts as a drive and data can be written to it. But when I plug it into another computer, the same device, will have these exact errors in the dmesg output.
Same raspberry pi, but different host computer, so it's like some host computers react differently, or behave differently.
[ 31.151871] dwc2 20980000.usb: dwc2_hsotg_start_req: ep3 is stalled
[ 31.152272] dwc2 20980000.usb: dwc2_hsotg_ep_sethalt(ep 0c8394b5 ep3in, 0)
[ 31.154471] dwc2 20980000.usb: dwc2_hsotg_ep_sethalt(ep 0c8394b5 ep3in, 1)
[ 31.270882] dwc2 20980000.usb: dwc2_hsotg_ep_sethalt(ep 0c8394b5 ep3in, 1)
[ 31.270954] dwc2 20980000.usb: dwc2_hsotg_start_req: ep3 is stalled
[ 31.271326] dwc2 20980000.usb: dwc2_hsotg_ep_sethalt(ep 0c8394b5 ep3in, 0)
[ 31.290948] dwc2 20980000.usb: dwc2_hsotg_ep_sethalt(ep 0c8394b5 ep3in, 1)
[ 31.410835] dwc2 20980000.usb: dwc2_hsotg_ep_sethalt(ep 0c8394b5 ep3in, 1)
@christhomas you may want to check if https://github.com/macmpi/xg_multi solves your issue.
Tested OK on PiZeroW with Trixie.
Linux raspberrypi 6.12.47+rpt-rpi-v6 #1 Raspbian 1:6.12.47-1+rpt1 (2025-09-16) armv6l GNU/Linux
@christhomas you may want to check if https://github.com/macmpi/xg_multi solves your issue. Tested OK on PiZeroW with Trixie.
Linux raspberrypi 6.12.47+rpt-rpi-v6 #1 Raspbian 1:6.12.47-1+rpt1 (2025-09-16) armv6l GNU/Linux
Thanks! I'll take a look
Can report the same with g_multi on 6.12.59-0 on PiZeroW.
[ 34.516207] dwc2 20980000.usb: dwc2_hsotg_ep_sethalt(ep 51f609dd ep5in, 1)
[ 34.621578] dwc2 20980000.usb: dwc2_hsotg_ep_sethalt(ep 51f609dd ep5in, 1)
[ 34.621655] dwc2 20980000.usb: dwc2_hsotg_start_req: ep5 is stalled
[ 34.621802] dwc2 20980000.usb: dwc2_hsotg_ep_sethalt(ep 51f609dd ep5in, 0)
[ 34.622059] dwc2 20980000.usb: dwc2_hsotg_ep_sethalt(ep 51f609dd ep5in, 1)
[ 34.731527] dwc2 20980000.usb: dwc2_hsotg_ep_sethalt(ep 51f609dd ep5in, 1)
[ 34.731579] dwc2 20980000.usb: dwc2_hsotg_start_req: ep5 is stalled
Linux 6.14.0-36-generic #36~24.04.1-Ubuntu host-side has (note sd 1:0:0:0: Power-on or device reset occurred):
[396669.996553] usb 1-6: new full-speed USB device number 93 using xhci_hcd
[396677.550357] usb 1-6: new high-speed USB device number 94 using xhci_hcd
[396677.674243] usb 1-6: New USB device found, idVendor=1d6b, idProduct=0104, bcdDevice= 6.12
[396677.674262] usb 1-6: New USB device strings: Mfr=3, Product=4, SerialNumber=0
[396677.674269] usb 1-6: Product: Multifunction Composite Gadget
[396677.674275] usb 1-6: Manufacturer: Linux 6.12.59-0-rpi with 20980000.usb
[396677.679630] cdc_acm 1-6:1.2: ttyACM0: USB ACM device
[396677.680281] usb-storage 1-6:1.4: USB Mass Storage device detected
[396677.680491] scsi host1: usb-storage 1-6:1.4
[396677.721811] rndis_host 1-6:1.0 usb0: register 'rndis_host' at usb-0000:00:14.0-6, RNDIS device, f6:67:ce:b3:c0:ea
[396677.722598] usbcore: registered new interface driver rndis_host
[396677.733196] rndis_host 1-6:1.0 enxf667ceb3c0ea: renamed from usb0
[396683.456449] scsi 1:0:0:0: Direct-Access Linux File-Stor Gadget 0612 PQ: 0 ANSI: 2
[396683.456998] sd 1:0:0:0: Attached scsi generic sg0 type 0
[396683.458173] sd 1:0:0:0: Power-on or device reset occurred
[396683.458905] sd 1:0:0:0: [sda] 215040 512-byte logical blocks: (110 MB/105 MiB)
[396683.564772] sd 1:0:0:0: [sda] Write Protect is off
[396683.564777] sd 1:0:0:0: [sda] Mode Sense: 0f 00 00 00
[396683.674706] sd 1:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[396683.898727] sda:
[396683.898807] sd 1:0:0:0: [sda] Attached SCSI disk
With xg_mutli (g_multi look-alike but libcomposite configfs - does ecm for networking) all is good with no errors,... unless if for some reason networking setup is delayed, then I see following gadget crash:
[ 66.461661] dwc2 20980000.usb: dwc2_hsotg_ep_stop_xfr: timeout GINTSTS.GOUTNAKEFF
[ 66.461877] dwc2 20980000.usb: dwc2_hsotg_ep_stop_xfr: timeout DOEPCTL.EPDisable
[ 66.462087] dwc2 20980000.usb: dwc2_hsotg_ep_stop_xfr: timeout GINTSTS.GOUTNAKEFF
[ 66.462268] dwc2 20980000.usb: dwc2_hsotg_ep_stop_xfr: timeout DOEPCTL.EPDisable
[ 66.462477] dwc2 20980000.usb: dwc2_hsotg_ep_stop_xfr: timeout GINTSTS.GOUTNAKEFF
[ 66.462659] dwc2 20980000.usb: dwc2_hsotg_ep_stop_xfr: timeout DOEPCTL.EPDisable
[ 66.462842] dwc2 20980000.usb: dwc2_hsotg_ep_stop_xfr: timeout GINTSTS.GOUTNAKEFF
[ 66.463019] dwc2 20980000.usb: dwc2_hsotg_ep_stop_xfr: timeout DOEPCTL.EPDisable
[ 66.512705] dwc2 20980000.usb: new device is high-speed
[ 71.631564] dwc2 20980000.usb: new device is high-speed
If mass-storage component is not used, all is good.
Seems like some weird interaction between mass-storage and usb0 networking port (@maxnet signaled some similar interactions issues with serial a long time ago).
Unsure anyone got to the bottom of it.
gentle ping @lategoodbye in case of any potential clues.
Can report the same with g_multi on 6.12.59-0 on PiZeroW.
It seems 6.12.62 includes fixes for several issues related to gadgets & overall dwc2: ~~I have not encountered previous problems anymore...so far...~~ (6.12.63 has few more fixes).
EDIT: well...a bit further: issue still there 😟
dwc2_hsotg_ep_sethalt issue may be worked-around by setting stall=0 parameter into g_multi module options, like:
modprobe g_multi file=/dev/mmcblk0p1 stall=0 removable=1
https://www.kernel.org/doc/Documentation/usb/mass-storage.txt says:
Its requirements are modest; only a bulk-in and a bulk-out endpoint
are needed. The memory requirement amounts to two 16K buffers.
Support is included for full-speed, high-speed and SuperSpeed
operation.
Note that the driver is slightly non-portable in that it assumes
a single memory/DMA buffer will be usable for bulk-in and bulk-out
endpoints. With most device controllers this is not an issue, but
there may be some with hardware restrictions that prevent a buffer
from being used by more than one endpoint.
[...]
- stall=b
Specifies whether the gadget is allowed to halt bulk endpoints.
The default is determined according to the type of USB device
controller, but usually true.
dmesg says:
[ 20.764243] dwc2 20980000.usb: EPs: 8, dedicated fifos, 4080 entries in SPRAM
@pelwell Are there some known hardware/configuration limitations with Pi's USB device controller that require stall=0, like as in Disabled on some USB devices known not to work correctly?