From patchwork Thu Jun 27 20:52:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 167982 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2821857ilk; Thu, 27 Jun 2019 13:52:46 -0700 (PDT) X-Received: by 2002:a65:6102:: with SMTP id z2mr5482073pgu.194.1561668766557; Thu, 27 Jun 2019 13:52:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561668766; cv=none; d=google.com; s=arc-20160816; b=ahuhzUo0pAcxPBFNrvjdiAUmn9iOFV+fQq7aOUPQTmgh0c4DV9OdiUb5HWHCEp1pOc j2QYMjP6zJ2KrL1aReov4Fp98eqN2TR0oFXDyuRBPAUmx6p6/cGs3ZlHIP+jue1BBBI1 G4FPiL+I6gYDr2ZZYwULMK9r8ED96aJPEy3zPa+C4K5jXl6zt6e+rYPrL1o38OtCoXc+ EiGdGl7uWthUkuK3mcL/LTR4XiGq/54W393wXsF3NqrtqttH1+Kv0zLvGTkOqiP5gzsa M+SwRe1CLsUZiOKEaWZbesk0hffbZTkod7YVJFYwQ34WPKoS+1bHdzvRoA9+qmRTVdf6 zEdw== 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=XDEati5AnmeIwG/gbfDq9Iz0JoFW4jKO9V1cvoJDwbs=; b=MNEXRyKK/6KsnbIgujT9isaGNc5dlC+rbIghWHgb6ur7qOB3q/ivcHYY/5IZnD+eCb 6a3cC7xzIRciFS3EPId+FxgII5HNonOigUtzLtrgTDy++N08wfx8DmlxbSLuNeJzug3r OhS1RbEQ4Nh1EjmXsdhujoR9bHv65gK/X1KrBNgiJKKadfnANIJji5TXoACmQ0jFLbJG hzYqunzOinX5WI7ngPEcVYc7ta3fOm40jDT/GUNlJYhA74Gt+tpgIM0ni8bwJ1fheITN y2WZesZZfOES/5E52BnH2pgBh+zbs4pBu/9S2L8cgvNRunx61r+CWta5a2Ls+nJeV9SX 7U+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zj0cwyUJ; 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 bx14sor7818326pjb.21.2019.06.27.13.52.46 for (Google Transport Security); Thu, 27 Jun 2019 13:52:46 -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=zj0cwyUJ; 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=XDEati5AnmeIwG/gbfDq9Iz0JoFW4jKO9V1cvoJDwbs=; b=zj0cwyUJjc4490ScZRzBvv+fzHqbH+UoOGU6jOcMpp/NPafDKPGu0mfwwyGL4NSL8I aMuqyYlFFw9hV/Tss88XvbIqvsWoMbtRYuVkVP4a9rizV4aFKNqFOlvcBzfSxY3xN9ju ZTwyS0G/f1RnzSE9HsvPDQqJ1rJONC2miE/fcQbIfSkeLp8su0LErsR0MyIx0L1MT1AG c4yPv868SisEcCj0GjZXCdDrsh3uMv6BL5bkm+ysWAsuHWt0FGxkx83qr5i/E5AMhCsD DDE0VqI9oDz8T6cm6Anj3W+1CKy+btKOSUMnEPyRlkMBNO+Zk4cEU3Q5pNPWgCaRul+C FRew== 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=XDEati5AnmeIwG/gbfDq9Iz0JoFW4jKO9V1cvoJDwbs=; b=GctQhK5AXcT2kcgl7ZsXUFLseahvr/XcswU7fyuok78ZqsJrv8EfDIyDuLx1n72RjC bcGBExx13afKjTrmdA4+X0Y9ylh/CJs3H5tt1bbjXRsG+mFCLCAzA+HjWX5hPwSEjTmL 8stmMTGE7DGt5KS+oa/whN1SVBthd2ORt6ICmxPH7W3KX3idfjq5ZQynWkzZIKP+PQ/v rGipABwTNW20Ox1X288VjypCmZTSNJwY4SxA7ODWjbm4ryC/NyuvChhPrtf+zh4uxx4a CesHV8OZXSj+iQnYW7iexgDcn585zQUFl1FpjopIqKZwRYNNb0T8/89flEy0HsJ+cBkH vvbg== X-Gm-Message-State: APjAAAUx3pCEGfGSip+9aSZitZaG8r86AoGwpl+4X/ADB7bw+qc2LzZI pavOBIkIdvHwJXVzHCCHrCn+qyV2 X-Google-Smtp-Source: APXvYqw2DIFNltOk0pMfuDdIDROXrYNXCaXcRvY6zoErZhyNm0BDHfPoUZrYtANNsXav9qIru1U82g== X-Received: by 2002:a17:90a:2228:: with SMTP id c37mr8570819pje.9.1561668766064; Thu, 27 Jun 2019 13:52:46 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id 2sm3674083pff.174.2019.06.27.13.52.44 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 27 Jun 2019 13:52:45 -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 1/9] usb: dwc3: gadget: combine unaligned and zero flags Date: Thu, 27 Jun 2019 20:52:32 +0000 Message-Id: <20190627205240.38366-2-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190627205240.38366-1-john.stultz@linaro.org> References: <20190627205240.38366-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 65ba1038b111..4894fed1441c 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1070,7 +1070,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); @@ -1114,7 +1114,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); @@ -1130,7 +1130,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); @@ -1412,7 +1412,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); @@ -1423,7 +1423,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); @@ -2252,7 +2252,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; } @@ -2329,11 +2330,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 Thu Jun 27 20:52:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 167983 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2821885ilk; Thu, 27 Jun 2019 13:52:48 -0700 (PDT) X-Received: by 2002:a65:5144:: with SMTP id g4mr5596061pgq.116.1561668768001; Thu, 27 Jun 2019 13:52:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561668767; cv=none; d=google.com; s=arc-20160816; b=tmiFn6OqF+qeJWnkcVDLTchayVQ28Du4eOq8W8qhBtJ17zAEqh7aCpno52K+AyBEub 0v4WsTU6m3X5A/lfGaBgdexiCJgeMD+qHEDLGz9s+pDa+8BKEbbcvI2N29da0LBflqea OSAL29WwUpHfAg1c7YrfRjxPXC8Z2Z4rEVlpNv3SpPJhgGXXD4vwWr3SlYDT9uMQwBRE 6qR/p+61aqbVF/35dwLaELJAiLmckYhQo60mGVtS+xaLjtyVGXmkxzwS35GwreBY7eqv eWKZDNO42f8ZuCnfAIERbVSmFO7YZY/0SDgsLC+Gu+uQI2FNRN5TnUoRYEBIVjnfxGQ1 /djg== 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=4Ag3DptOQlKFvwhPzNLWrHIQu/RujtBlVJPxwQgjUZ4=; b=mX8t5K9YtT0Z0v44Vm0qlyqjv42dWzpWPV1aOGVcg3T195DVPadThIjAM/NbpKqn0Z M2Sv0QMqepB/mPrAuhXN19A1b2ytXAVzjuOdIuql+rY0tg+FkkHzjiz4jH78eDolLhX+ 8sgEvMJH5XyTApkJwmql8Nm8q7MzUkmtnEX7Nzo+KsKOUU12F4WeTPFWPS9LRDt2HS75 0iy7zy0JLFHklqlW4sd0MtmG4XmQYA2cRUle2Vn6ho/XoWQCik2kHFOwURoMp4VSdhSU FGzN8WMFmxms9qNPFBgX4UumAVNA+CH+LMhxKFVONFPNWthN4Ogr+l18lkBmkNFYK8xP rOfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xHiJhrSX; 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 bx14sor7818402pjb.21.2019.06.27.13.52.47 for (Google Transport Security); Thu, 27 Jun 2019 13:52:47 -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=xHiJhrSX; 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=4Ag3DptOQlKFvwhPzNLWrHIQu/RujtBlVJPxwQgjUZ4=; b=xHiJhrSX+JSre8rOd6Cct+h18tuOFNpJtHqH//2drv/WJrQ6DlvS6OjN+XkAzsSJ7p 5PGrfaHh8wCqeYYjfEkBEyoMNJv9B2jxgxogc8EE5RgIoDIweZHyEUI6gQjx7oNCB33d BRxXXO1g6O8f9BZu9HY400wvD7gnICKH88EKc4tLwdhBfBGXqTGbPNjEvl2jzw8fhYZQ /OCY8sLnUW6bsKHR/pgTJwJGLXMUu2MkuHeSG0XygFeBU7INB584rv6oPHJH5hsjNu32 zec75NOMp0HZM9oEmfWX2KCFQAYgAXO5A9eGXCOT2pokFSMya5iYtzOCkmro7ugBtjnU 5zrQ== 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=4Ag3DptOQlKFvwhPzNLWrHIQu/RujtBlVJPxwQgjUZ4=; b=bR1uclQSq53VQn8rHaYA0mkpJD9ckL+x3P/XjFNeE93XbFbUv68y6HYztG8KOIqRiz xU/B+OteWFxUmQnqU1n7qHQl1S6aqn8KodR0Gzt0P20YhrmryVQ7ZSO0ZnNwt2b6qhfV mCQ9J2DN443h6nBgKDs3DBJIdydx71ucEcTgrh4sWnSuLvPXt62QK4wC46fesn2hqclM acA9GJsmUZqtNe90LHKnV7rIozaZ/Jj8W6NAagSvqvPSAse0JUMd/F2alauD/Jp0u/qg evjUA/o1AdY57CE2YHv6o3+pyUzqZG8XrxIB6p8RSj6whQMzk0MCEN50RB0E0BjIYNtd ZxIA== X-Gm-Message-State: APjAAAXdGJRnj6t0k7wmAG3x5KuIkstwCqyhskopurs+uvwkO0nyQ8ft YDoXzDmjM+V2rdwc9Y7jsoLQpCPEN7Frng== X-Google-Smtp-Source: APXvYqwFzFzc5WG5FDPcHRdqb2AaRR84Y9E3us/OjEIh46TdQGH18lAYeE49opbpuX3HCTe4z8EjjA== X-Received: by 2002:a17:90a:270f:: with SMTP id o15mr8423034pje.56.1561668767538; Thu, 27 Jun 2019 13:52:47 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id 2sm3674083pff.174.2019.06.27.13.52.46 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 27 Jun 2019 13:52:46 -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 2/9] usb: dwc3: gadget: track number of TRBs per request Date: Thu, 27 Jun 2019 20:52:33 +0000 Message-Id: <20190627205240.38366-3-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190627205240.38366-1-john.stultz@linaro.org> References: <20190627205240.38366-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 4894fed1441c..019643a6ce9d 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1043,6 +1043,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); } @@ -1077,6 +1079,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, @@ -1121,6 +1124,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, @@ -1137,6 +1141,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, @@ -2233,6 +2238,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 Thu Jun 27 20:52:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 167984 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2821914ilk; Thu, 27 Jun 2019 13:52:49 -0700 (PDT) X-Received: by 2002:a17:902:d695:: with SMTP id v21mr6528464ply.342.1561668769597; Thu, 27 Jun 2019 13:52:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561668769; cv=none; d=google.com; s=arc-20160816; b=clSAONd87Y6lo0OLjyHopFGGVSkxmoOR0LEm5khkgqGNijWEszAZrokZh/QeZihPG6 /7uGDYJYiBMSgJoL4cPSVCI0eKbPlTbADI9Zg1IOYu1sp6D1oQ0jQ2zMo0T9ukO/XleA v13+YCdNmI/VjWQa0wtpipme49hUvk7tCKBcEZRxyaBK2dyVzx+yw6Qx/OwHQgWtasQ2 X+Jjmn8crG4qg7Cj7ma8FlzuRrwiBL8VROteCoMDBwtzIFBU5mgpujMyX2osi/gbS8L/ kY07WH2KW8QYn5OBXKvdpt2T1iF27uq/HIaILngVAtu5HfZTq78MJVw+K6KniM9mWpTn nmAQ== 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=9FOb1l6NNujBgS6Pd8VeV0djJsyicx4ys2rNzFqoG7Q=; b=FKOIs3ORcxvbltCIrORM8By2El9uJpcXeQRP/po8DBBxKHBG32EXKhir7WGagHAvzT NX2HmPH9w2ooaXWSXt/1kY/MZrGEOXinEtqE20txh2cvQ8HXDawBBxdQRGjRXIJ/nF3f DvOkTQUyZDriAPn16Dx7QYd59IszHD5K9s3bBVcHyjUd5CiwzTZb5s9SMgYB5fl4K4Lm ef0JBQtC8aImAlZezleu7U9tV9jT+7dS1s14qgwbrkVzdDJHD3ZE8Z57VQUL0RKWD+Ym Ru5tZTM0CGPg6/BuI1lZ8TX2b5LTthuzHWACc9EoEziM8hBocRxK32QRsfotkHXENQDf 0bRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jZTy9GN9; 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 o2sor7797091pjp.26.2019.06.27.13.52.49 for (Google Transport Security); Thu, 27 Jun 2019 13:52:49 -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=jZTy9GN9; 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=9FOb1l6NNujBgS6Pd8VeV0djJsyicx4ys2rNzFqoG7Q=; b=jZTy9GN90LSuaoebKhySaUJBbIs/l70thCKH0ogjOOYnf/FImagU1mFVs7SVkvyqv1 Oj6TfG4WHhDxW0FALTRuCvImxwAMbuCetVw2/Uz+Cmm57Se0OLRiYUOoUo5o3yCfIRZq WzyzhtDTiNoptljlGDvrfADw560u434AQtlScKg+2m86W7cuCH1GUaywOowQsJDvvgih O1aVgm4kH1rwEmBrhHAAhjowCSNKJeFnVlPD+SuBnzN8DrAY1WWjCHGOCZt8OwhUQIPX CV1L8NyANpsdnx+5aKvDhAW3Z7LaFgiAGKVJKBwOhTQjTqLmMmTzFXQ+vfydsbQhNKB+ YkFA== 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=9FOb1l6NNujBgS6Pd8VeV0djJsyicx4ys2rNzFqoG7Q=; b=al1YhjCE/ZR441yiQn1h2GeVl5ZrIMGoN0gSjT3RiuyLYBXFvB7NaqnOhVGHtrmWqW zOSzGULeF2kmLUOMmAWWeBDJGuDHo0HlgJG0dX7W26wY+vDHF9nawUaqtUlBPjgRXAy4 bWGOLSSwQzrT1vlJlKnSXOT3hYTQLxZ++IKlx9q2WyZV/AjW8j65R7HDZ0mMjVHGspH9 1/yDzkJcn0ecNSN2u4Ohr5eTqkB+5ufzQXRY2ryYnsQs+6+iixC7hb4bLN81sl5gfW2D jBcIBPxe3JRv9CQ0k01UwE/KQLPJIanmNsJQvnkYlWZx0JfAS96z9kl0D8HvDscTLBDr juuw== X-Gm-Message-State: APjAAAW/CsSYYSw2Un9ojBxqEzyS9QDWssNKisLfnZ0K/JksuefqTQWp AxPkpIJXbs+DuANXVjb2m2580Dvc X-Google-Smtp-Source: APXvYqxRCzT9WvpX0UY5boOll5wk4dWaNsxfMfmoyhUn7t+zOVaBDkQ7G/8C8FNy0PH5a0V2038Erw== X-Received: by 2002:a17:90a:634a:: with SMTP id v10mr8609992pjs.16.1561668769151; Thu, 27 Jun 2019 13:52:49 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id 2sm3674083pff.174.2019.06.27.13.52.47 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 27 Jun 2019 13:52:48 -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 3/9] usb: dwc3: gadget: use num_trbs when skipping TRBs on ->dequeue() Date: Thu, 27 Jun 2019 20:52:34 +0000 Message-Id: <20190627205240.38366-4-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190627205240.38366-1-john.stultz@linaro.org> References: <20190627205240.38366-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 019643a6ce9d..cb6dfea5d5e7 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1370,6 +1370,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); @@ -1407,32 +1409,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; } @@ -1443,8 +1425,6 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, } out1: - /* giveback the request */ - dwc3_gadget_giveback(dep, req, -ECONNRESET); out0: From patchwork Thu Jun 27 20:52:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 167985 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2821973ilk; Thu, 27 Jun 2019 13:52:52 -0700 (PDT) X-Received: by 2002:a17:90a:ad41:: with SMTP id w1mr8389261pjv.52.1561668772835; Thu, 27 Jun 2019 13:52:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561668772; cv=none; d=google.com; s=arc-20160816; b=j5AiCRJR+5UoT16WQZFp7cQbt6ZHjm0Jakv5Pfcc0TLi40ma6SnNzZO+/6rfq5Lg/4 d/SuHS+cCxAK9E79QotS0vBBcZRpUqsOvt4JUBy09UO8VbzrRIzT4PrNmFjr06s9KDCY daqdfOQMP9FrKAQI2PjB9+DNzRjGTUkKcMY1mnqAtF/NYE+XYvGPP0KtwQ7bsCE9CnWJ GdAFlDwMMmbfVVUOPaAdqHvcfe3zZ0zSygxQTXsJ7+g3notBJw0j/aMDoOzO1jWqySIL vEggqcDbNP6F1CM8na7j3xM/D33WGEf/3d9R8oRESXuGHbcXShF35bU6opa6H/RmvO/I Znew== 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=FFCtQU5sSYcakyL0pYyK6CZbXF6VG4/IPn3EqOoScBQ=; b=SXHt49kZUya5/mfmL8IsYKcIFJFme5QQNX6riWAJNBDMdZRRTHlqVv2EEm6qKQVd3r f3XlXu0v+9ytlGVwjMmBoMqjmO1/LEGhEMt1rK2up0glwyT2ayh9vOBUMr+09EZYyx1W Yi96d3H8rSCO3SIwaXI5nC1mnCYPIMPHMLQXcMcrAFyx7CXej+JGnrNBwZulXqBM2K6p /sU9HR5p0NwJoNBImnl345R2/z619lvbzY99gPmVZQzEgqLdT2n0YB6aegCuDCdg+U4i DCKZwfFmTFIoGB4MGs4+VwiJaLFPTKATZkiEpeiaOcfoaKGzOXQBzraElmg4uSa1FiEw bdSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i6g7tyjs; 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 e8sor43783plb.48.2019.06.27.13.52.52 for (Google Transport Security); Thu, 27 Jun 2019 13:52:52 -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=i6g7tyjs; 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=FFCtQU5sSYcakyL0pYyK6CZbXF6VG4/IPn3EqOoScBQ=; b=i6g7tyjsi0VqwFXI1RCnbQJnRRMBe1r2ij/wCB60zhC2J1rHRwUKJehchm8A5BPQS9 gFrbbdav83VFym+Vm79VqtmTYMfgUYrtNt6vB4uB3cVqx7Q0xtDmg/sXrTofJQ5CwZHu Tph57dgwsQyz83Y5PIifEw+2r7iZOwGf54sGX4fhnXEWnWWGMVegbVsDtkemjZnPlvmN 3CGXg/XC3Atx+8BWCEFxJwN0TS9gxqMlzrelHEcK++Jw4RoHLINYHJADQ6+0cn/hkMTV eHFWB1wTFNeTW9zP5jLqrtjVG5dx8EhPsV9gYhFzzSJC6sicmxZPzD952Ih/9+PPYzkZ IIag== 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=FFCtQU5sSYcakyL0pYyK6CZbXF6VG4/IPn3EqOoScBQ=; b=njJ3a3jR5Dq5JN7V4EogrZxhDVT1/0skIUPj/xXoTU1it6PWRG78+i1KJpHH339KvR oTl4lSW2lAdYMS1Uu1L1ALf5GJxqy29hlzoR4hy7gp6yFA5/TFVfonBOt/XF7HCZr1ua RY+rwL0jvWJm5vtWUnnydgL9/mWjxuXEnjWeO5XysiAT/xEetsonJ/rKZStSppSBE0MQ sl1JRxNaBV2G+YblYTTRCfGkL+cSdyzFHsjio47HqK+Kuc01jMbglTwwmPxVhm9/afeh YV29x0kQcM6oFtN7iFE85RAG4Z7U8tvKI/B/hGgT3b7yVDPuuDbix7Vt0YGWhJ9jlpW2 IHDg== X-Gm-Message-State: APjAAAW0wsKyd9Hlh5FD0DcEqEABFHM/IJpCA6ydQ70ih/hfdwKkarNY 8nMjCfdL/G0gFEguv6zMTlKDPiPM X-Google-Smtp-Source: APXvYqwABklyTTxO1LkkcxWaehjJJvJc92mMugHgTs1JfmaCljr1SVdn3N3uUvR8aUW8F1cG7ujZIQ== X-Received: by 2002:a17:902:f81:: with SMTP id 1mr6893773plz.191.1561668772388; Thu, 27 Jun 2019 13:52:52 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id 2sm3674083pff.174.2019.06.27.13.52.50 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 27 Jun 2019 13:52:51 -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 5/9] usb: dwc3: gadget: introduce cancelled_list Date: Thu, 27 Jun 2019 20:52:36 +0000 Message-Id: <20190627205240.38366-6-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190627205240.38366-1-john.stultz@linaro.org> References: <20190627205240.38366-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 f0c3b08ff7c6..34331a9fb584 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2146,6 +2146,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 Thu Jun 27 20:52:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 167987 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2821988ilk; Thu, 27 Jun 2019 13:52:54 -0700 (PDT) X-Received: by 2002:a17:902:778d:: with SMTP id o13mr7076197pll.82.1561668774203; Thu, 27 Jun 2019 13:52:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561668774; cv=none; d=google.com; s=arc-20160816; b=wFQk4w2JAkarJjOCpD3omGTzy2InSM6Srz3YMFCxJfGQmj77wCHMgZe96D59edIOjE FtWEIvbrDPMZElA4oieBuvfP3eY5Cykb345LOJABldAMluXwN30gOe0NoVc8Kn6fbRYW Y37vfd32inKns/0seSaZ3fmDv85I+IrSzGmWPCHHvYvym9Es5xTPlVsgjWIU3YxTHluw lHX1vd6NbZhcC3o5W1pXBmvIGG2BBoLc+vatPLfSVblcWE5FzKVF4JlK5z3B/II8jR0o 0EKE8CgEj3YpeleiuOAfPujLACIuNxuBJwHgHLpNujQqE//yZ5X3dj99SITyXQYg6u/V S/ew== 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=ZrL274DhNKyTQBw9OhusDzJRVLn3r/FwIe97KUSVcog=; b=LO0n1AjSmWCT1U7v1lNpYIFp2cqRCDmrraqDNGIBTjMHQ7mTMBlrXucrXQFa1O+8KA ZnMbOVvhEh5vq7KhGQA4jVfOZoe1GDTcGhSiaxeV0WPswpxnoiFgbbTc7bScqdYNd70o +OpLtkoUZQP/0waFrC/1b09zNwm8FcNUCv/FWkGjWlYU+vEMFZqLI5r+D3iJi1GRFOyn bQz9Cz0sGpLRumCSdsq4zZ8DyPS3rwwrtphDiL7yL371IlB5tOZxXeOblgK7oq/T66XO 4GTb7EgL7YveqN5P85xQ5Gp5s8+rn6yOAPYYHz7WSZ7Em1JMaZf6rM+dbAf6+lVbL2Y9 Ifyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LijsNOiR; 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 n13sor8043142pjf.14.2019.06.27.13.52.54 for (Google Transport Security); Thu, 27 Jun 2019 13:52:54 -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=LijsNOiR; 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=ZrL274DhNKyTQBw9OhusDzJRVLn3r/FwIe97KUSVcog=; b=LijsNOiRu7AOnbIFYl8i2/9YtZD/HBFXNXyokFi7ArT8pjo4rUhbK7ZABtYNbou5t7 vZwPWaBA/26JvKn/KJqALkNkLyNPIURIWlmMOajizfJxyMyqtZpBg3Cs3SP/a4s4W471 NH/JKDXu9Xjg/AYuN4bjY+33UeTX4fwXjAYuUYb+0ArMMJzWdgcrbVids31C6xdG3cRW GjsQzPsW5g2ZWRDPTaCLM/U2OiBC4uJ17u9EV3uGyVURg1OOumzJy0Y4/9APc5AUQoYk 3a6tr+pEeHEoYwQEe8zvX4DiIEZm6lpJey83CFiQxv7JdnN2qUotZjw9Xd1vUfIKXgcj A3SA== 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=ZrL274DhNKyTQBw9OhusDzJRVLn3r/FwIe97KUSVcog=; b=r7IX/Wm/z3AXww5H47Qi2NglPlAzfn0jgl2zf8s1LEov9p2TSAVhpNddWdnKU6fiZh 2iTPvVHoeTCTlkyper3kp/JwBNTiAQ9cn3O3c4AKuwQmrdRJZZdKFHEKNaZfFXLBGt2/ eU2pUUKhww4T1+xueLuUIC/3xpjWM54BSw9xdMs7CwQ9Qgkqe1IaLeizgmzpydRnOVNo KfzqYCKWosBplh9Vh5tqa937n4cKhbuAs+13Kvc1aQWjAAFi/kMMXNhHDyeDzBkt1Aoj /JhQDn7Q7NwgyuZ8OD/KKKJKWEPOYzILRv8oGKPWx3a3jfkjLqmQcUFDct8QtmVlpYzs 72Ag== X-Gm-Message-State: APjAAAXRaAo24el6ZeZYK9duSnHXVMq875TG2dn4Q9lxb2trnoIB8NTs zbwAumm2U8U37q1r+mhvETEhvHqS X-Google-Smtp-Source: APXvYqwo0ph4DAMPKAKH/MsnyPj2uoZWLuEKCKC099RmQ8ouNVtkjqZJdDaOlT9eegAIdii+wQO9Tg== X-Received: by 2002:a17:90a:8d86:: with SMTP id d6mr8058912pjo.127.1561668773759; Thu, 27 Jun 2019 13:52:53 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id 2sm3674083pff.174.2019.06.27.13.52.52 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 27 Jun 2019 13:52:52 -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 6/9] usb: dwc3: gadget: move requests to cancelled_list Date: Thu, 27 Jun 2019 20:52:37 +0000 Message-Id: <20190627205240.38366-7-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190627205240.38366-1-john.stultz@linaro.org> References: <20190627205240.38366-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 34331a9fb584..25cdce359736 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1366,6 +1366,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) { @@ -1402,8 +1413,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); @@ -1411,7 +1423,6 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, goto out0; } -out1: dwc3_gadget_giveback(dep, req, -ECONNRESET); out0: From patchwork Thu Jun 27 20:52:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 167988 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2822020ilk; Thu, 27 Jun 2019 13:52:56 -0700 (PDT) X-Received: by 2002:a17:90a:bb8b:: with SMTP id v11mr8345638pjr.64.1561668776080; Thu, 27 Jun 2019 13:52:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561668776; cv=none; d=google.com; s=arc-20160816; b=Wk5FWACYk9pUZS6ic+a+It3o9jM7AIN/k/IX9tmpUZwLNJKge+B+31pw/vpNmWKvL3 WOxo77TXSdq0DHjMweqSLrj0Jdsqg1bt7WLY+ctlW1yAU2JTlGRrwzk4dIu6stETNMC0 HbTBenVuJO6hj7rdeEsKbR2utyZlVY85aFTBf83DH7haaKStSgk0eCqxEqBlaV6wJN+t nQu6DTGMUeIpMzPL/+RB7lhDfLYf1vkM4X6QsRoE2Pi1WeHhP96OslCb1Fa9F6rC3zBR qupioqosHo0ZgF9PoTVhFLfFFNvyXG4LqLl7QyUWCZI8YEGAo6XxT3HiW7U/rilpZCb1 xMzQ== 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=sJy5RsZ+XgQxP8NLHGHXPC++ycB1Ut5oAgR2rBDauhI=; b=VR5Y8nZYPyg6RX7in2YEVbkHFyDIXOBcEErmm0eCWdKehL6D7YXQtGMR8ByztRr+Gy y+2fj8vF9zjIcF6QHwsFs4STjMcIRkH3tQY+wivcSpAM8xCiLWHY059vI842TTXKgSgl NEFCt7cH0dC3YGRQovmS8Tdb2sN8dABSsUxrOEGT2qLT4OHHDBtGG6wejZKd683VQtZY FXob2hHZLJvpmGZ33JWywJe8jMfhdIWCsQRJ7SQ2eC2CRHz7/VC9g7Ft8+x2EvAK19gX 15rbtZ02a5JhgF+pPopRZVpZ7rBASAbexm31vLDdP+CD8vb4Moh1RbG4vwF1b60QFyD4 VFvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eV+URhzu; 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 p7sor7642879pjo.4.2019.06.27.13.52.56 for (Google Transport Security); Thu, 27 Jun 2019 13:52:56 -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=eV+URhzu; 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=sJy5RsZ+XgQxP8NLHGHXPC++ycB1Ut5oAgR2rBDauhI=; b=eV+URhzutNlGwIftbtsLHQnZL/iqKcoUJpTwLk6FovaHQF/pihPA4h8aU4Zpny0ymN NqrEyZ9vDESdgjnnCKHLxNAjPNhH2fF7mNaRFVY1JCmUh7QwS4j7MBKU+fVjB+Av1f6m HZumFLQ5tSHeyaGF/unoC3vzkXGwV8/W60N80XgvyOGy4PKAT13CFRMA+TMWolda16Qt VjZ4RJXR9SHAGHPnQBEikUydJCmQXNitcDWkG5SJd0M2rKwrs1aWi+KOm2+F3yoLkSfe UrB2IWO2ozLNTSRqcwVfpjaKM292fnrMcjYqBXw2hKegjPX3X9MuFrl5BU6P8q1zTeaR eZNQ== 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=sJy5RsZ+XgQxP8NLHGHXPC++ycB1Ut5oAgR2rBDauhI=; b=rWK+o9gWvCyon8FI2wKRdjTjE9FpFRAK9NlgD/AiJLUxgZh5Gr7QLLKPrNLeRGF+rz aDiO871L2GzElWkowvBj4VFZtdETV9JTiBKlrjqpxRuZPerYTjC4wSwInZe4iyIMU0MM kSdZDKy5kO+fg7SUvWkmywpR0V6sS0v1WCayVAK0W4ZapnMlXdFcnGRNw5PYc4wp/09p j7XptRYzDonXzYSoAXLe1hmClSm9HX2BUnhP1VXxcfsTxK5tvFYX7EfvLTUgDbeyrj67 xhosYfOQ5NMwitmQQqycCxb9DUnqucmwugbbHaQ4VQ4/n9lsY8siIafzm7eLc1cEOQYR 9NpA== X-Gm-Message-State: APjAAAVXEJkjqUjp7AVB6ReP/cm1+TRjarJh0qJIda8HH/sRFsXlyIcV xhrjqgBhOwEu7luMjkUxKfbDvBoi X-Google-Smtp-Source: APXvYqx6BBy9Nzx+u+U0xZbdLTdsXsNMmWr2PYmfOqM0/uZF8Eo8cbUuQX5EkeX7TpofkKfNfpKylg== X-Received: by 2002:a17:90a:be0a:: with SMTP id a10mr8017668pjs.112.1561668775599; Thu, 27 Jun 2019 13:52:55 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id 2sm3674083pff.174.2019.06.27.13.52.53 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 27 Jun 2019 13:52:54 -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 7/9] usb: dwc3: gadget: remove wait_end_transfer Date: Thu, 27 Jun 2019 20:52:38 +0000 Message-Id: <20190627205240.38366-8-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190627205240.38366-1-john.stultz@linaro.org> References: <20190627205240.38366-1-john.stultz@linaro.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 25cdce359736..879f652c5580 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -640,8 +640,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; @@ -1406,15 +1404,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", @@ -1915,8 +1909,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); @@ -1925,36 +1917,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); @@ -2451,7 +2413,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 Thu Jun 27 20:52:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 167989 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2822054ilk; Thu, 27 Jun 2019 13:52:58 -0700 (PDT) X-Received: by 2002:a17:90a:21ac:: with SMTP id q41mr8562694pjc.31.1561668777996; Thu, 27 Jun 2019 13:52:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561668777; cv=none; d=google.com; s=arc-20160816; b=O3xNO89mzJbg6Ra90GAqioUXOTMNKehCjyhmjjXy65ztzxODxj+i24mkFyFH4LBfxQ gTbPYI4gNeZGxjFLmGuz4Z8ZkWiHwITChS1cLwGwClCFuj6iAzqqQf9zx1RNECUlT9JO fqGn50C0rb8dOQT/jPXoKzZzTZb0UGsOj14GyuKXgy7eU1Q6+FLq48etjkyy8vEnV4th 1/DsSxqWviMS+OLpjxV2zCS+gMc9yPNJ7zA6IK/m63lL4c9juRTE276AuOS1YnJo7Hh3 oqq6GApKZmrA1TuuMC7QZpvcnc0/2obP4ftU8eBktkPa/WJEEUtnxLURCuDLBx4uPciT gwKg== 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=ueb/BBqVPcgcgShNRILhcqgksfTQMKckAnG70UYWi7Y=; b=wZzfd0EAZX3+wOuDq2hboBdP5D/Wc+nNAPc6QbGHHQNqAFiMgspkd4yijdVrW3PtV5 IFPRUKs1gzeTD7ODLNmUDRkFsKKdKbk0g+kRPmkc/AThqZ500yVRbJMNoCjNQPEmDrN4 XjnfFHDPpQQrCrRLO701EfCPf5v2zfDO9duFr7dTCefrvIiKK85aBrQNN+EmUg+4SFt9 3tEmuzMJvFWLCMvsf7/tWDTNp10bf7a1KdxEX7AMrjrn/gghbuIuE1xTe/UJQxGbxUYS k9D2Yf8Ls3WSaBhHAD4BiembFgaTYNBzTHdUoNSkMVwvBZZTkbpFvbjX7nenq/0Iik7s Uk1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YpvV2Bf7; 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 m9sor51514pgq.33.2019.06.27.13.52.57 for (Google Transport Security); Thu, 27 Jun 2019 13:52:57 -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=YpvV2Bf7; 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=ueb/BBqVPcgcgShNRILhcqgksfTQMKckAnG70UYWi7Y=; b=YpvV2Bf75JwXf8zBL791UUdonRQB1s2FnGsM4WUtvTVpxINnBkWjZ071FmocfAawdX NUs7QZyUSMflrdueEkKNZn9NWZ0WFSd0BMoBbgVFI5CNI3Jy/3PqRQG5CiELjJsbTe7n 7ZKZIJxq2tyv7zO25HRedUVCmwi4yQcjKfFA0NDeRjcRQ5wRGMThZDHBuoYYiRYQZL3o ZVaV0DUDHhPPUU7PDFsaVBnfkwLRsHmgJ/s9bDUd8xjY0m/o3hRmWRv9fH/utDBHoYvc li6z6fOj2GinZGhmyoz943Bvp32xwUlZvCpgbV7dtm+ijB9ymVQJABsQzEBldCzBHOu5 jnJQ== 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=ueb/BBqVPcgcgShNRILhcqgksfTQMKckAnG70UYWi7Y=; b=Mg/yuHXS7ONqw+uNSHFa+60mYGjm1tfOZC4TLPuMa/1olPUPAyy8M1Bbx2lNOUDnxP VHJnVIuSC0QoxYEHnDr3RNvETH44noe7pNgdKQ7S7nbNiJNzjM9YN7q7Bftffd3RkG0w fOwZCDd33nn8VSEvFiFhVn5t45O0goInXOLSwP2TL3f9yecdAhrXWD3EiD1QjvdOPOV4 Z0hI5FshdKmonhUXm8ieUS0rmXTzhsoUvkGwttu1LeHRN9ZkfX5xucBd92HIGbo6MBVT qlpzh7m2A1LjkR8nBYvfbOiG8SG7o5Qv4XZl9TwDX+lEXxPZPB4FGIAMSPzUrxTvHXQV lj8Q== X-Gm-Message-State: APjAAAWbLEkmwnzOlrl0SsQu+xnU7gz5F6OSgvHOU/0t+TTshycmnFGC xzZcprQfxcbICTsHqR3ShjsuweCH X-Google-Smtp-Source: APXvYqw6yndLJFqzJcTPdL5U8C6p4mcNBLoGKWs5pKly+0Z18tO3DXGXGcUh3kXtYe8GJ+Y6ng9frA== X-Received: by 2002:a65:6694:: with SMTP id b20mr5506490pgw.155.1561668777440; Thu, 27 Jun 2019 13:52:57 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id 2sm3674083pff.174.2019.06.27.13.52.55 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 27 Jun 2019 13:52:56 -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 8/9] Revert "usb: dwc3: gadget: Clear req->needs_extra_trb flag on cleanup" Date: Thu, 27 Jun 2019 20:52:39 +0000 Message-Id: <20190627205240.38366-9-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190627205240.38366-1-john.stultz@linaro.org> References: <20190627205240.38366-1-john.stultz@linaro.org> This reverts commit 25ad17d692ad54c3c33b2a31e5ce2a82e38de14e, as with other patches backported to -stable, we can now apply the actual upstream commit that matches this. 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 879f652c5580..843586f20572 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 Thu Jun 27 20:52:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 167990 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2822075ilk; Thu, 27 Jun 2019 13:52:59 -0700 (PDT) X-Received: by 2002:a17:902:8d97:: with SMTP id v23mr6801977plo.157.1561668779617; Thu, 27 Jun 2019 13:52:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561668779; cv=none; d=google.com; s=arc-20160816; b=MalhqOIVUkdyPESX2pUiffCA9reaIbbmH/MZuHYQDMDWfbkVnzxfaUGX5LtAmQhcJX /Pr44mOyvFgSuE/F1BPe8Jb4cMRSd0/tM42Y7/z9YqZU5atlgXbiWvGpaC6ljt/BkylQ 56PcgKG9yasvP+XOQvvdW9z/AoTfNOu17J3XtrKx34/gYKAD57I6+ZipZJCAigi/DQUI lrTB4eZ244lrrp/74vbKZLzxBsYcojArXUDpLUlfYcH7HC7NfobehCBHWviLRRsyGKSy P0GlKglvRj3zFTC+q2+ufx17HAzFDdebrqXqrfNYlSHFtd4Nq7JJmIHdxp4/eoJU24i6 Q+lQ== 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=DJRudAcAZNXH2ktZLcWW05FSEYSS+9+cw/N+J58T4tAwGImGG9dUjdhelVsAx80tO3 IV/h/WBKBzUp20E950S1+gpigPBWh+KYMbYVkFY2bBEweJe8v3YNUnMy4+VZB1E8rsKK 2VbgsVbA4NDCcSoGHRKD0pFZCXUAMu+nHBRyDdBL+iLfxKUtbcqtKD6tnieW3buTsjOe MPhHYGQfm9AQCs5UCZBOpyV0e778SQgWusiBT+/Y5E3RyNJtK9Mb47kfTDdGcEM79Eeu +2TCD2iZxnhSLWLeGzstG9GDUgmiGOIbQ4MC5WESR52UYg+TzkIGpyShAhyvidWVI1IO bY/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FT+BOXS8; 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 y16sor4390pfe.48.2019.06.27.13.52.59 for (Google Transport Security); Thu, 27 Jun 2019 13:52:59 -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=FT+BOXS8; 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=FT+BOXS8krhFYzP6qgkGdTRIuN8UEsdd7/J8Rk/TUCvNz5vD+gALlNCjhBRbIyg2+e MhGEv+r6MSWMg0hPYeg+IO7ul1XPK65iNNIVI6Z0n3TbWoWyTiOzVSbZ1TrHf3P5bsll wflv/q/ksLyXrQJQzt13c5gcCn8ChgNlwa8D+06Mp8/blyCxT/DNAUTeVhtYIwNTTRAH 4A1YRmiJzIY8sAIaajfuF2qEu/ZXMnUvTcYbEzmJ6DRI23NNxVHK3EGJZXFDvOONHjVy b/x/iCuPGw6JGjnvJCYoxYs7SzL/j19MXh3Z+y+kfPrn44MA+V+WR3aP1HHbvclQs3GO cEXw== 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=TrPMB6cwAEmth6ADqHC1UUyej6ql1MVJKpJ9k0ZP+Y+lVOIP2ZtR2ncqUe63RWIqZ8 Bv9srVSVDG5gTTf0LjSXLCqoyeV0AXxSzLwaykEAPHIk82bE8rtdggL+O62nlHMn9PiA m5FIxrKO2tXe0SckEpeAfkolmlRpFQqThcx06XDuyD/QOMYWxfGoBZYWMAkeoX9/6g8G i5+JZ5edIbNIz9HZNeUPgN0O4XT+tnz0ndIF5ia6ft6Q+wwMtTB9eBKx8ZWZ7cUhUN+H GT49OdyF0/R/Sv1XtAVBO2lHZKkmBpsqYofMXAiXz8EBB2Hevifunhv9DKETMxl48Uc/ c9Lw== X-Gm-Message-State: APjAAAXPE2DXGn83Q1MbTyiuqPSziVOzu2unKmOV3xXw4ve1JPOk9uP3 AMu8HU8x7+XSWeUOm4LnpcK9xO5w X-Google-Smtp-Source: APXvYqyBb+wX2HfJ0wt7W/TgcNxknQdoGdW16YqdoS56BW7Ng+PgtitplGMtO7YyOovSzLxYZ3UKug== X-Received: by 2002:a65:500d:: with SMTP id f13mr5539367pgo.151.1561668779150; Thu, 27 Jun 2019 13:52:59 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id 2sm3674083pff.174.2019.06.27.13.52.57 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 27 Jun 2019 13:52:58 -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 9/9] usb: dwc3: gadget: Clear req->needs_extra_trb flag on cleanup Date: Thu, 27 Jun 2019 20:52:40 +0000 Message-Id: <20190627205240.38366-10-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190627205240.38366-1-john.stultz@linaro.org> References: <20190627205240.38366-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;