qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [usb] fixes for emulated usb hub - rediff against current
@ 2006-04-28 15:03 Lonnie Mendez
  0 siblings, 0 replies; only message in thread
From: Lonnie Mendez @ 2006-04-28 15:03 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1103 bytes --]

   This is a rediff against CVS of the hub patch.  It implements changes 
to allow dynamic size for ports > 7 (the hub uses 8 ports so we run into 
problems).

   The FreeBSD workaround as mentioned in the patch is best explained here:

http://fxr.watson.org/fxr/source/dev/usb/uhub.c#L83

   uhub only allocates 1 byte for a hub that is currently returning 2 
bytes (8 ports).  I've submitted a patch to their bug repository (not 
yet accepted) but it's still good to have the older guests working once 
they do apply it.

   NAK is set to return on no change in hub or port status for the 
status change endpoint.  The specification and diagrams I've seen 
indicate this is correct.  It may be a nuissance to flood the log with 
NAKs, but I believe this can be filtered out by developers quite 
easily.  There are also seems to be noticeable effects which occur when 
the hub doesn't do this.  A very minor one is that win2k polls for port 
9 port status on an 8 port hub (perhaps to check sanity of hub):

frame 1505: pid=SETUP addr=0x02 ep=0 len=8
     data_out= a3 00 00 00 09 00 04 00
     ret=-3

[-- Attachment #2: qemu-hubfixups.diff --]
[-- Type: text/plain, Size: 3138 bytes --]

--- qemu/hw/usb-hub.c	2006-04-24 16:25:26.000000000 -0500
+++ qemu/hw/usb-hub.c	2006-04-28 09:58:10.000000000 -0500
@@ -158,9 +158,9 @@
 	0x0a,			/* u16  wHubCharacteristics; */
 	0x00,			/*   (per-port OC, no power switching) */
 	0x01,			/*  u8  bPwrOn2pwrGood; 2ms */
-	0x00,			/*  u8  bHubContrCurrent; 0 mA */
-	0x00,			/*  u8  DeviceRemovable; *** 7 Ports max *** */
-	0xff			/*  u8  PortPwrCtrlMask; *** 7 ports max *** */
+	0x00			/*  u8  bHubContrCurrent; 0 mA */
+
+        /* DeviceRemovable and PortPwrCtrlMask patched in later */
 };
 
 static void usb_hub_attach(USBPort *port1, USBDevice *dev)
@@ -219,6 +219,12 @@
         }
         ret = 0;
         break;
+    case EndpointOutRequest | USB_REQ_CLEAR_FEATURE:
+        if (value == 0 && index != 0x81) { /* clear ep halt */
+            goto fail;
+        }
+        ret = 0;
+        break;
     case DeviceOutRequest | USB_REQ_SET_FEATURE:
         if (value == USB_DEVICE_REMOTE_WAKEUP) {
             dev->remote_wakeup = 1;
@@ -241,6 +247,11 @@
         case USB_DT_CONFIG:
             memcpy(data, qemu_hub_config_descriptor, 
                    sizeof(qemu_hub_config_descriptor));
+
+            /* status change endpoint size based on number
+             * of ports */
+            data[22] = (s->nb_ports + 1 + 7) / 8;
+
             ret = sizeof(qemu_hub_config_descriptor);
             break;
         case USB_DT_STRING:
@@ -385,11 +396,29 @@
         }
         break;
     case GetHubDescriptor:
-        memcpy(data, qemu_hub_hub_descriptor, 
-               sizeof(qemu_hub_hub_descriptor));
-        data[2] = s->nb_ports;
-        ret = sizeof(qemu_hub_hub_descriptor);
-        break;
+        {
+            unsigned int n, limit, var_hub_size = 0;
+            memcpy(data, qemu_hub_hub_descriptor, 
+                   sizeof(qemu_hub_hub_descriptor));
+            data[2] = s->nb_ports;
+
+            /* fill DeviceRemovable bits */
+            limit = ((s->nb_ports + 1 + 7) / 8) + 7;
+            for (n = 7; n < limit; n++) {
+                data[n] = 0x00;
+                var_hub_size++;
+            }
+
+            /* fill PortPwrCtrlMask bits */
+            limit = limit + ((s->nb_ports + 7) / 8);
+            for (;n < limit; n++) {
+                data[n] = 0xff;
+                var_hub_size++;
+            }
+
+            ret = sizeof(qemu_hub_hub_descriptor) + var_hub_size;
+            break;
+        }
     default:
     fail:
         ret = USB_RET_STALL;
@@ -411,8 +440,11 @@
             unsigned int status;
             int i, n;
             n = (s->nb_ports + 1 + 7) / 8;
-            if (n > len)
+            if (len == 1) { /* FreeBSD workaround */
+                n = 1;
+            } else if (n > len) {
                 return USB_RET_BABBLE;
+            }
             status = 0;
             for(i = 0; i < s->nb_ports; i++) {
                 port = &s->ports[i];
@@ -425,7 +457,7 @@
                 }
                 ret = n;
             } else {
-                ret = 0;
+                ret = USB_RET_NAK; /* usb11 11.13.1 */
             }
         } else {
             goto fail;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-04-28 15:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-28 15:03 [Qemu-devel] [usb] fixes for emulated usb hub - rediff against current Lonnie Mendez

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).