[v1] raw/ifpga: check afu device before unplug

Message ID 20230326214134.782428-1-wei.huang@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v1] raw/ifpga: check afu device before unplug |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-unit-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS

Commit Message

Wei Huang March 26, 2023, 9:41 p.m. UTC
  AFU device may be already unplugged in IFPGA bus cleanup process,
unplug AFU device only when it exists.

Signed-off-by: Wei Huang <wei.huang@intel.com>
---
 drivers/raw/ifpga/ifpga_rawdev.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
  

Comments

Zhang, Tianfei March 30, 2023, 9:06 a.m. UTC | #1
> -----Original Message-----
> From: Huang, Wei <wei.huang@intel.com>
> Sent: Monday, March 27, 2023 5:42 AM
> To: dev@dpdk.org; thomas@monjalon.net; david.marchand@redhat.com
> Cc: stable@dpdk.org; Xu, Rosen <rosen.xu@intel.com>; Zhang, Tianfei
> <tianfei.zhang@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>; Huang, Wei
> <wei.huang@intel.com>
> Subject: [PATCH v1] raw/ifpga: check afu device before unplug
> 
> AFU device may be already unplugged in IFPGA bus cleanup process, unplug AFU
> device only when it exists.
> 
> Signed-off-by: Wei Huang <wei.huang@intel.com>
> ---
>  drivers/raw/ifpga/ifpga_rawdev.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c
> index 1020adc..0d43c87 100644
> --- a/drivers/raw/ifpga/ifpga_rawdev.c
> +++ b/drivers/raw/ifpga/ifpga_rawdev.c
> @@ -29,6 +29,7 @@
>  #include <bus_vdev_driver.h>
>  #include <rte_string_fns.h>
>  #include <rte_pmd_i40e.h>
> +#include <bus_driver.h>
> 
>  #include "base/opae_hw_api.h"
>  #include "base/opae_ifpga_hw_api.h"
> @@ -1832,12 +1833,19 @@ static int ifpga_rawdev_get_string_arg(const char *key
> __rte_unused,
>  	return ret;
>  }
> 
> +static int cmp_dev_name(const struct rte_device *dev, const void
> +*_name) {
> +	const char *name = _name;
> +	return strcmp(dev->name, name);
> +}
> +
>  static int
>  ifpga_cfg_remove(struct rte_vdev_device *vdev)  {
>  	struct rte_rawdev *rawdev = NULL;
>  	struct ifpga_rawdev *ifpga_dev;
>  	struct ifpga_vdev_args args;
> +	struct rte_bus *bus;
>  	char dev_name[RTE_RAWDEV_NAME_MAX_LEN];
>  	const char *vdev_name = NULL;
>  	char *tmp_vdev = NULL;
> @@ -1864,7 +1872,13 @@ static int ifpga_rawdev_get_string_arg(const char *key
> __rte_unused,
> 
>  	snprintf(dev_name, RTE_RAWDEV_NAME_MAX_LEN, "%d|%s",
>  		args.port, args.bdf);
> -	ret = rte_eal_hotplug_remove(RTE_STR(IFPGA_BUS_NAME), dev_name);
> +	bus = rte_bus_find_by_name(RTE_STR(IFPGA_BUS_NAME));
> +	if (bus) {
> +		if (bus->find_device(NULL, cmp_dev_name, dev_name)) {
> +			ret =
> rte_eal_hotplug_remove(RTE_STR(IFPGA_BUS_NAME),
> +				dev_name);
> +		}
> +	}
> 

It looks good for me.
Acked-by: Tianfei Zhang <tianfei.zhang@intel.com>
  
Xu, Rosen May 3, 2023, 5:19 a.m. UTC | #2
Hi,

> -----Original Message-----
> From: Huang, Wei <wei.huang@intel.com>
> Sent: Monday, March 27, 2023 5:42 AM
> To: dev@dpdk.org; thomas@monjalon.net; david.marchand@redhat.com
> Cc: stable@dpdk.org; Xu, Rosen <rosen.xu@intel.com>; Zhang, Tianfei
> <tianfei.zhang@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>; Huang, Wei
> <wei.huang@intel.com>
> Subject: [PATCH v1] raw/ifpga: check afu device before unplug
> 
> AFU device may be already unplugged in IFPGA bus cleanup process, unplug
> AFU device only when it exists.
> 
> Signed-off-by: Wei Huang <wei.huang@intel.com>
> ---
>  drivers/raw/ifpga/ifpga_rawdev.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/raw/ifpga/ifpga_rawdev.c
> b/drivers/raw/ifpga/ifpga_rawdev.c
> index 1020adc..0d43c87 100644
> --- a/drivers/raw/ifpga/ifpga_rawdev.c
> +++ b/drivers/raw/ifpga/ifpga_rawdev.c
> @@ -29,6 +29,7 @@
>  #include <bus_vdev_driver.h>
>  #include <rte_string_fns.h>
>  #include <rte_pmd_i40e.h>
> +#include <bus_driver.h>
> 
>  #include "base/opae_hw_api.h"
>  #include "base/opae_ifpga_hw_api.h"
> @@ -1832,12 +1833,19 @@ static int ifpga_rawdev_get_string_arg(const
> char *key __rte_unused,
>  	return ret;
>  }
> 
> +static int cmp_dev_name(const struct rte_device *dev, const void
> +*_name) {
> +	const char *name = _name;
> +	return strcmp(dev->name, name);
> +}
> +
>  static int
>  ifpga_cfg_remove(struct rte_vdev_device *vdev)  {
>  	struct rte_rawdev *rawdev = NULL;
>  	struct ifpga_rawdev *ifpga_dev;
>  	struct ifpga_vdev_args args;
> +	struct rte_bus *bus;
>  	char dev_name[RTE_RAWDEV_NAME_MAX_LEN];
>  	const char *vdev_name = NULL;
>  	char *tmp_vdev = NULL;
> @@ -1864,7 +1872,13 @@ static int ifpga_rawdev_get_string_arg(const char
> *key __rte_unused,
> 
>  	snprintf(dev_name, RTE_RAWDEV_NAME_MAX_LEN, "%d|%s",
>  		args.port, args.bdf);
> -	ret = rte_eal_hotplug_remove(RTE_STR(IFPGA_BUS_NAME),
> dev_name);
> +	bus = rte_bus_find_by_name(RTE_STR(IFPGA_BUS_NAME));
> +	if (bus) {
> +		if (bus->find_device(NULL, cmp_dev_name, dev_name)) {
> +			ret =
> rte_eal_hotplug_remove(RTE_STR(IFPGA_BUS_NAME),
> +				dev_name);
> +		}
> +	}
> 
>  	for (i = 0; i < IFPGA_MAX_VDEV; i++) {
>  		tmp_vdev = ifpga_dev->vdev_name[i];
> --
> 1.8.3.1

Reviewed-by: Rosen Xu <rosen.xu@intel.com>
  
Thomas Monjalon June 12, 2023, 8:30 p.m. UTC | #3
> > AFU device may be already unplugged in IFPGA bus cleanup process, unplug AFU
> > device only when it exists.
> > 
> > Signed-off-by: Wei Huang <wei.huang@intel.com>
> 
> It looks good for me.
> Acked-by: Tianfei Zhang <tianfei.zhang@intel.com>

Applied, thanks.
  

Patch

diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c
index 1020adc..0d43c87 100644
--- a/drivers/raw/ifpga/ifpga_rawdev.c
+++ b/drivers/raw/ifpga/ifpga_rawdev.c
@@ -29,6 +29,7 @@ 
 #include <bus_vdev_driver.h>
 #include <rte_string_fns.h>
 #include <rte_pmd_i40e.h>
+#include <bus_driver.h>
 
 #include "base/opae_hw_api.h"
 #include "base/opae_ifpga_hw_api.h"
@@ -1832,12 +1833,19 @@  static int ifpga_rawdev_get_string_arg(const char *key __rte_unused,
 	return ret;
 }
 
+static int cmp_dev_name(const struct rte_device *dev, const void *_name)
+{
+	const char *name = _name;
+	return strcmp(dev->name, name);
+}
+
 static int
 ifpga_cfg_remove(struct rte_vdev_device *vdev)
 {
 	struct rte_rawdev *rawdev = NULL;
 	struct ifpga_rawdev *ifpga_dev;
 	struct ifpga_vdev_args args;
+	struct rte_bus *bus;
 	char dev_name[RTE_RAWDEV_NAME_MAX_LEN];
 	const char *vdev_name = NULL;
 	char *tmp_vdev = NULL;
@@ -1864,7 +1872,13 @@  static int ifpga_rawdev_get_string_arg(const char *key __rte_unused,
 
 	snprintf(dev_name, RTE_RAWDEV_NAME_MAX_LEN, "%d|%s",
 		args.port, args.bdf);
-	ret = rte_eal_hotplug_remove(RTE_STR(IFPGA_BUS_NAME), dev_name);
+	bus = rte_bus_find_by_name(RTE_STR(IFPGA_BUS_NAME));
+	if (bus) {
+		if (bus->find_device(NULL, cmp_dev_name, dev_name)) {
+			ret = rte_eal_hotplug_remove(RTE_STR(IFPGA_BUS_NAME),
+				dev_name);
+		}
+	}
 
 	for (i = 0; i < IFPGA_MAX_VDEV; i++) {
 		tmp_vdev = ifpga_dev->vdev_name[i];