Home | History | Annotate | Line # | Download | only in isa
if_ep_isa.c revision 1.16
      1  1.16   thorpej /*	$NetBSD: if_ep_isa.c,v 1.16 1997/10/05 18:37:02 thorpej Exp $	*/
      2  1.16   thorpej 
      3  1.16   thorpej /*-
      4  1.16   thorpej  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
      5  1.16   thorpej  * All rights reserved.
      6  1.16   thorpej  *
      7  1.16   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.16   thorpej  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  1.16   thorpej  * NASA Ames Research Center.
     10  1.16   thorpej  *
     11  1.16   thorpej  * Redistribution and use in source and binary forms, with or without
     12  1.16   thorpej  * modification, are permitted provided that the following conditions
     13  1.16   thorpej  * are met:
     14  1.16   thorpej  * 1. Redistributions of source code must retain the above copyright
     15  1.16   thorpej  *    notice, this list of conditions and the following disclaimer.
     16  1.16   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.16   thorpej  *    notice, this list of conditions and the following disclaimer in the
     18  1.16   thorpej  *    documentation and/or other materials provided with the distribution.
     19  1.16   thorpej  * 3. All advertising materials mentioning features or use of this software
     20  1.16   thorpej  *    must display the following acknowledgement:
     21  1.16   thorpej  *	This product includes software developed by the NetBSD
     22  1.16   thorpej  *	Foundation, Inc. and its contributors.
     23  1.16   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.16   thorpej  *    contributors may be used to endorse or promote products derived
     25  1.16   thorpej  *    from this software without specific prior written permission.
     26  1.16   thorpej  *
     27  1.16   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.16   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.16   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.16   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.16   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.16   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.16   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.16   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.16   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.16   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.16   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     38  1.16   thorpej  */
     39   1.1   thorpej 
     40   1.1   thorpej /*
     41  1.11  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.1   thorpej #include "bpfilter.h"
     72   1.1   thorpej 
     73   1.1   thorpej #include <sys/param.h>
     74   1.3  christos #include <sys/systm.h>
     75   1.1   thorpej #include <sys/mbuf.h>
     76   1.1   thorpej #include <sys/socket.h>
     77   1.1   thorpej #include <sys/ioctl.h>
     78   1.1   thorpej #include <sys/errno.h>
     79   1.1   thorpej #include <sys/syslog.h>
     80   1.1   thorpej #include <sys/select.h>
     81   1.1   thorpej #include <sys/device.h>
     82   1.2   thorpej #include <sys/queue.h>
     83   1.1   thorpej 
     84   1.1   thorpej #include <net/if.h>
     85   1.1   thorpej #include <net/if_dl.h>
     86  1.11  jonathan #include <net/if_ether.h>
     87  1.11  jonathan #include <net/if_media.h>
     88  1.10        is 
     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.10        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.1   thorpej #include <dev/ic/elink3var.h>
    113   1.1   thorpej #include <dev/ic/elink3reg.h>
    114   1.1   thorpej 
    115   1.1   thorpej #include <dev/isa/isavar.h>
    116   1.1   thorpej #include <dev/isa/elink.h>
    117   1.1   thorpej 
    118  1.12       cgd #ifdef __BROKEN_INDIRECT_CONFIG
    119   1.1   thorpej int ep_isa_probe __P((struct device *, void *, void *));
    120  1.12       cgd #else
    121  1.12       cgd int ep_isa_probe __P((struct device *, struct cfdata *, void *));
    122  1.12       cgd #endif
    123   1.1   thorpej void ep_isa_attach __P((struct device *, struct device *, void *));
    124   1.1   thorpej 
    125   1.1   thorpej struct cfattach ep_isa_ca = {
    126   1.1   thorpej 	sizeof(struct ep_softc), ep_isa_probe, ep_isa_attach
    127   1.1   thorpej };
    128   1.1   thorpej 
    129  1.13     veego static	void epaddcard __P((int, int, int, int));
    130   1.1   thorpej 
    131   1.2   thorpej /*
    132   1.2   thorpej  * This keeps track of which ISAs have been through an ep probe sequence.
    133   1.2   thorpej  * A simple static variable isn't enough, since it's conceivable that
    134   1.2   thorpej  * a system might have more than one ISA bus.
    135   1.2   thorpej  *
    136   1.2   thorpej  * The "er_bus" member is the unit number of the parent ISA bus, e.g. "0"
    137   1.2   thorpej  * for "isa0".
    138   1.2   thorpej  */
    139   1.2   thorpej struct ep_isa_done_probe {
    140   1.2   thorpej 	LIST_ENTRY(ep_isa_done_probe)	er_link;
    141   1.2   thorpej 	int				er_bus;
    142   1.2   thorpej };
    143   1.2   thorpej static LIST_HEAD(, ep_isa_done_probe) ep_isa_all_probes;
    144   1.2   thorpej static int ep_isa_probes_initialized;
    145   1.2   thorpej 
    146   1.2   thorpej #define MAXEPCARDS	20	/* if you have more than 20, you lose */
    147   1.1   thorpej 
    148   1.1   thorpej static struct epcard {
    149   1.2   thorpej 	int	bus;
    150   1.1   thorpej 	int	iobase;
    151   1.1   thorpej 	int	irq;
    152   1.1   thorpej 	char	available;
    153  1.14    mjacob 	long	model;
    154   1.1   thorpej } epcards[MAXEPCARDS];
    155   1.1   thorpej static int nepcards;
    156   1.1   thorpej 
    157   1.1   thorpej static void
    158  1.13     veego epaddcard(bus, iobase, irq, model)
    159  1.13     veego 	int bus, iobase, irq, model;
    160   1.1   thorpej {
    161   1.1   thorpej 
    162   1.1   thorpej 	if (nepcards >= MAXEPCARDS)
    163   1.1   thorpej 		return;
    164   1.2   thorpej 	epcards[nepcards].bus = bus;
    165   1.1   thorpej 	epcards[nepcards].iobase = iobase;
    166   1.1   thorpej 	epcards[nepcards].irq = (irq == 2) ? 9 : irq;
    167  1.13     veego 	epcards[nepcards].model = model;
    168   1.1   thorpej 	epcards[nepcards].available = 1;
    169   1.1   thorpej 	nepcards++;
    170   1.1   thorpej }
    171   1.1   thorpej 
    172   1.1   thorpej /*
    173   1.1   thorpej  * 3c509 cards on the ISA bus are probed in ethernet address order.
    174   1.1   thorpej  * The probe sequence requires careful orchestration, and we'd like
    175   1.1   thorpej  * like to allow the irq and base address to be wildcarded. So, we
    176   1.1   thorpej  * probe all the cards the first time epprobe() is called. On subsequent
    177   1.1   thorpej  * calls we look for matching cards.
    178   1.1   thorpej  */
    179   1.1   thorpej int
    180   1.1   thorpej ep_isa_probe(parent, match, aux)
    181   1.1   thorpej 	struct device *parent;
    182  1.12       cgd #ifdef __BROKEN_INDIRECT_CONFIG
    183  1.12       cgd 	void *match;
    184  1.12       cgd #else
    185  1.12       cgd 	struct cfdata *match;
    186  1.12       cgd #endif
    187  1.12       cgd 	void *aux;
    188   1.1   thorpej {
    189   1.1   thorpej 	struct isa_attach_args *ia = aux;
    190   1.8   thorpej 	bus_space_tag_t iot = ia->ia_iot;
    191  1.15       cjs 	bus_space_handle_t ioh, ioh2;
    192   1.1   thorpej 	int slot, iobase, irq, i;
    193   1.2   thorpej 	u_int16_t vendor, model;
    194   1.2   thorpej 	struct ep_isa_done_probe *er;
    195   1.2   thorpej 	int bus = parent->dv_unit;
    196   1.2   thorpej 
    197   1.2   thorpej 	if (ep_isa_probes_initialized == 0) {
    198   1.2   thorpej 		LIST_INIT(&ep_isa_all_probes);
    199   1.2   thorpej 		ep_isa_probes_initialized = 1;
    200   1.2   thorpej 	}
    201   1.2   thorpej 
    202   1.2   thorpej 	/*
    203   1.2   thorpej 	 * Probe this bus if we haven't done so already.
    204   1.2   thorpej 	 */
    205   1.2   thorpej 	for (er = ep_isa_all_probes.lh_first; er != NULL;
    206   1.2   thorpej 	    er = er->er_link.le_next)
    207   1.2   thorpej 		if (er->er_bus == parent->dv_unit)
    208   1.2   thorpej 			goto bus_probed;
    209   1.2   thorpej 
    210   1.2   thorpej 	/*
    211   1.2   thorpej 	 * Mark this bus so we don't probe it again.
    212   1.2   thorpej 	 */
    213   1.2   thorpej 	er = (struct ep_isa_done_probe *)
    214   1.2   thorpej 	    malloc(sizeof(struct ep_isa_done_probe), M_DEVBUF, M_NOWAIT);
    215   1.2   thorpej 	if (er == NULL)
    216   1.2   thorpej 		panic("ep_isa_probe: can't allocate state storage");
    217   1.2   thorpej 
    218   1.2   thorpej 	er->er_bus = bus;
    219   1.2   thorpej 	LIST_INSERT_HEAD(&ep_isa_all_probes, er, er_link);
    220   1.2   thorpej 
    221   1.2   thorpej 	/*
    222   1.2   thorpej 	 * Map the Etherlink ID port for the probe sequence.
    223   1.2   thorpej 	 */
    224   1.8   thorpej 	if (bus_space_map(iot, ELINK_ID_PORT, 1, 0, &ioh)) {
    225   1.7  christos 		printf("ep_isa_probe: can't map Etherlink ID port\n");
    226   1.3  christos 		return 0;
    227   1.2   thorpej 	}
    228   1.2   thorpej 
    229   1.2   thorpej 	for (slot = 0; slot < MAXEPCARDS; slot++) {
    230   1.8   thorpej 		elink_reset(iot, ioh, parent->dv_unit);
    231   1.8   thorpej 		elink_idseq(iot, ioh, ELINK_509_POLY);
    232   1.2   thorpej 
    233   1.2   thorpej 		/* Untag all the adapters so they will talk to us. */
    234   1.2   thorpej 		if (slot == 0)
    235   1.8   thorpej 			bus_space_write_1(iot, ioh, 0, TAG_ADAPTER + 0);
    236   1.1   thorpej 
    237   1.8   thorpej 		vendor = htons(epreadeeprom(iot, ioh, EEPROM_MFG_ID));
    238   1.2   thorpej 		if (vendor != MFG_ID)
    239   1.2   thorpej 			continue;
    240   1.1   thorpej 
    241   1.8   thorpej 		model = htons(epreadeeprom(iot, ioh, EEPROM_PROD_ID));
    242  1.13     veego 		/*
    243  1.13     veego 		 * XXX: Add a new product id to check for other cards
    244  1.13     veego 		 * (3c515?) and fix the check in ep_isa_attach.
    245  1.13     veego 		 */
    246  1.13     veego 		if ((model & 0xfff0) != PROD_ID_3C509) {
    247   1.1   thorpej #ifndef trusted
    248   1.7  christos 			printf(
    249   1.2   thorpej 			 "ep_isa_probe: ignoring model %04x\n", model);
    250   1.1   thorpej #endif
    251   1.2   thorpej 			continue;
    252   1.1   thorpej 			}
    253   1.1   thorpej 
    254   1.8   thorpej 		iobase = epreadeeprom(iot, ioh, EEPROM_ADDR_CFG);
    255   1.2   thorpej 		iobase = (iobase & 0x1f) * 0x10 + 0x200;
    256   1.1   thorpej 
    257   1.8   thorpej 		irq = epreadeeprom(iot, ioh, EEPROM_RESOURCE_CFG);
    258   1.2   thorpej 		irq >>= 12;
    259   1.2   thorpej 
    260   1.2   thorpej 		/* so card will not respond to contention again */
    261   1.8   thorpej 		bus_space_write_1(iot, ioh, 0, TAG_ADAPTER + 1);
    262   1.2   thorpej 
    263   1.2   thorpej 		/*
    264   1.2   thorpej 		 * XXX: this should probably not be done here
    265   1.2   thorpej 		 * because it enables the drq/irq lines from
    266   1.2   thorpej 		 * the board. Perhaps it should be done after
    267   1.2   thorpej 		 * we have checked for irq/drq collisions?
    268   1.2   thorpej 		 */
    269   1.8   thorpej 		bus_space_write_1(iot, ioh, 0, ACTIVATE_ADAPTER_TO_CONFIG);
    270  1.13     veego 
    271  1.13     veego 		/*
    272  1.13     veego 		 * Don't attach a 3c509 in PnP mode.
    273  1.13     veego 		 */
    274  1.13     veego 		if ((model & 0xfff0) == PROD_ID_3C509) {
    275  1.15       cjs 			if (bus_space_map(iot, iobase, 1, 0, &ioh2)) {
    276  1.15       cjs 				printf(
    277  1.15       cjs 				"ep_isa_probe: can't map Etherlink iobase\n");
    278  1.15       cjs 				return 0;
    279  1.15       cjs 			}
    280  1.15       cjs 			if (bus_space_read_2(iot, ioh2, EP_W0_EEPROM_COMMAND)
    281  1.13     veego 			    & EEPROM_TST_MODE) {
    282  1.13     veego 				printf(
    283  1.13     veego 				 "3COM 3C509 Ethernet card in PnP mode\n");
    284  1.13     veego 				continue;
    285  1.13     veego 			}
    286  1.15       cjs 			bus_space_unmap(iot, ioh2, 1);
    287  1.13     veego 		}
    288  1.13     veego 		epaddcard(bus, iobase, irq, model);
    289   1.1   thorpej 	}
    290   1.2   thorpej 	/* XXX should we sort by ethernet address? */
    291   1.2   thorpej 
    292   1.8   thorpej 	bus_space_unmap(iot, ioh, 1);
    293   1.2   thorpej 
    294  1.13     veego bus_probed:
    295   1.1   thorpej 
    296   1.1   thorpej 	for (i = 0; i < nepcards; i++) {
    297   1.2   thorpej 		if (epcards[i].bus != bus)
    298   1.2   thorpej 			continue;
    299   1.1   thorpej 		if (epcards[i].available == 0)
    300   1.1   thorpej 			continue;
    301   1.1   thorpej 		if (ia->ia_iobase != IOBASEUNK &&
    302   1.1   thorpej 		    ia->ia_iobase != epcards[i].iobase)
    303   1.1   thorpej 			continue;
    304   1.1   thorpej 		if (ia->ia_irq != IRQUNK &&
    305   1.1   thorpej 		    ia->ia_irq != epcards[i].irq)
    306   1.1   thorpej 			continue;
    307   1.1   thorpej 		goto good;
    308   1.1   thorpej 	}
    309   1.1   thorpej 	return 0;
    310   1.1   thorpej 
    311   1.1   thorpej good:
    312   1.1   thorpej 	epcards[i].available = 0;
    313   1.1   thorpej 	ia->ia_iobase = epcards[i].iobase;
    314   1.1   thorpej 	ia->ia_irq = epcards[i].irq;
    315   1.1   thorpej 	ia->ia_iosize = 0x10;
    316   1.1   thorpej 	ia->ia_msize = 0;
    317  1.13     veego 	ia->ia_aux = (void *)epcards[i].model;
    318   1.1   thorpej 	return 1;
    319   1.1   thorpej }
    320   1.1   thorpej 
    321   1.1   thorpej void
    322   1.1   thorpej ep_isa_attach(parent, self, aux)
    323   1.1   thorpej 	struct device *parent, *self;
    324   1.1   thorpej 	void *aux;
    325   1.1   thorpej {
    326   1.1   thorpej 	struct ep_softc *sc = (void *)self;
    327   1.1   thorpej 	struct isa_attach_args *ia = aux;
    328   1.8   thorpej 	bus_space_tag_t iot = ia->ia_iot;
    329   1.8   thorpej 	bus_space_handle_t ioh;
    330  1.13     veego 	int chipset;
    331   1.1   thorpej 
    332   1.2   thorpej 	/* Map i/o space. */
    333   1.8   thorpej 	if (bus_space_map(iot, ia->ia_iobase, ia->ia_iosize, 0, &ioh))
    334   1.2   thorpej 		panic("ep_isa_attach: can't map i/o space");
    335   1.2   thorpej 
    336   1.8   thorpej 	sc->sc_iot = iot;
    337   1.2   thorpej 	sc->sc_ioh = ioh;
    338   1.1   thorpej 	sc->bustype = EP_BUS_ISA;
    339   1.1   thorpej 
    340  1.14    mjacob 	chipset = (int)(long)ia->ia_aux;
    341  1.13     veego 	if ((chipset & 0xfff0) == PROD_ID_3C509) {
    342  1.13     veego 		printf(": 3Com 3C509 Ethernet\n");
    343  1.13     veego 		epconfig(sc, EP_CHIPSET_3C509);
    344  1.13     veego 	} else {
    345  1.13     veego 		/*
    346  1.13     veego 		 * XXX: Maybe a 3c515, but the check in ep_isa_probe looks
    347  1.13     veego 		 * at the moment only for a 3c509.
    348  1.13     veego 		 */
    349  1.13     veego 		printf(": unknown 3Com Ethernet card: %04x\n", chipset);
    350  1.13     veego 		epconfig(sc, EP_CHIPSET_UNKNOWN);
    351  1.13     veego 	}
    352   1.1   thorpej 
    353   1.1   thorpej 	sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
    354   1.1   thorpej 	    IPL_NET, epintr, sc);
    355   1.1   thorpej }
    356