Home | History | Annotate | Line # | Download | only in dev
if_le.c revision 1.13
      1  1.13   tsutsui /*	$NetBSD: if_le.c,v 1.13 2005/02/06 02:18:02 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.12     lukem 
     39  1.12     lukem #include <sys/cdefs.h>
     40  1.13   tsutsui __KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.13 2005/02/06 02:18:02 tsutsui Exp $");
     41   1.1    tsubai 
     42   1.2  jonathan #include "opt_inet.h"
     43   1.1    tsubai #include "bpfilter.h"
     44   1.1    tsubai 
     45   1.1    tsubai #include <sys/param.h>
     46   1.1    tsubai #include <sys/systm.h>
     47   1.1    tsubai #include <sys/mbuf.h>
     48   1.1    tsubai #include <sys/syslog.h>
     49   1.1    tsubai #include <sys/socket.h>
     50   1.1    tsubai #include <sys/device.h>
     51   1.1    tsubai 
     52   1.1    tsubai #include <net/if.h>
     53   1.1    tsubai #include <net/if_ether.h>
     54   1.1    tsubai #include <net/if_media.h>
     55   1.1    tsubai 
     56   1.1    tsubai #ifdef INET
     57   1.1    tsubai #include <netinet/in.h>
     58   1.1    tsubai #include <netinet/if_inarp.h>
     59   1.1    tsubai #endif
     60   1.1    tsubai 
     61   1.1    tsubai #include <machine/cpu.h>
     62   1.1    tsubai #include <machine/adrsmap.h>
     63   1.1    tsubai 
     64   1.3  drochner #include <dev/ic/lancereg.h>
     65   1.3  drochner #include <dev/ic/lancevar.h>
     66   1.1    tsubai #include <dev/ic/am7990reg.h>
     67   1.1    tsubai #include <dev/ic/am7990var.h>
     68   1.1    tsubai 
     69  1.10   tsutsui #include <newsmips/dev/hbvar.h>
     70  1.10   tsutsui 
     71   1.1    tsubai /*
     72   1.1    tsubai  * LANCE registers.
     73   1.1    tsubai  * The real stuff is in dev/ic/am7990reg.h
     74   1.1    tsubai  */
     75   1.1    tsubai struct lereg1 {
     76  1.13   tsutsui 	volatile uint16_t	ler1_rdp;	/* data port */
     77  1.13   tsutsui 	volatile uint16_t	ler1_rap;	/* register select port */
     78   1.1    tsubai };
     79   1.1    tsubai 
     80   1.1    tsubai /*
     81   1.1    tsubai  * Ethernet software status per interface.
     82   1.1    tsubai  * The real stuff is in dev/ic/am7990var.h
     83   1.1    tsubai  */
     84   1.1    tsubai struct	le_softc {
     85   1.1    tsubai 	struct	am7990_softc sc_am7990;	/* glue to MI code */
     86   1.1    tsubai 
     87   1.1    tsubai 	struct	lereg1 *sc_r1;		/* LANCE registers */
     88   1.1    tsubai };
     89   1.1    tsubai 
     90  1.13   tsutsui static int	le_match(struct device *, struct cfdata *, void *);
     91  1.13   tsutsui static void	le_attach(struct device *, struct device *, void *);
     92   1.1    tsubai 
     93   1.9   thorpej CFATTACH_DECL(le, sizeof(struct le_softc),
     94   1.9   thorpej     le_match, le_attach, NULL, NULL);
     95   1.1    tsubai 
     96   1.7       mrg #if defined(_KERNEL_OPT)
     97   1.3  drochner #include "opt_ddb.h"
     98   1.3  drochner #endif
     99   1.3  drochner 
    100   1.3  drochner #ifdef DDB
    101   1.3  drochner #define	integrate
    102   1.3  drochner #define hide
    103   1.3  drochner #else
    104   1.3  drochner #define	integrate	static __inline
    105   1.3  drochner #define hide		static
    106   1.3  drochner #endif
    107   1.3  drochner 
    108  1.13   tsutsui hide void lewrcsr(struct lance_softc *, uint16_t, uint16_t);
    109  1.13   tsutsui hide uint16_t lerdcsr(struct lance_softc *, uint16_t);
    110   1.1    tsubai 
    111   1.1    tsubai hide void
    112  1.13   tsutsui lewrcsr(struct lance_softc *sc, uint16_t port, uint16_t val)
    113   1.1    tsubai {
    114  1.13   tsutsui 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    115   1.1    tsubai 
    116   1.1    tsubai 	ler1->ler1_rap = port;
    117   1.1    tsubai 	ler1->ler1_rdp = val;
    118   1.1    tsubai }
    119   1.1    tsubai 
    120  1.13   tsutsui hide uint16_t
    121  1.13   tsutsui lerdcsr(struct lance_softc *sc, uint16_t port)
    122   1.1    tsubai {
    123  1.13   tsutsui 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    124  1.13   tsutsui 	uint16_t val;
    125   1.1    tsubai 
    126   1.1    tsubai 	ler1->ler1_rap = port;
    127   1.1    tsubai 	val = ler1->ler1_rdp;
    128  1.13   tsutsui 	return val;
    129   1.1    tsubai }
    130   1.1    tsubai 
    131   1.1    tsubai int
    132  1.13   tsutsui le_match(struct device *parent, struct cfdata *cf, void *aux)
    133   1.1    tsubai {
    134  1.10   tsutsui 	struct hb_attach_args *ha = aux;
    135   1.1    tsubai 
    136  1.10   tsutsui 	if (strcmp(ha->ha_name, "le"))
    137   1.1    tsubai 		return 0;
    138   1.1    tsubai 
    139  1.10   tsutsui 	if (hb_badaddr((void *)ha->ha_addr, 1)) /* XXX */
    140   1.1    tsubai 		return 0;
    141   1.1    tsubai 
    142   1.1    tsubai 	return 1;
    143   1.1    tsubai }
    144   1.1    tsubai 
    145   1.1    tsubai void
    146  1.13   tsutsui le_attach(struct device *parent, struct device *self, void *aux)
    147   1.1    tsubai {
    148   1.1    tsubai 	struct le_softc *lesc = (struct le_softc *)self;
    149   1.3  drochner 	struct lance_softc *sc = &lesc->sc_am7990.lsc;
    150  1.10   tsutsui 	struct hb_attach_args *ha = aux;
    151  1.11   tsutsui 	int intlevel, intmask;
    152   1.1    tsubai 	u_char *p;
    153   1.1    tsubai 
    154  1.10   tsutsui 	intlevel = ha->ha_level;
    155   1.5    tsubai 	if (intlevel == -1) {
    156   1.5    tsubai 		printf(": interrupt level not configured\n");
    157   1.5    tsubai 		return;
    158   1.5    tsubai 	}
    159   1.5    tsubai 	printf(" level %d", intlevel);
    160   1.5    tsubai 
    161  1.10   tsutsui 	switch (ha->ha_addr) {
    162   1.1    tsubai 
    163   1.6    tsubai 	case LANCE_PORT:
    164   1.1    tsubai 		sc->sc_mem = (void *)LANCE_MEMORY;
    165  1.13   tsutsui 		p = (u_char *)(ETHER_ID + 16);
    166  1.11   tsutsui 		intmask = INTST1_LANCE;
    167   1.1    tsubai 		break;
    168   1.6    tsubai 	case LANCE_PORT1:
    169   1.1    tsubai 		sc->sc_mem = (void *)LANCE_MEMORY1;
    170  1.13   tsutsui 		p = (u_char *)(ETHER_ID1 + 16);
    171  1.11   tsutsui 		intmask = INTST1_SLOT3; /* XXX not tested */
    172   1.1    tsubai 		break;
    173   1.6    tsubai 	case LANCE_PORT2:
    174   1.1    tsubai 		sc->sc_mem = (void *)LANCE_MEMORY2;
    175  1.13   tsutsui 		p = (u_char *)(ETHER_ID2 + 16);
    176  1.11   tsutsui 		intmask = INTST1_SLOT3; /* XXX not tested */
    177   1.1    tsubai 		break;
    178   1.1    tsubai 
    179   1.1    tsubai 	default:
    180   1.6    tsubai 		printf(": unknown LANCE addr\n");
    181   1.6    tsubai 		return;
    182   1.1    tsubai 	}
    183   1.1    tsubai 
    184  1.10   tsutsui 	lesc->sc_r1 = (void *)ha->ha_addr;
    185   1.6    tsubai 
    186   1.1    tsubai 	sc->sc_memsize = 0x4000;	/* 16K */
    187   1.1    tsubai 	sc->sc_addr = (int)sc->sc_mem & 0x00ffffff;
    188   1.1    tsubai 	sc->sc_conf3 = LE_C3_BSWP|LE_C3_BCON;
    189   1.1    tsubai 
    190   1.1    tsubai 	sc->sc_enaddr[0] = (*p++ << 4);
    191   1.1    tsubai 	sc->sc_enaddr[0] |= *p++ & 0x0f;
    192   1.1    tsubai 	sc->sc_enaddr[1] = (*p++ << 4);
    193   1.1    tsubai 	sc->sc_enaddr[1] |= *p++ & 0x0f;
    194   1.1    tsubai 	sc->sc_enaddr[2] = (*p++ << 4);
    195   1.1    tsubai 	sc->sc_enaddr[2] |= *p++ & 0x0f;
    196   1.1    tsubai 	sc->sc_enaddr[3] = (*p++ << 4);
    197   1.1    tsubai 	sc->sc_enaddr[3] |= *p++ & 0x0f;
    198   1.1    tsubai 	sc->sc_enaddr[4] = (*p++ << 4);
    199   1.1    tsubai 	sc->sc_enaddr[4] |= *p++ & 0x0f;
    200   1.1    tsubai 	sc->sc_enaddr[5] = (*p++ << 4);
    201   1.1    tsubai 	sc->sc_enaddr[5] |= *p++ & 0x0f;
    202   1.1    tsubai 
    203   1.3  drochner 	sc->sc_copytodesc = lance_copytobuf_contig;
    204   1.3  drochner 	sc->sc_copyfromdesc = lance_copyfrombuf_contig;
    205   1.3  drochner 	sc->sc_copytobuf = lance_copytobuf_contig;
    206   1.3  drochner 	sc->sc_copyfrombuf = lance_copyfrombuf_contig;
    207   1.3  drochner 	sc->sc_zerobuf = lance_zerobuf_contig;
    208   1.1    tsubai 
    209   1.1    tsubai 	sc->sc_rdcsr = lerdcsr;
    210   1.1    tsubai 	sc->sc_wrcsr = lewrcsr;
    211   1.1    tsubai 	sc->sc_hwinit = NULL;
    212   1.1    tsubai 
    213   1.3  drochner 	am7990_config(&lesc->sc_am7990);
    214  1.11   tsutsui 	hb_intr_establish(intlevel, intmask, IPL_NET, am7990_intr, sc);
    215   1.1    tsubai }
    216