1998-10-31 04:44:16 +03:00
|
|
|
/* $NetBSD: if_ne_isapnp.c,v 1.9 1998/10/31 01:44:16 thorpej Exp $ */
|
1997-10-16 21:18:29 +04:00
|
|
|
|
|
|
|
/*-
|
1998-10-31 04:44:16 +03:00
|
|
|
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
|
1997-10-16 21:18:29 +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 and Matt Thomas of the 3am Software Foundry.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
1998-07-05 04:51:04 +04:00
|
|
|
#include "opt_inet.h"
|
1998-07-05 10:49:00 +04:00
|
|
|
#include "opt_ns.h"
|
1997-10-16 21:18:29 +04:00
|
|
|
#include "bpfilter.h"
|
|
|
|
|
|
|
|
#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>
|
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/if_inarp.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NS
|
|
|
|
#include <netns/ns.h>
|
|
|
|
#include <netns/ns_if.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#include <net/bpfdesc.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <machine/intr.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
|
|
|
|
#include <dev/ic/dp8390reg.h>
|
|
|
|
#include <dev/ic/dp8390var.h>
|
|
|
|
|
|
|
|
#include <dev/ic/ne2000reg.h>
|
|
|
|
#include <dev/ic/ne2000var.h>
|
|
|
|
|
1998-10-31 04:44:16 +03:00
|
|
|
#include <dev/ic/rtl80x9reg.h>
|
|
|
|
#include <dev/ic/rtl80x9var.h>
|
|
|
|
|
1997-10-16 21:18:29 +04:00
|
|
|
#include <dev/isa/isavar.h>
|
|
|
|
|
|
|
|
#include <dev/isapnp/isapnpreg.h>
|
|
|
|
#include <dev/isapnp/isapnpvar.h>
|
1998-07-23 23:30:44 +04:00
|
|
|
#include <dev/isapnp/isapnpdevs.h>
|
1997-10-16 21:18:29 +04:00
|
|
|
|
|
|
|
static int ne_isapnp_match __P((struct device *, struct cfdata *, void *));
|
|
|
|
static void ne_isapnp_attach __P((struct device *, struct device *, void *));
|
|
|
|
|
|
|
|
struct ne_isapnp_softc {
|
|
|
|
struct ne2000_softc sc_ne2000; /* real "ne2000" softc */
|
|
|
|
|
|
|
|
/* ISA-specific goo. */
|
|
|
|
void *sc_ih; /* interrupt cookie */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cfattach ne_isapnp_ca = {
|
|
|
|
sizeof(struct ne_isapnp_softc), ne_isapnp_match, ne_isapnp_attach
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
1998-07-23 23:30:44 +04:00
|
|
|
ne_isapnp_match(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *match;
|
|
|
|
void *aux;
|
1997-10-16 21:18:29 +04:00
|
|
|
{
|
1998-07-23 23:30:44 +04:00
|
|
|
return isapnp_devmatch(aux, &isapnp_ne_devinfo);
|
1997-10-16 21:18:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ne_isapnp_attach(
|
|
|
|
struct device *parent,
|
|
|
|
struct device *self,
|
|
|
|
void *aux)
|
|
|
|
{
|
|
|
|
struct ne_isapnp_softc * const isc = (struct ne_isapnp_softc *)self;
|
|
|
|
struct ne2000_softc * const nsc = &isc->sc_ne2000;
|
|
|
|
struct dp8390_softc * const dsc = &nsc->sc_dp8390;
|
|
|
|
struct isapnp_attach_args * const ipa = aux;
|
1997-12-17 04:31:59 +03:00
|
|
|
bus_space_tag_t nict;
|
|
|
|
bus_space_handle_t nich;
|
|
|
|
bus_space_tag_t asict;
|
1997-10-16 21:18:29 +04:00
|
|
|
bus_space_handle_t asich;
|
1998-10-31 04:44:16 +03:00
|
|
|
void (*npp_init_media) __P((struct dp8390_softc *, int **,
|
|
|
|
int *, int *));
|
|
|
|
int *media, nmedia, defmedia;
|
1997-10-16 21:18:29 +04:00
|
|
|
const char *typestr;
|
1998-10-31 04:44:16 +03:00
|
|
|
int netype;
|
1997-10-16 21:18:29 +04:00
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
1998-10-31 04:44:16 +03:00
|
|
|
npp_init_media = NULL;
|
|
|
|
media = NULL;
|
|
|
|
nmedia = defmedia = 0;
|
|
|
|
|
1997-10-16 21:18:29 +04:00
|
|
|
if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
|
|
|
|
printf("%s: can't configure isapnp resources\n",
|
|
|
|
dsc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1997-12-17 04:31:59 +03:00
|
|
|
nict = ipa->ipa_iot;
|
|
|
|
nich = ipa->ipa_io[0].h;
|
|
|
|
|
|
|
|
asict = nict;
|
|
|
|
|
1997-10-16 21:18:29 +04:00
|
|
|
if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
|
|
|
|
NE2000_ASIC_NPORTS, &asich)) {
|
|
|
|
printf("%s: can't subregion i/o space\n", dsc->sc_dev.dv_xname);
|
|
|
|
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-16 21:18:29 +04:00
|
|
|
case NE2000_TYPE_NE1000:
|
|
|
|
typestr = "NE1000";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NE2000_TYPE_NE2000:
|
|
|
|
typestr = "NE2000";
|
1998-10-31 04:44:16 +03:00
|
|
|
/*
|
|
|
|
* Check for a RealTek 8019.
|
|
|
|
*/
|
|
|
|
bus_space_write_1(nict, nich, ED_P0_CR,
|
|
|
|
ED_CR_PAGE_0 | ED_CR_STP);
|
|
|
|
if (bus_space_read_1(nict, nich, NERTL_RTL0_8019ID0) ==
|
|
|
|
RTL0_8019ID0 &&
|
|
|
|
bus_space_read_1(nict, nich, NERTL_RTL0_8019ID1) ==
|
|
|
|
RTL0_8019ID1) {
|
|
|
|
typestr = "NE2000 (RTL8019)";
|
|
|
|
npp_init_media = rtl80x9_init_media;
|
|
|
|
dsc->sc_mediachange = rtl80x9_mediachange;
|
|
|
|
dsc->sc_mediastatus = rtl80x9_mediastatus;
|
|
|
|
dsc->init_card = rtl80x9_init_card;
|
|
|
|
}
|
1997-10-16 21:18:29 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("%s: where did the card go?!\n", dsc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("%s: %s Ethernet\n", dsc->sc_dev.dv_xname, typestr);
|
|
|
|
|
1998-10-31 04:44:16 +03:00
|
|
|
/* Initialize media, if we have it. */
|
|
|
|
if (npp_init_media != NULL)
|
|
|
|
(*npp_init_media)(dsc, &media, &nmedia, &defmedia);
|
|
|
|
|
1997-10-16 21:18:29 +04:00
|
|
|
/* This interface is always enabled. */
|
|
|
|
dsc->sc_enabled = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do generic NE2000 attach. This will read the station address
|
|
|
|
* from the EEPROM.
|
|
|
|
*/
|
1998-10-31 04:44:16 +03:00
|
|
|
ne2000_attach(nsc, NULL, media, nmedia, defmedia);
|
1997-10-16 21:18:29 +04:00
|
|
|
|
|
|
|
/* Establish the interrupt handler. */
|
|
|
|
isc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
|
1997-10-29 00:27:55 +03:00
|
|
|
ipa->ipa_irq[0].type, IPL_NET, dp8390_intr, dsc);
|
1997-10-16 21:18:29 +04:00
|
|
|
if (isc->sc_ih == NULL)
|
|
|
|
printf("%s: couldn't establish interrupt handler\n",
|
|
|
|
dsc->sc_dev.dv_xname);
|
|
|
|
}
|