Statistics
| Branch: | Revision:

root / hw / usb / hcd-ehci.c @ 873123fe

History | View | Annotate | Download (79.1 kB)

# Date Author Comment
66f092d2 09/11/2012 08:42 am Hans de Goede

Revert "ehci: don't flush cache on doorbell rings."

This reverts commit 9bc3a3a216e2689bfcdd36c3e079333bbdbf3ba0, which got
added to fix an issue where the real, underlying cause was not stopping
the ep queue on an error.

Now that the underlying cause is fixed by the "usb: Halt ep queue and...

dafe31fc 09/11/2012 08:42 am Hans de Goede

ehci: Validate qh is not changed unexpectedly by the guest

-combine the qh check with the check for devaddr changes
-also ensure that p gets set to NULL when the queue gets cancelled on
devaddr change, which was not done properly before this patch

Signed-off-by: Hans de Goede <>

522079dd 09/11/2012 08:42 am Hans de Goede

ehci: Update copyright headers to reflect recent work

Update copyright headers to reflect all the work Gerd and I have been doing
on the EHCI emulation.

Signed-off-by: Hans de Goede <>

0e795352 09/11/2012 08:42 am Hans de Goede

ehci: Properly cleanup packets on cancel

Signed-off-by: Hans de Goede <>

4b63a0df 09/11/2012 08:42 am Hans de Goede

ehci: Properly report completed but not yet processed packets to the guest

Reported packets which have completed before being cancelled as such to the
host. Note that the new code path this patch adds is untested since it I've
been unable to actually trigger the race which needs this code path....

616789cd 09/11/2012 08:42 am Gerd Hoffmann

ehci: check for EHCI_ASYNC_FINISHED first in ehci_free_packet

Otherwise we'll see the packet free twice in the trace log even though
it actually happens only once.

Signed-off-by: Gerd Hoffmann <>

5c514681 09/11/2012 08:42 am Gerd Hoffmann

ehci: trace guest bugs

make qemu_queue_{cancel,reset} return the number of packets released,
so the caller can figure whenever there have been active packets even
though there shouldn't have been any. Add tracepoint to log this.

Signed-off-by: Gerd Hoffmann <>

1defcbd1 09/11/2012 08:42 am Gerd Hoffmann

ehci: add doorbell trace events

Signed-off-by: Gerd Hoffmann <>

3a8ca08e 09/11/2012 08:42 am Hans de Goede

ehci: Add some additional ehci_trace_guest_bug() calls

Signed-off-by: Hans de Goede <>
Signed-off-by: Gerd Hoffmann <>

ef5b2344 09/11/2012 08:42 am Hans de Goede

ehci: Fix memory leak in handling of NAK-ed packets

Currently each time we try to execute a NAK-ed packet we redo
ehci_init_transfer, and usb_packet_map, re-allocing (without freeing) the
sg list every time.

This patch fixes this, it does this by introducing another async state, so...

eff6dce7 09/11/2012 08:42 am Hans de Goede

ehci: Handle USB_RET_PROCERR in ehci_fill_queue

USB_RET_PROCERR can be triggered by the guest (by for example requesting more
then BUFFSIZE bytes), so don't assert on it.

Signed-off-by: Hans de Goede <>
Signed-off-by: Gerd Hoffmann <>

cf1f8169 09/11/2012 08:42 am Hans de Goede

ehci: Correct a comment in fetchqtd packet processing

Since my previous comment said "Should never happen", I tried changing the
next line to an assert(0), which did not go well, which as the new comments
explains is logical if you think about it for a moment....

45b339b1 09/11/2012 08:42 am Hans de Goede

usb: controllers do not need to check for babble themselves

If an (emulated) usb-device tries to write more data to a packet then
its iov len, this will trigger an assert in usb_packet_copy(), and if
a driver somehow circumvents that check and writes more data to the...

adf47834 08/31/2012 04:47 pm Hans de Goede

ehci: Fix interrupt endpoints no longer working

One of the recent changes (likely the addition of queuing support) has broken
interrupt endpoints, this patch fixes this.

Signed-off-by: Hans de Goede <>

287fd3f1 08/31/2012 04:47 pm Gerd Hoffmann

ehci: handle TD deactivation of inflight packets

Check the TDs of inflight packets, cancel
packets in case the guest clears the active bit.

Signed-off-by: Gerd Hoffmann <>

574ef171 08/31/2012 01:02 pm Hans de Goede

ehci: simplify ehci_state_executing

ehci_state_executing does not need to check for p->usb_status == USB_RET_ASYNC
or USB_RET_PROCERR, since ehci_execute_complete already does a similar check
and will trigger an assert if either value is encountered.

USB_RET_ASYNC should never be the packet status when execute_complete runs...

