[dpdk-dev] [PATCH 12/32] net/dpaa2: vfio scan for net and sec device

Hemant Agrawal hemant.agrawal at nxp.com
Sun Dec 4 19:17:07 CET 2016


Signed-off-by: Hemant Agrawal <hemant.agrawal at nxp.com>
---
 drivers/net/dpaa2/dpaa2_vfio.c | 68 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 65 insertions(+), 3 deletions(-)

diff --git a/drivers/net/dpaa2/dpaa2_vfio.c b/drivers/net/dpaa2/dpaa2_vfio.c
index e7e33d3..58c77c9 100644
--- a/drivers/net/dpaa2/dpaa2_vfio.c
+++ b/drivers/net/dpaa2/dpaa2_vfio.c
@@ -188,15 +188,58 @@ static int64_t vfio_map_mcp_obj(struct dpaa2_vfio_group *group, char *mcp_obj)
 	return v_addr;
 }
 
+static inline int
+dpaa2_compare_dpaa2_dev(const struct rte_dpaa2_device *dev,
+			 const struct rte_dpaa2_device *dev2)
+{
+	/*not the same family device */
+	if (dev->dev_type != dev2->dev_type)
+		return -1;
+
+	if (dev->object_id == dev2->object_id)
+		return 0;
+	else
+		return 1;
+}
+
+static void
+dpaa2_bus_add_device(struct rte_bus *bus, struct rte_dpaa2_device *dev)
+{
+	/* device is valid, add in list (sorted) */
+	if (TAILQ_EMPTY(&bus->device_list)) {
+		rte_eal_device_insert(&dev->device);
+		rte_eal_bus_add_device(bus, &dev->device);
+	} else {
+		struct rte_dpaa2_device *dev2;
+		struct rte_device *r_dev2;
+		int ret;
+
+		TAILQ_FOREACH(r_dev2, &bus->device_list, next) {
+			dev2 = container_of(r_dev2, struct rte_dpaa2_device,
+						device);
+			ret = dpaa2_compare_dpaa2_dev(dev, dev2);
+			if (ret <= 0)
+				continue;
+
+			rte_eal_bus_insert_device(bus, &dev2->device,
+						  &dev->device);
+			rte_eal_device_insert(&dev->device);
+			return;
+		}
+		rte_eal_device_insert(&dev->device);
+		rte_eal_bus_add_device(bus, &dev->device);
+	}
+}
+
 /* Following function shall fetch total available list of MC devices
  * from VFIO container & populate private list of devices and other
  * data structures
  */
-int dpaa2_vfio_process_group(struct rte_bus *bus __rte_unused)
+int dpaa2_vfio_process_group(struct rte_bus *bus)
 {
 	struct dpaa2_vfio_device *vdev;
 	struct vfio_device_info device_info = { .argsz = sizeof(device_info) };
-	char *temp_obj, *object_type __rte_unused, *mcp_obj, *dev_name;
+	char *temp_obj, *object_type, *mcp_obj, *dev_name;
 	int32_t object_id, i, dev_fd;
 	DIR *d;
 	struct dirent *dir;
@@ -327,6 +370,25 @@ int dpaa2_vfio_process_group(struct rte_bus *bus __rte_unused)
 			DPAA2_VFIO_LOG(ERR, "DPAA2 VFIO_DEVICE_GET_INFO fail");
 			goto FAILURE;
 		}
+		if (!strcmp(object_type, "dpni") ||
+		    !strcmp(object_type, "dpseci")) {
+			struct rte_dpaa2_device *dev;
+
+			dev = malloc(sizeof(struct rte_dpaa2_device));
+			if (dev == NULL)
+				return -1;
+
+			memset(dev, 0, sizeof(*dev));
+			/* store hw_id of dpni/dpseci device */
+			dev->object_id = object_id;
+			dev->dev_type = (strcmp(object_type, "dpseci")) ?
+				DPAA2_MC_DPNI_DEVID : DPAA2_MC_DPSECI_DEVID;
+
+			RTE_LOG(INFO, PMD, "DPAA2: Added [%s-%d]\n",
+				object_type, object_id);
+
+			dpaa2_bus_add_device(bus, dev);
+		}
 	}
 	closedir(d);
 
@@ -367,7 +429,7 @@ int dpaa2_vfio_setup_group(void)
 	/* Check whether fsl-mc container exists or not */
 	DPAA2_VFIO_LOG(DEBUG, " container device path = %s", path);
 	if (stat(path, &st) < 0) {
-		DPAA2_VFIO_LOG(ERR, "vfio: Error (%d) getting FSL-MC device (%s)",
+		DPAA2_VFIO_LOG(ERR, "vfio: Error (%d) getting FSL-MC dev (%s)",
 			     errno,  path);
 		return -errno;
 	}
-- 
1.9.1



More information about the dev mailing list