diff options
| author | Pavel Roskin <proski@gnu.org> | 2005-09-01 20:10:06 -0400 |
|---|---|---|
| committer | Jeff Garzik <jgarzik@pobox.com> | 2005-09-05 18:14:08 -0400 |
| commit | 3a48c4c2d52a08e12319ab7caacad0a9b88e6cb4 (patch) | |
| tree | 035dffa590835d9a1c998b7984d958a68f08bec4 /drivers | |
| parent | ec82905177a22b0fe0abaf4ecb76813d3d45d16e (diff) | |
[PATCH] orinoco: New driver - spectrum_cs.
Signed-off-by: Pavel Roskin <proski@gnu.org>
diff-tree dee4f325520d4ea29397dd67ca657b7235bb1790 (from c88faac230cc9775445e5c644991c352e35c72a1)
Author: Pavel Roskin <proski@gnu.org>
Date: Thu Sep 1 17:46:39 2005 -0400
New driver - spectrum_cs.
Driver for 802.11b cards using RAM-loadable Symbol firmware, such as
Symbol Wireless Networker LA4100, CompactFlash cards by Socket
Communications and Intel PRO/Wireless 2011B.
The driver implements Symbol firmware download. The rest is handled
in hermes.c and orinoco.c.
Utilities for downloading the Symbol firmware are available at
http://sourceforge.net/projects/orinoco/
Signed-off-by: Jeff Garzik <jgarzik@pobox.com>
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/net/wireless/Kconfig | 13 | ||||
| -rw-r--r-- | drivers/net/wireless/Makefile | 1 | ||||
| -rw-r--r-- | drivers/net/wireless/spectrum_cs.c | 1120 |
3 files changed, 1134 insertions, 0 deletions
diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig index ae7c876d6475..00a07f32a81e 100644 --- a/drivers/net/wireless/Kconfig +++ b/drivers/net/wireless/Kconfig | |||
| @@ -375,6 +375,19 @@ config PCMCIA_HERMES | |||
| 375 | configure your card and that /etc/pcmcia/wireless.opts works: | 375 | configure your card and that /etc/pcmcia/wireless.opts works: |
| 376 | <http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html>. | 376 | <http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html>. |
| 377 | 377 | ||
| 378 | config PCMCIA_SPECTRUM | ||
| 379 | tristate "Symbol Spectrum24 Trilogy PCMCIA card support" | ||
| 380 | depends on NET_RADIO && PCMCIA && HERMES | ||
| 381 | ---help--- | ||
| 382 | |||
| 383 | This is a driver for 802.11b cards using RAM-loadable Symbol | ||
| 384 | firmware, such as Symbol Wireless Networker LA4100, CompactFlash | ||
| 385 | cards by Socket Communications and Intel PRO/Wireless 2011B. | ||
| 386 | |||
| 387 | This driver requires firmware download on startup. Utilities | ||
| 388 | for downloading Symbol firmware are available at | ||
| 389 | <http://sourceforge.net/projects/orinoco/> | ||
| 390 | |||
| 378 | config AIRO_CS | 391 | config AIRO_CS |
| 379 | tristate "Cisco/Aironet 34X/35X/4500/4800 PCMCIA cards" | 392 | tristate "Cisco/Aironet 34X/35X/4500/4800 PCMCIA cards" |
| 380 | depends on NET_RADIO && PCMCIA && (BROKEN || !M32R) | 393 | depends on NET_RADIO && PCMCIA && (BROKEN || !M32R) |
diff --git a/drivers/net/wireless/Makefile b/drivers/net/wireless/Makefile index d2c8ccc21467..3a6f7ba326ca 100644 --- a/drivers/net/wireless/Makefile +++ b/drivers/net/wireless/Makefile | |||
| @@ -23,6 +23,7 @@ obj-$(CONFIG_PLX_HERMES) += orinoco_plx.o | |||
| 23 | obj-$(CONFIG_PCI_HERMES) += orinoco_pci.o | 23 | obj-$(CONFIG_PCI_HERMES) += orinoco_pci.o |
| 24 | obj-$(CONFIG_TMD_HERMES) += orinoco_tmd.o | 24 | obj-$(CONFIG_TMD_HERMES) += orinoco_tmd.o |
| 25 | obj-$(CONFIG_NORTEL_HERMES) += orinoco_nortel.o | 25 | obj-$(CONFIG_NORTEL_HERMES) += orinoco_nortel.o |
| 26 | obj-$(CONFIG_PCMCIA_SPECTRUM) += spectrum_cs.o | ||
| 26 | 27 | ||
| 27 | obj-$(CONFIG_AIRO) += airo.o | 28 | obj-$(CONFIG_AIRO) += airo.o |
| 28 | obj-$(CONFIG_AIRO_CS) += airo_cs.o airo.o | 29 | obj-$(CONFIG_AIRO_CS) += airo_cs.o airo.o |
diff --git a/drivers/net/wireless/spectrum_cs.c b/drivers/net/wireless/spectrum_cs.c new file mode 100644 index 000000000000..39c6cdf7f3f7 --- /dev/null +++ b/drivers/net/wireless/spectrum_cs.c | |||
| @@ -0,0 +1,1120 @@ | |||
| 1 | /* | ||
| 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. | ||
| 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/config.h> | ||
| 25 | #ifdef __IN_PCMCIA_PACKAGE__ | ||
| 26 | #include <pcmcia/k_compat.h> | ||
| 27 | #endif /* __IN_PCMCIA_PACKAGE__ */ | ||
| 28 | |||
| 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> | ||
| 41 | |||
| 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> | ||
| 47 | |||
| 48 | #include <asm/uaccess.h> | ||
| 49 | #include <asm/io.h> | ||
| 50 | #include <asm/system.h> | ||
| 51 | |||
| 52 | #include "orinoco.h" | ||
| 53 | |||
| 54 | /* | ||
| 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. | ||
| 58 | * | ||
| 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. | ||
| 64 | */ | ||
| 65 | /* #define SPECTRUM_FW_INCLUDED 1 */ | ||
| 66 | |||
| 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 */ | ||
| 77 | |||
| 78 | /********************************************************************/ | ||
| 79 | /* Module stuff */ | ||
| 80 | /********************************************************************/ | ||
| 81 | |||
| 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"); | ||
| 85 | |||
| 86 | /* Module parameters */ | ||
| 87 | |||
| 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"); | ||
| 93 | |||
| 94 | /********************************************************************/ | ||
| 95 | /* Magic constants */ | ||
| 96 | /********************************************************************/ | ||
| 97 | |||
| 98 | /* | ||
| 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. | ||
| 102 | */ | ||
| 103 | static dev_info_t dev_info = DRIVER_NAME; | ||
| 104 | |||
| 105 | /********************************************************************/ | ||
| 106 | /* Data structures */ | ||
| 107 | /********************************************************************/ | ||
| 108 | |||
| 109 | /* PCMCIA specific device information (goes in the card field of | ||
| 110 | * struct orinoco_private */ | ||
| 111 | struct orinoco_pccard { | ||
| 112 | dev_link_t link; | ||
| 113 | dev_node_t node; | ||
| 114 | }; | ||
| 115 | |||
| 116 | /* | ||
| 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). | ||
| 120 | */ | ||
| 121 | static dev_link_t *dev_list; /* = NULL */ | ||
| 122 | |||
| 123 | /********************************************************************/ | ||
| 124 | /* Function prototypes */ | ||
| 125 | /********************************************************************/ | ||
| 126 | |||
| 127 | /* device methods */ | ||
| 128 | static int spectrum_cs_hard_reset(struct orinoco_private *priv); | ||
| 129 | |||
| 130 | /* PCMCIA gumpf */ | ||
| 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); | ||
| 135 | |||
| 136 | static dev_link_t *spectrum_cs_attach(void); | ||
| 137 | static void spectrum_cs_detach(dev_link_t *); | ||
| 138 | |||
| 139 | /********************************************************************/ | ||
| 140 | /* Firmware downloader */ | ||
| 141 | /********************************************************************/ | ||
| 142 | |||
| 143 | /* Position of PDA in the adapter memory */ | ||
| 144 | #define EEPROM_ADDR 0x3000 | ||
| 145 | #define EEPROM_LEN 0x200 | ||
| 146 | #define PDA_OFFSET 0x100 | ||
| 147 | |||
| 148 | #define PDA_ADDR (EEPROM_ADDR + PDA_OFFSET) | ||
| 149 | #define PDA_WORDS ((EEPROM_LEN - PDA_OFFSET) / 2) | ||
| 150 | |||
| 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 */ | ||
| 155 | |||
| 156 | /* | ||
| 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. | ||
| 160 | */ | ||
| 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 */ | ||
| 164 | |||
| 165 | #define HERMES_AUX_PW0 0xFE01 | ||
| 166 | #define HERMES_AUX_PW1 0xDC23 | ||
| 167 | #define HERMES_AUX_PW2 0xBA45 | ||
| 168 | |||
| 169 | /* End markers */ | ||
| 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 */ | ||
| 173 | |||
| 174 | /* | ||
| 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. | ||
| 178 | */ | ||
| 179 | |||
| 180 | /* | ||
| 181 | * The binary image to be downloaded consists of series of data blocks. | ||
| 182 | * Each block has the following structure. | ||
| 183 | */ | ||
| 184 | struct dblock { | ||
| 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)); | ||
| 189 | |||
| 190 | /* | ||
| 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. | ||
| 194 | */ | ||
| 195 | struct pdr { | ||
| 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)); | ||
| 201 | |||
| 202 | |||
| 203 | /* | ||
| 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. | ||
| 207 | */ | ||
| 208 | struct pdi { | ||
| 209 | u16 _len; /* length of ID and data, in words */ | ||
| 210 | u16 _id; /* record ID */ | ||
| 211 | char data[0]; /* plug data */ | ||
| 212 | } __attribute__ ((packed));; | ||
| 213 | |||
| 214 | |||
| 215 | /* Functions for access to little-endian data */ | ||
| 216 | static inline u32 | ||
| 217 | dblock_addr(const struct dblock *blk) | ||
| 218 | { | ||
| 219 | return le32_to_cpu(blk->_addr); | ||
| 220 | } | ||
| 221 | |||
| 222 | static inline u32 | ||
| 223 | dblock_len(const struct dblock *blk) | ||
| 224 | { | ||
| 225 | return le16_to_cpu(blk->_len); | ||
| 226 | } | ||
| 227 | |||
| 228 | static inline u32 | ||
| 229 | pdr_id(const struct pdr *pdr) | ||
| 230 | { | ||
| 231 | return le32_to_cpu(pdr->_id); | ||
| 232 | } | ||
| 233 | |||
| 234 | static inline u32 | ||
| 235 | pdr_addr(const struct pdr *pdr) | ||
| 236 | { | ||
| 237 | return le32_to_cpu(pdr->_addr); | ||
| 238 | } | ||
| 239 | |||
| 240 | static inline u32 | ||
| 241 | pdr_len(const struct pdr *pdr) | ||
| 242 | { | ||
| 243 | return le32_to_cpu(pdr->_len); | ||
| 244 | } | ||
| 245 | |||
| 246 | static inline u32 | ||
| 247 | pdi_id(const struct pdi *pdi) | ||
| 248 | { | ||
| 249 | return le16_to_cpu(pdi->_id); | ||
| 250 | } | ||
| 251 | |||
| 252 | /* Return length of the data only, in bytes */ | ||
| 253 | static inline u32 | ||
| 254 | pdi_len(const struct pdi *pdi) | ||
| 255 | { | ||
| 256 | return 2 * (le16_to_cpu(pdi->_len) - 1); | ||
| 257 | } | ||
| 258 | |||
| 259 | |||
| 260 | /* Set address of the auxiliary port */ | ||
| 261 | static inline void | ||
| 262 | spectrum_aux_setaddr(hermes_t *hw, u32 addr) | ||
| 263 | { | ||
| 264 | hermes_write_reg(hw, HERMES_AUXPAGE, (u16) (addr >> 7)); | ||
| 265 | hermes_write_reg(hw, HERMES_AUXOFFSET, (u16) (addr & 0x7F)); | ||
| 266 | } | ||
| 267 | |||
| 268 | |||
| 269 | /* Open access to the auxiliary port */ | ||
| 270 | static int | ||
| 271 | spectrum_aux_open(hermes_t *hw) | ||
| 272 | { | ||
| 273 | int i; | ||
| 274 | |||
| 275 | /* Already open? */ | ||
| 276 | if (hermes_read_reg(hw, HERMES_CONTROL) == HERMES_AUX_ENABLED) | ||
| 277 | return 0; | ||
| 278 | |||
| 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); | ||
| 283 | |||
| 284 | for (i = 0; i < 20; i++) { | ||
| 285 | udelay(10); | ||
| 286 | if (hermes_read_reg(hw, HERMES_CONTROL) == | ||
| 287 | HERMES_AUX_ENABLED) | ||
| 288 | return 0; | ||
| 289 | } | ||
| 290 | |||
| 291 | return -EBUSY; | ||
| 292 | } | ||
| 293 | |||
| 294 | |||
| 295 | #define CS_CHECK(fn, ret) \ | ||
| 296 | do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) | ||
| 297 | |||
| 298 | /* | ||
| 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. | ||
| 301 | */ | ||
| 302 | static int | ||
| 303 | spectrum_reset(dev_link_t *link, int idle) | ||
| 304 | { | ||
| 305 | int last_ret, last_fn; | ||
| 306 | conf_reg_t reg; | ||
| 307 | u_int save_cor; | ||
| 308 | |||
| 309 | /* Doing it if hardware is gone is guaranteed crash */ | ||
| 310 | if (!(link->state & DEV_CONFIG)) | ||
| 311 | return -ENODEV; | ||
| 312 | |||
| 313 | /* Save original COR value */ | ||
| 314 | reg.Function = 0; | ||
| 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; | ||
| 320 | |||
| 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, ®)); | ||
| 327 | udelay(1000); | ||
| 328 | |||
| 329 | /* Read CCSR */ | ||
| 330 | reg.Action = CS_READ; | ||
| 331 | reg.Offset = CISREG_CCSR; | ||
| 332 | CS_CHECK(AccessConfigurationRegister, | ||
| 333 | pcmcia_access_configuration_register(link->handle, ®)); | ||
| 334 | |||
| 335 | /* | ||
| 336 | * Start or stop the firmware. Memory width bit should be | ||
| 337 | * preserved from the value we've just read. | ||
| 338 | */ | ||
| 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, ®)); | ||
| 344 | udelay(1000); | ||
| 345 | |||
| 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, ®)); | ||
| 352 | udelay(1000); | ||
| 353 | return 0; | ||
| 354 | |||
| 355 | cs_failed: | ||
| 356 | cs_error(link->handle, last_fn, last_ret); | ||
| 357 | return -ENODEV; | ||
| 358 | } | ||
| 359 | |||
| 360 | |||
| 361 | /* | ||
| 362 | * Scan PDR for the record with the specified RECORD_ID. | ||
| 363 | * If it's not found, return NULL. | ||
| 364 | */ | ||
| 365 | static struct pdr * | ||
| 366 | spectrum_find_pdr(struct pdr *first_pdr, u32 record_id) | ||
| 367 | { | ||
| 368 | struct pdr *pdr = first_pdr; | ||
| 369 | |||
| 370 | while (pdr_id(pdr) != PDI_END) { | ||
| 371 | /* | ||
| 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. | ||
| 375 | */ | ||
| 376 | if (pdr_len(pdr) < 2) | ||
| 377 | return NULL; | ||
| 378 | |||
| 379 | /* If the record ID matches, we are done */ | ||
| 380 | if (pdr_id(pdr) == record_id) | ||
| 381 | return pdr; | ||
| 382 | |||
| 383 | pdr = (struct pdr *) pdr->next; | ||
| 384 | } | ||
| 385 | return NULL; | ||
| 386 | } | ||
| 387 | |||
| 388 | |||
| 389 | /* Process one Plug Data Item - find corresponding PDR and plug it */ | ||
| 390 | static int | ||
| 391 | spectrum_plug_pdi(hermes_t *hw, struct pdr *first_pdr, struct pdi *pdi) | ||
| 392 | { | ||
| 393 | struct pdr *pdr; | ||
| 394 | |||
| 395 | /* Find the PDI corresponding to this PDR */ | ||
| 396 | pdr = spectrum_find_pdr(first_pdr, pdi_id(pdi)); | ||
| 397 | |||
| 398 | /* No match is found, safe to ignore */ | ||
| 399 | if (!pdr) | ||
| 400 | return 0; | ||
| 401 | |||
| 402 | /* Lengths of the data in PDI and PDR must match */ | ||
| 403 | if (pdi_len(pdi) != pdr_len(pdr)) | ||
| 404 | return -EINVAL; | ||
| 405 | |||
| 406 | /* do the actual plugging */ | ||
| 407 | spectrum_aux_setaddr(hw, pdr_addr(pdr)); | ||
| 408 | hermes_write_words(hw, HERMES_AUXDATA, pdi->data, | ||
| 409 | pdi_len(pdi) / 2); | ||
| 410 | |||
| 411 | return 0; | ||
| 412 | } | ||
| 413 | |||
| 414 | |||
| 415 | /* Read PDA from the adapter */ | ||
| 416 | static int | ||
| 417 | spectrum_read_pda(hermes_t *hw, u16 *pda, int pda_len) | ||
| 418 | { | ||
| 419 | int ret; | ||
| 420 | int pda_size; | ||
| 421 | |||
| 422 | /* Issue command to read EEPROM */ | ||
| 423 | ret = hermes_docmd_wait(hw, HERMES_CMD_READMIF, 0, NULL); | ||
| 424 | if (ret) | ||
| 425 | return ret; | ||
| 426 | |||
| 427 | /* Open auxiliary port */ | ||
| 428 | ret = spectrum_aux_open(hw); | ||
| 429 | if (ret) | ||
| 430 | return ret; | ||
| 431 | |||
| 432 | /* read PDA from EEPROM */ | ||
| 433 | spectrum_aux_setaddr(hw, PDA_ADDR); | ||
| 434 | hermes_read_words(hw, HERMES_AUXDATA, pda, pda_len / 2); | ||
| 435 | |||
| 436 | /* Check PDA length */ | ||
| 437 | pda_size = le16_to_cpu(pda[0]); | ||
| 438 | if (pda_size > pda_len) | ||
| 439 | return -EINVAL; | ||
| 440 | |||
| 441 | return 0; | ||
| 442 | } | ||
| 443 | |||
| 444 | |||
| 445 | /* Parse PDA and write the records into the adapter */ | ||
| 446 | static int | ||
| 447 | spectrum_apply_pda(hermes_t *hw, const struct dblock *first_block, | ||
| 448 | u16 *pda) | ||
| 449 | { | ||
| 450 | int ret; | ||
| 451 | struct pdi *pdi; | ||
| 452 | struct pdr *first_pdr; | ||
| 453 | const struct dblock *blk = first_block; | ||
| 454 | |||
| 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)]; | ||
| 458 | |||
| 459 | first_pdr = (struct pdr *) blk; | ||
| 460 | |||
| 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); | ||
| 465 | if (ret) | ||
| 466 | return ret; | ||
| 467 | |||
| 468 | /* Increment to the next PDI */ | ||
| 469 | pdi = (struct pdi *) &pdi->data[pdi_len(pdi)]; | ||
| 470 | } | ||
| 471 | return 0; | ||
| 472 | } | ||
| 473 | |||
| 474 | |||
| 475 | /* Load firmware blocks into the adapter */ | ||
| 476 | static int | ||
| 477 | spectrum_load_blocks(hermes_t *hw, const struct dblock *first_block) | ||
| 478 | { | ||
| 479 | const struct dblock *blk; | ||
| 480 | u32 blkaddr; | ||
| 481 | u32 blklen; | ||
| 482 | |||
| 483 | blk = first_block; | ||
| 484 | blkaddr = dblock_addr(blk); | ||
| 485 | blklen = dblock_len(blk); | ||
| 486 | |||
| 487 | while (dblock_addr(blk) != BLOCK_END) { | ||
| 488 | spectrum_aux_setaddr(hw, blkaddr); | ||
| 489 | hermes_write_words(hw, HERMES_AUXDATA, blk->data, | ||
| 490 | blklen / 2); | ||
| 491 | |||
| 492 | blk = (struct dblock *) &blk->data[blklen]; | ||
| 493 | blkaddr = dblock_addr(blk); | ||
| 494 | blklen = dblock_len(blk); | ||
| 495 | } | ||
| 496 | return 0; | ||
| 497 | } | ||
| 498 | |||
| 499 | |||
| 500 | /* | ||
| 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. | ||
| 504 | */ | ||
| 505 | static int | ||
| 506 | spectrum_dl_image(hermes_t *hw, dev_link_t *link, | ||
| 507 | const unsigned char *image) | ||
| 508 | { | ||
| 509 | int ret; | ||
| 510 | const unsigned char *ptr; | ||
| 511 | const struct dblock *first_block; | ||
| 512 | |||
| 513 | /* Plug Data Area (PDA) */ | ||
| 514 | u16 pda[PDA_WORDS]; | ||
| 515 | |||
| 516 | /* Binary block begins after the 0x1A marker */ | ||
| 517 | ptr = image; | ||
| 518 | while (*ptr++ != TEXT_END); | ||
| 519 | first_block = (const struct dblock *) ptr; | ||
| 520 | |||
| 521 | /* Read the PDA */ | ||
| 522 | if (image != primsym) { | ||
| 523 | ret = spectrum_read_pda(hw, pda, sizeof(pda)); | ||
| 524 | if (ret) | ||
| 525 | return ret; | ||
| 526 | } | ||
| 527 | |||
| 528 | /* Stop the firmware, so that it can be safely rewritten */ | ||
| 529 | ret = spectrum_reset(link, 1); | ||
| 530 | if (ret) | ||
| 531 | return ret; | ||
| 532 | |||
| 533 | /* Program the adapter with new firmware */ | ||
| 534 | ret = spectrum_load_blocks(hw, first_block); | ||
| 535 | if (ret) | ||
| 536 | return ret; | ||
| 537 | |||
| 538 | /* Write the PDA to the adapter */ | ||
| 539 | if (image != primsym) { | ||
| 540 | ret = spectrum_apply_pda(hw, first_block, pda); | ||
| 541 | if (ret) | ||
| 542 | return ret; | ||
| 543 | } | ||
| 544 | |||
| 545 | /* Run the firmware */ | ||
| 546 | ret = spectrum_reset(link, 0); | ||
| 547 | if (ret) | ||
| 548 | return ret; | ||
| 549 | |||
| 550 | /* Reset hermes chip and make sure it responds */ | ||
| 551 | ret = hermes_init(hw); | ||
| 552 | |||
| 553 | /* hermes_reset() should return 0 with the secondary firmware */ | ||
| 554 | if (image != primsym && ret != 0) | ||
| 555 | return -ENODEV; | ||
| 556 | |||
| 557 | /* And this should work with any firmware */ | ||
| 558 | if (!hermes_present(hw)) | ||
| 559 | return -ENODEV; | ||
| 560 | |||
| 561 | return 0; | ||
| 562 | } | ||
| 563 | |||
| 564 | |||
| 565 | /* | ||
| 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. | ||
| 568 | */ | ||
| 569 | static int | ||
| 570 | spectrum_dl_firmware(hermes_t *hw, dev_link_t *link) | ||
| 571 | { | ||
| 572 | int ret; | ||
| 573 | client_handle_t handle = link->handle; | ||
| 574 | |||
| 575 | #ifndef SPECTRUM_FW_INCLUDED | ||
| 576 | const struct firmware *fw_entry; | ||
| 577 | |||
| 578 | if (request_firmware(&fw_entry, primary_fw_name, | ||
| 579 | &handle_to_dev(handle)) == 0) { | ||
| 580 | primsym = fw_entry->data; | ||
| 581 | } else { | ||
| 582 | printk(KERN_ERR PFX "Cannot find firmware: %s\n", | ||
| 583 | primary_fw_name); | ||
| 584 | return -ENOENT; | ||
| 585 | } | ||
| 586 | |||
| 587 | if (request_firmware(&fw_entry, secondary_fw_name, | ||
| 588 | &handle_to_dev(handle)) == 0) { | ||
| 589 | secsym = fw_entry->data; | ||
| 590 | } else { | ||
| 591 | printk(KERN_ERR PFX "Cannot find firmware: %s\n", | ||
| 592 | secondary_fw_name); | ||
| 593 | return -ENOENT; | ||
| 594 | } | ||
| 595 | #endif | ||
| 596 | |||
| 597 | /* Load primary firmware */ | ||
| 598 | ret = spectrum_dl_image(hw, link, primsym); | ||
| 599 | if (ret) { | ||
| 600 | printk(KERN_ERR PFX "Primary firmware download failed\n"); | ||
| 601 | return ret; | ||
| 602 | } | ||
| 603 | |||
| 604 | /* Load secondary firmware */ | ||
| 605 | ret = spectrum_dl_image(hw, link, secsym); | ||
| 606 | |||
| 607 | if (ret) { | ||
| 608 | printk(KERN_ERR PFX "Secondary firmware download failed\n"); | ||
| 609 | } | ||
| 610 | |||
| 611 | return ret; | ||
| 612 | } | ||
| 613 | |||
| 614 | /********************************************************************/ | ||
| 615 | /* Device methods */ | ||
| 616 | /********************************************************************/ | ||
| 617 | |||
| 618 | static int | ||
| 619 | spectrum_cs_hard_reset(struct orinoco_private *priv) | ||
| 620 | { | ||
| 621 | struct orinoco_pccard *card = priv->card; | ||
| 622 | dev_link_t *link = &card->link; | ||
| 623 | int err; | ||
| 624 | |||
| 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"); | ||
| 629 | err = -ENODEV; | ||
| 630 | } | ||
| 631 | } else { | ||
| 632 | /* Soft reset using COR and HCR */ | ||
| 633 | spectrum_reset(link, 0); | ||
| 634 | } | ||
| 635 | |||
| 636 | return 0; | ||
| 637 | } | ||
| 638 | |||
| 639 | /********************************************************************/ | ||
| 640 | /* PCMCIA stuff */ | ||
| 641 | /********************************************************************/ | ||
| 642 | |||
| 643 | /* | ||
| 644 | * This creates an "instance" of the driver, allocating local data | ||
| 645 | * structures for one device. The device is registered with Card | ||
| 646 | * Services. | ||
| 647 | * | ||
| 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. */ | ||
| 651 | static dev_link_t * | ||
| 652 | spectrum_cs_attach(void) | ||
| 653 | { | ||
| 654 | struct net_device *dev; | ||
| 655 | struct orinoco_private *priv; | ||
| 656 | struct orinoco_pccard *card; | ||
| 657 | dev_link_t *link; | ||
| 658 | client_reg_t client_reg; | ||
| 659 | int ret; | ||
| 660 | |||
| 661 | dev = alloc_orinocodev(sizeof(*card), spectrum_cs_hard_reset); | ||
| 662 | if (! dev) | ||
| 663 | return NULL; | ||
| 664 | priv = netdev_priv(dev); | ||
| 665 | card = priv->card; | ||
| 666 | |||
| 667 | /* Link both structures together */ | ||
| 668 | link = &card->link; | ||
| 669 | link->priv = dev; | ||
| 670 | |||
| 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; | ||
| 676 | |||
| 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; | ||
| 684 | |||
| 685 | /* Register with Card Services */ | ||
| 686 | /* FIXME: need a lock? */ | ||
| 687 | link->next = dev_list; | ||
| 688 | dev_list = link; | ||
| 689 | |||
| 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; | ||
| 693 | |||
| 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); | ||
| 698 | return NULL; | ||
| 699 | } | ||
| 700 | |||
| 701 | return link; | ||
| 702 | } /* spectrum_cs_attach */ | ||
| 703 | |||
| 704 | /* | ||
| 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 | ||
| 708 | * is released. | ||
| 709 | */ | ||
| 710 | static void spectrum_cs_detach(dev_link_t *link) | ||
| 711 | { | ||
| 712 | dev_link_t **linkp; | ||
| 713 | struct net_device *dev = link->priv; | ||
| 714 | |||
| 715 | /* Locate device structure */ | ||
| 716 | for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) | ||
| 717 | if (*linkp == link) | ||
| 718 | break; | ||
| 719 | |||
| 720 | BUG_ON(*linkp == NULL); | ||
| 721 | |||
| 722 | if (link->state & DEV_CONFIG) | ||
| 723 | spectrum_cs_release(link); | ||
| 724 | |||
| 725 | /* Break the link with Card Services */ | ||
| 726 | if (link->handle) | ||
| 727 | pcmcia_deregister_client(link->handle); | ||
| 728 | |||
| 729 | /* Unlink device structure, and free it */ | ||
| 730 | *linkp = link->next; | ||
| 731 | DEBUG(0, PFX "detach: link=%p link->dev=%p\n", link, link->dev); | ||
| 732 | if (link->dev) { | ||
| 733 | DEBUG(0, PFX "About to unregister net device %p\n", | ||
| 734 | dev); | ||
| 735 | unregister_netdev(dev); | ||
| 736 | } | ||
| 737 | free_orinocodev(dev); | ||
| 738 | } /* spectrum_cs_detach */ | ||
| 739 | |||
| 740 | /* | ||
| 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. | ||
| 744 | */ | ||
| 745 | |||
| 746 | static void | ||
| 747 | spectrum_cs_config(dev_link_t *link) | ||
| 748 | { | ||
| 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; | ||
| 755 | u_char buf[64]; | ||
| 756 | config_info_t conf; | ||
| 757 | cisinfo_t info; | ||
| 758 | tuple_t tuple; | ||
| 759 | cisparse_t parse; | ||
| 760 | void __iomem *mem; | ||
| 761 | |||
| 762 | CS_CHECK(ValidateCIS, pcmcia_validate_cis(handle, &info)); | ||
| 763 | |||
| 764 | /* | ||
| 765 | * This reads the card's CONFIG tuple to find its | ||
| 766 | * configuration registers. | ||
| 767 | */ | ||
| 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]; | ||
| 778 | |||
| 779 | /* Configure card */ | ||
| 780 | link->state |= DEV_CONFIG; | ||
| 781 | |||
| 782 | /* Look up the current Vcc */ | ||
| 783 | CS_CHECK(GetConfigurationInfo, | ||
| 784 | pcmcia_get_configuration_info(handle, &conf)); | ||
| 785 | link->conf.Vcc = conf.Vcc; | ||
| 786 | |||
| 787 | /* | ||
| 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. | ||
| 792 | * | ||
| 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. | ||
| 800 | */ | ||
| 801 | tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; | ||
| 802 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); | ||
| 803 | while (1) { | ||
| 804 | cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); | ||
| 805 | cistpl_cftable_entry_t dflt = { .index = 0 }; | ||
| 806 | |||
| 807 | if ( (pcmcia_get_tuple_data(handle, &tuple) != 0) | ||
| 808 | || (pcmcia_parse_tuple(handle, &tuple, &parse) != 0)) | ||
| 809 | goto next_entry; | ||
| 810 | |||
| 811 | if (cfg->flags & CISTPL_CFTABLE_DEFAULT) | ||
| 812 | dflt = *cfg; | ||
| 813 | if (cfg->index == 0) | ||
| 814 | goto next_entry; | ||
| 815 | link->conf.ConfigIndex = cfg->index; | ||
| 816 | |||
| 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; | ||
| 821 | } | ||
| 822 | |||
| 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); | ||
| 828 | if (!ignore_cis_vcc) | ||
| 829 | goto next_entry; | ||
| 830 | } | ||
| 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); | ||
| 834 | if(!ignore_cis_vcc) | ||
| 835 | goto next_entry; | ||
| 836 | } | ||
| 837 | } | ||
| 838 | |||
| 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; | ||
| 845 | |||
| 846 | /* Do we need to allocate an interrupt? */ | ||
| 847 | link->conf.Attributes |= CONF_ENABLE_IRQ; | ||
| 848 | |||
| 849 | /* IO window settings */ | ||
| 850 | link->io.NumPorts1 = link->io.NumPorts2 = 0; | ||
| 851 | if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { | ||
| 852 | cistpl_io_t *io = | ||
| 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; | ||
| 865 | if (io->nwin > 1) { | ||
| 866 | link->io.Attributes2 = | ||
| 867 | link->io.Attributes1; | ||
| 868 | link->io.BasePort2 = io->win[1].base; | ||
| 869 | link->io.NumPorts2 = io->win[1].len; | ||
| 870 | } | ||
| 871 | |||
| 872 | /* This reserves IO space but doesn't actually enable it */ | ||
| 873 | if (pcmcia_request_io(link->handle, &link->io) != 0) | ||
| 874 | goto next_entry; | ||
| 875 | } | ||
| 876 | |||
| 877 | |||
| 878 | /* If we got this far, we're cool! */ | ||
| 879 | |||
| 880 | break; | ||
| 881 | |||
| 882 | next_entry: | ||
| 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"); | ||
| 890 | goto cs_failed; | ||
| 891 | } | ||
| 892 | } | ||
| 893 | |||
| 894 | /* | ||
| 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. | ||
| 898 | */ | ||
| 899 | CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); | ||
| 900 | |||
| 901 | /* We initialize the hermes structure before completing PCMCIA | ||
| 902 | * configuration just in case the interrupt handler gets | ||
| 903 | * called. */ | ||
| 904 | mem = ioport_map(link->io.BasePort1, link->io.NumPorts1); | ||
| 905 | if (!mem) | ||
| 906 | goto cs_failed; | ||
| 907 | |||
| 908 | hermes_struct_init(hw, mem, HERMES_16BIT_REGSPACING); | ||
| 909 | |||
| 910 | /* | ||
| 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. | ||
| 914 | */ | ||
| 915 | CS_CHECK(RequestConfiguration, | ||
| 916 | pcmcia_request_configuration(link->handle, &link->conf)); | ||
| 917 | |||
| 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; | ||
| 923 | |||
| 924 | /* Reset card and download firmware */ | ||
| 925 | if (spectrum_cs_hard_reset(priv) != 0) { | ||
| 926 | goto failed; | ||
| 927 | } | ||
| 928 | |||
| 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"); | ||
| 933 | goto failed; | ||
| 934 | } | ||
| 935 | |||
| 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; | ||
| 943 | |||
| 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); | ||
| 948 | if (link->conf.Vpp1) | ||
| 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); | ||
| 958 | printk("\n"); | ||
| 959 | |||
| 960 | return; | ||
| 961 | |||
| 962 | cs_failed: | ||
| 963 | cs_error(link->handle, last_fn, last_ret); | ||
| 964 | |||
| 965 | failed: | ||
| 966 | spectrum_cs_release(link); | ||
| 967 | } /* spectrum_cs_config */ | ||
| 968 | |||
| 969 | /* | ||
| 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. | ||
| 973 | */ | ||
| 974 | static void | ||
| 975 | spectrum_cs_release(dev_link_t *link) | ||
| 976 | { | ||
| 977 | struct net_device *dev = link->priv; | ||
| 978 | struct orinoco_private *priv = netdev_priv(dev); | ||
| 979 | unsigned long flags; | ||
| 980 | |||
| 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); | ||
| 986 | |||
| 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; | ||
| 994 | if (priv->hw.iobase) | ||
| 995 | ioport_unmap(priv->hw.iobase); | ||
| 996 | } /* spectrum_cs_release */ | ||
| 997 | |||
| 998 | /* | ||
| 999 | * The card status event handler. Mostly, this schedules other stuff | ||
| 1000 | * to run after an event is received. | ||
| 1001 | */ | ||
| 1002 | static int | ||
| 1003 | spectrum_cs_event(event_t event, int priority, | ||
| 1004 | event_callback_args_t * args) | ||
| 1005 | { | ||
| 1006 | dev_link_t *link = args->client_data; | ||
| 1007 | struct net_device *dev = link->priv; | ||
| 1008 | struct orinoco_private *priv = netdev_priv(dev); | ||
| 1009 | int err = 0; | ||
| 1010 | unsigned long flags; | ||
| 1011 | |||
| 1012 | switch (event) { | ||
| 1013 | case CS_EVENT_CARD_REMOVAL: | ||
| 1014 | link->state &= ~DEV_PRESENT; | ||
| 1015 | if (link->state & DEV_CONFIG) { | ||
| 1016 | unsigned long flags; | ||
| 1017 | |||
| 1018 | spin_lock_irqsave(&priv->lock, flags); | ||
| 1019 | netif_device_detach(dev); | ||
| 1020 | priv->hw_unavailable++; | ||
| 1021 | spin_unlock_irqrestore(&priv->lock, flags); | ||
| 1022 | } | ||
| 1023 | break; | ||
| 1024 | |||
| 1025 | case CS_EVENT_CARD_INSERTION: | ||
| 1026 | link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; | ||
| 1027 | spectrum_cs_config(link); | ||
| 1028 | break; | ||
| 1029 | |||
| 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); | ||
| 1040 | |||
| 1041 | err = __orinoco_down(dev); | ||
| 1042 | if (err) | ||
| 1043 | printk(KERN_WARNING "%s: %s: Error %d downing interface\n", | ||
| 1044 | dev->name, | ||
| 1045 | event == CS_EVENT_PM_SUSPEND ? "SUSPEND" : "RESET_PHYSICAL", | ||
| 1046 | err); | ||
| 1047 | |||
| 1048 | netif_device_detach(dev); | ||
| 1049 | priv->hw_unavailable++; | ||
| 1050 | |||
| 1051 | spin_unlock_irqrestore(&priv->lock, flags); | ||
| 1052 | |||
| 1053 | pcmcia_release_configuration(link->handle); | ||
| 1054 | } | ||
| 1055 | break; | ||
| 1056 | |||
| 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); | ||
| 1068 | } | ||
| 1069 | break; | ||
| 1070 | } | ||
| 1071 | |||
| 1072 | return err; | ||
| 1073 | } /* spectrum_cs_event */ | ||
| 1074 | |||
| 1075 | /********************************************************************/ | ||
| 1076 | /* Module initialization */ | ||
| 1077 | /********************************************************************/ | ||
| 1078 | |||
| 1079 | /* Can't be declared "const" or the whole __initdata section will | ||
| 1080 | * become const */ | ||
| 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)"; | ||
| 1084 | |||
| 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 */ | ||
| 1089 | PCMCIA_DEVICE_NULL, | ||
| 1090 | }; | ||
| 1091 | MODULE_DEVICE_TABLE(pcmcia, spectrum_cs_ids); | ||
| 1092 | |||
| 1093 | static struct pcmcia_driver orinoco_driver = { | ||
| 1094 | .owner = THIS_MODULE, | ||
| 1095 | .drv = { | ||
| 1096 | .name = DRIVER_NAME, | ||
| 1097 | }, | ||
| 1098 | .attach = spectrum_cs_attach, | ||
| 1099 | .event = spectrum_cs_event, | ||
| 1100 | .detach = spectrum_cs_detach, | ||
| 1101 | .id_table = spectrum_cs_ids, | ||
| 1102 | }; | ||
| 1103 | |||
| 1104 | static int __init | ||
| 1105 | init_spectrum_cs(void) | ||
| 1106 | { | ||
| 1107 | printk(KERN_DEBUG "%s\n", version); | ||
| 1108 | |||
| 1109 | return pcmcia_register_driver(&orinoco_driver); | ||
| 1110 | } | ||
| 1111 | |||
| 1112 | static void __exit | ||
| 1113 | exit_spectrum_cs(void) | ||
| 1114 | { | ||
| 1115 | pcmcia_unregister_driver(&orinoco_driver); | ||
| 1116 | BUG_ON(dev_list != NULL); | ||
| 1117 | } | ||
| 1118 | |||
| 1119 | module_init(init_spectrum_cs); | ||
| 1120 | module_exit(exit_spectrum_cs); | ||
