File: /usr/src/linux/drivers/net/wireless/airo_cs.c

1     /*======================================================================
2     
3         Aironet driver for 4500 and 4800 series cards
4     
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
7         the end of this file.
8     
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
14         Aironet.
15     
16         In addition this module was derived from dummy_cs.
17         The initial developer of dummy_cs is David A. Hinds
18         <dhinds@hyper.stanford.edu>.  Portions created by David A. Hinds
19         are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.    
20         
21     ======================================================================*/
22     
23     #include <linux/config.h>
24     #ifdef __IN_PCMCIA_PACKAGE__
25     #include <pcmcia/k_compat.h>
26     #endif
27     
28     #include <linux/init.h>
29     #include <linux/kernel.h>
30     #include <linux/module.h>
31     
32     #include <linux/sched.h>
33     #include <linux/ptrace.h>
34     #include <linux/slab.h>
35     #include <linux/string.h>
36     #include <linux/timer.h>
37     #include <linux/netdevice.h>
38     #include <asm/io.h>
39     #include <asm/system.h>
40     
41     #include <pcmcia/version.h>
42     #include <pcmcia/cs_types.h>
43     #include <pcmcia/cs.h>
44     #include <pcmcia/cistpl.h>
45     #include <pcmcia/cisreg.h>
46     #include <pcmcia/ds.h>
47     
48     /*
49        All the PCMCIA modules use PCMCIA_DEBUG to control debugging.  If
50        you do not define PCMCIA_DEBUG at all, all the debug code will be
51        left out.  If you compile with PCMCIA_DEBUG=0, the debug code will
52        be present but disabled -- but it can then be enabled for specific
53        modules at load time with a 'pc_debug=#' option to insmod.
54     */
55     #ifdef PCMCIA_DEBUG
56     static int pc_debug = PCMCIA_DEBUG;
57     MODULE_PARM(pc_debug, "i");
58     static char *version = "$Revision: 1.2 $";
59     #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args);
60     #else
61     #define DEBUG(n, args...)
62     #endif
63     
64     /*====================================================================*/
65     
66     /* Parameters that can be set with 'insmod' */
67     
68     /* The old way: bit map of interrupts to choose from */
69     /* This means pick from 15, 14, 12, 11, 10, 9, 7, 5, 4, and 3 */
70     static u_int irq_mask = 0xdeb8;
71     /* Newer, simpler way of listing specific interrupts */
72     static int irq_list[4] = { -1 };
73     
74     MODULE_AUTHOR("Benjamin Reed");
75     MODULE_DESCRIPTION("Support for Cisco/Aironet 802.11 wireless ethernet \
76                        cards.  This is the module that links the PCMCIA card \
77     		   with the airo module.");
78     MODULE_LICENSE("Dual BSD/GPL");
79     MODULE_SUPPORTED_DEVICE("Aironet 4500, 4800 and Cisco 340 PCMCIA cards");
80     MODULE_PARM(irq_mask, "i");
81     MODULE_PARM(irq_list, "1-4i");
82     
83     /*====================================================================*/
84     
85     /*
86        The event() function is this driver's Card Services event handler.
87        It will be called by Card Services when an appropriate card status
88        event is received.  The config() and release() entry points are
89        used to configure or release a socket, in response to card
90        insertion and ejection events.  They are invoked from the airo_cs
91        event handler. 
92     */
93     
94     struct net_device *init_airo_card( int, int, int );
95     void stop_airo_card( struct net_device *, int );
96     int reset_airo_card( struct net_device * );
97     
98     static void airo_config(dev_link_t *link);
99     static void airo_release(u_long arg);
100     static int airo_event(event_t event, int priority,
101     		       event_callback_args_t *args);
102     
103     /*
104        The attach() and detach() entry points are used to create and destroy
105        "instances" of the driver, where each instance represents everything
106        needed to manage one actual PCMCIA card.
107     */
108     
109     static dev_link_t *airo_attach(void);
110     static void airo_detach(dev_link_t *);
111     
112     /*
113        You'll also need to prototype all the functions that will actually
114        be used to talk to your device.  See 'pcmem_cs' for a good example
115        of a fully self-sufficient driver; the other drivers rely more or
116        less on other parts of the kernel.
117     */
118     
119     /*
120        The dev_info variable is the "key" that is used to match up this
121        device driver with appropriate cards, through the card configuration
122        database.
123     */
124     
125     static dev_info_t dev_info = "airo_cs";
126     
127     /*
128        A linked list of "instances" of the  aironet device.  Each actual
129        PCMCIA card corresponds to one device instance, and is described
130        by one dev_link_t structure (defined in ds.h).
131     
132        You may not want to use a linked list for this -- for example, the
133        memory card driver uses an array of dev_link_t pointers, where minor
134        device numbers are used to derive the corresponding array index.
135     */
136     
137     static dev_link_t *dev_list = NULL;
138     
139     /*
140        A dev_link_t structure has fields for most things that are needed
141        to keep track of a socket, but there will usually be some device
142        specific information that also needs to be kept track of.  The
143        'priv' pointer in a dev_link_t structure can be used to point to
144        a device-specific private data structure, like this.
145     
146        A driver needs to provide a dev_node_t structure for each device
147        on a card.  In some cases, there is only one device per card (for
148        example, ethernet cards, modems).  In other cases, there may be
149        many actual or logical devices (SCSI adapters, memory cards with
150        multiple partitions).  The dev_node_t structures need to be kept
151        in a linked list starting at the 'dev' field of a dev_link_t
152        structure.  We allocate them in the card's private data structure,
153        because they generally shouldn't be allocated dynamically.
154     
155        In this case, we also provide a flag to indicate if a device is
156        "stopped" due to a power management event, or card ejection.  The
157        device IO routines can use a flag like this to throttle IO to a
158        card that is not ready to accept it.
159     */
160        
161     typedef struct local_info_t {
162     	dev_node_t	node;
163     	struct net_device *eth_dev;
164     } local_info_t;
165     
166     /*====================================================================*/
167     
168     static void cs_error(client_handle_t handle, int func, int ret)
169     {
170     	error_info_t err = { func, ret };
171     	CardServices(ReportError, handle, &err);
172     }
173     
174     /*======================================================================
175       
176       This bit of code is used to avoid unregistering network devices
177       at inappropriate times.  2.2 and later kernels are fairly picky
178       about when this can happen.
179       
180       ======================================================================*/
181     
182     static void flush_stale_links(void)
183     {
184     	dev_link_t *link, *next;
185     	for (link = dev_list; link; link = next) {
186     		next = link->next;
187     		if (link->state & DEV_STALE_LINK)
188     			airo_detach(link);
189     	}
190     }
191      
192     /*======================================================================
193       
194       airo_attach() creates an "instance" of the driver, allocating
195       local data structures for one device.  The device is registered
196       with Card Services.
197       
198       The dev_link structure is initialized, but we don't actually
199       configure the card at this point -- we wait until we receive a
200       card insertion event.
201       
202       ======================================================================*/
203     
204     static dev_link_t *airo_attach(void)
205     {
206     	client_reg_t client_reg;
207     	dev_link_t *link;
208     	local_info_t *local;
209     	int ret, i;
210     	
211     	DEBUG(0, "airo_attach()\n");
212     	flush_stale_links();
213     	
214     	/* Initialize the dev_link_t structure */
215     	link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
216     	if (!link) {
217     		printk(KERN_ERR "airo_cs: no memory for new device\n");
218     		return NULL;
219     	}
220     	memset(link, 0, sizeof(struct dev_link_t));
221     	link->release.function = &airo_release;
222     	link->release.data = (u_long)link;
223     	
224     	/* Interrupt setup */
225     	link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
226     	link->irq.IRQInfo1 = IRQ_INFO2_VALID|IRQ_LEVEL_ID;
227     	if (irq_list[0] == -1)
228     		link->irq.IRQInfo2 = irq_mask;
229     	else
230     		for (i = 0; i < 4; i++)
231     			link->irq.IRQInfo2 |= 1 << irq_list[i];
232     	link->irq.Handler = NULL;
233     	
234     	/*
235     	  General socket configuration defaults can go here.  In this
236     	  client, we assume very little, and rely on the CIS for almost
237     	  everything.  In most clients, many details (i.e., number, sizes,
238     	  and attributes of IO windows) are fixed by the nature of the
239     	  device, and can be hard-wired here.
240     	*/
241     	link->conf.Attributes = 0;
242     	link->conf.Vcc = 50;
243     	link->conf.IntType = INT_MEMORY_AND_IO;
244     	
245     	/* Allocate space for private device-specific data */
246     	local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
247     	memset(local, 0, sizeof(local_info_t));
248     	link->priv = local;
249     	
250     	/* Register with Card Services */
251     	link->next = dev_list;
252     	dev_list = link;
253     	client_reg.dev_info = &dev_info;
254     	client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
255     	client_reg.EventMask =
256     		CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
257     		CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
258     		CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
259     	client_reg.event_handler = &airo_event;
260     	client_reg.Version = 0x0210;
261     	client_reg.event_callback_args.client_data = link;
262     	ret = CardServices(RegisterClient, &link->handle, &client_reg);
263     	if (ret != 0) {
264     		cs_error(link->handle, RegisterClient, ret);
265     		airo_detach(link);
266     		return NULL;
267     	}
268     	
269     	return link;
270     } /* airo_attach */
271     
272     /*======================================================================
273       
274       This deletes a driver "instance".  The device is de-registered
275       with Card Services.  If it has been released, all local data
276       structures are freed.  Otherwise, the structures will be freed
277       when the device is released.
278       
279       ======================================================================*/
280     
281     static void airo_detach(dev_link_t *link)
282     {
283     	dev_link_t **linkp;
284     	
285     	DEBUG(0, "airo_detach(0x%p)\n", link);
286     	
287     	/* Locate device structure */
288     	for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
289     		if (*linkp == link) break;
290     	if (*linkp == NULL)
291     		return;
292     	
293     	del_timer(&link->release);
294     	if ( link->state & DEV_CONFIG ) {
295     		airo_release( (int)link );
296     		if ( link->state & DEV_STALE_CONFIG ) {
297     			link->state |= DEV_STALE_LINK;
298     			return;
299     		}
300     	}
301     	
302     	if ( ((local_info_t*)link->priv)->eth_dev ) {
303     		stop_airo_card( ((local_info_t*)link->priv)->eth_dev, 0 );
304     	}
305     	((local_info_t*)link->priv)->eth_dev = 0;   
306     	
307     	/* Break the link with Card Services */
308     	if (link->handle)
309     		CardServices(DeregisterClient, link->handle);
310     	
311     	
312     	
313     	/* Unlink device structure, free pieces */
314     	*linkp = link->next;
315     	if (link->priv) {
316     		kfree(link->priv);
317     	}
318     	kfree(link);
319     	
320     } /* airo_detach */
321     
322     /*======================================================================
323       
324       airo_config() is scheduled to run after a CARD_INSERTION event
325       is received, to configure the PCMCIA socket, and to make the
326       device available to the system.
327       
328       ======================================================================*/
329     
330     #define CS_CHECK(fn, args...) \
331     while ((last_ret=CardServices(last_fn=(fn),args))!=0) goto cs_failed
332     
333     #define CFG_CHECK(fn, args...) \
334     if (CardServices(fn, args) != 0) goto next_entry
335     
336     static void airo_config(dev_link_t *link)
337     {
338     	client_handle_t handle;
339     	tuple_t tuple;
340     	cisparse_t parse;
341     	local_info_t *dev;
342     	int last_fn, last_ret;
343     	u_char buf[64];
344     	win_req_t req;
345     	memreq_t map;
346     	
347     	handle = link->handle;
348     	dev = link->priv;
349     
350     	DEBUG(0, "airo_config(0x%p)\n", link);
351     	
352     	/*
353     	  This reads the card's CONFIG tuple to find its configuration
354     	  registers.
355     	*/
356     	tuple.DesiredTuple = CISTPL_CONFIG;
357     	tuple.Attributes = 0;
358     	tuple.TupleData = buf;
359     	tuple.TupleDataMax = sizeof(buf);
360     	tuple.TupleOffset = 0;
361     	CS_CHECK(GetFirstTuple, handle, &tuple);
362     	CS_CHECK(GetTupleData, handle, &tuple);
363     	CS_CHECK(ParseTuple, handle, &tuple, &parse);
364     	link->conf.ConfigBase = parse.config.base;
365     	link->conf.Present = parse.config.rmask[0];
366     	
367     	/* Configure card */
368     	link->state |= DEV_CONFIG;
369     	
370     	/*
371     	  In this loop, we scan the CIS for configuration table entries,
372     	  each of which describes a valid card configuration, including
373     	  voltage, IO window, memory window, and interrupt settings.
374     	  
375     	  We make no assumptions about the card to be configured: we use
376     	  just the information available in the CIS.  In an ideal world,
377     	  this would work for any PCMCIA card, but it requires a complete
378     	  and accurate CIS.  In practice, a driver usually "knows" most of
379     	  these things without consulting the CIS, and most client drivers
380     	  will only use the CIS to fill in implementation-defined details.
381     	*/
382     	tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
383     	CS_CHECK(GetFirstTuple, handle, &tuple);
384     	while (1) {
385     		cistpl_cftable_entry_t dflt = { 0 };
386     		cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
387     		CFG_CHECK(GetTupleData, handle, &tuple);
388     		CFG_CHECK(ParseTuple, handle, &tuple, &parse);
389     		
390     		if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
391     		if (cfg->index == 0) goto next_entry;
392     		link->conf.ConfigIndex = cfg->index;
393     		
394     		/* Does this card need audio output? */
395     		if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
396     			link->conf.Attributes |= CONF_ENABLE_SPKR;
397     			link->conf.Status = CCSR_AUDIO_ENA;
398     		}
399     		
400     		/* Use power settings for Vcc and Vpp if present */
401     		/*  Note that the CIS values need to be rescaled */
402     		if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM))
403     			link->conf.Vcc = cfg->vcc.param[CISTPL_POWER_VNOM]/10000;
404     		else if (dflt.vcc.present & (1<<CISTPL_POWER_VNOM))
405     			link->conf.Vcc = dflt.vcc.param[CISTPL_POWER_VNOM]/10000;
406     		
407     		if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
408     			link->conf.Vpp1 = link->conf.Vpp2 =
409     				cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
410     		else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
411     			link->conf.Vpp1 = link->conf.Vpp2 =
412     				dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
413     		
414     		/* Do we need to allocate an interrupt? */
415     		if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
416     			link->conf.Attributes |= CONF_ENABLE_IRQ;
417     		
418     		/* IO window settings */
419     		link->io.NumPorts1 = link->io.NumPorts2 = 0;
420     		if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
421     			cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
422     			link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
423     			if (!(io->flags & CISTPL_IO_8BIT))
424     				link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
425     			if (!(io->flags & CISTPL_IO_16BIT))
426     				link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
427     			link->io.BasePort1 = io->win[0].base;
428     			link->io.NumPorts1 = io->win[0].len;
429     			if (io->nwin > 1) {
430     				link->io.Attributes2 = link->io.Attributes1;
431     				link->io.BasePort2 = io->win[1].base;
432     				link->io.NumPorts2 = io->win[1].len;
433     			}
434     		}
435     		
436     		/* This reserves IO space but doesn't actually enable it */
437     		CFG_CHECK(RequestIO, link->handle, &link->io); 
438     		
439     		/*
440     		  Now set up a common memory window, if needed.  There is room
441     		  in the dev_link_t structure for one memory window handle,
442     		  but if the base addresses need to be saved, or if multiple
443     		  windows are needed, the info should go in the private data
444     		  structure for this device.
445     		  
446     		  Note that the memory window base is a physical address, and
447     		  needs to be mapped to virtual space with ioremap() before it
448     		  is used.
449     		*/
450     		if ((cfg->mem.nwin > 0) || (dflt.mem.nwin > 0)) {
451     			cistpl_mem_t *mem =
452     				(cfg->mem.nwin) ? &cfg->mem : &dflt.mem;
453     			req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM;
454     			req.Base = mem->win[0].host_addr;
455     			req.Size = mem->win[0].len;
456     			req.AccessSpeed = 0;
457     			link->win = (window_handle_t)link->handle;
458     			CFG_CHECK(RequestWindow, &link->win, &req);
459     			map.Page = 0; map.CardOffset = mem->win[0].card_addr;
460     			CFG_CHECK(MapMemPage, link->win, &map);
461     		}
462     		/* If we got this far, we're cool! */
463     		break;
464     		
465     	next_entry:
466     		CS_CHECK(GetNextTuple, handle, &tuple);
467     	}
468     	
469         /*
470           Allocate an interrupt line.  Note that this does not assign a
471           handler to the interrupt, unless the 'Handler' member of the
472           irq structure is initialized.
473         */
474     	if (link->conf.Attributes & CONF_ENABLE_IRQ)
475     		CS_CHECK(RequestIRQ, link->handle, &link->irq);
476     	
477     	/*
478     	  This actually configures the PCMCIA socket -- setting up
479     	  the I/O windows and the interrupt mapping, and putting the
480     	  card and host interface into "Memory and IO" mode.
481     	*/
482     	CS_CHECK(RequestConfiguration, link->handle, &link->conf);
483     	((local_info_t*)link->priv)->eth_dev = 
484     		init_airo_card( link->irq.AssignedIRQ,
485     				link->io.BasePort1, 1 );
486     	if (!((local_info_t*)link->priv)->eth_dev) goto cs_failed;
487     	
488     	/*
489     	  At this point, the dev_node_t structure(s) need to be
490     	  initialized and arranged in a linked list at link->dev.
491     	*/
492     	strcpy(dev->node.dev_name, ((local_info_t*)link->priv)->eth_dev->name );
493     	dev->node.major = dev->node.minor = 0;
494     	link->dev = &dev->node;
495     	
496     	/* Finally, report what we've done */
497     	printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d",
498     	       dev->node.dev_name, link->conf.ConfigIndex,
499     	       link->conf.Vcc/10, link->conf.Vcc%10);
500     	if (link->conf.Vpp1)
501     		printk(", Vpp %d.%d", link->conf.Vpp1/10, link->conf.Vpp1%10);
502     	if (link->conf.Attributes & CONF_ENABLE_IRQ)
503     		printk(", irq %d", link->irq.AssignedIRQ);
504     	if (link->io.NumPorts1)
505     		printk(", io 0x%04x-0x%04x", link->io.BasePort1,
506     		       link->io.BasePort1+link->io.NumPorts1-1);
507     	if (link->io.NumPorts2)
508     		printk(" & 0x%04x-0x%04x", link->io.BasePort2,
509     		       link->io.BasePort2+link->io.NumPorts2-1);
510     	if (link->win)
511     		printk(", mem 0x%06lx-0x%06lx", req.Base,
512     		       req.Base+req.Size-1);
513     	printk("\n");
514     	
515     	link->state &= ~DEV_CONFIG_PENDING;
516     	return;
517     	
518      cs_failed:
519     	cs_error(link->handle, last_fn, last_ret);
520     	airo_release((u_long)link);
521     	
522     } /* airo_config */
523     
524     /*======================================================================
525       
526       After a card is removed, airo_release() will unregister the
527       device, and release the PCMCIA configuration.  If the device is
528       still open, this will be postponed until it is closed.
529       
530       ======================================================================*/
531     
532     static void airo_release(u_long arg)
533     {
534     	dev_link_t *link = (dev_link_t *)arg;
535     	
536     	DEBUG(0, "airo_release(0x%p)\n", link);
537     	
538     	/*
539     	  If the device is currently in use, we won't release until it
540     	  is actually closed, because until then, we can't be sure that
541     	  no one will try to access the device or its data structures.
542     	*/
543     	if (link->open) {
544     		DEBUG(1, "airo_cs: release postponed, '%s' still open\n",
545     		      link->dev->dev_name);
546     		link->state |= DEV_STALE_CONFIG;
547     		return;
548     	}
549     	
550     	/* Unlink the device chain */
551     	link->dev = NULL;
552     	
553     	/*
554     	  In a normal driver, additional code may be needed to release
555     	  other kernel data structures associated with this device. 
556     	*/
557     	
558     	/* Don't bother checking to see if these succeed or not */
559     	if (link->win)
560     		CardServices(ReleaseWindow, link->win);
561     	CardServices(ReleaseConfiguration, link->handle);
562     	if (link->io.NumPorts1)
563     		CardServices(ReleaseIO, link->handle, &link->io);
564     	if (link->irq.AssignedIRQ)
565     		CardServices(ReleaseIRQ, link->handle, &link->irq);
566     	link->state &= ~DEV_CONFIG;
567     	
568     } /* airo_release */
569     
570     /*======================================================================
571       
572       The card status event handler.  Mostly, this schedules other
573       stuff to run after an event is received.
574     
575       When a CARD_REMOVAL event is received, we immediately set a
576       private flag to block future accesses to this device.  All the
577       functions that actually access the device should check this flag
578       to make sure the card is still present.
579       
580       ======================================================================*/
581     
582     static int airo_event(event_t event, int priority,
583     		      event_callback_args_t *args)
584     {
585     	dev_link_t *link = args->client_data;
586     	local_info_t *local = link->priv;
587     	
588     	DEBUG(1, "airo_event(0x%06x)\n", event);
589     	
590     	switch (event) {
591     	case CS_EVENT_CARD_REMOVAL:
592     		link->state &= ~DEV_PRESENT;
593     		if (link->state & DEV_CONFIG) {
594     			netif_device_detach(local->eth_dev);
595     			mod_timer(&link->release, jiffies + HZ/20);
596     		}
597     		break;
598     	case CS_EVENT_CARD_INSERTION:
599     		link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
600     		airo_config(link);
601     		break;
602     	case CS_EVENT_PM_SUSPEND:
603     		link->state |= DEV_SUSPEND;
604     		/* Fall through... */
605     	case CS_EVENT_RESET_PHYSICAL:
606     		if (link->state & DEV_CONFIG) {
607     			netif_device_detach(local->eth_dev);
608     			CardServices(ReleaseConfiguration, link->handle);
609     		}
610     		break;
611     	case CS_EVENT_PM_RESUME:
612     		link->state &= ~DEV_SUSPEND;
613     		/* Fall through... */
614     	case CS_EVENT_CARD_RESET:
615     		if (link->state & DEV_CONFIG) {
616     			CardServices(RequestConfiguration, link->handle, &link->conf);
617     			reset_airo_card(local->eth_dev);
618     			netif_device_attach(local->eth_dev);
619     		}
620     		break;
621     	}
622     	return 0;
623     } /* airo_event */
624     
625     /*====================================================================*/
626     
627     static int airo_cs_init(void)
628     {
629     	servinfo_t serv;
630     	DEBUG(0, "%s\n", version);
631     	CardServices(GetCardServicesInfo, &serv);
632     	if (serv.Revision != CS_RELEASE_CODE) {
633     		printk(KERN_NOTICE "airo_cs: Card Services release "
634     		       "does not match!\n");
635     		return -1;
636     	}
637     	register_pcmcia_driver(&dev_info, &airo_attach, &airo_detach);
638     	return 0;
639     }
640     
641     static void airo_cs_cleanup(void)
642     {
643     	DEBUG(0, "airo_cs: unloading\n");
644     	unregister_pcmcia_driver(&dev_info);
645     	while (dev_list != NULL) {
646     		if (dev_list->state & DEV_CONFIG)
647     			airo_release((u_long)dev_list);
648     		airo_detach(dev_list);
649     	}
650     }
651     
652     /*
653         This program is free software; you can redistribute it and/or
654         modify it under the terms of the GNU General Public License
655         as published by the Free Software Foundation; either version 2
656         of the License, or (at your option) any later version.
657     
658         This program is distributed in the hope that it will be useful,
659         but WITHOUT ANY WARRANTY; without even the implied warranty of
660         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
661         GNU General Public License for more details.
662     
663         In addition:
664     
665         Redistribution and use in source and binary forms, with or without
666         modification, are permitted provided that the following conditions
667         are met:
668     
669         1. Redistributions of source code must retain the above copyright
670            notice, this list of conditions and the following disclaimer.
671         2. Redistributions in binary form must reproduce the above copyright
672            notice, this list of conditions and the following disclaimer in the
673            documentation and/or other materials provided with the distribution.
674         3. The name of the author may not be used to endorse or promote
675            products derived from this software without specific prior written
676            permission.
677     
678         THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
679         IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
680         WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
681         ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
682         INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
683         (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
684         SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
685         HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
686         STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
687         IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
688         POSSIBILITY OF SUCH DAMAGE.    
689     */
690     
691     module_init(airo_cs_init);
692     module_exit(airo_cs_cleanup);
693