From patchwork Mon Nov 8 16:26:10 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 70432 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 914B6B710A for ; Tue, 9 Nov 2010 03:26:39 +1100 (EST) Received: from localhost ([127.0.0.1]:56513 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PFUYG-0002GK-S2 for incoming@patchwork.ozlabs.org; Mon, 08 Nov 2010 11:26:36 -0500 Received: from [140.186.70.92] (port=42582 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PFUXF-0002FY-FQ for qemu-devel@nongnu.org; Mon, 08 Nov 2010 11:25:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PFUXE-0007xP-5r for qemu-devel@nongnu.org; Mon, 08 Nov 2010 11:25:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:3430) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PFUXD-0007x9-Tf for qemu-devel@nongnu.org; Mon, 08 Nov 2010 11:25:32 -0500 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.13.8/8.13.8) with ESMTP id oA8GPUxE019875 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 8 Nov 2010 11:25:30 -0500 Received: from shalem.localdomain (vpn2-10-78.ams2.redhat.com [10.36.10.78]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id oA8GPN4C019743; Mon, 8 Nov 2010 11:25:29 -0500 From: Hans de Goede To: qemu-devel@nongnu.org Date: Mon, 8 Nov 2010 17:26:10 +0100 Message-Id: <1289233570-6529-4-git-send-email-hdegoede@redhat.com> In-Reply-To: <1289233570-6529-1-git-send-email-hdegoede@redhat.com> References: <1289233570-6529-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. Cc: spice-devel@lists.freedesktop.org, Gerd Hoffmann , Hans de Goede Subject: [Qemu-devel] [PATCH 3/3] usb-linux: Get the active configuration from sysfs rather then asking the dev X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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. --- usb-linux.c | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-) diff --git a/usb-linux.c b/usb-linux.c index 0a46692..25ba5b7 100644 --- a/usb-linux.c +++ b/usb-linux.c @@ -152,6 +152,8 @@ static QTAILQ_HEAD(, USBHostDevice) hostdevs = QTAILQ_HEAD_INITIALIZER(hostdevs) static int usb_host_close(USBHostDevice *dev); static int parse_filter(const char *spec, struct USBAutoFilter *f); static void usb_host_auto_check(void *unused); +static int usb_host_read_file(char *line, size_t line_size, + const char *device_file, const char *device_name); static int is_isoc(USBHostDevice *s, int ep) { @@ -781,6 +783,23 @@ static int usb_linux_get_configuration(USBHostDevice *s) struct usb_ctrltransfer ct; int ret; + if (usb_fs_type == USB_FS_SYS) { + char device_name[32], line[1024]; + int configuration; + + sprintf(device_name, "%d-%d", s->bus_num, s->devpath); + + if (!usb_host_read_file(line, sizeof(line), "bConfigurationValue", + device_name)) { + goto usbdevfs; + } + if (sscanf(line, "%d", &configuration) != 1) { + goto usbdevfs; + } + return configuration; + } + +usbdevfs: ct.bRequestType = USB_DIR_IN; ct.bRequest = USB_REQ_GET_CONFIGURATION; ct.wValue = 0;