Home | History | Annotate | Line # | Download | only in eisa
if_ep_eisa.c revision 1.19.6.1
      1  1.19.6.1        he /*	$NetBSD: if_ep_eisa.c,v 1.19.6.1 1999/08/22 17:07:16 he 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.1   thorpej  * 4. The name of Herb Peyerl may not be used to endorse or promote products
     57       1.1   thorpej  *    derived from this software without specific prior written permission.
     58       1.1   thorpej  *
     59       1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     60       1.1   thorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     61       1.1   thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     62       1.1   thorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     63       1.1   thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     64       1.1   thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     65       1.1   thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     66       1.1   thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     67       1.1   thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     68       1.1   thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     69       1.1   thorpej  */
     70       1.1   thorpej 
     71      1.16  jonathan #include "opt_inet.h"
     72      1.17  jonathan #include "opt_ns.h"
     73       1.1   thorpej #include "bpfilter.h"
     74       1.1   thorpej 
     75       1.1   thorpej #include <sys/param.h>
     76       1.3  christos #include <sys/systm.h>
     77       1.1   thorpej #include <sys/mbuf.h>
     78       1.1   thorpej #include <sys/socket.h>
     79       1.1   thorpej #include <sys/ioctl.h>
     80       1.1   thorpej #include <sys/errno.h>
     81       1.1   thorpej #include <sys/syslog.h>
     82       1.1   thorpej #include <sys/select.h>
     83       1.1   thorpej #include <sys/device.h>
     84       1.1   thorpej 
     85       1.1   thorpej #include <net/if.h>
     86       1.1   thorpej #include <net/if_dl.h>
     87      1.11        is #include <net/if_ether.h>
     88      1.12  jonathan #include <net/if_media.h>
     89       1.1   thorpej 
     90       1.1   thorpej #ifdef INET
     91       1.1   thorpej #include <netinet/in.h>
     92       1.1   thorpej #include <netinet/in_systm.h>
     93       1.1   thorpej #include <netinet/in_var.h>
     94       1.1   thorpej #include <netinet/ip.h>
     95      1.11        is #include <netinet/if_inarp.h>
     96       1.1   thorpej #endif
     97       1.1   thorpej 
     98       1.1   thorpej #ifdef NS
     99       1.1   thorpej #include <netns/ns.h>
    100       1.1   thorpej #include <netns/ns_if.h>
    101       1.1   thorpej #endif
    102       1.1   thorpej 
    103       1.1   thorpej #if NBPFILTER > 0
    104       1.1   thorpej #include <net/bpf.h>
    105       1.1   thorpej #include <net/bpfdesc.h>
    106       1.1   thorpej #endif
    107       1.1   thorpej 
    108       1.1   thorpej #include <machine/cpu.h>
    109       1.2   thorpej #include <machine/bus.h>
    110       1.5   mycroft #include <machine/intr.h>
    111       1.1   thorpej 
    112      1.18   thorpej #include <dev/mii/miivar.h>
    113      1.18   thorpej 
    114       1.1   thorpej #include <dev/ic/elink3var.h>
    115       1.1   thorpej #include <dev/ic/elink3reg.h>
    116       1.1   thorpej 
    117       1.1   thorpej #include <dev/eisa/eisareg.h>
    118       1.1   thorpej #include <dev/eisa/eisavar.h>
    119       1.1   thorpej #include <dev/eisa/eisadevs.h>
    120       1.1   thorpej 
    121      1.13       cgd int ep_eisa_match __P((struct device *, struct cfdata *, void *));
    122       1.1   thorpej void ep_eisa_attach __P((struct device *, struct device *, void *));
    123       1.1   thorpej 
    124       1.1   thorpej struct cfattach ep_eisa_ca = {
    125       1.1   thorpej 	sizeof(struct ep_softc), ep_eisa_match, ep_eisa_attach
    126       1.1   thorpej };
    127       1.1   thorpej 
    128       1.1   thorpej /* XXX move these somewhere else */
    129       1.1   thorpej #define EISA_CONTROL	0x0c84
    130       1.1   thorpej #define EISA_RESET	0x04
    131       1.1   thorpej #define EISA_ERROR	0x02
    132       1.1   thorpej #define EISA_ENABLE	0x01
    133       1.1   thorpej 
    134      1.18   thorpej struct ep_eisa_product {
    135      1.18   thorpej 	const char	*eep_eisaid;	/* EISA ID */
    136      1.18   thorpej 	u_short		eep_chipset;	/* 3Com chipset used */
    137      1.18   thorpej 	int		eep_flags;	/* initial softc flags */
    138      1.18   thorpej 	const char	*eep_name;	/* device name */
    139      1.18   thorpej } ep_eisa_products[] = {
    140      1.19      fvdl 	{ "TCM5091",			ELINK_CHIPSET_3C509,
    141      1.18   thorpej 	  0,				EISA_PRODUCT_TCM5091 },
    142      1.18   thorpej 
    143      1.19      fvdl 	{ "TCM5092",			ELINK_CHIPSET_3C509,
    144      1.18   thorpej 	  0,				EISA_PRODUCT_TCM5092 },
    145      1.19      fvdl 	{ "TCM5093",			ELINK_CHIPSET_3C509,
    146      1.18   thorpej 	  0,				EISA_PRODUCT_TCM5093 },
    147  1.19.6.1        he 	{ "TCM5094",			ELINK_CHIPSET_3C509,
    148  1.19.6.1        he 	  0,				EISA_PRODUCT_TCM5094 },
    149      1.18   thorpej 
    150      1.18   thorpej 	/*
    151      1.18   thorpej 	 * Note: The 3c597 Fast Etherlink MII (TCM5972) is an
    152      1.18   thorpej 	 * MII connector for an external PHY.  We treat it as
    153      1.18   thorpej 	 * `manual' in the core driver.
    154      1.18   thorpej 	 */
    155      1.19      fvdl 	{ "TCM5920",			ELINK_CHIPSET_VORTEX,
    156      1.18   thorpej 	  0,				EISA_PRODUCT_TCM5920 },
    157      1.19      fvdl 	{ "TCM5970",			ELINK_CHIPSET_VORTEX,
    158      1.18   thorpej 	  0,				EISA_PRODUCT_TCM5970 },
    159      1.19      fvdl 	{ "TCM5971",			ELINK_CHIPSET_VORTEX,
    160      1.18   thorpej 	  0,				EISA_PRODUCT_TCM5971 },
    161      1.19      fvdl 	{ "TCM5972",			ELINK_CHIPSET_VORTEX,
    162      1.18   thorpej 	  0,				EISA_PRODUCT_TCM5972 },
    163      1.18   thorpej 
    164      1.18   thorpej 	{ NULL,				0,
    165      1.18   thorpej 	  0,				NULL },
    166      1.18   thorpej };
    167      1.18   thorpej 
    168      1.18   thorpej struct ep_eisa_product *ep_eisa_lookup __P((struct eisa_attach_args *));
    169      1.18   thorpej 
    170      1.18   thorpej struct ep_eisa_product *
    171      1.18   thorpej ep_eisa_lookup(ea)
    172      1.18   thorpej 	struct eisa_attach_args *ea;
    173      1.18   thorpej {
    174      1.18   thorpej 	struct ep_eisa_product *eep;
    175      1.18   thorpej 
    176      1.18   thorpej 	for (eep = ep_eisa_products; eep->eep_name != NULL; eep++)
    177      1.18   thorpej 		if (strcmp(ea->ea_idstring, eep->eep_eisaid) == 0)
    178      1.18   thorpej 			return (eep);
    179      1.18   thorpej 
    180      1.18   thorpej 	return (NULL);
    181      1.18   thorpej }
    182      1.18   thorpej 
    183       1.1   thorpej int
    184       1.1   thorpej ep_eisa_match(parent, match, aux)
    185       1.1   thorpej 	struct device *parent;
    186      1.13       cgd 	struct cfdata *match;
    187      1.13       cgd 	void *aux;
    188       1.1   thorpej {
    189       1.1   thorpej 	struct eisa_attach_args *ea = aux;
    190       1.1   thorpej 
    191       1.1   thorpej 	/* must match one of our known ID strings */
    192      1.18   thorpej 	if (ep_eisa_lookup(ea) != NULL)
    193      1.18   thorpej 		return (1);
    194       1.1   thorpej 
    195      1.18   thorpej 	return (0);
    196       1.1   thorpej }
    197       1.1   thorpej 
    198       1.1   thorpej void
    199       1.1   thorpej ep_eisa_attach(parent, self, aux)
    200       1.1   thorpej 	struct device *parent, *self;
    201       1.1   thorpej 	void *aux;
    202       1.1   thorpej {
    203       1.1   thorpej 	struct ep_softc *sc = (void *)self;
    204       1.1   thorpej 	struct eisa_attach_args *ea = aux;
    205       1.9   thorpej 	bus_space_tag_t iot = ea->ea_iot;
    206       1.9   thorpej 	bus_space_handle_t ioh;
    207       1.1   thorpej 	eisa_chipset_tag_t ec = ea->ea_ec;
    208       1.1   thorpej 	eisa_intr_handle_t ih;
    209      1.18   thorpej 	const char *intrstr;
    210      1.18   thorpej 	struct ep_eisa_product *eep;
    211       1.6   thorpej 	u_int irq;
    212       1.1   thorpej 
    213       1.2   thorpej 	/* Map i/o space. */
    214       1.9   thorpej 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot),
    215      1.18   thorpej 	    EISA_SLOT_SIZE, 0, &ioh)) {
    216      1.18   thorpej 		printf("\n");
    217       1.2   thorpej 		panic("ep_eisa_attach: can't map i/o space");
    218      1.18   thorpej 	}
    219       1.2   thorpej 
    220       1.2   thorpej 	sc->sc_ioh = ioh;
    221       1.9   thorpej 	sc->sc_iot = iot;
    222       1.1   thorpej 
    223       1.1   thorpej 	/* Reset card. */
    224       1.9   thorpej 	bus_space_write_1(iot, ioh, EISA_CONTROL, EISA_ENABLE | EISA_RESET);
    225       1.1   thorpej 	delay(10);
    226       1.9   thorpej 	bus_space_write_1(iot, ioh, EISA_CONTROL, EISA_ENABLE);
    227       1.1   thorpej 	/* Wait for reset? */
    228       1.1   thorpej 	delay(1000);
    229       1.1   thorpej 
    230       1.1   thorpej 	/* Read the IRQ from the card. */
    231      1.19      fvdl 	irq = bus_space_read_2(iot, ioh, ELINK_W0_RESOURCE_CFG) >> 12;
    232       1.1   thorpej 
    233      1.18   thorpej 	eep = ep_eisa_lookup(ea);
    234      1.18   thorpej 	if (eep == NULL) {
    235      1.18   thorpej 		printf("\n");
    236      1.18   thorpej 		panic("ep_eisa_attach: impossible");
    237      1.10  jonathan 	}
    238      1.18   thorpej 
    239      1.18   thorpej 	printf(": 3Com %s\n", eep->eep_name);
    240      1.18   thorpej 
    241      1.18   thorpej 	sc->enable = NULL;
    242      1.18   thorpej 	sc->disable = NULL;
    243      1.18   thorpej 	sc->enabled = 1;
    244      1.18   thorpej 
    245      1.19      fvdl 	sc->bustype = ELINK_BUS_EISA;
    246      1.18   thorpej 	sc->ep_flags = eep->eep_flags;
    247       1.1   thorpej 
    248       1.1   thorpej 	if (eisa_intr_map(ec, irq, &ih)) {
    249       1.8  christos 		printf("%s: couldn't map interrupt (%u)\n",
    250       1.1   thorpej 		    sc->sc_dev.dv_xname, irq);
    251       1.1   thorpej 		return;
    252       1.1   thorpej 	}
    253       1.1   thorpej 	intrstr = eisa_intr_string(ec, ih);
    254       1.1   thorpej 	sc->sc_ih = eisa_intr_establish(ec, ih, IST_EDGE, IPL_NET,
    255       1.1   thorpej 	    epintr, sc);
    256       1.1   thorpej 	if (sc->sc_ih == NULL) {
    257       1.8  christos 		printf("%s: couldn't establish interrupt",
    258       1.1   thorpej 		    sc->sc_dev.dv_xname);
    259       1.1   thorpej 		if (intrstr != NULL)
    260       1.8  christos 			printf(" at %s", intrstr);
    261       1.8  christos 		printf("\n");
    262       1.1   thorpej 		return;
    263       1.1   thorpej 	}
    264       1.1   thorpej 	if (intrstr != NULL)
    265       1.8  christos 		printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname,
    266       1.1   thorpej 		    intrstr);
    267       1.1   thorpej 
    268      1.18   thorpej 	epconfig(sc, eep->eep_chipset, NULL);
    269       1.1   thorpej }
    270