All of lore.kernel.org
 help / color / mirror / Atom feed
* [Accel-config] [PATCH v1 3/4] accel-config: Store bus type in device context
@ 2021-03-11 18:03 ramesh.thomas
  0 siblings, 0 replies; only message in thread
From: ramesh.thomas @ 2021-03-11 18:03 UTC (permalink / raw)
  To: accel-config

[-- Attachment #1: Type: text/plain, Size: 7505 bytes --]

From: Ramesh Thomas <ramesh.thomas(a)intel.com>

Store bus type in device context to be used as the driver portal in
compat modes. It will be also used to construct driver paths which will
work 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 25d783c..6e472d4 100644
--- a/accfg/lib/libaccfg.c
+++ b/accfg/lib/libaccfg.c
@@ -31,6 +31,12 @@
 #define IDXD_DRIVER_PATH "/sys/bus/dsa/drivers/"
 #define IDXD_DRIVER_PORTAL "idxd"
 
+char *accfg_bus_types[] = {
+	"dsa",
+	"iax",
+	NULL
+};
+
 const char *accfg_wq_mode_str[] = {
 	[ACCFG_WQ_SHARED]	= "shared",
 	[ACCFG_WQ_DEDICATED]	= "dedicated",
@@ -408,10 +414,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);
 }
 
@@ -496,7 +503,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;
@@ -593,6 +601,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;
 
@@ -640,7 +650,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;
@@ -737,7 +747,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;
@@ -825,7 +835,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;
@@ -928,14 +938,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) {
@@ -944,16 +955,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) {
@@ -975,7 +985,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);
 }
 
@@ -1706,7 +1716,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

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-11 18:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-11 18:03 [Accel-config] [PATCH v1 3/4] accel-config: Store bus type in device context ramesh.thomas

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.