Skip to content

usb2otg: channel halt, periodic and SMP fixes (2.1) - #2324

Merged
Kalamatee merged 5 commits into
aros-development-team:masterfrom
bsek:usb2otg-halt-smp-fixes
Nov 30, 2026
Merged

Kalamatee merged 5 commits into
aros-development-team:masterfrom
bsek:usb2otg-halt-smp-fixes

Conversation

@bsek

@bsek bsek commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor
  • Wait for AXI writes after the core reset. OpenUnit and the wedge recovery set the AXI burst bit instead of bit 4, which hung the DMA under heavy isochronous IN.
  • Handle periodic channels as dwc2 does: no TX FIFO flush while other channels are enabled, no CHDIS on direct iso channels, and iso waits for periodic request queue space.
  • Do not write CHDIS to a channel that has already halted. The pending disable cancelled the next transfer on the channel, so a pulled USB stick left its bulk channel dead for the next device.
  • SMP: a dropped split iso packet called Cause() with hu_Lock held, four IRQ paths changed the transfer queues without the lock, and the SOF gate's busy bits are now atomic.
  • The HCCHAR max packet size mask is 11 bits. It kept 10, so a 1024-byte endpoint was programmed with 0 and high-speed isochronous transfers always ended in babble.

Tested on a Raspberry Pi 3B+ (aarch64, SMP) with keyboard, mouse, hub, mass storage replug, a USB webcam and USB audio.

OpenUnit and the wedge recovery set the AXI burst bit instead of bit 4,
as device init and dwc2 on BCM2835 do. Under heavy isochronous IN the
DMA then hung and took the whole controller with it.
@Kalamatee

Copy link
Copy Markdown
Member

Thanks. I've read the five commits against master; Two things need changing, both in 508dbc935a. Line numbers refer to the PR head 3337dbcd0e.

1. A stuck direct iso channel is re-armed while it may still be enabled

usb2otg_iso_sof() (usb2otg_iso.c:567) no longer writes CHDIS to a direct channel at USB2OTG_ISO_STUCK. At 2 * USB2OTG_ISO_STUCK it drops the packet with iso_packet_done() and clears is_Armed, but nothing has halted the channel. A direct channel normally halts by itself at the end of its microframe, so this path only runs when it didn't. CHENA can still be set at that point.

On the next SOF, iso_kick() → iso_arm_direct() → iso_start() rewrites TRANSSIZE, DMAADDR and HCCHAR on that enabled channel. For IN, iso_load() has already handed is_Buf to the next packet while the old transfer may still be writing into it. Reprogramming an enabled channel is undefined on this core, and it's what the halt wait in usb2otg_halt_channel_preserve_char() exists to prevent.

Fix: check CHENA before dropping the packet. If the channel is still enabled, reset it with usb2otg_exorcise_channel() (already used on iso channels at :380, :476 and :593), or leave it armed until it halts.

2. usb2otg_halt_channel_preserve_char() can now return with the channel still enabled

The new early return (usb2otg_intr.c:136) skips the TX FIFO flush whenever any other channel is enabled. While an iso stream runs, its channel is enabled almost all the time, so a channel whose halt times out now nearly always comes back still enabled. Before, that only happened when the flush also failed.

The 20 callers treat the channel as halted afterwards: they requeue the request, free the channel and later program it again (for example :1641, :2747). Not flushing is right, but the function should report the failure, so callers keep the channel out of use and leave it to the wedge recovery instead of reprogramming it.

bsek added 2 commits November 29, 2026 14:56
No TX FIFO flush while other channels are enabled. A channel whose
halt fails is quarantined. No CHDIS on direct iso channels, a stuck one
is reset when its packet is dropped. Iso waits for periodic request
queue space and HPTXSTS is logged when a periodic channel gets stuck.
The pending disable cancelled the next transfer on the channel, so a
pulled USB stick left its bulk channel dead for the next device, and
the first SSPLIT of split control transfers halted bare. A bulk
give-up now also resets the channel. Version 2.1.
@bsek
bsek force-pushed the usb2otg-halt-smp-fixes branch from 3337dbc to d627eeb Compare November 29, 2026 13:59
@bsek

bsek commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, both fixed in the periodic-channels commit.

  1. When a direct iso packet is dropped and CHENA is still set, the channel is now reset with usb2otg_exorcise_channel(). The scenario couldn't occur as described: iso_kick() returns early while CHENA is set, before iso_arm_direct()/iso_load(), so the channel was never reprogrammed while enabled. But that check meant a channel that never halted stalled the stream forever, so the reset is needed.
  2. When the halt gives up (no flush, or still stuck after the flush), it now quarantines the channel in hu_DeadChannels. SetupChannel won't pick it, and the watchdog recovers it or escalates. Before, the only guard was SetupChannel's own CHENA check, which only caught it when the channel was programmed again.

@Kalamatee

Kalamatee commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

channels that fail to halt are now marked out of use in hu_DeadChannels. That marking happens from the IRQ path without hu_Lock, mostly with a plain read-modify-write of the byte. The watchdog clears bits in the same byte under the lock, and it can run on another CPU, so the two updates can collide and one gets lost. Then either:

  • the mark disappears, and the channel is handed out while still enabled, which is what the quarantine is meant to prevent;
  • or a channel the watchdog just released is marked dead again.

Fix: use AROS_ATOMIC_OR/AROS_ATOMIC_AND on hu_DeadChannels, as is already done for the SOF gate bits. Taking the lock inside the helper won't work, because the watchdog calls it while already holding the lock.

bsek added 2 commits November 30, 2026 17:40
A dropped split iso packet called Cause() with hu_Lock held, which
takes the lock again. Four IRQ paths changed the transfer queues
without the lock other CPUs take for them. The SOF gate's busy bits
and hu_DeadChannels are atomic, as the gate softint and the watchdog
can run on any CPU.
The mask kept 10 bits, so a 1024-byte endpoint was programmed with 0.
High-speed isochronous transfers then ended in babble every time.
@bsek
bsek force-pushed the usb2otg-halt-smp-fixes branch from d627eeb to 431f2c5 Compare November 30, 2026 16:42
@bsek

bsek commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

Right, fixed in the SMP locking commit. Every bit update of hu_DeadChannels now uses AROS_ATOMIC_OR/AROS_ATOMIC_AND: the quarantine helper, usb2otg_escalate_hw_reset(), the watchdog release paths and the two quarantine sites in SetupChannel, which had the same race. The plain = 0 resets after a core reset are left as single stores.

@Kalamatee
Kalamatee merged commit b71b631 into aros-development-team:master Nov 30, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants