1 /* $NetBSD: if_lc_isa.c,v 1.6 1997/11/30 20:03:15 christos 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 withough 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 "bpfilter.h" 36 37 #include <sys/param.h> 38 #include <sys/systm.h> 39 #include <sys/mbuf.h> 40 #include <sys/socket.h> 41 #include <sys/ioctl.h> 42 #include <sys/errno.h> 43 #include <sys/syslog.h> 44 #include <sys/select.h> 45 #include <sys/device.h> 46 #include <sys/queue.h> 47 48 #include <net/if.h> 49 #include <net/if_dl.h> 50 #include <net/if_ether.h> 51 #include <net/if_media.h> 52 53 54 #ifdef INET 55 #include <netinet/in.h> 56 #include <netinet/in_systm.h> 57 #include <netinet/in_var.h> 58 #include <netinet/ip.h> 59 #include <netinet/if_inarp.h> 60 #endif 61 62 #ifdef NS 63 #include <netns/ns.h> 64 #include <netns/ns_if.h> 65 #endif 66 67 #if NBPFILTER > 0 68 #include <net/bpf.h> 69 #include <net/bpfdesc.h> 70 #endif 71 72 #include <machine/cpu.h> 73 #include <machine/bus.h> 74 #include <machine/intr.h> 75 76 #include <dev/ic/lemacreg.h> 77 #include <dev/ic/lemacvar.h> 78 79 #include <dev/isa/isavar.h> 80 81 extern struct cfdriver lc_cd; 82 83 static int lemac_isa_find __P((lemac_softc_t *, struct isa_attach_args *, 84 int)); 85 #ifdef __BROKEN_INDIRECT_CONFIG 86 static int lemac_isa_probe __P((struct device *, void *, void *)); 87 #else 88 static int lemac_isa_probe __P((struct device *, struct cfdata *, void *)); 89 #endif 90 static void lemac_isa_attach __P((struct device *, struct device *, void *)); 91 92 struct cfattach lc_isa_ca = { 93 sizeof(lemac_softc_t), lemac_isa_probe, lemac_isa_attach 94 }; 95 96 static int 97 lemac_isa_find(sc, ia, attach) 98 lemac_softc_t *sc; 99 struct isa_attach_args *ia; 100 int attach; 101 { 102 bus_addr_t maddr; 103 bus_addr_t msize; 104 int rv = 0, irq; 105 106 /* 107 * Disallow wildcarded i/o addresses. 108 */ 109 if (ia->ia_iobase == IOBASEUNK) 110 return 0; 111 112 /* 113 * Make sure this is a valid LEMAC address. 114 */ 115 if (ia->ia_iobase & (LEMAC_IOSIZE - 1)) 116 return 0; 117 118 sc->sc_iot = ia->ia_iot; 119 120 /* 121 * Map the LEMAC's port space for the probe sequence. 122 */ 123 ia->ia_iosize = LEMAC_IOSIZE; 124 125 if (bus_space_map(sc->sc_iot, ia->ia_iobase, ia->ia_iosize, 0, 126 &sc->sc_ioh)) { 127 if (attach) 128 printf(": can't map i/o space\n"); 129 return 0; 130 } 131 132 /* 133 * Read the Ethernet address from the EEPROM. 134 * It must start with one of the DEC OUIs and pass the 135 * DEC ethernet checksum test. 136 */ 137 if (lemac_port_check(sc->sc_iot, sc->sc_ioh) == 0) 138 goto outio; 139 140 /* 141 * Get information about memory space and attempt to map it. 142 */ 143 lemac_info_get(sc->sc_iot, sc->sc_ioh, &maddr, &msize, &irq); 144 145 if (ia->ia_maddr != maddr && ia->ia_maddr != MADDRUNK) 146 goto outio; 147 148 sc->sc_memt = ia->ia_memt; 149 if (bus_space_map(ia->ia_memt, maddr, msize, 0, &sc->sc_memh)) { 150 if (attach) 151 printf(": can't map mem space\n"); 152 goto outio; 153 } 154 155 156 /* 157 * Double-check IRQ configuration. 158 */ 159 if (ia->ia_irq != irq && ia->ia_irq != IRQUNK) 160 printf("%s: overriding IRQ %d to %d\n", sc->sc_dv.dv_xname, 161 ia->ia_irq, irq); 162 163 if (attach) { 164 sc->sc_ats = shutdownhook_establish(lemac_shutdown, sc); 165 if (sc->sc_ats == NULL) 166 printf("\n%s: warning: can't establish shutdown hook\n", 167 sc->sc_dv.dv_xname); 168 169 lemac_ifattach(sc); 170 171 sc->sc_ih = isa_intr_establish(ia->ia_ic, irq, IST_EDGE, 172 IPL_NET, lemac_intr, sc); 173 } 174 175 /* 176 * I guess we've found one. 177 */ 178 rv = 1; 179 180 ia->ia_maddr = maddr; 181 ia->ia_msize = msize; 182 ia->ia_irq = irq; 183 184 if (rv == 0 || !attach) 185 bus_space_unmap(sc->sc_memt, sc->sc_memh, msize); 186 outio: 187 if (rv == 0 || !attach) 188 bus_space_unmap(sc->sc_iot, sc->sc_ioh, LEMAC_IOSIZE); 189 return rv; 190 } 191 192 static int 193 lemac_isa_probe(parent, match, aux) 194 struct device *parent; 195 #ifdef __BROKEN_INDIRECT_CONFIG 196 void *match; 197 #else 198 struct cfdata *match; 199 #endif 200 void *aux; 201 { 202 struct isa_attach_args *ia = aux; 203 #ifdef __BROKEN_INDIRECT_CONFIG 204 struct cfdata *cf = ((struct device *)match)->dv_cfdata; 205 #else 206 struct cfdata *cf = match; 207 #endif 208 lemac_softc_t sc; 209 (void)sprintf(sc.sc_dv.dv_xname, "%s%d", lc_cd.cd_name, cf->cf_unit); 210 211 return lemac_isa_find(&sc, ia, 0); 212 } 213 214 static void 215 lemac_isa_attach(parent, self, aux) 216 struct device *parent; 217 struct device *self; 218 void *aux; 219 { 220 lemac_softc_t *sc = (void *)self; 221 struct isa_attach_args *ia = aux; 222 223 (void) lemac_isa_find(sc, ia, 1); 224 } 225