From patchwork Wed May 6 02:46:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11530147 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 72967139F for ; Wed, 6 May 2020 02:46:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 51FEC2075E for ; Wed, 6 May 2020 02:46:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="PjnwE1YM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726470AbgEFCqQ (ORCPT ); Tue, 5 May 2020 22:46:16 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:50054 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725915AbgEFCqQ (ORCPT ); Tue, 5 May 2020 22:46:16 -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 1C008C1324; Wed, 6 May 2020 02:46:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1588733175; bh=AZYtsK6RyTCnkegFvkbkNFPoHGJNBqM/RZHtQa2EkQk=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=PjnwE1YMLGsmAE/ZOoDFvba7c95TNIjbbnbPJqTJ834aA4p8tsFb1ZL88Y7XOooT+ AG3RfT0JRzdeb3u0Lh45RRSEf97arhsRbx9/jU0tJZk2yh6HLylgWrOPzFMFSjJCJZ clnMk4BaYI12hvoI86iRCo9OPa9JOMJmd6gcoYOQiIRsa5NA5Qg7eDtu8hTUrBsEhT EC3hrPhNhhJOHiURuPdgdYu2j5bPYUgNTLulYXhIkJC6uH8B063GcQo/dPGSji5RXj IHdcTcH6FZQI1n8yJ28QjiyPZJRbKGfrIZCvLxS4pCWlH2EXis+ACyDMga7ojoBSiz nK1wH5yODscRA== 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 C189CA025E; Wed, 6 May 2020 02:46:13 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Tue, 05 May 2020 19:46:13 -0700 Date: Tue, 05 May 2020 19:46:13 -0700 Message-Id: In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH v2 01/11] usb: gadget: Introduce usb_request->is_last 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 To take advantage of DWC3 internal TRB prefetch and cache for performance, inform the controller the last request with stream_id before switching to a different stream transfer. This allows the controller to maintain its transfer burst within the stream ID. Introduce the usb-request is_last field to help inform the DWC3 controller of this. Signed-off-by: Thinh Nguyen --- include/linux/usb/gadget.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index e959c09a97c9..281eabae7f33 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -42,6 +42,8 @@ struct usb_ep; * @num_mapped_sgs: number of SG entries mapped to DMA (internal) * @length: Length of that data * @stream_id: The stream id, when USB3.0 bulk streams are being used + * @is_last: Indicates if this is the last request of a stream_id before + * switching to a different stream (required for DWC3 controllers). * @no_interrupt: If true, hints that no completion irq is needed. * Helpful sometimes with deep request queues that are handled * directly by DMA controllers. @@ -104,6 +106,7 @@ struct usb_request { unsigned num_mapped_sgs; unsigned stream_id:16; + unsigned is_last:1; unsigned no_interrupt:1; unsigned zero:1; unsigned short_not_ok:1; From patchwork Wed May 6 02:46:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11530149 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 C4B56139F for ; Wed, 6 May 2020 02:46:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A372420721 for ; Wed, 6 May 2020 02:46:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="OrMo32hB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726477AbgEFCqX (ORCPT ); Tue, 5 May 2020 22:46:23 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:50070 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725915AbgEFCqW (ORCPT ); Tue, 5 May 2020 22:46:22 -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 5BD07C1324; Wed, 6 May 2020 02:46:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1588733182; bh=6nEFgLMiGfghXIIIhHOa/3OHX63NMi6tx7ygjwoLhjI=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=OrMo32hB2VaIxbdu5u4cIxz4/JBFOFkckjU3LZmfZQStFG2NaGjTDxPG3Is1gGS6p qWoXnS6vpl6pIAZLXxXBhIRcXVJZ1M1x+/7KquYD22Y8bKAnNuv439Fwt8Da7lqM9k g4oyvsz35w7+z+oUYTxZV4+kyRybKDnApNpzmsFhshOQj4h9KA8mxr8Sa4kj1kfyJv hSeR2b9ujHbJS5dInbOa3eS2lhMAyO7hpRiPZMtUJRJMU8lyrcCV3TNtThFG1H6WBh j2N96hfAG4UfN0lYWlsuQfiGstLCaz9k8oc2qOe9Mu62xvrJPwy70SUvK2Cwj9bbOh CrHO38eEou/cg== 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 0E432A0252; Wed, 6 May 2020 02:46:19 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Tue, 05 May 2020 19:46:19 -0700 Date: Tue, 05 May 2020 19:46:19 -0700 Message-Id: In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH v2 02/11] usb: gadget: f_tcm: Inform last stream request 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 Set the request->is_last to each stream request to indicate that the request is the last stream request of a transfer. The DWC3 controller needs to know this info to properly switch streams. The current implementation of f_tcm uses a single request per transfer, so every stream request is the last of its stream. Signed-off-by: Thinh Nguyen --- drivers/usb/gadget/function/f_tcm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index 36504931b2d1..2979cbe4d95f 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -531,6 +531,7 @@ static int uasp_prepare_r_request(struct usbg_cmd *cmd) stream->req_in->sg = se_cmd->t_data_sg; } + stream->req_in->is_last = 1; stream->req_in->complete = uasp_status_data_cmpl; stream->req_in->length = se_cmd->data_length; stream->req_in->context = cmd; @@ -554,6 +555,7 @@ static void uasp_prepare_status(struct usbg_cmd *cmd) */ iu->len = cpu_to_be16(se_cmd->scsi_sense_length); iu->status = se_cmd->scsi_status; + stream->req_status->is_last = 1; stream->req_status->context = cmd; stream->req_status->length = se_cmd->scsi_sense_length + 16; stream->req_status->buf = iu; @@ -991,6 +993,7 @@ static int usbg_prepare_w_request(struct usbg_cmd *cmd, struct usb_request *req) req->sg = se_cmd->t_data_sg; } + req->is_last = 1; req->complete = usbg_data_write_cmpl; req->length = se_cmd->data_length; req->context = cmd; From patchwork Wed May 6 02:46:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11530151 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 62FFB139F for ; Wed, 6 May 2020 02:46:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4A7582075E for ; Wed, 6 May 2020 02:46:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="k27q1iH/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726495AbgEFCq3 (ORCPT ); Tue, 5 May 2020 22:46:29 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:35308 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725915AbgEFCq2 (ORCPT ); Tue, 5 May 2020 22:46:28 -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 4E1FF407EB; Wed, 6 May 2020 02:46:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1588733188; bh=ckRmBTKph7EhgNhUtFY9c7FoFMzx8WlCbW95deYWMrM=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=k27q1iH/kWD20MFR6h1gVBqcVA9Vzz/SqqvgEY/2cCT1NTA0JdgFIIFJTUkDAO/PI opyFBNE/neYr7LUZ18rcQf/h2PUCu8XaKhemKVPOqwPS4q33FbCi8KJyG0xJYAXoh+ PpmgMT53xZO8TIVB96a55T/L2K0BYIj2VwQkDtRGUgZNSHtRtKysoD2tdbEdpPKPsd tQnxbHqyWEhz7rjLwfK262Z8HKRmjn9+7TqlIPnjBxx6fzXBlCUgopwWX0ClTVDLFE DE4PEmCxoHPl8cdeSjGsQp7h4Pp7ObitnWpVnMDc4FYd2wDLk5RjdRg7xpfgp/ARbZ 7yjO/neZsidAw== 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 386B3A0259; Wed, 6 May 2020 02:46:27 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Tue, 05 May 2020 19:46:27 -0700 Date: Tue, 05 May 2020 19:46:27 -0700 Message-Id: <3cf43b3df0c0523a2ac7f853dd5c30c0c98efa49.1588732815.git.thinhn@synopsys.com> In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH v2 03/11] usb: dwc3: gadget: Continue to process pending 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 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 4ca3e197bee4..865e6fbb7360 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2605,10 +2605,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); @@ -2632,6 +2630,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) { @@ -2661,6 +2677,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. From patchwork Wed May 6 02:46:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11530153 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 652E9139F for ; Wed, 6 May 2020 02:46:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 40F942075E for ; Wed, 6 May 2020 02:46:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="DizfBtK7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726129AbgEFCqf (ORCPT ); Tue, 5 May 2020 22:46:35 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:50086 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725915AbgEFCqf (ORCPT ); Tue, 5 May 2020 22:46:35 -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 7BDAFC1324; Wed, 6 May 2020 02:46:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1588733194; bh=xt6Sw5O+Er2S1enRqwZlVgsKdI0/x2gDivNEbRVKUXw=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=DizfBtK7LAx6gf1ddwXnGC0fcsrbREdxyQq9y3MFZXLWhr4CMwoFlQt9BokzJfaJ7 5EfIpjLbSoRGcPdxbiMIl8lTcs9Rd/mF7tImHx8MPyQspQYbaLp0Xw/YPMnlZijcH6 CWPWFwM/tMiIxs5epPnQDRUI4fMuYRnWCVElAJQkbj8u0S0nRbm+H90C0AX3FQrsCV Gtd2jkrNxoyYgv5OkD9va8vRfi4bl9UPUOr7++BlGo5FbYRLT0bdjFGx5nQCvyw4oM IEgocpnicmI6lMxl9NijMnKMJqjvqn8geFDFPr9UDljMgEx12gRCeqAZ0Mp/c3chVF WiaeIeRSeh8pQ== 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 4ACD6A025B; Wed, 6 May 2020 02:46:33 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Tue, 05 May 2020 19:46:33 -0700 Date: Tue, 05 May 2020 19:46:33 -0700 Message-Id: In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH v2 04/11] usb: dwc3: gadget: Check for in-progress END_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 While handling TRBs completion, if a END_TRANSFER command isn't completed, don't kick new transfer or issue END_TRANSFER command. Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 865e6fbb7360..3bb6f847a865 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2675,11 +2675,15 @@ static void dwc3_gadget_endpoint_transfer_in_progress(struct dwc3_ep *dep, dwc3_gadget_ep_cleanup_completed_requests(dep, event, status); + if (dep->flags & DWC3_EP_END_TRANSFER_PENDING) + goto out; + if (stop) dwc3_stop_active_transfer(dep, true, true); else if (dwc3_gadget_ep_should_continue(dep)) __dwc3_gadget_kick_transfer(dep); +out: /* * WORKAROUND: This is the 2nd half of U1/U2 -> U0 workaround. * See dwc3_gadget_linksts_change_interrupt() for 1st half. From patchwork Wed May 6 02:46:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11530155 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 6187E15AB for ; Wed, 6 May 2020 02:46:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4842B2078D for ; Wed, 6 May 2020 02:46:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="HSjcrW0E" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726509AbgEFCql (ORCPT ); Tue, 5 May 2020 22:46:41 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:35324 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725915AbgEFCqk (ORCPT ); Tue, 5 May 2020 22:46:40 -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 742DA407EB; Wed, 6 May 2020 02:46:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1588733200; bh=fVQGphNaK6vsw+djrlG972AwxHW+TxpYNDAmECvVKeA=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=HSjcrW0Ezlw80H7aOWNLE+EUL3KixgvX93sroe2FRcBFrUX+ZdCWlfNZxAmpQ61zt wZRm9CqdwZni3egJ4nnTgGrveW6z6jo9DxWMqyUIFHBlFn2LJr6pRUiWuKX/GP94Cu Nt0OhGjZsjnVudhVY/qF2VeutgMm5QsNb8Of44zob+kwI7jfOtNtjVFVTtwJyiMzK2 pxnOK+/FZIQIlHeXwweM7Xqi8ADvBqJbmr9vrnqNirmJSu9JRhpx7JvBOUTCCIQCDG MtGfxSy+RAQGIaTdDeotL3fzUFvVYSxiqhdadVPAAu6pergn1O15uCiWm9A4XQqIU6 rpO+CoNcl+p4w== 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 5DBE7A025B; Wed, 6 May 2020 02:46:39 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Tue, 05 May 2020 19:46:39 -0700 Date: Tue, 05 May 2020 19:46:39 -0700 Message-Id: <74771c4ae93eb67e16f868b7b62f576c03d866a7.1588732815.git.thinhn@synopsys.com> In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH v2 05/11] usb: dwc3: gadget: Refactor TRB completion handler 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 To prepare for handling of XferComplete event, let's refactor and split up dwc3_gadget_endpoint_transfer_in_progress() to handle TRBs completion for different events. The handling of TRBs completion will be the same, but the status of XferComplete event is different than XferInProgress. No functional change in this commit. Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 3bb6f847a865..5f98b424f20b 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2654,34 +2654,22 @@ static void dwc3_gadget_endpoint_frame_from_event(struct dwc3_ep *dep, dep->frame_number = event->parameters; } -static void dwc3_gadget_endpoint_transfer_in_progress(struct dwc3_ep *dep, - const struct dwc3_event_depevt *event) +static bool dwc3_gadget_endpoint_trbs_complete(struct dwc3_ep *dep, + const struct dwc3_event_depevt *event, int status) { struct dwc3 *dwc = dep->dwc; - unsigned status = 0; - bool stop = false; - - dwc3_gadget_endpoint_frame_from_event(dep, event); - - if (event->status & DEPEVT_STATUS_BUSERR) - status = -ECONNRESET; - - if (event->status & DEPEVT_STATUS_MISSED_ISOC) { - status = -EXDEV; - - if (list_empty(&dep->started_list)) - stop = true; - } + bool no_started_trb = true; dwc3_gadget_ep_cleanup_completed_requests(dep, event, status); if (dep->flags & DWC3_EP_END_TRANSFER_PENDING) goto out; - if (stop) + if (status == -EXDEV && list_empty(&dep->started_list)) dwc3_stop_active_transfer(dep, true, true); else if (dwc3_gadget_ep_should_continue(dep)) - __dwc3_gadget_kick_transfer(dep); + if (__dwc3_gadget_kick_transfer(dep) == 0) + no_started_trb = false; out: /* @@ -2699,7 +2687,7 @@ static void dwc3_gadget_endpoint_transfer_in_progress(struct dwc3_ep *dep, continue; if (!list_empty(&dep->started_list)) - return; + return no_started_trb; } reg = dwc3_readl(dwc->regs, DWC3_DCTL); @@ -2708,6 +2696,25 @@ static void dwc3_gadget_endpoint_transfer_in_progress(struct dwc3_ep *dep, dwc->u1u2 = 0; } + + return no_started_trb; +} + +static void dwc3_gadget_endpoint_transfer_in_progress(struct dwc3_ep *dep, + const struct dwc3_event_depevt *event) +{ + int status = 0; + + if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) + dwc3_gadget_endpoint_frame_from_event(dep, event); + + if (event->status & DEPEVT_STATUS_BUSERR) + status = -ECONNRESET; + + if (event->status & DEPEVT_STATUS_MISSED_ISOC) + status = -EXDEV; + + dwc3_gadget_endpoint_trbs_complete(dep, event, status); } static void dwc3_gadget_endpoint_transfer_not_ready(struct dwc3_ep *dep, From patchwork Wed May 6 02:46:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11530157 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 8ED5815AB for ; Wed, 6 May 2020 02:46:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C7A92075E for ; Wed, 6 May 2020 02:46:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="SZDlTnjv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726514AbgEFCqr (ORCPT ); Tue, 5 May 2020 22:46:47 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:50092 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725915AbgEFCqr (ORCPT ); Tue, 5 May 2020 22:46:47 -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 A7DDFC1324; Wed, 6 May 2020 02:46:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1588733206; bh=X/Vlrm4XVv8F68xYVlydCczkB39v5861HS30a8cJ7os=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=SZDlTnjv5Jv5pLp0WAlhFNLIZqNPV009gV3ucWkhCfwbG9on6QzDosEWCJKYFcIIi CXOa3RjutBeuk+wl2yjOee5NMzOjzSNebyKf5NL3xyd+U0YHePtVAWsGtGho7gDzur vtGmJD9gCmgPaPh+LVYmYOFtzJHTrY22L7MU7Ca3kyKssBmu2sFp6rmCOkZ7j9Af9U bgecJgaWLtPSDTWBWSjMezPettlwGd5YQ2ObBULUyFtAN4plOl9I/b+wqhNK9T4da7 96B3GzbR4eIQUcHT+quJZNjSntbm55soRtkznS87TCcQfKBUOe8qnRkLHPKHgley3P U0dB8WhQ/8z2A== 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 704B3A007C; Wed, 6 May 2020 02:46:45 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Tue, 05 May 2020 19:46:45 -0700 Date: Tue, 05 May 2020 19:46:45 -0700 Message-Id: <3c12b4e3f719509310257778a8524886a7efe95b.1588732815.git.thinhn@synopsys.com> In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH v2 06/11] usb: dwc3: gadget: Enable XferComplete event 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 To switch from one stream to another, this requires the driver to start a new transfer with a specific stream ID. For a transfer to complete, the driver needs to indicate the last TRB of a transfer, and it needs to enable XferComplete event to handle completed TRBs of a transfer. Let's enable this event only for stream capable endpoints. Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 5f98b424f20b..81aa7de4cb17 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -579,6 +579,7 @@ static int dwc3_gadget_set_ep_config(struct dwc3_ep *dep, unsigned int action) if (usb_ss_max_streams(comp_desc) && usb_endpoint_xfer_bulk(desc)) { params.param1 |= DWC3_DEPCFG_STREAM_CAPABLE + | DWC3_DEPCFG_XFER_COMPLETE_EN | DWC3_DEPCFG_STREAM_EVENT_EN; dep->stream_capable = true; } From patchwork Wed May 6 02:46:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11530159 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 DACB3139F for ; Wed, 6 May 2020 02:46:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C15642075E for ; Wed, 6 May 2020 02:46:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="IZlrOMGH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726308AbgEFCqx (ORCPT ); Tue, 5 May 2020 22:46:53 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:35330 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726267AbgEFCqw (ORCPT ); Tue, 5 May 2020 22:46:52 -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 99AC2407EB; Wed, 6 May 2020 02:46:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1588733212; bh=tWvLRuvfGh5JXlk8gPVgcTVAjJHe67SDYV/sJT9UvmM=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=IZlrOMGHHIG2LWIdIZHwTJM97wk4lX0nj/RGyYsF12roZQ/G2T08u1LJJeG9CdmtI eb+Qrd1cyVsIAkkJkncgoeypfc6/fPRRnbncM1r61ZxsUpzcjFhgGhINDL4PJzg/uv MYFGogE17xHE9hK4w2Co4Dbks5kp7xQNorD553Xpi1wlN2/lRcY1/O6sHQzei1odps MB0u4wkmbl7OWsdVsISlzRlnF6YdUzNAlq0/AIhmGG3vARVMJn4/pAEQ2lC1cv2+TA Gzbd7e+At0pdhbF5VqvLF48xgtge/Gq0WmDuU0ZVuNAIWBNZ9yCnN37KPwdAbQfgdQ Uqd04RuUvpBuQ== 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 8352AA006D; Wed, 6 May 2020 02:46:51 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Tue, 05 May 2020 19:46:51 -0700 Date: Tue, 05 May 2020 19:46:51 -0700 Message-Id: <379e73bfe1f4afc51be8b4ee3247387f3196fcb0.1588732815.git.thinhn@synopsys.com> In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH v2 07/11] usb: dwc3: gadget: Handle XferComplete for streams 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 In DWC3, to prepare TRBs for streams, all the TRBs of a transfer will use the same stream ID. To start a new stream, the driver needs to wait for the current transfer to complete or ended (by END_TRANFER command). As a result, inform the controller of the last TRB of a transfer so that it knows when a transfer completes and start a new transfer of a new stream. Even though the transfer completion handling can be applied for other non-isoc endpoints, only do it for streams due to its requirement. It's better to keep the controller's TRB cache full than waiting for transfer completion and starting a new transfer. Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 81aa7de4cb17..052f6dc52a51 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -919,7 +919,8 @@ static u32 dwc3_calc_trbs_left(struct dwc3_ep *dep) static void __dwc3_prepare_one_trb(struct dwc3_ep *dep, struct dwc3_trb *trb, dma_addr_t dma, unsigned length, unsigned chain, unsigned node, - unsigned stream_id, unsigned short_not_ok, unsigned no_interrupt) + unsigned stream_id, unsigned short_not_ok, + unsigned no_interrupt, unsigned is_last) { struct dwc3 *dwc = dep->dwc; struct usb_gadget *gadget = &dwc->gadget; @@ -1012,6 +1013,8 @@ static void __dwc3_prepare_one_trb(struct dwc3_ep *dep, struct dwc3_trb *trb, if (chain) trb->ctrl |= DWC3_TRB_CTRL_CHN; + else if (dep->stream_capable && is_last) + trb->ctrl |= DWC3_TRB_CTRL_LST; if (usb_endpoint_xfer_bulk(dep->endpoint.desc) && dep->stream_capable) trb->ctrl |= DWC3_TRB_CTRL_SID_SOFN(stream_id); @@ -1039,6 +1042,7 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep, unsigned stream_id = req->request.stream_id; unsigned short_not_ok = req->request.short_not_ok; unsigned no_interrupt = req->request.no_interrupt; + unsigned is_last = req->request.is_last; if (req->request.num_sgs > 0) { length = sg_dma_len(req->start_sg); @@ -1059,7 +1063,7 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep, req->num_trbs++; __dwc3_prepare_one_trb(dep, trb, dma, length, chain, node, - stream_id, short_not_ok, no_interrupt); + stream_id, short_not_ok, no_interrupt, is_last); } static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, @@ -1104,7 +1108,8 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, maxp - rem, false, 1, req->request.stream_id, req->request.short_not_ok, - req->request.no_interrupt); + req->request.no_interrupt, + req->request.is_last); } else { dwc3_prepare_one_trb(dep, req, chain, i); } @@ -1148,7 +1153,8 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr, maxp - rem, false, 1, req->request.stream_id, req->request.short_not_ok, - req->request.no_interrupt); + req->request.no_interrupt, + req->request.is_last); } else if (req->request.zero && req->request.length && (IS_ALIGNED(req->request.length, maxp))) { struct dwc3 *dwc = dep->dwc; @@ -1165,7 +1171,8 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr, 0, false, 1, req->request.stream_id, req->request.short_not_ok, - req->request.no_interrupt); + req->request.no_interrupt, + req->request.is_last); } else { dwc3_prepare_one_trb(dep, req, false, 0); } @@ -2718,6 +2725,19 @@ static void dwc3_gadget_endpoint_transfer_in_progress(struct dwc3_ep *dep, dwc3_gadget_endpoint_trbs_complete(dep, event, status); } +static void dwc3_gadget_endpoint_transfer_complete(struct dwc3_ep *dep, + const struct dwc3_event_depevt *event) +{ + int status = 0; + + dep->flags &= ~DWC3_EP_TRANSFER_STARTED; + + if (event->status & DEPEVT_STATUS_BUSERR) + status = -ECONNRESET; + + dwc3_gadget_endpoint_trbs_complete(dep, event, status); +} + static void dwc3_gadget_endpoint_transfer_not_ready(struct dwc3_ep *dep, const struct dwc3_event_depevt *event) { @@ -2781,8 +2801,10 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc, dep->flags &= ~DWC3_EP_DELAY_START; } break; - case DWC3_DEPEVT_STREAMEVT: case DWC3_DEPEVT_XFERCOMPLETE: + dwc3_gadget_endpoint_transfer_complete(dep, event); + break; + case DWC3_DEPEVT_STREAMEVT: case DWC3_DEPEVT_RXTXFIFOEVT: break; } From patchwork Wed May 6 02:46: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: 11530161 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 C66B5139F for ; Wed, 6 May 2020 02:47:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AE7862078D for ; Wed, 6 May 2020 02:47:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="AD/aY3Yd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725966AbgEFCrA (ORCPT ); Tue, 5 May 2020 22:47:00 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:50100 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725900AbgEFCq7 (ORCPT ); Tue, 5 May 2020 22:46:59 -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 C5DDAC1324; Wed, 6 May 2020 02:46:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1588733218; bh=0SfLJBqomQSNCzEXBWY9qdA1GMz+7S/c7taKJul25Hc=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=AD/aY3YdxzOpvJuOg/X5iTlnuGInGWxvfr7GT5yoRGfxN9pvqgou2nu9NQxHzt0VZ cJMhirLbY+9oZcWk4Xyh7l315tVYQj6H5ngE7JS17TXKVbceTvVLOYW+A0vHfp5v0v 2lcLDLNOI2cH/lMm3uYADClYAXoicHbNMVQU2Od6YwO5b6JdMgC7Jkh+XM+W25DDps MK2VQpdlLz2T9eSJ/807YfKofhpfOz9EmLCuxgmLFDAuLD3LLDlEZhZmX1DXUVOlGZ x52SMRT7lnqSB2W2IdB74035dG8Q/Qc9G+rK5gyJCIl7Xo9rEMbI13JD8WpglbF3IO Hge6XDFWUP2Mw== 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 9575DA0259; Wed, 6 May 2020 02:46:57 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Tue, 05 May 2020 19:46:57 -0700 Date: Tue, 05 May 2020 19:46:57 -0700 Message-Id: <710d4c82ec587f6653c476b0ec5a9f94c7ab7446.1588732815.git.thinhn@synopsys.com> In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH v2 08/11] usb: dwc3: gadget: Wait for transfer completion 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 transfer is in-progress, any new request should not kick off another transfer. The driver needs to wait for the current transfer to complete before starting off the next transfer. Introduce a new flag DWC3_EP_WAIT_TRANSFER_COMPLETE for this. Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/core.h | 1 + drivers/usb/dwc3/gadget.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 7204a838ec06..b11183a715a7 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -701,6 +701,7 @@ struct dwc3_ep { #define DWC3_EP_END_TRANSFER_PENDING BIT(4) #define DWC3_EP_PENDING_REQUEST BIT(5) #define DWC3_EP_DELAY_START BIT(6) +#define DWC3_EP_WAIT_TRANSFER_COMPLETE BIT(7) /* This last one is specific to EP0 */ #define DWC3_EP0_DIR_IN BIT(31) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 052f6dc52a51..97c6a5785725 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1292,6 +1292,9 @@ static int __dwc3_gadget_kick_transfer(struct dwc3_ep *dep) return ret; } + if (dep->stream_capable && req->request.is_last) + dep->flags |= DWC3_EP_WAIT_TRANSFER_COMPLETE; + return 0; } @@ -1498,6 +1501,9 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req) list_add_tail(&req->list, &dep->pending_list); req->status = DWC3_REQUEST_STATUS_QUEUED; + if (dep->flags & DWC3_EP_WAIT_TRANSFER_COMPLETE) + return 0; + /* Start the transfer only after the END_TRANSFER is completed */ if (dep->flags & DWC3_EP_END_TRANSFER_PENDING) { dep->flags |= DWC3_EP_DELAY_START; @@ -2735,7 +2741,8 @@ static void dwc3_gadget_endpoint_transfer_complete(struct dwc3_ep *dep, if (event->status & DEPEVT_STATUS_BUSERR) status = -ECONNRESET; - dwc3_gadget_endpoint_trbs_complete(dep, event, status); + if (dwc3_gadget_endpoint_trbs_complete(dep, event, status)) + dep->flags &= ~DWC3_EP_WAIT_TRANSFER_COMPLETE; } static void dwc3_gadget_endpoint_transfer_not_ready(struct dwc3_ep *dep, From patchwork Wed May 6 02:47:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11530163 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 A7F0117E8 for ; Wed, 6 May 2020 02:47:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 85D0120721 for ; Wed, 6 May 2020 02:47:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="dq06K5Ob" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726222AbgEFCrG (ORCPT ); Tue, 5 May 2020 22:47:06 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:50106 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725900AbgEFCrF (ORCPT ); Tue, 5 May 2020 22:47:05 -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 D9699C1324; Wed, 6 May 2020 02:47:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1588733224; bh=x266bhHc995vTrO+GJqke9RLV7rizATihZjNwl6K25w=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=dq06K5ObXQO0Xip5N1m9Kka51dhGFPJgzltXfT4gdvuXmFx7vJM7kWpuqtAAIYgm4 jl6NujnyTsLyhiaGT7hOLf3lXx6U6EGNed68eMyQfRf+fw3qVW6Q07/NiIK8rUI41T UNi3eOGXfzNknUd/MyjFUbPT+hgYy1Z+gq5DrU6SzZi1hsq0DqW9DCjxoPZDrevLcz EsN0I80mlmkr0gQYEDWb9AkPBgx7KT/ur9+CoDYmDSyNlVTyXjBQVY2Pd5d52+NRvH rQYYfWR2YhsZQ1z9ljo36TtqgZqdLRHbt4hr4OrbJ1WQ79Wj98GH7xIpk/FglEDmle GcZpXmlxEeSZQ== 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 A945FA006D; Wed, 6 May 2020 02:47:03 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Tue, 05 May 2020 19:47:03 -0700 Date: Tue, 05 May 2020 19:47:03 -0700 Message-Id: In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH v2 09/11] usb: dwc3: gadget: Don't prepare beyond a 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 Don't prepare TRBs beyond a transfer. In DWC_usb32, its transfer burst capability may try to read and use TRBs beyond the active transfer. For other controllers, they don't process the next transfer TRBs until the current transfer is completed. Explicitly prevent preparing TRBs ahead for all controllers. Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 97c6a5785725..07824b670440 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1231,6 +1231,14 @@ static void dwc3_prepare_trbs(struct dwc3_ep *dep) if (!dwc3_calc_trbs_left(dep)) return; + + /* + * Don't prepare beyond a transfer. In DWC_usb32, its transfer + * burst capability may try to read and use TRBs beyond the + * active transfer instead of stopping. + */ + if (dep->stream_capable && req->request.is_last) + return; } } From patchwork Wed May 6 02:47:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11530165 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 D8EF215AB for ; Wed, 6 May 2020 02:47:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB6EE2075E for ; Wed, 6 May 2020 02:47:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="ej+r1gWW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726267AbgEFCrM (ORCPT ); Tue, 5 May 2020 22:47:12 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:35350 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725900AbgEFCrL (ORCPT ); Tue, 5 May 2020 22:47:11 -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 D2EC4407EB; Wed, 6 May 2020 02:47:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1588733230; bh=QJEDb6O5ZScCj1lbVmTqdBKZOam2RSzMoqvwYG5aHpA=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=ej+r1gWWk9sd5bW+JJxM+LsqTiatODHgAb/mWpUzxTibMNF/wzbW88mVrybOzk3q/ 2bHa2lRLgHZN4W8nRx9j+a7evgfdcEw6mgBAOumAcKr6lekSe5m97pdpgqOGTTGnU6 k5aYxVIWm4IR+nt7M9tvaNcnkFzs3I9/owhW8f39nwh6fF9PNxRUHNgXHglaOrvMQP EQYDZzOGA1KbeSRxutwzdGFfIoOm3q0ku8+FZKPDPp/9bsUavbhl9Qkl763xl2WT4t Rz1Uf4Dd7GvdJ+u7T0h51bzkFi4L4dZ2XjKspp+jbUG+igN7dR1WAxFl8YmAZTKzAI ajKmnIAC1jvZQ== 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 BC49DA0252; Wed, 6 May 2020 02:47:09 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Tue, 05 May 2020 19:47:09 -0700 Date: Tue, 05 May 2020 19:47:09 -0700 Message-Id: <2e4105b7476563b25a8b4e0896fdcd76b6a29b9c.1588732815.git.thinhn@synopsys.com> In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH v2 10/11] usb: dwc3: gadget: Handle stream transfers 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 Overview of stream transfer requirement: * A transfer will have a set of TRBs of the same stream ID. * A transfer is started with a stream ID in START_TRANSFER command. * A new stream will only start when the previous completes. Overview of stream events: * A "prime" from host indicates that its endpoints are active (buffers prepared and ready to receive/transmit data). The controller automatically initiates stream if it sees this. * A "NoStream" rejection event indicates that the host isn't ready. Host will put the endpoint back to idle state. Device may need to reinitiate the stream to start transfer again. * A Stream Found event means host accepted device initiated stream. Nothing needs to be done from driver. To initiate a stream, the driver will issue START_TRANSFER command with a stream ID. To reinitiate the stream, the driver must issue END_TRANSFER and restart the transfer with START_TRANSFER command with the same stream ID. This implementation handles device-initated streams (e.g. UASP driver). It also handles some hosts' quirky behavior where they only prime each endpoint once. Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/core.h | 8 ++++ drivers/usb/dwc3/debug.h | 2 + drivers/usb/dwc3/gadget.c | 97 +++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 104 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index b11183a715a7..4def088329c7 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -495,6 +495,7 @@ #define DWC3_DGCMD_SELECTED_FIFO_FLUSH 0x09 #define DWC3_DGCMD_ALL_FIFO_FLUSH 0x0a #define DWC3_DGCMD_SET_ENDPOINT_NRDY 0x0c +#define DWC3_DGCMD_SET_ENDPOINT_PRIME 0x0d #define DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK 0x10 #define DWC3_DGCMD_STATUS(n) (((n) >> 12) & 0x0F) @@ -702,6 +703,9 @@ struct dwc3_ep { #define DWC3_EP_PENDING_REQUEST BIT(5) #define DWC3_EP_DELAY_START BIT(6) #define DWC3_EP_WAIT_TRANSFER_COMPLETE BIT(7) +#define DWC3_EP_IGNORE_NEXT_NOSTREAM BIT(8) +#define DWC3_EP_FORCE_RESTART_STREAM BIT(9) +#define DWC3_EP_FIRST_STREAM_PRIMED BIT(10) /* This last one is specific to EP0 */ #define DWC3_EP0_DIR_IN BIT(31) @@ -1301,6 +1305,10 @@ struct dwc3_event_depevt { #define DEPEVT_STREAMEVT_FOUND 1 #define DEPEVT_STREAMEVT_NOTFOUND 2 +/* Stream event parameter */ +#define DEPEVT_STREAM_PRIME 0xfffe +#define DEPEVT_STREAM_NOSTREAM 0x0 + /* Control-only Status */ #define DEPEVT_STATUS_CONTROL_DATA 1 #define DEPEVT_STATUS_CONTROL_STATUS 2 diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h index 0f95656c9622..d8f600e0e88f 100644 --- a/drivers/usb/dwc3/debug.h +++ b/drivers/usb/dwc3/debug.h @@ -68,6 +68,8 @@ dwc3_gadget_generic_cmd_string(u8 cmd) return "All FIFO Flush"; case DWC3_DGCMD_SET_ENDPOINT_NRDY: return "Set Endpoint NRDY"; + case DWC3_DGCMD_SET_ENDPOINT_PRIME: + return "Set Endpoint Prime"; case DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK: return "Run SoC Bus Loopback Test"; default: diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 07824b670440..0380f76151a1 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -610,6 +610,9 @@ static int dwc3_gadget_set_ep_config(struct dwc3_ep *dep, unsigned int action) return dwc3_send_gadget_ep_cmd(dep, DWC3_DEPCMD_SETEPCONFIG, ¶ms); } +static void dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force, + bool interrupt); + /** * __dwc3_gadget_ep_enable - initializes a hw endpoint * @dep: endpoint to be initialized @@ -670,7 +673,7 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep, unsigned int action) * Issue StartTransfer here with no-op TRB so we can always rely on No * Response Update Transfer command. */ - if ((usb_endpoint_xfer_bulk(desc) && !dep->stream_capable) || + if (usb_endpoint_xfer_bulk(desc) || usb_endpoint_xfer_int(desc)) { struct dwc3_gadget_ep_cmd_params params; struct dwc3_trb *trb; @@ -689,6 +692,29 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep, unsigned int action) ret = dwc3_send_gadget_ep_cmd(dep, cmd, ¶ms); if (ret < 0) return ret; + + if (dep->stream_capable) { + /* + * For streams, at start, there maybe a race where the + * host primes the endpoint before the function driver + * queues a request to initiate a stream. In that case, + * the controller will not see the prime to generate the + * ERDY and start stream. To workaround this, issue a + * no-op TRB as normal, but end it immediately. As a + * result, when the function driver queues the request, + * the next START_TRANSFER command will cause the + * controller to generate an ERDY to initiate the + * stream. + */ + dwc3_stop_active_transfer(dep, true, true); + + /* + * All stream eps will reinitiate stream on NoStream + * rejection until we can determine that the host can + * prime after the first transfer. + */ + dep->flags |= DWC3_EP_FORCE_RESTART_STREAM; + } } out: @@ -697,8 +723,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep, unsigned int action) return 0; } -static void dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force, - bool interrupt); static void dwc3_remove_requests(struct dwc3 *dwc, struct dwc3_ep *dep) { struct dwc3_request *req; @@ -2772,6 +2796,63 @@ static void dwc3_gadget_endpoint_transfer_not_ready(struct dwc3_ep *dep, (void) __dwc3_gadget_start_isoc(dep); } +static void dwc3_gadget_endpoint_stream_event(struct dwc3_ep *dep, + const struct dwc3_event_depevt *event) +{ + struct dwc3 *dwc = dep->dwc; + + if (event->status == DEPEVT_STREAMEVT_FOUND) { + dep->flags |= DWC3_EP_FIRST_STREAM_PRIMED; + goto out; + } + + /* Note: NoStream rejection event param value is 0 and not 0xFFFF */ + switch (event->parameters) { + case DEPEVT_STREAM_PRIME: + /* + * If the host can properly transition the endpoint state from + * idle to prime after a NoStream rejection, there's no need to + * force restarting the endpoint to reinitiate the stream. To + * simplify the check, assume the host follows the USB spec if + * it primed the endpoint more than once. + */ + if (dep->flags & DWC3_EP_FORCE_RESTART_STREAM) { + if (dep->flags & DWC3_EP_FIRST_STREAM_PRIMED) + dep->flags &= ~DWC3_EP_FORCE_RESTART_STREAM; + else + dep->flags |= DWC3_EP_FIRST_STREAM_PRIMED; + } + + break; + case DEPEVT_STREAM_NOSTREAM: + if ((dep->flags & DWC3_EP_IGNORE_NEXT_NOSTREAM) || + !(dep->flags & DWC3_EP_FORCE_RESTART_STREAM) || + !(dep->flags & DWC3_EP_WAIT_TRANSFER_COMPLETE)) + break; + + /* + * If the host rejects a stream due to no active stream, by the + * USB and xHCI spec, the endpoint will be put back to idle + * state. When the host is ready (buffer added/updated), it will + * prime the endpoint to inform the usb device controller. This + * triggers the device controller to issue ERDY to restart the + * stream. However, some hosts don't follow this and keep the + * endpoint in the idle state. No prime will come despite host + * streams are updated, and the device controller will not be + * triggered to generate ERDY to move the next stream data. To + * workaround this and maintain compatibility with various + * hosts, force to reinitate the stream until the host is ready + * instead of waiting for the host to prime the endpoint. + */ + dep->flags |= DWC3_EP_DELAY_START; + dwc3_stop_active_transfer(dep, true, true); + return; + } + +out: + dep->flags &= ~DWC3_EP_IGNORE_NEXT_NOSTREAM; +} + static void dwc3_endpoint_interrupt(struct dwc3 *dwc, const struct dwc3_event_depevt *event) { @@ -2820,6 +2901,8 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc, dwc3_gadget_endpoint_transfer_complete(dep, event); break; case DWC3_DEPEVT_STREAMEVT: + dwc3_gadget_endpoint_stream_event(dep, event); + break; case DWC3_DEPEVT_RXTXFIFOEVT: break; } @@ -2911,6 +2994,14 @@ static void dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force, WARN_ON_ONCE(ret); dep->resource_index = 0; + /* + * The END_TRANSFER command will cause the controller to generate a + * NoStream Event, and it's not due to the host DP NoStream rejection. + * Ignore the next NoStream event. + */ + if (dep->stream_capable) + dep->flags |= DWC3_EP_IGNORE_NEXT_NOSTREAM; + if (!interrupt) dep->flags &= ~DWC3_EP_TRANSFER_STARTED; else From patchwork Wed May 6 02:47:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11530167 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 5ACB1139F for ; Wed, 6 May 2020 02:47:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 407C42075E for ; Wed, 6 May 2020 02:47:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="JELiGysP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726268AbgEFCrR (ORCPT ); Tue, 5 May 2020 22:47:17 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:35356 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725900AbgEFCrR (ORCPT ); Tue, 5 May 2020 22:47:17 -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 E65E1439BE; Wed, 6 May 2020 02:47:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1588733237; bh=zOD6jbscIV0qhP8yifrHCULGQmM2lESM/VgvCcX/JVg=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=JELiGysPBMxQthJszBvsrbg9VqXaagG0F56IOtr8579PFYVCJcbUWVRiJ6VDaRYZK cpsoIMdgtYY1s4f6caFfn9fHv1EGJ36SHFvH33+Jsom7lyEy0hjhJS5hPW2DkRYUPK eRcqsCJd4dULFWGKkWDAY+4w64u2uVldDLQq3bpUnxAPYZ7+4Zxr7L7VjV7hgO+DJK Jkh/1W5cl2Z4vWVTruhuzPvgbCMZiCH7Au6A0IPZNzz4HOjkEKnzUwNjZoqUJHMx4r vCOlf3qtoHtaqmgVGwlR+0eOEIH7IzIn2va5pDoacZFdvatJVUAQdWlaUdrtdgwhe8 h2vKWw7hC0zaQ== 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 CF7A6A0252; Wed, 6 May 2020 02:47:15 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Tue, 05 May 2020 19:47:15 -0700 Date: Tue, 05 May 2020 19:47:15 -0700 Message-Id: In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH v2 11/11] usb: dwc3: gadget: Use SET_EP_PRIME for NoStream 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 DWC_usb32 v1.00a and later can use SET_EP_PRIME command to reinitiate a stream. Use the command to handle NoStream rejection instead of ending and restarting the endpoint. Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/core.h | 3 +++ drivers/usb/dwc3/gadget.c | 13 ++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 4def088329c7..013f42a2b5dc 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -1161,6 +1161,9 @@ struct dwc3 { #define DWC31_REVISION_180A 0x3138302a #define DWC31_REVISION_190A 0x3139302a +#define DWC32_REVISION_ANY 0x0 +#define DWC32_REVISION_100A 0x3130302a + u32 version_type; #define DWC31_VERSIONTYPE_ANY 0x0 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 0380f76151a1..fea4fde1b5e3 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2844,9 +2844,16 @@ static void dwc3_gadget_endpoint_stream_event(struct dwc3_ep *dep, * hosts, force to reinitate the stream until the host is ready * instead of waiting for the host to prime the endpoint. */ - dep->flags |= DWC3_EP_DELAY_START; - dwc3_stop_active_transfer(dep, true, true); - return; + if (DWC3_VER_IS_WITHIN(DWC32, 100A, ANY)) { + unsigned int cmd = DWC3_DGCMD_SET_ENDPOINT_PRIME; + + dwc3_send_gadget_generic_command(dwc, cmd, dep->number); + } else { + dep->flags |= DWC3_EP_DELAY_START; + dwc3_stop_active_transfer(dep, true, true); + return; + } + break; } out: