From patchwork Tue May 31 09:39:43 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 97996 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3E81FB6F6E for ; Tue, 31 May 2011 19:39:58 +1000 (EST) Received: from localhost ([::1]:35527 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QRLQZ-0006Pq-IZ for incoming@patchwork.ozlabs.org; Tue, 31 May 2011 05:39:55 -0400 Received: from eggs.gnu.org ([140.186.70.92]:48471) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QRLQG-0006Ks-FS for qemu-devel@nongnu.org; Tue, 31 May 2011 05:39:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QRLQF-0003OP-BW for qemu-devel@nongnu.org; Tue, 31 May 2011 05:39:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33346) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QRLQF-0003OF-3R for qemu-devel@nongnu.org; Tue, 31 May 2011 05:39:35 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p4V9dY0Q021373 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 31 May 2011 05:39:34 -0400 Received: from shalem.localdomain.com (vpn1-4-207.ams2.redhat.com [10.36.4.207]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p4V9dSsE003893; Tue, 31 May 2011 05:39:33 -0400 From: Hans de Goede To: qemu-devel@nongnu.org Date: Tue, 31 May 2011 11:39:43 +0200 Message-Id: <1306834783-13070-5-git-send-email-hdegoede@redhat.com> In-Reply-To: <1306834783-13070-1-git-send-email-hdegoede@redhat.com> References: <1306834783-13070-1-git-send-email-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Hans de Goede Subject: [Qemu-devel] [PATCH 4/4] usb-linux: allow "compatible" high speed devices to connect at fullspeed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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. --- usb-linux.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 39 insertions(+), 0 deletions(-) diff --git a/usb-linux.c b/usb-linux.c index 71e5f4d..187e6ae 100644 --- a/usb-linux.c +++ b/usb-linux.c @@ -1062,6 +1062,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) { @@ -1142,6 +1178,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);