1 /* $NetBSD: if_le.c,v 1.37 1997/03/17 03:17:39 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 1996 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Adam Glass and Gordon W. Ross. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 #include "bpfilter.h" 40 41 #include <sys/param.h> 42 #include <sys/systm.h> 43 #include <sys/mbuf.h> 44 #include <sys/syslog.h> 45 #include <sys/socket.h> 46 #include <sys/device.h> 47 48 #include <net/if.h> 49 #include <net/if_ether.h> 50 #include <net/if_media.h> 51 52 #ifdef INET 53 #include <netinet/in.h> 54 #include <netinet/if_inarp.h> 55 #endif 56 57 #include <machine/autoconf.h> 58 #include <machine/cpu.h> 59 #include <machine/dvma.h> 60 #include <machine/obio.h> 61 #include <machine/idprom.h> 62 63 #include <dev/ic/am7990reg.h> 64 #include <dev/ic/am7990var.h> 65 66 /* 67 * LANCE registers. 68 * The real stuff is in dev/ic/am7990reg.h 69 */ 70 struct lereg1 { 71 volatile u_int16_t ler1_rdp; /* data port */ 72 volatile u_int16_t ler1_rap; /* register select port */ 73 }; 74 75 /* 76 * Ethernet software status per interface. 77 * The real stuff is in dev/ic/am7990var.h 78 */ 79 struct le_softc { 80 struct am7990_softc sc_am7990; /* glue to MI code */ 81 82 struct lereg1 *sc_r1; /* LANCE registers */ 83 }; 84 85 static int le_match __P((struct device *, struct cfdata *, void *)); 86 static void le_attach __P((struct device *, struct device *, void *)); 87 88 struct cfattach le_ca = { 89 sizeof(struct le_softc), le_match, le_attach 90 }; 91 92 hide void lewrcsr __P((struct am7990_softc *, u_int16_t, u_int16_t)); 93 hide u_int16_t lerdcsr __P((struct am7990_softc *, u_int16_t)); 94 95 hide void 96 lewrcsr(sc, port, val) 97 struct am7990_softc *sc; 98 u_int16_t port, val; 99 { 100 register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1; 101 102 ler1->ler1_rap = port; 103 ler1->ler1_rdp = val; 104 } 105 106 hide u_int16_t 107 lerdcsr(sc, port) 108 struct am7990_softc *sc; 109 u_int16_t port; 110 { 111 register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1; 112 u_int16_t val; 113 114 ler1->ler1_rap = port; 115 val = ler1->ler1_rdp; 116 return (val); 117 } 118 119 int 120 le_match(parent, cf, aux) 121 struct device *parent; 122 struct cfdata *cf; 123 void *aux; 124 { 125 struct confargs *ca = aux; 126 127 /* Make sure there is something there... */ 128 if (bus_peek(ca->ca_bustype, ca->ca_paddr, 1) == -1) 129 return (0); 130 131 /* Default interrupt priority. */ 132 if (ca->ca_intpri == -1) 133 ca->ca_intpri = 3; 134 135 return (1); 136 } 137 138 void 139 le_attach(parent, self, aux) 140 struct device *parent, *self; 141 void *aux; 142 { 143 struct le_softc *lesc = (struct le_softc *)self; 144 struct am7990_softc *sc = &lesc->sc_am7990; 145 struct confargs *ca = aux; 146 147 lesc->sc_r1 = (struct lereg1 *) 148 obio_alloc(ca->ca_paddr, sizeof(struct lereg1)); 149 150 sc->sc_memsize = 0x4000; /* 16K */ 151 sc->sc_mem = dvma_malloc(sc->sc_memsize); 152 sc->sc_addr = (u_long)sc->sc_mem & 0xffffff; 153 sc->sc_conf3 = LE_C3_BSWP; 154 155 idprom_etheraddr(sc->sc_enaddr); 156 157 sc->sc_copytodesc = am7990_copytobuf_contig; 158 sc->sc_copyfromdesc = am7990_copyfrombuf_contig; 159 sc->sc_copytobuf = am7990_copytobuf_contig; 160 sc->sc_copyfrombuf = am7990_copyfrombuf_contig; 161 sc->sc_zerobuf = am7990_zerobuf_contig; 162 163 sc->sc_rdcsr = lerdcsr; 164 sc->sc_wrcsr = lewrcsr; 165 sc->sc_hwinit = NULL; 166 167 am7990_config(sc); 168 169 /* Install interrupt handler. */ 170 isr_add_autovect(am7990_intr, (void *)sc, ca->ca_intpri); 171 } 172