c7cdca3b 08/31/2012 01:02 pm Gerd Hoffmann

ehci: add ehci_cancel_queue()

Factor out function to cancel all packets of a queue.
No behavior change.

Signed-off-by: Gerd Hoffmann <>

a1c3e4b8 08/31/2012 12:58 pm Hans de Goede

ehci: Schedule async-bh when IAAD bit gets set

After the "ehci: Print a warning when a queue unexpectedly contains packets
on cancel" commit. Under certain reproducable conditions I was getting the
following message: "EHCI: Warning queue not empty on queue reset"....

53dd6f70 08/31/2012 12:58 pm Hans de Goede

ehci: Remove unnecessary ehci_flush_qh call

ehci_qh_do_overlay() already calls ehci_flush_qh() before it returns, calling
it twice is useless.

Signed-off-by: Hans de Goede <>
Signed-off-by: Gerd Hoffmann <>

7ce86aa1 08/31/2012 12:57 pm Hans de Goede

ehci: Fix NULL ptr deref when unplugging an USB dev with an iso stream active

Signed-off-by: Hans de Goede <>

e983395d 08/31/2012 12:57 pm Gerd Hoffmann

usb: unique packet ids

This patch adds IDs to usb packets. Those IDs are (a) supposed to be
unique for the lifecycle of a packet (from packet setup until the packet
is either completed or canceled) and (b) stable across migration.

uhci, ohci, ehci and xhci use the guest physical address of the transfer...

0132b4b6 08/31/2012 12:55 pm Hans de Goede

usb: Halt ep queue en cancel pending packets on a packet error

For controllers which queue up more then 1 packet at a time, we must halt the
ep queue, and inside the controller code cancel all pending packets on an
error.

There are multiple reasons for this:...

47d073cc 08/16/2012 12:48 pm Hans de Goede

ehci: Fix setting of halt bit from usbcmd register updates

This fixes linux guests started without any USB devices not seeing newly
plugged devices until "lsusb" is done inside the guest.

Signed-off-by: Hans de Goede <>
Signed-off-by: Gerd Hoffmann <>

6d3b6d3d 08/16/2012 09:39 am Gerd Hoffmann

ehci: fix Interrupt Threshold Control implementation

First, not all interrupts are subject to Interrupt Threshold Control,
some of them must be delivered without delay.

Second, Interrupt Threshold Control state must be part of vmstate,
otherwise we might loose IRQs on migration....

df6839c7 08/15/2012 05:18 pm Alejandro Martinez Ruiz

ehci: fix assertion typo

Signed-off-by: Alejandro Martinez Ruiz <>
Reviewed-by: Andreas Färber <>
Signed-off-by: Stefan Hajnoczi <>

f0ad01f9 07/12/2012 04:00 pm Gerd Hoffmann

ehci: raise irq in the frame timer

With the async schedule being kicked from other places than the frame
timer (commit 0f588df8b3688b00e77aabaa32e26ece5f19bd39) it may happen
that we call ehci_commit_interrupt() more than once per frame.

Move the call from the async schedule handler to the frame timer to...

7efc17af 07/12/2012 04:00 pm Gerd Hoffmann

ehci: implement Interrupt Threshold Control support

Also reorganize and comment the irq functions while being at it.

Signed-off-by: Gerd Hoffmann <>

afb7a0b8 07/12/2012 04:00 pm Gerd Hoffmann

ehci: improve expire time calculation

Move down the expire time calculation down in the frame timer, to the
point where the timer is actually reloaded. This way we'll notice any
async_stepdown changes (especially resetting to 0 due to usb activity).

Signed-off-by: Gerd Hoffmann <>

7341ea07 07/09/2012 12:59 pm Hans de Goede

usb-ehci: Fix an assert whenever isoc transfers are used

hcd-ehci.c is missing an usb_packet_init() call for the ipacket UsbPacket
it uses for isoc transfers, triggering an assert (taking the entire vm down)
in usb_packet_setup as soon as any isoc transfers are done by a high speed...

37952117 07/09/2012 12:59 pm Hans de Goede

ehci: Kick async schedule on wakeup in the non companion case

Commit 0f588df8b3688b00e77aabaa32e26ece5f19bd39, added code
to ehci_wakeup to kick the async schedule on wakeup, but the else
was positioned wrong making it trigger for devices which are routed...

9bc3a3a2 07/09/2012 12:59 pm Gerd Hoffmann

ehci: don't flush cache on doorbell rings.

Commit 4be23939ab0d7019c7e59a37485b416fbbf0f073 makes ehci instantly
zap any unlinked queue heads when the guest rings the doorbell.

While hacking up uas support this turned out to be a problem. The linux
kernel can unlink and instantly relink the very same queue head, thereby...

