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