pcmcia: do not use io_req_t when calling pcmcia_request_io()
[deliverable/linux.git] / 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 © 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 \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
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/system.h>
78 #include <asm/bitops.h>
79
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
86 #include <pcmcia/cs.h>
87 #include <pcmcia/cistpl.h>
88 #include <pcmcia/cisreg.h>
89 #include <pcmcia/ciscode.h>
90 #include <pcmcia/ds.h>
91 #include <debug.h>
92
93 #include <hcf.h>
94 #include <dhf.h>
95 #include <hcfdef.h>
96
97 #include <wl_if.h>
98 #include <wl_internal.h>
99 #include <wl_util.h>
100 #include <wl_main.h>
101 #include <wl_netdev.h>
102 #include <wl_cs.h>
103 #include <wl_sysfs.h>
104
105
106 /*******************************************************************************
107 * global definitions
108 ******************************************************************************/
109 #if DBG
110 extern dbg_info_t *DbgInfo;
111 #endif /* DBG */
112
113
114 /*******************************************************************************
115 * wl_adapter_attach()
116 *******************************************************************************
117 *
118 * DESCRIPTION:
119 *
120 * Creates an instance of the driver, allocating local data structures for
121 * one device. The device is registered with Card Services.
122 *
123 * PARAMETERS:
124 *
125 * none
126 *
127 * RETURNS:
128 *
129 * pointer to an allocated dev_link_t structure
130 * NULL on failure
131 *
132 ******************************************************************************/
133 static int wl_adapter_attach(struct pcmcia_device *link)
134 {
135 struct net_device *dev;
136 struct wl_private *lp;
137 /*------------------------------------------------------------------------*/
138
139 DBG_FUNC( "wl_adapter_attach" );
140 DBG_ENTER( DbgInfo );
141
142 dev = wl_device_alloc();
143 if(dev == NULL) {
144 DBG_ERROR( DbgInfo, "wl_device_alloc returned NULL\n");
145 return -ENOMEM;
146 }
147
148 link->resource[0]->end = HCF_NUM_IO_PORTS;
149 link->resource[0]->flags = IO_DATA_PATH_WIDTH_16;
150 link->conf.Attributes = CONF_ENABLE_IRQ;
151 link->conf.IntType = INT_MEMORY_AND_IO;
152 link->conf.ConfigIndex = 5;
153 link->conf.Present = PRESENT_OPTION;
154
155 link->priv = dev;
156 lp = wl_priv(dev);
157 lp->link = link;
158
159 wl_adapter_insert(link);
160
161 DBG_LEAVE( DbgInfo );
162 return 0;
163 } // wl_adapter_attach
164 /*============================================================================*/
165
166
167
168 /*******************************************************************************
169 * wl_adapter_detach()
170 *******************************************************************************
171 *
172 * DESCRIPTION:
173 *
174 * This deletes a driver "instance". The device is de-registered with Card
175 * Services. If it has been released, then the net device is unregistered, and
176 * all local data structures are freed. Otherwise, the structures will be
177 * freed when the device is released.
178 *
179 * PARAMETERS:
180 *
181 * link - pointer to the dev_link_t structure representing the device to
182 * detach
183 *
184 * RETURNS:
185 *
186 * N/A
187 *
188 ******************************************************************************/
189 static void wl_adapter_detach(struct pcmcia_device *link)
190 {
191 struct net_device *dev = link->priv;
192 /*------------------------------------------------------------------------*/
193
194
195 DBG_FUNC( "wl_adapter_detach" );
196 DBG_ENTER( DbgInfo );
197 DBG_PARAM( DbgInfo, "link", "0x%p", link );
198
199 wl_adapter_release(link);
200
201 if (dev) {
202 unregister_wlags_sysfs(dev);
203 unregister_netdev(dev);
204 }
205
206 wl_device_dealloc(dev);
207
208 DBG_LEAVE( DbgInfo );
209 } // wl_adapter_detach
210 /*============================================================================*/
211
212
213 /*******************************************************************************
214 * wl_adapter_release()
215 *******************************************************************************
216 *
217 * DESCRIPTION:
218 *
219 * After a card is removed, this routine will release the PCMCIA
220 * configuration. If the device is still open, this will be postponed until it
221 * is closed.
222 *
223 * PARAMETERS:
224 *
225 * arg - a u_long representing a pointer to a dev_link_t structure for the
226 * device to be released.
227 *
228 * RETURNS:
229 *
230 * N/A
231 *
232 ******************************************************************************/
233 void wl_adapter_release( struct pcmcia_device *link )
234 {
235 DBG_FUNC( "wl_adapter_release" );
236 DBG_ENTER( DbgInfo );
237 DBG_PARAM( DbgInfo, "link", "0x%p", link);
238
239 /* Stop hardware */
240 wl_remove(link->priv);
241
242 pcmcia_disable_device(link);
243
244 DBG_LEAVE( DbgInfo );
245 } // wl_adapter_release
246 /*============================================================================*/
247
248 static int wl_adapter_suspend(struct pcmcia_device *link)
249 {
250 struct net_device *dev = link->priv;
251
252 //if (link->open) {
253 netif_device_detach(dev);
254 wl_suspend(dev);
255 //// CHECK! pcmcia_release_configuration(link->handle);
256 //}
257
258 return 0;
259 } // wl_adapter_suspend
260
261 static int wl_adapter_resume(struct pcmcia_device *link)
262 {
263 struct net_device *dev = link->priv;
264
265 wl_resume(dev);
266
267 netif_device_attach( dev );
268
269 return 0;
270 } // wl_adapter_resume
271
272 /*******************************************************************************
273 * wl_adapter_insert()
274 *******************************************************************************
275 *
276 * DESCRIPTION:
277 *
278 * wl_adapter_insert() is scheduled to run after a CARD_INSERTION event is
279 * received, to configure the PCMCIA socket, and to make the ethernet device
280 * available to the system.
281 *
282 * PARAMETERS:
283 *
284 * link - pointer to the dev_link_t structure representing the device to
285 * insert
286 *
287 * RETURNS:
288 *
289 * N/A
290 *
291 ******************************************************************************/
292 void wl_adapter_insert( struct pcmcia_device *link )
293 {
294 struct net_device *dev;
295 int i;
296 int ret;
297 /*------------------------------------------------------------------------*/
298
299 DBG_FUNC( "wl_adapter_insert" );
300 DBG_ENTER( DbgInfo );
301 DBG_PARAM( DbgInfo, "link", "0x%p", link );
302
303 dev = link->priv;
304
305 /* Do we need to allocate an interrupt? */
306 link->conf.Attributes |= CONF_ENABLE_IRQ;
307 link->io_lines = 6;
308
309 ret = pcmcia_request_io(link);
310 if (ret != 0)
311 goto failed;
312
313 ret = pcmcia_request_irq(link, (void *) wl_isr);
314 if (ret != 0)
315 goto failed;
316
317 ret = pcmcia_request_configuration(link, &link->conf);
318 if (ret != 0)
319 goto failed;
320
321 dev->irq = link->irq;
322 dev->base_addr = link->resource[0]->start;
323
324 SET_NETDEV_DEV(dev, &link->dev);
325 if (register_netdev(dev) != 0) {
326 printk("%s: register_netdev() failed\n", MODULE_NAME);
327 goto failed;
328 }
329
330 register_wlags_sysfs(dev);
331
332 printk(KERN_INFO "%s: Wireless, io_addr %#03lx, irq %d, ""mac_address ",
333 dev->name, dev->base_addr, dev->irq);
334 for( i = 0; i < ETH_ALEN; i++ ) {
335 printk("%02X%c", dev->dev_addr[i], ((i < (ETH_ALEN-1)) ? ':' : '\n'));
336 }
337
338 DBG_LEAVE( DbgInfo );
339 return;
340
341 failed:
342 wl_adapter_release( link );
343
344 DBG_LEAVE(DbgInfo);
345 return;
346 } // wl_adapter_insert
347 /*============================================================================*/
348
349
350 /*******************************************************************************
351 * wl_adapter_open()
352 *******************************************************************************
353 *
354 * DESCRIPTION:
355 *
356 * Open the device.
357 *
358 * PARAMETERS:
359 *
360 * dev - a pointer to a net_device structure representing the network
361 * device to open.
362 *
363 * RETURNS:
364 *
365 * 0 on success
366 * errno value otherwise
367 *
368 ******************************************************************************/
369 int wl_adapter_open( struct net_device *dev )
370 {
371 struct wl_private *lp = wl_priv(dev);
372 struct pcmcia_device *link = lp->link;
373 int result = 0;
374 int hcf_status = HCF_SUCCESS;
375 /*------------------------------------------------------------------------*/
376
377
378 DBG_FUNC( "wl_adapter_open" );
379 DBG_ENTER( DbgInfo );
380 DBG_PRINT( "%s\n", VERSION_INFO );
381 DBG_PARAM( DbgInfo, "dev", "%s (0x%p)", dev->name, dev );
382
383 if(!pcmcia_dev_present(link))
384 {
385 DBG_LEAVE( DbgInfo );
386 return -ENODEV;
387 }
388
389 link->open++;
390
391 hcf_status = wl_open( dev );
392
393 if( hcf_status != HCF_SUCCESS ) {
394 link->open--;
395 result = -ENODEV;
396 }
397
398 DBG_LEAVE( DbgInfo );
399 return result;
400 } // wl_adapter_open
401 /*============================================================================*/
402
403
404 /*******************************************************************************
405 * wl_adapter_close()
406 *******************************************************************************
407 *
408 * DESCRIPTION:
409 *
410 * Close the device.
411 *
412 * PARAMETERS:
413 *
414 * dev - a pointer to a net_device structure representing the network
415 * device to close.
416 *
417 * RETURNS:
418 *
419 * 0 on success
420 * errno value otherwise
421 *
422 ******************************************************************************/
423 int wl_adapter_close( struct net_device *dev )
424 {
425 struct wl_private *lp = wl_priv(dev);
426 struct pcmcia_device *link = lp->link;
427 /*------------------------------------------------------------------------*/
428
429
430 DBG_FUNC( "wl_adapter_close" );
431 DBG_ENTER( DbgInfo );
432 DBG_PARAM( DbgInfo, "dev", "%s (0x%p)", dev->name, dev );
433
434 if( link == NULL ) {
435 DBG_LEAVE( DbgInfo );
436 return -ENODEV;
437 }
438
439 DBG_TRACE( DbgInfo, "%s: Shutting down adapter.\n", dev->name );
440 wl_close( dev );
441
442 link->open--;
443
444 DBG_LEAVE( DbgInfo );
445 return 0;
446 } // wl_adapter_close
447 /*============================================================================*/
448
449 static struct pcmcia_device_id wl_adapter_ids[] = {
450 #if ! ((HCF_TYPE) & HCF_TYPE_HII5)
451 PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0003),
452 PCMCIA_DEVICE_PROD_ID12("Agere Systems", "Wireless PC Card Model 0110",
453 0x33103a9b, 0xe175b0dd),
454 #else
455 PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0004),
456 PCMCIA_DEVICE_PROD_ID12("Linksys", "WCF54G_Wireless-G_CompactFlash_Card",
457 0x0733cc81, 0x98a599e1),
458 #endif // (HCF_TYPE) & HCF_TYPE_HII5
459 PCMCIA_DEVICE_NULL,
460 };
461 MODULE_DEVICE_TABLE(pcmcia, wl_adapter_ids);
462
463 static struct pcmcia_driver wlags49_driver = {
464 .owner = THIS_MODULE,
465 .drv = {
466 .name = DRIVER_NAME,
467 },
468 .probe = wl_adapter_attach,
469 .remove = wl_adapter_detach,
470 .id_table = wl_adapter_ids,
471 .suspend = wl_adapter_suspend,
472 .resume = wl_adapter_resume,
473 };
474
475
476
477 /*******************************************************************************
478 * wl_adapter_init_module()
479 *******************************************************************************
480 *
481 * DESCRIPTION:
482 *
483 * Called by init_module() to perform PCMCIA driver initialization.
484 *
485 * PARAMETERS:
486 *
487 * N/A
488 *
489 * RETURNS:
490 *
491 * 0 on success
492 * -1 on error
493 *
494 ******************************************************************************/
495 int wl_adapter_init_module( void )
496 {
497 int ret;
498 /*------------------------------------------------------------------------*/
499
500
501 DBG_FUNC( "wl_adapter_init_module" );
502 DBG_ENTER( DbgInfo );
503 DBG_TRACE( DbgInfo, "wl_adapter_init_module() -- PCMCIA\n" );
504
505 ret = pcmcia_register_driver(&wlags49_driver);
506
507 DBG_LEAVE( DbgInfo );
508 return ret;
509 } // wl_adapter_init_module
510 /*============================================================================*/
511
512
513 /*******************************************************************************
514 * wl_adapter_cleanup_module()
515 *******************************************************************************
516 *
517 * DESCRIPTION:
518 *
519 * Called by cleanup_module() to perform driver uninitialization.
520 *
521 * PARAMETERS:
522 *
523 * N/A
524 *
525 * RETURNS:
526 *
527 * N/A
528 *
529 ******************************************************************************/
530 void wl_adapter_cleanup_module( void )
531 {
532 DBG_FUNC( "wl_adapter_cleanup_module" );
533 DBG_ENTER( DbgInfo );
534 DBG_TRACE( DbgInfo, "wl_adapter_cleanup_module() -- PCMCIA\n" );
535
536
537 pcmcia_unregister_driver(&wlags49_driver);
538
539 DBG_LEAVE( DbgInfo );
540 return;
541 } // wl_adapter_cleanup_module
542 /*============================================================================*/
543
544
545 /*******************************************************************************
546 * wl_adapter_is_open()
547 *******************************************************************************
548 *
549 * DESCRIPTION:
550 *
551 * Check with Card Services to determine if this device is open.
552 *
553 * PARAMETERS:
554 *
555 * dev - a pointer to the net_device structure whose open status will be
556 * checked
557 *
558 * RETURNS:
559 *
560 * nonzero if device is open
561 * 0 otherwise
562 *
563 ******************************************************************************/
564 int wl_adapter_is_open( struct net_device *dev )
565 {
566 struct wl_private *lp = wl_priv(dev);
567 struct pcmcia_device *link = lp->link;
568
569 if(!pcmcia_dev_present(link)) {
570 return 0;
571 }
572
573 return( link->open );
574 } // wl_adapter_is_open
575 /*============================================================================*/
576
577
578 #if DBG
579
580 /*******************************************************************************
581 * DbgEvent()
582 *******************************************************************************
583 *
584 * DESCRIPTION:
585 *
586 * Converts the card serivces events to text for debugging.
587 *
588 * PARAMETERS:
589 *
590 * mask - a integer representing the error(s) being reported by Card
591 * Services.
592 *
593 * RETURNS:
594 *
595 * a pointer to a string describing the error(s)
596 *
597 ******************************************************************************/
598 const char* DbgEvent( int mask )
599 {
600 static char DbgBuffer[256];
601 char *pBuf;
602 /*------------------------------------------------------------------------*/
603
604
605 pBuf = DbgBuffer;
606 *pBuf = '\0';
607
608
609 if( mask & CS_EVENT_WRITE_PROTECT )
610 strcat( pBuf, "WRITE_PROTECT " );
611
612 if(mask & CS_EVENT_CARD_LOCK)
613 strcat( pBuf, "CARD_LOCK " );
614
615 if(mask & CS_EVENT_CARD_INSERTION)
616 strcat( pBuf, "CARD_INSERTION " );
617
618 if(mask & CS_EVENT_CARD_REMOVAL)
619 strcat( pBuf, "CARD_REMOVAL " );
620
621 if(mask & CS_EVENT_BATTERY_DEAD)
622 strcat( pBuf, "BATTERY_DEAD " );
623
624 if(mask & CS_EVENT_BATTERY_LOW)
625 strcat( pBuf, "BATTERY_LOW " );
626
627 if(mask & CS_EVENT_READY_CHANGE)
628 strcat( pBuf, "READY_CHANGE " );
629
630 if(mask & CS_EVENT_CARD_DETECT)
631 strcat( pBuf, "CARD_DETECT " );
632
633 if(mask & CS_EVENT_RESET_REQUEST)
634 strcat( pBuf, "RESET_REQUEST " );
635
636 if(mask & CS_EVENT_RESET_PHYSICAL)
637 strcat( pBuf, "RESET_PHYSICAL " );
638
639 if(mask & CS_EVENT_CARD_RESET)
640 strcat( pBuf, "CARD_RESET " );
641
642 if(mask & CS_EVENT_REGISTRATION_COMPLETE)
643 strcat( pBuf, "REGISTRATION_COMPLETE " );
644
645 // if(mask & CS_EVENT_RESET_COMPLETE)
646 // strcat( pBuf, "RESET_COMPLETE " );
647
648 if(mask & CS_EVENT_PM_SUSPEND)
649 strcat( pBuf, "PM_SUSPEND " );
650
651 if(mask & CS_EVENT_PM_RESUME)
652 strcat( pBuf, "PM_RESUME " );
653
654 if(mask & CS_EVENT_INSERTION_REQUEST)
655 strcat( pBuf, "INSERTION_REQUEST " );
656
657 if(mask & CS_EVENT_EJECTION_REQUEST)
658 strcat( pBuf, "EJECTION_REQUEST " );
659
660 if(mask & CS_EVENT_MTD_REQUEST)
661 strcat( pBuf, "MTD_REQUEST " );
662
663 if(mask & CS_EVENT_ERASE_COMPLETE)
664 strcat( pBuf, "ERASE_COMPLETE " );
665
666 if(mask & CS_EVENT_REQUEST_ATTENTION)
667 strcat( pBuf, "REQUEST_ATTENTION " );
668
669 if(mask & CS_EVENT_CB_DETECT)
670 strcat( pBuf, "CB_DETECT " );
671
672 if(mask & CS_EVENT_3VCARD)
673 strcat( pBuf, "3VCARD " );
674
675 if(mask & CS_EVENT_XVCARD)
676 strcat( pBuf, "XVCARD " );
677
678
679 if( *pBuf ) {
680 pBuf[strlen(pBuf) - 1] = '\0';
681 } else {
682 if( mask != 0x0 ) {
683 sprintf( pBuf, "<<0x%08x>>", mask );
684 }
685 }
686
687 return pBuf;
688 } // DbgEvent
689 /*============================================================================*/
690
691 #endif /* DBG */
This page took 0.047885 seconds and 5 git commands to generate.