a5e0139a 07/09/2012 10:57 am Gerd Hoffmann

ehci: fix ehci_qh_do_overlay

Use ehci_flush_qh to make sure we touch inly the fields the hc is
allowed to touch.

Signed-off-by: Gerd Hoffmann <>

4ed1c57a 07/09/2012 10:57 am Gerd Hoffmann

ehci: fix td writeback

Only write back the dwords the hc is supposed to update. Should not
make a difference in theory as the guest must not touch the td while
it is active to avoid races. But it is still more correct.

Signed-off-by: Gerd Hoffmann <>

e2f89926 06/28/2012 12:33 am David Gibson

usb: Convert usb_packet_{map, unmap} to universal DMA helpers

The USB UHCI and EHCI drivers were converted some time ago to use the
pci_dma_*() helper functions. However, this conversion was not complete
because in some places both these drivers do DMA via the usb_packet_map()...

9a773408 06/20/2012 03:46 pm Gerd Hoffmann

ehci: add live migration support

Signed-off-by: Gerd Hoffmann <>

30e9d412 06/20/2012 03:46 pm Gerd Hoffmann

ehci: tracing improvements

Signed-off-by: Gerd Hoffmann <>

ec807d12 06/07/2012 11:02 am Gerd Hoffmann

ehci: add ehci_*_enabled() helpers

Add helper functions to query whenever the async / periodic schedule
is enabled or not. Put them into use too.

Signed-off-by: Gerd Hoffmann <>

b53f685d 06/07/2012 11:02 am Gerd Hoffmann

ehci: update status bits in ehci_set_state

Update the status register in the ehci_set_state function, to make sure
the guest-visible register is in sync with our internal schedule state.

Signed-off-by: Gerd Hoffmann <>

daf25307 06/07/2012 11:02 am Gerd Hoffmann

ehci: fix halt status handling

When the enable bits for controller / async schedule / periodic schedule
change just make sure we kick the frame timer and let
ehci_advance_periodic_state and ehci_advance_async_state handle the
controller state changes.

This will make ehci set USBSTS_HALT when the controller shutdown is...

863b4741 06/07/2012 11:02 am Gerd Hoffmann

ehci: remove unused attach_poll_counter

Signed-off-by: Gerd Hoffmann <>

6ceced0b 06/07/2012 11:02 am Gerd Hoffmann

ehci: create ehci_update_frindex

Factor out code from ehci_frame_timer.

Signed-off-by: Gerd Hoffmann <>

3a215326 06/07/2012 11:02 am Gerd Hoffmann

ehci: adaptive wakeup rate.

Adapt the frame timer sleeps according to the actual needs. With the
periodic schedule being active we'll have to wakeup 1000 times per
second and go check for work. In case only the async schedule is active
we can be more lazy though. When idle ehci will increate the sleep time...

f020ed36 06/07/2012 11:02 am Gerd Hoffmann

ehci: rework frame skipping

Move the framecount check out of the loop and use the new
ehci_update_frindex function to skip frames if needed.

Signed-off-by: Gerd Hoffmann <>

eb36a88e 06/07/2012 11:02 am Gerd Hoffmann

ehci: add EHCIPacket

Add a separate EHCIPacket struct and move fields over from EHCIQueue.
Preparing for supporting multiple packets per queue being in flight at
the same time. No functional changes yet.

Fix some codestyle issues along the way.

Signed-off-by: Gerd Hoffmann <>

4224558f 06/07/2012 11:02 am Gerd Hoffmann

ehci: make ehci_execute work on EHCIPacket instead of EHCIQueue

This way it is possible to use ehci_execute to submit others than the
first EHCIPacket of the EHCIQueue.

Signed-off-by: Gerd Hoffmann <>

e59928b3 06/07/2012 11:02 am Gerd Hoffmann

ehci: cache USBDevice in EHCIQueue

Keep a USBDevice pointer in EHCIQueue so we don't have to lookup the
device on each usb packet submission.

Signed-off-by: Gerd Hoffmann <>

cd665715 06/07/2012 11:02 am Gerd Hoffmann

ehci: move ehci_flush_qh

Move ehci_flush_qh() function up in the source code.
No code change.

Signed-off-by: Gerd Hoffmann <>

773dc9cd 06/07/2012 11:02 am Gerd Hoffmann

ehci: add queuing support

Add packet queuing. Follow the qTD chain to see if there are more
packets we can submit. Improves performance on larger transfers,
especially with usb-host, as we don't have to wait for a packet to
finish before sending the next one to the host for processing....

8f6d5e26 06/07/2012 11:02 am Gerd Hoffmann

ehci: tweak queue initialization

Little tweak for the queue initialization, set the QH address in the
allocation function.

