Skip to contentSkip to conversation

Add support for ABI change in driver

PATCH Superseded ramesh.thomas at intel.com 2 participants 7 messages Mar 11, 2021

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

ramesh.thomas at intel.com

#0 lore raw

cover Add support for ABI change in driver

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

The new ABI changes the way devices are enumerated in sysfs and the driver portals used to bind and unbind. These patches add support for the new ABI as well as compatibility with the ones in older kernels.

Following are the modes that are supported.

1. New ABI:

- Both iax and dsa devices will be in same bus /sys/bus/dsa
- Different driver portals for "user", "kernel" and "mdev" type wqs

2. Kernel 5.11 and 5.12:

- iax and dsa will be in 2 separate buses
- Bus, device and driver portal names are same

3. Older kernels :

- Has only dsa bus

4. OSV having kernel with CONFIG_INTEL_IDXD_COMPAT enabled:

- Only one dsa bus
- Both iax and dsa devices will be on dsa bus.
- Only one driver portal for all wq types

Following are the changes added.

- Detect compatibility mode during init and store bus, driver and portal details in device contexts.

- Currently enumeration assumes device, bus and driver have the same name and relies on that to construct paths. Change it to dynamically construct paths based on compatibility mode that was detected during init.

Ramesh Thomas (4):
accel-config: Fix some indentation and coding style issues
accel-config: Add compatibility mode detection
accel-config: Store bus type in device context
accel-config: Add support for new driver portals

 accfg/lib/libaccfg.c    | 80 +++++++++++++++++++++++++++++------------
 accfg/lib/private.h     | 70 ++++++++++++++++++------------------
 accfg/libaccel_config.h | 37 +++++++++----------
 util/sysfs.c            |  5 +--
 util/sysfs.h            | 13 +++----
 5 files changed, 122 insertions(+), 83 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/4 accel-config: Fix some indentation and coding style issues

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

Fix indentation issues to make patch review easier

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/private.h     | 68 ++++++++++++++++++++---------------------
 accfg/libaccel_config.h | 34 ++++++++++-----------
 2 files changed, 51 insertions(+), 51 deletions(-)
