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 #ifdef __IN_PCMCIA_PACKAGE__
26 #include <pcmcia/k_compat.h>
27 #endif /* __IN_PCMCIA_PACKAGE__ */
29 #include <linux/module.h>
30 #include <linux/kernel.h>
31 #include <linux/init.h>
32 #include <linux/sched.h>
33 #include <linux/ptrace.h>
34 #include <linux/slab.h>
35 #include <linux/string.h>
36 #include <linux/ioport.h>
37 #include <linux/netdevice.h>
38 #include <linux/if_arp.h>
39 #include <linux/etherdevice.h>
40 #include <linux/wireless.h>
42 #include <pcmcia/cs_types.h>
43 #include <pcmcia/cs.h>
44 #include <pcmcia/cistpl.h>
45 #include <pcmcia/cisreg.h>
46 #include <pcmcia/ds.h>
48 #include <asm/uaccess.h>
50 #include <asm/system.h>
55 * If SPECTRUM_FW_INCLUDED is defined, the firmware is hardcoded into
56 * the driver. Use get_symbol_fw script to generate spectrum_fw.h and
57 * copy it to the same directory as spectrum_cs.c.
59 * If SPECTRUM_FW_INCLUDED is not defined, the firmware is loaded at the
60 * runtime using hotplug. Use the same get_symbol_fw script to generate
61 * files symbol_sp24t_prim_fw symbol_sp24t_sec_fw, copy them to the
62 * hotplug firmware directory (typically /usr/lib/hotplug/firmware) and
63 * make sure that you have hotplug installed and enabled in the kernel.
65 /* #define SPECTRUM_FW_INCLUDED 1 */
67 #ifdef SPECTRUM_FW_INCLUDED
68 /* Header with the firmware */
69 #include "spectrum_fw.h"
70 #else /* !SPECTRUM_FW_INCLUDED */
71 #include <linux/firmware.h>
72 static unsigned char *primsym
;
73 static unsigned char *secsym
;
74 static const char primary_fw_name
[] = "symbol_sp24t_prim_fw";
75 static const char secondary_fw_name
[] = "symbol_sp24t_sec_fw";
76 #endif /* !SPECTRUM_FW_INCLUDED */
78 /********************************************************************/
80 /********************************************************************/
82 MODULE_AUTHOR("Pavel Roskin <proski@gnu.org>");
83 MODULE_DESCRIPTION("Driver for Symbol Spectrum24 Trilogy cards with firmware downloader");
84 MODULE_LICENSE("Dual MPL/GPL");
86 /* Module parameters */
88 /* Some D-Link cards have buggy CIS. They do work at 5v properly, but
89 * don't have any CIS entry for it. This workaround it... */
90 static int ignore_cis_vcc
; /* = 0 */
91 module_param(ignore_cis_vcc
, int, 0);
92 MODULE_PARM_DESC(ignore_cis_vcc
, "Allow voltage mismatch between card and socket");
94 /********************************************************************/
96 /********************************************************************/
99 * The dev_info variable is the "key" that is used to match up this
100 * device driver with appropriate cards, through the card
101 * configuration database.
103 static dev_info_t dev_info
= DRIVER_NAME
;
105 /********************************************************************/
106 /* Data structures */
107 /********************************************************************/
109 /* PCMCIA specific device information (goes in the card field of
110 * struct orinoco_private */
111 struct orinoco_pccard
{
117 * A linked list of "instances" of the device. Each actual PCMCIA
118 * card corresponds to one device instance, and is described by one
119 * dev_link_t structure (defined in ds.h).
121 static dev_link_t
*dev_list
; /* = NULL */
123 /********************************************************************/
124 /* Function prototypes */
125 /********************************************************************/
128 static int spectrum_cs_hard_reset(struct orinoco_private
*priv
);
131 static void spectrum_cs_config(dev_link_t
* link
);
132 static void spectrum_cs_release(dev_link_t
* link
);
133 static int spectrum_cs_event(event_t event
, int priority
,
134 event_callback_args_t
* args
);
136 static dev_link_t
*spectrum_cs_attach(void);
137 static void spectrum_cs_detach(dev_link_t
*);
139 /********************************************************************/
140 /* Firmware downloader */
141 /********************************************************************/
143 /* Position of PDA in the adapter memory */
144 #define EEPROM_ADDR 0x3000
145 #define EEPROM_LEN 0x200
146 #define PDA_OFFSET 0x100
148 #define PDA_ADDR (EEPROM_ADDR + PDA_OFFSET)
149 #define PDA_WORDS ((EEPROM_LEN - PDA_OFFSET) / 2)
151 /* Constants for the CISREG_CCSR register */
152 #define HCR_RUN 0x07 /* run firmware after reset */
153 #define HCR_IDLE 0x0E /* don't run firmware after reset */
154 #define HCR_MEM16 0x10 /* memory width bit, should be preserved */
157 * AUX port access. To unlock the AUX port write the access keys to the
158 * PARAM0-2 registers, then write HERMES_AUX_ENABLE to the HERMES_CONTROL
159 * register. Then read it and make sure it's HERMES_AUX_ENABLED.
161 #define HERMES_AUX_ENABLE 0x8000 /* Enable auxiliary port access */
162 #define HERMES_AUX_DISABLE 0x4000 /* Disable to auxiliary port access */
163 #define HERMES_AUX_ENABLED 0xC000 /* Auxiliary port is open */
165 #define HERMES_AUX_PW0 0xFE01
166 #define HERMES_AUX_PW1 0xDC23
167 #define HERMES_AUX_PW2 0xBA45
170 #define PDI_END 0x00000000 /* End of PDA */
171 #define BLOCK_END 0xFFFFFFFF /* Last image block */
172 #define TEXT_END 0x1A /* End of text header */
175 * The following structures have little-endian fields denoted by
176 * the leading underscore. Don't access them directly - use inline
177 * functions defined below.
181 * The binary image to be downloaded consists of series of data blocks.
182 * Each block has the following structure.
185 u32 _addr
; /* adapter address where to write the block */
186 u16 _len
; /* length of the data only, in bytes */
187 char data
[0]; /* data to be written */
188 } __attribute__ ((packed
));
191 * Plug Data References are located in in the image after the last data
192 * block. They refer to areas in the adapter memory where the plug data
193 * items with matching ID should be written.
196 u32 _id
; /* record ID */
197 u32 _addr
; /* adapter address where to write the data */
198 u32 _len
; /* expected length of the data, in bytes */
199 char next
[0]; /* next PDR starts here */
200 } __attribute__ ((packed
));
204 * Plug Data Items are located in the EEPROM read from the adapter by
205 * primary firmware. They refer to the device-specific data that should
206 * be plugged into the secondary firmware.
209 u16 _len
; /* length of ID and data, in words */
210 u16 _id
; /* record ID */
211 char data
[0]; /* plug data */
212 } __attribute__ ((packed
));;
215 /* Functions for access to little-endian data */
217 dblock_addr(const struct dblock
*blk
)
219 return le32_to_cpu(blk
->_addr
);
223 dblock_len(const struct dblock
*blk
)
225 return le16_to_cpu(blk
->_len
);
229 pdr_id(const struct pdr
*pdr
)
231 return le32_to_cpu(pdr
->_id
);
235 pdr_addr(const struct pdr
*pdr
)
237 return le32_to_cpu(pdr
->_addr
);
241 pdr_len(const struct pdr
*pdr
)
243 return le32_to_cpu(pdr
->_len
);
247 pdi_id(const struct pdi
*pdi
)
249 return le16_to_cpu(pdi
->_id
);
252 /* Return length of the data only, in bytes */
254 pdi_len(const struct pdi
*pdi
)
256 return 2 * (le16_to_cpu(pdi
->_len
) - 1);
260 /* Set address of the auxiliary port */
262 spectrum_aux_setaddr(hermes_t
*hw
, u32 addr
)
264 hermes_write_reg(hw
, HERMES_AUXPAGE
, (u16
) (addr
>> 7));
265 hermes_write_reg(hw
, HERMES_AUXOFFSET
, (u16
) (addr
& 0x7F));
269 /* Open access to the auxiliary port */
271 spectrum_aux_open(hermes_t
*hw
)
276 if (hermes_read_reg(hw
, HERMES_CONTROL
) == HERMES_AUX_ENABLED
)
279 hermes_write_reg(hw
, HERMES_PARAM0
, HERMES_AUX_PW0
);
280 hermes_write_reg(hw
, HERMES_PARAM1
, HERMES_AUX_PW1
);
281 hermes_write_reg(hw
, HERMES_PARAM2
, HERMES_AUX_PW2
);
282 hermes_write_reg(hw
, HERMES_CONTROL
, HERMES_AUX_ENABLE
);
284 for (i
= 0; i
< 20; i
++) {
286 if (hermes_read_reg(hw
, HERMES_CONTROL
) ==
295 #define CS_CHECK(fn, ret) \
296 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
299 * Reset the card using configuration registers COR and CCSR.
300 * If IDLE is 1, stop the firmware, so that it can be safely rewritten.
303 spectrum_reset(dev_link_t
*link
, int idle
)
305 int last_ret
, last_fn
;
309 /* Doing it if hardware is gone is guaranteed crash */
310 if (!(link
->state
& DEV_CONFIG
))
313 /* Save original COR value */
315 reg
.Action
= CS_READ
;
316 reg
.Offset
= CISREG_COR
;
317 CS_CHECK(AccessConfigurationRegister
,
318 pcmcia_access_configuration_register(link
->handle
, ®
));
319 save_cor
= reg
.Value
;
321 /* Soft-Reset card */
322 reg
.Action
= CS_WRITE
;
323 reg
.Offset
= CISREG_COR
;
324 reg
.Value
= (save_cor
| COR_SOFT_RESET
);
325 CS_CHECK(AccessConfigurationRegister
,
326 pcmcia_access_configuration_register(link
->handle
, ®
));
330 reg
.Action
= CS_READ
;
331 reg
.Offset
= CISREG_CCSR
;
332 CS_CHECK(AccessConfigurationRegister
,
333 pcmcia_access_configuration_register(link
->handle
, ®
));
336 * Start or stop the firmware. Memory width bit should be
337 * preserved from the value we've just read.
339 reg
.Action
= CS_WRITE
;
340 reg
.Offset
= CISREG_CCSR
;
341 reg
.Value
= (idle
? HCR_IDLE
: HCR_RUN
) | (reg
.Value
& HCR_MEM16
);
342 CS_CHECK(AccessConfigurationRegister
,
343 pcmcia_access_configuration_register(link
->handle
, ®
));
346 /* Restore original COR configuration index */
347 reg
.Action
= CS_WRITE
;
348 reg
.Offset
= CISREG_COR
;
349 reg
.Value
= (save_cor
& ~COR_SOFT_RESET
);
350 CS_CHECK(AccessConfigurationRegister
,
351 pcmcia_access_configuration_register(link
->handle
, ®
));
356 cs_error(link
->handle
, last_fn
, last_ret
);
362 * Scan PDR for the record with the specified RECORD_ID.
363 * If it's not found, return NULL.
366 spectrum_find_pdr(struct pdr
*first_pdr
, u32 record_id
)
368 struct pdr
*pdr
= first_pdr
;
370 while (pdr_id(pdr
) != PDI_END
) {
372 * PDR area is currently not terminated by PDI_END.
373 * It's followed by CRC records, which have the type
374 * field where PDR has length. The type can be 0 or 1.
376 if (pdr_len(pdr
) < 2)
379 /* If the record ID matches, we are done */
380 if (pdr_id(pdr
) == record_id
)
383 pdr
= (struct pdr
*) pdr
->next
;
389 /* Process one Plug Data Item - find corresponding PDR and plug it */
391 spectrum_plug_pdi(hermes_t
*hw
, struct pdr
*first_pdr
, struct pdi
*pdi
)
395 /* Find the PDI corresponding to this PDR */
396 pdr
= spectrum_find_pdr(first_pdr
, pdi_id(pdi
));
398 /* No match is found, safe to ignore */
402 /* Lengths of the data in PDI and PDR must match */
403 if (pdi_len(pdi
) != pdr_len(pdr
))
406 /* do the actual plugging */
407 spectrum_aux_setaddr(hw
, pdr_addr(pdr
));
408 hermes_write_words(hw
, HERMES_AUXDATA
, pdi
->data
,
415 /* Read PDA from the adapter */
417 spectrum_read_pda(hermes_t
*hw
, u16
*pda
, int pda_len
)
422 /* Issue command to read EEPROM */
423 ret
= hermes_docmd_wait(hw
, HERMES_CMD_READMIF
, 0, NULL
);
427 /* Open auxiliary port */
428 ret
= spectrum_aux_open(hw
);
432 /* read PDA from EEPROM */
433 spectrum_aux_setaddr(hw
, PDA_ADDR
);
434 hermes_read_words(hw
, HERMES_AUXDATA
, pda
, pda_len
/ 2);
436 /* Check PDA length */
437 pda_size
= le16_to_cpu(pda
[0]);
438 if (pda_size
> pda_len
)
445 /* Parse PDA and write the records into the adapter */
447 spectrum_apply_pda(hermes_t
*hw
, const struct dblock
*first_block
,
452 struct pdr
*first_pdr
;
453 const struct dblock
*blk
= first_block
;
455 /* Skip all blocks to locate Plug Data References */
456 while (dblock_addr(blk
) != BLOCK_END
)
457 blk
= (struct dblock
*) &blk
->data
[dblock_len(blk
)];
459 first_pdr
= (struct pdr
*) blk
;
461 /* Go through every PDI and plug them into the adapter */
462 pdi
= (struct pdi
*) (pda
+ 2);
463 while (pdi_id(pdi
) != PDI_END
) {
464 ret
= spectrum_plug_pdi(hw
, first_pdr
, pdi
);
468 /* Increment to the next PDI */
469 pdi
= (struct pdi
*) &pdi
->data
[pdi_len(pdi
)];
475 /* Load firmware blocks into the adapter */
477 spectrum_load_blocks(hermes_t
*hw
, const struct dblock
*first_block
)
479 const struct dblock
*blk
;
484 blkaddr
= dblock_addr(blk
);
485 blklen
= dblock_len(blk
);
487 while (dblock_addr(blk
) != BLOCK_END
) {
488 spectrum_aux_setaddr(hw
, blkaddr
);
489 hermes_write_words(hw
, HERMES_AUXDATA
, blk
->data
,
492 blk
= (struct dblock
*) &blk
->data
[blklen
];
493 blkaddr
= dblock_addr(blk
);
494 blklen
= dblock_len(blk
);
501 * Process a firmware image - stop the card, load the firmware, reset
502 * the card and make sure it responds. For the secondary firmware take
503 * care of the PDA - read it and then write it on top of the firmware.
506 spectrum_dl_image(hermes_t
*hw
, dev_link_t
*link
,
507 const unsigned char *image
)
510 const unsigned char *ptr
;
511 const struct dblock
*first_block
;
513 /* Plug Data Area (PDA) */
516 /* Binary block begins after the 0x1A marker */
518 while (*ptr
++ != TEXT_END
);
519 first_block
= (const struct dblock
*) ptr
;
522 if (image
!= primsym
) {
523 ret
= spectrum_read_pda(hw
, pda
, sizeof(pda
));
528 /* Stop the firmware, so that it can be safely rewritten */
529 ret
= spectrum_reset(link
, 1);
533 /* Program the adapter with new firmware */
534 ret
= spectrum_load_blocks(hw
, first_block
);
538 /* Write the PDA to the adapter */
539 if (image
!= primsym
) {
540 ret
= spectrum_apply_pda(hw
, first_block
, pda
);
545 /* Run the firmware */
546 ret
= spectrum_reset(link
, 0);
550 /* Reset hermes chip and make sure it responds */
551 ret
= hermes_init(hw
);
553 /* hermes_reset() should return 0 with the secondary firmware */
554 if (image
!= primsym
&& ret
!= 0)
557 /* And this should work with any firmware */
558 if (!hermes_present(hw
))
566 * Download the firmware into the card, this also does a PCMCIA soft
567 * reset on the card, to make sure it's in a sane state.
570 spectrum_dl_firmware(hermes_t
*hw
, dev_link_t
*link
)
573 client_handle_t handle
= link
->handle
;
575 #ifndef SPECTRUM_FW_INCLUDED
576 const struct firmware
*fw_entry
;
578 if (request_firmware(&fw_entry
, primary_fw_name
,
579 &handle_to_dev(handle
)) == 0) {
580 primsym
= fw_entry
->data
;
582 printk(KERN_ERR PFX
"Cannot find firmware: %s\n",
587 if (request_firmware(&fw_entry
, secondary_fw_name
,
588 &handle_to_dev(handle
)) == 0) {
589 secsym
= fw_entry
->data
;
591 printk(KERN_ERR PFX
"Cannot find firmware: %s\n",
597 /* Load primary firmware */
598 ret
= spectrum_dl_image(hw
, link
, primsym
);
600 printk(KERN_ERR PFX
"Primary firmware download failed\n");
604 /* Load secondary firmware */
605 ret
= spectrum_dl_image(hw
, link
, secsym
);
608 printk(KERN_ERR PFX
"Secondary firmware download failed\n");
614 /********************************************************************/
616 /********************************************************************/
619 spectrum_cs_hard_reset(struct orinoco_private
*priv
)
621 struct orinoco_pccard
*card
= priv
->card
;
622 dev_link_t
*link
= &card
->link
;
625 if (!hermes_present(&priv
->hw
)) {
626 /* The firmware needs to be reloaded */
627 if (spectrum_dl_firmware(&priv
->hw
, &card
->link
) != 0) {
628 printk(KERN_ERR PFX
"Firmware download failed\n");
632 /* Soft reset using COR and HCR */
633 spectrum_reset(link
, 0);
639 /********************************************************************/
641 /********************************************************************/
644 * This creates an "instance" of the driver, allocating local data
645 * structures for one device. The device is registered with Card
648 * The dev_link structure is initialized, but we don't actually
649 * configure the card at this point -- we wait until we receive a card
650 * insertion event. */
652 spectrum_cs_attach(void)
654 struct net_device
*dev
;
655 struct orinoco_private
*priv
;
656 struct orinoco_pccard
*card
;
658 client_reg_t client_reg
;
661 dev
= alloc_orinocodev(sizeof(*card
), spectrum_cs_hard_reset
);
664 priv
= netdev_priv(dev
);
667 /* Link both structures together */
671 /* Interrupt setup */
672 link
->irq
.Attributes
= IRQ_TYPE_EXCLUSIVE
| IRQ_HANDLE_PRESENT
;
673 link
->irq
.IRQInfo1
= IRQ_LEVEL_ID
;
674 link
->irq
.Handler
= orinoco_interrupt
;
675 link
->irq
.Instance
= dev
;
677 /* General socket configuration defaults can go here. In this
678 * client, we assume very little, and rely on the CIS for
679 * almost everything. In most clients, many details (i.e.,
680 * number, sizes, and attributes of IO windows) are fixed by
681 * the nature of the device, and can be hard-wired here. */
682 link
->conf
.Attributes
= 0;
683 link
->conf
.IntType
= INT_MEMORY_AND_IO
;
685 /* Register with Card Services */
686 /* FIXME: need a lock? */
687 link
->next
= dev_list
;
690 client_reg
.dev_info
= &dev_info
;
691 client_reg
.Version
= 0x0210; /* FIXME: what does this mean? */
692 client_reg
.event_callback_args
.client_data
= link
;
694 ret
= pcmcia_register_client(&link
->handle
, &client_reg
);
695 if (ret
!= CS_SUCCESS
) {
696 cs_error(link
->handle
, RegisterClient
, ret
);
697 spectrum_cs_detach(link
);
702 } /* spectrum_cs_attach */
705 * This deletes a driver "instance". The device is de-registered with
706 * Card Services. If it has been released, all local data structures
707 * are freed. Otherwise, the structures will be freed when the device
710 static void spectrum_cs_detach(dev_link_t
*link
)
713 struct net_device
*dev
= link
->priv
;
715 /* Locate device structure */
716 for (linkp
= &dev_list
; *linkp
; linkp
= &(*linkp
)->next
)
720 BUG_ON(*linkp
== NULL
);
722 if (link
->state
& DEV_CONFIG
)
723 spectrum_cs_release(link
);
725 /* Break the link with Card Services */
727 pcmcia_deregister_client(link
->handle
);
729 /* Unlink device structure, and free it */
731 DEBUG(0, PFX
"detach: link=%p link->dev=%p\n", link
, link
->dev
);
733 DEBUG(0, PFX
"About to unregister net device %p\n",
735 unregister_netdev(dev
);
737 free_orinocodev(dev
);
738 } /* spectrum_cs_detach */
741 * spectrum_cs_config() is scheduled to run after a CARD_INSERTION
742 * event is received, to configure the PCMCIA socket, and to make the
743 * device available to the system.
747 spectrum_cs_config(dev_link_t
*link
)
749 struct net_device
*dev
= link
->priv
;
750 client_handle_t handle
= link
->handle
;
751 struct orinoco_private
*priv
= netdev_priv(dev
);
752 struct orinoco_pccard
*card
= priv
->card
;
753 hermes_t
*hw
= &priv
->hw
;
754 int last_fn
, last_ret
;
762 CS_CHECK(ValidateCIS
, pcmcia_validate_cis(handle
, &info
));
765 * This reads the card's CONFIG tuple to find its
766 * configuration registers.
768 tuple
.DesiredTuple
= CISTPL_CONFIG
;
769 tuple
.Attributes
= 0;
770 tuple
.TupleData
= buf
;
771 tuple
.TupleDataMax
= sizeof(buf
);
772 tuple
.TupleOffset
= 0;
773 CS_CHECK(GetFirstTuple
, pcmcia_get_first_tuple(handle
, &tuple
));
774 CS_CHECK(GetTupleData
, pcmcia_get_tuple_data(handle
, &tuple
));
775 CS_CHECK(ParseTuple
, pcmcia_parse_tuple(handle
, &tuple
, &parse
));
776 link
->conf
.ConfigBase
= parse
.config
.base
;
777 link
->conf
.Present
= parse
.config
.rmask
[0];
780 link
->state
|= DEV_CONFIG
;
782 /* Look up the current Vcc */
783 CS_CHECK(GetConfigurationInfo
,
784 pcmcia_get_configuration_info(handle
, &conf
));
785 link
->conf
.Vcc
= conf
.Vcc
;
788 * In this loop, we scan the CIS for configuration table
789 * entries, each of which describes a valid card
790 * configuration, including voltage, IO window, memory window,
791 * and interrupt settings.
793 * We make no assumptions about the card to be configured: we
794 * use just the information available in the CIS. In an ideal
795 * world, this would work for any PCMCIA card, but it requires
796 * a complete and accurate CIS. In practice, a driver usually
797 * "knows" most of these things without consulting the CIS,
798 * and most client drivers will only use the CIS to fill in
799 * implementation-defined details.
801 tuple
.DesiredTuple
= CISTPL_CFTABLE_ENTRY
;
802 CS_CHECK(GetFirstTuple
, pcmcia_get_first_tuple(handle
, &tuple
));
804 cistpl_cftable_entry_t
*cfg
= &(parse
.cftable_entry
);
805 cistpl_cftable_entry_t dflt
= { .index
= 0 };
807 if ( (pcmcia_get_tuple_data(handle
, &tuple
) != 0)
808 || (pcmcia_parse_tuple(handle
, &tuple
, &parse
) != 0))
811 if (cfg
->flags
& CISTPL_CFTABLE_DEFAULT
)
815 link
->conf
.ConfigIndex
= cfg
->index
;
817 /* Does this card need audio output? */
818 if (cfg
->flags
& CISTPL_CFTABLE_AUDIO
) {
819 link
->conf
.Attributes
|= CONF_ENABLE_SPKR
;
820 link
->conf
.Status
= CCSR_AUDIO_ENA
;
823 /* Use power settings for Vcc and Vpp if present */
824 /* Note that the CIS values need to be rescaled */
825 if (cfg
->vcc
.present
& (1 << CISTPL_POWER_VNOM
)) {
826 if (conf
.Vcc
!= cfg
->vcc
.param
[CISTPL_POWER_VNOM
] / 10000) {
827 DEBUG(2, "spectrum_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n", conf
.Vcc
, cfg
->vcc
.param
[CISTPL_POWER_VNOM
] / 10000);
831 } else if (dflt
.vcc
.present
& (1 << CISTPL_POWER_VNOM
)) {
832 if (conf
.Vcc
!= dflt
.vcc
.param
[CISTPL_POWER_VNOM
] / 10000) {
833 DEBUG(2, "spectrum_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n", conf
.Vcc
, dflt
.vcc
.param
[CISTPL_POWER_VNOM
] / 10000);
839 if (cfg
->vpp1
.present
& (1 << CISTPL_POWER_VNOM
))
840 link
->conf
.Vpp1
= link
->conf
.Vpp2
=
841 cfg
->vpp1
.param
[CISTPL_POWER_VNOM
] / 10000;
842 else if (dflt
.vpp1
.present
& (1 << CISTPL_POWER_VNOM
))
843 link
->conf
.Vpp1
= link
->conf
.Vpp2
=
844 dflt
.vpp1
.param
[CISTPL_POWER_VNOM
] / 10000;
846 /* Do we need to allocate an interrupt? */
847 link
->conf
.Attributes
|= CONF_ENABLE_IRQ
;
849 /* IO window settings */
850 link
->io
.NumPorts1
= link
->io
.NumPorts2
= 0;
851 if ((cfg
->io
.nwin
> 0) || (dflt
.io
.nwin
> 0)) {
853 (cfg
->io
.nwin
) ? &cfg
->io
: &dflt
.io
;
854 link
->io
.Attributes1
= IO_DATA_PATH_WIDTH_AUTO
;
855 if (!(io
->flags
& CISTPL_IO_8BIT
))
856 link
->io
.Attributes1
=
857 IO_DATA_PATH_WIDTH_16
;
858 if (!(io
->flags
& CISTPL_IO_16BIT
))
859 link
->io
.Attributes1
=
860 IO_DATA_PATH_WIDTH_8
;
861 link
->io
.IOAddrLines
=
862 io
->flags
& CISTPL_IO_LINES_MASK
;
863 link
->io
.BasePort1
= io
->win
[0].base
;
864 link
->io
.NumPorts1
= io
->win
[0].len
;
866 link
->io
.Attributes2
=
867 link
->io
.Attributes1
;
868 link
->io
.BasePort2
= io
->win
[1].base
;
869 link
->io
.NumPorts2
= io
->win
[1].len
;
872 /* This reserves IO space but doesn't actually enable it */
873 if (pcmcia_request_io(link
->handle
, &link
->io
) != 0)
878 /* If we got this far, we're cool! */
883 if (link
->io
.NumPorts1
)
884 pcmcia_release_io(link
->handle
, &link
->io
);
885 last_ret
= pcmcia_get_next_tuple(handle
, &tuple
);
886 if (last_ret
== CS_NO_MORE_ITEMS
) {
887 printk(KERN_ERR PFX
"GetNextTuple(): No matching "
888 "CIS configuration. Maybe you need the "
889 "ignore_cis_vcc=1 parameter.\n");
895 * Allocate an interrupt line. Note that this does not assign
896 * a handler to the interrupt, unless the 'Handler' member of
897 * the irq structure is initialized.
899 CS_CHECK(RequestIRQ
, pcmcia_request_irq(link
->handle
, &link
->irq
));
901 /* We initialize the hermes structure before completing PCMCIA
902 * configuration just in case the interrupt handler gets
904 mem
= ioport_map(link
->io
.BasePort1
, link
->io
.NumPorts1
);
908 hermes_struct_init(hw
, mem
, HERMES_16BIT_REGSPACING
);
911 * This actually configures the PCMCIA socket -- setting up
912 * the I/O windows and the interrupt mapping, and putting the
913 * card and host interface into "Memory and IO" mode.
915 CS_CHECK(RequestConfiguration
,
916 pcmcia_request_configuration(link
->handle
, &link
->conf
));
918 /* Ok, we have the configuration, prepare to register the netdev */
919 dev
->base_addr
= link
->io
.BasePort1
;
920 dev
->irq
= link
->irq
.AssignedIRQ
;
921 SET_MODULE_OWNER(dev
);
922 card
->node
.major
= card
->node
.minor
= 0;
924 /* Reset card and download firmware */
925 if (spectrum_cs_hard_reset(priv
) != 0) {
929 SET_NETDEV_DEV(dev
, &handle_to_dev(handle
));
930 /* Tell the stack we exist */
931 if (register_netdev(dev
) != 0) {
932 printk(KERN_ERR PFX
"register_netdev() failed\n");
936 /* At this point, the dev_node_t structure(s) needs to be
937 * initialized and arranged in a linked list at link->dev. */
938 strcpy(card
->node
.dev_name
, dev
->name
);
939 link
->dev
= &card
->node
; /* link->dev being non-NULL is also
940 used to indicate that the
941 net_device has been registered */
942 link
->state
&= ~DEV_CONFIG_PENDING
;
944 /* Finally, report what we've done */
945 printk(KERN_DEBUG
"%s: index 0x%02x: Vcc %d.%d",
946 dev
->name
, link
->conf
.ConfigIndex
,
947 link
->conf
.Vcc
/ 10, link
->conf
.Vcc
% 10);
949 printk(", Vpp %d.%d", link
->conf
.Vpp1
/ 10,
950 link
->conf
.Vpp1
% 10);
951 printk(", irq %d", link
->irq
.AssignedIRQ
);
952 if (link
->io
.NumPorts1
)
953 printk(", io 0x%04x-0x%04x", link
->io
.BasePort1
,
954 link
->io
.BasePort1
+ link
->io
.NumPorts1
- 1);
955 if (link
->io
.NumPorts2
)
956 printk(" & 0x%04x-0x%04x", link
->io
.BasePort2
,
957 link
->io
.BasePort2
+ link
->io
.NumPorts2
- 1);
963 cs_error(link
->handle
, last_fn
, last_ret
);
966 spectrum_cs_release(link
);
967 } /* spectrum_cs_config */
970 * After a card is removed, spectrum_cs_release() will unregister the
971 * device, and release the PCMCIA configuration. If the device is
972 * still open, this will be postponed until it is closed.
975 spectrum_cs_release(dev_link_t
*link
)
977 struct net_device
*dev
= link
->priv
;
978 struct orinoco_private
*priv
= netdev_priv(dev
);
981 /* We're committed to taking the device away now, so mark the
982 * hardware as unavailable */
983 spin_lock_irqsave(&priv
->lock
, flags
);
984 priv
->hw_unavailable
++;
985 spin_unlock_irqrestore(&priv
->lock
, flags
);
987 /* Don't bother checking to see if these succeed or not */
988 pcmcia_release_configuration(link
->handle
);
989 if (link
->io
.NumPorts1
)
990 pcmcia_release_io(link
->handle
, &link
->io
);
991 if (link
->irq
.AssignedIRQ
)
992 pcmcia_release_irq(link
->handle
, &link
->irq
);
993 link
->state
&= ~DEV_CONFIG
;
995 ioport_unmap(priv
->hw
.iobase
);
996 } /* spectrum_cs_release */
999 * The card status event handler. Mostly, this schedules other stuff
1000 * to run after an event is received.
1003 spectrum_cs_event(event_t event
, int priority
,
1004 event_callback_args_t
* args
)
1006 dev_link_t
*link
= args
->client_data
;
1007 struct net_device
*dev
= link
->priv
;
1008 struct orinoco_private
*priv
= netdev_priv(dev
);
1010 unsigned long flags
;
1013 case CS_EVENT_CARD_REMOVAL
:
1014 link
->state
&= ~DEV_PRESENT
;
1015 if (link
->state
& DEV_CONFIG
) {
1016 unsigned long flags
;
1018 spin_lock_irqsave(&priv
->lock
, flags
);
1019 netif_device_detach(dev
);
1020 priv
->hw_unavailable
++;
1021 spin_unlock_irqrestore(&priv
->lock
, flags
);
1025 case CS_EVENT_CARD_INSERTION
:
1026 link
->state
|= DEV_PRESENT
| DEV_CONFIG_PENDING
;
1027 spectrum_cs_config(link
);
1030 case CS_EVENT_PM_SUSPEND
:
1031 link
->state
|= DEV_SUSPEND
;
1032 /* Fall through... */
1033 case CS_EVENT_RESET_PHYSICAL
:
1034 /* Mark the device as stopped, to block IO until later */
1035 if (link
->state
& DEV_CONFIG
) {
1036 /* This is probably racy, but I can't think of
1037 a better way, short of rewriting the PCMCIA
1038 layer to not suck :-( */
1039 spin_lock_irqsave(&priv
->lock
, flags
);
1041 err
= __orinoco_down(dev
);
1043 printk(KERN_WARNING
"%s: %s: Error %d downing interface\n",
1045 event
== CS_EVENT_PM_SUSPEND
? "SUSPEND" : "RESET_PHYSICAL",
1048 netif_device_detach(dev
);
1049 priv
->hw_unavailable
++;
1051 spin_unlock_irqrestore(&priv
->lock
, flags
);
1053 pcmcia_release_configuration(link
->handle
);
1057 case CS_EVENT_PM_RESUME
:
1058 link
->state
&= ~DEV_SUSPEND
;
1059 /* Fall through... */
1060 case CS_EVENT_CARD_RESET
:
1061 if (link
->state
& DEV_CONFIG
) {
1062 /* FIXME: should we double check that this is
1063 * the same card as we had before */
1064 pcmcia_request_configuration(link
->handle
, &link
->conf
);
1065 netif_device_attach(dev
);
1066 priv
->hw_unavailable
--;
1067 schedule_work(&priv
->reset_work
);
1073 } /* spectrum_cs_event */
1075 /********************************************************************/
1076 /* Module initialization */
1077 /********************************************************************/
1079 /* Can't be declared "const" or the whole __initdata section will
1081 static char version
[] __initdata
= DRIVER_NAME
" " DRIVER_VERSION
1082 " (Pavel Roskin <proski@gnu.org>,"
1083 " David Gibson <hermes@gibson.dropbear.id.au>, et al)";
1085 static struct pcmcia_device_id spectrum_cs_ids
[] = {
1086 PCMCIA_DEVICE_MANF_CARD(0x026c, 0x0001), /* Symbol Spectrum24 LA4100 */
1087 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0001), /* Socket Communications CF */
1088 PCMCIA_DEVICE_MANF_CARD(0x0089, 0x0001), /* Intel PRO/Wireless 2011B */
1091 MODULE_DEVICE_TABLE(pcmcia
, spectrum_cs_ids
);
1093 static struct pcmcia_driver orinoco_driver
= {
1094 .owner
= THIS_MODULE
,
1096 .name
= DRIVER_NAME
,
1098 .attach
= spectrum_cs_attach
,
1099 .event
= spectrum_cs_event
,
1100 .detach
= spectrum_cs_detach
,
1101 .id_table
= spectrum_cs_ids
,
1105 init_spectrum_cs(void)
1107 printk(KERN_DEBUG
"%s\n", version
);
1109 return pcmcia_register_driver(&orinoco_driver
);
1113 exit_spectrum_cs(void)
1115 pcmcia_unregister_driver(&orinoco_driver
);
1116 BUG_ON(dev_list
!= NULL
);
1119 module_init(init_spectrum_cs
);
1120 module_exit(exit_spectrum_cs
);