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