Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb add config_pending usage to uhub and general USB...



details:   https://anonhg.NetBSD.org/src/rev/c5d31bcbd473
branches:  trunk
changeset: 433508:c5d31bcbd473
user:      mrg <mrg%NetBSD.org@localhost>
date:      Tue Sep 18 01:36:44 2018 +0000

description:
add config_pending usage to uhub and general USB device attachment.

- call config_pending_incr() and config_pending_decr() around attaching
  devices against "usbdevif" attribute.

uhub:
- convert sc_explorepending and sc_running to bool.  add new sc_first_explore.
- call config_pending_incr() at the start of uhub_attach().  dropped in
  uhub_explore(), if this is the first explore.

diffstat:

 sys/dev/usb/uhub.c     |  35 +++++++++++++++++++++--------------
 sys/dev/usb/usb_subr.c |   6 ++++--
 2 files changed, 25 insertions(+), 16 deletions(-)

diffs (159 lines):

diff -r 05d76a6042d2 -r c5d31bcbd473 sys/dev/usb/uhub.c
--- a/sys/dev/usb/uhub.c        Tue Sep 18 01:25:09 2018 +0000
+++ b/sys/dev/usb/uhub.c        Tue Sep 18 01:36:44 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uhub.c,v 1.138 2018/02/01 09:50:48 msaitoh Exp $       */
+/*     $NetBSD: uhub.c,v 1.139 2018/09/18 01:36:44 mrg 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.138 2018/02/01 09:50:48 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.139 2018/09/18 01:36:44 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -113,9 +113,9 @@
        uint8_t                 *sc_statuspend;
        uint8_t                 *sc_status;
        size_t                   sc_statuslen;
-       int                      sc_explorepending;
-
-       u_char                   sc_running;
+       bool                     sc_explorepending;
+       bool                     sc_first_explore;
+       bool                     sc_running;
 };
 
 #define UHUB_IS_HIGH_SPEED(sc) \
@@ -263,6 +263,8 @@
        usb_endpoint_descriptor_t *ed;
        struct usbd_tt *tts = NULL;
 
+       config_pending_incr(self);
+
        UHUBHIST_FUNC(); UHUBHIST_CALLED();
 
        sc->sc_dev = self;
@@ -284,14 +286,14 @@
        if (err) {
                DPRINTF("configuration failed, sc %#jx error %jd",
                    (uintptr_t)sc, err, 0, 0);
-               return;
+               goto bad2;
        }
 
        if (dev->ud_depth > USB_HUB_MAX_DEPTH) {
                aprint_error_dev(self,
                    "hub depth (%d) exceeded, hub ignored\n",
                    USB_HUB_MAX_DEPTH);
-               return;
+               goto bad2;
        }
 
        /* Get hub descriptor. */
@@ -301,7 +303,7 @@
        if (err) {
                DPRINTF("getting hub descriptor failed, uhub%jd error %jd",
                    device_unit(self), err, 0, 0);
-               return;
+               goto bad2;
        }
 
        for (nremov = 0, port = 1; port <= nports; port++)
@@ -365,7 +367,7 @@
 
        /* force initial scan */
        memset(sc->sc_status, 0xff, sc->sc_statuslen);
-       sc->sc_explorepending = 1;
+       sc->sc_explorepending = true;
 
        err = usbd_open_pipe_intr(iface, ed->bEndpointAddress,
                  USBD_SHORT_XFER_OK|USBD_MPSAFE, &sc->sc_ipipe, sc,
@@ -450,8 +452,8 @@
                usbd_delay_ms(dev, pwrdly);
 
        /* The usual exploration will finish the setup. */
-
-       sc->sc_running = 1;
+       sc->sc_running = true;
+       sc->sc_first_explore = true;
 
        if (!pmf_device_register(self, NULL, NULL))
                aprint_error_dev(self, "couldn't establish power handler\n");
@@ -469,7 +471,8 @@
                kmem_free(hub,
                    sizeof(*hub) + (nports-1) * sizeof(struct usbd_port));
        dev->ud_hub = NULL;
-       return;
+ bad2:
+       config_pending_decr(self);
 }
 
 usbd_status
@@ -778,7 +781,7 @@
                }
        }
        mutex_enter(&sc->sc_lock);
-       sc->sc_explorepending = 0;
+       sc->sc_explorepending = false;
        for (int i = 0; i < sc->sc_statuslen; i++) {
                if (sc->sc_statuspend[i] != 0) {
                        memcpy(sc->sc_status, sc->sc_statuspend,
@@ -789,6 +792,10 @@
                }
        }
        mutex_exit(&sc->sc_lock);
+       if (sc->sc_first_explore) {
+               config_pending_decr(sc->sc_dev);
+               sc->sc_first_explore = false;
+       }
 
        return USBD_NORMAL_COMPLETION;
 }
@@ -943,7 +950,7 @@
                }
 
                if (!sc->sc_explorepending) {
-                       sc->sc_explorepending = 1;
+                       sc->sc_explorepending = true;
 
                        memcpy(sc->sc_status, sc->sc_statuspend,
                            sc->sc_statuslen);
diff -r 05d76a6042d2 -r c5d31bcbd473 sys/dev/usb/usb_subr.c
--- a/sys/dev/usb/usb_subr.c    Tue Sep 18 01:25:09 2018 +0000
+++ b/sys/dev/usb/usb_subr.c    Tue Sep 18 01:36:44 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usb_subr.c,v 1.226 2018/08/02 06:09:04 riastradh Exp $ */
+/*     $NetBSD: usb_subr.c,v 1.227 2018/09/18 01:36:44 mrg Exp $       */
 /*     $FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $   */
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.226 2018/08/02 06:09:04 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.227 2018/09/18 01:36:44 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -907,6 +907,7 @@
        dlocs[USBDEVIFCF_INTERFACE] = -1;
 
        KERNEL_LOCK(1, curlwp);
+       config_pending_incr(parent);
        dv = config_found_sm_loc(parent, "usbdevif", dlocs, &uaa, usbd_print,
                                 config_stdsubmatch);
        KERNEL_UNLOCK_ONE(curlwp);
@@ -917,6 +918,7 @@
                dev->ud_nifaces_claimed = 1; /* XXX */
                usbd_serialnumber(dv, dev);
        }
+       config_pending_decr(parent);
        return USBD_NORMAL_COMPLETION;
 }
 



Home | Main Index | Thread Index | Old Index