From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FZUW0-0000zG-C8 for qemu-devel@nongnu.org; Fri, 28 Apr 2006 11:04:16 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FZUVy-0000xy-SU for qemu-devel@nongnu.org; Fri, 28 Apr 2006 11:04:16 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FZUVy-0000xg-Lz for qemu-devel@nongnu.org; Fri, 28 Apr 2006 11:04:14 -0400 Received: from [24.93.47.44] (helo=ms-smtp-05.texas.rr.com) by monty-python.gnu.org with esmtp (Exim 4.52) id 1FZUZ8-0004Ba-5M for qemu-devel@nongnu.org; Fri, 28 Apr 2006 11:07:30 -0400 Received: from [192.168.0.11] (cpe-67-9-160-120.austin.res.rr.com [67.9.160.120]) by ms-smtp-05.texas.rr.com (8.13.4/8.13.4) with ESMTP id k3SF3cW6006165 for ; Fri, 28 Apr 2006 10:03:38 -0500 (CDT) Message-ID: <44522EC4.4050002@austin.rr.com> Date: Fri, 28 Apr 2006 10:03:32 -0500 From: Lonnie Mendez MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------070906060901070005080202" Subject: [Qemu-devel] [usb] fixes for emulated usb hub - rediff against current Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------070906060901070005080202 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 --------------070906060901070005080202 Content-Type: text/plain; name="qemu-hubfixups.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="qemu-hubfixups.diff" --- 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; --------------070906060901070005080202--