xillybus_pcie.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/drivers/misc/xillybus_pcie.c
  4. *
  5. * Copyright 2011 Xillybus Ltd, http://xillybus.com
  6. *
  7. * Driver for the Xillybus FPGA/host framework using PCI Express.
  8. */
  9. #include <linux/module.h>
  10. #include <linux/pci.h>
  11. #include <linux/slab.h>
  12. #include "xillybus.h"
  13. MODULE_DESCRIPTION("Xillybus driver for PCIe");
  14. MODULE_AUTHOR("Eli Billauer, Xillybus Ltd.");
  15. MODULE_ALIAS("xillybus_pcie");
  16. MODULE_LICENSE("GPL v2");
  17. #define PCI_DEVICE_ID_XILLYBUS 0xebeb
  18. #define PCI_VENDOR_ID_ACTEL 0x11aa
  19. #define PCI_VENDOR_ID_LATTICE 0x1204
  20. static const char xillyname[] = "xillybus_pcie";
  21. static const struct pci_device_id xillyids[] = {
  22. {PCI_DEVICE(PCI_VENDOR_ID_XILINX, PCI_DEVICE_ID_XILLYBUS)},
  23. {PCI_DEVICE(PCI_VENDOR_ID_ALTERA, PCI_DEVICE_ID_XILLYBUS)},
  24. {PCI_DEVICE(PCI_VENDOR_ID_ACTEL, PCI_DEVICE_ID_XILLYBUS)},
  25. {PCI_DEVICE(PCI_VENDOR_ID_LATTICE, PCI_DEVICE_ID_XILLYBUS)},
  26. { /* End: all zeroes */ }
  27. };
  28. static int xilly_probe(struct pci_dev *pdev,
  29. const struct pci_device_id *ent)
  30. {
  31. struct xilly_endpoint *endpoint;
  32. int rc;
  33. endpoint = xillybus_init_endpoint(&pdev->dev);
  34. if (!endpoint)
  35. return -ENOMEM;
  36. pci_set_drvdata(pdev, endpoint);
  37. endpoint->owner = THIS_MODULE;
  38. rc = pcim_enable_device(pdev);
  39. if (rc) {
  40. dev_err(endpoint->dev,
  41. "pcim_enable_device() failed. Aborting.\n");
  42. return rc;
  43. }
  44. /* L0s has caused packet drops. No power saving, thank you. */
  45. pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S);
  46. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  47. dev_err(endpoint->dev,
  48. "Incorrect BAR configuration. Aborting.\n");
  49. return -ENODEV;
  50. }
  51. rc = pcim_iomap_regions(pdev, 0x01, xillyname);
  52. if (rc) {
  53. dev_err(endpoint->dev,
  54. "pcim_iomap_regions() failed. Aborting.\n");
  55. return rc;
  56. }
  57. endpoint->registers = pcim_iomap_table(pdev)[0];
  58. pci_set_master(pdev);
  59. /* Set up a single MSI interrupt */
  60. if (pci_enable_msi(pdev)) {
  61. dev_err(endpoint->dev,
  62. "Failed to enable MSI interrupts. Aborting.\n");
  63. return -ENODEV;
  64. }
  65. rc = devm_request_irq(&pdev->dev, pdev->irq, xillybus_isr, 0,
  66. xillyname, endpoint);
  67. if (rc) {
  68. dev_err(endpoint->dev,
  69. "Failed to register MSI handler. Aborting.\n");
  70. return -ENODEV;
  71. }
  72. /*
  73. * Some (old and buggy?) hardware drops 64-bit addressed PCIe packets,
  74. * even when the PCIe driver claims that a 64-bit mask is OK. On the
  75. * other hand, on some architectures, 64-bit addressing is mandatory.
  76. * So go for the 64-bit mask only when failing is the other option.
  77. */
  78. if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
  79. endpoint->dma_using_dac = 0;
  80. } else if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) {
  81. endpoint->dma_using_dac = 1;
  82. } else {
  83. dev_err(endpoint->dev, "Failed to set DMA mask. Aborting.\n");
  84. return -ENODEV;
  85. }
  86. return xillybus_endpoint_discovery(endpoint);
  87. }
  88. static void xilly_remove(struct pci_dev *pdev)
  89. {
  90. struct xilly_endpoint *endpoint = pci_get_drvdata(pdev);
  91. xillybus_endpoint_remove(endpoint);
  92. }
  93. MODULE_DEVICE_TABLE(pci, xillyids);
  94. static struct pci_driver xillybus_driver = {
  95. .name = xillyname,
  96. .id_table = xillyids,
  97. .probe = xilly_probe,
  98. .remove = xilly_remove,
  99. };
  100. module_pci_driver(xillybus_driver);