Commit Graph

105 Commits

Author SHA1 Message Date
Jan Kiszka 9e8dd45164 notifier: Pass data argument to callback
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>
2011-07-23 11:26:06 -05:00
Hans de Goede e4b1776765 usb-linux: allow "compatible" high speed devices to connect at fullspeed
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>
2011-06-23 11:28:06 +02:00
Hans de Goede ba3f9bfba9 usb: Add a speedmask to devices
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>
2011-06-23 11:28:06 +02:00
Hans de Goede fa19bf831b usb: Proper error propagation for usb_device_attach errors
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-06-23 11:28:06 +02:00
Gerd Hoffmann 8288726256 usb-linux: track inflight iso urb count
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>
2011-06-23 10:18:37 +02:00
Gerd Hoffmann b81bcd8aa0 usb-linux: make iso urb count contigurable
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>
2011-06-23 10:18:37 +02:00
Gerd Hoffmann ca3a36cf2b usb-linux: add get_endp()
Add a helper function to get the endpoint data structure
and put it into use.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-06-23 10:18:37 +02:00
Hans de Goede f8ddbfbcda usb-linux: Enlarge buffer for descriptors to 8192 bytes
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>
2011-06-14 12:56:49 +02:00
Gerd Hoffmann 1f45a81bef usb-linux: only cleanup in host_close when host_open was successful. 2011-06-14 12:56:49 +02:00
Hans de Goede 97f8616648 usb-linux: Don't try to open the same device twice
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>
2011-06-14 12:56:49 +02:00
Hans de Goede 130314f83d usb-linux: Ensure devep != 0
So that we don't index endp_table with a negative index.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-06-14 12:56:49 +02:00
Hans de Goede 61c1117f08 usb-linux: Don't do perror when errno is not set
Note that "op" also is not set, so before this change these error paths
would feed NULL to perror.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-06-14 12:56:49 +02:00
Hans de Goede f264cfbf4a usb-linux: Teach about super speed
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-06-14 12:56:49 +02:00
Hans de Goede 3991c35e85 usb-linux: Get speed from sysfs rather then from the connectinfo ioctl
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>
2011-06-14 12:56:49 +02:00
Gerd Hoffmann 41c01ee715 usb-linux: catch ENODEV in more places.
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>
2011-06-14 12:36:28 +02:00
Alexandre Raymond 9bf0960a9a Fix compilation warning due to missing header for sigaction (followup)
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>
2011-06-08 09:04:29 +01:00
Gerd Hoffmann eb5e680ae5 usb: move cancel callback to USBDeviceInfo
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>
2011-05-26 11:55:03 +02:00
Gerd Hoffmann 6dfcdccb09 usb-linux: fix max_packet_size for highspeed.
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>
2011-05-26 11:55:02 +02:00
Gerd Hoffmann 71138531d3 usb-linux: split large xfers
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>
2011-05-26 11:55:02 +02:00
Gerd Hoffmann 227ebeb535 usb-linux: walk async urb list in cancel
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>
2011-05-26 11:55:02 +02:00
Gerd Hoffmann 7a8fc83f34 usb-linux: track aurbs in list
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>
2011-05-26 11:55:02 +02:00
Gerd Hoffmann 9056a2972a usb-linux: add hostport property
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>
2011-05-26 11:55:02 +02:00
Gerd Hoffmann 5557d82081 usb-linux: fix device path aka physical port handling
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>
2011-05-26 11:55:02 +02:00
Hans de Goede 50b7963e72 usb-linux: use usb_generic_handle_packet()
Make the linux usb host passthrough code use the usb_generic_handle_packet()
function, rather then the curent DYI code. This removes 200 lines of almost
identical code.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2011-05-26 11:55:02 +02:00
Stefan Weil 0225e254ae usb-linux: Add missing break statement
cppcheck report:
usb-linux.c:661: warning: Redundant assignment of "len" in switch

