From: mpi Date: Fri, 12 Jun 2015 15:47:31 +0000 (+0000) Subject: Only match devices with a valid configuration. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=7ebc5b51da5611c78123bf2a163bb4cee0fee6d5;p=openbsd Only match devices with a valid configuration. Most of the WiFi/Ethernet USB adapter only have one configuration and always use its first interface. In order to improve USB descriptors parsing start by reducing the number of places where a configuration is set. Tests & ok stsp@ --- diff --git a/sys/dev/usb/if_athn_usb.c b/sys/dev/usb/if_athn_usb.c index 9513cc7d0be..4f473a62e44 100644 --- a/sys/dev/usb/if_athn_usb.c +++ b/sys/dev/usb/if_athn_usb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_athn_usb.c,v 1.33 2015/03/02 15:23:28 stsp Exp $ */ +/* $OpenBSD: if_athn_usb.c,v 1.34 2015/06/12 15:47:31 mpi Exp $ */ /*- * Copyright (c) 2011 Damien Bergamini @@ -220,11 +220,11 @@ athn_usb_match(struct device *parent, void *match, void *aux) { struct usb_attach_arg *uaa = aux; - if (uaa->iface != NULL) + if (uaa->iface == NULL || uaa->configno != 1) return (UMATCH_NONE); return ((athn_usb_lookup(uaa->vendor, uaa->product) != NULL) ? - UMATCH_VENDOR_PRODUCT : UMATCH_NONE); + UMATCH_VENDOR_PRODUCT_CONF_IFACE : UMATCH_NONE); } void @@ -233,9 +233,9 @@ athn_usb_attach(struct device *parent, struct device *self, void *aux) struct athn_usb_softc *usc = (struct athn_usb_softc *)self; struct athn_softc *sc = &usc->sc_sc; struct usb_attach_arg *uaa = aux; - int error; usc->sc_udev = uaa->device; + usc->sc_iface = uaa->iface; usc->flags = athn_usb_lookup(uaa->vendor, uaa->product)->flags; sc->flags |= ATHN_FLAG_USB; @@ -251,20 +251,6 @@ athn_usb_attach(struct device *parent, struct device *self, void *aux) usb_init_task(&usc->sc_task, athn_usb_task, sc, USB_TASK_TYPE_GENERIC); - if (usbd_set_config_no(usc->sc_udev, 1, 0) != 0) { - printf("%s: could not set configuration no\n", - sc->sc_dev.dv_xname); - return; - } - - /* Get the first interface handle. */ - error = usbd_device2interface_handle(usc->sc_udev, 0, &usc->sc_iface); - if (error != 0) { - printf("%s: could not get interface handle\n", - sc->sc_dev.dv_xname); - return; - } - if (athn_usb_open_pipes(usc) != 0) return; diff --git a/sys/dev/usb/if_axe.c b/sys/dev/usb/if_axe.c index f1c683af957..3d37736ebd6 100644 --- a/sys/dev/usb/if_axe.c +++ b/sys/dev/usb/if_axe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_axe.c,v 1.130 2015/05/17 02:44:38 canacar Exp $ */ +/* $OpenBSD: if_axe.c,v 1.131 2015/06/12 15:47:31 mpi Exp $ */ /* * Copyright (c) 2005, 2006, 2007 Jonathan Gray @@ -671,11 +671,11 @@ axe_match(struct device *parent, void *match, void *aux) { struct usb_attach_arg *uaa = aux; - if (!uaa->iface) - return(UMATCH_NONE); + if (uaa->iface == NULL || uaa->configno != 1) + return (UMATCH_NONE); return (axe_lookup(uaa->vendor, uaa->product) != NULL ? - UMATCH_VENDOR_PRODUCT : UMATCH_NONE); + UMATCH_VENDOR_PRODUCT_CONF_IFACE : UMATCH_NONE); } /* @@ -687,8 +687,6 @@ axe_attach(struct device *parent, struct device *self, void *aux) { struct axe_softc *sc = (struct axe_softc *)self; struct usb_attach_arg *uaa = aux; - struct usbd_device *dev = uaa->device; - usbd_status err; usb_interface_descriptor_t *id; usb_endpoint_descriptor_t *ed; struct mii_data *mii; @@ -698,15 +696,8 @@ axe_attach(struct device *parent, struct device *self, void *aux) int i, s; sc->axe_unit = self->dv_unit; /*device_get_unit(self);*/ - sc->axe_udev = dev; - - err = usbd_set_config_no(dev, AXE_CONFIG_NO, 1); - if (err) { - printf("%s: getting interface handle failed\n", - sc->axe_dev.dv_xname); - return; - } - + sc->axe_udev = uaa->device; + sc->axe_iface = uaa->iface; sc->axe_flags = axe_lookup(uaa->vendor, uaa->product)->axe_flags; usb_init_task(&sc->axe_tick_task, axe_tick_task, sc, @@ -715,13 +706,6 @@ axe_attach(struct device *parent, struct device *self, void *aux) usb_init_task(&sc->axe_stop_task, (void (*)(void *))axe_stop, sc, USB_TASK_TYPE_GENERIC); - err = usbd_device2interface_handle(dev, AXE_IFACE_IDX, &sc->axe_iface); - if (err) { - printf("%s: getting interface handle failed\n", - sc->axe_dev.dv_xname); - return; - } - sc->axe_product = uaa->product; sc->axe_vendor = uaa->vendor; diff --git a/sys/dev/usb/if_axen.c b/sys/dev/usb/if_axen.c index 92c9a38bcdf..6d7e9c65c83 100644 --- a/sys/dev/usb/if_axen.c +++ b/sys/dev/usb/if_axen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_axen.c,v 1.12 2015/03/20 11:58:04 mpi Exp $ */ +/* $OpenBSD: if_axen.c,v 1.13 2015/06/12 15:47:31 mpi Exp $ */ /* * Copyright (c) 2013 Yojiro UO @@ -641,11 +641,11 @@ axen_match(struct device *parent, void *match, void *aux) { struct usb_attach_arg *uaa = aux; - if (!uaa->iface) - return UMATCH_NONE; + if (uaa->iface == NULL || uaa->configno != 1) + return (UMATCH_NONE); return (axen_lookup(uaa->vendor, uaa->product) != NULL ? - UMATCH_VENDOR_PRODUCT : UMATCH_NONE); + UMATCH_VENDOR_PRODUCT_CONF_IFACE : UMATCH_NONE); } void @@ -653,8 +653,6 @@ axen_attach(struct device *parent, struct device *self, void *aux) { struct axen_softc *sc = (struct axen_softc *)self; struct usb_attach_arg *uaa = aux; - struct usbd_device *dev = uaa->device; - usbd_status err; usb_interface_descriptor_t *id; usb_endpoint_descriptor_t *ed; struct mii_data *mii; @@ -664,15 +662,8 @@ axen_attach(struct device *parent, struct device *self, void *aux) int i, s; sc->axen_unit = self->dv_unit; /*device_get_unit(self);*/ - sc->axen_udev = dev; - - err = usbd_set_config_no(dev, AXEN_CONFIG_NO, 1); - if (err) { - printf("%s: getting interface handle failed\n", - sc->axen_dev.dv_xname); - return; - } - + sc->axen_udev = uaa->device; + sc->axen_iface = uaa->iface; sc->axen_flags = axen_lookup(uaa->vendor, uaa->product)->axen_flags; usb_init_task(&sc->axen_tick_task, axen_tick_task, sc, @@ -681,14 +672,6 @@ axen_attach(struct device *parent, struct device *self, void *aux) usb_init_task(&sc->axen_stop_task, (void (*)(void *))axen_stop, sc, USB_TASK_TYPE_GENERIC); - err = usbd_device2interface_handle(dev, AXEN_IFACE_IDX, - &sc->axen_iface); - if (err) { - printf("%s: getting interface handle failed\n", - sc->axen_dev.dv_xname); - return; - } - sc->axen_product = uaa->product; sc->axen_vendor = uaa->vendor; diff --git a/sys/dev/usb/if_axenreg.h b/sys/dev/usb/if_axenreg.h index d5f9428873a..4b14b1a6038 100644 --- a/sys/dev/usb/if_axenreg.h +++ b/sys/dev/usb/if_axenreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_axenreg.h,v 1.3 2014/01/08 22:24:35 bluhm Exp $ */ +/* $OpenBSD: if_axenreg.h,v 1.4 2015/06/12 15:47:31 mpi Exp $ */ /* * Copyright (c) 2013 Yojiro UO . All right reserved. @@ -211,9 +211,6 @@ #define AXEN_TX_LIST_CNT 1 -#define AXEN_CONFIG_NO 1 -#define AXEN_IFACE_IDX 0 - /* * The interrupt endpoint is currently unused * by the ASIX part. diff --git a/sys/dev/usb/if_axereg.h b/sys/dev/usb/if_axereg.h index f7ec264e5af..cf7bd1d8258 100644 --- a/sys/dev/usb/if_axereg.h +++ b/sys/dev/usb/if_axereg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_axereg.h,v 1.25 2015/05/17 02:44:38 canacar Exp $ */ +/* $OpenBSD: if_axereg.h,v 1.26 2015/06/12 15:47:31 mpi Exp $ */ /* * Copyright (c) 1997, 1998, 1999, 2000-2003 @@ -184,9 +184,6 @@ #define AXE_CTL_READ 0x01 #define AXE_CTL_WRITE 0x02 -#define AXE_CONFIG_NO 1 -#define AXE_IFACE_IDX 0 - /* EEPROM Map */ #define AXE_EEPROM_772B_NODEID 0x04 diff --git a/sys/dev/usb/if_rsu.c b/sys/dev/usb/if_rsu.c index 72f4b0b6945..e995b39ec01 100644 --- a/sys/dev/usb/if_rsu.c +++ b/sys/dev/usb/if_rsu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_rsu.c,v 1.26 2015/03/14 03:38:49 jsg Exp $ */ +/* $OpenBSD: if_rsu.c,v 1.27 2015/06/12 15:47:31 mpi Exp $ */ /*- * Copyright (c) 2010 Damien Bergamini @@ -197,11 +197,11 @@ rsu_match(struct device *parent, void *match, void *aux) { struct usb_attach_arg *uaa = aux; - if (uaa->iface != NULL) + if (uaa->iface == NULL || uaa->configno != 1) return (UMATCH_NONE); return ((usb_lookup(rsu_devs, uaa->vendor, uaa->product) != NULL) ? - UMATCH_VENDOR_PRODUCT : UMATCH_NONE); + UMATCH_VENDOR_PRODUCT_CONF_IFACE : UMATCH_NONE); } void @@ -214,24 +214,11 @@ rsu_attach(struct device *parent, struct device *self, void *aux) int i, error; sc->sc_udev = uaa->device; + sc->sc_iface = uaa->iface; usb_init_task(&sc->sc_task, rsu_task, sc, USB_TASK_TYPE_GENERIC); timeout_set(&sc->calib_to, rsu_calib_to, sc); - if (usbd_set_config_no(sc->sc_udev, 1, 0) != 0) { - printf("%s: could not set configuration no\n", - sc->sc_dev.dv_xname); - return; - } - - /* Get the first interface handle. */ - error = usbd_device2interface_handle(sc->sc_udev, 0, &sc->sc_iface); - if (error != 0) { - printf("%s: could not get interface handle\n", - sc->sc_dev.dv_xname); - return; - } - /* Read chip revision. */ sc->cut = MS(rsu_read_4(sc, R92S_PMC_FSM), R92S_PMC_FSM_CUT); if (sc->cut != 3) diff --git a/sys/dev/usb/if_rum.c b/sys/dev/usb/if_rum.c index ce8d27de106..02e07cf97d1 100644 --- a/sys/dev/usb/if_rum.c +++ b/sys/dev/usb/if_rum.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_rum.c,v 1.110 2015/03/14 03:38:49 jsg Exp $ */ +/* $OpenBSD: if_rum.c,v 1.111 2015/06/12 15:47:31 mpi Exp $ */ /*- * Copyright (c) 2005-2007 Damien Bergamini @@ -229,11 +229,11 @@ rum_match(struct device *parent, void *match, void *aux) { struct usb_attach_arg *uaa = aux; - if (uaa->iface != NULL) + if (uaa->iface == NULL || uaa->configno != 1) return UMATCH_NONE; return (usb_lookup(rum_devs, uaa->vendor, uaa->product) != NULL) ? - UMATCH_VENDOR_PRODUCT : UMATCH_NONE; + UMATCH_VENDOR_PRODUCT_CONF_IFACE : UMATCH_NONE; } void @@ -268,26 +268,11 @@ rum_attach(struct device *parent, struct device *self, void *aux) struct ifnet *ifp = &ic->ic_if; usb_interface_descriptor_t *id; usb_endpoint_descriptor_t *ed; - usbd_status error; int i, ntries; uint32_t tmp; sc->sc_udev = uaa->device; - - if (usbd_set_config_no(sc->sc_udev, RT2573_CONFIG_NO, 0) != 0) { - printf("%s: could not set configuration no\n", - sc->sc_dev.dv_xname); - return; - } - - /* get the first interface handle */ - error = usbd_device2interface_handle(sc->sc_udev, RT2573_IFACE_INDEX, - &sc->sc_iface); - if (error != 0) { - printf("%s: could not get interface handle\n", - sc->sc_dev.dv_xname); - return; - } + sc->sc_iface = uaa->iface; /* * Find endpoints. diff --git a/sys/dev/usb/if_rumreg.h b/sys/dev/usb/if_rumreg.h index 763fab1d9c6..5ca6d2cc3b1 100644 --- a/sys/dev/usb/if_rumreg.h +++ b/sys/dev/usb/if_rumreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_rumreg.h,v 1.15 2013/11/26 20:33:18 deraadt Exp $ */ +/* $OpenBSD: if_rumreg.h,v 1.16 2015/06/12 15:47:31 mpi Exp $ */ /*- * Copyright (c) 2005, 2006 Damien Bergamini @@ -20,9 +20,6 @@ #define RT2573_TX_DESC_SIZE (sizeof (struct rum_tx_desc)) #define RT2573_RX_DESC_SIZE (sizeof (struct rum_rx_desc)) -#define RT2573_CONFIG_NO 1 -#define RT2573_IFACE_INDEX 0 - #define RT2573_MCU_CNTL 0x01 #define RT2573_WRITE_MAC 0x02 #define RT2573_READ_MAC 0x03 diff --git a/sys/dev/usb/if_run.c b/sys/dev/usb/if_run.c index 5c3ffc3cf2c..73c87bf0889 100644 --- a/sys/dev/usb/if_run.c +++ b/sys/dev/usb/if_run.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_run.c,v 1.108 2015/03/14 03:38:49 jsg Exp $ */ +/* $OpenBSD: if_run.c,v 1.109 2015/06/12 15:47:31 mpi Exp $ */ /*- * Copyright (c) 2008-2010 Damien Bergamini @@ -518,11 +518,11 @@ run_match(struct device *parent, void *match, void *aux) { struct usb_attach_arg *uaa = aux; - if (uaa->iface != NULL) + if (uaa->iface == NULL || uaa->configno != 1) return UMATCH_NONE; return (usb_lookup(run_devs, uaa->vendor, uaa->product) != NULL) ? - UMATCH_VENDOR_PRODUCT : UMATCH_NONE; + UMATCH_VENDOR_PRODUCT_CONF_IFACE : UMATCH_NONE; } void @@ -534,24 +534,11 @@ run_attach(struct device *parent, struct device *self, void *aux) struct ifnet *ifp = &ic->ic_if; usb_interface_descriptor_t *id; usb_endpoint_descriptor_t *ed; - int i, nrx, ntx, ntries, error; + int i, nrx, ntx, ntries; uint32_t ver; sc->sc_udev = uaa->device; - - if (usbd_set_config_no(sc->sc_udev, 1, 0) != 0) { - printf("%s: could not set configuration no\n", - sc->sc_dev.dv_xname); - return; - } - - /* get the first interface handle */ - error = usbd_device2interface_handle(sc->sc_udev, 0, &sc->sc_iface); - if (error != 0) { - printf("%s: could not get interface handle\n", - sc->sc_dev.dv_xname); - return; - } + sc->sc_iface = uaa->iface; /* * Find all bulk endpoints. There are 7 bulk endpoints: 1 for RX diff --git a/sys/dev/usb/if_urtw.c b/sys/dev/usb/if_urtw.c index d369cd9cc67..782cdd837da 100644 --- a/sys/dev/usb/if_urtw.c +++ b/sys/dev/usb/if_urtw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_urtw.c,v 1.52 2015/03/14 03:38:49 jsg Exp $ */ +/* $OpenBSD: if_urtw.c,v 1.53 2015/06/12 15:47:31 mpi Exp $ */ /*- * Copyright (c) 2009 Martynas Venckus @@ -585,11 +585,11 @@ urtw_match(struct device *parent, void *match, void *aux) { struct usb_attach_arg *uaa = aux; - if (uaa->iface != NULL) + if (uaa->iface == NULL || uaa->configno != 1) return (UMATCH_NONE); return ((urtw_lookup(uaa->vendor, uaa->product) != NULL) ? - UMATCH_VENDOR_PRODUCT : UMATCH_NONE); + UMATCH_VENDOR_PRODUCT_CONF_IFACE : UMATCH_NONE); } void @@ -605,21 +605,9 @@ urtw_attach(struct device *parent, struct device *self, void *aux) int i; sc->sc_udev = uaa->device; + sc->sc_iface = uaa->iface; sc->sc_hwrev = urtw_lookup(uaa->vendor, uaa->product)->rev; - if (usbd_set_config_no(sc->sc_udev, 1, 0) != 0) { - printf("%s: could not set configuration no\n", - sc->sc_dev.dv_xname); - return; - } - - /* Get the first interface handle. */ - if (usbd_device2interface_handle(sc->sc_udev, 0, &sc->sc_iface) != 0) { - printf("%s: could not get interface handle\n", - sc->sc_dev.dv_xname); - return; - } - printf("%s: ", sc->sc_dev.dv_xname); if (sc->sc_hwrev & URTW_HWREV_8187) { diff --git a/sys/dev/usb/if_urtwn.c b/sys/dev/usb/if_urtwn.c index 0fa8b8125fe..db473980fa6 100644 --- a/sys/dev/usb/if_urtwn.c +++ b/sys/dev/usb/if_urtwn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_urtwn.c,v 1.47 2015/05/12 11:46:15 stsp Exp $ */ +/* $OpenBSD: if_urtwn.c,v 1.48 2015/06/12 15:47:31 mpi Exp $ */ /*- * Copyright (c) 2010 Damien Bergamini @@ -273,11 +273,11 @@ urtwn_match(struct device *parent, void *match, void *aux) { struct usb_attach_arg *uaa = aux; - if (uaa->iface != NULL) + if (uaa->iface == NULL || uaa->configno != 1) return (UMATCH_NONE); return ((usb_lookup(urtwn_devs, uaa->vendor, uaa->product) != NULL) ? - UMATCH_VENDOR_PRODUCT : UMATCH_NONE); + UMATCH_VENDOR_PRODUCT_CONF_IFACE : UMATCH_NONE); } void @@ -290,25 +290,12 @@ urtwn_attach(struct device *parent, struct device *self, void *aux) int i, error; sc->sc_udev = uaa->device; + sc->sc_iface = uaa->iface; usb_init_task(&sc->sc_task, urtwn_task, sc, USB_TASK_TYPE_GENERIC); timeout_set(&sc->scan_to, urtwn_next_scan, sc); timeout_set(&sc->calib_to, urtwn_calib_to, sc); - if (usbd_set_config_no(sc->sc_udev, 1, 0) != 0) { - printf("%s: could not set configuration no\n", - sc->sc_dev.dv_xname); - return; - } - - /* Get the first interface handle. */ - error = usbd_device2interface_handle(sc->sc_udev, 0, &sc->sc_iface); - if (error != 0) { - printf("%s: could not get interface handle\n", - sc->sc_dev.dv_xname); - return; - } - if (uaa->product == USB_PRODUCT_DLINK_DWA123D1 || uaa->product == USB_PRODUCT_DLINK_DWA125D1 || uaa->product == USB_PRODUCT_ELECOM_WDC150SU2M || diff --git a/sys/dev/usb/if_wi_usb.c b/sys/dev/usb/if_wi_usb.c index 32bff94fc6b..1b15af9f675 100644 --- a/sys/dev/usb/if_wi_usb.c +++ b/sys/dev/usb/if_wi_usb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_wi_usb.c,v 1.65 2015/06/10 20:50:05 miod Exp $ */ +/* $OpenBSD: if_wi_usb.c,v 1.66 2015/06/12 15:47:31 mpi Exp $ */ /* * Copyright (c) 2003 Dale Rahn. All rights reserved. @@ -271,11 +271,11 @@ wi_usb_match(struct device *parent, void *match, void *aux) { struct usb_attach_arg *uaa = aux; - if (uaa->iface != NULL) + if (uaa->iface == NULL || uaa->configno != 1) return (UMATCH_NONE); return (wi_usb_lookup(uaa->vendor, uaa->product) != NULL ? - UMATCH_VENDOR_PRODUCT : UMATCH_NONE); + UMATCH_VENDOR_PRODUCT_CONF_IFACE : UMATCH_NONE); } @@ -290,29 +290,15 @@ wi_usb_attach(struct device *parent, struct device *self, void *aux) struct usb_attach_arg *uaa = aux; /* int s; */ struct usbd_device *dev = uaa->device; - struct usbd_interface *iface; - usbd_status err; + struct usbd_interface *iface = uaa->iface; usb_interface_descriptor_t *id; usb_endpoint_descriptor_t *ed; int i; DPRINTFN(5,(" : wi_usb_attach: sc=%p", sc)); - err = usbd_set_config_no(dev, WI_USB_CONFIG_NO, 1); - if (err) { - printf("%s: setting config no failed\n", sc->wi_usb_dev.dv_xname); - return; - } - /* XXX - any tasks? */ - err = usbd_device2interface_handle(dev, WI_USB_IFACE_IDX, &iface); - if (err) { - printf("%s: getting interface handle failed\n", - sc->wi_usb_dev.dv_xname); - return; - } - /* XXX - flags? */ sc->wi_usb_udev = dev; diff --git a/sys/dev/usb/if_wi_usb.h b/sys/dev/usb/if_wi_usb.h index ebac126eda2..7216a5b0aed 100644 --- a/sys/dev/usb/if_wi_usb.h +++ b/sys/dev/usb/if_wi_usb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_wi_usb.h,v 1.2 2005/10/31 05:37:13 jsg Exp $ */ +/* $OpenBSD: if_wi_usb.h,v 1.3 2015/06/12 15:47:31 mpi Exp $ */ /* * Copyright (c) 2003 Dale Rahn. All rights reserved. @@ -28,15 +28,11 @@ * Materiel Command, USAF, under agreement number F30602-01-2-0537. */ -#define WI_USB_CONFIG_NO 1 - #define WI_USB_ENDPT_TX 1 #define WI_USB_ENDPT_RX 2 #define WI_USB_ENDPT_INTR 3 #define WI_USB_ENDPT_MAX 4 -#define WI_USB_IFACE_IDX 0 - /* XXX */ #define WI_USB_DATA_MAXLEN WI_DEFAULT_DATALEN