Home | History | Annotate | Line # | Download | only in dev
if_ne_zbus.c revision 1.2
      1 /*	$NetBSD: if_ne_zbus.c,v 1.2 1999/11/25 21:53:01 is 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 Bernd Ernesti.
      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  * Thanks to Village Tronic for giving me a card.
     41  * Bernd Ernesti
     42  */
     43 
     44 #include <sys/param.h>
     45 #include <sys/device.h>
     46 #include <sys/malloc.h>
     47 #include <sys/mbuf.h>
     48 #include <sys/socket.h>
     49 #include <sys/syslog.h>
     50 #include <sys/systm.h>
     51 
     52 #include <net/if.h>
     53 #include <net/if_media.h>
     54 #include <net/if_ether.h>
     55 
     56 #include <machine/bus.h>
     57 
     58 #include <dev/ic/dp8390reg.h>
     59 #include <dev/ic/dp8390var.h>
     60 
     61 #include <dev/ic/ne2000reg.h>
     62 #include <dev/ic/ne2000var.h>
     63 
     64 #include <dev/ic/rtl80x9reg.h>
     65 #include <dev/ic/rtl80x9var.h>
     66 
     67 #include <amiga/amiga/device.h>
     68 #include <amiga/amiga/isr.h>
     69 
     70 #include <amiga/dev/zbusvar.h>
     71 
     72 int	ne_zbus_match __P((struct device *, struct cfdata *, void *));
     73 void	ne_zbus_attach __P((struct device *, struct device *, void *));
     74 
     75 struct ne_zbus_softc {
     76 	struct ne2000_softc	sc_ne2000;
     77 	struct bus_space_tag	sc_bst;
     78 	struct isr		sc_isr;
     79 };
     80 
     81 struct cfattach ne_zbus_ca = {
     82 	sizeof(struct ne_zbus_softc), ne_zbus_match, ne_zbus_attach
     83 };
     84 
     85 /* The amiga address are shifted by one bit to the ISA-Bus. */
     86 #define	NE_ARIADNE_II_NPORTS	0x40
     87 #define	NE_ARIADNE_II_NICBASE	0x0300	/* 0x0600 */
     88 #define	NE_ARIADNE_II_NICSIZE	0x20
     89 #define	NE_ARIADNE_II_ASICBASE	0x0310	/* 0x0620 */
     90 #define	NE_ARIADNE_II_ASICSIZE	0x20
     91 
     92 int
     93 ne_zbus_match(parent, cf, aux)
     94 	struct device *parent;
     95 	struct cfdata *cf;
     96 	void *aux;
     97 {
     98 	struct zbus_args *zap = aux;
     99 
    100 	/* Ariadne II ethernet card */
    101 	if (zap->manid == 2167 && zap->prodid == 202)
    102 		return (1);
    103 
    104 	/* X-serv ethernet card */
    105 	if (zap->manid == 4626 && zap->prodid == 23)
    106 		return (1);
    107 
    108 	return (0);
    109 }
    110 
    111 /*
    112  * Install interface into kernel networking data structures
    113  */
    114 void
    115 ne_zbus_attach(parent, self, aux)
    116 	struct device *parent, *self;
    117 	void   *aux;
    118 {
    119 	struct ne_zbus_softc *zsc = (struct ne_zbus_softc *)self;
    120 	struct ne2000_softc *nsc = &zsc->sc_ne2000;
    121 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
    122 	struct zbus_args *zap = aux;
    123 	bus_space_tag_t nict = &zsc->sc_bst;
    124 	bus_space_handle_t nich;
    125 	bus_space_tag_t asict = nict;
    126 	bus_space_handle_t asich;
    127 	int *media, nmedia, defmedia;
    128 
    129 	media = NULL;
    130 	nmedia = defmedia = 0;
    131 
    132 	dsc->sc_mediachange = rtl80x9_mediachange;
    133 	dsc->sc_mediastatus = rtl80x9_mediastatus;
    134 	dsc->init_card = rtl80x9_init_card;
    135 
    136 	zsc->sc_bst.base = (u_long)zap->va + 0;
    137 	if (zap->manid == 4626)
    138 		 zsc->sc_bst.base += 0x8000;
    139 
    140 	zsc->sc_bst.stride = 1;
    141 	zsc->sc_bst.absm = &amiga_interleaved_wordaccess_methods;
    142 
    143 	printf("\n");
    144 
    145 	/* Map i/o space. */
    146 	if (bus_space_map(nict, NE_ARIADNE_II_NICBASE, NE_ARIADNE_II_NPORTS, 0, &nich)) {
    147 		printf("%s: can't map nic i/o space\n", dsc->sc_dev.dv_xname);
    148 		return;
    149 	}
    150 
    151 	if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET, NE_ARIADNE_II_ASICSIZE,
    152 	    &asich)) {
    153 		printf("%s: can't map asic i/o space\n", dsc->sc_dev.dv_xname);
    154 		return;
    155 	}
    156 
    157 	dsc->sc_regt = nict;
    158 	dsc->sc_regh = nich;
    159 
    160 	nsc->sc_asict = asict;
    161 	nsc->sc_asich = asich;
    162 
    163 	/* Initialize media. */
    164 	rtl80x9_init_media(dsc, &media, &nmedia, &defmedia);
    165 
    166 	/* This interface is always enabled. */
    167 	dsc->sc_enabled = 1;
    168 
    169 	/*
    170 	 * Do generic NE2000 attach.  This will read the station address
    171 	 * from the EEPROM.
    172 	 */
    173 	ne2000_attach(nsc, NULL, media, nmedia, defmedia);
    174 
    175 	zsc->sc_isr.isr_intr = dp8390_intr;
    176 	zsc->sc_isr.isr_arg = dsc;
    177 	zsc->sc_isr.isr_ipl = 2;
    178 	add_isr(&zsc->sc_isr);
    179 }
    180