linux下的ehci控制器调试

本文详细介绍了在Linux系统中如何调试EHCI(Enhanced Host Controller Interface)控制器,包括使用debugfs挂载调试文件系统,查看USB设备信息,深入解读usbfs中的Topology、Bandwidth、Device descriptor等Tag,以及分析async和periodic调度快照,同时提供了ehci运行状态统计和寄存器现场的解析。
摘要由CSDN通过智能技术生成

1 调试方法

linux下的usb ehci控制器的调试方法:
  1. mount -t debugfs debugfs /sys/kernel/debug
  2. cat /sys/kernel/debug/usb/devices
  3. cat /sys/kernel/debug/usb/usbmon/$(bus_num)u
  4. ehci控制器下的async、periodic、registers等字段的解析
步骤1:目的是mount上调试文件系统,这个调试文件系统功能强大,譬如gpio,audio,usb,binder等模块,在这下面都提供了丰富的信息。
步骤2:查看目前usb host controller下,设备的链接情况及usb设备的信息
步骤3:抓特定usb controller下的usb传输包,该部分的详细解析,请查看我的另一篇blog:linux下的usb抓包方法
步骤4: 查看ehci控制器的驱动工作情况,这里重点讨论这条

2 解读


2.1 usbfs

        usbfs文件系统提供当前链接的usb设备的设备信息,usbfs的代码实现,请参考:linux/drivers/usb/core/inode.c。 另外通过usbfs,可以在用户空间实现usb的驱动,即在用户空间发起usb的控制、块传输。接口代码在如下位置:linux/drivers/usb/core/devio.c 下面我将解析下usbfs中的/sys/kernel/debug/usb/devices文件的格式和含义:

2.1.1 Topology Tag


    通过tag为T的条目,可以知道目前系统的usb设备的链接情况,即设备的拓扑结构图。
Selecting only the "T:" and "I:" lines from output of devices file(for example, by using
"procusb ti"), we have:
T:  Bus=00 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12   MxCh= 2
T:  Bus=00 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  2 Spd=12   MxCh= 4
I:  If#= 0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub
T:  Bus=00 Lev=02 Prnt=02 Port=00 Cnt=01 Dev#=  3 Spd=1.5  MxCh= 0
I:  If#= 0 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=01 Prot=02 Driver=mouse
T:  Bus=00 Lev=02 Prnt=02 Port=02 Cnt=02 Dev#=  4 Spd=12   MxCh= 0
I:  If#= 0 Alt= 0 #EPs= 3 Cls=00(>ifc ) Sub=00 Prot=00 Driver=serial

Physically this looks like (or could be converted to):


Or, in a more tree-like structure (ports [Connectors] without
connections could be omitted):

PC:  Dev# 1, root hub, 2 ports, 12 Mbps
|_ CN.0:  Dev# 2, hub, 4 ports, 12 Mbps
     |_ CN.0:  Dev #3, mouse, 1.5 Mbps
     |_ CN.1:
     |_ CN.2:  Dev #4, serial, 12 Mbps
     |_ CN.3:
|_ CN.1:

2.1.2 Bandwidth Tag

Bandwidth info:


    Bandwidth allocation is an approximation of how much of one frame
    (millisecond) is in use.  It reflects only periodic transfers, which
    are the only transfers that reserve bandwidth.  Control and bulk
    transfers use all other bandwidth, including reserved bandwidth that
    is not used for transfers (such as for short packets).

    The percentage is how much of the "reserved" bandwidth is scheduled by
    those transfers.  For a low or full speed bus (loosely, "USB 1.1"),
    90% of the bus bandwidth is reserved.  For a high speed bus (loosely,
    "USB 2.0") 80% is reserved.

2.1.3 Device descriptor andProduct ID Tag

Device descriptor info & Product ID info:
D:  Ver=x.xx Cls=xx(s) Sub=xx Prot=xx MxPS=dd #Cfgs=dd
P:  Vendor=xxxx ProdID=xxxx Rev=xx.xx

MaxPacketSize of Default Endpoint:即是控制端点的最大包大小

2.1.4 Configuration Tag

Configuration descriptor info:


    USB devices may have multiple configurations, each of which act
    rather differently.  For example, a bus-powered configuration
    might be much less capable than one that is self-powered.  Only
    one device configuration can be active at a time; most devices
    have only one configuration.

    Each configuration consists of one or more interfaces.  Each
    interface serves a distinct "function", which is typically bound
    to a different USB device driver.  One common example is a USB
    speaker with an audio interface for playback, and a HID interface
    for use with software volume control.
    一个设备可能有多个配置,一个配置可能有多个接口,但同一时间,只能有一个配置生效;但同一时间则可以有多个接口生效,对于有多个配置的情况,C后面的*号,标记当前生效的配置

2.1.5 Interface Tag

Interface descriptor info (can be multiple per Config):


    A given interface may have one or more "alternate" settings.
    For example, default settings may not use more than a small
    amount of periodic bandwidth.  To use significant fractions
    of bus bandwidth, drivers must select a non-default altsetting.

    Only one setting for an interface may be active at a time, and
    only one driver may bind to an interface at a time.  Most devices
    have only one alternate setting per interface.
    一个配置可能包含多个接口,而一个接口则可以包含多个可选的设置,这些可选
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值