hostap_cs.c 24 KB

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