Home | History | Annotate | Line # | Download | only in dev
if_ne_neptune.c revision 1.7.6.3
      1 /*	$NetBSD: if_ne_neptune.c,v 1.7.6.3 2004/09/21 13:24:08 skrll 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  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by the NetBSD
     22  *	Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 #include <sys/cdefs.h>
     41 __KERNEL_RCSID(0, "$NetBSD: if_ne_neptune.c,v 1.7.6.3 2004/09/21 13:24:08 skrll Exp $");
     42 
     43 #include "opt_inet.h"
     44 #include "opt_ns.h"
     45 #include "bpfilter.h"
     46 
     47 #include <sys/param.h>
     48 #include <sys/systm.h>
     49 #include <sys/mbuf.h>
     50 #include <sys/socket.h>
     51 #include <sys/ioctl.h>
     52 #include <sys/errno.h>
     53 #include <sys/syslog.h>
     54 #include <sys/select.h>
     55 #include <sys/device.h>
     56 
     57 #include <net/if.h>
     58 #include <net/if_dl.h>
     59 #include <net/if_ether.h>
     60 #include <net/if_media.h>
     61 
     62 #ifdef INET
     63 #include <netinet/in.h>
     64 #include <netinet/in_systm.h>
     65 #include <netinet/in_var.h>
     66 #include <netinet/ip.h>
     67 #include <netinet/if_inarp.h>
     68 #endif
     69 
     70 #ifdef NS
     71 #include <netns/ns.h>
     72 #include <netns/ns_if.h>
     73 #endif
     74 
     75 #if NBPFILTER > 0
     76 #include <net/bpf.h>
     77 #include <net/bpfdesc.h>
     78 #endif
     79 
     80 #include <machine/bus.h>
     81 
     82 #include <dev/ic/dp8390reg.h>
     83 #include <dev/ic/dp8390var.h>
     84 
     85 #include <dev/ic/ne2000reg.h>
     86 #include <dev/ic/ne2000var.h>
     87 
     88 #include <dev/ic/rtl80x9reg.h>
     89 #include <dev/ic/rtl80x9var.h>
     90 
     91 #include <arch/x68k/dev/neptunevar.h>
     92 
     93 static int ne_neptune_match __P((struct device *, struct cfdata *, void *));
     94 static void ne_neptune_attach __P((struct device *, struct device *, void *));
     95 static int ne_neptune_intr __P((void *));
     96 
     97 #define ne_neptune_softc ne2000_softc
     98 
     99 CFATTACH_DECL(ne_neptune, sizeof(struct ne_neptune_softc),
    100     ne_neptune_match, ne_neptune_attach, NULL, NULL);
    101 
    102 int
    103 ne_neptune_match(parent, match, aux)
    104 	struct device *parent;
    105 	struct cfdata *match;
    106 	void *aux;
    107 {
    108 	struct neptune_attach_args *na = aux;
    109 	bus_space_tag_t nict = na->na_bst;
    110 	bus_space_handle_t nich;
    111 	bus_space_tag_t asict;
    112 	bus_space_handle_t asich;
    113 	int rv = 0;
    114 
    115 	if (na->na_addr == NEPTUNECF_ADDR_DEFAULT)
    116 		na->na_addr = 0x300;
    117 
    118 	/* Make sure this is a valid NE[12]000 i/o address. */
    119 	if ((na->na_addr & 0x1f) != 0)
    120 		return (0);
    121 
    122 	/* Map i/o space. */
    123 	if (bus_space_map(nict, na->na_addr, NE2000_NPORTS*2, 0, &nich))
    124 		return (0);
    125 
    126 	asict = nict;
    127 	if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
    128 	    NE2000_ASIC_NPORTS*2, &asich))
    129 		goto out;
    130 
    131 	/* Look for an NE2000-compatible card. */
    132 	rv = ne2000_detect(nict, nich, asict, asich);
    133 
    134  out:
    135 	bus_space_unmap(nict, nich, NE2000_NPORTS);
    136 	return (rv);
    137 }
    138 
    139 void
    140 ne_neptune_attach(parent, self, aux)
    141 	struct device *parent, *self;
    142 	void *aux;
    143 {
    144 	struct ne_neptune_softc *nsc = (struct ne_neptune_softc *)self;
    145 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
    146 	struct neptune_attach_args *na = aux;
    147 	bus_space_tag_t nict = na->na_bst;
    148 	bus_space_handle_t nich;
    149 	bus_space_tag_t asict = nict;
    150 	bus_space_handle_t asich;
    151 	const char *typestr;
    152 	int netype;
    153 
    154 	printf("\n");
    155 
    156 	/* Map i/o space. */
    157 	if (bus_space_map(nict, na->na_addr, NE2000_NPORTS*2, 0, &nich)) {
    158 		printf("%s: can't map i/o space\n", dsc->sc_dev.dv_xname);
    159 		return;
    160 	}
    161 
    162 	if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
    163 	    NE2000_ASIC_NPORTS*2, &asich)) {
    164 		printf("%s: can't subregion i/o space\n", dsc->sc_dev.dv_xname);
    165 		return;
    166 	}
    167 
    168 	dsc->sc_regt = nict;
    169 	dsc->sc_regh = nich;
    170 
    171 	nsc->sc_asict = asict;
    172 	nsc->sc_asich = asich;
    173 
    174 	/*
    175 	 * Detect it again, so we can print some information about the
    176 	 * interface.
    177 	 */
    178 	netype = ne2000_detect(nict, nich, asict, asich);
    179 	switch (netype) {
    180 	case NE2000_TYPE_NE1000:
    181 		typestr = "NE1000";
    182 		break;
    183 
    184 	case NE2000_TYPE_NE2000:
    185 		typestr = "NE2000";
    186 		/*
    187 		 * Check for a Realtek 8019.
    188 		 */
    189 		bus_space_write_1(nict, nich, ED_P0_CR,
    190 		    ED_CR_PAGE_0 | ED_CR_STP);
    191 		if (bus_space_read_1(nict, nich, NERTL_RTL0_8019ID0) ==
    192 								RTL0_8019ID0 &&
    193 		    bus_space_read_1(nict, nich, NERTL_RTL0_8019ID1) ==
    194 								RTL0_8019ID1) {
    195 			typestr = "NE2000 (RTL8019)";
    196 			dsc->sc_mediachange = rtl80x9_mediachange;
    197 			dsc->sc_mediastatus = rtl80x9_mediastatus;
    198 			dsc->init_card = rtl80x9_init_card;
    199 			dsc->sc_media_init = rtl80x9_media_init;
    200 		}
    201 		break;
    202 
    203 	default:
    204 		printf("%s: where did the card go?!\n", dsc->sc_dev.dv_xname);
    205 		return;
    206 	}
    207 
    208 	printf("%s: %s Ethernet\n", dsc->sc_dev.dv_xname, typestr);
    209 
    210 	/* This interface is always enabled. */
    211 	dsc->sc_enabled = 1;
    212 
    213 	/*
    214 	 * Do generic NE2000 attach.  This will read the station address
    215 	 * from the EEPROM.
    216 	 */
    217 	ne2000_attach(nsc, NULL);
    218 
    219 	/* Establish the interrupt handler. */
    220 	if (neptune_intr_establish(na->na_intr, "ne", ne_neptune_intr, dsc))
    221 		printf("%s: couldn't establish interrupt handler\n",
    222 		    dsc->sc_dev.dv_xname);
    223 }
    224 
    225 static int
    226 ne_neptune_intr(arg)
    227 	void *arg;
    228 {
    229 	spl4();			/* XXX */
    230 	return dp8390_intr(arg);
    231 }
    232