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; }