Skip to contentSkip to conversation

raw/ifpga: check afu device before unplug

PATCH Applied Wei Huang 4 participants 4 messages Mar 27, 2023 – Jun 12, 2023

lore
Share & tools
lore

Wei Huang

author
#0 lore raw

PATCH 1/1 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.

---
 drivers/raw/ifpga/ifpga_rawdev.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/raw/ifpga/ifpga_rawdev.c +15 -1
index 1020adc..0d43c87 100644
@@ -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];
Signature · 1 line
1.8.3.1
Acked-by on v1 1/1
#1 lore raw
Quoted 56 lines

-----Original Message-----
From: Huang, Wei <[email protected]>
Sent: Monday, March 27, 2023 5:42 AM
To: [email protected]; [email protected]; [email protected]
Cc: [email protected]; Xu, Rosen <[email protected]>; Zhang, Tianfei <[email protected]>; Zhang, Qi Z <[email protected]>; Huang, Wei <[email protected]>
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.

---
 drivers/raw/ifpga/ifpga_rawdev.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/raw/ifpga/ifpga_rawdev.c +8 -0
index 1020adc..0d43c87 100644
@@ -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);

drivers/raw/ifpga/ifpga_rawdev.c static int ifpga_rawdev_get_string_arg(const char *key · line 1884

Quoted 10 lines
drivers/raw/ifpga/ifpga_rawdev.c +7 -1
-	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.

Reviewed-by on v1 1/1
#3 lore raw
In reply to Wei Huang

Hi,

Quoted 69 lines

-----Original Message-----
From: Huang, Wei <[email protected]>
Sent: Monday, March 27, 2023 5:42 AM
To: [email protected]; [email protected]; [email protected]
Cc: [email protected]; Xu, Rosen <[email protected]>; Zhang, Tianfei <[email protected]>; Zhang, Qi Z <[email protected]>; Huang, Wei <[email protected]>
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.

---
 drivers/raw/ifpga/ifpga_rawdev.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/raw/ifpga/ifpga_rawdev.c +15 -1
index 1020adc..0d43c87 100644
@@ -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);
+		}
+	}
drivers/raw/ifpga/ifpga_rawdev.c +0 -1
 	for (i = 0; i < IFPGA_MAX_VDEV; i++) {
 		tmp_vdev = ifpga_dev->vdev_name[i];
--
Quoted 1 line

1.8.3.1