1473c88f9SBruce Richardson.. SPDX-License-Identifier: BSD-3-Clause 263f3f7cdSWei Huang Copyright(c) 2018-2022 Intel Corporation. 3473c88f9SBruce Richardson 4473c88f9SBruce RichardsonIFPGA Rawdev Driver 5473c88f9SBruce Richardson====================== 6473c88f9SBruce Richardson 7473c88f9SBruce RichardsonFPGA is used more and more widely in Cloud and NFV, one primary reason is 8473c88f9SBruce Richardsonthat FPGA not only provides ASIC performance but also it's more flexible 9473c88f9SBruce Richardsonthan ASIC. 10473c88f9SBruce Richardson 11473c88f9SBruce RichardsonFPGA uses Partial Reconfigure (PR) Parts of Bit Stream to achieve its 12473c88f9SBruce Richardsonflexibility. That means one FPGA Device Bit Stream is divided into many Parts 13473c88f9SBruce Richardsonof Bit Stream(each Part of Bit Stream is defined as AFU-Accelerated Function 14473c88f9SBruce RichardsonUnit), and each AFU is a hardware acceleration unit which can be dynamically 15473c88f9SBruce Richardsonreloaded respectively. 16473c88f9SBruce Richardson 17473c88f9SBruce RichardsonBy PR (Partial Reconfiguration) AFUs, one FPGA resources can be time-shared by 18473c88f9SBruce Richardsondifferent users. FPGA hot upgrade and fault tolerance can be provided easily. 19473c88f9SBruce Richardson 20473c88f9SBruce RichardsonThe SW IFPGA Rawdev Driver (**ifpga_rawdev**) provides a Rawdev driver 21473c88f9SBruce Richardsonthat utilizes Intel FPGA Software Stack OPAE(Open Programmable Acceleration 22473c88f9SBruce RichardsonEngine) for FPGA management. 23473c88f9SBruce Richardson 24473c88f9SBruce RichardsonImplementation details 25473c88f9SBruce Richardson---------------------- 26473c88f9SBruce Richardson 27473c88f9SBruce RichardsonEach instance of IFPGA Rawdev Driver is probed by Intel FpgaDev. In coordination 28473c88f9SBruce Richardsonwith OPAE share code IFPGA Rawdev Driver provides common FPGA management ops 29473c88f9SBruce Richardsonfor FPGA operation, OPAE provides all following operations: 30473c88f9SBruce Richardson- FPGA PR (Partial Reconfiguration) management 31473c88f9SBruce Richardson- FPGA AFUs Identifying 32473c88f9SBruce Richardson- FPGA Thermal Management 33473c88f9SBruce Richardson- FPGA Power Management 34473c88f9SBruce Richardson- FPGA Performance reporting 35473c88f9SBruce Richardson- FPGA Remote Debug 36473c88f9SBruce Richardson 37473c88f9SBruce RichardsonAll configuration parameters are taken by vdev_ifpga_cfg driver. Besides 38473c88f9SBruce Richardsonconfiguration, vdev_ifpga_cfg driver also hot plugs in IFPGA Bus. 39473c88f9SBruce Richardson 40473c88f9SBruce RichardsonAll of the AFUs of one FPGA may share same PCI BDF and AFUs scan depend on 41473c88f9SBruce RichardsonIFPGA Rawdev Driver so IFPGA Bus takes AFU device scan and AFU drivers probe. 42473c88f9SBruce RichardsonAll AFU device driver bind to AFU device by its UUID (Universally Unique 43473c88f9SBruce RichardsonIdentifier). 44473c88f9SBruce Richardson 45473c88f9SBruce RichardsonTo avoid unnecessary code duplication and ensure maximum performance, 46473c88f9SBruce Richardsonhandling of AFU devices is left to different PMDs; all the design as 47473c88f9SBruce Richardsonsummarized by the following block diagram:: 48473c88f9SBruce Richardson 49473c88f9SBruce Richardson +---------------------------------------------------------------+ 50473c88f9SBruce Richardson | Application(s) | 51473c88f9SBruce Richardson +----------------------------.----------------------------------+ 52473c88f9SBruce Richardson | 53473c88f9SBruce Richardson | 54473c88f9SBruce Richardson +----------------------------'----------------------------------+ 55473c88f9SBruce Richardson | DPDK Framework (APIs) | 56473c88f9SBruce Richardson +----------|------------|--------.---------------------|--------+ 57473c88f9SBruce Richardson / \ | 58473c88f9SBruce Richardson / \ | 59473c88f9SBruce Richardson +-------'-------+ +-------'-------+ +--------'--------+ 60473c88f9SBruce Richardson | Eth PMD | | Crypto PMD | | | 61473c88f9SBruce Richardson +-------.-------+ +-------.-------+ | | 62473c88f9SBruce Richardson | | | | 63473c88f9SBruce Richardson | | | | 64473c88f9SBruce Richardson +-------'-------+ +-------'-------+ | IFPGA | 65473c88f9SBruce Richardson | Eth AFU Dev | |Crypto AFU Dev | | Rawdev Driver | 66473c88f9SBruce Richardson +-------.-------+ +-------.-------+ |(OPAE Share Code)| 67473c88f9SBruce Richardson | | | | 68473c88f9SBruce Richardson | | Rawdev | | 69473c88f9SBruce Richardson +-------'------------------'-------+ Ops | | 70473c88f9SBruce Richardson | IFPGA Bus | -------->| | 71473c88f9SBruce Richardson +-----------------.----------------+ +--------.--------+ 72473c88f9SBruce Richardson | | 73473c88f9SBruce Richardson Hot-plugin -->| | 74473c88f9SBruce Richardson | | 75473c88f9SBruce Richardson +-----------------'------------------+ +--------'--------+ 76473c88f9SBruce Richardson | vdev_ifpga_cfg driver | | Intel FpgaDev | 77473c88f9SBruce Richardson +------------------------------------+ +-----------------+ 78473c88f9SBruce Richardson 79473c88f9SBruce Richardson 80473c88f9SBruce RichardsonRun-time parameters 81473c88f9SBruce Richardson------------------- 82473c88f9SBruce Richardson 83473c88f9SBruce RichardsonThis driver is invoked automatically in systems added with Intel FPGA, 84473c88f9SBruce Richardsonbut PR and IFPGA Bus scan is triggered by command line using 85473c88f9SBruce Richardson``--vdev 'ifpga_rawdev_cfg`` EAL option. 86473c88f9SBruce Richardson 87473c88f9SBruce RichardsonThe following device parameters are supported: 88473c88f9SBruce Richardson 89473c88f9SBruce Richardson- ``ifpga`` [string] 90473c88f9SBruce Richardson 91473c88f9SBruce Richardson Provide a specific Intel FPGA device PCI BDF. Can be provided multiple 92473c88f9SBruce Richardson times for additional instances. 93473c88f9SBruce Richardson 94473c88f9SBruce Richardson- ``port`` [int] 95473c88f9SBruce Richardson 96473c88f9SBruce Richardson Each FPGA can provide many channels to PR AFU by software, each channels 97473c88f9SBruce Richardson is identified by this parameter. 98473c88f9SBruce Richardson 99473c88f9SBruce Richardson- ``afu_bts`` [string] 100473c88f9SBruce Richardson 101473c88f9SBruce Richardson If null, the AFU Bit Stream has been PR in FPGA, if not forces PR and 102473c88f9SBruce Richardson identifies AFU Bit Stream file. 10363f3f7cdSWei Huang 10463f3f7cdSWei Huang 10503260531SWei HuangIFPGA AFU Driver 10603260531SWei Huang================ 10703260531SWei Huang 10803260531SWei HuangAFU (Acceleration Function Unit) is a function or set of functions 10903260531SWei Huangthat perform various acceleration task on FPGA platform. 11003260531SWei HuangThe image of AFU is called as GBS (Green Bit Stream) 11103260531SWei Huangwhich can be used by PR (Partial Reconfigure) tool to load into the FPGA, 11203260531SWei Huangdifferent AFUs can be dynamically reloaded respectively. 11303260531SWei Huang 11403260531SWei HuangAFU has two main communication paths between the host: 11503260531SWei Huang 11603260531SWei Huang- FPGA to host transactions 11703260531SWei Huang 11803260531SWei Huang The FPGA accesses host memory using a 512 bits data path. 11903260531SWei Huang This data path has separate channels for read and write traffic 12003260531SWei Huang allowing for simultaneous read and write to occur. 12103260531SWei Huang The read and write channels support bursts of 1, 2, and 4 cache lines. 12203260531SWei Huang 12303260531SWei Huang- Host to FPGA (MMIO) transactions 12403260531SWei Huang 12503260531SWei Huang The host can access a 256 KB address space within the FPGA. 12603260531SWei Huang This address space contains Device Feature Header (DFHs) 12703260531SWei Huang and the control and status registers of the AFU hardware. 12803260531SWei Huang 12903260531SWei HuangAFU must implement the following registers: 13003260531SWei Huang 13103260531SWei Huang- AFU DFH - a 64-bit header at MMIO address offset 0x0 13203260531SWei Huang 13303260531SWei Huang- AFU ID - a 128-bit UUID at MMIO address offset 0x2 13403260531SWei Huang 13503260531SWei HuangThe AFU is enumerated and recorded by IFPGA Rawdev Driver. 13603260531SWei HuangThen AFU devices are created with the help of IFPGA Bus Driver, 13703260531SWei HuangAFU driver probe these AFU devices and expose them 13803260531SWei Huangas standard raw devices for application to access. 13903260531SWei Huang 14003260531SWei HuangImplementation details 14103260531SWei Huang---------------------- 14203260531SWei Huang 14303260531SWei HuangIFPGA Rawdev Driver identifies AFU in FPGA, AFU location (PF/VF address) 14403260531SWei Huangand UUID are taken by ``ifpga_rawdev_cfg`` vdev driver 14503260531SWei Huangwhich hot plug AFU into IFPGA Bus. 14603260531SWei Huang 14703260531SWei HuangIFPGA Bus takes AFU device scan and AFU driver probe. 14803260531SWei HuangAll AFU device driver bind to AFU device by its dedicated UUID. 14903260531SWei HuangTo avoid unnecessary code duplication and ensure maximum performance, 15003260531SWei HuangAFU driver implements the common part of raw device driver. 15103260531SWei HuangSeveral specific AFU drivers are provided for reference. 15203260531SWei HuangThe design is summarized by the following block diagram:: 15303260531SWei Huang 15403260531SWei Huang +---------------------------------------------------------------+ 15503260531SWei Huang | Application(s) | 15603260531SWei Huang +----------------------------.----------------------------------+ 15703260531SWei Huang | 15803260531SWei Huang +----------------------------'----------------------------------+ 15903260531SWei Huang | DPDK Framework (Rawdev APIs) | 16003260531SWei Huang +-----------------+------------------------------------+--------+ 16103260531SWei Huang | | 16203260531SWei Huang +-----------------'----------------+ | 16303260531SWei Huang | IFPGA AFU Driver | +--------'--------+ 16403260531SWei Huang | | | | 16503260531SWei Huang |+---------------+ +--------------+| | | 16603260531SWei Huang || AFU Dev1 PMD | | AFU Dev2 PMD || | | 16703260531SWei Huang |+-------+-------+ +-------+------+| | | 16803260531SWei Huang +--------|-----------------|-------+ | | 16903260531SWei Huang | | | | 17003260531SWei Huang +--------'------+ +-------'-------+ | IFPGA | 17103260531SWei Huang | AFU Dev1 | | AFU Dev2 | | Rawdev Driver | 17203260531SWei Huang +-------.-------+ +-------.-------+ | | 17303260531SWei Huang | | Rawdev | | 17403260531SWei Huang +-------'------------------'-------+ Ops | | 17503260531SWei Huang | IFPGA Bus |--------->| | 17603260531SWei Huang +-----------------.----------------+ +--------.--------+ 17703260531SWei Huang | | 17803260531SWei Huang Hot-plugin -->| | 17903260531SWei Huang | | 18003260531SWei Huang +-----------------'------------------+ +--------'--------+ 18103260531SWei Huang | ifpga_rawdev_cfg vdev driver | | Intel FpgaDev | 18203260531SWei Huang +------------------------------------+ +-----------------+ 18303260531SWei Huang 18403260531SWei HuangHow to test AFU function 18503260531SWei Huang------------------------ 18603260531SWei Huang 18703260531SWei HuangSuppose AFU is found in FPGA at PCI address 31:00.0, 18803260531SWei Huangthen you can create and test a AFU device by following steps in application. 18903260531SWei Huang 19003260531SWei Huang#. rte_vdev_init("ifpga_rawdev_cfg0", "ifpga=31:00.0,port=0") 19103260531SWei Huang 19203260531SWei Huang#. rawdev = rte_rawdev_pmd_get_named_dev("afu_0|31:00.0") 19303260531SWei Huang 19403260531SWei Huang#. rte_rawdev_configure(rawdev->dev_id, &cfg, sizeof(cfg)) 19503260531SWei Huang 19603260531SWei Huang#. rte_rawdev_selftest(rawdev->dev_id) 19703260531SWei Huang 19803260531SWei Huang#. rte_vdev_uninit("ifpga_rawdev_cfg0") 19903260531SWei Huang 20003260531SWei HuangAFU device name format used in ``rte_rawdev_pmd_get_named_dev`` is ``afu_[port]|[BDF]``. 20103260531SWei HuangPlease refer to OPAE documentation for the meaning of port. 20203260531SWei HuangEach AFU device has specific configuration data, they are defined in ``rte_pmd_afu.h``. 20303260531SWei Huang 20403260531SWei Huang 20563f3f7cdSWei HuangOpen FPGA Stack 20663f3f7cdSWei Huang===================== 20763f3f7cdSWei Huang 20863f3f7cdSWei HuangOpen FPGA Stack (OFS) is a collection of RTL and open source software providing 20963f3f7cdSWei Huanginterfaces to access the instantiated RTL easily in an FPGA. OFS leverages the 21063f3f7cdSWei HuangDFL for the implementation of the FPGA RTL design. 21163f3f7cdSWei Huang 21263f3f7cdSWei HuangOFS designs allow for the arrangement of software interfaces across multiple 21363f3f7cdSWei HuangPCIe endpoints. Some of these interfaces may be PFs defined in the static region 21463f3f7cdSWei Huangthat connect to interfaces in an IP that is loaded via Partial Reconfiguration (PR). 21563f3f7cdSWei HuangAnd some of these interfaces may be VFs defined in the PR region that can be 21663f3f7cdSWei Huangreconfigured by the end-user. Furthermore, these PFs/VFs may use DFLs such that 21763f3f7cdSWei Huangfeatures may be discovered and accessed in user space with the aid of a generic 21863f3f7cdSWei Huangkernel driver like vfio-pci. The diagram below depicts an example design with one 21963f3f7cdSWei HuangPF and two VFs. In this example, it will export the management functions via PF0 22063f3f7cdSWei Huangand acceleration functions via VF0 and VF1, leverage VFIO to export the MMIO space 22163f3f7cdSWei Huangto an application.:: 22263f3f7cdSWei Huang 22363f3f7cdSWei Huang +-----------------+ +-------------+ +------------+ 22463f3f7cdSWei Huang | FPGA Management | | DPDK App | | User App | 22563f3f7cdSWei Huang | App | | | | | 22663f3f7cdSWei Huang +--------+--------+ +------+------+ +-----+------+ 22763f3f7cdSWei Huang | | | 22863f3f7cdSWei Huang +--------+--------+ +------+------+ | 22963f3f7cdSWei Huang | IFPGA PMD | | AFU PMD | | 23063f3f7cdSWei Huang +--------+--------+ +------+------+ | 23163f3f7cdSWei Huang | | | 23263f3f7cdSWei Huang +--------+------------------+---------------+------+ 23363f3f7cdSWei Huang | VFIO-PCI | 23463f3f7cdSWei Huang +--------+------------------+---------------+------+ 23563f3f7cdSWei Huang | | | 23663f3f7cdSWei Huang +--------+--------+ +------+------+ +-----+------+ 23763f3f7cdSWei Huang | PF0 | | PF0_VF0 | | PF0_VF1 | 23863f3f7cdSWei Huang +-----------------+ +-------------+ +------------+ 23963f3f7cdSWei Huang 24063f3f7cdSWei HuangAs accelerators are specialized hardware, they are typically limited in the 24163f3f7cdSWei Huangnumber installed in a given system. Many use cases require them to be shared 24263f3f7cdSWei Huangacross multiple software contexts or threads of software execution, either 24363f3f7cdSWei Huangthrough partitioning of individual dedicated resources, or virtualization of 24463f3f7cdSWei Huangshared resources. OFS provides several models to share the AFU resources via 24563f3f7cdSWei HuangPR mechanism and hardware-based virtualization schemes. 24663f3f7cdSWei Huang 247*443b949eSDavid Marchand#. Legacy model. 24863f3f7cdSWei Huang With legacy model FPGA cards like Intel PAC N3000 or N5000, there is 24963f3f7cdSWei Huang a notion that the boundary between the AFU and the shell is also the unit of 25063f3f7cdSWei Huang PR for those FPGA platforms. This model is only able to handle a 25163f3f7cdSWei Huang single context, because it only has one PR engine, and one PR region which 25263f3f7cdSWei Huang has an associated Port device. 253*443b949eSDavid Marchand 254*443b949eSDavid Marchand#. Multiple VFs per PR slot. 25563f3f7cdSWei Huang In this model, available AFU resources may allow instantiation of many VFs 25663f3f7cdSWei Huang which have a dedicated PCIe function with their own dedicated MMIO space, or 25763f3f7cdSWei Huang partition a region of MMIO space on a single PCIe function. Intel PAC N6000 25863f3f7cdSWei Huang card has implemented this model. 25963f3f7cdSWei Huang In this model, the AFU/PR slot was not connected to port device. For DFL's view, 26063f3f7cdSWei Huang the Next_AFU pointer in FIU feature header of port device points to NULL in this 26163f3f7cdSWei Huang model. On the other hand, each VF can start with an AFU feature header without 26263f3f7cdSWei Huang being connected to a FIU Port feature header. 26363f3f7cdSWei Huang 26463f3f7cdSWei HuangThe VFs are created through the Linux kernel driver before we use them in DPDK. 26563f3f7cdSWei Huang 26663f3f7cdSWei HuangOFS provides the diversity for accessing the AFU resource to RTL developer. 26763f3f7cdSWei HuangAn IP designer may choose to add more than one PF for interfacing with IP 26863f3f7cdSWei Huangon the FPGA and choose different model to access the AFU resource. 26963f3f7cdSWei Huang 27063f3f7cdSWei HuangThere is one reference architecture design using the "Multiple VFs per PR slot" 27163f3f7cdSWei Huangmodel for OFS as illustrated below. In this reference design, it exports the 27263f3f7cdSWei HuangFPGA management functions via PF0. PF1 will bind with DPDK virtio driver 27363f3f7cdSWei Huangpresenting itself as a network interface to the application. PF2 will bind to the 27463f3f7cdSWei Huangvfio-pci driver allowing the user space software to discover and interface 27563f3f7cdSWei Huangwith the specific workload like diagnostic test. It leverages AFU PMD driver to 27663f3f7cdSWei Huangaccess the AFU resources in DPDK.:: 27763f3f7cdSWei Huang 27863f3f7cdSWei Huang +----------------------+ 27963f3f7cdSWei Huang | PF/VF mux/demux | 28063f3f7cdSWei Huang +--+--+-----+------+-+-+ 28163f3f7cdSWei Huang | | | | | 28263f3f7cdSWei Huang +------------------------+ | | | | 28363f3f7cdSWei Huang PF0 | +---------+ +-+ | | 28463f3f7cdSWei Huang +---+---+ | +---+----+ | | 28563f3f7cdSWei Huang | DFH | | | DFH | | | 28663f3f7cdSWei Huang +-------+ +-----+----+ +--------+ | | 28763f3f7cdSWei Huang | FME | | VirtIO | | Test | | | 28863f3f7cdSWei Huang +---+---+ +----------+ +--------+ | | 28963f3f7cdSWei Huang | PF1 PF2 | | 29063f3f7cdSWei Huang | | | 29163f3f7cdSWei Huang | +----------+ | 29263f3f7cdSWei Huang | | ++ 29363f3f7cdSWei Huang | | | 29463f3f7cdSWei Huang | | PF0_VF0 | PF0_VF1 29563f3f7cdSWei Huang | +-----------------+-----------+------------+ 29663f3f7cdSWei Huang | | +-----+-----------+--------+ | 29763f3f7cdSWei Huang | | | | | | | 29863f3f7cdSWei Huang | | +------+ | +--+ -+ +--+---+ | | 29963f3f7cdSWei Huang | | | Port | | | DFH | | DFH | | | 30063f3f7cdSWei Huang +-----------+ +------+ | +-----+ +------+ | | 30163f3f7cdSWei Huang | | | DEV | | DEV | | | 30263f3f7cdSWei Huang | | +-----+ +------+ | | 30363f3f7cdSWei Huang | | PR Slot | | 30463f3f7cdSWei Huang | +--------------------------+ | 30563f3f7cdSWei Huang | Port Gasket | 30663f3f7cdSWei Huang +------------------------------------------+ 307