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