Home | History | Annotate | Line # | Download | only in dev
if_le.c revision 1.20.16.2
      1  1.20.16.2       scw /*	$NetBSD: if_le.c,v 1.20.16.2 2000/03/13 12:15:27 scw Exp $	*/
      2       1.18   mycroft 
      3       1.18   mycroft /*-
      4       1.18   mycroft  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5       1.18   mycroft  * All rights reserved.
      6       1.18   mycroft  *
      7       1.18   mycroft  * This code is derived from software contributed to The NetBSD Foundation
      8       1.18   mycroft  * by Charles M. Hannum.
      9       1.18   mycroft  *
     10       1.18   mycroft  * Redistribution and use in source and binary forms, with or without
     11       1.18   mycroft  * modification, are permitted provided that the following conditions
     12       1.18   mycroft  * are met:
     13       1.18   mycroft  * 1. Redistributions of source code must retain the above copyright
     14       1.18   mycroft  *    notice, this list of conditions and the following disclaimer.
     15       1.18   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.18   mycroft  *    notice, this list of conditions and the following disclaimer in the
     17       1.18   mycroft  *    documentation and/or other materials provided with the distribution.
     18       1.18   mycroft  * 3. All advertising materials mentioning features or use of this software
     19       1.18   mycroft  *    must display the following acknowledgement:
     20       1.18   mycroft  *        This product includes software developed by the NetBSD
     21       1.18   mycroft  *        Foundation, Inc. and its contributors.
     22       1.18   mycroft  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.18   mycroft  *    contributors may be used to endorse or promote products derived
     24       1.18   mycroft  *    from this software without specific prior written permission.
     25       1.18   mycroft  *
     26       1.18   mycroft  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.18   mycroft  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.18   mycroft  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.18   mycroft  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.18   mycroft  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.18   mycroft  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.18   mycroft  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.18   mycroft  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.18   mycroft  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.18   mycroft  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.18   mycroft  * POSSIBILITY OF SUCH DAMAGE.
     37       1.18   mycroft  */
     38        1.1     chuck 
     39        1.1     chuck /*-
     40        1.2   mycroft  * Copyright (c) 1992, 1993
     41        1.1     chuck  *	The Regents of the University of California.  All rights reserved.
     42        1.1     chuck  *
     43        1.2   mycroft  * This code is derived from software contributed to Berkeley by
     44        1.2   mycroft  * Ralph Campbell and Rick Macklem.
     45        1.2   mycroft  *
     46        1.1     chuck  * Redistribution and use in source and binary forms, with or without
     47        1.1     chuck  * modification, are permitted provided that the following conditions
     48        1.1     chuck  * are met:
     49        1.1     chuck  * 1. Redistributions of source code must retain the above copyright
     50        1.1     chuck  *    notice, this list of conditions and the following disclaimer.
     51        1.1     chuck  * 2. Redistributions in binary form must reproduce the above copyright
     52        1.1     chuck  *    notice, this list of conditions and the following disclaimer in the
     53        1.1     chuck  *    documentation and/or other materials provided with the distribution.
     54        1.1     chuck  * 3. All advertising materials mentioning features or use of this software
     55        1.1     chuck  *    must display the following acknowledgement:
     56        1.1     chuck  *	This product includes software developed by the University of
     57        1.1     chuck  *	California, Berkeley and its contributors.
     58        1.1     chuck  * 4. Neither the name of the University nor the names of its contributors
     59        1.1     chuck  *    may be used to endorse or promote products derived from this software
     60        1.1     chuck  *    without specific prior written permission.
     61        1.1     chuck  *
     62        1.1     chuck  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     63        1.1     chuck  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     64        1.1     chuck  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     65        1.1     chuck  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     66        1.1     chuck  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     67        1.1     chuck  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     68        1.1     chuck  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     69        1.1     chuck  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     70        1.1     chuck  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     71        1.1     chuck  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     72        1.1     chuck  * SUCH DAMAGE.
     73        1.1     chuck  *
     74        1.2   mycroft  *	@(#)if_le.c	8.2 (Berkeley) 11/16/93
     75        1.1     chuck  */
     76        1.1     chuck 
     77       1.16  jonathan #include "opt_inet.h"
     78        1.1     chuck #include "bpfilter.h"
     79        1.1     chuck 
     80        1.1     chuck #include <sys/param.h>
     81        1.1     chuck #include <sys/systm.h>
     82        1.1     chuck #include <sys/mbuf.h>
     83        1.2   mycroft #include <sys/syslog.h>
     84        1.1     chuck #include <sys/socket.h>
     85        1.2   mycroft #include <sys/device.h>
     86        1.1     chuck 
     87        1.1     chuck #include <net/if.h>
     88       1.12        is #include <net/if_ether.h>
     89       1.13   thorpej #include <net/if_media.h>
     90        1.1     chuck 
     91        1.1     chuck #ifdef INET
     92        1.1     chuck #include <netinet/in.h>
     93       1.12        is #include <netinet/if_inarp.h>
     94        1.1     chuck #endif
     95        1.1     chuck 
     96       1.10     chuck #include <machine/autoconf.h>
     97        1.1     chuck #include <machine/cpu.h>
     98  1.20.16.1       scw #include <machine/bus.h>
     99        1.1     chuck 
    100        1.2   mycroft #include <mvme68k/dev/pccreg.h>
    101        1.7     chuck #include <mvme68k/dev/pccvar.h>
    102        1.7     chuck 
    103       1.17  drochner #include <dev/ic/lancereg.h>
    104       1.17  drochner #include <dev/ic/lancevar.h>
    105        1.2   mycroft #include <dev/ic/am7990reg.h>
    106        1.2   mycroft #include <dev/ic/am7990var.h>
    107        1.2   mycroft 
    108        1.8   thorpej #include <mvme68k/dev/if_lereg.h>
    109        1.8   thorpej #include <mvme68k/dev/if_levar.h>
    110        1.2   mycroft 
    111       1.20       scw 
    112       1.14       gwr int 	le_pcc_match __P((struct device *, struct cfdata  *, void *));
    113        1.7     chuck void	le_pcc_attach __P((struct device *, struct device *, void *));
    114        1.1     chuck 
    115        1.7     chuck struct cfattach le_pcc_ca = {
    116        1.7     chuck 	sizeof(struct le_softc), le_pcc_match, le_pcc_attach
    117        1.4   thorpej };
    118       1.15   thorpej 
    119       1.15   thorpej extern struct cfdriver le_cd;
    120        1.4   thorpej 
    121       1.17  drochner #if defined(_KERNEL) && !defined(_LKM)
    122       1.17  drochner #include "opt_ddb.h"
    123       1.17  drochner #endif
    124       1.17  drochner 
    125       1.17  drochner #ifdef DDB
    126       1.17  drochner #define hide
    127       1.17  drochner #else
    128  1.20.16.1       scw #define hide	static
    129       1.17  drochner #endif
    130       1.17  drochner 
    131       1.17  drochner hide void le_pcc_wrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
    132       1.17  drochner hide u_int16_t le_pcc_rdcsr __P((struct lance_softc *, u_int16_t));
    133        1.1     chuck 
    134        1.8   thorpej hide void
    135        1.8   thorpej le_pcc_wrcsr(sc, port, val)
    136       1.17  drochner 	struct lance_softc *sc;
    137        1.2   mycroft 	u_int16_t port, val;
    138        1.1     chuck {
    139  1.20.16.1       scw 	struct le_softc *lsc = (struct le_softc *) sc;
    140        1.1     chuck 
    141  1.20.16.1       scw 	bus_space_write_2(lsc->sc_bust, lsc->sc_bush, LEPCC_RAP, port);
    142  1.20.16.1       scw 	bus_space_write_2(lsc->sc_bust, lsc->sc_bush, LEPCC_RDP, val);
    143        1.1     chuck }
    144        1.1     chuck 
    145        1.8   thorpej hide u_int16_t
    146        1.8   thorpej le_pcc_rdcsr(sc, port)
    147       1.17  drochner 	struct lance_softc *sc;
    148        1.2   mycroft 	u_int16_t port;
    149        1.1     chuck {
    150  1.20.16.1       scw 	struct le_softc *lsc = (struct le_softc *) sc;
    151        1.1     chuck 
    152  1.20.16.1       scw 	bus_space_write_2(lsc->sc_bust, lsc->sc_bush, LEPCC_RAP, port);
    153  1.20.16.1       scw 	return bus_space_read_2(lsc->sc_bust, lsc->sc_bush, LEPCC_RDP);
    154        1.1     chuck }
    155        1.1     chuck 
    156        1.1     chuck int
    157       1.14       gwr le_pcc_match(parent, cf, aux)
    158        1.2   mycroft 	struct device *parent;
    159       1.14       gwr 	struct cfdata *cf;
    160       1.14       gwr 	void *aux;
    161        1.1     chuck {
    162        1.7     chuck 	struct pcc_attach_args *pa = aux;
    163        1.7     chuck 
    164        1.7     chuck 	if (strcmp(pa->pa_name, le_cd.cd_name))
    165        1.7     chuck 		return (0);
    166        1.1     chuck 
    167        1.7     chuck 	pa->pa_ipl = cf->pcccf_ipl;
    168        1.7     chuck 	return (1);
    169        1.1     chuck }
    170        1.1     chuck 
    171        1.1     chuck void
    172        1.7     chuck le_pcc_attach(parent, self, aux)
    173        1.2   mycroft 	struct device *parent, *self;
    174        1.2   mycroft 	void *aux;
    175        1.2   mycroft {
    176  1.20.16.1       scw 	struct le_softc *lsc = (void *)self;
    177  1.20.16.1       scw 	struct lance_softc *sc = &lsc->sc_am7990.lsc;
    178        1.7     chuck 	struct pcc_attach_args *pa = aux;
    179  1.20.16.1       scw 	bus_dma_segment_t seg;
    180  1.20.16.1       scw 	int rseg;
    181        1.1     chuck 
    182        1.7     chuck 	/* Map control registers. */
    183  1.20.16.1       scw 	lsc->sc_bust = pa->pa_bust;
    184  1.20.16.1       scw 	bus_space_map(pa->pa_bust, pa->pa_offset, 4, 0, &lsc->sc_bush);
    185        1.1     chuck 
    186  1.20.16.1       scw 	/* Get contiguous DMA-able memory for the lance */
    187  1.20.16.1       scw 	if ( bus_dmamem_alloc(pa->pa_dmat, ether_data_buff_size, NBPG, 0,
    188  1.20.16.2       scw 	    &seg, 1, &rseg,
    189  1.20.16.2       scw 	    BUS_DMA_NOWAIT | BUS_DMA_ONBOARD_RAM | BUS_DMA_24BIT) != 0 ) {
    190  1.20.16.1       scw 		printf("%s: Failed to allocate ether buffer\n", self->dv_xname);
    191  1.20.16.1       scw 		return;
    192  1.20.16.1       scw 	}
    193  1.20.16.1       scw 
    194  1.20.16.1       scw 	if ( bus_dmamem_map(pa->pa_dmat, &seg, rseg, ether_data_buff_size,
    195  1.20.16.1       scw 	    (caddr_t *) &sc->sc_mem, BUS_DMA_NOWAIT | BUS_DMA_COHERENT) != 0 ) {
    196  1.20.16.1       scw 		printf("%s: Failed to map ether buffer\n", self->dv_xname);
    197  1.20.16.1       scw 		bus_dmamem_free(pa->pa_dmat, &seg, rseg);
    198  1.20.16.1       scw 		return;
    199  1.20.16.1       scw 	}
    200  1.20.16.1       scw 
    201  1.20.16.2       scw 	sc->sc_addr = seg.ds_addr;
    202       1.20       scw 	sc->sc_memsize = ether_data_buff_size;
    203  1.20.16.1       scw 	sc->sc_conf3 = LE_C3_BSWP;
    204        1.2   mycroft 
    205       1.12        is 	myetheraddr(sc->sc_enaddr);
    206        1.2   mycroft 
    207       1.17  drochner 	sc->sc_copytodesc = lance_copytobuf_contig;
    208       1.17  drochner 	sc->sc_copyfromdesc = lance_copyfrombuf_contig;
    209       1.17  drochner 	sc->sc_copytobuf = lance_copytobuf_contig;
    210       1.17  drochner 	sc->sc_copyfrombuf = lance_copyfrombuf_contig;
    211       1.17  drochner 	sc->sc_zerobuf = lance_zerobuf_contig;
    212        1.1     chuck 
    213        1.8   thorpej 	sc->sc_rdcsr = le_pcc_rdcsr;
    214        1.8   thorpej 	sc->sc_wrcsr = le_pcc_wrcsr;
    215        1.8   thorpej 	sc->sc_hwinit = NULL;
    216        1.1     chuck 
    217  1.20.16.1       scw 	am7990_config(&lsc->sc_am7990);
    218       1.10     chuck 
    219       1.10     chuck 	/* Are we the boot device? */
    220       1.10     chuck 	if (PCC_PADDR(pa->pa_offset) == bootaddr)
    221       1.11   thorpej 		booted_device = self;
    222        1.8   thorpej 
    223        1.8   thorpej 	pccintr_establish(PCCV_LE, am7990_intr, pa->pa_ipl, sc);
    224  1.20.16.1       scw 
    225  1.20.16.1       scw 	pcc_reg_write(sys_pcc, PCCREG_LANCE_INTR_CTRL,
    226  1.20.16.1       scw 	    pa->pa_ipl | PCC_IENABLE);
    227        1.1     chuck }
    228