islpci_hotplug.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /*
  2. * Copyright (C) 2002 Intersil Americas Inc.
  3. * Copyright (C) 2003 Herbert Valerio Riedel <hvr@gnu.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  16. *
  17. */
  18. #include <linux/interrupt.h>
  19. #include <linux/module.h>
  20. #include <linux/pci.h>
  21. #include <linux/delay.h>
  22. #include <linux/init.h> /* For __init, __exit */
  23. #include <linux/dma-mapping.h>
  24. #include "prismcompat.h"
  25. #include "islpci_dev.h"
  26. #include "islpci_mgt.h" /* for pc_debug */
  27. #include "isl_oid.h"
  28. MODULE_AUTHOR("[Intersil] R.Bastings and W.Termorshuizen, The prism54.org Development Team <prism54-devel@prism54.org>");
  29. MODULE_DESCRIPTION("The Prism54 802.11 Wireless LAN adapter");
  30. MODULE_LICENSE("GPL");
  31. static int init_pcitm = 0;
  32. module_param(init_pcitm, int, 0);
  33. /* In this order: vendor, device, subvendor, subdevice, class, class_mask,
  34. * driver_data
  35. * If you have an update for this please contact prism54-devel@prism54.org
  36. * The latest list can be found at http://wireless.kernel.org/en/users/Drivers/p54 */
  37. static const struct pci_device_id prism54_id_tbl[] = {
  38. /* Intersil PRISM Duette/Prism GT Wireless LAN adapter */
  39. {
  40. 0x1260, 0x3890,
  41. PCI_ANY_ID, PCI_ANY_ID,
  42. 0, 0, 0
  43. },
  44. /* 3COM 3CRWE154G72 Wireless LAN adapter */
  45. {
  46. PCI_VDEVICE(3COM, 0x6001), 0
  47. },
  48. /* Intersil PRISM Indigo Wireless LAN adapter */
  49. {
  50. 0x1260, 0x3877,
  51. PCI_ANY_ID, PCI_ANY_ID,
  52. 0, 0, 0
  53. },
  54. /* Intersil PRISM Javelin/Xbow Wireless LAN adapter */
  55. {
  56. 0x1260, 0x3886,
  57. PCI_ANY_ID, PCI_ANY_ID,
  58. 0, 0, 0
  59. },
  60. /* End of list */
  61. {0,0,0,0,0,0,0}
  62. };
  63. /* register the device with the Hotplug facilities of the kernel */
  64. MODULE_DEVICE_TABLE(pci, prism54_id_tbl);
  65. static int prism54_probe(struct pci_dev *, const struct pci_device_id *);
  66. static void prism54_remove(struct pci_dev *);
  67. static int prism54_suspend(struct pci_dev *, pm_message_t state);
  68. static int prism54_resume(struct pci_dev *);
  69. static struct pci_driver prism54_driver = {
  70. .name = DRV_NAME,
  71. .id_table = prism54_id_tbl,
  72. .probe = prism54_probe,
  73. .remove = prism54_remove,
  74. .suspend = prism54_suspend,
  75. .resume = prism54_resume,
  76. };
  77. /******************************************************************************
  78. Module initialization functions
  79. ******************************************************************************/
  80. static int
  81. prism54_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  82. {
  83. struct net_device *ndev;
  84. u8 latency_tmr;
  85. u32 mem_addr;
  86. islpci_private *priv;
  87. int rvalue;
  88. /* Enable the pci device */
  89. if (pci_enable_device(pdev)) {
  90. printk(KERN_ERR "%s: pci_enable_device() failed.\n", DRV_NAME);
  91. return -ENODEV;
  92. }
  93. /* check whether the latency timer is set correctly */
  94. pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency_tmr);
  95. #if VERBOSE > SHOW_ERROR_MESSAGES
  96. DEBUG(SHOW_TRACING, "latency timer: %x\n", latency_tmr);
  97. #endif
  98. if (latency_tmr < PCIDEVICE_LATENCY_TIMER_MIN) {
  99. /* set the latency timer */
  100. pci_write_config_byte(pdev, PCI_LATENCY_TIMER,
  101. PCIDEVICE_LATENCY_TIMER_VAL);
  102. }
  103. /* enable PCI DMA */
  104. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
  105. printk(KERN_ERR "%s: 32-bit PCI DMA not supported", DRV_NAME);
  106. goto do_pci_disable_device;
  107. }
  108. /* 0x40 is the programmable timer to configure the response timeout (TRDY_TIMEOUT)
  109. * 0x41 is the programmable timer to configure the retry timeout (RETRY_TIMEOUT)
  110. * The RETRY_TIMEOUT is used to set the number of retries that the core, as a
  111. * Master, will perform before abandoning a cycle. The default value for
  112. * RETRY_TIMEOUT is 0x80, which far exceeds the PCI 2.1 requirement for new
  113. * devices. A write of zero to the RETRY_TIMEOUT register disables this
  114. * function to allow use with any non-compliant legacy devices that may
  115. * execute more retries.
  116. *
  117. * Writing zero to both these two registers will disable both timeouts and
  118. * *can* solve problems caused by devices that are slow to respond.
  119. * Make this configurable - MSW
  120. */
  121. if ( init_pcitm >= 0 ) {
  122. pci_write_config_byte(pdev, 0x40, (u8)init_pcitm);
  123. pci_write_config_byte(pdev, 0x41, (u8)init_pcitm);
  124. } else {
  125. printk(KERN_INFO "PCI TRDY/RETRY unchanged\n");
  126. }
  127. /* request the pci device I/O regions */
  128. rvalue = pci_request_regions(pdev, DRV_NAME);
  129. if (rvalue) {
  130. printk(KERN_ERR "%s: pci_request_regions failure (rc=%d)\n",
  131. DRV_NAME, rvalue);
  132. goto do_pci_disable_device;
  133. }
  134. /* check if the memory window is indeed set */
  135. rvalue = pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &mem_addr);
  136. if (rvalue || !mem_addr) {
  137. printk(KERN_ERR "%s: PCI device memory region not configured; fix your BIOS or CardBus bridge/drivers\n",
  138. DRV_NAME);
  139. goto do_pci_release_regions;
  140. }
  141. /* enable PCI bus-mastering */
  142. DEBUG(SHOW_TRACING, "%s: pci_set_master(pdev)\n", DRV_NAME);
  143. pci_set_master(pdev);
  144. /* enable MWI */
  145. pci_try_set_mwi(pdev);
  146. /* setup the network device interface and its structure */
  147. if (!(ndev = islpci_setup(pdev))) {
  148. /* error configuring the driver as a network device */
  149. printk(KERN_ERR "%s: could not configure network device\n",
  150. DRV_NAME);
  151. goto do_pci_clear_mwi;
  152. }
  153. priv = netdev_priv(ndev);
  154. islpci_set_state(priv, PRV_STATE_PREBOOT); /* we are attempting to boot */
  155. /* card is in unknown state yet, might have some interrupts pending */
  156. isl38xx_disable_interrupts(priv->device_base);
  157. /* request for the interrupt before uploading the firmware */
  158. rvalue = request_irq(pdev->irq, islpci_interrupt,
  159. IRQF_SHARED, ndev->name, priv);
  160. if (rvalue) {
  161. /* error, could not hook the handler to the irq */
  162. printk(KERN_ERR "%s: could not install IRQ handler\n",
  163. ndev->name);
  164. goto do_unregister_netdev;
  165. }
  166. /* firmware upload is triggered in islpci_open */
  167. return 0;
  168. do_unregister_netdev:
  169. unregister_netdev(ndev);
  170. islpci_free_memory(priv);
  171. free_netdev(ndev);
  172. priv = NULL;
  173. do_pci_clear_mwi:
  174. pci_clear_mwi(pdev);
  175. do_pci_release_regions:
  176. pci_release_regions(pdev);
  177. do_pci_disable_device:
  178. pci_disable_device(pdev);
  179. return -EIO;
  180. }
  181. /* set by cleanup_module */
  182. static volatile int __in_cleanup_module = 0;
  183. /* this one removes one(!!) instance only */
  184. static void
  185. prism54_remove(struct pci_dev *pdev)
  186. {
  187. struct net_device *ndev = pci_get_drvdata(pdev);
  188. islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
  189. BUG_ON(!priv);
  190. if (!__in_cleanup_module) {
  191. printk(KERN_DEBUG "%s: hot unplug detected\n", ndev->name);
  192. islpci_set_state(priv, PRV_STATE_OFF);
  193. }
  194. printk(KERN_DEBUG "%s: removing device\n", ndev->name);
  195. unregister_netdev(ndev);
  196. /* free the interrupt request */
  197. if (islpci_get_state(priv) != PRV_STATE_OFF) {
  198. isl38xx_disable_interrupts(priv->device_base);
  199. islpci_set_state(priv, PRV_STATE_OFF);
  200. /* This bellow causes a lockup at rmmod time. It might be
  201. * because some interrupts still linger after rmmod time,
  202. * see bug #17 */
  203. /* pci_set_power_state(pdev, 3);*/ /* try to power-off */
  204. }
  205. free_irq(pdev->irq, priv);
  206. /* free the PCI memory and unmap the remapped page */
  207. islpci_free_memory(priv);
  208. free_netdev(ndev);
  209. priv = NULL;
  210. pci_clear_mwi(pdev);
  211. pci_release_regions(pdev);
  212. pci_disable_device(pdev);
  213. }
  214. static int
  215. prism54_suspend(struct pci_dev *pdev, pm_message_t state)
  216. {
  217. struct net_device *ndev = pci_get_drvdata(pdev);
  218. islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
  219. BUG_ON(!priv);
  220. pci_save_state(pdev);
  221. /* tell the device not to trigger interrupts for now... */
  222. isl38xx_disable_interrupts(priv->device_base);
  223. /* from now on assume the hardware was already powered down
  224. and don't touch it anymore */
  225. islpci_set_state(priv, PRV_STATE_OFF);
  226. netif_stop_queue(ndev);
  227. netif_device_detach(ndev);
  228. return 0;
  229. }
  230. static int
  231. prism54_resume(struct pci_dev *pdev)
  232. {
  233. struct net_device *ndev = pci_get_drvdata(pdev);
  234. islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
  235. int err;
  236. BUG_ON(!priv);
  237. printk(KERN_NOTICE "%s: got resume request\n", ndev->name);
  238. err = pci_enable_device(pdev);
  239. if (err) {
  240. printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
  241. ndev->name);
  242. return err;
  243. }
  244. pci_restore_state(pdev);
  245. /* alright let's go into the PREBOOT state */
  246. islpci_reset(priv, 1);
  247. netif_device_attach(ndev);
  248. netif_start_queue(ndev);
  249. return 0;
  250. }
  251. static int __init
  252. prism54_module_init(void)
  253. {
  254. printk(KERN_INFO "Loaded %s driver, version %s\n",
  255. DRV_NAME, DRV_VERSION);
  256. __bug_on_wrong_struct_sizes ();
  257. return pci_register_driver(&prism54_driver);
  258. }
  259. /* by the time prism54_module_exit() terminates, as a postcondition
  260. * all instances will have been destroyed by calls to
  261. * prism54_remove() */
  262. static void __exit
  263. prism54_module_exit(void)
  264. {
  265. __in_cleanup_module = 1;
  266. pci_unregister_driver(&prism54_driver);
  267. printk(KERN_INFO "Unloaded %s driver\n", DRV_NAME);
  268. __in_cleanup_module = 0;
  269. }
  270. /* register entry points */
  271. module_init(prism54_module_init);
  272. module_exit(prism54_module_exit);
  273. /* EOF */