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