#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <net/if.h>
#include <net/if_media.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <machine/bus.h>
#include <machine/intr.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcidevs.h>
#include <dev/mii/miivar.h>
#include <dev/ic/dp8390reg.h>
#include <dev/ic/dp8390var.h>
#include <dev/ic/ne2000reg.h>
#include <dev/ic/ne2000var.h>
#include <dev/ic/rtl80x9reg.h>
#include <dev/ic/rtl80x9var.h>
struct ne_pci_softc {
struct ne2000_softc sc_ne2000;
void *sc_ih;
};
int ne_pci_match(struct device *, void *, void *);
void ne_pci_attach(struct device *, struct device *, void *);
const struct cfattach ne_pci_ca = {
sizeof(struct ne_pci_softc), ne_pci_match, ne_pci_attach
};
const struct ne_pci_product {
pci_vendor_id_t npp_vendor;
pci_product_id_t npp_product;
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 *);
} ne_pci_prod[] = {
{ PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_RT8029,
rtl80x9_mediachange, rtl80x9_mediastatus,
rtl80x9_init_card, rtl80x9_media_init,
},
{ PCI_VENDOR_WINBOND, PCI_PRODUCT_WINBOND_W89C940F,
NULL, NULL,
NULL, NULL,
},
{ PCI_VENDOR_VIATECH, PCI_PRODUCT_VIATECH_VT86C926,
NULL, NULL,
NULL, NULL,
},
{ PCI_VENDOR_SURECOM, PCI_PRODUCT_SURECOM_NE34,
NULL, NULL,
NULL, NULL,
},
{ PCI_VENDOR_NETVIN, PCI_PRODUCT_NETVIN_NV5000,
NULL, NULL,
NULL, NULL,
},
{ PCI_VENDOR_COMPEX, PCI_PRODUCT_COMPEX_COMPEXE,
NULL, NULL,
NULL, NULL,
},
{ PCI_VENDOR_WINBOND2, PCI_PRODUCT_WINBOND2_W89C940,
NULL, NULL,
NULL, NULL,
},
{ PCI_VENDOR_KTI, PCI_PRODUCT_KTI_KTIE,
NULL, NULL,
NULL, NULL,
},
};
const struct ne_pci_product *ne_pci_lookup(struct pci_attach_args *);
const struct ne_pci_product *
ne_pci_lookup(struct pci_attach_args *pa)
{
const struct ne_pci_product *npp;
for (npp = ne_pci_prod;
npp < &ne_pci_prod[nitems(ne_pci_prod)];
npp++) {
if (PCI_VENDOR(pa->pa_id) == npp->npp_vendor &&
PCI_PRODUCT(pa->pa_id) == npp->npp_product)
return (npp);
}
return (NULL);
}
#define PCI_CBIO 0x10
int
ne_pci_match(struct device *parent, void *match, void *aux)
{
struct pci_attach_args *pa = aux;
if (ne_pci_lookup(pa) != NULL)
return (1);
return (0);
}
void
ne_pci_attach(struct device *parent, struct device *self, void *aux)
{
struct ne_pci_softc *psc = (struct ne_pci_softc *)self;
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_size_t iosize;
bus_space_tag_t nict;
bus_space_handle_t nich;
bus_space_tag_t asict;
bus_space_handle_t asich;
const char *intrstr;
const struct ne_pci_product *npp;
pci_intr_handle_t ih;
npp = ne_pci_lookup(pa);
if (npp == NULL) {
printf("\n");
panic("ne_pci_attach: impossible");
}
if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
&nict, &nich, NULL, &iosize, 0)) {
printf(": can't map i/o space\n");
return;
}
asict = nict;
if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
NE2000_ASIC_NPORTS, &asich)) {
printf(": can't subregion i/o space\n");
bus_space_unmap(nict, nich, iosize);
return;
}
dsc->sc_regt = nict;
dsc->sc_regh = nich;
nsc->sc_asict = asict;
nsc->sc_asich = asich;
dsc->sc_enabled = 1;
dsc->sc_mediachange = npp->npp_mediachange;
dsc->sc_mediastatus = npp->npp_mediastatus;
dsc->sc_media_init = npp->npp_media_init;
dsc->init_card = npp->npp_init_card;
if (pci_intr_map(pa, &ih)) {
printf(": couldn't map interrupt\n");
bus_space_unmap(nict, nich, iosize);
return;
}
intrstr = pci_intr_string(pc, ih);
psc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, dp8390_intr, dsc,
dsc->sc_dev.dv_xname);
if (psc->sc_ih == NULL) {
printf(": couldn't establish interrupt");
if (intrstr != NULL)
printf(" at %s", intrstr);
printf("\n");
bus_space_unmap(nict, nich, iosize);
return;
}
printf(": %s", intrstr);
ne2000_attach(nsc, NULL);
}