Annotation of sys/arch/vax/vsa/if_le_vsbus.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: if_le_vsbus.c,v 1.9 2004/07/07 23:10:46 deraadt Exp $ */
! 2: /* $NetBSD: if_le_vsbus.c,v 1.10 2000/06/29 07:14:18 mrg Exp $ */
! 3:
! 4: /*-
! 5: * Copyright (c) 1998 The NetBSD Foundation, Inc.
! 6: * All rights reserved.
! 7: *
! 8: * This code is derived from software contributed to The NetBSD Foundation
! 9: * by Charles M. Hannum.
! 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. Neither the name of the University nor the names of its contributors
! 56: * may be used to endorse or promote products derived from this software
! 57: * without specific prior written permission.
! 58: *
! 59: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
! 60: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 61: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 62: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
! 63: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 64: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 65: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 66: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 67: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 68: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 69: * SUCH DAMAGE.
! 70: *
! 71: * @(#)if_le.c 8.2 (Berkeley) 11/16/93
! 72: */
! 73:
! 74: #include "bpfilter.h"
! 75:
! 76: #include <sys/param.h>
! 77: #include <sys/syslog.h>
! 78: #include <sys/socket.h>
! 79: #include <sys/device.h>
! 80: #include <sys/reboot.h>
! 81:
! 82: #include <uvm/uvm_extern.h>
! 83:
! 84: #include <net/if.h>
! 85: #include <net/if_media.h>
! 86:
! 87: #ifdef INET
! 88: #include <netinet/in.h>
! 89: #endif
! 90: #include <netinet/if_ether.h>
! 91:
! 92: #include <machine/cpu.h>
! 93: #include <machine/sid.h>
! 94: #include <machine/scb.h>
! 95: #include <machine/rpb.h>
! 96: #include <machine/bus.h>
! 97: #include <machine/vsbus.h>
! 98:
! 99: #include <dev/ic/am7990reg.h>
! 100: #include <dev/ic/am7990var.h>
! 101:
! 102: struct le_softc {
! 103: struct am7990_softc sc_am7990; /* Must be first */
! 104: struct evcount sc_intrcnt;
! 105: bus_dmamap_t sc_dm;
! 106: volatile u_short *sc_rap;
! 107: volatile u_short *sc_rdp;
! 108: };
! 109:
! 110: static int le_vsbus_match(struct device *, struct cfdata *, void *);
! 111: static void le_vsbus_attach(struct device *, struct device *, void *);
! 112: static void lewrcsr(struct am7990_softc *, u_int16_t, u_int16_t);
! 113: static u_int16_t lerdcsr(struct am7990_softc *, u_int16_t);
! 114:
! 115: struct cfattach le_vsbus_ca = {
! 116: sizeof(struct le_softc), (cfmatch_t)le_vsbus_match, le_vsbus_attach
! 117: };
! 118:
! 119: static void
! 120: lewrcsr(ls, port, val)
! 121: struct am7990_softc *ls;
! 122: u_int16_t port, val;
! 123: {
! 124: struct le_softc *sc = (void *)ls;
! 125:
! 126: *sc->sc_rap = port;
! 127: *sc->sc_rdp = val;
! 128: }
! 129:
! 130: static u_int16_t
! 131: lerdcsr(ls, port)
! 132: struct am7990_softc *ls;
! 133: u_int16_t port;
! 134: {
! 135: struct le_softc *sc = (void *)ls;
! 136:
! 137: *sc->sc_rap = port;
! 138: return *sc->sc_rdp;
! 139: }
! 140:
! 141: static int
! 142: le_vsbus_match(parent, cf, aux)
! 143: struct device *parent;
! 144: struct cfdata *cf;
! 145: void *aux;
! 146: {
! 147: struct vsbus_attach_args *va = aux;
! 148: volatile short *rdp, *rap;
! 149: struct leinit initblock;
! 150: bus_dmamap_t map;
! 151: int i;
! 152: int rv = 0;
! 153: int error;
! 154:
! 155: if (vax_boardtype == VAX_BTYP_49 || vax_boardtype == VAX_BTYP_1303)
! 156: return 0;
! 157:
! 158: error = bus_dmamap_create(va->va_dmat, sizeof(initblock), 1,
! 159: sizeof(initblock), 0, BUS_DMA_NOWAIT, &map);
! 160: if (error) {
! 161: return 0;
! 162: }
! 163:
! 164: error = bus_dmamap_load(va->va_dmat, map, &initblock,
! 165: sizeof(initblock), NULL, BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
! 166: if (error) {
! 167: bus_dmamap_destroy(va->va_dmat, map);
! 168: return 0;
! 169: }
! 170:
! 171: memset(&initblock, 0, sizeof(initblock));
! 172:
! 173: rdp = (short *)va->va_addr;
! 174: rap = rdp + 2;
! 175:
! 176: /* Make sure the chip is stopped. */
! 177: *rap = LE_CSR0;
! 178: *rdp = LE_C0_STOP;
! 179: DELAY(100);
! 180: *rap = LE_CSR1;
! 181: *rdp = map->dm_segs->ds_addr & 0xffff;
! 182: *rap = LE_CSR2;
! 183: *rdp = (map->dm_segs->ds_addr >> 16) & 0xffff;
! 184: *rap = LE_CSR0;
! 185: *rdp = LE_C0_INIT|LE_C0_INEA;
! 186:
! 187: /* Wait for initialization to finish. */
! 188: for (i = 100; i >= 0; i--) {
! 189: DELAY(1000);
! 190: /* Should have interrupted by now */
! 191: if (*rdp & LE_C0_IDON)
! 192: rv = 1;
! 193: }
! 194: *rap = LE_CSR0;
! 195: *rdp = LE_C0_STOP;
! 196:
! 197: bus_dmamap_unload(va->va_dmat, map);
! 198: bus_dmamap_destroy(va->va_dmat, map);
! 199: return rv;
! 200: }
! 201:
! 202: static void
! 203: le_vsbus_attach(parent, self, aux)
! 204: struct device *parent, *self;
! 205: void *aux;
! 206: {
! 207: struct vsbus_attach_args *va = aux;
! 208: struct le_softc *sc = (void *)self;
! 209: bus_dma_segment_t seg;
! 210: int *lance_addr;
! 211: int i, err, rseg;
! 212: static int cvec;
! 213:
! 214: sc->sc_rdp = (short *)vax_map_physmem(NI_BASE, 1);
! 215: sc->sc_rap = sc->sc_rdp + 2;
! 216:
! 217: /*
! 218: * MD functions.
! 219: */
! 220: sc->sc_am7990.sc_rdcsr = lerdcsr;
! 221: sc->sc_am7990.sc_wrcsr = lewrcsr;
! 222: sc->sc_am7990.sc_nocarrier = NULL;
! 223:
! 224: scb_vecalloc(va->va_cvec, (void (*)(void *)) am7990_intr, sc,
! 225: SCB_ISTACK, &sc->sc_intrcnt);
! 226: cvec = va->va_cvec;
! 227: evcount_attach(&sc->sc_intrcnt, self->dv_xname,
! 228: (void *)&cvec, &evcount_intr);
! 229:
! 230: /*
! 231: * Allocate a (DMA-safe) block for all descriptors and buffers.
! 232: */
! 233:
! 234: #define ALLOCSIZ (64 * 1024)
! 235: err = bus_dmamem_alloc(va->va_dmat, ALLOCSIZ, NBPG, 0,
! 236: &seg, 1, &rseg, BUS_DMA_NOWAIT);
! 237: if (err) {
! 238: printf(": unable to alloc buffer block: err %d\n", err);
! 239: return;
! 240: }
! 241: err = bus_dmamem_map(va->va_dmat, &seg, rseg, ALLOCSIZ,
! 242: (caddr_t *)&sc->sc_am7990.sc_mem,
! 243: BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
! 244: if (err) {
! 245: printf(": unable to map buffer block: err %d\n", err);
! 246: bus_dmamem_free(va->va_dmat, &seg, rseg);
! 247: return;
! 248: }
! 249: err = bus_dmamap_create(va->va_dmat, ALLOCSIZ, rseg, ALLOCSIZ,
! 250: 0, BUS_DMA_NOWAIT, &sc->sc_dm);
! 251: if (err) {
! 252: printf(": unable to create dma map: err %d\n", err);
! 253: bus_dmamem_free(va->va_dmat, &seg, rseg);
! 254: return;
! 255: }
! 256: err = bus_dmamap_load(va->va_dmat, sc->sc_dm, sc->sc_am7990.sc_mem,
! 257: ALLOCSIZ, NULL, BUS_DMA_NOWAIT);
! 258: if (err) {
! 259: printf(": unable to load dma map: err %d\n", err);
! 260: bus_dmamap_destroy(va->va_dmat, sc->sc_dm);
! 261: bus_dmamem_free(va->va_dmat, &seg, rseg);
! 262: return;
! 263: }
! 264: printf(" buf 0x%lx-0x%lx", sc->sc_dm->dm_segs->ds_addr,
! 265: sc->sc_dm->dm_segs->ds_addr + sc->sc_dm->dm_segs->ds_len - 1);
! 266: sc->sc_am7990.sc_addr = sc->sc_dm->dm_segs->ds_addr & 0xffffff;
! 267: sc->sc_am7990.sc_memsize = sc->sc_dm->dm_segs->ds_len;
! 268:
! 269: sc->sc_am7990.sc_copytodesc = am7990_copytobuf_contig;
! 270: sc->sc_am7990.sc_copyfromdesc = am7990_copyfrombuf_contig;
! 271: sc->sc_am7990.sc_copytobuf = am7990_copytobuf_contig;
! 272: sc->sc_am7990.sc_copyfrombuf = am7990_copyfrombuf_contig;
! 273: sc->sc_am7990.sc_zerobuf = am7990_zerobuf_contig;
! 274:
! 275: #ifdef LEDEBUG
! 276: sc->sc_am7990.sc_debug = 1;
! 277: #endif
! 278: /*
! 279: * Get the ethernet address out of rom
! 280: */
! 281: lance_addr = (int *)vax_map_physmem(NI_ADDR, 1);
! 282: for (i = 0; i < 6; i++)
! 283: sc->sc_am7990.sc_arpcom.ac_enaddr[i] = (u_char)lance_addr[i];
! 284: vax_unmap_physmem((vaddr_t)lance_addr, 1);
! 285:
! 286: bcopy(self->dv_xname, sc->sc_am7990.sc_arpcom.ac_if.if_xname,
! 287: IFNAMSIZ);
! 288: /* Prettier printout */
! 289: printf("\n%s", self->dv_xname);
! 290:
! 291: am7990_config(&sc->sc_am7990);
! 292: }
CVSweb