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