12dbc0838SMauro Carvalho Chehab======================================================== 22dbc0838SMauro Carvalho ChehabOpenCAPI (Open Coherent Accelerator Processor Interface) 32dbc0838SMauro Carvalho Chehab======================================================== 42dbc0838SMauro Carvalho Chehab 52dbc0838SMauro Carvalho ChehabOpenCAPI is an interface between processors and accelerators. It aims 62dbc0838SMauro Carvalho Chehabat being low-latency and high-bandwidth. The specification is 72dbc0838SMauro Carvalho Chehabdeveloped by the `OpenCAPI Consortium <http://opencapi.org/>`_. 82dbc0838SMauro Carvalho Chehab 9*987b741cSTom RixIt allows an accelerator (which could be an FPGA, ASICs, ...) to access 102dbc0838SMauro Carvalho Chehabthe host memory coherently, using virtual addresses. An OpenCAPI 112dbc0838SMauro Carvalho Chehabdevice can also host its own memory, that can be accessed from the 122dbc0838SMauro Carvalho Chehabhost. 132dbc0838SMauro Carvalho Chehab 142dbc0838SMauro Carvalho ChehabOpenCAPI is known in linux as 'ocxl', as the open, processor-agnostic 152dbc0838SMauro Carvalho Chehabevolution of 'cxl' (the driver for the IBM CAPI interface for 162dbc0838SMauro Carvalho Chehabpowerpc), which was named that way to avoid confusion with the ISDN 172dbc0838SMauro Carvalho ChehabCAPI subsystem. 182dbc0838SMauro Carvalho Chehab 192dbc0838SMauro Carvalho Chehab 202dbc0838SMauro Carvalho ChehabHigh-level view 212dbc0838SMauro Carvalho Chehab=============== 222dbc0838SMauro Carvalho Chehab 232dbc0838SMauro Carvalho ChehabOpenCAPI defines a Data Link Layer (DL) and Transaction Layer (TL), to 242dbc0838SMauro Carvalho Chehabbe implemented on top of a physical link. Any processor or device 252dbc0838SMauro Carvalho Chehabimplementing the DL and TL can start sharing memory. 262dbc0838SMauro Carvalho Chehab 272dbc0838SMauro Carvalho Chehab:: 282dbc0838SMauro Carvalho Chehab 292dbc0838SMauro Carvalho Chehab +-----------+ +-------------+ 302dbc0838SMauro Carvalho Chehab | | | | 312dbc0838SMauro Carvalho Chehab | | | Accelerated | 322dbc0838SMauro Carvalho Chehab | Processor | | Function | 332dbc0838SMauro Carvalho Chehab | | +--------+ | Unit | +--------+ 342dbc0838SMauro Carvalho Chehab | |--| Memory | | (AFU) |--| Memory | 352dbc0838SMauro Carvalho Chehab | | +--------+ | | +--------+ 362dbc0838SMauro Carvalho Chehab +-----------+ +-------------+ 372dbc0838SMauro Carvalho Chehab | | 382dbc0838SMauro Carvalho Chehab +-----------+ +-------------+ 392dbc0838SMauro Carvalho Chehab | TL | | TLX | 402dbc0838SMauro Carvalho Chehab +-----------+ +-------------+ 412dbc0838SMauro Carvalho Chehab | | 422dbc0838SMauro Carvalho Chehab +-----------+ +-------------+ 432dbc0838SMauro Carvalho Chehab | DL | | DLX | 442dbc0838SMauro Carvalho Chehab +-----------+ +-------------+ 452dbc0838SMauro Carvalho Chehab | | 462dbc0838SMauro Carvalho Chehab | PHY | 472dbc0838SMauro Carvalho Chehab +---------------------------------------+ 482dbc0838SMauro Carvalho Chehab 492dbc0838SMauro Carvalho Chehab 502dbc0838SMauro Carvalho Chehab 512dbc0838SMauro Carvalho ChehabDevice discovery 522dbc0838SMauro Carvalho Chehab================ 532dbc0838SMauro Carvalho Chehab 542dbc0838SMauro Carvalho ChehabOpenCAPI relies on a PCI-like configuration space, implemented on the 552dbc0838SMauro Carvalho Chehabdevice. So the host can discover AFUs by querying the config space. 562dbc0838SMauro Carvalho Chehab 572dbc0838SMauro Carvalho ChehabOpenCAPI devices in Linux are treated like PCI devices (with a few 582dbc0838SMauro Carvalho Chehabcaveats). The firmware is expected to abstract the hardware as if it 592dbc0838SMauro Carvalho Chehabwas a PCI link. A lot of the existing PCI infrastructure is reused: 602dbc0838SMauro Carvalho Chehabdevices are scanned and BARs are assigned during the standard PCI 612dbc0838SMauro Carvalho Chehabenumeration. Commands like 'lspci' can therefore be used to see what 622dbc0838SMauro Carvalho Chehabdevices are available. 632dbc0838SMauro Carvalho Chehab 642dbc0838SMauro Carvalho ChehabThe configuration space defines the AFU(s) that can be found on the 652dbc0838SMauro Carvalho Chehabphysical adapter, such as its name, how many memory contexts it can 662dbc0838SMauro Carvalho Chehabwork with, the size of its MMIO areas, ... 672dbc0838SMauro Carvalho Chehab 682dbc0838SMauro Carvalho Chehab 692dbc0838SMauro Carvalho Chehab 702dbc0838SMauro Carvalho ChehabMMIO 712dbc0838SMauro Carvalho Chehab==== 722dbc0838SMauro Carvalho Chehab 732dbc0838SMauro Carvalho ChehabOpenCAPI defines two MMIO areas for each AFU: 742dbc0838SMauro Carvalho Chehab 752dbc0838SMauro Carvalho Chehab* the global MMIO area, with registers pertinent to the whole AFU. 762dbc0838SMauro Carvalho Chehab* a per-process MMIO area, which has a fixed size for each context. 772dbc0838SMauro Carvalho Chehab 782dbc0838SMauro Carvalho Chehab 792dbc0838SMauro Carvalho Chehab 802dbc0838SMauro Carvalho ChehabAFU interrupts 812dbc0838SMauro Carvalho Chehab============== 822dbc0838SMauro Carvalho Chehab 832dbc0838SMauro Carvalho ChehabOpenCAPI includes the possibility for an AFU to send an interrupt to a 842dbc0838SMauro Carvalho Chehabhost process. It is done through a 'intrp_req' defined in the 852dbc0838SMauro Carvalho ChehabTransaction Layer, specifying a 64-bit object handle which defines the 862dbc0838SMauro Carvalho Chehabinterrupt. 872dbc0838SMauro Carvalho Chehab 882dbc0838SMauro Carvalho ChehabThe driver allows a process to allocate an interrupt and obtain its 892dbc0838SMauro Carvalho Chehab64-bit object handle, that can be passed to the AFU. 902dbc0838SMauro Carvalho Chehab 912dbc0838SMauro Carvalho Chehab 922dbc0838SMauro Carvalho Chehab 932dbc0838SMauro Carvalho Chehabchar devices 942dbc0838SMauro Carvalho Chehab============ 952dbc0838SMauro Carvalho Chehab 962dbc0838SMauro Carvalho ChehabThe driver creates one char device per AFU found on the physical 972dbc0838SMauro Carvalho Chehabdevice. A physical device may have multiple functions and each 982dbc0838SMauro Carvalho Chehabfunction can have multiple AFUs. At the time of this writing though, 992dbc0838SMauro Carvalho Chehabit has only been tested with devices exporting only one AFU. 1002dbc0838SMauro Carvalho Chehab 1012dbc0838SMauro Carvalho ChehabChar devices can be found in /dev/ocxl/ and are named as: 1022dbc0838SMauro Carvalho Chehab/dev/ocxl/<AFU name>.<location>.<index> 1032dbc0838SMauro Carvalho Chehab 1042dbc0838SMauro Carvalho Chehabwhere <AFU name> is a max 20-character long name, as found in the 1052dbc0838SMauro Carvalho Chehabconfig space of the AFU. 1062dbc0838SMauro Carvalho Chehab<location> is added by the driver and can help distinguish devices 1072dbc0838SMauro Carvalho Chehabwhen a system has more than one instance of the same OpenCAPI device. 1082dbc0838SMauro Carvalho Chehab<index> is also to help distinguish AFUs in the unlikely case where a 1092dbc0838SMauro Carvalho Chehabdevice carries multiple copies of the same AFU. 1102dbc0838SMauro Carvalho Chehab 1112dbc0838SMauro Carvalho Chehab 1122dbc0838SMauro Carvalho Chehab 1132dbc0838SMauro Carvalho ChehabSysfs class 1142dbc0838SMauro Carvalho Chehab=========== 1152dbc0838SMauro Carvalho Chehab 1162dbc0838SMauro Carvalho ChehabAn ocxl class is added for the devices representing the AFUs. See 1172dbc0838SMauro Carvalho Chehab/sys/class/ocxl. The layout is described in 1182dbc0838SMauro Carvalho ChehabDocumentation/ABI/testing/sysfs-class-ocxl 1192dbc0838SMauro Carvalho Chehab 1202dbc0838SMauro Carvalho Chehab 1212dbc0838SMauro Carvalho Chehab 1222dbc0838SMauro Carvalho ChehabUser API 1232dbc0838SMauro Carvalho Chehab======== 1242dbc0838SMauro Carvalho Chehab 1252dbc0838SMauro Carvalho Chehabopen 1262dbc0838SMauro Carvalho Chehab---- 1272dbc0838SMauro Carvalho Chehab 1282dbc0838SMauro Carvalho ChehabBased on the AFU definition found in the config space, an AFU may 1292dbc0838SMauro Carvalho Chehabsupport working with more than one memory context, in which case the 1302dbc0838SMauro Carvalho Chehabassociated char device may be opened multiple times by different 1312dbc0838SMauro Carvalho Chehabprocesses. 1322dbc0838SMauro Carvalho Chehab 1332dbc0838SMauro Carvalho Chehab 1342dbc0838SMauro Carvalho Chehabioctl 1352dbc0838SMauro Carvalho Chehab----- 1362dbc0838SMauro Carvalho Chehab 1372dbc0838SMauro Carvalho ChehabOCXL_IOCTL_ATTACH: 1382dbc0838SMauro Carvalho Chehab 1392dbc0838SMauro Carvalho Chehab Attach the memory context of the calling process to the AFU so that 1402dbc0838SMauro Carvalho Chehab the AFU can access its memory. 1412dbc0838SMauro Carvalho Chehab 1422dbc0838SMauro Carvalho ChehabOCXL_IOCTL_IRQ_ALLOC: 1432dbc0838SMauro Carvalho Chehab 1442dbc0838SMauro Carvalho Chehab Allocate an AFU interrupt and return an identifier. 1452dbc0838SMauro Carvalho Chehab 1462dbc0838SMauro Carvalho ChehabOCXL_IOCTL_IRQ_FREE: 1472dbc0838SMauro Carvalho Chehab 1482dbc0838SMauro Carvalho Chehab Free a previously allocated AFU interrupt. 1492dbc0838SMauro Carvalho Chehab 1502dbc0838SMauro Carvalho ChehabOCXL_IOCTL_IRQ_SET_FD: 1512dbc0838SMauro Carvalho Chehab 1522dbc0838SMauro Carvalho Chehab Associate an event fd to an AFU interrupt so that the user process 1532dbc0838SMauro Carvalho Chehab can be notified when the AFU sends an interrupt. 1542dbc0838SMauro Carvalho Chehab 1552dbc0838SMauro Carvalho ChehabOCXL_IOCTL_GET_METADATA: 1562dbc0838SMauro Carvalho Chehab 1572dbc0838SMauro Carvalho Chehab Obtains configuration information from the card, such at the size of 1582dbc0838SMauro Carvalho Chehab MMIO areas, the AFU version, and the PASID for the current context. 1592dbc0838SMauro Carvalho Chehab 1602dbc0838SMauro Carvalho ChehabOCXL_IOCTL_ENABLE_P9_WAIT: 1612dbc0838SMauro Carvalho Chehab 1622dbc0838SMauro Carvalho Chehab Allows the AFU to wake a userspace thread executing 'wait'. Returns 1632dbc0838SMauro Carvalho Chehab information to userspace to allow it to configure the AFU. Note that 1642dbc0838SMauro Carvalho Chehab this is only available on POWER9. 1652dbc0838SMauro Carvalho Chehab 1662dbc0838SMauro Carvalho ChehabOCXL_IOCTL_GET_FEATURES: 1672dbc0838SMauro Carvalho Chehab 1682dbc0838SMauro Carvalho Chehab Reports on which CPU features that affect OpenCAPI are usable from 1692dbc0838SMauro Carvalho Chehab userspace. 1702dbc0838SMauro Carvalho Chehab 1712dbc0838SMauro Carvalho Chehab 1722dbc0838SMauro Carvalho Chehabmmap 1732dbc0838SMauro Carvalho Chehab---- 1742dbc0838SMauro Carvalho Chehab 1752dbc0838SMauro Carvalho ChehabA process can mmap the per-process MMIO area for interactions with the 1762dbc0838SMauro Carvalho ChehabAFU. 177