History | View | Annotate | Download (73.1 kB)
usb: Add an usb_device_ep_stopped USBDevice method
Some usb devices (host or network redirection) can benefit from knowing whenthe guest stops using an endpoint. Redirection may involve submitting packetsindependently from the guest (in combination with a fifo buffer between the...
ehci: Add a ehci_writeback_async_complete_packet helper function
Also drop the warning printf, which was there mainly because this was anuntested code path (as the previous bug fixes to it show), but that nolonger is the case now :)
Signed-off-by: Hans de Goede <hdegoede@redhat.com>...
ehci: Add ehci_verify_qh and ehci_verify_qtd helper functions
Signed-off-by: Hans de Goede <hdegoede@redhat.com>Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
ehci: Verify guest does not change the token of inflight qtd-s
This is not allowed, except for clearing active on cancellation, so don'twarn when the new token does not have its active bit set.
This unifies the cancellation path for modified qtd-s, and prepares...
ehci: Move get / put_dwords upwards
No other changes.
ehci: writeback_async_complete_packet: verify qh and qtd
ehci: Verify qtd for async completed packets
Remove the short-circuiting of fetchqtd in fetchqh, so that theqtd gets properly verified before completing the transaction.
ehci: Add an ehci_get_pid helper function
ehci: Verify a queue's ep direction does not change
ehci_fill_queue assumes that there is a one on one relationship between an epand a qh, this patch adds a check to ensure this.
Note I don't expect this to ever trigger, this is just something I noticed...
ehci: Use uframe precision for interrupt threshold checking (v2)
Before this patch, the following could happen:1) Transfer completes, raises interrupt2) .5 ms later we check if the guest has queued up any new transfers3) We find and execute a new transfer...
ehci: Further speedup rescanning if async schedule after raising an interrupt
I tried lowering the time between raising an interrupt and rescanning theasync schedule to see if the guest has queued a new transfer before, butthat did not have any positive effect. I now believe the cause for this is...
ehci: Don't call commit_irq after raising PCD
ehci_raise_irq(s, USBSTS_PCD), gets applied immediately so there is no needto call commit_irq after it.
ehci: Lower timer freq when the periodic schedule is idle
Lower the timer freq if no iso schedule packets complete for 64 frames ina row.
We can safely do this, without adding latency, because:1) If there is isoc traffic this will never trigger2) For async handled interrupt packets (only usb-host), the completion handler...
ehci: Don't access packet after freeing it
ehci_state_writeback() will free the packet, so we should not accessthe packet after calling ehci_state_writeback().
ehci: Fixup q->qtdaddr after cancelling an already completed packet
This avoids the q->qtdaddr == p->qtdaddr asserts we have triggering, whena queue contains multiple completed packages when we cancel the queue.
I triggered this with windows7 + async interrupt endpoint handling (*)...
ehci: Better detection for qtd-s linked in circles
Windows links interrupt qtd-s in circles, which means that when interruptendpoints return USB_RET_ASYNC, combined with the recent"ehci: Retry to fill the queue while waiting for td completion" patch,we keep adding the tds to the queue over and over again, as we detect the...
ehci: Don't verify the next pointer for periodic qh-s and qtd-s
While testing the move to async packet handling for interrupt endpoints Inoticed that Windows-XP likes to play tricks with the next pointer forperiodic qh-s, so we should not fail qh / qtd verification when it changes....
ehci: keep the frame timer running in case the guest asked for frame list rollover interrupts
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
ehci: handle dma errors
Starting with commit 1c380f9460522f32c8dd2577b2a53d518ec91c6d dmatransfers can actually fail. This patch makes ehci keep trackof the busmaster bit in pci config space, by setting/clearing thedma_context pointer. Attempts to dma without context will result...
ehci: Add support for packets with both data and an error status
usb: split packet result into actual_length + status
Since with the ehci and xhci controllers a single packet can be largerthen maxpacketsize, it is possible for the result of a single packetto be both having transferred some data as well as the transfer to have...
ehci: Get rid of the magical PROC_ERR status
Instead make ehci_execute and ehci_fill_queue return the again value.
usb/ehci: seperate out PCIisms
Seperate the PCI stuff from the EHCI components. Extracted the PCIDeviceout into a new wrapper struct to make EHCIState non-PCI-specific. Seperatedtho non PCI init component out into a seperate "common" init function.
Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>...
usb/ehci: Guard definition of EHCI_DEBUG
Guard against re-definition of EHCI_DEBUG. Allows for turning on of debug infofrom configure (using --qemu-extra-cflags="-DEHCI_DEBUG=1") rather than sourcecode hacking.
usb/ehci: split into multiple source files
usb/ehci: parameterise the register region offsets
The capabilities register and operational register offsets can vary from oneEHCI implementation to the next. Parameterise accordingly.
Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
usb/ehci: Abstract away PCI DMA API
Pull the DMAContext for the PCI DMA out at device init time and put it intothe device state. Use dma_memory_read/write() instead of pci specific versions.
usb: Move clearing of queue on halt to the core
hcds which queue up more then one packet at once (uhci, ehci and xhci),must clear the queue after an error which has caused the queue to halt.
Currently this is handled as a special case inside the hcd code, this...
usb: Move short-not-ok handling to the core
After a short-not-ok packet ending short, we should not advance the queue.Move enforcing this to the core, rather then handling it in the hcd code.
This may result in the queue now actually containing multiple input packets...
usb: Add an int_req flag to USBPacket
usb: Enforce iso endpoints never returing USB_RET_ASYNC
ehci was already testing for this, and we depend in various placeson no devices doing this, so lets move the check for this to theusb core.
ehci: Get rid of packet tbytes field
This field is used in some places to track the tbytes field of the token, butin other places the field is used directly, use it directly everywhere forconsistency.
ehci: Set int flag on a short input packet
According to 4.15.1.2 an interrupt must be raised when a short packetis received. If we don't do this it may take a significant time forthe guest to notice a short trasnfer has completed, since only the last td...
ehci: Improve latency of interrupt delivery and async schedule scanning
While doing various performance tests of reading from USB mass storage devicesI noticed the following::1) When an async handled packet completes, we don't immediately report an interrupt to the guest, instead we wait for the frame-timer to run and...
ehci: Speed up the timer of raising int from the async schedule
Often the guest will queue up new packets in response to a packet, in theasync schedule with its IOC flag set, completing. By speeding up theframe-timer, we notice these new packets earlier. This increases the...
ehci: Detect going in circles when filling the queue
For ctrl endpoints Windows (atleast Win7) creates circular td lists, so farthese were not a problem because we would stop filling the queue if altnextwas set. Since further patches in this patchset remove the altnext check this...
ehci: Retry to fill the queue while waiting for td completion
If the guest is using multiple transfers to try and keep the usb bus busy /used at maximum efficiency, currently we would see / do the following:
1) submit transfer 1 to the device2) submit transfer 2 to the device...
usb: Add USB_RET_ADD_TO_QUEUE packet result code
This can be used by usb-device code which wishes to process an entire endpointqueue at once, to do this the usb-device code returns USB_RET_ADD_TO_QUEUEfrom its handle_data class method and defines a flush_ep_queue class method...
Rename target_phys_addr_t to hwaddr
target_phys_addr_t is unwieldly, violates the C standard (_t suffixes arereserved) and its purpose doesn't match the name (most target_phys_addr_taddresses are not target specific). Replace it with a finger-friendly,...
ehci: Fix interrupt packet MULT handling
There are several issues with our handling of the MULT epcap fieldof interrupt qhs, which this patch fixes.
1) When we don't execute a transaction because of the transaction counterbeing 0, p->async stays EHCI_ASYNC_NONE, and the next time we process the...
ehci: Don't set seen to 0 when removing unseen queue-heads
When removing unseen queue-heads from the async queue list, we should notset the seen flag to 0, as this may cause them to be removed byehci_queues_rip_unused() during the next call to ehci_advance_async_state()...
ehci: Walk async schedule before and after migration
ehci: switch to new-style memory ops
Also register different memory regions for capabilities,operational registers and port status registers. Createseparate tracepoints for operational regs and port statusregs. Ditch a bunch of sanity checks because the memory...
ehci: Fix interrupts stopping when Interrupt Threshold Control is 8
If Interrupt Threshold Control is 8 or a multiple of 8, thens->usbsts_frindex can become exactly 0x4000, at which point(s->usbsts_frindex > s->frindex) will never become true, ass->usbsts_frindex will not be lowered / reset in this case....
ehci: Don't process too much frames in 1 timer tick (v2)
The Linux ehci isoc scheduling code fills the entire schedule ahead oftime minus 80 frames. If we make a large jump in where we are in theschedule, ie 40 frames, then the scheduler all of a sudden will only have...
Revert "ehci: don't flush cache on doorbell rings."
This reverts commit 9bc3a3a216e2689bfcdd36c3e079333bbdbf3ba0, which gotadded to fix an issue where the real, underlying cause was not stoppingthe ep queue on an error.
Now that the underlying cause is fixed by the "usb: Halt ep queue and...
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 <hdegoede@redhat.com>
ehci: Update copyright headers to reflect recent work
Update copyright headers to reflect all the work Gerd and I have been doingon the EHCI emulation.
ehci: Properly cleanup packets on cancel
ehci: Properly report completed but not yet processed packets to the guest
Reported packets which have completed before being cancelled as such to thehost. Note that the new code path this patch adds is untested since it I'vebeen unable to actually trigger the race which needs this code path....
ehci: check for EHCI_ASYNC_FINISHED first in ehci_free_packet
Otherwise we'll see the packet free twice in the trace log even thoughit actually happens only once.
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 eventhough there shouldn't have been any. Add tracepoint to log this.
ehci: add doorbell trace events
ehci: Add some additional ehci_trace_guest_bug() calls
ehci: Fix memory leak in handling of NAK-ed packets
Currently each time we try to execute a NAK-ed packet we redoehci_init_transfer, and usb_packet_map, re-allocing (without freeing) thesg list every time.
This patch fixes this, it does this by introducing another async state, so...
ehci: Handle USB_RET_PROCERR in ehci_fill_queue
USB_RET_PROCERR can be triggered by the guest (by for example requesting morethen BUFFSIZE bytes), so don't assert on it.
ehci: Correct a comment in fetchqtd packet processing
Since my previous comment said "Should never happen", I tried changing thenext line to an assert(0), which did not go well, which as the new commentsexplains is logical if you think about it for a moment....
usb: controllers do not need to check for babble themselves
If an (emulated) usb-device tries to write more data to a packet thenits iov len, this will trigger an assert in usb_packet_copy(), and ifa driver somehow circumvents that check and writes more data to the...
ehci: Fix interrupt endpoints no longer working
One of the recent changes (likely the addition of queuing support) has brokeninterrupt endpoints, this patch fixes this.
ehci: handle TD deactivation of inflight packets
Check the TDs of inflight packets, cancelpackets in case the guest clears the active bit.
ehci: simplify ehci_state_executing
ehci_state_executing does not need to check for p->usb_status == USB_RET_ASYNCor USB_RET_PROCERR, since ehci_execute_complete already does a similar checkand will trigger an assert if either value is encountered.
USB_RET_ASYNC should never be the packet status when execute_complete runs...
ehci: add ehci_cancel_queue()
Factor out function to cancel all packets of a queue.No behavior change.
ehci: Schedule async-bh when IAAD bit gets set
After the "ehci: Print a warning when a queue unexpectedly contains packetson cancel" commit. Under certain reproducable conditions I was getting thefollowing message: "EHCI: Warning queue not empty on queue reset"....
ehci: Remove unnecessary ehci_flush_qh call
ehci_qh_do_overlay() already calls ehci_flush_qh() before it returns, callingit twice is useless.
ehci: Fix NULL ptr deref when unplugging an USB dev with an iso stream active
usb: unique packet ids
This patch adds IDs to usb packets. Those IDs are (a) supposed to beunique for the lifecycle of a packet (from packet setup until the packetis either completed or canceled) and (b) stable across migration.
uhci, ohci, ehci and xhci use the guest physical address of the transfer...
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 theep queue, and inside the controller code cancel all pending packets on anerror.
There are multiple reasons for this:...
ehci: Fix setting of halt bit from usbcmd register updates
This fixes linux guests started without any USB devices not seeing newlyplugged devices until "lsusb" is done inside the guest.
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....
ehci: fix assertion typo
Signed-off-by: Alejandro Martinez Ruiz <alex@securiforest.com>Reviewed-by: Andreas Färber <afaerber@suse.de>Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
ehci: raise irq in the frame timer
With the async schedule being kicked from other places than the frametimer (commit 0f588df8b3688b00e77aabaa32e26ece5f19bd39) it may happenthat we call ehci_commit_interrupt() more than once per frame.
Move the call from the async schedule handler to the frame timer to...
ehci: implement Interrupt Threshold Control support
Also reorganize and comment the irq functions while being at it.
ehci: improve expire time calculation
Move down the expire time calculation down in the frame timer, to thepoint where the timer is actually reloaded. This way we'll notice anyasync_stepdown changes (especially resetting to 0 due to usb activity).
usb-ehci: Fix an assert whenever isoc transfers are used
hcd-ehci.c is missing an usb_packet_init() call for the ipacket UsbPacketit 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...
ehci: Kick async schedule on wakeup in the non companion case
Commit 0f588df8b3688b00e77aabaa32e26ece5f19bd39, added codeto ehci_wakeup to kick the async schedule on wakeup, but the elsewas positioned wrong making it trigger for devices which are routed...
ehci: don't flush cache on doorbell rings.
Commit 4be23939ab0d7019c7e59a37485b416fbbf0f073 makes ehci instantlyzap any unlinked queue heads when the guest rings the doorbell.
While hacking up uas support this turned out to be a problem. The linuxkernel can unlink and instantly relink the very same queue head, thereby...
ehci: fix ehci_qh_do_overlay
Use ehci_flush_qh to make sure we touch inly the fields the hc isallowed to touch.
ehci: fix td writeback
Only write back the dwords the hc is supposed to update. Should notmake a difference in theory as the guest must not touch the td whileit is active to avoid races. But it is still more correct.
usb: Convert usb_packet_{map, unmap} to universal DMA helpers
The USB UHCI and EHCI drivers were converted some time ago to use thepci_dma_*() helper functions. However, this conversion was not completebecause in some places both these drivers do DMA via the usb_packet_map()...
ehci: add live migration support
ehci: tracing improvements
ehci: add ehci_*_enabled() helpers
Add helper functions to query whenever the async / periodic scheduleis enabled or not. Put them into use too.
ehci: update status bits in ehci_set_state
Update the status register in the ehci_set_state function, to make surethe guest-visible register is in sync with our internal schedule state.
ehci: fix halt status handling
When the enable bits for controller / async schedule / periodic schedulechange just make sure we kick the frame timer and letehci_advance_periodic_state and ehci_advance_async_state handle thecontroller state changes.
This will make ehci set USBSTS_HALT when the controller shutdown is...
ehci: remove unused attach_poll_counter
ehci: create ehci_update_frindex
Factor out code from ehci_frame_timer.
ehci: adaptive wakeup rate.
Adapt the frame timer sleeps according to the actual needs. With theperiodic schedule being active we'll have to wakeup 1000 times persecond and go check for work. In case only the async schedule is activewe can be more lazy though. When idle ehci will increate the sleep time...
ehci: rework frame skipping
Move the framecount check out of the loop and use the newehci_update_frindex function to skip frames if needed.
ehci: add EHCIPacket
Add a separate EHCIPacket struct and move fields over from EHCIQueue.Preparing for supporting multiple packets per queue being in flight atthe same time. No functional changes yet.
Fix some codestyle issues along the way.
ehci: make ehci_execute work on EHCIPacket instead of EHCIQueue
This way it is possible to use ehci_execute to submit others than thefirst EHCIPacket of the EHCIQueue.
ehci: cache USBDevice in EHCIQueue
Keep a USBDevice pointer in EHCIQueue so we don't have to lookup thedevice on each usb packet submission.
ehci: move ehci_flush_qh
Move ehci_flush_qh() function up in the source code.No code change.
ehci: add queuing support
Add packet queuing. Follow the qTD chain to see if there are morepackets we can submit. Improves performance on larger transfers,especially with usb-host, as we don't have to wait for a packet tofinish before sending the next one to the host for processing....
ehci: tweak queue initialization
Little tweak for the queue initialization, set the QH address in theallocation function.
ehci: add async field to EHCIQueue
Keep track whenever a EHCIQueue is part of the async or periodicschedule. This way we don't have to pass around the async flageverywhere but can look it up from the EHCIQueue struct when needed.
ehci: move async schedule to bottom half
This way we can kick the async schedule independant from theperiodic frame timer.
ehci: schedule async bh on async packet completion
When a packet completes which happens to be part of the async schedulekick the async bottom half for processing,
ehci: kick async schedule on wakeup
Kick async schedule when we get a wakeupnotification from a usb device.
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.
fix some common typos
These were identified using: http://github.com/lyda/misspell-checkand 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/'...