Home | History | Annotate | Line # | Download | only in dev
if_le.c revision 1.25
      1  1.25  thorpej /*	$NetBSD: if_le.c,v 1.25 1995/12/30 21:03:02 thorpej Exp $	*/
      2  1.20      cgd 
      3  1.24  mycroft /*-
      4  1.24  mycroft  * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
      5  1.24  mycroft  * Copyright (c) 1992, 1993
      6  1.24  mycroft  *	The Regents of the University of California.  All rights reserved.
      7  1.24  mycroft  *
      8  1.24  mycroft  * This code is derived from software contributed to Berkeley by
      9  1.24  mycroft  * Ralph Campbell and Rick Macklem.
     10   1.1      cgd  *
     11   1.1      cgd  * Redistribution and use in source and binary forms, with or without
     12   1.1      cgd  * modification, are permitted provided that the following conditions
     13   1.1      cgd  * are met:
     14   1.1      cgd  * 1. Redistributions of source code must retain the above copyright
     15   1.1      cgd  *    notice, this list of conditions and the following disclaimer.
     16   1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     17   1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     18   1.1      cgd  *    documentation and/or other materials provided with the distribution.
     19   1.1      cgd  * 3. All advertising materials mentioning features or use of this software
     20   1.1      cgd  *    must display the following acknowledgement:
     21   1.1      cgd  *	This product includes software developed by the University of
     22   1.1      cgd  *	California, Berkeley and its contributors.
     23   1.1      cgd  * 4. Neither the name of the University nor the names of its contributors
     24   1.1      cgd  *    may be used to endorse or promote products derived from this software
     25   1.1      cgd  *    without specific prior written permission.
     26   1.1      cgd  *
     27   1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     28   1.1      cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     29   1.1      cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     30   1.1      cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     31   1.1      cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     32   1.1      cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     33   1.1      cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     34   1.1      cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     35   1.1      cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     36   1.1      cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     37   1.1      cgd  * SUCH DAMAGE.
     38   1.1      cgd  *
     39  1.24  mycroft  *	@(#)if_le.c	8.2 (Berkeley) 11/16/93
     40   1.1      cgd  */
     41   1.1      cgd 
     42   1.1      cgd #include "bpfilter.h"
     43   1.1      cgd 
     44   1.5  mycroft #include <sys/param.h>
     45   1.5  mycroft #include <sys/systm.h>
     46   1.5  mycroft #include <sys/mbuf.h>
     47  1.24  mycroft #include <sys/syslog.h>
     48   1.5  mycroft #include <sys/socket.h>
     49  1.24  mycroft #include <sys/device.h>
     50   1.5  mycroft 
     51   1.5  mycroft #include <net/if.h>
     52   1.1      cgd 
     53   1.1      cgd #ifdef INET
     54   1.5  mycroft #include <netinet/in.h>
     55   1.5  mycroft #include <netinet/if_ether.h>
     56   1.1      cgd #endif
     57   1.1      cgd 
     58   1.5  mycroft #include <machine/cpu.h>
     59  1.18  mycroft #include <machine/mtpr.h>
     60  1.24  mycroft 
     61   1.5  mycroft #include <hp300/hp300/isr.h>
     62  1.25  thorpej 
     63  1.18  mycroft #ifdef USELEDS
     64  1.18  mycroft #include <hp300/hp300/led.h>
     65  1.25  thorpej /*
     66  1.25  thorpej  * Enable the transmit and receive hooks.
     67  1.25  thorpej  */
     68  1.25  thorpej #define LE_TINT_HOOK
     69  1.25  thorpej #define LE_RINT_HOOK
     70  1.18  mycroft #endif
     71   1.1      cgd 
     72   1.5  mycroft #include <hp300/dev/device.h>
     73   1.5  mycroft #include <hp300/dev/if_lereg.h>
     74  1.24  mycroft #include <hp300/dev/if_levar.h>
     75  1.24  mycroft #include <dev/ic/am7990reg.h>
     76  1.24  mycroft #define	LE_NEED_BUF_CONTIG
     77  1.24  mycroft #include <dev/ic/am7990var.h>
     78   1.1      cgd 
     79  1.24  mycroft #include "le.h"
     80  1.24  mycroft struct	le_softc le_softc[NLE];
     81  1.13  mycroft 
     82  1.24  mycroft #define	LE_SOFTC(unit)	&le_softc[unit]
     83  1.24  mycroft #define	LE_DELAY(x)	DELAY(x)
     84  1.24  mycroft #define	LEINTR_UNIT
     85  1.24  mycroft 
     86  1.24  mycroft int	lematch __P((struct hp_device *));
     87  1.24  mycroft void	leattach __P((struct hp_device *));
     88  1.24  mycroft int	leintr __P((int));
     89  1.13  mycroft 
     90  1.24  mycroft struct	driver ledriver = {
     91  1.24  mycroft 	lematch, leattach, "le",
     92  1.24  mycroft };
     93  1.13  mycroft 
     94   1.1      cgd /* offsets for:	   ID,   REGS,    MEM,  NVRAM */
     95   1.1      cgd int	lestd[] = { 0, 0x4000, 0x8000, 0xC008 };
     96   1.1      cgd 
     97  1.24  mycroft integrate void
     98  1.13  mycroft lewrcsr(sc, port, val)
     99  1.13  mycroft 	struct le_softc *sc;
    100  1.24  mycroft 	u_int16_t port, val;
    101  1.13  mycroft {
    102  1.13  mycroft 	register struct lereg0 *ler0 = sc->sc_r0;
    103  1.13  mycroft 	register struct lereg1 *ler1 = sc->sc_r1;
    104  1.13  mycroft 
    105  1.13  mycroft 	do {
    106  1.13  mycroft 		ler1->ler1_rap = port;
    107  1.13  mycroft 	} while ((ler0->ler0_status & LE_ACK) == 0);
    108  1.13  mycroft 	do {
    109  1.13  mycroft 		ler1->ler1_rdp = val;
    110  1.13  mycroft 	} while ((ler0->ler0_status & LE_ACK) == 0);
    111  1.13  mycroft }
    112  1.13  mycroft 
    113  1.24  mycroft integrate u_int16_t
    114  1.13  mycroft lerdcsr(sc, port)
    115  1.13  mycroft 	struct le_softc *sc;
    116  1.24  mycroft 	u_int16_t port;
    117  1.13  mycroft {
    118  1.13  mycroft 	register struct lereg0 *ler0 = sc->sc_r0;
    119  1.13  mycroft 	register struct lereg1 *ler1 = sc->sc_r1;
    120  1.24  mycroft 	u_int16_t val;
    121  1.13  mycroft 
    122  1.13  mycroft 	do {
    123  1.13  mycroft 		ler1->ler1_rap = port;
    124  1.13  mycroft 	} while ((ler0->ler0_status & LE_ACK) == 0);
    125  1.13  mycroft 	do {
    126  1.13  mycroft 		val = ler1->ler1_rdp;
    127  1.13  mycroft 	} while ((ler0->ler0_status & LE_ACK) == 0);
    128  1.13  mycroft 	return (val);
    129  1.13  mycroft }
    130  1.13  mycroft 
    131  1.25  thorpej /* ARGSUSED */
    132  1.25  thorpej static void
    133  1.25  thorpej hp300_le_tint_hook(sc)
    134  1.25  thorpej 	struct le_softc *sc;
    135  1.25  thorpej {
    136  1.25  thorpej 
    137  1.25  thorpej #ifdef USELEDS
    138  1.25  thorpej 	if (inledcontrol == 0)
    139  1.25  thorpej 		ledcontrol(0, 0, LED_LANXMT);
    140  1.25  thorpej #endif
    141  1.25  thorpej }
    142  1.25  thorpej 
    143  1.25  thorpej /* ARGSUSED */
    144  1.25  thorpej static void
    145  1.25  thorpej hp300_le_rint_hook(sc)
    146  1.25  thorpej 	struct le_softc *sc;
    147  1.25  thorpej {
    148  1.25  thorpej 
    149  1.25  thorpej #ifdef USELEDS
    150  1.25  thorpej 	if (inledcontrol == 0)
    151  1.25  thorpej 		ledcontrol(0, 0, LED_LANRCV);
    152  1.25  thorpej #endif
    153  1.25  thorpej }
    154  1.25  thorpej 
    155  1.23  thorpej int
    156  1.23  thorpej lematch(hd)
    157  1.23  thorpej 	struct hp_device *hd;
    158  1.23  thorpej {
    159  1.23  thorpej 	register struct lereg0 *ler0;
    160  1.24  mycroft 	struct le_softc *sc = LE_SOFTC(hd->hp_unit);
    161  1.23  thorpej 
    162  1.23  thorpej 	ler0 = (struct lereg0 *)(lestd[0] + (int)hd->hp_addr);
    163  1.23  thorpej 	if (ler0->ler0_id != LEID)
    164  1.23  thorpej 		return (0);
    165  1.23  thorpej 
    166  1.23  thorpej 	hd->hp_ipl = LE_IPL(ler0->ler0_status);
    167  1.23  thorpej 	sc->sc_hd = hd;
    168  1.23  thorpej 
    169  1.23  thorpej 	return (1);
    170  1.23  thorpej }
    171  1.23  thorpej 
    172   1.1      cgd /*
    173   1.1      cgd  * Interface exists: make available by filling in network interface
    174   1.1      cgd  * record.  System will initialize the interface when it is ready
    175   1.1      cgd  * to accept packets.
    176   1.1      cgd  */
    177  1.23  thorpej void
    178   1.1      cgd leattach(hd)
    179   1.1      cgd 	struct hp_device *hd;
    180   1.1      cgd {
    181   1.1      cgd 	register struct lereg0 *ler0;
    182  1.24  mycroft 	struct le_softc *sc = LE_SOFTC(hd->hp_unit);
    183   1.1      cgd 	char *cp;
    184   1.1      cgd 	int i;
    185   1.1      cgd 
    186   1.5  mycroft 	ler0 = sc->sc_r0 = (struct lereg0 *)(lestd[0] + (int)hd->hp_addr);
    187  1.24  mycroft 	ler0->ler0_id = 0xFF;
    188  1.24  mycroft 	DELAY(100);
    189  1.24  mycroft 
    190  1.24  mycroft 	/* XXXX kluge for now */
    191  1.24  mycroft 	sc->sc_dev.dv_unit = hd->hp_unit;
    192  1.24  mycroft 	sprintf(sc->sc_dev.dv_xname, "%s%d", ledriver.d_name, hd->hp_unit);
    193  1.24  mycroft 
    194  1.13  mycroft 	sc->sc_r1 = (struct lereg1 *)(lestd[1] + (int)hd->hp_addr);
    195  1.13  mycroft 	sc->sc_mem = (void *)(lestd[2] + (int)hd->hp_addr);
    196  1.24  mycroft 	sc->sc_conf3 = LE_C3_BSWP;
    197  1.24  mycroft 	sc->sc_addr = 0;
    198  1.24  mycroft 	sc->sc_memsize = 16384;
    199   1.1      cgd 
    200   1.1      cgd 	/*
    201   1.1      cgd 	 * Read the ethernet address off the board, one nibble at a time.
    202   1.1      cgd 	 */
    203   1.1      cgd 	cp = (char *)(lestd[3] + (int)hd->hp_addr);
    204  1.13  mycroft 	for (i = 0; i < sizeof(sc->sc_arpcom.ac_enaddr); i++) {
    205  1.13  mycroft 		sc->sc_arpcom.ac_enaddr[i] = (*++cp & 0xF) << 4;
    206   1.1      cgd 		cp++;
    207  1.13  mycroft 		sc->sc_arpcom.ac_enaddr[i] |= *++cp & 0xF;
    208   1.1      cgd 		cp++;
    209   1.1      cgd 	}
    210   1.1      cgd 
    211  1.24  mycroft 	sc->sc_copytodesc = copytobuf_contig;
    212  1.24  mycroft 	sc->sc_copyfromdesc = copyfrombuf_contig;
    213  1.24  mycroft 	sc->sc_copytobuf = copytobuf_contig;
    214  1.24  mycroft 	sc->sc_copyfrombuf = copyfrombuf_contig;
    215  1.24  mycroft 	sc->sc_zerobuf = zerobuf_contig;
    216  1.25  thorpej 
    217  1.25  thorpej #ifdef LE_TINT_HOOK
    218  1.25  thorpej 	sc->sc_tint_hook = hp300_le_tint_hook;
    219  1.25  thorpej #endif
    220  1.25  thorpej #ifdef LE_RINT_HOOK
    221  1.25  thorpej 	sc->sc_rint_hook = hp300_le_rint_hook;
    222  1.25  thorpej #endif
    223  1.24  mycroft 
    224  1.24  mycroft 	sc->sc_arpcom.ac_if.if_name = ledriver.d_name;
    225  1.24  mycroft 	leconfig(sc);
    226  1.24  mycroft 
    227  1.24  mycroft 	sc->sc_isr.isr_intr = leintr;
    228  1.24  mycroft 	sc->sc_isr.isr_arg = hd->hp_unit;
    229  1.24  mycroft 	sc->sc_isr.isr_ipl = hd->hp_ipl;
    230  1.24  mycroft 	isrlink(&sc->sc_isr);
    231   1.1      cgd 	ler0->ler0_status = LE_IE;
    232   1.1      cgd }
    233  1.14  mycroft 
    234  1.24  mycroft #include <dev/ic/am7990.c>
    235