2010-03-03 16:39:57 +03:00
|
|
|
/* $NetBSD: if_ne_isa.c,v 1.27 2010/03/03 13:39:57 tsutsui Exp $ */
|
1997-10-15 03:01:10 +04:00
|
|
|
|
|
|
|
/*-
|
1998-10-31 04:44:16 +03:00
|
|
|
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
|
1997-10-15 03:01:10 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
|
|
|
|
* NASA Ames Research Center.
|
|
|
|
*
|
|
|
|
* 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. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``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 FOUNDATION OR CONTRIBUTORS
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 11:01:09 +03:00
|
|
|
#include <sys/cdefs.h>
|
2010-03-03 16:39:57 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: if_ne_isa.c,v 1.27 2010/03/03 13:39:57 tsutsui Exp $");
|
2001-11-13 11:01:09 +03:00
|
|
|
|
1997-10-15 03:01:10 +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 <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/intr.h>
|
|
|
|
#include <sys/bus.h>
|
1997-10-15 03:01:10 +04:00
|
|
|
|
|
|
|
#include <dev/ic/dp8390reg.h>
|
|
|
|
#include <dev/ic/dp8390var.h>
|
|
|
|
|
|
|
|
#include <dev/ic/ne2000reg.h>
|
|
|
|
#include <dev/ic/ne2000var.h>
|
|
|
|
|
|
|
|
#include <dev/isa/isavar.h>
|
|
|
|
|
2008-03-12 17:31:11 +03:00
|
|
|
int ne_isa_match(device_t, cfdata_t, void *);
|
|
|
|
void ne_isa_attach(device_t, device_t, void *);
|
1997-10-15 03:01:10 +04:00
|
|
|
|
|
|
|
struct ne_isa_softc {
|
|
|
|
struct ne2000_softc sc_ne2000; /* real "ne2000" softc */
|
|
|
|
|
|
|
|
/* ISA-specific goo. */
|
|
|
|
void *sc_ih; /* interrupt cookie */
|
|
|
|
};
|
|
|
|
|
2008-03-12 17:31:11 +03:00
|
|
|
CFATTACH_DECL_NEW(ne_isa, sizeof(struct ne_isa_softc),
|
2002-10-02 07:10:45 +04:00
|
|
|
ne_isa_match, ne_isa_attach, NULL, NULL);
|
1997-10-15 03:01:10 +04:00
|
|
|
|
|
|
|
int
|
2008-03-12 17:31:11 +03:00
|
|
|
ne_isa_match(device_t parent, cfdata_t match, void *aux)
|
1997-10-15 03:01:10 +04:00
|
|
|
{
|
|
|
|
struct isa_attach_args *ia = aux;
|
|
|
|
bus_space_tag_t nict = ia->ia_iot;
|
|
|
|
bus_space_handle_t nich;
|
|
|
|
bus_space_tag_t asict;
|
|
|
|
bus_space_handle_t asich;
|
|
|
|
int rv = 0;
|
|
|
|
|
2002-01-08 00:46:56 +03:00
|
|
|
if (ia->ia_nio < 1)
|
|
|
|
return (0);
|
|
|
|
if (ia->ia_nirq < 1)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (ISA_DIRECT_CONFIG(ia))
|
|
|
|
return (0);
|
|
|
|
|
1997-10-15 03:01:10 +04:00
|
|
|
/* Disallow wildcarded values. */
|
2004-09-15 00:20:46 +04:00
|
|
|
if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
|
1997-10-15 03:01:10 +04:00
|
|
|
return (0);
|
2004-09-15 00:20:46 +04:00
|
|
|
if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ)
|
1997-10-15 03:01:10 +04:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* Make sure this is a valid NE[12]000 i/o address. */
|
2002-01-08 00:46:56 +03:00
|
|
|
if ((ia->ia_io[0].ir_addr & 0x1f) != 0)
|
1997-10-15 03:01:10 +04:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* Map i/o space. */
|
2002-01-08 00:46:56 +03:00
|
|
|
if (bus_space_map(nict, ia->ia_io[0].ir_addr, NE2000_NPORTS, 0, &nich))
|
1997-10-15 03:01:10 +04:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
asict = nict;
|
|
|
|
if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
|
|
|
|
NE2000_ASIC_NPORTS, &asich))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Look for an NE2000-compatible card. */
|
|
|
|
rv = ne2000_detect(nict, nich, asict, asich);
|
|
|
|
|
2002-01-08 00:46:56 +03:00
|
|
|
if (rv) {
|
|
|
|
ia->ia_nio = 1;
|
|
|
|
ia->ia_io[0].ir_size = NE2000_NPORTS;
|
|
|
|
|
|
|
|
ia->ia_nirq = 1;
|
|
|
|
|
|
|
|
ia->ia_niomem = 0;
|
|
|
|
ia->ia_ndrq = 0;
|
|
|
|
}
|
1997-10-15 03:01:10 +04:00
|
|
|
|
|
|
|
out:
|
|
|
|
bus_space_unmap(nict, nich, NE2000_NPORTS);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-03-12 17:31:11 +03:00
|
|
|
ne_isa_attach(device_t parent, device_t self, void *aux)
|
1997-10-15 03:01:10 +04:00
|
|
|
{
|
2008-03-12 17:31:11 +03:00
|
|
|
struct ne_isa_softc *isc = device_private(self);
|
1997-10-15 03:01:10 +04:00
|
|
|
struct ne2000_softc *nsc = &isc->sc_ne2000;
|
|
|
|
struct dp8390_softc *dsc = &nsc->sc_dp8390;
|
|
|
|
struct isa_attach_args *ia = aux;
|
|
|
|
bus_space_tag_t nict = ia->ia_iot;
|
|
|
|
bus_space_handle_t nich;
|
|
|
|
bus_space_tag_t asict = nict;
|
|
|
|
bus_space_handle_t asich;
|
|
|
|
const char *typestr;
|
1998-10-31 04:44:16 +03:00
|
|
|
int netype;
|
1997-10-15 03:01:10 +04:00
|
|
|
|
2008-03-12 17:31:11 +03:00
|
|
|
dsc->sc_dev = self;
|
|
|
|
aprint_normal("\n");
|
1997-10-15 03:01:10 +04:00
|
|
|
|
|
|
|
/* Map i/o space. */
|
2002-01-08 00:46:56 +03:00
|
|
|
if (bus_space_map(nict, ia->ia_io[0].ir_addr, NE2000_NPORTS,
|
|
|
|
0, &nich)) {
|
2008-03-12 17:31:11 +03:00
|
|
|
aprint_error_dev(self, "can't map i/o space\n");
|
1997-10-15 03:01:10 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
|
|
|
|
NE2000_ASIC_NPORTS, &asich)) {
|
2008-03-12 17:31:11 +03:00
|
|
|
aprint_error_dev(self, "can't subregion i/o space\n");
|
1997-10-15 03:01:10 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dsc->sc_regt = nict;
|
|
|
|
dsc->sc_regh = nich;
|
|
|
|
|
|
|
|
nsc->sc_asict = asict;
|
|
|
|
nsc->sc_asich = asich;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Detect it again, so we can print some information about the
|
|
|
|
* interface.
|
|
|
|
*/
|
1998-10-31 04:44:16 +03:00
|
|
|
netype = ne2000_detect(nict, nich, asict, asich);
|
|
|
|
switch (netype) {
|
1997-10-15 03:01:10 +04:00
|
|
|
case NE2000_TYPE_NE1000:
|
|
|
|
typestr = "NE1000";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NE2000_TYPE_NE2000:
|
|
|
|
typestr = "NE2000";
|
2010-03-03 16:39:57 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NE2000_TYPE_RTL8019:
|
|
|
|
typestr = "NE2000 (RTL8019)";
|
1997-10-15 03:01:10 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2008-03-12 17:31:11 +03:00
|
|
|
aprint_error_dev(self, "where did the card go?!\n");
|
1997-10-15 03:01:10 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-03-12 17:31:11 +03:00
|
|
|
aprint_normal_dev(self, "%s Ethernet\n", typestr);
|
1997-10-15 03:01:10 +04:00
|
|
|
|
|
|
|
/* This interface is always enabled. */
|
|
|
|
dsc->sc_enabled = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do generic NE2000 attach. This will read the station address
|
|
|
|
* from the EEPROM.
|
|
|
|
*/
|
2001-02-12 21:49:03 +03:00
|
|
|
ne2000_attach(nsc, NULL);
|
1997-10-15 03:01:10 +04:00
|
|
|
|
|
|
|
/* Establish the interrupt handler. */
|
2002-01-08 00:46:56 +03:00
|
|
|
isc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
|
|
|
|
IST_EDGE, IPL_NET, dp8390_intr, dsc);
|
1997-10-15 03:01:10 +04:00
|
|
|
if (isc->sc_ih == NULL)
|
2008-03-12 17:31:11 +03:00
|
|
|
aprint_error_dev(self,
|
|
|
|
"couldn't establish interrupt handler\n");
|
1997-10-15 03:01:10 +04:00
|
|
|
}
|