Home | History | Annotate | Line # | Download | only in dev
if_le.c revision 1.13
      1 /*	$NetBSD: if_le.c,v 1.13 2005/06/02 15:26:35 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.13 2005/06/02 15:26:35 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 uint16_t	ler1_rdp;	/* data port */
     81 	volatile uint16_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 const uint8_t *idrom_addr;
    101 extern uint32_t lance_mem_phys;
    102 
    103 #if defined(_KERNEL_OPT)
    104 #include "opt_ddb.h"
    105 #endif
    106 
    107 #ifdef DDB
    108 #define	integrate
    109 #define hide
    110 #else
    111 #define	integrate	static __inline
    112 #define hide		static
    113 #endif
    114 
    115 hide void lewrcsr(struct lance_softc *, uint16_t, uint16_t);
    116 hide uint16_t lerdcsr(struct lance_softc *, uint16_t);
    117 int leintr(int);
    118 
    119 hide void
    120 lewrcsr(struct lance_softc *sc, uint16_t port, uint16_t val)
    121 {
    122 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    123 
    124 	ler1->ler1_rap = port;
    125 	ler1->ler1_rdp = val;
    126 }
    127 
    128 hide uint16_t
    129 lerdcsr(struct lance_softc *sc, uint16_t port)
    130 {
    131 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    132 	uint16_t val;
    133 
    134 	ler1->ler1_rap = port;
    135 	val = ler1->ler1_rdp;
    136 	return val;
    137 }
    138 
    139 int
    140 le_match(struct device *parent, struct cfdata *cf, void *aux)
    141 {
    142 	struct hb_attach_args *ha = aux;
    143 	int addr;
    144 
    145 	if (strcmp(ha->ha_name, "le"))
    146 		return 0;
    147 
    148 	addr = IIOV(ha->ha_address);
    149 
    150 	if (badaddr((void *)addr, 1))
    151 		return 0;
    152 
    153 	return 1;
    154 }
    155 
    156 void
    157 le_attach(struct device *parent, struct device *self, void *aux)
    158 {
    159 	struct le_softc *lesc = (struct le_softc *)self;
    160 	struct lance_softc *sc = &lesc->sc_am7990.lsc;
    161 	struct hb_attach_args *ha = aux;
    162 	const uint8_t *p;
    163 
    164 	lesc->sc_r1 = (void *)IIOV(ha->ha_address);
    165 
    166 	if (ISIIOPA(ha->ha_address)) {
    167 		sc->sc_mem = (u_char *)IIOV(lance_mem_phys);
    168 		p = idrom_addr + 0x10;
    169 	} else {
    170 		sc->sc_mem = lesc->sc_r1 - 0x10000;
    171 		p = (const uint8_t *)(lesc->sc_r1 + 0x8010);
    172 	}
    173 
    174 	sc->sc_memsize = 0x4000;	/* 16K */
    175 	sc->sc_addr = lance_mem_phys & 0x00ffffff;
    176 	sc->sc_conf3 = LE_C3_BSWP|LE_C3_BCON;
    177 
    178 	sc->sc_enaddr[0] = (*p++ << 4);
    179 	sc->sc_enaddr[0] |= *p++ & 0x0f;
    180 	sc->sc_enaddr[1] = (*p++ << 4);
    181 	sc->sc_enaddr[1] |= *p++ & 0x0f;
    182 	sc->sc_enaddr[2] = (*p++ << 4);
    183 	sc->sc_enaddr[2] |= *p++ & 0x0f;
    184 	sc->sc_enaddr[3] = (*p++ << 4);
    185 	sc->sc_enaddr[3] |= *p++ & 0x0f;
    186 	sc->sc_enaddr[4] = (*p++ << 4);
    187 	sc->sc_enaddr[4] |= *p++ & 0x0f;
    188 	sc->sc_enaddr[5] = (*p++ << 4);
    189 	sc->sc_enaddr[5] |= *p++ & 0x0f;
    190 
    191 	sc->sc_copytodesc = lance_copytobuf_contig;
    192 	sc->sc_copyfromdesc = lance_copyfrombuf_contig;
    193 	sc->sc_copytobuf = lance_copytobuf_contig;
    194 	sc->sc_copyfrombuf = lance_copyfrombuf_contig;
    195 	sc->sc_zerobuf = lance_zerobuf_contig;
    196 
    197 	sc->sc_rdcsr = lerdcsr;
    198 	sc->sc_wrcsr = lewrcsr;
    199 	sc->sc_hwinit = NULL;
    200 
    201 	am7990_config(&lesc->sc_am7990);
    202 }
    203 
    204 int
    205 leintr(int unit)
    206 {
    207 	struct am7990_softc *sc;
    208 
    209 	if (unit >= le_cd.cd_ndevs)
    210 		return 0;
    211 
    212 	sc = le_cd.cd_devs[unit];
    213 	return am7990_intr(sc);
    214 }
    215