hostap_pci.c 11 KB

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