1 /* $NetBSD: if_le.c,v 1.12 2003/07/15 02:59:29 lukem 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 <sys/cdefs.h> 40 __KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.12 2003/07/15 02:59:29 lukem Exp $"); 41 42 #include "opt_inet.h" 43 #include "bpfilter.h" 44 45 #include <sys/param.h> 46 #include <sys/systm.h> 47 #include <sys/mbuf.h> 48 #include <sys/syslog.h> 49 #include <sys/socket.h> 50 #include <sys/device.h> 51 52 #include <net/if.h> 53 #include <net/if_ether.h> 54 #include <net/if_media.h> 55 56 #ifdef INET 57 #include <netinet/in.h> 58 #include <netinet/if_inarp.h> 59 #endif 60 61 #include <machine/cpu.h> 62 #include <machine/adrsmap.h> 63 64 #include <dev/ic/lancereg.h> 65 #include <dev/ic/lancevar.h> 66 #include <dev/ic/am7990reg.h> 67 #include <dev/ic/am7990var.h> 68 69 #include <newsmips/dev/hbvar.h> 70 71 /* 72 * LANCE registers. 73 * The real stuff is in dev/ic/am7990reg.h 74 */ 75 struct lereg1 { 76 volatile u_int16_t ler1_rdp; /* data port */ 77 volatile u_int16_t ler1_rap; /* register select port */ 78 }; 79 80 /* 81 * Ethernet software status per interface. 82 * The real stuff is in dev/ic/am7990var.h 83 */ 84 struct le_softc { 85 struct am7990_softc sc_am7990; /* glue to MI code */ 86 87 struct lereg1 *sc_r1; /* LANCE registers */ 88 }; 89 90 static int le_match __P((struct device *, struct cfdata *, void *)); 91 static void le_attach __P((struct device *, struct device *, void *)); 92 93 CFATTACH_DECL(le, sizeof(struct le_softc), 94 le_match, le_attach, NULL, NULL); 95 96 #if defined(_KERNEL_OPT) 97 #include "opt_ddb.h" 98 #endif 99 100 #ifdef DDB 101 #define integrate 102 #define hide 103 #else 104 #define integrate static __inline 105 #define hide static 106 #endif 107 108 hide void lewrcsr __P((struct lance_softc *, u_int16_t, u_int16_t)); 109 hide u_int16_t lerdcsr __P((struct lance_softc *, u_int16_t)); 110 111 hide void 112 lewrcsr(sc, port, val) 113 struct lance_softc *sc; 114 u_int16_t port, val; 115 { 116 register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1; 117 118 ler1->ler1_rap = port; 119 ler1->ler1_rdp = val; 120 } 121 122 hide u_int16_t 123 lerdcsr(sc, port) 124 struct lance_softc *sc; 125 u_int16_t port; 126 { 127 register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1; 128 u_int16_t val; 129 130 ler1->ler1_rap = port; 131 val = ler1->ler1_rdp; 132 return (val); 133 } 134 135 int 136 le_match(parent, cf, aux) 137 struct device *parent; 138 struct cfdata *cf; 139 void *aux; 140 { 141 struct hb_attach_args *ha = aux; 142 143 if (strcmp(ha->ha_name, "le")) 144 return 0; 145 146 if (hb_badaddr((void *)ha->ha_addr, 1)) /* XXX */ 147 return 0; 148 149 return 1; 150 } 151 152 void 153 le_attach(parent, self, aux) 154 struct device *parent, *self; 155 void *aux; 156 { 157 struct le_softc *lesc = (struct le_softc *)self; 158 struct lance_softc *sc = &lesc->sc_am7990.lsc; 159 struct hb_attach_args *ha = aux; 160 int intlevel, intmask; 161 u_char *p; 162 163 intlevel = ha->ha_level; 164 if (intlevel == -1) { 165 printf(": interrupt level not configured\n"); 166 return; 167 } 168 printf(" level %d", intlevel); 169 170 switch (ha->ha_addr) { 171 172 case LANCE_PORT: 173 sc->sc_mem = (void *)LANCE_MEMORY; 174 p = (u_char *)(ETHER_ID+16); 175 intmask = INTST1_LANCE; 176 break; 177 case LANCE_PORT1: 178 sc->sc_mem = (void *)LANCE_MEMORY1; 179 p = (u_char *)(ETHER_ID1+16); 180 intmask = INTST1_SLOT3; /* XXX not tested */ 181 break; 182 case LANCE_PORT2: 183 sc->sc_mem = (void *)LANCE_MEMORY2; 184 p = (u_char *)(ETHER_ID2+16); 185 intmask = INTST1_SLOT3; /* XXX not tested */ 186 break; 187 188 default: 189 printf(": unknown LANCE addr\n"); 190 return; 191 } 192 193 lesc->sc_r1 = (void *)ha->ha_addr; 194 195 sc->sc_memsize = 0x4000; /* 16K */ 196 sc->sc_addr = (int)sc->sc_mem & 0x00ffffff; 197 sc->sc_conf3 = LE_C3_BSWP|LE_C3_BCON; 198 199 sc->sc_enaddr[0] = (*p++ << 4); 200 sc->sc_enaddr[0] |= *p++ & 0x0f; 201 sc->sc_enaddr[1] = (*p++ << 4); 202 sc->sc_enaddr[1] |= *p++ & 0x0f; 203 sc->sc_enaddr[2] = (*p++ << 4); 204 sc->sc_enaddr[2] |= *p++ & 0x0f; 205 sc->sc_enaddr[3] = (*p++ << 4); 206 sc->sc_enaddr[3] |= *p++ & 0x0f; 207 sc->sc_enaddr[4] = (*p++ << 4); 208 sc->sc_enaddr[4] |= *p++ & 0x0f; 209 sc->sc_enaddr[5] = (*p++ << 4); 210 sc->sc_enaddr[5] |= *p++ & 0x0f; 211 212 sc->sc_copytodesc = lance_copytobuf_contig; 213 sc->sc_copyfromdesc = lance_copyfrombuf_contig; 214 sc->sc_copytobuf = lance_copytobuf_contig; 215 sc->sc_copyfrombuf = lance_copyfrombuf_contig; 216 sc->sc_zerobuf = lance_zerobuf_contig; 217 218 sc->sc_rdcsr = lerdcsr; 219 sc->sc_wrcsr = lewrcsr; 220 sc->sc_hwinit = NULL; 221 222 am7990_config(&lesc->sc_am7990); 223 hb_intr_establish(intlevel, intmask, IPL_NET, am7990_intr, sc); 224 } 225