Home | History | Annotate | Line # | Download | only in mca
if_tra_mca.c revision 1.1
      1 /*	$NetBSD: if_tra_mca.c,v 1.1 2005/04/03 11:21:44 jdolecek Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2004 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 Tiara LANCard/E II and friends adapted from if_ate_mca.c by Dave J. Barnes 2004.
     41  */
     42 
     43 #include <sys/cdefs.h>
     44 __KERNEL_RCSID(0, "$NetBSD: if_tra_mca.c,v 1.1 2005/04/03 11:21:44 jdolecek 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/mb86950reg.h>
     60 #include <dev/ic/mb86950var.h>
     61 
     62 #include <dev/mca/mcavar.h>
     63 #include <dev/mca/mcadevs.h>
     64 
     65 int	tiara_mca_match __P((struct device *, struct cfdata *, void *));
     66 void	tiara_mca_attach __P((struct device *, struct device *, void *));
     67 
     68 #define TIARA_NPORTS 0x20 /* 32 */
     69 #define TIARA_PROM_ID 24 /* offset to mac addr stored in prom */
     70 
     71 struct tiara_softc {
     72 	struct	mb86950_softc sc_mb86950;	/* real "mb86950" softc */
     73 
     74 	/* MCA-specific goo. */
     75 	void	*sc_ih;				/* interrupt cookie */
     76 };
     77 
     78 CFATTACH_DECL(tra_mca, sizeof(struct tiara_softc),
     79     tiara_mca_match, tiara_mca_attach, NULL, NULL);
     80 
     81 static const struct tiara_mca_product {
     82 	u_int32_t	tra_prodid;	/* MCA product ID */
     83 	const char	*tra_name;	/* device name */
     84 } tiara_mca_products[] = {
     85 	{ MCA_PRODUCT_TIARA,	"Tiara LANCard/E2"},
     86 	{ MCA_PRODUCT_TIARA_TP,	"Tiara LANCard/E2 TP"},
     87 	{ MCA_PRODUCT_SMC3016,  "SMC 3016/MC"},
     88 	{ 0	}
     89 };
     90 
     91 static const struct tiara_mca_product *tiara_mca_lookup __P((u_int32_t));
     92 
     93 static const struct tiara_mca_product *
     94 tiara_mca_lookup(id)
     95 	u_int32_t id;
     96 {
     97 	const struct tiara_mca_product *tra_p;
     98 
     99 	for (tra_p = tiara_mca_products; tra_p->tra_name != NULL; tra_p++)
    100 		if (id == tra_p->tra_prodid)
    101 			return (tra_p);
    102 
    103 	return (NULL);
    104 }
    105 
    106 int
    107 tiara_mca_match(parent, match, aux)
    108 	struct device *parent;
    109 	struct cfdata *match;
    110 	void *aux;
    111 {
    112 	struct mca_attach_args *ma = (struct mca_attach_args *) aux;
    113 
    114 	if (tiara_mca_lookup(ma->ma_id) != NULL)
    115 		return (1);
    116 
    117 	return (0);
    118 }
    119 
    120 /* see POS diagrams below for explanation */
    121 static const int tiara_irq[] = {
    122 	3, 4, 7, 9
    123 };
    124 static const int smc_iobase[] = {
    125 	0x300, 0x340, 0x360, 0x1980, 0x2000, 0x5680, 0x5900, 0x8080
    126 };
    127 static const int smc_irq[] = {
    128 	9, 10, 11, 15, 3, 5, 7, 4
    129 };
    130 
    131 void
    132 tiara_mca_attach(parent, self, aux)
    133 	struct device *parent, *self;
    134 	void *aux;
    135 {
    136 	struct tiara_softc *isc = (struct tiara_softc *)self;
    137 	struct mb86950_softc *sc = &isc->sc_mb86950;
    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 pos2;
    143 	int iobase = 0, irq = 0;
    144 	const struct tiara_mca_product *tra_p;
    145 
    146     pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
    147 
    148 	tra_p = tiara_mca_lookup(ma->ma_id);
    149 
    150     switch (tra_p->tra_prodid) {
    151 
    152     case MCA_PRODUCT_TIARA:
    153     case MCA_PRODUCT_TIARA_TP:
    154 
    155 		/*
    156 		 * POS register 2: (adf pos0)
    157 		 * 7 6 5 4 3 2 1 0
    158 		 * \_____/ \_/  \ \__ enable: 0=adapter disabled, 1=adapter enabled
    159 		 *       \   \   \___ boot rom: 0=disabled, 1=enabled
    160 		 *        \   \______ IRQ 00=3 01=4 10=7 11=9
    161 		 *         \_________ Base I/O Port
    162 		 *						0000=0x1200 0001=0x1220 ... 1110=0x13c0 1111=0x13e0
    163 		 *
    164 		 * POS register 3: (adf pos1) not used
    165 		 * POS register 4: (adf pos2) not used
    166 		 *
    167 		 * POS register 5: (adf pos3) ignored
    168 		 *
    169 		 * 7 6 5 4 3 2 1 0
    170 		 * 1 1 0 X \____/
    171 		 *              \____EPROM Address
    172 		 */
    173 	    iobase = 0x1200 + ((pos2 & 0xf0) << 1);
    174 	    irq = tiara_irq[((pos2 & 0x0c) >> 2)];
    175 
    176 		/* XXX SWAG for number pkts. */
    177 		/* My Tiara LANCard has 128K memory ?!? */
    178 		sc->txb_num_pkt = 4;
    179 		sc->rxb_num_pkt = (65535 - 8192 - 4) / 64;
    180 		/* XXX                       */
    181 
    182     	break;
    183 
    184 	case MCA_PRODUCT_SMC3016:
    185 		/*
    186 		 * POS register 2: (adf pos0)
    187 		 * 7 6 5 4 3 2 1 0
    188 		 * \_____/ \___/  \__ enable: 0=adapter disabled, 1=adapter enabled
    189 		 *       \     \_____ I/O Address (see ioaddr table)
    190 		 *        \__________ IRQ (see irq table)
    191 		 *
    192 		 * POS register 3: (adf pos1) ignored
    193          * 7 6 5 4 3 2 1 0
    194 		 * X X X X \____/
    195 		 *              \____EPROM Address (0000 = not used)
    196          */
    197 		iobase = smc_iobase[((pos2 & 0x0e) >> 1)];
    198 		if ((pos2 & 0x80) != 0) irq = smc_irq[((pos2 & 0x70) >> 4)];
    199 		else printf("%s: unsupported irq selected\n",sc->sc_dev.dv_xname);
    200 
    201 		/* XXX SWAG for number pkts. */
    202 		/* The SMC3016 has a 12K rx buffer and a 4k tx buffer */
    203 		sc->txb_num_pkt = 2;
    204 		sc->rxb_num_pkt = (12288 - 4) / 64;
    205 		/* XXX                       */
    206 
    207     	break;
    208     }
    209 
    210 
    211 #ifdef DIAGNOSTIC
    212 	tra_p = tiara_mca_lookup(ma->ma_id);
    213 	if (tra_p == NULL) {
    214 		printf("\n%s: where did the card go?\n", sc->sc_dev.dv_xname);
    215 		return;
    216 	}
    217 #endif
    218 
    219 	printf(" slot %d ports %#x-%#x irq %d: %s\n", ma->ma_slot + 1,iobase, iobase + TIARA_NPORTS, irq, tra_p->tra_name);
    220 
    221 	/* Map i/o space. */
    222 	if (bus_space_map(iot, iobase, TIARA_NPORTS, 0, &ioh)) {
    223 		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
    224 		return;
    225 	}
    226 
    227 	sc->sc_bst = iot;
    228 	sc->sc_bsh = ioh;
    229 
    230 	/* Get ethernet address from PROM */
    231 	bus_space_read_region_1(iot, ioh, TIARA_PROM_ID, myea, ETHER_ADDR_LEN);
    232 
    233 	/* This interface is always enabled. */
    234 /* XXX
    235 	sc->sc_stat |= NIC_STAT_ENABLED;
    236 */
    237 	/*
    238 	 * Do generic MB86950 attach.
    239 	 */
    240 	mb86950_attach(sc, myea);
    241 
    242 
    243 	mb86950_config(sc, NULL, 0, 0);
    244 
    245 	/* Establish the interrupt handler. */
    246 	isc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET,
    247 			mb86950_intr, sc);
    248 	if (isc->sc_ih == NULL) {
    249 		printf("%s: couldn't establish interrupt handler\n",
    250 		    sc->sc_dev.dv_xname);
    251 		return;
    252 	}
    253 }
    254