Home | History | Annotate | Line # | Download | only in isapnp
if_ne_isapnp.c revision 1.7
      1  1.7  christos /*	$NetBSD: if_ne_isapnp.c,v 1.7 1998/07/23 19:30:45 christos Exp $	*/
      2  1.1      matt 
      3  1.1      matt /*-
      4  1.1      matt  * Copyright (c) 1997 The NetBSD Foundation, Inc.
      5  1.1      matt  * All rights reserved.
      6  1.1      matt  *
      7  1.1      matt  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1      matt  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  1.1      matt  * NASA Ames Research Center and Matt Thomas of the 3am Software Foundry.
     10  1.1      matt  *
     11  1.1      matt  * Redistribution and use in source and binary forms, with or without
     12  1.1      matt  * modification, are permitted provided that the following conditions
     13  1.1      matt  * are met:
     14  1.1      matt  * 1. Redistributions of source code must retain the above copyright
     15  1.1      matt  *    notice, this list of conditions and the following disclaimer.
     16  1.1      matt  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1      matt  *    notice, this list of conditions and the following disclaimer in the
     18  1.1      matt  *    documentation and/or other materials provided with the distribution.
     19  1.1      matt  * 3. All advertising materials mentioning features or use of this software
     20  1.1      matt  *    must display the following acknowledgement:
     21  1.1      matt  *	This product includes software developed by the NetBSD
     22  1.1      matt  *	Foundation, Inc. and its contributors.
     23  1.1      matt  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.1      matt  *    contributors may be used to endorse or promote products derived
     25  1.1      matt  *    from this software without specific prior written permission.
     26  1.1      matt  *
     27  1.1      matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.1      matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.1      matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.1      matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.1      matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.1      matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.1      matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.1      matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.1      matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.1      matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.1      matt  * POSSIBILITY OF SUCH DAMAGE.
     38  1.1      matt  */
     39  1.1      matt 
     40  1.5  jonathan #include "opt_inet.h"
     41  1.6  jonathan #include "opt_ns.h"
     42  1.1      matt #include "bpfilter.h"
     43  1.1      matt 
     44  1.1      matt #include <sys/param.h>
     45  1.1      matt #include <sys/systm.h>
     46  1.1      matt #include <sys/mbuf.h>
     47  1.1      matt #include <sys/socket.h>
     48  1.1      matt #include <sys/ioctl.h>
     49  1.1      matt #include <sys/errno.h>
     50  1.1      matt #include <sys/syslog.h>
     51  1.1      matt #include <sys/select.h>
     52  1.1      matt #include <sys/device.h>
     53  1.1      matt 
     54  1.1      matt #include <net/if.h>
     55  1.1      matt #include <net/if_dl.h>
     56  1.1      matt #include <net/if_ether.h>
     57  1.1      matt #include <net/if_media.h>
     58  1.1      matt 
     59  1.1      matt #ifdef INET
     60  1.1      matt #include <netinet/in.h>
     61  1.1      matt #include <netinet/in_systm.h>
     62  1.1      matt #include <netinet/in_var.h>
     63  1.1      matt #include <netinet/ip.h>
     64  1.1      matt #include <netinet/if_inarp.h>
     65  1.1      matt #endif
     66  1.1      matt 
     67  1.1      matt #ifdef NS
     68  1.1      matt #include <netns/ns.h>
     69  1.1      matt #include <netns/ns_if.h>
     70  1.1      matt #endif
     71  1.1      matt 
     72  1.1      matt #if NBPFILTER > 0
     73  1.1      matt #include <net/bpf.h>
     74  1.1      matt #include <net/bpfdesc.h>
     75  1.1      matt #endif
     76  1.1      matt 
     77  1.1      matt #include <machine/intr.h>
     78  1.1      matt #include <machine/bus.h>
     79  1.1      matt 
     80  1.1      matt #include <dev/ic/dp8390reg.h>
     81  1.1      matt #include <dev/ic/dp8390var.h>
     82  1.1      matt 
     83  1.1      matt #include <dev/ic/ne2000reg.h>
     84  1.1      matt #include <dev/ic/ne2000var.h>
     85  1.1      matt 
     86  1.1      matt #include <dev/isa/isavar.h>
     87  1.1      matt 
     88  1.1      matt #include <dev/isapnp/isapnpreg.h>
     89  1.1      matt #include <dev/isapnp/isapnpvar.h>
     90  1.7  christos #include <dev/isapnp/isapnpdevs.h>
     91  1.1      matt 
     92  1.1      matt static int ne_isapnp_match __P((struct device *, struct cfdata *, void *));
     93  1.1      matt static void ne_isapnp_attach __P((struct device *, struct device *, void *));
     94  1.1      matt 
     95  1.1      matt struct ne_isapnp_softc {
     96  1.1      matt 	struct	ne2000_softc sc_ne2000;		/* real "ne2000" softc */
     97  1.1      matt 
     98  1.1      matt 	/* ISA-specific goo. */
     99  1.1      matt 	void	*sc_ih;				/* interrupt cookie */
    100  1.1      matt };
    101  1.1      matt 
    102  1.1      matt struct cfattach ne_isapnp_ca = {
    103  1.1      matt 	sizeof(struct ne_isapnp_softc), ne_isapnp_match, ne_isapnp_attach
    104  1.1      matt };
    105  1.1      matt 
    106  1.1      matt static int
    107  1.7  christos ne_isapnp_match(parent, match, aux)
    108  1.7  christos 	struct device *parent;
    109  1.7  christos 	struct cfdata *match;
    110  1.7  christos 	void *aux;
    111  1.1      matt {
    112  1.7  christos 	return isapnp_devmatch(aux, &isapnp_ne_devinfo);
    113  1.1      matt }
    114  1.1      matt 
    115  1.1      matt static void
    116  1.1      matt ne_isapnp_attach(
    117  1.1      matt 	struct device *parent,
    118  1.1      matt 	struct device *self,
    119  1.1      matt 	void *aux)
    120  1.1      matt {
    121  1.1      matt 	struct ne_isapnp_softc * const isc = (struct ne_isapnp_softc *)self;
    122  1.1      matt 	struct ne2000_softc * const nsc = &isc->sc_ne2000;
    123  1.1      matt 	struct dp8390_softc * const dsc = &nsc->sc_dp8390;
    124  1.1      matt 	struct isapnp_attach_args * const ipa = aux;
    125  1.3   thorpej 	bus_space_tag_t nict;
    126  1.3   thorpej 	bus_space_handle_t nich;
    127  1.3   thorpej 	bus_space_tag_t asict;
    128  1.1      matt 	bus_space_handle_t asich;
    129  1.1      matt 	const char *typestr;
    130  1.1      matt 
    131  1.1      matt 	printf("\n");
    132  1.1      matt 
    133  1.1      matt 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
    134  1.1      matt 		printf("%s: can't configure isapnp resources\n",
    135  1.1      matt 		    dsc->sc_dev.dv_xname);
    136  1.1      matt 		return;
    137  1.1      matt 	}
    138  1.3   thorpej 
    139  1.3   thorpej 	nict = ipa->ipa_iot;
    140  1.3   thorpej 	nich = ipa->ipa_io[0].h;
    141  1.3   thorpej 
    142  1.3   thorpej 	asict = nict;
    143  1.1      matt 
    144  1.1      matt 	if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
    145  1.1      matt 	    NE2000_ASIC_NPORTS, &asich)) {
    146  1.1      matt 		printf("%s: can't subregion i/o space\n", dsc->sc_dev.dv_xname);
    147  1.1      matt 		return;
    148  1.1      matt 	}
    149  1.1      matt 
    150  1.1      matt 	dsc->sc_regt = nict;
    151  1.1      matt 	dsc->sc_regh = nich;
    152  1.1      matt 
    153  1.1      matt 	nsc->sc_asict = asict;
    154  1.1      matt 	nsc->sc_asich = asich;
    155  1.1      matt 
    156  1.1      matt 	/*
    157  1.1      matt 	 * Detect it again, so we can print some information about the
    158  1.1      matt 	 * interface.
    159  1.1      matt 	 */
    160  1.1      matt 	switch (ne2000_detect(nict, nich, asict, asich)) {
    161  1.1      matt 	case NE2000_TYPE_NE1000:
    162  1.1      matt 		typestr = "NE1000";
    163  1.1      matt 		break;
    164  1.1      matt 
    165  1.1      matt 	case NE2000_TYPE_NE2000:
    166  1.1      matt 		typestr = "NE2000";
    167  1.1      matt 		break;
    168  1.1      matt 
    169  1.1      matt 	default:
    170  1.1      matt 		printf("%s: where did the card go?!\n", dsc->sc_dev.dv_xname);
    171  1.1      matt 		return;
    172  1.1      matt 	}
    173  1.1      matt 
    174  1.1      matt 	printf("%s: %s Ethernet\n", dsc->sc_dev.dv_xname, typestr);
    175  1.1      matt 
    176  1.1      matt 	/* This interface is always enabled. */
    177  1.1      matt 	dsc->sc_enabled = 1;
    178  1.1      matt 
    179  1.1      matt 	/*
    180  1.1      matt 	 * Do generic NE2000 attach.  This will read the station address
    181  1.1      matt 	 * from the EEPROM.
    182  1.1      matt 	 */
    183  1.1      matt 	ne2000_attach(nsc, NULL);
    184  1.1      matt 
    185  1.1      matt 	/* Establish the interrupt handler. */
    186  1.1      matt 	isc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
    187  1.2  christos 	    ipa->ipa_irq[0].type, IPL_NET, dp8390_intr, dsc);
    188  1.1      matt 	if (isc->sc_ih == NULL)
    189  1.1      matt 		printf("%s: couldn't establish interrupt handler\n",
    190  1.1      matt 		    dsc->sc_dev.dv_xname);
    191  1.1      matt }
    192