Home | History | Annotate | Line # | Download | only in mca
if_ate_mca.c revision 1.16
      1 /*	$NetBSD: if_ate_mca.c,v 1.16 2006/10/12 01:31:25 christos 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.16 2006/10/12 01:31:25 christos 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,			NULL,		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(struct device *parent __unused, struct cfdata *match __unused,
    111     void *aux)
    112 {
    113 	struct mca_attach_args *ma = (struct mca_attach_args *) aux;
    114 
    115 	if (ate_mca_lookup(ma->ma_id) != NULL)
    116 		return (1);
    117 
    118 	return (0);
    119 }
    120 
    121 /* see POS diagrams below for explanation of these arrays' contents */
    122 static const int ats_iobase[] = {
    123 	0x400, 0x2400, 0x4400, 0x6400, 0x1400, 0x3400, 0x5400, 0x7400
    124 };
    125 static const int ats_irq[] = {
    126 	3, 4, 5, 9, 10, 11, 12, 15
    127 };
    128 
    129 void
    130 ate_mca_attach(struct device *parent __unused, struct device *self,
    131     void *aux)
    132 {
    133 	struct ate_softc *isc = device_private(self);
    134 	struct mb86960_softc *sc = &isc->sc_mb86960;
    135 	struct mca_attach_args *ma = aux;
    136 	bus_space_tag_t iot = ma->ma_iot;
    137 	bus_space_handle_t ioh;
    138 	u_int8_t myea[ETHER_ADDR_LEN];
    139 	int pos3, pos4;
    140 	int iobase, irq;
    141 	const struct ate_mca_product *atp;
    142 
    143 	pos3 = mca_conf_read(ma->ma_mc, ma->ma_slot, 3);
    144 	pos4 = mca_conf_read(ma->ma_mc, ma->ma_slot, 4);
    145 
    146 	/*
    147 	 * POS register 2: (adf pos0)
    148 	 * 7 6 5 4 3 2 1 0
    149 	 *               \__ enable: 0=adapter disabled, 1=adapter enabled
    150 	 *
    151 	 * POS register 3: (adf pos1)
    152 	 *
    153 	 * 7 6 5 4 3 2 1 0
    154 	 * \_/ \___/ \___/
    155 	 *   \     \     \__ I/O Port Addresses: 000=0x400-0x4FF 100=0x1400-
    156 	 *    \     \          001=0x2400 101=0x3400 010=0x4400 110=0x5400
    157 	 *     \     \         011=0x6400 111=0x7400
    158 	 *      \     \_____ Boot ROM Memory Address
    159 	 *       \
    160 	 *        \_________ Lower 2 bit of Interrupt Request Number
    161 	 *
    162 	 * POS register 4: (adf pos2)
    163 	 *
    164 	 * 7 6 5 4 3 2 1 0
    165 	 *   \      \_______ Twisted Pair Type: 0=100 ohm, Unshielded
    166 	 *    \                1=150 ohm, Shielded
    167 	 *     \____________ Higher 1 bit of Interrupt Request Number:
    168 	 *                   000=3 001=4 010=5 011=9 100=10 101=11 110=12 111=15
    169 	 */
    170 
    171 	atp = ate_mca_lookup(ma->ma_id);
    172 #ifdef DIAGNOSTIC
    173 	if (atp == NULL) {
    174 		printf("\n%s: where did the card go?\n", sc->sc_dev.dv_xname);
    175 		return;
    176 	}
    177 #endif
    178 
    179 	iobase = ats_iobase[pos3 & 0x7];
    180 	irq = ats_irq[((pos4 & 0x40) >> 4) | ((pos3 & 0xc0) >> 6)];
    181 
    182 	printf(" slot %d irq %d: %s\n", ma->ma_slot + 1, irq, atp->at_name);
    183 
    184 	/* Map i/o space. */
    185 	if (bus_space_map(iot, iobase, ATE_NPORTS, 0, &ioh)) {
    186 		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
    187 		return;
    188 	}
    189 
    190 	sc->sc_bst = iot;
    191 	sc->sc_bsh = ioh;
    192 
    193 	/* Get ethernet address. */
    194 	ate_mca_detect(iot, ioh, myea);
    195 
    196 	/* This interface is always enabled. */
    197 	sc->sc_stat |= FE_STAT_ENABLED;
    198 
    199 	/*
    200 	 * Do generic MB86960 attach.
    201 	 */
    202 	mb86960_attach(sc, myea);
    203 
    204 	mb86960_config(sc, NULL, 0, 0);
    205 
    206 	/* Establish the interrupt handler. */
    207 	isc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET,
    208 			mb86960_intr, sc);
    209 	if (isc->sc_ih == NULL) {
    210 		printf("%s: couldn't establish interrupt handler\n",
    211 		    sc->sc_dev.dv_xname);
    212 		return;
    213 	}
    214 }
    215 
    216 /*
    217  * Very simplified ate_detect() from dev/isa/if_ate.c, only
    218  * to determine ethernet address.
    219  */
    220 static void
    221 ate_mca_detect(iot, ioh, enaddr)
    222 	bus_space_tag_t iot;
    223 	bus_space_handle_t ioh;
    224 	u_int8_t enaddr[ETHER_ADDR_LEN];
    225 {
    226 	u_int8_t eeprom[FE_EEPROM_SIZE];
    227 
    228 	/* Get our station address from EEPROM. */
    229 	mb86965_read_eeprom(iot, ioh, eeprom);
    230 	memcpy(enaddr, eeprom + FE_ATI_EEP_ADDR, ETHER_ADDR_LEN);
    231 }
    232