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