Home | History | Annotate | Line # | Download | only in mca
if_tra_mca.c revision 1.14.12.2
      1 /*	$NetBSD: if_tra_mca.c,v 1.14.12.2 2012/10/30 17:21:19 yamt 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  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /*
     33  * Driver for Tiara LANCard/E II and friends adapted from if_ate_mca.c
     34  * by Dave J. Barnes 2004.
     35  */
     36 
     37 #include <sys/cdefs.h>
     38 __KERNEL_RCSID(0, "$NetBSD: if_tra_mca.c,v 1.14.12.2 2012/10/30 17:21:19 yamt Exp $");
     39 
     40 #include <sys/param.h>
     41 #include <sys/systm.h>
     42 #include <sys/device.h>
     43 #include <sys/socket.h>
     44 #include <sys/syslog.h>
     45 #include <sys/rnd.h>
     46 
     47 #include <net/if.h>
     48 #include <net/if_ether.h>
     49 #include <net/if_media.h>
     50 
     51 #include <sys/bus.h>
     52 #include <sys/intr.h>
     53 
     54 #include <dev/ic/mb86950reg.h>
     55 #include <dev/ic/mb86950var.h>
     56 
     57 #include <dev/mca/mcavar.h>
     58 #include <dev/mca/mcadevs.h>
     59 
     60 int	tiara_mca_match(device_t, cfdata_t, void *);
     61 void	tiara_mca_attach(device_t, device_t, void *);
     62 
     63 #define TIARA_NPORTS 0x20 /* 32 */
     64 #define TIARA_PROM_ID 24 /* offset to mac addr stored in prom */
     65 
     66 struct tiara_softc {
     67 	struct	mb86950_softc sc_mb86950;	/* real "mb86950" softc */
     68 
     69 	/* MCA-specific goo. */
     70 	void	*sc_ih;				/* interrupt cookie */
     71 };
     72 
     73 CFATTACH_DECL_NEW(tra_mca, sizeof(struct tiara_softc),
     74     tiara_mca_match, tiara_mca_attach, NULL, NULL);
     75 
     76 static const struct tiara_mca_product {
     77 	u_int32_t	tra_prodid;	/* MCA product ID */
     78 	const char	*tra_name;	/* device name */
     79 } tiara_mca_products[] = {
     80 	{ MCA_PRODUCT_TIARA,	"Tiara LANCard/E2"},
     81 	{ MCA_PRODUCT_TIARA_TP,	"Tiara LANCard/E2 TP"},
     82 	{ MCA_PRODUCT_SMC3016,  "SMC 3016/MC"},
     83 	{ 0,			NULL },
     84 };
     85 
     86 static const struct tiara_mca_product *tiara_mca_lookup(u_int32_t);
     87 
     88 static const struct tiara_mca_product *
     89 tiara_mca_lookup(u_int32_t id)
     90 {
     91 	const struct tiara_mca_product *tra_p;
     92 
     93 	for (tra_p = tiara_mca_products; tra_p->tra_name != NULL; tra_p++)
     94 		if (id == tra_p->tra_prodid)
     95 			return (tra_p);
     96 
     97 	return (NULL);
     98 }
     99 
    100 int
    101 tiara_mca_match(device_t parent, cfdata_t match, void *aux)
    102 {
    103 	struct mca_attach_args *ma = (struct mca_attach_args *) aux;
    104 
    105 	if (tiara_mca_lookup(ma->ma_id) != NULL)
    106 		return (1);
    107 
    108 	return (0);
    109 }
    110 
    111 /* see POS diagrams below for explanation */
    112 static const int tiara_irq[] = {
    113 	3, 4, 7, 9
    114 };
    115 static const int smc_iobase[] = {
    116 	0x300, 0x340, 0x360, 0x1980, 0x2000, 0x5680, 0x5900, 0x8080
    117 };
    118 static const int smc_irq[] = {
    119 	9, 10, 11, 15, 3, 5, 7, 4
    120 };
    121 
    122 void
    123 tiara_mca_attach(device_t parent, device_t self, void *aux)
    124 {
    125 	struct tiara_softc *isc = device_private(self);
    126 	struct mb86950_softc *sc = &isc->sc_mb86950;
    127 	struct mca_attach_args *ma = aux;
    128 	bus_space_tag_t iot = ma->ma_iot;
    129 	bus_space_handle_t ioh;
    130 	u_int8_t myea[ETHER_ADDR_LEN];
    131 	int pos2;
    132 	int iobase = 0, irq = 0;
    133 	const struct tiara_mca_product *tra_p;
    134 
    135 	pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
    136 
    137 	tra_p = tiara_mca_lookup(ma->ma_id);
    138 
    139 	switch (tra_p->tra_prodid) {
    140 
    141 	case MCA_PRODUCT_TIARA:
    142 	case MCA_PRODUCT_TIARA_TP:
    143 		/*
    144 		 * POS register 2: (adf pos0)
    145 		 * 7 6 5 4 3 2 1 0
    146 		 * \_____/ \_/  \ \__ enable: 0=disabled, 1=enabled
    147 		 *       \   \   \___ boot rom: 0=disabled, 1=enabled
    148 		 *        \   \______ IRQ 00=3 01=4 10=7 11=9
    149 		 *         \_________ Base I/O Port
    150 		 *			0000=0x1200 0001=0x1220 ... 1110=0x13c0 1111=0x13e0
    151 		 *
    152 		 * POS register 3: (adf pos1) not used
    153 		 * POS register 4: (adf pos2) not used
    154 		 *
    155 		 * POS register 5: (adf pos3) ignored
    156 		 *
    157 		 * 7 6 5 4 3 2 1 0
    158 		 * 1 1 0 X \____/
    159 		 *              \____EPROM Address
    160 		 */
    161 		iobase = 0x1200 + ((pos2 & 0xf0) << 1);
    162 		irq = tiara_irq[((pos2 & 0x0c) >> 2)];
    163 
    164 		/* XXX SWAG for number pkts. */
    165 		/* My Tiara LANCard has 128K memory ?!? */
    166 		sc->txb_num_pkt = 4;
    167 		sc->rxb_num_pkt = (65535 - 8192 - 4) / 64;
    168 		/* XXX                       */
    169 
    170 		break;
    171 
    172 	case MCA_PRODUCT_SMC3016:
    173 		/*
    174 		 * POS register 2: (adf pos0)
    175 		 * 7 6 5 4 3 2 1 0
    176 		 * \_____/ \___/  \__ enable: 0=disabled, 1=enabled
    177 		 *       \     \_____ I/O Address (see ioaddr table)
    178 		 *        \__________ IRQ (see irq table)
    179 		 *
    180 		 * POS register 3: (adf pos1) ignored
    181 		 * 7 6 5 4 3 2 1 0
    182 		 * X X X X \____/
    183 		 *              \____EPROM Address (0000 = not used)
    184 		 */
    185 		iobase = smc_iobase[((pos2 & 0x0e) >> 1)];
    186 		if ((pos2 & 0x80) != 0)
    187 			irq = smc_irq[((pos2 & 0x70) >> 4)];
    188 		else {
    189 			aprint_error_dev(self, "unsupported irq selected\n");
    190 			return;
    191 		}
    192 
    193 		/* XXX SWAG for number pkts. */
    194 		/* The SMC3016 has a 12K rx buffer and a 4k tx buffer */
    195 		sc->txb_num_pkt = 2;
    196 		sc->rxb_num_pkt = (12288 - 4) / 64;
    197 		/* XXX                       */
    198 
    199 		break;
    200 	}
    201 
    202 
    203 #ifdef DIAGNOSTIC
    204 	tra_p = tiara_mca_lookup(ma->ma_id);
    205 	if (tra_p == NULL) {
    206 		aprint_normal("\n");
    207 		aprint_error_dev(self, "where did the card go?\n");
    208 		return;
    209 	}
    210 #endif
    211 
    212 	printf(" slot %d ports %#x-%#x irq %d: %s\n", ma->ma_slot + 1,iobase, iobase + TIARA_NPORTS, irq, tra_p->tra_name);
    213 
    214 	/* Map i/o space. */
    215 	if (bus_space_map(iot, iobase, TIARA_NPORTS, 0, &ioh)) {
    216 		aprint_error_dev(self, "can't map i/o space\n");
    217 		return;
    218 	}
    219 
    220 	sc->sc_dev = self;
    221 	sc->sc_bst = iot;
    222 	sc->sc_bsh = ioh;
    223 
    224 	/* Get ethernet address from PROM */
    225 	bus_space_read_region_1(iot, ioh, TIARA_PROM_ID, myea, ETHER_ADDR_LEN);
    226 
    227 	/* This interface is always enabled. */
    228 	/* XXX
    229 	sc->sc_stat |= NIC_STAT_ENABLED;
    230 	*/
    231 
    232 	/*
    233 	 * Do generic MB86950 attach.
    234 	 */
    235 	mb86950_attach(sc, myea);
    236 
    237 
    238 	mb86950_config(sc, NULL, 0, 0);
    239 
    240 	/* Establish the interrupt handler. */
    241 	isc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET,
    242 			mb86950_intr, sc);
    243 	if (isc->sc_ih == NULL) {
    244 		aprint_error_dev(self, "couldn't establish interrupt handler\n");
    245 		return;
    246 	}
    247 }
    248