]> Pileus Git - ~andy/linux/blob - drivers/staging/wlags49_h2/wl_cs.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/uml
[~andy/linux] / drivers / staging / wlags49_h2 / wl_cs.c
1 /*******************************************************************************
2  * Agere Systems Inc.
3  * Wireless device driver for Linux (wlags49).
4  *
5  * Copyright (c) 1998-2003 Agere Systems Inc.
6  * All rights reserved.
7  *   http://www.agere.com
8  *
9  * Initially developed by TriplePoint, Inc.
10  *   http://www.triplepoint.com
11  *
12  *------------------------------------------------------------------------------
13  *
14  *   This file contains processing and initialization specific to Card Services
15  *   devices (PCMCIA, CF).
16  *
17  *------------------------------------------------------------------------------
18  *
19  * SOFTWARE LICENSE
20  *
21  * This software is provided subject to the following terms and conditions,
22  * which you should read carefully before using the software.  Using this
23  * software indicates your acceptance of these terms and conditions.  If you do
24  * not agree with these terms and conditions, do not use the software.
25  *
26  * Copyright (c) 2003 Agere Systems Inc.
27  * All rights reserved.
28  *
29  * Redistribution and use in source or binary forms, with or without
30  * modifications, are permitted provided that the following conditions are met:
31  *
32  * . Redistributions of source code must retain the above copyright notice, this
33  *    list of conditions and the following Disclaimer as comments in the code as
34  *    well as in the documentation and/or other materials provided with the
35  *    distribution.
36  *
37  * . Redistributions in binary form must reproduce the above copyright notice,
38  *    this list of conditions and the following Disclaimer in the documentation
39  *    and/or other materials provided with the distribution.
40  *
41  * . Neither the name of Agere Systems Inc. nor the names of the contributors
42  *    may be used to endorse or promote products derived from this software
43  *    without specific prior written permission.
44  *
45  * Disclaimer
46  *
47  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
48  * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF
49  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  ANY
50  * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN
51  * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY
52  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
53  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
54  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
55  * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT
56  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
57  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
58  * DAMAGE.
59  *
60  ******************************************************************************/
61
62 /*******************************************************************************
63  *  include files
64  ******************************************************************************/
65 #include <wl_version.h>
66
67 #include <linux/kernel.h>
68 #include <linux/sched.h>
69 #include <linux/ptrace.h>
70 #include <linux/ctype.h>
71 #include <linux/string.h>
72 #include <linux/timer.h>
73 #include <linux/interrupt.h>
74 #include <linux/in.h>
75 #include <linux/delay.h>
76 #include <asm/io.h>
77 #include <asm/bitops.h>
78
79 #include <linux/netdevice.h>
80 #include <linux/etherdevice.h>
81 #include <linux/skbuff.h>
82 #include <linux/if_arp.h>
83 #include <linux/ioport.h>
84 #include <linux/module.h>
85
86 #include <pcmcia/cistpl.h>
87 #include <pcmcia/cisreg.h>
88 #include <pcmcia/ciscode.h>
89 #include <pcmcia/ds.h>
90 #include <debug.h>
91
92 #include <hcf.h>
93 #include <dhf.h>
94 #include <hcfdef.h>
95
96 #include <wl_if.h>
97 #include <wl_internal.h>
98 #include <wl_util.h>
99 #include <wl_main.h>
100 #include <wl_netdev.h>
101 #include <wl_cs.h>
102
103 /*******************************************************************************
104  *      wl_adapter_attach()
105  *******************************************************************************
106  *
107  *  DESCRIPTION:
108  *
109  *      Creates an instance of the driver, allocating local data structures for
110  *  one device. The device is registered with Card Services.
111  *
112  *  PARAMETERS:
113  *
114  *      none
115  *
116  *  RETURNS:
117  *
118  *      pointer to an allocated dev_link_t structure
119  *      NULL on failure
120  *
121  ******************************************************************************/
122 static int wl_adapter_attach(struct pcmcia_device *link)
123 {
124         struct net_device   *dev;
125         struct wl_private   *lp;
126         int ret;
127
128         dev = wl_device_alloc();
129         if (dev == NULL) {
130                 DBG_ERROR(DbgInfo, "wl_device_alloc returned NULL\n");
131                 return -ENOMEM;
132         }
133
134         link->resource[0]->end  = HCF_NUM_IO_PORTS;
135         link->resource[0]->flags= IO_DATA_PATH_WIDTH_16;
136         link->config_flags     |= CONF_ENABLE_IRQ;
137         link->config_index      = 5;
138         link->config_regs       = PRESENT_OPTION;
139
140         link->priv = dev;
141         lp = wl_priv(dev);
142         lp->link = link;
143
144         ret = wl_adapter_insert(link);
145         if (ret != 0)
146                 wl_device_dealloc(dev);
147
148         return ret;
149 } /* wl_adapter_attach */
150 /*============================================================================*/
151
152
153
154 static void wl_adapter_detach(struct pcmcia_device *link)
155 {
156         struct net_device   *dev = link->priv;
157
158         DBG_PARAM(DbgInfo, "link", "0x%p", link);
159
160         wl_adapter_release(link);
161
162         if (dev) {
163                 unregister_netdev(dev);
164                 wl_device_dealloc(dev);
165         }
166 } /* wl_adapter_detach */
167 /*============================================================================*/
168
169
170 void wl_adapter_release(struct pcmcia_device *link)
171 {
172         DBG_PARAM(DbgInfo, "link", "0x%p", link);
173
174         /* Stop hardware */
175         wl_remove(link->priv);
176
177         pcmcia_disable_device(link);
178 } /* wl_adapter_release */
179 /*============================================================================*/
180
181 static int wl_adapter_suspend(struct pcmcia_device *link)
182 {
183         struct net_device *dev = link->priv;
184
185         /* if (link->open) { */
186         netif_device_detach(dev);
187         wl_suspend(dev);
188         /* CHECK! pcmcia_release_configuration(link->handle); */
189         /* } */
190
191         return 0;
192 } /* wl_adapter_suspend */
193
194 static int wl_adapter_resume(struct pcmcia_device *link)
195 {
196         struct net_device *dev = link->priv;
197
198         wl_resume(dev);
199
200         netif_device_attach(dev);
201
202         return 0;
203 } /* wl_adapter_resume */
204
205 int wl_adapter_insert(struct pcmcia_device *link)
206 {
207         struct net_device *dev;
208         int ret;
209
210         DBG_PARAM(DbgInfo, "link", "0x%p", link);
211
212         dev     = link->priv;
213
214         /* Do we need to allocate an interrupt? */
215         link->config_flags |= CONF_ENABLE_IRQ;
216         link->io_lines = 6;
217
218         ret = pcmcia_request_io(link);
219         if (ret != 0)
220                 goto failed;
221
222         ret = pcmcia_request_irq(link, (void *) wl_isr);
223         if (ret != 0)
224                 goto failed;
225
226         ret = pcmcia_enable_device(link);
227         if (ret != 0)
228                 goto failed;
229
230         dev->irq        = link->irq;
231         dev->base_addr  = link->resource[0]->start;
232
233         SET_NETDEV_DEV(dev, &link->dev);
234         ret = register_netdev(dev);
235         if (ret != 0) {
236                 printk("%s: register_netdev() failed\n", KBUILD_MODNAME);
237                 goto failed;
238         }
239
240         printk(KERN_INFO "%s: Wireless, io_addr %#03lx, irq %d, mac_address"
241                 " %pM\n", dev->name, dev->base_addr, dev->irq, dev->dev_addr);
242
243         return 0;
244
245 failed:
246         wl_adapter_release(link);
247         return ret;
248 } /* wl_adapter_insert */
249 /*============================================================================*/
250
251
252 /*******************************************************************************
253  *      wl_adapter_open()
254  *******************************************************************************
255  *
256  *  DESCRIPTION:
257  *
258  *      Open the device.
259  *
260  *  PARAMETERS:
261  *
262  *      dev - a pointer to a net_device structure representing the network
263  *            device to open.
264  *
265  *  RETURNS:
266  *
267  *      0 on success
268  *      errno value otherwise
269  *
270  ******************************************************************************/
271 int wl_adapter_open(struct net_device *dev)
272 {
273         struct wl_private *lp = wl_priv(dev);
274         struct pcmcia_device *link = lp->link;
275         int result = 0;
276         int hcf_status = HCF_SUCCESS;
277
278         DBG_PRINT("%s\n", VERSION_INFO);
279         DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
280
281         if (!pcmcia_dev_present(link))
282                 return -ENODEV;
283
284         link->open++;
285
286         hcf_status = wl_open(dev);
287
288         if (hcf_status != HCF_SUCCESS) {
289                 link->open--;
290                 result = -ENODEV;
291         }
292
293         return result;
294 } /* wl_adapter_open */
295 /*============================================================================*/
296
297
298 /*******************************************************************************
299  *      wl_adapter_close()
300  *******************************************************************************
301  *
302  *  DESCRIPTION:
303  *
304  *      Close the device.
305  *
306  *  PARAMETERS:
307  *
308  *      dev - a pointer to a net_device structure representing the network
309  *            device to close.
310  *
311  *  RETURNS:
312  *
313  *      0 on success
314  *      errno value otherwise
315  *
316  ******************************************************************************/
317 int wl_adapter_close(struct net_device *dev)
318 {
319         struct wl_private *lp = wl_priv(dev);
320         struct pcmcia_device *link = lp->link;
321
322         DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
323
324         if (link == NULL)
325                 return -ENODEV;
326
327         DBG_TRACE(DbgInfo, "%s: Shutting down adapter.\n", dev->name);
328         wl_close(dev);
329
330         link->open--;
331
332         return 0;
333 } /* wl_adapter_close */
334 /*============================================================================*/
335
336 static const struct pcmcia_device_id wl_adapter_ids[] = {
337 #if !((HCF_TYPE) & HCF_TYPE_HII5)
338         PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0003),
339         PCMCIA_DEVICE_PROD_ID12("Agere Systems", "Wireless PC Card Model 0110",
340                                 0x33103a9b, 0xe175b0dd),
341 #else
342         PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0004),
343         PCMCIA_DEVICE_PROD_ID12("Linksys", "WCF54G_Wireless-G_CompactFlash_Card",
344                                 0x0733cc81, 0x98a599e1),
345 #endif  /* (HCF_TYPE) & HCF_TYPE_HII5 */
346         PCMCIA_DEVICE_NULL,
347 };
348 MODULE_DEVICE_TABLE(pcmcia, wl_adapter_ids);
349
350 static struct pcmcia_driver wlags49_driver = {
351         .owner      = THIS_MODULE,
352         .name       = DRIVER_NAME,
353         .probe      = wl_adapter_attach,
354         .remove     = wl_adapter_detach,
355         .id_table   = wl_adapter_ids,
356         .suspend    = wl_adapter_suspend,
357         .resume     = wl_adapter_resume,
358 };
359
360
361
362 /*******************************************************************************
363  *      wl_adapter_init_module()
364  *******************************************************************************
365  *
366  *  DESCRIPTION:
367  *
368  *      Called by init_module() to perform PCMCIA driver initialization.
369  *
370  *  PARAMETERS:
371  *
372  *      N/A
373  *
374  *  RETURNS:
375  *
376  *      0 on success
377  *      -1 on error
378  *
379  ******************************************************************************/
380 int wl_adapter_init_module(void)
381 {
382         return pcmcia_register_driver(&wlags49_driver);
383 } /* wl_adapter_init_module */
384 /*============================================================================*/
385
386
387 /*******************************************************************************
388  *      wl_adapter_cleanup_module()
389  *******************************************************************************
390  *
391  *  DESCRIPTION:
392  *
393  *      Called by cleanup_module() to perform driver uninitialization.
394  *
395  *  PARAMETERS:
396  *
397  *      N/A
398  *
399  *  RETURNS:
400  *
401  *      N/A
402  *
403  ******************************************************************************/
404 void wl_adapter_cleanup_module(void)
405 {
406         pcmcia_unregister_driver(&wlags49_driver);
407 } /* wl_adapter_cleanup_module */
408 /*============================================================================*/
409
410
411 /*******************************************************************************
412  *      wl_adapter_is_open()
413  *******************************************************************************
414  *
415  *  DESCRIPTION:
416  *
417  *      Check with Card Services to determine if this device is open.
418  *
419  *  PARAMETERS:
420  *
421  *      dev - a pointer to the net_device structure whose open status will be
422  *            checked
423  *
424  *  RETURNS:
425  *
426  *      nonzero if device is open
427  *      0 otherwise
428  *
429  ******************************************************************************/
430 int wl_adapter_is_open(struct net_device *dev)
431 {
432         struct wl_private *lp = wl_priv(dev);
433         struct pcmcia_device *link = lp->link;
434
435         if (!pcmcia_dev_present(link))
436                 return 0;
437
438         return link->open;
439 } /* wl_adapter_is_open */
440 /*============================================================================*/