static int ex_isa_attach(device_t dev) { struct ex_softc * sc = device_get_softc(dev); int error = 0; uint16_t temp; sc->dev = dev; sc->ioport_rid = 0; sc->irq_rid = 0; sc->flags |= HAS_INT_NO_REG; if ((error = ex_alloc_resources(dev)) != 0) { device_printf(dev, "ex_alloc_resources() failed!\n"); goto bad; } /* * Fill in several fields of the softc structure: * - I/O base address. * - Hardware Ethernet address. * - IRQ number (if not supplied in config file, read it from EEPROM). * - Connector type. */ sc->irq_no = rman_get_start(sc->irq); ex_get_address(sc, sc->enaddr); temp = ex_eeprom_read(sc, EE_W0); device_printf(sc->dev, "%s config, %s bus, ", (temp & EE_W0_PNP) ? "PnP" : "Manual", (temp & EE_W0_BUS16) ? "16-bit" : "8-bit"); temp = ex_eeprom_read(sc, EE_W6); printf("board id 0x%03x, stepping 0x%01x\n", (temp & EE_W6_BOARD_MASK) >> EE_W6_BOARD_SHIFT, temp & EE_W6_STEP_MASK); if ((error = ex_attach(dev)) != 0) { device_printf(dev, "ex_attach() failed!\n"); goto bad; } return(0); bad: ex_release_resources(dev); return (error); }
void ex_get_address(struct ex_softc *sc, u_char *enaddr) { uint16_t eaddr_tmp; eaddr_tmp = ex_eeprom_read(sc, EE_Eth_Addr_Lo); enaddr[5] = eaddr_tmp & 0xff; enaddr[4] = eaddr_tmp >> 8; eaddr_tmp = ex_eeprom_read(sc, EE_Eth_Addr_Mid); enaddr[3] = eaddr_tmp & 0xff; enaddr[2] = eaddr_tmp >> 8; eaddr_tmp = ex_eeprom_read(sc, EE_Eth_Addr_Hi); enaddr[1] = eaddr_tmp & 0xff; enaddr[0] = eaddr_tmp >> 8; return; }
int ex_attach(device_t dev) { struct ex_softc * sc = device_get_softc(dev); struct ifnet * ifp; struct ifmedia * ifm; int error; uint16_t temp; ifp = sc->ifp = if_alloc(IFT_ETHER); if (ifp == NULL) { device_printf(dev, "can not if_alloc()\n"); return (ENOSPC); } /* work out which set of irq <-> internal tables to use */ if (ex_card_type(sc->enaddr) == CARD_TYPE_EX_10_PLUS) { sc->irq2ee = plus_irq2eemap; sc->ee2irq = plus_ee2irqmap; } else { sc->irq2ee = irq2eemap; sc->ee2irq = ee2irqmap; } sc->mem_size = CARD_RAM_SIZE; /* XXX This should be read from the card itself. */ /* * Initialize the ifnet structure. */ ifp->if_softc = sc; if_initname(ifp, device_get_name(dev), device_get_unit(dev)); ifp->if_flags = IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST; ifp->if_start = ex_start; ifp->if_ioctl = ex_ioctl; ifp->if_init = ex_init; IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen); ifmedia_init(&sc->ifmedia, 0, ex_ifmedia_upd, ex_ifmedia_sts); mtx_init(&sc->lock, device_get_nameunit(dev), MTX_NETWORK_LOCK, MTX_DEF); callout_init_mtx(&sc->timer, &sc->lock, 0); temp = ex_eeprom_read(sc, EE_W5); if (temp & EE_W5_PORT_TPE) ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_T, 0, NULL); if (temp & EE_W5_PORT_BNC) ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_2, 0, NULL); if (temp & EE_W5_PORT_AUI) ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_5, 0, NULL); ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_AUTO, 0, NULL); ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_NONE, 0, NULL); ifmedia_set(&sc->ifmedia, ex_get_media(sc)); ifm = &sc->ifmedia; ifm->ifm_media = ifm->ifm_cur->ifm_media; ex_ifmedia_upd(ifp); /* * Attach the interface. */ ether_ifattach(ifp, sc->enaddr); error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET | INTR_MPSAFE, NULL, ex_intr, (void *)sc, &sc->ih); if (error) { device_printf(dev, "bus_setup_intr() failed!\n"); ether_ifdetach(ifp); mtx_destroy(&sc->lock); return (error); } return(0); }
static int ex_isa_probe(device_t dev) { bus_addr_t iobase; u_int irq; char * irq2ee; u_char * ee2irq; u_char enaddr[6]; int tmp; int error; struct ex_softc *sc = device_get_softc(dev); /* Check isapnp ids */ error = ISA_PNP_PROBE(device_get_parent(dev), dev, ex_ids); /* If the card had a PnP ID that didn't match any we know about */ if (error == ENXIO) return(error); /* If we had some other problem. */ if (!(error == 0 || error == ENOENT)) return(error); error = ex_alloc_resources(dev); if (error != 0) goto bad; iobase = bus_get_resource_start(dev, SYS_RES_IOPORT, 0); if (!ex_look_for_card(sc)) { if (bootverbose) printf("ex: no card found at 0x%03lx.\n", (unsigned long)iobase); error = ENXIO; goto bad; } if (bootverbose) printf("ex: ex_isa_probe() found card at 0x%03lx\n", (unsigned long)iobase); /* * Reset the card. */ CSR_WRITE_1(sc, CMD_REG, Reset_CMD); DELAY(800); ex_get_address(sc, enaddr); /* work out which set of irq <-> internal tables to use */ if (ex_card_type(enaddr) == CARD_TYPE_EX_10_PLUS) { irq2ee = plus_irq2eemap; ee2irq = plus_ee2irqmap; } else { irq2ee = irq2eemap; ee2irq = ee2irqmap; } tmp = ex_eeprom_read(sc, EE_W1) & EE_W1_INT_SEL; irq = bus_get_resource_start(dev, SYS_RES_IRQ, 0); if (irq > 0) { /* This will happen if board is in PnP mode. */ if (ee2irq[tmp] != irq) { device_printf(dev, "WARNING: IRQ mismatch: EEPROM %d, using %d\n", ee2irq[tmp], irq); } } else { irq = ee2irq[tmp]; bus_set_resource(dev, SYS_RES_IRQ, 0, irq, 1); } if (irq == 0) { printf("ex: invalid IRQ.\n"); error = ENXIO; } bad:; ex_release_resources(dev); return (error); }
/* * Non-destructive identify. */ static void ex_isa_identify(driver_t *driver, device_t parent) { device_t child; bus_addr_t ioport; u_char enaddr[6]; u_int irq; int tmp; const char * desc; struct ex_softc sc; int rid; if (bootverbose) printf("ex_isa_identify()\n"); for (ioport = 0x200; ioport < 0x3a0; ioport += 0x10) { rid = 0; sc.ioport = bus_alloc_resource(parent, SYS_RES_IOPORT, &rid, ioport, ioport, 0x10, RF_ACTIVE); if (sc.ioport == NULL) continue; /* No board found at address */ if (!ex_look_for_card(&sc)) { bus_release_resource(parent, SYS_RES_IOPORT, rid, sc.ioport); continue; } if (bootverbose) printf("ex: Found card at 0x%03lx!\n", (unsigned long)ioport); /* Board in PnP mode */ if (ex_eeprom_read(&sc, EE_W0) & EE_W0_PNP) { /* Reset the card. */ CSR_WRITE_1(&sc, CMD_REG, Reset_CMD); DELAY(500); if (bootverbose) printf("ex: card at 0x%03lx in PnP mode!\n", (unsigned long)ioport); bus_release_resource(parent, SYS_RES_IOPORT, rid, sc.ioport); continue; } bzero(enaddr, sizeof(enaddr)); /* Reset the card. */ CSR_WRITE_1(&sc, CMD_REG, Reset_CMD); DELAY(400); ex_get_address(&sc, enaddr); tmp = ex_eeprom_read(&sc, EE_W1) & EE_W1_INT_SEL; /* work out which set of irq <-> internal tables to use */ if (ex_card_type(enaddr) == CARD_TYPE_EX_10_PLUS) { irq = plus_ee2irqmap[tmp]; desc = "Intel Pro/10+"; } else { irq = ee2irqmap[tmp]; desc = "Intel Pro/10"; } bus_release_resource(parent, SYS_RES_IOPORT, rid, sc.ioport); child = BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, "ex", -1); device_set_desc_copy(child, desc); device_set_driver(child, driver); bus_set_resource(child, SYS_RES_IRQ, 0, irq, 1); bus_set_resource(child, SYS_RES_IOPORT, 0, ioport, EX_IOSIZE); if (bootverbose) printf("ex: Adding board at 0x%03lx, irq %d\n", (unsigned long)ioport, irq); } return; }