From: Primoz Fiser <primoz.fiser@norik.com>
To: barebox@lists.infradead.org
Subject: [PATCH 1/3] usb: hub_port_reset(): Speedup hub reset handling
Date: Tue, 1 Oct 2019 10:17:58 +0200 [thread overview]
Message-ID: <20191001081800.19128-2-primoz.fiser@norik.com> (raw)
In-Reply-To: <20191001081800.19128-1-primoz.fiser@norik.com>
Start with a short USB hub reset delay of 20ms. This can be enough for
some configurations. Switch to longer reset delay only if the short
delay hasn't been long enough.
This USB hub reset handling strategy is also used in the Linux kernel
USB hub driver, function hub_port_reset().
Without patch:
$ time usb
usb: USB: scanning bus for devices...
usb: 17 USB Device(s) found
time: 21750ms
With patch:
$ time usb
usb: USB: scanning bus for devices...
usb: 17 USB Device(s) found
time: 16355ms
Delta: ~5.5 seconds
Signed-off-by: Primoz Fiser <primoz.fiser@norik.com>
---
drivers/usb/core/hub.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index d01a01607..91604e1ef 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -30,6 +30,9 @@
#define USB_BUFSIZ 512
+#define HUB_SHORT_RESET_TIME 20
+#define HUB_LONG_RESET_TIME 200
+
static int usb_get_hub_descriptor(struct usb_device *dev, void *data, int size)
{
return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
@@ -116,12 +119,13 @@ int hub_port_reset(struct usb_device *hub, int port, struct usb_device *usb)
int tries;
struct usb_port_status portsts;
unsigned short portstatus, portchange;
+ int delay = HUB_SHORT_RESET_TIME; /* start with short reset delay */
dev_dbg(&hub->dev, "hub_port_reset: resetting port %d...\n", port);
for (tries = 0; tries < MAX_TRIES; tries++) {
usb_set_port_feature(hub, port + 1, USB_PORT_FEAT_RESET);
- mdelay(200);
+ mdelay(delay);
if (usb_get_port_status(hub, port + 1, &portsts) < 0) {
dev_dbg(&hub->dev, "get_port_status failed status %lX\n",
@@ -148,7 +152,8 @@ int hub_port_reset(struct usb_device *hub, int port, struct usb_device *usb)
if (portstatus & USB_PORT_STAT_ENABLE)
break;
- mdelay(200);
+ /* Switch to long reset delay for the next round */
+ delay = HUB_LONG_RESET_TIME;
}
if (tries == MAX_TRIES) {
--
2.17.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2019-10-01 8:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-01 8:17 [PATCH 0/3] usb: Reduce USB scanning time Primoz Fiser
2019-10-01 8:17 ` Primoz Fiser [this message]
2019-10-01 8:17 ` [PATCH 2/3] usb: usb_hub_port_connect_change(): Remove unnecessary delays Primoz Fiser
2019-10-01 8:18 ` [PATCH 3/3] usb: Change power-on / scanning timeout handling Primoz Fiser
2019-10-02 7:11 ` [PATCH 0/3] usb: Reduce USB scanning time Sascha Hauer
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=20191001081800.19128-2-primoz.fiser@norik.com \
--to=primoz.fiser@norik.com \
--cc=barebox@lists.infradead.org \
/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