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