xref: /openbsd/share/man/man4/usb.4 (revision 73471bf0)
1.\"	$OpenBSD: usb.4,v 1.211 2021/09/08 20:29:21 jmc 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: September 8 2021 $
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/1Gb USB Ethernet device
114.It Xr axen 4
115ASIX Electronics AX88179 10/100/1Gb 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 mue 4
125Microchip LAN75xx/LAN78xx 10/100/1Gb USB Ethernet device
126.It Xr smsc 4
127SMSC LAN95xx 10/100 USB Ethernet device
128.It Xr uaq 4
129Aquantia AQC111U/AQC112U 100/1Gb/2.5Gb/5Gb USB Ethernet device
130.It Xr udav 4
131Davicom DM9601 10/100 USB Ethernet device
132.It Xr ure 4
133Realtek RTL8152/RTL8153/RTL8153B/RTL8156 10/100/1Gb/2.5Gb USB Ethernet device
134.It Xr url 4
135Realtek RTL8150L 10/100 USB Ethernet device
136.It Xr urndis 4
137USB Remote NDIS Ethernet device
138.El
139.Ss Wireless network interfaces
140.Bl -tag -width 12n -offset ind -compact
141.It Xr athn 4
142Atheros IEEE 802.11a/b/g/n wireless network device
143.It Xr atu 4
144Atmel AT76C50x IEEE 802.11b wireless network device
145.It Xr bwfm 4
146Broadcom and Cypress IEEE 802.11a/ac/b/g/n wireless network device
147.It Xr otus 4
148Atheros USB IEEE 802.11a/b/g/n wireless network device
149.It Xr rsu 4
150Realtek RTL8188SU/RTL8192SU USB IEEE 802.11b/g/n wireless network device
151.It Xr rum 4
152Ralink Technology/MediaTek USB IEEE 802.11a/b/g wireless network device
153.It Xr run 4
154Ralink Technology/MediaTek USB IEEE 802.11a/b/g/n wireless network device
155.It Xr uath 4
156Atheros USB IEEE 802.11a/b/g wireless network device
157.It Xr upgt 4
158Conexant/Intersil PrismGT SoftMAC USB IEEE 802.11b/g wireless network device
159.It Xr ural 4
160Ralink Technology/MediaTek USB IEEE 802.11b/g wireless network device
161.It Xr urtw 4
162Realtek RTL8187L/RTL8187B USB IEEE 802.11b/g wireless network device
163.It Xr urtwn 4
164Realtek RTL8188CU/RTL8188EU/RTL8192CU/RTL8192EU USB IEEE 802.11b/g/n wireless
165network device
166.It Xr wi 4
167Intersil PRISM 2-3 IEEE 802.11b wireless network device
168.It Xr zyd 4
169ZyDAS ZD1211/ZD1211B USB IEEE 802.11b/g wireless network device
170.El
171.Ss Serial and parallel interfaces
172.Bl -tag -width 12n -offset ind -compact
173.It Xr moscom 4
174MosChip Semiconductor MCS7703 based USB serial adapter
175.It Xr uark 4
176Arkmicro Technologies ARK3116 based USB serial adapter
177.It Xr ubsa 4
178Belkin USB serial adapter
179.It Xr uchcom 4
180WinChipHead CH341/340 based USB serial adapter
181.It Xr ucom 4
182USB tty support
183.It Xr ucrcom 4
184Chromebook USB serial console
185.It Xr ucycom 4
186Cypress microcontroller based USB serial adapter
187.It Xr uftdi 4
188FTDI USB serial adapter
189.It Xr uipaq 4
190iPAQ USB units
191.It Xr ukspan 4
192Keyspan USB serial adapter
193.It Xr ulpt 4
194USB printer support
195.It Xr umcs 4
196MosChip Semiconductor based USB multiport serial adapter
197.It Xr umct 4
198MCT USB-RS232 USB serial adapter
199.It Xr umodem 4
200USB modem support
201.It Xr umsm 4
202Qualcomm MSM modem device
203.It Xr uplcom 4
204Prolific PL-2303 USB serial adapter
205.It Xr uscom 4
206simple USB serial adapters
207.It Xr uslcom 4
208Silicon Laboratories CP210x based USB serial adapter
209.It Xr uslhcom 4
210Silicon Laboratories CP2110 based USB serial adapter
211.It Xr uticom 4
212Texas Instruments TUSB3410 USB serial adapter
213.It Xr uvisor 4
214USB Handspring Visor
215.It Xr uvscom 4
216SUNTAC Slipper U VS-10U USB serial adapter
217.It Xr uxrcom 4
218Exar XR21V1410 USB serial adapter
219.El
220.Ss Audio devices
221.Bl -tag -width 12n -offset ind -compact
222.It Xr uaudio 4
223USB audio devices
224.It Xr umidi 4
225USB MIDI devices
226.El
227.Ss Video devices
228.Bl -tag -width 12n -offset ind -compact
229.It Xr udl 4
230DisplayLink DL-120 / DL-160 USB display devices
231.It Xr utvfu 4
232USB Fushicai USBTV007 audio/video capture device
233.It Xr uvideo 4
234USB video devices
235.El
236.Ss Time receiver devices
237.Bl -tag -width 12n -offset ind -compact
238.It Xr udcf 4
239Gude ADS Expert mouseCLOCK USB timedelta sensor
240.It Xr umbg 4
241Meinberg Funkuhren USB5131 timedelta sensor
242.El
243.Ss Radio receiver devices
244.Bl -tag -width 12n -offset ind -compact
245.It Xr udsbr 4
246D-Link DSB-R100 USB radio device
247.El
248.Ss Human Interface Devices
249.Bl -tag -width 12n -offset ind -compact
250.It Xr fido 4
251FIDO/U2F security keys
252.It Xr ubcmtp 4
253Broadcom trackpad mouse
254.It Xr ucc 4
255Consumer Control keyboards
256.It Xr ugold 4
257TEMPer gold HID thermometer and hygrometer
258.It Xr uhid 4
259Generic driver for Human Interface Devices
260.It Xr uhidev 4
261Base driver for all Human Interface Devices
262.It Xr uhidpp 4
263Logitech HID++ devices
264.It Xr ujoy 4
265USB joysticks/gamecontrollers
266.It Xr ukbd 4
267USB keyboards that follow the boot protocol
268.It Xr ums 4
269USB HID mouse, touchscreen and digitiser devices
270.It Xr umstc 4
271Microsoft Surface Type Cover keyboard
272.It Xr umt 4
273USB HID multitouch touchpad devices
274.It Xr uoaklux 4
275Toradex OAK USB illuminance sensor
276.It Xr uoakrh 4
277Toradex OAK USB temperature and relative humidity sensor
278.It Xr uoakv 4
279Toradex OAK USB +/-10V 8channel ADC interface
280.It Xr upd 4
281USB Power Devices sensor
282.It Xr uthum 4
283TEMPer HID thermometer and hygrometer
284.It Xr utpms 4
285Apple touchpad mouse
286.It Xr utrh 4
287USBRH temperature and humidity sensor
288.It Xr utwitch 4
289YUREX USB twitch/jiggle of knee sensor
290.It Xr uwacom 4
291Wacom USB tablets
292.El
293.Ss WAN network devices
294.Bl -tag -width 12n -offset ind -compact
295.It Xr umb 4
296USB Mobile Broadband Interface Model (MBIM)
297.El
298.Ss Miscellaneous devices
299.Bl -tag -width 12n -offset ind -compact
300.It Xr uberry 4
301Research In Motion BlackBerry
302.It Xr ugen 4
303USB generic device support
304.It Xr ugl 4
305Genesys Logic based host-to-host adapters
306.It Xr uonerng 4
307Moonbase Otago OneRNG TRNG
308.It Xr uow 4
309Maxim/Dallas DS2490 USB 1-Wire adapter
310.It Xr upl 4
311Prolific based host-to-host adapters
312.It Xr urng 4
313USB Random Number Generator devices
314.It Xr usps 4
315USPS composite AC power and temperature sensor
316.It Xr uts 4
317USB touchscreen support
318.El
319.Sh INTRODUCTION TO USB
320There are different versions of the USB
321which provide different speeds.
322USB 3 can operate up to 5.0Gb/s.
323USB 2 operates at 480Mb/s, while USB versions 1 and 1.1 operate at
32412 Mb/s and 1.5 Mb/s for low speed devices.
325Each USB has a host controller that is the master of the bus;
326all other devices on the bus only speak when spoken to.
327.Pp
328There can be up to 127 devices (apart from the host controller)
329on a bus, each with its own address.
330The addresses are assigned
331dynamically by the host when each device is attached to the bus.
332.Pp
333Within each device there can be up to 16 endpoints.
334Each endpoint
335is individually addressed and the addresses are static.
336Each of these endpoints will communicate in one of four different modes:
337control, isochronous, bulk, or interrupt.
338A device always has at least one endpoint.
339This is a control endpoint at address 0
340and is used to give commands to the device and extract basic data,
341such as descriptors, from the device.
342Each endpoint, except the control endpoint, is unidirectional.
343.Pp
344The endpoints in a device are grouped into interfaces.
345An interface is a logical unit within a device; e.g.,
346a compound device with both a keyboard and a trackball would present
347one interface for each.
348An interface can sometimes be set into different modes,
349called alternate settings, which affects how it operates.
350Different alternate settings can have different endpoints
351within it.
352.Pp
353A device may operate in different configurations.
354Depending on the
355configuration the device may present different sets of endpoints
356and interfaces.
357.Pp
358Each device located on a hub has several
359.Xr config 8
360locators:
361.Pp
362.Bl -tag -width configuration -compact
363.It Cd port
364Number of the port on closest upstream hub.
365.It Cd configuration
366Configuration the device must be in for this driver to attach.
367This locator does not set the configuration; it is iterated by the bus
368enumeration.
369.It Cd interface
370Interface number within a device that an interface driver attaches to.
371.It Cd vendor
37216-bit vendor ID of the device.
373.It Cd product
37416-bit product ID of the device.
375.It Cd release
37616-bit release (revision) number of the device.
377.El
378.Pp
379The first locator can be used to pin down a particular device
380according to its physical position in the device tree.
381The last three locators can be used to pin down a particular
382device according to what device it actually is.
383.Pp
384The bus enumeration of the USB bus proceeds in several steps:
385.Bl -enum
386.It
387Any device-specific driver can attach to the device.
388.It
389If none is found, any device class specific driver can attach.
390.It
391If none is found, all configurations are iterated over.
392For each configuration all the interfaces are iterated over and interface
393drivers can attach.
394If any interface driver attached in a certain
395configuration, the iteration over configurations is stopped.
396.It
397If still no drivers have been found, the generic USB driver can attach.
398.El
399.Sh USB CONTROLLER INTERFACE
400Use the following to get access to the USB specific structures
401and defines:
402.Bd -literal -offset indent
403#include <dev/usb/usb.h>
404.Ed
405.Pp
406The
407.Pa /dev/usbN
408device can be opened and a few operations can be performed on it.
409The following
410.Xr ioctl 2
411commands are supported on the controller device:
412.Bl -tag -width xxxxxx
413.It Dv USB_DEVICEINFO Fa "struct usb_device_info"
414This command can be used to retrieve some information about a device
415on the bus.
416The
417.Va udi_addr
418field should be filled before the call and the other fields will
419be filled by information about the device on that address.
420Should no such device exist, an error is reported.
421.Bd -literal
422#define USB_MAX_DEVNAMES 4
423#define USB_MAX_DEVNAMELEN 16
424struct usb_device_info {
425	u_int8_t	udi_bus;
426	u_int8_t	udi_addr;	/* device address */
427	char		udi_product[USB_MAX_STRING_LEN];
428	char		udi_vendor[USB_MAX_STRING_LEN];
429	char		udi_release[8];
430	u_int16_t	udi_productNo;
431	u_int16_t	udi_vendorNo;
432	u_int16_t	udi_releaseNo;
433	u_int8_t	udi_class;
434	u_int8_t	udi_subclass;
435	u_int8_t	udi_protocol;
436	u_int8_t	udi_config;
437	u_int8_t	udi_speed;
438#define USB_SPEED_LOW	1
439#define USB_SPEED_FULL	2
440#define USB_SPEED_HIGH	3
441#define USB_SPEED_SUPER	4
442	u_int8_t	udi_port;
443	int		udi_power;	/* power consumption */
444	int		udi_nports;
445	char		udi_devnames[USB_MAX_DEVNAMES]
446			    [USB_MAX_DEVNAMELEN];
447	u_int32_t	udi_ports[16];	/* hub only */
448	char		udi_serial[USB_MAX_STRING_LEN];
449};
450.Ed
451.Pp
452The
453.Va udi_bus
454field contains the device unit number of the device.
455.Pp
456The
457.Va udi_product ,
458.Va udi_vendor ,
459and
460.Va udi_release
461fields contain self-explanatory descriptions of the device.
462The
463.Va udi_productNo ,
464.Va udi_vendorNo ,
465and
466.Va udi_releaseNo
467fields contain numeric identifiers for the device.
468.Pp
469The
470.Va udi_class
471and
472.Va udi_subclass
473fields contain the device class and subclass.
474.Pp
475The
476.Va udi_config
477field shows the current configuration of the device.
478.Pp
479The
480.Va udi_protocol
481field contains the device protocol as given from the device.
482.Pp
483The
484.Va udi_speed
485field
486contains the speed of the device.
487.Pp
488The
489.Va udi_power
490field shows the power consumption in milli-amps drawn at 5 volts
491or is zero if the device is self powered.
492.Pp
493The
494.Va udi_devnames
495field contains the names and instance numbers of the device drivers
496for the devices attached to this device.
497.Pp
498If the device is a hub, the
499.Va udi_nports
500field is non-zero and the
501.Va udi_ports
502field contains the addresses of the connected devices.
503If no device is connected to a port, one of the
504.Dv USB_PORT_*
505values indicates its status.
506.It Dv USB_DEVICESTATS Fa "struct usb_device_stats"
507This command retrieves statistics about the controller.
508.Bd -unfilled
509struct usb_device_stats {
510	u_long	uds_requests[4];
511};
512.Ed
513.Pp
514The
515.Va uds_requests
516field is indexed by the transfer kind, i.e.\&
517.Dv UE_* ,
518and indicates how many transfers of each kind have been completed
519by the controller.
520.It Dv USB_DEVICE_GET_DDESC Fa "struct usb_device_ddesc"
521This command can be used to retrieve the device descriptor
522of a device on the bus.
523The
524.Va udd_addr
525field needs to be filled with the bus device address:
526.Bd -literal
527struct usb_device_ddesc {
528	u_int8_t	udd_bus;
529	u_int8_t	udd_addr;	/* device address */
530	usb_device_descriptor_t udd_desc;
531};
532.Ed
533.Pp
534The
535.Va udd_bus
536field contains the device unit number.
537.Pp
538The
539.Va udd_desc
540field contains the device descriptor structure.
541.It Dv USB_DEVICE_GET_CDESC Fa "struct usb_device_cdesc"
542This command can be used to retrieve the configuration descriptor for the
543given configuration of a device on the bus.
544The
545.Va udc_addr
546field needs to be filled with the bus device address.
547The
548.Va udc_config_index
549field needs to be filled with the configuration index for the
550relevant configuration descriptor.
551For convenience the current configuration can be specified by
552.Dv USB_CURRENT_CONFIG_INDEX :
553.Bd -literal
554struct usb_device_cdesc {
555	u_int8_t	udc_bus;
556	u_int8_t	udc_addr;	/* device address */
557	int		udc_config_index;
558	usb_config_descriptor_t udc_desc;
559};
560.Ed
561.Pp
562The
563.Va udc_bus
564field contains the device unit number.
565.Pp
566The
567.Va udc_desc
568field contains the configuration descriptor structure.
569.It Dv USB_DEVICE_GET_FDESC Fa "struct usb_device_fdesc"
570This command can be used to retrieve all descriptors for the
571given configuration of a device on the bus.
572The
573.Va udf_addr
574field needs to be filled with the bus device address.
575The
576.Va udf_config_index
577field needs to be filled with the configuration index for the
578relevant configuration descriptor.
579For convenience the current configuration can be specified by
580.Dv USB_CURRENT_CONFIG_INDEX .
581The
582.Va udf_data
583field needs to point to a memory area of the size given in the
584.Va udf_size
585field.
586The proper size can be determined by first issuing a
587.Dv USB_DEVICE_GET_CDESC
588command and inspecting the
589.Va wTotalLength
590field:
591.Bd -literal
592struct usb_device_fdesc {
593	u_int8_t	 udf_bus;
594	u_int8_t	 udf_addr;	/* device address */
595	int		 udf_config_index;
596	u_int		 udf_size;
597	u_char		*udf_data;
598};
599.Ed
600.Pp
601The
602.Va udf_bus
603field contains the device unit number.
604.Pp
605The
606.Va udf_data
607field contains all descriptors.
608.It Dv USB_REQUEST Fa "struct usb_ctl_request"
609This command can be used to execute arbitrary requests on the control pipe.
610This is
611.Em DANGEROUS
612and should be used with great care since it
613can destroy the bus integrity.
614.Pp
615The
616.Vt usb_ctl_request
617structure has the following definition:
618.Bd -literal
619typedef struct {
620        uByte           bmRequestType;
621        uByte           bRequest;
622        uWord           wValue;
623        uWord           wIndex;
624        uWord           wLength;
625} __packed usb_device_request_t;
626
627struct usb_ctl_request {
628	int	ucr_addr;
629	usb_device_request_t ucr_request;
630	void	*ucr_data;
631	int	ucr_flags;
632#define USBD_SHORT_XFER_OK 0x04	/* allow short reads */
633	int	ucr_actlen;	/* actual length transferred */
634};
635.Ed
636.Pp
637The
638.Va ucr_addr
639field identifies the device on which to perform the request.
640The
641.Va ucr_request
642field identifies parameters of the request, such as length and type.
643The
644.Va ucr_data
645field contains the location where data will be read from or written to.
646The
647.Va ucr_flags
648field specifies options for the request, and the
649.Va ucr_actlen
650field contains the actual length transferred as the result of the request.
651.El
652.Pp
653The include file
654.In dev/usb/usb.h
655contains definitions for the types used by the various
656.Xr ioctl 2
657calls.
658The naming convention of the fields for the various USB descriptors
659exactly follows the naming in the USB specification.
660Byte sized fields can be accessed directly, but word (16-bit)
661sized fields must be accessed by the
662.Fn UGETW field
663and
664.Fn USETW field value
665macros and double word (32-bit) sized fields must be accessed by the
666.Fn UGETDW field
667and
668.Fn USETDW field value
669macros to handle byte order and alignment properly.
670.Pp
671The include file
672.In dev/usb/usbhid.h
673similarly contains the definitions for
674Human Interface Devices (HID).
675.Sh SEE ALSO
676.Xr usbhidaction 1 ,
677.Xr usbhidctl 1 ,
678.Xr ioctl 2 ,
679.Xr dwctwo 4 ,
680.Xr ehci 4 ,
681.Xr ohci 4 ,
682.Xr uhci 4 ,
683.Xr xhci 4 ,
684.Xr config 8 ,
685.Xr usbdevs 8
686.Pp
687The USB specifications can be found at:
688.Lk https://www.usb.org/documents
689.Sh HISTORY
690The
691.Nm
692driver
693appeared in
694.Ox 2.6 .
695