Blame doc/src/drv_arch/drv_arch.md

Packit 534379
# Open Programmable Accelerator Engine (OPAE) Linux Device Driver Architecture #
Packit 534379
Packit 534379
.. toctree::
Packit 534379
Packit 534379
.. highlight:: c
Packit 534379
Packit 534379
.. highlight:: sh
Packit 534379
Packit 534379
.. highlight:: console
Packit 534379
Packit 534379
The OPAE FPGA Linux Device Driver provides interfaces for user-space applications to
Packit 534379
configure, enumerate, open, and access FPGA accelerators on platforms equipped
Packit 534379
with Intel FPGA solutions. The OPAE FPGA driver also enables system-level management functions such
Packit 534379
as FPGA reconfiguration and virtualization.
Packit 534379
Packit 534379
## Hardware Architecture ##
Packit 534379
Packit 534379
The Linux Operating System treats the FPGA hardware as a PCIe\* device. A predefined data structure,
Packit 534379
Device Feature List (DFL), allows for dynamic feature discovery in an Intel
Packit 534379
FPGA solution.
Packit 534379
Packit 534379
![FPGA PCIe Device](FPGA_PCIe_Device.png "FPGA PCIe Device")
Packit 534379
Packit 534379
The Linux Device Driver implements PCIe Single Root I/O Virtualization (SR-IOV) for the creation of
Packit 534379
Virtual Functions (VFs). The device driver can release individual accelerators
Packit 534379
for assignment to virtual machines (VMs).
Packit 534379
Packit 534379
![Virtualized FPGA PCIe Device](FPGA_PCIe_Device_SRIOV.png "Virtualized FPGA PCIe Device")
Packit 534379
Packit 534379
## FPGA Management Engine (FME) ##
Packit 534379
Packit 534379
The FPGA Management Engine provides error reporting, reconfiguration, performance reporting, and other
Packit 534379
infrastructure functions. Each FPGA has one FME which is always accessed through the Physical
Packit 534379
Function (PF). The Intel Xeon® Processor with Integrated FPGA also performs power and thermal management.
Packit 534379
These functions are not available on the Intel Programmable Acceleration Card (PAC).
Packit 534379
Packit 534379
User-space applications can acquire exclusive access to the FME using `open()`,
Packit 534379
and release it using `close()`. Device access may be managed by standard Linux
Packit 534379
interfaces and tools.
Packit 534379
Packit 534379
.. Note::
Packit 534379
Packit 534379
```
Packit 534379
    If an application terminates without freeing the FME or Port resources, Linux closes all
Packit 534379
    file descriptors owned by the terminating process, freeing those resources.
Packit 534379
```
Packit 534379
Packit 534379
## Port ##
Packit 534379
Packit 534379
A Port represents the interface between two components:
Packit 534379
* The FPGA Interface Manager (FIM) which is part of the static FPGA fabric
Packit 534379
* The Accelerator Function Unit (AFU) which is the partially reconfigurable region
Packit 534379
Packit 534379
The Port controls the communication from software to the AFU and makes features such as reset and debug available.
Packit 534379
Packit 534379
## Accelerator Function Unit (AFU) ##
Packit 534379
Packit 534379
An AFU attaches to a Port. The AFU provides a 256 KB memory mapped I/O (MMIO) region for accelerator-specific control registers.
Packit 534379
Packit 534379
* Use `open()` on the Port device to acquire access to an AFU associated with the Port device.
Packit 534379
* Use `close()`on the Port device to release the AFU associated with the Port device.
Packit 534379
* Use `mmap()` on the Port device to map accelerator MMIO regions.
Packit 534379
Packit 534379
## Partial Reconfiguration (PR) ##
Packit 534379
Packit 534379
Use PR to reconfigure an AFU from a bitstream file. Successful reconfiguration has the following requirement:
Packit 534379
Packit 534379
* You must generate the reconfiguration AFU for the exact FIM. The AFU and FIM are compatible if their interface IDs match.
Packit 534379
You can verify this match by comparing the interface ID in the bitstream header against the interface ID that is
Packit 534379
exported by the driver in sysfs.
Packit 534379
Packit 534379
In all other cases PR fails and may cause system instability.
Packit 534379
Packit 534379
.. note::
Packit 534379
Packit 534379
```
Packit 534379
    Platforms that support 512-bit Partial Reconfiguration require
Packit 534379
    binutils >= version 2.25.
Packit 534379
```
Packit 534379
Packit 534379
Close any software programs accessing the FPGA, including those running in a virtualized host before
Packit 534379
initiating PR. For virtualized environments, the recommended sequence is as
Packit 534379
follows:
Packit 534379
Packit 534379
1. Unload the driver from the guest
Packit 534379
2. Release the VF from the guest
Packit 534379
Packit 534379
.. note::
Packit 534379
Packit 534379
```
Packit 534379
    NOTE: Releasing the VF from the guest while an application on the guest is
Packit 534379
    still accessing its resources may lead to VM instabilities. We recommend
Packit 534379
    closing all applications accessing the VF in the guest before releasing the
Packit 534379
    VF.
Packit 534379
```
Packit 534379
3. Disable SR-IOV
Packit 534379
4. Perform PR
Packit 534379
5. Enable SR-IOV
Packit 534379
6. Assign the VF to the guest
Packit 534379
7. Load the driver in the guest
Packit 534379
Packit 534379
## FPGA Virtualization ##
Packit 534379
Packit 534379
To enable accelerator access from applications running on a VM, create a VF for
Packit 534379
the port using the following process:
Packit 534379
Packit 534379
1. Release the Port from the PF using the associated ioctl on the FME device.
Packit 534379
Packit 534379
2. Use the following command to enable SR-IOV and VFs. Each VF can own a single Port with an AFU. In the following command,
Packit 534379
N is the number of Port released from the PF.
Packit 534379
Packit 534379
```console
Packit 534379
    echo N > $PCI_DEVICE_PATH/sriov_numvfs
Packit 534379
```
Packit 534379
.. note::
Packit 534379
Packit 534379
```
Packit 534379
    NOTE: The number, 'N', cannot be greater than the number of supported VFs.
Packit 534379
    This can be read from $PCI_DEVICE_PATH/sriov_totalvfs.
Packit 534379
```
Packit 534379
Packit 534379
3. Pass the VFs through to VMs using hypervisor interfaces.
Packit 534379
Packit 534379
4. Access the AFU on a VF from applications running on the VM using the same driver inside the VM.
Packit 534379
Packit 534379
.. Note::
Packit 534379
Packit 534379
``
Packit 534379
Creating VFs is only supported for port devices. Consequently, PR and other management functions are only available through
Packit 534379
the PF.
Packit 534379
```
Packit 534379
## Driver Organization ##
Packit 534379
Packit 534379
### PCIe Module Device Driver ###
Packit 534379
Packit 534379
!## Driver Organization ##
Packit 534379
Packit 534379
### PCIe Module Device Driver ###
Packit 534379
Packit 534379
![Driver Organization](Driver_Organization.png "Driver Organization")
Packit 534379
Packit 534379
Packit 534379
Packit 534379
Packit 534379
FPGA devices appear as a PCIe devices. Once enumeration detects a PCIe PF or VF, the Linux OS loads the FPGA PCIe
Packit 534379
device driver. The device driver performs the following functions:
Packit 534379
Packit 534379
1. Walks through the Device Feature List in PCIe device base address register (BAR) memory to discover features
Packit 534379
and their sub-features and creates necessary platform devices.
Packit 534379
2. Enables SR-IOV.
Packit 534379
3. Introduces the feature device infrastructure, which abstracts operations for sub-features and provides common functions
Packit 534379
to feature device drivers.
Packit 534379
Packit 534379
### PCIe Module Device Driver Functions ###
Packit 534379
Packit 534379
The PCIe Module Device Driver performs the following functions:
Packit 534379
Packit 534379
1. PCIe discovery, device enumeration, and feature discovery.
Packit 534379
2. Creates sysfs directories for the device, FME, and Port.
Packit 534379
3. Creates the platform driver instances, causing the Linux kernel to load their respective drivers.
Packit 534379
Packit 534379
### FME Platform Module Device Driver ###
Packit 534379
Packit 534379
The FME Platform Module Device Driver loads automatically after the PCIe driver creates the
Packit 534379
FME Platform Module. It provides the following features for FPGA management:
Packit 534379
Packit 534379
1. Power and thermal management, error reporting, performance reporting, and other infrastructure functions. You can access
Packit 534379
these functions via sysfs interfaces the FME driver provides.
Packit 534379
Packit 534379
2. Partial Reconfiguration. During PR sub-feature initialization, the FME driver registers the FPGA Manager framework
Packit 534379
to support PR. When the FME receives the relevant ioctl request from user-space, it invokes the common interface
Packit 534379
function from the FPGA Manager to reconfigure the AFU using PR.
Packit 534379
Packit 534379
3. Port management for virtualization (releasing/assigning port device).
Packit 534379
Packit 534379
After a port device is released, you can use the PCIe driver SR-IOV interfaces to create/destroy VFs.
Packit 534379
Packit 534379
For more information, refer to "FPGA Virtualization".
Packit 534379
Packit 534379
### FME Platform Module Device Driver Functions ###
Packit 534379
Packit 534379
The FME Platform Module Device Driver performs the the following functions:
Packit 534379
Packit 534379
* Creates the FME character device node.
Packit 534379
* Creates the FME sysfs files and implements the FME sysfs file accessors.
Packit 534379
* Implements the FME private feature sub-drivers.
Packit 534379
* FME private feature sub-drivers:
Packit 534379
    * FME Header
Packit 534379
    * Partial Reconfiguration
Packit 534379
    * Global Error
Packit 534379
    * Global Performance
Packit 534379
Packit 534379
### Port Platform Module Device Driver ###
Packit 534379
Packit 534379
After the PCIe Module Device Driver creates the Port Platform Module device,
Packit 534379
the FPGA Port and AFU driver are loaded.  This module provides an
Packit 534379
interface for user-space applications to access the individual
Packit 534379
accelerators, including basic reset control on the Port, AFU MMIO region
Packit 534379
export, DMA buffer mapping service, and remote debug functions.
Packit 534379
Packit 534379
### Port Platform Module Device Driver Functions ###
Packit 534379
Packit 534379
The Port Platform Module Device Driver performs the the following functions:
Packit 534379
Packit 534379
* Creates the Port character device node.
Packit 534379
* Creates the Port sysfs files and implements the Port sysfs file accessors.
Packit 534379
* Implements the following Port private feature sub-drivers.
Packit 534379
    * Port Header
Packit 534379
    * AFU
Packit 534379
    * Port Error
Packit 534379
    * Signal Tap
Packit 534379
Packit 534379
### OPAE FPGA Driver Interface ###
Packit 534379
The user-space interface consists of a sysfs hierarchy and ioctl requests. Most
Packit 534379
kernel attributes can be accessed/modified via sysfs nodes in this hierarchy.
Packit 534379
More complex I/O operations are controlled via ioctl requests. The OPAE API
Packit 534379
implementation, libopae-c, has been designed to use this interface to
Packit 534379
interact with the OPAE FPGA kernel drivers.
Packit 534379