~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/driver-api/usb/usb.rst

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /Documentation/driver-api/usb/usb.rst (Version linux-6.12-rc7) and /Documentation/driver-api/usb/usb.rst (Version linux-6.4.16)


  1 .. _usb-hostside-api:                               1 .. _usb-hostside-api:
  2                                                     2 
  3 ===========================                         3 ===========================
  4 The Linux-USB Host Side API                         4 The Linux-USB Host Side API
  5 ===========================                         5 ===========================
  6                                                     6 
  7 Introduction to USB on Linux                        7 Introduction to USB on Linux
  8 ============================                        8 ============================
  9                                                     9 
 10 A Universal Serial Bus (USB) is used to connec     10 A Universal Serial Bus (USB) is used to connect a host, such as a PC or
 11 workstation, to a number of peripheral devices     11 workstation, to a number of peripheral devices. USB uses a tree
 12 structure, with the host as the root (the syst     12 structure, with the host as the root (the system's master), hubs as
 13 interior nodes, and peripherals as leaves (and     13 interior nodes, and peripherals as leaves (and slaves). Modern PCs
 14 support several such trees of USB devices, usu     14 support several such trees of USB devices, usually
 15 a few USB 3.0 (5 GBit/s) or USB 3.1 (10 GBit/s     15 a few USB 3.0 (5 GBit/s) or USB 3.1 (10 GBit/s) and some legacy
 16 USB 2.0 (480 MBit/s) busses just in case.          16 USB 2.0 (480 MBit/s) busses just in case.
 17                                                    17 
 18 That master/slave asymmetry was designed-in fo     18 That master/slave asymmetry was designed-in for a number of reasons, one
 19 being ease of use. It is not physically possib     19 being ease of use. It is not physically possible to mistake upstream and
 20 downstream or it does not matter with a type C     20 downstream or it does not matter with a type C plug (or they are built into the
 21 peripheral). Also, the host software doesn't n     21 peripheral). Also, the host software doesn't need to deal with
 22 distributed auto-configuration since the pre-d     22 distributed auto-configuration since the pre-designated master node
 23 manages all that.                                  23 manages all that.
 24                                                    24 
 25 Kernel developers added USB support to Linux e     25 Kernel developers added USB support to Linux early in the 2.2 kernel
 26 series and have been developing it further sin     26 series and have been developing it further since then. Besides support
 27 for each new generation of USB, various host c     27 for each new generation of USB, various host controllers gained support,
 28 new drivers for peripherals have been added an     28 new drivers for peripherals have been added and advanced features for latency
 29 measurement and improved power management intr     29 measurement and improved power management introduced.
 30                                                    30 
 31 Linux can run inside USB devices as well as on     31 Linux can run inside USB devices as well as on the hosts that control
 32 the devices. But USB device drivers running in     32 the devices. But USB device drivers running inside those peripherals
 33 don't do the same things as the ones running i     33 don't do the same things as the ones running inside hosts, so they've
 34 been given a different name: *gadget drivers*.     34 been given a different name: *gadget drivers*. This document does not
 35 cover gadget drivers.                              35 cover gadget drivers.
 36                                                    36 
 37 USB Host-Side API Model                            37 USB Host-Side API Model
 38 =======================                            38 =======================
 39                                                    39 
 40 Host-side drivers for USB devices talk to the      40 Host-side drivers for USB devices talk to the "usbcore" APIs. There are
 41 two. One is intended for *general-purpose* dri     41 two. One is intended for *general-purpose* drivers (exposed through
 42 driver frameworks), and the other is for drive     42 driver frameworks), and the other is for drivers that are *part of the
 43 core*. Such core drivers include the *hub* dri     43 core*. Such core drivers include the *hub* driver (which manages trees
 44 of USB devices) and several different kinds of     44 of USB devices) and several different kinds of *host controller
 45 drivers*, which control individual busses.         45 drivers*, which control individual busses.
 46                                                    46 
 47 The device model seen by USB drivers is relati     47 The device model seen by USB drivers is relatively complex.
 48                                                    48 
 49 -  USB supports four kinds of data transfers (     49 -  USB supports four kinds of data transfers (control, bulk, interrupt,
 50    and isochronous). Two of them (control and      50    and isochronous). Two of them (control and bulk) use bandwidth as
 51    it's available, while the other two (interr     51    it's available, while the other two (interrupt and isochronous) are
 52    scheduled to provide guaranteed bandwidth.      52    scheduled to provide guaranteed bandwidth.
 53                                                    53 
 54 -  The device description model includes one o     54 -  The device description model includes one or more "configurations"
 55    per device, only one of which is active at      55    per device, only one of which is active at a time. Devices are supposed
 56    to be capable of operating at lower than th     56    to be capable of operating at lower than their top
 57    speeds and may provide a BOS descriptor sho     57    speeds and may provide a BOS descriptor showing the lowest speed they
 58    remain fully operational at.                    58    remain fully operational at.
 59                                                    59 
 60 -  From USB 3.0 on configurations have one or      60 -  From USB 3.0 on configurations have one or more "functions", which
 61    provide a common functionality and are grou     61    provide a common functionality and are grouped together for purposes
 62    of power management.                            62    of power management.
 63                                                    63 
 64 -  Configurations or functions have one or mor     64 -  Configurations or functions have one or more "interfaces", each of which may have
 65    "alternate settings". Interfaces may be sta     65    "alternate settings". Interfaces may be standardized by USB "Class"
 66    specifications, or may be specific to a ven     66    specifications, or may be specific to a vendor or device.
 67                                                    67 
 68    USB device drivers actually bind to interfa     68    USB device drivers actually bind to interfaces, not devices. Think of
 69    them as "interface drivers", though you may     69    them as "interface drivers", though you may not see many devices
 70    where the distinction is important. *Most U     70    where the distinction is important. *Most USB devices are simple,
 71    with only one function, one configuration,      71    with only one function, one configuration, one interface, and one alternate
 72    setting.*                                       72    setting.*
 73                                                    73 
 74 -  Interfaces have one or more "endpoints", ea     74 -  Interfaces have one or more "endpoints", each of which supports one
 75    type and direction of data transfer such as     75    type and direction of data transfer such as "bulk out" or "interrupt
 76    in". The entire configuration may have up t     76    in". The entire configuration may have up to sixteen endpoints in
 77    each direction, allocated as needed among a     77    each direction, allocated as needed among all the interfaces.
 78                                                    78 
 79 -  Data transfer on USB is packetized; each en     79 -  Data transfer on USB is packetized; each endpoint has a maximum
 80    packet size. Drivers must often be aware of     80    packet size. Drivers must often be aware of conventions such as
 81    flagging the end of bulk transfers using "s     81    flagging the end of bulk transfers using "short" (including zero
 82    length) packets.                                82    length) packets.
 83                                                    83 
 84 -  The Linux USB API supports synchronous call     84 -  The Linux USB API supports synchronous calls for control and bulk
 85    messages. It also supports asynchronous cal     85    messages. It also supports asynchronous calls for all kinds of data
 86    transfer, using request structures called "     86    transfer, using request structures called "URBs" (USB Request
 87    Blocks).                                        87    Blocks).
 88                                                    88 
 89 Accordingly, the USB Core API exposed to devic     89 Accordingly, the USB Core API exposed to device drivers covers quite a
 90 lot of territory. You'll probably need to cons     90 lot of territory. You'll probably need to consult the USB 3.0
 91 specification, available online from www.usb.o     91 specification, available online from www.usb.org at no cost, as well as
 92 class or device specifications.                    92 class or device specifications.
 93                                                    93 
 94 The only host-side drivers that actually touch     94 The only host-side drivers that actually touch hardware (reading/writing
 95 registers, handling IRQs, and so on) are the H     95 registers, handling IRQs, and so on) are the HCDs. In theory, all HCDs
 96 provide the same functionality through the sam     96 provide the same functionality through the same API. In practice, that's
 97 becoming more true, but there are still differ     97 becoming more true, but there are still differences
 98 that crop up especially with fault handling on     98 that crop up especially with fault handling on the less common controllers.
 99 Different controllers don't                        99 Different controllers don't
