2 * Driver for 802.11b cards using RAM-loadable Symbol firmware, such as
3 * Symbol Wireless Networker LA4100, CompactFlash cards by Socket
4 * Communications and Intel PRO/Wireless 2011B.
6 * The driver implements Symbol firmware download. The rest is handled
7 * in hermes.c and orinoco.c.
9 * Utilities for downloading the Symbol firmware are available at
10 * http://sourceforge.net/projects/orinoco/
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.
18 * See copyright notice in file orinoco.c.
21 #define DRIVER_NAME "spectrum_cs"
22 #define PFX DRIVER_NAME ": "
24 #include <linux/config.h>
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/init.h>
28 #include <linux/delay.h>
29 #include <linux/firmware.h>
30 #include <pcmcia/cs_types.h>
31 #include <pcmcia/cs.h>
32 #include <pcmcia/cistpl.h>
33 #include <pcmcia/cisreg.h>
34 #include <pcmcia/ds.h>
38 static unsigned char *primsym;
39 static unsigned char *secsym;
40 static const char primary_fw_name[] = "symbol_sp24t_prim_fw";
41 static const char secondary_fw_name[] = "symbol_sp24t_sec_fw";
43 /********************************************************************/
45 /********************************************************************/
47 MODULE_AUTHOR("Pavel Roskin <proski@gnu.org>");
48 MODULE_DESCRIPTION("Driver for Symbol Spectrum24 Trilogy cards with firmware downloader");
49 MODULE_LICENSE("Dual MPL/GPL");
51 /* Module parameters */
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");
59 /********************************************************************/
61 /********************************************************************/
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.
68 static dev_info_t dev_info = DRIVER_NAME;
70 /********************************************************************/
72 /********************************************************************/
74 /* PCMCIA specific device information (goes in the card field of
75 * struct orinoco_private */
76 struct orinoco_pccard {
82 * A linked list of "instances" of the device. Each actual PCMCIA
83 * card corresponds to one device instance, and is described by one
84 * dev_link_t structure (defined in ds.h).
86 static dev_link_t *dev_list; /* = NULL */
88 /********************************************************************/
89 /* Function prototypes */
90 /********************************************************************/
92 static void spectrum_cs_release(dev_link_t *link);
93 static void spectrum_cs_detach(dev_link_t *link);
95 /********************************************************************/
96 /* Firmware downloader */
97 /********************************************************************/
99 /* Position of PDA in the adapter memory */
100 #define EEPROM_ADDR 0x3000
101 #define EEPROM_LEN 0x200
102 #define PDA_OFFSET 0x100
104 #define PDA_ADDR (EEPROM_ADDR + PDA_OFFSET)
105 #define PDA_WORDS ((EEPROM_LEN - PDA_OFFSET) / 2)
107 /* Constants for the CISREG_CCSR register */
108 #define HCR_RUN 0x07 /* run firmware after reset */
109 #define HCR_IDLE 0x0E /* don't run firmware after reset */
110 #define HCR_MEM16 0x10 /* memory width bit, should be preserved */
113 * AUX port access. To unlock the AUX port write the access keys to the
114 * PARAM0-2 registers, then write HERMES_AUX_ENABLE to the HERMES_CONTROL
115 * register. Then read it and make sure it's HERMES_AUX_ENABLED.
117 #define HERMES_AUX_ENABLE 0x8000 /* Enable auxiliary port access */
118 #define HERMES_AUX_DISABLE 0x4000 /* Disable to auxiliary port access */
119 #define HERMES_AUX_ENABLED 0xC000 /* Auxiliary port is open */
121 #define HERMES_AUX_PW0 0xFE01
122 #define HERMES_AUX_PW1 0xDC23
123 #define HERMES_AUX_PW2 0xBA45
126 #define PDI_END 0x00000000 /* End of PDA */
127 #define BLOCK_END 0xFFFFFFFF /* Last image block */
128 #define TEXT_END 0x1A /* End of text header */
131 * The following structures have little-endian fields denoted by
132 * the leading underscore. Don't access them directly - use inline
133 * functions defined below.
137 * The binary image to be downloaded consists of series of data blocks.
138 * Each block has the following structure.
141 __le32 _addr; /* adapter address where to write the block */
142 __le16 _len; /* length of the data only, in bytes */
143 char data[0]; /* data to be written */
144 } __attribute__ ((packed));
147 * Plug Data References are located in in the image after the last data
148 * block. They refer to areas in the adapter memory where the plug data
149 * items with matching ID should be written.
152 __le32 _id; /* record ID */
153 __le32 _addr; /* adapter address where to write the data */
154 __le32 _len; /* expected length of the data, in bytes */
155 char next[0]; /* next PDR starts here */
156 } __attribute__ ((packed));
160 * Plug Data Items are located in the EEPROM read from the adapter by
161 * primary firmware. They refer to the device-specific data that should
162 * be plugged into the secondary firmware.
165 __le16 _len; /* length of ID and data, in words */
166 __le16 _id; /* record ID */
167 char data[0]; /* plug data */
168 } __attribute__ ((packed));;
171 /* Functions for access to little-endian data */
173 dblock_addr(const struct dblock *blk)
175 return le32_to_cpu(blk->_addr);
179 dblock_len(const struct dblock *blk)
181 return le16_to_cpu(blk->_len);
185 pdr_id(const struct pdr *pdr)
187 return le32_to_cpu(pdr->_id);
191 pdr_addr(const struct pdr *pdr)
193 return le32_to_cpu(pdr->_addr);
197 pdr_len(const struct pdr *pdr)
199 return le32_to_cpu(pdr->_len);
203 pdi_id(const struct pdi *pdi)
205 return le16_to_cpu(pdi->_id);
208 /* Return length of the data only, in bytes */
210 pdi_len(const struct pdi *pdi)
212 return 2 * (le16_to_cpu(pdi->_len) - 1);
216 /* Set address of the auxiliary port */
218 spectrum_aux_setaddr(hermes_t *hw, u32 addr)
220 hermes_write_reg(hw, HERMES_AUXPAGE, (u16) (addr >> 7));
221 hermes_write_reg(hw, HERMES_AUXOFFSET, (u16) (addr & 0x7F));
225 /* Open access to the auxiliary port */
227 spectrum_aux_open(hermes_t *hw)
232 if (hermes_read_reg(hw, HERMES_CONTROL) == HERMES_AUX_ENABLED)
235 hermes_write_reg(hw, HERMES_PARAM0, HERMES_AUX_PW0);
236 hermes_write_reg(hw, HERMES_PARAM1, HERMES_AUX_PW1);
237 hermes_write_reg(hw, HERMES_PARAM2, HERMES_AUX_PW2);
238 hermes_write_reg(hw, HERMES_CONTROL, HERMES_AUX_ENABLE);
240 for (i = 0; i < 20; i++) {
242 if (hermes_read_reg(hw, HERMES_CONTROL) ==
251 #define CS_CHECK(fn, ret) \
252 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
255 * Reset the card using configuration registers COR and CCSR.
256 * If IDLE is 1, stop the firmware, so that it can be safely rewritten.
259 spectrum_reset(dev_link_t *link, int idle)
261 int last_ret, last_fn;
265 /* Doing it if hardware is gone is guaranteed crash */
266 if (!(link->state & DEV_CONFIG))
269 /* Save original COR value */
271 reg.Action = CS_READ;
272 reg.Offset = CISREG_COR;
273 CS_CHECK(AccessConfigurationRegister,
274 pcmcia_access_configuration_register(link->handle, ®));
275 save_cor = reg.Value;
277 /* Soft-Reset card */
278 reg.Action = CS_WRITE;
279 reg.Offset = CISREG_COR;
280 reg.Value = (save_cor | COR_SOFT_RESET);
281 CS_CHECK(AccessConfigurationRegister,
282 pcmcia_access_configuration_register(link->handle, ®));
286 reg.Action = CS_READ;
287 reg.Offset = CISREG_CCSR;
288 CS_CHECK(AccessConfigurationRegister,
289 pcmcia_access_configuration_register(link->handle, ®));
292 * Start or stop the firmware. Memory width bit should be
293 * preserved from the value we've just read.
295 reg.Action = CS_WRITE;
296 reg.Offset = CISREG_CCSR;
297 reg.Value = (idle ? HCR_IDLE : HCR_RUN) | (reg.Value & HCR_MEM16);
298 CS_CHECK(AccessConfigurationRegister,
299 pcmcia_access_configuration_register(link->handle, ®));
302 /* Restore original COR configuration index */
303 reg.Action = CS_WRITE;
304 reg.Offset = CISREG_COR;
305 reg.Value = (save_cor & ~COR_SOFT_RESET);
306 CS_CHECK(AccessConfigurationRegister,
307 pcmcia_access_configuration_register(link->handle, ®));
312 cs_error(link->handle, last_fn, last_ret);
318 * Scan PDR for the record with the specified RECORD_ID.
319 * If it's not found, return NULL.
322 spectrum_find_pdr(struct pdr *first_pdr, u32 record_id)
324 struct pdr *pdr = first_pdr;
326 while (pdr_id(pdr) != PDI_END) {
328 * PDR area is currently not terminated by PDI_END.
329 * It's followed by CRC records, which have the type
330 * field where PDR has length. The type can be 0 or 1.
332 if (pdr_len(pdr) < 2)
335 /* If the record ID matches, we are done */
336 if (pdr_id(pdr) == record_id)
339 pdr = (struct pdr *) pdr->next;
345 /* Process one Plug Data Item - find corresponding PDR and plug it */
347 spectrum_plug_pdi(hermes_t *hw, struct pdr *first_pdr, struct pdi *pdi)
351 /* Find the PDI corresponding to this PDR */
352 pdr = spectrum_find_pdr(first_pdr, pdi_id(pdi));
354 /* No match is found, safe to ignore */
358 /* Lengths of the data in PDI and PDR must match */
359 if (pdi_len(pdi) != pdr_len(pdr))
362 /* do the actual plugging */
363 spectrum_aux_setaddr(hw, pdr_addr(pdr));
364 hermes_write_words(hw, HERMES_AUXDATA, pdi->data,
371 /* Read PDA from the adapter */
373 spectrum_read_pda(hermes_t *hw, __le16 *pda, int pda_len)
378 /* Issue command to read EEPROM */
379 ret = hermes_docmd_wait(hw, HERMES_CMD_READMIF, 0, NULL);
383 /* Open auxiliary port */
384 ret = spectrum_aux_open(hw);
388 /* read PDA from EEPROM */
389 spectrum_aux_setaddr(hw, PDA_ADDR);
390 hermes_read_words(hw, HERMES_AUXDATA, pda, pda_len / 2);
392 /* Check PDA length */
393 pda_size = le16_to_cpu(pda[0]);
394 if (pda_size > pda_len)
401 /* Parse PDA and write the records into the adapter */
403 spectrum_apply_pda(hermes_t *hw, const struct dblock *first_block,
408 struct pdr *first_pdr;
409 const struct dblock *blk = first_block;
411 /* Skip all blocks to locate Plug Data References */
412 while (dblock_addr(blk) != BLOCK_END)
413 blk = (struct dblock *) &blk->data[dblock_len(blk)];
415 first_pdr = (struct pdr *) blk;
417 /* Go through every PDI and plug them into the adapter */
418 pdi = (struct pdi *) (pda + 2);
419 while (pdi_id(pdi) != PDI_END) {
420 ret = spectrum_plug_pdi(hw, first_pdr, pdi);
424 /* Increment to the next PDI */
425 pdi = (struct pdi *) &pdi->data[pdi_len(pdi)];
431 /* Load firmware blocks into the adapter */
433 spectrum_load_blocks(hermes_t *hw, const struct dblock *first_block)
435 const struct dblock *blk;
440 blkaddr = dblock_addr(blk);
441 blklen = dblock_len(blk);
443 while (dblock_addr(blk) != BLOCK_END) {
444 spectrum_aux_setaddr(hw, blkaddr);
445 hermes_write_words(hw, HERMES_AUXDATA, blk->data,
448 blk = (struct dblock *) &blk->data[blklen];
449 blkaddr = dblock_addr(blk);
450 blklen = dblock_len(blk);
457 * Process a firmware image - stop the card, load the firmware, reset
458 * the card and make sure it responds. For the secondary firmware take
459 * care of the PDA - read it and then write it on top of the firmware.
462 spectrum_dl_image(hermes_t *hw, dev_link_t *link,
463 const unsigned char *image)
466 const unsigned char *ptr;
467 const struct dblock *first_block;
469 /* Plug Data Area (PDA) */
470 __le16 pda[PDA_WORDS];
472 /* Binary block begins after the 0x1A marker */
474 while (*ptr++ != TEXT_END);
475 first_block = (const struct dblock *) ptr;
478 if (image != primsym) {
479 ret = spectrum_read_pda(hw, pda, sizeof(pda));
484 /* Stop the firmware, so that it can be safely rewritten */
485 ret = spectrum_reset(link, 1);
489 /* Program the adapter with new firmware */
490 ret = spectrum_load_blocks(hw, first_block);
494 /* Write the PDA to the adapter */
495 if (image != primsym) {
496 ret = spectrum_apply_pda(hw, first_block, pda);
501 /* Run the firmware */
502 ret = spectrum_reset(link, 0);
506 /* Reset hermes chip and make sure it responds */
507 ret = hermes_init(hw);
509 /* hermes_reset() should return 0 with the secondary firmware */
510 if (image != primsym && ret != 0)
513 /* And this should work with any firmware */
514 if (!hermes_present(hw))
522 * Download the firmware into the card, this also does a PCMCIA soft
523 * reset on the card, to make sure it's in a sane state.
526 spectrum_dl_firmware(hermes_t *hw, dev_link_t *link)
529 client_handle_t handle = link->handle;
530 const struct firmware *fw_entry;
532 if (request_firmware(&fw_entry, primary_fw_name,
533 &handle_to_dev(handle)) == 0) {
534 primsym = fw_entry->data;
536 printk(KERN_ERR PFX "Cannot find firmware: %s\n",
541 if (request_firmware(&fw_entry, secondary_fw_name,
542 &handle_to_dev(handle)) == 0) {
543 secsym = fw_entry->data;
545 printk(KERN_ERR PFX "Cannot find firmware: %s\n",
550 /* Load primary firmware */
551 ret = spectrum_dl_image(hw, link, primsym);
553 printk(KERN_ERR PFX "Primary firmware download failed\n");
557 /* Load secondary firmware */
558 ret = spectrum_dl_image(hw, link, secsym);
561 printk(KERN_ERR PFX "Secondary firmware download failed\n");
567 /********************************************************************/
569 /********************************************************************/
572 spectrum_cs_hard_reset(struct orinoco_private *priv)
574 struct orinoco_pccard *card = priv->card;
575 dev_link_t *link = &card->link;
578 if (!hermes_present(&priv->hw)) {
579 /* The firmware needs to be reloaded */
580 if (spectrum_dl_firmware(&priv->hw, &card->link) != 0) {
581 printk(KERN_ERR PFX "Firmware download failed\n");
585 /* Soft reset using COR and HCR */
586 spectrum_reset(link, 0);
592 /********************************************************************/
594 /********************************************************************/
597 * This creates an "instance" of the driver, allocating local data
598 * structures for one device. The device is registered with Card
601 * The dev_link structure is initialized, but we don't actually
602 * configure the card at this point -- we wait until we receive a card
603 * insertion event. */
605 spectrum_cs_attach(void)
607 struct net_device *dev;
608 struct orinoco_private *priv;
609 struct orinoco_pccard *card;
611 client_reg_t client_reg;
614 dev = alloc_orinocodev(sizeof(*card), spectrum_cs_hard_reset);
617 priv = netdev_priv(dev);
620 /* Link both structures together */
624 /* Interrupt setup */
625 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
626 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
627 link->irq.Handler = orinoco_interrupt;
628 link->irq.Instance = dev;
630 /* General socket configuration defaults can go here. In this
631 * client, we assume very little, and rely on the CIS for
632 * almost everything. In most clients, many details (i.e.,
633 * number, sizes, and attributes of IO windows) are fixed by
634 * the nature of the device, and can be hard-wired here. */
635 link->conf.Attributes = 0;
636 link->conf.IntType = INT_MEMORY_AND_IO;
638 /* Register with Card Services */
639 /* FIXME: need a lock? */
640 link->next = dev_list;
643 client_reg.dev_info = &dev_info;
644 client_reg.Version = 0x0210; /* FIXME: what does this mean? */
645 client_reg.event_callback_args.client_data = link;
647 ret = pcmcia_register_client(&link->handle, &client_reg);
648 if (ret != CS_SUCCESS) {
649 cs_error(link->handle, RegisterClient, ret);
650 spectrum_cs_detach(link);
655 } /* spectrum_cs_attach */
658 * This deletes a driver "instance". The device is de-registered with
659 * Card Services. If it has been released, all local data structures
660 * are freed. Otherwise, the structures will be freed when the device
663 static void spectrum_cs_detach(dev_link_t *link)
666 struct net_device *dev = link->priv;
668 /* Locate device structure */
669 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
673 BUG_ON(*linkp == NULL);
675 if (link->state & DEV_CONFIG)
676 spectrum_cs_release(link);
678 /* Break the link with Card Services */
680 pcmcia_deregister_client(link->handle);
682 /* Unlink device structure, and free it */
684 DEBUG(0, PFX "detach: link=%p link->dev=%p\n", link, link->dev);
686 DEBUG(0, PFX "About to unregister net device %p\n",
688 unregister_netdev(dev);
690 free_orinocodev(dev);
691 } /* spectrum_cs_detach */
694 * spectrum_cs_config() is scheduled to run after a CARD_INSERTION
695 * event is received, to configure the PCMCIA socket, and to make the
696 * device available to the system.
700 spectrum_cs_config(dev_link_t *link)
702 struct net_device *dev = link->priv;
703 client_handle_t handle = link->handle;
704 struct orinoco_private *priv = netdev_priv(dev);
705 struct orinoco_pccard *card = priv->card;
706 hermes_t *hw = &priv->hw;
707 int last_fn, last_ret;
715 CS_CHECK(ValidateCIS, pcmcia_validate_cis(handle, &info));
718 * This reads the card's CONFIG tuple to find its
719 * configuration registers.
721 tuple.DesiredTuple = CISTPL_CONFIG;
722 tuple.Attributes = 0;
723 tuple.TupleData = buf;
724 tuple.TupleDataMax = sizeof(buf);
725 tuple.TupleOffset = 0;
726 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
727 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
728 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
729 link->conf.ConfigBase = parse.config.base;
730 link->conf.Present = parse.config.rmask[0];
733 link->state |= DEV_CONFIG;
735 /* Look up the current Vcc */
736 CS_CHECK(GetConfigurationInfo,
737 pcmcia_get_configuration_info(handle, &conf));
738 link->conf.Vcc = conf.Vcc;
741 * In this loop, we scan the CIS for configuration table
742 * entries, each of which describes a valid card
743 * configuration, including voltage, IO window, memory window,
744 * and interrupt settings.
746 * We make no assumptions about the card to be configured: we
747 * use just the information available in the CIS. In an ideal
748 * world, this would work for any PCMCIA card, but it requires
749 * a complete and accurate CIS. In practice, a driver usually
750 * "knows" most of these things without consulting the CIS,
751 * and most client drivers will only use the CIS to fill in
752 * implementation-defined details.
754 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
755 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
757 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
758 cistpl_cftable_entry_t dflt = { .index = 0 };
760 if ( (pcmcia_get_tuple_data(handle, &tuple) != 0)
761 || (pcmcia_parse_tuple(handle, &tuple, &parse) != 0))
764 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
768 link->conf.ConfigIndex = cfg->index;
770 /* Does this card need audio output? */
771 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
772 link->conf.Attributes |= CONF_ENABLE_SPKR;
773 link->conf.Status = CCSR_AUDIO_ENA;
776 /* Use power settings for Vcc and Vpp if present */
777 /* Note that the CIS values need to be rescaled */
778 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
779 if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) {
780 DEBUG(2, "spectrum_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n", conf.Vcc, cfg->vcc.param[CISTPL_POWER_VNOM] / 10000);
784 } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
785 if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] / 10000) {
786 DEBUG(2, "spectrum_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n", conf.Vcc, dflt.vcc.param[CISTPL_POWER_VNOM] / 10000);
792 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
793 link->conf.Vpp1 = link->conf.Vpp2 =
794 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
795 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
796 link->conf.Vpp1 = link->conf.Vpp2 =
797 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
799 /* Do we need to allocate an interrupt? */
800 link->conf.Attributes |= CONF_ENABLE_IRQ;
802 /* IO window settings */
803 link->io.NumPorts1 = link->io.NumPorts2 = 0;
804 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
806 (cfg->io.nwin) ? &cfg->io : &dflt.io;
807 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
808 if (!(io->flags & CISTPL_IO_8BIT))
809 link->io.Attributes1 =
810 IO_DATA_PATH_WIDTH_16;
811 if (!(io->flags & CISTPL_IO_16BIT))
812 link->io.Attributes1 =
813 IO_DATA_PATH_WIDTH_8;
814 link->io.IOAddrLines =
815 io->flags & CISTPL_IO_LINES_MASK;
816 link->io.BasePort1 = io->win[0].base;
817 link->io.NumPorts1 = io->win[0].len;
819 link->io.Attributes2 =
820 link->io.Attributes1;
821 link->io.BasePort2 = io->win[1].base;
822 link->io.NumPorts2 = io->win[1].len;
825 /* This reserves IO space but doesn't actually enable it */
826 if (pcmcia_request_io(link->handle, &link->io) != 0)
831 /* If we got this far, we're cool! */
836 if (link->io.NumPorts1)
837 pcmcia_release_io(link->handle, &link->io);
838 last_ret = pcmcia_get_next_tuple(handle, &tuple);
839 if (last_ret == CS_NO_MORE_ITEMS) {
840 printk(KERN_ERR PFX "GetNextTuple(): No matching "
841 "CIS configuration. Maybe you need the "
842 "ignore_cis_vcc=1 parameter.\n");
848 * Allocate an interrupt line. Note that this does not assign
849 * a handler to the interrupt, unless the 'Handler' member of
850 * the irq structure is initialized.
852 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq));
854 /* We initialize the hermes structure before completing PCMCIA
855 * configuration just in case the interrupt handler gets
857 mem = ioport_map(link->io.BasePort1, link->io.NumPorts1);
861 hermes_struct_init(hw, mem, HERMES_16BIT_REGSPACING);
864 * This actually configures the PCMCIA socket -- setting up
865 * the I/O windows and the interrupt mapping, and putting the
866 * card and host interface into "Memory and IO" mode.
868 CS_CHECK(RequestConfiguration,
869 pcmcia_request_configuration(link->handle, &link->conf));
871 /* Ok, we have the configuration, prepare to register the netdev */
872 dev->base_addr = link->io.BasePort1;
873 dev->irq = link->irq.AssignedIRQ;
874 SET_MODULE_OWNER(dev);
875 card->node.major = card->node.minor = 0;
877 /* Reset card and download firmware */
878 if (spectrum_cs_hard_reset(priv) != 0) {
882 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
883 /* Tell the stack we exist */
884 if (register_netdev(dev) != 0) {
885 printk(KERN_ERR PFX "register_netdev() failed\n");
889 /* At this point, the dev_node_t structure(s) needs to be
890 * initialized and arranged in a linked list at link->dev. */
891 strcpy(card->node.dev_name, dev->name);
892 link->dev = &card->node; /* link->dev being non-NULL is also
893 used to indicate that the
894 net_device has been registered */
895 link->state &= ~DEV_CONFIG_PENDING;
897 /* Finally, report what we've done */
898 printk(KERN_DEBUG "%s: index 0x%02x: Vcc %d.%d",
899 dev->name, link->conf.ConfigIndex,
900 link->conf.Vcc / 10, link->conf.Vcc % 10);
902 printk(", Vpp %d.%d", link->conf.Vpp1 / 10,
903 link->conf.Vpp1 % 10);
904 printk(", irq %d", link->irq.AssignedIRQ);
905 if (link->io.NumPorts1)
906 printk(", io 0x%04x-0x%04x", link->io.BasePort1,
907 link->io.BasePort1 + link->io.NumPorts1 - 1);
908 if (link->io.NumPorts2)
909 printk(" & 0x%04x-0x%04x", link->io.BasePort2,
910 link->io.BasePort2 + link->io.NumPorts2 - 1);
916 cs_error(link->handle, last_fn, last_ret);
919 spectrum_cs_release(link);
920 } /* spectrum_cs_config */
923 * After a card is removed, spectrum_cs_release() will unregister the
924 * device, and release the PCMCIA configuration. If the device is
925 * still open, this will be postponed until it is closed.
928 spectrum_cs_release(dev_link_t *link)
930 struct net_device *dev = link->priv;
931 struct orinoco_private *priv = netdev_priv(dev);
934 /* We're committed to taking the device away now, so mark the
935 * hardware as unavailable */
936 spin_lock_irqsave(&priv->lock, flags);
937 priv->hw_unavailable++;
938 spin_unlock_irqrestore(&priv->lock, flags);
940 /* Don't bother checking to see if these succeed or not */
941 pcmcia_release_configuration(link->handle);
942 if (link->io.NumPorts1)
943 pcmcia_release_io(link->handle, &link->io);
944 if (link->irq.AssignedIRQ)
945 pcmcia_release_irq(link->handle, &link->irq);
946 link->state &= ~DEV_CONFIG;
948 ioport_unmap(priv->hw.iobase);
949 } /* spectrum_cs_release */
952 * The card status event handler. Mostly, this schedules other stuff
953 * to run after an event is received.
956 spectrum_cs_event(event_t event, int priority,
957 event_callback_args_t * args)
959 dev_link_t *link = args->client_data;
960 struct net_device *dev = link->priv;
961 struct orinoco_private *priv = netdev_priv(dev);
966 case CS_EVENT_CARD_REMOVAL:
967 link->state &= ~DEV_PRESENT;
968 if (link->state & DEV_CONFIG) {
971 spin_lock_irqsave(&priv->lock, flags);
972 netif_device_detach(dev);
973 priv->hw_unavailable++;
974 spin_unlock_irqrestore(&priv->lock, flags);
978 case CS_EVENT_CARD_INSERTION:
979 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
980 spectrum_cs_config(link);
983 case CS_EVENT_PM_SUSPEND:
984 link->state |= DEV_SUSPEND;
985 /* Fall through... */
986 case CS_EVENT_RESET_PHYSICAL:
987 /* Mark the device as stopped, to block IO until later */
988 if (link->state & DEV_CONFIG) {
989 /* This is probably racy, but I can't think of
990 a better way, short of rewriting the PCMCIA
991 layer to not suck :-( */
992 spin_lock_irqsave(&priv->lock, flags);
994 err = __orinoco_down(dev);
996 printk(KERN_WARNING "%s: %s: Error %d downing interface\n",
998 event == CS_EVENT_PM_SUSPEND ? "SUSPEND" : "RESET_PHYSICAL",
1001 netif_device_detach(dev);
1002 priv->hw_unavailable++;
1004 spin_unlock_irqrestore(&priv->lock, flags);
1006 pcmcia_release_configuration(link->handle);
1010 case CS_EVENT_PM_RESUME:
1011 link->state &= ~DEV_SUSPEND;
1012 /* Fall through... */
1013 case CS_EVENT_CARD_RESET:
1014 if (link->state & DEV_CONFIG) {
1015 /* FIXME: should we double check that this is
1016 * the same card as we had before */
1017 pcmcia_request_configuration(link->handle, &link->conf);
1018 netif_device_attach(dev);
1019 priv->hw_unavailable--;
1020 schedule_work(&priv->reset_work);
1026 } /* spectrum_cs_event */
1028 /********************************************************************/
1029 /* Module initialization */
1030 /********************************************************************/
1032 /* Can't be declared "const" or the whole __initdata section will
1034 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
1035 " (Pavel Roskin <proski@gnu.org>,"
1036 " David Gibson <hermes@gibson.dropbear.id.au>, et al)";
1038 static struct pcmcia_device_id spectrum_cs_ids[] = {
1039 PCMCIA_DEVICE_MANF_CARD(0x026c, 0x0001), /* Symbol Spectrum24 LA4100 */
1040 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0001), /* Socket Communications CF */
1041 PCMCIA_DEVICE_PROD_ID12("Intel", "PRO/Wireless LAN PC Card", 0x816cc815, 0x6fbf459a), /* 2011B, not 2011 */
1044 MODULE_DEVICE_TABLE(pcmcia, spectrum_cs_ids);
1046 static struct pcmcia_driver orinoco_driver = {
1047 .owner = THIS_MODULE,
1049 .name = DRIVER_NAME,
1051 .attach = spectrum_cs_attach,
1052 .detach = spectrum_cs_detach,
1053 .event = spectrum_cs_event,
1054 .id_table = spectrum_cs_ids,
1058 init_spectrum_cs(void)
1060 printk(KERN_DEBUG "%s\n", version);
1062 return pcmcia_register_driver(&orinoco_driver);
1066 exit_spectrum_cs(void)
1068 pcmcia_unregister_driver(&orinoco_driver);
1069 BUG_ON(dev_list != NULL);
1072 module_init(init_spectrum_cs);
1073 module_exit(exit_spectrum_cs);