Home | History | Annotate | Line # | Download | only in isapnp
      1 /*	$NetBSD: if_ne_isapnp.c,v 1.27 2010/03/03 13:39:57 tsutsui 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 and Matt Thomas of the 3am Software Foundry.
     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_isapnp.c,v 1.27 2010/03/03 13:39:57 tsutsui 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 
     46 #include <net/if.h>
     47 #include <net/if_dl.h>
     48 #include <net/if_ether.h>
     49 #include <net/if_media.h>
     50 
     51 #include <sys/intr.h>
     52 #include <sys/bus.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 <dev/isa/isavar.h>
     61 
     62 #include <dev/isapnp/isapnpreg.h>
     63 #include <dev/isapnp/isapnpvar.h>
     64 #include <dev/isapnp/isapnpdevs.h>
     65 
     66 static int ne_isapnp_match(device_t, cfdata_t , void *);
     67 static void ne_isapnp_attach(device_t, device_t, void *);
     68 
     69 struct ne_isapnp_softc {
     70 	struct	ne2000_softc sc_ne2000;		/* real "ne2000" softc */
     71 
     72 	/* ISA-specific goo. */
     73 	void	*sc_ih;				/* interrupt cookie */
     74 };
     75 
     76 CFATTACH_DECL_NEW(ne_isapnp, sizeof(struct ne_isapnp_softc),
     77     ne_isapnp_match, ne_isapnp_attach, NULL, NULL);
     78 
     79 static int
     80 ne_isapnp_match(device_t parent, cfdata_t match, void *aux)
     81 {
     82 	int pri, variant;
     83 
     84 	pri = isapnp_devmatch(aux, &isapnp_ne_devinfo, &variant);
     85 	if (pri && variant > 0)
     86 		pri = 0;
     87 	return (pri);
     88 }
     89 
     90 static void
     91 ne_isapnp_attach(device_t parent, device_t self, void *aux)
     92 {
     93 	struct ne_isapnp_softc * const isc = device_private(self);
     94 	struct ne2000_softc * const nsc = &isc->sc_ne2000;
     95 	struct dp8390_softc * const dsc = &nsc->sc_dp8390;
     96 	struct isapnp_attach_args * const ipa = aux;
     97 	bus_space_tag_t nict;
     98 	bus_space_handle_t nich;
     99 	bus_space_tag_t asict;
    100 	bus_space_handle_t asich;
    101 	const char *typestr;
    102 	int netype;
    103 
    104 	aprint_normal("\n");
    105 
    106 	dsc->sc_dev = self;
    107 
    108 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
    109 		aprint_error_dev(self, "can't configure isapnp resources\n");
    110 		return;
    111 	}
    112 
    113 	nict = ipa->ipa_iot;
    114 	nich = ipa->ipa_io[0].h;
    115 
    116 	asict = nict;
    117 
    118 	if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
    119 	    NE2000_ASIC_NPORTS, &asich)) {
    120 		aprint_error_dev(self, "can't subregion i/o space\n");
    121 		return;
    122 	}
    123 
    124 	dsc->sc_regt = nict;
    125 	dsc->sc_regh = nich;
    126 
    127 	nsc->sc_asict = asict;
    128 	nsc->sc_asich = asich;
    129 
    130 	/*
    131 	 * Detect it again, so we can print some information about the
    132 	 * interface.
    133 	 */
    134 	netype = ne2000_detect(nict, nich, asict, asich);
    135 	switch (netype) {
    136 	case NE2000_TYPE_NE1000:
    137 		typestr = "NE1000";
    138 		break;
    139 
    140 	case NE2000_TYPE_NE2000:
    141 		typestr = "NE2000";
    142 		break;
    143 
    144 	case NE2000_TYPE_RTL8019:
    145 		typestr = "NE2000 (RTL8019)";
    146 		break;
    147 
    148 	default:
    149 		aprint_error_dev(self, "where did the card go?!\n");
    150 		return;
    151 	}
    152 
    153 	aprint_normal_dev(self, "%s Ethernet\n", typestr);
    154 
    155 	/* This interface is always enabled. */
    156 	dsc->sc_enabled = 1;
    157 
    158 	/*
    159 	 * Do generic NE2000 attach.  This will read the station address
    160 	 * from the EEPROM.
    161 	 */
    162 	ne2000_attach(nsc, NULL);
    163 
    164 	/* Establish the interrupt handler. */
    165 	isc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
    166 	    ipa->ipa_irq[0].type, IPL_NET, dp8390_intr, dsc);
    167 	if (isc->sc_ih == NULL)
    168 		aprint_error_dev(self,
    169 		    "couldn't establish interrupt handler\n");
    170 }
    171