1 /* $NetBSD: if_le.c,v 1.5 2003/09/28 22:00:26 cl 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 <sys/cdefs.h> 30 __KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.5 2003/09/28 22:00:26 cl Exp $"); 31 32 #include "opt_inet.h" 33 34 #include <sys/param.h> 35 #include <sys/systm.h> 36 #include <sys/socket.h> 37 #include <sys/device.h> 38 39 #include <net/if.h> 40 #include <net/if_ether.h> 41 #include <net/if_media.h> 42 43 #ifdef INET 44 #include <netinet/in.h> 45 #include <netinet/if_inarp.h> 46 #endif 47 48 #include <machine/cpu.h> 49 #include <machine/pte.h> 50 51 #include <machine/autoconf.h> 52 53 #include <dev/ic/lancereg.h> 54 #include <dev/ic/lancevar.h> 55 #include <dev/ic/am79900reg.h> 56 #include <dev/ic/am79900var.h> 57 58 #include <cesfic/cesfic/isr.h> 59 60 int lematch __P((struct device *, struct cfdata *, void *)); 61 void leattach __P((struct device *, struct device *, void *)); 62 63 CFATTACH_DECL(le, sizeof(struct am79900_softc), 64 lematch, leattach, NULL, NULL); 65 66 int leintr __P((void *)); 67 68 void lewrcsr __P((struct lance_softc *, u_int16_t, u_int16_t)); 69 u_int16_t lerdcsr __P((struct lance_softc *, u_int16_t)); 70 71 static char *lebase, *lemembase; 72 73 void 74 lewrcsr(sc, port, val) 75 struct lance_softc *sc; 76 u_int16_t port, val; 77 { 78 *(volatile int *)(lebase + 4) = port; 79 *(volatile int *)(lebase + 0) = val; 80 } 81 82 u_int16_t 83 lerdcsr(sc, port) 84 struct lance_softc *sc; 85 u_int16_t port; 86 { 87 u_int16_t val; 88 89 *(volatile int *)(lebase + 4) = port; 90 val = *(volatile int *)(lebase + 0); 91 return (val); 92 } 93 94 int 95 lematch(parent, match, aux) 96 struct device *parent; 97 struct cfdata *match; 98 void *aux; 99 { 100 return (1); 101 } 102 103 /* 104 * Interface exists: make available by filling in network interface 105 * record. System will initialize the interface when it is ready 106 * to accept packets. 107 */ 108 extern void sic_enable_int __P((int, int, int, int, int)); 109 static char hwa[6] = {0x00,0x80,0xa2,0x00,0x30,0x23}; 110 void 111 leattach(parent, self, aux) 112 struct device *parent, *self; 113 void *aux; 114 { 115 int i; 116 struct lance_softc *sc = (struct lance_softc *)self; 117 118 mainbus_map(0x4c000000, 0x10000, 0, (void *)&lemembase); 119 mainbus_map(0x48000000, 0x1000, 0, (void *)&lebase); 120 121 sc->sc_mem = lemembase; 122 sc->sc_conf3 = LE_C3_BSWP; 123 sc->sc_addr = 0x4c000000; 124 sc->sc_memsize = 64 * 1024; 125 126 if (cesfic_getetheraddr(sc->sc_enaddr)) { 127 /* fallback */ 128 for (i = 0; i < sizeof(sc->sc_enaddr); i++) { 129 sc->sc_enaddr[i] = hwa[i]; 130 } 131 } 132 133 sc->sc_copytodesc = lance_copytobuf_contig; 134 sc->sc_copyfromdesc = lance_copyfrombuf_contig; 135 sc->sc_copytobuf = lance_copytobuf_contig; 136 sc->sc_copyfrombuf = lance_copyfrombuf_contig; 137 sc->sc_zerobuf = lance_zerobuf_contig; 138 139 sc->sc_rdcsr = lerdcsr; 140 sc->sc_wrcsr = lewrcsr; 141 sc->sc_hwinit = NULL; 142 143 lewrcsr(sc, 4, 0x44); 144 am79900_config((struct am79900_softc *)sc); 145 146 /* Establish the interrupt handler. */ 147 (void) isrlink(leintr, sc, 3, ISRPRI_NET); 148 sic_enable_int(17, 0, 1, 3, 0); 149 } 150 151 int 152 leintr(arg) 153 void *arg; 154 { 155 struct lance_softc *sc = arg; 156 u_int16_t isr4; 157 158 isr4 = lerdcsr(sc, 4); 159 if (isr4 & 0x08) { 160 lewrcsr(sc, 4, isr4); 161 return (1); 162 } 163 164 return (am79900_intr(sc)); 165 } 166