hostap_cs.c 24 KB

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