USB: DMA Hangs if USB Reset is Received During DMA Transfer in Device Mode
Details:
USB Controller contains a DMA master port used for transferring data to and from the
system memory. This DMA master port may not properly terminate the transfer if bus
reset (2.0 reset or warm/hot reset for Superspeed) is received while the DMA
transfer is active. This can lock up the DMA master.
USB 2.0 bus reset or SuperSpeed Warm/Hot reset may be issued by the USB host in
response to abnormal operation by the USB device. USB host will first try to recover
from the error condition (for example CRC error in data packet) through transaction
retries before issuing reset. During this time, the USB data buffers in the
controller will be temporarily unavailable for new DMA transfers. This gives
opportunity to finish pending DMA transfer. The following aspects affect the
probability of receiving reset while DMA is active:
- Time required for host to
detect abnormal behavior of the device.
- Time required for host to
retry transactions and time required for device to respond to retries.
- Time required for host to
initiate reset signaling.
- Time required for device to
finish pending transfers for all available on-chip buffers.
If the system latency is extremely high, the reset may be received while the DMA
transfer is still in progress or pending.
This issue impacts all speeds, but the probability of occurrence is very low.
This issue only affects device mode.
Workaround(s):
The following two options can be used to recover from this very unlikely scenario.
USB subsystem reset is required to recover once a DMA lockup occurs.
Option1: Use other system level mechanism to detect lockup and reset USB subsystem.
If DMA locks up after reset, host will not be able to enumerate the device. Host may
retry resetting the device again, but subsequent retries will fail since bus reset
is not sufficient to recover from DMA lockup. After unsuccessful enumeration, host
software has to raise the issue to system level so that alternate mechanism can be
used to convey lockup to device.
Option2: Following software workaround can be used to detect DMA lock up and reset
the subsystem. The following is the workaround procedure.
- Software checks if AXI is
idle when the first descriptor missing interrupt occurs after bus reset. AXI
status can be checked by reading AXI_IDLE MMR bit in DMA_AXI_CAP register.
If AXI is idle, software proceeds to step 2. If AXI is not idle, software
proceeds to step 6.
- Initiate a dummy DMA transfer
by following below steps.
- Configure a dummy IN1
endpoint.
- Prepare TRB and data
packet for IN1. Enable Interrupt-on-Completion (IOC) for this
transfer.
- Ring doorbell for
IN1
- Start T2 timer where
T2 < 50ms. Suggested T2 time is 40ms in order to allow sufficient
time for DMA to finish dummy transfer if DMA is not hung
- Wait for IOC interrupt. If
IOC interrupt is received, proceed to step 3. If T2 timer elapses and IOC
was not received, then proceed to step 6.
- Check that IN1 data is
correct by reading BUF_ADDR, BUF_DATA, and BUF_CTRL MMR in Controller
register space. If data is correct, proceed to step 5. If data is incorrect,
proceed to step 6.
- DMA master is not hung if
this step is reached. Software can proceed with further programming to
service the SETUP packet. Workaround flow can be exited.
- DMA master is hung if this
step is reached. Software performs the following steps to recover USB
subsystem from the hang:
- Force device
disconnect.
- Start T1 timer where
T1 >= 200ms. T1 needs to be greater than 200ms in order to allow
host to recognize device disconnect. A higher T1 delay can be used
if the system can tolerate more downtime. In the highly unlikely
scenario that any USB transfers are still pending after this delay,
resetting the subsystem can potentially lockup the system bus and
may lead to full chip reset. Higher T1 delay provides more time for
any pending system bus transfers to finish.
- Software initiates a
force reset of USB subsystem using respective LPSC.
- Wait until T1 timer
elapses.
- Restart USB subsystem
by following same steps performed after power on reset to setup USB
in device mode.