1e463c063SMauro Carvalho Chehab.. _usb-hostside-api: 2e463c063SMauro Carvalho Chehab 34ad4b21bSMauro Carvalho Chehab=========================== 44ad4b21bSMauro Carvalho ChehabThe Linux-USB Host Side API 54ad4b21bSMauro Carvalho Chehab=========================== 64ad4b21bSMauro Carvalho Chehab 74ad4b21bSMauro Carvalho ChehabIntroduction to USB on Linux 84ad4b21bSMauro Carvalho Chehab============================ 94ad4b21bSMauro Carvalho Chehab 104ad4b21bSMauro Carvalho ChehabA Universal Serial Bus (USB) is used to connect a host, such as a PC or 114ad4b21bSMauro Carvalho Chehabworkstation, to a number of peripheral devices. USB uses a tree 124ad4b21bSMauro Carvalho Chehabstructure, with the host as the root (the system's master), hubs as 134ad4b21bSMauro Carvalho Chehabinterior nodes, and peripherals as leaves (and slaves). Modern PCs 144ad4b21bSMauro Carvalho Chehabsupport several such trees of USB devices, usually 154ad4b21bSMauro Carvalho Chehaba few USB 3.0 (5 GBit/s) or USB 3.1 (10 GBit/s) and some legacy 164ad4b21bSMauro Carvalho ChehabUSB 2.0 (480 MBit/s) busses just in case. 174ad4b21bSMauro Carvalho Chehab 184ad4b21bSMauro Carvalho ChehabThat master/slave asymmetry was designed-in for a number of reasons, one 194ad4b21bSMauro Carvalho Chehabbeing ease of use. It is not physically possible to mistake upstream and 204ad4b21bSMauro Carvalho Chehabdownstream or it does not matter with a type C plug (or they are built into the 214ad4b21bSMauro Carvalho Chehabperipheral). Also, the host software doesn't need to deal with 224ad4b21bSMauro Carvalho Chehabdistributed auto-configuration since the pre-designated master node 234ad4b21bSMauro Carvalho Chehabmanages all that. 244ad4b21bSMauro Carvalho Chehab 254ad4b21bSMauro Carvalho ChehabKernel developers added USB support to Linux early in the 2.2 kernel 264ad4b21bSMauro Carvalho Chehabseries and have been developing it further since then. Besides support 274ad4b21bSMauro Carvalho Chehabfor each new generation of USB, various host controllers gained support, 284ad4b21bSMauro Carvalho Chehabnew drivers for peripherals have been added and advanced features for latency 294ad4b21bSMauro Carvalho Chehabmeasurement and improved power management introduced. 304ad4b21bSMauro Carvalho Chehab 314ad4b21bSMauro Carvalho ChehabLinux can run inside USB devices as well as on the hosts that control 324ad4b21bSMauro Carvalho Chehabthe devices. But USB device drivers running inside those peripherals 334ad4b21bSMauro Carvalho Chehabdon't do the same things as the ones running inside hosts, so they've 344ad4b21bSMauro Carvalho Chehabbeen given a different name: *gadget drivers*. This document does not 354ad4b21bSMauro Carvalho Chehabcover gadget drivers. 364ad4b21bSMauro Carvalho Chehab 374ad4b21bSMauro Carvalho ChehabUSB Host-Side API Model 384ad4b21bSMauro Carvalho Chehab======================= 394ad4b21bSMauro Carvalho Chehab 404ad4b21bSMauro Carvalho ChehabHost-side drivers for USB devices talk to the "usbcore" APIs. There are 414ad4b21bSMauro Carvalho Chehabtwo. One is intended for *general-purpose* drivers (exposed through 424ad4b21bSMauro Carvalho Chehabdriver frameworks), and the other is for drivers that are *part of the 434ad4b21bSMauro Carvalho Chehabcore*. Such core drivers include the *hub* driver (which manages trees 444ad4b21bSMauro Carvalho Chehabof USB devices) and several different kinds of *host controller 454ad4b21bSMauro Carvalho Chehabdrivers*, which control individual busses. 464ad4b21bSMauro Carvalho Chehab 474ad4b21bSMauro Carvalho ChehabThe device model seen by USB drivers is relatively complex. 484ad4b21bSMauro Carvalho Chehab 494ad4b21bSMauro Carvalho Chehab- USB supports four kinds of data transfers (control, bulk, interrupt, 504ad4b21bSMauro Carvalho Chehab and isochronous). Two of them (control and bulk) use bandwidth as 514ad4b21bSMauro Carvalho Chehab it's available, while the other two (interrupt and isochronous) are 524ad4b21bSMauro Carvalho Chehab scheduled to provide guaranteed bandwidth. 534ad4b21bSMauro Carvalho Chehab 544ad4b21bSMauro Carvalho Chehab- The device description model includes one or more "configurations" 554ad4b21bSMauro Carvalho Chehab per device, only one of which is active at a time. Devices are supposed 564ad4b21bSMauro Carvalho Chehab to be capable of operating at lower than their top 574ad4b21bSMauro Carvalho Chehab speeds and may provide a BOS descriptor showing the lowest speed they 584ad4b21bSMauro Carvalho Chehab remain fully operational at. 594ad4b21bSMauro Carvalho Chehab 604ad4b21bSMauro Carvalho Chehab- From USB 3.0 on configurations have one or more "functions", which 614ad4b21bSMauro Carvalho Chehab provide a common functionality and are grouped together for purposes 624ad4b21bSMauro Carvalho Chehab of power management. 634ad4b21bSMauro Carvalho Chehab 644ad4b21bSMauro Carvalho Chehab- Configurations or functions have one or more "interfaces", each of which may have 654ad4b21bSMauro Carvalho Chehab "alternate settings". Interfaces may be standardized by USB "Class" 664ad4b21bSMauro Carvalho Chehab specifications, or may be specific to a vendor or device. 674ad4b21bSMauro Carvalho Chehab 684ad4b21bSMauro Carvalho Chehab USB device drivers actually bind to interfaces, not devices. Think of 694ad4b21bSMauro Carvalho Chehab them as "interface drivers", though you may not see many devices 704ad4b21bSMauro Carvalho Chehab where the distinction is important. *Most USB devices are simple, 714ad4b21bSMauro Carvalho Chehab with only one function, one configuration, one interface, and one alternate 724ad4b21bSMauro Carvalho Chehab setting.* 734ad4b21bSMauro Carvalho Chehab 744ad4b21bSMauro Carvalho Chehab- Interfaces have one or more "endpoints", each of which supports one 754ad4b21bSMauro Carvalho Chehab type and direction of data transfer such as "bulk out" or "interrupt 764ad4b21bSMauro Carvalho Chehab in". The entire configuration may have up to sixteen endpoints in 774ad4b21bSMauro Carvalho Chehab each direction, allocated as needed among all the interfaces. 784ad4b21bSMauro Carvalho Chehab 794ad4b21bSMauro Carvalho Chehab- Data transfer on USB is packetized; each endpoint has a maximum 804ad4b21bSMauro Carvalho Chehab packet size. Drivers must often be aware of conventions such as 814ad4b21bSMauro Carvalho Chehab flagging the end of bulk transfers using "short" (including zero 824ad4b21bSMauro Carvalho Chehab length) packets. 834ad4b21bSMauro Carvalho Chehab 844ad4b21bSMauro Carvalho Chehab- The Linux USB API supports synchronous calls for control and bulk 854ad4b21bSMauro Carvalho Chehab messages. It also supports asynchronous calls for all kinds of data 864ad4b21bSMauro Carvalho Chehab transfer, using request structures called "URBs" (USB Request 874ad4b21bSMauro Carvalho Chehab Blocks). 884ad4b21bSMauro Carvalho Chehab 894ad4b21bSMauro Carvalho ChehabAccordingly, the USB Core API exposed to device drivers covers quite a 904ad4b21bSMauro Carvalho Chehablot of territory. You'll probably need to consult the USB 3.0 914ad4b21bSMauro Carvalho Chehabspecification, available online from www.usb.org at no cost, as well as 924ad4b21bSMauro Carvalho Chehabclass or device specifications. 934ad4b21bSMauro Carvalho Chehab 944ad4b21bSMauro Carvalho ChehabThe only host-side drivers that actually touch hardware (reading/writing 954ad4b21bSMauro Carvalho Chehabregisters, handling IRQs, and so on) are the HCDs. In theory, all HCDs 964ad4b21bSMauro Carvalho Chehabprovide the same functionality through the same API. In practice, that's 974ad4b21bSMauro Carvalho Chehabbecoming more true, but there are still differences 984ad4b21bSMauro Carvalho Chehabthat crop up especially with fault handling on the less common controllers. 994ad4b21bSMauro Carvalho ChehabDifferent controllers don't 1004ad4b21bSMauro Carvalho Chehabnecessarily report the same aspects of failures, and recovery from 1014ad4b21bSMauro Carvalho Chehabfaults (including software-induced ones like unlinking an URB) isn't yet 1024ad4b21bSMauro Carvalho Chehabfully consistent. Device driver authors should make a point of doing 1034ad4b21bSMauro Carvalho Chehabdisconnect testing (while the device is active) with each different host 1044ad4b21bSMauro Carvalho Chehabcontroller driver, to make sure drivers don't have bugs of their own as 1054ad4b21bSMauro Carvalho Chehabwell as to make sure they aren't relying on some HCD-specific behavior. 1064ad4b21bSMauro Carvalho Chehab 1079a3c8b35SMauro Carvalho Chehab.. _usb_chapter9: 1089a3c8b35SMauro Carvalho Chehab 1094ad4b21bSMauro Carvalho ChehabUSB-Standard Types 1104ad4b21bSMauro Carvalho Chehab================== 1114ad4b21bSMauro Carvalho Chehab 1126c05cdbbSFabio EstevamIn ``include/uapi/linux/usb/ch9.h`` you will find the USB data types defined 1136c05cdbbSFabio Estevamin chapter 9 of the USB specification. These data types are used throughout 1146c05cdbbSFabio EstevamUSB, and in APIs including this host side API, gadget APIs, usb character 1156c05cdbbSFabio Estevamdevices and debugfs interfaces. That file is itself included by 1166c05cdbbSFabio Estevam``include/linux/usb/ch9.h``, which also contains declarations of a few 1176c05cdbbSFabio Estevamutility routines for manipulating these data types; the implementations 1186c05cdbbSFabio Estevamare in ``drivers/usb/common/common.c``. 1194ad4b21bSMauro Carvalho Chehab 120caa93d9bSFabio Estevam.. kernel-doc:: drivers/usb/common/common.c 121caa93d9bSFabio Estevam :export: 1224ad4b21bSMauro Carvalho Chehab 1236c05cdbbSFabio EstevamIn addition, some functions useful for creating debugging output are 1246c05cdbbSFabio Estevamdefined in ``drivers/usb/common/debug.c``. 1259a3c8b35SMauro Carvalho Chehab 12610505b72SFabio Estevam.. _usb_header: 12710505b72SFabio Estevam 1284ad4b21bSMauro Carvalho ChehabHost-Side Data Types and Macros 1294ad4b21bSMauro Carvalho Chehab=============================== 1304ad4b21bSMauro Carvalho Chehab 1314ad4b21bSMauro Carvalho ChehabThe host side API exposes several layers to drivers, some of which are 1324ad4b21bSMauro Carvalho Chehabmore necessary than others. These support lifecycle models for host side 1334ad4b21bSMauro Carvalho Chehabdrivers and devices, and support passing buffers through usbcore to some 1344ad4b21bSMauro Carvalho ChehabHCD that performs the I/O for the device driver. 1354ad4b21bSMauro Carvalho Chehab 1364ad4b21bSMauro Carvalho Chehab.. kernel-doc:: include/linux/usb.h 1374ad4b21bSMauro Carvalho Chehab :internal: 1384ad4b21bSMauro Carvalho Chehab 1394ad4b21bSMauro Carvalho ChehabUSB Core APIs 1404ad4b21bSMauro Carvalho Chehab============= 1414ad4b21bSMauro Carvalho Chehab 1424ad4b21bSMauro Carvalho ChehabThere are two basic I/O models in the USB API. The most elemental one is 1434ad4b21bSMauro Carvalho Chehabasynchronous: drivers submit requests in the form of an URB, and the 1444ad4b21bSMauro Carvalho ChehabURB's completion callback handles the next step. All USB transfer types 1454ad4b21bSMauro Carvalho Chehabsupport that model, although there are special cases for control URBs 1464ad4b21bSMauro Carvalho Chehab(which always have setup and status stages, but may not have a data 1474ad4b21bSMauro Carvalho Chehabstage) and isochronous URBs (which allow large packets and include 1484ad4b21bSMauro Carvalho Chehabper-packet fault reports). Built on top of that is synchronous API 1494ad4b21bSMauro Carvalho Chehabsupport, where a driver calls a routine that allocates one or more URBs, 1504ad4b21bSMauro Carvalho Chehabsubmits them, and waits until they complete. There are synchronous 1514ad4b21bSMauro Carvalho Chehabwrappers for single-buffer control and bulk transfers (which are awkward 1524ad4b21bSMauro Carvalho Chehabto use in some driver disconnect scenarios), and for scatterlist based 1534ad4b21bSMauro Carvalho Chehabstreaming i/o (bulk or interrupt). 1544ad4b21bSMauro Carvalho Chehab 1554ad4b21bSMauro Carvalho ChehabUSB drivers need to provide buffers that can be used for DMA, although 1564ad4b21bSMauro Carvalho Chehabthey don't necessarily need to provide the DMA mapping themselves. There 1574ad4b21bSMauro Carvalho Chehabare APIs to use used when allocating DMA buffers, which can prevent use 1584ad4b21bSMauro Carvalho Chehabof bounce buffers on some systems. In some cases, drivers may be able to 1594ad4b21bSMauro Carvalho Chehabrely on 64bit DMA to eliminate another kind of bounce buffer. 1604ad4b21bSMauro Carvalho Chehab 1614ad4b21bSMauro Carvalho Chehab.. kernel-doc:: drivers/usb/core/urb.c 1624ad4b21bSMauro Carvalho Chehab :export: 1634ad4b21bSMauro Carvalho Chehab 1644ad4b21bSMauro Carvalho Chehab.. kernel-doc:: drivers/usb/core/message.c 1654ad4b21bSMauro Carvalho Chehab :export: 1664ad4b21bSMauro Carvalho Chehab 1674ad4b21bSMauro Carvalho Chehab.. kernel-doc:: drivers/usb/core/file.c 1684ad4b21bSMauro Carvalho Chehab :export: 1694ad4b21bSMauro Carvalho Chehab 1704ad4b21bSMauro Carvalho Chehab.. kernel-doc:: drivers/usb/core/driver.c 1714ad4b21bSMauro Carvalho Chehab :export: 1724ad4b21bSMauro Carvalho Chehab 1734ad4b21bSMauro Carvalho Chehab.. kernel-doc:: drivers/usb/core/usb.c 1744ad4b21bSMauro Carvalho Chehab :export: 1754ad4b21bSMauro Carvalho Chehab 1764ad4b21bSMauro Carvalho Chehab.. kernel-doc:: drivers/usb/core/hub.c 1774ad4b21bSMauro Carvalho Chehab :export: 1784ad4b21bSMauro Carvalho Chehab 1794ad4b21bSMauro Carvalho ChehabHost Controller APIs 1804ad4b21bSMauro Carvalho Chehab==================== 1814ad4b21bSMauro Carvalho Chehab 1824ad4b21bSMauro Carvalho ChehabThese APIs are only for use by host controller drivers, most of which 1834ad4b21bSMauro Carvalho Chehabimplement standard register interfaces such as XHCI, EHCI, OHCI, or UHCI. UHCI 1844ad4b21bSMauro Carvalho Chehabwas one of the first interfaces, designed by Intel and also used by VIA; 1854ad4b21bSMauro Carvalho Chehabit doesn't do much in hardware. OHCI was designed later, to have the 1864ad4b21bSMauro Carvalho Chehabhardware do more work (bigger transfers, tracking protocol state, and so 1874ad4b21bSMauro Carvalho Chehabon). EHCI was designed with USB 2.0; its design has features that 1884ad4b21bSMauro Carvalho Chehabresemble OHCI (hardware does much more work) as well as UHCI (some parts 1894ad4b21bSMauro Carvalho Chehabof ISO support, TD list processing). XHCI was designed with USB 3.0. It 1904ad4b21bSMauro Carvalho Chehabcontinues to shift support for functionality into hardware. 1914ad4b21bSMauro Carvalho Chehab 1924ad4b21bSMauro Carvalho ChehabThere are host controllers other than the "big three", although most PCI 1934ad4b21bSMauro Carvalho Chehabbased controllers (and a few non-PCI based ones) use one of those 1944ad4b21bSMauro Carvalho Chehabinterfaces. Not all host controllers use DMA; some use PIO, and there is 1954ad4b21bSMauro Carvalho Chehabalso a simulator and a virtual host controller to pipe USB over the network. 1964ad4b21bSMauro Carvalho Chehab 1974ad4b21bSMauro Carvalho ChehabThe same basic APIs are available to drivers for all those controllers. 1984ad4b21bSMauro Carvalho ChehabFor historical reasons they are in two layers: :c:type:`struct 1994ad4b21bSMauro Carvalho Chehabusb_bus <usb_bus>` is a rather thin layer that became available 2004ad4b21bSMauro Carvalho Chehabin the 2.2 kernels, while :c:type:`struct usb_hcd <usb_hcd>` 2014ad4b21bSMauro Carvalho Chehabis a more featureful layer 2024ad4b21bSMauro Carvalho Chehabthat lets HCDs share common code, to shrink driver size and 2034ad4b21bSMauro Carvalho Chehabsignificantly reduce hcd-specific behaviors. 2044ad4b21bSMauro Carvalho Chehab 2054ad4b21bSMauro Carvalho Chehab.. kernel-doc:: drivers/usb/core/hcd.c 2064ad4b21bSMauro Carvalho Chehab :export: 2074ad4b21bSMauro Carvalho Chehab 2084ad4b21bSMauro Carvalho Chehab.. kernel-doc:: drivers/usb/core/hcd-pci.c 2094ad4b21bSMauro Carvalho Chehab :export: 2104ad4b21bSMauro Carvalho Chehab 2114ad4b21bSMauro Carvalho Chehab.. kernel-doc:: drivers/usb/core/buffer.c 2124ad4b21bSMauro Carvalho Chehab :internal: 2134ad4b21bSMauro Carvalho Chehab 2148a6a285dSMauro Carvalho ChehabThe USB character device nodes 2158a6a285dSMauro Carvalho Chehab============================== 2164ad4b21bSMauro Carvalho Chehab 2178a6a285dSMauro Carvalho ChehabThis chapter presents the Linux character device nodes. You may prefer 2188a6a285dSMauro Carvalho Chehabto avoid writing new kernel code for your USB driver. User mode device 2198a6a285dSMauro Carvalho Chehabdrivers are usually packaged as applications or libraries, and may use 2208a6a285dSMauro Carvalho Chehabcharacter devices through some programming library that wraps it. 22196801b35SMauro Carvalho ChehabSuch libraries include: 22296801b35SMauro Carvalho Chehab 22396801b35SMauro Carvalho Chehab - `libusb <http://libusb.sourceforge.net>`__ for C/C++, and 22496801b35SMauro Carvalho Chehab - `jUSB <http://jUSB.sourceforge.net>`__ for Java. 22596801b35SMauro Carvalho Chehab 22696801b35SMauro Carvalho ChehabSome old information about it can be seen at the "USB Device Filesystem" 22796801b35SMauro Carvalho Chehabsection of the USB Guide. The latest copy of the USB Guide can be found 22896801b35SMauro Carvalho Chehabat http://www.linux-usb.org/ 2294ad4b21bSMauro Carvalho Chehab 2309a3c8b35SMauro Carvalho Chehab.. note:: 2314ad4b21bSMauro Carvalho Chehab 2328a6a285dSMauro Carvalho Chehab - They were used to be implemented via *usbfs*, but this is not part of 2338a6a285dSMauro Carvalho Chehab the sysfs debug interface. 2348a6a285dSMauro Carvalho Chehab 2358a6a285dSMauro Carvalho Chehab - This particular documentation is incomplete, especially with respect 2364ad4b21bSMauro Carvalho Chehab to the asynchronous mode. As of kernel 2.5.66 the code and this 2374ad4b21bSMauro Carvalho Chehab (new) documentation need to be cross-reviewed. 2384ad4b21bSMauro Carvalho Chehab 2398a6a285dSMauro Carvalho ChehabWhat files are in "devtmpfs"? 2408a6a285dSMauro Carvalho Chehab----------------------------- 2414ad4b21bSMauro Carvalho Chehab 2428a6a285dSMauro Carvalho ChehabConventionally mounted at ``/dev/bus/usb/``, usbfs features include: 2434ad4b21bSMauro Carvalho Chehab 24496801b35SMauro Carvalho Chehab- ``/dev/bus/usb/BBB/DDD`` ... magic files exposing the each device's 2454ad4b21bSMauro Carvalho Chehab configuration descriptors, and supporting a series of ioctls for 2464ad4b21bSMauro Carvalho Chehab making device requests, including I/O to devices. (Purely for access 2474ad4b21bSMauro Carvalho Chehab by programs.) 2484ad4b21bSMauro Carvalho Chehab 24996801b35SMauro Carvalho ChehabEach bus is given a number (``BBB``) based on when it was enumerated; within 25096801b35SMauro Carvalho Chehabeach bus, each device is given a similar number (``DDD``). Those ``BBB/DDD`` 2514ad4b21bSMauro Carvalho Chehabpaths are not "stable" identifiers; expect them to change even if you 2524ad4b21bSMauro Carvalho Chehabalways leave the devices plugged in to the same hub port. *Don't even 2534ad4b21bSMauro Carvalho Chehabthink of saving these in application configuration files.* Stable 2544ad4b21bSMauro Carvalho Chehabidentifiers are available, for user mode applications that want to use 2554ad4b21bSMauro Carvalho Chehabthem. HID and networking devices expose these stable IDs, so that for 2564ad4b21bSMauro Carvalho Chehabexample you can be sure that you told the right UPS to power down its 25796801b35SMauro Carvalho Chehabsecond server. Pleast note that it doesn't (yet) expose those IDs. 2584ad4b21bSMauro Carvalho Chehab 25996801b35SMauro Carvalho Chehab/dev/bus/usb/BBB/DDD 26096801b35SMauro Carvalho Chehab-------------------- 2614ad4b21bSMauro Carvalho Chehab 2624ad4b21bSMauro Carvalho ChehabUse these files in one of these basic ways: 2634ad4b21bSMauro Carvalho Chehab 26496801b35SMauro Carvalho Chehab- *They can be read,* producing first the device descriptor (18 bytes) and 2654ad4b21bSMauro Carvalho Chehab then the descriptors for the current configuration. See the USB 2.0 spec 2664ad4b21bSMauro Carvalho Chehab for details about those binary data formats. You'll need to convert most 2674ad4b21bSMauro Carvalho Chehab multibyte values from little endian format to your native host byte 2684ad4b21bSMauro Carvalho Chehab order, although a few of the fields in the device descriptor (both of 2694ad4b21bSMauro Carvalho Chehab the BCD-encoded fields, and the vendor and product IDs) will be 2704ad4b21bSMauro Carvalho Chehab byteswapped for you. Note that configuration descriptors include 2714ad4b21bSMauro Carvalho Chehab descriptors for interfaces, altsettings, endpoints, and maybe additional 2724ad4b21bSMauro Carvalho Chehab class descriptors. 2734ad4b21bSMauro Carvalho Chehab 27496801b35SMauro Carvalho Chehab- *Perform USB operations* using *ioctl()* requests to make endpoint I/O 2754ad4b21bSMauro Carvalho Chehab requests (synchronously or asynchronously) or manage the device. These 27696801b35SMauro Carvalho Chehab requests need the ``CAP_SYS_RAWIO`` capability, as well as filesystem 2774ad4b21bSMauro Carvalho Chehab access permissions. Only one ioctl request can be made on one of these 2784ad4b21bSMauro Carvalho Chehab device files at a time. This means that if you are synchronously reading 2794ad4b21bSMauro Carvalho Chehab an endpoint from one thread, you won't be able to write to a different 2804ad4b21bSMauro Carvalho Chehab endpoint from another thread until the read completes. This works for 2814ad4b21bSMauro Carvalho Chehab *half duplex* protocols, but otherwise you'd use asynchronous i/o 2824ad4b21bSMauro Carvalho Chehab requests. 2834ad4b21bSMauro Carvalho Chehab 28496801b35SMauro Carvalho ChehabEach connected USB device has one file. The ``BBB`` indicates the bus 28596801b35SMauro Carvalho Chehabnumber. The ``DDD`` indicates the device address on that bus. Both 28696801b35SMauro Carvalho Chehabof these numbers are assigned sequentially, and can be reused, so 28796801b35SMauro Carvalho Chehabyou can't rely on them for stable access to devices. For example, 28896801b35SMauro Carvalho Chehabit's relatively common for devices to re-enumerate while they are 28996801b35SMauro Carvalho Chehabstill connected (perhaps someone jostled their power supply, hub, 29096801b35SMauro Carvalho Chehabor USB cable), so a device might be ``002/027`` when you first connect 29196801b35SMauro Carvalho Chehabit and ``002/048`` sometime later. 29296801b35SMauro Carvalho Chehab 29396801b35SMauro Carvalho ChehabThese files can be read as binary data. The binary data consists 29496801b35SMauro Carvalho Chehabof first the device descriptor, then the descriptors for each 29596801b35SMauro Carvalho Chehabconfiguration of the device. Multi-byte fields in the device descriptor 29696801b35SMauro Carvalho Chehabare converted to host endianness by the kernel. The configuration 29796801b35SMauro Carvalho Chehabdescriptors are in bus endian format! The configuration descriptor 29896801b35SMauro Carvalho Chehabare wTotalLength bytes apart. If a device returns less configuration 29996801b35SMauro Carvalho Chehabdescriptor data than indicated by wTotalLength there will be a hole in 30096801b35SMauro Carvalho Chehabthe file for the missing bytes. This information is also shown 30196801b35SMauro Carvalho Chehabin text form by the ``/sys/kernel/debug/usb/devices`` file, described later. 30296801b35SMauro Carvalho Chehab 30396801b35SMauro Carvalho ChehabThese files may also be used to write user-level drivers for the USB 30496801b35SMauro Carvalho Chehabdevices. You would open the ``/dev/bus/usb/BBB/DDD`` file read/write, 30596801b35SMauro Carvalho Chehabread its descriptors to make sure it's the device you expect, and then 30696801b35SMauro Carvalho Chehabbind to an interface (or perhaps several) using an ioctl call. You 30796801b35SMauro Carvalho Chehabwould issue more ioctls to the device to communicate to it using 30896801b35SMauro Carvalho Chehabcontrol, bulk, or other kinds of USB transfers. The IOCTLs are 30996801b35SMauro Carvalho Chehablisted in the ``<linux/usbdevice_fs.h>`` file, and at this writing the 31096801b35SMauro Carvalho Chehabsource code (``linux/drivers/usb/core/devio.c``) is the primary reference 31196801b35SMauro Carvalho Chehabfor how to access devices through those files. 31296801b35SMauro Carvalho Chehab 31396801b35SMauro Carvalho ChehabNote that since by default these ``BBB/DDD`` files are writable only by 31496801b35SMauro Carvalho Chehabroot, only root can write such user mode drivers. You can selectively 31596801b35SMauro Carvalho Chehabgrant read/write permissions to other users by using ``chmod``. Also, 31696801b35SMauro Carvalho Chehabusbfs mount options such as ``devmode=0666`` may be helpful. 31796801b35SMauro Carvalho Chehab 31896801b35SMauro Carvalho Chehab 3194ad4b21bSMauro Carvalho ChehabLife Cycle of User Mode Drivers 3204ad4b21bSMauro Carvalho Chehab------------------------------- 3214ad4b21bSMauro Carvalho Chehab 3224ad4b21bSMauro Carvalho ChehabSuch a driver first needs to find a device file for a device it knows 3234ad4b21bSMauro Carvalho Chehabhow to handle. Maybe it was told about it because a ``/sbin/hotplug`` 3244ad4b21bSMauro Carvalho Chehabevent handling agent chose that driver to handle the new device. Or 32596801b35SMauro Carvalho Chehabmaybe it's an application that scans all the ``/dev/bus/usb`` device files, 3264ad4b21bSMauro Carvalho Chehaband ignores most devices. In either case, it should :c:func:`read()` 3274ad4b21bSMauro Carvalho Chehaball the descriptors from the device file, and check them against what it 3284ad4b21bSMauro Carvalho Chehabknows how to handle. It might just reject everything except a particular 3294ad4b21bSMauro Carvalho Chehabvendor and product ID, or need a more complex policy. 3304ad4b21bSMauro Carvalho Chehab 3314ad4b21bSMauro Carvalho ChehabNever assume there will only be one such device on the system at a time! 3324ad4b21bSMauro Carvalho ChehabIf your code can't handle more than one device at a time, at least 3334ad4b21bSMauro Carvalho Chehabdetect when there's more than one, and have your users choose which 3344ad4b21bSMauro Carvalho Chehabdevice to use. 3354ad4b21bSMauro Carvalho Chehab 3364ad4b21bSMauro Carvalho ChehabOnce your user mode driver knows what device to use, it interacts with 3374ad4b21bSMauro Carvalho Chehabit in either of two styles. The simple style is to make only control 3384ad4b21bSMauro Carvalho Chehabrequests; some devices don't need more complex interactions than those. 3394ad4b21bSMauro Carvalho Chehab(An example might be software using vendor-specific control requests for 3404ad4b21bSMauro Carvalho Chehabsome initialization or configuration tasks, with a kernel driver for the 3414ad4b21bSMauro Carvalho Chehabrest.) 3424ad4b21bSMauro Carvalho Chehab 3434ad4b21bSMauro Carvalho ChehabMore likely, you need a more complex style driver: one using non-control 3444ad4b21bSMauro Carvalho Chehabendpoints, reading or writing data and claiming exclusive use of an 3454ad4b21bSMauro Carvalho Chehabinterface. *Bulk* transfers are easiest to use, but only their sibling 3464ad4b21bSMauro Carvalho Chehab*interrupt* transfers work with low speed devices. Both interrupt and 3474ad4b21bSMauro Carvalho Chehab*isochronous* transfers offer service guarantees because their bandwidth 3484ad4b21bSMauro Carvalho Chehabis reserved. Such "periodic" transfers are awkward to use through usbfs, 3494ad4b21bSMauro Carvalho Chehabunless you're using the asynchronous calls. However, interrupt transfers 3504ad4b21bSMauro Carvalho Chehabcan also be used in a synchronous "one shot" style. 3514ad4b21bSMauro Carvalho Chehab 3524ad4b21bSMauro Carvalho ChehabYour user-mode driver should never need to worry about cleaning up 3534ad4b21bSMauro Carvalho Chehabrequest state when the device is disconnected, although it should close 3544ad4b21bSMauro Carvalho Chehabits open file descriptors as soon as it starts seeing the ENODEV errors. 3554ad4b21bSMauro Carvalho Chehab 3564ad4b21bSMauro Carvalho ChehabThe ioctl() Requests 3574ad4b21bSMauro Carvalho Chehab-------------------- 3584ad4b21bSMauro Carvalho Chehab 3594ad4b21bSMauro Carvalho ChehabTo use these ioctls, you need to include the following headers in your 3609a3c8b35SMauro Carvalho Chehabuserspace program:: 3614ad4b21bSMauro Carvalho Chehab 3624ad4b21bSMauro Carvalho Chehab #include <linux/usb.h> 3634ad4b21bSMauro Carvalho Chehab #include <linux/usbdevice_fs.h> 3644ad4b21bSMauro Carvalho Chehab #include <asm/byteorder.h> 3654ad4b21bSMauro Carvalho Chehab 3664ad4b21bSMauro Carvalho ChehabThe standard USB device model requests, from "Chapter 9" of the USB 2.0 3674ad4b21bSMauro Carvalho Chehabspecification, are automatically included from the ``<linux/usb/ch9.h>`` 3684ad4b21bSMauro Carvalho Chehabheader. 3694ad4b21bSMauro Carvalho Chehab 3704ad4b21bSMauro Carvalho ChehabUnless noted otherwise, the ioctl requests described here will update 3714ad4b21bSMauro Carvalho Chehabthe modification time on the usbfs file to which they are applied 3724ad4b21bSMauro Carvalho Chehab(unless they fail). A return of zero indicates success; otherwise, a 373e1c3e6e1SMauro Carvalho Chehabstandard USB error code is returned (These are documented in 374e1c3e6e1SMauro Carvalho Chehab:ref:`usb-error-codes`). 3754ad4b21bSMauro Carvalho Chehab 3764ad4b21bSMauro Carvalho ChehabEach of these files multiplexes access to several I/O streams, one per 3774ad4b21bSMauro Carvalho Chehabendpoint. Each device has one control endpoint (endpoint zero) which 3784ad4b21bSMauro Carvalho Chehabsupports a limited RPC style RPC access. Devices are configured by 3794ad4b21bSMauro Carvalho Chehabhub_wq (in the kernel) setting a device-wide *configuration* that 3804ad4b21bSMauro Carvalho Chehabaffects things like power consumption and basic functionality. The 3814ad4b21bSMauro Carvalho Chehabendpoints are part of USB *interfaces*, which may have *altsettings* 3824ad4b21bSMauro Carvalho Chehabaffecting things like which endpoints are available. Many devices only 3834ad4b21bSMauro Carvalho Chehabhave a single configuration and interface, so drivers for them will 3844ad4b21bSMauro Carvalho Chehabignore configurations and altsettings. 3854ad4b21bSMauro Carvalho Chehab 3864ad4b21bSMauro Carvalho ChehabManagement/Status Requests 3874ad4b21bSMauro Carvalho Chehab~~~~~~~~~~~~~~~~~~~~~~~~~~ 3884ad4b21bSMauro Carvalho Chehab 3894ad4b21bSMauro Carvalho ChehabA number of usbfs requests don't deal very directly with device I/O. 3904ad4b21bSMauro Carvalho ChehabThey mostly relate to device management and status. These are all 3914ad4b21bSMauro Carvalho Chehabsynchronous requests. 3924ad4b21bSMauro Carvalho Chehab 3934ad4b21bSMauro Carvalho ChehabUSBDEVFS_CLAIMINTERFACE 3944ad4b21bSMauro Carvalho Chehab This is used to force usbfs to claim a specific interface, which has 3954ad4b21bSMauro Carvalho Chehab not previously been claimed by usbfs or any other kernel driver. The 3964ad4b21bSMauro Carvalho Chehab ioctl parameter is an integer holding the number of the interface 3974ad4b21bSMauro Carvalho Chehab (bInterfaceNumber from descriptor). 3984ad4b21bSMauro Carvalho Chehab 3994ad4b21bSMauro Carvalho Chehab Note that if your driver doesn't claim an interface before trying to 4004ad4b21bSMauro Carvalho Chehab use one of its endpoints, and no other driver has bound to it, then 4014ad4b21bSMauro Carvalho Chehab the interface is automatically claimed by usbfs. 4024ad4b21bSMauro Carvalho Chehab 4034ad4b21bSMauro Carvalho Chehab This claim will be released by a RELEASEINTERFACE ioctl, or by 4044ad4b21bSMauro Carvalho Chehab closing the file descriptor. File modification time is not updated 4054ad4b21bSMauro Carvalho Chehab by this request. 4064ad4b21bSMauro Carvalho Chehab 4074ad4b21bSMauro Carvalho ChehabUSBDEVFS_CONNECTINFO 4084ad4b21bSMauro Carvalho Chehab Says whether the device is lowspeed. The ioctl parameter points to a 4099a3c8b35SMauro Carvalho Chehab structure like this:: 4104ad4b21bSMauro Carvalho Chehab 4114ad4b21bSMauro Carvalho Chehab struct usbdevfs_connectinfo { 4124ad4b21bSMauro Carvalho Chehab unsigned int devnum; 4134ad4b21bSMauro Carvalho Chehab unsigned char slow; 4144ad4b21bSMauro Carvalho Chehab }; 4154ad4b21bSMauro Carvalho Chehab 4164ad4b21bSMauro Carvalho Chehab File modification time is not updated by this request. 4174ad4b21bSMauro Carvalho Chehab 4184ad4b21bSMauro Carvalho Chehab *You can't tell whether a "not slow" device is connected at high 4194ad4b21bSMauro Carvalho Chehab speed (480 MBit/sec) or just full speed (12 MBit/sec).* You should 4204ad4b21bSMauro Carvalho Chehab know the devnum value already, it's the DDD value of the device file 4214ad4b21bSMauro Carvalho Chehab name. 4224ad4b21bSMauro Carvalho Chehab 4237713aaf4SOliver NeukumUSBDEVFS_GET_SPEED 4247713aaf4SOliver Neukum Returns the speed of the device. The speed is returned as a 4257713aaf4SOliver Neukum nummerical value in accordance with enum usb_device_speed 4267713aaf4SOliver Neukum 4277713aaf4SOliver Neukum File modification time is not updated by this request. 4287713aaf4SOliver Neukum 4294ad4b21bSMauro Carvalho ChehabUSBDEVFS_GETDRIVER 4304ad4b21bSMauro Carvalho Chehab Returns the name of the kernel driver bound to a given interface (a 4314ad4b21bSMauro Carvalho Chehab string). Parameter is a pointer to this structure, which is 4329a3c8b35SMauro Carvalho Chehab modified:: 4334ad4b21bSMauro Carvalho Chehab 4344ad4b21bSMauro Carvalho Chehab struct usbdevfs_getdriver { 4354ad4b21bSMauro Carvalho Chehab unsigned int interface; 4364ad4b21bSMauro Carvalho Chehab char driver[USBDEVFS_MAXDRIVERNAME + 1]; 4374ad4b21bSMauro Carvalho Chehab }; 4384ad4b21bSMauro Carvalho Chehab 4394ad4b21bSMauro Carvalho Chehab File modification time is not updated by this request. 4404ad4b21bSMauro Carvalho Chehab 4414ad4b21bSMauro Carvalho ChehabUSBDEVFS_IOCTL 4424ad4b21bSMauro Carvalho Chehab Passes a request from userspace through to a kernel driver that has 4439a3c8b35SMauro Carvalho Chehab an ioctl entry in the *struct usb_driver* it registered:: 4444ad4b21bSMauro Carvalho Chehab 4454ad4b21bSMauro Carvalho Chehab struct usbdevfs_ioctl { 4464ad4b21bSMauro Carvalho Chehab int ifno; 4474ad4b21bSMauro Carvalho Chehab int ioctl_code; 4484ad4b21bSMauro Carvalho Chehab void *data; 4494ad4b21bSMauro Carvalho Chehab }; 4504ad4b21bSMauro Carvalho Chehab 4514ad4b21bSMauro Carvalho Chehab /* user mode call looks like this. 4524ad4b21bSMauro Carvalho Chehab * 'request' becomes the driver->ioctl() 'code' parameter. 4534ad4b21bSMauro Carvalho Chehab * the size of 'param' is encoded in 'request', and that data 4544ad4b21bSMauro Carvalho Chehab * is copied to or from the driver->ioctl() 'buf' parameter. 4554ad4b21bSMauro Carvalho Chehab */ 4564ad4b21bSMauro Carvalho Chehab static int 4574ad4b21bSMauro Carvalho Chehab usbdev_ioctl (int fd, int ifno, unsigned request, void *param) 4584ad4b21bSMauro Carvalho Chehab { 4594ad4b21bSMauro Carvalho Chehab struct usbdevfs_ioctl wrapper; 4604ad4b21bSMauro Carvalho Chehab 4614ad4b21bSMauro Carvalho Chehab wrapper.ifno = ifno; 4624ad4b21bSMauro Carvalho Chehab wrapper.ioctl_code = request; 4634ad4b21bSMauro Carvalho Chehab wrapper.data = param; 4644ad4b21bSMauro Carvalho Chehab 4654ad4b21bSMauro Carvalho Chehab return ioctl (fd, USBDEVFS_IOCTL, &wrapper); 4664ad4b21bSMauro Carvalho Chehab } 4674ad4b21bSMauro Carvalho Chehab 4684ad4b21bSMauro Carvalho Chehab File modification time is not updated by this request. 4694ad4b21bSMauro Carvalho Chehab 4704ad4b21bSMauro Carvalho Chehab This request lets kernel drivers talk to user mode code through 4714ad4b21bSMauro Carvalho Chehab filesystem operations even when they don't create a character or 4724ad4b21bSMauro Carvalho Chehab block special device. It's also been used to do things like ask 4734ad4b21bSMauro Carvalho Chehab devices what device special file should be used. Two pre-defined 4744ad4b21bSMauro Carvalho Chehab ioctls are used to disconnect and reconnect kernel drivers, so that 4754ad4b21bSMauro Carvalho Chehab user mode code can completely manage binding and configuration of 4764ad4b21bSMauro Carvalho Chehab devices. 4774ad4b21bSMauro Carvalho Chehab 4784ad4b21bSMauro Carvalho ChehabUSBDEVFS_RELEASEINTERFACE 4794ad4b21bSMauro Carvalho Chehab This is used to release the claim usbfs made on interface, either 4804ad4b21bSMauro Carvalho Chehab implicitly or because of a USBDEVFS_CLAIMINTERFACE call, before the 4814ad4b21bSMauro Carvalho Chehab file descriptor is closed. The ioctl parameter is an integer holding 4824ad4b21bSMauro Carvalho Chehab the number of the interface (bInterfaceNumber from descriptor); File 4834ad4b21bSMauro Carvalho Chehab modification time is not updated by this request. 4844ad4b21bSMauro Carvalho Chehab 4859a3c8b35SMauro Carvalho Chehab .. warning:: 4864ad4b21bSMauro Carvalho Chehab 4874ad4b21bSMauro Carvalho Chehab *No security check is made to ensure that the task which made 4884ad4b21bSMauro Carvalho Chehab the claim is the one which is releasing it. This means that user 4894ad4b21bSMauro Carvalho Chehab mode driver may interfere other ones.* 4904ad4b21bSMauro Carvalho Chehab 4914ad4b21bSMauro Carvalho ChehabUSBDEVFS_RESETEP 4924ad4b21bSMauro Carvalho Chehab Resets the data toggle value for an endpoint (bulk or interrupt) to 4934ad4b21bSMauro Carvalho Chehab DATA0. The ioctl parameter is an integer endpoint number (1 to 15, 4944ad4b21bSMauro Carvalho Chehab as identified in the endpoint descriptor), with USB_DIR_IN added 4954ad4b21bSMauro Carvalho Chehab if the device's endpoint sends data to the host. 4964ad4b21bSMauro Carvalho Chehab 49796801b35SMauro Carvalho Chehab .. Warning:: 4984ad4b21bSMauro Carvalho Chehab 4994ad4b21bSMauro Carvalho Chehab *Avoid using this request. It should probably be removed.* Using 5004ad4b21bSMauro Carvalho Chehab it typically means the device and driver will lose toggle 5014ad4b21bSMauro Carvalho Chehab synchronization. If you really lost synchronization, you likely 5024ad4b21bSMauro Carvalho Chehab need to completely handshake with the device, using a request 5034ad4b21bSMauro Carvalho Chehab like CLEAR_HALT or SET_INTERFACE. 5044ad4b21bSMauro Carvalho Chehab 5054ad4b21bSMauro Carvalho ChehabUSBDEVFS_DROP_PRIVILEGES 5064ad4b21bSMauro Carvalho Chehab This is used to relinquish the ability to do certain operations 5074ad4b21bSMauro Carvalho Chehab which are considered to be privileged on a usbfs file descriptor. 5084ad4b21bSMauro Carvalho Chehab This includes claiming arbitrary interfaces, resetting a device on 5094ad4b21bSMauro Carvalho Chehab which there are currently claimed interfaces from other users, and 5104ad4b21bSMauro Carvalho Chehab issuing USBDEVFS_IOCTL calls. The ioctl parameter is a 32 bit mask 5114ad4b21bSMauro Carvalho Chehab of interfaces the user is allowed to claim on this file descriptor. 5124ad4b21bSMauro Carvalho Chehab You may issue this ioctl more than one time to narrow said mask. 5134ad4b21bSMauro Carvalho Chehab 5144ad4b21bSMauro Carvalho ChehabSynchronous I/O Support 5154ad4b21bSMauro Carvalho Chehab~~~~~~~~~~~~~~~~~~~~~~~ 5164ad4b21bSMauro Carvalho Chehab 5174ad4b21bSMauro Carvalho ChehabSynchronous requests involve the kernel blocking until the user mode 5184ad4b21bSMauro Carvalho Chehabrequest completes, either by finishing successfully or by reporting an 5194ad4b21bSMauro Carvalho Chehaberror. In most cases this is the simplest way to use usbfs, although as 5204ad4b21bSMauro Carvalho Chehabnoted above it does prevent performing I/O to more than one endpoint at 5214ad4b21bSMauro Carvalho Chehaba time. 5224ad4b21bSMauro Carvalho Chehab 5234ad4b21bSMauro Carvalho ChehabUSBDEVFS_BULK 5244ad4b21bSMauro Carvalho Chehab Issues a bulk read or write request to the device. The ioctl 5259a3c8b35SMauro Carvalho Chehab parameter is a pointer to this structure:: 5264ad4b21bSMauro Carvalho Chehab 5274ad4b21bSMauro Carvalho Chehab struct usbdevfs_bulktransfer { 5284ad4b21bSMauro Carvalho Chehab unsigned int ep; 5294ad4b21bSMauro Carvalho Chehab unsigned int len; 5304ad4b21bSMauro Carvalho Chehab unsigned int timeout; /* in milliseconds */ 5314ad4b21bSMauro Carvalho Chehab void *data; 5324ad4b21bSMauro Carvalho Chehab }; 5334ad4b21bSMauro Carvalho Chehab 53496801b35SMauro Carvalho Chehab The ``ep`` value identifies a bulk endpoint number (1 to 15, as 5354ad4b21bSMauro Carvalho Chehab identified in an endpoint descriptor), masked with USB_DIR_IN when 5364ad4b21bSMauro Carvalho Chehab referring to an endpoint which sends data to the host from the 53796801b35SMauro Carvalho Chehab device. The length of the data buffer is identified by ``len``; Recent 5384ad4b21bSMauro Carvalho Chehab kernels support requests up to about 128KBytes. *FIXME say how read 5394ad4b21bSMauro Carvalho Chehab length is returned, and how short reads are handled.*. 5404ad4b21bSMauro Carvalho Chehab 5414ad4b21bSMauro Carvalho ChehabUSBDEVFS_CLEAR_HALT 5424ad4b21bSMauro Carvalho Chehab Clears endpoint halt (stall) and resets the endpoint toggle. This is 5434ad4b21bSMauro Carvalho Chehab only meaningful for bulk or interrupt endpoints. The ioctl parameter 5444ad4b21bSMauro Carvalho Chehab is an integer endpoint number (1 to 15, as identified in an endpoint 5454ad4b21bSMauro Carvalho Chehab descriptor), masked with USB_DIR_IN when referring to an endpoint 5464ad4b21bSMauro Carvalho Chehab which sends data to the host from the device. 5474ad4b21bSMauro Carvalho Chehab 5484ad4b21bSMauro Carvalho Chehab Use this on bulk or interrupt endpoints which have stalled, 54996801b35SMauro Carvalho Chehab returning ``-EPIPE`` status to a data transfer request. Do not issue 5504ad4b21bSMauro Carvalho Chehab the control request directly, since that could invalidate the host's 5514ad4b21bSMauro Carvalho Chehab record of the data toggle. 5524ad4b21bSMauro Carvalho Chehab 5534ad4b21bSMauro Carvalho ChehabUSBDEVFS_CONTROL 5544ad4b21bSMauro Carvalho Chehab Issues a control request to the device. The ioctl parameter points 5559a3c8b35SMauro Carvalho Chehab to a structure like this:: 5564ad4b21bSMauro Carvalho Chehab 5574ad4b21bSMauro Carvalho Chehab struct usbdevfs_ctrltransfer { 5584ad4b21bSMauro Carvalho Chehab __u8 bRequestType; 5594ad4b21bSMauro Carvalho Chehab __u8 bRequest; 5604ad4b21bSMauro Carvalho Chehab __u16 wValue; 5614ad4b21bSMauro Carvalho Chehab __u16 wIndex; 5624ad4b21bSMauro Carvalho Chehab __u16 wLength; 5634ad4b21bSMauro Carvalho Chehab __u32 timeout; /* in milliseconds */ 5644ad4b21bSMauro Carvalho Chehab void *data; 5654ad4b21bSMauro Carvalho Chehab }; 5664ad4b21bSMauro Carvalho Chehab 5674ad4b21bSMauro Carvalho Chehab The first eight bytes of this structure are the contents of the 5684ad4b21bSMauro Carvalho Chehab SETUP packet to be sent to the device; see the USB 2.0 specification 5694ad4b21bSMauro Carvalho Chehab for details. The bRequestType value is composed by combining a 57069966c94SMauro Carvalho Chehab ``USB_TYPE_*`` value, a ``USB_DIR_*`` value, and a ``USB_RECIP_*`` 57169966c94SMauro Carvalho Chehab value (from ``linux/usb.h``). If wLength is nonzero, it describes 5724ad4b21bSMauro Carvalho Chehab the length of the data buffer, which is either written to the device 5734ad4b21bSMauro Carvalho Chehab (USB_DIR_OUT) or read from the device (USB_DIR_IN). 5744ad4b21bSMauro Carvalho Chehab 5754ad4b21bSMauro Carvalho Chehab At this writing, you can't transfer more than 4 KBytes of data to or 5764ad4b21bSMauro Carvalho Chehab from a device; usbfs has a limit, and some host controller drivers 5774ad4b21bSMauro Carvalho Chehab have a limit. (That's not usually a problem.) *Also* there's no way 5784ad4b21bSMauro Carvalho Chehab to say it's not OK to get a short read back from the device. 5794ad4b21bSMauro Carvalho Chehab 5804ad4b21bSMauro Carvalho ChehabUSBDEVFS_RESET 5814ad4b21bSMauro Carvalho Chehab Does a USB level device reset. The ioctl parameter is ignored. After 5824ad4b21bSMauro Carvalho Chehab the reset, this rebinds all device interfaces. File modification 5834ad4b21bSMauro Carvalho Chehab time is not updated by this request. 5844ad4b21bSMauro Carvalho Chehab 5859a3c8b35SMauro Carvalho Chehab.. warning:: 5864ad4b21bSMauro Carvalho Chehab 5874ad4b21bSMauro Carvalho Chehab *Avoid using this call* until some usbcore bugs get fixed, since 5884ad4b21bSMauro Carvalho Chehab it does not fully synchronize device, interface, and driver (not 5894ad4b21bSMauro Carvalho Chehab just usbfs) state. 5904ad4b21bSMauro Carvalho Chehab 5914ad4b21bSMauro Carvalho ChehabUSBDEVFS_SETINTERFACE 5924ad4b21bSMauro Carvalho Chehab Sets the alternate setting for an interface. The ioctl parameter is 5939a3c8b35SMauro Carvalho Chehab a pointer to a structure like this:: 5944ad4b21bSMauro Carvalho Chehab 5954ad4b21bSMauro Carvalho Chehab struct usbdevfs_setinterface { 5964ad4b21bSMauro Carvalho Chehab unsigned int interface; 5974ad4b21bSMauro Carvalho Chehab unsigned int altsetting; 5984ad4b21bSMauro Carvalho Chehab }; 5994ad4b21bSMauro Carvalho Chehab 6004ad4b21bSMauro Carvalho Chehab File modification time is not updated by this request. 6014ad4b21bSMauro Carvalho Chehab 6024ad4b21bSMauro Carvalho Chehab Those struct members are from some interface descriptor applying to 6034ad4b21bSMauro Carvalho Chehab the current configuration. The interface number is the 6044ad4b21bSMauro Carvalho Chehab bInterfaceNumber value, and the altsetting number is the 6054ad4b21bSMauro Carvalho Chehab bAlternateSetting value. (This resets each endpoint in the 6064ad4b21bSMauro Carvalho Chehab interface.) 6074ad4b21bSMauro Carvalho Chehab 6084ad4b21bSMauro Carvalho ChehabUSBDEVFS_SETCONFIGURATION 6094ad4b21bSMauro Carvalho Chehab Issues the :c:func:`usb_set_configuration()` call for the 6104ad4b21bSMauro Carvalho Chehab device. The parameter is an integer holding the number of a 6114ad4b21bSMauro Carvalho Chehab configuration (bConfigurationValue from descriptor). File 6124ad4b21bSMauro Carvalho Chehab modification time is not updated by this request. 6134ad4b21bSMauro Carvalho Chehab 6149a3c8b35SMauro Carvalho Chehab.. warning:: 6154ad4b21bSMauro Carvalho Chehab 6164ad4b21bSMauro Carvalho Chehab *Avoid using this call* until some usbcore bugs get fixed, since 6174ad4b21bSMauro Carvalho Chehab it does not fully synchronize device, interface, and driver (not 6184ad4b21bSMauro Carvalho Chehab just usbfs) state. 6194ad4b21bSMauro Carvalho Chehab 6204ad4b21bSMauro Carvalho ChehabAsynchronous I/O Support 6214ad4b21bSMauro Carvalho Chehab~~~~~~~~~~~~~~~~~~~~~~~~ 6224ad4b21bSMauro Carvalho Chehab 6234ad4b21bSMauro Carvalho ChehabAs mentioned above, there are situations where it may be important to 6244ad4b21bSMauro Carvalho Chehabinitiate concurrent operations from user mode code. This is particularly 6254ad4b21bSMauro Carvalho Chehabimportant for periodic transfers (interrupt and isochronous), but it can 6264ad4b21bSMauro Carvalho Chehabbe used for other kinds of USB requests too. In such cases, the 6274ad4b21bSMauro Carvalho Chehabasynchronous requests described here are essential. Rather than 6284ad4b21bSMauro Carvalho Chehabsubmitting one request and having the kernel block until it completes, 6294ad4b21bSMauro Carvalho Chehabthe blocking is separate. 6304ad4b21bSMauro Carvalho Chehab 6314ad4b21bSMauro Carvalho ChehabThese requests are packaged into a structure that resembles the URB used 6324ad4b21bSMauro Carvalho Chehabby kernel device drivers. (No POSIX Async I/O support here, sorry.) It 63369966c94SMauro Carvalho Chehabidentifies the endpoint type (``USBDEVFS_URB_TYPE_*``), endpoint 6344ad4b21bSMauro Carvalho Chehab(number, masked with USB_DIR_IN as appropriate), buffer and length, 6354ad4b21bSMauro Carvalho Chehaband a user "context" value serving to uniquely identify each request. 6364ad4b21bSMauro Carvalho Chehab(It's usually a pointer to per-request data.) Flags can modify requests 6374ad4b21bSMauro Carvalho Chehab(not as many as supported for kernel drivers). 6384ad4b21bSMauro Carvalho Chehab 6394ad4b21bSMauro Carvalho ChehabEach request can specify a realtime signal number (between SIGRTMIN and 6404ad4b21bSMauro Carvalho ChehabSIGRTMAX, inclusive) to request a signal be sent when the request 6414ad4b21bSMauro Carvalho Chehabcompletes. 6424ad4b21bSMauro Carvalho Chehab 6434ad4b21bSMauro Carvalho ChehabWhen usbfs returns these urbs, the status value is updated, and the 6444ad4b21bSMauro Carvalho Chehabbuffer may have been modified. Except for isochronous transfers, the 6454ad4b21bSMauro Carvalho Chehabactual_length is updated to say how many bytes were transferred; if the 6464ad4b21bSMauro Carvalho ChehabUSBDEVFS_URB_DISABLE_SPD flag is set ("short packets are not OK"), if 6479a3c8b35SMauro Carvalho Chehabfewer bytes were read than were requested then you get an error report:: 6484ad4b21bSMauro Carvalho Chehab 6494ad4b21bSMauro Carvalho Chehab struct usbdevfs_iso_packet_desc { 6504ad4b21bSMauro Carvalho Chehab unsigned int length; 6514ad4b21bSMauro Carvalho Chehab unsigned int actual_length; 6524ad4b21bSMauro Carvalho Chehab unsigned int status; 6534ad4b21bSMauro Carvalho Chehab }; 6544ad4b21bSMauro Carvalho Chehab 6554ad4b21bSMauro Carvalho Chehab struct usbdevfs_urb { 6564ad4b21bSMauro Carvalho Chehab unsigned char type; 6574ad4b21bSMauro Carvalho Chehab unsigned char endpoint; 6584ad4b21bSMauro Carvalho Chehab int status; 6594ad4b21bSMauro Carvalho Chehab unsigned int flags; 6604ad4b21bSMauro Carvalho Chehab void *buffer; 6614ad4b21bSMauro Carvalho Chehab int buffer_length; 6624ad4b21bSMauro Carvalho Chehab int actual_length; 6634ad4b21bSMauro Carvalho Chehab int start_frame; 6644ad4b21bSMauro Carvalho Chehab int number_of_packets; 6654ad4b21bSMauro Carvalho Chehab int error_count; 6664ad4b21bSMauro Carvalho Chehab unsigned int signr; 6674ad4b21bSMauro Carvalho Chehab void *usercontext; 6684ad4b21bSMauro Carvalho Chehab struct usbdevfs_iso_packet_desc iso_frame_desc[]; 6694ad4b21bSMauro Carvalho Chehab }; 6704ad4b21bSMauro Carvalho Chehab 6714ad4b21bSMauro Carvalho ChehabFor these asynchronous requests, the file modification time reflects 6724ad4b21bSMauro Carvalho Chehabwhen the request was initiated. This contrasts with their use with the 6734ad4b21bSMauro Carvalho Chehabsynchronous requests, where it reflects when requests complete. 6744ad4b21bSMauro Carvalho Chehab 6754ad4b21bSMauro Carvalho ChehabUSBDEVFS_DISCARDURB 6764ad4b21bSMauro Carvalho Chehab *TBS* File modification time is not updated by this request. 6774ad4b21bSMauro Carvalho Chehab 6784ad4b21bSMauro Carvalho ChehabUSBDEVFS_DISCSIGNAL 6794ad4b21bSMauro Carvalho Chehab *TBS* File modification time is not updated by this request. 6804ad4b21bSMauro Carvalho Chehab 6814ad4b21bSMauro Carvalho ChehabUSBDEVFS_REAPURB 6824ad4b21bSMauro Carvalho Chehab *TBS* File modification time is not updated by this request. 6834ad4b21bSMauro Carvalho Chehab 6844ad4b21bSMauro Carvalho ChehabUSBDEVFS_REAPURBNDELAY 6854ad4b21bSMauro Carvalho Chehab *TBS* File modification time is not updated by this request. 6864ad4b21bSMauro Carvalho Chehab 6874ad4b21bSMauro Carvalho ChehabUSBDEVFS_SUBMITURB 6884ad4b21bSMauro Carvalho Chehab *TBS* 6898a6a285dSMauro Carvalho Chehab 6908a6a285dSMauro Carvalho ChehabThe USB devices 6918a6a285dSMauro Carvalho Chehab=============== 6928a6a285dSMauro Carvalho Chehab 6938a6a285dSMauro Carvalho ChehabThe USB devices are now exported via debugfs: 6948a6a285dSMauro Carvalho Chehab 6958a6a285dSMauro Carvalho Chehab- ``/sys/kernel/debug/usb/devices`` ... a text file showing each of the USB 6968a6a285dSMauro Carvalho Chehab devices on known to the kernel, and their configuration descriptors. 6978a6a285dSMauro Carvalho Chehab You can also poll() this to learn about new devices. 6988a6a285dSMauro Carvalho Chehab 6998a6a285dSMauro Carvalho Chehab/sys/kernel/debug/usb/devices 7008a6a285dSMauro Carvalho Chehab----------------------------- 7018a6a285dSMauro Carvalho Chehab 7028a6a285dSMauro Carvalho ChehabThis file is handy for status viewing tools in user mode, which can scan 7038a6a285dSMauro Carvalho Chehabthe text format and ignore most of it. More detailed device status 7048a6a285dSMauro Carvalho Chehab(including class and vendor status) is available from device-specific 7054269a691STom Saegerfiles. For information about the current format of this file, see below. 7068a6a285dSMauro Carvalho Chehab 7078a6a285dSMauro Carvalho ChehabThis file, in combination with the poll() system call, can also be used 7088a6a285dSMauro Carvalho Chehabto detect when devices are added or removed:: 7098a6a285dSMauro Carvalho Chehab 7108a6a285dSMauro Carvalho Chehab int fd; 7118a6a285dSMauro Carvalho Chehab struct pollfd pfd; 7128a6a285dSMauro Carvalho Chehab 7138a6a285dSMauro Carvalho Chehab fd = open("/sys/kernel/debug/usb/devices", O_RDONLY); 7148a6a285dSMauro Carvalho Chehab pfd = { fd, POLLIN, 0 }; 7158a6a285dSMauro Carvalho Chehab for (;;) { 7168a6a285dSMauro Carvalho Chehab /* The first time through, this call will return immediately. */ 7178a6a285dSMauro Carvalho Chehab poll(&pfd, 1, -1); 7188a6a285dSMauro Carvalho Chehab 7198a6a285dSMauro Carvalho Chehab /* To see what's changed, compare the file's previous and current 7208a6a285dSMauro Carvalho Chehab contents or scan the filesystem. (Scanning is more precise.) */ 7218a6a285dSMauro Carvalho Chehab } 7228a6a285dSMauro Carvalho Chehab 7238a6a285dSMauro Carvalho ChehabNote that this behavior is intended to be used for informational and 7248a6a285dSMauro Carvalho Chehabdebug purposes. It would be more appropriate to use programs such as 7258a6a285dSMauro Carvalho Chehabudev or HAL to initialize a device or start a user-mode helper program, 7268a6a285dSMauro Carvalho Chehabfor instance. 72796801b35SMauro Carvalho Chehab 72896801b35SMauro Carvalho ChehabIn this file, each device's output has multiple lines of ASCII output. 72996801b35SMauro Carvalho Chehab 73096801b35SMauro Carvalho ChehabI made it ASCII instead of binary on purpose, so that someone 73196801b35SMauro Carvalho Chehabcan obtain some useful data from it without the use of an 73296801b35SMauro Carvalho Chehabauxiliary program. However, with an auxiliary program, the numbers 73396801b35SMauro Carvalho Chehabin the first 4 columns of each ``T:`` line (topology info: 73496801b35SMauro Carvalho ChehabLev, Prnt, Port, Cnt) can be used to build a USB topology diagram. 73596801b35SMauro Carvalho Chehab 73696801b35SMauro Carvalho ChehabEach line is tagged with a one-character ID for that line:: 73796801b35SMauro Carvalho Chehab 73896801b35SMauro Carvalho Chehab T = Topology (etc.) 73996801b35SMauro Carvalho Chehab B = Bandwidth (applies only to USB host controllers, which are 74096801b35SMauro Carvalho Chehab virtualized as root hubs) 74196801b35SMauro Carvalho Chehab D = Device descriptor info. 74296801b35SMauro Carvalho Chehab P = Product ID info. (from Device descriptor, but they won't fit 74396801b35SMauro Carvalho Chehab together on one line) 74496801b35SMauro Carvalho Chehab S = String descriptors. 74596801b35SMauro Carvalho Chehab C = Configuration descriptor info. (* = active configuration) 74696801b35SMauro Carvalho Chehab I = Interface descriptor info. 74796801b35SMauro Carvalho Chehab E = Endpoint descriptor info. 74896801b35SMauro Carvalho Chehab 74996801b35SMauro Carvalho Chehab/sys/kernel/debug/usb/devices output format 75096801b35SMauro Carvalho Chehab~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 75196801b35SMauro Carvalho Chehab 75296801b35SMauro Carvalho ChehabLegend:: 75396801b35SMauro Carvalho Chehab d = decimal number (may have leading spaces or 0's) 75496801b35SMauro Carvalho Chehab x = hexadecimal number (may have leading spaces or 0's) 75596801b35SMauro Carvalho Chehab s = string 75696801b35SMauro Carvalho Chehab 75796801b35SMauro Carvalho Chehab 75896801b35SMauro Carvalho Chehab 75996801b35SMauro Carvalho ChehabTopology info 76096801b35SMauro Carvalho Chehab^^^^^^^^^^^^^ 76196801b35SMauro Carvalho Chehab 76296801b35SMauro Carvalho Chehab:: 76396801b35SMauro Carvalho Chehab 76496801b35SMauro Carvalho Chehab T: Bus=dd Lev=dd Prnt=dd Port=dd Cnt=dd Dev#=ddd Spd=dddd MxCh=dd 76596801b35SMauro Carvalho Chehab | | | | | | | | |__MaxChildren 76696801b35SMauro Carvalho Chehab | | | | | | | |__Device Speed in Mbps 76796801b35SMauro Carvalho Chehab | | | | | | |__DeviceNumber 76896801b35SMauro Carvalho Chehab | | | | | |__Count of devices at this level 76996801b35SMauro Carvalho Chehab | | | | |__Connector/Port on Parent for this device 77096801b35SMauro Carvalho Chehab | | | |__Parent DeviceNumber 77196801b35SMauro Carvalho Chehab | | |__Level in topology for this bus 77296801b35SMauro Carvalho Chehab | |__Bus number 77396801b35SMauro Carvalho Chehab |__Topology info tag 77496801b35SMauro Carvalho Chehab 77596801b35SMauro Carvalho ChehabSpeed may be: 77696801b35SMauro Carvalho Chehab 77796801b35SMauro Carvalho Chehab ======= ====================================================== 77896801b35SMauro Carvalho Chehab 1.5 Mbit/s for low speed USB 77996801b35SMauro Carvalho Chehab 12 Mbit/s for full speed USB 780*f176638aSAlan Stern 480 Mbit/s for high speed USB (added for USB 2.0) 78196801b35SMauro Carvalho Chehab 5000 Mbit/s for SuperSpeed USB (added for USB 3.0) 78296801b35SMauro Carvalho Chehab ======= ====================================================== 78396801b35SMauro Carvalho Chehab 78496801b35SMauro Carvalho ChehabFor reasons lost in the mists of time, the Port number is always 78596801b35SMauro Carvalho Chehabtoo low by 1. For example, a device plugged into port 4 will 78696801b35SMauro Carvalho Chehabshow up with ``Port=03``. 78796801b35SMauro Carvalho Chehab 78896801b35SMauro Carvalho ChehabBandwidth info 78996801b35SMauro Carvalho Chehab^^^^^^^^^^^^^^ 79096801b35SMauro Carvalho Chehab 79196801b35SMauro Carvalho Chehab:: 79296801b35SMauro Carvalho Chehab 79396801b35SMauro Carvalho Chehab B: Alloc=ddd/ddd us (xx%), #Int=ddd, #Iso=ddd 79496801b35SMauro Carvalho Chehab | | | |__Number of isochronous requests 79596801b35SMauro Carvalho Chehab | | |__Number of interrupt requests 79696801b35SMauro Carvalho Chehab | |__Total Bandwidth allocated to this bus 79796801b35SMauro Carvalho Chehab |__Bandwidth info tag 79896801b35SMauro Carvalho Chehab 79996801b35SMauro Carvalho ChehabBandwidth allocation is an approximation of how much of one frame 80096801b35SMauro Carvalho Chehab(millisecond) is in use. It reflects only periodic transfers, which 80196801b35SMauro Carvalho Chehabare the only transfers that reserve bandwidth. Control and bulk 80296801b35SMauro Carvalho Chehabtransfers use all other bandwidth, including reserved bandwidth that 80396801b35SMauro Carvalho Chehabis not used for transfers (such as for short packets). 80496801b35SMauro Carvalho Chehab 80596801b35SMauro Carvalho ChehabThe percentage is how much of the "reserved" bandwidth is scheduled by 80696801b35SMauro Carvalho Chehabthose transfers. For a low or full speed bus (loosely, "USB 1.1"), 80796801b35SMauro Carvalho Chehab90% of the bus bandwidth is reserved. For a high speed bus (loosely, 80896801b35SMauro Carvalho Chehab"USB 2.0") 80% is reserved. 80996801b35SMauro Carvalho Chehab 81096801b35SMauro Carvalho Chehab 81196801b35SMauro Carvalho ChehabDevice descriptor info & Product ID info 81296801b35SMauro Carvalho Chehab^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 81396801b35SMauro Carvalho Chehab 81496801b35SMauro Carvalho Chehab:: 81596801b35SMauro Carvalho Chehab 81696801b35SMauro Carvalho Chehab D: Ver=x.xx Cls=xx(s) Sub=xx Prot=xx MxPS=dd #Cfgs=dd 81796801b35SMauro Carvalho Chehab P: Vendor=xxxx ProdID=xxxx Rev=xx.xx 81896801b35SMauro Carvalho Chehab 81996801b35SMauro Carvalho Chehabwhere:: 82096801b35SMauro Carvalho Chehab 82196801b35SMauro Carvalho Chehab D: Ver=x.xx Cls=xx(sssss) Sub=xx Prot=xx MxPS=dd #Cfgs=dd 82296801b35SMauro Carvalho Chehab | | | | | | |__NumberConfigurations 82396801b35SMauro Carvalho Chehab | | | | | |__MaxPacketSize of Default Endpoint 82496801b35SMauro Carvalho Chehab | | | | |__DeviceProtocol 82596801b35SMauro Carvalho Chehab | | | |__DeviceSubClass 82696801b35SMauro Carvalho Chehab | | |__DeviceClass 82796801b35SMauro Carvalho Chehab | |__Device USB version 82896801b35SMauro Carvalho Chehab |__Device info tag #1 82996801b35SMauro Carvalho Chehab 83096801b35SMauro Carvalho Chehabwhere:: 83196801b35SMauro Carvalho Chehab 83296801b35SMauro Carvalho Chehab P: Vendor=xxxx ProdID=xxxx Rev=xx.xx 83396801b35SMauro Carvalho Chehab | | | |__Product revision number 83496801b35SMauro Carvalho Chehab | | |__Product ID code 83596801b35SMauro Carvalho Chehab | |__Vendor ID code 83696801b35SMauro Carvalho Chehab |__Device info tag #2 83796801b35SMauro Carvalho Chehab 83896801b35SMauro Carvalho Chehab 83996801b35SMauro Carvalho ChehabString descriptor info 84096801b35SMauro Carvalho Chehab^^^^^^^^^^^^^^^^^^^^^^ 84196801b35SMauro Carvalho Chehab:: 84296801b35SMauro Carvalho Chehab 84396801b35SMauro Carvalho Chehab S: Manufacturer=ssss 84496801b35SMauro Carvalho Chehab | |__Manufacturer of this device as read from the device. 84596801b35SMauro Carvalho Chehab | For USB host controller drivers (virtual root hubs) this may 84696801b35SMauro Carvalho Chehab | be omitted, or (for newer drivers) will identify the kernel 84796801b35SMauro Carvalho Chehab | version and the driver which provides this hub emulation. 84896801b35SMauro Carvalho Chehab |__String info tag 84996801b35SMauro Carvalho Chehab 85096801b35SMauro Carvalho Chehab S: Product=ssss 85196801b35SMauro Carvalho Chehab | |__Product description of this device as read from the device. 85296801b35SMauro Carvalho Chehab | For older USB host controller drivers (virtual root hubs) this 85396801b35SMauro Carvalho Chehab | indicates the driver; for newer ones, it's a product (and vendor) 85496801b35SMauro Carvalho Chehab | description that often comes from the kernel's PCI ID database. 85596801b35SMauro Carvalho Chehab |__String info tag 85696801b35SMauro Carvalho Chehab 85796801b35SMauro Carvalho Chehab S: SerialNumber=ssss 85896801b35SMauro Carvalho Chehab | |__Serial Number of this device as read from the device. 85996801b35SMauro Carvalho Chehab | For USB host controller drivers (virtual root hubs) this is 86096801b35SMauro Carvalho Chehab | some unique ID, normally a bus ID (address or slot name) that 86196801b35SMauro Carvalho Chehab | can't be shared with any other device. 86296801b35SMauro Carvalho Chehab |__String info tag 86396801b35SMauro Carvalho Chehab 86496801b35SMauro Carvalho Chehab 86596801b35SMauro Carvalho Chehab 86696801b35SMauro Carvalho ChehabConfiguration descriptor info 86796801b35SMauro Carvalho Chehab^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 86896801b35SMauro Carvalho Chehab:: 86996801b35SMauro Carvalho Chehab 87096801b35SMauro Carvalho Chehab C:* #Ifs=dd Cfg#=dd Atr=xx MPwr=dddmA 87196801b35SMauro Carvalho Chehab | | | | | |__MaxPower in mA 87296801b35SMauro Carvalho Chehab | | | | |__Attributes 87396801b35SMauro Carvalho Chehab | | | |__ConfiguratioNumber 87496801b35SMauro Carvalho Chehab | | |__NumberOfInterfaces 87596801b35SMauro Carvalho Chehab | |__ "*" indicates the active configuration (others are " ") 87696801b35SMauro Carvalho Chehab |__Config info tag 87796801b35SMauro Carvalho Chehab 87896801b35SMauro Carvalho ChehabUSB devices may have multiple configurations, each of which act 87996801b35SMauro Carvalho Chehabrather differently. For example, a bus-powered configuration 88096801b35SMauro Carvalho Chehabmight be much less capable than one that is self-powered. Only 88196801b35SMauro Carvalho Chehabone device configuration can be active at a time; most devices 88296801b35SMauro Carvalho Chehabhave only one configuration. 88396801b35SMauro Carvalho Chehab 88496801b35SMauro Carvalho ChehabEach configuration consists of one or more interfaces. Each 88596801b35SMauro Carvalho Chehabinterface serves a distinct "function", which is typically bound 88696801b35SMauro Carvalho Chehabto a different USB device driver. One common example is a USB 88796801b35SMauro Carvalho Chehabspeaker with an audio interface for playback, and a HID interface 88896801b35SMauro Carvalho Chehabfor use with software volume control. 88996801b35SMauro Carvalho Chehab 89096801b35SMauro Carvalho ChehabInterface descriptor info (can be multiple per Config) 89196801b35SMauro Carvalho Chehab^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 89296801b35SMauro Carvalho Chehab:: 89396801b35SMauro Carvalho Chehab 89496801b35SMauro Carvalho Chehab I:* If#=dd Alt=dd #EPs=dd Cls=xx(sssss) Sub=xx Prot=xx Driver=ssss 89596801b35SMauro Carvalho Chehab | | | | | | | | |__Driver name 89696801b35SMauro Carvalho Chehab | | | | | | | | or "(none)" 89796801b35SMauro Carvalho Chehab | | | | | | | |__InterfaceProtocol 89896801b35SMauro Carvalho Chehab | | | | | | |__InterfaceSubClass 89996801b35SMauro Carvalho Chehab | | | | | |__InterfaceClass 90096801b35SMauro Carvalho Chehab | | | | |__NumberOfEndpoints 90196801b35SMauro Carvalho Chehab | | | |__AlternateSettingNumber 90296801b35SMauro Carvalho Chehab | | |__InterfaceNumber 90396801b35SMauro Carvalho Chehab | |__ "*" indicates the active altsetting (others are " ") 90496801b35SMauro Carvalho Chehab |__Interface info tag 90596801b35SMauro Carvalho Chehab 90696801b35SMauro Carvalho ChehabA given interface may have one or more "alternate" settings. 90796801b35SMauro Carvalho ChehabFor example, default settings may not use more than a small 90896801b35SMauro Carvalho Chehabamount of periodic bandwidth. To use significant fractions 90996801b35SMauro Carvalho Chehabof bus bandwidth, drivers must select a non-default altsetting. 91096801b35SMauro Carvalho Chehab 91196801b35SMauro Carvalho ChehabOnly one setting for an interface may be active at a time, and 91296801b35SMauro Carvalho Chehabonly one driver may bind to an interface at a time. Most devices 91396801b35SMauro Carvalho Chehabhave only one alternate setting per interface. 91496801b35SMauro Carvalho Chehab 91596801b35SMauro Carvalho Chehab 91696801b35SMauro Carvalho ChehabEndpoint descriptor info (can be multiple per Interface) 91796801b35SMauro Carvalho Chehab^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 91896801b35SMauro Carvalho Chehab 91996801b35SMauro Carvalho Chehab:: 92096801b35SMauro Carvalho Chehab 92196801b35SMauro Carvalho Chehab E: Ad=xx(s) Atr=xx(ssss) MxPS=dddd Ivl=dddss 92296801b35SMauro Carvalho Chehab | | | | |__Interval (max) between transfers 92396801b35SMauro Carvalho Chehab | | | |__EndpointMaxPacketSize 92496801b35SMauro Carvalho Chehab | | |__Attributes(EndpointType) 92596801b35SMauro Carvalho Chehab | |__EndpointAddress(I=In,O=Out) 92696801b35SMauro Carvalho Chehab |__Endpoint info tag 92796801b35SMauro Carvalho Chehab 92896801b35SMauro Carvalho ChehabThe interval is nonzero for all periodic (interrupt or isochronous) 92996801b35SMauro Carvalho Chehabendpoints. For high speed endpoints the transfer interval may be 93096801b35SMauro Carvalho Chehabmeasured in microseconds rather than milliseconds. 93196801b35SMauro Carvalho Chehab 93296801b35SMauro Carvalho ChehabFor high speed periodic endpoints, the ``EndpointMaxPacketSize`` reflects 93396801b35SMauro Carvalho Chehabthe per-microframe data transfer size. For "high bandwidth" 93496801b35SMauro Carvalho Chehabendpoints, that can reflect two or three packets (for up to 93596801b35SMauro Carvalho Chehab3KBytes every 125 usec) per endpoint. 93696801b35SMauro Carvalho Chehab 93796801b35SMauro Carvalho ChehabWith the Linux-USB stack, periodic bandwidth reservations use the 93896801b35SMauro Carvalho Chehabtransfer intervals and sizes provided by URBs, which can be less 93996801b35SMauro Carvalho Chehabthan those found in endpoint descriptor. 94096801b35SMauro Carvalho Chehab 94196801b35SMauro Carvalho ChehabUsage examples 94296801b35SMauro Carvalho Chehab~~~~~~~~~~~~~~ 94396801b35SMauro Carvalho Chehab 94496801b35SMauro Carvalho ChehabIf a user or script is interested only in Topology info, for 94596801b35SMauro Carvalho Chehabexample, use something like ``grep ^T: /sys/kernel/debug/usb/devices`` 94696801b35SMauro Carvalho Chehabfor only the Topology lines. A command like 94796801b35SMauro Carvalho Chehab``grep -i ^[tdp]: /sys/kernel/debug/usb/devices`` can be used to list 94896801b35SMauro Carvalho Chehabonly the lines that begin with the characters in square brackets, 94996801b35SMauro Carvalho Chehabwhere the valid characters are TDPCIE. With a slightly more able 95096801b35SMauro Carvalho Chehabscript, it can display any selected lines (for example, only T, D, 95196801b35SMauro Carvalho Chehaband P lines) and change their output format. (The ``procusb`` 95296801b35SMauro Carvalho ChehabPerl script is the beginning of this idea. It will list only 95396801b35SMauro Carvalho Chehabselected lines [selected from TBDPSCIE] or "All" lines from 95496801b35SMauro Carvalho Chehab``/sys/kernel/debug/usb/devices``.) 95596801b35SMauro Carvalho Chehab 95696801b35SMauro Carvalho ChehabThe Topology lines can be used to generate a graphic/pictorial 95796801b35SMauro Carvalho Chehabof the USB devices on a system's root hub. (See more below 95896801b35SMauro Carvalho Chehabon how to do this.) 95996801b35SMauro Carvalho Chehab 96096801b35SMauro Carvalho ChehabThe Interface lines can be used to determine what driver is 96196801b35SMauro Carvalho Chehabbeing used for each device, and which altsetting it activated. 96296801b35SMauro Carvalho Chehab 96396801b35SMauro Carvalho ChehabThe Configuration lines could be used to list maximum power 96496801b35SMauro Carvalho Chehab(in milliamps) that a system's USB devices are using. 96596801b35SMauro Carvalho ChehabFor example, ``grep ^C: /sys/kernel/debug/usb/devices``. 96696801b35SMauro Carvalho Chehab 96796801b35SMauro Carvalho Chehab 96896801b35SMauro Carvalho ChehabHere's an example, from a system which has a UHCI root hub, 96996801b35SMauro Carvalho Chehaban external hub connected to the root hub, and a mouse and 97096801b35SMauro Carvalho Chehaba serial converter connected to the external hub. 97196801b35SMauro Carvalho Chehab 97296801b35SMauro Carvalho Chehab:: 97396801b35SMauro Carvalho Chehab 97496801b35SMauro Carvalho Chehab T: Bus=00 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2 97596801b35SMauro Carvalho Chehab B: Alloc= 28/900 us ( 3%), #Int= 2, #Iso= 0 97696801b35SMauro Carvalho Chehab D: Ver= 1.00 Cls=09(hub ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 97796801b35SMauro Carvalho Chehab P: Vendor=0000 ProdID=0000 Rev= 0.00 97896801b35SMauro Carvalho Chehab S: Product=USB UHCI Root Hub 97996801b35SMauro Carvalho Chehab S: SerialNumber=dce0 98096801b35SMauro Carvalho Chehab C:* #Ifs= 1 Cfg#= 1 Atr=40 MxPwr= 0mA 98196801b35SMauro Carvalho Chehab I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub 98296801b35SMauro Carvalho Chehab E: Ad=81(I) Atr=03(Int.) MxPS= 8 Ivl=255ms 98396801b35SMauro Carvalho Chehab 98496801b35SMauro Carvalho Chehab T: Bus=00 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=12 MxCh= 4 98596801b35SMauro Carvalho Chehab D: Ver= 1.00 Cls=09(hub ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 98696801b35SMauro Carvalho Chehab P: Vendor=0451 ProdID=1446 Rev= 1.00 98796801b35SMauro Carvalho Chehab C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=100mA 98896801b35SMauro Carvalho Chehab I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub 98996801b35SMauro Carvalho Chehab E: Ad=81(I) Atr=03(Int.) MxPS= 1 Ivl=255ms 99096801b35SMauro Carvalho Chehab 99196801b35SMauro Carvalho Chehab T: Bus=00 Lev=02 Prnt=02 Port=00 Cnt=01 Dev#= 3 Spd=1.5 MxCh= 0 99296801b35SMauro Carvalho Chehab D: Ver= 1.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 99396801b35SMauro Carvalho Chehab P: Vendor=04b4 ProdID=0001 Rev= 0.00 99496801b35SMauro Carvalho Chehab C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=100mA 99596801b35SMauro Carvalho Chehab I: If#= 0 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=01 Prot=02 Driver=mouse 99696801b35SMauro Carvalho Chehab E: Ad=81(I) Atr=03(Int.) MxPS= 3 Ivl= 10ms 99796801b35SMauro Carvalho Chehab 99896801b35SMauro Carvalho Chehab T: Bus=00 Lev=02 Prnt=02 Port=02 Cnt=02 Dev#= 4 Spd=12 MxCh= 0 99996801b35SMauro Carvalho Chehab D: Ver= 1.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 100096801b35SMauro Carvalho Chehab P: Vendor=0565 ProdID=0001 Rev= 1.08 100196801b35SMauro Carvalho Chehab S: Manufacturer=Peracom Networks, Inc. 100296801b35SMauro Carvalho Chehab S: Product=Peracom USB to Serial Converter 100396801b35SMauro Carvalho Chehab C:* #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr=100mA 100496801b35SMauro Carvalho Chehab I: If#= 0 Alt= 0 #EPs= 3 Cls=00(>ifc ) Sub=00 Prot=00 Driver=serial 100596801b35SMauro Carvalho Chehab E: Ad=81(I) Atr=02(Bulk) MxPS= 64 Ivl= 16ms 100696801b35SMauro Carvalho Chehab E: Ad=01(O) Atr=02(Bulk) MxPS= 16 Ivl= 16ms 100796801b35SMauro Carvalho Chehab E: Ad=82(I) Atr=03(Int.) MxPS= 8 Ivl= 8ms 100896801b35SMauro Carvalho Chehab 100996801b35SMauro Carvalho Chehab 101096801b35SMauro Carvalho ChehabSelecting only the ``T:`` and ``I:`` lines from this (for example, by using 101196801b35SMauro Carvalho Chehab``procusb ti``), we have 101296801b35SMauro Carvalho Chehab 101396801b35SMauro Carvalho Chehab:: 101496801b35SMauro Carvalho Chehab 101596801b35SMauro Carvalho Chehab T: Bus=00 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2 101696801b35SMauro Carvalho Chehab T: Bus=00 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=12 MxCh= 4 101796801b35SMauro Carvalho Chehab I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub 101896801b35SMauro Carvalho Chehab T: Bus=00 Lev=02 Prnt=02 Port=00 Cnt=01 Dev#= 3 Spd=1.5 MxCh= 0 101996801b35SMauro Carvalho Chehab I: If#= 0 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=01 Prot=02 Driver=mouse 102096801b35SMauro Carvalho Chehab T: Bus=00 Lev=02 Prnt=02 Port=02 Cnt=02 Dev#= 4 Spd=12 MxCh= 0 102196801b35SMauro Carvalho Chehab I: If#= 0 Alt= 0 #EPs= 3 Cls=00(>ifc ) Sub=00 Prot=00 Driver=serial 102296801b35SMauro Carvalho Chehab 102396801b35SMauro Carvalho Chehab 102496801b35SMauro Carvalho ChehabPhysically this looks like (or could be converted to):: 102596801b35SMauro Carvalho Chehab 102696801b35SMauro Carvalho Chehab +------------------+ 102796801b35SMauro Carvalho Chehab | PC/root_hub (12)| Dev# = 1 102896801b35SMauro Carvalho Chehab +------------------+ (nn) is Mbps. 102996801b35SMauro Carvalho Chehab Level 0 | CN.0 | CN.1 | [CN = connector/port #] 103096801b35SMauro Carvalho Chehab +------------------+ 103196801b35SMauro Carvalho Chehab / 103296801b35SMauro Carvalho Chehab / 103396801b35SMauro Carvalho Chehab +-----------------------+ 103496801b35SMauro Carvalho Chehab Level 1 | Dev#2: 4-port hub (12)| 103596801b35SMauro Carvalho Chehab +-----------------------+ 103696801b35SMauro Carvalho Chehab |CN.0 |CN.1 |CN.2 |CN.3 | 103796801b35SMauro Carvalho Chehab +-----------------------+ 103896801b35SMauro Carvalho Chehab \ \____________________ 103996801b35SMauro Carvalho Chehab \_____ \ 104096801b35SMauro Carvalho Chehab \ \ 104196801b35SMauro Carvalho Chehab +--------------------+ +--------------------+ 104296801b35SMauro Carvalho Chehab Level 2 | Dev# 3: mouse (1.5)| | Dev# 4: serial (12)| 104396801b35SMauro Carvalho Chehab +--------------------+ +--------------------+ 104496801b35SMauro Carvalho Chehab 104596801b35SMauro Carvalho Chehab 104696801b35SMauro Carvalho Chehab 104796801b35SMauro Carvalho ChehabOr, in a more tree-like structure (ports [Connectors] without 104896801b35SMauro Carvalho Chehabconnections could be omitted):: 104996801b35SMauro Carvalho Chehab 105096801b35SMauro Carvalho Chehab PC: Dev# 1, root hub, 2 ports, 12 Mbps 105196801b35SMauro Carvalho Chehab |_ CN.0: Dev# 2, hub, 4 ports, 12 Mbps 105296801b35SMauro Carvalho Chehab |_ CN.0: Dev #3, mouse, 1.5 Mbps 105396801b35SMauro Carvalho Chehab |_ CN.1: 105496801b35SMauro Carvalho Chehab |_ CN.2: Dev #4, serial, 12 Mbps 105596801b35SMauro Carvalho Chehab |_ CN.3: 105696801b35SMauro Carvalho Chehab |_ CN.1: 1057