Repository navigation
Description
Describe the bug
In our currently BLE project, we use the Pi4 as the BLE host, sometimes, controller's evently buffer exhausted after sent to USB layer(BLE event transfered via endpoint 1).
We captured the USB infer log bug Lecroy sniffer and finding the the IN token of endpoint 1. On host side, we have confirmed that URB has been submitted to endpoint1 successfully, but no IN token sent out.
To reproduce
establlish connection with a mass of BLE devices repeatlly(> 80 devices ).
Expected behaviour
all success
Actual behaviour
sometimes, no HCI events reported to Host, and controller reports "ALLOC_EVENT_NOBUFF",
with Lecroy USB sniffer, no IN Token sent out on Endpoint 1.
System
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
-
Which model of Raspberry Pi? e.g. Pi3B+, PiZeroW
Pi4, reproduced
Pi3, no reproduced. -
Which OS and version (
cat /etc/rpi-issue)?
Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, dcfd74d7d1fa293065ac6d565711e9ff891fe2b8, stage4 -
Which firmware version (
vcgencmd version)?
version 40787ee5905644f639a2a0f6e00ae12e517a2211 (clean) (release) (start) -
Which kernel version (
uname -a)?
Linux PiAP1 5.10.771-v7l+ su without password via /proc/pid/mem write #2 SMP Tue Nov 9 10:17:02 GMT 2021 armv7l GNU/Linux
reproduced on kernel 5.10.52 and kernel 5.10.77
Logs
//from the timestamp "487.569599", after the last "xhci_urb_enqueue: ep1in-intr", no IN Token sent out
-0 [000] d.s. 487.545584: xhci_queue_trb: INTR: Buffer 000000040405cb40 length 16 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
-0 [000] d.s. 487.545585: xhci_ring_ep_doorbell: Ring doorbell for Slot 2 ep1in
-0 [000] ..s. 487.546581: xhci_urb_enqueue: ep1in-intr: urb 992aeedf pipe 1077969792 slot 2 length 0/16 sgs 0/0 stream 0 flags 00010200
-0 [000] d.s. 487.546583: xhci_queue_trb: INTR: Buffer 000000040405cb40 length 16 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
-0 [000] d.s. 487.546584: xhci_ring_ep_doorbell: Ring doorbell for Slot 2 ep1in
-0 [000] ..s. 487.547600: xhci_urb_enqueue: ep1in-intr: urb 992aeedf pipe 1077969792 slot 2 length 0/16 sgs 0/0 stream 0 flags 00010200
-0 [000] d.s. 487.547605: xhci_queue_trb: INTR: Buffer 000000040405cb40 length 16 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
-0 [000] d.s. 487.547607: xhci_ring_ep_doorbell: Ring doorbell for Slot 2 ep1in
-0 [000] ..s. 487.567604: xhci_urb_enqueue: ep1in-intr: urb 992aeedf pipe 1077969792 slot 2 length 0/16 sgs 0/0 stream 0 flags 00010200
-0 [000] d.s. 487.567611: xhci_queue_trb: INTR: Buffer 000000040405cb40 length 16 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
-0 [000] d.s. 487.567613: xhci_ring_ep_doorbell: Ring doorbell for Slot 2 ep1in
-0 [000] ..s. 487.568586: xhci_urb_enqueue: ep1in-intr: urb 992aeedf pipe 1077969792 slot 2 length 0/16 sgs 0/0 stream 0 flags 00010200
-0 [000] d.s. 487.568589: xhci_queue_trb: INTR: Buffer 000000040405cb40 length 16 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
-0 [000] d.s. 487.568590: xhci_ring_ep_doorbell: Ring doorbell for Slot 2 ep1in
-0 [000] ..s. 487.569599: xhci_urb_enqueue: ep1in-intr: urb 992aeedf pipe 1077969792 slot 2 length 0/16 sgs 0/0 stream 0 flags 00010200
-0 [000] d.s. 487.569604: xhci_queue_trb: INTR: Buffer 000000040405cb40 length 16 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
-0 [000] d.s. 487.569605: xhci_ring_ep_doorbell: Ring doorbell for Slot 2 ep1in
-0 [000] .ns. 487.672186: xhci_urb_enqueue: ep2in-bulk: urb abbde4e2 pipe 3225486208 slot 2 length 0/4096 sgs 0/0 stream 0 flags 00010200
-0 [000] dns. 487.672192: xhci_queue_trb: BULK: Buffer 0000000403f82000 length 4096 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
-0 [000] dns. 487.672194: xhci_ring_ep_doorbell: Ring doorbell for Slot 2 ep2in
-0 [000] .ns. 487.755046: xhci_urb_enqueue: ep2in-bulk: urb abbde4e2 pipe 3225486208 slot 2 length 0/4096 sgs 0/0 stream 0 flags 00010200
-0 [000] dns. 487.755053: xhci_queue_trb: BULK: Buffer 0000000403f82000 length 4096 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
-0 [000] dns. 487.755055: xhci_ring_ep_doorbell: Ring doorbell for Slot 2 ep2in
Conn_Thread-843 [000] .... 488.933191: xhci_urb_enqueue: ep0out-control: urb d93b4aef pipe 2147484416 slot 2 length 0/3 sgs 0/0 stream 0 flags 00000000
Conn_Thread-843 [000] d... 488.933198: xhci_queue_trb: CTRL: bRequestType 20 bRequest 00 wValue 0000 wIndex 0000 wLength 3 length 8 TD size 0 intr 0 type 'Setup Stage' flags I:i:c
Conn_Thread-843 [000] d... 488.933200: xhci_queue_trb: CTRL: Buffer c020cb1cc000200e length 3 TD size 0 intr 0 type 'Data Stage' flags I:i:c:s:i:e:C
Conn_Thread-843 [000] d... 488.933201: xhci_queue_trb: CTRL: Buffer 0000000000000000 length 0 TD size 0 intr 0 type 'Status Stage' flags I:c:e:C
Conn_Thread-843 [000] d... 488.933203: xhci_ring_ep_doorbell: Ring doorbell for Slot 2 ep0in
-0 [000] .ns. 489.831245: xhci_urb_enqueue: ep2in-bulk: urb abbde4e2 pipe 3225486208 slot 2 length 0/4096 sgs 0/0 stream 0 flags 00010200
-0 [000] dns. 489.831257: xhci_queue_trb: BULK: Buffer 0000000403f82000 length 4096 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
-0 [000] dns. 489.831260: xhci_ring_ep_doorbell: Ring doorbell for Slot 2 ep2in
-0 [000] .ns. 489.881219: xhci_urb_enqueue: ep2in-bulk: urb abbde4e2 pipe 3225486208 slot 2 length 0/4096 sgs 0/0 stream 0 flags 00010200
-0 [000] dns. 489.881227: xhci_queue_trb: BULK: Buffer 0000000403f82000 length 4096 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
-0 [000] dns. 489.881229: xhci_ring_ep_doorbell: Ring doorbell for Slot 2 ep2in
-0 [000] .ns. 489.931215: xhci_urb_enqueue: ep2in-bulk: urb abbde4e2 pipe 3225486208 slot 2 length 0/4096 sgs 0/0 stream 0 flags 00010200
-0 [000] dns. 489.931221: xhci_queue_trb: BULK: Buffer 0000000403f82000 length 4096 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
If applicable, add the relevant output from dmesg or similar.
Additional context
Have you encounter simliar problem before?
Thank you
Julian
Activity
P33M commentedon Nov 10, 2021
Are the BLE devices being accessed via USB?
Is there anything in dmesg?
Also, you reference a "Lecroy USB sniffer" but your post doesn't contain any further details on packets you have captured. Are there any errors reported by the tool?
JulianGu001 commentedon Nov 18, 2021
it seems something of HW goes wrong, please check the log and give some advice.
Thanks
JulianGu001 commentedon Nov 18, 2021
By the way, we reproduce this issue easily on Pi 4, but we haven't see it happen on Pi 3 as so far.
JulianGu001 commentedon Nov 18, 2021
From our analysis, after URB of Endpoint 1 submitted,the doorbell reg was ring up successfully, but the IN token did not sent out by capturing the USB sniffer log.
what kinds of reason may cause this situation?
P33M commentedon Nov 18, 2021
Either the controller did not fetch the TRB on the doorbell ring, or the TRB was somehow invalid when the controller read it.
Please capture another instance of failure with a USB driver trace as before, but also dump the contents of the files (and the associated filenames) in
/sys/kernel/debug/usb/xhci/0000:01:00.0/devices/02when the first failing transfer happens - these contain the transfer rings and enqueue/dequeue pointers for the device.JulianGu001 commentedon Nov 18, 2021
Hi P33M,
Thanks for your quick response, I checked the files under the directory you mentioned, there're so many folders and files.

