FPGA Device Feature List (DFL) Device Drivers
Subsystems (4)
v6 cover FPGA Device Feature List (DFL) Device Drivers
Hi All,
Here is v6 patch-series adding drivers for FPGA DFL devices.
This patch series provides a common framework to support FPGA Device Feature List (DFL), and also feature dev drivers under this DFL framework to provide interfaces for userspace applications to configure, enumerate, open, and access FPGA accelerators on DFL based FPGA device and enables system level management functions such as FPGA partial reconfiguration, power management and virtualization.
This patch series only adds the basic functions for FPGA accelerators and partial reconfiguration. Patches for more functions, e.g power management and virtualization, will be submitted after this series gets reviewed.
Note this patch series is only verified on DFL based Intel(R) FPGA PCIe devices (e.g Intel Server Platform with In-package FPGA and Intel FPGA PCIe Acceleration Cards).
Patch 1: add a document for FPGA DFL framework driver overview, including Device Feature List (DFL) introduction, the HW architecture, driver organization, device enumeration and opens.
Patch 2: add region_id for fpga_image_info data structure, which allows driver to pass region id information to fpga-mgr for FPGA reconfiguration function. (Used by Patch 17)
Patch 3: add a 'status' sysfs interface to fpga-mgr class, it reflects the status of the fpga-mgr including reconfiguration errors. (Used by Patch 18)
Patch 4-5: add compat_id support in fpga manager and region, this compat id is used for compatibility check before further actions (e.g partial reconfiguration). (Used by Patch 19 and 22)
Patch 6-11: add FPGA device feature list support, it provides common enumeration interfaces which creates container device (FPGA base region) and all feature devices by walking through all the 'Device Feature Lists' provided low level drivers. A global list is added to DFL framework to manage port ops from different ports.
Patch 12-13: implement FPGA PCIe device driver. It locates all 'Device Feature Lists' in PCIe device memory and invokes common interfaces from above device feature list framework to finish the enumeration.
Patch 14-17: implement FPGA Management Engine (FME) driver. It's a platform driver matching with the FME platform device created by above device feature list framework during enumeration. Sysfs and device file ioctls are exposed as user interfaces to allow partial reconfiguration to Accelerated Function Units (AFUs) from user space applications.
Patch 18-22: implement FPGA manager/bridge/region platform drivers for Intel FPGA Management Engine (FME). These platform drivers match with platform devices created by above FME driver, they use the generic fpga-mgr/bridge/region class infrastructure to implement FPGA partial reconfiguration function.
Patch 23-28: implement FPGA Accelerated Function Unit (AFU) driver. It's a platform driver matching with AFU platform device created by above device feature list framework during enumeration. It provides user interfaces to expose the AFU MMIO region, map/unmap dma buffer, and control the port which AFU connects to.
Patch 29: add a entry in MAINTAINERS for this FPGA DFL drivers patchset.
Changes from v5:
- Improve functions/APIs naming per suggestion from Alan Tull.
- Improve DFL framework code and comments to simply the work for adding a new feature device support.
- Correct the time in copyright, and fix other comments from Alan Tull.
- Add a entry in MAINTAINERS for this FPGA DFL drivers patchset.
Changes from v4:
- Update the dfl.txt documentation, remove descriptions for the APIs and features which are not implemented in this patch series.
- Add DFL_ / dfl_ prefix for APIs and data structure, to avoid directly using fpga_xxx as definition.
- Use "static region" and "PR bistream" instead of "blue bitstream" and "green bistream" in description to avoid misunderstanding.
- Fix building issues caused by BIT() on 64bit register definition and missing correct header file for readq and writeq.
- Remove port specific code in DFL framework, and introduce port ops support to resolve the dependency issue between FME driver module and Port driver module. (more details in Patch 8).
- Add compat id to fpga manager, as in case some hardware implements the compat id in fpga manager's register, not register belongs to fpga region, and it's value is shared by all related fpga regions.
- Pass mapped ioaddr to fme manager platform device from dfl-fme-pr via pdata.
- Fix other comments from Alan and Moritze, including description improvement, coding style issue and etc.
Changes from v3:
- Fix SPDX license issue.
- Rename documentation to dfl.txt, add introduction for Device Feature List (DFL) and re-organize the content.
- Rename to FPGA Device Feature List (DFL) drivers from Intel FPGA device drivers for better reuse purposes. Unified driver and files to dfl-*.*
- Remove static feature_info table from common enumeration code, and switch to use feature id for sub feature driver matching.
- Remove next_afu register checking for AFU from common enumeration code.
- Remove interface_id sysfs for dfl-fme-mgr and use per fpga-region compat_id instead. (new patch 13, 15, 19).
- Add more comments for driver data structures and functions.
- Fix typos, issues in debug message/commit message and other places.
Changes from v2:
- Split common enumeration code from pcie driver to a separated module which for device feature list support.
- Drop fpga-dev class and switch to use fpga base region as container.
- Update the intel-fpga.txt documentation for new driver organization.
- Rename feature device drivers for future code reuse.
- Rebase code due to fpga APIs changes
- replace bitfields with marco and shift.
- fix typos, checkpatch issue and other comments.
Changes from v1:
- Use GPLv2 license instead of Dual BSD/GPL.
- Move the code to drivers/fpga folder.
- Update the intel-fpga.txt documentation for new driver organization.
- Add documentation for new sysfs interfaces.
- Switch to use common fpga-region interface for partial reconfiguration (PR) function in FME. It creates fpga-region/fpga-mgr/fpga-bridge platform devices and leave the implementation to their platform drivers.
- Add platform drivers for FME fpga-mgr/bridge/region platform devices.
- Fix kbuild warnings, typos and other comments.
This patch series depends on the below patchset from Alan Tull. [PATCH 00/14] fpga api changes and kernel-doc fixup[1]
[1]https://marc.info/?l=linux-kernel&m=152651462215380&w=2
Kang Luwei (3):
fpga: dfl: add FPGA Management Engine driver basic framework
fpga: dfl: fme: add header sub feature support
fpga: dfl: fme: add partial reconfiguration sub feature support
Wu Hao (23):
docs: fpga: add a document for FPGA Device Feature List (DFL)
Framework Overview
fpga: mgr: add region_id to fpga_image_info
fpga: mgr: add status for fpga-manager
fpga: mgr: add compat_id support
fpga: region: add compat_id support
fpga: add device feature list support
fpga: dfl: add chardev support for feature devices
fpga: dfl: add dfl_fpga_cdev_find_port
fpga: dfl: add dfl_fpga_port_ops support.
fpga: dfl: add dfl_fpga_check_port_id function.
fpga: dfl-pci: add enumeration for feature devices
fpga: dfl: fme: add DFL_FPGA_GET_API_VERSION/CHECK_EXTENSION ioctls
support
fpga: dfl: add fpga manager platform driver for FME
fpga: dfl: fme-mgr: add compat_id support
fpga: dfl: add fpga bridge platform driver for FME
fpga: dfl: add fpga region platform driver for FME
fpga: dfl: fme-region: add support for compat_id
fpga: dfl: add FPGA Accelerated Function Unit driver basic framework
fpga: dfl: afu: add port ops support
fpga: dfl: afu: add header sub feature support
fpga: dfl: afu: add DFL_FPGA_GET_API_VERSION/CHECK_EXTENSION ioctls
support
fpga: dfl: afu: add DFL_FPGA_PORT_DMA_MAP/UNMAP ioctls support
MAINTAINERS: add entry for FPGA DFL drivers
Xiao Guangrong (2):
fpga: dfl: add feature device infrastructure
fpga: dfl: afu: add afu sub feature support
Zhang Yi (1):
fpga: add FPGA DFL PCIe device driver
Documentation/ABI/testing/sysfs-class-fpga-manager | 24 + Documentation/ABI/testing/sysfs-class-fpga-region | 9 + Documentation/ABI/testing/sysfs-platform-dfl-fme | 23 + Documentation/ABI/testing/sysfs-platform-dfl-port | 16 + Documentation/fpga/dfl.txt | 285 ++++++ Documentation/ioctl/ioctl-number.txt | 1 + MAINTAINERS | 8 + drivers/fpga/Kconfig | 68 ++ drivers/fpga/Makefile | 14 + drivers/fpga/dfl-afu-dma-region.c | 463 +++++++++ drivers/fpga/dfl-afu-main.c | 636 ++++++++++++ drivers/fpga/dfl-afu-region.c | 166 ++++ drivers/fpga/dfl-afu.h | 100 ++ drivers/fpga/dfl-fme-br.c | 114 +++ drivers/fpga/dfl-fme-main.c | 279 ++++++ drivers/fpga/dfl-fme-mgr.c | 349 +++++++ drivers/fpga/dfl-fme-pr.c | 474 +++++++++ drivers/fpga/dfl-fme-pr.h | 84 ++ drivers/fpga/dfl-fme-region.c | 89 ++ drivers/fpga/dfl-fme.h | 38 + drivers/fpga/dfl-pci.c | 310 ++++++ drivers/fpga/dfl.c | 1042 ++++++++++++++++++++ drivers/fpga/dfl.h | 410 ++++++++ drivers/fpga/fpga-mgr.c | 28 + drivers/fpga/fpga-region.c | 22 + include/linux/fpga/fpga-mgr.h | 24 + include/linux/fpga/fpga-region.h | 2 + include/uapi/linux/fpga-dfl.h | 178 ++++ 28 files changed, 5256 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-fpga-region create mode 100644 Documentation/ABI/testing/sysfs-platform-dfl-fme create mode 100644 Documentation/ABI/testing/sysfs-platform-dfl-port create mode 100644 Documentation/fpga/dfl.txt create mode 100644 drivers/fpga/dfl-afu-dma-region.c create mode 100644 drivers/fpga/dfl-afu-main.c create mode 100644 drivers/fpga/dfl-afu-region.c create mode 100644 drivers/fpga/dfl-afu.h create mode 100644 drivers/fpga/dfl-fme-br.c create mode 100644 drivers/fpga/dfl-fme-main.c create mode 100644 drivers/fpga/dfl-fme-mgr.c create mode 100644 drivers/fpga/dfl-fme-pr.c create mode 100644 drivers/fpga/dfl-fme-pr.h create mode 100644 drivers/fpga/dfl-fme-region.c create mode 100644 drivers/fpga/dfl-fme.h create mode 100644 drivers/fpga/dfl-pci.c create mode 100644 drivers/fpga/dfl.c create mode 100644 drivers/fpga/dfl.h create mode 100644 include/uapi/linux/fpga-dfl.h
Signature · 1 line
1.8.3.1
PATCH v6 1/29 docs: fpga: add a document for FPGA Device Feature List (DFL) Framework Overview
Add a document for FPGA Device Feature List (DFL) Framework Overview.
---
v2: added FME fpga-mgr/bridge/region platform driver to driver organization.
updated open discussion per current implementation.
fixed some typos.
v3: use FPGA base region as container device instead of fpga-dev class.
split common enumeration code from pcie driver to functions exposed by device feature list framework.
update FME performance reporting which supports both integrated (iperf/) and discrete (dperf/) FPGA solutions.
v4: rename this doc to Device Feature List (DFL) Framework Overview (dfl.txt)
add Device Feature List introduction and re-organize the content.
add description for port reset, bitstream_id/metadata and etc.
v5: remove introduction of the APIs/features which aren't covered in this patchset.
replace "blue/green bitstream" terminology with "static region" and "PR bitstream". add a "DFL_" prefix to IOCTL APIs introduced by DFL framework.
s/FPGA Bus Device Module/FPGA DFL Device Module/
fix typos, improve descriptions per comments from Alan Tull against v4.
v6: add Acked-by from Alan.
--- Documentation/fpga/dfl.txt | 285 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 285 insertions(+) create mode 100644 Documentation/fpga/dfl.txt
Documentation/fpga/dfl.txt new file +285 -0
@@ -0,0 +1,285 @@ +=============================================================================== + FPGA Device Feature List (DFL) Framework Overview +------------------------------------------------------------------------------- + Enno Luebbers <[email protected]> + Xiao Guangrong <[email protected]> + Wu Hao <[email protected]> + +The Device Feature List (DFL) FPGA framework (and drivers according to this +this framework) hides the very details of low layer hardwares and provides +unified interfaces to userspace. Applications could use these interfaces to +configure, enumerate, open and access FPGA accelerators on platforms which +implemented the DFL in the device memory. Besides this, the DFL framework +enables system level management functions such as FPGA reconfiguration. + + +Device Feature List (DFL) Overview +================================== +Device Feature List (DFL) defines a linked list of feature headers within the +device MMIO space to provide an extensible way of adding features. Software can +walk through these predefined data structures to enumerate FPGA features: +FPGA Interface Unit (FIU), Accelerated Function Unit (AFU) and Private Features, +as illustrated below: + + Header Header Header Header + +----------+ +-->+----------+ +-->+----------+ +-->+----------+ + | Type | | | Type | | | Type | | | Type | + | FIU | | | Private | | | Private | | | Private | + +----------+ | | Feature | | | Feature | | | Feature | + | Next_DFH |--+ +----------+ | +----------+ | +----------+ + +----------+ | Next_DFH |--+ | Next_DFH |--+ | Next_DFH |--> NULL + | ID | +----------+ +----------+ +----------+ + +----------+ | ID | | ID | | ID | + | Next_AFU |--+ +----------+ +----------+ +----------+ + +----------+ | | Feature | | Feature | | Feature | + | Header | | | Register | | Register | | Register | + | Register | | | Set | | Set | | Set | + | Set | | +----------+ +----------+ +----------+ + +----------+ | Header + +-->+----------+ + | Type | + | AFU | + +----------+ + | Next_DFH |--> NULL + +----------+ + | GUID | + +----------+ + | Header | + | Register | + | Set | + +----------+ + +FPGA Interface Unit (FIU) represents a standalone functional unit for the +interface to FPGA, e.g the FPGA Management Engine (FME) and Port (more +descriptions on FME and Port in later sections). + +Accelerated Function Unit (AFU) represents a FPGA programmable region, and +always connects to a FIU (e.g a Port) as its child as illustrated above. + +Private Features represent sub features of the FIU and AFU. They could be +various function blocks with different IDs, but all private features which +belong to the same FIU or AFU, must be linked to one list via the Next Device +Feature Header (Next_DFH) pointer. + +Each FIU, AFU and Private Feature could implement its own functional registers. +The functional register set for FIU and AFU, is named as Header Register Set, +e.g FME Header Register Set, and the one for Private Feature, is named as +Feature Register Set, e.g FME Partial Reconfiguration Feature Register Set. + +This Device Feature List provides a way of linking features together, it's +convenient for software to locate each feature by walking through this list, +and can be implemented in register regions of any FPGA device. + + +FIU - FME (FPGA Management Engine) +================================== +The FPGA Management Engine performs reconfiguration, and other infrastructure +functions. Each FPGA device only has one FME. + +User-space applications can acquire exclusive access to the FME using open(), +and release it using close(). + +The following functions are exposed through ioctls: + + Get driver API version (DFL_FPGA_GET_API_VERSION) + Check for extensions (DFL_FPGA_CHECK_EXTENSION) + Program bitstream (DFL_FPGA_FME_PORT_PR) + +More functions are exposed through sysfs +(/sys/class/fpga_region/regionX/dfl-fme.n/): + + Read bitstream ID (bitstream_id) + bitstream_id indicates version of the static FPGA region. + + Read bitstream metadata (bitstream_metadata) + bitstream_metadata includes detailed information of static FPGA region, + e.g synthesis date and seed. + + Read number of ports (ports_num) + one FPGA device may have more than 1 port, this sysfs interface indicates + how many ports the FPGA device has. + + +FIU - PORT +========== +A port represents the interface between the static FPGA fabric and a partially +reconfigurable region containing an AFU. It controls the communication from SW +to the accelerator and exposes features such as reset and debug. Each FPGA +device may have more than 1 port, but always 1 AFU per port. + + +AFU +=== +An AFU is attached to a port FIU and exposes a fixed length MMIO region to be +used for accelerator-specific control registers. + +User-space applications can acquire exclusive access to an AFU attached to a +port by using open() on the port device node, and release it using close(). + +The following functions are exposed through ioctls: + + Get driver API version (DFL_FPGA_GET_API_VERSION) + Check for extensions (DFL_FPGA_CHECK_EXTENSION) + Get port info (DFL_FPGA_PORT_GET_INFO) + Get MMIO region info (DFL_FPGA_PORT_GET_REGION_INFO) + Map DMA buffer (DFL_FPGA_PORT_DMA_MAP) + Unmap DMA buffer (DFL_FPGA_PORT_DMA_UNMAP) + Reset AFU (*DFL_FPGA_PORT_RESET) + +*DFL_FPGA_PORT_RESET: reset the FPGA Port and its AFU. Userspace can do Port +reset at any time, e.g during DMA or Partial Reconfiguration. But it should +never cause any system level issue, only functional failure (e.g DMA or PR +operation failure) and be recoverable from the failure. + +User-space applications can also mmap() accelerator MMIO regions. + +More functions are exposed through sysfs: +(/sys/class/fpga_region/<regionX>/<dfl-port.m>/): + + Read Accelerator GUID (afu_id) + afu_id indicates which PR bitstream is programmed to this AFU. + + +DFL Framework Overview +====================== + + +----------+ +--------+ +--------+ +--------+ + | FME | | AFU | | AFU | | AFU | + | Module | | Module | | Module | | Module | + +----------+ +--------+ +--------+ +--------+ + +-----------------------+ + | FPGA Container Device | Device Feature List + | (FPGA Base Region) | Framework + +-----------------------+ +-------------------------------------------------------------------- + +----------------------------+ + | FPGA DFL Device Module | + | (e.g PCIE/Platform Device) | + +----------------------------+ + +------------------------+ + | FPGA Hardware Device | + +------------------------+ + +DFL framework in kernel provides common interfaces to create container device +(FPGA base region), discover feature devices and their private features from the +given Device Feature Lists, and create platform devices for feature devices +(e.g FME, Port and AFU) with related resources under the container device. It +also abstracts operations for the private features and exposes common ops to +feature device drivers. + +The FPGA DFL Device could be different hardwares, e.g PCIe device, platform +device and etc. Its driver module is always loaded first once the device is +created by the system. This driver plays an infrastructural role in the +driver architecture. It locates the DFLs in the device memory, handles them +and related resources to common interfaces from DFL framework for enumeration. +(Please refer to drivers/fpga/dfl.c for detailed enumeration APIs). + +The FPGA Management Engine (FME) driver is a platform driver which is loaded +automatically after FME platform device creation from the DFL device module. It +provides the key features for FPGA management, including: + + a) Expose static FPGA region information, e.g version and metadata. + Users can read related information via sysfs interfaces exposed + by FME driver. + + b) Partial Reconfiguration. The FME driver creates FPGA manager, FPGA + bridges and FPGA regions during PR sub feature initialization. Once + it receives a DFL_FPGA_FME_PORT_PR ioctl from user, it invokes the + common interface function from FPGA Region to complete the partial + reconfiguration of the PR bitstream to the given port. + +Similar to the FME driver, the FPGA Accelerated Function Unit (AFU) driver is +probed once the AFU platform device is created. The main function of this module +is to provide an interface for userspace applications to access the individual +accelerators, including basic reset control on port, AFU MMIO region export, dma +buffer mapping service functions. + +After feature platform devices creation, matched platform drivers will be loaded +automatically to handle different functionalities. Please refer to next sections +for detailed information on functional units which have been already implemented +under this DFL framework. + + +Partial Reconfiguration +======================= +As mentioned above, accelerators can be reconfigured through partial +reconfiguration of a PR bitstream file. The PR bitstream file must have been +generated for the exact static FPGA region and targeted reconfigurable region +(port) of the FPGA, otherwise, the reconfiguration operation will fail and +possibly cause system instability. This compatibility can be checked by +comparing the compatibility ID noted in the header of PR bitstream file against +the compat_id exposed by the target FPGA region. This check is usually done by +userspace before calling the reconfiguration IOCTL. + + +Device enumeration +================== +This section introduces how applications enumerate the fpga device from +the sysfs hierarchy under /sys/class/fpga_region. + +In the example below, two DFL based FPGA devices are installed in the host. Each +fpga device has one FME and two ports (AFUs). + +FPGA regions are created under /sys/class/fpga_region/ + + /sys/class/fpga_region/region0 + /sys/class/fpga_region/region1 + /sys/class/fpga_region/region2 + ... + +Application needs to search each regionX folder, if feature device is found, +(e.g "dfl-port.n" or "dfl-fme.m" is found), then it's the base +fpga region which represents the FPGA device. + +Each base region has one FME and two ports (AFUs) as child devices: + + /sys/class/fpga_region/region0/dfl-fme.0 + /sys/class/fpga_region/region0/dfl-port.0 + /sys/class/fpga_region/region0/dfl-port.1 + ... + + /sys/class/fpga_region/region3/dfl-fme.1 + /sys/class/fpga_region/region3/dfl-port.2 + /sys/class/fpga_region/region3/dfl-port.3 + ... + +In general, the FME/AFU sysfs interfaces are named as follows: + + /sys/class/fpga_region/<regionX>/<dfl-fme.n>/ + /sys/class/fpga_region/<regionX>/<dfl-port.m>/ + +with 'n' consecutively numbering all FMEs and 'm' consecutively numbering all +ports. + +The device nodes used for ioctl() or mmap() can be referenced through: + + /sys/class/fpga_region/<regionX>/<dfl-fme.n>/dev + /sys/class/fpga_region/<regionX>/<dfl-port.n>/dev + + +Add new FIUs support +==================== +It's possible that developers made some new function blocks (FIUs) under this +DFL framework, then new platform device driver needs to be developed for the +new feature dev (FIU) following the same way as existing feature dev drivers +(e.g FME and Port/AFU platform device driver). Besides that, it requires +modification on DFL framework enumeration code too, for new FIU type detection +and related platform devices creation. + + +Add new private features support +================================ +In some cases, we may need to add some new private features to existing FIUs +(e.g FME or Port). Developers don't need to touch enumeration code in DFL +framework, as each private feature will be parsed automatically, and related +mmio resources can be found under FIU platform device created by DFL framework. +Developer only needs to provide a sub feature driver with matched feature id. +FME Partial Reconfiguration Sub Feature driver (see drivers/fpga/dfl-fme-pr.c) +could be a reference. + + +Open discussion +=============== +FME driver exports one ioctl (DFL_FPGA_FME_PORT_PR) for partial reconfiguration +to user now. In the future, if unified user interfaces for reconfiguration are +added, FME driver should switch to them from ioctl interface.
Signature · 1 line
1.8.3.1
PATCH v6 2/29 fpga: mgr: add region_id to fpga_image_info
In reply to Wu HaoThis patch adds region_id to fpga_image_info data structure, it allows driver to pass region id information to fpga-mgr via fpga_image_info for fpga reconfiguration function.
---
v3: add one line comment for region_id
v4: add Acked-by from Moritz and Alan.
--- include/linux/fpga/fpga-mgr.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/fpga/fpga-mgr.h +2 -0
@@ -77,6 +77,7 @@ enum fpga_mgr_states {* @sgt: scatter/gather table containing FPGA image * @buf: contiguous buffer containing FPGA image * @count: size of buf +* @region_id: id of target region * @dev: device that owns this * @overlay: Device Tree overlay */
@@ -89,6 +90,7 @@ struct fpga_image_info {struct sg_table *sgt;const char *buf;size_t count; +int region_id;struct device *dev;#ifdef CONFIG_OF struct device_node *overlay;
Signature · 1 line
1.8.3.1
PATCH v6 3/29 fpga: mgr: add status for fpga-manager
In reply to Wu HaoThis patch adds status sysfs interface for fpga manager, it's a read only interface which allows user to get fpga manager status, including full/partial reconfiguration error and other status information. It adds a status callback to fpga_manager_ops too, allows each fpga_manager driver to define its own method to collect latest status from hardware.
The following sysfs file is created:
* /sys/class/fpga_manager/<fpga>/status
Return status of fpga manager, including reconfiguration errors.
---
v3: add one line description for status
add status callback function to fpga_manager_ops
update fpga-mgr status if any failure or during initialization s/INCOMPATIBLE_BS_ERR/INCOMPATIBLE_IMAGE_ERR/
v4: simply code per suggestion from Alan.
add supported status strings (and descriptions) in sysfs document. remove unused error code (SECURE_LOAD_ERR).
v5: fix the wrong commit message and add Acked-by from Alan and Moritz.
v6: rebase.
--- Documentation/ABI/testing/sysfs-class-fpga-manager | 24 +++++++++++++++++++ drivers/fpga/fpga-mgr.c | 28 ++++++++++++++++++++++ include/linux/fpga/fpga-mgr.h | 9 +++++++ 3 files changed, 61 insertions(+)
Documentation/ABI/testing/sysfs-class-fpga-manager +24 -0
@@ -35,3 +35,27 @@ Description: Read fpga manager state as a string. * write complete = Doing post programming steps * write complete error = Error while doing post programming * operating = FPGA is programmed and operating + +What: /sys/class/fpga_manager/<fpga>/status +Date: June 2018 +KernelVersion: 4.18 +Contact: Wu Hao <[email protected]> +Description: Read fpga manager status as a string. + If FPGA programming operation fails, it could be caused by crc + error or incompatible bitstream image. The intent of this + interface is to provide more detailed information for FPGA + programming errors to userspace. This is a list of strings for + the supported status. + + * reconfig operation error - invalid operations detected by + reconfiguration hardware. + e.g start reconfiguration + with errors not cleared + * reconfig CRC error - CRC error detected by + reconfiguration hardware. + * reconfig incompatible image - reconfiguration image is + incompatible with hardware + * reconfig IP protocol error - protocol errors detected by + reconfiguration hardware + * reconfig fifo overflow error - FIFO overflow detected by + reconfiguration hardware
drivers/fpga/fpga-mgr.c +28 -0
@@ -406,12 +406,40 @@ static ssize_t state_show(struct device *dev,return sprintf (buf,"%s\n" , state_str[mgr->state]); } +static ssize_t status_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct fpga_manager *mgr =to_fpga_manager (dev); +u64 status; +int len =0 ; + +if (!mgr->mops->status) +return -ENOENT ; + + status = mgr->mops->status (mgr); + +if (status &FPGA_MGR_STATUS_OPERATION_ERR ) + len +=sprintf (buf + len,"reconfig operation error\n" ); +if (status &FPGA_MGR_STATUS_CRC_ERR ) + len +=sprintf (buf + len,"reconfig CRC error\n" ); +if (status &FPGA_MGR_STATUS_INCOMPATIBLE_IMAGE_ERR ) + len +=sprintf (buf + len,"reconfig incompatible image\n" ); +if (status &FPGA_MGR_STATUS_IP_PROTOCOL_ERR ) + len +=sprintf (buf + len,"reconfig IP protocol error\n" ); +if (status &FPGA_MGR_STATUS_FIFO_OVERFLOW_ERR ) + len +=sprintf (buf + len,"reconfig fifo overflow error\n" ); + +return len; +} +static DEVICE_ATTR_RO (name);static DEVICE_ATTR_RO (state); +static DEVICE_ATTR_RO (status);static struct attribute *fpga_mgr_attrs[] = { &dev_attr_name.attr, &dev_attr_state.attr, + &dev_attr_status.attr,NULL , };ATTRIBUTE_GROUPS (fpga_mgr);
include/linux/fpga/fpga-mgr.h +9 -0
@@ -101,6 +101,7 @@ struct fpga_image_info {* struct fpga_manager_ops - ops for low level fpga manager drivers * @initial_header_size: Maximum number of bytes that should be passed into write_init * @state: returns an enum value of the FPGA's state +* @status: returns status of the FPGA, including reconfiguration error code * @write_init: prepare the FPGA to receive confuration data * @write: write count bytes of configuration data to the FPGA * @write_sg: write the scatter list of configuration data to the FPGA
@@ -115,6 +116,7 @@ struct fpga_image_info {struct fpga_manager_ops {size_t initial_header_size;enum fpga_mgr_states (*state)(struct fpga_manager *mgr); +u64 (*status)(struct fpga_manager *mgr);int (*write_init)(struct fpga_manager *mgr,struct fpga_image_info *info,const char *buf,size_t count);
@@ -126,6 +128,13 @@ struct fpga_manager_ops {const struct attribute_group **groups; }; +/* FPGA manager status: Partial/Full Reconfiguration errors */ +#define FPGA_MGR_STATUS_OPERATION_ERR BIT(0) +#define FPGA_MGR_STATUS_CRC_ERR BIT(1) +#define FPGA_MGR_STATUS_INCOMPATIBLE_IMAGE_ERR BIT(2) +#define FPGA_MGR_STATUS_IP_PROTOCOL_ERR BIT(3) +#define FPGA_MGR_STATUS_FIFO_OVERFLOW_ERR BIT(4) +/** * struct fpga_manager - fpga manager structure * @name: name of low level fpga manager
Signature · 1 line
1.8.3.1
PATCH v6 4/29 fpga: mgr: add compat_id support
In reply to Wu HaoThis patch introduces compat_id support to fpga manager, it adds a fpga_compat_id pointer to fpga manager data structure to allow fpga manager drivers to save the compatibility id. This compat_id could be used for compatibility checking before doing partial reconfiguration to associated fpga regions.
---
v6: add Acked-by from Alan.
--- include/linux/fpga/fpga-mgr.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
include/linux/fpga/fpga-mgr.h +13 -0
@@ -136,11 +136,23 @@ struct fpga_manager_ops {#define FPGA_MGR_STATUS_FIFO_OVERFLOW_ERR BIT(4)/** +* struct fpga_compat_id - id for compatibility check +* +* @id_h: high 64bit of the compat_id +* @id_l: low 64bit of the compat_id +*/ +struct fpga_compat_id { +u64 id_h; +u64 id_l; +}; + +/** * struct fpga_manager - fpga manager structure * @name: name of low level fpga manager * @dev: fpga manager device * @ref_mutex: only allows one reference to fpga manager * @state: state of fpga manager +* @compat_id: FPGA manager id for compatibility check. * @mops: pointer to struct of fpga manager ops * @priv: low level driver private date */
@@ -149,6 +161,7 @@ struct fpga_manager {struct device dev;struct mutex ref_mutex;enum fpga_mgr_states state; +struct fpga_compat_id *compat_id;const struct fpga_manager_ops *mops;void *priv; };
Signature · 1 line
1.8.3.1
PATCH v6 5/29 fpga: region: add compat_id support
In reply to Wu HaoThis patch introduces a compat_id pointer member and sysfs interface for each fpga region, similar as compat_id for fpga manager, it allows applications to read the per region compat_id for compatibility checking before other actions on this fpga-region (e.g PR).
---
v5: use pointer for compat_id as it's optional to implement.
v6: add Acked-by from Alan.
--- Documentation/ABI/testing/sysfs-class-fpga-region | 9 +++++++++ drivers/fpga/fpga-region.c | 22 ++++++++++++++++++++++ include/linux/fpga/fpga-region.h | 2 ++ 3 files changed, 33 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-fpga-region
Documentation/ABI/testing/sysfs-class-fpga-region new file +9 -0
@@ -0,0 +1,9 @@ +What: /sys/class/fpga_region/<region>/compat_id +Date: June 2018 +KernelVersion: 4.18 +Contact: Wu Hao <[email protected]> +Description: FPGA region id for compatibility check, e.g compatibility + of the FPGA reconfiguration hardware and image. This value + is defined or calculated by the layer that is creating the + FPGA region. This interface returns the compat_id value or + just error code -ENOENT in case compat_id is not used.
drivers/fpga/fpga-region.c +22 -0
@@ -158,6 +158,27 @@ int fpga_region_program_fpga(struct fpga_region *region) }EXPORT_SYMBOL_GPL (fpga_region_program_fpga); +static ssize_t compat_id_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct fpga_region *region =to_fpga_region (dev); + +if (!region->compat_id) +return -ENOENT ; + +return sprintf (buf,"%016llx%016llx\n" , + (unsigned long long )region->compat_id->id_h, + (unsigned long long )region->compat_id->id_l); +} + +static DEVICE_ATTR_RO (compat_id); + +static struct attribute *fpga_region_attrs[] = { + &dev_attr_compat_id.attr, +NULL , +}; +ATTRIBUTE_GROUPS (fpga_region); +/** * fpga_region_create - alloc and init a struct fpga_region * @dev: device parent
@@ -258,6 +279,7 @@ static int __init fpga_region_init(void)if (IS_ERR (fpga_region_class))return PTR_ERR (fpga_region_class); + fpga_region_class->dev_groups = fpga_region_groups; fpga_region_class->dev_release = fpga_region_dev_release;return 0 ;
include/linux/fpga/fpga-region.h +2 -0
@@ -14,6 +14,7 @@* @bridge_list: list of FPGA bridges specified in region * @mgr: FPGA manager * @info: FPGA image info +* @compat_id: FPGA region id for compatibility check. * @priv: private data * @get_bridges: optional function to get bridges to a list */
@@ -23,6 +24,7 @@ struct fpga_region {struct list_head bridge_list;struct fpga_manager *mgr;struct fpga_image_info *info; +struct fpga_compat_id *compat_id;void *priv;int (*get_bridges)(struct fpga_region *region); };
Signature · 1 line
1.8.3.1
PATCH v6 6/29 fpga: add device feature list support
In reply to Wu HaoDevice Feature List (DFL) defines a feature list structure that creates a link list of feature headers within the MMIO space to provide an extensible way of adding features. This patch introduces a kernel module to provide basic infrastructure to support FPGA devices which implement the Device Feature List.
Usually there will be different features and their sub features linked into the DFL. This code provides common APIs for feature enumeration, it creates a container device (FPGA base region), walks through the DFLs and creates platform devices for feature devices (Currently it only supports two different feature devices, FPGA Management Engine (FME) and Port which the Accelerator Function Unit (AFU) connected to). In order to enumerate the DFLs, the common APIs required low level driver to provide necessary enumeration information (e.g address for each device feature list for given device) and fill it to the dfl_fpga_enum_info data structure. Please refer to below description for APIs added for enumeration.
Functions for enumeration information preparation:
*dfl_fpga_enum_info_alloc
allocate enumeration information data structure.
*dfl_fpga_enum_info_add_dfl
add a device feature list to dfl_fpga_enum_info data structure.
*dfl_fpga_enum_info_free
free dfl_fpga_enum_info data structure and related resources.
Functions for feature device enumeration:
*dfl_fpga_feature_devs_enumerate
enumerate feature devices and return container device.
*dfl_fpga_feature_devs_remove
remove feature devices under given container device.
---
v3: split from another patch.
separate dfl enumeration code from original pcie driver. provide common data structures and APIs for enumeration. update device feature list parsing process according to latest hw. add dperf/iperf/hssi sub feature placeholder according to latest hw. remove build_info_add_sub_feature and other small functions. replace *_feature_num function with macro.
remove writeq/readq.
v4: fix SPDX license issue
rename files to dfl.[ch], fix typo and add more comments. remove static feature_info tables for FME and Port. remove check on next_afu link list as only FIU has next_afu ptr. remove unused macro in header file.
add more comments for functions.
v5: add "dfl_" prefix to functions and data structures.
remove port related functions from DFL framework.
use BIT_ULL for 64bit register definition.
save dfl_fpga_cdev in pdata for feature platform devices. rebase due to fpga region api changes.
v6: update time in copyright and improve function name.
introduce dfl_devs table to save feature device info.
--- drivers/fpga/Kconfig | 16 ++ drivers/fpga/Makefile | 3 + drivers/fpga/dfl.c | 721 ++++++++++++++++++++++++++++++++++++++++++++++++++ drivers/fpga/dfl.h | 279 +++++++++++++++++++ 4 files changed, 1019 insertions(+) create mode 100644 drivers/fpga/dfl.c create mode 100644 drivers/fpga/dfl.h
drivers/fpga/Kconfig +16 -0
@@ -130,4 +130,20 @@ config OF_FPGA_REGION Support for loading FPGA images by applying a Device Tree overlay. +config FPGA_DFL + tristate "FPGA Device Feature List (DFL) support" + select FPGA_BRIDGE + select FPGA_REGION + help + Device Feature List (DFL) defines a feature list structure that + creates a link list of feature headers within the MMIO space + to provide an extensible way of adding features for FPGA. + Driver can walk through the feature headers to enumerate feature + devices (e.g FPGA Management Engine, Port and Accelerator + Function Unit) and their private features for target FPGA devices. + + Select this option to enable common support for Field-Programmable + Gate Array (FPGA) solutions which implement Device Feature List. + It provides enumeration APIs, and feature device infrastructure. + endif # FPGA
drivers/fpga/Makefile +3 -0
@@ -28,3 +28,6 @@ obj-$(CONFIG_XILINX_PR_DECOUPLER) += xilinx-pr-decoupler.o # High Level Interfaces obj-$(CONFIG_FPGA_REGION) += fpga-region.o obj-$(CONFIG_OF_FPGA_REGION) += of-fpga-region.o + +# FPGA Device Feature List Support +obj-$(CONFIG_FPGA_DFL) += dfl.o
drivers/fpga/dfl.c new file +721 -0
721 lines not on this page · raw message
drivers/fpga/dfl.h new file +279 -0
279 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 7/29 fpga: dfl: add chardev support for feature devices
In reply to Wu HaoFor feature devices drivers, both the FPGA Management Engine (FME) and Accelerated Function Unit (AFU) driver need to expose user interfaces via the device file, for example, mmap and ioctls.
This patch adds chardev support in the dfl driver for feature devices, FME and AFU. It reserves the chardev regions for FME and AFU, and provide interfaces for FME and AFU driver to register their device file operations.
---
v2: rebased
v3: move chardev support to fpga-dfl framework
v4: rebase, and add more comments in code.
v5: rebase, and add dfl_ prefix to APIs and data structures.
v6: add index in dfl_devs to link to dfl_chrdevs.
improve naming on APIs.
--- drivers/fpga/dfl.c | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++-- drivers/fpga/dfl.h | 8 ++++ 2 files changed, 130 insertions(+), 3 deletions(-)
drivers/fpga/dfl.c +122 -3
@@ -22,6 +22,11 @@* dfl_devs table which is indexed by dfl_id_type, e.g name string used for * platform device creation (define name strings in dfl.h, as they could be * reused by platform device drivers). +* +* if the new feature dev needs chardev support, then it's required to add +* a new item in dfl_chardevs table, and configure dfl_devs[i].devt_type as +* index to dfl_chardevs table. If no chardev support just set devt_type +* as one invalid index (DFL_FPGA_DEVT_MAX). */ enum dfl_id_type {FME_ID ,/* fme id allocation and mapping */
@@ -29,22 +34,48 @@ enum dfl_id_type { DFL_ID_MAX, }; +enum dfl_fpga_devt_type { +DFL_FPGA_DEVT_FME , +DFL_FPGA_DEVT_PORT , +DFL_FPGA_DEVT_MAX , +}; +/** * dfl_dev_info - dfl feature device information. * @name: name string of the feature platform device. * @dfh_id: id value in Device Feature Header (DFH) register by DFL spec. * @id: idr id of the feature dev. +* @devt_type: index to dfl_chrdevs[]. */ struct dfl_dev_info {const char *name;u32 dfh_id;struct idr id; +enum dfl_fpga_devt_type devt_type; };/* it is indexed by dfl_id_type */ static struct dfl_dev_info dfl_devs[] = { - {.name =DFL_FPGA_FEATURE_DEV_FME , .dfh_id =DFH_ID_FIU_FME }, - {.name =DFL_FPGA_FEATURE_DEV_PORT , .dfh_id =DFH_ID_FIU_PORT }, + {.name =DFL_FPGA_FEATURE_DEV_FME , .dfh_id =DFH_ID_FIU_FME , + .devt_type =DFL_FPGA_DEVT_FME }, + {.name =DFL_FPGA_FEATURE_DEV_PORT , .dfh_id =DFH_ID_FIU_PORT , + .devt_type =DFL_FPGA_DEVT_PORT }, +}; + +/** +* dfl_chardev_info - chardev information of dfl feature device +* @name: nmae string of the char device. +* @devt: devt of the char device. +*/ +struct dfl_chardev_info { +const char *name; +dev_t devt; +}; + +/* indexed by enum dfl_fpga_devt_type */ +struct dfl_chardev_info dfl_chrdevs[] = { + {.name =DFL_FPGA_FEATURE_DEV_FME }, + {.name =DFL_FPGA_FEATURE_DEV_PORT }, };static void dfl_ids_init (void )
@@ -105,6 +136,86 @@ static enum dfl_id_type dfh_id_to_type(u32 id)return DFL_ID_MAX ; } +static void dfl_chardev_uinit (void ) +{ +int i; + +for (i =0 ; i <DFL_FPGA_DEVT_MAX ; i++) +if (MAJOR (dfl_chrdevs[i].devt)) { +unregister_chrdev_region (dfl_chrdevs[i].devt, +MINORMASK ); + dfl_chrdevs[i].devt =MKDEV (0 ,0 ); + } +} + +static int dfl_chardev_init (void ) +{ +int i, ret; + +for (i =0 ; i <DFL_FPGA_DEVT_MAX ; i++) { + ret =alloc_chrdev_region (&dfl_chrdevs[i].devt,0 ,MINORMASK , + dfl_chrdevs[i].name); +if (ret) + goto exit; + } + +return 0 ; + +exit: +dfl_chardev_uinit (); +return ret; +} + +static dev_t dfl_get_devt (enum dfl_fpga_devt_type type,int id) +{ +if (type >=DFL_FPGA_DEVT_MAX ) +return 0 ; + +return MKDEV (MAJOR (dfl_chrdevs[type].devt), id); +} + +/** +* dfl_fpga_dev_ops_register - register cdev ops for feature dev +* +* @pdev: feature dev. +* @fops: file operations for feature dev's cdev. +* @owner: owning module/driver. +* +* Return: 0 on success, negative error code otherwise. +*/ +int dfl_fpga_dev_ops_register (struct platform_device *pdev, +const struct file_operations *fops, +struct module *owner) +{ +struct dfl_feature_platform_data *pdata =dev_get_platdata (&pdev->dev); + +cdev_init (&pdata->cdev, fops); + pdata->cdev.owner = owner; + +/* +* set parent to the feature device so that its refcount is +* decreased after the last refcount of cdev is gone, that +* makes sure the feature device is valid during device +* file's life-cycle. +*/ + pdata->cdev.kobj.parent = &pdev->dev.kobj; + +return cdev_add (&pdata->cdev, pdev->dev.devt,1 ); +} +EXPORT_SYMBOL_GPL (dfl_fpga_dev_ops_register); + +/** +* dfl_fpga_dev_ops_unregister - unregister cdev ops for feature dev +* @pdev: feature dev. +*/ +void dfl_fpga_dev_ops_unregister (struct platform_device *pdev) +{ +struct dfl_feature_platform_data *pdata =dev_get_platdata (&pdev->dev); + +cdev_del (&pdata->cdev); +} +EXPORT_SYMBOL_GPL (dfl_fpga_dev_ops_unregister); +/** * struct build_feature_devs_info - info collected during feature dev build. *
@@ -266,6 +377,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)return fdev->id; fdev->dev.parent = &binfo->cdev->region->dev; + fdev->dev.devt =dfl_get_devt (dfl_devs[type].devt_type, fdev->id);return 0 ; }
@@ -703,13 +815,20 @@ void dfl_fpga_feature_devs_remove(struct dfl_fpga_cdev *cdev)static int __init dfl_fpga_init (void ) { +int ret; +dfl_ids_init (); -return 0 ; + ret =dfl_chardev_init (); +if (ret) +dfl_ids_destroy (); + +return ret; } static void __exit dfl_fpga_exit(void) { +dfl_chardev_uinit ();dfl_ids_destroy (); }
drivers/fpga/dfl.h +8 -0
@@ -15,6 +15,7 @@#define __FPGA_DFL_H#include <linux/bitfield.h> +#include <linux/cdev.h> #include <linux/delay.h> #include <linux/fs.h> #include <linux/iopoll.h>
@@ -150,6 +151,7 @@ struct dfl_feature {* * @node: node to link feature devs to container device's port_dev_list. * @lock: mutex to protect platform data. +* @cdev: cdev of feature dev. * @dev: ptr to platform device linked with this platform data. * @dfl_cdev: ptr to container device. * @disable_count: count for port disable.
@@ -159,6 +161,7 @@ struct dfl_feature {struct dfl_feature_platform_data {struct list_head node;struct mutex lock; +struct cdev cdev;struct platform_device *dev;struct dfl_fpga_cdev *dfl_cdev;unsigned int disable_count;
@@ -176,6 +179,11 @@ static inline int dfl_feature_platform_data_size(const int num) num * sizeof(struct dfl_feature); } +int dfl_fpga_dev_ops_register (struct platform_device *pdev, +const struct file_operations *fops, +struct module *owner); +void dfl_fpga_dev_ops_unregister (struct platform_device *pdev); +#define dfl_fpga_dev_for_each_feature (pdata, feature) \ for ((feature) = (pdata)->features; \ (feature) < (pdata)->features + (pdata)->num; (feature)++)
Signature · 1 line
1.8.3.1
PATCH v6 8/29 fpga: dfl: add dfl_fpga_cdev_find_port
In reply to Wu HaoFor feature devices, we need a method to find the port dedicated to the device. This patch adds a function dfl_fpga_cdev_find_port for this purpose. e.g FPGA Management Engine (FME) Partial Reconfiguration sub feature, it uses this function to find dedicated port on the device for PR function implementation.
---
v3: s/fpga_for_each_port/fpga_cdev_find_port/
move fpga_cdev_find_port to fpga-dfl module.
v4: improve description in commit message.
add comments to remind user to put_device after use this function.
v5: add "dfl_" prefix to functions.
improve function comments per suggestion from Alan Tull. add Acked-by from Alan and Moritz.
v6: reabse.
--- drivers/fpga/dfl.c | 32 ++++++++++++++++++++++++++++++++ drivers/fpga/dfl.h | 21 +++++++++++++++++++++ 2 files changed, 53 insertions(+)
drivers/fpga/dfl.c +32 -0
@@ -813,6 +813,38 @@ void dfl_fpga_feature_devs_remove(struct dfl_fpga_cdev *cdev) }EXPORT_SYMBOL_GPL (dfl_fpga_feature_devs_remove); +/** +* __dfl_fpga_cdev_find_port - find a port under given container device +* +* @cdev: container device +* @data: data passed to match function +* @match: match function used to find specific port from the port device list +* +* Find a port device under container device. This function needs to be +* invoked with lock held. +* +* Return: pointer to port's platform device if successful, NULL otherwise. +* +* NOTE: you will need to drop the device reference with put_device() after use. +*/ +struct platform_device * +__dfl_fpga_cdev_find_port (struct dfl_fpga_cdev *cdev,void *data, +int (*match)(struct platform_device *,void *)) +{ +struct dfl_feature_platform_data *pdata; +struct platform_device *port_dev; + +list_for_each_entry (pdata, &cdev->port_dev_list, node) { + port_dev = pdata->dev; + +if (match (port_dev, data) &&get_device (&port_dev->dev)) +return port_dev; + } + +return NULL ; +} +EXPORT_SYMBOL_GPL (__dfl_fpga_cdev_find_port); +static int __init dfl_fpga_init (void ) {int ret;
drivers/fpga/dfl.h +21 -0
@@ -284,4 +284,25 @@ struct dfl_fpga_cdev * dfl_fpga_feature_devs_enumerate(struct dfl_fpga_enum_info *info);void dfl_fpga_feature_devs_remove (struct dfl_fpga_cdev *cdev); +/* +* need to drop the device reference with put_device() after use port platform +* device returned by __dfl_fpga_cdev_find_port and dfl_fpga_cdev_find_port +* functions. +*/ +struct platform_device * +__dfl_fpga_cdev_find_port (struct dfl_fpga_cdev *cdev,void *data, +int (*match)(struct platform_device *,void *)); + +static inline struct platform_device * +dfl_fpga_cdev_find_port (struct dfl_fpga_cdev *cdev,void *data, +int (*match)(struct platform_device *,void *)) +{ +struct platform_device *pdev; + +mutex_lock (&cdev->lock); + pdev =__dfl_fpga_cdev_find_port (cdev, data, match); +mutex_unlock (&cdev->lock); + +return pdev; +}#endif /* __FPGA_DFL_H */
Signature · 1 line
1.8.3.1
PATCH v6 9/29 fpga: dfl: add feature device infrastructure
In reply to Wu HaoFrom: Xiao Guangrong <[email protected]>
This patch abstracts the common operations of the sub features, and defines the feature_ops data structure, including init, uinit and ioctl function pointers. And this patch adds some common helper functions for FME and AFU drivers, e.g dfl_feature_dev_use_begin/end which are used to ensure exclusive usage of the feature device file.
---
v2: rebased
v3: use const for feature_ops.
replace pci related function.
v4: rebase and add more comments in code.
v5: remove useless WARN_ON().
reorder declarations in functions per suggestion from Moritz. add "dfl_" prefix to functions and data structure.
v6: add comments for init/uinit function.
add Acked-by from Alan.
--- drivers/fpga/dfl.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/fpga/dfl.h | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 152 insertions(+), 1 deletion(-)
drivers/fpga/dfl.c +71 -0
@@ -136,6 +136,77 @@ static enum dfl_id_type dfh_id_to_type(u32 id)return DFL_ID_MAX ; } +/** +* dfl_fpga_dev_feature_uinit - uinit for sub features of dfl feature device +* @pdev: feature device. +*/ +void dfl_fpga_dev_feature_uinit (struct platform_device *pdev) +{ +struct dfl_feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct dfl_feature *feature; + +dfl_fpga_dev_for_each_feature (pdata, feature) +if (feature->ops) { + feature->ops->uinit (pdev, feature); + feature->ops =NULL ; + } +} +EXPORT_SYMBOL_GPL (dfl_fpga_dev_feature_uinit); + +static int dfl_feature_instance_init (struct platform_device *pdev, +struct dfl_feature_platform_data *pdata, +struct dfl_feature *feature, +struct dfl_feature_driver *drv) +{ +int ret; + + ret = drv->ops->init (pdev, feature); +if (ret) +return ret; + + feature->ops = drv->ops; + +return ret; +} + +/** +* dfl_fpga_dev_feature_init - init for sub features of dfl feature device +* @pdev: feature device. +* @feature_drvs: drvs for sub features. +* +* This function will match sub features with given feature drvs list, and +* use matched drv to init related sub feature. +* +* Return: 0 on success, negative error code otherwise. +*/ +int dfl_fpga_dev_feature_init (struct platform_device *pdev, +struct dfl_feature_driver *feature_drvs) +{ +struct dfl_feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct dfl_feature_driver *drv = feature_drvs; +struct dfl_feature *feature; +int ret; + +while (drv->ops) { +dfl_fpga_dev_for_each_feature (pdata, feature) { +/* match feature and drv using id */ +if (feature->id == drv->id) { + ret =dfl_feature_instance_init (pdev, pdata, + feature, drv); +if (ret) + goto exit; + } + } + drv++; + } + +return 0 ; +exit: +dfl_fpga_dev_feature_uinit (pdev); +return ret; +} +EXPORT_SYMBOL_GPL (dfl_fpga_dev_feature_init); +static void dfl_chardev_uinit (void ) {int i;
drivers/fpga/dfl.h +81 -1
134 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 10/29 fpga: dfl: add dfl_fpga_port_ops support.
In reply to Wu HaoIn some cases, other DFL driver modules may need to access some port operations, e.g disable / enable port for partial reconfiguration in FME module. In order to avoid dependency between port and FME modules, this patch introduces the dfl_fpga_port_ops support in DFL framework. A global dfl_fpga_port_ops list is added in the DFL framework, and it allows other DFL modules to use these port operations registered to this list, even in virtualization case, the port platform device is turned into VF / guest VM and hidden in host, the registered port_ops is still usable. It resolves the dependency issues between modules, but once get port ops API returns a valid port ops, that means related port driver module has been module_get to prevent from unexpected unload, and put port ops API must be invoked after use.
These APIs introduced by this patch is listed below:
* dfl_fpga_port_ops_add
add one port ops to the global list.
* dfl_fpga_port_ops_del
del one port ops from the global list.
* dfl_fpga_port_ops_get / dfl_fpga_port_ops_put
get/put the port ops before/after use.
---
v6: add more comments and improve API naming to dfl_fpga_port_xxx.
add Acked-by from Alan.
--- drivers/fpga/dfl.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ drivers/fpga/dfl.h | 21 +++++++++++++++ 2 files changed, 98 insertions(+)
drivers/fpga/dfl.c +77 -0
@@ -136,6 +136,83 @@ static enum dfl_id_type dfh_id_to_type(u32 id)return DFL_ID_MAX ; } +/* +* introduce a global port_ops list, it allows port drivers to register ops +* in such list, then other feature devices (e.g FME), could use the port +* functions even related port platform device is hidden. Below is one example, +* in virtualization case of PCIe based FPGA DFL device, when SRIOV is +* enabled, port (and it's AFU) is turned into VF and port platform device +* is hidden from system but it's still required to access port to finish FPGA +* reconfiguration function in FME. +*/ + +static DEFINE_MUTEX (dfl_port_ops_mutex); +static LIST_HEAD (dfl_port_ops_list); + +/** +* dfl_fpga_port_ops_get - get matched port ops from the global list +* @pdev: platform device to match with associated port ops. +* Return: matched port ops on success, NULL otherwise. +* +* Please note that must dfl_fpga_port_ops_put after use the port_ops. +*/ +struct dfl_fpga_port_ops *dfl_fpga_port_ops_get (struct platform_device *pdev) +{ +struct dfl_fpga_port_ops *ops =NULL ; + +mutex_lock (&dfl_port_ops_mutex); +if (list_empty (&dfl_port_ops_list)) + goto done; + +list_for_each_entry (ops, &dfl_port_ops_list, node) { +/* match port_ops using the name of platform device */ +if (!strcmp (pdev->name, ops->name)) { +if (!try_module_get (ops->owner)) + ops =NULL ; + goto done; + } + } +done: +mutex_unlock (&dfl_port_ops_mutex); +return ops; +} +EXPORT_SYMBOL_GPL (dfl_fpga_port_ops_get); + +/** +* dfl_fpga_port_ops_put - put port ops +* @ops: port ops. +*/ +void dfl_fpga_port_ops_put (struct dfl_fpga_port_ops *ops) +{ +if (ops && ops->owner) +module_put (ops->owner); +} +EXPORT_SYMBOL_GPL (dfl_fpga_port_ops_put); + +/** +* dfl_fpga_port_ops_add - add port_ops to global list +* @ops: port ops to add. +*/ +void dfl_fpga_port_ops_add (struct dfl_fpga_port_ops *ops) +{ +mutex_lock (&dfl_port_ops_mutex); +list_add_tail (&ops->node, &dfl_port_ops_list); +mutex_unlock (&dfl_port_ops_mutex); +} +EXPORT_SYMBOL_GPL (dfl_fpga_port_ops_add); + +/** +* dfl_fpga_port_ops_del - remove port_ops from global list +* @ops: port ops to del. +*/ +void dfl_fpga_port_ops_del (struct dfl_fpga_port_ops *ops) +{ +mutex_lock (&dfl_port_ops_mutex); +list_del (&ops->node); +mutex_unlock (&dfl_port_ops_mutex); +} +EXPORT_SYMBOL_GPL (dfl_fpga_port_ops_del); +/** * dfl_fpga_dev_feature_uinit - uinit for sub features of dfl feature device * @pdev: feature device.
drivers/fpga/dfl.h +21 -0
@@ -130,6 +130,27 @@/* Latency tolerance reporting. '1' >= 40us, '0' < 40us.*/ #define PORT_CTRL_LATENCY BIT_ULL(2)#define PORT_CTRL_SFTRST_ACK BIT_ULL(4)/* HW ack for reset */ +/** +* struct dfl_fpga_port_ops - port ops +* +* @name: name of this port ops, to match with port platform device. +* @owner: pointer to the module which owns this port ops. +* @node: node to link port ops to global list. +* @get_id: get port id from hardware. +* @enable_set: enable/disable the port. +*/ +struct dfl_fpga_port_ops { +const char *name; +struct module *owner; +struct list_head node; +int (*get_id)(struct platform_device *pdev); +int (*enable_set)(struct platform_device *pdev,bool enable); +}; + +void dfl_fpga_port_ops_add (struct dfl_fpga_port_ops *ops); +void dfl_fpga_port_ops_del (struct dfl_fpga_port_ops *ops); +struct dfl_fpga_port_ops *dfl_fpga_port_ops_get (struct platform_device *pdev); +void dfl_fpga_port_ops_put (struct dfl_fpga_port_ops *ops);/** * struct dfl_feature_driver - sub feature's driver
Signature · 1 line
1.8.3.1
PATCH v6 11/29 fpga: dfl: add dfl_fpga_check_port_id function.
In reply to Wu HaoThis patch adds one common function in DFL framework. It uses port_ops get_id callback to get port id and compare it with given value. This function could be used as match function of the dfl_fpga_cdev_find_port function.
---
v6: reabse and add Acked-by from Alan.
--- drivers/fpga/dfl.c | 22 ++++++++++++++++++++++ drivers/fpga/dfl.h | 1 + 2 files changed, 23 insertions(+)
drivers/fpga/dfl.c +22 -0
@@ -214,6 +214,28 @@ void dfl_fpga_port_ops_del(struct dfl_fpga_port_ops *ops)EXPORT_SYMBOL_GPL (dfl_fpga_port_ops_del);/** +* dfl_fpga_check_port_id - check the port id +* @pdev: port platform device. +* @pport_id: port id to compare. +* +* Return: 1 if port device matches with given port id, otherwise 0. +*/ +int dfl_fpga_check_port_id (struct platform_device *pdev,void *pport_id) +{ +struct dfl_fpga_port_ops *port_ops =dfl_fpga_port_ops_get (pdev); +int port_id; + +if (!port_ops || !port_ops->get_id) +return 0 ; + + port_id = port_ops->get_id (pdev); +dfl_fpga_port_ops_put (port_ops); + +return port_id == *(int *)pport_id; +} +EXPORT_SYMBOL_GPL (dfl_fpga_check_port_id); + +/** * dfl_fpga_dev_feature_uinit - uinit for sub features of dfl feature device * @pdev: feature device. */
drivers/fpga/dfl.h +1 -0
@@ -151,6 +151,7 @@ struct dfl_fpga_port_ops {void dfl_fpga_port_ops_del (struct dfl_fpga_port_ops *ops);struct dfl_fpga_port_ops *dfl_fpga_port_ops_get (struct platform_device *pdev);void dfl_fpga_port_ops_put (struct dfl_fpga_port_ops *ops); +int dfl_fpga_check_port_id (struct platform_device *pdev,void *pport_id);/** * struct dfl_feature_driver - sub feature's driver
Signature · 1 line
1.8.3.1
PATCH v6 12/29 fpga: add FPGA DFL PCIe device driver
In reply to Wu HaoFrom: Zhang Yi <[email protected]>
This patch implements the basic framework of the driver for FPGA PCIe device which implements the Device Feature List (DFL) in its MMIO space. This driver is verified on Intel(R) PCIe based FPGA DFL devices, including both integrated (e.g Intel Server Platform with In-package FPGA) and discrete (e.g Intel FPGA PCIe Acceleration Cards) solutions.
---
v2: move the code to drivers/fpga folder as suggested by Alan Tull.
switch to GPLv2 license.
fix comments from Moritz Fischer.
v3: switch to pci_set_dma_mask/consistent_dma_mask() function.
remove pci_save_state() in probe function.
rename driver to INTEL_FPGA_DFL_PCI and intel-dfl-pci.c to indicate this driver supports Intel FPGA PCI devices which implement DFL. improve Kconfig description for INTEL_FPGA_DFL_PCI
v4: rename to FPGA_DFL_PCI (dfl-pci.c) for better reuse.
fix SPDX license issue.
v5: use module_pci_driver() instead.
add Acked-by from Alan and Moritz.
v6: rebase and unify naming in Kconfig
--- drivers/fpga/Kconfig | 15 +++++++ drivers/fpga/Makefile | 3 ++ drivers/fpga/dfl-pci.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 drivers/fpga/dfl-pci.c
drivers/fpga/Kconfig +15 -0
@@ -146,4 +146,19 @@ config FPGA_DFL Gate Array (FPGA) solutions which implement Device Feature List. It provides enumeration APIs, and feature device infrastructure. +config FPGA_DFL_PCI + tristate "FPGA DFL PCIe Device Driver" + depends on PCI && FPGA_DFL + help + Select this option to enable PCIe driver for PCIe based + Field-Programmable Gate Array (FPGA) solutions which implemented + the Device Feature List (DFL). This driver provides interfaces + for userspace applications to configure, enumerate, open and access + FPGA accelerators on the FPGA DFL devices, enables system level + management functions such as FPGA partial reconfiguration, power + management, and virtualization with DFL framework and DFL feature + device drivers. + + To compile this as a module, choose M here. + endif # FPGA
drivers/fpga/Makefile +3 -0
@@ -31,3 +31,6 @@ obj-$(CONFIG_OF_FPGA_REGION) += of-fpga-region.o # FPGA Device Feature List Support obj-$(CONFIG_FPGA_DFL) += dfl.o + +# Drivers for FPGAs which implement DFL +obj-$(CONFIG_FPGA_DFL_PCI) += dfl-pci.o
drivers/fpga/dfl-pci.c new file +114 -0
114 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 13/29 fpga: dfl-pci: add enumeration for feature devices
In reply to Wu HaoThe Device Feature List (DFL) is implemented in MMIO, and features are linked via the DFLs. This patch enables pcie driver to prepare enumeration information (e.g locations of all device feature lists in MMIO) and use common APIs provided by the Device Feature List framework to enumerate each feature device linked.
---
v3: split from another patch
use common functions from DFL framework for enumeration.
v4: rebase
v5: rebase due to naming changes on DFL framework APIs.
add acked-by from Alan.
v6: reabse
--- drivers/fpga/dfl-pci.c | 200 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 198 insertions(+), 2 deletions(-)
drivers/fpga/dfl-pci.c +198 -2
@@ -22,9 +22,52 @@#include <linux/errno.h> #include <linux/aer.h> +#include "dfl.h" +#define DRV_VERSION "0.8"#define DRV_NAME "dfl-pci" +struct cci_drvdata { +struct dfl_fpga_cdev *cdev;/* container device */ +struct list_head regions;/* list of pci bar mapping region */ +}; + +/* pci bar mapping info */ +struct cci_region { +int bar; +void __iomem *ioaddr;/* pointer to mapped bar region */ +struct list_head node; +}; + +static void __iomem *cci_pci_ioremap_bar (struct pci_dev *pcidev,int bar) +{ +struct cci_drvdata *drvdata =pci_get_drvdata (pcidev); +struct cci_region *region; + +list_for_each_entry (region, &drvdata->regions, node) +if (region->bar == bar) { +dev_dbg (&pcidev->dev,"BAR %d region exists\n" , bar); +return region->ioaddr; + } + + region =devm_kzalloc (&pcidev->dev,sizeof (*region),GFP_KERNEL ); +if (!region) +return NULL ; + + region->bar = bar; + region->ioaddr =pci_ioremap_bar (pcidev, bar); +if (!region->ioaddr) { +dev_err (&pcidev->dev,"can't ioremap memory from BAR %d.\n" , + bar); +devm_kfree (&pcidev->dev, region); +return NULL ; + } + +list_add (®ion->node, &drvdata->regions); + +return region->ioaddr; +} +/* PCI Device ID */ #define PCIE_DEVICE_ID_PF_INT_5_X 0xBCBD#define PCIE_DEVICE_ID_PF_INT_6_X 0xBCC0
@@ -45,6 +88,144 @@ };MODULE_DEVICE_TABLE (pci, cci_pcie_id_tbl); +static int cci_init_drvdata (struct pci_dev *pcidev) +{ +struct cci_drvdata *drvdata; + + drvdata =devm_kzalloc (&pcidev->dev,sizeof (*drvdata),GFP_KERNEL ); +if (!drvdata) +return -ENOMEM ; + +INIT_LIST_HEAD (&drvdata->regions); + +pci_set_drvdata (pcidev, drvdata); + +return 0 ; +} + +static void cci_pci_release_regions (struct pci_dev *pcidev) +{ +struct cci_drvdata *drvdata =pci_get_drvdata (pcidev); +struct cci_region *tmp, *region; + +list_for_each_entry_safe (region, tmp, &drvdata->regions, node) { +list_del (®ion->node); +if (region->ioaddr) +pci_iounmap (pcidev, region->ioaddr); +devm_kfree (&pcidev->dev, region); + } +} + +static void cci_remove_drvdata (struct pci_dev *pcidev) +{ +struct cci_drvdata *drvdata =pci_get_drvdata (pcidev); + +cci_pci_release_regions (pcidev); +pci_set_drvdata (pcidev,NULL ); +devm_kfree (&pcidev->dev, drvdata); +} + +static void cci_remove_feature_devs (struct pci_dev *pcidev) +{ +struct cci_drvdata *drvdata =pci_get_drvdata (pcidev); + +/* remove all children feature devices */ +dfl_fpga_feature_devs_remove (drvdata->cdev); +} + +/* enumerate feature devices under pci device */ +static int cci_enumerate_feature_devs (struct pci_dev *pcidev) +{ +struct cci_drvdata *drvdata =pci_get_drvdata (pcidev); +struct dfl_fpga_enum_info *info; +struct dfl_fpga_cdev *cdev; +resource_size_t start, len; +int port_num, bar, i, ret =0 ; +void __iomem *base; +u32 offset; +u64 v; + +/* allocate enumeration info via pci_dev */ + info =dfl_fpga_enum_info_alloc (&pcidev->dev); +if (!info) +return -ENOMEM ; + +/* start to find Device Feature List from Bar 0 */ + base =cci_pci_ioremap_bar (pcidev,0 ); +if (!base) { + ret = -ENOMEM ; + goto enum_info_free_exit; + } + +/* +* PF device has FME and Ports/AFUs, and VF device only has 1 Port/AFU. +* check them and add related "Device Feature List" info for the next +* step enumeration. +*/ +if (dfl_feature_is_fme (base)) { + start =pci_resource_start (pcidev,0 ); + len =pci_resource_len (pcidev,0 ); + +dfl_fpga_enum_info_add_dfl (info, start, len, base); + +/* +* find more Device Feature Lists (e.g Ports) per information +* indicated by FME module. +*/ + v =readq (base +FME_HDR_CAP ); + port_num =FIELD_GET (FME_CAP_NUM_PORTS , v); + +WARN_ON (port_num >MAX_DFL_FPGA_PORT_NUM ); + +for (i =0 ; i < port_num; i++) { + v =readq (base +FME_HDR_PORT_OFST (i)); + +/* skip ports which are not implemented. */ +if (!(v &FME_PORT_OFST_IMP )) +continue ; + +/* +* add Port's Device Feature List information for next +* step enumeration. +*/ + bar =FIELD_GET (FME_PORT_OFST_BAR_ID , v); + offset =FIELD_GET (FME_PORT_OFST_DFH_OFST , v); + base =cci_pci_ioremap_bar (pcidev, bar); +if (!base) +continue ; + + start =pci_resource_start (pcidev, bar) + offset; + len =pci_resource_len (pcidev, bar) - offset; + +dfl_fpga_enum_info_add_dfl (info, start, len, + base + offset); + } + }else if (dfl_feature_is_port (base)) { + start =pci_resource_start (pcidev,0 ); + len =pci_resource_len (pcidev,0 ); + +dfl_fpga_enum_info_add_dfl (info, start, len, base); + }else { + ret = -ENODEV ; + goto enum_info_free_exit; + } + +/* start enumeration with prepared enumeration information */ + cdev =dfl_fpga_feature_devs_enumerate (info); +if (IS_ERR (cdev)) { +dev_err (&pcidev->dev,"Enumeration failure\n" ); + ret =PTR_ERR (cdev); + goto enum_info_free_exit; + } + + drvdata->cdev = cdev; + +enum_info_free_exit: +dfl_fpga_enum_info_free (info); + +return ret; +} +static int cci_pci_probe (struct pci_dev *pcidev,const struct pci_device_id *pcidevid) {
@@ -82,9 +263,22 @@ int cci_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *pcidevid) goto release_region_exit; } -/* TODO: create and add the platform device per feature list */ -return 0 ; + ret =cci_init_drvdata (pcidev); +if (ret) { +dev_err (&pcidev->dev,"Fail to init drvdata %d.\n" , ret); + goto release_region_exit; + } + + ret =cci_enumerate_feature_devs (pcidev); +if (ret) { +dev_err (&pcidev->dev,"enumeration failure %d.\n" , ret); + goto remove_drvdata_exit; + } + +return ret; +remove_drvdata_exit: +cci_remove_drvdata (pcidev); release_region_exit:pci_release_regions (pcidev); disable_error_report_exit:
@@ -95,6 +289,8 @@ int cci_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *pcidevid)static void cci_pci_remove (struct pci_dev *pcidev) { +cci_remove_feature_devs (pcidev); +cci_remove_drvdata (pcidev);pci_release_regions (pcidev);pci_disable_pcie_error_reporting (pcidev);pci_disable_device (pcidev);
Signature · 1 line
1.8.3.1
PATCH v6 14/29 fpga: dfl: add FPGA Management Engine driver basic framework
In reply to Wu HaoFrom: Kang Luwei <[email protected]>
The FPGA Management Engine (FME) provides power, thermal management, performance counters, partial reconfiguration and other functions. For each function, it is packaged into a private feature linked to the FME feature device in the 'Device Feature List'. It's a platform device created by DFL framework.
This patch adds the basic framework of FME platform driver. It defines sub feature drivers to handle the different sub features, including init, uinit and ioctl. It also registers the file operations for the device file.
---
v3: rename driver from intel-fpga-fme to dfl-fme
rename Kconfig from INTEL_FPGA_FME to FPGA_DFL_FME
v4: fix SPDX license issue, use dfl-fme as module name
v5: rebase, due to DFL framework naming changes on functions and data structures.
fix uinit order in remove function.
remove else block in fme_ioctl function per suggestion from Alan.
v6: fix copyright time, rebase and add Acked-by from Alan.
--- drivers/fpga/Kconfig | 10 +++ drivers/fpga/Makefile | 3 + drivers/fpga/dfl-fme-main.c | 158 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 171 insertions(+) create mode 100644 drivers/fpga/dfl-fme-main.c
drivers/fpga/Kconfig +10 -0
@@ -146,6 +146,16 @@ config FPGA_DFL Gate Array (FPGA) solutions which implement Device Feature List. It provides enumeration APIs, and feature device infrastructure. +config FPGA_DFL_FME + tristate "FPGA DFL FME Driver" + depends on FPGA_DFL + help + The FPGA Management Engine (FME) is a feature device implemented + under Device Feature List (DFL) framework. Select this option to + enable the platform device driver for FME which implements all + FPGA platform level management features. There shall be 1 FME + per DFL based FPGA device. + config FPGA_DFL_PCI tristate "FPGA DFL PCIe Device Driver" depends on PCI && FPGA_DFL
drivers/fpga/Makefile +3 -0
@@ -31,6 +31,9 @@ obj-$(CONFIG_OF_FPGA_REGION) += of-fpga-region.o # FPGA Device Feature List Support obj-$(CONFIG_FPGA_DFL) += dfl.o +obj-$(CONFIG_FPGA_DFL_FME) += dfl-fme.o + +dfl-fme-objs := dfl-fme-main.o # Drivers for FPGAs which implement DFL obj-$(CONFIG_FPGA_DFL_PCI) += dfl-pci.o
drivers/fpga/dfl-fme-main.c new file +158 -0
158 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 15/29 fpga: dfl: fme: add header sub feature support
In reply to Wu HaoFrom: Kang Luwei <[email protected]>
The Header Register set is always present for FPGA Management Engine (FME), this patch implements init and uinit function for header sub feature and introduces several read-only sysfs interfaces for the capability and status.
Sysfs interfaces:
* /sys/class/fpga_region/<regionX>/<dfl-fme.x>/ports_num Read-only. Number of ports implemented
* /sys/class/fpga_region/<regionX>/<dfl-fme.x>/bitstream_id Read-only. Bitstream (static FPGA region) identifier number. It contains the detailed version and other information of this static FPGA region.
* /sys/class/fpga_region/<regionX>/<dfl-fme.x>/bitstream_metadata Read-only. Bitstream (static FPGA region) meta data. It contains the synthesis date, seed and other information of this static FPGA region.
---
v2: add sysfs documentation
v3: rename driver to fpga-dfl-fme.
improve sysfs doc and commit description. replace bitfield.
v4: rebase and switch to use id for sub feature matching.
add more description for bitstream_id/metadata.
v5: rebase due to DFL framework API naming changes.
replace "blue bitstream" terminology.
fix one typo in sysfs doc and add acked-by from Alan.
v6: reabse
--- Documentation/ABI/testing/sysfs-platform-dfl-fme | 23 ++++++++ drivers/fpga/dfl-fme-main.c | 68 ++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-platform-dfl-fme
Documentation/ABI/testing/sysfs-platform-dfl-fme new file +23 -0
@@ -0,0 +1,23 @@ +What: /sys/bus/platform/devices/dfl-fme.0/ports_num +Date: June 2018 +KernelVersion: 4.18 +Contact: Wu Hao <[email protected]> +Description: Read-only. One DFL FPGA device may have more than 1 + port/Accelerator Function Unit (AFU). It returns the + number of ports on the FPGA device when read it. + +What: /sys/bus/platform/devices/dfl-fme.0/bitstream_id +Date: June 2018 +KernelVersion: 4.18 +Contact: Wu Hao <[email protected]> +Description: Read-only. It returns Bitstream (static FPGA region) + identifier number, which includes the detailed version + and other information of this static FPGA region. + +What: /sys/bus/platform/devices/dfl-fme.0/bitstream_metadata +Date: June 2018 +KernelVersion: 4.18 +Contact: Wu Hao <[email protected]> +Description: Read-only. It returns Bitstream (static FPGA region) meta + data, which includes the synthesis date, seed and other + information of this static FPGA region.
drivers/fpga/dfl-fme-main.c +68 -0
84 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 16/29 fpga: dfl: fme: add DFL_FPGA_GET_API_VERSION/CHECK_EXTENSION ioctls support
In reply to Wu HaoDFL_FPGA_GET_API_VERSION and DFL_FPGA_CHECK_EXTENSION ioctls are common ones which need to be supported by all feature devices drivers including FME and AFU. Userspace application can use these ioctl interfaces to get the API info and check if specific extension is supported or not in current driver.
This patch implements above 2 ioctls in FPGA Management Engine (FME) driver.
---
v2: switched to GPLv2 license.
v3: rename intel-fpga.h to fpga-dfl.h and rebased.
v4: fix SPDX license issue.
add Acked-by from Alan and Moritz.
v5: rebase due to DFL framework API naming changes.
add DFL_ prefix to IOCTL APIs.
v6: rebase and fix copyright time.
--- Documentation/ioctl/ioctl-number.txt | 1 + drivers/fpga/dfl-fme-main.c | 12 +++++++++ include/uapi/linux/fpga-dfl.h | 48 ++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 include/uapi/linux/fpga-dfl.h
Documentation/ioctl/ioctl-number.txt +1 -0
@@ -322,6 +322,7 @@ Code Seq#(hex) Include File Comments 0xB3 00 linux/mmc/ioctl.h 0xB4 00-0F linux/gpio.h <mailto:[email protected]> 0xB5 00-0F uapi/linux/rpmsg.h <mailto:[email protected]> +0xB6 all linux/fpga-dfl.h 0xC0 00-0F linux/usb/iowarrior.h 0xCA 00-0F uapi/misc/cxl.h 0xCA 10-2F uapi/misc/ocxl.h
drivers/fpga/dfl-fme-main.c +12 -0
@@ -16,6 +16,7 @@#include <linux/kernel.h> #include <linux/module.h> +#include <linux/fpga-dfl.h> #include "dfl.h"
@@ -116,6 +117,13 @@ static void fme_hdr_uinit(struct platform_device *pdev, }, }; +static long fme_ioctl_check_extension (struct dfl_feature_platform_data *pdata, +unsigned long arg) +{ +/* No extension support for now */ +return 0 ; +} +static int fme_open (struct inode *inode,struct file *filp) {struct platform_device *fdev =dfl_fpga_inode_to_feature_dev (inode);
@@ -156,6 +164,10 @@ static long fme_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)dev_dbg (&pdev->dev,"%s cmd 0x%x\n" , __func__, cmd);switch (cmd) { +case DFL_FPGA_GET_API_VERSION : +return DFL_FPGA_API_VERSION ; +case DFL_FPGA_CHECK_EXTENSION : +return fme_ioctl_check_extension (pdata, arg);default :/* * Let sub-feature's ioctl function to handle the cmd
include/uapi/linux/fpga-dfl.h new file +48 -0
48 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 17/29 fpga: dfl: fme: add partial reconfiguration sub feature support
In reply to Wu HaoFrom: Kang Luwei <[email protected]>
Partial Reconfiguration (PR) is the most important function for FME. It allows reconfiguration for given Port/Accelerated Function Unit (AFU).
It creates platform devices for fpga-mgr, fpga-regions and fpga-bridges, and invokes fpga-region's interface (fpga_region_program_fpga) for PR operation once PR request received via ioctl. Below user space interface is exposed by this sub feature.
Ioctl interface:
* DFL_FPGA_FME_PORT_PR
Do partial reconfiguration per information from userspace, including target port(AFU), buffer size and address info. It returns error code to userspace if failed. For detailed PR error information, user needs to read fpga-mgr's status sysfs interface.
---
v2: moved the code to drivers/fpga folder as suggested by Alan Tull.
switched to GPLv2 license.
removed status from FPGA_FME_PORT_PR ioctl data structure. added platform devices creation for fpga-mgr/fpga-region/fpga-bridge. switched to fpga-region interface fpga_region_program_fpga for PR. fixed comments from Alan Tull on FPGA_MGR_PARTIAL_RECONFIG flag usage. fixed kbuild warnings.
v3: rename driver files to dfl-fme-*.
rebase due to fpga APIs change.
replace bitfields.
switch to fpga_cdev_find_port to find port device.
v4: rebase and correct comments for some function.
fix SPDX license issue.
remove unnecessary input parameter for destroy_bridge/region function. add dfl-fme-pr.h for PR sub feature data structure and registers.
v5: rebase due to DFL framework API naming changes.
improve naming for IOCTL API, functions and data structure. defer finding port platform device to fme bridge.
pass mapped ioaddr to fme manager via pdata.
remove useless devm_kfree().
v6: rebase, fix copyright time and improve function name.
add Acked-by from Alan.
--- drivers/fpga/Makefile | 2 +- drivers/fpga/dfl-fme-main.c | 43 +++- drivers/fpga/dfl-fme-pr.c | 474 ++++++++++++++++++++++++++++++++++++++++++ drivers/fpga/dfl-fme-pr.h | 84 ++++++++ drivers/fpga/dfl-fme.h | 38 ++++ include/uapi/linux/fpga-dfl.h | 28 +++ 6 files changed, 667 insertions(+), 2 deletions(-) create mode 100644 drivers/fpga/dfl-fme-pr.c create mode 100644 drivers/fpga/dfl-fme-pr.h create mode 100644 drivers/fpga/dfl-fme.h
drivers/fpga/Makefile +1 -1
@@ -33,7 +33,7 @@ obj-$(CONFIG_OF_FPGA_REGION) += of-fpga-region.o obj-$(CONFIG_FPGA_DFL) += dfl.o obj-$(CONFIG_FPGA_DFL_FME) += dfl-fme.o -dfl-fme-objs := dfl-fme-main.o +dfl-fme-objs := dfl-fme-main.o dfl-fme-pr.o # Drivers for FPGAs which implement DFL obj-$(CONFIG_FPGA_DFL_PCI) += dfl-pci.o
drivers/fpga/dfl-fme-main.c +42 -1
82 lines not on this page · raw message
drivers/fpga/dfl-fme-pr.c new file +474 -0
474 lines not on this page · raw message
drivers/fpga/dfl-fme-pr.h new file +84 -0
84 lines not on this page · raw message
drivers/fpga/dfl-fme.h new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Header file for FPGA Management Engine (FME) Driver +* +* Copyright (C) 2017-2018 Intel Corporation, Inc. +* +* Authors: +* Kang Luwei <[email protected]> +* Xiao Guangrong <[email protected]> +* Wu Hao <[email protected]> +* Joseph Grecco <[email protected]> +* Enno Luebbers <[email protected]> +* Tim Whisonant <[email protected]> +* Ananda Ravuri <[email protected]> +* Henry Mitchel <[email protected]> +*/ + +#ifndef __DFL_FME_H +#define __DFL_FME_H + +/** +* struct dfl_fme - dfl fme private data +* +* @mgr: FME's FPGA manager platform device. +* @region_list: link list of FME's FPGA regions. +* @bridge_list: link list of FME's FPGA bridges. +* @pdata: fme platform device's pdata. +*/ +struct dfl_fme { +struct platform_device *mgr; +struct list_head region_list; +struct list_head bridge_list; +struct dfl_feature_platform_data *pdata; +}; + +extern const struct dfl_feature_ops pr_mgmt_ops; + +#endif /* __DFL_FME_H */
include/uapi/linux/fpga-dfl.h +28 -0
@@ -14,6 +14,8 @@#ifndef _UAPI_LINUX_FPGA_DFL_H#define _UAPI_LINUX_FPGA_DFL_H +#include <linux/types.h> +#define DFL_FPGA_API_VERSION 0/*
@@ -26,6 +28,7 @@#define DFL_FPGA_MAGIC 0xB6#define DFL_FPGA_BASE 0 +#define DFL_FME_BASE 0x80/** * DFL_FPGA_GET_API_VERSION - _IO(DFL_FPGA_MAGIC, DFL_FPGA_BASE + 0)
@@ -45,4 +48,29 @@#define DFL_FPGA_CHECK_EXTENSION _IO(DFL_FPGA_MAGIC, DFL_FPGA_BASE + 1) +/* IOCTLs for FME file descriptor */ + +/** +* DFL_FPGA_FME_PORT_PR - _IOW(DFL_FPGA_MAGIC, DFL_FME_BASE + 0, +* struct dfl_fpga_fme_port_pr) +* +* Driver does Partial Reconfiguration based on Port ID and Buffer (Image) +* provided by caller. +* Return: 0 on success, -errno on failure. +* If DFL_FPGA_FME_PORT_PR returns -EIO, that indicates the HW has detected +* some errors during PR, under this case, the user can fetch HW error info +* from the status of FME's fpga manager. +*/ + +struct dfl_fpga_fme_port_pr { +/* Input */ +__u32 argsz;/* Structure length */ +__u32 flags;/* Zero for now */ +__u32 port_id; +__u32 buffer_size; +__u64 buffer_address;/* Userspace address to the buffer for PR */ +}; + +#define DFL_FPGA_FME_PORT_PR _IO(DFL_FPGA_MAGIC, DFL_FME_BASE + 0) +#endif /* _UAPI_LINUX_FPGA_DFL_H */
Signature · 1 line
1.8.3.1
PATCH v6 18/29 fpga: dfl: add fpga manager platform driver for FME
In reply to Wu HaoThis patch adds fpga manager driver for FPGA Management Engine (FME). It implements fpga_manager_ops for FPGA Partial Reconfiguration function.
---
v3: rename driver to dfl-fpga-fme-mgr
implemented status callback for fpga manager
rebased due to fpga api changes
v4: rename to dfl-fme-mgr, and fix SPDX license issue
add pr_credit comments and improve dev_err message remove interface_id sysfs interface
include dfl-fme-pr.h instead of dfl.h
v5: move related register definition from dfl-fme-pr.h to dfl-fme-mgr.c
use mapped ioaddr passed via pdata for register access. rebase due to fpga manager API changes.
include header file for readq/writeq.
v6: rebase, fix copyright time and add Acked-by from Alan.
--- drivers/fpga/Kconfig | 6 + drivers/fpga/Makefile | 1 + drivers/fpga/dfl-fme-mgr.c | 334 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 341 insertions(+) create mode 100644 drivers/fpga/dfl-fme-mgr.c
drivers/fpga/Kconfig +6 -0
@@ -156,6 +156,12 @@ config FPGA_DFL_FME FPGA platform level management features. There shall be 1 FME per DFL based FPGA device. +config FPGA_DFL_FME_MGR + tristate "FPGA DFL FME Manager Driver" + depends on FPGA_DFL_FME + help + Say Y to enable FPGA Manager driver for FPGA Management Engine. + config FPGA_DFL_PCI tristate "FPGA DFL PCIe Device Driver" depends on PCI && FPGA_DFL
drivers/fpga/Makefile +1 -0
@@ -32,6 +32,7 @@ obj-$(CONFIG_OF_FPGA_REGION) += of-fpga-region.o # FPGA Device Feature List Support obj-$(CONFIG_FPGA_DFL) += dfl.o obj-$(CONFIG_FPGA_DFL_FME) += dfl-fme.o +obj-$(CONFIG_FPGA_DFL_FME_MGR) += dfl-fme-mgr.o dfl-fme-objs := dfl-fme-main.o dfl-fme-pr.o
drivers/fpga/dfl-fme-mgr.c new file +334 -0
334 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 19/29 fpga: dfl: fme-mgr: add compat_id support
In reply to Wu HaoThis patch adds compat_id support to fme manager driver, it reads the ID from the hardware register. And it could be used for compatibility check before partial reconfiguration.
---
v6: add Acked-by from Alan.
--- drivers/fpga/dfl-fme-mgr.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/fpga/dfl-fme-mgr.c +15 -0
@@ -272,9 +272,17 @@ static u64 fme_mgr_status(struct fpga_manager *mgr) .status = fme_mgr_status, }; +static void fme_mgr_get_compat_id (void __iomem *fme_pr, +struct fpga_compat_id *id) +{ + id->id_l =readq (fme_pr +FME_PR_INTFC_ID_L ); + id->id_h =readq (fme_pr +FME_PR_INTFC_ID_H ); +} +static int fme_mgr_probe (struct platform_device *pdev) {struct dfl_fme_mgr_pdata *pdata =dev_get_platdata (&pdev->dev); +struct fpga_compat_id *compat_id;struct device *dev = &pdev->dev;struct fme_mgr_priv *priv;struct fpga_manager *mgr;
@@ -295,11 +303,18 @@ static int fme_mgr_probe(struct platform_device *pdev)return PTR_ERR (priv->ioaddr); } + compat_id =devm_kzalloc (dev,sizeof (*compat_id),GFP_KERNEL ); +if (!compat_id) +return -ENOMEM ; + +fme_mgr_get_compat_id (priv->ioaddr, compat_id); + mgr =fpga_mgr_create (dev,"DFL FME FPGA Manager" , &fme_mgr_ops, priv);if (!mgr)return -ENOMEM ; + mgr->compat_id = compat_id;platform_set_drvdata (pdev, mgr); ret =fpga_mgr_register (mgr);
Signature · 1 line
1.8.3.1
PATCH v6 20/29 fpga: dfl: add fpga bridge platform driver for FME
In reply to Wu HaoThis patch adds fpga bridge platform driver for FPGA Management Engine. It implements the enable_set callback for fpga bridge.
---
v3: rename driver to fpga-dfl-fme-br
remove useless dev_dbg in probe function. rebased due to fpga api change.
v4: rename to dfl-fme-br and fix SPDX license issue
include dfl-fme-pr.h instead of dfl-fme.h add Acked-by from Alan and Moritz
v5: rebase due to API changes.
defer port and its ops finding when really need.
v6: reabse, and fix copyright time.
--- drivers/fpga/Kconfig | 6 +++ drivers/fpga/Makefile | 1 + drivers/fpga/dfl-fme-br.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 drivers/fpga/dfl-fme-br.c
drivers/fpga/Kconfig +6 -0
@@ -162,6 +162,12 @@ config FPGA_DFL_FME_MGR help Say Y to enable FPGA Manager driver for FPGA Management Engine. +config FPGA_DFL_FME_BRIDGE + tristate "FPGA DFL FME Bridge Driver" + depends on FPGA_DFL_FME + help + Say Y to enable FPGA Bridge driver for FPGA Management Engine. + config FPGA_DFL_PCI tristate "FPGA DFL PCIe Device Driver" depends on PCI && FPGA_DFL
drivers/fpga/Makefile +1 -0
@@ -33,6 +33,7 @@ obj-$(CONFIG_OF_FPGA_REGION) += of-fpga-region.o obj-$(CONFIG_FPGA_DFL) += dfl.o obj-$(CONFIG_FPGA_DFL_FME) += dfl-fme.o obj-$(CONFIG_FPGA_DFL_FME_MGR) += dfl-fme-mgr.o +obj-$(CONFIG_FPGA_DFL_FME_BRIDGE) += dfl-fme-br.o dfl-fme-objs := dfl-fme-main.o dfl-fme-pr.o
drivers/fpga/dfl-fme-br.c new file +114 -0
114 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 21/29 fpga: dfl: add fpga region platform driver for FME
In reply to Wu HaoThis patch adds fpga region platform driver for FPGA Management Engine. It register an fpga region with given fpga manager / bridge device.
---
v3: rename driver to fpga-dfl-fme-region
fix fpga_mgr_put order problem in remove function. rebased due to fpga api changes.
v4: rename to dfl-fme-region, fix SPDX license issue
include dfl-fme-pr.h instead of dfl-fme.h and dfl.h add Acked-by from Alan and Moritz
v5: rebase, due to fpga region api changes.
v6: rebase, and fix copyright time.
--- drivers/fpga/Kconfig | 6 +++ drivers/fpga/Makefile | 1 + drivers/fpga/dfl-fme-region.c | 88 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 drivers/fpga/dfl-fme-region.c
drivers/fpga/Kconfig +6 -0
@@ -168,6 +168,12 @@ config FPGA_DFL_FME_BRIDGE help Say Y to enable FPGA Bridge driver for FPGA Management Engine. +config FPGA_DFL_FME_REGION + tristate "FPGA DFL FME Region Driver" + depends on FPGA_DFL_FME + help + Say Y to enable FPGA Region driver for FPGA Management Engine. + config FPGA_DFL_PCI tristate "FPGA DFL PCIe Device Driver" depends on PCI && FPGA_DFL
drivers/fpga/Makefile +1 -0
@@ -34,6 +34,7 @@ obj-$(CONFIG_FPGA_DFL) += dfl.o obj-$(CONFIG_FPGA_DFL_FME) += dfl-fme.o obj-$(CONFIG_FPGA_DFL_FME_MGR) += dfl-fme-mgr.o obj-$(CONFIG_FPGA_DFL_FME_BRIDGE) += dfl-fme-br.o +obj-$(CONFIG_FPGA_DFL_FME_REGION) += dfl-fme-region.o dfl-fme-objs := dfl-fme-main.o dfl-fme-pr.o
drivers/fpga/dfl-fme-region.c new file +88 -0
88 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 22/29 fpga: dfl: fme-region: add support for compat_id
In reply to Wu HaoThis patch adds compat_id support, it reuses fme manager's compat id, as the per region compat id is actually from the fme manager's register.
---
v5: reuse fme manager's compat_id as per region compat_id
v6: rebase, fix copyright time and add Acked-by from Alan.
--- drivers/fpga/dfl-fme-region.c | 1 + 1 file changed, 1 insertion(+)
drivers/fpga/dfl-fme-region.c +1 -0
@@ -45,6 +45,7 @@ static int fme_region_probe(struct platform_device *pdev) } region->priv = pdata; + region->compat_id = mgr->compat_id;platform_set_drvdata (pdev, region); ret =fpga_region_register (region);
Signature · 1 line
1.8.3.1
PATCH v6 23/29 fpga: dfl: add FPGA Accelerated Function Unit driver basic framework
In reply to Wu HaoOn DFL FPGA devices, the Accelerated Function Unit (AFU), can be reprogrammed for different functions. It connects to the FPGA infrastructure (static FPGA region) via a Port. Port CSRs are implemented separately from the AFU CSRs to provide control and status of the Port. Once valid PR bitstream is programmed into the AFU, it allows access to the AFU CSRs in the AFU MMIO space.
This patch only implements basic driver framework for AFU, including device file operation framework.
---
v3: rename driver to dfl-afu-main.c
v4: rename to dfl-port and fix SPDX license issue.
v5: rebase, and add Acked-by from Alan.
fix uinit order in remove function.
v6: rebase, and fix copyright time.
--- drivers/fpga/Kconfig | 9 +++ drivers/fpga/Makefile | 2 + drivers/fpga/dfl-afu-main.c | 162 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 173 insertions(+) create mode 100644 drivers/fpga/dfl-afu-main.c
drivers/fpga/Kconfig +9 -0
@@ -174,6 +174,15 @@ config FPGA_DFL_FME_REGION help Say Y to enable FPGA Region driver for FPGA Management Engine. +config FPGA_DFL_AFU + tristate "FPGA DFL AFU Driver" + depends on FPGA_DFL + help + This is the driver for FPGA Accelerated Function Unit (AFU) which + implements AFU and Port management features. A User AFU connects + to the FPGA infrastructure via a Port. There may be more than 1 + Port/AFU per DFL based FPGA device. + config FPGA_DFL_PCI tristate "FPGA DFL PCIe Device Driver" depends on PCI && FPGA_DFL
drivers/fpga/Makefile +2 -0
@@ -35,8 +35,10 @@ obj-$(CONFIG_FPGA_DFL_FME) += dfl-fme.o obj-$(CONFIG_FPGA_DFL_FME_MGR) += dfl-fme-mgr.o obj-$(CONFIG_FPGA_DFL_FME_BRIDGE) += dfl-fme-br.o obj-$(CONFIG_FPGA_DFL_FME_REGION) += dfl-fme-region.o +obj-$(CONFIG_FPGA_DFL_AFU) += dfl-afu.o dfl-fme-objs := dfl-fme-main.o dfl-fme-pr.o +dfl-afu-objs := dfl-afu-main.o # Drivers for FPGAs which implement DFL obj-$(CONFIG_FPGA_DFL_PCI) += dfl-pci.o
drivers/fpga/dfl-afu-main.c new file +162 -0
162 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 24/29 fpga: dfl: afu: add port ops support
In reply to Wu HaoThis patch registers the port ops into the global list in the DFL framework, and it allows other modules to use the port ops. And This patch includes the implementation of the get_id and enable_set ops too.
---
v6: rebase, fix copyright time and add Acked-by from Alan.
--- drivers/fpga/dfl-afu-main.c | 122 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 121 insertions(+), 1 deletion(-)
drivers/fpga/dfl-afu-main.c +121 -1
@@ -19,6 +19,83 @@#include "dfl.h" +/** +* port_enable - enable a port +* @pdev: port platform device. +* +* Enable Port by clear the port soft reset bit, which is set by default. +* The User AFU is unable to respond to any MMIO access while in reset. +* port_enable function should only be used after port_disable +* function. +*/ +static void port_enable (struct platform_device *pdev) +{ +struct dfl_feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +void __iomem *base; +u64 v; + +WARN_ON (!pdata->disable_count); + +if (--pdata->disable_count !=0 ) +return ; + + base =dfl_get_feature_ioaddr_by_id (&pdev->dev,PORT_FEATURE_ID_HEADER ); + +/* Clear port soft reset */ + v =readq (base +PORT_HDR_CTRL ); + v &= ~PORT_CTRL_SFTRST ; +writeq (v, base +PORT_HDR_CTRL ); +} + +#define RST_POLL_INVL 10/* us */ +#define RST_POLL_TIMEOUT 1000/* us */ + +/** +* port_disable - disable a port +* @pdev: port platform device. +* +* Disable Port by setting the port soft reset bit, it puts the port into +* reset. +*/ +static int port_disable (struct platform_device *pdev) +{ +struct dfl_feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +void __iomem *base; +u64 v; + +if (pdata->disable_count++ !=0 ) +return 0 ; + + base =dfl_get_feature_ioaddr_by_id (&pdev->dev,PORT_FEATURE_ID_HEADER ); + +/* Set port soft reset */ + v =readq (base +PORT_HDR_CTRL ); + v |=PORT_CTRL_SFTRST ; +writeq (v, base +PORT_HDR_CTRL ); + +/* +* HW sets ack bit to 1 when all outstanding requests have been drained +* on this port and minimum soft reset pulse width has elapsed. +* Driver polls port_soft_reset_ack to determine if reset done by HW. +*/ +if (readq_poll_timeout (base +PORT_HDR_CTRL , v, v &PORT_CTRL_SFTRST , +RST_POLL_INVL ,RST_POLL_TIMEOUT )) { +dev_err (&pdev->dev,"timeout, fail to reset device\n" ); +return -ETIMEDOUT ; + } + +return 0 ; +} + +static int port_get_id (struct platform_device *pdev) +{ +void __iomem *base; + + base =dfl_get_feature_ioaddr_by_id (&pdev->dev,PORT_FEATURE_ID_HEADER ); + +return FIELD_GET (PORT_CAP_PORT_NUM ,readq (base +PORT_HDR_CAP )); +} +static int port_hdr_init (struct platform_device *pdev,struct dfl_feature *feature) {
@@ -119,6 +196,28 @@ static long afu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) .unlocked_ioctl = afu_ioctl, }; +static int port_enable_set (struct platform_device *pdev,bool enable) +{ +struct dfl_feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +int ret =0 ; + +mutex_lock (&pdata->lock); +if (enable) +port_enable (pdev); +else + ret =port_disable (pdev); +mutex_unlock (&pdata->lock); + +return ret; +} + +static struct dfl_fpga_port_ops afu_port_ops = { + .name =DFL_FPGA_FEATURE_DEV_PORT , + .owner =THIS_MODULE , + .get_id = port_get_id, + .enable_set = port_enable_set, +}; +static int afu_probe (struct platform_device *pdev) {int ret;
@@ -154,7 +253,28 @@ static int afu_remove(struct platform_device *pdev) .remove = afu_remove, }; -module_platform_driver (afu_driver); +static int __init afu_init (void ) +{ +int ret; + +dfl_fpga_port_ops_add (&afu_port_ops); + + ret =platform_driver_register (&afu_driver); +if (ret) +dfl_fpga_port_ops_del (&afu_port_ops); + +return ret; +} + +static void __exit afu_exit(void) +{ +platform_driver_unregister (&afu_driver); + +dfl_fpga_port_ops_del (&afu_port_ops); +} + +module_init (afu_init); +module_exit (afu_exit);MODULE_DESCRIPTION ("FPGA Accelerated Function Unit driver" );MODULE_AUTHOR ("Intel Corporation" );
Signature · 1 line
1.8.3.1
PATCH v6 25/29 fpga: dfl: afu: add header sub feature support
In reply to Wu HaoThe port header register set is always present for port, it is mainly for capability, control and status of the ports that AFU connected to.
This patch implements header sub feature support. Below user interfaces are created by this patch.
Sysfs interface:
* /sys/class/fpga_region/<regionX>/<dfl-port.x>/id Read-only. Port ID.
Ioctl interface:
* DFL_FPGA_PORT_RESET
Reset the FPGA Port and its AFU.
---
v3: rename driver name to fpga-dfl-afu
add more description for reset ioctl.
fix some checkpatch issues.
v4: rebase.
add Acked-by from Alan.
v5: rebase, and merge port functions from DFL framework code.
add DFL_ prefix to APIs.
v6: rebase.
--- Documentation/ABI/testing/sysfs-platform-dfl-port | 7 ++ drivers/fpga/dfl-afu-main.c | 79 ++++++++++++++++++++++- include/uapi/linux/fpga-dfl.h | 17 +++++ 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-platform-dfl-port
Documentation/ABI/testing/sysfs-platform-dfl-port new file +7 -0
@@ -0,0 +1,7 @@ +What: /sys/bus/platform/devices/dfl-port.0/id +Date: June 2018 +KernelVersion: 4.18 +Contact: Wu Hao <[email protected]> +Description: Read-only. It returns id of this port. One DFL FPGA device + may have more than one port. Userspace could use this id to + distinguish different ports under same FPGA device.
drivers/fpga/dfl-afu-main.c +78 -1
119 lines not on this page · raw message
include/uapi/linux/fpga-dfl.h +17 -0
@@ -28,8 +28,11 @@#define DFL_FPGA_MAGIC 0xB6#define DFL_FPGA_BASE 0 +#define DFL_PORT_BASE 0x40#define DFL_FME_BASE 0x80 +/* Common IOCTLs for both FME and AFU file descriptor */ +/** * DFL_FPGA_GET_API_VERSION - _IO(DFL_FPGA_MAGIC, DFL_FPGA_BASE + 0) *
@@ -48,6 +51,20 @@#define DFL_FPGA_CHECK_EXTENSION _IO(DFL_FPGA_MAGIC, DFL_FPGA_BASE + 1) +/* IOCTLs for AFU file descriptor */ + +/** +* DFL_FPGA_PORT_RESET - _IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 0) +* +* Reset the FPGA Port and its AFU. No parameters are supported. +* Userspace can do Port reset at any time, e.g during DMA or PR. But +* it should never cause any system level issue, only functional failure +* (e.g DMA or PR operation failure) and be recoverable from the failure. +* Return: 0 on success, -errno of failure +*/ + +#define DFL_FPGA_PORT_RESET _IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 0) +/* IOCTLs for FME file descriptor */ /**
Signature · 1 line
1.8.3.1
PATCH v6 26/29 fpga: dfl: afu: add DFL_FPGA_GET_API_VERSION/CHECK_EXTENSION ioctls support
In reply to Wu HaoDFL_FPGA_GET_API_VERSION and DFL_FPGA_CHECK_EXTENSION ioctls are common ones which need to be supported by all feature devices drivers including FME and AFU. This patch implements above 2 ioctls in FPGA Accelerated Function Unit (AFU) driver.
---
v2: rebased
v3: rebased as driver renamed to fpga-dfl-afu
fix one checkpatch issue
v4: add Acked-by from Alan and Moritz.
v5: rebase, and add DFL_ prefix to APIs.
v6: rebase.
--- drivers/fpga/dfl-afu-main.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/fpga/dfl-afu-main.c +11 -0
@@ -236,6 +236,13 @@ static int afu_release(struct inode *inode, struct file *filp)return 0 ; } +static long afu_ioctl_check_extension (struct dfl_feature_platform_data *pdata, +unsigned long arg) +{ +/* No extension support for now */ +return 0 ; +} +static long afu_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) {struct platform_device *pdev = filp->private_data;
@@ -248,6 +255,10 @@ static long afu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) pdata =dev_get_platdata (&pdev->dev);switch (cmd) { +case DFL_FPGA_GET_API_VERSION : +return DFL_FPGA_API_VERSION ; +case DFL_FPGA_CHECK_EXTENSION : +return afu_ioctl_check_extension (pdata, arg);default :/* * Let sub-feature's ioctl function to handle the cmd
Signature · 1 line
1.8.3.1
PATCH v6 27/29 fpga: dfl: afu: add afu sub feature support
In reply to Wu HaoFrom: Xiao Guangrong <[email protected]>
User Accelerated Function Unit sub feature exposes the MMIO region of the AFU. After valid PR bitstream is programmed and the port is enabled, then this MMIO region could be accessed.
This patch adds support to enumerate the AFU MMIO region and expose it to userspace via mmap file operation. Below interfaces are exposed to user:
Sysfs interface:
* /sys/class/fpga_region/<regionX>/<dfl-port.x>/afu_id Read-only. Indicate which PR bitstream is programmed to this AFU.
Ioctl interfaces:
* DFL_FPGA_PORT_GET_INFO
Provide info to userspace on the number of supported region. Only UAFU region is supported now.
* DFL_FPGA_PORT_GET_REGION_INFO
Provide region information, including access permission, region size, offset from the start of device fd.
---
v2: moved the code to drivers/fpga folder as suggested by Alan Tull.
switched to GPLv2 license.
fixed kbuild warnings.
v3: improved commit description and fixed coding style issues.
replaced fpga_pdata_to_pcidev with fpga_pdata_to_fpga_cdev
v4: rebase and fix SPDX license issue
v5: rebase, due to DFL framework naming changes.
add DFL_ prefix to IOCTL API.
remove "user" afu, and replace "green bitstream" terminology. add "mmio" to afu region functions and data structures.
v6: rebase, fix copyright time and add Acked-by Alan.
--- Documentation/ABI/testing/sysfs-platform-dfl-port | 9 + drivers/fpga/Makefile | 2 +- drivers/fpga/dfl-afu-main.c | 219 +++++++++++++++++++++- drivers/fpga/dfl-afu-region.c | 166 ++++++++++++++++ drivers/fpga/dfl-afu.h | 71 +++++++ include/uapi/linux/fpga-dfl.h | 48 +++++ 6 files changed, 508 insertions(+), 7 deletions(-) create mode 100644 drivers/fpga/dfl-afu-region.c create mode 100644 drivers/fpga/dfl-afu.h
Documentation/ABI/testing/sysfs-platform-dfl-port +9 -0
@@ -5,3 +5,12 @@ Contact: Wu Hao <[email protected]> Description: Read-only. It returns id of this port. One DFL FPGA device may have more than one port. Userspace could use this id to distinguish different ports under same FPGA device. + +What: /sys/bus/platform/devices/dfl-port.0/afu_id +Date: June 2018 +KernelVersion: 4.18 +Contact: Wu Hao <[email protected]> +Description: Read-only. User can program different PR bitstreams to FPGA + Accelerator Function Unit (AFU) for different functions. It + returns uuid which could be used to identify which PR bitstream + is programmed in this AFU.
drivers/fpga/Makefile +1 -1
@@ -38,7 +38,7 @@ obj-$(CONFIG_FPGA_DFL_FME_REGION) += dfl-fme-region.o obj-$(CONFIG_FPGA_DFL_AFU) += dfl-afu.o dfl-fme-objs := dfl-fme-main.o dfl-fme-pr.o -dfl-afu-objs := dfl-afu-main.o +dfl-afu-objs := dfl-afu-main.o dfl-afu-region.o # Drivers for FPGAs which implement DFL obj-$(CONFIG_FPGA_DFL_PCI) += dfl-pci.o
drivers/fpga/dfl-afu-main.c +213 -6
288 lines not on this page · raw message
drivers/fpga/dfl-afu-region.c new file +166 -0
166 lines not on this page · raw message
drivers/fpga/dfl-afu.h new file +71 -0
71 lines not on this page · raw message
include/uapi/linux/fpga-dfl.h +48 -0
54 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 28/29 fpga: dfl: afu: add DFL_FPGA_PORT_DMA_MAP/UNMAP ioctls support
In reply to Wu HaoDMA memory regions are required for Accelerated Function Unit (AFU) usage. These two ioctls allow user space applications to map user memory regions for dma, and unmap them after use. Iova is returned from driver to user space application via DFL_FPGA_PORT_DMA_MAP ioctl. Application needs to unmap it after use, otherwise, driver will unmap them in device file release operation.
Each AFU has its own rb tree to keep track of its mapped DMA regions.
Ioctl interfaces:
* DFL_FPGA_PORT_DMA_MAP
Do the dma mapping per user_addr and length which provided by user. Return iova in provided struct dfl_fpga_port_dma_map.
* DFL_FPGA_PORT_DMA_UNMAP
Unmap the dma region per iova provided by user.
---
v2: moved the code to drivers/fpga folder as suggested by Alan Tull.
switched to GPLv2 license.
fixed kbuild warnings.
v3: improved commit description and fixed coding style issues.
replaced fpga_pdata_to_pcidev with fpga_pdata_to_fpga_cdev
v4: rebase and fix SPDX license issue
v5: rebase, and add DFL_ prefix to IOCTL APIs.
v6: rebase, fix copyright time and add Acked-by from Alan.
--- drivers/fpga/Makefile | 2 +- drivers/fpga/dfl-afu-dma-region.c | 463 ++++++++++++++++++++++++++++++++++++++ drivers/fpga/dfl-afu-main.c | 61 ++++- drivers/fpga/dfl-afu.h | 31 ++- include/uapi/linux/fpga-dfl.h | 37 +++ 5 files changed, 591 insertions(+), 3 deletions(-) create mode 100644 drivers/fpga/dfl-afu-dma-region.c
drivers/fpga/Makefile +1 -1
@@ -38,7 +38,7 @@ obj-$(CONFIG_FPGA_DFL_FME_REGION) += dfl-fme-region.o obj-$(CONFIG_FPGA_DFL_AFU) += dfl-afu.o dfl-fme-objs := dfl-fme-main.o dfl-fme-pr.o -dfl-afu-objs := dfl-afu-main.o dfl-afu-region.o +dfl-afu-objs := dfl-afu-main.o dfl-afu-region.o dfl-afu-dma-region.o # Drivers for FPGAs which implement DFL obj-$(CONFIG_FPGA_DFL_PCI) += dfl-pci.o
drivers/fpga/dfl-afu-dma-region.c new file +463 -0
463 lines not on this page · raw message
drivers/fpga/dfl-afu-main.c +60 -1
91 lines not on this page · raw message
drivers/fpga/dfl-afu.h +30 -1
@@ -41,11 +41,31 @@ struct dfl_afu_mmio_region { };/** +* struct fpga_afu_dma_region - afu DMA region data structure +* +* @user_addr: region userspace virtual address. +* @length: region length. +* @iova: region IO virtual address. +* @pages: ptr to pages of this region. +* @node: rb tree node. +* @in_use: flag to indicate if this region is in_use. +*/ +struct dfl_afu_dma_region { +u64 user_addr; +u64 length; +u64 iova; +struct page **pages; +struct rb_node node; +bool in_use; +}; + +/** * struct dfl_afu - afu device data structure * * @region_cur_offset: current region offset from start to the device fd. * @num_regions: num of mmio regions. * @regions: the mmio region link list of this afu feature device. +* @dma_regions: root of dma regions rb tree. * @num_umsgs: num of umsgs. * @pdata: afu platform device's pdata. */
@@ -54,6 +74,7 @@ struct dfl_afu {int num_regions;u8 num_umsgs;struct list_head regions; +struct rb_root dma_regions;struct dfl_feature_platform_data *pdata; };
@@ -68,4 +89,12 @@ int afu_mmio_region_get_by_index(struct dfl_feature_platform_data *pdata,int afu_mmio_region_get_by_offset (struct dfl_feature_platform_data *pdata,u64 offset,u64 size,struct dfl_afu_mmio_region *pregion); -#endif +void afu_dma_region_init (struct dfl_feature_platform_data *pdata); +void afu_dma_region_destroy (struct dfl_feature_platform_data *pdata); +int afu_dma_map_region (struct dfl_feature_platform_data *pdata, +u64 user_addr,u64 length,u64 *iova); +int afu_dma_unmap_region (struct dfl_feature_platform_data *pdata,u64 iova); +struct dfl_afu_dma_region * +afu_dma_region_find (struct dfl_feature_platform_data *pdata, +u64 iova,u64 size); +#endif /* __DFL_AFU_H */
include/uapi/linux/fpga-dfl.h +37 -0
@@ -113,6 +113,43 @@ struct dfl_fpga_port_region_info {#define DFL_FPGA_PORT_GET_REGION_INFO _IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 2) +/** +* DFL_FPGA_PORT_DMA_MAP - _IOWR(DFL_FPGA_MAGIC, DFL_PORT_BASE + 3, +* struct dfl_fpga_port_dma_map) +* +* Map the dma memory per user_addr and length which are provided by caller. +* Driver fills the iova in provided struct afu_port_dma_map. +* This interface only accepts page-size aligned user memory for dma mapping. +* Return: 0 on success, -errno on failure. +*/ +struct dfl_fpga_port_dma_map { +/* Input */ +__u32 argsz;/* Structure length */ +__u32 flags;/* Zero for now */ +__u64 user_addr;/* Process virtual address */ +__u64 length;/* Length of mapping (bytes)*/ +/* Output */ +__u64 iova;/* IO virtual address */ +}; + +#define DFL_FPGA_PORT_DMA_MAP _IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 3) + +/** +* DFL_FPGA_PORT_DMA_UNMAP - _IOW(FPGA_MAGIC, PORT_BASE + 4, +* struct dfl_fpga_port_dma_unmap) +* +* Unmap the dma memory per iova provided by caller. +* Return: 0 on success, -errno on failure. +*/ +struct dfl_fpga_port_dma_unmap { +/* Input */ +__u32 argsz;/* Structure length */ +__u32 flags;/* Zero for now */ +__u64 iova;/* IO virtual address */ +}; + +#define DFL_FPGA_PORT_DMA_UNMAP _IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 4) +/* IOCTLs for FME file descriptor */ /**
Signature · 1 line
1.8.3.1
PATCH v6 29/29 MAINTAINERS: add entry for FPGA DFL drivers
In reply to Wu HaoAdd entry for FPGA Device Feature List (DFL) drivers.
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -5619,6 +5619,14 @@ F: drivers/fpga/ F: include/linux/fpga/ W: http://www.rocketboards.org +FPGA DFL DRIVERS +M: Wu Hao <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/fpga/dfl.txt +F: include/uapi/linux/fpga-dfl.h +F: drivers/fpga/dfl* + FPU EMULATOR M: Bill Metzenthen <[email protected]> W: http://floatingpoint.sourceforge.net/emulator/index.html
Signature · 1 line
1.8.3.1
Randy Dunlap
reviewerRe: [PATCH v6 06/29] fpga: add device feature list support
In reply to Wu HaoHi,
Quoted 6 lines · Wu Hao
drivers/fpga/Kconfig +0
-0
drivers/fpga/Kconfig config OF_FPGA_REGION · line 139
Quoted 10 lines
drivers/fpga/Kconfig +7
-0@@ -130,4 +130,20 @@ config OF_FPGA_REGION Support for loading FPGA images by applying a Device Tree overlay. +config FPGA_DFL + tristate "FPGA Device Feature List (DFL) support" + select FPGA_BRIDGE + select FPGA_REGION + help + Device Feature List (DFL) defines a feature list structure that + creates a link list of feature headers within the MMIO space
a linked list
drivers/fpga/Kconfig config OF_FPGA_REGION · line 142
Quoted 3 lines
drivers/fpga/Kconfig +3
-0+ to provide an extensible way of adding features for FPGA. + Driver can walk through the feature headers to enumerate feature + devices (e.g FPGA Management Engine, Port and Accelerator
(e.g.
drivers/fpga/Kconfig config OF_FPGA_REGION · line 147
Quoted 5 lines
drivers/fpga/Kconfig +5
-0+ Function Unit) and their private features for target FPGA devices. + + Select this option to enable common support for Field-Programmable + Gate Array (FPGA) solutions which implement Device Feature List. + It provides enumeration APIs, and feature device infrastructure.
^no comma
Quoted 2 lines
drivers/fpga/Kconfig +1
-0+ endif # FPGA
Signature · 1 line
~Randy
Randy Dunlap
reviewerPATCH v6 12/29 fpga: add FPGA DFL PCIe device driver
In reply to Wu HaoHi,
Quoted 7 lines · Wu Hao
From: Zhang Yi <[email protected]>
drivers/fpga/Kconfig +0
-0
drivers/fpga/Kconfig config FPGA_DFL · line 153
Quoted 8 lines
drivers/fpga/Kconfig +5
-0@@ -146,4 +146,19 @@ config FPGA_DFL Gate Array (FPGA) solutions which implement Device Feature List. It provides enumeration APIs, and feature device infrastructure. +config FPGA_DFL_PCI + tristate "FPGA DFL PCIe Device Driver" + depends on PCI && FPGA_DFL + help + Select this option to enable PCIe driver for PCIe based
PCIe-based
drivers/fpga/Kconfig config FPGA_DFL · line 154
Quoted 1 line
drivers/fpga/Kconfig +1
-0+ Field-Programmable Gate Array (FPGA) solutions which implemented
which implement
Quoted 10 lines
drivers/fpga/Kconfig +9
-0+ the Device Feature List (DFL). This driver provides interfaces + for userspace applications to configure, enumerate, open and access + FPGA accelerators on the FPGA DFL devices, enables system level + management functions such as FPGA partial reconfiguration, power + management, and virtualization with DFL framework and DFL feature + device drivers. + + To compile this as a module, choose M here. + endif # FPGA
Signature · 1 line
~Randy
Randy Dunlap
reviewerPATCH v6 14/29 fpga: dfl: add FPGA Management Engine driver basic framework
In reply to Wu HaoHi,
Quoted 9 lines · Wu Hao
From: Kang Luwei <[email protected]>
drivers/fpga/Kconfig +0
-0@@ -146,6 +146,16 @@ config FPGA_DFL Gate Array (FPGA) solutions which implement Device Feature List.
drivers/fpga/Kconfig config FPGA_DFL · line 156
Quoted 10 lines
drivers/fpga/Kconfig +8
-0It provides enumeration APIs, and feature device infrastructure. +config FPGA_DFL_FME + tristate "FPGA DFL FME Driver" + depends on FPGA_DFL + help + The FPGA Management Engine (FME) is a feature device implemented + under Device Feature List (DFL) framework. Select this option to + enable the platform device driver for FME which implements all + FPGA platform level management features. There shall be 1 FME
better:
be one FME
Quoted 5 lines
drivers/fpga/Kconfig +2
-0+ per DFL based FPGA device. + config FPGA_DFL_PCI tristate "FPGA DFL PCIe Device Driver" depends on PCI && FPGA_DFL
Signature · 1 line
~Randy
Randy Dunlap
reviewerPATCH v6 23/29 fpga: dfl: add FPGA Accelerated Function Unit driver basic framework
In reply to Wu HaoHi,
Quoted 6 lines · Wu Hao
drivers/fpga/Kconfig +0
-0
drivers/fpga/Kconfig config FPGA_DFL_FME_REGION · line 183
Quoted 10 lines
drivers/fpga/Kconfig +7
-0@@ -174,6 +174,15 @@ config FPGA_DFL_FME_REGION help Say Y to enable FPGA Region driver for FPGA Management Engine. +config FPGA_DFL_AFU + tristate "FPGA DFL AFU Driver" + depends on FPGA_DFL + help + This is the driver for FPGA Accelerated Function Unit (AFU) which + implements AFU and Port management features. A User AFU connects + to the FPGA infrastructure via a Port. There may be more than 1
better:
more than one
Quoted 5 lines
drivers/fpga/Kconfig +2
-0+ Port/AFU per DFL based FPGA device. + config FPGA_DFL_PCI tristate "FPGA DFL PCIe Device Driver" depends on PCI && FPGA_DFL
Signature · 1 line
~Randy
Re: [PATCH v6 06/29] fpga: add device feature list support
In reply to Wu HaoQuoted 34 lines · Wu Hao
Device Feature List (DFL) defines a feature list structure that creates a link list of feature headers within the MMIO space to provide an extensible way of adding features. This patch introduces a kernel module to provide basic infrastructure to support FPGA devices which implement the Device Feature List.
Usually there will be different features and their sub features linked into the DFL. This code provides common APIs for feature enumeration, it creates a container device (FPGA base region), walks through the DFLs and creates platform devices for feature devices (Currently it only supports two different feature devices, FPGA Management Engine (FME) and Port which the Accelerator Function Unit (AFU) connected to). In order to enumerate the DFLs, the common APIs required low level driver to provide necessary enumeration information (e.g address for each device feature list for given device) and fill it to the
dfl_fpga_enum_infodata structure. Please refer to below description for APIs added for enumeration.Functions for enumeration information preparation:
*dfl_fpga_enum_info_alloc
allocate enumeration information data structure.
*dfl_fpga_enum_info_add_dfl
add a device feature list todfl_fpga_enum_infodata structure.
*dfl_fpga_enum_info_free
freedfl_fpga_enum_infodata structure and related resources.Functions for feature device enumeration:
*dfl_fpga_feature_devs_enumerate
enumerate feature devices and return container device.
*dfl_fpga_feature_devs_remove
remove feature devices under given container device.
Quoted 7 lines
Signed-off-by Tim Whisonant <[email protected]>Signed-off-by Enno Luebbers <[email protected]>Signed-off-by Shiva Rao <[email protected]>Signed-off-by Christopher Rauer <[email protected]>Signed-off-by Zhang Yi <[email protected]>Signed-off-by Xiao Guangrong <[email protected]>Signed-off-by Wu Hao <[email protected]>
Quoted 22 lines
---
v3: split from another patch.
separate dfl enumeration code from original pcie driver. provide common data structures and APIs for enumeration. update device feature list parsing process according to latest hw. add dperf/iperf/hssi sub feature placeholder according to latest hw. removebuild_info_add_sub_featureand other small functions. replace*_feature_numfunction with macro.
remove writeq/readq.
v4: fix SPDX license issue
rename files to dfl.[ch], fix typo and add more comments. remove staticfeature_infotables for FME and Port. remove check onnext_afulink list as only FIU hasnext_afuptr. remove unused macro in header file.
add more comments for functions.
v5: add "dfl_" prefix to functions and data structures.
remove port related functions from DFL framework.
useBIT_ULLfor 64bit register definition.
savedfl_fpga_cdevin pdata for feature platform devices. rebase due to fpga region api changes.
v6: update time in copyright and improve function name.
introducedfl_devstable to save feature device info.
Re: [PATCH v6 07/29] fpga: dfl: add chardev support for feature devices
In reply to Wu HaoQuoted 8 lines · Wu Hao
For feature devices drivers, both the FPGA Management Engine (FME) and Accelerated Function Unit (AFU) driver need to expose user interfaces via the device file, for example, mmap and ioctls.
This patch adds chardev support in the dfl driver for feature devices, FME and AFU. It reserves the chardev regions for FME and AFU, and provide interfaces for FME and AFU driver to register their device file operations.
Quoted 7 lines
Signed-off-by Tim Whisonant <[email protected]>Signed-off-by Enno Luebbers <[email protected]>Signed-off-by Shiva Rao <[email protected]>Signed-off-by Christopher Rauer <[email protected]>Signed-off-by Zhang Yi <[email protected]>Signed-off-by Xiao Guangrong <[email protected]>Signed-off-by Wu Hao <[email protected]>
Quoted 7 lines
---
v2: rebased
v3: move chardev support to fpga-dfl framework
v4: rebase, and add more comments in code.
v5: rebase, and adddfl_prefix to APIs and data structures.
v6: add index indfl_devsto link todfl_chrdevs.
improve naming on APIs.
Re: [PATCH v6 03/29] fpga: mgr: add status for fpga-manager
In reply to Wu HaoOn Tue, Jun 12, 2018 at 5:10 AM, Wu Hao <[email protected]> wrote:
Hi Hao,
Quoted 10 lines
Documentation/ABI/testing/sysfs-class-fpga-manager | 24 +++++++++++++++++++ drivers/fpga/fpga-mgr.c | 28 ++++++++++++++++++++++ include/linux/fpga/fpga-mgr.h | 9 +++++++ 3 files changed, 61 insertions(+)Documentation/ABI/testing/sysfs-class-fpga-manager +0
-0
Documentation/ABI/testing/sysfs-class-fpga-manager Description: Read fpga manager state as a string. · line 41
Quoted 7 lines
Documentation/ABI/testing/sysfs-class-fpga-manager +4
-0@@ -35,3 +35,27 @@ Description: Read fpga manager state as a string. * write complete = Doing post programming steps * write complete error = Error while doing post programming * operating = FPGA is programmed and operating + +What: /sys/class/fpga_manager/<fpga>/status +Date: June 2018 +KernelVersion: 4.18
4.19
Greg is queuing new functionality for 4.19 after 4.18-rc1 is done.
Quoted 2 lines
Documentation/ABI/testing/sysfs-class-fpga-manager +2
-0+Contact: Wu Hao <[email protected]> +Description: Read fpga manager status as a string.
Quoted 3 lines · Wu Hao
Hi All,
Here is v6 patch-series adding drivers for FPGA DFL devices.
I pushed this patchset to a branch on my linux-fpga kernel.org git repo for the robots to test.
Alan
Quoted 7 lines
This patch series provides a common framework to support FPGA Device Feature List (DFL), and also feature dev drivers under this DFL framework to provide interfaces for userspace applications to configure, enumerate, open, and access FPGA accelerators on DFL based FPGA device and enables system level management functions such as FPGA partial reconfiguration, power management and virtualization.
Quoted 7 lines · Alan Tull
Quoted 3 lines · Wu Hao
Hi All,
Here is v6 patch-series adding drivers for FPGA DFL devices.
I pushed this patchset to a branch on my linux-fpga kernel.org git repo for the robots to test.
Hi Alan
Thanks a lot for review, will update target kernel version to 4.19 in sysfs documentation, fix Kconfig description per comments from Randy and also one improvement reported by kbuild in v7.
Thanks
Hao
Quoted 10 lines
Alan
Quoted 7 lines
This patch series provides a common framework to support FPGA Device Feature List (DFL), and also feature dev drivers under this DFL framework to provide interfaces for userspace applications to configure, enumerate, open, and access FPGA accelerators on DFL based FPGA device and enables system level management functions such as FPGA partial reconfiguration, power management and virtualization.
Re: [PATCH v6 12/29] fpga: add FPGA DFL PCIe device driver
In reply to Randy DunlapQuoted 21 lines · Randy Dunlap
Hi,
Quoted 7 lines · Wu Hao
From: Zhang Yi <[email protected]>
drivers/fpga/Kconfig +0
-0drivers/fpga/Kconfig config FPGA_DFL · line 153
Quoted 8 lines
drivers/fpga/Kconfig +5
-0@@ -146,4 +146,19 @@ config FPGA_DFL Gate Array (FPGA) solutions which implement Device Feature List. It provides enumeration APIs, and feature device infrastructure. +config FPGA_DFL_PCI + tristate "FPGA DFL PCIe Device Driver" + depends on PCI && FPGA_DFL + help + Select this option to enable PCIe driver for PCIe basedPCIe-based
Quoted 3 lines
drivers/fpga/Kconfig config FPGA_DFL · line 154
Quoted 1 line
drivers/fpga/Kconfig +1
-0+ Field-Programmable Gate Array (FPGA) solutions which implementedwhich implement
Hi Randy
Thanks for the comments on these patches, I will fix them all in the next version.
Hao
Quoted 15 lines
Quoted 11 lines
drivers/fpga/Kconfig +9
-0+ the Device Feature List (DFL). This driver provides interfaces + for userspace applications to configure, enumerate, open and access + FPGA accelerators on the FPGA DFL devices, enables system level + management functions such as FPGA partial reconfiguration, power + management, and virtualization with DFL framework and DFL feature + device drivers. + + To compile this as a module, choose M here. + endif # FPGASignature · 1 line
~Randy
Re: [PATCH v6 29/29] MAINTAINERS: add entry for FPGA DFL drivers
In reply to Wu HaoQuoted 3 lines · Wu Hao
Add entry for FPGA Device Feature List (DFL) drivers.
Signed-off-by Wu Hao <[email protected]>
Quoted 26 lines
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)MAINTAINERS +8
-1@@ -5619,6 +5619,14 @@ F: drivers/fpga/ F: include/linux/fpga/ W: http://www.rocketboards.org +FPGA DFL DRIVERS +M: Wu Hao <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/fpga/dfl.txt +F: include/uapi/linux/fpga-dfl.h +F: drivers/fpga/dfl* + FPU EMULATOR M: Bill Metzenthen <[email protected]> W: http://floatingpoint.sourceforge.net/emulator/index.html --1.8.3.1
Re: [PATCH v6 29/29] MAINTAINERS: add entry for FPGA DFL drivers
In reply to Wu HaoQuoted 3 lines · Wu Hao
Add entry for FPGA Device Feature List (DFL) drivers.
Signed-off-by Wu Hao <[email protected]>
Quoted 26 lines
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)MAINTAINERS +8
-0@@ -5619,6 +5619,14 @@ F: drivers/fpga/ F: include/linux/fpga/ W: http://www.rocketboards.org +FPGA DFL DRIVERS +M: Wu Hao <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/fpga/dfl.txt +F: include/uapi/linux/fpga-dfl.h +F: drivers/fpga/dfl* + FPU EMULATOR M: Bill Metzenthen <[email protected]> W: http://floatingpoint.sourceforge.net/emulator/index.htmlSignature · 1 line
1.8.3.1
Thanks,
Moritz
Moritz Fischer
maintainerRe: [PATCH v6 12/29] fpga: add FPGA DFL PCIe device driver
In reply to Wu HaoQuoted 122 lines · Wu Hao
From: Zhang Yi <[email protected]>
This patch implements the basic framework of the driver for FPGA PCIe device which implements the Device Feature List (DFL) in its MMIO space. This driver is verified on Intel(R) PCIe based FPGA DFL devices, including both integrated (e.g Intel Server Platform with In-package FPGA) and discrete (e.g Intel FPGA PCIe Acceleration Cards) solutions.
Signed-off-by Tim Whisonant <[email protected]>Signed-off-by Enno Luebbers <[email protected]>Signed-off-by Shiva Rao <[email protected]>Signed-off-by Christopher Rauer <[email protected]>Signed-off-by Zhang Yi <[email protected]>Signed-off-by Xiao Guangrong <[email protected]>Signed-off-by Wu Hao <[email protected]>Acked-by Alan Tull <[email protected]>Acked-by Moritz Fischer <[email protected]>---
v2: move the code todrivers/fpgafolder as suggested by Alan Tull.
switch to GPLv2 license.
fix comments from Moritz Fischer.
v3: switch to pci_set_dma_mask/consistent_dma_mask() function.
removepci_save_state()in probe function.
rename driver toINTEL_FPGA_DFL_PCIandintel-dfl-pci.cto indicate this driver supports Intel FPGA PCI devices which implement DFL. improveKconfigdescription forINTEL_FPGA_DFL_PCI
v4: rename toFPGA_DFL_PCI(dfl-pci.c) for better reuse.
fix SPDX license issue.
v5: usemodule_pci_driver()instead.
add Acked-by from Alan and Moritz.
v6: rebase and unify naming inKconfig--- drivers/fpga/Kconfig | 15 +++++++ drivers/fpga/Makefile | 3 ++ drivers/fpga/dfl-pci.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 drivers/fpga/dfl-pci.cdrivers/fpga/Kconfig +15
-0@@ -146,4 +146,19 @@ config FPGA_DFL Gate Array (FPGA) solutions which implement Device Feature List. It provides enumeration APIs, and feature device infrastructure. +config FPGA_DFL_PCI + tristate "FPGA DFL PCIe Device Driver" + depends on PCI && FPGA_DFL + help + Select this option to enable PCIe driver for PCIe based + Field-Programmable Gate Array (FPGA) solutions which implemented + the Device Feature List (DFL). This driver provides interfaces + for userspace applications to configure, enumerate, open and access + FPGA accelerators on the FPGA DFL devices, enables system level + management functions such as FPGA partial reconfiguration, power + management, and virtualization with DFL framework and DFL feature + device drivers. + + To compile this as a module, choose M here. + endif # FPGAdrivers/fpga/Makefile +3
-0@@ -31,3 +31,6 @@ obj-$(CONFIG_OF_FPGA_REGION) += of-fpga-region.o # FPGA Device Feature List Support obj-$(CONFIG_FPGA_DFL) += dfl.o + +# Drivers for FPGAs which implement DFL +obj-$(CONFIG_FPGA_DFL_PCI) += dfl-pci.odrivers/fpga/dfl-pci.c new file +43
-0@@ -0,0 +1,114 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Driver for FPGA Device Feature List (DFL) PCIe device +* +* Copyright (C) 2017-2018 Intel Corporation, Inc. +* +* Authors: +* Zhang Yi <[email protected]> +* Xiao Guangrong <[email protected]> +* Joseph Grecco <[email protected]> +* Enno Luebbers <[email protected]> +* Tim Whisonant <[email protected]> +* Ananda Ravuri <[email protected]> +* Henry Mitchel <[email protected]> +*/ + +#include <linux/pci.h> +#include <linux/types.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/stddef.h> +#include <linux/errno.h> +#include <linux/aer.h> + +#define DRV_VERSION "0.8" +#define DRV_NAME "dfl-pci" + +/* PCI Device ID */ +#define PCIE_DEVICE_ID_PF_INT_5_X 0xBCBD +#define PCIE_DEVICE_ID_PF_INT_6_X 0xBCC0 +#define PCIE_DEVICE_ID_PF_DSC_1_X 0x09C4 +/* VF Device */ +#define PCIE_DEVICE_ID_VF_INT_5_X 0xBCBF +#define PCIE_DEVICE_ID_VF_INT_6_X 0xBCC1 +#define PCIE_DEVICE_ID_VF_DSC_1_X 0x09C5 + +static struct pci_device_id cci_pcie_id_tbl[] = { + {PCI_DEVICE (PCI_VENDOR_ID_INTEL ,PCIE_DEVICE_ID_PF_INT_5_X ),}, + {PCI_DEVICE (PCI_VENDOR_ID_INTEL ,PCIE_DEVICE_ID_VF_INT_5_X ),}, + {PCI_DEVICE (PCI_VENDOR_ID_INTEL ,PCIE_DEVICE_ID_PF_INT_6_X ),}, + {PCI_DEVICE (PCI_VENDOR_ID_INTEL ,PCIE_DEVICE_ID_VF_INT_6_X ),}, + {PCI_DEVICE (PCI_VENDOR_ID_INTEL ,PCIE_DEVICE_ID_PF_DSC_1_X ),}, + {PCI_DEVICE (PCI_VENDOR_ID_INTEL ,PCIE_DEVICE_ID_VF_DSC_1_X ),},
drivers/fpga/dfl-pci.c line 53
Quoted 10 lines
drivers/fpga/dfl-pci.c new file +10
-0+ {0,} +}; +MODULE_DEVICE_TABLE (pci, cci_pcie_id_tbl); + +static +int cci_pci_probe (struct pci_dev *pcidev,const struct pci_device_id *pcidevid) +{ +int ret; + + ret =pci_enable_device (pcidev);
Any reason we cannot use pcim_enable_device() here?
Quoted 64 lines
drivers/fpga/dfl-pci.c new file +61
-0+if (ret <0 ) { +dev_err (&pcidev->dev,"Failed to enable device %d.\n" , ret); +return ret; + } + + ret =pci_enable_pcie_error_reporting (pcidev); +if (ret && ret != -EINVAL ) +dev_info (&pcidev->dev,"PCIE AER unavailable %d.\n" , ret); + + ret =pci_request_regions (pcidev,DRV_NAME ); +if (ret) { +dev_err (&pcidev->dev,"Failed to request regions.\n" ); + goto disable_error_report_exit; + } + +pci_set_master (pcidev); + +if (!pci_set_dma_mask (pcidev,DMA_BIT_MASK (64 ))) { + ret =pci_set_consistent_dma_mask (pcidev,DMA_BIT_MASK (64 )); +if (ret) + goto release_region_exit; + }else if (!pci_set_dma_mask (pcidev,DMA_BIT_MASK (32 ))) { + ret =pci_set_consistent_dma_mask (pcidev,DMA_BIT_MASK (32 )); +if (ret) + goto release_region_exit; + }else { + ret = -EIO ; +dev_err (&pcidev->dev,"No suitable DMA support available.\n" ); + goto release_region_exit; + } + +/* TODO: create and add the platform device per feature list */ +return 0 ; + +release_region_exit: +pci_release_regions (pcidev); +disable_error_report_exit: +pci_disable_pcie_error_reporting (pcidev); +pci_disable_device (pcidev); +return ret; +} + +static void cci_pci_remove (struct pci_dev *pcidev) +{ +pci_release_regions (pcidev); +pci_disable_pcie_error_reporting (pcidev); +pci_disable_device (pcidev); +} + +static struct pci_driver cci_pci_driver = { + .name =DRV_NAME , + .id_table = cci_pcie_id_tbl, + .probe = cci_pci_probe, + .remove = cci_pci_remove, +}; + +module_pci_driver (cci_pci_driver); + +MODULE_DESCRIPTION ("FPGA DFL PCIe Device Driver" ); +MODULE_AUTHOR ("Intel Corporation" ); +MODULE_LICENSE ("GPL v2" );Signature · 1 line
1.8.3.1
Cheers,
Moritz
Re: [PATCH v6 14/29] fpga: dfl: add FPGA Management Engine driver basic framework
In reply to Wu HaoQuoted 12 lines · Wu Hao
From: Kang Luwei <[email protected]>
The FPGA Management Engine (FME) provides power, thermal management, performance counters, partial reconfiguration and other functions. For each function, it is packaged into a private feature linked to the FME feature device in the 'Device Feature List'. It's a platform device created by DFL framework.
This patch adds the basic framework of FME platform driver. It defines sub feature drivers to handle the different sub features, including init, uinit and ioctl. It also registers the file operations for the device file.
Quoted 8 lines
Signed-off-by Tim Whisonant <[email protected]>Signed-off-by Enno Luebbers <[email protected]>Signed-off-by Shiva Rao <[email protected]>Signed-off-by Christopher Rauer <[email protected]>Signed-off-by Kang Luwei <[email protected]>Signed-off-by Xiao Guangrong <[email protected]>Signed-off-by Wu Hao <[email protected]>Acked-by Alan Tull <[email protected]>
Quoted 217 lines
---
v3: rename driver from intel-fpga-fme to dfl-fme
renameKconfigfromINTEL_FPGA_FMEtoFPGA_DFL_FME
v4: fix SPDX license issue, use dfl-fme as module name
v5: rebase, due to DFL framework naming changes on functions and data structures.
fix uinit order in remove function.
remove else block infme_ioctlfunction per suggestion from Alan.
v6: fix copyright time, rebase and add Acked-by from Alan.--- drivers/fpga/Kconfig | 10 +++ drivers/fpga/Makefile | 3 + drivers/fpga/dfl-fme-main.c | 158 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 171 insertions(+) create mode 100644 drivers/fpga/dfl-fme-main.cdrivers/fpga/Kconfig +10
-0@@ -146,6 +146,16 @@ config FPGA_DFL Gate Array (FPGA) solutions which implement Device Feature List. It provides enumeration APIs, and feature device infrastructure. +config FPGA_DFL_FME + tristate "FPGA DFL FME Driver" + depends on FPGA_DFL + help + The FPGA Management Engine (FME) is a feature device implemented + under Device Feature List (DFL) framework. Select this option to + enable the platform device driver for FME which implements all + FPGA platform level management features. There shall be 1 FME + per DFL based FPGA device. + config FPGA_DFL_PCI tristate "FPGA DFL PCIe Device Driver" depends on PCI && FPGA_DFLdrivers/fpga/Makefile +3
-0@@ -31,6 +31,9 @@ obj-$(CONFIG_OF_FPGA_REGION) += of-fpga-region.o # FPGA Device Feature List Support obj-$(CONFIG_FPGA_DFL) += dfl.o +obj-$(CONFIG_FPGA_DFL_FME) += dfl-fme.o + +dfl-fme-objs := dfl-fme-main.o # Drivers for FPGAs which implement DFL obj-$(CONFIG_FPGA_DFL_PCI) += dfl-pci.odrivers/fpga/dfl-fme-main.c new file +158
-0@@ -0,0 +1,158 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Driver for FPGA Management Engine (FME) +* +* Copyright (C) 2017-2018 Intel Corporation, Inc. +* +* Authors: +* Kang Luwei <[email protected]> +* Xiao Guangrong <[email protected]> +* Joseph Grecco <[email protected]> +* Enno Luebbers <[email protected]> +* Tim Whisonant <[email protected]> +* Ananda Ravuri <[email protected]> +* Henry Mitchel <[email protected]> +*/ + +#include <linux/kernel.h> +#include <linux/module.h> + +#include "dfl.h" + +static int fme_hdr_init (struct platform_device *pdev, +struct dfl_feature *feature) +{ +dev_dbg (&pdev->dev,"FME HDR Init.\n" ); + +return 0 ; +} + +static void fme_hdr_uinit (struct platform_device *pdev, +struct dfl_feature *feature) +{ +dev_dbg (&pdev->dev,"FME HDR UInit.\n" ); +} + +static const struct dfl_feature_ops fme_hdr_ops = { + .init = fme_hdr_init, + .uinit = fme_hdr_uinit, +}; + +static struct dfl_feature_driver fme_feature_drvs[] = { + { + .id =FME_FEATURE_ID_HEADER , + .ops = &fme_hdr_ops, + }, + { + .ops =NULL , + }, +}; + +static int fme_open (struct inode *inode,struct file *filp) +{ +struct platform_device *fdev =dfl_fpga_inode_to_feature_dev (inode); +struct dfl_feature_platform_data *pdata =dev_get_platdata (&fdev->dev); +int ret; + +if (WARN_ON (!pdata)) +return -ENODEV ; + + ret =dfl_feature_dev_use_begin (pdata); +if (ret) +return ret; + +dev_dbg (&fdev->dev,"Device File Open\n" ); + filp->private_data = pdata; + +return 0 ; +} + +static int fme_release (struct inode *inode,struct file *filp) +{ +struct dfl_feature_platform_data *pdata = filp->private_data; +struct platform_device *pdev = pdata->dev; + +dev_dbg (&pdev->dev,"Device File Release\n" ); +dfl_feature_dev_use_end (pdata); + +return 0 ; +} + +static long fme_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) +{ +struct dfl_feature_platform_data *pdata = filp->private_data; +struct platform_device *pdev = pdata->dev; +struct dfl_feature *f; +long ret; + +dev_dbg (&pdev->dev,"%s cmd 0x%x\n" , __func__, cmd); + +switch (cmd) { +default : +/* +* Let sub-feature's ioctl function to handle the cmd +* Sub-feature's ioctl returns -ENODEV when cmd is not +* handled in this sub feature, and returns 0 and other +* error code if cmd is handled. +*/ +dfl_fpga_dev_for_each_feature (pdata, f) { +if (f->ops && f->ops->ioctl) { + ret = f->ops->ioctl (pdev, f, cmd, arg); +if (ret != -ENODEV ) +return ret; + } + } + } + +return -EINVAL ; +} + +static const struct file_operations fme_fops = { + .owner =THIS_MODULE , + .open = fme_open, + .release = fme_release, + .unlocked_ioctl = fme_ioctl, +}; + +static int fme_probe (struct platform_device *pdev) +{ +int ret; + + ret =dfl_fpga_dev_feature_init (pdev, fme_feature_drvs); +if (ret) + goto exit; + + ret =dfl_fpga_dev_ops_register (pdev, &fme_fops,THIS_MODULE ); +if (ret) + goto feature_uinit; + +return 0 ; + +feature_uinit: +dfl_fpga_dev_feature_uinit (pdev); +exit: +return ret; +} + +static int fme_remove (struct platform_device *pdev) +{ +dfl_fpga_dev_ops_unregister (pdev); +dfl_fpga_dev_feature_uinit (pdev); + +return 0 ; +} + +static struct platform_driver fme_driver = { + .driver = { + .name =DFL_FPGA_FEATURE_DEV_FME , + }, + .probe = fme_probe, + .remove = fme_remove, +}; + +module_platform_driver (fme_driver); + +MODULE_DESCRIPTION ("FPGA Management Engine driver" ); +MODULE_AUTHOR ("Intel Corporation" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("platform:dfl-fme" );Signature · 1 line
1.8.3.1
Thanks,
Moritz
Re: [PATCH v6 22/29] fpga: dfl: fme-region: add support for compat_id
In reply to Wu HaoQuoted 6 lines · Wu Hao
This patch adds
compat_idsupport, it reuses fme manager's compat id, as the per region compat id is actually from the fme manager's register.Signed-off-by Wu Hao <[email protected]>Acked-by Alan Tull <[email protected]>
Quoted 22 lines
---
v5: reuse fme manager'scompat_idas per regioncompat_id
v6: rebase, fix copyright time and add Acked-by from Alan.--- drivers/fpga/dfl-fme-region.c | 1 + 1 file changed, 1 insertion(+)drivers/fpga/dfl-fme-region.c +1
-0@@ -45,6 +45,7 @@ static int fme_region_probe(struct platform_device *pdev) } region->priv = pdata; + region->compat_id = mgr->compat_id;platform_set_drvdata (pdev, region); ret =fpga_region_register (region);Signature · 1 line
1.8.3.1
Re: [PATCH v6 05/29] fpga: region: add compat_id support
In reply to Wu HaoQuoted 7 lines · Wu Hao
This patch introduces a
compat_idpointer member and sysfs interface for each fpga region, similar ascompat_idfor fpga manager, it allows applications to read the per regioncompat_idfor compatibility checking before other actions on this fpga-region (e.g PR).Signed-off-by Wu Hao <[email protected]>Acked-by Alan Tull <[email protected]>
Quoted 88 lines
---
v5: use pointer forcompat_idas it's optional to implement.
v6: add Acked-by from Alan.--- Documentation/ABI/testing/sysfs-class-fpga-region | 9 +++++++++ drivers/fpga/fpga-region.c | 22 ++++++++++++++++++++++ include/linux/fpga/fpga-region.h | 2 ++ 3 files changed, 33 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-fpga-regionDocumentation/ABI/testing/sysfs-class-fpga-region new file +9
-0@@ -0,0 +1,9 @@ +What: /sys/class/fpga_region/<region>/compat_id +Date: June 2018 +KernelVersion: 4.18 +Contact: Wu Hao <[email protected]> +Description: FPGA region id for compatibility check, e.g compatibility + of the FPGA reconfiguration hardware and image. This value + is defined or calculated by the layer that is creating the + FPGA region. This interface returns the compat_id value or + just error code -ENOENT in case compat_id is not used.drivers/fpga/fpga-region.c +22
-0@@ -158,6 +158,27 @@ int fpga_region_program_fpga(struct fpga_region *region) }EXPORT_SYMBOL_GPL (fpga_region_program_fpga); +static ssize_t compat_id_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct fpga_region *region =to_fpga_region (dev); + +if (!region->compat_id) +return -ENOENT ; + +return sprintf (buf,"%016llx%016llx\n" , + (unsigned long long )region->compat_id->id_h, + (unsigned long long )region->compat_id->id_l); +} + +static DEVICE_ATTR_RO (compat_id); + +static struct attribute *fpga_region_attrs[] = { + &dev_attr_compat_id.attr, +NULL , +}; +ATTRIBUTE_GROUPS (fpga_region); +/** * fpga_region_create - alloc and init a struct fpga_region * @dev: device parent @@ -258,6 +279,7 @@ static int __init fpga_region_init(void)if (IS_ERR (fpga_region_class))return PTR_ERR (fpga_region_class); + fpga_region_class->dev_groups = fpga_region_groups; fpga_region_class->dev_release = fpga_region_dev_release;return 0 ;include/linux/fpga/fpga-region.h +2
-0@@ -14,6 +14,7 @@* @bridge_list: list of FPGA bridges specified in region * @mgr: FPGA manager * @info: FPGA image info +* @compat_id: FPGA region id for compatibility check. * @priv: private data * @get_bridges: optional function to get bridges to a list */ @@ -23,6 +24,7 @@ struct fpga_region {struct list_head bridge_list;struct fpga_manager *mgr;struct fpga_image_info *info; +struct fpga_compat_id *compat_id;void *priv;int (*get_bridges)(struct fpga_region *region); };Signature · 1 line
1.8.3.1
Thanks,
Moritz
Re: [PATCH v6 12/29] fpga: add FPGA DFL PCIe device driver
In reply to Moritz FischerQuoted 127 lines · Moritz Fischer
Quoted 126 lines · Wu Hao
From: Zhang Yi <[email protected]>
This patch implements the basic framework of the driver for FPGA PCIe device which implements the Device Feature List (DFL) in its MMIO space. This driver is verified on Intel(R) PCIe based FPGA DFL devices, including both integrated (e.g Intel Server Platform with In-package FPGA) and discrete (e.g Intel FPGA PCIe Acceleration Cards) solutions.
Signed-off-by Tim Whisonant <[email protected]>Signed-off-by Enno Luebbers <[email protected]>Signed-off-by Shiva Rao <[email protected]>Signed-off-by Christopher Rauer <[email protected]>Signed-off-by Zhang Yi <[email protected]>Signed-off-by Xiao Guangrong <[email protected]>Signed-off-by Wu Hao <[email protected]>Acked-by Alan Tull <[email protected]>Acked-by Moritz Fischer <[email protected]>---
v2: move the code todrivers/fpgafolder as suggested by Alan Tull.
switch to GPLv2 license.
fix comments from Moritz Fischer.
v3: switch to pci_set_dma_mask/consistent_dma_mask() function.
removepci_save_state()in probe function.
rename driver toINTEL_FPGA_DFL_PCIandintel-dfl-pci.cto indicate this driver supports Intel FPGA PCI devices which implement DFL. improveKconfigdescription forINTEL_FPGA_DFL_PCI
v4: rename toFPGA_DFL_PCI(dfl-pci.c) for better reuse.
fix SPDX license issue.
v5: usemodule_pci_driver()instead.
add Acked-by from Alan and Moritz.
v6: rebase and unify naming inKconfig--- drivers/fpga/Kconfig | 15 +++++++ drivers/fpga/Makefile | 3 ++ drivers/fpga/dfl-pci.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 drivers/fpga/dfl-pci.cdrivers/fpga/Kconfig +15
-0@@ -146,4 +146,19 @@ config FPGA_DFL Gate Array (FPGA) solutions which implement Device Feature List. It provides enumeration APIs, and feature device infrastructure. +config FPGA_DFL_PCI + tristate "FPGA DFL PCIe Device Driver" + depends on PCI && FPGA_DFL + help + Select this option to enable PCIe driver for PCIe based + Field-Programmable Gate Array (FPGA) solutions which implemented + the Device Feature List (DFL). This driver provides interfaces + for userspace applications to configure, enumerate, open and access + FPGA accelerators on the FPGA DFL devices, enables system level + management functions such as FPGA partial reconfiguration, power + management, and virtualization with DFL framework and DFL feature + device drivers. + + To compile this as a module, choose M here. + endif # FPGAdrivers/fpga/Makefile +3
-0@@ -31,3 +31,6 @@ obj-$(CONFIG_OF_FPGA_REGION) += of-fpga-region.o # FPGA Device Feature List Support obj-$(CONFIG_FPGA_DFL) += dfl.o + +# Drivers for FPGAs which implement DFL +obj-$(CONFIG_FPGA_DFL_PCI) += dfl-pci.odrivers/fpga/dfl-pci.c new file +47
-0@@ -0,0 +1,114 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Driver for FPGA Device Feature List (DFL) PCIe device +* +* Copyright (C) 2017-2018 Intel Corporation, Inc. +* +* Authors: +* Zhang Yi <[email protected]> +* Xiao Guangrong <[email protected]> +* Joseph Grecco <[email protected]> +* Enno Luebbers <[email protected]> +* Tim Whisonant <[email protected]> +* Ananda Ravuri <[email protected]> +* Henry Mitchel <[email protected]> +*/ + +#include <linux/pci.h> +#include <linux/types.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/stddef.h> +#include <linux/errno.h> +#include <linux/aer.h> + +#define DRV_VERSION "0.8" +#define DRV_NAME "dfl-pci" + +/* PCI Device ID */ +#define PCIE_DEVICE_ID_PF_INT_5_X 0xBCBD +#define PCIE_DEVICE_ID_PF_INT_6_X 0xBCC0 +#define PCIE_DEVICE_ID_PF_DSC_1_X 0x09C4 +/* VF Device */ +#define PCIE_DEVICE_ID_VF_INT_5_X 0xBCBF +#define PCIE_DEVICE_ID_VF_INT_6_X 0xBCC1 +#define PCIE_DEVICE_ID_VF_DSC_1_X 0x09C5 + +static struct pci_device_id cci_pcie_id_tbl[] = { + {PCI_DEVICE (PCI_VENDOR_ID_INTEL ,PCIE_DEVICE_ID_PF_INT_5_X ),}, + {PCI_DEVICE (PCI_VENDOR_ID_INTEL ,PCIE_DEVICE_ID_VF_INT_5_X ),}, + {PCI_DEVICE (PCI_VENDOR_ID_INTEL ,PCIE_DEVICE_ID_PF_INT_6_X ),}, + {PCI_DEVICE (PCI_VENDOR_ID_INTEL ,PCIE_DEVICE_ID_VF_INT_6_X ),}, + {PCI_DEVICE (PCI_VENDOR_ID_INTEL ,PCIE_DEVICE_ID_PF_DSC_1_X ),}, + {PCI_DEVICE (PCI_VENDOR_ID_INTEL ,PCIE_DEVICE_ID_VF_DSC_1_X ),}, + {0 ,} +}; +MODULE_DEVICE_TABLE (pci, cci_pcie_id_tbl); +
Quoted 8 lines
drivers/fpga/dfl-pci.c line 53
Quoted 6 lines
drivers/fpga/dfl-pci.c new file +6
-0+static +int cci_pci_probe (struct pci_dev *pcidev,const struct pci_device_id *pcidevid) +{ +int ret; + + ret =pci_enable_device (pcidev);Any reason we cannot use
pcim_enable_device()here?
Hi Moritz
Thanks for the comments, pcim_enable_device() saves code for sure, will switch to it in the next version.
Thanks
Hao
Re: [PATCH v6 19/29] fpga: dfl: fme-mgr: add compat_id support
In reply to Wu HaoQuoted 6 lines · Wu Hao
This patch adds
compat_idsupport to fme manager driver, it reads the ID from the hardware register. And it could be used for compatibility check before partial reconfiguration.Signed-off-by Wu Hao <[email protected]>Acked-by Alan Tull <[email protected]>
Quoted 50 lines
---
v6: add Acked-by from Alan.--- drivers/fpga/dfl-fme-mgr.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)drivers/fpga/dfl-fme-mgr.c +15
-0@@ -272,9 +272,17 @@ static u64 fme_mgr_status(struct fpga_manager *mgr) .status = fme_mgr_status, }; +static void fme_mgr_get_compat_id (void __iomem *fme_pr, +struct fpga_compat_id *id) +{ + id->id_l =readq (fme_pr +FME_PR_INTFC_ID_L ); + id->id_h =readq (fme_pr +FME_PR_INTFC_ID_H ); +} +static int fme_mgr_probe (struct platform_device *pdev) {struct dfl_fme_mgr_pdata *pdata =dev_get_platdata (&pdev->dev); +struct fpga_compat_id *compat_id;struct device *dev = &pdev->dev;struct fme_mgr_priv *priv;struct fpga_manager *mgr;@@ -295,11 +303,18 @@ static int fme_mgr_probe(struct platform_device *pdev)return PTR_ERR (priv->ioaddr); } + compat_id =devm_kzalloc (dev,sizeof (*compat_id),GFP_KERNEL ); +if (!compat_id) +return -ENOMEM ; + +fme_mgr_get_compat_id (priv->ioaddr, compat_id); + mgr =fpga_mgr_create (dev,"DFL FME FPGA Manager" , &fme_mgr_ops, priv);if (!mgr)return -ENOMEM ; + mgr->compat_id = compat_id;platform_set_drvdata (pdev, mgr); ret =fpga_mgr_register (mgr);Signature · 1 line
1.8.3.1
Thanks,
Moritz
Moritz Fischer
maintainerRe: [PATCH v6 17/29] fpga: dfl: fme: add partial reconfiguration sub feature support
In reply to Wu HaoHi,
quick question for Alan inline below.
Quoted 312 lines · Wu Hao
From: Kang Luwei <[email protected]>
Partial Reconfiguration (PR) is the most important function for FME. It allows reconfiguration for given Port/Accelerated Function Unit (AFU).
It creates platform devices for fpga-mgr, fpga-regions and fpga-bridges, and invokes fpga-region's interface (
fpga_region_program_fpga) for PR operation once PR request received via ioctl. Below user space interface is exposed by this sub feature.Ioctl interface:
*DFL_FPGA_FME_PORT_PR
Do partial reconfiguration per information from userspace, including target port(AFU), buffer size and address info. It returns error code to userspace if failed. For detailed PR error information, user needs to read fpga-mgr's status sysfs interface.Signed-off-by Tim Whisonant <[email protected]>Signed-off-by Enno Luebbers <[email protected]>Signed-off-by Shiva Rao <[email protected]>Signed-off-by Christopher Rauer <[email protected]>Signed-off-by Kang Luwei <[email protected]>Signed-off-by Xiao Guangrong <[email protected]>Signed-off-by Wu Hao <[email protected]>Acked-by Alan Tull <[email protected]>---
v2: moved the code todrivers/fpgafolder as suggested by Alan Tull.
switched to GPLv2 license.
removed status fromFPGA_FME_PORT_PRioctl data structure. added platform devices creation for fpga-mgr/fpga-region/fpga-bridge. switched to fpga-region interfacefpga_region_program_fpgafor PR. fixed comments from Alan Tull onFPGA_MGR_PARTIAL_RECONFIGflag usage. fixed kbuild warnings.
v3: rename driver files to dfl-fme-*.
rebase due to fpga APIs change.
replace bitfields.
switch tofpga_cdev_find_portto find port device.
v4: rebase and correct comments for some function.
fix SPDX license issue.
remove unnecessary input parameter for destroy_bridge/region function. adddfl-fme-pr.hfor PR sub feature data structure and registers.
v5: rebase due to DFL framework API naming changes.
improve naming for IOCTL API, functions and data structure. defer finding port platform device to fme bridge.
pass mapped ioaddr to fme manager via pdata.
remove uselessdevm_kfree().
v6: rebase, fix copyright time and improve function name.
add Acked-by from Alan.--- drivers/fpga/Makefile | 2 +- drivers/fpga/dfl-fme-main.c | 43 +++- drivers/fpga/dfl-fme-pr.c | 474 ++++++++++++++++++++++++++++++++++++++++++ drivers/fpga/dfl-fme-pr.h | 84 ++++++++ drivers/fpga/dfl-fme.h | 38 ++++ include/uapi/linux/fpga-dfl.h | 28 +++ 6 files changed, 667 insertions(+), 2 deletions(-) create mode 100644 drivers/fpga/dfl-fme-pr.c create mode 100644 drivers/fpga/dfl-fme-pr.h create mode 100644 drivers/fpga/dfl-fme.hdrivers/fpga/Makefile +1
-1@@ -33,7 +33,7 @@ obj-$(CONFIG_OF_FPGA_REGION) += of-fpga-region.o obj-$(CONFIG_FPGA_DFL) += dfl.o obj-$(CONFIG_FPGA_DFL_FME) += dfl-fme.o -dfl-fme-objs := dfl-fme-main.o +dfl-fme-objs := dfl-fme-main.o dfl-fme-pr.o # Drivers for FPGAs which implement DFL obj-$(CONFIG_FPGA_DFL_PCI) += dfl-pci.odrivers/fpga/dfl-fme-main.c +42
-1@@ -19,6 +19,7 @@#include <linux/fpga-dfl.h> #include "dfl.h" +#include "dfl-fme.h" static ssize_t ports_num_show (struct device *dev,struct device_attribute *attr,char *buf)@@ -113,6 +114,10 @@ static void fme_hdr_uinit(struct platform_device *pdev, .ops = &fme_hdr_ops, }, { + .id = FME_FEATURE_ID_PR_MGMT, + .ops = &pr_mgmt_ops, + }, + { .ops = NULL, }, };@@ -187,6 +192,35 @@ static long fme_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)return -EINVAL ; } +static int fme_dev_init (struct platform_device *pdev) +{ +struct dfl_feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct dfl_fme *fme; + + fme =devm_kzalloc (&pdev->dev,sizeof (*fme),GFP_KERNEL ); +if (!fme) +return -ENOMEM ; + + fme->pdata = pdata; + +mutex_lock (&pdata->lock); +dfl_fpga_pdata_set_private (pdata, fme); +mutex_unlock (&pdata->lock); + +return 0 ; +} + +static void fme_dev_destroy (struct platform_device *pdev) +{ +struct dfl_feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct dfl_fme *fme; + +mutex_lock (&pdata->lock); + fme =dfl_fpga_pdata_get_private (pdata); +dfl_fpga_pdata_set_private (pdata,NULL ); +mutex_unlock (&pdata->lock); +} +static const struct file_operations fme_fops = { .owner =THIS_MODULE , .open = fme_open,@@ -198,10 +232,14 @@ static int fme_probe(struct platform_device *pdev) {int ret; - ret =dfl_fpga_dev_feature_init (pdev, fme_feature_drvs); + ret =fme_dev_init (pdev);if (ret) goto exit; + ret =dfl_fpga_dev_feature_init (pdev, fme_feature_drvs); +if (ret) + goto dev_destroy; + ret =dfl_fpga_dev_ops_register (pdev, &fme_fops,THIS_MODULE );if (ret) goto feature_uinit;@@ -210,6 +248,8 @@ static int fme_probe(struct platform_device *pdev) feature_uinit:dfl_fpga_dev_feature_uinit (pdev); +dev_destroy: +fme_dev_destroy (pdev); exit:return ret; }@@ -218,6 +258,7 @@ static int fme_remove(struct platform_device *pdev) {dfl_fpga_dev_ops_unregister (pdev);dfl_fpga_dev_feature_uinit (pdev); +fme_dev_destroy (pdev);return 0 ; }drivers/fpga/dfl-fme-pr.c new file +141
-0@@ -0,0 +1,474 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Driver for FPGA Management Engine (FME) Partial Reconfiguration +* +* Copyright (C) 2017-2018 Intel Corporation, Inc. +* +* Authors: +* Kang Luwei <[email protected]> +* Xiao Guangrong <[email protected]> +* Wu Hao <[email protected]> +* Joseph Grecco <[email protected]> +* Enno Luebbers <[email protected]> +* Tim Whisonant <[email protected]> +* Ananda Ravuri <[email protected]> +* Christopher Rauer <[email protected]> +* Henry Mitchel <[email protected]> +*/ + +#include <linux/types.h> +#include <linux/device.h> +#include <linux/vmalloc.h> +#include <linux/uaccess.h> +#include <linux/fpga/fpga-mgr.h> +#include <linux/fpga/fpga-bridge.h> +#include <linux/fpga/fpga-region.h> +#include <linux/fpga-dfl.h> + +#include "dfl.h" +#include "dfl-fme.h" +#include "dfl-fme-pr.h" + +static struct dfl_fme_region * +dfl_fme_region_find_by_port_id (struct dfl_fme *fme,int port_id) +{ +struct dfl_fme_region *fme_region; + +list_for_each_entry (fme_region, &fme->region_list, node) +if (fme_region->port_id == port_id) +return fme_region; + +return NULL ; +} + +static int dfl_fme_region_match (struct device *dev,const void *data) +{ +return dev->parent == data; +} + +static struct fpga_region *dfl_fme_region_find (struct dfl_fme *fme,int port_id) +{ +struct dfl_fme_region *fme_region; +struct fpga_region *region; + + fme_region =dfl_fme_region_find_by_port_id (fme, port_id); +if (!fme_region) +return NULL ; + + region =fpga_region_class_find (NULL , &fme_region->region->dev, + dfl_fme_region_match); +if (!region) +return NULL ; + +return region; +} + +static int fme_pr (struct platform_device *pdev,unsigned long arg) +{ +struct dfl_feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +void __user *argp = (void __user *)arg; +struct dfl_fpga_fme_port_pr port_pr; +struct fpga_image_info *info; +struct fpga_region *region; +void __iomem *fme_hdr; +struct dfl_fme *fme; +unsigned long minsz; +void *buf =NULL ; +int ret =0 ; +u64 v; + + minsz = offsetofend(struct dfl_fpga_fme_port_pr, buffer_address); + +if (copy_from_user (&port_pr, argp, minsz)) +return -EFAULT ; + +if (port_pr.argsz < minsz || port_pr.flags) +return -EINVAL ; + +if (!IS_ALIGNED (port_pr.buffer_size,4 )) +return -EINVAL ; + +/* get fme header region */ + fme_hdr =dfl_get_feature_ioaddr_by_id (&pdev->dev, +FME_FEATURE_ID_HEADER ); + +/* check port id */ + v =readq (fme_hdr +FME_HDR_CAP ); +if (port_pr.port_id >=FIELD_GET (FME_CAP_NUM_PORTS , v)) { +dev_dbg (&pdev->dev,"port number more than maximum\n" ); +return -EINVAL ; + } + +if (!access_ok (VERIFY_READ , + (void __user *)(unsigned long )port_pr.buffer_address, + port_pr.buffer_size)) +return -EFAULT ; + + buf =vmalloc (port_pr.buffer_size); +if (!buf) +return -ENOMEM ; + +if (copy_from_user (buf, + (void __user *)(unsigned long )port_pr.buffer_address, + port_pr.buffer_size)) { + ret = -EFAULT ; + goto free_exit; + } + +/* prepare fpga_image_info for PR */ + info =fpga_image_info_alloc (&pdev->dev); +if (!info) { + ret = -ENOMEM ; + goto free_exit; + } + + info->flags |=FPGA_MGR_PARTIAL_RECONFIG ; + +mutex_lock (&pdata->lock); + fme =dfl_fpga_pdata_get_private (pdata); +/* fme device has been unregistered. */ +if (!fme) { + ret = -EINVAL ; + goto unlock_exit; + } + + region =dfl_fme_region_find (fme, port_pr.port_id); +if (!region) { + ret = -EINVAL ; + goto unlock_exit; + } + +fpga_image_info_free (region->info);
drivers/fpga/dfl-fme-pr.c line 151
Quoted 10 lines
drivers/fpga/dfl-fme-pr.c new file +10
-0+ + info->buf = buf; + info->count = port_pr.buffer_size; + info->region_id = port_pr.port_id; + region->info = info; + + ret =fpga_region_program_fpga (region); + +if (region->get_bridges) +fpga_bridges_put (®ion->bridge_list);
I'm wondering if this should not be done as part of fpga_region_program_fpga() (It's not at the moment).
Alan, am I missing something obvious? :)
Quoted 511 lines
drivers/fpga/dfl-fme-pr.c new file +323
-0+ +put_device (®ion->dev); +unlock_exit: +mutex_unlock (&pdata->lock); +free_exit: +vfree (buf); +if (copy_to_user ((void __user *)arg, &port_pr, minsz)) +return -EFAULT ; + +return ret; +} + +/** +* dfl_fme_create_mgr - create fpga mgr platform device as child device +* +* @pdata: fme platform_device's pdata +* +* Return: mgr platform device if successful, and error code otherwise. +*/ +static struct platform_device * +dfl_fme_create_mgr (struct dfl_feature_platform_data *pdata, +struct dfl_feature *feature) +{ +struct platform_device *mgr, *fme = pdata->dev; +struct dfl_fme_mgr_pdata mgr_pdata; +int ret = -ENOMEM ; + +if (!feature->ioaddr) +return ERR_PTR (-ENODEV ); + + mgr_pdata.ioaddr = feature->ioaddr; + +/* +* Each FME has only one fpga-mgr, so allocate platform device using +* the same FME platform device id. +*/ + mgr =platform_device_alloc (DFL_FPGA_FME_MGR , fme->id); +if (!mgr) +return ERR_PTR (ret); + + mgr->dev.parent = &fme->dev; + + ret =platform_device_add_data (mgr, &mgr_pdata,sizeof (mgr_pdata)); +if (ret) + goto create_mgr_err; + + ret =platform_device_add (mgr); +if (ret) + goto create_mgr_err; + +return mgr; + +create_mgr_err: +platform_device_put (mgr); +return ERR_PTR (ret); +} + +/** +* dfl_fme_destroy_mgr - destroy fpga mgr platform device +* @pdata: fme platform device's pdata +*/ +static void dfl_fme_destroy_mgr (struct dfl_feature_platform_data *pdata) +{ +struct dfl_fme *priv =dfl_fpga_pdata_get_private (pdata); + +platform_device_unregister (priv->mgr); +} + +/** +* dfl_fme_create_bridge - create fme fpga bridge platform device as child +* +* @pdata: fme platform device's pdata +* @port_id: port id for the bridge to be created. +* +* Return: bridge platform device if successful, and error code otherwise. +*/ +static struct dfl_fme_bridge * +dfl_fme_create_bridge (struct dfl_feature_platform_data *pdata,int port_id) +{ +struct device *dev = &pdata->dev->dev; +struct dfl_fme_br_pdata br_pdata; +struct dfl_fme_bridge *fme_br; +int ret = -ENOMEM ; + + fme_br =devm_kzalloc (dev,sizeof (*fme_br),GFP_KERNEL ); +if (!fme_br) +return ERR_PTR (ret); + + br_pdata.cdev = pdata->dfl_cdev; + br_pdata.port_id = port_id; + + fme_br->br =platform_device_alloc (DFL_FPGA_FME_BRIDGE , +PLATFORM_DEVID_AUTO ); +if (!fme_br->br) +return ERR_PTR (ret); + + fme_br->br->dev.parent = dev; + + ret =platform_device_add_data (fme_br->br, &br_pdata,sizeof (br_pdata)); +if (ret) + goto create_br_err; + + ret =platform_device_add (fme_br->br); +if (ret) + goto create_br_err; + +return fme_br; + +create_br_err: +platform_device_put (fme_br->br); +return ERR_PTR (ret); +} + +/** +* dfl_fme_destroy_bridge - destroy fpga bridge platform device +* @fme_br: fme bridge to destroy +*/ +static void dfl_fme_destroy_bridge (struct dfl_fme_bridge *fme_br) +{ +platform_device_unregister (fme_br->br); +} + +/** +* dfl_fme_destroy_bridge - destroy all fpga bridge platform device +* @pdata: fme platform device's pdata +*/ +static void dfl_fme_destroy_bridges (struct dfl_feature_platform_data *pdata) +{ +struct dfl_fme *priv =dfl_fpga_pdata_get_private (pdata); +struct dfl_fme_bridge *fbridge, *tmp; + +list_for_each_entry_safe (fbridge, tmp, &priv->bridge_list, node) { +list_del (&fbridge->node); +dfl_fme_destroy_bridge (fbridge); + } +} + +/** +* dfl_fme_create_region - create fpga region platform device as child +* +* @pdata: fme platform device's pdata +* @mgr: mgr platform device needed for region +* @br: br platform device needed for region +* @port_id: port id +* +* Return: fme region if successful, and error code otherwise. +*/ +static struct dfl_fme_region * +dfl_fme_create_region (struct dfl_feature_platform_data *pdata, +struct platform_device *mgr, +struct platform_device *br,int port_id) +{ +struct dfl_fme_region_pdata region_pdata; +struct device *dev = &pdata->dev->dev; +struct dfl_fme_region *fme_region; +int ret = -ENOMEM ; + + fme_region =devm_kzalloc (dev,sizeof (*fme_region),GFP_KERNEL ); +if (!fme_region) +return ERR_PTR (ret); + + region_pdata.mgr = mgr; + region_pdata.br = br; + +/* +* Each FPGA device may have more than one port, so allocate platform +* device using the same port platform device id. +*/ + fme_region->region =platform_device_alloc (DFL_FPGA_FME_REGION , br->id); +if (!fme_region->region) +return ERR_PTR (ret); + + fme_region->region->dev.parent = dev; + + ret =platform_device_add_data (fme_region->region, ®ion_pdata, +sizeof (region_pdata)); +if (ret) + goto create_region_err; + + ret =platform_device_add (fme_region->region); +if (ret) + goto create_region_err; + + fme_region->port_id = port_id; + +return fme_region; + +create_region_err: +platform_device_put (fme_region->region); +return ERR_PTR (ret); +} + +/** +* dfl_fme_destroy_region - destroy fme region +* @fme_region: fme region to destroy +*/ +static void dfl_fme_destroy_region (struct dfl_fme_region *fme_region) +{ +platform_device_unregister (fme_region->region); +} + +/** +* dfl_fme_destroy_regions - destroy all fme regions +* @pdata: fme platform device's pdata +*/ +static void dfl_fme_destroy_regions (struct dfl_feature_platform_data *pdata) +{ +struct dfl_fme *priv =dfl_fpga_pdata_get_private (pdata); +struct dfl_fme_region *fme_region, *tmp; + +list_for_each_entry_safe (fme_region, tmp, &priv->region_list, node) { +list_del (&fme_region->node); +dfl_fme_destroy_region (fme_region); + } +} + +static int pr_mgmt_init (struct platform_device *pdev, +struct dfl_feature *feature) +{ +struct dfl_feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct dfl_fme_region *fme_region; +struct dfl_fme_bridge *fme_br; +struct platform_device *mgr; +struct dfl_fme *priv; +void __iomem *fme_hdr; +int ret = -ENODEV , i =0 ; +u64 fme_cap, port_offset; + + fme_hdr =dfl_get_feature_ioaddr_by_id (&pdev->dev, +FME_FEATURE_ID_HEADER ); + +mutex_lock (&pdata->lock); + priv =dfl_fpga_pdata_get_private (pdata); + +/* Initialize the region and bridge sub device list */ +INIT_LIST_HEAD (&priv->region_list); +INIT_LIST_HEAD (&priv->bridge_list); + +/* Create fpga mgr platform device */ + mgr =dfl_fme_create_mgr (pdata, feature); +if (IS_ERR (mgr)) { +dev_err (&pdev->dev,"fail to create fpga mgr pdev\n" ); + goto unlock; + } + + priv->mgr = mgr; + +/* Read capability register to check number of regions and bridges */ + fme_cap =readq (fme_hdr +FME_HDR_CAP ); +for (; i <FIELD_GET (FME_CAP_NUM_PORTS , fme_cap); i++) { + port_offset =readq (fme_hdr +FME_HDR_PORT_OFST (i)); +if (!(port_offset &FME_PORT_OFST_IMP )) +continue ; + +/* Create bridge for each port */ + fme_br =dfl_fme_create_bridge (pdata, i); +if (IS_ERR (fme_br)) { + ret =PTR_ERR (fme_br); + goto destroy_region; + } + +list_add (&fme_br->node, &priv->bridge_list); + +/* Create region for each port */ + fme_region =dfl_fme_create_region (pdata, mgr, + fme_br->br, i); +if (!fme_region) { + ret =PTR_ERR (fme_region); + goto destroy_region; + } + +list_add (&fme_region->node, &priv->region_list); + } +mutex_unlock (&pdata->lock); + +return 0 ; + +destroy_region: +dfl_fme_destroy_regions (pdata); +dfl_fme_destroy_bridges (pdata); +dfl_fme_destroy_mgr (pdata); +unlock: +mutex_unlock (&pdata->lock); +return ret; +} + +static void pr_mgmt_uinit (struct platform_device *pdev, +struct dfl_feature *feature) +{ +struct dfl_feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct dfl_fme *priv; + +mutex_lock (&pdata->lock); + priv =dfl_fpga_pdata_get_private (pdata); + +dfl_fme_destroy_regions (pdata); +dfl_fme_destroy_bridges (pdata); +dfl_fme_destroy_mgr (pdata); +mutex_unlock (&pdata->lock); +} + +static long fme_pr_ioctl (struct platform_device *pdev, +struct dfl_feature *feature, +unsigned int cmd,unsigned long arg) +{ +long ret; + +switch (cmd) { +case DFL_FPGA_FME_PORT_PR : + ret =fme_pr (pdev, arg); +break ; +default : + ret = -ENODEV ; + } + +return ret; +} + +const struct dfl_feature_ops pr_mgmt_ops = { + .init = pr_mgmt_init, + .uinit = pr_mgmt_uinit, + .ioctl = fme_pr_ioctl, +};drivers/fpga/dfl-fme-pr.h new file +84
-0@@ -0,0 +1,84 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Header file for FPGA Management Engine (FME) Partial Reconfiguration Driver +* +* Copyright (C) 2017-2018 Intel Corporation, Inc. +* +* Authors: +* Kang Luwei <[email protected]> +* Xiao Guangrong <[email protected]> +* Wu Hao <[email protected]> +* Joseph Grecco <[email protected]> +* Enno Luebbers <[email protected]> +* Tim Whisonant <[email protected]> +* Ananda Ravuri <[email protected]> +* Henry Mitchel <[email protected]> +*/ + +#ifndef __DFL_FME_PR_H +#define __DFL_FME_PR_H + +#include <linux/platform_device.h> + +/** +* struct dfl_fme_region - FME fpga region data structure +* +* @region: platform device of the FPGA region. +* @node: used to link fme_region to a list. +* @port_id: indicate which port this region connected to. +*/ +struct dfl_fme_region { +struct platform_device *region; +struct list_head node; +int port_id; +}; + +/** +* struct dfl_fme_region_pdata - platform data for FME region platform device. +* +* @mgr: platform device of the FPGA manager. +* @br: platform device of the FPGA bridge. +* @region_id: region id (same as port_id). +*/ +struct dfl_fme_region_pdata { +struct platform_device *mgr; +struct platform_device *br; +int region_id; +}; + +/** +* struct dfl_fme_bridge - FME fpga bridge data structure +* +* @br: platform device of the FPGA bridge. +* @node: used to link fme_bridge to a list. +*/ +struct dfl_fme_bridge { +struct platform_device *br; +struct list_head node; +}; + +/** +* struct dfl_fme_bridge_pdata - platform data for FME bridge platform device. +* +* @cdev: container device. +* @port_id: port id. +*/ +struct dfl_fme_br_pdata { +struct dfl_fpga_cdev *cdev; +int port_id; +}; + +/** +* struct dfl_fme_mgr_pdata - platform data for FME manager platform device. +* +* @ioaddr: mapped io address for FME manager platform device. +*/ +struct dfl_fme_mgr_pdata { +void __iomem *ioaddr; +}; + +#define DFL_FPGA_FME_MGR "dfl-fme-mgr" +#define DFL_FPGA_FME_BRIDGE "dfl-fme-bridge" +#define DFL_FPGA_FME_REGION "dfl-fme-region" + +#endif /* __DFL_FME_PR_H */ drivers/fpga/dfl-fme.h new file +38
-0@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Header file for FPGA Management Engine (FME) Driver +* +* Copyright (C) 2017-2018 Intel Corporation, Inc. +* +* Authors: +* Kang Luwei <[email protected]> +* Xiao Guangrong <[email protected]> +* Wu Hao <[email protected]> +* Joseph Grecco <[email protected]> +* Enno Luebbers <[email protected]> +* Tim Whisonant <[email protected]> +* Ananda Ravuri <[email protected]> +* Henry Mitchel <[email protected]> +*/ + +#ifndef __DFL_FME_H +#define __DFL_FME_H + +/** +* struct dfl_fme - dfl fme private data +* +* @mgr: FME's FPGA manager platform device. +* @region_list: link list of FME's FPGA regions. +* @bridge_list: link list of FME's FPGA bridges. +* @pdata: fme platform device's pdata. +*/ +struct dfl_fme { +struct platform_device *mgr; +struct list_head region_list; +struct list_head bridge_list; +struct dfl_feature_platform_data *pdata; +}; + +extern const struct dfl_feature_ops pr_mgmt_ops; + +#endif /* __DFL_FME_H */ include/uapi/linux/fpga-dfl.h +28
-0@@ -14,6 +14,8 @@#ifndef _UAPI_LINUX_FPGA_DFL_H#define _UAPI_LINUX_FPGA_DFL_H +#include <linux/types.h> +#define DFL_FPGA_API_VERSION 0/* @@ -26,6 +28,7 @@#define DFL_FPGA_MAGIC 0xB6#define DFL_FPGA_BASE 0 +#define DFL_FME_BASE 0x80/** * DFL_FPGA_GET_API_VERSION - _IO(DFL_FPGA_MAGIC, DFL_FPGA_BASE + 0) @@ -45,4 +48,29 @@#define DFL_FPGA_CHECK_EXTENSION _IO(DFL_FPGA_MAGIC, DFL_FPGA_BASE + 1) +/* IOCTLs for FME file descriptor */ + +/** +* DFL_FPGA_FME_PORT_PR - _IOW(DFL_FPGA_MAGIC, DFL_FME_BASE + 0, +* struct dfl_fpga_fme_port_pr) +* +* Driver does Partial Reconfiguration based on Port ID and Buffer (Image) +* provided by caller. +* Return: 0 on success, -errno on failure. +* If DFL_FPGA_FME_PORT_PR returns -EIO, that indicates the HW has detected +* some errors during PR, under this case, the user can fetch HW error info +* from the status of FME's fpga manager. +*/ + +struct dfl_fpga_fme_port_pr { +/* Input */ +__u32 argsz;/* Structure length */ +__u32 flags;/* Zero for now */ +__u32 port_id; +__u32 buffer_size; +__u64 buffer_address;/* Userspace address to the buffer for PR */ +}; + +#define DFL_FPGA_FME_PORT_PR _IO(DFL_FPGA_MAGIC, DFL_FME_BASE + 0) +#endif /* _UAPI_LINUX_FPGA_DFL_H */ Signature · 1 line
1.8.3.1
Thanks,
Moritz
Moritz Fischer
maintainerRe: [PATCH v6 18/29] fpga: dfl: add fpga manager platform driver for FME
In reply to Wu HaoHi Hao,
small nit below, looks good otherwise.
Quoted 260 lines · Wu Hao
This patch adds fpga manager driver for FPGA Management Engine (FME). It implements
fpga_manager_opsfor FPGA Partial Reconfiguration function.Signed-off-by Tim Whisonant <[email protected]>Signed-off-by Enno Luebbers <[email protected]>Signed-off-by Shiva Rao <[email protected]>Signed-off-by Christopher Rauer <[email protected]>Signed-off-by Kang Luwei <[email protected]>Signed-off-by Xiao Guangrong <[email protected]>Signed-off-by Wu Hao <[email protected]>Acked-by Alan Tull <[email protected]>---
v3: rename driver to dfl-fpga-fme-mgr
implemented status callback for fpga manager
rebased due to fpga api changes
v4: rename to dfl-fme-mgr, and fix SPDX license issue
addpr_creditcomments and improvedev_errmessage removeinterface_idsysfs interface
includedfl-fme-pr.hinstead ofdfl.h
v5: move related register definition fromdfl-fme-pr.htodfl-fme-mgr.c
use mapped ioaddr passed via pdata for register access. rebase due to fpga manager API changes.
include header file for readq/writeq.
v6: rebase, fix copyright time and add Acked-by from Alan.--- drivers/fpga/Kconfig | 6 + drivers/fpga/Makefile | 1 + drivers/fpga/dfl-fme-mgr.c | 334 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 341 insertions(+) create mode 100644 drivers/fpga/dfl-fme-mgr.cdrivers/fpga/Kconfig +6
-0@@ -156,6 +156,12 @@ config FPGA_DFL_FME FPGA platform level management features. There shall be 1 FME per DFL based FPGA device. +config FPGA_DFL_FME_MGR + tristate "FPGA DFL FME Manager Driver" + depends on FPGA_DFL_FME + help + Say Y to enable FPGA Manager driver for FPGA Management Engine. + config FPGA_DFL_PCI tristate "FPGA DFL PCIe Device Driver" depends on PCI && FPGA_DFLdrivers/fpga/Makefile +1
-0@@ -32,6 +32,7 @@ obj-$(CONFIG_OF_FPGA_REGION) += of-fpga-region.o # FPGA Device Feature List Support obj-$(CONFIG_FPGA_DFL) += dfl.o obj-$(CONFIG_FPGA_DFL_FME) += dfl-fme.o +obj-$(CONFIG_FPGA_DFL_FME_MGR) += dfl-fme-mgr.o dfl-fme-objs := dfl-fme-main.o dfl-fme-pr.odrivers/fpga/dfl-fme-mgr.c new file +194
-0@@ -0,0 +1,334 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* FPGA Manager Driver for FPGA Management Engine (FME) +* +* Copyright (C) 2017-2018 Intel Corporation, Inc. +* +* Authors: +* Kang Luwei <[email protected]> +* Xiao Guangrong <[email protected]> +* Wu Hao <[email protected]> +* Joseph Grecco <[email protected]> +* Enno Luebbers <[email protected]> +* Tim Whisonant <[email protected]> +* Ananda Ravuri <[email protected]> +* Christopher Rauer <[email protected]> +* Henry Mitchel <[email protected]> +*/ + +#include <linux/bitfield.h> +#include <linux/module.h> +#include <linux/iopoll.h> +#include <linux/io-64-nonatomic-lo-hi.h> +#include <linux/fpga/fpga-mgr.h> + +#include "dfl-fme-pr.h" + +/* FME Partial Reconfiguration Sub Feature Register Set */ +#define FME_PR_DFH 0x0 +#define FME_PR_CTRL 0x8 +#define FME_PR_STS 0x10 +#define FME_PR_DATA 0x18 +#define FME_PR_ERR 0x20 +#define FME_PR_INTFC_ID_H 0xA8 +#define FME_PR_INTFC_ID_L 0xB0 + +/* FME PR Control Register Bitfield */ +#define FME_PR_CTRL_PR_RST BIT_ULL(0)/* Reset PR engine */ +#define FME_PR_CTRL_PR_RSTACK BIT_ULL(4)/* Ack for PR engine reset */ +#define FME_PR_CTRL_PR_RGN_ID GENMASK_ULL(9, 7)/* PR Region ID */ +#define FME_PR_CTRL_PR_START BIT_ULL(12)/* Start to request PR service */ +#define FME_PR_CTRL_PR_COMPLETE BIT_ULL(13)/* PR data push completion */ + +/* FME PR Status Register Bitfield */ +/* Number of available entries in HW queue inside the PR engine. */ +#define FME_PR_STS_PR_CREDIT GENMASK_ULL(8, 0) +#define FME_PR_STS_PR_STS BIT_ULL(16)/* PR operation status */ +#define FME_PR_STS_PR_STS_IDLE 0 +#define FME_PR_STS_PR_CTRLR_STS GENMASK_ULL(22, 20)/* Controller status */ +#define FME_PR_STS_PR_HOST_STS GENMASK_ULL(27, 24)/* PR host status */ + +/* FME PR Data Register Bitfield */ +/* PR data from the raw-binary file. */ +#define FME_PR_DATA_PR_DATA_RAW GENMASK_ULL(32, 0) + +/* FME PR Error Register */ +/* PR Operation errors detected. */ +#define FME_PR_ERR_OPERATION_ERR BIT_ULL(0) +/* CRC error detected. */ +#define FME_PR_ERR_CRC_ERR BIT_ULL(1) +/* Incompatible PR bitstream detected. */ +#define FME_PR_ERR_INCOMPATIBLE_BS BIT_ULL(2) +/* PR data push protocol violated. */ +#define FME_PR_ERR_PROTOCOL_ERR BIT_ULL(3) +/* PR data fifo overflow error detected */ +#define FME_PR_ERR_FIFO_OVERFLOW BIT_ULL(4) + +#define PR_WAIT_TIMEOUT 8000000 +#define PR_HOST_STATUS_IDLE 0 + +struct fme_mgr_priv { +void __iomem *ioaddr; +u64 pr_error; +}; + +static u64 pr_error_to_mgr_status (u64 err) +{ +u64 status =0 ; + +if (err &FME_PR_ERR_OPERATION_ERR ) + status |=FPGA_MGR_STATUS_OPERATION_ERR ; +if (err &FME_PR_ERR_CRC_ERR ) + status |=FPGA_MGR_STATUS_CRC_ERR ; +if (err &FME_PR_ERR_INCOMPATIBLE_BS ) + status |=FPGA_MGR_STATUS_INCOMPATIBLE_IMAGE_ERR ; +if (err &FME_PR_ERR_PROTOCOL_ERR ) + status |=FPGA_MGR_STATUS_IP_PROTOCOL_ERR ; +if (err &FME_PR_ERR_FIFO_OVERFLOW ) + status |=FPGA_MGR_STATUS_FIFO_OVERFLOW_ERR ; + +return status; +} + +static u64 fme_mgr_pr_error_handle (void __iomem *fme_pr) +{ +u64 pr_status, pr_error; + + pr_status =readq (fme_pr +FME_PR_STS ); +if (!(pr_status &FME_PR_STS_PR_STS )) +return 0 ; + + pr_error =readq (fme_pr +FME_PR_ERR ); +writeq (pr_error, fme_pr +FME_PR_ERR ); + +return pr_error; +} + +static int fme_mgr_write_init (struct fpga_manager *mgr, +struct fpga_image_info *info, +const char *buf,size_t count) +{ +struct device *dev = &mgr->dev; +struct fme_mgr_priv *priv = mgr->priv; +void __iomem *fme_pr = priv->ioaddr; +u64 pr_ctrl, pr_status; + +if (!(info->flags &FPGA_MGR_PARTIAL_RECONFIG )) { +dev_err (dev,"only supports partial reconfiguration.\n" ); +return -EINVAL ; + } + +dev_dbg (dev,"resetting PR before initiated PR\n" ); + + pr_ctrl =readq (fme_pr +FME_PR_CTRL ); + pr_ctrl |=FME_PR_CTRL_PR_RST ; +writeq (pr_ctrl, fme_pr +FME_PR_CTRL ); + +if (readq_poll_timeout (fme_pr +FME_PR_CTRL , pr_ctrl, + pr_ctrl &FME_PR_CTRL_PR_RSTACK ,1 , +PR_WAIT_TIMEOUT )) { +dev_err (dev,"PR Reset ACK timeout\n" ); +return -ETIMEDOUT ; + } + + pr_ctrl =readq (fme_pr +FME_PR_CTRL ); + pr_ctrl &= ~FME_PR_CTRL_PR_RST ; +writeq (pr_ctrl, fme_pr +FME_PR_CTRL ); + +dev_dbg (dev, +"waiting for PR resource in HW to be initialized and ready\n" ); + +if (readq_poll_timeout (fme_pr +FME_PR_STS , pr_status, + (pr_status &FME_PR_STS_PR_STS ) == +FME_PR_STS_PR_STS_IDLE ,1 ,PR_WAIT_TIMEOUT )) { +dev_err (dev,"PR Status timeout\n" ); + priv->pr_error =fme_mgr_pr_error_handle (fme_pr); +return -ETIMEDOUT ; + } + +dev_dbg (dev,"check and clear previous PR error\n" ); + priv->pr_error =fme_mgr_pr_error_handle (fme_pr); +if (priv->pr_error) +dev_dbg (dev,"previous PR error detected %llx\n" , + (unsigned long long )priv->pr_error); + +dev_dbg (dev,"set PR port ID\n" ); + + pr_ctrl =readq (fme_pr +FME_PR_CTRL ); + pr_ctrl &= ~FME_PR_CTRL_PR_RGN_ID ; + pr_ctrl |=FIELD_PREP (FME_PR_CTRL_PR_RGN_ID , info->region_id); +writeq (pr_ctrl, fme_pr +FME_PR_CTRL ); + +return 0 ; +} + +static int fme_mgr_write (struct fpga_manager *mgr, +const char *buf,size_t count) +{ +struct device *dev = &mgr->dev; +struct fme_mgr_priv *priv = mgr->priv; +void __iomem *fme_pr = priv->ioaddr; +u64 pr_ctrl, pr_status, pr_data; +int delay =0 , pr_credit, i =0 ; + +dev_dbg (dev,"start request\n" ); + + pr_ctrl =readq (fme_pr +FME_PR_CTRL ); + pr_ctrl |=FME_PR_CTRL_PR_START ; +writeq (pr_ctrl, fme_pr +FME_PR_CTRL ); + +dev_dbg (dev,"pushing data from bitstream to HW\n" ); + +/* +* driver can push data to PR hardware using PR_DATA register once HW +* has enough pr_credit (> 1), pr_credit reduces one for every 32bit +* pr data write to PR_DATA register. If pr_credit <= 1, driver needs +* to wait for enough pr_credit from hardware by polling. +*/ + pr_status =readq (fme_pr +FME_PR_STS ); + pr_credit =FIELD_GET (FME_PR_STS_PR_CREDIT , pr_status); + +while (count >0 ) { +while (pr_credit <=1 ) { +if (delay++ >PR_WAIT_TIMEOUT ) { +dev_err (dev,"PR_CREDIT timeout\n" );
drivers/fpga/dfl-fme-mgr.c line 204
Quoted 10 lines
drivers/fpga/dfl-fme-mgr.c new file +10
-0+return -ETIMEDOUT ; + } +udelay (1 ); + + pr_status =readq (fme_pr +FME_PR_STS ); + pr_credit =FIELD_GET (FME_PR_STS_PR_CREDIT , pr_status); + } + +if (count <4 ) { +WARN_ON (1 );
Maybe an error message instead of WARN_ON()? How about "Invalid PR bitstream size" ?
Quoted 133 lines
drivers/fpga/dfl-fme-mgr.c new file +130
-0+return -EINVAL ; + } + + pr_data =0 ; + pr_data |=FIELD_PREP (FME_PR_DATA_PR_DATA_RAW , + *(((u32 *)buf) + i)); +writeq (pr_data, fme_pr +FME_PR_DATA ); + count -=4 ; + pr_credit--; + i++; + } + +return 0 ; +} + +static int fme_mgr_write_complete (struct fpga_manager *mgr, +struct fpga_image_info *info) +{ +struct device *dev = &mgr->dev; +struct fme_mgr_priv *priv = mgr->priv; +void __iomem *fme_pr = priv->ioaddr; +u64 pr_ctrl; + + pr_ctrl =readq (fme_pr +FME_PR_CTRL ); + pr_ctrl |=FME_PR_CTRL_PR_COMPLETE ; +writeq (pr_ctrl, fme_pr +FME_PR_CTRL ); + +dev_dbg (dev,"green bitstream push complete\n" ); +dev_dbg (dev,"waiting for HW to release PR resource\n" ); + +if (readq_poll_timeout (fme_pr +FME_PR_CTRL , pr_ctrl, + !(pr_ctrl &FME_PR_CTRL_PR_START ),1 , +PR_WAIT_TIMEOUT )) { +dev_err (dev,"PR Completion ACK timeout.\n" ); +return -ETIMEDOUT ; + } + +dev_dbg (dev,"PR operation complete, checking status\n" ); + priv->pr_error =fme_mgr_pr_error_handle (fme_pr); +if (priv->pr_error) { +dev_dbg (dev,"PR error detected %llx\n" , + (unsigned long long )priv->pr_error); +return -EIO ; + } + +dev_dbg (dev,"PR done successfully\n" ); + +return 0 ; +} + +static enum fpga_mgr_states fme_mgr_state (struct fpga_manager *mgr) +{ +return FPGA_MGR_STATE_UNKNOWN ; +} + +static u64 fme_mgr_status (struct fpga_manager *mgr) +{ +struct fme_mgr_priv *priv = mgr->priv; + +return pr_error_to_mgr_status (priv->pr_error); +} + +static const struct fpga_manager_ops fme_mgr_ops = { + .write_init = fme_mgr_write_init, + .write = fme_mgr_write, + .write_complete = fme_mgr_write_complete, + .state = fme_mgr_state, + .status = fme_mgr_status, +}; + +static int fme_mgr_probe (struct platform_device *pdev) +{ +struct dfl_fme_mgr_pdata *pdata =dev_get_platdata (&pdev->dev); +struct device *dev = &pdev->dev; +struct fme_mgr_priv *priv; +struct fpga_manager *mgr; +struct resource *res; +int ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + +if (pdata->ioaddr) + priv->ioaddr = pdata->ioaddr; + +if (!priv->ioaddr) { + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + priv->ioaddr =devm_ioremap_resource (dev, res); +if (IS_ERR (priv->ioaddr)) +return PTR_ERR (priv->ioaddr); + } + + mgr =fpga_mgr_create (dev,"DFL FME FPGA Manager" , + &fme_mgr_ops, priv); +if (!mgr) +return -ENOMEM ; + +platform_set_drvdata (pdev, mgr); + + ret =fpga_mgr_register (mgr); +if (ret) +fpga_mgr_free (mgr); + +return ret; +} + +static int fme_mgr_remove (struct platform_device *pdev) +{ +struct fpga_manager *mgr =platform_get_drvdata (pdev); + +fpga_mgr_unregister (mgr); + +return 0 ; +} + +static struct platform_driver fme_mgr_driver = { + .driver = { + .name =DFL_FPGA_FME_MGR , + }, + .probe = fme_mgr_probe, + .remove = fme_mgr_remove, +}; + +module_platform_driver (fme_mgr_driver); + +MODULE_DESCRIPTION ("FPGA Manager for DFL FPGA Management Engine" ); +MODULE_AUTHOR ("Intel Corporation" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("platform:dfl-fme-mgr" );Signature · 1 line
1.8.3.1
Thanks,
Moritz
Re: [PATCH v6 18/29] fpga: dfl: add fpga manager platform driver for FME
Quoted 269 lines · Moritz Fischer
Hi Hao,
small nit below, looks good otherwise.
Quoted 264 lines · Wu Hao
This patch adds fpga manager driver for FPGA Management Engine (FME). It implements
fpga_manager_opsfor FPGA Partial Reconfiguration function.Signed-off-by Tim Whisonant <[email protected]>Signed-off-by Enno Luebbers <[email protected]>Signed-off-by Shiva Rao <[email protected]>Signed-off-by Christopher Rauer <[email protected]>Signed-off-by Kang Luwei <[email protected]>Signed-off-by Xiao Guangrong <[email protected]>Signed-off-by Wu Hao <[email protected]>Acked-by Alan Tull <[email protected]>---
v3: rename driver to dfl-fpga-fme-mgr
implemented status callback for fpga manager
rebased due to fpga api changes
v4: rename to dfl-fme-mgr, and fix SPDX license issue
addpr_creditcomments and improvedev_errmessage removeinterface_idsysfs interface
includedfl-fme-pr.hinstead ofdfl.h
v5: move related register definition fromdfl-fme-pr.htodfl-fme-mgr.c
use mapped ioaddr passed via pdata for register access. rebase due to fpga manager API changes.
include header file for readq/writeq.
v6: rebase, fix copyright time and add Acked-by from Alan.--- drivers/fpga/Kconfig | 6 + drivers/fpga/Makefile | 1 + drivers/fpga/dfl-fme-mgr.c | 334 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 341 insertions(+) create mode 100644 drivers/fpga/dfl-fme-mgr.cdrivers/fpga/Kconfig +6
-0@@ -156,6 +156,12 @@ config FPGA_DFL_FME FPGA platform level management features. There shall be 1 FME per DFL based FPGA device. +config FPGA_DFL_FME_MGR + tristate "FPGA DFL FME Manager Driver" + depends on FPGA_DFL_FME + help + Say Y to enable FPGA Manager driver for FPGA Management Engine. + config FPGA_DFL_PCI tristate "FPGA DFL PCIe Device Driver" depends on PCI && FPGA_DFLdrivers/fpga/Makefile +1
-0@@ -32,6 +32,7 @@ obj-$(CONFIG_OF_FPGA_REGION) += of-fpga-region.o # FPGA Device Feature List Support obj-$(CONFIG_FPGA_DFL) += dfl.o obj-$(CONFIG_FPGA_DFL_FME) += dfl-fme.o +obj-$(CONFIG_FPGA_DFL_FME_MGR) += dfl-fme-mgr.o dfl-fme-objs := dfl-fme-main.o dfl-fme-pr.odrivers/fpga/dfl-fme-mgr.c new file +198
-0@@ -0,0 +1,334 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* FPGA Manager Driver for FPGA Management Engine (FME) +* +* Copyright (C) 2017-2018 Intel Corporation, Inc. +* +* Authors: +* Kang Luwei <[email protected]> +* Xiao Guangrong <[email protected]> +* Wu Hao <[email protected]> +* Joseph Grecco <[email protected]> +* Enno Luebbers <[email protected]> +* Tim Whisonant <[email protected]> +* Ananda Ravuri <[email protected]> +* Christopher Rauer <[email protected]> +* Henry Mitchel <[email protected]> +*/ + +#include <linux/bitfield.h> +#include <linux/module.h> +#include <linux/iopoll.h> +#include <linux/io-64-nonatomic-lo-hi.h> +#include <linux/fpga/fpga-mgr.h> + +#include "dfl-fme-pr.h" + +/* FME Partial Reconfiguration Sub Feature Register Set */ +#define FME_PR_DFH 0x0 +#define FME_PR_CTRL 0x8 +#define FME_PR_STS 0x10 +#define FME_PR_DATA 0x18 +#define FME_PR_ERR 0x20 +#define FME_PR_INTFC_ID_H 0xA8 +#define FME_PR_INTFC_ID_L 0xB0 + +/* FME PR Control Register Bitfield */ +#define FME_PR_CTRL_PR_RST BIT_ULL(0)/* Reset PR engine */ +#define FME_PR_CTRL_PR_RSTACK BIT_ULL(4)/* Ack for PR engine reset */ +#define FME_PR_CTRL_PR_RGN_ID GENMASK_ULL(9, 7)/* PR Region ID */ +#define FME_PR_CTRL_PR_START BIT_ULL(12)/* Start to request PR service */ +#define FME_PR_CTRL_PR_COMPLETE BIT_ULL(13)/* PR data push completion */ + +/* FME PR Status Register Bitfield */ +/* Number of available entries in HW queue inside the PR engine. */ +#define FME_PR_STS_PR_CREDIT GENMASK_ULL(8, 0) +#define FME_PR_STS_PR_STS BIT_ULL(16)/* PR operation status */ +#define FME_PR_STS_PR_STS_IDLE 0 +#define FME_PR_STS_PR_CTRLR_STS GENMASK_ULL(22, 20)/* Controller status */ +#define FME_PR_STS_PR_HOST_STS GENMASK_ULL(27, 24)/* PR host status */ + +/* FME PR Data Register Bitfield */ +/* PR data from the raw-binary file. */ +#define FME_PR_DATA_PR_DATA_RAW GENMASK_ULL(32, 0) + +/* FME PR Error Register */ +/* PR Operation errors detected. */ +#define FME_PR_ERR_OPERATION_ERR BIT_ULL(0) +/* CRC error detected. */ +#define FME_PR_ERR_CRC_ERR BIT_ULL(1) +/* Incompatible PR bitstream detected. */ +#define FME_PR_ERR_INCOMPATIBLE_BS BIT_ULL(2) +/* PR data push protocol violated. */ +#define FME_PR_ERR_PROTOCOL_ERR BIT_ULL(3) +/* PR data fifo overflow error detected */ +#define FME_PR_ERR_FIFO_OVERFLOW BIT_ULL(4) + +#define PR_WAIT_TIMEOUT 8000000 +#define PR_HOST_STATUS_IDLE 0 + +struct fme_mgr_priv { +void __iomem *ioaddr; +u64 pr_error; +}; + +static u64 pr_error_to_mgr_status (u64 err) +{ +u64 status =0 ; + +if (err &FME_PR_ERR_OPERATION_ERR ) + status |=FPGA_MGR_STATUS_OPERATION_ERR ; +if (err &FME_PR_ERR_CRC_ERR ) + status |=FPGA_MGR_STATUS_CRC_ERR ; +if (err &FME_PR_ERR_INCOMPATIBLE_BS ) + status |=FPGA_MGR_STATUS_INCOMPATIBLE_IMAGE_ERR ; +if (err &FME_PR_ERR_PROTOCOL_ERR ) + status |=FPGA_MGR_STATUS_IP_PROTOCOL_ERR ; +if (err &FME_PR_ERR_FIFO_OVERFLOW ) + status |=FPGA_MGR_STATUS_FIFO_OVERFLOW_ERR ; + +return status; +} + +static u64 fme_mgr_pr_error_handle (void __iomem *fme_pr) +{ +u64 pr_status, pr_error; + + pr_status =readq (fme_pr +FME_PR_STS ); +if (!(pr_status &FME_PR_STS_PR_STS )) +return 0 ; + + pr_error =readq (fme_pr +FME_PR_ERR ); +writeq (pr_error, fme_pr +FME_PR_ERR ); + +return pr_error; +} + +static int fme_mgr_write_init (struct fpga_manager *mgr, +struct fpga_image_info *info, +const char *buf,size_t count) +{ +struct device *dev = &mgr->dev; +struct fme_mgr_priv *priv = mgr->priv; +void __iomem *fme_pr = priv->ioaddr; +u64 pr_ctrl, pr_status; + +if (!(info->flags &FPGA_MGR_PARTIAL_RECONFIG )) { +dev_err (dev,"only supports partial reconfiguration.\n" ); +return -EINVAL ; + } + +dev_dbg (dev,"resetting PR before initiated PR\n" ); + + pr_ctrl =readq (fme_pr +FME_PR_CTRL ); + pr_ctrl |=FME_PR_CTRL_PR_RST ; +writeq (pr_ctrl, fme_pr +FME_PR_CTRL ); + +if (readq_poll_timeout (fme_pr +FME_PR_CTRL , pr_ctrl, + pr_ctrl &FME_PR_CTRL_PR_RSTACK ,1 , +PR_WAIT_TIMEOUT )) { +dev_err (dev,"PR Reset ACK timeout\n" ); +return -ETIMEDOUT ; + } + + pr_ctrl =readq (fme_pr +FME_PR_CTRL ); + pr_ctrl &= ~FME_PR_CTRL_PR_RST ; +writeq (pr_ctrl, fme_pr +FME_PR_CTRL ); + +dev_dbg (dev, +"waiting for PR resource in HW to be initialized and ready\n" ); + +if (readq_poll_timeout (fme_pr +FME_PR_STS , pr_status, + (pr_status &FME_PR_STS_PR_STS ) == +FME_PR_STS_PR_STS_IDLE ,1 ,PR_WAIT_TIMEOUT )) { +dev_err (dev,"PR Status timeout\n" ); + priv->pr_error =fme_mgr_pr_error_handle (fme_pr); +return -ETIMEDOUT ; + } + +dev_dbg (dev,"check and clear previous PR error\n" ); + priv->pr_error =fme_mgr_pr_error_handle (fme_pr); +if (priv->pr_error) +dev_dbg (dev,"previous PR error detected %llx\n" , + (unsigned long long )priv->pr_error); + +dev_dbg (dev,"set PR port ID\n" ); + + pr_ctrl =readq (fme_pr +FME_PR_CTRL ); + pr_ctrl &= ~FME_PR_CTRL_PR_RGN_ID ; + pr_ctrl |=FIELD_PREP (FME_PR_CTRL_PR_RGN_ID , info->region_id); +writeq (pr_ctrl, fme_pr +FME_PR_CTRL ); + +return 0 ; +} + +static int fme_mgr_write (struct fpga_manager *mgr, +const char *buf,size_t count) +{ +struct device *dev = &mgr->dev; +struct fme_mgr_priv *priv = mgr->priv; +void __iomem *fme_pr = priv->ioaddr; +u64 pr_ctrl, pr_status, pr_data; +int delay =0 , pr_credit, i =0 ; + +dev_dbg (dev,"start request\n" ); + + pr_ctrl =readq (fme_pr +FME_PR_CTRL ); + pr_ctrl |=FME_PR_CTRL_PR_START ; +writeq (pr_ctrl, fme_pr +FME_PR_CTRL ); + +dev_dbg (dev,"pushing data from bitstream to HW\n" ); + +/* +* driver can push data to PR hardware using PR_DATA register once HW +* has enough pr_credit (> 1), pr_credit reduces one for every 32bit +* pr data write to PR_DATA register. If pr_credit <= 1, driver needs +* to wait for enough pr_credit from hardware by polling. +*/ + pr_status =readq (fme_pr +FME_PR_STS ); + pr_credit =FIELD_GET (FME_PR_STS_PR_CREDIT , pr_status); + +while (count >0 ) { +while (pr_credit <=1 ) { +if (delay++ >PR_WAIT_TIMEOUT ) { +dev_err (dev,"PR_CREDIT timeout\n" ); +return -ETIMEDOUT ; + } +udelay (1 ); +
Quoted 8 lines
drivers/fpga/dfl-fme-mgr.c line 204
Quoted 6 lines
drivers/fpga/dfl-fme-mgr.c new file +6
-0+ pr_status =readq (fme_pr +FME_PR_STS ); + pr_credit =FIELD_GET (FME_PR_STS_PR_CREDIT , pr_status); + } + +if (count <4 ) { +WARN_ON (1 );Maybe an error message instead of
WARN_ON()? How about "Invalid PR bitstream size" ?
Sure, will change this in the next version.
Hao
Quoted 3 lines
Thanks,
Moritz
Re: [PATCH v6 17/29] fpga: dfl: fme: add partial reconfiguration sub feature support
In reply to Moritz FischerOn Wed, Jun 13, 2018 at 8:07 PM, Moritz Fischer <[email protected]> wrote:
Hellooo,
This probably could use a comment, please see below.
Quoted 95 lines
Hi,
quick question for Alan inline below.
Quoted 76 lines
drivers/fpga/dfl-fme-pr.c new file +76
-0+static int fme_pr (struct platform_device *pdev,unsigned long arg) +{ +struct dfl_feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +void __user *argp = (void __user *)arg; +struct dfl_fpga_fme_port_pr port_pr; +struct fpga_image_info *info; +struct fpga_region *region; +void __iomem *fme_hdr; +struct dfl_fme *fme; +unsigned long minsz; +void *buf =NULL ; +int ret =0 ; +u64 v; + + minsz = offsetofend(struct dfl_fpga_fme_port_pr, buffer_address); + +if (copy_from_user (&port_pr, argp, minsz)) +return -EFAULT ; + +if (port_pr.argsz < minsz || port_pr.flags) +return -EINVAL ; + +if (!IS_ALIGNED (port_pr.buffer_size,4 )) +return -EINVAL ; + +/* get fme header region */ + fme_hdr =dfl_get_feature_ioaddr_by_id (&pdev->dev, +FME_FEATURE_ID_HEADER ); + +/* check port id */ + v =readq (fme_hdr +FME_HDR_CAP ); +if (port_pr.port_id >=FIELD_GET (FME_CAP_NUM_PORTS , v)) { +dev_dbg (&pdev->dev,"port number more than maximum\n" ); +return -EINVAL ; + } + +if (!access_ok (VERIFY_READ , + (void __user *)(unsigned long )port_pr.buffer_address, + port_pr.buffer_size)) +return -EFAULT ; + + buf =vmalloc (port_pr.buffer_size); +if (!buf) +return -ENOMEM ; + +if (copy_from_user (buf, + (void __user *)(unsigned long )port_pr.buffer_address, + port_pr.buffer_size)) { + ret = -EFAULT ; + goto free_exit; + } + +/* prepare fpga_image_info for PR */ + info =fpga_image_info_alloc (&pdev->dev); +if (!info) { + ret = -ENOMEM ; + goto free_exit; + } + + info->flags |=FPGA_MGR_PARTIAL_RECONFIG ; + +mutex_lock (&pdata->lock); + fme =dfl_fpga_pdata_get_private (pdata); +/* fme device has been unregistered. */ +if (!fme) { + ret = -EINVAL ; + goto unlock_exit; + } + + region =dfl_fme_region_find (fme, port_pr.port_id); +if (!region) { + ret = -EINVAL ; + goto unlock_exit; + } + +fpga_image_info_free (region->info);drivers/fpga/dfl-fme-pr.c line 151
Quoted 10 lines
drivers/fpga/dfl-fme-pr.c new file +10
-0+ + info->buf = buf; + info->count = port_pr.buffer_size; + info->region_id = port_pr.port_id; + region->info = info; + + ret =fpga_region_program_fpga (region); + +if (region->get_bridges) +fpga_bridges_put (®ion->bridge_list);I'm wondering if this should not be done as part of
fpga_region_program_fpga()(It's not at the moment).
Quoted 1 line
Alan, am I missing something obvious? :)
It is up to the caller of fpga_region_program_fpga to put the bridges before programming again. That prevents something other than the caller from reprogramming a partial region or messing with the bridges until the caller puts the bridges.
For example, for DT support, applying an overlay calls fpga_region_program_fpga() which gets the bridges, disables them, does the programming, and reenables the bridges. Then the bridges are held, preventing anything else from disabling the bridges until the overlay is removed. This was important in the DT case since the
overlay could include child nodes for hardware in the FPGA. Allowing
anyone else to play with the bridges while those drivers were expecting hardware access could be bad.
I can't remember for certain, but I think this code has to put the bridges here because this patch set allows userspace to reset the PR region's logic by disabling/reenabling the bridge to clear things out between acceleration runs (which Hao promises is OK to do, it's documented elsewhere in the pachset). It probably could use a comment right here to explain why the bridges are put here so future generations know not to break this.
Alan
Quoted 11 lines
Quoted 11 lines
drivers/fpga/dfl-fme-pr.c new file +11
-0+ +put_device (®ion->dev); +unlock_exit: +mutex_unlock (&pdata->lock); +free_exit: +vfree (buf); +if (copy_to_user ((void __user *)arg, &port_pr, minsz)) +return -EFAULT ; + +return ret; +}
Re: [PATCH v6 17/29] fpga: dfl: fme: add partial reconfiguration sub feature support
Quoted 117 lines · Alan Tull
On Wed, Jun 13, 2018 at 8:07 PM, Moritz Fischer <[email protected]> wrote:
Hellooo,
This probably could use a comment, please see below.
Quoted 95 lines
Hi,
quick question for Alan inline below.
Quoted 76 lines
drivers/fpga/dfl-fme-pr.c new file +76
-0+static int fme_pr (struct platform_device *pdev,unsigned long arg) +{ +struct dfl_feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +void __user *argp = (void __user *)arg; +struct dfl_fpga_fme_port_pr port_pr; +struct fpga_image_info *info; +struct fpga_region *region; +void __iomem *fme_hdr; +struct dfl_fme *fme; +unsigned long minsz; +void *buf =NULL ; +int ret =0 ; +u64 v; + + minsz = offsetofend(struct dfl_fpga_fme_port_pr, buffer_address); + +if (copy_from_user (&port_pr, argp, minsz)) +return -EFAULT ; + +if (port_pr.argsz < minsz || port_pr.flags) +return -EINVAL ; + +if (!IS_ALIGNED (port_pr.buffer_size,4 )) +return -EINVAL ; + +/* get fme header region */ + fme_hdr =dfl_get_feature_ioaddr_by_id (&pdev->dev, +FME_FEATURE_ID_HEADER ); + +/* check port id */ + v =readq (fme_hdr +FME_HDR_CAP ); +if (port_pr.port_id >=FIELD_GET (FME_CAP_NUM_PORTS , v)) { +dev_dbg (&pdev->dev,"port number more than maximum\n" ); +return -EINVAL ; + } + +if (!access_ok (VERIFY_READ , + (void __user *)(unsigned long )port_pr.buffer_address, + port_pr.buffer_size)) +return -EFAULT ; + + buf =vmalloc (port_pr.buffer_size); +if (!buf) +return -ENOMEM ; + +if (copy_from_user (buf, + (void __user *)(unsigned long )port_pr.buffer_address, + port_pr.buffer_size)) { + ret = -EFAULT ; + goto free_exit; + } + +/* prepare fpga_image_info for PR */ + info =fpga_image_info_alloc (&pdev->dev); +if (!info) { + ret = -ENOMEM ; + goto free_exit; + } + + info->flags |=FPGA_MGR_PARTIAL_RECONFIG ; + +mutex_lock (&pdata->lock); + fme =dfl_fpga_pdata_get_private (pdata); +/* fme device has been unregistered. */ +if (!fme) { + ret = -EINVAL ; + goto unlock_exit; + } + + region =dfl_fme_region_find (fme, port_pr.port_id); +if (!region) { + ret = -EINVAL ; + goto unlock_exit; + } + +fpga_image_info_free (region->info);drivers/fpga/dfl-fme-pr.c line 151
Quoted 10 lines
drivers/fpga/dfl-fme-pr.c new file +10
-0+ + info->buf = buf; + info->count = port_pr.buffer_size; + info->region_id = port_pr.port_id; + region->info = info; + + ret =fpga_region_program_fpga (region); + +if (region->get_bridges) +fpga_bridges_put (®ion->bridge_list);I'm wondering if this should not be done as part of
fpga_region_program_fpga()(It's not at the moment).Quoted 1 line
Alan, am I missing something obvious? :)
It is up to the caller of
fpga_region_program_fpgato put the bridges before programming again. That prevents something other than the caller from reprogramming a partial region or messing with the bridges until the caller puts the bridges.For example, for DT support, applying an overlay calls
fpga_region_program_fpga()which gets the bridges, disables them, does the programming, and reenables the bridges. Then the bridges are held, preventing anything else from disabling the bridges until the overlay is removed. This was important in the DT case since the
overlay could include child nodes for hardware in the FPGA. Allowing
anyone else to play with the bridges while those drivers were expecting hardware access could be bad.
Quoted 7 lines
I can't remember for certain, but I think this code has to put the bridges here because this patch set allows userspace to reset the PR region's logic by disabling/reenabling the bridge to clear things out between acceleration runs (which Hao promises is OK to do, it's documented elsewhere in the pachset). It probably could use a comment right here to explain why the bridges are put here so future generations know not to break this.
Yes, it's correct. I can add some comments here in the next version.
Thanks
Hao
Quoted 18 lines
Alan
Quoted 11 lines
drivers/fpga/dfl-fme-pr.c line 162
Quoted 11 lines
drivers/fpga/dfl-fme-pr.c new file +11
-0+ +put_device (®ion->dev); +unlock_exit: +mutex_unlock (&pdata->lock); +free_exit: +vfree (buf); +if (copy_to_user ((void __user *)arg, &port_pr, minsz)) +return -EFAULT ; + +return ret; +}--
To unsubscribe from this list: send the line "unsubscribe linux-fpga" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html