From patchwork Mon Jul 18 15:51:25 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 105315 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 95029B6F70 for ; Tue, 19 Jul 2011 02:06:31 +1000 (EST) Received: from localhost ([::1]:60772 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QiqKx-00089G-W7 for incoming@patchwork.ozlabs.org; Mon, 18 Jul 2011 12:06:28 -0400 Received: from eggs.gnu.org ([140.186.70.92]:51576) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qiq6e-00051o-80 for qemu-devel@nongnu.org; Mon, 18 Jul 2011 11:51:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qiq6a-0002iK-VO for qemu-devel@nongnu.org; Mon, 18 Jul 2011 11:51:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36054) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qiq6a-0002i7-55 for qemu-devel@nongnu.org; Mon, 18 Jul 2011 11:51:36 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p6IFpZcS009141 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 18 Jul 2011 11:51:35 -0400 Received: from rincewind.home.kraxel.org (vpn1-5-9.ams2.redhat.com [10.36.5.9]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p6IFpXlw010320; Mon, 18 Jul 2011 11:51:34 -0400 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id 93BCD40409; Mon, 18 Jul 2011 17:51:29 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Mon, 18 Jul 2011 17:51:25 +0200 Message-Id: <1311004288-10970-7-git-send-email-kraxel@redhat.com> In-Reply-To: <1311004288-10970-1-git-send-email-kraxel@redhat.com> References: <1311004288-10970-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 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 6/9] usb-host: iovec support 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 Add full support for iovecs to usb-host. The code can split large transfers into smaller ones already, we are using this to also split requests at iovec borders. Signed-off-by: Gerd Hoffmann --- usb-linux.c | 27 ++++++++++++++++++--------- 1 files changed, 18 insertions(+), 9 deletions(-) diff --git a/usb-linux.c b/usb-linux.c index 83ebf6e..536d93c 100644 --- a/usb-linux.c +++ b/usb-linux.c @@ -707,7 +707,7 @@ static int usb_host_handle_data(USBDevice *dev, USBPacket *p) USBHostDevice *s = DO_UPCAST(USBHostDevice, dev, dev); struct usbdevfs_urb *urb; AsyncURB *aurb; - int ret, rem; + int ret, rem, prem, v; uint8_t *pbuf; uint8_t ep; @@ -735,10 +735,18 @@ static int usb_host_handle_data(USBDevice *dev, USBPacket *p) return usb_host_handle_iso_data(s, p, p->pid == USB_TOKEN_IN); } - assert(p->iov.niov == 1); /* temporary */ - rem = p->iov.iov[0].iov_len; - pbuf = p->iov.iov[0].iov_base; + v = 0; + prem = p->iov.iov[v].iov_len; + pbuf = p->iov.iov[v].iov_base; + rem = p->iov.size; while (rem) { + if (prem == 0) { + v++; + assert(v < p->iov.niov); + prem = p->iov.iov[v].iov_len; + pbuf = p->iov.iov[v].iov_base; + assert(prem <= rem); + } aurb = async_alloc(s); aurb->packet = p; @@ -747,16 +755,17 @@ static int usb_host_handle_data(USBDevice *dev, USBPacket *p) urb->type = USBDEVFS_URB_TYPE_BULK; urb->usercontext = s; urb->buffer = pbuf; + urb->buffer_length = prem; - if (rem > MAX_USBFS_BUFFER_SIZE) { + if (urb->buffer_length > MAX_USBFS_BUFFER_SIZE) { urb->buffer_length = MAX_USBFS_BUFFER_SIZE; - aurb->more = 1; - } else { - urb->buffer_length = rem; - aurb->more = 0; } pbuf += urb->buffer_length; + prem -= urb->buffer_length; rem -= urb->buffer_length; + if (rem) { + aurb->more = 1; + } ret = ioctl(s->fd, USBDEVFS_SUBMITURB, urb);