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