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