3.8.1 Handling Babble Conditions DWC_otg handles two cases of babble: packet babble and port babble. Packet babble occurs if the device sends more data than the maximum packet size for the channel. Port babble occurs if the controller continues to receive data from the device at EOF2 (the end of frame 2, which is very close to SOF). When DWC_otg detects a packet babble, it stops writing data into the Rx buffer and waits for the end of packet (EOP). When it detects an EOP, it flushes already-written data in the Rx buffer and generates a Babble interrupt to the application |
I'm sorry for not making my point clear.
DWC_otg driver can handle packet babble in the data phase properly. It provides interrupt function, dwc2_hc_babble_intr, It mainly does two things:
1) Delete the URB request from the endpoint linked list maintained by the USB host controller, mark the URB transfer result as OVERFLOW error, and delete the remaining URB requests in the data phase of the BOT transfer.
2) Halt the currently used channel and indicate that the reason for the channel halt is Babble Error.
When the urb complete (babble error occurs), the sg_complete function of urb(s) will notify the mass storage driver that the data phase of the BOT transfer is over. The rest is done by the mass storage driver, such us:
1) Get CSW for device status, interpret CSW, return USB_STOR_TRANSPORT_ERROR.
2) Handle Errors(here is USB_STOR_TRANSPORT_ERROR).
3) Initiate port reset.
4) Notify the SCSI layer implements a retransmission mechanism.
How us->iobuf overflow could occur?
For 1), the USB device does not know that a Babble Error has occurred at this time (DWC_otg knows what happened), It actually continuously returns 512 bytes data through DMA write to CSW address (As can be seen in the waveform in the appendix document before). The DWC_otg controller driver cannot control how much data the device returns(13 or 512 bytes). However, the USB storage driver pre-allocates a default buffer size of 64 bytes for CBW/CSW.
For 3), the device does not realize that a babble error has occurred until the port reset is successfully completed (by interface usb_stor_port_reset). Then device will enter the enumeration process. It looks like things are heading in the right direction.
For 4), as for the urb that has a babble error, SCSI will execute a retransmission mechanism.
thanks,
Dai xin
At 2025-03-14 22:16:48, "Alan Stern" <st...@rowland.harvard.edu> wrote: >On Fri, Mar 14, 2025 at 10:28:41AM +0800, daixin_tkzc wrote: >> I'm sorry for not making my point clear. >> >> DWC_otg driver can handle packet babble in the data phase properly. It provides interrupt function, dwc2_hc_babble_intr, It mainly does two things: >> >> 1) Delete the URB request from the endpoint linked list maintained by the USB host controller, mark the URB transfer result as OVERFLOW error, and delete the remaining URB requests in the data phase of the BOT transfer. >> >> 2) Halt the currently used channel and indicate that the reason for the channel halt is Babble Error. >> >> When the urb complete (babble error occurs), the sg_complete function of urb(s) will notify the mass storage driver that the data phase of the BOT transfer is over. The rest is done by the mass storage driver, such us: >> >> 1) Get CSW for device status, interpret CSW, return USB_STOR_TRANSPORT_ERROR. >> >> 2) Handle Errors(here is USB_STOR_TRANSPORT_ERROR). >> >> 3) Initiate port reset. >> >> 4) Notify the SCSI layer implements a retransmission mechanism. >> >> How us->iobuf overflow could occur? >> >> For 1), the USB device does not know that a Babble Error has occurred at this time (DWC_otg knows what happened), It actually continuously returns 512 bytes data through DMA write to CSW address (As can be seen in the waveform in the appendix document before). The DWC_otg controller driver cannot control how much data the device returns(13 or 512 bytes). > >But the DWC_otg controller _can_ control how much data gets written to >the URB's transfer buffer. > >> However, the USB storage driver pre-allocates a default buffer size of 64 bytes for CBW/CSW. > >Furthermore, the CSW URB has a transfer_length of 13. So the DWC_otg >controller will ensure that no more than 13 bytes are written to the >buffer, even if the device sends 512 bytes. Right? > >Alan Stern>
Yes, dwc_otg should indeed ensure that DMA writes memory data no more than 13 bytes (even if Rxfifo receives 512 bytes).But in fact, the dwc_otg manual has different configuration requirements for the XferSize register before DMA transfer: For BOT's OUT transaction, the HCTSIZ register is filled with as many bytes as the software requests to send; for IN transactions, no matter how many bytes the software requests to receive, the HCTSIZ register needs to be filled with 512 alignment, that is, the software requests 31 bytes in the CBW phase, and HCTSIZ is filled with 31; the software requests 13 bytes in the CSW phase, and HCTSIZ is still filled with 512. As observed in the waveform (I am sorry to quote the attached pictures because I am not sure whether the appendix document is visible).data packets without Babble Error:data packets with Babble Error (The device sent an extra packet204):
CSW buffer data through DMA write(0x70004000-0x7000400c) under normal circumstances:
CSW buffer data through DMA write(0x70004000-0x700041fc) after Babble Error:
From this, it seems that it is indeed a problem with the dwc2_otg controller, which does not handle the Babble error problem well. For example, as Matthew Dharm mentioned, dwc2_otg should discard the extra bytes. Unfortunately, software does not seem to be able to do anything about it. Please allow us to explain the reason behind changing the US_IOBUF_SIZE macro. 1) The macro comment says, “But Freecom needs a 64-byte buffer, so that's the size we'll allocate”. We thought that "Freecom" had a similar problem, otherwise a 32-byte buffer size would be enough. 2) We only observed the Babble Error phenomenon on mass storage devices, and the maximum packet size supported by the USB 2.0 controller for bulk transfers is only 512.
thanks,
Dai Xin
At 2025-03-15 17:37:38, "Matthew Dharm" <mdhar...@one-eyed-alien.net> wrote: >On Sat, Mar 15, 2025 at 2:05 AM daixin_tkzc <daixi...@163.com> wrote: >> Yes, dwc_otg should indeed ensure that DMA writes memory data no more than 13 bytes (even if Rxfifo receives 512 bytes). >> But in fact, the dwc_otg manual has different configuration requirements for the XferSize register before DMA transfer: >> For BOT's OUT transaction, the HCTSIZ register is filled with as many bytes as the software requests to send; for IN transactions, no matter how many bytes the software requests to receive, the HCTSIZ register needs to be filled with 512 alignment, that is, the software requests 31 bytes in the CBW phase, and HCTSIZ is filled with 31; the software requests 13 bytes in the CSW phase, and HCTSIZ is still filled with 512. > >"Alignment" is not the same thing as "size". A buffer can be 32 bytes >and aligned on a 4MByte boundary. Hardware devices often impose >alignment requirements as it simplifies the logic required to access >the buffer. > >> Please allow us to explain the reason behind changing the US_IOBUF_SIZE macro. >> 1) The macro comment says, “But Freecom needs a 64-byte buffer, so that's the >> size we'll allocate”. We thought that "Freecom" had a similar problem, otherwise a 32-byte buffer size would be enough.>
I'm sorry you may have misunderstood me.HCTSIZ register only reflects the transfer size for the Host Channel (between host and device). The dwc_otg manual explains it as follows:Non-Scatter/Gather DMA Mode: Transfer Size (XferSize) For an OUT, this field is the number of data bytes the host sends during the transfer. For an IN, this field is the buffer size that the application has Reserved for the transfer. The application is expected to program this field as an integer multiple of the maximum packet size for IN transactions (periodic and non-periodic).We only see from the waveform on the axi bus: if babble error happened, it will write 512 bytes to memory(us->iobuf) in the CSW phase. In normal, it's 13, however the HCTSIZ register is always configured 512 in the CSW phase. This may be a problem with the controller itself.
>Your reasoning is incorrect. The "Freecom" device does NOT have a >babble problem. The Freecom device uses a vendor-specific protocol >which requires a 64-byte buffer buffer for all of its command and >status transfers. us->iobuf is used by multiple protocols for command >and status, including CB, CBI, BOT, Freecom, and others -- as such, it >needs to be the largest size required by any of those protocols. >>Matt
Thanks for your explanation, we understand why this macro is set 64.