]> Pileus Git - ~andy/linux/blob - drivers/staging/wlags49_h2/wl_cs.c
a33eea140113663587845219e26893b2f3efcb21
[~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 /*******************************************************************************
105  *  global definitions
106  ******************************************************************************/
107 #if DBG
108 extern dbg_info_t *DbgInfo;
109 #endif  /* DBG */
110
111
112 /*******************************************************************************
113  *      wl_adapter_attach()
114  *******************************************************************************
115  *
116  *  DESCRIPTION:
117  *
118  *      Creates an instance of the driver, allocating local data structures for
119  *  one device. The device is registered with Card Services.
120  *
121  *  PARAMETERS:
122  *
123  *      none
124  *
125  *  RETURNS:
126  *
127  *      pointer to an allocated dev_link_t structure
128  *      NULL on failure
129  *
130  ******************************************************************************/
131 static int wl_adapter_attach(struct pcmcia_device *link)
132 {
133         struct net_device   *dev;
134         struct wl_private   *lp;
135         int ret;
136
137         dev = wl_device_alloc();
138         if (dev == NULL) {
139                 DBG_ERROR(DbgInfo, "wl_device_alloc returned NULL\n");
140                 return -ENOMEM;
141         }
142
143         link->resource[0]->end  = HCF_NUM_IO_PORTS;
144         link->resource[0]->flags= IO_DATA_PATH_WIDTH_16;
145         link->config_flags     |= CONF_ENABLE_IRQ;
146         link->config_index      = 5;
147         link->config_regs       = PRESENT_OPTION;
148
149         link->priv = dev;
150         lp = wl_priv(dev);
151         lp->link = link;
152
153         ret = wl_adapter_insert(link);
154         if (ret != 0)
155                 wl_device_dealloc(dev);
156
157         return ret;
158 } /* wl_adapter_attach */
159 /*============================================================================*/
160
161
162
163 static void wl_adapter_detach(struct pcmcia_device *link)
164 {
165         struct net_device   *dev = link->priv;
166
167         DBG_PARAM(DbgInfo, "link", "0x%p", link);
168
169         wl_adapter_release(link);
170
171         if (dev) {
172                 unregister_netdev(dev);
173                 wl_device_dealloc(dev);
174         }
175 } /* wl_adapter_detach */
176 /*============================================================================*/
177
178
179 void wl_adapter_release(struct pcmcia_device *link)
180 {
181         DBG_PARAM(DbgInfo, "link", "0x%p", link);
182
183         /* Stop hardware */
184         wl_remove(link->priv);
185
186         pcmcia_disable_device(link);
187 } /* wl_adapter_release */
188 /*============================================================================*/
189
190 static int wl_adapter_suspend(struct pcmcia_device *link)
191 {
192         struct net_device *dev = link->priv;
193
194         /* if (link->open) { */
195         netif_device_detach(dev);
196         wl_suspend(dev);
197         /* CHECK! pcmcia_release_configuration(link->handle); */
198         /* } */
199
200         return 0;
201 } /* wl_adapter_suspend */
202
203 static int wl_adapter_resume(struct pcmcia_device *link)
204 {
205         struct net_device *dev = link->priv;
206
207         wl_resume(dev);
208
209         netif_device_attach(dev);
210
211         return 0;
212 } /* wl_adapter_resume */
213
214 int wl_adapter_insert(struct pcmcia_device *link)
215 {
216         struct net_device *dev;
217         int ret;
218
219         DBG_PARAM(DbgInfo, "link", "0x%p", link);
220
221         dev     = link->priv;
222
223         /* Do we need to allocate an interrupt? */
224         link->config_flags |= CONF_ENABLE_IRQ;
225         link->io_lines = 6;
226
227         ret = pcmcia_request_io(link);
228         if (ret != 0)
229                 goto failed;
230
231         ret = pcmcia_request_irq(link, (void *) wl_isr);
232         if (ret != 0)
233                 goto failed;
234
235         ret = pcmcia_enable_device(link);
236         if (ret != 0)
237                 goto failed;
238
239         dev->irq        = link->irq;
240         dev->base_addr  = link->resource[0]->start;
241
242         SET_NETDEV_DEV(dev, &link->dev);
243         ret = register_netdev(dev);
244         if (ret != 0) {
245                 printk("%s: register_netdev() failed\n", MODULE_NAME);
246                 goto failed;
247         }
248
249         printk(KERN_INFO "%s: Wireless, io_addr %#03lx, irq %d, mac_address"
250                 " %pM\n", dev->name, dev->base_addr, dev->irq, dev->dev_addr);
251
252         return 0;
253
254 failed:
255         wl_adapter_release(link);
256         return ret;
257 } /* wl_adapter_insert */
258 /*============================================================================*/
259
260
261 /*******************************************************************************
262  *      wl_adapter_open()
263  *******************************************************************************
264  *
265  *  DESCRIPTION:
266  *
267  *      Open the device.
268  *
269  *  PARAMETERS:
270  *
271  *      dev - a pointer to a net_device structure representing the network
272  *            device to open.
273  *
274  *  RETURNS:
275  *
276  *      0 on success
277  *      errno value otherwise
278  *
279  ******************************************************************************/
280 int wl_adapter_open(struct net_device *dev)
281 {
282         struct wl_private *lp = wl_priv(dev);
283         struct pcmcia_device *link = lp->link;
284         int result = 0;
285         int hcf_status = HCF_SUCCESS;
286
287         DBG_PRINT("%s\n", VERSION_INFO);
288         DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
289
290         if (!pcmcia_dev_present(link))
291                 return -ENODEV;
292
293         link->open++;
294
295         hcf_status = wl_open(dev);
296
297         if (hcf_status != HCF_SUCCESS) {
298                 link->open--;
299                 result = -ENODEV;
300         }
301
302         return result;
303 } /* wl_adapter_open */
304 /*============================================================================*/
305
306
307 /*******************************************************************************
308  *      wl_adapter_close()
309  *******************************************************************************
310  *
311  *  DESCRIPTION:
312  *
313  *      Close the device.
314  *
315  *  PARAMETERS:
316  *
317  *      dev - a pointer to a net_device structure representing the network
318  *            device to close.
319  *
320  *  RETURNS:
321  *
322  *      0 on success
323  *      errno value otherwise
324  *
325  ******************************************************************************/
326 int wl_adapter_close(struct net_device *dev)
327 {
328         struct wl_private *lp = wl_priv(dev);
329         struct pcmcia_device *link = lp->link;
330
331         DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
332
333         if (link == NULL)
334                 return -ENODEV;
335
336         DBG_TRACE(DbgInfo, "%s: Shutting down adapter.\n", dev->name);
337         wl_close(dev);
338
339         link->open--;
340
341         return 0;
342 } /* wl_adapter_close */
343 /*============================================================================*/
344
345 static const struct pcmcia_device_id wl_adapter_ids[] = {
346 #if !((HCF_TYPE) & HCF_TYPE_HII5)
347         PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0003),
348         PCMCIA_DEVICE_PROD_ID12("Agere Systems", "Wireless PC Card Model 0110",
349                                 0x33103a9b, 0xe175b0dd),
350 #else
351         PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0004),
352         PCMCIA_DEVICE_PROD_ID12("Linksys", "WCF54G_Wireless-G_CompactFlash_Card",
353                                 0x0733cc81, 0x98a599e1),
354 #endif  /* (HCF_TYPE) & HCF_TYPE_HII5 */
355         PCMCIA_DEVICE_NULL,
356 };
357 MODULE_DEVICE_TABLE(pcmcia, wl_adapter_ids);
358
359 static struct pcmcia_driver wlags49_driver = {
360         .owner      = THIS_MODULE,
361         .name       = DRIVER_NAME,
362         .probe      = wl_adapter_attach,
363         .remove     = wl_adapter_detach,
364         .id_table   = wl_adapter_ids,
365         .suspend    = wl_adapter_suspend,
366         .resume     = wl_adapter_resume,
367 };
368
369
370
371 /*******************************************************************************
372  *      wl_adapter_init_module()
373  *******************************************************************************
374  *
375  *  DESCRIPTION:
376  *
377  *      Called by init_module() to perform PCMCIA driver initialization.
378  *
379  *  PARAMETERS:
380  *
381  *      N/A
382  *
383  *  RETURNS:
384  *
385  *      0 on success
386  *      -1 on error
387  *
388  ******************************************************************************/
389 int wl_adapter_init_module(void)
390 {
391         int ret;
392
393         DBG_TRACE(DbgInfo, "wl_adapter_init_module() -- PCMCIA\n");
394
395         ret = pcmcia_register_driver(&wlags49_driver);
396
397         return ret;
398 } /* wl_adapter_init_module */
399 /*============================================================================*/
400
401
402 /*******************************************************************************
403  *      wl_adapter_cleanup_module()
404  *******************************************************************************
405  *
406  *  DESCRIPTION:
407  *
408  *      Called by cleanup_module() to perform driver uninitialization.
409  *
410  *  PARAMETERS:
411  *
412  *      N/A
413  *
414  *  RETURNS:
415  *
416  *      N/A
417  *
418  ******************************************************************************/
419 void wl_adapter_cleanup_module(void)
420 {
421         DBG_TRACE(DbgInfo, "wl_adapter_cleanup_module() -- PCMCIA\n");
422
423         pcmcia_unregister_driver(&wlags49_driver);
424
425         return;
426 } /* wl_adapter_cleanup_module */
427 /*============================================================================*/
428
429
430 /*******************************************************************************
431  *      wl_adapter_is_open()
432  *******************************************************************************
433  *
434  *  DESCRIPTION:
435  *
436  *      Check with Card Services to determine if this device is open.
437  *
438  *  PARAMETERS:
439  *
440  *      dev - a pointer to the net_device structure whose open status will be
441  *            checked
442  *
443  *  RETURNS:
444  *
445  *      nonzero if device is open
446  *      0 otherwise
447  *
448  ******************************************************************************/
449 int wl_adapter_is_open(struct net_device *dev)
450 {
451         struct wl_private *lp = wl_priv(dev);
452         struct pcmcia_device *link = lp->link;
453
454         if (!pcmcia_dev_present(link))
455                 return 0;
456
457         return link->open;
458 } /* wl_adapter_is_open */
459 /*============================================================================*/