DPDK patches and discussions
 help / color / mirror / Atom feed
From: Nipun Gupta <nipun.gupta@amd.com>
To: <dev@dpdk.org>, <thomas@monjalon.net>, <david.marchand@redhat.com>
Cc: <ferruh.yigit@amd.com>, <harpreet.anand@amd.com>,
	<nikhil.agarwal@amd.com>
Subject: [RFC PATCH 4/6] bus/cdx: support plug unplug and dev iterator
Date: Tue, 24 Jan 2023 19:37:44 +0530	[thread overview]
Message-ID: <20230124140746.594066-5-nipun.gupta@amd.com> (raw)
In-Reply-To: <20230124140746.594066-1-nipun.gupta@amd.com>

Add support for plugging and unplugging CDX devices on
the CDX bus. Also, CDX dev iterator support has been added
for the CDX bus.

Signed-off-by: Nipun Gupta <nipun.gupta@amd.com>
---
 drivers/bus/cdx/cdx.c         | 142 +++++++++++++++++++++++++++++++---
 drivers/bus/cdx/rte_bus_cdx.h |   1 +
 2 files changed, 133 insertions(+), 10 deletions(-)

diff --git a/drivers/bus/cdx/cdx.c b/drivers/bus/cdx/cdx.c
index d0adfb74ef..151d35ffd3 100644
--- a/drivers/bus/cdx/cdx.c
+++ b/drivers/bus/cdx/cdx.c
@@ -69,6 +69,7 @@
 #include <rte_eal_paging.h>
 #include <rte_errno.h>
 #include <rte_devargs.h>
+#include <rte_kvargs.h>
 #include <rte_malloc.h>
 #include <rte_memcpy.h>
 #include <rte_vfio.h>
@@ -81,6 +82,15 @@
 #define SYSFS_CDX_DEVICES "/sys/bus/cdx/devices"
 #define CDX_BUS_NAME	cdx
 
+enum cdx_params {
+	RTE_CDX_PARAM_NAME,
+};
+
+static const char * const cdx_params_keys[] = {
+	[RTE_CDX_PARAM_NAME] = "name",
+	NULL,
+};
+
 /**
  * @file
  * CDX probing using Linux sysfs.
@@ -88,7 +98,7 @@
 
 /* Add a device to CDX bus */
 static void
-rte_cdx_add_device(struct rte_cdx_device *cdx_dev)
+cdx_add_device(struct rte_cdx_device *cdx_dev)
 {
 	TAILQ_INSERT_TAIL(&rte_cdx_bus.device_list, cdx_dev, next);
 }
@@ -258,7 +268,7 @@ cdx_scan_one(const char *dirname, const char *dev_name)
 	}
 	dev->id.device_id = (uint16_t)tmp;
 
-	rte_cdx_add_device(dev);
+	cdx_add_device(dev);
 
 	return 0;
 
@@ -275,7 +285,7 @@ cdx_scan_one(const char *dirname, const char *dev_name)
  * list.
  */
 static int
