Home | History | Annotate | Line # | Download | only in dev
if_le.c revision 1.9
      1 /*	$NetBSD: if_le.c,v 1.9 2004/09/04 11:30:39 tsutsui 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  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * news68k/dev/if_le.c - based on newsmips/dev/if_le.c
     41  */
     42 
     43 #include <sys/cdefs.h>
     44 __KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.9 2004/09/04 11:30:39 tsutsui Exp $");
     45 
     46 #include "opt_inet.h"
     47 #include "bpfilter.h"
     48 
     49 #include <sys/param.h>
     50 #include <sys/systm.h>
     51 #include <sys/mbuf.h>
     52 #include <sys/socket.h>
     53 #include <sys/device.h>
     54 
     55 #include <net/if.h>
     56 #include <net/if_ether.h>
     57 #include <net/if_media.h>
     58 
     59 #ifdef INET
     60 #include <netinet/in.h>
     61 #include <netinet/if_inarp.h>
     62 #endif
     63 
     64 #include <machine/cpu.h>
     65 
     66 #include <news68k/dev/hbvar.h>
     67 
     68 #include <dev/ic/lancereg.h>
     69 #include <dev/ic/lancevar.h>
     70 #include <dev/ic/am7990reg.h>
     71 #include <dev/ic/am7990var.h>
     72 
     73 #include "ioconf.h"
     74 
     75 /*
     76  * LANCE registers.
     77  * The real stuff is in dev/ic/am7990reg.h
     78  */
     79 struct lereg1 {
     80 	volatile u_int16_t	ler1_rdp;	/* data port */
     81 	volatile u_int16_t	ler1_rap;	/* register select port */
     82 };
     83 
     84 /*
     85  * Ethernet software status per interface.
     86  * The real stuff is in dev/ic/am7990var.h
     87  */
     88 struct	le_softc {
     89 	struct	am7990_softc sc_am7990;	/* glue to MI code */
     90 
     91 	struct	lereg1 *sc_r1;		/* LANCE registers */
     92 };
     93 
     94 static int  le_match(struct device *, struct cfdata *, void *);
     95 static void le_attach(struct device *, struct device *, void *);
     96 
     97 CFATTACH_DECL(le, sizeof(struct le_softc),
     98     le_match, le_attach, NULL, NULL);
     99 
    100 extern volatile u_char *lance_mem, *idrom_addr;
    101 
    102 #if defined(_KERNEL_OPT)
    103 #include "opt_ddb.h"
    104 #endif
    105 
    106 #ifdef DDB
    107 #define	integrate
    108 #define hide
    109 #else
    110 #define	integrate	static __inline
    111 #define hide		static
    112 #endif
    113 
    114 hide void lewrcsr(struct lance_softc *, u_int16_t, u_int16_t);
    115 hide u_int16_t lerdcsr(struct lance_softc *, u_int16_t);
    116 int leintr(int);
    117 
    118 hide void
    119 lewrcsr(sc, port, val)
    120 	struct lance_softc *sc;
    121 	u_int16_t port, val;
    122 {
    123 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    124 
    125 	ler1->ler1_rap = port;
    126 	ler1->ler1_rdp = val;
    127 }
    128 
    129 hide u_int16_t
    130 lerdcsr(sc, port)
    131 	struct lance_softc *sc;
    132 	u_int16_t port;
    133 {
    134 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    135 	u_int16_t val;
    136 
    137 	ler1->ler1_rap = port;
    138 	val = ler1->ler1_rdp;
    139 	return (val);
    140 }
    141 
    142 int
    143 le_match(parent, cf, aux)
    144 	struct device *parent;
    145 	struct cfdata *cf;
    146 	void *aux;
    147 {
    148 	struct hb_attach_args *ha = aux;
    149 	int addr;
    150 
    151 	if (strcmp(ha->ha_name, "le"))
    152 		return 0;
    153 
    154 	addr = IIOV(ha->ha_address);
    155 
    156 	if (badaddr((void *)addr, 1))
    157 		return 0;
    158 
    159 	return 1;
    160 }
    161 
    162 void
    163 le_attach(parent, self, aux)
    164 	struct device *parent, *self;
    165 	void *aux;
    166 {
    167 	struct le_softc *lesc = (struct le_softc *)self;
    168 	struct lance_softc *sc = &lesc->sc_am7990.lsc;
    169 	struct hb_attach_args *ha = aux;
    170 	u_char *p;
    171 
    172 	lesc->sc_r1 = (void *)IIOV(ha->ha_address);
    173 
    174 	if (ISIIOPA(ha->ha_address)) {
    175 		sc->sc_mem = (u_char *)lance_mem;
    176 		p = (u_char *)(idrom_addr + 0x10);
    177 	} else {
    178 		sc->sc_mem = lesc->sc_r1 - 0x10000;
    179 		p = (u_char *)(lesc->sc_r1 + 0x8010);
    180 	}
    181 
    182 	sc->sc_memsize = 0x4000;	/* 16K */
    183 	sc->sc_addr = (int)sc->sc_mem & 0x00ffffff;
    184 	sc->sc_conf3 = LE_C3_BSWP|LE_C3_BCON;
    185 
    186 	sc->sc_enaddr[0] = (*p++ << 4);
    187 	sc->sc_enaddr[0] |= *p++ & 0x0f;
    188 	sc->sc_enaddr[1] = (*p++ << 4);
    189 	sc->sc_enaddr[1] |= *p++ & 0x0f;
    190 	sc->sc_enaddr[2] = (*p++ << 4);
    191 	sc->sc_enaddr[2] |= *p++ & 0x0f;
    192 	sc->sc_enaddr[3] = (*p++ << 4);
    193 	sc->sc_enaddr[3] |= *p++ & 0x0f;
    194 	sc->sc_enaddr[4] = (*p++ << 4);
    195 	sc->sc_enaddr[4] |= *p++ & 0x0f;
    196 	sc->sc_enaddr[5] = (*p++ << 4);
    197 	sc->sc_enaddr[5] |= *p++ & 0x0f;
    198 
    199 	sc->sc_copytodesc = lance_copytobuf_contig;
    200 	sc->sc_copyfromdesc = lance_copyfrombuf_contig;
    201 	sc->sc_copytobuf = lance_copytobuf_contig;
    202 	sc->sc_copyfrombuf = lance_copyfrombuf_contig;
    203 	sc->sc_zerobuf = lance_zerobuf_contig;
    204 
    205 	sc->sc_rdcsr = lerdcsr;
    206 	sc->sc_wrcsr = lewrcsr;
    207 	sc->sc_hwinit = NULL;
    208 
    209 	am7990_config(&lesc->sc_am7990);
    210 }
    211 
    212 int
    213 leintr(unit)
    214 	int unit;
    215 {
    216 	struct am7990_softc *sc;
    217 
    218 	if (unit >= le_cd.cd_ndevs)
    219 		return 0;
    220 
    221 	sc = le_cd.cd_devs[unit];
    222 	return am7990_intr(sc);
    223 }
    224