Lines Matching +full:one +full:- +full:to +full:- +full:one
1 .. _usb-hostside-api:
4 The Linux-USB Host Side API
7 Introduction to USB on Linux
10 A Universal Serial Bus (USB) is used to connect a host, such as a PC or
11 workstation, to a number of peripheral devices. USB uses a tree
18 That master/slave asymmetry was designed-in for a number of reasons, one
19 being ease of use. It is not physically possible to mistake upstream and
21 peripheral). Also, the host software doesn't need to deal with
22 distributed auto-configuration since the pre-designated master node
25 Kernel developers added USB support to Linux early in the 2.2 kernel
37 USB Host-Side API Model
40 Host-side drivers for USB devices talk to the "usbcore" APIs. There are
41 two. One is intended for *general-purpose* drivers (exposed through
49 - USB supports four kinds of data transfers (control, bulk, interrupt,
52 scheduled to provide guaranteed bandwidth.
54 - The device description model includes one or more "configurations"
55 per device, only one of which is active at a time. Devices are supposed
56 to be capable of operating at lower than their top
60 - From USB 3.0 on configurations have one or more "functions", which
64 - Configurations or functions have one or more "interfaces", each of which may have
66 specifications, or may be specific to a vendor or device.
68 USB device drivers actually bind to interfaces, not devices. Think of
71 with only one function, one configuration, one interface, and one alternate
74 - Interfaces have one or more "endpoints", each of which supports one
76 in". The entire configuration may have up to sixteen endpoints in
79 - Data transfer on USB is packetized; each endpoint has a maximum
84 - The Linux USB API supports synchronous calls for control and bulk
89 Accordingly, the USB Core API exposed to device drivers covers quite a
90 lot of territory. You'll probably need to consult the USB 3.0
94 The only host-side drivers that actually touch hardware (reading/writing
101 faults (including software-induced ones like unlinking an URB) isn't yet
104 controller driver, to make sure drivers don't have bugs of their own as
105 well as to make sure they aren't relying on some HCD-specific behavior.
109 USB-Standard Types
120 .. kernel-doc:: drivers/usb/common/common.c
128 Host-Side Data Types and Macros
131 The host side API exposes several layers to drivers, some of which are
133 drivers and devices, and support passing buffers through usbcore to some
136 .. kernel-doc:: include/linux/usb.h
142 There are two basic I/O models in the USB API. The most elemental one is
148 per-packet fault reports). Built on top of that is synchronous API
149 support, where a driver calls a routine that allocates one or more URBs,
151 wrappers for single-buffer control and bulk transfers (which are awkward
152 to use in some driver disconnect scenarios), and for scatterlist based
155 USB drivers need to provide buffers that can be used for DMA, although
156 they don't necessarily need to provide the DMA mapping themselves. There
157 are APIs to use used when allocating DMA buffers, which can prevent use
158 of bounce buffers on some systems. In some cases, drivers may be able to
159 rely on 64bit DMA to eliminate another kind of bounce buffer.
161 .. kernel-doc:: drivers/usb/core/urb.c
164 .. kernel-doc:: drivers/usb/core/message.c
167 .. kernel-doc:: drivers/usb/core/file.c
170 .. kernel-doc:: drivers/usb/core/driver.c
173 .. kernel-doc:: drivers/usb/core/usb.c
176 .. kernel-doc:: drivers/usb/core/hub.c
184 was one of the first interfaces, designed by Intel and also used by VIA;
185 it doesn't do much in hardware. OHCI was designed later, to have the
190 continues to shift support for functionality into hardware.
193 based controllers (and a few non-PCI based ones) use one of those
195 also a simulator and a virtual host controller to pipe USB over the network.
197 The same basic APIs are available to drivers for all those controllers.
202 that lets HCDs share common code, to shrink driver size and
203 significantly reduce hcd-specific behaviors.
205 .. kernel-doc:: drivers/usb/core/hcd.c
208 .. kernel-doc:: drivers/usb/core/hcd-pci.c
211 .. kernel-doc:: drivers/usb/core/buffer.c
218 to avoid writing new kernel code for your USB driver. User mode device
223 - `libusb <http://libusb.sourceforge.net>`__ for C/C++, and
224 - `jUSB <http://jUSB.sourceforge.net>`__ for Java.
228 at http://www.linux-usb.org/
232 - They were used to be implemented via *usbfs*, but this is not part of
235 - This particular documentation is incomplete, especially with respect
236 to the asynchronous mode. As of kernel 2.5.66 the code and this
237 (new) documentation need to be cross-reviewed.
240 -----------------------------
244 - ``/dev/bus/usb/BBB/DDD`` ... magic files exposing the each device's
246 making device requests, including I/O to devices. (Purely for access
251 paths are not "stable" identifiers; expect them to change even if you
252 always leave the devices plugged in to the same hub port. *Don't even
254 identifiers are available, for user mode applications that want to use
256 example you can be sure that you told the right UPS to power down its
260 --------------------
262 Use these files in one of these basic ways:
264 - *They can be read,* producing first the device descriptor (18 bytes) and
266 for details about those binary data formats. You'll need to convert most
267 multibyte values from little endian format to your native host byte
269 the BCD-encoded fields, and the vendor and product IDs) will be
274 - *Perform USB operations* using *ioctl()* requests to make endpoint I/O
277 access permissions. Only one ioctl request can be made on one of these
279 an endpoint from one thread, you won't be able to write to a different
284 Each connected USB device has one file. The ``BBB`` indicates the bus
287 you can't rely on them for stable access to devices. For example,
288 it's relatively common for devices to re-enumerate while they are
295 configuration of the device. Multi-byte fields in the device descriptor
296 are converted to host endianness by the kernel. The configuration
303 These files may also be used to write user-level drivers for the USB
305 read its descriptors to make sure it's the device you expect, and then
306 bind to an interface (or perhaps several) using an ioctl call. You
307 would issue more ioctls to the device to communicate to it using
311 for how to access devices through those files.
315 grant read/write permissions to other users by using ``chmod``. Also,
320 -------------------------------
322 Such a driver first needs to find a device file for a device it knows
323 how to handle. Maybe it was told about it because a ``/sbin/hotplug``
324 event handling agent chose that driver to handle the new device. Or
328 knows how to handle. It might just reject everything except a particular
331 Never assume there will only be one such device on the system at a time!
332 If your code can't handle more than one device at a time, at least
333 detect when there's more than one, and have your users choose which
334 device to use.
336 Once your user mode driver knows what device to use, it interacts with
337 it in either of two styles. The simple style is to make only control
339 (An example might be software using vendor-specific control requests for
343 More likely, you need a more complex style driver: one using non-control
345 interface. *Bulk* transfers are easiest to use, but only their sibling
348 is reserved. Such "periodic" transfers are awkward to use through usbfs,
350 can also be used in a synchronous "one shot" style.
352 Your user-mode driver should never need to worry about cleaning up
357 --------------------
359 To use these ioctls, you need to include the following headers in your
371 the modification time on the usbfs file to which they are applied
374 :ref:`usb-error-codes`).
376 Each of these files multiplexes access to several I/O streams, one per
377 endpoint. Each device has one control endpoint (endpoint zero) which
379 hub_wq (in the kernel) setting a device-wide *configuration* that
390 They mostly relate to device management and status. These are all
394 This is used to force usbfs to claim a specific interface, which has
399 Note that if your driver doesn't claim an interface before trying to
400 use one of its endpoints, and no other driver has bound to it, then
408 Says whether the device is lowspeed. The ioctl parameter points to a
430 Returns the name of the kernel driver bound to a given interface (a
431 string). Parameter is a pointer to this structure, which is
442 Passes a request from userspace through to a kernel driver that has
452 * 'request' becomes the driver->ioctl() 'code' parameter.
454 * is copied to or from the driver->ioctl() 'buf' parameter.
470 This request lets kernel drivers talk to user mode code through
472 block special device. It's also been used to do things like ask
473 devices what device special file should be used. Two pre-defined
474 ioctls are used to disconnect and reconnect kernel drivers, so that
479 This is used to release the claim usbfs made on interface, either
487 *No security check is made to ensure that the task which made
488 the claim is the one which is releasing it. This means that user
492 Resets the data toggle value for an endpoint (bulk or interrupt) to
493 DATA0. The ioctl parameter is an integer endpoint number (1 to 15,
495 if the device's endpoint sends data to the host.
502 need to completely handshake with the device, using a request
506 This is used to relinquish the ability to do certain operations
507 which are considered to be privileged on a usbfs file descriptor.
511 of interfaces the user is allowed to claim on this file descriptor.
512 You may issue this ioctl more than one time to narrow said mask.
519 error. In most cases this is the simplest way to use usbfs, although as
520 noted above it does prevent performing I/O to more than one endpoint at
524 Issues a bulk read or write request to the device. The ioctl
525 parameter is a pointer to this structure::
534 The ``ep`` value identifies a bulk endpoint number (1 to 15, as
536 referring to an endpoint which sends data to the host from the
538 kernels support requests up to about 128KBytes. *FIXME say how read
544 is an integer endpoint number (1 to 15, as identified in an endpoint
545 descriptor), masked with USB_DIR_IN when referring to an endpoint
546 which sends data to the host from the device.
549 returning ``-EPIPE`` status to a data transfer request. Do not issue
554 Issues a control request to the device. The ioctl parameter points
555 to a structure like this::
568 SETUP packet to be sent to the device; see the USB 2.0 specification
572 the length of the data buffer, which is either written to the device
575 At this writing, you can't transfer more than 4 KBytes of data to or
578 to say it's not OK to get a short read back from the device.
593 a pointer to a structure like this::
602 Those struct members are from some interface descriptor applying to
623 As mentioned above, there are situations where it may be important to
628 submitting one request and having the kernel block until it completes,
635 and a user "context" value serving to uniquely identify each request.
636 (It's usually a pointer to per-request data.) Flags can modify requests
640 SIGRTMAX, inclusive) to request a signal be sent when the request
645 actual_length is updated to say how many bytes were transferred; if the
695 - ``/sys/kernel/debug/usb/devices`` ... a text file showing each of the USB
696 devices on known to the kernel, and their configuration descriptors.
697 You can also poll() this to learn about new devices.
700 -----------------------------
704 (including class and vendor status) is available from device-specific
708 to detect when devices are added or removed::
717 poll(&pfd, 1, -1);
719 /* To see what's changed, compare the file's previous and current
723 Note that this behavior is intended to be used for informational and
724 debug purposes. It would be more appropriate to use programs such as
725 udev or HAL to initialize a device or start a user-mode helper program,
734 Lev, Prnt, Port, Cnt) can be used to build a USB topology diagram.
736 Each line is tagged with a one-character ID for that line::
739 B = Bandwidth (applies only to USB host controllers, which are
743 together on one line)
796 | |__Total Bandwidth allocated to this bus
799 Bandwidth allocation is an approximation of how much of one frame
879 rather differently. For example, a bus-powered configuration
880 might be much less capable than one that is self-powered. Only
881 one device configuration can be active at a time; most devices
882 have only one configuration.
884 Each configuration consists of one or more interfaces. Each
886 to a different USB device driver. One common example is a USB
906 A given interface may have one or more "alternate" settings.
908 amount of periodic bandwidth. To use significant fractions
909 of bus bandwidth, drivers must select a non-default altsetting.
911 Only one setting for an interface may be active at a time, and
912 only one driver may bind to an interface at a time. Most devices
913 have only one alternate setting per interface.
933 the per-microframe data transfer size. For "high bandwidth"
934 endpoints, that can reflect two or three packets (for up to
937 With the Linux-USB stack, periodic bandwidth reservations use the
947 ``grep -i ^[tdp]: /sys/kernel/debug/usb/devices`` can be used to list
956 The Topology lines can be used to generate a graphic/pictorial
958 on how to do this.)
960 The Interface lines can be used to determine what driver is
963 The Configuration lines could be used to list maximum power
969 an external hub connected to the root hub, and a mouse and
970 a serial converter connected to the external hub.
1002 S: Product=Peracom USB to Serial Converter
1024 Physically this looks like (or could be converted to)::
1026 +------------------+
1028 +------------------+ (nn) is Mbps.
1030 +------------------+
1033 +-----------------------+
1034 Level 1 | Dev#2: 4-port hub (12)|
1035 +-----------------------+
1037 +-----------------------+
1041 +--------------------+ +--------------------+
1043 +--------------------+ +--------------------+
1047 Or, in a more tree-like structure (ports [Connectors] without