Skip to contentSkip to conversation

accel-config: Add API to return uacce device path

PATCH Superseded ramesh.thomas at intel.com 2 participants 3 messages Apr 6, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

ramesh.thomas at intel.com

#0 lore raw

PATCH 1/1 accel-config: Add API to return uacce device path

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

Return path to uacce device path for user wqs. This includes support for legacy mode device names.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccel-config.sym |  5 ++++
 accfg/lib/libaccfg.c          | 55 +++++++++++++++++++++++++++++++++++
 accfg/libaccel_config.h       |  1 +
 3 files changed, 61 insertions(+)
accfg/lib/libaccel-config.sym +5 -0
index 4de2a49..a28ac97 100644
@@ -141,3 +141,8 @@ global:
 	accfg_remove_mdev;
 	accfg_device_get_mdev_enabled;
 } LIBACCFG_6;
+
+LIBACCFG_8 {
+global:
+	accfg_wq_get_uacce_path;
+} LIBACCFG_7;
accfg/lib/libaccfg.c +55 -0

67 lines not on this page · raw message

accfg/libaccel_config.h +1 -0
index 94aef80..e61fd40 100644
@@ -276,6 +276,7 @@ int accfg_wq_enable(struct accfg_wq *wq);
 int accfg_wq_disable(struct accfg_wq *wq, bool force);
 int accfg_wq_priority_boundary(struct accfg_wq *wq);
 int accfg_wq_size_boundary(struct accfg_device *device, int wq_num);
+int accfg_wq_get_uacce_path(struct accfg_wq *wq, char *buf, size_t size);
 
 /* libaccfg function for engine */
 struct accfg_engine;
Signature · 1 line
2.26.3
#1 lore raw
Quoted 17 lines · ramesh.thomas(a)intel.com

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

Return path to uacce device path for user wqs. This includes support for legacy mode device names.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
  accfg/lib/libaccel-config.sym |  5 ++++
  accfg/lib/libaccfg.c          | 55 +++++++++++++++++++++++++++++++++++
  accfg/libaccel_config.h       |  1 +
  3 files changed, 61 insertions(+)
accfg/lib/libaccel-config.sym +0 -0
index 4de2a49..a28ac97 100644

accfg/lib/libaccel-config.sym global: · line 147

Quoted 7 lines
accfg/lib/libaccel-config.sym +4 -0
@@ -141,3 +141,8 @@ global:
  	accfg_remove_mdev;
  	accfg_device_get_mdev_enabled;
  } LIBACCFG_6;
+
+LIBACCFG_8 {
+global:
+	accfg_wq_get_uacce_path;

I wonder instead of have a specific call to uacce accfg_wq_get_uacce_path, we should just have accfg_wq_get_user_dev_path(). And it's capable of providing a path for legacy or uacce. And we can get users to just move over to that. The user really shouldn't care if it's uacce or something else.

Quoted 86 lines
accfg/lib/libaccel-config.sym +1 -0
+} LIBACCFG_7;
accfg/lib/libaccfg.c +55 -0
index 1d89d4c..dd0219c 100644
@@ -25,6 +25,7 @@
  #include <ccan/build_assert/build_assert.h>
  #include <util/sysfs.h>
  #include <accfg/libaccel_config.h>
+#include <fnmatch.h>
  #include "private.h"
 
  #define MDEV_POSTFIX "mdev_supported_types"
@@ -2099,6 +2100,60 @@ ACCFG_EXPORT int accfg_wq_size_boundary(struct accfg_device *device,
  	return 0;
  }
 
+ACCFG_EXPORT int accfg_wq_get_uacce_path(struct accfg_wq *wq, char *buf,
+		size_t size)
+{
+	struct dirent **d;
+	int n, n1;
+	char *f;
+	char p[PATH_MAX];
+	struct accfg_ctx *ctx;
+	int rc = 0;
+
+	ctx = accfg_device_get_ctx(wq->device);
+
+	sprintf(p, "/dev/%s", wq->device->bus_type_str);
+	n1 = n = scandir(p, &d, NULL, alphasort);
+	if (n < 0) {
+		err(ctx, "UACCE device path not found %s\n", p);
+		return -ENOENT;
+	}
+
+	sprintf(p, "%s-*", accfg_wq_get_devname(wq));
+
+	while (n--) {
+		f = &d[n]->d_name[0];
+
+		if (!fnmatch(p, f, 0) || !strcmp(accfg_wq_get_devname(wq), f))
+			break;
+	}
+
+	if (n < 0) {
+		err(ctx, "UACCE device for %s not found at /dev/%s\n",
+				accfg_wq_get_devname(wq),
+				wq->device->bus_type_str);
+		rc = -ENOENT;
+		goto ext_uacce;
+	}
+
+	n = sprintf(p, "/dev/%s/%s", wq->device->bus_type_str, f);
+
+	if ((size_t)n >= size) {
+		err(ctx, "Buffer size too small. Need %d bytes\n", n + 1);
+		rc = -ERANGE;
+		goto ext_uacce;
+	}
+
+	strcpy(buf, p);
+
+ext_uacce:
+	while (n1--)
+		free(d[n1]);
+	free(d);
+
+	return rc;
+}
+
  #define accfg_wq_set_field(wq, val, field) \
  ACCFG_EXPORT int accfg_wq_set_##field( \
  		struct accfg_wq *wq, int val) \
accfg/libaccel_config.h +1 -0
index 94aef80..e61fd40 100644
@@ -276,6 +276,7 @@ int accfg_wq_enable(struct accfg_wq *wq);
  int accfg_wq_disable(struct accfg_wq *wq, bool force);
  int accfg_wq_priority_boundary(struct accfg_wq *wq);
  int accfg_wq_size_boundary(struct accfg_device *device, int wq_num);
+int accfg_wq_get_uacce_path(struct accfg_wq *wq, char *buf, size_t size);
 
  /* libaccfg function for engine */
  struct accfg_engine;
#2 lore raw
Quoted 23 lines · Dave Jiang
Quoted 22 lines · ramesh.thomas(a)intel.com

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

Return path to uacce device path for user wqs. This includes support for legacy mode device names.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
  accfg/lib/libaccel-config.sym |  5 ++++
  accfg/lib/libaccfg.c          | 55 +++++++++++++++++++++++++++++++++++
  accfg/libaccel_config.h       |  1 +
  3 files changed, 61 insertions(+)
accfg/lib/libaccel-config.sym +2 -0
index 4de2a49..a28ac97 100644
@@ -141,3 +141,8 @@ global:
  	accfg_remove_mdev;
  	accfg_device_get_mdev_enabled;
  } LIBACCFG_6;
+
+LIBACCFG_8 {
Quoted 8 lines

accfg/lib/libaccel-config.sym global: · line 147

Quoted 2 lines
accfg/lib/libaccel-config.sym +2 -0
+global:
+	accfg_wq_get_uacce_path;

I wonder instead of have a specific call to uacce accfg_wq_get_uacce_path, we should just have accfg_wq_get_user_dev_path(). And it's capable of providing a path for legacy or uacce. And we can get users to just move over to that. The user really shouldn't care if it's uacce or something else.

I can give the API a generic name. It currently provides both legacy and uacce paths.