Cc: Hans de Goede <hdegoede@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Stefan Weil <weil@mail.berlios.de>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-05-09 16:18:32 +02:00
Gerd Hoffmann 13a9a0d3e2 usb: move complete callback to port ops 2011-05-04 14:11:08 +02:00
Hans de Goede bb6d5498c6 usb-linux: Add support for buffering iso out usb packets
Extend the iso buffering code to also buffer iso out packets, this
fixes for example using usb speakers with usb redirection.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2011-05-04 12:25:24 +02:00
Hans de Goede 3a4854b372 usb-linux: We only need to keep track of 15 endpoints
Currently we reserve room for endpoint data for 16 endpoints, but given
that we only use endpoint data for endpoints 1-15, and always index the
array with the endpoint-number - 1, 15 is enough.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2011-05-04 12:25:24 +02:00
Hans de Goede 975f29984d usb-linux: Refuse iso packets when max packet size is 0 (alt setting 0)
Refuse iso usb packets when then max packet size for the endpoint is 0,
this avoids an abort in usb_host_alloc_iso() caused by trying to qemu_malloc
a 0 bytes large buffer.
2011-05-04 12:25:24 +02:00
Hans de Goede a0b5fece8a usb-linux: Refuse packets for endpoints which are not in the usb descriptor
If an endpoint is not in the usb descriptor we've no idea what kind of
endpoint it is and thus how to handle it, refuse packages in this case.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2011-05-04 12:25:24 +02:00
Hans de Goede 060dc841d1 usb-linux: Add support for buffering iso usb packets
Currently we are submitting iso packets to the host one at a time, as we
receive them from the emulated host controller. This has 2 problems:
1) If we were fast enough to submit every packet in time for the next host host
controller usb frame, we would be generating 1000 hardware interrupts per
second on the host
2) We are not fast enough to submit every packet in time for the next host host
controller usb frame, causing us to not submit iso urbs in some usb frames
which causes devices with an endpoint with an interval of 1 ms (so every
frame) to loose data. This causes for example ubs-1.1 webcams to not work
properly (usb-2.0 is not supported at all atm).

This patch fixes both problems by changing the iso packet pass through handling
to buffer packets. This version only does so for iso input packets (webcams,
audio in) I'm working on a second patch extending this to iso output packets
(audio out).

This patch makes use of the linux batching of iso packets in one urb.
When an iso in packet gets received from the emulated host controller,
it immediately submits 3 urbs with 32 iso in packets each. This causes
the host to only get an hw interrupt every 32 packets dropping the
interrupt rate to 32 interrupts per second and gives it a queue of urbs
to work from once the first 32 iso in packets have been received to make sure
no packets are dropped.

Besides submitting a whole bunch or urbs as soon as the first urb is
received, effectively creating a buffer inside the kernel, this patch also
gets rid of the asynchroneous completion for iso in urbs. Instead they are
only marked as complete in the fd write callback (which usbfs uses to signal
complete urbs). These complete packets then get consumed by returning them
synchroneously to the emulated host controller when it submits an iso in
packet for the ep in question. When no complete packets are ready (which
happens when the stream is starting) a 0 length packet gets returned to
the emulated host controller.

With this patch I've several usb-1.1 webcams working well with usb pass
through, where as without this patch none of them work.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2011-05-04 12:25:24 +02:00
Hans de Goede c43831fb47 usb-linux: Get the alt. setting from sysfs rather then asking the dev
At least one device I have lies when receiving a USB_REQ_GET_INTERFACE,
always returning 0 even if the alternate setting is different. This is
likely caused because in practice this control message is never used as
the operating system's usb stack knows which alternate setting it has
told the device to get into, and thus this ctrl message does not get
tested by device manufacturers.

When usb_fs_type == USB_FS_SYS, the active alt. setting can be read directly
from sysfs, which allows using this device through qemu's usb redirection.
More in general it seems a good idea to not send needless control msg's to
devices, esp. as the code in question is called every time a set_interface
is done. Which happens multiple times during virtual machine startup, and
when device drivers are activating the usb device.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2011-05-04 12:25:24 +02:00
Hans de Goede ed3a328db9 usb-linux: introduce a usb_linux_alt_setting function
The next patch in this series introduces multiple ways to get the
alt setting dependent upon usb_fs_type, it is cleaner to put this
into its own function.

Note that this patch also changes the assumed alt setting in case
of an error getting the alt setting to be 0 (a sane default) rather
then the interface numberwhich makes no sense.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2011-05-04 12:25:24 +02:00
Brad Hards a0102082de usb: fix spelling errors in usb-linux.c
Signed-off-by: Brad Hards <bradh@frogmouth.net>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2011-04-16 12:24:28 +01:00
Brad Hards 021730f728 usb: initialise data element in Linux USB_DISCONNECT ioctl
This isn't used, but leaving it empty causes valgrind noise.

Signed-off-by: Brad Hards <bradh@frogmouth.net>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2011-04-16 12:24:28 +01:00
Paolo Bonzini 7bd427d801 change all rt_clock references to use millisecond resolution accessors
This was done with:

    sed -i '/get_clock\>.*rt_clock/s/get_clock\>/get_clock_ms/' \
        $(git grep -l 'get_clock\>.*rt_clock' )
    sed -i '/new_timer\>.*rt_clock/s/new_timer\>/new_timer_ms/' \
        $(git grep -l 'new_timer\>.*rt_clock' )

