spectrum_cs.c 25 KB

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