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