if_wi_pccard.c revision 117767
1178476Sjb/*
2178476Sjb * Copyright (c) 1997, 1998, 1999
3178476Sjb *	Bill Paul <wpaul@ctr.columbia.edu>.  All rights reserved.
4178476Sjb *
5178476Sjb * Redistribution and use in source and binary forms, with or without
6178476Sjb * modification, are permitted provided that the following conditions
7178476Sjb * are met:
8178476Sjb * 1. Redistributions of source code must retain the above copyright
9178476Sjb *    notice, this list of conditions and the following disclaimer.
10178476Sjb * 2. Redistributions in binary form must reproduce the above copyright
11178476Sjb *    notice, this list of conditions and the following disclaimer in the
12178476Sjb *    documentation and/or other materials provided with the distribution.
13178476Sjb * 3. All advertising materials mentioning features or use of this software
14178476Sjb *    must display the following acknowledgement:
15178476Sjb *	This product includes software developed by Bill Paul.
16178476Sjb * 4. Neither the name of the author nor the names of any co-contributors
17178476Sjb *    may be used to endorse or promote products derived from this software
18178476Sjb *    without specific prior written permission.
19178476Sjb *
20178476Sjb * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21178476Sjb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22178476Sjb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23178476Sjb * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24178476Sjb * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25178476Sjb * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26178476Sjb * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27178476Sjb * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28178476Sjb * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29178476Sjb * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30178476Sjb * THE POSSIBILITY OF SUCH DAMAGE.
31178476Sjb */
32178476Sjb
33178476Sjb/*
34178476Sjb * Lucent WaveLAN/IEEE 802.11 PCMCIA driver for FreeBSD.
35178476Sjb *
36178476Sjb * Written by Bill Paul <wpaul@ctr.columbia.edu>
37178476Sjb * Electrical Engineering Department
38178476Sjb * Columbia University, New York City
39178476Sjb */
40178476Sjb
41178476Sjb#include <sys/cdefs.h>
42178476Sjb__FBSDID("$FreeBSD: head/sys/dev/wi/if_wi_pccard.c 117767 2003-07-19 05:51:44Z imp $");
43178476Sjb
44178476Sjb#include "opt_wi.h"
45178476Sjb
46178476Sjb#include <sys/param.h>
47#include <sys/kernel.h>
48#include <sys/socket.h>
49#include <sys/systm.h>
50#include <sys/module.h>
51#include <sys/bus.h>
52
53#include <machine/bus.h>
54#include <machine/resource.h>
55#include <sys/rman.h>
56
57#include <net/if.h>
58#include <net/if_arp.h>
59#include <net/ethernet.h>
60#include <net/if_dl.h>
61#include <net/if_media.h>
62#include <net/if_types.h>
63
64#include <net80211/ieee80211_var.h>
65
66#include <dev/pccard/pccardvar.h>
67#if __FreeBSD_version >= 500000
68#include <dev/pccard/pccarddevs.h>
69#endif
70
71#include <dev/wi/if_wavelan_ieee.h>
72#include <dev/wi/if_wivar.h>
73#include <dev/wi/if_wireg.h>
74#ifdef WI_SYMBOL_FIRMWARE
75#include <dev/wi/spectrum24t_cf.h>
76#endif
77
78#include "card_if.h"
79
80static int wi_pccard_probe(device_t);
81static int wi_pccard_attach(device_t);
82
83#if __FreeBSD_version < 500000
84static device_method_t wi_pccard_methods[] = {
85	/* Device interface */
86	DEVMETHOD(device_probe,		wi_pccard_probe),
87	DEVMETHOD(device_attach,	wi_pccard_attach),
88	DEVMETHOD(device_detach,	wi_detach),
89	DEVMETHOD(device_shutdown,	wi_shutdown),
90
91	{ 0, 0 }
92};
93
94#else
95static int wi_pccard_match(device_t);
96
97static device_method_t wi_pccard_methods[] = {
98	/* Device interface */
99	DEVMETHOD(device_probe,		pccard_compat_probe),
100	DEVMETHOD(device_attach,	pccard_compat_attach),
101	DEVMETHOD(device_detach,	wi_detach),
102	DEVMETHOD(device_shutdown,	wi_shutdown),
103
104	/* Card interface */
105	DEVMETHOD(card_compat_match,	wi_pccard_match),
106	DEVMETHOD(card_compat_probe,	wi_pccard_probe),
107	DEVMETHOD(card_compat_attach,	wi_pccard_attach),
108
109	{ 0, 0 }
110};
111
112#endif
113
114static driver_t wi_pccard_driver = {
115	"wi",
116	wi_pccard_methods,
117	sizeof(struct wi_softc)
118};
119
120DRIVER_MODULE(wi, pccard, wi_pccard_driver, wi_devclass, 0, 0);
121MODULE_DEPEND(wi, wlan, 1, 1, 1);
122MODULE_DEPEND(wi, pccard, 1, 1, 1);
123
124#if __FreeBSD_version >= 500000
125static const struct pccard_product wi_pccard_products[] = {
126	PCMCIA_CARD(3COM, 3CRWE737A, 0),
127	PCMCIA_CARD(3COM, 3CRWE777A, 0),
128	PCMCIA_CARD(ACTIONTEC, PRISM, 0),
129	PCMCIA_CARD(ADDTRON, AWP100, 0),
130	PCMCIA_CARD(AIRVAST, WN_100, 0),
131	PCMCIA_CARD(ALLIEDTELESIS, WR211PCM, 0),
132	PCMCIA_CARD(ARTEM, ONAIR, 0),
133 	PCMCIA_CARD(ASUS, WL100, 0),
134	PCMCIA_CARD(BAY, EMOBILITY_11B, 0),
135	PCMCIA_CARD(BUFFALO, WLI_PCM_S11, 0),
136	PCMCIA_CARD(BUFFALO, WLI_CF_S11G, 0),
137	PCMCIA_CARD(COMPAQ, NC5004, 0),
138	PCMCIA_CARD(CONTEC, FX_DS110_PCC, 0),
139	PCMCIA_CARD(COREGA, WIRELESS_LAN_PCC_11, 0),
140	PCMCIA_CARD(COREGA, WIRELESS_LAN_PCCA_11, 0),
141	PCMCIA_CARD(COREGA, WIRELESS_LAN_PCCB_11, 0),
142	PCMCIA_CARD(COREGA, WIRELESS_LAN_PCCL_11, 0),
143	PCMCIA_CARD(DLINK, DWL650H, 0),
144	PCMCIA_CARD(ELSA, XI300_IEEE, 0),
145	PCMCIA_CARD(ELSA, XI325_IEEE, 0),
146	PCMCIA_CARD(ELSA, XI800_IEEE, 0),
147	PCMCIA_CARD(EMTAC, WLAN, 0),
148	PCMCIA_CARD(ERICSSON, WIRELESSLAN, 0),
149	PCMCIA_CARD(GEMTEK, WLAN, 0),
150	PCMCIA_CARD(HWN, AIRWAY80211, 0),
151	PCMCIA_CARD(INTEL, PRO_WLAN_2011, 0),
152	PCMCIA_CARD(INTERSIL, PRISM2, 0),
153	PCMCIA_CARD(IODATA2, WNB11PCM, 0),
154	PCMCIA_CARD(IODATA2, WCF12, 0),
155	PCMCIA_CARD(LINKSYS2, IWN, 0),
156	PCMCIA_CARD(LINKSYS2, IWN3, 0),
157	PCMCIA_CARD(LINKSYS2, WCF11, 0),
158	PCMCIA_CARD(LUCENT, WAVELAN_IEEE, 0),
159	PCMCIA_CARD(NETGEAR_2, MA401RA, 0),
160	PCMCIA_CARD(NOKIA, C020_WLAN, 0),
161	PCMCIA_CARD(NOKIA, C110_WLAN, 0),
162	PCMCIA_CARD(PLANEX_2, GWNS11H, 0),
163	PCMCIA_CARD(PROXIM, RANGELANDS_8430, 0),
164	PCMCIA_CARD(SAMSUNG, SWL_2000N, 0),
165	PCMCIA_CARD(SIEMENS, SS1021, 0),
166	PCMCIA_CARD(SIMPLETECH, SPECTRUM24_ALT, 0),
167	PCMCIA_CARD(SOCKET, LP_WLAN_CF, 0),
168	PCMCIA_CARD(SYMBOL, LA4100, 0),
169	PCMCIA_CARD(TDK, LAK_CD011WL, 0),
170	{ NULL }
171};
172
173static int
174wi_pccard_match(dev)
175	device_t	dev;
176{
177	const struct pccard_product *pp;
178
179	if ((pp = pccard_product_lookup(dev, wi_pccard_products,
180	    sizeof(wi_pccard_products[0]), NULL)) != NULL) {
181		if (pp->pp_name != NULL)
182			device_set_desc(dev, pp->pp_name);
183		return (0);
184	}
185	return (ENXIO);
186}
187#endif
188
189static int
190wi_pccard_probe(dev)
191	device_t	dev;
192{
193	struct wi_softc	*sc;
194	int		error;
195
196	sc = device_get_softc(dev);
197	sc->wi_gone = 0;
198	sc->wi_bus_type = WI_BUS_PCCARD;
199
200	error = wi_alloc(dev, 0);
201	if (error)
202		return (error);
203
204	wi_free(dev);
205
206	/* Make sure interrupts are disabled. */
207	CSR_WRITE_2(sc, WI_INT_EN, 0);
208	CSR_WRITE_2(sc, WI_EVENT_ACK, 0xFFFF);
209
210	return (0);
211}
212
213static int
214wi_pccard_attach(device_t dev)
215{
216	struct wi_softc		*sc;
217	int			error;
218	uint32_t		vendor;
219	uint32_t		product;
220	int			retval;
221
222	sc = device_get_softc(dev);
223
224	error = wi_alloc(dev, 0);
225	if (error) {
226		device_printf(dev, "wi_alloc() failed! (%d)\n", error);
227		return (error);
228	}
229
230#if __FreeBSD_version > 500000
231	/*
232	 * The cute little Symbol LA4100-series CF cards need to have
233	 * code downloaded to them.
234	 */
235	pccard_get_vendor(dev, &vendor);
236	pccard_get_product(dev, &product);
237	if (vendor == PCMCIA_VENDOR_SYMBOL &&
238	    product == PCMCIA_PRODUCT_SYMBOL_LA4100) {
239#ifdef WI_SYMBOL_FIRMWARE
240		if (wi_symbol_load_firm(sc,
241		    spectrum24t_primsym, sizeof(spectrum24t_primsym),
242		    spectrum24t_secsym, sizeof(spectrum24t_secsym))) {
243			device_printf(dev, "couldn't load firmware\n");
244		}
245#else
246		device_printf(dev,
247		    "Symbol LA4100 needs 'option WI_SYMBOL_FIRMWARE'\n");
248		wi_free(dev);
249		return (ENXIO);
250#endif
251	}
252#endif
253	retval = wi_attach(dev);
254	if (retval != 0)
255		wi_free(dev);
256	return (retval);
257}
258