hostap_cs.c 27 KB

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