spectrum_cs.c 25 KB

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