Home | History | Annotate | Line # | Download | only in dev
if_le.c revision 1.29
      1 /*	$NetBSD: if_le.c,v 1.29 1996/04/22 02:30:45 christos 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 
     53 #ifdef INET
     54 #include <netinet/in.h>
     55 #include <netinet/if_ether.h>
     56 #endif
     57 
     58 #include <machine/cpu.h>
     59 #include <machine/mtpr.h>
     60 
     61 #include <hp300/hp300/isr.h>
     62 
     63 #ifdef USELEDS
     64 #include <hp300/hp300/led.h>
     65 #endif
     66 
     67 #include <hp300/dev/device.h>
     68 #include <hp300/dev/if_lereg.h>
     69 #include <hp300/dev/if_levar.h>
     70 #include <dev/ic/am7990reg.h>
     71 #define	LE_NEED_BUF_CONTIG
     72 #include <dev/ic/am7990var.h>
     73 
     74 #include "le.h"
     75 struct	le_softc le_softc[NLE];
     76 
     77 #define	LE_SOFTC(unit)	&le_softc[unit]
     78 #define	LE_DELAY(x)	DELAY(x)
     79 
     80 int	lematch __P((struct hp_device *));
     81 void	leattach __P((struct hp_device *));
     82 int	leintr __P((void *));
     83 static	int hp300_leintr __P((void *));	/* machine-dependent wrapper */
     84 
     85 struct	driver ledriver = {
     86 	lematch, leattach, "le",
     87 };
     88 
     89 /* offsets for:	   ID,   REGS,    MEM,  NVRAM */
     90 int	lestd[] = { 0, 0x4000, 0x8000, 0xC008 };
     91 
     92 integrate void
     93 lehwinit(sc)
     94 	struct le_softc *sc;
     95 {
     96 }
     97 
     98 integrate void
     99 lewrcsr(sc, port, val)
    100 	struct le_softc *sc;
    101 	u_int16_t port, val;
    102 {
    103 	register struct lereg0 *ler0 = sc->sc_r0;
    104 	register struct lereg1 *ler1 = sc->sc_r1;
    105 
    106 	do {
    107 		ler1->ler1_rap = port;
    108 	} while ((ler0->ler0_status & LE_ACK) == 0);
    109 	do {
    110 		ler1->ler1_rdp = val;
    111 	} while ((ler0->ler0_status & LE_ACK) == 0);
    112 }
    113 
    114 integrate u_int16_t
    115 lerdcsr(sc, port)
    116 	struct le_softc *sc;
    117 	u_int16_t port;
    118 {
    119 	register struct lereg0 *ler0 = sc->sc_r0;
    120 	register struct lereg1 *ler1 = sc->sc_r1;
    121 	u_int16_t val;
    122 
    123 	do {
    124 		ler1->ler1_rap = port;
    125 	} while ((ler0->ler0_status & LE_ACK) == 0);
    126 	do {
    127 		val = ler1->ler1_rdp;
    128 	} while ((ler0->ler0_status & LE_ACK) == 0);
    129 	return (val);
    130 }
    131 
    132 int
    133 lematch(hd)
    134 	struct hp_device *hd;
    135 {
    136 	register struct lereg0 *ler0;
    137 	struct le_softc *sc = LE_SOFTC(hd->hp_unit);
    138 
    139 	ler0 = (struct lereg0 *)(lestd[0] + (int)hd->hp_addr);
    140 	if (ler0->ler0_id != LEID)
    141 		return (0);
    142 
    143 	hd->hp_ipl = LE_IPL(ler0->ler0_status);
    144 	sc->sc_hd = hd;
    145 
    146 	return (1);
    147 }
    148 
    149 /*
    150  * Interface exists: make available by filling in network interface
    151  * record.  System will initialize the interface when it is ready
    152  * to accept packets.
    153  */
    154 void
    155 leattach(hd)
    156 	struct hp_device *hd;
    157 {
    158 	register struct lereg0 *ler0;
    159 	struct le_softc *sc = LE_SOFTC(hd->hp_unit);
    160 	char *cp;
    161 	int i;
    162 
    163 	ler0 = sc->sc_r0 = (struct lereg0 *)(lestd[0] + (int)hd->hp_addr);
    164 	ler0->ler0_id = 0xFF;
    165 	DELAY(100);
    166 
    167 	/* XXXX kluge for now */
    168 	sc->sc_dev.dv_unit = hd->hp_unit;
    169 	sprintf(sc->sc_dev.dv_xname, "%s%d", ledriver.d_name, hd->hp_unit);
    170 
    171 	sc->sc_r1 = (struct lereg1 *)(lestd[1] + (int)hd->hp_addr);
    172 	sc->sc_mem = (void *)(lestd[2] + (int)hd->hp_addr);
    173 	sc->sc_conf3 = LE_C3_BSWP;
    174 	sc->sc_addr = 0;
    175 	sc->sc_memsize = 16384;
    176 
    177 	/*
    178 	 * Read the ethernet address off the board, one nibble at a time.
    179 	 */
    180 	cp = (char *)(lestd[3] + (int)hd->hp_addr);
    181 	for (i = 0; i < sizeof(sc->sc_arpcom.ac_enaddr); i++) {
    182 		sc->sc_arpcom.ac_enaddr[i] = (*++cp & 0xF) << 4;
    183 		cp++;
    184 		sc->sc_arpcom.ac_enaddr[i] |= *++cp & 0xF;
    185 		cp++;
    186 	}
    187 
    188 	sc->sc_copytodesc = am7990_copytobuf_contig;
    189 	sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
    190 	sc->sc_copytobuf = am7990_copytobuf_contig;
    191 	sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
    192 	sc->sc_zerobuf = am7990_zerobuf_contig;
    193 
    194 	sc->sc_arpcom.ac_if.if_name = ledriver.d_name;
    195 	leconfig(sc);
    196 
    197 	/* Establish the interrupt handler. */
    198 	isrlink(hp300_leintr, sc, hd->hp_ipl, ISRPRI_NET);
    199 	ler0->ler0_status = LE_IE;
    200 }
    201 
    202 static int
    203 hp300_leintr(arg)
    204 	void *arg;
    205 {
    206 	struct le_softc *sc = arg;
    207 	u_int16_t isr;
    208 
    209 #ifdef USELEDS
    210 	isr = lerdcsr(sc, LE_CSR0);
    211 
    212 	if ((isr & LE_C0_INTR) == 0)
    213 		return (0);
    214 
    215 	if (isr & LE_C0_RINT)
    216 		if (inledcontrol == 0)
    217 			ledcontrol(0, 0, LED_LANRCV);
    218 
    219 	if (isr & LE_C0_TINT)
    220 		if (inledcontrol == 0)
    221 			ledcontrol(0, 0, LED_LANXMT);
    222 #endif /* USELEDS */
    223 
    224 	return (leintr(sc));
    225 }
    226 
    227 #include <dev/ic/am7990.c>
    228