hostap_cs.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928
  1. #define PRISM2_PCCARD
  2. #include <linux/module.h>
  3. #include <linux/init.h>
  4. #include <linux/if.h>
  5. #include <linux/wait.h>
  6. #include <linux/timer.h>
  7. #include <linux/skbuff.h>
  8. #include <linux/netdevice.h>
  9. #include <linux/workqueue.h>
  10. #include <linux/wireless.h>
  11. #include <net/iw_handler.h>
  12. #include <pcmcia/cs_types.h>
  13. #include <pcmcia/cs.h>
  14. #include <pcmcia/cistpl.h>
  15. #include <pcmcia/cisreg.h>
  16. #include <pcmcia/ds.h>
  17. #include <asm/io.h>
  18. #include "hostap_wlan.h"
  19. static char *version = PRISM2_VERSION " (Jouni Malinen <jkmaline@cc.hut.fi>)";
  20. static dev_info_t dev_info = "hostap_cs";
  21. MODULE_AUTHOR("Jouni Malinen");
  22. MODULE_DESCRIPTION("Support for Intersil Prism2-based 802.11 wireless LAN "
  23. "cards (PC Card).");
  24. MODULE_SUPPORTED_DEVICE("Intersil Prism2-based WLAN cards (PC Card)");
  25. MODULE_LICENSE("GPL");
  26. MODULE_VERSION(PRISM2_VERSION);
  27. static int ignore_cis_vcc;
  28. module_param(ignore_cis_vcc, int, 0444);
  29. MODULE_PARM_DESC(ignore_cis_vcc, "Ignore broken CIS VCC entry");
  30. /* struct local_info::hw_priv */
  31. struct hostap_cs_priv {
  32. dev_node_t node;
  33. struct pcmcia_device *link;
  34. int sandisk_connectplus;
  35. };
  36. #ifdef PRISM2_IO_DEBUG
  37. static inline void hfa384x_outb_debug(struct net_device *dev, int a, u8 v)
  38. {
  39. struct hostap_interface *iface;
  40. local_info_t *local;
  41. unsigned long flags;
  42. iface = netdev_priv(dev);
  43. local = iface->local;
  44. spin_lock_irqsave(&local->lock, flags);
  45. prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTB, a, v);
  46. outb(v, dev->base_addr + a);
  47. spin_unlock_irqrestore(&local->lock, flags);
  48. }
  49. static inline u8 hfa384x_inb_debug(struct net_device *dev, int a)
  50. {
  51. struct hostap_interface *iface;
  52. local_info_t *local;
  53. unsigned long flags;
  54. u8 v;
  55. iface = netdev_priv(dev);
  56. local = iface->local;
  57. spin_lock_irqsave(&local->lock, flags);
  58. v = inb(dev->base_addr + a);
  59. prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INB, a, v);
  60. spin_unlock_irqrestore(&local->lock, flags);
  61. return v;
  62. }
  63. static inline void hfa384x_outw_debug(struct net_device *dev, int a, u16 v)
  64. {
  65. struct hostap_interface *iface;
  66. local_info_t *local;
  67. unsigned long flags;
  68. iface = netdev_priv(dev);
  69. local = iface->local;
  70. spin_lock_irqsave(&local->lock, flags);
  71. prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTW, a, v);
  72. outw(v, dev->base_addr + a);
  73. spin_unlock_irqrestore(&local->lock, flags);
  74. }
  75. static inline u16 hfa384x_inw_debug(struct net_device *dev, int a)
  76. {
  77. struct hostap_interface *iface;
  78. local_info_t *local;
  79. unsigned long flags;
  80. u16 v;
  81. iface = netdev_priv(dev);
  82. local = iface->local;
  83. spin_lock_irqsave(&local->lock, flags);
  84. v = inw(dev->base_addr + a);
  85. prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INW, a, v);
  86. spin_unlock_irqrestore(&local->lock, flags);
  87. return v;
  88. }
  89. static inline void hfa384x_outsw_debug(struct net_device *dev, int a,
  90. u8 *buf, int wc)
  91. {
  92. struct hostap_interface *iface;
  93. local_info_t *local;
  94. unsigned long flags;
  95. iface = netdev_priv(dev);
  96. local = iface->local;
  97. spin_lock_irqsave(&local->lock, flags);
  98. prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTSW, a, wc);
  99. outsw(dev->base_addr + a, buf, wc);
  100. spin_unlock_irqrestore(&local->lock, flags);
  101. }
  102. static inline void hfa384x_insw_debug(struct net_device *dev, int a,
  103. u8 *buf, int wc)
  104. {
  105. struct hostap_interface *iface;
  106. local_info_t *local;
  107. unsigned long flags;
  108. iface = netdev_priv(dev);
  109. local = iface->local;
  110. spin_lock_irqsave(&local->lock, flags);
  111. prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INSW, a, wc);
  112. insw(dev->base_addr + a, buf, wc);
  113. spin_unlock_irqrestore(&local->lock, flags);
  114. }
  115. #define HFA384X_OUTB(v,a) hfa384x_outb_debug(dev, (a), (v))
  116. #define HFA384X_INB(a) hfa384x_inb_debug(dev, (a))
  117. #define HFA384X_OUTW(v,a) hfa384x_outw_debug(dev, (a), (v))
  118. #define HFA384X_INW(a) hfa384x_inw_debug(dev, (a))
  119. #define HFA384X_OUTSW(a, buf, wc) hfa384x_outsw_debug(dev, (a), (buf), (wc))
  120. #define HFA384X_INSW(a, buf, wc) hfa384x_insw_debug(dev, (a), (buf), (wc))
  121. #else /* PRISM2_IO_DEBUG */
  122. #define HFA384X_OUTB(v,a) outb((v), dev->base_addr + (a))
  123. #define HFA384X_INB(a) inb(dev->base_addr + (a))
  124. #define HFA384X_OUTW(v,a) outw((v), dev->base_addr + (a))
  125. #define HFA384X_INW(a) inw(dev->base_addr + (a))
  126. #define HFA384X_INSW(a, buf, wc) insw(dev->base_addr + (a), buf, wc)
  127. #define HFA384X_OUTSW(a, buf, wc) outsw(dev->base_addr + (a), buf, wc)
  128. #endif /* PRISM2_IO_DEBUG */
  129. static int hfa384x_from_bap(struct net_device *dev, u16 bap, void *buf,
  130. int len)
  131. {
  132. u16 d_off;
  133. u16 *pos;
  134. d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF;
  135. pos = (u16 *) buf;
  136. if (len / 2)
  137. HFA384X_INSW(d_off, buf, len / 2);
  138. pos += len / 2;
  139. if (len & 1)
  140. *((char *) pos) = HFA384X_INB(d_off);
  141. return 0;
  142. }
  143. static int hfa384x_to_bap(struct net_device *dev, u16 bap, void *buf, int len)
  144. {
  145. u16 d_off;
  146. u16 *pos;
  147. d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF;
  148. pos = (u16 *) buf;
  149. if (len / 2)
  150. HFA384X_OUTSW(d_off, buf, len / 2);
  151. pos += len / 2;
  152. if (len & 1)
  153. HFA384X_OUTB(*((char *) pos), d_off);
  154. return 0;
  155. }
  156. /* FIX: This might change at some point.. */
  157. #include "hostap_hw.c"
  158. static void prism2_detach(struct pcmcia_device *p_dev);
  159. static void prism2_release(u_long arg);
  160. static int prism2_config(struct pcmcia_device *link);
  161. static int prism2_pccard_card_present(local_info_t *local)
  162. {
  163. struct hostap_cs_priv *hw_priv = local->hw_priv;
  164. if (hw_priv != NULL && hw_priv->link != NULL && pcmcia_dev_present(hw_priv->link))
  165. return 1;
  166. return 0;
  167. }
  168. /*
  169. * SanDisk CompactFlash WLAN Flashcard - Product Manual v1.0
  170. * Document No. 20-10-00058, January 2004
  171. * http://www.sandisk.com/pdf/industrial/ProdManualCFWLANv1.0.pdf
  172. */
  173. #define SANDISK_WLAN_ACTIVATION_OFF 0x40
  174. #define SANDISK_HCR_OFF 0x42
  175. static void sandisk_set_iobase(local_info_t *local)
  176. {
  177. int res;
  178. conf_reg_t reg;
  179. struct hostap_cs_priv *hw_priv = local->hw_priv;
  180. reg.Function = 0;
  181. reg.Action = CS_WRITE;
  182. reg.Offset = 0x10; /* 0x3f0 IO base 1 */
  183. reg.Value = hw_priv->link->io.BasePort1 & 0x00ff;
  184. res = pcmcia_access_configuration_register(hw_priv->link,
  185. &reg);
  186. if (res != CS_SUCCESS) {
  187. printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 0 -"
  188. " res=%d\n", res);
  189. }
  190. udelay(10);
  191. reg.Function = 0;
  192. reg.Action = CS_WRITE;
  193. reg.Offset = 0x12; /* 0x3f2 IO base 2 */
  194. reg.Value = (hw_priv->link->io.BasePort1 & 0xff00) >> 8;
  195. res = pcmcia_access_configuration_register(hw_priv->link,
  196. &reg);
  197. if (res != CS_SUCCESS) {
  198. printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 1 -"
  199. " res=%d\n", res);
  200. }
  201. }
  202. static void sandisk_write_hcr(local_info_t *local, int hcr)
  203. {
  204. struct net_device *dev = local->dev;
  205. int i;
  206. HFA384X_OUTB(0x80, SANDISK_WLAN_ACTIVATION_OFF);
  207. udelay(50);
  208. for (i = 0; i < 10; i++) {
  209. HFA384X_OUTB(hcr, SANDISK_HCR_OFF);
  210. }
  211. udelay(55);
  212. HFA384X_OUTB(0x45, SANDISK_WLAN_ACTIVATION_OFF);
  213. }
  214. static int sandisk_enable_wireless(struct net_device *dev)
  215. {
  216. int res, ret = 0;
  217. conf_reg_t reg;
  218. struct hostap_interface *iface = dev->priv;
  219. local_info_t *local = iface->local;
  220. tuple_t tuple;
  221. cisparse_t *parse = NULL;
  222. u_char buf[64];
  223. struct hostap_cs_priv *hw_priv = local->hw_priv;
  224. if (hw_priv->link->io.NumPorts1 < 0x42) {
  225. /* Not enough ports to be SanDisk multi-function card */
  226. ret = -ENODEV;
  227. goto done;
  228. }
  229. parse = kmalloc(sizeof(cisparse_t), GFP_KERNEL);
  230. if (parse == NULL) {
  231. ret = -ENOMEM;
  232. goto done;
  233. }
  234. tuple.DesiredTuple = CISTPL_MANFID;
  235. tuple.Attributes = TUPLE_RETURN_COMMON;
  236. tuple.TupleData = buf;
  237. tuple.TupleDataMax = sizeof(buf);
  238. tuple.TupleOffset = 0;
  239. if (pcmcia_get_first_tuple(hw_priv->link, &tuple) ||
  240. pcmcia_get_tuple_data(hw_priv->link, &tuple) ||
  241. pcmcia_parse_tuple(hw_priv->link, &tuple, parse) ||
  242. parse->manfid.manf != 0xd601 || parse->manfid.card != 0x0101) {
  243. /* No SanDisk manfid found */
  244. ret = -ENODEV;
  245. goto done;
  246. }
  247. tuple.DesiredTuple = CISTPL_LONGLINK_MFC;
  248. if (pcmcia_get_first_tuple(hw_priv->link, &tuple) ||
  249. pcmcia_get_tuple_data(hw_priv->link, &tuple) ||
  250. pcmcia_parse_tuple(hw_priv->link, &tuple, parse) ||
  251. parse->longlink_mfc.nfn < 2) {
  252. /* No multi-function links found */
  253. ret = -ENODEV;
  254. goto done;
  255. }
  256. printk(KERN_DEBUG "%s: Multi-function SanDisk ConnectPlus detected"
  257. " - using vendor-specific initialization\n", dev->name);
  258. hw_priv->sandisk_connectplus = 1;
  259. reg.Function = 0;
  260. reg.Action = CS_WRITE;
  261. reg.Offset = CISREG_COR;
  262. reg.Value = COR_SOFT_RESET;
  263. res = pcmcia_access_configuration_register(hw_priv->link,
  264. &reg);
  265. if (res != CS_SUCCESS) {
  266. printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n",
  267. dev->name, res);
  268. goto done;
  269. }
  270. mdelay(5);
  271. reg.Function = 0;
  272. reg.Action = CS_WRITE;
  273. reg.Offset = CISREG_COR;
  274. /*
  275. * Do not enable interrupts here to avoid some bogus events. Interrupts
  276. * will be enabled during the first cor_sreset call.
  277. */
  278. reg.Value = COR_LEVEL_REQ | 0x8 | COR_ADDR_DECODE | COR_FUNC_ENA;
  279. res = pcmcia_access_configuration_register(hw_priv->link,
  280. &reg);
  281. if (res != CS_SUCCESS) {
  282. printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n",
  283. dev->name, res);
  284. goto done;
  285. }
  286. mdelay(5);
  287. sandisk_set_iobase(local);
  288. HFA384X_OUTB(0xc5, SANDISK_WLAN_ACTIVATION_OFF);
  289. udelay(10);
  290. HFA384X_OUTB(0x4b, SANDISK_WLAN_ACTIVATION_OFF);
  291. udelay(10);
  292. done:
  293. kfree(parse);
  294. return ret;
  295. }
  296. static void prism2_pccard_cor_sreset(local_info_t *local)
  297. {
  298. int res;
  299. conf_reg_t reg;
  300. struct hostap_cs_priv *hw_priv = local->hw_priv;
  301. if (!prism2_pccard_card_present(local))
  302. return;
  303. reg.Function = 0;
  304. reg.Action = CS_READ;
  305. reg.Offset = CISREG_COR;
  306. reg.Value = 0;
  307. res = pcmcia_access_configuration_register(hw_priv->link,
  308. &reg);
  309. if (res != CS_SUCCESS) {
  310. printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 1 (%d)\n",
  311. res);
  312. return;
  313. }
  314. printk(KERN_DEBUG "prism2_pccard_cor_sreset: original COR %02x\n",
  315. reg.Value);
  316. reg.Action = CS_WRITE;
  317. reg.Value |= COR_SOFT_RESET;
  318. res = pcmcia_access_configuration_register(hw_priv->link,
  319. &reg);
  320. if (res != CS_SUCCESS) {
  321. printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 2 (%d)\n",
  322. res);
  323. return;
  324. }
  325. mdelay(hw_priv->sandisk_connectplus ? 5 : 2);
  326. reg.Value &= ~COR_SOFT_RESET;
  327. if (hw_priv->sandisk_connectplus)
  328. reg.Value |= COR_IREQ_ENA;
  329. res = pcmcia_access_configuration_register(hw_priv->link,
  330. &reg);
  331. if (res != CS_SUCCESS) {
  332. printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 3 (%d)\n",
  333. res);
  334. return;
  335. }
  336. mdelay(hw_priv->sandisk_connectplus ? 5 : 2);
  337. if (hw_priv->sandisk_connectplus)
  338. sandisk_set_iobase(local);
  339. }
  340. static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
  341. {
  342. int res;
  343. conf_reg_t reg;
  344. int old_cor;
  345. struct hostap_cs_priv *hw_priv = local->hw_priv;
  346. if (!prism2_pccard_card_present(local))
  347. return;
  348. if (hw_priv->sandisk_connectplus) {
  349. sandisk_write_hcr(local, hcr);
  350. return;
  351. }
  352. reg.Function = 0;
  353. reg.Action = CS_READ;
  354. reg.Offset = CISREG_COR;
  355. reg.Value = 0;
  356. res = pcmcia_access_configuration_register(hw_priv->link,
  357. &reg);
  358. if (res != CS_SUCCESS) {
  359. printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 1 "
  360. "(%d)\n", res);
  361. return;
  362. }
  363. printk(KERN_DEBUG "prism2_pccard_genesis_sreset: original COR %02x\n",
  364. reg.Value);
  365. old_cor = reg.Value;
  366. reg.Action = CS_WRITE;
  367. reg.Value |= COR_SOFT_RESET;
  368. res = pcmcia_access_configuration_register(hw_priv->link,
  369. &reg);
  370. if (res != CS_SUCCESS) {
  371. printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 2 "
  372. "(%d)\n", res);
  373. return;
  374. }
  375. mdelay(10);
  376. /* Setup Genesis mode */
  377. reg.Action = CS_WRITE;
  378. reg.Value = hcr;
  379. reg.Offset = CISREG_CCSR;
  380. res = pcmcia_access_configuration_register(hw_priv->link,
  381. &reg);
  382. if (res != CS_SUCCESS) {
  383. printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 3 "
  384. "(%d)\n", res);
  385. return;
  386. }
  387. mdelay(10);
  388. reg.Action = CS_WRITE;
  389. reg.Offset = CISREG_COR;
  390. reg.Value = old_cor & ~COR_SOFT_RESET;
  391. res = pcmcia_access_configuration_register(hw_priv->link,
  392. &reg);
  393. if (res != CS_SUCCESS) {
  394. printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 4 "
  395. "(%d)\n", res);
  396. return;
  397. }
  398. mdelay(10);
  399. }
  400. static struct prism2_helper_functions prism2_pccard_funcs =
  401. {
  402. .card_present = prism2_pccard_card_present,
  403. .cor_sreset = prism2_pccard_cor_sreset,
  404. .genesis_reset = prism2_pccard_genesis_reset,
  405. .hw_type = HOSTAP_HW_PCCARD,
  406. };
  407. /* allocate local data and register with CardServices
  408. * initialize dev_link structure, but do not configure the card yet */
  409. static int hostap_cs_probe(struct pcmcia_device *p_dev)
  410. {
  411. int ret;
  412. PDEBUG(DEBUG_HW, "%s: setting Vcc=33 (constant)\n", dev_info);
  413. p_dev->conf.IntType = INT_MEMORY_AND_IO;
  414. ret = prism2_config(p_dev);
  415. if (ret) {
  416. PDEBUG(DEBUG_EXTRA, "prism2_config() failed\n");
  417. }
  418. return ret;
  419. }
  420. static void prism2_detach(struct pcmcia_device *link)
  421. {
  422. PDEBUG(DEBUG_FLOW, "prism2_detach\n");
  423. prism2_release((u_long)link);
  424. /* release net devices */
  425. if (link->priv) {
  426. struct hostap_cs_priv *hw_priv;
  427. struct net_device *dev;
  428. struct hostap_interface *iface;
  429. dev = link->priv;
  430. iface = netdev_priv(dev);
  431. hw_priv = iface->local->hw_priv;
  432. prism2_free_local_data(dev);
  433. kfree(hw_priv);
  434. }
  435. }
  436. #define CS_CHECK(fn, ret) \
  437. do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
  438. #define CFG_CHECK2(fn, retf) \
  439. do { int ret = (retf); \
  440. if (ret != 0) { \
  441. PDEBUG(DEBUG_EXTRA, "CardServices(" #fn ") returned %d\n", ret); \
  442. cs_error(link, fn, ret); \
  443. goto next_entry; \
  444. } \
  445. } while (0)
  446. /* run after a CARD_INSERTION event is received to configure the PCMCIA
  447. * socket and make the device available to the system */
  448. static int prism2_config(struct pcmcia_device *link)
  449. {
  450. struct net_device *dev;
  451. struct hostap_interface *iface;
  452. local_info_t *local;
  453. int ret = 1;
  454. tuple_t tuple;
  455. cisparse_t *parse;
  456. int last_fn, last_ret;
  457. u_char buf[64];
  458. config_info_t conf;
  459. cistpl_cftable_entry_t dflt = { 0 };
  460. struct hostap_cs_priv *hw_priv;
  461. PDEBUG(DEBUG_FLOW, "prism2_config()\n");
  462. parse = kmalloc(sizeof(cisparse_t), GFP_KERNEL);
  463. hw_priv = kmalloc(sizeof(*hw_priv), GFP_KERNEL);
  464. if (parse == NULL || hw_priv == NULL) {
  465. ret = -ENOMEM;
  466. goto failed;
  467. }
  468. memset(hw_priv, 0, sizeof(*hw_priv));
  469. tuple.DesiredTuple = CISTPL_CONFIG;
  470. tuple.Attributes = 0;
  471. tuple.TupleData = buf;
  472. tuple.TupleDataMax = sizeof(buf);
  473. tuple.TupleOffset = 0;
  474. CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
  475. CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
  476. CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, parse));
  477. link->conf.ConfigBase = parse->config.base;
  478. link->conf.Present = parse->config.rmask[0];
  479. CS_CHECK(GetConfigurationInfo,
  480. pcmcia_get_configuration_info(link, &conf));
  481. /* Look for an appropriate configuration table entry in the CIS */
  482. tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
  483. CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
  484. for (;;) {
  485. cistpl_cftable_entry_t *cfg = &(parse->cftable_entry);
  486. CFG_CHECK2(GetTupleData,
  487. pcmcia_get_tuple_data(link, &tuple));
  488. CFG_CHECK2(ParseTuple,
  489. pcmcia_parse_tuple(link, &tuple, parse));
  490. if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
  491. dflt = *cfg;
  492. if (cfg->index == 0)
  493. goto next_entry;
  494. link->conf.ConfigIndex = cfg->index;
  495. PDEBUG(DEBUG_EXTRA, "Checking CFTABLE_ENTRY 0x%02X "
  496. "(default 0x%02X)\n", cfg->index, dflt.index);
  497. /* Does this card need audio output? */
  498. if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
  499. link->conf.Attributes |= CONF_ENABLE_SPKR;
  500. link->conf.Status = CCSR_AUDIO_ENA;
  501. }
  502. /* Use power settings for Vcc and Vpp if present */
  503. /* Note that the CIS values need to be rescaled */
  504. if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
  505. if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] /
  506. 10000 && !ignore_cis_vcc) {
  507. PDEBUG(DEBUG_EXTRA, " Vcc mismatch - skipping"
  508. " this entry\n");
  509. goto next_entry;
  510. }
  511. } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
  512. if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] /
  513. 10000 && !ignore_cis_vcc) {
  514. PDEBUG(DEBUG_EXTRA, " Vcc (default) mismatch "
  515. "- skipping this entry\n");
  516. goto next_entry;
  517. }
  518. }
  519. if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
  520. link->conf.Vpp =
  521. cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
  522. else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
  523. link->conf.Vpp =
  524. dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
  525. /* Do we need to allocate an interrupt? */
  526. if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
  527. link->conf.Attributes |= CONF_ENABLE_IRQ;
  528. else if (!(link->conf.Attributes & CONF_ENABLE_IRQ)) {
  529. /* At least Compaq WL200 does not have IRQInfo1 set,
  530. * but it does not work without interrupts.. */
  531. printk("Config has no IRQ info, but trying to enable "
  532. "IRQ anyway..\n");
  533. link->conf.Attributes |= CONF_ENABLE_IRQ;
  534. }
  535. /* IO window settings */
  536. PDEBUG(DEBUG_EXTRA, "IO window settings: cfg->io.nwin=%d "
  537. "dflt.io.nwin=%d\n",
  538. cfg->io.nwin, dflt.io.nwin);
  539. link->io.NumPorts1 = link->io.NumPorts2 = 0;
  540. if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
  541. cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
  542. link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
  543. PDEBUG(DEBUG_EXTRA, "io->flags = 0x%04X, "
  544. "io.base=0x%04x, len=%d\n", io->flags,
  545. io->win[0].base, io->win[0].len);
  546. if (!(io->flags & CISTPL_IO_8BIT))
  547. link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
  548. if (!(io->flags & CISTPL_IO_16BIT))
  549. link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  550. link->io.IOAddrLines = io->flags &
  551. CISTPL_IO_LINES_MASK;
  552. link->io.BasePort1 = io->win[0].base;
  553. link->io.NumPorts1 = io->win[0].len;
  554. if (io->nwin > 1) {
  555. link->io.Attributes2 = link->io.Attributes1;
  556. link->io.BasePort2 = io->win[1].base;
  557. link->io.NumPorts2 = io->win[1].len;
  558. }
  559. }
  560. /* This reserves IO space but doesn't actually enable it */
  561. CFG_CHECK2(RequestIO,
  562. pcmcia_request_io(link, &link->io));
  563. /* This configuration table entry is OK */
  564. break;
  565. next_entry:
  566. CS_CHECK(GetNextTuple,
  567. pcmcia_get_next_tuple(link, &tuple));
  568. }
  569. /* Need to allocate net_device before requesting IRQ handler */
  570. dev = prism2_init_local_data(&prism2_pccard_funcs, 0,
  571. &handle_to_dev(link));
  572. if (dev == NULL)
  573. goto failed;
  574. link->priv = dev;
  575. iface = netdev_priv(dev);
  576. local = iface->local;
  577. local->hw_priv = hw_priv;
  578. hw_priv->link = link;
  579. strcpy(hw_priv->node.dev_name, dev->name);
  580. link->dev_node = &hw_priv->node;
  581. /*
  582. * Allocate an interrupt line. Note that this does not assign a
  583. * handler to the interrupt, unless the 'Handler' member of the
  584. * irq structure is initialized.
  585. */
  586. if (link->conf.Attributes & CONF_ENABLE_IRQ) {
  587. link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
  588. link->irq.IRQInfo1 = IRQ_LEVEL_ID;
  589. link->irq.Handler = prism2_interrupt;
  590. link->irq.Instance = dev;
  591. CS_CHECK(RequestIRQ,
  592. pcmcia_request_irq(link, &link->irq));
  593. }
  594. /*
  595. * This actually configures the PCMCIA socket -- setting up
  596. * the I/O windows and the interrupt mapping, and putting the
  597. * card and host interface into "Memory and IO" mode.
  598. */
  599. CS_CHECK(RequestConfiguration,
  600. pcmcia_request_configuration(link, &link->conf));
  601. dev->irq = link->irq.AssignedIRQ;
  602. dev->base_addr = link->io.BasePort1;
  603. /* Finally, report what we've done */
  604. printk(KERN_INFO "%s: index 0x%02x: ",
  605. dev_info, link->conf.ConfigIndex);
  606. if (link->conf.Vpp)
  607. printk(", Vpp %d.%d", link->conf.Vpp / 10,
  608. link->conf.Vpp % 10);
  609. if (link->conf.Attributes & CONF_ENABLE_IRQ)
  610. printk(", irq %d", link->irq.AssignedIRQ);
  611. if (link->io.NumPorts1)
  612. printk(", io 0x%04x-0x%04x", link->io.BasePort1,
  613. link->io.BasePort1+link->io.NumPorts1-1);
  614. if (link->io.NumPorts2)
  615. printk(" & 0x%04x-0x%04x", link->io.BasePort2,
  616. link->io.BasePort2+link->io.NumPorts2-1);
  617. printk("\n");
  618. local->shutdown = 0;
  619. sandisk_enable_wireless(dev);
  620. ret = prism2_hw_config(dev, 1);
  621. if (!ret) {
  622. ret = hostap_hw_ready(dev);
  623. if (ret == 0 && local->ddev)
  624. strcpy(hw_priv->node.dev_name, local->ddev->name);
  625. }
  626. kfree(parse);
  627. return ret;
  628. cs_failed:
  629. cs_error(link, last_fn, last_ret);
  630. failed:
  631. kfree(parse);
  632. kfree(hw_priv);
  633. prism2_release((u_long)link);
  634. return ret;
  635. }
  636. static void prism2_release(u_long arg)
  637. {
  638. struct pcmcia_device *link = (struct pcmcia_device *)arg;
  639. PDEBUG(DEBUG_FLOW, "prism2_release\n");
  640. if (link->priv) {
  641. struct net_device *dev = link->priv;
  642. struct hostap_interface *iface;
  643. iface = netdev_priv(dev);
  644. prism2_hw_shutdown(dev, 0);
  645. iface->local->shutdown = 1;
  646. }
  647. pcmcia_disable_device(link);
  648. PDEBUG(DEBUG_FLOW, "release - done\n");
  649. }
  650. static int hostap_cs_suspend(struct pcmcia_device *link)
  651. {
  652. struct net_device *dev = (struct net_device *) link->priv;
  653. int dev_open = 0;
  654. struct hostap_interface *iface = NULL;
  655. if (dev)
  656. iface = netdev_priv(dev);
  657. PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_SUSPEND\n", dev_info);
  658. if (iface && iface->local)
  659. dev_open = iface->local->num_dev_open > 0;
  660. if (dev_open) {
  661. netif_stop_queue(dev);
  662. netif_device_detach(dev);
  663. }
  664. prism2_suspend(dev);
  665. return 0;
  666. }
  667. static int hostap_cs_resume(struct pcmcia_device *link)
  668. {
  669. struct net_device *dev = (struct net_device *) link->priv;
  670. int dev_open = 0;
  671. struct hostap_interface *iface = NULL;
  672. if (dev)
  673. iface = netdev_priv(dev);
  674. PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_RESUME\n", dev_info);
  675. if (iface && iface->local)
  676. dev_open = iface->local->num_dev_open > 0;
  677. prism2_hw_shutdown(dev, 1);
  678. prism2_hw_config(dev, dev_open ? 0 : 1);
  679. if (dev_open) {
  680. netif_device_attach(dev);
  681. netif_start_queue(dev);
  682. }
  683. return 0;
  684. }
  685. static struct pcmcia_device_id hostap_cs_ids[] = {
  686. PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7100),
  687. PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7300),
  688. PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0777),
  689. PCMCIA_DEVICE_MANF_CARD(0x0126, 0x8000),
  690. PCMCIA_DEVICE_MANF_CARD(0x0138, 0x0002),
  691. PCMCIA_DEVICE_MANF_CARD(0x0250, 0x0002),
  692. PCMCIA_DEVICE_MANF_CARD(0x026f, 0x030b),
  693. PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1612),
  694. PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1613),
  695. PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0002),
  696. PCMCIA_DEVICE_MANF_CARD(0x02aa, 0x0002),
  697. PCMCIA_DEVICE_MANF_CARD(0x02d2, 0x0001),
  698. PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x0001),
  699. PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x7300),
  700. /* PCMCIA_DEVICE_MANF_CARD(0xc00f, 0x0000), conflict with pcnet_cs */
  701. PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0002),
  702. PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005),
  703. PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0010),
  704. PCMCIA_DEVICE_MANF_CARD(0x0126, 0x0002),
  705. PCMCIA_DEVICE_MANF_CARD_PROD_ID1(0x0156, 0x0002, "INTERSIL",
  706. 0x74c5e40d),
  707. PCMCIA_DEVICE_MANF_CARD_PROD_ID1(0x0156, 0x0002, "Intersil",
  708. 0x4b801a17),
  709. PCMCIA_MFC_DEVICE_PROD_ID12(0, "SanDisk", "ConnectPlus",
  710. 0x7a954bd9, 0x74be00c6),
  711. PCMCIA_DEVICE_PROD_ID1234(
  712. "Intersil", "PRISM 2_5 PCMCIA ADAPTER", "ISL37300P",
  713. "Eval-RevA",
  714. 0x4b801a17, 0x6345a0bf, 0xc9049a39, 0xc23adc0e),
  715. PCMCIA_DEVICE_PROD_ID123(
  716. "Addtron", "AWP-100 Wireless PCMCIA", "Version 01.02",
  717. 0xe6ec52ce, 0x08649af2, 0x4b74baa0),
  718. PCMCIA_DEVICE_PROD_ID123(
  719. "D", "Link DWL-650 11Mbps WLAN Card", "Version 01.02",
  720. 0x71b18589, 0xb6f1b0ab, 0x4b74baa0),
  721. PCMCIA_DEVICE_PROD_ID123(
  722. "Instant Wireless ", " Network PC CARD", "Version 01.02",
  723. 0x11d901af, 0x6e9bd926, 0x4b74baa0),
  724. PCMCIA_DEVICE_PROD_ID123(
  725. "SMC", "SMC2632W", "Version 01.02",
  726. 0xc4f8b18b, 0x474a1f2a, 0x4b74baa0),
  727. PCMCIA_DEVICE_PROD_ID12("BUFFALO", "WLI-CF-S11G",
  728. 0x2decece3, 0x82067c18),
  729. PCMCIA_DEVICE_PROD_ID12("Compaq", "WL200_11Mbps_Wireless_PCI_Card",
  730. 0x54f7c49c, 0x15a75e5b),
  731. PCMCIA_DEVICE_PROD_ID12("INTERSIL", "HFA384x/IEEE",
  732. 0x74c5e40d, 0xdb472a18),
  733. PCMCIA_DEVICE_PROD_ID12("Linksys", "Wireless CompactFlash Card",
  734. 0x0733cc81, 0x0c52f395),
  735. PCMCIA_DEVICE_PROD_ID12(
  736. "ZoomAir 11Mbps High", "Rate wireless Networking",
  737. 0x273fe3db, 0x32a1eaee),
  738. PCMCIA_DEVICE_PROD_ID123(
  739. "Pretec", "CompactWLAN Card 802.11b", "2.5",
  740. 0x1cadd3e5, 0xe697636c, 0x7a5bfcf1),
  741. PCMCIA_DEVICE_PROD_ID123(
  742. "U.S. Robotics", "IEEE 802.11b PC-CARD", "Version 01.02",
  743. 0xc7b8df9d, 0x1700d087, 0x4b74baa0),
  744. PCMCIA_DEVICE_PROD_ID123(
  745. "Allied Telesyn", "AT-WCL452 Wireless PCMCIA Radio",
  746. "Ver. 1.00",
  747. 0x5cd01705, 0x4271660f, 0x9d08ee12),
  748. PCMCIA_DEVICE_PROD_ID123(
  749. "corega", "WL PCCL-11", "ISL37300P",
  750. 0xa21501a, 0x59868926, 0xc9049a39),
  751. PCMCIA_DEVICE_NULL
  752. };
  753. MODULE_DEVICE_TABLE(pcmcia, hostap_cs_ids);
  754. static struct pcmcia_driver hostap_driver = {
  755. .drv = {
  756. .name = "hostap_cs",
  757. },
  758. .probe = hostap_cs_probe,
  759. .remove = prism2_detach,
  760. .owner = THIS_MODULE,
  761. .id_table = hostap_cs_ids,
  762. .suspend = hostap_cs_suspend,
  763. .resume = hostap_cs_resume,
  764. };
  765. static int __init init_prism2_pccard(void)
  766. {
  767. printk(KERN_INFO "%s: %s\n", dev_info, version);
  768. return pcmcia_register_driver(&hostap_driver);
  769. }
  770. static void __exit exit_prism2_pccard(void)
  771. {
  772. pcmcia_unregister_driver(&hostap_driver);
  773. printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
  774. }
  775. module_init(init_prism2_pccard);
  776. module_exit(exit_prism2_pccard);