Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb.rst: move documentation from proc_usb_info.txt to USB ReST book

The contents of proc_usb_info.txt complements what's there at
driver-api usb book. Yet, it is outdated, as it still refers
to the USB character devices as usbfs.

So, move the contents to usb.rst, adjusting it to point to
the right places.

Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>

authored by

Mauro Carvalho Chehab and committed by
Jonathan Corbet
96801b35 9b06f754

+404 -423
+404 -33
Documentation/driver-api/usb/usb.rst
··· 212 212 to avoid writing new kernel code for your USB driver. User mode device 213 213 drivers are usually packaged as applications or libraries, and may use 214 214 character devices through some programming library that wraps it. 215 - Such libraries include 216 - `libusb <http://libusb.sourceforge.net>`__ for C/C++, and 217 - `jUSB <http://jUSB.sourceforge.net>`__ for Java. 215 + Such libraries include: 216 + 217 + - `libusb <http://libusb.sourceforge.net>`__ for C/C++, and 218 + - `jUSB <http://jUSB.sourceforge.net>`__ for Java. 219 + 220 + Some old information about it can be seen at the "USB Device Filesystem" 221 + section of the USB Guide. The latest copy of the USB Guide can be found 222 + at http://www.linux-usb.org/ 218 223 219 224 .. note:: 220 225 ··· 235 230 236 231 Conventionally mounted at ``/dev/bus/usb/``, usbfs features include: 237 232 238 - - ``/dev/bus/usb//BBB/DDD`` ... magic files exposing the each device's 233 + - ``/dev/bus/usb/BBB/DDD`` ... magic files exposing the each device's 239 234 configuration descriptors, and supporting a series of ioctls for 240 235 making device requests, including I/O to devices. (Purely for access 241 236 by programs.) 242 237 243 - Each bus is given a number (BBB) based on when it was enumerated; within 244 - each bus, each device is given a similar number (DDD). Those BBB/DDD 238 + Each bus is given a number (``BBB``) based on when it was enumerated; within 239 + each bus, each device is given a similar number (``DDD``). Those ``BBB/DDD`` 245 240 paths are not "stable" identifiers; expect them to change even if you 246 241 always leave the devices plugged in to the same hub port. *Don't even 247 242 think of saving these in application configuration files.* Stable 248 243 identifiers are available, for user mode applications that want to use 249 244 them. HID and networking devices expose these stable IDs, so that for 250 245 example you can be sure that you told the right UPS to power down its 251 - second server. "usbfs" doesn't (yet) expose those IDs. 246 + second server. Pleast note that it doesn't (yet) expose those IDs. 252 247 253 - /dev/bus/usb//BBB/DDD 254 - --------------------- 248 + /dev/bus/usb/BBB/DDD 249 + -------------------- 255 250 256 251 Use these files in one of these basic ways: 257 252 258 - *They can be read,* producing first the device descriptor (18 bytes) and 259 - then the descriptors for the current configuration. See the USB 2.0 spec 260 - for details about those binary data formats. You'll need to convert most 261 - multibyte values from little endian format to your native host byte 262 - order, although a few of the fields in the device descriptor (both of 263 - the BCD-encoded fields, and the vendor and product IDs) will be 264 - byteswapped for you. Note that configuration descriptors include 265 - descriptors for interfaces, altsettings, endpoints, and maybe additional 266 - class descriptors. 253 + - *They can be read,* producing first the device descriptor (18 bytes) and 254 + then the descriptors for the current configuration. See the USB 2.0 spec 255 + for details about those binary data formats. You'll need to convert most 256 + multibyte values from little endian format to your native host byte 257 + order, although a few of the fields in the device descriptor (both of 258 + the BCD-encoded fields, and the vendor and product IDs) will be 259 + byteswapped for you. Note that configuration descriptors include 260 + descriptors for interfaces, altsettings, endpoints, and maybe additional 261 + class descriptors. 267 262 268 - *Perform USB operations* using *ioctl()* requests to make endpoint I/O 269 - requests (synchronously or asynchronously) or manage the device. These 270 - requests need the CAP_SYS_RAWIO capability, as well as filesystem 271 - access permissions. Only one ioctl request can be made on one of these 272 - device files at a time. This means that if you are synchronously reading 273 - an endpoint from one thread, you won't be able to write to a different 274 - endpoint from another thread until the read completes. This works for 275 - *half duplex* protocols, but otherwise you'd use asynchronous i/o 276 - requests. 263 + - *Perform USB operations* using *ioctl()* requests to make endpoint I/O 264 + requests (synchronously or asynchronously) or manage the device. These 265 + requests need the ``CAP_SYS_RAWIO`` capability, as well as filesystem 266 + access permissions. Only one ioctl request can be made on one of these 267 + device files at a time. This means that if you are synchronously reading 268 + an endpoint from one thread, you won't be able to write to a different 269 + endpoint from another thread until the read completes. This works for 270 + *half duplex* protocols, but otherwise you'd use asynchronous i/o 271 + requests. 272 + 273 + Each connected USB device has one file. The ``BBB`` indicates the bus 274 + number. The ``DDD`` indicates the device address on that bus. Both 275 + of these numbers are assigned sequentially, and can be reused, so 276 + you can't rely on them for stable access to devices. For example, 277 + it's relatively common for devices to re-enumerate while they are 278 + still connected (perhaps someone jostled their power supply, hub, 279 + or USB cable), so a device might be ``002/027`` when you first connect 280 + it and ``002/048`` sometime later. 281 + 282 + These files can be read as binary data. The binary data consists 283 + of first the device descriptor, then the descriptors for each 284 + configuration of the device. Multi-byte fields in the device descriptor 285 + are converted to host endianness by the kernel. The configuration 286 + descriptors are in bus endian format! The configuration descriptor 287 + are wTotalLength bytes apart. If a device returns less configuration 288 + descriptor data than indicated by wTotalLength there will be a hole in 289 + the file for the missing bytes. This information is also shown 290 + in text form by the ``/sys/kernel/debug/usb/devices`` file, described later. 291 + 292 + These files may also be used to write user-level drivers for the USB 293 + devices. You would open the ``/dev/bus/usb/BBB/DDD`` file read/write, 294 + read its descriptors to make sure it's the device you expect, and then 295 + bind to an interface (or perhaps several) using an ioctl call. You 296 + would issue more ioctls to the device to communicate to it using 297 + control, bulk, or other kinds of USB transfers. The IOCTLs are 298 + listed in the ``<linux/usbdevice_fs.h>`` file, and at this writing the 299 + source code (``linux/drivers/usb/core/devio.c``) is the primary reference 300 + for how to access devices through those files. 301 + 302 + Note that since by default these ``BBB/DDD`` files are writable only by 303 + root, only root can write such user mode drivers. You can selectively 304 + grant read/write permissions to other users by using ``chmod``. Also, 305 + usbfs mount options such as ``devmode=0666`` may be helpful. 306 + 277 307 278 308 Life Cycle of User Mode Drivers 279 309 ------------------------------- ··· 316 276 Such a driver first needs to find a device file for a device it knows 317 277 how to handle. Maybe it was told about it because a ``/sbin/hotplug`` 318 278 event handling agent chose that driver to handle the new device. Or 319 - maybe it's an application that scans all the /dev/bus/usb/ device files, 279 + maybe it's an application that scans all the ``/dev/bus/usb`` device files, 320 280 and ignores most devices. In either case, it should :c:func:`read()` 321 281 all the descriptors from the device file, and check them against what it 322 282 knows how to handle. It might just reject everything except a particular ··· 470 430 the number of the interface (bInterfaceNumber from descriptor); File 471 431 modification time is not updated by this request. 472 432 473 - .. warning:: 433 + .. warning:: 474 434 475 435 *No security check is made to ensure that the task which made 476 436 the claim is the one which is releasing it. This means that user ··· 482 442 as identified in the endpoint descriptor), with USB_DIR_IN added 483 443 if the device's endpoint sends data to the host. 484 444 485 - **Warning** 445 + .. Warning:: 486 446 487 447 *Avoid using this request. It should probably be removed.* Using 488 448 it typically means the device and driver will lose toggle ··· 519 479 void *data; 520 480 }; 521 481 522 - The "ep" value identifies a bulk endpoint number (1 to 15, as 482 + The ``ep`` value identifies a bulk endpoint number (1 to 15, as 523 483 identified in an endpoint descriptor), masked with USB_DIR_IN when 524 484 referring to an endpoint which sends data to the host from the 525 - device. The length of the data buffer is identified by "len"; Recent 485 + device. The length of the data buffer is identified by ``len``; Recent 526 486 kernels support requests up to about 128KBytes. *FIXME say how read 527 487 length is returned, and how short reads are handled.*. 528 488 ··· 534 494 which sends data to the host from the device. 535 495 536 496 Use this on bulk or interrupt endpoints which have stalled, 537 - returning *-EPIPE* status to a data transfer request. Do not issue 497 + returning ``-EPIPE`` status to a data transfer request. Do not issue 538 498 the control request directly, since that could invalidate the host's 539 499 record of the data toggle. 540 500 ··· 714 674 debug purposes. It would be more appropriate to use programs such as 715 675 udev or HAL to initialize a device or start a user-mode helper program, 716 676 for instance. 677 + 678 + In this file, each device's output has multiple lines of ASCII output. 679 + 680 + I made it ASCII instead of binary on purpose, so that someone 681 + can obtain some useful data from it without the use of an 682 + auxiliary program. However, with an auxiliary program, the numbers 683 + in the first 4 columns of each ``T:`` line (topology info: 684 + Lev, Prnt, Port, Cnt) can be used to build a USB topology diagram. 685 + 686 + Each line is tagged with a one-character ID for that line:: 687 + 688 + T = Topology (etc.) 689 + B = Bandwidth (applies only to USB host controllers, which are 690 + virtualized as root hubs) 691 + D = Device descriptor info. 692 + P = Product ID info. (from Device descriptor, but they won't fit 693 + together on one line) 694 + S = String descriptors. 695 + C = Configuration descriptor info. (* = active configuration) 696 + I = Interface descriptor info. 697 + E = Endpoint descriptor info. 698 + 699 + /sys/kernel/debug/usb/devices output format 700 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 701 + 702 + Legend:: 703 + d = decimal number (may have leading spaces or 0's) 704 + x = hexadecimal number (may have leading spaces or 0's) 705 + s = string 706 + 707 + 708 + 709 + Topology info 710 + ^^^^^^^^^^^^^ 711 + 712 + :: 713 + 714 + T: Bus=dd Lev=dd Prnt=dd Port=dd Cnt=dd Dev#=ddd Spd=dddd MxCh=dd 715 + | | | | | | | | |__MaxChildren 716 + | | | | | | | |__Device Speed in Mbps 717 + | | | | | | |__DeviceNumber 718 + | | | | | |__Count of devices at this level 719 + | | | | |__Connector/Port on Parent for this device 720 + | | | |__Parent DeviceNumber 721 + | | |__Level in topology for this bus 722 + | |__Bus number 723 + |__Topology info tag 724 + 725 + Speed may be: 726 + 727 + ======= ====================================================== 728 + 1.5 Mbit/s for low speed USB 729 + 12 Mbit/s for full speed USB 730 + 480 Mbit/s for high speed USB (added for USB 2.0); 731 + also used for Wireless USB, which has no fixed speed 732 + 5000 Mbit/s for SuperSpeed USB (added for USB 3.0) 733 + ======= ====================================================== 734 + 735 + For reasons lost in the mists of time, the Port number is always 736 + too low by 1. For example, a device plugged into port 4 will 737 + show up with ``Port=03``. 738 + 739 + Bandwidth info 740 + ^^^^^^^^^^^^^^ 741 + 742 + :: 743 + 744 + B: Alloc=ddd/ddd us (xx%), #Int=ddd, #Iso=ddd 745 + | | | |__Number of isochronous requests 746 + | | |__Number of interrupt requests 747 + | |__Total Bandwidth allocated to this bus 748 + |__Bandwidth info tag 749 + 750 + Bandwidth allocation is an approximation of how much of one frame 751 + (millisecond) is in use. It reflects only periodic transfers, which 752 + are the only transfers that reserve bandwidth. Control and bulk 753 + transfers use all other bandwidth, including reserved bandwidth that 754 + is not used for transfers (such as for short packets). 755 + 756 + The percentage is how much of the "reserved" bandwidth is scheduled by 757 + those transfers. For a low or full speed bus (loosely, "USB 1.1"), 758 + 90% of the bus bandwidth is reserved. For a high speed bus (loosely, 759 + "USB 2.0") 80% is reserved. 760 + 761 + 762 + Device descriptor info & Product ID info 763 + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 764 + 765 + :: 766 + 767 + D: Ver=x.xx Cls=xx(s) Sub=xx Prot=xx MxPS=dd #Cfgs=dd 768 + P: Vendor=xxxx ProdID=xxxx Rev=xx.xx 769 + 770 + where:: 771 + 772 + D: Ver=x.xx Cls=xx(sssss) Sub=xx Prot=xx MxPS=dd #Cfgs=dd 773 + | | | | | | |__NumberConfigurations 774 + | | | | | |__MaxPacketSize of Default Endpoint 775 + | | | | |__DeviceProtocol 776 + | | | |__DeviceSubClass 777 + | | |__DeviceClass 778 + | |__Device USB version 779 + |__Device info tag #1 780 + 781 + where:: 782 + 783 + P: Vendor=xxxx ProdID=xxxx Rev=xx.xx 784 + | | | |__Product revision number 785 + | | |__Product ID code 786 + | |__Vendor ID code 787 + |__Device info tag #2 788 + 789 + 790 + String descriptor info 791 + ^^^^^^^^^^^^^^^^^^^^^^ 792 + :: 793 + 794 + S: Manufacturer=ssss 795 + | |__Manufacturer of this device as read from the device. 796 + | For USB host controller drivers (virtual root hubs) this may 797 + | be omitted, or (for newer drivers) will identify the kernel 798 + | version and the driver which provides this hub emulation. 799 + |__String info tag 800 + 801 + S: Product=ssss 802 + | |__Product description of this device as read from the device. 803 + | For older USB host controller drivers (virtual root hubs) this 804 + | indicates the driver; for newer ones, it's a product (and vendor) 805 + | description that often comes from the kernel's PCI ID database. 806 + |__String info tag 807 + 808 + S: SerialNumber=ssss 809 + | |__Serial Number of this device as read from the device. 810 + | For USB host controller drivers (virtual root hubs) this is 811 + | some unique ID, normally a bus ID (address or slot name) that 812 + | can't be shared with any other device. 813 + |__String info tag 814 + 815 + 816 + 817 + Configuration descriptor info 818 + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 819 + :: 820 + 821 + C:* #Ifs=dd Cfg#=dd Atr=xx MPwr=dddmA 822 + | | | | | |__MaxPower in mA 823 + | | | | |__Attributes 824 + | | | |__ConfiguratioNumber 825 + | | |__NumberOfInterfaces 826 + | |__ "*" indicates the active configuration (others are " ") 827 + |__Config info tag 828 + 829 + USB devices may have multiple configurations, each of which act 830 + rather differently. For example, a bus-powered configuration 831 + might be much less capable than one that is self-powered. Only 832 + one device configuration can be active at a time; most devices 833 + have only one configuration. 834 + 835 + Each configuration consists of one or more interfaces. Each 836 + interface serves a distinct "function", which is typically bound 837 + to a different USB device driver. One common example is a USB 838 + speaker with an audio interface for playback, and a HID interface 839 + for use with software volume control. 840 + 841 + Interface descriptor info (can be multiple per Config) 842 + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 843 + :: 844 + 845 + I:* If#=dd Alt=dd #EPs=dd Cls=xx(sssss) Sub=xx Prot=xx Driver=ssss 846 + | | | | | | | | |__Driver name 847 + | | | | | | | | or "(none)" 848 + | | | | | | | |__InterfaceProtocol 849 + | | | | | | |__InterfaceSubClass 850 + | | | | | |__InterfaceClass 851 + | | | | |__NumberOfEndpoints 852 + | | | |__AlternateSettingNumber 853 + | | |__InterfaceNumber 854 + | |__ "*" indicates the active altsetting (others are " ") 855 + |__Interface info tag 856 + 857 + A given interface may have one or more "alternate" settings. 858 + For example, default settings may not use more than a small 859 + amount of periodic bandwidth. To use significant fractions 860 + of bus bandwidth, drivers must select a non-default altsetting. 861 + 862 + Only one setting for an interface may be active at a time, and 863 + only one driver may bind to an interface at a time. Most devices 864 + have only one alternate setting per interface. 865 + 866 + 867 + Endpoint descriptor info (can be multiple per Interface) 868 + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 869 + 870 + :: 871 + 872 + E: Ad=xx(s) Atr=xx(ssss) MxPS=dddd Ivl=dddss 873 + | | | | |__Interval (max) between transfers 874 + | | | |__EndpointMaxPacketSize 875 + | | |__Attributes(EndpointType) 876 + | |__EndpointAddress(I=In,O=Out) 877 + |__Endpoint info tag 878 + 879 + The interval is nonzero for all periodic (interrupt or isochronous) 880 + endpoints. For high speed endpoints the transfer interval may be 881 + measured in microseconds rather than milliseconds. 882 + 883 + For high speed periodic endpoints, the ``EndpointMaxPacketSize`` reflects 884 + the per-microframe data transfer size. For "high bandwidth" 885 + endpoints, that can reflect two or three packets (for up to 886 + 3KBytes every 125 usec) per endpoint. 887 + 888 + With the Linux-USB stack, periodic bandwidth reservations use the 889 + transfer intervals and sizes provided by URBs, which can be less 890 + than those found in endpoint descriptor. 891 + 892 + Usage examples 893 + ~~~~~~~~~~~~~~ 894 + 895 + If a user or script is interested only in Topology info, for 896 + example, use something like ``grep ^T: /sys/kernel/debug/usb/devices`` 897 + for only the Topology lines. A command like 898 + ``grep -i ^[tdp]: /sys/kernel/debug/usb/devices`` can be used to list 899 + only the lines that begin with the characters in square brackets, 900 + where the valid characters are TDPCIE. With a slightly more able 901 + script, it can display any selected lines (for example, only T, D, 902 + and P lines) and change their output format. (The ``procusb`` 903 + Perl script is the beginning of this idea. It will list only 904 + selected lines [selected from TBDPSCIE] or "All" lines from 905 + ``/sys/kernel/debug/usb/devices``.) 906 + 907 + The Topology lines can be used to generate a graphic/pictorial 908 + of the USB devices on a system's root hub. (See more below 909 + on how to do this.) 910 + 911 + The Interface lines can be used to determine what driver is 912 + being used for each device, and which altsetting it activated. 913 + 914 + The Configuration lines could be used to list maximum power 915 + (in milliamps) that a system's USB devices are using. 916 + For example, ``grep ^C: /sys/kernel/debug/usb/devices``. 917 + 918 + 919 + Here's an example, from a system which has a UHCI root hub, 920 + an external hub connected to the root hub, and a mouse and 921 + a serial converter connected to the external hub. 922 + 923 + :: 924 + 925 + T: Bus=00 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2 926 + B: Alloc= 28/900 us ( 3%), #Int= 2, #Iso= 0 927 + D: Ver= 1.00 Cls=09(hub ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 928 + P: Vendor=0000 ProdID=0000 Rev= 0.00 929 + S: Product=USB UHCI Root Hub 930 + S: SerialNumber=dce0 931 + C:* #Ifs= 1 Cfg#= 1 Atr=40 MxPwr= 0mA 932 + I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub 933 + E: Ad=81(I) Atr=03(Int.) MxPS= 8 Ivl=255ms 934 + 935 + T: Bus=00 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=12 MxCh= 4 936 + D: Ver= 1.00 Cls=09(hub ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 937 + P: Vendor=0451 ProdID=1446 Rev= 1.00 938 + C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=100mA 939 + I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub 940 + E: Ad=81(I) Atr=03(Int.) MxPS= 1 Ivl=255ms 941 + 942 + T: Bus=00 Lev=02 Prnt=02 Port=00 Cnt=01 Dev#= 3 Spd=1.5 MxCh= 0 943 + D: Ver= 1.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 944 + P: Vendor=04b4 ProdID=0001 Rev= 0.00 945 + C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=100mA 946 + I: If#= 0 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=01 Prot=02 Driver=mouse 947 + E: Ad=81(I) Atr=03(Int.) MxPS= 3 Ivl= 10ms 948 + 949 + T: Bus=00 Lev=02 Prnt=02 Port=02 Cnt=02 Dev#= 4 Spd=12 MxCh= 0 950 + D: Ver= 1.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 951 + P: Vendor=0565 ProdID=0001 Rev= 1.08 952 + S: Manufacturer=Peracom Networks, Inc. 953 + S: Product=Peracom USB to Serial Converter 954 + C:* #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr=100mA 955 + I: If#= 0 Alt= 0 #EPs= 3 Cls=00(>ifc ) Sub=00 Prot=00 Driver=serial 956 + E: Ad=81(I) Atr=02(Bulk) MxPS= 64 Ivl= 16ms 957 + E: Ad=01(O) Atr=02(Bulk) MxPS= 16 Ivl= 16ms 958 + E: Ad=82(I) Atr=03(Int.) MxPS= 8 Ivl= 8ms 959 + 960 + 961 + Selecting only the ``T:`` and ``I:`` lines from this (for example, by using 962 + ``procusb ti``), we have 963 + 964 + :: 965 + 966 + T: Bus=00 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2 967 + T: Bus=00 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=12 MxCh= 4 968 + I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub 969 + T: Bus=00 Lev=02 Prnt=02 Port=00 Cnt=01 Dev#= 3 Spd=1.5 MxCh= 0 970 + I: If#= 0 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=01 Prot=02 Driver=mouse 971 + T: Bus=00 Lev=02 Prnt=02 Port=02 Cnt=02 Dev#= 4 Spd=12 MxCh= 0 972 + I: If#= 0 Alt= 0 #EPs= 3 Cls=00(>ifc ) Sub=00 Prot=00 Driver=serial 973 + 974 + 975 + Physically this looks like (or could be converted to):: 976 + 977 + +------------------+ 978 + | PC/root_hub (12)| Dev# = 1 979 + +------------------+ (nn) is Mbps. 980 + Level 0 | CN.0 | CN.1 | [CN = connector/port #] 981 + +------------------+ 982 + / 983 + / 984 + +-----------------------+ 985 + Level 1 | Dev#2: 4-port hub (12)| 986 + +-----------------------+ 987 + |CN.0 |CN.1 |CN.2 |CN.3 | 988 + +-----------------------+ 989 + \ \____________________ 990 + \_____ \ 991 + \ \ 992 + +--------------------+ +--------------------+ 993 + Level 2 | Dev# 3: mouse (1.5)| | Dev# 4: serial (12)| 994 + +--------------------+ +--------------------+ 995 + 996 + 997 + 998 + Or, in a more tree-like structure (ports [Connectors] without 999 + connections could be omitted):: 1000 + 1001 + PC: Dev# 1, root hub, 2 ports, 12 Mbps 1002 + |_ CN.0: Dev# 2, hub, 4 ports, 12 Mbps 1003 + |_ CN.0: Dev #3, mouse, 1.5 Mbps 1004 + |_ CN.1: 1005 + |_ CN.2: Dev #4, serial, 12 Mbps 1006 + |_ CN.3: 1007 + |_ CN.1:
-390
Documentation/usb/proc_usb_info.txt
··· 1 - /proc/bus/usb filesystem output 2 - =============================== 3 - (version 2010.09.13) 4 - 5 - 6 - The usbfs filesystem for USB devices is traditionally mounted at 7 - /proc/bus/usb. It provides the /sys/kernel/debug/usb/devices file, as well as 8 - the /proc/bus/usb/BBB/DDD files. 9 - 10 - In many modern systems the usbfs filesystem isn't used at all. Instead 11 - USB device nodes are created under /dev/usb/ or someplace similar. The 12 - "devices" file is available in debugfs, typically as 13 - /sys/kernel/debug/usb/devices. 14 - 15 - 16 - **NOTE**: If /proc/bus/usb appears empty, and a host controller 17 - driver has been linked, then you need to mount the 18 - filesystem. Issue the command (as root): 19 - 20 - mount -t usbfs none /proc/bus/usb 21 - 22 - An alternative and more permanent method would be to add 23 - 24 - none /proc/bus/usb usbfs defaults 0 0 25 - 26 - to /etc/fstab. This will mount usbfs at each reboot. 27 - You can then issue `cat /sys/kernel/debug/usb/devices` to extract 28 - USB device information, and user mode drivers can use usbfs 29 - to interact with USB devices. 30 - 31 - There are a number of mount options supported by usbfs. 32 - Consult the source code (linux/drivers/usb/core/inode.c) for 33 - information about those options. 34 - 35 - **NOTE**: The filesystem has been renamed from "usbdevfs" to 36 - "usbfs", to reduce confusion with "devfs". You may 37 - still see references to the older "usbdevfs" name. 38 - 39 - For more information on mounting the usbfs file system, see the 40 - "USB Device Filesystem" section of the USB Guide. The latest copy 41 - of the USB Guide can be found at http://www.linux-usb.org/ 42 - 43 - 44 - THE /proc/bus/usb/BBB/DDD FILES: 45 - -------------------------------- 46 - Each connected USB device has one file. The BBB indicates the bus 47 - number. The DDD indicates the device address on that bus. Both 48 - of these numbers are assigned sequentially, and can be reused, so 49 - you can't rely on them for stable access to devices. For example, 50 - it's relatively common for devices to re-enumerate while they are 51 - still connected (perhaps someone jostled their power supply, hub, 52 - or USB cable), so a device might be 002/027 when you first connect 53 - it and 002/048 sometime later. 54 - 55 - These files can be read as binary data. The binary data consists 56 - of first the device descriptor, then the descriptors for each 57 - configuration of the device. Multi-byte fields in the device descriptor 58 - are converted to host endianness by the kernel. The configuration 59 - descriptors are in bus endian format! The configuration descriptor 60 - are wTotalLength bytes apart. If a device returns less configuration 61 - descriptor data than indicated by wTotalLength there will be a hole in 62 - the file for the missing bytes. This information is also shown 63 - in text form by the /sys/kernel/debug/usb/devices file, described later. 64 - 65 - These files may also be used to write user-level drivers for the USB 66 - devices. You would open the /proc/bus/usb/BBB/DDD file read/write, 67 - read its descriptors to make sure it's the device you expect, and then 68 - bind to an interface (or perhaps several) using an ioctl call. You 69 - would issue more ioctls to the device to communicate to it using 70 - control, bulk, or other kinds of USB transfers. The IOCTLs are 71 - listed in the <linux/usbdevice_fs.h> file, and at this writing the 72 - source code (linux/drivers/usb/core/devio.c) is the primary reference 73 - for how to access devices through those files. 74 - 75 - Note that since by default these BBB/DDD files are writable only by 76 - root, only root can write such user mode drivers. You can selectively 77 - grant read/write permissions to other users by using "chmod". Also, 78 - usbfs mount options such as "devmode=0666" may be helpful. 79 - 80 - 81 - 82 - THE /sys/kernel/debug/usb/devices FILE: 83 - ------------------------------- 84 - In /sys/kernel/debug/usb/devices, each device's output has multiple 85 - lines of ASCII output. 86 - I made it ASCII instead of binary on purpose, so that someone 87 - can obtain some useful data from it without the use of an 88 - auxiliary program. However, with an auxiliary program, the numbers 89 - in the first 4 columns of each "T:" line (topology info: 90 - Lev, Prnt, Port, Cnt) can be used to build a USB topology diagram. 91 - 92 - Each line is tagged with a one-character ID for that line: 93 - 94 - T = Topology (etc.) 95 - B = Bandwidth (applies only to USB host controllers, which are 96 - virtualized as root hubs) 97 - D = Device descriptor info. 98 - P = Product ID info. (from Device descriptor, but they won't fit 99 - together on one line) 100 - S = String descriptors. 101 - C = Configuration descriptor info. (* = active configuration) 102 - I = Interface descriptor info. 103 - E = Endpoint descriptor info. 104 - 105 - ======================================================================= 106 - 107 - /sys/kernel/debug/usb/devices output format: 108 - 109 - Legend: 110 - d = decimal number (may have leading spaces or 0's) 111 - x = hexadecimal number (may have leading spaces or 0's) 112 - s = string 113 - 114 - 115 - Topology info: 116 - 117 - T: Bus=dd Lev=dd Prnt=dd Port=dd Cnt=dd Dev#=ddd Spd=dddd MxCh=dd 118 - | | | | | | | | |__MaxChildren 119 - | | | | | | | |__Device Speed in Mbps 120 - | | | | | | |__DeviceNumber 121 - | | | | | |__Count of devices at this level 122 - | | | | |__Connector/Port on Parent for this device 123 - | | | |__Parent DeviceNumber 124 - | | |__Level in topology for this bus 125 - | |__Bus number 126 - |__Topology info tag 127 - 128 - Speed may be: 129 - 1.5 Mbit/s for low speed USB 130 - 12 Mbit/s for full speed USB 131 - 480 Mbit/s for high speed USB (added for USB 2.0); 132 - also used for Wireless USB, which has no fixed speed 133 - 5000 Mbit/s for SuperSpeed USB (added for USB 3.0) 134 - 135 - For reasons lost in the mists of time, the Port number is always 136 - too low by 1. For example, a device plugged into port 4 will 137 - show up with "Port=03". 138 - 139 - Bandwidth info: 140 - B: Alloc=ddd/ddd us (xx%), #Int=ddd, #Iso=ddd 141 - | | | |__Number of isochronous requests 142 - | | |__Number of interrupt requests 143 - | |__Total Bandwidth allocated to this bus 144 - |__Bandwidth info tag 145 - 146 - Bandwidth allocation is an approximation of how much of one frame 147 - (millisecond) is in use. It reflects only periodic transfers, which 148 - are the only transfers that reserve bandwidth. Control and bulk 149 - transfers use all other bandwidth, including reserved bandwidth that 150 - is not used for transfers (such as for short packets). 151 - 152 - The percentage is how much of the "reserved" bandwidth is scheduled by 153 - those transfers. For a low or full speed bus (loosely, "USB 1.1"), 154 - 90% of the bus bandwidth is reserved. For a high speed bus (loosely, 155 - "USB 2.0") 80% is reserved. 156 - 157 - 158 - Device descriptor info & Product ID info: 159 - 160 - D: Ver=x.xx Cls=xx(s) Sub=xx Prot=xx MxPS=dd #Cfgs=dd 161 - P: Vendor=xxxx ProdID=xxxx Rev=xx.xx 162 - 163 - where 164 - D: Ver=x.xx Cls=xx(sssss) Sub=xx Prot=xx MxPS=dd #Cfgs=dd 165 - | | | | | | |__NumberConfigurations 166 - | | | | | |__MaxPacketSize of Default Endpoint 167 - | | | | |__DeviceProtocol 168 - | | | |__DeviceSubClass 169 - | | |__DeviceClass 170 - | |__Device USB version 171 - |__Device info tag #1 172 - 173 - where 174 - P: Vendor=xxxx ProdID=xxxx Rev=xx.xx 175 - | | | |__Product revision number 176 - | | |__Product ID code 177 - | |__Vendor ID code 178 - |__Device info tag #2 179 - 180 - 181 - String descriptor info: 182 - 183 - S: Manufacturer=ssss 184 - | |__Manufacturer of this device as read from the device. 185 - | For USB host controller drivers (virtual root hubs) this may 186 - | be omitted, or (for newer drivers) will identify the kernel 187 - | version and the driver which provides this hub emulation. 188 - |__String info tag 189 - 190 - S: Product=ssss 191 - | |__Product description of this device as read from the device. 192 - | For older USB host controller drivers (virtual root hubs) this 193 - | indicates the driver; for newer ones, it's a product (and vendor) 194 - | description that often comes from the kernel's PCI ID database. 195 - |__String info tag 196 - 197 - S: SerialNumber=ssss 198 - | |__Serial Number of this device as read from the device. 199 - | For USB host controller drivers (virtual root hubs) this is 200 - | some unique ID, normally a bus ID (address or slot name) that 201 - | can't be shared with any other device. 202 - |__String info tag 203 - 204 - 205 - 206 - Configuration descriptor info: 207 - 208 - C:* #Ifs=dd Cfg#=dd Atr=xx MPwr=dddmA 209 - | | | | | |__MaxPower in mA 210 - | | | | |__Attributes 211 - | | | |__ConfiguratioNumber 212 - | | |__NumberOfInterfaces 213 - | |__ "*" indicates the active configuration (others are " ") 214 - |__Config info tag 215 - 216 - USB devices may have multiple configurations, each of which act 217 - rather differently. For example, a bus-powered configuration 218 - might be much less capable than one that is self-powered. Only 219 - one device configuration can be active at a time; most devices 220 - have only one configuration. 221 - 222 - Each configuration consists of one or more interfaces. Each 223 - interface serves a distinct "function", which is typically bound 224 - to a different USB device driver. One common example is a USB 225 - speaker with an audio interface for playback, and a HID interface 226 - for use with software volume control. 227 - 228 - 229 - Interface descriptor info (can be multiple per Config): 230 - 231 - I:* If#=dd Alt=dd #EPs=dd Cls=xx(sssss) Sub=xx Prot=xx Driver=ssss 232 - | | | | | | | | |__Driver name 233 - | | | | | | | | or "(none)" 234 - | | | | | | | |__InterfaceProtocol 235 - | | | | | | |__InterfaceSubClass 236 - | | | | | |__InterfaceClass 237 - | | | | |__NumberOfEndpoints 238 - | | | |__AlternateSettingNumber 239 - | | |__InterfaceNumber 240 - | |__ "*" indicates the active altsetting (others are " ") 241 - |__Interface info tag 242 - 243 - A given interface may have one or more "alternate" settings. 244 - For example, default settings may not use more than a small 245 - amount of periodic bandwidth. To use significant fractions 246 - of bus bandwidth, drivers must select a non-default altsetting. 247 - 248 - Only one setting for an interface may be active at a time, and 249 - only one driver may bind to an interface at a time. Most devices 250 - have only one alternate setting per interface. 251 - 252 - 253 - Endpoint descriptor info (can be multiple per Interface): 254 - 255 - E: Ad=xx(s) Atr=xx(ssss) MxPS=dddd Ivl=dddss 256 - | | | | |__Interval (max) between transfers 257 - | | | |__EndpointMaxPacketSize 258 - | | |__Attributes(EndpointType) 259 - | |__EndpointAddress(I=In,O=Out) 260 - |__Endpoint info tag 261 - 262 - The interval is nonzero for all periodic (interrupt or isochronous) 263 - endpoints. For high speed endpoints the transfer interval may be 264 - measured in microseconds rather than milliseconds. 265 - 266 - For high speed periodic endpoints, the "MaxPacketSize" reflects 267 - the per-microframe data transfer size. For "high bandwidth" 268 - endpoints, that can reflect two or three packets (for up to 269 - 3KBytes every 125 usec) per endpoint. 270 - 271 - With the Linux-USB stack, periodic bandwidth reservations use the 272 - transfer intervals and sizes provided by URBs, which can be less 273 - than those found in endpoint descriptor. 274 - 275 - 276 - ======================================================================= 277 - 278 - 279 - If a user or script is interested only in Topology info, for 280 - example, use something like "grep ^T: /sys/kernel/debug/usb/devices" 281 - for only the Topology lines. A command like 282 - "grep -i ^[tdp]: /sys/kernel/debug/usb/devices" can be used to list 283 - only the lines that begin with the characters in square brackets, 284 - where the valid characters are TDPCIE. With a slightly more able 285 - script, it can display any selected lines (for example, only T, D, 286 - and P lines) and change their output format. (The "procusb" 287 - Perl script is the beginning of this idea. It will list only 288 - selected lines [selected from TBDPSCIE] or "All" lines from 289 - /sys/kernel/debug/usb/devices.) 290 - 291 - The Topology lines can be used to generate a graphic/pictorial 292 - of the USB devices on a system's root hub. (See more below 293 - on how to do this.) 294 - 295 - The Interface lines can be used to determine what driver is 296 - being used for each device, and which altsetting it activated. 297 - 298 - The Configuration lines could be used to list maximum power 299 - (in milliamps) that a system's USB devices are using. 300 - For example, "grep ^C: /sys/kernel/debug/usb/devices". 301 - 302 - 303 - Here's an example, from a system which has a UHCI root hub, 304 - an external hub connected to the root hub, and a mouse and 305 - a serial converter connected to the external hub. 306 - 307 - T: Bus=00 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2 308 - B: Alloc= 28/900 us ( 3%), #Int= 2, #Iso= 0 309 - D: Ver= 1.00 Cls=09(hub ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 310 - P: Vendor=0000 ProdID=0000 Rev= 0.00 311 - S: Product=USB UHCI Root Hub 312 - S: SerialNumber=dce0 313 - C:* #Ifs= 1 Cfg#= 1 Atr=40 MxPwr= 0mA 314 - I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub 315 - E: Ad=81(I) Atr=03(Int.) MxPS= 8 Ivl=255ms 316 - 317 - T: Bus=00 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=12 MxCh= 4 318 - D: Ver= 1.00 Cls=09(hub ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 319 - P: Vendor=0451 ProdID=1446 Rev= 1.00 320 - C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=100mA 321 - I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub 322 - E: Ad=81(I) Atr=03(Int.) MxPS= 1 Ivl=255ms 323 - 324 - T: Bus=00 Lev=02 Prnt=02 Port=00 Cnt=01 Dev#= 3 Spd=1.5 MxCh= 0 325 - D: Ver= 1.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 326 - P: Vendor=04b4 ProdID=0001 Rev= 0.00 327 - C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=100mA 328 - I: If#= 0 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=01 Prot=02 Driver=mouse 329 - E: Ad=81(I) Atr=03(Int.) MxPS= 3 Ivl= 10ms 330 - 331 - T: Bus=00 Lev=02 Prnt=02 Port=02 Cnt=02 Dev#= 4 Spd=12 MxCh= 0 332 - D: Ver= 1.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 333 - P: Vendor=0565 ProdID=0001 Rev= 1.08 334 - S: Manufacturer=Peracom Networks, Inc. 335 - S: Product=Peracom USB to Serial Converter 336 - C:* #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr=100mA 337 - I: If#= 0 Alt= 0 #EPs= 3 Cls=00(>ifc ) Sub=00 Prot=00 Driver=serial 338 - E: Ad=81(I) Atr=02(Bulk) MxPS= 64 Ivl= 16ms 339 - E: Ad=01(O) Atr=02(Bulk) MxPS= 16 Ivl= 16ms 340 - E: Ad=82(I) Atr=03(Int.) MxPS= 8 Ivl= 8ms 341 - 342 - 343 - Selecting only the "T:" and "I:" lines from this (for example, by using 344 - "procusb ti"), we have: 345 - 346 - T: Bus=00 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2 347 - T: Bus=00 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=12 MxCh= 4 348 - I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub 349 - T: Bus=00 Lev=02 Prnt=02 Port=00 Cnt=01 Dev#= 3 Spd=1.5 MxCh= 0 350 - I: If#= 0 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=01 Prot=02 Driver=mouse 351 - T: Bus=00 Lev=02 Prnt=02 Port=02 Cnt=02 Dev#= 4 Spd=12 MxCh= 0 352 - I: If#= 0 Alt= 0 #EPs= 3 Cls=00(>ifc ) Sub=00 Prot=00 Driver=serial 353 - 354 - 355 - Physically this looks like (or could be converted to): 356 - 357 - +------------------+ 358 - | PC/root_hub (12)| Dev# = 1 359 - +------------------+ (nn) is Mbps. 360 - Level 0 | CN.0 | CN.1 | [CN = connector/port #] 361 - +------------------+ 362 - / 363 - / 364 - +-----------------------+ 365 - Level 1 | Dev#2: 4-port hub (12)| 366 - +-----------------------+ 367 - |CN.0 |CN.1 |CN.2 |CN.3 | 368 - +-----------------------+ 369 - \ \____________________ 370 - \_____ \ 371 - \ \ 372 - +--------------------+ +--------------------+ 373 - Level 2 | Dev# 3: mouse (1.5)| | Dev# 4: serial (12)| 374 - +--------------------+ +--------------------+ 375 - 376 - 377 - 378 - Or, in a more tree-like structure (ports [Connectors] without 379 - connections could be omitted): 380 - 381 - PC: Dev# 1, root hub, 2 ports, 12 Mbps 382 - |_ CN.0: Dev# 2, hub, 4 ports, 12 Mbps 383 - |_ CN.0: Dev #3, mouse, 1.5 Mbps 384 - |_ CN.1: 385 - |_ CN.2: Dev #4, serial, 12 Mbps 386 - |_ CN.3: 387 - |_ CN.1: 388 - 389 - 390 - ### END ###