Home | History | Annotate | Line # | Download | only in dev
if_le.c revision 1.36
      1 /*	$NetBSD: if_le.c,v 1.36 1996/12/17 08:41:13 thorpej 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/autoconf.h>
     59 #include <machine/cpu.h>
     60 #include <machine/mtpr.h>
     61 
     62 #include <hp300/hp300/isr.h>
     63 
     64 #ifdef USELEDS
     65 #include <hp300/hp300/led.h>
     66 #endif
     67 
     68 #ifndef NEWCONFIG
     69 #include <hp300/dev/device.h>
     70 #endif
     71 
     72 #include <dev/ic/am7990reg.h>
     73 #include <dev/ic/am7990var.h>
     74 
     75 #include <hp300/dev/dioreg.h>
     76 #include <hp300/dev/diovar.h>
     77 #include <hp300/dev/diodevs.h>
     78 #include <hp300/dev/if_lereg.h>
     79 #include <hp300/dev/if_levar.h>
     80 
     81 #ifdef NEWCONFIG
     82 int	lematch __P((struct device *, struct cfdata *, void *));
     83 void	leattach __P((struct device *, struct device *, void *));
     84 
     85 struct cfattach le_ca = {
     86 	sizeof(struct le_softc), lematch, leattach
     87 };
     88 #else /* ! NEWCONFIG */
     89 #include "le.h"
     90 struct	le_softc le_softc[NLE];
     91 
     92 int	lematch __P((struct hp_device *));
     93 void	leattach __P((struct hp_device *));
     94 
     95 struct	driver ledriver = {
     96 	lematch, leattach, "le",
     97 };
     98 #endif /* NEWCONFIG */
     99 
    100 int	leintr __P((void *));
    101 
    102 /* offsets for:	   ID,   REGS,    MEM,  NVRAM */
    103 int	lestd[] = { 0, 0x4000, 0x8000, 0xC008 };
    104 
    105 hide void lewrcsr __P((struct am7990_softc *, u_int16_t, u_int16_t));
    106 hide u_int16_t lerdcsr __P((struct am7990_softc *, u_int16_t));
    107 
    108 hide void
    109 lewrcsr(sc, port, val)
    110 	struct am7990_softc *sc;
    111 	u_int16_t port, val;
    112 {
    113 	register struct lereg0 *ler0 = ((struct le_softc *)sc)->sc_r0;
    114 	register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    115 
    116 	do {
    117 		ler1->ler1_rap = port;
    118 	} while ((ler0->ler0_status & LE_ACK) == 0);
    119 	do {
    120 		ler1->ler1_rdp = val;
    121 	} while ((ler0->ler0_status & LE_ACK) == 0);
    122 }
    123 
    124 hide u_int16_t
    125 lerdcsr(sc, port)
    126 	struct am7990_softc *sc;
    127 	u_int16_t port;
    128 {
    129 	register struct lereg0 *ler0 = ((struct le_softc *)sc)->sc_r0;
    130 	register struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    131 	u_int16_t val;
    132 
    133 	do {
    134 		ler1->ler1_rap = port;
    135 	} while ((ler0->ler0_status & LE_ACK) == 0);
    136 	do {
    137 		val = ler1->ler1_rdp;
    138 	} while ((ler0->ler0_status & LE_ACK) == 0);
    139 	return (val);
    140 }
    141 
    142 #ifdef NEWCONFIG
    143 int
    144 lematch(parent, match, aux)
    145 	struct device *parent;
    146 	struct cfdata *match;
    147 	void *aux;
    148 {
    149 	struct dio_attach_args *da = aux;
    150 
    151 	if (da->da_id == DIO_DEVICE_ID_LAN)
    152 		return (1);
    153 	return (0);
    154 }
    155 #else /* ! NEWCONFIG */
    156 int
    157 lematch(hd)
    158 	struct hp_device *hd;
    159 {
    160 	register struct lereg0 *ler0;
    161 	struct le_softc *lesc = &le_softc[hd->hp_unit];
    162 
    163 	ler0 = (struct lereg0 *)(lestd[0] + (int)hd->hp_addr);
    164 	if (ler0->ler0_id != LEID)
    165 		return (0);
    166 
    167 	hd->hp_ipl = LE_IPL(ler0->ler0_status);
    168 	lesc->sc_hd = hd;
    169 
    170 	return (1);
    171 }
    172 #endif /* NEWCONFIG */
    173 
    174 /*
    175  * Interface exists: make available by filling in network interface
    176  * record.  System will initialize the interface when it is ready
    177  * to accept packets.
    178  */
    179 #ifdef NEWCONFIG
    180 void
    181 leattach(parent, self, aux)
    182 	struct device *parent, *self;
    183 	void *aux;
    184 #else /* ! NEWCONFIG */
    185 void
    186 leattach(hd)
    187 	struct hp_device *hd;
    188 #endif /* NEWCONFIG */
    189 {
    190 	register struct lereg0 *ler0;
    191 #ifdef NEWCONFIG
    192 	struct dio_attach_args *da = aux;
    193 	struct le_softc *lesc = (struct le_softc *)self;
    194 	caddr_t addr;
    195 #else
    196 	struct le_softc *lesc = &le_softc[hd->hp_unit];
    197 	caddr_t addr = hd->hp_addr;
    198 #endif /* NEWCONFIG */
    199 	struct am7990_softc *sc = &lesc->sc_am7990;
    200 	char *cp;
    201 	int i, ipl;
    202 
    203 #ifdef NEWCONFIG
    204 	addr = iomap(dio_scodetopa(da->da_scode), da->da_size);
    205 	if (addr == 0) {
    206 		printf("\n%s: can't map LANCE registers\n",
    207 		    sc->sc_dev.dv_xname);
    208 		return;
    209 	}
    210 #endif /* NEWCONFIG */
    211 
    212 	ler0 = lesc->sc_r0 = (struct lereg0 *)(lestd[0] + (int)addr);
    213 	ler0->ler0_id = 0xFF;
    214 	DELAY(100);
    215 
    216 #ifdef NEWCONFIG
    217 	ipl = DIO_IPL(addr);
    218 	printf(" ipl %d", ipl);
    219 #else /* ! NEWCONFIG */
    220 	/* XXXX kluge for now */
    221 	hd->hp_dev.dv_class = DV_IFNET;
    222 	bcopy(&hd->hp_dev, &sc->sc_dev, sizeof(struct device));
    223 	ipl = hd->hp_ipl;
    224 #endif /* NEWCONFIG */
    225 
    226 	lesc->sc_r1 = (struct lereg1 *)(lestd[1] + (int)addr);
    227 	sc->sc_mem = (void *)(lestd[2] + (int)addr);
    228 	sc->sc_conf3 = LE_C3_BSWP;
    229 	sc->sc_addr = 0;
    230 	sc->sc_memsize = 16384;
    231 
    232 	/*
    233 	 * Read the ethernet address off the board, one nibble at a time.
    234 	 */
    235 	cp = (char *)(lestd[3] + (int)addr);
    236 	for (i = 0; i < sizeof(sc->sc_arpcom.ac_enaddr); i++) {
    237 		sc->sc_arpcom.ac_enaddr[i] = (*++cp & 0xF) << 4;
    238 		cp++;
    239 		sc->sc_arpcom.ac_enaddr[i] |= *++cp & 0xF;
    240 		cp++;
    241 	}
    242 
    243 	sc->sc_copytodesc = am7990_copytobuf_contig;
    244 	sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
    245 	sc->sc_copytobuf = am7990_copytobuf_contig;
    246 	sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
    247 	sc->sc_zerobuf = am7990_zerobuf_contig;
    248 
    249 	sc->sc_rdcsr = lerdcsr;
    250 	sc->sc_wrcsr = lewrcsr;
    251 	sc->sc_hwinit = NULL;
    252 
    253 	am7990_config(sc);
    254 
    255 	/* Establish the interrupt handler. */
    256 	(void) isrlink(leintr, sc, ipl, ISRPRI_NET);
    257 	ler0->ler0_status = LE_IE;
    258 }
    259 
    260 int
    261 leintr(arg)
    262 	void *arg;
    263 {
    264 	struct am7990_softc *sc = arg;
    265 	u_int16_t isr;
    266 
    267 #ifdef USELEDS
    268 	isr = lerdcsr(sc, LE_CSR0);
    269 
    270 	if ((isr & LE_C0_INTR) == 0)
    271 		return (0);
    272 
    273 	if (isr & LE_C0_RINT)
    274 		if (inledcontrol == 0)
    275 			ledcontrol(0, 0, LED_LANRCV);
    276 
    277 	if (isr & LE_C0_TINT)
    278 		if (inledcontrol == 0)
    279 			ledcontrol(0, 0, LED_LANXMT);
    280 #endif /* USELEDS */
    281 
    282 	return (am7990_intr(sc));
    283 }
    284