1/* 2 * Driver for 802.11b cards using RAM-loadable Symbol firmware, such as 3 * Symbol Wireless Networker LA4137, CompactFlash cards by Socket 4 * Communications and Intel PRO/Wireless 2011B. 5 * 6 * The driver implements Symbol firmware download. The rest is handled 7 * in hermes.c and orinoco.c. 8 * 9 * Utilities for downloading the Symbol firmware are available at 10 * http://sourceforge.net/projects/orinoco/ 11 * 12 * Copyright (C) 2002-2005 Pavel Roskin <proski@gnu.org> 13 * Portions based on orinoco_cs.c: 14 * Copyright (C) David Gibson, Linuxcare Australia 15 * Portions based on Spectrum24tDnld.c from original spectrum24 driver: 16 * Copyright (C) Symbol Technologies. 17 * 18 * See copyright notice in file orinoco.c. 19 */ 20 21#define DRIVER_NAME "spectrum_cs" 22#define PFX DRIVER_NAME ": " 23 24#include <linux/module.h> 25#include <linux/kernel.h> 26#include <linux/init.h> 27#include <linux/delay.h> 28#include <linux/firmware.h> 29#include <pcmcia/cs_types.h> 30#include <pcmcia/cs.h> 31#include <pcmcia/cistpl.h> 32#include <pcmcia/cisreg.h> 33#include <pcmcia/ds.h> 34 35#include "orinoco.h" 36 37static const char primary_fw_name[] = "symbol_sp24t_prim_fw"; 38static const char secondary_fw_name[] = "symbol_sp24t_sec_fw"; 39 40/********************************************************************/ 41/* Module stuff */ 42/********************************************************************/ 43 44MODULE_AUTHOR("Pavel Roskin <proski@gnu.org>"); 45MODULE_DESCRIPTION("Driver for Symbol Spectrum24 Trilogy cards with firmware downloader"); 46MODULE_LICENSE("Dual MPL/GPL"); 47 48/* Module parameters */ 49 50static int ignore_cis_vcc; /* = 0 */ 51module_param(ignore_cis_vcc, int, 0); 52MODULE_PARM_DESC(ignore_cis_vcc, "Allow voltage mismatch between card and socket"); 53 54/********************************************************************/ 55/* Data structures */ 56/********************************************************************/ 57 58/* PCMCIA specific device information (goes in the card field of 59 * struct orinoco_private */ 60struct orinoco_pccard { 61 struct pcmcia_device *p_dev; 62 dev_node_t node; 63}; 64 65/********************************************************************/ 66/* Function prototypes */ 67/********************************************************************/ 68 69static int spectrum_cs_config(struct pcmcia_device *link); 70static void spectrum_cs_release(struct pcmcia_device *link); 71 72/********************************************************************/ 73/* Firmware downloader */ 74/********************************************************************/ 75 76/* Position of PDA in the adapter memory */ 77#define EEPROM_ADDR 0x3000 78#define EEPROM_LEN 0x200 79#define PDA_OFFSET 0x100 80 81#define PDA_ADDR (EEPROM_ADDR + PDA_OFFSET) 82#define PDA_WORDS ((EEPROM_LEN - PDA_OFFSET) / 2) 83 84/* Constants for the CISREG_CCSR register */ 85#define HCR_RUN 0x07 /* run firmware after reset */ 86#define HCR_IDLE 0x0E /* don't run firmware after reset */ 87#define HCR_MEM16 0x10 /* memory width bit, should be preserved */ 88 89/* 90 * AUX port access. To unlock the AUX port write the access keys to the 91 * PARAM0-2 registers, then write HERMES_AUX_ENABLE to the HERMES_CONTROL 92 * register. Then read it and make sure it's HERMES_AUX_ENABLED. 93 */ 94#define HERMES_AUX_ENABLE 0x8000 /* Enable auxiliary port access */ 95#define HERMES_AUX_DISABLE 0x4000 /* Disable to auxiliary port access */ 96#define HERMES_AUX_ENABLED 0xC000 /* Auxiliary port is open */ 97 98#define HERMES_AUX_PW0 0xFE01 99#define HERMES_AUX_PW1 0xDC23 100#define HERMES_AUX_PW2 0xBA45 101 102/* End markers */ 103#define PDI_END 0x00000000 /* End of PDA */ 104#define BLOCK_END 0xFFFFFFFF /* Last image block */ 105#define TEXT_END 0x1A /* End of text header */ 106 107/* 108 * The following structures have little-endian fields denoted by 109 * the leading underscore. Don't access them directly - use inline 110 * functions defined below. 111 */ 112 113/* 114 * The binary image to be downloaded consists of series of data blocks. 115 * Each block has the following structure. 116 */ 117struct dblock { 118 __le32 addr; /* adapter address where to write the block */ 119 __le16 len; /* length of the data only, in bytes */ 120 char data[0]; /* data to be written */ 121} __attribute__ ((packed)); 122 123/* 124 * Plug Data References are located in in the image after the last data 125 * block. They refer to areas in the adapter memory where the plug data 126 * items with matching ID should be written. 127 */ 128struct pdr { 129 __le32 id; /* record ID */ 130 __le32 addr; /* adapter address where to write the data */ 131 __le32 len; /* expected length of the data, in bytes */ 132 char next[0]; /* next PDR starts here */ 133} __attribute__ ((packed)); 134 135 136/* 137 * Plug Data Items are located in the EEPROM read from the adapter by 138 * primary firmware. They refer to the device-specific data that should 139 * be plugged into the secondary firmware. 140 */ 141struct pdi { 142 __le16 len; /* length of ID and data, in words */ 143 __le16 id; /* record ID */ 144 char data[0]; /* plug data */ 145} __attribute__ ((packed)); 146 147 148/* Functions for access to little-endian data */ 149static inline u32 150dblock_addr(const struct dblock *blk) 151{ 152 return le32_to_cpu(blk->addr); 153} 154 155static inline u32 156dblock_len(const struct dblock *blk) 157{ 158 return le16_to_cpu(blk->len); 159} 160 161static inline u32 162pdr_id(const struct pdr *pdr) 163{ 164 return le32_to_cpu(pdr->id); 165} 166 167static inline u32 168pdr_addr(const struct pdr *pdr) 169{ 170 return le32_to_cpu(pdr->addr); 171} 172 173static inline u32 174pdr_len(const struct pdr *pdr) 175{ 176 return le32_to_cpu(pdr->len); 177} 178 179static inline u32 180pdi_id(const struct pdi *pdi) 181{ 182 return le16_to_cpu(pdi->id); 183} 184 185/* Return length of the data only, in bytes */ 186static inline u32 187pdi_len(const struct pdi *pdi) 188{ 189 return 2 * (le16_to_cpu(pdi->len) - 1); 190} 191 192 193/* Set address of the auxiliary port */ 194static inline void 195spectrum_aux_setaddr(hermes_t *hw, u32 addr) 196{ 197 hermes_write_reg(hw, HERMES_AUXPAGE, (u16) (addr >> 7)); 198 hermes_write_reg(hw, HERMES_AUXOFFSET, (u16) (addr & 0x7F)); 199} 200 201 202/* Open access to the auxiliary port */ 203static int 204spectrum_aux_open(hermes_t *hw) 205{ 206 int i; 207 208 /* Already open? */ 209 if (hermes_read_reg(hw, HERMES_CONTROL) == HERMES_AUX_ENABLED) 210 return 0; 211 212 hermes_write_reg(hw, HERMES_PARAM0, HERMES_AUX_PW0); 213 hermes_write_reg(hw, HERMES_PARAM1, HERMES_AUX_PW1); 214 hermes_write_reg(hw, HERMES_PARAM2, HERMES_AUX_PW2); 215 hermes_write_reg(hw, HERMES_CONTROL, HERMES_AUX_ENABLE); 216 217 for (i = 0; i < 20; i++) { 218 udelay(10); 219 if (hermes_read_reg(hw, HERMES_CONTROL) == 220 HERMES_AUX_ENABLED) 221 return 0; 222 } 223 224 return -EBUSY; 225} 226 227 228#define CS_CHECK(fn, ret) \ 229 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 230 231/* 232 * Reset the card using configuration registers COR and CCSR. 233 * If IDLE is 1, stop the firmware, so that it can be safely rewritten. 234 */ 235static int 236spectrum_reset(struct pcmcia_device *link, int idle) 237{ 238 int last_ret, last_fn; 239 conf_reg_t reg; 240 u_int save_cor; 241 242 /* Doing it if hardware is gone is guaranteed crash */ 243 if (!pcmcia_dev_present(link)) 244 return -ENODEV; 245 246 /* Save original COR value */ 247 reg.Function = 0; 248 reg.Action = CS_READ; 249 reg.Offset = CISREG_COR; 250 CS_CHECK(AccessConfigurationRegister, 251 pcmcia_access_configuration_register(link, ®)); 252 save_cor = reg.Value; 253 254 /* Soft-Reset card */ 255 reg.Action = CS_WRITE; 256 reg.Offset = CISREG_COR; 257 reg.Value = (save_cor | COR_SOFT_RESET); 258 CS_CHECK(AccessConfigurationRegister, 259 pcmcia_access_configuration_register(link, ®)); 260 udelay(1000); 261 262 /* Read CCSR */ 263 reg.Action = CS_READ; 264 reg.Offset = CISREG_CCSR; 265 CS_CHECK(AccessConfigurationRegister, 266 pcmcia_access_configuration_register(link, ®)); 267 268 /* 269 * Start or stop the firmware. Memory width bit should be 270 * preserved from the value we've just read. 271 */ 272 reg.Action = CS_WRITE; 273 reg.Offset = CISREG_CCSR; 274 reg.Value = (idle ? HCR_IDLE : HCR_RUN) | (reg.Value & HCR_MEM16); 275 CS_CHECK(AccessConfigurationRegister, 276 pcmcia_access_configuration_register(link, ®)); 277 udelay(1000); 278 279 /* Restore original COR configuration index */ 280 reg.Action = CS_WRITE; 281 reg.Offset = CISREG_COR; 282 reg.Value = (save_cor & ~COR_SOFT_RESET); 283 CS_CHECK(AccessConfigurationRegister, 284 pcmcia_access_configuration_register(link, ®)); 285 udelay(1000); 286 return 0; 287 288 cs_failed: 289 cs_error(link, last_fn, last_ret); 290 return -ENODEV; 291} 292 293 294/* 295 * Scan PDR for the record with the specified RECORD_ID. 296 * If it's not found, return NULL. 297 */ 298static struct pdr * 299spectrum_find_pdr(struct pdr *first_pdr, u32 record_id) 300{ 301 struct pdr *pdr = first_pdr; 302 303 while (pdr_id(pdr) != PDI_END) { 304 /* 305 * PDR area is currently not terminated by PDI_END. 306 * It's followed by CRC records, which have the type 307 * field where PDR has length. The type can be 0 or 1. 308 */ 309 if (pdr_len(pdr) < 2) 310 return NULL; 311 312 /* If the record ID matches, we are done */ 313 if (pdr_id(pdr) == record_id) 314 return pdr; 315 316 pdr = (struct pdr *) pdr->next; 317 } 318 return NULL; 319} 320 321 322/* Process one Plug Data Item - find corresponding PDR and plug it */ 323static int 324spectrum_plug_pdi(hermes_t *hw, struct pdr *first_pdr, struct pdi *pdi) 325{ 326 struct pdr *pdr; 327 328 /* Find the PDI corresponding to this PDR */ 329 pdr = spectrum_find_pdr(first_pdr, pdi_id(pdi)); 330 331 /* No match is found, safe to ignore */ 332 if (!pdr) 333 return 0; 334 335 /* Lengths of the data in PDI and PDR must match */ 336 if (pdi_len(pdi) != pdr_len(pdr)) 337 return -EINVAL; 338 339 /* do the actual plugging */ 340 spectrum_aux_setaddr(hw, pdr_addr(pdr)); 341 hermes_write_bytes(hw, HERMES_AUXDATA, pdi->data, pdi_len(pdi)); 342 343 return 0; 344} 345 346 347/* Read PDA from the adapter */ 348static int 349spectrum_read_pda(hermes_t *hw, __le16 *pda, int pda_len) 350{ 351 int ret; 352 int pda_size; 353 354 /* Issue command to read EEPROM */ 355 ret = hermes_docmd_wait(hw, HERMES_CMD_READMIF, 0, NULL); 356 if (ret) 357 return ret; 358 359 /* Open auxiliary port */ 360 ret = spectrum_aux_open(hw); 361 if (ret) 362 return ret; 363 364 /* read PDA from EEPROM */ 365 spectrum_aux_setaddr(hw, PDA_ADDR); 366 hermes_read_words(hw, HERMES_AUXDATA, pda, pda_len / 2); 367 368 /* Check PDA length */ 369 pda_size = le16_to_cpu(pda[0]); 370 if (pda_size > pda_len) 371 return -EINVAL; 372 373 return 0; 374} 375 376 377/* Parse PDA and write the records into the adapter */ 378static int 379spectrum_apply_pda(hermes_t *hw, const struct dblock *first_block, 380 __le16 *pda) 381{ 382 int ret; 383 struct pdi *pdi; 384 struct pdr *first_pdr; 385 const struct dblock *blk = first_block; 386 387 /* Skip all blocks to locate Plug Data References */ 388 while (dblock_addr(blk) != BLOCK_END) 389 blk = (struct dblock *) &blk->data[dblock_len(blk)]; 390 391 first_pdr = (struct pdr *) blk; 392 393 /* Go through every PDI and plug them into the adapter */ 394 pdi = (struct pdi *) (pda + 2); 395 while (pdi_id(pdi) != PDI_END) { 396 ret = spectrum_plug_pdi(hw, first_pdr, pdi); 397 if (ret) 398 return ret; 399 400 /* Increment to the next PDI */ 401 pdi = (struct pdi *) &pdi->data[pdi_len(pdi)]; 402 } 403 return 0; 404} 405 406 407/* Load firmware blocks into the adapter */ 408static int 409spectrum_load_blocks(hermes_t *hw, const struct dblock *first_block) 410{ 411 const struct dblock *blk; 412 u32 blkaddr; 413 u32 blklen; 414 415 blk = first_block; 416 blkaddr = dblock_addr(blk); 417 blklen = dblock_len(blk); 418 419 while (dblock_addr(blk) != BLOCK_END) { 420 spectrum_aux_setaddr(hw, blkaddr); 421 hermes_write_bytes(hw, HERMES_AUXDATA, blk->data, 422 blklen); 423 424 blk = (struct dblock *) &blk->data[blklen]; 425 blkaddr = dblock_addr(blk); 426 blklen = dblock_len(blk); 427 } 428 return 0; 429} 430 431 432/* 433 * Process a firmware image - stop the card, load the firmware, reset 434 * the card and make sure it responds. For the secondary firmware take 435 * care of the PDA - read it and then write it on top of the firmware. 436 */ 437static int 438spectrum_dl_image(hermes_t *hw, struct pcmcia_device *link, 439 const unsigned char *image, int secondary) 440{ 441 int ret; 442 const unsigned char *ptr; 443 const struct dblock *first_block; 444 445 /* Plug Data Area (PDA) */ 446 __le16 pda[PDA_WORDS]; 447 448 /* Binary block begins after the 0x1A marker */ 449 ptr = image; 450 while (*ptr++ != TEXT_END); 451 first_block = (const struct dblock *) ptr; 452 453 /* Read the PDA */ 454 if (secondary) { 455 ret = spectrum_read_pda(hw, pda, sizeof(pda)); 456 if (ret) 457 return ret; 458 } 459 460 /* Stop the firmware, so that it can be safely rewritten */ 461 ret = spectrum_reset(link, 1); 462 if (ret) 463 return ret; 464 465 /* Program the adapter with new firmware */ 466 ret = spectrum_load_blocks(hw, first_block); 467 if (ret) 468 return ret; 469 470 /* Write the PDA to the adapter */ 471 if (secondary) { 472 ret = spectrum_apply_pda(hw, first_block, pda); 473 if (ret) 474 return ret; 475 } 476 477 /* Run the firmware */ 478 ret = spectrum_reset(link, 0); 479 if (ret) 480 return ret; 481 482 /* Reset hermes chip and make sure it responds */ 483 ret = hermes_init(hw); 484 485 /* hermes_reset() should return 0 with the secondary firmware */ 486 if (secondary && ret != 0) 487 return -ENODEV; 488 489 /* And this should work with any firmware */ 490 if (!hermes_present(hw)) 491 return -ENODEV; 492 493 return 0; 494} 495 496 497/* 498 * Download the firmware into the card, this also does a PCMCIA soft 499 * reset on the card, to make sure it's in a sane state. 500 */ 501static int 502spectrum_dl_firmware(hermes_t *hw, struct pcmcia_device *link) 503{ 504 int ret; 505 const struct firmware *fw_entry; 506 507 if (request_firmware(&fw_entry, primary_fw_name, 508 &handle_to_dev(link)) != 0) { 509 printk(KERN_ERR PFX "Cannot find firmware: %s\n", 510 primary_fw_name); 511 return -ENOENT; 512 } 513 514 /* Load primary firmware */ 515 ret = spectrum_dl_image(hw, link, fw_entry->data, 0); 516 release_firmware(fw_entry); 517 if (ret) { 518 printk(KERN_ERR PFX "Primary firmware download failed\n"); 519 return ret; 520 } 521 522 if (request_firmware(&fw_entry, secondary_fw_name, 523 &handle_to_dev(link)) != 0) { 524 printk(KERN_ERR PFX "Cannot find firmware: %s\n", 525 secondary_fw_name); 526 return -ENOENT; 527 } 528 529 /* Load secondary firmware */ 530 ret = spectrum_dl_image(hw, link, fw_entry->data, 1); 531 release_firmware(fw_entry); 532 if (ret) { 533 printk(KERN_ERR PFX "Secondary firmware download failed\n"); 534 } 535 536 return ret; 537} 538 539/********************************************************************/ 540/* Device methods */ 541/********************************************************************/ 542 543static int 544spectrum_cs_hard_reset(struct orinoco_private *priv) 545{ 546 struct orinoco_pccard *card = priv->card; 547 struct pcmcia_device *link = card->p_dev; 548 int err; 549 550 if (!hermes_present(&priv->hw)) { 551 /* The firmware needs to be reloaded */ 552 if (spectrum_dl_firmware(&priv->hw, link) != 0) { 553 printk(KERN_ERR PFX "Firmware download failed\n"); 554 err = -ENODEV; 555 } 556 } else { 557 /* Soft reset using COR and HCR */ 558 spectrum_reset(link, 0); 559 } 560 561 return 0; 562} 563 564/********************************************************************/ 565/* PCMCIA stuff */ 566/********************************************************************/ 567 568/* 569 * This creates an "instance" of the driver, allocating local data 570 * structures for one device. The device is registered with Card 571 * Services. 572 * 573 * The dev_link structure is initialized, but we don't actually 574 * configure the card at this point -- we wait until we receive a card 575 * insertion event. */ 576static int 577spectrum_cs_probe(struct pcmcia_device *link) 578{ 579 struct net_device *dev; 580 struct orinoco_private *priv; 581 struct orinoco_pccard *card; 582 583 dev = alloc_orinocodev(sizeof(*card), spectrum_cs_hard_reset); 584 if (! dev) 585 return -ENOMEM; 586 priv = netdev_priv(dev); 587 card = priv->card; 588 589 /* Link both structures together */ 590 card->p_dev = link; 591 link->priv = dev; 592 593 /* Interrupt setup */ 594 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; 595 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 596 link->irq.Handler = orinoco_interrupt; 597 link->irq.Instance = dev; 598 599 /* General socket configuration defaults can go here. In this 600 * client, we assume very little, and rely on the CIS for 601 * almost everything. In most clients, many details (i.e., 602 * number, sizes, and attributes of IO windows) are fixed by 603 * the nature of the device, and can be hard-wired here. */ 604 link->conf.Attributes = 0; 605 link->conf.IntType = INT_MEMORY_AND_IO; 606 607 return spectrum_cs_config(link); 608} /* spectrum_cs_attach */ 609 610/* 611 * This deletes a driver "instance". The device is de-registered with 612 * Card Services. If it has been released, all local data structures 613 * are freed. Otherwise, the structures will be freed when the device 614 * is released. 615 */ 616static void spectrum_cs_detach(struct pcmcia_device *link) 617{ 618 struct net_device *dev = link->priv; 619 620 if (link->dev_node) 621 unregister_netdev(dev); 622 623 spectrum_cs_release(link); 624 625 free_orinocodev(dev); 626} /* spectrum_cs_detach */ 627 628/* 629 * spectrum_cs_config() is scheduled to run after a CARD_INSERTION 630 * event is received, to configure the PCMCIA socket, and to make the 631 * device available to the system. 632 */ 633 634static int 635spectrum_cs_config(struct pcmcia_device *link) 636{ 637 struct net_device *dev = link->priv; 638 struct orinoco_private *priv = netdev_priv(dev); 639 struct orinoco_pccard *card = priv->card; 640 hermes_t *hw = &priv->hw; 641 int last_fn, last_ret; 642 u_char buf[64]; 643 config_info_t conf; 644 tuple_t tuple; 645 cisparse_t parse; 646 void __iomem *mem; 647 648 /* Look up the current Vcc */ 649 CS_CHECK(GetConfigurationInfo, 650 pcmcia_get_configuration_info(link, &conf)); 651 652 /* 653 * In this loop, we scan the CIS for configuration table 654 * entries, each of which describes a valid card 655 * configuration, including voltage, IO window, memory window, 656 * and interrupt settings. 657 * 658 * We make no assumptions about the card to be configured: we 659 * use just the information available in the CIS. In an ideal 660 * world, this would work for any PCMCIA card, but it requires 661 * a complete and accurate CIS. In practice, a driver usually 662 * "knows" most of these things without consulting the CIS, 663 * and most client drivers will only use the CIS to fill in 664 * implementation-defined details. 665 */ 666 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 667 tuple.Attributes = 0; 668 tuple.TupleData = buf; 669 tuple.TupleDataMax = sizeof(buf); 670 tuple.TupleOffset = 0; 671 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple)); 672 while (1) { 673 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); 674 cistpl_cftable_entry_t dflt = { .index = 0 }; 675 676 if ( (pcmcia_get_tuple_data(link, &tuple) != 0) 677 || (pcmcia_parse_tuple(link, &tuple, &parse) != 0)) 678 goto next_entry; 679 680 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) 681 dflt = *cfg; 682 if (cfg->index == 0) 683 goto next_entry; 684 link->conf.ConfigIndex = cfg->index; 685 686 /* Use power settings for Vcc and Vpp if present */ 687 /* Note that the CIS values need to be rescaled */ 688 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) { 689 if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) { 690 DEBUG(2, "spectrum_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n", conf.Vcc, cfg->vcc.param[CISTPL_POWER_VNOM] / 10000); 691 if (!ignore_cis_vcc) 692 goto next_entry; 693 } 694 } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) { 695 if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] / 10000) { 696 DEBUG(2, "spectrum_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n", conf.Vcc, dflt.vcc.param[CISTPL_POWER_VNOM] / 10000); 697 if(!ignore_cis_vcc) 698 goto next_entry; 699 } 700 } 701 702 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) 703 link->conf.Vpp = 704 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; 705 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) 706 link->conf.Vpp = 707 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000; 708 709 /* Do we need to allocate an interrupt? */ 710 link->conf.Attributes |= CONF_ENABLE_IRQ; 711 712 /* IO window settings */ 713 link->io.NumPorts1 = link->io.NumPorts2 = 0; 714 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { 715 cistpl_io_t *io = 716 (cfg->io.nwin) ? &cfg->io : &dflt.io; 717 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 718 if (!(io->flags & CISTPL_IO_8BIT)) 719 link->io.Attributes1 = 720 IO_DATA_PATH_WIDTH_16; 721 if (!(io->flags & CISTPL_IO_16BIT)) 722 link->io.Attributes1 = 723 IO_DATA_PATH_WIDTH_8; 724 link->io.IOAddrLines = 725 io->flags & CISTPL_IO_LINES_MASK; 726 link->io.BasePort1 = io->win[0].base; 727 link->io.NumPorts1 = io->win[0].len; 728 if (io->nwin > 1) { 729 link->io.Attributes2 = 730 link->io.Attributes1; 731 link->io.BasePort2 = io->win[1].base; 732 link->io.NumPorts2 = io->win[1].len; 733 } 734 735 /* This reserves IO space but doesn't actually enable it */ 736 if (pcmcia_request_io(link, &link->io) != 0) 737 goto next_entry; 738 } 739 740 741 /* If we got this far, we're cool! */ 742 743 break; 744 745 next_entry: 746 pcmcia_disable_device(link); 747 last_ret = pcmcia_get_next_tuple(link, &tuple); 748 if (last_ret == CS_NO_MORE_ITEMS) { 749 printk(KERN_ERR PFX "GetNextTuple(): No matching " 750 "CIS configuration. Maybe you need the " 751 "ignore_cis_vcc=1 parameter.\n"); 752 goto cs_failed; 753 } 754 } 755 756 /* 757 * Allocate an interrupt line. Note that this does not assign 758 * a handler to the interrupt, unless the 'Handler' member of 759 * the irq structure is initialized. 760 */ 761 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); 762 763 /* We initialize the hermes structure before completing PCMCIA 764 * configuration just in case the interrupt handler gets 765 * called. */ 766 mem = ioport_map(link->io.BasePort1, link->io.NumPorts1); 767 if (!mem) 768 goto cs_failed; 769 770 hermes_struct_init(hw, mem, HERMES_16BIT_REGSPACING); 771 772 /* 773 * This actually configures the PCMCIA socket -- setting up 774 * the I/O windows and the interrupt mapping, and putting the 775 * card and host interface into "Memory and IO" mode. 776 */ 777 CS_CHECK(RequestConfiguration, 778 pcmcia_request_configuration(link, &link->conf)); 779 780 /* Ok, we have the configuration, prepare to register the netdev */ 781 dev->base_addr = link->io.BasePort1; 782 dev->irq = link->irq.AssignedIRQ; 783 SET_MODULE_OWNER(dev); 784 card->node.major = card->node.minor = 0; 785 786 /* Reset card and download firmware */ 787 if (spectrum_cs_hard_reset(priv) != 0) { 788 goto failed; 789 } 790 791 SET_NETDEV_DEV(dev, &handle_to_dev(link)); 792 /* Tell the stack we exist */ 793 if (register_netdev(dev) != 0) { 794 printk(KERN_ERR PFX "register_netdev() failed\n"); 795 goto failed; 796 } 797 798 /* At this point, the dev_node_t structure(s) needs to be 799 * initialized and arranged in a linked list at link->dev_node. */ 800 strcpy(card->node.dev_name, dev->name); 801 link->dev_node = &card->node; /* link->dev_node being non-NULL is also 802 used to indicate that the 803 net_device has been registered */ 804 805 /* Finally, report what we've done */ 806 printk(KERN_DEBUG "%s: " DRIVER_NAME " at %s, irq %d, io " 807 "0x%04x-0x%04x\n", dev->name, dev->dev.parent->bus_id, 808 link->irq.AssignedIRQ, link->io.BasePort1, 809 link->io.BasePort1 + link->io.NumPorts1 - 1); 810 811 return 0; 812 813 cs_failed: 814 cs_error(link, last_fn, last_ret); 815 816 failed: 817 spectrum_cs_release(link); 818 return -ENODEV; 819} /* spectrum_cs_config */ 820 821/* 822 * After a card is removed, spectrum_cs_release() will unregister the 823 * device, and release the PCMCIA configuration. If the device is 824 * still open, this will be postponed until it is closed. 825 */ 826static void 827spectrum_cs_release(struct pcmcia_device *link) 828{ 829 struct net_device *dev = link->priv; 830 struct orinoco_private *priv = netdev_priv(dev); 831 unsigned long flags; 832 833 /* We're committed to taking the device away now, so mark the 834 * hardware as unavailable */ 835 spin_lock_irqsave(&priv->lock, flags); 836 priv->hw_unavailable++; 837 spin_unlock_irqrestore(&priv->lock, flags); 838 839 pcmcia_disable_device(link); 840 if (priv->hw.iobase) 841 ioport_unmap(priv->hw.iobase); 842} /* spectrum_cs_release */ 843 844 845static int 846spectrum_cs_suspend(struct pcmcia_device *link) 847{ 848 struct net_device *dev = link->priv; 849 struct orinoco_private *priv = netdev_priv(dev); 850 int err = 0; 851 852 /* Mark the device as stopped, to block IO until later */ 853 spin_lock(&priv->lock); 854 855 err = __orinoco_down(dev); 856 if (err) 857 printk(KERN_WARNING "%s: Error %d downing interface\n", 858 dev->name, err); 859 860 netif_device_detach(dev); 861 priv->hw_unavailable++; 862 863 spin_unlock(&priv->lock); 864 865 return err; 866} 867 868static int 869spectrum_cs_resume(struct pcmcia_device *link) 870{ 871 struct net_device *dev = link->priv; 872 struct orinoco_private *priv = netdev_priv(dev); 873 874 netif_device_attach(dev); 875 priv->hw_unavailable--; 876 schedule_work(&priv->reset_work); 877 878 return 0; 879} 880 881 882/********************************************************************/ 883/* Module initialization */ 884/********************************************************************/ 885 886/* Can't be declared "const" or the whole __initdata section will 887 * become const */ 888static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION 889 " (Pavel Roskin <proski@gnu.org>," 890 " David Gibson <hermes@gibson.dropbear.id.au>, et al)"; 891 892static struct pcmcia_device_id spectrum_cs_ids[] = { 893 PCMCIA_DEVICE_MANF_CARD(0x026c, 0x0001), /* Symbol Spectrum24 LA4137 */ 894 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0001), /* Socket Communications CF */ 895 PCMCIA_DEVICE_PROD_ID12("Intel", "PRO/Wireless LAN PC Card", 0x816cc815, 0x6fbf459a), /* 2011B, not 2011 */ 896 PCMCIA_DEVICE_NULL, 897}; 898MODULE_DEVICE_TABLE(pcmcia, spectrum_cs_ids); 899 900static struct pcmcia_driver orinoco_driver = { 901 .owner = THIS_MODULE, 902 .drv = { 903 .name = DRIVER_NAME, 904 }, 905 .probe = spectrum_cs_probe, 906 .remove = spectrum_cs_detach, 907 .suspend = spectrum_cs_suspend, 908 .resume = spectrum_cs_resume, 909 .id_table = spectrum_cs_ids, 910}; 911 912static int __init 913init_spectrum_cs(void) 914{ 915 printk(KERN_DEBUG "%s\n", version); 916 917 return pcmcia_register_driver(&orinoco_driver); 918} 919 920static void __exit 921exit_spectrum_cs(void) 922{ 923 pcmcia_unregister_driver(&orinoco_driver); 924} 925 926module_init(init_spectrum_cs); 927module_exit(exit_spectrum_cs); 928