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