2011-07-27 00:51:23 +04:00
|
|
|
/* $NetBSD: if_ne_pci.c,v 1.36 2011/07/26 20:51:24 dyoung Exp $ */
|
1997-10-15 03:12:17 +04:00
|
|
|
|
|
|
|
/*-
|
1998-04-10 05:28:59 +04:00
|
|
|
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
|
1997-10-15 03:12:17 +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 10:48:40 +03:00
|
|
|
#include <sys/cdefs.h>
|
2011-07-27 00:51:23 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: if_ne_pci.c,v 1.36 2011/07/26 20:51:24 dyoung Exp $");
|
2001-11-13 10:48:40 +03:00
|
|
|
|
2000-03-22 23:58:25 +03:00
|
|
|
#include "opt_ipkdb.h"
|
1997-10-15 03:12:17 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/intr.h>
|
1997-10-15 03:12:17 +04:00
|
|
|
|
2000-03-22 23:58:25 +03:00
|
|
|
#ifdef IPKDB_NE_PCI
|
|
|
|
#include <ipkdb/ipkdb.h>
|
|
|
|
#endif
|
|
|
|
|
1997-10-15 03:12:17 +04:00
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/pci/pcidevs.h>
|
|
|
|
|
|
|
|
#include <dev/ic/dp8390reg.h>
|
|
|
|
#include <dev/ic/dp8390var.h>
|
|
|
|
|
|
|
|
#include <dev/ic/ne2000reg.h>
|
|
|
|
#include <dev/ic/ne2000var.h>
|
|
|
|
|
1998-10-31 03:27:41 +03:00
|
|
|
#include <dev/ic/rtl80x9reg.h>
|
1998-10-31 03:45:48 +03:00
|
|
|
#include <dev/ic/rtl80x9var.h>
|
1998-10-28 01:30:56 +03:00
|
|
|
|
1997-10-15 03:12:17 +04:00
|
|
|
struct ne_pci_softc {
|
|
|
|
struct ne2000_softc sc_ne2000; /* real "ne2000" softc */
|
|
|
|
|
|
|
|
/* PCI-specific goo */
|
|
|
|
void *sc_ih; /* interrupt handle */
|
|
|
|
};
|
|
|
|
|
2009-05-06 14:34:32 +04:00
|
|
|
static int ne_pci_match(device_t, cfdata_t, void *);
|
|
|
|
static void ne_pci_attach(device_t, device_t, void *);
|
1997-10-15 03:12:17 +04:00
|
|
|
|
2008-03-12 17:31:11 +03:00
|
|
|
CFATTACH_DECL_NEW(ne_pci, sizeof(struct ne_pci_softc),
|
2002-10-02 20:51:16 +04:00
|
|
|
ne_pci_match, ne_pci_attach, NULL, NULL);
|
1997-10-15 03:12:17 +04:00
|
|
|
|
2000-03-22 23:58:25 +03:00
|
|
|
#ifdef IPKDB_NE_PCI
|
|
|
|
static struct ne_pci_softc ipkdb_softc;
|
|
|
|
static pci_chipset_tag_t ipkdb_pc;
|
|
|
|
static pcitag_t ipkdb_tag;
|
|
|
|
static struct ipkdb_if *ne_kip;
|
|
|
|
|
2004-08-22 03:48:33 +04:00
|
|
|
int ne_pci_ipkdb_attach(struct ipkdb_if *, bus_space_tag_t, /* XXX */
|
|
|
|
pci_chipset_tag_t, int, int);
|
2000-03-22 23:58:25 +03:00
|
|
|
|
2004-08-22 03:48:33 +04:00
|
|
|
static int ne_pci_isipkdb(pci_chipset_tag_t, pcitag_t);
|
2000-03-22 23:58:25 +03:00
|
|
|
#endif
|
|
|
|
|
2004-08-22 03:48:33 +04:00
|
|
|
static const struct ne_pci_product {
|
1998-10-27 22:49:37 +03:00
|
|
|
pci_vendor_id_t npp_vendor;
|
|
|
|
pci_product_id_t npp_product;
|
2004-08-22 03:48:33 +04:00
|
|
|
int (*npp_mediachange)(struct dp8390_softc *);
|
|
|
|
void (*npp_mediastatus)(struct dp8390_softc *, struct ifmediareq *);
|
|
|
|
void (*npp_init_card)(struct dp8390_softc *);
|
|
|
|
void (*npp_media_init)(struct dp8390_softc *);
|
1998-10-27 22:49:37 +03:00
|
|
|
const char *npp_name;
|
|
|
|
} ne_pci_products[] = {
|
1998-10-28 03:15:54 +03:00
|
|
|
{ PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_RT8029,
|
1998-10-31 03:45:48 +03:00
|
|
|
rtl80x9_mediachange, rtl80x9_mediastatus,
|
2001-02-12 21:49:03 +03:00
|
|
|
rtl80x9_init_card, rtl80x9_media_init,
|
2004-02-13 13:00:54 +03:00
|
|
|
"Realtek 8029" },
|
1998-10-28 03:15:54 +03:00
|
|
|
|
|
|
|
{ PCI_VENDOR_WINBOND, PCI_PRODUCT_WINBOND_W89C940F,
|
|
|
|
NULL, NULL,
|
|
|
|
NULL, NULL,
|
1998-10-27 22:49:37 +03:00
|
|
|
"Winbond 89C940F" },
|
|
|
|
|
2000-03-06 06:07:08 +03:00
|
|
|
{ PCI_VENDOR_WINBOND, PCI_PRODUCT_WINBOND_W89C940F_1,
|
|
|
|
NULL, NULL,
|
|
|
|
NULL, NULL,
|
|
|
|
"Winbond 89C940F" },
|
|
|
|
|
1998-10-28 03:15:54 +03:00
|
|
|
{ PCI_VENDOR_VIATECH, PCI_PRODUCT_VIATECH_VT86C926,
|
|
|
|
NULL, NULL,
|
|
|
|
NULL, NULL,
|
1998-10-27 22:49:37 +03:00
|
|
|
"VIA Technologies VT86C926" },
|
|
|
|
|
1998-10-28 03:15:54 +03:00
|
|
|
{ PCI_VENDOR_SURECOM, PCI_PRODUCT_SURECOM_NE34,
|
|
|
|
NULL, NULL,
|
|
|
|
NULL, NULL,
|
1998-10-27 22:49:37 +03:00
|
|
|
"Surecom NE-34" },
|
|
|
|
|
1998-10-28 03:15:54 +03:00
|
|
|
{ PCI_VENDOR_NETVIN, PCI_PRODUCT_NETVIN_5000,
|
|
|
|
NULL, NULL,
|
|
|
|
NULL, NULL,
|
1998-10-27 22:49:37 +03:00
|
|
|
"NetVin 5000" },
|
1998-04-10 05:28:59 +04:00
|
|
|
|
1998-05-05 21:23:08 +04:00
|
|
|
/* XXX The following entries need sanity checking in pcidevs */
|
1998-10-28 03:15:54 +03:00
|
|
|
{ PCI_VENDOR_COMPEX, PCI_PRODUCT_COMPEX_NE2KETHER,
|
|
|
|
NULL, NULL,
|
|
|
|
NULL, NULL,
|
1998-10-27 22:49:37 +03:00
|
|
|
"Compex" },
|
|
|
|
|
1998-10-28 03:15:54 +03:00
|
|
|
{ PCI_VENDOR_PROLAN, PCI_PRODUCT_PROLAN_NE2KETHER,
|
|
|
|
NULL, NULL,
|
|
|
|
NULL, NULL,
|
1998-10-27 22:49:37 +03:00
|
|
|
"ProLAN" },
|
|
|
|
|
1998-10-28 03:15:54 +03:00
|
|
|
{ PCI_VENDOR_KTI, PCI_PRODUCT_KTI_NE2KETHER,
|
|
|
|
NULL, NULL,
|
|
|
|
NULL, NULL,
|
1998-10-27 22:49:37 +03:00
|
|
|
"KTI" },
|
|
|
|
|
1998-10-28 03:15:54 +03:00
|
|
|
{ 0, 0,
|
|
|
|
NULL, NULL,
|
|
|
|
NULL, NULL,
|
1998-10-27 22:49:37 +03:00
|
|
|
NULL },
|
1998-04-10 05:28:59 +04:00
|
|
|
};
|
|
|
|
|
2004-08-22 03:48:33 +04:00
|
|
|
static const struct ne_pci_product *
|
|
|
|
ne_pci_lookup(const struct pci_attach_args *pa)
|
1998-04-10 05:28:59 +04:00
|
|
|
{
|
1998-10-27 22:49:37 +03:00
|
|
|
const struct ne_pci_product *npp;
|
1998-04-10 05:28:59 +04:00
|
|
|
|
1998-10-27 22:49:37 +03:00
|
|
|
for (npp = ne_pci_products; npp->npp_name != NULL; npp++) {
|
|
|
|
if (PCI_VENDOR(pa->pa_id) == npp->npp_vendor &&
|
|
|
|
PCI_PRODUCT(pa->pa_id) == npp->npp_product)
|
|
|
|
return (npp);
|
1998-04-10 05:28:59 +04:00
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
1997-10-15 03:12:17 +04:00
|
|
|
/*
|
|
|
|
* PCI constants.
|
|
|
|
* XXX These should be in a common file!
|
|
|
|
*/
|
2011-07-27 00:51:23 +04:00
|
|
|
#define PCI_CBIO PCI_BAR(0) /* Configuration Base IO Address */
|
1997-10-15 03:12:17 +04:00
|
|
|
|
2004-08-22 03:48:33 +04:00
|
|
|
static int
|
2009-05-06 14:34:32 +04:00
|
|
|
ne_pci_match(device_t parent, cfdata_t match, void *aux)
|
1997-10-15 03:12:17 +04:00
|
|
|
{
|
|
|
|
struct pci_attach_args *pa = aux;
|
|
|
|
|
1998-10-27 22:49:37 +03:00
|
|
|
if (ne_pci_lookup(pa) != NULL)
|
1998-04-10 05:28:59 +04:00
|
|
|
return (1);
|
1997-10-15 03:12:17 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-08-22 03:48:33 +04:00
|
|
|
static void
|
2009-05-06 14:34:32 +04:00
|
|
|
ne_pci_attach(device_t parent, device_t self, void *aux)
|
1997-10-15 03:12:17 +04:00
|
|
|
{
|
2008-03-12 17:31:11 +03:00
|
|
|
struct ne_pci_softc *psc = device_private(self);
|
1997-10-15 03:12:17 +04:00
|
|
|
struct ne2000_softc *nsc = &psc->sc_ne2000;
|
|
|
|
struct dp8390_softc *dsc = &nsc->sc_dp8390;
|
|
|
|
struct pci_attach_args *pa = aux;
|
|
|
|
pci_chipset_tag_t pc = pa->pa_pc;
|
|
|
|
bus_space_tag_t nict;
|
|
|
|
bus_space_handle_t nich;
|
|
|
|
bus_space_tag_t asict;
|
|
|
|
bus_space_handle_t asich;
|
1998-10-27 22:49:37 +03:00
|
|
|
const char *intrstr;
|
|
|
|
const struct ne_pci_product *npp;
|
1997-10-15 03:12:17 +04:00
|
|
|
pci_intr_handle_t ih;
|
|
|
|
pcireg_t csr;
|
|
|
|
|
1998-10-27 22:49:37 +03:00
|
|
|
npp = ne_pci_lookup(pa);
|
|
|
|
if (npp == NULL) {
|
|
|
|
printf("\n");
|
|
|
|
panic("ne_pci_attach: impossible");
|
1997-10-15 03:12:17 +04:00
|
|
|
}
|
|
|
|
|
2008-03-12 17:31:11 +03:00
|
|
|
dsc->sc_dev = self;
|
|
|
|
|
1998-10-27 22:49:37 +03:00
|
|
|
printf(": %s Ethernet\n", npp->npp_name);
|
1997-10-15 03:12:17 +04:00
|
|
|
|
2000-03-22 23:58:25 +03:00
|
|
|
#ifdef IPKDB_NE_PCI
|
|
|
|
if (ne_pci_isipkdb(pc, pa->pa_tag)) {
|
|
|
|
nict = ipkdb_softc.sc_ne2000.sc_dp8390.sc_regt;
|
|
|
|
nich = ipkdb_softc.sc_ne2000.sc_dp8390.sc_regh;
|
|
|
|
ne_kip->port = nsc;
|
|
|
|
} else
|
|
|
|
#endif
|
1997-10-15 03:12:17 +04:00
|
|
|
if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
|
|
|
|
&nict, &nich, NULL, NULL)) {
|
2008-03-12 17:31:11 +03:00
|
|
|
aprint_error_dev(dsc->sc_dev, "can't map i/o space\n");
|
1997-10-15 03:12:17 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
asict = nict;
|
|
|
|
if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
|
|
|
|
NE2000_ASIC_NPORTS, &asich)) {
|
2008-03-12 17:31:11 +03:00
|
|
|
aprint_error_dev(dsc->sc_dev, "can't subregion i/o space\n");
|
1997-10-15 03:12:17 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dsc->sc_regt = nict;
|
|
|
|
dsc->sc_regh = nich;
|
|
|
|
|
|
|
|
nsc->sc_asict = asict;
|
|
|
|
nsc->sc_asich = asich;
|
|
|
|
|
|
|
|
/* Enable the card. */
|
|
|
|
csr = pci_conf_read(pc, pa->pa_tag,
|
|
|
|
PCI_COMMAND_STATUS_REG);
|
|
|
|
pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
|
|
|
|
csr | PCI_COMMAND_MASTER_ENABLE);
|
|
|
|
|
|
|
|
/* This interface is always enabled. */
|
|
|
|
dsc->sc_enabled = 1;
|
|
|
|
|
2001-02-12 21:49:03 +03:00
|
|
|
dsc->sc_mediachange = npp->npp_mediachange;
|
|
|
|
dsc->sc_mediastatus = npp->npp_mediastatus;
|
|
|
|
dsc->sc_media_init = npp->npp_media_init;
|
1998-10-28 03:15:54 +03:00
|
|
|
dsc->init_card = npp->npp_init_card;
|
|
|
|
|
1997-10-15 03:12:17 +04:00
|
|
|
/*
|
|
|
|
* 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:12:17 +04:00
|
|
|
|
|
|
|
/* Map and establish the interrupt. */
|
2000-12-29 01:59:06 +03:00
|
|
|
if (pci_intr_map(pa, &ih)) {
|
2008-03-12 17:31:11 +03:00
|
|
|
aprint_error_dev(dsc->sc_dev, "couldn't map interrupt\n");
|
1997-10-15 03:12:17 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
intrstr = pci_intr_string(pc, ih);
|
|
|
|
psc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, dp8390_intr, dsc);
|
|
|
|
if (psc->sc_ih == NULL) {
|
2008-03-12 17:31:11 +03:00
|
|
|
aprint_error_dev(dsc->sc_dev, "couldn't establish interrupt");
|
1997-10-15 03:12:17 +04:00
|
|
|
if (intrstr != NULL)
|
2008-03-12 17:31:11 +03:00
|
|
|
aprint_error(" at %s", intrstr);
|
|
|
|
aprint_error("\n");
|
1997-10-15 03:12:17 +04:00
|
|
|
return;
|
|
|
|
}
|
2008-03-12 17:31:11 +03:00
|
|
|
aprint_normal_dev(dsc->sc_dev, "interrupting at %s\n", intrstr);
|
1997-10-15 03:12:17 +04:00
|
|
|
}
|
2000-03-22 23:58:25 +03:00
|
|
|
|
|
|
|
#ifdef IPKDB_NE_PCI
|
|
|
|
static int
|
2004-08-22 03:48:33 +04:00
|
|
|
ne_pci_isipkdb(pci_chipset_tag_t pc, pcitag_t tag)
|
2000-03-22 23:58:25 +03:00
|
|
|
{
|
|
|
|
return !memcmp(&pc, &ipkdb_pc, sizeof pc)
|
|
|
|
&& !memcmp(&tag, &ipkdb_tag, sizeof tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-08-22 03:48:33 +04:00
|
|
|
ne_pci_ipkdb_attach(struct ipkdb_if *kip, bus_space_tag_t iot,
|
|
|
|
pci_chipset_tag_t pc, int bus, int dev)
|
2000-03-22 23:58:25 +03:00
|
|
|
{
|
|
|
|
struct pci_attach_args pa;
|
|
|
|
bus_space_tag_t nict, asict;
|
|
|
|
bus_space_handle_t nich, asich;
|
|
|
|
u_int32_t csr;
|
|
|
|
|
|
|
|
pa.pa_iot = iot;
|
|
|
|
pa.pa_pc = pc;
|
|
|
|
pa.pa_device = dev;
|
|
|
|
pa.pa_function = 0;
|
2011-05-17 21:34:47 +04:00
|
|
|
pa.pa_flags = PCI_FLAGS_IO_OKAY;
|
2000-03-22 23:58:25 +03:00
|
|
|
pa.pa_tag = pci_make_tag(pc, bus, dev, /*func*/0);
|
|
|
|
pa.pa_id = pci_conf_read(pc, pa.pa_tag, PCI_ID_REG);
|
|
|
|
pa.pa_class = pci_conf_read(pc, pa.pa_tag, PCI_CLASS_REG);
|
|
|
|
if (ne_pci_lookup(&pa) == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (pci_mapreg_map(&pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
|
|
|
|
&nict, &nich, NULL, NULL))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
asict = nict;
|
|
|
|
if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
|
|
|
|
NE2000_ASIC_NPORTS, &asich)) {
|
|
|
|
bus_space_unmap(nict, nich, NE2000_NPORTS);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable card */
|
|
|
|
csr = pci_conf_read(pc, pa.pa_tag, PCI_COMMAND_STATUS_REG);
|
|
|
|
pci_conf_write(pc, pa.pa_tag, PCI_COMMAND_STATUS_REG,
|
|
|
|
csr | PCI_COMMAND_MASTER_ENABLE);
|
|
|
|
|
|
|
|
ipkdb_softc.sc_ne2000.sc_dp8390.sc_regt = nict;
|
|
|
|
ipkdb_softc.sc_ne2000.sc_dp8390.sc_regh = nich;
|
|
|
|
ipkdb_softc.sc_ne2000.sc_asict = asict;
|
|
|
|
ipkdb_softc.sc_ne2000.sc_asich = asich;
|
|
|
|
|
|
|
|
kip->port = &ipkdb_softc;
|
|
|
|
ipkdb_pc = pc;
|
|
|
|
ipkdb_tag = pa.pa_tag;
|
|
|
|
ne_kip = kip;
|
|
|
|
|
|
|
|
if (ne2000_ipkdb_attach(kip) < 0) {
|
|
|
|
bus_space_unmap(nict, nich, NE2000_NPORTS);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2004-08-22 03:48:33 +04:00
|
|
|
#endif /* IPKDB_NE_PCI */
|