qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Hans de Goede <hdegoede@redhat.com>, Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 09/13] usb-linux: allow "compatible" high speed devices to connect at fullspeed
Date: Fri, 24 Jun 2011 12:59:31 +0200	[thread overview]
Message-ID: <1308913175-10454-10-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1308913175-10454-1-git-send-email-kraxel@redhat.com>

From: Hans de Goede <hdegoede@redhat.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>
---
 usb-linux.c |   39 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/usb-linux.c b/usb-linux.c
index 4d22c9c..1a2deb3 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -1088,6 +1088,42 @@ static int usb_linux_update_endp_table(USBHostDevice *s)
     return 0;
 }
 
+/*
+ * Check if we can safely redirect a usb2 device to a usb1 virtual controller,
+ * this function assumes this is safe, if:
+ * 1) There are no isoc endpoints
+ * 2) There are no interrupt endpoints with a max_packet_size > 64
+ * Note bulk endpoints with a max_packet_size > 64 in theory also are not
+ * usb1 compatible, but in practice this seems to work fine.
+ */
+static int usb_linux_full_speed_compat(USBHostDevice *dev)
+{
+    int i, packet_size;
+
+    /*
+     * usb_linux_update_endp_table only registers info about ep in the current
+     * interface altsettings, so we need to parse the descriptors again.
+     */
+    for (i = 0; (i + 5) < dev->descr_len; i += dev->descr[i]) {
+        if (dev->descr[i + 1] == USB_DT_ENDPOINT) {
+            switch (dev->descr[i + 3] & 0x3) {
+            case 0x00: /* CONTROL */
+                break;
+            case 0x01: /* ISO */
+                return 0;
+            case 0x02: /* BULK */
+                break;
+            case 0x03: /* INTERRUPT */
+                packet_size = dev->descr[i + 4] + (dev->descr[i + 5] << 8);
+                if (packet_size > 64)
+                    return 0;
+                break;
+            }
+        }
+    }
+    return 1;
+}
+
 static int usb_host_open(USBHostDevice *dev, int bus_num,
                         int addr, char *port, const char *prod_name, int speed)
 {
@@ -1168,6 +1204,9 @@ static int usb_host_open(USBHostDevice *dev, int bus_num,
     }
     dev->dev.speed = speed;
     dev->dev.speedmask = (1 << speed);
+    if (dev->dev.speed == USB_SPEED_HIGH && usb_linux_full_speed_compat(dev)) {
+        dev->dev.speedmask |= USB_SPEED_MASK_FULL;
+    }
 
     printf("husb: grabbed usb device %d.%d\n", bus_num, addr);
 
-- 
1.7.1

  parent reply	other threads:[~2011-06-24 10:59 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-24 10:59 [Qemu-devel] [PULL] usb patch queue Gerd Hoffmann
2011-06-24 10:59 ` [Qemu-devel] [PATCH 01/13] usb-linux: add get_endp() Gerd Hoffmann
2011-06-24 10:59 ` [Qemu-devel] [PATCH 02/13] usb-linux: make iso urb count contigurable Gerd Hoffmann
2011-06-24 10:59 ` [Qemu-devel] [PATCH 03/13] usb-linux: track inflight iso urb count Gerd Hoffmann
2011-06-24 10:59 ` [Qemu-devel] [PATCH 04/13] ehci: add freq + maxframes properties Gerd Hoffmann
2011-06-24 10:59 ` [Qemu-devel] [PATCH 05/13] ehci: switch to nanoseconds Gerd Hoffmann
2011-06-24 10:59 ` [Qemu-devel] [PATCH 06/13] usb-bus: Don't allow attaching a device to a bus with no free ports Gerd Hoffmann
2011-06-24 10:59 ` [Qemu-devel] [PATCH 07/13] usb: Proper error propagation for usb_device_attach errors Gerd Hoffmann
2011-06-24 10:59 ` [Qemu-devel] [PATCH 08/13] usb: Add a speedmask to devices Gerd Hoffmann
2011-06-24 10:59 ` Gerd Hoffmann [this message]
2011-06-24 10:59 ` [Qemu-devel] [PATCH 10/13] usb-bus: Don't allow speed mismatch while attaching devices Gerd Hoffmann
2011-06-24 10:59 ` [Qemu-devel] [PATCH 11/13] hw/usb-ohci.c: Fix handling of remote wakeup corner cases Gerd Hoffmann
2011-06-24 10:59 ` [Qemu-devel] [PATCH 12/13] usb-storage: Turn drive serial into a qdev property usb-storage.serial Gerd Hoffmann
2011-06-24 10:59 ` [Qemu-devel] [PATCH 13/13] usb: ignore USB_DT_DEBUG Gerd Hoffmann
2011-06-24 13:30 ` [Qemu-devel] [PULL] usb patch queue Hans de Goede
2011-06-27 20:19 ` Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1308913175-10454-10-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=hdegoede@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).