Add Sample and Onoe TX rate control algorithm support in 2661/2561 part
[dragonfly.git] / sys / dev / netif / wi / if_wi_pccard.c
1 /*
2  * Copyright (c) 1997, 1998, 1999
3  *      Bill Paul <wpaul@ctr.columbia.edu>.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by Bill Paul.
16  * 4. Neither the name of the author nor the names of any co-contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30  * THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * $FreeBSD: src/sys/dev/wi/if_wi_pccard.c,v 1.47 2004/06/09 06:31:40 imp Exp $
33  * $DragonFly: src/sys/dev/netif/wi/if_wi_pccard.c,v 1.10 2006/10/25 20:55:59 dillon Exp $
34  */
35
36 /*
37  * Lucent WaveLAN/IEEE 802.11 PCMCIA driver for FreeBSD.
38  *
39  * Written by Bill Paul <wpaul@ctr.columbia.edu>
40  * Electrical Engineering Department
41  * Columbia University, New York City
42  */
43
44 #include "opt_wi.h"
45
46 #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 #include <sys/thread.h>
53 #include <sys/rman.h>
54
55 #include <net/if.h>
56 #include <net/if_arp.h>
57 #include <net/ethernet.h>
58 #include <net/if_dl.h>
59 #include <net/if_media.h>
60 #include <net/if_types.h>
61
62 #include <netproto/802_11/ieee80211_var.h>
63 #include <netproto/802_11/ieee80211_radiotap.h>
64 #include <netproto/802_11/if_wavelan_ieee.h>
65
66 #include <bus/pccard/pccardreg.h>
67 #include <bus/pccard/pccardvar.h>
68 #include <bus/pccard/pccarddevs.h>
69
70 #include <dev/netif/wi/if_wireg.h>
71 #include <dev/netif/wi/if_wivar.h>
72 #ifdef WI_SYMBOL_FIRMWARE
73 #include <dev/netif/wi/spectrum24t_cf.h>
74 #endif
75
76 #include "card_if.h"
77
78 static int wi_pccard_probe(device_t);
79 static int wi_pccard_attach(device_t);
80
81 static int wi_pccard_match(device_t);
82
83 static device_method_t wi_pccard_methods[] = {
84         /* Device interface */
85         DEVMETHOD(device_probe,         pccard_compat_probe),
86         DEVMETHOD(device_attach,        pccard_compat_attach),
87         DEVMETHOD(device_detach,        wi_detach),
88         DEVMETHOD(device_shutdown,      wi_shutdown),
89
90         /* Card interface */
91         DEVMETHOD(card_compat_match,    wi_pccard_match),
92         DEVMETHOD(card_compat_probe,    wi_pccard_probe),
93         DEVMETHOD(card_compat_attach,   wi_pccard_attach),
94
95         { 0, 0 }
96 };
97
98 static driver_t wi_pccard_driver = {
99         "wi",
100         wi_pccard_methods,
101         sizeof(struct wi_softc)
102 };
103
104 DRIVER_MODULE(wi, pccard, wi_pccard_driver, wi_devclass, 0, 0);
105 MODULE_DEPEND(wi, wlan, 1, 1, 1);
106
107 static const struct pccard_product wi_pccard_products[] = {
108         PCMCIA_CARD(3COM, 3CRWE737A, 0),
109         PCMCIA_CARD(3COM, 3CRWE777A, 0),
110         PCMCIA_CARD(ACTIONTEC, PRISM, 0),
111         PCMCIA_CARD(ADDTRON, AWP100, 0),
112         PCMCIA_CARD(AIRVAST, WN_100, 0),
113         PCMCIA_CARD(ALLIEDTELESIS, WR211PCM, 0),
114         PCMCIA_CARD(ARTEM, ONAIR, 0),
115         PCMCIA_CARD(ASUS, WL100, 0),
116         PCMCIA_CARD(BAY, EMOBILITY_11B, 0),
117         PCMCIA_CARD(BROMAX, IWN, 0),
118         PCMCIA_CARD(BROMAX, IWN3, 0),
119         PCMCIA_CARD(BROMAX, WCF11, 0),
120         PCMCIA_CARD(BUFFALO, WLI_CF_S11G, 0),
121         PCMCIA_CARD(BUFFALO, WLI_PCM_S11, 0),
122         PCMCIA_CARD(COMPAQ, NC5004, 0),
123         PCMCIA_CARD(CONTEC, FX_DS110_PCC, 0),
124         PCMCIA_CARD(COREGA, WIRELESS_LAN_PCC_11, 0),
125         PCMCIA_CARD(COREGA, WIRELESS_LAN_PCCA_11, 0),
126         PCMCIA_CARD(COREGA, WIRELESS_LAN_PCCB_11, 0),
127         PCMCIA_CARD(COREGA, WIRELESS_LAN_PCCL_11, 0),
128         PCMCIA_CARD(DLINK, DWL650H, 0),
129         PCMCIA_CARD(ELSA, XI300_IEEE, 0),
130         PCMCIA_CARD(ELSA, XI325_IEEE, 0),
131         PCMCIA_CARD(ELSA, XI800_IEEE, 0),
132         PCMCIA_CARD(EMTAC, WLAN, 0),
133         PCMCIA_CARD(ERICSSON, WIRELESSLAN, 0),
134         PCMCIA_CARD(GEMTEK, WLAN, 0),
135         PCMCIA_CARD(HWN, AIRWAY80211, 0), 
136         PCMCIA_CARD(INTEL, PRO_WLAN_2011, 0),
137         PCMCIA_CARD(INTERSIL, MA401RA, 0),
138         PCMCIA_CARD(INTERSIL, DWL650, 0),
139         PCMCIA_CARD(INTERSIL2, PRISM2, 0),
140         PCMCIA_CARD(IODATA2, WCF12, 0),
141         PCMCIA_CARD(IODATA2, WNB11PCM, 0),
142         PCMCIA_CARD(FUJITSU, WL110, 0),
143         PCMCIA_CARD(LUCENT, WAVELAN_IEEE, 0),
144         PCMCIA_CARD(MICROSOFT, MN_520, 0),
145         PCMCIA_CARD(NOKIA, C020_WLAN, 0),
146         PCMCIA_CARD(NOKIA, C110_WLAN, 0),
147         PCMCIA_CARD(PLANEX_2, GWNS11H, 0),
148         PCMCIA_CARD(PROXIM, HARMONY, 0),
149         PCMCIA_CARD(PROXIM, RANGELANDS_8430, 0),
150         PCMCIA_CARD(SAMSUNG, SWL_2000N, 0),
151         PCMCIA_CARD(SIEMENS, SS1021, 0),
152         PCMCIA_CARD(SIMPLETECH, SPECTRUM24_ALT, 0),
153         PCMCIA_CARD(SOCKET, LP_WLAN_CF, 0),
154         PCMCIA_CARD(SYMBOL, LA4100, 0),
155         PCMCIA_CARD(TDK, LAK_CD011WL, 0),
156         { NULL }
157 };
158
159 static int
160 wi_pccard_match(device_t dev)
161 {
162         const struct pccard_product *pp;
163         u_int32_t fcn;
164
165         /* Make sure we're a network driver */
166         fcn = pccard_get_function(dev);
167         if (fcn != PCCARD_FUNCTION_NETWORK)
168                 return (ENXIO);
169
170         if ((pp = pccard_product_lookup(dev, wi_pccard_products,
171             sizeof(wi_pccard_products[0]), NULL)) != NULL) {
172                 if (pp->pp_name != NULL)
173                         device_set_desc(dev, pp->pp_name);
174                 return (0);
175         }
176         return (ENXIO);
177 }
178
179 static int
180 wi_pccard_probe(device_t dev)
181 {
182         struct wi_softc *sc;
183         int             error;
184
185         sc = device_get_softc(dev);
186         sc->wi_gone = 0;
187         sc->wi_bus_type = WI_BUS_PCCARD;
188
189         error = wi_alloc(dev, 0);
190         if (error)
191                 return (error);
192
193         /* Make sure interrupts are disabled. */
194         CSR_WRITE_2(sc, WI_INT_EN, 0);
195         CSR_WRITE_2(sc, WI_EVENT_ACK, 0xFFFF);
196
197         wi_free(dev);
198
199         return (0);
200 }
201
202 static int
203 wi_pccard_attach(device_t dev)
204 {
205         struct wi_softc         *sc;
206         int                     error;
207         uint32_t                vendor;
208         uint32_t                product;
209
210         sc = device_get_softc(dev);
211
212         error = wi_alloc(dev, 0);
213         if (error) {
214                 device_printf(dev, "wi_alloc() failed! (%d)\n", error);
215                 return (error);
216         }
217
218         /*
219          * The cute little Symbol LA4100-series CF cards need to have
220          * code downloaded to them.
221          */
222         vendor = pccard_get_vendor(dev);
223         product = pccard_get_product(dev);
224         if (vendor == PCMCIA_VENDOR_SYMBOL &&
225             product == PCMCIA_PRODUCT_SYMBOL_LA4100) {
226 #ifdef WI_SYMBOL_FIRMWARE
227                 if (wi_symbol_load_firm(sc,
228                     spectrum24t_primsym, sizeof(spectrum24t_primsym),
229                     spectrum24t_secsym, sizeof(spectrum24t_secsym))) {
230                         device_printf(dev, "couldn't load firmware\n");
231                         return (ENXIO);
232                 }
233 #else
234                 device_printf(dev,
235                     "Symbol LA4100 needs 'option WI_SYMBOL_FIRMWARE'\n");
236                 wi_free(dev);
237                 return (ENXIO);
238 #endif
239         }
240         return wi_attach(dev);
241 }