Home | History | Annotate | Line # | Download | only in t_sh7706lan
if_ne_mainbus.c revision 1.2.12.1
      1 /*	$NetBSD: if_ne_mainbus.c,v 1.2.12.1 2013/02/25 00:28:40 tls Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  * NASA Ames Research Center.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  * POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 #include <sys/cdefs.h>
     34 __KERNEL_RCSID(0, "$NetBSD: if_ne_mainbus.c,v 1.2.12.1 2013/02/25 00:28:40 tls Exp $");
     35 
     36 #include <sys/param.h>
     37 #include <sys/systm.h>
     38 #include <sys/mbuf.h>
     39 #include <sys/socket.h>
     40 #include <sys/ioctl.h>
     41 #include <sys/errno.h>
     42 #include <sys/syslog.h>
     43 #include <sys/select.h>
     44 #include <sys/device.h>
     45 #include <sys/bus.h>
     46 
     47 #include <net/if.h>
     48 #include <net/if_dl.h>
     49 #include <net/if_ether.h>
     50 #include <net/if_media.h>
     51 
     52 #include <sys/intr.h>
     53 
     54 #include <dev/ic/dp8390reg.h>
     55 #include <dev/ic/dp8390var.h>
     56 
     57 #include <dev/ic/ne2000reg.h>
     58 #include <dev/ic/ne2000var.h>
     59 
     60 #include <machine/autoconf.h>
     61 
     62 #include <sh3/exception.h>
     63 
     64 static int ne_mainbus_match(device_t, cfdata_t, void *);
     65 static void ne_mainbus_attach(device_t, device_t, void *);
     66 
     67 struct ne_mainbus_softc {
     68 	struct	ne2000_softc sc_ne2000;		/* real "ne2000" softc */
     69 
     70 	void	*sc_ih;				/* interrupt cookie */
     71 };
     72 
     73 CFATTACH_DECL_NEW(ne_mainbus, sizeof(struct ne_mainbus_softc),
     74     ne_mainbus_match, ne_mainbus_attach, NULL, NULL);
     75 
     76 extern struct _bus_space t_sh7706lan_bus_io;
     77 
     78 static int
     79 ne_mainbus_match(device_t parent, cfdata_t cf, void *aux)
     80 {
     81 	struct mainbus_attach_args *maa = (struct mainbus_attach_args *)aux;
     82 	bus_space_tag_t nict = &t_sh7706lan_bus_io;
     83 	bus_space_handle_t nich;
     84 	bus_space_tag_t asict;
     85 	bus_space_handle_t asich;
     86 	int rv = 0;
     87 
     88 	if (strcmp(maa->ma_name, "ne") != 0)
     89 		return 0;
     90 
     91 	/* Map i/o space. */
     92 	if (bus_space_map(nict, 0x10000300, NE2000_NPORTS, 0, &nich))
     93 		return 0;
     94 
     95 	asict = nict;
     96 	if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
     97 	    NE2000_ASIC_NPORTS, &asich))
     98 		goto out;
     99 
    100 	/* Look for an NE2000-compatible card. */
    101 	rv = ne2000_detect(nict, nich, asict, asich);
    102 
    103  out:
    104 	bus_space_unmap(nict, nich, NE2000_NPORTS);
    105 	return rv;
    106 }
    107 
    108 static void
    109 ne_mainbus_attach(device_t parent, device_t self, void *aux)
    110 {
    111 	struct ne_mainbus_softc *msc = device_private(self);
    112 	struct ne2000_softc *nsc = &msc->sc_ne2000;
    113 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
    114 	bus_space_tag_t nict = &t_sh7706lan_bus_io;
    115 	bus_space_handle_t nich;
    116 	bus_space_tag_t asict = nict;
    117 	bus_space_handle_t asich;
    118 	const char *typestr;
    119 	int netype;
    120 
    121 	dsc->sc_dev = self;
    122 
    123 	aprint_naive("\n");
    124 	aprint_normal("\n");
    125 
    126 	/* Map i/o space. */
    127 	if (bus_space_map(nict, 0x10000300, NE2000_NPORTS, 0, &nich)){
    128 		aprint_error_dev(self, "can't map i/o space\n");
    129 		return;
    130 	}
    131 
    132 	if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
    133 	    NE2000_ASIC_NPORTS, &asich)) {
    134 		aprint_error_dev(self, "can't subregion i/o space\n");
    135 		bus_space_unmap(nict, nich, NE2000_NPORTS);
    136 		return;
    137 	}
    138 
    139 	dsc->sc_regt = nict;
    140 	dsc->sc_regh = nich;
    141 
    142 	nsc->sc_asict = asict;
    143 	nsc->sc_asich = asich;
    144 
    145 	/*
    146 	 * Detect it again, so we can print some information about the
    147 	 * interface.
    148 	 */
    149 	netype = ne2000_detect(nict, nich, asict, asich);
    150 	switch (netype) {
    151 	case NE2000_TYPE_NE1000:
    152 		typestr = "NE1000";
    153 		break;
    154 
    155 	case NE2000_TYPE_NE2000:
    156 		typestr = "NE2000";
    157 		break;
    158 
    159 	case NE2000_TYPE_RTL8019:
    160 		typestr = "NE2000 (RTL8019)";
    161  		break;
    162 
    163 	default:
    164 		aprint_error_dev(self, "where did the card go?!\n");
    165 		bus_space_unmap(nict, nich, NE2000_NPORTS);
    166 		return;
    167 	}
    168 
    169 	aprint_normal_dev(self, "%s Ethernet\n", typestr);
    170 
    171 	/* This interface is always enabled. */
    172 	dsc->sc_enabled = 1;
    173 
    174 	/* force 8bit */
    175 	nsc->sc_quirk |= NE2000_QUIRK_8BIT;
    176 
    177 	/*
    178 	 * Do generic NE2000 attach.  This will read the station address
    179 	 * from the EEPROM.
    180 	 */
    181 	ne2000_attach(nsc, NULL);
    182 
    183 	/* Establish the interrupt handler. */
    184 	msc->sc_ih = intc_intr_establish(SH7709_INTEVT2_IRQ2, IST_LEVEL,
    185 	    IPL_NET, dp8390_intr, dsc);
    186 	if (msc->sc_ih == NULL)
    187 		aprint_error_dev(self,
    188 		    "couldn't establish interrupt handler\n");
    189 }
    190