islpci_hotplug.c 8.6 KB

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