after checking that get_clock and new_timer never occur twice
on the same line.  There were no missed occurrences; however, even
if there had been, they would have been caught by the compiler.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2011-03-21 09:23:23 +01:00
Hans de Goede 2cc59d8cb0 usb-linux: Get the active configuration from sysfs rather then asking the dev
Some devices seem to choke on receiving a USB_REQ_GET_CONFIGURATION ctrl msg
(witnessed with a digital picture frame usb id 1908:1320).
When usb_fs_type == USB_FS_SYS, the active configuration can be read directly
from sysfs, which allows using this device through qemu's usb redirection.
More in general it seems a good idea to not send needless control msg's to
devices, esp. as the code in question is called every time a set_interface
is done. Which happens multiple times during virtual machine startup, and
when device drivers are activating the usb device.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-11-16 14:35:00 -06:00
Hans de Goede 71d71bbdeb usb-linux: introduce a usb_linux_get_configuration function
The next patch in this series introduces multiple ways to get the
configuration dependent upon usb_fs_type, it is cleaner to put this
into its own function.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-11-16 14:35:00 -06:00
Hans de Goede 0f5160d1ea usb-linux: Store devpath into USBHostDevice when usb_fs_type == USB_FS_SYS
This allows us to recreate the sysfspath used during scanning later
(which will be used in a later patch in this series).

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-11-16 14:35:00 -06:00
Shahar Havivi b373a63a2e Return usb device to host on exit
Signed-off-by: Shahar Havivi <shaharh@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2010-06-30 22:51:17 +02:00
Shahar Havivi 00ff227a32 Return usb device to host on usb_del command
Signed-off-by: Shahar Havivi <shaharh@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2010-06-30 22:51:09 +02:00
David Ahern 2791104cfb Changes to usb-linux to conform to coding style
Signed-off-by: David Ahern <daahern@cisco.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-05-03 12:39:53 -05:00
Blue Swirl d4c4e6fdc7 usb: remove dead assignments, spotted by clang analyzer
Value stored is never read.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2010-04-25 18:23:04 +00:00
Anthony Liguori ddbda4323e Revert "usb-linux: remove unreachable default in switch statement"
This reverts commit 3c9c706c3b.

This breaks build (gcc 4.3.2):
    CC    usb-linux.o
 cc1: warnings being treated as errors
 /src/qemu/usb-linux.c: In function 'usb_linux_update_endp_table':
 /src/qemu/usb-linux.c:759: error: 'type' may be used uninitialized in
 this function

Reported-by: Blue Swirl <blauwirbel@gmail.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-03-19 15:27:27 -05:00
Paul Bolle 3c9c706c3b usb-linux: remove unreachable default in switch statement
Signed-off-by: Paul Bolle <pebolle@tiscali.nl>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-03-17 10:41:39 -05:00
Markus Armbruster 4491e0f398 usb: Remove disabled monitor_printf() in usb_read_file()
The monitor_printf() reports failure.  Printing is wrong, because the
caller tries various arguments, and expects the function to fail for
some or all.

Disabled since commit 26a9e82a.  Remove it.
2010-03-16 16:55:04 +01:00
malc d0f2c4c602 Do not use dprintf
dprintf is already claimed by POSIX[1], and on at least one system
is implemented as a macro

[1] http://www.opengroup.org/onlinepubs/9699919799/functions/dprintf.html

Signed-off-by: malc <av1474@comtv.ru>
2010-02-07 02:03:50 +03:00
Christian Krause fd7a446f16 usb-linux: increase buffer for USB control requests
The WLAN USB stick ZyXEL NWD271N (0586:3417) uses very large
usb control transfers of more than 2048 bytes which won't fit
into the buffer of the ctrl_struct. This results in an error message
"husb: ctrl buffer too small" and a non-working device.
Increasing the buffer size to 8192 seems to be a safe choice.

Signed-off-by: Christian Krause <chkr@plauener.de>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2010-02-06 17:14:24 +01:00
Paolo Bonzini b29a7def92 usb-linux.c: remove write-only variable
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2010-02-05 18:13:25 +00:00
Kirill A. Shutemov 9f99cee7fa usb-linux.c: fix warning with _FORTIFY_SOURCE
CC    usb-linux.o
cc1: warnings being treated as errors
usb-linux.c: In function 'usb_host_read_file':
usb-linux.c:1204: error: ignoring return value of 'fgets', declared with attribute warn_unused_result
make: *** [usb-linux.o] Error 1

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-26 14:59:20 -06:00