Download Data Center Software from Total Phase.
1 Aptiv DABR
Aptiv acquired Indian Unwired,Delphi Automotive USB Bridge / Hub,Hub中集成了UDC,upstream UDC连接的主机称为A-Host,downstream UDC被B-Host枚举成Relay device,2个UDC实现Host-to-Host功能。
DABR integrates Nios II/Cortex M0 and two SLS USB20SF, which means System Level Solutions USB 2.0 Device, Software Enumeration FIFO Interface, and there is an External FIFO Controller between two USB devices.
2 Microchip HFC Device
2.1 基本概念
HFC是Hub Feature Controller的缩写,其VID和PID为0x0424_0x7040。技术主要来源于收购的SMSC,该公司发明了HSIC接口(1.2V LVCMOS)。
USB HUB为什么没有port0?因为upstream就是port0,downstream口从port1开始。
2.2 HFC主要功能
1)IO桥接,包括GPIO/I2C/SPI/UART
2)FlexConnect,第一款支持FlexConnect的Hub是USB84604
3)CarPlay OTG Hub(另外一种独立销售的是USB CarPlay Dongle,也叫CarPlay盒子)
2.3 FlexConnect
Microchip Hub FlexConnect的技术实际是交换Hub Repeater的upstream port和downstream port。USB SETUP command的状态阶段的状态包是个ZLP。
Figure 2-1 MULTI-HOST BRIDGE SETUP PACKET
1)当ROLE_SWITCH_TYPE的值为00时,表示切换到H2H模式,此后内部的UDC1(Apple NCM和iAP2,VID和PID为0x0424_0x7010)连接到upstream,UDC2(Apple NCM和iAP2,VID和PID为0x0424_0x7020)连接到iPhone连接的那个downstream port,被iPhone枚举。
2)当ROLE_SWITCH_TYPE的值为01时,表示切换到flex模式,wValue只需使能HS port,不要使能SS port,否则电脑可能无法枚举hub。
2.4 APL xHCI LTSSM stuck issue
not warm reset yet, waiting 200ms
not enabled, trying warm reset again
This log shows ss port stuck issue.
Disable USB3 roothub port: Clear power Feature and Set BH_Reset Feature.
23 01 0008 port1 0000
23 03 001c port1 0000
Disable USB3 non roothub port: Set Rx.disabled Feature.
23 03 0005 0400|port1 0000
Add # define DEBUG at the first line of the hub.c file (above the header files) for enabling Linux dynamic debug log.
2.5 URLs
MicrochipTech/USB-Hub-Linux-Examples
https://github.com/MicrochipTech/USB-Hub-Linux-Examples
3 libusb库的使用
3.1 Linux查找libusb.h的路径
locate libusb.h
locate usb-1.0
3.2 libusb usbi_backend后端驱动
external/libusb/libusb/core.c
1)Linux
优先使用/dev/bus/usb/BBB/DDD(BBB是总线号,DDD是设备地址),如果该目录不存在,再使用/proc/bus/usb/BBB/DDD,最后才使用/dev/usbdev*.*。
Linux kernel usb_device内存释放的回调函数是usb_release_dev()。
2)Windows
使用动态库UsbDkHelper.dll(USB Development Kit)或者WinUsb。
3.3 Linux libusb调试
1)usbfs日志获取
echo 1 > /sys/module/usbcore/parameters/usbfs_snoop
dmesg -w | grep usb
2)usbfs使用内存调整
modprobe usbcore usbfs_memory_mb=64
3)60秒超时
可以将传输函数的实现都拷贝到自己的代码中,然后修改默认的60秒超时。
3.4 Hub libusb控制传输
1)获得Hub支持的端口数
bmRequestType:0xa0 /* LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_DEVICE */
bRequest:6 /* LIBUSB_REQUEST_GET_DESCRIPTOR */
wValue:SS是LIBUSB_DT_SUPERSPEED_HUB << 8,HS是LIBUSB_DT_HUB << 8
wIndex:0
wLength:SS是12,HS是sizeof(struct usb_hub_descriptor)
timeout:5000ms
返回的Hub描述符中的bNbrPorts是支持的端口数目。
2)获得Hub的portsc状态
bmRequestType:0xa3 /* LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_OTHER */
bRequest:0 /* LIBUSB_REQUEST_GET_STATUS */
wValue:0
wIndex:port1
wLength:4
timeout:1000ms
返回的0和1字节是wPortStatus,2和3字节是wPortChange,都是小端格式。
3)LTSSM状态的设置
bmRequestType:0x23 /* LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_OTHER */
bRequest:3 /* LIBUSB_REQUEST_SET_FEATURE */
wValue:5 /* USB_PORT_FEAT_LINK_STATE */
wIndex:port1 | link_state << 8
wLength:0
timeout:1000ms
其中link_state的值的范围从0到15,默认是5(LTSSM.RxDetect),详细内容参考xHCI spec page392。
设置link_state到LTSSM.Disabled后,对该端口BH_Reset或者removal-insertion,该port将强制进入HS模式。
4)HS或者SS port复位
bmRequestType:0x23 /* LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_OTHER */
bRequest:1 or 3 /* LIBUSB_REQUEST_CLEAR{SET}_FEATURE */
wValue:8 /* USB_PORT_FEAT_POWER */
wIndex:port1
wLength:0
timeout:1000ms
对于roothub port,需要Clear Feature和Set Feature成对出现;对于非roothub port,只需要Clear Feature,不需要Set Feature,否则SS port口无法复位。
Clearing power feature can disable USB3 LTSSM.
For BH_RESET, only set 0x1c to wValue, other fields are the same as LIBUSB_REQUEST_SET_FEATURE.
3.5 libusb zerocopy
libusb version 1.0.21: libusb_dev_mem_alloc()
https://forums.developer.nvidia.com/t/usbfs-zerocopy-not-working/66091/7
Linux下more命令C语言实现
for Linux Makefile
CFLAGS = -I/usr/include/libusb-1.0
LDFLAGS = -L/lib/x86_64-linux-gnu -lusb-1.0
4 Abbreviations
HUB3CV:USB 3 Hub Command Verifier Ver. 2.1.12.1
SMSC:Smart Mixed-Signal Connectivity
UCH:USB Controller Hub
USB BH reset:Bigger Hammer or Brad Hosler,表示warm reset;you may be confused why the USB 3.0 spec calls the same type of reset "warm reset" in some places and "BH reset" in other places. "BH" reset is supposed to stand for "Big Hammer" reset, but it also stands for "Brad Hosler". Brad died shortly after the USB 3.0 bus specification was started, and they decided to name the reset after him. The suggestion was made shortly before the spec was finalized, so the wording is a bit inconsistent.