if_lc_isa.c revision 1.5
1/* $NetBSD: if_lc_isa.c,v 1.5 1997/11/17 03:34:24 thorpej 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 81extern struct cfdriver lc_cd; 82 83static int 84lemac_isa_probe( 85 struct device *parent, 86#ifdef __BROKEN_INDIRECT_CONFIG 87 void *match, 88#else 89 struct cfdata *match, 90#endif 91 void *aux) 92{ 93 struct isa_attach_args * const ia = aux; 94#ifdef __BROKEN_INDIRECT_CONFIG 95 struct cfdata *cf = ((struct device *)match)->dv_cfdata; 96#else 97 struct cfdata *cf = match; 98#endif 99 int irq, rv = 0; 100 bus_addr_t maddr; 101 bus_addr_t msize; 102 bus_space_handle_t memh; 103 bus_space_handle_t ioh; 104 105 /* 106 * Disallow wildcarded i/o addresses. 107 */ 108 if (ia->ia_iobase == IOBASEUNK) 109 return 0; 110 111 /* 112 * Make sure this is a valid LEMAC address. 113 */ 114 if (ia->ia_iobase & (LEMAC_IOSIZE - 1)) 115 return 0; 116 117 /* 118 * Map the LEMAC's port space for the probe sequence. 119 */ 120 if (bus_space_map(ia->ia_iot, ia->ia_iobase, LEMAC_IOSIZE, 0, &ioh)) 121 return 0; 122 123 /* 124 * Read the Ethernet address from the EEPROM. 125 * It must start with one of the DEC OUIs and pass the 126 * DEC ethernet checksum test. 127 */ 128 if (lemac_port_check(ia->ia_iot, ioh) == 0) 129 goto out; 130 131 /* 132 * Get information about memory space and attempt to map it. 133 */ 134 lemac_info_get(ia->ia_iot, ioh, &maddr, &msize, &irq); 135 if (ia->ia_maddr != maddr && ia->ia_maddr != MADDRUNK) 136 goto out; 137 if (bus_space_map(ia->ia_memt, maddr, msize, 0, &memh)) 138 goto out; 139 bus_space_unmap(ia->ia_memt, memh, msize); 140 141 /* 142 * Double-check IRQ configuration. 143 */ 144 if (ia->ia_irq != irq && ia->ia_irq != IRQUNK) 145 printf("%s%d: overriding IRQ %d to %d\n", lc_cd.cd_name, cf->cf_unit, 146 ia->ia_irq, irq); 147 ia->ia_irq = irq; 148 149 /* 150 * I guess we've found one. 151 */ 152 rv = 1; 153 154 out: 155 bus_space_unmap(ia->ia_iot, ioh, LEMAC_IOSIZE); 156 return rv; 157} 158 159static void 160lemac_isa_attach( 161 struct device *parent, 162 struct device *self, 163 void *aux) 164{ 165 lemac_softc_t *sc = (void *)self; 166 struct isa_attach_args *ia = aux; 167 168 /* Map i/o space. */ 169 sc->sc_iot = ia->ia_iot; 170 if (bus_space_map(sc->sc_iot, ia->ia_iobase, ia->ia_iosize, 0, 171 &sc->sc_ioh)) { 172 printf(": can't map i/o space\n"); 173 return; 174 } 175 176 if (ia->ia_msize && ia->ia_maddr) { 177 sc->sc_memt = ia->ia_memt; 178 /* Map memory space. */ 179 if (bus_space_map(sc->sc_memt, ia->ia_maddr, ia->ia_msize, 0, 180 &sc->sc_memh)) { 181 printf(": can't map mem space\n"); 182 return; 183 } 184 } 185 186 sc->sc_ats = shutdownhook_establish(lemac_shutdown, sc); 187 if (sc->sc_ats == NULL) 188 printf("\n%s: warning: couldn't establish shutdown hook\n", 189 sc->sc_dv.dv_xname); 190 191 lemac_ifattach(sc); 192 193 sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE, 194 IPL_NET, lemac_intr, sc); 195} 196 197struct cfattach lc_isa_ca = { 198 sizeof(lemac_softc_t), lemac_isa_probe, lemac_isa_attach 199}; 200