Do you need all of them?
I'm not sure if the token issue happen, when I dump thest files, the contents still keep freeze just at that failing moment, will they change dynamically?
P33M commentedon Nov 18, 2021
Ah. I was expecting at most one OUT and one IN endpoint. Please capture just the contents of ep-context and all the files in the ep02 directory.
If you can manually determine that a hang has occured, it is very likely that the endpoint state will be preserved as the transfer rings take a long time to wrap around and overwrite past data.
JulianGu001 commentedon Nov 19, 2021
Hi Sir,
I reproduced this issue twice and upload the log here, please have a check :
you can address this issue point around the last "xhci_urb_enqueue: ep1in-intr:" , which should not stop, because endpoint 1 shuold keep polling every 1ms.
1.)
usb_trace_001.txt
xhci_debug.zip
2.)
xhci_debug.zip
usb_trace_002.txt
JulianGu001 commentedon Nov 20, 2021
Hi Sir,


I checked the contents of /sys/kernel/debug/usb/xhci/0000:01:00.0/devices/02/ep02 in the xhci_debug.zip which was dumpped when Endpoint 1 IN token stopped,
found that:
but in the trbs:
Is that normal?
BR
Thanks
P33M commentedon Nov 22, 2021
I did notice that, but it's possible the TRB was turned into a no-op by error recovery operations on the ring.
It would be useful if you could try several more times to replicate the hang, and see where ep02's dequeue pointer is each time - is it always just after a Link TRB?
Also please post a full
sudo lsusb -vof the BLE adapter.JulianGu001 commentedon Nov 24, 2021
zhuhangtian commentedon Nov 24, 2021
pi4-usb-vl805-IN-token-issue-log-5segs.zip
Some more logs about this issue, tried allocate 5 segments for the endpoint (interrupt IN) instead of 2, the stuck trb is always the first trb of ring last segment (when 2 segments, it's also the first trb of 2nd segment).
for example, this endpiont allocated:
segment0->trbs dma addr: 0x41b61d000
segment1->trbs dma addr: 0x41b61c000
segment2->trbs dma addr: 0x41b61b000
segment3->trbs dma addr: 0x41b61a000
segment4->trbs dma addr: 0x41b619000
when the issue happens, dump the ring deq pointer:

the buffer 0(No-op) is set AFTER issue happens when stopping ep in td_to_noop() function, it's not the cause of the issue.
trb deq pointer: 0x41b619000, the 1st trb of last segment.
added some logs in xhci-hcd.

at the issue point, xhci set doorbell register, ring->enqueue trb is 0x41b619000, and the buffer(field1 field0) is 402b67e40
ftrace logs:

xhci ring doorbell for ep1in, but no more interrupt for ep1 anymore, since host controller is not sending IN token.
P33M commentedon Nov 24, 2021
There's a known bug in the Via controller where it can't handle a SET_DEQUEUE_POINTER command on a stopped ring where the TRB pointed to is a Link TRB. The ring isn't being stopped in this case, it should just be "parked" as it's an interrupt ring with no assigned TRBs. Ringing the doorbell should cause the controller to advance past the Link TRB and read the (now valid) first TRB in the next ring segment.
The same code flow is used for both bulk and interrupt traffic, and HID behaves the same way as your driver (submit a single URB at a time, which translates to a single active TRB on the ring), so why don't keyboards etc stop working?
As an experiment, what happens if you constrain the length of the buffer you use in your URB to exactly the maxpacket size of the endpoint - 16 bytes?
JulianGu001 commentedon Nov 24, 2021
Could this bug cause USB host to stop sending IN token of Interrupt Endpoint?And if it has been resolved in the latest kernel?
We have updated the kernel ot 5.10.77, but we can still reproduce this issue.
P33M commentedon Nov 24, 2021
I'm saying there's a possibility that this is a variant of an existing bug, but the existing bug is not in evidence in this case.
One thing I have noticed that is unusual: the transfer ring for EP02 has 5 segments, so it has grown in size from the default 2. Edit: I see you have noticed the same. Can you instrument the xhci_mem.c : xhci_ring_expansion() function to see if this is being called repeatedly?
There should be no reason for a low-bandwidth ring like this one to get expanded.
329 remaining items
usb: xhci: add VLI_TRB_CACHE_BUG quirk
usb: xhci: add VLI_TRB_CACHE_BUG quirk
usb: xhci: add VLI_TRB_CACHE_BUG quirk
usb: xhci: add VLI_TRB_CACHE_BUG quirk
usb: xhci: add VLI_TRB_CACHE_BUG quirk
usb: xhci: add VLI_TRB_CACHE_BUG quirk
usb: xhci: add VLI_TRB_CACHE_BUG quirk
usb: xhci: add VLI_TRB_CACHE_BUG quirk
usb: xhci: add VLI_TRB_CACHE_BUG quirk
usb: xhci: add VLI_TRB_CACHE_BUG quirk
usb: xhci: add VLI_TRB_CACHE_BUG quirk
usb: xhci: add VLI_TRB_CACHE_BUG quirk
usb: xhci: add VLI_TRB_CACHE_BUG quirk
usb: xhci: add VLI_TRB_CACHE_BUG quirk
usb: xhci: Enable the TRB overfetch quirk on VIA VL805