Home | History | Annotate | Line # | Download | only in isa
if_lc_isa.c revision 1.30
      1  1.30    bouyer /*	$NetBSD: if_lc_isa.c,v 1.30 2009/02/13 22:39:37 bouyer 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.30    bouyer __KERNEL_RCSID(0, "$NetBSD: if_lc_isa.c,v 1.30 2009/02/13 22:39:37 bouyer 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.28        ad #include <sys/cpu.h>
     55  1.28        ad #include <sys/bus.h>
     56  1.28        ad #include <sys/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.20     perry static int lemac_isa_find(lemac_softc_t *, struct isa_attach_args *, int);
     66  1.20     perry static int lemac_isa_probe(struct device *, struct cfdata *, void *);
     67  1.20     perry static void lemac_isa_attach(struct device *, struct device *, void *);
     68   1.6  christos 
     69  1.16   thorpej CFATTACH_DECL(lc_isa, sizeof(lemac_softc_t),
     70  1.16   thorpej     lemac_isa_probe, lemac_isa_attach, NULL, NULL);
     71   1.6  christos 
     72   1.6  christos static int
     73   1.6  christos lemac_isa_find(sc, ia, attach)
     74   1.6  christos 	lemac_softc_t *sc;
     75   1.6  christos 	struct isa_attach_args *ia;
     76   1.6  christos 	int attach;
     77   1.6  christos {
     78   1.6  christos 	bus_addr_t maddr;
     79  1.30    bouyer 	bus_size_t msiz;
     80   1.6  christos 	int rv = 0, irq;
     81   1.6  christos 
     82  1.13   thorpej 	if (ia->ia_nio < 1)
     83  1.13   thorpej 		return (0);
     84  1.13   thorpej 	if (ia->ia_niomem < 1)
     85  1.13   thorpej 		return (0);
     86  1.13   thorpej 	if (ia->ia_nirq < 1)
     87  1.13   thorpej 		return (0);
     88  1.13   thorpej 
     89  1.13   thorpej 	if (ISA_DIRECT_CONFIG(ia))
     90  1.13   thorpej 		return (0);
     91  1.13   thorpej 
     92   1.6  christos 	/*
     93   1.6  christos 	 * Disallow wildcarded i/o addresses.
     94   1.6  christos 	 */
     95  1.19  drochner 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
     96   1.6  christos 		return 0;
     97   1.6  christos 
     98   1.6  christos 	/*
     99   1.6  christos 	 * Make sure this is a valid LEMAC address.
    100   1.6  christos 	 */
    101  1.13   thorpej 	if (ia->ia_io[0].ir_addr & (LEMAC_IOSIZE - 1))
    102   1.6  christos 		return 0;
    103   1.6  christos 
    104   1.6  christos 	sc->sc_iot = ia->ia_iot;
    105   1.6  christos 
    106  1.13   thorpej 	if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, LEMAC_IOSIZE, 0,
    107   1.6  christos 	    &sc->sc_ioh)) {
    108   1.6  christos 		if (attach)
    109   1.6  christos 			printf(": can't map i/o space\n");
    110   1.6  christos 		return 0;
    111   1.6  christos 	}
    112   1.6  christos 
    113   1.6  christos 	/*
    114   1.6  christos 	 * Read the Ethernet address from the EEPROM.
    115   1.6  christos 	 * It must start with one of the DEC OUIs and pass the
    116   1.6  christos 	 * DEC ethernet checksum test.
    117   1.6  christos 	 */
    118   1.6  christos 	if (lemac_port_check(sc->sc_iot, sc->sc_ioh) == 0)
    119   1.6  christos 		goto outio;
    120   1.6  christos 
    121   1.6  christos 	/*
    122   1.6  christos 	 * Get information about memory space and attempt to map it.
    123   1.6  christos 	 */
    124  1.22  christos 	lemac_info_get(sc->sc_iot, sc->sc_ioh, &maddr, &msiz, &irq);
    125   1.6  christos 
    126  1.19  drochner 	if (ia->ia_iomem[0].ir_addr != ISA_UNKNOWN_IOMEM &&
    127  1.13   thorpej 	    ia->ia_iomem[0].ir_addr != maddr)
    128   1.6  christos 		goto outio;
    129   1.6  christos 
    130  1.18   mycroft 	if (attach) {
    131  1.22  christos 		if (msiz == 0) {
    132  1.18   mycroft 			printf(": memory configuration is invalid\n");
    133  1.18   mycroft 			goto outio;
    134  1.18   mycroft 		}
    135  1.18   mycroft 
    136  1.18   mycroft 		sc->sc_memt = ia->ia_memt;
    137  1.22  christos 		if (bus_space_map(ia->ia_memt, maddr, msiz, 0, &sc->sc_memh)) {
    138   1.6  christos 			printf(": can't map mem space\n");
    139  1.18   mycroft 			goto outio;
    140  1.18   mycroft 		}
    141   1.6  christos 	}
    142   1.6  christos 
    143   1.6  christos 	/*
    144   1.6  christos 	 * Double-check IRQ configuration.
    145   1.6  christos 	 */
    146  1.19  drochner 	if (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ &&
    147  1.13   thorpej 	    ia->ia_irq[0].ir_irq != irq)
    148  1.29    cegger 		printf("%s: overriding IRQ %d to %d\n", device_xname(&sc->sc_dv),
    149  1.13   thorpej 		       ia->ia_irq[0].ir_irq, irq);
    150   1.6  christos 
    151   1.6  christos 	if (attach) {
    152   1.6  christos 		sc->sc_ats = shutdownhook_establish(lemac_shutdown, sc);
    153  1.29    cegger 		if (sc->sc_ats == NULL) {
    154  1.29    cegger 			aprint_normal("\n");
    155  1.29    cegger 			aprint_error_dev(&sc->sc_dv, "warning: can't establish shutdown hook\n");
    156  1.29    cegger 		}
    157   1.6  christos 
    158   1.6  christos 		lemac_ifattach(sc);
    159   1.6  christos 
    160   1.6  christos 		sc->sc_ih = isa_intr_establish(ia->ia_ic, irq, IST_EDGE,
    161   1.6  christos 		    IPL_NET, lemac_intr, sc);
    162   1.6  christos 	}
    163   1.6  christos 
    164   1.6  christos 	/*
    165   1.6  christos 	 * I guess we've found one.
    166   1.6  christos 	 */
    167   1.6  christos 	rv = 1;
    168   1.6  christos 
    169  1.13   thorpej 	ia->ia_nio = 1;
    170  1.13   thorpej 	ia->ia_io[0].ir_size = LEMAC_IOSIZE;
    171  1.13   thorpej 
    172  1.13   thorpej 	ia->ia_niomem = 1;
    173  1.13   thorpej 	ia->ia_iomem[0].ir_addr = maddr;
    174  1.22  christos 	ia->ia_iomem[0].ir_size = msiz;
    175  1.13   thorpej 
    176  1.13   thorpej 	ia->ia_nirq = 1;
    177  1.13   thorpej 	ia->ia_irq[0].ir_irq = irq;
    178  1.13   thorpej 
    179  1.13   thorpej 	ia->ia_ndrq = 0;
    180   1.6  christos 
    181   1.6  christos outio:
    182   1.6  christos 	if (rv == 0 || !attach)
    183   1.6  christos 		bus_space_unmap(sc->sc_iot, sc->sc_ioh, LEMAC_IOSIZE);
    184   1.6  christos 	return rv;
    185   1.6  christos }
    186   1.6  christos 
    187   1.1      matt static int
    188  1.27  christos lemac_isa_probe(struct device *parent, struct cfdata *match, void *aux)
    189   1.1      matt {
    190   1.6  christos 	struct isa_attach_args *ia = aux;
    191   1.6  christos 	struct cfdata *cf = match;
    192   1.6  christos 	lemac_softc_t sc;
    193  1.17    itojun 	snprintf(sc.sc_dv.dv_xname, sizeof(sc.sc_dv.dv_xname), "%s%d",
    194  1.17    itojun 	    lc_cd.cd_name, cf->cf_unit);
    195  1.21     perry 
    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.27  christos lemac_isa_attach(struct device *parent, struct device *self, void *aux)
    201   1.1      matt {
    202   1.6  christos 	lemac_softc_t *sc = (void *)self;
    203   1.6  christos 	struct isa_attach_args *ia = aux;
    204   1.1      matt 
    205   1.6  christos 	(void) lemac_isa_find(sc, ia, 1);
    206   1.1      matt }
    207