2004-08-10 22:43:49 +04:00
|
|
|
/* $NetBSD: if_awi_pcmcia.c,v 1.32 2004/08/10 18:43:49 mycroft Exp $ */
|
1999-11-05 08:13:36 +03:00
|
|
|
|
1999-11-04 20:12:43 +03:00
|
|
|
/*-
|
2004-08-10 20:43:47 +04:00
|
|
|
* Copyright (c) 1999, 2004 The NetBSD Foundation, Inc.
|
1999-11-04 20:12:43 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Bill Sommerfeld
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PCMCIA attachment for BayStack 650 802.11FH PCMCIA card,
|
|
|
|
* based on the AMD 79c930 802.11 controller chip.
|
|
|
|
*
|
2003-10-22 13:04:39 +04:00
|
|
|
* This attachment can probably be trivially adapted for other FH and
|
1999-11-04 20:12:43 +03:00
|
|
|
* DS cards based on the same chipset.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 10:24:43 +03:00
|
|
|
#include <sys/cdefs.h>
|
2004-08-10 22:43:49 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: if_awi_pcmcia.c,v 1.32 2004/08/10 18:43:49 mycroft Exp $");
|
2001-11-13 10:24:43 +03:00
|
|
|
|
1999-11-04 20:12:43 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
#include <net/if_media.h>
|
2003-10-13 12:10:48 +04:00
|
|
|
|
|
|
|
#include <net80211/ieee80211_var.h>
|
|
|
|
#include <net80211/ieee80211_compat.h>
|
1999-11-04 20:12:43 +03:00
|
|
|
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/intr.h>
|
|
|
|
|
|
|
|
#include <dev/ic/am79c930reg.h>
|
|
|
|
#include <dev/ic/am79c930var.h>
|
|
|
|
#include <dev/ic/awireg.h>
|
|
|
|
#include <dev/ic/awivar.h>
|
|
|
|
|
|
|
|
#include <dev/pcmcia/pcmciareg.h>
|
|
|
|
#include <dev/pcmcia/pcmciavar.h>
|
|
|
|
#include <dev/pcmcia/pcmciadevs.h>
|
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
static int awi_pcmcia_match(struct device *, struct cfdata *, void *);
|
2004-08-10 20:43:47 +04:00
|
|
|
static int awi_pcmcia_validate_config(struct pcmcia_config_entry *);
|
2001-09-18 13:09:57 +04:00
|
|
|
static void awi_pcmcia_attach(struct device *, struct device *, void *);
|
|
|
|
static int awi_pcmcia_detach(struct device *, int);
|
|
|
|
static int awi_pcmcia_enable(struct awi_softc *);
|
|
|
|
static void awi_pcmcia_disable(struct awi_softc *);
|
1999-11-04 20:12:43 +03:00
|
|
|
|
|
|
|
struct awi_pcmcia_softc {
|
2000-02-01 13:00:41 +03:00
|
|
|
struct awi_softc sc_awi; /* real "awi" softc */
|
1999-11-04 20:12:43 +03:00
|
|
|
|
|
|
|
/* PCMCIA-specific goo */
|
|
|
|
struct pcmcia_function *sc_pf; /* our PCMCIA function */
|
2001-09-18 13:09:57 +04:00
|
|
|
void *sc_ih; /* interrupt handler */
|
1999-11-04 20:12:43 +03:00
|
|
|
|
2004-08-10 20:43:47 +04:00
|
|
|
int sc_state;
|
|
|
|
#define AWI_PCMCIA_ATTACH1 1
|
|
|
|
#define AWI_PCMCIA_ATTACH2 2
|
|
|
|
#define AWI_PCMCIA_ATTACHED 3
|
|
|
|
};
|
1999-11-04 20:12:43 +03:00
|
|
|
|
2002-10-01 01:57:46 +04:00
|
|
|
CFATTACH_DECL(awi_pcmcia, sizeof(struct awi_pcmcia_softc),
|
2002-10-02 20:51:16 +04:00
|
|
|
awi_pcmcia_match, awi_pcmcia_attach, awi_pcmcia_detach, awi_activate);
|
1999-11-04 20:12:43 +03:00
|
|
|
|
2004-08-10 22:39:08 +04:00
|
|
|
static const struct pcmcia_product awi_pcmcia_products[] = {
|
2000-02-03 11:52:21 +03:00
|
|
|
{ PCMCIA_VENDOR_BAY, PCMCIA_PRODUCT_BAY_STACK_650,
|
2004-08-10 22:39:08 +04:00
|
|
|
PCMCIA_CIS_BAY_STACK_650 },
|
2000-02-03 11:52:21 +03:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
{ PCMCIA_VENDOR_BAY, PCMCIA_PRODUCT_BAY_STACK_660,
|
2004-08-10 22:39:08 +04:00
|
|
|
PCMCIA_CIS_BAY_STACK_660 },
|
2000-03-22 14:22:20 +03:00
|
|
|
|
|
|
|
{ PCMCIA_VENDOR_BAY, PCMCIA_PRODUCT_BAY_SURFER_PRO,
|
2004-08-10 22:39:08 +04:00
|
|
|
PCMCIA_CIS_BAY_SURFER_PRO },
|
2000-03-22 14:22:20 +03:00
|
|
|
|
|
|
|
{ PCMCIA_VENDOR_AMD, PCMCIA_PRODUCT_AMD_AM79C930,
|
2004-08-10 22:39:08 +04:00
|
|
|
PCMCIA_CIS_AMD_AM79C930 },
|
2000-02-03 11:52:21 +03:00
|
|
|
|
|
|
|
{ PCMCIA_VENDOR_ICOM, PCMCIA_PRODUCT_ICOM_SL200,
|
2004-08-10 22:39:08 +04:00
|
|
|
PCMCIA_CIS_ICOM_SL200 },
|
2000-02-03 11:52:21 +03:00
|
|
|
|
2000-03-23 01:33:47 +03:00
|
|
|
{ PCMCIA_VENDOR_NOKIA, PCMCIA_PRODUCT_NOKIA_C020_WLAN,
|
2004-08-10 22:39:08 +04:00
|
|
|
PCMCIA_CIS_NOKIA_C020_WLAN },
|
2000-03-23 01:33:47 +03:00
|
|
|
|
2000-06-09 17:05:02 +04:00
|
|
|
{ PCMCIA_VENDOR_FARALLON, PCMCIA_PRODUCT_FARALLON_SKYLINE,
|
2004-08-10 22:39:08 +04:00
|
|
|
PCMCIA_CIS_FARALLON_SKYLINE },
|
2000-02-03 11:52:21 +03:00
|
|
|
};
|
2004-08-10 22:39:08 +04:00
|
|
|
static const size_t awi_pcmcia_nproducts =
|
|
|
|
sizeof(awi_pcmcia_products) / sizeof(awi_pcmcia_products[0]);
|
1999-11-06 19:43:53 +03:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
static int
|
1999-11-04 20:12:43 +03:00
|
|
|
awi_pcmcia_enable(sc)
|
|
|
|
struct awi_softc *sc;
|
|
|
|
{
|
2000-02-01 11:58:25 +03:00
|
|
|
struct awi_pcmcia_softc *psc = (struct awi_pcmcia_softc *)sc;
|
1999-11-04 20:12:43 +03:00
|
|
|
struct pcmcia_function *pf = psc->sc_pf;
|
2004-08-10 20:43:47 +04:00
|
|
|
int error;
|
|
|
|
|
|
|
|
if (psc->sc_state == AWI_PCMCIA_ATTACH1) {
|
|
|
|
psc->sc_state = AWI_PCMCIA_ATTACH2;
|
|
|
|
return (0);
|
|
|
|
}
|
1999-11-04 20:12:43 +03:00
|
|
|
|
|
|
|
/* establish the interrupt. */
|
2001-09-18 13:09:57 +04:00
|
|
|
psc->sc_ih = pcmcia_intr_establish(pf, IPL_NET, awi_intr, sc);
|
2004-08-10 20:43:47 +04:00
|
|
|
if (!psc->sc_ih)
|
|
|
|
return (EIO);
|
2000-03-22 14:22:20 +03:00
|
|
|
|
2004-08-10 20:43:47 +04:00
|
|
|
error = pcmcia_function_enable(pf);
|
|
|
|
if (error) {
|
2001-09-18 13:09:57 +04:00
|
|
|
pcmcia_intr_disestablish(pf, psc->sc_ih);
|
2004-08-10 20:43:47 +04:00
|
|
|
psc->sc_ih = 0;
|
2000-03-22 14:22:20 +03:00
|
|
|
}
|
|
|
|
|
2004-08-10 20:43:47 +04:00
|
|
|
return (error);
|
1999-11-04 20:12:43 +03:00
|
|
|
}
|
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
static void
|
1999-11-04 20:12:43 +03:00
|
|
|
awi_pcmcia_disable(sc)
|
|
|
|
struct awi_softc *sc;
|
|
|
|
{
|
2000-02-01 11:58:25 +03:00
|
|
|
struct awi_pcmcia_softc *psc = (struct awi_pcmcia_softc *)sc;
|
1999-11-04 20:12:43 +03:00
|
|
|
struct pcmcia_function *pf = psc->sc_pf;
|
|
|
|
|
2000-02-01 11:58:25 +03:00
|
|
|
pcmcia_function_disable(pf);
|
2001-09-18 13:09:57 +04:00
|
|
|
pcmcia_intr_disestablish(pf, psc->sc_ih);
|
2004-08-10 20:43:47 +04:00
|
|
|
psc->sc_ih = 0;
|
1999-11-04 20:12:43 +03:00
|
|
|
}
|
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
static int
|
1999-11-04 20:12:43 +03:00
|
|
|
awi_pcmcia_match(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *match;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct pcmcia_attach_args *pa = aux;
|
|
|
|
|
2004-08-10 22:39:08 +04:00
|
|
|
if (pcmcia_product_lookup(pa, awi_pcmcia_products, awi_pcmcia_nproducts,
|
|
|
|
sizeof(awi_pcmcia_products[0]), NULL))
|
1999-11-04 20:12:43 +03:00
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
static int
|
2004-08-10 20:43:47 +04:00
|
|
|
awi_pcmcia_validate_config(cfe)
|
1999-11-04 20:12:43 +03:00
|
|
|
struct pcmcia_config_entry *cfe;
|
|
|
|
{
|
2004-08-10 20:43:47 +04:00
|
|
|
if (cfe->iftype != PCMCIA_IFTYPE_IO ||
|
|
|
|
cfe->num_iospace < 1 ||
|
|
|
|
cfe->iospace[0].length < AM79C930_IO_SIZE)
|
|
|
|
return (EINVAL);
|
|
|
|
if (cfe->num_memspace < 1) {
|
|
|
|
cfe->memspace[0].length = AM79C930_MEM_SIZE;
|
|
|
|
cfe->memspace[0].cardaddr = 0;
|
|
|
|
cfe->memspace[0].hostaddr = 0;
|
|
|
|
} else if (cfe->memspace[0].length < AM79C930_MEM_SIZE)
|
|
|
|
return (EINVAL);
|
|
|
|
return (0);
|
1999-11-04 20:12:43 +03:00
|
|
|
}
|
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
static void
|
1999-11-04 20:12:43 +03:00
|
|
|
awi_pcmcia_attach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
2000-02-01 11:58:25 +03:00
|
|
|
struct awi_pcmcia_softc *psc = (void *)self;
|
1999-11-04 20:12:43 +03:00
|
|
|
struct awi_softc *sc = &psc->sc_awi;
|
|
|
|
struct pcmcia_attach_args *pa = aux;
|
|
|
|
struct pcmcia_config_entry *cfe;
|
2004-08-10 20:43:47 +04:00
|
|
|
int error;
|
2000-02-03 11:52:21 +03:00
|
|
|
|
1999-11-04 20:12:43 +03:00
|
|
|
psc->sc_pf = pa->pf;
|
|
|
|
|
2004-08-10 20:43:47 +04:00
|
|
|
error = pcmcia_function_configure(pa->pf, awi_pcmcia_validate_config);
|
|
|
|
if (error) {
|
|
|
|
aprint_error("%s: configure failed, error=%d\n", self->dv_xname,
|
|
|
|
error);
|
|
|
|
return;
|
1999-11-04 20:12:43 +03:00
|
|
|
}
|
|
|
|
|
2004-08-10 20:43:47 +04:00
|
|
|
cfe = pa->pf->cfe;
|
|
|
|
sc->sc_chip.sc_bustype = AM79C930_BUS_PCMCIA;
|
|
|
|
sc->sc_chip.sc_iot = cfe->iospace[0].handle.iot;
|
|
|
|
sc->sc_chip.sc_ioh = cfe->iospace[0].handle.ioh;
|
|
|
|
if (cfe->num_memspace > 0) {
|
|
|
|
sc->sc_chip.sc_memt = cfe->memspace[0].handle.memt;
|
|
|
|
sc->sc_chip.sc_memh = cfe->memspace[0].handle.memh;
|
1999-11-04 20:48:13 +03:00
|
|
|
am79c930_chip_init(&sc->sc_chip, 1);
|
2004-08-10 20:43:47 +04:00
|
|
|
} else
|
|
|
|
am79c930_chip_init(&sc->sc_chip, 0);
|
|
|
|
|
|
|
|
error = awi_pcmcia_enable(sc);
|
|
|
|
if (error)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
awi_read_bytes(sc, AWI_BANNER, sc->sc_banner, AWI_BANNER_LEN);
|
|
|
|
if (memcmp(sc->sc_banner, "PCnetMobile:", 12))
|
|
|
|
goto fail2;
|
1999-11-04 20:12:43 +03:00
|
|
|
|
|
|
|
sc->sc_enable = awi_pcmcia_enable;
|
|
|
|
sc->sc_disable = awi_pcmcia_disable;
|
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
sc->sc_cansleep = 1;
|
2000-02-01 11:52:05 +03:00
|
|
|
|
2004-08-10 20:43:47 +04:00
|
|
|
psc->sc_state = AWI_PCMCIA_ATTACH1;
|
|
|
|
sc->sc_enabled = 1;
|
2000-03-22 14:22:20 +03:00
|
|
|
if (awi_attach(sc) != 0) {
|
2004-08-10 20:43:47 +04:00
|
|
|
printf("%s: failed to attach controller\n", self->dv_xname);
|
|
|
|
goto fail2;
|
2000-02-01 11:52:05 +03:00
|
|
|
}
|
1999-11-06 19:43:53 +03:00
|
|
|
|
2004-08-10 20:43:47 +04:00
|
|
|
if (psc->sc_state == AWI_PCMCIA_ATTACH1)
|
|
|
|
awi_pcmcia_disable(sc);
|
2000-03-22 14:22:20 +03:00
|
|
|
sc->sc_enabled = 0;
|
2004-08-10 20:43:47 +04:00
|
|
|
psc->sc_state = AWI_PCMCIA_ATTACHED;
|
2000-03-22 14:22:20 +03:00
|
|
|
return;
|
1999-11-04 20:12:43 +03:00
|
|
|
|
2004-08-10 20:43:47 +04:00
|
|
|
fail2:
|
|
|
|
awi_pcmcia_disable(sc);
|
|
|
|
sc->sc_enabled = 0;
|
|
|
|
fail:
|
|
|
|
pcmcia_function_unconfigure(pa->pf);
|
1999-11-04 20:12:43 +03:00
|
|
|
}
|
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
static int
|
1999-11-04 20:12:43 +03:00
|
|
|
awi_pcmcia_detach(self, flags)
|
|
|
|
struct device *self;
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
struct awi_pcmcia_softc *psc = (struct awi_pcmcia_softc *)self;
|
2000-03-22 14:22:20 +03:00
|
|
|
int error;
|
|
|
|
|
2004-08-10 20:43:47 +04:00
|
|
|
if (psc->sc_state != AWI_PCMCIA_ATTACHED)
|
2000-03-22 14:22:20 +03:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
error = awi_detach(&psc->sc_awi);
|
2004-08-10 20:43:47 +04:00
|
|
|
if (error)
|
2000-03-22 14:22:20 +03:00
|
|
|
return (error);
|
|
|
|
|
2004-08-10 20:43:47 +04:00
|
|
|
pcmcia_function_unconfigure(psc->sc_pf);
|
1999-11-04 20:12:43 +03:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
return (0);
|
1999-11-04 20:12:43 +03:00
|
|
|
}
|