aboutsummaryrefslogtreecommitdiff
path: root/hw/usb
AgeCommit message (Collapse)Author
2012-05-14Merge remote-tracking branch 'kraxel/usb.50' into stagingAnthony Liguori
* kraxel/usb.50: usb-host: handle guest-issued clear halt
2012-05-14usb-host: handle guest-issued clear haltGerd Hoffmann
Most important here is to update our internal endpoint state so we know the endpoint isn't in halted state any more. Without this usb-host tries to clear halt again with the next data transfer submitted. Doing this twice is (a) not correct and (b) confuses some usb devices, rendering them non-functional in the guest. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-05-14fix some common typosJim Meyering
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/' Manually eliding the FP, "rela->real" and resolving "addres" to address (not "adders") we get this: sed -i '450s!thru!through!' Changelog sed -i '260s!neccessary!necessary!' coroutine-sigaltstack.c sed -i '54s!miniscule!minuscule!' disas.c sed -i '1094s!thru!through!' hw/usb/hcd-ehci.c sed -i '1095s!thru!through!' hw/usb/hcd-ehci.c sed -i '21s!unecessary!unnecessary!' qapi-schema-guest.json sed -i '307s!explictly!explicitly!' qemu-ga.c sed -i '490s!preceeding!preceding!' qga/commands-posix.c sed -i '792s!addres!address!' qga/commands-posix.c sed -i '6s!beeing!being!' tests/tcg/test-mmap.c Also, manually fix "arithmentic", spotted by Peter Maydell: sed -i 's!arithmentic!arithmetic!' coroutine-sigaltstack.c Signed-off-by: Jim Meyering <meyering@redhat.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2012-04-26usb-uhci: update irq line on resetGerd Hoffmann
uhci_reset() clears irq mask and irq status registers, but doesn't update the irq line. Which may result in suspious IRQs after uhci reset. Fix it. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-26usb: add serial number generatorGerd Hoffmann
This patch adds a function which creates unique serial numbers for usb devices and puts it into use. Windows guests tend to become unhappy if they find two identical usb devices in the system. Effects range from non-functional devices (with yellow exclamation mark in device manager) to BSODs. Handing out unique serial numbers to devices fixes this. With this patch applied almost all emulated devices get a generated, unique serial number. There are two exceptions: * usb-storage devices will prefer a user-specified serial number and will only get a generated number in case the serial property is unset. * usb-hid devices keep the fixed serial number "42" as it is used to signal "remote wakeup actually works". See commit 7b074a22dab4bdda9864b933f1bc811a3db42845 Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-26usb-redir: Not finding an async urb id is not an errorHans de Goede
We clear our pending async urb list on device disconnect and we may still receive "packet complete" packets from our peer after this, which will then refer to packet ids no longer in our list. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-26usb-redir: Reset device address and speed on disconnectHans de Goede
Without this disconnected devices look like the last redirected device in the monitor in "info usb". Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-26usb-redir: An interface count of 0 is a valid valueHans de Goede
An interface-count of 0 happens when a device is in unconfigured state when it gets redirected. So we should not use 0 to detect not having received interface info from our peer. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-26usb-xhci: fix bit testLai Jiangshan
use & instead of the wrong && Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-26usb-xhci: Use PCI DMA helper functionsDavid Gibson
Shortly before 1.0, we added helper functions / wrappers for doing PCI DMA from individual devices. This makes what's going on clearer and means that when we add IOMMU support somewhere in the future, only the general PCI code will have to change, not every device that uses PCI DMA. However, usb-xhci is not using these wrappers, despite being a PCI only device. This patch remedies the situation, using the pci dma functions instead of direct calls to cpu_physical_memory_{read,write}(). Likewise address parameters for DMA are changed to dma_addr_t instead of target_phys_addr_t. [ kraxel: removed #ifdefs ] Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-26usb-host: fix zero-length packetsGerd Hoffmann
usb-host optimizes away zero-length packets by not entering the processing loop at all. Which isn't correct, we should submit a zero-length urb to the host devicein that case. This patch makes sure we run the processing loop at least once. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-26usb-host: don't dereference invalid iovecsGerd Hoffmann
usb-host assumes the first iovec element is always valid. In case of a zero-length packet this isn't true though. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-26usb-storage: fix request cancelingGerd Hoffmann
Little fix for usb packet handling on i/o cancelation. The usb packet pointer (s->packet) is cleared at the wrong place: The scsi request cancel handler does it. When a usb packet is canceled the usb-storage emulation canceles the scsi request if present. In most cases there is one, so usually s->packet is cleared as needed even with the code sitting at the wrong place. If there is no scsi request in flight s->packet is not cleared though. The usb-storage emulation will then try to complete an usb packet which is not in flight any more and thereby trigger an assert() in the usb core. Fix this by clearing s->packet at the correct place, which is the usb packet cancel header. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-26usb-ehci: Ensure frindex writes leave a valid frindex valueHans de Goede
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 practice, but theoretically a guest can write a value >= 0x4000 or a value which is not a multiple of 8 value to frindex, this patch ensures that things will still work when that happens. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-26usb-ehci: add missing usb_packet_init() callGerd Hoffmann
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-26usb-ehci: remove hackGerd Hoffmann
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 Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-17usb-ehci: drop assert()Gerd Hoffmann
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 need to throw a core dump here. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-17usb-redir: Notify our peer when we reject a device due to a speed mismatchHans de Goede
Also cleanup (reset) our device state when we reject a device due to a speed mismatch. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-17usb-ehci: Drop unused sofv valueHans de Goede
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 <hdegoede@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-17usb-host: rewrite usb_linux_update_endp_tableGerd Hoffmann
This patch carries a complete rewrite of the usb descriptor parser. Changes / improvements: * We are using the USBDescriptor struct instead of hard-coded offsets now to access descriptor data. * (debug) printfs are all gone, tracepoints have been added instead. * We don't try (and fail) to skip over unneeded descriptors. We parse them all one by one. We keep track of which configuration, interface and altsetting we are looking at and use this information to figure which desciptors are in use and which we can ignore. * On parse errors we clear all endpoint information, which will disallow any communication with the device, except control endpoint messages. This makes sure we don't end up with a silly device state where half of the endpoints got enabled and the other half was left disabled. * Some sanity checks have been added. The new parser is more robust and also leaves complete device information in the trace log if you enable the ush_host_parse_* tracepoints. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-17usb: use USBDescriptor for endpoint descriptors.Gerd Hoffmann
Add endpoint descriptor substruct to USBDescriptor, use it in the descriptor generator code. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-17usb: use USBDescriptor for interface descriptors.Gerd Hoffmann
Add interface descriptor substruct to USBDescriptor, use it in the descriptor generator code. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-17usb: use USBDescriptor for config descriptors.Gerd Hoffmann
Add config descriptor substruct to USBDescriptor, use it in the descriptor generator code. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-17usb: use USBDescriptor for device qualifier descriptors.Gerd Hoffmann
Add device qualifier substruct to USBDescriptor, use it in the descriptor generator code. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-17usb: add USBDescriptor, use for device descriptors.Gerd Hoffmann
This patch adds a new type for the binary representation of usb descriptors. It is put into use for the descriptor generator code where the struct replaces the hard-coded offsets. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-17usb-ehci: frindex always is a 14 bits counterHans de Goede
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 each time frame (e.g. micro-frame). Bits [N:3] are used for the Frame List current index. This means that each location of the frame list is accessed 8 times (frames or micro-frames) before moving to the next index. The following illustrates values of N based on the value of the Frame List Size field in the USBCMD register. USBCMD[Frame List Size] Number Elements N 00b 1024 12 01b 512 11 10b 256 10 11b Reserved" Notice how the text talks about "Bits [N:3]" are used ..., it does NOT say that when N == 12 (our case) the counter will wrap from 8191 to 0, or in otherwords that it is a 13 bits counter (bits 0 - 12). The other hint is in "Table 2-10. USBSTS USB Status Register Bit Definitions": "Bit 3 Frame List Rollover - R/WC. The Host Controller sets this bit to a one when the Frame List Index (see Section 2.3.4) rolls over from its maximum value to zero. The exact value at which the rollover occurs depends on the frame list size. For example, if the frame list size (as programmed in the Frame List Size field of the USBCMD register) is 1024, the Frame Index Register rolls over every time FRINDEX[13] toggles. Similarly, if the size is 512, the Host Controller sets this bit to a one every time FRINDEX[12] toggles." Notice how this text talks about setting bit 3 when bit 13 of frindex toggles (when there are 1024 entries, so our case), so this indicates that frindex has a bit 13 making it a 14 bit counter. Besides these clear hints the real proof is in the pudding. Before this patch I could not stream data from a USB2 webcam under Windows XP, after this cam using a USB2 webcam under Windows XP works fine, and no regressions with other operating systems were seen. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-17usb-ehci: fix ehci_child_detachGerd Hoffmann
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 where the usb hub is plugged in is not affected. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-17usb-hub: add tracepointsGerd Hoffmann
Add tracepoints to the usb hub emulation. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-17usb_packet_set_state: handle p->ep == NULLGerd Hoffmann
usb_packet_set_state can be called with p->ep = NULL. The tracepoint there tries to log endpoint information, which leads to a segfault. This patch makes usb_packet_set_state handle the NULL pointer properly. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-17usb-host: add property to turn off pipeliningGerd Hoffmann
Add a property to usb-host to disable the bulk endpoint pipelining. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-17usb-host: add usb packet to request tracepointsGerd Hoffmann
Add pointer to USBPacket to all tracepoints tracking requests to make it easier to identify them when multiple requests are in flight. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-17usb-host: trace canceled requestsGerd Hoffmann
Add tracepoints to track canceled requests. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-17usb-host: trace emulated requestsGerd Hoffmann
Add tracepoint to track completion of emulated control requests. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-17Add bootindex support to usb-host and usb-redirGerd Hoffmann
When passing through a usb pendrive seabios will present it in the F12 boot menu and will happily boot from it. This patch adds bootorder support so you can even make it the default boot device. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-17usb-uhci: queuing fixGerd Hoffmann
When we queue up usb packets we may happen to find a already queued packet, which also might be finished at that point already. We don't want continue processing the packet at this point though, so lets just signal back we've found a in-flight packet when in queuing mode. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-17usb-uhci: stop queue filling when we find a in-flight tdGerd Hoffmann
Not only QHs can form rings, but TDs too. With the new queuing/pipelining support we are following TD chains and can actually walk in circles. An assert() prevents us from entering an endless loop then. Fix is easy: Just stop queuing when we figure the TD we are about to queue up is in flight already. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-17usb/vmstate: add parent dev pathGerd Hoffmann
... to make vmstate id string truely unique with multiple host controllers, i.e. move from "1/usb-ptr" to "0000:00:01.3/1/usb-ptr" (usb tabled connected to piix3 uhci). This obviously breaks migration. To handle this the usb bus property "full-path" is added. When setting this to false old behavior is maintained. This way current qemu will be compatible with old versions when started using '-M pc-$oldversion'. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-04-09qdev: qdev_unplug(): use error_set()Luiz Capitulino
It currently uses qerror_report(), but next commit will convert the drive_del command to the QAPI and this requires using error_set(). One particularity of qerror_report() is that it knows when it's running on monitor context or command-line context and prints the error message accordingly. error_set() doesn't do this, so we have to be careful not to drop error messages. qdev_unplug() has three kinds of usages: 1. It's called when hot adding a device fails, to undo anything that has been done before hitting the error 2. It's called by function monitor functions like device_del(), to unplug a device 3. It's used by xen_platform.c in a way that doesn't _seem_ to be in monitor context Only item 2 can print an error message to the user, this commit maintains that. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2012-03-13Endian fix an assertion in usb-msdBenjamin Herrenschmidt
This fixes a broken endian assumption in an assertion in usb-msd. Cc: Gerd Hoffman <kraxel@redhat.com> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-03-13uhci: alloc can't fail, drop check.Gerd Hoffmann
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-03-13uhci: new uhci_handle_td return code for tds still in flightGerd Hoffmann
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-03-13uhci: renumber uhci_handle_td return codesGerd Hoffmann
Step #2 (separate for better bisectability): renumber so the silly '-1' goes away. Pick a range which doesn't overlap the old values. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-03-13uhci: use enum for uhci_handle_td return codesGerd Hoffmann
Step #1 (separate for better bisectability): replace numbers with names. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-03-13uhci: tracing supportGerd Hoffmann
Zap DPRINTF, add tracepoints instead. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-03-13uhci: cancel on schedule stop.Gerd Hoffmann
Cancel any in-flight transaction when the guest stops the uhci schedule. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-03-13uhci: fix uhci_async_cancel_allGerd Hoffmann
It should also free all queues. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-03-13uhci: pass addr to uhci_async_allocGerd Hoffmann
Also do async->td initialization in uhci_async_alloc now. Prepares for adding tracepoints. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-03-13usb: improve packet state sanity checksGerd Hoffmann
Add a new function to check whenever the packet state is as expected, log more informations in case it isn't. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-03-13usb-ohci: DMA writeback bug fixesWei Yang
This patch fixes two bugs in the OHCI device where the device writes back data to system memory that should be exclusively under the control of the guest side driver. In OHCI specification Section 5.2.7, it mentioned "In all cases, Host Controller Driver is responsible for the insertion and removal of all Endpoint Descriptors in the various Host Controller Endpoint Descriptor lists". In the ohci_frame_boundary(), ohci_put_hcca() writes the entire hcca back including the interrupt ED lists which should be under driver control. This violates the specification and can race with a host driver updating that list at the same time. In the OHCI Spec Section 4.6, Transfer Descriptor Queue Processing, it mentioned "Since the TD pointed to by TailP is not accessed by the HC, the Host Controller Driver can initialize that TD and link at least one other to it without creating a coherency or synchronization problem". While the function ohci_put_ed() writes the entire endpoint descriptor back including the TailP which should under driver control. This violate the specification and can race with a host driver updating the TD list at the same time. In each case the solution is to make sure we don't write data which is under driver control. Cc: Gerd Hoffman <kraxel@redhat.com> Signed-off-by: Wei Yang <weiyang@linux.vnet.ibm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-03-13usb-ehci: drop unused isoch_pause variableHans de Goede
Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>