100 necessarily report the same aspects of failure    100 necessarily report the same aspects of failures, and recovery from
101 faults (including software-induced ones like u    101 faults (including software-induced ones like unlinking an URB) isn't yet
102 fully consistent. Device driver authors should    102 fully consistent. Device driver authors should make a point of doing
103 disconnect testing (while the device is active    103 disconnect testing (while the device is active) with each different host
104 controller driver, to make sure drivers don't     104 controller driver, to make sure drivers don't have bugs of their own as
105 well as to make sure they aren't relying on so    105 well as to make sure they aren't relying on some HCD-specific behavior.
106                                                   106 
107 .. _usb_chapter9:                                 107 .. _usb_chapter9:
108                                                   108 
109 USB-Standard Types                                109 USB-Standard Types
110 ==================                                110 ==================
111                                                   111 
112 In ``include/uapi/linux/usb/ch9.h`` you will f    112 In ``include/uapi/linux/usb/ch9.h`` you will find the USB data types defined
113 in chapter 9 of the USB specification. These d    113 in chapter 9 of the USB specification. These data types are used throughout
114 USB, and in APIs including this host side API,    114 USB, and in APIs including this host side API, gadget APIs, usb character
115 devices and debugfs interfaces. That file is i    115 devices and debugfs interfaces. That file is itself included by
116 ``include/linux/usb/ch9.h``, which also contai    116 ``include/linux/usb/ch9.h``, which also contains declarations of a few
117 utility routines for manipulating these data t    117 utility routines for manipulating these data types; the implementations
118 are in ``drivers/usb/common/common.c``.           118 are in ``drivers/usb/common/common.c``.
119                                                   119 
120 .. kernel-doc:: drivers/usb/common/common.c       120 .. kernel-doc:: drivers/usb/common/common.c
121    :export:                                       121    :export:
122                                                   122 
123 In addition, some functions useful for creatin    123 In addition, some functions useful for creating debugging output are
124 defined in ``drivers/usb/common/debug.c``.        124 defined in ``drivers/usb/common/debug.c``.
125                                                   125 
126 .. _usb_header:                                   126 .. _usb_header:
127                                                   127 
128 Host-Side Data Types and Macros                   128 Host-Side Data Types and Macros
129 ===============================                   129 ===============================
130                                                   130 
131 The host side API exposes several layers to dr    131 The host side API exposes several layers to drivers, some of which are
132 more necessary than others. These support life    132 more necessary than others. These support lifecycle models for host side
133 drivers and devices, and support passing buffe    133 drivers and devices, and support passing buffers through usbcore to some
134 HCD that performs the I/O for the device drive    134 HCD that performs the I/O for the device driver.
135                                                   135 
136 .. kernel-doc:: include/linux/usb.h               136 .. kernel-doc:: include/linux/usb.h
137    :internal:                                     137    :internal:
138                                                   138 
139 USB Core APIs                                     139 USB Core APIs
140 =============                                     140 =============
141                                                   141 
142 There are two basic I/O models in the USB API.    142 There are two basic I/O models in the USB API. The most elemental one is
143 asynchronous: drivers submit requests in the f    143 asynchronous: drivers submit requests in the form of an URB, and the
144 URB's completion callback handles the next ste    144 URB's completion callback handles the next step. All USB transfer types
145 support that model, although there are special    145 support that model, although there are special cases for control URBs
146 (which always have setup and status stages, bu    146 (which always have setup and status stages, but may not have a data
147 stage) and isochronous URBs (which allow large    147 stage) and isochronous URBs (which allow large packets and include
148 per-packet fault reports). Built on top of tha    148 per-packet fault reports). Built on top of that is synchronous API
149 support, where a driver calls a routine that a    149 support, where a driver calls a routine that allocates one or more URBs,
150 submits them, and waits until they complete. T    150 submits them, and waits until they complete. There are synchronous
151 wrappers for single-buffer control and bulk tr    151 wrappers for single-buffer control and bulk transfers (which are awkward
152 to use in some driver disconnect scenarios), a    152 to use in some driver disconnect scenarios), and for scatterlist based
153 streaming i/o (bulk or interrupt).                153 streaming i/o (bulk or interrupt).
154                                                   154 
155 USB drivers need to provide buffers that can b    155 USB drivers need to provide buffers that can be used for DMA, although
156 they don't necessarily need to provide the DMA    156 they don't necessarily need to provide the DMA mapping themselves. There
157 are APIs to use used when allocating DMA buffe    157 are APIs to use used when allocating DMA buffers, which can prevent use
158 of bounce buffers on some systems. In some cas    158 of bounce buffers on some systems. In some cases, drivers may be able to
159 rely on 64bit DMA to eliminate another kind of    159 rely on 64bit DMA to eliminate another kind of bounce buffer.
160                                                   160 
161 .. kernel-doc:: drivers/usb/core/urb.c            161 .. kernel-doc:: drivers/usb/core/urb.c
162    :export:                                       162    :export:
163                                                   163 
164 .. kernel-doc:: drivers/usb/core/message.c        164 .. kernel-doc:: drivers/usb/core/message.c
165    :export:                                       165    :export:
166                                                   166 
167 .. kernel-doc:: drivers/usb/core/file.c           167 .. kernel-doc:: drivers/usb/core/file.c
168    :export:                                       168    :export:
169                                                   169 
170 .. kernel-doc:: drivers/usb/core/driver.c         170 .. kernel-doc:: drivers/usb/core/driver.c
171    :export:                                       171    :export:
172                                                   172 
173 .. kernel-doc:: drivers/usb/core/usb.c            173 .. kernel-doc:: drivers/usb/core/usb.c
174    :export:                                       174    :export:
175                                                   175 
176 .. kernel-doc:: drivers/usb/core/hub.c            176 .. kernel-doc:: drivers/usb/core/hub.c
177    :export:                                       177    :export:
178                                                   178 
179 Host Controller APIs                              179 Host Controller APIs
180 ====================                              180 ====================
181                                                   181 
182 These APIs are only for use by host controller    182 These APIs are only for use by host controller drivers, most of which
183 implement standard register interfaces such as    183 implement standard register interfaces such as XHCI, EHCI, OHCI, or UHCI. UHCI
184 was one of the first interfaces, designed by I    184 was one of the first interfaces, designed by Intel and also used by VIA;
185 it doesn't do much in hardware. OHCI was desig    185 it doesn't do much in hardware. OHCI was designed later, to have the
186 hardware do more work (bigger transfers, track    186 hardware do more work (bigger transfers, tracking protocol state, and so
187 on). EHCI was designed with USB 2.0; its desig    187 on). EHCI was designed with USB 2.0; its design has features that
188 resemble OHCI (hardware does much more work) a    188 resemble OHCI (hardware does much more work) as well as UHCI (some parts
189 of ISO support, TD list processing). XHCI was     189 of ISO support, TD list processing). XHCI was designed with USB 3.0. It
190 continues to shift support for functionality i    190 continues to shift support for functionality into hardware.
191                                                   191 
192 There are host controllers other than the "big    192 There are host controllers other than the "big three", although most PCI
193 based controllers (and a few non-PCI based one    193 based controllers (and a few non-PCI based ones) use one of those
194 interfaces. Not all host controllers use DMA;     194 interfaces. Not all host controllers use DMA; some use PIO, and there is
195 also a simulator and a virtual host controller    195 also a simulator and a virtual host controller to pipe USB over the network.
196                                                   196 
197 The same basic APIs are available to drivers f    197 The same basic APIs are available to drivers for all those controllers.
198 For historical reasons they are in two layers:    198 For historical reasons they are in two layers: :c:type:`struct
199 usb_bus <usb_bus>` is a rather thin layer that    199 usb_bus <usb_bus>` is a rather thin layer that became available
200 in the 2.2 kernels, while :c:type:`struct usb_    200 in the 2.2 kernels, while :c:type:`struct usb_hcd <usb_hcd>`
201 is a more featureful layer                        201 is a more featureful layer
202 that lets HCDs share common code, to shrink dr    202 that lets HCDs share common code, to shrink driver size and
203 significantly reduce hcd-specific behaviors.      203 significantly reduce hcd-specific behaviors.
204                                                   204 
205 .. kernel-doc:: drivers/usb/core/hcd.c            205 .. kernel-doc:: drivers/usb/core/hcd.c
206    :export:                                       206    :export:
207                                                   207 
208 .. kernel-doc:: drivers/usb/core/hcd-pci.c        208 .. kernel-doc:: drivers/usb/core/hcd-pci.c
209    :export:                                       209    :export:
210                                                   210 
211 .. kernel-doc:: drivers/usb/core/buffer.c         211 .. kernel-doc:: drivers/usb/core/buffer.c
212    :internal:                                     212    :internal:
213                                                   213 
214 The USB character device nodes                    214 The USB character device nodes
215 ==============================                    215 ==============================
216                                                   216 
217 This chapter presents the Linux character devi    217 This chapter presents the Linux character device nodes. You may prefer
218 to avoid writing new kernel code for your USB     218 to avoid writing new kernel code for your USB driver. User mode device
219 drivers are usually packaged as applications o    219 drivers are usually packaged as applications or libraries, and may use
220 character devices through some programming lib    220 character devices through some programming library that wraps it.
221 Such libraries include:                           221 Such libraries include:
222                                                   222 
223  - `libusb <http://libusb.sourceforge.net>`__     223  - `libusb <http://libusb.sourceforge.net>`__ for C/C++, and
224  - `jUSB <http://jUSB.sourceforge.net>`__ for     224  - `jUSB <http://jUSB.sourceforge.net>`__ for Java.
225                                                   225 
226 Some old information about it can be seen at t    226 Some old information about it can be seen at the "USB Device Filesystem"
227 section of the USB Guide. The latest copy of t    227 section of the USB Guide. The latest copy of the USB Guide can be found
228 at http://www.linux-usb.org/                      228 at http://www.linux-usb.org/
229                                                   229 
230 .. note::                                         230 .. note::
231                                                   231 
232   - They were used to be implemented via *usbf    232   - They were used to be implemented via *usbfs*, but this is not part of
233     the sysfs debug interface.                    233     the sysfs debug interface.
234                                                   234 
235    - This particular documentation is incomple    235    - This particular documentation is incomplete, especially with respect
236      to the asynchronous mode. As of kernel 2.    236      to the asynchronous mode. As of kernel 2.5.66 the code and this
237      (new) documentation need to be cross-revi    237      (new) documentation need to be cross-reviewed.
238                                                   238 
239 What files are in "devtmpfs"?                     239 What files are in "devtmpfs"?
240 -----------------------------                     240 -----------------------------
241                                                   241 
242 Conventionally mounted at ``/dev/bus/usb/``, u    242 Conventionally mounted at ``/dev/bus/usb/``, usbfs features include:
243                                                   243 
244 -  ``/dev/bus/usb/BBB/DDD`` ... magic files ex    244 -  ``/dev/bus/usb/BBB/DDD`` ... magic files exposing the each device's
245    configuration descriptors, and supporting a    245    configuration descriptors, and supporting a series of ioctls for
246    making device requests, including I/O to de    246    making device requests, including I/O to devices. (Purely for access
247    by programs.)                                  247    by programs.)
248                                                   248 
249 Each bus is given a number (``BBB``) based on     249 Each bus is given a number (``BBB``) based on when it was enumerated; within
250 each bus, each device is given a similar numbe    250 each bus, each device is given a similar number (``DDD``). Those ``BBB/DDD``
251 paths are not "stable" identifiers; expect the    251 paths are not "stable" identifiers; expect them to change even if you
252 always leave the devices plugged in to the sam    252 always leave the devices plugged in to the same hub port. *Don't even
253 think of saving these in application configura    253 think of saving these in application configuration files.* Stable
254 identifiers are available, for user mode appli    254 identifiers are available, for user mode applications that want to use
255 them. HID and networking devices expose these     255 them. HID and networking devices expose these stable IDs, so that for
256 example you can be sure that you told the righ    256 example you can be sure that you told the right UPS to power down its
257 second server. Pleast note that it doesn't (ye    257 second server. Pleast note that it doesn't (yet) expose those IDs.
258                                                   258 
259 /dev/bus/usb/BBB/DDD                              259 /dev/bus/usb/BBB/DDD
260 --------------------                              260 --------------------
261                                                   261 
262 Use these files in one of these basic ways:       262 Use these files in one of these basic ways:
263                                                   263 
264 - *They can be read,* producing first the devi    264 - *They can be read,* producing first the device descriptor (18 bytes) and
265   then the descriptors for the current configu    265   then the descriptors for the current configuration. See the USB 2.0 spec
266   for details about those binary data formats.    266   for details about those binary data formats. You'll need to convert most
267   multibyte values from little endian format t    267   multibyte values from little endian format to your native host byte
268   order, although a few of the fields in the d    268   order, although a few of the fields in the device descriptor (both of
269   the BCD-encoded fields, and the vendor and p    269   the BCD-encoded fields, and the vendor and product IDs) will be
270   byteswapped for you. Note that configuration    270   byteswapped for you. Note that configuration descriptors include
271   descriptors for interfaces, altsettings, end    271   descriptors for interfaces, altsettings, endpoints, and maybe additional
272   class descriptors.                              272   class descriptors.
273                                                   273 
274 - *Perform USB operations* using *ioctl()* req    274 - *Perform USB operations* using *ioctl()* requests to make endpoint I/O
275   requests (synchronously or asynchronously) o    275   requests (synchronously or asynchronously) or manage the device. These
276   requests need the ``CAP_SYS_RAWIO`` capabili    276   requests need the ``CAP_SYS_RAWIO`` capability, as well as filesystem
277   access permissions. Only one ioctl request c    277   access permissions. Only one ioctl request can be made on one of these
278   device files at a time. This means that if y    278   device files at a time. This means that if you are synchronously reading
279   an endpoint from one thread, you won't be ab    279   an endpoint from one thread, you won't be able to write to a different
280   endpoint from another thread until the read     280   endpoint from another thread until the read completes. This works for
281   *half duplex* protocols, but otherwise you'd    281   *half duplex* protocols, but otherwise you'd use asynchronous i/o
282   requests.                                       282   requests.
283                                                   283 
284 Each connected USB device has one file.  The `    284 Each connected USB device has one file.  The ``BBB`` indicates the bus
285 number.  The ``DDD`` indicates the device addr    285 number.  The ``DDD`` indicates the device address on that bus.  Both
286 of these numbers are assigned sequentially, an    286 of these numbers are assigned sequentially, and can be reused, so
287 you can't rely on them for stable access to de    287 you can't rely on them for stable access to devices.  For example,
288 it's relatively common for devices to re-enume    288 it's relatively common for devices to re-enumerate while they are
289 still connected (perhaps someone jostled their    289 still connected (perhaps someone jostled their power supply, hub,
290 or USB cable), so a device might be ``002/027`    290 or USB cable), so a device might be ``002/027`` when you first connect
291 it and ``002/048`` sometime later.                291 it and ``002/048`` sometime later.
292                                                   292 
293 These files can be read as binary data.  The b    293 These files can be read as binary data.  The binary data consists
294 of first the device descriptor, then the descr    294 of first the device descriptor, then the descriptors for each
295 configuration of the device.  Multi-byte field    295 configuration of the device.  Multi-byte fields in the device descriptor
296 are converted to host endianness by the kernel    296 are converted to host endianness by the kernel.  The configuration
297 descriptors are in bus endian format! The conf    297 descriptors are in bus endian format! The configuration descriptor
298 are wTotalLength bytes apart. If a device retu    298 are wTotalLength bytes apart. If a device returns less configuration
299 descriptor data than indicated by wTotalLength    299 descriptor data than indicated by wTotalLength there will be a hole in
300 the file for the missing bytes.  This informat    300 the file for the missing bytes.  This information is also shown
301 in text form by the ``/sys/kernel/debug/usb/de    301 in text form by the ``/sys/kernel/debug/usb/devices`` file, described later.
302                                                   302 
303 These files may also be used to write user-lev    303 These files may also be used to write user-level drivers for the USB
304 devices.  You would open the ``/dev/bus/usb/BB    304 devices.  You would open the ``/dev/bus/usb/BBB/DDD`` file read/write,
305 read its descriptors to make sure it's the dev    305 read its descriptors to make sure it's the device you expect, and then
306 bind to an interface (or perhaps several) usin    306 bind to an interface (or perhaps several) using an ioctl call.  You
307 would issue more ioctls to the device to commu    307 would issue more ioctls to the device to communicate to it using
308 control, bulk, or other kinds of USB transfers    308 control, bulk, or other kinds of USB transfers.  The IOCTLs are
309 listed in the ``<linux/usbdevice_fs.h>`` file,    309 listed in the ``<linux/usbdevice_fs.h>`` file, and at this writing the
310 source code (``linux/drivers/usb/core/devio.c`    310 source code (``linux/drivers/usb/core/devio.c``) is the primary reference
311 for how to access devices through those files.    311 for how to access devices through those files.
312                                                   312 
313 Note that since by default these ``BBB/DDD`` f    313 Note that since by default these ``BBB/DDD`` files are writable only by
314 root, only root can write such user mode drive    314 root, only root can write such user mode drivers.  You can selectively
315 grant read/write permissions to other users by    315 grant read/write permissions to other users by using ``chmod``.  Also,
316 usbfs mount options such as ``devmode=0666`` m    316 usbfs mount options such as ``devmode=0666`` may be helpful.
317                                                   317 
318                                                   318 
319 Life Cycle of User Mode Drivers                   319 Life Cycle of User Mode Drivers
320 -------------------------------                   320 -------------------------------
321                                                   321 
322 Such a driver first needs to find a device fil    322 Such a driver first needs to find a device file for a device it knows
323 how to handle. Maybe it was told about it beca    323 how to handle. Maybe it was told about it because a ``/sbin/hotplug``
324 event handling agent chose that driver to hand    324 event handling agent chose that driver to handle the new device. Or
325 maybe it's an application that scans all the `    325 maybe it's an application that scans all the ``/dev/bus/usb`` device files,
326 and ignores most devices. In either case, it s    326 and ignores most devices. In either case, it should :c:func:`read()`
327 all the descriptors from the device file, and     327 all the descriptors from the device file, and check them against what it
328 knows how to handle. It might just reject ever    328 knows how to handle. It might just reject everything except a particular
329 vendor and product ID, or need a more complex     329 vendor and product ID, or need a more complex policy.
330                                                   330 
331 Never assume there will only be one such devic    331 Never assume there will only be one such device on the system at a time!
332 If your code can't handle more than one device    332 If your code can't handle more than one device at a time, at least
333 detect when there's more than one, and have yo    333 detect when there's more than one, and have your users choose which
334 device to use.                                    334 device to use.
335                                                   335 
336 Once your user mode driver knows what device t    336 Once your user mode driver knows what device to use, it interacts with
337 it in either of two styles. The simple style i    337 it in either of two styles. The simple style is to make only control
338 requests; some devices don't need more complex    338 requests; some devices don't need more complex interactions than those.
339 (An example might be software using vendor-spe    339 (An example might be software using vendor-specific control requests for
340 some initialization or configuration tasks, wi    340 some initialization or configuration tasks, with a kernel driver for the
341 rest.)                                            341 rest.)
342                                                   342 
343 More likely, you need a more complex style dri    343 More likely, you need a more complex style driver: one using non-control
344 endpoints, reading or writing data and claimin    344 endpoints, reading or writing data and claiming exclusive use of an
345 interface. *Bulk* transfers are easiest to use    345 interface. *Bulk* transfers are easiest to use, but only their sibling
346 *interrupt* transfers work with low speed devi    346 *interrupt* transfers work with low speed devices. Both interrupt and
347 *isochronous* transfers offer service guarante    347 *isochronous* transfers offer service guarantees because their bandwidth
348 is reserved. Such "periodic" transfers are awk    348 is reserved. Such "periodic" transfers are awkward to use through usbfs,
349 unless you're using the asynchronous calls. Ho    349 unless you're using the asynchronous calls. However, interrupt transfers
350 can also be used in a synchronous "one shot" s    350 can also be used in a synchronous "one shot" style.
351                                                   351 
352 Your user-mode driver should never need to wor    352 Your user-mode driver should never need to worry about cleaning up
353 request state when the device is disconnected,    353 request state when the device is disconnected, although it should close
354 its open file descriptors as soon as it starts    354 its open file descriptors as soon as it starts seeing the ENODEV errors.
355                                                   355 
356 The ioctl() Requests                              356 The ioctl() Requests
357 --------------------                              357 --------------------
358                                                   358 
359 To use these ioctls, you need to include the f    359 To use these ioctls, you need to include the following headers in your
360 userspace program::                               360 userspace program::
361                                                   361 
362     #include <linux/usb.h>                        362     #include <linux/usb.h>
363     #include <linux/usbdevice_fs.h>               363     #include <linux/usbdevice_fs.h>
364     #include <asm/byteorder.h>                    364     #include <asm/byteorder.h>
365                                                   365 
366 The standard USB device model requests, from "    366 The standard USB device model requests, from "Chapter 9" of the USB 2.0
367 specification, are automatically included from    367 specification, are automatically included from the ``<linux/usb/ch9.h>``
368 header.                                           368 header.
369                                                   369 
370 Unless noted otherwise, the ioctl requests des    370 Unless noted otherwise, the ioctl requests described here will update
371 the modification time on the usbfs file to whi    371 the modification time on the usbfs file to which they are applied
372 (unless they fail). A return of zero indicates    372 (unless they fail). A return of zero indicates success; otherwise, a
373 standard USB error code is returned (These are    373 standard USB error code is returned (These are documented in
374 :ref:`usb-error-codes`).                          374 :ref:`usb-error-codes`).
375                                                   375 
376 Each of these files multiplexes access to seve    376 Each of these files multiplexes access to several I/O streams, one per
377 endpoint. Each device has one control endpoint    377 endpoint. Each device has one control endpoint (endpoint zero) which
378 supports a limited RPC style RPC access. Devic    378 supports a limited RPC style RPC access. Devices are configured by
379 hub_wq (in the kernel) setting a device-wide *    379 hub_wq (in the kernel) setting a device-wide *configuration* that
380 affects things like power consumption and basi    380 affects things like power consumption and basic functionality. The
381 endpoints are part of USB *interfaces*, which     381 endpoints are part of USB *interfaces*, which may have *altsettings*
382 affecting things like which endpoints are avai    382 affecting things like which endpoints are available. Many devices only
383 have a single configuration and interface, so     383 have a single configuration and interface, so drivers for them will
384 ignore configurations and altsettings.            384 ignore configurations and altsettings.
385                                                   385 
386 Management/Status Requests                        386 Management/Status Requests
387 ~~~~~~~~~~~~~~~~~~~~~~~~~~                        387 ~~~~~~~~~~~~~~~~~~~~~~~~~~
388                                                   388 
389 A number of usbfs requests don't deal very dir    389 A number of usbfs requests don't deal very directly with device I/O.
390 They mostly relate to device management and st    390 They mostly relate to device management and status. These are all
391 synchronous requests.                             391 synchronous requests.
392                                                   392 
393 USBDEVFS_CLAIMINTERFACE                           393 USBDEVFS_CLAIMINTERFACE
394     This is used to force usbfs to claim a spe    394     This is used to force usbfs to claim a specific interface, which has
395     not previously been claimed by usbfs or an    395     not previously been claimed by usbfs or any other kernel driver. The
396     ioctl parameter is an integer holding the     396     ioctl parameter is an integer holding the number of the interface
397     (bInterfaceNumber from descriptor).           397     (bInterfaceNumber from descriptor).
398                                                   398 
399     Note that if your driver doesn't claim an     399     Note that if your driver doesn't claim an interface before trying to
400     use one of its endpoints, and no other dri    400     use one of its endpoints, and no other driver has bound to it, then
401     the interface is automatically claimed by     401     the interface is automatically claimed by usbfs.
402                                                   402 
403     This claim will be released by a RELEASEIN    403     This claim will be released by a RELEASEINTERFACE ioctl, or by
404     closing the file descriptor. File modifica    404     closing the file descriptor. File modification time is not updated
405     by this request.                              405     by this request.
406                                                   406 
407 USBDEVFS_CONNECTINFO                              407 USBDEVFS_CONNECTINFO
408     Says whether the device is lowspeed. The i    408     Says whether the device is lowspeed. The ioctl parameter points to a
409     structure like this::                         409     structure like this::
410                                                   410 
411         struct usbdevfs_connectinfo {             411         struct usbdevfs_connectinfo {
412                 unsigned int   devnum;            412                 unsigned int   devnum;
413                 unsigned char  slow;              413                 unsigned char  slow;
414         };                                        414         };
415                                                   415 
416     File modification time is not updated by t    416     File modification time is not updated by this request.
417                                                   417 
418     *You can't tell whether a "not slow" devic    418     *You can't tell whether a "not slow" device is connected at high
419     speed (480 MBit/sec) or just full speed (1    419     speed (480 MBit/sec) or just full speed (12 MBit/sec).* You should
420     know the devnum value already, it's the DD    420     know the devnum value already, it's the DDD value of the device file
421     name.                                         421     name.
422                                                   422 
423 USBDEVFS_GET_SPEED                             << 
424     Returns the speed of the device. The speed << 
425     numerical value in accordance with enum us << 
426                                                << 
427     File modification time is not updated by t << 
428                                                << 
429 USBDEVFS_GETDRIVER                                423 USBDEVFS_GETDRIVER
430     Returns the name of the kernel driver boun    424     Returns the name of the kernel driver bound to a given interface (a
431     string). Parameter is a pointer to this st    425     string). Parameter is a pointer to this structure, which is
432     modified::                                    426     modified::
433                                                   427 
434         struct usbdevfs_getdriver {               428         struct usbdevfs_getdriver {
435                 unsigned int  interface;          429                 unsigned int  interface;
436                 char          driver[USBDEVFS_    430                 char          driver[USBDEVFS_MAXDRIVERNAME + 1];
437         };                                        431         };
438                                                   432 
439     File modification time is not updated by t    433     File modification time is not updated by this request.
440                                                   434 
441 USBDEVFS_IOCTL                                    435 USBDEVFS_IOCTL
442     Passes a request from userspace through to    436     Passes a request from userspace through to a kernel driver that has
443     an ioctl entry in the *struct usb_driver*     437     an ioctl entry in the *struct usb_driver* it registered::
444                                                   438 
445         struct usbdevfs_ioctl {                   439         struct usbdevfs_ioctl {
446                 int     ifno;                     440                 int     ifno;
447                 int     ioctl_code;               441                 int     ioctl_code;
448                 void    *data;                    442                 void    *data;
449         };                                        443         };
450                                                   444 
451         /* user mode call looks like this.        445         /* user mode call looks like this.
452          * 'request' becomes the driver->ioctl    446          * 'request' becomes the driver->ioctl() 'code' parameter.
453          * the size of 'param' is encoded in '    447          * the size of 'param' is encoded in 'request', and that data
454          * is copied to or from the driver->io    448          * is copied to or from the driver->ioctl() 'buf' parameter.
455          */                                       449          */
456         static int                                450         static int
457         usbdev_ioctl (int fd, int ifno, unsign    451         usbdev_ioctl (int fd, int ifno, unsigned request, void *param)
458         {                                         452         {
459                 struct usbdevfs_ioctl   wrappe    453                 struct usbdevfs_ioctl   wrapper;
460                                                   454 
461                 wrapper.ifno = ifno;              455                 wrapper.ifno = ifno;
462                 wrapper.ioctl_code = request;     456                 wrapper.ioctl_code = request;
463                 wrapper.data = param;             457                 wrapper.data = param;
464                                                   458 
465                 return ioctl (fd, USBDEVFS_IOC    459                 return ioctl (fd, USBDEVFS_IOCTL, &wrapper);
466         }                                         460         }
467                                                   461 
468     File modification time is not updated by t    462     File modification time is not updated by this request.
469                                                   463 
470     This request lets kernel drivers talk to u    464     This request lets kernel drivers talk to user mode code through
471     filesystem operations even when they don't    465     filesystem operations even when they don't create a character or
472     block special device. It's also been used     466     block special device. It's also been used to do things like ask
473     devices what device special file should be    467     devices what device special file should be used. Two pre-defined
474     ioctls are used to disconnect and reconnec    468     ioctls are used to disconnect and reconnect kernel drivers, so that
475     user mode code can completely manage bindi    469     user mode code can completely manage binding and configuration of
476     devices.                                      470     devices.
477                                                   471 
478 USBDEVFS_RELEASEINTERFACE                         472 USBDEVFS_RELEASEINTERFACE
479     This is used to release the claim usbfs ma    473     This is used to release the claim usbfs made on interface, either
480     implicitly or because of a USBDEVFS_CLAIMI    474     implicitly or because of a USBDEVFS_CLAIMINTERFACE call, before the
481     file descriptor is closed. The ioctl param    475     file descriptor is closed. The ioctl parameter is an integer holding
482     the number of the interface (bInterfaceNum    476     the number of the interface (bInterfaceNumber from descriptor); File
483     modification time is not updated by this r    477     modification time is not updated by this request.
484                                                   478 
485     .. warning::                                  479     .. warning::
486                                                   480 
487         *No security check is made to ensure t    481         *No security check is made to ensure that the task which made
488         the claim is the one which is releasin    482         the claim is the one which is releasing it. This means that user
489         mode driver may interfere other ones.*    483         mode driver may interfere other ones.*
490                                                   484 
491 USBDEVFS_RESETEP                                  485 USBDEVFS_RESETEP
492     Resets the data toggle value for an endpoi    486     Resets the data toggle value for an endpoint (bulk or interrupt) to
493     DATA0. The ioctl parameter is an integer e    487     DATA0. The ioctl parameter is an integer endpoint number (1 to 15,
494     as identified in the endpoint descriptor),    488     as identified in the endpoint descriptor), with USB_DIR_IN added
495     if the device's endpoint sends data to the    489     if the device's endpoint sends data to the host.
496                                                   490 
497     .. Warning::                                  491     .. Warning::
498                                                   492 
499         *Avoid using this request. It should p    493         *Avoid using this request. It should probably be removed.* Using
500         it typically means the device and driv    494         it typically means the device and driver will lose toggle
501         synchronization. If you really lost sy    495         synchronization. If you really lost synchronization, you likely
502         need to completely handshake with the     496         need to completely handshake with the device, using a request
503         like CLEAR_HALT or SET_INTERFACE.         497         like CLEAR_HALT or SET_INTERFACE.
504                                                   498 
505 USBDEVFS_DROP_PRIVILEGES                          499 USBDEVFS_DROP_PRIVILEGES
506     This is used to relinquish the ability to     500     This is used to relinquish the ability to do certain operations
507     which are considered to be privileged on a    501     which are considered to be privileged on a usbfs file descriptor.
508     This includes claiming arbitrary interface    502     This includes claiming arbitrary interfaces, resetting a device on
509     which there are currently claimed interfac    503     which there are currently claimed interfaces from other users, and
510     issuing USBDEVFS_IOCTL calls. The ioctl pa    504     issuing USBDEVFS_IOCTL calls. The ioctl parameter is a 32 bit mask
511     of interfaces the user is allowed to claim    505     of interfaces the user is allowed to claim on this file descriptor.
512     You may issue this ioctl more than one tim    506     You may issue this ioctl more than one time to narrow said mask.
513                                                   507 
514 Synchronous I/O Support                           508 Synchronous I/O Support
515 ~~~~~~~~~~~~~~~~~~~~~~~                           509 ~~~~~~~~~~~~~~~~~~~~~~~
516                                                   510 
517 Synchronous requests involve the kernel blocki    511 Synchronous requests involve the kernel blocking until the user mode
518 request completes, either by finishing success    512 request completes, either by finishing successfully or by reporting an
519 error. In most cases this is the simplest way     513 error. In most cases this is the simplest way to use usbfs, although as
520 noted above it does prevent performing I/O to     514 noted above it does prevent performing I/O to more than one endpoint at
521 a time.                                           515 a time.
522                                                   516 
523 USBDEVFS_BULK                                     517 USBDEVFS_BULK
524     Issues a bulk read or write request to the    518     Issues a bulk read or write request to the device. The ioctl
525     parameter is a pointer to this structure::    519     parameter is a pointer to this structure::
526                                                   520 
527         struct usbdevfs_bulktransfer {            521         struct usbdevfs_bulktransfer {
528                 unsigned int  ep;                 522                 unsigned int  ep;
529                 unsigned int  len;                523                 unsigned int  len;
530                 unsigned int  timeout; /* in m    524                 unsigned int  timeout; /* in milliseconds */
531                 void          *data;              525                 void          *data;
532         };                                        526         };
533                                                   527 
534     The ``ep`` value identifies a bulk endpoin    528     The ``ep`` value identifies a bulk endpoint number (1 to 15, as
535     identified in an endpoint descriptor), mas    529     identified in an endpoint descriptor), masked with USB_DIR_IN when
536     referring to an endpoint which sends data     530     referring to an endpoint which sends data to the host from the
537     device. The length of the data buffer is i    531     device. The length of the data buffer is identified by ``len``; Recent
538     kernels support requests up to about 128KB    532     kernels support requests up to about 128KBytes. *FIXME say how read
539     length is returned, and how short reads ar    533     length is returned, and how short reads are handled.*.
540                                                   534 
541 USBDEVFS_CLEAR_HALT                               535 USBDEVFS_CLEAR_HALT
542     Clears endpoint halt (stall) and resets th    536     Clears endpoint halt (stall) and resets the endpoint toggle. This is
543     only meaningful for bulk or interrupt endp    537     only meaningful for bulk or interrupt endpoints. The ioctl parameter
544     is an integer endpoint number (1 to 15, as    538     is an integer endpoint number (1 to 15, as identified in an endpoint
545     descriptor), masked with USB_DIR_IN when r    539     descriptor), masked with USB_DIR_IN when referring to an endpoint
546     which sends data to the host from the devi    540     which sends data to the host from the device.
547                                                   541 
548     Use this on bulk or interrupt endpoints wh    542     Use this on bulk or interrupt endpoints which have stalled,
549     returning ``-EPIPE`` status to a data tran    543     returning ``-EPIPE`` status to a data transfer request. Do not issue
550     the control request directly, since that c    544     the control request directly, since that could invalidate the host's
551     record of the data toggle.                    545     record of the data toggle.
552                                                   546 
553 USBDEVFS_CONTROL                                  547 USBDEVFS_CONTROL
554     Issues a control request to the device. Th    548     Issues a control request to the device. The ioctl parameter points
555     to a structure like this::                    549     to a structure like this::
556                                                   550 
557         struct usbdevfs_ctrltransfer {            551         struct usbdevfs_ctrltransfer {
558                 __u8   bRequestType;              552                 __u8   bRequestType;
559                 __u8   bRequest;                  553                 __u8   bRequest;
560                 __u16  wValue;                    554                 __u16  wValue;
561                 __u16  wIndex;                    555                 __u16  wIndex;
562                 __u16  wLength;                   556                 __u16  wLength;
563                 __u32  timeout;  /* in millise    557                 __u32  timeout;  /* in milliseconds */
564                 void   *data;                     558                 void   *data;
565         };                                        559         };
566                                                   560 
567     The first eight bytes of this structure ar    561     The first eight bytes of this structure are the contents of the
568     SETUP packet to be sent to the device; see    562     SETUP packet to be sent to the device; see the USB 2.0 specification
569     for details. The bRequestType value is com    563     for details. The bRequestType value is composed by combining a
570     ``USB_TYPE_*`` value, a ``USB_DIR_*`` valu    564     ``USB_TYPE_*`` value, a ``USB_DIR_*`` value, and a ``USB_RECIP_*``
571     value (from ``linux/usb.h``). If wLength i    565     value (from ``linux/usb.h``). If wLength is nonzero, it describes
572     the length of the data buffer, which is ei    566     the length of the data buffer, which is either written to the device
573     (USB_DIR_OUT) or read from the device (USB    567     (USB_DIR_OUT) or read from the device (USB_DIR_IN).
574                                                   568 
575     At this writing, you can't transfer more t    569     At this writing, you can't transfer more than 4 KBytes of data to or
576     from a device; usbfs has a limit, and some    570     from a device; usbfs has a limit, and some host controller drivers
577     have a limit. (That's not usually a proble    571     have a limit. (That's not usually a problem.) *Also* there's no way
578     to say it's not OK to get a short read bac    572     to say it's not OK to get a short read back from the device.
579                                                   573 
580 USBDEVFS_RESET                                    574 USBDEVFS_RESET
581     Does a USB level device reset. The ioctl p    575     Does a USB level device reset. The ioctl parameter is ignored. After
582     the reset, this rebinds all device interfa    576     the reset, this rebinds all device interfaces. File modification
583     time is not updated by this request.          577     time is not updated by this request.
584                                                   578 
585 .. warning::                                      579 .. warning::
586                                                   580 
587         *Avoid using this call* until some usb    581         *Avoid using this call* until some usbcore bugs get fixed, since
588         it does not fully synchronize device,     582         it does not fully synchronize device, interface, and driver (not
589         just usbfs) state.                        583         just usbfs) state.
590                                                   584 
591 USBDEVFS_SETINTERFACE                             585 USBDEVFS_SETINTERFACE
592     Sets the alternate setting for an interfac    586     Sets the alternate setting for an interface. The ioctl parameter is
593     a pointer to a structure like this::          587     a pointer to a structure like this::
594                                                   588 
595         struct usbdevfs_setinterface {            589         struct usbdevfs_setinterface {
596                 unsigned int  interface;          590                 unsigned int  interface;
597                 unsigned int  altsetting;         591                 unsigned int  altsetting;
598         };                                        592         };
599                                                   593 
600     File modification time is not updated by t    594     File modification time is not updated by this request.
601                                                   595 
602     Those struct members are from some interfa    596     Those struct members are from some interface descriptor applying to
603     the current configuration. The interface n    597     the current configuration. The interface number is the
604     bInterfaceNumber value, and the altsetting    598     bInterfaceNumber value, and the altsetting number is the
605     bAlternateSetting value. (This resets each    599     bAlternateSetting value. (This resets each endpoint in the
606     interface.)                                   600     interface.)
607                                                   601 
608 USBDEVFS_SETCONFIGURATION                         602 USBDEVFS_SETCONFIGURATION
609     Issues the :c:func:`usb_set_configuration(    603     Issues the :c:func:`usb_set_configuration()` call for the
610     device. The parameter is an integer holdin    604     device. The parameter is an integer holding the number of a
611     configuration (bConfigurationValue from de    605     configuration (bConfigurationValue from descriptor). File
612     modification time is not updated by this r    606     modification time is not updated by this request.
613                                                   607 
614 .. warning::                                      608 .. warning::
615                                                   609 
616         *Avoid using this call* until some usb    610         *Avoid using this call* until some usbcore bugs get fixed, since
617         it does not fully synchronize device,     611         it does not fully synchronize device, interface, and driver (not
618         just usbfs) state.                        612         just usbfs) state.
619                                                   613 
620 Asynchronous I/O Support                          614 Asynchronous I/O Support
621 ~~~~~~~~~~~~~~~~~~~~~~~~                          615 ~~~~~~~~~~~~~~~~~~~~~~~~
622                                                   616 
623 As mentioned above, there are situations where    617 As mentioned above, there are situations where it may be important to
624 initiate concurrent operations from user mode     618 initiate concurrent operations from user mode code. This is particularly
625 important for periodic transfers (interrupt an    619 important for periodic transfers (interrupt and isochronous), but it can
626 be used for other kinds of USB requests too. I    620 be used for other kinds of USB requests too. In such cases, the
627 asynchronous requests described here are essen    621 asynchronous requests described here are essential. Rather than
628 submitting one request and having the kernel b    622 submitting one request and having the kernel block until it completes,
629 the blocking is separate.                         623 the blocking is separate.
630                                                   624 
631 These requests are packaged into a structure t    625 These requests are packaged into a structure that resembles the URB used
632 by kernel device drivers. (No POSIX Async I/O     626 by kernel device drivers. (No POSIX Async I/O support here, sorry.) It
633 identifies the endpoint type (``USBDEVFS_URB_T    627 identifies the endpoint type (``USBDEVFS_URB_TYPE_*``), endpoint
634 (number, masked with USB_DIR_IN as appropriate    628 (number, masked with USB_DIR_IN as appropriate), buffer and length,
635 and a user "context" value serving to uniquely    629 and a user "context" value serving to uniquely identify each request.
636 (It's usually a pointer to per-request data.)     630 (It's usually a pointer to per-request data.) Flags can modify requests
637 (not as many as supported for kernel drivers).    631 (not as many as supported for kernel drivers).
638                                                   632 
639 Each request can specify a realtime signal num    633 Each request can specify a realtime signal number (between SIGRTMIN and
640 SIGRTMAX, inclusive) to request a signal be se    634 SIGRTMAX, inclusive) to request a signal be sent when the request
641 completes.                                        635 completes.
642                                                   636 
643 When usbfs returns these urbs, the status valu    637 When usbfs returns these urbs, the status value is updated, and the
644 buffer may have been modified. Except for isoc    638 buffer may have been modified. Except for isochronous transfers, the
645 actual_length is updated to say how many bytes    639 actual_length is updated to say how many bytes were transferred; if the
646 USBDEVFS_URB_DISABLE_SPD flag is set ("short p    640 USBDEVFS_URB_DISABLE_SPD flag is set ("short packets are not OK"), if
647 fewer bytes were read than were requested then    641 fewer bytes were read than were requested then you get an error report::
648                                                   642 
649     struct usbdevfs_iso_packet_desc {             643     struct usbdevfs_iso_packet_desc {
650             unsigned int                     l    644             unsigned int                     length;
651             unsigned int                     a    645             unsigned int                     actual_length;
652             unsigned int                     s    646             unsigned int                     status;
653     };                                            647     };
654                                                   648 
655     struct usbdevfs_urb {                         649     struct usbdevfs_urb {
656             unsigned char                    t    650             unsigned char                    type;
657             unsigned char                    e    651             unsigned char                    endpoint;
658             int                              s    652             int                              status;
659             unsigned int                     f    653             unsigned int                     flags;
660             void                             *    654             void                             *buffer;
661             int                              b    655             int                              buffer_length;
662             int                              a    656             int                              actual_length;
663             int                              s    657             int                              start_frame;
664             int                              n    658             int                              number_of_packets;
665             int                              e    659             int                              error_count;
666             unsigned int                     s    660             unsigned int                     signr;
667             void                             *    661             void                             *usercontext;
668             struct usbdevfs_iso_packet_desc  i    662             struct usbdevfs_iso_packet_desc  iso_frame_desc[];
669     };                                            663     };
670                                                   664 
671 For these asynchronous requests, the file modi    665 For these asynchronous requests, the file modification time reflects
672 when the request was initiated. This contrasts    666 when the request was initiated. This contrasts with their use with the
673 synchronous requests, where it reflects when r    667 synchronous requests, where it reflects when requests complete.
674                                                   668 
675 USBDEVFS_DISCARDURB                               669 USBDEVFS_DISCARDURB
676     *TBS* File modification time is not update    670     *TBS* File modification time is not updated by this request.
677                                                   671 
678 USBDEVFS_DISCSIGNAL                               672 USBDEVFS_DISCSIGNAL
679     *TBS* File modification time is not update    673     *TBS* File modification time is not updated by this request.
680                                                   674 
681 USBDEVFS_REAPURB                                  675 USBDEVFS_REAPURB
682     *TBS* File modification time is not update    676     *TBS* File modification time is not updated by this request.
683                                                   677 
684 USBDEVFS_REAPURBNDELAY                            678 USBDEVFS_REAPURBNDELAY
685     *TBS* File modification time is not update    679     *TBS* File modification time is not updated by this request.
686                                                   680 
687 USBDEVFS_SUBMITURB                                681 USBDEVFS_SUBMITURB
688     *TBS*                                         682     *TBS*
689                                                   683 
690 The USB devices                                   684 The USB devices
691 ===============                                   685 ===============
692                                                   686 
693 The USB devices are now exported via debugfs:     687 The USB devices are now exported via debugfs:
694                                                   688 
695 -  ``/sys/kernel/debug/usb/devices`` ... a tex    689 -  ``/sys/kernel/debug/usb/devices`` ... a text file showing each of the USB
696    devices on known to the kernel, and their c    690    devices on known to the kernel, and their configuration descriptors.
697    You can also poll() this to learn about new    691    You can also poll() this to learn about new devices.
698                                                   692 
699 /sys/kernel/debug/usb/devices                     693 /sys/kernel/debug/usb/devices
700 -----------------------------                     694 -----------------------------
701                                                   695 
702 This file is handy for status viewing tools in    696 This file is handy for status viewing tools in user mode, which can scan
703 the text format and ignore most of it. More de    697 the text format and ignore most of it. More detailed device status
704 (including class and vendor status) is availab    698 (including class and vendor status) is available from device-specific
705 files. For information about the current forma    699 files. For information about the current format of this file, see below.
706                                                   700 
707 This file, in combination with the poll() syst    701 This file, in combination with the poll() system call, can also be used
708 to detect when devices are added or removed::     702 to detect when devices are added or removed::
709                                                   703 
710     int fd;                                       704     int fd;
711     struct pollfd pfd;                            705     struct pollfd pfd;
712                                                   706 
713     fd = open("/sys/kernel/debug/usb/devices",    707     fd = open("/sys/kernel/debug/usb/devices", O_RDONLY);
714     pfd = { fd, POLLIN, 0 };                      708     pfd = { fd, POLLIN, 0 };
715     for (;;) {                                    709     for (;;) {
716         /* The first time through, this call w    710         /* The first time through, this call will return immediately. */
717         poll(&pfd, 1, -1);                        711         poll(&pfd, 1, -1);
718                                                   712 
719         /* To see what's changed, compare the     713         /* To see what's changed, compare the file's previous and current
720            contents or scan the filesystem.  (    714            contents or scan the filesystem.  (Scanning is more precise.) */
721     }                                             715     }
722                                                   716 
723 Note that this behavior is intended to be used    717 Note that this behavior is intended to be used for informational and
724 debug purposes. It would be more appropriate t    718 debug purposes. It would be more appropriate to use programs such as
725 udev or HAL to initialize a device or start a     719 udev or HAL to initialize a device or start a user-mode helper program,
726 for instance.                                     720 for instance.
727                                                   721 
728 In this file, each device's output has multipl    722 In this file, each device's output has multiple lines of ASCII output.
729                                                   723 
730 I made it ASCII instead of binary on purpose,     724 I made it ASCII instead of binary on purpose, so that someone
731 can obtain some useful data from it without th    725 can obtain some useful data from it without the use of an
732 auxiliary program.  However, with an auxiliary    726 auxiliary program.  However, with an auxiliary program, the numbers
733 in the first 4 columns of each ``T:`` line (to    727 in the first 4 columns of each ``T:`` line (topology info:
734 Lev, Prnt, Port, Cnt) can be used to build a U    728 Lev, Prnt, Port, Cnt) can be used to build a USB topology diagram.
735                                                   729 
736 Each line is tagged with a one-character ID fo    730 Each line is tagged with a one-character ID for that line::
737                                                   731 
738         T = Topology (etc.)                       732         T = Topology (etc.)
739         B = Bandwidth (applies only to USB hos    733         B = Bandwidth (applies only to USB host controllers, which are
740         virtualized as root hubs)                 734         virtualized as root hubs)
741         D = Device descriptor info.               735         D = Device descriptor info.
742         P = Product ID info. (from Device desc    736         P = Product ID info. (from Device descriptor, but they won't fit
743         together on one line)                     737         together on one line)
744         S = String descriptors.                   738         S = String descriptors.
745         C = Configuration descriptor info. (*     739         C = Configuration descriptor info. (* = active configuration)
746         I = Interface descriptor info.            740         I = Interface descriptor info.
747         E = Endpoint descriptor info.             741         E = Endpoint descriptor info.
748                                                   742 
749 /sys/kernel/debug/usb/devices output format       743 /sys/kernel/debug/usb/devices output format
750 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       744 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
751                                                   745 
752 Legend::                                          746 Legend::
753   d = decimal number (may have leading spaces     747   d = decimal number (may have leading spaces or 0's)
754   x = hexadecimal number (may have leading spa    748   x = hexadecimal number (may have leading spaces or 0's)
755   s = string                                      749   s = string
756                                                   750 
757                                                   751 
758                                                   752 
759 Topology info                                     753 Topology info
760 ^^^^^^^^^^^^^                                     754 ^^^^^^^^^^^^^
761                                                   755 
762 ::                                                756 ::
763                                                   757 
764         T:  Bus=dd Lev=dd Prnt=dd Port=dd Cnt=    758         T:  Bus=dd Lev=dd Prnt=dd Port=dd Cnt=dd Dev#=ddd Spd=dddd MxCh=dd
765         |   |      |      |       |       |       759         |   |      |      |       |       |      |        |        |__MaxChildren
766         |   |      |      |       |       |       760         |   |      |      |       |       |      |        |__Device Speed in Mbps
767         |   |      |      |       |       |       761         |   |      |      |       |       |      |__DeviceNumber
768         |   |      |      |       |       |__C    762         |   |      |      |       |       |__Count of devices at this level
769         |   |      |      |       |__Connector    763         |   |      |      |       |__Connector/Port on Parent for this device
770         |   |      |      |__Parent DeviceNumb    764         |   |      |      |__Parent DeviceNumber
771         |   |      |__Level in topology for th    765         |   |      |__Level in topology for this bus
772         |   |__Bus number                         766         |   |__Bus number
773         |__Topology info tag                      767         |__Topology info tag
774                                                   768 
775 Speed may be:                                     769 Speed may be:
776                                                   770 
777         ======= ==============================    771         ======= ======================================================
778         1.5     Mbit/s for low speed USB          772         1.5     Mbit/s for low speed USB
779         12      Mbit/s for full speed USB         773         12      Mbit/s for full speed USB
780         480     Mbit/s for high speed USB (add !! 774         480     Mbit/s for high speed USB (added for USB 2.0);
                                                   >> 775                 also used for Wireless USB, which has no fixed speed
781         5000    Mbit/s for SuperSpeed USB (add    776         5000    Mbit/s for SuperSpeed USB (added for USB 3.0)
782         ======= ==============================    777         ======= ======================================================
783                                                   778 
784 For reasons lost in the mists of time, the Por    779 For reasons lost in the mists of time, the Port number is always
785 too low by 1.  For example, a device plugged i    780 too low by 1.  For example, a device plugged into port 4 will
786 show up with ``Port=03``.                         781 show up with ``Port=03``.
787                                                   782 
788 Bandwidth info                                    783 Bandwidth info
789 ^^^^^^^^^^^^^^                                    784 ^^^^^^^^^^^^^^
790                                                   785 
791 ::                                                786 ::
792                                                   787 
793         B:  Alloc=ddd/ddd us (xx%), #Int=ddd,     788         B:  Alloc=ddd/ddd us (xx%), #Int=ddd, #Iso=ddd
794         |   |                       |             789         |   |                       |         |__Number of isochronous requests
795         |   |                       |__Number     790         |   |                       |__Number of interrupt requests
796         |   |__Total Bandwidth allocated to th    791         |   |__Total Bandwidth allocated to this bus
797         |__Bandwidth info tag                     792         |__Bandwidth info tag
798                                                   793 
799 Bandwidth allocation is an approximation of ho    794 Bandwidth allocation is an approximation of how much of one frame
800 (millisecond) is in use.  It reflects only per    795 (millisecond) is in use.  It reflects only periodic transfers, which
801 are the only transfers that reserve bandwidth.    796 are the only transfers that reserve bandwidth.  Control and bulk
802 transfers use all other bandwidth, including r    797 transfers use all other bandwidth, including reserved bandwidth that
803 is not used for transfers (such as for short p    798 is not used for transfers (such as for short packets).
804                                                   799 
805 The percentage is how much of the "reserved" b    800 The percentage is how much of the "reserved" bandwidth is scheduled by
806 those transfers.  For a low or full speed bus     801 those transfers.  For a low or full speed bus (loosely, "USB 1.1"),
807 90% of the bus bandwidth is reserved.  For a h    802 90% of the bus bandwidth is reserved.  For a high speed bus (loosely,
808 "USB 2.0") 80% is reserved.                       803 "USB 2.0") 80% is reserved.
809                                                   804 
810                                                   805 
811 Device descriptor info & Product ID info          806 Device descriptor info & Product ID info
812 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^          807 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
813                                                   808 
814 ::                                                809 ::
815                                                   810 
816         D:  Ver=x.xx Cls=xx(s) Sub=xx Prot=xx     811         D:  Ver=x.xx Cls=xx(s) Sub=xx Prot=xx MxPS=dd #Cfgs=dd
817         P:  Vendor=xxxx ProdID=xxxx Rev=xx.xx     812         P:  Vendor=xxxx ProdID=xxxx Rev=xx.xx
818                                                   813 
819 where::                                           814 where::
820                                                   815 
821         D:  Ver=x.xx Cls=xx(sssss) Sub=xx Prot    816         D:  Ver=x.xx Cls=xx(sssss) Sub=xx Prot=xx MxPS=dd #Cfgs=dd
822         |   |        |             |      |       817         |   |        |             |      |       |       |__NumberConfigurations
823         |   |        |             |      |       818         |   |        |             |      |       |__MaxPacketSize of Default Endpoint
824         |   |        |             |      |__D    819         |   |        |             |      |__DeviceProtocol
825         |   |        |             |__DeviceSu    820         |   |        |             |__DeviceSubClass
826         |   |        |__DeviceClass               821         |   |        |__DeviceClass
827         |   |__Device USB version                 822         |   |__Device USB version
828         |__Device info tag #1                     823         |__Device info tag #1
829                                                   824 
830 where::                                           825 where::
831                                                   826 
832         P:  Vendor=xxxx ProdID=xxxx Rev=xx.xx     827         P:  Vendor=xxxx ProdID=xxxx Rev=xx.xx
833         |   |           |           |__Product    828         |   |           |           |__Product revision number
834         |   |           |__Product ID code        829         |   |           |__Product ID code
835         |   |__Vendor ID code                     830         |   |__Vendor ID code
836         |__Device info tag #2                     831         |__Device info tag #2
837                                                   832 
838                                                   833 
839 String descriptor info                            834 String descriptor info
840 ^^^^^^^^^^^^^^^^^^^^^^                            835 ^^^^^^^^^^^^^^^^^^^^^^
841 ::                                                836 ::
842                                                   837 
843         S:  Manufacturer=ssss                     838         S:  Manufacturer=ssss
844         |   |__Manufacturer of this device as     839         |   |__Manufacturer of this device as read from the device.
845         |      For USB host controller drivers    840         |      For USB host controller drivers (virtual root hubs) this may
846         |      be omitted, or (for newer drive    841         |      be omitted, or (for newer drivers) will identify the kernel
847         |      version and the driver which pr    842         |      version and the driver which provides this hub emulation.
848         |__String info tag                        843         |__String info tag
849                                                   844 
850         S:  Product=ssss                          845         S:  Product=ssss
851         |   |__Product description of this dev    846         |   |__Product description of this device as read from the device.
852         |      For older USB host controller d    847         |      For older USB host controller drivers (virtual root hubs) this
853         |      indicates the driver; for newer    848         |      indicates the driver; for newer ones, it's a product (and vendor)
854         |      description that often comes fr    849         |      description that often comes from the kernel's PCI ID database.
855         |__String info tag                        850         |__String info tag
856                                                   851 
857         S:  SerialNumber=ssss                     852         S:  SerialNumber=ssss
858         |   |__Serial Number of this device as    853         |   |__Serial Number of this device as read from the device.
859         |      For USB host controller drivers    854         |      For USB host controller drivers (virtual root hubs) this is
860         |      some unique ID, normally a bus     855         |      some unique ID, normally a bus ID (address or slot name) that
861         |      can't be shared with any other     856         |      can't be shared with any other device.
862         |__String info tag                        857         |__String info tag
863                                                   858 
864                                                   859 
865                                                   860 
866 Configuration descriptor info                     861 Configuration descriptor info
867 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                     862 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
868 ::                                                863 ::
869                                                   864 
870         C:* #Ifs=dd Cfg#=dd Atr=xx MPwr=dddmA     865         C:* #Ifs=dd Cfg#=dd Atr=xx MPwr=dddmA
871         | | |       |       |      |__MaxPower    866         | | |       |       |      |__MaxPower in mA
872         | | |       |       |__Attributes         867         | | |       |       |__Attributes
873         | | |       |__ConfiguratioNumber         868         | | |       |__ConfiguratioNumber
874         | | |__NumberOfInterfaces                 869         | | |__NumberOfInterfaces
875         | |__ "*" indicates the active configu    870         | |__ "*" indicates the active configuration (others are " ")
876         |__Config info tag                        871         |__Config info tag
877                                                   872 
878 USB devices may have multiple configurations,     873 USB devices may have multiple configurations, each of which act
879 rather differently.  For example, a bus-powere    874 rather differently.  For example, a bus-powered configuration
880 might be much less capable than one that is se    875 might be much less capable than one that is self-powered.  Only
881 one device configuration can be active at a ti    876 one device configuration can be active at a time; most devices
882 have only one configuration.                      877 have only one configuration.
883                                                   878 
884 Each configuration consists of one or more int    879 Each configuration consists of one or more interfaces.  Each
885 interface serves a distinct "function", which     880 interface serves a distinct "function", which is typically bound
886 to a different USB device driver.  One common     881 to a different USB device driver.  One common example is a USB
887 speaker with an audio interface for playback,     882 speaker with an audio interface for playback, and a HID interface
888 for use with software volume control.             883 for use with software volume control.
889                                                   884 
890 Interface descriptor info (can be multiple per    885 Interface descriptor info (can be multiple per Config)
891 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^    886 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
892 ::                                                887 ::
893                                                   888 
894         I:* If#=dd Alt=dd #EPs=dd Cls=xx(sssss    889         I:* If#=dd Alt=dd #EPs=dd Cls=xx(sssss) Sub=xx Prot=xx Driver=ssss
895         | | |      |      |       |               890         | | |      |      |       |             |      |       |__Driver name
896         | | |      |      |       |               891         | | |      |      |       |             |      |          or "(none)"
897         | | |      |      |       |               892         | | |      |      |       |             |      |__InterfaceProtocol
898         | | |      |      |       |               893         | | |      |      |       |             |__InterfaceSubClass
899         | | |      |      |       |__Interface    894         | | |      |      |       |__InterfaceClass
900         | | |      |      |__NumberOfEndpoints    895         | | |      |      |__NumberOfEndpoints
901         | | |      |__AlternateSettingNumber      896         | | |      |__AlternateSettingNumber
902         | | |__InterfaceNumber                    897         | | |__InterfaceNumber
903         | |__ "*" indicates the active altsett    898         | |__ "*" indicates the active altsetting (others are " ")
904         |__Interface info tag                     899         |__Interface info tag
905                                                   900 
906 A given interface may have one or more "altern    901 A given interface may have one or more "alternate" settings.
907 For example, default settings may not use more    902 For example, default settings may not use more than a small
908 amount of periodic bandwidth.  To use signific    903 amount of periodic bandwidth.  To use significant fractions
909 of bus bandwidth, drivers must select a non-de    904 of bus bandwidth, drivers must select a non-default altsetting.
910                                                   905 
911 Only one setting for an interface may be activ    906 Only one setting for an interface may be active at a time, and
912 only one driver may bind to an interface at a     907 only one driver may bind to an interface at a time.  Most devices
913 have only one alternate setting per interface.    908 have only one alternate setting per interface.
914                                                   909 
915                                                   910 
916 Endpoint descriptor info (can be multiple per     911 Endpoint descriptor info (can be multiple per Interface)
917 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^    912 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
918                                                   913 
919 ::                                                914 ::
920                                                   915 
921         E:  Ad=xx(s) Atr=xx(ssss) MxPS=dddd Iv    916         E:  Ad=xx(s) Atr=xx(ssss) MxPS=dddd Ivl=dddss
922         |   |        |            |         |_    917         |   |        |            |         |__Interval (max) between transfers
923         |   |        |            |__EndpointM    918         |   |        |            |__EndpointMaxPacketSize
924         |   |        |__Attributes(EndpointTyp    919         |   |        |__Attributes(EndpointType)
925         |   |__EndpointAddress(I=In,O=Out)        920         |   |__EndpointAddress(I=In,O=Out)
926         |__Endpoint info tag                      921         |__Endpoint info tag
927                                                   922 
928 The interval is nonzero for all periodic (inte    923 The interval is nonzero for all periodic (interrupt or isochronous)
929 endpoints.  For high speed endpoints the trans    924 endpoints.  For high speed endpoints the transfer interval may be
930 measured in microseconds rather than milliseco    925 measured in microseconds rather than milliseconds.
931                                                   926 
932 For high speed periodic endpoints, the ``Endpo    927 For high speed periodic endpoints, the ``EndpointMaxPacketSize`` reflects
933 the per-microframe data transfer size.  For "h    928 the per-microframe data transfer size.  For "high bandwidth"
934 endpoints, that can reflect two or three packe    929 endpoints, that can reflect two or three packets (for up to
935 3KBytes every 125 usec) per endpoint.             930 3KBytes every 125 usec) per endpoint.
936                                                   931 
937 With the Linux-USB stack, periodic bandwidth r    932 With the Linux-USB stack, periodic bandwidth reservations use the
938 transfer intervals and sizes provided by URBs,    933 transfer intervals and sizes provided by URBs, which can be less
939 than those found in endpoint descriptor.          934 than those found in endpoint descriptor.
940                                                   935 
941 Usage examples                                    936 Usage examples
942 ~~~~~~~~~~~~~~                                    937 ~~~~~~~~~~~~~~
943                                                   938 
944 If a user or script is interested only in Topo    939 If a user or script is interested only in Topology info, for
945 example, use something like ``grep ^T: /sys/ke    940 example, use something like ``grep ^T: /sys/kernel/debug/usb/devices``
946 for only the Topology lines.  A command like      941 for only the Topology lines.  A command like
947 ``grep -i ^[tdp]: /sys/kernel/debug/usb/device    942 ``grep -i ^[tdp]: /sys/kernel/debug/usb/devices`` can be used to list
948 only the lines that begin with the characters     943 only the lines that begin with the characters in square brackets,
949 where the valid characters are TDPCIE.  With a    944 where the valid characters are TDPCIE.  With a slightly more able
950 script, it can display any selected lines (for    945 script, it can display any selected lines (for example, only T, D,
951 and P lines) and change their output format.      946 and P lines) and change their output format.  (The ``procusb``
952 Perl script is the beginning of this idea.  It    947 Perl script is the beginning of this idea.  It will list only
953 selected lines [selected from TBDPSCIE] or "Al    948 selected lines [selected from TBDPSCIE] or "All" lines from
954 ``/sys/kernel/debug/usb/devices``.)               949 ``/sys/kernel/debug/usb/devices``.)
955                                                   950 
956 The Topology lines can be used to generate a g    951 The Topology lines can be used to generate a graphic/pictorial
957 of the USB devices on a system's root hub.  (S    952 of the USB devices on a system's root hub.  (See more below
958 on how to do this.)                               953 on how to do this.)
959                                                   954 
960 The Interface lines can be used to determine w    955 The Interface lines can be used to determine what driver is
961 being used for each device, and which altsetti    956 being used for each device, and which altsetting it activated.
962                                                   957 
963 The Configuration lines could be used to list     958 The Configuration lines could be used to list maximum power
964 (in milliamps) that a system's USB devices are    959 (in milliamps) that a system's USB devices are using.
965 For example, ``grep ^C: /sys/kernel/debug/usb/    960 For example, ``grep ^C: /sys/kernel/debug/usb/devices``.
966                                                   961 
967                                                   962 
968 Here's an example, from a system which has a U    963 Here's an example, from a system which has a UHCI root hub,
969 an external hub connected to the root hub, and    964 an external hub connected to the root hub, and a mouse and
970 a serial converter connected to the external h    965 a serial converter connected to the external hub.
971                                                   966 
972 ::                                                967 ::
973                                                   968 
974         T:  Bus=00 Lev=00 Prnt=00 Port=00 Cnt=    969         T:  Bus=00 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12   MxCh= 2
975         B:  Alloc= 28/900 us ( 3%), #Int=  2,     970         B:  Alloc= 28/900 us ( 3%), #Int=  2, #Iso=  0
976         D:  Ver= 1.00 Cls=09(hub  ) Sub=00 Pro    971         D:  Ver= 1.00 Cls=09(hub  ) Sub=00 Prot=00 MxPS= 8 #Cfgs=  1
977         P:  Vendor=0000 ProdID=0000 Rev= 0.00     972         P:  Vendor=0000 ProdID=0000 Rev= 0.00
978         S:  Product=USB UHCI Root Hub             973         S:  Product=USB UHCI Root Hub
979         S:  SerialNumber=dce0                     974         S:  SerialNumber=dce0
980         C:* #Ifs= 1 Cfg#= 1 Atr=40 MxPwr=  0mA    975         C:* #Ifs= 1 Cfg#= 1 Atr=40 MxPwr=  0mA
981         I:  If#= 0 Alt= 0 #EPs= 1 Cls=09(hub      976         I:  If#= 0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub
982         E:  Ad=81(I) Atr=03(Int.) MxPS=   8 Iv    977         E:  Ad=81(I) Atr=03(Int.) MxPS=   8 Ivl=255ms
983                                                   978 
984         T:  Bus=00 Lev=01 Prnt=01 Port=00 Cnt=    979         T:  Bus=00 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  2 Spd=12   MxCh= 4
985         D:  Ver= 1.00 Cls=09(hub  ) Sub=00 Pro    980         D:  Ver= 1.00 Cls=09(hub  ) Sub=00 Prot=00 MxPS= 8 #Cfgs=  1
986         P:  Vendor=0451 ProdID=1446 Rev= 1.00     981         P:  Vendor=0451 ProdID=1446 Rev= 1.00
987         C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=100mA    982         C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=100mA
988         I:  If#= 0 Alt= 0 #EPs= 1 Cls=09(hub      983         I:  If#= 0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub
989         E:  Ad=81(I) Atr=03(Int.) MxPS=   1 Iv    984         E:  Ad=81(I) Atr=03(Int.) MxPS=   1 Ivl=255ms
990                                                   985 
991         T:  Bus=00 Lev=02 Prnt=02 Port=00 Cnt=    986         T:  Bus=00 Lev=02 Prnt=02 Port=00 Cnt=01 Dev#=  3 Spd=1.5  MxCh= 0
992         D:  Ver= 1.00 Cls=00(>ifc ) Sub=00 Pro    987         D:  Ver= 1.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs=  1
993         P:  Vendor=04b4 ProdID=0001 Rev= 0.00     988         P:  Vendor=04b4 ProdID=0001 Rev= 0.00
994         C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=100mA    989         C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=100mA
995         I:  If#= 0 Alt= 0 #EPs= 1 Cls=03(HID      990         I:  If#= 0 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=01 Prot=02 Driver=mouse
996         E:  Ad=81(I) Atr=03(Int.) MxPS=   3 Iv    991         E:  Ad=81(I) Atr=03(Int.) MxPS=   3 Ivl= 10ms
997                                                   992 
998         T:  Bus=00 Lev=02 Prnt=02 Port=02 Cnt=    993         T:  Bus=00 Lev=02 Prnt=02 Port=02 Cnt=02 Dev#=  4 Spd=12   MxCh= 0
999         D:  Ver= 1.00 Cls=00(>ifc ) Sub=00 Pro    994         D:  Ver= 1.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs=  1
1000         P:  Vendor=0565 ProdID=0001 Rev= 1.08    995         P:  Vendor=0565 ProdID=0001 Rev= 1.08
1001         S:  Manufacturer=Peracom Networks, In    996         S:  Manufacturer=Peracom Networks, Inc.
1002         S:  Product=Peracom USB to Serial Con    997         S:  Product=Peracom USB to Serial Converter
1003         C:* #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr=100m    998         C:* #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr=100mA
1004         I:  If#= 0 Alt= 0 #EPs= 3 Cls=00(>ifc    999         I:  If#= 0 Alt= 0 #EPs= 3 Cls=00(>ifc ) Sub=00 Prot=00 Driver=serial
1005         E:  Ad=81(I) Atr=02(Bulk) MxPS=  64 I    1000         E:  Ad=81(I) Atr=02(Bulk) MxPS=  64 Ivl= 16ms
1006         E:  Ad=01(O) Atr=02(Bulk) MxPS=  16 I    1001         E:  Ad=01(O) Atr=02(Bulk) MxPS=  16 Ivl= 16ms
1007         E:  Ad=82(I) Atr=03(Int.) MxPS=   8 I    1002         E:  Ad=82(I) Atr=03(Int.) MxPS=   8 Ivl=  8ms
1008                                                  1003 
1009                                                  1004 
1010 Selecting only the ``T:`` and ``I:`` lines fr    1005 Selecting only the ``T:`` and ``I:`` lines from this (for example, by using
1011 ``procusb ti``), we have                         1006 ``procusb ti``), we have
1012                                                  1007 
1013 ::                                               1008 ::
1014                                                  1009 
1015         T:  Bus=00 Lev=00 Prnt=00 Port=00 Cnt    1010         T:  Bus=00 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12   MxCh= 2
1016         T:  Bus=00 Lev=01 Prnt=01 Port=00 Cnt    1011         T:  Bus=00 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  2 Spd=12   MxCh= 4
1017         I:  If#= 0 Alt= 0 #EPs= 1 Cls=09(hub     1012         I:  If#= 0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub
1018         T:  Bus=00 Lev=02 Prnt=02 Port=00 Cnt    1013         T:  Bus=00 Lev=02 Prnt=02 Port=00 Cnt=01 Dev#=  3 Spd=1.5  MxCh= 0
1019         I:  If#= 0 Alt= 0 #EPs= 1 Cls=03(HID     1014         I:  If#= 0 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=01 Prot=02 Driver=mouse
1020         T:  Bus=00 Lev=02 Prnt=02 Port=02 Cnt    1015         T:  Bus=00 Lev=02 Prnt=02 Port=02 Cnt=02 Dev#=  4 Spd=12   MxCh= 0
1021         I:  If#= 0 Alt= 0 #EPs= 3 Cls=00(>ifc    1016         I:  If#= 0 Alt= 0 #EPs= 3 Cls=00(>ifc ) Sub=00 Prot=00 Driver=serial
1022                                                  1017 
1023                                                  1018 
1024 Physically this looks like (or could be conve    1019 Physically this looks like (or could be converted to)::
1025                                                  1020 
1026                       +------------------+       1021                       +------------------+
1027                       |  PC/root_hub (12)|       1022                       |  PC/root_hub (12)|   Dev# = 1
1028                       +------------------+       1023                       +------------------+   (nn) is Mbps.
1029     Level 0           |  CN.0   |  CN.1  |       1024     Level 0           |  CN.0   |  CN.1  |   [CN = connector/port #]
1030                       +------------------+       1025                       +------------------+
1031                           /                      1026                           /
1032                          /                       1027                          /
1033             +-----------------------+            1028             +-----------------------+
1034   Level 1   | Dev#2: 4-port hub (12)|            1029   Level 1   | Dev#2: 4-port hub (12)|
1035             +-----------------------+            1030             +-----------------------+
1036             |CN.0 |CN.1 |CN.2 |CN.3 |            1031             |CN.0 |CN.1 |CN.2 |CN.3 |
1037             +-----------------------+            1032             +-----------------------+
1038                 \           \________________    1033                 \           \____________________
1039                  \_____                          1034                  \_____                          \
1040                        \                         1035                        \                          \
1041                +--------------------+      +-    1036                +--------------------+      +--------------------+
1042   Level 2      | Dev# 3: mouse (1.5)|      |     1037   Level 2      | Dev# 3: mouse (1.5)|      | Dev# 4: serial (12)|
1043                +--------------------+      +-    1038                +--------------------+      +--------------------+
1044                                                  1039 
1045                                                  1040 
1046                                                  1041 
1047 Or, in a more tree-like structure (ports [Con    1042 Or, in a more tree-like structure (ports [Connectors] without
1048 connections could be omitted)::                  1043 connections could be omitted)::
1049                                                  1044 
1050         PC:  Dev# 1, root hub, 2 ports, 12 Mb    1045         PC:  Dev# 1, root hub, 2 ports, 12 Mbps
1051         |_ CN.0:  Dev# 2, hub, 4 ports, 12 Mb    1046         |_ CN.0:  Dev# 2, hub, 4 ports, 12 Mbps
1052              |_ CN.0:  Dev #3, mouse, 1.5 Mbp    1047              |_ CN.0:  Dev #3, mouse, 1.5 Mbps
1053              |_ CN.1:                            1048              |_ CN.1:
1054              |_ CN.2:  Dev #4, serial, 12 Mbp    1049              |_ CN.2:  Dev #4, serial, 12 Mbps
1055              |_ CN.3:                            1050              |_ CN.3:
1056         |_ CN.1:                                 1051         |_ CN.1:
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php