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