From patchwork Fri Jun 28 18:24:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 168121 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4020562ilk; Fri, 28 Jun 2019 11:24:19 -0700 (PDT) X-Received: by 2002:a17:90a:3aed:: with SMTP id b100mr15005340pjc.63.1561746259835; Fri, 28 Jun 2019 11:24:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561746259; cv=none; d=google.com; s=arc-20160816; b=mcfcA1wu4nHjZ69SGy6ZmelpjTIRvE+8EGBTCPG+qKFoIVTqT87jsjQHFrmmVg1gfV slw5FAGgzONtaezElpejnKUPePGYmBlKrqSvkYP3hc+6CpjvcmCJ3XOj8JvK6r9BJLYg w5pngJIi8RYdxxIdVkiVM3+X20CprNEghqnhCWYUsv/SgwIjV7bWYfm4dynWLChc0Vzw ptyoGFHYVLPem9zxK0z6m/2KOCP0uMoVmpjQ0dp9EoGHLXUSQfMpWYJLN3ajpCL+OcYZ VPve+1R5q8NKC5+Za6780VqZhQIIJPPuqRpSzu4cbQxYgc5tHjdjv/0xbhcJkSb3WTUW JASQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=80ekKnnJbJ+N9S8CSdtwlr9DiGvzY1b4sXIFJmFharo=; b=rpRkqtsI9h6Fo5r8a28UGP2sPhQY9ySynBDzaW50xjiVPYz11ZICzZPfU8hx+5vJlc Eg9qt+ZUdjkXUhV5XFPAxqPauzcUaVsRUelhT2ZDC4hAgc3Gkj1hO2PhRMUWfSAiVFb7 b2vwOnXTjuz6pZqUO4xHb0auZsdmpu3NepFhVcygye3s3xqJrjPuRNf8OS+bL5vnmCjj zTL7VJksmne326YkhKP51rI27ioOUJ82QnKVoOfcEm1oXXh/KCKaPSP1NXUlDbplCwpF 4BEPmXcZBwTvAnwTDzhE9kQrxlZkKb45FFr8db679cgrQa5nekssUM6XyWhgLuZcDLj2 AlpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N7n5rsXU; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id v13sor1289255pgn.35.2019.06.28.11.24.19 for (Google Transport Security); Fri, 28 Jun 2019 11:24:19 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N7n5rsXU; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=80ekKnnJbJ+N9S8CSdtwlr9DiGvzY1b4sXIFJmFharo=; b=N7n5rsXUCKOo6iC/j6Yoz9nSlgDmhyVVXfwTfbqvI75MhNqSHBZsu4UTtnGk8jwnRF JqwdgJqAPKCBXPBDgBNzH9lPdRsDPtse3H4Vy+BCQxCwiDK6eWz/q4Z+H7DWjEmhmfPH 7NMrKie2+MIA0cv9h52OEILExdLi9Hcd4CTPftfm2fuLKQXzIjSGTcRhFX//WCnMQguZ dEZvZpfGFB0AvGkSJHD24Fc9fN/OYEuugW6/Zde80HoCUdKux8R65Q7z2wW4ba87gjrr mOP+oLCf0Qr+r1i0D6AtaTcua9wlmRg2n820LMTDC32lDtniMVCg35R0eLhIUN/hDczp Muow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=80ekKnnJbJ+N9S8CSdtwlr9DiGvzY1b4sXIFJmFharo=; b=qXgeu2eTvxroq2GzzX4A//jR/DJQ3i/EHWALyCSuzxB7Y6c2HtNgh+NExbeTYHSHHe JX+IzLa3iow5QPzpmZNxtRHxPSLVcD+RACS2qd16WPX5qmIl2TQYRyclO9hT8DhLQ3gU ZEg/Hom6ppxP6ppKH1JvR4tPdSwlkoCNtRNNGVncUKYNKtvQ1hVNOslaQRgD5cCn644j c6b7AYCmJAwDpbb9p1inRRJo/H6OL9a91IR+8PbI49QH4XR0fSBGTQr077JDS+ouY8L8 wXJl1lx2L+qMPK2kMnWPTtAFcJZe5s80jIzANyabCbzf07/FH8Mk7ubBbYa/RFYK4ruV asog== X-Gm-Message-State: APjAAAUW7rii/0HU5tEiAzAIbNh7tQDitwRH09Esu6A7MRI2PP2w0grS HJ9smALjx0jUWbDqkueEk6kNZy3nIObogA== X-Google-Smtp-Source: APXvYqyYnBAyWCgFARuxspznmYO7UnkE0AX8irdmIt+l6LSBhyP2TvzeVO9riPN40MErj5bcpzk/jQ== X-Received: by 2002:a63:db07:: with SMTP id e7mr6227730pgg.110.1561746259294; Fri, 28 Jun 2019 11:24:19 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id s15sm2916223pfd.183.2019.06.28.11.24.17 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 28 Jun 2019 11:24:17 -0700 (PDT) From: John Stultz To: stable@vger.kernel.org Cc: John Stultz , Fei Yang , Sam Protsenko , Felipe Balbi , linux-usb@vger.kernel.org Subject: [PATCH 4.19.y v2 1/9] Revert "usb: dwc3: gadget: Clear req->needs_extra_trb flag on cleanup" Date: Fri, 28 Jun 2019 18:24:05 +0000 Message-Id: <20190628182413.33225-2-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190628182413.33225-1-john.stultz@linaro.org> References: <20190628182413.33225-1-john.stultz@linaro.org> This reverts commit 25ad17d692ad54c3c33b2a31e5ce2a82e38de14e, as we will be cherry-picking a number of changes from upstream that allows us to later cherry-pick the same fix from upstream rather than using this modified backported version. Cc: Fei Yang Cc: Sam Protsenko Cc: Felipe Balbi Cc: linux-usb@vger.kernel.org Cc: stable@vger.kernel.org # 4.19.y Signed-off-by: John Stultz --- drivers/usb/dwc3/gadget.c | 2 -- 1 file changed, 2 deletions(-) -- 2.17.1 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 65ba1038b111..eaa78e6c972c 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -177,8 +177,6 @@ static void dwc3_gadget_del_and_unmap_request(struct dwc3_ep *dep, req->started = false; list_del(&req->list); req->remaining = 0; - req->unaligned = false; - req->zero = false; if (req->request.status == -EINPROGRESS) req->request.status = status; From patchwork Fri Jun 28 18:24:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 168122 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4020589ilk; Fri, 28 Jun 2019 11:24:21 -0700 (PDT) X-Received: by 2002:a65:498c:: with SMTP id r12mr10331929pgs.27.1561746261145; Fri, 28 Jun 2019 11:24:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561746261; cv=none; d=google.com; s=arc-20160816; b=uf6z5iXAA64gbxwUa4Au9kQzgi5CClXxz3r/X2JI0uuKiqJJvMbCq8TejplqujN6e8 4TUNndc+H2H3XloQ+4NwOCdrDynAbs+AZJgzNkFuN6Vp3VPJmFW3Ow3NiZFV55EDC1Wo nmhG3QfwwIrJRFVJ1i3hPOqlMiUpzaDGo4pyUw5/NUDxxljJX77sDkwG/fj65iolfODd iBFYHowE2XtSIxP/6oOvBuUhSrrQr5L6py4BeN+zotmrvuCe0Rgx/YTcyg/hNfTsl10v HAlel6sTBd6VjpbnYHkA9Nr2oeC9Jm2G0u4/u/fXKj+K/x3FUVVirZyI57+EkqeSRGsY A+zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=88fRjj74GZN01nX0sSKgncvdEa4gXr3r1F+OW3u4lS8=; b=BNlfou9Qo+bhGHbUZYTTgBE98xLDpnncsby4O/pWJM+WZSEALly2jT6LwxPAV1DNu5 zeJmcyaUIzd0Z4OeYxi9aI3hIWvn0P7BaV1qL75ZOxyszZyNM1mT5n/TCnd9HftkL53e 6XbO68406xXR+jwDM8kEdPB91zFoRtKJpz9H8qD3WCzI200jLksBwcNj4M9Uq1NMXOVo tX5lln87k5i5yubn63ztoxfVyCYr+c7hj545SL8KNXSyLVb1ulg1Smi0tlt0S6QIZMO4 uWuUThz9kZeWLdFb9xUM5GIc5NqawgWtN8zuL7hfB1xpZGhUAhQkJK189b7xKuEwN28B ZTkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DFywPhvk; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id n9sor650738pgl.53.2019.06.28.11.24.21 for (Google Transport Security); Fri, 28 Jun 2019 11:24:21 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DFywPhvk; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=88fRjj74GZN01nX0sSKgncvdEa4gXr3r1F+OW3u4lS8=; b=DFywPhvkx8VftWLHnF+hjOhCP6z+9tHooSDVr5iWKkQbFcu5W0rypK+ZNa1k4CrKbB rgSLyJw90E0YW8ciwrDmdc6ngSaPML6MUHTa5+OAFRfKkOPKdlOYDyBfEwmV6otqdQ2k e4vBJlYrxYGGN3ip5ijM4/EzHyxDTV381B1Im51Bp2AzgD8zltbEBG4CmolNXogB+s1D Xma67Uu4qPudHxECpKjjiERRBudywazCn+n6NwdKH/6nDJw/+IhYguEkJRcAiH7ROKvH 4BJQUbgP/bazB9mr5ekU4tc0Fo7EdK1W6PiervT5dKCKSTLcjOgUS1gbPDxUeBu8F3pi Zbcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=88fRjj74GZN01nX0sSKgncvdEa4gXr3r1F+OW3u4lS8=; b=RXxmYQ0sn3stO6DgKksYKwOSsSbm/DcEsg8a7BWR57MnDYkyZ7l66tJ+leYoC3lc3s 92S8jmY/GncRhmDbHgysKihXbqVGgj2miwENWTySeCq12zhLnPElwuSqvv5iEr1oSMkk 3DIyTeRcLg+4VQQ24WBmgd4q2YxpJdCtSIEhDFvFFi0ExWZ5NVFP/AXgbJe2Qpaec7aq PKB0ZjLdoaR7h+76JQDsOdgDq2+60xx597duGK9Yux73ZieJUiBLwRo1XPQBwA4byl5c BPNf8uBbm3KYtki1PIMgTe50bkUrDnuuDlX+3RG2z1V6r/MdI4OX64uLNZoXzgNrrMoO xygA== X-Gm-Message-State: APjAAAWWqF/rIvEAPLYN4f3sQE8tEkbWOnp6vU+73RG7lyJUGd9EbGmC e49KIxGyi7sHAiki6HOG8ysj/Dyx X-Google-Smtp-Source: APXvYqzSf+2FES9KMIflO6lAuK1yNAY9PsuuqnAtpqrmG1IdzcjRxQg9SWRS+em/RPAfgRad+TT+CA== X-Received: by 2002:a63:f817:: with SMTP id n23mr10705991pgh.35.1561746260608; Fri, 28 Jun 2019 11:24:20 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id s15sm2916223pfd.183.2019.06.28.11.24.19 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 28 Jun 2019 11:24:19 -0700 (PDT) From: John Stultz To: stable@vger.kernel.org Cc: Felipe Balbi , Fei Yang , Sam Protsenko , Felipe Balbi , linux-usb@vger.kernel.org, John Stultz Subject: [PATCH 4.19.y v2 2/9] usb: dwc3: gadget: combine unaligned and zero flags Date: Fri, 28 Jun 2019 18:24:06 +0000 Message-Id: <20190628182413.33225-3-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190628182413.33225-1-john.stultz@linaro.org> References: <20190628182413.33225-1-john.stultz@linaro.org> From: Felipe Balbi commit 1a22ec643580626f439c8583edafdcc73798f2fb upstream Both flags are used for the same purpose in dwc3: appending an extra TRB at the end to deal with controller requirements. By combining both flags into one, we make it clear that the situation is the same and that they should be treated equally. Cc: Fei Yang Cc: Sam Protsenko Cc: Felipe Balbi Cc: linux-usb@vger.kernel.org Cc: stable@vger.kernel.org # 4.19.y Signed-off-by: Felipe Balbi (cherry picked from commit 1a22ec643580626f439c8583edafdcc73798f2fb) Signed-off-by: John Stultz --- drivers/usb/dwc3/core.h | 7 +++---- drivers/usb/dwc3/gadget.c | 18 +++++++++--------- 2 files changed, 12 insertions(+), 13 deletions(-) -- 2.17.1 diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 5bfb62533e0f..4872cba8699b 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -847,11 +847,11 @@ struct dwc3_hwparams { * @epnum: endpoint number to which this request refers * @trb: pointer to struct dwc3_trb * @trb_dma: DMA address of @trb - * @unaligned: true for OUT endpoints with length not divisible by maxp + * @needs_extra_trb: true when request needs one extra TRB (either due to ZLP + * or unaligned OUT) * @direction: IN or OUT direction flag * @mapped: true when request has been dma-mapped * @started: request is started - * @zero: wants a ZLP */ struct dwc3_request { struct usb_request request; @@ -867,11 +867,10 @@ struct dwc3_request { struct dwc3_trb *trb; dma_addr_t trb_dma; - unsigned unaligned:1; + unsigned needs_extra_trb:1; unsigned direction:1; unsigned mapped:1; unsigned started:1; - unsigned zero:1; }; /* diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index eaa78e6c972c..8db7466e4f76 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1068,7 +1068,7 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, struct dwc3 *dwc = dep->dwc; struct dwc3_trb *trb; - req->unaligned = true; + req->needs_extra_trb = true; /* prepare normal TRB */ dwc3_prepare_one_trb(dep, req, true, i); @@ -1112,7 +1112,7 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, struct dwc3 *dwc = dep->dwc; struct dwc3_trb *trb; - req->unaligned = true; + req->needs_extra_trb = true; /* prepare normal TRB */ dwc3_prepare_one_trb(dep, req, true, 0); @@ -1128,7 +1128,7 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, struct dwc3 *dwc = dep->dwc; struct dwc3_trb *trb; - req->zero = true; + req->needs_extra_trb = true; /* prepare normal TRB */ dwc3_prepare_one_trb(dep, req, true, 0); @@ -1410,7 +1410,7 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, dwc3_ep_inc_deq(dep); } - if (r->unaligned || r->zero) { + if (r->needs_extra_trb) { trb = r->trb + r->num_pending_sgs + 1; trb->ctrl &= ~DWC3_TRB_CTRL_HWO; dwc3_ep_inc_deq(dep); @@ -1421,7 +1421,7 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, trb->ctrl &= ~DWC3_TRB_CTRL_HWO; dwc3_ep_inc_deq(dep); - if (r->unaligned || r->zero) { + if (r->needs_extra_trb) { trb = r->trb + 1; trb->ctrl &= ~DWC3_TRB_CTRL_HWO; dwc3_ep_inc_deq(dep); @@ -2250,7 +2250,8 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct dwc3_ep *dep, * with one TRB pending in the ring. We need to manually clear HWO bit * from that TRB. */ - if ((req->zero || req->unaligned) && !(trb->ctrl & DWC3_TRB_CTRL_CHN)) { + + if (req->needs_extra_trb && !(trb->ctrl & DWC3_TRB_CTRL_CHN)) { trb->ctrl &= ~DWC3_TRB_CTRL_HWO; return 1; } @@ -2327,11 +2328,10 @@ static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep, ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event, status); - if (req->unaligned || req->zero) { + if (req->needs_extra_trb) { ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event, status); - req->unaligned = false; - req->zero = false; + req->needs_extra_trb = false; } req->request.actual = req->request.length - req->remaining; From patchwork Fri Jun 28 18:24:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 168123 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4020620ilk; Fri, 28 Jun 2019 11:24:22 -0700 (PDT) X-Received: by 2002:a63:e356:: with SMTP id o22mr7852944pgj.150.1561746262777; Fri, 28 Jun 2019 11:24:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561746262; cv=none; d=google.com; s=arc-20160816; b=hDQIFph2fWrgFCvRXtfcJQXICLIFzax2LMoK+Y+Jd8dDr0+TaBn0khRqyWHP9RtKxA 7L4KhGB0OpHlJPNT0JbNiYPikvSdfrii378oiSSjMORlQFRCFfUXSnu9w2QmRUMy+CWC 2S9uuJ+aBrZVKHn9obS3gAfFKiJHscDirF9GVPdM0VtynqZPoIiFLGNwQ0xzULAzgDZR F9jawwxls4znfyTin26j8wiSBWSNffXwpQRmwL8TrFwyaqDDmhdpsFU8ac+u58Tuyrw3 k7Ew8U4TEDn/GqAYoQc21xj7VI9c4nTwBS3/4laExBkr/IRKNqiUfK7NPVteJTHladfG ZCfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ih7U4hpwGmfoDyYEDt6ssld4EzhtjygGMzYklaGP3Wc=; b=0F7oNUWiLqd7u8GpW0KvllembTeqen94+5NoFU/mDuYU8wGUXm5+6y5sPosBnUH6Ay Bjr8BsDDLIAfcJhwulYZDq23oSEDc4DpM0aPJ9ctnbrLflj3c7GTKctdLgF0Pt29bVjG +FG5+hRTWnlCNZWzwsN/WiNc+fi8WWEek+yAM8yX7u5wM8RyzNGLJnGCNzWPcBpnOwKk Q8He1FCrZ4f0f0+wqVE4/D2RqnZBCKsStgNQebqtEgpFCIEBPd9uiHMCqpc1/QtDoqcW Q0Mv4+rJuKhtkm6WE6C60/E5IKMOABpcF0x+SUJdY43KVv/8Is9SpyRw2yUUD8N9vrmd yyLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mk8J9R2L; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id m10sor3362709pje.25.2019.06.28.11.24.22 for (Google Transport Security); Fri, 28 Jun 2019 11:24:22 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mk8J9R2L; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ih7U4hpwGmfoDyYEDt6ssld4EzhtjygGMzYklaGP3Wc=; b=mk8J9R2LyueC0i6f8ZRSA4DJA28jyZ55n95SHVFP+uj39/BO2/IP0UxjTWqCeq+eym C9Cw336mhXrmmHCrfxSmauKAhudkV8ioUSHg4cI7lRcrIbrEvlov9A8WtIgE1hoMLyse 1wJpZ57harz3Dfq81xg6bEm2chVzpT3sTF+rfxzjdoSOEZYIjxESghqgqV9Qvh2p9ZGg NN+KFLHYLoz9RCCQAayXKK5w6VZvIaRekatiZLtaetKv+W68+BQbUd+ugJqQewUhcykj 3at2yTQZPpWIatsQRPnl1GYEBbQH5ijtulJnlZqqxO/Yx0QsW6657rOMwAsQRVRHNIgb fMvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ih7U4hpwGmfoDyYEDt6ssld4EzhtjygGMzYklaGP3Wc=; b=DRyTvrHkoGp3ljp+ZbozUBBIQ5m+iBJYli27dIWawVgfqoz7v3RxmN7Rkvvh8sozow M0RhVosdpiQHWsjwwGXmK4jqqowbI+YtX9rmuQEmoatPvFDy/vzP31YkBH4/hlFvIC1C Rp91A+330lWVy9AySqck1pDbp+w/BHZ/rWpKW5BjlPuCuwMdQFw+WZ0TEqrOF9/OkMPp 3pv2mnzQj+dTz+hJcgs7m6Uc50sqvWdA5/jrABJnTxQpKKLhxnCiRoOFo9IsFxzKWhCn PIF0cTO+3HiOhy4wTct0IrcYabaIMik2Jopxk+EZOLx+rRjL+9+m4j3/BjsK5kuaB/sZ Hzrw== X-Gm-Message-State: APjAAAWdp/Sj48i/ebZqIEj9qyUHRkzEdT+/dFHYFjio4W87ov3FYj/6 JFCrX70a2V1G68fxjsmgOi+8utBo X-Google-Smtp-Source: APXvYqwNCvTT67rkuVqcy61BjZbsAe5ofBN1aWGbeqvKWE2t4Pbv7bPlmW0h2lAhCJbdl9UBETECtA== X-Received: by 2002:a17:90a:a116:: with SMTP id s22mr14679396pjp.47.1561746262349; Fri, 28 Jun 2019 11:24:22 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id s15sm2916223pfd.183.2019.06.28.11.24.20 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 28 Jun 2019 11:24:21 -0700 (PDT) From: John Stultz To: stable@vger.kernel.org Cc: Felipe Balbi , Fei Yang , Sam Protsenko , Felipe Balbi , linux-usb@vger.kernel.org, John Stultz Subject: [PATCH 4.19.y v2 3/9] usb: dwc3: gadget: track number of TRBs per request Date: Fri, 28 Jun 2019 18:24:07 +0000 Message-Id: <20190628182413.33225-4-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190628182413.33225-1-john.stultz@linaro.org> References: <20190628182413.33225-1-john.stultz@linaro.org> From: Felipe Balbi commit 09fe1f8d7e2f461275b1cdd832f2cfa5e9be346d upstream This will help us remove the wait_event() from our ->dequeue(). Cc: Fei Yang Cc: Sam Protsenko Cc: Felipe Balbi Cc: linux-usb@vger.kernel.org Cc: stable@vger.kernel.org # 4.19.y Signed-off-by: Felipe Balbi (cherry picked from commit 09fe1f8d7e2f461275b1cdd832f2cfa5e9be346d) Signed-off-by: John Stultz --- drivers/usb/dwc3/core.h | 3 +++ drivers/usb/dwc3/gadget.c | 6 ++++++ 2 files changed, 9 insertions(+) -- 2.17.1 diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 4872cba8699b..0de78cb29f2c 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -847,6 +847,7 @@ struct dwc3_hwparams { * @epnum: endpoint number to which this request refers * @trb: pointer to struct dwc3_trb * @trb_dma: DMA address of @trb + * @num_trbs: number of TRBs used by this request * @needs_extra_trb: true when request needs one extra TRB (either due to ZLP * or unaligned OUT) * @direction: IN or OUT direction flag @@ -867,6 +868,8 @@ struct dwc3_request { struct dwc3_trb *trb; dma_addr_t trb_dma; + unsigned num_trbs; + unsigned needs_extra_trb:1; unsigned direction:1; unsigned mapped:1; diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 8db7466e4f76..fd91c494307c 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1041,6 +1041,8 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep, req->trb_dma = dwc3_trb_dma_offset(dep, trb); } + req->num_trbs++; + __dwc3_prepare_one_trb(dep, trb, dma, length, chain, node, stream_id, short_not_ok, no_interrupt); } @@ -1075,6 +1077,7 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, /* Now prepare one extra TRB to align transfer size */ trb = &dep->trb_pool[dep->trb_enqueue]; + req->num_trbs++; __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr, maxp - rem, false, 1, req->request.stream_id, @@ -1119,6 +1122,7 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, /* Now prepare one extra TRB to align transfer size */ trb = &dep->trb_pool[dep->trb_enqueue]; + req->num_trbs++; __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr, maxp - rem, false, 1, req->request.stream_id, req->request.short_not_ok, @@ -1135,6 +1139,7 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, /* Now prepare one extra TRB to handle ZLP */ trb = &dep->trb_pool[dep->trb_enqueue]; + req->num_trbs++; __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr, 0, false, 1, req->request.stream_id, req->request.short_not_ok, @@ -2231,6 +2236,7 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct dwc3_ep *dep, dwc3_ep_inc_deq(dep); trace_dwc3_complete_trb(dep, trb); + req->num_trbs--; /* * If we're in the middle of series of chained TRBs and we From patchwork Fri Jun 28 18:24:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 168124 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4020662ilk; Fri, 28 Jun 2019 11:24:24 -0700 (PDT) X-Received: by 2002:a65:55ca:: with SMTP id k10mr10735117pgs.14.1561746264744; Fri, 28 Jun 2019 11:24:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561746264; cv=none; d=google.com; s=arc-20160816; b=ng2sfo2jB/NoeXX6REXTTJdwUoWPCfsSAPG81N49lYUP50NtVksbQ8qnHzL6wKy+Ql UpmnTwC/aRYPT553DoPMTXGeEWXwUB7LxaHE9nLoq+I+4BEbxMAF2WuNZUwFThqCB0qN Vg1Y3Y5KTtCZiOBheEme7EgR0BWcOchkeb/miHN/oRJFwpwUiu2VdzgDQ1CyB8G/DqCM 3KegU0TA9HyACyGAV5Sul9mCsAlFG7/8Y5M0fuE/hWFirCD0KmbwXWnowMEU+aUxm4Kp 9bYZNQDsZHx6Rg/JxY0rzn5oITOBUBuOw88udDy5bfbUfuy3DmtiWjT3mzP5CIpyKUeh XbrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IT1pd6Y/Qs6l6wqmDTMXa67ucrhPLOrxpJINsob31Ek=; b=aR9UInjRlYUoq3ug2w9j3cFMCdIHRxenVM1tFGJJGGqTjjnO5r6f0r/qfs736Gycb5 toHTFvk9r7NU+/eX3ZgpPo91Xfo2Msa3D3mWw8nMjzhySfEELtgnqy7ZxZijNRX0QO3M YrKELOqXW7nbHA5Twov+tXwUgVEXV+QP3xFrSAP24fEWRDUkqPXr6UxcLCwRwtbqqG3J qmo+rTAT2LFjUnZz+IGmNOXkQW/a3REfOL0oa6NIMpmPsXUgpuG4z7pUsjaidjtCCaFN W1+YWDdoYxu1T2lwSNHtTh5KQty77YgyJvqGHtMxI/IKW7Bq61QZ7z62vhxG66yGMHGE /tlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JDN8QZz7; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id t69sor3416879pjb.5.2019.06.28.11.24.24 for (Google Transport Security); Fri, 28 Jun 2019 11:24:24 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JDN8QZz7; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IT1pd6Y/Qs6l6wqmDTMXa67ucrhPLOrxpJINsob31Ek=; b=JDN8QZz7n8TFHv42pQ/ba4vuwtpFNDbmqW5mj5+fH8kag6pOfRfLtILhFQm8UvflA+ ijuYHFrvdKOYi/J9cU+GDlPTfCweQOfAGu4SrdcBc5n+dZDf+46EfqBAcEcxrZYtebOr ZSULmjefsey6rzKLDhrEltCdQRXDvp0k+eBClIS2TmSwCqFfCZeaILMaW7+P0dQyaMHG Iaff/YJBxaVjGtacLoyimeulIWl074RkPcdAEUkowwN95AD1c3XTNo+X/R/L/n8FjabZ FKGqbyu3mgi2fwlKFHSl9VCRFwIWqDUTueSUaW4fDiGUlqk/Yywo78rkA10UJd2sVnIY 1qWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IT1pd6Y/Qs6l6wqmDTMXa67ucrhPLOrxpJINsob31Ek=; b=WChNqZ0Vvqq/owjm+TJ3grPrSGPbWRckjG4ykZ19HojTW4rJCslm8jqo0qwa8qOdQw a+g486ZVlIlKma3/X/RH6jXgcRe9WcXVK2uGLov37s6Qag6zQVjbf9PM4jFwbPSMtGiR jINhdu3WgxEKsVxk8FwN+p8HC5LdlX+X4ONrGt73pbXikbOUZRLz/fwTCxYhouC4Ox5Q 4RK7eeIuQbg4L2AYMu7Oveb7I4y8wv6lJ1CZYksuh00UptttTnq8s8fCQ4Gyi3ZeFD+4 hDK46jUWyWWKm1/MvC9SdZNHRgElMcAwhCdQqpPffhPTTOmZ4mDo7VGyZrv9/2L+Pyc6 fCaA== X-Gm-Message-State: APjAAAU8+qpuai/Y9iuyJzIG9uFVU48hXlFJwzGBIkx3r4clE7hUdmiH 4mfCcc1ALfqSW/bfX9i717crxZ/K X-Google-Smtp-Source: APXvYqzeLd2WfKVOEvFZElOrK1KYgAkV0GbyMlNufBzlTwl/hEkuywHYikMsTe1rxYvjEBuYisYOJA== X-Received: by 2002:a17:90a:9503:: with SMTP id t3mr5159952pjo.47.1561746264299; Fri, 28 Jun 2019 11:24:24 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id s15sm2916223pfd.183.2019.06.28.11.24.22 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 28 Jun 2019 11:24:23 -0700 (PDT) From: John Stultz To: stable@vger.kernel.org Cc: Felipe Balbi , Fei Yang , Sam Protsenko , Felipe Balbi , linux-usb@vger.kernel.org, John Stultz Subject: [PATCH 4.19.y v2 4/9] usb: dwc3: gadget: use num_trbs when skipping TRBs on ->dequeue() Date: Fri, 28 Jun 2019 18:24:08 +0000 Message-Id: <20190628182413.33225-5-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190628182413.33225-1-john.stultz@linaro.org> References: <20190628182413.33225-1-john.stultz@linaro.org> From: Felipe Balbi commit c3acd59014148470dc58519870fbc779785b4bf7 upstream Now that we track how many TRBs a request uses, it's easier to skip over them in case of a call to usb_ep_dequeue(). Let's do so and simplify the code a bit. Cc: Fei Yang Cc: Sam Protsenko Cc: Felipe Balbi Cc: linux-usb@vger.kernel.org Cc: stable@vger.kernel.org # 4.19.y Signed-off-by: Felipe Balbi (cherry picked from commit c3acd59014148470dc58519870fbc779785b4bf7) Signed-off-by: John Stultz --- drivers/usb/dwc3/gadget.c | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) -- 2.17.1 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index fd91c494307c..4e08904890ed 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1368,6 +1368,8 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, break; } if (r == req) { + int i; + /* wait until it is processed */ dwc3_stop_active_transfer(dep, true); @@ -1405,32 +1407,12 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, if (!r->trb) goto out0; - if (r->num_pending_sgs) { + for (i = 0; i < r->num_trbs; i++) { struct dwc3_trb *trb; - int i = 0; - - for (i = 0; i < r->num_pending_sgs; i++) { - trb = r->trb + i; - trb->ctrl &= ~DWC3_TRB_CTRL_HWO; - dwc3_ep_inc_deq(dep); - } - - if (r->needs_extra_trb) { - trb = r->trb + r->num_pending_sgs + 1; - trb->ctrl &= ~DWC3_TRB_CTRL_HWO; - dwc3_ep_inc_deq(dep); - } - } else { - struct dwc3_trb *trb = r->trb; + trb = r->trb + i; trb->ctrl &= ~DWC3_TRB_CTRL_HWO; dwc3_ep_inc_deq(dep); - - if (r->needs_extra_trb) { - trb = r->trb + 1; - trb->ctrl &= ~DWC3_TRB_CTRL_HWO; - dwc3_ep_inc_deq(dep); - } } goto out1; } @@ -1441,8 +1423,6 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, } out1: - /* giveback the request */ - dwc3_gadget_giveback(dep, req, -ECONNRESET); out0: From patchwork Fri Jun 28 18:24:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 168125 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4020686ilk; Fri, 28 Jun 2019 11:24:26 -0700 (PDT) X-Received: by 2002:a17:902:b608:: with SMTP id b8mr13390113pls.303.1561746266295; Fri, 28 Jun 2019 11:24:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561746266; cv=none; d=google.com; s=arc-20160816; b=dIsJeUCyHVE/BgDcZxJL2UPU5uDdl/5OGSbCC0LgW2kL0CArHOoButRsV9XVOp4pdK xXUtyEm0znSveAnPR0U4Q1GYvMuT+zBugFY7egHglsjtm0nVljVGeq2QYeqfVBdS4VnW 1fUeqPMPNpP/pu7Ke6IfbjRCiVHBK5HrXH426oSgnIKDDK/RSZNWlcw1yfp5bjcpeNmo jm7qT0xaMOozHf060zv20qUjzTVrCtk4JyxzU1Sgg0co2l9q0e0Yz0xykzS2rjj9z1Fn 22/hLJqlScUf+yCSMAbg4awtfnglR/a/VpklaPr3F9YaCH8IwbpjVuFCFV7Z/Cs99UHe 8fkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lT3fxv5LATFR+LwgNYhFFmzfdH8/UFjXtWib2WTIrbM=; b=oVLNZTaHDQsN8hcWW+MxEolR1AJTfAPR1gWAoQkXne7yEJQFVuvxqKFxnTeh36Gc5k yiQbCGU/x8dMoOfiPw50Mw5L4udxT8oBWJNiSZa6/WKG1sEQiExDKBNXLvZOBFrBVfwB Rm0Sl7aGHpNnuG9JyqID/7S7Igbvd148enEgEjPEZ294snacOrNDFT4XINYTv04Mq+fn 7+Enmk95xZTMM9w2I6ZjRoyttfH92yRtk+KnUl7hiOuzFBxYrBAY4jzshWDHn3knDVHy 4p5fnRZe+kIJ4nvvTvGr45Y0QhZF8ptmcH79HfTX0CkGC6FZdO0BPr3N4gpEkV9DUUSh JmRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NSJevXZY; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id z2sor3447198pjn.1.2019.06.28.11.24.26 for (Google Transport Security); Fri, 28 Jun 2019 11:24:26 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NSJevXZY; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lT3fxv5LATFR+LwgNYhFFmzfdH8/UFjXtWib2WTIrbM=; b=NSJevXZYgKbgf3gTOSY6ABPd6HIDrATAwaVAkJtHmyEV+e1XC44yrZTYnWrwylUFk6 vjzp/7EFBH8eQF7ClX1CCZG5sZq3ssBVu2XmAqafeeVifGN7hJ105CaRnuTf2P2tvw8H xeBaE0EnK0n1OZYWH6JB3NNg0V5tw2/cNNt3ry5kEo80Gdh7xA7bKCQn52WITt0KIN7J J6qXD1je1YFbfeATZU5suXDkrPwsOud2ZQFmluHjfzS3PjT36LETox1fcI2adhcUg6S7 2iFyUdgUwEKMoM4+lypKEa/fynWRv3vRD2Cqk8leOXknbx92ap/uFbIHwtNe/STBBBDi yRow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=lT3fxv5LATFR+LwgNYhFFmzfdH8/UFjXtWib2WTIrbM=; b=ZN062XSfMuYYUkQfIQyeDA09XEGGoyIe6YqME2taoU2o3PkXNmb0nAUGlHRSDUU/g9 AObgD3GZWGdPTH2r198gZnLDG8u61x2NPSbrRRxScDXCehXV6EwzwohkWPdS2/30daUQ coOqUtA5y3zuo0IiK/TL5a66QK0qw9oyGHt/4KHD3q7QRwBC6kL/56rsdMaO4UQG3WUt 7pslnc+HR2N8N5H9tlEjN85Q4pvG+IOdqFmWhgZSpIMGoevh/wamua4BLmV7QrZn83LH AgmmVAEZzviUI/e6/mdkIJq9vNOTs9HCXHD00PHPusQPRhJ72c3JYActWOurRVcjaGcV PfDg== X-Gm-Message-State: APjAAAVTD2qCVxpRQ3dyXTgGmzPjrE3J9jIW1rNufyFDsqxeGVlZE/l1 4SDTyujJzJd70Wa2/Tw3K2so/TP2 X-Google-Smtp-Source: APXvYqxFBgbJKazoH14+J2IhpQeuPNTxNOQwuSXCkvYIBIZNSudfMZQPcQIomrsNlyGq7MiTx2OEYQ== X-Received: by 2002:a17:90a:ad86:: with SMTP id s6mr14952881pjq.42.1561746265909; Fri, 28 Jun 2019 11:24:25 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id s15sm2916223pfd.183.2019.06.28.11.24.24 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 28 Jun 2019 11:24:25 -0700 (PDT) From: John Stultz To: stable@vger.kernel.org Cc: Felipe Balbi , Fei Yang , Sam Protsenko , Felipe Balbi , linux-usb@vger.kernel.org, John Stultz Subject: [PATCH 4.19.y v2 5/9] usb: dwc3: gadget: extract dwc3_gadget_ep_skip_trbs() Date: Fri, 28 Jun 2019 18:24:09 +0000 Message-Id: <20190628182413.33225-6-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190628182413.33225-1-john.stultz@linaro.org> References: <20190628182413.33225-1-john.stultz@linaro.org> From: Felipe Balbi commit 7746a8dfb3f9c91b3a0b63a1d5c2664410e6498d upstream Extract the logic for skipping over TRBs to its own function. This makes the code slightly more readable and makes it easier to move this call to its final resting place as a following patch. Cc: Fei Yang Cc: Sam Protsenko Cc: Felipe Balbi Cc: linux-usb@vger.kernel.org Cc: stable@vger.kernel.org # 4.19.y Signed-off-by: Felipe Balbi (cherry picked from commit 7746a8dfb3f9c91b3a0b63a1d5c2664410e6498d) Signed-off-by: John Stultz --- drivers/usb/dwc3/gadget.c | 61 +++++++++++++++------------------------ 1 file changed, 24 insertions(+), 37 deletions(-) -- 2.17.1 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 4e08904890ed..46aa20b376cd 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1341,6 +1341,29 @@ static int dwc3_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request, return ret; } +static void dwc3_gadget_ep_skip_trbs(struct dwc3_ep *dep, struct dwc3_request *req) +{ + int i; + + /* + * If request was already started, this means we had to + * stop the transfer. With that we also need to ignore + * all TRBs used by the request, however TRBs can only + * be modified after completion of END_TRANSFER + * command. So what we do here is that we wait for + * END_TRANSFER completion and only after that, we jump + * over TRBs by clearing HWO and incrementing dequeue + * pointer. + */ + for (i = 0; i < req->num_trbs; i++) { + struct dwc3_trb *trb; + + trb = req->trb + i; + trb->ctrl &= ~DWC3_TRB_CTRL_HWO; + dwc3_ep_inc_deq(dep); + } +} + static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, struct usb_request *request) { @@ -1368,38 +1391,8 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, break; } if (r == req) { - int i; - /* wait until it is processed */ dwc3_stop_active_transfer(dep, true); - - /* - * If request was already started, this means we had to - * stop the transfer. With that we also need to ignore - * all TRBs used by the request, however TRBs can only - * be modified after completion of END_TRANSFER - * command. So what we do here is that we wait for - * END_TRANSFER completion and only after that, we jump - * over TRBs by clearing HWO and incrementing dequeue - * pointer. - * - * Note that we have 2 possible types of transfers here: - * - * i) Linear buffer request - * ii) SG-list based request - * - * SG-list based requests will have r->num_pending_sgs - * set to a valid number (> 0). Linear requests, - * normally use a single TRB. - * - * For each of these two cases, if r->unaligned flag is - * set, one extra TRB has been used to align transfer - * size to wMaxPacketSize. - * - * All of these cases need to be taken into - * consideration so we don't mess up our TRB ring - * pointers. - */ wait_event_lock_irq(dep->wait_end_transfer, !(dep->flags & DWC3_EP_END_TRANSFER_PENDING), dwc->lock); @@ -1407,13 +1400,7 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, if (!r->trb) goto out0; - for (i = 0; i < r->num_trbs; i++) { - struct dwc3_trb *trb; - - trb = r->trb + i; - trb->ctrl &= ~DWC3_TRB_CTRL_HWO; - dwc3_ep_inc_deq(dep); - } + dwc3_gadget_ep_skip_trbs(dep, r); goto out1; } dev_err(dwc->dev, "request %pK was not queued to %s\n", From patchwork Fri Jun 28 18:24:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 168126 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4020723ilk; Fri, 28 Jun 2019 11:24:28 -0700 (PDT) X-Received: by 2002:a65:4945:: with SMTP id q5mr10797259pgs.9.1561746268140; Fri, 28 Jun 2019 11:24:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561746268; cv=none; d=google.com; s=arc-20160816; b=oAY8NinZyU70b3yHBIPU1JuQPJ5HRpkKOmOsiirgVxCXiqs1n5OJPMx+QLX6EKnnDG b+iUXDkVAUxlNZ5mU2vYIQxHmjr7Yy4F7nVh5pwmNTjaJ2YndrfX9N4bHeDwwk7kptj4 H2KJqfWVwSqi38Eu068F+QKvMMSxTWE3ZXt3zs4+0JAZtXxersuPfprNYesufioY+1bZ IG91iZ2JL/SAZa/mR/ZHyhyGhlPEo5nhM9mJhVlnr6qAuxC8uNCAqraOgP4JiM59vsvP rCS07/+kKm1na0Q+SrBpbhPTaY2kBbAx5OpHm+Eq+db5u7LjJ0+Ux6IWg9MLy5iXavmr n/+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DDZGKZ3w7wUwrEm8FX1ASPwXOimJmyPEnuezYoXx+I8=; b=qGjfyfLdsiakzNbJiUBfkKFQUN6wPMLkhQnw1qkfMdIo8XgPB1OdxqU8om8rmlzG/T tnlcmn6lBEhtygtrgpP39o/lwsg2V4/5+gIsEBaw3ZX4MwxjsEatEwZSpxYD3H6ybjb4 OnWcGecl9LCJvrs3FKciaZxoX2oQo7YbwTni0fGJ/Ufq1nhjC57PFye4G6/HOjyESb3t Bify+B6eTSHXMO31qvVrEEMH4ThIGEqJ4Q1AbwbEHrEl0pe150CqRqfeGfC5c1RVj7xc 9gCAMYB/dh3fClO1ltaUbp8WFRAxHSQOvBOr0PwmzSTZ1Xu6wjslXa5yOcg+KmImUtel BIMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CFr4YuFA; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id v75sor3423924pjb.26.2019.06.28.11.24.28 for (Google Transport Security); Fri, 28 Jun 2019 11:24:28 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CFr4YuFA; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DDZGKZ3w7wUwrEm8FX1ASPwXOimJmyPEnuezYoXx+I8=; b=CFr4YuFAJ4CxD6EpGmjrwbV8ZIDMplHe16uLlYTmXLMT/n8sVa1kkkDZspxOIo7N4Y iwHYu38lElMkN+RfwzTsUxMoed7bGFFRCOZGWXlCB22crZeKZ+8FrV9hwzyiI9vZTLlI rzzeHEMdgj3VQckfWLa+a88HPnC5E1Suwv7H0SKFUfLxw7hyUO97PHn2tyCcGUrK8Q0u d6erI+z85f3CcHZQyLYs6YsF459KLnDFEP7hTdtKgvJY9j1tsTd7H2VXnDkM3OAd9Vag ht6sy4mXJpGFRKIZ3tT9/SL+r9gEmXwS7lu8bPw2ue7+O6uSPxX9PGa5ttRXn6kQbX4e qSIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DDZGKZ3w7wUwrEm8FX1ASPwXOimJmyPEnuezYoXx+I8=; b=QFM38SN3HmfAITivCt4Kpvgtz80BjFkQwooGNGadXQ7jPJMPtwml8WngSoqlMwfaiM POq9jYBfS6y6E73KVqHlVJ5BKnnbpopYhkAtuoqsdggFUNS546gkTLUHpIVn3JqKpKVM 6j8LkkgRs5eh+7h+Q/Tc98ThyrrKEuUYK/ZL0GH3PokGv4EnbfYGMuJ199hLrTpUEGvb TFyjXhNQNkDgnWYHBTlgUhdRzOimOnqrzaPEMbhkZpMl/6whF0e1Yjdwjw2jvP77ws40 W0InMD5ZrrDDsWZJ8IiiS0zgq1PU0MLnOjRuzgMnkTXDtnS2W3A0NmfSG/H3WLOMmO5R +E5w== X-Gm-Message-State: APjAAAV2TcTS52Xb74ISDFxK/krCBguSxDu9Md2HB7Od1Sso5NmtrDj4 UE+S/zvMCjl6rjmZ8u883t8Cv8wH X-Google-Smtp-Source: APXvYqx3g7h5vvxkXrT1Ioc3tfWK+hwMhoc+6Gew5Hk0v0/fv3t0WaflZUIIz+aQTaGKOOsB4v7dRQ== X-Received: by 2002:a17:90a:a489:: with SMTP id z9mr4530868pjp.24.1561746267725; Fri, 28 Jun 2019 11:24:27 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id s15sm2916223pfd.183.2019.06.28.11.24.25 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 28 Jun 2019 11:24:26 -0700 (PDT) From: John Stultz To: stable@vger.kernel.org Cc: Felipe Balbi , Fei Yang , Sam Protsenko , Felipe Balbi , linux-usb@vger.kernel.org, John Stultz Subject: [PATCH 4.19.y v2 6/9] usb: dwc3: gadget: introduce cancelled_list Date: Fri, 28 Jun 2019 18:24:10 +0000 Message-Id: <20190628182413.33225-7-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190628182413.33225-1-john.stultz@linaro.org> References: <20190628182413.33225-1-john.stultz@linaro.org> From: Felipe Balbi commit d5443bbf5fc8f8389cce146b1fc2987cdd229d12 upstream This list will host cancelled requests who still have TRBs being processed. Cc: Fei Yang Cc: Sam Protsenko Cc: Felipe Balbi Cc: linux-usb@vger.kernel.org Cc: stable@vger.kernel.org # 4.19.y Signed-off-by: Felipe Balbi (cherry picked from commit d5443bbf5fc8f8389cce146b1fc2987cdd229d12) Signed-off-by: John Stultz --- drivers/usb/dwc3/core.h | 2 ++ drivers/usb/dwc3/gadget.c | 1 + drivers/usb/dwc3/gadget.h | 15 +++++++++++++++ 3 files changed, 18 insertions(+) -- 2.17.1 diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 0de78cb29f2c..24f0b108b7f6 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -636,6 +636,7 @@ struct dwc3_event_buffer { /** * struct dwc3_ep - device side endpoint representation * @endpoint: usb endpoint + * @cancelled_list: list of cancelled requests for this endpoint * @pending_list: list of pending requests for this endpoint * @started_list: list of started requests on this endpoint * @wait_end_transfer: wait_queue_head_t for waiting on End Transfer complete @@ -659,6 +660,7 @@ struct dwc3_event_buffer { */ struct dwc3_ep { struct usb_ep endpoint; + struct list_head cancelled_list; struct list_head pending_list; struct list_head started_list; diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 46aa20b376cd..c2169bc626c8 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2144,6 +2144,7 @@ static int dwc3_gadget_init_endpoint(struct dwc3 *dwc, u8 epnum) INIT_LIST_HEAD(&dep->pending_list); INIT_LIST_HEAD(&dep->started_list); + INIT_LIST_HEAD(&dep->cancelled_list); return 0; } diff --git a/drivers/usb/dwc3/gadget.h b/drivers/usb/dwc3/gadget.h index 2aacd1afd9ff..023a473648eb 100644 --- a/drivers/usb/dwc3/gadget.h +++ b/drivers/usb/dwc3/gadget.h @@ -79,6 +79,21 @@ static inline void dwc3_gadget_move_started_request(struct dwc3_request *req) list_move_tail(&req->list, &dep->started_list); } +/** + * dwc3_gadget_move_cancelled_request - move @req to the cancelled_list + * @req: the request to be moved + * + * Caller should take care of locking. This function will move @req from its + * current list to the endpoint's cancelled_list. + */ +static inline void dwc3_gadget_move_cancelled_request(struct dwc3_request *req) +{ + struct dwc3_ep *dep = req->dep; + + req->started = false; + list_move_tail(&req->list, &dep->cancelled_list); +} + void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req, int status); From patchwork Fri Jun 28 18:24:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 168127 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4020751ilk; Fri, 28 Jun 2019 11:24:29 -0700 (PDT) X-Received: by 2002:a17:902:a409:: with SMTP id p9mr13373241plq.218.1561746269764; Fri, 28 Jun 2019 11:24:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561746269; cv=none; d=google.com; s=arc-20160816; b=bwoViG8Z4kkna4YYqEbrIgt2t8cCAU0BuIghiZ7iCH42Z9/TvyVJubTa/aNwHwKvDk HoJ0U0bKI/EWvaflDapST4XKXHqFme8k15KEqxAR0Og1HNNFglGelqS4/oPYMuwNernM hUYKmNkl3LUIsjX1eHgCShbCHV9MzGGZwwHuFbTQEU7V93ID25sjY5HqQiu+NNujFRoY jU2JxzDHp1b0zS0XSzIuN0l2aIaLRlYprdRoZ/Va1UQIoWW+Nq1a3T40TgOoHt6iKIxs B48ngVOcwG2NSqbxkNZI4AB+r5FW7SmoX2+qdHZtFvWe49s5wFYUbLmC3WpsvdbHeet1 cZoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dZYduMfUWZ9SXxQiDlz5Ott25WscyPClGVJovh/j864=; b=Tnymy1AzDQGwur9fufRhUXhXiABpez0dXj9q2WjE7djdjO9OEo70X6DIAJn7FC7yff PTbwKxTAqo59qjWAXON+IS3Ju3CXK9wflCPFzdf7Dv2MLr/2LYmN4WzRnbLqjsYMBZj4 XVG0Cb6eyfPNmeL68jvxGMREcsqf1EJpGA/0QcXG9+1avABfRy/+6Ptwvqqv0xxTetfb 5XmXOuDfiAd7nxjDhZoqmM+SiHA0+6azJLwvjUr7DvRXKkNRiWN3H7E794GpSOzBxTzJ h65vKCqZ9aDlddQj7GMNACZAiqWGHtpoYRCiMTsxGomQQJDGcwoh8R6MMDMfiUaYFnxV eOcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dcz6yeTS; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id e1sor1514108pff.23.2019.06.28.11.24.29 for (Google Transport Security); Fri, 28 Jun 2019 11:24:29 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dcz6yeTS; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dZYduMfUWZ9SXxQiDlz5Ott25WscyPClGVJovh/j864=; b=dcz6yeTS+k9GW7rabIn/2jY7ktaZSb0v0RMSqU/Vl5fRVl6SddKmc9Gs/PSNl3Ag3P GsdxcSY97gFY4U8+ipD0Hrdy9dIx3IZw5IeVPPujWUdv+A8BAKm+QGpxPJ4e4fGx/dSE R07ouFUy2VcVkbM7pkQ3U3zjXglParYEw9SXblesMALpid29Wq+XlhgJqkJ4gxvziwuO BkZs33KdHh8dj00S4qmdFqSpxX/cYWvdL5nHutJwLSBNr73FCjPZDXyLlFcNweKy9Ko1 f+1WQIIVCJuDZrQ6SzkKhvWqOPt//OvyHOH4zzF6QU+yh0rJVQvLznywfHoDy+emC4Vo RsJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dZYduMfUWZ9SXxQiDlz5Ott25WscyPClGVJovh/j864=; b=aZXjYs9vzFMyjPLFec6QGjPtQMr3uFk5azJGsX0Uh53rE3sCCjrKVg6LSWOc0bQYdB PWECvwRPXbjXjV8JG2pQJQX2OgHcrUmKTXzVjNCz0bETsmIzWHnnVG3NfQRp3xd2rroP COSCrVVJ527RsPxe41JN2pMID7I+y7StDmUZKmPA9ep3RLL4RQA/ud7qP8HPRSnbhXtk xQq+eo2Ikxm7PZUDC05Nk4oofPjaa+EVQpCPZnfMNdeQY1X4iaOcuxRAMEcVaOavAC8J Cj8GJD8cXJrGCOY3M4fknzLDe74dEOAPj1nwgiKBqTFy60sRAx+Ii6u7YiDuB3bXB7UT Eicg== X-Gm-Message-State: APjAAAWXFpEG+MRexEeA+CWyOUmWOYAm4womc1WWBH8dJ+tCJh+KiSzC 2fiXHqk2ngQjCx7Em8femsS/3dH7 X-Google-Smtp-Source: APXvYqxwHT+rEAoznXp4RnOp+y/5ybIX1wyiM6yFmGmuvOOiuwojDxDrPEZMBAe5MJovxEHAv771qQ== X-Received: by 2002:a63:d4c:: with SMTP id 12mr10869247pgn.30.1561746269237; Fri, 28 Jun 2019 11:24:29 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id s15sm2916223pfd.183.2019.06.28.11.24.27 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 28 Jun 2019 11:24:28 -0700 (PDT) From: John Stultz To: stable@vger.kernel.org Cc: Felipe Balbi , Fei Yang , Sam Protsenko , Felipe Balbi , linux-usb@vger.kernel.org, John Stultz Subject: [PATCH 4.19.y v2 7/9] usb: dwc3: gadget: move requests to cancelled_list Date: Fri, 28 Jun 2019 18:24:11 +0000 Message-Id: <20190628182413.33225-8-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190628182413.33225-1-john.stultz@linaro.org> References: <20190628182413.33225-1-john.stultz@linaro.org> From: Felipe Balbi commit d4f1afe5e896c18ae01099a85dab5e1a198bd2a8 upstream Whenever we have a request in flight, we can move it to the cancelled list and later simply iterate over that list and skip over any TRBs we find. Cc: Fei Yang Cc: Sam Protsenko Cc: Felipe Balbi Cc: linux-usb@vger.kernel.org Cc: stable@vger.kernel.org # 4.19.y Signed-off-by: Felipe Balbi (cherry picked from commit d4f1afe5e896c18ae01099a85dab5e1a198bd2a8) Signed-off-by: John Stultz --- drivers/usb/dwc3/gadget.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index c2169bc626c8..8291fa1624e1 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1364,6 +1364,17 @@ static void dwc3_gadget_ep_skip_trbs(struct dwc3_ep *dep, struct dwc3_request *r } } +static void dwc3_gadget_ep_cleanup_cancelled_requests(struct dwc3_ep *dep) +{ + struct dwc3_request *req; + struct dwc3_request *tmp; + + list_for_each_entry_safe(req, tmp, &dep->cancelled_list, list) { + dwc3_gadget_ep_skip_trbs(dep, req); + dwc3_gadget_giveback(dep, req, -ECONNRESET); + } +} + static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, struct usb_request *request) { @@ -1400,8 +1411,9 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, if (!r->trb) goto out0; - dwc3_gadget_ep_skip_trbs(dep, r); - goto out1; + dwc3_gadget_move_cancelled_request(req); + dwc3_gadget_ep_cleanup_cancelled_requests(dep); + goto out0; } dev_err(dwc->dev, "request %pK was not queued to %s\n", request, ep->name); @@ -1409,7 +1421,6 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, goto out0; } -out1: dwc3_gadget_giveback(dep, req, -ECONNRESET); out0: From patchwork Fri Jun 28 18:24:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 168129 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4020835ilk; Fri, 28 Jun 2019 11:24:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqwYdm3RJtrYkY+MA+3KtCpoR2C4FCBcLE1/wR1RWxJ1Dh/i9EaAq8sj6sSSKh4Dq+jmaIb+ X-Received: by 2002:a65:6204:: with SMTP id d4mr10536547pgv.104.1561746273567; Fri, 28 Jun 2019 11:24:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561746273; cv=none; d=google.com; s=arc-20160816; b=sgz/Jh/CnaS4F3cjY3TDVhGnEnbic0QUb7Du8i9sfJ3/UTUaa+g9TOX7Wg9hq2/aEv L0BhpBAsdwTDAx+9bBxUyVIg9E9JHtxL5AXtwXT32thpZHMMMXLaLfHa0OzJWDj8Cm0S 2m7nz/VypjnuO9/Ls5l26qOp1MgHPpNVPSOSfirppqcWD63OlunYBjL9FHQgJSSL8uuo zOHXzxn28DZcjhbnoNLAw5X6jrHgEu4qkegRPrS0tWdgNWJTprjbhpbpg6A14if8DmnJ FQBVClHpOeorxOtFP4GIbTPTFVrD+AyqLxiBmnwPeFi8AYZNWibrP6uksNYSrwcxu1PA WyEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=QyWp4X95ZOlj3HRqIqq5Np/f7SP+VBBbMvRFL8CO2Wg=; b=Houq+Suxoww5EnqJg8JS14KHTbf65R8MWQaM/7oCWxqufRHPQBX9COhj2xBSr50WpT QxfkkXRvhUJJum92OVXDQJusNRtJz3lZwl7YSm2wfTxBqpYAsdObYKkYmO6Ts0yQHktm K1BQzG/+w0rnmzp1Nb7VCWvijlDyuxdEHWWG9g9CjQDmIi21yAlyQMKO7xQEoH0UF8N9 V5Q1krUeFQXeUH1Mm0ZMoS81nBSOXow/M1WcPyQ/VDTcwdi1L0MsZI26C8GJOJQkDZNR jqD8q607L0I24I+s82zmhAwx8rFzapkBKqh+8anPGbfNqYYzczxyxxZ7NNKSOkvsKroK z06g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XIPcfHO4; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 d4si2761259pla.358.2019.06.28.11.24.33; Fri, 28 Jun 2019 11:24:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=XIPcfHO4; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 S1726780AbfF1SYc (ORCPT + 14 others); Fri, 28 Jun 2019 14:24:32 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:36185 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726770AbfF1SYc (ORCPT ); Fri, 28 Jun 2019 14:24:32 -0400 Received: by mail-pg1-f196.google.com with SMTP id c13so2950928pgg.3 for ; Fri, 28 Jun 2019 11:24:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QyWp4X95ZOlj3HRqIqq5Np/f7SP+VBBbMvRFL8CO2Wg=; b=XIPcfHO4VsSPLqfzuX9EknWyUzKfZeNAGlgIl5DvpfyFARsmMtjqfOY9qznNxUVvDi caVVSaQpoCa65JBY0X3Qb5xTxNujl3yXqzpywqRXH0uQs/6Ud50ltEiY4l5cJHqIjgtP dSryzxy3/sMCJTZsQa49DUJPyZ3DpIf4ywu+RZS917/y8pAWmhf1gDGDxUEHFe9AiSaC 1plqPiHWm+iGP+KJ4nVifefFRThInHn0fUUDeOYrBiL3i4yuXW2BHiFk4+6r3Y35ciR0 ENHyMYGYZNAcKNDDTAwP+2Ll45JJZCUTAk+14Y5vguVCp0jILTZP3wCpSpAxbBF8d7rF us4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QyWp4X95ZOlj3HRqIqq5Np/f7SP+VBBbMvRFL8CO2Wg=; b=FyHH0r7pCu06uWZt5saZbcp2QYPKi3SH+7vRyzk0NqOvia7nyhmVVwDXWzQvew+yJ7 uioVzu1AVN1h1CUrqgnTq95BF3nGj2mVZ5L1gQli+1lYtHAHWwwJhitTEND+ThOION7C QB5qDe49JElMWzWKeMTOvyb/1gJHCLl1zjca6eRhpD2i5JWGgGZWmepB4qBBXrYSTEyo KZv0HJ0XkFNGRKj4Akvtff2oN+o2KhQAjpMAPSg4A/nEvMjqfLydbKmkNWBXo5ulTLHx xhMNkcXmGpsnDWV8vUUXQrMBBGnjDzYCmCsfsJZ4I4kLjVIwJl8u2syGQVClUHAwyori NWVw== X-Gm-Message-State: APjAAAUoBqCWiw49x7lgWZLnKzJqCBJwn9ruZJBo343nemLgUdMc4KfE K7Qhm20AfbZllhu6Dd0hmJWVOwormw8= X-Received: by 2002:a63:c0f:: with SMTP id b15mr10554185pgl.33.1561746271000; Fri, 28 Jun 2019 11:24:31 -0700 (PDT) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id s15sm2916223pfd.183.2019.06.28.11.24.29 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 28 Jun 2019 11:24:30 -0700 (PDT) From: John Stultz To: stable@vger.kernel.org Cc: Felipe Balbi , Fei Yang , Sam Protsenko , Felipe Balbi , linux-usb@vger.kernel.org, John Stultz Subject: [PATCH 4.19.y v2 8/9] usb: dwc3: gadget: remove wait_end_transfer Date: Fri, 28 Jun 2019 18:24:12 +0000 Message-Id: <20190628182413.33225-9-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190628182413.33225-1-john.stultz@linaro.org> References: <20190628182413.33225-1-john.stultz@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Felipe Balbi commit fec9095bdef4e7c988adb603d0d4f92ee735d4a1 upstream Now that we have a list of cancelled requests, we can skip over TRBs when END_TRANSFER command completes. Cc: Fei Yang Cc: Sam Protsenko Cc: Felipe Balbi Cc: linux-usb@vger.kernel.org Cc: stable@vger.kernel.org # 4.19.y Signed-off-by: Felipe Balbi (cherry picked from commit fec9095bdef4e7c988adb603d0d4f92ee735d4a1) Signed-off-by: John Stultz --- drivers/usb/dwc3/core.h | 3 --- drivers/usb/dwc3/gadget.c | 40 +-------------------------------------- 2 files changed, 1 insertion(+), 42 deletions(-) -- 2.17.1 diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 24f0b108b7f6..131028501752 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -639,7 +639,6 @@ struct dwc3_event_buffer { * @cancelled_list: list of cancelled requests for this endpoint * @pending_list: list of pending requests for this endpoint * @started_list: list of started requests on this endpoint - * @wait_end_transfer: wait_queue_head_t for waiting on End Transfer complete * @lock: spinlock for endpoint request queue traversal * @regs: pointer to first endpoint register * @trb_pool: array of transaction buffers @@ -664,8 +663,6 @@ struct dwc3_ep { struct list_head pending_list; struct list_head started_list; - wait_queue_head_t wait_end_transfer; - spinlock_t lock; void __iomem *regs; diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 8291fa1624e1..843586f20572 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -638,8 +638,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep, unsigned int action) reg |= DWC3_DALEPENA_EP(dep->number); dwc3_writel(dwc->regs, DWC3_DALEPENA, reg); - init_waitqueue_head(&dep->wait_end_transfer); - if (usb_endpoint_xfer_control(desc)) goto out; @@ -1404,15 +1402,11 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, if (r == req) { /* wait until it is processed */ dwc3_stop_active_transfer(dep, true); - wait_event_lock_irq(dep->wait_end_transfer, - !(dep->flags & DWC3_EP_END_TRANSFER_PENDING), - dwc->lock); if (!r->trb) goto out0; dwc3_gadget_move_cancelled_request(req); - dwc3_gadget_ep_cleanup_cancelled_requests(dep); goto out0; } dev_err(dwc->dev, "request %pK was not queued to %s\n", @@ -1913,8 +1907,6 @@ static int dwc3_gadget_stop(struct usb_gadget *g) { struct dwc3 *dwc = gadget_to_dwc(g); unsigned long flags; - int epnum; - u32 tmo_eps = 0; spin_lock_irqsave(&dwc->lock, flags); @@ -1923,36 +1915,6 @@ static int dwc3_gadget_stop(struct usb_gadget *g) __dwc3_gadget_stop(dwc); - for (epnum = 2; epnum < DWC3_ENDPOINTS_NUM; epnum++) { - struct dwc3_ep *dep = dwc->eps[epnum]; - int ret; - - if (!dep) - continue; - - if (!(dep->flags & DWC3_EP_END_TRANSFER_PENDING)) - continue; - - ret = wait_event_interruptible_lock_irq_timeout(dep->wait_end_transfer, - !(dep->flags & DWC3_EP_END_TRANSFER_PENDING), - dwc->lock, msecs_to_jiffies(5)); - - if (ret <= 0) { - /* Timed out or interrupted! There's nothing much - * we can do so we just log here and print which - * endpoints timed out at the end. - */ - tmo_eps |= 1 << epnum; - dep->flags &= DWC3_EP_END_TRANSFER_PENDING; - } - } - - if (tmo_eps) { - dev_err(dwc->dev, - "end transfer timed out on endpoints 0x%x [bitmap]\n", - tmo_eps); - } - out: dwc->gadget_driver = NULL; spin_unlock_irqrestore(&dwc->lock, flags); @@ -2449,7 +2411,7 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc, if (cmd == DWC3_DEPCMD_ENDTRANSFER) { dep->flags &= ~DWC3_EP_END_TRANSFER_PENDING; - wake_up(&dep->wait_end_transfer); + dwc3_gadget_ep_cleanup_cancelled_requests(dep); } break; case DWC3_DEPEVT_STREAMEVT: From patchwork Fri Jun 28 18:24:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 168128 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4020822ilk; Fri, 28 Jun 2019 11:24:33 -0700 (PDT) X-Received: by 2002:a63:89c2:: with SMTP id v185mr10424676pgd.241.1561746273165; Fri, 28 Jun 2019 11:24:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561746273; cv=none; d=google.com; s=arc-20160816; b=J6FcIthS4gsiRcvxo6m9UbCH+oJbI6XTYP7xcQqdy2FTM7DdIPZ8rLueSQTYDiSwBl 3/gnGlqAfk+jD2NZcW0wvCS3T5My8eQ0Y6XeIxE/5jpPRGhmQv25ISkTBhUlavX8QszI pnlOYC3oD0x26E48/P141EokBhTEtn/JULW8HLMcBN8A1sw2Eu+lnAIBVAFPHSHpX9GG bsvkXUSXIF5n7E12b3YTGGhWVLHOaske7jSuq6RliclXKcHvRMxppynVzDb+E9vxZWI2 R+fWdaVcqnLtMt5IAl9dSJfDK3d9G+yjyyfuUBnkb3z0bFwLDVJa21qqSfx/vMd/NdpK Xvvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PDI+SV9GVbs38aQev8L4wXqHdjl41NulymWKKVfYEMs=; b=HVpEKBMQPTkOyHmWsJDPX6c/10bJGO/Wapyd3Z9PNBEjHXob5xdTJOZLBdxq6AvpEm n4Gpk4QubN4TbI1Gj7mzPmqtcSe8G12XptB4nreuUe4WfUeNBJMlgqdAKzx2waLwJVVN 9jqpsnlDOZeRAztxusigO3Ipz9hn5OW/q6wtAAMitTHGKrttnNqHyirQN1hqgetdeoCP EKpxjSh8Tl1A6wYJfxWRX5ekQem4MMnnyD1XKZEVs33F/AMjMaGu37IQ3bneozaBrKes /HdIS8/vyis7fHX93FpWLOGTm3Nf17QOZvWY7f0gl7C7uuYF+prF/z13b4ndwDxyf7eY 5ysw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qYrnaW3l; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id 37sor3526759pld.19.2019.06.28.11.24.33 for (Google Transport Security); Fri, 28 Jun 2019 11:24:33 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qYrnaW3l; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PDI+SV9GVbs38aQev8L4wXqHdjl41NulymWKKVfYEMs=; b=qYrnaW3lA1R/6Lwx4ACSRpppLZSqj/nsm3HWJ/XyVJwBmDMDUednPJzQch3mC+6g81 cPJ9u2y2ef5RaRc4afkelF71jKIGTM6gU1NZtMwdTJngKcmKhXrSuxlNPocHnozZLmvs oR2JXHYWYgFKOZk1ELyxIUUZhBKMm4lp/A2PL4hNsaczXpzhQy3Z024AghkMA5TLL0VQ EdGdtVc+6BVpxJeup6O0MuUV17IsSM5fRlQvXnPxWQgr91vTI4uVmTQ8gakEk5WDCYwi vh0wbNusAu55fvfNftAaOQjKXrnSj1YPFpRzKidXW+9Sr9de4iFTLvHi9AYeaQTpguGC evfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PDI+SV9GVbs38aQev8L4wXqHdjl41NulymWKKVfYEMs=; b=PFAx9MfgDgwgBl10tMSNG+A6y2dOQIvayeYJfGs1bEnLjVoTXkrnrRfvqXa8apwMoV /oV3grgtyj1PYnn01oC4X/dZGmpn4om2vUfHZIOd0dWe/FO8Qgme1Yu3f937df4mRWHU cH52t8fFZDicg+zwbTO7f87h7ZaOxDwT1cImVbdQ1MSKS13fNOa3K6SB8HHYP2tAvs02 s2an5eC5Gc+Bwl/LKx7pX/i5TjYRa7LsBW/8NuI3shPBM+HkoFNezqkmrolf9xPEcy3Z MKhjeITsbEHiHH4F3PZ//Z6upowkHGY+lUk2xWoP9QpowTH5xPKNylqyWchYuYbTs5iP ZKkg== X-Gm-Message-State: APjAAAU5Grxy4IARdbFIKf7r+Ytmp7k8qEYwYbHXWQ4V0+agWNjUHFac NquKa5LhxJ45s9bXdvQYujS7fiyW X-Google-Smtp-Source: APXvYqy5EteuxJPd8uSp7RfKzmDXMzcgaoORnjNlj/kg/wwocf9+URJb3sIck64ZvXt+s++AWxRmvA== X-Received: by 2002:a17:90a:9f08:: with SMTP id n8mr14979208pjp.102.1561746272721; Fri, 28 Jun 2019 11:24:32 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id s15sm2916223pfd.183.2019.06.28.11.24.31 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 28 Jun 2019 11:24:31 -0700 (PDT) From: John Stultz To: stable@vger.kernel.org Cc: Jack Pham , Fei Yang , Sam Protsenko , Felipe Balbi , linux-usb@vger.kernel.org, Felipe Balbi , John Stultz Subject: [PATCH 4.19.y v2 9/9] usb: dwc3: gadget: Clear req->needs_extra_trb flag on cleanup Date: Fri, 28 Jun 2019 18:24:13 +0000 Message-Id: <20190628182413.33225-10-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190628182413.33225-1-john.stultz@linaro.org> References: <20190628182413.33225-1-john.stultz@linaro.org> From: Jack Pham commit bd6742249b9ca918565e4e3abaa06665e587f4b5 upstream OUT endpoint requests may somtimes have this flag set when preparing to be submitted to HW indicating that there is an additional TRB chained to the request for alignment purposes. If that request is removed before the controller can execute the transfer (e.g. ep_dequeue/ep_disable), the request will not go through the dwc3_gadget_ep_cleanup_completed_request() handler and will not have its needs_extra_trb flag cleared when dwc3_gadget_giveback() is called. This same request could be later requeued for a new transfer that does not require an extra TRB and if it is successfully completed, the cleanup and TRB reclamation will incorrectly process the additional TRB which belongs to the next request, and incorrectly advances the TRB dequeue pointer, thereby messing up calculation of the next requeust's actual/remaining count when it completes. The right thing to do here is to ensure that the flag is cleared before it is given back to the function driver. A good place to do that is in dwc3_gadget_del_and_unmap_request(). Fixes: c6267a51639b ("usb: dwc3: gadget: align transfers to wMaxPacketSize") Cc: Fei Yang Cc: Sam Protsenko Cc: Felipe Balbi Cc: linux-usb@vger.kernel.org Cc: stable@vger.kernel.org # 4.19.y Signed-off-by: Jack Pham Signed-off-by: Felipe Balbi (cherry picked from commit bd6742249b9ca918565e4e3abaa06665e587f4b5) Signed-off-by: John Stultz --- drivers/usb/dwc3/gadget.c | 1 + 1 file changed, 1 insertion(+) -- 2.17.1 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 843586f20572..e7122b5199d2 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -177,6 +177,7 @@ static void dwc3_gadget_del_and_unmap_request(struct dwc3_ep *dep, req->started = false; list_del(&req->list); req->remaining = 0; + req->needs_extra_trb = false; if (req->request.status == -EINPROGRESS) req->request.status = status;