1 /* $NetBSD: if_lc_isa.c,v 1.18 2004/07/03 21:29:08 mycroft 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.18 2004/07/03 21:29:08 mycroft 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 63 extern struct cfdriver lc_cd; 64 65 static int lemac_isa_find __P((lemac_softc_t *, struct isa_attach_args *, 66 int)); 67 static int lemac_isa_probe __P((struct device *, struct cfdata *, void *)); 68 static void lemac_isa_attach __P((struct device *, struct device *, void *)); 69 70 CFATTACH_DECL(lc_isa, sizeof(lemac_softc_t), 71 lemac_isa_probe, lemac_isa_attach, NULL, NULL); 72 73 static int 74 lemac_isa_find(sc, ia, attach) 75 lemac_softc_t *sc; 76 struct isa_attach_args *ia; 77 int attach; 78 { 79 bus_addr_t maddr; 80 bus_addr_t msize; 81 int rv = 0, irq; 82 83 if (ia->ia_nio < 1) 84 return (0); 85 if (ia->ia_niomem < 1) 86 return (0); 87 if (ia->ia_nirq < 1) 88 return (0); 89 90 if (ISA_DIRECT_CONFIG(ia)) 91 return (0); 92 93 /* 94 * Disallow wildcarded i/o addresses. 95 */ 96 if (ia->ia_io[0].ir_addr == ISACF_PORT_DEFAULT) 97 return 0; 98 99 /* 100 * Make sure this is a valid LEMAC address. 101 */ 102 if (ia->ia_io[0].ir_addr & (LEMAC_IOSIZE - 1)) 103 return 0; 104 105 sc->sc_iot = ia->ia_iot; 106 107 if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, LEMAC_IOSIZE, 0, 108 &sc->sc_ioh)) { 109 if (attach) 110 printf(": can't map i/o space\n"); 111 return 0; 112 } 113 114 /* 115 * Read the Ethernet address from the EEPROM. 116 * It must start with one of the DEC OUIs and pass the 117 * DEC ethernet checksum test. 118 */ 119 if (lemac_port_check(sc->sc_iot, sc->sc_ioh) == 0) 120 goto outio; 121 122 /* 123 * Get information about memory space and attempt to map it. 124 */ 125 lemac_info_get(sc->sc_iot, sc->sc_ioh, &maddr, &msize, &irq); 126 127 if (ia->ia_iomem[0].ir_addr != ISACF_IOMEM_DEFAULT && 128 ia->ia_iomem[0].ir_addr != maddr) 129 goto outio; 130 131 if (attach) { 132 if (msize == 0) { 133 printf(": memory configuration is invalid\n"); 134 goto outio; 135 } 136 137 sc->sc_memt = ia->ia_memt; 138 if (bus_space_map(ia->ia_memt, maddr, msize, 0, &sc->sc_memh)) { 139 printf(": can't map mem space\n"); 140 goto outio; 141 } 142 } 143 144 /* 145 * Double-check IRQ configuration. 146 */ 147 if (ia->ia_irq[0].ir_irq != ISACF_IRQ_DEFAULT && 148 ia->ia_irq[0].ir_irq != irq) 149 printf("%s: overriding IRQ %d to %d\n", sc->sc_dv.dv_xname, 150 ia->ia_irq[0].ir_irq, irq); 151 152 if (attach) { 153 sc->sc_ats = shutdownhook_establish(lemac_shutdown, sc); 154 if (sc->sc_ats == NULL) 155 printf("\n%s: warning: can't establish shutdown hook\n", 156 sc->sc_dv.dv_xname); 157 158 lemac_ifattach(sc); 159 160 sc->sc_ih = isa_intr_establish(ia->ia_ic, irq, IST_EDGE, 161 IPL_NET, lemac_intr, sc); 162 } 163 164 /* 165 * I guess we've found one. 166 */ 167 rv = 1; 168 169 ia->ia_nio = 1; 170 ia->ia_io[0].ir_size = LEMAC_IOSIZE; 171 172 ia->ia_niomem = 1; 173 ia->ia_iomem[0].ir_addr = maddr; 174 ia->ia_iomem[0].ir_size = msize; 175 176 ia->ia_nirq = 1; 177 ia->ia_irq[0].ir_irq = irq; 178 179 ia->ia_ndrq = 0; 180 181 if (rv == 0 && attach) 182 bus_space_unmap(sc->sc_memt, sc->sc_memh, msize); 183 outio: 184 if (rv == 0 || !attach) 185 bus_space_unmap(sc->sc_iot, sc->sc_ioh, LEMAC_IOSIZE); 186 return rv; 187 } 188 189 static int 190 lemac_isa_probe(parent, match, aux) 191 struct device *parent; 192 struct cfdata *match; 193 void *aux; 194 { 195 struct isa_attach_args *ia = aux; 196 struct cfdata *cf = match; 197 lemac_softc_t sc; 198 snprintf(sc.sc_dv.dv_xname, sizeof(sc.sc_dv.dv_xname), "%s%d", 199 lc_cd.cd_name, cf->cf_unit); 200 201 return lemac_isa_find(&sc, ia, 0); 202 } 203 204 static void 205 lemac_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