Home | History | Annotate | Line # | Download | only in eisa
if_ep_eisa.c revision 1.39.4.1
      1 /*	$NetBSD: if_ep_eisa.c,v 1.39.4.1 2009/02/02 20:48:00 snj Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  * NASA Ames Research Center.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  * POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 /*
     34  * Copyright (c) 1997 Jonathan Stone <jonathan (at) NetBSD.org>
     35  * Copyright (c) 1994 Herb Peyerl <hpeyerl (at) beer.org>
     36  * All rights reserved.
     37  *
     38  * Redistribution and use in source and binary forms, with or without
     39  * modification, are permitted provided that the following conditions
     40  * are met:
     41  * 1. Redistributions of source code must retain the above copyright
     42  *    notice, this list of conditions and the following disclaimer.
     43  * 2. Redistributions in binary form must reproduce the above copyright
     44  *    notice, this list of conditions and the following disclaimer in the
     45  *    documentation and/or other materials provided with the distribution.
     46  * 3. All advertising materials mentioning features or use of this software
     47  *    must display the following acknowledgement:
     48  *      This product includes software developed by Herb Peyerl.
     49  *      This product includes software developed by Jonathan Stone.
     50  * 4. The name of Herb Peyerl or Jonathan Stone may not be used to endorse
     51  *    or promote products derived from this software without specific
     52  *    prior written permission.
     53  *
     54  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     55  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     56  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     57  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     58  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     59  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     60  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     61  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     62  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     63  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     64  */
     65 
     66 #include <sys/cdefs.h>
     67 __KERNEL_RCSID(0, "$NetBSD: if_ep_eisa.c,v 1.39.4.1 2009/02/02 20:48:00 snj Exp $");
     68 
     69 #include "opt_inet.h"
     70 #include "bpfilter.h"
     71 
     72 #include <sys/param.h>
     73 #include <sys/systm.h>
     74 #include <sys/mbuf.h>
     75 #include <sys/socket.h>
     76 #include <sys/ioctl.h>
     77 #include <sys/errno.h>
     78 #include <sys/syslog.h>
     79 #include <sys/select.h>
     80 #include <sys/device.h>
     81 
     82 #include <net/if.h>
     83 #include <net/if_dl.h>
     84 #include <net/if_ether.h>
     85 #include <net/if_media.h>
     86 
     87 #ifdef INET
     88 #include <netinet/in.h>
     89 #include <netinet/in_systm.h>
     90 #include <netinet/in_var.h>
     91 #include <netinet/ip.h>
     92 #include <netinet/if_inarp.h>
     93 #endif
     94 
     95 
     96 #if NBPFILTER > 0
     97 #include <net/bpf.h>
     98 #include <net/bpfdesc.h>
     99 #endif
    100 
    101 #include <sys/cpu.h>
    102 #include <sys/bus.h>
    103 #include <sys/intr.h>
    104 
    105 #include <dev/mii/miivar.h>
    106 
    107 #include <dev/ic/elink3var.h>
    108 #include <dev/ic/elink3reg.h>
    109 
    110 #include <dev/eisa/eisareg.h>
    111 #include <dev/eisa/eisavar.h>
    112 #include <dev/eisa/eisadevs.h>
    113 
    114 static int	ep_eisa_match(device_t , cfdata_t , void *);
    115 static void	ep_eisa_attach(device_t , device_t , void *);
    116 
    117 CFATTACH_DECL_NEW(ep_eisa, sizeof(struct ep_softc),
    118     ep_eisa_match, ep_eisa_attach, NULL, NULL);
    119 
    120 /* XXX move these somewhere else */
    121 /* While attaching we need a few special EISA registers of the card,
    122    these are mapped at slotbase+EP_EISA_CFG_BASE with len EP_EISA_CFG_SIZE */
    123 #define EP_EISA_CFG_BASE	0x0c80
    124 #define	EP_EISA_CFG_CONTROL	0x0004	/* 1 byte */
    125 #define	EP_EISA_CFG_RESOURCE	0x0008	/* 2 byte */
    126 #define	EP_EISA_CFG_SIZE	0x000a
    127 
    128 /* The generic driver backend only needs access to the standard ports,
    129    mapped at the beginning of the eisa slot space */
    130 #define	EP_IOPORT_OFFSET	0x0000
    131 #define	EP_IOPORT_SIZE		0x0020
    132 
    133 /* Bits for the eisa control register */
    134 #define EISA_RESET	0x04
    135 #define EISA_ERROR	0x02
    136 #define EISA_ENABLE	0x01
    137 
    138 static const struct ep_eisa_product {
    139 	const char	*eep_eisaid;	/* EISA ID */
    140 	u_short		eep_chipset;	/* 3Com chipset used */
    141 	int		eep_flags;	/* initial softc flags */
    142 	const char	*eep_name;	/* device name */
    143 } ep_eisa_products[] = {
    144 	{ "TCM5090",			ELINK_CHIPSET_3C509,
    145 	  0,				EISA_PRODUCT_TCM5090 },
    146 	{ "TCM5091",			ELINK_CHIPSET_3C509,
    147 	  0,				EISA_PRODUCT_TCM5091 },
    148 	{ "TCM5092",			ELINK_CHIPSET_3C509,
    149 	  0,				EISA_PRODUCT_TCM5092 },
    150 	{ "TCM5093",			ELINK_CHIPSET_3C509,
    151 	  0,				EISA_PRODUCT_TCM5093 },
    152 	{ "TCM5094",			ELINK_CHIPSET_3C509,
    153 	  0,				EISA_PRODUCT_TCM5094 },
    154 	{ "TCM5095",			ELINK_CHIPSET_3C509,
    155 	  0,				EISA_PRODUCT_TCM5095 },
    156 	{ "TCM5098",			ELINK_CHIPSET_3C509,
    157 	  0,				EISA_PRODUCT_TCM5098 },
    158 
    159 	/*
    160 	 * Note: The 3c597 Fast Etherlink MII (TCM5972) is an
    161 	 * MII connector for an external PHY.  We treat it as
    162 	 * `manual' in the core driver.
    163 	 */
    164 	{ "TCM5920",			ELINK_CHIPSET_VORTEX,
    165 	  0,				EISA_PRODUCT_TCM5920 },
    166 	{ "TCM5970",			ELINK_CHIPSET_VORTEX,
    167 	  0,				EISA_PRODUCT_TCM5970 },
    168 	{ "TCM5971",			ELINK_CHIPSET_VORTEX,
    169 	  0,				EISA_PRODUCT_TCM5971 },
    170 	{ "TCM5972",			ELINK_CHIPSET_VORTEX,
    171 	  0,				EISA_PRODUCT_TCM5972 },
    172 
    173 	{ NULL,				0,
    174 	  0,				NULL },
    175 };
    176 
    177 static const struct ep_eisa_product *
    178 ep_eisa_lookup(const struct eisa_attach_args *ea)
    179 {
    180 	const struct ep_eisa_product *eep;
    181 
    182 	for (eep = ep_eisa_products; eep->eep_name != NULL; eep++)
    183 		if (strcmp(ea->ea_idstring, eep->eep_eisaid) == 0)
    184 			return (eep);
    185 
    186 	return (NULL);
    187 }
    188 
    189 static int
    190 ep_eisa_match(device_t parent, cfdata_t match, void *aux)
    191 {
    192 	struct eisa_attach_args *ea = aux;
    193 
    194 	/* must match one of our known ID strings */
    195 	if (ep_eisa_lookup(ea) != NULL)
    196 		return (1);
    197 
    198 	return (0);
    199 }
    200 
    201 static void
    202 ep_eisa_attach(device_t parent, device_t self, void *aux)
    203 {
    204 	struct ep_softc *sc = device_private(self);
    205 	struct eisa_attach_args *ea = aux;
    206 	bus_space_tag_t iot = ea->ea_iot;
    207 	bus_space_handle_t ioh, ioh_cfg;
    208 	eisa_chipset_tag_t ec = ea->ea_ec;
    209 	eisa_intr_handle_t ih;
    210 	const char *intrstr;
    211 	const struct ep_eisa_product *eep;
    212 	u_int irq;
    213 
    214 	/* Map i/o space. */
    215 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) + EP_EISA_CFG_BASE,
    216 	    EP_EISA_CFG_SIZE, 0, &ioh_cfg)) {
    217 		printf("\n");
    218 		panic("ep_eisa_attach: can't map eisa cfg i/o space");
    219 	}
    220 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) + EP_IOPORT_OFFSET,
    221 	    EP_IOPORT_SIZE, 0, &ioh)) {
    222 		printf("\n");
    223 		panic("ep_eisa_attach: can't map i/o space");
    224 	}
    225 
    226 	sc->sc_dev = self;
    227 	sc->sc_ioh = ioh;
    228 	sc->sc_iot = iot;
    229 
    230 	bus_space_write_1(iot, ioh_cfg, EP_EISA_CFG_CONTROL, EISA_ENABLE);
    231 	delay(4000);
    232 
    233 	/* Read the IRQ from the card. */
    234 	irq = bus_space_read_2(iot, ioh_cfg, EP_EISA_CFG_RESOURCE) >> 12;
    235 
    236 	eep = ep_eisa_lookup(ea);
    237 	if (eep == NULL) {
    238 		printf("\n");
    239 		panic("ep_eisa_attach: impossible");
    240 	}
    241 
    242 	/* we don't need access to the config registers any more, but
    243 	   noone else should be able to map this space, so keep it
    244 	   reserved? */
    245 #if 0
    246 	bus_space_unmap(iot, ioh_cfg, EP_EISA_CFG_SIZE);
    247 #endif
    248 
    249 	printf(": %s\n", eep->eep_name);
    250 
    251 	sc->enable = NULL;
    252 	sc->disable = NULL;
    253 	sc->enabled = 1;
    254 
    255 	sc->bustype = ELINK_BUS_EISA;
    256 	sc->ep_flags = eep->eep_flags;
    257 
    258 	if (eisa_intr_map(ec, irq, &ih)) {
    259 		aprint_error_dev(sc->sc_dev, "couldn't map interrupt (%u)\n",
    260 		    irq);
    261 		return;
    262 	}
    263 	intrstr = eisa_intr_string(ec, ih);
    264 	sc->sc_ih = eisa_intr_establish(ec, ih, IST_EDGE, IPL_NET,
    265 	    epintr, sc);
    266 	if (sc->sc_ih == NULL) {
    267 		aprint_error_dev(sc->sc_dev, "couldn't establish interrupt");
    268 		if (intrstr != NULL)
    269 			printf(" at %s", intrstr);
    270 		printf("\n");
    271 		return;
    272 	}
    273 	if (intrstr != NULL)
    274 		printf("%s: interrupting at %s\n", device_xname(sc->sc_dev),
    275 		    intrstr);
    276 
    277 	epconfig(sc, eep->eep_chipset, NULL);
    278 }
    279