From patchwork Thu Oct 23 13:49:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 39366 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f71.google.com (mail-ee0-f71.google.com [74.125.83.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 03C2920341 for ; Thu, 23 Oct 2014 13:49:51 +0000 (UTC) Received: by mail-ee0-f71.google.com with SMTP id e51sf882255eek.2 for ; Thu, 23 Oct 2014 06:49:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:date:from:to:cc:subject:message-id :reply-to:references:mime-version:content-type:content-disposition :in-reply-to:user-agent:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=IhwIJ6eFNaloOxHYqj5R1HbZ1cIiRfe7Og/ksAtOZQ8=; b=kZoJoaDuu0/BPUw4EIQ5EsZB8qaoX2bXUjz88fsHA0lAMJtHqNHKWQ90oSh3H4B6fZ yX73V3fOwQXDHki7g+lF7WINKZm9Nk7gDZxiysyLoiIqNe/qDxfdeV8KaHatRinwkxom wgS8BcrUmdkR+WXVqberQheI0+mIqFk/4ZHPnezRyLKlk4B8c7+6F00neanl3RwJ312n e67EhxlZEt/d1DeC15rW7ZcyseKLtrH0Mz4ek746YX+aOKamLJkuHjKCHAwI9G96M8rE 3TCYRw90J+bRhxpwKKELeIkr7IEN6FRglJpNKkdhlQmuQS/yaL3Ihq8XIKQ4IgDbwvME kNIw== X-Gm-Message-State: ALoCoQlthCVl4lSmHGGPjvx01e2pmerIHS273GmjehjvPte9UyGOjSTQRJXwX82FcyyccmRVAj+b X-Received: by 10.112.140.132 with SMTP id rg4mr644278lbb.12.1414072191137; Thu, 23 Oct 2014 06:49:51 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.44.229 with SMTP id h5ls346499lam.4.gmail; Thu, 23 Oct 2014 06:49:51 -0700 (PDT) X-Received: by 10.112.146.37 with SMTP id sz5mr5187930lbb.27.1414072190991; Thu, 23 Oct 2014 06:49:50 -0700 (PDT) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id 1si2737344lai.41.2014.10.23.06.49.50 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 23 Oct 2014 06:49:50 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by mail-la0-f42.google.com with SMTP id gf13so992289lab.15 for ; Thu, 23 Oct 2014 06:49:50 -0700 (PDT) X-Received: by 10.112.130.41 with SMTP id ob9mr5176046lbb.74.1414072190908; Thu, 23 Oct 2014 06:49:50 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp258076lbz; Thu, 23 Oct 2014 06:49:48 -0700 (PDT) X-Received: by 10.66.218.7 with SMTP id pc7mr3745946pac.133.1414072188199; Thu, 23 Oct 2014 06:49:48 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fg6si1592855pad.209.2014.10.23.06.49.47 for ; Thu, 23 Oct 2014 06:49:48 -0700 (PDT) Received-SPF: none (google.com: linux-usb-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755965AbaJWNtc (ORCPT + 3 others); Thu, 23 Oct 2014 09:49:32 -0400 Received: from comal.ext.ti.com ([198.47.26.152]:56794 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751879AbaJWNt3 (ORCPT ); Thu, 23 Oct 2014 09:49:29 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id s9NDnKip028571; Thu, 23 Oct 2014 08:49:20 -0500 Received: from DLEE70.ent.ti.com (dlee70.ent.ti.com [157.170.170.113]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s9NDnJYx019333; Thu, 23 Oct 2014 08:49:19 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.174.1; Thu, 23 Oct 2014 08:49:19 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s9NDnIHt018042; Thu, 23 Oct 2014 08:49:19 -0500 Date: Thu, 23 Oct 2014 08:49:03 -0500 From: Felipe Balbi To: Felipe Balbi CC: Alan Stern , Anton Tikhomirov , "'Paul Zimmerman'" , "'David Laight'" , "'Linux USB Mailing List'" Subject: Re: [PATCH 18/28] usb: dwc3: ep0: fix Data Phase for transfer sizes aligned to wMaxPacketSize Message-ID: <20141023134903.GB13573@saruman> Reply-To: References: <00b701cfedbc$1f1750d0$5d45f270$%tikhomirov@samsung.com> <20141023134808.GA13573@saruman> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20141023134808.GA13573@saruman> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-usb-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: balbi@ti.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Hi, On Thu, Oct 23, 2014 at 08:48:08AM -0500, Felipe Balbi wrote: > On Wed, Oct 22, 2014 at 10:14:54AM -0400, Alan Stern wrote: > > On Wed, 22 Oct 2014, Anton Tikhomirov wrote: > > > > > > That's right, and it's true for USB-2 as well. A ZLP is needed only in > > > > cases where the host otherwise wouldn't know the transfer is over, > > > > i.e., when the transfer length is a nonzero multiple of the maxpacket > > > > size and is smaller than wLength. > > > > > > Shall we use/check struct usb_request's zero flag for this? > > > > Of course; we have to. There's no other way for the UDC driver to know > > whether the transfer is shorter than the host expects. > > alright, so I take it this incremental diff is enough ? > > diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c > index 0a34e71..ce6b0c7 100644 > --- a/drivers/usb/dwc3/ep0.c > +++ b/drivers/usb/dwc3/ep0.c > @@ -830,7 +830,8 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc, > } else { > dwc3_gadget_giveback(ep0, r, 0); > > - if (IS_ALIGNED(ur->length, ep0->endpoint.maxpacket)) { > + if (IS_ALIGNED(ur->length, ep0->endpoint.maxpacket) && > + ur->zero) { > int ret; > > dwc->ep0_next_event = DWC3_EP0_COMPLETE; > here's v2: 8<-------------------------------------------------------------- >From 1080b54d66e3e77410b41732e76746ed8e2c01c7 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Tue, 30 Sep 2014 10:39:14 -0500 Subject: [PATCH] usb: dwc3: ep0: fix Data Phase for transfer sizes aligned to wMaxPacketSize According to Section 8.5.3.2 of the USB 2.0 specification, a USB device must terminate a Data Phase with either a short packet or a ZLP (if the previous transfer was a multiple of wMaxPacketSize). For reference, here's what the USB 2.0 specification, section 8.5.3.2 says: " 8.5.3.2 Variable-length Data Stage A control pipe may have a variable-length data phase in which the host requests more data than is contained in the specified data structure. When all of the data structure is returned to the host, the function should indicate that the Data stage is ended by returning a packet that is shorter than the MaxPacketSize for the pipe. If the data structure is an exact multiple of wMaxPacketSize for the pipe, the function will return a zero-length packet to indicate the end of the Data stage. " Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/ep0.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c index a47cc1e..ce6b0c7 100644 --- a/drivers/usb/dwc3/ep0.c +++ b/drivers/usb/dwc3/ep0.c @@ -828,12 +828,19 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc, dwc3_ep0_stall_and_restart(dwc); } else { - /* - * handle the case where we have to send a zero packet. This - * seems to be case when req.length > maxpacket. Could it be? - */ - if (r) - dwc3_gadget_giveback(ep0, r, 0); + dwc3_gadget_giveback(ep0, r, 0); + + if (IS_ALIGNED(ur->length, ep0->endpoint.maxpacket) && + ur->zero) { + int ret; + + dwc->ep0_next_event = DWC3_EP0_COMPLETE; + + ret = dwc3_ep0_start_trans(dwc, epnum, + dwc->ctrl_req_addr, 0, + DWC3_TRBCTL_CONTROL_DATA); + WARN_ON(ret < 0); + } } }