xref: /OK3568_Linux_fs/kernel/Documentation/fpga/dfl.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun=================================================
2*4882a593SmuzhiyunFPGA Device Feature List (DFL) Framework Overview
3*4882a593Smuzhiyun=================================================
4*4882a593Smuzhiyun
5*4882a593SmuzhiyunAuthors:
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun- Enno Luebbers <enno.luebbers@intel.com>
8*4882a593Smuzhiyun- Xiao Guangrong <guangrong.xiao@linux.intel.com>
9*4882a593Smuzhiyun- Wu Hao <hao.wu@intel.com>
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunThe Device Feature List (DFL) FPGA framework (and drivers according to
12*4882a593Smuzhiyunthis framework) hides the very details of low layer hardwares and provides
13*4882a593Smuzhiyununified interfaces to userspace. Applications could use these interfaces to
14*4882a593Smuzhiyunconfigure, enumerate, open and access FPGA accelerators on platforms which
15*4882a593Smuzhiyunimplement the DFL in the device memory. Besides this, the DFL framework
16*4882a593Smuzhiyunenables system level management functions such as FPGA reconfiguration.
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun
19*4882a593SmuzhiyunDevice Feature List (DFL) Overview
20*4882a593Smuzhiyun==================================
21*4882a593SmuzhiyunDevice Feature List (DFL) defines a linked list of feature headers within the
22*4882a593Smuzhiyundevice MMIO space to provide an extensible way of adding features. Software can
23*4882a593Smuzhiyunwalk through these predefined data structures to enumerate FPGA features:
24*4882a593SmuzhiyunFPGA Interface Unit (FIU), Accelerated Function Unit (AFU) and Private Features,
25*4882a593Smuzhiyunas illustrated below::
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun    Header            Header            Header            Header
28*4882a593Smuzhiyun +----------+  +-->+----------+  +-->+----------+  +-->+----------+
29*4882a593Smuzhiyun |   Type   |  |   |  Type    |  |   |  Type    |  |   |  Type    |
30*4882a593Smuzhiyun |   FIU    |  |   | Private  |  |   | Private  |  |   | Private  |
31*4882a593Smuzhiyun +----------+  |   | Feature  |  |   | Feature  |  |   | Feature  |
32*4882a593Smuzhiyun | Next_DFH |--+   +----------+  |   +----------+  |   +----------+
33*4882a593Smuzhiyun +----------+      | Next_DFH |--+   | Next_DFH |--+   | Next_DFH |--> NULL
34*4882a593Smuzhiyun |    ID    |      +----------+      +----------+      +----------+
35*4882a593Smuzhiyun +----------+      |    ID    |      |    ID    |      |    ID    |
36*4882a593Smuzhiyun | Next_AFU |--+   +----------+      +----------+      +----------+
37*4882a593Smuzhiyun +----------+  |   | Feature  |      | Feature  |      | Feature  |
38*4882a593Smuzhiyun |  Header  |  |   | Register |      | Register |      | Register |
39*4882a593Smuzhiyun | Register |  |   |   Set    |      |   Set    |      |   Set    |
40*4882a593Smuzhiyun |   Set    |  |   +----------+      +----------+      +----------+
41*4882a593Smuzhiyun +----------+  |      Header
42*4882a593Smuzhiyun               +-->+----------+
43*4882a593Smuzhiyun                   |   Type   |
44*4882a593Smuzhiyun                   |   AFU    |
45*4882a593Smuzhiyun                   +----------+
46*4882a593Smuzhiyun                   | Next_DFH |--> NULL
47*4882a593Smuzhiyun                   +----------+
48*4882a593Smuzhiyun                   |   GUID   |
49*4882a593Smuzhiyun                   +----------+
50*4882a593Smuzhiyun                   |  Header  |
51*4882a593Smuzhiyun                   | Register |
52*4882a593Smuzhiyun                   |   Set    |
53*4882a593Smuzhiyun                   +----------+
54*4882a593Smuzhiyun
55*4882a593SmuzhiyunFPGA Interface Unit (FIU) represents a standalone functional unit for the
56*4882a593Smuzhiyuninterface to FPGA, e.g. the FPGA Management Engine (FME) and Port (more
57*4882a593Smuzhiyundescriptions on FME and Port in later sections).
58*4882a593Smuzhiyun
59*4882a593SmuzhiyunAccelerated Function Unit (AFU) represents a FPGA programmable region and
60*4882a593Smuzhiyunalways connects to a FIU (e.g. a Port) as its child as illustrated above.
61*4882a593Smuzhiyun
62*4882a593SmuzhiyunPrivate Features represent sub features of the FIU and AFU. They could be
63*4882a593Smuzhiyunvarious function blocks with different IDs, but all private features which
64*4882a593Smuzhiyunbelong to the same FIU or AFU, must be linked to one list via the Next Device
65*4882a593SmuzhiyunFeature Header (Next_DFH) pointer.
66*4882a593Smuzhiyun
67*4882a593SmuzhiyunEach FIU, AFU and Private Feature could implement its own functional registers.
68*4882a593SmuzhiyunThe functional register set for FIU and AFU, is named as Header Register Set,
69*4882a593Smuzhiyune.g. FME Header Register Set, and the one for Private Feature, is named as
70*4882a593SmuzhiyunFeature Register Set, e.g. FME Partial Reconfiguration Feature Register Set.
71*4882a593Smuzhiyun
72*4882a593SmuzhiyunThis Device Feature List provides a way of linking features together, it's
73*4882a593Smuzhiyunconvenient for software to locate each feature by walking through this list,
74*4882a593Smuzhiyunand can be implemented in register regions of any FPGA device.
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun
77*4882a593SmuzhiyunFIU - FME (FPGA Management Engine)
78*4882a593Smuzhiyun==================================
79*4882a593SmuzhiyunThe FPGA Management Engine performs reconfiguration and other infrastructure
80*4882a593Smuzhiyunfunctions. Each FPGA device only has one FME.
81*4882a593Smuzhiyun
82*4882a593SmuzhiyunUser-space applications can acquire exclusive access to the FME using open(),
83*4882a593Smuzhiyunand release it using close().
84*4882a593Smuzhiyun
85*4882a593SmuzhiyunThe following functions are exposed through ioctls:
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun- Get driver API version (DFL_FPGA_GET_API_VERSION)
88*4882a593Smuzhiyun- Check for extensions (DFL_FPGA_CHECK_EXTENSION)
89*4882a593Smuzhiyun- Program bitstream (DFL_FPGA_FME_PORT_PR)
90*4882a593Smuzhiyun- Assign port to PF (DFL_FPGA_FME_PORT_ASSIGN)
91*4882a593Smuzhiyun- Release port from PF (DFL_FPGA_FME_PORT_RELEASE)
92*4882a593Smuzhiyun- Get number of irqs of FME global error (DFL_FPGA_FME_ERR_GET_IRQ_NUM)
93*4882a593Smuzhiyun- Set interrupt trigger for FME error (DFL_FPGA_FME_ERR_SET_IRQ)
94*4882a593Smuzhiyun
95*4882a593SmuzhiyunMore functions are exposed through sysfs
96*4882a593Smuzhiyun(/sys/class/fpga_region/regionX/dfl-fme.n/):
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun Read bitstream ID (bitstream_id)
99*4882a593Smuzhiyun     bitstream_id indicates version of the static FPGA region.
100*4882a593Smuzhiyun
101*4882a593Smuzhiyun Read bitstream metadata (bitstream_metadata)
102*4882a593Smuzhiyun     bitstream_metadata includes detailed information of static FPGA region,
103*4882a593Smuzhiyun     e.g. synthesis date and seed.
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun Read number of ports (ports_num)
106*4882a593Smuzhiyun     one FPGA device may have more than one port, this sysfs interface indicates
107*4882a593Smuzhiyun     how many ports the FPGA device has.
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun Global error reporting management (errors/)
110*4882a593Smuzhiyun     error reporting sysfs interfaces allow user to read errors detected by the
111*4882a593Smuzhiyun     hardware, and clear the logged errors.
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun Power management (dfl_fme_power hwmon)
114*4882a593Smuzhiyun     power management hwmon sysfs interfaces allow user to read power management
115*4882a593Smuzhiyun     information (power consumption, thresholds, threshold status, limits, etc.)
116*4882a593Smuzhiyun     and configure power thresholds for different throttling levels.
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun Thermal management (dfl_fme_thermal hwmon)
119*4882a593Smuzhiyun     thermal management hwmon sysfs interfaces allow user to read thermal
120*4882a593Smuzhiyun     management information (current temperature, thresholds, threshold status,
121*4882a593Smuzhiyun     etc.).
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun Performance reporting
124*4882a593Smuzhiyun     performance counters are exposed through perf PMU APIs. Standard perf tool
125*4882a593Smuzhiyun     can be used to monitor all available perf events. Please see performance
126*4882a593Smuzhiyun     counter section below for more detailed information.
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun
129*4882a593SmuzhiyunFIU - PORT
130*4882a593Smuzhiyun==========
131*4882a593SmuzhiyunA port represents the interface between the static FPGA fabric and a partially
132*4882a593Smuzhiyunreconfigurable region containing an AFU. It controls the communication from SW
133*4882a593Smuzhiyunto the accelerator and exposes features such as reset and debug. Each FPGA
134*4882a593Smuzhiyundevice may have more than one port, but always one AFU per port.
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun
137*4882a593SmuzhiyunAFU
138*4882a593Smuzhiyun===
139*4882a593SmuzhiyunAn AFU is attached to a port FIU and exposes a fixed length MMIO region to be
140*4882a593Smuzhiyunused for accelerator-specific control registers.
141*4882a593Smuzhiyun
142*4882a593SmuzhiyunUser-space applications can acquire exclusive access to an AFU attached to a
143*4882a593Smuzhiyunport by using open() on the port device node and release it using close().
144*4882a593Smuzhiyun
145*4882a593SmuzhiyunThe following functions are exposed through ioctls:
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun- Get driver API version (DFL_FPGA_GET_API_VERSION)
148*4882a593Smuzhiyun- Check for extensions (DFL_FPGA_CHECK_EXTENSION)
149*4882a593Smuzhiyun- Get port info (DFL_FPGA_PORT_GET_INFO)
150*4882a593Smuzhiyun- Get MMIO region info (DFL_FPGA_PORT_GET_REGION_INFO)
151*4882a593Smuzhiyun- Map DMA buffer (DFL_FPGA_PORT_DMA_MAP)
152*4882a593Smuzhiyun- Unmap DMA buffer (DFL_FPGA_PORT_DMA_UNMAP)
153*4882a593Smuzhiyun- Reset AFU (DFL_FPGA_PORT_RESET)
154*4882a593Smuzhiyun- Get number of irqs of port error (DFL_FPGA_PORT_ERR_GET_IRQ_NUM)
155*4882a593Smuzhiyun- Set interrupt trigger for port error (DFL_FPGA_PORT_ERR_SET_IRQ)
156*4882a593Smuzhiyun- Get number of irqs of UINT (DFL_FPGA_PORT_UINT_GET_IRQ_NUM)
157*4882a593Smuzhiyun- Set interrupt trigger for UINT (DFL_FPGA_PORT_UINT_SET_IRQ)
158*4882a593Smuzhiyun
159*4882a593SmuzhiyunDFL_FPGA_PORT_RESET:
160*4882a593Smuzhiyun  reset the FPGA Port and its AFU. Userspace can do Port
161*4882a593Smuzhiyun  reset at any time, e.g. during DMA or Partial Reconfiguration. But it should
162*4882a593Smuzhiyun  never cause any system level issue, only functional failure (e.g. DMA or PR
163*4882a593Smuzhiyun  operation failure) and be recoverable from the failure.
164*4882a593Smuzhiyun
165*4882a593SmuzhiyunUser-space applications can also mmap() accelerator MMIO regions.
166*4882a593Smuzhiyun
167*4882a593SmuzhiyunMore functions are exposed through sysfs:
168*4882a593Smuzhiyun(/sys/class/fpga_region/<regionX>/<dfl-port.m>/):
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun Read Accelerator GUID (afu_id)
171*4882a593Smuzhiyun     afu_id indicates which PR bitstream is programmed to this AFU.
172*4882a593Smuzhiyun
173*4882a593Smuzhiyun Error reporting (errors/)
174*4882a593Smuzhiyun     error reporting sysfs interfaces allow user to read port/afu errors
175*4882a593Smuzhiyun     detected by the hardware, and clear the logged errors.
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun
178*4882a593SmuzhiyunDFL Framework Overview
179*4882a593Smuzhiyun======================
180*4882a593Smuzhiyun
181*4882a593Smuzhiyun::
182*4882a593Smuzhiyun
183*4882a593Smuzhiyun         +----------+    +--------+ +--------+ +--------+
184*4882a593Smuzhiyun         |   FME    |    |  AFU   | |  AFU   | |  AFU   |
185*4882a593Smuzhiyun         |  Module  |    | Module | | Module | | Module |
186*4882a593Smuzhiyun         +----------+    +--------+ +--------+ +--------+
187*4882a593Smuzhiyun                 +-----------------------+
188*4882a593Smuzhiyun                 | FPGA Container Device |    Device Feature List
189*4882a593Smuzhiyun                 |  (FPGA Base Region)   |         Framework
190*4882a593Smuzhiyun                 +-----------------------+
191*4882a593Smuzhiyun  ------------------------------------------------------------------
192*4882a593Smuzhiyun               +----------------------------+
193*4882a593Smuzhiyun               |   FPGA DFL Device Module   |
194*4882a593Smuzhiyun               | (e.g. PCIE/Platform Device)|
195*4882a593Smuzhiyun               +----------------------------+
196*4882a593Smuzhiyun                 +------------------------+
197*4882a593Smuzhiyun                 |  FPGA Hardware Device  |
198*4882a593Smuzhiyun                 +------------------------+
199*4882a593Smuzhiyun
200*4882a593SmuzhiyunDFL framework in kernel provides common interfaces to create container device
201*4882a593Smuzhiyun(FPGA base region), discover feature devices and their private features from the
202*4882a593Smuzhiyungiven Device Feature Lists and create platform devices for feature devices
203*4882a593Smuzhiyun(e.g. FME, Port and AFU) with related resources under the container device. It
204*4882a593Smuzhiyunalso abstracts operations for the private features and exposes common ops to
205*4882a593Smuzhiyunfeature device drivers.
206*4882a593Smuzhiyun
207*4882a593SmuzhiyunThe FPGA DFL Device could be different hardwares, e.g. PCIe device, platform
208*4882a593Smuzhiyundevice and etc. Its driver module is always loaded first once the device is
209*4882a593Smuzhiyuncreated by the system. This driver plays an infrastructural role in the
210*4882a593Smuzhiyundriver architecture. It locates the DFLs in the device memory, handles them
211*4882a593Smuzhiyunand related resources to common interfaces from DFL framework for enumeration.
212*4882a593Smuzhiyun(Please refer to drivers/fpga/dfl.c for detailed enumeration APIs).
213*4882a593Smuzhiyun
214*4882a593SmuzhiyunThe FPGA Management Engine (FME) driver is a platform driver which is loaded
215*4882a593Smuzhiyunautomatically after FME platform device creation from the DFL device module. It
216*4882a593Smuzhiyunprovides the key features for FPGA management, including:
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun	a) Expose static FPGA region information, e.g. version and metadata.
219*4882a593Smuzhiyun	   Users can read related information via sysfs interfaces exposed
220*4882a593Smuzhiyun	   by FME driver.
221*4882a593Smuzhiyun
222*4882a593Smuzhiyun	b) Partial Reconfiguration. The FME driver creates FPGA manager, FPGA
223*4882a593Smuzhiyun	   bridges and FPGA regions during PR sub feature initialization. Once
224*4882a593Smuzhiyun	   it receives a DFL_FPGA_FME_PORT_PR ioctl from user, it invokes the
225*4882a593Smuzhiyun	   common interface function from FPGA Region to complete the partial
226*4882a593Smuzhiyun	   reconfiguration of the PR bitstream to the given port.
227*4882a593Smuzhiyun
228*4882a593SmuzhiyunSimilar to the FME driver, the FPGA Accelerated Function Unit (AFU) driver is
229*4882a593Smuzhiyunprobed once the AFU platform device is created. The main function of this module
230*4882a593Smuzhiyunis to provide an interface for userspace applications to access the individual
231*4882a593Smuzhiyunaccelerators, including basic reset control on port, AFU MMIO region export, dma
232*4882a593Smuzhiyunbuffer mapping service functions.
233*4882a593Smuzhiyun
234*4882a593SmuzhiyunAfter feature platform devices creation, matched platform drivers will be loaded
235*4882a593Smuzhiyunautomatically to handle different functionalities. Please refer to next sections
236*4882a593Smuzhiyunfor detailed information on functional units which have been already implemented
237*4882a593Smuzhiyununder this DFL framework.
238*4882a593Smuzhiyun
239*4882a593Smuzhiyun
240*4882a593SmuzhiyunPartial Reconfiguration
241*4882a593Smuzhiyun=======================
242*4882a593SmuzhiyunAs mentioned above, accelerators can be reconfigured through partial
243*4882a593Smuzhiyunreconfiguration of a PR bitstream file. The PR bitstream file must have been
244*4882a593Smuzhiyungenerated for the exact static FPGA region and targeted reconfigurable region
245*4882a593Smuzhiyun(port) of the FPGA, otherwise, the reconfiguration operation will fail and
246*4882a593Smuzhiyunpossibly cause system instability. This compatibility can be checked by
247*4882a593Smuzhiyuncomparing the compatibility ID noted in the header of PR bitstream file against
248*4882a593Smuzhiyunthe compat_id exposed by the target FPGA region. This check is usually done by
249*4882a593Smuzhiyunuserspace before calling the reconfiguration IOCTL.
250*4882a593Smuzhiyun
251*4882a593Smuzhiyun
252*4882a593SmuzhiyunFPGA virtualization - PCIe SRIOV
253*4882a593Smuzhiyun================================
254*4882a593SmuzhiyunThis section describes the virtualization support on DFL based FPGA device to
255*4882a593Smuzhiyunenable accessing an accelerator from applications running in a virtual machine
256*4882a593Smuzhiyun(VM). This section only describes the PCIe based FPGA device with SRIOV support.
257*4882a593Smuzhiyun
258*4882a593SmuzhiyunFeatures supported by the particular FPGA device are exposed through Device
259*4882a593SmuzhiyunFeature Lists, as illustrated below:
260*4882a593Smuzhiyun
261*4882a593Smuzhiyun::
262*4882a593Smuzhiyun
263*4882a593Smuzhiyun    +-------------------------------+  +-------------+
264*4882a593Smuzhiyun    |              PF               |  |     VF      |
265*4882a593Smuzhiyun    +-------------------------------+  +-------------+
266*4882a593Smuzhiyun        ^            ^         ^              ^
267*4882a593Smuzhiyun        |            |         |              |
268*4882a593Smuzhiyun  +-----|------------|---------|--------------|-------+
269*4882a593Smuzhiyun  |     |            |         |              |       |
270*4882a593Smuzhiyun  |  +-----+     +-------+ +-------+      +-------+   |
271*4882a593Smuzhiyun  |  | FME |     | Port0 | | Port1 |      | Port2 |   |
272*4882a593Smuzhiyun  |  +-----+     +-------+ +-------+      +-------+   |
273*4882a593Smuzhiyun  |                  ^         ^              ^       |
274*4882a593Smuzhiyun  |                  |         |              |       |
275*4882a593Smuzhiyun  |              +-------+ +------+       +-------+   |
276*4882a593Smuzhiyun  |              |  AFU  | |  AFU |       |  AFU  |   |
277*4882a593Smuzhiyun  |              +-------+ +------+       +-------+   |
278*4882a593Smuzhiyun  |                                                   |
279*4882a593Smuzhiyun  |            DFL based FPGA PCIe Device             |
280*4882a593Smuzhiyun  +---------------------------------------------------+
281*4882a593Smuzhiyun
282*4882a593SmuzhiyunFME is always accessed through the physical function (PF).
283*4882a593Smuzhiyun
284*4882a593SmuzhiyunPorts (and related AFUs) are accessed via PF by default, but could be exposed
285*4882a593Smuzhiyunthrough virtual function (VF) devices via PCIe SRIOV. Each VF only contains
286*4882a593Smuzhiyun1 Port and 1 AFU for isolation. Users could assign individual VFs (accelerators)
287*4882a593Smuzhiyuncreated via PCIe SRIOV interface, to virtual machines.
288*4882a593Smuzhiyun
289*4882a593SmuzhiyunThe driver organization in virtualization case is illustrated below:
290*4882a593Smuzhiyun::
291*4882a593Smuzhiyun
292*4882a593Smuzhiyun    +-------++------++------+             |
293*4882a593Smuzhiyun    | FME   || FME  || FME  |             |
294*4882a593Smuzhiyun    | FPGA  || FPGA || FPGA |             |
295*4882a593Smuzhiyun    |Manager||Bridge||Region|             |
296*4882a593Smuzhiyun    +-------++------++------+             |
297*4882a593Smuzhiyun    +-----------------------+  +--------+ |             +--------+
298*4882a593Smuzhiyun    |          FME          |  |  AFU   | |             |  AFU   |
299*4882a593Smuzhiyun    |         Module        |  | Module | |             | Module |
300*4882a593Smuzhiyun    +-----------------------+  +--------+ |             +--------+
301*4882a593Smuzhiyun          +-----------------------+       |       +-----------------------+
302*4882a593Smuzhiyun          | FPGA Container Device |       |       | FPGA Container Device |
303*4882a593Smuzhiyun          |  (FPGA Base Region)   |       |       |  (FPGA Base Region)   |
304*4882a593Smuzhiyun          +-----------------------+       |       +-----------------------+
305*4882a593Smuzhiyun            +------------------+          |         +------------------+
306*4882a593Smuzhiyun            | FPGA PCIE Module |          | Virtual | FPGA PCIE Module |
307*4882a593Smuzhiyun            +------------------+   Host   | Machine +------------------+
308*4882a593Smuzhiyun   -------------------------------------- | ------------------------------
309*4882a593Smuzhiyun             +---------------+            |          +---------------+
310*4882a593Smuzhiyun             | PCI PF Device |            |          | PCI VF Device |
311*4882a593Smuzhiyun             +---------------+            |          +---------------+
312*4882a593Smuzhiyun
313*4882a593SmuzhiyunFPGA PCIe device driver is always loaded first once a FPGA PCIe PF or VF device
314*4882a593Smuzhiyunis detected. It:
315*4882a593Smuzhiyun
316*4882a593Smuzhiyun* Finishes enumeration on both FPGA PCIe PF and VF device using common
317*4882a593Smuzhiyun  interfaces from DFL framework.
318*4882a593Smuzhiyun* Supports SRIOV.
319*4882a593Smuzhiyun
320*4882a593SmuzhiyunThe FME device driver plays a management role in this driver architecture, it
321*4882a593Smuzhiyunprovides ioctls to release Port from PF and assign Port to PF. After release
322*4882a593Smuzhiyuna port from PF, then it's safe to expose this port through a VF via PCIe SRIOV
323*4882a593Smuzhiyunsysfs interface.
324*4882a593Smuzhiyun
325*4882a593SmuzhiyunTo enable accessing an accelerator from applications running in a VM, the
326*4882a593Smuzhiyunrespective AFU's port needs to be assigned to a VF using the following steps:
327*4882a593Smuzhiyun
328*4882a593Smuzhiyun#. The PF owns all AFU ports by default. Any port that needs to be
329*4882a593Smuzhiyun   reassigned to a VF must first be released through the
330*4882a593Smuzhiyun   DFL_FPGA_FME_PORT_RELEASE ioctl on the FME device.
331*4882a593Smuzhiyun
332*4882a593Smuzhiyun#. Once N ports are released from PF, then user can use command below
333*4882a593Smuzhiyun   to enable SRIOV and VFs. Each VF owns only one Port with AFU.
334*4882a593Smuzhiyun
335*4882a593Smuzhiyun   ::
336*4882a593Smuzhiyun
337*4882a593Smuzhiyun      echo N > $PCI_DEVICE_PATH/sriov_numvfs
338*4882a593Smuzhiyun
339*4882a593Smuzhiyun#. Pass through the VFs to VMs
340*4882a593Smuzhiyun
341*4882a593Smuzhiyun#. The AFU under VF is accessible from applications in VM (using the
342*4882a593Smuzhiyun   same driver inside the VF).
343*4882a593Smuzhiyun
344*4882a593SmuzhiyunNote that an FME can't be assigned to a VF, thus PR and other management
345*4882a593Smuzhiyunfunctions are only available via the PF.
346*4882a593Smuzhiyun
347*4882a593SmuzhiyunDevice enumeration
348*4882a593Smuzhiyun==================
349*4882a593SmuzhiyunThis section introduces how applications enumerate the fpga device from
350*4882a593Smuzhiyunthe sysfs hierarchy under /sys/class/fpga_region.
351*4882a593Smuzhiyun
352*4882a593SmuzhiyunIn the example below, two DFL based FPGA devices are installed in the host. Each
353*4882a593Smuzhiyunfpga device has one FME and two ports (AFUs).
354*4882a593Smuzhiyun
355*4882a593SmuzhiyunFPGA regions are created under /sys/class/fpga_region/::
356*4882a593Smuzhiyun
357*4882a593Smuzhiyun	/sys/class/fpga_region/region0
358*4882a593Smuzhiyun	/sys/class/fpga_region/region1
359*4882a593Smuzhiyun	/sys/class/fpga_region/region2
360*4882a593Smuzhiyun	...
361*4882a593Smuzhiyun
362*4882a593SmuzhiyunApplication needs to search each regionX folder, if feature device is found,
363*4882a593Smuzhiyun(e.g. "dfl-port.n" or "dfl-fme.m" is found), then it's the base
364*4882a593Smuzhiyunfpga region which represents the FPGA device.
365*4882a593Smuzhiyun
366*4882a593SmuzhiyunEach base region has one FME and two ports (AFUs) as child devices::
367*4882a593Smuzhiyun
368*4882a593Smuzhiyun	/sys/class/fpga_region/region0/dfl-fme.0
369*4882a593Smuzhiyun	/sys/class/fpga_region/region0/dfl-port.0
370*4882a593Smuzhiyun	/sys/class/fpga_region/region0/dfl-port.1
371*4882a593Smuzhiyun	...
372*4882a593Smuzhiyun
373*4882a593Smuzhiyun	/sys/class/fpga_region/region3/dfl-fme.1
374*4882a593Smuzhiyun	/sys/class/fpga_region/region3/dfl-port.2
375*4882a593Smuzhiyun	/sys/class/fpga_region/region3/dfl-port.3
376*4882a593Smuzhiyun	...
377*4882a593Smuzhiyun
378*4882a593SmuzhiyunIn general, the FME/AFU sysfs interfaces are named as follows::
379*4882a593Smuzhiyun
380*4882a593Smuzhiyun	/sys/class/fpga_region/<regionX>/<dfl-fme.n>/
381*4882a593Smuzhiyun	/sys/class/fpga_region/<regionX>/<dfl-port.m>/
382*4882a593Smuzhiyun
383*4882a593Smuzhiyunwith 'n' consecutively numbering all FMEs and 'm' consecutively numbering all
384*4882a593Smuzhiyunports.
385*4882a593Smuzhiyun
386*4882a593SmuzhiyunThe device nodes used for ioctl() or mmap() can be referenced through::
387*4882a593Smuzhiyun
388*4882a593Smuzhiyun	/sys/class/fpga_region/<regionX>/<dfl-fme.n>/dev
389*4882a593Smuzhiyun	/sys/class/fpga_region/<regionX>/<dfl-port.n>/dev
390*4882a593Smuzhiyun
391*4882a593Smuzhiyun
392*4882a593SmuzhiyunPerformance Counters
393*4882a593Smuzhiyun====================
394*4882a593SmuzhiyunPerformance reporting is one private feature implemented in FME. It could
395*4882a593Smuzhiyunsupports several independent, system-wide, device counter sets in hardware to
396*4882a593Smuzhiyunmonitor and count for performance events, including "basic", "cache", "fabric",
397*4882a593Smuzhiyun"vtd" and "vtd_sip" counters. Users could use standard perf tool to monitor
398*4882a593SmuzhiyunFPGA cache hit/miss rate, transaction number, interface clock counter of AFU
399*4882a593Smuzhiyunand other FPGA performance events.
400*4882a593Smuzhiyun
401*4882a593SmuzhiyunDifferent FPGA devices may have different counter sets, depending on hardware
402*4882a593Smuzhiyunimplementation. E.g., some discrete FPGA cards don't have any cache. User could
403*4882a593Smuzhiyunuse "perf list" to check which perf events are supported by target hardware.
404*4882a593Smuzhiyun
405*4882a593SmuzhiyunIn order to allow user to use standard perf API to access these performance
406*4882a593Smuzhiyuncounters, driver creates a perf PMU, and related sysfs interfaces in
407*4882a593Smuzhiyun/sys/bus/event_source/devices/dfl_fme* to describe available perf events and
408*4882a593Smuzhiyunconfiguration options.
409*4882a593Smuzhiyun
410*4882a593SmuzhiyunThe "format" directory describes the format of the config field of struct
411*4882a593Smuzhiyunperf_event_attr. There are 3 bitfields for config: "evtype" defines which type
412*4882a593Smuzhiyunthe perf event belongs to; "event" is the identity of the event within its
413*4882a593Smuzhiyuncategory; "portid" is introduced to decide counters set to monitor on FPGA
414*4882a593Smuzhiyunoverall data or a specific port.
415*4882a593Smuzhiyun
416*4882a593SmuzhiyunThe "events" directory describes the configuration templates for all available
417*4882a593Smuzhiyunevents which can be used with perf tool directly. For example, fab_mmio_read
418*4882a593Smuzhiyunhas the configuration "event=0x06,evtype=0x02,portid=0xff", which shows this
419*4882a593Smuzhiyunevent belongs to fabric type (0x02), the local event id is 0x06 and it is for
420*4882a593Smuzhiyunoverall monitoring (portid=0xff).
421*4882a593Smuzhiyun
422*4882a593SmuzhiyunExample usage of perf::
423*4882a593Smuzhiyun
424*4882a593Smuzhiyun  $# perf list |grep dfl_fme
425*4882a593Smuzhiyun
426*4882a593Smuzhiyun  dfl_fme0/fab_mmio_read/                              [Kernel PMU event]
427*4882a593Smuzhiyun  <...>
428*4882a593Smuzhiyun  dfl_fme0/fab_port_mmio_read,portid=?/                [Kernel PMU event]
429*4882a593Smuzhiyun  <...>
430*4882a593Smuzhiyun
431*4882a593Smuzhiyun  $# perf stat -a -e dfl_fme0/fab_mmio_read/ <command>
432*4882a593Smuzhiyun  or
433*4882a593Smuzhiyun  $# perf stat -a -e dfl_fme0/event=0x06,evtype=0x02,portid=0xff/ <command>
434*4882a593Smuzhiyun  or
435*4882a593Smuzhiyun  $# perf stat -a -e dfl_fme0/config=0xff2006/ <command>
436*4882a593Smuzhiyun
437*4882a593SmuzhiyunAnother example, fab_port_mmio_read monitors mmio read of a specific port. So
438*4882a593Smuzhiyunits configuration template is "event=0x06,evtype=0x01,portid=?". The portid
439*4882a593Smuzhiyunshould be explicitly set.
440*4882a593Smuzhiyun
441*4882a593SmuzhiyunIts usage of perf::
442*4882a593Smuzhiyun
443*4882a593Smuzhiyun  $# perf stat -a -e dfl_fme0/fab_port_mmio_read,portid=0x0/ <command>
444*4882a593Smuzhiyun  or
445*4882a593Smuzhiyun  $# perf stat -a -e dfl_fme0/event=0x06,evtype=0x02,portid=0x0/ <command>
446*4882a593Smuzhiyun  or
447*4882a593Smuzhiyun  $# perf stat -a -e dfl_fme0/config=0x2006/ <command>
448*4882a593Smuzhiyun
449*4882a593SmuzhiyunPlease note for fabric counters, overall perf events (fab_*) and port perf
450*4882a593Smuzhiyunevents (fab_port_*) actually share one set of counters in hardware, so it can't
451*4882a593Smuzhiyunmonitor both at the same time. If this set of counters is configured to monitor
452*4882a593Smuzhiyunoverall data, then per port perf data is not supported. See below example::
453*4882a593Smuzhiyun
454*4882a593Smuzhiyun  $# perf stat -e dfl_fme0/fab_mmio_read/,dfl_fme0/fab_port_mmio_write,\
455*4882a593Smuzhiyun                                                    portid=0/ sleep 1
456*4882a593Smuzhiyun
457*4882a593Smuzhiyun  Performance counter stats for 'system wide':
458*4882a593Smuzhiyun
459*4882a593Smuzhiyun                 3      dfl_fme0/fab_mmio_read/
460*4882a593Smuzhiyun   <not supported>      dfl_fme0/fab_port_mmio_write,portid=0x0/
461*4882a593Smuzhiyun
462*4882a593Smuzhiyun       1.001750904 seconds time elapsed
463*4882a593Smuzhiyun
464*4882a593SmuzhiyunThe driver also provides a "cpumask" sysfs attribute, which contains only one
465*4882a593SmuzhiyunCPU id used to access these perf events. Counting on multiple CPU is not allowed
466*4882a593Smuzhiyunsince they are system-wide counters on FPGA device.
467*4882a593Smuzhiyun
468*4882a593SmuzhiyunThe current driver does not support sampling. So "perf record" is unsupported.
469*4882a593Smuzhiyun
470*4882a593Smuzhiyun
471*4882a593SmuzhiyunInterrupt support
472*4882a593Smuzhiyun=================
473*4882a593SmuzhiyunSome FME and AFU private features are able to generate interrupts. As mentioned
474*4882a593Smuzhiyunabove, users could call ioctl (DFL_FPGA_*_GET_IRQ_NUM) to know whether or how
475*4882a593Smuzhiyunmany interrupts are supported for this private feature. Drivers also implement
476*4882a593Smuzhiyunan eventfd based interrupt handling mechanism for users to get notified when
477*4882a593Smuzhiyuninterrupt happens. Users could set eventfds to driver via
478*4882a593Smuzhiyunioctl (DFL_FPGA_*_SET_IRQ), and then poll/select on these eventfds waiting for
479*4882a593Smuzhiyunnotification.
480*4882a593SmuzhiyunIn Current DFL, 3 sub features (Port error, FME global error and AFU interrupt)
481*4882a593Smuzhiyunsupport interrupts.
482*4882a593Smuzhiyun
483*4882a593Smuzhiyun
484*4882a593SmuzhiyunAdd new FIUs support
485*4882a593Smuzhiyun====================
486*4882a593SmuzhiyunIt's possible that developers made some new function blocks (FIUs) under this
487*4882a593SmuzhiyunDFL framework, then new platform device driver needs to be developed for the
488*4882a593Smuzhiyunnew feature dev (FIU) following the same way as existing feature dev drivers
489*4882a593Smuzhiyun(e.g. FME and Port/AFU platform device driver). Besides that, it requires
490*4882a593Smuzhiyunmodification on DFL framework enumeration code too, for new FIU type detection
491*4882a593Smuzhiyunand related platform devices creation.
492*4882a593Smuzhiyun
493*4882a593Smuzhiyun
494*4882a593SmuzhiyunAdd new private features support
495*4882a593Smuzhiyun================================
496*4882a593SmuzhiyunIn some cases, we may need to add some new private features to existing FIUs
497*4882a593Smuzhiyun(e.g. FME or Port). Developers don't need to touch enumeration code in DFL
498*4882a593Smuzhiyunframework, as each private feature will be parsed automatically and related
499*4882a593Smuzhiyunmmio resources can be found under FIU platform device created by DFL framework.
500*4882a593SmuzhiyunDeveloper only needs to provide a sub feature driver with matched feature id.
501*4882a593SmuzhiyunFME Partial Reconfiguration Sub Feature driver (see drivers/fpga/dfl-fme-pr.c)
502*4882a593Smuzhiyuncould be a reference.
503*4882a593Smuzhiyun
504*4882a593Smuzhiyun
505*4882a593SmuzhiyunOpen discussion
506*4882a593Smuzhiyun===============
507*4882a593SmuzhiyunFME driver exports one ioctl (DFL_FPGA_FME_PORT_PR) for partial reconfiguration
508*4882a593Smuzhiyunto user now. In the future, if unified user interfaces for reconfiguration are
509*4882a593Smuzhiyunadded, FME driver should switch to them from ioctl interface.
510