Home | History | Annotate | Line # | Download | only in mca
if_ne_mca.c revision 1.2
      1 /*	$NetBSD: if_ne_mca.c,v 1.2 2001/04/23 06:10:08 jdolecek Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jaromir Dolecek.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * Driver for Novell NE/2 Ethernet Adapter (and clones).
     41  *
     42  * According to Linux ne2 driver, Arco and Compex card should be also
     43  * supported by this driver. However, NetBSD driver was only tested
     44  * with the Novell adapter so far.
     45  */
     46 
     47 #include <sys/param.h>
     48 #include <sys/systm.h>
     49 #include <sys/mbuf.h>
     50 #include <sys/errno.h>
     51 #include <sys/device.h>
     52 #include <sys/protosw.h>
     53 #include <sys/socket.h>
     54 
     55 #include <net/if.h>
     56 #include <net/if_types.h>
     57 #include <net/if_media.h>
     58 #include <net/if_ether.h>
     59 
     60 #include <machine/bus.h>
     61 
     62 #include <dev/ic/dp8390reg.h>
     63 #include <dev/ic/dp8390var.h>
     64 
     65 #include <dev/ic/ne2000reg.h>
     66 #include <dev/ic/ne2000var.h>
     67 
     68 #include <dev/ic/rtl80x9reg.h>
     69 #include <dev/ic/rtl80x9var.h>
     70 
     71 #include <dev/mca/mcadevs.h>
     72 #include <dev/mca/mcavar.h>
     73 
     74 #define	NE2_NPORTS	0x30
     75 
     76 struct ne_mca_softc {
     77 	struct ne2000_softc sc_ne2000;		/* real "ne2000" softc */
     78 
     79 	/* MCA-specific goo */
     80 	void		*sc_ih;		/* interrupt handle */
     81 };
     82 
     83 int	ne_mca_match __P((struct device *, struct cfdata *, void *));
     84 void	ne_mca_attach __P((struct device *, struct device *, void *));
     85 
     86 struct cfattach ne_mca_ca = {
     87 	sizeof(struct ne_mca_softc), ne_mca_match, ne_mca_attach
     88 };
     89 
     90 static const struct ne_mca_products {
     91 	u_int32_t ne_id;
     92 	const char *ne_name;
     93 } ne_mca_products[] = {
     94 	{ MCA_PRODUCT_ARCOAE,	"Arco Electronics AE/2 Ethernet Adapter" },
     95 	{ MCA_PRODUCT_NE2,	"Novell NE/2 Ethernet Adapter" },
     96 	{ MCA_PRODUCT_CENET16, "Compex Inc. PS/2 ENET16-MC/P Microchannel Ad."},
     97 	{ 0, NULL }
     98 };
     99 
    100 static const struct ne_mca_products *ne_mca_lookup __P((int id));
    101 
    102 static const struct ne_mca_products *
    103 ne_mca_lookup(int id)
    104 {
    105 	const struct ne_mca_products *np;
    106 
    107 	for(np = ne_mca_products; np->ne_name; np++)
    108 		if (id == np->ne_id)
    109 			return (np);
    110 
    111 	return (NULL);
    112 }
    113 
    114 int
    115 ne_mca_match(struct device *parent, struct cfdata *cf, void *aux)
    116 {
    117 	struct mca_attach_args *ma = aux;
    118 
    119 	if (ne_mca_lookup(ma->ma_id))
    120 		return (1);
    121 
    122 	return (0);
    123 }
    124 
    125 /* These values were taken from NE/2 ADF file */
    126 static const int ne_mca_irq[] = {
    127 	3, 4, 5, 9
    128 };
    129 static const int ne_mca_iobase[] = {
    130 	0, 0x1000, 0x2020, 0x8020, 0xa0a0, 0xb0b0, 0xc0c0, 0xc3d0
    131 };
    132 
    133 void
    134 ne_mca_attach(struct device *parent, struct device *self, void *aux)
    135 {
    136 	struct ne_mca_softc *psc = (struct ne_mca_softc *)self;
    137 	struct ne2000_softc *nsc = &psc->sc_ne2000;
    138 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
    139 	struct mca_attach_args *ma = aux;
    140 	bus_space_tag_t nict;
    141 	bus_space_handle_t nich;
    142 	bus_space_tag_t asict;
    143 	bus_space_handle_t asich;
    144 	int pos2, iobase, irq;
    145 	const struct ne_mca_products *np;
    146 
    147 	pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
    148 
    149 	/*
    150 	 * POS register 2: (adf pos0)
    151 	 *
    152 	 * 7 6 5 4 3 2 1 0
    153 	 *   \_/ | \___/ \__ enable: 0=adapter disabled, 1=adapter enabled
    154 	 *    |  |     \____ I/O, Mem: 001=0x1000-0x102f 010=0x2020-0x204f
    155 	 *    |  |             011=0x8020-0x804f 100=0xa0a0-0xa0cf
    156 	 *    |  |             101=0xb0b0-0xb0df 110=0xc0c0-0xc0ef
    157 	 *     \  \            111=0xc3d0-0xc3ff
    158 	 *      \  \________ Boot Rom: 1=disabled 0=enabled
    159 	 *       \__________ Interrupt level: 00=3 01=4 10=5 11=9
    160 	 */
    161 
    162 	np = ne_mca_lookup(ma->ma_id);
    163 
    164 	iobase = ne_mca_iobase[(pos2 & 0x0e) >> 1];
    165 	irq = ne_mca_irq[(pos2 & 0x60) >> 5];
    166 
    167 	printf(" slot %d irq %d: %s\n", ma->ma_slot + 1, irq, np->ne_name);
    168 
    169 	nict = ma->ma_iot;
    170 
    171 	/* Map the device. */
    172 	if (bus_space_map(nict, iobase, NE2_NPORTS, 0, &nich)) {
    173 		printf("%s: can't map i/o space\n", dsc->sc_dev.dv_xname);
    174 		return;
    175 	}
    176 
    177 	asict = nict;
    178 	if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
    179 	    NE2000_ASIC_NPORTS, &asich)) {
    180 		printf("%s: can't subregion i/o space\n", dsc->sc_dev.dv_xname);
    181 		return;
    182 	}
    183 
    184 	dsc->sc_regt = nict;
    185 	dsc->sc_regh = nich;
    186 
    187 	nsc->sc_asict = asict;
    188 	nsc->sc_asich = asich;
    189 
    190 	/* This interface is always enabled. */
    191 	dsc->sc_enabled = 1;
    192 
    193 	dsc->sc_mediachange	= NULL;
    194 	dsc->sc_mediastatus	= NULL;
    195 	dsc->sc_media_init	= NULL;
    196 	dsc->init_card		= NULL;
    197 
    198 	/*
    199 	 * This is necessary for NE/2. Hopefully the other clones also work
    200 	 * this way.
    201 	 */
    202 	nsc->sc_type = NE2000_TYPE_AX88190;
    203 
    204 	/*
    205 	 * Do generic NE2000 attach.  This will read the station address
    206 	 * from the EEPROM.
    207 	 */
    208 	if (ne2000_attach(nsc, NULL))
    209 		return;
    210 
    211 	/* establish interrupt handler */
    212 	psc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET, dp8390_intr,
    213 			dsc);
    214 	if (psc->sc_ih == NULL) {
    215 		printf("%s: couldn't establish interrupt handler\n",
    216 		       dsc->sc_dev.dv_xname);
    217 		return;
    218 	}
    219 }
    220