Home | History | Annotate | Line # | Download | only in dev
      1 /*	$NetBSD: if_ne_xsh.c,v 1.5 2023/12/20 00:40:42 thorpej Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2013 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Radoslaw Kujawa.
      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 100 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 <machine/cpu.h>
     47 
     48 #include <net/if.h>
     49 #include <net/if_media.h>
     50 #include <net/if_ether.h>
     51 
     52 #include <dev/ic/dp8390reg.h>
     53 #include <dev/ic/dp8390var.h>
     54 
     55 #include <dev/ic/ne2000reg.h>
     56 #include <dev/ic/ne2000var.h>
     57 
     58 #include <dev/ic/ax88190var.h>
     59 
     60 #include <amiga/amiga/device.h>
     61 #include <amiga/amiga/isr.h>
     62 
     63 #include <amiga/dev/xshvar.h>
     64 #include <amiga/dev/zbusvar.h>
     65 
     66 /* #define NE_XSH_DEBUG 1 */
     67 
     68 int	ne_xsh_match(device_t, cfdata_t , void *);
     69 void	ne_xsh_attach(device_t, device_t, void *);
     70 #ifdef NE_XSH_DEBUG
     71 void	ne_xsh_debug_mapping(bus_space_tag_t, bus_space_handle_t,
     72 	    bus_space_handle_t);
     73 #endif /* NE_XSH_DEBUG */
     74 
     75 struct ne_xsh_softc {
     76 	struct ne2000_softc	sc_ne2000;
     77 	struct bus_space_tag	sc_bst;
     78 	struct isr		sc_isr;
     79 };
     80 
     81 CFATTACH_DECL_NEW(ne_xsh, sizeof(struct ne_xsh_softc),
     82     ne_xsh_match, ne_xsh_attach, NULL, NULL);
     83 
     84 int
     85 ne_xsh_match(device_t parent, cfdata_t cf, void *aux)
     86 {
     87 	struct xshbus_attach_args *xap = aux;
     88 
     89 	if (strcmp(xap->xaa_name, "ne_xsh") != 0)
     90 		return 0;
     91 
     92 	return 1;
     93 }
     94 
     95 void
     96 ne_xsh_attach(device_t parent, device_t self, void *aux)
     97 {
     98 	struct ne_xsh_softc *zsc = device_private(self);
     99 	struct ne2000_softc *nsc = &zsc->sc_ne2000;
    100 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
    101 
    102 	struct xshbus_attach_args *xap = aux;
    103 
    104 	bus_space_tag_t xsht;
    105 	bus_space_handle_t nich;
    106 	bus_space_handle_t asich;
    107 
    108 	dsc->sc_dev = self;
    109 
    110 	zsc->sc_bst.base = xap->xaa_base;
    111 	zsc->sc_bst.absm = &amiga_bus_stride_4;
    112 
    113 	aprint_normal("\n");
    114 
    115 	xsht = &zsc->sc_bst;
    116 
    117 	/* Map the NIC and ASIC spaces. */
    118 	if (bus_space_map(xsht, NE2000_NIC_OFFSET, NE2000_NPORTS, 0, &nich)) {
    119 		aprint_error_dev(self, "can't map nic i/o space\n");
    120 		return;
    121 	}
    122 	if (bus_space_subregion(xsht, nich, NE2000_ASIC_OFFSET,
    123 	    NE2000_ASIC_NPORTS, &asich)) {
    124 		aprint_error_dev(self, "can't map asic i/o space\n");
    125 		return;
    126 	}
    127 
    128 #ifdef NE_XSH_DEBUG
    129 	ne_xsh_debug_mapping(xsht, nich, asich);
    130 #endif /* NE_XSH_DEBUG */
    131 
    132 	dsc->sc_regt = xsht;
    133 	dsc->sc_regh = nich;
    134 
    135 	nsc->sc_asict = xsht;
    136 	nsc->sc_asich = asich;
    137 
    138 	/* This interface is always enabled. */
    139 	dsc->sc_enabled = 1;
    140 
    141 	nsc->sc_type = NE2000_TYPE_AX88796;
    142 
    143 	dsc->sc_mediachange = ax88190_mediachange;
    144 	dsc->sc_mediastatus = ax88190_mediastatus;
    145 	dsc->init_card = ax88190_init_card;
    146 	dsc->stop_card = ax88190_stop_card;
    147 	dsc->sc_media_init = ax88190_media_init;
    148 	dsc->sc_media_fini = ax88190_media_fini;
    149 
    150 	/*
    151 	 * Do generic NE2000 attach.  This will read the station address
    152 	 * from the EEPROM.
    153 	 */
    154 	ne2000_attach(nsc, NULL);
    155 
    156 	zsc->sc_isr.isr_intr = dp8390_intr;
    157 	zsc->sc_isr.isr_arg = dsc;
    158 	zsc->sc_isr.isr_ipl = 2;
    159 	add_isr(&zsc->sc_isr);
    160 }
    161 
    162 #ifdef NE_XSH_DEBUG
    163 void
    164 ne_xsh_debug_mapping(bus_space_tag_t xsht, bus_space_handle_t nich,
    165     bus_space_handle_t asich)
    166 {
    167 	bus_addr_t va;
    168 	int i;
    169 
    170 	aprint_normal("xsh: NIC mapping: ");
    171 	for(va = nich, i = 0; i < NE2000_NIC_NPORTS; i++) {
    172 		aprint_normal("%x:%x ", i, kvtop((void*) (va+i)));
    173 	}
    174 	aprint_normal("\n");
    175 
    176 	aprint_normal("xsh: ASIC mapping: ");
    177 	for(va = asich, i = 0; i < NE2000_ASIC_NPORTS; i++) {
    178 		aprint_normal("%x:%x ", i, kvtop((void*) (va+i)));
    179 	}
    180 	aprint_normal("\n");
    181 }
    182 #endif /* NE_XSH_DEBUG */
    183