Home | History | Annotate | Line # | Download | only in dec
if_le_dec.c revision 1.9
      1 /*	$NetBSD: if_le_dec.c,v 1.9 1998/07/05 00:51:17 jonathan Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1997 Jonathan Stone. All rights reserved.
      5  * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
      6  * Copyright (c) 1992, 1993
      7  *	The Regents of the University of California.  All rights reserved.
      8  *
      9  * This code is derived from software contributed to Berkeley by
     10  * Ralph Campbell and Rick Macklem.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  * 3. All advertising materials mentioning features or use of this software
     21  *    must display the following acknowledgement:
     22  *	This product includes software developed by the University of
     23  *	California, Berkeley and its contributors.
     24  * 4. Neither the name of the University nor the names of its contributors
     25  *    may be used to endorse or promote products derived from this software
     26  *    without specific prior written permission.
     27  *
     28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     38  * SUCH DAMAGE.
     39  *
     40  *	@(#)if_le.c	8.2 (Berkeley) 11/16/93
     41  */
     42 
     43 #include "opt_inet.h"
     44 #include "bpfilter.h"
     45 
     46 #include <sys/param.h>
     47 #include <sys/systm.h>
     48 #include <sys/mbuf.h>
     49 #include <sys/syslog.h>
     50 #include <sys/socket.h>
     51 #include <sys/device.h>
     52 
     53 #include <net/if.h>
     54 #include <net/if_ether.h>
     55 #include <net/if_media.h>
     56 
     57 #ifdef INET
     58 #include <netinet/in.h>
     59 #include <netinet/if_inarp.h>
     60 #endif
     61 
     62 #include <dev/ic/am7990reg.h>
     63 #include <dev/ic/am7990var.h>
     64 
     65 #include <dev/tc/if_levar.h>
     66 #include <dev/tc/tcvar.h>
     67 
     68 #include <machine/bus.h>
     69 
     70 /* access LANCE registers */
     71 void le_dec_writereg __P((volatile u_short *regptr, u_short val));
     72 #define	LERDWR(cntl, src, dst)	{ (dst) = (src); tc_mb(); }
     73 #define	LEWREG(src, dst)	le_dec_writereg(&(dst), (src))
     74 
     75 hide void le_dec_wrcsr __P((struct am7990_softc *, u_int16_t, u_int16_t));
     76 hide u_int16_t le_dec_rdcsr __P((struct am7990_softc *, u_int16_t));
     77 
     78 void
     79 dec_le_common_attach(sc, eap)
     80 	struct am7990_softc *sc;
     81 	u_char *eap;
     82 {
     83 	int i;
     84 
     85 	sc->sc_rdcsr = le_dec_rdcsr;
     86 	sc->sc_wrcsr = le_dec_wrcsr;
     87 	sc->sc_hwinit = NULL;
     88 
     89 	sc->sc_conf3 = 0;
     90 	sc->sc_addr = 0;
     91 	sc->sc_memsize = 65536;
     92 
     93 	/*
     94 	 * Get the ethernet address out of rom
     95 	 */
     96 	for (i = 0; i < sizeof(sc->sc_enaddr); i++) {
     97 		sc->sc_enaddr[i] = *eap;
     98 		eap += 4;
     99 	}
    100 
    101 	am7990_config(sc);
    102 }
    103 
    104 hide void
    105 le_dec_wrcsr(sc, port, val)
    106 	struct am7990_softc *sc;
    107 	u_int16_t port, val;
    108 {
    109 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    110 
    111 	LEWREG(port, ler1->ler1_rap);
    112 	LERDWR(port, val, ler1->ler1_rdp);
    113 }
    114 
    115 hide u_int16_t
    116 le_dec_rdcsr(sc, port)
    117 	struct am7990_softc *sc;
    118 	u_int16_t port;
    119 {
    120 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    121 	u_int16_t val;
    122 
    123 	LEWREG(port, ler1->ler1_rap);
    124 	LERDWR(0, ler1->ler1_rdp, val);
    125 	return (val);
    126 }
    127 
    128 /*
    129  * Write a lance register port, reading it back to ensure success. This seems
    130  * to be necessary during initialization, since the chip appears to be a bit
    131  * pokey sometimes.
    132  */
    133 void
    134 le_dec_writereg(regptr, val)
    135 	register volatile u_short *regptr;
    136 	register u_short val;
    137 {
    138 	register int i = 0;
    139 
    140 	while (*regptr != val) {
    141 		*regptr = val;
    142 		tc_mb();
    143 		if (++i > 10000) {
    144 			printf("le: Reg did not settle (to x%x): x%x\n", val,
    145 			    *regptr);
    146 			return;
    147 		}
    148 		DELAY(100);
    149 	}
    150 }
    151 
    152 /*
    153  * Routines for accessing the transmit and receive buffers are provided
    154  * by am7990.c, because of the LE_NEED_BUF_* macros defined above.
    155  * Unfortunately, CPU addressing of these buffers is done in one of
    156  * 3 ways:
    157  * - contiguous (for the 3max and turbochannel option card)
    158  * - gap2, which means shorts (2 bytes) interspersed with short (2 byte)
    159  *   spaces (for the pmax, vax 3400, and ioasic LANCE descriptors)
    160  * - gap16, which means 16bytes interspersed with 16byte spaces
    161  *   for buffers which must begin on a 32byte boundary (for 3min, maxine,
    162  *   and alpha)
    163  * The buffer offset is the logical byte offset, assuming contiguous storage.
    164  */
    165