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