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: 11023057 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E350D13B1 for ; Fri, 28 Jun 2019 18:24:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87927284C3 for ; Fri, 28 Jun 2019 18:24:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B9832862C; Fri, 28 Jun 2019 18:24:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 25A41284C3 for ; Fri, 28 Jun 2019 18:24:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726666AbfF1SYU (ORCPT ); Fri, 28 Jun 2019 14:24:20 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:35180 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726520AbfF1SYU (ORCPT ); Fri, 28 Jun 2019 14:24:20 -0400 Received: by mail-pf1-f194.google.com with SMTP id d126so3399507pfd.2 for ; Fri, 28 Jun 2019 11:24:19 -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=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=JC0SNs6sv1Rb/rADCbnUps1SxSAoJlnPABUbTqKutvgsV37QmbiSZ3a/ZjiDIpINIn pczUGUf0pY1mX+t6gK1u1LnzHFu2iDNcqWYYl6lmsLb9C1bzRRXrQZZvnWNZIdCeSXuC KhGwlbD+0UG8vZ4wk3CM0xz6v3/sCVuWt4ZSGDMDQqaBDP4+rVY4u7m7MBu4JEAIROO6 dYFVByU+KSOuu1PrN7cUZOuVFZlaFg+rvyl/NLlSVwBR4/uhkvm1gtplY9GyRQBh1pQA U9PajHDxPpZ7Y/PVdsTfLlKfRFg8qUGqZTLf29WjYtTbbCYgGQnEVT2Tseg/QINjoLYy ZN4Q== X-Gm-Message-State: APjAAAUOD2QHkO6x5DU+oElACIyge2Zv3gt8v+4CgcxhN7neGi6L4IfW tsk7wV7e8IZy3PXTr/p7sO7Qfg== 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) 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> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 11023059 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DEB4714BD for ; Fri, 28 Jun 2019 18:24:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81E72284C3 for ; Fri, 28 Jun 2019 18:24:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75BC12862C; Fri, 28 Jun 2019 18:24:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E88EE284C3 for ; Fri, 28 Jun 2019 18:24:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726674AbfF1SYW (ORCPT ); Fri, 28 Jun 2019 14:24:22 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:46456 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726525AbfF1SYV (ORCPT ); Fri, 28 Jun 2019 14:24:21 -0400 Received: by mail-pf1-f196.google.com with SMTP id 81so3381355pfy.13 for ; Fri, 28 Jun 2019 11:24:21 -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=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=Djo1BHKbAWThNXp8nmB8skguWp/MkPDGc7Dn/YqwQ8zq2HIfnO4n4Jp2spEiitXHxP g+T5yL5igvNxEk98Iht424HeloHbY022bfQn60A/dxYhqucB56inAVNCcOYDfEYMOmIt 2dCC8YA0frcNOgDClGflj1USdYkOvGxkJXLCdYFngptnS7Dcgf1jmbvccQldsJiIoikt ir8Gqr3rUfY9LK4GxwCH4AQ6nAdga8cXSHy8ZDcTxrD6nDa6mSRPkZsN6YR4ndpAnpvg uPEBbxA0VNVjuggb6e6ouICxPXOtD4QDMYx0dQnPjainG9v02SMHkaXeBsMaiVQGOPIK IpIg== X-Gm-Message-State: APjAAAXqCsUUIUyuRaMXfV2Sh6GXYzgtThPKYFn/I2rFxKd0uFCWSBjR om9qta5Ik+WvVeQbCX1ixaO8hQ== 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) 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> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 11023061 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0BF5C14BD for ; Fri, 28 Jun 2019 18:24:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A3DCF284C3 for ; Fri, 28 Jun 2019 18:24:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 982A52862C; Fri, 28 Jun 2019 18:24:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 32971284C3 for ; Fri, 28 Jun 2019 18:24:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726729AbfF1SYX (ORCPT ); Fri, 28 Jun 2019 14:24:23 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:39522 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726667AbfF1SYX (ORCPT ); Fri, 28 Jun 2019 14:24:23 -0400 Received: by mail-pg1-f193.google.com with SMTP id 196so2949477pgc.6 for ; Fri, 28 Jun 2019 11:24:22 -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=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=ONlpvCy/5tmSw4ZKIbXV1nEmIuZq1smP/2UVf//KquK97QYUoIGZijyY58O+2oJfOD LaKb+L3e72tVez1oSuJEf1mOwmeXHBaXHYbvWqn5H+69m2r23AdjepTNxdBuJtbjg6G/ Dz+TFA5M11R8LqsQhgu99NChOysP7rBz/Ca+CYjLplXYzngQPUkto2yL6NAw9fwVilJL yWKpy1lThB7iERJWBRSlTG7gq3eCKc2JPAceIEWlxauIS9p9hXKkFLst7cf5nFpWmIG9 WlYUQGmgx6a1MRXrvmV85ccPwaMbG3d/XppV8n729BEsvNwBclVVEGDDyw9bwnHRLf2W l9yg== X-Gm-Message-State: APjAAAUJeXAupEbnyrF/7NIBe8OYZ5lxcdKm4S9O6J9+HycVmDeM9hmp +CCwFWkdoqB74fVs5h87hUOJNA== 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) 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> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(+) 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: 11023063 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D57813B1 for ; Fri, 28 Jun 2019 18:24:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6C61284C3 for ; Fri, 28 Jun 2019 18:24:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9AF122862C; Fri, 28 Jun 2019 18:24:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F456284C3 for ; Fri, 28 Jun 2019 18:24:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726731AbfF1SYZ (ORCPT ); Fri, 28 Jun 2019 14:24:25 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:39527 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726689AbfF1SYZ (ORCPT ); Fri, 28 Jun 2019 14:24:25 -0400 Received: by mail-pg1-f195.google.com with SMTP id 196so2949527pgc.6 for ; Fri, 28 Jun 2019 11:24:24 -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=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=PPWVhwvUMnPBvpKDg10rctyP5MGIpPFuZJ1exPwPLo/tO9u0aPlb4ZoD5DM7mFW5pt UITP2sxmqXfmLSC4q+iYFv7tFT+/QuaIbBhmjnTQ7zJmGq9gdEMv2YG5070ONLEq9mm/ zvUEF6BFyh4QazgHX90TqHFsof5Sfb3mhGPYPGcLoq2lQ8KZx8CJ5RAPkOjfwqAVGxuR tECmaTSSPBZgySjsll3LQPtEpgSa3LytlH9L1brvUqKd13RpAFCuhO878eKfD5A/FHCx pGDEkp5Ftso95RP1n5bawkkSd4Ofv1oEUZqoCeMcswhgrUN+09bZkeByWJSGL9SbyS3p 1HvA== X-Gm-Message-State: APjAAAWXBGuRQbxfUEEdnbq8UpfhGPLydqup22b2nF8MC0h5HMCkjd2/ 0vRBPr/Mns1wOng4Zc3QB1Y9cA== 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) 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> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 11023065 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 918C713B1 for ; Fri, 28 Jun 2019 18:24:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35836284C3 for ; Fri, 28 Jun 2019 18:24:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A0292862C; Fri, 28 Jun 2019 18:24:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFD35284C3 for ; Fri, 28 Jun 2019 18:24:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726747AbfF1SY1 (ORCPT ); Fri, 28 Jun 2019 14:24:27 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:38822 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726693AbfF1SY0 (ORCPT ); Fri, 28 Jun 2019 14:24:26 -0400 Received: by mail-pf1-f195.google.com with SMTP id y15so3404573pfn.5 for ; Fri, 28 Jun 2019 11:24:26 -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=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=TEVvT8wDUqDQMXHOtjhHaoism4830urn6dWUTmIMJEiodfbG3FA6FOLR/p+swdfKBC Q7rEeNOz4FFOYz8pcxcrwfpVTs3txSjBu61qWWKOuSP8uKk3C4pFIWlauCb05rUevUeS HKEuq8RaOSYtOL6xOWmu3qFZTRRe7EUl6jj7kM88kc8sOxb8G0iQI7HJwEZ/wmv07msC X+NaCfCXWprMOSSaAkGwpVG3T5y7kkwUTXABZooHQEz8JVqwXSFvY/JT59n0imSqSzYJ tqIhfXhiFesPzVXhcVmTVXSiT5MVxPWLs5JBS+uH5gZl6V+CXKCrdXNbqEsXWTSjhDJj B5jg== X-Gm-Message-State: APjAAAWR3pCusRtmGI2D0/DtrGrF5O8khn7Ch4v3VjZ7q0Mc4frkGFIa twCOh+F80L+suPK2K79pFwxXSw== 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) 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> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 11023067 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4562014BD for ; Fri, 28 Jun 2019 18:24:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DEAF1284C3 for ; Fri, 28 Jun 2019 18:24:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D341D2862C; Fri, 28 Jun 2019 18:24:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 70073284C3 for ; Fri, 28 Jun 2019 18:24:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726754AbfF1SY2 (ORCPT ); Fri, 28 Jun 2019 14:24:28 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:35198 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726738AbfF1SY2 (ORCPT ); Fri, 28 Jun 2019 14:24:28 -0400 Received: by mail-pf1-f193.google.com with SMTP id d126so3399682pfd.2 for ; Fri, 28 Jun 2019 11:24:28 -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=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=bFe9jbw43VwgKMSlJ1ZZ6/aYt6Ezle03ULb6KvjEHkNBzZyaqFRxQtR9T8Afv+IoAy xmw25CwTcdjpUpUvE7+Ieu0AgB2ZVjaqrA2HgD+fPyytr20Gz/sGBOg7eWwLOjKKvMcw G1m3XlLQVyd9bD58mSJCQPVLEOoj+QXev25t0yMEiqpMV+SQhFGyceVKSU0OAgfWo8zh UjP/kThIIoiNOvRqzTDJHe9WPKN91FJs4xei8BYyD4QXpQjntMX65V2gGq13AN4Ne8rx jYTRmTjUOpJ0ADeN7ao7qb64Gbjbed5rcxeVEH0DKhO1/xExeFWSnGP4nlr78EYJJL1V //oA== X-Gm-Message-State: APjAAAXO9GwpuH/0vgEmJFCaLb4Qhi6VTwxh+Z+X/N+5+dPtqMOuf/97 NAUPaLKsVPE/VqMNiACBsW/iaQ== 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) 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> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(+) 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: 11023069 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1879514BD for ; Fri, 28 Jun 2019 18:24:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B047D284C3 for ; Fri, 28 Jun 2019 18:24:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4CB92862C; Fri, 28 Jun 2019 18:24:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3ED0E284C3 for ; Fri, 28 Jun 2019 18:24:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726766AbfF1SYa (ORCPT ); Fri, 28 Jun 2019 14:24:30 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:35202 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726750AbfF1SYa (ORCPT ); Fri, 28 Jun 2019 14:24:30 -0400 Received: by mail-pf1-f196.google.com with SMTP id d126so3399700pfd.2 for ; Fri, 28 Jun 2019 11:24:29 -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=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=lKvan9MZuCsuB1/026JwgajMYxL7mUX8AIJ/YqHsp32jhfAJe/+JapTRMUl0DbpEog uSWQHXs4aYY69cKWLMWOWcmXey8UgQHKdFaH3Si3GrY3pZ983ny2aOWnxW+R99uUnr1/ Z0h38Gytig97Y16wZdzaygxhEjfek9FNdPEH4qrf7IAMzIqBn+mdYhFPpbiyJei0G39q IpxtsW7EQiBFbxHqQQOJF4lMr6KkZzNJiwtNmXKdQSQMoSVqZaLq2yzBjUUjB/1gQXxe moqf4RofVZIjNhSF5+NBQvMO7weW1NNQDEMVpsKhGhF+36m0Shy1En/pjpztKJZ3mwhY spsQ== X-Gm-Message-State: APjAAAVHK4j+VYKXRmDT6m5s7firOJ0ysHFdlDEfwYp30FPNh7EveEfI G2DVcHss8TqtPikSJzJ5+FwgPg== 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) 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> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 11023071 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DAE8713B1 for ; Fri, 28 Jun 2019 18:24:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F6E9284C3 for ; Fri, 28 Jun 2019 18:24:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 726A82862C; Fri, 28 Jun 2019 18:24:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2B6E284C3 for ; Fri, 28 Jun 2019 18:24:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726775AbfF1SYc (ORCPT ); Fri, 28 Jun 2019 14:24:32 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:33771 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726761AbfF1SYc (ORCPT ); Fri, 28 Jun 2019 14:24:32 -0400 Received: by mail-pg1-f194.google.com with SMTP id m4so2957043pgk.0 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=mzhC/2jxPJAqkfg5/fOg97NPPnxoPdGTolmI0iHWLVPDIxhe6UJy+Utm3Jfcr8nI0Q Bpv7CcaVhoMdoR2pB0xbHRTZXfIeIZVXJFuIDgJ/0fCfw6bN8IqsV09dPBUL3SaTyQha 12+HdtDlUowfqiL2XVGot4Px5D0/9AW8FqE2TXdgIQ3URaHOiS2mfPkJivjYLICwm94C Rxt53lEBoGEfzaptTptByggkrM7+2VqGYQwLEam98vw3EHrfFFx3QRrKDf1DnWi3fcUd mc2WYeGGkgsWeKGYZfgv+gzk1pcNBuWWg1EVcxmgKYCnj7n6zcUqIQLaPioBJs/dyKtL ifcQ== X-Gm-Message-State: APjAAAWS2NSp6tldiYbj/ki38q/X31cIBprZTRwUdFBMyX9O3y1Iaf0q +zPwA0TDbaXfv3gNkSuOz3bFgA== X-Google-Smtp-Source: APXvYqy2cKPm9RfrknaLyyXtYPWo4W7FTtXpZsIaLCs1GrPvCW6CaTrvDh1U3tvruLyd2zuJea0bHg== 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: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 11023073 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D30F314BD for ; Fri, 28 Jun 2019 18:24:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 78E03284C3 for ; Fri, 28 Jun 2019 18:24:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A45A2862C; Fri, 28 Jun 2019 18:24:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 081AB284C3 for ; Fri, 28 Jun 2019 18:24:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726770AbfF1SYe (ORCPT ); Fri, 28 Jun 2019 14:24:34 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:35210 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726761AbfF1SYd (ORCPT ); Fri, 28 Jun 2019 14:24:33 -0400 Received: by mail-pf1-f195.google.com with SMTP id d126so3399772pfd.2 for ; Fri, 28 Jun 2019 11:24:33 -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=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=jlnvym2qj9f+r8CKML88TIgW+TV6ib35Ah5OShb2Qklcyd9NBqmI+5X39dZclQ8vaC PUa1IlevT+DdmilwF8qR2t4440W4y0dBZuQRDI+Bpt7AB9zofN+WTKy7gsT7c/Ob5dyg KJvLnCDVmnqYjOW8LqiKbrWiCwe5X4vIo1OuRURhH7idVT4hCR1cmMBly3jy1maIQRz2 975BVntmhGLZTbeOy6DSP+xax5SopmN6Vp7YfqWIRAlQHKxKsMhz6DXo2dLgqKYpA5Lc 0RWA/TTPvTWZCsztEPZiABQgKjQJ/HOdQlOTR5RLzMf4QGtUP/bMRocJwoE45XVn3A5c PxoA== X-Gm-Message-State: APjAAAXo/JPXWUZPf50zWASCetONU4WQUzmLAx/yc3xrezTEQpxASgp3 QpCJw7EVWBPL7FvsdUjuG8mgAA== 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) 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> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(+) 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;