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