On 14.5.2023 4.50, yunhua li wrote:
yunhua li <yunhual@xxxxxxxxx> 6:46 PM (2 minutes ago) to linux-usb Hello all For USB 3.0 isochronous endpoint, anyone know how to calculate bandwidth for an XHCI chip? I have 3 isochronous Cameras. Camera1: 1920*1200*16(YUV) *20(FPS) = 737280000 ~ 740Mb/s Camera2: 1200*1200*16(YUV) * 20(FPS) = 460800000 ~ 470Mb/s Camera3: 1200*1200*16(YUV) * 20(FPS) = 460800000 ~ 470Mb/s 16(YUV) is 2 byte YUV encoding for each pixel. 20(FPS) is the frame rate. Total bandwidth 740+470+470 = 1680Mb/s ~ 1.7Gb/s USB 3.0 speed is 5Gbps. count in 10b/8b encoding, is 4Gbps. I know there is some protocol overhead. When I open the 3rd camera with guvcview or other software. I got the following error. xhci_hcd 0000:49:00.0: xhci_check_bandwidth called for udev 000000004bbf2dcd xhci_hcd 0000:49:00.0: // Ding dong! usb 10-2: Not enough bandwidth for new device state. xhci_hcd 0000:49:00.0: xhci_reset_bandwidth called for udev 000000004bbf2dcd usb 10-2: Not enough bandwidth for altsetting 1 the error comes xhci_check_bandwidth from https://elixir.bootlin.com/linux/v5.10.140/source/drivers/usb/host/xhci.c#L2906 xhci_configure_endpoint https://elixir.bootlin.com/linux/v5.10.140/source/drivers/usb/host/xhci.c#L2862 The result is COMP_BANDWIDTH_ERROR or COMP_SECONDARY_BANDWIDTH_ERROR https://elixir.bootlin.com/linux/v5.10.140/source/drivers/usb/host/xhci.c#L2022 The bandwidth check is done by hardware, not software, I just want to know how to calculate the max supported bandwidth for 3 isochronous devices? I tried to read the XHCI spec. https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/extensible-host-controler-interface-usb-xhci.pdf But I couldn't figure it out. I appreciate any help, and thanks for your time to read my post.
Disclaimer: haven't really needed to calculate or look deep into this as hardware does the bandwidth calculation, but here's how I understood it: USB 3.0 (Gen 1) A microframe is 125 microseconds (8 per millisecond, or 8000 per second) a microframe can fit 3 isoc bursts, a burst can contain 16 isoc packets a isoc packet can contain 1024 bytes. So for usb 3.0 you got 8000 * 3* 16 * 1024 bytes, roughly 393 Mbytes (~3.15 Gbits) for one USB 3.0 superspeed bus instance. Depending on the xHC vendor there can be a dedicated USB 3.0 bus instance per roothub port, or it several ports may share a bus instance, or possibly have only one bus instance shared among all usb 3.0 roothub ports. USB 3 spec says max 90% of bandwidth can be allocated for isoc transfers xhci specs says "Total Available Bandwidth will be at least 20% lower than the cited bit rate of a Bus Instance" Instead of looking at camera bandwidth it's probably better to look at the MaxPacketSize, MaxBurst, Interval, and BytesPerInterval fields of the camera isoc endpoint descriptors. Add together those for all active isoc endpoints and check if it fits the 3 bursts, 16 packets, 1024 bytes. Remember the Interval, most devices don't send data every microframe. xhci supports a "Get port bandwidth" command that shows available bandwidth per port at the moment. Current upstream driver does not support it, but I have some old debugging patches that could be rebased and tried out if you are interested. Thanks Mathias