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 © 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
\93AS IS
\94 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/slab.h>
71 #include <linux/ctype.h>
72 #include <linux/string.h>
73 #include <linux/timer.h>
74 #include <linux/interrupt.h>
76 #include <linux/delay.h>
78 #include <asm/system.h>
79 #include <asm/bitops.h>
81 #include <linux/netdevice.h>
82 #include <linux/etherdevice.h>
83 #include <linux/skbuff.h>
84 #include <linux/if_arp.h>
85 #include <linux/ioport.h>
87 #include <pcmcia/cs_types.h>
88 #include <pcmcia/cs.h>
89 #include <pcmcia/cistpl.h>
90 #include <pcmcia/cisreg.h>
91 #include <pcmcia/ciscode.h>
92 #include <pcmcia/ds.h>
100 #include <wl_internal.h>
103 #include <wl_netdev.h>
105 #include <wl_sysfs.h>
108 /*******************************************************************************
110 ******************************************************************************/
111 #define CS_CHECK(fn, ret) do { \
112 last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; \
115 /*******************************************************************************
117 ******************************************************************************/
119 extern dbg_info_t *DbgInfo;
123 /*******************************************************************************
124 * wl_adapter_attach()
125 *******************************************************************************
129 * Creates an instance of the driver, allocating local data structures for
130 * one device. The device is registered with Card Services.
138 * pointer to an allocated dev_link_t structure
141 ******************************************************************************/
142 static int wl_adapter_attach(struct pcmcia_device *link)
144 struct net_device *dev;
145 struct wl_private *lp;
146 /*------------------------------------------------------------------------*/
148 DBG_FUNC( "wl_adapter_attach" );
149 DBG_ENTER( DbgInfo );
151 dev = wl_device_alloc();
153 DBG_ERROR( DbgInfo, "wl_device_alloc returned NULL\n");
157 link->io.NumPorts1 = HCF_NUM_IO_PORTS;
158 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
159 link->io.IOAddrLines = 6;
160 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_HANDLE_PRESENT;
161 link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
162 link->irq.Handler = &wl_isr;
163 link->conf.Attributes = CONF_ENABLE_IRQ;
164 link->conf.IntType = INT_MEMORY_AND_IO;
165 link->conf.ConfigIndex = 5;
166 link->conf.Present = PRESENT_OPTION;
168 link->priv = link->irq.Instance = dev;
172 wl_adapter_insert(link);
174 DBG_LEAVE( DbgInfo );
176 } // wl_adapter_attach
177 /*============================================================================*/
181 /*******************************************************************************
182 * wl_adapter_detach()
183 *******************************************************************************
187 * This deletes a driver "instance". The device is de-registered with Card
188 * Services. If it has been released, then the net device is unregistered, and
189 * all local data structures are freed. Otherwise, the structures will be
190 * freed when the device is released.
194 * link - pointer to the dev_link_t structure representing the device to
201 ******************************************************************************/
202 static void wl_adapter_detach(struct pcmcia_device *link)
204 struct net_device *dev = link->priv;
205 /*------------------------------------------------------------------------*/
208 DBG_FUNC( "wl_adapter_detach" );
209 DBG_ENTER( DbgInfo );
210 DBG_PARAM( DbgInfo, "link", "0x%p", link );
212 wl_adapter_release(link);
215 unregister_wlags_sysfs(dev);
216 unregister_netdev(dev);
219 wl_device_dealloc(dev);
221 DBG_LEAVE( DbgInfo );
222 } // wl_adapter_detach
223 /*============================================================================*/
226 /*******************************************************************************
227 * wl_adapter_release()
228 *******************************************************************************
232 * After a card is removed, this routine will release the PCMCIA
233 * configuration. If the device is still open, this will be postponed until it
238 * arg - a u_long representing a pointer to a dev_link_t structure for the
239 * device to be released.
245 ******************************************************************************/
246 void wl_adapter_release( struct pcmcia_device *link )
248 DBG_FUNC( "wl_adapter_release" );
249 DBG_ENTER( DbgInfo );
250 DBG_PARAM( DbgInfo, "link", "0x%p", link);
253 wl_remove(link->priv);
255 pcmcia_disable_device(link);
257 DBG_LEAVE( DbgInfo );
258 } // wl_adapter_release
259 /*============================================================================*/
261 static int wl_adapter_suspend(struct pcmcia_device *link)
263 struct net_device *dev = link->priv;
266 netif_device_detach(dev);
268 //// CHECK! pcmcia_release_configuration(link->handle);
272 } // wl_adapter_suspend
274 static int wl_adapter_resume(struct pcmcia_device *link)
276 struct net_device *dev = link->priv;
280 netif_device_attach( dev );
283 } // wl_adapter_resume
285 /*******************************************************************************
286 * wl_adapter_insert()
287 *******************************************************************************
291 * wl_adapter_insert() is scheduled to run after a CARD_INSERTION event is
292 * received, to configure the PCMCIA socket, and to make the ethernet device
293 * available to the system.
297 * link - pointer to the dev_link_t structure representing the device to
304 ******************************************************************************/
305 void wl_adapter_insert( struct pcmcia_device *link )
307 struct net_device *dev;
309 int last_fn, last_ret;
310 /*------------------------------------------------------------------------*/
312 DBG_FUNC( "wl_adapter_insert" );
313 DBG_ENTER( DbgInfo );
314 DBG_PARAM( DbgInfo, "link", "0x%p", link );
318 /* Do we need to allocate an interrupt? */
319 link->conf.Attributes |= CONF_ENABLE_IRQ;
321 CS_CHECK(RequestIO, pcmcia_request_io(link, &link->io));
322 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
323 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
326 dev->irq = link->irq.AssignedIRQ;
327 dev->base_addr = link->io.BasePort1;
329 SET_NETDEV_DEV(dev, &handle_to_dev(link));
330 if (register_netdev(dev) != 0) {
331 printk("%s: register_netdev() failed\n", MODULE_NAME);
334 link->dev_node = &( wl_priv(dev) )->node;
335 strcpy(( wl_priv(dev) )->node.dev_name, dev->name);
336 register_wlags_sysfs(dev);
338 printk(KERN_INFO "%s: Wireless, io_addr %#03lx, irq %d, ""mac_address ",
339 dev->name, dev->base_addr, dev->irq);
340 for( i = 0; i < ETH_ALEN; i++ ) {
341 printk("%02X%c", dev->dev_addr[i], ((i < (ETH_ALEN-1)) ? ':' : '\n'));
344 DBG_LEAVE( DbgInfo );
349 cs_error( link, last_fn, last_ret );
353 wl_adapter_release( link );
357 } // wl_adapter_insert
358 /*============================================================================*/
361 /*******************************************************************************
363 *******************************************************************************
371 * dev - a pointer to a net_device structure representing the network
377 * errno value otherwise
379 ******************************************************************************/
380 int wl_adapter_open( struct net_device *dev )
382 struct wl_private *lp = wl_priv(dev);
383 struct pcmcia_device *link = lp->link;
385 int hcf_status = HCF_SUCCESS;
386 /*------------------------------------------------------------------------*/
389 DBG_FUNC( "wl_adapter_open" );
390 DBG_ENTER( DbgInfo );
391 DBG_PRINT( "%s\n", VERSION_INFO );
392 DBG_PARAM( DbgInfo, "dev", "%s (0x%p)", dev->name, dev );
394 if(!pcmcia_dev_present(link))
396 DBG_LEAVE( DbgInfo );
402 hcf_status = wl_open( dev );
404 if( hcf_status != HCF_SUCCESS ) {
409 DBG_LEAVE( DbgInfo );
412 /*============================================================================*/
415 /*******************************************************************************
417 *******************************************************************************
425 * dev - a pointer to a net_device structure representing the network
431 * errno value otherwise
433 ******************************************************************************/
434 int wl_adapter_close( struct net_device *dev )
436 struct wl_private *lp = wl_priv(dev);
437 struct pcmcia_device *link = lp->link;
438 /*------------------------------------------------------------------------*/
441 DBG_FUNC( "wl_adapter_close" );
442 DBG_ENTER( DbgInfo );
443 DBG_PARAM( DbgInfo, "dev", "%s (0x%p)", dev->name, dev );
446 DBG_LEAVE( DbgInfo );
450 DBG_TRACE( DbgInfo, "%s: Shutting down adapter.\n", dev->name );
455 DBG_LEAVE( DbgInfo );
457 } // wl_adapter_close
458 /*============================================================================*/
460 static struct pcmcia_device_id wl_adapter_ids[] = {
461 #if ! ((HCF_TYPE) & HCF_TYPE_HII5)
462 PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0003),
463 PCMCIA_DEVICE_PROD_ID12("Agere Systems", "Wireless PC Card Model 0110",
464 0x33103a9b, 0xe175b0dd),
466 PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0004),
467 PCMCIA_DEVICE_PROD_ID12("Linksys", "WCF54G_Wireless-G_CompactFlash_Card",
468 0x0733cc81, 0x98a599e1),
469 #endif // (HCF_TYPE) & HCF_TYPE_HII5
472 MODULE_DEVICE_TABLE(pcmcia, wl_adapter_ids);
474 static struct pcmcia_driver wlags49_driver = {
475 .owner = THIS_MODULE,
479 .probe = wl_adapter_attach,
480 .remove = wl_adapter_detach,
481 .id_table = wl_adapter_ids,
482 .suspend = wl_adapter_suspend,
483 .resume = wl_adapter_resume,
488 /*******************************************************************************
489 * wl_adapter_init_module()
490 *******************************************************************************
494 * Called by init_module() to perform PCMCIA driver initialization.
505 ******************************************************************************/
506 int wl_adapter_init_module( void )
509 /*------------------------------------------------------------------------*/
512 DBG_FUNC( "wl_adapter_init_module" );
513 DBG_ENTER( DbgInfo );
514 DBG_TRACE( DbgInfo, "wl_adapter_init_module() -- PCMCIA\n" );
516 ret = pcmcia_register_driver(&wlags49_driver);
518 DBG_LEAVE( DbgInfo );
520 } // wl_adapter_init_module
521 /*============================================================================*/
524 /*******************************************************************************
525 * wl_adapter_cleanup_module()
526 *******************************************************************************
530 * Called by cleanup_module() to perform driver uninitialization.
540 ******************************************************************************/
541 void wl_adapter_cleanup_module( void )
543 DBG_FUNC( "wl_adapter_cleanup_module" );
544 DBG_ENTER( DbgInfo );
545 DBG_TRACE( DbgInfo, "wl_adapter_cleanup_module() -- PCMCIA\n" );
548 pcmcia_unregister_driver(&wlags49_driver);
550 DBG_LEAVE( DbgInfo );
552 } // wl_adapter_cleanup_module
553 /*============================================================================*/
556 /*******************************************************************************
557 * wl_adapter_is_open()
558 *******************************************************************************
562 * Check with Card Services to determine if this device is open.
566 * dev - a pointer to the net_device structure whose open status will be
571 * nonzero if device is open
574 ******************************************************************************/
575 int wl_adapter_is_open( struct net_device *dev )
577 struct wl_private *lp = wl_priv(dev);
578 struct pcmcia_device *link = lp->link;
580 if(!pcmcia_dev_present(link)) {
584 return( link->open );
585 } // wl_adapter_is_open
586 /*============================================================================*/
591 /*******************************************************************************
593 *******************************************************************************
597 * Converts the card serivces events to text for debugging.
601 * mask - a integer representing the error(s) being reported by Card
606 * a pointer to a string describing the error(s)
608 ******************************************************************************/
609 const char* DbgEvent( int mask )
611 static char DbgBuffer[256];
613 /*------------------------------------------------------------------------*/
620 if( mask & CS_EVENT_WRITE_PROTECT )
621 strcat( pBuf, "WRITE_PROTECT " );
623 if(mask & CS_EVENT_CARD_LOCK)
624 strcat( pBuf, "CARD_LOCK " );
626 if(mask & CS_EVENT_CARD_INSERTION)
627 strcat( pBuf, "CARD_INSERTION " );
629 if(mask & CS_EVENT_CARD_REMOVAL)
630 strcat( pBuf, "CARD_REMOVAL " );
632 if(mask & CS_EVENT_BATTERY_DEAD)
633 strcat( pBuf, "BATTERY_DEAD " );
635 if(mask & CS_EVENT_BATTERY_LOW)
636 strcat( pBuf, "BATTERY_LOW " );
638 if(mask & CS_EVENT_READY_CHANGE)
639 strcat( pBuf, "READY_CHANGE " );
641 if(mask & CS_EVENT_CARD_DETECT)
642 strcat( pBuf, "CARD_DETECT " );
644 if(mask & CS_EVENT_RESET_REQUEST)
645 strcat( pBuf, "RESET_REQUEST " );
647 if(mask & CS_EVENT_RESET_PHYSICAL)
648 strcat( pBuf, "RESET_PHYSICAL " );
650 if(mask & CS_EVENT_CARD_RESET)
651 strcat( pBuf, "CARD_RESET " );
653 if(mask & CS_EVENT_REGISTRATION_COMPLETE)
654 strcat( pBuf, "REGISTRATION_COMPLETE " );
656 // if(mask & CS_EVENT_RESET_COMPLETE)
657 // strcat( pBuf, "RESET_COMPLETE " );
659 if(mask & CS_EVENT_PM_SUSPEND)
660 strcat( pBuf, "PM_SUSPEND " );
662 if(mask & CS_EVENT_PM_RESUME)
663 strcat( pBuf, "PM_RESUME " );
665 if(mask & CS_EVENT_INSERTION_REQUEST)
666 strcat( pBuf, "INSERTION_REQUEST " );
668 if(mask & CS_EVENT_EJECTION_REQUEST)
669 strcat( pBuf, "EJECTION_REQUEST " );
671 if(mask & CS_EVENT_MTD_REQUEST)
672 strcat( pBuf, "MTD_REQUEST " );
674 if(mask & CS_EVENT_ERASE_COMPLETE)
675 strcat( pBuf, "ERASE_COMPLETE " );
677 if(mask & CS_EVENT_REQUEST_ATTENTION)
678 strcat( pBuf, "REQUEST_ATTENTION " );
680 if(mask & CS_EVENT_CB_DETECT)
681 strcat( pBuf, "CB_DETECT " );
683 if(mask & CS_EVENT_3VCARD)
684 strcat( pBuf, "3VCARD " );
686 if(mask & CS_EVENT_XVCARD)
687 strcat( pBuf, "XVCARD " );
691 pBuf[strlen(pBuf) - 1] = '\0';
694 sprintf( pBuf, "<<0x%08x>>", mask );
700 /*============================================================================*/