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