ioat.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * Intel I/OAT DMA Linux driver
  3. * Copyright(c) 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 <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. { 0, }
  46. };
  47. struct ioat_device {
  48. struct pci_dev *pdev;
  49. void __iomem *iobase;
  50. struct ioatdma_device *dma;
  51. struct dca_provider *dca;
  52. };
  53. static int __devinit ioat_probe(struct pci_dev *pdev,
  54. const struct pci_device_id *id);
  55. static void __devexit ioat_remove(struct pci_dev *pdev);
  56. static int ioat_dca_enabled = 1;
  57. module_param(ioat_dca_enabled, int, 0644);
  58. MODULE_PARM_DESC(ioat_dca_enabled, "control support of dca service (default: 1)");
  59. static int ioat_setup_functionality(struct pci_dev *pdev, void __iomem *iobase)
  60. {
  61. struct ioat_device *device = pci_get_drvdata(pdev);
  62. u8 version;
  63. int err = 0;
  64. version = readb(iobase + IOAT_VER_OFFSET);
  65. switch (version) {
  66. case IOAT_VER_1_2:
  67. device->dma = ioat_dma_probe(pdev, iobase);
  68. if (device->dma && ioat_dca_enabled)
  69. device->dca = ioat_dca_init(pdev, iobase);
  70. break;
  71. case IOAT_VER_2_0:
  72. device->dma = ioat_dma_probe(pdev, iobase);
  73. if (device->dma && ioat_dca_enabled)
  74. device->dca = ioat2_dca_init(pdev, iobase);
  75. break;
  76. default:
  77. err = -ENODEV;
  78. break;
  79. }
  80. if (!device->dma)
  81. err = -ENODEV;
  82. return err;
  83. }
  84. static void ioat_shutdown_functionality(struct pci_dev *pdev)
  85. {
  86. struct ioat_device *device = pci_get_drvdata(pdev);
  87. dev_err(&pdev->dev, "Removing dma and dca services\n");
  88. if (device->dca) {
  89. unregister_dca_provider(device->dca);
  90. free_dca_provider(device->dca);
  91. device->dca = NULL;
  92. }
  93. if (device->dma) {
  94. ioat_dma_remove(device->dma);
  95. device->dma = NULL;
  96. }
  97. }
  98. static struct pci_driver ioat_pci_driver = {
  99. .name = "ioatdma",
  100. .id_table = ioat_pci_tbl,
  101. .probe = ioat_probe,
  102. .shutdown = ioat_shutdown_functionality,
  103. .remove = __devexit_p(ioat_remove),
  104. };
  105. static int __devinit ioat_probe(struct pci_dev *pdev,
  106. const struct pci_device_id *id)
  107. {
  108. void __iomem *iobase;
  109. struct ioat_device *device;
  110. unsigned long mmio_start, mmio_len;
  111. int err;
  112. err = pci_enable_device(pdev);
  113. if (err)
  114. goto err_enable_device;
  115. err = pci_request_regions(pdev, ioat_pci_driver.name);
  116. if (err)
  117. goto err_request_regions;
  118. err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
  119. if (err)
  120. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  121. if (err)
  122. goto err_set_dma_mask;
  123. err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
  124. if (err)
  125. err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  126. if (err)
  127. goto err_set_dma_mask;
  128. mmio_start = pci_resource_start(pdev, 0);
  129. mmio_len = pci_resource_len(pdev, 0);
  130. iobase = ioremap(mmio_start, mmio_len);
  131. if (!iobase) {
  132. err = -ENOMEM;
  133. goto err_ioremap;
  134. }
  135. device = kzalloc(sizeof(*device), GFP_KERNEL);
  136. if (!device) {
  137. err = -ENOMEM;
  138. goto err_kzalloc;
  139. }
  140. device->pdev = pdev;
  141. pci_set_drvdata(pdev, device);
  142. device->iobase = iobase;
  143. pci_set_master(pdev);
  144. err = ioat_setup_functionality(pdev, iobase);
  145. if (err)
  146. goto err_version;
  147. return 0;
  148. err_version:
  149. kfree(device);
  150. err_kzalloc:
  151. iounmap(iobase);
  152. err_ioremap:
  153. err_set_dma_mask:
  154. pci_release_regions(pdev);
  155. pci_disable_device(pdev);
  156. err_request_regions:
  157. err_enable_device:
  158. return err;
  159. }
  160. /*
  161. * It is unsafe to remove this module: if removed while a requested
  162. * dma is outstanding, esp. from tcp, it is possible to hang while
  163. * waiting for something that will never finish. However, if you're
  164. * feeling lucky, this usually works just fine.
  165. */
  166. static void __devexit ioat_remove(struct pci_dev *pdev)
  167. {
  168. struct ioat_device *device = pci_get_drvdata(pdev);
  169. ioat_shutdown_functionality(pdev);
  170. kfree(device);
  171. }
  172. static int __init ioat_init_module(void)
  173. {
  174. return pci_register_driver(&ioat_pci_driver);
  175. }
  176. module_init(ioat_init_module);
  177. static void __exit ioat_exit_module(void)
  178. {
  179. pci_unregister_driver(&ioat_pci_driver);
  180. }
  181. module_exit(ioat_exit_module);