spectrum_cs.c 26 KB

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