Skip to contentSkip to conversation

usb-linux: allow multiple devices with matching IDs

PATCH In review Grazvydas Ignotas 2 participants 3 messages Oct 22, 2010 – Nov 13, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb-linux: allow multiple devices with matching IDs

Right now if we pass through multiple USB devices with matching vendor and product IDs, only first one is passed to guest, as the code thinks second device is already attached. The only way to get those devices working is to specify bus.addr which is inconvenient if devices are frequently replugged on host, because the address changes after replug.

Fix this by checking bus.addr before assuming the device is already attached. This way -usbdevice host:1234:1234 -usbdevice host:1234:1234 will pass through 2 devices correctly.

---
 usb-linux.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
usb-linux.c +6 -2
index c3c38ec..b5f1396 100644
@@ -1464,9 +1464,13 @@ static int usb_host_auto_scan(void *opaque, int bus_num, int addr,
         }
         /* We got a match */
 
-        /* Already attached ? */
         if (s->fd != -1) {
-            return 0;
+            /* Already attached? */
+            if (s->bus_num == bus_num && s->addr == addr)
+                return 0;
+
+            /* Not attached but needs another hostdev */
+            continue;
         }
         DPRINTF("husb: auto open: bus_num %d addr %d\n", bus_num, addr);
 
Signature · 1 line
1.6.3.3
#1 lore raw
Quoted 24 lines · Grazvydas Ignotas

Right now if we pass through multiple USB devices with matching vendor and product IDs, only first one is passed to guest, as the code thinks second device is already attached. The only way to get those devices working is to specify bus.addr which is inconvenient if devices are frequently replugged on host, because the address changes after replug.

Fix this by checking bus.addr before assuming the device is already attached. This way -usbdevice host:1234:1234 -usbdevice host:1234:1234 will pass through 2 devices correctly.

---
 usb-linux.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
usb-linux.c +0 -1
index c3c38ec..b5f1396 100644
@@ -1464,9 +1464,13 @@ static int usb_host_auto_scan(void *opaque, int bus_num, int addr,
         }
         /* We got a match */
 
-        /* Already attached ? */

usb-linux.c static int usb_host_auto_scan(void *opaque, int bus_num, int addr, · line 1475

Quoted 10 lines
usb-linux.c +6 -1
         if (s->fd != -1) {
-            return 0;
+            /* Already attached? */
+            if (s->bus_num == bus_num && s->addr == addr)
+                return 0;
+
+            /* Not attached but needs another hostdev */
+            continue;
         }
         DPRINTF("husb: auto open: bus_num %d addr %d\n", bus_num, addr);

Did you test that filtering by bus and addr still works?

#2 lore raw
Quoted 25 lines · Markus Armbruster
Quoted 23 lines · Grazvydas Ignotas

Right now if we pass through multiple USB devices with matching vendor and product IDs, only first one is passed to guest, as the code thinks second device is already attached. The only way to get those devices working is to specify bus.addr which is inconvenient if devices are frequently replugged on host, because the address changes after replug.

Fix this by checking bus.addr before assuming the device is already attached. This way -usbdevice host:1234:1234 -usbdevice host:1234:1234 will pass through 2 devices correctly.

---
 usb-linux.c |    8 ++++++--

 1 files changed, 6 insertions(+), 2 deletions(-)
usb-linux.c +0 -0
index c3c38ec..b5f1396 100644
@@ -1464,9 +1464,13 @@ static int usb_host_auto_scan(void *opaque, int bus_num, int addr,
          }
          /* We got a match */
 
Quoted 14 lines

usb-linux.c static int usb_host_auto_scan(void *opaque, int bus_num, int addr, · line 1475

Quoted 11 lines
usb-linux.c +6 -2
-        /* Already attached ? */
          if (s->fd != -1) {
-            return 0;
+            /* Already attached? */
+            if (s->bus_num == bus_num && s->addr == addr)
+                return 0;
+
+            /* Not attached but needs another hostdev */
+            continue;
          }
          DPRINTF("husb: auto open: bus_num %d addr %d\n", bus_num, addr);

Did you test that filtering by bus and addr still works?

Yes. However it still acts strange when one of those 2 devices is unplugged, so you can drop this patch for now I guess.