Home | History | Annotate | Line # | Download | only in dev
if_le_obio.c revision 1.18.2.2
      1  1.18.2.1    skrll /*	$NetBSD: if_le_obio.c,v 1.18.2.2 2004/09/18 14:40:27 skrll Exp $	*/
      2       1.1       pk 
      3       1.1       pk /*-
      4       1.4  mycroft  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
      5       1.1       pk  * All rights reserved.
      6       1.1       pk  *
      7       1.1       pk  * This code is derived from software contributed to The NetBSD Foundation
      8       1.5       pk  * by Charles M. Hannum; Jason R. Thorpe of the Numerical Aerospace
      9       1.5       pk  * Simulation Facility, NASA Ames Research Center; Paul Kranenburg.
     10       1.1       pk  *
     11       1.1       pk  * Redistribution and use in source and binary forms, with or without
     12       1.1       pk  * modification, are permitted provided that the following conditions
     13       1.1       pk  * are met:
     14       1.1       pk  * 1. Redistributions of source code must retain the above copyright
     15       1.1       pk  *    notice, this list of conditions and the following disclaimer.
     16       1.1       pk  * 2. Redistributions in binary form must reproduce the above copyright
     17       1.1       pk  *    notice, this list of conditions and the following disclaimer in the
     18       1.1       pk  *    documentation and/or other materials provided with the distribution.
     19       1.1       pk  * 3. All advertising materials mentioning features or use of this software
     20       1.1       pk  *    must display the following acknowledgement:
     21       1.1       pk  *	This product includes software developed by the NetBSD
     22       1.1       pk  *	Foundation, Inc. and its contributors.
     23       1.1       pk  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24       1.1       pk  *    contributors may be used to endorse or promote products derived
     25       1.1       pk  *    from this software without specific prior written permission.
     26       1.1       pk  *
     27       1.1       pk  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28       1.1       pk  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29       1.1       pk  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30       1.1       pk  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31       1.1       pk  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32       1.1       pk  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33       1.1       pk  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34       1.1       pk  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35       1.1       pk  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36       1.1       pk  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37       1.1       pk  * POSSIBILITY OF SUCH DAMAGE.
     38       1.1       pk  */
     39       1.1       pk 
     40  1.18.2.1    skrll #include <sys/cdefs.h>
     41  1.18.2.1    skrll __KERNEL_RCSID(0, "$NetBSD: if_le_obio.c,v 1.18.2.2 2004/09/18 14:40:27 skrll Exp $");
     42  1.18.2.1    skrll 
     43       1.1       pk #include "opt_inet.h"
     44       1.1       pk #include "bpfilter.h"
     45       1.1       pk 
     46       1.1       pk #include <sys/param.h>
     47       1.1       pk #include <sys/systm.h>
     48       1.1       pk #include <sys/device.h>
     49       1.1       pk #include <sys/malloc.h>
     50       1.5       pk #include <sys/socket.h>
     51       1.1       pk 
     52      1.18  thorpej #include <uvm/uvm_extern.h>
     53      1.18  thorpej 
     54       1.1       pk #include <net/if.h>
     55       1.1       pk #include <net/if_ether.h>
     56       1.1       pk #include <net/if_media.h>
     57       1.1       pk 
     58       1.8       pk #include <machine/bus.h>
     59       1.8       pk #include <machine/intr.h>
     60       1.1       pk #include <machine/autoconf.h>
     61       1.1       pk 
     62       1.1       pk #include <dev/ic/lancereg.h>
     63       1.1       pk #include <dev/ic/lancevar.h>
     64       1.1       pk #include <dev/ic/am7990reg.h>
     65       1.1       pk #include <dev/ic/am7990var.h>
     66       1.1       pk 
     67       1.1       pk /*
     68       1.1       pk  * LANCE registers.
     69       1.1       pk  */
     70       1.5       pk #define LEREG1_RDP	0	/* Register Data port */
     71       1.5       pk #define LEREG1_RAP	2	/* Register Address port */
     72       1.1       pk 
     73       1.1       pk struct	le_softc {
     74       1.5       pk 	struct	am7990_softc	sc_am7990;	/* glue to MI code */
     75       1.5       pk 	bus_space_tag_t		sc_bustag;
     76       1.5       pk 	bus_dma_tag_t		sc_dmatag;
     77       1.7       pk 	bus_dmamap_t		sc_dmamap;
     78       1.5       pk 	bus_space_handle_t	sc_reg;		/* LANCE registers */
     79       1.1       pk };
     80       1.1       pk 
     81       1.1       pk #define MEMSIZE 0x4000		/* LANCE memory size */
     82       1.1       pk 
     83       1.1       pk int	lematch_obio __P((struct device *, struct cfdata *, void *));
     84       1.1       pk void	leattach_obio __P((struct device *, struct device *, void *));
     85       1.1       pk 
     86       1.1       pk /*
     87       1.1       pk  * Media types supported.
     88       1.1       pk  */
     89       1.1       pk static int lemedia[] = {
     90       1.1       pk 	IFM_ETHER|IFM_10_T,
     91       1.1       pk };
     92       1.1       pk #define NLEMEDIA	(sizeof(lemedia) / sizeof(lemedia[0]))
     93       1.1       pk 
     94      1.15  thorpej CFATTACH_DECL(le_obio, sizeof(struct le_softc),
     95      1.16  thorpej     lematch_obio, leattach_obio, NULL, NULL);
     96       1.1       pk 
     97       1.1       pk extern struct cfdriver le_cd;
     98       1.1       pk 
     99      1.12      mrg #if defined(_KERNEL_OPT)
    100       1.1       pk #include "opt_ddb.h"
    101       1.1       pk #endif
    102       1.1       pk 
    103       1.1       pk static void lewrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
    104       1.1       pk static u_int16_t lerdcsr __P((struct lance_softc *, u_int16_t));
    105       1.1       pk 
    106       1.1       pk static void
    107       1.1       pk lewrcsr(sc, port, val)
    108       1.1       pk 	struct lance_softc *sc;
    109       1.1       pk 	u_int16_t port, val;
    110       1.1       pk {
    111       1.5       pk 	struct le_softc *lesc = (struct le_softc *)sc;
    112  1.18.2.1    skrll 	bus_space_tag_t t = lesc->sc_bustag;
    113  1.18.2.1    skrll 	bus_space_handle_t h = lesc->sc_reg;
    114       1.1       pk 
    115  1.18.2.1    skrll 	bus_space_write_2(t, h, LEREG1_RAP, port);
    116  1.18.2.1    skrll 	bus_space_write_2(t, h, LEREG1_RDP, val);
    117       1.1       pk }
    118       1.1       pk 
    119       1.1       pk static u_int16_t
    120       1.1       pk lerdcsr(sc, port)
    121       1.1       pk 	struct lance_softc *sc;
    122       1.1       pk 	u_int16_t port;
    123       1.1       pk {
    124       1.5       pk 	struct le_softc *lesc = (struct le_softc *)sc;
    125  1.18.2.1    skrll 	bus_space_tag_t t = lesc->sc_bustag;
    126  1.18.2.1    skrll 	bus_space_handle_t h = lesc->sc_reg;
    127       1.1       pk 
    128  1.18.2.1    skrll 	bus_space_write_2(t, h, LEREG1_RAP, port);
    129  1.18.2.1    skrll 	return (bus_space_read_2(t, h, LEREG1_RDP));
    130       1.1       pk }
    131       1.1       pk 
    132       1.1       pk int
    133       1.1       pk lematch_obio(parent, cf, aux)
    134       1.1       pk 	struct device *parent;
    135       1.1       pk 	struct cfdata *cf;
    136       1.1       pk 	void *aux;
    137       1.1       pk {
    138       1.1       pk 	union obio_attach_args *uoba = aux;
    139       1.1       pk 	struct obio4_attach_args *oba;
    140       1.1       pk 
    141       1.1       pk 	if (uoba->uoba_isobio4 == 0)
    142       1.1       pk 		return (0);
    143       1.1       pk 
    144       1.1       pk 	oba = &uoba->uoba_oba4;
    145      1.13       pk 	return (bus_space_probe(oba->oba_bustag, oba->oba_paddr,
    146       1.1       pk 				2,	/* probe size */
    147       1.1       pk 				0,	/* offset */
    148       1.1       pk 				0,	/* flags */
    149       1.1       pk 				NULL, NULL));
    150       1.1       pk }
    151       1.1       pk 
    152       1.1       pk void
    153       1.1       pk leattach_obio(parent, self, aux)
    154       1.1       pk 	struct device *parent, *self;
    155       1.1       pk 	void *aux;
    156       1.1       pk {
    157       1.1       pk 	union obio_attach_args *uoba = aux;
    158       1.1       pk 	struct obio4_attach_args *oba = &uoba->uoba_oba4;
    159       1.1       pk 	struct le_softc *lesc = (struct le_softc *)self;
    160       1.1       pk 	struct lance_softc *sc = &lesc->sc_am7990.lsc;
    161       1.3       pk 	bus_dma_segment_t seg;
    162       1.7       pk 	bus_dma_tag_t dmatag;
    163       1.3       pk 	int rseg;
    164       1.7       pk 	int error;
    165       1.1       pk 
    166       1.1       pk 	lesc->sc_bustag = oba->oba_bustag;
    167       1.7       pk 	lesc->sc_dmatag = dmatag = oba->oba_dmatag;
    168       1.1       pk 
    169      1.13       pk 	if (bus_space_map(oba->oba_bustag, oba->oba_paddr,
    170      1.13       pk 			  2 * sizeof(u_int16_t),
    171      1.13       pk 			  0, &lesc->sc_reg) != 0) {
    172       1.3       pk 		printf("%s @ obio: cannot map registers\n", self->dv_xname);
    173       1.1       pk 		return;
    174       1.1       pk 	}
    175       1.1       pk 
    176       1.7       pk 	/* Get a DMA handle */
    177       1.7       pk 	if ((error = bus_dmamap_create(dmatag, MEMSIZE, 1, MEMSIZE, 0,
    178       1.7       pk 					BUS_DMA_NOWAIT|BUS_DMA_24BIT,
    179       1.7       pk 					&lesc->sc_dmamap)) != 0) {
    180       1.7       pk 		printf("%s: DMA map create error %d\n",
    181       1.7       pk 			self->dv_xname, error);
    182       1.7       pk 		return;
    183       1.7       pk 	}
    184       1.7       pk 
    185       1.7       pk 	/* Allocate DMA buffer */
    186      1.18  thorpej 	if ((error = bus_dmamem_alloc(dmatag, MEMSIZE, PAGE_SIZE, 0,
    187       1.3       pk 			     &seg, 1, &rseg,
    188       1.7       pk 			     BUS_DMA_NOWAIT | BUS_DMA_24BIT)) != 0) {
    189       1.7       pk 		printf("%s: DMA memory allocation error %d\n",
    190       1.7       pk 			self->dv_xname, error);
    191       1.3       pk 		return;
    192       1.3       pk 	}
    193       1.7       pk 	/* Map DMA buffer into kernel space */
    194       1.7       pk 	if ((error = bus_dmamem_map(dmatag, &seg, rseg, MEMSIZE,
    195       1.3       pk 			   (caddr_t *)&sc->sc_mem,
    196       1.7       pk 			   BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
    197       1.7       pk 		printf("%s: DMA memory map error %d\n", self->dv_xname, error);
    198       1.3       pk 		bus_dmamem_free(lesc->sc_dmatag, &seg, rseg);
    199       1.3       pk 		return;
    200       1.3       pk 	}
    201       1.7       pk 	/* Load DMA buffer */
    202       1.9  thorpej 	if ((error = bus_dmamap_load(dmatag, lesc->sc_dmamap,
    203      1.11       pk 				     sc->sc_mem, MEMSIZE, NULL,
    204       1.9  thorpej 				     BUS_DMA_NOWAIT)) != 0) {
    205       1.7       pk 		printf("%s: DMA buffer map load error %d\n",
    206       1.7       pk 			self->dv_xname, error);
    207       1.7       pk 		bus_dmamem_unmap(dmatag, (caddr_t)sc->sc_mem, MEMSIZE);
    208       1.7       pk 		bus_dmamem_free(dmatag, &seg, rseg);
    209       1.7       pk 		return;
    210       1.7       pk 	}
    211       1.7       pk 
    212       1.7       pk 	sc->sc_addr = lesc->sc_dmamap->dm_segs[0].ds_addr & 0xffffff;
    213       1.1       pk 	sc->sc_memsize = MEMSIZE;
    214       1.1       pk 	sc->sc_conf3 = LE_C3_BSWP | LE_C3_ACON | LE_C3_BCON;
    215       1.1       pk 
    216       1.1       pk 	sc->sc_supmedia = lemedia;
    217       1.1       pk 	sc->sc_nsupmedia = NLEMEDIA;
    218       1.1       pk 	sc->sc_defaultmedia = lemedia[0];
    219       1.1       pk 
    220  1.18.2.1    skrll 	prom_getether(0, sc->sc_enaddr);
    221       1.1       pk 
    222       1.1       pk 	sc->sc_copytodesc = lance_copytobuf_contig;
    223       1.1       pk 	sc->sc_copyfromdesc = lance_copyfrombuf_contig;
    224       1.1       pk 	sc->sc_copytobuf = lance_copytobuf_contig;
    225       1.1       pk 	sc->sc_copyfrombuf = lance_copyfrombuf_contig;
    226       1.1       pk 	sc->sc_zerobuf = lance_zerobuf_contig;
    227       1.1       pk 
    228       1.1       pk 	sc->sc_rdcsr = lerdcsr;
    229       1.1       pk 	sc->sc_wrcsr = lewrcsr;
    230       1.1       pk 
    231       1.1       pk 	am7990_config(&lesc->sc_am7990);
    232       1.1       pk 
    233       1.1       pk 	/* Install interrupt */
    234      1.17       pk 	(void)bus_intr_establish(lesc->sc_bustag, oba->oba_pri, IPL_NET,
    235       1.1       pk 				 am7990_intr, sc);
    236       1.1       pk }
    237