Home | History | Annotate | Line # | Download | only in dev
if_le.c revision 1.45
      1 /*	$NetBSD: if_le.c,v 1.45 1998/07/05 00:51:09 jonathan Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*-
     40  * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
     41  * Copyright (c) 1992, 1993
     42  *	The Regents of the University of California.  All rights reserved.
     43  *
     44  * This code is derived from software contributed to Berkeley by
     45  * Ralph Campbell and Rick Macklem.
     46  *
     47  * Redistribution and use in source and binary forms, with or without
     48  * modification, are permitted provided that the following conditions
     49  * are met:
     50  * 1. Redistributions of source code must retain the above copyright
     51  *    notice, this list of conditions and the following disclaimer.
     52  * 2. Redistributions in binary form must reproduce the above copyright
     53  *    notice, this list of conditions and the following disclaimer in the
     54  *    documentation and/or other materials provided with the distribution.
     55  * 3. All advertising materials mentioning features or use of this software
     56  *    must display the following acknowledgement:
     57  *	This product includes software developed by the University of
     58  *	California, Berkeley and its contributors.
     59  * 4. Neither the name of the University nor the names of its contributors
     60  *    may be used to endorse or promote products derived from this software
     61  *    without specific prior written permission.
     62  *
     63  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     64  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     65  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     66  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     67  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     68  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     69  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     70  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     71  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     72  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     73  * SUCH DAMAGE.
     74  *
     75  *	@(#)if_le.c	8.2 (Berkeley) 11/16/93
     76  */
     77 
     78 #include "opt_inet.h"
     79 #include "bpfilter.h"
     80 
     81 #include <sys/param.h>
     82 #include <sys/systm.h>
     83 #include <sys/mbuf.h>
     84 #include <sys/syslog.h>
     85 #include <sys/socket.h>
     86 #include <sys/device.h>
     87 
     88 #include <net/if.h>
     89 #include <net/if_ether.h>
     90 #include <net/if_media.h>
     91 
     92 #ifdef INET
     93 #include <netinet/in.h>
     94 #include <netinet/if_inarp.h>
     95 #endif
     96 
     97 #include <machine/autoconf.h>
     98 #include <machine/cpu.h>
     99 #include <machine/intr.h>
    100 
    101 #include <dev/ic/am7990reg.h>
    102 #include <dev/ic/am7990var.h>
    103 
    104 #include <hp300/dev/dioreg.h>
    105 #include <hp300/dev/diovar.h>
    106 #include <hp300/dev/diodevs.h>
    107 #include <hp300/dev/if_lereg.h>
    108 #include <hp300/dev/if_levar.h>
    109 
    110 #include "opt_useleds.h"
    111 
    112 #ifdef USELEDS
    113 #include <hp300/hp300/leds.h>
    114 #endif
    115 
    116 int	lematch __P((struct device *, struct cfdata *, void *));
    117 void	leattach __P((struct device *, struct device *, void *));
    118 
    119 struct cfattach le_ca = {
    120 	sizeof(struct le_softc), lematch, leattach
    121 };
    122 
    123 int	leintr __P((void *));
    124 
    125 hide void le_copytobuf __P((struct am7990_softc *, void *, int, int));
    126 hide void le_copyfrombuf __P((struct am7990_softc *, void *, int, int));
    127 hide void le_zerobuf __P((struct am7990_softc *, int, int));
    128 
    129 /* offsets for:	   ID,   REGS,    MEM,  NVRAM */
    130 int	lestd[] = { 0, 0x4000, 0x8000, 0xC008 };
    131 
    132 hide void lewrcsr __P((struct am7990_softc *, u_int16_t, u_int16_t));
    133 hide u_int16_t lerdcsr __P((struct am7990_softc *, u_int16_t));
    134 
    135 hide void
    136 lewrcsr(sc, port, val)
    137 	struct am7990_softc *sc;
    138 	u_int16_t port, val;
    139 {
    140 	struct le_softc *lesc = (struct le_softc *)sc;
    141 	bus_space_tag_t bst = lesc->sc_bst;
    142 	bus_space_handle_t bsh0 = lesc->sc_bsh0;
    143 	bus_space_handle_t bsh1 = lesc->sc_bsh1;
    144 
    145 	do {
    146 		bus_space_write_2(bst, bsh1, LER1_RAP, port);
    147 	} while ((bus_space_read_1(bst, bsh0, LER0_STATUS) & LE_ACK) == 0);
    148 	do {
    149 		bus_space_write_2(bst, bsh1, LER1_RDP, val);
    150 	} while ((bus_space_read_1(bst, bsh0, LER0_STATUS) & LE_ACK) == 0);
    151 }
    152 
    153 hide u_int16_t
    154 lerdcsr(sc, port)
    155 	struct am7990_softc *sc;
    156 	u_int16_t port;
    157 {
    158 	struct le_softc *lesc = (struct le_softc *)sc;
    159 	bus_space_tag_t bst = lesc->sc_bst;
    160 	bus_space_handle_t bsh0 = lesc->sc_bsh0;
    161 	bus_space_handle_t bsh1 = lesc->sc_bsh1;
    162 	u_int16_t val;
    163 
    164 	do {
    165 		bus_space_write_2(bst, bsh1, LER1_RAP, port);
    166 	} while ((bus_space_read_1(bst, bsh0, LER0_STATUS) & LE_ACK) == 0);
    167 	do {
    168 		val = bus_space_read_2(bst, bsh1, LER1_RDP);
    169 	} while ((bus_space_read_1(bst, bsh0, LER0_STATUS) & LE_ACK) == 0);
    170 
    171 	return (val);
    172 }
    173 
    174 int
    175 lematch(parent, match, aux)
    176 	struct device *parent;
    177 	struct cfdata *match;
    178 	void *aux;
    179 {
    180 	struct dio_attach_args *da = aux;
    181 
    182 	if (da->da_id == DIO_DEVICE_ID_LAN)
    183 		return (1);
    184 	return (0);
    185 }
    186 
    187 /*
    188  * Interface exists: make available by filling in network interface
    189  * record.  System will initialize the interface when it is ready
    190  * to accept packets.
    191  */
    192 void
    193 leattach(parent, self, aux)
    194 	struct device *parent, *self;
    195 	void *aux;
    196 {
    197 	struct dio_attach_args *da = aux;
    198 	struct le_softc *lesc = (struct le_softc *)self;
    199 	struct am7990_softc *sc = &lesc->sc_am7990;
    200 	bus_space_tag_t bst = da->da_bst;
    201 	bus_space_handle_t bsh0, bsh1, bsh2;
    202 	bus_size_t offset;
    203 	int i, ipl;
    204 
    205 	if (bus_space_map(bst, (bus_addr_t)dio_scodetopa(da->da_scode),
    206 	    da->da_size, 0, &bsh0)) {
    207 		printf("\n%s: can't map LANCE registers\n",
    208 		    sc->sc_dev.dv_xname);
    209 		return;
    210 	}
    211 
    212 	if (bus_space_subregion(bst, bsh0, lestd[1], LER1_SIZE, &bsh1)) {
    213 		printf("\n%s: can't subregion LANCE space\n",
    214 		    sc->sc_dev.dv_xname);
    215 		return;
    216 	}
    217 
    218 	if (bus_space_subregion(bst, bsh0, lestd[2], LE_BUFSIZE, &bsh2)) {
    219 		printf("\n%s: can't subregion buffer space\n",
    220 		    sc->sc_dev.dv_xname);
    221 		return;
    222 	}
    223 
    224 	lesc->sc_bst = bst;
    225 	lesc->sc_bsh0 = bsh0;
    226 	lesc->sc_bsh1 = bsh1;
    227 	lesc->sc_bsh2 = bsh2;
    228 
    229 	bus_space_write_1(bst, bsh0, LER0_ID, 0xff);
    230 	DELAY(100);
    231 
    232 	ipl = DIO_IPL((caddr_t)bsh0);			/* XXX */
    233 	printf(" ipl %d", ipl);
    234 
    235 	sc->sc_conf3 = LE_C3_BSWP;
    236 	sc->sc_addr = 0;
    237 	sc->sc_memsize = LE_BUFSIZE;
    238 
    239 	/*
    240 	 * Read the ethernet address off the board, one nibble at a time.
    241 	 */
    242 	offset = lestd[3];
    243 	for (i = 0; i < sizeof(sc->sc_enaddr); i++) {
    244 		sc->sc_enaddr[i] =
    245 		    (bus_space_read_1(bst, bsh0, ++offset) & 0xf) << 4;
    246 		offset++;
    247 		sc->sc_enaddr[i] |=
    248 		    (bus_space_read_1(bst, bsh0, ++offset) & 0xf);
    249 		offset++;
    250 	}
    251 
    252 	sc->sc_copytodesc = le_copytobuf;
    253 	sc->sc_copyfromdesc = le_copyfrombuf;
    254 	sc->sc_copytobuf = le_copytobuf;
    255 	sc->sc_copyfrombuf = le_copyfrombuf;
    256 	sc->sc_zerobuf = le_zerobuf;
    257 
    258 	sc->sc_rdcsr = lerdcsr;
    259 	sc->sc_wrcsr = lewrcsr;
    260 	sc->sc_hwinit = NULL;
    261 
    262 	am7990_config(sc);
    263 
    264 	/* Establish the interrupt handler. */
    265 	(void) dio_intr_establish(leintr, sc, ipl, IPL_NET);
    266 	bus_space_write_1(bst, bsh0, LER0_STATUS, LE_IE);
    267 }
    268 
    269 int
    270 leintr(arg)
    271 	void *arg;
    272 {
    273 	struct am7990_softc *sc = arg;
    274 #ifdef USELEDS
    275 	u_int16_t isr;
    276 
    277 	isr = lerdcsr(sc, LE_CSR0);
    278 
    279 	if ((isr & LE_C0_INTR) == 0)
    280 		return (0);
    281 
    282 	if (isr & LE_C0_RINT)
    283 		ledcontrol(0, 0, LED_LANRCV);
    284 
    285 	if (isr & LE_C0_TINT)
    286 		ledcontrol(0, 0, LED_LANXMT);
    287 #endif /* USELEDS */
    288 
    289 	return (am7990_intr(sc));
    290 }
    291 
    292 hide void
    293 le_copytobuf(sc, from, boff, len)
    294 	struct am7990_softc *sc;
    295 	void *from;
    296 	int boff, len;
    297 {
    298 	struct le_softc *lesc = (struct le_softc *)sc;
    299 
    300 	bus_space_write_region_1(lesc->sc_bst, lesc->sc_bsh2, boff, from, len);
    301 }
    302 
    303 hide void
    304 le_copyfrombuf(sc, to, boff, len)
    305 	struct am7990_softc *sc;
    306 	void *to;
    307 	int boff, len;
    308 {
    309 	struct le_softc *lesc = (struct le_softc *)sc;
    310 
    311 	bus_space_read_region_1(lesc->sc_bst, lesc->sc_bsh2, boff, to, len);
    312 }
    313 
    314 hide void
    315 le_zerobuf(sc, boff, len)
    316 	struct am7990_softc *sc;
    317 	int boff, len;
    318 {
    319 	struct le_softc *lesc = (struct le_softc *)sc;
    320 
    321 	bus_space_set_region_1(lesc->sc_bst, lesc->sc_bsh2, boff, 0, len);
    322 }
    323