hostap_cs.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  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(dev_link_t *link);
  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);
  436. return NULL;
  437. }
  438. return link;
  439. }
  440. static void prism2_detach(dev_link_t *link)
  441. {
  442. dev_link_t **linkp;
  443. PDEBUG(DEBUG_FLOW, "prism2_detach\n");
  444. for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
  445. if (*linkp == link)
  446. break;
  447. if (*linkp == NULL) {
  448. printk(KERN_WARNING "%s: Attempt to detach non-existing "
  449. "PCMCIA client\n", dev_info);
  450. return;
  451. }
  452. if (link->state & DEV_CONFIG) {
  453. prism2_release((u_long)link);
  454. }
  455. if (link->handle) {
  456. int res = pcmcia_deregister_client(link->handle);
  457. if (res) {
  458. printk("CardService(DeregisterClient) => %d\n", res);
  459. cs_error(link->handle, DeregisterClient, res);
  460. }
  461. }
  462. *linkp = link->next;
  463. /* release net devices */
  464. if (link->priv) {
  465. struct net_device *dev;
  466. struct hostap_interface *iface;
  467. dev = link->priv;
  468. iface = netdev_priv(dev);
  469. kfree(iface->local->hw_priv);
  470. iface->local->hw_priv = NULL;
  471. prism2_free_local_data(dev);
  472. }
  473. kfree(link);
  474. }
  475. #define CS_CHECK(fn, ret) \
  476. do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
  477. #define CFG_CHECK2(fn, retf) \
  478. do { int ret = (retf); \
  479. if (ret != 0) { \
  480. PDEBUG(DEBUG_EXTRA, "CardServices(" #fn ") returned %d\n", ret); \
  481. cs_error(link->handle, fn, ret); \
  482. goto next_entry; \
  483. } \
  484. } while (0)
  485. /* run after a CARD_INSERTION event is received to configure the PCMCIA
  486. * socket and make the device available to the system */
  487. static int prism2_config(dev_link_t *link)
  488. {
  489. struct net_device *dev;
  490. struct hostap_interface *iface;
  491. local_info_t *local;
  492. int ret = 1;
  493. tuple_t tuple;
  494. cisparse_t *parse;
  495. int last_fn, last_ret;
  496. u_char buf[64];
  497. config_info_t conf;
  498. cistpl_cftable_entry_t dflt = { 0 };
  499. struct hostap_cs_priv *hw_priv;
  500. PDEBUG(DEBUG_FLOW, "prism2_config()\n");
  501. parse = kmalloc(sizeof(cisparse_t), GFP_KERNEL);
  502. hw_priv = kmalloc(sizeof(*hw_priv), GFP_KERNEL);
  503. if (parse == NULL || hw_priv == NULL) {
  504. kfree(parse);
  505. kfree(hw_priv);
  506. ret = -ENOMEM;
  507. goto failed;
  508. }
  509. memset(hw_priv, 0, sizeof(*hw_priv));
  510. tuple.DesiredTuple = CISTPL_CONFIG;
  511. tuple.Attributes = 0;
  512. tuple.TupleData = buf;
  513. tuple.TupleDataMax = sizeof(buf);
  514. tuple.TupleOffset = 0;
  515. CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link->handle, &tuple));
  516. CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link->handle, &tuple));
  517. CS_CHECK(ParseTuple, pcmcia_parse_tuple(link->handle, &tuple, parse));
  518. link->conf.ConfigBase = parse->config.base;
  519. link->conf.Present = parse->config.rmask[0];
  520. CS_CHECK(GetConfigurationInfo,
  521. pcmcia_get_configuration_info(link->handle, &conf));
  522. PDEBUG(DEBUG_HW, "%s: %s Vcc=%d (from config)\n", dev_info,
  523. ignore_cis_vcc ? "ignoring" : "setting", conf.Vcc);
  524. link->conf.Vcc = conf.Vcc;
  525. /* Look for an appropriate configuration table entry in the CIS */
  526. tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
  527. CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link->handle, &tuple));
  528. for (;;) {
  529. cistpl_cftable_entry_t *cfg = &(parse->cftable_entry);
  530. CFG_CHECK2(GetTupleData,
  531. pcmcia_get_tuple_data(link->handle, &tuple));
  532. CFG_CHECK2(ParseTuple,
  533. pcmcia_parse_tuple(link->handle, &tuple, parse));
  534. if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
  535. dflt = *cfg;
  536. if (cfg->index == 0)
  537. goto next_entry;
  538. link->conf.ConfigIndex = cfg->index;
  539. PDEBUG(DEBUG_EXTRA, "Checking CFTABLE_ENTRY 0x%02X "
  540. "(default 0x%02X)\n", cfg->index, dflt.index);
  541. /* Does this card need audio output? */
  542. if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
  543. link->conf.Attributes |= CONF_ENABLE_SPKR;
  544. link->conf.Status = CCSR_AUDIO_ENA;
  545. }
  546. /* Use power settings for Vcc and Vpp if present */
  547. /* Note that the CIS values need to be rescaled */
  548. if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
  549. if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] /
  550. 10000 && !ignore_cis_vcc) {
  551. PDEBUG(DEBUG_EXTRA, " Vcc mismatch - skipping"
  552. " this entry\n");
  553. goto next_entry;
  554. }
  555. } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
  556. if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] /
  557. 10000 && !ignore_cis_vcc) {
  558. PDEBUG(DEBUG_EXTRA, " Vcc (default) mismatch "
  559. "- skipping this entry\n");
  560. goto next_entry;
  561. }
  562. }
  563. if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
  564. link->conf.Vpp1 = link->conf.Vpp2 =
  565. cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
  566. else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
  567. link->conf.Vpp1 = link->conf.Vpp2 =
  568. dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
  569. /* Do we need to allocate an interrupt? */
  570. if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
  571. link->conf.Attributes |= CONF_ENABLE_IRQ;
  572. else if (!(link->conf.Attributes & CONF_ENABLE_IRQ)) {
  573. /* At least Compaq WL200 does not have IRQInfo1 set,
  574. * but it does not work without interrupts.. */
  575. printk("Config has no IRQ info, but trying to enable "
  576. "IRQ anyway..\n");
  577. link->conf.Attributes |= CONF_ENABLE_IRQ;
  578. }
  579. /* IO window settings */
  580. PDEBUG(DEBUG_EXTRA, "IO window settings: cfg->io.nwin=%d "
  581. "dflt.io.nwin=%d\n",
  582. cfg->io.nwin, dflt.io.nwin);
  583. link->io.NumPorts1 = link->io.NumPorts2 = 0;
  584. if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
  585. cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
  586. link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
  587. PDEBUG(DEBUG_EXTRA, "io->flags = 0x%04X, "
  588. "io.base=0x%04x, len=%d\n", io->flags,
  589. io->win[0].base, io->win[0].len);
  590. if (!(io->flags & CISTPL_IO_8BIT))
  591. link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
  592. if (!(io->flags & CISTPL_IO_16BIT))
  593. link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  594. link->io.IOAddrLines = io->flags &
  595. CISTPL_IO_LINES_MASK;
  596. link->io.BasePort1 = io->win[0].base;
  597. link->io.NumPorts1 = io->win[0].len;
  598. if (io->nwin > 1) {
  599. link->io.Attributes2 = link->io.Attributes1;
  600. link->io.BasePort2 = io->win[1].base;
  601. link->io.NumPorts2 = io->win[1].len;
  602. }
  603. }
  604. /* This reserves IO space but doesn't actually enable it */
  605. CFG_CHECK2(RequestIO,
  606. pcmcia_request_io(link->handle, &link->io));
  607. /* This configuration table entry is OK */
  608. break;
  609. next_entry:
  610. CS_CHECK(GetNextTuple,
  611. pcmcia_get_next_tuple(link->handle, &tuple));
  612. }
  613. /* Need to allocate net_device before requesting IRQ handler */
  614. dev = prism2_init_local_data(&prism2_pccard_funcs, 0,
  615. &handle_to_dev(link->handle));
  616. if (dev == NULL)
  617. goto failed;
  618. link->priv = dev;
  619. iface = netdev_priv(dev);
  620. local = iface->local;
  621. local->hw_priv = hw_priv;
  622. hw_priv->link = link;
  623. strcpy(hw_priv->node.dev_name, dev->name);
  624. link->dev = &hw_priv->node;
  625. /*
  626. * Allocate an interrupt line. Note that this does not assign a
  627. * handler to the interrupt, unless the 'Handler' member of the
  628. * irq structure is initialized.
  629. */
  630. if (link->conf.Attributes & CONF_ENABLE_IRQ) {
  631. link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
  632. link->irq.IRQInfo1 = IRQ_LEVEL_ID;
  633. link->irq.Handler = prism2_interrupt;
  634. link->irq.Instance = dev;
  635. CS_CHECK(RequestIRQ,
  636. pcmcia_request_irq(link->handle, &link->irq));
  637. }
  638. /*
  639. * This actually configures the PCMCIA socket -- setting up
  640. * the I/O windows and the interrupt mapping, and putting the
  641. * card and host interface into "Memory and IO" mode.
  642. */
  643. CS_CHECK(RequestConfiguration,
  644. pcmcia_request_configuration(link->handle, &link->conf));
  645. dev->irq = link->irq.AssignedIRQ;
  646. dev->base_addr = link->io.BasePort1;
  647. /* Finally, report what we've done */
  648. printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d",
  649. dev_info, link->conf.ConfigIndex,
  650. link->conf.Vcc / 10, link->conf.Vcc % 10);
  651. if (link->conf.Vpp1)
  652. printk(", Vpp %d.%d", link->conf.Vpp1 / 10,
  653. link->conf.Vpp1 % 10);
  654. if (link->conf.Attributes & CONF_ENABLE_IRQ)
  655. printk(", irq %d", link->irq.AssignedIRQ);
  656. if (link->io.NumPorts1)
  657. printk(", io 0x%04x-0x%04x", link->io.BasePort1,
  658. link->io.BasePort1+link->io.NumPorts1-1);
  659. if (link->io.NumPorts2)
  660. printk(" & 0x%04x-0x%04x", link->io.BasePort2,
  661. link->io.BasePort2+link->io.NumPorts2-1);
  662. printk("\n");
  663. link->state |= DEV_CONFIG;
  664. link->state &= ~DEV_CONFIG_PENDING;
  665. local->shutdown = 0;
  666. sandisk_enable_wireless(dev);
  667. ret = prism2_hw_config(dev, 1);
  668. if (!ret) {
  669. ret = hostap_hw_ready(dev);
  670. if (ret == 0 && local->ddev)
  671. strcpy(hw_priv->node.dev_name, local->ddev->name);
  672. }
  673. kfree(parse);
  674. return ret;
  675. cs_failed:
  676. cs_error(link->handle, last_fn, last_ret);
  677. failed:
  678. kfree(parse);
  679. kfree(hw_priv);
  680. prism2_release((u_long)link);
  681. return ret;
  682. }
  683. static void prism2_release(u_long arg)
  684. {
  685. dev_link_t *link = (dev_link_t *)arg;
  686. PDEBUG(DEBUG_FLOW, "prism2_release\n");
  687. if (link->priv) {
  688. struct net_device *dev = link->priv;
  689. struct hostap_interface *iface;
  690. iface = netdev_priv(dev);
  691. if (link->state & DEV_CONFIG)
  692. prism2_hw_shutdown(dev, 0);
  693. iface->local->shutdown = 1;
  694. }
  695. if (link->win)
  696. pcmcia_release_window(link->win);
  697. pcmcia_release_configuration(link->handle);
  698. if (link->io.NumPorts1)
  699. pcmcia_release_io(link->handle, &link->io);
  700. if (link->irq.AssignedIRQ)
  701. pcmcia_release_irq(link->handle, &link->irq);
  702. link->state &= ~DEV_CONFIG;
  703. PDEBUG(DEBUG_FLOW, "release - done\n");
  704. }
  705. static int prism2_event(event_t event, int priority,
  706. event_callback_args_t *args)
  707. {
  708. dev_link_t *link = args->client_data;
  709. struct net_device *dev = (struct net_device *) link->priv;
  710. int dev_open = 0;
  711. if (link->state & DEV_CONFIG) {
  712. struct hostap_interface *iface = netdev_priv(dev);
  713. if (iface && iface->local)
  714. dev_open = iface->local->num_dev_open > 0;
  715. }
  716. switch (event) {
  717. case CS_EVENT_CARD_INSERTION:
  718. PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_CARD_INSERTION\n", dev_info);
  719. link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
  720. if (prism2_config(link)) {
  721. PDEBUG(DEBUG_EXTRA, "prism2_config() failed\n");
  722. }
  723. break;
  724. case CS_EVENT_CARD_REMOVAL:
  725. PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_CARD_REMOVAL\n", dev_info);
  726. link->state &= ~DEV_PRESENT;
  727. if (link->state & DEV_CONFIG) {
  728. netif_stop_queue(dev);
  729. netif_device_detach(dev);
  730. prism2_release((u_long) link);
  731. }
  732. break;
  733. case CS_EVENT_PM_SUSPEND:
  734. PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_SUSPEND\n", dev_info);
  735. link->state |= DEV_SUSPEND;
  736. /* fall through */
  737. case CS_EVENT_RESET_PHYSICAL:
  738. PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_RESET_PHYSICAL\n", dev_info);
  739. if (link->state & DEV_CONFIG) {
  740. if (dev_open) {
  741. netif_stop_queue(dev);
  742. netif_device_detach(dev);
  743. }
  744. prism2_suspend(dev);
  745. pcmcia_release_configuration(link->handle);
  746. }
  747. break;
  748. case CS_EVENT_PM_RESUME:
  749. PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_RESUME\n", dev_info);
  750. link->state &= ~DEV_SUSPEND;
  751. /* fall through */
  752. case CS_EVENT_CARD_RESET:
  753. PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_CARD_RESET\n", dev_info);
  754. if (link->state & DEV_CONFIG) {
  755. pcmcia_request_configuration(link->handle,
  756. &link->conf);
  757. prism2_hw_shutdown(dev, 1);
  758. prism2_hw_config(dev, dev_open ? 0 : 1);
  759. if (dev_open) {
  760. netif_device_attach(dev);
  761. netif_start_queue(dev);
  762. }
  763. }
  764. break;
  765. default:
  766. PDEBUG(DEBUG_EXTRA, "%s: prism2_event() - unknown event %d\n",
  767. dev_info, event);
  768. break;
  769. }
  770. return 0;
  771. }
  772. static struct pcmcia_device_id hostap_cs_ids[] = {
  773. PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7100),
  774. PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7300),
  775. PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0777),
  776. PCMCIA_DEVICE_MANF_CARD(0x0126, 0x8000),
  777. PCMCIA_DEVICE_MANF_CARD(0x0138, 0x0002),
  778. PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0002),
  779. PCMCIA_DEVICE_MANF_CARD(0x0250, 0x0002),
  780. PCMCIA_DEVICE_MANF_CARD(0x026f, 0x030b),
  781. PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1612),
  782. PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1613),
  783. PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0002),
  784. PCMCIA_DEVICE_MANF_CARD(0x02aa, 0x0002),
  785. PCMCIA_DEVICE_MANF_CARD(0x02d2, 0x0001),
  786. PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x0001),
  787. PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x7300),
  788. PCMCIA_DEVICE_MANF_CARD(0xc00f, 0x0000),
  789. PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0002),
  790. PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005),
  791. PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0010),
  792. PCMCIA_MFC_DEVICE_PROD_ID12(0, "SanDisk", "ConnectPlus",
  793. 0x7a954bd9, 0x74be00c6),
  794. PCMCIA_DEVICE_PROD_ID1234(
  795. "Intersil", "PRISM 2_5 PCMCIA ADAPTER", "ISL37300P",
  796. "Eval-RevA",
  797. 0x4b801a17, 0x6345a0bf, 0xc9049a39, 0xc23adc0e),
  798. PCMCIA_DEVICE_PROD_ID123(
  799. "Addtron", "AWP-100 Wireless PCMCIA", "Version 01.02",
  800. 0xe6ec52ce, 0x08649af2, 0x4b74baa0),
  801. PCMCIA_DEVICE_PROD_ID123(
  802. "D", "Link DWL-650 11Mbps WLAN Card", "Version 01.02",
  803. 0x71b18589, 0xb6f1b0ab, 0x4b74baa0),
  804. PCMCIA_DEVICE_PROD_ID123(
  805. "Instant Wireless ", " Network PC CARD", "Version 01.02",
  806. 0x11d901af, 0x6e9bd926, 0x4b74baa0),
  807. PCMCIA_DEVICE_PROD_ID123(
  808. "SMC", "SMC2632W", "Version 01.02",
  809. 0xc4f8b18b, 0x474a1f2a, 0x4b74baa0),
  810. PCMCIA_DEVICE_PROD_ID12("BUFFALO", "WLI-CF-S11G",
  811. 0x2decece3, 0x82067c18),
  812. PCMCIA_DEVICE_PROD_ID12("Compaq", "WL200_11Mbps_Wireless_PCI_Card",
  813. 0x54f7c49c, 0x15a75e5b),
  814. PCMCIA_DEVICE_PROD_ID12("INTERSIL", "HFA384x/IEEE",
  815. 0x74c5e40d, 0xdb472a18),
  816. PCMCIA_DEVICE_PROD_ID12("Linksys", "Wireless CompactFlash Card",
  817. 0x0733cc81, 0x0c52f395),
  818. PCMCIA_DEVICE_PROD_ID12(
  819. "ZoomAir 11Mbps High", "Rate wireless Networking",
  820. 0x273fe3db, 0x32a1eaee),
  821. PCMCIA_DEVICE_NULL
  822. };
  823. MODULE_DEVICE_TABLE(pcmcia, hostap_cs_ids);
  824. static struct pcmcia_driver hostap_driver = {
  825. .drv = {
  826. .name = "hostap_cs",
  827. },
  828. .attach = prism2_attach,
  829. .detach = prism2_detach,
  830. .owner = THIS_MODULE,
  831. .event = prism2_event,
  832. .id_table = hostap_cs_ids,
  833. };
  834. static int __init init_prism2_pccard(void)
  835. {
  836. printk(KERN_INFO "%s: %s\n", dev_info, version);
  837. return pcmcia_register_driver(&hostap_driver);
  838. }
  839. static void __exit exit_prism2_pccard(void)
  840. {
  841. pcmcia_unregister_driver(&hostap_driver);
  842. printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
  843. }
  844. module_init(init_prism2_pccard);
  845. module_exit(exit_prism2_pccard);