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