ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / net / wireless / orinoco_cs.c
1 /* orinoco_cs.c 0.13e   - (formerly known as dldwd_cs.c)
2  *
3  * A driver for "Hermes" chipset based PCMCIA wireless adaptors, such
4  * as the Lucent WavelanIEEE/Orinoco cards and their OEM (Cabletron/
5  * EnteraSys RoamAbout 802.11, ELSA Airlancer, Melco Buffalo and others).
6  * It should also be usable on various Prism II based cards such as the
7  * Linksys, D-Link and Farallon Skyline. It should also work on Symbol
8  * cards such as the 3Com AirConnect and Ericsson WLAN.
9  * 
10  * Copyright notice & release notes in file orinoco.c
11  */
12
13 #include <linux/config.h>
14 #ifdef  __IN_PCMCIA_PACKAGE__
15 #include <pcmcia/k_compat.h>
16 #endif /* __IN_PCMCIA_PACKAGE__ */
17
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/sched.h>
22 #include <linux/ptrace.h>
23 #include <linux/slab.h>
24 #include <linux/string.h>
25 #include <linux/ioport.h>
26 #include <linux/netdevice.h>
27 #include <linux/if_arp.h>
28 #include <linux/etherdevice.h>
29 #include <linux/wireless.h>
30
31 #include <pcmcia/version.h>
32 #include <pcmcia/cs_types.h>
33 #include <pcmcia/cs.h>
34 #include <pcmcia/cistpl.h>
35 #include <pcmcia/cisreg.h>
36 #include <pcmcia/ds.h>
37
38 #include <asm/uaccess.h>
39 #include <asm/io.h>
40 #include <asm/system.h>
41
42 #include "orinoco.h"
43
44 /********************************************************************/
45 /* Module stuff                                                     */
46 /********************************************************************/
47
48 MODULE_AUTHOR("David Gibson <hermes@gibson.dropbear.id.au>");
49 MODULE_DESCRIPTION("Driver for PCMCIA Lucent Orinoco, Prism II based and similar wireless cards");
50 #ifdef MODULE_LICENSE
51 MODULE_LICENSE("Dual MPL/GPL");
52 #endif
53
54 /* Module parameters */
55
56 /* The old way: bit map of interrupts to choose from */
57 /* This means pick from 15, 14, 12, 11, 10, 9, 7, 5, 4, and 3 */
58 static uint irq_mask = 0xdeb8;
59 /* Newer, simpler way of listing specific interrupts */
60 static int irq_list[4] = { -1 };
61
62 /* Some D-Link cards have buggy CIS. They do work at 5v properly, but
63  * don't have any CIS entry for it. This workaround it... */
64 static int ignore_cis_vcc; /* = 0 */
65
66 MODULE_PARM(irq_mask, "i");
67 MODULE_PARM(irq_list, "1-4i");
68 MODULE_PARM(ignore_cis_vcc, "i");
69
70 /********************************************************************/
71 /* Magic constants                                                  */
72 /********************************************************************/
73
74 /*
75  * The dev_info variable is the "key" that is used to match up this
76  * device driver with appropriate cards, through the card
77  * configuration database.
78  */
79 static dev_info_t dev_info = "orinoco_cs";
80
81 /********************************************************************/
82 /* Data structures                                                  */
83 /********************************************************************/
84
85 /* PCMCIA specific device information (goes in the card field of
86  * struct orinoco_private */
87 struct orinoco_pccard {
88         dev_link_t link;
89         dev_node_t node;
90
91         /* Used to handle hard reset */
92         /* yuck, we need this hack to work around the insanity of the
93          * PCMCIA layer */
94         unsigned long hard_reset_in_progress; 
95 };
96
97 /*
98  * A linked list of "instances" of the device.  Each actual PCMCIA
99  * card corresponds to one device instance, and is described by one
100  * dev_link_t structure (defined in ds.h).
101  */
102 static dev_link_t *dev_list; /* = NULL */
103
104 /********************************************************************/
105 /* Function prototypes                                              */
106 /********************************************************************/
107
108 /* device methods */
109 static int orinoco_cs_hard_reset(struct orinoco_private *priv);
110
111 /* PCMCIA gumpf */
112 static void orinoco_cs_config(dev_link_t * link);
113 static void orinoco_cs_release(dev_link_t * link);
114 static int orinoco_cs_event(event_t event, int priority,
115                             event_callback_args_t * args);
116
117 static dev_link_t *orinoco_cs_attach(void);
118 static void orinoco_cs_detach(dev_link_t *);
119
120 /********************************************************************/
121 /* Device methods                                                   */
122 /********************************************************************/
123
124 static int
125 orinoco_cs_hard_reset(struct orinoco_private *priv)
126 {
127         struct orinoco_pccard *card = priv->card;
128         dev_link_t *link = &card->link;
129         int err;
130
131         /* We need atomic ops here, because we're not holding the lock */
132         set_bit(0, &card->hard_reset_in_progress);
133
134         err = pcmcia_reset_card(link->handle, NULL);
135         if (err)
136                 return err;
137
138         clear_bit(0, &card->hard_reset_in_progress);
139
140         return 0;
141 }
142
143 /********************************************************************/
144 /* PCMCIA stuff                                                     */
145 /********************************************************************/
146
147 /* In 2.5 (as of 2.5.69 at least) there is a cs_error exported which
148  * does this, but it's not in 2.4 so we do our own for now. */
149 static void
150 orinoco_cs_error(client_handle_t handle, int func, int ret)
151 {
152         error_info_t err = { func, ret };
153         pcmcia_report_error(handle, &err);
154 }
155
156 /*
157  * This creates an "instance" of the driver, allocating local data
158  * structures for one device.  The device is registered with Card
159  * Services.
160  * 
161  * The dev_link structure is initialized, but we don't actually
162  * configure the card at this point -- we wait until we receive a card
163  * insertion event.  */
164 static dev_link_t *
165 orinoco_cs_attach(void)
166 {
167         struct net_device *dev;
168         struct orinoco_private *priv;
169         struct orinoco_pccard *card;
170         dev_link_t *link;
171         client_reg_t client_reg;
172         int ret, i;
173
174         dev = alloc_orinocodev(sizeof(*card), orinoco_cs_hard_reset);
175         if (! dev)
176                 return NULL;
177         priv = dev->priv;
178         card = priv->card;
179
180         /* Link both structures together */
181         link = &card->link;
182         link->priv = dev;
183
184         /* Interrupt setup */
185         link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
186         link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
187         if (irq_list[0] == -1)
188                 link->irq.IRQInfo2 = irq_mask;
189         else
190                 for (i = 0; i < 4; i++)
191                         link->irq.IRQInfo2 |= 1 << irq_list[i];
192         link->irq.Handler = NULL;
193
194         /* General socket configuration defaults can go here.  In this
195          * client, we assume very little, and rely on the CIS for
196          * almost everything.  In most clients, many details (i.e.,
197          * number, sizes, and attributes of IO windows) are fixed by
198          * the nature of the device, and can be hard-wired here. */
199         link->conf.Attributes = 0;
200         link->conf.IntType = INT_MEMORY_AND_IO;
201
202         /* Register with Card Services */
203         /* FIXME: need a lock? */
204         link->next = dev_list;
205         dev_list = link;
206
207         client_reg.dev_info = &dev_info;
208         client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
209         client_reg.EventMask =
210                 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
211                 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
212                 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
213         client_reg.event_handler = &orinoco_cs_event;
214         client_reg.Version = 0x0210; /* FIXME: what does this mean? */
215         client_reg.event_callback_args.client_data = link;
216
217         ret = pcmcia_register_client(&link->handle, &client_reg);
218         if (ret != CS_SUCCESS) {
219                 orinoco_cs_error(link->handle, RegisterClient, ret);
220                 orinoco_cs_detach(link);
221                 return NULL;
222         }
223
224         return link;
225 }                               /* orinoco_cs_attach */
226
227 /*
228  * This deletes a driver "instance".  The device is de-registered with
229  * Card Services.  If it has been released, all local data structures
230  * are freed.  Otherwise, the structures will be freed when the device
231  * is released.
232  */
233 static void
234 orinoco_cs_detach(dev_link_t * link)
235 {
236         dev_link_t **linkp;
237         struct net_device *dev = link->priv;
238
239         /* Locate device structure */
240         for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
241                 if (*linkp == link)
242                         break;
243         if (*linkp == NULL) {
244                 BUG();
245                 return;
246         }
247
248         if (link->state & DEV_CONFIG)
249                 orinoco_cs_release(link);
250
251         /* Break the link with Card Services */
252         if (link->handle)
253                 pcmcia_deregister_client(link->handle);
254
255         /* Unlink device structure, and free it */
256         *linkp = link->next;
257         DEBUG(0, "orinoco_cs: detach: link=%p link->dev=%p\n", link, link->dev);
258         if (link->dev) {
259                 DEBUG(0, "orinoco_cs: About to unregister net device %p\n",
260                       dev);
261                 unregister_netdev(dev);
262         }
263         free_netdev(dev);
264 }                               /* orinoco_cs_detach */
265
266 /*
267  * orinoco_cs_config() is scheduled to run after a CARD_INSERTION
268  * event is received, to configure the PCMCIA socket, and to make the
269  * device available to the system.
270  */
271
272 #define CS_CHECK(fn, ret) \
273 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
274
275 static void
276 orinoco_cs_config(dev_link_t *link)
277 {
278         struct net_device *dev = link->priv;
279         client_handle_t handle = link->handle;
280         struct orinoco_private *priv = dev->priv;
281         struct orinoco_pccard *card = priv->card;
282         hermes_t *hw = &priv->hw;
283         int last_fn, last_ret;
284         u_char buf[64];
285         config_info_t conf;
286         cisinfo_t info;
287         tuple_t tuple;
288         cisparse_t parse;
289
290         CS_CHECK(ValidateCIS, pcmcia_validate_cis(handle, &info));
291
292         /*
293          * This reads the card's CONFIG tuple to find its
294          * configuration registers.
295          */
296         tuple.DesiredTuple = CISTPL_CONFIG;
297         tuple.Attributes = 0;
298         tuple.TupleData = buf;
299         tuple.TupleDataMax = sizeof(buf);
300         tuple.TupleOffset = 0;
301         CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
302         CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
303         CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
304         link->conf.ConfigBase = parse.config.base;
305         link->conf.Present = parse.config.rmask[0];
306
307         /* Configure card */
308         link->state |= DEV_CONFIG;
309
310         /* Look up the current Vcc */
311         CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &conf));
312         link->conf.Vcc = conf.Vcc;
313
314         /*
315          * In this loop, we scan the CIS for configuration table
316          * entries, each of which describes a valid card
317          * configuration, including voltage, IO window, memory window,
318          * and interrupt settings.
319          *
320          * We make no assumptions about the card to be configured: we
321          * use just the information available in the CIS.  In an ideal
322          * world, this would work for any PCMCIA card, but it requires
323          * a complete and accurate CIS.  In practice, a driver usually
324          * "knows" most of these things without consulting the CIS,
325          * and most client drivers will only use the CIS to fill in
326          * implementation-defined details.
327          */
328         tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
329         CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
330         while (1) {
331                 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
332                 cistpl_cftable_entry_t dflt = { .index = 0 };
333
334                 if (pcmcia_get_tuple_data(handle, &tuple) != 0 ||
335                                 pcmcia_parse_tuple(handle, &tuple, &parse) != 0)
336                         goto next_entry;
337
338                 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
339                         dflt = *cfg;
340                 if (cfg->index == 0)
341                         goto next_entry;
342                 link->conf.ConfigIndex = cfg->index;
343
344                 /* Does this card need audio output? */
345                 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
346                         link->conf.Attributes |= CONF_ENABLE_SPKR;
347                         link->conf.Status = CCSR_AUDIO_ENA;
348                 }
349
350                 /* Use power settings for Vcc and Vpp if present */
351                 /* Note that the CIS values need to be rescaled */
352                 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
353                         if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) {
354                                 DEBUG(2, "orinoco_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n",  conf.Vcc, cfg->vcc.param[CISTPL_POWER_VNOM] / 10000);
355                                 if (!ignore_cis_vcc)
356                                         goto next_entry;
357                         }
358                 } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
359                         if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] / 10000) {
360                                 DEBUG(2, "orinoco_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n",  conf.Vcc, dflt.vcc.param[CISTPL_POWER_VNOM] / 10000);
361                                 if(!ignore_cis_vcc)
362                                         goto next_entry;
363                         }
364                 }
365
366                 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
367                         link->conf.Vpp1 = link->conf.Vpp2 =
368                             cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
369                 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
370                         link->conf.Vpp1 = link->conf.Vpp2 =
371                             dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
372                 
373                 /* Do we need to allocate an interrupt? */
374                 if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
375                         link->conf.Attributes |= CONF_ENABLE_IRQ;
376
377                 /* IO window settings */
378                 link->io.NumPorts1 = link->io.NumPorts2 = 0;
379                 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
380                         cistpl_io_t *io =
381                             (cfg->io.nwin) ? &cfg->io : &dflt.io;
382                         link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
383                         if (!(io->flags & CISTPL_IO_8BIT))
384                                 link->io.Attributes1 =
385                                     IO_DATA_PATH_WIDTH_16;
386                         if (!(io->flags & CISTPL_IO_16BIT))
387                                 link->io.Attributes1 =
388                                     IO_DATA_PATH_WIDTH_8;
389                         link->io.IOAddrLines =
390                             io->flags & CISTPL_IO_LINES_MASK;
391                         link->io.BasePort1 = io->win[0].base;
392                         link->io.NumPorts1 = io->win[0].len;
393                         if (io->nwin > 1) {
394                                 link->io.Attributes2 =
395                                     link->io.Attributes1;
396                                 link->io.BasePort2 = io->win[1].base;
397                                 link->io.NumPorts2 = io->win[1].len;
398                         }
399
400                         /* This reserves IO space but doesn't actually enable it */
401                         if (pcmcia_request_io(link->handle, &link->io) != 0)
402                                 goto next_entry;
403                 }
404
405
406                 /* If we got this far, we're cool! */
407
408                 break;
409                 
410         next_entry:
411                 if (link->io.NumPorts1)
412                         pcmcia_release_io(link->handle, &link->io);
413                 last_ret = pcmcia_get_next_tuple(handle, &tuple);
414                 if (last_ret  == CS_NO_MORE_ITEMS) {
415                         printk(KERN_ERR "GetNextTuple().  No matching CIS configuration, "
416                                "maybe you need the ignore_cis_vcc=1 parameter.\n");
417                         goto cs_failed;
418                 }
419         }
420
421         /*
422          * Allocate an interrupt line.  Note that this does not assign
423          * a handler to the interrupt, unless the 'Handler' member of
424          * the irq structure is initialized.
425          */
426         if (link->conf.Attributes & CONF_ENABLE_IRQ) {
427                 int i;
428
429                 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
430                 link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
431                 if (irq_list[0] == -1)
432                         link->irq.IRQInfo2 = irq_mask;
433                 else
434                         for (i=0; i<4; i++)
435                                 link->irq.IRQInfo2 |= 1 << irq_list[i];
436                 
437                 link->irq.Handler = orinoco_interrupt; 
438                 link->irq.Instance = dev; 
439                 
440                 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq));
441         }
442
443         /* We initialize the hermes structure before completing PCMCIA
444          * configuration just in case the interrupt handler gets
445          * called. */
446         hermes_struct_init(hw, link->io.BasePort1,
447                                 HERMES_IO, HERMES_16BIT_REGSPACING);
448
449         /*
450          * This actually configures the PCMCIA socket -- setting up
451          * the I/O windows and the interrupt mapping, and putting the
452          * card and host interface into "Memory and IO" mode.
453          */
454         CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf));
455
456         /* Ok, we have the configuration, prepare to register the netdev */
457         dev->base_addr = link->io.BasePort1;
458         dev->irq = link->irq.AssignedIRQ;
459         SET_MODULE_OWNER(dev);
460         card->node.major = card->node.minor = 0;
461
462         /* register_netdev will give us an ethX name */
463         dev->name[0] = '\0';
464         /* Tell the stack we exist */
465         if (register_netdev(dev) != 0) {
466                 printk(KERN_ERR "orinoco_cs: register_netdev() failed\n");
467                 goto failed;
468         }
469
470         /* At this point, the dev_node_t structure(s) needs to be
471          * initialized and arranged in a linked list at link->dev. */
472         strcpy(card->node.dev_name, dev->name);
473         link->dev = &card->node; /* link->dev being non-NULL is also
474                                     used to indicate that the
475                                     net_device has been registered */
476         link->state &= ~DEV_CONFIG_PENDING;
477
478         /* Finally, report what we've done */
479         printk(KERN_DEBUG "%s: index 0x%02x: Vcc %d.%d",
480                dev->name, link->conf.ConfigIndex,
481                link->conf.Vcc / 10, link->conf.Vcc % 10);
482         if (link->conf.Vpp1)
483                 printk(", Vpp %d.%d", link->conf.Vpp1 / 10,
484                        link->conf.Vpp1 % 10);
485         if (link->conf.Attributes & CONF_ENABLE_IRQ)
486                 printk(", irq %d", link->irq.AssignedIRQ);
487         if (link->io.NumPorts1)
488                 printk(", io 0x%04x-0x%04x", link->io.BasePort1,
489                        link->io.BasePort1 + link->io.NumPorts1 - 1);
490         if (link->io.NumPorts2)
491                 printk(" & 0x%04x-0x%04x", link->io.BasePort2,
492                        link->io.BasePort2 + link->io.NumPorts2 - 1);
493         printk("\n");
494
495         return;
496
497  cs_failed:
498         orinoco_cs_error(link->handle, last_fn, last_ret);
499
500  failed:
501         orinoco_cs_release(link);
502 }                               /* orinoco_cs_config */
503
504 /*
505  * After a card is removed, orinoco_cs_release() will unregister the
506  * device, and release the PCMCIA configuration.  If the device is
507  * still open, this will be postponed until it is closed.
508  */
509 static void
510 orinoco_cs_release(dev_link_t *link)
511 {
512         struct net_device *dev = link->priv;
513         struct orinoco_private *priv = dev->priv;
514         unsigned long flags;
515
516         /* We're committed to taking the device away now, so mark the
517          * hardware as unavailable */
518         spin_lock_irqsave(&priv->lock, flags);
519         priv->hw_unavailable++;
520         spin_unlock_irqrestore(&priv->lock, flags);
521
522         /* Don't bother checking to see if these succeed or not */
523         pcmcia_release_configuration(link->handle);
524         if (link->io.NumPorts1)
525                 pcmcia_release_io(link->handle, &link->io);
526         if (link->irq.AssignedIRQ)
527                 pcmcia_release_irq(link->handle, &link->irq);
528         link->state &= ~DEV_CONFIG;
529 }                               /* orinoco_cs_release */
530
531 /*
532  * The card status event handler.  Mostly, this schedules other stuff
533  * to run after an event is received.
534  */
535 static int
536 orinoco_cs_event(event_t event, int priority,
537                        event_callback_args_t * args)
538 {
539         dev_link_t *link = args->client_data;
540         struct net_device *dev = link->priv;
541         struct orinoco_private *priv = dev->priv;
542         struct orinoco_pccard *card = priv->card;
543         int err = 0;
544         unsigned long flags;
545
546         switch (event) {
547         case CS_EVENT_CARD_REMOVAL:
548                 link->state &= ~DEV_PRESENT;
549                 if (link->state & DEV_CONFIG) {
550                         orinoco_lock(priv, &flags);
551
552                         netif_device_detach(dev);
553                         priv->hw_unavailable++;
554
555                         orinoco_unlock(priv, &flags);
556                 }
557                 break;
558
559         case CS_EVENT_CARD_INSERTION:
560                 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
561                 orinoco_cs_config(link);
562                 break;
563
564         case CS_EVENT_PM_SUSPEND:
565                 link->state |= DEV_SUSPEND;
566                 /* Fall through... */
567         case CS_EVENT_RESET_PHYSICAL:
568                 /* Mark the device as stopped, to block IO until later */
569                 if (link->state & DEV_CONFIG) {
570                         /* This is probably racy, but I can't think of
571                            a better way, short of rewriting the PCMCIA
572                            layer to not suck :-( */
573                         if (! test_bit(0, &card->hard_reset_in_progress)) {
574                                 spin_lock_irqsave(&priv->lock, flags);
575
576                                 err = __orinoco_down(dev);
577                                 if (err)
578                                         printk(KERN_WARNING "%s: %s: Error %d downing interface\n",
579                                                dev->name,
580                                                event == CS_EVENT_PM_SUSPEND ? "SUSPEND" : "RESET_PHYSICAL",
581                                                err);
582                                 
583                                 netif_device_detach(dev);
584                                 priv->hw_unavailable++;
585
586                                 spin_unlock_irqrestore(&priv->lock, flags);
587                         }
588
589                         pcmcia_release_configuration(link->handle);
590                 }
591                 break;
592
593         case CS_EVENT_PM_RESUME:
594                 link->state &= ~DEV_SUSPEND;
595                 /* Fall through... */
596         case CS_EVENT_CARD_RESET:
597                 if (link->state & DEV_CONFIG) {
598                         /* FIXME: should we double check that this is
599                          * the same card as we had before */
600                         pcmcia_request_configuration(link->handle, &link->conf);
601
602                         if (! test_bit(0, &card->hard_reset_in_progress)) {
603                                 err = orinoco_reinit_firmware(dev);
604                                 if (err) {
605                                         printk(KERN_ERR "%s: Error %d re-initializing firmware\n",
606                                                dev->name, err);
607                                         break;
608                                 }
609                                 
610                                 spin_lock_irqsave(&priv->lock, flags);
611                                 
612                                 netif_device_attach(dev);
613                                 priv->hw_unavailable--;
614                                 
615                                 if (priv->open && ! priv->hw_unavailable) {
616                                         err = __orinoco_up(dev);
617                                         if (err)
618                                                 printk(KERN_ERR "%s: Error %d restarting card\n",
619                                                        dev->name, err);
620                                         
621                                 }
622
623                                 spin_unlock_irqrestore(&priv->lock, flags);
624                         }
625                 }
626                 break;
627         }
628
629         return err;
630 }                               /* orinoco_cs_event */
631
632 /********************************************************************/
633 /* Module initialization                                            */
634 /********************************************************************/
635
636 /* Can't be declared "const" or the whole __initdata section will
637  * become const */
638 static char version[] __initdata = "orinoco_cs.c 0.13e (David Gibson <hermes@gibson.dropbear.id.au> and others)";
639
640 static struct pcmcia_driver orinoco_driver = {
641         .owner          = THIS_MODULE,
642         .drv            = {
643                 .name   = "orinoco_cs",
644         },
645         .attach         = orinoco_cs_attach,
646         .detach         = orinoco_cs_detach,
647 };
648
649 static int __init
650 init_orinoco_cs(void)
651 {
652         printk(KERN_DEBUG "%s\n", version);
653
654         return pcmcia_register_driver(&orinoco_driver);
655 }
656
657 static void __exit
658 exit_orinoco_cs(void)
659 {
660         pcmcia_unregister_driver(&orinoco_driver);
661
662         if (dev_list)
663                 DEBUG(0, "orinoco_cs: Removing leftover devices.\n");
664         while (dev_list != NULL) {
665                 if (dev_list->state & DEV_CONFIG)
666                         orinoco_cs_release(dev_list);
667                 orinoco_cs_detach(dev_list);
668         }
669 }
670
671 module_init(init_orinoco_cs);
672 module_exit(exit_orinoco_cs);
673