hostap_cs.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016
  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 hostap_cs_suspend(struct pcmcia_device *p_dev)
  707. {
  708. dev_link_t *link = dev_to_instance(p_dev);
  709. struct net_device *dev = (struct net_device *) link->priv;
  710. int dev_open = 0;
  711. PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_SUSPEND\n", dev_info);
  712. link->state |= DEV_SUSPEND;
  713. if (link->state & DEV_CONFIG) {
  714. struct hostap_interface *iface = netdev_priv(dev);
  715. if (iface && iface->local)
  716. dev_open = iface->local->num_dev_open > 0;
  717. if (dev_open) {
  718. netif_stop_queue(dev);
  719. netif_device_detach(dev);
  720. }
  721. prism2_suspend(dev);
  722. pcmcia_release_configuration(link->handle);
  723. }
  724. return 0;
  725. }
  726. static int hostap_cs_resume(struct pcmcia_device *p_dev)
  727. {
  728. dev_link_t *link = dev_to_instance(p_dev);
  729. struct net_device *dev = (struct net_device *) link->priv;
  730. int dev_open = 0;
  731. PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_RESUME\n", dev_info);
  732. link->state &= ~DEV_SUSPEND;
  733. if (link->state & DEV_CONFIG) {
  734. struct hostap_interface *iface = netdev_priv(dev);
  735. if (iface && iface->local)
  736. dev_open = iface->local->num_dev_open > 0;
  737. pcmcia_request_configuration(link->handle, &link->conf);
  738. prism2_hw_shutdown(dev, 1);
  739. prism2_hw_config(dev, dev_open ? 0 : 1);
  740. if (dev_open) {
  741. netif_device_attach(dev);
  742. netif_start_queue(dev);
  743. }
  744. }
  745. return 0;
  746. }
  747. static int prism2_event(event_t event, int priority,
  748. event_callback_args_t *args)
  749. {
  750. dev_link_t *link = args->client_data;
  751. struct net_device *dev = (struct net_device *) link->priv;
  752. switch (event) {
  753. case CS_EVENT_CARD_INSERTION:
  754. PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_CARD_INSERTION\n", dev_info);
  755. link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
  756. if (prism2_config(link)) {
  757. PDEBUG(DEBUG_EXTRA, "prism2_config() failed\n");
  758. }
  759. break;
  760. case CS_EVENT_CARD_REMOVAL:
  761. PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_CARD_REMOVAL\n", dev_info);
  762. link->state &= ~DEV_PRESENT;
  763. if (link->state & DEV_CONFIG) {
  764. netif_stop_queue(dev);
  765. netif_device_detach(dev);
  766. prism2_release((u_long) link);
  767. }
  768. break;
  769. default:
  770. PDEBUG(DEBUG_EXTRA, "%s: prism2_event() - unknown event %d\n",
  771. dev_info, event);
  772. break;
  773. }
  774. return 0;
  775. }
  776. static struct pcmcia_device_id hostap_cs_ids[] = {
  777. PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7100),
  778. PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7300),
  779. PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0777),
  780. PCMCIA_DEVICE_MANF_CARD(0x0126, 0x8000),
  781. PCMCIA_DEVICE_MANF_CARD(0x0138, 0x0002),
  782. PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0002),
  783. PCMCIA_DEVICE_MANF_CARD(0x0250, 0x0002),
  784. PCMCIA_DEVICE_MANF_CARD(0x026f, 0x030b),
  785. PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1612),
  786. PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1613),
  787. PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0002),
  788. PCMCIA_DEVICE_MANF_CARD(0x02aa, 0x0002),
  789. PCMCIA_DEVICE_MANF_CARD(0x02d2, 0x0001),
  790. PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x0001),
  791. PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x7300),
  792. PCMCIA_DEVICE_MANF_CARD(0xc00f, 0x0000),
  793. PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0002),
  794. PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005),
  795. PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0010),
  796. PCMCIA_MFC_DEVICE_PROD_ID12(0, "SanDisk", "ConnectPlus",
  797. 0x7a954bd9, 0x74be00c6),
  798. PCMCIA_DEVICE_PROD_ID1234(
  799. "Intersil", "PRISM 2_5 PCMCIA ADAPTER", "ISL37300P",
  800. "Eval-RevA",
  801. 0x4b801a17, 0x6345a0bf, 0xc9049a39, 0xc23adc0e),
  802. PCMCIA_DEVICE_PROD_ID123(
  803. "Addtron", "AWP-100 Wireless PCMCIA", "Version 01.02",
  804. 0xe6ec52ce, 0x08649af2, 0x4b74baa0),
  805. PCMCIA_DEVICE_PROD_ID123(
  806. "D", "Link DWL-650 11Mbps WLAN Card", "Version 01.02",
  807. 0x71b18589, 0xb6f1b0ab, 0x4b74baa0),
  808. PCMCIA_DEVICE_PROD_ID123(
  809. "Instant Wireless ", " Network PC CARD", "Version 01.02",
  810. 0x11d901af, 0x6e9bd926, 0x4b74baa0),
  811. PCMCIA_DEVICE_PROD_ID123(
  812. "SMC", "SMC2632W", "Version 01.02",
  813. 0xc4f8b18b, 0x474a1f2a, 0x4b74baa0),
  814. PCMCIA_DEVICE_PROD_ID12("BUFFALO", "WLI-CF-S11G",
  815. 0x2decece3, 0x82067c18),
  816. PCMCIA_DEVICE_PROD_ID12("Compaq", "WL200_11Mbps_Wireless_PCI_Card",
  817. 0x54f7c49c, 0x15a75e5b),
  818. PCMCIA_DEVICE_PROD_ID12("INTERSIL", "HFA384x/IEEE",
  819. 0x74c5e40d, 0xdb472a18),
  820. PCMCIA_DEVICE_PROD_ID12("Linksys", "Wireless CompactFlash Card",
  821. 0x0733cc81, 0x0c52f395),
  822. PCMCIA_DEVICE_PROD_ID12(
  823. "ZoomAir 11Mbps High", "Rate wireless Networking",
  824. 0x273fe3db, 0x32a1eaee),
  825. PCMCIA_DEVICE_NULL
  826. };
  827. MODULE_DEVICE_TABLE(pcmcia, hostap_cs_ids);
  828. static struct pcmcia_driver hostap_driver = {
  829. .drv = {
  830. .name = "hostap_cs",
  831. },
  832. .attach = prism2_attach,
  833. .detach = prism2_detach,
  834. .owner = THIS_MODULE,
  835. .event = prism2_event,
  836. .id_table = hostap_cs_ids,
  837. .suspend = hostap_cs_suspend,
  838. .resume = hostap_cs_resume,
  839. };
  840. static int __init init_prism2_pccard(void)
  841. {
  842. printk(KERN_INFO "%s: %s\n", dev_info, version);
  843. return pcmcia_register_driver(&hostap_driver);
  844. }
  845. static void __exit exit_prism2_pccard(void)
  846. {
  847. pcmcia_unregister_driver(&hostap_driver);
  848. printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
  849. }
  850. module_init(init_prism2_pccard);
  851. module_exit(exit_prism2_pccard);