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: releng/10.3/sys/dev/an/if_an_pccard.c 265614 2014-05-07 21:38:33Z gavin $");
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 */
8055992Swpaulstatic int  an_pccard_probe(device_t);
8155992Swpaulstatic int  an_pccard_attach(device_t);
8255992Swpaul
8355992Swpaulstatic device_method_t an_pccard_methods[] = {
8455992Swpaul	/* Device interface */
85150448Simp	DEVMETHOD(device_probe,		an_pccard_probe),
86150448Simp	DEVMETHOD(device_attach,	an_pccard_attach),
87123978Sambrisko	DEVMETHOD(device_detach,	an_detach),
8855992Swpaul	DEVMETHOD(device_shutdown,	an_shutdown),
8955992Swpaul
9055992Swpaul	{ 0, 0 }
9155992Swpaul};
9255992Swpaul
9355992Swpaulstatic driver_t an_pccard_driver = {
9455992Swpaul	"an",
9555992Swpaul	an_pccard_methods,
9655992Swpaul	sizeof(struct an_softc)
9755992Swpaul};
9855992Swpaul
9955992Swpaulstatic devclass_t an_pccard_devclass;
10055992Swpaul
101113506SmdoddDRIVER_MODULE(an, pccard, an_pccard_driver, an_pccard_devclass, 0, 0);
102113506SmdoddMODULE_DEPEND(an, wlan, 1, 1, 1);
10355992Swpaul
10486382Simpstatic const struct pccard_product an_pccard_products[] = {
105147580Simp	PCMCIA_CARD(AIRONET, PC4800),
106147580Simp	PCMCIA_CARD(AIRONET, PC4500),
107147580Simp	PCMCIA_CARD(AIRONET, 350),
108147580Simp	PCMCIA_CARD(XIRCOM, CWE1130),
10986385Simp	{ NULL }
11086382Simp};
11186382Simp
11283270Sbrooksstatic int
113150448Simpan_pccard_probe(device_t dev)
11486382Simp{
11586382Simp	const struct pccard_product *pp;
11686382Simp
11786382Simp	if ((pp = pccard_product_lookup(dev, an_pccard_products,
11886386Simp	    sizeof(an_pccard_products[0]), NULL)) != NULL) {
119113315Simp		if (pp->pp_name != NULL)
120113315Simp			device_set_desc(dev, pp->pp_name);
12186386Simp		return (0);
12286382Simp	}
12386386Simp	return (ENXIO);
12486382Simp}
12586382Simp
12686382Simpstatic int
127150448Simpan_pccard_attach(device_t dev)
12855992Swpaul{
129150448Simp	struct an_softc *sc = device_get_softc(dev);
130150448Simp	int flags = device_get_flags(dev);
13155992Swpaul	int     error;
13255992Swpaul
13355992Swpaul	error = an_probe(dev); /* 0 is failure for now */
134150448Simp	if (error == 0) {
135150448Simp		error = ENXIO;
136150448Simp		goto fail;
137150448Simp	}
138150448Simp	error = an_alloc_irq(dev, 0, 0);
139150448Simp	if (error != 0)
140150448Simp		goto fail;
14155992Swpaul
14255992Swpaul	an_alloc_irq(dev, sc->irq_rid, 0);
14383270Sbrooks
144198995Sjhb	error = an_attach(sc, flags);
145150447Simp	if (error)
146113316Simp		goto fail;
147113316Simp
148113316Simp	/*
149113316Simp	 * Must setup the interrupt after the an_attach to prevent racing.
150113316Simp	 */
15155992Swpaul	error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
152166901Spiso			       NULL, an_intr, sc, &sc->irq_handle);
153113316Simpfail:
154113316Simp	if (error)
155113316Simp		an_release_resources(dev);
15655992Swpaul	return (error);
15783270Sbrooks}
158