2002-10-02 20:51:16 +04:00
|
|
|
/* $NetBSD: if_rtk_pci.c,v 1.15 2002/10/02 16:51:28 thorpej Exp $ */
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1997, 1998
|
|
|
|
* Bill Paul <wpaul@ctr.columbia.edu>. 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Bill Paul.
|
|
|
|
* 4. Neither the name of the author nor the names of any co-contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY Bill Paul 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 Bill Paul OR THE VOICES IN HIS HEAD
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* FreeBSD Id: if_rl.c,v 1.17 1999/06/19 20:17:37 wpaul Exp
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RealTek 8129/8139 PCI NIC driver
|
|
|
|
*
|
|
|
|
* Supports several extremely cheap PCI 10/100 adapters based on
|
|
|
|
* the RealTek chipset. Datasheets can be obtained from
|
|
|
|
* www.realtek.com.tw.
|
|
|
|
*
|
|
|
|
* Written by Bill Paul <wpaul@ctr.columbia.edu>
|
|
|
|
* Electrical Engineering Department
|
|
|
|
* Columbia University, New York City
|
|
|
|
*/
|
|
|
|
|
2001-11-13 10:48:40 +03:00
|
|
|
#include <sys/cdefs.h>
|
2002-10-02 20:51:16 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: if_rtk_pci.c,v 1.15 2002/10/02 16:51:28 thorpej Exp $");
|
2001-11-13 10:48:40 +03:00
|
|
|
|
2000-04-10 11:42:55 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/callout.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_arp.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_media.h>
|
2001-06-13 02:28:15 +04:00
|
|
|
|
2000-04-10 11:42:55 +04:00
|
|
|
#include <machine/bus.h>
|
|
|
|
|
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/pci/pcidevs.h>
|
|
|
|
|
|
|
|
#include <dev/mii/mii.h>
|
|
|
|
#include <dev/mii/miivar.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Default to using PIO access for this driver. On SMP systems,
|
|
|
|
* there appear to be problems with memory mapped mode: it looks like
|
|
|
|
* doing too many memory mapped access back to back in rapid succession
|
|
|
|
* can hang the bus. I'm inclined to blame this on crummy design/construction
|
|
|
|
* on the part of RealTek. Memory mapped mode does appear to work on
|
|
|
|
* uniprocessor systems though.
|
|
|
|
*/
|
2001-01-31 10:44:04 +03:00
|
|
|
#ifndef dreamcast /* XXX */
|
2000-05-19 17:42:29 +04:00
|
|
|
#define RTK_USEIOSPACE
|
2001-01-31 10:44:04 +03:00
|
|
|
#endif
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
#include <dev/ic/rtl81x9reg.h>
|
2000-04-26 18:02:34 +04:00
|
|
|
#include <dev/ic/rtl81x9var.h>
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
struct rtk_pci_softc {
|
|
|
|
struct rtk_softc sc_rtk; /* real rtk softc */
|
2002-02-06 15:43:05 +03:00
|
|
|
|
2000-04-10 11:42:55 +04:00
|
|
|
/* PCI-specific goo.*/
|
|
|
|
void *sc_ih;
|
|
|
|
pci_chipset_tag_t sc_pc; /* PCI chipset */
|
|
|
|
pcitag_t sc_pcitag; /* PCI tag */
|
|
|
|
};
|
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
static const struct rtk_type rtk_pci_devs[] = {
|
2000-04-10 11:42:55 +04:00
|
|
|
{ PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_RT8129,
|
2000-05-15 05:55:12 +04:00
|
|
|
"RealTek 8129 10/100BaseTX",
|
2000-05-19 17:42:29 +04:00
|
|
|
RTK_8129 },
|
2000-04-10 11:42:55 +04:00
|
|
|
{ PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_RT8139,
|
2000-05-15 05:55:12 +04:00
|
|
|
"RealTek 8139 10/100BaseTX",
|
2000-05-19 17:42:29 +04:00
|
|
|
RTK_8139 },
|
2000-04-10 11:42:55 +04:00
|
|
|
{ PCI_VENDOR_ACCTON, PCI_PRODUCT_ACCTON_MPX5030,
|
2000-05-15 05:55:12 +04:00
|
|
|
"Accton MPX 5030/5038 10/100BaseTX",
|
2000-05-19 17:42:29 +04:00
|
|
|
RTK_8139 },
|
2000-04-10 11:42:55 +04:00
|
|
|
{ PCI_VENDOR_DELTA, PCI_PRODUCT_DELTA_8139,
|
2000-05-15 05:55:12 +04:00
|
|
|
"Delta Electronics 8139 10/100BaseTX",
|
2000-05-19 17:42:29 +04:00
|
|
|
RTK_8139 },
|
2000-04-10 11:42:55 +04:00
|
|
|
{ PCI_VENDOR_ADDTRON, PCI_PRODUCT_ADDTRON_8139,
|
2000-05-15 05:55:12 +04:00
|
|
|
"Addtron Technology 8139 10/100BaseTX",
|
2000-05-19 17:42:29 +04:00
|
|
|
RTK_8139 },
|
2001-01-31 10:44:04 +03:00
|
|
|
{ PCI_VENDOR_SEGA, PCI_PRODUCT_SEGA_BROADBAND,
|
|
|
|
"SEGA Broadband Adapter",
|
|
|
|
RTK_8139 },
|
2001-07-18 05:10:09 +04:00
|
|
|
{ PCI_VENDOR_DLINK, PCI_PRODUCT_DLINK_DFE530TXPLUS,
|
2001-06-11 10:36:23 +04:00
|
|
|
"D-Link Systems DFE 530TX+",
|
|
|
|
RTK_8139 },
|
2000-05-15 05:55:12 +04:00
|
|
|
{ 0, 0, NULL, 0 }
|
2000-04-10 11:42:55 +04:00
|
|
|
};
|
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
const struct rtk_type *rtk_pci_lookup __P((const struct pci_attach_args *));
|
|
|
|
|
|
|
|
int rtk_pci_match __P((struct device *, struct cfdata *, void *));
|
|
|
|
void rtk_pci_attach __P((struct device *, struct device *, void *));
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2002-10-01 00:37:04 +04:00
|
|
|
CFATTACH_DECL(rtk_pci, sizeof(struct rtk_pci_softc),
|
2002-10-02 20:51:16 +04:00
|
|
|
rtk_pci_match, rtk_pci_attach, NULL, NULL);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
const struct rtk_type *
|
|
|
|
rtk_pci_lookup(pa)
|
2000-04-10 11:42:55 +04:00
|
|
|
const struct pci_attach_args *pa;
|
|
|
|
{
|
2000-05-15 05:55:12 +04:00
|
|
|
const struct rtk_type *t;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2002-02-06 15:43:05 +03:00
|
|
|
for (t = rtk_pci_devs; t->rtk_name != NULL; t++) {
|
2000-05-15 05:55:12 +04:00
|
|
|
if (PCI_VENDOR(pa->pa_id) == t->rtk_vid &&
|
|
|
|
PCI_PRODUCT(pa->pa_id) == t->rtk_did) {
|
2000-04-10 11:42:55 +04:00
|
|
|
return (t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-05-15 05:55:12 +04:00
|
|
|
rtk_pci_match(parent, match, aux)
|
2000-04-10 11:42:55 +04:00
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *match;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct pci_attach_args *pa = aux;
|
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
if (rtk_pci_lookup(pa) != NULL)
|
2000-04-10 11:42:55 +04:00
|
|
|
return (1);
|
2000-05-15 05:55:12 +04:00
|
|
|
|
2000-04-10 11:42:55 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach the interface. Allocate softc structures, do ifmedia
|
|
|
|
* setup and ethernet/BPF attach.
|
|
|
|
*/
|
|
|
|
void
|
2000-05-15 05:55:12 +04:00
|
|
|
rtk_pci_attach(parent, self, aux)
|
2000-04-10 11:42:55 +04:00
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
2000-05-15 05:55:12 +04:00
|
|
|
struct rtk_pci_softc *psc = (struct rtk_pci_softc *)self;
|
|
|
|
struct rtk_softc *sc = &psc->sc_rtk;
|
|
|
|
pcireg_t command;
|
2000-04-10 11:42:55 +04:00
|
|
|
struct pci_attach_args *pa = aux;
|
|
|
|
pci_chipset_tag_t pc = pa->pa_pc;
|
|
|
|
pci_intr_handle_t ih;
|
|
|
|
const char *intrstr = NULL;
|
2000-05-15 05:55:12 +04:00
|
|
|
const struct rtk_type *t;
|
|
|
|
int pmreg;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
psc->sc_pc = pa->pa_pc;
|
|
|
|
psc->sc_pcitag = pa->pa_tag;
|
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
t = rtk_pci_lookup(pa);
|
2000-05-01 19:08:50 +04:00
|
|
|
if (t == NULL) {
|
|
|
|
printf("\n");
|
2000-05-15 05:55:12 +04:00
|
|
|
panic("rtk_pci_attach: impossible");
|
2000-05-01 19:08:50 +04:00
|
|
|
}
|
2000-05-15 05:55:12 +04:00
|
|
|
printf(": %s\n", t->rtk_name);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle power management nonsense.
|
|
|
|
*/
|
|
|
|
|
2000-04-24 19:25:00 +04:00
|
|
|
if (pci_get_capability(pc, pa->pa_tag, PCI_CAP_PWRMGMT, &pmreg, 0)) {
|
|
|
|
command = pci_conf_read(pc, pa->pa_tag, pmreg + 4);
|
2000-05-19 17:42:29 +04:00
|
|
|
if (command & RTK_PSTATE_MASK) {
|
2000-05-15 05:55:12 +04:00
|
|
|
pcireg_t iobase, membase, irq;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/* Save important PCI config data. */
|
2000-05-19 17:42:29 +04:00
|
|
|
iobase = pci_conf_read(pc, pa->pa_tag, RTK_PCI_LOIO);
|
|
|
|
membase = pci_conf_read(pc, pa->pa_tag, RTK_PCI_LOMEM);
|
2000-05-01 19:08:50 +04:00
|
|
|
irq = pci_conf_read(pc, pa->pa_tag,
|
2002-02-06 15:43:05 +03:00
|
|
|
PCI_PRODUCT_DELTA_8139);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/* Reset the power state. */
|
|
|
|
printf("%s: chip is is in D%d power mode "
|
2002-02-06 15:43:05 +03:00
|
|
|
"-- setting to D0\n", sc->sc_dev.dv_xname,
|
|
|
|
command & RTK_PSTATE_MASK);
|
2000-04-10 11:42:55 +04:00
|
|
|
command &= 0xFFFFFFFC;
|
2000-04-24 19:25:00 +04:00
|
|
|
pci_conf_write(pc, pa->pa_tag, pmreg + 4, command);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/* Restore PCI config data. */
|
2000-05-19 17:42:29 +04:00
|
|
|
pci_conf_write(pc, pa->pa_tag, RTK_PCI_LOIO, iobase);
|
|
|
|
pci_conf_write(pc, pa->pa_tag, RTK_PCI_LOMEM, membase);
|
2000-05-01 19:08:50 +04:00
|
|
|
pci_conf_write(pc, pa->pa_tag,
|
2002-02-06 15:43:05 +03:00
|
|
|
PCI_PRODUCT_DELTA_8139, irq);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Map control/status registers.
|
|
|
|
*/
|
2000-05-19 17:42:29 +04:00
|
|
|
#ifdef RTK_USEIOSPACE
|
|
|
|
if (pci_mapreg_map(pa, RTK_PCI_LOIO, PCI_MAPREG_TYPE_IO, 0,
|
2000-05-15 05:55:12 +04:00
|
|
|
&sc->rtk_btag, &sc->rtk_bhandle, NULL, NULL)) {
|
2000-05-01 19:08:50 +04:00
|
|
|
printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
|
2000-05-15 05:55:12 +04:00
|
|
|
return;
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
#else
|
2000-05-19 17:42:29 +04:00
|
|
|
if (pci_mapreg_map(pa, RTK_PCI_LOMEM, PCI_MAPREG_TYPE_MEM, 0,
|
2000-05-15 05:55:12 +04:00
|
|
|
&sc->rtk_btag, &sc->rtk_bhandle, NULL, NULL)) {
|
2001-01-31 10:44:04 +03:00
|
|
|
printf("%s: can't map mem space\n", sc->sc_dev.dv_xname);
|
2000-05-15 05:55:12 +04:00
|
|
|
return;
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Allocate interrupt */
|
2000-12-29 01:59:06 +03:00
|
|
|
if (pci_intr_map(pa, &ih)) {
|
2000-04-10 11:42:55 +04:00
|
|
|
printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
|
2000-05-15 05:55:12 +04:00
|
|
|
return;
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
intrstr = pci_intr_string(pc, ih);
|
2000-05-15 05:55:12 +04:00
|
|
|
psc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, rtk_intr, sc);
|
2000-04-10 11:42:55 +04:00
|
|
|
if (psc->sc_ih == NULL) {
|
|
|
|
printf("%s: couldn't establish interrupt",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
if (intrstr != NULL)
|
|
|
|
printf(" at %s", intrstr);
|
|
|
|
printf("\n");
|
2000-05-15 05:55:12 +04:00
|
|
|
return;
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
sc->rtk_type = t->rtk_type;
|
|
|
|
|
2000-04-10 11:42:55 +04:00
|
|
|
printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
|
|
|
|
|
|
|
|
sc->sc_dmat = pa->pa_dmat;
|
2002-02-06 15:43:05 +03:00
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
rtk_attach(sc);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|