hostap_cs.c 26 KB

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