1 /* $NetBSD: if_le.c,v 1.21 2001/11/28 05:22:48 lukem Exp $ */ 2 3 /*- 4 * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace 9 * Simulation Facility, NASA Ames Research Center. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by the NetBSD 22 * Foundation, Inc. and its contributors. 23 * 4. Neither the name of The NetBSD Foundation nor the names of its 24 * contributors may be used to endorse or promote products derived 25 * from this software without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 * POSSIBILITY OF SUCH DAMAGE. 38 */ 39 40 /*- 41 * Copyright (c) 1992, 1993 42 * The Regents of the University of California. All rights reserved. 43 * 44 * This code is derived from software contributed to Berkeley by 45 * Ralph Campbell and Rick Macklem. 46 * 47 * Redistribution and use in source and binary forms, with or without 48 * modification, are permitted provided that the following conditions 49 * are met: 50 * 1. Redistributions of source code must retain the above copyright 51 * notice, this list of conditions and the following disclaimer. 52 * 2. Redistributions in binary form must reproduce the above copyright 53 * notice, this list of conditions and the following disclaimer in the 54 * documentation and/or other materials provided with the distribution. 55 * 3. All advertising materials mentioning features or use of this software 56 * must display the following acknowledgement: 57 * This product includes software developed by the University of 58 * California, Berkeley and its contributors. 59 * 4. Neither the name of the University nor the names of its contributors 60 * may be used to endorse or promote products derived from this software 61 * without specific prior written permission. 62 * 63 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 64 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 65 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 66 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 67 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 68 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 69 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 70 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 71 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 72 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 73 * SUCH DAMAGE. 74 * 75 * @(#)if_le.c 8.2 (Berkeley) 11/16/93 76 */ 77 78 #include "opt_inet.h" 79 #include "bpfilter.h" 80 81 #include <sys/param.h> 82 #include <sys/syslog.h> 83 #include <sys/socket.h> 84 #include <sys/device.h> 85 #include <sys/reboot.h> 86 87 #include <uvm/uvm_extern.h> 88 89 #include <net/if.h> 90 #include <net/if_ether.h> 91 #include <net/if_media.h> 92 93 #ifdef INET 94 #include <netinet/in.h> 95 #include <netinet/if_inarp.h> 96 #endif 97 98 #include <machine/cpu.h> 99 #include <machine/nexus.h> 100 #include <machine/scb.h> 101 102 #include <dev/ic/lancereg.h> 103 #include <dev/ic/lancevar.h> 104 #include <dev/ic/am7990reg.h> 105 #include <dev/ic/am7990var.h> 106 107 #include "ioconf.h" 108 109 #define LEVEC 0xd4 /* Interrupt vector on 3300/3400 */ 110 111 struct le_softc { 112 struct am7990_softc sc_am7990; /* Must be first */ 113 struct evcnt sc_intrcnt; 114 volatile u_short *sc_rap; 115 volatile u_short *sc_rdp; 116 }; 117 118 int le_ibus_match __P((struct device *, struct cfdata *, void *)); 119 void le_ibus_attach __P((struct device *, struct device *, void *)); 120 void lewrcsr __P((struct lance_softc *, u_int16_t, u_int16_t)); 121 u_int16_t lerdcsr __P((struct lance_softc *, u_int16_t)); 122 void lance_copytobuf_gap2 __P((struct lance_softc *, void *, int, int)); 123 void lance_copyfrombuf_gap2 __P((struct lance_softc *, void *, int, int)); 124 void lance_zerobuf_gap2 __P((struct lance_softc *, int, int)); 125 126 struct cfattach le_ibus_ca = { 127 sizeof(struct le_softc), le_ibus_match, le_ibus_attach 128 }; 129 130 void 131 lewrcsr(ls, port, val) 132 struct lance_softc *ls; 133 u_int16_t port, val; 134 { 135 struct le_softc *sc = (void *)ls; 136 137 *sc->sc_rap = port; 138 *sc->sc_rdp = val; 139 } 140 141 u_int16_t 142 lerdcsr(ls, port) 143 struct lance_softc *ls; 144 u_int16_t port; 145 { 146 struct le_softc *sc = (void *)ls; 147 148 *sc->sc_rap = port; 149 return *sc->sc_rdp; 150 } 151 152 int 153 le_ibus_match(parent, cf, aux) 154 struct device *parent; 155 struct cfdata *cf; 156 void *aux; 157 { 158 struct bp_conf *bp = aux; 159 160 if (strcmp("lance", bp->type)) 161 return 0; 162 return 1; 163 } 164 165 void 166 le_ibus_attach(parent, self, aux) 167 struct device *parent, *self; 168 void *aux; 169 { 170 struct le_softc *sc = (void *)self; 171 int *lance_addr; 172 int i, vec, br; 173 174 sc->sc_rdp = (short *)vax_map_physmem(0x20084400, 1); 175 sc->sc_rap = sc->sc_rdp + 2; 176 177 /* 178 * Set interrupt vector, by forcing an interrupt. 179 */ 180 scb_vecref(0, 0); /* Clear vector ref */ 181 *sc->sc_rap = LE_CSR0; 182 *sc->sc_rdp = LE_C0_STOP; 183 DELAY(100); 184 *sc->sc_rdp = LE_C0_INIT|LE_C0_INEA; 185 DELAY(100000); 186 i = scb_vecref(&vec, &br); 187 if (i == 0 || vec == 0) 188 return; 189 scb_vecalloc(vec, (void (*)(void *))am7990_intr, sc, 190 SCB_ISTACK, &sc->sc_intrcnt); 191 evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL, 192 self->dv_xname, "intr"); 193 194 printf(": vec %o ipl %x\n%s", vec, br, self->dv_xname); 195 /* 196 * MD functions. 197 */ 198 sc->sc_am7990.lsc.sc_rdcsr = lerdcsr; 199 sc->sc_am7990.lsc.sc_wrcsr = lewrcsr; 200 sc->sc_am7990.lsc.sc_nocarrier = NULL; 201 202 sc->sc_am7990.lsc.sc_mem = 203 (void *)uvm_km_valloc(kernel_map, (128 * 1024)); 204 if (sc->sc_am7990.lsc.sc_mem == 0) 205 return; 206 207 ioaccess((vaddr_t)sc->sc_am7990.lsc.sc_mem, 0x20120000, 208 (128 * 1024) >> VAX_PGSHIFT); 209 210 211 sc->sc_am7990.lsc.sc_addr = 0; 212 sc->sc_am7990.lsc.sc_memsize = (64 * 1024); 213 214 sc->sc_am7990.lsc.sc_copytodesc = lance_copytobuf_gap2; 215 sc->sc_am7990.lsc.sc_copyfromdesc = lance_copyfrombuf_gap2; 216 sc->sc_am7990.lsc.sc_copytobuf = lance_copytobuf_gap2; 217 sc->sc_am7990.lsc.sc_copyfrombuf = lance_copyfrombuf_gap2; 218 sc->sc_am7990.lsc.sc_zerobuf = lance_zerobuf_gap2; 219 220 /* 221 * Get the ethernet address out of rom 222 */ 223 lance_addr = (int *)vax_map_physmem(0x20084200, 1); 224 for (i = 0; i < 6; i++) 225 sc->sc_am7990.lsc.sc_enaddr[i] = (u_char)lance_addr[i]; 226 vax_unmap_physmem((vaddr_t)lance_addr, 1); 227 228 bcopy(self->dv_xname, sc->sc_am7990.lsc.sc_ethercom.ec_if.if_xname, 229 IFNAMSIZ); 230 am7990_config(&sc->sc_am7990); 231 } 232 233 /* 234 * gap2: two bytes of data followed by two bytes of pad. 235 * 236 * Buffers must be 4-byte aligned. The code doesn't worry about 237 * doing an extra byte. 238 */ 239 240 void 241 lance_copytobuf_gap2(sc, fromv, boff, len) 242 struct lance_softc *sc; 243 void *fromv; 244 int boff; 245 register int len; 246 { 247 volatile caddr_t buf = sc->sc_mem; 248 register caddr_t from = fromv; 249 register volatile u_int16_t *bptr; 250 251 if (boff & 0x1) { 252 /* handle unaligned first byte */ 253 bptr = ((volatile u_int16_t *)buf) + (boff - 1); 254 *bptr = (*from++ << 8) | (*bptr & 0xff); 255 bptr += 2; 256 len--; 257 } else 258 bptr = ((volatile u_int16_t *)buf) + boff; 259 while (len > 1) { 260 *bptr = (from[1] << 8) | (from[0] & 0xff); 261 bptr += 2; 262 from += 2; 263 len -= 2; 264 } 265 if (len == 1) 266 *bptr = (u_int16_t)*from; 267 } 268 269 void 270 lance_copyfrombuf_gap2(sc, tov, boff, len) 271 struct lance_softc *sc; 272 void *tov; 273 int boff, len; 274 { 275 volatile caddr_t buf = sc->sc_mem; 276 register caddr_t to = tov; 277 register volatile u_int16_t *bptr; 278 register u_int16_t tmp; 279 280 if (boff & 0x1) { 281 /* handle unaligned first byte */ 282 bptr = ((volatile u_int16_t *)buf) + (boff - 1); 283 *to++ = (*bptr >> 8) & 0xff; 284 bptr += 2; 285 len--; 286 } else 287 bptr = ((volatile u_int16_t *)buf) + boff; 288 while (len > 1) { 289 tmp = *bptr; 290 *to++ = tmp & 0xff; 291 *to++ = (tmp >> 8) & 0xff; 292 bptr += 2; 293 len -= 2; 294 } 295 if (len == 1) 296 *to = *bptr & 0xff; 297 } 298 299 void 300 lance_zerobuf_gap2(sc, boff, len) 301 struct lance_softc *sc; 302 int boff, len; 303 { 304 volatile caddr_t buf = sc->sc_mem; 305 register volatile u_int16_t *bptr; 306 307 if ((unsigned)boff & 0x1) { 308 bptr = ((volatile u_int16_t *)buf) + (boff - 1); 309 *bptr &= 0xff; 310 bptr += 2; 311 len--; 312 } else 313 bptr = ((volatile u_int16_t *)buf) + boff; 314 while (len > 0) { 315 *bptr = 0; 316 bptr += 2; 317 len -= 2; 318 } 319 } 320