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