islpci_hotplug.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. */
  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://prism54.org/supported_cards.php */
  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. 0x10b7, 0x6001,
  47. PCI_ANY_ID, PCI_ANY_ID,
  48. 0, 0, 0
  49. },
  50. /* Intersil PRISM Indigo Wireless LAN adapter */
  51. {
  52. 0x1260, 0x3877,
  53. PCI_ANY_ID, PCI_ANY_ID,
  54. 0, 0, 0
  55. },
  56. /* Intersil PRISM Javelin/Xbow Wireless LAN adapter */
  57. {
  58. 0x1260, 0x3886,
  59. PCI_ANY_ID, PCI_ANY_ID,
  60. 0, 0, 0
  61. },
  62. /* End of list */
  63. {0,0,0,0,0,0,0}
  64. };
  65. /* register the device with the Hotplug facilities of the kernel */
  66. MODULE_DEVICE_TABLE(pci, prism54_id_tbl);
  67. static int prism54_probe(struct pci_dev *, const struct pci_device_id *);
  68. static void prism54_remove(struct pci_dev *);
  69. static int prism54_suspend(struct pci_dev *, pm_message_t state);
  70. static int prism54_resume(struct pci_dev *);
  71. static struct pci_driver prism54_driver = {
  72. .name = DRV_NAME,
  73. .id_table = prism54_id_tbl,
  74. .probe = prism54_probe,
  75. .remove = prism54_remove,
  76. .suspend = prism54_suspend,
  77. .resume = prism54_resume,
  78. };
  79. /******************************************************************************
  80. Module initialization functions
  81. ******************************************************************************/
  82. static int
  83. prism54_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  84. {
  85. struct net_device *ndev;
  86. u8 latency_tmr;
  87. u32 mem_addr;
  88. islpci_private *priv;
  89. int rvalue;
  90. /* Enable the pci device */
  91. if (pci_enable_device(pdev)) {
  92. printk(KERN_ERR "%s: pci_enable_device() failed.\n", DRV_NAME);
  93. return -ENODEV;
  94. }
  95. /* check whether the latency timer is set correctly */
  96. pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency_tmr);
  97. #if VERBOSE > SHOW_ERROR_MESSAGES
  98. DEBUG(SHOW_TRACING, "latency timer: %x\n", latency_tmr);
  99. #endif
  100. if (latency_tmr < PCIDEVICE_LATENCY_TIMER_MIN) {
  101. /* set the latency timer */
  102. pci_write_config_byte(pdev, PCI_LATENCY_TIMER,
  103. PCIDEVICE_LATENCY_TIMER_VAL);
  104. }
  105. /* enable PCI DMA */
  106. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
  107. printk(KERN_ERR "%s: 32-bit PCI DMA not supported", DRV_NAME);
  108. goto do_pci_disable_device;
  109. }
  110. /* 0x40 is the programmable timer to configure the response timeout (TRDY_TIMEOUT)
  111. * 0x41 is the programmable timer to configure the retry timeout (RETRY_TIMEOUT)
  112. * The RETRY_TIMEOUT is used to set the number of retries that the core, as a
  113. * Master, will perform before abandoning a cycle. The default value for
  114. * RETRY_TIMEOUT is 0x80, which far exceeds the PCI 2.1 requirement for new
  115. * devices. A write of zero to the RETRY_TIMEOUT register disables this
  116. * function to allow use with any non-compliant legacy devices that may
  117. * execute more retries.
  118. *
  119. * Writing zero to both these two registers will disable both timeouts and
  120. * *can* solve problems caused by devices that are slow to respond.
  121. * Make this configurable - MSW
  122. */
  123. if ( init_pcitm >= 0 ) {
  124. pci_write_config_byte(pdev, 0x40, (u8)init_pcitm);
  125. pci_write_config_byte(pdev, 0x41, (u8)init_pcitm);
  126. } else {
  127. printk(KERN_INFO "PCI TRDY/RETRY unchanged\n");
  128. }
  129. /* request the pci device I/O regions */
  130. rvalue = pci_request_regions(pdev, DRV_NAME);
  131. if (rvalue) {
  132. printk(KERN_ERR "%s: pci_request_regions failure (rc=%d)\n",
  133. DRV_NAME, rvalue);
  134. goto do_pci_disable_device;
  135. }
  136. /* check if the memory window is indeed set */
  137. rvalue = pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &mem_addr);
  138. if (rvalue || !mem_addr) {
  139. printk(KERN_ERR "%s: PCI device memory region not configured; fix your BIOS or CardBus bridge/drivers\n",
  140. DRV_NAME);
  141. goto do_pci_release_regions;
  142. }
  143. /* enable PCI bus-mastering */
  144. DEBUG(SHOW_TRACING, "%s: pci_set_master(pdev)\n", DRV_NAME);
  145. pci_set_master(pdev);
  146. /* enable MWI */
  147. pci_try_set_mwi(pdev);
  148. /* setup the network device interface and its structure */
  149. if (!(ndev = islpci_setup(pdev))) {
  150. /* error configuring the driver as a network device */
  151. printk(KERN_ERR "%s: could not configure network device\n",
  152. DRV_NAME);
  153. goto do_pci_clear_mwi;
  154. }
  155. priv = netdev_priv(ndev);
  156. islpci_set_state(priv, PRV_STATE_PREBOOT); /* we are attempting to boot */
  157. /* card is in unknown state yet, might have some interrupts pending */
  158. isl38xx_disable_interrupts(priv->device_base);
  159. /* request for the interrupt before uploading the firmware */
  160. rvalue = request_irq(pdev->irq, &islpci_interrupt,
  161. IRQF_SHARED, ndev->name, priv);
  162. if (rvalue) {
  163. /* error, could not hook the handler to the irq */
  164. printk(KERN_ERR "%s: could not install IRQ handler\n",
  165. ndev->name);
  166. goto do_unregister_netdev;
  167. }
  168. /* firmware upload is triggered in islpci_open */
  169. return 0;
  170. do_unregister_netdev:
  171. unregister_netdev(ndev);
  172. islpci_free_memory(priv);
  173. pci_set_drvdata(pdev, NULL);
  174. free_netdev(ndev);
  175. priv = NULL;
  176. do_pci_clear_mwi:
  177. pci_clear_mwi(pdev);
  178. do_pci_release_regions:
  179. pci_release_regions(pdev);
  180. do_pci_disable_device:
  181. pci_disable_device(pdev);
  182. return -EIO;
  183. }
  184. /* set by cleanup_module */
  185. static volatile int __in_cleanup_module = 0;
  186. /* this one removes one(!!) instance only */
  187. static void
  188. prism54_remove(struct pci_dev *pdev)
  189. {
  190. struct net_device *ndev = pci_get_drvdata(pdev);
  191. islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
  192. BUG_ON(!priv);
  193. if (!__in_cleanup_module) {
  194. printk(KERN_DEBUG "%s: hot unplug detected\n", ndev->name);
  195. islpci_set_state(priv, PRV_STATE_OFF);
  196. }
  197. printk(KERN_DEBUG "%s: removing device\n", ndev->name);
  198. unregister_netdev(ndev);
  199. /* free the interrupt request */
  200. if (islpci_get_state(priv) != PRV_STATE_OFF) {
  201. isl38xx_disable_interrupts(priv->device_base);
  202. islpci_set_state(priv, PRV_STATE_OFF);
  203. /* This bellow causes a lockup at rmmod time. It might be
  204. * because some interrupts still linger after rmmod time,
  205. * see bug #17 */
  206. /* pci_set_power_state(pdev, 3);*/ /* try to power-off */
  207. }
  208. free_irq(pdev->irq, priv);
  209. /* free the PCI memory and unmap the remapped page */
  210. islpci_free_memory(priv);
  211. pci_set_drvdata(pdev, NULL);
  212. free_netdev(ndev);
  213. priv = NULL;
  214. pci_clear_mwi(pdev);
  215. pci_release_regions(pdev);
  216. pci_disable_device(pdev);
  217. }
  218. static int
  219. prism54_suspend(struct pci_dev *pdev, pm_message_t state)
  220. {
  221. struct net_device *ndev = pci_get_drvdata(pdev);
  222. islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
  223. BUG_ON(!priv);
  224. pci_save_state(pdev);
  225. /* tell the device not to trigger interrupts for now... */
  226. isl38xx_disable_interrupts(priv->device_base);
  227. /* from now on assume the hardware was already powered down
  228. and don't touch it anymore */
  229. islpci_set_state(priv, PRV_STATE_OFF);
  230. netif_stop_queue(ndev);
  231. netif_device_detach(ndev);
  232. return 0;
  233. }
  234. static int
  235. prism54_resume(struct pci_dev *pdev)
  236. {
  237. struct net_device *ndev = pci_get_drvdata(pdev);
  238. islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
  239. int err;
  240. BUG_ON(!priv);
  241. printk(KERN_NOTICE "%s: got resume request\n", ndev->name);
  242. err = pci_enable_device(pdev);
  243. if (err) {
  244. printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
  245. ndev->name);
  246. return err;
  247. }
  248. pci_restore_state(pdev);
  249. /* alright let's go into the PREBOOT state */
  250. islpci_reset(priv, 1);
  251. netif_device_attach(ndev);
  252. netif_start_queue(ndev);
  253. return 0;
  254. }
  255. static int __init
  256. prism54_module_init(void)
  257. {
  258. printk(KERN_INFO "Loaded %s driver, version %s\n",
  259. DRV_NAME, DRV_VERSION);
  260. __bug_on_wrong_struct_sizes ();
  261. return pci_register_driver(&prism54_driver);
  262. }
  263. /* by the time prism54_module_exit() terminates, as a postcondition
  264. * all instances will have been destroyed by calls to
  265. * prism54_remove() */
  266. static void __exit
  267. prism54_module_exit(void)
  268. {
  269. __in_cleanup_module = 1;
  270. pci_unregister_driver(&prism54_driver);
  271. printk(KERN_INFO "Unloaded %s driver\n", DRV_NAME);
  272. __in_cleanup_module = 0;
  273. }
  274. /* register entry points */
  275. module_init(prism54_module_init);
  276. module_exit(prism54_module_exit);
  277. /* EOF */