From patchwork Thu Mar 7 15:22:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Grzeschik X-Patchwork-Id: 13585885 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2CE5612EBF6 for ; Thu, 7 Mar 2024 15:22:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824948; cv=none; b=Soioh0WtYs9fv7oD7VENmu9RUbLsUhD6yAIVRzAfMYSHe7zlPOzIEdI0wLSb3tEcZzusIrZXSbg9SGWz5alpry4tJk5ZipVBzxFMMBAv8BwjGDCuDzUcnpAoqgJUgtMocUcIEFE0yD6lbeOFC3D/F4PWU0bPnhfnPDohHI2OQe4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824948; c=relaxed/simple; bh=y5PPyv47vwajakI0WCCzwWI0+5CKdDwYJF4dLuKJReo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eBRRJXpWu+OzwBxqi+OA8TTo+isCMMuQ54eS5XmdrSYN+oq6j8znfdhobA4QxZqK1RVbcaiJjbg2vP2O5TgYYCBfLcggNrl3Z9Hha4xXnkkVFa6aQSfE36vbjKIp/Oxf+VgwYT9E75czwePRuYdlSPnZdU9d2dZhBXuC442AUe4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1riFZd-0007ML-5V; Thu, 07 Mar 2024 16:22:21 +0100 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1riFZb-004y6h-QD; Thu, 07 Mar 2024 16:22:19 +0100 Received: from localhost ([::1] helo=dude04.red.stw.pengutronix.de) by dude04.red.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1riFZb-0029BI-2R; Thu, 07 Mar 2024 16:22:19 +0100 From: Michael Grzeschik Date: Thu, 07 Mar 2024 16:22:03 +0100 Subject: [PATCH 1/3] usb: dwc3: gadget: reclaim the whole started list when request was missed Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240307-dwc3-gadget-complete-irq-v1-1-4fe9ac0ba2b7@pengutronix.de> References: <20240307-dwc3-gadget-complete-irq-v1-0-4fe9ac0ba2b7@pengutronix.de> In-Reply-To: <20240307-dwc3-gadget-complete-irq-v1-0-4fe9ac0ba2b7@pengutronix.de> To: Thinh Nguyen , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Grzeschik X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2318; i=m.grzeschik@pengutronix.de; h=from:subject:message-id; bh=y5PPyv47vwajakI0WCCzwWI0+5CKdDwYJF4dLuKJReo=; b=owEBbQKS/ZANAwAKAb9pWET5cfSrAcsmYgBl6duq3zOdIbp0K9WhuFx01AOQ4JwAkYlDIamtp OB6ObNC54eJAjMEAAEKAB0WIQQV2+2Fpbqd6fvv0Gi/aVhE+XH0qwUCZenbqgAKCRC/aVhE+XH0 q8oFD/9+mQ6z0hwSyuHxcNOp6QcLDz8wHB44r/R5uJW485dramOromUtXGAQfi9OXN/T57c5pfr G0mPqQbMu3MOY3oyan3YYoxry5IkRUTE9TWyUxZn+m2mtBVcDCLxWbyjWTqWKZNILkHro0DzEBf OjIwhv7+RrDQYnn7tehjH2tCpcBhNkW76TKely9/WpYEnMA1WokOX9VdqeHbOwOkIXX2YWxtKCn bLItFf3n5ZNa9YwQLwelQ1GfWOOW/NcQG7V37IBlQLcYivMFBMwZKhcD3Pm+QM6qH47DGcT1qw4 6OsLEeOCKIAMYDpHnefAZ2dBJI4TbZ/BhmB3/XTU5D93v7ZMzYtVfUMMPnPhPXPY1xHape7hG/M PzRxwgrVfSSmM1SrTEmzQHGDgNE8n5RB9Qjt5QYHJD50fR15NcjlyDBj4FrzvpHqMfQwGxf9awC KpYDOSFOxOxbN7aJAjOHTywwhpx/8z4qPUC+08D1CxSt72wWRv8S8T64m/oAqfCm+6MC9CnFIiw 0fkg1uTGg6ep0nKl8fwGjsV60s121BRL14LRDawTR8BdtOc8fj5ko2U1govmgCGJXSUUie7uk/k Z3xwqM3mfssadEPHAqA9MgS3LsSiQ5wRar6LgAl08bRSitIym3U7HvOD/0eTfxlBtDPa93v6qU7 m7RRKDMBdRx1uUA== X-Developer-Key: i=m.grzeschik@pengutronix.de; a=openpgp; fpr=957BC452CE953D7EA60CF4FC0BE9E3157A1E2C64 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: m.grzeschik@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-usb@vger.kernel.org On EXDEV/Missed status interrupt, the handler has to stop the running transfer and ensure that every request complete call will not run kick on the current transfer. This is achieved by calling dwc3_stop_active_transfer early before cleaning up the started request list. If the current transfer was stopped we can not keep all requests in the hardware and have to reclaim them all. Since the requests could have no_interrupt bit the cleanup on an stopped pipeline has to remove every request and may not stop on the one that has the IOC bit set. To ensure that the dwc3_gadget_ep_cleanup_completed_request will iterate over every request in that case, we skip the stop condition in reclaim_completed_trb if the current transfer was stopped by checking for DWC3_EP_END_TRANSFER_PENDING bit set. Signed-off-by: Michael Grzeschik --- drivers/usb/dwc3/gadget.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 40c52dbc28d3b..b9fce7b1dcdec 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -3404,7 +3404,8 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct dwc3_ep *dep, DWC3_TRB_SIZE_TRBSTS(trb->size) == DWC3_TRBSTS_MISSED_ISOC) return 1; - if ((trb->ctrl & DWC3_TRB_CTRL_IOC) || + if (((trb->ctrl & DWC3_TRB_CTRL_IOC) && + !(dep->flags & DWC3_EP_END_TRANSFER_PENDING)) || (trb->ctrl & DWC3_TRB_CTRL_LST)) return 1; @@ -3568,6 +3569,9 @@ static bool dwc3_gadget_endpoint_trbs_complete(struct dwc3_ep *dep, struct dwc3 *dwc = dep->dwc; bool no_started_trb = true; + if (status == -EXDEV) + dwc3_stop_active_transfer(dep, true, true); + dwc3_gadget_ep_cleanup_completed_requests(dep, event, status); if (dep->flags & DWC3_EP_END_TRANSFER_PENDING) @@ -3578,7 +3582,7 @@ static bool dwc3_gadget_endpoint_trbs_complete(struct dwc3_ep *dep, if (usb_endpoint_xfer_isoc(dep->endpoint.desc) && list_empty(&dep->started_list) && - (list_empty(&dep->pending_list) || status == -EXDEV)) + (list_empty(&dep->pending_list))) dwc3_stop_active_transfer(dep, true, true); else if (dwc3_gadget_ep_should_continue(dep)) if (__dwc3_gadget_kick_transfer(dep) == 0) From patchwork Thu Mar 7 15:22:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Grzeschik X-Patchwork-Id: 13585884 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EB6712F365 for ; Thu, 7 Mar 2024 15:22:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824948; cv=none; b=PKFVsvnM2I8q8f64z+7SlszoTMPXbB5kNiKZuNZr5uK6VtKu9yvHWysKrvWfA5PxVghquzkLpiaSbSlTMboiqKKYLrNIbHUnW8boCFW38NxrF48fCA0CJN+O4HQ8RBoRSDLEiWsKOOGHtiVl6dlTcjB80E1bAXEWam/IH7lBpHQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824948; c=relaxed/simple; bh=RchjYOpu4op2nA0WUf6YXLOXTpb5ovl/Mszcmr7J9FA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NQ/VkkyoQUfbGhYnsTRKT69TPTsS8DOgzqPkkWSN90RRKqMWQPERoOUyhjroa418P26IkobWTxtgS1cZ/OaFgR23uQITxKDzFoVBCZcKBmnlgCC+Ww3wRmcPKn9z1Oc4ZAr+byq78RVTv21/jpXJyvWeJhoiXF5bmOTKxyawx0k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1riFZd-0007MN-5V; Thu, 07 Mar 2024 16:22:21 +0100 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1riFZb-004y6i-QR; Thu, 07 Mar 2024 16:22:19 +0100 Received: from localhost ([::1] helo=dude04.red.stw.pengutronix.de) by dude04.red.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1riFZb-0029BI-2S; Thu, 07 Mar 2024 16:22:19 +0100 From: Michael Grzeschik Date: Thu, 07 Mar 2024 16:22:04 +0100 Subject: [PATCH 2/3] usb: dwc3: gadget: check drained isoc ep Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240307-dwc3-gadget-complete-irq-v1-2-4fe9ac0ba2b7@pengutronix.de> References: <20240307-dwc3-gadget-complete-irq-v1-0-4fe9ac0ba2b7@pengutronix.de> In-Reply-To: <20240307-dwc3-gadget-complete-irq-v1-0-4fe9ac0ba2b7@pengutronix.de> To: Thinh Nguyen , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Grzeschik X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1656; i=m.grzeschik@pengutronix.de; h=from:subject:message-id; bh=RchjYOpu4op2nA0WUf6YXLOXTpb5ovl/Mszcmr7J9FA=; b=owEBbQKS/ZANAwAKAb9pWET5cfSrAcsmYgBl6durknLdj/tkPafi1nYQL17vXUkAmEPBoxHzW 4PiiL0KpNuJAjMEAAEKAB0WIQQV2+2Fpbqd6fvv0Gi/aVhE+XH0qwUCZenbqwAKCRC/aVhE+XH0 qzTJEAC4UD1G/DrJazVsiJzLvfJdHjo12eK7GSkPwrRXb7PShdhMFdDXRi2m6s7Q1eFXHzm2vQ1 /hFSjePhhVnkMS0LBmSL80xpt53k5inHbVIjzLoZnbqxMAY77RhUTjtilsfz0cBX/7XYMV8MYOU XC7kQE3X7iMvljdEQO4nodULhuzb97pkBIKHKjtWqShStdA25hjxOmGdxU0Ztjt1F/bAwfxfFW4 7N7mCuutfCMIjyBR5LD/IqkAVKhxgfo0zkz30Cn3RZAbXs33kjZ7rn5SSEGLwB78ER7aCYPyZi7 B3p+WiztT3DwAEbNzRG0TsGq0P5kvjVz3z1kW6IqFPLMZ7Se+5fq6ZVX8yTCjFUwoOshwAnloph NwHI12FaY4tV61vk92AlZ1J5CSN8jX7UcMPk72zxViVnnxkUMU3x78FbvNAdkKymivHTVykxR0D kV53ukseKzuB/osbDGEY+YeZm+5M20z+bsaVuh/NcZgd8Pk8aslddvC5m8KEgobHYuGmaQslc84 k5B2q7+XYmjQuvCTu9N1/KqqJuGouGLY9pE1lD54i6b4G7yYkpzBo5qzYU31/5pYs5KbmiZGLYO T8Bi/tMVUz55LCrhHkM6PBOtMM0IXl2JoM3nS0Cfvl3ZyRrMCbEs2WH/1NOt23UY32+ZE2CnNxm nOCUPgrTREomefw== X-Developer-Key: i=m.grzeschik@pengutronix.de; a=openpgp; fpr=957BC452CE953D7EA60CF4FC0BE9E3157A1E2C64 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: m.grzeschik@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-usb@vger.kernel.org To avoid a potential underrun of an currently drained transfer we add a check for that scenario in the dwc3_gadget_endpoint_trbs_complete function. In the case of an empty trb ring, we call the stop_transfer cmd and avoid the underrun to occur. Signed-off-by: Michael Grzeschik --- drivers/usb/dwc3/gadget.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index b9fce7b1dcdec..f22b68a0b2dac 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -3568,8 +3568,23 @@ static bool dwc3_gadget_endpoint_trbs_complete(struct dwc3_ep *dep, { struct dwc3 *dwc = dep->dwc; bool no_started_trb = true; + unsigned int transfer_in_flight = 0; + + /* It is possible that the interrupt thread was delayed by + * scheduling in the system, and therefor the HW has already + * run dry. In that case the last trb in the queue is already + * handled by the hw. By checking the HWO bit we know to restart + * the whole transfer. The condition to appear is more likely + * if not every req has the IOC bit set and therefor does not + * trigger the interrupt thread frequently. + */ + if (dep->number && usb_endpoint_xfer_isoc(dep->endpoint.desc)) { + struct dwc3_trb *trb = dwc3_ep_prev_trb(dep, dep->trb_enqueue); + + transfer_in_flight = trb->ctrl & DWC3_TRB_CTRL_HWO; + } - if (status == -EXDEV) + if (status == -EXDEV || !transfer_in_flight) dwc3_stop_active_transfer(dep, true, true); dwc3_gadget_ep_cleanup_completed_requests(dep, event, status); From patchwork Thu Mar 7 15:22:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Grzeschik X-Patchwork-Id: 13585886 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 303F312F370 for ; Thu, 7 Mar 2024 15:22:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824948; cv=none; b=HMyD89Gtds9pySdxu5H8vARPHFk5SpFHZxv3a/I5Me6WqfpMcjttOMiaeb5xoB2iJyGIlr/DRybu06zKVFJUso5bOrNAnrxtmKjR2+5xzoqg2BALoGAasgY1KxF0vYU85NgofmOToM6+bbuSFREalUQkKN91X57iOfx2B3Qs3nw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709824948; c=relaxed/simple; bh=Ez1QdUV04iD4E6g4vgQsdKZqu2XEGi7/ylSKu6ZB/CU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oNtZnmgEGW29zm5Rz3qgoYtUXUmUJdrog94cnpcUAx2FsYDjC3StcUQgHSLPpd5R5eQFCf/URcxyJi5GbVj7feBPmttwys6oMWWQgtghHmqITeNbsk5osqV+Eer1l+DJg6b3n5BWRYYsQ/cuRCX0DNi/aG5OU/gFg9hNwVGIhrU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1riFZd-0007MM-5V; Thu, 07 Mar 2024 16:22:21 +0100 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1riFZb-004y6j-QV; Thu, 07 Mar 2024 16:22:19 +0100 Received: from localhost ([::1] helo=dude04.red.stw.pengutronix.de) by dude04.red.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1riFZb-0029BI-2T; Thu, 07 Mar 2024 16:22:19 +0100 From: Michael Grzeschik Date: Thu, 07 Mar 2024 16:22:05 +0100 Subject: [PATCH 3/3] usb: dwc3: gadget: check the whole started queue for missed requests in complete Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240307-dwc3-gadget-complete-irq-v1-3-4fe9ac0ba2b7@pengutronix.de> References: <20240307-dwc3-gadget-complete-irq-v1-0-4fe9ac0ba2b7@pengutronix.de> In-Reply-To: <20240307-dwc3-gadget-complete-irq-v1-0-4fe9ac0ba2b7@pengutronix.de> To: Thinh Nguyen , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Grzeschik X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2246; i=m.grzeschik@pengutronix.de; h=from:subject:message-id; bh=Ez1QdUV04iD4E6g4vgQsdKZqu2XEGi7/ylSKu6ZB/CU=; b=owEBbQKS/ZANAwAKAb9pWET5cfSrAcsmYgBl6durU2XZUppWhknO+4hbYmEDglFjpowcKZEIx 9SflZ9T1ZOJAjMEAAEKAB0WIQQV2+2Fpbqd6fvv0Gi/aVhE+XH0qwUCZenbqwAKCRC/aVhE+XH0 qzk1EACelLwRYh3AlWHS6eUG1KKpMfBZqocop45UyYKduPTX4vExZsrHqeR8A2VWvjywd0ckrHN VtBohqFvhjVQ4Nh9zONDzs4+EQqnHo/ePf+0E3wDl/nvjIxDbfj8s6kwtlAVjaslcUs3ntzOOAJ AiNYIEGw/u+pR2abmCu9/GvYFPXbnIIVxkghcQ2YMRXaVAcMEJaBEPT0jzmF6mvyXXR/eFVWPVe ic70MG48Q5SCkmBLYhbH42WETbLBNVOUX9V9G5MoQTijI5YVf746+Pj9TLRzgJy/Xsbrs3BfPsB U4xjq0RlxDutqioS+nC6yAncjsZoR7Cx83Fl05v5qFSOGXXFv4LUkSxuhQz6OkNd/Zvu2TqKqeV I4iw2PExnGbqzbDgmtg9cGxBk2Lx6Mra4xTK6Tz4Md5j+XkhVaqm+Mdu6eXjp7fIdeABSpF10Y1 ZZTNvgBShfytRcmeFJ/cWvapOW2Zx/c4bQEpaJfQ/edKc/6OGl+ut6Unlyvq+qyNykcbz4oET+P DxWed70G/7DapkPEA67fQ4xmb6/mguKK6VXjD3scLV4TbJgGxb39klLcnG3xLBgDF1NW/WCSDhf uTvLsJr9BNmDfhIl9SEMDHHS1pfb7Kv83yDkBXyaK9N6C3YoxPJmjc+aJN9Xfgq0MF7C2XXnBjT +IVLY1I1lA6DIXQ== X-Developer-Key: i=m.grzeschik@pengutronix.de; a=openpgp; fpr=957BC452CE953D7EA60CF4FC0BE9E3157A1E2C64 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: m.grzeschik@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-usb@vger.kernel.org The function dwc3_gadget_endpoint_trbs_complete will be called with the interrupt event. This event is only representing the interrupt reason of the exact trb that had IOC enabled. In the current approach the function dwc3_gadget_ep_cleanup_completed_requests will give back and complete the requests with the corresponding trb status and therefor will correctly return the missed requests that are already finished. Since inbetween those complete functioncalls of the properly finished and the missed trbs, a missed transfer could get new trbs enqueued with the updatecmd, this will just lead to more missed trbs. To break the cascading scenario this patch is checking all trbs from the started list for any trb that has the missed trb status before even calling the complete handler but stopping the transfer instead. Signed-off-by: Michael Grzeschik --- drivers/usb/dwc3/gadget.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index f22b68a0b2dac..ca87f4d988d41 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -3563,6 +3563,21 @@ static void dwc3_gadget_endpoint_frame_from_event(struct dwc3_ep *dep, dep->frame_number = event->parameters; } +static int dwc3_gadget_ep_check_missed_requests(struct dwc3_ep *dep) +{ + struct dwc3_request *req; + struct dwc3_request *tmp; + + list_for_each_entry_safe(req, tmp, &dep->started_list, list) { + struct dwc3_trb *trb = req->trb; + + if (DWC3_TRB_SIZE_TRBSTS(trb->size) == DWC3_TRBSTS_MISSED_ISOC) + return -EXDEV; + } + + return 0; +} + static bool dwc3_gadget_endpoint_trbs_complete(struct dwc3_ep *dep, const struct dwc3_event_depevt *event, int status) { @@ -3584,7 +3599,7 @@ static bool dwc3_gadget_endpoint_trbs_complete(struct dwc3_ep *dep, transfer_in_flight = trb->ctrl & DWC3_TRB_CTRL_HWO; } - if (status == -EXDEV || !transfer_in_flight) + if (status == -EXDEV || !transfer_in_flight || dwc3_gadget_ep_check_missed_requests(dep)) dwc3_stop_active_transfer(dep, true, true); dwc3_gadget_ep_cleanup_completed_requests(dep, event, status);