From ec3938679d2502c31b968b69cf7d13e132f05f88 Mon Sep 17 00:00:00 2001 From: Martin Pieuchot Date: Fri, 7 Mar 2014 18:57:24 +0000 Subject: Indtroduce usbd_get_hub_descriptor() to start cleaning uhub(4)'s mess. This will help us deal with the different hub device descriptors used by super speed devices. --- sys/dev/usb/uhub.c | 25 ++++++++++--------------- sys/dev/usb/usbdi_util.c | 17 ++++++++++++++++- sys/dev/usb/usbdi_util.h | 4 +++- 3 files changed, 29 insertions(+), 17 deletions(-) (limited to 'sys/dev') diff --git a/sys/dev/usb/uhub.c b/sys/dev/usb/uhub.c index 26d913d7739..e656b07898b 100644 --- a/sys/dev/usb/uhub.c +++ b/sys/dev/usb/uhub.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uhub.c,v 1.63 2013/10/19 08:29:30 mpi Exp $ */ +/* $OpenBSD: uhub.c,v 1.64 2014/03/07 18:57:23 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 $ */ @@ -121,14 +121,16 @@ uhub_attach(struct device *parent, struct device *self, void *aux) struct uhub_softc *sc = (struct uhub_softc *)self; struct usb_attach_arg *uaa = aux; struct usbd_device *dev = uaa->device; - usbd_status err; struct usbd_hub *hub = NULL; - usb_device_request_t req; usb_hub_descriptor_t hubdesc; - int p, port, nports, nremov, pwrdly; + int p, port, nports, pwrdly; struct usbd_interface *iface; usb_endpoint_descriptor_t *ed; struct usbd_tt *tts = NULL; + usbd_status err; +#ifdef UHUB_DEBUG + int nremov; +#endif sc->sc_hub = dev; @@ -146,28 +148,21 @@ uhub_attach(struct device *parent, struct device *self, void *aux) } /* Get hub descriptor. */ - req.bmRequestType = UT_READ_CLASS_DEVICE; - req.bRequest = UR_GET_DESCRIPTOR; - USETW2(req.wValue, UDESC_HUB, 0); - USETW(req.wIndex, 0); - USETW(req.wLength, USB_HUB_DESCRIPTOR_SIZE); - err = usbd_do_request(dev, &req, &hubdesc); + err = usbd_get_hub_descriptor(dev, &hubdesc, 1); nports = hubdesc.bNbrPorts; - if (!err && nports > 7) { - USETW(req.wLength, USB_HUB_DESCRIPTOR_SIZE + (nports+1) / 8); - err = usbd_do_request(dev, &req, &hubdesc); - } + if (!err && nports > 7) + usbd_get_hub_descriptor(dev, &hubdesc, nports); if (err) { DPRINTF("%s: getting hub descriptor failed, error=%s\n", sc->sc_dev.dv_xname, usbd_errstr(err)); return; } +#ifdef UHUB_DEBUG for (nremov = 0, port = 1; port <= nports; port++) if (!UHD_NOT_REMOV(&hubdesc, port)) nremov++; -#ifdef UHUB_DEBUG printf("%s: %d port%s with %d removable, %s powered", sc->sc_dev.dv_xname, nports, nports != 1 ? "s" : "", nremov, dev->self_powered ? "self" : "bus"); diff --git a/sys/dev/usb/usbdi_util.c b/sys/dev/usb/usbdi_util.c index 0ee79ee1ef5..439209de101 100644 --- a/sys/dev/usb/usbdi_util.c +++ b/sys/dev/usb/usbdi_util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: usbdi_util.c,v 1.34 2013/11/13 13:48:08 pirofti Exp $ */ +/* $OpenBSD: usbdi_util.c,v 1.35 2014/03/07 18:57:23 mpi Exp $ */ /* $NetBSD: usbdi_util.c,v 1.40 2002/07/11 21:14:36 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usbdi_util.c,v 1.14 1999/11/17 22:33:50 n_hibma Exp $ */ @@ -105,6 +105,21 @@ usbd_get_hub_status(struct usbd_device *dev, usb_hub_status_t *st) return (usbd_do_request(dev, &req, st)); } +usbd_status +usbd_get_hub_descriptor(struct usbd_device *dev, usb_hub_descriptor_t *hd, + uint8_t nports) +{ + usb_device_request_t req; + uint16_t len = USB_HUB_DESCRIPTOR_SIZE + (nports + 1) / 8; + + req.bmRequestType = UT_READ_CLASS_DEVICE; + req.bRequest = UR_GET_DESCRIPTOR; + USETW2(req.wValue, UDESC_HUB, 0); + USETW(req.wIndex, 0); + USETW(req.wLength, len); + return (usbd_do_request(dev, &req, hd)); +} + usbd_status usbd_set_address(struct usbd_device *dev, int addr) { diff --git a/sys/dev/usb/usbdi_util.h b/sys/dev/usb/usbdi_util.h index 801febb5e1c..d140e7f8409 100644 --- a/sys/dev/usb/usbdi_util.h +++ b/sys/dev/usb/usbdi_util.h @@ -1,4 +1,4 @@ -/* $OpenBSD: usbdi_util.h,v 1.23 2013/11/02 12:23:58 mpi Exp $ */ +/* $OpenBSD: usbdi_util.h,v 1.24 2014/03/07 18:57:23 mpi Exp $ */ /* $NetBSD: usbdi_util.h,v 1.28 2002/07/11 21:14:36 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usbdi_util.h,v 1.9 1999/11/17 22:33:50 n_hibma Exp $ */ @@ -43,6 +43,8 @@ usbd_status usbd_set_port_feature(struct usbd_device *dev, int, int); usbd_status usbd_clear_port_feature(struct usbd_device *, int, int); usbd_status usbd_get_device_status(struct usbd_device *, usb_status_t *); usbd_status usbd_get_hub_status(struct usbd_device *, usb_hub_status_t *); +usbd_status usbd_get_hub_descriptor(struct usbd_device *, + usb_hub_descriptor_t *, uint8_t); usbd_status usbd_get_protocol(struct usbd_interface *dev, u_int8_t *report); usbd_status usbd_set_protocol(struct usbd_interface *dev, int report); usbd_status usbd_get_report_descriptor(struct usbd_device *dev, int ifcno, -- cgit v1.2.3