Home | History | Annotate | Line # | Download | only in dev
if_le.c revision 1.29
      1  1.29  thorpej /*	$NetBSD: if_le.c,v 1.29 1996/05/07 01:32:31 thorpej Exp $	*/
      2  1.12      cgd 
      3  1.24  mycroft /*-
      4  1.24  mycroft  * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
      5  1.24  mycroft  * Copyright (c) 1992, 1993
      6  1.24  mycroft  *	The Regents of the University of California.  All rights reserved.
      7   1.1    glass  *
      8  1.24  mycroft  * This code is derived from software contributed to Berkeley by
      9  1.24  mycroft  * Ralph Campbell and Rick Macklem.
     10   1.1    glass  *
     11  1.24  mycroft  * Redistribution and use in source and binary forms, with or without
     12  1.24  mycroft  * modification, are permitted provided that the following conditions
     13  1.24  mycroft  * are met:
     14  1.24  mycroft  * 1. Redistributions of source code must retain the above copyright
     15  1.24  mycroft  *    notice, this list of conditions and the following disclaimer.
     16  1.24  mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.24  mycroft  *    notice, this list of conditions and the following disclaimer in the
     18  1.24  mycroft  *    documentation and/or other materials provided with the distribution.
     19  1.24  mycroft  * 3. All advertising materials mentioning features or use of this software
     20  1.24  mycroft  *    must display the following acknowledgement:
     21  1.24  mycroft  *	This product includes software developed by the University of
     22  1.24  mycroft  *	California, Berkeley and its contributors.
     23  1.24  mycroft  * 4. Neither the name of the University nor the names of its contributors
     24  1.24  mycroft  *    may be used to endorse or promote products derived from this software
     25  1.24  mycroft  *    without specific prior written permission.
     26  1.24  mycroft  *
     27  1.24  mycroft  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     28  1.24  mycroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     29  1.24  mycroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     30  1.24  mycroft  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     31  1.24  mycroft  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     32  1.24  mycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     33  1.24  mycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     34  1.24  mycroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     35  1.24  mycroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     36  1.24  mycroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     37  1.24  mycroft  * SUCH DAMAGE.
     38  1.24  mycroft  *
     39  1.24  mycroft  *	@(#)if_le.c	8.2 (Berkeley) 11/16/93
     40   1.1    glass  */
     41   1.1    glass 
     42   1.1    glass #include "bpfilter.h"
     43   1.1    glass 
     44   1.8    glass #include <sys/param.h>
     45   1.8    glass #include <sys/systm.h>
     46   1.8    glass #include <sys/mbuf.h>
     47  1.24  mycroft #include <sys/syslog.h>
     48   1.8    glass #include <sys/socket.h>
     49  1.16      gwr #include <sys/device.h>
     50   1.8    glass 
     51   1.8    glass #include <net/if.h>
     52  1.10      gwr 
     53   1.1    glass #ifdef INET
     54   1.8    glass #include <netinet/in.h>
     55   1.8    glass #include <netinet/if_ether.h>
     56   1.1    glass #endif
     57   1.1    glass 
     58   1.8    glass #include <machine/autoconf.h>
     59  1.10      gwr #include <machine/cpu.h>
     60  1.24  mycroft #include <machine/dvma.h>
     61  1.24  mycroft #include <machine/isr.h>
     62  1.24  mycroft #include <machine/obio.h>
     63  1.24  mycroft #include <machine/idprom.h>
     64  1.24  mycroft 
     65  1.24  mycroft #include <dev/ic/am7990reg.h>
     66  1.24  mycroft #include <dev/ic/am7990var.h>
     67  1.24  mycroft 
     68  1.29  thorpej #include <sun3/dev/if_lereg.h>
     69  1.29  thorpej #include <sun3/dev/if_levar.h>
     70  1.24  mycroft 
     71  1.26      gwr static int	le_match __P((struct device *, void *, void *));
     72  1.26      gwr static void	le_attach __P((struct device *, struct device *, void *));
     73  1.10      gwr 
     74  1.25  thorpej struct cfattach le_ca = {
     75  1.26      gwr 	sizeof(struct le_softc), le_match, le_attach
     76  1.25  thorpej };
     77  1.25  thorpej 
     78  1.29  thorpej hide void lewrcsr __P((struct am7990_softc *, u_int16_t, u_int16_t));
     79  1.29  thorpej hide u_int16_t lerdcsr __P((struct am7990_softc *, u_int16_t));
     80  1.10      gwr 
     81  1.29  thorpej hide void
     82  1.24  mycroft lewrcsr(sc, port, val)
     83  1.29  thorpej 	struct am7990_softc *sc;
     84  1.24  mycroft 	u_int16_t port, val;
     85  1.16      gwr {
     86  1.29  thorpej 	register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
     87  1.16      gwr 
     88  1.24  mycroft 	ler1->ler1_rap = port;
     89  1.24  mycroft 	ler1->ler1_rdp = val;
     90  1.16      gwr }
     91  1.16      gwr 
     92  1.29  thorpej hide u_int16_t
     93  1.24  mycroft lerdcsr(sc, port)
     94  1.29  thorpej 	struct am7990_softc *sc;
     95  1.24  mycroft 	u_int16_t port;
     96  1.16      gwr {
     97  1.29  thorpej 	register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
     98  1.24  mycroft 	u_int16_t val;
     99  1.16      gwr 
    100  1.24  mycroft 	ler1->ler1_rap = port;
    101  1.24  mycroft 	val = ler1->ler1_rdp;
    102  1.24  mycroft 	return (val);
    103  1.16      gwr }
    104  1.16      gwr 
    105  1.24  mycroft int
    106  1.26      gwr le_match(parent, vcf, aux)
    107  1.24  mycroft 	struct device *parent;
    108  1.26      gwr 	void *vcf, *aux;
    109  1.10      gwr {
    110  1.26      gwr 	struct cfdata *cf = vcf;
    111  1.16      gwr 	struct confargs *ca = aux;
    112  1.26      gwr 	int pa, x;
    113  1.18      gwr 
    114  1.26      gwr 	/*
    115  1.26      gwr 	 * OBIO match functions may be called for every possible
    116  1.26      gwr 	 * physical address, so match only our physical address.
    117  1.26      gwr 	 */
    118  1.26      gwr 	if ((pa = cf->cf_paddr) == -1) {
    119  1.26      gwr 		/* Use our default PA. */
    120  1.26      gwr 		pa = OBIO_AMD_ETHER;
    121  1.26      gwr 	}
    122  1.26      gwr 	if (pa != ca->ca_paddr)
    123  1.26      gwr 		return (0);
    124  1.23      gwr 
    125  1.24  mycroft 	/* The peek returns -1 on bus error. */
    126  1.24  mycroft 	x = bus_peek(ca->ca_bustype, ca->ca_paddr, 1);
    127  1.24  mycroft 	return (x != -1);
    128   1.1    glass }
    129   1.1    glass 
    130  1.10      gwr void
    131  1.26      gwr le_attach(parent, self, aux)
    132  1.24  mycroft 	struct device *parent, *self;
    133  1.24  mycroft 	void *aux;
    134  1.10      gwr {
    135  1.29  thorpej 	struct le_softc *lesc = (struct le_softc *)self;
    136  1.29  thorpej 	struct am7990_softc *sc = &lesc->sc_am7990;
    137  1.26      gwr 	struct cfdata *cf = self->dv_cfdata;
    138  1.24  mycroft 	struct confargs *ca = aux;
    139  1.26      gwr 	int intpri;
    140  1.26      gwr 
    141  1.26      gwr 	/* Default interrupt level. */
    142  1.26      gwr 	if ((intpri = cf->cf_intpri) == -1)
    143  1.26      gwr 		intpri = 3;
    144  1.26      gwr 	printf(" level %d", intpri);
    145  1.10      gwr 
    146  1.29  thorpej 	lesc->sc_r1 = (struct lereg1 *)
    147  1.24  mycroft 	    obio_alloc(ca->ca_paddr, OBIO_AMD_ETHER_SIZE);
    148  1.26      gwr 
    149  1.26      gwr 	sc->sc_memsize = 0x4000;	/* 16K */
    150  1.26      gwr 	sc->sc_mem = dvma_malloc(sc->sc_memsize);
    151  1.26      gwr 	sc->sc_addr = (u_long)sc->sc_mem & 0xffffff;
    152  1.24  mycroft 	sc->sc_conf3 = LE_C3_BSWP;
    153   1.1    glass 
    154  1.24  mycroft 	idprom_etheraddr(sc->sc_arpcom.ac_enaddr);
    155   1.1    glass 
    156  1.27      cgd 	sc->sc_copytodesc = am7990_copytobuf_contig;
    157  1.27      cgd 	sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
    158  1.27      cgd 	sc->sc_copytobuf = am7990_copytobuf_contig;
    159  1.27      cgd 	sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
    160  1.27      cgd 	sc->sc_zerobuf = am7990_zerobuf_contig;
    161   1.1    glass 
    162  1.29  thorpej 	sc->sc_rdcsr = lerdcsr;
    163  1.29  thorpej 	sc->sc_wrcsr = lewrcsr;
    164  1.29  thorpej 	sc->sc_hwinit = NULL;
    165  1.29  thorpej 
    166  1.29  thorpej 	am7990_config(sc);
    167  1.16      gwr 
    168  1.24  mycroft 	/* Install interrupt handler. */
    169  1.29  thorpej 	isr_add_autovect(am7990_intr, (void *)sc, intpri);
    170   1.1    glass }
    171