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