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