Blame Documentation/usb/ehci.txt

Packit 7b02f3
27-Dec-2002
Packit 7b02f3
Packit 7b02f3
The EHCI driver is used to talk to high speed USB 2.0 devices using
Packit 7b02f3
USB 2.0-capable host controller hardware.  The USB 2.0 standard is
Packit 7b02f3
compatible with the USB 1.1 standard. It defines three transfer speeds:
Packit 7b02f3
Packit 7b02f3
    - "High Speed" 480 Mbit/sec (60 MByte/sec)
Packit 7b02f3
    - "Full Speed" 12 Mbit/sec (1.5 MByte/sec)
Packit 7b02f3
    - "Low Speed" 1.5 Mbit/sec
Packit 7b02f3
Packit 7b02f3
USB 1.1 only addressed full speed and low speed.  High speed devices
Packit 7b02f3
can be used on USB 1.1 systems, but they slow down to USB 1.1 speeds.
Packit 7b02f3
Packit 7b02f3
USB 1.1 devices may also be used on USB 2.0 systems.  When plugged
Packit 7b02f3
into an EHCI controller, they are given to a USB 1.1 "companion"
Packit 7b02f3
controller, which is a OHCI or UHCI controller as normally used with
Packit 7b02f3
such devices.  When USB 1.1 devices plug into USB 2.0 hubs, they
Packit 7b02f3
interact with the EHCI controller through a "Transaction Translator"
Packit 7b02f3
(TT) in the hub, which turns low or full speed transactions into
Packit 7b02f3
high speed "split transactions" that don't waste transfer bandwidth.
Packit 7b02f3
Packit 7b02f3
At this writing, this driver has been seen to work with implementations
Packit 7b02f3
of EHCI from (in alphabetical order):  Intel, NEC, Philips, and VIA.
Packit 7b02f3
Other EHCI implementations are becoming available from other vendors;
Packit 7b02f3
you should expect this driver to work with them too.
Packit 7b02f3
Packit 7b02f3
While usb-storage devices have been available since mid-2001 (working
Packit 7b02f3
quite speedily on the 2.4 version of this driver), hubs have only
Packit 7b02f3
been available since late 2001, and other kinds of high speed devices
Packit 7b02f3
appear to be on hold until more systems come with USB 2.0 built-in.
Packit 7b02f3
Such new systems have been available since early 2002, and became much
Packit 7b02f3
more typical in the second half of 2002.
Packit 7b02f3
Packit 7b02f3
Note that USB 2.0 support involves more than just EHCI.  It requires
Packit 7b02f3
other changes to the Linux-USB core APIs, including the hub driver,
Packit 7b02f3
but those changes haven't needed to really change the basic "usbcore"
Packit 7b02f3
APIs exposed to USB device drivers.
Packit 7b02f3
Packit 7b02f3
- David Brownell
Packit 7b02f3
  <dbrownell@users.sourceforge.net>
Packit 7b02f3
Packit 7b02f3
Packit 7b02f3
FUNCTIONALITY
Packit 7b02f3
Packit 7b02f3
This driver is regularly tested on x86 hardware, and has also been
Packit 7b02f3
used on PPC hardware so big/little endianness issues should be gone.
Packit 7b02f3
It's believed to do all the right PCI magic so that I/O works even on
Packit 7b02f3
systems with interesting DMA mapping issues.
Packit 7b02f3
Packit 7b02f3
Transfer Types
Packit 7b02f3
Packit 7b02f3
At this writing the driver should comfortably handle all control, bulk,
Packit 7b02f3
and interrupt transfers, including requests to USB 1.1 devices through
Packit 7b02f3
transaction translators (TTs) in USB 2.0 hubs.  But you may find bugs.
Packit 7b02f3
Packit 7b02f3
High Speed Isochronous (ISO) transfer support is also functional, but
Packit 7b02f3
at this writing no Linux drivers have been using that support.
Packit 7b02f3
Packit 7b02f3
Full Speed Isochronous transfer support, through transaction translators,
Packit 7b02f3
is not yet available.  Note that split transaction support for ISO
Packit 7b02f3
transfers can't share much code with the code for high speed ISO transfers,
Packit 7b02f3
since EHCI represents these with a different data structure.  So for now,
Packit 7b02f3
most USB audio and video devices can't be connected to high speed buses.
Packit 7b02f3
Packit 7b02f3
Driver Behavior
Packit 7b02f3
Packit 7b02f3
Transfers of all types can be queued.  This means that control transfers
Packit 7b02f3
from a driver on one interface (or through usbfs) won't interfere with
Packit 7b02f3
ones from another driver, and that interrupt transfers can use periods
Packit 7b02f3
of one frame without risking data loss due to interrupt processing costs.
Packit 7b02f3
Packit 7b02f3
The EHCI root hub code hands off USB 1.1 devices to its companion
Packit 7b02f3
controller.  This driver doesn't need to know anything about those
Packit 7b02f3
drivers; a OHCI or UHCI driver that works already doesn't need to change
Packit 7b02f3
just because the EHCI driver is also present.
Packit 7b02f3
Packit 7b02f3
There are some issues with power management; suspend/resume doesn't
Packit 7b02f3
behave quite right at the moment.
Packit 7b02f3
Packit 7b02f3
Also, some shortcuts have been taken with the scheduling periodic
Packit 7b02f3
transactions (interrupt and isochronous transfers).  These place some
Packit 7b02f3
limits on the number of periodic transactions that can be scheduled,
Packit 7b02f3
and prevent use of polling intervals of less than one frame.
Packit 7b02f3
Packit 7b02f3
Packit 7b02f3
USE BY
Packit 7b02f3
Packit 7b02f3
Assuming you have an EHCI controller (on a PCI card or motherboard)
Packit 7b02f3
and have compiled this driver as a module, load this like:
Packit 7b02f3
Packit 7b02f3
    # modprobe ehci-hcd
