hostap_pci.c 11 KB

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