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