pci.c 5.7 KB

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