Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* orinoco_cs.c (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 | #define DRIVER_NAME "orinoco_cs" |
| 14 | #define PFX DRIVER_NAME ": " |
| 15 | |
| 16 | #include <linux/config.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <pcmcia/cs_types.h> |
| 32 | #include <pcmcia/cs.h> |
| 33 | #include <pcmcia/cistpl.h> |
| 34 | #include <pcmcia/cisreg.h> |
| 35 | #include <pcmcia/ds.h> |
| 36 | |
| 37 | #include <asm/uaccess.h> |
| 38 | #include <asm/io.h> |
| 39 | #include <asm/system.h> |
| 40 | |
| 41 | #include "orinoco.h" |
| 42 | |
| 43 | /********************************************************************/ |
| 44 | /* Module stuff */ |
| 45 | /********************************************************************/ |
| 46 | |
| 47 | MODULE_AUTHOR("David Gibson <hermes@gibson.dropbear.id.au>"); |
| 48 | MODULE_DESCRIPTION("Driver for PCMCIA Lucent Orinoco, Prism II based and similar wireless cards"); |
| 49 | MODULE_LICENSE("Dual MPL/GPL"); |
| 50 | |
| 51 | /* Module parameters */ |
| 52 | |
| 53 | /* Some D-Link cards have buggy CIS. They do work at 5v properly, but |
| 54 | * don't have any CIS entry for it. This workaround it... */ |
| 55 | static int ignore_cis_vcc; /* = 0 */ |
| 56 | module_param(ignore_cis_vcc, int, 0); |
| 57 | MODULE_PARM_DESC(ignore_cis_vcc, "Allow voltage mismatch between card and socket"); |
| 58 | |
| 59 | /********************************************************************/ |
| 60 | /* Magic constants */ |
| 61 | /********************************************************************/ |
| 62 | |
| 63 | /* |
| 64 | * The dev_info variable is the "key" that is used to match up this |
| 65 | * device driver with appropriate cards, through the card |
| 66 | * configuration database. |
| 67 | */ |
| 68 | static dev_info_t dev_info = DRIVER_NAME; |
| 69 | |
| 70 | /********************************************************************/ |
| 71 | /* Data structures */ |
| 72 | /********************************************************************/ |
| 73 | |
| 74 | /* PCMCIA specific device information (goes in the card field of |
| 75 | * struct orinoco_private */ |
| 76 | struct orinoco_pccard { |
| 77 | dev_link_t link; |
| 78 | dev_node_t node; |
| 79 | |
| 80 | /* Used to handle hard reset */ |
| 81 | /* yuck, we need this hack to work around the insanity of the |
| 82 | * PCMCIA layer */ |
| 83 | unsigned long hard_reset_in_progress; |
| 84 | }; |
| 85 | |
| 86 | /* |
| 87 | * A linked list of "instances" of the device. Each actual PCMCIA |
| 88 | * card corresponds to one device instance, and is described by one |
| 89 | * dev_link_t structure (defined in ds.h). |
| 90 | */ |
| 91 | static dev_link_t *dev_list; /* = NULL */ |
| 92 | |
| 93 | /********************************************************************/ |
| 94 | /* Function prototypes */ |
| 95 | /********************************************************************/ |
| 96 | |
| 97 | /* device methods */ |
| 98 | static int orinoco_cs_hard_reset(struct orinoco_private *priv); |
| 99 | |
| 100 | /* PCMCIA gumpf */ |
| 101 | static void orinoco_cs_config(dev_link_t * link); |
| 102 | static void orinoco_cs_release(dev_link_t * link); |
| 103 | static int orinoco_cs_event(event_t event, int priority, |
| 104 | event_callback_args_t * args); |
| 105 | |
| 106 | static dev_link_t *orinoco_cs_attach(void); |
| 107 | static void orinoco_cs_detach(dev_link_t *); |
| 108 | |
| 109 | /********************************************************************/ |
| 110 | /* Device methods */ |
| 111 | /********************************************************************/ |
| 112 | |
| 113 | static int |
| 114 | orinoco_cs_hard_reset(struct orinoco_private *priv) |
| 115 | { |
| 116 | struct orinoco_pccard *card = priv->card; |
| 117 | dev_link_t *link = &card->link; |
| 118 | int err; |
| 119 | |
| 120 | /* We need atomic ops here, because we're not holding the lock */ |
| 121 | set_bit(0, &card->hard_reset_in_progress); |
| 122 | |
| 123 | err = pcmcia_reset_card(link->handle, NULL); |
| 124 | if (err) |
| 125 | return err; |
| 126 | |
| 127 | msleep(100); |
| 128 | clear_bit(0, &card->hard_reset_in_progress); |
| 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | /********************************************************************/ |
| 134 | /* PCMCIA stuff */ |
| 135 | /********************************************************************/ |
| 136 | |
| 137 | /* |
| 138 | * This creates an "instance" of the driver, allocating local data |
| 139 | * structures for one device. The device is registered with Card |
| 140 | * Services. |
| 141 | * |
| 142 | * The dev_link structure is initialized, but we don't actually |
| 143 | * configure the card at this point -- we wait until we receive a card |
| 144 | * insertion event. */ |
| 145 | static dev_link_t * |
| 146 | orinoco_cs_attach(void) |
| 147 | { |
| 148 | struct net_device *dev; |
| 149 | struct orinoco_private *priv; |
| 150 | struct orinoco_pccard *card; |
| 151 | dev_link_t *link; |
| 152 | client_reg_t client_reg; |
| 153 | int ret; |
| 154 | |
| 155 | dev = alloc_orinocodev(sizeof(*card), orinoco_cs_hard_reset); |
| 156 | if (! dev) |
| 157 | return NULL; |
| 158 | priv = netdev_priv(dev); |
| 159 | card = priv->card; |
| 160 | |
| 161 | /* Link both structures together */ |
| 162 | link = &card->link; |
| 163 | link->priv = dev; |
| 164 | |
| 165 | /* Interrupt setup */ |
| 166 | link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; |
| 167 | link->irq.IRQInfo1 = IRQ_LEVEL_ID; |
| 168 | link->irq.Handler = orinoco_interrupt; |
| 169 | link->irq.Instance = dev; |
| 170 | |
| 171 | /* General socket configuration defaults can go here. In this |
| 172 | * client, we assume very little, and rely on the CIS for |
| 173 | * almost everything. In most clients, many details (i.e., |
| 174 | * number, sizes, and attributes of IO windows) are fixed by |
| 175 | * the nature of the device, and can be hard-wired here. */ |
| 176 | link->conf.Attributes = 0; |
| 177 | link->conf.IntType = INT_MEMORY_AND_IO; |
| 178 | |
| 179 | /* Register with Card Services */ |
| 180 | /* FIXME: need a lock? */ |
| 181 | link->next = dev_list; |
| 182 | dev_list = link; |
| 183 | |
| 184 | client_reg.dev_info = &dev_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | client_reg.Version = 0x0210; /* FIXME: what does this mean? */ |
| 186 | client_reg.event_callback_args.client_data = link; |
| 187 | |
| 188 | ret = pcmcia_register_client(&link->handle, &client_reg); |
| 189 | if (ret != CS_SUCCESS) { |
| 190 | cs_error(link->handle, RegisterClient, ret); |
| 191 | orinoco_cs_detach(link); |
| 192 | return NULL; |
| 193 | } |
| 194 | |
| 195 | return link; |
| 196 | } /* orinoco_cs_attach */ |
| 197 | |
| 198 | /* |
| 199 | * This deletes a driver "instance". The device is de-registered with |
| 200 | * Card Services. If it has been released, all local data structures |
| 201 | * are freed. Otherwise, the structures will be freed when the device |
| 202 | * is released. |
| 203 | */ |
| 204 | static void orinoco_cs_detach(dev_link_t *link) |
| 205 | { |
| 206 | dev_link_t **linkp; |
| 207 | struct net_device *dev = link->priv; |
| 208 | |
| 209 | /* Locate device structure */ |
| 210 | for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) |
| 211 | if (*linkp == link) |
| 212 | break; |
| 213 | |
| 214 | BUG_ON(*linkp == NULL); |
| 215 | |
| 216 | if (link->state & DEV_CONFIG) |
| 217 | orinoco_cs_release(link); |
| 218 | |
| 219 | /* Break the link with Card Services */ |
| 220 | if (link->handle) |
| 221 | pcmcia_deregister_client(link->handle); |
| 222 | |
| 223 | /* Unlink device structure, and free it */ |
| 224 | *linkp = link->next; |
| 225 | DEBUG(0, PFX "detach: link=%p link->dev=%p\n", link, link->dev); |
| 226 | if (link->dev) { |
| 227 | DEBUG(0, PFX "About to unregister net device %p\n", |
| 228 | dev); |
| 229 | unregister_netdev(dev); |
| 230 | } |
| 231 | free_orinocodev(dev); |
| 232 | } /* orinoco_cs_detach */ |
| 233 | |
| 234 | /* |
| 235 | * orinoco_cs_config() is scheduled to run after a CARD_INSERTION |
| 236 | * event is received, to configure the PCMCIA socket, and to make the |
| 237 | * device available to the system. |
| 238 | */ |
| 239 | |
| 240 | #define CS_CHECK(fn, ret) do { \ |
| 241 | last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; \ |
| 242 | } while (0) |
| 243 | |
| 244 | static void |
| 245 | orinoco_cs_config(dev_link_t *link) |
| 246 | { |
| 247 | struct net_device *dev = link->priv; |
| 248 | client_handle_t handle = link->handle; |
| 249 | struct orinoco_private *priv = netdev_priv(dev); |
| 250 | struct orinoco_pccard *card = priv->card; |
| 251 | hermes_t *hw = &priv->hw; |
| 252 | int last_fn, last_ret; |
| 253 | u_char buf[64]; |
| 254 | config_info_t conf; |
| 255 | cisinfo_t info; |
| 256 | tuple_t tuple; |
| 257 | cisparse_t parse; |
| 258 | void __iomem *mem; |
| 259 | |
| 260 | CS_CHECK(ValidateCIS, pcmcia_validate_cis(handle, &info)); |
| 261 | |
| 262 | /* |
| 263 | * This reads the card's CONFIG tuple to find its |
| 264 | * configuration registers. |
| 265 | */ |
| 266 | tuple.DesiredTuple = CISTPL_CONFIG; |
| 267 | tuple.Attributes = 0; |
| 268 | tuple.TupleData = buf; |
| 269 | tuple.TupleDataMax = sizeof(buf); |
| 270 | tuple.TupleOffset = 0; |
| 271 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); |
| 272 | CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); |
| 273 | CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); |
| 274 | link->conf.ConfigBase = parse.config.base; |
| 275 | link->conf.Present = parse.config.rmask[0]; |
| 276 | |
| 277 | /* Configure card */ |
| 278 | link->state |= DEV_CONFIG; |
| 279 | |
| 280 | /* Look up the current Vcc */ |
| 281 | CS_CHECK(GetConfigurationInfo, |
| 282 | pcmcia_get_configuration_info(handle, &conf)); |
| 283 | link->conf.Vcc = conf.Vcc; |
| 284 | |
| 285 | /* |
| 286 | * In this loop, we scan the CIS for configuration table |
| 287 | * entries, each of which describes a valid card |
| 288 | * configuration, including voltage, IO window, memory window, |
| 289 | * and interrupt settings. |
| 290 | * |
| 291 | * We make no assumptions about the card to be configured: we |
| 292 | * use just the information available in the CIS. In an ideal |
| 293 | * world, this would work for any PCMCIA card, but it requires |
| 294 | * a complete and accurate CIS. In practice, a driver usually |
| 295 | * "knows" most of these things without consulting the CIS, |
| 296 | * and most client drivers will only use the CIS to fill in |
| 297 | * implementation-defined details. |
| 298 | */ |
| 299 | tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; |
| 300 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); |
| 301 | while (1) { |
| 302 | cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); |
| 303 | cistpl_cftable_entry_t dflt = { .index = 0 }; |
| 304 | |
| 305 | if ( (pcmcia_get_tuple_data(handle, &tuple) != 0) |
| 306 | || (pcmcia_parse_tuple(handle, &tuple, &parse) != 0)) |
| 307 | goto next_entry; |
| 308 | |
| 309 | if (cfg->flags & CISTPL_CFTABLE_DEFAULT) |
| 310 | dflt = *cfg; |
| 311 | if (cfg->index == 0) |
| 312 | goto next_entry; |
| 313 | link->conf.ConfigIndex = cfg->index; |
| 314 | |
| 315 | /* Does this card need audio output? */ |
| 316 | if (cfg->flags & CISTPL_CFTABLE_AUDIO) { |
| 317 | link->conf.Attributes |= CONF_ENABLE_SPKR; |
| 318 | link->conf.Status = CCSR_AUDIO_ENA; |
| 319 | } |
| 320 | |
| 321 | /* Use power settings for Vcc and Vpp if present */ |
| 322 | /* Note that the CIS values need to be rescaled */ |
| 323 | if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) { |
| 324 | if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) { |
| 325 | DEBUG(2, "orinoco_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n", conf.Vcc, cfg->vcc.param[CISTPL_POWER_VNOM] / 10000); |
| 326 | if (!ignore_cis_vcc) |
| 327 | goto next_entry; |
| 328 | } |
| 329 | } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) { |
| 330 | if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] / 10000) { |
| 331 | DEBUG(2, "orinoco_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n", conf.Vcc, dflt.vcc.param[CISTPL_POWER_VNOM] / 10000); |
| 332 | if(!ignore_cis_vcc) |
| 333 | goto next_entry; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) |
| 338 | link->conf.Vpp1 = link->conf.Vpp2 = |
| 339 | cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; |
| 340 | else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) |
| 341 | link->conf.Vpp1 = link->conf.Vpp2 = |
| 342 | dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000; |
| 343 | |
| 344 | /* Do we need to allocate an interrupt? */ |
| 345 | link->conf.Attributes |= CONF_ENABLE_IRQ; |
| 346 | |
| 347 | /* IO window settings */ |
| 348 | link->io.NumPorts1 = link->io.NumPorts2 = 0; |
| 349 | if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { |
| 350 | cistpl_io_t *io = |
| 351 | (cfg->io.nwin) ? &cfg->io : &dflt.io; |
| 352 | link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; |
| 353 | if (!(io->flags & CISTPL_IO_8BIT)) |
| 354 | link->io.Attributes1 = |
| 355 | IO_DATA_PATH_WIDTH_16; |
| 356 | if (!(io->flags & CISTPL_IO_16BIT)) |
| 357 | link->io.Attributes1 = |
| 358 | IO_DATA_PATH_WIDTH_8; |
| 359 | link->io.IOAddrLines = |
| 360 | io->flags & CISTPL_IO_LINES_MASK; |
| 361 | link->io.BasePort1 = io->win[0].base; |
| 362 | link->io.NumPorts1 = io->win[0].len; |
| 363 | if (io->nwin > 1) { |
| 364 | link->io.Attributes2 = |
| 365 | link->io.Attributes1; |
| 366 | link->io.BasePort2 = io->win[1].base; |
| 367 | link->io.NumPorts2 = io->win[1].len; |
| 368 | } |
| 369 | |
| 370 | /* This reserves IO space but doesn't actually enable it */ |
| 371 | if (pcmcia_request_io(link->handle, &link->io) != 0) |
| 372 | goto next_entry; |
| 373 | } |
| 374 | |
| 375 | |
| 376 | /* If we got this far, we're cool! */ |
| 377 | |
| 378 | break; |
| 379 | |
| 380 | next_entry: |
| 381 | if (link->io.NumPorts1) |
| 382 | pcmcia_release_io(link->handle, &link->io); |
| 383 | last_ret = pcmcia_get_next_tuple(handle, &tuple); |
| 384 | if (last_ret == CS_NO_MORE_ITEMS) { |
| 385 | printk(KERN_ERR PFX "GetNextTuple(): No matching " |
| 386 | "CIS configuration. Maybe you need the " |
| 387 | "ignore_cis_vcc=1 parameter.\n"); |
| 388 | goto cs_failed; |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | /* |
| 393 | * Allocate an interrupt line. Note that this does not assign |
| 394 | * a handler to the interrupt, unless the 'Handler' member of |
| 395 | * the irq structure is initialized. |
| 396 | */ |
| 397 | CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); |
| 398 | |
| 399 | /* We initialize the hermes structure before completing PCMCIA |
| 400 | * configuration just in case the interrupt handler gets |
| 401 | * called. */ |
| 402 | mem = ioport_map(link->io.BasePort1, link->io.NumPorts1); |
| 403 | if (!mem) |
| 404 | goto cs_failed; |
| 405 | |
| 406 | hermes_struct_init(hw, mem, HERMES_16BIT_REGSPACING); |
| 407 | |
| 408 | /* |
| 409 | * This actually configures the PCMCIA socket -- setting up |
| 410 | * the I/O windows and the interrupt mapping, and putting the |
| 411 | * card and host interface into "Memory and IO" mode. |
| 412 | */ |
| 413 | CS_CHECK(RequestConfiguration, |
| 414 | pcmcia_request_configuration(link->handle, &link->conf)); |
| 415 | |
| 416 | /* Ok, we have the configuration, prepare to register the netdev */ |
| 417 | dev->base_addr = link->io.BasePort1; |
| 418 | dev->irq = link->irq.AssignedIRQ; |
| 419 | SET_MODULE_OWNER(dev); |
| 420 | card->node.major = card->node.minor = 0; |
| 421 | |
| 422 | SET_NETDEV_DEV(dev, &handle_to_dev(handle)); |
| 423 | /* Tell the stack we exist */ |
| 424 | if (register_netdev(dev) != 0) { |
| 425 | printk(KERN_ERR PFX "register_netdev() failed\n"); |
| 426 | goto failed; |
| 427 | } |
| 428 | |
| 429 | /* At this point, the dev_node_t structure(s) needs to be |
| 430 | * initialized and arranged in a linked list at link->dev. */ |
| 431 | strcpy(card->node.dev_name, dev->name); |
| 432 | link->dev = &card->node; /* link->dev being non-NULL is also |
| 433 | used to indicate that the |
| 434 | net_device has been registered */ |
| 435 | link->state &= ~DEV_CONFIG_PENDING; |
| 436 | |
| 437 | /* Finally, report what we've done */ |
| 438 | printk(KERN_DEBUG "%s: index 0x%02x: Vcc %d.%d", |
| 439 | dev->name, link->conf.ConfigIndex, |
| 440 | link->conf.Vcc / 10, link->conf.Vcc % 10); |
| 441 | if (link->conf.Vpp1) |
| 442 | printk(", Vpp %d.%d", link->conf.Vpp1 / 10, |
| 443 | link->conf.Vpp1 % 10); |
| 444 | printk(", irq %d", link->irq.AssignedIRQ); |
| 445 | if (link->io.NumPorts1) |
| 446 | printk(", io 0x%04x-0x%04x", link->io.BasePort1, |
| 447 | link->io.BasePort1 + link->io.NumPorts1 - 1); |
| 448 | if (link->io.NumPorts2) |
| 449 | printk(" & 0x%04x-0x%04x", link->io.BasePort2, |
| 450 | link->io.BasePort2 + link->io.NumPorts2 - 1); |
| 451 | printk("\n"); |
| 452 | |
| 453 | return; |
| 454 | |
| 455 | cs_failed: |
| 456 | cs_error(link->handle, last_fn, last_ret); |
| 457 | |
| 458 | failed: |
| 459 | orinoco_cs_release(link); |
| 460 | } /* orinoco_cs_config */ |
| 461 | |
| 462 | /* |
| 463 | * After a card is removed, orinoco_cs_release() will unregister the |
| 464 | * device, and release the PCMCIA configuration. If the device is |
| 465 | * still open, this will be postponed until it is closed. |
| 466 | */ |
| 467 | static void |
| 468 | orinoco_cs_release(dev_link_t *link) |
| 469 | { |
| 470 | struct net_device *dev = link->priv; |
| 471 | struct orinoco_private *priv = netdev_priv(dev); |
| 472 | unsigned long flags; |
| 473 | |
| 474 | /* We're committed to taking the device away now, so mark the |
| 475 | * hardware as unavailable */ |
| 476 | spin_lock_irqsave(&priv->lock, flags); |
| 477 | priv->hw_unavailable++; |
| 478 | spin_unlock_irqrestore(&priv->lock, flags); |
| 479 | |
| 480 | /* Don't bother checking to see if these succeed or not */ |
| 481 | pcmcia_release_configuration(link->handle); |
| 482 | if (link->io.NumPorts1) |
| 483 | pcmcia_release_io(link->handle, &link->io); |
| 484 | if (link->irq.AssignedIRQ) |
| 485 | pcmcia_release_irq(link->handle, &link->irq); |
| 486 | link->state &= ~DEV_CONFIG; |
| 487 | if (priv->hw.iobase) |
| 488 | ioport_unmap(priv->hw.iobase); |
| 489 | } /* orinoco_cs_release */ |
| 490 | |
| 491 | /* |
| 492 | * The card status event handler. Mostly, this schedules other stuff |
| 493 | * to run after an event is received. |
| 494 | */ |
| 495 | static int |
| 496 | orinoco_cs_event(event_t event, int priority, |
| 497 | event_callback_args_t * args) |
| 498 | { |
| 499 | dev_link_t *link = args->client_data; |
| 500 | struct net_device *dev = link->priv; |
| 501 | struct orinoco_private *priv = netdev_priv(dev); |
| 502 | struct orinoco_pccard *card = priv->card; |
| 503 | int err = 0; |
| 504 | unsigned long flags; |
| 505 | |
| 506 | switch (event) { |
| 507 | case CS_EVENT_CARD_REMOVAL: |
| 508 | link->state &= ~DEV_PRESENT; |
| 509 | if (link->state & DEV_CONFIG) { |
| 510 | unsigned long flags; |
| 511 | |
| 512 | spin_lock_irqsave(&priv->lock, flags); |
| 513 | netif_device_detach(dev); |
| 514 | priv->hw_unavailable++; |
| 515 | spin_unlock_irqrestore(&priv->lock, flags); |
| 516 | } |
| 517 | break; |
| 518 | |
| 519 | case CS_EVENT_CARD_INSERTION: |
| 520 | link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; |
| 521 | orinoco_cs_config(link); |
| 522 | break; |
| 523 | |
| 524 | case CS_EVENT_PM_SUSPEND: |
| 525 | link->state |= DEV_SUSPEND; |
| 526 | /* Fall through... */ |
| 527 | case CS_EVENT_RESET_PHYSICAL: |
| 528 | /* Mark the device as stopped, to block IO until later */ |
| 529 | if (link->state & DEV_CONFIG) { |
| 530 | /* This is probably racy, but I can't think of |
| 531 | a better way, short of rewriting the PCMCIA |
| 532 | layer to not suck :-( */ |
| 533 | if (! test_bit(0, &card->hard_reset_in_progress)) { |
| 534 | spin_lock_irqsave(&priv->lock, flags); |
| 535 | |
| 536 | err = __orinoco_down(dev); |
| 537 | if (err) |
| 538 | printk(KERN_WARNING "%s: %s: Error %d downing interface\n", |
| 539 | dev->name, |
| 540 | event == CS_EVENT_PM_SUSPEND ? "SUSPEND" : "RESET_PHYSICAL", |
| 541 | err); |
| 542 | |
| 543 | netif_device_detach(dev); |
| 544 | priv->hw_unavailable++; |
| 545 | |
| 546 | spin_unlock_irqrestore(&priv->lock, flags); |
| 547 | } |
| 548 | |
| 549 | pcmcia_release_configuration(link->handle); |
| 550 | } |
| 551 | break; |
| 552 | |
| 553 | case CS_EVENT_PM_RESUME: |
| 554 | link->state &= ~DEV_SUSPEND; |
| 555 | /* Fall through... */ |
| 556 | case CS_EVENT_CARD_RESET: |
| 557 | if (link->state & DEV_CONFIG) { |
| 558 | /* FIXME: should we double check that this is |
| 559 | * the same card as we had before */ |
| 560 | pcmcia_request_configuration(link->handle, &link->conf); |
| 561 | |
| 562 | if (! test_bit(0, &card->hard_reset_in_progress)) { |
| 563 | err = orinoco_reinit_firmware(dev); |
| 564 | if (err) { |
| 565 | printk(KERN_ERR "%s: Error %d re-initializing firmware\n", |
| 566 | dev->name, err); |
| 567 | break; |
| 568 | } |
| 569 | |
| 570 | spin_lock_irqsave(&priv->lock, flags); |
| 571 | |
| 572 | netif_device_attach(dev); |
| 573 | priv->hw_unavailable--; |
| 574 | |
| 575 | if (priv->open && ! priv->hw_unavailable) { |
| 576 | err = __orinoco_up(dev); |
| 577 | if (err) |
| 578 | printk(KERN_ERR "%s: Error %d restarting card\n", |
| 579 | dev->name, err); |
| 580 | |
| 581 | } |
| 582 | |
| 583 | spin_unlock_irqrestore(&priv->lock, flags); |
| 584 | } |
| 585 | } |
| 586 | break; |
| 587 | } |
| 588 | |
| 589 | return err; |
| 590 | } /* orinoco_cs_event */ |
| 591 | |
| 592 | /********************************************************************/ |
| 593 | /* Module initialization */ |
| 594 | /********************************************************************/ |
| 595 | |
| 596 | /* Can't be declared "const" or the whole __initdata section will |
| 597 | * become const */ |
| 598 | static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION |
| 599 | " (David Gibson <hermes@gibson.dropbear.id.au>, " |
| 600 | "Pavel Roskin <proski@gnu.org>, et al)"; |
| 601 | |
Dominik Brodowski | 7422c56 | 2005-06-27 16:28:27 -0700 | [diff] [blame] | 602 | static struct pcmcia_device_id orinoco_cs_ids[] = { |
Pavel Roskin | 9c8a11d | 2005-09-16 02:18:31 -0400 | [diff] [blame^] | 603 | PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7100), /* SonicWALL Long Range Wireless Card */ |
| 604 | PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7300), /* Sohoware NCP110, Philips 802.11b */ |
| 605 | PCMCIA_DEVICE_MANF_CARD(0x0089, 0x0002), /* AnyPoint(TM) Wireless II PC Card */ |
| 606 | PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0777), /* 3Com AirConnect PCI 777A */ |
| 607 | PCMCIA_DEVICE_MANF_CARD(0x0126, 0x8000), /* PROXIM RangeLAN-DS/LAN PC CARD */ |
| 608 | PCMCIA_DEVICE_MANF_CARD(0x0138, 0x0002), /* Compaq WL100 11 Mbps Wireless Adapter */ |
| 609 | PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0002), /* Lucent Orinoco and old Intersil */ |
| 610 | PCMCIA_DEVICE_MANF_CARD(0x016b, 0x0001), /* Ericsson WLAN Card C11 */ |
| 611 | PCMCIA_DEVICE_MANF_CARD(0x01eb, 0x080a), /* Nortel Networks eMobility 802.11 Wireless Adapter */ |
| 612 | PCMCIA_DEVICE_MANF_CARD(0x01ff, 0x0008), /* Intermec MobileLAN 11Mbps 802.11b WLAN Card */ |
| 613 | PCMCIA_DEVICE_MANF_CARD(0x0250, 0x0002), /* Samsung SWL2000-N 11Mb/s WLAN Card */ |
| 614 | PCMCIA_DEVICE_MANF_CARD(0x0261, 0x0002), /* AirWay 802.11 Adapter (PCMCIA) */ |
| 615 | PCMCIA_DEVICE_MANF_CARD(0x0268, 0x0001), /* ARtem Onair */ |
| 616 | PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0305), /* Buffalo WLI-PCM-S11 */ |
| 617 | PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1612), /* Linksys WPC11 Version 2.5 */ |
| 618 | PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1613), /* Linksys WPC11 Version 3 */ |
| 619 | PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0002), /* Compaq HNW-100 11 Mbps Wireless Adapter */ |
| 620 | PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0673), /* Linksys WCF12 Wireless CompactFlash Card */ |
| 621 | PCMCIA_DEVICE_MANF_CARD(0x02aa, 0x0002), /* ASUS SpaceLink WL-100 */ |
| 622 | PCMCIA_DEVICE_MANF_CARD(0x02ac, 0x0002), /* SpeedStream SS1021 Wireless Adapter */ |
| 623 | PCMCIA_DEVICE_MANF_CARD(0x14ea, 0xb001), /* PLANEX RoadLannerWave GW-NS11H */ |
| 624 | PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x7300), /* Airvast WN-100 */ |
| 625 | PCMCIA_DEVICE_MANF_CARD(0x9005, 0x0021), /* Adaptec Ultra Wireless ANW-8030 */ |
| 626 | PCMCIA_DEVICE_MANF_CARD(0xc001, 0x0008), /* CONTEC FLEXSCAN/FX-DDS110-PCC */ |
| 627 | PCMCIA_DEVICE_MANF_CARD(0xc250, 0x0002), /* Conceptronic CON11Cpro, EMTAC A2424i */ |
| 628 | PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0002), /* Safeway 802.11b, ZCOMAX AirRunner/XI-300 */ |
| 629 | PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005), /* D-Link DCF660, Sandisk Connect SDWCFB-000 */ |
| 630 | PCMCIA_DEVICE_PROD_ID12(" ", "IEEE 802.11 Wireless LAN/PC Card", 0x3b6e20c8, 0xefccafe9), |
Dominik Brodowski | 7422c56 | 2005-06-27 16:28:27 -0700 | [diff] [blame] | 631 | PCMCIA_DEVICE_PROD_ID12("3Com", "3CRWE737A AirConnect Wireless LAN PC Card", 0x41240e5b, 0x56010af3), |
Dominik Brodowski | 7422c56 | 2005-06-27 16:28:27 -0700 | [diff] [blame] | 632 | PCMCIA_DEVICE_PROD_ID12("ACTIONTEC", "PRISM Wireless LAN PC Card", 0x393089da, 0xa71e69d5), |
Pavel Roskin | 9c8a11d | 2005-09-16 02:18:31 -0400 | [diff] [blame^] | 633 | PCMCIA_DEVICE_PROD_ID12("Addtron", "AWP-100 Wireless PCMCIA", 0xe6ec52ce, 0x08649af2), |
| 634 | PCMCIA_DEVICE_PROD_ID123("AIRVAST", "IEEE 802.11b Wireless PCMCIA Card", "HFA3863", 0xea569531, 0x4bcb9645, 0x355cb092), |
| 635 | PCMCIA_DEVICE_PROD_ID12("Allied Telesyn", "AT-WCL452 Wireless PCMCIA Radio", 0x5cd01705, 0x4271660f), |
| 636 | PCMCIA_DEVICE_PROD_ID12("ASUS", "802_11b_PC_CARD_25", 0x78fc06ee, 0xdb9aa842), |
| 637 | PCMCIA_DEVICE_PROD_ID12("ASUS", "802_11B_CF_CARD_25", 0x78fc06ee, 0x45a50c1e), |
Dominik Brodowski | 7422c56 | 2005-06-27 16:28:27 -0700 | [diff] [blame] | 638 | PCMCIA_DEVICE_PROD_ID12("Avaya Communication", "Avaya Wireless PC Card", 0xd8a43b78, 0x0d341169), |
Pavel Roskin | 9c8a11d | 2005-09-16 02:18:31 -0400 | [diff] [blame^] | 639 | PCMCIA_DEVICE_PROD_ID12("BENQ", "AWL100 PCMCIA ADAPTER", 0x35dadc74, 0x01f7fedb), |
Dominik Brodowski | 7422c56 | 2005-06-27 16:28:27 -0700 | [diff] [blame] | 640 | PCMCIA_DEVICE_PROD_ID12("BUFFALO", "WLI-PCM-L11G", 0x2decece3, 0xf57ca4b3), |
Pavel Roskin | 9c8a11d | 2005-09-16 02:18:31 -0400 | [diff] [blame^] | 641 | PCMCIA_DEVICE_PROD_ID12("BUFFALO", "WLI-CF-S11G", 0x2decece3, 0x82067c18), |
Dominik Brodowski | 7422c56 | 2005-06-27 16:28:27 -0700 | [diff] [blame] | 642 | PCMCIA_DEVICE_PROD_ID12("Cabletron", "RoamAbout 802.11 DS", 0x32d445f5, 0xedeffd90), |
Pavel Roskin | 9c8a11d | 2005-09-16 02:18:31 -0400 | [diff] [blame^] | 643 | PCMCIA_DEVICE_PROD_ID12("Compaq", "WL200_11Mbps_Wireless_PCI_Card", 0x54f7c49c, 0x15a75e5b), |
| 644 | PCMCIA_DEVICE_PROD_ID123("corega", "WL PCCL-11", "ISL37300P", 0x0a21501a, 0x59868926, 0xc9049a39), |
Dominik Brodowski | 7422c56 | 2005-06-27 16:28:27 -0700 | [diff] [blame] | 645 | PCMCIA_DEVICE_PROD_ID12("corega K.K.", "Wireless LAN PCC-11", 0x5261440f, 0xa6405584), |
| 646 | PCMCIA_DEVICE_PROD_ID12("corega K.K.", "Wireless LAN PCCA-11", 0x5261440f, 0xdf6115f9), |
Komuro | f39a4aa | 2005-09-13 01:25:05 -0700 | [diff] [blame] | 647 | PCMCIA_DEVICE_PROD_ID12("corega_K.K.", "Wireless_LAN_PCCB-11", 0x29e33311, 0xee7a27ae), |
Dominik Brodowski | 7422c56 | 2005-06-27 16:28:27 -0700 | [diff] [blame] | 648 | PCMCIA_DEVICE_PROD_ID12("D", "Link DRC-650 11Mbps WLAN Card", 0x71b18589, 0xf144e3ac), |
| 649 | PCMCIA_DEVICE_PROD_ID12("D", "Link DWL-650 11Mbps WLAN Card", 0x71b18589, 0xb6f1b0ab), |
Pavel Roskin | 9c8a11d | 2005-09-16 02:18:31 -0400 | [diff] [blame^] | 650 | PCMCIA_DEVICE_PROD_ID12("D-Link Corporation", "D-Link DWL-650H 11Mbps WLAN Adapter", 0xef544d24, 0xcd8ea916), |
| 651 | PCMCIA_DEVICE_PROD_ID12("Digital Data Communications", "WPC-0100", 0xfdd73470, 0xe0b6f146), |
Dominik Brodowski | 7422c56 | 2005-06-27 16:28:27 -0700 | [diff] [blame] | 652 | PCMCIA_DEVICE_PROD_ID12("ELSA", "AirLancer MC-11", 0x4507a33a, 0xef54f0e3), |
| 653 | PCMCIA_DEVICE_PROD_ID12("HyperLink", "Wireless PC Card 11Mbps", 0x56cc3f1a, 0x0bcf220c), |
Pavel Roskin | 9c8a11d | 2005-09-16 02:18:31 -0400 | [diff] [blame^] | 654 | PCMCIA_DEVICE_PROD_ID123("Instant Wireless ", " Network PC CARD", "Version 01.02", 0x11d901af, 0x6e9bd926, 0x4b74baa0), |
| 655 | PCMCIA_DEVICE_PROD_ID12("Intel", "PRO/Wireless 2011 LAN PC Card", 0x816cc815, 0x07f58077), |
Dominik Brodowski | 7422c56 | 2005-06-27 16:28:27 -0700 | [diff] [blame] | 656 | PCMCIA_DEVICE_PROD_ID12("INTERSIL", "HFA384x/IEEE", 0x74c5e40d, 0xdb472a18), |
Pavel Roskin | 9c8a11d | 2005-09-16 02:18:31 -0400 | [diff] [blame^] | 657 | PCMCIA_DEVICE_PROD_ID12("INTERSIL", "I-GATE 11M PC Card / PC Card plus", 0x74c5e40d, 0x8304ff77), |
| 658 | PCMCIA_DEVICE_PROD_ID12("Intersil", "PRISM 2_5 PCMCIA ADAPTER", 0x4b801a17, 0x6345a0bf), |
| 659 | PCMCIA_DEVICE_PROD_ID123("Intersil", "PRISM Freedom PCMCIA Adapter", "ISL37100P", 0x4b801a17, 0xf222ec2d, 0x630d52b2), |
| 660 | PCMCIA_DEVICE_PROD_ID12("LeArtery", "SYNCBYAIR 11Mbps Wireless LAN PC Card", 0x7e3b326a, 0x49893e92), |
| 661 | PCMCIA_DEVICE_PROD_ID12("Linksys", "Wireless CompactFlash Card", 0x0733cc81, 0x0c52f395), |
Dominik Brodowski | 7422c56 | 2005-06-27 16:28:27 -0700 | [diff] [blame] | 662 | PCMCIA_DEVICE_PROD_ID12("Lucent Technologies", "WaveLAN/IEEE", 0x23eb9949, 0xc562e72a), |
| 663 | PCMCIA_DEVICE_PROD_ID12("MELCO", "WLI-PCM-L11", 0x481e0094, 0x7360e410), |
| 664 | PCMCIA_DEVICE_PROD_ID12("MELCO", "WLI-PCM-L11G", 0x481e0094, 0xf57ca4b3), |
| 665 | PCMCIA_DEVICE_PROD_ID12("Microsoft", "Wireless Notebook Adapter MN-520", 0x5961bf85, 0x6eec8c01), |
| 666 | PCMCIA_DEVICE_PROD_ID12("NCR", "WaveLAN/IEEE", 0x24358cd4, 0xc562e72a), |
Pavel Roskin | 9c8a11d | 2005-09-16 02:18:31 -0400 | [diff] [blame^] | 667 | PCMCIA_DEVICE_PROD_ID12("NETGEAR MA401 Wireless PC", "Card", 0xa37434e9, 0x9762e8f1), |
Dominik Brodowski | 7422c56 | 2005-06-27 16:28:27 -0700 | [diff] [blame] | 668 | PCMCIA_DEVICE_PROD_ID12("NETGEAR MA401RA Wireless PC", "Card", 0x0306467f, 0x9762e8f1), |
Pavel Roskin | 9c8a11d | 2005-09-16 02:18:31 -0400 | [diff] [blame^] | 669 | PCMCIA_DEVICE_PROD_ID12("Nortel Networks", "emobility 802.11 Wireless LAN PC Card", 0x2d617ea0, 0x88cd5767), |
| 670 | PCMCIA_DEVICE_PROD_ID12("OEM", "PRISM2 IEEE 802.11 PC-Card", 0xfea54c90, 0x48f2bdd6), |
| 671 | PCMCIA_DEVICE_PROD_ID12("OTC", "Wireless AirEZY 2411-PCC WLAN Card", 0x4ac44287, 0x235a6bed), |
| 672 | PCMCIA_DEVICE_PROD_ID123("PCMCIA", "11M WLAN Card v2.5", "ISL37300P", 0x281f1c5d, 0x6e440487, 0xc9049a39), |
Dominik Brodowski | 7422c56 | 2005-06-27 16:28:27 -0700 | [diff] [blame] | 673 | PCMCIA_DEVICE_PROD_ID12("PLANEX", "GeoWave/GW-CF110", 0x209f40ab, 0xd9715264), |
Pavel Roskin | 9c8a11d | 2005-09-16 02:18:31 -0400 | [diff] [blame^] | 674 | PCMCIA_DEVICE_PROD_ID12("PLANEX", "GeoWave/GW-NS110", 0x209f40ab, 0x46263178), |
Dominik Brodowski | 7422c56 | 2005-06-27 16:28:27 -0700 | [diff] [blame] | 675 | PCMCIA_DEVICE_PROD_ID12("PROXIM", "LAN PC CARD HARMONY 80211B", 0xc6536a5e, 0x090c3cd9), |
| 676 | PCMCIA_DEVICE_PROD_ID12("PROXIM", "LAN PCI CARD HARMONY 80211B", 0xc6536a5e, 0x9f494e26), |
| 677 | PCMCIA_DEVICE_PROD_ID12("SAMSUNG", "11Mbps WLAN Card", 0x43d74cb4, 0x579bd91b), |
Pavel Roskin | 9c8a11d | 2005-09-16 02:18:31 -0400 | [diff] [blame^] | 678 | PCMCIA_DEVICE_PROD_ID12("SMC", "SMC2632W", 0xc4f8b18b, 0x474a1f2a), |
| 679 | PCMCIA_DEVICE_PROD_ID12("Symbol Technologies", "LA4111 Spectrum24 Wireless LAN PC Card", 0x3f02b4d6, 0x3663cb0e), |
| 680 | PCMCIA_DEVICE_PROD_ID123("The Linksys Group, Inc.", "Instant Wireless Network PC Card", "ISL37300P", 0xa5f472c2, 0x590eb502, 0xc9049a39), |
| 681 | PCMCIA_DEVICE_PROD_ID12("ZoomAir 11Mbps High", "Rate wireless Networking", 0x273fe3db, 0x32a1eaee), |
Dominik Brodowski | 7422c56 | 2005-06-27 16:28:27 -0700 | [diff] [blame] | 682 | PCMCIA_DEVICE_NULL, |
| 683 | }; |
| 684 | MODULE_DEVICE_TABLE(pcmcia, orinoco_cs_ids); |
| 685 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | static struct pcmcia_driver orinoco_driver = { |
| 687 | .owner = THIS_MODULE, |
| 688 | .drv = { |
| 689 | .name = DRIVER_NAME, |
| 690 | }, |
| 691 | .attach = orinoco_cs_attach, |
Dominik Brodowski | 1e212f3 | 2005-07-07 17:59:00 -0700 | [diff] [blame] | 692 | .event = orinoco_cs_event, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | .detach = orinoco_cs_detach, |
Dominik Brodowski | 7422c56 | 2005-06-27 16:28:27 -0700 | [diff] [blame] | 694 | .id_table = orinoco_cs_ids, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | }; |
| 696 | |
| 697 | static int __init |
| 698 | init_orinoco_cs(void) |
| 699 | { |
| 700 | printk(KERN_DEBUG "%s\n", version); |
| 701 | |
| 702 | return pcmcia_register_driver(&orinoco_driver); |
| 703 | } |
| 704 | |
| 705 | static void __exit |
| 706 | exit_orinoco_cs(void) |
| 707 | { |
| 708 | pcmcia_unregister_driver(&orinoco_driver); |
| 709 | BUG_ON(dev_list != NULL); |
| 710 | } |
| 711 | |
| 712 | module_init(init_orinoco_cs); |
| 713 | module_exit(exit_orinoco_cs); |