Home | History | Annotate | Line # | Download | only in isa
if_ep_isa.c revision 1.12
      1  1.12       cgd /*	$NetBSD: if_ep_isa.c,v 1.12 1997/04/18 00:50:37 cgd Exp $	*/
      2   1.1   thorpej 
      3   1.1   thorpej /*
      4  1.11  jonathan  * Copyright (c) 1997 Jonathan Stone <jonathan (at) NetBSD.org>
      5   1.2   thorpej  * Copyright (c) 1996 Jason R. Thorpe <thorpej (at) beer.org>
      6   1.4   thorpej  * Copyright (c) 1994 Herb Peyerl <hpeyerl (at) beer.org>
      7   1.1   thorpej  * All rights reserved.
      8   1.1   thorpej  *
      9   1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     10   1.1   thorpej  * modification, are permitted provided that the following conditions
     11   1.1   thorpej  * are met:
     12   1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     13   1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     14   1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     16   1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     17   1.1   thorpej  * 3. All advertising materials mentioning features or use of this software
     18   1.1   thorpej  *    must display the following acknowledgement:
     19   1.1   thorpej  *      This product includes software developed by Herb Peyerl.
     20   1.1   thorpej  * 4. The name of Herb Peyerl may not be used to endorse or promote products
     21   1.1   thorpej  *    derived from this software without specific prior written permission.
     22   1.1   thorpej  *
     23   1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24   1.1   thorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25   1.1   thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26   1.1   thorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27   1.1   thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28   1.1   thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29   1.1   thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30   1.1   thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31   1.1   thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32   1.1   thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33   1.1   thorpej  */
     34   1.1   thorpej 
     35   1.1   thorpej #include "bpfilter.h"
     36   1.1   thorpej 
     37   1.1   thorpej #include <sys/param.h>
     38   1.3  christos #include <sys/systm.h>
     39   1.1   thorpej #include <sys/mbuf.h>
     40   1.1   thorpej #include <sys/socket.h>
     41   1.1   thorpej #include <sys/ioctl.h>
     42   1.1   thorpej #include <sys/errno.h>
     43   1.1   thorpej #include <sys/syslog.h>
     44   1.1   thorpej #include <sys/select.h>
     45   1.1   thorpej #include <sys/device.h>
     46   1.2   thorpej #include <sys/queue.h>
     47   1.1   thorpej 
     48   1.1   thorpej #include <net/if.h>
     49   1.1   thorpej #include <net/if_dl.h>
     50  1.11  jonathan #include <net/if_ether.h>
     51  1.11  jonathan #include <net/if_media.h>
     52  1.10        is 
     53   1.1   thorpej 
     54   1.1   thorpej #ifdef INET
     55   1.1   thorpej #include <netinet/in.h>
     56   1.1   thorpej #include <netinet/in_systm.h>
     57   1.1   thorpej #include <netinet/in_var.h>
     58   1.1   thorpej #include <netinet/ip.h>
     59  1.10        is #include <netinet/if_inarp.h>
     60   1.1   thorpej #endif
     61   1.1   thorpej 
     62   1.1   thorpej #ifdef NS
     63   1.1   thorpej #include <netns/ns.h>
     64   1.1   thorpej #include <netns/ns_if.h>
     65   1.1   thorpej #endif
     66   1.1   thorpej 
     67   1.1   thorpej #if NBPFILTER > 0
     68   1.1   thorpej #include <net/bpf.h>
     69   1.1   thorpej #include <net/bpfdesc.h>
     70   1.1   thorpej #endif
     71   1.1   thorpej 
     72   1.1   thorpej #include <machine/cpu.h>
     73   1.2   thorpej #include <machine/bus.h>
     74   1.5   mycroft #include <machine/intr.h>
     75   1.1   thorpej 
     76   1.1   thorpej #include <dev/ic/elink3var.h>
     77   1.1   thorpej #include <dev/ic/elink3reg.h>
     78   1.1   thorpej 
     79   1.1   thorpej #include <dev/isa/isavar.h>
     80   1.1   thorpej #include <dev/isa/elink.h>
     81   1.1   thorpej 
     82  1.12       cgd #ifdef __BROKEN_INDIRECT_CONFIG
     83   1.1   thorpej int ep_isa_probe __P((struct device *, void *, void *));
     84  1.12       cgd #else
     85  1.12       cgd int ep_isa_probe __P((struct device *, struct cfdata *, void *));
     86  1.12       cgd #endif
     87   1.1   thorpej void ep_isa_attach __P((struct device *, struct device *, void *));
     88   1.1   thorpej 
     89   1.1   thorpej struct cfattach ep_isa_ca = {
     90   1.1   thorpej 	sizeof(struct ep_softc), ep_isa_probe, ep_isa_attach
     91   1.1   thorpej };
     92   1.1   thorpej 
     93   1.2   thorpej static	void epaddcard __P((int, int, int));
     94   1.1   thorpej 
     95   1.2   thorpej /*
     96   1.2   thorpej  * This keeps track of which ISAs have been through an ep probe sequence.
     97   1.2   thorpej  * A simple static variable isn't enough, since it's conceivable that
     98   1.2   thorpej  * a system might have more than one ISA bus.
     99   1.2   thorpej  *
    100   1.2   thorpej  * The "er_bus" member is the unit number of the parent ISA bus, e.g. "0"
    101   1.2   thorpej  * for "isa0".
    102   1.2   thorpej  */
    103   1.2   thorpej struct ep_isa_done_probe {
    104   1.2   thorpej 	LIST_ENTRY(ep_isa_done_probe)	er_link;
    105   1.2   thorpej 	int				er_bus;
    106   1.2   thorpej };
    107   1.2   thorpej static LIST_HEAD(, ep_isa_done_probe) ep_isa_all_probes;
    108   1.2   thorpej static int ep_isa_probes_initialized;
    109   1.2   thorpej 
    110   1.2   thorpej #define MAXEPCARDS	20	/* if you have more than 20, you lose */
    111   1.1   thorpej 
    112   1.1   thorpej static struct epcard {
    113   1.2   thorpej 	int	bus;
    114   1.1   thorpej 	int	iobase;
    115   1.1   thorpej 	int	irq;
    116   1.1   thorpej 	char	available;
    117   1.1   thorpej } epcards[MAXEPCARDS];
    118   1.1   thorpej static int nepcards;
    119   1.1   thorpej 
    120   1.1   thorpej static void
    121   1.2   thorpej epaddcard(bus, iobase, irq)
    122   1.2   thorpej 	int bus, iobase, irq;
    123   1.1   thorpej {
    124   1.1   thorpej 
    125   1.1   thorpej 	if (nepcards >= MAXEPCARDS)
    126   1.1   thorpej 		return;
    127   1.2   thorpej 	epcards[nepcards].bus = bus;
    128   1.1   thorpej 	epcards[nepcards].iobase = iobase;
    129   1.1   thorpej 	epcards[nepcards].irq = (irq == 2) ? 9 : irq;
    130   1.1   thorpej 	epcards[nepcards].available = 1;
    131   1.1   thorpej 	nepcards++;
    132   1.1   thorpej }
    133   1.1   thorpej 
    134   1.1   thorpej /*
    135   1.1   thorpej  * 3c509 cards on the ISA bus are probed in ethernet address order.
    136   1.1   thorpej  * The probe sequence requires careful orchestration, and we'd like
    137   1.1   thorpej  * like to allow the irq and base address to be wildcarded. So, we
    138   1.1   thorpej  * probe all the cards the first time epprobe() is called. On subsequent
    139   1.1   thorpej  * calls we look for matching cards.
    140   1.1   thorpej  */
    141   1.1   thorpej int
    142   1.1   thorpej ep_isa_probe(parent, match, aux)
    143   1.1   thorpej 	struct device *parent;
    144  1.12       cgd #ifdef __BROKEN_INDIRECT_CONFIG
    145  1.12       cgd 	void *match;
    146  1.12       cgd #else
    147  1.12       cgd 	struct cfdata *match;
    148  1.12       cgd #endif
    149  1.12       cgd 	void *aux;
    150   1.1   thorpej {
    151   1.1   thorpej 	struct isa_attach_args *ia = aux;
    152   1.8   thorpej 	bus_space_tag_t iot = ia->ia_iot;
    153   1.8   thorpej 	bus_space_handle_t ioh;
    154   1.1   thorpej 	int slot, iobase, irq, i;
    155   1.2   thorpej 	u_int16_t vendor, model;
    156   1.2   thorpej 	struct ep_isa_done_probe *er;
    157   1.2   thorpej 	int bus = parent->dv_unit;
    158   1.2   thorpej 
    159   1.2   thorpej 	if (ep_isa_probes_initialized == 0) {
    160   1.2   thorpej 		LIST_INIT(&ep_isa_all_probes);
    161   1.2   thorpej 		ep_isa_probes_initialized = 1;
    162   1.2   thorpej 	}
    163   1.2   thorpej 
    164   1.2   thorpej 	/*
    165   1.2   thorpej 	 * Probe this bus if we haven't done so already.
    166   1.2   thorpej 	 */
    167   1.2   thorpej 	for (er = ep_isa_all_probes.lh_first; er != NULL;
    168   1.2   thorpej 	    er = er->er_link.le_next)
    169   1.2   thorpej 		if (er->er_bus == parent->dv_unit)
    170   1.2   thorpej 			goto bus_probed;
    171   1.2   thorpej 
    172   1.2   thorpej 	/*
    173   1.2   thorpej 	 * Mark this bus so we don't probe it again.
    174   1.2   thorpej 	 */
    175   1.2   thorpej 	er = (struct ep_isa_done_probe *)
    176   1.2   thorpej 	    malloc(sizeof(struct ep_isa_done_probe), M_DEVBUF, M_NOWAIT);
    177   1.2   thorpej 	if (er == NULL)
    178   1.2   thorpej 		panic("ep_isa_probe: can't allocate state storage");
    179   1.2   thorpej 
    180   1.2   thorpej 	er->er_bus = bus;
    181   1.2   thorpej 	LIST_INSERT_HEAD(&ep_isa_all_probes, er, er_link);
    182   1.2   thorpej 
    183   1.2   thorpej 	/*
    184   1.2   thorpej 	 * Map the Etherlink ID port for the probe sequence.
    185   1.2   thorpej 	 */
    186   1.8   thorpej 	if (bus_space_map(iot, ELINK_ID_PORT, 1, 0, &ioh)) {
    187   1.7  christos 		printf("ep_isa_probe: can't map Etherlink ID port\n");
    188   1.3  christos 		return 0;
    189   1.2   thorpej 	}
    190   1.2   thorpej 
    191   1.2   thorpej 	for (slot = 0; slot < MAXEPCARDS; slot++) {
    192   1.8   thorpej 		elink_reset(iot, ioh, parent->dv_unit);
    193   1.8   thorpej 		elink_idseq(iot, ioh, ELINK_509_POLY);
    194   1.2   thorpej 
    195   1.2   thorpej 		/* Untag all the adapters so they will talk to us. */
    196   1.2   thorpej 		if (slot == 0)
    197   1.8   thorpej 			bus_space_write_1(iot, ioh, 0, TAG_ADAPTER + 0);
    198   1.1   thorpej 
    199   1.8   thorpej 		vendor = htons(epreadeeprom(iot, ioh, EEPROM_MFG_ID));
    200   1.2   thorpej 		if (vendor != MFG_ID)
    201   1.2   thorpej 			continue;
    202   1.1   thorpej 
    203   1.8   thorpej 		model = htons(epreadeeprom(iot, ioh, EEPROM_PROD_ID));
    204   1.2   thorpej 		if ((model & 0xfff0) != PROD_ID) {
    205   1.1   thorpej #ifndef trusted
    206   1.7  christos 			printf(
    207   1.2   thorpej 			 "ep_isa_probe: ignoring model %04x\n", model);
    208   1.1   thorpej #endif
    209   1.2   thorpej 			continue;
    210   1.1   thorpej 			}
    211   1.1   thorpej 
    212   1.8   thorpej 		iobase = epreadeeprom(iot, ioh, EEPROM_ADDR_CFG);
    213   1.2   thorpej 		iobase = (iobase & 0x1f) * 0x10 + 0x200;
    214   1.1   thorpej 
    215   1.8   thorpej 		irq = epreadeeprom(iot, ioh, EEPROM_RESOURCE_CFG);
    216   1.2   thorpej 		irq >>= 12;
    217   1.2   thorpej 		epaddcard(bus, iobase, irq);
    218   1.2   thorpej 
    219   1.2   thorpej 		/* so card will not respond to contention again */
    220   1.8   thorpej 		bus_space_write_1(iot, ioh, 0, TAG_ADAPTER + 1);
    221   1.2   thorpej 
    222   1.2   thorpej 		/*
    223   1.2   thorpej 		 * XXX: this should probably not be done here
    224   1.2   thorpej 		 * because it enables the drq/irq lines from
    225   1.2   thorpej 		 * the board. Perhaps it should be done after
    226   1.2   thorpej 		 * we have checked for irq/drq collisions?
    227   1.2   thorpej 		 */
    228   1.8   thorpej 		bus_space_write_1(iot, ioh, 0, ACTIVATE_ADAPTER_TO_CONFIG);
    229   1.1   thorpej 	}
    230   1.2   thorpej 	/* XXX should we sort by ethernet address? */
    231   1.2   thorpej 
    232   1.8   thorpej 	bus_space_unmap(iot, ioh, 1);
    233   1.2   thorpej 
    234   1.2   thorpej  bus_probed:
    235   1.1   thorpej 
    236   1.1   thorpej 	for (i = 0; i < nepcards; i++) {
    237   1.2   thorpej 		if (epcards[i].bus != bus)
    238   1.2   thorpej 			continue;
    239   1.1   thorpej 		if (epcards[i].available == 0)
    240   1.1   thorpej 			continue;
    241   1.1   thorpej 		if (ia->ia_iobase != IOBASEUNK &&
    242   1.1   thorpej 		    ia->ia_iobase != epcards[i].iobase)
    243   1.1   thorpej 			continue;
    244   1.1   thorpej 		if (ia->ia_irq != IRQUNK &&
    245   1.1   thorpej 		    ia->ia_irq != epcards[i].irq)
    246   1.1   thorpej 			continue;
    247   1.1   thorpej 		goto good;
    248   1.1   thorpej 	}
    249   1.1   thorpej 	return 0;
    250   1.1   thorpej 
    251   1.1   thorpej good:
    252   1.1   thorpej 	epcards[i].available = 0;
    253   1.1   thorpej 	ia->ia_iobase = epcards[i].iobase;
    254   1.1   thorpej 	ia->ia_irq = epcards[i].irq;
    255   1.1   thorpej 	ia->ia_iosize = 0x10;
    256   1.1   thorpej 	ia->ia_msize = 0;
    257   1.1   thorpej 	return 1;
    258   1.1   thorpej }
    259   1.1   thorpej 
    260   1.1   thorpej void
    261   1.1   thorpej ep_isa_attach(parent, self, aux)
    262   1.1   thorpej 	struct device *parent, *self;
    263   1.1   thorpej 	void *aux;
    264   1.1   thorpej {
    265   1.1   thorpej 	struct ep_softc *sc = (void *)self;
    266   1.1   thorpej 	struct isa_attach_args *ia = aux;
    267   1.8   thorpej 	bus_space_tag_t iot = ia->ia_iot;
    268   1.8   thorpej 	bus_space_handle_t ioh;
    269   1.1   thorpej 
    270   1.2   thorpej 	/* Map i/o space. */
    271   1.8   thorpej 	if (bus_space_map(iot, ia->ia_iobase, ia->ia_iosize, 0, &ioh))
    272   1.2   thorpej 		panic("ep_isa_attach: can't map i/o space");
    273   1.2   thorpej 
    274   1.8   thorpej 	sc->sc_iot = iot;
    275   1.2   thorpej 	sc->sc_ioh = ioh;
    276   1.1   thorpej 	sc->bustype = EP_BUS_ISA;
    277   1.1   thorpej 
    278   1.7  christos 	printf(": 3Com 3C509 Ethernet\n");
    279   1.1   thorpej 
    280   1.9  jonathan 	/* we can't easily tell if this is a 3c509, 3c509B, or 3c515 */
    281   1.9  jonathan 	epconfig(sc, EP_CHIPSET_UNKNOWN);	/* XXX */
    282   1.1   thorpej 
    283   1.1   thorpej 	sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
    284   1.1   thorpej 	    IPL_NET, epintr, sc);
    285   1.1   thorpej }
    286