2012-10-27 21:17:22 +04:00
|
|
|
/* $NetBSD: if_lc_isa.c,v 1.34 2012/10/27 17:18:24 chs Exp $ */
|
1997-08-01 01:58:19 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1994, 1995, 1997 Matt Thomas <matt@3am-software.com>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. The name of the author may not be used to endorse or promote products
|
2001-06-13 14:45:57 +04:00
|
|
|
* derived from this software without specific prior written permission
|
1997-08-01 01:58:19 +04:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DEC EtherWORKS 3 Ethernet Controllers
|
|
|
|
*
|
|
|
|
* Written by Matt Thomas
|
|
|
|
*
|
|
|
|
* This driver supports the LEMAC (DE203, DE204, and DE205) cards.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 11:01:09 +03:00
|
|
|
#include <sys/cdefs.h>
|
2012-10-27 21:17:22 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: if_lc_isa.c,v 1.34 2012/10/27 17:18:24 chs Exp $");
|
2001-11-13 11:01:09 +03:00
|
|
|
|
1997-08-01 01:58:19 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/cpu.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/intr.h>
|
1997-08-01 01:58:19 +04:00
|
|
|
|
|
|
|
#include <dev/ic/lemacreg.h>
|
|
|
|
#include <dev/ic/lemacvar.h>
|
|
|
|
|
|
|
|
#include <dev/isa/isavar.h>
|
|
|
|
|
1997-11-17 06:34:24 +03:00
|
|
|
extern struct cfdriver lc_cd;
|
|
|
|
|
2012-10-27 21:17:22 +04:00
|
|
|
static int lemac_isa_find(lemac_softc_t *, const char *, struct isa_attach_args *, int);
|
2009-05-12 13:10:15 +04:00
|
|
|
static int lemac_isa_probe(device_t, cfdata_t, void *);
|
|
|
|
static void lemac_isa_attach(device_t, device_t, void *);
|
1997-11-30 23:03:15 +03:00
|
|
|
|
2012-10-27 21:17:22 +04:00
|
|
|
CFATTACH_DECL_NEW(lc_isa, sizeof(lemac_softc_t),
|
2002-10-02 07:10:45 +04:00
|
|
|
lemac_isa_probe, lemac_isa_attach, NULL, NULL);
|
1997-11-30 23:03:15 +03:00
|
|
|
|
|
|
|
static int
|
2012-10-27 21:17:22 +04:00
|
|
|
lemac_isa_find(lemac_softc_t *sc, const char *xname, struct isa_attach_args *ia, int attach)
|
1997-11-30 23:03:15 +03:00
|
|
|
{
|
|
|
|
bus_addr_t maddr;
|
2009-02-14 01:39:37 +03:00
|
|
|
bus_size_t msiz;
|
1997-11-30 23:03:15 +03:00
|
|
|
int rv = 0, irq;
|
|
|
|
|
2002-01-08 00:46:56 +03:00
|
|
|
if (ia->ia_nio < 1)
|
|
|
|
return (0);
|
|
|
|
if (ia->ia_niomem < 1)
|
|
|
|
return (0);
|
|
|
|
if (ia->ia_nirq < 1)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (ISA_DIRECT_CONFIG(ia))
|
|
|
|
return (0);
|
|
|
|
|
1997-11-30 23:03:15 +03:00
|
|
|
/*
|
|
|
|
* Disallow wildcarded i/o addresses.
|
|
|
|
*/
|
2004-09-15 00:20:46 +04:00
|
|
|
if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
|
1997-11-30 23:03:15 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure this is a valid LEMAC address.
|
|
|
|
*/
|
2002-01-08 00:46:56 +03:00
|
|
|
if (ia->ia_io[0].ir_addr & (LEMAC_IOSIZE - 1))
|
1997-11-30 23:03:15 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
sc->sc_iot = ia->ia_iot;
|
|
|
|
|
2002-01-08 00:46:56 +03:00
|
|
|
if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, LEMAC_IOSIZE, 0,
|
1997-11-30 23:03:15 +03:00
|
|
|
&sc->sc_ioh)) {
|
|
|
|
if (attach)
|
|
|
|
printf(": can't map i/o space\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the Ethernet address from the EEPROM.
|
|
|
|
* It must start with one of the DEC OUIs and pass the
|
|
|
|
* DEC ethernet checksum test.
|
|
|
|
*/
|
|
|
|
if (lemac_port_check(sc->sc_iot, sc->sc_ioh) == 0)
|
|
|
|
goto outio;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get information about memory space and attempt to map it.
|
|
|
|
*/
|
2005-05-30 08:32:38 +04:00
|
|
|
lemac_info_get(sc->sc_iot, sc->sc_ioh, &maddr, &msiz, &irq);
|
1997-11-30 23:03:15 +03:00
|
|
|
|
2004-09-15 00:20:46 +04:00
|
|
|
if (ia->ia_iomem[0].ir_addr != ISA_UNKNOWN_IOMEM &&
|
2002-01-08 00:46:56 +03:00
|
|
|
ia->ia_iomem[0].ir_addr != maddr)
|
1997-11-30 23:03:15 +03:00
|
|
|
goto outio;
|
|
|
|
|
2004-07-04 01:29:08 +04:00
|
|
|
if (attach) {
|
2005-05-30 08:32:38 +04:00
|
|
|
if (msiz == 0) {
|
2004-07-04 01:29:08 +04:00
|
|
|
printf(": memory configuration is invalid\n");
|
|
|
|
goto outio;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_memt = ia->ia_memt;
|
2005-05-30 08:32:38 +04:00
|
|
|
if (bus_space_map(ia->ia_memt, maddr, msiz, 0, &sc->sc_memh)) {
|
1997-11-30 23:03:15 +03:00
|
|
|
printf(": can't map mem space\n");
|
2004-07-04 01:29:08 +04:00
|
|
|
goto outio;
|
|
|
|
}
|
1997-11-30 23:03:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Double-check IRQ configuration.
|
|
|
|
*/
|
2004-09-15 00:20:46 +04:00
|
|
|
if (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ &&
|
2002-01-08 00:46:56 +03:00
|
|
|
ia->ia_irq[0].ir_irq != irq)
|
2012-10-27 21:17:22 +04:00
|
|
|
printf("%s: overriding IRQ %d to %d\n", xname,
|
2002-01-08 00:46:56 +03:00
|
|
|
ia->ia_irq[0].ir_irq, irq);
|
1997-11-30 23:03:15 +03:00
|
|
|
|
|
|
|
if (attach) {
|
|
|
|
sc->sc_ats = shutdownhook_establish(lemac_shutdown, sc);
|
2008-04-09 00:08:49 +04:00
|
|
|
if (sc->sc_ats == NULL) {
|
|
|
|
aprint_normal("\n");
|
2012-10-27 21:17:22 +04:00
|
|
|
aprint_error("%s: warning: can't establish shutdown hook\n", xname);
|
2008-04-09 00:08:49 +04:00
|
|
|
}
|
1997-11-30 23:03:15 +03:00
|
|
|
|
|
|
|
lemac_ifattach(sc);
|
|
|
|
|
|
|
|
sc->sc_ih = isa_intr_establish(ia->ia_ic, irq, IST_EDGE,
|
|
|
|
IPL_NET, lemac_intr, sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* I guess we've found one.
|
|
|
|
*/
|
|
|
|
rv = 1;
|
|
|
|
|
2002-01-08 00:46:56 +03:00
|
|
|
ia->ia_nio = 1;
|
|
|
|
ia->ia_io[0].ir_size = LEMAC_IOSIZE;
|
|
|
|
|
|
|
|
ia->ia_niomem = 1;
|
|
|
|
ia->ia_iomem[0].ir_addr = maddr;
|
2005-05-30 08:32:38 +04:00
|
|
|
ia->ia_iomem[0].ir_size = msiz;
|
2002-01-08 00:46:56 +03:00
|
|
|
|
|
|
|
ia->ia_nirq = 1;
|
|
|
|
ia->ia_irq[0].ir_irq = irq;
|
|
|
|
|
|
|
|
ia->ia_ndrq = 0;
|
1997-11-30 23:03:15 +03:00
|
|
|
|
|
|
|
outio:
|
|
|
|
if (rv == 0 || !attach)
|
|
|
|
bus_space_unmap(sc->sc_iot, sc->sc_ioh, LEMAC_IOSIZE);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1997-08-01 01:58:19 +04:00
|
|
|
static int
|
2009-05-12 13:10:15 +04:00
|
|
|
lemac_isa_probe(device_t parent, cfdata_t match, void *aux)
|
1997-08-01 01:58:19 +04:00
|
|
|
{
|
1997-11-30 23:03:15 +03:00
|
|
|
struct isa_attach_args *ia = aux;
|
2009-05-12 12:44:19 +04:00
|
|
|
cfdata_t cf = match;
|
1997-11-30 23:03:15 +03:00
|
|
|
lemac_softc_t sc;
|
2012-10-27 21:17:22 +04:00
|
|
|
char xname[16];
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2012-10-27 21:17:22 +04:00
|
|
|
snprintf(xname, sizeof(xname), "%s%d", lc_cd.cd_name, cf->cf_unit);
|
|
|
|
|
|
|
|
return lemac_isa_find(&sc, xname, ia, 0);
|
1997-08-01 01:58:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-05-12 13:10:15 +04:00
|
|
|
lemac_isa_attach(device_t parent, device_t self, void *aux)
|
1997-08-01 01:58:19 +04:00
|
|
|
{
|
2012-10-27 21:17:22 +04:00
|
|
|
lemac_softc_t *sc = device_private(self);
|
1997-11-30 23:03:15 +03:00
|
|
|
struct isa_attach_args *ia = aux;
|
1997-08-01 01:58:19 +04:00
|
|
|
|
2012-10-27 21:17:22 +04:00
|
|
|
sc->sc_dev = self;
|
|
|
|
(void) lemac_isa_find(sc, device_xname(self), ia, 1);
|
1997-08-01 01:58:19 +04:00
|
|
|
}
|