Content-Type: multipart/mixed; boundary="===============3352266397908173194==" MIME-Version: 1.0 From: ramesh.thomas at intel.com Subject: [Accel-config] [PATCH v1 02/11] accel-config: Create mdev structures and load mdevs into device context Date: Wed, 02 Dec 2020 14:30:48 -0500 Message-ID: <20201202193057.299615-3-ramesh.thomas@intel.com> In-Reply-To: 20201202193057.299615-1-ramesh.thomas@intel.com To: accel-config@lists.01.org List-ID: --===============3352266397908173194== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Ramesh Thomas Lays the foundation for the mdev implementation - Create private and exported structures for mdev types and mdev list - Create routines to scan and classify mdevs in sysfs - Store mdev details in device contexts during init Signed-off-by: Ramesh Thomas --- accfg/lib/libaccfg.c | 81 +++++++++++++++++++++++++++++++++++++++++ accfg/lib/private.h | 8 ++++ accfg/libaccel_config.h | 7 ++++ 3 files changed, 96 insertions(+) diff --git a/accfg/lib/libaccfg.c b/accfg/lib/libaccfg.c index 9b5615a..0dd1f0c 100644 --- a/accfg/lib/libaccfg.c +++ b/accfg/lib/libaccfg.c @@ -43,6 +43,12 @@ ACCFG_EXPORT char *accfg_basenames[] =3D { NULL }; = +ACCFG_EXPORT char *accfg_mdev_basenames[] =3D { + [ACCFG_MDEV_TYPE_1_DWQ] =3D "1dwq", + [ACCFG_MDEV_TYPE_1_SWQ] =3D "1swq", + NULL +}; + enum { ACCFG_CMD_STATUS_MAX =3D 0x45, }; @@ -407,6 +413,77 @@ static int device_parse_type(struct accfg_device *devi= ce) return 0; } = +static int mdev_str_to_type(char *mdev_type_str) +{ + char **b; + char *s; + int l, i; + + s =3D strchr(mdev_type_str, '-'); + if (!s) + s =3D mdev_type_str; + else + s++; + l =3D (int) (strchrnul(s, '-') - s); + + for (b =3D accfg_mdev_basenames, i =3D 0; *b !=3D NULL; b++, i++) + if (!strncmp(*b, s, l)) + return i; + + return ACCFG_MDEV_TYPE_UNKNOWN; +} + +static int add_device_mdevs(struct accfg_ctx *ctx, struct accfg_device *de= v) +{ + struct accfg_device_mdev *dev_mdev; + uuid_t uu; + struct dirent **d; + char *f, *mdev_type_str; + char p[PATH_MAX]; + char mdev_path[PATH_MAX]; + int n, n1, rc =3D 0; + + n1 =3D n =3D scandir(dev->mdev_path, &d, NULL, alphasort); + if (n < 0) { + err(ctx, "scandir failed\n"); + return -ENOENT; + } + + while (n--) { + f =3D &d[n]->d_name[0]; + if (*f =3D=3D '.' || uuid_parse(f, uu)) + continue; + sprintf(p, "%s/%s/mdev_type", dev->mdev_path, f); + if (!realpath(p, mdev_path)) + continue; + dev_mdev =3D calloc(1, + sizeof(struct accfg_device_mdev)); + if (!dev_mdev) { + err(ctx, "allocation failed\n"); + rc =3D -ENOMEM; + goto exit_add_mdev; + } + uuid_copy(dev_mdev->uuid, uu); + mdev_type_str =3D strrchr(mdev_path, '/') + 1; + dev_mdev->device =3D dev; + dev_mdev->type =3D mdev_str_to_type(mdev_type_str); + if (dev_mdev->type =3D=3D ACCFG_MDEV_TYPE_UNKNOWN) { + err(ctx, "mdev type error\n"); + free(dev_mdev); + rc =3D -EINVAL; + goto exit_add_mdev; + } + list_add_tail(&dev->mdev_list, &dev_mdev->list); + } + +exit_add_mdev: + while (n1--) + free(d[n1]); + free(d); + + return rc; +} + static void *add_device(void *parent, int id, const char *ctl_base, char *= dev_prefix) { struct accfg_ctx *ctx =3D parent; @@ -439,6 +516,7 @@ static void *add_device(void *parent, int id, const cha= r *ctl_base, char *dev_pr list_head_init(&device->groups); list_head_init(&device->wqs); list_head_init(&device->engines); + list_head_init(&device->mdev_list); = device->ctx =3D ctx; device->id =3D id; @@ -501,6 +579,9 @@ static void *add_device(void *parent, int id, const cha= r *ctl_base, char *dev_pr list_add_tail(&ctx->devices, &device->list); free(path); = + if (add_device_mdevs(ctx, device)) + goto err_dev_path; + return device; = err_dev_path: diff --git a/accfg/lib/private.h b/accfg/lib/private.h index 365d484..305d73e 100644 --- a/accfg/lib/private.h +++ b/accfg/lib/private.h @@ -35,6 +35,7 @@ struct accfg_device { char *device_type_str; enum accfg_device_type type; size_t buf_len; + struct list_head mdev_list; = /* Device Attributes */ struct accfg_error errors; @@ -56,6 +57,13 @@ struct accfg_device { char *pasid_enabled; }; = +struct accfg_device_mdev { + struct accfg_device *device; + uuid_t uuid; + enum accfg_mdev_type type; + struct list_node list; +}; + struct accfg_group { struct accfg_device *device; int id; diff --git a/accfg/libaccel_config.h b/accfg/libaccel_config.h index f85670c..e89bd40 100644 --- a/accfg/libaccel_config.h +++ b/accfg/libaccel_config.h @@ -67,6 +67,12 @@ enum accfg_control_flag { ACCFG_WQ_DISABLE, }; = +enum accfg_mdev_type { + ACCFG_MDEV_TYPE_1_DWQ, + ACCFG_MDEV_TYPE_1_SWQ, + ACCFG_MDEV_TYPE_UNKNOWN, +}; + /* no need to save device error */ struct accfg_error { uint64_t val[4]; @@ -78,6 +84,7 @@ struct dev_parameters { }; = extern char *accfg_basenames[]; +extern char *accfg_mdev_basenames[]; = struct group_parameters { unsigned int tokens_reserved; -- = 2.26.2 --===============3352266397908173194==--