[v1] raw/ifpga: remove virtual device unplug operation

Message ID 20230316204445.360330-1-wei.huang@intel.com (mailing list archive)
State Rejected, archived
Delegated to: Thomas Monjalon
Headers
Series [v1] raw/ifpga: remove virtual device unplug operation |

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-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance fail Performance Testing issues
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS

Commit Message

Wei Huang March 16, 2023, 8:44 p.m. UTC
  VDEV bus has implemented cleanup() function to perform cleanup for
devices on the bus during eal_cleanup(), so there is no need for
ifpga driver to record virtual devices and unplug them.

Signed-off-by: Wei Huang <wei.huang@intel.com>
---
 drivers/raw/ifpga/ifpga_rawdev.c | 99 ++++------------------------------------
 drivers/raw/ifpga/ifpga_rawdev.h |  2 -
 2 files changed, 9 insertions(+), 92 deletions(-)
  

Comments

Xu, Rosen March 20, 2023, 6:51 a.m. UTC | #1
Hi,

> -----Original Message-----
> From: Huang, Wei <wei.huang@intel.com>
> Sent: Friday, March 17, 2023 4:45 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: remove virtual device unplug operation
> 
> VDEV bus has implemented cleanup() function to perform cleanup for
> devices on the bus during eal_cleanup(), so there is no need for ifpga driver
> to record virtual devices and unplug them.
> 
> Signed-off-by: Wei Huang <wei.huang@intel.com>
> ---
>  drivers/raw/ifpga/ifpga_rawdev.c | 99 ++++------------------------------------
>  drivers/raw/ifpga/ifpga_rawdev.h |  2 -
>  2 files changed, 9 insertions(+), 92 deletions(-)
> 
> diff --git a/drivers/raw/ifpga/ifpga_rawdev.c
> b/drivers/raw/ifpga/ifpga_rawdev.c
> index 1020adc..8e6e70f 100644
> --- a/drivers/raw/ifpga/ifpga_rawdev.c
> +++ b/drivers/raw/ifpga/ifpga_rawdev.c
> @@ -140,8 +140,6 @@ struct ifpga_rawdev *
>  	for (i = 0; i < IFPGA_MAX_IRQ; i++)
>  		dev->intr_handle[i] = NULL;
>  	dev->poll_enabled = 0;
> -	for (i = 0; i < IFPGA_MAX_VDEV; i++)
> -		dev->vdev_name[i] = NULL;
> 
>  	return dev;
>  }
> @@ -749,17 +747,11 @@ static int set_surprise_link_check_aer(
>  	struct ifpga_rawdev *ifpga_rdev = NULL;
>  	struct opae_adapter *adapter;
>  	struct opae_manager *mgr;
> -	char *vdev_name = NULL;
> -	int i, ret = 0;
> +	int ret = 0;
> 
>  	if (dev) {
>  		ifpga_rdev = ifpga_rawdev_get(dev);
>  		if (ifpga_rdev) {
> -			for (i = 0; i < IFPGA_MAX_VDEV; i++) {
> -				vdev_name = ifpga_rdev->vdev_name[i];
> -				if (vdev_name)
> -					rte_vdev_uninit(vdev_name);
> -			}
>  			ifpga_monitor_stop_func(ifpga_rdev);
>  			ifpga_rdev->rawdev = NULL;
>  		}
> @@ -1778,104 +1770,31 @@ static int ifpga_rawdev_get_string_arg(const
> char *key __rte_unused,  static int  ifpga_cfg_probe(struct rte_vdev_device
> *vdev)  {
> -	struct rte_rawdev *rawdev = NULL;
> -	struct ifpga_rawdev *ifpga_dev;
>  	struct ifpga_vdev_args args;
>  	char dev_name[RTE_RAWDEV_NAME_MAX_LEN];
> -	const char *vdev_name = NULL;
> -	int i, n, ret = 0;
> -
> -	vdev_name = rte_vdev_device_name(vdev);
> -	if (!vdev_name)
> -		return -EINVAL;
> +	int ret = 0;
> 
> -	IFPGA_RAWDEV_PMD_INFO("probe ifpga virtual device %s",
> vdev_name);
> +	IFPGA_RAWDEV_PMD_INFO("probe ifpga virtual device %s",
> +		rte_vdev_device_name(vdev));
> 
>  	ret = ifpga_vdev_parse_devargs(vdev->device.devargs, &args);
>  	if (ret)
>  		return ret;
> 
>  	memset(dev_name, 0, sizeof(dev_name));
> -	snprintf(dev_name, RTE_RAWDEV_NAME_MAX_LEN, "IFPGA:%s",
> args.bdf);
> -	rawdev = rte_rawdev_pmd_get_named_dev(dev_name);
> -	if (!rawdev)
> -		return -ENODEV;
> -	ifpga_dev = ifpga_rawdev_get(rawdev);
> -	if (!ifpga_dev)
> -		return -ENODEV;
> -
> -	for (i = 0; i < IFPGA_MAX_VDEV; i++) {
> -		if (ifpga_dev->vdev_name[i] == NULL) {
> -			n = strlen(vdev_name) + 1;
> -			ifpga_dev->vdev_name[i] = rte_malloc(NULL, n, 0);
> -			if (ifpga_dev->vdev_name[i] == NULL)
> -				return -ENOMEM;
> -			strlcpy(ifpga_dev->vdev_name[i], vdev_name, n);
> -			break;
> -		}
> -	}
> -
> -	if (i >= IFPGA_MAX_VDEV) {
> -		IFPGA_RAWDEV_PMD_ERR("Can't create more virtual
> device!");
> -		return -ENOENT;
> -	}
> -
>  	snprintf(dev_name, RTE_RAWDEV_NAME_MAX_LEN, "%d|%s",
>  		args.port, args.bdf);
> -	ret = rte_eal_hotplug_add(RTE_STR(IFPGA_BUS_NAME),
> -			dev_name, vdev->device.devargs->args);
> -	if (ret) {
> -		rte_free(ifpga_dev->vdev_name[i]);
> -		ifpga_dev->vdev_name[i] = NULL;
> -	}
> -
> -	return ret;
> +	return rte_eal_hotplug_add(RTE_STR(IFPGA_BUS_NAME),
> dev_name,
> +			vdev->device.devargs->args);
>  }
> 
>  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;
> -	char dev_name[RTE_RAWDEV_NAME_MAX_LEN];
> -	const char *vdev_name = NULL;
> -	char *tmp_vdev = NULL;
> -	int i, ret = 0;
> -
> -	vdev_name = rte_vdev_device_name(vdev);
> -	if (!vdev_name)
> -		return -EINVAL;
> +	IFPGA_RAWDEV_PMD_INFO("remove ifpga virtual device %s",
> +		rte_vdev_device_name(vdev));
> 
> -	IFPGA_RAWDEV_PMD_INFO("remove ifpga virtual device %s",
> vdev_name);
> -
> -	ret = ifpga_vdev_parse_devargs(vdev->device.devargs, &args);
> -	if (ret)
> -		return ret;
> -
> -	memset(dev_name, 0, sizeof(dev_name));
> -	snprintf(dev_name, RTE_RAWDEV_NAME_MAX_LEN, "IFPGA:%s",
> args.bdf);
> -	rawdev = rte_rawdev_pmd_get_named_dev(dev_name);
> -	if (!rawdev)
> -		return -ENODEV;
> -	ifpga_dev = ifpga_rawdev_get(rawdev);
> -	if (!ifpga_dev)
> -		return -ENODEV;
> -
> -	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);
> -
> -	for (i = 0; i < IFPGA_MAX_VDEV; i++) {
> -		tmp_vdev = ifpga_dev->vdev_name[i];
> -		if (tmp_vdev && !strcmp(tmp_vdev, vdev_name)) {
> -			free(tmp_vdev);
> -			ifpga_dev->vdev_name[i] = NULL;
> -			break;
> -		}
> -	}
> -
> -	return ret;
> +	return 0;
>  }
> 
>  static struct rte_vdev_driver ifpga_cfg_driver = { diff --git
> a/drivers/raw/ifpga/ifpga_rawdev.h b/drivers/raw/ifpga/ifpga_rawdev.h
> index 0fb66cb..1c128c7 100644
> --- a/drivers/raw/ifpga/ifpga_rawdev.h
> +++ b/drivers/raw/ifpga/ifpga_rawdev.h
> @@ -65,8 +65,6 @@ struct ifpga_rawdev {
>  	void *intr_handle[IFPGA_MAX_IRQ];
>  	/* enable monitor thread poll device's sensors or not */
>  	int poll_enabled;
> -	/* name of virtual devices created on raw device */
> -	char *vdev_name[IFPGA_MAX_VDEV];
>  };
> 
>  struct ifpga_vdev_args {
> --
> 1.8.3.1

Acked-by: Rosen Xu <rosen.xu@intel.com>
  
Qi Zhang March 20, 2023, 12:58 p.m. UTC | #2
> -----Original Message-----
> From: Xu, Rosen <rosen.xu@intel.com>
> Sent: Monday, March 20, 2023 2:52 PM
> To: Huang, Wei <wei.huang@intel.com>; dev@dpdk.org;
> thomas@monjalon.net; david.marchand@redhat.com
> Cc: stable@dpdk.org; Zhang, Tianfei <tianfei.zhang@intel.com>; Zhang, Qi Z
> <qi.z.zhang@intel.com>
> Subject: RE: [PATCH v1] raw/ifpga: remove virtual device unplug operation
> 
> Hi,
> 
> > -----Original Message-----
> > From: Huang, Wei <wei.huang@intel.com>
> > Sent: Friday, March 17, 2023 4:45 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: remove virtual device unplug operation
> >
> > VDEV bus has implemented cleanup() function to perform cleanup for
> > devices on the bus during eal_cleanup(), so there is no need for ifpga
> > driver to record virtual devices and unplug them.
> >
> > Signed-off-by: Wei Huang <wei.huang@intel.com>
> > ---
> >  drivers/raw/ifpga/ifpga_rawdev.c | 99
> > ++++------------------------------------
> >  drivers/raw/ifpga/ifpga_rawdev.h |  2 -
> >  2 files changed, 9 insertions(+), 92 deletions(-)
> >
> > diff --git a/drivers/raw/ifpga/ifpga_rawdev.c
> > b/drivers/raw/ifpga/ifpga_rawdev.c
> > index 1020adc..8e6e70f 100644
> > --- a/drivers/raw/ifpga/ifpga_rawdev.c
> > +++ b/drivers/raw/ifpga/ifpga_rawdev.c
> > @@ -140,8 +140,6 @@ struct ifpga_rawdev *
> >  	for (i = 0; i < IFPGA_MAX_IRQ; i++)
> >  		dev->intr_handle[i] = NULL;
> >  	dev->poll_enabled = 0;
> > -	for (i = 0; i < IFPGA_MAX_VDEV; i++)
> > -		dev->vdev_name[i] = NULL;
> >
> >  	return dev;
> >  }
> > @@ -749,17 +747,11 @@ static int set_surprise_link_check_aer(
> >  	struct ifpga_rawdev *ifpga_rdev = NULL;
> >  	struct opae_adapter *adapter;
> >  	struct opae_manager *mgr;
> > -	char *vdev_name = NULL;
> > -	int i, ret = 0;
> > +	int ret = 0;
> >
> >  	if (dev) {
> >  		ifpga_rdev = ifpga_rawdev_get(dev);
> >  		if (ifpga_rdev) {
> > -			for (i = 0; i < IFPGA_MAX_VDEV; i++) {
> > -				vdev_name = ifpga_rdev->vdev_name[i];
> > -				if (vdev_name)
> > -					rte_vdev_uninit(vdev_name);
> > -			}
> >  			ifpga_monitor_stop_func(ifpga_rdev);
> >  			ifpga_rdev->rawdev = NULL;
> >  		}
> > @@ -1778,104 +1770,31 @@ static int ifpga_rawdev_get_string_arg(const
> > char *key __rte_unused,  static int  ifpga_cfg_probe(struct
> > rte_vdev_device
> > *vdev)  {
> > -	struct rte_rawdev *rawdev = NULL;
> > -	struct ifpga_rawdev *ifpga_dev;
> >  	struct ifpga_vdev_args args;
> >  	char dev_name[RTE_RAWDEV_NAME_MAX_LEN];
> > -	const char *vdev_name = NULL;
> > -	int i, n, ret = 0;
> > -
> > -	vdev_name = rte_vdev_device_name(vdev);
> > -	if (!vdev_name)
> > -		return -EINVAL;
> > +	int ret = 0;
> >
> > -	IFPGA_RAWDEV_PMD_INFO("probe ifpga virtual device %s",
> > vdev_name);
> > +	IFPGA_RAWDEV_PMD_INFO("probe ifpga virtual device %s",
> > +		rte_vdev_device_name(vdev));
> >
> >  	ret = ifpga_vdev_parse_devargs(vdev->device.devargs, &args);
> >  	if (ret)
> >  		return ret;
> >
> >  	memset(dev_name, 0, sizeof(dev_name));
> > -	snprintf(dev_name, RTE_RAWDEV_NAME_MAX_LEN, "IFPGA:%s",
> > args.bdf);
> > -	rawdev = rte_rawdev_pmd_get_named_dev(dev_name);
> > -	if (!rawdev)
> > -		return -ENODEV;
> > -	ifpga_dev = ifpga_rawdev_get(rawdev);
> > -	if (!ifpga_dev)
> > -		return -ENODEV;
> > -
> > -	for (i = 0; i < IFPGA_MAX_VDEV; i++) {
> > -		if (ifpga_dev->vdev_name[i] == NULL) {
> > -			n = strlen(vdev_name) + 1;
> > -			ifpga_dev->vdev_name[i] = rte_malloc(NULL, n, 0);
> > -			if (ifpga_dev->vdev_name[i] == NULL)
> > -				return -ENOMEM;
> > -			strlcpy(ifpga_dev->vdev_name[i], vdev_name, n);
> > -			break;
> > -		}
> > -	}
> > -
> > -	if (i >= IFPGA_MAX_VDEV) {
> > -		IFPGA_RAWDEV_PMD_ERR("Can't create more virtual
> > device!");
> > -		return -ENOENT;
> > -	}
> > -
> >  	snprintf(dev_name, RTE_RAWDEV_NAME_MAX_LEN, "%d|%s",
> >  		args.port, args.bdf);
> > -	ret = rte_eal_hotplug_add(RTE_STR(IFPGA_BUS_NAME),
> > -			dev_name, vdev->device.devargs->args);
> > -	if (ret) {
> > -		rte_free(ifpga_dev->vdev_name[i]);
> > -		ifpga_dev->vdev_name[i] = NULL;
> > -	}
> > -
> > -	return ret;
> > +	return rte_eal_hotplug_add(RTE_STR(IFPGA_BUS_NAME),
> > dev_name,
> > +			vdev->device.devargs->args);
> >  }
> >
> >  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;
> > -	char dev_name[RTE_RAWDEV_NAME_MAX_LEN];
> > -	const char *vdev_name = NULL;
> > -	char *tmp_vdev = NULL;
> > -	int i, ret = 0;
> > -
> > -	vdev_name = rte_vdev_device_name(vdev);
> > -	if (!vdev_name)
> > -		return -EINVAL;
> > +	IFPGA_RAWDEV_PMD_INFO("remove ifpga virtual device %s",
> > +		rte_vdev_device_name(vdev));
> >
> > -	IFPGA_RAWDEV_PMD_INFO("remove ifpga virtual device %s",
> > vdev_name);
> > -
> > -	ret = ifpga_vdev_parse_devargs(vdev->device.devargs, &args);
> > -	if (ret)
> > -		return ret;
> > -
> > -	memset(dev_name, 0, sizeof(dev_name));
> > -	snprintf(dev_name, RTE_RAWDEV_NAME_MAX_LEN, "IFPGA:%s",
> > args.bdf);
> > -	rawdev = rte_rawdev_pmd_get_named_dev(dev_name);
> > -	if (!rawdev)
> > -		return -ENODEV;
> > -	ifpga_dev = ifpga_rawdev_get(rawdev);
> > -	if (!ifpga_dev)
> > -		return -ENODEV;
> > -
> > -	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);
> > -
> > -	for (i = 0; i < IFPGA_MAX_VDEV; i++) {
> > -		tmp_vdev = ifpga_dev->vdev_name[i];
> > -		if (tmp_vdev && !strcmp(tmp_vdev, vdev_name)) {
> > -			free(tmp_vdev);
> > -			ifpga_dev->vdev_name[i] = NULL;
> > -			break;
> > -		}
> > -	}
> > -
> > -	return ret;
> > +	return 0;
> >  }
> >
> >  static struct rte_vdev_driver ifpga_cfg_driver = { diff --git
> > a/drivers/raw/ifpga/ifpga_rawdev.h b/drivers/raw/ifpga/ifpga_rawdev.h
> > index 0fb66cb..1c128c7 100644
> > --- a/drivers/raw/ifpga/ifpga_rawdev.h
> > +++ b/drivers/raw/ifpga/ifpga_rawdev.h
> > @@ -65,8 +65,6 @@ struct ifpga_rawdev {
> >  	void *intr_handle[IFPGA_MAX_IRQ];
> >  	/* enable monitor thread poll device's sensors or not */
> >  	int poll_enabled;
> > -	/* name of virtual devices created on raw device */
> > -	char *vdev_name[IFPGA_MAX_VDEV];
> >  };
> >
> >  struct ifpga_vdev_args {
> > --
> > 1.8.3.1
> 
> Acked-by: Rosen Xu <rosen.xu@intel.com>

Applied to dpdk-next-net-intel.

Thanks
Qi
  
Qi Zhang March 20, 2023, 1 p.m. UTC | #3
> -----Original Message-----
> From: Zhang, Qi Z
> Sent: Monday, March 20, 2023 8:59 PM
> To: Xu, Rosen <rosen.xu@intel.com>; Huang, Wei <wei.huang@intel.com>;
> dev@dpdk.org; thomas@monjalon.net; david.marchand@redhat.com
> Cc: stable@dpdk.org; Zhang, Tianfei <tianfei.zhang@intel.com>
> Subject: RE: [PATCH v1] raw/ifpga: remove virtual device unplug operation
> 
> 
> 
> > -----Original Message-----
> > From: Xu, Rosen <rosen.xu@intel.com>
> > Sent: Monday, March 20, 2023 2:52 PM
> > To: Huang, Wei <wei.huang@intel.com>; dev@dpdk.org;
> > thomas@monjalon.net; david.marchand@redhat.com
> > Cc: stable@dpdk.org; Zhang, Tianfei <tianfei.zhang@intel.com>; Zhang,
> > Qi Z <qi.z.zhang@intel.com>
> > Subject: RE: [PATCH v1] raw/ifpga: remove virtual device unplug
> > operation
> >
> > Hi,
> >
> > > -----Original Message-----
> > > From: Huang, Wei <wei.huang@intel.com>
> > > Sent: Friday, March 17, 2023 4:45 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: remove virtual device unplug
> > > operation
> > >
> > > VDEV bus has implemented cleanup() function to perform cleanup for
> > > devices on the bus during eal_cleanup(), so there is no need for
> > > ifpga driver to record virtual devices and unplug them.
> > >
> > > Signed-off-by: Wei Huang <wei.huang@intel.com>
> > > ---
> > >  drivers/raw/ifpga/ifpga_rawdev.c | 99
> > > ++++------------------------------------
> > >  drivers/raw/ifpga/ifpga_rawdev.h |  2 -
> > >  2 files changed, 9 insertions(+), 92 deletions(-)
> > >
> > > diff --git a/drivers/raw/ifpga/ifpga_rawdev.c
> > > b/drivers/raw/ifpga/ifpga_rawdev.c
> > > index 1020adc..8e6e70f 100644
> > > --- a/drivers/raw/ifpga/ifpga_rawdev.c
> > > +++ b/drivers/raw/ifpga/ifpga_rawdev.c
> > > @@ -140,8 +140,6 @@ struct ifpga_rawdev *
> > >  	for (i = 0; i < IFPGA_MAX_IRQ; i++)
> > >  		dev->intr_handle[i] = NULL;
> > >  	dev->poll_enabled = 0;
> > > -	for (i = 0; i < IFPGA_MAX_VDEV; i++)
> > > -		dev->vdev_name[i] = NULL;
> > >
> > >  	return dev;
> > >  }
> > > @@ -749,17 +747,11 @@ static int set_surprise_link_check_aer(
> > >  	struct ifpga_rawdev *ifpga_rdev = NULL;
> > >  	struct opae_adapter *adapter;
> > >  	struct opae_manager *mgr;
> > > -	char *vdev_name = NULL;
> > > -	int i, ret = 0;
> > > +	int ret = 0;
> > >
> > >  	if (dev) {
> > >  		ifpga_rdev = ifpga_rawdev_get(dev);
> > >  		if (ifpga_rdev) {
> > > -			for (i = 0; i < IFPGA_MAX_VDEV; i++) {
> > > -				vdev_name = ifpga_rdev->vdev_name[i];
> > > -				if (vdev_name)
> > > -					rte_vdev_uninit(vdev_name);
> > > -			}
> > >  			ifpga_monitor_stop_func(ifpga_rdev);
> > >  			ifpga_rdev->rawdev = NULL;
> > >  		}
> > > @@ -1778,104 +1770,31 @@ static int
> > > ifpga_rawdev_get_string_arg(const char *key __rte_unused,  static
> > > int  ifpga_cfg_probe(struct rte_vdev_device
> > > *vdev)  {
> > > -	struct rte_rawdev *rawdev = NULL;
> > > -	struct ifpga_rawdev *ifpga_dev;
> > >  	struct ifpga_vdev_args args;
> > >  	char dev_name[RTE_RAWDEV_NAME_MAX_LEN];
> > > -	const char *vdev_name = NULL;
> > > -	int i, n, ret = 0;
> > > -
> > > -	vdev_name = rte_vdev_device_name(vdev);
> > > -	if (!vdev_name)
> > > -		return -EINVAL;
> > > +	int ret = 0;
> > >
> > > -	IFPGA_RAWDEV_PMD_INFO("probe ifpga virtual device %s",
> > > vdev_name);
> > > +	IFPGA_RAWDEV_PMD_INFO("probe ifpga virtual device %s",
> > > +		rte_vdev_device_name(vdev));
> > >
> > >  	ret = ifpga_vdev_parse_devargs(vdev->device.devargs, &args);
> > >  	if (ret)
> > >  		return ret;
> > >
> > >  	memset(dev_name, 0, sizeof(dev_name));
> > > -	snprintf(dev_name, RTE_RAWDEV_NAME_MAX_LEN, "IFPGA:%s",
> > > args.bdf);
> > > -	rawdev = rte_rawdev_pmd_get_named_dev(dev_name);
> > > -	if (!rawdev)
> > > -		return -ENODEV;
> > > -	ifpga_dev = ifpga_rawdev_get(rawdev);
> > > -	if (!ifpga_dev)
> > > -		return -ENODEV;
> > > -
> > > -	for (i = 0; i < IFPGA_MAX_VDEV; i++) {
> > > -		if (ifpga_dev->vdev_name[i] == NULL) {
> > > -			n = strlen(vdev_name) + 1;
> > > -			ifpga_dev->vdev_name[i] = rte_malloc(NULL, n, 0);
> > > -			if (ifpga_dev->vdev_name[i] == NULL)
> > > -				return -ENOMEM;
> > > -			strlcpy(ifpga_dev->vdev_name[i], vdev_name, n);
> > > -			break;
> > > -		}
> > > -	}
> > > -
> > > -	if (i >= IFPGA_MAX_VDEV) {
> > > -		IFPGA_RAWDEV_PMD_ERR("Can't create more virtual
> > > device!");
> > > -		return -ENOENT;
> > > -	}
> > > -
> > >  	snprintf(dev_name, RTE_RAWDEV_NAME_MAX_LEN, "%d|%s",
> > >  		args.port, args.bdf);
> > > -	ret = rte_eal_hotplug_add(RTE_STR(IFPGA_BUS_NAME),
> > > -			dev_name, vdev->device.devargs->args);
> > > -	if (ret) {
> > > -		rte_free(ifpga_dev->vdev_name[i]);
> > > -		ifpga_dev->vdev_name[i] = NULL;
> > > -	}
> > > -
> > > -	return ret;
> > > +	return rte_eal_hotplug_add(RTE_STR(IFPGA_BUS_NAME),
> > > dev_name,
> > > +			vdev->device.devargs->args);
> > >  }
> > >
> > >  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;
> > > -	char dev_name[RTE_RAWDEV_NAME_MAX_LEN];
> > > -	const char *vdev_name = NULL;
> > > -	char *tmp_vdev = NULL;
> > > -	int i, ret = 0;
> > > -
> > > -	vdev_name = rte_vdev_device_name(vdev);
> > > -	if (!vdev_name)
> > > -		return -EINVAL;
> > > +	IFPGA_RAWDEV_PMD_INFO("remove ifpga virtual device %s",
> > > +		rte_vdev_device_name(vdev));
> > >
> > > -	IFPGA_RAWDEV_PMD_INFO("remove ifpga virtual device %s",
> > > vdev_name);
> > > -
> > > -	ret = ifpga_vdev_parse_devargs(vdev->device.devargs, &args);
> > > -	if (ret)
> > > -		return ret;
> > > -
> > > -	memset(dev_name, 0, sizeof(dev_name));
> > > -	snprintf(dev_name, RTE_RAWDEV_NAME_MAX_LEN, "IFPGA:%s",
> > > args.bdf);
> > > -	rawdev = rte_rawdev_pmd_get_named_dev(dev_name);
> > > -	if (!rawdev)
> > > -		return -ENODEV;
> > > -	ifpga_dev = ifpga_rawdev_get(rawdev);
> > > -	if (!ifpga_dev)
> > > -		return -ENODEV;
> > > -
> > > -	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);
> > > -
> > > -	for (i = 0; i < IFPGA_MAX_VDEV; i++) {
> > > -		tmp_vdev = ifpga_dev->vdev_name[i];
> > > -		if (tmp_vdev && !strcmp(tmp_vdev, vdev_name)) {
> > > -			free(tmp_vdev);
> > > -			ifpga_dev->vdev_name[i] = NULL;
> > > -			break;
> > > -		}
> > > -	}
> > > -
> > > -	return ret;
> > > +	return 0;
> > >  }
> > >
> > >  static struct rte_vdev_driver ifpga_cfg_driver = { diff --git
> > > a/drivers/raw/ifpga/ifpga_rawdev.h
> > > b/drivers/raw/ifpga/ifpga_rawdev.h
> > > index 0fb66cb..1c128c7 100644
> > > --- a/drivers/raw/ifpga/ifpga_rawdev.h
> > > +++ b/drivers/raw/ifpga/ifpga_rawdev.h
> > > @@ -65,8 +65,6 @@ struct ifpga_rawdev {
> > >  	void *intr_handle[IFPGA_MAX_IRQ];
> > >  	/* enable monitor thread poll device's sensors or not */
> > >  	int poll_enabled;
> > > -	/* name of virtual devices created on raw device */
> > > -	char *vdev_name[IFPGA_MAX_VDEV];
> > >  };
> > >
> > >  struct ifpga_vdev_args {
> > > --
> > > 1.8.3.1
> >
> > Acked-by: Rosen Xu <rosen.xu@intel.com>
> 
> Applied to dpdk-next-net-intel.
> 
> Thanks
> Qi

Sorry, this didnt happen, I replied on the wrong email.
  
Thomas Monjalon March 20, 2023, 4:06 p.m. UTC | #4
16/03/2023 21:44, Wei Huang:
> VDEV bus has implemented cleanup() function to perform cleanup for
> devices on the bus during eal_cleanup(), so there is no need for
> ifpga driver to record virtual devices and unplug them.

Why no need?
If the application wants to explicitly remove a device, what happens?
  
Wei Huang March 21, 2023, 12:11 a.m. UTC | #5
Hi Tomas,

> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Sent: Tuesday, March 21, 2023 00:06
> To: Huang, Wei <wei.huang@intel.com>
> Cc: dev@dpdk.org; david.marchand@redhat.com; stable@dpdk.org; Xu,
> Rosen <rosen.xu@intel.com>; Zhang, Tianfei <tianfei.zhang@intel.com>;
> Zhang, Qi Z <qi.z.zhang@intel.com>
> Subject: Re: [PATCH v1] raw/ifpga: remove virtual device unplug operation
> 
> 16/03/2023 21:44, Wei Huang:
> > VDEV bus has implemented cleanup() function to perform cleanup for
> > devices on the bus during eal_cleanup(), so there is no need for ifpga
> > driver to record virtual devices and unplug them.
> 
> Why no need?
> If the application wants to explicitly remove a device, what happens?
> 
>
EAL will output an error information "Cannot find plugged device (%s)".
  
Thomas Monjalon March 21, 2023, 8:14 a.m. UTC | #6
21/03/2023 01:11, Huang, Wei:
> From: Thomas Monjalon <thomas@monjalon.net>
> > 16/03/2023 21:44, Wei Huang:
> > > VDEV bus has implemented cleanup() function to perform cleanup for
> > > devices on the bus during eal_cleanup(), so there is no need for ifpga
> > > driver to record virtual devices and unplug them.
> > 
> > Why no need?
> > If the application wants to explicitly remove a device, what happens?
> > 
> >
> EAL will output an error information "Cannot find plugged device (%s)".

It does not look what we expect.
  
Wei Huang March 21, 2023, 8:41 a.m. UTC | #7
Hi Thomas,

> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Sent: Tuesday, March 21, 2023 16:14
> To: Huang, Wei <wei.huang@intel.com>
> Cc: dev@dpdk.org; david.marchand@redhat.com; stable@dpdk.org; Xu,
> Rosen <rosen.xu@intel.com>; Zhang, Tianfei <tianfei.zhang@intel.com>;
> Zhang, Qi Z <qi.z.zhang@intel.com>
> Subject: Re: [PATCH v1] raw/ifpga: remove virtual device unplug operation
> 
> 21/03/2023 01:11, Huang, Wei:
> > From: Thomas Monjalon <thomas@monjalon.net>
> > > 16/03/2023 21:44, Wei Huang:
> > > > VDEV bus has implemented cleanup() function to perform cleanup for
> > > > devices on the bus during eal_cleanup(), so there is no need for
> > > > ifpga driver to record virtual devices and unplug them.
> > >
> > > Why no need?
> > > If the application wants to explicitly remove a device, what happens?
> > >
> > >
> > EAL will output an error information "Cannot find plugged device (%s)".
> 
> It does not look what we expect.
> 
Let me clear it.
With this patch, no error information will be outputted.
Without this patch, error information will be outputted. Because bus cleanup action will unplug virtual device, then ifpga PMD unplug the virtual device which is already be cleanup, bus->find_device() returns NULL, EAL output "Cannot find plugged device (%s)\n" at line 302 in eal_common_dev.c
  
Thomas Monjalon March 21, 2023, 10:30 a.m. UTC | #8
21/03/2023 09:41, Huang, Wei:
> From: Thomas Monjalon <thomas@monjalon.net>
> > 21/03/2023 01:11, Huang, Wei:
> > > From: Thomas Monjalon <thomas@monjalon.net>
> > > > 16/03/2023 21:44, Wei Huang:
> > > > > VDEV bus has implemented cleanup() function to perform cleanup for
> > > > > devices on the bus during eal_cleanup(), so there is no need for
> > > > > ifpga driver to record virtual devices and unplug them.
> > > >
> > > > Why no need?
> > > > If the application wants to explicitly remove a device, what happens?
> > > >
> > > >
> > > EAL will output an error information "Cannot find plugged device (%s)".
> > 
> > It does not look what we expect.
> > 
> Let me clear it.
> With this patch, no error information will be outputted.
> Without this patch, error information will be outputted.
> Because bus cleanup action will unplug virtual device,
> then ifpga PMD unplug the virtual device which is already be cleanup,

Why ipfga unplug the device after the bus cleanup?
I'm not following.

> bus->find_device() returns NULL,
> EAL output "Cannot find plugged device (%s)\n" at line 302 in eal_common_dev.c

Anyway, the good answer is not to completely remove the "remove" operation.
  
Wei Huang March 22, 2023, 1:26 a.m. UTC | #9
> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Sent: Tuesday, March 21, 2023 18:30
> To: Huang, Wei <wei.huang@intel.com>
> Cc: dev@dpdk.org; david.marchand@redhat.com; stable@dpdk.org; Xu,
> Rosen <rosen.xu@intel.com>; Zhang, Tianfei <tianfei.zhang@intel.com>;
> Zhang, Qi Z <qi.z.zhang@intel.com>
> Subject: Re: [PATCH v1] raw/ifpga: remove virtual device unplug operation
> 
> 21/03/2023 09:41, Huang, Wei:
> > From: Thomas Monjalon <thomas@monjalon.net>
> > > 21/03/2023 01:11, Huang, Wei:
> > > > From: Thomas Monjalon <thomas@monjalon.net>
> > > > > 16/03/2023 21:44, Wei Huang:
> > > > > > VDEV bus has implemented cleanup() function to perform cleanup
> > > > > > for devices on the bus during eal_cleanup(), so there is no
> > > > > > need for ifpga driver to record virtual devices and unplug them.
> > > > >
> > > > > Why no need?
> > > > > If the application wants to explicitly remove a device, what happens?
> > > > >
> > > > >
> > > > EAL will output an error information "Cannot find plugged device (%s)".
> > >
> > > It does not look what we expect.
> > >
> > Let me clear it.
> > With this patch, no error information will be outputted.
> > Without this patch, error information will be outputted.
> > Because bus cleanup action will unplug virtual device, then ifpga PMD
> > unplug the virtual device which is already be cleanup,
> 
> Why ipfga unplug the device after the bus cleanup?
> I'm not following.
> 
The virtual device is created upon ifpga, if VDEV bus doesn't perform cleanup, ifpga has the responsibility to unplug these virtual devices.

> > bus->find_device() returns NULL,
> > EAL output "Cannot find plugged device (%s)\n" at line 302 in
> > eal_common_dev.c
> 
> Anyway, the good answer is not to completely remove the "remove"
> operation.
> 
If not to completely remove the "remove", the same virtual device will be unplug twice, is it reasonable?
  
Thomas Monjalon March 22, 2023, 11:54 a.m. UTC | #10
22/03/2023 02:26, Huang, Wei:
> From: Thomas Monjalon <thomas@monjalon.net>
> > 21/03/2023 09:41, Huang, Wei:
> > > From: Thomas Monjalon <thomas@monjalon.net>
> > > > 21/03/2023 01:11, Huang, Wei:
> > > > > From: Thomas Monjalon <thomas@monjalon.net>
> > > > > > 16/03/2023 21:44, Wei Huang:
> > > > > > > VDEV bus has implemented cleanup() function to perform cleanup
> > > > > > > for devices on the bus during eal_cleanup(), so there is no
> > > > > > > need for ifpga driver to record virtual devices and unplug them.
> > > > > >
> > > > > > Why no need?
> > > > > > If the application wants to explicitly remove a device, what happens?
> > > > > >
> > > > > >
> > > > > EAL will output an error information "Cannot find plugged device (%s)".
> > > >
> > > > It does not look what we expect.
> > > >
> > > Let me clear it.
> > > With this patch, no error information will be outputted.
> > > Without this patch, error information will be outputted.
> > > Because bus cleanup action will unplug virtual device, then ifpga PMD
> > > unplug the virtual device which is already be cleanup,
> > 
> > Why ipfga unplug the device after the bus cleanup?
> > I'm not following.
> > 
> The virtual device is created upon ifpga, if VDEV bus doesn't perform cleanup,
> ifpga has the responsibility to unplug these virtual devices.

Really I don't understand the flow.
Are you talking about EAL cleanup case?
What happens first? Do you need ifpga to be called first?
I think you need the correct checks to allow any order of cleanup.

> > > bus->find_device() returns NULL,
> > > EAL output "Cannot find plugged device (%s)\n" at line 302 in
> > > eal_common_dev.c
> > 
> > Anyway, the good answer is not to completely remove the "remove"
> > operation.
> > 
> If not to completely remove the "remove", the same virtual device will be unplug twice, is it reasonable?

You need to add a check to not unplug something already unplugged.
But you must allow the user calling "remove" directly.
  
Wei Huang March 23, 2023, 3:26 a.m. UTC | #11
> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Sent: Wednesday, March 22, 2023 19:54
> To: Huang, Wei <wei.huang@intel.com>
> Cc: dev@dpdk.org; david.marchand@redhat.com; stable@dpdk.org; Xu,
> Rosen <rosen.xu@intel.com>; Zhang, Tianfei <tianfei.zhang@intel.com>;
> Zhang, Qi Z <qi.z.zhang@intel.com>
> Subject: Re: [PATCH v1] raw/ifpga: remove virtual device unplug operation
> 
> 22/03/2023 02:26, Huang, Wei:
> > From: Thomas Monjalon <thomas@monjalon.net>
> > > 21/03/2023 09:41, Huang, Wei:
> > > > From: Thomas Monjalon <thomas@monjalon.net>
> > > > > 21/03/2023 01:11, Huang, Wei:
> > > > > > From: Thomas Monjalon <thomas@monjalon.net>
> > > > > > > 16/03/2023 21:44, Wei Huang:
> > > > > > > > VDEV bus has implemented cleanup() function to perform
> > > > > > > > cleanup for devices on the bus during eal_cleanup(), so
> > > > > > > > there is no need for ifpga driver to record virtual devices and
> unplug them.
> > > > > > >
> > > > > > > Why no need?
> > > > > > > If the application wants to explicitly remove a device, what
> happens?
> > > > > > >
> > > > > > >
> > > > > > EAL will output an error information "Cannot find plugged device
> (%s)".
> > > > >
> > > > > It does not look what we expect.
> > > > >
> > > > Let me clear it.
> > > > With this patch, no error information will be outputted.
> > > > Without this patch, error information will be outputted.
> > > > Because bus cleanup action will unplug virtual device, then ifpga
> > > > PMD unplug the virtual device which is already be cleanup,
> > >
> > > Why ipfga unplug the device after the bus cleanup?
> > > I'm not following.
> > >
> > The virtual device is created upon ifpga, if VDEV bus doesn't perform
> > cleanup, ifpga has the responsibility to unplug these virtual devices.
> 
> Really I don't understand the flow.
> Are you talking about EAL cleanup case?
Yes, it's about EAL cleanup.
> What happens first? Do you need ifpga to be called first?
The cleanup flow is rte_eal_cleanup() -> eal_bus_cleanup()
eal_bus_cleanup() will call each bus's cleanup method to complete cleanup work.  
There are three types of device related to ifpga PMD: PCI device, VDEV device and AFU device.
VDEV device is created on PCI device, it's a mediate device which purpose is to plug a AFU device on IFPGA bus.
Before eal_bus_cleanup() is implemented, application will call rte_pmd_ifpga_cleanup() to remove PCI device, VDEV device will be removed when PCI device is removed, AFU device will be removed when VDEV device is removed, it works fine.
Now eal_bus_cleanup() takes the job, application has no need to call rte_pmd_ifpga_cleanup(), ifpga PCI device has no need to remove ifpga VDEV device and ifpga VDEV device has no need to remove ifpga AFU device.
> I think you need the correct checks to allow any order of cleanup.
When this patch is committed, no order dependent on cleanup.

> > > > bus->find_device() returns NULL,
> > > > EAL output "Cannot find plugged device (%s)\n" at line 302 in
> > > > eal_common_dev.c
> > >
> > > Anyway, the good answer is not to completely remove the "remove"
> > > operation.
> > >
> > If not to completely remove the "remove", the same virtual device will be
> unplug twice, is it reasonable?
> 
> You need to add a check to not unplug something already unplugged.
> But you must allow the user calling "remove" directly.
> 
rte_pmd_ifpga_cleanup() is the only one interface for user to calling "remove" directly, when this patch is committed, VDEV and AFU device will not be unplugged twice.
For PCI device, the implementation of rte_pmd_ifpga_cleanup() is like below
	for (i = 0; i < IFPGA_RAWDEV_NUM; i++) {
		dev = &ifpga_rawdevices[i];
		if (dev->rawdev) {
			rte_rawdev_pmd_release(dev->rawdev);
			dev->rawdev = NULL;
		}
	}
If ifpga PCI device is already removed, dev->rawdev is NULL, it will not be unplugged again.
  
Thomas Monjalon March 23, 2023, 8:52 a.m. UTC | #12
23/03/2023 04:26, Huang, Wei:
> From: Thomas Monjalon <thomas@monjalon.net>
> > 22/03/2023 02:26, Huang, Wei:
> > > From: Thomas Monjalon <thomas@monjalon.net>
> > > > 21/03/2023 09:41, Huang, Wei:
> > > > > From: Thomas Monjalon <thomas@monjalon.net>
> > > > > > 21/03/2023 01:11, Huang, Wei:
> > > > > > > From: Thomas Monjalon <thomas@monjalon.net>
> > > > > > > > 16/03/2023 21:44, Wei Huang:
> > > > > > > > > VDEV bus has implemented cleanup() function to perform
> > > > > > > > > cleanup for devices on the bus during eal_cleanup(), so
> > > > > > > > > there is no need for ifpga driver to record virtual devices and
> > unplug them.
> > > > > > > >
> > > > > > > > Why no need?
> > > > > > > > If the application wants to explicitly remove a device, what
> > happens?
> > > > > > > >
> > > > > > > >
> > > > > > > EAL will output an error information "Cannot find plugged device
> > (%s)".
> > > > > >
> > > > > > It does not look what we expect.
> > > > > >
> > > > > Let me clear it.
> > > > > With this patch, no error information will be outputted.
> > > > > Without this patch, error information will be outputted.
> > > > > Because bus cleanup action will unplug virtual device, then ifpga
> > > > > PMD unplug the virtual device which is already be cleanup,
> > > >
> > > > Why ipfga unplug the device after the bus cleanup?
> > > > I'm not following.
> > > >
> > > The virtual device is created upon ifpga, if VDEV bus doesn't perform
> > > cleanup, ifpga has the responsibility to unplug these virtual devices.
> > 
> > Really I don't understand the flow.
> > Are you talking about EAL cleanup case?
> Yes, it's about EAL cleanup.
> > What happens first? Do you need ifpga to be called first?
> The cleanup flow is rte_eal_cleanup() -> eal_bus_cleanup()
> eal_bus_cleanup() will call each bus's cleanup method to complete cleanup work.  
> There are three types of device related to ifpga PMD: PCI device, VDEV device and AFU device.
> VDEV device is created on PCI device, it's a mediate device which purpose is to plug a AFU device on IFPGA bus.
> Before eal_bus_cleanup() is implemented, application will call rte_pmd_ifpga_cleanup() to remove PCI device, VDEV device will be removed when PCI device is removed, AFU device will be removed when VDEV device is removed, it works fine.
> Now eal_bus_cleanup() takes the job, application has no need to call rte_pmd_ifpga_cleanup(), ifpga PCI device has no need to remove ifpga VDEV device and ifpga VDEV device has no need to remove ifpga AFU device.

That's the problem in your approach.
You need to keep the code removing children devices.
And if all children are removed, then the parent should remove itself.
If you implement these 2 conditions, the cleanup can happen in any order.

> > I think you need the correct checks to allow any order of cleanup.
> When this patch is committed, no order dependent on cleanup.
> 
> > > > > bus->find_device() returns NULL,
> > > > > EAL output "Cannot find plugged device (%s)\n" at line 302 in
> > > > > eal_common_dev.c
> > > >
> > > > Anyway, the good answer is not to completely remove the "remove"
> > > > operation.
> > > >
> > > If not to completely remove the "remove", the same virtual device will be
> > unplug twice, is it reasonable?
> > 
> > You need to add a check to not unplug something already unplugged.
> > But you must allow the user calling "remove" directly.
> > 
> rte_pmd_ifpga_cleanup() is the only one interface for user to calling "remove" directly,

No, there are functions in EAL to "remove" devices, like rte_dev_remove(),
and we must make sure it works effectively.

> when this patch is committed, VDEV and AFU device will not be unplugged twice.
> For PCI device, the implementation of rte_pmd_ifpga_cleanup() is like below
> 	for (i = 0; i < IFPGA_RAWDEV_NUM; i++) {
> 		dev = &ifpga_rawdevices[i];
> 		if (dev->rawdev) {
> 			rte_rawdev_pmd_release(dev->rawdev);
> 			dev->rawdev = NULL;
> 		}
> 	}
> If ifpga PCI device is already removed, dev->rawdev is NULL, it will not be unplugged again.
  
Wei Huang March 24, 2023, 1:27 a.m. UTC | #13
> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Sent: Thursday, March 23, 2023 16:52
> To: Huang, Wei <wei.huang@intel.com>
> Cc: dev@dpdk.org; david.marchand@redhat.com; stable@dpdk.org; Xu,
> Rosen <rosen.xu@intel.com>; Zhang, Tianfei <tianfei.zhang@intel.com>;
> Zhang, Qi Z <qi.z.zhang@intel.com>
> Subject: Re: [PATCH v1] raw/ifpga: remove virtual device unplug operation
> 
> 23/03/2023 04:26, Huang, Wei:
> > From: Thomas Monjalon <thomas@monjalon.net>
> > > 22/03/2023 02:26, Huang, Wei:
> > > > From: Thomas Monjalon <thomas@monjalon.net>
> > > > > 21/03/2023 09:41, Huang, Wei:
> > > > > > From: Thomas Monjalon <thomas@monjalon.net>
> > > > > > > 21/03/2023 01:11, Huang, Wei:
> > > > > > > > From: Thomas Monjalon <thomas@monjalon.net>
> > > > > > > > > 16/03/2023 21:44, Wei Huang:
> > > > > > > > > > VDEV bus has implemented cleanup() function to perform
> > > > > > > > > > cleanup for devices on the bus during eal_cleanup(),
> > > > > > > > > > so there is no need for ifpga driver to record virtual
> > > > > > > > > > devices and
> > > unplug them.
> > > > > > > > >
> > > > > > > > > Why no need?
> > > > > > > > > If the application wants to explicitly remove a device,
> > > > > > > > > what
> > > happens?
> > > > > > > > >
> > > > > > > > >
> > > > > > > > EAL will output an error information "Cannot find plugged
> > > > > > > > device
> > > (%s)".
> > > > > > >
> > > > > > > It does not look what we expect.
> > > > > > >
> > > > > > Let me clear it.
> > > > > > With this patch, no error information will be outputted.
> > > > > > Without this patch, error information will be outputted.
> > > > > > Because bus cleanup action will unplug virtual device, then
> > > > > > ifpga PMD unplug the virtual device which is already be
> > > > > > cleanup,
> > > > >
> > > > > Why ipfga unplug the device after the bus cleanup?
> > > > > I'm not following.
> > > > >
> > > > The virtual device is created upon ifpga, if VDEV bus doesn't
> > > > perform cleanup, ifpga has the responsibility to unplug these virtual
> devices.
> > >
> > > Really I don't understand the flow.
> > > Are you talking about EAL cleanup case?
> > Yes, it's about EAL cleanup.
> > > What happens first? Do you need ifpga to be called first?
> > The cleanup flow is rte_eal_cleanup() -> eal_bus_cleanup()
> > eal_bus_cleanup() will call each bus's cleanup method to complete cleanup
> work.
> > There are three types of device related to ifpga PMD: PCI device, VDEV
> device and AFU device.
> > VDEV device is created on PCI device, it's a mediate device which purpose
> is to plug a AFU device on IFPGA bus.
> > Before eal_bus_cleanup() is implemented, application will call
> rte_pmd_ifpga_cleanup() to remove PCI device, VDEV device will be
> removed when PCI device is removed, AFU device will be removed when
> VDEV device is removed, it works fine.
> > Now eal_bus_cleanup() takes the job, application has no need to call
> rte_pmd_ifpga_cleanup(), ifpga PCI device has no need to remove ifpga
> VDEV device and ifpga VDEV device has no need to remove ifpga AFU device.
> 
> That's the problem in your approach.
> You need to keep the code removing children devices.
> And if all children are removed, then the parent should remove itself.
> If you implement these 2 conditions, the cleanup can happen in any order.
> 
OK, this patch should be rejected, I will commit another patch according to your comments.
> > > I think you need the correct checks to allow any order of cleanup.
> > When this patch is committed, no order dependent on cleanup.
> >
> > > > > > bus->find_device() returns NULL,
> > > > > > EAL output "Cannot find plugged device (%s)\n" at line 302 in
> > > > > > eal_common_dev.c
> > > > >
> > > > > Anyway, the good answer is not to completely remove the "remove"
> > > > > operation.
> > > > >
> > > > If not to completely remove the "remove", the same virtual device
> > > > will be
> > > unplug twice, is it reasonable?
> > >
> > > You need to add a check to not unplug something already unplugged.
> > > But you must allow the user calling "remove" directly.
> > >
> > rte_pmd_ifpga_cleanup() is the only one interface for user to calling
> > "remove" directly,
> 
> No, there are functions in EAL to "remove" devices, like rte_dev_remove(),
> and we must make sure it works effectively.
> 
> > when this patch is committed, VDEV and AFU device will not be unplugged
> twice.
> > For PCI device, the implementation of rte_pmd_ifpga_cleanup() is like
> below
> > 	for (i = 0; i < IFPGA_RAWDEV_NUM; i++) {
> > 		dev = &ifpga_rawdevices[i];
> > 		if (dev->rawdev) {
> > 			rte_rawdev_pmd_release(dev->rawdev);
> > 			dev->rawdev = NULL;
> > 		}
> > 	}
> > If ifpga PCI device is already removed, dev->rawdev is NULL, it will not be
> unplugged again.
> 
> 
>
  

Patch

diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c
index 1020adc..8e6e70f 100644
--- a/drivers/raw/ifpga/ifpga_rawdev.c
+++ b/drivers/raw/ifpga/ifpga_rawdev.c
@@ -140,8 +140,6 @@  struct ifpga_rawdev *
 	for (i = 0; i < IFPGA_MAX_IRQ; i++)
 		dev->intr_handle[i] = NULL;
 	dev->poll_enabled = 0;
-	for (i = 0; i < IFPGA_MAX_VDEV; i++)
-		dev->vdev_name[i] = NULL;
 
 	return dev;
 }
@@ -749,17 +747,11 @@  static int set_surprise_link_check_aer(
 	struct ifpga_rawdev *ifpga_rdev = NULL;
 	struct opae_adapter *adapter;
 	struct opae_manager *mgr;
-	char *vdev_name = NULL;
-	int i, ret = 0;
+	int ret = 0;
 
 	if (dev) {
 		ifpga_rdev = ifpga_rawdev_get(dev);
 		if (ifpga_rdev) {
-			for (i = 0; i < IFPGA_MAX_VDEV; i++) {
-				vdev_name = ifpga_rdev->vdev_name[i];
-				if (vdev_name)
-					rte_vdev_uninit(vdev_name);
-			}
 			ifpga_monitor_stop_func(ifpga_rdev);
 			ifpga_rdev->rawdev = NULL;
 		}
@@ -1778,104 +1770,31 @@  static int ifpga_rawdev_get_string_arg(const char *key __rte_unused,
 static int
 ifpga_cfg_probe(struct rte_vdev_device *vdev)
 {
-	struct rte_rawdev *rawdev = NULL;
-	struct ifpga_rawdev *ifpga_dev;
 	struct ifpga_vdev_args args;
 	char dev_name[RTE_RAWDEV_NAME_MAX_LEN];
-	const char *vdev_name = NULL;
-	int i, n, ret = 0;
-
-	vdev_name = rte_vdev_device_name(vdev);
-	if (!vdev_name)
-		return -EINVAL;
+	int ret = 0;
 
-	IFPGA_RAWDEV_PMD_INFO("probe ifpga virtual device %s", vdev_name);
+	IFPGA_RAWDEV_PMD_INFO("probe ifpga virtual device %s",
+		rte_vdev_device_name(vdev));
 
 	ret = ifpga_vdev_parse_devargs(vdev->device.devargs, &args);
 	if (ret)
 		return ret;
 
 	memset(dev_name, 0, sizeof(dev_name));
-	snprintf(dev_name, RTE_RAWDEV_NAME_MAX_LEN, "IFPGA:%s", args.bdf);
-	rawdev = rte_rawdev_pmd_get_named_dev(dev_name);
-	if (!rawdev)
-		return -ENODEV;
-	ifpga_dev = ifpga_rawdev_get(rawdev);
-	if (!ifpga_dev)
-		return -ENODEV;
-
-	for (i = 0; i < IFPGA_MAX_VDEV; i++) {
-		if (ifpga_dev->vdev_name[i] == NULL) {
-			n = strlen(vdev_name) + 1;
-			ifpga_dev->vdev_name[i] = rte_malloc(NULL, n, 0);
-			if (ifpga_dev->vdev_name[i] == NULL)
-				return -ENOMEM;
-			strlcpy(ifpga_dev->vdev_name[i], vdev_name, n);
-			break;
-		}
-	}
-
-	if (i >= IFPGA_MAX_VDEV) {
-		IFPGA_RAWDEV_PMD_ERR("Can't create more virtual device!");
-		return -ENOENT;
-	}
-
 	snprintf(dev_name, RTE_RAWDEV_NAME_MAX_LEN, "%d|%s",
 		args.port, args.bdf);
-	ret = rte_eal_hotplug_add(RTE_STR(IFPGA_BUS_NAME),
-			dev_name, vdev->device.devargs->args);
-	if (ret) {
-		rte_free(ifpga_dev->vdev_name[i]);
-		ifpga_dev->vdev_name[i] = NULL;
-	}
-
-	return ret;
+	return rte_eal_hotplug_add(RTE_STR(IFPGA_BUS_NAME), dev_name,
+			vdev->device.devargs->args);
 }
 
 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;
-	char dev_name[RTE_RAWDEV_NAME_MAX_LEN];
-	const char *vdev_name = NULL;
-	char *tmp_vdev = NULL;
-	int i, ret = 0;
-
-	vdev_name = rte_vdev_device_name(vdev);
-	if (!vdev_name)
-		return -EINVAL;
+	IFPGA_RAWDEV_PMD_INFO("remove ifpga virtual device %s",
+		rte_vdev_device_name(vdev));
 
-	IFPGA_RAWDEV_PMD_INFO("remove ifpga virtual device %s", vdev_name);
-
-	ret = ifpga_vdev_parse_devargs(vdev->device.devargs, &args);
-	if (ret)
-		return ret;
-
-	memset(dev_name, 0, sizeof(dev_name));
-	snprintf(dev_name, RTE_RAWDEV_NAME_MAX_LEN, "IFPGA:%s", args.bdf);
-	rawdev = rte_rawdev_pmd_get_named_dev(dev_name);
-	if (!rawdev)
-		return -ENODEV;
-	ifpga_dev = ifpga_rawdev_get(rawdev);
-	if (!ifpga_dev)
-		return -ENODEV;
-
-	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);
-
-	for (i = 0; i < IFPGA_MAX_VDEV; i++) {
-		tmp_vdev = ifpga_dev->vdev_name[i];
-		if (tmp_vdev && !strcmp(tmp_vdev, vdev_name)) {
-			free(tmp_vdev);
-			ifpga_dev->vdev_name[i] = NULL;
-			break;
-		}
-	}
-
-	return ret;
+	return 0;
 }
 
 static struct rte_vdev_driver ifpga_cfg_driver = {
diff --git a/drivers/raw/ifpga/ifpga_rawdev.h b/drivers/raw/ifpga/ifpga_rawdev.h
index 0fb66cb..1c128c7 100644
--- a/drivers/raw/ifpga/ifpga_rawdev.h
+++ b/drivers/raw/ifpga/ifpga_rawdev.h
@@ -65,8 +65,6 @@  struct ifpga_rawdev {
 	void *intr_handle[IFPGA_MAX_IRQ];
 	/* enable monitor thread poll device's sensors or not */
 	int poll_enabled;
-	/* name of virtual devices created on raw device */
-	char *vdev_name[IFPGA_MAX_VDEV];
 };
 
 struct ifpga_vdev_args {