From: mpi Date: Sat, 9 Aug 2014 09:45:14 +0000 (+0000) Subject: Do not store the whole USB hub descriptor in the "struct usbd_hub" X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=eff17a6a55d0fce39da7e589cb0eb3147404c33e;p=openbsd Do not store the whole USB hub descriptor in the "struct usbd_hub" to help integrating super speed hubs that use a different descriptor. --- diff --git a/sys/dev/usb/uhub.c b/sys/dev/usb/uhub.c index dde6dba4d41..0f448d66931 100644 --- a/sys/dev/usb/uhub.c +++ b/sys/dev/usb/uhub.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uhub.c,v 1.69 2014/07/12 18:48:52 tedu Exp $ */ +/* $OpenBSD: uhub.c,v 1.70 2014/08/09 09:45:14 mpi Exp $ */ /* $NetBSD: uhub.c,v 1.64 2003/02/08 03:32:51 ichiro Exp $ */ /* $FreeBSD: src/sys/dev/usb/uhub.c,v 1.18 1999/11/17 22:33:43 n_hibma Exp $ */ @@ -113,7 +113,7 @@ uhub_attach(struct device *parent, struct device *self, void *aux) struct usbd_device *dev = uaa->device; struct usbd_hub *hub = NULL; usb_hub_descriptor_t hubdesc; - int p, port, nports, pwrdly; + int p, port, nports, powerdelay; struct usbd_interface *iface; usb_endpoint_descriptor_t *ed; struct usbd_tt *tts = NULL; @@ -140,6 +140,7 @@ uhub_attach(struct device *parent, struct device *self, void *aux) /* Get hub descriptor. */ err = usbd_get_hub_descriptor(dev, &hubdesc, 1); nports = hubdesc.bNbrPorts; + powerdelay = (hubdesc.bPwrOn2PwrGood * UHD_PWRON_FACTOR); if (!err && nports > 7) usbd_get_hub_descriptor(dev, &hubdesc, nports); if (err) { @@ -183,7 +184,8 @@ uhub_attach(struct device *parent, struct device *self, void *aux) dev->hub = hub; dev->hub->hubsoftc = sc; hub->explore = uhub_explore; - hub->hubdesc = hubdesc; + hub->nports = nports; + hub->powerdelay = powerdelay; if (!dev->self_powered && dev->powersrc->parent != NULL && !dev->powersrc->parent->self_powered) { @@ -277,10 +279,6 @@ uhub_attach(struct device *parent, struct device *self, void *aux) } } - /* XXX should check for none, individual, or ganged power? */ - - pwrdly = dev->hub->hubdesc.bPwrOn2PwrGood * UHD_PWRON_FACTOR - + USB_EXTRA_POWER_UP_TIME; for (port = 1; port <= nports; port++) { /* Turn the power on. */ err = usbd_set_port_feature(dev, port, UHF_PORT_POWER); @@ -290,9 +288,9 @@ uhub_attach(struct device *parent, struct device *self, void *aux) usbd_errstr(err)); } - /* Wait for stable power. Root hubs delay in their event thread. */ + /* Wait for stable power. */ if (dev->powersrc->parent != NULL) - usbd_delay_ms(dev, pwrdly); + usbd_delay_ms(dev, powerdelay + USB_EXTRA_POWER_UP_TIME); /* The usual exploration will finish the setup. */ @@ -314,7 +312,6 @@ uhub_attach(struct device *parent, struct device *self, void *aux) int uhub_explore(struct usbd_device *dev) { - usb_hub_descriptor_t *hd = &dev->hub->hubdesc; struct uhub_softc *sc = dev->hub->hubsoftc; struct usbd_port *up; usbd_status err; @@ -332,7 +329,7 @@ uhub_explore(struct usbd_device *dev) if (dev->depth > USB_HUB_MAX_DEPTH) return (EOPNOTSUPP); - for (port = 1; port <= hd->bNbrPorts; port++) { + for (port = 1; port <= dev->hub->nports; port++) { up = &dev->hub->ports[port-1]; err = usbd_get_port_status(dev, port, &up->status); if (err) { @@ -478,7 +475,7 @@ uhub_detach(struct device *self, int flags) struct uhub_softc *sc = (struct uhub_softc *)self; struct usbd_hub *hub = sc->sc_hub->hub; struct usbd_port *rup; - int port, nports; + int port; if (hub == NULL) /* Must be partially working */ return (0); @@ -486,8 +483,7 @@ uhub_detach(struct device *self, int flags) usbd_abort_pipe(sc->sc_ipipe); usbd_close_pipe(sc->sc_ipipe); - nports = hub->hubdesc.bNbrPorts; - for(port = 0; port < nports; port++) { + for (port = 0; port < hub->nports; port++) { rup = &hub->ports[port]; if (rup->device != NULL) { usbd_detach(rup->device, self); diff --git a/sys/dev/usb/usb.c b/sys/dev/usb/usb.c index 7a1b3ae2b96..5cd6b3cff37 100644 --- a/sys/dev/usb/usb.c +++ b/sys/dev/usb/usb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: usb.c,v 1.100 2014/07/12 18:48:52 tedu Exp $ */ +/* $OpenBSD: usb.c,v 1.101 2014/08/09 09:45:14 mpi Exp $ */ /* $NetBSD: usb.c,v 1.77 2003/01/01 00:10:26 thorpej Exp $ */ /* @@ -835,8 +835,8 @@ usb_explore(void *v) timersub(&now, &sc->sc_ptime, &waited); waited_ms = waited.tv_sec * 1000 + waited.tv_usec / 1000; - pwrdly = sc->sc_bus->root_hub->hub->hubdesc.bPwrOn2PwrGood * - UHD_PWRON_FACTOR + USB_EXTRA_POWER_UP_TIME; + pwrdly = sc->sc_bus->root_hub->hub->powerdelay + + USB_EXTRA_POWER_UP_TIME; if (pwrdly > waited_ms) usb_delay_ms(sc->sc_bus, pwrdly - waited_ms); } diff --git a/sys/dev/usb/usb_subr.c b/sys/dev/usb/usb_subr.c index d42c45ca2ec..75027b8d83f 100644 --- a/sys/dev/usb/usb_subr.c +++ b/sys/dev/usb/usb_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: usb_subr.c,v 1.106 2014/07/12 18:48:53 tedu Exp $ */ +/* $OpenBSD: usb_subr.c,v 1.107 2014/08/09 09:45:14 mpi Exp $ */ /* $NetBSD: usb_subr.c,v 1.103 2003/01/10 11:19:13 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $ */ @@ -1070,7 +1070,7 @@ usbd_new_device(struct device *parent, struct usbd_bus *bus, int depth, adev = hub, hub = hub->myhub) ; if (hub) { - for (p = 0; p < hub->hub->hubdesc.bNbrPorts; p++) { + for (p = 0; p < hub->hub->nports; p++) { if (hub->hub->ports[p].device == adev) { dev->myhsport = &hub->hub->ports[p]; goto found; @@ -1367,8 +1367,7 @@ usbd_fill_deviceinfo(struct usbd_device *dev, struct usb_device_info *di, if (dev->hub) { for (i = 0; - i < nitems(di->udi_ports) && - i < dev->hub->hubdesc.bNbrPorts; i++) { + i < nitems(di->udi_ports) && i < dev->hub->nports; i++) { p = &dev->hub->ports[i]; if (p->device) err = p->device->address; @@ -1385,7 +1384,7 @@ usbd_fill_deviceinfo(struct usbd_device *dev, struct usb_device_info *di, } di->udi_ports[i] = err; } - di->udi_nports = dev->hub->hubdesc.bNbrPorts; + di->udi_nports = dev->hub->nports; } else di->udi_nports = 0; diff --git a/sys/dev/usb/usbdivar.h b/sys/dev/usb/usbdivar.h index c8b860a5846..980e5ddb30c 100644 --- a/sys/dev/usb/usbdivar.h +++ b/sys/dev/usb/usbdivar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: usbdivar.h,v 1.61 2014/07/09 18:15:04 mpi Exp $ */ +/* $OpenBSD: usbdivar.h,v 1.62 2014/08/09 09:45:14 mpi Exp $ */ /* $NetBSD: usbdivar.h,v 1.70 2002/07/11 21:14:36 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usbdivar.h,v 1.11 1999/11/17 22:33:51 n_hibma Exp $ */ @@ -90,7 +90,8 @@ struct usbd_port { struct usbd_hub { int (*explore)(struct usbd_device *); void *hubsoftc; - usb_hub_descriptor_t hubdesc; + int nports; + u_int8_t powerdelay; struct usbd_port *ports; };