1 /*******************************************************************************
3 * Wireless device driver for Linux (wlags49).
5 * Copyright (c) 1998-2003 Agere Systems Inc.
9 * Initially developed by TriplePoint, Inc.
10 * http://www.triplepoint.com
12 *------------------------------------------------------------------------------
14 * This file contains processing and initialization specific to Card Services
15 * devices (PCMCIA, CF).
17 *------------------------------------------------------------------------------
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.
26 * Copyright (c) 2003 Agere Systems Inc.
27 * All rights reserved.
29 * Redistribution and use in source or binary forms, with or without
30 * modifications, are permitted provided that the following conditions are met:
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
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.
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.
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
60 ******************************************************************************/
62 /*******************************************************************************
64 ******************************************************************************/
65 #include <wl_version.h>
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>
75 #include <linux/delay.h>
77 #include <asm/system.h>
78 #include <asm/bitops.h>
80 #include <linux/netdevice.h>
81 #include <linux/etherdevice.h>
82 #include <linux/skbuff.h>
83 #include <linux/if_arp.h>
84 #include <linux/ioport.h>
85 #include <linux/module.h>
87 #include <pcmcia/cistpl.h>
88 #include <pcmcia/cisreg.h>
89 #include <pcmcia/ciscode.h>
90 #include <pcmcia/ds.h>
98 #include <wl_internal.h>
101 #include <wl_netdev.h>
103 #include <wl_sysfs.h>
106 /*******************************************************************************
108 ******************************************************************************/
110 extern dbg_info_t *DbgInfo;
114 /*******************************************************************************
115 * wl_adapter_attach()
116 *******************************************************************************
120 * Creates an instance of the driver, allocating local data structures for
121 * one device. The device is registered with Card Services.
129 * pointer to an allocated dev_link_t structure
132 ******************************************************************************/
133 static int wl_adapter_attach(struct pcmcia_device *link)
135 struct net_device *dev;
136 struct wl_private *lp;
137 /*--------------------------------------------------------------------*/
139 DBG_FUNC("wl_adapter_attach");
142 dev = wl_device_alloc();
144 DBG_ERROR(DbgInfo, "wl_device_alloc returned NULL\n");
148 link->resource[0]->end = HCF_NUM_IO_PORTS;
149 link->resource[0]->flags= IO_DATA_PATH_WIDTH_16;
150 link->config_flags |= CONF_ENABLE_IRQ;
151 link->config_index = 5;
152 link->config_regs = PRESENT_OPTION;
158 wl_adapter_insert(link);
162 } /* wl_adapter_attach */
163 /*============================================================================*/
167 static void wl_adapter_detach(struct pcmcia_device *link)
169 struct net_device *dev = link->priv;
170 /*--------------------------------------------------------------------*/
172 DBG_FUNC("wl_adapter_detach");
174 DBG_PARAM(DbgInfo, "link", "0x%p", link);
176 wl_adapter_release(link);
179 unregister_wlags_sysfs(dev);
180 unregister_netdev(dev);
183 wl_device_dealloc(dev);
186 } /* wl_adapter_detach */
187 /*============================================================================*/
190 void wl_adapter_release(struct pcmcia_device *link)
192 DBG_FUNC("wl_adapter_release");
194 DBG_PARAM(DbgInfo, "link", "0x%p", link);
197 wl_remove(link->priv);
199 pcmcia_disable_device(link);
202 } /* wl_adapter_release */
203 /*============================================================================*/
205 static int wl_adapter_suspend(struct pcmcia_device *link)
207 struct net_device *dev = link->priv;
209 /* if (link->open) { */
210 netif_device_detach(dev);
212 /* CHECK! pcmcia_release_configuration(link->handle); */
216 } /* wl_adapter_suspend */
218 static int wl_adapter_resume(struct pcmcia_device *link)
220 struct net_device *dev = link->priv;
224 netif_device_attach(dev);
227 } /* wl_adapter_resume */
229 void wl_adapter_insert(struct pcmcia_device *link)
231 struct net_device *dev;
234 /*--------------------------------------------------------------------*/
236 DBG_FUNC("wl_adapter_insert");
238 DBG_PARAM(DbgInfo, "link", "0x%p", link);
242 /* Do we need to allocate an interrupt? */
243 link->config_flags |= CONF_ENABLE_IRQ;
246 ret = pcmcia_request_io(link);
250 ret = pcmcia_request_irq(link, (void *) wl_isr);
254 ret = pcmcia_enable_device(link);
258 dev->irq = link->irq;
259 dev->base_addr = link->resource[0]->start;
261 SET_NETDEV_DEV(dev, &link->dev);
262 if (register_netdev(dev) != 0) {
263 printk("%s: register_netdev() failed\n", MODULE_NAME);
267 register_wlags_sysfs(dev);
269 printk(KERN_INFO "%s: Wireless, io_addr %#03lx, irq %d, ""mac_address ",
270 dev->name, dev->base_addr, dev->irq);
271 for (i = 0; i < ETH_ALEN; i++)
272 printk("%02X%c", dev->dev_addr[i], ((i < (ETH_ALEN-1)) ? ':' : '\n'));
278 wl_adapter_release(link);
282 } /* wl_adapter_insert */
283 /*============================================================================*/
286 /*******************************************************************************
288 *******************************************************************************
296 * dev - a pointer to a net_device structure representing the network
302 * errno value otherwise
304 ******************************************************************************/
305 int wl_adapter_open(struct net_device *dev)
307 struct wl_private *lp = wl_priv(dev);
308 struct pcmcia_device *link = lp->link;
310 int hcf_status = HCF_SUCCESS;
311 /*--------------------------------------------------------------------*/
313 DBG_FUNC("wl_adapter_open");
315 DBG_PRINT("%s\n", VERSION_INFO);
316 DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
318 if (!pcmcia_dev_present(link)) {
325 hcf_status = wl_open(dev);
327 if (hcf_status != HCF_SUCCESS) {
334 } /* wl_adapter_open */
335 /*============================================================================*/
338 /*******************************************************************************
340 *******************************************************************************
348 * dev - a pointer to a net_device structure representing the network
354 * errno value otherwise
356 ******************************************************************************/
357 int wl_adapter_close(struct net_device *dev)
359 struct wl_private *lp = wl_priv(dev);
360 struct pcmcia_device *link = lp->link;
361 /*--------------------------------------------------------------------*/
363 DBG_FUNC("wl_adapter_close");
365 DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
372 DBG_TRACE(DbgInfo, "%s: Shutting down adapter.\n", dev->name);
379 } /* wl_adapter_close */
380 /*============================================================================*/
382 static const struct pcmcia_device_id wl_adapter_ids[] = {
383 #if !((HCF_TYPE) & HCF_TYPE_HII5)
384 PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0003),
385 PCMCIA_DEVICE_PROD_ID12("Agere Systems", "Wireless PC Card Model 0110",
386 0x33103a9b, 0xe175b0dd),
388 PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0004),
389 PCMCIA_DEVICE_PROD_ID12("Linksys", "WCF54G_Wireless-G_CompactFlash_Card",
390 0x0733cc81, 0x98a599e1),
391 #endif /* (HCF_TYPE) & HCF_TYPE_HII5 */
394 MODULE_DEVICE_TABLE(pcmcia, wl_adapter_ids);
396 static struct pcmcia_driver wlags49_driver = {
397 .owner = THIS_MODULE,
399 .probe = wl_adapter_attach,
400 .remove = wl_adapter_detach,
401 .id_table = wl_adapter_ids,
402 .suspend = wl_adapter_suspend,
403 .resume = wl_adapter_resume,
408 /*******************************************************************************
409 * wl_adapter_init_module()
410 *******************************************************************************
414 * Called by init_module() to perform PCMCIA driver initialization.
425 ******************************************************************************/
426 int wl_adapter_init_module(void)
429 /*--------------------------------------------------------------------*/
431 DBG_FUNC("wl_adapter_init_module");
433 DBG_TRACE(DbgInfo, "wl_adapter_init_module() -- PCMCIA\n");
435 ret = pcmcia_register_driver(&wlags49_driver);
439 } /* wl_adapter_init_module */
440 /*============================================================================*/
443 /*******************************************************************************
444 * wl_adapter_cleanup_module()
445 *******************************************************************************
449 * Called by cleanup_module() to perform driver uninitialization.
459 ******************************************************************************/
460 void wl_adapter_cleanup_module(void)
462 DBG_FUNC("wl_adapter_cleanup_module");
464 DBG_TRACE(DbgInfo, "wl_adapter_cleanup_module() -- PCMCIA\n");
467 pcmcia_unregister_driver(&wlags49_driver);
471 } /* wl_adapter_cleanup_module */
472 /*============================================================================*/
475 /*******************************************************************************
476 * wl_adapter_is_open()
477 *******************************************************************************
481 * Check with Card Services to determine if this device is open.
485 * dev - a pointer to the net_device structure whose open status will be
490 * nonzero if device is open
493 ******************************************************************************/
494 int wl_adapter_is_open(struct net_device *dev)
496 struct wl_private *lp = wl_priv(dev);
497 struct pcmcia_device *link = lp->link;
499 if (!pcmcia_dev_present(link))
503 } /* wl_adapter_is_open */
504 /*============================================================================*/