if_lc_isa.c revision 1.12
1/* $NetBSD: if_lc_isa.c,v 1.12 2001/11/13 08:01:20 lukem Exp $ */ 2 3/*- 4 * Copyright (c) 1994, 1995, 1997 Matt Thomas <matt@3am-software.com> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. The name of the author may not be used to endorse or promote products 13 * derived from this software without specific prior written permission 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27/* 28 * DEC EtherWORKS 3 Ethernet Controllers 29 * 30 * Written by Matt Thomas 31 * 32 * This driver supports the LEMAC (DE203, DE204, and DE205) cards. 33 */ 34 35#include <sys/cdefs.h> 36__KERNEL_RCSID(0, "$NetBSD: if_lc_isa.c,v 1.12 2001/11/13 08:01:20 lukem Exp $"); 37 38#include <sys/param.h> 39#include <sys/systm.h> 40#include <sys/mbuf.h> 41#include <sys/socket.h> 42#include <sys/ioctl.h> 43#include <sys/errno.h> 44#include <sys/syslog.h> 45#include <sys/select.h> 46#include <sys/device.h> 47#include <sys/queue.h> 48 49#include <net/if.h> 50#include <net/if_dl.h> 51#include <net/if_ether.h> 52#include <net/if_media.h> 53 54#include <machine/cpu.h> 55#include <machine/bus.h> 56#include <machine/intr.h> 57 58#include <dev/ic/lemacreg.h> 59#include <dev/ic/lemacvar.h> 60 61#include <dev/isa/isavar.h> 62 63extern struct cfdriver lc_cd; 64 65static int lemac_isa_find __P((lemac_softc_t *, struct isa_attach_args *, 66 int)); 67static int lemac_isa_probe __P((struct device *, struct cfdata *, void *)); 68static void lemac_isa_attach __P((struct device *, struct device *, void *)); 69 70struct cfattach lc_isa_ca = { 71 sizeof(lemac_softc_t), lemac_isa_probe, lemac_isa_attach 72}; 73 74static int 75lemac_isa_find(sc, ia, attach) 76 lemac_softc_t *sc; 77 struct isa_attach_args *ia; 78 int attach; 79{ 80 bus_addr_t maddr; 81 bus_addr_t msize; 82 int rv = 0, irq; 83 84 /* 85 * Disallow wildcarded i/o addresses. 86 */ 87 if (ia->ia_iobase == IOBASEUNK) 88 return 0; 89 90 /* 91 * Make sure this is a valid LEMAC address. 92 */ 93 if (ia->ia_iobase & (LEMAC_IOSIZE - 1)) 94 return 0; 95 96 sc->sc_iot = ia->ia_iot; 97 98 /* 99 * Map the LEMAC's port space for the probe sequence. 100 */ 101 ia->ia_iosize = LEMAC_IOSIZE; 102 103 if (bus_space_map(sc->sc_iot, ia->ia_iobase, ia->ia_iosize, 0, 104 &sc->sc_ioh)) { 105 if (attach) 106 printf(": can't map i/o space\n"); 107 return 0; 108 } 109 110 /* 111 * Read the Ethernet address from the EEPROM. 112 * It must start with one of the DEC OUIs and pass the 113 * DEC ethernet checksum test. 114 */ 115 if (lemac_port_check(sc->sc_iot, sc->sc_ioh) == 0) 116 goto outio; 117 118 /* 119 * Get information about memory space and attempt to map it. 120 */ 121 lemac_info_get(sc->sc_iot, sc->sc_ioh, &maddr, &msize, &irq); 122 123 if (ia->ia_maddr != maddr && ia->ia_maddr != MADDRUNK) 124 goto outio; 125 126 sc->sc_memt = ia->ia_memt; 127 if (bus_space_map(ia->ia_memt, maddr, msize, 0, &sc->sc_memh)) { 128 if (attach) 129 printf(": can't map mem space\n"); 130 goto outio; 131 } 132 133 134 /* 135 * Double-check IRQ configuration. 136 */ 137 if (ia->ia_irq != irq && ia->ia_irq != IRQUNK) 138 printf("%s: overriding IRQ %d to %d\n", sc->sc_dv.dv_xname, 139 ia->ia_irq, irq); 140 141 if (attach) { 142 sc->sc_ats = shutdownhook_establish(lemac_shutdown, sc); 143 if (sc->sc_ats == NULL) 144 printf("\n%s: warning: can't establish shutdown hook\n", 145 sc->sc_dv.dv_xname); 146 147 lemac_ifattach(sc); 148 149 sc->sc_ih = isa_intr_establish(ia->ia_ic, irq, IST_EDGE, 150 IPL_NET, lemac_intr, sc); 151 } 152 153 /* 154 * I guess we've found one. 155 */ 156 rv = 1; 157 158 ia->ia_maddr = maddr; 159 ia->ia_msize = msize; 160 ia->ia_irq = irq; 161 162 if (rv == 0 || !attach) 163 bus_space_unmap(sc->sc_memt, sc->sc_memh, msize); 164outio: 165 if (rv == 0 || !attach) 166 bus_space_unmap(sc->sc_iot, sc->sc_ioh, LEMAC_IOSIZE); 167 return rv; 168} 169 170static int 171lemac_isa_probe(parent, match, aux) 172 struct device *parent; 173 struct cfdata *match; 174 void *aux; 175{ 176 struct isa_attach_args *ia = aux; 177 struct cfdata *cf = match; 178 lemac_softc_t sc; 179 (void)sprintf(sc.sc_dv.dv_xname, "%s%d", lc_cd.cd_name, cf->cf_unit); 180 181 return lemac_isa_find(&sc, ia, 0); 182} 183 184static void 185lemac_isa_attach(parent, self, aux) 186 struct device *parent; 187 struct device *self; 188 void *aux; 189{ 190 lemac_softc_t *sc = (void *)self; 191 struct isa_attach_args *ia = aux; 192 193 (void) lemac_isa_find(sc, ia, 1); 194} 195