ioat.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * Intel I/OAT DMA Linux driver
  3. * Copyright(c) 2004 - 2007 Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. */
  22. /*
  23. * This driver supports an Intel I/OAT DMA engine, which does asynchronous
  24. * copy operations.
  25. */
  26. #include <linux/init.h>
  27. #include <linux/module.h>
  28. #include <linux/pci.h>
  29. #include <linux/interrupt.h>
  30. #include "ioatdma.h"
  31. #include "ioatdma_registers.h"
  32. #include "ioatdma_hw.h"
  33. MODULE_VERSION("1.24");
  34. MODULE_LICENSE("GPL");
  35. MODULE_AUTHOR("Intel Corporation");
  36. static struct pci_device_id ioat_pci_tbl[] = {
  37. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT) },
  38. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_CNB) },
  39. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_SCNB) },
  40. { PCI_DEVICE(PCI_VENDOR_ID_UNISYS, PCI_DEVICE_ID_UNISYS_DMA_DIRECTOR) },
  41. { 0, }
  42. };
  43. struct ioat_device {
  44. struct pci_dev *pdev;
  45. void __iomem *iobase;
  46. struct ioatdma_device *dma;
  47. };
  48. static int __devinit ioat_probe(struct pci_dev *pdev,
  49. const struct pci_device_id *id);
  50. #ifdef IOAT_DMA_REMOVE
  51. static void __devexit ioat_remove(struct pci_dev *pdev);
  52. #endif
  53. static int ioat_setup_functionality(struct pci_dev *pdev, void __iomem *iobase)
  54. {
  55. struct ioat_device *device = pci_get_drvdata(pdev);
  56. u8 version;
  57. int err = 0;
  58. version = readb(iobase + IOAT_VER_OFFSET);
  59. switch (version) {
  60. case IOAT_VER_1_2:
  61. device->dma = ioat_dma_probe(pdev, iobase);
  62. break;
  63. default:
  64. err = -ENODEV;
  65. break;
  66. }
  67. return err;
  68. }
  69. static void ioat_shutdown_functionality(struct pci_dev *pdev)
  70. {
  71. struct ioat_device *device = pci_get_drvdata(pdev);
  72. if (device->dma) {
  73. ioat_dma_remove(device->dma);
  74. device->dma = NULL;
  75. }
  76. }
  77. static struct pci_driver ioat_pci_drv = {
  78. .name = "ioatdma",
  79. .id_table = ioat_pci_tbl,
  80. .probe = ioat_probe,
  81. .shutdown = ioat_shutdown_functionality,
  82. #ifdef IOAT_DMA_REMOVE
  83. .remove = __devexit_p(ioat_remove),
  84. #endif
  85. };
  86. static int __devinit ioat_probe(struct pci_dev *pdev,
  87. const struct pci_device_id *id)
  88. {
  89. void __iomem *iobase;
  90. struct ioat_device *device;
  91. unsigned long mmio_start, mmio_len;
  92. int err;
  93. err = pci_enable_device(pdev);
  94. if (err)
  95. goto err_enable_device;
  96. err = pci_request_regions(pdev, ioat_pci_drv.name);
  97. if (err)
  98. goto err_request_regions;
  99. err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
  100. if (err)
  101. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  102. if (err)
  103. goto err_set_dma_mask;
  104. err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
  105. if (err)
  106. err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  107. if (err)
  108. goto err_set_dma_mask;
  109. mmio_start = pci_resource_start(pdev, 0);
  110. mmio_len = pci_resource_len(pdev, 0);
  111. iobase = ioremap(mmio_start, mmio_len);
  112. if (!iobase) {
  113. err = -ENOMEM;
  114. goto err_ioremap;
  115. }
  116. device = kzalloc(sizeof(*device), GFP_KERNEL);
  117. if (!device) {
  118. err = -ENOMEM;
  119. goto err_kzalloc;
  120. }
  121. device->pdev = pdev;
  122. pci_set_drvdata(pdev, device);
  123. device->iobase = iobase;
  124. pci_set_master(pdev);
  125. err = ioat_setup_functionality(pdev, iobase);
  126. if (err)
  127. goto err_version;
  128. return 0;
  129. err_version:
  130. kfree(device);
  131. err_kzalloc:
  132. iounmap(iobase);
  133. err_ioremap:
  134. err_set_dma_mask:
  135. pci_release_regions(pdev);
  136. pci_disable_device(pdev);
  137. err_request_regions:
  138. err_enable_device:
  139. return err;
  140. }
  141. #ifdef IOAT_DMA_REMOVE
  142. /*
  143. * It is unsafe to remove this module: if removed while a requested
  144. * dma is outstanding, esp. from tcp, it is possible to hang while
  145. * waiting for something that will never finish, thus hanging at
  146. * least one cpu. However, if you're feeling lucky and need to do
  147. * some testing, this usually works just fine.
  148. */
  149. static void __devexit ioat_remove(struct pci_dev *pdev)
  150. {
  151. struct ioat_device *device = pci_get_drvdata(pdev);
  152. ioat_shutdown_functionality(pdev);
  153. kfree(device);
  154. iounmap(device->iobase);
  155. pci_release_regions(pdev);
  156. pci_disable_device(pdev);
  157. }
  158. #endif
  159. static int __init ioat_init_module(void)
  160. {
  161. return pci_register_driver(&ioat_pci_drv);
  162. }
  163. module_init(ioat_init_module);
  164. static void __exit ioat_exit_module(void)
  165. {
  166. pci_unregister_driver(&ioat_pci_drv);
  167. }
  168. module_exit(ioat_exit_module);