Home | History | Annotate | Line # | Download | only in dec
if_le_dec.c revision 1.12
      1 /*	$NetBSD: if_le_dec.c,v 1.12 2001/11/13 12:49:45 lukem 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 <sys/cdefs.h>
     44 __KERNEL_RCSID(0, "$NetBSD: if_le_dec.c,v 1.12 2001/11/13 12:49:45 lukem Exp $");
     45 
     46 #include "opt_inet.h"
     47 #include "bpfilter.h"
     48 
     49 #include <sys/param.h>
     50 #include <sys/systm.h>
     51 #include <sys/mbuf.h>
     52 #include <sys/syslog.h>
     53 #include <sys/socket.h>
     54 #include <sys/device.h>
     55 
     56 #include <net/if.h>
     57 #include <net/if_ether.h>
     58 #include <net/if_media.h>
     59 
     60 #ifdef INET
     61 #include <netinet/in.h>
     62 #include <netinet/if_inarp.h>
     63 #endif
     64 
     65 #include <dev/ic/lancereg.h>
     66 #include <dev/ic/lancevar.h>
     67 #include <dev/ic/am7990reg.h>
     68 #include <dev/ic/am7990var.h>
     69 
     70 #include <dev/tc/if_levar.h>
     71 #include <dev/tc/tcvar.h>
     72 
     73 #include <machine/bus.h>
     74 
     75 /* access LANCE registers */
     76 void le_dec_writereg __P((volatile u_short *regptr, u_short val));
     77 #define	LERDWR(cntl, src, dst)	{ (dst) = (src); tc_mb(); }
     78 #define	LEWREG(src, dst)	le_dec_writereg(&(dst), (src))
     79 
     80 #if defined(_KERNEL_OPT)
     81 #include "opt_ddb.h"
     82 #endif
     83 
     84 #ifdef DDB
     85 #define	integrate
     86 #define hide
     87 #else
     88 #define	integrate	static __inline
     89 #define hide		static
     90 #endif
     91 
     92 hide void le_dec_wrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
     93 hide u_int16_t le_dec_rdcsr __P((struct lance_softc *, u_int16_t));
     94 
     95 void
     96 dec_le_common_attach(sc, eap)
     97 	struct am7990_softc *sc;
     98 	u_char *eap;
     99 {
    100 	int i;
    101 
    102 	sc->lsc.sc_rdcsr = le_dec_rdcsr;
    103 	sc->lsc.sc_wrcsr = le_dec_wrcsr;
    104 	sc->lsc.sc_hwinit = NULL;
    105 
    106 	sc->lsc.sc_conf3 = 0;
    107 	sc->lsc.sc_addr = 0;
    108 	sc->lsc.sc_memsize = 65536;
    109 
    110 	/*
    111 	 * Get the ethernet address out of rom
    112 	 */
    113 	for (i = 0; i < sizeof(sc->lsc.sc_enaddr); i++) {
    114 		sc->lsc.sc_enaddr[i] = *eap;
    115 		eap += 4;
    116 	}
    117 
    118 	am7990_config(sc);
    119 }
    120 
    121 hide void
    122 le_dec_wrcsr(sc, port, val)
    123 	struct lance_softc *sc;
    124 	u_int16_t port, val;
    125 {
    126 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    127 
    128 	LEWREG(port, ler1->ler1_rap);
    129 	LERDWR(port, val, ler1->ler1_rdp);
    130 }
    131 
    132 hide u_int16_t
    133 le_dec_rdcsr(sc, port)
    134 	struct lance_softc *sc;
    135 	u_int16_t port;
    136 {
    137 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    138 	u_int16_t val;
    139 
    140 	LEWREG(port, ler1->ler1_rap);
    141 	LERDWR(0, ler1->ler1_rdp, val);
    142 	return (val);
    143 }
    144 
    145 /*
    146  * Write a lance register port, reading it back to ensure success. This seems
    147  * to be necessary during initialization, since the chip appears to be a bit
    148  * pokey sometimes.
    149  */
    150 void
    151 le_dec_writereg(regptr, val)
    152 	register volatile u_short *regptr;
    153 	register u_short val;
    154 {
    155 	register int i = 0;
    156 
    157 	while (*regptr != val) {
    158 		*regptr = val;
    159 		tc_mb();
    160 		if (++i > 10000) {
    161 			printf("le: Reg did not settle (to x%x): x%x\n", val,
    162 			    *regptr);
    163 			return;
    164 		}
    165 		DELAY(100);
    166 	}
    167 }
    168 
    169 /*
    170  * Routines for accessing the transmit and receive buffers are provided
    171  * by am7990.c, because of the LE_NEED_BUF_* macros defined above.
    172  * Unfortunately, CPU addressing of these buffers is done in one of
    173  * 3 ways:
    174  * - contiguous (for the 3max and turbochannel option card)
    175  * - gap2, which means shorts (2 bytes) interspersed with short (2 byte)
    176  *   spaces (for the pmax, vax 3400, and ioasic LANCE descriptors)
    177  * - gap16, which means 16bytes interspersed with 16byte spaces
    178  *   for buffers which must begin on a 32byte boundary (for 3min, maxine,
    179  *   and alpha)
    180  * The buffer offset is the logical byte offset, assuming contiguous storage.
    181  */
    182