Packit 7b02f3
Packit 7b02f3
and remove it by:
Packit 7b02f3
Packit 7b02f3
    # rmmod ehci-hcd
Packit 7b02f3
Packit 7b02f3
You should also have a driver for a "companion controller", such as
Packit 7b02f3
"ohci-hcd"  or "uhci-hcd".  In case of any trouble with the EHCI driver,
Packit 7b02f3
remove its module and then the driver for that companion controller will
Packit 7b02f3
take over (at lower speed) all the devices that were previously handled
Packit 7b02f3
by the EHCI driver.
Packit 7b02f3
Packit 7b02f3
Module parameters (pass to "modprobe") include:
Packit 7b02f3
Packit 7b02f3
    log2_irq_thresh (default 0):
Packit 7b02f3
	Log2 of default interrupt delay, in microframes.  The default
Packit 7b02f3
	value is 0, indicating 1 microframe (125 usec).  Maximum value
Packit 7b02f3
	is 6, indicating 2^6 = 64 microframes.  This controls how often
Packit 7b02f3
	the EHCI controller can issue interrupts.
Packit 7b02f3
Packit 7b02f3
If you're using this driver on a 2.5 kernel, and you've enabled USB
Packit 7b02f3
debugging support, you'll see three files in the "sysfs" directory for
Packit 7b02f3
any EHCI controller:
Packit 7b02f3
Packit 7b02f3
	"async" dumps the asynchronous schedule, used for control
Packit 7b02f3
		and bulk transfers.  Shows each active qh and the qtds
Packit 7b02f3
		pending, usually one qtd per urb.  (Look at it with
Packit 7b02f3
		usb-storage doing disk I/O; watch the request queues!)
Packit 7b02f3
	"periodic" dumps the periodic schedule, used for interrupt
Packit 7b02f3
		and isochronous transfers.  Doesn't show qtds.
Packit 7b02f3
	"registers" show controller register state, and
