All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shreyansh Jain <shreyansh.jain@nxp.com>
To: <david.marchand@6wind.com>
Cc: <dev@dpdk.org>, <thomas.monjalon@6wind.com>,
	Shreyansh Jain <shreyansh.jain@nxp.com>
Subject: [PATCH v7 4/9] eal/bus: support for scanning of bus
Date: Tue, 17 Jan 2017 15:39:29 +0530	[thread overview]
Message-ID: <1484647774-28984-5-git-send-email-shreyansh.jain@nxp.com> (raw)
In-Reply-To: <1484647774-28984-1-git-send-email-shreyansh.jain@nxp.com>

Scan for bus discovers the devices available on the bus and adds them
to a bus specific device list. Each bus mandatorily implements this
method.

Test cases for Bus are also updated by this patch.

Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 app/test/test_bus.c                     | 175 ++++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_common_bus.c  |   2 +
 lib/librte_eal/common/include/rte_bus.h |  18 ++++
 3 files changed, 195 insertions(+)

diff --git a/app/test/test_bus.c b/app/test/test_bus.c
index 9680bac..0b6d011 100644
--- a/app/test/test_bus.c
+++ b/app/test/test_bus.c
@@ -106,10 +106,26 @@ struct dummy_bus_map {
 struct rte_bus_list orig_bus_list =
 	TAILQ_HEAD_INITIALIZER(orig_bus_list);
 
+/* Forward declarations for callbacks from bus */
+
+/* Bus A
+ * Scan would register devA1 and devA2 to bus
+ */
+static int scan_fn_for_busA(void);
+
+/* Bus B
+ * Scan would register devB1 and devB2 to bus
+ */
+static int scan_fn_for_busB(void);
+
+/* generic implementations wrapped around by above declarations */
+static int generic_scan_fn(struct rte_bus *bus);
+
 struct dummy_bus busA = {
 	.name = "busA_impl", /* busA */
 	.bus = {
 		.name = "busA",
+		.scan = scan_fn_for_busA,
 	},
 };
 
@@ -117,6 +133,7 @@ struct dummy_bus busB = {
 	.name = "busB_impl", /* busB */
 	.bus = {
 		.name = "busB",
+		.scan = scan_fn_for_busB,
 	},
 };
 
@@ -226,9 +243,81 @@ dump_device_tree(void)
 	printf("------>8-------\n");
 }
 
+/* @internal
+ * Move over the bus_map and find the entry matching the bus object
+ * passed as argument.
+ * For each device in that bus_map list, register.
+ *
+ * @param bus
+ *	bus to scan againt test entry
+ * @return
+ *	0 for successful scan, even if no devices are found
+ *	!0 for any error in scanning (like, invalid bus)
+ */
+static int
+generic_scan_fn(struct rte_bus *bus)
+{
+	int i = 0;
+	struct dummy_device *ddev = NULL;
+	struct dummy_bus_map *dbmap = NULL;
+	struct dummy_bus *db = NULL;
+
+	if (!bus)
+		return -1;
+
+	/* Extract the device tree node using the bus passed */
+	for (i = 0; bus_map[i].name; i++) {
+		if (!strcmp(bus_map[i].name, bus->name)) {
+			dbmap = &bus_map[i];
+			break;
+		}
+	}
+
+	if (!dbmap)
+		return -1;
+
+	db = dbmap->dbus;
+
+	/* For all the devices in the device tree (bus_map), add device */
+	for (i = 0; dbmap->ddevices[i]; i++) {
+		ddev = dbmap->ddevices[i];
+		TAILQ_INSERT_TAIL(&db->device_list, ddev, next);
+		ddev->dev.bus = bus;
+	}
+
+	return 0;
+}
+
+int
+scan_fn_for_busA(void) {
+	struct dummy_bus_map *dbm;
+
+	dbm = &bus_map[0];
+	while (dbm) {
+		if (strcmp(dbm->name, "busA") == 0)
+			return generic_scan_fn(&dbm->dbus->bus);
+		dbm++;
+	}
+	return 1;
+}
+
+int
+scan_fn_for_busB(void) {
+	struct dummy_bus_map *dbm;
+
+	dbm = &bus_map[0];
+	while (dbm) {
+		if (strcmp(dbm->name, "busB") == 0)
+			return generic_scan_fn(&dbm->dbus->bus);
+		dbm++;
+	}
+	return 1;
+}
+
 static int
 test_bus_setup(void)
 {
+	int i = 0;
 	struct rte_bus *bus_p = NULL;
 
 	/* Preserve the original bus list before executing test */
@@ -238,6 +327,13 @@ test_bus_setup(void)
 		TAILQ_INSERT_TAIL(&orig_bus_list, bus_p, next);
 	}
 
