Content-Type: multipart/mixed; boundary="===============8298566075196984706==" MIME-Version: 1.0 From: ramesh.thomas at intel.com Subject: [Accel-config] [PATCH v3 4/4] accel-config: Add support for new device bind paths Date: Wed, 17 Mar 2021 11:16:32 -0400 Message-ID: <20210317151632.336691-5-ramesh.thomas@intel.com> In-Reply-To: 20210317151632.336691-1-ramesh.thomas@intel.com To: accel-config@lists.01.org List-ID: --===============8298566075196984706== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Ramesh Thomas Use the per wq-type device portals to construct driver bind paths if not in compat mode. If in compat mode, use the bus type stored in driver context. Driver bind paths in compat mode - /sys/bus/dsa/drivers/dsa/ /sys/bus/iax/drivers/iax/ Driver bind paths in new ABI: /sys/bus/dsa/drivers/idxd/ (devices) /sys/bus/dsa/drivers// (wqs) Signed-off-by: Ramesh Thomas --- accfg/lib/libaccfg.c | 57 +++++++++++++++++++++++++++++++++++------ accfg/libaccel_config.h | 3 ++- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/accfg/lib/libaccfg.c b/accfg/lib/libaccfg.c index c1b27b3..1d89d4c 100644 --- a/accfg/lib/libaccfg.c +++ b/accfg/lib/libaccfg.c @@ -29,6 +29,17 @@ = #define MDEV_POSTFIX "mdev_supported_types" #define IDXD_DRIVER_BIND_PATH "/sys/bus/dsa/drivers/idxd" +#define IDXD_DRIVER(d) ((d)->ctx->compat ? \ + (d)->bus_type_str : "idxd") +#define IDXD_WQ_DEVICE_PORTAL(d, w) ((d)->ctx->compat ? \ + (d)->bus_type_str : accfg_wq_device_portals[(w)->type]) + +char *accfg_wq_device_portals[] =3D { + [ACCFG_WQT_KERNEL] =3D "idxd-kernel-portal", + [ACCFG_WQT_USER] =3D "idxd-user-portal", + [ACCFG_WQT_MDEV] =3D "idxd-mdev-portal", + NULL +}; = char *accfg_bus_types[] =3D { "dsa", @@ -640,6 +651,8 @@ static int wq_parse_type(struct accfg_wq *wq, char *wq_= type) wq->type =3D ACCFG_WQT_KERNEL; else if (strcmp(ptype, "user") =3D=3D 0) wq->type =3D ACCFG_WQT_USER; + else if (strcmp(ptype, "mdev") =3D=3D 0) + wq->type =3D ACCFG_WQT_MDEV; else wq->type =3D ACCFG_WQT_NONE; = @@ -1519,6 +1532,34 @@ ACCFG_EXPORT char *accfg_device_get_type_str(struct = accfg_device *device) return device->device_type_str; } = +static int get_driver_bind_path(char *bus_name, const char *drv_name, + char **path) +{ + char p[PATH_MAX]; + + sprintf(p, "/sys/bus/%s/drivers/%s/bind", bus_name, drv_name); + + *path =3D strdup(p); + if (!*path) + return -errno; + + return 0; +} + +static int get_driver_unbind_path(char *bus_name, const char *dev_name, + char **path) +{ + char p[PATH_MAX]; + + sprintf(p, "/sys/bus/%s/devices/%s/driver/unbind", bus_name, dev_name); + + *path =3D realpath(p, NULL); + if (!*path) + return -errno; + + return 0; +} + /* Helper function to parse the device enable flag */ static int accfg_device_control(struct accfg_device *device, enum accfg_control_flag flag, bool force) @@ -1533,15 +1574,15 @@ static int accfg_device_control(struct accfg_device= *device, ctx =3D accfg_device_get_ctx(device); = if (flag =3D=3D ACCFG_DEVICE_ENABLE) { - rc =3D asprintf(&path, "/sys/bus/%s/drivers/%s/bind", - device->device_type_str, device->device_type_str); + rc =3D get_driver_bind_path(device->bus_type_str, + IDXD_DRIVER(device), &path); if (rc < 0) return rc; } else if (flag =3D=3D ACCFG_DEVICE_DISABLE) { int clients; = - rc =3D asprintf(&path, "/sys/bus/%s/drivers/%s/unbind", - device->device_type_str, device->device_type_str); + rc =3D get_driver_unbind_path(device->bus_type_str, + accfg_device_get_devname(device), &path); if (rc < 0) return rc; = @@ -1943,15 +1984,15 @@ static int accfg_wq_control(struct accfg_wq *wq, en= um accfg_control_flag flag, const char *wq_name =3D accfg_wq_get_devname(wq); = if (flag =3D=3D ACCFG_WQ_ENABLE) { - rc =3D asprintf(&path, "/sys/bus/%s/drivers/%s/bind", - device->device_type_str, device->device_type_str); + rc =3D get_driver_bind_path(device->bus_type_str, + IDXD_WQ_DEVICE_PORTAL(device, wq), &path); if (rc < 0) return rc; } else if (flag =3D=3D ACCFG_WQ_DISABLE) { int clients; = - rc =3D asprintf(&path, "/sys/bus/%s/drivers/%s/unbind", - device->device_type_str, device->device_type_str); + rc =3D get_driver_unbind_path(device->bus_type_str, wq_name, + &path); if (rc < 0) return rc; = diff --git a/accfg/libaccel_config.h b/accfg/libaccel_config.h index 091c388..b7b64c4 100644 --- a/accfg/libaccel_config.h +++ b/accfg/libaccel_config.h @@ -58,7 +58,8 @@ enum accfg_wq_state { enum accfg_wq_type { ACCFG_WQT_NONE =3D 0, ACCFG_WQT_KERNEL, - ACCFG_WQT_USER + ACCFG_WQT_USER, + ACCFG_WQT_MDEV, }; = enum accfg_control_flag { -- = 2.26.2 --===============8298566075196984706==--