Skip to contentSkip to conversation

Re-attach usb device to kernel while usb_host_open fails

PATCH In review Lin Ma 2 participants 4 messages Jun 23, 2015 – Jun 24, 2015

lore
Share & tools
lore

Lin Ma

author
#0 lore raw

PATCH 1/1 Re-attach usb device to kernel while usb_host_open fails

---
 hw/usb/host-libusb.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/usb/host-libusb.c +5 -0
index 10f4735..7258c4d 100644
@@ -888,6 +888,11 @@ static int usb_host_open(USBHostDevice *s, libusb_device *dev)
 fail:
     trace_usb_host_open_failure(bus_num, addr);
     if (s->dh != NULL) {
+        qemu_remove_exit_notifier(&s->exit);
+        QTAILQ_REMOVE(&hostdevs, s, next);
+        usb_host_release_interfaces(s);
+        libusb_reset_device(s->dh);
+        usb_host_attach_kernel(s);
         libusb_close(s->dh);
         s->dh = NULL;
         s->dev = NULL;
Signature · 1 line
2.1.4
#1 lore raw
Quoted 10 lines · Lin Ma
---
 hw/usb/host-libusb.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/usb/host-libusb.c +0 -0
index 10f4735..7258c4d 100644

hw/usb/host-libusb.c static int usb_host_open(USBHostDevice *s, libusb_device *dev) · line 892

Quoted 5 lines
hw/usb/host-libusb.c +2 -0
@@ -888,6 +888,11 @@ static int usb_host_open(USBHostDevice *s, libusb_device *dev)
 fail:
     trace_usb_host_open_failure(bus_num, addr);
     if (s->dh != NULL) {
+        qemu_remove_exit_notifier(&s->exit);
+        QTAILQ_REMOVE(&hostdevs, s, next);

This change will cause a regression. For example, if an usb device's (assume that it's usb1.0 device) speed does not match the ehci adapter, then then invoking usb_host_open failed. if somebody changes the usb device to an usb 2.0 device, it will not auto check because the device has removed from the global hostdevs list.

So I think we don't need do the above operations.

Regards,
-Gonglei

Quoted 7 lines
hw/usb/host-libusb.c +3 -0
+        usb_host_release_interfaces(s);
+        libusb_reset_device(s->dh);
+        usb_host_attach_kernel(s);
         libusb_close(s->dh);
         s->dh = NULL;
         s->dev = NULL;
author
#2 lore raw
Quoted 22 lines · Gonglei
Quoted 10 lines · Lin Ma
---
  hw/usb/host-libusb.c | 5 +++++
  1 file changed, 5 insertions(+)
hw/usb/host-libusb.c +0 -0
index 10f4735..7258c4d 100644

hw/usb/host-libusb.c static int usb_host_open(USBHostDevice *s, libusb_device *dev) · line 892

Quoted 5 lines
hw/usb/host-libusb.c +2 -0
@@ -888,6 +888,11 @@ static int usb_host_open(USBHostDevice *s, libusb_device *dev)
  fail:
      trace_usb_host_open_failure(bus_num, addr);
      if (s->dh != NULL) {
+        qemu_remove_exit_notifier(&s->exit);
+        QTAILQ_REMOVE(&hostdevs, s, next);

This change will cause a regression. For example, if an usb device's (assume that it's usb1.0 device) speed does not match the ehci adapter, then then invoking usb_host_open failed. if somebody changes the usb device to an usb 2.0 device, it will not auto check because the device has removed from the global hostdevs list.

Quoted 1 line

So I think we don't need do the above operations.

In this situation, in my opinion, User should perform device_add to add the device again, Then the device will be added to hostdevs list and can be auto checked again, right?

In addition, The usb_host_open will be performed 3 times until 's->errcount >= 3' while invoking usb_host_open failed. If the usb device isn't removed from hostdevs list, It will be detached & re-attached 3 times.

Thanks,
Lin

Quoted 9 lines
Quoted 7 lines
hw/usb/host-libusb.c +3 -0
+        usb_host_release_interfaces(s);
+        libusb_reset_device(s->dh);
+        usb_host_attach_kernel(s);
          libusb_close(s->dh);
          s->dh = NULL;
          s->dev = NULL;
#3 lore raw
Quoted 24 lines · Lin Ma
Quoted 22 lines · Gonglei
Quoted 10 lines · Lin Ma
---
  hw/usb/host-libusb.c | 5 +++++
  1 file changed, 5 insertions(+)
hw/usb/host-libusb.c +0 -0
index 10f4735..7258c4d 100644

hw/usb/host-libusb.c static int usb_host_open(USBHostDevice *s, libusb_device *dev) · line 892

Quoted 5 lines
hw/usb/host-libusb.c +2 -0
@@ -888,6 +888,11 @@ static int usb_host_open(USBHostDevice *s, libusb_device *dev)
  fail:
      trace_usb_host_open_failure(bus_num, addr);
      if (s->dh != NULL) {
+        qemu_remove_exit_notifier(&s->exit);
+        QTAILQ_REMOVE(&hostdevs, s, next);

This change will cause a regression. For example, if an usb device's (assume that it's usb1.0 device) speed does not match the ehci adapter, then then invoking usb_host_open failed. if somebody changes the usb device to an usb 2.0 device, it will not auto check because the device has removed from the global hostdevs list.

Quoted 4 lines
Quoted 1 line

So I think we don't need do the above operations.

In this situation, in my opinion, User should perform device_add to add the device again, Then the device will be added to hostdevs list and can be auto checked again, right?

No, that's a regression if you ask users call device_add again. The purpose that we use bus/port to identify one usb device is can handle this scenario. After passing through one usb device by usb/port, the guest can auto check the device though you changed a usb device in the same physical port.

Quoted 3 lines

In addition, The usb_host_open will be performed 3 times until 's->errcount >= 3' while invoking usb_host_open failed. If the usb device isn't removed from hostdevs list, It will be detached & re-attached 3 times.

Yes, that's no problem as a protecting logic.

Regards,
-Gonglei

Quoted 13 lines

Thanks,
Lin

Quoted 9 lines
Quoted 7 lines
hw/usb/host-libusb.c +3 -0
+        usb_host_release_interfaces(s);
+        libusb_reset_device(s->dh);
+        usb_host_attach_kernel(s);
          libusb_close(s->dh);
          s->dh = NULL;
          s->dev = NULL;