2001-11-13 10:48:40 +03:00
|
|
|
/* $NetBSD: if_gem_pci.c,v 1.8 2001/11/13 07:48:43 lukem Exp $ */
|
2001-09-16 04:11:41 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright (C) 2001 Eduardo Horvath.
|
|
|
|
* 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. 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 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PCI bindings for Sun GEM ethernet controllers.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 10:48:40 +03:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__KERNEL_RCSID(0, "$NetBSD: if_gem_pci.c,v 1.8 2001/11/13 07:48:43 lukem Exp $");
|
|
|
|
|
2001-09-16 04:11:41 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
|
|
|
|
#include <machine/endian.h>
|
|
|
|
|
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/intr.h>
|
|
|
|
|
|
|
|
#include <dev/mii/mii.h>
|
|
|
|
#include <dev/mii/miivar.h>
|
|
|
|
#include <dev/mii/mii_bitbang.h>
|
|
|
|
|
|
|
|
#include <dev/ic/gemreg.h>
|
|
|
|
#include <dev/ic/gemvar.h>
|
|
|
|
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcidevs.h>
|
|
|
|
|
2001-10-18 07:55:07 +04:00
|
|
|
/* XXX Should use Properties when that's fleshed out. */
|
|
|
|
#ifdef macppc
|
|
|
|
#include <dev/ofw/openfirm.h>
|
|
|
|
#endif /* macppc */
|
|
|
|
|
2001-09-16 04:11:41 +04:00
|
|
|
struct gem_pci_softc {
|
|
|
|
struct gem_softc gsc_gem; /* GEM device */
|
|
|
|
void *gsc_ih;
|
|
|
|
};
|
|
|
|
|
|
|
|
int gem_match_pci __P((struct device *, struct cfdata *, void *));
|
|
|
|
void gem_attach_pci __P((struct device *, struct device *, void *));
|
|
|
|
|
|
|
|
struct cfattach gem_pci_ca = {
|
|
|
|
sizeof(struct gem_pci_softc), gem_match_pci, gem_attach_pci
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach routines need to be split out to different bus-specific files.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
gem_match_pci(parent, cf, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *cf;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct pci_attach_args *pa = aux;
|
|
|
|
|
|
|
|
if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SUN &&
|
|
|
|
(PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_ERINETWORK ||
|
|
|
|
PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_GEMNETWORK))
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_APPLE &&
|
|
|
|
(PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_GMAC ||
|
|
|
|
PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_GMAC2))
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gem_attach_pci(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct pci_attach_args *pa = aux;
|
|
|
|
struct gem_pci_softc *gsc = (void *)self;
|
|
|
|
struct gem_softc *sc = &gsc->gsc_gem;
|
2001-10-18 10:28:17 +04:00
|
|
|
pci_intr_handle_t ih;
|
2001-09-16 04:11:41 +04:00
|
|
|
const char *intrstr;
|
2001-09-24 08:39:40 +04:00
|
|
|
char devinfo[256];
|
2001-10-18 19:09:15 +04:00
|
|
|
uint8_t enaddr[ETHER_ADDR_LEN];
|
2001-09-24 08:39:40 +04:00
|
|
|
|
|
|
|
pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
|
|
|
|
printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
|
2001-09-16 04:11:41 +04:00
|
|
|
|
|
|
|
sc->sc_dmatag = pa->pa_dmat;
|
|
|
|
|
2001-10-18 10:28:17 +04:00
|
|
|
sc->sc_pci = 1; /* XXX */
|
2001-09-16 04:11:41 +04:00
|
|
|
|
2001-10-18 07:48:48 +04:00
|
|
|
#define PCI_GEM_BASEADDR (PCI_MAPREG_START + 0x00)
|
|
|
|
|
|
|
|
/* XXX Need to check for a 64-bit mem BAR? */
|
|
|
|
if (pci_mapreg_map(pa, PCI_GEM_BASEADDR,
|
|
|
|
PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0,
|
2001-10-18 10:14:33 +04:00
|
|
|
&sc->sc_bustag, &sc->sc_h, NULL, NULL) != 0)
|
2001-09-16 04:11:41 +04:00
|
|
|
{
|
2001-10-18 10:28:17 +04:00
|
|
|
printf("%s: unable to map device registers\n",
|
2001-10-18 07:48:48 +04:00
|
|
|
sc->sc_dev.dv_xname);
|
2001-09-16 04:11:41 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-10-18 07:48:48 +04:00
|
|
|
/*
|
|
|
|
* XXX This should be done with properties, when those are
|
|
|
|
* XXX fleshed out.
|
|
|
|
*/
|
2001-09-16 04:11:41 +04:00
|
|
|
#ifdef __sparc__
|
2001-10-18 07:48:48 +04:00
|
|
|
{
|
|
|
|
extern void myetheraddr __P((u_char *));
|
2001-10-18 19:09:15 +04:00
|
|
|
myetheraddr(enaddr);
|
2001-10-18 07:48:48 +04:00
|
|
|
}
|
2001-10-18 07:55:07 +04:00
|
|
|
#endif /* __sparc__ */
|
|
|
|
#ifdef macppc
|
|
|
|
{
|
|
|
|
int node;
|
|
|
|
|
|
|
|
node = pcidev_to_ofdev(pa->pa_pc, pa->pa_tag);
|
|
|
|
if (node == 0) {
|
|
|
|
printf("%s: unable to locate OpenFirmware node\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-10-18 19:09:15 +04:00
|
|
|
OF_getprop(node, "local-mac-address", enaddr, sizeof(enaddr));
|
2001-10-18 07:55:07 +04:00
|
|
|
}
|
|
|
|
#endif /* macppc */
|
2001-09-16 04:11:41 +04:00
|
|
|
|
2001-10-18 10:28:17 +04:00
|
|
|
if (pci_intr_map(pa, &ih) != 0) {
|
|
|
|
printf("%s: unable to map interrupt\n", sc->sc_dev.dv_xname);
|
|
|
|
return;
|
2001-09-16 04:11:41 +04:00
|
|
|
}
|
2001-10-18 10:28:17 +04:00
|
|
|
intrstr = pci_intr_string(pa->pa_pc, ih);
|
|
|
|
gsc->gsc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_NET, gem_intr, sc);
|
|
|
|
if (gsc->gsc_ih == NULL) {
|
|
|
|
printf("%s: unable to establish interrupt",
|
2001-09-16 04:11:41 +04:00
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
if (intrstr != NULL)
|
|
|
|
printf(" at %s", intrstr);
|
|
|
|
printf("\n");
|
2001-10-18 07:48:48 +04:00
|
|
|
return;
|
2001-09-16 04:11:41 +04:00
|
|
|
}
|
2001-10-18 10:28:17 +04:00
|
|
|
printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
|
|
|
|
|
2001-10-18 19:09:15 +04:00
|
|
|
/* Finish off the attach. */
|
|
|
|
gem_attach(sc, enaddr);
|
2001-09-16 04:11:41 +04:00
|
|
|
}
|