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>
86 #include <pcmcia/cistpl.h>
87 #include <pcmcia/cisreg.h>
88 #include <pcmcia/ciscode.h>
89 #include <pcmcia/ds.h>
97 #include <wl_internal.h>
100 #include <wl_netdev.h>
102 #include <wl_sysfs.h>
105 /*******************************************************************************
107 ******************************************************************************/
109 extern dbg_info_t
*DbgInfo
;
113 /*******************************************************************************
114 * wl_adapter_attach()
115 *******************************************************************************
119 * Creates an instance of the driver, allocating local data structures for
120 * one device. The device is registered with Card Services.
128 * pointer to an allocated dev_link_t structure
131 ******************************************************************************/
132 static int wl_adapter_attach(struct pcmcia_device
*link
)
134 struct net_device
*dev
;
135 struct wl_private
*lp
;
136 /*--------------------------------------------------------------------*/
138 DBG_FUNC("wl_adapter_attach");
141 dev
= wl_device_alloc();
143 DBG_ERROR(DbgInfo
, "wl_device_alloc returned NULL\n");
147 link
->resource
[0]->end
= HCF_NUM_IO_PORTS
;
148 link
->resource
[0]->flags
= IO_DATA_PATH_WIDTH_16
;
149 link
->config_flags
|= CONF_ENABLE_IRQ
;
150 link
->config_index
= 5;
151 link
->config_regs
= PRESENT_OPTION
;
157 wl_adapter_insert(link
);
161 } /* wl_adapter_attach */
162 /*============================================================================*/
166 static void wl_adapter_detach(struct pcmcia_device
*link
)
168 struct net_device
*dev
= link
->priv
;
169 /*--------------------------------------------------------------------*/
171 DBG_FUNC("wl_adapter_detach");
173 DBG_PARAM(DbgInfo
, "link", "0x%p", link
);
175 wl_adapter_release(link
);
178 unregister_wlags_sysfs(dev
);
179 unregister_netdev(dev
);
182 wl_device_dealloc(dev
);
185 } /* wl_adapter_detach */
186 /*============================================================================*/
189 void wl_adapter_release(struct pcmcia_device
*link
)
191 DBG_FUNC("wl_adapter_release");
193 DBG_PARAM(DbgInfo
, "link", "0x%p", link
);
196 wl_remove(link
->priv
);
198 pcmcia_disable_device(link
);
201 } /* wl_adapter_release */
202 /*============================================================================*/
204 static int wl_adapter_suspend(struct pcmcia_device
*link
)
206 struct net_device
*dev
= link
->priv
;
208 /* if (link->open) { */
209 netif_device_detach(dev
);
211 /* CHECK! pcmcia_release_configuration(link->handle); */
215 } /* wl_adapter_suspend */
217 static int wl_adapter_resume(struct pcmcia_device
*link
)
219 struct net_device
*dev
= link
->priv
;
223 netif_device_attach(dev
);
226 } /* wl_adapter_resume */
228 void wl_adapter_insert(struct pcmcia_device
*link
)
230 struct net_device
*dev
;
233 /*--------------------------------------------------------------------*/
235 DBG_FUNC("wl_adapter_insert");
237 DBG_PARAM(DbgInfo
, "link", "0x%p", link
);
241 /* Do we need to allocate an interrupt? */
242 link
->config_flags
|= CONF_ENABLE_IRQ
;
245 ret
= pcmcia_request_io(link
);
249 ret
= pcmcia_request_irq(link
, (void *) wl_isr
);
253 ret
= pcmcia_enable_device(link
);
257 dev
->irq
= link
->irq
;
258 dev
->base_addr
= link
->resource
[0]->start
;
260 SET_NETDEV_DEV(dev
, &link
->dev
);
261 if (register_netdev(dev
) != 0) {
262 printk("%s: register_netdev() failed\n", MODULE_NAME
);
266 register_wlags_sysfs(dev
);
268 printk(KERN_INFO
"%s: Wireless, io_addr %#03lx, irq %d, ""mac_address ",
269 dev
->name
, dev
->base_addr
, dev
->irq
);
270 for (i
= 0; i
< ETH_ALEN
; i
++)
271 printk("%02X%c", dev
->dev_addr
[i
], ((i
< (ETH_ALEN
-1)) ? ':' : '\n'));
277 wl_adapter_release(link
);
281 } /* wl_adapter_insert */
282 /*============================================================================*/
285 /*******************************************************************************
287 *******************************************************************************
295 * dev - a pointer to a net_device structure representing the network
301 * errno value otherwise
303 ******************************************************************************/
304 int wl_adapter_open(struct net_device
*dev
)
306 struct wl_private
*lp
= wl_priv(dev
);
307 struct pcmcia_device
*link
= lp
->link
;
309 int hcf_status
= HCF_SUCCESS
;
310 /*--------------------------------------------------------------------*/
312 DBG_FUNC("wl_adapter_open");
314 DBG_PRINT("%s\n", VERSION_INFO
);
315 DBG_PARAM(DbgInfo
, "dev", "%s (0x%p)", dev
->name
, dev
);
317 if (!pcmcia_dev_present(link
)) {
324 hcf_status
= wl_open(dev
);
326 if (hcf_status
!= HCF_SUCCESS
) {
333 } /* wl_adapter_open */
334 /*============================================================================*/
337 /*******************************************************************************
339 *******************************************************************************
347 * dev - a pointer to a net_device structure representing the network
353 * errno value otherwise
355 ******************************************************************************/
356 int wl_adapter_close(struct net_device
*dev
)
358 struct wl_private
*lp
= wl_priv(dev
);
359 struct pcmcia_device
*link
= lp
->link
;
360 /*--------------------------------------------------------------------*/
362 DBG_FUNC("wl_adapter_close");
364 DBG_PARAM(DbgInfo
, "dev", "%s (0x%p)", dev
->name
, dev
);
371 DBG_TRACE(DbgInfo
, "%s: Shutting down adapter.\n", dev
->name
);
378 } /* wl_adapter_close */
379 /*============================================================================*/
381 static struct pcmcia_device_id wl_adapter_ids
[] = {
382 #if !((HCF_TYPE) & HCF_TYPE_HII5)
383 PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0003),
384 PCMCIA_DEVICE_PROD_ID12("Agere Systems", "Wireless PC Card Model 0110",
385 0x33103a9b, 0xe175b0dd),
387 PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0004),
388 PCMCIA_DEVICE_PROD_ID12("Linksys", "WCF54G_Wireless-G_CompactFlash_Card",
389 0x0733cc81, 0x98a599e1),
390 #endif /* (HCF_TYPE) & HCF_TYPE_HII5 */
393 MODULE_DEVICE_TABLE(pcmcia
, wl_adapter_ids
);
395 static struct pcmcia_driver wlags49_driver
= {
396 .owner
= THIS_MODULE
,
398 .probe
= wl_adapter_attach
,
399 .remove
= wl_adapter_detach
,
400 .id_table
= wl_adapter_ids
,
401 .suspend
= wl_adapter_suspend
,
402 .resume
= wl_adapter_resume
,
407 /*******************************************************************************
408 * wl_adapter_init_module()
409 *******************************************************************************
413 * Called by init_module() to perform PCMCIA driver initialization.
424 ******************************************************************************/
425 int wl_adapter_init_module(void)
428 /*--------------------------------------------------------------------*/
430 DBG_FUNC("wl_adapter_init_module");
432 DBG_TRACE(DbgInfo
, "wl_adapter_init_module() -- PCMCIA\n");
434 ret
= pcmcia_register_driver(&wlags49_driver
);
438 } /* wl_adapter_init_module */
439 /*============================================================================*/
442 /*******************************************************************************
443 * wl_adapter_cleanup_module()
444 *******************************************************************************
448 * Called by cleanup_module() to perform driver uninitialization.
458 ******************************************************************************/
459 void wl_adapter_cleanup_module(void)
461 DBG_FUNC("wl_adapter_cleanup_module");
463 DBG_TRACE(DbgInfo
, "wl_adapter_cleanup_module() -- PCMCIA\n");
466 pcmcia_unregister_driver(&wlags49_driver
);
470 } /* wl_adapter_cleanup_module */
471 /*============================================================================*/
474 /*******************************************************************************
475 * wl_adapter_is_open()
476 *******************************************************************************
480 * Check with Card Services to determine if this device is open.
484 * dev - a pointer to the net_device structure whose open status will be
489 * nonzero if device is open
492 ******************************************************************************/
493 int wl_adapter_is_open(struct net_device
*dev
)
495 struct wl_private
*lp
= wl_priv(dev
);
496 struct pcmcia_device
*link
= lp
->link
;
498 if (!pcmcia_dev_present(link
))
502 } /* wl_adapter_is_open */
503 /*============================================================================*/
508 /*******************************************************************************
510 *******************************************************************************
514 * Converts the card serivces events to text for debugging.
518 * mask - a integer representing the error(s) being reported by Card
523 * a pointer to a string describing the error(s)
525 ******************************************************************************/
526 const char *DbgEvent(int mask
)
528 static char DbgBuffer
[256];
530 /*--------------------------------------------------------------------*/
536 if (mask
& CS_EVENT_WRITE_PROTECT
)
537 strcat(pBuf
, "WRITE_PROTECT ");
539 if (mask
& CS_EVENT_CARD_LOCK
)
540 strcat(pBuf
, "CARD_LOCK ");
542 if (mask
& CS_EVENT_CARD_INSERTION
)
543 strcat(pBuf
, "CARD_INSERTION ");
545 if (mask
& CS_EVENT_CARD_REMOVAL
)
546 strcat(pBuf
, "CARD_REMOVAL ");
548 if (mask
& CS_EVENT_BATTERY_DEAD
)
549 strcat(pBuf
, "BATTERY_DEAD ");
551 if (mask
& CS_EVENT_BATTERY_LOW
)
552 strcat(pBuf
, "BATTERY_LOW ");
554 if (mask
& CS_EVENT_READY_CHANGE
)
555 strcat(pBuf
, "READY_CHANGE ");
557 if (mask
& CS_EVENT_CARD_DETECT
)
558 strcat(pBuf
, "CARD_DETECT ");
560 if (mask
& CS_EVENT_RESET_REQUEST
)
561 strcat(pBuf
, "RESET_REQUEST ");
563 if (mask
& CS_EVENT_RESET_PHYSICAL
)
564 strcat(pBuf
, "RESET_PHYSICAL ");
566 if (mask
& CS_EVENT_CARD_RESET
)
567 strcat(pBuf
, "CARD_RESET ");
569 if (mask
& CS_EVENT_REGISTRATION_COMPLETE
)
570 strcat(pBuf
, "REGISTRATION_COMPLETE ");
572 /* if (mask & CS_EVENT_RESET_COMPLETE)
573 strcat(pBuf, "RESET_COMPLETE "); */
575 if (mask
& CS_EVENT_PM_SUSPEND
)
576 strcat(pBuf
, "PM_SUSPEND ");
578 if (mask
& CS_EVENT_PM_RESUME
)
579 strcat(pBuf
, "PM_RESUME ");
581 if (mask
& CS_EVENT_INSERTION_REQUEST
)
582 strcat(pBuf
, "INSERTION_REQUEST ");
584 if (mask
& CS_EVENT_EJECTION_REQUEST
)
585 strcat(pBuf
, "EJECTION_REQUEST ");
587 if (mask
& CS_EVENT_MTD_REQUEST
)
588 strcat(pBuf
, "MTD_REQUEST ");
590 if (mask
& CS_EVENT_ERASE_COMPLETE
)
591 strcat(pBuf
, "ERASE_COMPLETE ");
593 if (mask
& CS_EVENT_REQUEST_ATTENTION
)
594 strcat(pBuf
, "REQUEST_ATTENTION ");
596 if (mask
& CS_EVENT_CB_DETECT
)
597 strcat(pBuf
, "CB_DETECT ");
599 if (mask
& CS_EVENT_3VCARD
)
600 strcat(pBuf
, "3VCARD ");
602 if (mask
& CS_EVENT_XVCARD
)
603 strcat(pBuf
, "XVCARD ");
607 pBuf
[strlen(pBuf
) - 1] = '\0';
610 sprintf(pBuf
, "<<0x%08x>>", mask
);
615 /*============================================================================*/