ocxl.rst 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. ========================================================
  2. OpenCAPI (Open Coherent Accelerator Processor Interface)
  3. ========================================================
  4. OpenCAPI is an interface between processors and accelerators. It aims
  5. at being low-latency and high-bandwidth.
  6. The specification was developed by the OpenCAPI Consortium, and is now
  7. available from the `Compute Express Link Consortium
  8. <https://computeexpresslink.org/resource/opencapi-specification-archive/>`_.
  9. It allows an accelerator (which could be an FPGA, ASICs, ...) to access
  10. the host memory coherently, using virtual addresses. An OpenCAPI
  11. device can also host its own memory, that can be accessed from the
  12. host.
  13. OpenCAPI is known in linux as 'ocxl', as the open, processor-agnostic
  14. evolution of 'cxl' (the driver for the IBM CAPI interface for
  15. powerpc), which was named that way to avoid confusion with the ISDN
  16. CAPI subsystem.
  17. High-level view
  18. ===============
  19. OpenCAPI defines a Data Link Layer (DL) and Transaction Layer (TL), to
  20. be implemented on top of a physical link. Any processor or device
  21. implementing the DL and TL can start sharing memory.
  22. ::
  23. +-----------+ +-------------+
  24. | | | |
  25. | | | Accelerated |
  26. | Processor | | Function |
  27. | | +--------+ | Unit | +--------+
  28. | |--| Memory | | (AFU) |--| Memory |
  29. | | +--------+ | | +--------+
  30. +-----------+ +-------------+
  31. | |
  32. +-----------+ +-------------+
  33. | TL | | TLX |
  34. +-----------+ +-------------+
  35. | |
  36. +-----------+ +-------------+
  37. | DL | | DLX |
  38. +-----------+ +-------------+
  39. | |
  40. | PHY |
  41. +---------------------------------------+
  42. Device discovery
  43. ================
  44. OpenCAPI relies on a PCI-like configuration space, implemented on the
  45. device. So the host can discover AFUs by querying the config space.
  46. OpenCAPI devices in Linux are treated like PCI devices (with a few
  47. caveats). The firmware is expected to abstract the hardware as if it
  48. was a PCI link. A lot of the existing PCI infrastructure is reused:
  49. devices are scanned and BARs are assigned during the standard PCI
  50. enumeration. Commands like 'lspci' can therefore be used to see what
  51. devices are available.
  52. The configuration space defines the AFU(s) that can be found on the
  53. physical adapter, such as its name, how many memory contexts it can
  54. work with, the size of its MMIO areas, ...
  55. MMIO
  56. ====
  57. OpenCAPI defines two MMIO areas for each AFU:
  58. * the global MMIO area, with registers pertinent to the whole AFU.
  59. * a per-process MMIO area, which has a fixed size for each context.
  60. AFU interrupts
  61. ==============
  62. OpenCAPI includes the possibility for an AFU to send an interrupt to a
  63. host process. It is done through a 'intrp_req' defined in the
  64. Transaction Layer, specifying a 64-bit object handle which defines the
  65. interrupt.
  66. The driver allows a process to allocate an interrupt and obtain its
  67. 64-bit object handle, that can be passed to the AFU.
  68. char devices
  69. ============
  70. The driver creates one char device per AFU found on the physical
  71. device. A physical device may have multiple functions and each
  72. function can have multiple AFUs. At the time of this writing though,
  73. it has only been tested with devices exporting only one AFU.
  74. Char devices can be found in /dev/ocxl/ and are named as:
  75. /dev/ocxl/<AFU name>.<location>.<index>
  76. where <AFU name> is a max 20-character long name, as found in the
  77. config space of the AFU.
  78. <location> is added by the driver and can help distinguish devices
  79. when a system has more than one instance of the same OpenCAPI device.
  80. <index> is also to help distinguish AFUs in the unlikely case where a
  81. device carries multiple copies of the same AFU.
  82. Sysfs class
  83. ===========
  84. An ocxl class is added for the devices representing the AFUs. See
  85. /sys/class/ocxl. The layout is described in
  86. Documentation/ABI/testing/sysfs-class-ocxl
  87. User API
  88. ========
  89. open
  90. ----
  91. Based on the AFU definition found in the config space, an AFU may
  92. support working with more than one memory context, in which case the
  93. associated char device may be opened multiple times by different
  94. processes.
  95. ioctl
  96. -----
  97. OCXL_IOCTL_ATTACH:
  98. Attach the memory context of the calling process to the AFU so that
  99. the AFU can access its memory.
  100. OCXL_IOCTL_IRQ_ALLOC:
  101. Allocate an AFU interrupt and return an identifier.
  102. OCXL_IOCTL_IRQ_FREE:
  103. Free a previously allocated AFU interrupt.
  104. OCXL_IOCTL_IRQ_SET_FD:
  105. Associate an event fd to an AFU interrupt so that the user process
  106. can be notified when the AFU sends an interrupt.
  107. OCXL_IOCTL_GET_METADATA:
  108. Obtains configuration information from the card, such at the size of
  109. MMIO areas, the AFU version, and the PASID for the current context.
  110. OCXL_IOCTL_ENABLE_P9_WAIT:
  111. Allows the AFU to wake a userspace thread executing 'wait'. Returns
  112. information to userspace to allow it to configure the AFU. Note that
  113. this is only available on POWER9.
  114. OCXL_IOCTL_GET_FEATURES:
  115. Reports on which CPU features that affect OpenCAPI are usable from
  116. userspace.
  117. mmap
  118. ----
  119. A process can mmap the per-process MMIO area for interactions with the
  120. AFU.