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