hostap_cs.c 22 KB

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