-rte_cdx_scan(void)
+cdx_scan(void)
 {
 	struct dirent *e;
 	DIR *dir;
@@ -355,7 +365,7 @@ cdx_unmap_resource(void *requested_addr, size_t size)
  * Match the CDX Driver and Device using device id and vendor id.
  */
 static int
-rte_cdx_match(const struct rte_cdx_driver *cdx_drv,
+cdx_match(const struct rte_cdx_driver *cdx_drv,
 		const struct rte_cdx_device *cdx_dev)
 {
 	const struct rte_cdx_id *id_table;
@@ -381,7 +391,7 @@ rte_cdx_match(const struct rte_cdx_driver *cdx_drv,
  * driver.
  */
 static int
-rte_cdx_probe_one_driver(struct rte_cdx_driver *dr,
+cdx_probe_one_driver(struct rte_cdx_driver *dr,
 		struct rte_cdx_device *dev)
 {
 	const char *dev_name = dev->device.name;
@@ -392,7 +402,7 @@ rte_cdx_probe_one_driver(struct rte_cdx_driver *dr,
 		return -EINVAL;
 
 	/* The device is not blocked; Check if driver supports it */
-	if (!rte_cdx_match(dr, dev))
+	if (!cdx_match(dr, dev))
 		/* Match of device and driver failed */
 		return 1;
 
@@ -420,6 +430,7 @@ rte_cdx_probe_one_driver(struct rte_cdx_driver *dr,
 	} else {
 		dev->device.driver = &dr->driver;
 	}
+	dev->driver = dr;
 
 	return ret;
 
@@ -446,7 +457,7 @@ cdx_probe_all_drivers(struct rte_cdx_device *dev)
 		return -EINVAL;
 
 	FOREACH_DRIVER_ON_CDXBUS(dr) {
-		rc = rte_cdx_probe_one_driver(dr, dev);
+		rc = cdx_probe_one_driver(dr, dev);
 		if (rc < 0)
 			/* negative value is an error */
 			return rc;
@@ -560,6 +571,71 @@ cdx_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
 	return NULL;
 }
 
+/* Remove a device from CDX bus */
+static void
+cdx_remove_device(struct rte_cdx_device *cdx_dev)
+{
+	TAILQ_REMOVE(&rte_cdx_bus.device_list, cdx_dev, next);
+}
+
+/*
+ * If vendor/device ID match, call the remove() function of the
+ * driver.
+ */
+static int
+cdx_detach_dev(struct rte_cdx_device *dev)
+{
+	struct rte_cdx_driver *dr;
+	int ret = 0;
+
+	if (dev == NULL)
+		return -EINVAL;
+
+	dr = dev->driver;
+
+	CDX_BUS_DEBUG("detach device %s using driver: %s",
+		dev->device.name, dr->driver.name);
+
+	if (dr->remove) {
+		ret = dr->remove(dev);
+		if (ret < 0)
+			return ret;
+	}
+
+	/* clear driver structure */
+	dev->driver = NULL;
+	dev->device.driver = NULL;
+
+	rte_cdx_unmap_device(dev);
+
+	rte_intr_instance_free(dev->intr_handle);
+	dev->intr_handle = NULL;
+
+	return 0;
+}
+
+static int
+cdx_plug(struct rte_device *dev)
+{
+	return cdx_probe_all_drivers(RTE_DEV_TO_CDX_DEV(dev));
+}
+
+static int
+cdx_unplug(struct rte_device *dev)
+{
+	struct rte_cdx_device *cdx_dev;
+	int ret;
+
+	cdx_dev = RTE_DEV_TO_CDX_DEV(dev);
+	ret = cdx_detach_dev(cdx_dev);
+	if (ret == 0) {
+		cdx_remove_device(cdx_dev);
+		rte_devargs_remove(dev->devargs);
+		free(cdx_dev);
+	}
+	return ret;
+}
+
 static int
 cdx_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
 {
@@ -589,7 +665,7 @@ cdx_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
 }
 
 static enum rte_iova_mode
-rte_cdx_get_iommu_class(void)
+cdx_get_iommu_class(void)
 {
 	if (TAILQ_EMPTY(&rte_cdx_bus.device_list))
 		return RTE_IOVA_DC;
@@ -597,15 +673,61 @@ rte_cdx_get_iommu_class(void)
 	return RTE_IOVA_VA;
 }
 
+static int
+cdx_dev_match(const struct rte_device *dev,
+		const void *_kvlist)
+{
+	const struct rte_kvargs *kvlist = _kvlist;
+	const char *key = cdx_params_keys[RTE_CDX_PARAM_NAME];
+	const char *name;
+
+	/* no kvlist arg, all devices match */
+	if (kvlist == NULL)
+		return 0;
+
+	/* if key is present in kvlist and does not match, filter device */
+	name = rte_kvargs_get(kvlist, key);
+	if (name != NULL && strcmp(name, dev->name))
+		return -1;
+
+	return 0;
+}
+
+static void *
+cdx_dev_iterate(const void *start,
+		const char *str,
+		const struct rte_dev_iterator *it __rte_unused)
+{
+	rte_bus_find_device_t find_device;
+	struct rte_kvargs *kvargs = NULL;
+	struct rte_device *dev;
+
+	if (str != NULL) {
+		kvargs = rte_kvargs_parse(str, cdx_params_keys);
+		if (kvargs == NULL) {
+			CDX_BUS_ERR("cannot parse argument list %s", str);
+			rte_errno = EINVAL;
+			return NULL;
+		}
+	}
+	find_device = rte_cdx_bus.bus.find_device;
+	dev = find_device(start, cdx_dev_match, kvargs);
+	rte_kvargs_free(kvargs);
+	return dev;
+}
+
 struct rte_cdx_bus rte_cdx_bus = {
 	.bus = {
-		.scan = rte_cdx_scan,
+		.scan = cdx_scan,
 		.probe = cdx_probe,
 		.find_device = cdx_find_device,
+		.plug = cdx_plug,
+		.unplug = cdx_unplug,
 		.parse = cdx_parse,
 		.dma_map = cdx_dma_map,
 		.dma_unmap = cdx_dma_unmap,
-		.get_iommu_class = rte_cdx_get_iommu_class,
+		.get_iommu_class = cdx_get_iommu_class,
+		.dev_iterate = cdx_dev_iterate,
 	},
 	.device_list = TAILQ_HEAD_INITIALIZER(rte_cdx_bus.device_list),
 	.driver_list = TAILQ_HEAD_INITIALIZER(rte_cdx_bus.driver_list),
diff --git a/drivers/bus/cdx/rte_bus_cdx.h b/drivers/bus/cdx/rte_bus_cdx.h
index 43d75bc3b4..564fa8d047 100644
--- a/drivers/bus/cdx/rte_bus_cdx.h
+++ b/drivers/bus/cdx/rte_bus_cdx.h
@@ -78,6 +78,7 @@ struct rte_cdx_id {
 struct rte_cdx_device {
 	RTE_TAILQ_ENTRY(rte_cdx_device) next;	/**< Next probed CDX device. */
 	struct rte_device device;		/**< Inherit core device */
+	struct rte_cdx_driver *driver;		/**< CDX driver used in probing */
 	struct rte_cdx_id id;			/**< CDX ID. */
 	struct rte_mem_resource mem_resource[CDX_MAX_RESOURCE];
 						/**< CDX Memory Resource */
-- 
2.25.1


  parent reply	other threads:[~2023-01-24 14:08 UTC|newest]

Thread overview: 102+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-24 14:07 [RFC PATCH 0/6] add support for CDX bus Nipun Gupta
2023-01-24 14:07 ` [RFC PATCH 1/6] bus/cdx: introduce cdx bus Nipun Gupta
2023-01-24 14:07 ` [RFC PATCH 2/6] bus/cdx: add dma map and unmap support Nipun Gupta
2023-01-24 14:07 ` [RFC PATCH 3/6] bus/cdx: add support for MSI Nipun Gupta
2023-01-24 14:07 ` Nipun Gupta [this message]
2023-01-24 14:07 ` [RFC PATCH 5/6] bus: enable cdx bus Nipun Gupta
2023-01-24 14:07 ` [RFC PATCH 6/6] config/arm: add AMD CDX Nipun Gupta
2023-04-07  6:01 ` [PATCH 0/6] add support for CDX bus Nipun Gupta
2023-04-07  6:01   ` [PATCH 1/6] bus/cdx: introduce cdx bus Nipun Gupta
2023-04-07  6:01   ` [PATCH 2/6] bus/cdx: add dma map and unmap support Nipun Gupta
2023-04-07  6:01   ` [PATCH 3/6] bus/cdx: add support for MSI Nipun Gupta
2023-04-07  6:01   ` [PATCH 4/6] bus/cdx: support plug unplug and dev iterator Nipun Gupta
2023-04-07  6:01   ` [PATCH 5/6] bus: enable cdx bus Nipun Gupta
2023-04-07  6:01   ` [PATCH 6/6] config/arm: add AMD CDX Nipun Gupta
2023-04-07  7:18   ` [PATCH 0/6] add support for CDX bus David Marchand
2023-04-07  7:29     ` Nipun Gupta
2023-04-13 13:25       ` Gupta, Nipun
2023-04-13 13:26 ` [PATCH v2 " Nipun Gupta
2023-04-13 13:26   ` [PATCH v2 1/6] bus/cdx: introduce cdx bus Nipun Gupta
2023-04-14 16:45     ` Ferruh Yigit
2023-04-16  9:20       ` Gupta, Nipun
2023-04-13 13:27   ` [PATCH v2 2/6] bus/cdx: add dma map and unmap support Nipun Gupta
2023-04-13 13:27   ` [PATCH v2 3/6] bus/cdx: add support for MSI Nipun Gupta
2023-04-14 16:45     ` Ferruh Yigit
2023-04-16  9:20       ` Gupta, Nipun
2023-04-13 13:27   ` [PATCH v2 4/6] bus/cdx: support plug unplug and dev iterator Nipun Gupta
2023-04-13 13:27   ` [PATCH v2 5/6] bus: enable cdx bus Nipun Gupta
2023-04-14 16:45     ` Ferruh Yigit
2023-04-16  9:21       ` Gupta, Nipun
2023-04-13 13:27   ` [PATCH v2 6/6] config/arm: add AMD CDX Nipun Gupta
2023-04-14 16:45   ` [PATCH v2 0/6] add support for CDX bus Ferruh Yigit
2023-04-21 14:54 ` [PATCH v3 0/5] Support AMD CDX bus, for FPGA based CDX devices. The CDX Nipun Gupta
2023-04-21 14:54   ` [PATCH v3 1/5] bus/cdx: introduce cdx bus Nipun Gupta
2023-04-21 14:54   ` [PATCH v3 2/5] bus/cdx: add DMA map and unmap support Nipun Gupta
2023-04-21 14:54   ` [PATCH v3 3/5] bus/cdx: add support for MSI Nipun Gupta
2023-04-21 14:54   ` [PATCH v3 4/5] bus/cdx: support plug unplug and dev iterator Nipun Gupta
2023-04-21 14:54   ` [PATCH v3 5/5] config/arm: add AMD CDX Nipun Gupta
2023-05-04 15:28     ` Ferruh Yigit
2023-05-08 10:24       ` Gupta, Nipun
2023-05-08 10:44         ` Thomas Monjalon
2023-05-08 10:48           ` Gupta, Nipun
2023-05-08 11:26         ` Ferruh Yigit
2023-05-08 17:16           ` Honnappa Nagarahalli
2023-05-08 17:47             ` Ferruh Yigit
2023-05-09  4:35               ` Gupta, Nipun
2023-05-09  5:55           ` Ruifeng Wang
2023-06-14 10:30             ` Ferruh Yigit
2023-06-15  7:00               ` Ruifeng Wang
2023-05-08 11:18 ` [PATCH v4 0/4] Support AMD CDX bus, for FPGA based CDX devices. The CDX Nipun Gupta
2023-05-08 11:18   ` [PATCH v4 1/4] bus/cdx: introduce cdx bus Nipun Gupta
2023-05-09  6:54     ` Xia, Chenbo
2023-05-09 11:09       ` Gupta, Nipun
2023-05-09 11:25         ` Ferruh Yigit
2023-05-10  1:29           ` Xia, Chenbo
2023-05-24 11:14     ` Thomas Monjalon
2023-05-24 17:04       ` Gupta, Nipun
2023-05-08 11:18   ` [PATCH v4 2/4] bus/cdx: add DMA map and unmap support Nipun Gupta
2023-05-08 11:18   ` [PATCH v4 3/4] bus/cdx: add support for MSI Nipun Gupta
2023-05-24 11:06     ` Thomas Monjalon
2023-05-24 17:06       ` Gupta, Nipun
2023-05-08 11:18   ` [PATCH v4 4/4] bus/cdx: support plug unplug and dev iterator Nipun Gupta
2023-05-12 10:25   ` [PATCH v4 0/4] Support AMD CDX bus, for FPGA based CDX devices. The CDX Ferruh Yigit
2023-05-25 10:08 ` [PATCH v5 0/5] Support AMD CDX bus Nipun Gupta
2023-05-25 10:08   ` [PATCH v5 1/5] bus/cdx: introduce " Nipun Gupta
2023-06-01 15:00     ` David Marchand
2023-06-01 18:10       ` Nipun Gupta
2023-06-05  8:04       ` Nipun Gupta
2023-05-25 10:08   ` [PATCH v5 2/5] bus/cdx: add DMA map and unmap support Nipun Gupta
2023-06-01 15:07     ` David Marchand
2023-05-25 10:08   ` [PATCH v5 3/5] eal/interrupts: add IRQ count in interrupt handle Nipun Gupta
2023-06-01 15:25     ` David Marchand
2023-06-01 18:04       ` Nipun Gupta
2023-06-01 18:18         ` Gupta, Nipun
2023-06-06  7:18     ` [EXT] " Harman Kalra
2023-06-06  7:27       ` Nipun Gupta
2023-06-07  5:45         ` Harman Kalra
2023-05-25 10:08   ` [PATCH v5 4/5] bus/cdx: add support for MSI Nipun Gupta
2023-06-01 15:09     ` David Marchand
2023-06-05  8:05       ` Nipun Gupta
2023-05-25 10:08   ` [PATCH v5 5/5] bus/cdx: support plug unplug and dev iterator Nipun Gupta
2023-06-05 13:26 ` [PATCH v6 0/4] Support AMD CDX bus Nipun Gupta
2023-06-05 13:26   ` [PATCH v6 1/4] bus/cdx: introduce " Nipun Gupta
2023-06-06  8:55     ` Thomas Monjalon
2023-06-05 13:26   ` [PATCH v6 2/4] bus/cdx: add DMA map and unmap support Nipun Gupta
2023-06-05 13:26   ` [PATCH v6 3/4] bus/cdx: add support for MSI Nipun Gupta
2023-06-06  9:30     ` David Marchand
2023-06-06  9:42       ` Nipun Gupta
2023-06-05 13:26   ` [PATCH v6 4/4] bus/cdx: support plug unplug and dev iterator Nipun Gupta
2023-06-06 10:02 ` [PATCH v7 0/4] Support AMD CDX bus Nipun Gupta
2023-06-06 10:02   ` [PATCH v7 1/4] bus/cdx: introduce " Nipun Gupta
2023-06-06 13:00     ` Thomas Monjalon
2023-06-06 13:38       ` Nipun Gupta
2023-06-06 13:43         ` Thomas Monjalon
2023-06-06 10:02   ` [PATCH v7 2/4] bus/cdx: add DMA map and unmap support Nipun Gupta
2023-06-06 10:02   ` [PATCH v7 3/4] bus/cdx: add support for MSI Nipun Gupta
2023-06-06 10:02   ` [PATCH v7 4/4] bus/cdx: support plug unplug and dev iterator Nipun Gupta
2023-06-07  4:24 ` [PATCH v8 0/4] Support AMD CDX bus Nipun Gupta
2023-06-07  4:24   ` [PATCH v8 1/4] bus/cdx: introduce " Nipun Gupta
2023-06-07  4:24   ` [PATCH v8 2/4] bus/cdx: add DMA map and unmap support Nipun Gupta
2023-06-07  4:24   ` [PATCH v8 3/4] bus/cdx: add support for MSI Nipun Gupta
2023-06-07  4:24   ` [PATCH v8 4/4] bus/cdx: support plug unplug and dev iterator Nipun Gupta
2023-06-07 13:36   ` [PATCH v8 0/4] Support AMD CDX bus Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230124140746.594066-5-nipun.gupta@amd.com \
    --to=nipun.gupta@amd.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@amd.com \
    --cc=harpreet.anand@amd.com \
    --cc=nikhil.agarwal@amd.com \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).