From patchwork Tue Mar 31 01:54:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11466615 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 B97ED13A4 for ; Tue, 31 Mar 2020 01:54:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8D66B20748 for ; Tue, 31 Mar 2020 01:54:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="lngxnT+g" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729196AbgCaBy6 (ORCPT ); Mon, 30 Mar 2020 21:54:58 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:47324 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729089AbgCaBy6 (ORCPT ); Mon, 30 Mar 2020 21:54:58 -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 DD60EC0FDE; Tue, 31 Mar 2020 01:54:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1585619697; bh=uW1dLN1Bde+fzdsPKs7tCI6ZsuSSFNk6dYLaa6h1bxU=; h=Date:From:Subject:To:Cc:From; b=lngxnT+gwDCS6SD4Bopojhutc/3MwQ2f38f5PLfU9117aQFATrG6laYK4szWG48xZ NQ2M4Uhp4aMeKWqtHL0lHiB6nyNHO+hVcrv568RnKZKCSFnSfVnfbezt7An9tzIIM5 nVt2AV6XLmSafZ/O+vHobg4gQrXQeAVDA+6O66a1+UntkBe9jcyQpWgPjcoUhNZdAL EbuhMN0bDudF6kSwcsEIpeicFcnVkBYfFdQ6CkxLF9FaSbl6qwKX6eIwph2NwtJu4D xOFMwyLsHm1zKG80PCBhJ5UNGxX2XGH9FHrkmvN7+YH0ucjmWpkNjfLjwYKcP19yEo UTScJ8wQxHb7Q== 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 92E7FA007C; Tue, 31 Mar 2020 01:54:56 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Mon, 30 Mar 2020 18:54:56 -0700 Date: Mon, 30 Mar 2020 18:54:56 -0700 Message-Id: <07653eda952a5afaca528a69f9b3d160ee695db1.1585619602.git.thinhn@synopsys.com> From: Thinh Nguyen Subject: [PATCH 1/2] usb: dwc3: gadget: Fix request completion check To: Felipe Balbi , Greg Kroah-Hartman , linux-usb@vger.kernel.org Cc: John Youn , Thinh Nguyen Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org A request may not be completed because not all the TRBs are prepared for it. This happens when we run out of available TRBs. When some TRBs are completed, the driver needs to prepare the rest of the TRBs for the request. The check dwc3_gadget_ep_request_completed() shouldn't be checking the amount of data received but rather the number of pending TRBs. Revise this request completion check. Fixes: e0c42ce590fe ("usb: dwc3: gadget: simplify IOC handling") Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 1a4fc03742aa..c45853b14cff 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2550,14 +2550,7 @@ static int dwc3_gadget_ep_reclaim_trb_linear(struct dwc3_ep *dep, static bool dwc3_gadget_ep_request_completed(struct dwc3_request *req) { - /* - * For OUT direction, host may send less than the setup - * length. Return true for all OUT requests. - */ - if (!req->direction) - return true; - - return req->request.actual == req->request.length; + return req->num_pending_sgs == 0; } static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep, @@ -2581,8 +2574,7 @@ static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep, req->request.actual = req->request.length - req->remaining; - if (!dwc3_gadget_ep_request_completed(req) || - req->num_pending_sgs) { + if (!dwc3_gadget_ep_request_completed(req)) { __dwc3_gadget_kick_transfer(dep); goto out; } From patchwork Tue Mar 31 01:55:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11466617 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 C89AD15AB for ; Tue, 31 Mar 2020 01:55:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A332620748 for ; Tue, 31 Mar 2020 01:55:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="kU65Quq+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729239AbgCaBzF (ORCPT ); Mon, 30 Mar 2020 21:55:05 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:47330 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729089AbgCaBzF (ORCPT ); Mon, 30 Mar 2020 21:55:05 -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 75380C0FDE; Tue, 31 Mar 2020 01:55:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1585619704; bh=8VlwsDwtSalujAW89F+NTDDWavApHp975EpzhHu3DZw=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=kU65Quq+ha9dMum83ciackTIzDvonyCUj7gQbFeCM5j5kj5y3SLKnQLFiaHBYEc7c aCjl8xxTgZ2Adt7x2Xj40LynfXmkWFB/lDhRzt7jrLSsa3jYYC+0kpJtRzs0ARUoLW ynpUF3EAGBdT8JMSPcmThc87oH/DeeEGo9JcJbum8jzCSidKFsM+iJDDeep/8KwAq/ 3SFtdwbsFBLSToBrK38o8A3M/YMOrhy7mSE8r+ltGAzS62BAfSdE0D954cVlZZvAfs ksvQnhxwQkYFmhLJmgn4m9/RN7ULbxBpVlzBHN85gYz3EsEhkd0OGoJa4S8IqeXVEk zQnQie4E2njQw== 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 02A96A007B; Tue, 31 Mar 2020 01:55:02 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Mon, 30 Mar 2020 18:55:02 -0700 Date: Mon, 30 Mar 2020 18:55:02 -0700 Message-Id: <23622902d05e7fc24f60de868bd4810f6194f64f.1585619602.git.thinhn@synopsys.com> In-Reply-To: <07653eda952a5afaca528a69f9b3d160ee695db1.1585619602.git.thinhn@synopsys.com> References: <07653eda952a5afaca528a69f9b3d160ee695db1.1585619602.git.thinhn@synopsys.com> From: Thinh Nguyen Subject: [PATCH 2/2] usb: dwc3: gadget: Continue to process pending requests To: Felipe Balbi , Greg Kroah-Hartman , linux-usb@vger.kernel.org Cc: John Youn , Thinh Nguyen Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If there are still pending requests because no TRB was available, prepare more when started requests are completed. Introduce dwc3_gadget_ep_should_continue() to check for incomplete and pending requests to resume updating new TRBs to the controller's TRB cache. Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index c45853b14cff..3c4024d34434 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2574,10 +2574,8 @@ static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep, req->request.actual = req->request.length - req->remaining; - if (!dwc3_gadget_ep_request_completed(req)) { - __dwc3_gadget_kick_transfer(dep); + if (!dwc3_gadget_ep_request_completed(req)) goto out; - } dwc3_gadget_giveback(dep, req, status); @@ -2601,6 +2599,24 @@ static void dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep, } } +static bool dwc3_gadget_ep_should_continue(struct dwc3_ep *dep) +{ + struct dwc3_request *req; + + if (!list_empty(&dep->pending_list)) + return true; + + /* + * We only need to check the first entry of the started list. We can + * assume the completed requests are removed from the started list. + */ + req = next_request(&dep->started_list); + if (!req) + return false; + + return !dwc3_gadget_ep_request_completed(req); +} + static void dwc3_gadget_endpoint_frame_from_event(struct dwc3_ep *dep, const struct dwc3_event_depevt *event) { @@ -2630,6 +2646,8 @@ static void dwc3_gadget_endpoint_transfer_in_progress(struct dwc3_ep *dep, if (stop) dwc3_stop_active_transfer(dep, true, true); + else if (dwc3_gadget_ep_should_continue(dep)) + __dwc3_gadget_kick_transfer(dep); /* * WORKAROUND: This is the 2nd half of U1/U2 -> U0 workaround.