Home | History | Annotate | Line # | Download | only in mca
if_ate_mca.c revision 1.5
      1 /*	$NetBSD: if_ate_mca.c,v 1.5 2002/09/28 18:19:09 tsutsui 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 ATI AT1720X MCA cards based on Fujitsu MB8696xA controller.
     41  */
     42 
     43 #include <sys/cdefs.h>
     44 __KERNEL_RCSID(0, "$NetBSD: if_ate_mca.c,v 1.5 2002/09/28 18:19:09 tsutsui Exp $");
     45 
     46 #include <sys/param.h>
     47 #include <sys/systm.h>
     48 #include <sys/device.h>
     49 #include <sys/socket.h>
     50 #include <sys/syslog.h>
     51 
     52 #include <net/if.h>
     53 #include <net/if_ether.h>
     54 #include <net/if_media.h>
     55 
     56 #include <machine/bus.h>
     57 #include <machine/intr.h>
     58 
     59 #include <dev/ic/mb86960reg.h>
     60 #include <dev/ic/mb86960var.h>
     61 #include <dev/ic/ate_subr.h>
     62 
     63 #include <dev/mca/mcavar.h>
     64 #include <dev/mca/mcadevs.h>
     65 
     66 int	ate_mca_match __P((struct device *, struct cfdata *, void *));
     67 void	ate_mca_attach __P((struct device *, struct device *, void *));
     68 static void ate_mca_detect __P((bus_space_tag_t, bus_space_handle_t,
     69     u_int8_t enaddr[ETHER_ADDR_LEN]));
     70 
     71 #define ATE_NPORTS 0x20
     72 
     73 struct ate_softc {
     74 	struct	mb86960_softc sc_mb86960;	/* real "mb86960" softc */
     75 
     76 	/* MCA-specific goo. */
     77 	void	*sc_ih;				/* interrupt cookie */
     78 };
     79 
     80 const struct cfattach ate_mca_ca = {
     81 	sizeof(struct ate_softc), ate_mca_match, ate_mca_attach
     82 };
     83 
     84 static const struct ate_mca_product {
     85 	u_int32_t	at_prodid;	/* MCA product ID */
     86 	const char	*at_name;	/* device name */
     87 	int		at_type;	/* device type */
     88 } ate_mca_products[] = {
     89 	{ MCA_PRODUCT_AT1720T,	"ATI AT1720T",	FE_TYPE_AT1700T		},
     90 	{ MCA_PRODUCT_AT1720BT,	"ATI AT1720BT",	FE_TYPE_AT1700BT	},
     91 	{ MCA_PRODUCT_AT1720AT, "ATI AT1720AT",	FE_TYPE_AT1700AT	},
     92 	{ MCA_PRODUCT_AT1720FT, "ATI AT1720FT",	FE_TYPE_AT1700FT	},
     93 	{ 0, 	},
     94 };
     95 
     96 static const struct ate_mca_product *ate_mca_lookup __P((u_int32_t));
     97 
     98 static const struct ate_mca_product *
     99 ate_mca_lookup(id)
    100 	u_int32_t id;
    101 {
    102 	const struct ate_mca_product *atp;
    103 
    104 	for (atp = ate_mca_products; atp->at_name != NULL; atp++)
    105 		if (id == atp->at_prodid)
    106 			return (atp);
    107 
    108 	return (NULL);
    109 }
    110 
    111 int
    112 ate_mca_match(parent, match, aux)
    113 	struct device *parent;
    114 	struct cfdata *match;
    115 	void *aux;
    116 {
    117 	struct mca_attach_args *ma = (struct mca_attach_args *) aux;
    118 
    119 	if (ate_mca_lookup(ma->ma_id) != NULL)
    120 		return (1);
    121 
    122 	return (0);
    123 }
    124 
    125 /* see POS diagrams below for explanation of these arrays' contents */
    126 static const int ats_iobase[] = {
    127 	0x400, 0x2400, 0x4400, 0x6400, 0x1400, 0x3400, 0x5400, 0x7400
    128 };
    129 static const int ats_irq[] = {
    130 	3, 4, 5, 9, 10, 11, 12, 15
    131 };
    132 
    133 void
    134 ate_mca_attach(parent, self, aux)
    135 	struct device *parent, *self;
    136 	void *aux;
    137 {
    138 	struct ate_softc *isc = (struct ate_softc *)self;
    139 	struct mb86960_softc *sc = &isc->sc_mb86960;
    140 	struct mca_attach_args *ma = aux;
    141 	bus_space_tag_t iot = ma->ma_iot;
    142 	bus_space_handle_t ioh;
    143 	u_int8_t myea[ETHER_ADDR_LEN];
    144 	int type, pos3, pos4;
    145 	int iobase, irq;
    146 	const struct ate_mca_product *atp;
    147 
    148 	pos3 = mca_conf_read(ma->ma_mc, ma->ma_slot, 3);
    149 	pos4 = mca_conf_read(ma->ma_mc, ma->ma_slot, 4);
    150 
    151 	/*
    152 	 * POS register 2: (adf pos0)
    153 	 * 7 6 5 4 3 2 1 0
    154 	 *               \__ enable: 0=adapter disabled, 1=adapter enabled
    155 	 *
    156 	 * POS register 3: (adf pos1)
    157 	 *
    158 	 * 7 6 5 4 3 2 1 0
    159 	 * \_/ \___/ \___/
    160 	 *   \     \     \__ I/O Port Addresses: 000=0x400-0x4FF 100=0x1400-
    161 	 *    \     \          001=0x2400 101=0x3400 010=0x4400 110=0x5400
    162 	 *     \     \         011=0x6400 111=0x7400
    163 	 *      \     \_____ Boot ROM Memory Address
    164 	 *       \
    165 	 *        \_________ Lower 2 bit of Interrupt Request Number
    166 	 *
    167 	 * POS register 4: (adf pos2)
    168 	 *
    169 	 * 7 6 5 4 3 2 1 0
    170 	 *   \      \_______ Twisted Pair Type: 0=100 ohm, Unshielded
    171 	 *    \                1=150 ohm, Shielded
    172 	 *     \____________ Higher 1 bit of Interrupt Request Number:
    173 	 *                   000=3 001=4 010=5 011=9 100=10 101=11 110=12 111=15
    174 	 */
    175 
    176 	atp = ate_mca_lookup(ma->ma_id);
    177 #ifdef DIAGNOSTIC
    178 	if (atp == NULL) {
    179 		printf("\n%s: where did the card go?\n", sc->sc_dev.dv_xname);
    180 		return;
    181 	}
    182 #endif
    183 
    184 	iobase = ats_iobase[pos3 & 0x7];
    185 	irq = ats_irq[((pos4 & 0x40) >> 4) | ((pos3 & 0xc0) >> 6)];
    186 
    187 	printf(" slot %d irq %d: %s\n", ma->ma_slot + 1, irq, atp->at_name);
    188 
    189 	/* Map i/o space. */
    190 	if (bus_space_map(iot, iobase, ATE_NPORTS, 0, &ioh)) {
    191 		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
    192 		return;
    193 	}
    194 
    195 	sc->sc_bst = iot;
    196 	sc->sc_bsh = ioh;
    197 
    198 	/* Determine the card type and get ethernet address. */
    199 	ate_mca_detect(iot, ioh, myea);
    200 	type = atp->at_type;
    201 
    202 	/* This interface is always enabled. */
    203 	sc->sc_flags |= FE_FLAGS_ENABLED;
    204 
    205 	/*
    206 	 * Do generic MB86960 attach.
    207 	 */
    208 	mb86960_attach(sc, MB86960_TYPE_86965, myea);
    209 
    210 	mb86960_config(sc, NULL, 0, 0);
    211 
    212 	/* Establish the interrupt handler. */
    213 	isc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET,
    214 			mb86960_intr, sc);
    215 	if (isc->sc_ih == NULL) {
    216 		printf("%s: couldn't establish interrupt handler\n",
    217 		    sc->sc_dev.dv_xname);
    218 		return;
    219 	}
    220 }
    221 
    222 /*
    223  * Very simplified ate_detect() from dev/isa/if_ate.c, only
    224  * to determine ethernet address.
    225  */
    226 static void
    227 ate_mca_detect(iot, ioh, enaddr)
    228 	bus_space_tag_t iot;
    229 	bus_space_handle_t ioh;
    230 	u_int8_t enaddr[ETHER_ADDR_LEN];
    231 {
    232 	u_char eeprom[FE_EEPROM_SIZE];
    233 
    234 	/* Get our station address from EEPROM. */
    235 	ate_read_eeprom(iot, ioh, eeprom);
    236 	bcopy(eeprom + FE_ATI_EEP_ADDR, enaddr, ETHER_ADDR_LEN);
    237 }
    238