Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp675968ybl; Tue, 28 Jan 2020 09:57:12 -0800 (PST) X-Google-Smtp-Source: APXvYqwW2/kdBGMUvlpNa/pOmyoKlw/4VGC/qytYgBBYOM2q71bI6NtKn9q+LoAVHiqeOz/6wtgO X-Received: by 2002:aca:5490:: with SMTP id i138mr3714517oib.69.1580234232613; Tue, 28 Jan 2020 09:57:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580234232; cv=none; d=google.com; s=arc-20160816; b=vQj1zCx8JqkAf+TwWcfoLxKwjs7aaLReAX3RplHVSvvGmri+kfGhBYmdh8yQ2LUNmI 2sTmYu2LsCBwgHZluckY4PJOvk6UEOpTB4NCCTc7mvwuhZ4UFwpV9RzJqAmAc4Yz8rZr Fo+eLdb+u4g4VgdeoX3+BZ8ehPhD5i31q25VcT0nkPI+bxY4hZxfeYpwuWKcB5trG5a0 U1EAyNeEO+A6hUMhLJE8anaBpkrngX2HvpVL/Yvc4KqS0n6w5iBQGbqBkQx6Dt9msqGu WyKi6tEVTbBB8jWZPL44VN1UtvmgvAuePXXTGV5ZxYifMAlYZV5NhzYti7zHtgblPjSv NJ7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=ZY7xaJn7n2xK8pyc24KAivSTBtQ7s0DFRl/UfjgiFDQ=; b=VlqUS7I4veJGGU9GBbAjpIoNkVOvgd+S6bUHyX2BVk28BLeoJKE0jb4WNfCXQzx2+2 w2qbrHUU1snmFOGkAvTOJan6HyfkSBdnYxz6curwecW8yrX6lUBZlRLMey9Zc9AmQqhO ewlV6FObgf0iY3tyA3BMe0QYCkSj7zgW37nrl4PEgJHAHIBiAwzyXAtjZIMpWeU8aLqk dblNVcBgMIOndGB360sPj8gxdfHxZGSYXqGNJ2Zeiu1kr3SlmraoL9FlaxPnMuq8qyED 3/lkNf5hVJMnidu1RjqBdKofxJQqP+Cgh3MHcnjx43c/OirxbfUbQL4AjF8wsyyUlnuT nOnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CtNJv9u6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i12si5375292oik.171.2020.01.28.09.57.00; Tue, 28 Jan 2020 09:57:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CtNJv9u6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726557AbgA1R4E (ORCPT + 99 others); Tue, 28 Jan 2020 12:56:04 -0500 Received: from mail-oi1-f193.google.com ([209.85.167.193]:46053 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726233AbgA1R4E (ORCPT ); Tue, 28 Jan 2020 12:56:04 -0500 Received: by mail-oi1-f193.google.com with SMTP id v19so1279741oic.12 for ; Tue, 28 Jan 2020 09:56:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZY7xaJn7n2xK8pyc24KAivSTBtQ7s0DFRl/UfjgiFDQ=; b=CtNJv9u6gdgcpEgO+F9AYTS+Y/zbse1lthV5QHgKUjesjrGCTPaCMLny7uJCmY3C3X wOMApwMDTaji20lnDHokBwKeHHspyli2JrF4qHiina6D2KkhhfcvvIIDgwi3JWHhQ9u4 NdG3fdQHa2LGLGGV8/TGvZwCUd9m1WdD8QFAX2mX78OVSGgacCH5NuksHeyeKeqrTnsn zlnMHgESkru9PG5WE6QWNifpIMgKLTcCzxPjKAM9levONhdEkdvHIvA5IFGAWGUgsmTb waJDbzcFC5gSf1P0o4boXjpCOBQNSUwQ9kVgH2XG4N9a5204bzS9DFtCY5biZ+92h0Tb gwPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ZY7xaJn7n2xK8pyc24KAivSTBtQ7s0DFRl/UfjgiFDQ=; b=b+WIhl0OnGZhA6w/ZYLCJx4asymlVtqxfel/Pq+lXibRoIiw5/vbQWgO2x1CsmPPP4 Yej4vFL8T5wFxOL2mphtcL8Y9n23wmKxl53reh4VnikewpiarhUO2WHxd7pqDR8gW6cq T+cMbensq+0F6EO3O3CLqXOHsMAPbKc5TSXV9YCozoKKrN6y58+PERnZDilqkd6zcV1h 6kwknx53zXwp3v/GdYMuXs6EAP0dUPtvTmeQWCusJiUSnYkgKxEKDwXzjjPLsk0OtKrb SrnFdhg3sCZrD7Bh6qkpNNH1gYnfmUCbbnwCWWw1AMt9ZpjAurdCpMfPvbhy/PEsBaA7 esRg== X-Gm-Message-State: APjAAAV9DN4VHFxp61PRU5fUOtb0k9ivbANiwbOBvF//wQEu7i3jhKo3 8fOzw+k0KAnDrZAhkVaHwEDyDgnnGRvZnORhSzHTqQ== X-Received: by 2002:aca:c551:: with SMTP id v78mr3694137oif.161.1580234162434; Tue, 28 Jan 2020 09:56:02 -0800 (PST) MIME-Version: 1.0 References: <20200127193046.110258-1-john.stultz@linaro.org> <87sgjz90lt.fsf@kernel.org> In-Reply-To: <87sgjz90lt.fsf@kernel.org> From: John Stultz Date: Tue, 28 Jan 2020 09:55:50 -0800 Message-ID: Subject: Re: [PATCH v2] usb: dwc3: gadget: Check for IOC/LST bit in TRB->ctrl fields To: Felipe Balbi Cc: lkml , Anurag Kumar Vulisha , Yang Fei , Thinh Nguyen , Tejas Joglekar , Andrzej Pietrasiewicz , Jack Pham , Todd Kjos , Greg KH , Linux USB List , stable Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 28, 2020 at 5:23 AM Felipe Balbi wrote: > > > Hi, > > John Stultz writes: > > > From: Anurag Kumar Vulisha > > > > The current code in dwc3_gadget_ep_reclaim_completed_trb() will > > check for IOC/LST bit in the event->status and returns if > > IOC/LST bit is set. This logic doesn't work if multiple TRBs > > are queued per request and the IOC/LST bit is set on the last > > TRB of that request. > > > > Consider an example where a queued request has multiple queued > > TRBs and IOC/LST bit is set only for the last TRB. In this case, > > the core generates XferComplete/XferInProgress events only for > > the last TRB (since IOC/LST are set only for the last TRB). As > > per the logic in dwc3_gadget_ep_reclaim_completed_trb() > > event->status is checked for IOC/LST bit and returns on the > > first TRB. This leaves the remaining TRBs left unhandled. > > > > Similarly, if the gadget function enqueues an unaligned request > > with sglist already in it, it should fail the same way, since we > > will append another TRB to something that already uses more than > > one TRB. > > > > To aviod this, this patch changes the code to check for IOC/LST > > bits in TRB->ctrl instead. > > > > At a practical level, this patch resolves USB transfer stalls seen > > with adb on dwc3 based HiKey960 after functionfs gadget added > > scatter-gather support around v4.20. > > > > Cc: Felipe Balbi > > Cc: Yang Fei > > Cc: Thinh Nguyen > > Cc: Tejas Joglekar > > Cc: Andrzej Pietrasiewicz > > Cc: Jack Pham > > Cc: Todd Kjos > > Cc: Greg KH > > Cc: Linux USB List > > Cc: stable > > Tested-by: Tejas Joglekar > > Reviewed-by: Thinh Nguyen > > Signed-off-by: Anurag Kumar Vulisha > > [jstultz: forward ported to mainline, reworded commit log, reworked > > to only check trb->ctrl as suggested by Felipe] > > Signed-off-by: John Stultz > > --- > > v2: > > * Rework to only check trb->ctrl as suggested by Felipe > > * Reword the commit message to include more of Felipe's assessment > > --- > > drivers/usb/dwc3/gadget.c | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c > > index 154f3f3e8cff..9a085eee1ae3 100644 > > --- a/drivers/usb/dwc3/gadget.c > > +++ b/drivers/usb/dwc3/gadget.c > > @@ -2420,7 +2420,8 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct dwc3_ep *dep, > > if (event->status & DEPEVT_STATUS_SHORT && !chain) > > return 1; > > > > - if (event->status & DEPEVT_STATUS_IOC) > > + if ((trb->ctrl & DWC3_TRB_CTRL_IOC) || > > + (trb->ctrl & DWC3_TRB_CTRL_LST)) > > why the LST bit here? It wasn't there before. In fact, we never set LST > in dwc3 anymore :-) So, it was in the patch before, just on separate lines: https://lore.kernel.org/lkml/20200122222645.38805-2-john.stultz@linaro.org/ - if (event->status & DEPEVT_STATUS_IOC) + if ((event->status & DEPEVT_STATUS_IOC) && + (trb->ctrl & DWC3_TRB_CTRL_IOC)) + return 1; + + if ((event->status & DEPEVT_STATUS_LST) && + (trb->ctrl & DWC3_TRB_CTRL_LST)) return 1; So I just merged the two checks into one line. But I'm ok to drop the CTRL_LST check if that really isn't used. Let me know and I'll rework and resend. thanks -john