Home | History | Annotate | Line # | Download | only in dev
if_le.c revision 1.3.14.1
      1  1.3.14.1    bouyer /*	$NetBSD: if_le.c,v 1.3.14.1 2000/11/20 20:17:21 bouyer 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.1    tsubai struct cfattach le_ca = {
     90       1.1    tsubai 	sizeof(struct le_softc), le_match, le_attach
     91       1.1    tsubai };
     92       1.1    tsubai 
     93       1.3  drochner #if defined(_KERNEL) && !defined(_LKM)
     94       1.3  drochner #include "opt_ddb.h"
     95       1.3  drochner #endif
     96       1.3  drochner 
     97       1.3  drochner #ifdef DDB
     98       1.3  drochner #define	integrate
     99       1.3  drochner #define hide
    100       1.3  drochner #else
    101       1.3  drochner #define	integrate	static __inline
    102       1.3  drochner #define hide		static
    103       1.3  drochner #endif
    104       1.3  drochner 
    105       1.3  drochner hide void lewrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
    106       1.3  drochner hide u_int16_t lerdcsr __P((struct lance_softc *, u_int16_t));
    107       1.1    tsubai 
    108       1.1    tsubai hide void
    109       1.1    tsubai lewrcsr(sc, port, val)
    110       1.3  drochner 	struct lance_softc *sc;
    111       1.1    tsubai 	u_int16_t port, val;
    112       1.1    tsubai {
    113       1.1    tsubai 	register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    114       1.1    tsubai 
    115       1.1    tsubai 	ler1->ler1_rap = port;
    116       1.1    tsubai 	ler1->ler1_rdp = val;
    117       1.1    tsubai }
    118       1.1    tsubai 
    119       1.1    tsubai hide u_int16_t
    120       1.1    tsubai lerdcsr(sc, port)
    121       1.3  drochner 	struct lance_softc *sc;
    122       1.1    tsubai 	u_int16_t port;
    123       1.1    tsubai {
    124       1.1    tsubai 	register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    125       1.1    tsubai 	u_int16_t val;
    126       1.1    tsubai 
    127       1.1    tsubai 	ler1->ler1_rap = port;
    128       1.1    tsubai 	val = ler1->ler1_rdp;
    129       1.1    tsubai 	return (val);
    130       1.1    tsubai }
    131       1.1    tsubai 
    132       1.1    tsubai int
    133       1.1    tsubai le_match(parent, cf, aux)
    134       1.1    tsubai 	struct device *parent;
    135       1.1    tsubai 	struct cfdata *cf;
    136       1.1    tsubai 	void *aux;
    137       1.1    tsubai {
    138       1.1    tsubai 	struct confargs *ca = aux;
    139       1.1    tsubai 
    140       1.1    tsubai 	if (strcmp(ca->ca_name, "le"))
    141       1.1    tsubai 		return 0;
    142       1.1    tsubai 
    143  1.3.14.1    bouyer 	if (badaddr((void *)cf->cf_addr, 1))
    144       1.1    tsubai 		return 0;
    145       1.1    tsubai 
    146       1.1    tsubai 	return 1;
    147       1.1    tsubai }
    148       1.1    tsubai 
    149       1.1    tsubai void
    150       1.1    tsubai le_attach(parent, self, aux)
    151       1.1    tsubai 	struct device *parent, *self;
    152       1.1    tsubai 	void *aux;
    153       1.1    tsubai {
    154       1.1    tsubai 	struct le_softc *lesc = (struct le_softc *)self;
    155       1.3  drochner 	struct lance_softc *sc = &lesc->sc_am7990.lsc;
    156  1.3.14.1    bouyer 	struct cfdata *cf = self->dv_cfdata;
    157  1.3.14.1    bouyer 	int intlevel;
    158       1.1    tsubai 	u_char *p;
    159       1.1    tsubai 
    160  1.3.14.1    bouyer 	intlevel = cf->cf_level;
    161  1.3.14.1    bouyer 	if (intlevel == -1) {
    162  1.3.14.1    bouyer 		printf(": interrupt level not configured\n");
    163  1.3.14.1    bouyer 		return;
    164  1.3.14.1    bouyer 	}
    165  1.3.14.1    bouyer 	printf(" level %d", intlevel);
    166       1.1    tsubai 
    167  1.3.14.1    bouyer 	switch (cf->cf_addr) {
    168  1.3.14.1    bouyer 
    169  1.3.14.1    bouyer 	case LANCE_PORT:
    170       1.1    tsubai 		sc->sc_mem = (void *)LANCE_MEMORY;
    171       1.1    tsubai 		p = (u_char *)(ETHER_ID+16);
    172       1.1    tsubai 		break;
    173  1.3.14.1    bouyer 	case LANCE_PORT1:
    174       1.1    tsubai 		sc->sc_mem = (void *)LANCE_MEMORY1;
    175       1.1    tsubai 		p = (u_char *)(ETHER_ID1+16);
    176       1.1    tsubai 		break;
    177  1.3.14.1    bouyer 	case LANCE_PORT2:
    178       1.1    tsubai 		sc->sc_mem = (void *)LANCE_MEMORY2;
    179       1.1    tsubai 		p = (u_char *)(ETHER_ID2+16);
    180       1.1    tsubai 		break;
    181       1.1    tsubai 
    182       1.1    tsubai 	default:
    183  1.3.14.1    bouyer 		printf(": unknown LANCE addr\n");
    184  1.3.14.1    bouyer 		return;
    185       1.1    tsubai 	}
    186       1.1    tsubai 
    187  1.3.14.1    bouyer 	lesc->sc_r1 = (void *)cf->cf_addr;
    188  1.3.14.1    bouyer 
    189       1.1    tsubai 	sc->sc_memsize = 0x4000;	/* 16K */
    190       1.1    tsubai 	sc->sc_addr = (int)sc->sc_mem & 0x00ffffff;
    191       1.1    tsubai 	sc->sc_conf3 = LE_C3_BSWP|LE_C3_BCON;
    192       1.1    tsubai 
    193       1.1    tsubai 	sc->sc_enaddr[0] = (*p++ << 4);
    194       1.1    tsubai 	sc->sc_enaddr[0] |= *p++ & 0x0f;
    195       1.1    tsubai 	sc->sc_enaddr[1] = (*p++ << 4);
    196       1.1    tsubai 	sc->sc_enaddr[1] |= *p++ & 0x0f;
    197       1.1    tsubai 	sc->sc_enaddr[2] = (*p++ << 4);
    198       1.1    tsubai 	sc->sc_enaddr[2] |= *p++ & 0x0f;
    199       1.1    tsubai 	sc->sc_enaddr[3] = (*p++ << 4);
    200       1.1    tsubai 	sc->sc_enaddr[3] |= *p++ & 0x0f;
    201       1.1    tsubai 	sc->sc_enaddr[4] = (*p++ << 4);
    202       1.1    tsubai 	sc->sc_enaddr[4] |= *p++ & 0x0f;
    203       1.1    tsubai 	sc->sc_enaddr[5] = (*p++ << 4);
    204       1.1    tsubai 	sc->sc_enaddr[5] |= *p++ & 0x0f;
    205       1.1    tsubai 
    206       1.3  drochner 	sc->sc_copytodesc = lance_copytobuf_contig;
    207       1.3  drochner 	sc->sc_copyfromdesc = lance_copyfrombuf_contig;
    208       1.3  drochner 	sc->sc_copytobuf = lance_copytobuf_contig;
    209       1.3  drochner 	sc->sc_copyfrombuf = lance_copyfrombuf_contig;
    210       1.3  drochner 	sc->sc_zerobuf = lance_zerobuf_contig;
    211       1.1    tsubai 
    212       1.1    tsubai 	sc->sc_rdcsr = lerdcsr;
    213       1.1    tsubai 	sc->sc_wrcsr = lewrcsr;
    214       1.1    tsubai 	sc->sc_hwinit = NULL;
    215       1.1    tsubai 
    216       1.3  drochner 	am7990_config(&lesc->sc_am7990);
    217  1.3.14.1    bouyer 	hb_intr_establish(intlevel, IPL_NET, am7990_intr, sc);
    218       1.1    tsubai }
    219