From patchwork Mon May 16 19:56:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 95822 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 2C0ADB6EF7 for ; Tue, 17 May 2011 06:00:48 +1000 (EST) Received: from localhost ([::1]:40891 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QM3y9-0003cj-Ij for incoming@patchwork.ozlabs.org; Mon, 16 May 2011 16:00:45 -0400 Received: from eggs.gnu.org ([140.186.70.92]:57805) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QM3uG-0005Pp-V7 for qemu-devel@nongnu.org; Mon, 16 May 2011 15:56:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QM3uF-0004Ni-M0 for qemu-devel@nongnu.org; Mon, 16 May 2011 15:56:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35673) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QM3uF-0004NX-Cn for qemu-devel@nongnu.org; Mon, 16 May 2011 15:56:43 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p4GJug7t007551 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 16 May 2011 15:56:42 -0400 Received: from rincewind.home.kraxel.org (vpn1-4-42.ams2.redhat.com [10.36.4.42]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p4GJuXMq027724; Mon, 16 May 2011 15:56:34 -0400 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id 34C6542995; Mon, 16 May 2011 21:56:23 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Mon, 16 May 2011 21:56:12 +0200 Message-Id: <1305575782-31766-9-git-send-email-kraxel@redhat.com> In-Reply-To: <1305575782-31766-1-git-send-email-kraxel@redhat.com> References: <1305575782-31766-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 08/18] usb-linux: fix device path aka physical port handling 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 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 "info usbhost" monitor command now prints bus number, (os-assigned) device address and physical port for each device. Signed-off-by: Gerd Hoffmann --- usb-linux.c | 38 ++++++++++++++++++++------------------ 1 files changed, 20 insertions(+), 18 deletions(-) diff --git a/usb-linux.c b/usb-linux.c index 84d3a8b..2fa3591 100644 --- a/usb-linux.c +++ b/usb-linux.c @@ -54,7 +54,7 @@ struct usb_ctrltransfer { void *data; }; -typedef int USBScanFunc(void *opaque, int bus_num, int addr, int devpath, +typedef int USBScanFunc(void *opaque, int bus_num, int addr, char *port, int class_id, int vendor_id, int product_id, const char *product_name, int speed); @@ -71,6 +71,7 @@ typedef int USBScanFunc(void *opaque, int bus_num, int addr, int devpath, #define USBPROCBUS_PATH "/proc/bus/usb" #define PRODUCT_NAME_SZ 32 #define MAX_ENDPOINTS 15 +#define MAX_PORTLEN 8 #define USBDEVBUS_PATH "/dev/bus/usb" #define USBSYSBUS_PATH "/sys/bus/usb" @@ -123,7 +124,7 @@ typedef struct USBHostDevice { /* Host side address */ int bus_num; int addr; - int devpath; + char port[MAX_PORTLEN]; struct USBAutoFilter match; QTAILQ_ENTRY(USBHostDevice) next; @@ -836,7 +837,7 @@ static int usb_linux_get_configuration(USBHostDevice *s) char device_name[32], line[1024]; int configuration; - sprintf(device_name, "%d-%d", s->bus_num, s->devpath); + sprintf(device_name, "%d-%s", s->bus_num, s->port); if (!usb_host_read_file(line, sizeof(line), "bConfigurationValue", device_name)) { @@ -882,7 +883,7 @@ static uint8_t usb_linux_get_alt_setting(USBHostDevice *s, char device_name[64], line[1024]; int alt_setting; - sprintf(device_name, "%d-%d:%d.%d", s->bus_num, s->devpath, + sprintf(device_name, "%d-%s:%d.%d", s->bus_num, s->port, (int)configuration, (int)interface); if (!usb_host_read_file(line, sizeof(line), "bAlternateSetting", @@ -1001,7 +1002,7 @@ static int usb_linux_update_endp_table(USBHostDevice *s) } static int usb_host_open(USBHostDevice *dev, int bus_num, - int addr, int devpath, const char *prod_name) + int addr, char *port, const char *prod_name) { int fd = -1, ret; struct usbdevfs_connectinfo ci; @@ -1027,7 +1028,7 @@ static int usb_host_open(USBHostDevice *dev, int bus_num, dev->bus_num = bus_num; dev->addr = addr; - dev->devpath = devpath; + strcpy(dev->port, port); dev->fd = fd; /* read the device description */ @@ -1401,8 +1402,9 @@ static int usb_host_scan_sys(void *opaque, USBScanFunc *func) { DIR *dir = NULL; char line[1024]; - int bus_num, addr, devpath, speed, class_id, product_id, vendor_id; + int bus_num, addr, speed, class_id, product_id, vendor_id; int ret = 0; + char port[MAX_PORTLEN]; char product_name[512]; struct dirent *de; @@ -1418,8 +1420,8 @@ static int usb_host_scan_sys(void *opaque, USBScanFunc *func) if (!strncmp(de->d_name, "usb", 3)) { tmpstr += 3; } - if (sscanf(tmpstr, "%d-%d", &bus_num, &devpath) < 1) { - goto the_end; + if (sscanf(tmpstr, "%d-%7[0-9.]", &bus_num, port) < 2) { + continue; } if (!usb_host_read_file(line, sizeof(line), "devnum", de->d_name)) { @@ -1471,7 +1473,7 @@ static int usb_host_scan_sys(void *opaque, USBScanFunc *func) speed = USB_SPEED_FULL; } - ret = func(opaque, bus_num, addr, devpath, class_id, vendor_id, + ret = func(opaque, bus_num, addr, port, class_id, vendor_id, product_id, product_name, speed); if (ret) { goto the_end; @@ -1562,7 +1564,7 @@ static int usb_host_scan(void *opaque, USBScanFunc *func) static QEMUTimer *usb_auto_timer; -static int usb_host_auto_scan(void *opaque, int bus_num, int addr, int devpath, +static int usb_host_auto_scan(void *opaque, int bus_num, int addr, char *port, int class_id, int vendor_id, int product_id, const char *product_name, int speed) { @@ -1598,7 +1600,7 @@ static int usb_host_auto_scan(void *opaque, int bus_num, int addr, int devpath, } DPRINTF("husb: auto open: bus_num %d addr %d\n", bus_num, addr); - usb_host_open(s, bus_num, addr, devpath, product_name); + usb_host_open(s, bus_num, addr, port, product_name); } return 0; @@ -1720,8 +1722,8 @@ static const char *usb_class_str(uint8_t class) return p->class_name; } -static void usb_info_device(Monitor *mon, int bus_num, int addr, int class_id, - int vendor_id, int product_id, +static void usb_info_device(Monitor *mon, int bus_num, int addr, char *port, + int class_id, int vendor_id, int product_id, const char *product_name, int speed) { @@ -1742,8 +1744,8 @@ static void usb_info_device(Monitor *mon, int bus_num, int addr, int class_id, break; } - monitor_printf(mon, " Device %d.%d, speed %s Mb/s\n", - bus_num, addr, speed_str); + monitor_printf(mon, " Bus %d, Addr %d, Port %s, Speed %s Mb/s\n", + bus_num, addr, port, speed_str); class_str = usb_class_str(class_id); if (class_str) { monitor_printf(mon, " %s:", class_str); @@ -1758,14 +1760,14 @@ static void usb_info_device(Monitor *mon, int bus_num, int addr, int class_id, } static int usb_host_info_device(void *opaque, int bus_num, int addr, - int devpath, int class_id, + char *path, int class_id, int vendor_id, int product_id, const char *product_name, int speed) { Monitor *mon = opaque; - usb_info_device(mon, bus_num, addr, class_id, vendor_id, product_id, + usb_info_device(mon, bus_num, addr, path, class_id, vendor_id, product_id, product_name, speed); return 0; }