2006-03-29 10:22:38 +04:00
|
|
|
/* $NetBSD: if_tlp_cardbus.c,v 1.49 2006/03/29 06:22:38 thorpej Exp $ */
|
1999-11-19 21:23:35 +03:00
|
|
|
|
|
|
|
/*-
|
2000-01-26 00:50:30 +03:00
|
|
|
* Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
|
1999-11-19 21:23:35 +03: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.
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* CardBus bus front-end for the Digital Semiconductor ``Tulip'' (21x4x)
|
|
|
|
* Ethernet controller family driver.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 15:51:12 +03:00
|
|
|
#include <sys/cdefs.h>
|
2006-03-29 10:22:38 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: if_tlp_cardbus.c,v 1.49 2006/03/29 06:22:38 thorpej Exp $");
|
2001-11-13 15:51:12 +03:00
|
|
|
|
1999-11-19 21:23:35 +03:00
|
|
|
#include "opt_inet.h"
|
|
|
|
#include "opt_ns.h"
|
|
|
|
#include "bpfilter.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
2005-02-27 03:26:58 +03:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
1999-11-19 21:23:35 +03:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/device.h>
|
1999-12-11 03:32:59 +03:00
|
|
|
|
|
|
|
#include <machine/endian.h>
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1999-11-19 21:23:35 +03:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
#if NBPFILTER > 0
|
1999-11-19 21:23:35 +03:00
|
|
|
#include <net/bpf.h>
|
2005-02-27 03:26:58 +03:00
|
|
|
#endif
|
1999-11-19 21:23:35 +03:00
|
|
|
|
|
|
|
#ifdef INET
|
2005-02-27 03:26:58 +03:00
|
|
|
#include <netinet/in.h>
|
1999-11-19 21:23:35 +03:00
|
|
|
#include <netinet/if_inarp.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NS
|
|
|
|
#include <netns/ns.h>
|
|
|
|
#include <netns/ns_if.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/intr.h>
|
|
|
|
|
|
|
|
#include <dev/mii/miivar.h>
|
|
|
|
#include <dev/mii/mii_bitbang.h>
|
|
|
|
|
|
|
|
#include <dev/ic/tulipreg.h>
|
|
|
|
#include <dev/ic/tulipvar.h>
|
|
|
|
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcidevs.h>
|
|
|
|
|
|
|
|
#include <dev/cardbus/cardbusvar.h>
|
2004-08-02 23:31:52 +04:00
|
|
|
#include <dev/pci/pcidevs.h>
|
1999-11-19 21:23:35 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* PCI configuration space registers used by the Tulip.
|
|
|
|
*/
|
|
|
|
#define TULIP_PCI_IOBA 0x10 /* i/o mapped base */
|
|
|
|
#define TULIP_PCI_MMBA 0x14 /* memory mapped base */
|
|
|
|
#define TULIP_PCI_CFDA 0x40 /* configuration driver area */
|
|
|
|
|
|
|
|
#define CFDA_SLEEP 0x80000000 /* sleep mode */
|
1999-12-07 10:36:19 +03:00
|
|
|
#define CFDA_SNOOZE 0x40000000 /* snooze mode */
|
1999-11-19 21:23:35 +03:00
|
|
|
|
|
|
|
struct tulip_cardbus_softc {
|
|
|
|
struct tulip_softc sc_tulip; /* real Tulip softc */
|
|
|
|
|
|
|
|
/* CardBus-specific goo. */
|
|
|
|
void *sc_ih; /* interrupt handle */
|
|
|
|
cardbus_devfunc_t sc_ct; /* our CardBus devfuncs */
|
2000-03-10 09:55:09 +03:00
|
|
|
cardbustag_t sc_tag; /* our CardBus tag */
|
1999-11-19 21:23:35 +03:00
|
|
|
int sc_csr; /* CSR bits */
|
2000-03-10 09:55:09 +03:00
|
|
|
bus_size_t sc_mapsize; /* the size of mapped bus space
|
|
|
|
region */
|
2000-03-10 10:26:41 +03:00
|
|
|
|
|
|
|
int sc_cben; /* CardBus enables */
|
|
|
|
int sc_bar_reg; /* which BAR to use */
|
|
|
|
pcireg_t sc_bar_val; /* value of the BAR */
|
2000-03-15 21:39:50 +03:00
|
|
|
|
|
|
|
int sc_intrline; /* interrupt line */
|
1999-11-19 21:23:35 +03:00
|
|
|
};
|
|
|
|
|
2005-02-04 05:10:35 +03:00
|
|
|
int tlp_cardbus_match(struct device *, struct cfdata *, void *);
|
|
|
|
void tlp_cardbus_attach(struct device *, struct device *, void *);
|
|
|
|
int tlp_cardbus_detach(struct device *, int);
|
1999-11-19 21:23:35 +03:00
|
|
|
|
2002-10-01 00:43:55 +04:00
|
|
|
CFATTACH_DECL(tlp_cardbus, sizeof(struct tulip_cardbus_softc),
|
2002-10-02 20:33:28 +04:00
|
|
|
tlp_cardbus_match, tlp_cardbus_attach, tlp_cardbus_detach, tlp_activate);
|
1999-11-19 21:23:35 +03:00
|
|
|
|
|
|
|
const struct tulip_cardbus_product {
|
|
|
|
u_int32_t tcp_vendor; /* PCI vendor ID */
|
|
|
|
u_int32_t tcp_product; /* PCI product ID */
|
|
|
|
tulip_chip_t tcp_chip; /* base Tulip chip type */
|
|
|
|
} tlp_cardbus_products[] = {
|
2004-08-02 23:31:52 +04:00
|
|
|
{ PCI_VENDOR_DEC, PCI_PRODUCT_DEC_21142,
|
2000-04-04 23:22:50 +04:00
|
|
|
TULIP_CHIP_21142 },
|
1999-11-19 21:23:35 +03:00
|
|
|
|
2004-08-02 23:31:52 +04:00
|
|
|
{ PCI_VENDOR_XIRCOM, PCI_PRODUCT_XIRCOM_X3201_3_21143,
|
2000-04-04 23:22:50 +04:00
|
|
|
TULIP_CHIP_X3201_3 },
|
2000-01-26 00:50:30 +03:00
|
|
|
|
2004-08-02 23:31:52 +04:00
|
|
|
{ PCI_VENDOR_ADMTEK, PCI_PRODUCT_ADMTEK_AN985,
|
|
|
|
TULIP_CHIP_AN985 },
|
|
|
|
|
|
|
|
{ PCI_VENDOR_ACCTON, PCI_PRODUCT_ACCTON_EN2242,
|
2001-04-13 04:18:11 +04:00
|
|
|
TULIP_CHIP_AN985 },
|
|
|
|
|
2004-08-02 23:31:52 +04:00
|
|
|
{ PCI_VENDOR_ABOCOM, PCI_PRODUCT_ABOCOM_FE2500,
|
2001-01-16 21:55:00 +03:00
|
|
|
TULIP_CHIP_AN985 },
|
|
|
|
|
2004-08-02 23:31:52 +04:00
|
|
|
{ PCI_VENDOR_ABOCOM, PCI_PRODUCT_ABOCOM_PCM200,
|
2001-01-16 21:55:00 +03:00
|
|
|
TULIP_CHIP_AN985 },
|
|
|
|
|
2004-08-02 23:31:52 +04:00
|
|
|
{ PCI_VENDOR_ABOCOM, PCI_PRODUCT_ABOCOM_FE2500MX,
|
2001-03-14 04:41:09 +03:00
|
|
|
TULIP_CHIP_AN985 },
|
|
|
|
|
2004-08-02 23:31:52 +04:00
|
|
|
{ PCI_VENDOR_HAWKING, PCI_PRODUCT_HAWKING_PN672TX,
|
2002-11-11 15:51:38 +03:00
|
|
|
TULIP_CHIP_AN985 },
|
|
|
|
|
2004-08-02 23:31:52 +04:00
|
|
|
{ PCI_VENDOR_ADMTEK, PCI_PRODUCT_ADMTEK_AN985_2,
|
2002-02-18 00:21:58 +03:00
|
|
|
TULIP_CHIP_AN985 },
|
|
|
|
|
2004-08-02 23:31:52 +04:00
|
|
|
{ PCI_VENDOR_MICROSOFT, PCI_PRODUCT_MICROSOFT_MN120,
|
2003-10-24 21:04:16 +04:00
|
|
|
TULIP_CHIP_AN985 },
|
|
|
|
|
2005-06-13 19:27:41 +04:00
|
|
|
{ PCI_VENDOR_LINKSYS, PCI_PRODUCT_LINKSYS_PCMPC200,
|
|
|
|
TULIP_CHIP_AN985 },
|
|
|
|
|
1999-11-19 21:23:35 +03:00
|
|
|
{ 0, 0,
|
2000-04-04 23:22:50 +04:00
|
|
|
TULIP_CHIP_INVALID },
|
1999-11-19 21:23:35 +03:00
|
|
|
};
|
|
|
|
|
2002-04-14 21:17:10 +04:00
|
|
|
struct tlp_cardbus_quirks {
|
2005-02-04 05:10:35 +03:00
|
|
|
void (*tpq_func)(struct tulip_cardbus_softc *,
|
|
|
|
const u_int8_t *);
|
2002-04-14 21:17:10 +04:00
|
|
|
u_int8_t tpq_oui[3];
|
|
|
|
};
|
|
|
|
|
2005-02-04 05:10:35 +03:00
|
|
|
void tlp_cardbus_lxt_quirks(struct tulip_cardbus_softc *,
|
|
|
|
const u_int8_t *);
|
2002-04-14 21:17:10 +04:00
|
|
|
|
|
|
|
const struct tlp_cardbus_quirks tlp_cardbus_21142_quirks[] = {
|
|
|
|
{ tlp_cardbus_lxt_quirks, { 0x00, 0x40, 0x05 } },
|
|
|
|
{ NULL, { 0, 0, 0 } }
|
|
|
|
};
|
|
|
|
|
2005-02-04 05:10:35 +03:00
|
|
|
void tlp_cardbus_setup(struct tulip_cardbus_softc *);
|
2000-03-10 09:55:09 +03:00
|
|
|
|
2005-02-04 05:10:35 +03:00
|
|
|
int tlp_cardbus_enable(struct tulip_softc *);
|
|
|
|
void tlp_cardbus_disable(struct tulip_softc *);
|
|
|
|
void tlp_cardbus_power(struct tulip_softc *, int);
|
2000-03-15 21:39:50 +03:00
|
|
|
|
2005-02-04 05:10:35 +03:00
|
|
|
void tlp_cardbus_x3201_reset(struct tulip_softc *);
|
2000-01-26 00:50:30 +03:00
|
|
|
|
1999-11-19 21:23:35 +03:00
|
|
|
const struct tulip_cardbus_product *tlp_cardbus_lookup
|
2005-02-04 05:10:35 +03:00
|
|
|
(const struct cardbus_attach_args *);
|
|
|
|
void tlp_cardbus_get_quirks(struct tulip_cardbus_softc *,
|
|
|
|
const u_int8_t *, const struct tlp_cardbus_quirks *);
|
1999-11-19 21:23:35 +03:00
|
|
|
|
|
|
|
const struct tulip_cardbus_product *
|
|
|
|
tlp_cardbus_lookup(ca)
|
|
|
|
const struct cardbus_attach_args *ca;
|
|
|
|
{
|
|
|
|
const struct tulip_cardbus_product *tcp;
|
|
|
|
|
|
|
|
for (tcp = tlp_cardbus_products;
|
2000-01-25 22:29:17 +03:00
|
|
|
tlp_chip_names[tcp->tcp_chip] != NULL;
|
1999-11-19 21:23:35 +03:00
|
|
|
tcp++) {
|
|
|
|
if (PCI_VENDOR(ca->ca_id) == tcp->tcp_vendor &&
|
|
|
|
PCI_PRODUCT(ca->ca_id) == tcp->tcp_product)
|
|
|
|
return (tcp);
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2002-04-14 21:17:10 +04:00
|
|
|
void
|
|
|
|
tlp_cardbus_get_quirks(csc, enaddr, tpq)
|
|
|
|
struct tulip_cardbus_softc *csc;
|
|
|
|
const u_int8_t *enaddr;
|
|
|
|
const struct tlp_cardbus_quirks *tpq;
|
|
|
|
{
|
|
|
|
|
|
|
|
for (; tpq->tpq_func != NULL; tpq++) {
|
|
|
|
if (tpq->tpq_oui[0] == enaddr[0] &&
|
|
|
|
tpq->tpq_oui[1] == enaddr[1] &&
|
|
|
|
tpq->tpq_oui[2] == enaddr[2]) {
|
|
|
|
(*tpq->tpq_func)(csc, enaddr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-19 21:23:35 +03:00
|
|
|
int
|
|
|
|
tlp_cardbus_match(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *match;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct cardbus_attach_args *ca = aux;
|
|
|
|
|
|
|
|
if (tlp_cardbus_lookup(ca) != NULL)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tlp_cardbus_attach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
2006-03-29 10:22:38 +04:00
|
|
|
struct tulip_cardbus_softc *csc = device_private(self);
|
1999-11-19 21:23:35 +03:00
|
|
|
struct tulip_softc *sc = &csc->sc_tulip;
|
|
|
|
struct cardbus_attach_args *ca = aux;
|
|
|
|
cardbus_devfunc_t ct = ca->ca_ct;
|
|
|
|
const struct tulip_cardbus_product *tcp;
|
|
|
|
u_int8_t enaddr[ETHER_ADDR_LEN];
|
2000-03-07 03:43:36 +03:00
|
|
|
bus_addr_t adr;
|
2001-01-16 21:55:00 +03:00
|
|
|
pcireg_t reg;
|
1999-11-19 21:23:35 +03:00
|
|
|
|
2005-09-09 18:50:58 +04:00
|
|
|
sc->sc_devno = 0;
|
1999-11-19 21:23:35 +03:00
|
|
|
sc->sc_dmat = ca->ca_dmat;
|
|
|
|
csc->sc_ct = ct;
|
2000-03-10 09:55:09 +03:00
|
|
|
csc->sc_tag = ca->ca_tag;
|
1999-11-19 21:23:35 +03:00
|
|
|
|
|
|
|
tcp = tlp_cardbus_lookup(ca);
|
|
|
|
if (tcp == NULL) {
|
|
|
|
printf("\n");
|
|
|
|
panic("tlp_cardbus_attach: impossible");
|
|
|
|
}
|
|
|
|
sc->sc_chip = tcp->tcp_chip;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* By default, Tulip registers are 8 bytes long (4 bytes
|
|
|
|
* followed by a 4 byte pad).
|
|
|
|
*/
|
|
|
|
sc->sc_regshift = 3;
|
|
|
|
|
2000-03-15 21:39:50 +03:00
|
|
|
/*
|
|
|
|
* Power management hooks.
|
|
|
|
*/
|
|
|
|
sc->sc_enable = tlp_cardbus_enable;
|
|
|
|
sc->sc_disable = tlp_cardbus_disable;
|
2000-03-20 00:45:23 +03:00
|
|
|
sc->sc_power = tlp_cardbus_power;
|
2000-03-15 21:39:50 +03:00
|
|
|
|
1999-11-19 21:23:35 +03:00
|
|
|
/*
|
|
|
|
* Get revision info, and set some chip-specific variables.
|
|
|
|
*/
|
|
|
|
sc->sc_rev = PCI_REVISION(ca->ca_class);
|
|
|
|
switch (sc->sc_chip) {
|
|
|
|
case TULIP_CHIP_21142:
|
|
|
|
if (sc->sc_rev >= 0x20)
|
|
|
|
sc->sc_chip = TULIP_CHIP_21143;
|
|
|
|
break;
|
|
|
|
|
2001-01-16 21:55:00 +03:00
|
|
|
case TULIP_CHIP_AN985:
|
|
|
|
/*
|
|
|
|
* The AN983 and AN985 are very similar, and are
|
|
|
|
* differentiated by a "signature" register that
|
|
|
|
* is like, but not identical, to a PCI ID register.
|
|
|
|
*/
|
|
|
|
reg = cardbus_conf_read(ct->ct_cc, ct->ct_cf, csc->sc_tag,
|
|
|
|
0x80);
|
|
|
|
switch (reg) {
|
|
|
|
case 0x09811317:
|
|
|
|
sc->sc_chip = TULIP_CHIP_AN985;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x09851317:
|
|
|
|
sc->sc_chip = TULIP_CHIP_AN983;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-07-18 14:39:28 +04:00
|
|
|
default:
|
|
|
|
/* Nothing. -- to make gcc happy */
|
2001-07-18 19:24:24 +04:00
|
|
|
break;
|
1999-11-19 21:23:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
printf(": %s Ethernet, pass %d.%d\n",
|
2000-01-25 22:29:17 +03:00
|
|
|
tlp_chip_names[sc->sc_chip],
|
1999-11-19 21:23:35 +03:00
|
|
|
(sc->sc_rev >> 4) & 0xf, sc->sc_rev & 0xf);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Map the device.
|
|
|
|
*/
|
2002-04-14 21:17:10 +04:00
|
|
|
csc->sc_csr = CARDBUS_COMMAND_MASTER_ENABLE;
|
|
|
|
if (Cardbus_mapreg_map(ct, TULIP_PCI_MMBA,
|
|
|
|
CARDBUS_MAPREG_TYPE_MEM, 0, &sc->sc_st, &sc->sc_sh, &adr,
|
2000-02-04 10:59:20 +03:00
|
|
|
&csc->sc_mapsize) == 0) {
|
2000-03-07 03:43:36 +03:00
|
|
|
#if rbus
|
2000-03-14 05:08:21 +03:00
|
|
|
#else
|
|
|
|
(*ct->ct_cf->cardbus_mem_open)(cc, 0, adr, adr+csc->sc_mapsize);
|
|
|
|
#endif
|
|
|
|
csc->sc_cben = CARDBUS_MEM_ENABLE;
|
2002-04-14 21:17:10 +04:00
|
|
|
csc->sc_csr |= CARDBUS_COMMAND_MEM_ENABLE;
|
2000-03-14 05:08:21 +03:00
|
|
|
csc->sc_bar_reg = TULIP_PCI_MMBA;
|
2002-04-14 21:17:10 +04:00
|
|
|
csc->sc_bar_val = adr | CARDBUS_MAPREG_TYPE_MEM;
|
|
|
|
} else if (Cardbus_mapreg_map(ct, TULIP_PCI_IOBA,
|
|
|
|
CARDBUS_MAPREG_TYPE_IO, 0, &sc->sc_st, &sc->sc_sh, &adr,
|
|
|
|
&csc->sc_mapsize) == 0) {
|
|
|
|
#if rbus
|
|
|
|
#else
|
|
|
|
(*ct->ct_cf->cardbus_io_open)(cc, 0, adr, adr+csc->sc_mapsize);
|
|
|
|
#endif
|
|
|
|
csc->sc_cben = CARDBUS_IO_ENABLE;
|
|
|
|
csc->sc_csr |= CARDBUS_COMMAND_IO_ENABLE;
|
|
|
|
csc->sc_bar_reg = TULIP_PCI_IOBA;
|
|
|
|
csc->sc_bar_val = adr | CARDBUS_MAPREG_TYPE_IO;
|
1999-11-19 21:23:35 +03:00
|
|
|
} else {
|
|
|
|
printf("%s: unable to map device registers\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-01-25 06:44:27 +03:00
|
|
|
/*
|
2000-03-10 10:26:41 +03:00
|
|
|
* Bring the chip out of powersave mode and initialize the
|
|
|
|
* configuration registers.
|
2000-01-25 06:44:27 +03:00
|
|
|
*/
|
2000-03-10 10:26:41 +03:00
|
|
|
tlp_cardbus_setup(csc);
|
2000-01-25 06:44:27 +03:00
|
|
|
|
1999-11-19 21:23:35 +03:00
|
|
|
/*
|
2000-01-26 00:50:30 +03:00
|
|
|
* Read the contents of the Ethernet Address ROM/SROM.
|
1999-11-19 21:23:35 +03:00
|
|
|
*/
|
2000-01-26 00:50:30 +03:00
|
|
|
switch (sc->sc_chip) {
|
|
|
|
case TULIP_CHIP_X3201_3:
|
|
|
|
/*
|
|
|
|
* No SROM on this chip.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2000-03-07 03:43:36 +03:00
|
|
|
if (tlp_read_srom(sc) == 0)
|
|
|
|
goto cant_cope;
|
|
|
|
break;
|
2000-01-26 00:50:30 +03:00
|
|
|
}
|
1999-11-19 21:23:35 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Deal with chip/board quirks. This includes setting up
|
|
|
|
* the mediasw, and extracting the Ethernet address from
|
|
|
|
* the rombuf.
|
|
|
|
*/
|
|
|
|
switch (sc->sc_chip) {
|
|
|
|
case TULIP_CHIP_21142:
|
|
|
|
case TULIP_CHIP_21143:
|
|
|
|
/* Check for new format SROM. */
|
2000-04-04 23:33:21 +04:00
|
|
|
if (tlp_isv_srom_enaddr(sc, enaddr) != 0) {
|
1999-11-19 21:23:35 +03:00
|
|
|
/*
|
|
|
|
* We start out with the 2114x ISV media switch.
|
|
|
|
* When we search for quirks, we may change to
|
|
|
|
* a different switch.
|
|
|
|
*/
|
|
|
|
sc->sc_mediasw = &tlp_2114x_isv_mediasw;
|
2000-04-04 23:33:21 +04:00
|
|
|
} else if (tlp_parse_old_srom(sc, enaddr) == 0) {
|
2000-04-04 23:22:50 +04:00
|
|
|
/*
|
2000-04-04 23:33:21 +04:00
|
|
|
* Not an ISV SROM, and not in old DEC Address
|
|
|
|
* ROM format. Try to snarf it out of the CIS.
|
2000-04-04 23:22:50 +04:00
|
|
|
*/
|
|
|
|
if (ca->ca_cis.funce.network.netid_present == 0)
|
|
|
|
goto cant_cope;
|
|
|
|
|
|
|
|
/* Grab the MAC address from the CIS. */
|
|
|
|
memcpy(enaddr, ca->ca_cis.funce.network.netid,
|
|
|
|
sizeof(enaddr));
|
2000-04-04 23:33:21 +04:00
|
|
|
}
|
2000-04-04 23:22:50 +04:00
|
|
|
|
2002-04-14 21:17:10 +04:00
|
|
|
/*
|
|
|
|
* Deal with any quirks this board might have.
|
|
|
|
*/
|
|
|
|
tlp_cardbus_get_quirks(csc, enaddr, tlp_cardbus_21142_quirks);
|
2000-04-04 23:33:21 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we don't already have a media switch, default to
|
|
|
|
* MII-over-SIO, with no special reset routine.
|
|
|
|
*/
|
|
|
|
if (sc->sc_mediasw == NULL) {
|
|
|
|
printf("%s: defaulting to MII-over-SIO; no bets...\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
2000-04-04 23:22:50 +04:00
|
|
|
sc->sc_mediasw = &tlp_sio_mii_mediasw;
|
|
|
|
}
|
1999-11-19 21:23:35 +03:00
|
|
|
break;
|
|
|
|
|
2001-01-16 21:55:00 +03:00
|
|
|
case TULIP_CHIP_AN983:
|
|
|
|
case TULIP_CHIP_AN985:
|
|
|
|
/*
|
|
|
|
* The ADMtek AN985's Ethernet address is located
|
|
|
|
* at offset 8 of its EEPROM.
|
|
|
|
*/
|
|
|
|
memcpy(enaddr, &sc->sc_srom[8], ETHER_ADDR_LEN);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The ADMtek AN985 can be configured in Single-Chip
|
|
|
|
* mode or MAC-only mode. Single-Chip uses the built-in
|
|
|
|
* PHY, MAC-only has an external PHY (usually HomePNA).
|
|
|
|
* The selection is based on an EEPROM setting, and both
|
|
|
|
* PHYs are access via MII attached to SIO.
|
|
|
|
*
|
|
|
|
* The AN985 "ghosts" the internal PHY onto all
|
|
|
|
* MII addresses, so we have to use a media init
|
|
|
|
* routine that limits the search.
|
|
|
|
* XXX How does this work with MAC-only mode?
|
|
|
|
*/
|
|
|
|
sc->sc_mediasw = &tlp_an985_mediasw;
|
|
|
|
break;
|
|
|
|
|
2000-01-26 00:50:30 +03:00
|
|
|
case TULIP_CHIP_X3201_3:
|
1999-11-19 21:23:35 +03:00
|
|
|
/*
|
2000-03-07 03:43:36 +03:00
|
|
|
* The X3201 doesn't have an SROM. Lift the MAC address
|
2000-01-26 00:50:30 +03:00
|
|
|
* from the CIS. Also, we have a special media switch:
|
|
|
|
* MII-on-SIO, plus some special GPIO setup.
|
1999-11-19 21:23:35 +03:00
|
|
|
*/
|
2000-01-26 00:50:30 +03:00
|
|
|
memcpy(enaddr, ca->ca_cis.funce.network.netid, sizeof(enaddr));
|
|
|
|
sc->sc_reset = tlp_cardbus_x3201_reset;
|
|
|
|
sc->sc_mediasw = &tlp_sio_mii_mediasw;
|
|
|
|
break;
|
1999-11-19 21:23:35 +03:00
|
|
|
|
2000-01-26 00:50:30 +03:00
|
|
|
default:
|
|
|
|
cant_cope:
|
1999-11-19 21:23:35 +03:00
|
|
|
printf("%s: sorry, unable to handle your board\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-03-15 21:39:50 +03:00
|
|
|
/* Remember which interrupt line. */
|
|
|
|
csc->sc_intrline = ca->ca_intrline;
|
1999-11-19 21:23:35 +03:00
|
|
|
|
2000-04-04 23:22:50 +04:00
|
|
|
/*
|
|
|
|
* The CardBus cards will make it to store-and-forward mode as
|
|
|
|
* soon as you put them under any kind of load, so just start
|
|
|
|
* out there.
|
|
|
|
*/
|
|
|
|
sc->sc_txthresh = TXTH_SF;
|
|
|
|
|
1999-11-19 21:23:35 +03:00
|
|
|
/*
|
|
|
|
* Finish off the attach.
|
|
|
|
*/
|
|
|
|
tlp_attach(sc, enaddr);
|
2000-03-15 21:39:50 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Power down the socket.
|
|
|
|
*/
|
|
|
|
Cardbus_function_disable(csc->sc_ct);
|
1999-11-19 21:23:35 +03:00
|
|
|
}
|
2000-01-26 00:50:30 +03:00
|
|
|
|
2000-02-02 01:54:47 +03:00
|
|
|
int
|
|
|
|
tlp_cardbus_detach(self, flags)
|
|
|
|
struct device *self;
|
|
|
|
int flags;
|
|
|
|
{
|
2006-03-29 10:22:38 +04:00
|
|
|
struct tulip_cardbus_softc *csc = device_private(self);
|
2000-02-02 01:54:47 +03:00
|
|
|
struct tulip_softc *sc = &csc->sc_tulip;
|
2000-02-04 16:43:56 +03:00
|
|
|
struct cardbus_devfunc *ct = csc->sc_ct;
|
2000-02-02 01:54:47 +03:00
|
|
|
int rv;
|
2000-02-04 10:59:20 +03:00
|
|
|
|
2000-02-04 16:43:56 +03:00
|
|
|
#if defined(DIAGNOSTIC)
|
2000-03-15 21:39:50 +03:00
|
|
|
if (ct == NULL)
|
2002-09-27 19:35:29 +04:00
|
|
|
panic("%s: data structure lacks", sc->sc_dev.dv_xname);
|
2000-02-04 10:59:20 +03:00
|
|
|
#endif
|
2000-02-02 01:54:47 +03:00
|
|
|
|
2000-03-15 21:39:50 +03:00
|
|
|
rv = tlp_detach(sc);
|
|
|
|
if (rv)
|
|
|
|
return (rv);
|
2000-02-04 10:59:20 +03:00
|
|
|
|
2000-03-07 03:43:36 +03:00
|
|
|
/*
|
|
|
|
* Unhook the interrupt handler.
|
|
|
|
*/
|
2000-03-15 21:39:50 +03:00
|
|
|
if (csc->sc_ih != NULL)
|
|
|
|
cardbus_intr_disestablish(ct->ct_cc, ct->ct_cf, csc->sc_ih);
|
2000-02-04 10:59:20 +03:00
|
|
|
|
2000-03-07 03:43:36 +03:00
|
|
|
/*
|
2000-03-15 21:39:50 +03:00
|
|
|
* Release bus space and close window.
|
2000-03-07 03:43:36 +03:00
|
|
|
*/
|
2000-03-22 04:35:14 +03:00
|
|
|
if (csc->sc_bar_reg != 0)
|
|
|
|
Cardbus_mapreg_unmap(ct, csc->sc_bar_reg,
|
|
|
|
sc->sc_st, sc->sc_sh, csc->sc_mapsize);
|
2000-03-07 03:43:36 +03:00
|
|
|
|
|
|
|
return (0);
|
2000-02-02 01:54:47 +03:00
|
|
|
}
|
|
|
|
|
2000-03-15 21:39:50 +03:00
|
|
|
int
|
|
|
|
tlp_cardbus_enable(sc)
|
|
|
|
struct tulip_softc *sc;
|
|
|
|
{
|
|
|
|
struct tulip_cardbus_softc *csc = (void *) sc;
|
|
|
|
cardbus_devfunc_t ct = csc->sc_ct;
|
|
|
|
cardbus_chipset_tag_t cc = ct->ct_cc;
|
|
|
|
cardbus_function_tag_t cf = ct->ct_cf;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Power on the socket.
|
|
|
|
*/
|
|
|
|
Cardbus_function_enable(ct);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the PCI configuration registers.
|
|
|
|
*/
|
|
|
|
tlp_cardbus_setup(csc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Map and establish the interrupt.
|
|
|
|
*/
|
|
|
|
csc->sc_ih = cardbus_intr_establish(cc, cf, csc->sc_intrline, IPL_NET,
|
|
|
|
tlp_intr, sc);
|
|
|
|
if (csc->sc_ih == NULL) {
|
|
|
|
printf("%s: unable to establish interrupt at %d\n",
|
|
|
|
sc->sc_dev.dv_xname, csc->sc_intrline);
|
|
|
|
Cardbus_function_disable(csc->sc_ct);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
printf("%s: interrupting at %d\n", sc->sc_dev.dv_xname,
|
|
|
|
csc->sc_intrline);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tlp_cardbus_disable(sc)
|
|
|
|
struct tulip_softc *sc;
|
|
|
|
{
|
|
|
|
struct tulip_cardbus_softc *csc = (void *) sc;
|
|
|
|
cardbus_devfunc_t ct = csc->sc_ct;
|
|
|
|
cardbus_chipset_tag_t cc = ct->ct_cc;
|
|
|
|
cardbus_function_tag_t cf = ct->ct_cf;
|
|
|
|
|
|
|
|
/* Unhook the interrupt handler. */
|
|
|
|
cardbus_intr_disestablish(cc, cf, csc->sc_ih);
|
|
|
|
csc->sc_ih = NULL;
|
|
|
|
|
|
|
|
/* Power down the socket. */
|
|
|
|
Cardbus_function_disable(ct);
|
|
|
|
}
|
|
|
|
|
2000-03-20 00:45:23 +03:00
|
|
|
void
|
|
|
|
tlp_cardbus_power(sc, why)
|
|
|
|
struct tulip_softc *sc;
|
|
|
|
int why;
|
|
|
|
{
|
|
|
|
|
2004-08-02 23:31:52 +04:00
|
|
|
switch (why) {
|
|
|
|
case PWR_RESUME:
|
|
|
|
tlp_cardbus_enable(sc);
|
|
|
|
break;
|
|
|
|
case PWR_SUSPEND:
|
|
|
|
tlp_cardbus_disable(sc);
|
|
|
|
break;
|
2000-03-20 00:45:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-10 09:55:09 +03:00
|
|
|
void
|
2000-03-10 10:26:41 +03:00
|
|
|
tlp_cardbus_setup(csc)
|
2000-03-10 09:55:09 +03:00
|
|
|
struct tulip_cardbus_softc *csc;
|
|
|
|
{
|
|
|
|
struct tulip_softc *sc = &csc->sc_tulip;
|
|
|
|
cardbus_devfunc_t ct = csc->sc_ct;
|
|
|
|
cardbus_chipset_tag_t cc = ct->ct_cc;
|
|
|
|
cardbus_function_tag_t cf = ct->ct_cf;
|
|
|
|
pcireg_t reg;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check to see if the device is in power-save mode, and
|
|
|
|
* bring it out if necessary.
|
|
|
|
*/
|
|
|
|
switch (sc->sc_chip) {
|
|
|
|
case TULIP_CHIP_21142:
|
|
|
|
case TULIP_CHIP_21143:
|
|
|
|
case TULIP_CHIP_X3201_3:
|
|
|
|
/*
|
|
|
|
* Clear the "sleep mode" bit in the CFDA register.
|
|
|
|
*/
|
|
|
|
reg = cardbus_conf_read(cc, cf, csc->sc_tag, TULIP_PCI_CFDA);
|
|
|
|
if (reg & (CFDA_SLEEP|CFDA_SNOOZE))
|
|
|
|
cardbus_conf_write(cc, cf, csc->sc_tag, TULIP_PCI_CFDA,
|
|
|
|
reg & ~(CFDA_SLEEP|CFDA_SNOOZE));
|
|
|
|
break;
|
2001-07-18 14:39:28 +04:00
|
|
|
|
|
|
|
default:
|
|
|
|
/* Nothing. -- to make gcc happy */
|
2001-07-18 19:24:24 +04:00
|
|
|
break;
|
2000-03-10 09:55:09 +03:00
|
|
|
}
|
|
|
|
|
2004-05-09 03:40:01 +04:00
|
|
|
(void)cardbus_setpowerstate(sc->sc_dev.dv_xname, ct, csc->sc_tag,
|
|
|
|
PCI_PWR_D0);
|
2000-03-10 10:26:41 +03:00
|
|
|
|
|
|
|
/* Program the BAR. */
|
|
|
|
cardbus_conf_write(cc, cf, csc->sc_tag, csc->sc_bar_reg,
|
|
|
|
csc->sc_bar_val);
|
|
|
|
|
2004-07-22 19:48:17 +04:00
|
|
|
/* Make sure the right access type is on the CardBus bridge. */
|
|
|
|
(*ct->ct_cf->cardbus_ctrl)(cc, csc->sc_cben);
|
|
|
|
(*ct->ct_cf->cardbus_ctrl)(cc, CARDBUS_BM_ENABLE);
|
|
|
|
|
2000-03-10 10:26:41 +03:00
|
|
|
/* Enable the appropriate bits in the PCI CSR. */
|
|
|
|
reg = cardbus_conf_read(cc, cf, csc->sc_tag, PCI_COMMAND_STATUS_REG);
|
|
|
|
reg &= ~(PCI_COMMAND_IO_ENABLE|PCI_COMMAND_MEM_ENABLE);
|
|
|
|
reg |= csc->sc_csr;
|
|
|
|
cardbus_conf_write(cc, cf, csc->sc_tag, PCI_COMMAND_STATUS_REG, reg);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure the latency timer is set to some reasonable
|
|
|
|
* value.
|
|
|
|
*/
|
|
|
|
reg = cardbus_conf_read(cc, cf, csc->sc_tag, PCI_BHLC_REG);
|
|
|
|
if (PCI_LATTIMER(reg) < 0x20) {
|
|
|
|
reg &= ~(PCI_LATTIMER_MASK << PCI_LATTIMER_SHIFT);
|
|
|
|
reg |= (0x20 << PCI_LATTIMER_SHIFT);
|
|
|
|
cardbus_conf_write(cc, cf, csc->sc_tag, PCI_BHLC_REG, reg);
|
|
|
|
}
|
2000-03-10 09:55:09 +03:00
|
|
|
}
|
|
|
|
|
2000-01-26 00:50:30 +03:00
|
|
|
void
|
|
|
|
tlp_cardbus_x3201_reset(sc)
|
|
|
|
struct tulip_softc *sc;
|
|
|
|
{
|
|
|
|
u_int32_t reg;
|
|
|
|
|
|
|
|
reg = TULIP_READ(sc, CSR_SIAGEN);
|
|
|
|
|
|
|
|
/* make GP[2,0] outputs */
|
|
|
|
TULIP_WRITE(sc, CSR_SIAGEN, (reg & ~SIAGEN_MD) | SIAGEN_CWE |
|
|
|
|
0x00050000);
|
|
|
|
TULIP_WRITE(sc, CSR_SIAGEN, (reg & ~SIAGEN_CWE) | SIAGEN_MD);
|
|
|
|
}
|
2002-04-14 21:17:10 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
tlp_cardbus_lxt_quirks(csc, enaddr)
|
|
|
|
struct tulip_cardbus_softc *csc;
|
|
|
|
const u_int8_t *enaddr;
|
|
|
|
{
|
|
|
|
struct tulip_softc *sc = &csc->sc_tulip;
|
|
|
|
|
|
|
|
sc->sc_mediasw = &tlp_sio_mii_mediasw;
|
|
|
|
}
|