* Add in support for the IBM ServeRAID controller.
[dragonfly.git] / share / man / man4 / usb.4
1 .\" Copyright (c) 1997, 1998
2 .\"     Nick Hibma <n_hibma@FreeBSD.org>. All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the author nor the names of any co-contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"   without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY NICK HIBMA AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL NICK HIBMA OR THE VOICES IN HIS HEAD
20 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26 .\" THE POSSIBILITY OF SUCH DAMAGE.
27 .\"
28 .\" $FreeBSD: src/share/man/man4/usb.4,v 1.9.2.10 2002/12/19 20:48:25 trhodes Exp $
29 .\" $DragonFly: src/share/man/man4/usb.4,v 1.2 2003/06/17 04:36:59 dillon Exp $
30 .\"
31 .Dd February 21, 1999
32 .Dt USB 4
33 .Os
34 .Sh NAME
35 .Nm usb
36 .Nd Universal Serial Bus
37 .Sh SYNOPSIS
38 .Cd "device usb"
39 .Pp
40 .In dev/usb/usb.h
41 .In dev/usb/usbhid.h
42 .Sh DESCRIPTION
43 .Fx
44 provides machine-independent bus support and drivers for
45 .Tn USB
46 devices.
47 .Pp
48 The
49 .Nm
50 driver has three layers: the controller, the bus, and the
51 device layer.
52 The controller attaches to a physical bus
53 (like
54 .Xr pci 4 ) .
55 The
56 .Tn USB
57 bus attaches to the controller, and the root hub attaches
58 to the controller.
59 Any devices attached to the bus will attach to the root hub
60 or another hub attached to the
61 .Tn USB
62 bus.
63 .Pp
64 The
65 .Nm uhub
66 device will always be present as it is needed for the
67 root hub.
68 .Sh INTRODUCTION TO USB
69 The
70 .Tn USB
71 is a 12 Mb/s serial bus (1.5 Mb/s for low speed devices).
72 Each
73 .Tn USB
74 has a host controller that is the master of the bus;
75 all other devices on the bus only speak when spoken to.
76 .Pp
77 There can be up to 127 devices (apart from the host controller)
78 on a bus, each with its own address.
79 The addresses are assigned
80 dynamically by the host when each device is attached to the bus.
81 .Pp
82 Within each device there can be up to 16 endpoints.
83 Each endpoint
84 is individually addressed and the addresses are static.
85 Each of these endpoints will communicate in one of four different modes:
86 .Em control , isochronous , bulk ,
87 or
88 .Em interrupt .
89 A device always has at least one endpoint.
90 This endpoint has address 0 and is a control
91 endpoint and is used to give commands to and extract basic data,
92 such as descriptors, from the device.
93 Each endpoint, except the control endpoint, is unidirectional.
94 .Pp
95 The endpoints in a device are grouped into interfaces.
96 An interface is a logical unit within a device; e.g.\&
97 a compound device with both a keyboard and a trackball would present
98 one interface for each.
99 An interface can sometimes be set into different modes,
100 called alternate settings, which affects how it operates.
101 Different alternate settings can have different endpoints
102 within it.
103 .Pp
104 A device may operate in different configurations.
105 Depending on the
106 configuration, the device may present different sets of endpoints
107 and interfaces.
108 .Pp
109 Each device located on a hub has several
110 .Xr config 8
111 locators:
112 .Bl -tag -compact -width xxxxxx
113 .It Cd port
114 this is the number of the port on the closest upstream hub.
115 .It Cd configuration
116 this is the configuration the device must be in for this driver to attach.
117 This locator does not set the configuration; it is iterated by the bus
118 enumeration.
119 .It Cd interface
120 this is the interface number within a device that an interface driver
121 attaches to.
122 .It Cd vendor
123 this is the 16 bit vendor id of the device.
124 .It Cd product
125 this is the 16 bit product id of the device.
126 .It Cd release
127 this is the 16 bit release (revision) number of the device.
128 .El
129 The first locator can be used to pin down a particular device
130 according to its physical position in the device tree.
131 The last three locators can be used to pin down a particular
132 device according to what device it actually is.
133 .Pp
134 The bus enumeration of the
135 .Tn USB
136 bus proceeds in several steps:
137 .Bl -enum
138 .It
139 Any device specific driver can attach to the device.
140 .It
141 If none is found, any device class specific driver can attach.
142 .It
143 If none is found, all configurations are iterated over.
144 For each configuration, all the interfaces are iterated over, and interface
145 drivers can attach.
146 If any interface driver attached in a certain
147 configuration, the iteration over configurations is stopped.
148 .It
149 If still no drivers have been found, the generic
150 .Tn USB
151 driver can attach.
152 .El
153 .Sh USB CONTROLLER INTERFACE
154 Use the following to get access to the
155 .Tn USB
156 specific structures and defines.
157 .Pp
158 .In dev/usb/usb.h
159 .Pp
160 The
161 .Pa /dev/usb Ns Ar N
162 can be opened and a few operations can be performed on it.
163 The
164 .Xr poll 2
165 system call will say that I/O is possible on the controller device when a
166 .Tn USB
167 device has been connected or disconnected to the bus.
168 .Pp
169 The following
170 .Xr ioctl 2
171 commands are supported on the controller device:
172 .Bl -tag -width xxxxxx
173 .It Dv USB_DISCOVER
174 This command will cause a complete bus discovery to be initiated.
175 If any devices attached or detached from the bus they will be
176 processed during this command.
177 This is the only way that new devices are found on the bus.
178 .It Dv USB_DEVICEINFO Vt "struct usb_device_info"
179 This command can be used to retrieve some information about a device
180 on the bus.
181 The
182 .Va addr
183 field should be filled before the call and the other fields will
184 be filled by information about the device on that address.
185 Should no such device exist, an error is reported.
186 .Bd -literal
187 struct usb_device_info {
188         u_int8_t        bus;
189         u_int8_t        addr;
190         usb_event_cookie_t cookie;
191         char            product[USB_MAX_STRING_LEN];
192         char            vendor[USB_MAX_STRING_LEN];
193         char            release[8];
194         u_int16_t       productNo;
195         u_int16_t       vendorNo;
196         u_int16_t       releaseNo;
197         u_int8_t        class;
198         u_int8_t        subclass;
199         u_int8_t        protocol;
200         u_int8_t        config;
201         u_int8_t        lowspeed;
202         int             power;
203         int             nports;
204         char            devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
205         u_int8_t        ports[16];
206 #define USB_PORT_ENABLED      0xff
207 #define USB_PORT_SUSPENDED    0xfe
208 #define USB_PORT_POWERED      0xfd
209 #define USB_PORT_DISABLED     0xfc
210 };
211 .Ed
212 .Pp
213 .Va bus
214 and
215 .Va addr
216 contain the topological information for the device.
217 .Va devnames
218 contains the device names of the connected drivers.
219 For example, the
220 third
221 .Tn USB
222 Zip drive connected will be
223 .Li umass2 .
224 The
225 .Va product , vendor
226 and
227 .Va release
228 fields contain self-explanatory descriptions of the device.
229 .Va productNo , vendorNo , releaseNo , class , subclass
230 and
231 .Va protocol
232 contain the corresponding values from the device descriptors.
233 The
234 .Va config
235 field shows the current configuration of the device.
236 .Pp
237 .Va lowspeed
238 indicates whether the device is a full speed (0) or low speed (1)
239 device.
240 The
241 .Va power
242 field shows the power consumption in milli-amps drawn at 5 volts,
243 or zero if the device is self powered.
244 .Pp
245 If the device is a hub, the
246 .Va nports
247 field is non-zero, and the
248 .Va ports
249 field contains the addresses of the connected devices.
250 If no device is connected to a port, one of the
251 .Dv USB_PORT_*
252 values indicates its status.
253 .It Dv USB_DEVICESTATS Vt "struct usb_device_stats"
254 This command retrieves statistics about the controller.
255 .Bd -literal
256 struct usb_device_stats {
257         u_long  requests[4];
258 };
259 .Ed
260 .Pp
261 The
262 .Va requests
263 field is indexed by the transfer kind, i.e.\&
264 .Dv UE_* ,
265 and indicates how many transfers of each kind that has been completed
266 by the controller.
267 .It Dv USB_REQUEST Vt "struct usb_ctl_request"
268 This command can be used to execute arbitrary requests on the control pipe.
269 This is
270 .Em DANGEROUS
271 and should be used with great care since it
272 can destroy the bus integrity.
273 .El
274 .Pp
275 The include file
276 .Aq Pa dev/usb/usb.h
277 contains definitions for the types used by the various
278 .Xr ioctl 2
279 calls.
280 The naming convention of the fields for the various
281 .Tn USB
282 descriptors exactly follows the naming in the
283 .Tn USB
284 specification.
285 Byte sized fields can be accessed directly, but word (16 bit)
286 sized fields must be access by the
287 .Fn UGETW field
288 and
289 .Fn USETW field value
290 macros to handle byte order and alignment properly.
291 .Pp
292 The include file
293 .Aq Pa dev/usb/usbhid.h
294 similarly contains the definitions for
295 Human Interface Devices
296 .Pq Tn HID .
297 .Sh USB EVENT INTERFACE
298 All
299 .Tn USB
300 events are reported via the
301 .Pa /dev/usb
302 device.
303 This devices can be opened for reading and each
304 .Xr read 2
305 will yield an event record (if something has happened).
306 The
307 .Xr poll 2
308 system call can be used to determine if an event record is available
309 for reading.
310 .Pp
311 The event record has the following definition:
312 .Bd -literal
313 struct usb_event {
314         int                                 ue_type;
315 #define USB_EVENT_CTRLR_ATTACH 1
316 #define USB_EVENT_CTRLR_DETACH 2
317 #define USB_EVENT_DEVICE_ATTACH 3
318 #define USB_EVENT_DEVICE_DETACH 4
319 #define USB_EVENT_DRIVER_ATTACH 5
320 #define USB_EVENT_DRIVER_DETACH 6
321         struct timespec                     ue_time;
322         union {
323                 struct {
324                         int                 ue_bus;
325                 } ue_ctrlr;
326                 struct usb_device_info      ue_device;
327                 struct {
328                         usb_event_cookie_t  ue_cookie;
329                         char                ue_devname[16];
330                 } ue_driver;
331         } u;
332 };
333 .Ed
334 The
335 .Va ue_type
336 field identifies the type of event that is described.
337 The possible events are attach/detach of a host controller,
338 a device, or a device driver.
339 The union contains information
340 pertinent to the different types of events.
341 .Pp
342 The
343 .Va ue_bus
344 contains the number of the
345 .Tn USB
346 bus for host controller events.
347 .Pp
348 The
349 .Va ue_device
350 record contains information about the device in a device event event.
351 .Pp
352 The
353 .Va ue_cookie
354 is an opaque value that uniquely determines which which
355 device a device driver has been attached to (i.e., it equals
356 the cookie value in the device that the driver attached to).
357 .Pp
358 The
359 .Va ue_devname
360 contains the name of the device (driver) as seen in, e.g.,
361 kernel messages.
362 .Pp
363 Note that there is a separation between device and device
364 driver events.
365 A device event is generated when a physical
366 .Tn USB
367 device is attached or detached.
368 A single
369 .Tn USB
370 device may
371 have zero, one, or many device drivers associated with it.
372 .Sh SEE ALSO
373 The
374 .Tn USB
375 specifications can be found at:
376 .Pp
377 .D1 Pa http://www.usb.org/developers/docs.html
378 .Pp
379 .Xr aue 4 ,
380 .Xr cue 4 ,
381 .Xr kue 4 ,
382 .Xr ohci 4 ,
383 .Xr pci 4 ,
384 .Xr ucom 4 ,
385 .Xr ugen 4 ,
386 .Xr uhci 4 ,
387 .Xr uhid 4 ,
388 .Xr ukbd 4 ,
389 .Xr ulpt 4 ,
390 .Xr umass 4 ,
391 .Xr ums 4 ,
392 .Xr urio 4 ,
393 .Xr uscanner 4 ,
394 .Xr usbd 8 ,
395 .Xr usbdevs 8
396 .Sh HISTORY
397 The
398 .Nm
399 driver first appeared in
400 .Fx 3.0 .
401 .Sh AUTHORS
402 The
403 .Nm
404 driver was written by
405 .An Lennart Augustsson Aq augustss@carlstedt.se
406 for the
407 .Nx
408 project.