[Accel-config] [PATCH v3 3/4] accel-config: Store bus type in device context

ramesh.thomas at intel.com
Newsgroups dev.linux.lists.accel-config
Message-ID <[email protected]>
From: Ramesh Thomas <ramesh.thomas(a)intel.com>

Store bus type in device context to be used as the driver in compat
modes. It will be also used to construct driver bind paths in all modes.

Signed-off-by: Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccfg.c | 48 ++++++++++++++++++++++++++------------------
 accfg/lib/private.h  |  1 +
 util/sysfs.c         |  5 +++--
 util/sysfs.h         | 13 ++++++------
 4 files changed, 40 insertions(+), 27 deletions(-)

diff --git a/accfg/lib/libaccfg.c b/accfg/lib/libaccfg.c
index 58ad97f..c1b27b3 100644
--- a/accfg/lib/libaccfg.c
+++ b/accfg/lib/libaccfg.c
@@ -30,6 +30,12 @@
 #define MDEV_POSTFIX "mdev_supported_types"
 #define IDXD_DRIVER_BIND_PATH "/sys/bus/dsa/drivers/idxd"
 
+char *accfg_bus_types[] = {
+	"dsa",
+	"iax",
+	NULL
+};
+
 const char *accfg_wq_mode_str[] = {
 	[ACCFG_WQ_SHARED]	= "shared",
 	[ACCFG_WQ_DEDICATED]	= "dedicated",
@@ -407,10 +413,11 @@ ACCFG_EXPORT void accfg_set_log_priority(struct accfg_ctx *ctx,
 }
 
 static int device_parse(struct accfg_ctx *ctx, const char *base_path,
-			char *dev_prefix, int (*filter)(const struct dirent *),
+			char *dev_prefix, char *bus_type,
+			int (*filter)(const struct dirent *),
 			void *parent, add_dev_fn add_dev)
 {
-	return sysfs_device_parse(ctx, base_path, dev_prefix,
+	return sysfs_device_parse(ctx, base_path, dev_prefix, bus_type,
 			filter, parent, add_dev);
 }
 
@@ -495,7 +502,8 @@ exit_add_mdev:
 	return rc;
 }
 
-static void *add_device(void *parent, int id, const char *ctl_base, char *dev_prefix)
+static void *add_device(void *parent, int id, const char *ctl_base,
+		char *dev_prefix, char *bus_type)
 {
 	struct accfg_ctx *ctx = parent;
 	struct accfg_device *device;
@@ -592,6 +600,8 @@ static void *add_device(void *parent, int id, const char *ctl_base, char *dev_pr
 	if (rc < 0)
 		goto err_dev_path;
 
+	device->bus_type_str = bus_type;
+
 	if (device->mdev_path && add_device_mdevs(ctx, device))
 		goto err_dev_path;
 
@@ -639,7 +649,7 @@ static int wq_parse_type(struct accfg_wq *wq, char *wq_type)
 }
 
 static void *add_wq(void *parent, int id, const char *wq_base,
-		char *dev_prefix)
+		char *dev_prefix, char *bus_type)
 {
 	struct accfg_wq *wq;
 	struct accfg_device *device = parent;
@@ -736,7 +746,7 @@ err_wq:
 }
 
 static void *add_group(void *parent, int id, const char *group_base,
-		char *dev_prefix)
+		char *dev_prefix, char *bus_type)
 {
 	struct accfg_group *group;
 	struct accfg_device *device = parent;
@@ -824,7 +834,7 @@ err_group:
 }
 
 static void *add_engine(void *parent, int id, const char *engine_base,
-		char *dev_prefix)
+		char *dev_prefix, char *bus_type)
 {
 	struct accfg_engine *engine;
 	struct accfg_device *device = parent;
@@ -927,14 +937,15 @@ static void groups_init(struct accfg_device *device)
 	device->group_init = 1;
 	set_filename_prefix("group");
 	device_parse(device->ctx, device->device_path, "group",
-			filter_file_name_prefix,
+			device->bus_type_str, filter_file_name_prefix,
 			device, add_group);
 }
 
 static void devices_init(struct accfg_ctx *ctx)
 {
 	char **accel_name;
-	char *path;
+	char **bus_type;
+	char path[PATH_MAX];
 	struct accfg_device *device;
 
 	if (ctx->devices_init) {
@@ -943,16 +954,15 @@ static void devices_init(struct accfg_ctx *ctx)
 	}
 	ctx->devices_init = 1;
 
-	for (accel_name = accfg_basenames; *accel_name != NULL;
-		accel_name++) {
-		if (asprintf(&path, "/sys/bus/%s/devices", *accel_name) < 0) {
-			err(ctx, "devices_init set path failed\n");
-			continue;
+	for (bus_type = accfg_bus_types; *bus_type != NULL; bus_type++) {
+		sprintf(path, "/sys/bus/%s/devices", *bus_type);
+		for (accel_name = accfg_basenames; *accel_name != NULL;
+				accel_name++) {
+			set_filename_prefix(*accel_name);
+			device_parse(ctx, path, *accel_name, *bus_type,
+					filter_file_name_prefix, ctx,
+					add_device);
 		}
-		set_filename_prefix(*accel_name);
-		device_parse(ctx, path, *accel_name,
-				filter_file_name_prefix, ctx, add_device);
-		free(path);
 	}
 
 	accfg_device_foreach(ctx, device) {
@@ -974,7 +984,7 @@ static void engines_init(struct accfg_device *device)
 	}
 	set_filename_prefix("engine");
 	device_parse(ctx, device->device_path, "engine",
-			filter_file_name_prefix, device,
+			device->bus_type_str, filter_file_name_prefix, device,
 			add_engine);
 }
 
@@ -1705,7 +1715,7 @@ static void wqs_init(struct accfg_device *device)
 		group->wqs_init = 1;
 	}
 	set_filename_prefix("wq");
-	device_parse(ctx, device->device_path, "wq",
+	device_parse(ctx, device->device_path, "wq", device->bus_type_str,
 			filter_file_name_prefix, device, add_wq);
 }
 
diff --git a/accfg/lib/private.h b/accfg/lib/private.h
index f407643..7f3162e 100644
--- a/accfg/lib/private.h
+++ b/accfg/lib/private.h
@@ -32,6 +32,7 @@ struct accfg_device {
 	char *device_path;
 	char *mdev_path;
 	char *device_buf;
+	char *bus_type_str;
 	char *device_type_str;
 	enum accfg_device_type type;
 	size_t buf_len;
diff --git a/util/sysfs.c b/util/sysfs.c
index 41f6a73..b2ad502 100644
--- a/util/sysfs.c
+++ b/util/sysfs.c
@@ -75,7 +75,8 @@ int __sysfs_write_attr_quiet(struct log_ctx *ctx, const char *path,
 	return write_attr(ctx, path, buf, 1);
 }
 
-int __sysfs_device_parse(struct log_ctx *ctx, const char *base_path, char *dev_prefix,
+int __sysfs_device_parse(struct log_ctx *ctx, const char *base_path,
+			char *dev_prefix, char *bus_type,
 			int (*filter)(const struct dirent *),
 			void *parent, add_dev_fn add_dev)
 {
@@ -104,7 +105,7 @@ int __sysfs_device_parse(struct log_ctx *ctx, const char *base_path, char *dev_p
 				de->d_name, id);
 			continue;
 		}
-		dev = add_dev(parent, id, dev_path, dev_prefix);
+		dev = add_dev(parent, id, dev_path, dev_prefix, bus_type);
 		free(dev_path);
 		if (!dev) {
 			add_errors++;
diff --git a/util/sysfs.h b/util/sysfs.h
index 497b015..abd4701 100644
--- a/util/sysfs.h
+++ b/util/sysfs.h
@@ -8,7 +8,7 @@
 #include <dirent.h>
 
 typedef void *(*add_dev_fn)(void *parent, int id, const char *dev_path,
-		char *dev_prefix);
+		char *dev_prefix, char *bus_type);
 
 #define SYSFS_ATTR_SIZE 1024
 
@@ -17,15 +17,16 @@ int __sysfs_read_attr(struct log_ctx *ctx, const char *path, char *buf);
 int __sysfs_write_attr(struct log_ctx *ctx, const char *path, const char *buf);
 int __sysfs_write_attr_quiet(struct log_ctx *ctx, const char *path,
 		const char *buf);
-int __sysfs_device_parse(struct log_ctx *ctx, const char *base_path, char *dev_prefix,
-				int (*filter)(const struct dirent *),
-				void *parent, add_dev_fn add_dev);
+int __sysfs_device_parse(struct log_ctx *ctx, const char *base_path,
+		char *dev_prefix, char *bus_type,
+		int (*filter)(const struct dirent *),
+		void *parent, add_dev_fn add_dev);
 
 #define sysfs_read_attr(c, p, b) __sysfs_read_attr(&(c)->ctx, (p), (b))
 #define sysfs_write_attr(c, p, b) __sysfs_write_attr(&(c)->ctx, (p), (b))
 #define sysfs_write_attr_quiet(c, p, b) __sysfs_write_attr_quiet(&(c)->ctx, (p), (b))
-#define sysfs_device_parse(c, b, d, m, p, fn) __sysfs_device_parse(&(c)->ctx, \
-		(b), (d), (m), (p), (fn))
+#define sysfs_device_parse(c, b, d, bt, m, p, fn) __sysfs_device_parse(&(c)->ctx, \
+		(b), (d), (bt), (m), (p), (fn))
 
 static inline const char *devpath_to_devname(const char *devpath)
 {
-- 
2.26.2
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.