public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 3/7] usb: dwc2: Throttle the setup packet resending
Date: Tue,  3 May 2016 22:51:16 +0200	[thread overview]
Message-ID: <1462308680-9366-3-git-send-email-marex@denx.de> (raw)
In-Reply-To: <1462308680-9366-1-git-send-email-marex@denx.de>

Abort the request in case any of the tokens in the packet failed to
complete transfer 10 times. This is a precaution needed so that we
don't end in endless loop when scanning the bus with some braindead
devices.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chin Liang See <clsee@altera.com>
Cc: Dinh Nguyen <dinguyen@opensource.altera.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Cc: Stefan Roese <sr@denx.de>
Cc: Stephen Warren <swarren@nvidia.com>
---
 drivers/usb/host/dwc2.c | 44 ++++++++++++++++++++++++++++++++------------
 1 file changed, 32 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c
index 8d3949e..27fcf7c 100644
--- a/drivers/usb/host/dwc2.c
+++ b/drivers/usb/host/dwc2.c
@@ -993,6 +993,8 @@ static int _submit_control_msg(struct dwc2_priv *priv, struct usb_device *dev,
 	u8 pid;
 	/* For CONTROL endpoint pid should start with DATA1 */
 	int status_direction;
+	int againctr = 0;
+	const int againmax = 10;
 
 	if (devnum == priv->root_hub_devnum) {
 		dev->status = 0;
@@ -1003,25 +1005,37 @@ static int _submit_control_msg(struct dwc2_priv *priv, struct usb_device *dev,
 
 	/* SETUP stage */
 	pid = DWC2_HC_PID_SETUP;
-	do {
+	againctr = 0;
+	while (true) {
 		ret = chunk_msg(priv, dev, pipe, &pid, 0, setup, 8);
-	} while (ret == -EAGAIN);
-	if (ret)
-		return ret;
+		if (!ret)
+			break;
+		if (ret != -EAGAIN)
+			return ret;
+		if (againctr == againmax)
+			return -EINVAL;
+		againctr++;
+	};
 
 	/* DATA stage */
 	act_len = 0;
 	if (buffer) {
 		pid = DWC2_HC_PID_DATA1;
-		do {
+		againctr = 0;
+		while (true) {
 			ret = chunk_msg(priv, dev, pipe, &pid, usb_pipein(pipe),
 					buffer, len);
 			act_len += dev->act_len;
 			buffer += dev->act_len;
 			len -= dev->act_len;
-		} while (ret == -EAGAIN);
-		if (ret)
-			return ret;
+			if (!ret)
+				break;
+			if (ret != -EAGAIN)
+				return ret;
+			if (againctr == againmax)
+				return -EINVAL;
+			againctr++;
+		};
 		status_direction = usb_pipeout(pipe);
 	} else {
 		/* No-data CONTROL always ends with an IN transaction */
@@ -1030,12 +1044,18 @@ static int _submit_control_msg(struct dwc2_priv *priv, struct usb_device *dev,
 
 	/* STATUS stage */
 	pid = DWC2_HC_PID_DATA1;
-	do {
+	againctr = 0;
+	while (true) {
 		ret = chunk_msg(priv, dev, pipe, &pid, status_direction,
 				priv->status_buffer, 0);
-	} while (ret == -EAGAIN);
-	if (ret)
-		return ret;
+		if (!ret)
+			break;
+		if (ret != -EAGAIN)
+			return ret;
+		if (againctr == againmax)
+			return -EINVAL;
+		againctr++;
+	};
 
 	dev->act_len = act_len;
 
-- 
2.7.0

  parent reply	other threads:[~2016-05-03 20:51 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-03 20:51 [U-Boot] [PATCH 1/7] usb: Don't init pointer to zero, but NULL Marek Vasut
2016-05-03 20:51 ` [U-Boot] [PATCH 2/7] usb: dwc2: Resend setup packet in all fail cases Marek Vasut
2016-05-04  9:36   ` Chin Liang See
2016-05-03 20:51 ` Marek Vasut [this message]
2016-05-04  9:37   ` [U-Boot] [PATCH 3/7] usb: dwc2: Throttle the setup packet resending Chin Liang See
2016-05-04 17:08   ` Stephen Warren
2016-05-04 21:21     ` Marek Vasut
2016-05-06 18:04     ` Marek Vasut
2016-05-03 20:51 ` [U-Boot] [PATCH 4/7] usb: Wait after sending Set Configuration request Marek Vasut
2016-05-04  7:41   ` Stefan Roese
2016-05-04  9:45     ` Chin Liang See
2016-05-04 10:00       ` Stefan Roese
2016-05-04 10:24         ` Chin Liang See
2016-05-05  4:14       ` Sriram Dash
2016-05-04 10:21     ` Marek Vasut
2016-05-03 20:51 ` [U-Boot] [PATCH 5/7] usb: Assure Get Descriptor request is in separate microframe Marek Vasut
2016-05-04  8:03   ` Stefan Roese
2016-05-04 10:25     ` Marek Vasut
2016-05-04 17:10   ` Stephen Warren
2016-05-03 20:51 ` [U-Boot] [PATCH 6/7] usb: hub: Don't continue on get_port_status failure Marek Vasut
2016-05-04  8:05   ` Stefan Roese
2016-05-04  9:38     ` Chin Liang See
2016-05-03 20:51 ` [U-Boot] [PATCH 7/7] usb: hub: Increase the query delay Marek Vasut
2016-05-04  8:07   ` Stefan Roese
2016-05-04 11:39     ` Marek Vasut
2016-05-04 16:27       ` Stefan Roese
2016-05-04 17:11   ` Stephen Warren
2016-05-04 21:32   ` [U-Boot] [PATCH] " Marek Vasut
2016-05-04 21:34     ` Stephen Warren
2016-05-04 21:38       ` Marek Vasut
2016-05-04  7:36 ` [U-Boot] [PATCH 1/7] usb: Don't init pointer to zero, but NULL Stefan Roese
2016-05-04  9:35   ` Chin Liang See
2016-05-06 16:36 ` Marek Vasut

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1462308680-9366-3-git-send-email-marex@denx.de \
    --to=marex@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox