Home | History | Annotate | Line # | Download | only in dev
if_le.c revision 1.44
      1  1.44   thorpej /*	$NetBSD: if_le.c,v 1.44 2002/10/01 05:32:43 thorpej 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.40  jonathan #include "opt_inet.h"
     40   1.1     glass #include "bpfilter.h"
     41   1.1     glass 
     42   1.8     glass #include <sys/param.h>
     43   1.8     glass #include <sys/systm.h>
     44   1.8     glass #include <sys/mbuf.h>
     45  1.24   mycroft #include <sys/syslog.h>
     46   1.8     glass #include <sys/socket.h>
     47  1.16       gwr #include <sys/device.h>
     48   1.8     glass 
     49   1.8     glass #include <net/if.h>
     50  1.36        is #include <net/if_ether.h>
     51  1.37   thorpej #include <net/if_media.h>
     52  1.10       gwr 
     53   1.1     glass #ifdef INET
     54   1.8     glass #include <netinet/in.h>
     55  1.36        is #include <netinet/if_inarp.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/idprom.h>
     62  1.24   mycroft 
     63  1.41  drochner #include <dev/ic/lancereg.h>
     64  1.41  drochner #include <dev/ic/lancevar.h>
     65  1.24   mycroft #include <dev/ic/am7990reg.h>
     66  1.24   mycroft #include <dev/ic/am7990var.h>
     67  1.24   mycroft 
     68  1.39       gwr #define LE_MEMSIZE	0x4000	/* 16K */
     69  1.39       gwr 
     70  1.33       gwr /*
     71  1.33       gwr  * LANCE registers.
     72  1.33       gwr  * The real stuff is in dev/ic/am7990reg.h
     73  1.33       gwr  */
     74  1.33       gwr struct lereg1 {
     75  1.33       gwr 	volatile u_int16_t	ler1_rdp;	/* data port */
     76  1.33       gwr 	volatile u_int16_t	ler1_rap;	/* register select port */
     77  1.33       gwr };
     78  1.33       gwr 
     79  1.33       gwr /*
     80  1.33       gwr  * Ethernet software status per interface.
     81  1.33       gwr  * The real stuff is in dev/ic/am7990var.h
     82  1.33       gwr  */
     83  1.33       gwr struct	le_softc {
     84  1.33       gwr 	struct	am7990_softc sc_am7990;	/* glue to MI code */
     85  1.33       gwr 
     86  1.33       gwr 	struct	lereg1 *sc_r1;		/* LANCE registers */
     87  1.33       gwr };
     88  1.24   mycroft 
     89  1.34       gwr static int	le_match __P((struct device *, struct cfdata *, void *));
     90  1.26       gwr static void	le_attach __P((struct device *, struct device *, void *));
     91  1.10       gwr 
     92  1.44   thorpej CFATTACH_DECL(le, sizeof(struct le_softc),
     93  1.44   thorpej     le_match, le_attach, NULL, NULL)
     94  1.25   thorpej 
     95  1.42       mrg #if defined(_KERNEL_OPT)
     96  1.41  drochner #include "opt_ddb.h"
     97  1.41  drochner #endif
     98  1.41  drochner 
     99  1.41  drochner #ifdef DDB
    100  1.41  drochner #define	integrate
    101  1.41  drochner #define hide
    102  1.41  drochner #else
    103  1.41  drochner #define	integrate	static __inline
    104  1.41  drochner #define hide		static
    105  1.41  drochner #endif
    106  1.41  drochner 
    107  1.41  drochner hide void lewrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
    108  1.41  drochner hide u_int16_t lerdcsr __P((struct lance_softc *, u_int16_t));
    109  1.10       gwr 
    110  1.29   thorpej hide void
    111  1.24   mycroft lewrcsr(sc, port, val)
    112  1.41  drochner 	struct lance_softc *sc;
    113  1.24   mycroft 	u_int16_t port, val;
    114  1.16       gwr {
    115  1.29   thorpej 	register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    116  1.16       gwr 
    117  1.24   mycroft 	ler1->ler1_rap = port;
    118  1.24   mycroft 	ler1->ler1_rdp = val;
    119  1.16       gwr }
    120  1.16       gwr 
    121  1.29   thorpej hide u_int16_t
    122  1.24   mycroft lerdcsr(sc, port)
    123  1.41  drochner 	struct lance_softc *sc;
    124  1.24   mycroft 	u_int16_t port;
    125  1.16       gwr {
    126  1.29   thorpej 	register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    127  1.24   mycroft 	u_int16_t val;
    128  1.16       gwr 
    129  1.24   mycroft 	ler1->ler1_rap = port;
    130  1.24   mycroft 	val = ler1->ler1_rdp;
    131  1.24   mycroft 	return (val);
    132  1.16       gwr }
    133  1.16       gwr 
    134  1.24   mycroft int
    135  1.34       gwr le_match(parent, cf, aux)
    136  1.24   mycroft 	struct device *parent;
    137  1.34       gwr 	struct cfdata *cf;
    138  1.34       gwr 	void *aux;
    139  1.10       gwr {
    140  1.16       gwr 	struct confargs *ca = aux;
    141  1.18       gwr 
    142  1.32       gwr 	/* Make sure there is something there... */
    143  1.39       gwr 	if (bus_peek(ca->ca_bustype, ca->ca_paddr, 2) == -1)
    144  1.26       gwr 		return (0);
    145  1.23       gwr 
    146  1.32       gwr 	/* Default interrupt priority. */
    147  1.32       gwr 	if (ca->ca_intpri == -1)
    148  1.32       gwr 		ca->ca_intpri = 3;
    149  1.32       gwr 
    150  1.32       gwr 	return (1);
    151   1.1     glass }
    152   1.1     glass 
    153  1.10       gwr void
    154  1.26       gwr le_attach(parent, self, aux)
    155  1.24   mycroft 	struct device *parent, *self;
    156  1.24   mycroft 	void *aux;
    157  1.10       gwr {
    158  1.29   thorpej 	struct le_softc *lesc = (struct le_softc *)self;
    159  1.41  drochner 	struct lance_softc *sc = &lesc->sc_am7990.lsc;
    160  1.24   mycroft 	struct confargs *ca = aux;
    161  1.10       gwr 
    162  1.39       gwr 	lesc->sc_r1 = bus_mapin(ca->ca_bustype,
    163  1.39       gwr 	    ca->ca_paddr, sizeof(struct lereg1));
    164  1.26       gwr 
    165  1.39       gwr 	sc->sc_memsize = LE_MEMSIZE;
    166  1.26       gwr 	sc->sc_mem = dvma_malloc(sc->sc_memsize);
    167  1.39       gwr 	sc->sc_addr = dvma_kvtopa(sc->sc_mem, ca->ca_bustype);
    168  1.39       gwr #ifdef	_SUN3X_
    169  1.39       gwr 	sc->sc_conf3 = LE_C3_BSWP | LE_C3_ACON | LE_C3_BCON;
    170  1.39       gwr #else
    171  1.24   mycroft 	sc->sc_conf3 = LE_C3_BSWP;
    172  1.39       gwr #endif
    173   1.1     glass 
    174  1.36        is 	idprom_etheraddr(sc->sc_enaddr);
    175   1.1     glass 
    176  1.41  drochner 	sc->sc_copytodesc = lance_copytobuf_contig;
    177  1.41  drochner 	sc->sc_copyfromdesc = lance_copyfrombuf_contig;
    178  1.41  drochner 	sc->sc_copytobuf = lance_copytobuf_contig;
    179  1.41  drochner 	sc->sc_copyfrombuf = lance_copyfrombuf_contig;
    180  1.41  drochner 	sc->sc_zerobuf = lance_zerobuf_contig;
    181   1.1     glass 
    182  1.29   thorpej 	sc->sc_rdcsr = lerdcsr;
    183  1.29   thorpej 	sc->sc_wrcsr = lewrcsr;
    184  1.29   thorpej 	sc->sc_hwinit = NULL;
    185  1.29   thorpej 
    186  1.41  drochner 	am7990_config(&lesc->sc_am7990);
    187  1.16       gwr 
    188  1.24   mycroft 	/* Install interrupt handler. */
    189  1.32       gwr 	isr_add_autovect(am7990_intr, (void *)sc, ca->ca_intpri);
    190   1.1     glass }
    191