islpci_hotplug.c 9.2 KB

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