accfg/lib/private.h +34 -34
index 24e2ee8..0fdc5d5 100644
@@ -20,32 +20,32 @@
 
 struct accfg_device {
 	struct accfg_ctx *ctx;
-        unsigned int id;
-	struct accfg_group* group;
-	struct accfg_wq* wq;
-	struct accfg_engine* engine;
+	unsigned int id;
+	struct accfg_group *group;
+	struct accfg_wq *wq;
+	struct accfg_engine *engine;
 	struct list_head groups;
 	struct list_head wqs;
 	struct list_head engines;
-        struct list_node list;
+	struct list_node list;
 	int group_init;
-        char *device_path;
+	char *device_path;
 	char *mdev_path;
-        char *device_buf;
+	char *device_buf;
 	char *device_type_str;
 	enum accfg_device_type type;
-        size_t buf_len;
+	size_t buf_len;
 	struct list_head mdev_list;
 
 	/* Device Attributes */
 	struct accfg_error errors;
 	int max_groups;
-        int max_work_queues;
-        int max_engines;
-        int max_work_queues_size;
-        int numa_node;
-        int ims_size;
-        int max_batch_size;
+	int max_work_queues;
+	int max_engines;
+	int max_work_queues_size;
+	int numa_node;
+	int ims_size;
+	int max_batch_size;
 	int configurable;
 	int max_tokens;
 	unsigned int token_limit;
@@ -65,9 +65,9 @@ struct accfg_device_mdev {
 };
 
 struct accfg_group {
-        struct accfg_device *device;
-        int id;
-        int buf_len;
+	struct accfg_device *device;
+	int id;
+	int buf_len;
 	int size;
 	char *group_path;
 	char *group_buf;
@@ -91,12 +91,12 @@ struct accfg_group {
 
 struct accfg_engine {
 	struct accfg_device *device;
-        struct accfg_group *group;
-        struct list_node list;
-        char *engine_path;
-        char *engine_buf;
-        int type, id, buf_len;
-        int numa_node;
+	struct accfg_group *group;
+	struct list_node list;
+	char *engine_path;
+	char *engine_buf;
+	int type, id, buf_len;
+	int numa_node;
 
 	/* Engine Attributes */
 	int group_id;
@@ -104,12 +104,12 @@ struct accfg_engine {
 
 struct accfg_wq {
 	struct accfg_device *device;
-        struct accfg_group *group;
+	struct accfg_group *group;
 	struct list_node list;
 	char *wq_path;
-        char *wq_buf;
-        int id, buf_len;
-        int numa_node;
+	char *wq_buf;
+	int id, buf_len;
+	int numa_node;
 
 	/* Workqueue Attributes */
 	int group_id;
@@ -138,23 +138,23 @@ struct accfg_wq {
  * @timeout: default library timeout in milliseconds
  */
 struct accfg_ctx {
-        /* log_ctx must be first member for accfg_set_log_fn compat */
-        struct log_ctx ctx;
-        int refcount;
-        int devices_init;
+	/* log_ctx must be first member for accfg_set_log_fn compat */
+	struct log_ctx ctx;
+	int refcount;
+	int devices_init;
 	int groups_init;
 	struct list_head devices;
 	uint64_t timeout;
-        void *private_data;
+	void *private_data;
 };
 
 static inline int check_udev(struct udev *udev)
 {
-        return udev ? 0 : -ENXIO;
+	return udev ? 0 : -ENXIO;
 }
 
 static inline int check_kmod(struct kmod_ctx *kmod_ctx)
 {
-        return kmod_ctx ? 0 : -ENXIO;
+	return kmod_ctx ? 0 : -ENXIO;
 }
 #endif /* _LIBACCFG_PRIVATE_H_ */
accfg/libaccel_config.h +17 -17
index 95bb5d2..091c388 100644
@@ -76,7 +76,7 @@ enum accfg_mdev_type {
 
 /* no need to save device error */
 struct accfg_error {
-        uint64_t val[4];
+	uint64_t val[4];
 };
 
 /* parameters read from sysfs of accfg driver */
@@ -131,7 +131,7 @@ int accfg_new(struct accfg_ctx **ctx);
 
 /* override default log routine */
 void accfg_set_log_fn(struct accfg_ctx *ctx,
-void (*log_fn) (struct accfg_ctx * ctx,
+void (*log_fn)(struct accfg_ctx *ctx,
 	       int priority, const char *file,
 	       int line, const char *fn,
 	       const char *format,
@@ -147,9 +147,9 @@ int accfg_device_disable(struct accfg_device *device, bool force);
 struct accfg_device *accfg_device_get_first(struct accfg_ctx *ctx);
 struct accfg_device *accfg_device_get_next(struct accfg_device *device);
 #define accfg_device_foreach(ctx, device) \
-        for (device = accfg_device_get_first(ctx); \
-             device != NULL; \
-             device = accfg_device_get_next(device))
+	for (device = accfg_device_get_first(ctx); \
+	     device != NULL; \
+	     device = accfg_device_get_next(device))
 struct accfg_ctx *accfg_device_get_ctx(struct accfg_device *);
 const char *accfg_device_get_devname(struct accfg_device *device);
 int accfg_device_type_validate(const char *dev_name);
@@ -184,7 +184,7 @@ int accfg_device_get_clients(struct accfg_device *device);
 int accfg_device_set_token_limit(struct accfg_device *dev, int val);
 int accfg_device_is_active(struct accfg_device *device);
 int accfg_device_get_cmd_status(struct accfg_device *device);
-const char * accfg_device_get_cmd_status_str(struct accfg_device *device);
+const char *accfg_device_get_cmd_status_str(struct accfg_device *device);
 
 struct accfg_device_mdev;
 struct accfg_device_mdev *accfg_device_first_mdev(struct accfg_device *device);
@@ -205,9 +205,9 @@ struct accfg_group;
 struct accfg_group *accfg_group_get_first(struct accfg_device *device);
 struct accfg_group *accfg_group_get_next(struct accfg_group *group);
 #define accfg_group_foreach(device, group) \
-        for (group = accfg_group_get_first(device); \
-             group != NULL; \
-             group = accfg_group_get_next(group))
+	for (group = accfg_group_get_first(device); \
+	     group != NULL; \
+	     group = accfg_group_get_next(group))
 int accfg_group_get_id(struct accfg_group *group);
 struct accfg_group *accfg_device_group_get_by_id(struct accfg_device *device,
 						int id);
@@ -235,9 +235,9 @@ struct accfg_wq *accfg_wq_get_next(struct accfg_wq *wq);
 
 
 #define accfg_wq_foreach(device, wq) \
-        for (wq = accfg_wq_get_first(device); \
-             wq != NULL; \
-             wq = accfg_wq_get_next(wq))
+	for (wq = accfg_wq_get_first(device); \
+	     wq != NULL; \
+	     wq = accfg_wq_get_next(wq))
 
 struct accfg_ctx *accfg_wq_get_ctx(struct accfg_wq *wq);
 struct accfg_device *accfg_wq_get_device(struct accfg_wq *wq);
@@ -268,9 +268,9 @@ int accfg_wq_set_threshold(struct accfg_wq *wq, int val);
 int accfg_wq_set_block_on_fault(struct accfg_wq *wq, int val);
 int accfg_wq_set_max_batch_size(struct accfg_wq *wq, int val);
 int accfg_wq_set_max_transfer_size(struct accfg_wq *wq, uint64_t val);
-int accfg_wq_set_str_mode(struct accfg_wq *wq, const char* val);
+int accfg_wq_set_str_mode(struct accfg_wq *wq, const char *val);
 int accfg_wq_set_mode(struct accfg_wq *wq, enum accfg_wq_mode mode);
-int accfg_wq_set_str_type(struct accfg_wq *wq, const char* val);
+int accfg_wq_set_str_type(struct accfg_wq *wq, const char *val);
 int accfg_wq_set_str_name(struct accfg_wq *wq, const char *val);
 int accfg_wq_enable(struct accfg_wq *wq);
 int accfg_wq_disable(struct accfg_wq *wq, bool force);
@@ -282,9 +282,9 @@ struct accfg_engine;
 struct accfg_engine *accfg_engine_get_first(struct accfg_device *device);
 struct accfg_engine *accfg_engine_get_next(struct accfg_engine *engine);
 #define accfg_engine_foreach(device, engine) \
-        for (engine = accfg_engine_get_first(device); \
-             engine != NULL; \
-             engine = accfg_engine_get_next(engine))
+	for (engine = accfg_engine_get_first(device); \
+	     engine != NULL; \
+	     engine = accfg_engine_get_next(engine))
 struct accfg_ctx *accfg_engine_get_ctx(struct accfg_engine *engine);
 struct accfg_device *accfg_engine_get_device(struct accfg_engine *engine);
 struct accfg_group *accfg_engine_get_group(struct accfg_engine *engine);
Signature · 1 line
2.26.2
#2 lore raw

PATCH 2/4 accel-config: Add compatibility mode detection

In reply to ramesh.thomas at intel.com

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

Add a flag in accfg context to store commpatibility mode. Absence of /sys/bus/dsa/drivers/idxd indicates compatibility mode.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccfg.c | 5 +++++
 accfg/lib/private.h  | 1 +
 2 files changed, 6 insertions(+)
accfg/lib/libaccfg.c +5 -0
index 450be4f..25d783c 100644
@@ -28,6 +28,8 @@
 #include "private.h"
 
 #define MDEV_POSTFIX "mdev_supported_types"
+#define IDXD_DRIVER_PATH "/sys/bus/dsa/drivers/"
+#define IDXD_DRIVER_PORTAL "idxd"
 
 const char *accfg_wq_mode_str[] = {
 	[ACCFG_WQ_SHARED]	= "shared",
@@ -310,6 +312,9 @@ ACCFG_EXPORT int accfg_new(struct accfg_ctx **ctx)
 	c->refcount = 1;
 	log_init(&c->ctx, "libaccfg", "ACCFG_LOG");
 	c->timeout = 5000;
+	if (access(IDXD_DRIVER_PATH IDXD_DRIVER_PORTAL, R_OK))
+		c->compat = true;
+
 	list_head_init(&c->devices);
 
 	info(c, "ctx %p created\n", c);
accfg/lib/private.h +1 -0
index 0fdc5d5..f407643 100644
@@ -146,6 +146,7 @@ struct accfg_ctx {
 	struct list_head devices;
 	uint64_t timeout;
 	void *private_data;
+	bool compat;
 };
 
 static inline int check_udev(struct udev *udev)
Signature · 1 line
2.26.2
#3 lore raw

[Accel-config] Re: [PATCH v1 2/4] accel-config: Add compatibility mode detection

Quoted 16 lines · ramesh.thomas(a)intel.com

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

Add a flag in accfg context to store commpatibility mode. Absence of /sys/bus/dsa/drivers/idxd indicates compatibility mode.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
  accfg/lib/libaccfg.c | 5 +++++
  accfg/lib/private.h  | 1 +
  2 files changed, 6 insertions(+)
accfg/lib/libaccfg.c +0 -0
index 450be4f..25d783c 100644

accfg/lib/libaccfg.c line 32

Quoted 5 lines
accfg/lib/libaccfg.c +2 -0
@@ -28,6 +28,8 @@
  #include "private.h"
 
  #define MDEV_POSTFIX "mdev_supported_types"
+#define IDXD_DRIVER_PATH "/sys/bus/dsa/drivers/"
+#define IDXD_DRIVER_PORTAL "idxd"

Portal is actually a device term. We have portal drivers for the WQ but not the device. Maybe IDXD_DRIVER_BIND_PATH?

accfg/lib/libaccfg.c ACCFG_EXPORT int accfg_new(struct accfg_ctx **ctx) · line 315

Quoted 8 lines
accfg/lib/libaccfg.c +1 -0
  const char *accfg_wq_mode_str[] = {
  	[ACCFG_WQ_SHARED]	= "shared",
@@ -310,6 +312,9 @@ ACCFG_EXPORT int accfg_new(struct accfg_ctx **ctx)
  	c->refcount = 1;
  	log_init(&c->ctx, "libaccfg", "ACCFG_LOG");
  	c->timeout = 5000;
+	if (access(IDXD_DRIVER_PATH IDXD_DRIVER_PORTAL, R_OK))

I think you want to detect /sys/bus/dsa/drivers/dsa to be in compat mode? If COMPAT is turned off, /sys/bus/dsa/drivers/dsa would not exist.

Quoted 17 lines
accfg/lib/libaccfg.c +2 -0
+		c->compat = true;
+
  	list_head_init(&c->devices);
 
  	info(c, "ctx %p created\n", c);
accfg/lib/private.h +1 -0
index 0fdc5d5..f407643 100644
@@ -146,6 +146,7 @@ struct accfg_ctx {
  	struct list_head devices;
  	uint64_t timeout;
  	void *private_data;
+	bool compat;
  };
 
  static inline int check_udev(struct udev *udev)
#4 lore raw

[Accel-config] Re: [PATCH v1 2/4] accel-config: Add compatibility mode detection

Quoted 20 lines · Dave Jiang
Quoted 18 lines · ramesh.thomas(a)intel.com

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

Add a flag in accfg context to store commpatibility mode. Absence of /sys/bus/dsa/drivers/idxd indicates compatibility mode.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
  accfg/lib/libaccfg.c | 5 +++++
  accfg/lib/private.h  | 1 +
  2 files changed, 6 insertions(+)
accfg/lib/libaccfg.c +0 -0
index 450be4f..25d783c 100644
@@ -28,6 +28,8 @@
  #include "private.h"
 
Quoted 6 lines

accfg/lib/libaccfg.c line 32

Quoted 3 lines
accfg/lib/libaccfg.c +2 -0
  #define MDEV_POSTFIX "mdev_supported_types"
+#define IDXD_DRIVER_PATH "/sys/bus/dsa/drivers/"
+#define IDXD_DRIVER_PORTAL "idxd"

Portal is actually a device term. We have portal drivers for the WQ but not the device. Maybe IDXD_DRIVER_BIND_PATH?

Ok, will combine the 2 into one.
#define IDXD_DRIVER_BIND_PATH "/sys/bus/dsa/drivers/idxd"

(Looks like there was a merge issue. This will be in patch #2 in next version.)

Quoted 12 lines

accfg/lib/libaccfg.c ACCFG_EXPORT int accfg_new(struct accfg_ctx **ctx) · line 315

Quoted 9 lines
accfg/lib/libaccfg.c +1 -0
  const char *accfg_wq_mode_str[] = {
  	[ACCFG_WQ_SHARED]	= "shared",
@@ -310,6 +312,9 @@ ACCFG_EXPORT int accfg_new(struct accfg_ctx **ctx)
  	c->refcount = 1;
  	log_init(&c->ctx, "libaccfg", "ACCFG_LOG");
  	c->timeout = 5000;
+	if (access(IDXD_DRIVER_PATH IDXD_DRIVER_PORTAL, R_OK))

I think you want to detect /sys/bus/dsa/drivers/dsa to be in compat mode? If COMPAT is turned off, /sys/bus/dsa/drivers/dsa would not exist.

"compat mode" in accel-config refers to it being compatible with ABI in older kernels. It does not mean the kernel mode enabled by CONFIG_INTEL_IDXD_COMPAT.

There can be a case in older kernels with only iax devices being present, resulting in /sys/bus/iax/drivers/iax. Whereas /sys/bus/dsa/drivers/idxd will never be present in older kernels. In kernels with the new ABI, if ".../idxd" is found then accel-config will use new ABI as it should, irrespective of the kernel being built with CONFIG_INTEL_IDXD_COMPAT enabled or not.

Quoted 19 lines
Quoted 19 lines
accfg/lib/libaccfg.c +2 -0
+		c->compat = true;
+
  	list_head_init(&c->devices);
 
  	info(c, "ctx %p created\n", c);
accfg/lib/private.h +1 -0
index 0fdc5d5..f407643 100644
@@ -146,6 +146,7 @@ struct accfg_ctx {
  	struct list_head devices;
  	uint64_t timeout;
  	void *private_data;
+	bool compat;
  };
 
  static inline int check_udev(struct udev *udev)
#5 lore raw

PATCH 3/4 accel-config: Store bus type in device context

In reply to ramesh.thomas at intel.com

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(-)
accfg/lib/libaccfg.c +29 -19
index 25d783c..6e472d4 100644
@@ -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);
 }
 
accfg/lib/private.h +1 -0
index f407643..7f3162e 100644
@@ -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;
util/sysfs.c +3 -2
index 41f6a73..b2ad502 100644
@@ -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++;
util/sysfs.h +7 -6
index 497b015..abd4701 100644
@@ -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)
 {
Signature · 1 line
2.26.2
#6 lore raw

PATCH 4/4 accel-config: Add support for new driver portals

In reply to ramesh.thomas at intel.com

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

Use the new driver portals if not in compat mode. If in compat mode, use the bus type stored in driver context for bus and driver portal. This will work in all compat modes as follows
- iax and dsa in their own buses and have portal name same as bus
- iax and dsa in dsa bus
- only dsa device in dsa bus

This will also work if kernel is built with compat mode. If idxd portal is present then the new ABI is used, otherwise behave same as compat mode in which all devices are in dsa bus.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccfg.c    | 27 +++++++++++++++++++++++----
 accfg/libaccel_config.h |  3 ++-
 2 files changed, 25 insertions(+), 5 deletions(-)
accfg/lib/libaccfg.c +23 -4
index 6e472d4..269e7e8 100644
@@ -30,6 +30,19 @@
 #define MDEV_POSTFIX "mdev_supported_types"
 #define IDXD_DRIVER_PATH "/sys/bus/dsa/drivers/"
 #define IDXD_DRIVER_PORTAL "idxd"
+#define IDXD_DRIVER_PATH "/sys/bus/dsa/drivers/"
+#define IDXD_DRIVER_PORTAL "idxd"
+#define GET_IDXD_PORTAL(c, d) ((c)->compat ? \
+		(d)->bus_type_str : IDXD_DRIVER_PORTAL)
+#define GET_IDXD_WQ_PORTAL(c, d, w) ((c)->compat ? \
+		(d)->bus_type_str : accfg_wq_driver_portals[(w)->type])
+
+char *accfg_wq_driver_portals[] = {
+	[ACCFG_WQT_KERNEL] = "idxd-kernel-portal",
+	[ACCFG_WQT_USER] = "idxd-user-portal",
+	[ACCFG_WQT_MDEV] = "idxd-mdev-portal",
+	NULL
+};
 
 char *accfg_bus_types[] = {
 	"dsa",
@@ -641,6 +654,8 @@ static int wq_parse_type(struct accfg_wq *wq, char *wq_type)
 		wq->type = ACCFG_WQT_KERNEL;
 	else if (strcmp(ptype, "user") == 0)
 		wq->type = ACCFG_WQT_USER;
+	else if (strcmp(ptype, "mdev") == 0)
+		wq->type = ACCFG_WQT_MDEV;
 	else
 		wq->type = ACCFG_WQT_NONE;
 
@@ -1535,14 +1550,16 @@ static int accfg_device_control(struct accfg_device *device,
 
 	if (flag == ACCFG_DEVICE_ENABLE) {
 		rc = asprintf(&path, "/sys/bus/%s/drivers/%s/bind",
-				device->device_type_str, device->device_type_str);
+				device->bus_type_str,
+				GET_IDXD_PORTAL(ctx, device));
 		if (rc < 0)
 			return rc;
 	} else if (flag == ACCFG_DEVICE_DISABLE) {
 		int clients;
 
 		rc = asprintf(&path, "/sys/bus/%s/drivers/%s/unbind",
-				device->device_type_str, device->device_type_str);
+				device->bus_type_str,
+				GET_IDXD_PORTAL(ctx, device));
 		if (rc < 0)
 			return rc;
 
@@ -1945,14 +1962,16 @@ static int accfg_wq_control(struct accfg_wq *wq, enum accfg_control_flag flag,
 
 	if (flag == ACCFG_WQ_ENABLE) {
 		rc = asprintf(&path, "/sys/bus/%s/drivers/%s/bind",
-				device->device_type_str, device->device_type_str);
+				device->bus_type_str,
+				GET_IDXD_WQ_PORTAL(ctx, device, wq));
 		if (rc < 0)
 			return rc;
 	} else if (flag == ACCFG_WQ_DISABLE) {
 		int clients;
 
 		rc = asprintf(&path, "/sys/bus/%s/drivers/%s/unbind",
-				device->device_type_str, device->device_type_str);
+				device->bus_type_str,
+				GET_IDXD_WQ_PORTAL(ctx, device, wq));
 		if (rc < 0)
 			return rc;
 
accfg/libaccel_config.h +2 -1
index 091c388..b7b64c4 100644
@@ -58,7 +58,8 @@ enum accfg_wq_state {
 enum accfg_wq_type {
 	ACCFG_WQT_NONE = 0,
 	ACCFG_WQT_KERNEL,
-	ACCFG_WQT_USER
+	ACCFG_WQT_USER,
+	ACCFG_WQT_MDEV,
 };
 
 enum accfg_control_flag {
Signature · 1 line
2.26.2