1 /*======================================================================
3 Aironet driver for 4500 and 4800 series cards
5 This code is released under both the GPL version 2 and BSD licenses.
6 Either license may be used. The respective licenses are found at
9 This code was developed by Benjamin Reed <breed@users.sourceforge.net>
10 including portions of which come from the Aironet PC4500
11 Developer's Reference Manual and used with permission. Copyright
12 (C) 1999 Benjamin Reed. All Rights Reserved. Permission to use
13 code in the Developer's manual was granted for this driver by
16 In addition this module was derived from dummy_cs.
17 The initial developer of dummy_cs is David A. Hinds
18 <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
19 are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
21 ======================================================================*/
23 #include <linux/config.h>
24 #ifdef __IN_PCMCIA_PACKAGE__
25 #include <pcmcia/k_compat.h>
27 #include <linux/init.h>
28 #include <linux/kernel.h>
29 #include <linux/module.h>
30 #include <linux/ptrace.h>
31 #include <linux/slab.h>
32 #include <linux/string.h>
33 #include <linux/timer.h>
34 #include <linux/netdevice.h>
36 #include <pcmcia/version.h>
37 #include <pcmcia/cs_types.h>
38 #include <pcmcia/cs.h>
39 #include <pcmcia/cistpl.h>
40 #include <pcmcia/cisreg.h>
41 #include <pcmcia/ds.h>
44 #include <asm/system.h>
47 All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If
48 you do not define PCMCIA_DEBUG at all, all the debug code will be
49 left out. If you compile with PCMCIA_DEBUG=0, the debug code will
50 be present but disabled -- but it can then be enabled for specific
51 modules at load time with a 'pc_debug=#' option to insmod.
54 static int pc_debug
= PCMCIA_DEBUG
;
55 module_param(pc_debug
, int, 0);
56 static char *version
= "$Revision: 1.2 $";
57 #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args);
59 #define DEBUG(n, args...)
62 /*====================================================================*/
64 MODULE_AUTHOR("Benjamin Reed");
65 MODULE_DESCRIPTION("Support for Cisco/Aironet 802.11 wireless ethernet \
66 cards. This is the module that links the PCMCIA card \
67 with the airo module.");
68 MODULE_LICENSE("Dual BSD/GPL");
69 MODULE_SUPPORTED_DEVICE("Aironet 4500, 4800 and Cisco 340 PCMCIA cards");
71 /*====================================================================*/
74 The event() function is this driver's Card Services event handler.
75 It will be called by Card Services when an appropriate card status
76 event is received. The config() and release() entry points are
77 used to configure or release a socket, in response to card
78 insertion and ejection events. They are invoked from the airo_cs
82 struct net_device
*init_airo_card( int, int, int, struct device
* );
83 void stop_airo_card( struct net_device
*, int );
84 int reset_airo_card( struct net_device
* );
86 static void airo_config(dev_link_t
*link
);
87 static void airo_release(dev_link_t
*link
);
88 static int airo_event(event_t event
, int priority
,
89 event_callback_args_t
*args
);
92 The attach() and detach() entry points are used to create and destroy
93 "instances" of the driver, where each instance represents everything
94 needed to manage one actual PCMCIA card.
97 static dev_link_t
*airo_attach(void);
98 static void airo_detach(dev_link_t
*);
101 You'll also need to prototype all the functions that will actually
102 be used to talk to your device. See 'pcmem_cs' for a good example
103 of a fully self-sufficient driver; the other drivers rely more or
104 less on other parts of the kernel.
108 The dev_info variable is the "key" that is used to match up this
109 device driver with appropriate cards, through the card configuration
113 static dev_info_t dev_info
= "airo_cs";
116 A linked list of "instances" of the aironet device. Each actual
117 PCMCIA card corresponds to one device instance, and is described
118 by one dev_link_t structure (defined in ds.h).
120 You may not want to use a linked list for this -- for example, the
121 memory card driver uses an array of dev_link_t pointers, where minor
122 device numbers are used to derive the corresponding array index.
125 static dev_link_t
*dev_list
= NULL
;
128 A dev_link_t structure has fields for most things that are needed
129 to keep track of a socket, but there will usually be some device
130 specific information that also needs to be kept track of. The
131 'priv' pointer in a dev_link_t structure can be used to point to
132 a device-specific private data structure, like this.
134 A driver needs to provide a dev_node_t structure for each device
135 on a card. In some cases, there is only one device per card (for
136 example, ethernet cards, modems). In other cases, there may be
137 many actual or logical devices (SCSI adapters, memory cards with
138 multiple partitions). The dev_node_t structures need to be kept
139 in a linked list starting at the 'dev' field of a dev_link_t
140 structure. We allocate them in the card's private data structure,
141 because they generally shouldn't be allocated dynamically.
143 In this case, we also provide a flag to indicate if a device is
144 "stopped" due to a power management event, or card ejection. The
145 device IO routines can use a flag like this to throttle IO to a
146 card that is not ready to accept it.
149 typedef struct local_info_t
{
151 struct net_device
*eth_dev
;
154 /*======================================================================
156 airo_attach() creates an "instance" of the driver, allocating
157 local data structures for one device. The device is registered
160 The dev_link structure is initialized, but we don't actually
161 configure the card at this point -- we wait until we receive a
162 card insertion event.
164 ======================================================================*/
166 static dev_link_t
*airo_attach(void)
168 client_reg_t client_reg
;
173 DEBUG(0, "airo_attach()\n");
175 /* Initialize the dev_link_t structure */
176 link
= kmalloc(sizeof(struct dev_link_t
), GFP_KERNEL
);
178 printk(KERN_ERR
"airo_cs: no memory for new device\n");
181 memset(link
, 0, sizeof(struct dev_link_t
));
183 /* Interrupt setup */
184 link
->irq
.Attributes
= IRQ_TYPE_EXCLUSIVE
;
185 link
->irq
.IRQInfo1
= IRQ_LEVEL_ID
;
186 link
->irq
.Handler
= NULL
;
189 General socket configuration defaults can go here. In this
190 client, we assume very little, and rely on the CIS for almost
191 everything. In most clients, many details (i.e., number, sizes,
192 and attributes of IO windows) are fixed by the nature of the
193 device, and can be hard-wired here.
195 link
->conf
.Attributes
= 0;
197 link
->conf
.IntType
= INT_MEMORY_AND_IO
;
199 /* Allocate space for private device-specific data */
200 local
= kmalloc(sizeof(local_info_t
), GFP_KERNEL
);
202 printk(KERN_ERR
"airo_cs: no memory for new device\n");
206 memset(local
, 0, sizeof(local_info_t
));
209 /* Register with Card Services */
210 link
->next
= dev_list
;
212 client_reg
.dev_info
= &dev_info
;
213 client_reg
.Version
= 0x0210;
214 client_reg
.event_callback_args
.client_data
= link
;
215 ret
= pcmcia_register_client(&link
->handle
, &client_reg
);
217 cs_error(link
->handle
, RegisterClient
, ret
);
225 /*======================================================================
227 This deletes a driver "instance". The device is de-registered
228 with Card Services. If it has been released, all local data
229 structures are freed. Otherwise, the structures will be freed
230 when the device is released.
232 ======================================================================*/
234 static void airo_detach(dev_link_t
*link
)
238 DEBUG(0, "airo_detach(0x%p)\n", link
);
240 /* Locate device structure */
241 for (linkp
= &dev_list
; *linkp
; linkp
= &(*linkp
)->next
)
242 if (*linkp
== link
) break;
246 if (link
->state
& DEV_CONFIG
)
249 if ( ((local_info_t
*)link
->priv
)->eth_dev
) {
250 stop_airo_card( ((local_info_t
*)link
->priv
)->eth_dev
, 0 );
252 ((local_info_t
*)link
->priv
)->eth_dev
= NULL
;
254 /* Break the link with Card Services */
256 pcmcia_deregister_client(link
->handle
);
260 /* Unlink device structure, free pieces */
269 /*======================================================================
271 airo_config() is scheduled to run after a CARD_INSERTION event
272 is received, to configure the PCMCIA socket, and to make the
273 device available to the system.
275 ======================================================================*/
277 #define CS_CHECK(fn, ret) \
278 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
280 static void airo_config(dev_link_t
*link
)
282 client_handle_t handle
;
286 int last_fn
, last_ret
;
291 handle
= link
->handle
;
294 DEBUG(0, "airo_config(0x%p)\n", link
);
297 This reads the card's CONFIG tuple to find its configuration
300 tuple
.DesiredTuple
= CISTPL_CONFIG
;
301 tuple
.Attributes
= 0;
302 tuple
.TupleData
= buf
;
303 tuple
.TupleDataMax
= sizeof(buf
);
304 tuple
.TupleOffset
= 0;
305 CS_CHECK(GetFirstTuple
, pcmcia_get_first_tuple(handle
, &tuple
));
306 CS_CHECK(GetTupleData
, pcmcia_get_tuple_data(handle
, &tuple
));
307 CS_CHECK(ParseTuple
, pcmcia_parse_tuple(handle
, &tuple
, &parse
));
308 link
->conf
.ConfigBase
= parse
.config
.base
;
309 link
->conf
.Present
= parse
.config
.rmask
[0];
312 link
->state
|= DEV_CONFIG
;
315 In this loop, we scan the CIS for configuration table entries,
316 each of which describes a valid card configuration, including
317 voltage, IO window, memory window, and interrupt settings.
319 We make no assumptions about the card to be configured: we use
320 just the information available in the CIS. In an ideal world,
321 this would work for any PCMCIA card, but it requires a complete
322 and accurate CIS. In practice, a driver usually "knows" most of
323 these things without consulting the CIS, and most client drivers
324 will only use the CIS to fill in implementation-defined details.
326 tuple
.DesiredTuple
= CISTPL_CFTABLE_ENTRY
;
327 CS_CHECK(GetFirstTuple
, pcmcia_get_first_tuple(handle
, &tuple
));
329 cistpl_cftable_entry_t dflt
= { 0 };
330 cistpl_cftable_entry_t
*cfg
= &(parse
.cftable_entry
);
331 if (pcmcia_get_tuple_data(handle
, &tuple
) != 0 ||
332 pcmcia_parse_tuple(handle
, &tuple
, &parse
) != 0)
335 if (cfg
->flags
& CISTPL_CFTABLE_DEFAULT
) dflt
= *cfg
;
336 if (cfg
->index
== 0) goto next_entry
;
337 link
->conf
.ConfigIndex
= cfg
->index
;
339 /* Does this card need audio output? */
340 if (cfg
->flags
& CISTPL_CFTABLE_AUDIO
) {
341 link
->conf
.Attributes
|= CONF_ENABLE_SPKR
;
342 link
->conf
.Status
= CCSR_AUDIO_ENA
;
345 /* Use power settings for Vcc and Vpp if present */
346 /* Note that the CIS values need to be rescaled */
347 if (cfg
->vcc
.present
& (1<<CISTPL_POWER_VNOM
))
348 link
->conf
.Vcc
= cfg
->vcc
.param
[CISTPL_POWER_VNOM
]/10000;
349 else if (dflt
.vcc
.present
& (1<<CISTPL_POWER_VNOM
))
350 link
->conf
.Vcc
= dflt
.vcc
.param
[CISTPL_POWER_VNOM
]/10000;
352 if (cfg
->vpp1
.present
& (1<<CISTPL_POWER_VNOM
))
353 link
->conf
.Vpp1
= link
->conf
.Vpp2
=
354 cfg
->vpp1
.param
[CISTPL_POWER_VNOM
]/10000;
355 else if (dflt
.vpp1
.present
& (1<<CISTPL_POWER_VNOM
))
356 link
->conf
.Vpp1
= link
->conf
.Vpp2
=
357 dflt
.vpp1
.param
[CISTPL_POWER_VNOM
]/10000;
359 /* Do we need to allocate an interrupt? */
360 if (cfg
->irq
.IRQInfo1
|| dflt
.irq
.IRQInfo1
)
361 link
->conf
.Attributes
|= CONF_ENABLE_IRQ
;
363 /* IO window settings */
364 link
->io
.NumPorts1
= link
->io
.NumPorts2
= 0;
365 if ((cfg
->io
.nwin
> 0) || (dflt
.io
.nwin
> 0)) {
366 cistpl_io_t
*io
= (cfg
->io
.nwin
) ? &cfg
->io
: &dflt
.io
;
367 link
->io
.Attributes1
= IO_DATA_PATH_WIDTH_AUTO
;
368 if (!(io
->flags
& CISTPL_IO_8BIT
))
369 link
->io
.Attributes1
= IO_DATA_PATH_WIDTH_16
;
370 if (!(io
->flags
& CISTPL_IO_16BIT
))
371 link
->io
.Attributes1
= IO_DATA_PATH_WIDTH_8
;
372 link
->io
.BasePort1
= io
->win
[0].base
;
373 link
->io
.NumPorts1
= io
->win
[0].len
;
375 link
->io
.Attributes2
= link
->io
.Attributes1
;
376 link
->io
.BasePort2
= io
->win
[1].base
;
377 link
->io
.NumPorts2
= io
->win
[1].len
;
381 /* This reserves IO space but doesn't actually enable it */
382 if (pcmcia_request_io(link
->handle
, &link
->io
) != 0)
386 Now set up a common memory window, if needed. There is room
387 in the dev_link_t structure for one memory window handle,
388 but if the base addresses need to be saved, or if multiple
389 windows are needed, the info should go in the private data
390 structure for this device.
392 Note that the memory window base is a physical address, and
393 needs to be mapped to virtual space with ioremap() before it
396 if ((cfg
->mem
.nwin
> 0) || (dflt
.mem
.nwin
> 0)) {
398 (cfg
->mem
.nwin
) ? &cfg
->mem
: &dflt
.mem
;
399 req
.Attributes
= WIN_DATA_WIDTH_16
|WIN_MEMORY_TYPE_CM
;
400 req
.Base
= mem
->win
[0].host_addr
;
401 req
.Size
= mem
->win
[0].len
;
403 if (pcmcia_request_window(&link
->handle
, &req
, &link
->win
) != 0)
405 map
.Page
= 0; map
.CardOffset
= mem
->win
[0].card_addr
;
406 if (pcmcia_map_mem_page(link
->win
, &map
) != 0)
409 /* If we got this far, we're cool! */
413 CS_CHECK(GetNextTuple
, pcmcia_get_next_tuple(handle
, &tuple
));
417 Allocate an interrupt line. Note that this does not assign a
418 handler to the interrupt, unless the 'Handler' member of the
419 irq structure is initialized.
421 if (link
->conf
.Attributes
& CONF_ENABLE_IRQ
)
422 CS_CHECK(RequestIRQ
, pcmcia_request_irq(link
->handle
, &link
->irq
));
425 This actually configures the PCMCIA socket -- setting up
426 the I/O windows and the interrupt mapping, and putting the
427 card and host interface into "Memory and IO" mode.
429 CS_CHECK(RequestConfiguration
, pcmcia_request_configuration(link
->handle
, &link
->conf
));
430 ((local_info_t
*)link
->priv
)->eth_dev
=
431 init_airo_card( link
->irq
.AssignedIRQ
,
432 link
->io
.BasePort1
, 1, &handle_to_dev(handle
) );
433 if (!((local_info_t
*)link
->priv
)->eth_dev
) goto cs_failed
;
436 At this point, the dev_node_t structure(s) need to be
437 initialized and arranged in a linked list at link->dev.
439 strcpy(dev
->node
.dev_name
, ((local_info_t
*)link
->priv
)->eth_dev
->name
);
440 dev
->node
.major
= dev
->node
.minor
= 0;
441 link
->dev
= &dev
->node
;
443 /* Finally, report what we've done */
444 printk(KERN_INFO
"%s: index 0x%02x: Vcc %d.%d",
445 dev
->node
.dev_name
, link
->conf
.ConfigIndex
,
446 link
->conf
.Vcc
/10, link
->conf
.Vcc
%10);
448 printk(", Vpp %d.%d", link
->conf
.Vpp1
/10, link
->conf
.Vpp1
%10);
449 if (link
->conf
.Attributes
& CONF_ENABLE_IRQ
)
450 printk(", irq %d", link
->irq
.AssignedIRQ
);
451 if (link
->io
.NumPorts1
)
452 printk(", io 0x%04x-0x%04x", link
->io
.BasePort1
,
453 link
->io
.BasePort1
+link
->io
.NumPorts1
-1);
454 if (link
->io
.NumPorts2
)
455 printk(" & 0x%04x-0x%04x", link
->io
.BasePort2
,
456 link
->io
.BasePort2
+link
->io
.NumPorts2
-1);
458 printk(", mem 0x%06lx-0x%06lx", req
.Base
,
459 req
.Base
+req
.Size
-1);
462 link
->state
&= ~DEV_CONFIG_PENDING
;
466 cs_error(link
->handle
, last_fn
, last_ret
);
471 /*======================================================================
473 After a card is removed, airo_release() will unregister the
474 device, and release the PCMCIA configuration. If the device is
475 still open, this will be postponed until it is closed.
477 ======================================================================*/
479 static void airo_release(dev_link_t
*link
)
481 DEBUG(0, "airo_release(0x%p)\n", link
);
483 /* Unlink the device chain */
487 In a normal driver, additional code may be needed to release
488 other kernel data structures associated with this device.
491 /* Don't bother checking to see if these succeed or not */
493 pcmcia_release_window(link
->win
);
494 pcmcia_release_configuration(link
->handle
);
495 if (link
->io
.NumPorts1
)
496 pcmcia_release_io(link
->handle
, &link
->io
);
497 if (link
->irq
.AssignedIRQ
)
498 pcmcia_release_irq(link
->handle
, &link
->irq
);
499 link
->state
&= ~DEV_CONFIG
;
502 /*======================================================================
504 The card status event handler. Mostly, this schedules other
505 stuff to run after an event is received.
507 When a CARD_REMOVAL event is received, we immediately set a
508 private flag to block future accesses to this device. All the
509 functions that actually access the device should check this flag
510 to make sure the card is still present.
512 ======================================================================*/
514 static int airo_event(event_t event
, int priority
,
515 event_callback_args_t
*args
)
517 dev_link_t
*link
= args
->client_data
;
518 local_info_t
*local
= link
->priv
;
520 DEBUG(1, "airo_event(0x%06x)\n", event
);
523 case CS_EVENT_CARD_REMOVAL
:
524 link
->state
&= ~DEV_PRESENT
;
525 if (link
->state
& DEV_CONFIG
) {
526 netif_device_detach(local
->eth_dev
);
530 case CS_EVENT_CARD_INSERTION
:
531 link
->state
|= DEV_PRESENT
| DEV_CONFIG_PENDING
;
534 case CS_EVENT_PM_SUSPEND
:
535 link
->state
|= DEV_SUSPEND
;
536 /* Fall through... */
537 case CS_EVENT_RESET_PHYSICAL
:
538 if (link
->state
& DEV_CONFIG
) {
539 netif_device_detach(local
->eth_dev
);
540 pcmcia_release_configuration(link
->handle
);
543 case CS_EVENT_PM_RESUME
:
544 link
->state
&= ~DEV_SUSPEND
;
545 /* Fall through... */
546 case CS_EVENT_CARD_RESET
:
547 if (link
->state
& DEV_CONFIG
) {
548 pcmcia_request_configuration(link
->handle
, &link
->conf
);
549 reset_airo_card(local
->eth_dev
);
550 netif_device_attach(local
->eth_dev
);
557 static struct pcmcia_device_id airo_ids
[] = {
558 PCMCIA_DEVICE_MANF_CARD(0x015f, 0x000a),
559 PCMCIA_DEVICE_MANF_CARD(0x015f, 0x0005),
560 PCMCIA_DEVICE_MANF_CARD(0x015f, 0x0007),
561 PCMCIA_DEVICE_MANF_CARD(0x0105, 0x0007),
564 MODULE_DEVICE_TABLE(pcmcia
, airo_ids
);
566 static struct pcmcia_driver airo_driver
= {
567 .owner
= THIS_MODULE
,
571 .attach
= airo_attach
,
573 .detach
= airo_detach
,
574 .id_table
= airo_ids
,
577 static int airo_cs_init(void)
579 return pcmcia_register_driver(&airo_driver
);
582 static void airo_cs_cleanup(void)
584 pcmcia_unregister_driver(&airo_driver
);
585 BUG_ON(dev_list
!= NULL
);
589 This program is free software; you can redistribute it and/or
590 modify it under the terms of the GNU General Public License
591 as published by the Free Software Foundation; either version 2
592 of the License, or (at your option) any later version.
594 This program is distributed in the hope that it will be useful,
595 but WITHOUT ANY WARRANTY; without even the implied warranty of
596 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
597 GNU General Public License for more details.
601 Redistribution and use in source and binary forms, with or without
602 modification, are permitted provided that the following conditions
605 1. Redistributions of source code must retain the above copyright
606 notice, this list of conditions and the following disclaimer.
607 2. Redistributions in binary form must reproduce the above copyright
608 notice, this list of conditions and the following disclaimer in the
609 documentation and/or other materials provided with the distribution.
610 3. The name of the author may not be used to endorse or promote
611 products derived from this software without specific prior written
614 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
615 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
616 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
617 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
618 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
619 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
620 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
621 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
622 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
623 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
624 POSSIBILITY OF SUCH DAMAGE.
627 module_init(airo_cs_init
);
628 module_exit(airo_cs_cleanup
);