Home | History | Annotate | Line # | Download | only in isa
if_lc_isa.c revision 1.13
      1  1.13   thorpej /*	$NetBSD: if_lc_isa.c,v 1.13 2002/01/07 21:47:08 thorpej Exp $ */
      2   1.1      matt 
      3   1.1      matt /*-
      4   1.1      matt  * Copyright (c) 1994, 1995, 1997 Matt Thomas <matt (at) 3am-software.com>
      5   1.1      matt  * All rights reserved.
      6   1.1      matt  *
      7   1.1      matt  * Redistribution and use in source and binary forms, with or without
      8   1.1      matt  * modification, are permitted provided that the following conditions
      9   1.1      matt  * are met:
     10   1.1      matt  * 1. Redistributions of source code must retain the above copyright
     11   1.1      matt  *    notice, this list of conditions and the following disclaimer.
     12   1.1      matt  * 2. The name of the author may not be used to endorse or promote products
     13  1.10       wiz  *    derived from this software without specific prior written permission
     14   1.1      matt  *
     15   1.1      matt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16   1.1      matt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     17   1.1      matt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     18   1.1      matt  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     19   1.1      matt  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     20   1.1      matt  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     21   1.1      matt  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     22   1.1      matt  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23   1.1      matt  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     24   1.1      matt  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25   1.1      matt  */
     26   1.1      matt 
     27   1.1      matt /*
     28   1.1      matt  * DEC EtherWORKS 3 Ethernet Controllers
     29   1.1      matt  *
     30   1.1      matt  * Written by Matt Thomas
     31   1.1      matt  *
     32   1.1      matt  *   This driver supports the LEMAC (DE203, DE204, and DE205) cards.
     33   1.1      matt  */
     34  1.12     lukem 
     35  1.12     lukem #include <sys/cdefs.h>
     36  1.13   thorpej __KERNEL_RCSID(0, "$NetBSD: if_lc_isa.c,v 1.13 2002/01/07 21:47:08 thorpej Exp $");
     37   1.1      matt 
     38   1.1      matt #include <sys/param.h>
     39   1.1      matt #include <sys/systm.h>
     40   1.1      matt #include <sys/mbuf.h>
     41   1.1      matt #include <sys/socket.h>
     42   1.1      matt #include <sys/ioctl.h>
     43   1.1      matt #include <sys/errno.h>
     44   1.1      matt #include <sys/syslog.h>
     45   1.1      matt #include <sys/select.h>
     46   1.1      matt #include <sys/device.h>
     47   1.1      matt #include <sys/queue.h>
     48   1.1      matt 
     49   1.1      matt #include <net/if.h>
     50   1.1      matt #include <net/if_dl.h>
     51   1.1      matt #include <net/if_ether.h>
     52   1.1      matt #include <net/if_media.h>
     53   1.1      matt 
     54   1.1      matt #include <machine/cpu.h>
     55   1.1      matt #include <machine/bus.h>
     56   1.1      matt #include <machine/intr.h>
     57   1.1      matt 
     58   1.1      matt #include <dev/ic/lemacreg.h>
     59   1.1      matt #include <dev/ic/lemacvar.h>
     60   1.1      matt 
     61   1.1      matt #include <dev/isa/isavar.h>
     62   1.1      matt 
     63   1.5   thorpej extern struct cfdriver lc_cd;
     64   1.5   thorpej 
     65   1.6  christos static int lemac_isa_find __P((lemac_softc_t *, struct isa_attach_args *,
     66   1.6  christos     int));
     67   1.6  christos static int lemac_isa_probe __P((struct device *, struct cfdata *, void *));
     68   1.6  christos static void lemac_isa_attach __P((struct device *, struct device *, void *));
     69   1.6  christos 
     70   1.6  christos struct cfattach lc_isa_ca = {
     71   1.6  christos 	sizeof(lemac_softc_t), lemac_isa_probe, lemac_isa_attach
     72   1.6  christos };
     73   1.6  christos 
     74   1.6  christos static int
     75   1.6  christos lemac_isa_find(sc, ia, attach)
     76   1.6  christos 	lemac_softc_t *sc;
     77   1.6  christos 	struct isa_attach_args *ia;
     78   1.6  christos 	int attach;
     79   1.6  christos {
     80   1.6  christos 	bus_addr_t maddr;
     81   1.6  christos 	bus_addr_t msize;
     82   1.6  christos 	int rv = 0, irq;
     83   1.6  christos 
     84  1.13   thorpej 	if (ia->ia_nio < 1)
     85  1.13   thorpej 		return (0);
     86  1.13   thorpej 	if (ia->ia_niomem < 1)
     87  1.13   thorpej 		return (0);
     88  1.13   thorpej 	if (ia->ia_nirq < 1)
     89  1.13   thorpej 		return (0);
     90  1.13   thorpej 
     91  1.13   thorpej 	if (ISA_DIRECT_CONFIG(ia))
     92  1.13   thorpej 		return (0);
     93  1.13   thorpej 
     94   1.6  christos 	/*
     95   1.6  christos 	 * Disallow wildcarded i/o addresses.
     96   1.6  christos 	 */
     97  1.13   thorpej 	if (ia->ia_io[0].ir_addr == ISACF_PORT_DEFAULT)
     98   1.6  christos 		return 0;
     99   1.6  christos 
    100   1.6  christos 	/*
    101   1.6  christos 	 * Make sure this is a valid LEMAC address.
    102   1.6  christos 	 */
    103  1.13   thorpej 	if (ia->ia_io[0].ir_addr & (LEMAC_IOSIZE - 1))
    104   1.6  christos 		return 0;
    105   1.6  christos 
    106   1.6  christos 	sc->sc_iot = ia->ia_iot;
    107   1.6  christos 
    108  1.13   thorpej 	if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, LEMAC_IOSIZE, 0,
    109   1.6  christos 	    &sc->sc_ioh)) {
    110   1.6  christos 		if (attach)
    111   1.6  christos 			printf(": can't map i/o space\n");
    112   1.6  christos 		return 0;
    113   1.6  christos 	}
    114   1.6  christos 
    115   1.6  christos 	/*
    116   1.6  christos 	 * Read the Ethernet address from the EEPROM.
    117   1.6  christos 	 * It must start with one of the DEC OUIs and pass the
    118   1.6  christos 	 * DEC ethernet checksum test.
    119   1.6  christos 	 */
    120   1.6  christos 	if (lemac_port_check(sc->sc_iot, sc->sc_ioh) == 0)
    121   1.6  christos 		goto outio;
    122   1.6  christos 
    123   1.6  christos 	/*
    124   1.6  christos 	 * Get information about memory space and attempt to map it.
    125   1.6  christos 	 */
    126   1.6  christos 	lemac_info_get(sc->sc_iot, sc->sc_ioh, &maddr, &msize, &irq);
    127   1.6  christos 
    128  1.13   thorpej 	if (ia->ia_iomem[0].ir_addr != ISACF_IOMEM_DEFAULT &&
    129  1.13   thorpej 	    ia->ia_iomem[0].ir_addr != maddr)
    130   1.6  christos 		goto outio;
    131   1.6  christos 
    132   1.6  christos 	sc->sc_memt = ia->ia_memt;
    133   1.6  christos 	if (bus_space_map(ia->ia_memt, maddr, msize, 0, &sc->sc_memh)) {
    134   1.6  christos 		if (attach)
    135   1.6  christos 			printf(": can't map mem space\n");
    136   1.6  christos 		goto outio;
    137   1.6  christos 	}
    138   1.6  christos 
    139   1.6  christos 
    140   1.6  christos 	/*
    141   1.6  christos 	 * Double-check IRQ configuration.
    142   1.6  christos 	 */
    143  1.13   thorpej 	if (ia->ia_irq[0].ir_irq != ISACF_IRQ_DEFAULT &&
    144  1.13   thorpej 	    ia->ia_irq[0].ir_irq != irq)
    145   1.6  christos 		printf("%s: overriding IRQ %d to %d\n", sc->sc_dv.dv_xname,
    146  1.13   thorpej 		       ia->ia_irq[0].ir_irq, irq);
    147   1.6  christos 
    148   1.6  christos 	if (attach) {
    149   1.6  christos 		sc->sc_ats = shutdownhook_establish(lemac_shutdown, sc);
    150   1.6  christos 		if (sc->sc_ats == NULL)
    151   1.6  christos 			printf("\n%s: warning: can't establish shutdown hook\n",
    152   1.6  christos 			    sc->sc_dv.dv_xname);
    153   1.6  christos 
    154   1.6  christos 		lemac_ifattach(sc);
    155   1.6  christos 
    156   1.6  christos 		sc->sc_ih = isa_intr_establish(ia->ia_ic, irq, IST_EDGE,
    157   1.6  christos 		    IPL_NET, lemac_intr, sc);
    158   1.6  christos 	}
    159   1.6  christos 
    160   1.6  christos 	/*
    161   1.6  christos 	 * I guess we've found one.
    162   1.6  christos 	 */
    163   1.6  christos 	rv = 1;
    164   1.6  christos 
    165  1.13   thorpej 	ia->ia_nio = 1;
    166  1.13   thorpej 	ia->ia_io[0].ir_size = LEMAC_IOSIZE;
    167  1.13   thorpej 
    168  1.13   thorpej 	ia->ia_niomem = 1;
    169  1.13   thorpej 	ia->ia_iomem[0].ir_addr = maddr;
    170  1.13   thorpej 	ia->ia_iomem[0].ir_size = msize;
    171  1.13   thorpej 
    172  1.13   thorpej 	ia->ia_nirq = 1;
    173  1.13   thorpej 	ia->ia_irq[0].ir_irq = irq;
    174  1.13   thorpej 
    175  1.13   thorpej 	ia->ia_ndrq = 0;
    176   1.6  christos 
    177   1.6  christos 	if (rv == 0 || !attach)
    178   1.6  christos 		bus_space_unmap(sc->sc_memt, sc->sc_memh, msize);
    179   1.6  christos outio:
    180   1.6  christos 	if (rv == 0 || !attach)
    181   1.6  christos 		bus_space_unmap(sc->sc_iot, sc->sc_ioh, LEMAC_IOSIZE);
    182   1.6  christos 	return rv;
    183   1.6  christos }
    184   1.6  christos 
    185   1.1      matt static int
    186   1.6  christos lemac_isa_probe(parent, match, aux)
    187   1.6  christos 	struct device *parent;
    188   1.6  christos 	struct cfdata *match;
    189   1.6  christos 	void *aux;
    190   1.1      matt {
    191   1.6  christos 	struct isa_attach_args *ia = aux;
    192   1.6  christos 	struct cfdata *cf = match;
    193   1.6  christos 	lemac_softc_t sc;
    194   1.6  christos 	(void)sprintf(sc.sc_dv.dv_xname, "%s%d", lc_cd.cd_name, cf->cf_unit);
    195   1.6  christos 
    196   1.6  christos 	return lemac_isa_find(&sc, ia, 0);
    197   1.1      matt }
    198   1.1      matt 
    199   1.1      matt static void
    200   1.6  christos lemac_isa_attach(parent, self, aux)
    201   1.6  christos 	struct device *parent;
    202   1.6  christos 	struct device *self;
    203   1.6  christos 	void *aux;
    204   1.1      matt {
    205   1.6  christos 	lemac_softc_t *sc = (void *)self;
    206   1.6  christos 	struct isa_attach_args *ia = aux;
    207   1.1      matt 
    208   1.6  christos 	(void) lemac_isa_find(sc, ia, 1);
    209   1.1      matt }
    210