Skip to contentSkip to conversation

Implement the function usb_hub_handle_reset

PATCH In review hkran 2 participants 3 messages Nov 22, 2011 – Nov 23, 2011

lore
Share & tools
lore

hkran

author
#0 lore raw

PATCH 1/1 Implement the function usb_hub_handle_reset

Implement the function usb_hub_handle_reset. without it the guest propablly fail to configure the usb device attached to the virtulized hub with a correct address.

Typically, attaching more than one usb devices when lauch qemu may lead to the problem.

---
 hw/usb-hub.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)
hw/usb-hub.c +12 -1
index 3eb0f1a..6731075 100644
@@ -220,7 +220,18 @@ static void usb_hub_complete(USBPort *port, USBPacket *packet)
 
 static void usb_hub_handle_reset(USBDevice *dev)
 {
-    /* XXX: do it */
+    USBHubPort *port = NULL;
+    USBHubState *s = (USBHubState *)dev;
+    int i;
+
+    for(i = 0; i < NUM_PORTS; i++) {
+        port = &(s->ports[i]);
+        if(port->wPortStatus & PORT_STAT_CONNECTION) {
+            usb_reset(&port->port);
+            port->wPortStatus = PORT_STAT_CONNECTION | PORT_STAT_POWER;
+            port->wPortChange = PORT_STAT_C_CONNECTION;
+        }
+    }
 }
 
 static int usb_hub_handle_control(USBDevice *dev, USBPacket *p,
Signature · 1 line
1.7.1
#1 lore raw
Quoted 6 lines · hkran

Implement the function usb_hub_handle_reset. without it the guest propablly fail to configure the usb device attached to the virtulized hub with a correct address.

Typically, attaching more than one usb devices when lauch qemu may lead to the problem.

What is the exact problem you are trying to fix?

cheers,
Gerd

author
#2 lore raw
Quoted 5 lines · Gerd Hoffmann
Quoted 4 lines · hkran

Implement the function usb_hub_handle_reset. without it the guest propablly fail to configure the usb device attached to the virtulized hub with a correct address.

Quoted 8 lines
Quoted 2 lines

Typically, attaching more than one usb devices when lauch qemu may lead to the problem.

What is the exact problem you are trying to fix?

cheers,
Gerd

For example, I use the following command line to lautch qemu to play win7

/home/huikai/qemu10/bin/qemu-system-x86_64 -enable-kvm -m 1024 -drive
file=/root/win7_86.img,if=ide -net user -net nic,model=rtl8139 -localtime -chardev stdio,id=muxstdio -mon chardev=muxstdio -usb -usbdevice tablet -spice port=2345,disable-ticketing -cdrom /home/guest/Fedora-15-i686-Live-Desktop.iso -boot once=d -usbdevice host:0000:7777

Here, I attatched two usbdevice tablet and a usb storage device "host:0000:7777" on the host side. After guest have booted.there will not see the usb storage device. using monitor cmd "info usb" found the below:

(qemu) info usb
Device 0.1, Port 1, Speed 12 Mb/s, Product QEMU USB Tablet Device 0.3, Port 2, Speed 12 Mb/s, Product QEMU USB Hub Device 0.3, Port 2.1, Speed 480 Mb/s, Product host:2.4

the device "host:0000:7777" have not been configured successfully, guest OS can not to see it.

I traced qemu and found that there will be several reset cmd issued by the guest usb protocol stack during win7 booting, if we left the hub_reset to do nothing, the usbdevice attached to it will fail to be configured just in above case. (If we "hot plug-in " a usb device via qemu's monitor, the problem is not so easy to be reproduced because the reset cmd only be issued only once or none)

(the problem is not always reproduced, but high possibility).