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