hostap_cs.c 27 KB

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