Start maintaining endpoint state at USBDevice level. Add USBEndpoint
struct and some helper functions to deal with it. For now it contains
the endpoint type only. Moved over some bits from usb-linux.c
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Move fields from USBHostDevice to USBDevice.
Add bits to usb-desc.c to fill them for emulated devices too.
Also allow to set configuration 0 (== None) for emulated devices.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This patch removes support for parsing /proc/bus/usb/devices for device
discovery. The code lacks a few features compared to the sysfs code and
is also bitrotting as everybody has sysfs these days.
This implies having sysfs mounted is mandatory now to use the usb-host
driver. udev isn't required though. qemu will prefer the udev-managed
device nodes below /dev/bus/usb, but in case this directory isn't preset
qemu will use the device nodes below /proc/bus/usb (default usbfs mount
point).
Bottom line: make sure you have both sysfs and usbfs mounted properly,
and everything should continue to work as it did before.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Factor out port release into a separate function. Call release function
in exit notifier too. Add explicit call the USBDEVFS_RELEASE_PORT
ioctl, just closing the hub file handle seems not to be enougth. Make
sure we release the port before resetting the device, otherwise host
drivers will not re-attach.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Changed From V1:
Use DPRINTF instead of fprintf,because it is not an error.
When testing ipod on QEMU by He Jie Xu<xuhj@linux.vnet.ibm.com>,qemu made a assertion.
We found that the ipod with 2 configurations,and the usb-linux did not parse the descriptor correctly.
The descr_len returned is the total length of the all configurations,not one configuration.
The older version will through the other configurations instead of skip,continue parsing the descriptor of interfaces/endpoints in other configurations,then went wrong.
This patch will put the configuration descriptor parse in loop outside and dispel the other configurations not requested.
Signed-off-by: Cao,Bing Bu <mars@linux.vnet.ibm.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Add a special function to reset the host usb device. It tracks the time
needed by the USBDEVFS_RESET ioctl and prints a warning in case it needs
too long. Usually it should be finished in 200 - 300 miliseconds.
Warning threshold is one second.
Intention is to help troubleshooting by indicating that the usb device
stopped responding even to a reset request and is possibly broken.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Commit 0c402e5abb is incomplete
and misses one of the two function pointer calls in
usb_host_scan_dev(). Add the additional port handling logic
to the other call too.
Spotted by Coverity.
Cc: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
The whole usb_host_close() function is skipped in case the device is not
in attached state. This is wrong though, only then usb_device_detach()
must be skipped, all other cleanup (especially device reset and closing
the file handle) still needs to be done. There are code paths where
usb_host_close() is called with the device in detached state already.
This fixes usb-host devices not being released and returned to the host
after removing them with device_del.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
In case the host uses the usb device usbfs will refuse to set the
configuration due to the device being busy. Handle this case by
disconnection the interfaces, then trying again.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Move code to claim usb ports and to disconnect usb interfaces into
usb_host_claim_port and usb_host_disconnect_ifaces functions. No
functional change.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
USB Devices can have up to 15 IN and 15 OUT endpoints, not 15 endpoints
total. Move from one array to two arrays (one IN, one OUT) to maintain
the endpoint state.
When configured to pass through a specific host port (using hostbus and
hostport properties), try to claim the port if supported by the kernel.
That will avoid any kernel drivers binding to devices plugged into that
port. It will not stop any userspace apps (such as usb_modeswitch)
access the device via usbfs though.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
It is perfectly fine to leave the usb device in unconfigured state
(USBHostDevice->configuration == 0). Just do that and wait for the
guest to explicitly set a configuration. This is closer to what real
hardware does and it also simplifies the device initialization. There
is no need to figure how the device is configured on the host.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Limit the number of times qemu tries to open host devices to three.
Reset error counter when the device goes away, after un-plugging and
re-plugging the device qemu will try again three times.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Two fixes for the price of one ;)
First, reinitialize the endpoint table after device reset.
This is needed anyway as the reset might have switched interfaces.
It also clears the endpoint halted state.
Second the CLEAR_HALT ioctl wants a unsigned int passed in as
argument, not uint8_t.
This gets my usb sd card reader (sandisk micromate) going.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Add a bunch of trace points to usb-linux.c Drop a bunch of DPRINTK's in
favor of the trace points. Also cleanup error reporting a bit while being
at it.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Add full support for iovecs to usb-host. The code can split large
transfers into smaller ones already, we are using this to also split
requests at iovec borders.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Zap data pointer from USBPacket, add a QEMUIOVector instead.
Add a bunch of helper functions to manage USBPacket data.
Switch over users to the new interface.
Note that USBPacket->len was used for two purposes: First to
pass in the buffer size and second to return the number of
transfered bytes or the status code on async transfers. There
is a new result variable for the latter. A new status code
was added to catch uninitialized result.
Nobody creates iovecs with more than one element (yet).
Some users are (temporarely) limited to iovecs with a single
element to keep the patch size as small as possible.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This allows to pass additional information to the notifier callback
which is useful if sender and receiver do not share any other distinct
data structure.
Will be used first for the clock reset notifier.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Some usb2 highspeed devices, like usb-msd devices, work fine when redirected
to a usb1 virtual controller. Allow this to avoid the new speedhecks causing
regressions for users who do not enable the new experimental ehci code.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This is used to indicate at which speed[s] the device can operate,
so that this can be checked to match the ports capabilities when it gets
attached to a bus.
Note that currently all usb1 emulated device claim to be fullspeed, this
seems to not cause any problems, but still seems wrong, because with real
hardware keyboards, mice and tablets usually are lo-speed, so reporting these
as fullspeed devices seems wrong.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Track the number of iso urbs which are currently in flight.
Log a message in case the count goes down to zero. Also
warn in case many urbs are returned at the same time.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Add a qdev property for the number of iso urbs which
usb-linux keeps in flight, so it can be configured at
runtime. Make it default to four (old hardcoded value
used to be three).
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
1024 bytes is way to small, one hd UVC webcam I have over here has so
many resolutions its descriptors take op close to 4k. Hopefully 8k will
be enough for all devices.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
If a user wants to redirect 2 identical usb sticks, in theory this is
possible by doing:
usb_add host🔢5678
usb_add host🔢5678
But this will lead to us trying to open the first stick twice, since we
don't break the loop after having found a match in our filter list, so the next'
filter list entry will result in us trying to open the same device again.
Fix this by adding the missing break.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
The connectinfo ioctl only differentiates between lo speed devices, and
all other speeds, where as we would like to know the real speed. The real
speed is available in sysfs so use that when available.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Factor out disconnect code (called when a device disappears) to a
separate function. Add a check for ENODEV errno to a few more places
to make sure we notice disconnects.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This patch removes all references to signal.h when qemu-common.h is included
as they become redundant.
Signed-off-by: Alexandre Raymond <cerbere@gmail.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Remove the cancel callback from the USBPacket struct, move it over
to USBDeviceInfo. Zap usb_defer_packet() which is obsolete now.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Calculate the max packet size correctly. Only bits 0..11 specify the size,
bits 11+12 specify the number of (highspeed) microframes the endpoint wants
to use.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Add support for splitting large transfers into multiple smaller ones.
This is needed for the upcoming EHCI emulation which allows guests
to submit requests up to 20k in size. The linux kernel allows 16k
max size though.
Based on a patch from David Ahern, see
http://www.mail-archive.com/qemu-devel@nongnu.org/msg30337.html
Cc: David Ahern <daahern@cisco.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Lookup async urbs which are to be canceled using the linked list
instead of the direct opaque pointer. There are two reasons we
are doing that: First, to avoid the opaque poiner to the callback,
which is needed for upcoming cleanups. Second, because we might
need multiple urbs per request for highspeed support, so a single
opaque pointer doesn't cut it any more anyway.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This patch adds code to track all async urbs in a linked list,
so we can find them without having to pass around a opaque
pointer to them. Prerequisite for the cleanups.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This patch adds a hostport property which allows to specify the host usb
devices to pass through by bus number and physical port. This means you
can basically hand over one (or more) of the usb plugs on your host to
the guest and whatever device is plugged in there will show up in the
guest.
Usage:
-device usb-host,hostbus=1,hostport=1
You can figure the port numbers by plugging in some usb device, then
find it in "info usbhost" and pick bus and port specified there.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
The device path isn't just a number. It specifies the physical port
the device is connected to and in case the device is connected via
usb hub you'll have two numbers there, like this: "5.1". The first
specifies the root port where the hub is plugged into, the second
specifies the port number of the hub where the device is plugged in.
With multiple hubs chained the string can become longer.
This patch renames devpath to port and makes it a string. It also
adapts the sysfs parsing code accordingly. The parser code is also more
strict now and skips the root hubs (which can't be assigned anyway).
The "info usbhost" monitor command now prints bus number, (os-assigned)
device address and physical port for each device.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>