Home | History | Annotate | Line # | Download | only in sbus
if_le_lebuffer.c revision 1.3
      1  1.3       pk /*	$NetBSD: if_le_lebuffer.c,v 1.3 1998/08/29 20:32:11 pk Exp $	*/
      2  1.1       pk 
      3  1.1       pk /*-
      4  1.2  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.3       pk  * by Charles M. Hannum; Jason R. Thorpe of the Numerical Aerospace
      9  1.3       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.1       pk 
     41  1.1       pk #include "opt_inet.h"
     42  1.1       pk #include "bpfilter.h"
     43  1.1       pk 
     44  1.1       pk #include <sys/param.h>
     45  1.1       pk #include <sys/systm.h>
     46  1.1       pk #include <sys/mbuf.h>
     47  1.1       pk #include <sys/syslog.h>
     48  1.1       pk #include <sys/socket.h>
     49  1.1       pk #include <sys/device.h>
     50  1.1       pk #include <sys/malloc.h>
     51  1.1       pk 
     52  1.1       pk #include <net/if.h>
     53  1.1       pk #include <net/if_ether.h>
     54  1.1       pk #include <net/if_media.h>
     55  1.1       pk 
     56  1.1       pk #ifdef INET
     57  1.1       pk #include <netinet/in.h>
     58  1.1       pk #include <netinet/if_inarp.h>
     59  1.1       pk #endif
     60  1.1       pk 
     61  1.1       pk #include <machine/autoconf.h>
     62  1.1       pk #include <machine/cpu.h>
     63  1.1       pk 
     64  1.1       pk #include <dev/sbus/sbusvar.h>
     65  1.1       pk #include <dev/sbus/lebuffervar.h>
     66  1.1       pk 
     67  1.1       pk #include <dev/ic/lancereg.h>
     68  1.1       pk #include <dev/ic/lancevar.h>
     69  1.1       pk #include <dev/ic/am7990reg.h>
     70  1.1       pk #include <dev/ic/am7990var.h>
     71  1.1       pk 
     72  1.1       pk /*
     73  1.1       pk  * LANCE registers.
     74  1.1       pk  */
     75  1.3       pk #define LEREG1_RDP	0	/* Register Data port */
     76  1.3       pk #define LEREG1_RAP	2	/* Register Address port */
     77  1.1       pk 
     78  1.1       pk struct	le_softc {
     79  1.3       pk 	struct	am7990_softc	sc_am7990;	/* glue to MI code */
     80  1.3       pk 	struct	sbusdev		sc_sd;		/* sbus device */
     81  1.3       pk 	bus_space_tag_t		sc_bustag;
     82  1.3       pk 	bus_dma_tag_t		sc_dmatag;
     83  1.3       pk 	bus_space_handle_t	sc_reg;		/* LANCE registers */
     84  1.1       pk };
     85  1.1       pk 
     86  1.1       pk 
     87  1.1       pk int	lematch_lebuffer __P((struct device *, struct cfdata *, void *));
     88  1.1       pk void	leattach_lebuffer __P((struct device *, struct device *, void *));
     89  1.1       pk 
     90  1.1       pk /*
     91  1.1       pk  * Media types supported.
     92  1.1       pk  */
     93  1.1       pk static int lemedia[] = {
     94  1.1       pk 	IFM_ETHER|IFM_10_T,
     95  1.1       pk };
     96  1.1       pk #define NLEMEDIA	(sizeof(lemedia) / sizeof(lemedia[0]))
     97  1.1       pk 
     98  1.1       pk struct cfattach le_lebuffer_ca = {
     99  1.1       pk 	sizeof(struct le_softc), lematch_lebuffer, leattach_lebuffer
    100  1.1       pk };
    101  1.1       pk 
    102  1.1       pk extern struct cfdriver le_cd;
    103  1.1       pk 
    104  1.1       pk #if defined(_KERNEL) && !defined(_LKM)
    105  1.1       pk #include "opt_ddb.h"
    106  1.1       pk #endif
    107  1.1       pk 
    108  1.1       pk #ifdef DDB
    109  1.1       pk #define	integrate
    110  1.1       pk #define hide
    111  1.1       pk #else
    112  1.1       pk #define	integrate	static __inline
    113  1.1       pk #define hide		static
    114  1.1       pk #endif
    115  1.1       pk 
    116  1.1       pk static void lewrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
    117  1.1       pk static u_int16_t lerdcsr __P((struct lance_softc *, u_int16_t));
    118  1.1       pk 
    119  1.1       pk static void
    120  1.1       pk lewrcsr(sc, port, val)
    121  1.1       pk 	struct lance_softc *sc;
    122  1.1       pk 	u_int16_t port, val;
    123  1.1       pk {
    124  1.3       pk 	struct le_softc *lesc = (struct le_softc *)sc;
    125  1.1       pk 
    126  1.3       pk 	bus_space_write_2(lesc->sc_bustag, lesc->sc_reg, LEREG1_RAP, port);
    127  1.3       pk 	bus_space_write_2(lesc->sc_bustag, lesc->sc_reg, LEREG1_RDP, val);
    128  1.1       pk 
    129  1.1       pk #if defined(SUN4M)
    130  1.1       pk 	/*
    131  1.1       pk 	 * We need to flush the Sbus->Mbus write buffers. This can most
    132  1.1       pk 	 * easily be accomplished by reading back the register that we
    133  1.1       pk 	 * just wrote (thanks to Chris Torek for this solution).
    134  1.1       pk 	 */
    135  1.1       pk 	if (CPU_ISSUN4M) {
    136  1.1       pk 		volatile u_int16_t discard;
    137  1.3       pk 		discard = bus_space_read_2(lesc->sc_bustag, lesc->sc_reg,
    138  1.3       pk 					   LEREG1_RDP);
    139  1.1       pk 	}
    140  1.1       pk #endif
    141  1.1       pk }
    142  1.1       pk 
    143  1.1       pk static u_int16_t
    144  1.1       pk lerdcsr(sc, port)
    145  1.1       pk 	struct lance_softc *sc;
    146  1.1       pk 	u_int16_t port;
    147  1.1       pk {
    148  1.3       pk 	struct le_softc *lesc = (struct le_softc *)sc;
    149  1.1       pk 
    150  1.3       pk 	bus_space_write_2(lesc->sc_bustag, lesc->sc_reg, LEREG1_RAP, port);
    151  1.3       pk 	return (bus_space_read_2(lesc->sc_bustag, lesc->sc_reg, LEREG1_RDP));
    152  1.1       pk }
    153  1.1       pk 
    154  1.1       pk int
    155  1.1       pk lematch_lebuffer(parent, cf, aux)
    156  1.1       pk 	struct device *parent;
    157  1.1       pk 	struct cfdata *cf;
    158  1.1       pk 	void *aux;
    159  1.1       pk {
    160  1.1       pk 	struct sbus_attach_args *sa = aux;
    161  1.1       pk 
    162  1.1       pk 	return (strcmp(cf->cf_driver->cd_name, sa->sa_name) == 0);
    163  1.1       pk }
    164  1.1       pk 
    165  1.1       pk 
    166  1.1       pk #define SAME_LANCE(bp, sa) \
    167  1.3       pk 	(bp->val[0] == sa->sa_slot && bp->val[1] == sa->sa_offset)
    168  1.1       pk 
    169  1.1       pk 
    170  1.1       pk void
    171  1.1       pk leattach_lebuffer(parent, self, aux)
    172  1.1       pk 	struct device *parent, *self;
    173  1.1       pk 	void *aux;
    174  1.1       pk {
    175  1.1       pk 	struct sbus_attach_args *sa = aux;
    176  1.1       pk 	struct le_softc *lesc = (struct le_softc *)self;
    177  1.1       pk 	struct lance_softc *sc = &lesc->sc_am7990.lsc;
    178  1.1       pk 	struct lebuf_softc *lebuf = (struct lebuf_softc *)parent;
    179  1.1       pk 	/* XXX the following declarations should be elsewhere */
    180  1.1       pk 	extern void myetheraddr __P((u_char *));
    181  1.1       pk 
    182  1.1       pk 	lesc->sc_bustag = sa->sa_bustag;
    183  1.1       pk 	lesc->sc_dmatag = sa->sa_dmatag;
    184  1.1       pk 
    185  1.1       pk 	if (bus_space_map2(sa->sa_bustag,
    186  1.1       pk 			   sa->sa_slot,
    187  1.1       pk 			   sa->sa_offset,
    188  1.3       pk 			   sa->sa_size,
    189  1.1       pk 			   BUS_SPACE_MAP_LINEAR,
    190  1.3       pk 			   0, &lesc->sc_reg)) {
    191  1.1       pk 		printf("%s @ lebuffer: cannot map registers\n", self->dv_xname);
    192  1.1       pk 		return;
    193  1.1       pk 	}
    194  1.1       pk 
    195  1.1       pk 	sc->sc_mem = lebuf->sc_buffer;
    196  1.1       pk 	sc->sc_memsize = lebuf->sc_bufsiz;
    197  1.1       pk 	sc->sc_addr = 0; /* Lance view is offset by buffer location */
    198  1.1       pk 	lebuf->attached = 1;
    199  1.1       pk 
    200  1.1       pk 	/* That old black magic... */
    201  1.1       pk 	sc->sc_conf3 = getpropint(sa->sa_node, "busmaster-regval",
    202  1.1       pk 				  LE_C3_BSWP | LE_C3_ACON | LE_C3_BCON);
    203  1.1       pk 
    204  1.1       pk 	/* Assume SBus is grandparent */
    205  1.1       pk 	lesc->sc_sd.sd_reset = (void *)lance_reset;
    206  1.1       pk 	sbus_establish(&lesc->sc_sd, parent);
    207  1.1       pk 
    208  1.1       pk 	if (sa->sa_bp != NULL && strcmp(sa->sa_bp->name, le_cd.cd_name) == 0 &&
    209  1.1       pk 	    SAME_LANCE(sa->sa_bp, sa))
    210  1.1       pk 		sa->sa_bp->dev = &sc->sc_dev;
    211  1.1       pk 
    212  1.1       pk 	sc->sc_supmedia = lemedia;
    213  1.1       pk 	sc->sc_nsupmedia = NLEMEDIA;
    214  1.1       pk 	sc->sc_defaultmedia = lemedia[0];
    215  1.1       pk 
    216  1.1       pk 	myetheraddr(sc->sc_enaddr);
    217  1.1       pk 
    218  1.1       pk 	sc->sc_copytodesc = lance_copytobuf_contig;
    219  1.1       pk 	sc->sc_copyfromdesc = lance_copyfrombuf_contig;
    220  1.1       pk 	sc->sc_copytobuf = lance_copytobuf_contig;
    221  1.1       pk 	sc->sc_copyfrombuf = lance_copyfrombuf_contig;
    222  1.1       pk 	sc->sc_zerobuf = lance_zerobuf_contig;
    223  1.1       pk 
    224  1.1       pk 	sc->sc_rdcsr = lerdcsr;
    225  1.1       pk 	sc->sc_wrcsr = lewrcsr;
    226  1.1       pk 
    227  1.1       pk 	am7990_config(&lesc->sc_am7990);
    228  1.1       pk 
    229  1.1       pk 	(void)bus_intr_establish(lesc->sc_bustag, sa->sa_pri, 0,
    230  1.1       pk 				 am7990_intr, sc);
    231  1.1       pk }
    232