if_an_pccard.c revision 147580
1139749Simp/*-
255992Swpaul * Copyright (c) 1997, 1998, 1999
355992Swpaul *	Bill Paul <wpaul@ctr.columbia.edu>.  All rights reserved.
455992Swpaul *
555992Swpaul * Redistribution and use in source and binary forms, with or without
655992Swpaul * modification, are permitted provided that the following conditions
755992Swpaul * are met:
855992Swpaul * 1. Redistributions of source code must retain the above copyright
955992Swpaul *    notice, this list of conditions and the following disclaimer.
1055992Swpaul * 2. Redistributions in binary form must reproduce the above copyright
1155992Swpaul *    notice, this list of conditions and the following disclaimer in the
1255992Swpaul *    documentation and/or other materials provided with the distribution.
1355992Swpaul * 3. All advertising materials mentioning features or use of this software
1455992Swpaul *    must display the following acknowledgement:
1555992Swpaul *	This product includes software developed by Bill Paul.
1655992Swpaul * 4. Neither the name of the author nor the names of any co-contributors
1755992Swpaul *    may be used to endorse or promote products derived from this software
1855992Swpaul *    without specific prior written permission.
1955992Swpaul *
2055992Swpaul * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
2155992Swpaul * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2255992Swpaul * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2355992Swpaul * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
2455992Swpaul * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2555992Swpaul * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2655992Swpaul * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2755992Swpaul * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2855992Swpaul * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2955992Swpaul * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3055992Swpaul * THE POSSIBILITY OF SUCH DAMAGE.
3155992Swpaul */
3255992Swpaul/*
3355992Swpaul * Aironet 4500/4800 802.11 PCMCIA/ISA/PCI driver for FreeBSD.
3455992Swpaul *
3555992Swpaul * Written by Bill Paul <wpaul@ctr.columbia.edu>
3655992Swpaul * Electrical Engineering Department
3755992Swpaul * Columbia University, New York City
3855992Swpaul */
3955992Swpaul
40113038Sobrien#include <sys/cdefs.h>
41113038Sobrien__FBSDID("$FreeBSD: head/sys/dev/an/if_an_pccard.c 147580 2005-06-24 14:36:54Z imp $");
42113038Sobrien
4355992Swpaul#include "opt_inet.h"
4455992Swpaul
4555992Swpaul#ifdef INET
4655992Swpaul#define ANCACHE
4755992Swpaul#endif
4855992Swpaul
4955992Swpaul#include <sys/param.h>
5055992Swpaul#include <sys/systm.h>
5155992Swpaul#include <sys/socket.h>
5255992Swpaul#include <sys/kernel.h>
5355992Swpaul
5455992Swpaul#include <sys/module.h>
5555992Swpaul#include <sys/bus.h>
5655992Swpaul#include <machine/bus.h>
5755992Swpaul#include <sys/rman.h>
5874914Sjhb#include <sys/lock.h>
5967365Sjhb#include <sys/mutex.h>
6055992Swpaul#include <machine/resource.h>
6155992Swpaul
6255992Swpaul#include <net/if.h>
6355992Swpaul#include <net/if_arp.h>
6455992Swpaul#include <net/ethernet.h>
6555992Swpaul#include <net/if_dl.h>
6655992Swpaul#include <net/if_types.h>
6777217Sphk#include <net/if_media.h>
6855992Swpaul
69129764Simp#include <dev/an/if_aironet_ieee.h>
70129764Simp#include <dev/an/if_anreg.h>
71129764Simp
7286382Simp#include <dev/pccard/pccardvar.h>
73129764Simp
74129740Simp#include "pccarddevs.h"
7586382Simp#include "card_if.h"
7686382Simp
7755992Swpaul/*
7855992Swpaul * Support for PCMCIA cards.
7955992Swpaul */
8086382Simpstatic int  an_pccard_match(device_t);
8155992Swpaulstatic int  an_pccard_probe(device_t);
8255992Swpaulstatic int  an_pccard_attach(device_t);
8355992Swpaul
8455992Swpaulstatic device_method_t an_pccard_methods[] = {
8555992Swpaul	/* Device interface */
8686382Simp	DEVMETHOD(device_probe,		pccard_compat_probe),
8786382Simp	DEVMETHOD(device_attach,	pccard_compat_attach),
88123978Sambrisko	DEVMETHOD(device_detach,	an_detach),
8955992Swpaul	DEVMETHOD(device_shutdown,	an_shutdown),
9055992Swpaul
9186382Simp	/* Card interface */
9286382Simp	DEVMETHOD(card_compat_match, 	an_pccard_match),
9386382Simp	DEVMETHOD(card_compat_probe,	an_pccard_probe),
9486382Simp	DEVMETHOD(card_compat_attach,	an_pccard_attach),
9586382Simp
9655992Swpaul	{ 0, 0 }
9755992Swpaul};
9855992Swpaul
9955992Swpaulstatic driver_t an_pccard_driver = {
10055992Swpaul	"an",
10155992Swpaul	an_pccard_methods,
10255992Swpaul	sizeof(struct an_softc)
10355992Swpaul};
10455992Swpaul
10555992Swpaulstatic devclass_t an_pccard_devclass;
10655992Swpaul
107113506SmdoddDRIVER_MODULE(an, pccard, an_pccard_driver, an_pccard_devclass, 0, 0);
108113506SmdoddMODULE_DEPEND(an, wlan, 1, 1, 1);
10955992Swpaul
11086382Simpstatic const struct pccard_product an_pccard_products[] = {
111147580Simp	PCMCIA_CARD(AIRONET, PC4800),
112147580Simp	PCMCIA_CARD(AIRONET, PC4500),
113147580Simp	PCMCIA_CARD(AIRONET, 350),
114147580Simp	PCMCIA_CARD(XIRCOM, CWE1130),
11586385Simp	{ NULL }
11686382Simp};
11786382Simp
11883270Sbrooksstatic int
11986382Simpan_pccard_match(device_t dev)
12086382Simp{
12186382Simp	const struct pccard_product *pp;
12286382Simp
12386382Simp	if ((pp = pccard_product_lookup(dev, an_pccard_products,
12486386Simp	    sizeof(an_pccard_products[0]), NULL)) != NULL) {
125113315Simp		if (pp->pp_name != NULL)
126113315Simp			device_set_desc(dev, pp->pp_name);
12786386Simp		return (0);
12886382Simp	}
12986386Simp	return (ENXIO);
13086382Simp}
13186382Simp
13286382Simpstatic int
13355992Swpaulan_pccard_probe(device_t dev)
13455992Swpaul{
13555992Swpaul	int     error;
13655992Swpaul
13755992Swpaul	error = an_probe(dev); /* 0 is failure for now */
13855992Swpaul	if (error != 0) {
13955992Swpaul		device_set_desc(dev, "Aironet PC4500/PC4800");
14055992Swpaul		error = an_alloc_irq(dev, 0, 0);
14155992Swpaul	} else
14255992Swpaul	        error = 1;
14355992Swpaul	an_release_resources(dev);
14455992Swpaul	return (error);
14555992Swpaul}
14655992Swpaul
14755992Swpaul
14855992Swpaulstatic int
14955992Swpaulan_pccard_attach(device_t dev)
15055992Swpaul{
15155992Swpaul	struct an_softc *sc = device_get_softc(dev);
15255992Swpaul	int flags = device_get_flags(dev);
15355992Swpaul	int error;
15483270Sbrooks
15555992Swpaul	an_alloc_port(dev, sc->port_rid, AN_IOSIZ);
15655992Swpaul	an_alloc_irq(dev, sc->irq_rid, 0);
15783270Sbrooks
158113316Simp	sc->an_bhandle = rman_get_bushandle(sc->port_res);
159113316Simp	sc->an_btag = rman_get_bustag(sc->port_res);
160113316Simp	sc->an_dev = dev;
161113316Simp
162113316Simp	error = an_attach(sc, device_get_unit(dev), flags);
163113316Simp	if (error) {
164113316Simp		goto fail;
165113316Simp	}
166113316Simp
167113316Simp	/*
168113316Simp	 * Must setup the interrupt after the an_attach to prevent racing.
169113316Simp	 */
17055992Swpaul	error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
17155992Swpaul			       an_intr, sc, &sc->irq_handle);
17255992Swpaul	if (error) {
173113316Simp		goto fail;
17455992Swpaul	}
17583270Sbrooks
176113316Simpfail:
177113316Simp	if (error)
178113316Simp		an_release_resources(dev);
17955992Swpaul	return (error);
18083270Sbrooks}
181