hostap_pci.c 10 KB

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