fpga: dfl: fix kernel warning on port release/assign for SRIOV
Subsystems (2)
v4 cover fpga: dfl: fix kernel warning on port release/assign for SRIOV
With the Intel FPGA PAC D5005, DFL ports are registered as platform devices in PF mode. The port device must be removed from the host when the user wants to configure the port as a VF for use by a user-space driver, e.g., for pass-through to a virtual machine. The FME device ioctls DFL_FPGA_FME_PORT_RELEASE/ASSIGN are assigned for this purpose.
In the previous implementation, the port platform device is not completely destroyed on port release: it is removed from the system by platform_device_del(), but the platform device instance is retained. When DFL_FPGA_FME_PORT_ASSIGN is called, the platform device is added back with platform_device_add(), which conflicts with this comment of device_add(): "Do not call this routine more than once for any device structure", and would previously cause a kernel warning at runtime.
This patch completely unregisters the port platform device on release and registers a new device on assign. But the main work is to remove the dependency on struct dfl_feature_platform_data for many internal DFL APIs. This structure holds many DFL enumeration infos for feature devices. Many DFL APIs are expected to work with these infos even when the port platform device is unregistered. But after this change, the platform_data will be freed on port release. Hence this patch introduces a new structure dfl_feature_dev_data, which acts similarly to the previous dfl_feature_platform_data. dfl_feature_platform_data then only needs a pointer to dfl_feature_dev_data to query DFL enumeration infos.
Changes since v3:
- The last patch of the v2 series has been broken up into smaller, self-contained patches, which carry out and describe each cosmetic or functional transformation separately to ensure its correctness.
- When a port had been released using the DFL_FPGA_FME_PORT_RELEASE ioctl, the corresponding device id was no longer being released as part of dfl_fpga_feature_devs_remove(). Instead of manually cleaning up feature device ids, use devm_add_action_or_reset() to automatically free the device id right before the corresponding feature device data is freed.
Changes since v2:
- Restructure series to break monolithic v1 patch into logical, self-contained patches, instead of per-file patches as in v2. In particular, the next-to-last patch only contains non-functional changes that are strictly limited to replacing pdata with fdata.
- Omit unneeded null pointer check from fme_open(), the same as for afu_open(). Refactor dfl_fpga_inode_to_feature_dev_data() to directly return the platform data and retrieve the device from the data.
- Fix missing free() of type in binfo_create_feature_dev_data(). Free allocated FIU type when devm_kmemdup() returns a NULL pointer.
- Store fdata instead of pdata as file descriptor private data in fme_open() since pdata is only used to look up fdata.
- Remove pdata pointers that are only used to look up fdata, in dfl_fpga_dev_feature_uinit() and dfl_feature_ioctl_set_irq().
- Omit unneeded argument pdata from dfl_feature_instance_init().
- Drop redundant 0 in zero initializer of dfl_feature_platform_data in feature_dev_register().
- Revert defining pointer to device when the pointer is only used once per function, in afu_dma_region_add() and afu_dma_region_add().
- Revert minor, unneeded code formatting changes to reduce noise.
Changes since v1:
- Split monolithic patch into series at request of maintainer.
- Substitute binfo->type for removed function feature_dev_id_type() in parse_feature_irqs().
- Return ERR_PTR(-ENOMEM) on !feature->params in binfo_create_feature_dev_data().
- Reorder cdev as first member of struct dfl_feature_platform_data such that container_of() to obtain pdata evaluates to a no-op.
- Change afu_ioctl_*() to receive dfl_feature_dev_data instead of dfl_feature_platform_data.
- Change fme_hdr_ioctl_*() to receive dfl_feature_dev_data instead of dfl_feature_platform_data.
- Replace local variable pdata with fdata in afu_mmap().
- Remove unused local variable pdata in afu_dev_{init,destroy}().
- Remove unused local variable pdata in fme_dev_{init,destroy}().
- Reorder local variables in afu_dma_unpin_pages() to reverse Christmas tree order.
- Align kernel-doc function name for __dfl_fpga_cdev_find_port_data().
- Substitute @fdata for @pdata in kernel-doc comments for dfl_fme_create_mgr() and dfl_fme_destroy_mgr().
Peter Colberg (18):
fpga: dfl: omit unneeded argument pdata from
dfl_feature_instance_init()
fpga: dfl: return platform data from
dfl_fpga_inode_to_feature_dev_data()
fpga: dfl: afu: use parent device to log errors on port enable/disable
fpga: dfl: afu: define local pointer to feature device
fpga: dfl: pass feature platform data instead of device as argument
fpga: dfl: factor out feature data creation from
build_info_commit_dev()
fpga: dfl: store FIU type in feature platform data
fpga: dfl: refactor internal DFL APIs to take/return feature device
data
fpga: dfl: factor out feature device registration
fpga: dfl: factor out feature device data from platform device data
fpga: dfl: convert features from flexible array member to separate
array
fpga: dfl: store MMIO resources in feature device data
fpga: dfl: store platform device name in feature device data
fpga: dfl: store platform device id in feature device data
fpga: dfl: convert is_feature_dev_detected() to use FIU type
fpga: dfl: allocate platform device after feature device data
fpga: dfl: remove unneeded function build_info_create_dev()
fpga: dfl: drop unneeded get_device() and put_device() of feature
device
Xu Yilun (1):
fpga: dfl: destroy/recreate feature platform device on port
release/assign
drivers/fpga/dfl-afu-dma-region.c | 117 ++++---- drivers/fpga/dfl-afu-error.c | 59 ++-- drivers/fpga/dfl-afu-main.c | 278 +++++++++---------- drivers/fpga/dfl-afu-region.c | 51 ++-- drivers/fpga/dfl-afu.h | 26 +- drivers/fpga/dfl-fme-br.c | 24 +- drivers/fpga/dfl-fme-error.c | 98 +++---- drivers/fpga/dfl-fme-main.c | 95 +++---- drivers/fpga/dfl-fme-pr.c | 86 +++--- drivers/fpga/dfl.c | 431 ++++++++++++++---------------- drivers/fpga/dfl.h | 140 ++++++---- 11 files changed, 708 insertions(+), 697 deletions(-)
Signature · 1 line
2.47.0
PATCH v4 1/19 fpga: dfl: omit unneeded argument pdata from dfl_feature_instance_init()
The argument pdata passed to dfl_feature_instance_init() was never used.
---
Changes since v3:
- No changes.
Changes since v2:
- New patch extracted from monolithic v1 patch.
--- drivers/fpga/dfl.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/fpga/dfl.c +1 -3
@@ -520,7 +520,6 @@ void dfl_fpga_dev_feature_uinit(struct platform_device *pdev)EXPORT_SYMBOL_GPL (dfl_fpga_dev_feature_uinit);static int dfl_feature_instance_init (struct platform_device *pdev, -struct dfl_feature_platform_data *pdata,struct dfl_feature *feature,struct dfl_feature_driver *drv) {
@@ -587,8 +586,7 @@ int dfl_fpga_dev_feature_init(struct platform_device *pdev,while (drv->ops) {dfl_fpga_dev_for_each_feature (pdata, feature) {if (dfl_feature_drv_match (feature, drv)) { - ret =dfl_feature_instance_init (pdev, pdata, - feature, drv); + ret =dfl_feature_instance_init (pdev, feature, drv);if (ret) goto exit; }
Signature · 1 line
2.47.0
PATCH v4 2/19 fpga: dfl: return platform data from dfl_fpga_inode_to_feature_dev_data()
In reply to Peter ColbergRefactor dfl_fpga_inode_to_feature_dev() to directly return the feature device platform data instead of the platform device, and retrieve the device from the data. The null pointer checks are not needed since the platform device is guaranteed to have associated feature device data.
This patch is part of a refactoring of the internal DFL APIs to move the feature device data into a new struct dfl_feature_dev_data which lifetime is independent of the corresponding platform device.
---
Changes since v3:
- Revise subject and description to detail the refactoring of dfl_fpga_inode_to_feature_dev_data() and mention the reason for the refactoring.
Changes since v2:
- New patch extracted from monolithic v1 patch.
--- drivers/fpga/dfl-afu-main.c | 8 ++------ drivers/fpga/dfl-fme-main.c | 7 ++----- drivers/fpga/dfl.h | 6 +++--- 3 files changed, 7 insertions(+), 14 deletions(-)
drivers/fpga/dfl-afu-main.c +2 -6
@@ -595,14 +595,10 @@ static struct dfl_feature_driver port_feature_drvs[] = {static int afu_open (struct inode *inode,struct file *filp) { -struct platform_device *fdev =dfl_fpga_inode_to_feature_dev (inode); -struct dfl_feature_platform_data *pdata; +struct dfl_feature_platform_data *pdata =dfl_fpga_inode_to_feature_dev_data (inode); +struct platform_device *fdev = pdata->dev;int ret; - pdata =dev_get_platdata (&fdev->dev); -if (WARN_ON (!pdata)) -return -ENODEV ; -mutex_lock (&pdata->lock); ret =dfl_feature_dev_use_begin (pdata, filp->f_flags &O_EXCL );if (!ret) {
drivers/fpga/dfl-fme-main.c +2 -5
@@ -598,13 +598,10 @@ static long fme_ioctl_check_extension(struct dfl_feature_platform_data *pdata,static int fme_open (struct inode *inode,struct file *filp) { -struct platform_device *fdev =dfl_fpga_inode_to_feature_dev (inode); -struct dfl_feature_platform_data *pdata =dev_get_platdata (&fdev->dev); +struct dfl_feature_platform_data *pdata =dfl_fpga_inode_to_feature_dev_data (inode); +struct platform_device *fdev = pdata->dev;int ret; -if (WARN_ON (!pdata)) -return -ENODEV ; -mutex_lock (&pdata->lock); ret =dfl_feature_dev_use_begin (pdata, filp->f_flags &O_EXCL );if (!ret) {
drivers/fpga/dfl.h +3 -3
@@ -398,14 +398,14 @@ int dfl_fpga_dev_ops_register(struct platform_device *pdev, struct module *owner);void dfl_fpga_dev_ops_unregister (struct platform_device *pdev); -static inline -struct platform_device *dfl_fpga_inode_to_feature_dev (struct inode *inode) +static inline struct dfl_feature_platform_data * +dfl_fpga_inode_to_feature_dev_data (struct inode *inode) {struct dfl_feature_platform_data *pdata; pdata = container_of(inode->i_cdev, struct dfl_feature_platform_data, cdev); -return pdata->dev; +return pdata; }#define dfl_fpga_dev_for_each_feature (pdata, feature) \
Signature · 1 line
2.47.0
PATCH v4 3/19 fpga: dfl: afu: use parent device to log errors on port enable/disable
In reply to Peter ColbergAFU port enable/disable may be triggered from userspace at any point, e.g., after a port has been released. This commit prepares a subsequent commit that destroys the port platform device on port release, which is then no longer available during port enable/disable. Use the parent, physical DFL, e.g., PCIe FPGA device instead for logging errors.
---
Changes since v3:
- Replace "physical" with "physical DFL" (device) in description for consistency with other patches.
Changes since v2:
- New patch extracted from monolithic v1 patch.
--- drivers/fpga/dfl-afu-main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/fpga/dfl-afu-main.c +4 -2
@@ -60,7 +60,8 @@ int __afu_port_enable(struct platform_device *pdev)if (readq_poll_timeout (base +PORT_HDR_CTRL , v, !(v &PORT_CTRL_SFTRST_ACK ),RST_POLL_INVL ,RST_POLL_TIMEOUT )) { -dev_err (&pdev->dev,"timeout, failure to enable device\n" ); +dev_err (pdata->dfl_cdev->parent, +"timeout, failure to enable device\n" );return -ETIMEDOUT ; }
@@ -99,7 +100,8 @@ int __afu_port_disable(struct platform_device *pdev)if (readq_poll_timeout (base +PORT_HDR_CTRL , v, v &PORT_CTRL_SFTRST_ACK ,RST_POLL_INVL ,RST_POLL_TIMEOUT )) { -dev_err (&pdev->dev,"timeout, failure to disable device\n" ); +dev_err (pdata->dfl_cdev->parent, +"timeout, failure to disable device\n" );return -ETIMEDOUT ; }
Signature · 1 line
2.47.0
PATCH v4 4/19 fpga: dfl: afu: define local pointer to feature device
In reply to Peter ColbergDefine local pointer to pdata->dev->dev to avoid repetition.
---
Changes since v3:
- No changes.
Changes since v2:
- New patch extracted from monolithic v1 patch.
--- drivers/fpga/dfl-afu-dma-region.c | 9 +++++---- drivers/fpga/dfl-afu-region.c | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-)
drivers/fpga/dfl-afu-dma-region.c +5 -4
@@ -301,6 +301,7 @@ afu_dma_region_find_iova(struct dfl_feature_platform_data *pdata, u64 iova)int afu_dma_map_region (struct dfl_feature_platform_data *pdata,u64 user_addr,u64 length,u64 *iova) { +struct device *dev = &pdata->dev->dev;struct dfl_afu_dma_region *region;int ret;
@@ -325,13 +326,13 @@ int afu_dma_map_region(struct dfl_feature_platform_data *pdata,/* Pin the user memory region */ ret =afu_dma_pin_pages (pdata, region);if (ret) { -dev_err (&pdata->dev->dev,"failed to pin memory region\n" ); +dev_err (dev,"failed to pin memory region\n" ); goto free_region; }/* Only accept continuous pages, return error else */ if (!afu_dma_check_continuous_pages (region)) { -dev_err (&pdata->dev->dev,"pages are not continuous\n" ); +dev_err (dev,"pages are not continuous\n" ); ret = -EINVAL ; goto unpin_pages; }
@@ -342,7 +343,7 @@ int afu_dma_map_region(struct dfl_feature_platform_data *pdata, region->length, DMA_BIDIRECTIONAL);if (dma_mapping_error (dfl_fpga_pdata_to_parent (pdata), region->iova)) { -dev_err (&pdata->dev->dev,"failed to map for dma\n" ); +dev_err (dev,"failed to map for dma\n" ); ret = -EFAULT ; goto unpin_pages; }
@@ -353,7 +354,7 @@ int afu_dma_map_region(struct dfl_feature_platform_data *pdata, ret =afu_dma_region_add (pdata, region);mutex_unlock (&pdata->lock);if (ret) { -dev_err (&pdata->dev->dev,"failed to add dma region\n" ); +dev_err (dev,"failed to add dma region\n" ); goto unmap_dma; }
drivers/fpga/dfl-afu-region.c +3 -2
@@ -50,11 +50,12 @@ static struct dfl_afu_mmio_region *get_region_by_index(struct dfl_afu *afu,int afu_mmio_region_add (struct dfl_feature_platform_data *pdata,u32 region_index,u64 region_size,u64 phys,u32 flags) { +struct device *dev = &pdata->dev->dev;struct dfl_afu_mmio_region *region;struct dfl_afu *afu;int ret =0 ; - region =devm_kzalloc (&pdata->dev->dev,sizeof (*region),GFP_KERNEL ); + region =devm_kzalloc (dev,sizeof (*region),GFP_KERNEL );if (!region)return -ENOMEM ;
@@ -85,7 +86,7 @@ int afu_mmio_region_add(struct dfl_feature_platform_data *pdata,return 0 ; exit: -devm_kfree (&pdata->dev->dev, region); +devm_kfree (dev, region);return ret; }
Signature · 1 line
2.47.0
PATCH v4 5/19 fpga: dfl: pass feature platform data instead of device as argument
In reply to Peter ColbergFor functions which use the feature platform data, instead of invoking dev_get_platdata() on the device, directly pass the data as an argument.
This patch is part of a refactoring of the internal DFL APIs to move the feature device data into a new struct dfl_feature_dev_data which lifetime is independent of the corresponding platform device.
---
Changes since v3:
- Extend description to mention the reason for the refactoring.
Changes since v2:
- New patch extracted from monolithic v1 patch.
--- drivers/fpga/dfl-afu-error.c | 29 +++++++------- drivers/fpga/dfl-afu-main.c | 76 +++++++++++++++++++----------------- drivers/fpga/dfl-afu.h | 4 +- drivers/fpga/dfl-fme-br.c | 26 ++++++------ drivers/fpga/dfl-fme-error.c | 32 ++++++++------- drivers/fpga/dfl-fme-main.c | 18 ++++++--- drivers/fpga/dfl-fme-pr.c | 6 +-- drivers/fpga/dfl.c | 71 ++++++++++++++------------------- drivers/fpga/dfl.h | 35 +++++++++-------- 9 files changed, 150 insertions(+), 147 deletions(-)
drivers/fpga/dfl-afu-error.c +15 -14
@@ -28,11 +28,11 @@#define ERROR_MASK GENMASK_ULL(63, 0)/* mask or unmask port errors by the error mask register. */ -static void __afu_port_err_mask (struct device *dev,bool mask) +static void __afu_port_err_mask (struct dfl_feature_platform_data *pdata,bool mask) {void __iomem *base; - base =dfl_get_feature_ioaddr_by_id (dev,PORT_FEATURE_ID_ERROR ); + base =dfl_get_feature_ioaddr_by_id (pdata,PORT_FEATURE_ID_ERROR );writeq (mask ?ERROR_MASK :0 , base +PORT_ERROR_MASK ); }
@@ -42,7 +42,7 @@ static void afu_port_err_mask(struct device *dev, bool mask)struct dfl_feature_platform_data *pdata =dev_get_platdata (dev);mutex_lock (&pdata->lock); -__afu_port_err_mask (dev, mask); +__afu_port_err_mask (pdata, mask);mutex_unlock (&pdata->lock); }
@@ -50,13 +50,12 @@ static void afu_port_err_mask(struct device *dev, bool mask)static int afu_port_err_clear (struct device *dev,u64 err) {struct dfl_feature_platform_data *pdata =dev_get_platdata (dev); -struct platform_device *pdev =to_platform_device (dev);void __iomem *base_err, *base_hdr;int enable_ret =0 , ret = -EBUSY ;u64 v; - base_err =dfl_get_feature_ioaddr_by_id (dev,PORT_FEATURE_ID_ERROR ); - base_hdr =dfl_get_feature_ioaddr_by_id (dev,PORT_FEATURE_ID_HEADER ); + base_err =dfl_get_feature_ioaddr_by_id (pdata,PORT_FEATURE_ID_ERROR ); + base_hdr =dfl_get_feature_ioaddr_by_id (pdata,PORT_FEATURE_ID_HEADER );mutex_lock (&pdata->lock);
@@ -80,12 +79,12 @@ static int afu_port_err_clear(struct device *dev, u64 err) }/* Halt Port by keeping Port in reset */ - ret =__afu_port_disable (pdev); + ret =__afu_port_disable (pdata);if (ret) goto done;/* Mask all errors */ -__afu_port_err_mask (dev, true); +__afu_port_err_mask (pdata, true);/* Clear errors if err input matches with current port errors.*/ v =readq (base_err +PORT_ERROR );
@@ -102,10 +101,10 @@ static int afu_port_err_clear(struct device *dev, u64 err) }/* Clear mask */ -__afu_port_err_mask (dev, false); +__afu_port_err_mask (pdata, false);/* Enable the Port by clearing the reset */ - enable_ret =__afu_port_enable (pdev); + enable_ret =__afu_port_enable (pdata); done:mutex_unlock (&pdata->lock);
@@ -119,7 +118,7 @@ static ssize_t errors_show(struct device *dev, struct device_attribute *attr,void __iomem *base;u64 error; - base =dfl_get_feature_ioaddr_by_id (dev,PORT_FEATURE_ID_ERROR ); + base =dfl_get_feature_ioaddr_by_id (pdata,PORT_FEATURE_ID_ERROR );mutex_lock (&pdata->lock); error =readq (base +PORT_ERROR );
@@ -150,7 +149,7 @@ static ssize_t first_error_show(struct device *dev,void __iomem *base;u64 error; - base =dfl_get_feature_ioaddr_by_id (dev,PORT_FEATURE_ID_ERROR ); + base =dfl_get_feature_ioaddr_by_id (pdata,PORT_FEATURE_ID_ERROR );mutex_lock (&pdata->lock); error =readq (base +PORT_FIRST_ERROR );
@@ -168,7 +167,7 @@ static ssize_t first_malformed_req_show(struct device *dev,void __iomem *base;u64 req0, req1; - base =dfl_get_feature_ioaddr_by_id (dev,PORT_FEATURE_ID_ERROR ); + base =dfl_get_feature_ioaddr_by_id (pdata,PORT_FEATURE_ID_ERROR );mutex_lock (&pdata->lock); req0 =readq (base +PORT_MALFORMED_REQ0 );
@@ -190,13 +189,15 @@ static struct attribute *port_err_attrs[] = {static umode_t port_err_attrs_visible (struct kobject *kobj,struct attribute *attr,int n) { +struct dfl_feature_platform_data *pdata;struct device *dev =kobj_to_dev (kobj); + pdata =dev_get_platdata (dev);/* * sysfs entries are visible only if related private feature is * enumerated. */ -if (!dfl_get_feature_by_id (dev,PORT_FEATURE_ID_ERROR )) +if (!dfl_get_feature_by_id (pdata,PORT_FEATURE_ID_ERROR ))return 0 ;return attr->mode;
drivers/fpga/dfl-afu-main.c +40 -36
273 lines not on this page · raw message
drivers/fpga/dfl-afu.h +2 -2
@@ -77,8 +77,8 @@ struct dfl_afu { };/* hold pdata->lock when call __afu_port_enable/disable */ -int __afu_port_enable (struct platform_device *pdev); -int __afu_port_disable (struct platform_device *pdev); +int __afu_port_enable (struct dfl_feature_platform_data *pdata); +int __afu_port_disable (struct dfl_feature_platform_data *pdata);void afu_mmio_region_init (struct dfl_feature_platform_data *pdata); int afu_mmio_region_add(struct dfl_feature_platform_data *pdata,
drivers/fpga/dfl-fme-br.c +13 -13
@@ -22,34 +22,34 @@struct fme_br_priv {struct dfl_fme_br_pdata *pdata;struct dfl_fpga_port_ops *port_ops; -struct platform_device *port_pdev; +struct dfl_feature_platform_data *port_pdata; };static int fme_bridge_enable_set (struct fpga_bridge *bridge,bool enable) { +struct dfl_feature_platform_data *port_pdata;struct fme_br_priv *priv = bridge->priv; -struct platform_device *port_pdev;struct dfl_fpga_port_ops *ops; -if (!priv->port_pdev) { - port_pdev =dfl_fpga_cdev_find_port (priv->pdata->cdev, - &priv->pdata->port_id, - dfl_fpga_check_port_id); -if (!port_pdev) +if (!priv->port_pdata) { + port_pdata =dfl_fpga_cdev_find_port_data (priv->pdata->cdev, + &priv->pdata->port_id, + dfl_fpga_check_port_id); +if (!port_pdata)return -ENODEV ; - priv->port_pdev = port_pdev; + priv->port_pdata = port_pdata; } -if (priv->port_pdev && !priv->port_ops) { - ops =dfl_fpga_port_ops_get (priv->port_pdev); +if (priv->port_pdata && !priv->port_ops) { + ops =dfl_fpga_port_ops_get (priv->port_pdata);if (!ops || !ops->enable_set)return -ENOENT ; priv->port_ops = ops; } -return priv->port_ops->enable_set (priv->port_pdev, enable); +return priv->port_ops->enable_set (priv->port_pdata, enable); }static const struct fpga_bridge_ops fme_bridge_ops = {
@@ -85,8 +85,8 @@ static void fme_br_remove(struct platform_device *pdev)fpga_bridge_unregister (br); -if (priv->port_pdev) -put_device (&priv->port_pdev->dev); +if (priv->port_pdata) +put_device (&priv->port_pdata->dev->dev);if (priv->port_ops)dfl_fpga_port_ops_put (priv->port_ops); }
drivers/fpga/dfl-fme-error.c +18 -14
@@ -46,7 +46,7 @@ static ssize_t pcie0_errors_show(struct device *dev,void __iomem *base;u64 value; - base =dfl_get_feature_ioaddr_by_id (dev,FME_FEATURE_ID_GLOBAL_ERR ); + base =dfl_get_feature_ioaddr_by_id (pdata,FME_FEATURE_ID_GLOBAL_ERR );mutex_lock (&pdata->lock); value =readq (base +PCIE0_ERROR );
@@ -67,7 +67,7 @@ static ssize_t pcie0_errors_store(struct device *dev,if (kstrtou64 (buf,0 , &val))return -EINVAL ; - base =dfl_get_feature_ioaddr_by_id (dev,FME_FEATURE_ID_GLOBAL_ERR ); + base =dfl_get_feature_ioaddr_by_id (pdata,FME_FEATURE_ID_GLOBAL_ERR );mutex_lock (&pdata->lock);writeq (GENMASK_ULL (63 ,0 ), base +PCIE0_ERROR_MASK );
@@ -91,7 +91,7 @@ static ssize_t pcie1_errors_show(struct device *dev,void __iomem *base;u64 value; - base =dfl_get_feature_ioaddr_by_id (dev,FME_FEATURE_ID_GLOBAL_ERR ); + base =dfl_get_feature_ioaddr_by_id (pdata,FME_FEATURE_ID_GLOBAL_ERR );mutex_lock (&pdata->lock); value =readq (base +PCIE1_ERROR );
@@ -112,7 +112,7 @@ static ssize_t pcie1_errors_store(struct device *dev,if (kstrtou64 (buf,0 , &val))return -EINVAL ; - base =dfl_get_feature_ioaddr_by_id (dev,FME_FEATURE_ID_GLOBAL_ERR ); + base =dfl_get_feature_ioaddr_by_id (pdata,FME_FEATURE_ID_GLOBAL_ERR );mutex_lock (&pdata->lock);writeq (GENMASK_ULL (63 ,0 ), base +PCIE1_ERROR_MASK );
@@ -132,9 +132,10 @@ static DEVICE_ATTR_RW(pcie1_errors);static ssize_t nonfatal_errors_show (struct device *dev,struct device_attribute *attr,char *buf) { +struct dfl_feature_platform_data *pdata =dev_get_platdata (dev);void __iomem *base; - base =dfl_get_feature_ioaddr_by_id (dev,FME_FEATURE_ID_GLOBAL_ERR ); + base =dfl_get_feature_ioaddr_by_id (pdata,FME_FEATURE_ID_GLOBAL_ERR );return sprintf (buf,"0x%llx\n" , (unsigned long long )readq (base +RAS_NONFAT_ERROR ));
@@ -144,9 +145,10 @@ static DEVICE_ATTR_RO(nonfatal_errors);static ssize_t catfatal_errors_show (struct device *dev,struct device_attribute *attr,char *buf) { +struct dfl_feature_platform_data *pdata =dev_get_platdata (dev);void __iomem *base; - base =dfl_get_feature_ioaddr_by_id (dev,FME_FEATURE_ID_GLOBAL_ERR ); + base =dfl_get_feature_ioaddr_by_id (pdata,FME_FEATURE_ID_GLOBAL_ERR );return sprintf (buf,"0x%llx\n" , (unsigned long long )readq (base +RAS_CATFAT_ERROR ));
@@ -160,7 +162,7 @@ static ssize_t inject_errors_show(struct device *dev,void __iomem *base;u64 v; - base =dfl_get_feature_ioaddr_by_id (dev,FME_FEATURE_ID_GLOBAL_ERR ); + base =dfl_get_feature_ioaddr_by_id (pdata,FME_FEATURE_ID_GLOBAL_ERR );mutex_lock (&pdata->lock); v =readq (base +RAS_ERROR_INJECT );
@@ -185,7 +187,7 @@ static ssize_t inject_errors_store(struct device *dev,if (inject_error & ~INJECT_ERROR_MASK )return -EINVAL ; - base =dfl_get_feature_ioaddr_by_id (dev,FME_FEATURE_ID_GLOBAL_ERR ); + base =dfl_get_feature_ioaddr_by_id (pdata,FME_FEATURE_ID_GLOBAL_ERR );mutex_lock (&pdata->lock); v =readq (base +RAS_ERROR_INJECT );
@@ -205,7 +207,7 @@ static ssize_t fme_errors_show(struct device *dev,void __iomem *base;u64 value; - base =dfl_get_feature_ioaddr_by_id (dev,FME_FEATURE_ID_GLOBAL_ERR ); + base =dfl_get_feature_ioaddr_by_id (pdata,FME_FEATURE_ID_GLOBAL_ERR );mutex_lock (&pdata->lock); value =readq (base +FME_ERROR );
@@ -226,7 +228,7 @@ static ssize_t fme_errors_store(struct device *dev,if (kstrtou64 (buf,0 , &val))return -EINVAL ; - base =dfl_get_feature_ioaddr_by_id (dev,FME_FEATURE_ID_GLOBAL_ERR ); + base =dfl_get_feature_ioaddr_by_id (pdata,FME_FEATURE_ID_GLOBAL_ERR );mutex_lock (&pdata->lock);writeq (GENMASK_ULL (63 ,0 ), base +FME_ERROR_MASK );
@@ -252,7 +254,7 @@ static ssize_t first_error_show(struct device *dev,void __iomem *base;u64 value; - base =dfl_get_feature_ioaddr_by_id (dev,FME_FEATURE_ID_GLOBAL_ERR ); + base =dfl_get_feature_ioaddr_by_id (pdata,FME_FEATURE_ID_GLOBAL_ERR );mutex_lock (&pdata->lock); value =readq (base +FME_FIRST_ERROR );
@@ -269,7 +271,7 @@ static ssize_t next_error_show(struct device *dev,void __iomem *base;u64 value; - base =dfl_get_feature_ioaddr_by_id (dev,FME_FEATURE_ID_GLOBAL_ERR ); + base =dfl_get_feature_ioaddr_by_id (pdata,FME_FEATURE_ID_GLOBAL_ERR );mutex_lock (&pdata->lock); value =readq (base +FME_NEXT_ERROR );
@@ -294,13 +296,15 @@ static struct attribute *fme_global_err_attrs[] = {static umode_t fme_global_err_attrs_visible (struct kobject *kobj,struct attribute *attr,int n) { +struct dfl_feature_platform_data *pdata;struct device *dev =kobj_to_dev (kobj); + pdata =dev_get_platdata (dev);/* * sysfs entries are visible only if related private feature is * enumerated. */ -if (!dfl_get_feature_by_id (dev,FME_FEATURE_ID_GLOBAL_ERR )) +if (!dfl_get_feature_by_id (pdata,FME_FEATURE_ID_GLOBAL_ERR ))return 0 ;return attr->mode;
@@ -317,7 +321,7 @@ static void fme_err_mask(struct device *dev, bool mask)struct dfl_feature_platform_data *pdata =dev_get_platdata (dev);void __iomem *base; - base =dfl_get_feature_ioaddr_by_id (dev,FME_FEATURE_ID_GLOBAL_ERR ); + base =dfl_get_feature_ioaddr_by_id (pdata,FME_FEATURE_ID_GLOBAL_ERR );mutex_lock (&pdata->lock);
drivers/fpga/dfl-fme-main.c +12 -6
@@ -28,10 +28,11 @@static ssize_t ports_num_show (struct device *dev,struct device_attribute *attr,char *buf) { +struct dfl_feature_platform_data *pdata =dev_get_platdata (dev);void __iomem *base;u64 v; - base =dfl_get_feature_ioaddr_by_id (dev,FME_FEATURE_ID_HEADER ); + base =dfl_get_feature_ioaddr_by_id (pdata,FME_FEATURE_ID_HEADER ); v =readq (base +FME_HDR_CAP );
@@ -47,10 +48,11 @@ static DEVICE_ATTR_RO(ports_num);static ssize_t bitstream_id_show (struct device *dev,struct device_attribute *attr,char *buf) { +struct dfl_feature_platform_data *pdata =dev_get_platdata (dev);void __iomem *base;u64 v; - base =dfl_get_feature_ioaddr_by_id (dev,FME_FEATURE_ID_HEADER ); + base =dfl_get_feature_ioaddr_by_id (pdata,FME_FEATURE_ID_HEADER ); v =readq (base +FME_HDR_BITSTREAM_ID );
@@ -65,10 +67,11 @@ static DEVICE_ATTR_RO(bitstream_id);static ssize_t bitstream_metadata_show (struct device *dev,struct device_attribute *attr,char *buf) { +struct dfl_feature_platform_data *pdata =dev_get_platdata (dev);void __iomem *base;u64 v; - base =dfl_get_feature_ioaddr_by_id (dev,FME_FEATURE_ID_HEADER ); + base =dfl_get_feature_ioaddr_by_id (pdata,FME_FEATURE_ID_HEADER ); v =readq (base +FME_HDR_BITSTREAM_MD );
@@ -79,10 +82,11 @@ static DEVICE_ATTR_RO(bitstream_metadata);static ssize_t cache_size_show (struct device *dev,struct device_attribute *attr,char *buf) { +struct dfl_feature_platform_data *pdata =dev_get_platdata (dev);void __iomem *base;u64 v; - base =dfl_get_feature_ioaddr_by_id (dev,FME_FEATURE_ID_HEADER ); + base =dfl_get_feature_ioaddr_by_id (pdata,FME_FEATURE_ID_HEADER ); v =readq (base +FME_HDR_CAP );
@@ -94,10 +98,11 @@ static DEVICE_ATTR_RO(cache_size);static ssize_t fabric_version_show (struct device *dev,struct device_attribute *attr,char *buf) { +struct dfl_feature_platform_data *pdata =dev_get_platdata (dev);void __iomem *base;u64 v; - base =dfl_get_feature_ioaddr_by_id (dev,FME_FEATURE_ID_HEADER ); + base =dfl_get_feature_ioaddr_by_id (pdata,FME_FEATURE_ID_HEADER ); v =readq (base +FME_HDR_CAP );
@@ -109,10 +114,11 @@ static DEVICE_ATTR_RO(fabric_version);static ssize_t socket_id_show (struct device *dev,struct device_attribute *attr,char *buf) { +struct dfl_feature_platform_data *pdata =dev_get_platdata (dev);void __iomem *base;u64 v; - base =dfl_get_feature_ioaddr_by_id (dev,FME_FEATURE_ID_HEADER ); + base =dfl_get_feature_ioaddr_by_id (pdata,FME_FEATURE_ID_HEADER ); v =readq (base +FME_HDR_CAP );
drivers/fpga/dfl-fme-pr.c +2 -4
@@ -87,8 +87,7 @@ static int fme_pr(struct platform_device *pdev, unsigned long arg)return -EINVAL ;/* get fme header region */ - fme_hdr =dfl_get_feature_ioaddr_by_id (&pdev->dev, -FME_FEATURE_ID_HEADER ); + fme_hdr =dfl_get_feature_ioaddr_by_id (pdata,FME_FEATURE_ID_HEADER );/* check port id */ v =readq (fme_hdr +FME_HDR_CAP );
@@ -378,8 +377,7 @@ static int pr_mgmt_init(struct platform_device *pdev,int ret = -ENODEV , i =0 ;u64 fme_cap, port_offset; - fme_hdr =dfl_get_feature_ioaddr_by_id (&pdev->dev, -FME_FEATURE_ID_HEADER ); + fme_hdr =dfl_get_feature_ioaddr_by_id (pdata,FME_FEATURE_ID_HEADER );mutex_lock (&pdata->lock); priv =dfl_fpga_pdata_get_private (pdata);
drivers/fpga/dfl.c +30 -41
187 lines not on this page · raw message
drivers/fpga/dfl.h +18 -17
@@ -206,6 +206,8 @@#define PORT_UINT_CAP_INT_NUM GENMASK_ULL(11, 0)/* Interrupts num */ #define PORT_UINT_CAP_FST_VECT GENMASK_ULL(23, 12)/* First Vector */ +struct dfl_feature_platform_data ; +/** * struct dfl_fpga_port_ops - port ops *
@@ -219,15 +221,15 @@ struct dfl_fpga_port_ops {const char *name;struct module *owner;struct list_head node; -int (*get_id)(struct platform_device *pdev); -int (*enable_set)(struct platform_device *pdev,bool enable); +int (*get_id)(struct dfl_feature_platform_data *pdata); +int (*enable_set)(struct dfl_feature_platform_data *pdata,bool enable); };void dfl_fpga_port_ops_add (struct dfl_fpga_port_ops *ops);void dfl_fpga_port_ops_del (struct dfl_fpga_port_ops *ops); -struct dfl_fpga_port_ops *dfl_fpga_port_ops_get (struct platform_device *pdev); +struct dfl_fpga_port_ops *dfl_fpga_port_ops_get (struct dfl_feature_platform_data *pdata);void dfl_fpga_port_ops_put (struct dfl_fpga_port_ops *ops); -int dfl_fpga_check_port_id (struct platform_device *pdev,void *pport_id); +int dfl_fpga_check_port_id (struct dfl_feature_platform_data *pdata,void *pport_id);/** * struct dfl_feature_id - dfl private feature id
@@ -413,9 +415,8 @@ dfl_fpga_inode_to_feature_dev_data(struct inode *inode) (feature) < (pdata)->features + (pdata)->num; (feature)++)static inline -struct dfl_feature *dfl_get_feature_by_id (struct device *dev,u16 id) +struct dfl_feature *dfl_get_feature_by_id (struct dfl_feature_platform_data *pdata,u16 id) { -struct dfl_feature_platform_data *pdata =dev_get_platdata (dev);struct dfl_feature *feature;dfl_fpga_dev_for_each_feature (pdata, feature)
@@ -426,9 +427,9 @@ struct dfl_feature *dfl_get_feature_by_id(struct device *dev, u16 id) }static inline -void __iomem *dfl_get_feature_ioaddr_by_id (struct device *dev,u16 id) +void __iomem *dfl_get_feature_ioaddr_by_id (struct dfl_feature_platform_data *pdata,u16 id) { -struct dfl_feature *feature =dfl_get_feature_by_id (dev, id); +struct dfl_feature *feature =dfl_get_feature_by_id (pdata, id);if (feature && feature->ioaddr)return feature->ioaddr;
@@ -527,21 +528,21 @@ void dfl_fpga_feature_devs_remove(struct dfl_fpga_cdev *cdev);* device returned by __dfl_fpga_cdev_find_port and dfl_fpga_cdev_find_port * functions. */ -struct platform_device * -__dfl_fpga_cdev_find_port (struct dfl_fpga_cdev *cdev,void *data, -int (*match)(struct platform_device *,void *)); +struct dfl_feature_platform_data * +__dfl_fpga_cdev_find_port_data (struct dfl_fpga_cdev *cdev,void *data, +int (*match)(struct dfl_feature_platform_data *,void *)); -static inline struct platform_device * -dfl_fpga_cdev_find_port (struct dfl_fpga_cdev *cdev,void *data, -int (*match)(struct platform_device *,void *)) +static inline struct dfl_feature_platform_data * +dfl_fpga_cdev_find_port_data (struct dfl_fpga_cdev *cdev,void *data, +int (*match)(struct dfl_feature_platform_data *,void *)) { -struct platform_device *pdev; +struct dfl_feature_platform_data *pdata;mutex_lock (&cdev->lock); - pdev =__dfl_fpga_cdev_find_port (cdev, data, match); + pdata =__dfl_fpga_cdev_find_port_data (cdev, data, match);mutex_unlock (&cdev->lock); -return pdev; +return pdata; }int dfl_fpga_cdev_release_port (struct dfl_fpga_cdev *cdev,int port_id);
Signature · 1 line
2.47.0
PATCH v4 6/19 fpga: dfl: factor out feature data creation from build_info_commit_dev()
In reply to Peter ColbergAdd a separate function, binfo_create_feature_dev_data(), which allocates and populates the feature platform data, and call the function from build_info_commit_dev(), which registers the feature platform device.
---
Changes since v3:
- Replace ERR_PTR(PTR_ERR(feature->ioaddr) with feature->ioaddr and remove unneeded local variable ret.
- Add missing commas in description.
Changes since v2:
- New patch extracted from monolithic v1 patch.
--- drivers/fpga/dfl.c | 72 +++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 32 deletions(-)
drivers/fpga/dfl.c +40 -32
@@ -749,22 +749,18 @@ static void dfl_fpga_cdev_add_port_data(struct dfl_fpga_cdev *cdev,mutex_unlock (&cdev->lock); } -/* -* register current feature device, it is called when we need to switch to -* another feature parsing or we have parsed all features on given device -* feature list. -*/ -static int build_info_commit_dev (struct build_feature_devs_info *binfo) +static struct dfl_feature_platform_data * +binfo_create_feature_dev_data (struct build_feature_devs_info *binfo) {struct platform_device *fdev = binfo->feature_dev;struct dfl_feature_platform_data *pdata;struct dfl_feature_info *finfo, *p;enum dfl_id_type type; -int ret, index =0 , res_idx =0 ; +int index =0 , res_idx =0 ; type =feature_dev_id_type (fdev);if (WARN_ON_ONCE (type >=DFL_ID_MAX )) -return -EINVAL ; +return ERR_PTR (-EINVAL );/* * we do not need to care for the memory which is associated with
@@ -774,7 +770,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)*/ pdata =kzalloc (struct_size (pdata, features, binfo->feature_num),GFP_KERNEL );if (!pdata) -return -ENOMEM ; +return ERR_PTR (-ENOMEM ); pdata->dev = fdev; pdata->num = binfo->feature_num;
@@ -799,7 +795,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo) fdev->resource =kcalloc (binfo->feature_num,sizeof (*fdev->resource),GFP_KERNEL );if (!fdev->resource) -return -ENOMEM ; +return ERR_PTR (-ENOMEM );/* fill features and resource information for feature dev */ list_for_each_entry_safe (finfo, p, &binfo->sub_features, node) {
@@ -818,7 +814,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo) finfo->params, finfo->param_size, GFP_KERNEL);if (!feature->params) -return -ENOMEM ; +return ERR_PTR (-ENOMEM ); feature->param_size = finfo->param_size; }
@@ -835,7 +831,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)devm_ioremap_resource (binfo->dev, &finfo->mmio_res);if (IS_ERR (feature->ioaddr)) -return PTR_ERR (feature->ioaddr); +return feature->ioaddr; }else { feature->resource_index = res_idx; fdev->resource[res_idx++] = finfo->mmio_res;
@@ -845,7 +841,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo) ctx =devm_kcalloc (binfo->dev, finfo->nr_irqs,sizeof (*ctx),GFP_KERNEL );if (!ctx) -return -ENOMEM ; +return ERR_PTR (-ENOMEM );for (i =0 ; i < finfo->nr_irqs; i++) ctx[i].irq =
@@ -859,25 +855,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)kfree (finfo); } - ret =platform_device_add (binfo->feature_dev); -if (!ret) { -if (type ==PORT_ID ) -dfl_fpga_cdev_add_port_data (binfo->cdev, - pdata); -else - binfo->cdev->fme_dev = -get_device (&binfo->feature_dev->dev); -/* -* reset it to avoid build_info_free() freeing their resource. -* -* The resource of successfully registered feature devices -* will be freed by platform_device_unregister(). See the -* comments in build_info_create_dev(). -*/ - binfo->feature_dev =NULL ; - } - -return ret; +return pdata; } static int
@@ -912,6 +890,36 @@ build_info_create_dev(struct build_feature_devs_info *binfo,return 0 ; } +static int build_info_commit_dev (struct build_feature_devs_info *binfo) +{ +struct dfl_feature_platform_data *pdata; +int ret; + + pdata =binfo_create_feature_dev_data (binfo); +if (IS_ERR (pdata)) +return PTR_ERR (pdata); + + ret =platform_device_add (binfo->feature_dev); +if (ret) +return ret; + +if (feature_dev_id_type (binfo->feature_dev) ==PORT_ID ) +dfl_fpga_cdev_add_port_data (binfo->cdev, pdata); +else + binfo->cdev->fme_dev =get_device (&binfo->feature_dev->dev); + +/* +* reset it to avoid build_info_free() freeing their resource. +* +* The resource of successfully registered feature devices +* will be freed by platform_device_unregister(). See the +* comments in build_info_create_dev(). +*/ + binfo->feature_dev =NULL ; + +return 0 ; +} +static void build_info_free (struct build_feature_devs_info *binfo) {struct dfl_feature_info *finfo, *p;
Signature · 1 line
2.47.0
PATCH v4 7/19 fpga: dfl: store FIU type in feature platform data
In reply to Peter ColbergRemove the local function feature_dev_id_type() in favor of persisting the FIU type in struct dfl_feature_platform_data. Add type to struct build_feature_devs_info and drop argument to build_info_create_dev().
---
Changes since v3:
- Revert change that converts is_feature_dev_detected() to use FIU type, which has been factored out into a separate, second to last patch.
- Restore Christmas tree order of local variable declarations in binfo_create_feature_dev_data().
- Replace "favour" with "favor" in description.
Changes since v2:
- New patch extracted from monolithic v1 patch.
--- drivers/fpga/dfl.c | 55 ++++++++++++++++++++++------------------------ drivers/fpga/dfl.h | 3 +++ 2 files changed, 29 insertions(+), 29 deletions(-)
drivers/fpga/dfl.c +26 -29
@@ -119,17 +119,6 @@ static void dfl_id_free(enum dfl_id_type type, int id)mutex_unlock (&dfl_id_mutex); } -static enum dfl_id_type feature_dev_id_type (struct platform_device *pdev) -{ -int i; - -for (i =0 ; i <ARRAY_SIZE (dfl_devs); i++) -if (!strcmp (dfl_devs[i].name, pdev->name)) -return i; - -return DFL_ID_MAX ; -} -static enum dfl_id_type dfh_id_to_type (u16 id) {int i;
@@ -379,7 +368,7 @@ dfl_dev_add(struct dfl_feature_platform_data *pdata,if (ret) goto put_dev; - ddev->type =feature_dev_id_type (pdev); + ddev->type = pdata->type; ddev->feature_id = feature->id; ddev->revision = feature->revision; ddev->dfh_version = feature->dfh_version;
@@ -693,6 +682,7 @@ EXPORT_SYMBOL_GPL(dfl_fpga_dev_ops_unregister);* @irq_table: Linux IRQ numbers for all irqs, indexed by local irq index of * this device. * @feature_dev: current feature device. +* @type: the current FIU type. * @ioaddr: header register region address of current FIU in enumeration. * @start: register resource start of current FIU. * @len: max register resource length of current FIU.
@@ -706,6 +696,7 @@ struct build_feature_devs_info {int *irq_table;struct platform_device *feature_dev; +enum dfl_id_type type;void __iomem *ioaddr;resource_size_t start;resource_size_t len;
@@ -754,11 +745,10 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo) {struct platform_device *fdev = binfo->feature_dev;struct dfl_feature_platform_data *pdata; +enum dfl_id_type type = binfo->type;struct dfl_feature_info *finfo, *p; -enum dfl_id_type type;int index =0 , res_idx =0 ; - type =feature_dev_id_type (fdev);if (WARN_ON_ONCE (type >=DFL_ID_MAX ))return ERR_PTR (-EINVAL );
@@ -773,6 +763,7 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)return ERR_PTR (-ENOMEM ); pdata->dev = fdev; + pdata->type = type; pdata->num = binfo->feature_num; pdata->dfl_cdev = binfo->cdev; pdata->id =FEATURE_DEV_ID_UNUSED ;
@@ -859,14 +850,11 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo) }static int -build_info_create_dev (struct build_feature_devs_info *binfo, -enum dfl_id_type type) +build_info_create_dev (struct build_feature_devs_info *binfo) { +enum dfl_id_type type = binfo->type;struct platform_device *fdev; -if (type >=DFL_ID_MAX ) -return -EINVAL ; -/* * we use -ENODEV as the initialization indicator which indicates * whether the id need to be reclaimed
@@ -903,7 +891,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)if (ret)return ret; -if (feature_dev_id_type (binfo->feature_dev) ==PORT_ID ) +if (binfo->type ==PORT_ID )dfl_fpga_cdev_add_port_data (binfo->cdev, pdata);else binfo->cdev->fme_dev =get_device (&binfo->feature_dev->dev);
@@ -917,6 +905,9 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)*/ binfo->feature_dev =NULL ; +/* reset the binfo for next FIU */ + binfo->type =DFL_ID_MAX ; +return 0 ; }
@@ -929,8 +920,7 @@ static void build_info_free(struct build_feature_devs_info *binfo)* build_info_create_dev() */ if (binfo->feature_dev && binfo->feature_dev->id >=0 ) { -dfl_id_free (feature_dev_id_type (binfo->feature_dev), - binfo->feature_dev->id); +dfl_id_free (binfo->type, binfo->feature_dev->id);list_for_each_entry_safe (finfo, p, &binfo->sub_features, node) {list_del (&finfo->node);
@@ -1028,7 +1018,7 @@ static int parse_feature_irqs(struct build_feature_devs_info *binfo,* Instead, features with interrupt functionality provide * the information in feature specific registers. */ - type =feature_dev_id_type (binfo->feature_dev); + type = binfo->type;if (type ==PORT_ID ) {switch (fid) {case PORT_FEATURE_ID_UINT :
@@ -1230,7 +1220,7 @@ static int parse_feature_afu(struct build_feature_devs_info *binfo,return -EINVAL ; } -switch (feature_dev_id_type (binfo->feature_dev)) { +switch (binfo->type) {case PORT_ID :return parse_feature_port_afu (binfo, ofst);default :
@@ -1276,6 +1266,7 @@ static void build_info_complete(struct build_feature_devs_info *binfo)static int parse_feature_fiu (struct build_feature_devs_info *binfo,resource_size_t ofst) { +enum dfl_id_type type;int ret =0 ;u32 offset;u16 id;
@@ -1297,8 +1288,14 @@ static int parse_feature_fiu(struct build_feature_devs_info *binfo, v =readq (binfo->ioaddr +DFH ); id =FIELD_GET (DFH_ID , v); + type =dfh_id_to_type (id); +if (type >=DFL_ID_MAX ) +return -EINVAL ; + + binfo->type = type; +/* create platform device for dfl feature dev */ - ret =build_info_create_dev (binfo,dfh_id_to_type (id)); + ret =build_info_create_dev (binfo);if (ret)return ret;
@@ -1518,13 +1515,13 @@ EXPORT_SYMBOL_GPL(dfl_fpga_enum_info_add_irq);static int remove_feature_dev (struct device *dev,void *data) { +struct dfl_feature_platform_data *pdata =dev_get_platdata (dev);struct platform_device *pdev =to_platform_device (dev); -enum dfl_id_type type =feature_dev_id_type (pdev);int id = pdev->id;platform_device_unregister (pdev); -dfl_id_free (type, id); +dfl_id_free (pdata->type, id);return 0 ; }
@@ -1576,6 +1573,7 @@ dfl_fpga_feature_devs_enumerate(struct dfl_fpga_enum_info *info) goto unregister_region_exit; } + binfo->type =DFL_ID_MAX ; binfo->dev = info->dev; binfo->cdev = cdev;
@@ -1628,8 +1626,7 @@ void dfl_fpga_feature_devs_remove(struct dfl_fpga_cdev *cdev)/* remove released ports */ if (!device_is_registered (&port_dev->dev)) { -dfl_id_free (feature_dev_id_type (port_dev), - port_dev->id); +dfl_id_free (pdata->type, port_dev->id);platform_device_put (port_dev); }
drivers/fpga/dfl.h +3 -0
@@ -17,6 +17,7 @@#include <linux/bitfield.h> #include <linux/cdev.h> #include <linux/delay.h> +#include <linux/dfl.h> #include <linux/eventfd.h> #include <linux/fs.h> #include <linux/interrupt.h>
@@ -308,6 +309,7 @@ struct dfl_feature {* @lock: mutex to protect platform data. * @cdev: cdev of feature dev. * @dev: ptr to platform device linked with this platform data. +* @type: type of DFL FIU for the feature dev. See enum dfl_id_type. * @dfl_cdev: ptr to container device. * @id: id used for this feature device. * @disable_count: count for port disable.
@@ -322,6 +324,7 @@ struct dfl_feature_platform_data {struct mutex lock;struct cdev cdev;struct platform_device *dev; +enum dfl_id_type type;struct dfl_fpga_cdev *dfl_cdev;int id;unsigned int disable_count;
Signature · 1 line
2.47.0
PATCH v4 8/19 fpga: dfl: refactor internal DFL APIs to take/return feature device data
In reply to Peter ColbergThis change prepares a subsequent commit which factors out the DFL enumeration info from the structure dfl_feature_platform_data into a new structure dfl_feature_dev_data, whose lifetime is independent of the feature device which will be destroyed during port release.
Add an alias dfl_feature_dev_data for dfl_feature_platform_data, and an alias to_dfl_feature_dev_data() for dev_get_platdata(), and refactor internal DFL APIs to take/return dfl_feature_dev_data instead. The aliases will be replaced with implementations in a subsequent commit.
This change does not introduce any functional changes.
---
Changes since v3:
- Add "pdata" -> "fdata" substitution when looping over ports in dfl_fpga_feature_devs_remove(). This is now needed since the last patch of the v2 series has been broken up into many smaller patches, which retain and successively modify the loop until its final removal in the new, significantly smaller last patch.
- Replace "infos" with "info" in description.
- Replace "may be destroyed" with "will be destroyed" (during port release) in description.
- Replace generic "functions" with "internal DFL APIs" in description.
Changes since v2:
- New patch extracted from monolithic v1 patch.
--- drivers/fpga/dfl-afu-dma-region.c | 110 ++++++------ drivers/fpga/dfl-afu-error.c | 60 +++---- drivers/fpga/dfl-afu-main.c | 276 +++++++++++++++--------------- drivers/fpga/dfl-afu-region.c | 48 +++--- drivers/fpga/dfl-afu.h | 26 +-- drivers/fpga/dfl-fme-br.c | 22 +-- drivers/fpga/dfl-fme-error.c | 102 +++++------ drivers/fpga/dfl-fme-main.c | 98 +++++------ drivers/fpga/dfl-fme-pr.c | 84 ++++----- drivers/fpga/dfl.c | 182 ++++++++++---------- drivers/fpga/dfl.h | 77 +++++---- 11 files changed, 544 insertions(+), 541 deletions(-)
drivers/fpga/dfl-afu-dma-region.c +55 -55
@@ -16,26 +16,26 @@#include "dfl-afu.h" -void afu_dma_region_init (struct dfl_feature_platform_data *pdata) +void afu_dma_region_init (struct dfl_feature_dev_data *fdata) { -struct dfl_afu *afu =dfl_fpga_pdata_get_private (pdata); +struct dfl_afu *afu =dfl_fpga_fdata_get_private (fdata); afu->dma_regions =RB_ROOT ; }/** * afu_dma_pin_pages - pin pages of given dma memory region -* @pdata: feature device platform data +* @fdata: feature dev data * @region: dma memory region to be pinned * * Pin all the pages of given dfl_afu_dma_region. * Return 0 for success or negative error code. */ -static int afu_dma_pin_pages (struct dfl_feature_platform_data *pdata, +static int afu_dma_pin_pages (struct dfl_feature_dev_data *fdata,struct dfl_afu_dma_region *region) {int npages = region->length >>PAGE_SHIFT ; -struct device *dev = &pdata->dev->dev; +struct device *dev = &fdata->dev->dev;int ret, pinned; ret =account_locked_vm (current->mm, npages, true);
@@ -73,17 +73,17 @@ static int afu_dma_pin_pages(struct dfl_feature_platform_data *pdata,/** * afu_dma_unpin_pages - unpin pages of given dma memory region -* @pdata: feature device platform data +* @fdata: feature dev data * @region: dma memory region to be unpinned * * Unpin all the pages of given dfl_afu_dma_region. * Return 0 for success or negative error code. */ -static void afu_dma_unpin_pages (struct dfl_feature_platform_data *pdata, +static void afu_dma_unpin_pages (struct dfl_feature_dev_data *fdata,struct dfl_afu_dma_region *region) {long npages = region->length >>PAGE_SHIFT ; -struct device *dev = &pdata->dev->dev; +struct device *dev = &fdata->dev->dev;unpin_user_pages (region->pages, npages);kfree (region->pages);
@@ -133,20 +133,20 @@ static bool dma_region_check_iova(struct dfl_afu_dma_region *region,/** * afu_dma_region_add - add given dma region to rbtree -* @pdata: feature device platform data +* @fdata: feature dev data * @region: dma region to be added * * Return 0 for success, -EEXIST if dma region has already been added. * -* Needs to be called with pdata->lock heold. +* Needs to be called with fdata->lock held. */ -static int afu_dma_region_add (struct dfl_feature_platform_data *pdata, +static int afu_dma_region_add (struct dfl_feature_dev_data *fdata,struct dfl_afu_dma_region *region) { -struct dfl_afu *afu =dfl_fpga_pdata_get_private (pdata); +struct dfl_afu *afu =dfl_fpga_fdata_get_private (fdata);struct rb_node **new, *parent =NULL ; -dev_dbg (&pdata->dev->dev,"add region (iova = %llx)\n" , +dev_dbg (&fdata->dev->dev,"add region (iova = %llx)\n" , (unsigned long long )region->iova); new = &afu->dma_regions.rb_node;
@@ -177,50 +177,50 @@ static int afu_dma_region_add(struct dfl_feature_platform_data *pdata,/** * afu_dma_region_remove - remove given dma region from rbtree -* @pdata: feature device platform data +* @fdata: feature dev data * @region: dma region to be removed * -* Needs to be called with pdata->lock heold. +* Needs to be called with fdata->lock held. */ -static void afu_dma_region_remove (struct dfl_feature_platform_data *pdata, +static void afu_dma_region_remove (struct dfl_feature_dev_data *fdata,struct dfl_afu_dma_region *region) {struct dfl_afu *afu; -dev_dbg (&pdata->dev->dev,"del region (iova = %llx)\n" , +dev_dbg (&fdata->dev->dev,"del region (iova = %llx)\n" , (unsigned long long )region->iova); - afu =dfl_fpga_pdata_get_private (pdata); + afu =dfl_fpga_fdata_get_private (fdata);rb_erase (®ion->node, &afu->dma_regions); }/** * afu_dma_region_destroy - destroy all regions in rbtree -* @pdata: feature device platform data +* @fdata: feature dev data * -* Needs to be called with pdata->lock heold. +* Needs to be called with fdata->lock held. */ -void afu_dma_region_destroy (struct dfl_feature_platform_data *pdata) +void afu_dma_region_destroy (struct dfl_feature_dev_data *fdata) { -struct dfl_afu *afu =dfl_fpga_pdata_get_private (pdata); +struct dfl_afu *afu =dfl_fpga_fdata_get_private (fdata);struct rb_node *node =rb_first (&afu->dma_regions);struct dfl_afu_dma_region *region;while (node) { region = container_of(node, struct dfl_afu_dma_region, node); -dev_dbg (&pdata->dev->dev,"del region (iova = %llx)\n" , +dev_dbg (&fdata->dev->dev,"del region (iova = %llx)\n" , (unsigned long long )region->iova);rb_erase (node, &afu->dma_regions);if (region->iova) -dma_unmap_page (dfl_fpga_pdata_to_parent (pdata), +dma_unmap_page (dfl_fpga_fdata_to_parent (fdata), region->iova, region->length,DMA_BIDIRECTIONAL );if (region->pages) -afu_dma_unpin_pages (pdata, region); +afu_dma_unpin_pages (fdata, region); node =rb_next (node);kfree (region);
@@ -229,7 +229,7 @@ void afu_dma_region_destroy(struct dfl_feature_platform_data *pdata)/** * afu_dma_region_find - find the dma region from rbtree based on iova and size -* @pdata: feature device platform data +* @fdata: feature dev data * @iova: address of the dma memory area * @size: size of the dma memory area *
@@ -239,14 +239,14 @@ void afu_dma_region_destroy(struct dfl_feature_platform_data *pdata)* [@iova, @iova+size) * If nothing is matched returns NULL. * -* Needs to be called with pdata->lock held. +* Needs to be called with fdata->lock held. */ struct dfl_afu_dma_region * -afu_dma_region_find (struct dfl_feature_platform_data *pdata,u64 iova,u64 size) +afu_dma_region_find (struct dfl_feature_dev_data *fdata,u64 iova,u64 size) { -struct dfl_afu *afu =dfl_fpga_pdata_get_private (pdata); +struct dfl_afu *afu =dfl_fpga_fdata_get_private (fdata);struct rb_node *node = afu->dma_regions.rb_node; -struct device *dev = &pdata->dev->dev; +struct device *dev = &fdata->dev->dev;while (node) {struct dfl_afu_dma_region *region;
@@ -276,20 +276,20 @@ afu_dma_region_find(struct dfl_feature_platform_data *pdata, u64 iova, u64 size)/** * afu_dma_region_find_iova - find the dma region from rbtree by iova -* @pdata: feature device platform data +* @fdata: feature dev data * @iova: address of the dma region * -* Needs to be called with pdata->lock held. +* Needs to be called with fdata->lock held. */ static struct dfl_afu_dma_region * -afu_dma_region_find_iova (struct dfl_feature_platform_data *pdata,u64 iova) +afu_dma_region_find_iova (struct dfl_feature_dev_data *fdata,u64 iova) { -return afu_dma_region_find (pdata, iova,0 ); +return afu_dma_region_find (fdata, iova,0 ); }/** * afu_dma_map_region - map memory region for dma -* @pdata: feature device platform data +* @fdata: feature dev data * @user_addr: address of the memory region * @length: size of the memory region * @iova: pointer of iova address
@@ -298,10 +298,10 @@ afu_dma_region_find_iova(struct dfl_feature_platform_data *pdata, u64 iova)* of the memory region via @iova. * Return 0 for success, otherwise error code. */ -int afu_dma_map_region (struct dfl_feature_platform_data *pdata, +int afu_dma_map_region (struct dfl_feature_dev_data *fdata,u64 user_addr,u64 length,u64 *iova) { -struct device *dev = &pdata->dev->dev; +struct device *dev = &fdata->dev->dev;struct dfl_afu_dma_region *region;int ret;
@@ -324,7 +324,7 @@ int afu_dma_map_region(struct dfl_feature_platform_data *pdata, region->length = length;/* Pin the user memory region */ - ret =afu_dma_pin_pages (pdata, region); + ret =afu_dma_pin_pages (fdata, region);if (ret) {dev_err (dev,"failed to pin memory region\n" ); goto free_region;
@@ -338,11 +338,11 @@ int afu_dma_map_region(struct dfl_feature_platform_data *pdata, }/* As pages are continuous then start to do DMA mapping */ - region->iova =dma_map_page (dfl_fpga_pdata_to_parent (pdata), + region->iova =dma_map_page (dfl_fpga_fdata_to_parent (fdata), region->pages[0 ],0 , region->length,DMA_BIDIRECTIONAL ); -if (dma_mapping_error (dfl_fpga_pdata_to_parent (pdata), region->iova)) { +if (dma_mapping_error (dfl_fpga_fdata_to_parent (fdata), region->iova)) {dev_err (dev,"failed to map for dma\n" ); ret = -EFAULT ; goto unpin_pages;
@@ -350,9 +350,9 @@ int afu_dma_map_region(struct dfl_feature_platform_data *pdata, *iova = region->iova; -mutex_lock (&pdata->lock); - ret =afu_dma_region_add (pdata, region); -mutex_unlock (&pdata->lock); +mutex_lock (&fdata->lock); + ret =afu_dma_region_add (fdata, region); +mutex_unlock (&fdata->lock);if (ret) {dev_err (dev,"failed to add dma region\n" ); goto unmap_dma;
@@ -361,10 +361,10 @@ int afu_dma_map_region(struct dfl_feature_platform_data *pdata,return 0 ; unmap_dma: -dma_unmap_page (dfl_fpga_pdata_to_parent (pdata), +dma_unmap_page (dfl_fpga_fdata_to_parent (fdata), region->iova, region->length,DMA_BIDIRECTIONAL ); unpin_pages: -afu_dma_unpin_pages (pdata, region); +afu_dma_unpin_pages (fdata, region); free_region:kfree (region);return ret;
@@ -372,34 +372,34 @@ int afu_dma_map_region(struct dfl_feature_platform_data *pdata,/** * afu_dma_unmap_region - unmap dma memory region -* @pdata: feature device platform data +* @fdata: feature dev data * @iova: dma address of the region * * Unmap dma memory region based on @iova. * Return 0 for success, otherwise error code. */ -int afu_dma_unmap_region (struct dfl_feature_platform_data *pdata,u64 iova) +int afu_dma_unmap_region (struct dfl_feature_dev_data *fdata,u64 iova) {struct dfl_afu_dma_region *region; -mutex_lock (&pdata->lock); - region =afu_dma_region_find_iova (pdata, iova); +mutex_lock (&fdata->lock); + region =afu_dma_region_find_iova (fdata, iova);if (!region) { -mutex_unlock (&pdata->lock); +mutex_unlock (&fdata->lock);return -EINVAL ; }if (region->in_use) { -mutex_unlock (&pdata->lock); +mutex_unlock (&fdata->lock);return -EBUSY ; } -afu_dma_region_remove (pdata, region); -mutex_unlock (&pdata->lock); +afu_dma_region_remove (fdata, region); +mutex_unlock (&fdata->lock); -dma_unmap_page (dfl_fpga_pdata_to_parent (pdata), +dma_unmap_page (dfl_fpga_fdata_to_parent (fdata), region->iova, region->length,DMA_BIDIRECTIONAL ); -afu_dma_unpin_pages (pdata, region); +afu_dma_unpin_pages (fdata, region);kfree (region);return 0 ;
drivers/fpga/dfl-afu-error.c +30 -30
152 lines not on this page · raw message
drivers/fpga/dfl-afu-main.c +138 -138
704 lines not on this page · raw message
drivers/fpga/dfl-afu-region.c +24 -24
141 lines not on this page · raw message
drivers/fpga/dfl-afu.h +13 -13
@@ -76,27 +76,27 @@ struct dfl_afu {struct rb_root dma_regions; }; -/* hold pdata->lock when call __afu_port_enable/disable */ -int __afu_port_enable (struct dfl_feature_platform_data *pdata); -int __afu_port_disable (struct dfl_feature_platform_data *pdata); +/* hold fdata->lock when call __afu_port_enable/disable */ +int __afu_port_enable (struct dfl_feature_dev_data *fdata); +int __afu_port_disable (struct dfl_feature_dev_data *fdata); -void afu_mmio_region_init (struct dfl_feature_platform_data *pdata); -int afu_mmio_region_add (struct dfl_feature_platform_data *pdata, +void afu_mmio_region_init (struct dfl_feature_dev_data *fdata); +int afu_mmio_region_add (struct dfl_feature_dev_data *fdata,u32 region_index,u64 region_size,u64 phys,u32 flags); -void afu_mmio_region_destroy (struct dfl_feature_platform_data *pdata); -int afu_mmio_region_get_by_index (struct dfl_feature_platform_data *pdata, +void afu_mmio_region_destroy (struct dfl_feature_dev_data *fdata); +int afu_mmio_region_get_by_index (struct dfl_feature_dev_data *fdata,u32 region_index,struct dfl_afu_mmio_region *pregion); -int afu_mmio_region_get_by_offset (struct dfl_feature_platform_data *pdata, +int afu_mmio_region_get_by_offset (struct dfl_feature_dev_data *fdata,u64 offset,u64 size,struct dfl_afu_mmio_region *pregion); -void afu_dma_region_init (struct dfl_feature_platform_data *pdata); -void afu_dma_region_destroy (struct dfl_feature_platform_data *pdata); -int afu_dma_map_region (struct dfl_feature_platform_data *pdata, +void afu_dma_region_init (struct dfl_feature_dev_data *fdata); +void afu_dma_region_destroy (struct dfl_feature_dev_data *fdata); +int afu_dma_map_region (struct dfl_feature_dev_data *fdata,u64 user_addr,u64 length,u64 *iova); -int afu_dma_unmap_region (struct dfl_feature_platform_data *pdata,u64 iova); +int afu_dma_unmap_region (struct dfl_feature_dev_data *fdata,u64 iova);struct dfl_afu_dma_region * -afu_dma_region_find (struct dfl_feature_platform_data *pdata, +afu_dma_region_find (struct dfl_feature_dev_data *fdata,u64 iova,u64 size);extern const struct dfl_feature_ops port_err_ops;
drivers/fpga/dfl-fme-br.c +11 -11
@@ -22,34 +22,34 @@struct fme_br_priv {struct dfl_fme_br_pdata *pdata;struct dfl_fpga_port_ops *port_ops; -struct dfl_feature_platform_data *port_pdata; +struct dfl_feature_dev_data *port_fdata; };static int fme_bridge_enable_set (struct fpga_bridge *bridge,bool enable) { -struct dfl_feature_platform_data *port_pdata;struct fme_br_priv *priv = bridge->priv; +struct dfl_feature_dev_data *port_fdata;struct dfl_fpga_port_ops *ops; -if (!priv->port_pdata) { - port_pdata =dfl_fpga_cdev_find_port_data (priv->pdata->cdev, +if (!priv->port_fdata) { + port_fdata =dfl_fpga_cdev_find_port_data (priv->pdata->cdev, &priv->pdata->port_id, dfl_fpga_check_port_id); -if (!port_pdata) +if (!port_fdata)return -ENODEV ; - priv->port_pdata = port_pdata; + priv->port_fdata = port_fdata; } -if (priv->port_pdata && !priv->port_ops) { - ops =dfl_fpga_port_ops_get (priv->port_pdata); +if (priv->port_fdata && !priv->port_ops) { + ops =dfl_fpga_port_ops_get (priv->port_fdata);if (!ops || !ops->enable_set)return -ENOENT ; priv->port_ops = ops; } -return priv->port_ops->enable_set (priv->port_pdata, enable); +return priv->port_ops->enable_set (priv->port_fdata, enable); }static const struct fpga_bridge_ops fme_bridge_ops = {
@@ -85,8 +85,8 @@ static void fme_br_remove(struct platform_device *pdev)fpga_bridge_unregister (br); -if (priv->port_pdata) -put_device (&priv->port_pdata->dev->dev); +if (priv->port_fdata) +put_device (&priv->port_fdata->dev->dev);if (priv->port_ops)dfl_fpga_port_ops_put (priv->port_ops); }
drivers/fpga/dfl-fme-error.c +51 -51
285 lines not on this page · raw message
drivers/fpga/dfl-fme-main.c +49 -49
263 lines not on this page · raw message
drivers/fpga/dfl-fme-pr.c +42 -42
229 lines not on this page · raw message
drivers/fpga/dfl.c +91 -91
467 lines not on this page · raw message
drivers/fpga/dfl.h +40 -37
169 lines not on this page · raw message
Signature · 1 line
2.47.0
PATCH v4 9/19 fpga: dfl: factor out feature device registration
In reply to Peter ColbergAdd separate functions, feature_dev_{register,unregister}(), that wrap platform_device_add() and platform_device_unregister(), respectively. These are invoked once per feature device in this commit but will be reused in a subsequent commit to destroy and recreate the platform device when the corresponding port is released and reassigned.
The function feature_dev_register() will be extended in subsequent commits to allocate the platform device, add resources and platform data, and finally add the platform device to the device hierarchy.
The function feature_dev_unregister() is in its final form. After unregistering the device, the device pointer in the feature data is reset to NULL to signal that the platform device has been destroyed. This will substitute device_is_registered() in a subsequent commit.
---
Changes since v3:
- New patch extracted from last patch of v3 series.
--- drivers/fpga/dfl.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-)
drivers/fpga/dfl.c +27 -4
@@ -872,12 +872,35 @@ build_info_create_dev(struct build_feature_devs_info *binfo)if (fdev->id <0 )return fdev->id; - fdev->dev.parent = &binfo->cdev->region->dev; - fdev->dev.devt =dfl_get_devt (dfl_devs[type].devt_type, fdev->id); +return 0 ; +} + +/* +* register current feature device, it is called when we need to switch to +* another feature parsing or we have parsed all features on given device +* feature list. +*/ +static int feature_dev_register (struct dfl_feature_dev_data *fdata) +{ +struct platform_device *fdev = fdata->dev; +int ret; + + fdev->dev.parent = &fdata->dfl_cdev->region->dev; + fdev->dev.devt =dfl_get_devt (dfl_devs[fdata->type].devt_type, fdev->id); + + ret =platform_device_add (fdev); +if (ret) +return ret;return 0 ; } +static void feature_dev_unregister (struct dfl_feature_dev_data *fdata) +{ +platform_device_unregister (fdata->dev); + fdata->dev =NULL ; +} +static int build_info_commit_dev (struct build_feature_devs_info *binfo) {struct dfl_feature_dev_data *fdata;
@@ -887,7 +910,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)if (IS_ERR (fdata))return PTR_ERR (fdata); - ret =platform_device_add (binfo->feature_dev); + ret =feature_dev_register (fdata);if (ret)return ret;
@@ -1519,7 +1542,7 @@ static int remove_feature_dev(struct device *dev, void *data)struct platform_device *pdev =to_platform_device (dev);int id = pdev->id; -platform_device_unregister (pdev); +feature_dev_unregister (fdata);dfl_id_free (fdata->type, id);
Signature · 1 line
2.47.0
PATCH v4 10/19 fpga: dfl: factor out feature device data from platform device data
In reply to Peter ColbergAdd a structure dfl_feature_dev_data to hold the DFL enumeration info previously held in dfl_feature_platform_data. Allocate the new structure using device-managed memory whose lifetime is bound to the lifetime of the physical DFL, e.g., PCIe FPGA device. In a subsequent commit, this will allow the feature platform device to be completely destroyed and recreated on port release and assign, respectively, while retaining the feature data in the new dfl_feature_dev_data structure.
---
Changes since v3:
- New patch extracted from last patch of v3 series.
--- drivers/fpga/dfl.c | 16 +++++++--------- drivers/fpga/dfl.h | 42 ++++++++++++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 23 deletions(-)
drivers/fpga/dfl.c +7 -9
@@ -752,13 +752,7 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)if (WARN_ON_ONCE (type >=DFL_ID_MAX ))return ERR_PTR (-EINVAL ); -/* -* we do not need to care for the memory which is associated with -* the platform device. After calling platform_device_unregister(), -* it will be automatically freed by device's release() callback, -* platform_device_release(). -*/ - fdata =kzalloc (struct_size (fdata, features, binfo->feature_num),GFP_KERNEL ); + fdata =devm_kzalloc (binfo->dev,struct_size (fdata, features, binfo->feature_num),GFP_KERNEL );if (!fdata)return ERR_PTR (-ENOMEM );
@@ -779,8 +773,6 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)*/ WARN_ON (fdata->disable_count); - fdev->dev.platform_data = fdata; -/* each sub feature has one MMIO resource */ fdev->num_resources = binfo->feature_num; fdev->resource = kcalloc(binfo->feature_num, sizeof(*fdev->resource),
@@ -882,12 +874,18 @@ build_info_create_dev(struct build_feature_devs_info *binfo)*/ static int feature_dev_register (struct dfl_feature_dev_data *fdata) { +struct dfl_feature_platform_data pdata = {};struct platform_device *fdev = fdata->dev;int ret; fdev->dev.parent = &fdata->dfl_cdev->region->dev; fdev->dev.devt =dfl_get_devt (dfl_devs[fdata->type].devt_type, fdev->id); + pdata.fdata = fdata; + ret =platform_device_add_data (fdev, &pdata,sizeof (pdata)); +if (ret) +return ret; + ret =platform_device_add (fdev);if (ret)return ret;
drivers/fpga/dfl.h +28 -14
89 lines not on this page · raw message
Signature · 1 line
2.47.0
PATCH v4 11/19 fpga: dfl: convert features from flexible array member to separate array
In reply to Peter ColbergUse a separate array allocation for features and substitute a pointer for the flexible array member in the feature device data. A subsequent commit will add another array for resources. The current commit converts the flexible array member to a separate allocation for consistency.
---
Changes since v3:
- New patch extracted from last patch of v3 series.
--- drivers/fpga/dfl.c | 7 ++++++- drivers/fpga/dfl.h | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/fpga/dfl.c +6 -1
@@ -752,10 +752,15 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)if (WARN_ON_ONCE (type >=DFL_ID_MAX ))return ERR_PTR (-EINVAL ); - fdata =devm_kzalloc (binfo->dev,struct_size (fdata, features, binfo->feature_num),GFP_KERNEL ); + fdata =devm_kzalloc (binfo->dev,sizeof (*fdata),GFP_KERNEL );if (!fdata)return ERR_PTR (-ENOMEM ); + fdata->features =devm_kcalloc (binfo->dev, binfo->feature_num, +sizeof (*fdata->features),GFP_KERNEL ); +if (!fdata->features) +return ERR_PTR (-ENOMEM ); + fdata->dev = fdev; fdata->type = type; fdata->num = binfo->feature_num;
drivers/fpga/dfl.h +1 -1
@@ -330,7 +330,7 @@ struct dfl_feature_dev_data {int open_count;void *private;int num; -struct dfl_feature features[]; +struct dfl_feature *features; };/**
Signature · 1 line
2.47.0
PATCH v4 12/19 fpga: dfl: store MMIO resources in feature device data
In reply to Peter ColbergInstead of directly copying the MMIO resource of each feature to the feature device resources, add a new member to the feature device data to store the resources and copy them to the feature device using platform_device_add_resources(). This prepares a subsequent commit which completely destroys and recreates the feature device when releasing and reassigning the corresponding port, respectively.
---
Changes since v3:
- New patch extracted from last patch of v3 series.
--- drivers/fpga/dfl.c | 21 +++++++++++++-------- drivers/fpga/dfl.h | 4 ++++ 2 files changed, 17 insertions(+), 8 deletions(-)
drivers/fpga/dfl.c +13 -8
@@ -761,6 +761,11 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)if (!fdata->features)return ERR_PTR (-ENOMEM ); + fdata->resources =devm_kcalloc (binfo->dev, binfo->feature_num, +sizeof (*fdata->resources),GFP_KERNEL ); +if (!fdata->resources) +return ERR_PTR (-ENOMEM ); + fdata->dev = fdev; fdata->type = type; fdata->num = binfo->feature_num;
@@ -778,13 +783,6 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)*/ WARN_ON (fdata->disable_count); -/* each sub feature has one MMIO resource */ - fdev->num_resources = binfo->feature_num; - fdev->resource =kcalloc (binfo->feature_num,sizeof (*fdev->resource), -GFP_KERNEL ); -if (!fdev->resource) -return ERR_PTR (-ENOMEM ); -/* fill features and resource information for feature dev */ list_for_each_entry_safe (finfo, p, &binfo->sub_features, node) {struct dfl_feature *feature = &fdata->features[index++];
@@ -822,7 +820,7 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)return feature->ioaddr; }else { feature->resource_index = res_idx; - fdev->resource[res_idx++] = finfo->mmio_res; + fdata->resources[res_idx++] = finfo->mmio_res; }if (finfo->nr_irqs) {
@@ -843,6 +841,8 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)kfree (finfo); } + fdata->resource_num = res_idx; +return fdata; }
@@ -886,6 +886,11 @@ static int feature_dev_register(struct dfl_feature_dev_data *fdata) fdev->dev.parent = &fdata->dfl_cdev->region->dev; fdev->dev.devt =dfl_get_devt (dfl_devs[fdata->type].devt_type, fdev->id); + ret =platform_device_add_resources (fdev, fdata->resources, + fdata->resource_num); +if (ret) +return ret; + pdata.fdata = fdata; ret =platform_device_add_data (fdev, &pdata,sizeof (pdata));if (ret)
drivers/fpga/dfl.h +4 -0
@@ -317,6 +317,8 @@ struct dfl_feature {* @num: number for sub features. * @private: ptr to feature dev private data. * @features: sub features for the feature dev. +* @resource_num: number of resources for the feature dev. +* @resources: resources for the feature dev. */ struct dfl_feature_dev_data {struct list_head node;
@@ -331,6 +333,8 @@ struct dfl_feature_dev_data {void *private;int num;struct dfl_feature *features; +int resource_num; +struct resource *resources; };/**
Signature · 1 line
2.47.0
PATCH v4 13/19 fpga: dfl: store platform device name in feature device data
In reply to Peter ColbergAdd a new member, pdev_name, to the structure dfl_feature_dev_data that holds the platform device name for convenience. A subsequent commit will completely destroy the platform device during port release, after which fdata->dev is unavailable, while fdata itself remains available.
---
Changes since v3:
- New patch extracted from last patch of v3 series.
--- drivers/fpga/dfl.c | 3 ++- drivers/fpga/dfl.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/fpga/dfl.c +2 -1
@@ -160,7 +160,7 @@ struct dfl_fpga_port_ops *dfl_fpga_port_ops_get(struct dfl_feature_dev_data *fdalist_for_each_entry (ops, &dfl_port_ops_list, node) {/* match port_ops using the name of platform device */ -if (!strcmp (fdata->dev->name, ops->name)) { +if (!strcmp (fdata->pdev_name, ops->name)) {if (!try_module_get (ops->owner)) ops =NULL ; goto done;
@@ -768,6 +768,7 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo) fdata->dev = fdev; fdata->type = type; + fdata->pdev_name = dfl_devs[type].name; fdata->num = binfo->feature_num; fdata->dfl_cdev = binfo->cdev; fdata->id =FEATURE_DEV_ID_UNUSED ;
drivers/fpga/dfl.h +2 -0
@@ -309,6 +309,7 @@ struct dfl_feature {* @lock: mutex to protect feature dev data. * @dev: ptr to the feature's platform device linked with this structure. * @type: type of DFL FIU for the feature dev. See enum dfl_id_type. +* @pdev_name: platform device name for the feature dev. * @dfl_cdev: ptr to container device. * @id: id used for the feature device. * @disable_count: count for port disable.
@@ -325,6 +326,7 @@ struct dfl_feature_dev_data {struct mutex lock;struct platform_device *dev;enum dfl_id_type type; +const char *pdev_name;struct dfl_fpga_cdev *dfl_cdev;int id;unsigned int disable_count;
Signature · 1 line
2.47.0
PATCH v4 14/19 fpga: dfl: store platform device id in feature device data
In reply to Peter ColbergDelay the feature device id allocation from build_info_create_dev() to binfo_create_feature_dev_data() and store the id in the feature device data before copying it to the device. This will allow reusing the same id in a subsequent commit which completely destroys and recreates the feature device when releasing and reassigning the corresponding port.
Instead of manually freeing the id when no longer needed, use a device-managed resource with a custom action to automatically free the id right before the feature device data is freed. The id registry is guaranteed to be allocated when dfl_id_free_action() is invoked, since the DFL PCIe device and its device-managed resources will be destroyed before dfl_ids_destroy() is called in dfl_fpga_exit().
---
Changes since v3:
- New patch extracted from last patch of v3 series.
--- drivers/fpga/dfl.c | 43 ++++++++++++++++++++++--------------------- drivers/fpga/dfl.h | 2 ++ 2 files changed, 24 insertions(+), 21 deletions(-)
drivers/fpga/dfl.c +22 -21
@@ -740,6 +740,13 @@ static void dfl_fpga_cdev_add_port_data(struct dfl_fpga_cdev *cdev,mutex_unlock (&cdev->lock); } +static void dfl_id_free_action (void *arg) +{ +struct dfl_feature_dev_data *fdata = arg; + +dfl_id_free (fdata->type, fdata->pdev_id); +} +static struct dfl_feature_dev_data *binfo_create_feature_dev_data (struct build_feature_devs_info *binfo) {
@@ -747,7 +754,7 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)enum dfl_id_type type = binfo->type;struct dfl_feature_info *finfo, *p;struct dfl_feature_dev_data *fdata; -int index =0 , res_idx =0 ; +int ret, index =0 , res_idx =0 ;if (WARN_ON_ONCE (type >=DFL_ID_MAX ))return ERR_PTR (-EINVAL );
@@ -768,6 +775,17 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo) fdata->dev = fdev; fdata->type = type; + + fdata->pdev_id =dfl_id_alloc (type, binfo->dev); +if (fdata->pdev_id <0 ) +return ERR_PTR (fdata->pdev_id); + + ret =devm_add_action_or_reset (binfo->dev, dfl_id_free_action, fdata); +if (ret) +return ERR_PTR (ret); + + fdev->id = fdata->pdev_id; + fdata->pdev_name = dfl_devs[type].name; fdata->num = binfo->feature_num; fdata->dfl_cdev = binfo->cdev;
@@ -866,10 +884,6 @@ build_info_create_dev(struct build_feature_devs_info *binfo)INIT_LIST_HEAD (&binfo->sub_features); - fdev->id =dfl_id_alloc (type, &fdev->dev); -if (fdev->id <0 ) -return fdev->id; -return 0 ; }
@@ -947,17 +961,9 @@ static void build_info_free(struct build_feature_devs_info *binfo) {struct dfl_feature_info *finfo, *p; -/* -* it is a valid id, free it. See comments in -* build_info_create_dev() -*/ -if (binfo->feature_dev && binfo->feature_dev->id >=0 ) { -dfl_id_free (binfo->type, binfo->feature_dev->id); - -list_for_each_entry_safe (finfo, p, &binfo->sub_features, node) { -list_del (&finfo->node); -kfree (finfo); - } +list_for_each_entry_safe (finfo, p, &binfo->sub_features, node) { +list_del (&finfo->node); +kfree (finfo); }platform_device_put (binfo->feature_dev);
@@ -1548,13 +1554,9 @@ EXPORT_SYMBOL_GPL(dfl_fpga_enum_info_add_irq);static int remove_feature_dev (struct device *dev,void *data) {struct dfl_feature_dev_data *fdata =to_dfl_feature_dev_data (dev); -struct platform_device *pdev =to_platform_device (dev); -int id = pdev->id;feature_dev_unregister (fdata); -dfl_id_free (fdata->type, id); -return 0 ; }
@@ -1658,7 +1660,6 @@ void dfl_fpga_feature_devs_remove(struct dfl_fpga_cdev *cdev)/* remove released ports */ if (!device_is_registered (&port_dev->dev)) { -dfl_id_free (fdata->type, port_dev->id);platform_device_put (port_dev); }
drivers/fpga/dfl.h +2 -0
@@ -309,6 +309,7 @@ struct dfl_feature {* @lock: mutex to protect feature dev data. * @dev: ptr to the feature's platform device linked with this structure. * @type: type of DFL FIU for the feature dev. See enum dfl_id_type. +* @pdev_id: platform device id for the feature dev. * @pdev_name: platform device name for the feature dev. * @dfl_cdev: ptr to container device. * @id: id used for the feature device.
@@ -326,6 +327,7 @@ struct dfl_feature_dev_data {struct mutex lock;struct platform_device *dev;enum dfl_id_type type; +int pdev_id;const char *pdev_name;struct dfl_fpga_cdev *dfl_cdev;int id;
Signature · 1 line
2.47.0
Re: [PATCH v4 14/19] fpga: dfl: store platform device id in feature device data
drivers/fpga/dfl.c void dfl_fpga_feature_devs_remove(struct dfl_fpga_cdev *cdev) · line 1661
Quoted 5 lines
drivers/fpga/dfl.c +0
-1@@ -1658,7 +1660,6 @@ void dfl_fpga_feature_devs_remove(struct dfl_fpga_cdev *cdev)/* remove released ports */ if (!device_is_registered (&port_dev->dev)) { -dfl_id_free (fdata->type, port_dev->id);
Also remove the braces.
Thanks,
Yilun
Quoted 2 lines
drivers/fpga/dfl.c +0
-0platform_device_put (port_dev); }
Re: [PATCH v4 14/19] fpga: dfl: store platform device id in feature device data
Quoted 10 lines · Xu Yilun
drivers/fpga/dfl.c void dfl_fpga_feature_devs_remove(struct dfl_fpga_cdev *cdev) · line 1661
Quoted 8 lines
(quoted diff) +0
-0@@ -1658,7 +1660,6 @@ void dfl_fpga_feature_devs_remove(struct dfl_fpga_cdev *cdev)/* remove released ports */
if (!device_is_registered(&port_dev->dev)) {drivers/fpga/dfl.c +0
-1-dfl_id_free (fdata->type, port_dev->id);Also remove the braces.
Thanks, this has been resolved in [PATCH v5 14/18].
Peter
Quoted 6 lines
Thanks,
YilunQuoted 2 lines
platform_device_put(port_dev); }
PATCH v4 15/19 fpga: dfl: convert is_feature_dev_detected() to use FIU type
In reply to Peter ColbergUse binfo->type instead of binfo->feature_dev to decide whether a feature device was detected during feature parsing. A subsequent commit will delay the allocation of the feature platform device to feature_dev_register() and remove binfo->feature_dev.
This commit does not introduce any functional changes.
---
Changes since v3:
- New patch extracted from last patch of v3 series.
--- drivers/fpga/dfl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/fpga/dfl.c +1 -1
@@ -1248,7 +1248,7 @@ static int parse_feature_port_afu(struct build_feature_devs_info *binfo,return create_feature_instance (binfo, ofst, size,FEATURE_ID_AFU ); } -#define is_feature_dev_detected (binfo) (!!(binfo)->feature_dev) +#define is_feature_dev_detected (binfo) ((binfo)->type != DFL_ID_MAX)static int parse_feature_afu (struct build_feature_devs_info *binfo,resource_size_t ofst)
Signature · 1 line
2.47.0
Re: [PATCH v4 15/19] fpga: dfl: convert is_feature_dev_detected() to use FIU type
Quoted 22 lines · Peter Colberg
Use
binfo->typeinstead ofbinfo->feature_devto decide whether a feature device was detected during feature parsing. A subsequent commit will delay the allocation of the feature platform device tofeature_dev_register()and removebinfo->feature_dev.This commit does not introduce any functional changes.
Signed-off-by Peter Colberg <[email protected]>Reviewed-by Matthew Gerlach <[email protected]>Reviewed-by Basheer Ahmed Muddebihal <[email protected]>---
Changes since v3:
- New patch extracted from last patch of v3 series.--- drivers/fpga/dfl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/fpga/dfl.c +0
-0
drivers/fpga/dfl.c static int parse_feature_port_afu(struct build_feature_devs_info *binfo, · line 1251
Quoted 5 lines
drivers/fpga/dfl.c +1
-1@@ -1248,7 +1248,7 @@ static int parse_feature_port_afu(struct build_feature_devs_info *binfo,return create_feature_instance (binfo, ofst, size,FEATURE_ID_AFU ); } -#define is_feature_dev_detected (binfo) (!!(binfo)->feature_dev) +#define is_feature_dev_detected (binfo) ((binfo)->type != DFL_ID_MAX)
I still doesn't get why put the change here. How it resolves my concern compared to v3?
Thanks,
Yilun
Quoted 7 lines
drivers/fpga/dfl.c +0
-0static int parse_feature_afu (struct build_feature_devs_info *binfo,resource_size_t ofst)Signature · 1 line
2.47.0
Re: [PATCH v4 15/19] fpga: dfl: convert is_feature_dev_detected() to use FIU type
Quoted 26 lines · Xu Yilun
Quoted 25 lines · Peter Colberg
Use
binfo->typeinstead ofbinfo->feature_devto decide whether a feature device was detected during feature parsing. A subsequent commit will delay the allocation of the feature platform device tofeature_dev_register()and removebinfo->feature_dev.This commit does not introduce any functional changes.
Signed-off-by Peter Colberg <[email protected]>Reviewed-by Matthew Gerlach <[email protected]>Reviewed-by Basheer Ahmed Muddebihal <[email protected]>---
Changes since v3:
- New patch extracted from last patch of v3 series.--- drivers/fpga/dfl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/fpga/dfl.c +0
-0@@ -1248,7 +1248,7 @@ static int parse_feature_port_afu(struct build_feature_devs_info *binfo,return create_feature_instance (binfo, ofst, size,FEATURE_ID_AFU ); }
Quoted 5 lines
drivers/fpga/dfl.c static int parse_feature_port_afu(struct build_feature_devs_info *binfo, · line 1251
Quoted 2 lines
drivers/fpga/dfl.c +1
-1-#define is_feature_dev_detected (binfo) (!!(binfo)->feature_dev) +#define is_feature_dev_detected (binfo) ((binfo)->type != DFL_ID_MAX)I still doesn't get why put the change here. How it resolves my concern compared to v3?
Could you elaborate on your concern? I moved this change into a separate commit so that it is not lost in other changes, but I don't see how the two definitions would not be functionally equivalent. Would it help to extend the commit description along the following lines?
1. Before this series, binfo->feature_dev was initialized to NULL by devm_kzalloc() in dfl_fpga_feature_devs_enumerate(). After this series, binfo->type is initialized to DFL_ID_MAX in dfl_fpga_feature_devs_enumerate().
2. Before this series, binfo->feature_dev was set to a non-NULL pointer in build_info_create_dev(), which in turn was called from parse_feature_fiu(). After this series, binfo->type is set to a non-DFL_ID_MAX value, as returned by dfh_id_to_type(), in parse_feature_fiu().
3. Before this series, binfo->feature_dev was reset to NULL at the end of build_info_commit_dev(). After this series, binfo->type is reset to DFL_ID_MAX at the end of build_info_commit_dev().
Thanks,
Peter
Quoted 11 lines
Thanks,
YilunQuoted 7 lines
drivers/fpga/dfl.c +0
-0static int parse_feature_afu (struct build_feature_devs_info *binfo,resource_size_t ofst)Signature · 1 line
2.47.0
Re: [PATCH v4 15/19] fpga: dfl: convert is_feature_dev_detected() to use FIU type
Quoted 27 lines · Peter
Quoted 26 lines · Xu Yilun
Quoted 25 lines · Peter Colberg
Use
binfo->typeinstead ofbinfo->feature_devto decide whether a feature device was detected during feature parsing. A subsequent commit will delay the allocation of the feature platform device tofeature_dev_register()and removebinfo->feature_dev.This commit does not introduce any functional changes.
Signed-off-by Peter Colberg <[email protected]>Reviewed-by Matthew Gerlach <[email protected]>Reviewed-by Basheer Ahmed Muddebihal <[email protected]>---
Changes since v3:
- New patch extracted from last patch of v3 series.--- drivers/fpga/dfl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/fpga/dfl.c +0
-0@@ -1248,7 +1248,7 @@ static int parse_feature_port_afu(struct build_feature_devs_info *binfo,return create_feature_instance (binfo, ofst, size,FEATURE_ID_AFU ); }
Quoted 8 lines
Quoted 5 lines
drivers/fpga/dfl.c static int parse_feature_port_afu(struct build_feature_devs_info *binfo, · line 1251
Quoted 2 lines
drivers/fpga/dfl.c +1
-1-#define is_feature_dev_detected (binfo) (!!(binfo)->feature_dev) +#define is_feature_dev_detected (binfo) ((binfo)->type != DFL_ID_MAX)I still doesn't get why put the change here. How it resolves my concern compared to v3?
Could you elaborate on your concern? I moved this change into a separate commit so that it is not lost in other changes, but I don't
I did't mean this change had to be separated, I doubt it impacts the functionality when it was applied. After the series were all applied the issue may be fixed but people review patches one by one.
Quoted 9 lines
see how the two definitions would not be functionally equivalent. Would it help to extend the commit description along the following lines?
1. Before this series,
binfo->feature_devwas initialized to NULL bydevm_kzalloc()indfl_fpga_feature_devs_enumerate(). After this series,binfo->typeis initialized toDFL_ID_MAXindfl_fpga_feature_devs_enumerate().
2. Before this series,binfo->feature_devwas set to a non-NULL pointer inbuild_info_create_dev(), which in turn was called from
So at the point of *this patch* is applied, binfo->feature_dev & binfo->type don't initialize at the same time, there is some gap the caller of is_feature_dev_detected() would get a different result, e.g. when build_info_create_dev() fails, binfo->type holds valid DFL_ID but binfo->feature_dev is NULL.
Quoted 22 lines
parse_feature_fiu(). After this series,binfo->typeis set to a non-DFL_ID_MAX value, as returned bydfh_id_to_type(), inparse_feature_fiu().
3. Before this series,binfo->feature_devwas reset to NULL at the end ofbuild_info_commit_dev(). After this series,binfo->typeis reset toDFL_ID_MAXat the end ofbuild_info_commit_dev().Thanks,
PeterQuoted 11 lines
Thanks,
YilunQuoted 7 lines
drivers/fpga/dfl.c +0
-0static int parse_feature_afu (struct build_feature_devs_info *binfo,resource_size_t ofst)Signature · 1 line
2.47.0
Re: [PATCH v4 15/19] fpga: dfl: convert is_feature_dev_detected() to use FIU type
Quoted 51 lines · Xu Yilun
Quoted 27 lines · Peter
Quoted 26 lines · Xu Yilun
Quoted 25 lines · Peter Colberg
Use
binfo->typeinstead ofbinfo->feature_devto decide whether a feature device was detected during feature parsing. A subsequent commit will delay the allocation of the feature platform device tofeature_dev_register()and removebinfo->feature_dev.This commit does not introduce any functional changes.
Signed-off-by Peter Colberg <[email protected]>Reviewed-by Matthew Gerlach <[email protected]>Reviewed-by Basheer Ahmed Muddebihal <[email protected]>---
Changes since v3:
- New patch extracted from last patch of v3 series.--- drivers/fpga/dfl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/fpga/dfl.c +0
-0@@ -1248,7 +1248,7 @@ static int parse_feature_port_afu(struct build_feature_devs_info *binfo,return create_feature_instance (binfo, ofst, size,FEATURE_ID_AFU ); }Quoted 8 lines
Quoted 5 lines
drivers/fpga/dfl.c static int parse_feature_port_afu(struct build_feature_devs_info *binfo, · line 1251
Quoted 2 lines
drivers/fpga/dfl.c +1
-1-#define is_feature_dev_detected (binfo) (!!(binfo)->feature_dev) +#define is_feature_dev_detected (binfo) ((binfo)->type != DFL_ID_MAX)I still doesn't get why put the change here. How it resolves my concern compared to v3?
Could you elaborate on your concern? I moved this change into a separate commit so that it is not lost in other changes, but I don't
I did't mean this change had to be separated, I doubt it impacts the functionality when it was applied. After the series were all applied the issue may be fixed but people review patches one by one.
Quoted 9 lines
see how the two definitions would not be functionally equivalent. Would it help to extend the commit description along the following lines?
1. Before this series,
binfo->feature_devwas initialized to NULL bydevm_kzalloc()indfl_fpga_feature_devs_enumerate(). After this series,binfo->typeis initialized toDFL_ID_MAXindfl_fpga_feature_devs_enumerate().
2. Before this series,binfo->feature_devwas set to a non-NULL pointer inbuild_info_create_dev(), which in turn was called from
Quoted 5 lines
So at the point of *this patch* is applied,
binfo->feature_dev&binfo->typedon't initialize at the same time, there is some gap the caller ofis_feature_dev_detected()would get a different result, e.g. whenbuild_info_create_dev()fails,binfo->typeholds validDFL_IDbutbinfo->feature_devis NULL.
Thank you for the clarification. This and the subsequent patch have been merged in [PATCH v5 15/18], to avoid a window between binfo->type already holding a valid DFL id but binfo->feature_dev still NULL.
Peter
Quoted 23 lines
Quoted 23 lines
parse_feature_fiu(). After this series,binfo->typeis set to a non-DFL_ID_MAX value, as returned bydfh_id_to_type(), inparse_feature_fiu().
3. Before this series,binfo->feature_devwas reset to NULL at the end ofbuild_info_commit_dev(). After this series,binfo->typeis reset toDFL_ID_MAXat the end ofbuild_info_commit_dev().Thanks,
PeterQuoted 11 lines
Thanks,
YilunQuoted 7 lines
drivers/fpga/dfl.c +0
-0static int parse_feature_afu (struct build_feature_devs_info *binfo,resource_size_t ofst)Signature · 1 line
2.47.0
PATCH v4 16/19 fpga: dfl: allocate platform device after feature device data
In reply to Peter ColbergDelay calling platform_device_alloc() from build_info_create_dev() to feature_dev_register(), now that the feature device data contains all necessary data to create the feature device. This completes the new function feature_dev_register(), which will be reused in a subsequent commit to fully recreate the feature device when assigning a port.
---
Changes since v3:
- New patch extracted from last patch of v3 series.
--- drivers/fpga/dfl.c | 59 +++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 37 deletions(-)
drivers/fpga/dfl.c +22 -37
@@ -681,7 +681,6 @@ EXPORT_SYMBOL_GPL(dfl_fpga_dev_ops_unregister);* @nr_irqs: number of irqs for all feature devices. * @irq_table: Linux IRQ numbers for all irqs, indexed by local irq index of * this device. -* @feature_dev: current feature device. * @type: the current FIU type. * @ioaddr: header register region address of current FIU in enumeration. * @start: register resource start of current FIU.
@@ -695,7 +694,6 @@ struct build_feature_devs_info {unsigned int nr_irqs;int *irq_table; -struct platform_device *feature_dev;enum dfl_id_type type;void __iomem *ioaddr;resource_size_t start;
@@ -750,7 +748,6 @@ static void dfl_id_free_action(void *arg)static struct dfl_feature_dev_data *binfo_create_feature_dev_data (struct build_feature_devs_info *binfo) { -struct platform_device *fdev = binfo->feature_dev;enum dfl_id_type type = binfo->type;struct dfl_feature_info *finfo, *p;struct dfl_feature_dev_data *fdata;
@@ -773,7 +770,6 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)if (!fdata->resources)return ERR_PTR (-ENOMEM ); - fdata->dev = fdev; fdata->type = type; fdata->pdev_id =dfl_id_alloc (type, binfo->dev);
@@ -784,8 +780,6 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)if (ret)return ERR_PTR (ret); - fdev->id = fdata->pdev_id; - fdata->pdev_name = dfl_devs[type].name; fdata->num = binfo->feature_num; fdata->dfl_cdev = binfo->cdev;
@@ -809,7 +803,6 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)unsigned int i;/* save resource information for each feature */ - feature->dev = fdev; feature->id = finfo->fid; feature->revision = finfo->revision; feature->dfh_version = finfo->dfh_version;
@@ -868,18 +861,6 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)static int build_info_create_dev (struct build_feature_devs_info *binfo) { -enum dfl_id_type type = binfo->type; -struct platform_device *fdev; - -/* -* we use -ENODEV as the initialization indicator which indicates -* whether the id need to be reclaimed -*/ - fdev =platform_device_alloc (dfl_devs[type].name, -ENODEV ); -if (!fdev) -return -ENOMEM ; - - binfo->feature_dev = fdev; binfo->feature_num =0 ;INIT_LIST_HEAD (&binfo->sub_features);
@@ -895,27 +876,43 @@ build_info_create_dev(struct build_feature_devs_info *binfo)static int feature_dev_register (struct dfl_feature_dev_data *fdata) {struct dfl_feature_platform_data pdata = {}; -struct platform_device *fdev = fdata->dev; +struct platform_device *fdev; +struct dfl_feature *feature;int ret; + fdev =platform_device_alloc (fdata->pdev_name, fdata->pdev_id); +if (!fdev) +return -ENOMEM ; + + fdata->dev = fdev; + fdev->dev.parent = &fdata->dfl_cdev->region->dev; fdev->dev.devt =dfl_get_devt (dfl_devs[fdata->type].devt_type, fdev->id); +dfl_fpga_dev_for_each_feature (fdata, feature) + feature->dev = fdev; + ret =platform_device_add_resources (fdev, fdata->resources, fdata->resource_num);if (ret) -return ret; + goto err_put_dev; pdata.fdata = fdata; ret =platform_device_add_data (fdev, &pdata,sizeof (pdata));if (ret) -return ret; + goto err_put_dev; ret =platform_device_add (fdev);if (ret) -return ret; + goto err_put_dev;return 0 ; + +err_put_dev: +platform_device_put (fdev); + fdata->dev =NULL ; + +return ret; }static void feature_dev_unregister (struct dfl_feature_dev_data *fdata)
@@ -940,16 +937,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)if (binfo->type ==PORT_ID )dfl_fpga_cdev_add_port_data (binfo->cdev, fdata);else - binfo->cdev->fme_dev =get_device (&binfo->feature_dev->dev); - -/* -* reset it to avoid build_info_free() freeing their resource. -* -* The resource of successfully registered feature devices -* will be freed by platform_device_unregister(). See the -* comments in build_info_create_dev(). -*/ - binfo->feature_dev =NULL ; + binfo->cdev->fme_dev =get_device (&fdata->dev->dev);/* reset the binfo for next FIU */ binfo->type =DFL_ID_MAX ;
@@ -966,8 +954,6 @@ static void build_info_free(struct build_feature_devs_info *binfo)kfree (finfo); } -platform_device_put (binfo->feature_dev); -devm_kfree (binfo->dev, binfo); }
@@ -1262,8 +1248,7 @@ static int parse_feature_afu(struct build_feature_devs_info *binfo,case PORT_ID :return parse_feature_port_afu (binfo, ofst);default : -dev_info (binfo->dev,"AFU belonging to FIU %s is not supported yet.\n" , - binfo->feature_dev->name); +dev_info (binfo->dev,"AFU belonging to FIU is not supported yet.\n" ); }return 0 ;
Signature · 1 line
2.47.0
Re: [PATCH v4 16/19] fpga: dfl: allocate platform device after feature device data
Quoted 121 lines · Peter Colberg
Delay calling
platform_device_alloc()frombuild_info_create_dev()tofeature_dev_register(), now that the feature device data contains all necessary data to create the feature device. This completes the new functionfeature_dev_register(), which will be reused in a subsequent commit to fully recreate the feature device when assigning a port.Signed-off-by Peter Colberg <[email protected]>Reviewed-by Matthew Gerlach <[email protected]>Reviewed-by Basheer Ahmed Muddebihal <[email protected]>---
Changes since v3:
- New patch extracted from last patch of v3 series.--- drivers/fpga/dfl.c | 59 +++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 37 deletions(-)drivers/fpga/dfl.c +13
-22@@ -681,7 +681,6 @@ EXPORT_SYMBOL_GPL(dfl_fpga_dev_ops_unregister);* @nr_irqs: number of irqs for all feature devices. * @irq_table: Linux IRQ numbers for all irqs, indexed by local irq index of * this device. -* @feature_dev: current feature device. * @type: the current FIU type. * @ioaddr: header register region address of current FIU in enumeration. * @start: register resource start of current FIU. @@ -695,7 +694,6 @@ struct build_feature_devs_info {unsigned int nr_irqs;int *irq_table; -struct platform_device *feature_dev;enum dfl_id_type type;void __iomem *ioaddr;resource_size_t start;@@ -750,7 +748,6 @@ static void dfl_id_free_action(void *arg)static struct dfl_feature_dev_data *binfo_create_feature_dev_data (struct build_feature_devs_info *binfo) { -struct platform_device *fdev = binfo->feature_dev;enum dfl_id_type type = binfo->type;struct dfl_feature_info *finfo, *p;struct dfl_feature_dev_data *fdata;@@ -773,7 +770,6 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)if (!fdata->resources)return ERR_PTR (-ENOMEM ); - fdata->dev = fdev; fdata->type = type; fdata->pdev_id =dfl_id_alloc (type, binfo->dev);@@ -784,8 +780,6 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)if (ret)return ERR_PTR (ret); - fdev->id = fdata->pdev_id; - fdata->pdev_name = dfl_devs[type].name; fdata->num = binfo->feature_num; fdata->dfl_cdev = binfo->cdev;@@ -809,7 +803,6 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)unsigned int i;/* save resource information for each feature */ - feature->dev = fdev; feature->id = finfo->fid; feature->revision = finfo->revision; feature->dfh_version = finfo->dfh_version;@@ -868,18 +861,6 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)static int build_info_create_dev (struct build_feature_devs_info *binfo) { -enum dfl_id_type type = binfo->type; -struct platform_device *fdev; - -/* -* we use -ENODEV as the initialization indicator which indicates -* whether the id need to be reclaimed -*/ - fdev =platform_device_alloc (dfl_devs[type].name, -ENODEV ); -if (!fdev) -return -ENOMEM ; - - binfo->feature_dev = fdev; binfo->feature_num =0 ;INIT_LIST_HEAD (&binfo->sub_features);@@ -895,27 +876,43 @@ build_info_create_dev(struct build_feature_devs_info *binfo)static int feature_dev_register (struct dfl_feature_dev_data *fdata) {struct dfl_feature_platform_data pdata = {}; -struct platform_device *fdev = fdata->dev; +struct platform_device *fdev; +struct dfl_feature *feature;int ret; + fdev =platform_device_alloc (fdata->pdev_name, fdata->pdev_id); +if (!fdev) +return -ENOMEM ; + + fdata->dev = fdev; + fdev->dev.parent = &fdata->dfl_cdev->region->dev; fdev->dev.devt =dfl_get_devt (dfl_devs[fdata->type].devt_type, fdev->id); +dfl_fpga_dev_for_each_feature (fdata, feature) + feature->dev = fdev; + ret =platform_device_add_resources (fdev, fdata->resources, fdata->resource_num);if (ret) -return ret; + goto err_put_dev; pdata.fdata = fdata; ret =platform_device_add_data (fdev, &pdata,sizeof (pdata));if (ret) -return ret; + goto err_put_dev;
drivers/fpga/dfl.c build_info_create_dev(struct build_feature_devs_info *binfo) · line 913
Quoted 10 lines
drivers/fpga/dfl.c +5
-1ret =platform_device_add (fdev);if (ret) -return ret; + goto err_put_dev;return 0 ; + +err_put_dev: +platform_device_put (fdev); + fdata->dev =NULL ;
Do we also need to clean up all the feature->dev?
Thanks,
Yilun
Quoted 46 lines
drivers/fpga/dfl.c +4
-14+ +return ret; }static void feature_dev_unregister (struct dfl_feature_dev_data *fdata)@@ -940,16 +937,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)if (binfo->type ==PORT_ID )dfl_fpga_cdev_add_port_data (binfo->cdev, fdata);else - binfo->cdev->fme_dev =get_device (&binfo->feature_dev->dev); - -/* -* reset it to avoid build_info_free() freeing their resource. -* -* The resource of successfully registered feature devices -* will be freed by platform_device_unregister(). See the -* comments in build_info_create_dev(). -*/ - binfo->feature_dev =NULL ; + binfo->cdev->fme_dev =get_device (&fdata->dev->dev);/* reset the binfo for next FIU */ binfo->type =DFL_ID_MAX ;@@ -966,8 +954,6 @@ static void build_info_free(struct build_feature_devs_info *binfo)kfree (finfo); } -platform_device_put (binfo->feature_dev); -devm_kfree (binfo->dev, binfo); }@@ -1262,8 +1248,7 @@ static int parse_feature_afu(struct build_feature_devs_info *binfo,case PORT_ID :return parse_feature_port_afu (binfo, ofst);default : -dev_info (binfo->dev,"AFU belonging to FIU %s is not supported yet.\n" , - binfo->feature_dev->name); +dev_info (binfo->dev,"AFU belonging to FIU is not supported yet.\n" ); }return 0 ;Signature · 1 line
2.47.0
Re: [PATCH v4 16/19] fpga: dfl: allocate platform device after feature device data
Quoted 127 lines · Xu Yilun
Quoted 126 lines · Peter Colberg
Delay calling
platform_device_alloc()frombuild_info_create_dev()tofeature_dev_register(), now that the feature device data contains all necessary data to create the feature device. This completes the new functionfeature_dev_register(), which will be reused in a subsequent commit to fully recreate the feature device when assigning a port.Signed-off-by Peter Colberg <[email protected]>Reviewed-by Matthew Gerlach <[email protected]>Reviewed-by Basheer Ahmed Muddebihal <[email protected]>---
Changes since v3:
- New patch extracted from last patch of v3 series.--- drivers/fpga/dfl.c | 59 +++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 37 deletions(-)drivers/fpga/dfl.c +14
-23@@ -681,7 +681,6 @@ EXPORT_SYMBOL_GPL(dfl_fpga_dev_ops_unregister);* @nr_irqs: number of irqs for all feature devices. * @irq_table: Linux IRQ numbers for all irqs, indexed by local irq index of * this device. -* @feature_dev: current feature device. * @type: the current FIU type. * @ioaddr: header register region address of current FIU in enumeration. * @start: register resource start of current FIU. @@ -695,7 +694,6 @@ struct build_feature_devs_info {unsigned int nr_irqs;int *irq_table; -struct platform_device *feature_dev;enum dfl_id_type type;void __iomem *ioaddr;resource_size_t start;@@ -750,7 +748,6 @@ static void dfl_id_free_action(void *arg)static struct dfl_feature_dev_data *binfo_create_feature_dev_data (struct build_feature_devs_info *binfo) { -struct platform_device *fdev = binfo->feature_dev;enum dfl_id_type type = binfo->type;struct dfl_feature_info *finfo, *p;struct dfl_feature_dev_data *fdata;@@ -773,7 +770,6 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)if (!fdata->resources)return ERR_PTR (-ENOMEM ); - fdata->dev = fdev; fdata->type = type; fdata->pdev_id =dfl_id_alloc (type, binfo->dev);@@ -784,8 +780,6 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)if (ret)return ERR_PTR (ret); - fdev->id = fdata->pdev_id; - fdata->pdev_name = dfl_devs[type].name; fdata->num = binfo->feature_num; fdata->dfl_cdev = binfo->cdev;@@ -809,7 +803,6 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)unsigned int i;/* save resource information for each feature */ - feature->dev = fdev; feature->id = finfo->fid; feature->revision = finfo->revision; feature->dfh_version = finfo->dfh_version;@@ -868,18 +861,6 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)static int build_info_create_dev (struct build_feature_devs_info *binfo) { -enum dfl_id_type type = binfo->type; -struct platform_device *fdev; - -/* -* we use -ENODEV as the initialization indicator which indicates -* whether the id need to be reclaimed -*/ - fdev =platform_device_alloc (dfl_devs[type].name, -ENODEV ); -if (!fdev) -return -ENOMEM ; - - binfo->feature_dev = fdev; binfo->feature_num =0 ;INIT_LIST_HEAD (&binfo->sub_features);@@ -895,27 +876,43 @@ build_info_create_dev(struct build_feature_devs_info *binfo)static int feature_dev_register (struct dfl_feature_dev_data *fdata) {struct dfl_feature_platform_data pdata = {}; -struct platform_device *fdev = fdata->dev; +struct platform_device *fdev; +struct dfl_feature *feature;int ret; + fdev =platform_device_alloc (fdata->pdev_name, fdata->pdev_id); +if (!fdev) +return -ENOMEM ; + + fdata->dev = fdev; + fdev->dev.parent = &fdata->dfl_cdev->region->dev; fdev->dev.devt =dfl_get_devt (dfl_devs[fdata->type].devt_type, fdev->id); +dfl_fpga_dev_for_each_feature (fdata, feature) + feature->dev = fdev; + ret =platform_device_add_resources (fdev, fdata->resources, fdata->resource_num);if (ret) -return ret; + goto err_put_dev; pdata.fdata = fdata; ret =platform_device_add_data (fdev, &pdata,sizeof (pdata));if (ret) -return ret; + goto err_put_dev; ret =platform_device_add (fdev);if (ret) -return ret; + goto err_put_dev;
Quoted 7 lines
drivers/fpga/dfl.c build_info_create_dev(struct build_feature_devs_info *binfo) · line 913
Quoted 5 lines
drivers/fpga/dfl.c +4
-0return 0 ; + +err_put_dev: +platform_device_put (fdev); + fdata->dev =NULL ;Do we also need to clean up all the
feature->dev?
Yes, thank you for the suggestion. It is not needed for functional correctness since feature->dev is exclusively used when non-NULL, but it seems a good idea for consistency.
Thanks,
Peter
Quoted 50 lines
Thanks,
YilunQuoted 46 lines
drivers/fpga/dfl.c +4
-14+ +return ret; }static void feature_dev_unregister (struct dfl_feature_dev_data *fdata)@@ -940,16 +937,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)if (binfo->type ==PORT_ID )dfl_fpga_cdev_add_port_data (binfo->cdev, fdata);else - binfo->cdev->fme_dev =get_device (&binfo->feature_dev->dev); - -/* -* reset it to avoid build_info_free() freeing their resource. -* -* The resource of successfully registered feature devices -* will be freed by platform_device_unregister(). See the -* comments in build_info_create_dev(). -*/ - binfo->feature_dev =NULL ; + binfo->cdev->fme_dev =get_device (&fdata->dev->dev);/* reset the binfo for next FIU */ binfo->type =DFL_ID_MAX ;@@ -966,8 +954,6 @@ static void build_info_free(struct build_feature_devs_info *binfo)kfree (finfo); } -platform_device_put (binfo->feature_dev); -devm_kfree (binfo->dev, binfo); }@@ -1262,8 +1248,7 @@ static int parse_feature_afu(struct build_feature_devs_info *binfo,case PORT_ID :return parse_feature_port_afu (binfo, ofst);default : -dev_info (binfo->dev,"AFU belonging to FIU %s is not supported yet.\n" , - binfo->feature_dev->name); +dev_info (binfo->dev,"AFU belonging to FIU is not supported yet.\n" ); }return 0 ;Signature · 1 line
2.47.0
Re: [PATCH v4 16/19] fpga: dfl: allocate platform device after feature device data
Quoted 136 lines · Peter
Quoted 127 lines · Xu Yilun
Quoted 126 lines · Peter Colberg
Delay calling
platform_device_alloc()frombuild_info_create_dev()tofeature_dev_register(), now that the feature device data contains all necessary data to create the feature device. This completes the new functionfeature_dev_register(), which will be reused in a subsequent commit to fully recreate the feature device when assigning a port.Signed-off-by Peter Colberg <[email protected]>Reviewed-by Matthew Gerlach <[email protected]>Reviewed-by Basheer Ahmed Muddebihal <[email protected]>---
Changes since v3:
- New patch extracted from last patch of v3 series.--- drivers/fpga/dfl.c | 59 +++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 37 deletions(-)drivers/fpga/dfl.c +14
-23@@ -681,7 +681,6 @@ EXPORT_SYMBOL_GPL(dfl_fpga_dev_ops_unregister);* @nr_irqs: number of irqs for all feature devices. * @irq_table: Linux IRQ numbers for all irqs, indexed by local irq index of * this device. -* @feature_dev: current feature device. * @type: the current FIU type. * @ioaddr: header register region address of current FIU in enumeration. * @start: register resource start of current FIU. @@ -695,7 +694,6 @@ struct build_feature_devs_info {unsigned int nr_irqs;int *irq_table; -struct platform_device *feature_dev;enum dfl_id_type type;void __iomem *ioaddr;resource_size_t start;@@ -750,7 +748,6 @@ static void dfl_id_free_action(void *arg)static struct dfl_feature_dev_data *binfo_create_feature_dev_data (struct build_feature_devs_info *binfo) { -struct platform_device *fdev = binfo->feature_dev;enum dfl_id_type type = binfo->type;struct dfl_feature_info *finfo, *p;struct dfl_feature_dev_data *fdata;@@ -773,7 +770,6 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)if (!fdata->resources)return ERR_PTR (-ENOMEM ); - fdata->dev = fdev; fdata->type = type; fdata->pdev_id =dfl_id_alloc (type, binfo->dev);@@ -784,8 +780,6 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)if (ret)return ERR_PTR (ret); - fdev->id = fdata->pdev_id; - fdata->pdev_name = dfl_devs[type].name; fdata->num = binfo->feature_num; fdata->dfl_cdev = binfo->cdev;@@ -809,7 +803,6 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)unsigned int i;/* save resource information for each feature */ - feature->dev = fdev; feature->id = finfo->fid; feature->revision = finfo->revision; feature->dfh_version = finfo->dfh_version;@@ -868,18 +861,6 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)static int build_info_create_dev (struct build_feature_devs_info *binfo) { -enum dfl_id_type type = binfo->type; -struct platform_device *fdev; - -/* -* we use -ENODEV as the initialization indicator which indicates -* whether the id need to be reclaimed -*/ - fdev =platform_device_alloc (dfl_devs[type].name, -ENODEV ); -if (!fdev) -return -ENOMEM ; - - binfo->feature_dev = fdev; binfo->feature_num =0 ;INIT_LIST_HEAD (&binfo->sub_features);@@ -895,27 +876,43 @@ build_info_create_dev(struct build_feature_devs_info *binfo)static int feature_dev_register (struct dfl_feature_dev_data *fdata) {struct dfl_feature_platform_data pdata = {}; -struct platform_device *fdev = fdata->dev; +struct platform_device *fdev; +struct dfl_feature *feature;int ret; + fdev =platform_device_alloc (fdata->pdev_name, fdata->pdev_id); +if (!fdev) +return -ENOMEM ; + + fdata->dev = fdev; + fdev->dev.parent = &fdata->dfl_cdev->region->dev; fdev->dev.devt =dfl_get_devt (dfl_devs[fdata->type].devt_type, fdev->id); +dfl_fpga_dev_for_each_feature (fdata, feature) + feature->dev = fdev; + ret =platform_device_add_resources (fdev, fdata->resources, fdata->resource_num);if (ret) -return ret; + goto err_put_dev; pdata.fdata = fdata; ret =platform_device_add_data (fdev, &pdata,sizeof (pdata));if (ret) -return ret; + goto err_put_dev; ret =platform_device_add (fdev);if (ret) -return ret; + goto err_put_dev;Quoted 7 lines
drivers/fpga/dfl.c build_info_create_dev(struct build_feature_devs_info *binfo) · line 913
Quoted 5 lines
drivers/fpga/dfl.c +4
-0return 0 ; + +err_put_dev: +platform_device_put (fdev); + fdata->dev =NULL ;Do we also need to clean up all the
feature->dev?
Quoted 3 lines
Yes, thank you for the suggestion. It is not needed for functional correctness since
feature->devis exclusively used when non-NULL, but it seems a good idea for consistency.
This has been implemented in [PATCH v5 15/18].
Thanks,
Peter
Quoted 55 lines
Thanks,
PeterQuoted 50 lines
Thanks,
YilunQuoted 46 lines
drivers/fpga/dfl.c +4
-14+ +return ret; }static void feature_dev_unregister (struct dfl_feature_dev_data *fdata)@@ -940,16 +937,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)if (binfo->type ==PORT_ID )dfl_fpga_cdev_add_port_data (binfo->cdev, fdata);else - binfo->cdev->fme_dev =get_device (&binfo->feature_dev->dev); - -/* -* reset it to avoid build_info_free() freeing their resource. -* -* The resource of successfully registered feature devices -* will be freed by platform_device_unregister(). See the -* comments in build_info_create_dev(). -*/ - binfo->feature_dev =NULL ; + binfo->cdev->fme_dev =get_device (&fdata->dev->dev);/* reset the binfo for next FIU */ binfo->type =DFL_ID_MAX ;@@ -966,8 +954,6 @@ static void build_info_free(struct build_feature_devs_info *binfo)kfree (finfo); } -platform_device_put (binfo->feature_dev); -devm_kfree (binfo->dev, binfo); }@@ -1262,8 +1248,7 @@ static int parse_feature_afu(struct build_feature_devs_info *binfo,case PORT_ID :return parse_feature_port_afu (binfo, ofst);default : -dev_info (binfo->dev,"AFU belonging to FIU %s is not supported yet.\n" , - binfo->feature_dev->name); +dev_info (binfo->dev,"AFU belonging to FIU is not supported yet.\n" ); }return 0 ;Signature · 1 line
2.47.0
PATCH v4 17/19 fpga: dfl: remove unneeded function build_info_create_dev()
In reply to Peter ColbergNow that the platform device allocation has been moved from build_info_create_dev() to feature_dev_register(), the former no longer serves its original purpose and may be removed.
---
Changes since v3:
- New patch extracted from last patch of v3 series.
--- drivers/fpga/dfl.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-)
drivers/fpga/dfl.c +2 -15
@@ -858,16 +858,6 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)return fdata; } -static int -build_info_create_dev (struct build_feature_devs_info *binfo) -{ - binfo->feature_num =0 ; - -INIT_LIST_HEAD (&binfo->sub_features); - -return 0 ; -} -/* * register current feature device, it is called when we need to switch to * another feature parsing or we have parsed all features on given device
@@ -1316,11 +1306,8 @@ static int parse_feature_fiu(struct build_feature_devs_info *binfo,return -EINVAL ; binfo->type = type; - -/* create platform device for dfl feature dev */ - ret =build_info_create_dev (binfo); -if (ret) -return ret; + binfo->feature_num =0 ; +INIT_LIST_HEAD (&binfo->sub_features); ret =create_feature_instance (binfo,0 ,0 ,0 );if (ret)
Signature · 1 line
2.47.0
Re: [PATCH v4 17/19] fpga: dfl: remove unneeded function build_info_create_dev()
Quoted 3 lines · Peter Colberg
Now that the platform device allocation has been moved from
build_info_create_dev()tofeature_dev_register(), the former no longer serves its original purpose and may be removed.
may be removed? It is removed in this patch, please be confirmative.
Thanks,
Yilun
Quoted 50 lines
Signed-off-by Peter Colberg <[email protected]>Reviewed-by Matthew Gerlach <[email protected]>Reviewed-by Basheer Ahmed Muddebihal <[email protected]>---
Changes since v3:
- New patch extracted from last patch of v3 series.--- drivers/fpga/dfl.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-)drivers/fpga/dfl.c +2
-15@@ -858,16 +858,6 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)return fdata; } -static int -build_info_create_dev (struct build_feature_devs_info *binfo) -{ - binfo->feature_num =0 ; - -INIT_LIST_HEAD (&binfo->sub_features); - -return 0 ; -} -/* * register current feature device, it is called when we need to switch to * another feature parsing or we have parsed all features on given device @@ -1316,11 +1306,8 @@ static int parse_feature_fiu(struct build_feature_devs_info *binfo,return -EINVAL ; binfo->type = type; - -/* create platform device for dfl feature dev */ - ret =build_info_create_dev (binfo); -if (ret) -return ret; + binfo->feature_num =0 ; +INIT_LIST_HEAD (&binfo->sub_features); ret =create_feature_instance (binfo,0 ,0 ,0 );if (ret)Signature · 1 line
2.47.0
Re: [PATCH v4 17/19] fpga: dfl: remove unneeded function build_info_create_dev()
Quoted 6 lines · Xu Yilun
Quoted 3 lines · Peter Colberg
Now that the platform device allocation has been moved from
build_info_create_dev()tofeature_dev_register(), the former no longer serves its original purpose and may be removed.may be removed? It is removed in this patch, please be confirmative.
The commit description has been revised in [PATCH v5 16/18].
Thanks,
Peter
Quoted 54 lines
Thanks,
YilunQuoted 50 lines
Signed-off-by Peter Colberg <[email protected]>Reviewed-by Matthew Gerlach <[email protected]>Reviewed-by Basheer Ahmed Muddebihal <[email protected]>---
Changes since v3:
- New patch extracted from last patch of v3 series.--- drivers/fpga/dfl.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-)drivers/fpga/dfl.c +2
-15@@ -858,16 +858,6 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)return fdata; } -static int -build_info_create_dev (struct build_feature_devs_info *binfo) -{ - binfo->feature_num =0 ; - -INIT_LIST_HEAD (&binfo->sub_features); - -return 0 ; -} -/* * register current feature device, it is called when we need to switch to * another feature parsing or we have parsed all features on given device @@ -1316,11 +1306,8 @@ static int parse_feature_fiu(struct build_feature_devs_info *binfo,return -EINVAL ; binfo->type = type; - -/* create platform device for dfl feature dev */ - ret =build_info_create_dev (binfo); -if (ret) -return ret; + binfo->feature_num =0 ; +INIT_LIST_HEAD (&binfo->sub_features); ret =create_feature_instance (binfo,0 ,0 ,0 );if (ret)Signature · 1 line
2.47.0
PATCH v4 18/19 fpga: dfl: drop unneeded get_device() and put_device() of feature device
In reply to Peter ColbergThe feature device data was originally stored as platform data, hence the memory allocation was tied to the lifetime of the feature device. Now that the feature device data is tied to the lifetime of the DFL PCIe FPGA device instead, get_device() and put_device() are no longer needed.
---
Changes since v3:
- New patch extracted from last patch of v3 series.
--- drivers/fpga/dfl-fme-br.c | 2 -- drivers/fpga/dfl.c | 16 +++++----------- drivers/fpga/dfl.h | 5 ----- 3 files changed, 5 insertions(+), 18 deletions(-)
drivers/fpga/dfl-fme-br.c +0 -2
@@ -85,8 +85,6 @@ static void fme_br_remove(struct platform_device *pdev)fpga_bridge_unregister (br); -if (priv->port_fdata) -put_device (&priv->port_fdata->dev->dev);if (priv->port_ops)dfl_fpga_port_ops_put (priv->port_ops); }
drivers/fpga/dfl.c +5 -11
@@ -734,7 +734,6 @@ static void dfl_fpga_cdev_add_port_data(struct dfl_fpga_cdev *cdev, {mutex_lock (&cdev->lock);list_add (&fdata->node, &cdev->port_dev_list); -get_device (&fdata->dev->dev);mutex_unlock (&cdev->lock); }
@@ -1636,7 +1635,6 @@ void dfl_fpga_feature_devs_remove(struct dfl_fpga_cdev *cdev) }list_del (&fdata->node); -put_device (&port_dev->dev); }mutex_unlock (&cdev->lock);
@@ -1668,7 +1666,7 @@ __dfl_fpga_cdev_find_port_data(struct dfl_fpga_cdev *cdev, void *data,struct dfl_feature_dev_data *fdata;list_for_each_entry (fdata, &cdev->port_dev_list, node) { -if (match (fdata, data) &&get_device (&fdata->dev->dev)) +if (match (fdata, data))return fdata; }
@@ -1719,19 +1717,17 @@ int dfl_fpga_cdev_release_port(struct dfl_fpga_cdev *cdev, int port_id)if (!device_is_registered (&fdata->dev->dev)) { ret = -EBUSY ; - goto put_dev_exit; + goto unlock_exit; }mutex_lock (&fdata->lock); ret =dfl_feature_dev_use_begin (fdata, true);mutex_unlock (&fdata->lock);if (ret) - goto put_dev_exit; + goto unlock_exit;platform_device_del (fdata->dev); cdev->released_port_num++; -put_dev_exit: -put_device (&fdata->dev->dev); unlock_exit:mutex_unlock (&cdev->lock);return ret;
@@ -1762,20 +1758,18 @@ int dfl_fpga_cdev_assign_port(struct dfl_fpga_cdev *cdev, int port_id)if (device_is_registered (&fdata->dev->dev)) { ret = -EBUSY ; - goto put_dev_exit; + goto unlock_exit; } ret =platform_device_add (fdata->dev);if (ret) - goto put_dev_exit; + goto unlock_exit;mutex_lock (&fdata->lock);dfl_feature_dev_use_end (fdata);mutex_unlock (&fdata->lock); cdev->released_port_num--; -put_dev_exit: -put_device (&fdata->dev->dev); unlock_exit:mutex_unlock (&cdev->lock);return ret;
drivers/fpga/dfl.h +0 -5
@@ -551,11 +551,6 @@ struct dfl_fpga_cdev * dfl_fpga_feature_devs_enumerate(struct dfl_fpga_enum_info *info);void dfl_fpga_feature_devs_remove (struct dfl_fpga_cdev *cdev); -/* -* need to drop the device reference with put_device() after use port platform -* device returned by __dfl_fpga_cdev_find_port and dfl_fpga_cdev_find_port -* functions. -*/ struct dfl_feature_dev_data *__dfl_fpga_cdev_find_port_data (struct dfl_fpga_cdev *cdev,void *data,int (*match)(struct dfl_feature_dev_data *,void *));
Signature · 1 line
2.47.0
Re: [PATCH v4 18/19] fpga: dfl: drop unneeded get_device() and put_device() of feature device
Quoted 2 lines · Peter Colberg
The feature device data was originally stored as platform data, hence the memory allocation was tied to the lifetime of the feature device.
Good to know the reason.
Thanks,
Yilun
PATCH v4 19/19 fpga: dfl: destroy/recreate feature platform device on port release/assign
In reply to Peter ColbergFrom: Xu Yilun <[email protected]>
Now that the internal DFL APIs have been converted to consume DFL enumeration info from a separate structure, dfl_feature_dev_data, which lifetime is independent of the feature device, proceed to completely destroy and recreate the feature platform device on port release and assign, respectively. This resolves a longstanding issue in the use of platform_device_add(), which states to "not call this routine more than once for any device structure" and which used to print a kernel warning.
The function feature_dev_unregister() resets the device pointer in the feature data to NULL to signal that the feature platform device has been destroyed. This substitutes the previous device_is_registered() checks.
---
Changes since v3:
- New patch extracted from last patch of v3 series.
--- drivers/fpga/dfl.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-)
drivers/fpga/dfl.c +6 -18
@@ -1620,22 +1620,10 @@ EXPORT_SYMBOL_GPL(dfl_fpga_feature_devs_enumerate);*/ void dfl_fpga_feature_devs_remove (struct dfl_fpga_cdev *cdev) { -struct dfl_feature_dev_data *fdata, *ptmp; -mutex_lock (&cdev->lock);if (cdev->fme_dev)put_device (cdev->fme_dev); -list_for_each_entry_safe (fdata, ptmp, &cdev->port_dev_list, node) { -struct platform_device *port_dev = fdata->dev; - -/* remove released ports */ -if (!device_is_registered (&port_dev->dev)) { -platform_device_put (port_dev); - } - -list_del (&fdata->node); - }mutex_unlock (&cdev->lock);remove_feature_devs (cdev);
@@ -1715,7 +1703,7 @@ int dfl_fpga_cdev_release_port(struct dfl_fpga_cdev *cdev, int port_id)if (!fdata) goto unlock_exit; -if (!device_is_registered (&fdata->dev->dev)) { +if (!fdata->dev) { ret = -EBUSY ; goto unlock_exit; }
@@ -1726,7 +1714,7 @@ int dfl_fpga_cdev_release_port(struct dfl_fpga_cdev *cdev, int port_id)if (ret) goto unlock_exit; -platform_device_del (fdata->dev); +feature_dev_unregister (fdata); cdev->released_port_num++; unlock_exit:mutex_unlock (&cdev->lock);
@@ -1756,12 +1744,12 @@ int dfl_fpga_cdev_assign_port(struct dfl_fpga_cdev *cdev, int port_id)if (!fdata) goto unlock_exit; -if (device_is_registered (&fdata->dev->dev)) { +if (fdata->dev) { ret = -EBUSY ; goto unlock_exit; } - ret =platform_device_add (fdata->dev); + ret =feature_dev_register (fdata);if (ret) goto unlock_exit;
@@ -1811,7 +1799,7 @@ void dfl_fpga_cdev_config_ports_pf(struct dfl_fpga_cdev *cdev)mutex_lock (&cdev->lock);list_for_each_entry (fdata, &cdev->port_dev_list, node) { -if (device_is_registered (&fdata->dev->dev)) +if (fdata->dev)continue ;config_port_pf_mode (cdev->fme_dev, fdata->id);
@@ -1848,7 +1836,7 @@ int dfl_fpga_cdev_config_ports_vf(struct dfl_fpga_cdev *cdev, int num_vfs) }list_for_each_entry (fdata, &cdev->port_dev_list, node) { -if (device_is_registered (&fdata->dev->dev)) +if (fdata->dev)continue ;config_port_vf_mode (cdev->fme_dev, fdata->id);
Signature · 1 line
2.47.0
Re: [PATCH v4 19/19] fpga: dfl: destroy/recreate feature platform device on port release/assign
Quoted 10 lines · Peter Colberg
From: Xu Yilun <[email protected]>
Now that the internal DFL APIs have been converted to consume DFL enumeration info from a separate structure,
dfl_feature_dev_data, which lifetime is independent of the feature device, proceed to completely destroy and recreate the feature platform device on port release and assign, respectively. This resolves a longstanding issue in the use ofplatform_device_add(), which states to "not call this routine more than once for any device structure" and which used to print a kernel warning.
Quoted 3 lines
The function
feature_dev_unregister()resets the device pointer in the feature data to NULL to signal that the feature platform device has been destroyed. This substitutes the previousdevice_is_registered()checks.
for this patch and all other patches that I didn't comment in this series.
Thanks.
Quoted 6 lines
Signed-off-by Xu Yilun <[email protected]>Signed-off-by Russ Weight <[email protected]>Signed-off-by Peter Colberg <[email protected]>Reviewed-by Matthew Gerlach <[email protected]>Reviewed-by Basheer Ahmed Muddebihal <[email protected]>
Re: [PATCH v4 19/19] fpga: dfl: destroy/recreate feature platform device on port release/assign
Quoted 11 lines · Xu Yilun
Quoted 10 lines · Peter Colberg
From: Xu Yilun <[email protected]>
Now that the internal DFL APIs have been converted to consume DFL enumeration info from a separate structure,
dfl_feature_dev_data, which lifetime is independent of the feature device, proceed to completely destroy and recreate the feature platform device on port release and assign, respectively. This resolves a longstanding issue in the use ofplatform_device_add(), which states to "not call this routine more than once for any device structure" and which used to print a kernel warning.
Quoted 8 lines
Quoted 3 lines
The function
feature_dev_unregister()resets the device pointer in the feature data to NULL to signal that the feature platform device has been destroyed. This substitutes the previousdevice_is_registered()checks.Acked-by Xu Yilun <[email protected]>for this patch and all other patches that I didn't comment in this series.
Thank you for the thorough review and your guidance in converting this change into a series of small patches that are easy to reason about.
Peter
Quoted 9 lines
Thanks.
Quoted 6 lines
Signed-off-by Xu Yilun <[email protected]>Signed-off-by Russ Weight <[email protected]>Signed-off-by Peter Colberg <[email protected]>Reviewed-by Matthew Gerlach <[email protected]>Reviewed-by Basheer Ahmed Muddebihal <[email protected]>