xref: /OK3568_Linux_fs/kernel/Documentation/usb/ehci.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun===========
2*4882a593SmuzhiyunEHCI driver
3*4882a593Smuzhiyun===========
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun27-Dec-2002
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunThe EHCI driver is used to talk to high speed USB 2.0 devices using
8*4882a593SmuzhiyunUSB 2.0-capable host controller hardware.  The USB 2.0 standard is
9*4882a593Smuzhiyuncompatible with the USB 1.1 standard. It defines three transfer speeds:
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun    - "High Speed" 480 Mbit/sec (60 MByte/sec)
12*4882a593Smuzhiyun    - "Full Speed" 12 Mbit/sec (1.5 MByte/sec)
13*4882a593Smuzhiyun    - "Low Speed" 1.5 Mbit/sec
14*4882a593Smuzhiyun
15*4882a593SmuzhiyunUSB 1.1 only addressed full speed and low speed.  High speed devices
16*4882a593Smuzhiyuncan be used on USB 1.1 systems, but they slow down to USB 1.1 speeds.
17*4882a593Smuzhiyun
18*4882a593SmuzhiyunUSB 1.1 devices may also be used on USB 2.0 systems.  When plugged
19*4882a593Smuzhiyuninto an EHCI controller, they are given to a USB 1.1 "companion"
20*4882a593Smuzhiyuncontroller, which is a OHCI or UHCI controller as normally used with
21*4882a593Smuzhiyunsuch devices.  When USB 1.1 devices plug into USB 2.0 hubs, they
22*4882a593Smuzhiyuninteract with the EHCI controller through a "Transaction Translator"
23*4882a593Smuzhiyun(TT) in the hub, which turns low or full speed transactions into
24*4882a593Smuzhiyunhigh speed "split transactions" that don't waste transfer bandwidth.
25*4882a593Smuzhiyun
26*4882a593SmuzhiyunAt this writing, this driver has been seen to work with implementations
27*4882a593Smuzhiyunof EHCI from (in alphabetical order):  Intel, NEC, Philips, and VIA.
28*4882a593SmuzhiyunOther EHCI implementations are becoming available from other vendors;
29*4882a593Smuzhiyunyou should expect this driver to work with them too.
30*4882a593Smuzhiyun
31*4882a593SmuzhiyunWhile usb-storage devices have been available since mid-2001 (working
32*4882a593Smuzhiyunquite speedily on the 2.4 version of this driver), hubs have only
33*4882a593Smuzhiyunbeen available since late 2001, and other kinds of high speed devices
34*4882a593Smuzhiyunappear to be on hold until more systems come with USB 2.0 built-in.
35*4882a593SmuzhiyunSuch new systems have been available since early 2002, and became much
36*4882a593Smuzhiyunmore typical in the second half of 2002.
37*4882a593Smuzhiyun
38*4882a593SmuzhiyunNote that USB 2.0 support involves more than just EHCI.  It requires
39*4882a593Smuzhiyunother changes to the Linux-USB core APIs, including the hub driver,
40*4882a593Smuzhiyunbut those changes haven't needed to really change the basic "usbcore"
41*4882a593SmuzhiyunAPIs exposed to USB device drivers.
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun- David Brownell
44*4882a593Smuzhiyun  <dbrownell@users.sourceforge.net>
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun
47*4882a593SmuzhiyunFunctionality
48*4882a593Smuzhiyun=============
49*4882a593Smuzhiyun
50*4882a593SmuzhiyunThis driver is regularly tested on x86 hardware, and has also been
51*4882a593Smuzhiyunused on PPC hardware so big/little endianness issues should be gone.
52*4882a593SmuzhiyunIt's believed to do all the right PCI magic so that I/O works even on
53*4882a593Smuzhiyunsystems with interesting DMA mapping issues.
54*4882a593Smuzhiyun
55*4882a593SmuzhiyunTransfer Types
56*4882a593Smuzhiyun--------------
57*4882a593Smuzhiyun
58*4882a593SmuzhiyunAt this writing the driver should comfortably handle all control, bulk,
59*4882a593Smuzhiyunand interrupt transfers, including requests to USB 1.1 devices through
60*4882a593Smuzhiyuntransaction translators (TTs) in USB 2.0 hubs.  But you may find bugs.
61*4882a593Smuzhiyun
62*4882a593SmuzhiyunHigh Speed Isochronous (ISO) transfer support is also functional, but
63*4882a593Smuzhiyunat this writing no Linux drivers have been using that support.
64*4882a593Smuzhiyun
65*4882a593SmuzhiyunFull Speed Isochronous transfer support, through transaction translators,
66*4882a593Smuzhiyunis not yet available.  Note that split transaction support for ISO
67*4882a593Smuzhiyuntransfers can't share much code with the code for high speed ISO transfers,
68*4882a593Smuzhiyunsince EHCI represents these with a different data structure.  So for now,
69*4882a593Smuzhiyunmost USB audio and video devices can't be connected to high speed buses.
70*4882a593Smuzhiyun
71*4882a593SmuzhiyunDriver Behavior
72*4882a593Smuzhiyun---------------
73*4882a593Smuzhiyun
74*4882a593SmuzhiyunTransfers of all types can be queued.  This means that control transfers
75*4882a593Smuzhiyunfrom a driver on one interface (or through usbfs) won't interfere with
76*4882a593Smuzhiyunones from another driver, and that interrupt transfers can use periods
77*4882a593Smuzhiyunof one frame without risking data loss due to interrupt processing costs.
78*4882a593Smuzhiyun
79*4882a593SmuzhiyunThe EHCI root hub code hands off USB 1.1 devices to its companion
80*4882a593Smuzhiyuncontroller.  This driver doesn't need to know anything about those
81*4882a593Smuzhiyundrivers; a OHCI or UHCI driver that works already doesn't need to change
82*4882a593Smuzhiyunjust because the EHCI driver is also present.
83*4882a593Smuzhiyun
84*4882a593SmuzhiyunThere are some issues with power management; suspend/resume doesn't
85*4882a593Smuzhiyunbehave quite right at the moment.
86*4882a593Smuzhiyun
87*4882a593SmuzhiyunAlso, some shortcuts have been taken with the scheduling periodic
88*4882a593Smuzhiyuntransactions (interrupt and isochronous transfers).  These place some
89*4882a593Smuzhiyunlimits on the number of periodic transactions that can be scheduled,
90*4882a593Smuzhiyunand prevent use of polling intervals of less than one frame.
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun
93*4882a593SmuzhiyunUse by
94*4882a593Smuzhiyun======
95*4882a593Smuzhiyun
96*4882a593SmuzhiyunAssuming you have an EHCI controller (on a PCI card or motherboard)
97*4882a593Smuzhiyunand have compiled this driver as a module, load this like::
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun    # modprobe ehci-hcd
100*4882a593Smuzhiyun
101*4882a593Smuzhiyunand remove it by::
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun    # rmmod ehci-hcd
104*4882a593Smuzhiyun
105*4882a593SmuzhiyunYou should also have a driver for a "companion controller", such as
106*4882a593Smuzhiyun"ohci-hcd"  or "uhci-hcd".  In case of any trouble with the EHCI driver,
107*4882a593Smuzhiyunremove its module and then the driver for that companion controller will
108*4882a593Smuzhiyuntake over (at lower speed) all the devices that were previously handled
109*4882a593Smuzhiyunby the EHCI driver.
110*4882a593Smuzhiyun
111*4882a593SmuzhiyunModule parameters (pass to "modprobe") include:
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun    log2_irq_thresh (default 0):
114*4882a593Smuzhiyun	Log2 of default interrupt delay, in microframes.  The default
115*4882a593Smuzhiyun	value is 0, indicating 1 microframe (125 usec).  Maximum value
116*4882a593Smuzhiyun	is 6, indicating 2^6 = 64 microframes.  This controls how often
117*4882a593Smuzhiyun	the EHCI controller can issue interrupts.
118*4882a593Smuzhiyun
119*4882a593SmuzhiyunIf you're using this driver on a 2.5 kernel, and you've enabled USB
120*4882a593Smuzhiyundebugging support, you'll see three files in the "sysfs" directory for
121*4882a593Smuzhiyunany EHCI controller:
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun	"async"
124*4882a593Smuzhiyun		dumps the asynchronous schedule, used for control
125*4882a593Smuzhiyun		and bulk transfers.  Shows each active qh and the qtds
126*4882a593Smuzhiyun		pending, usually one qtd per urb.  (Look at it with
127*4882a593Smuzhiyun		usb-storage doing disk I/O; watch the request queues!)
128*4882a593Smuzhiyun	"periodic"
129*4882a593Smuzhiyun		dumps the periodic schedule, used for interrupt
130*4882a593Smuzhiyun		and isochronous transfers.  Doesn't show qtds.
131*4882a593Smuzhiyun	"registers"
132*4882a593Smuzhiyun		show controller register state, and
133*4882a593Smuzhiyun
134*4882a593SmuzhiyunThe contents of those files can help identify driver problems.
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun
137*4882a593SmuzhiyunDevice drivers shouldn't care whether they're running over EHCI or not,
138*4882a593Smuzhiyunbut they may want to check for "usb_device->speed == USB_SPEED_HIGH".
139*4882a593SmuzhiyunHigh speed devices can do things that full speed (or low speed) ones
140*4882a593Smuzhiyuncan't, such as "high bandwidth" periodic (interrupt or ISO) transfers.
141*4882a593SmuzhiyunAlso, some values in device descriptors (such as polling intervals for
142*4882a593Smuzhiyunperiodic transfers) use different encodings when operating at high speed.
143*4882a593Smuzhiyun
144*4882a593SmuzhiyunHowever, do make a point of testing device drivers through USB 2.0 hubs.
145*4882a593SmuzhiyunThose hubs report some failures, such as disconnections, differently when
146*4882a593Smuzhiyuntransaction translators are in use; some drivers have been seen to behave
147*4882a593Smuzhiyunbadly when they see different faults than OHCI or UHCI report.
148*4882a593Smuzhiyun
149*4882a593Smuzhiyun
150*4882a593SmuzhiyunPerformance
151*4882a593Smuzhiyun===========
152*4882a593Smuzhiyun
153*4882a593SmuzhiyunUSB 2.0 throughput is gated by two main factors:  how fast the host
154*4882a593Smuzhiyuncontroller can process requests, and how fast devices can respond to
155*4882a593Smuzhiyunthem.  The 480 Mbit/sec "raw transfer rate" is obeyed by all devices,
156*4882a593Smuzhiyunbut aggregate throughput is also affected by issues like delays between
157*4882a593Smuzhiyunindividual high speed packets, driver intelligence, and of course the
158*4882a593Smuzhiyunoverall system load.  Latency is also a performance concern.
159*4882a593Smuzhiyun
160*4882a593SmuzhiyunBulk transfers are most often used where throughput is an issue.  It's
161*4882a593Smuzhiyungood to keep in mind that bulk transfers are always in 512 byte packets,
162*4882a593Smuzhiyunand at most 13 of those fit into one USB 2.0 microframe.  Eight USB 2.0
163*4882a593Smuzhiyunmicroframes fit in a USB 1.1 frame; a microframe is 1 msec/8 = 125 usec.
164*4882a593Smuzhiyun
165*4882a593SmuzhiyunSo more than 50 MByte/sec is available for bulk transfers, when both
166*4882a593Smuzhiyunhardware and device driver software allow it.  Periodic transfer modes
167*4882a593Smuzhiyun(isochronous and interrupt) allow the larger packet sizes which let you
168*4882a593Smuzhiyunapproach the quoted 480 MBit/sec transfer rate.
169*4882a593Smuzhiyun
170*4882a593SmuzhiyunHardware Performance
171*4882a593Smuzhiyun--------------------
172*4882a593Smuzhiyun
173*4882a593SmuzhiyunAt this writing, individual USB 2.0 devices tend to max out at around
174*4882a593Smuzhiyun20 MByte/sec transfer rates.  This is of course subject to change;
175*4882a593Smuzhiyunand some devices now go faster, while others go slower.
176*4882a593Smuzhiyun
177*4882a593SmuzhiyunThe first NEC implementation of EHCI seems to have a hardware bottleneck
178*4882a593Smuzhiyunat around 28 MByte/sec aggregate transfer rate.  While this is clearly
179*4882a593Smuzhiyunenough for a single device at 20 MByte/sec, putting three such devices
180*4882a593Smuzhiyunonto one bus does not get you 60 MByte/sec.  The issue appears to be
181*4882a593Smuzhiyunthat the controller hardware won't do concurrent USB and PCI access,
182*4882a593Smuzhiyunso that it's only trying six (or maybe seven) USB transactions each
183*4882a593Smuzhiyunmicroframe rather than thirteen.  (Seems like a reasonable trade off
184*4882a593Smuzhiyunfor a product that beat all the others to market by over a year!)
185*4882a593Smuzhiyun
186*4882a593SmuzhiyunIt's expected that newer implementations will better this, throwing
187*4882a593Smuzhiyunmore silicon real estate at the problem so that new motherboard chip
188*4882a593Smuzhiyunsets will get closer to that 60 MByte/sec target.  That includes an
189*4882a593Smuzhiyunupdated implementation from NEC, as well as other vendors' silicon.
190*4882a593Smuzhiyun
191*4882a593SmuzhiyunThere's a minimum latency of one microframe (125 usec) for the host
192*4882a593Smuzhiyunto receive interrupts from the EHCI controller indicating completion
193*4882a593Smuzhiyunof requests.  That latency is tunable; there's a module option.  By
194*4882a593Smuzhiyundefault ehci-hcd driver uses the minimum latency, which means that if
195*4882a593Smuzhiyunyou issue a control or bulk request you can often expect to learn that
196*4882a593Smuzhiyunit completed in less than 250 usec (depending on transfer size).
197*4882a593Smuzhiyun
198*4882a593SmuzhiyunSoftware Performance
199*4882a593Smuzhiyun--------------------
200*4882a593Smuzhiyun
201*4882a593SmuzhiyunTo get even 20 MByte/sec transfer rates, Linux-USB device drivers will
202*4882a593Smuzhiyunneed to keep the EHCI queue full.  That means issuing large requests,
203*4882a593Smuzhiyunor using bulk queuing if a series of small requests needs to be issued.
204*4882a593SmuzhiyunWhen drivers don't do that, their performance results will show it.
205*4882a593Smuzhiyun
206*4882a593SmuzhiyunIn typical situations, a usb_bulk_msg() loop writing out 4 KB chunks is
207*4882a593Smuzhiyungoing to waste more than half the USB 2.0 bandwidth.  Delays between the
208*4882a593SmuzhiyunI/O completion and the driver issuing the next request will take longer
209*4882a593Smuzhiyunthan the I/O.  If that same loop used 16 KB chunks, it'd be better; a
210*4882a593Smuzhiyunsequence of 128 KB chunks would waste a lot less.
211*4882a593Smuzhiyun
212*4882a593SmuzhiyunBut rather than depending on such large I/O buffers to make synchronous
213*4882a593SmuzhiyunI/O be efficient, it's better to just queue up several (bulk) requests
214*4882a593Smuzhiyunto the HC, and wait for them all to complete (or be canceled on error).
215*4882a593SmuzhiyunSuch URB queuing should work with all the USB 1.1 HC drivers too.
216*4882a593Smuzhiyun
217*4882a593SmuzhiyunIn the Linux 2.5 kernels, new usb_sg_*() api calls have been defined; they
218*4882a593Smuzhiyunqueue all the buffers from a scatterlist.  They also use scatterlist DMA
219*4882a593Smuzhiyunmapping (which might apply an IOMMU) and IRQ reduction, all of which will
220*4882a593Smuzhiyunhelp make high speed transfers run as fast as they can.
221*4882a593Smuzhiyun
222*4882a593Smuzhiyun
223*4882a593SmuzhiyunTBD:
224*4882a593Smuzhiyun   Interrupt and ISO transfer performance issues.  Those periodic
225*4882a593Smuzhiyun   transfers are fully scheduled, so the main issue is likely to be how
226*4882a593Smuzhiyun   to trigger "high bandwidth" modes.
227*4882a593Smuzhiyun
228*4882a593SmuzhiyunTBD:
229*4882a593Smuzhiyun   More than standard 80% periodic bandwidth allocation is possible
230*4882a593Smuzhiyun   through sysfs uframe_periodic_max parameter. Describe that.
231