2006-10-12 05:30:41 +04:00
|
|
|
/* $NetBSD: if_fxp_cardbus.c,v 1.25 2006/10/12 01:30:55 christos Exp $ */
|
1999-10-15 10:07:17 +04:00
|
|
|
|
|
|
|
/*
|
1999-10-31 18:12:39 +03:00
|
|
|
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
1999-10-15 10:07:17 +04:00
|
|
|
*
|
2000-03-10 10:11:47 +03:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Johan Danielsson.
|
1999-10-15 10:07:17 +04:00
|
|
|
*
|
2000-03-10 10:11:47 +03:00
|
|
|
* 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
|
1999-10-31 18:12:39 +03:00
|
|
|
* 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
|
1999-10-15 10:07:17 +04:00
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2000-03-10 10:11:47 +03:00
|
|
|
/*
|
|
|
|
* CardBus front-end for the Intel i82557 family of Ethernet chips.
|
|
|
|
*/
|
1999-10-15 10:07:17 +04:00
|
|
|
|
2001-11-13 15:51:12 +03:00
|
|
|
#include <sys/cdefs.h>
|
2006-10-12 05:30:41 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: if_fxp_cardbus.c,v 1.25 2006/10/12 01:30:55 christos Exp $");
|
2001-11-13 15:51:12 +03:00
|
|
|
|
1999-10-15 10:07:17 +04:00
|
|
|
#include "opt_inet.h"
|
|
|
|
#include "bpfilter.h"
|
|
|
|
#include "rnd.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
|
|
|
|
#if NRND > 0
|
|
|
|
#include <sys/rnd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
|
1999-12-12 20:46:36 +03:00
|
|
|
#include <machine/endian.h>
|
|
|
|
|
1999-10-15 10:07:17 +04:00
|
|
|
#if NBPFILTER > 0
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/if_inarp.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/intr.h>
|
|
|
|
|
|
|
|
#include <dev/mii/miivar.h>
|
|
|
|
|
1999-10-31 18:12:39 +03:00
|
|
|
#include <dev/ic/i82557reg.h>
|
|
|
|
#include <dev/ic/i82557var.h>
|
1999-10-15 10:07:17 +04:00
|
|
|
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcidevs.h>
|
|
|
|
|
|
|
|
#include <dev/cardbus/cardbusvar.h>
|
2004-08-02 23:14:28 +04:00
|
|
|
#include <dev/pci/pcidevs.h>
|
1999-10-15 10:07:17 +04:00
|
|
|
|
2005-02-04 05:10:35 +03:00
|
|
|
static int fxp_cardbus_match(struct device *, struct cfdata *, void *);
|
|
|
|
static void fxp_cardbus_attach(struct device *, struct device *, void *);
|
|
|
|
static int fxp_cardbus_detach(struct device * self, int flags);
|
|
|
|
static void fxp_cardbus_setup(struct fxp_softc * sc);
|
|
|
|
static int fxp_cardbus_enable(struct fxp_softc * sc);
|
|
|
|
static void fxp_cardbus_disable(struct fxp_softc * sc);
|
1999-10-15 10:07:17 +04:00
|
|
|
|
|
|
|
struct fxp_cardbus_softc {
|
2000-03-10 10:11:47 +03:00
|
|
|
struct fxp_softc sc;
|
|
|
|
cardbus_devfunc_t ct;
|
|
|
|
pcireg_t base0_reg;
|
|
|
|
pcireg_t base1_reg;
|
|
|
|
bus_size_t size;
|
1999-10-15 10:07:17 +04:00
|
|
|
};
|
|
|
|
|
2002-10-01 00:43:55 +04:00
|
|
|
CFATTACH_DECL(fxp_cardbus, sizeof(struct fxp_cardbus_softc),
|
2002-10-02 20:33:28 +04:00
|
|
|
fxp_cardbus_match, fxp_cardbus_attach, fxp_cardbus_detach, fxp_activate);
|
1999-10-15 10:07:17 +04:00
|
|
|
|
|
|
|
#ifdef CBB_DEBUG
|
|
|
|
#define DPRINTF(X) printf X
|
|
|
|
#else
|
|
|
|
#define DPRINTF(X)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int
|
2006-10-12 05:30:41 +04:00
|
|
|
fxp_cardbus_match(struct device *parent __unused, struct cfdata *match __unused,
|
|
|
|
void *aux)
|
1999-10-15 10:07:17 +04:00
|
|
|
{
|
2000-03-10 10:11:47 +03:00
|
|
|
struct cardbus_attach_args *ca = aux;
|
|
|
|
|
2004-08-02 23:14:28 +04:00
|
|
|
if (CARDBUS_VENDOR(ca->ca_id) == PCI_VENDOR_INTEL &&
|
|
|
|
CARDBUS_PRODUCT(ca->ca_id) == PCI_PRODUCT_INTEL_82557)
|
2000-03-22 03:17:46 +03:00
|
|
|
return (1);
|
|
|
|
|
|
|
|
return (0);
|
1999-10-15 10:07:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-10-12 05:30:41 +04:00
|
|
|
fxp_cardbus_attach(struct device *parent __unused, struct device *self,
|
|
|
|
void *aux)
|
1999-10-15 10:07:17 +04:00
|
|
|
{
|
2000-05-08 22:23:36 +04:00
|
|
|
static const char thisfunc[] = "fxp_cardbus_attach";
|
2000-03-10 10:11:47 +03:00
|
|
|
|
2006-03-29 10:22:38 +04:00
|
|
|
struct fxp_softc *sc = device_private(self);
|
|
|
|
struct fxp_cardbus_softc *csc = device_private(self);
|
2000-03-10 10:11:47 +03:00
|
|
|
struct cardbus_attach_args *ca = aux;
|
|
|
|
bus_space_tag_t iot, memt;
|
|
|
|
bus_space_handle_t ioh, memh;
|
|
|
|
|
|
|
|
bus_addr_t adr;
|
|
|
|
bus_size_t size;
|
|
|
|
|
|
|
|
csc->ct = ca->ca_ct;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Map control/status registers.
|
|
|
|
*/
|
2000-03-12 20:05:23 +03:00
|
|
|
if (Cardbus_mapreg_map(csc->ct, CARDBUS_BASE1_REG,
|
|
|
|
PCI_MAPREG_TYPE_IO, 0, &iot, &ioh, &adr, &size) == 0) {
|
|
|
|
csc->base1_reg = adr | 1;
|
|
|
|
sc->sc_st = iot;
|
|
|
|
sc->sc_sh = ioh;
|
|
|
|
csc->size = size;
|
|
|
|
} else if (Cardbus_mapreg_map(csc->ct, CARDBUS_BASE0_REG,
|
2000-03-10 10:11:47 +03:00
|
|
|
PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
|
|
|
|
0, &memt, &memh, &adr, &size) == 0) {
|
|
|
|
csc->base0_reg = adr;
|
|
|
|
sc->sc_st = memt;
|
|
|
|
sc->sc_sh = memh;
|
|
|
|
csc->size = size;
|
|
|
|
} else
|
2000-05-08 22:23:36 +04:00
|
|
|
panic("%s: failed to allocate mem and io space", thisfunc);
|
2000-03-10 10:11:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
if (ca->ca_cis.cis1_info[0] && ca->ca_cis.cis1_info[1])
|
|
|
|
printf(": %s %s\n", ca->ca_cis.cis1_info[0],
|
|
|
|
ca->ca_cis.cis1_info[1]);
|
|
|
|
else
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
sc->sc_dmat = ca->ca_dmat;
|
|
|
|
sc->sc_enable = fxp_cardbus_enable;
|
|
|
|
sc->sc_disable = fxp_cardbus_disable;
|
|
|
|
sc->sc_enabled = 0;
|
|
|
|
|
|
|
|
fxp_enable(sc);
|
|
|
|
fxp_attach(sc);
|
|
|
|
fxp_disable(sc);
|
1999-10-15 10:07:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-03-10 10:11:47 +03:00
|
|
|
fxp_cardbus_setup(struct fxp_softc * sc)
|
1999-10-15 10:07:17 +04:00
|
|
|
{
|
2000-03-10 10:11:47 +03:00
|
|
|
struct fxp_cardbus_softc *csc = (struct fxp_cardbus_softc *) sc;
|
|
|
|
struct cardbus_softc *psc =
|
2006-03-26 01:55:05 +03:00
|
|
|
(struct cardbus_softc *) device_parent(&sc->sc_dev);
|
2000-03-10 10:11:47 +03:00
|
|
|
cardbus_chipset_tag_t cc = psc->sc_cc;
|
|
|
|
cardbus_function_tag_t cf = psc->sc_cf;
|
|
|
|
pcireg_t command;
|
|
|
|
|
|
|
|
cardbustag_t tag = cardbus_make_tag(cc, cf, csc->ct->ct_bus,
|
2005-09-09 18:50:58 +04:00
|
|
|
csc->ct->ct_func);
|
2000-03-10 10:11:47 +03:00
|
|
|
|
|
|
|
command = Cardbus_conf_read(csc->ct, tag, CARDBUS_COMMAND_STATUS_REG);
|
|
|
|
if (csc->base0_reg) {
|
|
|
|
Cardbus_conf_write(csc->ct, tag,
|
|
|
|
CARDBUS_BASE0_REG, csc->base0_reg);
|
|
|
|
(cf->cardbus_ctrl) (cc, CARDBUS_MEM_ENABLE);
|
|
|
|
command |= CARDBUS_COMMAND_MEM_ENABLE |
|
|
|
|
CARDBUS_COMMAND_MASTER_ENABLE;
|
|
|
|
} else if (csc->base1_reg) {
|
|
|
|
Cardbus_conf_write(csc->ct, tag,
|
|
|
|
CARDBUS_BASE1_REG, csc->base1_reg);
|
|
|
|
(cf->cardbus_ctrl) (cc, CARDBUS_IO_ENABLE);
|
|
|
|
command |= (CARDBUS_COMMAND_IO_ENABLE |
|
|
|
|
CARDBUS_COMMAND_MASTER_ENABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
(cf->cardbus_ctrl) (cc, CARDBUS_BM_ENABLE);
|
|
|
|
|
|
|
|
/* enable the card */
|
|
|
|
Cardbus_conf_write(csc->ct, tag, CARDBUS_COMMAND_STATUS_REG, command);
|
1999-10-15 10:07:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-03-10 10:11:47 +03:00
|
|
|
fxp_cardbus_enable(struct fxp_softc * sc)
|
1999-10-15 10:07:17 +04:00
|
|
|
{
|
2000-03-10 10:11:47 +03:00
|
|
|
struct fxp_cardbus_softc *csc = (struct fxp_cardbus_softc *) sc;
|
|
|
|
struct cardbus_softc *psc =
|
2006-03-26 01:55:05 +03:00
|
|
|
(struct cardbus_softc *) device_parent(&sc->sc_dev);
|
2000-03-10 10:11:47 +03:00
|
|
|
cardbus_chipset_tag_t cc = psc->sc_cc;
|
|
|
|
cardbus_function_tag_t cf = psc->sc_cf;
|
1999-10-15 10:07:17 +04:00
|
|
|
|
2000-03-10 10:11:47 +03:00
|
|
|
Cardbus_function_enable(csc->ct);
|
1999-10-15 10:07:17 +04:00
|
|
|
|
2000-03-10 10:11:47 +03:00
|
|
|
fxp_cardbus_setup(sc);
|
1999-10-15 10:07:17 +04:00
|
|
|
|
2000-03-10 10:11:47 +03:00
|
|
|
/* Map and establish the interrupt. */
|
1999-10-15 10:07:17 +04:00
|
|
|
|
2000-03-10 10:11:47 +03:00
|
|
|
sc->sc_ih = cardbus_intr_establish(cc, cf, psc->sc_intrline, IPL_NET,
|
|
|
|
fxp_intr, sc);
|
|
|
|
if (NULL == sc->sc_ih) {
|
|
|
|
printf("%s: couldn't establish interrupt\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return 1;
|
|
|
|
}
|
1999-10-15 10:07:17 +04:00
|
|
|
|
2000-03-10 10:11:47 +03:00
|
|
|
printf("%s: interrupting at %d\n", sc->sc_dev.dv_xname,
|
|
|
|
psc->sc_intrline);
|
1999-10-15 10:07:17 +04:00
|
|
|
|
2000-03-10 10:11:47 +03:00
|
|
|
return 0;
|
1999-10-15 10:07:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-03-10 10:11:47 +03:00
|
|
|
fxp_cardbus_disable(struct fxp_softc * sc)
|
1999-10-15 10:07:17 +04:00
|
|
|
{
|
2000-03-10 10:11:47 +03:00
|
|
|
struct cardbus_softc *psc =
|
2006-03-26 01:55:05 +03:00
|
|
|
(struct cardbus_softc *) device_parent(&sc->sc_dev);
|
2000-03-10 10:11:47 +03:00
|
|
|
cardbus_chipset_tag_t cc = psc->sc_cc;
|
|
|
|
cardbus_function_tag_t cf = psc->sc_cf;
|
1999-10-15 10:07:17 +04:00
|
|
|
|
2000-03-10 10:11:47 +03:00
|
|
|
/* Remove interrupt handler. */
|
|
|
|
cardbus_intr_disestablish(cc, cf, sc->sc_ih);
|
|
|
|
|
|
|
|
Cardbus_function_disable(((struct fxp_cardbus_softc *) sc)->ct);
|
1999-10-15 10:07:17 +04:00
|
|
|
}
|
2000-02-10 01:15:57 +03:00
|
|
|
|
|
|
|
static int
|
2006-10-12 05:30:41 +04:00
|
|
|
fxp_cardbus_detach(struct device *self, int flags __unused)
|
2000-02-10 01:15:57 +03:00
|
|
|
{
|
2006-03-29 10:22:38 +04:00
|
|
|
struct fxp_softc *sc = device_private(self);
|
|
|
|
struct fxp_cardbus_softc *csc = device_private(self);
|
2000-02-10 01:15:57 +03:00
|
|
|
struct cardbus_devfunc *ct = csc->ct;
|
2000-03-10 10:11:47 +03:00
|
|
|
int rv, reg;
|
2000-02-10 01:15:57 +03:00
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
2000-03-10 10:11:47 +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-10 01:15:57 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
rv = fxp_detach(sc);
|
|
|
|
if (rv == 0) {
|
|
|
|
/*
|
|
|
|
* Unhook the interrupt handler.
|
|
|
|
*/
|
|
|
|
cardbus_intr_disestablish(ct->ct_cc, ct->ct_cf, sc->sc_ih);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* release bus space and close window
|
|
|
|
*/
|
2000-03-10 10:11:47 +03:00
|
|
|
if (csc->base0_reg)
|
2000-02-10 01:15:57 +03:00
|
|
|
reg = CARDBUS_BASE0_REG;
|
2000-03-10 10:11:47 +03:00
|
|
|
else
|
2000-02-10 01:15:57 +03:00
|
|
|
reg = CARDBUS_BASE1_REG;
|
|
|
|
Cardbus_mapreg_unmap(ct, reg, sc->sc_st, sc->sc_sh, csc->size);
|
|
|
|
}
|
|
|
|
return (rv);
|
|
|
|
}
|