pci.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. #define DRV_NAME "ioatdma"
  76. static struct pci_driver ioat_pci_driver = {
  77. .name = DRV_NAME,
  78. .id_table = ioat_pci_tbl,
  79. .probe = ioat_pci_probe,
  80. .remove = __devexit_p(ioat_remove),
  81. };
  82. static struct ioatdma_device *
  83. alloc_ioatdma(struct pci_dev *pdev, void __iomem *iobase)
  84. {
  85. struct device *dev = &pdev->dev;
  86. struct ioatdma_device *d = devm_kzalloc(dev, sizeof(*d), GFP_KERNEL);
  87. if (!d)
  88. return NULL;
  89. d->pdev = pdev;
  90. d->reg_base = iobase;
  91. return d;
  92. }
  93. static int __devinit ioat_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  94. {
  95. void __iomem * const *iomap;
  96. struct device *dev = &pdev->dev;
  97. struct ioatdma_device *device;
  98. int err;
  99. err = pcim_enable_device(pdev);
  100. if (err)
  101. return err;
  102. err = pcim_iomap_regions(pdev, 1 << IOAT_MMIO_BAR, DRV_NAME);
  103. if (err)
  104. return err;
  105. iomap = pcim_iomap_table(pdev);
  106. if (!iomap)
  107. return -ENOMEM;
  108. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
  109. if (err)
  110. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  111. if (err)
  112. return err;
  113. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  114. if (err)
  115. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  116. if (err)
  117. return err;
  118. device = devm_kzalloc(dev, sizeof(*device), GFP_KERNEL);
  119. if (!device)
  120. return -ENOMEM;
  121. pci_set_master(pdev);
  122. device = alloc_ioatdma(pdev, iomap[IOAT_MMIO_BAR]);
  123. if (!device)
  124. return -ENOMEM;
  125. pci_set_drvdata(pdev, device);
  126. device->version = readb(device->reg_base + IOAT_VER_OFFSET);
  127. if (device->version == IOAT_VER_1_2)
  128. err = ioat1_dma_probe(device, ioat_dca_enabled);
  129. else if (device->version == IOAT_VER_2_0)
  130. err = ioat2_dma_probe(device, ioat_dca_enabled);
  131. else if (device->version >= IOAT_VER_3_0)
  132. err = ioat3_dma_probe(device, ioat_dca_enabled);
  133. else
  134. return -ENODEV;
  135. if (err) {
  136. dev_err(dev, "Intel(R) I/OAT DMA Engine init failed\n");
  137. return -ENODEV;
  138. }
  139. return 0;
  140. }
  141. static void __devexit ioat_remove(struct pci_dev *pdev)
  142. {
  143. struct ioatdma_device *device = pci_get_drvdata(pdev);
  144. if (!device)
  145. return;
  146. dev_err(&pdev->dev, "Removing dma and dca services\n");
  147. if (device->dca) {
  148. unregister_dca_provider(device->dca);
  149. free_dca_provider(device->dca);
  150. device->dca = NULL;
  151. }
  152. ioat_dma_remove(device);
  153. }
  154. static int __init ioat_init_module(void)
  155. {
  156. pr_info("%s: Intel(R) QuickData Technology Driver %s\n",
  157. DRV_NAME, IOAT_DMA_VERSION);
  158. return pci_register_driver(&ioat_pci_driver);
  159. }
  160. module_init(ioat_init_module);
  161. static void __exit ioat_exit_module(void)
  162. {
  163. pci_unregister_driver(&ioat_pci_driver);
  164. }
  165. module_exit(ioat_exit_module);