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