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
165 .. kernel-doc:: drivers/usb/core/message.c
168 .. kernel-doc:: drivers/usb/core/file.c
171 .. kernel-doc:: drivers/usb/core/driver.c
174 .. kernel-doc:: drivers/usb/core/usb.c
177 .. kernel-doc:: drivers/usb/core/hub.c
185 was one of the first interfaces, designed by Intel and also used by VIA;
186 it doesn't do much in hardware. OHCI was designed later, to have the
191 continues to shift support for functionality into hardware.
194 based controllers (and a few non-PCI based ones) use one of those
196 also a simulator and a virtual host controller to pipe USB over the network.
198 The same basic APIs are available to drivers for all those controllers.
203 that lets HCDs share common code, to shrink driver size and
204 significantly reduce hcd-specific behaviors.
206 .. kernel-doc:: drivers/usb/core/hcd.c
209 .. kernel-doc:: drivers/usb/core/hcd-pci.c
212 .. kernel-doc:: drivers/usb/core/buffer.c
219 to avoid writing new kernel code for your USB driver. User mode device
224 - `libusb <http://libusb.sourceforge.net>`__ for C/C++, and
225 - `jUSB <http://jUSB.sourceforge.net>`__ for Java.
229 at http://www.linux-usb.org/
233 - They were used to be implemented via *usbfs*, but this is not part of
236 - This particular documentation is incomplete, especially with respect
237 to the asynchronous mode. As of kernel 2.5.66 the code and this
238 (new) documentation need to be cross-reviewed.
241 -----------------------------
245 - ``/dev/bus/usb/BBB/DDD`` ... magic files exposing the each device's
247 making device requests, including I/O to devices. (Purely for access
252 paths are not "stable" identifiers; expect them to change even if you
253 always leave the devices plugged in to the same hub port. *Don't even
255 identifiers are available, for user mode applications that want to use
257 example you can be sure that you told the right UPS to power down its
261 --------------------
263 Use these files in one of these basic ways:
265 - *They can be read,* producing first the device descriptor (18 bytes) and
267 for details about those binary data formats. You'll need to convert most
268 multibyte values from little endian format to your native host byte
270 the BCD-encoded fields, and the vendor and product IDs) will be
275 - *Perform USB operations* using *ioctl()* requests to make endpoint I/O
278 access permissions. Only one ioctl request can be made on one of these
280 an endpoint from one thread, you won't be able to write to a different
285 Each connected USB device has one file. The ``BBB`` indicates the bus
288 you can't rely on them for stable access to devices. For example,
289 it's relatively common for devices to re-enumerate while they are
296 configuration of the device. Multi-byte fields in the device descriptor
297 are converted to host endianness by the kernel. The configuration
304 These files may also be used to write user-level drivers for the USB
306 read its descriptors to make sure it's the device you expect, and then
307 bind to an interface (or perhaps several) using an ioctl call. You
308 would issue more ioctls to the device to communicate to it using
312 for how to access devices through those files.
316 grant read/write permissions to other users by using ``chmod``. Also,
321 -------------------------------
323 Such a driver first needs to find a device file for a device it knows
324 how to handle. Maybe it was told about it because a ``/sbin/hotplug``
325 event handling agent chose that driver to handle the new device. Or
329 knows how to handle. It might just reject everything except a particular
332 Never assume there will only be one such device on the system at a time!
333 If your code can't handle more than one device at a time, at least
334 detect when there's more than one, and have your users choose which
335 device to use.
337 Once your user mode driver knows what device to use, it interacts with
338 it in either of two styles. The simple style is to make only control
340 (An example might be software using vendor-specific control requests for
344 More likely, you need a more complex style driver: one using non-control
346 interface. *Bulk* transfers are easiest to use, but only their sibling
349 is reserved. Such "periodic" transfers are awkward to use through usbfs,
351 can also be used in a synchronous "one shot" style.
353 Your user-mode driver should never need to worry about cleaning up
358 --------------------
360 To use these ioctls, you need to include the following headers in your
372 the modification time on the usbfs file to which they are applied
375 :ref:`usb-error-codes`).
377 Each of these files multiplexes access to several I/O streams, one per
378 endpoint. Each device has one control endpoint (endpoint zero) which
380 hub_wq (in the kernel) setting a device-wide *configuration* that
391 They mostly relate to device management and status. These are all
395 This is used to force usbfs to claim a specific interface, which has
400 Note that if your driver doesn't claim an interface before trying to
401 use one of its endpoints, and no other driver has bound to it, then
409 Says whether the device is lowspeed. The ioctl parameter points to a
431 Returns the name of the kernel driver bound to a given interface (a
432 string). Parameter is a pointer to this structure, which is
443 Passes a request from userspace through to a kernel driver that has
453 * 'request' becomes the driver->ioctl() 'code' parameter.
455 * is copied to or from the driver->ioctl() 'buf' parameter.
471 This request lets kernel drivers talk to user mode code through
473 block special device. It's also been used to do things like ask
474 devices what device special file should be used. Two pre-defined
475 ioctls are used to disconnect and reconnect kernel drivers, so that
480 This is used to release the claim usbfs made on interface, either
488 *No security check is made to ensure that the task which made
489 the claim is the one which is releasing it. This means that user
493 Resets the data toggle value for an endpoint (bulk or interrupt) to
494 DATA0. The ioctl parameter is an integer endpoint number (1 to 15,
496 if the device's endpoint sends data to the host.
503 need to completely handshake with the device, using a request
507 This is used to relinquish the ability to do certain operations
508 which are considered to be privileged on a usbfs file descriptor.
512 of interfaces the user is allowed to claim on this file descriptor.
513 You may issue this ioctl more than one time to narrow said mask.
520 error. In most cases this is the simplest way to use usbfs, although as
521 noted above it does prevent performing I/O to more than one endpoint at
525 Issues a bulk read or write request to the device. The ioctl
526 parameter is a pointer to this structure::
535 The ``ep`` value identifies a bulk endpoint number (1 to 15, as
537 referring to an endpoint which sends data to the host from the
539 kernels support requests up to about 128KBytes. *FIXME say how read
545 is an integer endpoint number (1 to 15, as identified in an endpoint
546 descriptor), masked with USB_DIR_IN when referring to an endpoint
547 which sends data to the host from the device.
550 returning ``-EPIPE`` status to a data transfer request. Do not issue
555 Issues a control request to the device. The ioctl parameter points
556 to a structure like this::
569 SETUP packet to be sent to the device; see the USB 2.0 specification
573 the length of the data buffer, which is either written to the device
576 At this writing, you can't transfer more than 4 KBytes of data to or
579 to say it's not OK to get a short read back from the device.
594 a pointer to a structure like this::
603 Those struct members are from some interface descriptor applying to
624 As mentioned above, there are situations where it may be important to
629 submitting one request and having the kernel block until it completes,
636 and a user "context" value serving to uniquely identify each request.
637 (It's usually a pointer to per-request data.) Flags can modify requests
641 SIGRTMAX, inclusive) to request a signal be sent when the request
646 actual_length is updated to say how many bytes were transferred; if the
696 - ``/sys/kernel/debug/usb/devices`` ... a text file showing each of the USB
697 devices on known to the kernel, and their configuration descriptors.
698 You can also poll() this to learn about new devices.
701 -----------------------------
705 (including class and vendor status) is available from device-specific
709 to detect when devices are added or removed::
718 poll(&pfd, 1, -1);
720 /* To see what's changed, compare the file's previous and current
724 Note that this behavior is intended to be used for informational and
725 debug purposes. It would be more appropriate to use programs such as
726 udev or HAL to initialize a device or start a user-mode helper program,
735 Lev, Prnt, Port, Cnt) can be used to build a USB topology diagram.
737 Each line is tagged with a one-character ID for that line::
740 B = Bandwidth (applies only to USB host controllers, which are
744 together on one line)
797 | |__Total Bandwidth allocated to this bus
800 Bandwidth allocation is an approximation of how much of one frame
880 rather differently. For example, a bus-powered configuration
881 might be much less capable than one that is self-powered. Only
882 one device configuration can be active at a time; most devices
883 have only one configuration.
885 Each configuration consists of one or more interfaces. Each
887 to a different USB device driver. One common example is a USB
907 A given interface may have one or more "alternate" settings.
909 amount of periodic bandwidth. To use significant fractions
910 of bus bandwidth, drivers must select a non-default altsetting.
912 Only one setting for an interface may be active at a time, and
913 only one driver may bind to an interface at a time. Most devices
914 have only one alternate setting per interface.
934 the per-microframe data transfer size. For "high bandwidth"
935 endpoints, that can reflect two or three packets (for up to
938 With the Linux-USB stack, periodic bandwidth reservations use the
948 ``grep -i ^[tdp]: /sys/kernel/debug/usb/devices`` can be used to list
957 The Topology lines can be used to generate a graphic/pictorial
959 on how to do this.)
961 The Interface lines can be used to determine what driver is
964 The Configuration lines could be used to list maximum power
970 an external hub connected to the root hub, and a mouse and
971 a serial converter connected to the external hub.
1003 S: Product=Peracom USB to Serial Converter
1025 Physically this looks like (or could be converted to)::
1027 +------------------+
1029 +------------------+ (nn) is Mbps.
1031 +------------------+
1034 +-----------------------+
1035 Level 1 | Dev#2: 4-port hub (12)|
1036 +-----------------------+
1038 +-----------------------+
1042 +--------------------+ +--------------------+
1044 +--------------------+ +--------------------+
1048 Or, in a more tree-like structure (ports [Connectors] without