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 /*******************************************************************************
167 * wl_adapter_detach()
168 *******************************************************************************
172 * This deletes a driver "instance". The device is de-registered with Card
173 * Services. If it has been released, then the net device is unregistered, and
174 * all local data structures are freed. Otherwise, the structures will be
175 * freed when the device is released.
179 * link - pointer to the dev_link_t structure representing the device to
186 ******************************************************************************/
187 static void wl_adapter_detach(struct pcmcia_device
*link
)
189 struct net_device
*dev
= link
->priv
;
190 /*--------------------------------------------------------------------*/
192 DBG_FUNC("wl_adapter_detach");
194 DBG_PARAM(DbgInfo
, "link", "0x%p", link
);
196 wl_adapter_release(link
);
199 unregister_wlags_sysfs(dev
);
200 unregister_netdev(dev
);
203 wl_device_dealloc(dev
);
206 } /* wl_adapter_detach */
207 /*============================================================================*/
210 /*******************************************************************************
211 * wl_adapter_release()
212 *******************************************************************************
216 * After a card is removed, this routine will release the PCMCIA
217 * configuration. If the device is still open, this will be postponed until it
222 * arg - a u_long representing a pointer to a dev_link_t structure for the
223 * device to be released.
229 ******************************************************************************/
230 void wl_adapter_release(struct pcmcia_device
*link
)
232 DBG_FUNC("wl_adapter_release");
234 DBG_PARAM(DbgInfo
, "link", "0x%p", link
);
237 wl_remove(link
->priv
);
239 pcmcia_disable_device(link
);
242 } /* wl_adapter_release */
243 /*============================================================================*/
245 static int wl_adapter_suspend(struct pcmcia_device
*link
)
247 struct net_device
*dev
= link
->priv
;
249 /* if (link->open) { */
250 netif_device_detach(dev
);
252 /* CHECK! pcmcia_release_configuration(link->handle); */
256 } /* wl_adapter_suspend */
258 static int wl_adapter_resume(struct pcmcia_device
*link
)
260 struct net_device
*dev
= link
->priv
;
264 netif_device_attach(dev
);
267 } /* wl_adapter_resume */
269 /*******************************************************************************
270 * wl_adapter_insert()
271 *******************************************************************************
275 * wl_adapter_insert() is scheduled to run after a CARD_INSERTION event is
276 * received, to configure the PCMCIA socket, and to make the ethernet device
277 * available to the system.
281 * link - pointer to the dev_link_t structure representing the device to
288 ******************************************************************************/
289 void wl_adapter_insert(struct pcmcia_device
*link
)
291 struct net_device
*dev
;
294 /*--------------------------------------------------------------------*/
296 DBG_FUNC("wl_adapter_insert");
298 DBG_PARAM(DbgInfo
, "link", "0x%p", link
);
302 /* Do we need to allocate an interrupt? */
303 link
->config_flags
|= CONF_ENABLE_IRQ
;
306 ret
= pcmcia_request_io(link
);
310 ret
= pcmcia_request_irq(link
, (void *) wl_isr
);
314 ret
= pcmcia_enable_device(link
);
318 dev
->irq
= link
->irq
;
319 dev
->base_addr
= link
->resource
[0]->start
;
321 SET_NETDEV_DEV(dev
, &link
->dev
);
322 if (register_netdev(dev
) != 0) {
323 printk("%s: register_netdev() failed\n", MODULE_NAME
);
327 register_wlags_sysfs(dev
);
329 printk(KERN_INFO
"%s: Wireless, io_addr %#03lx, irq %d, ""mac_address ",
330 dev
->name
, dev
->base_addr
, dev
->irq
);
331 for (i
= 0; i
< ETH_ALEN
; i
++)
332 printk("%02X%c", dev
->dev_addr
[i
], ((i
< (ETH_ALEN
-1)) ? ':' : '\n'));
338 wl_adapter_release(link
);
342 } /* wl_adapter_insert */
343 /*============================================================================*/
346 /*******************************************************************************
348 *******************************************************************************
356 * dev - a pointer to a net_device structure representing the network
362 * errno value otherwise
364 ******************************************************************************/
365 int wl_adapter_open(struct net_device
*dev
)
367 struct wl_private
*lp
= wl_priv(dev
);
368 struct pcmcia_device
*link
= lp
->link
;
370 int hcf_status
= HCF_SUCCESS
;
371 /*--------------------------------------------------------------------*/
373 DBG_FUNC("wl_adapter_open");
375 DBG_PRINT("%s\n", VERSION_INFO
);
376 DBG_PARAM(DbgInfo
, "dev", "%s (0x%p)", dev
->name
, dev
);
378 if (!pcmcia_dev_present(link
)) {
385 hcf_status
= wl_open(dev
);
387 if (hcf_status
!= HCF_SUCCESS
) {
394 } /* wl_adapter_open */
395 /*============================================================================*/
398 /*******************************************************************************
400 *******************************************************************************
408 * dev - a pointer to a net_device structure representing the network
414 * errno value otherwise
416 ******************************************************************************/
417 int wl_adapter_close(struct net_device
*dev
)
419 struct wl_private
*lp
= wl_priv(dev
);
420 struct pcmcia_device
*link
= lp
->link
;
421 /*--------------------------------------------------------------------*/
423 DBG_FUNC("wl_adapter_close");
425 DBG_PARAM(DbgInfo
, "dev", "%s (0x%p)", dev
->name
, dev
);
432 DBG_TRACE(DbgInfo
, "%s: Shutting down adapter.\n", dev
->name
);
439 } /* wl_adapter_close */
440 /*============================================================================*/
442 static struct pcmcia_device_id wl_adapter_ids
[] = {
443 #if !((HCF_TYPE) & HCF_TYPE_HII5)
444 PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0003),
445 PCMCIA_DEVICE_PROD_ID12("Agere Systems", "Wireless PC Card Model 0110",
446 0x33103a9b, 0xe175b0dd),
448 PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0004),
449 PCMCIA_DEVICE_PROD_ID12("Linksys", "WCF54G_Wireless-G_CompactFlash_Card",
450 0x0733cc81, 0x98a599e1),
451 #endif /* (HCF_TYPE) & HCF_TYPE_HII5 */
454 MODULE_DEVICE_TABLE(pcmcia
, wl_adapter_ids
);
456 static struct pcmcia_driver wlags49_driver
= {
457 .owner
= THIS_MODULE
,
459 .probe
= wl_adapter_attach
,
460 .remove
= wl_adapter_detach
,
461 .id_table
= wl_adapter_ids
,
462 .suspend
= wl_adapter_suspend
,
463 .resume
= wl_adapter_resume
,
468 /*******************************************************************************
469 * wl_adapter_init_module()
470 *******************************************************************************
474 * Called by init_module() to perform PCMCIA driver initialization.
485 ******************************************************************************/
486 int wl_adapter_init_module(void)
489 /*--------------------------------------------------------------------*/
491 DBG_FUNC("wl_adapter_init_module");
493 DBG_TRACE(DbgInfo
, "wl_adapter_init_module() -- PCMCIA\n");
495 ret
= pcmcia_register_driver(&wlags49_driver
);
499 } /* wl_adapter_init_module */
500 /*============================================================================*/
503 /*******************************************************************************
504 * wl_adapter_cleanup_module()
505 *******************************************************************************
509 * Called by cleanup_module() to perform driver uninitialization.
519 ******************************************************************************/
520 void wl_adapter_cleanup_module(void)
522 DBG_FUNC("wl_adapter_cleanup_module");
524 DBG_TRACE(DbgInfo
, "wl_adapter_cleanup_module() -- PCMCIA\n");
527 pcmcia_unregister_driver(&wlags49_driver
);
531 } /* wl_adapter_cleanup_module */
532 /*============================================================================*/
535 /*******************************************************************************
536 * wl_adapter_is_open()
537 *******************************************************************************
541 * Check with Card Services to determine if this device is open.
545 * dev - a pointer to the net_device structure whose open status will be
550 * nonzero if device is open
553 ******************************************************************************/
554 int wl_adapter_is_open(struct net_device
*dev
)
556 struct wl_private
*lp
= wl_priv(dev
);
557 struct pcmcia_device
*link
= lp
->link
;
559 if (!pcmcia_dev_present(link
))
563 } /* wl_adapter_is_open */
564 /*============================================================================*/
569 /*******************************************************************************
571 *******************************************************************************
575 * Converts the card serivces events to text for debugging.
579 * mask - a integer representing the error(s) being reported by Card
584 * a pointer to a string describing the error(s)
586 ******************************************************************************/
587 const char *DbgEvent(int mask
)
589 static char DbgBuffer
[256];
591 /*--------------------------------------------------------------------*/
597 if (mask
& CS_EVENT_WRITE_PROTECT
)
598 strcat(pBuf
, "WRITE_PROTECT ");
600 if (mask
& CS_EVENT_CARD_LOCK
)
601 strcat(pBuf
, "CARD_LOCK ");
603 if (mask
& CS_EVENT_CARD_INSERTION
)
604 strcat(pBuf
, "CARD_INSERTION ");
606 if (mask
& CS_EVENT_CARD_REMOVAL
)
607 strcat(pBuf
, "CARD_REMOVAL ");
609 if (mask
& CS_EVENT_BATTERY_DEAD
)
610 strcat(pBuf
, "BATTERY_DEAD ");
612 if (mask
& CS_EVENT_BATTERY_LOW
)
613 strcat(pBuf
, "BATTERY_LOW ");
615 if (mask
& CS_EVENT_READY_CHANGE
)
616 strcat(pBuf
, "READY_CHANGE ");
618 if (mask
& CS_EVENT_CARD_DETECT
)
619 strcat(pBuf
, "CARD_DETECT ");
621 if (mask
& CS_EVENT_RESET_REQUEST
)
622 strcat(pBuf
, "RESET_REQUEST ");
624 if (mask
& CS_EVENT_RESET_PHYSICAL
)
625 strcat(pBuf
, "RESET_PHYSICAL ");
627 if (mask
& CS_EVENT_CARD_RESET
)
628 strcat(pBuf
, "CARD_RESET ");
630 if (mask
& CS_EVENT_REGISTRATION_COMPLETE
)
631 strcat(pBuf
, "REGISTRATION_COMPLETE ");
633 /* if (mask & CS_EVENT_RESET_COMPLETE)
634 strcat(pBuf, "RESET_COMPLETE "); */
636 if (mask
& CS_EVENT_PM_SUSPEND
)
637 strcat(pBuf
, "PM_SUSPEND ");
639 if (mask
& CS_EVENT_PM_RESUME
)
640 strcat(pBuf
, "PM_RESUME ");
642 if (mask
& CS_EVENT_INSERTION_REQUEST
)
643 strcat(pBuf
, "INSERTION_REQUEST ");
645 if (mask
& CS_EVENT_EJECTION_REQUEST
)
646 strcat(pBuf
, "EJECTION_REQUEST ");
648 if (mask
& CS_EVENT_MTD_REQUEST
)
649 strcat(pBuf
, "MTD_REQUEST ");
651 if (mask
& CS_EVENT_ERASE_COMPLETE
)
652 strcat(pBuf
, "ERASE_COMPLETE ");
654 if (mask
& CS_EVENT_REQUEST_ATTENTION
)
655 strcat(pBuf
, "REQUEST_ATTENTION ");
657 if (mask
& CS_EVENT_CB_DETECT
)
658 strcat(pBuf
, "CB_DETECT ");
660 if (mask
& CS_EVENT_3VCARD
)
661 strcat(pBuf
, "3VCARD ");
663 if (mask
& CS_EVENT_XVCARD
)
664 strcat(pBuf
, "XVCARD ");
668 pBuf
[strlen(pBuf
) - 1] = '\0';
671 sprintf(pBuf
, "<<0x%08x>>", mask
);
676 /*============================================================================*/