Home | History | Annotate | Line # | Download | only in dev
if_le.c revision 1.7.2.1
      1  1.7.2.1  jdolecek /*	$NetBSD: if_le.c,v 1.7.2.1 2002/10/10 18:34:34 jdolecek Exp $	*/
      2      1.1    tsubai 
      3      1.1    tsubai /*-
      4      1.1    tsubai  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5      1.1    tsubai  * All rights reserved.
      6      1.1    tsubai  *
      7      1.1    tsubai  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1    tsubai  * by Adam Glass and Gordon W. Ross.
      9      1.1    tsubai  *
     10      1.1    tsubai  * Redistribution and use in source and binary forms, with or without
     11      1.1    tsubai  * modification, are permitted provided that the following conditions
     12      1.1    tsubai  * are met:
     13      1.1    tsubai  * 1. Redistributions of source code must retain the above copyright
     14      1.1    tsubai  *    notice, this list of conditions and the following disclaimer.
     15      1.1    tsubai  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1    tsubai  *    notice, this list of conditions and the following disclaimer in the
     17      1.1    tsubai  *    documentation and/or other materials provided with the distribution.
     18      1.1    tsubai  * 3. All advertising materials mentioning features or use of this software
     19      1.1    tsubai  *    must display the following acknowledgement:
     20      1.1    tsubai  *        This product includes software developed by the NetBSD
     21      1.1    tsubai  *        Foundation, Inc. and its contributors.
     22      1.1    tsubai  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.1    tsubai  *    contributors may be used to endorse or promote products derived
     24      1.1    tsubai  *    from this software without specific prior written permission.
     25      1.1    tsubai  *
     26      1.1    tsubai  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.1    tsubai  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.1    tsubai  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.1    tsubai  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.1    tsubai  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.1    tsubai  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.1    tsubai  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.1    tsubai  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.1    tsubai  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.1    tsubai  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.1    tsubai  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1    tsubai  */
     38      1.1    tsubai 
     39      1.2  jonathan #include "opt_inet.h"
     40      1.1    tsubai #include "bpfilter.h"
     41      1.1    tsubai 
     42      1.1    tsubai #include <sys/param.h>
     43      1.1    tsubai #include <sys/systm.h>
     44      1.1    tsubai #include <sys/mbuf.h>
     45      1.1    tsubai #include <sys/syslog.h>
     46      1.1    tsubai #include <sys/socket.h>
     47      1.1    tsubai #include <sys/device.h>
     48      1.1    tsubai 
     49      1.1    tsubai #include <net/if.h>
     50      1.1    tsubai #include <net/if_ether.h>
     51      1.1    tsubai #include <net/if_media.h>
     52      1.1    tsubai 
     53      1.1    tsubai #ifdef INET
     54      1.1    tsubai #include <netinet/in.h>
     55      1.1    tsubai #include <netinet/if_inarp.h>
     56      1.1    tsubai #endif
     57      1.1    tsubai 
     58      1.1    tsubai #include <machine/autoconf.h>
     59      1.1    tsubai #include <machine/cpu.h>
     60      1.1    tsubai #include <machine/adrsmap.h>
     61      1.1    tsubai 
     62      1.3  drochner #include <dev/ic/lancereg.h>
     63      1.3  drochner #include <dev/ic/lancevar.h>
     64      1.1    tsubai #include <dev/ic/am7990reg.h>
     65      1.1    tsubai #include <dev/ic/am7990var.h>
     66      1.1    tsubai 
     67      1.1    tsubai /*
     68      1.1    tsubai  * LANCE registers.
     69      1.1    tsubai  * The real stuff is in dev/ic/am7990reg.h
     70      1.1    tsubai  */
     71      1.1    tsubai struct lereg1 {
     72      1.1    tsubai 	volatile u_int16_t	ler1_rdp;	/* data port */
     73      1.1    tsubai 	volatile u_int16_t	ler1_rap;	/* register select port */
     74      1.1    tsubai };
     75      1.1    tsubai 
     76      1.1    tsubai /*
     77      1.1    tsubai  * Ethernet software status per interface.
     78      1.1    tsubai  * The real stuff is in dev/ic/am7990var.h
     79      1.1    tsubai  */
     80      1.1    tsubai struct	le_softc {
     81      1.1    tsubai 	struct	am7990_softc sc_am7990;	/* glue to MI code */
     82      1.1    tsubai 
     83      1.1    tsubai 	struct	lereg1 *sc_r1;		/* LANCE registers */
     84      1.1    tsubai };
     85      1.1    tsubai 
     86      1.1    tsubai static int	le_match __P((struct device *, struct cfdata *, void *));
     87      1.1    tsubai static void	le_attach __P((struct device *, struct device *, void *));
     88      1.1    tsubai 
     89  1.7.2.1  jdolecek CFATTACH_DECL(le, sizeof(struct le_softc),
     90  1.7.2.1  jdolecek     le_match, le_attach, NULL, NULL);
     91      1.1    tsubai 
     92      1.7       mrg #if defined(_KERNEL_OPT)
     93      1.3  drochner #include "opt_ddb.h"
     94      1.3  drochner #endif
     95      1.3  drochner 
     96      1.3  drochner #ifdef DDB
     97      1.3  drochner #define	integrate
     98      1.3  drochner #define hide
     99      1.3  drochner #else
    100      1.3  drochner #define	integrate	static __inline
    101      1.3  drochner #define hide		static
    102      1.3  drochner #endif
    103      1.3  drochner 
    104      1.3  drochner hide void lewrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
    105      1.3  drochner hide u_int16_t lerdcsr __P((struct lance_softc *, u_int16_t));
    106      1.1    tsubai 
    107      1.1    tsubai hide void
    108      1.1    tsubai lewrcsr(sc, port, val)
    109      1.3  drochner 	struct lance_softc *sc;
    110      1.1    tsubai 	u_int16_t port, val;
    111      1.1    tsubai {
    112      1.1    tsubai 	register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    113      1.1    tsubai 
    114      1.1    tsubai 	ler1->ler1_rap = port;
    115      1.1    tsubai 	ler1->ler1_rdp = val;
    116      1.1    tsubai }
    117      1.1    tsubai 
    118      1.1    tsubai hide u_int16_t
    119      1.1    tsubai lerdcsr(sc, port)
    120      1.3  drochner 	struct lance_softc *sc;
    121      1.1    tsubai 	u_int16_t port;
    122      1.1    tsubai {
    123      1.1    tsubai 	register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    124      1.1    tsubai 	u_int16_t val;
    125      1.1    tsubai 
    126      1.1    tsubai 	ler1->ler1_rap = port;
    127      1.1    tsubai 	val = ler1->ler1_rdp;
    128      1.1    tsubai 	return (val);
    129      1.1    tsubai }
    130      1.1    tsubai 
    131      1.1    tsubai int
    132      1.1    tsubai le_match(parent, cf, aux)
    133      1.1    tsubai 	struct device *parent;
    134      1.1    tsubai 	struct cfdata *cf;
    135      1.1    tsubai 	void *aux;
    136      1.1    tsubai {
    137      1.1    tsubai 	struct confargs *ca = aux;
    138      1.1    tsubai 
    139      1.1    tsubai 	if (strcmp(ca->ca_name, "le"))
    140      1.1    tsubai 		return 0;
    141      1.1    tsubai 
    142      1.6    tsubai 	if (badaddr((void *)cf->cf_addr, 1))
    143      1.1    tsubai 		return 0;
    144      1.1    tsubai 
    145      1.1    tsubai 	return 1;
    146      1.1    tsubai }
    147      1.1    tsubai 
    148      1.1    tsubai void
    149      1.1    tsubai le_attach(parent, self, aux)
    150      1.1    tsubai 	struct device *parent, *self;
    151      1.1    tsubai 	void *aux;
    152      1.1    tsubai {
    153      1.1    tsubai 	struct le_softc *lesc = (struct le_softc *)self;
    154      1.3  drochner 	struct lance_softc *sc = &lesc->sc_am7990.lsc;
    155      1.6    tsubai 	struct cfdata *cf = self->dv_cfdata;
    156      1.5    tsubai 	int intlevel;
    157      1.1    tsubai 	u_char *p;
    158      1.1    tsubai 
    159      1.6    tsubai 	intlevel = cf->cf_level;
    160      1.5    tsubai 	if (intlevel == -1) {
    161      1.5    tsubai 		printf(": interrupt level not configured\n");
    162      1.5    tsubai 		return;
    163      1.5    tsubai 	}
    164      1.5    tsubai 	printf(" level %d", intlevel);
    165      1.5    tsubai 
    166      1.6    tsubai 	switch (cf->cf_addr) {
    167      1.1    tsubai 
    168      1.6    tsubai 	case LANCE_PORT:
    169      1.1    tsubai 		sc->sc_mem = (void *)LANCE_MEMORY;
    170      1.1    tsubai 		p = (u_char *)(ETHER_ID+16);
    171      1.1    tsubai 		break;
    172      1.6    tsubai 	case LANCE_PORT1:
    173      1.1    tsubai 		sc->sc_mem = (void *)LANCE_MEMORY1;
    174      1.1    tsubai 		p = (u_char *)(ETHER_ID1+16);
    175      1.1    tsubai 		break;
    176      1.6    tsubai 	case LANCE_PORT2:
    177      1.1    tsubai 		sc->sc_mem = (void *)LANCE_MEMORY2;
    178      1.1    tsubai 		p = (u_char *)(ETHER_ID2+16);
    179      1.1    tsubai 		break;
    180      1.1    tsubai 
    181      1.1    tsubai 	default:
    182      1.6    tsubai 		printf(": unknown LANCE addr\n");
    183      1.6    tsubai 		return;
    184      1.1    tsubai 	}
    185      1.1    tsubai 
    186      1.6    tsubai 	lesc->sc_r1 = (void *)cf->cf_addr;
    187      1.6    tsubai 
    188      1.1    tsubai 	sc->sc_memsize = 0x4000;	/* 16K */
    189      1.1    tsubai 	sc->sc_addr = (int)sc->sc_mem & 0x00ffffff;
    190      1.1    tsubai 	sc->sc_conf3 = LE_C3_BSWP|LE_C3_BCON;
    191      1.1    tsubai 
    192      1.1    tsubai 	sc->sc_enaddr[0] = (*p++ << 4);
    193      1.1    tsubai 	sc->sc_enaddr[0] |= *p++ & 0x0f;
    194      1.1    tsubai 	sc->sc_enaddr[1] = (*p++ << 4);
    195      1.1    tsubai 	sc->sc_enaddr[1] |= *p++ & 0x0f;
    196      1.1    tsubai 	sc->sc_enaddr[2] = (*p++ << 4);
    197      1.1    tsubai 	sc->sc_enaddr[2] |= *p++ & 0x0f;
    198      1.1    tsubai 	sc->sc_enaddr[3] = (*p++ << 4);
    199      1.1    tsubai 	sc->sc_enaddr[3] |= *p++ & 0x0f;
    200      1.1    tsubai 	sc->sc_enaddr[4] = (*p++ << 4);
    201      1.1    tsubai 	sc->sc_enaddr[4] |= *p++ & 0x0f;
    202      1.1    tsubai 	sc->sc_enaddr[5] = (*p++ << 4);
    203      1.1    tsubai 	sc->sc_enaddr[5] |= *p++ & 0x0f;
    204      1.1    tsubai 
    205      1.3  drochner 	sc->sc_copytodesc = lance_copytobuf_contig;
    206      1.3  drochner 	sc->sc_copyfromdesc = lance_copyfrombuf_contig;
    207      1.3  drochner 	sc->sc_copytobuf = lance_copytobuf_contig;
    208      1.3  drochner 	sc->sc_copyfrombuf = lance_copyfrombuf_contig;
    209      1.3  drochner 	sc->sc_zerobuf = lance_zerobuf_contig;
    210      1.1    tsubai 
    211      1.1    tsubai 	sc->sc_rdcsr = lerdcsr;
    212      1.1    tsubai 	sc->sc_wrcsr = lewrcsr;
    213      1.1    tsubai 	sc->sc_hwinit = NULL;
    214      1.1    tsubai 
    215      1.3  drochner 	am7990_config(&lesc->sc_am7990);
    216      1.6    tsubai 	hb_intr_establish(intlevel, IPL_NET, am7990_intr, sc);
    217      1.1    tsubai }
    218