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