Home | History | Annotate | Line # | Download | only in mca
if_ep_mca.c revision 1.2.2.3
      1  1.2.2.3  nathanw /*	$NetBSD: if_ep_mca.c,v 1.2.2.3 2001/06/21 20:04:04 nathanw Exp $	*/
      2  1.2.2.2  nathanw 
      3  1.2.2.2  nathanw /*-
      4  1.2.2.2  nathanw  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  1.2.2.2  nathanw  * All rights reserved.
      6  1.2.2.2  nathanw  *
      7  1.2.2.2  nathanw  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2.2.2  nathanw  * by Jaromir Dolecek.
      9  1.2.2.2  nathanw  *
     10  1.2.2.2  nathanw  * Redistribution and use in source and binary forms, with or without
     11  1.2.2.2  nathanw  * modification, are permitted provided that the following conditions
     12  1.2.2.2  nathanw  * are met:
     13  1.2.2.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     14  1.2.2.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     15  1.2.2.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.2.2.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     17  1.2.2.2  nathanw  *    documentation and/or other materials provided with the distribution.
     18  1.2.2.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     19  1.2.2.2  nathanw  *    must display the following acknowledgement:
     20  1.2.2.2  nathanw  *	This product includes software developed by the NetBSD
     21  1.2.2.2  nathanw  *	Foundation, Inc. and its contributors.
     22  1.2.2.2  nathanw  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.2.2.2  nathanw  *    contributors may be used to endorse or promote products derived
     24  1.2.2.2  nathanw  *    from this software without specific prior written permission.
     25  1.2.2.2  nathanw  *
     26  1.2.2.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.2.2.2  nathanw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.2.2.2  nathanw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.2.2.2  nathanw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.2.2.2  nathanw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.2.2.2  nathanw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.2.2.2  nathanw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.2.2.2  nathanw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.2.2.2  nathanw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.2.2.2  nathanw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.2.2.2  nathanw  * POSSIBILITY OF SUCH DAMAGE.
     37  1.2.2.2  nathanw  */
     38  1.2.2.2  nathanw 
     39  1.2.2.2  nathanw /*
     40  1.2.2.2  nathanw  * Copyright (c) 1997 Jonathan Stone <jonathan (at) NetBSD.org>
     41  1.2.2.2  nathanw  * Copyright (c) 1994 Herb Peyerl <hpeyerl (at) beer.org>
     42  1.2.2.2  nathanw  * All rights reserved.
     43  1.2.2.2  nathanw  *
     44  1.2.2.2  nathanw  * Redistribution and use in source and binary forms, with or without
     45  1.2.2.2  nathanw  * modification, are permitted provided that the following conditions
     46  1.2.2.2  nathanw  * are met:
     47  1.2.2.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     48  1.2.2.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     49  1.2.2.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     50  1.2.2.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     51  1.2.2.2  nathanw  *    documentation and/or other materials provided with the distribution.
     52  1.2.2.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     53  1.2.2.2  nathanw  *    must display the following acknowledgement:
     54  1.2.2.2  nathanw  *      This product includes software developed by Herb Peyerl.
     55  1.2.2.2  nathanw  * 4. The name of Herb Peyerl may not be used to endorse or promote products
     56  1.2.2.2  nathanw  *    derived from this software without specific prior written permission.
     57  1.2.2.2  nathanw  *
     58  1.2.2.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     59  1.2.2.2  nathanw  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     60  1.2.2.2  nathanw  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     61  1.2.2.2  nathanw  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     62  1.2.2.2  nathanw  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     63  1.2.2.2  nathanw  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     64  1.2.2.2  nathanw  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     65  1.2.2.2  nathanw  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     66  1.2.2.2  nathanw  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     67  1.2.2.2  nathanw  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     68  1.2.2.2  nathanw  */
     69  1.2.2.2  nathanw 
     70  1.2.2.2  nathanw /*
     71  1.2.2.2  nathanw  * Driver for 3Com 3c529 cards.
     72  1.2.2.2  nathanw  *
     73  1.2.2.3  nathanw  * If you encouter sucky performance, try kernel without DEBUG/DIAGNOSTIC.
     74  1.2.2.3  nathanw  * This helped on my test machine to change the performance of the card
     75  1.2.2.3  nathanw  * from like 5KB/s to like 800 KB/s.
     76  1.2.2.2  nathanw  */
     77  1.2.2.2  nathanw 
     78  1.2.2.2  nathanw #include <sys/param.h>
     79  1.2.2.2  nathanw #include <sys/systm.h>
     80  1.2.2.2  nathanw #include <sys/mbuf.h>
     81  1.2.2.2  nathanw #include <sys/socket.h>
     82  1.2.2.2  nathanw #include <sys/ioctl.h>
     83  1.2.2.2  nathanw #include <sys/errno.h>
     84  1.2.2.2  nathanw #include <sys/device.h>
     85  1.2.2.2  nathanw 
     86  1.2.2.2  nathanw #include <net/if.h>
     87  1.2.2.2  nathanw #include <net/if_ether.h>
     88  1.2.2.2  nathanw #include <net/if_media.h>
     89  1.2.2.2  nathanw 
     90  1.2.2.2  nathanw #include <machine/bus.h>
     91  1.2.2.2  nathanw 
     92  1.2.2.2  nathanw #include <dev/mii/miivar.h>
     93  1.2.2.2  nathanw 
     94  1.2.2.2  nathanw #include <dev/ic/elink3var.h>
     95  1.2.2.2  nathanw #include <dev/ic/elink3reg.h>
     96  1.2.2.2  nathanw 
     97  1.2.2.2  nathanw #include <dev/mca/mcavar.h>
     98  1.2.2.2  nathanw #include <dev/mca/mcadevs.h>
     99  1.2.2.2  nathanw 
    100  1.2.2.2  nathanw /*
    101  1.2.2.2  nathanw  * MCA constants.
    102  1.2.2.2  nathanw  */
    103  1.2.2.2  nathanw #define MCA_CBIO		0x200	/* Configuration Base IO Address */
    104  1.2.2.2  nathanw #define MCA_IOSZ		0x10	/* I/O space size */
    105  1.2.2.2  nathanw 
    106  1.2.2.2  nathanw int ep_mca_match __P((struct device *, struct cfdata *, void *));
    107  1.2.2.2  nathanw void ep_mca_attach __P((struct device *, struct device *, void *));
    108  1.2.2.2  nathanw 
    109  1.2.2.2  nathanw struct cfattach ep_mca_ca = {
    110  1.2.2.2  nathanw 	sizeof(struct ep_softc), ep_mca_match, ep_mca_attach
    111  1.2.2.2  nathanw };
    112  1.2.2.2  nathanw 
    113  1.2.2.2  nathanw const struct ep_mca_product {
    114  1.2.2.2  nathanw 	u_int32_t	epp_prodid;	/* MCA product ID */
    115  1.2.2.2  nathanw 	const char	*epp_name;	/* device name */
    116  1.2.2.2  nathanw } ep_mca_products[] = {
    117  1.2.2.2  nathanw 	{ MCA_PRODUCT_3C529_TP,	"3c529-TP Ethernet Adapter" },
    118  1.2.2.2  nathanw 	{ MCA_PRODUCT_3C529_TM, "3c529 Ethernet Adapter (test mode)" },
    119  1.2.2.2  nathanw 	{ MCA_PRODUCT_3C529_2T, "3c529 Ethernet Adapter (10base2/T)" },
    120  1.2.2.2  nathanw 	{ MCA_PRODUCT_3C529_T,	"3c529 Ethernet Adapter (10baseT)"   },
    121  1.2.2.2  nathanw 
    122  1.2.2.2  nathanw 	{ 0,			NULL },
    123  1.2.2.2  nathanw };
    124  1.2.2.2  nathanw 
    125  1.2.2.2  nathanw static const struct ep_mca_product *ep_mca_lookup
    126  1.2.2.2  nathanw     __P((const struct mca_attach_args *));
    127  1.2.2.2  nathanw 
    128  1.2.2.2  nathanw static const struct ep_mca_product *
    129  1.2.2.2  nathanw ep_mca_lookup(ma)
    130  1.2.2.2  nathanw 	const struct mca_attach_args *ma;
    131  1.2.2.2  nathanw {
    132  1.2.2.2  nathanw 	const struct ep_mca_product *epp;
    133  1.2.2.2  nathanw 
    134  1.2.2.2  nathanw 	for (epp = ep_mca_products; epp->epp_name != NULL; epp++)
    135  1.2.2.2  nathanw 		if (ma->ma_id == epp->epp_prodid)
    136  1.2.2.2  nathanw 			return (epp);
    137  1.2.2.2  nathanw 
    138  1.2.2.2  nathanw 	return (NULL);
    139  1.2.2.2  nathanw }
    140  1.2.2.2  nathanw 
    141  1.2.2.2  nathanw int
    142  1.2.2.2  nathanw ep_mca_match(parent, match, aux)
    143  1.2.2.2  nathanw 	struct device *parent;
    144  1.2.2.2  nathanw 	struct cfdata *match;
    145  1.2.2.2  nathanw 	void *aux;
    146  1.2.2.2  nathanw {
    147  1.2.2.2  nathanw 	struct mca_attach_args *ma = (struct mca_attach_args *) aux;
    148  1.2.2.2  nathanw 
    149  1.2.2.2  nathanw 	if (ep_mca_lookup(ma) != NULL)
    150  1.2.2.2  nathanw 		return (1);
    151  1.2.2.2  nathanw 
    152  1.2.2.2  nathanw 	return (0);
    153  1.2.2.2  nathanw }
    154  1.2.2.2  nathanw 
    155  1.2.2.2  nathanw void
    156  1.2.2.2  nathanw ep_mca_attach(parent, self, aux)
    157  1.2.2.2  nathanw 	struct device *parent, *self;
    158  1.2.2.2  nathanw 	void *aux;
    159  1.2.2.2  nathanw {
    160  1.2.2.2  nathanw 	struct ep_softc *sc = (void *)self;
    161  1.2.2.2  nathanw 	struct mca_attach_args *ma = aux;
    162  1.2.2.2  nathanw 	bus_space_handle_t ioh;
    163  1.2.2.2  nathanw 	int pos4, pos5, iobase, irq, media;
    164  1.2.2.2  nathanw 	const struct ep_mca_product *epp;
    165  1.2.2.2  nathanw 
    166  1.2.2.2  nathanw 	pos4 = mca_conf_read(ma->ma_mc, ma->ma_slot, 4);
    167  1.2.2.2  nathanw 	pos5 = mca_conf_read(ma->ma_mc, ma->ma_slot, 5);
    168  1.2.2.2  nathanw 
    169  1.2.2.2  nathanw 	/*
    170  1.2.2.2  nathanw 	 * POS register 2: (adf pos0)
    171  1.2.2.2  nathanw 	 * 7 6 5 4 3 2 1 0
    172  1.2.2.2  nathanw 	 *               \__ enable: 0=adapter disabled, 1=adapter enabled
    173  1.2.2.2  nathanw 	 *
    174  1.2.2.2  nathanw 	 * POS register 3: (adf pos1)
    175  1.2.2.2  nathanw 	 *
    176  1.2.2.2  nathanw 	 * 7 6 5 4 3 2 1 0
    177  1.2.2.2  nathanw 	 * \________/
    178  1.2.2.2  nathanw 	 *          \_______ Boot ROM Address Range: 0=disabled
    179  1.2.2.2  nathanw 	 *                     X=0xc2000-0xc3fff + (x * 0x2000)
    180  1.2.2.2  nathanw 	 *
    181  1.2.2.2  nathanw 	 * POS register 4: (adf pos2)
    182  1.2.2.2  nathanw 	 *
    183  1.2.2.2  nathanw 	 * 7 6 5 4 3 2 1 0
    184  1.2.2.2  nathanw 	 * \________/  \_/
    185  1.2.2.2  nathanw 	 *          \    \__ Transceiver Type: 00=on-board (RJ45), 01=ext(AUI)
    186  1.2.2.2  nathanw 	 *           \______ I/O Address Range: 0x200-0x20f + ((x>>2) * 0x400)
    187  1.2.2.2  nathanw 	 *
    188  1.2.2.2  nathanw 	 * POS register 5: (adf pos3)
    189  1.2.2.2  nathanw 	 *
    190  1.2.2.2  nathanw 	 * 7 6 5 4 3 2 1 0
    191  1.2.2.2  nathanw 	 *          \____/
    192  1.2.2.2  nathanw 	 *               \__ Interrupt level
    193  1.2.2.2  nathanw 	 */
    194  1.2.2.2  nathanw 
    195  1.2.2.2  nathanw 	iobase = MCA_CBIO + (((pos4 & 0xfc) >> 2) * 0x400);
    196  1.2.2.3  nathanw 	irq = (pos5 & 0x0f);
    197  1.2.2.2  nathanw 
    198  1.2.2.2  nathanw 	/* map the pio registers */
    199  1.2.2.2  nathanw 	if (bus_space_map(ma->ma_iot, iobase, MCA_IOSZ, 0, &ioh)) {
    200  1.2.2.3  nathanw 		printf(": unable to map i/o space\n", sc->sc_dev.dv_xname);
    201  1.2.2.2  nathanw 		return;
    202  1.2.2.2  nathanw 	}
    203  1.2.2.2  nathanw 
    204  1.2.2.2  nathanw 	sc->sc_iot = ma->ma_iot;
    205  1.2.2.2  nathanw 	sc->sc_ioh = ioh;
    206  1.2.2.2  nathanw 
    207  1.2.2.2  nathanw 	epp = ep_mca_lookup(ma);
    208  1.2.2.2  nathanw 	if (epp == NULL) {
    209  1.2.2.2  nathanw 		printf("\n");
    210  1.2.2.2  nathanw 		panic("ep_mca_attach: impossible");
    211  1.2.2.2  nathanw 	}
    212  1.2.2.2  nathanw 
    213  1.2.2.3  nathanw 	printf(" slot %d irq %d: 3Com %s\n", ma->ma_slot + 1,
    214  1.2.2.3  nathanw 		irq, epp->epp_name);
    215  1.2.2.2  nathanw 
    216  1.2.2.2  nathanw 	sc->enable = NULL;
    217  1.2.2.2  nathanw 	sc->disable = NULL;
    218  1.2.2.2  nathanw 	sc->enabled = 1;
    219  1.2.2.2  nathanw 
    220  1.2.2.2  nathanw 	sc->bustype = ELINK_BUS_MCA;
    221  1.2.2.2  nathanw 	sc->ep_flags = 0;
    222  1.2.2.2  nathanw 
    223  1.2.2.2  nathanw 	if (epconfig(sc, ELINK_CHIPSET_3C509, NULL))
    224  1.2.2.2  nathanw 		return;
    225  1.2.2.2  nathanw 
    226  1.2.2.2  nathanw 	/* Map and establish the interrupt. */
    227  1.2.2.2  nathanw 	sc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET, epintr, sc);
    228  1.2.2.2  nathanw 	if (sc->sc_ih == NULL) {
    229  1.2.2.2  nathanw 		printf("%s: couldn't establish interrupt handler\n",
    230  1.2.2.2  nathanw 		    sc->sc_dev.dv_xname);
    231  1.2.2.2  nathanw 		return;
    232  1.2.2.2  nathanw 	}
    233  1.2.2.2  nathanw 
    234  1.2.2.2  nathanw 	/*
    235  1.2.2.2  nathanw 	 * Set default media to be same as the one selected in POS.
    236  1.2.2.2  nathanw 	 */
    237  1.2.2.2  nathanw 	switch (pos4 & 0x03) {
    238  1.2.2.2  nathanw 	case 0x00:
    239  1.2.2.2  nathanw 		/* on-board RJ-45 */
    240  1.2.2.2  nathanw 		media = IFM_10_T;
    241  1.2.2.2  nathanw 		break;
    242  1.2.2.2  nathanw 	case 0x01:
    243  1.2.2.2  nathanw 		/* external AUI */
    244  1.2.2.2  nathanw 		media = IFM_10_5;
    245  1.2.2.2  nathanw 		break;
    246  1.2.2.2  nathanw 	case 0x02:
    247  1.2.2.2  nathanw 		/* undefined, should never be set */
    248  1.2.2.2  nathanw 		media = IFM_NONE;
    249  1.2.2.2  nathanw 		break;
    250  1.2.2.2  nathanw 	case 0x03:
    251  1.2.2.2  nathanw 		/* BNC */
    252  1.2.2.2  nathanw 		media = IFM_10_2;
    253  1.2.2.2  nathanw 		break;
    254  1.2.2.2  nathanw 	}
    255  1.2.2.2  nathanw 	ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|media);
    256  1.2.2.2  nathanw }
    257