From patchwork Fri Sep 26 16:55:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 38012 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5AD7E202DB for ; Fri, 26 Sep 2014 16:55:49 +0000 (UTC) Received: by mail-wg0-f72.google.com with SMTP id k14sf4162721wgh.3 for ; Fri, 26 Sep 2014 09:55:48 -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=XagJ2nVkMQGFw83gMO45d9P+NCOoacCIIGrDNsdTeYE=; b=TO5zuaUnUot4b3EKqMy1ZbTXLqP5OoVx08CmOEUb93o409EbIQ5UGNzX8Rh5ZtSNs8 oVchrYmvMP8G4Pa3ZP/brvz2Exq7ZXH2bBJYPXgzQstwyCPiIFfg2ZWkEH21UZ//0ci9 hFeAuRJHktwWRkafMM+OURUcmK6eLYh17eMoFi1La5gKbFtjs5QFFGG4DheOD67QXnsF cJCdEGLpisHXiW5fwS5S69dKqq5g/ZPUCEx/xkRnstOHJl3umDFrNYEGLHUbzGpwmtmX B5BWskjcjPoFZ+uTIZTnICmZAz2OHuWV7Cp9vAGzeLRwNsRQXy4WM1gQPxN3BQCnNBRl 4hVw== X-Gm-Message-State: ALoCoQkuoFTbRdnLyXOC3LGb5oJuQmSy905szINv02FLeEuziTF12IbiJ/CHITy883zmrfS9pDr3 X-Received: by 10.112.89.8 with SMTP id bk8mr3316151lbb.6.1411750547619; Fri, 26 Sep 2014 09:55:47 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.226 with SMTP id v2ls423061lav.50.gmail; Fri, 26 Sep 2014 09:55:47 -0700 (PDT) X-Received: by 10.112.235.70 with SMTP id uk6mr15811951lbc.89.1411750547470; Fri, 26 Sep 2014 09:55:47 -0700 (PDT) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com [209.85.215.52]) by mx.google.com with ESMTPS id lm5si3009454lac.87.2014.09.26.09.55.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 26 Sep 2014 09:55:47 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) client-ip=209.85.215.52; Received: by mail-la0-f52.google.com with SMTP id gq15so14764676lab.39 for ; Fri, 26 Sep 2014 09:55:47 -0700 (PDT) X-Received: by 10.112.4.33 with SMTP id h1mr20018014lbh.67.1411750546692; Fri, 26 Sep 2014 09:55:46 -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.130.169 with SMTP id of9csp94797lbb; Fri, 26 Sep 2014 09:55:44 -0700 (PDT) X-Received: by 10.68.220.10 with SMTP id ps10mr33683162pbc.135.1411750543437; Fri, 26 Sep 2014 09:55:43 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id or4si10379010pac.59.2014.09.26.09.55.42 for ; Fri, 26 Sep 2014 09:55:43 -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 S1755346AbaIZQzh (ORCPT + 3 others); Fri, 26 Sep 2014 12:55:37 -0400 Received: from bear.ext.ti.com ([192.94.94.41]:33809 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755143AbaIZQzf (ORCPT ); Fri, 26 Sep 2014 12:55:35 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id s8QGtW2C004546; Fri, 26 Sep 2014 11:55:32 -0500 Received: from DLEE70.ent.ti.com (dlemailx.itg.ti.com [157.170.170.113]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s8QGtWbO029729; Fri, 26 Sep 2014 11:55:32 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.174.1; Fri, 26 Sep 2014 11:55:32 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s8QGtVZc019222; Fri, 26 Sep 2014 11:55:32 -0500 Date: Fri, 26 Sep 2014 11:55:29 -0500 From: Felipe Balbi To: Felipe Balbi CC: Alan Stern , Linux USB Mailing List Subject: Re: g_mass_storage & READ_CAPACITY(16) Message-ID: <20140926165529.GH26227@saruman> Reply-To: References: <20140926153716.GD26227@saruman> <20140926161503.GG26227@saruman> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20140926161503.GG26227@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.52 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 Fri, Sep 26, 2014 at 11:15:03AM -0500, Felipe Balbi wrote: > On Fri, Sep 26, 2014 at 12:06:00PM -0400, Alan Stern wrote: > > > Any hints will be appreciated. > > > > We could implement READ CAPACITY(16) if necessary. But since we don't > > implement READ(16) or WRITE(16), it seems rather pointless. > > > > Are you certain you are interpreting the USBCV output correctly? > > heh, yes I am. That READ CAPACITY(16) is just a note, not the error > itself. It seems like one of the CSWs (it sends a lot of commands on > this test) was sent with zero bytes. I'll go fire up the sniffer and > debug this further. alright, found it. It was caused by another bug on my set_stall fix. Now, hopefully, it's all fixed. Passing USB20CV chapter 9 and MSC tests, also working against Linux and Mac OS X. Here's the final patch, I'll send it officialy once the merge window has closed: 8<-------------------------------------------------------------------- >From 4c6282e877ebef6db6bde6f661acf4ea37b3920a Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Wed, 24 Sep 2014 14:19:52 -0500 Subject: [PATCH] usb: dwc3: gadget: fix set_halt() bug with pending transfers According to our Gadget Framework API documentation, ->set_halt() *must* return -EAGAIN if we have pending transfers (on either direction) or FIFO isn't empty (on TX endpoints). Fix this bug so that the mass storage gadget can be used without stall=0 parameter. This patch should be backported to all kernels since v3.2. Cc: # v3.2+ Suggested-by: Alan Stern Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/ep0.c | 4 ++-- drivers/usb/dwc3/gadget.c | 16 ++++++++++++---- drivers/usb/dwc3/gadget.h | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c index 36f6158..ae6b575 100644 --- a/drivers/usb/dwc3/ep0.c +++ b/drivers/usb/dwc3/ep0.c @@ -256,7 +256,7 @@ static void dwc3_ep0_stall_and_restart(struct dwc3 *dwc) /* stall is always issued on EP0 */ dep = dwc->eps[0]; - __dwc3_gadget_ep_set_halt(dep, 1); + __dwc3_gadget_ep_set_halt(dep, 1, false); dep->flags = DWC3_EP_ENABLED; dwc->delayed_status = false; @@ -480,7 +480,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc, return -EINVAL; if (set == 0 && (dep->flags & DWC3_EP_WEDGE)) break; - ret = __dwc3_gadget_ep_set_halt(dep, set); + ret = __dwc3_gadget_ep_set_halt(dep, set, true); if (ret) return -EINVAL; break; diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index de53361..68497b3 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -581,7 +581,7 @@ static int __dwc3_gadget_ep_disable(struct dwc3_ep *dep) /* make sure HW endpoint isn't stalled */ if (dep->flags & DWC3_EP_STALL) - __dwc3_gadget_ep_set_halt(dep, 0); + __dwc3_gadget_ep_set_halt(dep, 0, false); reg = dwc3_readl(dwc->regs, DWC3_DALEPENA); reg &= ~DWC3_DALEPENA_EP(dep->number); @@ -1202,7 +1202,7 @@ out0: return ret; } -int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value) +int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value, int protocol) { struct dwc3_gadget_ep_cmd_params params; struct dwc3 *dwc = dep->dwc; @@ -1216,6 +1216,14 @@ int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value) memset(¶ms, 0x00, sizeof(params)); if (value) { + if (!protocol && ((dep->direction && dep->flags & DWC3_EP_BUSY) || + (!list_empty(&dep->req_queued) || + !list_empty(&dep->request_list)))) { + dev_dbg(dwc->dev, "%s: pending request, cannot halt\n", + dep->name); + return -EAGAIN; + } + ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, DWC3_DEPCMD_SETSTALL, ¶ms); if (ret) @@ -1246,7 +1254,7 @@ static int dwc3_gadget_ep_set_halt(struct usb_ep *ep, int value) int ret; spin_lock_irqsave(&dwc->lock, flags); - ret = __dwc3_gadget_ep_set_halt(dep, value); + ret = __dwc3_gadget_ep_set_halt(dep, value, false); spin_unlock_irqrestore(&dwc->lock, flags); return ret; @@ -1265,7 +1273,7 @@ static int dwc3_gadget_ep_set_wedge(struct usb_ep *ep) if (dep->number == 0 || dep->number == 1) ret = __dwc3_gadget_ep0_set_halt(ep, 1); else - ret = __dwc3_gadget_ep_set_halt(dep, 1); + ret = __dwc3_gadget_ep_set_halt(dep, 1, false); spin_unlock_irqrestore(&dwc->lock, flags); return ret; diff --git a/drivers/usb/dwc3/gadget.h b/drivers/usb/dwc3/gadget.h index f889008..18ae3ea 100644 --- a/drivers/usb/dwc3/gadget.h +++ b/drivers/usb/dwc3/gadget.h @@ -86,7 +86,7 @@ int __dwc3_gadget_ep0_set_halt(struct usb_ep *ep, int value); int dwc3_gadget_ep0_set_halt(struct usb_ep *ep, int value); int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request, gfp_t gfp_flags); -int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value); +int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value, int protocol); /** * dwc3_gadget_ep_get_transfer_index - Gets transfer index from HW