Home | History | Annotate | Line # | Download | only in if
if_le_vsbus.c revision 1.3
      1  1.3   matt /*	$NetBSD: if_le_vsbus.c,v 1.3 2000/01/24 02:54:03 matt Exp $	*/
      2  1.1  ragge 
      3  1.1  ragge /*-
      4  1.1  ragge  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  1.1  ragge  * All rights reserved.
      6  1.1  ragge  *
      7  1.1  ragge  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  ragge  * by Charles M. Hannum.
      9  1.1  ragge  *
     10  1.1  ragge  * Redistribution and use in source and binary forms, with or without
     11  1.1  ragge  * modification, are permitted provided that the following conditions
     12  1.1  ragge  * are met:
     13  1.1  ragge  * 1. Redistributions of source code must retain the above copyright
     14  1.1  ragge  *    notice, this list of conditions and the following disclaimer.
     15  1.1  ragge  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  ragge  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  ragge  *    documentation and/or other materials provided with the distribution.
     18  1.1  ragge  * 3. All advertising materials mentioning features or use of this software
     19  1.1  ragge  *    must display the following acknowledgement:
     20  1.1  ragge  *	  This product includes software developed by the NetBSD
     21  1.1  ragge  *	  Foundation, Inc. and its contributors.
     22  1.1  ragge  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  ragge  *    contributors may be used to endorse or promote products derived
     24  1.1  ragge  *    from this software without specific prior written permission.
     25  1.1  ragge  *
     26  1.1  ragge  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  ragge  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  ragge  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  ragge  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  ragge  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  ragge  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  ragge  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  ragge  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  ragge  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  ragge  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  ragge  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  ragge  */
     38  1.1  ragge 
     39  1.1  ragge /*-
     40  1.1  ragge  * Copyright (c) 1992, 1993
     41  1.1  ragge  *	The Regents of the University of California.  All rights reserved.
     42  1.1  ragge  *
     43  1.1  ragge  * This code is derived from software contributed to Berkeley by
     44  1.1  ragge  * Ralph Campbell and Rick Macklem.
     45  1.1  ragge  *
     46  1.1  ragge  * Redistribution and use in source and binary forms, with or without
     47  1.1  ragge  * modification, are permitted provided that the following conditions
     48  1.1  ragge  * are met:
     49  1.1  ragge  * 1. Redistributions of source code must retain the above copyright
     50  1.1  ragge  *    notice, this list of conditions and the following disclaimer.
     51  1.1  ragge  * 2. Redistributions in binary form must reproduce the above copyright
     52  1.1  ragge  *    notice, this list of conditions and the following disclaimer in the
     53  1.1  ragge  *    documentation and/or other materials provided with the distribution.
     54  1.1  ragge  * 3. All advertising materials mentioning features or use of this software
     55  1.1  ragge  *    must display the following acknowledgement:
     56  1.1  ragge  *	This product includes software developed by the University of
     57  1.1  ragge  *	California, Berkeley and its contributors.
     58  1.1  ragge  * 4. Neither the name of the University nor the names of its contributors
     59  1.1  ragge  *    may be used to endorse or promote products derived from this software
     60  1.1  ragge  *    without specific prior written permission.
     61  1.1  ragge  *
     62  1.1  ragge  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     63  1.1  ragge  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     64  1.1  ragge  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     65  1.1  ragge  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     66  1.1  ragge  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     67  1.1  ragge  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     68  1.1  ragge  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     69  1.1  ragge  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     70  1.1  ragge  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     71  1.1  ragge  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     72  1.1  ragge  * SUCH DAMAGE.
     73  1.1  ragge  *
     74  1.1  ragge  *	@(#)if_le.c	8.2 (Berkeley) 11/16/93
     75  1.1  ragge  */
     76  1.1  ragge 
     77  1.1  ragge #include "opt_inet.h"
     78  1.1  ragge #include "bpfilter.h"
     79  1.1  ragge 
     80  1.1  ragge #include <sys/param.h>
     81  1.1  ragge #include <sys/syslog.h>
     82  1.1  ragge #include <sys/socket.h>
     83  1.1  ragge #include <sys/device.h>
     84  1.1  ragge #include <sys/reboot.h>
     85  1.1  ragge 
     86  1.1  ragge #include <vm/vm.h>
     87  1.1  ragge #include <vm/vm_kern.h>
     88  1.1  ragge 
     89  1.1  ragge #include <net/if.h>
     90  1.1  ragge #include <net/if_ether.h>
     91  1.1  ragge #include <net/if_media.h>
     92  1.1  ragge 
     93  1.1  ragge #if INET
     94  1.1  ragge #include <netinet/in.h>
     95  1.1  ragge #include <netinet/if_inarp.h>
     96  1.1  ragge #endif
     97  1.1  ragge 
     98  1.1  ragge #include <machine/cpu.h>
     99  1.2  ragge #include <machine/sid.h>
    100  1.3   matt #include <machine/scb.h>
    101  1.1  ragge #include <machine/bus.h>
    102  1.1  ragge #include <machine/rpb.h>
    103  1.1  ragge #include <machine/vsbus.h>
    104  1.1  ragge 
    105  1.1  ragge #include <dev/ic/lancereg.h>
    106  1.1  ragge #include <dev/ic/lancevar.h>
    107  1.1  ragge #include <dev/ic/am7990reg.h>
    108  1.1  ragge #include <dev/ic/am7990var.h>
    109  1.1  ragge 
    110  1.1  ragge #include "ioconf.h"
    111  1.1  ragge 
    112  1.1  ragge struct le_softc {
    113  1.1  ragge 	struct	am7990_softc sc_am7990; /* Must be first */
    114  1.1  ragge 	volatile u_short *sc_rap;
    115  1.1  ragge 	volatile u_short *sc_rdp;
    116  1.1  ragge };
    117  1.1  ragge 
    118  1.1  ragge int	le_vsbus_match __P((struct device *, struct cfdata *, void *));
    119  1.1  ragge void	le_vsbus_attach __P((struct device *, struct device *, void *));
    120  1.1  ragge static	void	lewrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
    121  1.1  ragge static	u_int16_t lerdcsr __P((struct lance_softc *, u_int16_t));
    122  1.1  ragge 
    123  1.1  ragge struct cfattach le_vsbus_ca = {
    124  1.1  ragge 	sizeof(struct le_softc), le_vsbus_match, le_vsbus_attach
    125  1.1  ragge };
    126  1.1  ragge 
    127  1.1  ragge void
    128  1.1  ragge lewrcsr(ls, port, val)
    129  1.1  ragge 	struct lance_softc *ls;
    130  1.1  ragge 	u_int16_t port, val;
    131  1.1  ragge {
    132  1.1  ragge 	struct le_softc *sc = (void *)ls;
    133  1.1  ragge 
    134  1.1  ragge 	*sc->sc_rap = port;
    135  1.1  ragge 	*sc->sc_rdp = val;
    136  1.1  ragge }
    137  1.1  ragge 
    138  1.1  ragge u_int16_t
    139  1.1  ragge lerdcsr(ls, port)
    140  1.1  ragge 	struct lance_softc *ls;
    141  1.1  ragge 	u_int16_t port;
    142  1.1  ragge {
    143  1.1  ragge 	struct le_softc *sc = (void *)ls;
    144  1.1  ragge 
    145  1.1  ragge 	*sc->sc_rap = port;
    146  1.1  ragge 	return *sc->sc_rdp;
    147  1.1  ragge }
    148  1.1  ragge 
    149  1.1  ragge int
    150  1.1  ragge le_vsbus_match(parent, cf, aux)
    151  1.1  ragge 	struct device *parent;
    152  1.1  ragge 	struct cfdata *cf;
    153  1.1  ragge 	void *aux;
    154  1.1  ragge {
    155  1.1  ragge 	struct  vsbus_attach_args *va = aux;
    156  1.1  ragge 	volatile short *rdp, *rap;
    157  1.1  ragge 
    158  1.2  ragge 	if (vax_boardtype == VAX_BTYP_49)
    159  1.2  ragge 		return 0;
    160  1.1  ragge 	rdp = (short *)va->va_addr;
    161  1.1  ragge 	rap = rdp + 2;
    162  1.1  ragge 
    163  1.1  ragge 	/* Make sure the chip is stopped. */
    164  1.1  ragge 	*rap = LE_CSR0;
    165  1.1  ragge 	*rdp = LE_C0_STOP;
    166  1.1  ragge 	DELAY(100);
    167  1.1  ragge 	*rdp = LE_C0_INIT|LE_C0_INEA;
    168  1.1  ragge 
    169  1.1  ragge 	/* Wait for initialization to finish. */
    170  1.1  ragge 	DELAY(100000);
    171  1.1  ragge 
    172  1.1  ragge 	/* Should have interrupted by now */
    173  1.1  ragge 	if (*rdp & LE_C0_IDON)
    174  1.1  ragge 		return 1;
    175  1.1  ragge 	return 0;
    176  1.1  ragge }
    177  1.1  ragge 
    178  1.1  ragge void
    179  1.1  ragge le_vsbus_attach(parent, self, aux)
    180  1.1  ragge 	struct device *parent, *self;
    181  1.1  ragge 	void *aux;
    182  1.1  ragge {
    183  1.1  ragge 	struct  vsbus_attach_args *va = aux;
    184  1.1  ragge 	struct le_softc *sc = (void *)self;
    185  1.1  ragge 	bus_dma_segment_t seg;
    186  1.1  ragge 	int *lance_addr;
    187  1.1  ragge 	int i, err, rseg;
    188  1.1  ragge 
    189  1.1  ragge 	sc->sc_rdp = (short *)vax_map_physmem(NI_BASE, 1);
    190  1.1  ragge 	sc->sc_rap = sc->sc_rdp + 2;
    191  1.1  ragge 
    192  1.1  ragge 	/* Prettier printout */
    193  1.1  ragge 	printf("\n%s", self->dv_xname);
    194  1.1  ragge 
    195  1.1  ragge 	/*
    196  1.1  ragge 	 * MD functions.
    197  1.1  ragge 	 */
    198  1.1  ragge 	sc->sc_am7990.lsc.sc_rdcsr = lerdcsr;
    199  1.1  ragge 	sc->sc_am7990.lsc.sc_wrcsr = lewrcsr;
    200  1.1  ragge 	sc->sc_am7990.lsc.sc_nocarrier = NULL;
    201  1.1  ragge 
    202  1.3   matt 	scb_vecalloc(va->va_cvec, (void (*)(void *)) am7990_intr, sc, SCB_ISTACK);
    203  1.1  ragge         /*
    204  1.1  ragge          * Allocate a (DMA-safe) block for all descriptors and buffers.
    205  1.1  ragge          */
    206  1.1  ragge 
    207  1.1  ragge #define ALLOCSIZ (64 * 1024)
    208  1.1  ragge         err = bus_dmamem_alloc(va->va_dmat, ALLOCSIZ, NBPG, 0,
    209  1.1  ragge             &seg, 1, &rseg, BUS_DMA_NOWAIT);
    210  1.1  ragge         if (err) {
    211  1.1  ragge                 printf(": unable to alloc buffer block: err %d\n", err);
    212  1.1  ragge                 return;
    213  1.1  ragge         }
    214  1.1  ragge         err = bus_dmamem_map(va->va_dmat, &seg, rseg, ALLOCSIZ,
    215  1.1  ragge             (caddr_t *)&sc->sc_am7990.lsc.sc_mem,
    216  1.1  ragge 	    BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
    217  1.1  ragge         if (err) {
    218  1.1  ragge                 printf(": unable to map buffer block: err %d\n", err);
    219  1.1  ragge                 bus_dmamem_free(va->va_dmat, &seg, rseg);
    220  1.1  ragge                 return;
    221  1.1  ragge         }
    222  1.1  ragge 	sc->sc_am7990.lsc.sc_addr =
    223  1.1  ragge 	    (paddr_t)sc->sc_am7990.lsc.sc_mem & 0xffffff;
    224  1.1  ragge 	sc->sc_am7990.lsc.sc_memsize = ALLOCSIZ;
    225  1.1  ragge 
    226  1.1  ragge 	sc->sc_am7990.lsc.sc_copytodesc = lance_copytobuf_contig;
    227  1.1  ragge 	sc->sc_am7990.lsc.sc_copyfromdesc = lance_copyfrombuf_contig;
    228  1.1  ragge 	sc->sc_am7990.lsc.sc_copytobuf = lance_copytobuf_contig;
    229  1.1  ragge 	sc->sc_am7990.lsc.sc_copyfrombuf = lance_copyfrombuf_contig;
    230  1.1  ragge 	sc->sc_am7990.lsc.sc_zerobuf = lance_zerobuf_contig;
    231  1.1  ragge 
    232  1.1  ragge 	/*
    233  1.1  ragge 	 * Get the ethernet address out of rom
    234  1.1  ragge 	 */
    235  1.1  ragge 	lance_addr = (int *)vax_map_physmem(NI_ADDR, 1);
    236  1.1  ragge 	for (i = 0; i < 6; i++)
    237  1.1  ragge 		sc->sc_am7990.lsc.sc_enaddr[i] = (u_char)lance_addr[i];
    238  1.1  ragge 	vax_unmap_physmem((vaddr_t)lance_addr, 1);
    239  1.1  ragge 
    240  1.1  ragge 	bcopy(self->dv_xname, sc->sc_am7990.lsc.sc_ethercom.ec_if.if_xname,
    241  1.1  ragge 	    IFNAMSIZ);
    242  1.1  ragge 	am7990_config(&sc->sc_am7990);
    243  1.1  ragge 
    244  1.1  ragge 	/*
    245  1.1  ragge 	 * Register this device as boot device if we booted from it.
    246  1.1  ragge 	 * This will fail if there are more than one le in a machine,
    247  1.1  ragge 	 * fortunately there may be only one.
    248  1.1  ragge 	 */
    249  1.1  ragge 	if (B_TYPE(bootdev) == BDEV_LE)
    250  1.1  ragge 		booted_from = self;
    251  1.1  ragge }
    252