18c2ecf20Sopenharmony_ci================================================= 28c2ecf20Sopenharmony_ciFPGA Device Feature List (DFL) Framework Overview 38c2ecf20Sopenharmony_ci================================================= 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ciAuthors: 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci- Enno Luebbers <enno.luebbers@intel.com> 88c2ecf20Sopenharmony_ci- Xiao Guangrong <guangrong.xiao@linux.intel.com> 98c2ecf20Sopenharmony_ci- Wu Hao <hao.wu@intel.com> 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ciThe Device Feature List (DFL) FPGA framework (and drivers according to 128c2ecf20Sopenharmony_cithis framework) hides the very details of low layer hardwares and provides 138c2ecf20Sopenharmony_ciunified interfaces to userspace. Applications could use these interfaces to 148c2ecf20Sopenharmony_ciconfigure, enumerate, open and access FPGA accelerators on platforms which 158c2ecf20Sopenharmony_ciimplement the DFL in the device memory. Besides this, the DFL framework 168c2ecf20Sopenharmony_cienables system level management functions such as FPGA reconfiguration. 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ciDevice Feature List (DFL) Overview 208c2ecf20Sopenharmony_ci================================== 218c2ecf20Sopenharmony_ciDevice Feature List (DFL) defines a linked list of feature headers within the 228c2ecf20Sopenharmony_cidevice MMIO space to provide an extensible way of adding features. Software can 238c2ecf20Sopenharmony_ciwalk through these predefined data structures to enumerate FPGA features: 248c2ecf20Sopenharmony_ciFPGA Interface Unit (FIU), Accelerated Function Unit (AFU) and Private Features, 258c2ecf20Sopenharmony_cias illustrated below:: 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci Header Header Header Header 288c2ecf20Sopenharmony_ci +----------+ +-->+----------+ +-->+----------+ +-->+----------+ 298c2ecf20Sopenharmony_ci | Type | | | Type | | | Type | | | Type | 308c2ecf20Sopenharmony_ci | FIU | | | Private | | | Private | | | Private | 318c2ecf20Sopenharmony_ci +----------+ | | Feature | | | Feature | | | Feature | 328c2ecf20Sopenharmony_ci | Next_DFH |--+ +----------+ | +----------+ | +----------+ 338c2ecf20Sopenharmony_ci +----------+ | Next_DFH |--+ | Next_DFH |--+ | Next_DFH |--> NULL 348c2ecf20Sopenharmony_ci | ID | +----------+ +----------+ +----------+ 358c2ecf20Sopenharmony_ci +----------+ | ID | | ID | | ID | 368c2ecf20Sopenharmony_ci | Next_AFU |--+ +----------+ +----------+ +----------+ 378c2ecf20Sopenharmony_ci +----------+ | | Feature | | Feature | | Feature | 388c2ecf20Sopenharmony_ci | Header | | | Register | | Register | | Register | 398c2ecf20Sopenharmony_ci | Register | | | Set | | Set | | Set | 408c2ecf20Sopenharmony_ci | Set | | +----------+ +----------+ +----------+ 418c2ecf20Sopenharmony_ci +----------+ | Header 428c2ecf20Sopenharmony_ci +-->+----------+ 438c2ecf20Sopenharmony_ci | Type | 448c2ecf20Sopenharmony_ci | AFU | 458c2ecf20Sopenharmony_ci +----------+ 468c2ecf20Sopenharmony_ci | Next_DFH |--> NULL 478c2ecf20Sopenharmony_ci +----------+ 488c2ecf20Sopenharmony_ci | GUID | 498c2ecf20Sopenharmony_ci +----------+ 508c2ecf20Sopenharmony_ci | Header | 518c2ecf20Sopenharmony_ci | Register | 528c2ecf20Sopenharmony_ci | Set | 538c2ecf20Sopenharmony_ci +----------+ 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ciFPGA Interface Unit (FIU) represents a standalone functional unit for the 568c2ecf20Sopenharmony_ciinterface to FPGA, e.g. the FPGA Management Engine (FME) and Port (more 578c2ecf20Sopenharmony_cidescriptions on FME and Port in later sections). 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ciAccelerated Function Unit (AFU) represents a FPGA programmable region and 608c2ecf20Sopenharmony_cialways connects to a FIU (e.g. a Port) as its child as illustrated above. 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ciPrivate Features represent sub features of the FIU and AFU. They could be 638c2ecf20Sopenharmony_civarious function blocks with different IDs, but all private features which 648c2ecf20Sopenharmony_cibelong to the same FIU or AFU, must be linked to one list via the Next Device 658c2ecf20Sopenharmony_ciFeature Header (Next_DFH) pointer. 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ciEach FIU, AFU and Private Feature could implement its own functional registers. 688c2ecf20Sopenharmony_ciThe functional register set for FIU and AFU, is named as Header Register Set, 698c2ecf20Sopenharmony_cie.g. FME Header Register Set, and the one for Private Feature, is named as 708c2ecf20Sopenharmony_ciFeature Register Set, e.g. FME Partial Reconfiguration Feature Register Set. 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ciThis Device Feature List provides a way of linking features together, it's 738c2ecf20Sopenharmony_ciconvenient for software to locate each feature by walking through this list, 748c2ecf20Sopenharmony_ciand can be implemented in register regions of any FPGA device. 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ciFIU - FME (FPGA Management Engine) 788c2ecf20Sopenharmony_ci================================== 798c2ecf20Sopenharmony_ciThe FPGA Management Engine performs reconfiguration and other infrastructure 808c2ecf20Sopenharmony_cifunctions. Each FPGA device only has one FME. 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ciUser-space applications can acquire exclusive access to the FME using open(), 838c2ecf20Sopenharmony_ciand release it using close(). 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ciThe following functions are exposed through ioctls: 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci- Get driver API version (DFL_FPGA_GET_API_VERSION) 888c2ecf20Sopenharmony_ci- Check for extensions (DFL_FPGA_CHECK_EXTENSION) 898c2ecf20Sopenharmony_ci- Program bitstream (DFL_FPGA_FME_PORT_PR) 908c2ecf20Sopenharmony_ci- Assign port to PF (DFL_FPGA_FME_PORT_ASSIGN) 918c2ecf20Sopenharmony_ci- Release port from PF (DFL_FPGA_FME_PORT_RELEASE) 928c2ecf20Sopenharmony_ci- Get number of irqs of FME global error (DFL_FPGA_FME_ERR_GET_IRQ_NUM) 938c2ecf20Sopenharmony_ci- Set interrupt trigger for FME error (DFL_FPGA_FME_ERR_SET_IRQ) 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ciMore functions are exposed through sysfs 968c2ecf20Sopenharmony_ci(/sys/class/fpga_region/regionX/dfl-fme.n/): 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci Read bitstream ID (bitstream_id) 998c2ecf20Sopenharmony_ci bitstream_id indicates version of the static FPGA region. 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci Read bitstream metadata (bitstream_metadata) 1028c2ecf20Sopenharmony_ci bitstream_metadata includes detailed information of static FPGA region, 1038c2ecf20Sopenharmony_ci e.g. synthesis date and seed. 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci Read number of ports (ports_num) 1068c2ecf20Sopenharmony_ci one FPGA device may have more than one port, this sysfs interface indicates 1078c2ecf20Sopenharmony_ci how many ports the FPGA device has. 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci Global error reporting management (errors/) 1108c2ecf20Sopenharmony_ci error reporting sysfs interfaces allow user to read errors detected by the 1118c2ecf20Sopenharmony_ci hardware, and clear the logged errors. 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci Power management (dfl_fme_power hwmon) 1148c2ecf20Sopenharmony_ci power management hwmon sysfs interfaces allow user to read power management 1158c2ecf20Sopenharmony_ci information (power consumption, thresholds, threshold status, limits, etc.) 1168c2ecf20Sopenharmony_ci and configure power thresholds for different throttling levels. 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci Thermal management (dfl_fme_thermal hwmon) 1198c2ecf20Sopenharmony_ci thermal management hwmon sysfs interfaces allow user to read thermal 1208c2ecf20Sopenharmony_ci management information (current temperature, thresholds, threshold status, 1218c2ecf20Sopenharmony_ci etc.). 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci Performance reporting 1248c2ecf20Sopenharmony_ci performance counters are exposed through perf PMU APIs. Standard perf tool 1258c2ecf20Sopenharmony_ci can be used to monitor all available perf events. Please see performance 1268c2ecf20Sopenharmony_ci counter section below for more detailed information. 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ciFIU - PORT 1308c2ecf20Sopenharmony_ci========== 1318c2ecf20Sopenharmony_ciA port represents the interface between the static FPGA fabric and a partially 1328c2ecf20Sopenharmony_cireconfigurable region containing an AFU. It controls the communication from SW 1338c2ecf20Sopenharmony_cito the accelerator and exposes features such as reset and debug. Each FPGA 1348c2ecf20Sopenharmony_cidevice may have more than one port, but always one AFU per port. 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ciAFU 1388c2ecf20Sopenharmony_ci=== 1398c2ecf20Sopenharmony_ciAn AFU is attached to a port FIU and exposes a fixed length MMIO region to be 1408c2ecf20Sopenharmony_ciused for accelerator-specific control registers. 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ciUser-space applications can acquire exclusive access to an AFU attached to a 1438c2ecf20Sopenharmony_ciport by using open() on the port device node and release it using close(). 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ciThe following functions are exposed through ioctls: 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci- Get driver API version (DFL_FPGA_GET_API_VERSION) 1488c2ecf20Sopenharmony_ci- Check for extensions (DFL_FPGA_CHECK_EXTENSION) 1498c2ecf20Sopenharmony_ci- Get port info (DFL_FPGA_PORT_GET_INFO) 1508c2ecf20Sopenharmony_ci- Get MMIO region info (DFL_FPGA_PORT_GET_REGION_INFO) 1518c2ecf20Sopenharmony_ci- Map DMA buffer (DFL_FPGA_PORT_DMA_MAP) 1528c2ecf20Sopenharmony_ci- Unmap DMA buffer (DFL_FPGA_PORT_DMA_UNMAP) 1538c2ecf20Sopenharmony_ci- Reset AFU (DFL_FPGA_PORT_RESET) 1548c2ecf20Sopenharmony_ci- Get number of irqs of port error (DFL_FPGA_PORT_ERR_GET_IRQ_NUM) 1558c2ecf20Sopenharmony_ci- Set interrupt trigger for port error (DFL_FPGA_PORT_ERR_SET_IRQ) 1568c2ecf20Sopenharmony_ci- Get number of irqs of UINT (DFL_FPGA_PORT_UINT_GET_IRQ_NUM) 1578c2ecf20Sopenharmony_ci- Set interrupt trigger for UINT (DFL_FPGA_PORT_UINT_SET_IRQ) 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ciDFL_FPGA_PORT_RESET: 1608c2ecf20Sopenharmony_ci reset the FPGA Port and its AFU. Userspace can do Port 1618c2ecf20Sopenharmony_ci reset at any time, e.g. during DMA or Partial Reconfiguration. But it should 1628c2ecf20Sopenharmony_ci never cause any system level issue, only functional failure (e.g. DMA or PR 1638c2ecf20Sopenharmony_ci operation failure) and be recoverable from the failure. 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ciUser-space applications can also mmap() accelerator MMIO regions. 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ciMore functions are exposed through sysfs: 1688c2ecf20Sopenharmony_ci(/sys/class/fpga_region/<regionX>/<dfl-port.m>/): 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci Read Accelerator GUID (afu_id) 1718c2ecf20Sopenharmony_ci afu_id indicates which PR bitstream is programmed to this AFU. 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci Error reporting (errors/) 1748c2ecf20Sopenharmony_ci error reporting sysfs interfaces allow user to read port/afu errors 1758c2ecf20Sopenharmony_ci detected by the hardware, and clear the logged errors. 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ciDFL Framework Overview 1798c2ecf20Sopenharmony_ci====================== 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci:: 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci +----------+ +--------+ +--------+ +--------+ 1848c2ecf20Sopenharmony_ci | FME | | AFU | | AFU | | AFU | 1858c2ecf20Sopenharmony_ci | Module | | Module | | Module | | Module | 1868c2ecf20Sopenharmony_ci +----------+ +--------+ +--------+ +--------+ 1878c2ecf20Sopenharmony_ci +-----------------------+ 1888c2ecf20Sopenharmony_ci | FPGA Container Device | Device Feature List 1898c2ecf20Sopenharmony_ci | (FPGA Base Region) | Framework 1908c2ecf20Sopenharmony_ci +-----------------------+ 1918c2ecf20Sopenharmony_ci ------------------------------------------------------------------ 1928c2ecf20Sopenharmony_ci +----------------------------+ 1938c2ecf20Sopenharmony_ci | FPGA DFL Device Module | 1948c2ecf20Sopenharmony_ci | (e.g. PCIE/Platform Device)| 1958c2ecf20Sopenharmony_ci +----------------------------+ 1968c2ecf20Sopenharmony_ci +------------------------+ 1978c2ecf20Sopenharmony_ci | FPGA Hardware Device | 1988c2ecf20Sopenharmony_ci +------------------------+ 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ciDFL framework in kernel provides common interfaces to create container device 2018c2ecf20Sopenharmony_ci(FPGA base region), discover feature devices and their private features from the 2028c2ecf20Sopenharmony_cigiven Device Feature Lists and create platform devices for feature devices 2038c2ecf20Sopenharmony_ci(e.g. FME, Port and AFU) with related resources under the container device. It 2048c2ecf20Sopenharmony_cialso abstracts operations for the private features and exposes common ops to 2058c2ecf20Sopenharmony_cifeature device drivers. 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ciThe FPGA DFL Device could be different hardwares, e.g. PCIe device, platform 2088c2ecf20Sopenharmony_cidevice and etc. Its driver module is always loaded first once the device is 2098c2ecf20Sopenharmony_cicreated by the system. This driver plays an infrastructural role in the 2108c2ecf20Sopenharmony_cidriver architecture. It locates the DFLs in the device memory, handles them 2118c2ecf20Sopenharmony_ciand related resources to common interfaces from DFL framework for enumeration. 2128c2ecf20Sopenharmony_ci(Please refer to drivers/fpga/dfl.c for detailed enumeration APIs). 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ciThe FPGA Management Engine (FME) driver is a platform driver which is loaded 2158c2ecf20Sopenharmony_ciautomatically after FME platform device creation from the DFL device module. It 2168c2ecf20Sopenharmony_ciprovides the key features for FPGA management, including: 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci a) Expose static FPGA region information, e.g. version and metadata. 2198c2ecf20Sopenharmony_ci Users can read related information via sysfs interfaces exposed 2208c2ecf20Sopenharmony_ci by FME driver. 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_ci b) Partial Reconfiguration. The FME driver creates FPGA manager, FPGA 2238c2ecf20Sopenharmony_ci bridges and FPGA regions during PR sub feature initialization. Once 2248c2ecf20Sopenharmony_ci it receives a DFL_FPGA_FME_PORT_PR ioctl from user, it invokes the 2258c2ecf20Sopenharmony_ci common interface function from FPGA Region to complete the partial 2268c2ecf20Sopenharmony_ci reconfiguration of the PR bitstream to the given port. 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ciSimilar to the FME driver, the FPGA Accelerated Function Unit (AFU) driver is 2298c2ecf20Sopenharmony_ciprobed once the AFU platform device is created. The main function of this module 2308c2ecf20Sopenharmony_ciis to provide an interface for userspace applications to access the individual 2318c2ecf20Sopenharmony_ciaccelerators, including basic reset control on port, AFU MMIO region export, dma 2328c2ecf20Sopenharmony_cibuffer mapping service functions. 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ciAfter feature platform devices creation, matched platform drivers will be loaded 2358c2ecf20Sopenharmony_ciautomatically to handle different functionalities. Please refer to next sections 2368c2ecf20Sopenharmony_cifor detailed information on functional units which have been already implemented 2378c2ecf20Sopenharmony_ciunder this DFL framework. 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ciPartial Reconfiguration 2418c2ecf20Sopenharmony_ci======================= 2428c2ecf20Sopenharmony_ciAs mentioned above, accelerators can be reconfigured through partial 2438c2ecf20Sopenharmony_cireconfiguration of a PR bitstream file. The PR bitstream file must have been 2448c2ecf20Sopenharmony_cigenerated for the exact static FPGA region and targeted reconfigurable region 2458c2ecf20Sopenharmony_ci(port) of the FPGA, otherwise, the reconfiguration operation will fail and 2468c2ecf20Sopenharmony_cipossibly cause system instability. This compatibility can be checked by 2478c2ecf20Sopenharmony_cicomparing the compatibility ID noted in the header of PR bitstream file against 2488c2ecf20Sopenharmony_cithe compat_id exposed by the target FPGA region. This check is usually done by 2498c2ecf20Sopenharmony_ciuserspace before calling the reconfiguration IOCTL. 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ciFPGA virtualization - PCIe SRIOV 2538c2ecf20Sopenharmony_ci================================ 2548c2ecf20Sopenharmony_ciThis section describes the virtualization support on DFL based FPGA device to 2558c2ecf20Sopenharmony_cienable accessing an accelerator from applications running in a virtual machine 2568c2ecf20Sopenharmony_ci(VM). This section only describes the PCIe based FPGA device with SRIOV support. 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ciFeatures supported by the particular FPGA device are exposed through Device 2598c2ecf20Sopenharmony_ciFeature Lists, as illustrated below: 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_ci:: 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci +-------------------------------+ +-------------+ 2648c2ecf20Sopenharmony_ci | PF | | VF | 2658c2ecf20Sopenharmony_ci +-------------------------------+ +-------------+ 2668c2ecf20Sopenharmony_ci ^ ^ ^ ^ 2678c2ecf20Sopenharmony_ci | | | | 2688c2ecf20Sopenharmony_ci +-----|------------|---------|--------------|-------+ 2698c2ecf20Sopenharmony_ci | | | | | | 2708c2ecf20Sopenharmony_ci | +-----+ +-------+ +-------+ +-------+ | 2718c2ecf20Sopenharmony_ci | | FME | | Port0 | | Port1 | | Port2 | | 2728c2ecf20Sopenharmony_ci | +-----+ +-------+ +-------+ +-------+ | 2738c2ecf20Sopenharmony_ci | ^ ^ ^ | 2748c2ecf20Sopenharmony_ci | | | | | 2758c2ecf20Sopenharmony_ci | +-------+ +------+ +-------+ | 2768c2ecf20Sopenharmony_ci | | AFU | | AFU | | AFU | | 2778c2ecf20Sopenharmony_ci | +-------+ +------+ +-------+ | 2788c2ecf20Sopenharmony_ci | | 2798c2ecf20Sopenharmony_ci | DFL based FPGA PCIe Device | 2808c2ecf20Sopenharmony_ci +---------------------------------------------------+ 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ciFME is always accessed through the physical function (PF). 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_ciPorts (and related AFUs) are accessed via PF by default, but could be exposed 2858c2ecf20Sopenharmony_cithrough virtual function (VF) devices via PCIe SRIOV. Each VF only contains 2868c2ecf20Sopenharmony_ci1 Port and 1 AFU for isolation. Users could assign individual VFs (accelerators) 2878c2ecf20Sopenharmony_cicreated via PCIe SRIOV interface, to virtual machines. 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ciThe driver organization in virtualization case is illustrated below: 2908c2ecf20Sopenharmony_ci:: 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci +-------++------++------+ | 2938c2ecf20Sopenharmony_ci | FME || FME || FME | | 2948c2ecf20Sopenharmony_ci | FPGA || FPGA || FPGA | | 2958c2ecf20Sopenharmony_ci |Manager||Bridge||Region| | 2968c2ecf20Sopenharmony_ci +-------++------++------+ | 2978c2ecf20Sopenharmony_ci +-----------------------+ +--------+ | +--------+ 2988c2ecf20Sopenharmony_ci | FME | | AFU | | | AFU | 2998c2ecf20Sopenharmony_ci | Module | | Module | | | Module | 3008c2ecf20Sopenharmony_ci +-----------------------+ +--------+ | +--------+ 3018c2ecf20Sopenharmony_ci +-----------------------+ | +-----------------------+ 3028c2ecf20Sopenharmony_ci | FPGA Container Device | | | FPGA Container Device | 3038c2ecf20Sopenharmony_ci | (FPGA Base Region) | | | (FPGA Base Region) | 3048c2ecf20Sopenharmony_ci +-----------------------+ | +-----------------------+ 3058c2ecf20Sopenharmony_ci +------------------+ | +------------------+ 3068c2ecf20Sopenharmony_ci | FPGA PCIE Module | | Virtual | FPGA PCIE Module | 3078c2ecf20Sopenharmony_ci +------------------+ Host | Machine +------------------+ 3088c2ecf20Sopenharmony_ci -------------------------------------- | ------------------------------ 3098c2ecf20Sopenharmony_ci +---------------+ | +---------------+ 3108c2ecf20Sopenharmony_ci | PCI PF Device | | | PCI VF Device | 3118c2ecf20Sopenharmony_ci +---------------+ | +---------------+ 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ciFPGA PCIe device driver is always loaded first once a FPGA PCIe PF or VF device 3148c2ecf20Sopenharmony_ciis detected. It: 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci* Finishes enumeration on both FPGA PCIe PF and VF device using common 3178c2ecf20Sopenharmony_ci interfaces from DFL framework. 3188c2ecf20Sopenharmony_ci* Supports SRIOV. 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_ciThe FME device driver plays a management role in this driver architecture, it 3218c2ecf20Sopenharmony_ciprovides ioctls to release Port from PF and assign Port to PF. After release 3228c2ecf20Sopenharmony_cia port from PF, then it's safe to expose this port through a VF via PCIe SRIOV 3238c2ecf20Sopenharmony_cisysfs interface. 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ciTo enable accessing an accelerator from applications running in a VM, the 3268c2ecf20Sopenharmony_cirespective AFU's port needs to be assigned to a VF using the following steps: 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci#. The PF owns all AFU ports by default. Any port that needs to be 3298c2ecf20Sopenharmony_ci reassigned to a VF must first be released through the 3308c2ecf20Sopenharmony_ci DFL_FPGA_FME_PORT_RELEASE ioctl on the FME device. 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci#. Once N ports are released from PF, then user can use command below 3338c2ecf20Sopenharmony_ci to enable SRIOV and VFs. Each VF owns only one Port with AFU. 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci :: 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_ci echo N > $PCI_DEVICE_PATH/sriov_numvfs 3388c2ecf20Sopenharmony_ci 3398c2ecf20Sopenharmony_ci#. Pass through the VFs to VMs 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_ci#. The AFU under VF is accessible from applications in VM (using the 3428c2ecf20Sopenharmony_ci same driver inside the VF). 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_ciNote that an FME can't be assigned to a VF, thus PR and other management 3458c2ecf20Sopenharmony_cifunctions are only available via the PF. 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ciDevice enumeration 3488c2ecf20Sopenharmony_ci================== 3498c2ecf20Sopenharmony_ciThis section introduces how applications enumerate the fpga device from 3508c2ecf20Sopenharmony_cithe sysfs hierarchy under /sys/class/fpga_region. 3518c2ecf20Sopenharmony_ci 3528c2ecf20Sopenharmony_ciIn the example below, two DFL based FPGA devices are installed in the host. Each 3538c2ecf20Sopenharmony_cifpga device has one FME and two ports (AFUs). 3548c2ecf20Sopenharmony_ci 3558c2ecf20Sopenharmony_ciFPGA regions are created under /sys/class/fpga_region/:: 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_ci /sys/class/fpga_region/region0 3588c2ecf20Sopenharmony_ci /sys/class/fpga_region/region1 3598c2ecf20Sopenharmony_ci /sys/class/fpga_region/region2 3608c2ecf20Sopenharmony_ci ... 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_ciApplication needs to search each regionX folder, if feature device is found, 3638c2ecf20Sopenharmony_ci(e.g. "dfl-port.n" or "dfl-fme.m" is found), then it's the base 3648c2ecf20Sopenharmony_cifpga region which represents the FPGA device. 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_ciEach base region has one FME and two ports (AFUs) as child devices:: 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci /sys/class/fpga_region/region0/dfl-fme.0 3698c2ecf20Sopenharmony_ci /sys/class/fpga_region/region0/dfl-port.0 3708c2ecf20Sopenharmony_ci /sys/class/fpga_region/region0/dfl-port.1 3718c2ecf20Sopenharmony_ci ... 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ci /sys/class/fpga_region/region3/dfl-fme.1 3748c2ecf20Sopenharmony_ci /sys/class/fpga_region/region3/dfl-port.2 3758c2ecf20Sopenharmony_ci /sys/class/fpga_region/region3/dfl-port.3 3768c2ecf20Sopenharmony_ci ... 3778c2ecf20Sopenharmony_ci 3788c2ecf20Sopenharmony_ciIn general, the FME/AFU sysfs interfaces are named as follows:: 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci /sys/class/fpga_region/<regionX>/<dfl-fme.n>/ 3818c2ecf20Sopenharmony_ci /sys/class/fpga_region/<regionX>/<dfl-port.m>/ 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_ciwith 'n' consecutively numbering all FMEs and 'm' consecutively numbering all 3848c2ecf20Sopenharmony_ciports. 3858c2ecf20Sopenharmony_ci 3868c2ecf20Sopenharmony_ciThe device nodes used for ioctl() or mmap() can be referenced through:: 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_ci /sys/class/fpga_region/<regionX>/<dfl-fme.n>/dev 3898c2ecf20Sopenharmony_ci /sys/class/fpga_region/<regionX>/<dfl-port.n>/dev 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_ciPerformance Counters 3938c2ecf20Sopenharmony_ci==================== 3948c2ecf20Sopenharmony_ciPerformance reporting is one private feature implemented in FME. It could 3958c2ecf20Sopenharmony_cisupports several independent, system-wide, device counter sets in hardware to 3968c2ecf20Sopenharmony_cimonitor and count for performance events, including "basic", "cache", "fabric", 3978c2ecf20Sopenharmony_ci"vtd" and "vtd_sip" counters. Users could use standard perf tool to monitor 3988c2ecf20Sopenharmony_ciFPGA cache hit/miss rate, transaction number, interface clock counter of AFU 3998c2ecf20Sopenharmony_ciand other FPGA performance events. 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ciDifferent FPGA devices may have different counter sets, depending on hardware 4028c2ecf20Sopenharmony_ciimplementation. E.g., some discrete FPGA cards don't have any cache. User could 4038c2ecf20Sopenharmony_ciuse "perf list" to check which perf events are supported by target hardware. 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ciIn order to allow user to use standard perf API to access these performance 4068c2ecf20Sopenharmony_cicounters, driver creates a perf PMU, and related sysfs interfaces in 4078c2ecf20Sopenharmony_ci/sys/bus/event_source/devices/dfl_fme* to describe available perf events and 4088c2ecf20Sopenharmony_ciconfiguration options. 4098c2ecf20Sopenharmony_ci 4108c2ecf20Sopenharmony_ciThe "format" directory describes the format of the config field of struct 4118c2ecf20Sopenharmony_ciperf_event_attr. There are 3 bitfields for config: "evtype" defines which type 4128c2ecf20Sopenharmony_cithe perf event belongs to; "event" is the identity of the event within its 4138c2ecf20Sopenharmony_cicategory; "portid" is introduced to decide counters set to monitor on FPGA 4148c2ecf20Sopenharmony_cioverall data or a specific port. 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ciThe "events" directory describes the configuration templates for all available 4178c2ecf20Sopenharmony_cievents which can be used with perf tool directly. For example, fab_mmio_read 4188c2ecf20Sopenharmony_cihas the configuration "event=0x06,evtype=0x02,portid=0xff", which shows this 4198c2ecf20Sopenharmony_cievent belongs to fabric type (0x02), the local event id is 0x06 and it is for 4208c2ecf20Sopenharmony_cioverall monitoring (portid=0xff). 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_ciExample usage of perf:: 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_ci $# perf list |grep dfl_fme 4258c2ecf20Sopenharmony_ci 4268c2ecf20Sopenharmony_ci dfl_fme0/fab_mmio_read/ [Kernel PMU event] 4278c2ecf20Sopenharmony_ci <...> 4288c2ecf20Sopenharmony_ci dfl_fme0/fab_port_mmio_read,portid=?/ [Kernel PMU event] 4298c2ecf20Sopenharmony_ci <...> 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci $# perf stat -a -e dfl_fme0/fab_mmio_read/ <command> 4328c2ecf20Sopenharmony_ci or 4338c2ecf20Sopenharmony_ci $# perf stat -a -e dfl_fme0/event=0x06,evtype=0x02,portid=0xff/ <command> 4348c2ecf20Sopenharmony_ci or 4358c2ecf20Sopenharmony_ci $# perf stat -a -e dfl_fme0/config=0xff2006/ <command> 4368c2ecf20Sopenharmony_ci 4378c2ecf20Sopenharmony_ciAnother example, fab_port_mmio_read monitors mmio read of a specific port. So 4388c2ecf20Sopenharmony_ciits configuration template is "event=0x06,evtype=0x01,portid=?". The portid 4398c2ecf20Sopenharmony_cishould be explicitly set. 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_ciIts usage of perf:: 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci $# perf stat -a -e dfl_fme0/fab_port_mmio_read,portid=0x0/ <command> 4448c2ecf20Sopenharmony_ci or 4458c2ecf20Sopenharmony_ci $# perf stat -a -e dfl_fme0/event=0x06,evtype=0x02,portid=0x0/ <command> 4468c2ecf20Sopenharmony_ci or 4478c2ecf20Sopenharmony_ci $# perf stat -a -e dfl_fme0/config=0x2006/ <command> 4488c2ecf20Sopenharmony_ci 4498c2ecf20Sopenharmony_ciPlease note for fabric counters, overall perf events (fab_*) and port perf 4508c2ecf20Sopenharmony_cievents (fab_port_*) actually share one set of counters in hardware, so it can't 4518c2ecf20Sopenharmony_cimonitor both at the same time. If this set of counters is configured to monitor 4528c2ecf20Sopenharmony_cioverall data, then per port perf data is not supported. See below example:: 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_ci $# perf stat -e dfl_fme0/fab_mmio_read/,dfl_fme0/fab_port_mmio_write,\ 4558c2ecf20Sopenharmony_ci portid=0/ sleep 1 4568c2ecf20Sopenharmony_ci 4578c2ecf20Sopenharmony_ci Performance counter stats for 'system wide': 4588c2ecf20Sopenharmony_ci 4598c2ecf20Sopenharmony_ci 3 dfl_fme0/fab_mmio_read/ 4608c2ecf20Sopenharmony_ci <not supported> dfl_fme0/fab_port_mmio_write,portid=0x0/ 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_ci 1.001750904 seconds time elapsed 4638c2ecf20Sopenharmony_ci 4648c2ecf20Sopenharmony_ciThe driver also provides a "cpumask" sysfs attribute, which contains only one 4658c2ecf20Sopenharmony_ciCPU id used to access these perf events. Counting on multiple CPU is not allowed 4668c2ecf20Sopenharmony_cisince they are system-wide counters on FPGA device. 4678c2ecf20Sopenharmony_ci 4688c2ecf20Sopenharmony_ciThe current driver does not support sampling. So "perf record" is unsupported. 4698c2ecf20Sopenharmony_ci 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_ciInterrupt support 4728c2ecf20Sopenharmony_ci================= 4738c2ecf20Sopenharmony_ciSome FME and AFU private features are able to generate interrupts. As mentioned 4748c2ecf20Sopenharmony_ciabove, users could call ioctl (DFL_FPGA_*_GET_IRQ_NUM) to know whether or how 4758c2ecf20Sopenharmony_cimany interrupts are supported for this private feature. Drivers also implement 4768c2ecf20Sopenharmony_cian eventfd based interrupt handling mechanism for users to get notified when 4778c2ecf20Sopenharmony_ciinterrupt happens. Users could set eventfds to driver via 4788c2ecf20Sopenharmony_ciioctl (DFL_FPGA_*_SET_IRQ), and then poll/select on these eventfds waiting for 4798c2ecf20Sopenharmony_cinotification. 4808c2ecf20Sopenharmony_ciIn Current DFL, 3 sub features (Port error, FME global error and AFU interrupt) 4818c2ecf20Sopenharmony_cisupport interrupts. 4828c2ecf20Sopenharmony_ci 4838c2ecf20Sopenharmony_ci 4848c2ecf20Sopenharmony_ciAdd new FIUs support 4858c2ecf20Sopenharmony_ci==================== 4868c2ecf20Sopenharmony_ciIt's possible that developers made some new function blocks (FIUs) under this 4878c2ecf20Sopenharmony_ciDFL framework, then new platform device driver needs to be developed for the 4888c2ecf20Sopenharmony_cinew feature dev (FIU) following the same way as existing feature dev drivers 4898c2ecf20Sopenharmony_ci(e.g. FME and Port/AFU platform device driver). Besides that, it requires 4908c2ecf20Sopenharmony_cimodification on DFL framework enumeration code too, for new FIU type detection 4918c2ecf20Sopenharmony_ciand related platform devices creation. 4928c2ecf20Sopenharmony_ci 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_ciAdd new private features support 4958c2ecf20Sopenharmony_ci================================ 4968c2ecf20Sopenharmony_ciIn some cases, we may need to add some new private features to existing FIUs 4978c2ecf20Sopenharmony_ci(e.g. FME or Port). Developers don't need to touch enumeration code in DFL 4988c2ecf20Sopenharmony_ciframework, as each private feature will be parsed automatically and related 4998c2ecf20Sopenharmony_cimmio resources can be found under FIU platform device created by DFL framework. 5008c2ecf20Sopenharmony_ciDeveloper only needs to provide a sub feature driver with matched feature id. 5018c2ecf20Sopenharmony_ciFME Partial Reconfiguration Sub Feature driver (see drivers/fpga/dfl-fme-pr.c) 5028c2ecf20Sopenharmony_cicould be a reference. 5038c2ecf20Sopenharmony_ci 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_ciOpen discussion 5068c2ecf20Sopenharmony_ci=============== 5078c2ecf20Sopenharmony_ciFME driver exports one ioctl (DFL_FPGA_FME_PORT_PR) for partial reconfiguration 5088c2ecf20Sopenharmony_cito user now. In the future, if unified user interfaces for reconfiguration are 5098c2ecf20Sopenharmony_ciadded, FME driver should switch to them from ioctl interface. 510