ioat.c 6.0 KB

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