2004-08-22 03:48:33 +04:00
|
|
|
/* $NetBSD: if_an_pci.c,v 1.16 2004/08/21 23:48:33 thorpej Exp $ */
|
2000-12-14 07:11:25 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Atsushi Onoe.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PCI bus front-end for the Aironet PC4500/PC4800 Wireless LAN Adapter.
|
|
|
|
* Unlike WaveLAN, this adapter attached as PCI device using a PLX 9050
|
|
|
|
* PCI to "dumb bus" bridge chip.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 10:48:40 +03:00
|
|
|
#include <sys/cdefs.h>
|
2004-08-22 03:48:33 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: if_an_pci.c,v 1.16 2004/08/21 23:48:33 thorpej Exp $");
|
2001-11-13 10:48:40 +03:00
|
|
|
|
2000-12-14 07:11:25 +03:00
|
|
|
#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>
|
|
|
|
#include <sys/callout.h>
|
|
|
|
|
|
|
|
#include <machine/endian.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
#include <net/if_ether.h>
|
2003-10-13 10:45:32 +04:00
|
|
|
|
|
|
|
#include <net80211/ieee80211_var.h>
|
|
|
|
#include <net80211/ieee80211_compat.h>
|
2000-12-14 07:11:25 +03:00
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/intr.h>
|
|
|
|
|
|
|
|
#include <dev/ic/anreg.h>
|
|
|
|
#include <dev/ic/anvar.h>
|
|
|
|
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcidevs.h>
|
|
|
|
|
|
|
|
#define AN_PCI_PLX_IOBA 0x14 /* i/o base for PLX chip */
|
|
|
|
#define AN_PCI_IOBA 0x18 /* i/o base */
|
|
|
|
|
|
|
|
struct an_pci_softc {
|
|
|
|
struct an_softc sc_an; /* real "an" softc */
|
|
|
|
|
|
|
|
/* PCI-specific goo. */
|
|
|
|
void *sc_ih; /* interrupt handle */
|
|
|
|
};
|
|
|
|
|
2004-08-22 03:48:33 +04:00
|
|
|
static int an_pci_match(struct device *, struct cfdata *, void *);
|
|
|
|
static void an_pci_attach(struct device *, struct device *, void *);
|
2000-12-14 07:11:25 +03:00
|
|
|
|
2002-10-01 00:37:04 +04:00
|
|
|
CFATTACH_DECL(an_pci, sizeof(struct an_pci_softc),
|
2002-10-02 20:51:16 +04:00
|
|
|
an_pci_match, an_pci_attach, NULL, NULL);
|
2000-12-14 07:11:25 +03:00
|
|
|
|
2004-08-22 03:48:33 +04:00
|
|
|
static const struct an_pci_product {
|
2000-12-14 07:11:25 +03:00
|
|
|
u_int32_t app_vendor; /* PCI vendor ID */
|
|
|
|
u_int32_t app_product; /* PCI product ID */
|
|
|
|
} an_pci_products[] = {
|
|
|
|
{ PCI_VENDOR_AIRONET, PCI_PRODUCT_AIRONET_PC4xxx },
|
|
|
|
{ PCI_VENDOR_AIRONET, PCI_PRODUCT_AIRONET_PC4500 },
|
|
|
|
{ PCI_VENDOR_AIRONET, PCI_PRODUCT_AIRONET_PC4800 },
|
2004-08-06 01:43:46 +04:00
|
|
|
{ PCI_VENDOR_AIRONET, PCI_PRODUCT_AIRONET_PCI350 },
|
2000-12-14 07:11:25 +03:00
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
2004-08-22 03:48:33 +04:00
|
|
|
static int
|
2000-12-14 07:11:25 +03:00
|
|
|
an_pci_match(struct device *parent, struct cfdata *match, void *aux)
|
|
|
|
{
|
|
|
|
struct pci_attach_args *pa = aux;
|
|
|
|
const struct an_pci_product *app;
|
|
|
|
|
|
|
|
for (app = an_pci_products; app->app_vendor != 0; app++) {
|
|
|
|
if (PCI_VENDOR(pa->pa_id) == app->app_vendor &&
|
|
|
|
PCI_PRODUCT(pa->pa_id) == app->app_product)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-08-22 03:48:33 +04:00
|
|
|
static void
|
2000-12-14 07:11:25 +03:00
|
|
|
an_pci_attach(struct device *parent, struct device *self, void *aux)
|
|
|
|
{
|
|
|
|
struct pci_attach_args *pa = (struct pci_attach_args *)aux;
|
|
|
|
struct an_pci_softc *psc = (struct an_pci_softc *) self;
|
|
|
|
struct an_softc *sc = &psc->sc_an;
|
|
|
|
char devinfo[256];
|
|
|
|
char const *intrstr;
|
|
|
|
pci_intr_handle_t ih;
|
|
|
|
u_int32_t csr;
|
|
|
|
|
2003-01-31 03:07:39 +03:00
|
|
|
aprint_naive(": 802.11 controller\n");
|
|
|
|
|
2004-04-24 01:13:05 +04:00
|
|
|
pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
|
2003-01-31 03:07:39 +03:00
|
|
|
aprint_normal(": %s\n", devinfo);
|
2000-12-14 07:11:25 +03:00
|
|
|
|
|
|
|
/* Map I/O registers */
|
|
|
|
if (pci_mapreg_map(pa, AN_PCI_IOBA, PCI_MAPREG_TYPE_IO, 0,
|
2004-01-28 18:07:52 +03:00
|
|
|
&sc->sc_iot, &sc->sc_ioh, NULL, NULL) != 0) {
|
2003-01-31 03:07:39 +03:00
|
|
|
aprint_error("%s: unable to map registers\n", self->dv_xname);
|
2000-12-14 07:11:25 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable the device. */
|
|
|
|
csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
|
|
|
|
pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
|
|
|
|
csr | PCI_COMMAND_MASTER_ENABLE);
|
|
|
|
|
|
|
|
/* Map and establish the interrupt. */
|
2000-12-29 01:59:06 +03:00
|
|
|
if (pci_intr_map(pa, &ih)) {
|
2003-01-31 03:07:39 +03:00
|
|
|
aprint_error("%s: unable to map interrupt\n", self->dv_xname);
|
2000-12-14 07:11:25 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
intrstr = pci_intr_string(pa->pa_pc, ih);
|
|
|
|
psc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_NET, an_intr, sc);
|
|
|
|
if (psc->sc_ih == NULL) {
|
2003-01-31 03:07:39 +03:00
|
|
|
aprint_error("%s: unable to establish interrupt",
|
|
|
|
self->dv_xname);
|
2000-12-14 07:11:25 +03:00
|
|
|
if (intrstr != NULL)
|
2003-01-31 03:07:39 +03:00
|
|
|
aprint_normal(" at %s", intrstr);
|
|
|
|
aprint_normal("\n");
|
2000-12-14 07:11:25 +03:00
|
|
|
return;
|
|
|
|
}
|
2003-01-31 03:07:39 +03:00
|
|
|
aprint_normal("%s: interrupting at %s\n", self->dv_xname, intrstr);
|
2000-12-14 07:11:25 +03:00
|
|
|
sc->sc_enabled = 1;
|
|
|
|
|
|
|
|
if (an_attach(sc) != 0) {
|
2003-01-31 03:07:39 +03:00
|
|
|
aprint_error("%s: failed to attach controller\n",
|
|
|
|
self->dv_xname);
|
2000-12-14 07:11:25 +03:00
|
|
|
pci_intr_disestablish(pa->pa_pc, psc->sc_ih);
|
2004-01-29 19:57:29 +03:00
|
|
|
bus_space_unmap(sc->sc_iot, sc->sc_ioh, AN_IOSIZ);
|
2000-12-14 07:11:25 +03:00
|
|
|
}
|
|
|
|
}
|