hostap_cs.c 26 KB

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