ioat.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Intel I/OAT DMA Linux driver
  3. * Copyright(c) 2007 - 2009 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 <linux/dca.h>
  31. #include "ioatdma.h"
  32. #include "ioatdma_registers.h"
  33. #include "ioatdma_hw.h"
  34. MODULE_VERSION(IOAT_DMA_VERSION);
  35. MODULE_LICENSE("GPL");
  36. MODULE_AUTHOR("Intel Corporation");
  37. static struct pci_device_id ioat_pci_tbl[] = {
  38. /* I/OAT v1 platforms */
  39. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT) },
  40. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_CNB) },
  41. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_SCNB) },
  42. { PCI_DEVICE(PCI_VENDOR_ID_UNISYS, PCI_DEVICE_ID_UNISYS_DMA_DIRECTOR) },
  43. /* I/OAT v2 platforms */
  44. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_SNB) },
  45. /* I/OAT v3 platforms */
  46. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG0) },
  47. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG1) },
  48. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG2) },
  49. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG3) },
  50. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG4) },
  51. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG5) },
  52. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG6) },
  53. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG7) },
  54. { 0, }
  55. };
  56. struct ioat_device {
  57. struct pci_dev *pdev;
  58. void __iomem *iobase;
  59. struct ioatdma_device *dma;
  60. struct dca_provider *dca;
  61. };
  62. static int __devinit ioat_probe(struct pci_dev *pdev,
  63. const struct pci_device_id *id);
  64. static void __devexit ioat_remove(struct pci_dev *pdev);
  65. static int ioat_dca_enabled = 1;
  66. module_param(ioat_dca_enabled, int, 0644);
  67. MODULE_PARM_DESC(ioat_dca_enabled, "control support of dca service (default: 1)");
  68. static struct pci_driver ioat_pci_driver = {
  69. .name = "ioatdma",
  70. .id_table = ioat_pci_tbl,
  71. .probe = ioat_probe,
  72. .remove = __devexit_p(ioat_remove),
  73. };
  74. static int __devinit ioat_probe(struct pci_dev *pdev,
  75. const struct pci_device_id *id)
  76. {
  77. void __iomem *iobase;
  78. struct ioat_device *device;
  79. unsigned long mmio_start, mmio_len;
  80. int err;
  81. err = pci_enable_device(pdev);
  82. if (err)
  83. goto err_enable_device;
  84. err = pci_request_regions(pdev, ioat_pci_driver.name);
  85. if (err)
  86. goto err_request_regions;
  87. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
  88. if (err)
  89. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  90. if (err)
  91. goto err_set_dma_mask;
  92. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  93. if (err)
  94. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  95. if (err)
  96. goto err_set_dma_mask;
  97. mmio_start = pci_resource_start(pdev, 0);
  98. mmio_len = pci_resource_len(pdev, 0);
  99. iobase = ioremap(mmio_start, mmio_len);
  100. if (!iobase) {
  101. err = -ENOMEM;
  102. goto err_ioremap;
  103. }
  104. device = kzalloc(sizeof(*device), GFP_KERNEL);
  105. if (!device) {
  106. err = -ENOMEM;
  107. goto err_kzalloc;
  108. }
  109. device->pdev = pdev;
  110. pci_set_drvdata(pdev, device);
  111. device->iobase = iobase;
  112. pci_set_master(pdev);
  113. switch (readb(iobase + IOAT_VER_OFFSET)) {
  114. case IOAT_VER_1_2:
  115. device->dma = ioat_dma_probe(pdev, iobase);
  116. if (device->dma && ioat_dca_enabled)
  117. device->dca = ioat_dca_init(pdev, iobase);
  118. break;
  119. case IOAT_VER_2_0:
  120. device->dma = ioat_dma_probe(pdev, iobase);
  121. if (device->dma && ioat_dca_enabled)
  122. device->dca = ioat2_dca_init(pdev, iobase);
  123. break;
  124. case IOAT_VER_3_0:
  125. device->dma = ioat_dma_probe(pdev, iobase);
  126. if (device->dma && ioat_dca_enabled)
  127. device->dca = ioat3_dca_init(pdev, iobase);
  128. break;
  129. default:
  130. err = -ENODEV;
  131. break;
  132. }
  133. if (!device->dma)
  134. err = -ENODEV;
  135. if (err)
  136. goto err_version;
  137. return 0;
  138. err_version:
  139. kfree(device);
  140. err_kzalloc:
  141. iounmap(iobase);
  142. err_ioremap:
  143. err_set_dma_mask:
  144. pci_release_regions(pdev);
  145. pci_disable_device(pdev);
  146. err_request_regions:
  147. err_enable_device:
  148. return err;
  149. }
  150. static void __devexit ioat_remove(struct pci_dev *pdev)
  151. {
  152. struct ioat_device *device = pci_get_drvdata(pdev);
  153. dev_err(&pdev->dev, "Removing dma and dca services\n");
  154. if (device->dca) {
  155. unregister_dca_provider(device->dca);
  156. free_dca_provider(device->dca);
  157. device->dca = NULL;
  158. }
  159. if (device->dma) {
  160. ioat_dma_remove(device->dma);
  161. device->dma = NULL;
  162. }
  163. kfree(device);
  164. }
  165. static int __init ioat_init_module(void)
  166. {
  167. return pci_register_driver(&ioat_pci_driver);
  168. }
  169. module_init(ioat_init_module);
  170. static void __exit ioat_exit_module(void)
  171. {
  172. pci_unregister_driver(&ioat_pci_driver);
  173. }
  174. module_exit(ioat_exit_module);