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