From patchwork Sun Mar 29 23:12:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11464283 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 81EDA81 for ; Sun, 29 Mar 2020 23:13:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 60F8220748 for ; Sun, 29 Mar 2020 23:13:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="RWaJtr71" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727048AbgC2XNA (ORCPT ); Sun, 29 Mar 2020 19:13:00 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:45286 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726382AbgC2XNA (ORCPT ); Sun, 29 Mar 2020 19:13:00 -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 91E3CC0084; Sun, 29 Mar 2020 23:12:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1585523580; bh=RCGxBtxYv8rVaTq3wV0YTMUlztC7z8o6YvFJ+dJwEaA=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=RWaJtr713SG6j4Rwki7YR2+FlRzkPoksboI9p+JycmJ5bjd5Vifg7A91oKfzuYerH g/yMdzvmO9K46qnrn/d0HklHSKQqn610g53MlAmZ2GOYODo9tCYUTMU8f/Niec+S8R w728eOXlbha5usv3QpEotNE/BMnUttQtqQIHJhENdcZFDNJMrltFrvGZrIzZG6Yby2 qisfvd9Tn7fWqCX9EN4mJSBKlAYlrMNYiHJ4rUfj8/4uB8NDckM7w2m97PWXKxGKXN n45WMgD7AQn6loN+T1aug40HtHlVTi8+82RD5iWc3xSzCQJNoS0/AMy8gYq3wH6jbL Ab1DKDAClZAeA== 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 E2941A006D; Sun, 29 Mar 2020 23:12:57 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Sun, 29 Mar 2020 16:12:57 -0700 Date: Sun, 29 Mar 2020 16:12:57 -0700 Message-Id: In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH v2 1/4] 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 6d2b3de455cc..b02832ad9e72 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1220,6 +1220,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; @@ -1259,14 +1261,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 Sun Mar 29 23:13:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11464285 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 16F66913 for ; Sun, 29 Mar 2020 23:13:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E9CAA20781 for ; Sun, 29 Mar 2020 23:13:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="Wjs+SgYR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727173AbgC2XNG (ORCPT ); Sun, 29 Mar 2020 19:13:06 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:45296 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726382AbgC2XNG (ORCPT ); Sun, 29 Mar 2020 19:13:06 -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 6974CC0084; Sun, 29 Mar 2020 23:13:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1585523585; bh=ftGNMMX+UbJ0+sWej98tnEtCxrDD2tsF6QmsiMcLJkU=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=Wjs+SgYRvy5xtRyWRNLDeFwvvLqwT0gxw609+x/7OOaNiirLpBLihTAsLEBJl5xBU k9F0O8VB7V64TIg8ELXVJ6je04GjrhFFj0lwO6W3XdmyreWnC2aJ4k2ydW9l1QXMDR xeHQmz1B4PttgOyDs4izQP293PzMDtkTcQa8j+K9dkjEuntccLR3NHWfNDWVulq7LE Uhfj13RoP+I2iZiZ0+jY/owcl9/t4od3/kgjw4ViZVob3mrUJdrlYD4onx9RVO4YAt mPlQCqGmR3dvpWTShOYAVX4WP+ooYweNMssFfMxh7rkBFaAPCgceK1zwv4A03b5MG0 0x2sDoaM1aWeA== 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 38D9EA00B1; Sun, 29 Mar 2020 23:13:04 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Sun, 29 Mar 2020 16:13:04 -0700 Date: Sun, 29 Mar 2020 16:13:04 -0700 Message-Id: <7a132f0067d0969be47a082eecadf268b28f86cf.1585523081.git.thinhn@synopsys.com> In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH v2 2/4] usb: 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 b02832ad9e72..7989fe663300 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 Sun Mar 29 23:13:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11464287 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 709FA913 for ; Sun, 29 Mar 2020 23:13:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4E01920748 for ; Sun, 29 Mar 2020 23:13:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="UOJH8yHJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727191AbgC2XNL (ORCPT ); Sun, 29 Mar 2020 19:13:11 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:53112 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726382AbgC2XNL (ORCPT ); Sun, 29 Mar 2020 19:13:11 -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 649F143B0F; Sun, 29 Mar 2020 23:13:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1585523591; bh=kxDtcREaUceHbLcD6pcVdJ6rOx6X20TIrqm4cTn84BY=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=UOJH8yHJRiYLEApuO5z12+kZxiUqe9Ag3pSdLwQrMmbYOwf4/A8HGe5x6Yre+t+OY jP8+5Dj1b/wnncspVQp92mcFOqn7PhNK14Ph//PObcX4D2J0+HyO+zuxEPE2jEafF1 PmhvUazjOLbNnc9Ds6wHpywyF+TvEdpyq+zwmZv3aZ3bU0UaNZh4BpD/N/lm1P+i77 OBmBME5gosgROgY+K3/gY+X+U4tlUT7Dr0X9cvs3/qkIA61VF+LZwx2Wt5AJUimyUh qZ+CYyrVqwkQ/85anWW4dZbk7kVEaiSITghsGp2llL6JV51aAkj5astH4xS9MLxEiZ vpQ62EJH+exMg== 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 4E6A9A00B1; Sun, 29 Mar 2020 23:13:10 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Sun, 29 Mar 2020 16:13:10 -0700 Date: Sun, 29 Mar 2020 16:13:10 -0700 Message-Id: In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH v2 3/4] 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 7989fe663300..ee87b7b383f6 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1413,7 +1413,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; } @@ -1436,6 +1437,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; } @@ -2645,6 +2667,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); } From patchwork Sun Mar 29 23:13:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11464289 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 E85AC81 for ; Sun, 29 Mar 2020 23:13:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BE9D820781 for ; Sun, 29 Mar 2020 23:13:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="GD7FziVL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727192AbgC2XNS (ORCPT ); Sun, 29 Mar 2020 19:13:18 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:45328 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726382AbgC2XNS (ORCPT ); Sun, 29 Mar 2020 19:13:18 -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 9308AC0084; Sun, 29 Mar 2020 23:13:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1585523597; bh=nyZ3QBvaZomgtnCfnxNMPpDAxdv3dl+dAoNSRNRFac0=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=GD7FziVLCbId0otQ/99CmBgIn4V5zI63Bd9N6kLq0qJj7dCp/zZ8wN2E2kZWl75ff qoAUdba7mLodIIJRmREnpmuXciNaWDvsciWM9bC3B0FXF0OScRYW1byqDEXUQf/piV TImyGzesI3tosomnsN4NJDUTXxYjlnOTzXnPKYahUQ1SkGaWwANxtAX4kfML4d3NVt psNDkNh8hdj1YWQ4jlmde9wssFLFkLGL/vIl/lA9uPs4S48iL6wBoUpRYnbvLa5UhE 36hOMBQ6jzV8Vv4zM8rvy2RpzGCVnhHMe8a6whMAEVXoJsybbsZhiZ62uM+1Wp37mr oeKo8mgw0PoEQ== 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 64894A006D; Sun, 29 Mar 2020 23:13:16 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Sun, 29 Mar 2020 16:13:16 -0700 Date: Sun, 29 Mar 2020 16:13:16 -0700 Message-Id: <1538b1dfe07cb3fee30acbc8a21e44678032c088.1585523081.git.thinhn@synopsys.com> In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH v2 4/4] usb: dwc3: gadget: WARN on no-resource status 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 the driver issued START_TRANSFER and received a no-resource status, then generally there are a few reasons for this: 1) The driver did not allocate resource for the endpoint during power-on-reset initialization. 2) The transfer resource was reset. At this moment, we don't do this in the driver, but it occurs when the driver issues START_CONFIG cmd to ep0 with resource index=2. 3) The driver issues the START_TRANSFER command to an already started endpoint. Usually, this is because the END_TRANSFER command hasn't completed yet. Print out a warning to help debug this issue in the driver. Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index ee87b7b383f6..1a4fc03742aa 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -356,6 +356,8 @@ int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd, ret = 0; break; case DEPEVT_TRANSFER_NO_RESOURCE: + dev_WARN(dwc->dev, "No resource for %s\n", + dep->name); ret = -EINVAL; break; case DEPEVT_TRANSFER_BUS_EXPIRY: