From patchwork Thu Sep 24 08:21:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 258434 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9340C4346E for ; Thu, 24 Sep 2020 08:21:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 530EB221EB for ; Thu, 24 Sep 2020 08:21:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="Fk0qmA2S" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727235AbgIXIVT (ORCPT ); Thu, 24 Sep 2020 04:21:19 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:40338 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727089AbgIXIVT (ORCPT ); Thu, 24 Sep 2020 04:21:19 -0400 Received: from mailhost.synopsys.com (sv2-mailhost1.synopsys.com [10.205.2.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 7B0EB402DC; Thu, 24 Sep 2020 08:21:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1600935679; bh=xTLmBPtKTdMjcXU+24f4RxHnyGuBb7ByOH3+djITM4M=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=Fk0qmA2SI5H2OzeZtwg002JHWcNdwMadM0fT+6RKH2amYgVPvyFRHMZ9j2SEApSnh YZllRJBccU3KbHeinpcztCqjrBPY4WwpycGh8imhZ57sfq0mSSmjELIEOMrHlA/jmI d06NT0sC3C7sHN7DXei9XeMA2P90vVW741vfAwXte8h0Yw+2t6v+kbBrqsyLTFfgBf fZq92NPNsL60Sr5YDfB5j3ChZueOEUSuOcyq7EeF4hegDafqLf78uWZgbTm8cXdZNE 2pkTO2eqbHRSDqdhYCQWSpHHuEIz/j2yI5CAaPDEKJb7QObCvOY9FrYWqAltVz0B8G 3HCvZKhKGzKtg== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id 63D1EA0096; Thu, 24 Sep 2020 08:21:18 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Thu, 24 Sep 2020 01:21:18 -0700 Date: Thu, 24 Sep 2020 01:21:18 -0700 Message-Id: <290cbf2ba0fee13ba37cf934bf413795d4bd9a04.1600935293.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 01/10] usb: dwc3: gadget: Check MPS of the request length To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org Cc: John Youn , stable@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org When preparing for SG, not all the entries are prepared at once. When resume, don't use the remaining request length to calculate for MPS alignment. Use the entire request->length to do that. Cc: stable@vger.kernel.org Fixes: 5d187c0454ef ("usb: dwc3: gadget: Don't setup more than requested") Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index cb19d682bbac..44351078f833 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1098,6 +1098,8 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, struct scatterlist *s; int i; unsigned int length = req->request.length; + unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc); + unsigned int rem = length % maxp; unsigned int remaining = req->request.num_mapped_sgs - req->num_queued_sgs; @@ -1109,8 +1111,6 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, length -= sg_dma_len(s); for_each_sg(sg, s, remaining, i) { - unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc); - unsigned int rem = length % maxp; unsigned int trb_length; unsigned int chain = true; From patchwork Thu Sep 24 08:21:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 297523 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 479DBC4346E for ; Thu, 24 Sep 2020 08:21:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EFD3723772 for ; Thu, 24 Sep 2020 08:21:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="bF1SZmB3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727264AbgIXIV2 (ORCPT ); Thu, 24 Sep 2020 04:21:28 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:40346 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727265AbgIXIV0 (ORCPT ); Thu, 24 Sep 2020 04:21:26 -0400 Received: from mailhost.synopsys.com (sv2-mailhost1.synopsys.com [10.205.2.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 8F8DC402EF; Thu, 24 Sep 2020 08:21:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1600935685; bh=bpZOcgnHxr2qnnoKk0alXeL6UkN9hAC8Nf65rvQ7bQU=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=bF1SZmB35vHaQjR6yUV7hgQ9o1glc3W4ld1XiU9tbJSGOFXkF4FL7u1ZWeVzHC+Cf ebHbnAUiziY4i7/TXBD6vVteq0utAh9kFhC/nAmkUCWa/6EiFljn+NcRGQdfSD3W3d l7V+DdsyATfBDReKKNasmBC7mOMUrAdWWaTyOCqenXDyboUPyZuCoIubYMH+8ji28n Bv9WPKFNczv9ItxBMdFbrayRHgDGeMbvFdf8fAKARuTzfXPY88wyHeRtjd9NuhHV+J 4zRiWdmCgFBjzi7kCoIzFt8sPjhTznQ1zHIMb6kxk/AIh5l+pid55JySbc7rLX1/jl edFXpQyvDTPVQ== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id 782D7A0096; Thu, 24 Sep 2020 08:21:24 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Thu, 24 Sep 2020 01:21:24 -0700 Date: Thu, 24 Sep 2020 01:21:24 -0700 Message-Id: <326a4b8aa53cd427eec36678c2410c5698b89a13.1600935293.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 02/10] usb: dwc3: gadget: Reclaim extra TRBs after request completion To: Felipe Balbi , Greg Kroah-Hartman , Thinh.Nguyen@synopsys.com, linux-usb@vger.kernel.org Cc: John Youn , stable@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org An SG request may be partially completed (due to no available TRBs). Don't reclaim extra TRBs and clear the needs_extra_trb flag until the request is fully completed. Otherwise, the driver will reclaim the wrong TRB. Cc: stable@vger.kernel.org Fixes: 1f512119a08c ("usb: dwc3: gadget: add remaining sg entries to ring") Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 44351078f833..6017263929f3 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2738,6 +2738,11 @@ static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep, ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event, status); + req->request.actual = req->request.length - req->remaining; + + if (!dwc3_gadget_ep_request_completed(req)) + goto out; + if (req->needs_extra_trb) { unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc); @@ -2753,11 +2758,6 @@ static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep, req->needs_extra_trb = false; } - req->request.actual = req->request.length - req->remaining; - - if (!dwc3_gadget_ep_request_completed(req)) - goto out; - dwc3_gadget_giveback(dep, req, status); out: From patchwork Thu Sep 24 08:21:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 258433 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1264C2D0E2 for ; Thu, 24 Sep 2020 08:21:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4B7CF23772 for ; Thu, 24 Sep 2020 08:21:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="bTxvw80A" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727268AbgIXIVc (ORCPT ); Thu, 24 Sep 2020 04:21:32 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:40364 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727265AbgIXIVc (ORCPT ); Thu, 24 Sep 2020 04:21:32 -0400 Received: from mailhost.synopsys.com (sv2-mailhost2.synopsys.com [10.205.2.134]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 08BAE401AA; Thu, 24 Sep 2020 08:21:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1600935692; bh=dqHUPplraHZeVjkJ+HRF3MCQmDTuBVDEFzE0+gIxUAo=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=bTxvw80ALmkQMvRoZbEf3yIYIytqCGFscJ9gDC9Yo67cfMELx+8S8sSgdNG4eRvL4 UsVC9nZzngHUlBCyraf+0plTYfzZ2ZHQrSUlMJrrBlBLogHp2Z8I0PqPwdbQ7Ily5r +tSxhcPWTlY2MUDZxi7aeoE+URJx/pNiVEndQMKWiVPF9+Yccyfe6B9CVVB2wLbUjv syqREJ6+0w05E1NojwnA4rkj7/8PQmO6dxqorXer041VM8Y3pcXDekhpM0noaB70r3 VqW4NZ9c8IewCSRoe+lKhUdqfckEeU96WM7840qHIo1k4leQBGOukPXx294R/SeJ2u EVwE7CrKJUimw== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id A6D59A0099; Thu, 24 Sep 2020 08:21:30 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Thu, 24 Sep 2020 01:21:30 -0700 Date: Thu, 24 Sep 2020 01:21:30 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 03/10] usb: dwc3: gadget: Refactor preparing extra TRB To: Felipe Balbi , Greg Kroah-Hartman , Thinh.Nguyen@synopsys.com, linux-usb@vger.kernel.org Cc: John Youn Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org When the driver prepares the extra TRB, it uses bounce buffer. If we just add a new parameter to dwc3_prepare_one_trb() to indicate this, then we can refactor and simplify the driver quite a bit. dwc3_prepare_one_trb() also checks if a request had been moved to the started list. This is a prerequisite to subsequence patches improving the handling of extra TRBs. Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 93 +++++++++++---------------------------- 1 file changed, 25 insertions(+), 68 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 6017263929f3..c0309ad34d28 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1060,10 +1060,11 @@ static void __dwc3_prepare_one_trb(struct dwc3_ep *dep, struct dwc3_trb *trb, * @trb_length: buffer size of the TRB * @chain: should this TRB be chained to the next? * @node: only for isochronous endpoints. First TRB needs different type. + * @use_bounce_buffer: set to use bounce buffer */ static void dwc3_prepare_one_trb(struct dwc3_ep *dep, struct dwc3_request *req, unsigned int trb_length, - unsigned int chain, unsigned int node) + unsigned int chain, unsigned int node, bool use_bounce_buffer) { struct dwc3_trb *trb; dma_addr_t dma; @@ -1072,7 +1073,9 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep, unsigned int no_interrupt = req->request.no_interrupt; unsigned int is_last = req->request.is_last; - if (req->request.num_sgs > 0) + if (use_bounce_buffer) + dma = dep->dwc->bounce_addr; + else if (req->request.num_sgs > 0) dma = sg_dma_address(req->start_sg); else dma = req->request.dma; @@ -1129,56 +1132,35 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, chain = false; if (rem && usb_endpoint_dir_out(dep->endpoint.desc) && !chain) { - struct dwc3 *dwc = dep->dwc; - struct dwc3_trb *trb; - req->needs_extra_trb = true; /* prepare normal TRB */ - dwc3_prepare_one_trb(dep, req, trb_length, true, i); + dwc3_prepare_one_trb(dep, req, trb_length, + true, i, false); /* 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, - req->request.no_interrupt, - req->request.is_last); + dwc3_prepare_one_trb(dep, req, maxp - rem, + false, 1, true); } else if (req->request.zero && req->request.length && !usb_endpoint_xfer_isoc(dep->endpoint.desc) && !rem && !chain) { - struct dwc3 *dwc = dep->dwc; - struct dwc3_trb *trb; - req->needs_extra_trb = true; /* Prepare normal TRB */ - dwc3_prepare_one_trb(dep, req, trb_length, true, i); + dwc3_prepare_one_trb(dep, req, trb_length, + true, i, false); /* 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, - !req->direction, 1, - req->request.stream_id, - req->request.short_not_ok, - req->request.no_interrupt, - req->request.is_last); + dwc3_prepare_one_trb(dep, req, 0, + !req->direction, 1, true); /* Prepare one more TRB to handle MPS alignment */ - if (!req->direction) { - trb = &dep->trb_pool[dep->trb_enqueue]; - req->num_trbs++; - __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr, maxp, - false, 1, req->request.stream_id, - req->request.short_not_ok, - req->request.no_interrupt, - req->request.is_last); - } + if (!req->direction) + dwc3_prepare_one_trb(dep, req, maxp, + false, 1, true); } else { - dwc3_prepare_one_trb(dep, req, trb_length, chain, i); + dwc3_prepare_one_trb(dep, req, trb_length, + chain, i, false); } /* @@ -1216,54 +1198,29 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, unsigned int rem = length % maxp; if ((!length || rem) && usb_endpoint_dir_out(dep->endpoint.desc)) { - struct dwc3 *dwc = dep->dwc; - struct dwc3_trb *trb; - req->needs_extra_trb = true; /* prepare normal TRB */ - dwc3_prepare_one_trb(dep, req, length, true, 0); + dwc3_prepare_one_trb(dep, req, length, true, 0, false); /* 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, - req->request.no_interrupt, - req->request.is_last); + dwc3_prepare_one_trb(dep, req, maxp - rem, false, 1, true); } else if (req->request.zero && req->request.length && !usb_endpoint_xfer_isoc(dep->endpoint.desc) && (IS_ALIGNED(req->request.length, maxp))) { - struct dwc3 *dwc = dep->dwc; - struct dwc3_trb *trb; - req->needs_extra_trb = true; /* prepare normal TRB */ - dwc3_prepare_one_trb(dep, req, length, true, 0); + dwc3_prepare_one_trb(dep, req, length, true, 0, false); /* 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, - !req->direction, 1, req->request.stream_id, - req->request.short_not_ok, - req->request.no_interrupt, - req->request.is_last); + dwc3_prepare_one_trb(dep, req, 0, !req->direction, 1, true); /* Prepare one more TRB to handle MPS alignment for OUT */ - if (!req->direction) { - trb = &dep->trb_pool[dep->trb_enqueue]; - req->num_trbs++; - __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr, maxp, - false, 1, req->request.stream_id, - req->request.short_not_ok, - req->request.no_interrupt, - req->request.is_last); - } + if (!req->direction) + dwc3_prepare_one_trb(dep, req, maxp, false, 1, true); } else { - dwc3_prepare_one_trb(dep, req, length, false, 0); + dwc3_prepare_one_trb(dep, req, length, false, 0, false); } } From patchwork Thu Sep 24 08:21:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 297522 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A116EC4346E for ; Thu, 24 Sep 2020 08:21:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4DD17221EB for ; Thu, 24 Sep 2020 08:21:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="ZN18XPz1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727271AbgIXIVi (ORCPT ); Thu, 24 Sep 2020 04:21:38 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:40370 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727244AbgIXIVi (ORCPT ); Thu, 24 Sep 2020 04:21:38 -0400 Received: from mailhost.synopsys.com (sv2-mailhost1.synopsys.com [10.205.2.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 1C645402F6; Thu, 24 Sep 2020 08:21:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1600935698; bh=3K3pF/0A9zBNNE1uqiXkkWwBDyKeN4kKvcR4MyEa+yM=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=ZN18XPz1JsfpWgeU2Mp3HhnmGa11neFTtE9bepclssarnB0ot6CwtOgnR2J2xMOk9 ccajwCkWDjSrrRYd59sbf0NmCATbiZsvE94EN67ogei4qE30/SFADVEfp93oOHtIzl lG009urWpHSai3wEzjvBongC7Ly3hrMDLJ2rVOFsfsGHvJL+0FkXnXFMAtj/H4lyn0 6A5wZFHJf46mq5luJg7CfkKUD69aGWJnkzWNfNjAbmtxf4ozwpahKTZhPnupMinVxB 77ptwu6beoQxw5PV11ePfgFM/8qnu947Dq0pw5U02wfSgEvbUuJgLpX5vdL0uxOWHC mvQhV3nDKM/SQ== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id 06415A0096; Thu, 24 Sep 2020 08:21:37 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Thu, 24 Sep 2020 01:21:36 -0700 Date: Thu, 24 Sep 2020 01:21:36 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 04/10] usb: dwc3: gadget: Improve TRB ZLP setup To: Felipe Balbi , Greg Kroah-Hartman , Thinh.Nguyen@synopsys.com, linux-usb@vger.kernel.org Cc: John Youn Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org For OUT requests that requires extra TRBs for ZLP. We don't need to prepare the 0-length TRB and simply prepare the MPS size TRB. This reduces 1 TRB needed to prepare for ZLP. Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 50 ++++++++++++++------------------------- 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index c0309ad34d28..e49930a7acae 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1132,11 +1132,12 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, chain = false; if (rem && usb_endpoint_dir_out(dep->endpoint.desc) && !chain) { - req->needs_extra_trb = true; - /* prepare normal TRB */ - dwc3_prepare_one_trb(dep, req, trb_length, + if (req->request.length) { + req->needs_extra_trb = true; + dwc3_prepare_one_trb(dep, req, trb_length, true, i, false); + } /* Now prepare one extra TRB to align transfer size */ dwc3_prepare_one_trb(dep, req, maxp - rem, @@ -1151,13 +1152,9 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, true, i, false); /* Prepare one extra TRB to handle ZLP */ - dwc3_prepare_one_trb(dep, req, 0, - !req->direction, 1, true); - - /* Prepare one more TRB to handle MPS alignment */ - if (!req->direction) - dwc3_prepare_one_trb(dep, req, maxp, - false, 1, true); + dwc3_prepare_one_trb(dep, req, + req->direction ? 0 : maxp, + false, 1, true); } else { dwc3_prepare_one_trb(dep, req, trb_length, chain, i, false); @@ -1198,10 +1195,11 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, unsigned int rem = length % maxp; if ((!length || rem) && usb_endpoint_dir_out(dep->endpoint.desc)) { - req->needs_extra_trb = true; - /* prepare normal TRB */ - dwc3_prepare_one_trb(dep, req, length, true, 0, false); + if (req->request.length) { + req->needs_extra_trb = true; + dwc3_prepare_one_trb(dep, req, length, true, 0, false); + } /* Now prepare one extra TRB to align transfer size */ dwc3_prepare_one_trb(dep, req, maxp - rem, false, 1, true); @@ -1214,11 +1212,8 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, dwc3_prepare_one_trb(dep, req, length, true, 0, false); /* Prepare one extra TRB to handle ZLP */ - dwc3_prepare_one_trb(dep, req, 0, !req->direction, 1, true); - - /* Prepare one more TRB to handle MPS alignment for OUT */ - if (!req->direction) - dwc3_prepare_one_trb(dep, req, maxp, false, 1, true); + dwc3_prepare_one_trb(dep, req, req->direction ? 0 : maxp, + false, 1, true); } else { dwc3_prepare_one_trb(dep, req, length, false, 0, false); } @@ -2615,12 +2610,12 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct dwc3_ep *dep, } /* - * If we're dealing with unaligned size OUT transfer, we will be left - * with one TRB pending in the ring. We need to manually clear HWO bit - * from that TRB. + * We use bounce buffer for requests that needs extra TRB or OUT ZLP. If + * this TRB points to the bounce buffer address, it's a MPS alignment + * TRB. Don't add it to req->remaining calculation. */ - - if (req->needs_extra_trb && !(trb->ctrl & DWC3_TRB_CTRL_CHN)) { + if (trb->bpl == lower_32_bits(dep->dwc->bounce_addr) && + trb->bph == upper_32_bits(dep->dwc->bounce_addr)) { trb->ctrl &= ~DWC3_TRB_CTRL_HWO; return 1; } @@ -2701,17 +2696,8 @@ static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep, goto out; if (req->needs_extra_trb) { - unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc); - ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event, status); - - /* Reclaim MPS padding TRB for ZLP */ - if (!req->direction && req->request.zero && req->request.length && - !usb_endpoint_xfer_isoc(dep->endpoint.desc) && - (IS_ALIGNED(req->request.length, maxp))) - ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event, status); - req->needs_extra_trb = false; } From patchwork Thu Sep 24 08:21:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 258430 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55DE7C4727D for ; Thu, 24 Sep 2020 08:27:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 128352395B for ; Thu, 24 Sep 2020 08:27:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="kDo9S8zh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727277AbgIXI1m (ORCPT ); Thu, 24 Sep 2020 04:27:42 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:36042 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727051AbgIXI1l (ORCPT ); Thu, 24 Sep 2020 04:27:41 -0400 Received: from mailhost.synopsys.com (sv1-mailhost2.synopsys.com [10.205.2.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id E6B37C033F; Thu, 24 Sep 2020 08:21:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1600935705; bh=YxKLDUBCgq7shYYsFCjcpiogPu+ame6OLtK4Wfjsopc=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=kDo9S8zhnbOrs4pbhIObW8atP1e0J6f4Ljf2bw7Uz3CfKRWkyxdmaow/CHn9geBSz ohRvcsazPFTj3nVuabohwOByfWlKBUvI2lMj2JHIS6IEWPRAB1ATRrAakvFIITIu48 3qZ2OsYqdkeUYNVu1dS4D/VbUdrom8OXiLTQOIEFD2BxKmMRaAXrOLAPEs63Odn5tE CbUk6AC0vt2ZHvwGQmuoQBUw2BeNFaI3iZfBzd03NqFb7BqUkpH9rDmwwmV4z+1Edi S6/R8WIcsq+xBENNKEyK1BNQccT5WI1DoP9PCFn8CtJv9fqBlqU+j/HHXAtCw+RjEk eYUPOnsI4CcMw== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id 2BF98A0075; Thu, 24 Sep 2020 08:21:43 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Thu, 24 Sep 2020 01:21:43 -0700 Date: Thu, 24 Sep 2020 01:21:43 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 05/10] usb: dwc3: ep0: Fix ZLP for OUT ep0 requests To: Felipe Balbi , Greg Kroah-Hartman , Thinh.Nguyen@synopsys.com, linux-usb@vger.kernel.org Cc: John Youn , stable@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The current ZLP handling for ep0 requests is only for control IN requests. For OUT direction, DWC3 needs to check and setup for MPS alignment. Usually, control OUT requests can indicate its transfer size via the wLength field of the control message. So usb_request->zero is usually not needed for OUT direction. To handle ZLP OUT for control endpoint, make sure the TRB is MPS size. Cc: stable@vger.kernel.org Fixes: c7fcdeb2627c ("usb: dwc3: ep0: simplify EP0 state machine") Fixes: d6e5a549cc4d ("usb: dwc3: simplify ZLP handling") Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/ep0.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c index b0363e3ba4d1..5580caed8b0c 100644 --- a/drivers/usb/dwc3/ep0.c +++ b/drivers/usb/dwc3/ep0.c @@ -947,12 +947,16 @@ static void dwc3_ep0_xfer_complete(struct dwc3 *dwc, static void __dwc3_ep0_do_control_data(struct dwc3 *dwc, struct dwc3_ep *dep, struct dwc3_request *req) { + unsigned int trb_length = 0; int ret; req->direction = !!dep->number; if (req->request.length == 0) { - dwc3_ep0_prepare_one_trb(dep, dwc->ep0_trb_addr, 0, + if (!req->direction) + trb_length = dep->endpoint.maxpacket; + + dwc3_ep0_prepare_one_trb(dep, dwc->bounce_addr, trb_length, DWC3_TRBCTL_CONTROL_DATA, false); ret = dwc3_ep0_start_trans(dep); } else if (!IS_ALIGNED(req->request.length, dep->endpoint.maxpacket) @@ -999,9 +1003,12 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc, req->trb = &dwc->ep0_trb[dep->trb_enqueue - 1]; + if (!req->direction) + trb_length = dep->endpoint.maxpacket; + /* Now prepare one extra TRB to align transfer size */ dwc3_ep0_prepare_one_trb(dep, dwc->bounce_addr, - 0, DWC3_TRBCTL_CONTROL_DATA, + trb_length, DWC3_TRBCTL_CONTROL_DATA, false); ret = dwc3_ep0_start_trans(dep); } else { From patchwork Thu Sep 24 08:21:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 258432 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 518EFC4346E for ; Thu, 24 Sep 2020 08:21:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0419B221EB for ; Thu, 24 Sep 2020 08:21:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="Ked0/xeD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727219AbgIXIVv (ORCPT ); Thu, 24 Sep 2020 04:21:51 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:40378 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727244AbgIXIVv (ORCPT ); Thu, 24 Sep 2020 04:21:51 -0400 Received: from mailhost.synopsys.com (sv1-mailhost1.synopsys.com [10.205.2.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id D02FB402F6; Thu, 24 Sep 2020 08:21:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1600935710; bh=gEO2aUNRGHydgbcEuMsyfLCEwQoZbu+gIjaSeTTCsLg=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=Ked0/xeDCDmzNtSqVPCBrvaqeS13oskl0AbA9Jl4MM6oefn/aKwM1OPAWLHDe/0ze TZzeVoEYjNvQBtihiC2UDOD8tZtOGwz4CLJM1c2QK3ZxIpVe0WEFqjxapiHcHcaOMy PM33WnvSKD/oJJQw5VMMxrnj2jILsR9aGJ/p6nz0y0uHt0fTo72th06HzO87tFKVk/ yFN07DpK+n07KZm/O6Iw1X7vQ/kb13QhKMOR0KAkBrImtdPLyIJF57UWEFgv6DMgKf YBVrxBxT0vKthhoARUCJY2aAPTfUWo4dWaST4c9Em6Al8Hg1OXtfupa0DX/B3ZtzSf unqvodJuWbR1g== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id A23BEA01F1; Thu, 24 Sep 2020 08:21:49 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Thu, 24 Sep 2020 01:21:49 -0700 Date: Thu, 24 Sep 2020 01:21:49 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 06/10] usb: dwc3: gadget: Return the number of prepared TRBs To: Felipe Balbi , Greg Kroah-Hartman , Thinh.Nguyen@synopsys.com, linux-usb@vger.kernel.org Cc: John Youn Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org In preparation for fixing the check for number of remaining TRBs, revise dwc3_prepare_one_trb_linear() and dwc3_prepare_one_trb_sg() to return the number of prepared TRBs. Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index e49930a7acae..d3896657ddbd 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1094,7 +1094,7 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep, stream_id, short_not_ok, no_interrupt, is_last); } -static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, +static int dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, struct dwc3_request *req) { struct scatterlist *sg = req->start_sg; @@ -1105,6 +1105,7 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, unsigned int rem = length % maxp; unsigned int remaining = req->request.num_mapped_sgs - req->num_queued_sgs; + unsigned int num_trbs = req->num_trbs; /* * If we resume preparing the request, then get the remaining length of @@ -1131,9 +1132,15 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, if ((i == remaining - 1) || !length) chain = false; + if (!dwc3_calc_trbs_left(dep)) + break; + if (rem && usb_endpoint_dir_out(dep->endpoint.desc) && !chain) { /* prepare normal TRB */ if (req->request.length) { + if (dwc3_calc_trbs_left(dep) < 2) + goto out; + req->needs_extra_trb = true; dwc3_prepare_one_trb(dep, req, trb_length, true, i, false); @@ -1145,6 +1152,10 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, } else if (req->request.zero && req->request.length && !usb_endpoint_xfer_isoc(dep->endpoint.desc) && !rem && !chain) { + + if (dwc3_calc_trbs_left(dep) < 2) + goto out; + req->needs_extra_trb = true; /* Prepare normal TRB */ @@ -1185,18 +1196,28 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, if (!dwc3_calc_trbs_left(dep)) break; } + +out: + return req->num_trbs - num_trbs; } -static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, +static int dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, struct dwc3_request *req) { unsigned int length = req->request.length; unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc); unsigned int rem = length % maxp; + unsigned int num_trbs = req->num_trbs; + + if (!dwc3_calc_trbs_left(dep)) + goto out; if ((!length || rem) && usb_endpoint_dir_out(dep->endpoint.desc)) { /* prepare normal TRB */ if (req->request.length) { + if (dwc3_calc_trbs_left(dep) < 2) + goto out; + req->needs_extra_trb = true; dwc3_prepare_one_trb(dep, req, length, true, 0, false); } @@ -1206,6 +1227,10 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, } else if (req->request.zero && req->request.length && !usb_endpoint_xfer_isoc(dep->endpoint.desc) && (IS_ALIGNED(req->request.length, maxp))) { + + if (dwc3_calc_trbs_left(dep) < 2) + goto out; + req->needs_extra_trb = true; /* prepare normal TRB */ @@ -1215,8 +1240,14 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, dwc3_prepare_one_trb(dep, req, req->direction ? 0 : maxp, false, 1, true); } else { + if (!dwc3_calc_trbs_left(dep)) + goto out; + dwc3_prepare_one_trb(dep, req, length, false, 0, false); } + +out: + return req->num_trbs - num_trbs; } /* From patchwork Thu Sep 24 08:21:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 297521 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61121C4346E for ; Thu, 24 Sep 2020 08:21:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B7C0221EB for ; Thu, 24 Sep 2020 08:21:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="AAKUsSqV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727244AbgIXIV5 (ORCPT ); Thu, 24 Sep 2020 04:21:57 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:40384 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727229AbgIXIV5 (ORCPT ); Thu, 24 Sep 2020 04:21:57 -0400 Received: from mailhost.synopsys.com (sv1-mailhost2.synopsys.com [10.205.2.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id E2A27402F6; Thu, 24 Sep 2020 08:21:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1600935716; bh=hDa0Qt9akU1Do2fIdEZ7HtG8sq5HfGsbKvKMfweQDFQ=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=AAKUsSqVCjx04X0qdsBXsB5wxzAiu/HYJMObyOcAor6Znxr2HATABtKnRGAb3Voq3 HBi9Q932iJx3i8nNQ9rvaFERpHa1N3PpiH8eLEeip/UpoFxk1Vpw8lwLTfcKpPFreq FZqBH3u+6THwmyprIiOYPFLipWNRZzbZwySPO0AgIyXj7d3gkZIrgEMeb4MqaXPn7v KLjZtrqNutYD1w9Ll/b+MmZla7lz2pJvfhu/EsQhqclQ23FfCBiJy1AAI9amLYXXhQ l1cscdGLdLTMppVLOokp5N7ml7LzcBBdyW6nxXPj5pemuf3pGtsH0UXaMYr+ZKj7F0 TvMErEPDuYhwg== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id CD577A0072; Thu, 24 Sep 2020 08:21:55 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Thu, 24 Sep 2020 01:21:55 -0700 Date: Thu, 24 Sep 2020 01:21:55 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 07/10] usb: dwc3: gadget: Check for number of TRBs prepared To: Felipe Balbi , Greg Kroah-Hartman , Thinh.Nguyen@synopsys.com, linux-usb@vger.kernel.org Cc: John Youn Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org By returning the number of TRBs prepared, we know whether to execute __dwc3_gadget_kick_transfer(). This allows us to check if we ran out of TRBs when extra TRBs are needed for OUT transfers. It also allows us to properly handle usb_gadget_map_request_by_dev() error. Fixes: c6267a51639b ("usb: dwc3: gadget: align transfers to wMaxPacketSize") Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index d3896657ddbd..f43421246f89 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1257,10 +1257,13 @@ static int dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, * The function goes through the requests list and sets up TRBs for the * transfers. The function returns once there are no more TRBs available or * it runs out of requests. + * + * Returns the number of TRBs prepared or negative errno. */ -static void dwc3_prepare_trbs(struct dwc3_ep *dep) +static int dwc3_prepare_trbs(struct dwc3_ep *dep) { struct dwc3_request *req, *n; + int ret = 0; BUILD_BUG_ON_NOT_POWER_OF_2(DWC3_TRB_NUM); @@ -1275,11 +1278,14 @@ static void dwc3_prepare_trbs(struct dwc3_ep *dep) * break things. */ list_for_each_entry(req, &dep->started_list, list) { - if (req->num_pending_sgs > 0) - dwc3_prepare_one_trb_sg(dep, req); + if (req->num_pending_sgs > 0) { + ret = dwc3_prepare_one_trb_sg(dep, req); + if (!ret) + return ret; + } if (!dwc3_calc_trbs_left(dep)) - return; + return ret; /* * Don't prepare beyond a transfer. In DWC_usb32, its transfer @@ -1287,17 +1293,16 @@ static void dwc3_prepare_trbs(struct dwc3_ep *dep) * active transfer instead of stopping. */ if (dep->stream_capable && req->request.is_last) - return; + return ret; } list_for_each_entry_safe(req, n, &dep->pending_list, list) { struct dwc3 *dwc = dep->dwc; - int ret; ret = usb_gadget_map_request_by_dev(dwc->sysdev, &req->request, dep->direction); if (ret) - return; + return ret; req->sg = req->request.sg; req->start_sg = req->sg; @@ -1305,12 +1310,12 @@ static void dwc3_prepare_trbs(struct dwc3_ep *dep) req->num_pending_sgs = req->request.num_mapped_sgs; if (req->num_pending_sgs > 0) - dwc3_prepare_one_trb_sg(dep, req); + ret = dwc3_prepare_one_trb_sg(dep, req); else - dwc3_prepare_one_trb_linear(dep, req); + ret = dwc3_prepare_one_trb_linear(dep, req); - if (!dwc3_calc_trbs_left(dep)) - return; + if (!ret || !dwc3_calc_trbs_left(dep)) + return ret; /* * Don't prepare beyond a transfer. In DWC_usb32, its transfer @@ -1318,8 +1323,10 @@ static void dwc3_prepare_trbs(struct dwc3_ep *dep) * active transfer instead of stopping. */ if (dep->stream_capable && req->request.is_last) - return; + return ret; } + + return ret; } static void dwc3_gadget_ep_cleanup_cancelled_requests(struct dwc3_ep *dep); @@ -1332,12 +1339,12 @@ static int __dwc3_gadget_kick_transfer(struct dwc3_ep *dep) int ret; u32 cmd; - if (!dwc3_calc_trbs_left(dep)) - return 0; + ret = dwc3_prepare_trbs(dep); + if (ret <= 0) + return ret; starting = !(dep->flags & DWC3_EP_TRANSFER_STARTED); - dwc3_prepare_trbs(dep); req = next_request(&dep->started_list); if (!req) { dep->flags |= DWC3_EP_PENDING_REQUEST; From patchwork Thu Sep 24 08:22:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 258431 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5765FC4727D for ; Thu, 24 Sep 2020 08:22:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1056323772 for ; Thu, 24 Sep 2020 08:22:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="gvb/XJlS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727280AbgIXIWD (ORCPT ); Thu, 24 Sep 2020 04:22:03 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:40390 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727279AbgIXIWD (ORCPT ); Thu, 24 Sep 2020 04:22:03 -0400 Received: from mailhost.synopsys.com (sv1-mailhost1.synopsys.com [10.205.2.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 0106B402F6; Thu, 24 Sep 2020 08:22:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1600935723; bh=0GekWrqSOZaGKm3e1vDH+zdSTIClRyA8pjVIm08Ryfk=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=gvb/XJlSwdnsl+vlUomHuVIx+RqGukTF+3SgEvKULTeEv8iUtETgU44iMAZWVNrNP P6OvyLABHgwxcxHdW67x4LnROwG7jguzaJ5sb1+OxdiG5qCpNJbVfJFkVJ5NG0v9fb bTPg86OJjwzpjMyb7+eWhwEhOL+t3axH0q6fPUvB4PFC+3MMpoIcQVwLunvI8c0VEq GpStKCBLciLu/p3XGANDtvcpT1SOPEVAGrNk2S4dfWSuRkUQGAsdA7ud6P5mw++pPK JN1z8YBVUjOnc0iQQHQRZRKxFKCxz3BbuZ7IAi3wzCSpT8dB3E9PoTHlQhdpU8vATZ KF3lt8/M0t5EA== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id DFD1CA01F1; Thu, 24 Sep 2020 08:22:01 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Thu, 24 Sep 2020 01:22:01 -0700 Date: Thu, 24 Sep 2020 01:22:01 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 08/10] usb: dwc3: gadget: Set IOC if not enough for extra TRBs To: Felipe Balbi , Greg Kroah-Hartman , Thinh.Nguyen@synopsys.com, linux-usb@vger.kernel.org Cc: John Youn Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If we run out of TRBs because we need extra TRBs, make sure to set the IOC bit for the previously prepared TRB to get completion notification to free up TRBs to resume later. Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index f43421246f89..840d6e49f668 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1197,7 +1197,27 @@ static int dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, break; } + return req->num_trbs - num_trbs; + out: + /* + * If we run out of TRBs for MPS alignment setup, then set IOC on the + * previous TRB to get notified for TRB completion to resume when more + * TRBs are available. + * + * Note: normally we shouldn't update the TRB after the HWO bit is set. + * However, the controller doesn't update its internal cache to handle + * the newly prepared TRBs until UPDATE_TRANSFER or START_TRANSFER + * command is executed. At this point, it doesn't happen yet, so we + * should be fine modifying it here. + */ + if (i) { + struct dwc3_trb *trb; + + trb = dwc3_ep_prev_trb(dep, dep->trb_enqueue); + trb->ctrl |= DWC3_TRB_CTRL_IOC; + } + return req->num_trbs - num_trbs; } From patchwork Thu Sep 24 08:22:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 297519 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0682C4727F for ; Thu, 24 Sep 2020 08:27:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8FDAF23772 for ; Thu, 24 Sep 2020 08:27:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="KF1lxuwa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727283AbgIXI1m (ORCPT ); Thu, 24 Sep 2020 04:27:42 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:36046 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727088AbgIXI1m (ORCPT ); Thu, 24 Sep 2020 04:27:42 -0400 Received: from mailhost.synopsys.com (sv1-mailhost2.synopsys.com [10.205.2.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 2DE96C0344; Thu, 24 Sep 2020 08:22:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1600935729; bh=q5eRa53m7YjEo7Nc4vG9SexuD65UBAFQQ0v8uYk2hEM=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=KF1lxuwaFaDKiCd4tUXnOeLfnMQAgibmHfjICGi0W4kUMAZjVU8UQPqSF8RW6TXli pkGn5LV1F1NBINdh1BDMHMGvRwlaia6hljOTEsYbfZJKl+/9Gl+60y2LXGRb7K9AQf Y+f6fhaO7d1Oy2K2XRQhDmAQRieSTPjllZLo8IuBb86weP21KdvksSvKD/DPd2LuwQ a9A3Em4oLA4hlxLUa1ojAhm00gdn7RCWY9tljbNIsj+IFIyCuIC+D8SPNCswF6nVVr 1FfLMOXZt3NTugMesIY5CD1NZeOw5i/TQWsN1seEM+8zPbMVZ/BLgqPW01wIVtIGqa JFixGr0DedzVQ== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id F2158A0072; Thu, 24 Sep 2020 08:22:07 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Thu, 24 Sep 2020 01:22:07 -0700 Date: Thu, 24 Sep 2020 01:22:07 -0700 Message-Id: <8001e64c304f1526838fe6302580c84b43b47d82.1600935293.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 09/10] usb: dwc3: gadget: Refactor preparing last TRBs To: Felipe Balbi , Greg Kroah-Hartman , Thinh.Nguyen@synopsys.com, linux-usb@vger.kernel.org Cc: John Youn Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org There are a lot of common codes for preparing SG and linear TRBs. Refactor them for easier read. Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 129 ++++++++++++++------------------------ 1 file changed, 48 insertions(+), 81 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 840d6e49f668..e6fa2d295439 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1094,6 +1094,47 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep, stream_id, short_not_ok, no_interrupt, is_last); } +/** + * dwc3_prepare_last_sg - prepare TRBs for the last SG entry + * @dep: The endpoint that the request belongs to + * @req: The request to prepare + * @entry_length: The last SG entry size + * @node: Indicates whether this is not the first entry (for isoc only) + * + * Return the number of TRBs prepared. + */ +static int dwc3_prepare_last_sg(struct dwc3_ep *dep, + struct dwc3_request *req, unsigned int entry_length, + unsigned int node) +{ + unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc); + unsigned int rem = req->request.length % maxp; + unsigned int num_trbs = 1; + + if ((req->request.length && req->request.zero && !rem && + !usb_endpoint_xfer_isoc(dep->endpoint.desc)) || + (!req->direction && rem)) + num_trbs++; + + if (dwc3_calc_trbs_left(dep) < num_trbs) + return 0; + + req->needs_extra_trb = num_trbs > 1; + + /* Prepare a normal TRB */ + if (req->direction || req->request.length) + dwc3_prepare_one_trb(dep, req, entry_length, + req->needs_extra_trb, node, false); + + /* Prepare extra TRBs for ZLP and MPS OUT transfer alignment */ + if ((!req->direction && !req->request.length) || req->needs_extra_trb) + dwc3_prepare_one_trb(dep, req, + req->direction ? 0 : maxp - rem, + false, 1, true); + + return num_trbs; +} + static int dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, struct dwc3_request *req) { @@ -1101,8 +1142,6 @@ static int dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, struct scatterlist *s; int i; unsigned int length = req->request.length; - unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc); - unsigned int rem = length % maxp; unsigned int remaining = req->request.num_mapped_sgs - req->num_queued_sgs; unsigned int num_trbs = req->num_trbs; @@ -1116,7 +1155,7 @@ static int dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, for_each_sg(sg, s, remaining, i) { unsigned int trb_length; - unsigned int chain = true; + bool last_sg = false; trb_length = min_t(unsigned int, length, sg_dma_len(s)); @@ -1130,45 +1169,16 @@ static int dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, * mapped sg. */ if ((i == remaining - 1) || !length) - chain = false; + last_sg = true; if (!dwc3_calc_trbs_left(dep)) break; - if (rem && usb_endpoint_dir_out(dep->endpoint.desc) && !chain) { - /* prepare normal TRB */ - if (req->request.length) { - if (dwc3_calc_trbs_left(dep) < 2) - goto out; - - req->needs_extra_trb = true; - dwc3_prepare_one_trb(dep, req, trb_length, - true, i, false); - } - - /* Now prepare one extra TRB to align transfer size */ - dwc3_prepare_one_trb(dep, req, maxp - rem, - false, 1, true); - } else if (req->request.zero && req->request.length && - !usb_endpoint_xfer_isoc(dep->endpoint.desc) && - !rem && !chain) { - - if (dwc3_calc_trbs_left(dep) < 2) + if (last_sg) { + if (!dwc3_prepare_last_sg(dep, req, trb_length, i)) goto out; - - req->needs_extra_trb = true; - - /* Prepare normal TRB */ - dwc3_prepare_one_trb(dep, req, trb_length, - true, i, false); - - /* Prepare one extra TRB to handle ZLP */ - dwc3_prepare_one_trb(dep, req, - req->direction ? 0 : maxp, - false, 1, true); } else { - dwc3_prepare_one_trb(dep, req, trb_length, - chain, i, false); + dwc3_prepare_one_trb(dep, req, trb_length, 1, i, false); } /* @@ -1178,7 +1188,7 @@ static int dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, * we have free trbs we can continue queuing from where we * previously stopped */ - if (chain) + if (!last_sg) req->start_sg = sg_next(s); req->num_queued_sgs++; @@ -1224,50 +1234,7 @@ static int dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, static int dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, struct dwc3_request *req) { - unsigned int length = req->request.length; - unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc); - unsigned int rem = length % maxp; - unsigned int num_trbs = req->num_trbs; - - if (!dwc3_calc_trbs_left(dep)) - goto out; - - if ((!length || rem) && usb_endpoint_dir_out(dep->endpoint.desc)) { - /* prepare normal TRB */ - if (req->request.length) { - if (dwc3_calc_trbs_left(dep) < 2) - goto out; - - req->needs_extra_trb = true; - dwc3_prepare_one_trb(dep, req, length, true, 0, false); - } - - /* Now prepare one extra TRB to align transfer size */ - dwc3_prepare_one_trb(dep, req, maxp - rem, false, 1, true); - } else if (req->request.zero && req->request.length && - !usb_endpoint_xfer_isoc(dep->endpoint.desc) && - (IS_ALIGNED(req->request.length, maxp))) { - - if (dwc3_calc_trbs_left(dep) < 2) - goto out; - - req->needs_extra_trb = true; - - /* prepare normal TRB */ - dwc3_prepare_one_trb(dep, req, length, true, 0, false); - - /* Prepare one extra TRB to handle ZLP */ - dwc3_prepare_one_trb(dep, req, req->direction ? 0 : maxp, - false, 1, true); - } else { - if (!dwc3_calc_trbs_left(dep)) - goto out; - - dwc3_prepare_one_trb(dep, req, length, false, 0, false); - } - -out: - return req->num_trbs - num_trbs; + return dwc3_prepare_last_sg(dep, req, req->request.length, 0); } /* From patchwork Thu Sep 24 08:22:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 297520 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8F0FC4346E for ; Thu, 24 Sep 2020 08:27:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AADA12376F for ; Thu, 24 Sep 2020 08:27:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="UtIgfyzd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727237AbgIXI1m (ORCPT ); Thu, 24 Sep 2020 04:27:42 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:36044 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727031AbgIXI1l (ORCPT ); Thu, 24 Sep 2020 04:27:41 -0400 X-Greylist: delayed 356 seconds by postgrey-1.27 at vger.kernel.org; Thu, 24 Sep 2020 04:27:41 EDT Received: from mailhost.synopsys.com (sv2-mailhost1.synopsys.com [10.205.2.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 3D3D4C0358; Thu, 24 Sep 2020 08:22:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1600935735; bh=q78RPO7lq6RVCF3Lh3j0ZFxwGtGsivEE4E76RnVjC0c=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=UtIgfyzdWCJfapVM6FNG070GukzYr5ka5dH63vArPKKrx97NWfIotHj3jz8NZRbve If+h+Fd5+O/z41lp6ziExzLJ3v674g3mitvPGUfCpjGumJKUmCfwKw6v6fz30lKgKV Mmrsf0RAL1WiIqgIij9vFNczWqBIfZlWaZNOaRD2frIsC1803rwujBStMhUSb9yGm7 Jo5oKa1mkVPIi1hdS2IDWR09tA5OZJ586o0cxFxfRPdyubgpgNTdYfMQaqXS2JBsxG hmeJmZbJZ46yPu++kZD6uDgW+kk4aGvcImlpVc75KPsr6QN4wihPV+evMvC7SFoeLS gWXczUwV/YpWg== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id 0FDB3A009A; Thu, 24 Sep 2020 08:22:14 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Thu, 24 Sep 2020 01:22:14 -0700 Date: Thu, 24 Sep 2020 01:22:14 -0700 Message-Id: <4ae2ecebcd9fd1c72aa40e5808fe016631dc0879.1600935293.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 10/10] usb: dwc3: gadget: Rename misleading function names To: Felipe Balbi , Greg Kroah-Hartman , Thinh.Nguyen@synopsys.com, linux-usb@vger.kernel.org Cc: John Youn Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The functions dwc3_prepare_one_trb_sg and dwc3_prepare_one_trb_linear are not necessarily preparing "one" TRB, it can prepare multiple TRBs. Rename these functions as follow: dwc3_prepare_one_trb_sg -> dwc3_prepare_trbs_sg dwc3_prepare_one_trb_linear -> dwc3_prepare_trbs_linear Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index e6fa2d295439..ca10619c64a3 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1135,7 +1135,7 @@ static int dwc3_prepare_last_sg(struct dwc3_ep *dep, return num_trbs; } -static int dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, +static int dwc3_prepare_trbs_sg(struct dwc3_ep *dep, struct dwc3_request *req) { struct scatterlist *sg = req->start_sg; @@ -1231,7 +1231,7 @@ static int dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, return req->num_trbs - num_trbs; } -static int dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, +static int dwc3_prepare_trbs_linear(struct dwc3_ep *dep, struct dwc3_request *req) { return dwc3_prepare_last_sg(dep, req, req->request.length, 0); @@ -1266,7 +1266,7 @@ static int dwc3_prepare_trbs(struct dwc3_ep *dep) */ list_for_each_entry(req, &dep->started_list, list) { if (req->num_pending_sgs > 0) { - ret = dwc3_prepare_one_trb_sg(dep, req); + ret = dwc3_prepare_trbs_sg(dep, req); if (!ret) return ret; } @@ -1297,9 +1297,9 @@ static int dwc3_prepare_trbs(struct dwc3_ep *dep) req->num_pending_sgs = req->request.num_mapped_sgs; if (req->num_pending_sgs > 0) - ret = dwc3_prepare_one_trb_sg(dep, req); + ret = dwc3_prepare_trbs_sg(dep, req); else - ret = dwc3_prepare_one_trb_linear(dep, req); + ret = dwc3_prepare_trbs_linear(dep, req); if (!ret || !dwc3_calc_trbs_left(dep)) return ret;