Signed-off-by: Gerd Hoffmann <>

ae0138a8 06/07/2012 11:02 am Gerd Hoffmann

ehci: add async field to EHCIQueue

Keep track whenever a EHCIQueue is part of the async or periodic
schedule. This way we don't have to pass around the async flag
everywhere but can look it up from the EHCIQueue struct when needed.

Signed-off-by: Gerd Hoffmann <>

0fb3e299 06/07/2012 11:02 am Gerd Hoffmann

ehci: move async schedule to bottom half

This way we can kick the async schedule independant from the
periodic frame timer.

Signed-off-by: Gerd Hoffmann <>

ae710b99 06/07/2012 11:02 am Gerd Hoffmann

ehci: schedule async bh on async packet completion

When a packet completes which happens to be part of the async schedule
kick the async bottom half for processing,

Signed-off-by: Gerd Hoffmann <>

0f588df8 06/07/2012 11:02 am Gerd Hoffmann

ehci: kick async schedule on wakeup

Kick async schedule when we get a wakeup
notification from a usb device.

Signed-off-by: Gerd Hoffmann <>

7046530c 06/07/2012 11:02 am Gerd Hoffmann

ehci: fix reset

Check for the reset bit first when processing USBCMD register writes.
Also break out of the switch, there is no need to check the other bits.

Signed-off-by: Gerd Hoffmann <>

a31f0531 05/14/2012 08:27 am Jim Meyering

fix some common typos

These were identified using: http://github.com/lyda/misspell-check
and run like this to create a bourne shell script using GNU sed's
-i option:

git ls-files|grep -vF .bin | misspellings -f - |grep -v '^ERROR:' |perl \
-pe 's/^(.*?)\[(\d+)\]: (\w+) -> "(.*?)"$/sed -i '\''${2}s!$3!$4!'\'' $1/'...

e59a8cf1 04/26/2012 01:21 pm Gerd Hoffmann

usb-ehci: remove hack

To answer the question in the comment removed by this patch: I think
this was needed because several places in the ehci emulation did not
check the T bit of link entries correctly and thus might have followed
invalid references. See commit 2a5ff735dc1074171a0cbb1dc228d6d6e907f571...

0cc6a0f1 04/26/2012 01:21 pm Gerd Hoffmann

usb-ehci: add missing usb_packet_init() call

Signed-off-by: Gerd Hoffmann <>

8a771f77 04/26/2012 01:21 pm Hans de Goede

usb-ehci: Ensure frindex writes leave a valid frindex value

frindex is a 14 bits counter, so bits 31-14 should always be 0, and
after the commit titled "usb-ehci: frindex always is a 14 bits counter"
we rely on frindex always being a multiple of 8. I've not seen this in...

c7020c97 04/17/2012 11:23 am Gerd Hoffmann

usb-ehci: drop assert()

Not sure what the purpose of the assert() was, in any case it is bogous.
We can arrive there if transfer descriptors passed to us from the guest
failed to pass sanity checks, i.e. it is guest-triggerable. We deal
with that case by resetting the host controller. Everything is ok, no...

088351a7 04/17/2012 11:23 am Gerd Hoffmann

usb-ehci: fix ehci_child_detach

Looks like a cut+paste bug from ehci_detach. When the device itself is
detached from a ehci port (ehci_detach op) we have to clear the
device pointer for the companion port too. When a device gets removed
from a downstream port of a usb hub (ehci_child_detach op) the ehci port...

58ea88d8 04/17/2012 11:23 am Hans de Goede

usb-ehci: frindex always is a 14 bits counter

frindex always is a 14 bits counter, and not a 13 bits one as we were
emulating. There are some subtle hints to this in the spec, first of all
"Table 2-12. FRINDEX - Frame Index Register" says:
"Bit 13:0 Frame Index. The value in this register increments at the end of...

8e24283b 04/17/2012 11:23 am Hans de Goede

usb-ehci: Drop unused sofv value

The sofv value only ever gets a value assigned and is never used (read)
anywhere, so we can just drop it.

Signed-off-by: Hans de Goede <>
Signed-off-by: Gerd Hoffmann <>

f1ae32a1 03/13/2012 11:15 am Gerd Hoffmann

usb: the big rename

Reorganize usb source files. Create a new hw/usb/ directory and move
all usb source code to that place. Also make filenames a bit more
descriptive. Host adapters are prefixed with "hch-" now, usb device
emulations are prefixed with "dev-". Fixup paths Makefile and include...

fcb70eca 03/13/2012 11:15 am Hans de Goede

usb-ehci: drop unused isoch_pause variable

Signed-off-by: Hans de Goede <>
Signed-off-by: Gerd Hoffmann <>