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