qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: qemu-devel@nongnu.org
Cc: spice-devel@lists.freedesktop.org,
	Gerd Hoffmann <kraxel@redhat.com>,
	Hans de Goede <hdegoede@redhat.com>
Subject: [Qemu-devel] [PATCH 3/3] usb-linux: Get the active configuration from sysfs rather then asking the dev
Date: Mon,  8 Nov 2010 17:26:10 +0100	[thread overview]
Message-ID: <1289233570-6529-4-git-send-email-hdegoede@redhat.com> (raw)
In-Reply-To: <1289233570-6529-1-git-send-email-hdegoede@redhat.com>

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;
-- 
1.7.3.2

  parent reply	other threads:[~2010-11-08 16:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-08 16:26 [Qemu-devel] [PATCH 0/3] usb-linux do not send unnecessary GET_CONFIGURATION Hans de Goede
2010-11-08 16:26 ` [Qemu-devel] [PATCH 1/3] usb-linux: Store devpath into USBHostDevice when usb_fs_type == USB_FS_SYS Hans de Goede
2010-11-09 20:43   ` [Qemu-devel] " Yuriy Kaminskiy
2010-11-10  8:46     ` Hans de Goede
2010-11-08 16:26 ` [Qemu-devel] [PATCH 2/3] usb-linux: introduce a usb_linux_get_configuration function Hans de Goede
2010-11-08 16:26 ` Hans de Goede [this message]
2010-11-09 11:51 ` [Qemu-devel] Re: [PATCH 0/3] usb-linux do not send unnecessary GET_CONFIGURATION Gerd Hoffmann
  -- strict thread matches above, loose matches on Subject: below --
2010-11-10  9:06 [Qemu-devel] [PATCH 0/3] usb-linux do not send unnecessary GET_CONFIGURATION (v2) Hans de Goede
2010-11-10  9:06 ` [Qemu-devel] [PATCH 3/3] usb-linux: Get the active configuration from sysfs rather then asking the dev Hans de Goede

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=1289233570-6529-4-git-send-email-hdegoede@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=spice-devel@lists.freedesktop.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).