1 /* $NetBSD: if_le_isa.c,v 1.27 2001/07/08 17:55:50 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace 9 * Simulation Facility, NASA Ames Research Center. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by the NetBSD 22 * Foundation, Inc. and its contributors. 23 * 4. Neither the name of The NetBSD Foundation nor the names of its 24 * contributors may be used to endorse or promote products derived 25 * from this software without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 * POSSIBILITY OF SUCH DAMAGE. 38 */ 39 40 /*- 41 * Copyright (c) 1992, 1993 42 * The Regents of the University of California. All rights reserved. 43 * 44 * This code is derived from software contributed to Berkeley by 45 * Ralph Campbell and Rick Macklem. 46 * 47 * Redistribution and use in source and binary forms, with or without 48 * modification, are permitted provided that the following conditions 49 * are met: 50 * 1. Redistributions of source code must retain the above copyright 51 * notice, this list of conditions and the following disclaimer. 52 * 2. Redistributions in binary form must reproduce the above copyright 53 * notice, this list of conditions and the following disclaimer in the 54 * documentation and/or other materials provided with the distribution. 55 * 3. All advertising materials mentioning features or use of this software 56 * must display the following acknowledgement: 57 * This product includes software developed by the University of 58 * California, Berkeley and its contributors. 59 * 4. Neither the name of the University nor the names of its contributors 60 * may be used to endorse or promote products derived from this software 61 * without specific prior written permission. 62 * 63 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 64 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 65 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 66 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 67 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 68 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 69 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 70 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 71 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 72 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 73 * SUCH DAMAGE. 74 * 75 * @(#)if_le.c 8.2 (Berkeley) 11/16/93 76 */ 77 78 #include <sys/param.h> 79 #include <sys/systm.h> 80 #include <sys/mbuf.h> 81 #include <sys/syslog.h> 82 #include <sys/socket.h> 83 #include <sys/device.h> 84 85 #include <uvm/uvm_extern.h> 86 87 #include <net/if.h> 88 #include <net/if_ether.h> 89 #include <net/if_media.h> 90 91 #include <machine/cpu.h> 92 #include <machine/intr.h> 93 #include <machine/bus.h> 94 95 #include <dev/isa/isareg.h> 96 #include <dev/isa/isavar.h> 97 #include <dev/isa/isadmavar.h> 98 99 #include <dev/ic/lancereg.h> 100 #include <dev/ic/lancevar.h> 101 #include <dev/ic/am7990reg.h> 102 #include <dev/ic/am7990var.h> 103 104 #include <dev/isa/if_levar.h> 105 106 int ne2100_isa_probe __P((struct device *, struct cfdata *, void *)); 107 int bicc_isa_probe __P((struct device *, struct cfdata *, void *)); 108 void le_dummyattach __P((struct device *, struct device *, void *)); 109 int le_dummyprobe __P((struct device *, struct cfdata *, void *)); 110 void le_ne2100_attach __P((struct device *, struct device *, void *)); 111 void le_bicc_attach __P((struct device *, struct device *, void *)); 112 113 struct cfattach nele_ca = { 114 sizeof(struct device), ne2100_isa_probe, le_dummyattach 115 }, le_nele_ca = { 116 sizeof(struct le_softc), le_dummyprobe, le_ne2100_attach 117 }, bicc_ca = { 118 sizeof(struct device), bicc_isa_probe, le_dummyattach 119 }, le_bicc_ca = { 120 sizeof(struct le_softc), le_dummyprobe, le_bicc_attach 121 }; 122 123 struct le_isa_params { 124 char *name; 125 int iosize, rap, rdp; 126 int macstart, macstride; 127 } ne2100_params = { 128 "NE2100", 129 24, NE2100_RAP, NE2100_RDP, 130 0, 1 131 }, bicc_params = { 132 "BICC Isolan", 133 16, BICC_RAP, BICC_RDP, 134 0, 2 135 }; 136 137 int lance_isa_probe __P((struct isa_attach_args *, struct le_isa_params *)); 138 void le_isa_attach __P((struct device *, struct le_softc *, 139 struct isa_attach_args *, struct le_isa_params *)); 140 141 int le_isa_intredge __P((void *)); 142 143 #if defined(_KERNEL_OPT) 144 #include "opt_ddb.h" 145 #endif 146 147 #ifdef DDB 148 #define integrate 149 #define hide 150 #else 151 #define integrate static __inline 152 #define hide static 153 #endif 154 155 hide void le_isa_wrcsr __P((struct lance_softc *, u_int16_t, u_int16_t)); 156 hide u_int16_t le_isa_rdcsr __P((struct lance_softc *, u_int16_t)); 157 158 #define LE_ISA_MEMSIZE 16384 159 160 hide void 161 le_isa_wrcsr(sc, port, val) 162 struct lance_softc *sc; 163 u_int16_t port, val; 164 { 165 struct le_softc *lesc = (struct le_softc *)sc; 166 bus_space_tag_t iot = lesc->sc_iot; 167 bus_space_handle_t ioh = lesc->sc_ioh; 168 169 bus_space_write_2(iot, ioh, lesc->sc_rap, port); 170 bus_space_write_2(iot, ioh, lesc->sc_rdp, val); 171 } 172 173 hide u_int16_t 174 le_isa_rdcsr(sc, port) 175 struct lance_softc *sc; 176 u_int16_t port; 177 { 178 struct le_softc *lesc = (struct le_softc *)sc; 179 bus_space_tag_t iot = lesc->sc_iot; 180 bus_space_handle_t ioh = lesc->sc_ioh; 181 u_int16_t val; 182 183 bus_space_write_2(iot, ioh, lesc->sc_rap, port); 184 val = bus_space_read_2(iot, ioh, lesc->sc_rdp); 185 return (val); 186 } 187 188 int 189 ne2100_isa_probe(parent, match, aux) 190 struct device *parent; 191 struct cfdata *match; 192 void *aux; 193 { 194 return (lance_isa_probe(aux, &ne2100_params)); 195 } 196 197 int 198 bicc_isa_probe(parent, match, aux) 199 struct device *parent; 200 struct cfdata *match; 201 void *aux; 202 { 203 return (lance_isa_probe(aux, &bicc_params)); 204 } 205 206 /* 207 * Determine which chip is present on the card. 208 */ 209 int 210 lance_isa_probe(ia, p) 211 struct isa_attach_args *ia; 212 struct le_isa_params *p; 213 { 214 bus_space_tag_t iot = ia->ia_iot; 215 bus_space_handle_t ioh; 216 int rap, rdp; 217 int rv = 0; 218 219 /* Disallow wildcarded i/o address. */ 220 if (ia->ia_iobase == ISACF_PORT_DEFAULT) 221 return (0); 222 223 /* Map i/o space. */ 224 if (bus_space_map(iot, ia->ia_iobase, p->iosize, 0, &ioh)) 225 return (0); 226 227 rap = p->rap; 228 rdp = p->rdp; 229 230 /* Stop the LANCE chip and put it in a known state. */ 231 bus_space_write_2(iot, ioh, rap, LE_CSR0); 232 bus_space_write_2(iot, ioh, rdp, LE_C0_STOP); 233 delay(100); 234 235 bus_space_write_2(iot, ioh, rap, LE_CSR0); 236 if (bus_space_read_2(iot, ioh, rdp) != LE_C0_STOP) 237 goto bad; 238 239 bus_space_write_2(iot, ioh, rap, LE_CSR3); 240 bus_space_write_2(iot, ioh, rdp, 0); 241 242 ia->ia_iosize = p->iosize; 243 rv = 1; 244 245 bad: 246 bus_space_unmap(iot, ioh, p->iosize); 247 return (rv); 248 } 249 250 void 251 le_dummyattach(parent, self, aux) 252 struct device *parent, *self; 253 void *aux; 254 { 255 printf("\n"); 256 257 config_found(self, aux, 0); 258 } 259 260 int 261 le_dummyprobe(parent, match, aux) 262 struct device *parent; 263 struct cfdata *match; 264 void *aux; 265 { 266 return (1); 267 } 268 269 void 270 le_ne2100_attach(parent, self, aux) 271 struct device *parent, *self; 272 void *aux; 273 { 274 le_isa_attach(parent, (void *)self, aux, &ne2100_params); 275 } 276 277 void 278 le_bicc_attach(parent, self, aux) 279 struct device *parent, *self; 280 void *aux; 281 { 282 le_isa_attach(parent, (void *)self, aux, &bicc_params); 283 } 284 285 void 286 le_isa_attach(parent, lesc, ia, p) 287 struct device *parent; 288 struct le_softc *lesc; 289 struct isa_attach_args *ia; 290 struct le_isa_params *p; 291 { 292 struct lance_softc *sc = &lesc->sc_am7990.lsc; 293 bus_space_tag_t iot = ia->ia_iot; 294 bus_space_handle_t ioh; 295 bus_dma_tag_t dmat = ia->ia_dmat; 296 bus_dma_segment_t seg; 297 int i, rseg, error; 298 299 printf(": %s Ethernet\n", p->name); 300 301 if (bus_space_map(iot, ia->ia_iobase, p->iosize, 0, &ioh)) 302 panic("%s: can't map io", sc->sc_dev.dv_xname); 303 304 /* 305 * Extract the physical MAC address from the ROM. 306 */ 307 for (i = 0; i < sizeof(sc->sc_enaddr); i++) 308 sc->sc_enaddr[i] = 309 bus_space_read_1(iot, ioh, p->macstart + i * p->macstride); 310 311 lesc->sc_iot = iot; 312 lesc->sc_ioh = ioh; 313 lesc->sc_dmat = dmat; 314 lesc->sc_rap = p->rap; 315 lesc->sc_rdp = p->rdp; 316 317 /* 318 * Allocate a DMA area for the card. 319 */ 320 if (bus_dmamem_alloc(dmat, LE_ISA_MEMSIZE, PAGE_SIZE, 0, &seg, 1, 321 &rseg, BUS_DMA_NOWAIT)) { 322 printf("%s: couldn't allocate memory for card\n", 323 sc->sc_dev.dv_xname); 324 return; 325 } 326 if (bus_dmamem_map(dmat, &seg, rseg, LE_ISA_MEMSIZE, 327 (caddr_t *)&sc->sc_mem, 328 BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) { 329 printf("%s: couldn't map memory for card\n", 330 sc->sc_dev.dv_xname); 331 return; 332 } 333 334 /* 335 * Create and load the DMA map for the DMA area. 336 */ 337 if (bus_dmamap_create(dmat, LE_ISA_MEMSIZE, 1, 338 LE_ISA_MEMSIZE, 0, BUS_DMA_NOWAIT, &lesc->sc_dmam)) { 339 printf("%s: couldn't create DMA map\n", 340 sc->sc_dev.dv_xname); 341 bus_dmamem_free(dmat, &seg, rseg); 342 return; 343 } 344 if (bus_dmamap_load(dmat, lesc->sc_dmam, 345 sc->sc_mem, LE_ISA_MEMSIZE, NULL, BUS_DMA_NOWAIT)) { 346 printf("%s: coundn't load DMA map\n", 347 sc->sc_dev.dv_xname); 348 bus_dmamem_free(dmat, &seg, rseg); 349 return; 350 } 351 352 sc->sc_conf3 = 0; 353 sc->sc_addr = lesc->sc_dmam->dm_segs[0].ds_addr; 354 sc->sc_memsize = LE_ISA_MEMSIZE; 355 356 sc->sc_copytodesc = lance_copytobuf_contig; 357 sc->sc_copyfromdesc = lance_copyfrombuf_contig; 358 sc->sc_copytobuf = lance_copytobuf_contig; 359 sc->sc_copyfrombuf = lance_copyfrombuf_contig; 360 sc->sc_zerobuf = lance_zerobuf_contig; 361 362 sc->sc_rdcsr = le_isa_rdcsr; 363 sc->sc_wrcsr = le_isa_wrcsr; 364 sc->sc_hwinit = NULL; 365 366 if (ia->ia_drq != DRQUNK) { 367 if ((error = isa_dmacascade(ia->ia_ic, ia->ia_drq)) != 0) { 368 printf("%s: unable to cascade DRQ, error = %d\n", 369 sc->sc_dev.dv_xname, error); 370 return; 371 } 372 } 373 374 lesc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE, 375 IPL_NET, le_isa_intredge, sc); 376 377 printf("%s", sc->sc_dev.dv_xname); 378 am7990_config(&lesc->sc_am7990); 379 } 380 381 /* 382 * Controller interrupt. 383 */ 384 int 385 le_isa_intredge(arg) 386 void *arg; 387 { 388 389 if (am7990_intr(arg) == 0) 390 return (0); 391 for (;;) 392 if (am7990_intr(arg) == 0) 393 return (1); 394 } 395