static int ndisusb_attach(device_t self) { const struct drvdb_ent *db; struct ndisusb_softc *dummy = device_get_softc(self); struct usb_attach_arg *uaa = device_get_ivars(self); struct ndis_softc *sc; struct ndis_usb_type *t; driver_object *drv; int devidx = 0; device_set_usb_desc(self); db = uaa->driver_ivar; sc = (struct ndis_softc *)dummy; sc->ndis_dev = self; mtx_init(&sc->ndisusb_mtx, "NDIS USB", MTX_NETWORK_LOCK, MTX_DEF); sc->ndis_dobj = db->windrv_object; sc->ndis_regvals = db->windrv_regvals; sc->ndis_iftype = PNPBus; sc->ndisusb_dev = uaa->device; /* Create PDO for this device instance */ drv = windrv_lookup(0, "USB Bus"); windrv_create_pdo(drv, self); /* Figure out exactly which device we matched. */ t = db->windrv_devlist; while (t->ndis_name != NULL) { if ((uaa->info.idVendor == t->ndis_vid) && (uaa->info.idProduct == t->ndis_did)) { sc->ndis_devidx = devidx; break; } t++; devidx++; } if (ndis_attach(self) != 0) return (ENXIO); return (0); }
static int ndis_attach_usb(device_t dev) { const struct drvdb_ent *db; struct ndisusb_softc *dummy; struct usb_attach_arg *uaa; struct ndis_softc *sc; struct ndis_device_type *t; struct driver_object *drv; int devidx = 0; device_set_usb_desc(dev); dummy = device_get_softc(dev); uaa = device_get_ivars(dev); db = uaa->driver_ivar; sc = (struct ndis_softc *)dummy; sc->ndis_dev = dev; mtx_init(&sc->ndisusb_mtx, "NDIS USB", MTX_NETWORK_LOCK, MTX_DEF); sc->ndis_dobj = db->windrv_object; sc->ndis_regvals = db->windrv_regvals; sc->ndis_bus_type = NDIS_PNPBUS; sc->ndisusb_dev = uaa->device; drv = windrv_lookup(0, "USB Bus"); windrv_create_pdo(drv, dev); /* Figure out exactly which device we matched. */ for (t = db->windrv_devlist; t->name != NULL; t++, devidx++) { if ((uaa->info.idVendor == t->vendor) && (uaa->info.idProduct == t->device)) { sc->ndis_devidx = devidx; break; } } if (ndis_attach(dev) != 0) return (ENXIO); return (0); }
/* * Attach the interface. Allocate softc structures, do ifmedia * setup and ethernet/BPF attach. */ static int ndis_attach_pccard(device_t dev) { struct ndis_softc *sc; int unit, error = 0, rid; struct ndis_pccard_type *t; int devidx = 0; const char *prodstr, *vendstr; struct drvdb_ent *db; wlan_serialize_enter(); sc = device_get_softc(dev); unit = device_get_unit(dev); sc->ndis_dev = dev; db = windrv_match((matchfuncptr)ndis_devcompare, dev); if (db == NULL) { wlan_serialize_exit(); return (ENXIO); } sc->ndis_dobj = db->windrv_object; sc->ndis_regvals = db->windrv_regvals; resource_list_init(&sc->ndis_rl); sc->ndis_io_rid = 0; sc->ndis_res_io = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &sc->ndis_io_rid, RF_ACTIVE); if (sc->ndis_res_io == NULL) { device_printf(dev, "couldn't map iospace\n"); error = ENXIO; goto fail; } sc->ndis_rescnt++; resource_list_add(&sc->ndis_rl, SYS_RES_IOPORT, rid, rman_get_start(sc->ndis_res_io), rman_get_end(sc->ndis_res_io), rman_get_size(sc->ndis_res_io), -1); rid = 0; sc->ndis_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE); if (sc->ndis_irq == NULL) { device_printf(dev, "couldn't map interrupt\n"); error = ENXIO; goto fail; } sc->ndis_rescnt++; resource_list_add(&sc->ndis_rl, SYS_RES_IRQ, rid, rman_get_start(sc->ndis_irq), rman_get_start(sc->ndis_irq), 1, rman_get_cpuid(sc->ndis_irq)); sc->ndis_iftype = PCMCIABus; /* Figure out exactly which device we matched. */ t = db->windrv_devlist; prodstr = pccard_get_product_str(dev); vendstr = pccard_get_vendor_str(dev); while(t->ndis_name != NULL) { if (strcasecmp(vendstr, t->ndis_vid) == 0 && strcasecmp(prodstr, t->ndis_did) == 0) break; t++; devidx++; } sc->ndis_devidx = devidx; error = ndis_attach(dev); fail: wlan_serialize_exit(); return(error); }
static int ndis_attach_pccard(device_t dev) { struct ndis_softc *sc; struct ndis_device_type *t; struct drvdb_ent *db; uint32_t product, vendor; int devidx = 0, error = 0, rid = 0; sc = device_get_softc(dev); sc->ndis_dev = dev; db = windrv_match((matchfuncptr)ndis_devcompare_pccard, dev); if (db == NULL) return (ENXIO); sc->ndis_dobj = db->windrv_object; sc->ndis_regvals = db->windrv_regvals; resource_list_init(&sc->ndis_rl); sc->ndis_io_rid = 0; sc->ndis_res_io = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &sc->ndis_io_rid, RF_ACTIVE); if (sc->ndis_res_io == NULL) { device_printf(dev, "couldn't map iospace\n"); return (ENXIO); } sc->ndis_rescnt++; resource_list_add(&sc->ndis_rl, SYS_RES_IOPORT, sc->ndis_io_rid, rman_get_start(sc->ndis_res_io), rman_get_end(sc->ndis_res_io), rman_get_size(sc->ndis_res_io)); sc->ndis_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE); if (sc->ndis_irq == NULL) { device_printf(dev, "couldn't map interrupt\n"); return (ENXIO); } sc->ndis_rescnt++; resource_list_add(&sc->ndis_rl, SYS_RES_IRQ, rid, rman_get_start(sc->ndis_irq), rman_get_start(sc->ndis_irq), 1); sc->ndis_bus_type = NDIS_PCMCIABUS; error = pccard_get_product(dev, &product); if (error) return (error); error = pccard_get_vendor(dev, &vendor); if (error) return (error); /* Figure out exactly which device we matched. */ for (t = db->windrv_devlist; t->name != NULL; t++, devidx++) { if ((vendor == t->vendor) && (product == t->device)) break; } sc->ndis_devidx = devidx; error = ndis_alloc_amem(sc); if (error) { ndis_free_amem(sc); return (error); } return (ndis_attach(dev)); }
static int ndisusb_attach(device_t self) { struct drvdb_ent *db; struct ndisusb_softc *dummy = device_get_softc(self); struct usb_attach_arg *uaa = device_get_ivars(self); struct ndis_softc *sc; struct ndis_usb_type *t; driver_object *drv; int devidx = 0; usbd_status status; wlan_serialize_enter(); sc = (struct ndis_softc *)dummy; if (uaa->device == NULL) { wlan_serialize_exit(); return ENXIO; } db = windrv_match((matchfuncptr)ndisusb_devcompare, self); if (db == NULL) { wlan_serialize_exit(); return (ENXIO); } sc->ndis_dev = self; sc->ndis_dobj = db->windrv_object; sc->ndis_regvals = db->windrv_regvals; sc->ndis_iftype = PNPBus; /* Create PDO for this device instance */ drv = windrv_lookup(0, "USB Bus"); windrv_create_pdo(drv, self); status = usbd_set_config_no(uaa->device, NDISUSB_CONFIG_NO, 0); if (status != USBD_NORMAL_COMPLETION) { device_printf(self, "setting config no failed\n"); wlan_serialize_exit(); return (ENXIO); } /* Figure out exactly which device we matched. */ t = db->windrv_devlist; while (t->ndis_name != NULL) { if ((uaa->vendor == t->ndis_vid) && (uaa->product == t->ndis_did)) { sc->ndis_devidx = devidx; break; } t++; devidx++; } if (ndis_attach(self) != 0) { wlan_serialize_exit(); return ENXIO; } usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, uaa->device, self); wlan_serialize_exit(); return 0; }