Linux USB主机sysfs以及usbmon抓包

1 lsusb –t返回结果解释
/: Bus 08.Port 1: Dev 1, Class=root\_hub, Driver=uhci_hcd/2p, 12M
/: Bus 07.Port 1: Dev 1, Class=root\_hub, Driver=uhci_hcd/2p, 12M
/: Bus 06.Port 1: Dev 1, Class=root\_hub, Driver=uhci_hcd/2p, 12M
/: Bus 05.Port 1: Dev 1, Class=root\_hub, Driver=uhci_hcd/2p, 12M
/: Bus 04.Port 1: Dev 1, Class=root\_hub, Driver=uhci_hcd/2p, 12M
/: Bus 03.Port 1: Dev 1, Class=root\_hub, Driver=uhci_hcd/2p, 12M
/: Bus 02.Port 1: Dev 1, Class=root\_hub, Driver=ehci_hcd/6p, 480M
|__ Port 1: Dev 4, If 0, Class=stor., Driver=usb-storage, 480M
|__ Port 6: Dev 3, If 0, Class=’bInterfaceClass 0x0e not yet handled’, Driver=uvcvideo, 480M
|__ Port 6: Dev 3, If 1, Class=’bInterfaceClass 0x0e not yet handled’, Driver=uvcvideo, 480M
/: Bus 01.Port 1: Dev 1, Class=root\_hub, Driver=ehci_hcd/6p, 480M

2-1:4-0 for example, normally this can be explained as shown below.
2: Bus Number
1: Port Number
4: Device Number
0: Interface Number

2 LDD3
The USB sysfs device naming scheme is:
root_hub-hub_port:config.interface

As the devices go further down in the USB tree, and as more and more USB hubs are used, the hub port number is added to the strin gfollowin gthe previous hub port number in the chain. For a two-deep tree, the device name looks like:

bus-port.port.port ... :config.interface

3 Linux usbmon抓包
3.1 tcpdump - 节点/dev/usbmonX
1)mount -t debugfs none_debugs /sys/kernel/debug
2)cat /sys/kernel/debug/usb/devices - 确定usb的总线号
3)tcpdump -D
4)tcpdump -i usbmon1 -s 128 -w /data/usblog.pcap &
5)killall tcpdump
6)wireshark工具打开usblog.pcap

usbmon1 - xHCI LS/FS/HS
usbmon2 - xHCI SS

3.2 Wireshark过滤规则
1)usb.src == "1.6.1" and usb.dst == "host" - 改到对应的USB bus_no.addr.ep_no
2)usb.src == host and ublox

3.3 USB协议URB解析Wireshark插件
usb_table = DissectorTable.get("usb.bulk")
usb_table:add(0xff, my_proto)
usb_table:add(0xffff, my_proto)

3.4 usbmon sysfs接口
cat /sys/kernel/debug/usb/usbmon/1u > /sdcard/1u_usbmon.txt
命令中1u表示Bus=01,通过命令获得cat /sys/kernel/debug/usb/devices

cd /sys/kernel/debug/usb/usbmon
反向查找,查找不包含"1:003:2"(总线号:设备地址:端点号)字符串的其它内容
cat 1u  |grep -v "1:003:2"
排除多个字符串:cat 1u  |grep -vE "1:003:2|1:004:1"

3.5 usbfs
echo 1 > /sys/module/usbcore/parameters/usbfs_snoop

4 USB电源管理
4.1 全局禁止运行时autosuspend
echo -1 > /sys/module/usbcore/parameters/autosuspend

4.2 xHCI autosuspend
一个xHCI会注册2个host,一个是usb1(LS/FS/HS),另一个是usb2(SS)。
禁止usb1电源管理:
echo on > /sys/bus/usb/devices/usb1/power/control
禁止usb2电源管理:
echo on > /sys/bus/usb/devices/usb2/power/control

5 USB主机PORTSC寄存器
- EHCI每个port有一个寄存器PORTSC
- xHCI每个port有包含PORTSC在内的4个寄存器

5.1 USB2
Connected:
PORTSC1.CCS (bit 0) - Current Connection Status
PORTSC1.CSC (bit 1) - Connection Status Change

Reset - Great Than 10ms:
PORTSC1.PR (bit 8) - Port Reset
PORTSC1.PE (bit 2) - Port Enable

Disconnected:
PORTSC1.CCS (bit 0) 
PORTSC1.CSC (bit 1)
PORTSC1.PEC(bit 3) - Port Enable Change

5.2 USB3
Connected:
PORTSC.CCS (bit0 ) - Current Connection Status

Reset - Great Than 10ms:
PORTSC.PR (bit4) - Port Reset
PORTSC.PED (bit1) - Port Enabled/Disabled

echo "file xhci-hub.c +p" > /d/dynamic_debug/control
dmesg -n4
wPortStatus & 0x03表示复位成功

6 Abbreviations
ARC:Argonant RISC Core
AT91SAM9260:SAM means Smart ARM-based Microcontroller
ATMEL SAMBA:ATMEL Smart ARM-based Microcontroller Boot Assistant
CC2530:TI ChipCon2530
DWC2:Design Ware Controller 2,Apple的嵌入式设备,包括iPad和iPhone都是使用的DWC2
ISP1161:Philips' Integrated host Solution Pairs 1161,“Firms introduce USB host controllers”,https://www.eetimes.com/document.asp?doc_id=1290054
MDATA:More DATA,USB ep双缓冲(ep_kind配置使能)切换机制对应到DATA0和DATA1
MPH:USB Multi-Port Host,Intel的MPH的Port1作为OTG使用,和DWC3(仅作为slave)使用一个MUX开关来控制Host还是UDC连接到该Port1
Quirks:the attributes of a device that are considered to be noncompliant with expected operation
SL811HS:Cypress/ScanLogic 811 Host/Slave,性能上与ISP1161(Integrated host Solution Pairs 1161)相当
SPH:USB Single-Port Host
TDI:TransDimension Inc.,该公司首先发明了将TT集成到EHCI RootHub中的方法,这样对于嵌入式系统来说,就省去了OHCI/UHCI的硬件,同时降低了成本,作为对该公司的纪念,Linux内核定义了宏ehci_is_TDI(ehci);产品UHC124表示USB Host Controller;收购了ARC USB技术;现已被chipidea收购,chipidea又被mips收购
TLV:TI Low Value,高性价比
TPS:TI Performance Solution
TT:Transaction Translator(事务转换器,将USB2.0的包转换成USB1.1的包)
USB KVM:KVM是键盘(Keyboard)、显示器(Video)、鼠标(Mouse)的缩写;KVM端口是25-pin,包含VGA接口和USB接口
uSOF:micro Start of Frame,125us

发布了121 篇原创文章 · 获赞 49 · 访问量 32万+

猜你喜欢

转载自blog.csdn.net/zoosenpin/article/details/73840463
今日推荐