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: 11020523 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 B82C576 for ; Thu, 27 Jun 2019 20:52:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF1EE28703 for ; Thu, 27 Jun 2019 20:52:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2CED2870D; Thu, 27 Jun 2019 20:52:49 +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 7F98628703 for ; Thu, 27 Jun 2019 20:52:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726476AbfF0Uwr (ORCPT ); Thu, 27 Jun 2019 16:52:47 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:39549 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726443AbfF0Uwr (ORCPT ); Thu, 27 Jun 2019 16:52:47 -0400 Received: by mail-pf1-f194.google.com with SMTP id j2so1810911pfe.6 for ; Thu, 27 Jun 2019 13:52:46 -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=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=nDv3qdhT+LKxyin3TRcavG+MAGGAgX0p+AzcTHdEcHENhtKupVdadbVN9q8E8Mo/p8 belg1U93isPzHNUVkCtGa6bFk7wfzG4p5VZJ8m5Qps/DF6yG7i3dLe+r1zD64e2E6IzT MdYa+2m47Al8VJdnNppHsR2z4SAgJItBAkrpNosgjk+wSgMpbfI9TWZcDw/1TEyE+20R ixhJf2sdJlYFiC7CWD+oXJiyhIUcYSr9u7g1S7yGwWJlYA1o07c+5Zcn/rrlHUh8X9IU VZ8XUvYdGUePO+tSd+Bk8gsMVkYidIl3Mzu47yrH6727C2KCg+I32lkIXI5jZFXtAdP6 VFmg== X-Gm-Message-State: APjAAAVpxYJFeeDwAZxT8wAsZrAJMm4aGskosjzGiHMUHeWztTAp6tI+ ghO3vH+42rslHxyZDJEAqmoB8Q== 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) 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> 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 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: 11020525 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 4415314C0 for ; Thu, 27 Jun 2019 20:52:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C04B28703 for ; Thu, 27 Jun 2019 20:52:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2FFEC2870D; Thu, 27 Jun 2019 20:52:50 +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 BE19B2870F for ; Thu, 27 Jun 2019 20:52:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726500AbfF0Uws (ORCPT ); Thu, 27 Jun 2019 16:52:48 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:45441 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726480AbfF0Uws (ORCPT ); Thu, 27 Jun 2019 16:52:48 -0400 Received: by mail-pf1-f195.google.com with SMTP id r1so1795883pfq.12 for ; Thu, 27 Jun 2019 13:52:48 -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=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=ciNPvLgHhOZcJ4TnKYUZxZZfMKjxcENp1XuKGjHe2bneh2wJkTC8Qw0y4cIBTxpGF4 dnpttbkrK7QBfCJQuhD8PWJrQ7YCeS5ELqANi9seWctHBLRlSWAMMzufzblwgnf6K/C5 NtQ32TDlbsglnpHYB6Qt7tOztfgf4n4nVuMKmaR+D1ZnnO/P4Mr5M4u/mBYTXNtq38GP xn5yxZgO+nbU7RdRPLyEkMXfjpHRDkG/y47+BLUHCCelaFdDmLNBDmE0aMhDy3V1k5KI G9hyKesLVDTa1NHe1skRIxGInibJbZRiF6X87VtU57biVouWxfMcSFPKgbgC6RPanSE/ ikSQ== X-Gm-Message-State: APjAAAUqsh8GRni/l7EGiQsMohgDSNpQIErlb+DQqqbF2Ll0G7TmnWRQ +cPZYnkK5Gzch8bif2bDEbEC0g== 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) 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> 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 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: 11020527 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 D73A314C0 for ; Thu, 27 Jun 2019 20:52:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE55128703 for ; Thu, 27 Jun 2019 20:52:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2CCF2870D; Thu, 27 Jun 2019 20:52:51 +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 688E728703 for ; Thu, 27 Jun 2019 20:52:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726506AbfF0Uwu (ORCPT ); Thu, 27 Jun 2019 16:52:50 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:38148 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726480AbfF0Uwu (ORCPT ); Thu, 27 Jun 2019 16:52:50 -0400 Received: by mail-pg1-f193.google.com with SMTP id z75so1551447pgz.5 for ; Thu, 27 Jun 2019 13:52:49 -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=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=ZY/jtwDz6+40ylHYMjjBJ+FPn90nPqahYtZwN0rAhMJdyQziLU/kD57eVXKu88tY7a s8a4YsX7Wqp6BzUZGwBNxY7h74nIeJDCk2gpKzo+F4fss15rbzGsJDvf0cHXfUBU5aiX xVlYp1P2LYtnCiWqwByVCPJKbo9Su7QeF3ONLiLz5VJB+FEhX4kolRmMQi3P+QSQJ6te az5gdXfua5Ee+IS/RvUVKzRZUjTP0A+fVJHhFqqQGn3JSNU+S0c2LmQb/GFGzKfDa4FQ jgSMrQi8UQ6JlRpxpBzbNvEFGd4GSYe8vGEOvQDKTEIUEF82ULM8WrZ70FFWAhmuj3F3 wtEg== X-Gm-Message-State: APjAAAVWxscfGKIeV7vkw9MthdVLER7RSJvdkY/+GL5I3F4X0eynWtWM ceISTVDcqhYmObicEE0HA4bQ4Q== 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) 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> 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 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:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 11020529 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 5ACF476 for ; Thu, 27 Jun 2019 20:52:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 518CF28703 for ; Thu, 27 Jun 2019 20:52:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45E382870D; Thu, 27 Jun 2019 20:52:53 +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 C1C2728703 for ; Thu, 27 Jun 2019 20:52:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726514AbfF0Uwv (ORCPT ); Thu, 27 Jun 2019 16:52:51 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:40169 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726505AbfF0Uwv (ORCPT ); Thu, 27 Jun 2019 16:52:51 -0400 Received: by mail-pf1-f196.google.com with SMTP id p184so1809944pfp.7 for ; Thu, 27 Jun 2019 13:52:51 -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=x0T4yaPnaskEaM5/BDitZIdztqXyQmXKds/Qu7Ooum4=; b=UXhD5+/rbf+0Ef2XiMOaD9wCyvl3rZCSpx1VoptGkl6ryBZo1q+GfzSeOEJULx0nCa +gR/ZcO6K7lQG9MjfnnYIcMdVoWYO/uL2ogdcCAmQyVXTdP2wcgmd2GE6v4JOr9BlkAp E+GRzA7URfEX8++kQS4hD0hJ2X181NlZE57h6nkmuSaJ3iJAxWcojAALoA1MVNxAw3eL kd94qFDKj7mm9/zOo8RCY50KU56Ts3sf2Kim/dvI91i6RPwHPhyQTjwX27i77boJGSmR 8EcsZ6avuizzAIh3YT07I7f2YEDDn3/AfMgTE/x3MTcpXo3H32iQbhpp989SPBBqfX4u 1WNg== 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=x0T4yaPnaskEaM5/BDitZIdztqXyQmXKds/Qu7Ooum4=; b=YNhS+9c0L8d6pbCp9o8kB+FuXFdDWx4B0/n0AzILrxPY1iFVpJQMYDzYGMlqQe7kPQ CaJQs8Oyl12rNZDJL+tFQ0BEH9WVzSZXu9HtlKT1om1kBMrpaRFUMxth01xvoG/waNaH FyLqB5z9nIJpy2Veo578qAMgciAu5n2V4rxRZUh4k67j0m1tyYmGe9oaIsL/Eq9+/mfj PmS4kXKeiaIUNJReJ1EtEbN7ct3VnzYvxV3zwxYLSYgO4NEl/ninUzQ5w1+sT+wQtFsq b6FM47asiKUp6bidDs9XeRIoZtlr6QkfJJ8Q51voC7tof8rwRL2kKM56sY7LQrv9zVbS JJGw== X-Gm-Message-State: APjAAAWV1XKCWrqPZZuAuRO0clxpBXazljalC+fnAUdv09DzvEHOHRBH Ap+HIH+7rxHiqnUvyK0QiEh0wg== X-Google-Smtp-Source: APXvYqxR2nDJk9Mq/lm/Mf73r1h7BoL1EPPnnmuw7r56047wKZ4k09pvq6vWz7DfOEPZWZpv6nCChQ== X-Received: by 2002:a17:90a:1c17:: with SMTP id s23mr8537488pjs.108.1561668770524; Thu, 27 Jun 2019 13:52:50 -0700 (PDT) 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.49 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 27 Jun 2019 13:52:49 -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 4/9] usb: dwc3: gadget: extract dwc3_gadget_ep_skip_trbs() Date: Thu, 27 Jun 2019 20:52:35 +0000 Message-Id: <20190627205240.38366-5-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> 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 cb6dfea5d5e7..f0c3b08ff7c6 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1343,6 +1343,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) { @@ -1370,38 +1393,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); @@ -1409,13 +1402,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 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: 11020531 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 6550176 for ; Thu, 27 Jun 2019 20:52:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C8FA28703 for ; Thu, 27 Jun 2019 20:52:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 510FE2870D; Thu, 27 Jun 2019 20:52:55 +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 D38FE28703 for ; Thu, 27 Jun 2019 20:52:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726524AbfF0Uwx (ORCPT ); Thu, 27 Jun 2019 16:52:53 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:43781 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726520AbfF0Uwx (ORCPT ); Thu, 27 Jun 2019 16:52:53 -0400 Received: by mail-pl1-f194.google.com with SMTP id cl9so1913384plb.10 for ; Thu, 27 Jun 2019 13:52:52 -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=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=L+UmqMqIWvju0bmJ6LTsC5PQjfdjXa0ZASEQN2MCVtbQMmrHsS8tcoFLaLoFWzTxvK j3Y44TJirTIsRwNDYTvSIMqSAPKQn6yBVIT9YOC0eoP8pfd6b0YAXL3o91GG10tj/hnm SZrJL79/TR58jVw0DrdoWeCevDrW5zs5EoixFMZ+uD24IFeblvVbakOAfp9LIpBYZ0ci 3ZGTTm4qfs5bDxN76AOjzL4xVlogIxiI6u6bHe9Au8/HraOCR+UhiMO90slt3dTQWEo2 iR7do2fLz+7CvkFy2cS2X+eGnu3WU4is1PuQJraaVMu/sCCMESN2N37LdcFEw9lncGOI ifJA== X-Gm-Message-State: APjAAAXpwF/8svwFeGzfbTZeReP3xkLjGGq+VjMmLQ3zLF0e5FllTEEH Qb7SDvVbZkOO+JdIO1GniU5qdQ== 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) 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> 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 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: 11020533 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 3389076 for ; Thu, 27 Jun 2019 20:52:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2BB7C28703 for ; Thu, 27 Jun 2019 20:52:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 203B62870D; Thu, 27 Jun 2019 20:52:56 +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 BEBC228703 for ; Thu, 27 Jun 2019 20:52:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726542AbfF0Uwz (ORCPT ); Thu, 27 Jun 2019 16:52:55 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:34613 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726508AbfF0Uwy (ORCPT ); Thu, 27 Jun 2019 16:52:54 -0400 Received: by mail-pg1-f196.google.com with SMTP id p10so1558310pgn.1 for ; Thu, 27 Jun 2019 13:52:54 -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=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=uOjaAXjwjOFkrM03+wSsSXkjjcIvIekFqTiiTCuPbI3J2S6qv/f6cUK5Tuj0soSu0U HAST9JIDRngXZd3dh4VSTuURwatOvzDMldscjUnI4USvRxSFbSbTRv5frw2902UgIoiN bmZvJFSJfL8BCSW65hd5moNdfMkgpqPkSC72qDlonAVN1tVzffquvYPWLEhqPraqZnVr cwxiBEvuM+46aU73RUFyTFc2zVK6mggIv3FsmUVLcXvsvnqWi5PDxSAPNlAoasY2fD4v jNQDW+u8EGmtrGTAHk8GVJQ8iIDKeV8vBqX3ENRPidZPQFQzYYI8RSPKPKUucibGBvSY hbhg== X-Gm-Message-State: APjAAAUCY7DuhD+YEXjsIuXLj3RNeX1W3Ih5SYd3e1AVK50JprHN+xwv YIsOuH4qbfUevBzXE358VKeEBw== 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) 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> 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 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: 11020535 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 2CF8176 for ; Thu, 27 Jun 2019 20:52:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24A6328703 for ; Thu, 27 Jun 2019 20:52:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 18E6A2870D; Thu, 27 Jun 2019 20:52:58 +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 9DDFA28703 for ; Thu, 27 Jun 2019 20:52:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726550AbfF0Uw5 (ORCPT ); Thu, 27 Jun 2019 16:52:57 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:35986 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726525AbfF0Uw4 (ORCPT ); Thu, 27 Jun 2019 16:52:56 -0400 Received: by mail-pf1-f195.google.com with SMTP id r7so1820201pfl.3 for ; Thu, 27 Jun 2019 13:52:56 -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=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=sGQUNh/u3aNq839YDXcicVIm+faWRrCZOb80z1W/gnCkpA/6SNdFyIXH8OFDe7onuD EvACihG/MP0FhtsgdI1Jfe3J2EtfIeJN7RPegvo94QQgaFI9JCi+kD3ao3/BW4PPVoQv 93C6FouxhuRnXb4zproDU4V5tRpcb2fohZAzZD/o2zDs2KkBeWbbAKGWWWf4CzRHCcf0 Q/ykX6Y7yVNEleOLGnjtbqsOZmycmoPjhl7nWjGA36Xn1xFdLpfvT40/ejcidEfndgfK gXFoq3wPA+Wauwf0A0JOipGD3zFja/so6vLKzs69LN1tno3a/UrKnad6xR2x4idCf36r 20sw== X-Gm-Message-State: APjAAAWmRHsy6N0FZdNhNm7jzVE84GEAbAH2Fw4q53bxgywCSf9Q4hqQ TBxNWy/6IrGc5PMxmPgSCxikQg== 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) 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> 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 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: 11020537 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 C67E914C0 for ; Thu, 27 Jun 2019 20:52:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE32C28703 for ; Thu, 27 Jun 2019 20:52:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B239B2870D; Thu, 27 Jun 2019 20:52:59 +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 58FC128703 for ; Thu, 27 Jun 2019 20:52:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726558AbfF0Uw6 (ORCPT ); Thu, 27 Jun 2019 16:52:58 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:45493 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726543AbfF0Uw6 (ORCPT ); Thu, 27 Jun 2019 16:52:58 -0400 Received: by mail-pg1-f195.google.com with SMTP id z19so1535951pgl.12 for ; Thu, 27 Jun 2019 13:52:58 -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=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=lO68dOblE7i68IJDn2Cej1Rp4U8vG3FxoW5/ZN6NPs59MZdLrYjCcEcQx0AazMQ6ku Ogbo4+6jU8AM5YM/7jevCxB8Sq/NQjMMZBifbzXvgM4w7eylgHcqoybzhzlpJiHW39HG tx0XX2KW/tsnTAx8rBfnq+hOxfiRAEbzkHE8C2sLEEqEzAQTEVBy6d5X4Esf6sgPas0N T1VYLWKTUZ3ttnSCJoNmbBy7hsakj+5RLaapxpMGdR/imUGpfqgivB44GVjaIvG4TNoC qvOXULrJgCSZ3enNzYvviLxsAQQp9zNOYJLALyycJOTBfKw7htlBMlchuJDgF43KLiez Sn8Q== X-Gm-Message-State: APjAAAXda++jtMWnaUX70X7saMfl3++2cGFUGBQNyKANDxKw4bx4XYny Dxv6y2Zks2+uv0A7NP/JpWtm3mUjOos= 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) 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> 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 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(-) 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: 11020539 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 8D8C114C0 for ; Thu, 27 Jun 2019 20:53:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 845BB28703 for ; Thu, 27 Jun 2019 20:53:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7875F2870D; Thu, 27 Jun 2019 20:53:01 +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 1663928703 for ; Thu, 27 Jun 2019 20:53:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726563AbfF0UxA (ORCPT ); Thu, 27 Jun 2019 16:53:00 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:39813 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726553AbfF0UxA (ORCPT ); Thu, 27 Jun 2019 16:53:00 -0400 Received: by mail-pg1-f194.google.com with SMTP id 196so1550876pgc.6 for ; Thu, 27 Jun 2019 13:52:59 -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=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=iOwOb6ciYPC56aMTPxUUEKQgK7b+upQUqicxi8ipkWvz4xOU/ZRvJRFxy5TFLMZ+cA YAljmKkcYQ5/5p7+l6p/t4UFZ5h1/DbDY08dXxxxW522Ap2cHjg8kCqY3E2Qyp0/iT/b obKBQHb2PTASl0kdhf+T5dzdikt8itI9Y0XHohWHxVAGEDuuIYHilT+JQJ0YL6M0nwQG AtVWjLQmsofCxMRto/hsOEMwJ0bPzC48QX86FY/NS6MDujsizuL4oKCjlnHVPeAExKpQ QpSZOkxgaN+3Y0WOftYAZ9dn8Vnu/Taq4PuFPmibxIaSp5BMDI8TWNSpBb0VJPmKqdK9 IepQ== X-Gm-Message-State: APjAAAWM+4OvX07/0xRK8kJlvoclh7mG7Mt9LNXATmxIdLjdpWjtBaMo jLvBvpmoNZgmYXbF4zeazxz/FA== 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) 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> 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;