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