From patchwork Fri Mar 13 02:18:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11435829 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 E122014B4 for ; Fri, 13 Mar 2020 02:18:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C0FF8206FA for ; Fri, 13 Mar 2020 02:18:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="cNh1ymxa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726254AbgCMCSg (ORCPT ); Thu, 12 Mar 2020 22:18:36 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:34238 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726114AbgCMCSg (ORCPT ); Thu, 12 Mar 2020 22:18:36 -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 158FC40213; Fri, 13 Mar 2020 02:18:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1584065916; bh=CYSkk5aBDKzInX30KdcTekXCcc7h7MizEFtj+sYPcvQ=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=cNh1ymxaUxkebcJnabBfDqk44as+8+ON0m19zA2FjQb8RYwnKTn4JQl9HI+JSa0jU G9q0FRbT2B1rW2blZ5gubyaqUauj6D5fLt7OXNW1qvtsxnb3rQ4SU9W9eX/RBle973 yqG6ABHYzM84WCEKO+a1YT+bQXSEtrhzC4G9sahUYrNMGn5+BQp0Z69cQ6jhwB7bGt IkfqhcLNMbp399ldo2gusCgVqPY9i5v4Tevod94FkEC6tSSO+bqCkcg8jukXERCFKY rijlLBmXYNhBzxR/uB8m/MXmJ3mAiqZ1yNH5+nuZDk7uhPMBjxgEIH2Af3F7uj+IVD sStuTDwcHJA1g== 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 DF951A00A0; Fri, 13 Mar 2020 02:18:34 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Thu, 12 Mar 2020 19:18:34 -0700 Date: Thu, 12 Mar 2020 19:18:34 -0700 Message-Id: <015470a7d9b950df757b1abfecd6ef398ef04710.1584065705.git.thinhn@synopsys.com> In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH 1/3] usb: dwc3: gadget: Properly handle failed kick_transfer 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 dwc3 fails to issue START_TRANSFER/UPDATE_TRANSFER command, then we should properly end an active transfer and give back all the started requests. However if it's for an isoc endpoint, the failure maybe due to bus-expiry status. In this case, don't give back the requests and wait for the next retry. Fixes: 72246da40f37 ("usb: Introduce DesignWare USB3 DRD Driver") Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 1b7d2f9cb673..4cb7f9329657 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1213,6 +1213,8 @@ static void dwc3_prepare_trbs(struct dwc3_ep *dep) } } +static void dwc3_gadget_ep_cleanup_cancelled_requests(struct dwc3_ep *dep); + static int __dwc3_gadget_kick_transfer(struct dwc3_ep *dep) { struct dwc3_gadget_ep_cmd_params params; @@ -1252,14 +1254,20 @@ static int __dwc3_gadget_kick_transfer(struct dwc3_ep *dep) ret = dwc3_send_gadget_ep_cmd(dep, cmd, ¶ms); if (ret < 0) { - /* - * FIXME we need to iterate over the list of requests - * here and stop, unmap, free and del each of the linked - * requests instead of what we do now. - */ - if (req->trb) - memset(req->trb, 0, sizeof(struct dwc3_trb)); - dwc3_gadget_del_and_unmap_request(dep, req, ret); + struct dwc3_request *tmp; + + if (ret == -EAGAIN) + return ret; + + dwc3_stop_active_transfer(dep, true, true); + + list_for_each_entry_safe(req, tmp, &dep->started_list, list) + dwc3_gadget_move_cancelled_request(req); + + /* If ep isn't started, then there's no end transfer pending */ + if (!(dep->flags & DWC3_EP_END_TRANSFER_PENDING)) + dwc3_gadget_ep_cleanup_cancelled_requests(dep); + return ret; } From patchwork Fri Mar 13 02:18:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11435831 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 99EF66CA for ; Fri, 13 Mar 2020 02:18:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7888A206E7 for ; Fri, 13 Mar 2020 02:18:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="N2xr6p4V" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726310AbgCMCSn (ORCPT ); Thu, 12 Mar 2020 22:18:43 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:59752 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726114AbgCMCSn (ORCPT ); Thu, 12 Mar 2020 22:18:43 -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 B9E43C0F90; Fri, 13 Mar 2020 02:18:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1584065923; bh=zw1X5llw0DSrO2sR715wcLRGbpkntFZELb5bvipEvkY=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=N2xr6p4VLN2FUDOmMnkrUx7i873VALbE3m5jw0uO1w5GpORUayNllGj5DbLvWSbo2 lE0G95y0R1yBDmefz0g4AZqBLnaU/aYHx8o5ZwiQHyl+fQ7BSEq4U9h5pyGMyZohmq KMttujOYJEQWLW1zhGLCnkAeZqljk6FuyymtESXU66hs7iW+vPNswKAPI51F+Io68p MHFzoqvFO3br6gYi7ofMTDc68uYOP3KBFTASOK2+ZW+OxPGi5jgu8xYc9rgY/hdEwI 0ySfokPKbprUKwUxFfwJ9TY3Zr8Fxx/yyYjEJIEJuuWehCNffvhv1G+PQ2AIXVPw9w pdEtwhydK5dTQ== 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 45C3FA0079; Fri, 13 Mar 2020 02:18:41 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Thu, 12 Mar 2020 19:18:41 -0700 Date: Thu, 12 Mar 2020 19:18:41 -0700 Message-Id: In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH 2/3] ute: dwc3: gadget: Store resource index of start cmd 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 As long as the START_TRANSFER command completes, it provides the resource index of the endpoint. Use this when we need to issue END_TRANSFER command to an isoc endpoint to retry with a new XferNotReady event. Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 4cb7f9329657..f1aae4615cf1 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -387,9 +387,12 @@ int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd, trace_dwc3_gadget_ep_cmd(dep, cmd, params, cmd_status); - if (ret == 0 && DWC3_DEPCMD_CMD(cmd) == DWC3_DEPCMD_STARTTRANSFER) { - dep->flags |= DWC3_EP_TRANSFER_STARTED; - dwc3_gadget_ep_get_transfer_index(dep); + if (DWC3_DEPCMD_CMD(cmd) == DWC3_DEPCMD_STARTTRANSFER) { + if (ret == 0) + dep->flags |= DWC3_EP_TRANSFER_STARTED; + + if (ret != -ETIMEDOUT) + dwc3_gadget_ep_get_transfer_index(dep); } if (saved_config) { From patchwork Fri Mar 13 02:18:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11435835 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 EDA4616B1 for ; Fri, 13 Mar 2020 02:18:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CD9D620716 for ; Fri, 13 Mar 2020 02:18:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="d+DNsNPR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726446AbgCMCSt (ORCPT ); Thu, 12 Mar 2020 22:18:49 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:59758 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726114AbgCMCSt (ORCPT ); Thu, 12 Mar 2020 22:18:49 -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 C319BC0F90; Fri, 13 Mar 2020 02:18:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1584065928; bh=pO/SNUjIYWdzbrgJFeSQiHKyCGbQNnG/ACsmePrUyfk=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=d+DNsNPR+8HlKcTceep9bntU1qXGW343AczVaBMtU5yYAxxUW8lKd7gmYc/JcCX7q aEdOHN/3vkQzXfNxYDKuVrtI3/SFe/VC27za1OmvhK1JlkJeg8VxEByv/nOICQPFMH LHoBry0XQg5HJ2xs+aZ/LHYxWKhfZzGYXi14jwfVHzIDO7/8AcXR3xqPyOHrWFtDV+ rK3Uuda8phHbUbZyZ0sqFrATQXx9oBkmfM6gYmoPKSEBh+q3Mwbe5k/kMXesBbOUFW Mrc6r9srCL9DohiVWj1MD7da4rfWS3f2pRlVkfVNS2bCF41XfvXD3HhFnUaznPJ9oi kTBM8jIrkFhGg== 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 958B2A0072; Fri, 13 Mar 2020 02:18:47 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Thu, 12 Mar 2020 19:18:47 -0700 Date: Thu, 12 Mar 2020 19:18:47 -0700 Message-Id: In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH 3/3] usb: dwc3: gadget: Issue END_TRANSFER to retry isoc transfer 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 After a number of unsuccessful start isoc attempts due to bus-expiry status, issue END_TRANSFER command and retry on the next XferNotReady event. Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index f1aae4615cf1..a5ad02987536 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1406,7 +1406,8 @@ static int __dwc3_gadget_start_isoc(struct dwc3_ep *dep) int ret; int i; - if (list_empty(&dep->pending_list)) { + if (list_empty(&dep->pending_list) && + list_empty(&dep->started_list)) { dep->flags |= DWC3_EP_PENDING_REQUEST; return -EAGAIN; } @@ -1429,6 +1430,27 @@ static int __dwc3_gadget_start_isoc(struct dwc3_ep *dep) break; } + /* + * After a number of unsuccessful start attempts due to bus-expiry + * status, issue END_TRANSFER command and retry on the next XferNotReady + * event. + */ + if (ret == -EAGAIN) { + struct dwc3_gadget_ep_cmd_params params; + u32 cmd; + + cmd = DWC3_DEPCMD_ENDTRANSFER | + DWC3_DEPCMD_CMDIOC | + DWC3_DEPCMD_PARAM(dep->resource_index); + + dep->resource_index = 0; + memset(¶ms, 0, sizeof(params)); + + ret = dwc3_send_gadget_ep_cmd(dep, cmd, ¶ms); + if (!ret) + dep->flags |= DWC3_EP_END_TRANSFER_PENDING; + } + return ret; } @@ -2609,6 +2631,18 @@ static void dwc3_gadget_endpoint_transfer_not_ready(struct dwc3_ep *dep, const struct dwc3_event_depevt *event) { dwc3_gadget_endpoint_frame_from_event(dep, event); + + /* + * The XferNotReady event is generated only once before the endpoint + * starts. It will be generated again when END_TRANSFER command is + * issued. For some controller versions, the XferNotReady event may be + * generated while the END_TRANSFER command is still in process. Ignore + * it and wait for the next XferNotReady event after the command is + * completed. + */ + if (dep->flags & DWC3_EP_END_TRANSFER_PENDING) + return; + (void) __dwc3_gadget_start_isoc(dep); }