hostap_pci.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. #define PRISM2_PCI
  2. /* Host AP driver's support for Intersil Prism2.5 PCI cards is based on
  3. * driver patches from Reyk Floeter <reyk@vantronix.net> and
  4. * Andy Warner <andyw@pobox.com> */
  5. #include <linux/module.h>
  6. #include <linux/init.h>
  7. #include <linux/if.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 <linux/ioport.h>
  14. #include <linux/pci.h>
  15. #include <asm/io.h>
  16. #include "hostap_wlan.h"
  17. static char *version = PRISM2_VERSION " (Jouni Malinen <jkmaline@cc.hut.fi>)";
  18. static char *dev_info = "hostap_pci";
  19. MODULE_AUTHOR("Jouni Malinen");
  20. MODULE_DESCRIPTION("Support for Intersil Prism2.5-based 802.11 wireless LAN "
  21. "PCI cards.");
  22. MODULE_SUPPORTED_DEVICE("Intersil Prism2.5-based WLAN PCI cards");
  23. MODULE_LICENSE("GPL");
  24. MODULE_VERSION(PRISM2_VERSION);
  25. /* struct local_info::hw_priv */
  26. struct hostap_pci_priv {
  27. void __iomem *mem_start;
  28. };
  29. /* FIX: do we need mb/wmb/rmb with memory operations? */
  30. static struct pci_device_id prism2_pci_id_table[] __devinitdata = {
  31. /* Intersil Prism3 ISL3872 11Mb/s WLAN Controller */
  32. { 0x1260, 0x3872, PCI_ANY_ID, PCI_ANY_ID },
  33. /* Intersil Prism2.5 ISL3874 11Mb/s WLAN Controller */
  34. { 0x1260, 0x3873, PCI_ANY_ID, PCI_ANY_ID },
  35. /* Samsung MagicLAN SWL-2210P */
  36. { 0x167d, 0xa000, PCI_ANY_ID, PCI_ANY_ID },
  37. { 0 }
  38. };
  39. #ifdef PRISM2_IO_DEBUG
  40. static inline void hfa384x_outb_debug(struct net_device *dev, int a, u8 v)
  41. {
  42. struct hostap_interface *iface;
  43. struct hostap_pci_priv *hw_priv;
  44. local_info_t *local;
  45. unsigned long flags;
  46. iface = netdev_priv(dev);
  47. local = iface->local;
  48. hw_priv = local->hw_priv;
  49. spin_lock_irqsave(&local->lock, flags);
  50. prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTB, a, v);
  51. writeb(v, hw_priv->mem_start + a);
  52. spin_unlock_irqrestore(&local->lock, flags);
  53. }
  54. static inline u8 hfa384x_inb_debug(struct net_device *dev, int a)
  55. {
  56. struct hostap_interface *iface;
  57. struct hostap_pci_priv *hw_priv;
  58. local_info_t *local;
  59. unsigned long flags;
  60. u8 v;
  61. iface = netdev_priv(dev);
  62. local = iface->local;
  63. hw_priv = local->hw_priv;
  64. spin_lock_irqsave(&local->lock, flags);
  65. v = readb(hw_priv->mem_start + a);
  66. prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INB, a, v);
  67. spin_unlock_irqrestore(&local->lock, flags);
  68. return v;
  69. }
  70. static inline void hfa384x_outw_debug(struct net_device *dev, int a, u16 v)
  71. {
  72. struct hostap_interface *iface;
  73. struct hostap_pci_priv *hw_priv;
  74. local_info_t *local;
  75. unsigned long flags;
  76. iface = netdev_priv(dev);
  77. local = iface->local;
  78. hw_priv = local->hw_priv;
  79. spin_lock_irqsave(&local->lock, flags);
  80. prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTW, a, v);
  81. writew(v, hw_priv->mem_start + a);
  82. spin_unlock_irqrestore(&local->lock, flags);
  83. }
  84. static inline u16 hfa384x_inw_debug(struct net_device *dev, int a)
  85. {
  86. struct hostap_interface *iface;
  87. struct hostap_pci_priv *hw_priv;
  88. local_info_t *local;
  89. unsigned long flags;
  90. u16 v;
  91. iface = netdev_priv(dev);
  92. local = iface->local;
  93. hw_priv = local->hw_priv;
  94. spin_lock_irqsave(&local->lock, flags);
  95. v = readw(hw_priv->mem_start + a);
  96. prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INW, a, v);
  97. spin_unlock_irqrestore(&local->lock, flags);
  98. return v;
  99. }
  100. #define HFA384X_OUTB(v,a) hfa384x_outb_debug(dev, (a), (v))
  101. #define HFA384X_INB(a) hfa384x_inb_debug(dev, (a))
  102. #define HFA384X_OUTW(v,a) hfa384x_outw_debug(dev, (a), (v))
  103. #define HFA384X_INW(a) hfa384x_inw_debug(dev, (a))
  104. #define HFA384X_OUTW_DATA(v,a) hfa384x_outw_debug(dev, (a), cpu_to_le16((v)))
  105. #define HFA384X_INW_DATA(a) (u16) le16_to_cpu(hfa384x_inw_debug(dev, (a)))
  106. #else /* PRISM2_IO_DEBUG */
  107. static inline void hfa384x_outb(struct net_device *dev, int a, u8 v)
  108. {
  109. struct hostap_interface *iface;
  110. struct hostap_pci_priv *hw_priv;
  111. iface = netdev_priv(dev);
  112. hw_priv = iface->local->hw_priv;
  113. writeb(v, hw_priv->mem_start + a);
  114. }
  115. static inline u8 hfa384x_inb(struct net_device *dev, int a)
  116. {
  117. struct hostap_interface *iface;
  118. struct hostap_pci_priv *hw_priv;
  119. iface = netdev_priv(dev);
  120. hw_priv = iface->local->hw_priv;
  121. return readb(hw_priv->mem_start + a);
  122. }
  123. static inline void hfa384x_outw(struct net_device *dev, int a, u16 v)
  124. {
  125. struct hostap_interface *iface;
  126. struct hostap_pci_priv *hw_priv;
  127. iface = netdev_priv(dev);
  128. hw_priv = iface->local->hw_priv;
  129. writew(v, hw_priv->mem_start + a);
  130. }
  131. static inline u16 hfa384x_inw(struct net_device *dev, int a)
  132. {
  133. struct hostap_interface *iface;
  134. struct hostap_pci_priv *hw_priv;
  135. iface = netdev_priv(dev);
  136. hw_priv = iface->local->hw_priv;
  137. return readw(hw_priv->mem_start + a);
  138. }
  139. #define HFA384X_OUTB(v,a) hfa384x_outb(dev, (a), (v))
  140. #define HFA384X_INB(a) hfa384x_inb(dev, (a))
  141. #define HFA384X_OUTW(v,a) hfa384x_outw(dev, (a), (v))
  142. #define HFA384X_INW(a) hfa384x_inw(dev, (a))
  143. #define HFA384X_OUTW_DATA(v,a) hfa384x_outw(dev, (a), cpu_to_le16((v)))
  144. #define HFA384X_INW_DATA(a) (u16) le16_to_cpu(hfa384x_inw(dev, (a)))
  145. #endif /* PRISM2_IO_DEBUG */
  146. static int hfa384x_from_bap(struct net_device *dev, u16 bap, void *buf,
  147. int len)
  148. {
  149. u16 d_off;
  150. u16 *pos;
  151. d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF;
  152. pos = (u16 *) buf;
  153. for ( ; len > 1; len -= 2)
  154. *pos++ = HFA384X_INW_DATA(d_off);
  155. if (len & 1)
  156. *((char *) pos) = HFA384X_INB(d_off);
  157. return 0;
  158. }
  159. static int hfa384x_to_bap(struct net_device *dev, u16 bap, void *buf, int len)
  160. {
  161. u16 d_off;
  162. u16 *pos;
  163. d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF;
  164. pos = (u16 *) buf;
  165. for ( ; len > 1; len -= 2)
  166. HFA384X_OUTW_DATA(*pos++, d_off);
  167. if (len & 1)
  168. HFA384X_OUTB(*((char *) pos), d_off);
  169. return 0;
  170. }
  171. /* FIX: This might change at some point.. */
  172. #include "hostap_hw.c"
  173. static void prism2_pci_cor_sreset(local_info_t *local)
  174. {
  175. struct net_device *dev = local->dev;
  176. u16 reg;
  177. reg = HFA384X_INB(HFA384X_PCICOR_OFF);
  178. printk(KERN_DEBUG "%s: Original COR value: 0x%0x\n", dev->name, reg);
  179. /* linux-wlan-ng uses extremely long hold and settle times for
  180. * COR sreset. A comment in the driver code mentions that the long
  181. * delays appear to be necessary. However, at least IBM 22P6901 seems
  182. * to work fine with shorter delays.
  183. *
  184. * Longer delays can be configured by uncommenting following line: */
  185. /* #define PRISM2_PCI_USE_LONG_DELAYS */
  186. #ifdef PRISM2_PCI_USE_LONG_DELAYS
  187. int i;
  188. HFA384X_OUTW(reg | 0x0080, HFA384X_PCICOR_OFF);
  189. mdelay(250);
  190. HFA384X_OUTW(reg & ~0x0080, HFA384X_PCICOR_OFF);
  191. mdelay(500);
  192. /* Wait for f/w to complete initialization (CMD:BUSY == 0) */
  193. i = 2000000 / 10;
  194. while ((HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY) && --i)
  195. udelay(10);
  196. #else /* PRISM2_PCI_USE_LONG_DELAYS */
  197. HFA384X_OUTW(reg | 0x0080, HFA384X_PCICOR_OFF);
  198. mdelay(2);
  199. HFA384X_OUTW(reg & ~0x0080, HFA384X_PCICOR_OFF);
  200. mdelay(2);
  201. #endif /* PRISM2_PCI_USE_LONG_DELAYS */
  202. if (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY) {
  203. printk(KERN_DEBUG "%s: COR sreset timeout\n", dev->name);
  204. }
  205. }
  206. static void prism2_pci_genesis_reset(local_info_t *local, int hcr)
  207. {
  208. struct net_device *dev = local->dev;
  209. HFA384X_OUTW(0x00C5, HFA384X_PCICOR_OFF);
  210. mdelay(10);
  211. HFA384X_OUTW(hcr, HFA384X_PCIHCR_OFF);
  212. mdelay(10);
  213. HFA384X_OUTW(0x0045, HFA384X_PCICOR_OFF);
  214. mdelay(10);
  215. }
  216. static struct prism2_helper_functions prism2_pci_funcs =
  217. {
  218. .card_present = NULL,
  219. .cor_sreset = prism2_pci_cor_sreset,
  220. .genesis_reset = prism2_pci_genesis_reset,
  221. .hw_type = HOSTAP_HW_PCI,
  222. };
  223. static int prism2_pci_probe(struct pci_dev *pdev,
  224. const struct pci_device_id *id)
  225. {
  226. unsigned long phymem;
  227. void __iomem *mem = NULL;
  228. local_info_t *local = NULL;
  229. struct net_device *dev = NULL;
  230. static int cards_found /* = 0 */;
  231. int irq_registered = 0;
  232. struct hostap_interface *iface;
  233. struct hostap_pci_priv *hw_priv;
  234. hw_priv = kzalloc(sizeof(*hw_priv), GFP_KERNEL);
  235. if (hw_priv == NULL)
  236. return -ENOMEM;
  237. if (pci_enable_device(pdev))
  238. goto err_out_free;
  239. phymem = pci_resource_start(pdev, 0);
  240. if (!request_mem_region(phymem, pci_resource_len(pdev, 0), "Prism2")) {
  241. printk(KERN_ERR "prism2: Cannot reserve PCI memory region\n");
  242. goto err_out_disable;
  243. }
  244. mem = ioremap(phymem, pci_resource_len(pdev, 0));
  245. if (mem == NULL) {
  246. printk(KERN_ERR "prism2: Cannot remap PCI memory region\n") ;
  247. goto fail;
  248. }
  249. dev = prism2_init_local_data(&prism2_pci_funcs, cards_found,
  250. &pdev->dev);
  251. if (dev == NULL)
  252. goto fail;
  253. iface = netdev_priv(dev);
  254. local = iface->local;
  255. local->hw_priv = hw_priv;
  256. cards_found++;
  257. dev->irq = pdev->irq;
  258. hw_priv->mem_start = mem;
  259. prism2_pci_cor_sreset(local);
  260. pci_set_drvdata(pdev, dev);
  261. if (request_irq(dev->irq, prism2_interrupt, IRQF_SHARED, dev->name,
  262. dev)) {
  263. printk(KERN_WARNING "%s: request_irq failed\n", dev->name);
  264. goto fail;
  265. } else
  266. irq_registered = 1;
  267. if (!local->pri_only && prism2_hw_config(dev, 1)) {
  268. printk(KERN_DEBUG "%s: hardware initialization failed\n",
  269. dev_info);
  270. goto fail;
  271. }
  272. printk(KERN_INFO "%s: Intersil Prism2.5 PCI: "
  273. "mem=0x%lx, irq=%d\n", dev->name, phymem, dev->irq);
  274. return hostap_hw_ready(dev);
  275. fail:
  276. if (irq_registered && dev)
  277. free_irq(dev->irq, dev);
  278. if (mem)
  279. iounmap(mem);
  280. release_mem_region(phymem, pci_resource_len(pdev, 0));
  281. err_out_disable:
  282. pci_disable_device(pdev);
  283. prism2_free_local_data(dev);
  284. err_out_free:
  285. kfree(hw_priv);
  286. return -ENODEV;
  287. }
  288. static void prism2_pci_remove(struct pci_dev *pdev)
  289. {
  290. struct net_device *dev;
  291. struct hostap_interface *iface;
  292. void __iomem *mem_start;
  293. struct hostap_pci_priv *hw_priv;
  294. dev = pci_get_drvdata(pdev);
  295. iface = netdev_priv(dev);
  296. hw_priv = iface->local->hw_priv;
  297. /* Reset the hardware, and ensure interrupts are disabled. */
  298. prism2_pci_cor_sreset(iface->local);
  299. hfa384x_disable_interrupts(dev);
  300. if (dev->irq)
  301. free_irq(dev->irq, dev);
  302. mem_start = hw_priv->mem_start;
  303. prism2_free_local_data(dev);
  304. kfree(hw_priv);
  305. iounmap(mem_start);
  306. release_mem_region(pci_resource_start(pdev, 0),
  307. pci_resource_len(pdev, 0));
  308. pci_disable_device(pdev);
  309. }
  310. #ifdef CONFIG_PM
  311. static int prism2_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  312. {
  313. struct net_device *dev = pci_get_drvdata(pdev);
  314. if (netif_running(dev)) {
  315. netif_stop_queue(dev);
  316. netif_device_detach(dev);
  317. }
  318. prism2_suspend(dev);
  319. pci_save_state(pdev);
  320. pci_disable_device(pdev);
  321. pci_set_power_state(pdev, PCI_D3hot);
  322. return 0;
  323. }
  324. static int prism2_pci_resume(struct pci_dev *pdev)
  325. {
  326. struct net_device *dev = pci_get_drvdata(pdev);
  327. int err;
  328. err = pci_enable_device(pdev);
  329. if (err) {
  330. printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
  331. dev->name);
  332. return err;
  333. }
  334. pci_restore_state(pdev);
  335. prism2_hw_config(dev, 0);
  336. if (netif_running(dev)) {
  337. netif_device_attach(dev);
  338. netif_start_queue(dev);
  339. }
  340. return 0;
  341. }
  342. #endif /* CONFIG_PM */
  343. MODULE_DEVICE_TABLE(pci, prism2_pci_id_table);
  344. static struct pci_driver prism2_pci_drv_id = {
  345. .name = "hostap_pci",
  346. .id_table = prism2_pci_id_table,
  347. .probe = prism2_pci_probe,
  348. .remove = prism2_pci_remove,
  349. #ifdef CONFIG_PM
  350. .suspend = prism2_pci_suspend,
  351. .resume = prism2_pci_resume,
  352. #endif /* CONFIG_PM */
  353. /* Linux 2.4.6 added save_state and enable_wake that are not used here
  354. */
  355. };
  356. static int __init init_prism2_pci(void)
  357. {
  358. printk(KERN_INFO "%s: %s\n", dev_info, version);
  359. return pci_register_driver(&prism2_pci_drv_id);
  360. }
  361. static void __exit exit_prism2_pci(void)
  362. {
  363. pci_unregister_driver(&prism2_pci_drv_id);
  364. printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
  365. }
  366. module_init(init_prism2_pci);
  367. module_exit(exit_prism2_pci);