6dc13212a648f986ec8963f135098488c9d0cdc5
[linux-flexiantxendom0-3.2.10.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(u_long arg);
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 = CardServices(ResetCard, 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         CardServices(ReportError, handle, &err);
154 }
155
156
157 /* Remove zombie instances (card removed, detach pending) */
158 static void
159 flush_stale_links(void)
160 {
161         dev_link_t *link, *next;
162
163         TRACE_ENTER("");
164
165         for (link = dev_list; link; link = next) {
166                 next = link->next;
167                 if (link->state & DEV_STALE_LINK) {
168                         orinoco_cs_detach(link);
169                 }
170         }
171         TRACE_EXIT("");
172 }
173
174 /*
175  * This creates an "instance" of the driver, allocating local data
176  * structures for one device.  The device is registered with Card
177  * Services.
178  * 
179  * The dev_link structure is initialized, but we don't actually
180  * configure the card at this point -- we wait until we receive a card
181  * insertion event.  */
182 static dev_link_t *
183 orinoco_cs_attach(void)
184 {
185         struct net_device *dev;
186         struct orinoco_private *priv;
187         struct orinoco_pccard *card;
188         dev_link_t *link;
189         client_reg_t client_reg;
190         int ret, i;
191
192         /* A bit of cleanup */
193         flush_stale_links();
194
195         dev = alloc_orinocodev(sizeof(*card), orinoco_cs_hard_reset);
196         if (! dev)
197                 return NULL;
198         priv = dev->priv;
199         card = priv->card;
200
201         /* Link both structures together */
202         link = &card->link;
203         link->priv = dev;
204
205         /* Initialize the dev_link_t structure */
206         init_timer(&link->release);
207         link->release.function = &orinoco_cs_release;
208         link->release.data = (u_long) link;
209
210         /* Interrupt setup */
211         link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
212         link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
213         if (irq_list[0] == -1)
214                 link->irq.IRQInfo2 = irq_mask;
215         else
216                 for (i = 0; i < 4; i++)
217                         link->irq.IRQInfo2 |= 1 << irq_list[i];
218         link->irq.Handler = NULL;
219
220         /* General socket configuration defaults can go here.  In this
221          * client, we assume very little, and rely on the CIS for
222          * almost everything.  In most clients, many details (i.e.,
223          * number, sizes, and attributes of IO windows) are fixed by
224          * the nature of the device, and can be hard-wired here. */
225         link->conf.Attributes = 0;
226         link->conf.IntType = INT_MEMORY_AND_IO;
227
228         /* Register with Card Services */
229         /* FIXME: need a lock? */
230         link->next = dev_list;
231         dev_list = link;
232
233         client_reg.dev_info = &dev_info;
234         client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
235         client_reg.EventMask =
236                 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
237                 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
238                 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
239         client_reg.event_handler = &orinoco_cs_event;
240         client_reg.Version = 0x0210; /* FIXME: what does this mean? */
241         client_reg.event_callback_args.client_data = link;
242
243         ret = CardServices(RegisterClient, &link->handle, &client_reg);
244         if (ret != CS_SUCCESS) {
245                 orinoco_cs_error(link->handle, RegisterClient, ret);
246                 orinoco_cs_detach(link);
247                 return NULL;
248         }
249
250         return link;
251 }                               /* orinoco_cs_attach */
252
253 /*
254  * This deletes a driver "instance".  The device is de-registered with
255  * Card Services.  If it has been released, all local data structures
256  * are freed.  Otherwise, the structures will be freed when the device
257  * is released.
258  */
259 static void
260 orinoco_cs_detach(dev_link_t * link)
261 {
262         dev_link_t **linkp;
263         struct net_device *dev = link->priv;
264
265         /* Locate device structure */
266         for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
267                 if (*linkp == link)
268                         break;
269         if (*linkp == NULL) {
270                 BUG();
271                 return;
272         }
273
274         if (link->state & DEV_CONFIG) {
275                 orinoco_cs_release((u_long)link);
276                 if (link->state & DEV_CONFIG) {
277                         link->state |= DEV_STALE_LINK;
278                         return;
279                 }
280         }
281
282         /* Break the link with Card Services */
283         if (link->handle)
284                 CardServices(DeregisterClient, link->handle);
285
286         /* Unlink device structure, and free it */
287         *linkp = link->next;
288         DEBUG(0, "orinoco_cs: detach: link=%p link->dev=%p\n", link, link->dev);
289         if (link->dev) {
290                 DEBUG(0, "orinoco_cs: About to unregister net device %p\n",
291                       dev);
292                 unregister_netdev(dev);
293         }
294         kfree(dev);
295 }                               /* orinoco_cs_detach */
296
297 /*
298  * orinoco_cs_config() is scheduled to run after a CARD_INSERTION
299  * event is received, to configure the PCMCIA socket, and to make the
300  * device available to the system.
301  */
302
303 #define CS_CHECK(fn, args...) \
304         while ((last_ret=CardServices(last_fn=(fn),args))!=0) goto cs_failed
305
306 #define CFG_CHECK(fn, args...) \
307         if (CardServices(fn, args) != 0) goto next_entry
308
309 static void
310 orinoco_cs_config(dev_link_t *link)
311 {
312         struct net_device *dev = link->priv;
313         client_handle_t handle = link->handle;
314         struct orinoco_private *priv = dev->priv;
315         struct orinoco_pccard *card = priv->card;
316         hermes_t *hw = &priv->hw;
317         int last_fn, last_ret;
318         u_char buf[64];
319         config_info_t conf;
320         cisinfo_t info;
321         tuple_t tuple;
322         cisparse_t parse;
323
324         CS_CHECK(ValidateCIS, handle, &info);
325
326         /*
327          * This reads the card's CONFIG tuple to find its
328          * configuration registers.
329          */
330         tuple.DesiredTuple = CISTPL_CONFIG;
331         tuple.Attributes = 0;
332         tuple.TupleData = buf;
333         tuple.TupleDataMax = sizeof(buf);
334         tuple.TupleOffset = 0;
335         CS_CHECK(GetFirstTuple, handle, &tuple);
336         CS_CHECK(GetTupleData, handle, &tuple);
337         CS_CHECK(ParseTuple, handle, &tuple, &parse);
338         link->conf.ConfigBase = parse.config.base;
339         link->conf.Present = parse.config.rmask[0];
340
341         /* Configure card */
342         link->state |= DEV_CONFIG;
343
344         /* Look up the current Vcc */
345         CS_CHECK(GetConfigurationInfo, handle, &conf);
346         link->conf.Vcc = conf.Vcc;
347
348         /*
349          * In this loop, we scan the CIS for configuration table
350          * entries, each of which describes a valid card
351          * configuration, including voltage, IO window, memory window,
352          * and interrupt settings.
353          *
354          * We make no assumptions about the card to be configured: we
355          * use just the information available in the CIS.  In an ideal
356          * world, this would work for any PCMCIA card, but it requires
357          * a complete and accurate CIS.  In practice, a driver usually
358          * "knows" most of these things without consulting the CIS,
359          * and most client drivers will only use the CIS to fill in
360          * implementation-defined details.
361          */
362         tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
363         CS_CHECK(GetFirstTuple, handle, &tuple);
364         while (1) {
365                 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
366                 cistpl_cftable_entry_t dflt = { .index = 0 };
367
368                 CFG_CHECK(GetTupleData, handle, &tuple);
369                 CFG_CHECK(ParseTuple, handle, &tuple, &parse);
370
371                 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
372                         dflt = *cfg;
373                 if (cfg->index == 0)
374                         goto next_entry;
375                 link->conf.ConfigIndex = cfg->index;
376
377                 /* Does this card need audio output? */
378                 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
379                         link->conf.Attributes |= CONF_ENABLE_SPKR;
380                         link->conf.Status = CCSR_AUDIO_ENA;
381                 }
382
383                 /* Use power settings for Vcc and Vpp if present */
384                 /* Note that the CIS values need to be rescaled */
385                 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
386                         if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) {
387                                 DEBUG(2, "orinoco_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n",  conf.Vcc, cfg->vcc.param[CISTPL_POWER_VNOM] / 10000);
388                                 if (!ignore_cis_vcc)
389                                         goto next_entry;
390                         }
391                 } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
392                         if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] / 10000) {
393                                 DEBUG(2, "orinoco_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n",  conf.Vcc, dflt.vcc.param[CISTPL_POWER_VNOM] / 10000);
394                                 if(!ignore_cis_vcc)
395                                         goto next_entry;
396                         }
397                 }
398
399                 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
400                         link->conf.Vpp1 = link->conf.Vpp2 =
401                             cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
402                 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
403                         link->conf.Vpp1 = link->conf.Vpp2 =
404                             dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
405                 
406                 /* Do we need to allocate an interrupt? */
407                 if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
408                         link->conf.Attributes |= CONF_ENABLE_IRQ;
409
410                 /* IO window settings */
411                 link->io.NumPorts1 = link->io.NumPorts2 = 0;
412                 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
413                         cistpl_io_t *io =
414                             (cfg->io.nwin) ? &cfg->io : &dflt.io;
415                         link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
416                         if (!(io->flags & CISTPL_IO_8BIT))
417                                 link->io.Attributes1 =
418                                     IO_DATA_PATH_WIDTH_16;
419                         if (!(io->flags & CISTPL_IO_16BIT))
420                                 link->io.Attributes1 =
421                                     IO_DATA_PATH_WIDTH_8;
422                         link->io.IOAddrLines =
423                             io->flags & CISTPL_IO_LINES_MASK;
424                         link->io.BasePort1 = io->win[0].base;
425                         link->io.NumPorts1 = io->win[0].len;
426                         if (io->nwin > 1) {
427                                 link->io.Attributes2 =
428                                     link->io.Attributes1;
429                                 link->io.BasePort2 = io->win[1].base;
430                                 link->io.NumPorts2 = io->win[1].len;
431                         }
432
433                         /* This reserves IO space but doesn't actually enable it */
434                         CFG_CHECK(RequestIO, link->handle, &link->io);
435                 }
436
437
438                 /* If we got this far, we're cool! */
439
440                 break;
441                 
442         next_entry:
443                 if (link->io.NumPorts1)
444                         CardServices(ReleaseIO, link->handle, &link->io);
445                 last_ret = CardServices(GetNextTuple, handle, &tuple);
446                 if (last_ret  == CS_NO_MORE_ITEMS) {
447                         printk(KERN_ERR "GetNextTuple().  No matching CIS configuration, "
448                                "maybe you need the ignore_cis_vcc=1 parameter.\n");
449                         goto cs_failed;
450                 }
451         }
452
453         /*
454          * Allocate an interrupt line.  Note that this does not assign
455          * a handler to the interrupt, unless the 'Handler' member of
456          * the irq structure is initialized.
457          */
458         if (link->conf.Attributes & CONF_ENABLE_IRQ) {
459                 int i;
460
461                 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
462                 link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
463                 if (irq_list[0] == -1)
464                         link->irq.IRQInfo2 = irq_mask;
465                 else
466                         for (i=0; i<4; i++)
467                                 link->irq.IRQInfo2 |= 1 << irq_list[i];
468                 
469                 link->irq.Handler = orinoco_interrupt; 
470                 link->irq.Instance = dev; 
471                 
472                 CS_CHECK(RequestIRQ, link->handle, &link->irq);
473         }
474
475         /* We initialize the hermes structure before completing PCMCIA
476          * configuration just in case the interrupt handler gets
477          * called. */
478         hermes_struct_init(hw, link->io.BasePort1,
479                                 HERMES_IO, HERMES_16BIT_REGSPACING);
480
481         /*
482          * This actually configures the PCMCIA socket -- setting up
483          * the I/O windows and the interrupt mapping, and putting the
484          * card and host interface into "Memory and IO" mode.
485          */
486         CS_CHECK(RequestConfiguration, link->handle, &link->conf);
487
488         /* Ok, we have the configuration, prepare to register the netdev */
489         dev->base_addr = link->io.BasePort1;
490         dev->irq = link->irq.AssignedIRQ;
491         SET_MODULE_OWNER(dev);
492         card->node.major = card->node.minor = 0;
493
494         /* register_netdev will give us an ethX name */
495         dev->name[0] = '\0';
496         /* Tell the stack we exist */
497         if (register_netdev(dev) != 0) {
498                 printk(KERN_ERR "orinoco_cs: register_netdev() failed\n");
499                 goto failed;
500         }
501
502         /* At this point, the dev_node_t structure(s) needs to be
503          * initialized and arranged in a linked list at link->dev. */
504         strcpy(card->node.dev_name, dev->name);
505         link->dev = &card->node; /* link->dev being non-NULL is also
506                                     used to indicate that the
507                                     net_device has been registered */
508         link->state &= ~DEV_CONFIG_PENDING;
509
510         /* Finally, report what we've done */
511         printk(KERN_DEBUG "%s: index 0x%02x: Vcc %d.%d",
512                dev->name, link->conf.ConfigIndex,
513                link->conf.Vcc / 10, link->conf.Vcc % 10);
514         if (link->conf.Vpp1)
515                 printk(", Vpp %d.%d", link->conf.Vpp1 / 10,
516                        link->conf.Vpp1 % 10);
517         if (link->conf.Attributes & CONF_ENABLE_IRQ)
518                 printk(", irq %d", link->irq.AssignedIRQ);
519         if (link->io.NumPorts1)
520                 printk(", io 0x%04x-0x%04x", link->io.BasePort1,
521                        link->io.BasePort1 + link->io.NumPorts1 - 1);
522         if (link->io.NumPorts2)
523                 printk(" & 0x%04x-0x%04x", link->io.BasePort2,
524                        link->io.BasePort2 + link->io.NumPorts2 - 1);
525         printk("\n");
526
527         return;
528
529  cs_failed:
530         orinoco_cs_error(link->handle, last_fn, last_ret);
531
532  failed:
533         orinoco_cs_release((u_long) link);
534 }                               /* orinoco_cs_config */
535
536 /*
537  * After a card is removed, orinoco_cs_release() will unregister the
538  * device, and release the PCMCIA configuration.  If the device is
539  * still open, this will be postponed until it is closed.
540  */
541 static void
542 orinoco_cs_release(u_long arg)
543 {
544         dev_link_t *link = (dev_link_t *) arg;
545         struct net_device *dev = link->priv;
546         struct orinoco_private *priv = dev->priv;
547         unsigned long flags;
548
549         /* We're committed to taking the device away now, so mark the
550          * hardware as unavailable */
551         spin_lock_irqsave(&priv->lock, flags);
552         priv->hw_unavailable++;
553         spin_unlock_irqrestore(&priv->lock, flags);
554
555         /* Don't bother checking to see if these succeed or not */
556         CardServices(ReleaseConfiguration, link->handle);
557         if (link->io.NumPorts1)
558                 CardServices(ReleaseIO, link->handle, &link->io);
559         if (link->irq.AssignedIRQ)
560                 CardServices(ReleaseIRQ, link->handle, &link->irq);
561         link->state &= ~DEV_CONFIG;
562 }                               /* orinoco_cs_release */
563
564 /*
565  * The card status event handler.  Mostly, this schedules other stuff
566  * to run after an event is received.
567  */
568 static int
569 orinoco_cs_event(event_t event, int priority,
570                        event_callback_args_t * args)
571 {
572         dev_link_t *link = args->client_data;
573         struct net_device *dev = link->priv;
574         struct orinoco_private *priv = dev->priv;
575         struct orinoco_pccard *card = priv->card;
576         int err = 0;
577         unsigned long flags;
578
579         switch (event) {
580         case CS_EVENT_CARD_REMOVAL:
581                 link->state &= ~DEV_PRESENT;
582                 if (link->state & DEV_CONFIG) {
583                         orinoco_lock(priv, &flags);
584
585                         netif_device_detach(dev);
586                         priv->hw_unavailable++;
587
588                         orinoco_unlock(priv, &flags);
589                 }
590                 break;
591
592         case CS_EVENT_CARD_INSERTION:
593                 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
594                 orinoco_cs_config(link);
595                 break;
596
597         case CS_EVENT_PM_SUSPEND:
598                 link->state |= DEV_SUSPEND;
599                 /* Fall through... */
600         case CS_EVENT_RESET_PHYSICAL:
601                 /* Mark the device as stopped, to block IO until later */
602                 if (link->state & DEV_CONFIG) {
603                         /* This is probably racy, but I can't think of
604                            a better way, short of rewriting the PCMCIA
605                            layer to not suck :-( */
606                         if (! test_bit(0, &card->hard_reset_in_progress)) {
607                                 spin_lock_irqsave(&priv->lock, flags);
608
609                                 err = __orinoco_down(dev);
610                                 if (err)
611                                         printk(KERN_WARNING "%s: %s: Error %d downing interface\n",
612                                                dev->name,
613                                                event == CS_EVENT_PM_SUSPEND ? "SUSPEND" : "RESET_PHYSICAL",
614                                                err);
615                                 
616                                 netif_device_detach(dev);
617                                 priv->hw_unavailable++;
618
619                                 spin_unlock_irqrestore(&priv->lock, flags);
620                         }
621
622                         CardServices(ReleaseConfiguration, link->handle);
623                 }
624                 break;
625
626         case CS_EVENT_PM_RESUME:
627                 link->state &= ~DEV_SUSPEND;
628                 /* Fall through... */
629         case CS_EVENT_CARD_RESET:
630                 if (link->state & DEV_CONFIG) {
631                         /* FIXME: should we double check that this is
632                          * the same card as we had before */
633                         CardServices(RequestConfiguration, link->handle,
634                                      &link->conf);
635
636                         if (! test_bit(0, &card->hard_reset_in_progress)) {
637                                 err = orinoco_reinit_firmware(dev);
638                                 if (err) {
639                                         printk(KERN_ERR "%s: Error %d re-initializing firmware\n",
640                                                dev->name, err);
641                                         break;
642                                 }
643                                 
644                                 spin_lock_irqsave(&priv->lock, flags);
645                                 
646                                 netif_device_attach(dev);
647                                 priv->hw_unavailable--;
648                                 
649                                 if (priv->open && ! priv->hw_unavailable) {
650                                         err = __orinoco_up(dev);
651                                         if (err)
652                                                 printk(KERN_ERR "%s: Error %d restarting card\n",
653                                                        dev->name, err);
654                                         
655                                 }
656
657                                 spin_unlock_irqrestore(&priv->lock, flags);
658                         }
659                 }
660                 break;
661         }
662
663         return err;
664 }                               /* orinoco_cs_event */
665
666 /********************************************************************/
667 /* Module initialization                                            */
668 /********************************************************************/
669
670 /* Can't be declared "const" or the whole __initdata section will
671  * become const */
672 static char version[] __initdata = "orinoco_cs.c 0.13e (David Gibson <hermes@gibson.dropbear.id.au> and others)";
673
674 static struct pcmcia_driver orinoco_driver = {
675         .owner          = THIS_MODULE,
676         .drv            = {
677                 .name   = "orinoco_cs",
678         },
679         .attach         = orinoco_cs_attach,
680         .detach         = orinoco_cs_detach,
681 };
682
683 static int __init
684 init_orinoco_cs(void)
685 {
686         printk(KERN_DEBUG "%s\n", version);
687
688         return pcmcia_register_driver(&orinoco_driver);
689 }
690
691 static void __exit
692 exit_orinoco_cs(void)
693 {
694         pcmcia_unregister_driver(&orinoco_driver);
695
696         if (dev_list)
697                 DEBUG(0, "orinoco_cs: Removing leftover devices.\n");
698         while (dev_list != NULL) {
699                 if (dev_list->state & DEV_CONFIG)
700                         orinoco_cs_release((u_long) dev_list);
701                 orinoco_cs_detach(dev_list);
702         }
703 }
704
705 module_init(init_orinoco_cs);
706 module_exit(exit_orinoco_cs);
707