Home | History | Annotate | Line # | Download | only in isapnp
      1  1.27   tsutsui /*	$NetBSD: if_ne_isapnp.c,v 1.27 2010/03/03 13:39:57 tsutsui Exp $	*/
      2   1.1      matt 
      3   1.1      matt /*-
      4   1.9   thorpej  * Copyright (c) 1997, 1998 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  *
     20   1.1      matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21   1.1      matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22   1.1      matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23   1.1      matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24   1.1      matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25   1.1      matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26   1.1      matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27   1.1      matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28   1.1      matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29   1.1      matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30   1.1      matt  * POSSIBILITY OF SUCH DAMAGE.
     31   1.1      matt  */
     32  1.14     lukem 
     33  1.14     lukem #include <sys/cdefs.h>
     34  1.27   tsutsui __KERNEL_RCSID(0, "$NetBSD: if_ne_isapnp.c,v 1.27 2010/03/03 13:39:57 tsutsui Exp $");
     35   1.1      matt 
     36   1.1      matt #include <sys/param.h>
     37   1.1      matt #include <sys/systm.h>
     38   1.1      matt #include <sys/mbuf.h>
     39   1.1      matt #include <sys/socket.h>
     40   1.1      matt #include <sys/ioctl.h>
     41   1.1      matt #include <sys/errno.h>
     42   1.1      matt #include <sys/syslog.h>
     43   1.1      matt #include <sys/select.h>
     44   1.1      matt #include <sys/device.h>
     45   1.1      matt 
     46   1.1      matt #include <net/if.h>
     47   1.1      matt #include <net/if_dl.h>
     48   1.1      matt #include <net/if_ether.h>
     49   1.1      matt #include <net/if_media.h>
     50   1.1      matt 
     51  1.24        ad #include <sys/intr.h>
     52  1.24        ad #include <sys/bus.h>
     53   1.1      matt 
     54   1.1      matt #include <dev/ic/dp8390reg.h>
     55   1.1      matt #include <dev/ic/dp8390var.h>
     56   1.1      matt 
     57   1.1      matt #include <dev/ic/ne2000reg.h>
     58   1.1      matt #include <dev/ic/ne2000var.h>
     59   1.1      matt 
     60   1.1      matt #include <dev/isa/isavar.h>
     61   1.1      matt 
     62   1.1      matt #include <dev/isapnp/isapnpreg.h>
     63   1.1      matt #include <dev/isapnp/isapnpvar.h>
     64   1.7  christos #include <dev/isapnp/isapnpdevs.h>
     65   1.1      matt 
     66  1.25      cube static int ne_isapnp_match(device_t, cfdata_t , void *);
     67  1.25      cube static void ne_isapnp_attach(device_t, device_t, void *);
     68   1.1      matt 
     69   1.1      matt struct ne_isapnp_softc {
     70   1.1      matt 	struct	ne2000_softc sc_ne2000;		/* real "ne2000" softc */
     71   1.1      matt 
     72   1.1      matt 	/* ISA-specific goo. */
     73   1.1      matt 	void	*sc_ih;				/* interrupt cookie */
     74   1.1      matt };
     75   1.1      matt 
     76  1.25      cube CFATTACH_DECL_NEW(ne_isapnp, sizeof(struct ne_isapnp_softc),
     77  1.17   thorpej     ne_isapnp_match, ne_isapnp_attach, NULL, NULL);
     78   1.1      matt 
     79   1.1      matt static int
     80  1.25      cube ne_isapnp_match(device_t parent, cfdata_t match, void *aux)
     81   1.1      matt {
     82  1.11   mycroft 	int pri, variant;
     83  1.10   mycroft 
     84  1.11   mycroft 	pri = isapnp_devmatch(aux, &isapnp_ne_devinfo, &variant);
     85  1.11   mycroft 	if (pri && variant > 0)
     86  1.11   mycroft 		pri = 0;
     87  1.11   mycroft 	return (pri);
     88   1.1      matt }
     89   1.1      matt 
     90   1.1      matt static void
     91  1.25      cube ne_isapnp_attach(device_t parent, device_t self, void *aux)
     92   1.1      matt {
     93  1.21   thorpej 	struct ne_isapnp_softc * const isc = device_private(self);
     94   1.1      matt 	struct ne2000_softc * const nsc = &isc->sc_ne2000;
     95   1.1      matt 	struct dp8390_softc * const dsc = &nsc->sc_dp8390;
     96   1.1      matt 	struct isapnp_attach_args * const ipa = aux;
     97   1.3   thorpej 	bus_space_tag_t nict;
     98   1.3   thorpej 	bus_space_handle_t nich;
     99   1.3   thorpej 	bus_space_tag_t asict;
    100   1.1      matt 	bus_space_handle_t asich;
    101   1.1      matt 	const char *typestr;
    102   1.9   thorpej 	int netype;
    103   1.1      matt 
    104  1.25      cube 	aprint_normal("\n");
    105  1.25      cube 
    106  1.25      cube 	dsc->sc_dev = self;
    107   1.1      matt 
    108   1.1      matt 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
    109  1.25      cube 		aprint_error_dev(self, "can't configure isapnp resources\n");
    110   1.1      matt 		return;
    111   1.1      matt 	}
    112   1.3   thorpej 
    113   1.3   thorpej 	nict = ipa->ipa_iot;
    114   1.3   thorpej 	nich = ipa->ipa_io[0].h;
    115   1.3   thorpej 
    116   1.3   thorpej 	asict = nict;
    117   1.1      matt 
    118   1.1      matt 	if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
    119   1.1      matt 	    NE2000_ASIC_NPORTS, &asich)) {
    120  1.25      cube 		aprint_error_dev(self, "can't subregion i/o space\n");
    121   1.1      matt 		return;
    122   1.1      matt 	}
    123   1.1      matt 
    124   1.1      matt 	dsc->sc_regt = nict;
    125   1.1      matt 	dsc->sc_regh = nich;
    126   1.1      matt 
    127   1.1      matt 	nsc->sc_asict = asict;
    128   1.1      matt 	nsc->sc_asich = asich;
    129   1.1      matt 
    130   1.1      matt 	/*
    131   1.1      matt 	 * Detect it again, so we can print some information about the
    132   1.1      matt 	 * interface.
    133   1.1      matt 	 */
    134   1.9   thorpej 	netype = ne2000_detect(nict, nich, asict, asich);
    135   1.9   thorpej 	switch (netype) {
    136   1.1      matt 	case NE2000_TYPE_NE1000:
    137   1.1      matt 		typestr = "NE1000";
    138   1.1      matt 		break;
    139   1.1      matt 
    140   1.1      matt 	case NE2000_TYPE_NE2000:
    141   1.1      matt 		typestr = "NE2000";
    142  1.27   tsutsui 		break;
    143  1.27   tsutsui 
    144  1.27   tsutsui 	case NE2000_TYPE_RTL8019:
    145  1.27   tsutsui 		typestr = "NE2000 (RTL8019)";
    146   1.1      matt 		break;
    147   1.1      matt 
    148   1.1      matt 	default:
    149  1.25      cube 		aprint_error_dev(self, "where did the card go?!\n");
    150   1.1      matt 		return;
    151   1.1      matt 	}
    152   1.1      matt 
    153  1.25      cube 	aprint_normal_dev(self, "%s Ethernet\n", typestr);
    154   1.1      matt 
    155   1.1      matt 	/* This interface is always enabled. */
    156   1.1      matt 	dsc->sc_enabled = 1;
    157   1.1      matt 
    158   1.1      matt 	/*
    159   1.1      matt 	 * Do generic NE2000 attach.  This will read the station address
    160   1.1      matt 	 * from the EEPROM.
    161   1.1      matt 	 */
    162  1.12   thorpej 	ne2000_attach(nsc, NULL);
    163   1.1      matt 
    164   1.1      matt 	/* Establish the interrupt handler. */
    165   1.1      matt 	isc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
    166   1.2  christos 	    ipa->ipa_irq[0].type, IPL_NET, dp8390_intr, dsc);
    167   1.1      matt 	if (isc->sc_ih == NULL)
    168  1.25      cube 		aprint_error_dev(self,
    169  1.25      cube 		    "couldn't establish interrupt handler\n");
    170   1.1      matt }
    171