pci.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 "dma.h"
  32. #include "dma_v2.h"
  33. #include "registers.h"
  34. #include "hw.h"
  35. MODULE_VERSION(IOAT_DMA_VERSION);
  36. MODULE_LICENSE("Dual BSD/GPL");
  37. MODULE_AUTHOR("Intel Corporation");
  38. static struct pci_device_id ioat_pci_tbl[] = {
  39. /* I/OAT v1 platforms */
  40. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT) },
  41. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_CNB) },
  42. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_SCNB) },
  43. { PCI_VDEVICE(UNISYS, PCI_DEVICE_ID_UNISYS_DMA_DIRECTOR) },
  44. /* I/OAT v2 platforms */
  45. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_SNB) },
  46. /* I/OAT v3 platforms */
  47. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG0) },
  48. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG1) },
  49. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG2) },
  50. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG3) },
  51. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG4) },
  52. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG5) },
  53. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG6) },
  54. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG7) },
  55. /* I/OAT v3.2 platforms */
  56. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_JSF0) },
  57. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_JSF1) },
  58. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_JSF2) },
  59. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_JSF3) },
  60. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_JSF4) },
  61. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_JSF5) },
  62. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_JSF6) },
  63. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_JSF7) },
  64. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_JSF8) },
  65. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_JSF9) },
  66. { 0, }
  67. };
  68. MODULE_DEVICE_TABLE(pci, ioat_pci_tbl);
  69. static int __devinit ioat_pci_probe(struct pci_dev *pdev,
  70. const struct pci_device_id *id);
  71. static void __devexit ioat_remove(struct pci_dev *pdev);
  72. static int ioat_dca_enabled = 1;
  73. module_param(ioat_dca_enabled, int, 0644);
  74. MODULE_PARM_DESC(ioat_dca_enabled, "control support of dca service (default: 1)");
  75. struct kmem_cache *ioat2_cache;
  76. #define DRV_NAME "ioatdma"
  77. static struct pci_driver ioat_pci_driver = {
  78. .name = DRV_NAME,
  79. .id_table = ioat_pci_tbl,
  80. .probe = ioat_pci_probe,
  81. .remove = __devexit_p(ioat_remove),
  82. };
  83. static struct ioatdma_device *
  84. alloc_ioatdma(struct pci_dev *pdev, void __iomem *iobase)
  85. {
  86. struct device *dev = &pdev->dev;
  87. struct ioatdma_device *d = devm_kzalloc(dev, sizeof(*d), GFP_KERNEL);
  88. if (!d)
  89. return NULL;
  90. d->pdev = pdev;
  91. d->reg_base = iobase;
  92. return d;
  93. }
  94. static int __devinit ioat_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  95. {
  96. void __iomem * const *iomap;
  97. struct device *dev = &pdev->dev;
  98. struct ioatdma_device *device;
  99. int err;
  100. err = pcim_enable_device(pdev);
  101. if (err)
  102. return err;
  103. err = pcim_iomap_regions(pdev, 1 << IOAT_MMIO_BAR, DRV_NAME);
  104. if (err)
  105. return err;
  106. iomap = pcim_iomap_table(pdev);
  107. if (!iomap)
  108. return -ENOMEM;
  109. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
  110. if (err)
  111. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  112. if (err)
  113. return err;
  114. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  115. if (err)
  116. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  117. if (err)
  118. return err;
  119. device = devm_kzalloc(dev, sizeof(*device), GFP_KERNEL);
  120. if (!device)
  121. return -ENOMEM;
  122. pci_set_master(pdev);
  123. device = alloc_ioatdma(pdev, iomap[IOAT_MMIO_BAR]);
  124. if (!device)
  125. return -ENOMEM;
  126. pci_set_drvdata(pdev, device);
  127. device->version = readb(device->reg_base + IOAT_VER_OFFSET);
  128. if (device->version == IOAT_VER_1_2)
  129. err = ioat1_dma_probe(device, ioat_dca_enabled);
  130. else if (device->version == IOAT_VER_2_0)
  131. err = ioat2_dma_probe(device, ioat_dca_enabled);
  132. else if (device->version >= IOAT_VER_3_0)
  133. err = ioat3_dma_probe(device, ioat_dca_enabled);
  134. else
  135. return -ENODEV;
  136. if (err) {
  137. dev_err(dev, "Intel(R) I/OAT DMA Engine init failed\n");
  138. return -ENODEV;
  139. }
  140. return 0;
  141. }
  142. static void __devexit ioat_remove(struct pci_dev *pdev)
  143. {
  144. struct ioatdma_device *device = pci_get_drvdata(pdev);
  145. if (!device)
  146. return;
  147. dev_err(&pdev->dev, "Removing dma and dca services\n");
  148. if (device->dca) {
  149. unregister_dca_provider(device->dca, &pdev->dev);
  150. free_dca_provider(device->dca);
  151. device->dca = NULL;
  152. }
  153. ioat_dma_remove(device);
  154. }
  155. static int __init ioat_init_module(void)
  156. {
  157. int err;
  158. pr_info("%s: Intel(R) QuickData Technology Driver %s\n",
  159. DRV_NAME, IOAT_DMA_VERSION);
  160. ioat2_cache = kmem_cache_create("ioat2", sizeof(struct ioat_ring_ent),
  161. 0, SLAB_HWCACHE_ALIGN, NULL);
  162. if (!ioat2_cache)
  163. return -ENOMEM;
  164. err = pci_register_driver(&ioat_pci_driver);
  165. if (err)
  166. kmem_cache_destroy(ioat2_cache);
  167. return err;
  168. }
  169. module_init(ioat_init_module);
  170. static void __exit ioat_exit_module(void)
  171. {
  172. pci_unregister_driver(&ioat_pci_driver);
  173. kmem_cache_destroy(ioat2_cache);
  174. }
  175. module_exit(ioat_exit_module);