From patchwork Fri Oct 17 17:09:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 38909 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f70.google.com (mail-ee0-f70.google.com [74.125.83.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B076E202DB for ; Fri, 17 Oct 2014 17:10:43 +0000 (UTC) Received: by mail-ee0-f70.google.com with SMTP id c13sf791360eek.9 for ; Fri, 17 Oct 2014 10:10:42 -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:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=yI0PO9+LLf96hPCWwKoOubXiOsvCHMCoPyOC9YX1X2k=; b=LY7XxGrYUZODPRHcsdTh0uBwUezd1jViXDPsNnpa5NtKRupV80Df6A1Oej3Kw1N6kd 3u1pSAttSlrO7iKyQl7F9IjHt/K9ZEs+ubmmBumo6EJuj29ttTq48dGL8hD5YIsoE/Zu DLapiQG7REAbZCIT2pfMYz2RVx/Db5XfUpEYMEnsI1fqCHAyrtf8rayYFA+2UYpAjtD1 ispPa+i9YXVXAS6CFyZnA0XxTw/KQ2hSMCskex75DMk14PRxCZ2mXFG5RpXxfBGeS444 MYu9E0i7PqDB9qbIKPNU8iLsXqbiDZe/1lrhApDVmzTIjNDdeJ31zdPcEhWOU80zhu6i 5zkw== X-Gm-Message-State: ALoCoQkuXaJsKlP5y2VkSBGoP7kPZY1mm6Y0HIO8YDQ88cy8kHq43SZv3HlHFFXJivo2ZdtAaXLk X-Received: by 10.180.96.101 with SMTP id dr5mr55869wib.0.1413565842574; Fri, 17 Oct 2014 10:10:42 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.4.7 with SMTP id g7ls280025lag.43.gmail; Fri, 17 Oct 2014 10:10:42 -0700 (PDT) X-Received: by 10.112.247.43 with SMTP id yb11mr10178582lbc.51.1413565842447; Fri, 17 Oct 2014 10:10:42 -0700 (PDT) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id ay3si3022007lbc.4.2014.10.17.10.10.42 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 17 Oct 2014 10:10:42 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by mail-lb0-f169.google.com with SMTP id 10so1037711lbg.0 for ; Fri, 17 Oct 2014 10:10:42 -0700 (PDT) X-Received: by 10.152.5.38 with SMTP id p6mr5579785lap.44.1413565842359; Fri, 17 Oct 2014 10:10:42 -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 c5csp266742lbz; Fri, 17 Oct 2014 10:10:41 -0700 (PDT) X-Received: by 10.70.19.101 with SMTP id d5mr9771478pde.79.1413565840816; Fri, 17 Oct 2014 10:10:40 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id wq7si1512337pbc.257.2014.10.17.10.10.40 for ; Fri, 17 Oct 2014 10:10:40 -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 S1753543AbaJQRKe (ORCPT + 3 others); Fri, 17 Oct 2014 13:10:34 -0400 Received: from devils.ext.ti.com ([198.47.26.153]:35999 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753526AbaJQRKe (ORCPT ); Fri, 17 Oct 2014 13:10:34 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id s9HHAXxR024657 for ; Fri, 17 Oct 2014 12:10:33 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id s9HHAXsl023194 for ; Fri, 17 Oct 2014 12:10:33 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.174.1; Fri, 17 Oct 2014 12:10:33 -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 s9HHAW6c022320; Fri, 17 Oct 2014 12:10:33 -0500 From: Felipe Balbi To: Linux USB Mailing List CC: Felipe Balbi Subject: [PATCH 18/28] usb: dwc3: ep0: fix Data Phase for transfer sizes aligned to wMaxPacketSize Date: Fri, 17 Oct 2014 12:09:54 -0500 Message-ID: <1413565804-13061-19-git-send-email-balbi@ti.com> X-Mailer: git-send-email 2.1.0.GIT In-Reply-To: <1413565804-13061-1-git-send-email-balbi@ti.com> References: <1413565804-13061-1-git-send-email-balbi@ti.com> MIME-Version: 1.0 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.217.169 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: , 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 | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c index a47cc1e..0a34e71 100644 --- a/drivers/usb/dwc3/ep0.c +++ b/drivers/usb/dwc3/ep0.c @@ -828,12 +828,18 @@ 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)) { + 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); + } } }