Home | History | Annotate | Line # | Download | only in if
if_le.c revision 1.9
      1 /*	$NetBSD: if_le.c,v 1.9 1998/01/12 20:52:34 thorpej 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 "bpfilter.h"
     45 
     46 #include <sys/param.h>
     47 #include <sys/syslog.h>
     48 #include <sys/socket.h>
     49 #include <sys/device.h>
     50 #include <sys/reboot.h>
     51 
     52 #include <net/if.h>
     53 #include <net/if_ether.h>
     54 #include <net/if_media.h>
     55 
     56 #if INET
     57 #include <netinet/in.h>
     58 #include <netinet/if_inarp.h>
     59 #endif
     60 
     61 /*
     62  * This would be nice, but it's not yet there...
     63  *
     64  * #include <machine/autoconf.h>
     65  */
     66 
     67 #include <machine/pte.h>
     68 #include <machine/cpu.h>
     69 #include <machine/mtpr.h>
     70 #include <machine/uvax.h>
     71 #include <machine/ka410.h>
     72 #include <machine/vsbus.h>
     73 #include <machine/rpb.h>
     74 
     75 #include <dev/ic/am7990reg.h>
     76 #define LE_NEED_BUF_CONTIG
     77 #include <dev/ic/am7990var.h>
     78 
     79 #include <dev/tc/if_levar.h>
     80 
     81 #define xdebug(x)
     82 
     83 #ifdef LE_CHIP_IS_POKEY
     84 /*
     85  * access LANCE registers and double-check their contents
     86  */
     87 #define wbflush()	/* do nothing */
     88 void lewritereg();
     89 #define LERDWR(cntl, src, dst)	{ (dst) = (src); wbflush(); }
     90 #define LEWREG(src, dst)	lewritereg(&(dst), (src))
     91 #endif
     92 
     93 #define LE_IOSIZE 64*1024	/* 64K of real-mem are reserved and already */
     94 extern void *le_iomem;		/* mapped into virt-mem by cpu_steal_pages */
     95 extern u_long le_ioaddr;	/* le_iomem is virt, le_ioaddr is phys */
     96 
     97 #define LE_SOFTC(unit)	le_cd.cd_devs[unit]
     98 #define LE_DELAY(x)	DELAY(x)
     99 
    100 int lematch __P((struct device *, void *, void *));
    101 void leattach __P((struct device *, struct device *, void *));
    102 
    103 int leintr __P((void *sc));
    104 
    105 struct cfattach le_ca = {
    106 	sizeof(struct le_softc), lematch, leattach
    107 };
    108 
    109 extern struct cfdriver le_cd;
    110 
    111 hide void lewrcsr __P ((struct am7990_softc *, u_int16_t, u_int16_t));
    112 hide u_int16_t lerdcsr __P ((struct am7990_softc *, u_int16_t));
    113 
    114 hide void
    115 lewrcsr(sc, port, val)
    116 	struct am7990_softc *sc;
    117 	u_int16_t port, val;
    118 {
    119 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    120 
    121 #ifdef LE_CHIP_IS_POKEY
    122 	LEWREG(port, ler1->ler1_rap);
    123 	LERDWR(port, val, ler1->ler1_rdp);
    124 #else
    125 	ler1->ler1_rap = port;
    126 	ler1->ler1_rdp = val;
    127 #endif
    128 }
    129 
    130 hide u_int16_t
    131 lerdcsr(sc, port)
    132 	struct am7990_softc *sc;
    133 	u_int16_t port;
    134 {
    135 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    136 	u_int16_t val;
    137 
    138 #ifdef LE_CHIP_IS_POKEY
    139 	LEWREG(port, ler1->ler1_rap);
    140 	LERDWR(0, ler1->ler1_rdp, val);
    141 #else
    142 	ler1->ler1_rap = port;
    143 	val = ler1->ler1_rdp;
    144 #endif
    145 	return (val);
    146 }
    147 
    148 integrate void
    149 lehwinit(sc)
    150 	struct am7990_softc *sc;
    151 {
    152 }
    153 
    154 int
    155 lematch(parent, match, aux)
    156 	struct device *parent;
    157 	void *match, *aux;
    158 {
    159 	struct cfdata *cf = match;
    160 	struct confargs *ca = aux;
    161 
    162 	/*
    163 	 * There could/should be more checks, but for now...
    164 	 */
    165 	if (strcmp(ca->ca_name, "le") &&
    166 	    strcmp(ca->ca_name, "am7990") &&
    167 	    strcmp(ca->ca_name, "AM7990"))
    168 		return (0);
    169 
    170 	return (1);
    171 }
    172 
    173 /*
    174  *
    175  */
    176 void
    177 leattach(parent, self, aux)
    178 	struct device *parent, *self;
    179 	void *aux;
    180 {
    181 	register struct le_softc *sc = (void *)self;
    182 	struct confargs *ca = aux;
    183 	u_char *cp;	/* pointer to MAC address */
    184 	int i;
    185 
    186 	sc->sc_r1  = (void*)uvax_phys2virt(ca->ca_ioaddr);
    187 
    188 	sc->sc_am7990.sc_conf3 = 0;
    189 	sc->sc_am7990.sc_mem = le_iomem;
    190 	sc->sc_am7990.sc_addr = le_ioaddr;
    191 	sc->sc_am7990.sc_memsize = LE_IOSIZE;
    192 	sc->sc_am7990.sc_wrcsr = lewrcsr;
    193 	sc->sc_am7990.sc_rdcsr = lerdcsr;
    194 	sc->sc_am7990.sc_hwinit = lehwinit;
    195 	sc->sc_am7990.sc_nocarrier = NULL;
    196 
    197 	xdebug(("leattach: mem=%x, addr=%x, size=%x (%d)\n",
    198 	    sc->sc_am7990.sc_mem, sc->sc_am7990.sc_addr,
    199 	    sc->sc_am7990.sc_memsize, sc->sc_am7990.sc_memsize));
    200 
    201 	sc->sc_am7990.sc_copytodesc = am7990_copytobuf_contig;
    202 	sc->sc_am7990.sc_copyfromdesc = am7990_copyfrombuf_contig;
    203 	sc->sc_am7990.sc_copytobuf = am7990_copytobuf_contig;
    204 	sc->sc_am7990.sc_copyfrombuf = am7990_copyfrombuf_contig;
    205 	sc->sc_am7990.sc_zerobuf = am7990_zerobuf_contig;
    206 
    207 	/*
    208 	 * Get the ethernet address out of rom
    209 	 */
    210 	for (i = 0; i < sizeof(sc->sc_am7990.sc_enaddr); i++) {
    211 		int *eaddr = (void*)uvax_phys2virt(ca->ca_enaddr);
    212 		sc->sc_am7990.sc_enaddr[i] = (u_char)eaddr[i];
    213 	}
    214 
    215 	bcopy(self->dv_xname, sc->sc_am7990.sc_ethercom.ec_if.if_xname,
    216 	    IFNAMSIZ);
    217 	am7990_config(&sc->sc_am7990);
    218 
    219 #ifdef LEDEBUG
    220 	sc->sc_am7990.sc_debug = LEDEBUG;
    221 #endif
    222 
    223 	vsbus_intr_register(ca, am7990_intr, &sc->sc_am7990);
    224 	vsbus_intr_enable(ca);
    225 
    226 	/*
    227 	 * Register this device as boot device if we booted from it.
    228 	 * This will fail if there are more than one le in a machine,
    229 	 * fortunately there may be only one.
    230 	 */
    231 	if (B_TYPE(bootdev) == BDEV_LE)
    232 		booted_from = self;
    233 }
    234 
    235 #ifdef LE_CHIP_IS_POKEY
    236 /*
    237  * Write a lance register port, reading it back to ensure success. This seems
    238  * to be necessary during initialization, since the chip appears to be a bit
    239  * pokey sometimes.
    240  */
    241 void
    242 lewritereg(regptr, val)
    243 	register volatile u_short *regptr;
    244 	register u_short val;
    245 {
    246 	register int i = 0;
    247 
    248 	while (*regptr != val) {
    249 		*regptr = val;
    250 		wbflush();
    251 		if (++i > 10000) {
    252 			printf("le: Reg did not settle (to x%x): x%x\n", val,
    253 			    *regptr);
    254 			return;
    255 		}
    256 		DELAY(100);
    257 	}
    258 }
    259 #endif
    260