Home | History | Annotate | Line # | Download | only in dev
if_ne_zbus.c revision 1.14.12.1
      1  1.14.12.1      riz /*	$NetBSD: if_ne_zbus.c,v 1.14.12.1 2013/06/06 02:58:12 riz 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  *
     19        1.1    veego  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.1    veego  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.1    veego  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.1    veego  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.1    veego  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.1    veego  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.1    veego  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.1    veego  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.1    veego  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.1    veego  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.1    veego  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1    veego  */
     31        1.9  aymeric 
     32        1.9  aymeric #include <sys/cdefs.h>
     33  1.14.12.1      riz __KERNEL_RCSID(0, "$NetBSD: if_ne_zbus.c,v 1.14.12.1 2013/06/06 02:58:12 riz Exp $");
     34        1.1    veego 
     35        1.1    veego /*
     36        1.1    veego  * Thanks to Village Tronic for giving me a card.
     37        1.1    veego  * Bernd Ernesti
     38        1.1    veego  */
     39        1.1    veego 
     40        1.1    veego #include <sys/param.h>
     41        1.1    veego #include <sys/device.h>
     42        1.1    veego #include <sys/malloc.h>
     43        1.1    veego #include <sys/mbuf.h>
     44        1.1    veego #include <sys/socket.h>
     45        1.1    veego #include <sys/syslog.h>
     46        1.1    veego #include <sys/systm.h>
     47       1.14   dyoung #include <sys/bus.h>
     48        1.1    veego 
     49        1.1    veego #include <net/if.h>
     50        1.1    veego #include <net/if_media.h>
     51        1.1    veego #include <net/if_ether.h>
     52        1.1    veego 
     53        1.1    veego #include <dev/ic/dp8390reg.h>
     54        1.1    veego #include <dev/ic/dp8390var.h>
     55        1.1    veego 
     56        1.1    veego #include <dev/ic/ne2000reg.h>
     57        1.1    veego #include <dev/ic/ne2000var.h>
     58        1.8  aymeric 
     59        1.1    veego #include <dev/ic/rtl80x9reg.h>
     60        1.1    veego #include <dev/ic/rtl80x9var.h>
     61        1.1    veego 
     62        1.1    veego #include <amiga/amiga/device.h>
     63        1.1    veego #include <amiga/amiga/isr.h>
     64        1.1    veego 
     65        1.1    veego #include <amiga/dev/zbusvar.h>
     66        1.1    veego 
     67       1.12     cube int	ne_zbus_match(device_t, cfdata_t , void *);
     68       1.12     cube void	ne_zbus_attach(device_t, device_t, void *);
     69        1.1    veego 
     70        1.1    veego struct ne_zbus_softc {
     71        1.1    veego 	struct ne2000_softc	sc_ne2000;
     72        1.1    veego 	struct bus_space_tag	sc_bst;
     73        1.1    veego 	struct isr		sc_isr;
     74        1.1    veego };
     75        1.1    veego 
     76       1.12     cube CFATTACH_DECL_NEW(ne_zbus, sizeof(struct ne_zbus_softc),
     77       1.11  thorpej     ne_zbus_match, ne_zbus_attach, NULL, NULL);
     78        1.1    veego 
     79        1.3       is /*
     80        1.8  aymeric  * The Amiga address are shifted by one bit to the ISA-Bus, but
     81        1.3       is  * this is handled by the bus_space functions.
     82        1.3       is  */
     83        1.3       is #define	NE_ARIADNE_II_NPORTS	0x20
     84        1.1    veego #define	NE_ARIADNE_II_NICBASE	0x0300	/* 0x0600 */
     85        1.3       is #define	NE_ARIADNE_II_NICSIZE	0x10
     86        1.1    veego #define	NE_ARIADNE_II_ASICBASE	0x0310	/* 0x0620 */
     87        1.3       is #define	NE_ARIADNE_II_ASICSIZE	0x10
     88        1.1    veego 
     89  1.14.12.1      riz /*
     90  1.14.12.1      riz  * E3B Deneb firmware v11 creates fake X-Surf autoconfig entry.
     91  1.14.12.1      riz  * Do not attach ne driver to this fake card, otherwise kernel panic
     92  1.14.12.1      riz  * may occur.
     93  1.14.12.1      riz  */
     94  1.14.12.1      riz #define DENEB_XSURF_SERNO	0xC0FFEE01	/* Serial of the fake card */
     95  1.14.12.1      riz 
     96        1.1    veego int
     97       1.12     cube ne_zbus_match(device_t parent, cfdata_t cf, void *aux)
     98        1.1    veego {
     99        1.1    veego 	struct zbus_args *zap = aux;
    100        1.1    veego 
    101        1.1    veego 	/* Ariadne II ethernet card */
    102        1.1    veego 	if (zap->manid == 2167 && zap->prodid == 202)
    103        1.1    veego 		return (1);
    104        1.1    veego 
    105        1.6       is 	/* X-surf ethernet card */
    106  1.14.12.1      riz 	if (zap->manid == 4626 && zap->prodid == 23) {
    107  1.14.12.1      riz 		if (zap->serno != DENEB_XSURF_SERNO)
    108  1.14.12.1      riz 			return (1);
    109  1.14.12.1      riz 	}
    110        1.2       is 
    111        1.1    veego 	return (0);
    112        1.1    veego }
    113        1.1    veego 
    114        1.1    veego /*
    115        1.1    veego  * Install interface into kernel networking data structures
    116        1.1    veego  */
    117        1.1    veego void
    118       1.12     cube ne_zbus_attach(device_t parent, device_t self, void *aux)
    119        1.1    veego {
    120       1.12     cube 	struct ne_zbus_softc *zsc = device_private(self);
    121        1.1    veego 	struct ne2000_softc *nsc = &zsc->sc_ne2000;
    122        1.1    veego 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
    123        1.1    veego 	struct zbus_args *zap = aux;
    124        1.1    veego 	bus_space_tag_t nict = &zsc->sc_bst;
    125        1.1    veego 	bus_space_handle_t nich;
    126        1.1    veego 	bus_space_tag_t asict = nict;
    127        1.1    veego 	bus_space_handle_t asich;
    128        1.1    veego 
    129       1.12     cube 	dsc->sc_dev = self;
    130        1.1    veego 	dsc->sc_mediachange = rtl80x9_mediachange;
    131        1.1    veego 	dsc->sc_mediastatus = rtl80x9_mediastatus;
    132        1.1    veego 	dsc->init_card = rtl80x9_init_card;
    133        1.7  thorpej 	dsc->sc_media_init = rtl80x9_media_init;
    134        1.1    veego 
    135        1.1    veego 	zsc->sc_bst.base = (u_long)zap->va + 0;
    136        1.2       is 	if (zap->manid == 4626)
    137        1.2       is 		 zsc->sc_bst.base += 0x8000;
    138        1.2       is 
    139        1.5  aymeric 	zsc->sc_bst.absm = &amiga_bus_stride_2;
    140        1.1    veego 
    141       1.12     cube 	aprint_normal("\n");
    142        1.1    veego 
    143        1.1    veego 	/* Map i/o space. */
    144        1.1    veego 	if (bus_space_map(nict, NE_ARIADNE_II_NICBASE, NE_ARIADNE_II_NPORTS, 0, &nich)) {
    145       1.12     cube 		aprint_error_dev(self, "can't map nic i/o space\n");
    146        1.1    veego 		return;
    147        1.1    veego 	}
    148        1.1    veego 
    149        1.1    veego 	if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET, NE_ARIADNE_II_ASICSIZE,
    150        1.1    veego 	    &asich)) {
    151       1.12     cube 		aprint_error_dev(self, "can't map asic i/o space\n");
    152        1.8  aymeric 		return;
    153        1.1    veego 	}
    154        1.1    veego 
    155        1.1    veego 	dsc->sc_regt = nict;
    156        1.1    veego 	dsc->sc_regh = nich;
    157        1.1    veego 
    158        1.1    veego 	nsc->sc_asict = asict;
    159        1.1    veego 	nsc->sc_asich = asich;
    160        1.1    veego 
    161        1.1    veego 	/* This interface is always enabled. */
    162        1.1    veego 	dsc->sc_enabled = 1;
    163        1.1    veego 
    164        1.1    veego 	/*
    165        1.1    veego 	 * Do generic NE2000 attach.  This will read the station address
    166        1.1    veego 	 * from the EEPROM.
    167        1.1    veego 	 */
    168        1.7  thorpej 	ne2000_attach(nsc, NULL);
    169        1.1    veego 
    170        1.1    veego 	zsc->sc_isr.isr_intr = dp8390_intr;
    171        1.1    veego 	zsc->sc_isr.isr_arg = dsc;
    172        1.1    veego 	zsc->sc_isr.isr_ipl = 2;
    173        1.1    veego 	add_isr(&zsc->sc_isr);
    174        1.1    veego }
    175