From patchwork Fri Jan 13 10:18:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 135824 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1E37AB6F6F for ; Fri, 13 Jan 2012 23:31:15 +1100 (EST) Received: from localhost ([::1]:44154 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RlgHo-0006hH-Fe for incoming@patchwork.ozlabs.org; Fri, 13 Jan 2012 07:31:12 -0500 Received: from eggs.gnu.org ([140.186.70.92]:52559) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RlfQs-00045c-RV for qemu-devel@nongnu.org; Fri, 13 Jan 2012 06:36:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RlfQm-0000cI-Ba for qemu-devel@nongnu.org; Fri, 13 Jan 2012 06:36:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51248) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RlfQm-0000cC-3T for qemu-devel@nongnu.org; Fri, 13 Jan 2012 06:36:24 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q0DBaNbn030680 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 13 Jan 2012 06:36:23 -0500 Received: from rincewind.home.kraxel.org (ovpn-116-67.ams2.redhat.com [10.36.116.67]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q0DBZwqR023080; Fri, 13 Jan 2012 06:36:17 -0500 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id 0384D40EA0; Fri, 13 Jan 2012 11:18:35 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 13 Jan 2012 11:18:28 +0100 Message-Id: <1326449914-8591-12-git-send-email-kraxel@redhat.com> In-Reply-To: <1326449914-8591-1-git-send-email-kraxel@redhat.com> References: <1326449914-8591-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 11/17] usb: add max_packet_size to USBEndpoint X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Gerd Hoffmann --- hw/usb-desc.c | 2 ++ hw/usb.c | 37 +++++++++++++++++++++++++++++++++---- hw/usb.h | 4 ++++ usb-linux.c | 31 +++++-------------------------- 4 files changed, 44 insertions(+), 30 deletions(-) diff --git a/hw/usb-desc.c b/hw/usb-desc.c index 0768334..b3eb97b 100644 --- a/hw/usb-desc.c +++ b/hw/usb-desc.c @@ -248,6 +248,8 @@ static void usb_desc_ep_init(USBDevice *dev) ep = iface->eps[e].bEndpointAddress & 0x0f; usb_ep_set_type(dev, pid, ep, iface->eps[e].bmAttributes & 0x03); usb_ep_set_ifnum(dev, pid, ep, iface->bInterfaceNumber); + usb_ep_set_max_packet_size(dev, pid, ep, + iface->eps[e].wMaxPacketSize); } } } diff --git a/hw/usb.c b/hw/usb.c index f07cb9d..0f163b4 100644 --- a/hw/usb.c +++ b/hw/usb.c @@ -449,8 +449,9 @@ void usb_ep_dump(USBDevice *dev) fprintf(stderr, " Interface %d, alternative %d\n", ifnum, dev->altsetting[ifnum]); } - fprintf(stderr, " Endpoint %d, IN, %s\n", ep, - tname[dev->ep_in[ep].type]); + fprintf(stderr, " Endpoint %d, IN, %s, %d max\n", ep, + tname[dev->ep_in[ep].type], + dev->ep_in[ep].max_packet_size); } if (dev->ep_out[ep].type != USB_ENDPOINT_XFER_INVALID && dev->ep_out[ep].ifnum == ifnum) { @@ -459,8 +460,9 @@ void usb_ep_dump(USBDevice *dev) fprintf(stderr, " Interface %d, alternative %d\n", ifnum, dev->altsetting[ifnum]); } - fprintf(stderr, " Endpoint %d, OUT, %s\n", ep, - tname[dev->ep_out[ep].type]); + fprintf(stderr, " Endpoint %d, OUT, %s, %d max\n", ep, + tname[dev->ep_out[ep].type], + dev->ep_out[ep].max_packet_size); } } } @@ -498,3 +500,30 @@ void usb_ep_set_ifnum(USBDevice *dev, int pid, int ep, uint8_t ifnum) struct USBEndpoint *uep = usb_ep_get(dev, pid, ep); uep->ifnum = ifnum; } + +void usb_ep_set_max_packet_size(USBDevice *dev, int pid, int ep, + uint16_t raw) +{ + struct USBEndpoint *uep = usb_ep_get(dev, pid, ep); + int size, microframes; + + size = raw & 0x7ff; + switch ((raw >> 11) & 3) { + case 1: + microframes = 2; + break; + case 2: + microframes = 3; + break; + default: + microframes = 1; + break; + } + uep->max_packet_size = size * microframes; +} + +int usb_ep_get_max_packet_size(USBDevice *dev, int pid, int ep) +{ + struct USBEndpoint *uep = usb_ep_get(dev, pid, ep); + return uep->max_packet_size; +} diff --git a/hw/usb.h b/hw/usb.h index c35ff74..5ea984c 100644 --- a/hw/usb.h +++ b/hw/usb.h @@ -176,6 +176,7 @@ struct USBDescString { struct USBEndpoint { uint8_t type; uint8_t ifnum; + int max_packet_size; }; /* definition of a USB device */ @@ -339,6 +340,9 @@ uint8_t usb_ep_get_type(USBDevice *dev, int pid, int ep); uint8_t usb_ep_get_ifnum(USBDevice *dev, int pid, int ep); void usb_ep_set_type(USBDevice *dev, int pid, int ep, uint8_t type); void usb_ep_set_ifnum(USBDevice *dev, int pid, int ep, uint8_t ifnum); +void usb_ep_set_max_packet_size(USBDevice *dev, int pid, int ep, + uint16_t raw); +int usb_ep_get_max_packet_size(USBDevice *dev, int pid, int ep); void usb_attach(USBPort *port); void usb_detach(USBPort *port); diff --git a/usb-linux.c b/usb-linux.c index 2a7b748..56898dd 100644 --- a/usb-linux.c +++ b/usb-linux.c @@ -83,7 +83,6 @@ struct endp_data { AsyncURB *iso_urb; int iso_urb_idx; int iso_buffer_used; - int max_packet_size; int inflight; }; @@ -259,26 +258,6 @@ static int get_iso_buffer_used(USBHostDevice *s, int pid, int ep) return get_endp(s, pid, ep)->iso_buffer_used; } -static void set_max_packet_size(USBHostDevice *s, int pid, int ep, - uint8_t *descriptor) -{ - int raw = descriptor[4] + (descriptor[5] << 8); - int size, microframes; - - size = raw & 0x7ff; - switch ((raw >> 11) & 3) { - case 1: microframes = 2; break; - case 2: microframes = 3; break; - default: microframes = 1; break; - } - get_endp(s, pid, ep)->max_packet_size = size * microframes; -} - -static int get_max_packet_size(USBHostDevice *s, int pid, int ep) -{ - return get_endp(s, pid, ep)->max_packet_size; -} - /* * Async URB state. * We always allocate iso packet descriptors even for bulk transfers @@ -674,7 +653,7 @@ static void usb_host_handle_destroy(USBDevice *dev) static AsyncURB *usb_host_alloc_iso(USBHostDevice *s, int pid, uint8_t ep) { AsyncURB *aurb; - int i, j, len = get_max_packet_size(s, pid, ep); + int i, j, len = usb_ep_get_max_packet_size(&s->dev, pid, ep); aurb = g_malloc0(s->iso_urb_count * sizeof(*aurb)); for (i = 0; i < s->iso_urb_count; i++) { @@ -754,7 +733,7 @@ static int usb_host_handle_iso_data(USBHostDevice *s, USBPacket *p, int in) int i, j, ret, max_packet_size, offset, len = 0; uint8_t *buf; - max_packet_size = get_max_packet_size(s, p->pid, p->devep); + max_packet_size = usb_ep_get_max_packet_size(&s->dev, p->pid, p->devep); if (max_packet_size == 0) return USB_RET_NAK; @@ -1133,6 +1112,7 @@ static int usb_linux_update_endp_table(USBHostDevice *s) { uint8_t *descriptors; uint8_t devep, type, alt_interface; + uint16_t raw; int interface, length, i, ep, pid; struct endp_data *epd; @@ -1200,9 +1180,8 @@ static int usb_linux_update_endp_table(USBHostDevice *s) } type = descriptors[i + 3] & 0x3; - if (type == USB_ENDPOINT_XFER_ISOC) { - set_max_packet_size(s, pid, ep, descriptors + i); - }; + raw = descriptors[i + 4] + (descriptors[i + 5] << 8); + usb_ep_set_max_packet_size(&s->dev, pid, ep, raw); assert(usb_ep_get_type(&s->dev, pid, ep) == USB_ENDPOINT_XFER_INVALID); usb_ep_set_type(&s->dev, pid, ep, type);