Home | History | Annotate | Line # | Download | only in dev
if_le_obio.c revision 1.3
      1 /*	$NetBSD: if_le_obio.c,v 1.3 1998/07/31 22:21:35 pk Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1997 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  * NASA Ames Research Center.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by the NetBSD
     22  *	Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 /*-
     41  * Copyright (c) 1996
     42  *	The President and Fellows of Harvard College. All rights reserved.
     43  * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
     44  * Copyright (c) 1992, 1993
     45  *	The Regents of the University of California.  All rights reserved.
     46  *
     47  * This code is derived from software contributed to Berkeley by
     48  * Ralph Campbell and Rick Macklem.
     49  *
     50  * Redistribution and use in source and binary forms, with or without
     51  * modification, are permitted provided that the following conditions
     52  * are met:
     53  * 1. Redistributions of source code must retain the above copyright
     54  *    notice, this list of conditions and the following disclaimer.
     55  * 2. Redistributions in binary form must reproduce the above copyright
     56  *    notice, this list of conditions and the following disclaimer in the
     57  *    documentation and/or other materials provided with the distribution.
     58  * 3. All advertising materials mentioning features or use of this software
     59  *    must display the following acknowledgement:
     60  *	This product includes software developed by Aaron Brown and
     61  *	Harvard University.
     62  *	This product includes software developed by the University of
     63  *	California, Berkeley and its contributors.
     64  * 4. Neither the name of the University nor the names of its contributors
     65  *    may be used to endorse or promote products derived from this software
     66  *    without specific prior written permission.
     67  *
     68  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     69  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     70  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     71  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     72  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     73  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     74  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     75  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     76  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     77  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     78  * SUCH DAMAGE.
     79  *
     80  *	@(#)if_le.c	8.2 (Berkeley) 11/16/93
     81  */
     82 
     83 #include "opt_inet.h"
     84 #include "bpfilter.h"
     85 
     86 #include <sys/param.h>
     87 #include <sys/systm.h>
     88 #include <sys/mbuf.h>
     89 #include <sys/syslog.h>
     90 #include <sys/socket.h>
     91 #include <sys/device.h>
     92 #include <sys/malloc.h>
     93 
     94 #include <net/if.h>
     95 #include <net/if_ether.h>
     96 #include <net/if_media.h>
     97 
     98 #ifdef INET
     99 #include <netinet/in.h>
    100 #include <netinet/if_inarp.h>
    101 #endif
    102 
    103 #include <machine/autoconf.h>
    104 #include <machine/cpu.h>
    105 
    106 #include <dev/ic/lancereg.h>
    107 #include <dev/ic/lancevar.h>
    108 #include <dev/ic/am7990reg.h>
    109 #include <dev/ic/am7990var.h>
    110 
    111 /*
    112  * LANCE registers.
    113  */
    114 struct lereg1 {
    115 	volatile u_int16_t	ler1_rdp;	/* data port */
    116 	volatile u_int16_t	ler1_rap;	/* register select port */
    117 };
    118 
    119 struct	le_softc {
    120 	struct	am7990_softc sc_am7990;	/* glue to MI code */
    121 	bus_space_tag_t	sc_bustag;
    122 	bus_dma_tag_t	sc_dmatag;
    123 	struct	lereg1 *sc_r1;		/* LANCE registers */
    124 };
    125 
    126 #define MEMSIZE 0x4000		/* LANCE memory size */
    127 
    128 int	lematch_obio __P((struct device *, struct cfdata *, void *));
    129 void	leattach_obio __P((struct device *, struct device *, void *));
    130 
    131 /*
    132  * Media types supported.
    133  */
    134 static int lemedia[] = {
    135 	IFM_ETHER|IFM_10_T,
    136 };
    137 #define NLEMEDIA	(sizeof(lemedia) / sizeof(lemedia[0]))
    138 
    139 struct cfattach le_obio_ca = {
    140 	sizeof(struct le_softc), lematch_obio, leattach_obio
    141 };
    142 
    143 extern struct cfdriver le_cd;
    144 
    145 #if defined(_KERNEL) && !defined(_LKM)
    146 #include "opt_ddb.h"
    147 #endif
    148 
    149 #ifdef DDB
    150 #define	integrate
    151 #define hide
    152 #else
    153 #define	integrate	static __inline
    154 #define hide		static
    155 #endif
    156 
    157 static void lewrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
    158 static u_int16_t lerdcsr __P((struct lance_softc *, u_int16_t));
    159 
    160 static void
    161 lewrcsr(sc, port, val)
    162 	struct lance_softc *sc;
    163 	u_int16_t port, val;
    164 {
    165 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    166 
    167 	ler1->ler1_rap = port;
    168 	ler1->ler1_rdp = val;
    169 }
    170 
    171 static u_int16_t
    172 lerdcsr(sc, port)
    173 	struct lance_softc *sc;
    174 	u_int16_t port;
    175 {
    176 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    177 	u_int16_t val;
    178 
    179 	ler1->ler1_rap = port;
    180 	val = ler1->ler1_rdp;
    181 	return (val);
    182 }
    183 
    184 int
    185 lematch_obio(parent, cf, aux)
    186 	struct device *parent;
    187 	struct cfdata *cf;
    188 	void *aux;
    189 {
    190 	union obio_attach_args *uoba = aux;
    191 	struct obio4_attach_args *oba;
    192 
    193 	if (uoba->uoba_isobio4 == 0)
    194 		return (0);
    195 
    196 	oba = &uoba->uoba_oba4;
    197 	return (bus_space_probe(oba->oba_bustag, 0, oba->oba_paddr,
    198 				2,	/* probe size */
    199 				0,	/* offset */
    200 				0,	/* flags */
    201 				NULL, NULL));
    202 }
    203 
    204 void
    205 leattach_obio(parent, self, aux)
    206 	struct device *parent, *self;
    207 	void *aux;
    208 {
    209 	union obio_attach_args *uoba = aux;
    210 	struct obio4_attach_args *oba = &uoba->uoba_oba4;
    211 	struct le_softc *lesc = (struct le_softc *)self;
    212 	struct lance_softc *sc = &lesc->sc_am7990.lsc;
    213 	bus_space_handle_t bh;
    214 	bus_dma_segment_t seg;
    215 	int rseg;
    216 	/* XXX the following declarations should be elsewhere */
    217 	extern void myetheraddr __P((u_char *));
    218 
    219 	lesc->sc_bustag = oba->oba_bustag;
    220 	lesc->sc_dmatag = oba->oba_dmatag;
    221 
    222 	if (obio_bus_map(oba->oba_bustag, oba->oba_paddr,
    223 			 0, sizeof(struct lereg1),
    224 			 0, 0,
    225 			 &bh) != 0) {
    226 		printf("%s @ obio: cannot map registers\n", self->dv_xname);
    227 		return;
    228 	}
    229 	lesc->sc_r1 = (struct lereg1 *)bh;
    230 
    231 	if (oba->oba_bp != NULL &&
    232 	    strcmp(oba->oba_bp->name, le_cd.cd_name) == 0 &&
    233 	    sc->sc_dev.dv_unit == oba->oba_bp->val[1])
    234 		oba->oba_bp->dev = &sc->sc_dev;
    235 
    236 
    237 	if (bus_dmamem_alloc(lesc->sc_dmatag, MEMSIZE, NBPG, 0,
    238 			     &seg, 1, &rseg,
    239 			     BUS_DMA_NOWAIT | BUS_DMA_24BIT) != 0) {
    240 		printf("%s @ obio: DMA memory allocation error\n",
    241 			self->dv_xname);
    242 		return;
    243 	}
    244 	if (bus_dmamem_map(lesc->sc_dmatag, &seg, rseg, MEMSIZE,
    245 			   (caddr_t *)&sc->sc_mem,
    246 			   BUS_DMA_NOWAIT|BUS_DMA_COHERENT) != 0) {
    247 		printf("%s @ obio: DMA memory map error\n", self->dv_xname);
    248 		bus_dmamem_free(lesc->sc_dmatag, &seg, rseg);
    249 		return;
    250 	}
    251 	sc->sc_addr = seg.ds_addr & 0xffffff;
    252 	sc->sc_memsize = MEMSIZE;
    253 	sc->sc_conf3 = LE_C3_BSWP | LE_C3_ACON | LE_C3_BCON;
    254 
    255 	sc->sc_supmedia = lemedia;
    256 	sc->sc_nsupmedia = NLEMEDIA;
    257 	sc->sc_defaultmedia = lemedia[0];
    258 
    259 	myetheraddr(sc->sc_enaddr);
    260 
    261 	sc->sc_copytodesc = lance_copytobuf_contig;
    262 	sc->sc_copyfromdesc = lance_copyfrombuf_contig;
    263 	sc->sc_copytobuf = lance_copytobuf_contig;
    264 	sc->sc_copyfrombuf = lance_copyfrombuf_contig;
    265 	sc->sc_zerobuf = lance_zerobuf_contig;
    266 
    267 	sc->sc_rdcsr = lerdcsr;
    268 	sc->sc_wrcsr = lewrcsr;
    269 
    270 	am7990_config(&lesc->sc_am7990);
    271 
    272 	/* Install interrupt */
    273 	(void)bus_intr_establish(lesc->sc_bustag, oba->oba_pri, 0,
    274 				 am7990_intr, sc);
    275 }
    276