Packit 7b02f3
Packit 7b02f3
The contents of those files can help identify driver problems.
Packit 7b02f3
Packit 7b02f3
Packit 7b02f3
Device drivers shouldn't care whether they're running over EHCI or not,
Packit 7b02f3
but they may want to check for "usb_device->speed == USB_SPEED_HIGH".
Packit 7b02f3
High speed devices can do things that full speed (or low speed) ones
Packit 7b02f3
can't, such as "high bandwidth" periodic (interrupt or ISO) transfers.
Packit 7b02f3
Also, some values in device descriptors (such as polling intervals for
Packit 7b02f3
periodic transfers) use different encodings when operating at high speed.
Packit 7b02f3
Packit 7b02f3
However, do make a point of testing device drivers through USB 2.0 hubs.
Packit 7b02f3
Those hubs report some failures, such as disconnections, differently when
Packit 7b02f3
transaction translators are in use; some drivers have been seen to behave
Packit 7b02f3
badly when they see different faults than OHCI or UHCI report.
Packit 7b02f3
Packit 7b02f3
Packit 7b02f3
PERFORMANCE
Packit 7b02f3
Packit 7b02f3
USB 2.0 throughput is gated by two main factors:  how fast the host
Packit 7b02f3
controller can process requests, and how fast devices can respond to
Packit 7b02f3
them.  The 480 Mbit/sec "raw transfer rate" is obeyed by all devices,
Packit 7b02f3
but aggregate throughput is also affected by issues like delays between
Packit 7b02f3
individual high speed packets, driver intelligence, and of course the
Packit 7b02f3
overall system load.  Latency is also a performance concern.
Packit 7b02f3
Packit 7b02f3
Bulk transfers are most often used where throughput is an issue.  It's
Packit 7b02f3
good to keep in mind that bulk transfers are always in 512 byte packets,
Packit 7b02f3
and at most 13 of those fit into one USB 2.0 microframe.  Eight USB 2.0
Packit 7b02f3
microframes fit in a USB 1.1 frame; a microframe is 1 msec/8 = 125 usec.
Packit 7b02f3
Packit 7b02f3
So more than 50 MByte/sec is available for bulk transfers, when both
Packit 7b02f3
hardware and device driver software allow it.  Periodic transfer modes
Packit 7b02f3
(isochronous and interrupt) allow the larger packet sizes which let you
Packit 7b02f3
approach the quoted 480 MBit/sec transfer rate.
Packit 7b02f3
Packit 7b02f3
Hardware Performance
Packit 7b02f3
Packit 7b02f3
At this writing, individual USB 2.0 devices tend to max out at around
Packit 7b02f3
20 MByte/sec transfer rates.  This is of course subject to change;
Packit 7b02f3
and some devices now go faster, while others go slower.
Packit 7b02f3
Packit 7b02f3
The first NEC implementation of EHCI seems to have a hardware bottleneck
Packit 7b02f3
at around 28 MByte/sec aggregate transfer rate.  While this is clearly
Packit 7b02f3
enough for a single device at 20 MByte/sec, putting three such devices
Packit 7b02f3
onto one bus does not get you 60 MByte/sec.  The issue appears to be
Packit 7b02f3
that the controller hardware won't do concurrent USB and PCI access,
Packit 7b02f3
so that it's only trying six (or maybe seven) USB transactions each
Packit 7b02f3
microframe rather than thirteen.  (Seems like a reasonable trade off
Packit 7b02f3
for a product that beat all the others to market by over a year!)
Packit 7b02f3
Packit 7b02f3
It's expected that newer implementations will better this, throwing
Packit 7b02f3
more silicon real estate at the problem so that new motherboard chip
Packit 7b02f3
sets will get closer to that 60 MByte/sec target.  That includes an
Packit 7b02f3
updated implementation from NEC, as well as other vendors' silicon.
Packit 7b02f3
Packit 7b02f3
There's a minimum latency of one microframe (125 usec) for the host
Packit 7b02f3
to receive interrupts from the EHCI controller indicating completion
Packit 7b02f3
of requests.  That latency is tunable; there's a module option.  By
Packit 7b02f3
default ehci-hcd driver uses the minimum latency, which means that if
Packit 7b02f3
you issue a control or bulk request you can often expect to learn that
Packit 7b02f3
it completed in less than 250 usec (depending on transfer size).
Packit 7b02f3
Packit 7b02f3
Software Performance
Packit 7b02f3
Packit 7b02f3
To get even 20 MByte/sec transfer rates, Linux-USB device drivers will
Packit 7b02f3
need to keep the EHCI queue full.  That means issuing large requests,
Packit 7b02f3
or using bulk queuing if a series of small requests needs to be issued.
Packit 7b02f3
When drivers don't do that, their performance results will show it.
Packit 7b02f3
Packit 7b02f3
In typical situations, a usb_bulk_msg() loop writing out 4 KB chunks is
Packit 7b02f3
going to waste more than half the USB 2.0 bandwidth.  Delays between the
Packit 7b02f3
I/O completion and the driver issuing the next request will take longer
Packit 7b02f3
than the I/O.  If that same loop used 16 KB chunks, it'd be better; a
Packit 7b02f3
sequence of 128 KB chunks would waste a lot less.
Packit 7b02f3
Packit 7b02f3
But rather than depending on such large I/O buffers to make synchronous
Packit 7b02f3
I/O be efficient, it's better to just queue up several (bulk) requests
Packit 7b02f3
to the HC, and wait for them all to complete (or be canceled on error).
Packit 7b02f3
Such URB queuing should work with all the USB 1.1 HC drivers too.
Packit 7b02f3
Packit 7b02f3
In the Linux 2.5 kernels, new usb_sg_*() api calls have been defined; they
Packit 7b02f3
queue all the buffers from a scatterlist.  They also use scatterlist DMA
Packit 7b02f3
mapping (which might apply an IOMMU) and IRQ reduction, all of which will
Packit 7b02f3
help make high speed transfers run as fast as they can.
Packit 7b02f3
Packit 7b02f3
Packit 7b02f3
TBD:  Interrupt and ISO transfer performance issues.  Those periodic
Packit 7b02f3
transfers are fully scheduled, so the main issue is likely to be how
Packit 7b02f3
to trigger "high bandwidth" modes.
Packit 7b02f3
Packit 7b02f3
TBD:  More than standard 80% periodic bandwidth allocation is possible
Packit 7b02f3
through sysfs uframe_periodic_max parameter. Describe that.