Home | History | Annotate | Line # | Download | only in dev
if_ne_zbus.c revision 1.1.4.1
      1  1.1.4.1     he /*	$NetBSD: if_ne_zbus.c,v 1.1.4.1 2000/01/23 13:38:01 he Exp $	*/
      2      1.1  veego 
      3      1.1  veego /*-
      4      1.1  veego  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5      1.1  veego  * All rights reserved.
      6      1.1  veego  *
      7      1.1  veego  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1  veego  * by Bernd Ernesti.
      9      1.1  veego  *
     10      1.1  veego  * Redistribution and use in source and binary forms, with or without
     11      1.1  veego  * modification, are permitted provided that the following conditions
     12      1.1  veego  * are met:
     13      1.1  veego  * 1. Redistributions of source code must retain the above copyright
     14      1.1  veego  *    notice, this list of conditions and the following disclaimer.
     15      1.1  veego  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1  veego  *    notice, this list of conditions and the following disclaimer in the
     17      1.1  veego  *    documentation and/or other materials provided with the distribution.
     18      1.1  veego  * 3. All advertising materials mentioning features or use of this software
     19      1.1  veego  *    must display the following acknowledgement:
     20      1.1  veego  *	This product includes software developed by the NetBSD
     21      1.1  veego  *	Foundation, Inc. and its contributors.
     22      1.1  veego  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.1  veego  *    contributors may be used to endorse or promote products derived
     24      1.1  veego  *    from this software without specific prior written permission.
     25      1.1  veego  *
     26      1.1  veego  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.1  veego  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.1  veego  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.1  veego  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.1  veego  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.1  veego  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.1  veego  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.1  veego  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.1  veego  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.1  veego  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.1  veego  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1  veego  */
     38      1.1  veego 
     39      1.1  veego /*
     40      1.1  veego  * Thanks to Village Tronic for giving me a card.
     41      1.1  veego  * Bernd Ernesti
     42      1.1  veego  */
     43      1.1  veego 
     44      1.1  veego #include <sys/param.h>
     45      1.1  veego #include <sys/device.h>
     46      1.1  veego #include <sys/malloc.h>
     47      1.1  veego #include <sys/mbuf.h>
     48      1.1  veego #include <sys/socket.h>
     49      1.1  veego #include <sys/syslog.h>
     50      1.1  veego #include <sys/systm.h>
     51      1.1  veego 
     52      1.1  veego #include <net/if.h>
     53      1.1  veego #include <net/if_media.h>
     54      1.1  veego #include <net/if_ether.h>
     55      1.1  veego 
     56      1.1  veego #include <machine/bus.h>
     57      1.1  veego 
     58      1.1  veego #include <dev/ic/dp8390reg.h>
     59      1.1  veego #include <dev/ic/dp8390var.h>
     60      1.1  veego 
     61      1.1  veego #include <dev/ic/ne2000reg.h>
     62      1.1  veego #include <dev/ic/ne2000var.h>
     63      1.1  veego 
     64      1.1  veego #include <dev/ic/rtl80x9reg.h>
     65      1.1  veego #include <dev/ic/rtl80x9var.h>
     66      1.1  veego 
     67      1.1  veego #include <amiga/amiga/device.h>
     68      1.1  veego #include <amiga/amiga/isr.h>
     69      1.1  veego 
     70      1.1  veego #include <amiga/dev/zbusvar.h>
     71      1.1  veego 
     72      1.1  veego int	ne_zbus_match __P((struct device *, struct cfdata *, void *));
     73      1.1  veego void	ne_zbus_attach __P((struct device *, struct device *, void *));
     74      1.1  veego 
     75      1.1  veego struct ne_zbus_softc {
     76      1.1  veego 	struct ne2000_softc	sc_ne2000;
     77      1.1  veego 	struct bus_space_tag	sc_bst;
     78      1.1  veego 	struct isr		sc_isr;
     79      1.1  veego };
     80      1.1  veego 
     81      1.1  veego struct cfattach ne_zbus_ca = {
     82      1.1  veego 	sizeof(struct ne_zbus_softc), ne_zbus_match, ne_zbus_attach
     83      1.1  veego };
     84      1.1  veego 
     85      1.1  veego /* The amiga address are shifted by one bit to the ISA-Bus. */
     86      1.1  veego #define	NE_ARIADNE_II_NPORTS	0x40
     87      1.1  veego #define	NE_ARIADNE_II_NICBASE	0x0300	/* 0x0600 */
     88      1.1  veego #define	NE_ARIADNE_II_NICSIZE	0x20
     89      1.1  veego #define	NE_ARIADNE_II_ASICBASE	0x0310	/* 0x0620 */
     90      1.1  veego #define	NE_ARIADNE_II_ASICSIZE	0x20
     91      1.1  veego 
     92      1.1  veego int
     93      1.1  veego ne_zbus_match(parent, cf, aux)
     94      1.1  veego 	struct device *parent;
     95      1.1  veego 	struct cfdata *cf;
     96      1.1  veego 	void *aux;
     97      1.1  veego {
     98      1.1  veego 	struct zbus_args *zap = aux;
     99      1.1  veego 
    100      1.1  veego 	/* Ariadne II ethernet card */
    101      1.1  veego 	if (zap->manid == 2167 && zap->prodid == 202)
    102      1.1  veego 		return (1);
    103      1.1  veego 
    104  1.1.4.1     he 	/* X-serv ethernet card */
    105  1.1.4.1     he 	if (zap->manid == 4626 && zap->prodid == 23)
    106  1.1.4.1     he 		return (1);
    107  1.1.4.1     he 
    108      1.1  veego 	return (0);
    109      1.1  veego }
    110      1.1  veego 
    111      1.1  veego /*
    112      1.1  veego  * Install interface into kernel networking data structures
    113      1.1  veego  */
    114      1.1  veego void
    115      1.1  veego ne_zbus_attach(parent, self, aux)
    116      1.1  veego 	struct device *parent, *self;
    117      1.1  veego 	void   *aux;
    118      1.1  veego {
    119      1.1  veego 	struct ne_zbus_softc *zsc = (struct ne_zbus_softc *)self;
    120      1.1  veego 	struct ne2000_softc *nsc = &zsc->sc_ne2000;
    121      1.1  veego 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
    122      1.1  veego 	struct zbus_args *zap = aux;
    123      1.1  veego 	bus_space_tag_t nict = &zsc->sc_bst;
    124      1.1  veego 	bus_space_handle_t nich;
    125      1.1  veego 	bus_space_tag_t asict = nict;
    126      1.1  veego 	bus_space_handle_t asich;
    127      1.1  veego 	int *media, nmedia, defmedia;
    128      1.1  veego 
    129      1.1  veego 	media = NULL;
    130      1.1  veego 	nmedia = defmedia = 0;
    131      1.1  veego 
    132      1.1  veego 	dsc->sc_mediachange = rtl80x9_mediachange;
    133      1.1  veego 	dsc->sc_mediastatus = rtl80x9_mediastatus;
    134      1.1  veego 	dsc->init_card = rtl80x9_init_card;
    135      1.1  veego 
    136      1.1  veego 	zsc->sc_bst.base = (u_long)zap->va + 0;
    137  1.1.4.1     he 	if (zap->manid == 4626)
    138  1.1.4.1     he 		 zsc->sc_bst.base += 0x8000;
    139  1.1.4.1     he 
    140      1.1  veego 	zsc->sc_bst.stride = 1;
    141      1.1  veego 	zsc->sc_bst.absm = &amiga_interleaved_wordaccess_methods;
    142      1.1  veego 
    143      1.1  veego 	printf("\n");
    144      1.1  veego 
    145      1.1  veego 	/* Map i/o space. */
    146      1.1  veego 	if (bus_space_map(nict, NE_ARIADNE_II_NICBASE, NE_ARIADNE_II_NPORTS, 0, &nich)) {
    147      1.1  veego 		printf("%s: can't map nic i/o space\n", dsc->sc_dev.dv_xname);
    148      1.1  veego 		return;
    149      1.1  veego 	}
    150      1.1  veego 
    151      1.1  veego 	if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET, NE_ARIADNE_II_ASICSIZE,
    152      1.1  veego 	    &asich)) {
    153      1.1  veego 		printf("%s: can't map asic i/o space\n", dsc->sc_dev.dv_xname);
    154      1.1  veego 		return;
    155      1.1  veego 	}
    156      1.1  veego 
    157      1.1  veego 	dsc->sc_regt = nict;
    158      1.1  veego 	dsc->sc_regh = nich;
    159      1.1  veego 
    160      1.1  veego 	nsc->sc_asict = asict;
    161      1.1  veego 	nsc->sc_asich = asich;
    162      1.1  veego 
    163      1.1  veego 	/* Initialize media. */
    164      1.1  veego 	rtl80x9_init_media(dsc, &media, &nmedia, &defmedia);
    165      1.1  veego 
    166      1.1  veego 	/* This interface is always enabled. */
    167      1.1  veego 	dsc->sc_enabled = 1;
    168      1.1  veego 
    169      1.1  veego 	/*
    170      1.1  veego 	 * Do generic NE2000 attach.  This will read the station address
    171      1.1  veego 	 * from the EEPROM.
    172      1.1  veego 	 */
    173      1.1  veego 	ne2000_attach(nsc, NULL, media, nmedia, defmedia);
    174      1.1  veego 
    175      1.1  veego 	zsc->sc_isr.isr_intr = dp8390_intr;
    176      1.1  veego 	zsc->sc_isr.isr_arg = dsc;
    177      1.1  veego 	zsc->sc_isr.isr_ipl = 2;
    178      1.1  veego 	add_isr(&zsc->sc_isr);
    179      1.1  veego }
    180