FPGA Device Feature List (DFL) Device Drivers
Subsystems (4)
Re: [PATCH v4 14/24] fpga: dfl: fme: add partial reconfiguration sub feature support
In reply to Alan TullOn Mon, 5 Mar 2018, Alan Tull wrote:
Hi Hao,
I do think we should consider different hw implementations with this code because it does look like most of it is generic. Specifically, I think we should consider DFH based fpga images that have been shipped already, and I think we need to consider new hardware implementations as well. Full disclosure, I am particularly interested in porting to a new hw implementation for partial reconfiguration.
Please see some comments below.
Matthew Gerlach
Quoted 370 lines · Wu Hao
Hi Hao,
We are going to want to be able use different FPGA managers with this framework. The different manager may be part of a different FME in fabric or it may be a hardware FPGA manager. Fortunately, at this point now the changes, noted below, to get there are pretty small.
Quoted 111 lines
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:
*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]>---
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.--- drivers/fpga/Makefile | 2 +- drivers/fpga/dfl-fme-main.c | 45 +++- drivers/fpga/dfl-fme-pr.c | 497 ++++++++++++++++++++++++++++++++++++++++++ drivers/fpga/dfl-fme-pr.h | 113 ++++++++++ drivers/fpga/dfl-fme.h | 38 ++++ include/uapi/linux/fpga-dfl.h | 27 +++ 6 files changed, 720 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@@ -32,7 +32,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 +24
-0@@ -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)@@ -111,6 +112,10 @@ static struct feature_driver fme_feature_drvs[] = { .ops = &fme_hdr_ops, }, { + .id = FME_FEATURE_ID_PR_MGMT, + .ops = &pr_mgmt_ops, + }, + { .ops = NULL, }, };@@ -194,14 +199,49 @@ static const struct file_operations fme_fops = { .unlocked_ioctl = fme_ioctl, }; +static int fme_dev_init (struct platform_device *pdev) +{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *fme; + + fme =devm_kzalloc (&pdev->dev,sizeof (*fme),GFP_KERNEL ); +if (!fme) +return -ENOMEM ; + + fme->pdata = pdata; + +mutex_lock (&pdata->lock); +fpga_pdata_set_private (pdata, fme); +mutex_unlock (&pdata->lock); + +return 0 ; +} + +static void fme_dev_destroy (struct platform_device *pdev)drivers/fpga/dfl-fme-main.c static const struct file_operations fme_fops = { · line 230
Quoted 10 lines
drivers/fpga/dfl-fme-main.c +10
-0+{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *fme; + +mutex_lock (&pdata->lock); + fme =fpga_pdata_get_private (pdata); +fpga_pdata_set_private (pdata,NULL ); +mutex_unlock (&pdata->lock); + +devm_kfree (&pdev->dev, fme);Is this needed? This is called when the device is being destroyed anyway.
Quoted 220 lines
drivers/fpga/dfl-fme-main.c +10
-1+} +static int fme_probe (struct platform_device *pdev) {int ret; - ret =fpga_dev_feature_init (pdev, fme_feature_drvs); + ret =fme_dev_init (pdev);if (ret) goto exit; + ret =fpga_dev_feature_init (pdev, fme_feature_drvs); +if (ret) + goto dev_destroy; + ret =fpga_register_dev_ops (pdev, &fme_fops,THIS_MODULE );if (ret) goto feature_uinit;@@ -210,6 +250,8 @@ static int fme_probe(struct platform_device *pdev) feature_uinit:fpga_dev_feature_uinit (pdev); +dev_destroy: +fme_dev_destroy (pdev); exit:return ret; }@@ -218,6 +260,7 @@ static int fme_remove(struct platform_device *pdev) {fpga_dev_feature_uinit (pdev);fpga_unregister_dev_ops (pdev); +fme_dev_destroy (pdev);return 0 ; }drivers/fpga/dfl-fme-pr.c new file +179
-0@@ -0,0 +1,497 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Driver for FPGA Management Engine (FME) Partial Reconfiguration +* +* Copyright (C) 2017 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 fme_region * +find_fme_region_by_port_id (struct fpga_fme *fme,int port_id) +{ +struct 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 fpga_fme_region_match (struct device *dev,const void *data) +{ +return dev->parent == data; +} + +static struct fpga_region * +fpga_fme_region_find (struct fpga_fme *fme,int port_id) +{ +struct fme_region *fme_region; +struct fpga_region *region; + + fme_region =find_fme_region_by_port_id (fme, port_id); +if (!fme_region) +return NULL ; + + region =fpga_region_class_find (NULL , &fme_region->region->dev, + fpga_fme_region_match); +if (!region) +return NULL ; + +return region; +} + +static int fme_pr (struct platform_device *pdev,unsigned long arg) +{ +void __user *argp = (void __user *)arg; +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *fme; +struct fpga_image_info *info; +struct fpga_region *region; +struct fpga_fme_port_pr port_pr; +unsigned long minsz; +void __iomem *fme_hdr; +void *buf =NULL ; +int ret =0 ; +u64 v; + + minsz = offsetofend(struct 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 =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 =fpga_pdata_get_private (pdata); +/* fme device has been unregistered. */ +if (!fme) { + ret = -EINVAL ; + goto unlock_exit; + } + + region =fpga_fme_region_find (fme, port_pr.port_id); +if (!region) { + ret = -EINVAL ; + goto unlock_exit; + } + +fpga_image_info_free (region->info); + + 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); + +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; +} + +/** +* fpga_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 * +fpga_fme_create_mgr (struct feature_platform_data *pdata) +{ +struct platform_device *mgr, *fme = pdata->dev; +struct feature *feature; +struct resource res; +struct resource *pres; +int ret = -ENOMEM ;drivers/fpga/dfl-fme-pr.c line 189
Quoted 10 lines
drivers/fpga/dfl-fme-pr.c new file +10
-0+ + feature =get_feature_by_id (&pdata->dev->dev,FME_FEATURE_ID_PR_MGMT ); +if (!feature) +return ERR_PTR (-ENODEV ); + +/* +* Each FME has only one fpga-mgr, so allocate platform device using +* the same FME platform device id. +*/ + mgr =platform_device_alloc (FPGA_DFL_FME_MGR , fme->id);At this point, the framework is assuming all FME's include the same FPGA manager device which would use the driver in
dfl-fme-mgr.c.I'm thinking of two cases where the manager isn't the same as a
dfl-fme-mgr.cmanager are a bit different:
Quoted 6 lines
(1) a FME-based FPGA manager, but different implementation, different registers. The constraint is that the port implementation has to be
similar enough to use the rest of the base FME code. I am wondering
if the FPGA manager can be added to the DFL. At this point, the DFL
would drive which FPGA manager is alloc'd. That way the user gets to
use all this code indfl-fme-pr.cbut with their FPGA manager.
I am thinking of the case of porting to a new hardware implementation
for Partial Reconfiguration. Since the new hardware is completely different at the register level, we would need new a new feature id. The fme init code for this new feature should be able to call the generic
code here and pass in the fgpa_mgr_ops that are hardware specific.
Quoted 240 lines
(2) a FPGA manager that can be added by device tree in the case of a platform that is using device tree. I think this will be pretty simple and can be done later when someone is actually bringing this framework up on a FPGA running under device tree. I'm thinking that the base DFL device that reads the dfl data from hardware can have a DT property that points to the FPGA manager. That manager can be saved somewhere handy like the pdata and passed down to this code, which realizes it can use that existing device and doesn't need to alloc a platform device. But again, that's probably best done later.
Quoted 229 lines
drivers/fpga/dfl-fme-pr.c new file +229
-0+if (!mgr) +return ERR_PTR (ret); + + mgr->dev.parent = &fme->dev; + + pres =platform_get_resource (fme,IORESOURCE_MEM , + feature->resource_index); +if (!pres) { + ret = -ENODEV ; + goto create_mgr_err; + } + +memset (&res,0 ,sizeof (struct resource )); + + res.start = pres->start; + res.end = pres->end; + res.name = pres->name; + res.flags =IORESOURCE_MEM ; + + ret =platform_device_add_resources (mgr, &res,1 ); +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); +} + +/** +* fpga_fme_destroy_mgr - destroy fpga mgr platform device +* @pdata: fme platform device's pdata +*/ +static void fpga_fme_destroy_mgr (struct feature_platform_data *pdata) +{ +struct fpga_fme *priv =fpga_pdata_get_private (pdata); + +platform_device_unregister (priv->mgr); +} + +/** +* fpga_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 fme_bridge * +fpga_fme_create_bridge (struct feature_platform_data *pdata,int port_id) +{ +struct device *dev = &pdata->dev->dev; +struct fme_br_pdata br_pdata; +struct 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.port =fpga_cdev_find_port (fpga_pdata_to_fpga_cdev (pdata), + &port_id, fpga_port_check_id); +if (!br_pdata.port) +return ERR_PTR (-ENODEV ); + +/* +* Each FPGA device may have more than one port, so allocate platform +* device using the same port platform device id. +*/ + fme_br->br =platform_device_alloc (FPGA_DFL_FME_BRIDGE , + br_pdata.port->id); +if (!fme_br->br) { + ret = -ENOMEM ; + goto create_br_err; + } + + 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); +put_device (&br_pdata.port->dev); +return ERR_PTR (ret); +} + +/** +* fpga_fme_destroy_bridge - destroy fpga bridge platform device +* @fme_br: fme bridge to destroy +*/ +static void fpga_fme_destroy_bridge (struct fme_bridge *fme_br) +{ +struct fme_br_pdata *br_pdata =dev_get_platdata (&fme_br->br->dev); + +put_device (&br_pdata->port->dev); +platform_device_unregister (fme_br->br); +} + +/** +* fpga_fme_destroy_bridge - destroy all fpga bridge platform device +* @pdata: fme platform device's pdata +*/ +static void fpga_fme_destroy_bridges (struct feature_platform_data *pdata) +{ +struct fpga_fme *priv =fpga_pdata_get_private (pdata); +struct fme_bridge *fbridge, *tmp; + +list_for_each_entry_safe (fbridge, tmp, &priv->bridge_list, node) { +list_del (&fbridge->node); +fpga_fme_destroy_bridge (fbridge); + } +} + +/** +* fpga_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 fme_region * +fpga_fme_create_region (struct feature_platform_data *pdata, +struct platform_device *mgr, +struct platform_device *br,int port_id) +{ +struct device *dev = &pdata->dev->dev; +struct fme_region_pdata region_pdata; +struct 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 (FPGA_DFL_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); +} + +/** +* fpga_fme_destroy_region - destroy fme region +* @fme_region: fme region to destroy +*/ +static void fpga_fme_destroy_region (struct fme_region *fme_region) +{ +platform_device_unregister (fme_region->region); +} + +/** +* fpga_fme_destroy_regions - destroy all fme regions +* @pdata: fme platform device's pdata +*/ +static void fpga_fme_destroy_regions (struct feature_platform_data *pdata) +{ +struct fpga_fme *priv =fpga_pdata_get_private (pdata); +struct fme_region *fme_region, *tmp; + +list_for_each_entry_safe (fme_region, tmp, &priv->region_list, node) { +list_del (&fme_region->node); +fpga_fme_destroy_region (fme_region); + } +} + +static int pr_mgmt_init (struct platform_device *pdev,struct feature *feature) +{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +void __iomem *fme_hdr; +struct platform_device *mgr; +struct fme_region *fme_region; +struct fme_bridge *fme_br; +struct fpga_fme *priv; +int ret = -ENODEV , i =0 ; +u64 fme_cap, port_offset; + + fme_hdr =get_feature_ioaddr_by_id (&pdev->dev, +FME_FEATURE_ID_HEADER ); + +mutex_lock (&pdata->lock); + priv =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 =fpga_fme_create_mgr (pdata); +if (IS_ERR (mgr)) {
Quoted 8 lines
drivers/fpga/dfl-fme-pr.c line 426
Quoted 8 lines
drivers/fpga/dfl-fme-pr.c new file +8
-0+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 );
I don't think this capability field exists in currently deployed FPGA images using DFH. I believe this difference requires a new feature id to differentiate between deployed FPGA images and images with this new "feature".
Quoted 305 lines
Quoted 139 lines
drivers/fpga/dfl-fme-pr.c new file +71
-0+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 =fpga_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 =fpga_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: +fpga_fme_destroy_regions (pdata); +fpga_fme_destroy_bridges (pdata); +fpga_fme_destroy_mgr (pdata); +unlock: +mutex_unlock (&pdata->lock); +return ret; +} + +static void pr_mgmt_uinit (struct platform_device *pdev,struct feature *feature) +{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *priv; + +mutex_lock (&pdata->lock); + priv =fpga_pdata_get_private (pdata); + +fpga_fme_destroy_regions (pdata); +fpga_fme_destroy_bridges (pdata); +fpga_fme_destroy_mgr (pdata); +mutex_unlock (&pdata->lock); +} + +static long fme_pr_ioctl (struct platform_device *pdev,struct feature *feature, +unsigned int cmd,unsigned long arg) +{ +long ret; + +switch (cmd) { +case FPGA_FME_PORT_PR : + ret =fme_pr (pdev, arg); +break ; +default : + ret = -ENODEV ; + } + +return ret; +} + +const struct 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 +62
-0@@ -0,0 +1,113 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Header file for FPGA Management Engine (FME) Partial Reconfiguration Driver +* +* Copyright (C) 2017 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 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 fme_region { +struct platform_device *region; +struct list_head node; +int port_id; +}; + +/** +* struct 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 fme_region_pdata { +struct platform_device *mgr; +struct platform_device *br; +int region_id; +}; + +/** +* struct fme_bridge - FME fpga bridge data structure +* +* @br: platform device of the FPGA bridge. +* @node: used to link fme_bridge to a list. +*/ +struct fme_bridge { +struct platform_device *br; +struct list_head node; +}; + +/** +* struct fme_bridge_pdata - platform data for FME bridge platform device. +* drivers/fpga/dfl-fme-pr.h line 72
Quoted 10 lines
drivers/fpga/dfl-fme-pr.h new file +10
-0+* @port: platform device of the port feature dev. +*/ +struct fme_br_pdata { +struct platform_device *port; +}; + +#define FPGA_DFL_FME_MGR "dfl-fme-mgr" +#define FPGA_DFL_FME_BRIDGE "dfl-fme-bridge" +#define FPGA_DFL_FME_REGION "dfl-fme-region" +Everything in
dfl-fme-pr.hup to this point is good and general and should remain indfl-fme-pr.h. The register #defines for this FME's FPGA manager device below should be associated with the FPGA manager driver. Sorry if the way I stated that in the v3 review wasn't clear.Quoted 29 lines
drivers/fpga/dfl-fme-pr.h new file +29
-0+/* 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(0)/* Reset PR engine */ +#define FME_PR_CTRL_PR_RSTACK BIT(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(12)/* Start to request for PR service */ +#define FME_PR_CTRL_PR_COMPLETE BIT(13)/* PR data push complete notification */ + +/* 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(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 */ drivers/fpga/dfl-fme-pr.h line 111
Quoted 10 lines
drivers/fpga/dfl-fme-pr.h new file +10
-0+/* PR Operation errors detected. */ +#define FME_PR_ERR_OPERATION_ERR BIT(0) +/* CRC error detected. */ +#define FME_PR_ERR_CRC_ERR BIT(1) +/* Incompatible PR bitstream detected. */ +#define FME_PR_ERR_INCOMPATIBLE_BS BIT(2) +/* PR data push protocol violated. */ +#define FME_PR_ERR_PROTOCOL_ERR BIT(3) +/* PR data fifo overflow error detected */ +#define FME_PR_ERR_FIFO_OVERFLOW BIT(4)This stuff is specific to this FPGA manager device, so it should either be in the
dfl-fme-mgr.cor in adfl-fme-mgr.hQuoted 97 lines
drivers/fpga/dfl-fme-pr.h new file +2
-0+ +#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 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 fpga_fme - fpga 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 fpga_fme { +struct platform_device *mgr; +struct list_head region_list; +struct list_head bridge_list; +struct feature_platform_data *pdata; +}; + +extern const struct feature_ops pr_mgmt_ops; + +#endif /* __DFL_FME_H */ include/uapi/linux/fpga-dfl.h +27
-1@@ -14,6 +14,8 @@#ifndef _UAPI_LINUX_FPGA_DFL_H#define _UAPI_LINUX_FPGA_DFL_H +#include <linux/types.h> +#define FPGA_API_VERSION 0/* @@ -26,6 +28,7 @@#define FPGA_MAGIC 0xB6#define FPGA_BASE 0 +#define FME_BASE 0x80/** * FPGA_GET_API_VERSION - _IO(FPGA_MAGIC, FPGA_BASE + 0) @@ -45,4 +48,28 @@#define FPGA_CHECK_EXTENSION _IO(FPGA_MAGIC, FPGA_BASE + 1) +/* IOCTLs for FME file descriptor */ + +/** +* FPGA_FME_PORT_PR - _IOW(FPGA_MAGIC, FME_BASE + 0, struct 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 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 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 FPGA_FME_PORT_PR _IO(FPGA_MAGIC, FME_BASE + 0) +#endif /* _UAPI_LINUX_FPGA_DFL_H */ --Quoted 2 lines
2.7.4
Thanks,
Alan
--
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
Re: [PATCH v4 14/24] fpga: dfl: fme: add partial reconfiguration sub feature support
Quoted 5 lines · On Sun, Mar 11, 2018 at 01:09:31PM -0700, [email protected] wrote:
On Mon, 5 Mar 2018, Alan Tull wrote:
Quoted 8 lines
Hi Hao,
I do think we should consider different hw implementations with this code because it does look like most of it is generic. Specifically, I think we should consider DFH based fpga images that have been shipped already, and I think we need to consider new hardware implementations as well. Full disclosure, I am particularly interested in porting to a new hw implementation for partial reconfiguration.
Hi Matthew,
This dfl-fme-pr.c driver is developed for the PR sub feature (feature id = 0x5), but we can reuse it for any cases if possible.
Quoted 2 lines
Please see some comments below.
Thanks for the comments, please see my comments inline.
Quoted 380 lines
Matthew Gerlach
Quoted 370 lines · Wu Hao
Hi Hao,
We are going to want to be able use different FPGA managers with this framework. The different manager may be part of a different FME in fabric or it may be a hardware FPGA manager. Fortunately, at this point now the changes, noted below, to get there are pretty small.
Quoted 111 lines
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:
*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]>---
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.
---drivers/fpga/Makefile | 2 +- drivers/fpga/dfl-fme-main.c | 45 +++- drivers/fpga/dfl-fme-pr.c | 497 ++++++++++++++++++++++++++++++++++++++++++ drivers/fpga/dfl-fme-pr.h | 113 ++++++++++ drivers/fpga/dfl-fme.h | 38 ++++ include/uapi/linux/fpga-dfl.h | 27 +++ 6 files changed, 720 insertions(+), 2 deletions(-)create mode 100644
drivers/fpga/dfl-fme-pr.c
create mode 100644drivers/fpga/dfl-fme-pr.h
create mode 100644drivers/fpga/dfl-fme.hdrivers/fpga/Makefile +0
-0@@ -32,7 +32,7 @@ obj-$(CONFIG_OF_FPGA_REGION) += of-fpga-region.oobj-$(CONFIG_FPGA_DFL) += dfl.o
obj-$(CONFIG_FPGA_DFL_FME) += dfl-fme.odrivers/fpga/Makefile +1
-1-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 +24
-0@@ -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)@@ -111,6 +112,10 @@ static struct feature_driver fme_feature_drvs[] = { .ops = &fme_hdr_ops, }, { + .id = FME_FEATURE_ID_PR_MGMT, + .ops = &pr_mgmt_ops, + }, + { .ops = NULL, }, };@@ -194,14 +199,49 @@ static const struct file_operations fme_fops = { .unlocked_ioctl = fme_ioctl, }; +static int fme_dev_init (struct platform_device *pdev) +{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *fme; + + fme =devm_kzalloc (&pdev->dev,sizeof (*fme),GFP_KERNEL ); +if (!fme) +return -ENOMEM ; + + fme->pdata = pdata; + +mutex_lock (&pdata->lock); +fpga_pdata_set_private (pdata, fme); +mutex_unlock (&pdata->lock); + +return 0 ; +} + +static void fme_dev_destroy (struct platform_device *pdev)drivers/fpga/dfl-fme-main.c static const struct file_operations fme_fops = { · line 230
Quoted 10 lines
drivers/fpga/dfl-fme-main.c +10
-0+{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *fme; + +mutex_lock (&pdata->lock); + fme =fpga_pdata_get_private (pdata); +fpga_pdata_set_private (pdata,NULL ); +mutex_unlock (&pdata->lock); + +devm_kfree (&pdev->dev, fme);Is this needed? This is called when the device is being destroyed anyway.
Quoted 220 lines
drivers/fpga/dfl-fme-main.c +7
-1+} +static int fme_probe (struct platform_device *pdev) {int ret; - ret =fpga_dev_feature_init (pdev, fme_feature_drvs); + ret =fme_dev_init (pdev);if (ret) goto exit; + ret =fpga_dev_feature_init (pdev, fme_feature_drvs); +if (ret) + goto dev_destroy; + ret =fpga_register_dev_ops (pdev, &fme_fops,THIS_MODULE );if (ret) goto feature_uinit;@@ -210,6 +250,8 @@ static int fme_probe(struct platform_device *pdev)
feature_uinit:fpga_dev_feature_uinit(pdev);drivers/fpga/dfl-fme-main.c +2
-0+dev_destroy: +fme_dev_destroy (pdev);exit:
return ret; }drivers/fpga/dfl-fme-main.c +1
-0@@ -218,6 +260,7 @@ static int fme_remove(struct platform_device *pdev) {fpga_dev_feature_uinit (pdev);fpga_unregister_dev_ops (pdev); +fme_dev_destroy (pdev);return 0 ; }drivers/fpga/dfl-fme-pr.c new file +179
-0@@ -0,0 +1,497 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Driver for FPGA Management Engine (FME) Partial Reconfiguration +* +* Copyright (C) 2017 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 fme_region * +find_fme_region_by_port_id (struct fpga_fme *fme,int port_id) +{ +struct 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 fpga_fme_region_match (struct device *dev,const void *data) +{ +return dev->parent == data; +} + +static struct fpga_region * +fpga_fme_region_find (struct fpga_fme *fme,int port_id) +{ +struct fme_region *fme_region; +struct fpga_region *region; + + fme_region =find_fme_region_by_port_id (fme, port_id); +if (!fme_region) +return NULL ; + + region =fpga_region_class_find (NULL , &fme_region->region->dev, + fpga_fme_region_match); +if (!region) +return NULL ; + +return region; +} + +static int fme_pr (struct platform_device *pdev,unsigned long arg) +{ +void __user *argp = (void __user *)arg; +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *fme; +struct fpga_image_info *info; +struct fpga_region *region; +struct fpga_fme_port_pr port_pr; +unsigned long minsz; +void __iomem *fme_hdr; +void *buf =NULL ; +int ret =0 ; +u64 v; + + minsz = offsetofend(struct 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 =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 =fpga_pdata_get_private (pdata); +/* fme device has been unregistered. */ +if (!fme) { + ret = -EINVAL ; + goto unlock_exit; + } + + region =fpga_fme_region_find (fme, port_pr.port_id); +if (!region) { + ret = -EINVAL ; + goto unlock_exit; + } + +fpga_image_info_free (region->info); + + 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); + +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; +} + +/** +* fpga_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 * +fpga_fme_create_mgr (struct feature_platform_data *pdata) +{ +struct platform_device *mgr, *fme = pdata->dev; +struct feature *feature; +struct resource res; +struct resource *pres; +int ret = -ENOMEM ;drivers/fpga/dfl-fme-pr.c line 189
Quoted 10 lines
drivers/fpga/dfl-fme-pr.c new file +10
-0+ + feature =get_feature_by_id (&pdata->dev->dev,FME_FEATURE_ID_PR_MGMT ); +if (!feature) +return ERR_PTR (-ENODEV ); + +/* +* Each FME has only one fpga-mgr, so allocate platform device using +* the same FME platform device id. +*/ + mgr =platform_device_alloc (FPGA_DFL_FME_MGR , fme->id);At this point, the framework is assuming all FME's include the same FPGA manager device which would use the driver in
dfl-fme-mgr.c.I'm thinking of two cases where the manager isn't the same as a
dfl-fme-mgr.cmanager are a bit different:Quoted 6 lines
(1) a FME-based FPGA manager, but different implementation, different registers. The constraint is that the port implementation has to be
similar enough to use the rest of the base FME code. I am wondering
if the FPGA manager can be added to the DFL. At this point, the DFL
would drive which FPGA manager is alloc'd. That way the user gets to
use all this code indfl-fme-pr.cbut with their FPGA manager.
Quoted 6 lines
I am thinking of the case of porting to a new hardware implementation for Partial Reconfiguration. Since the new hardware is completely different at the register level, we would need new a new feature id. The fme init code for this new feature should be able to call the generic code here and pass in the
fgpa_mgr_opsthat are hardware specific.
Per my understanding, if we introduced one new private feature (with a different feature id), we could consider to reuse dfl-fme-pr.c firstly, e.g in the init function, it could check the feature id and take different code path for handling (create different fpga mgr). And for sure, we could introduce another private feature driver if existing code can't be reused at all. It depends the actual hardware implementation I think. : )
Quoted 245 lines
Quoted 245 lines
(2) a FPGA manager that can be added by device tree in the case of a platform that is using device tree. I think this will be pretty simple and can be done later when someone is actually bringing this framework up on a FPGA running under device tree. I'm thinking that the base DFL device that reads the dfl data from hardware can have a DT property that points to the FPGA manager. That manager can be saved somewhere handy like the pdata and passed down to this code, which realizes it can use that existing device and doesn't need to alloc a platform device. But again, that's probably best done later.
Quoted 234 lines
drivers/fpga/dfl-fme-pr.c new file +234
-0+if (!mgr) +return ERR_PTR (ret); + + mgr->dev.parent = &fme->dev; + + pres =platform_get_resource (fme,IORESOURCE_MEM , + feature->resource_index); +if (!pres) { + ret = -ENODEV ; + goto create_mgr_err; + } + +memset (&res,0 ,sizeof (struct resource )); + + res.start = pres->start; + res.end = pres->end; + res.name = pres->name; + res.flags =IORESOURCE_MEM ; + + ret =platform_device_add_resources (mgr, &res,1 ); +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); +} + +/** +* fpga_fme_destroy_mgr - destroy fpga mgr platform device +* @pdata: fme platform device's pdata +*/ +static void fpga_fme_destroy_mgr (struct feature_platform_data *pdata) +{ +struct fpga_fme *priv =fpga_pdata_get_private (pdata); + +platform_device_unregister (priv->mgr); +} + +/** +* fpga_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 fme_bridge * +fpga_fme_create_bridge (struct feature_platform_data *pdata,int port_id) +{ +struct device *dev = &pdata->dev->dev; +struct fme_br_pdata br_pdata; +struct 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.port =fpga_cdev_find_port (fpga_pdata_to_fpga_cdev (pdata), + &port_id, fpga_port_check_id); +if (!br_pdata.port) +return ERR_PTR (-ENODEV ); + +/* +* Each FPGA device may have more than one port, so allocate platform +* device using the same port platform device id. +*/ + fme_br->br =platform_device_alloc (FPGA_DFL_FME_BRIDGE , + br_pdata.port->id); +if (!fme_br->br) { + ret = -ENOMEM ; + goto create_br_err; + } + + 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); +put_device (&br_pdata.port->dev); +return ERR_PTR (ret); +} + +/** +* fpga_fme_destroy_bridge - destroy fpga bridge platform device +* @fme_br: fme bridge to destroy +*/ +static void fpga_fme_destroy_bridge (struct fme_bridge *fme_br) +{ +struct fme_br_pdata *br_pdata =dev_get_platdata (&fme_br->br->dev); + +put_device (&br_pdata->port->dev); +platform_device_unregister (fme_br->br); +} + +/** +* fpga_fme_destroy_bridge - destroy all fpga bridge platform device +* @pdata: fme platform device's pdata +*/ +static void fpga_fme_destroy_bridges (struct feature_platform_data *pdata) +{ +struct fpga_fme *priv =fpga_pdata_get_private (pdata); +struct fme_bridge *fbridge, *tmp; + +list_for_each_entry_safe (fbridge, tmp, &priv->bridge_list, node) { +list_del (&fbridge->node); +fpga_fme_destroy_bridge (fbridge); + } +} + +/** +* fpga_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 fme_region * +fpga_fme_create_region (struct feature_platform_data *pdata, +struct platform_device *mgr, +struct platform_device *br,int port_id) +{ +struct device *dev = &pdata->dev->dev; +struct fme_region_pdata region_pdata; +struct 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 (FPGA_DFL_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); +} + +/** +* fpga_fme_destroy_region - destroy fme region +* @fme_region: fme region to destroy +*/ +static void fpga_fme_destroy_region (struct fme_region *fme_region) +{ +platform_device_unregister (fme_region->region); +} + +/** +* fpga_fme_destroy_regions - destroy all fme regions +* @pdata: fme platform device's pdata +*/ +static void fpga_fme_destroy_regions (struct feature_platform_data *pdata) +{ +struct fpga_fme *priv =fpga_pdata_get_private (pdata); +struct fme_region *fme_region, *tmp; + +list_for_each_entry_safe (fme_region, tmp, &priv->region_list, node) { +list_del (&fme_region->node); +fpga_fme_destroy_region (fme_region); + } +} + +static int pr_mgmt_init (struct platform_device *pdev,struct feature *feature) +{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +void __iomem *fme_hdr; +struct platform_device *mgr; +struct fme_region *fme_region; +struct fme_bridge *fme_br; +struct fpga_fme *priv; +int ret = -ENODEV , i =0 ; +u64 fme_cap, port_offset; + + fme_hdr =get_feature_ioaddr_by_id (&pdev->dev, +FME_FEATURE_ID_HEADER ); + +mutex_lock (&pdata->lock); + priv =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 =fpga_fme_create_mgr (pdata); +if (IS_ERR (mgr)) { +dev_err (&pdev->dev,"fail to create fpga mgr pdev\n" ); + goto unlock; + } + + priv->mgr = mgr;
Quoted 8 lines
Quoted 3 lines
drivers/fpga/dfl-fme-pr.c line 426
Quoted 3 lines
drivers/fpga/dfl-fme-pr.c new file +3
-0+ +/* Read capability register to check number of regions and bridges */ + fme_cap =readq (fme_hdr +FME_HDR_CAP );I don't think this capability field exists in currently deployed FPGA images using DFH. I believe this difference requires a new feature id to differentiate between deployed FPGA images and images with this new "feature".
I'm not sure about the "currently deployed FPGA images using DFH", this feature driver is only for FME PR private feature (Yes, FME's private feature with id = 0x5). But if they use DFH, so they must have their own feature ids as that field is in the DFH, isn't it? Then we should be able to distinguish them based on that.
Thanks
Hao
Quoted 306 lines
Quoted 306 lines
Quoted 140 lines
drivers/fpga/dfl-fme-pr.c new file +71
-0+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 =fpga_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 =fpga_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: +fpga_fme_destroy_regions (pdata); +fpga_fme_destroy_bridges (pdata); +fpga_fme_destroy_mgr (pdata); +unlock: +mutex_unlock (&pdata->lock); +return ret; +} + +static void pr_mgmt_uinit (struct platform_device *pdev,struct feature *feature) +{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *priv; + +mutex_lock (&pdata->lock); + priv =fpga_pdata_get_private (pdata); + +fpga_fme_destroy_regions (pdata); +fpga_fme_destroy_bridges (pdata); +fpga_fme_destroy_mgr (pdata); +mutex_unlock (&pdata->lock); +} + +static long fme_pr_ioctl (struct platform_device *pdev,struct feature *feature, +unsigned int cmd,unsigned long arg) +{ +long ret; + +switch (cmd) { +case FPGA_FME_PORT_PR : + ret =fme_pr (pdev, arg); +break ; +default : + ret = -ENODEV ; + } + +return ret; +} + +const struct 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 +62
-0@@ -0,0 +1,113 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Header file for FPGA Management Engine (FME) Partial Reconfiguration Driver +* +* Copyright (C) 2017 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 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 fme_region { +struct platform_device *region; +struct list_head node; +int port_id; +}; + +/** +* struct 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 fme_region_pdata { +struct platform_device *mgr; +struct platform_device *br; +int region_id; +}; + +/** +* struct fme_bridge - FME fpga bridge data structure +* +* @br: platform device of the FPGA bridge. +* @node: used to link fme_bridge to a list. +*/ +struct fme_bridge { +struct platform_device *br; +struct list_head node; +}; + +/** +* struct fme_bridge_pdata - platform data for FME bridge platform device. +* drivers/fpga/dfl-fme-pr.h line 72
Quoted 10 lines
drivers/fpga/dfl-fme-pr.h new file +10
-0+* @port: platform device of the port feature dev. +*/ +struct fme_br_pdata { +struct platform_device *port; +}; + +#define FPGA_DFL_FME_MGR "dfl-fme-mgr" +#define FPGA_DFL_FME_BRIDGE "dfl-fme-bridge" +#define FPGA_DFL_FME_REGION "dfl-fme-region" +Everything in
dfl-fme-pr.hup to this point is good and general and should remain indfl-fme-pr.h. The register #defines for this FME's FPGA manager device below should be associated with the FPGA manager driver. Sorry if the way I stated that in the v3 review wasn't clear.Quoted 29 lines
drivers/fpga/dfl-fme-pr.h new file +29
-0+/* 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(0)/* Reset PR engine */ +#define FME_PR_CTRL_PR_RSTACK BIT(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(12)/* Start to request for PR service */ +#define FME_PR_CTRL_PR_COMPLETE BIT(13)/* PR data push complete notification */ + +/* 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(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 */ drivers/fpga/dfl-fme-pr.h line 111
Quoted 10 lines
drivers/fpga/dfl-fme-pr.h new file +10
-0+/* PR Operation errors detected. */ +#define FME_PR_ERR_OPERATION_ERR BIT(0) +/* CRC error detected. */ +#define FME_PR_ERR_CRC_ERR BIT(1) +/* Incompatible PR bitstream detected. */ +#define FME_PR_ERR_INCOMPATIBLE_BS BIT(2) +/* PR data push protocol violated. */ +#define FME_PR_ERR_PROTOCOL_ERR BIT(3) +/* PR data fifo overflow error detected */ +#define FME_PR_ERR_FIFO_OVERFLOW BIT(4)This stuff is specific to this FPGA manager device, so it should either be in the
dfl-fme-mgr.cor in adfl-fme-mgr.hQuoted 97 lines
drivers/fpga/dfl-fme-pr.h new file +2
-0+ +#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 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 fpga_fme - fpga 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 fpga_fme { +struct platform_device *mgr; +struct list_head region_list; +struct list_head bridge_list; +struct feature_platform_data *pdata; +}; + +extern const struct feature_ops pr_mgmt_ops; + +#endif /* __DFL_FME_H */ include/uapi/linux/fpga-dfl.h +27
-1@@ -14,6 +14,8 @@#ifndef _UAPI_LINUX_FPGA_DFL_H#define _UAPI_LINUX_FPGA_DFL_H +#include <linux/types.h> +#define FPGA_API_VERSION 0/* @@ -26,6 +28,7 @@#define FPGA_MAGIC 0xB6#define FPGA_BASE 0 +#define FME_BASE 0x80/** * FPGA_GET_API_VERSION - _IO(FPGA_MAGIC, FPGA_BASE + 0) @@ -45,4 +48,28 @@#define FPGA_CHECK_EXTENSION _IO(FPGA_MAGIC, FPGA_BASE + 1) +/* IOCTLs for FME file descriptor */ + +/** +* FPGA_FME_PORT_PR - _IOW(FPGA_MAGIC, FME_BASE + 0, struct 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 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 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 FPGA_FME_PORT_PR _IO(FPGA_MAGIC, FME_BASE + 0) +#endif /* _UAPI_LINUX_FPGA_DFL_H */ --Quoted 2 lines
2.7.4
Thanks,
Alan
--
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
Re: [PATCH v4 14/24] fpga: dfl: fme: add partial reconfiguration sub feature support
Quoted 11 lines · Wu Hao
Quoted 10 lines · On Sun, Mar 11, 2018 at 01:09:31PM -0700, [email protected] wrote:
Hi Hao,
I do think we should consider different hw implementations with this code because it does look like most of it is generic. Specifically, I think we should consider DFH based fpga images that have been shipped already, and I think we need to consider new hardware implementations as well. Full disclosure, I am particularly interested in porting to a new hw implementation for partial reconfiguration.
Hi Matthew,
The manager may not be the only thing that has to change for a new implementation, i.e. will your 'port' be able to work with this patchset? In the current implementation, the port is part of the dfl enumeration code (dfl.c and dfl.h) rather than being part of the bridge for some reason. We discussed the possibility of putting the port enable/disable code into the bridge driver [1], but that didn't seem feasible at least last December. I still would feel more confident if port were part of the bridge instead of part of dfl.
Alan
Re: [PATCH v4 14/24] fpga: dfl: fme: add partial reconfiguration sub feature support
In reply to Wu HaoOn Mon, 12 Mar 2018, Wu Hao wrote:
Hi Hao,
Please see my two comments inline.
Thanks,
Matthew Gerlach
Quoted 412 lines · On Sun, Mar 11, 2018 at 01:09:31PM -0700, [email protected] wrote:
Quoted 13 lines · Alan Tull
Hi Hao,
I do think we should consider different hw implementations with this code because it does look like most of it is generic. Specifically, I think we should consider DFH based fpga images that have been shipped already, and I think we need to consider new hardware implementations as well. Full disclosure, I am particularly interested in porting to a new hw implementation for partial reconfiguration.
Hi Matthew,
This
dfl-fme-pr.cdriver is developed for the PR sub feature (feature id =0x5), but we can reuse it for any cases if possible.Quoted 2 lines
Please see some comments below.
Thanks for the comments, please see my comments inline.
Quoted 380 lines
Matthew Gerlach
Quoted 370 lines · Wu Hao
Hi Hao,
We are going to want to be able use different FPGA managers with this framework. The different manager may be part of a different FME in fabric or it may be a hardware FPGA manager. Fortunately, at this point now the changes, noted below, to get there are pretty small.
Quoted 111 lines
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:
*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]>---
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.
---drivers/fpga/Makefile | 2 +- drivers/fpga/dfl-fme-main.c | 45 +++- drivers/fpga/dfl-fme-pr.c | 497 ++++++++++++++++++++++++++++++++++++++++++ drivers/fpga/dfl-fme-pr.h | 113 ++++++++++ drivers/fpga/dfl-fme.h | 38 ++++ include/uapi/linux/fpga-dfl.h | 27 +++ 6 files changed, 720 insertions(+), 2 deletions(-)create mode 100644
drivers/fpga/dfl-fme-pr.c
create mode 100644drivers/fpga/dfl-fme-pr.h
create mode 100644drivers/fpga/dfl-fme.hdrivers/fpga/Makefile +0
-0@@ -32,7 +32,7 @@ obj-$(CONFIG_OF_FPGA_REGION) += of-fpga-region.oobj-$(CONFIG_FPGA_DFL) += dfl.o
obj-$(CONFIG_FPGA_DFL_FME) += dfl-fme.odrivers/fpga/Makefile +1
-1-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 +24
-0@@ -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)@@ -111,6 +112,10 @@ static struct feature_driver fme_feature_drvs[] = { .ops = &fme_hdr_ops, }, { + .id = FME_FEATURE_ID_PR_MGMT, + .ops = &pr_mgmt_ops, + }, + { .ops = NULL, }, };@@ -194,14 +199,49 @@ static const struct file_operations fme_fops = { .unlocked_ioctl = fme_ioctl, }; +static int fme_dev_init (struct platform_device *pdev) +{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *fme; + + fme =devm_kzalloc (&pdev->dev,sizeof (*fme),GFP_KERNEL ); +if (!fme) +return -ENOMEM ; + + fme->pdata = pdata; + +mutex_lock (&pdata->lock); +fpga_pdata_set_private (pdata, fme); +mutex_unlock (&pdata->lock); + +return 0 ; +} + +static void fme_dev_destroy (struct platform_device *pdev)drivers/fpga/dfl-fme-main.c static const struct file_operations fme_fops = { · line 230
Quoted 10 lines
drivers/fpga/dfl-fme-main.c +10
-0+{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *fme; + +mutex_lock (&pdata->lock); + fme =fpga_pdata_get_private (pdata); +fpga_pdata_set_private (pdata,NULL ); +mutex_unlock (&pdata->lock); + +devm_kfree (&pdev->dev, fme);Is this needed? This is called when the device is being destroyed anyway.
Quoted 220 lines
drivers/fpga/dfl-fme-main.c +7
-1+} +static int fme_probe (struct platform_device *pdev) {int ret; - ret =fpga_dev_feature_init (pdev, fme_feature_drvs); + ret =fme_dev_init (pdev);if (ret) goto exit; + ret =fpga_dev_feature_init (pdev, fme_feature_drvs); +if (ret) + goto dev_destroy; + ret =fpga_register_dev_ops (pdev, &fme_fops,THIS_MODULE );if (ret) goto feature_uinit;@@ -210,6 +250,8 @@ static int fme_probe(struct platform_device *pdev)
feature_uinit:fpga_dev_feature_uinit(pdev);drivers/fpga/dfl-fme-main.c +2
-0+dev_destroy: +fme_dev_destroy (pdev);exit:
return ret; }drivers/fpga/dfl-fme-main.c +1
-0@@ -218,6 +260,7 @@ static int fme_remove(struct platform_device *pdev) {fpga_dev_feature_uinit (pdev);fpga_unregister_dev_ops (pdev); +fme_dev_destroy (pdev);return 0 ; }drivers/fpga/dfl-fme-pr.c new file +179
-0@@ -0,0 +1,497 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Driver for FPGA Management Engine (FME) Partial Reconfiguration +* +* Copyright (C) 2017 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 fme_region * +find_fme_region_by_port_id (struct fpga_fme *fme,int port_id) +{ +struct 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 fpga_fme_region_match (struct device *dev,const void *data) +{ +return dev->parent == data; +} + +static struct fpga_region * +fpga_fme_region_find (struct fpga_fme *fme,int port_id) +{ +struct fme_region *fme_region; +struct fpga_region *region; + + fme_region =find_fme_region_by_port_id (fme, port_id); +if (!fme_region) +return NULL ; + + region =fpga_region_class_find (NULL , &fme_region->region->dev, + fpga_fme_region_match); +if (!region) +return NULL ; + +return region; +} + +static int fme_pr (struct platform_device *pdev,unsigned long arg) +{ +void __user *argp = (void __user *)arg; +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *fme; +struct fpga_image_info *info; +struct fpga_region *region; +struct fpga_fme_port_pr port_pr; +unsigned long minsz; +void __iomem *fme_hdr; +void *buf =NULL ; +int ret =0 ; +u64 v; + + minsz = offsetofend(struct 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 =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 =fpga_pdata_get_private (pdata); +/* fme device has been unregistered. */ +if (!fme) { + ret = -EINVAL ; + goto unlock_exit; + } + + region =fpga_fme_region_find (fme, port_pr.port_id); +if (!region) { + ret = -EINVAL ; + goto unlock_exit; + } + +fpga_image_info_free (region->info); + + 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); + +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; +} + +/** +* fpga_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 * +fpga_fme_create_mgr (struct feature_platform_data *pdata) +{ +struct platform_device *mgr, *fme = pdata->dev; +struct feature *feature; +struct resource res; +struct resource *pres; +int ret = -ENOMEM ;drivers/fpga/dfl-fme-pr.c line 189
Quoted 10 lines
drivers/fpga/dfl-fme-pr.c new file +10
-0+ + feature =get_feature_by_id (&pdata->dev->dev,FME_FEATURE_ID_PR_MGMT ); +if (!feature) +return ERR_PTR (-ENODEV ); + +/* +* Each FME has only one fpga-mgr, so allocate platform device using +* the same FME platform device id. +*/ + mgr =platform_device_alloc (FPGA_DFL_FME_MGR , fme->id);At this point, the framework is assuming all FME's include the same FPGA manager device which would use the driver in
dfl-fme-mgr.c.I'm thinking of two cases where the manager isn't the same as a
dfl-fme-mgr.cmanager are a bit different:Quoted 6 lines
(1) a FME-based FPGA manager, but different implementation, different registers. The constraint is that the port implementation has to be
similar enough to use the rest of the base FME code. I am wondering
if the FPGA manager can be added to the DFL. At this point, the DFL
would drive which FPGA manager is alloc'd. That way the user gets to
use all this code indfl-fme-pr.cbut with their FPGA manager.Quoted 6 lines
I am thinking of the case of porting to a new hardware implementation for Partial Reconfiguration. Since the new hardware is completely different at the register level, we would need new a new feature id. The fme init code for this new feature should be able to call the generic code here and pass in the
fgpa_mgr_opsthat are hardware specific.
Quoted 6 lines
Per my understanding, if we introduced one new private feature (with a different feature id), we could consider to reuse
dfl-fme-pr.cfirstly, e.g in the init function, it could check the feature id and take different code path for handling (create different fpga mgr). And for sure, we could introduce another private feature driver if existing code can't be reused at all. It depends the actual hardware implementation I think. : )
It sounds to me like we are in aggreement that a lot of dfl-fme-pr.c could be reused by another hardware implementation. I am currently scoping Partial Reconfiguration for a FPGA that is not the Arria10, and I think this much of dfl-fme-pr.c could be reused for that different hw.
Quoted 255 lines
Quoted 246 lines
Quoted 246 lines
(2) a FPGA manager that can be added by device tree in the case of a platform that is using device tree. I think this will be pretty simple and can be done later when someone is actually bringing this framework up on a FPGA running under device tree. I'm thinking that the base DFL device that reads the dfl data from hardware can have a DT property that points to the FPGA manager. That manager can be saved somewhere handy like the pdata and passed down to this code, which realizes it can use that existing device and doesn't need to alloc a platform device. But again, that's probably best done later.
Quoted 234 lines
drivers/fpga/dfl-fme-pr.c new file +234
-0+if (!mgr) +return ERR_PTR (ret); + + mgr->dev.parent = &fme->dev; + + pres =platform_get_resource (fme,IORESOURCE_MEM , + feature->resource_index); +if (!pres) { + ret = -ENODEV ; + goto create_mgr_err; + } + +memset (&res,0 ,sizeof (struct resource )); + + res.start = pres->start; + res.end = pres->end; + res.name = pres->name; + res.flags =IORESOURCE_MEM ; + + ret =platform_device_add_resources (mgr, &res,1 ); +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); +} + +/** +* fpga_fme_destroy_mgr - destroy fpga mgr platform device +* @pdata: fme platform device's pdata +*/ +static void fpga_fme_destroy_mgr (struct feature_platform_data *pdata) +{ +struct fpga_fme *priv =fpga_pdata_get_private (pdata); + +platform_device_unregister (priv->mgr); +} + +/** +* fpga_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 fme_bridge * +fpga_fme_create_bridge (struct feature_platform_data *pdata,int port_id) +{ +struct device *dev = &pdata->dev->dev; +struct fme_br_pdata br_pdata; +struct 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.port =fpga_cdev_find_port (fpga_pdata_to_fpga_cdev (pdata), + &port_id, fpga_port_check_id); +if (!br_pdata.port) +return ERR_PTR (-ENODEV ); + +/* +* Each FPGA device may have more than one port, so allocate platform +* device using the same port platform device id. +*/ + fme_br->br =platform_device_alloc (FPGA_DFL_FME_BRIDGE , + br_pdata.port->id); +if (!fme_br->br) { + ret = -ENOMEM ; + goto create_br_err; + } + + 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); +put_device (&br_pdata.port->dev); +return ERR_PTR (ret); +} + +/** +* fpga_fme_destroy_bridge - destroy fpga bridge platform device +* @fme_br: fme bridge to destroy +*/ +static void fpga_fme_destroy_bridge (struct fme_bridge *fme_br) +{ +struct fme_br_pdata *br_pdata =dev_get_platdata (&fme_br->br->dev); + +put_device (&br_pdata->port->dev); +platform_device_unregister (fme_br->br); +} + +/** +* fpga_fme_destroy_bridge - destroy all fpga bridge platform device +* @pdata: fme platform device's pdata +*/ +static void fpga_fme_destroy_bridges (struct feature_platform_data *pdata) +{ +struct fpga_fme *priv =fpga_pdata_get_private (pdata); +struct fme_bridge *fbridge, *tmp; + +list_for_each_entry_safe (fbridge, tmp, &priv->bridge_list, node) { +list_del (&fbridge->node); +fpga_fme_destroy_bridge (fbridge); + } +} + +/** +* fpga_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 fme_region * +fpga_fme_create_region (struct feature_platform_data *pdata, +struct platform_device *mgr, +struct platform_device *br,int port_id) +{ +struct device *dev = &pdata->dev->dev; +struct fme_region_pdata region_pdata; +struct 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 (FPGA_DFL_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); +} + +/** +* fpga_fme_destroy_region - destroy fme region +* @fme_region: fme region to destroy +*/ +static void fpga_fme_destroy_region (struct fme_region *fme_region) +{ +platform_device_unregister (fme_region->region); +} + +/** +* fpga_fme_destroy_regions - destroy all fme regions +* @pdata: fme platform device's pdata +*/ +static void fpga_fme_destroy_regions (struct feature_platform_data *pdata) +{ +struct fpga_fme *priv =fpga_pdata_get_private (pdata); +struct fme_region *fme_region, *tmp; + +list_for_each_entry_safe (fme_region, tmp, &priv->region_list, node) { +list_del (&fme_region->node); +fpga_fme_destroy_region (fme_region); + } +} + +static int pr_mgmt_init (struct platform_device *pdev,struct feature *feature) +{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +void __iomem *fme_hdr; +struct platform_device *mgr; +struct fme_region *fme_region; +struct fme_bridge *fme_br; +struct fpga_fme *priv; +int ret = -ENODEV , i =0 ; +u64 fme_cap, port_offset; + + fme_hdr =get_feature_ioaddr_by_id (&pdev->dev, +FME_FEATURE_ID_HEADER ); + +mutex_lock (&pdata->lock); + priv =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 =fpga_fme_create_mgr (pdata); +if (IS_ERR (mgr)) { +dev_err (&pdev->dev,"fail to create fpga mgr pdev\n" ); + goto unlock; + } + + priv->mgr = mgr;Quoted 8 lines
Quoted 3 lines
drivers/fpga/dfl-fme-pr.c line 426
Quoted 3 lines
drivers/fpga/dfl-fme-pr.c new file +3
-0+ +/* Read capability register to check number of regions and bridges */ + fme_cap =readq (fme_hdr +FME_HDR_CAP );I don't think this capability field exists in currently deployed FPGA images using DFH. I believe this difference requires a new feature id to differentiate between deployed FPGA images and images with this new "feature".
Quoted 8 lines
I'm not sure about the "currently deployed FPGA images using DFH", this feature driver is only for FME PR private feature (Yes, FME's private feature with id =
0x5). But if they use DFH, so they must have their own feature ids as that field is in the DFH, isn't it? Then we should be able to distinguish them based on that.Thanks
Hao
I am specifically thinking of the FPGA images associated with DCP 1.0. Should this driver work with those images? It looks to me that this capability register is not in the DCP 1.0.
Quoted 308 lines
Quoted 307 lines
Quoted 307 lines
Quoted 141 lines
drivers/fpga/dfl-fme-pr.c new file +71
-0+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 =fpga_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 =fpga_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: +fpga_fme_destroy_regions (pdata); +fpga_fme_destroy_bridges (pdata); +fpga_fme_destroy_mgr (pdata); +unlock: +mutex_unlock (&pdata->lock); +return ret; +} + +static void pr_mgmt_uinit (struct platform_device *pdev,struct feature *feature) +{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *priv; + +mutex_lock (&pdata->lock); + priv =fpga_pdata_get_private (pdata); + +fpga_fme_destroy_regions (pdata); +fpga_fme_destroy_bridges (pdata); +fpga_fme_destroy_mgr (pdata); +mutex_unlock (&pdata->lock); +} + +static long fme_pr_ioctl (struct platform_device *pdev,struct feature *feature, +unsigned int cmd,unsigned long arg) +{ +long ret; + +switch (cmd) { +case FPGA_FME_PORT_PR : + ret =fme_pr (pdev, arg); +break ; +default : + ret = -ENODEV ; + } + +return ret; +} + +const struct 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 +62
-0@@ -0,0 +1,113 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Header file for FPGA Management Engine (FME) Partial Reconfiguration Driver +* +* Copyright (C) 2017 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 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 fme_region { +struct platform_device *region; +struct list_head node; +int port_id; +}; + +/** +* struct 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 fme_region_pdata { +struct platform_device *mgr; +struct platform_device *br; +int region_id; +}; + +/** +* struct fme_bridge - FME fpga bridge data structure +* +* @br: platform device of the FPGA bridge. +* @node: used to link fme_bridge to a list. +*/ +struct fme_bridge { +struct platform_device *br; +struct list_head node; +}; + +/** +* struct fme_bridge_pdata - platform data for FME bridge platform device. +* drivers/fpga/dfl-fme-pr.h line 72
Quoted 10 lines
drivers/fpga/dfl-fme-pr.h new file +10
-0+* @port: platform device of the port feature dev. +*/ +struct fme_br_pdata { +struct platform_device *port; +}; + +#define FPGA_DFL_FME_MGR "dfl-fme-mgr" +#define FPGA_DFL_FME_BRIDGE "dfl-fme-bridge" +#define FPGA_DFL_FME_REGION "dfl-fme-region" +Everything in
dfl-fme-pr.hup to this point is good and general and should remain indfl-fme-pr.h. The register #defines for this FME's FPGA manager device below should be associated with the FPGA manager driver. Sorry if the way I stated that in the v3 review wasn't clear.Quoted 29 lines
drivers/fpga/dfl-fme-pr.h new file +29
-0+/* 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(0)/* Reset PR engine */ +#define FME_PR_CTRL_PR_RSTACK BIT(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(12)/* Start to request for PR service */ +#define FME_PR_CTRL_PR_COMPLETE BIT(13)/* PR data push complete notification */ + +/* 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(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 */ drivers/fpga/dfl-fme-pr.h line 111
Quoted 10 lines
drivers/fpga/dfl-fme-pr.h new file +10
-0+/* PR Operation errors detected. */ +#define FME_PR_ERR_OPERATION_ERR BIT(0) +/* CRC error detected. */ +#define FME_PR_ERR_CRC_ERR BIT(1) +/* Incompatible PR bitstream detected. */ +#define FME_PR_ERR_INCOMPATIBLE_BS BIT(2) +/* PR data push protocol violated. */ +#define FME_PR_ERR_PROTOCOL_ERR BIT(3) +/* PR data fifo overflow error detected */ +#define FME_PR_ERR_FIFO_OVERFLOW BIT(4)This stuff is specific to this FPGA manager device, so it should either be in the
dfl-fme-mgr.cor in adfl-fme-mgr.hQuoted 97 lines
drivers/fpga/dfl-fme-pr.h new file +2
-0+ +#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 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 fpga_fme - fpga 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 fpga_fme { +struct platform_device *mgr; +struct list_head region_list; +struct list_head bridge_list; +struct feature_platform_data *pdata; +}; + +extern const struct feature_ops pr_mgmt_ops; + +#endif /* __DFL_FME_H */ include/uapi/linux/fpga-dfl.h +27
-1@@ -14,6 +14,8 @@#ifndef _UAPI_LINUX_FPGA_DFL_H#define _UAPI_LINUX_FPGA_DFL_H +#include <linux/types.h> +#define FPGA_API_VERSION 0/* @@ -26,6 +28,7 @@#define FPGA_MAGIC 0xB6#define FPGA_BASE 0 +#define FME_BASE 0x80/** * FPGA_GET_API_VERSION - _IO(FPGA_MAGIC, FPGA_BASE + 0) @@ -45,4 +48,28 @@#define FPGA_CHECK_EXTENSION _IO(FPGA_MAGIC, FPGA_BASE + 1) +/* IOCTLs for FME file descriptor */ + +/** +* FPGA_FME_PORT_PR - _IOW(FPGA_MAGIC, FME_BASE + 0, struct 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 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 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 FPGA_FME_PORT_PR _IO(FPGA_MAGIC, FME_BASE + 0) +#endif /* _UAPI_LINUX_FPGA_DFL_H */ --Quoted 2 lines
2.7.4
Thanks,
Alan
--
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
Re: [PATCH v4 14/24] fpga: dfl: fme: add partial reconfiguration sub feature support
Quoted 430 lines · On Mon, Mar 12, 2018 at 02:36:48PM -0700, [email protected] wrote:
On Mon, 12 Mar 2018, Wu Hao wrote:
Hi Hao,
Please see my two comments inline.
Thanks,
Matthew GerlachQuoted 412 lines · On Sun, Mar 11, 2018 at 01:09:31PM -0700, [email protected] wrote:
Quoted 13 lines · Alan Tull
Hi Hao,
I do think we should consider different hw implementations with this code because it does look like most of it is generic. Specifically, I think we should consider DFH based fpga images that have been shipped already, and I think we need to consider new hardware implementations as well. Full disclosure, I am particularly interested in porting to a new hw implementation for partial reconfiguration.
Hi Matthew,
This
dfl-fme-pr.cdriver is developed for the PR sub feature (feature id =0x5), but we can reuse it for any cases if possible.Quoted 2 lines
Please see some comments below.
Thanks for the comments, please see my comments inline.
Quoted 380 lines
Matthew Gerlach
Quoted 370 lines · Wu Hao
Hi Hao,
We are going to want to be able use different FPGA managers with this framework. The different manager may be part of a different FME in fabric or it may be a hardware FPGA manager. Fortunately, at this point now the changes, noted below, to get there are pretty small.
Quoted 111 lines
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:
*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]>---
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.
---drivers/fpga/Makefile | 2 +- drivers/fpga/dfl-fme-main.c | 45 +++- drivers/fpga/dfl-fme-pr.c | 497 ++++++++++++++++++++++++++++++++++++++++++ drivers/fpga/dfl-fme-pr.h | 113 ++++++++++ drivers/fpga/dfl-fme.h | 38 ++++ include/uapi/linux/fpga-dfl.h | 27 +++ 6 files changed, 720 insertions(+), 2 deletions(-)create mode 100644
drivers/fpga/dfl-fme-pr.c
create mode 100644drivers/fpga/dfl-fme-pr.h
create mode 100644drivers/fpga/dfl-fme.hdrivers/fpga/Makefile +0
-0@@ -32,7 +32,7 @@ obj-$(CONFIG_OF_FPGA_REGION) += of-fpga-region.oobj-$(CONFIG_FPGA_DFL) += dfl.o
obj-$(CONFIG_FPGA_DFL_FME) += dfl-fme.odrivers/fpga/Makefile +1
-1-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 +24
-0@@ -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)@@ -111,6 +112,10 @@ static struct feature_driver fme_feature_drvs[] = { .ops = &fme_hdr_ops, }, { + .id = FME_FEATURE_ID_PR_MGMT, + .ops = &pr_mgmt_ops, + }, + { .ops = NULL, }, };@@ -194,14 +199,49 @@ static const struct file_operations fme_fops = { .unlocked_ioctl = fme_ioctl, }; +static int fme_dev_init (struct platform_device *pdev) +{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *fme; + + fme =devm_kzalloc (&pdev->dev,sizeof (*fme),GFP_KERNEL ); +if (!fme) +return -ENOMEM ; + + fme->pdata = pdata; + +mutex_lock (&pdata->lock); +fpga_pdata_set_private (pdata, fme); +mutex_unlock (&pdata->lock); + +return 0 ; +} + +static void fme_dev_destroy (struct platform_device *pdev)drivers/fpga/dfl-fme-main.c static const struct file_operations fme_fops = { · line 230
Quoted 10 lines
drivers/fpga/dfl-fme-main.c +10
-0+{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *fme; + +mutex_lock (&pdata->lock); + fme =fpga_pdata_get_private (pdata); +fpga_pdata_set_private (pdata,NULL ); +mutex_unlock (&pdata->lock); + +devm_kfree (&pdev->dev, fme);Is this needed? This is called when the device is being destroyed anyway.
Quoted 220 lines
drivers/fpga/dfl-fme-main.c +7
-1+} +static int fme_probe (struct platform_device *pdev) {int ret; - ret =fpga_dev_feature_init (pdev, fme_feature_drvs); + ret =fme_dev_init (pdev);if (ret) goto exit; + ret =fpga_dev_feature_init (pdev, fme_feature_drvs); +if (ret) + goto dev_destroy; + ret =fpga_register_dev_ops (pdev, &fme_fops,THIS_MODULE );if (ret) goto feature_uinit;@@ -210,6 +250,8 @@ static int fme_probe(struct platform_device *pdev)
feature_uinit:fpga_dev_feature_uinit(pdev);drivers/fpga/dfl-fme-main.c +2
-0+dev_destroy: +fme_dev_destroy (pdev);exit:
return ret; }drivers/fpga/dfl-fme-main.c +1
-0@@ -218,6 +260,7 @@ static int fme_remove(struct platform_device *pdev) {fpga_dev_feature_uinit (pdev);fpga_unregister_dev_ops (pdev); +fme_dev_destroy (pdev);return 0 ; }drivers/fpga/dfl-fme-pr.c new file +179
-0@@ -0,0 +1,497 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Driver for FPGA Management Engine (FME) Partial Reconfiguration +* +* Copyright (C) 2017 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 fme_region * +find_fme_region_by_port_id (struct fpga_fme *fme,int port_id) +{ +struct 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 fpga_fme_region_match (struct device *dev,const void *data) +{ +return dev->parent == data; +} + +static struct fpga_region * +fpga_fme_region_find (struct fpga_fme *fme,int port_id) +{ +struct fme_region *fme_region; +struct fpga_region *region; + + fme_region =find_fme_region_by_port_id (fme, port_id); +if (!fme_region) +return NULL ; + + region =fpga_region_class_find (NULL , &fme_region->region->dev, + fpga_fme_region_match); +if (!region) +return NULL ; + +return region; +} + +static int fme_pr (struct platform_device *pdev,unsigned long arg) +{ +void __user *argp = (void __user *)arg; +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *fme; +struct fpga_image_info *info; +struct fpga_region *region; +struct fpga_fme_port_pr port_pr; +unsigned long minsz; +void __iomem *fme_hdr; +void *buf =NULL ; +int ret =0 ; +u64 v; + + minsz = offsetofend(struct 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 =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 =fpga_pdata_get_private (pdata); +/* fme device has been unregistered. */ +if (!fme) { + ret = -EINVAL ; + goto unlock_exit; + } + + region =fpga_fme_region_find (fme, port_pr.port_id); +if (!region) { + ret = -EINVAL ; + goto unlock_exit; + } + +fpga_image_info_free (region->info); + + 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); + +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; +} + +/** +* fpga_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 * +fpga_fme_create_mgr (struct feature_platform_data *pdata) +{ +struct platform_device *mgr, *fme = pdata->dev; +struct feature *feature; +struct resource res; +struct resource *pres; +int ret = -ENOMEM ;drivers/fpga/dfl-fme-pr.c line 189
Quoted 10 lines
drivers/fpga/dfl-fme-pr.c new file +10
-0+ + feature =get_feature_by_id (&pdata->dev->dev,FME_FEATURE_ID_PR_MGMT ); +if (!feature) +return ERR_PTR (-ENODEV ); + +/* +* Each FME has only one fpga-mgr, so allocate platform device using +* the same FME platform device id. +*/ + mgr =platform_device_alloc (FPGA_DFL_FME_MGR , fme->id);At this point, the framework is assuming all FME's include the same FPGA manager device which would use the driver in
dfl-fme-mgr.c.I'm thinking of two cases where the manager isn't the same as a
dfl-fme-mgr.cmanager are a bit different:Quoted 6 lines
(1) a FME-based FPGA manager, but different implementation, different registers. The constraint is that the port implementation has to be
similar enough to use the rest of the base FME code. I am wondering
if the FPGA manager can be added to the DFL. At this point, the DFL
would drive which FPGA manager is alloc'd. That way the user gets to
use all this code indfl-fme-pr.cbut with their FPGA manager.Quoted 6 lines
I am thinking of the case of porting to a new hardware implementation for Partial Reconfiguration. Since the new hardware is completely different at the register level, we would need new a new feature id. The fme init code for this new feature should be able to call the generic code here and pass in the
fgpa_mgr_opsthat are hardware specific.Quoted 6 lines
Per my understanding, if we introduced one new private feature (with a different feature id), we could consider to reuse
dfl-fme-pr.cfirstly, e.g in the init function, it could check the feature id and take different code path for handling (create different fpga mgr). And for sure, we could introduce another private feature driver if existing code can't be reused at all. It depends the actual hardware implementation I think. : )
Quoted 4 lines
It sounds to me like we are in aggreement that a lot of
dfl-fme-pr.ccould be reused by another hardware implementation. I am currently scoping Partial Reconfiguration for a FPGA that is not the Arria10, and I think this much ofdfl-fme-pr.ccould be reused for that different hw.
Yes, agree. : )
Quoted 262 lines
Quoted 262 lines
Quoted 247 lines
Quoted 247 lines
(2) a FPGA manager that can be added by device tree in the case of a platform that is using device tree. I think this will be pretty simple and can be done later when someone is actually bringing this framework up on a FPGA running under device tree. I'm thinking that the base DFL device that reads the dfl data from hardware can have a DT property that points to the FPGA manager. That manager can be saved somewhere handy like the pdata and passed down to this code, which realizes it can use that existing device and doesn't need to alloc a platform device. But again, that's probably best done later.
Quoted 234 lines
drivers/fpga/dfl-fme-pr.c new file +234
-0+if (!mgr) +return ERR_PTR (ret); + + mgr->dev.parent = &fme->dev; + + pres =platform_get_resource (fme,IORESOURCE_MEM , + feature->resource_index); +if (!pres) { + ret = -ENODEV ; + goto create_mgr_err; + } + +memset (&res,0 ,sizeof (struct resource )); + + res.start = pres->start; + res.end = pres->end; + res.name = pres->name; + res.flags =IORESOURCE_MEM ; + + ret =platform_device_add_resources (mgr, &res,1 ); +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); +} + +/** +* fpga_fme_destroy_mgr - destroy fpga mgr platform device +* @pdata: fme platform device's pdata +*/ +static void fpga_fme_destroy_mgr (struct feature_platform_data *pdata) +{ +struct fpga_fme *priv =fpga_pdata_get_private (pdata); + +platform_device_unregister (priv->mgr); +} + +/** +* fpga_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 fme_bridge * +fpga_fme_create_bridge (struct feature_platform_data *pdata,int port_id) +{ +struct device *dev = &pdata->dev->dev; +struct fme_br_pdata br_pdata; +struct 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.port =fpga_cdev_find_port (fpga_pdata_to_fpga_cdev (pdata), + &port_id, fpga_port_check_id); +if (!br_pdata.port) +return ERR_PTR (-ENODEV ); + +/* +* Each FPGA device may have more than one port, so allocate platform +* device using the same port platform device id. +*/ + fme_br->br =platform_device_alloc (FPGA_DFL_FME_BRIDGE , + br_pdata.port->id); +if (!fme_br->br) { + ret = -ENOMEM ; + goto create_br_err; + } + + 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); +put_device (&br_pdata.port->dev); +return ERR_PTR (ret); +} + +/** +* fpga_fme_destroy_bridge - destroy fpga bridge platform device +* @fme_br: fme bridge to destroy +*/ +static void fpga_fme_destroy_bridge (struct fme_bridge *fme_br) +{ +struct fme_br_pdata *br_pdata =dev_get_platdata (&fme_br->br->dev); + +put_device (&br_pdata->port->dev); +platform_device_unregister (fme_br->br); +} + +/** +* fpga_fme_destroy_bridge - destroy all fpga bridge platform device +* @pdata: fme platform device's pdata +*/ +static void fpga_fme_destroy_bridges (struct feature_platform_data *pdata) +{ +struct fpga_fme *priv =fpga_pdata_get_private (pdata); +struct fme_bridge *fbridge, *tmp; + +list_for_each_entry_safe (fbridge, tmp, &priv->bridge_list, node) { +list_del (&fbridge->node); +fpga_fme_destroy_bridge (fbridge); + } +} + +/** +* fpga_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 fme_region * +fpga_fme_create_region (struct feature_platform_data *pdata, +struct platform_device *mgr, +struct platform_device *br,int port_id) +{ +struct device *dev = &pdata->dev->dev; +struct fme_region_pdata region_pdata; +struct 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 (FPGA_DFL_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); +} + +/** +* fpga_fme_destroy_region - destroy fme region +* @fme_region: fme region to destroy +*/ +static void fpga_fme_destroy_region (struct fme_region *fme_region) +{ +platform_device_unregister (fme_region->region); +} + +/** +* fpga_fme_destroy_regions - destroy all fme regions +* @pdata: fme platform device's pdata +*/ +static void fpga_fme_destroy_regions (struct feature_platform_data *pdata) +{ +struct fpga_fme *priv =fpga_pdata_get_private (pdata); +struct fme_region *fme_region, *tmp; + +list_for_each_entry_safe (fme_region, tmp, &priv->region_list, node) { +list_del (&fme_region->node); +fpga_fme_destroy_region (fme_region); + } +} + +static int pr_mgmt_init (struct platform_device *pdev,struct feature *feature) +{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +void __iomem *fme_hdr; +struct platform_device *mgr; +struct fme_region *fme_region; +struct fme_bridge *fme_br; +struct fpga_fme *priv; +int ret = -ENODEV , i =0 ; +u64 fme_cap, port_offset; + + fme_hdr =get_feature_ioaddr_by_id (&pdev->dev, +FME_FEATURE_ID_HEADER ); + +mutex_lock (&pdata->lock); + priv =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 =fpga_fme_create_mgr (pdata); +if (IS_ERR (mgr)) { +dev_err (&pdev->dev,"fail to create fpga mgr pdev\n" ); + goto unlock; + } + + priv->mgr = mgr;Quoted 8 lines
Quoted 3 lines
drivers/fpga/dfl-fme-pr.c line 426
Quoted 3 lines
drivers/fpga/dfl-fme-pr.c new file +3
-0+ +/* Read capability register to check number of regions and bridges */ + fme_cap =readq (fme_hdr +FME_HDR_CAP );I don't think this capability field exists in currently deployed FPGA images using DFH. I believe this difference requires a new feature id to differentiate between deployed FPGA images and images with this new "feature".
I'm not sure about the "currently deployed FPGA images using DFH", this feature driver is only for FME PR private feature (Yes, FME's private feature with id =
0x5). But if they use DFH, so they must have their own feature ids as that field is in the DFH, isn't it? Then we should be able to distinguish them based on that.
Quoted 6 lines
Quoted 2 lines
Thanks
HaoI am specifically thinking of the FPGA images associated with DCP 1.0. Should this driver work with those images? It looks to me that this capability register is not in the DCP 1.0.
Sure, I verified this patchset on DCP 1.0, PR function works fine. This cap register is from FME header register set for the number of implemented ports.
Thanks
Hao
Quoted 313 lines
Quoted 300 lines
Quoted 300 lines
Quoted 300 lines
Quoted 142 lines
drivers/fpga/dfl-fme-pr.c new file +71
-0+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 =fpga_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 =fpga_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: +fpga_fme_destroy_regions (pdata); +fpga_fme_destroy_bridges (pdata); +fpga_fme_destroy_mgr (pdata); +unlock: +mutex_unlock (&pdata->lock); +return ret; +} + +static void pr_mgmt_uinit (struct platform_device *pdev,struct feature *feature) +{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_fme *priv; + +mutex_lock (&pdata->lock); + priv =fpga_pdata_get_private (pdata); + +fpga_fme_destroy_regions (pdata); +fpga_fme_destroy_bridges (pdata); +fpga_fme_destroy_mgr (pdata); +mutex_unlock (&pdata->lock); +} + +static long fme_pr_ioctl (struct platform_device *pdev,struct feature *feature, +unsigned int cmd,unsigned long arg) +{ +long ret; + +switch (cmd) { +case FPGA_FME_PORT_PR : + ret =fme_pr (pdev, arg); +break ; +default : + ret = -ENODEV ; + } + +return ret; +} + +const struct 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 +62
-0@@ -0,0 +1,113 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Header file for FPGA Management Engine (FME) Partial Reconfiguration Driver +* +* Copyright (C) 2017 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 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 fme_region { +struct platform_device *region; +struct list_head node; +int port_id; +}; + +/** +* struct 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 fme_region_pdata { +struct platform_device *mgr; +struct platform_device *br; +int region_id; +}; + +/** +* struct fme_bridge - FME fpga bridge data structure +* +* @br: platform device of the FPGA bridge. +* @node: used to link fme_bridge to a list. +*/ +struct fme_bridge { +struct platform_device *br; +struct list_head node; +}; + +/** +* struct fme_bridge_pdata - platform data for FME bridge platform device. +* drivers/fpga/dfl-fme-pr.h line 72
Quoted 10 lines
drivers/fpga/dfl-fme-pr.h new file +10
-0+* @port: platform device of the port feature dev. +*/ +struct fme_br_pdata { +struct platform_device *port; +}; + +#define FPGA_DFL_FME_MGR "dfl-fme-mgr" +#define FPGA_DFL_FME_BRIDGE "dfl-fme-bridge" +#define FPGA_DFL_FME_REGION "dfl-fme-region" +Everything in
dfl-fme-pr.hup to this point is good and general and should remain indfl-fme-pr.h. The register #defines for this FME's FPGA manager device below should be associated with the FPGA manager driver. Sorry if the way I stated that in the v3 review wasn't clear.Quoted 29 lines
drivers/fpga/dfl-fme-pr.h new file +29
-0+/* 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(0)/* Reset PR engine */ +#define FME_PR_CTRL_PR_RSTACK BIT(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(12)/* Start to request for PR service */ +#define FME_PR_CTRL_PR_COMPLETE BIT(13)/* PR data push complete notification */ + +/* 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(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 */ drivers/fpga/dfl-fme-pr.h line 111
Quoted 10 lines
drivers/fpga/dfl-fme-pr.h new file +10
-0+/* PR Operation errors detected. */ +#define FME_PR_ERR_OPERATION_ERR BIT(0) +/* CRC error detected. */ +#define FME_PR_ERR_CRC_ERR BIT(1) +/* Incompatible PR bitstream detected. */ +#define FME_PR_ERR_INCOMPATIBLE_BS BIT(2) +/* PR data push protocol violated. */ +#define FME_PR_ERR_PROTOCOL_ERR BIT(3) +/* PR data fifo overflow error detected */ +#define FME_PR_ERR_FIFO_OVERFLOW BIT(4)This stuff is specific to this FPGA manager device, so it should either be in the
dfl-fme-mgr.cor in adfl-fme-mgr.hQuoted 99 lines
drivers/fpga/dfl-fme-pr.h new file +2
-0+ +#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 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 fpga_fme - fpga 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 fpga_fme { +struct platform_device *mgr; +struct list_head region_list; +struct list_head bridge_list; +struct feature_platform_data *pdata; +}; + +extern const struct feature_ops pr_mgmt_ops; + +#endif /* __DFL_FME_H */ include/uapi/linux/fpga-dfl.h +27
-1@@ -14,6 +14,8 @@#ifndef _UAPI_LINUX_FPGA_DFL_H#define _UAPI_LINUX_FPGA_DFL_H +#include <linux/types.h> +#define FPGA_API_VERSION 0/* @@ -26,6 +28,7 @@#define FPGA_MAGIC 0xB6#define FPGA_BASE 0 +#define FME_BASE 0x80/** * FPGA_GET_API_VERSION - _IO(FPGA_MAGIC, FPGA_BASE + 0) @@ -45,4 +48,28 @@#define FPGA_CHECK_EXTENSION _IO(FPGA_MAGIC, FPGA_BASE + 1) +/* IOCTLs for FME file descriptor */ + +/** +* FPGA_FME_PORT_PR - _IOW(FPGA_MAGIC, FME_BASE + 0, struct 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 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 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 FPGA_FME_PORT_PR _IO(FPGA_MAGIC, FME_BASE + 0) +#endif /* _UAPI_LINUX_FPGA_DFL_H */ --2.7.4
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Thanks,
Alan
--
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--
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
PATCH v4 15/24 fpga: dfl-fme-pr: add compat_id support for dfl-fme-region platform device.
In reply to Wu HaoThis patch adds compat_id support when driver creates the platform device for dfl-fme-region. It allows dfl-fme-region platform driver to create fpga-region with correct compat_id.
--- drivers/fpga/dfl-fme-pr.c | 20 ++++++++++++++++++++ drivers/fpga/dfl-fme-pr.h | 3 +++ 2 files changed, 23 insertions(+)
drivers/fpga/dfl-fme-pr.c +20 -0
@@ -314,6 +314,25 @@ static void fpga_fme_destroy_bridges(struct feature_platform_data *pdata) }/** +* fpga_fme_get_region_compat_id - read region compat_id from hardware +* +* @dev: fme device. +*/ +static struct fpga_region_compat_id +fpga_fme_get_region_compat_id (struct device *dev) +{ +struct fpga_region_compat_id compat_id; +void __iomem *fme_pr; + + fme_pr =get_feature_ioaddr_by_id (dev,FME_FEATURE_ID_PR_MGMT ); + + compat_id.id_l =readq (fme_pr +FME_PR_INTFC_ID_L ); + compat_id.id_h =readq (fme_pr +FME_PR_INTFC_ID_H ); + +return compat_id; +} + +/** * fpga_fme_create_region - create fpga region platform device as child * * @pdata: fme platform device's pdata
@@ -339,6 +358,7 @@ fpga_fme_create_region(struct feature_platform_data *pdata, region_pdata.mgr = mgr; region_pdata.br = br; + region_pdata.compat_id =fpga_fme_get_region_compat_id (dev);/* * Each FPGA device may have more than one port, so allocate platform
drivers/fpga/dfl-fme-pr.h +3 -0
@@ -19,6 +19,7 @@#define __DFL_FME_PR_H#include <linux/platform_device.h> +#include <linux/fpga/fpga-region.h> /** * struct fme_region - FME fpga region data structure
@@ -39,11 +40,13 @@ struct fme_region {* @mgr: platform device of the FPGA manager. * @br: platform device of the FPGA bridge. * @region_id: region id (same as port_id). +* @compat_id: compat id of the FPGA region. */ struct fme_region_pdata {struct platform_device *mgr;struct platform_device *br;int region_id; +struct fpga_region_compat_id compat_id; };/**
Signature · 1 line
2.7.4
Re: [PATCH v4 15/24] fpga: dfl-fme-pr: add compat_id support for dfl-fme-region platform device.
On Tue, Feb 13, 2018 at 3:24 AM, Wu Hao <[email protected]> wrote:
Hi Hao,
Quoted 22 lines
This patch adds
compat_idsupport when driver creates the platform device for dfl-fme-region. It allows dfl-fme-region platform driver to create fpga-region with correctcompat_id.Signed-off-by Wu Hao <[email protected]>--- drivers/fpga/dfl-fme-pr.c | 20 ++++++++++++++++++++ drivers/fpga/dfl-fme-pr.h | 3 +++ 2 files changed, 23 insertions(+)drivers/fpga/dfl-fme-pr.c +4
-0@@ -314,6 +314,25 @@ static void fpga_fme_destroy_bridges(struct feature_platform_data *pdata) }/** +* fpga_fme_get_region_compat_id - read region compat_id from hardware +* +* @dev: fme device. +*/
drivers/fpga/dfl-fme-pr.c static void fpga_fme_destroy_bridges(struct feature_platform_data *pdata) · line 330
Quoted 10 lines
drivers/fpga/dfl-fme-pr.c +10
-0+static struct fpga_region_compat_id +fpga_fme_get_region_compat_id (struct device *dev) +{ +struct fpga_region_compat_id compat_id; +void __iomem *fme_pr; + + fme_pr =get_feature_ioaddr_by_id (dev,FME_FEATURE_ID_PR_MGMT ); + + compat_id.id_l =readq (fme_pr +FME_PR_INTFC_ID_L ); + compat_id.id_h =readq (fme_pr +FME_PR_INTFC_ID_H );
I tried building for 32 bit ARM and ran into readq and writeq not being defined. v2 had proper '#indef readq/writeq', so looks like we need that after all.
Alan
Re: [PATCH v4 15/24] fpga: dfl-fme-pr: add compat_id support for dfl-fme-region platform device.
Quoted 32 lines · Alan Tull
On Tue, Feb 13, 2018 at 3:24 AM, Wu Hao <[email protected]> wrote:
Hi Hao,
Quoted 28 lines
This patch adds
compat_idsupport when driver creates the platform device for dfl-fme-region. It allows dfl-fme-region platform driver to create fpga-region with correctcompat_id.Signed-off-by Wu Hao <[email protected]>--- drivers/fpga/dfl-fme-pr.c | 20 ++++++++++++++++++++ drivers/fpga/dfl-fme-pr.h | 3 +++ 2 files changed, 23 insertions(+)drivers/fpga/dfl-fme-pr.c +10
-0@@ -314,6 +314,25 @@ static void fpga_fme_destroy_bridges(struct feature_platform_data *pdata) }/** +* fpga_fme_get_region_compat_id - read region compat_id from hardware +* +* @dev: fme device. +*/ +static struct fpga_region_compat_id +fpga_fme_get_region_compat_id (struct device *dev) +{ +struct fpga_region_compat_id compat_id; +void __iomem *fme_pr; +
Quoted 8 lines
drivers/fpga/dfl-fme-pr.c static void fpga_fme_destroy_bridges(struct feature_platform_data *pdata) · line 330
Quoted 4 lines
drivers/fpga/dfl-fme-pr.c +4
-0+ fme_pr =get_feature_ioaddr_by_id (dev,FME_FEATURE_ID_PR_MGMT ); + + compat_id.id_l =readq (fme_pr +FME_PR_INTFC_ID_L ); + compat_id.id_h =readq (fme_pr +FME_PR_INTFC_ID_H );I tried building for 32 bit ARM and ran into readq and writeq not being defined. v2 had proper '#indef readq/writeq', so looks like we need that after all.
Sorry, it's missing a header file for dfl-fme-pr.h, as some files don't include dfl.h at this version. That header file has definitions for readq/writeq.
+#include <linux/io-64-nonatomic-lo-hi.h>
will fix it.
Thanks
Hao
Quoted 1 line
Alan
Re: [PATCH v4 15/24] fpga: dfl-fme-pr: add compat_id support for dfl-fme-region platform device.
Quoted 11 lines · Wu Hao
Quoted 9 lines · Alan Tull
drivers/fpga/dfl-fme-pr.c static void fpga_fme_destroy_bridges(struct feature_platform_data *pdata) · line 330
Quoted 3 lines · Wu Hao
drivers/fpga/dfl-fme-pr.c +3
-0+ + compat_id.id_l =readq (fme_pr +FME_PR_INTFC_ID_L ); + compat_id.id_h =readq (fme_pr +FME_PR_INTFC_ID_H );I tried building for 32 bit ARM and ran into readq and writeq not being defined. v2 had proper '#indef readq/writeq', so looks like we need that after all.
Quoted 6 lines
Sorry, it's missing a header file for
dfl-fme-pr.h, as some files don't includedfl.hat this version. That header file has definitions for readq/writeq.+#include <
linux/io-64-nonatomic-lo-hi.h>will fix it.
Hi Hao,
That sounds good. I was able to build if I added it. There are a couple issues in the enumeration code:
In file included from /home/atull/repos/linux-socfpga/include/linux/kernel.h:11:0,
from /home/atull/repos/linux-socfpga/include/linux/list.h:9, from /home/atull/repos/linux-socfpga/include/linux/module.h:9, from /home/atull/repos/linux-socfpga/drivers/fpga/dfl.c:13:/home/atull/repos/linux-socfpga/drivers/fpga/dfl.c: In function 'parse_feature_list':/home/atull/repos/linux-socfpga/include/linux/bitops.h:7:24: warning:
left shift count >= width of type [-Wshift-count-overflow]
#define BIT(nr) (1UL << (nr))
^
/home/atull/repos/linux-socfpga/drivers/fpga/dfl.h:73:19: note: in
expansion of macro 'BIT'
#define DFH_EOL BIT(40) /* End of list */
^
/home/atull/repos/linux-socfpga/drivers/fpga/dfl.c:643:12: note: in
expansion of macro 'DFH_EOL'
if ((v & DFH_EOL) || !ofst)
^and
CC drivers/fpga/dfl-fme-mgr.o
In file included from /home/atull/repos/linux-socfpga/include/linux/kernel.h:11:0,
from /home/atull/repos/linux-socfpga/include/linux/list.h:9, from/home/atull/repos/linux-socfpga/include/linux/kobject.h:19,
from /home/atull/repos/linux-socfpga/include/linux/device.h:16, from/home/atull/repos/linux-socfpga/drivers/fpga/dfl-fme-pr.c:20:/home/atull/repos/linux-socfpga/drivers/fpga/dfl-fme-pr.c: In function 'pr_mgmt_init':/home/atull/repos/linux-socfpga/include/linux/bitops.h:7:24: warning:
left shift count >= width of type [-Wshift-count-overflow]
#define BIT(nr) (1UL << (nr))
^
/home/atull/repos/linux-socfpga/drivers/fpga/dfl.h:113:27: note: in
expansion of macro 'BIT'
#define FME_PORT_OFST_IMP BIT(60)
^
/home/atull/repos/linux-socfpga/drivers/fpga/dfl-fme-pr.c:449:23:
note: in expansion of macro 'FME_PORT_OFST_IMP'
if (!(port_offset & FME_PORT_OFST_IMP))
^Alan
Quoted 5 lines
Thanks
HaoQuoted 1 line
Alan
Re: [PATCH v4 15/24] fpga: dfl-fme-pr: add compat_id support for dfl-fme-region platform device.
Quoted 65 lines · Alan Tull
Quoted 11 lines · Wu Hao
Quoted 9 lines · Alan Tull
drivers/fpga/dfl-fme-pr.c static void fpga_fme_destroy_bridges(struct feature_platform_data *pdata) · line 330
Quoted 3 lines · Wu Hao
drivers/fpga/dfl-fme-pr.c +3
-0+ + compat_id.id_l =readq (fme_pr +FME_PR_INTFC_ID_L ); + compat_id.id_h =readq (fme_pr +FME_PR_INTFC_ID_H );I tried building for 32 bit ARM and ran into readq and writeq not being defined. v2 had proper '#indef readq/writeq', so looks like we need that after all.
Quoted 6 lines
Sorry, it's missing a header file for
dfl-fme-pr.h, as some files don't includedfl.hat this version. That header file has definitions for readq/writeq.+#include <
linux/io-64-nonatomic-lo-hi.h>will fix it.
Hi Hao,
That sounds good. I was able to build if I added it. There are a couple issues in the enumeration code:
In file included from
/home/atull/repos/linux-socfpga/include/linux/kernel.h:11:0,
from/home/atull/repos/linux-socfpga/include/linux/list.h:9, from/home/atull/repos/linux-socfpga/include/linux/module.h:9, from/home/atull/repos/linux-socfpga/drivers/fpga/dfl.c:13:/home/atull/repos/linux-socfpga/drivers/fpga/dfl.c: In function 'parse_feature_list':/home/atull/repos/linux-socfpga/include/linux/bitops.h:7:24: warning:
left shift count >= width of type [-Wshift-count-overflow]#define BIT(nr) (1UL << (nr)) ^ /home/atull/repos/linux-socfpga/drivers/fpga/dfl.h:73:19: note: in expansion of macro 'BIT' #define DFH_EOL BIT(40) /* End of list */ ^ /home/atull/repos/linux-socfpga/drivers/fpga/dfl.c:643:12: note: in expansion of macro 'DFH_EOL' if ((v & DFH_EOL) || !ofst) ^and
CC
drivers/fpga/dfl-fme-mgr.o
In file included from/home/atull/repos/linux-socfpga/include/linux/kernel.h:11:0,
from/home/atull/repos/linux-socfpga/include/linux/list.h:9, from/home/atull/repos/linux-socfpga/include/linux/kobject.h:19,
from/home/atull/repos/linux-socfpga/include/linux/device.h:16, from/home/atull/repos/linux-socfpga/drivers/fpga/dfl-fme-pr.c:20:/home/atull/repos/linux-socfpga/drivers/fpga/dfl-fme-pr.c: In function 'pr_mgmt_init':/home/atull/repos/linux-socfpga/include/linux/bitops.h:7:24: warning:
left shift count >= width of type [-Wshift-count-overflow]#define BIT(nr) (1UL << (nr)) ^ /home/atull/repos/linux-socfpga/drivers/fpga/dfl.h:113:27: note: in expansion of macro 'BIT' #define FME_PORT_OFST_IMP BIT(60) ^
Quoted 3 lines
/home/atull/repos/linux-socfpga/drivers/fpga/dfl-fme-pr.c:449:23:
note: in expansion of macro 'FME_PORT_OFST_IMP'
if (!(port_offset &FME_PORT_OFST_IMP))
Hi Alan
I think it needs to use BIT_ULL instead of BIT.
will fix them in the next version.
Thanks
Hao
Quoted 9 lines
^Alan
Quoted 5 lines
Thanks
HaoQuoted 1 line
Alan
PATCH v4 16/24 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
--- drivers/fpga/Kconfig | 6 + drivers/fpga/Makefile | 1 + drivers/fpga/dfl-fme-mgr.c | 290 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 297 insertions(+) create mode 100644 drivers/fpga/dfl-fme-mgr.c
drivers/fpga/Kconfig +6 -0
@@ -150,6 +150,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 Device Feature List (DFL) PCIe Device Driver" depends on PCI && FPGA_DFL
drivers/fpga/Makefile +1 -0
@@ -31,6 +31,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 +290 -0
290 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH v4 16/24] fpga: dfl: add fpga manager platform driver for FME
On Tue, Feb 13, 2018 at 3:24 AM, Wu Hao <[email protected]> wrote:
Hi Hao,
Elsewhere we discussed moving #defines used only in this driver either to this .c file or to a similarly named .h file. A couple minor things below.
Quoted 297 lines
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]>---
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--- drivers/fpga/Kconfig | 6 + drivers/fpga/Makefile | 1 + drivers/fpga/dfl-fme-mgr.c | 290 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 297 insertions(+) create mode 100644 drivers/fpga/dfl-fme-mgr.cdrivers/fpga/Kconfig +6
-0@@ -150,6 +150,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 Device Feature List (DFL) PCIe Device Driver" depends on PCI && FPGA_DFLdrivers/fpga/Makefile +1
-0@@ -31,6 +31,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 +237
-0@@ -0,0 +1,290 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* FPGA Manager Driver for FPGA Management Engine (FME) +* +* Copyright (C) 2017 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/fpga/fpga-mgr.h> + +#include "dfl-fme-pr.h" + +#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 ); + + pr_status =readq (fme_pr +FME_PR_STS ); + pr_credit =FIELD_GET (FME_PR_STS_PR_CREDIT , pr_status); + } + +if (count >=4 ) { + 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++; + }else { +WARN_ON (1 ); +return -EINVAL ; + } + } + +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 device *dev = &pdev->dev; +struct fme_mgr_priv *priv;
drivers/fpga/dfl-fme-mgr.c line 247
Quoted 10 lines
drivers/fpga/dfl-fme-mgr.c new file +10
-0+struct fpga_manager *mgr; +struct resource *res; +int ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + priv->ioaddr =devm_ioremap (dev, res->start,resource_size (res));
How about using devm_ioremap_resourc(dev, res) here instead?
Quoted 8 lines
drivers/fpga/dfl-fme-mgr.c new file +8
-0+if (IS_ERR (priv->ioaddr)) +return PTR_ERR (priv->ioaddr); + + mgr =devm_kzalloc (dev,sizeof (*mgr),GFP_KERNEL ); +if (!mgr) +return -ENOMEM ; + + mgr->name ="DFL FPGA Manager" ;
drivers/fpga/dfl-fme-mgr.c line 265
Quoted 10 lines
drivers/fpga/dfl-fme-mgr.c new file +10
-0+ mgr->mops = &fme_mgr_ops; + mgr->priv = priv; + mgr->parent = dev; +platform_set_drvdata (pdev, mgr); + + ret =fpga_mgr_register (mgr); +if (ret) +dev_err (dev,"unable to register FPGA manager\n" ); + +return ret;
You can probably just do "return fpga_mgr_register(mgr);" here.
Thanks,
Alan
Quoted 28 lines
drivers/fpga/dfl-fme-mgr.c new file +25
-1+} + +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 =FPGA_DFL_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" ); --2.7.4
Re: [PATCH v4 16/24] fpga: dfl: add fpga manager platform driver for FME
Quoted 7 lines · Alan Tull
On Tue, Feb 13, 2018 at 3:24 AM, Wu Hao <[email protected]> wrote:
Hi Hao,
Elsewhere we discussed moving #defines used only in this driver either to this .c file or to a similarly named .h file. A couple minor things below.
Hi Alan,
Yes, I will move those #defines into a similarly named .h file.
Quoted 302 lines
Quoted 302 lines
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]>---
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--- drivers/fpga/Kconfig | 6 + drivers/fpga/Makefile | 1 + drivers/fpga/dfl-fme-mgr.c | 290 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 297 insertions(+) create mode 100644 drivers/fpga/dfl-fme-mgr.cdrivers/fpga/Kconfig +6
-0@@ -150,6 +150,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 Device Feature List (DFL) PCIe Device Driver" depends on PCI && FPGA_DFLdrivers/fpga/Makefile +1
-0@@ -31,6 +31,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 +241
-0@@ -0,0 +1,290 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* FPGA Manager Driver for FPGA Management Engine (FME) +* +* Copyright (C) 2017 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/fpga/fpga-mgr.h> + +#include "dfl-fme-pr.h" + +#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 ); + + pr_status =readq (fme_pr +FME_PR_STS ); + pr_credit =FIELD_GET (FME_PR_STS_PR_CREDIT , pr_status); + } + +if (count >=4 ) { + 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++; + }else { +WARN_ON (1 ); +return -EINVAL ; + } + } + +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 device *dev = &pdev->dev; +struct fme_mgr_priv *priv; +struct fpga_manager *mgr; +struct resource *res; +int ret; +
Quoted 8 lines
drivers/fpga/dfl-fme-mgr.c line 247
Quoted 6 lines
drivers/fpga/dfl-fme-mgr.c new file +6
-0+ priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + priv->ioaddr =devm_ioremap (dev, res->start,resource_size (res));How about using
devm_ioremap_resourc(dev, res)here instead?
Actually the register region has already been mapped in lower level driver (e.g pci) so I think we don't have to map the second time here. I plan to add some code to pass the ioaddr via the platform data, and check if valid ioaddr from the platform data firstly in this probe function. If no pdata or no valid ioaddr, then go with devm_ioremap_resource. :)
Quoted 13 lines
Quoted 13 lines
drivers/fpga/dfl-fme-mgr.c new file +12
-0+if (IS_ERR (priv->ioaddr)) +return PTR_ERR (priv->ioaddr); + + mgr =devm_kzalloc (dev,sizeof (*mgr),GFP_KERNEL ); +if (!mgr) +return -ENOMEM ; + + mgr->name ="DFL FPGA Manager" ; + mgr->mops = &fme_mgr_ops; + mgr->priv = priv; + mgr->parent = dev; +platform_set_drvdata (pdev, mgr);
Quoted 8 lines
drivers/fpga/dfl-fme-mgr.c line 265
Quoted 6 lines
drivers/fpga/dfl-fme-mgr.c new file +6
-0+ + ret =fpga_mgr_register (mgr); +if (ret) +dev_err (dev,"unable to register FPGA manager\n" ); + +return ret;You can probably just do "return
fpga_mgr_register(mgr);" here.
Yes, it looks better, I will fix it. Thanks a lot for the review.
Hao
Quoted 32 lines
Thanks,
AlanQuoted 28 lines
drivers/fpga/dfl-fme-mgr.c new file +25
-1+} + +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 =FPGA_DFL_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" ); --2.7.4
Moritz Fischer
maintainerRe: [PATCH v4 16/24] fpga: dfl: add fpga manager platform driver for FME
Quoted 324 lines · Wu Hao
Quoted 7 lines · Alan Tull
On Tue, Feb 13, 2018 at 3:24 AM, Wu Hao <[email protected]> wrote:
Hi Hao,
Elsewhere we discussed moving #defines used only in this driver either to this .c file or to a similarly named .h file. A couple minor things below.
Hi Alan,
Yes, I will move those #defines into a similarly named .h file.
Quoted 302 lines
Quoted 302 lines
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]>---
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--- drivers/fpga/Kconfig | 6 + drivers/fpga/Makefile | 1 + drivers/fpga/dfl-fme-mgr.c | 290 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 297 insertions(+) create mode 100644 drivers/fpga/dfl-fme-mgr.cdrivers/fpga/Kconfig +6
-0@@ -150,6 +150,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 Device Feature List (DFL) PCIe Device Driver" depends on PCI && FPGA_DFLdrivers/fpga/Makefile +1
-0@@ -31,6 +31,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 +241
-0@@ -0,0 +1,290 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* FPGA Manager Driver for FPGA Management Engine (FME) +* +* Copyright (C) 2017 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/fpga/fpga-mgr.h> + +#include "dfl-fme-pr.h" + +#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 ); + + pr_status =readq (fme_pr +FME_PR_STS ); + pr_credit =FIELD_GET (FME_PR_STS_PR_CREDIT , pr_status); + } + +if (count >=4 ) { + 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++; + }else { +WARN_ON (1 ); +return -EINVAL ; + } + } + +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 device *dev = &pdev->dev; +struct fme_mgr_priv *priv; +struct fpga_manager *mgr; +struct resource *res; +int ret; +Quoted 8 lines
drivers/fpga/dfl-fme-mgr.c line 247
Quoted 6 lines
drivers/fpga/dfl-fme-mgr.c new file +6
-0+ priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + priv->ioaddr =devm_ioremap (dev, res->start,resource_size (res));How about using
devm_ioremap_resourc(dev, res)here instead?
Quoted 5 lines
Actually the register region has already been mapped in lower level driver (e.g pci) so I think we don't have to map the second time here. I plan to add some code to pass the ioaddr via the platform data, and check if valid ioaddr from the platform data firstly in this probe function. If no pdata or no valid ioaddr, then go with
devm_ioremap_resource. :)
If you end up sharing register spaces between drivers is regmap / syscon maybe a good idea?
Quoted 51 lines
Quoted 14 lines
Quoted 14 lines
drivers/fpga/dfl-fme-mgr.c new file +12
-0+if (IS_ERR (priv->ioaddr)) +return PTR_ERR (priv->ioaddr); + + mgr =devm_kzalloc (dev,sizeof (*mgr),GFP_KERNEL ); +if (!mgr) +return -ENOMEM ; + + mgr->name ="DFL FPGA Manager" ; + mgr->mops = &fme_mgr_ops; + mgr->priv = priv; + mgr->parent = dev; +platform_set_drvdata (pdev, mgr);Quoted 8 lines
drivers/fpga/dfl-fme-mgr.c line 265
Quoted 6 lines
drivers/fpga/dfl-fme-mgr.c new file +6
-0+ + ret =fpga_mgr_register (mgr); +if (ret) +dev_err (dev,"unable to register FPGA manager\n" ); + +return ret;You can probably just do "return
fpga_mgr_register(mgr);" here.Yes, it looks better, I will fix it. Thanks a lot for the review.
Hao
Quoted 24 lines
Thanks,
AlanQuoted 20 lines
drivers/fpga/dfl-fme-mgr.c new file +20
-0+} + +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 =FPGA_DFL_FME_MGR , + }, + .probe = fme_mgr_probe, + .remove = fme_mgr_remove, +}; + +module_platform_driver (fme_mgr_driver);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/fpga/dfl-fme-mgr.c new file +5
-1+ +MODULE_DESCRIPTION ("FPGA Manager for DFL FPGA Management Engine" ); +MODULE_AUTHOR ("Intel Corporation" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("platform:dfl-fme-mgr" ); --2.7.4
Cheers,
Moritz
Re: [PATCH v4 16/24] fpga: dfl: add fpga manager platform driver for FME
Quoted 325 lines · Moritz Fischer
Quoted 324 lines · Wu Hao
Quoted 7 lines · Alan Tull
On Tue, Feb 13, 2018 at 3:24 AM, Wu Hao <[email protected]> wrote:
Hi Hao,
Elsewhere we discussed moving #defines used only in this driver either to this .c file or to a similarly named .h file. A couple minor things below.
Hi Alan,
Yes, I will move those #defines into a similarly named .h file.
Quoted 310 lines
Quoted 298 lines
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]>---
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--- drivers/fpga/Kconfig | 6 + drivers/fpga/Makefile | 1 + drivers/fpga/dfl-fme-mgr.c | 290 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 297 insertions(+) create mode 100644 drivers/fpga/dfl-fme-mgr.cdrivers/fpga/Kconfig +6
-0@@ -150,6 +150,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 Device Feature List (DFL) PCIe Device Driver" depends on PCI && FPGA_DFLdrivers/fpga/Makefile +1
-0@@ -31,6 +31,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 +237
-0@@ -0,0 +1,290 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* FPGA Manager Driver for FPGA Management Engine (FME) +* +* Copyright (C) 2017 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/fpga/fpga-mgr.h> + +#include "dfl-fme-pr.h" + +#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 ); + + pr_status =readq (fme_pr +FME_PR_STS ); + pr_credit =FIELD_GET (FME_PR_STS_PR_CREDIT , pr_status); + } + +if (count >=4 ) { + 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++; + }else { +WARN_ON (1 ); +return -EINVAL ; + } + } + +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 device *dev = &pdev->dev; +struct fme_mgr_priv *priv;drivers/fpga/dfl-fme-mgr.c line 247
Quoted 10 lines
drivers/fpga/dfl-fme-mgr.c new file +10
-0+struct fpga_manager *mgr; +struct resource *res; +int ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + priv->ioaddr =devm_ioremap (dev, res->start,resource_size (res));How about using
devm_ioremap_resourc(dev, res)here instead?
Quoted 8 lines
Quoted 5 lines
Actually the register region has already been mapped in lower level driver (e.g pci) so I think we don't have to map the second time here. I plan to add some code to pass the ioaddr via the platform data, and check if valid ioaddr from the platform data firstly in this probe function. If no pdata or no valid ioaddr, then go with
devm_ioremap_resource. :)If you end up sharing register spaces between drivers is regmap / syscon maybe a good idea?
Hi Moritz,
Thanks for the comments. I tried the regmap_mmio before but it failed to use regmap_read and regmap_write for register access. It requires to use writeq / readq for 64bit registers on the hardware, but regmap_read and regmap_write only accepts unsigned int value as input parameter. So I only replaced the bitfields struct/union with macro.
Thanks
Hao
Quoted 66 lines
Quoted 51 lines
Quoted 14 lines
Quoted 14 lines
drivers/fpga/dfl-fme-mgr.c new file +12
-0+if (IS_ERR (priv->ioaddr)) +return PTR_ERR (priv->ioaddr); + + mgr =devm_kzalloc (dev,sizeof (*mgr),GFP_KERNEL ); +if (!mgr) +return -ENOMEM ; + + mgr->name ="DFL FPGA Manager" ; + mgr->mops = &fme_mgr_ops; + mgr->priv = priv; + mgr->parent = dev; +platform_set_drvdata (pdev, mgr);Quoted 8 lines
drivers/fpga/dfl-fme-mgr.c line 265
Quoted 6 lines
drivers/fpga/dfl-fme-mgr.c new file +6
-0+ + ret =fpga_mgr_register (mgr); +if (ret) +dev_err (dev,"unable to register FPGA manager\n" ); + +return ret;You can probably just do "return
fpga_mgr_register(mgr);" here.Yes, it looks better, I will fix it. Thanks a lot for the review.
Hao
Quoted 24 lines
Thanks,
AlanQuoted 20 lines
drivers/fpga/dfl-fme-mgr.c new file +20
-0+} + +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 =FPGA_DFL_FME_MGR , + }, + .probe = fme_mgr_probe, + .remove = fme_mgr_remove, +}; + +module_platform_driver (fme_mgr_driver);Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/fpga/dfl-fme-mgr.c new file +5
-1+ +MODULE_DESCRIPTION ("FPGA Manager for DFL FPGA Management Engine" ); +MODULE_AUTHOR ("Intel Corporation" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("platform:dfl-fme-mgr" ); --2.7.4
Cheers,
Moritz
--
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
Re: [PATCH v4 16/24] fpga: dfl: add fpga manager platform driver for FME
Quoted 241 lines · Wu Hao
Quoted 240 lines · Moritz Fischer
Quoted 239 lines · Wu Hao
Quoted 7 lines · Alan Tull
On Tue, Feb 13, 2018 at 3:24 AM, Wu Hao <[email protected]> wrote:
Hi Hao,
Elsewhere we discussed moving #defines used only in this driver either to this .c file or to a similarly named .h file. A couple minor things below.
Hi Alan,
Yes, I will move those #defines into a similarly named .h file.
Quoted 226 lines
Quoted 226 lines
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]>---
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--- drivers/fpga/Kconfig | 6 + drivers/fpga/Makefile | 1 + drivers/fpga/dfl-fme-mgr.c | 290 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 297 insertions(+) create mode 100644 drivers/fpga/dfl-fme-mgr.cdrivers/fpga/Kconfig +6
-0@@ -150,6 +150,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 Device Feature List (DFL) PCIe Device Driver" depends on PCI && FPGA_DFLdrivers/fpga/Makefile +1
-0@@ -31,6 +31,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 +165
-0@@ -0,0 +1,290 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* FPGA Manager Driver for FPGA Management Engine (FME) +* +* Copyright (C) 2017 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/fpga/fpga-mgr.h> + +#include "dfl-fme-pr.h" + +#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 ); + + pr_status =readq (fme_pr +FME_PR_STS ); + pr_credit =FIELD_GET (FME_PR_STS_PR_CREDIT , pr_status); + } + +if (count >=4 ) { + pr_data =0 ; + pr_data |=FIELD_PREP (FME_PR_DATA_PR_DATA_RAW , + *(((u32 *)buf) + i));
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/fpga/dfl-fme-mgr.c line 173
Quoted 8 lines
drivers/fpga/dfl-fme-mgr.c new file +8
-0+writeq (pr_data, fme_pr +FME_PR_DATA ); + count -=4 ; + pr_credit--; + i++; + }else { +WARN_ON (1 ); +return -EINVAL ; + }
Where there's an if..else that has a 'return' on one of its branch, it can become an 'if' without the 'else'. This is strongly preferred in the kernel. Trying to avoid indention where possible. So this becomes
if (count < 4) {
WARN_ON(1);
return -EINVAL;
}pr_data = 0;
so on...
Alan
Quoted 163 lines
Quoted 77 lines
Quoted 77 lines
Quoted 76 lines
Quoted 64 lines
drivers/fpga/dfl-fme-mgr.c new file +64
-0+ } + +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 device *dev = &pdev->dev; +struct fme_mgr_priv *priv;drivers/fpga/dfl-fme-mgr.c line 247
Quoted 10 lines
drivers/fpga/dfl-fme-mgr.c new file +10
-0+struct fpga_manager *mgr; +struct resource *res; +int ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + priv->ioaddr =devm_ioremap (dev, res->start,resource_size (res));How about using
devm_ioremap_resourc(dev, res)here instead?Quoted 8 lines
Quoted 5 lines
Actually the register region has already been mapped in lower level driver (e.g pci) so I think we don't have to map the second time here. I plan to add some code to pass the ioaddr via the platform data, and check if valid ioaddr from the platform data firstly in this probe function. If no pdata or no valid ioaddr, then go with
devm_ioremap_resource. :)If you end up sharing register spaces between drivers is regmap / syscon maybe a good idea?
Hi Moritz,
Thanks for the comments. I tried the
regmap_mmiobefore but it failed to useregmap_readandregmap_writefor register access. It requires to use writeq / readq for 64bit registers on the hardware, butregmap_readandregmap_writeonly accepts unsigned int value as input parameter. So I only replaced the bitfields struct/union with macro.Thanks
HaoQuoted 66 lines
Quoted 51 lines
Quoted 14 lines
Quoted 14 lines
drivers/fpga/dfl-fme-mgr.c new file +12
-0+if (IS_ERR (priv->ioaddr)) +return PTR_ERR (priv->ioaddr); + + mgr =devm_kzalloc (dev,sizeof (*mgr),GFP_KERNEL ); +if (!mgr) +return -ENOMEM ; + + mgr->name ="DFL FPGA Manager" ; + mgr->mops = &fme_mgr_ops; + mgr->priv = priv; + mgr->parent = dev; +platform_set_drvdata (pdev, mgr);Quoted 8 lines
drivers/fpga/dfl-fme-mgr.c line 265
Quoted 6 lines
drivers/fpga/dfl-fme-mgr.c new file +6
-0+ + ret =fpga_mgr_register (mgr); +if (ret) +dev_err (dev,"unable to register FPGA manager\n" ); + +return ret;You can probably just do "return
fpga_mgr_register(mgr);" here.Yes, it looks better, I will fix it. Thanks a lot for the review.
Hao
Quoted 24 lines
Thanks,
AlanQuoted 20 lines
drivers/fpga/dfl-fme-mgr.c new file +20
-0+} + +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 =FPGA_DFL_FME_MGR , + }, + .probe = fme_mgr_probe, + .remove = fme_mgr_remove, +}; + +module_platform_driver (fme_mgr_driver);Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/fpga/dfl-fme-mgr.c new file +5
-1+ +MODULE_DESCRIPTION ("FPGA Manager for DFL FPGA Management Engine" ); +MODULE_AUTHOR ("Intel Corporation" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("platform:dfl-fme-mgr" ); --2.7.4
Cheers,
Moritz
--
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
Re: [PATCH v4 16/24] fpga: dfl: add fpga manager platform driver for FME
Quoted 256 lines · Alan Tull
Quoted 241 lines · Wu Hao
Quoted 240 lines · Moritz Fischer
Quoted 239 lines · Wu Hao
Quoted 7 lines · Alan Tull
On Tue, Feb 13, 2018 at 3:24 AM, Wu Hao <[email protected]> wrote:
Hi Hao,
Elsewhere we discussed moving #defines used only in this driver either to this .c file or to a similarly named .h file. A couple minor things below.
Hi Alan,
Yes, I will move those #defines into a similarly named .h file.
Quoted 226 lines
Quoted 226 lines
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]>---
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--- drivers/fpga/Kconfig | 6 + drivers/fpga/Makefile | 1 + drivers/fpga/dfl-fme-mgr.c | 290 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 297 insertions(+) create mode 100644 drivers/fpga/dfl-fme-mgr.cdrivers/fpga/Kconfig +6
-0@@ -150,6 +150,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 Device Feature List (DFL) PCIe Device Driver" depends on PCI && FPGA_DFLdrivers/fpga/Makefile +1
-0@@ -31,6 +31,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 +165
-0@@ -0,0 +1,290 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* FPGA Manager Driver for FPGA Management Engine (FME) +* +* Copyright (C) 2017 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/fpga/fpga-mgr.h> + +#include "dfl-fme-pr.h" + +#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 ); + + pr_status =readq (fme_pr +FME_PR_STS ); + pr_credit =FIELD_GET (FME_PR_STS_PR_CREDIT , pr_status); + } + +if (count >=4 ) { + pr_data =0 ; + pr_data |=FIELD_PREP (FME_PR_DATA_PR_DATA_RAW , + *(((u32 *)buf) + i));Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/fpga/dfl-fme-mgr.c line 173
Quoted 8 lines
drivers/fpga/dfl-fme-mgr.c new file +8
-0+writeq (pr_data, fme_pr +FME_PR_DATA ); + count -=4 ; + pr_credit--; + i++; + }else { +WARN_ON (1 ); +return -EINVAL ; + }Where there's an if..else that has a 'return' on one of its branch, it can become an 'if' without the 'else'. This is strongly preferred in the kernel. Trying to avoid indention where possible. So this becomes
Quoted 7 lines
if (count < 4) { WARN_ON(1); return -EINVAL; }
pr_data= 0;
so on...
Agree, code looks better with your suggestion.
I will fix this problem in the next verion. Thanks for the comments.
Hao
Quoted 170 lines
Alan
Quoted 88 lines
Quoted 77 lines
Quoted 77 lines
Quoted 76 lines
Quoted 64 lines
drivers/fpga/dfl-fme-mgr.c new file +64
-0+ } + +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 device *dev = &pdev->dev; +struct fme_mgr_priv *priv;drivers/fpga/dfl-fme-mgr.c line 247
Quoted 10 lines
drivers/fpga/dfl-fme-mgr.c new file +10
-0+struct fpga_manager *mgr; +struct resource *res; +int ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + priv->ioaddr =devm_ioremap (dev, res->start,resource_size (res));How about using
devm_ioremap_resourc(dev, res)here instead?Quoted 8 lines
Quoted 5 lines
Actually the register region has already been mapped in lower level driver (e.g pci) so I think we don't have to map the second time here. I plan to add some code to pass the ioaddr via the platform data, and check if valid ioaddr from the platform data firstly in this probe function. If no pdata or no valid ioaddr, then go with
devm_ioremap_resource. :)If you end up sharing register spaces between drivers is regmap / syscon maybe a good idea?
Hi Moritz,
Quoted 75 lines
Thanks for the comments. I tried the
regmap_mmiobefore but it failed to useregmap_readandregmap_writefor register access. It requires to use writeq / readq for 64bit registers on the hardware, butregmap_readandregmap_writeonly accepts unsigned int value as input parameter. So I only replaced the bitfields struct/union with macro.Thanks
HaoQuoted 66 lines
Quoted 51 lines
Quoted 14 lines
Quoted 14 lines
drivers/fpga/dfl-fme-mgr.c new file +12
-0+if (IS_ERR (priv->ioaddr)) +return PTR_ERR (priv->ioaddr); + + mgr =devm_kzalloc (dev,sizeof (*mgr),GFP_KERNEL ); +if (!mgr) +return -ENOMEM ; + + mgr->name ="DFL FPGA Manager" ; + mgr->mops = &fme_mgr_ops; + mgr->priv = priv; + mgr->parent = dev; +platform_set_drvdata (pdev, mgr);Quoted 8 lines
drivers/fpga/dfl-fme-mgr.c line 265
Quoted 6 lines
drivers/fpga/dfl-fme-mgr.c new file +6
-0+ + ret =fpga_mgr_register (mgr); +if (ret) +dev_err (dev,"unable to register FPGA manager\n" ); + +return ret;You can probably just do "return
fpga_mgr_register(mgr);" here.Yes, it looks better, I will fix it. Thanks a lot for the review.
Hao
Quoted 24 lines
Thanks,
AlanQuoted 20 lines
drivers/fpga/dfl-fme-mgr.c new file +20
-0+} + +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 =FPGA_DFL_FME_MGR , + }, + .probe = fme_mgr_probe, + .remove = fme_mgr_remove, +}; + +module_platform_driver (fme_mgr_driver);Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/fpga/dfl-fme-mgr.c new file +5
-1+ +MODULE_DESCRIPTION ("FPGA Manager for DFL FPGA Management Engine" ); +MODULE_AUTHOR ("Intel Corporation" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("platform:dfl-fme-mgr" ); --2.7.4
Cheers,
Moritz
--
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--
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
PATCH v4 17/24 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 call back 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
--- drivers/fpga/Kconfig | 6 ++++ drivers/fpga/Makefile | 1 + drivers/fpga/dfl-fme-br.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 drivers/fpga/dfl-fme-br.c
drivers/fpga/Kconfig +6 -0
@@ -156,6 +156,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 Device Feature List (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 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 +85 -0
85 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v4 18/24 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
--- drivers/fpga/Kconfig | 6 +++ drivers/fpga/Makefile | 1 + drivers/fpga/dfl-fme-region.c | 89 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 drivers/fpga/dfl-fme-region.c
drivers/fpga/Kconfig +6 -0
@@ -162,6 +162,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 Device Feature List (DFL) PCIe Device Driver" depends on PCI && FPGA_DFL
drivers/fpga/Makefile +1 -0
@@ -33,6 +33,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 +89 -0
89 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v4 19/24 fpga: dfl-fme-region: add compat_id support
In reply to Wu HaoThis patch adds compat_id support, configure the compat_id value of fpga_region, then userspace could read it from the common sysfs interface compat_id of fpga_region.
--- drivers/fpga/dfl-fme-region.c | 1 + 1 file changed, 1 insertion(+)
drivers/fpga/dfl-fme-region.c +1 -0
@@ -48,6 +48,7 @@ static int fme_region_probe(struct platform_device *pdev) region->get_bridges = fme_region_get_bridges; region->priv = pdata; region->parent = dev; + region->compat_id = pdata->compat_id;platform_set_drvdata (pdev, region); ret =fpga_region_register (region);
Signature · 1 line
2.7.4
PATCH v4 20/24 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("blue bistream") via a Port. Port CSRs are implemented separately from the AFU CSRs to provide control and status of the Port. Once valid green 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.
--- drivers/fpga/Kconfig | 9 +++ drivers/fpga/Makefile | 2 + drivers/fpga/dfl-afu-main.c | 159 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 170 insertions(+) create mode 100644 drivers/fpga/dfl-afu-main.c
drivers/fpga/Kconfig +9 -0
@@ -168,6 +168,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 Device Feature List (DFL) PCIe Device Driver" depends on PCI && FPGA_DFL
drivers/fpga/Makefile +2 -0
@@ -34,8 +34,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 +159 -0
159 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH v4 20/24] fpga: dfl: add FPGA Accelerated Function Unit driver basic framework
On Tue, Feb 13, 2018 at 3:24 AM, Wu Hao <[email protected]> wrote:
Hi Hao,
I acked this back in v2.
Quoted 10 lines
On DFL FPGA devices, the Accelerated Function Unit (AFU), can be reprogrammed for different functions. It connects to the FPGA
infrastructure("blue bistream")via a Port. Port CSRs are implemented separately from the AFU CSRs to provide control and status of the Port. Once valid green 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.
Quoted 6 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 Xiao Guangrong <[email protected]>Signed-off-by Wu Hao <[email protected]>
Alan
Re: [PATCH v4 20/24] fpga: dfl: add FPGA Accelerated Function Unit driver basic framework
In reply to Wu HaoOn Tue, Feb 13, 2018 at 3:24 AM, Wu Hao <[email protected]> wrote:
Hi Hao,
One minor thing below.
Quoted 162 lines
On DFL FPGA devices, the Accelerated Function Unit (AFU), can be reprogrammed for different functions. It connects to the FPGA
infrastructure("blue bistream")via a Port. Port CSRs are implemented separately from the AFU CSRs to provide control and status of the Port. Once valid green 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.
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 Xiao Guangrong <[email protected]>Signed-off-by Wu Hao <[email protected]>---
v3: rename driver todfl-afu-main.c
v4: rename to dfl-port and fix SPDX license issue.--- drivers/fpga/Kconfig | 9 +++ drivers/fpga/Makefile | 2 + drivers/fpga/dfl-afu-main.c | 159 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 170 insertions(+) create mode 100644 drivers/fpga/dfl-afu-main.cdrivers/fpga/Kconfig +9
-0@@ -168,6 +168,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 Device Feature List (DFL) PCIe Device Driver" depends on PCI && FPGA_DFLdrivers/fpga/Makefile +2
-0@@ -34,8 +34,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.odrivers/fpga/dfl-afu-main.c new file +95
-0@@ -0,0 +1,159 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Driver for FPGA Accelerated Function Unit (AFU) +* +* Copyright (C) 2017 Intel Corporation, Inc. +* +* Authors: +* Wu Hao <[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 port_hdr_init (struct platform_device *pdev,struct feature *feature) +{ +dev_dbg (&pdev->dev,"PORT HDR Init.\n" ); + +return 0 ; +} + +static void port_hdr_uinit (struct platform_device *pdev, +struct feature *feature) +{ +dev_dbg (&pdev->dev,"PORT HDR UInit.\n" ); +} + +static const struct feature_ops port_hdr_ops = { + .init = port_hdr_init, + .uinit = port_hdr_uinit, +}; + +static struct feature_driver port_feature_drvs[] = { + { + .id =PORT_FEATURE_ID_HEADER , + .ops = &port_hdr_ops, + }, + { + .ops =NULL , + } +}; + +static int afu_open (struct inode *inode,struct file *filp) +{ +struct platform_device *fdev =fpga_inode_to_feature_dev (inode); +struct feature_platform_data *pdata; +int ret; + + pdata =dev_get_platdata (&fdev->dev); +if (WARN_ON (!pdata)) +return -ENODEV ; + + ret =feature_dev_use_begin (pdata); +if (ret) +return ret; + +dev_dbg (&fdev->dev,"Device File Open\n" ); + filp->private_data = fdev; + +return 0 ; +} + +static int afu_release (struct inode *inode,struct file *filp) +{ +struct platform_device *pdev = filp->private_data; +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); + +dev_dbg (&pdev->dev,"Device File Release\n" ); + +feature_dev_use_end (pdata); + +return 0 ; +} + +static long afu_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) +{ +struct platform_device *pdev = filp->private_data; +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct 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
drivers/fpga/dfl-afu-main.c line 105
Quoted 10 lines
drivers/fpga/dfl-afu-main.c new file +10
-0+* handled in this sub feature, and returns 0 and other +* error code if cmd is handled. +*/ +fpga_dev_for_each_feature (pdata, f) +if (f->ops && f->ops->ioctl) { + ret = f->ops->ioctl (pdev, f, cmd, arg); +if (ret == -ENODEV ) +continue ; +else +return ret;
The continue..else isn't needed. Could just be
if (ret != -ENODEV)
return ret;
Thanks,
Alan
Quoted 57 lines
drivers/fpga/dfl-afu-main.c new file +54
-1+ } + } + +return -EINVAL ; +} + +static const struct file_operations afu_fops = { + .owner =THIS_MODULE , + .open = afu_open, + .release = afu_release, + .unlocked_ioctl = afu_ioctl, +}; + +static int afu_probe (struct platform_device *pdev) +{ +int ret; + +dev_dbg (&pdev->dev,"%s\n" , __func__); + + ret =fpga_dev_feature_init (pdev, port_feature_drvs); +if (ret) +return ret; + + ret =fpga_register_dev_ops (pdev, &afu_fops,THIS_MODULE ); +if (ret) +fpga_dev_feature_uinit (pdev); + +return ret; +} + +static int afu_remove (struct platform_device *pdev) +{ +dev_dbg (&pdev->dev,"%s\n" , __func__); + +fpga_dev_feature_uinit (pdev); +fpga_unregister_dev_ops (pdev); + +return 0 ; +} + +static struct platform_driver afu_driver = { + .driver = { + .name =FPGA_FEATURE_DEV_PORT , + }, + .probe = afu_probe, + .remove = afu_remove, +}; + +module_platform_driver (afu_driver); + +MODULE_DESCRIPTION ("FPGA Accelerated Function Unit driver" ); +MODULE_AUTHOR ("Intel Corporation" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("platform:dfl-port" ); --2.7.4
Re: [PATCH v4 20/24] fpga: dfl: add FPGA Accelerated Function Unit driver basic framework
Quoted 181 lines · Alan Tull
On Tue, Feb 13, 2018 at 3:24 AM, Wu Hao <[email protected]> wrote:
Hi Hao,
One minor thing below.
Quoted 162 lines
On DFL FPGA devices, the Accelerated Function Unit (AFU), can be reprogrammed for different functions. It connects to the FPGA
infrastructure("blue bistream")via a Port. Port CSRs are implemented separately from the AFU CSRs to provide control and status of the Port. Once valid green 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.
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 Xiao Guangrong <[email protected]>Signed-off-by Wu Hao <[email protected]>---
v3: rename driver todfl-afu-main.c
v4: rename to dfl-port and fix SPDX license issue.--- drivers/fpga/Kconfig | 9 +++ drivers/fpga/Makefile | 2 + drivers/fpga/dfl-afu-main.c | 159 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 170 insertions(+) create mode 100644 drivers/fpga/dfl-afu-main.cdrivers/fpga/Kconfig +9
-0@@ -168,6 +168,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 Device Feature List (DFL) PCIe Device Driver" depends on PCI && FPGA_DFLdrivers/fpga/Makefile +2
-0@@ -34,8 +34,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.odrivers/fpga/dfl-afu-main.c new file +95
-0@@ -0,0 +1,159 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Driver for FPGA Accelerated Function Unit (AFU) +* +* Copyright (C) 2017 Intel Corporation, Inc. +* +* Authors: +* Wu Hao <[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 port_hdr_init (struct platform_device *pdev,struct feature *feature) +{ +dev_dbg (&pdev->dev,"PORT HDR Init.\n" ); + +return 0 ; +} + +static void port_hdr_uinit (struct platform_device *pdev, +struct feature *feature) +{ +dev_dbg (&pdev->dev,"PORT HDR UInit.\n" ); +} + +static const struct feature_ops port_hdr_ops = { + .init = port_hdr_init, + .uinit = port_hdr_uinit, +}; + +static struct feature_driver port_feature_drvs[] = { + { + .id =PORT_FEATURE_ID_HEADER , + .ops = &port_hdr_ops, + }, + { + .ops =NULL , + } +}; + +static int afu_open (struct inode *inode,struct file *filp) +{ +struct platform_device *fdev =fpga_inode_to_feature_dev (inode); +struct feature_platform_data *pdata; +int ret; + + pdata =dev_get_platdata (&fdev->dev); +if (WARN_ON (!pdata)) +return -ENODEV ; + + ret =feature_dev_use_begin (pdata); +if (ret) +return ret; + +dev_dbg (&fdev->dev,"Device File Open\n" ); + filp->private_data = fdev; + +return 0 ; +} + +static int afu_release (struct inode *inode,struct file *filp) +{ +struct platform_device *pdev = filp->private_data; +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); + +dev_dbg (&pdev->dev,"Device File Release\n" ); + +feature_dev_use_end (pdata); + +return 0 ; +} + +static long afu_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) +{ +struct platform_device *pdev = filp->private_data; +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct 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 drivers/fpga/dfl-afu-main.c line 105
Quoted 10 lines
drivers/fpga/dfl-afu-main.c new file +10
-0+* handled in this sub feature, and returns 0 and other +* error code if cmd is handled. +*/ +fpga_dev_for_each_feature (pdata, f) +if (f->ops && f->ops->ioctl) { + ret = f->ops->ioctl (pdev, f, cmd, arg); +if (ret == -ENODEV ) +continue ; +else +return ret;The continue..else isn't needed. Could just be
if (ret !=-ENODEV)
Quoted 1 line
return ret;
Agree, will fix this in the next version. Thanks.
Hao
Quoted 61 lines
Thanks,
AlanQuoted 57 lines
drivers/fpga/dfl-afu-main.c new file +54
-1+ } + } + +return -EINVAL ; +} + +static const struct file_operations afu_fops = { + .owner =THIS_MODULE , + .open = afu_open, + .release = afu_release, + .unlocked_ioctl = afu_ioctl, +}; + +static int afu_probe (struct platform_device *pdev) +{ +int ret; + +dev_dbg (&pdev->dev,"%s\n" , __func__); + + ret =fpga_dev_feature_init (pdev, port_feature_drvs); +if (ret) +return ret; + + ret =fpga_register_dev_ops (pdev, &afu_fops,THIS_MODULE ); +if (ret) +fpga_dev_feature_uinit (pdev); + +return ret; +} + +static int afu_remove (struct platform_device *pdev) +{ +dev_dbg (&pdev->dev,"%s\n" , __func__); + +fpga_dev_feature_uinit (pdev); +fpga_unregister_dev_ops (pdev); + +return 0 ; +} + +static struct platform_driver afu_driver = { + .driver = { + .name =FPGA_FEATURE_DEV_PORT , + }, + .probe = afu_probe, + .remove = afu_remove, +}; + +module_platform_driver (afu_driver); + +MODULE_DESCRIPTION ("FPGA Accelerated Function Unit driver" ); +MODULE_AUTHOR ("Intel Corporation" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("platform:dfl-port" ); --2.7.4
PATCH v4 21/24 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:
* 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.
--- Documentation/ABI/testing/sysfs-platform-dfl-port | 7 ++++ drivers/fpga/dfl-afu-main.c | 44 ++++++++++++++++++++++- include/uapi/linux/fpga-dfl.h | 17 +++++++++ 3 files changed, 67 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: Februray 2018 +KernelVersion: 4.16 +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 +43 -1
74 lines not on this page · raw message
include/uapi/linux/fpga-dfl.h +17 -0
@@ -28,8 +28,11 @@#define FPGA_MAGIC 0xB6#define FPGA_BASE 0 +#define PORT_BASE 0x40#define FME_BASE 0x80 +/* Common IOCTLs for both FME and AFU file descriptor */ +/** * FPGA_GET_API_VERSION - _IO(FPGA_MAGIC, FPGA_BASE + 0) *
@@ -48,6 +51,20 @@#define FPGA_CHECK_EXTENSION _IO(FPGA_MAGIC, FPGA_BASE + 1) +/* IOCTLs for AFU file descriptor */ + +/** +* FPGA_PORT_RESET - _IO(FPGA_MAGIC, 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 FPGA_PORT_RESET _IO(FPGA_MAGIC, PORT_BASE + 0) +/* IOCTLs for FME file descriptor */ /**
Signature · 1 line
2.7.4
PATCH v4 22/24 fpga: dfl: afu: add FPGA_GET_API_VERSION/CHECK_EXTENSION ioctls support
In reply to Wu HaoFPGA_GET_API_VERSION and 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.
--- drivers/fpga/dfl-afu-main.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/fpga/dfl-afu-main.c +11 -0
@@ -121,6 +121,13 @@ static int afu_release(struct inode *inode, struct file *filp)return 0 ; } +static long afu_ioctl_check_extension (struct 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;
@@ -131,6 +138,10 @@ static long afu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)dev_dbg (&pdev->dev,"%s cmd 0x%x\n" , __func__, cmd);switch (cmd) { +case FPGA_GET_API_VERSION : +return FPGA_API_VERSION ; +case FPGA_CHECK_EXTENSION : +return afu_ioctl_check_extension (pdata, arg);default :/* * Let sub-feature's ioctl function to handle the cmd
Signature · 1 line
2.7.4
PATCH v4 23/24 fpga: dfl: afu: add user 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 green bitstream (GBS) is programmed and 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 green bitstream is programmed to this AFU.
Ioctl interfaces:
* FPGA_PORT_GET_INFO
Provide info to userspace on the number of supported region. Only UAFU region is supported now.
* 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.
add sysfs documentation.
switched to GPLv2 license.
v3: rename driver to fpga-dfl-afu
fix coding style and checkpatch issue.
only allow afu_id to be read when port isn't in reset.
v4: rebase and add more comments in code.
fix SPDX license issue.
--- Documentation/ABI/testing/sysfs-platform-dfl-port | 9 + drivers/fpga/Makefile | 2 +- drivers/fpga/dfl-afu-main.c | 211 +++++++++++++++++++++- drivers/fpga/dfl-afu-region.c | 165 +++++++++++++++++ drivers/fpga/dfl-afu.h | 71 ++++++++ include/uapi/linux/fpga-dfl.h | 47 +++++ 6 files changed, 501 insertions(+), 4 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: Februray 2018 +KernelVersion: 4.16 +Contact: Wu Hao <[email protected]> +Description: Read-only. User can program different green bitstreams (GBS) to + FPGA Accelerator Function Unit (AFU) for different functions. + It returns uuid which could be used to identify which GBS is + programmed in this AFU.
drivers/fpga/Makefile +1 -1
@@ -37,7 +37,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 +208 -3
274 lines not on this page · raw message
drivers/fpga/dfl-afu-region.c new file +165 -0
165 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 +47 -0
53 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH v4 23/24] fpga: dfl: afu: add user afu sub feature support
On Tue, Feb 13, 2018 at 3:24 AM, Wu Hao <[email protected]> wrote:
Hi Hao,
Quoted 3 lines
From: Xiao Guangrong <[email protected]>
User Accelerated Function Unit sub feature exposes the MMIO region of
Is it 'user accelerated'? I think it is the Accelerator interface.
Quoted 1 line
the AFU. After valid green bitstream (GBS) is programmed and port is
Would it make sense to just use "partial bitstream" or "PR bitstream" and "static bitstream" for this patchset? I don't think that adding this terminology makes things clearer. In any case when someone else uses this patchset, they may not be using this type of branding in their terminology.
Quoted 8 lines
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 green bitstream is programmed to this AFU.
Here too.
Quoted 5 lines
Ioctl interfaces:
*FPGA_PORT_GET_INFO
Provide info to userspace on the number of supported region. Only UAFU region is supported now.
I think UAFU is really the interface for an AFU. I'd like to not add more terminology than is really useful here. Unless I'm missing something, all the UAFU stuff here is really AFU and not some different block.
Quoted 95 lines
*
FPGA_PORT_GET_REGION_INFO
Provide region information, including access permission, region size, offset from the start of device fd.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 Xiao Guangrong <[email protected]>Signed-off-by Wu Hao <[email protected]>---
v2: moved the code todrivers/fpgafolder as suggested by Alan Tull.
add sysfs documentation.
switched to GPLv2 license.
v3: rename driver to fpga-dfl-afu
fix coding style and checkpatch issue.
only allowafu_idto be read when port isn't in reset.
v4: rebase and add more comments in code.
fix SPDX license issue.--- Documentation/ABI/testing/sysfs-platform-dfl-port | 9 + drivers/fpga/Makefile | 2 +- drivers/fpga/dfl-afu-main.c | 211 +++++++++++++++++++++- drivers/fpga/dfl-afu-region.c | 165 +++++++++++++++++ drivers/fpga/dfl-afu.h | 71 ++++++++ include/uapi/linux/fpga-dfl.h | 47 +++++ 6 files changed, 501 insertions(+), 4 deletions(-) create mode 100644 drivers/fpga/dfl-afu-region.c create mode 100644 drivers/fpga/dfl-afu.hDocumentation/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: Februray 2018 +KernelVersion: 4.16 +Contact: Wu Hao <[email protected]> +Description: Read-only. User can program different green bitstreams (GBS) to + FPGA Accelerator Function Unit (AFU) for different functions. + It returns uuid which could be used to identify which GBS is + programmed in this AFU.drivers/fpga/Makefile +1
-1@@ -37,7 +37,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.odrivers/fpga/dfl-afu-main.c +16
-1@@ -16,9 +16,10 @@#include <linux/kernel.h> #include <linux/module.h> +#include <linux/uaccess.h> #include <linux/fpga-dfl.h> -#include "dfl.h" +#include "dfl-afu.h" static ssize_t id_show (struct device *dev,struct device_attribute *attr,char *buf)@@ -78,12 +79,74 @@ static const struct feature_ops port_hdr_ops = { .ioctl = port_hdr_ioctl, }; +static ssize_t +afu_id_show (struct device *dev,struct device_attribute *attr,char *buf) +{ +struct feature_platform_data *pdata =dev_get_platdata (dev); +void __iomem *base; +u64 guidl, guidh; + + base =get_feature_ioaddr_by_id (dev,PORT_FEATURE_ID_AFU ); + +mutex_lock (&pdata->lock); +if (pdata->disable_count) { +mutex_unlock (&pdata->lock); +return -EBUSY ; + }
drivers/fpga/dfl-afu-main.c static const struct feature_ops port_hdr_ops = { · line 105
Quoted 10 lines
drivers/fpga/dfl-afu-main.c +10
-0+ + guidl =readq (base +GUID_L ); + guidh =readq (base +GUID_H ); +mutex_unlock (&pdata->lock); + +return scnprintf (buf,PAGE_SIZE ,"%016llx%016llx\n" , guidh, guidl); +} +static DEVICE_ATTR_RO (afu_id); + +static const struct attribute *port_uafu_attrs[] = {
port_afu_attrs?
drivers/fpga/dfl-afu-main.c static const struct feature_ops port_hdr_ops = { · line 110
Quoted 5 lines
drivers/fpga/dfl-afu-main.c +5
-0+ &dev_attr_afu_id.attr, + NULL +}; + +static int port_uafu_init (struct platform_device *pdev,struct feature *feature)
port_afu_init?
so on. The thing's userspace interface doesn't have to be named differently from the thing itself.
Quoted 108 lines
drivers/fpga/dfl-afu-main.c +91
-0+{ +struct resource *res = &pdev->resource[feature->resource_index]; +u32 flags =FPGA_REGION_READ |FPGA_REGION_WRITE |FPGA_REGION_MMAP ; +int ret; + +dev_dbg (&pdev->dev,"PORT AFU Init.\n" ); + + ret =afu_region_add (dev_get_platdata (&pdev->dev), +FPGA_PORT_INDEX_UAFU ,resource_size (res), + res->start, flags); +if (ret) +return ret; + +return sysfs_create_files (&pdev->dev.kobj, port_uafu_attrs); +} + +static void port_uafu_uinit (struct platform_device *pdev, +struct feature *feature) +{ +dev_dbg (&pdev->dev,"PORT AFU UInit.\n" ); + +sysfs_remove_files (&pdev->dev.kobj, port_uafu_attrs); +} + +static const struct feature_ops port_uafu_ops = { + .init = port_uafu_init, + .uinit = port_uafu_uinit, +}; +static struct feature_driver port_feature_drvs[] = { { .id =PORT_FEATURE_ID_HEADER , .ops = &port_hdr_ops, }, { + .id =PORT_FEATURE_ID_AFU , + .ops = &port_uafu_ops, + }, + { .ops =NULL , } };@@ -128,6 +191,64 @@ static long afu_ioctl_check_extension(struct feature_platform_data *pdata,return 0 ; } +static long +afu_ioctl_get_info (struct feature_platform_data *pdata,void __user *arg) +{ +struct fpga_port_info info; +struct fpga_afu *afu; +unsigned long minsz; + + minsz = offsetofend(struct fpga_port_info, num_umsgs); + +if (copy_from_user (&info, arg, minsz)) +return -EFAULT ; + +if (info.argsz < minsz) +return -EINVAL ; + +mutex_lock (&pdata->lock); + afu =fpga_pdata_get_private (pdata); + info.flags =0 ; + info.num_regions = afu->num_regions; + info.num_umsgs = afu->num_umsgs; +mutex_unlock (&pdata->lock); + +if (copy_to_user (arg, &info,sizeof (info))) +return -EFAULT ; + +return 0 ; +} + +static long +afu_ioctl_get_region_info (struct feature_platform_data *pdata,void __user *arg) +{ +struct fpga_port_region_info rinfo; +struct fpga_afu_region region; +unsigned long minsz; +long ret; + + minsz = offsetofend(struct fpga_port_region_info, offset); + +if (copy_from_user (&rinfo, arg, minsz)) +return -EFAULT ; + +if (rinfo.argsz < minsz || rinfo.padding) +return -EINVAL ; + + ret =afu_get_region_by_index (pdata, rinfo.index, ®ion); +if (ret) +return ret; + + rinfo.flags = region.flags; + rinfo.size = region.size; + rinfo.offset = region.offset; + +if (copy_to_user (arg, &rinfo,sizeof (rinfo))) +return -EFAULT ; + +return 0 ; +} +static long afu_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) {struct platform_device *pdev = filp->private_data;
drivers/fpga/dfl-afu-main.c static long afu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) · line 264
Quoted 2 lines
drivers/fpga/dfl-afu-main.c +0
-0@@ -142,6 +263,10 @@ static long afu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)return FPGA_API_VERSION ;case FPGA_CHECK_EXTENSION :
I commented elsewhere about the FPGA_* names. These names such as FPGA_CHECK_EXTENSION are specific to this DFL patchset, they weren't written as addtions to the lower level FPGA stuff.
Quoted 20 lines
drivers/fpga/dfl-afu-main.c +12
-0return afu_ioctl_check_extension (pdata, arg); +case FPGA_PORT_GET_INFO : +return afu_ioctl_get_info (pdata, (void __user *)arg); +case FPGA_PORT_GET_REGION_INFO : +return afu_ioctl_get_region_info (pdata, (void __user *)arg);default :/* * Let sub-feature's ioctl function to handle the cmd @@ -162,27 +287,106 @@ static long afu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)return -EINVAL ; } +static int afu_mmap (struct file *filp,struct vm_area_struct *vma) +{ +struct fpga_afu_region region; +struct platform_device *pdev = filp->private_data; +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +u64 size = vma->vm_end - vma->vm_start; +u64 offset; +int ret;
drivers/fpga/dfl-afu-main.c static long afu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) · line 307
Quoted 10 lines
drivers/fpga/dfl-afu-main.c +10
-0+ +if (!(vma->vm_flags &VM_SHARED )) +return -EINVAL ; + + offset = vma->vm_pgoff <<PAGE_SHIFT ; + ret =afu_get_region_by_offset (pdata, offset, size, ®ion); +if (ret) +return ret; + +if (!(region.flags &FPGA_REGION_MMAP ))
FPGA_REGION_*? We already have FPGA regions which are something different. Please call this something else.
Quoted 108 lines
drivers/fpga/dfl-afu-main.c +64
-2+return -EINVAL ; + +if ((vma->vm_flags &VM_READ ) && !(region.flags &FPGA_REGION_READ )) +return -EPERM ; + +if ((vma->vm_flags &VM_WRITE ) && !(region.flags &FPGA_REGION_WRITE )) +return -EPERM ; + + vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); + +return remap_pfn_range (vma, vma->vm_start, + (region.phys + (offset - region.offset)) >>PAGE_SHIFT , + size, vma->vm_page_prot); +} +static const struct file_operations afu_fops = { .owner =THIS_MODULE , .open = afu_open, .release = afu_release, .unlocked_ioctl = afu_ioctl, + .mmap = afu_mmap, }; +static int afu_dev_init (struct platform_device *pdev) +{ +struct fpga_afu *afu; +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); + + afu =devm_kzalloc (&pdev->dev,sizeof (*afu),GFP_KERNEL ); +if (!afu) +return -ENOMEM ; + + afu->pdata = pdata; + +mutex_lock (&pdata->lock); +fpga_pdata_set_private (pdata, afu); +afu_region_init (pdata); +mutex_unlock (&pdata->lock); +return 0 ; +} + +static int afu_dev_destroy (struct platform_device *pdev) +{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_afu *afu; + +mutex_lock (&pdata->lock); + afu =fpga_pdata_get_private (pdata); +afu_region_destroy (pdata); +fpga_pdata_set_private (pdata,NULL ); +mutex_unlock (&pdata->lock); + +devm_kfree (&pdev->dev, afu); + +return 0 ; +} +static int afu_probe (struct platform_device *pdev) {int ret;dev_dbg (&pdev->dev,"%s\n" , __func__); + ret =afu_dev_init (pdev); +if (ret) + goto exit; + ret =fpga_dev_feature_init (pdev, port_feature_drvs);if (ret) -return ret; + goto dev_destroy; ret =fpga_register_dev_ops (pdev, &afu_fops,THIS_MODULE ); -if (ret) +if (ret) {fpga_dev_feature_uinit (pdev); + goto dev_destroy; + } + +return 0 ; +dev_destroy: +afu_dev_destroy (pdev); +exit:return ret; }@@ -192,6 +396,7 @@ static int afu_remove(struct platform_device *pdev)fpga_dev_feature_uinit (pdev);fpga_unregister_dev_ops (pdev); +afu_dev_destroy (pdev);return 0 ; }drivers/fpga/dfl-afu-region.c new file +7
-0@@ -0,0 +1,165 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Driver for FPGA Accelerated Function Unit (AFU) Region Management +* +* Copyright (C) 2017 Intel Corporation, Inc. +* +* Authors:
drivers/fpga/dfl-afu-region.c line 17
Quoted 10 lines
drivers/fpga/dfl-afu-region.c new file +10
-0+* Wu Hao <[email protected]> +* Xiao Guangrong <[email protected]> +*/ +#include "dfl-afu.h" + +/** +* afu_region_init - init function for afu region support +* @pdata: afu platform device's pdata. +*/ +void afu_region_init (struct feature_platform_data *pdata)
These afu regions are memory regions? We also have 'FPGA regions' which are partial reconfiguration areas. It probably would be really helpful to name things to make it more clear what these are and that they are not what drivers/fpga already calls "FPGA regions".
Quoted 284 lines
drivers/fpga/dfl-afu-region.c new file +148
-0+{ +struct fpga_afu *afu =fpga_pdata_get_private (pdata); + +INIT_LIST_HEAD (&afu->regions); +} + +#define for_each_region (region, afu) \ + list_for_each_entry((region), &(afu)->regions, node) + +static struct fpga_afu_region *get_region_by_index (struct fpga_afu *afu, +u32 region_index) +{ +struct fpga_afu_region *region; + +for_each_region (region, afu) +if (region->index == region_index) +return region; + +return NULL ; +} + +/** +* afu_region_add - add a region to given feature dev. +* +* @region_index: region index. +* @region_size: region size. +* @phys: region's physical address of this region. +* @flags: region flags (access permission). +* +* Return: 0 on success, negative error code otherwise. +*/ +int afu_region_add (struct feature_platform_data *pdata,u32 region_index, +u64 region_size,u64 phys,u32 flags) +{ +struct fpga_afu_region *region; +struct fpga_afu *afu; +int ret =0 ; + + region =devm_kzalloc (&pdata->dev->dev,sizeof (*region),GFP_KERNEL ); +if (!region) +return -ENOMEM ; + + region->index = region_index; + region->size = region_size; + region->phys = phys; + region->flags = flags; + +mutex_lock (&pdata->lock); + + afu =fpga_pdata_get_private (pdata); + +/* check if @index already exists */ +if (get_region_by_index (afu, region_index)) { +mutex_unlock (&pdata->lock); + ret = -EEXIST ; + goto exit; + } + + region_size =PAGE_ALIGN (region_size); + region->offset = afu->region_cur_offset; +list_add (®ion->node, &afu->regions); + + afu->region_cur_offset += region_size; + afu->num_regions++; +mutex_unlock (&pdata->lock); + +return 0 ; + +exit: +devm_kfree (&pdata->dev->dev, region); +return ret; +} + +/** +* afu_region_destroy - destroy all regions under given feature dev. +* @pdata: afu platform device's pdata. +*/ +void afu_region_destroy (struct feature_platform_data *pdata) +{ +struct fpga_afu_region *tmp, *region; +struct fpga_afu *afu =fpga_pdata_get_private (pdata); + +list_for_each_entry_safe (region, tmp, &afu->regions, node) +devm_kfree (&pdata->dev->dev, region); +} + +/** +* afu_get_region_by_index - find an afu region by index. +* @pdata: afu platform device's pdata. +* @region_index: region index. +* @pregion: ptr to region for result. +* +* Return: 0 on success, negative error code otherwise. +*/ +int afu_get_region_by_index (struct feature_platform_data *pdata, +u32 region_index,struct fpga_afu_region *pregion) +{ +struct fpga_afu_region *region; +struct fpga_afu *afu; +int ret =0 ; + +mutex_lock (&pdata->lock); + afu =fpga_pdata_get_private (pdata); + region =get_region_by_index (afu, region_index); +if (!region) { + ret = -EINVAL ; + goto exit; + } + *pregion = *region; +exit: +mutex_unlock (&pdata->lock); +return ret; +} + +/** +* afu_get_region_by_offset - find an afu region by offset and size +* +* @pdata: afu platform device's pdata. +* @offset: region offset from start of the device fd. +* @size: region size. +* @pregion: ptr to region for result. +* +* Find the region which fully contains the region described by input +* parameters (offset and size) from the feature dev's region link list. +* +* Return: 0 on success, negative error code otherwise. +*/ +int afu_get_region_by_offset (struct feature_platform_data *pdata, +u64 offset,u64 size, +struct fpga_afu_region *pregion) +{ +struct fpga_afu_region *region; +struct fpga_afu *afu; +int ret =0 ; + +mutex_lock (&pdata->lock); + afu =fpga_pdata_get_private (pdata); +for_each_region (region, afu) +if (region->offset <= offset && + region->offset + region->size >= offset + size) { + *pregion = *region; + goto exit; + } + ret = -EINVAL ; +exit: +mutex_unlock (&pdata->lock); +return ret; +}drivers/fpga/dfl-afu.h new file +71
-0@@ -0,0 +1,71 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Header file for FPGA Accelerated Function Unit (AFU) Driver +* +* Copyright (C) 2017 Intel Corporation, Inc. +* +* Authors: +* Wu Hao <[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]> +*/ + +#ifndef __DFL_AFU_H +#define __DFL_AFU_H + +#include <linux/mm.h> + +#include "dfl.h" + +/** +* struct fpga_afu_region - afu region data structure +* +* @index: region index. +* @flags: region flags (access permission). +* @size: region size. +* @offset: region offset from start of the device fd. +* @phys: region's physical address. +* @node: node to add to afu feature dev's region list. +*/ +struct fpga_afu_region { +u32 index; +u32 flags; +u64 size; +u64 offset; +u64 phys; +struct list_head node; +}; + +/** +* struct fpga_afu - afu device data structure +* +* @region_cur_offset: current region offset from start to the device fd. +* @num_regions: num of regions. +* @regions: the region link list of this afu feature device. +* @num_umsgs: num of umsgs. +* @pdata: afu platform device's pdata. +*/ +struct fpga_afu { +u64 region_cur_offset; +int num_regions; +u8 num_umsgs; +struct list_head regions; + +struct feature_platform_data *pdata; +}; + +void afu_region_init (struct feature_platform_data *pdata); +int afu_region_add (struct feature_platform_data *pdata,u32 region_index, +u64 region_size,u64 phys,u32 flags); +void afu_region_destroy (struct feature_platform_data *pdata); +int afu_get_region_by_index (struct feature_platform_data *pdata, +u32 region_index,struct fpga_afu_region *pregion); +int afu_get_region_by_offset (struct feature_platform_data *pdata, +u64 offset,u64 size, +struct fpga_afu_region *pregion); + +#endif include/uapi/linux/fpga-dfl.h +47
-1@@ -65,6 +65,53 @@#define FPGA_PORT_RESET _IO(FPGA_MAGIC, PORT_BASE + 0) +/** +* FPGA_PORT_GET_INFO - _IOR(FPGA_MAGIC, PORT_BASE + 1, struct fpga_port_info) +* +* Retrieve information about the fpga port. +* Driver fills the info in provided struct fpga_port_info. +* Return: 0 on success, -errno on failure. +*/ +struct fpga_port_info { +/* Input */ +__u32 argsz;/* Structure length */ +/* Output */ +__u32 flags;/* Zero for now */ +__u32 num_regions;/* The number of supported regions */ +__u32 num_umsgs;/* The number of allocated umsgs */ +}; + +#define FPGA_PORT_GET_INFO _IO(FPGA_MAGIC, PORT_BASE + 1) + +/** +* FPGA_PORT_GET_REGION_INFO - _IOWR(FPGA_MAGIC, PORT_BASE + 2, +* struct fpga_port_region_info) +* +* Retrieve information about a device region. +* Caller provides struct fpga_port_region_info with index value set. +* Driver returns the region info in other fields. +* Return: 0 on success, -errno on failure. +*/ +struct fpga_port_region_info { +/* input */ +__u32 argsz;/* Structure length */ +/* Output */ +__u32 flags;/* Access permission */ +#define FPGA_REGION_READ (1 << 0)/* Region is readable */ +#define FPGA_REGION_WRITE (1 << 1)/* Region is writable */ +#define FPGA_REGION_MMAP (1 << 2)/* Can be mmaped to userspace */ +/* Input */ +__u32 index;/* Region index */ +#define FPGA_PORT_INDEX_UAFU 0/* User AFU */ +#define FPGA_PORT_INDEX_STP 1/* Signal Tap */ +__u32 padding; +/* Output */ +__u64 size;/* Region size (bytes) */ +__u64 offset;/* Region offset from start of device fd */ +}; + +#define FPGA_PORT_GET_REGION_INFO _IO(FPGA_MAGIC, PORT_BASE + 2) +/* IOCTLs for FME file descriptor */ /** --
Quoted 2 lines
2.7.4
Thanks,
Alan
Re: [PATCH v4 23/24] fpga: dfl: afu: add user afu sub feature support
Quoted 9 lines · Alan Tull
On Tue, Feb 13, 2018 at 3:24 AM, Wu Hao <[email protected]> wrote:
Hi Hao,
Quoted 3 lines
From: Xiao Guangrong <[email protected]>
User Accelerated Function Unit sub feature exposes the MMIO region of
Is it 'user accelerated'? I think it is the Accelerator interface.
Hi Alan,
This is only used to emphasize this is the interface to accelerator exposed to user. But looks like this causes some confusions for user actually from the description. I agree with you, that I will remove this UAFU from this patchset.
Quoted 8 lines
Quoted 2 lines
the AFU. After valid green bitstream (GBS) is programmed and port is
Would it make sense to just use "partial bitstream" or "PR bitstream" and "static bitstream" for this patchset? I don't think that adding this terminology makes things clearer. In any case when someone else uses this patchset, they may not be using this type of branding in their terminology.
Sure, will update the commit message and also sysfs doc below.
Quoted 18 lines
Quoted 9 lines
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 green bitstream is programmed to this AFU.Here too.
Quoted 5 lines
Ioctl interfaces:
*FPGA_PORT_GET_INFO
Provide info to userspace on the number of supported region. Only UAFU region is supported now.
Quoted 4 lines
I think UAFU is really the interface for an AFU. I'd like to not add more terminology than is really useful here. Unless I'm missing something, all the UAFU stuff here is really AFU and not some different block.
Yes, you're right, will remove UAFU from this patchset.
Quoted 117 lines
Quoted 96 lines
*
FPGA_PORT_GET_REGION_INFO
Provide region information, including access permission, region size, offset from the start of device fd.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 Xiao Guangrong <[email protected]>Signed-off-by Wu Hao <[email protected]>---
v2: moved the code todrivers/fpgafolder as suggested by Alan Tull.
add sysfs documentation.
switched to GPLv2 license.
v3: rename driver to fpga-dfl-afu
fix coding style and checkpatch issue.
only allowafu_idto be read when port isn't in reset.
v4: rebase and add more comments in code.
fix SPDX license issue.--- Documentation/ABI/testing/sysfs-platform-dfl-port | 9 + drivers/fpga/Makefile | 2 +- drivers/fpga/dfl-afu-main.c | 211 +++++++++++++++++++++- drivers/fpga/dfl-afu-region.c | 165 +++++++++++++++++ drivers/fpga/dfl-afu.h | 71 ++++++++ include/uapi/linux/fpga-dfl.h | 47 +++++ 6 files changed, 501 insertions(+), 4 deletions(-) create mode 100644 drivers/fpga/dfl-afu-region.c create mode 100644 drivers/fpga/dfl-afu.hDocumentation/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: Februray 2018 +KernelVersion: 4.16 +Contact: Wu Hao <[email protected]> +Description: Read-only. User can program different green bitstreams (GBS) to + FPGA Accelerator Function Unit (AFU) for different functions. + It returns uuid which could be used to identify which GBS is + programmed in this AFU.drivers/fpga/Makefile +1
-1@@ -37,7 +37,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.odrivers/fpga/dfl-afu-main.c +16
-1@@ -16,9 +16,10 @@#include <linux/kernel.h> #include <linux/module.h> +#include <linux/uaccess.h> #include <linux/fpga-dfl.h> -#include "dfl.h" +#include "dfl-afu.h" static ssize_t id_show (struct device *dev,struct device_attribute *attr,char *buf)@@ -78,12 +79,74 @@ static const struct feature_ops port_hdr_ops = { .ioctl = port_hdr_ioctl, }; +static ssize_t +afu_id_show (struct device *dev,struct device_attribute *attr,char *buf) +{ +struct feature_platform_data *pdata =dev_get_platdata (dev); +void __iomem *base; +u64 guidl, guidh; + + base =get_feature_ioaddr_by_id (dev,PORT_FEATURE_ID_AFU ); + +mutex_lock (&pdata->lock); +if (pdata->disable_count) { +mutex_unlock (&pdata->lock); +return -EBUSY ; + }drivers/fpga/dfl-afu-main.c static const struct feature_ops port_hdr_ops = { · line 105
Quoted 10 lines
drivers/fpga/dfl-afu-main.c +10
-0+ + guidl =readq (base +GUID_L ); + guidh =readq (base +GUID_H ); +mutex_unlock (&pdata->lock); + +return scnprintf (buf,PAGE_SIZE ,"%016llx%016llx\n" , guidh, guidl); +} +static DEVICE_ATTR_RO (afu_id); + +static const struct attribute *port_uafu_attrs[] = {
port_afu_attrs?drivers/fpga/dfl-afu-main.c static const struct feature_ops port_hdr_ops = { · line 110
Quoted 5 lines
drivers/fpga/dfl-afu-main.c +5
-0+ &dev_attr_afu_id.attr, + NULL +}; + +static int port_uafu_init (struct platform_device *pdev,struct feature *feature)
port_afu_init?
Quoted 2 lines
so on. The thing's userspace interface doesn't have to be named differently from the thing itself.
Agree, will fix them.
Quoted 107 lines
Quoted 107 lines
drivers/fpga/dfl-afu-main.c +91
-0+{ +struct resource *res = &pdev->resource[feature->resource_index]; +u32 flags =FPGA_REGION_READ |FPGA_REGION_WRITE |FPGA_REGION_MMAP ; +int ret; + +dev_dbg (&pdev->dev,"PORT AFU Init.\n" ); + + ret =afu_region_add (dev_get_platdata (&pdev->dev), +FPGA_PORT_INDEX_UAFU ,resource_size (res), + res->start, flags); +if (ret) +return ret; + +return sysfs_create_files (&pdev->dev.kobj, port_uafu_attrs); +} + +static void port_uafu_uinit (struct platform_device *pdev, +struct feature *feature) +{ +dev_dbg (&pdev->dev,"PORT AFU UInit.\n" ); + +sysfs_remove_files (&pdev->dev.kobj, port_uafu_attrs); +} + +static const struct feature_ops port_uafu_ops = { + .init = port_uafu_init, + .uinit = port_uafu_uinit, +}; +static struct feature_driver port_feature_drvs[] = { { .id =PORT_FEATURE_ID_HEADER , .ops = &port_hdr_ops, }, { + .id =PORT_FEATURE_ID_AFU , + .ops = &port_uafu_ops, + }, + { .ops =NULL , } };@@ -128,6 +191,64 @@ static long afu_ioctl_check_extension(struct feature_platform_data *pdata,return 0 ; } +static long +afu_ioctl_get_info (struct feature_platform_data *pdata,void __user *arg) +{ +struct fpga_port_info info; +struct fpga_afu *afu; +unsigned long minsz; + + minsz = offsetofend(struct fpga_port_info, num_umsgs); + +if (copy_from_user (&info, arg, minsz)) +return -EFAULT ; + +if (info.argsz < minsz) +return -EINVAL ; + +mutex_lock (&pdata->lock); + afu =fpga_pdata_get_private (pdata); + info.flags =0 ; + info.num_regions = afu->num_regions; + info.num_umsgs = afu->num_umsgs; +mutex_unlock (&pdata->lock); + +if (copy_to_user (arg, &info,sizeof (info))) +return -EFAULT ; + +return 0 ; +} + +static long +afu_ioctl_get_region_info (struct feature_platform_data *pdata,void __user *arg) +{ +struct fpga_port_region_info rinfo; +struct fpga_afu_region region; +unsigned long minsz; +long ret; + + minsz = offsetofend(struct fpga_port_region_info, offset); + +if (copy_from_user (&rinfo, arg, minsz)) +return -EFAULT ; + +if (rinfo.argsz < minsz || rinfo.padding) +return -EINVAL ; + + ret =afu_get_region_by_index (pdata, rinfo.index, ®ion); +if (ret) +return ret; + + rinfo.flags = region.flags; + rinfo.size = region.size; + rinfo.offset = region.offset; + +if (copy_to_user (arg, &rinfo,sizeof (rinfo))) +return -EFAULT ; + +return 0 ; +} +static long afu_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) {
Quoted 8 lines
drivers/fpga/dfl-afu-main.c static long afu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) · line 264
Quoted 4 lines
drivers/fpga/dfl-afu-main.c +0
-0struct platform_device *pdev = filp->private_data;@@ -142,6 +263,10 @@ static long afu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)return FPGA_API_VERSION ;case FPGA_CHECK_EXTENSION :I commented elsewhere about the FPGA_* names. These names such as
FPGA_CHECK_EXTENSIONare specific to this DFL patchset, they weren't written as addtions to the lower level FPGA stuff.
Yes, will fix this.
Quoted 26 lines
Quoted 26 lines
drivers/fpga/dfl-afu-main.c +17
-0return afu_ioctl_check_extension (pdata, arg); +case FPGA_PORT_GET_INFO : +return afu_ioctl_get_info (pdata, (void __user *)arg); +case FPGA_PORT_GET_REGION_INFO : +return afu_ioctl_get_region_info (pdata, (void __user *)arg);default :/* * Let sub-feature's ioctl function to handle the cmd @@ -162,27 +287,106 @@ static long afu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)return -EINVAL ; } +static int afu_mmap (struct file *filp,struct vm_area_struct *vma) +{ +struct fpga_afu_region region; +struct platform_device *pdev = filp->private_data; +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +u64 size = vma->vm_end - vma->vm_start; +u64 offset; +int ret; + +if (!(vma->vm_flags &VM_SHARED )) +return -EINVAL ; + + offset = vma->vm_pgoff <<PAGE_SHIFT ;
Quoted 8 lines
drivers/fpga/dfl-afu-main.c static long afu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) · line 307
Quoted 5 lines
drivers/fpga/dfl-afu-main.c +5
-0+ ret =afu_get_region_by_offset (pdata, offset, size, ®ion); +if (ret) +return ret; + +if (!(region.flags &FPGA_REGION_MMAP ))FPGA_REGION_*? We already have FPGA regions which are something different. Please call this something else.
Yes, will replace it with DFL_FPGA_*.
Quoted 116 lines
Quoted 116 lines
drivers/fpga/dfl-afu-main.c +64
-2+return -EINVAL ; + +if ((vma->vm_flags &VM_READ ) && !(region.flags &FPGA_REGION_READ )) +return -EPERM ; + +if ((vma->vm_flags &VM_WRITE ) && !(region.flags &FPGA_REGION_WRITE )) +return -EPERM ; + + vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); + +return remap_pfn_range (vma, vma->vm_start, + (region.phys + (offset - region.offset)) >>PAGE_SHIFT , + size, vma->vm_page_prot); +} +static const struct file_operations afu_fops = { .owner =THIS_MODULE , .open = afu_open, .release = afu_release, .unlocked_ioctl = afu_ioctl, + .mmap = afu_mmap, }; +static int afu_dev_init (struct platform_device *pdev) +{ +struct fpga_afu *afu; +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); + + afu =devm_kzalloc (&pdev->dev,sizeof (*afu),GFP_KERNEL ); +if (!afu) +return -ENOMEM ; + + afu->pdata = pdata; + +mutex_lock (&pdata->lock); +fpga_pdata_set_private (pdata, afu); +afu_region_init (pdata); +mutex_unlock (&pdata->lock); +return 0 ; +} + +static int afu_dev_destroy (struct platform_device *pdev) +{ +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +struct fpga_afu *afu; + +mutex_lock (&pdata->lock); + afu =fpga_pdata_get_private (pdata); +afu_region_destroy (pdata); +fpga_pdata_set_private (pdata,NULL ); +mutex_unlock (&pdata->lock); + +devm_kfree (&pdev->dev, afu); + +return 0 ; +} +static int afu_probe (struct platform_device *pdev) {int ret;dev_dbg (&pdev->dev,"%s\n" , __func__); + ret =afu_dev_init (pdev); +if (ret) + goto exit; + ret =fpga_dev_feature_init (pdev, port_feature_drvs);if (ret) -return ret; + goto dev_destroy; ret =fpga_register_dev_ops (pdev, &afu_fops,THIS_MODULE ); -if (ret) +if (ret) {fpga_dev_feature_uinit (pdev); + goto dev_destroy; + } + +return 0 ; +dev_destroy: +afu_dev_destroy (pdev); +exit:return ret; }@@ -192,6 +396,7 @@ static int afu_remove(struct platform_device *pdev)fpga_dev_feature_uinit (pdev);fpga_unregister_dev_ops (pdev); +afu_dev_destroy (pdev);return 0 ; }drivers/fpga/dfl-afu-region.c new file +14
-0@@ -0,0 +1,165 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Driver for FPGA Accelerated Function Unit (AFU) Region Management +* +* Copyright (C) 2017 Intel Corporation, Inc. +* +* Authors: +* Wu Hao <[email protected]> +* Xiao Guangrong <[email protected]> +*/ +#include "dfl-afu.h" + +/** +* afu_region_init - init function for afu region support
Quoted 8 lines
drivers/fpga/dfl-afu-region.c line 17
Quoted 3 lines
drivers/fpga/dfl-afu-region.c new file +3
-0+* @pdata: afu platform device's pdata. +*/ +void afu_region_init (struct feature_platform_data *pdata)These afu regions are memory regions? We also have 'FPGA regions' which are partial reconfiguration areas. It probably would be really helpful to name things to make it more clear what these are and that they are not what
drivers/fpgaalready calls "FPGA regions".
Yes, these afu regions are memory regions for MMIO, will fix this too.
Thanks
Hao
Quoted 290 lines
Quoted 285 lines
drivers/fpga/dfl-afu-region.c new file +148
-0+{ +struct fpga_afu *afu =fpga_pdata_get_private (pdata); + +INIT_LIST_HEAD (&afu->regions); +} + +#define for_each_region (region, afu) \ + list_for_each_entry((region), &(afu)->regions, node) + +static struct fpga_afu_region *get_region_by_index (struct fpga_afu *afu, +u32 region_index) +{ +struct fpga_afu_region *region; + +for_each_region (region, afu) +if (region->index == region_index) +return region; + +return NULL ; +} + +/** +* afu_region_add - add a region to given feature dev. +* +* @region_index: region index. +* @region_size: region size. +* @phys: region's physical address of this region. +* @flags: region flags (access permission). +* +* Return: 0 on success, negative error code otherwise. +*/ +int afu_region_add (struct feature_platform_data *pdata,u32 region_index, +u64 region_size,u64 phys,u32 flags) +{ +struct fpga_afu_region *region; +struct fpga_afu *afu; +int ret =0 ; + + region =devm_kzalloc (&pdata->dev->dev,sizeof (*region),GFP_KERNEL ); +if (!region) +return -ENOMEM ; + + region->index = region_index; + region->size = region_size; + region->phys = phys; + region->flags = flags; + +mutex_lock (&pdata->lock); + + afu =fpga_pdata_get_private (pdata); + +/* check if @index already exists */ +if (get_region_by_index (afu, region_index)) { +mutex_unlock (&pdata->lock); + ret = -EEXIST ; + goto exit; + } + + region_size =PAGE_ALIGN (region_size); + region->offset = afu->region_cur_offset; +list_add (®ion->node, &afu->regions); + + afu->region_cur_offset += region_size; + afu->num_regions++; +mutex_unlock (&pdata->lock); + +return 0 ; + +exit: +devm_kfree (&pdata->dev->dev, region); +return ret; +} + +/** +* afu_region_destroy - destroy all regions under given feature dev. +* @pdata: afu platform device's pdata. +*/ +void afu_region_destroy (struct feature_platform_data *pdata) +{ +struct fpga_afu_region *tmp, *region; +struct fpga_afu *afu =fpga_pdata_get_private (pdata); + +list_for_each_entry_safe (region, tmp, &afu->regions, node) +devm_kfree (&pdata->dev->dev, region); +} + +/** +* afu_get_region_by_index - find an afu region by index. +* @pdata: afu platform device's pdata. +* @region_index: region index. +* @pregion: ptr to region for result. +* +* Return: 0 on success, negative error code otherwise. +*/ +int afu_get_region_by_index (struct feature_platform_data *pdata, +u32 region_index,struct fpga_afu_region *pregion) +{ +struct fpga_afu_region *region; +struct fpga_afu *afu; +int ret =0 ; + +mutex_lock (&pdata->lock); + afu =fpga_pdata_get_private (pdata); + region =get_region_by_index (afu, region_index); +if (!region) { + ret = -EINVAL ; + goto exit; + } + *pregion = *region; +exit: +mutex_unlock (&pdata->lock); +return ret; +} + +/** +* afu_get_region_by_offset - find an afu region by offset and size +* +* @pdata: afu platform device's pdata. +* @offset: region offset from start of the device fd. +* @size: region size. +* @pregion: ptr to region for result. +* +* Find the region which fully contains the region described by input +* parameters (offset and size) from the feature dev's region link list. +* +* Return: 0 on success, negative error code otherwise. +*/ +int afu_get_region_by_offset (struct feature_platform_data *pdata, +u64 offset,u64 size, +struct fpga_afu_region *pregion) +{ +struct fpga_afu_region *region; +struct fpga_afu *afu; +int ret =0 ; + +mutex_lock (&pdata->lock); + afu =fpga_pdata_get_private (pdata); +for_each_region (region, afu) +if (region->offset <= offset && + region->offset + region->size >= offset + size) { + *pregion = *region; + goto exit; + } + ret = -EINVAL ; +exit: +mutex_unlock (&pdata->lock); +return ret; +}drivers/fpga/dfl-afu.h new file +71
-0@@ -0,0 +1,71 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Header file for FPGA Accelerated Function Unit (AFU) Driver +* +* Copyright (C) 2017 Intel Corporation, Inc. +* +* Authors: +* Wu Hao <[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]> +*/ + +#ifndef __DFL_AFU_H +#define __DFL_AFU_H + +#include <linux/mm.h> + +#include "dfl.h" + +/** +* struct fpga_afu_region - afu region data structure +* +* @index: region index. +* @flags: region flags (access permission). +* @size: region size. +* @offset: region offset from start of the device fd. +* @phys: region's physical address. +* @node: node to add to afu feature dev's region list. +*/ +struct fpga_afu_region { +u32 index; +u32 flags; +u64 size; +u64 offset; +u64 phys; +struct list_head node; +}; + +/** +* struct fpga_afu - afu device data structure +* +* @region_cur_offset: current region offset from start to the device fd. +* @num_regions: num of regions. +* @regions: the region link list of this afu feature device. +* @num_umsgs: num of umsgs. +* @pdata: afu platform device's pdata. +*/ +struct fpga_afu { +u64 region_cur_offset; +int num_regions; +u8 num_umsgs; +struct list_head regions; + +struct feature_platform_data *pdata; +}; + +void afu_region_init (struct feature_platform_data *pdata); +int afu_region_add (struct feature_platform_data *pdata,u32 region_index, +u64 region_size,u64 phys,u32 flags); +void afu_region_destroy (struct feature_platform_data *pdata); +int afu_get_region_by_index (struct feature_platform_data *pdata, +u32 region_index,struct fpga_afu_region *pregion); +int afu_get_region_by_offset (struct feature_platform_data *pdata, +u64 offset,u64 size, +struct fpga_afu_region *pregion); + +#endif include/uapi/linux/fpga-dfl.h +47
-1@@ -65,6 +65,53 @@#define FPGA_PORT_RESET _IO(FPGA_MAGIC, PORT_BASE + 0) +/** +* FPGA_PORT_GET_INFO - _IOR(FPGA_MAGIC, PORT_BASE + 1, struct fpga_port_info) +* +* Retrieve information about the fpga port. +* Driver fills the info in provided struct fpga_port_info. +* Return: 0 on success, -errno on failure. +*/ +struct fpga_port_info { +/* Input */ +__u32 argsz;/* Structure length */ +/* Output */ +__u32 flags;/* Zero for now */ +__u32 num_regions;/* The number of supported regions */ +__u32 num_umsgs;/* The number of allocated umsgs */ +}; + +#define FPGA_PORT_GET_INFO _IO(FPGA_MAGIC, PORT_BASE + 1) + +/** +* FPGA_PORT_GET_REGION_INFO - _IOWR(FPGA_MAGIC, PORT_BASE + 2, +* struct fpga_port_region_info) +* +* Retrieve information about a device region. +* Caller provides struct fpga_port_region_info with index value set. +* Driver returns the region info in other fields. +* Return: 0 on success, -errno on failure. +*/ +struct fpga_port_region_info { +/* input */ +__u32 argsz;/* Structure length */ +/* Output */ +__u32 flags;/* Access permission */ +#define FPGA_REGION_READ (1 << 0)/* Region is readable */ +#define FPGA_REGION_WRITE (1 << 1)/* Region is writable */ +#define FPGA_REGION_MMAP (1 << 2)/* Can be mmaped to userspace */ +/* Input */ +__u32 index;/* Region index */ +#define FPGA_PORT_INDEX_UAFU 0/* User AFU */ +#define FPGA_PORT_INDEX_STP 1/* Signal Tap */ +__u32 padding; +/* Output */ +__u64 size;/* Region size (bytes) */ +__u64 offset;/* Region offset from start of device fd */ +}; + +#define FPGA_PORT_GET_REGION_INFO _IO(FPGA_MAGIC, PORT_BASE + 2) +/* IOCTLs for FME file descriptor */ /** -- Quoted 2 lines
2.7.4
Thanks,
Alan
Re: [PATCH v4 23/24] fpga: dfl: afu: add user afu sub feature support
Quoted 21 lines · Wu Hao
Quoted 9 lines · Alan Tull
On Tue, Feb 13, 2018 at 3:24 AM, Wu Hao <[email protected]> wrote:
Hi Hao,
Quoted 3 lines
From: Xiao Guangrong <[email protected]>
User Accelerated Function Unit sub feature exposes the MMIO region of
Is it 'user accelerated'? I think it is the Accelerator interface.
Hi Alan,
This is only used to emphasize this is the interface to accelerator exposed to user. But looks like this causes some confusions for user actually from the description. I agree with you, that I will remove this UAFU from this patchset.
Quoted 3 lines
Quoted 2 lines
the AFU. After valid green bitstream (GBS) is programmed and port is
Quoted 7 lines
Quoted 5 lines
Would it make sense to just use "partial bitstream" or "PR bitstream" and "static bitstream" for this patchset? I don't think that adding this terminology makes things clearer. In any case when someone else uses this patchset, they may not be using this type of branding in their terminology.
Sure, will update the commit message and also sysfs doc below.
Yes and dfl.txt and the rest of the patchset as well, please.
Alan
Re: [PATCH v4 23/24] fpga: dfl: afu: add user afu sub feature support
Quoted 28 lines · Alan Tull
Quoted 27 lines · Wu Hao
Quoted 9 lines · Alan Tull
On Tue, Feb 13, 2018 at 3:24 AM, Wu Hao <[email protected]> wrote:
Hi Hao,
Quoted 3 lines
From: Xiao Guangrong <[email protected]>
User Accelerated Function Unit sub feature exposes the MMIO region of
Is it 'user accelerated'? I think it is the Accelerator interface.
Hi Alan,
This is only used to emphasize this is the interface to accelerator exposed to user. But looks like this causes some confusions for user actually from the description. I agree with you, that I will remove this UAFU from this patchset.
Quoted 8 lines
Quoted 2 lines
the AFU. After valid green bitstream (GBS) is programmed and port is
Would it make sense to just use "partial bitstream" or "PR bitstream" and "static bitstream" for this patchset? I don't think that adding this terminology makes things clearer. In any case when someone else uses this patchset, they may not be using this type of branding in their terminology.
Quoted 3 lines
Quoted 1 line
Sure, will update the commit message and also sysfs doc below.
Yes and dfl.txt and the rest of the patchset as well, please.
Sure, I understand that it may have different PR hardwares under this framework, each PR hardware may have a different terminology for its own bitstream. We should use common terminology in the common doc and code to avoid confusion. Thanks for the reminder. I will fix this.
Thanks
Hao
Quoted 2 lines
Alan
Re: [PATCH v4 23/24] fpga: dfl: afu: add user afu sub feature support
In reply to Wu HaoQuoted 6 lines · Wu Hao
Quoted 6 lines
Quoted 6 lines
drivers/fpga/dfl-afu-main.c +6
-0+static int afu_mmap (struct file *filp,struct vm_area_struct *vma) +{ +struct fpga_afu_region region; +struct platform_device *pdev = filp->private_data; +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +u64 size = vma->vm_end - vma->vm_start;
Quoted 8 lines
Quoted 8 lines
drivers/fpga/dfl-afu-main.c static long afu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) · line 303
Quoted 8 lines
drivers/fpga/dfl-afu-main.c +8
-0+u64 offset; +int ret; + +if (!(vma->vm_flags &VM_SHARED )) +return -EINVAL ; + + offset = vma->vm_pgoff <<PAGE_SHIFT ; + ret =afu_get_region_by_offset (pdata, offset, size, ®ion);
Most of the functions here are afu_region_*, but there's also afu_get_region_by_*. Better if afu_region_get_by_* to be consistent.
Quoted 9 lines
Quoted 7 lines
drivers/fpga/dfl-afu-main.c static long afu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) · line 307
Quoted 4 lines
drivers/fpga/dfl-afu-main.c +4
-0+if (ret) +return ret; + +if (!(region.flags &FPGA_REGION_MMAP ))FPGA_REGION_*? We already have FPGA regions which are something different. Please call this something else.
Yes, will replace it with DFL_FPGA_*.
Re: [PATCH v4 23/24] fpga: dfl: afu: add user afu sub feature support
Quoted 11 lines · Alan Tull
Quoted 9 lines · Wu Hao
Quoted 9 lines
Quoted 9 lines
drivers/fpga/dfl-afu-main.c +9
-0+static int afu_mmap (struct file *filp,struct vm_area_struct *vma) +{ +struct fpga_afu_region region; +struct platform_device *pdev = filp->private_data; +struct feature_platform_data *pdata =dev_get_platdata (&pdev->dev); +u64 size = vma->vm_end - vma->vm_start; +u64 offset; +int ret; +
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
drivers/fpga/dfl-afu-main.c static long afu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) · line 303
Quoted 5 lines
drivers/fpga/dfl-afu-main.c +5
-0+if (!(vma->vm_flags &VM_SHARED )) +return -EINVAL ; + + offset = vma->vm_pgoff <<PAGE_SHIFT ; + ret =afu_get_region_by_offset (pdata, offset, size, ®ion);Most of the functions here are afu_region_*, but there's also afu_get_region_by_*. Better if afu_region_get_by_* to be consistent.
Agree, will fix it in the next version, thanks a lot for the comments.
Hao
PATCH v4 24/24 fpga: dfl: afu: add 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 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:
* FPGA_PORT_DMA_MAP
Do the dma mapping per user_addr and length which provided by user. Return iova in provided struct afu_port_dma_map.
* 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
--- 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
@@ -37,7 +37,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,12 +41,32 @@ struct fpga_afu_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 fpga_afu_dma_region { +u64 user_addr; +u64 length; +u64 iova; +struct page **pages; +struct rb_node node; +bool in_use; +}; + +/** * struct fpga_afu - afu device data structure * * @region_cur_offset: current region offset from start to the device fd. * @num_regions: num of regions. * @regions: the region link list of this afu feature device. * @num_umsgs: num of umsgs. +* @dma_regions: root of dma regions rb tree. * @pdata: afu platform device's pdata. */ struct fpga_afu {
@@ -54,6 +74,7 @@ struct fpga_afu {int num_regions;u8 num_umsgs;struct list_head regions; +struct rb_root dma_regions;struct feature_platform_data *pdata; };
@@ -68,4 +89,12 @@ int afu_get_region_by_offset(struct feature_platform_data *pdata, u64 offset, u64 size, struct fpga_afu_region *pregion); -#endif +void afu_dma_region_init (struct feature_platform_data *pdata); +void afu_dma_region_destroy (struct feature_platform_data *pdata); +int afu_dma_map_region (struct feature_platform_data *pdata, +u64 user_addr,u64 length,u64 *iova); +int afu_dma_unmap_region (struct feature_platform_data *pdata,u64 iova); +struct fpga_afu_dma_region * +afu_dma_region_find (struct feature_platform_data *pdata,u64 iova,u64 size); + +#endif /* __DFL_AFU_H */
include/uapi/linux/fpga-dfl.h +37 -0
@@ -112,6 +112,43 @@ struct fpga_port_region_info {#define FPGA_PORT_GET_REGION_INFO _IO(FPGA_MAGIC, PORT_BASE + 2) +/** +* FPGA_PORT_DMA_MAP - _IOWR(FPGA_MAGIC, PORT_BASE + 3, +* struct 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 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 FPGA_PORT_DMA_MAP _IO(FPGA_MAGIC, PORT_BASE + 3) + +/** +* FPGA_PORT_DMA_UNMAP - _IOW(FPGA_MAGIC, PORT_BASE + 4, +* struct fpga_port_dma_unmap) +* +* Unmap the dma memory per iova provided by caller. +* Return: 0 on success, -errno on failure. +*/ +struct fpga_port_dma_unmap { +/* Input */ +__u32 argsz;/* Structure length */ +__u32 flags;/* Zero for now */ +__u64 iova;/* IO virtual address */ +}; + +#define FPGA_PORT_DMA_UNMAP _IO(FPGA_MAGIC, PORT_BASE + 4) +/* IOCTLs for FME file descriptor */ /**
Signature · 1 line
2.7.4