Home | History | Annotate | Line # | Download | only in dev
if_le.c revision 1.50.4.1
      1  1.50.4.1      yamt /*	$NetBSD: if_le.c,v 1.50.4.1 2008/05/16 02:23:17 yamt 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  *
     19      1.33       gwr  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20      1.33       gwr  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21      1.33       gwr  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22      1.35       gwr  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23      1.35       gwr  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24      1.33       gwr  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25      1.33       gwr  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26      1.33       gwr  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27      1.33       gwr  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28      1.33       gwr  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29      1.33       gwr  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1     glass  */
     31      1.46     lukem 
     32      1.46     lukem #include <sys/cdefs.h>
     33  1.50.4.1      yamt __KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.50.4.1 2008/05/16 02:23:17 yamt Exp $");
     34       1.1     glass 
     35      1.40  jonathan #include "opt_inet.h"
     36       1.1     glass #include "bpfilter.h"
     37       1.1     glass 
     38       1.8     glass #include <sys/param.h>
     39       1.8     glass #include <sys/systm.h>
     40       1.8     glass #include <sys/mbuf.h>
     41      1.24   mycroft #include <sys/syslog.h>
     42       1.8     glass #include <sys/socket.h>
     43      1.16       gwr #include <sys/device.h>
     44       1.8     glass 
     45       1.8     glass #include <net/if.h>
     46      1.36        is #include <net/if_ether.h>
     47      1.37   thorpej #include <net/if_media.h>
     48      1.10       gwr 
     49       1.1     glass #ifdef INET
     50       1.8     glass #include <netinet/in.h>
     51      1.36        is #include <netinet/if_inarp.h>
     52       1.1     glass #endif
     53       1.1     glass 
     54       1.8     glass #include <machine/autoconf.h>
     55      1.10       gwr #include <machine/cpu.h>
     56      1.24   mycroft #include <machine/dvma.h>
     57      1.24   mycroft #include <machine/idprom.h>
     58      1.24   mycroft 
     59      1.41  drochner #include <dev/ic/lancereg.h>
     60      1.41  drochner #include <dev/ic/lancevar.h>
     61      1.24   mycroft #include <dev/ic/am7990reg.h>
     62      1.24   mycroft #include <dev/ic/am7990var.h>
     63      1.24   mycroft 
     64      1.39       gwr #define LE_MEMSIZE	0x4000	/* 16K */
     65      1.39       gwr 
     66      1.33       gwr /*
     67      1.33       gwr  * LANCE registers.
     68      1.33       gwr  * The real stuff is in dev/ic/am7990reg.h
     69      1.33       gwr  */
     70      1.33       gwr struct lereg1 {
     71      1.47       chs 	volatile uint16_t	ler1_rdp;	/* data port */
     72      1.47       chs 	volatile uint16_t	ler1_rap;	/* register select port */
     73      1.33       gwr };
     74      1.33       gwr 
     75      1.33       gwr /*
     76      1.33       gwr  * Ethernet software status per interface.
     77      1.33       gwr  * The real stuff is in dev/ic/am7990var.h
     78      1.33       gwr  */
     79      1.33       gwr struct	le_softc {
     80      1.33       gwr 	struct	am7990_softc sc_am7990;	/* glue to MI code */
     81      1.33       gwr 
     82      1.33       gwr 	struct	lereg1 *sc_r1;		/* LANCE registers */
     83      1.33       gwr };
     84      1.24   mycroft 
     85      1.50   tsutsui static int	le_match(device_t, cfdata_t, void *);
     86      1.50   tsutsui static void	le_attach(device_t, device_t, void *);
     87      1.10       gwr 
     88      1.50   tsutsui CFATTACH_DECL_NEW(le, sizeof(struct le_softc),
     89      1.45   thorpej     le_match, le_attach, NULL, NULL);
     90      1.25   thorpej 
     91      1.42       mrg #if defined(_KERNEL_OPT)
     92      1.41  drochner #include "opt_ddb.h"
     93      1.41  drochner #endif
     94      1.41  drochner 
     95      1.41  drochner #ifdef DDB
     96      1.41  drochner #define	integrate
     97      1.41  drochner #define hide
     98      1.41  drochner #else
     99      1.49     perry #define	integrate	static inline
    100      1.41  drochner #define hide		static
    101      1.41  drochner #endif
    102      1.41  drochner 
    103      1.47       chs hide void lewrcsr(struct lance_softc *, uint16_t, uint16_t);
    104      1.47       chs hide uint16_t lerdcsr(struct lance_softc *, uint16_t);
    105      1.10       gwr 
    106      1.47       chs hide void
    107      1.47       chs lewrcsr(struct lance_softc *sc, uint16_t port, uint16_t val)
    108      1.16       gwr {
    109      1.47       chs 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    110      1.16       gwr 
    111      1.24   mycroft 	ler1->ler1_rap = port;
    112      1.24   mycroft 	ler1->ler1_rdp = val;
    113      1.16       gwr }
    114      1.16       gwr 
    115      1.47       chs hide uint16_t
    116      1.47       chs lerdcsr(struct lance_softc *sc, uint16_t port)
    117      1.16       gwr {
    118      1.47       chs 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    119      1.47       chs 	uint16_t val;
    120      1.16       gwr 
    121      1.24   mycroft 	ler1->ler1_rap = port;
    122      1.24   mycroft 	val = ler1->ler1_rdp;
    123      1.24   mycroft 	return (val);
    124      1.16       gwr }
    125      1.16       gwr 
    126      1.47       chs int
    127      1.50   tsutsui le_match(device_t parent, cfdata_t cf, void *aux)
    128      1.10       gwr {
    129      1.16       gwr 	struct confargs *ca = aux;
    130      1.18       gwr 
    131      1.32       gwr 	/* Make sure there is something there... */
    132      1.39       gwr 	if (bus_peek(ca->ca_bustype, ca->ca_paddr, 2) == -1)
    133      1.26       gwr 		return (0);
    134      1.23       gwr 
    135      1.32       gwr 	/* Default interrupt priority. */
    136      1.32       gwr 	if (ca->ca_intpri == -1)
    137      1.32       gwr 		ca->ca_intpri = 3;
    138      1.32       gwr 
    139      1.32       gwr 	return (1);
    140       1.1     glass }
    141       1.1     glass 
    142      1.47       chs void
    143      1.50   tsutsui le_attach(device_t parent, device_t self, void *aux)
    144      1.10       gwr {
    145      1.50   tsutsui 	struct le_softc *lesc = device_private(self);
    146      1.41  drochner 	struct lance_softc *sc = &lesc->sc_am7990.lsc;
    147      1.24   mycroft 	struct confargs *ca = aux;
    148      1.10       gwr 
    149      1.50   tsutsui 	sc->sc_dev = self;
    150      1.39       gwr 	lesc->sc_r1 = bus_mapin(ca->ca_bustype,
    151      1.39       gwr 	    ca->ca_paddr, sizeof(struct lereg1));
    152      1.26       gwr 
    153      1.39       gwr 	sc->sc_memsize = LE_MEMSIZE;
    154      1.26       gwr 	sc->sc_mem = dvma_malloc(sc->sc_memsize);
    155      1.39       gwr 	sc->sc_addr = dvma_kvtopa(sc->sc_mem, ca->ca_bustype);
    156      1.39       gwr #ifdef	_SUN3X_
    157      1.39       gwr 	sc->sc_conf3 = LE_C3_BSWP | LE_C3_ACON | LE_C3_BCON;
    158      1.39       gwr #else
    159      1.24   mycroft 	sc->sc_conf3 = LE_C3_BSWP;
    160      1.39       gwr #endif
    161       1.1     glass 
    162      1.36        is 	idprom_etheraddr(sc->sc_enaddr);
    163       1.1     glass 
    164      1.41  drochner 	sc->sc_copytodesc = lance_copytobuf_contig;
    165      1.41  drochner 	sc->sc_copyfromdesc = lance_copyfrombuf_contig;
    166      1.41  drochner 	sc->sc_copytobuf = lance_copytobuf_contig;
    167      1.41  drochner 	sc->sc_copyfrombuf = lance_copyfrombuf_contig;
    168      1.41  drochner 	sc->sc_zerobuf = lance_zerobuf_contig;
    169       1.1     glass 
    170      1.29   thorpej 	sc->sc_rdcsr = lerdcsr;
    171      1.29   thorpej 	sc->sc_wrcsr = lewrcsr;
    172      1.29   thorpej 	sc->sc_hwinit = NULL;
    173      1.29   thorpej 
    174      1.41  drochner 	am7990_config(&lesc->sc_am7990);
    175      1.16       gwr 
    176      1.24   mycroft 	/* Install interrupt handler. */
    177      1.32       gwr 	isr_add_autovect(am7990_intr, (void *)sc, ca->ca_intpri);
    178       1.1     glass }
    179