1 /* $NetBSD: if_le.c,v 1.3 2002/10/02 05:06:54 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 1997, 1999 5 * Matthias Drochner. 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. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * 27 */ 28 29 #include "opt_inet.h" 30 31 #include <sys/param.h> 32 #include <sys/systm.h> 33 #include <sys/socket.h> 34 #include <sys/device.h> 35 36 #include <net/if.h> 37 #include <net/if_ether.h> 38 #include <net/if_media.h> 39 40 #ifdef INET 41 #include <netinet/in.h> 42 #include <netinet/if_inarp.h> 43 #endif 44 45 #include <machine/cpu.h> 46 #include <machine/pte.h> 47 48 #include <machine/autoconf.h> 49 50 #include <dev/ic/lancereg.h> 51 #include <dev/ic/lancevar.h> 52 #include <dev/ic/am79900reg.h> 53 #include <dev/ic/am79900var.h> 54 55 #include <cesfic/cesfic/isr.h> 56 57 int lematch __P((struct device *, struct cfdata *, void *)); 58 void leattach __P((struct device *, struct device *, void *)); 59 60 CFATTACH_DECL(le, sizeof(struct am79900_softc), 61 lematch, leattach, NULL, NULL); 62 63 int leintr __P((void *)); 64 65 void lewrcsr __P((struct lance_softc *, u_int16_t, u_int16_t)); 66 u_int16_t lerdcsr __P((struct lance_softc *, u_int16_t)); 67 68 static char *lebase, *lemembase; 69 70 void 71 lewrcsr(sc, port, val) 72 struct lance_softc *sc; 73 u_int16_t port, val; 74 { 75 *(volatile int *)(lebase + 4) = port; 76 *(volatile int *)(lebase + 0) = val; 77 } 78 79 u_int16_t 80 lerdcsr(sc, port) 81 struct lance_softc *sc; 82 u_int16_t port; 83 { 84 u_int16_t val; 85 86 *(volatile int *)(lebase + 4) = port; 87 val = *(volatile int *)(lebase + 0); 88 return (val); 89 } 90 91 int 92 lematch(parent, match, aux) 93 struct device *parent; 94 struct cfdata *match; 95 void *aux; 96 { 97 return (1); 98 } 99 100 /* 101 * Interface exists: make available by filling in network interface 102 * record. System will initialize the interface when it is ready 103 * to accept packets. 104 */ 105 extern void sic_enable_int __P((int, int, int, int, int)); 106 static char hwa[6] = {0x00,0x80,0xa2,0x00,0x30,0x23}; 107 void 108 leattach(parent, self, aux) 109 struct device *parent, *self; 110 void *aux; 111 { 112 int i; 113 struct lance_softc *sc = (struct lance_softc *)self; 114 115 mainbus_map(0x4c000000, 0x10000, 0, (void **)&lemembase); 116 mainbus_map(0x48000000, 0x1000, 0, (void **)&lebase); 117 118 sc->sc_mem = lemembase; 119 sc->sc_conf3 = LE_C3_BSWP; 120 sc->sc_addr = 0x4c000000; 121 sc->sc_memsize = 64 * 1024; 122 123 if (cesfic_getetheraddr(sc->sc_enaddr)) { 124 /* fallback */ 125 for (i = 0; i < sizeof(sc->sc_enaddr); i++) { 126 sc->sc_enaddr[i] = hwa[i]; 127 } 128 } 129 130 sc->sc_copytodesc = lance_copytobuf_contig; 131 sc->sc_copyfromdesc = lance_copyfrombuf_contig; 132 sc->sc_copytobuf = lance_copytobuf_contig; 133 sc->sc_copyfrombuf = lance_copyfrombuf_contig; 134 sc->sc_zerobuf = lance_zerobuf_contig; 135 136 sc->sc_rdcsr = lerdcsr; 137 sc->sc_wrcsr = lewrcsr; 138 sc->sc_hwinit = NULL; 139 140 lewrcsr(sc, 4, 0x44); 141 am79900_config((struct am79900_softc *)sc); 142 143 /* Establish the interrupt handler. */ 144 (void) isrlink(leintr, sc, 3, ISRPRI_NET); 145 sic_enable_int(17, 0, 1, 3, 0); 146 } 147 148 int 149 leintr(arg) 150 void *arg; 151 { 152 struct lance_softc *sc = arg; 153 u_int16_t isr4; 154 155 isr4 = lerdcsr(sc, 4); 156 if (isr4 & 0x08) { 157 lewrcsr(sc, 4, isr4); 158 return (1); 159 } 160 161 return (am79900_intr(sc)); 162 } 163