From patchwork Thu Mar 5 21:23: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: 11422669 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4EF3B92A for ; Thu, 5 Mar 2020 21:23:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 25DD02166E for ; Thu, 5 Mar 2020 21:23:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="PJLgzcz7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726162AbgCEVXv (ORCPT ); Thu, 5 Mar 2020 16:23:51 -0500 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:47408 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726111AbgCEVXv (ORCPT ); Thu, 5 Mar 2020 16:23:51 -0500 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 B5E91C10CC; Thu, 5 Mar 2020 21:23:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1583443431; bh=yrq7Q9RqsiuUmyEzEOOBnbBOQwoF7QudkSxK5FWQMz8=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=PJLgzcz7QyDxpORLYGj7+Q6jdvt7xRFbn3JOjRIHx2Tg9IC3LEzwsDV8LLIRT6SN6 85A8pHj/dE7iJ99AWUmsaiMgIMlWVWibFda9OySAT24T+cJ1Rus/6CzRy3HAQd0BFP t5e/CZiOe9yGphXNkSLJT0Uhq5XhiMVGWL1rBqsQ2De6vxUjMxWPXH7LAF+ht94rTg xfMlZktmAR4tPIWthU9BAy+I4f1v/T6DEbyy/+T1DBynoPsnUdUP3cID8Yi6cghOgg 7PeNepYnfYe1smiZUFdsJeLGNnvo/QIbaUyEakXyjLA1VDc7huGeD2a7xtUUnj4j3Q 7pEk10feesNDA== 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 67C37A006D; Thu, 5 Mar 2020 21:23:49 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Thu, 05 Mar 2020 13:23:49 -0800 Date: Thu, 05 Mar 2020 13:23:49 -0800 Message-Id: <6daaa98986b2061c2784e7229df2af8baeb9d783.1583443184.git.thinhn@synopsys.com> In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH 1/6] usb: dwc3: gadget: Don't clear flags before transfer ended To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org Cc: John Youn Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org We track END_TRANSFER command completion. Don't clear transfer started/ended flag prematurely. Otherwise, we'd run into the problem with restarting transfer before END_TRANSFER command finishes. Fixes: 6d8a019614f3 ("usb: dwc3: gadget: check for Missed Isoc from event status") Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 1b7d2f9cb673..b87bdec84210 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2563,10 +2563,8 @@ static void dwc3_gadget_endpoint_transfer_in_progress(struct dwc3_ep *dep, dwc3_gadget_ep_cleanup_completed_requests(dep, event, status); - if (stop) { + if (stop) dwc3_stop_active_transfer(dep, true, true); - dep->flags = DWC3_EP_ENABLED; - } /* * WORKAROUND: This is the 2nd half of U1/U2 -> U0 workaround. From patchwork Thu Mar 5 21:23: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: 11422671 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E8C5392A for ; Thu, 5 Mar 2020 21:23:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CA1822166E for ; Thu, 5 Mar 2020 21:23:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="Da85A0EL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726164AbgCEVX5 (ORCPT ); Thu, 5 Mar 2020 16:23:57 -0500 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:53404 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726143AbgCEVX5 (ORCPT ); Thu, 5 Mar 2020 16:23:57 -0500 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 A645843BE1; Thu, 5 Mar 2020 21:23:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1583443436; bh=214pxbdSMsKMcN2v9wPcKz8IvNgRgep1Z23xn7RhH6Y=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=Da85A0EL5V/WZ+dqwzgu5tHMfYY0OnY7dYBGi/Qk8utzJUk0x+ztlXox02LvGlvqf +RLs/vaE8U3dXaTyXgSphwZRHsMC8XoV2lxtjwA7OHXhCJynd4AiBKIiBjxu0PftG1 96qjxGVhHcMK5bEYZD3l82Iv00ePgZcEZNjE85tPFHzADb+Jz4GXZmhTMcx9szRX8a ldl5YPtpKY5WHEEnh6o72EazZvl+a9zb3HWm+z6GZx9OOW3JUMJdpuKw7NmG8RreGe qlYkP08sK9mMtUgttq59qWft20MZqY9uqXWXvTKt+1sYeoptApmi88fIwFxIxPJRGh Xvd5ch1Lz9YRQ== 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 90C4AA006D; Thu, 5 Mar 2020 21:23:55 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Thu, 05 Mar 2020 13:23:55 -0800 Date: Thu, 05 Mar 2020 13:23:55 -0800 Message-Id: <4f9b6acbff2cd0be417fd4a943c1975bf41f8fda.1583443184.git.thinhn@synopsys.com> In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH 2/6] usb: dwc3: gadget: Properly handle ClearFeature(halt) To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org Cc: John Youn Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org DWC3 must not issue CLEAR_STALL command to control endpoints. The controller automatically clears the STALL when it receives the SETUP token. Also, when the driver receives ClearFeature(halt_ep), DWC3 must stop any active transfer from the endpoint and give back all the requests to the function drivers. Fixes: 72246da40f37 ("usb: Introduce DesignWare USB3 DRD Driver") Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index b87bdec84210..21b10364b888 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1501,6 +1501,10 @@ static void dwc3_gadget_ep_skip_trbs(struct dwc3_ep *dep, struct dwc3_request *r { int i; + /* If req->trb is not set, then the request has not started */ + if (!req->trb) + return; + /* * If request was already started, this means we had to * stop the transfer. With that we also need to ignore @@ -1591,6 +1595,8 @@ int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value, int protocol) { struct dwc3_gadget_ep_cmd_params params; struct dwc3 *dwc = dep->dwc; + struct dwc3_request *req; + struct dwc3_request *tmp; int ret; if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) { @@ -1627,13 +1633,37 @@ int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value, int protocol) else dep->flags |= DWC3_EP_STALL; } else { + /* + * Don't issue CLEAR_STALL command to control endpoints. The + * controller automatically clears the STALL when it receives + * the SETUP token. + */ + if (dep->number <= 1) { + dep->flags &= ~(DWC3_EP_STALL | DWC3_EP_WEDGE); + return 0; + } ret = dwc3_send_clear_stall_ep_cmd(dep); - if (ret) + if (ret) { dev_err(dwc->dev, "failed to clear STALL on %s\n", dep->name); - else - dep->flags &= ~(DWC3_EP_STALL | DWC3_EP_WEDGE); + return ret; + } + + dep->flags &= ~(DWC3_EP_STALL | DWC3_EP_WEDGE); + + dwc3_stop_active_transfer(dep, true, true); + + list_for_each_entry_safe(req, tmp, &dep->started_list, list) + dwc3_gadget_move_cancelled_request(req); + + list_for_each_entry_safe(req, tmp, &dep->pending_list, list) + dwc3_gadget_move_cancelled_request(req); + + if (!(dep->flags & DWC3_EP_END_TRANSFER_PENDING)) { + dep->flags &= ~DWC3_EP_DELAY_START; + dwc3_gadget_ep_cleanup_cancelled_requests(dep); + } } return ret; From patchwork Thu Mar 5 21:24: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: 11422673 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B70881395 for ; Thu, 5 Mar 2020 21:24:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8D67821D56 for ; Thu, 5 Mar 2020 21:24:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="WX6Ie/Nt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726178AbgCEVYD (ORCPT ); Thu, 5 Mar 2020 16:24:03 -0500 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:53412 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726143AbgCEVYD (ORCPT ); Thu, 5 Mar 2020 16:24:03 -0500 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 6041343BE1; Thu, 5 Mar 2020 21:24:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1583443443; bh=+wBPbe13994Dn1+F8xR0oAiYGqsds2IkNx+WDRUaBrA=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=WX6Ie/Nt8E6eI9txD/Wo7dG8LxXzuBM9viHuKJksoxgGVCLtY9b3TG9+dXzynXz9m nExvYuWJ0VQJdrYpWwOxS0pLLVOYo3ywMyb7Zxwz3C/GifGPhTTpGVgboQlzoC7igi /0eAT6Tq3tpGIXi7rIdoFucAsRfoGIMH4bBgcsA7y8c2SaTzHVZT/V/mzBRXA+SXMi bOp7AuP8ASKdMpikvqSTpNaFcfUKj45N08LYZop57sxQkRBrJHEFsENuaAjzhaWqP3 uRaXs7MlpE9UIG5/2izf/ITLPdF9thfFJ9HGiQPcX15ktMmP0BvguMwGqe1QyMkgF/ o2pqJ0Ha3ANDg== 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 D7326A00C0; Thu, 5 Mar 2020 21:24:01 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Thu, 05 Mar 2020 13:24:01 -0800 Date: Thu, 05 Mar 2020 13:24:01 -0800 Message-Id: <64f999fcdcab268f325296043d451964da65ffa2.1583443184.git.thinhn@synopsys.com> In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH 3/6] usb: dwc3: gadget: Wrap around when skip TRBs To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org Cc: John Youn , stable Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org When skipping TRBs, we need to account for wrapping around the ring buffer and not modifying some invalid TRBs. Without this fix, dwc3 won't be able to check for available TRBs. Cc: stable Fixes: 7746a8dfb3f9 ("usb: dwc3: gadget: extract dwc3_gadget_ep_skip_trbs()") Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 21b10364b888..8c27c6ede7c4 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1518,7 +1518,7 @@ static void dwc3_gadget_ep_skip_trbs(struct dwc3_ep *dep, struct dwc3_request *r for (i = 0; i < req->num_trbs; i++) { struct dwc3_trb *trb; - trb = req->trb + i; + trb = &dep->trb_pool[dep->trb_dequeue]; trb->ctrl &= ~DWC3_TRB_CTRL_HWO; dwc3_ep_inc_deq(dep); } From patchwork Thu Mar 5 21:24:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11422675 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D0AB01395 for ; Thu, 5 Mar 2020 21:24:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B20CA208C3 for ; Thu, 5 Mar 2020 21:24:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="JIG5lTXU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726181AbgCEVYK (ORCPT ); Thu, 5 Mar 2020 16:24:10 -0500 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:47454 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726143AbgCEVYK (ORCPT ); Thu, 5 Mar 2020 16:24:10 -0500 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 9306EC10CC; Thu, 5 Mar 2020 21:24:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1583443449; bh=tlrczmuj3wkip53r4dwXEWw86BROUDoqoipoiLsF5SI=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=JIG5lTXUAMSwwQ3yz9YEIRobHccY19BJ3fRwiqHGlsIpGTGy7mBEc6xt0sezk0Beo fZrNPL/TrvvOyRdpzs78ZcQxF/a3CtikR+pw73qw601YuLc9I+kxzDH9pjQwFs3YiK 5/UUT/+OdOSCaGdjKKTE+E+N2y923FcZepfu01nSgIxfzr7rCY6jcIusadjWbjyd2B nA2//ZOkaRbSSKopRdntchBFhf5+53Vm9eQdSYNOVGb4awPzLJTJvZAOp2p13gQtw9 9ow444HTZoaq+vrSI1GGncnNv/9rxthJzWzQzg+VvuOvP/VOoTMKJKXIeGMA4AbyzH dWpVBot9TKp3Q== 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 5CA86A0096; Thu, 5 Mar 2020 21:24:08 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Thu, 05 Mar 2020 13:24:08 -0800 Date: Thu, 05 Mar 2020 13:24:08 -0800 Message-Id: In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH 4/6] usb: dwc3: gadget: Give back staled requests To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org Cc: John Youn Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If a request is dequeued, the transfer is cancelled. Give back all the started requests. In most scenarios, the function driver dequeues all requests of a transfer when there's a failure. If the function driver follows this, then it's fine. If not, then we'd be skipping TRBs at different points within the dequeue and enqueue pointers, making dequeue/enqueue pointers useless. To enforce and make sure that we're properly skipping TRBs, cancel all the started requests and give back all the cancelled requests to the function drivers. Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 8c27c6ede7c4..42dc4973a997 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1553,6 +1553,11 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, spin_lock_irqsave(&dwc->lock, flags); + list_for_each_entry(r, &dep->cancelled_list, list) { + if (r == req) + goto out0; + } + list_for_each_entry(r, &dep->pending_list, list) { if (r == req) break; @@ -1564,13 +1569,21 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, break; } if (r == req) { + struct dwc3_request *t; + /* wait until it is processed */ dwc3_stop_active_transfer(dep, true, true); if (!r->trb) goto out0; - dwc3_gadget_move_cancelled_request(req); + /* + * Remove any started request if the transfer is + * cancelled. + */ + list_for_each_entry_safe(r, t, &dep->started_list, list) + dwc3_gadget_move_cancelled_request(r); + if (dep->flags & DWC3_EP_TRANSFER_STARTED) goto out0; else From patchwork Thu Mar 5 21:24: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: 11422677 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9033F92A for ; Thu, 5 Mar 2020 21:24:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6EB1C2166E for ; Thu, 5 Mar 2020 21:24:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="OQrNubxQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726209AbgCEVYQ (ORCPT ); Thu, 5 Mar 2020 16:24:16 -0500 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:53418 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726184AbgCEVYP (ORCPT ); Thu, 5 Mar 2020 16:24:15 -0500 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 8413343BE1; Thu, 5 Mar 2020 21:24:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1583443455; bh=i3rMXF7SBF5opHO2qJfGYBkbDJlOg5UEpxWLu7PbXVs=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=OQrNubxQMJDt16iP12ugdbQMTH12zZemCNWlxDvQIEcJJQxvTSKBmmVKvlqks7XVL TgmcX2HhPoLcOAwLwxEoJ1g0ypOjNxjB6jMN3CX1qWN0b77mshFKU5zJZ9Jh3awI2R foJRQ4IVEpJnH7k48RQwwxH/szSyyJANmHXy0kLRxcf0fl+PBlXfappEWy67al4MPt /ZRkvbdcRBiFOgTAk+Uz2moeWEHnR4jJ5kjQ4mOauVT36BJ12R4mwE9XmW9uzdhUQz zMHMMavdk8yhn5HZu9Xipp0tB3hmCfQ7mYo8L+2N6lrR3Z5kELEPtpAtIsD+OTUiLw D5yTB/BTLk9Dw== 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 6F3F7A0078; Thu, 5 Mar 2020 21:24:14 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Thu, 05 Mar 2020 13:24:14 -0800 Date: Thu, 05 Mar 2020 13:24:14 -0800 Message-Id: <7317cc35ba4aa18fbb19ef8048d38bd03f80bd10.1583443184.git.thinhn@synopsys.com> In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH 5/6] usb: dwc3: gadget: Remove unnecessary checks To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org Cc: John Youn Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Remove 2 unnecessary checks: 1) A request in the started_list must have its trb field set. So checking for req->trb is unnecessary. 2) An endpoint must have started (and have not ended) for the request to still be in the started_list. There's no point to check if the endpoint is started. We had this check because previously the driver didn't handle the endpoint's started/ended flags for END_TRANSFER command properly. See commit 9f45581f5eec ("usb: dwc3: gadget: early giveback if End Transfer already completed"). Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 42dc4973a997..cd00f2757cb5 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1574,9 +1574,6 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, /* wait until it is processed */ dwc3_stop_active_transfer(dep, true, true); - if (!r->trb) - goto out0; - /* * Remove any started request if the transfer is * cancelled. @@ -1584,10 +1581,7 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, list_for_each_entry_safe(r, t, &dep->started_list, list) dwc3_gadget_move_cancelled_request(r); - if (dep->flags & DWC3_EP_TRANSFER_STARTED) - goto out0; - else - goto out1; + goto out0; } dev_err(dwc->dev, "request %pK was not queued to %s\n", request, ep->name); @@ -1595,7 +1589,6 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, goto out0; } -out1: dwc3_gadget_giveback(dep, req, -ECONNRESET); out0: From patchwork Thu Mar 5 21:24:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11422679 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A34811395 for ; Thu, 5 Mar 2020 21:24:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 845B12166E for ; Thu, 5 Mar 2020 21:24:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="h55bMNdP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726222AbgCEVYW (ORCPT ); Thu, 5 Mar 2020 16:24:22 -0500 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:53428 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726184AbgCEVYV (ORCPT ); Thu, 5 Mar 2020 16:24:21 -0500 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 95AAD43BE1; Thu, 5 Mar 2020 21:24:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1583443461; bh=3/XMRGShBnl0C1pKRoEEBidRVlpCQ65FOlu6h1QXl1w=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=h55bMNdPCboO3IntyLISNxGpeCxLqhnfaYcoRfK72GF2MURuE7Hm3M38GV7rAp5VA hYhezFquVOvfpM0sgb/QzIQjz1arQTP3yQP8cO1m832H5HtwpZ7FqGB51RnBe07NTG uVIWOXkf9Q49e1ShBqh8yEMO8sNUsJUlA+IIG6aBfQTkLBnASiWd410Wo5MKk//65i hGp4XIA0zJdm2O8cSL0p/4FEKkXWaI9rgaUf2b+p/GsR4tZopvASzsm2YgoTxvUUCj 3TqBVn/htCLRnHjRxYI4JxxgFhgvMaFd/I5wRiYfwUMKWBKlThoLkQaxwf5+s9bQN6 ylTTs5QWf3bPQ== 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 8180EA006E; Thu, 5 Mar 2020 21:24:20 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Thu, 05 Mar 2020 13:24:20 -0800 Date: Thu, 05 Mar 2020 13:24:20 -0800 Message-Id: <17318e194eea91aca59a1965967f953a55629d1e.1583443184.git.thinhn@synopsys.com> In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH 6/6] usb: dwc3: gadget: Refactor dwc3_gadget_ep_dequeue To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org Cc: John Youn Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The flow from function dwc3_gadget_ep_dequeue() is not easy to follow. Refactor it for easier read. No functional change in this commit. Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index cd00f2757cb5..39c92df6e188 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1555,19 +1555,17 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, list_for_each_entry(r, &dep->cancelled_list, list) { if (r == req) - goto out0; + goto out; } list_for_each_entry(r, &dep->pending_list, list) { - if (r == req) - break; + if (r == req) { + dwc3_gadget_giveback(dep, req, -ECONNRESET); + goto out; + } } - if (r != req) { - list_for_each_entry(r, &dep->started_list, list) { - if (r == req) - break; - } + list_for_each_entry(r, &dep->started_list, list) { if (r == req) { struct dwc3_request *t; @@ -1581,17 +1579,14 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, list_for_each_entry_safe(r, t, &dep->started_list, list) dwc3_gadget_move_cancelled_request(r); - goto out0; + goto out; } - dev_err(dwc->dev, "request %pK was not queued to %s\n", - request, ep->name); - ret = -EINVAL; - goto out0; } - dwc3_gadget_giveback(dep, req, -ECONNRESET); - -out0: + dev_err(dwc->dev, "request %pK was not queued to %s\n", + request, ep->name); + ret = -EINVAL; +out: spin_unlock_irqrestore(&dwc->lock, flags); return ret;