Annotation of sys/dev/sbus/if_le_lebuffer.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: if_le_lebuffer.c,v 1.8 2007/05/31 17:23:14 sobrado Exp $ */
! 2: /* $NetBSD: if_le_lebuffer.c,v 1.10 2002/03/11 16:00:56 pk Exp $ */
! 3:
! 4: /*-
! 5: * Copyright (c) 1997, 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; Jason R. Thorpe of the Numerical Aerospace
! 10: * Simulation Facility, NASA Ames Research Center; Paul Kranenburg.
! 11: *
! 12: * Redistribution and use in source and binary forms, with or without
! 13: * modification, are permitted provided that the following conditions
! 14: * are met:
! 15: * 1. Redistributions of source code must retain the above copyright
! 16: * notice, this list of conditions and the following disclaimer.
! 17: * 2. Redistributions in binary form must reproduce the above copyright
! 18: * notice, this list of conditions and the following disclaimer in the
! 19: * documentation and/or other materials provided with the distribution.
! 20: * 3. All advertising materials mentioning features or use of this software
! 21: * must display the following acknowledgement:
! 22: * This product includes software developed by the NetBSD
! 23: * Foundation, Inc. and its contributors.
! 24: * 4. Neither the name of The NetBSD Foundation nor the names of its
! 25: * contributors may be used to endorse or promote products derived
! 26: * from this software without specific prior written permission.
! 27: *
! 28: * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
! 29: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
! 30: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
! 31: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
! 32: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
! 33: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
! 34: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
! 35: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
! 36: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
! 37: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
! 38: * POSSIBILITY OF SUCH DAMAGE.
! 39: */
! 40:
! 41: #include "bpfilter.h"
! 42:
! 43: #include <sys/cdefs.h>
! 44: #include <sys/param.h>
! 45: #include <sys/systm.h>
! 46: #include <sys/mbuf.h>
! 47: #include <sys/syslog.h>
! 48: #include <sys/socket.h>
! 49: #include <sys/device.h>
! 50: #include <sys/malloc.h>
! 51:
! 52: #include <net/if.h>
! 53: #include <net/if_media.h>
! 54:
! 55: #ifdef INET
! 56: #include <netinet/in.h>
! 57: #include <netinet/if_ether.h>
! 58: #endif
! 59:
! 60: #include <machine/bus.h>
! 61: #include <machine/intr.h>
! 62: #include <machine/autoconf.h>
! 63:
! 64: #include <dev/sbus/sbusvar.h>
! 65: #include <dev/sbus/lebuffervar.h>
! 66:
! 67: #include <dev/ic/am7990reg.h>
! 68: #include <dev/ic/am7990var.h>
! 69:
! 70: /*
! 71: * LANCE registers.
! 72: */
! 73: #define LEREG1_RDP 0 /* Register Data port */
! 74: #define LEREG1_RAP 2 /* Register Address port */
! 75:
! 76: struct le_softc {
! 77: struct am7990_softc sc_am7990; /* glue to MI code */
! 78: bus_space_tag_t sc_bustag;
! 79: bus_dma_tag_t sc_dmatag;
! 80: bus_space_handle_t sc_reg; /* LANCE registers */
! 81: };
! 82:
! 83:
! 84: int lematch_lebuffer(struct device *, void *, void *);
! 85: void leattach_lebuffer(struct device *, struct device *, void *);
! 86:
! 87: struct cfattach le_lebuffer_ca = {
! 88: sizeof(struct le_softc), lematch_lebuffer, leattach_lebuffer
! 89: };
! 90:
! 91: extern struct cfdriver le_cd;
! 92:
! 93: struct cfdriver lebuffer_cd = {
! 94: NULL, "lebuffer", DV_DULL
! 95: };
! 96:
! 97: void le_lebuffer_wrcsr(struct am7990_softc *, u_int16_t, u_int16_t);
! 98: u_int16_t le_lebuffer_rdcsr(struct am7990_softc *, u_int16_t);
! 99:
! 100: void
! 101: le_lebuffer_wrcsr(struct am7990_softc *sc, u_int16_t port, u_int16_t val)
! 102: {
! 103: struct le_softc *lesc = (struct le_softc *)sc;
! 104:
! 105: bus_space_write_2(lesc->sc_bustag, lesc->sc_reg, LEREG1_RAP, port);
! 106: bus_space_barrier(lesc->sc_bustag, lesc->sc_reg, LEREG1_RAP, 2,
! 107: BUS_SPACE_BARRIER_WRITE);
! 108: bus_space_write_2(lesc->sc_bustag, lesc->sc_reg, LEREG1_RDP, val);
! 109: bus_space_barrier(lesc->sc_bustag, lesc->sc_reg, LEREG1_RDP, 2,
! 110: BUS_SPACE_BARRIER_WRITE);
! 111:
! 112: #if defined(SUN4M)
! 113: /*
! 114: * We need to flush the SBus->MBus write buffers. This can most
! 115: * easily be accomplished by reading back the register that we
! 116: * just wrote (thanks to Chris Torek for this solution).
! 117: */
! 118: if (CPU_ISSUN4M) {
! 119: volatile u_int16_t discard;
! 120: discard = bus_space_read_2(lesc->sc_bustag, lesc->sc_reg,
! 121: LEREG1_RDP);
! 122: }
! 123: #endif
! 124: }
! 125:
! 126: u_int16_t
! 127: le_lebuffer_rdcsr(struct am7990_softc *sc, u_int16_t port)
! 128: {
! 129: struct le_softc *lesc = (struct le_softc *)sc;
! 130:
! 131: bus_space_write_2(lesc->sc_bustag, lesc->sc_reg, LEREG1_RAP, port);
! 132: bus_space_barrier(lesc->sc_bustag, lesc->sc_reg, LEREG1_RAP, 2,
! 133: BUS_SPACE_BARRIER_WRITE);
! 134: return (bus_space_read_2(lesc->sc_bustag, lesc->sc_reg, LEREG1_RDP));
! 135: }
! 136:
! 137: int
! 138: lematch_lebuffer(struct device *parent, void *vcf, void *aux)
! 139: {
! 140: struct sbus_attach_args *sa = aux;
! 141: struct cfdata *cf = vcf;
! 142:
! 143: return (strcmp(cf->cf_driver->cd_name, sa->sa_name) == 0);
! 144: }
! 145:
! 146:
! 147: void
! 148: leattach_lebuffer(struct device *parent, struct device *self, void *aux)
! 149: {
! 150: struct sbus_attach_args *sa = aux;
! 151: struct le_softc *lesc = (struct le_softc *)self;
! 152: struct am7990_softc *sc = &lesc->sc_am7990;
! 153: struct lebuf_softc *lebuf = (struct lebuf_softc *)parent;
! 154: /* XXX the following declarations should be elsewhere */
! 155: extern void myetheraddr(u_char *);
! 156:
! 157: lesc->sc_bustag = sa->sa_bustag;
! 158: lesc->sc_dmatag = sa->sa_dmatag;
! 159:
! 160: if (sbus_bus_map(sa->sa_bustag,
! 161: sa->sa_slot, sa->sa_offset, sa->sa_size,
! 162: 0, 0, &lesc->sc_reg)) {
! 163: printf(": cannot map registers\n");
! 164: return;
! 165: }
! 166:
! 167: sc->sc_mem = lebuf->sc_buffer;
! 168: sc->sc_memsize = lebuf->sc_bufsiz;
! 169: sc->sc_addr = 0; /* Lance view is offset by buffer location */
! 170: lebuf->attached = 1;
! 171:
! 172: /* That old black magic... */
! 173: sc->sc_conf3 = getpropint(sa->sa_node, "busmaster-regval",
! 174: LE_C3_BSWP | LE_C3_ACON | LE_C3_BCON);
! 175:
! 176: myetheraddr(sc->sc_arpcom.ac_enaddr);
! 177:
! 178: sc->sc_copytodesc = am7990_copytobuf_contig;
! 179: sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
! 180: sc->sc_copytobuf = am7990_copytobuf_contig;
! 181: sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
! 182: sc->sc_zerobuf = am7990_zerobuf_contig;
! 183:
! 184: sc->sc_rdcsr = le_lebuffer_rdcsr;
! 185: sc->sc_wrcsr = le_lebuffer_wrcsr;
! 186:
! 187: am7990_config(&lesc->sc_am7990);
! 188:
! 189: /* Establish interrupt handler */
! 190: if (sa->sa_nintr != 0)
! 191: (void)bus_intr_establish(lesc->sc_bustag, sa->sa_pri,
! 192: IPL_NET, 0, am7990_intr, sc, self->dv_xname);
! 193: }
CVSweb