Home | History | Annotate | Line # | Download | only in if
if_le.c revision 1.12
      1 /*	$NetBSD: if_le.c,v 1.12 1998/07/21 17:36:05 drochner Exp $	*/
      2 
      3 /* #define LE_CHIP_IS_POKEY	/* does VS2000 need this ??? */
      4 
      5 /*-
      6  * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
      7  * Copyright (c) 1992, 1993
      8  *	The Regents of the University of California.  All rights reserved.
      9  *
     10  * This code is derived from software contributed to Berkeley by
     11  * Ralph Campbell and Rick Macklem.
     12  *
     13  * Redistribution and use in source and binary forms, with or without
     14  * modification, are permitted provided that the following conditions
     15  * are met:
     16  * 1. Redistributions of source code must retain the above copyright
     17  *    notice, this list of conditions and the following disclaimer.
     18  * 2. Redistributions in binary form must reproduce the above copyright
     19  *    notice, this list of conditions and the following disclaimer in the
     20  *    documentation and/or other materials provided with the distribution.
     21  * 3. All advertising materials mentioning features or use of this software
     22  *    must display the following acknowledgement:
     23  *	This product includes software developed by the University of
     24  *	California, Berkeley and its contributors.
     25  * 4. Neither the name of the University nor the names of its contributors
     26  *    may be used to endorse or promote products derived from this software
     27  *    without specific prior written permission.
     28  *
     29  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     30  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     31  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     32  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     33  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     34  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     35  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     37  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     38  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     39  * SUCH DAMAGE.
     40  *
     41  *	@(#)if_le.c	8.2 (Berkeley) 11/16/93
     42  */
     43 
     44 #include "opt_inet.h"
     45 #include "bpfilter.h"
     46 
     47 #include <sys/param.h>
     48 #include <sys/syslog.h>
     49 #include <sys/socket.h>
     50 #include <sys/device.h>
     51 #include <sys/reboot.h>
     52 
     53 #include <net/if.h>
     54 #include <net/if_ether.h>
     55 #include <net/if_media.h>
     56 
     57 #if INET
     58 #include <netinet/in.h>
     59 #include <netinet/if_inarp.h>
     60 #endif
     61 
     62 /*
     63  * This would be nice, but it's not yet there...
     64  *
     65  * #include <machine/autoconf.h>
     66  */
     67 
     68 #include <machine/pte.h>
     69 #include <machine/cpu.h>
     70 #include <machine/mtpr.h>
     71 #include <machine/uvax.h>
     72 #include <machine/ka410.h>
     73 #include <machine/vsbus.h>
     74 #include <machine/rpb.h>
     75 
     76 #include <dev/ic/lancereg.h>
     77 #include <dev/ic/lancevar.h>
     78 #include <dev/ic/am7990reg.h>
     79 #define LE_NEED_BUF_CONTIG
     80 #include <dev/ic/am7990var.h>
     81 
     82 #include <dev/tc/if_levar.h>
     83 
     84 #define xdebug(x)
     85 
     86 #ifdef LE_CHIP_IS_POKEY
     87 /*
     88  * access LANCE registers and double-check their contents
     89  */
     90 #define wbflush()	/* do nothing */
     91 void lewritereg();
     92 #define LERDWR(cntl, src, dst)	{ (dst) = (src); wbflush(); }
     93 #define LEWREG(src, dst)	lewritereg(&(dst), (src))
     94 #endif
     95 
     96 #define LE_IOSIZE 64*1024	/* 64K of real-mem are reserved and already */
     97 extern void *le_iomem;		/* mapped into virt-mem by cpu_steal_pages */
     98 extern u_long le_ioaddr;	/* le_iomem is virt, le_ioaddr is phys */
     99 
    100 #define LE_SOFTC(unit)	le_cd.cd_devs[unit]
    101 #define LE_DELAY(x)	DELAY(x)
    102 
    103 int lematch __P((struct device *, struct cfdata *, void *));
    104 void leattach __P((struct device *, struct device *, void *));
    105 
    106 int leintr __P((void *sc));
    107 
    108 struct cfattach le_ca = {
    109 	sizeof(struct le_softc), lematch, leattach
    110 };
    111 
    112 extern struct cfdriver le_cd;
    113 
    114 #if defined(_KERNEL) && !defined(_LKM)
    115 #include "opt_ddb.h"
    116 #endif
    117 
    118 #ifdef DDB
    119 #define	integrate
    120 #define hide
    121 #else
    122 #define	integrate	static __inline
    123 #define hide		static
    124 #endif
    125 
    126 hide void lewrcsr __P ((struct lance_softc *, u_int16_t, u_int16_t));
    127 hide u_int16_t lerdcsr __P ((struct lance_softc *, u_int16_t));
    128 
    129 hide void
    130 lewrcsr(sc, port, val)
    131 	struct lance_softc *sc;
    132 	u_int16_t port, val;
    133 {
    134 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    135 
    136 #ifdef LE_CHIP_IS_POKEY
    137 	LEWREG(port, ler1->ler1_rap);
    138 	LERDWR(port, val, ler1->ler1_rdp);
    139 #else
    140 	ler1->ler1_rap = port;
    141 	ler1->ler1_rdp = val;
    142 #endif
    143 }
    144 
    145 hide u_int16_t
    146 lerdcsr(sc, port)
    147 	struct lance_softc *sc;
    148 	u_int16_t port;
    149 {
    150 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    151 	u_int16_t val;
    152 
    153 #ifdef LE_CHIP_IS_POKEY
    154 	LEWREG(port, ler1->ler1_rap);
    155 	LERDWR(0, ler1->ler1_rdp, val);
    156 #else
    157 	ler1->ler1_rap = port;
    158 	val = ler1->ler1_rdp;
    159 #endif
    160 	return (val);
    161 }
    162 
    163 integrate void
    164 lehwinit(sc)
    165 	struct lance_softc *sc;
    166 {
    167 }
    168 
    169 int
    170 lematch(parent, cf, aux)
    171 	struct device *parent;
    172 	struct cfdata *cf;
    173 	void *aux;
    174 {
    175 	struct confargs *ca = aux;
    176 
    177 	/*
    178 	 * There could/should be more checks, but for now...
    179 	 */
    180 	if (strcmp(ca->ca_name, "le") &&
    181 	    strcmp(ca->ca_name, "am7990") &&
    182 	    strcmp(ca->ca_name, "AM7990"))
    183 		return (0);
    184 
    185 	return (1);
    186 }
    187 
    188 /*
    189  *
    190  */
    191 void
    192 leattach(parent, self, aux)
    193 	struct device *parent, *self;
    194 	void *aux;
    195 {
    196 	register struct le_softc *sc = (void *)self;
    197 	struct confargs *ca = aux;
    198 	u_char *cp;	/* pointer to MAC address */
    199 	int i;
    200 
    201 	sc->sc_r1  = (void*)uvax_phys2virt(ca->ca_ioaddr);
    202 
    203 	sc->sc_am7990.lsc.sc_conf3 = 0;
    204 	sc->sc_am7990.lsc.sc_mem = le_iomem;
    205 	sc->sc_am7990.lsc.sc_addr = le_ioaddr;
    206 	sc->sc_am7990.lsc.sc_memsize = LE_IOSIZE;
    207 	sc->sc_am7990.lsc.sc_wrcsr = lewrcsr;
    208 	sc->sc_am7990.lsc.sc_rdcsr = lerdcsr;
    209 	sc->sc_am7990.lsc.sc_hwinit = lehwinit;
    210 	sc->sc_am7990.lsc.sc_nocarrier = NULL;
    211 
    212 	xdebug(("leattach: mem=%x, addr=%x, size=%x (%d)\n",
    213 	    sc->sc_am7990.lsc.sc_mem, sc->sc_am7990.lsc.sc_addr,
    214 	    sc->sc_am7990.lsc.sc_memsize, sc->sc_am7990.lsc.sc_memsize));
    215 
    216 	sc->sc_am7990.lsc.sc_copytodesc = lance_copytobuf_contig;
    217 	sc->sc_am7990.lsc.sc_copyfromdesc = lance_copyfrombuf_contig;
    218 	sc->sc_am7990.lsc.sc_copytobuf = lance_copytobuf_contig;
    219 	sc->sc_am7990.lsc.sc_copyfrombuf = lance_copyfrombuf_contig;
    220 	sc->sc_am7990.lsc.sc_zerobuf = lance_zerobuf_contig;
    221 
    222 	/*
    223 	 * Get the ethernet address out of rom
    224 	 */
    225 	for (i = 0; i < sizeof(sc->sc_am7990.lsc.sc_enaddr); i++) {
    226 		int *eaddr = (void*)uvax_phys2virt(ca->ca_enaddr);
    227 		sc->sc_am7990.lsc.sc_enaddr[i] = (u_char)eaddr[i];
    228 	}
    229 
    230 	bcopy(self->dv_xname, sc->sc_am7990.lsc.sc_ethercom.ec_if.if_xname,
    231 	    IFNAMSIZ);
    232 	am7990_config(&sc->sc_am7990);
    233 
    234 #ifdef LEDEBUG
    235 	sc->sc_am7990.lsc.sc_debug = LEDEBUG;
    236 #endif
    237 
    238 	vsbus_intr_register(ca, am7990_intr, &sc->sc_am7990);
    239 	vsbus_intr_enable(ca);
    240 
    241 	/*
    242 	 * Register this device as boot device if we booted from it.
    243 	 * This will fail if there are more than one le in a machine,
    244 	 * fortunately there may be only one.
    245 	 */
    246 	if (B_TYPE(bootdev) == BDEV_LE)
    247 		booted_from = self;
    248 }
    249 
    250 #ifdef LE_CHIP_IS_POKEY
    251 /*
    252  * Write a lance register port, reading it back to ensure success. This seems
    253  * to be necessary during initialization, since the chip appears to be a bit
    254  * pokey sometimes.
    255  */
    256 void
    257 lewritereg(regptr, val)
    258 	register volatile u_short *regptr;
    259 	register u_short val;
    260 {
    261 	register int i = 0;
    262 
    263 	while (*regptr != val) {
    264 		*regptr = val;
    265 		wbflush();
    266 		if (++i > 10000) {
    267 			printf("le: Reg did not settle (to x%x): x%x\n", val,
    268 			    *regptr);
    269 			return;
    270 		}
    271 		DELAY(100);
    272 	}
    273 }
    274 #endif
    275