hostap_cs.c 22 KB

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