1.\" $OpenBSD: usb.4,v 1.186 2017/10/30 15:49:10 patrick Exp $ 2.\" $NetBSD: usb.4,v 1.15 1999/07/29 14:20:32 augustss Exp $ 3.\" 4.\" Copyright (c) 1999 The NetBSD Foundation, Inc. 5.\" All rights reserved. 6.\" 7.\" This code is derived from software contributed to The NetBSD Foundation 8.\" by Lennart Augustsson. 9.\" 10.\" Redistribution and use in source and binary forms, with or without 11.\" modification, are permitted provided that the following conditions 12.\" are met: 13.\" 1. Redistributions of source code must retain the above copyright 14.\" notice, this list of conditions and the following disclaimer. 15.\" 2. Redistributions in binary form must reproduce the above copyright 16.\" notice, this list of conditions and the following disclaimer in the 17.\" documentation and/or other materials provided with the distribution. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29.\" POSSIBILITY OF SUCH DAMAGE. 30.\" 31.Dd $Mdocdate: October 30 2017 $ 32.Dt USB 4 33.Os 34.Sh NAME 35.Nm usb , 36.Nm uhub 37.Nd introduction to Universal Serial Bus support 38.Sh SYNOPSIS 39.Cd "# octeon specific" 40.Cd "dwctwo0 at iobus? irq 56" 41.Cd "# all architectures" 42.Cd "ehci* at cardbus?" 43.Cd "ohci* at cardbus?" 44.Cd "uhci* at cardbus?" 45.Cd "ehci* at pci?" 46.Cd "ohci* at pci?" 47.Cd "uhci* at pci?" 48.Cd "xhci* at pci?" 49.Cd "usb* at dwctwo?" 50.Cd "usb* at ehci? flags 0x00" 51.Cd "usb* at ohci? flags 0x00" 52.Cd "usb* at uhci? flags 0x00" 53.Cd "usb* at xhci? flags 0x00" 54.Cd "uhub* at usb?" 55.Cd "uhub* at uhub?" 56.Pp 57.Cd option USBVERBOSE 58.Pp 59.In dev/usb/usb.h 60.In dev/usb/usbhid.h 61.Sh DESCRIPTION 62.Ox 63provides machine-independent bus support and drivers for Universal 64Serial Bus (USB) devices. 65.Pp 66The 67.Ox 68.Nm 69driver has three layers (like 70.Xr scsi 4 71and 72.Xr pcmcia 4 ) : 73the controller, the bus, and the device layer. 74The controller attaches to a physical bus (like 75.Xr pci 4 76or 77.Xr cardbus 4 ) . 78The USB bus attaches to the controller and the root hub attaches 79to the USB bus. 80Devices, which may include further hubs, attach to the root hub. 81The attachment forms the same tree structure as the physical USB 82device tree. 83For each USB device there may be additional drivers attached to it. 84.Pp 85The 86.Cm uhub 87driver controls USB hubs and must always be present since there is 88at least one root hub in any USB system. 89.Pp 90The 91.Cm flags 92are used to specify if the devices on the USB bus should be probed 93early in the boot process. 94If the 95.Cm flags 96are specified with a value of 1, the USB bus will be probed when 97the USB host device is attached instead of waiting until kernel 98processes start running. 99.Pp 100.Ox 101provides support for the following devices. 102Note that not all architectures support all devices. 103.Ss Storage devices 104.Bl -tag -width 12n -offset ind -compact 105.It Xr umass 4 106USB Mass Storage Devices, e.g., external disk drives 107.El 108.Ss Wired network interfaces 109.Bl -tag -width 12n -offset ind -compact 110.It Xr aue 4 111ADMtek AN986/ADM8511 Pegasus family 10/100 USB Ethernet device 112.It Xr axe 4 113ASIX Electronics AX88172/AX88178/AX88772 10/100/Gigabit USB Ethernet device 114.It Xr axen 4 115ASIX Electronics AX88179 10/100/Gigabit USB Ethernet device 116.It Xr cdce 4 117USB Communication Device Class Ethernet device 118.It Xr cue 4 119CATC USB-EL1201A USB Ethernet device 120.It Xr kue 4 121Kawasaki LSI KL5KUSB101B USB Ethernet device 122.It Xr mos 4 123MosChip MCS7730/7830/7832 10/100 USB Ethernet device 124.It Xr smsc 4 125SMSC LAN95xx 10/100 USB Ethernet device 126.It Xr udav 4 127Davicom DM9601 10/100 USB Ethernet device 128.It Xr ure 4 129RealTek RTL8152/RTL8153 10/100/Gigabit USB Ethernet device 130.It Xr url 4 131Realtek RTL8150L 10/100 USB Ethernet device 132.It Xr urndis 4 133USB Remote NDIS Ethernet device 134.El 135.Ss Wireless network interfaces 136.Bl -tag -width 12n -offset ind -compact 137.It Xr athn 4 138Atheros IEEE 802.11a/b/g/n wireless network device 139.It Xr atu 4 140Atmel AT76C50x IEEE 802.11b wireless network device 141.It Xr bwfm 4 142Broadcom and Cypress wireless network device 143.It Xr otus 4 144Atheros USB IEEE 802.11a/b/g/n wireless network device 145.It Xr rsu 4 146Realtek RTL8188SU/RTL8192SU USB IEEE 802.11b/g/n wireless network device 147.It Xr rum 4 148Ralink Technology/MediaTek USB IEEE 802.11a/b/g wireless network device 149.It Xr run 4 150Ralink Technology/MediaTek USB IEEE 802.11a/b/g/n wireless network device 151.It Xr uath 4 152Atheros USB IEEE 802.11a/b/g wireless network device 153.It Xr upgt 4 154Conexant/Intersil PrismGT SoftMAC USB IEEE 802.11b/g wireless network device 155.It Xr ural 4 156Ralink Technology/MediaTek USB IEEE 802.11b/g wireless network device 157.It Xr urtw 4 158Realtek RTL8187L/RTL8187B USB IEEE 802.11b/g wireless network device 159.It Xr urtwn 4 160Realtek RTL8188CU/RTL8188EU/RTL8192CU USB IEEE 802.11b/g/n wireless network device 161.It Xr wi 4 162Intersil PRISM 2-3 IEEE 802.11b wireless network device 163.It Xr zyd 4 164ZyDAS ZD1211/ZD1211B USB IEEE 802.11b/g wireless network device 165.El 166.Ss Serial and parallel interfaces 167.Bl -tag -width 12n -offset ind -compact 168.It Xr moscom 4 169MosChip Semiconductor MCS7703 based USB serial adapter 170.It Xr uark 4 171Arkmicro Technologies ARK3116 based USB serial adapter 172.It Xr ubsa 4 173Belkin USB serial adapter 174.It Xr uchcom 4 175WinChipHead CH341/340 based USB serial adapter 176.It Xr ucom 4 177USB tty support 178.It Xr ucycom 4 179Cypress microcontroller based USB serial adapter 180.It Xr uftdi 4 181FTDI USB serial adapter 182.It Xr uipaq 4 183iPAQ USB units 184.It Xr ulpt 4 185USB printer support 186.It Xr umcs 4 187MosChip Semiconductor based USB multiport serial adapter 188.It Xr umct 4 189MCT USB-RS232 USB serial adapter 190.It Xr umodem 4 191USB modem support 192.It Xr umsm 4 193Qualcomm MSM modem device 194.It Xr uplcom 4 195Prolific PL-2303 USB serial adapter 196.It Xr uscom 4 197simple USB serial adapters 198.It Xr uslcom 4 199Silicon Laboratories CP210x based USB serial adapter 200.It Xr uslhcom 4 201Silicon Laboratories CP2110 based USB serial adapter 202.It Xr uticom 4 203Texas Instruments TUSB3410 USB serial adapter 204.It Xr uvisor 4 205USB Handspring Visor 206.It Xr uvscom 4 207SUNTAC Slipper U VS-10U USB serial adapter 208.El 209.Ss Audio devices 210.Bl -tag -width 12n -offset ind -compact 211.It Xr uaudio 4 212USB audio devices 213.It Xr umidi 4 214USB MIDI devices 215.El 216.Ss Video devices 217.Bl -tag -width 12n -offset ind -compact 218.It Xr udl 4 219DisplayLink DL-120 / DL-160 USB display devices 220.It Xr utvfu 4 221USB Fushicai USBTV007 audio/video capture device 222.It Xr uvideo 4 223USB video devices 224.El 225.Ss Time receiver devices 226.Bl -tag -width 12n -offset ind -compact 227.It Xr udcf 4 228Gude ADS Expert mouseCLOCK USB timedelta sensor 229.It Xr umbg 4 230Meinberg Funkuhren USB5131 timedelta sensor 231.El 232.Ss Radio receiver devices 233.Bl -tag -width 12n -offset ind -compact 234.It Xr udsbr 4 235D-Link DSB-R100 USB radio device 236.El 237.Ss Human Interface Devices 238.Bl -tag -width 12n -offset ind -compact 239.It Xr ubcmtp 4 240Broadcom trackpad mouse 241.It Xr uhid 4 242Generic driver for Human Interface Devices 243.It Xr uhidev 4 244Base driver for all Human Interface Devices 245.It Xr ukbd 4 246USB keyboards that follow the boot protocol 247.It Xr ums 4 248USB HID mouse, touchscreen and digitiser devices 249.It Xr uoaklux 4 250Toradex OAK USB illuminance sensor 251.It Xr uoakrh 4 252Toradex OAK USB temperature and relative humidity sensor 253.It Xr uoakv 4 254Toradex OAK USB +/-10V 8channel ADC interface 255.It Xr upd 4 256USB Power Devices sensor 257.It Xr uthum 4 258TEMPer HID thermometer and hygrometer 259.It Xr utpms 4 260Apple touchpad mouse 261.It Xr utrh 4 262USBRH temperature and humidity sensor 263.It Xr utwitch 4 264YUREX USB twitch/jiggle of knee sensor 265.It Xr uwacom 4 266Wacom USB tablets 267.El 268.Ss WAN network devices 269.Bl -tag -width 12n -offset ind -compact 270.It Xr umb 4 271USB Mobile Broadband Interface Model (MBIM) 272.El 273.Ss Miscellaneous devices 274.Bl -tag -width 12n -offset ind -compact 275.It Xr uberry 4 276Research In Motion BlackBerry 277.It Xr ugen 4 278USB generic device support 279.It Xr ugl 4 280Genesys Logic based host-to-host adapters 281.It Xr ugold 4 282TEMPer gold HID thermometer and hygrometer 283.It Xr uonerng 4 284Moonbase Otago OneRNG TRNG 285.It Xr uow 4 286Maxim/Dallas DS2490 USB 1-Wire adapter 287.It Xr upl 4 288Prolific based host-to-host adapters 289.It Xr urng 4 290USB Random Number Generator devices 291.It Xr usps 4 292USPS composite AC power and temperature sensor 293.It Xr uts 4 294USB touchscreen support 295.El 296.Sh INTRODUCTION TO USB 297There are different versions of the USB 298which provide different speeds. 299USB 3 can operate up to 5.0Gb/s. 300USB 2 operates at 480Mb/s, while USB versions 1 and 1.1 operate at 30112 Mb/s and 1.5 Mb/s for low speed devices. 302Each USB has a host controller that is the master of the bus; 303all other devices on the bus only speak when spoken to. 304.Pp 305There can be up to 127 devices (apart from the host controller) 306on a bus, each with its own address. 307The addresses are assigned 308dynamically by the host when each device is attached to the bus. 309.Pp 310Within each device there can be up to 16 endpoints. 311Each endpoint 312is individually addressed and the addresses are static. 313Each of these endpoints will communicate in one of four different modes: 314control, isochronous, bulk, or interrupt. 315A device always has at least one endpoint. 316This is a control endpoint at address 0 317and is used to give commands to the device and extract basic data, 318such as descriptors, from the device. 319Each endpoint, except the control endpoint, is unidirectional. 320.Pp 321The endpoints in a device are grouped into interfaces. 322An interface is a logical unit within a device; e.g., 323a compound device with both a keyboard and a trackball would present 324one interface for each. 325An interface can sometimes be set into different modes, 326called alternate settings, which affects how it operates. 327Different alternate settings can have different endpoints 328within it. 329.Pp 330A device may operate in different configurations. 331Depending on the 332configuration the device may present different sets of endpoints 333and interfaces. 334.Pp 335Each device located on a hub has several 336.Xr config 8 337locators: 338.Pp 339.Bl -tag -width configuration -compact 340.It Cd port 341Number of the port on closest upstream hub. 342.It Cd configuration 343Configuration the device must be in for this driver to attach. 344This locator does not set the configuration; it is iterated by the bus 345enumeration. 346.It Cd interface 347Interface number within a device that an interface driver attaches to. 348.It Cd vendor 34916-bit vendor ID of the device. 350.It Cd product 35116-bit product ID of the device. 352.It Cd release 35316-bit release (revision) number of the device. 354.El 355.Pp 356The first locator can be used to pin down a particular device 357according to its physical position in the device tree. 358The last three locators can be used to pin down a particular 359device according to what device it actually is. 360.Pp 361The bus enumeration of the USB bus proceeds in several steps: 362.Bl -enum 363.It 364Any device-specific driver can attach to the device. 365.It 366If none is found, any device class specific driver can attach. 367.It 368If none is found, all configurations are iterated over. 369For each configuration all the interfaces are iterated over and interface 370drivers can attach. 371If any interface driver attached in a certain 372configuration, the iteration over configurations is stopped. 373.It 374If still no drivers have been found, the generic USB driver can attach. 375.El 376.Sh USB CONTROLLER INTERFACE 377Use the following to get access to the USB specific structures 378and defines: 379.Bd -literal -offset indent 380#include <dev/usb/usb.h> 381.Ed 382.Pp 383The 384.Pa /dev/usbN 385device can be opened and a few operations can be performed on it. 386The 387.Xr poll 2 388system call will say that I/O is possible on the controller device 389when a USB device has been connected or disconnected to the bus. 390.Pp 391The following 392.Xr ioctl 2 393commands are supported on the controller device: 394.Bl -tag -width xxxxxx 395.It Dv USB_DEVICEINFO Fa "struct usb_device_info" 396This command can be used to retrieve some information about a device 397on the bus. 398The 399.Va udi_addr 400field should be filled before the call and the other fields will 401be filled by information about the device on that address. 402Should no such device exist, an error is reported. 403.Bd -literal 404#define USB_MAX_DEVNAMES 4 405#define USB_MAX_DEVNAMELEN 16 406struct usb_device_info { 407 u_int8_t udi_bus; 408 u_int8_t udi_addr; /* device address */ 409 char udi_product[USB_MAX_STRING_LEN]; 410 char udi_vendor[USB_MAX_STRING_LEN]; 411 char udi_release[8]; 412 u_int16_t udi_productNo; 413 u_int16_t udi_vendorNo; 414 u_int16_t udi_releaseNo; 415 u_int8_t udi_class; 416 u_int8_t udi_subclass; 417 u_int8_t udi_protocol; 418 u_int8_t udi_config; 419 u_int8_t udi_speed; 420#define USB_SPEED_LOW 1 421#define USB_SPEED_FULL 2 422#define USB_SPEED_HIGH 3 423 int udi_power; /* power consumption */ 424 int udi_nports; 425 char udi_devnames[USB_MAX_DEVNAMES] 426 [USB_MAX_DEVNAMELEN]; 427 u_int8_t udi_ports[16]; /* hub only */ 428#define USB_PORT_ENABLED 0xff 429#define USB_PORT_SUSPENDED 0xfe 430#define USB_PORT_POWERED 0xfd 431#define USB_PORT_DISABLED 0xfc 432 char udi_serial[USB_MAX_STRING_LEN]; 433}; 434.Ed 435.Pp 436The 437.Va udi_bus 438field contains the device unit number of the device. 439.Pp 440The 441.Va udi_product , 442.Va udi_vendor , 443and 444.Va udi_release 445fields contain self-explanatory descriptions of the device. 446The 447.Va udi_productNo , 448.Va udi_vendorNo , 449and 450.Va udi_releaseNo 451fields contain numeric identifiers for the device. 452.Pp 453The 454.Va udi_class 455and 456.Va udi_subclass 457fields contain the device class and subclass. 458.Pp 459The 460.Va udi_config 461field shows the current configuration of the device. 462.Pp 463The 464.Va udi_protocol 465field contains the device protocol as given from the device. 466.Pp 467The 468.Va udi_speed 469field 470contains the speed of the device. 471.Pp 472The 473.Va udi_power 474field shows the power consumption in milli-amps drawn at 5 volts 475or is zero if the device is self powered. 476.Pp 477The 478.Va udi_devnames 479field contains the names and instance numbers of the device drivers 480for the devices attached to this device. 481.Pp 482If the device is a hub, the 483.Va udi_nports 484field is non-zero and the 485.Va udi_ports 486field contains the addresses of the connected devices. 487If no device is connected to a port, one of the 488.Dv USB_PORT_* 489values indicates its status. 490.It Dv USB_DEVICESTATS Fa "struct usb_device_stats" 491This command retrieves statistics about the controller. 492.Bd -unfilled 493struct usb_device_stats { 494 u_long uds_requests[4]; 495}; 496.Ed 497.Pp 498The 499.Va uds_requests 500field is indexed by the transfer kind, i.e.\& 501.Dv UE_* , 502and indicates how many transfers of each kind have been completed 503by the controller. 504.It Dv USB_DEVICE_GET_DDESC Fa "struct usb_device_ddesc" 505This command can be used to retrieve the device descriptor 506of a device on the bus. 507The 508.Va udd_addr 509field needs to be filled with the bus device address: 510.Bd -literal 511struct usb_device_ddesc { 512 u_int8_t udd_bus; 513 u_int8_t udd_addr; /* device address */ 514 usb_device_descriptor_t udd_desc; 515}; 516.Ed 517.Pp 518The 519.Va udd_bus 520field contains the device unit number. 521.Pp 522The 523.Va udd_desc 524field contains the device descriptor structure. 525.It Dv USB_DEVICE_GET_CDESC Fa "struct usb_device_cdesc" 526This command can be used to retrieve the configuration descriptor for the 527given configuration of a device on the bus. 528The 529.Va udc_addr 530field needs to be filled with the bus device address. 531The 532.Va udc_config_index 533field needs to be filled with the configuration index for the 534relevant configuration descriptor. 535For convenience the current configuration can be specified by 536.Dv USB_CURRENT_CONFIG_INDEX : 537.Bd -literal 538struct usb_device_cdesc { 539 u_int8_t udc_bus; 540 u_int8_t udc_addr; /* device address */ 541 int udc_config_index; 542 usb_config_descriptor_t udc_desc; 543}; 544.Ed 545.Pp 546The 547.Va udc_bus 548field contains the device unit number. 549.Pp 550The 551.Va udc_desc 552field contains the configuration descriptor structure. 553.It Dv USB_DEVICE_GET_FDESC Fa "struct usb_device_fdesc" 554This command can be used to retrieve all descriptors for the 555given configuration of a device on the bus. 556The 557.Va udf_addr 558field needs to be filled with the bus device address. 559The 560.Va udf_config_index 561field needs to be filled with the configuration index for the 562relevant configuration descriptor. 563For convenience the current configuration can be specified by 564.Dv USB_CURRENT_CONFIG_INDEX . 565The 566.Va udf_data 567field needs to point to a memory area of the size given in the 568.Va udf_size 569field. 570The proper size can be determined by first issuing a 571.Dv USB_DEVICE_GET_CDESC 572command and inspecting the 573.Va wTotalLength 574field: 575.Bd -literal 576struct usb_device_fdesc { 577 u_int8_t udf_bus; 578 u_int8_t udf_addr; /* device address */ 579 int udf_config_index; 580 u_int udf_size; 581 u_char *udf_data; 582}; 583.Ed 584.Pp 585The 586.Va udf_bus 587field contains the device unit number. 588.Pp 589The 590.Va udf_data 591field contains all descriptors. 592.It Dv USB_REQUEST Fa "struct usb_ctl_request" 593This command can be used to execute arbitrary requests on the control pipe. 594This is 595.Em DANGEROUS 596and should be used with great care since it 597can destroy the bus integrity. 598.Pp 599The 600.Vt usb_ctl_request 601structure has the following definition: 602.Bd -literal 603typedef struct { 604 uByte bmRequestType; 605 uByte bRequest; 606 uWord wValue; 607 uWord wIndex; 608 uWord wLength; 609} __packed usb_device_request_t; 610 611struct usb_ctl_request { 612 int ucr_addr; 613 usb_device_request_t ucr_request; 614 void *ucr_data; 615 int ucr_flags; 616#define USBD_SHORT_XFER_OK 0x04 /* allow short reads */ 617 int ucr_actlen; /* actual length transferred */ 618}; 619.Ed 620.Pp 621The 622.Va ucr_addr 623field identifies the device on which to perform the request. 624The 625.Va ucr_request 626field identifies parameters of the request, such as length and type. 627The 628.Va ucr_data 629field contains the location where data will be read from or written to. 630The 631.Va ucr_flags 632field specifies options for the request, and the 633.Va ucr_actlen 634field contains the actual length transferred as the result of the request. 635.El 636.Pp 637The include file 638.In dev/usb/usb.h 639contains definitions for the types used by the various 640.Xr ioctl 2 641calls. 642The naming convention of the fields for the various USB descriptors 643exactly follows the naming in the USB specification. 644Byte sized fields can be accessed directly, but word (16-bit) 645sized fields must be accessed by the 646.Fn UGETW field 647and 648.Fn USETW field value 649macros and double word (32-bit) sized fields must be accessed by the 650.Fn UGETDW field 651and 652.Fn USETDW field value 653macros to handle byte order and alignment properly. 654.Pp 655The include file 656.In dev/usb/usbhid.h 657similarly contains the definitions for 658Human Interface Devices (HID). 659.Sh SEE ALSO 660.Xr usbhidaction 1 , 661.Xr usbhidctl 1 , 662.Xr ioctl 2 , 663.Xr dwctwo 4 , 664.Xr ehci 4 , 665.Xr ohci 4 , 666.Xr uhci 4 , 667.Xr xhci 4 , 668.Xr config 8 , 669.Xr usbdevs 8 670.Pp 671The USB specifications can be found at 672.Lk http://www.usb.org/developers/docs/ 673.Sh HISTORY 674The 675.Nm 676driver 677appeared in 678.Ox 2.6 . 679