Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/usb usb: uhub: remove unnecessary delays when poweri...



details:   https://anonhg.NetBSD.org/src/rev/0d6010307c08
branches:  trunk
changeset: 989052:0d6010307c08
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Oct 10 23:39:50 2021 +0000

description:
usb: uhub: remove unnecessary delays when powering on ports

In uhub_explore instead of waiting 300ms after powering up each
connected port, power up all of the connected ports and then wait for
300ms total.

diffstat:

 sys/dev/usb/uhub.c |  32 ++++++++++++++++++++++++++++----
 1 files changed, 28 insertions(+), 4 deletions(-)

diffs (81 lines):

diff -r 24051ed7755d -r 0d6010307c08 sys/dev/usb/uhub.c
--- a/sys/dev/usb/uhub.c        Sun Oct 10 23:30:44 2021 +0000
+++ b/sys/dev/usb/uhub.c        Sun Oct 10 23:39:50 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uhub.c,v 1.153 2021/06/13 14:48:10 riastradh Exp $     */
+/*     $NetBSD: uhub.c,v 1.154 2021/10/10 23:39:50 jmcneill Exp $      */
 /*     $FreeBSD: src/sys/dev/usb/uhub.c,v 1.18 1999/11/17 22:33:43 n_hibma Exp $       */
 /*     $OpenBSD: uhub.c,v 1.86 2015/06/29 18:27:40 mpi Exp $ */
 
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.153 2021/06/13 14:48:10 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.154 2021/10/10 23:39:50 jmcneill Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -124,6 +124,8 @@
        struct lwp              *sc_exploring;
 };
 
+typedef __BITMAP_TYPE(, uint8_t, UHD_NPORTS_MAX + 1) usb_port_mask;
+
 #define UHUB_IS_HIGH_SPEED(sc) \
     ((sc)->sc_proto == UDPROTO_HSHUBSTT || (sc)->sc_proto == UDPROTO_HSHUBMTT)
 #define UHUB_IS_SINGLE_TT(sc) ((sc)->sc_proto == UDPROTO_HSHUBSTT)
@@ -494,6 +496,8 @@
        int speed;
        int port;
        int change, status, reconnect, rescan;
+       usb_port_mask powerup_port;
+       int powerup_port_count = 0;
 
        UHUBHIST_FUNC();
        UHUBHIST_CALLARGS("uhub%jd dev=%#jx addr=%jd speed=%ju",
@@ -546,6 +550,8 @@
                }
        }
 
+       __BITMAP_ZERO(&powerup_port);
+
        for (port = 1; port <= hd->bNbrPorts; port++) {
                up = &dev->ud_hub->uh_ports[port - 1];
 
@@ -676,8 +682,24 @@
                DPRINTF("unit %jd dev->speed=%ju dev->depth=%ju",
                    device_unit(sc->sc_dev), dev->ud_speed, dev->ud_depth, 0);
 
-               /* Wait for maximum device power up time. */
-               usbd_delay_ms(dev, USB_PORT_POWERUP_DELAY);
+               __BITMAP_SET(port, &powerup_port);
+               powerup_port_count++;
+       }
+
+       if (powerup_port_count == 0) {
+               goto explore;
+       }
+
+       aprint_debug_dev(sc->sc_dev, "power up %u port(s)\n",
+           powerup_port_count);
+
+       /* Wait for maximum device power up time. */
+       usbd_delay_ms(dev, USB_PORT_POWERUP_DELAY);
+
+       for (port = 1; port <= hd->bNbrPorts; port++) {
+               if (!__BITMAP_ISSET(port, &powerup_port)) {
+                       continue;
+               }
 
                /* Reset port, which implies enabling it. */
                if (usbd_reset_port(dev, port, &up->up_status)) {
@@ -815,6 +837,8 @@
                                up->up_dev->ud_hub->uh_explore(up->up_dev);
                }
        }
+
+explore:
        mutex_enter(&sc->sc_lock);
        sc->sc_explorepending = false;
        for (int i = 0; i < sc->sc_statuslen; i++) {



Home | Main Index | Thread Index | Old Index