ioat.c 4.9 KB

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