if_le.c revision 1.11       1  1.11   tsutsui /*	$NetBSD: if_le.c,v 1.11 2003/05/10 09:46:25 tsutsui 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/cpu.h>
     59   1.1    tsubai #include <machine/adrsmap.h>
     60   1.1    tsubai 
     61   1.3  drochner #include <dev/ic/lancereg.h>
     62   1.3  drochner #include <dev/ic/lancevar.h>
     63   1.1    tsubai #include <dev/ic/am7990reg.h>
     64   1.1    tsubai #include <dev/ic/am7990var.h>
     65   1.1    tsubai 
     66  1.10   tsutsui #include <newsmips/dev/hbvar.h>
     67  1.10   tsutsui 
     68   1.1    tsubai /*
     69   1.1    tsubai  * LANCE registers.
     70   1.1    tsubai  * The real stuff is in dev/ic/am7990reg.h
     71   1.1    tsubai  */
     72   1.1    tsubai struct lereg1 {
     73   1.1    tsubai 	volatile u_int16_t	ler1_rdp;	/* data port */
     74   1.1    tsubai 	volatile u_int16_t	ler1_rap;	/* register select port */
     75   1.1    tsubai };
     76   1.1    tsubai 
     77   1.1    tsubai /*
     78   1.1    tsubai  * Ethernet software status per interface.
     79   1.1    tsubai  * The real stuff is in dev/ic/am7990var.h
     80   1.1    tsubai  */
     81   1.1    tsubai struct	le_softc {
     82   1.1    tsubai 	struct	am7990_softc sc_am7990;	/* glue to MI code */
     83   1.1    tsubai 
     84   1.1    tsubai 	struct	lereg1 *sc_r1;		/* LANCE registers */
     85   1.1    tsubai };
     86   1.1    tsubai 
     87   1.1    tsubai static int	le_match __P((struct device *, struct cfdata *, void *));
     88   1.1    tsubai static void	le_attach __P((struct device *, struct device *, void *));
     89   1.1    tsubai 
     90   1.9   thorpej CFATTACH_DECL(le, sizeof(struct le_softc),
     91   1.9   thorpej     le_match, le_attach, NULL, NULL);
     92   1.1    tsubai 
     93   1.7       mrg #if defined(_KERNEL_OPT)
     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.10   tsutsui 	struct hb_attach_args *ha = aux;
    139   1.1    tsubai 
    140  1.10   tsutsui 	if (strcmp(ha->ha_name, "le"))
    141   1.1    tsubai 		return 0;
    142   1.1    tsubai 
    143  1.10   tsutsui 	if (hb_badaddr((void *)ha->ha_addr, 1)) /* XXX */
    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.10   tsutsui 	struct hb_attach_args *ha = aux;
    157  1.11   tsutsui 	int intlevel, intmask;
    158   1.1    tsubai 	u_char *p;
    159   1.1    tsubai 
    160  1.10   tsutsui 	intlevel = ha->ha_level;
    161   1.5    tsubai 	if (intlevel == -1) {
    162   1.5    tsubai 		printf(": interrupt level not configured\n");
    163   1.5    tsubai 		return;
    164   1.5    tsubai 	}
    165   1.5    tsubai 	printf(" level %d", intlevel);
    166   1.5    tsubai 
    167  1.10   tsutsui 	switch (ha->ha_addr) {
    168   1.1    tsubai 
    169   1.6    tsubai 	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.11   tsutsui 		intmask = INTST1_LANCE;
    173   1.1    tsubai 		break;
    174   1.6    tsubai 	case LANCE_PORT1:
    175   1.1    tsubai 		sc->sc_mem = (void *)LANCE_MEMORY1;
    176   1.1    tsubai 		p = (u_char *)(ETHER_ID1+16);
    177  1.11   tsutsui 		intmask = INTST1_SLOT3; /* XXX not tested */
    178   1.1    tsubai 		break;
    179   1.6    tsubai 	case LANCE_PORT2:
    180   1.1    tsubai 		sc->sc_mem = (void *)LANCE_MEMORY2;
    181   1.1    tsubai 		p = (u_char *)(ETHER_ID2+16);
    182  1.11   tsutsui 		intmask = INTST1_SLOT3; /* XXX not tested */
    183   1.1    tsubai 		break;
    184   1.1    tsubai 
    185   1.1    tsubai 	default:
    186   1.6    tsubai 		printf(": unknown LANCE addr\n");
    187   1.6    tsubai 		return;
    188   1.1    tsubai 	}
    189   1.1    tsubai 
    190  1.10   tsutsui 	lesc->sc_r1 = (void *)ha->ha_addr;
    191   1.6    tsubai 
    192   1.1    tsubai 	sc->sc_memsize = 0x4000;	/* 16K */
    193   1.1    tsubai 	sc->sc_addr = (int)sc->sc_mem & 0x00ffffff;
    194   1.1    tsubai 	sc->sc_conf3 = LE_C3_BSWP|LE_C3_BCON;
    195   1.1    tsubai 
    196   1.1    tsubai 	sc->sc_enaddr[0] = (*p++ << 4);
    197   1.1    tsubai 	sc->sc_enaddr[0] |= *p++ & 0x0f;
    198   1.1    tsubai 	sc->sc_enaddr[1] = (*p++ << 4);
    199   1.1    tsubai 	sc->sc_enaddr[1] |= *p++ & 0x0f;
    200   1.1    tsubai 	sc->sc_enaddr[2] = (*p++ << 4);
    201   1.1    tsubai 	sc->sc_enaddr[2] |= *p++ & 0x0f;
    202   1.1    tsubai 	sc->sc_enaddr[3] = (*p++ << 4);
    203   1.1    tsubai 	sc->sc_enaddr[3] |= *p++ & 0x0f;
    204   1.1    tsubai 	sc->sc_enaddr[4] = (*p++ << 4);
    205   1.1    tsubai 	sc->sc_enaddr[4] |= *p++ & 0x0f;
    206   1.1    tsubai 	sc->sc_enaddr[5] = (*p++ << 4);
    207   1.1    tsubai 	sc->sc_enaddr[5] |= *p++ & 0x0f;
    208   1.1    tsubai 
    209   1.3  drochner 	sc->sc_copytodesc = lance_copytobuf_contig;
    210   1.3  drochner 	sc->sc_copyfromdesc = lance_copyfrombuf_contig;
    211   1.3  drochner 	sc->sc_copytobuf = lance_copytobuf_contig;
    212   1.3  drochner 	sc->sc_copyfrombuf = lance_copyfrombuf_contig;
    213   1.3  drochner 	sc->sc_zerobuf = lance_zerobuf_contig;
    214   1.1    tsubai 
    215   1.1    tsubai 	sc->sc_rdcsr = lerdcsr;
    216   1.1    tsubai 	sc->sc_wrcsr = lewrcsr;
    217   1.1    tsubai 	sc->sc_hwinit = NULL;
    218   1.1    tsubai 
    219   1.3  drochner 	am7990_config(&lesc->sc_am7990);
    220  1.11   tsutsui 	hb_intr_establish(intlevel, intmask, IPL_NET, am7990_intr, sc);
    221   1.1    tsubai }
    222