+	/* Initialize the bus lists */
+	for (i = 0; bus_map[i].name; i++) {
+		TAILQ_INIT(&bus_map[i].dbus->device_list);
+		TAILQ_INIT(&bus_map[i].dbus->driver_list);
+	}
+
+	dump_device_tree();
 	return 0;
 }
 
@@ -336,6 +432,79 @@ test_bus_unregistration(void)
 	return 0;
 }
 
+static int
+test_device_unregistration_on_bus(void)
+{
+	int i;
+	struct rte_bus *bus = NULL;
+	struct dummy_device *ddev;
+	struct dummy_bus *dbus;
+
+	for (i = 0; bus_map[i].name; i++) {
+		bus = &(bus_map[i].dbus->bus);
+		if (!bus) {
+			printf("Unable to find bus (%s)\n",
+			       bus_map[i].name);
+			return -1;
+		}
+
+		dbus = container_of(bus, struct dummy_bus, bus);
+		/* For bus 'bus', unregister all devices */
+		TAILQ_FOREACH(ddev, &dbus->device_list, next) {
+			TAILQ_REMOVE(&dbus->device_list, ddev, next);
+		}
+	}
+
+	for (i = 0; bus_map[i].name; i++) {
+		bus = &(bus_map[i].dbus->bus);
+		dbus = container_of(bus, struct dummy_bus, bus);
+
+		if (!TAILQ_EMPTY(&dbus->device_list)) {
+			printf("Unable to remove all devices on bus (%s)\n",
+			       bus->name);
+			return -1;
+		}
+	}
+
+	/* All devices from all buses have been removed */
+	printf("All devices on all buses unregistered.\n");
+	dump_device_tree();
+
+	return 0;
+}
+
+/* @internal
+ * For each bus registered, call the scan function to identify devices
+ * on the bus.
+ *
+ * @param void
+ * @return
+ *	0 for successful scan
+ *	!0 for unsuccessful scan
+ *
+ */
+static int
+test_bus_scan(void)
+{
+	int ret;
+	struct rte_bus *bus;
+
+	TAILQ_FOREACH(bus, &rte_bus_list, next) {
+		/* Call the scan function for each bus */
+		ret = bus->scan();
+		if (ret) {
+			printf("Scan of buses failed.\n");
+			return -1;
+		}
+	}
+
+	printf("Scan of all buses completed.\n");
+	dump_device_tree();
+
+	return 0;
+}
+
+
 int
 test_bus(void)
 {
@@ -346,6 +515,12 @@ test_bus(void)
 	if (test_bus_registration())
 		return -1;
 
+	if (test_bus_scan())
+		return -1;
+
+	if (test_device_unregistration_on_bus())
+		return -1;
+
 	if (test_bus_unregistration())
 		return -1;
 
diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index c891392..35baff8 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -51,6 +51,8 @@ rte_bus_register(struct rte_bus *bus)
 {
 	RTE_VERIFY(bus);
 	RTE_VERIFY(bus->name && strlen(bus->name));
+	/* A bus should mandatorily have the scan implemented */
+	RTE_VERIFY(bus->scan);
 
 	TAILQ_INSERT_TAIL(&rte_bus_list, bus, next);
 	RTE_LOG(INFO, EAL, "Registered [%s] bus.\n", bus->name);
diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index fe0f69d..152451c 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -60,11 +60,29 @@ TAILQ_HEAD(rte_bus_list, rte_bus);
 extern struct rte_bus_list rte_bus_list;
 
 /**
+ * Bus specific scan for devices attached on the bus.
+ * For each bus object, the scan would be reponsible for finding devices and
+ * adding them to its private device list.
+ *
+ * A bus should mandatorily implement this method.
+ *
+ * Generic bus object passed only as a helper for implementation to find
+ * their respective registered bus object. Implementations can choose not
+ * to use this variable.
+ *
+ * @return
+ *	0 for successful scan
+ *	!0 (<0) for unsuccessful scan with error value
+ */
+typedef int (*rte_bus_scan_t)(void);
+
+/**
  * A structure describing a generic bus.
  */
 struct rte_bus {
 	TAILQ_ENTRY(rte_bus) next;   /**< Next bus object in linked list */
 	const char *name;            /**< Name of the bus */
+	rte_bus_scan_t scan;         /**< Scan for devices attached to bus */
 };
 
 /**
-- 
2.7.4

  parent reply	other threads:[~2017-01-17 10:06 UTC|newest]

Thread overview: 146+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-16 15:38 [PATCH v6 0/8] Introducing EAL Bus-Device-Driver Model Shreyansh Jain
2017-01-16 15:38 ` [PATCH v6 1/8] eal/bus: introduce bus abstraction Shreyansh Jain
2017-01-16 15:38 ` [PATCH v6 2/8] test: add basic bus infrastructure tests Shreyansh Jain
2017-01-16 15:38 ` [PATCH v6 3/8] pci: split match and probe function Shreyansh Jain
2017-01-16 18:24   ` Stephen Hemminger
2017-01-17 10:10     ` Shreyansh Jain
2017-01-16 19:53   ` Ferruh Yigit
2017-01-17  4:54     ` Shreyansh Jain
2017-01-17  9:58       ` Ferruh Yigit
2017-01-17 10:14         ` Shreyansh Jain
2017-01-16 15:38 ` [PATCH v6 4/8] eal/bus: support for scanning of bus Shreyansh Jain
2017-01-16 15:38 ` [PATCH v6 5/8] eal: introduce bus scan and probe in EAL Shreyansh Jain
2017-01-16 19:58   ` Ferruh Yigit
2017-01-17  5:03     ` Shreyansh Jain
2017-01-17 23:04       ` Thomas Monjalon
2017-01-17 10:13     ` Shreyansh Jain
2017-01-16 15:38 ` [PATCH v6 6/8] test: update bus and pci unit test cases Shreyansh Jain
2017-01-16 15:38 ` [PATCH v6 7/8] eal: enable PCI bus Shreyansh Jain
2017-01-16 19:58   ` Ferruh Yigit
2017-01-17  5:04     ` Shreyansh Jain
2017-01-17 10:11     ` Shreyansh Jain
2017-01-16 15:38 ` [PATCH v6 8/8] eal: enable hotplugging of devices on bus Shreyansh Jain
2017-01-17  7:24   ` Shreyansh Jain
2017-01-16 18:27 ` [PATCH v6 0/8] Introducing EAL Bus-Device-Driver Model Stephen Hemminger
2017-01-17  5:08   ` Shreyansh Jain
2017-01-17  5:09   ` Shreyansh Jain
2017-01-17 10:09 ` [PATCH v7 0/9] " Shreyansh Jain
2017-01-17 10:09   ` [PATCH v7 1/9] eal/bus: introduce bus abstraction Shreyansh Jain
2017-01-17 10:09   ` [PATCH v7 2/9] test: add basic bus infrastructure tests Shreyansh Jain
2017-01-17 10:09   ` [PATCH v7 3/9] pci: split match and probe function Shreyansh Jain
2017-01-17 10:09   ` Shreyansh Jain [this message]
2017-01-17 10:09   ` [PATCH v7 5/9] eal/bus: introduce support for bus probing Shreyansh Jain
2017-01-17 10:09   ` [PATCH v7 6/9] eal: integrate bus scan and probe with EAL Shreyansh Jain
2017-01-17 10:09   ` [PATCH v7 7/9] test: update bus and pci unit test cases Shreyansh Jain
2017-01-17 10:09   ` [PATCH v7 8/9] eal: enable PCI bus Shreyansh Jain
2017-01-17 10:09   ` [PATCH v7 9/9] eal: enable hotplugging of devices on bus Shreyansh Jain
2017-01-17 10:47     ` Ferruh Yigit
2017-01-17 11:04       ` Shreyansh Jain
2017-01-17 13:40         ` Shreyansh Jain
2017-01-17 10:50   ` [PATCH v7 0/9] Introducing EAL Bus-Device-Driver Model Ferruh Yigit
2017-01-17 13:37   ` [PATCH v8 " Shreyansh Jain
2017-01-17 13:37     ` [PATCH v8 1/9] eal/bus: introduce bus abstraction Shreyansh Jain
2017-01-17 23:19       ` Thomas Monjalon
2017-01-18  5:12         ` Shreyansh Jain
2017-01-17 13:37     ` [PATCH v8 2/9] test: add basic bus infrastructure tests Shreyansh Jain
2017-01-17 23:23       ` Thomas Monjalon
2017-01-18  5:13         ` Shreyansh Jain
2017-01-18  6:56           ` Shreyansh Jain
2017-01-18  7:28             ` Thomas Monjalon
2017-01-18  8:42               ` Shreyansh Jain
2017-01-17 13:37     ` [PATCH v8 3/9] pci: split match and probe function Shreyansh Jain
2017-01-17 23:31       ` Thomas Monjalon
2017-01-18  6:17         ` Shreyansh Jain
2017-01-18  7:31           ` Thomas Monjalon
2017-01-17 13:37     ` [PATCH v8 4/9] eal/bus: support for scanning of bus Shreyansh Jain
2017-01-17 23:37       ` Thomas Monjalon
2017-01-18  5:15         ` Shreyansh Jain
2017-01-18  7:32           ` Thomas Monjalon
2017-01-17 13:37     ` [PATCH v8 5/9] eal/bus: introduce support for bus probing Shreyansh Jain
2017-01-17 23:38       ` Thomas Monjalon
2017-01-17 13:37     ` [PATCH v8 6/9] eal: integrate bus scan and probe with EAL Shreyansh Jain
2017-01-17 23:44       ` Thomas Monjalon
2017-01-17 13:37     ` [PATCH v8 7/9] test: update bus and pci unit test cases Shreyansh Jain
2017-01-17 23:46       ` Thomas Monjalon
2017-01-17 13:37     ` [PATCH v8 8/9] eal: enable PCI bus Shreyansh Jain
2017-01-17 23:57       ` Thomas Monjalon
2017-01-17 13:37     ` [PATCH v8 9/9] eal: enable hotplugging of devices on bus Shreyansh Jain
2017-01-17 15:17       ` Ferruh Yigit
2017-01-18 10:37     ` [PATCH v9 00/12] Introducing EAL Bus-Device-Driver Model Shreyansh Jain
2017-01-18 10:37       ` [PATCH v9 01/12] eal/bus: introduce bus abstraction Shreyansh Jain
2017-01-18 10:46         ` Thomas Monjalon
2017-01-18 10:52           ` Shreyansh Jain
2017-01-18 10:37       ` [PATCH v9 02/12] test: add basic bus infrastructure tests Shreyansh Jain
2017-01-18 10:37       ` [PATCH v9 03/12] pci: split match and probe function Shreyansh Jain
2017-01-18 10:37       ` [PATCH v9 04/12] eal: remove loop over drivers in device detach Shreyansh Jain
2017-01-18 10:41         ` Shreyansh Jain
2017-01-18 11:12         ` Thomas Monjalon
2017-01-18 12:15           ` Shreyansh Jain
2017-01-18 10:37       ` [PATCH v9 05/12] eal/bus: support for scanning of bus Shreyansh Jain
2017-01-18 10:37       ` [PATCH v9 06/12] eal/bus: introduce support for bus probing Shreyansh Jain
2017-01-18 10:37       ` [PATCH v9 07/12] eal: integrate bus scan and probe with EAL Shreyansh Jain
2017-01-18 10:37       ` [PATCH v9 08/12] eal/pci: add support for PCI bus Shreyansh Jain
2017-01-18 10:37       ` [PATCH v9 09/12] test: add test cases for scan and probe on BUS Shreyansh Jain
2017-01-18 10:37       ` [PATCH v9 10/12] test: add Bus based scan and probe test cases for PCI Shreyansh Jain
2017-01-18 10:37       ` [PATCH v9 11/12] eal: enable PCI bus Shreyansh Jain
2017-01-18 10:38       ` [PATCH v9 12/12] eal: enable hotplugging of devices on bus Shreyansh Jain
2017-01-18 11:10       ` [PATCH v9 00/12] Introducing EAL Bus-Device-Driver Model Thomas Monjalon
2017-01-18 14:05       ` [PATCH v10 00/13] " Shreyansh Jain
2017-01-18 14:05         ` [PATCH v10 01/13] eal/bus: introduce bus abstraction Shreyansh Jain
2017-01-18 14:05         ` [PATCH v10 02/13] test: add basic bus infrastructure tests Shreyansh Jain
2017-01-18 14:05         ` [PATCH v10 03/13] pci: split match and probe function Shreyansh Jain
2017-01-18 14:05         ` [PATCH v10 04/13] eal: remove loop over drivers in device detach Shreyansh Jain
2017-01-18 14:05         ` [PATCH v10 05/13] eal/bus: support for scanning of bus Shreyansh Jain
2017-01-18 14:05         ` [PATCH v10 06/13] eal/bus: introduce support for bus probing Shreyansh Jain
2017-01-18 14:05         ` [PATCH v10 07/13] eal: integrate bus scan and probe with EAL Shreyansh Jain
2017-01-18 14:05         ` [PATCH v10 08/13] eal/pci: add support for PCI bus Shreyansh Jain
2017-01-18 14:05         ` [PATCH v10 09/13] test: add test cases for scan and probe on BUS Shreyansh Jain
2017-01-18 14:05         ` [PATCH v10 10/13] test: add Bus based scan and probe test cases for PCI Shreyansh Jain
2017-01-18 14:05         ` [PATCH v10 11/13] eal: enable PCI bus Shreyansh Jain
2017-01-18 14:05         ` [PATCH v10 12/13] eal: enable hotplugging of devices on bus Shreyansh Jain
2017-01-18 14:05         ` [PATCH v10 13/13] doc: remove deprecation notice for rte_bus Shreyansh Jain
2017-01-19  4:45         ` [PATCH v11 00/13] rte_bus + rte_pci_bus Thomas Monjalon
2017-01-19  4:45           ` [PATCH v11 01/13] bus: introduce bus abstraction Thomas Monjalon
2017-01-19  4:45           ` [PATCH v11 02/13] bus: add scanning Thomas Monjalon
2017-01-19  4:45           ` [PATCH v11 03/13] bus: add probing Thomas Monjalon
2017-01-19  4:45           ` [PATCH v11 04/13] app/test: check bus registration Thomas Monjalon
2017-01-19  4:45           ` [PATCH v11 05/13] app/test: check bus scan Thomas Monjalon
2017-01-19  4:45           ` [PATCH v11 06/13] app/test: check bus probe Thomas Monjalon
2017-01-19  4:45           ` [PATCH v11 07/13] pci: split match and probe Thomas Monjalon
2017-02-15 10:45             ` Jan Blunck
2017-02-15 11:22               ` Thomas Monjalon
2017-02-15 11:52                 ` Shreyansh Jain
2017-02-15 11:30               ` Shreyansh Jain
2017-01-19  4:45           ` [PATCH v11 08/13] pci: remove loop over drivers in device detach Thomas Monjalon
2017-01-19  4:45           ` [PATCH v11 09/13] pci: add bus driver Thomas Monjalon
2017-02-15 10:42             ` Jan Blunck
2017-02-15 11:20               ` Thomas Monjalon
2017-01-19  4:45           ` [PATCH v11 10/13] app/test: add PCI " Thomas Monjalon
2017-01-19  4:45           ` [PATCH v11 11/13] pci: use bus driver for scan/probe Thomas Monjalon
2017-01-19  4:45           ` [PATCH v11 12/13] pci: use bus driver for attach/detach Thomas Monjalon
2017-02-15 11:08             ` Jan Blunck
2017-02-15 11:26               ` Thomas Monjalon
2017-02-15 11:39                 ` Jan Blunck
2017-02-15 14:04                   ` [RFC] eal: use busname and devargs to attach devices Jan Blunck
2017-01-19  4:45           ` [PATCH v11 13/13] doc: remove deprecation notice for rte_bus Thomas Monjalon
2017-01-19 17:40             ` Mcnamara, John
2017-01-19  4:50           ` [PATCH v11 00/13] rte_bus + rte_pci_bus Thomas Monjalon
2017-04-07 15:28           ` [PATCH v12 0/5] rte_bus_pci Gaetan Rivet
2017-04-07 15:28             ` [PATCH v12 1/5] pci: split match and probe Gaetan Rivet
2017-04-07 15:28             ` [PATCH v12 2/5] pci: remove loop over drivers in device detach Gaetan Rivet
2017-04-07 15:28             ` [PATCH v12 3/5] pci: add bus driver Gaetan Rivet
2017-04-07 15:28             ` [PATCH v12 4/5] pci: use bus driver for scan/probe Gaetan Rivet
2017-04-07 15:28             ` [PATCH v12 5/5] test: remove pci tests Gaetan Rivet
2017-04-11 11:07             ` [PATCH v13 0/7] rte_bus_pci Gaetan Rivet
2017-04-11 11:07               ` [PATCH v13 1/7] test: remove pci tests Gaetan Rivet
2017-04-11 11:07               ` [PATCH v13 2/7] pci: split match and probe Gaetan Rivet
2017-04-11 11:07               ` [PATCH v13 3/7] pci: remove loop over drivers in device detach Gaetan Rivet
2017-04-11 11:07               ` [PATCH v13 4/7] pci: add bus driver Gaetan Rivet
2017-04-11 11:07               ` [PATCH v13 5/7] pci: use bus driver for scan/probe Gaetan Rivet
2017-04-11 11:07               ` [PATCH v13 6/7] pci: use bus driver for attach/detach Gaetan Rivet
2017-04-14  8:43                 ` Thomas Monjalon
2017-04-11 11:07               ` [PATCH v13 7/7] doc: remove deprecation notice for rte_bus Gaetan Rivet
2017-04-11 11:32                 ` Shreyansh Jain
2017-04-11 11:54                   ` Gaëtan Rivet
2017-04-12 16:09               ` [PATCH v13 0/7] rte_bus_pci Stephen Hemminger
2017-04-14 12:16                 ` 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=1484647774-28984-5-git-send-email-shreyansh.jain@nxp.com \
    --to=shreyansh.jain@nxp.com \
    --cc=david.marchand@6wind.com \
    --cc=dev@dpdk.org \
    --cc=thomas.monjalon@6wind.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.