|
|
4a01d4 |
libndctl: Unify adding dimms for papr and nfit families
|
|
|
4a01d4 |
|
|
|
4a01d4 |
BZ:
|
|
|
4a01d4 |
Brew:
|
|
|
4a01d4 |
|
|
|
4a01d4 |
commit daef3a386a9c45105a2c045ddee46600e265939f
|
|
|
4a01d4 |
Author: Santosh Sivaraj <santosh@fossix.org>
|
|
|
4a01d4 |
Date: Thu May 13 11:42:15 2021 +0530
|
|
|
4a01d4 |
|
|
|
4a01d4 |
libndctl: Unify adding dimms for papr and nfit families
|
|
|
4a01d4 |
|
|
|
4a01d4 |
In preparation for enabling tests on non-nfit devices, unify both, already very
|
|
|
4a01d4 |
similar, functions into one. This will help in adding all attributes needed for
|
|
|
4a01d4 |
the unit tests. Since the function doesn't fail if some of the dimm attributes
|
|
|
4a01d4 |
are missing, this will work fine on PAPR platforms though only part of the DIMM
|
|
|
4a01d4 |
attributes are provided (This doesn't mean that all of the DIMM attributes can
|
|
|
4a01d4 |
be missing).
|
|
|
4a01d4 |
|
|
|
4a01d4 |
Link: https://lore.kernel.org/r/20210513061218.760322-1-santosh@fossix.org
|
|
|
4a01d4 |
Signed-off-by: Santosh Sivaraj <santosh@fossix.org>
|
|
|
4a01d4 |
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
|
|
|
4a01d4 |
|
|
|
4a01d4 |
diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
|
|
|
4a01d4 |
index 2f6d806..e45353f 100644
|
|
|
4a01d4 |
--- a/ndctl/lib/libndctl.c
|
|
|
4a01d4 |
+++ b/ndctl/lib/libndctl.c
|
|
|
4a01d4 |
@@ -1646,41 +1646,9 @@ static int ndctl_bind(struct ndctl_ctx *ctx, struct kmod_module *module,
|
|
|
4a01d4 |
static int ndctl_unbind(struct ndctl_ctx *ctx, const char *devpath);
|
|
|
4a01d4 |
static struct kmod_module *to_module(struct ndctl_ctx *ctx, const char *alias);
|
|
|
4a01d4 |
|
|
|
4a01d4 |
-static int add_papr_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
|
|
|
4a01d4 |
-{
|
|
|
4a01d4 |
- int rc = -ENODEV;
|
|
|
4a01d4 |
- char buf[SYSFS_ATTR_SIZE];
|
|
|
4a01d4 |
- struct ndctl_ctx *ctx = dimm->bus->ctx;
|
|
|
4a01d4 |
- char *path = calloc(1, strlen(dimm_base) + 100);
|
|
|
4a01d4 |
- const char * const devname = ndctl_dimm_get_devname(dimm);
|
|
|
4a01d4 |
-
|
|
|
4a01d4 |
- dbg(ctx, "%s: Probing of_pmem dimm at %s\n", devname, dimm_base);
|
|
|
4a01d4 |
-
|
|
|
4a01d4 |
- if (!path)
|
|
|
4a01d4 |
- return -ENOMEM;
|
|
|
4a01d4 |
-
|
|
|
4a01d4 |
- /* construct path to the papr compatible dimm flags file */
|
|
|
4a01d4 |
- sprintf(path, "%s/papr/flags", dimm_base);
|
|
|
4a01d4 |
-
|
|
|
4a01d4 |
- if (ndctl_bus_is_papr_scm(dimm->bus) &&
|
|
|
4a01d4 |
- sysfs_read_attr(ctx, path, buf) == 0) {
|
|
|
4a01d4 |
-
|
|
|
4a01d4 |
- dbg(ctx, "%s: Adding papr-scm dimm flags:\"%s\"\n", devname, buf);
|
|
|
4a01d4 |
- dimm->cmd_family = NVDIMM_FAMILY_PAPR;
|
|
|
4a01d4 |
-
|
|
|
4a01d4 |
- /* Parse dimm flags */
|
|
|
4a01d4 |
- parse_papr_flags(dimm, buf);
|
|
|
4a01d4 |
-
|
|
|
4a01d4 |
- /* Allocate monitor mode fd */
|
|
|
4a01d4 |
- dimm->health_eventfd = open(path, O_RDONLY|O_CLOEXEC);
|
|
|
4a01d4 |
- rc = 0;
|
|
|
4a01d4 |
- }
|
|
|
4a01d4 |
-
|
|
|
4a01d4 |
- free(path);
|
|
|
4a01d4 |
- return rc;
|
|
|
4a01d4 |
-}
|
|
|
4a01d4 |
-
|
|
|
4a01d4 |
-static int add_nfit_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
|
|
|
4a01d4 |
+static int populate_dimm_attributes(struct ndctl_dimm *dimm,
|
|
|
4a01d4 |
+ const char *dimm_base,
|
|
|
4a01d4 |
+ const char *bus_prefix)
|
|
|
4a01d4 |
{
|
|
|
4a01d4 |
int i, rc = -1;
|
|
|
4a01d4 |
char buf[SYSFS_ATTR_SIZE];
|
|
|
4a01d4 |
@@ -1694,7 +1662,7 @@ static int add_nfit_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
|
|
|
4a01d4 |
* 'unique_id' may not be available on older kernels, so don't
|
|
|
4a01d4 |
* fail if the read fails.
|
|
|
4a01d4 |
*/
|
|
|
4a01d4 |
- sprintf(path, "%s/nfit/id", dimm_base);
|
|
|
4a01d4 |
+ sprintf(path, "%s/%s/id", dimm_base, bus_prefix);
|
|
|
4a01d4 |
if (sysfs_read_attr(ctx, path, buf) == 0) {
|
|
|
4a01d4 |
unsigned int b[9];
|
|
|
4a01d4 |
|
|
|
4a01d4 |
@@ -1709,68 +1677,74 @@ static int add_nfit_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
|
|
|
4a01d4 |
}
|
|
|
4a01d4 |
}
|
|
|
4a01d4 |
|
|
|
4a01d4 |
- sprintf(path, "%s/nfit/handle", dimm_base);
|
|
|
4a01d4 |
+ sprintf(path, "%s/%s/handle", dimm_base, bus_prefix);
|
|
|
4a01d4 |
if (sysfs_read_attr(ctx, path, buf) < 0)
|
|
|
4a01d4 |
goto err_read;
|
|
|
4a01d4 |
dimm->handle = strtoul(buf, NULL, 0);
|
|
|
4a01d4 |
|
|
|
4a01d4 |
- sprintf(path, "%s/nfit/phys_id", dimm_base);
|
|
|
4a01d4 |
+ sprintf(path, "%s/%s/phys_id", dimm_base, bus_prefix);
|
|
|
4a01d4 |
if (sysfs_read_attr(ctx, path, buf) < 0)
|
|
|
4a01d4 |
goto err_read;
|
|
|
4a01d4 |
dimm->phys_id = strtoul(buf, NULL, 0);
|
|
|
4a01d4 |
|
|
|
4a01d4 |
- sprintf(path, "%s/nfit/serial", dimm_base);
|
|
|
4a01d4 |
+ sprintf(path, "%s/%s/serial", dimm_base, bus_prefix);
|
|
|
4a01d4 |
if (sysfs_read_attr(ctx, path, buf) == 0)
|
|
|
4a01d4 |
dimm->serial = strtoul(buf, NULL, 0);
|
|
|
4a01d4 |
|
|
|
4a01d4 |
- sprintf(path, "%s/nfit/vendor", dimm_base);
|
|
|
4a01d4 |
+ sprintf(path, "%s/%s/vendor", dimm_base, bus_prefix);
|
|
|
4a01d4 |
if (sysfs_read_attr(ctx, path, buf) == 0)
|
|
|
4a01d4 |
dimm->vendor_id = strtoul(buf, NULL, 0);
|
|
|
4a01d4 |
|
|
|
4a01d4 |
- sprintf(path, "%s/nfit/device", dimm_base);
|
|
|
4a01d4 |
+ sprintf(path, "%s/%s/device", dimm_base, bus_prefix);
|
|
|
4a01d4 |
if (sysfs_read_attr(ctx, path, buf) == 0)
|
|
|
4a01d4 |
dimm->device_id = strtoul(buf, NULL, 0);
|
|
|
4a01d4 |
|
|
|
4a01d4 |
- sprintf(path, "%s/nfit/rev_id", dimm_base);
|
|
|
4a01d4 |
+ sprintf(path, "%s/%s/rev_id", dimm_base, bus_prefix);
|
|
|
4a01d4 |
if (sysfs_read_attr(ctx, path, buf) == 0)
|
|
|
4a01d4 |
dimm->revision_id = strtoul(buf, NULL, 0);
|
|
|
4a01d4 |
|
|
|
4a01d4 |
- sprintf(path, "%s/nfit/dirty_shutdown", dimm_base);
|
|
|
4a01d4 |
+ sprintf(path, "%s/%s/dirty_shutdown", dimm_base, bus_prefix);
|
|
|
4a01d4 |
if (sysfs_read_attr(ctx, path, buf) == 0)
|
|
|
4a01d4 |
dimm->dirty_shutdown = strtoll(buf, NULL, 0);
|
|
|
4a01d4 |
|
|
|
4a01d4 |
- sprintf(path, "%s/nfit/subsystem_vendor", dimm_base);
|
|
|
4a01d4 |
+ sprintf(path, "%s/%s/subsystem_vendor", dimm_base, bus_prefix);
|
|
|
4a01d4 |
if (sysfs_read_attr(ctx, path, buf) == 0)
|
|
|
4a01d4 |
dimm->subsystem_vendor_id = strtoul(buf, NULL, 0);
|
|
|
4a01d4 |
|
|
|
4a01d4 |
- sprintf(path, "%s/nfit/subsystem_device", dimm_base);
|
|
|
4a01d4 |
+ sprintf(path, "%s/%s/subsystem_device", dimm_base, bus_prefix);
|
|
|
4a01d4 |
if (sysfs_read_attr(ctx, path, buf) == 0)
|
|
|
4a01d4 |
dimm->subsystem_device_id = strtoul(buf, NULL, 0);
|
|
|
4a01d4 |
|
|
|
4a01d4 |
- sprintf(path, "%s/nfit/subsystem_rev_id", dimm_base);
|
|
|
4a01d4 |
+ sprintf(path, "%s/%s/subsystem_rev_id", dimm_base, bus_prefix);
|
|
|
4a01d4 |
if (sysfs_read_attr(ctx, path, buf) == 0)
|
|
|
4a01d4 |
dimm->subsystem_revision_id = strtoul(buf, NULL, 0);
|
|
|
4a01d4 |
|
|
|
4a01d4 |
- sprintf(path, "%s/nfit/family", dimm_base);
|
|
|
4a01d4 |
+ sprintf(path, "%s/%s/family", dimm_base, bus_prefix);
|
|
|
4a01d4 |
if (sysfs_read_attr(ctx, path, buf) == 0)
|
|
|
4a01d4 |
dimm->cmd_family = strtoul(buf, NULL, 0);
|
|
|
4a01d4 |
|
|
|
4a01d4 |
- sprintf(path, "%s/nfit/dsm_mask", dimm_base);
|
|
|
4a01d4 |
+ sprintf(path, "%s/%s/dsm_mask", dimm_base, bus_prefix);
|
|
|
4a01d4 |
if (sysfs_read_attr(ctx, path, buf) == 0)
|
|
|
4a01d4 |
dimm->nfit_dsm_mask = strtoul(buf, NULL, 0);
|
|
|
4a01d4 |
|
|
|
4a01d4 |
- sprintf(path, "%s/nfit/format", dimm_base);
|
|
|
4a01d4 |
+ sprintf(path, "%s/%s/format", dimm_base, bus_prefix);
|
|
|
4a01d4 |
if (sysfs_read_attr(ctx, path, buf) == 0)
|
|
|
4a01d4 |
dimm->format[0] = strtoul(buf, NULL, 0);
|
|
|
4a01d4 |
for (i = 1; i < dimm->formats; i++) {
|
|
|
4a01d4 |
- sprintf(path, "%s/nfit/format%d", dimm_base, i);
|
|
|
4a01d4 |
+ sprintf(path, "%s/%s/format%d", dimm_base, bus_prefix, i);
|
|
|
4a01d4 |
if (sysfs_read_attr(ctx, path, buf) == 0)
|
|
|
4a01d4 |
dimm->format[i] = strtoul(buf, NULL, 0);
|
|
|
4a01d4 |
}
|
|
|
4a01d4 |
|
|
|
4a01d4 |
- sprintf(path, "%s/nfit/flags", dimm_base);
|
|
|
4a01d4 |
- if (sysfs_read_attr(ctx, path, buf) == 0)
|
|
|
4a01d4 |
- parse_nfit_mem_flags(dimm, buf);
|
|
|
4a01d4 |
+ sprintf(path, "%s/%s/flags", dimm_base, bus_prefix);
|
|
|
4a01d4 |
+ if (sysfs_read_attr(ctx, path, buf) == 0) {
|
|
|
4a01d4 |
+ if (ndctl_bus_has_nfit(dimm->bus))
|
|
|
4a01d4 |
+ parse_nfit_mem_flags(dimm, buf);
|
|
|
4a01d4 |
+ else if (ndctl_bus_is_papr_scm(dimm->bus)) {
|
|
|
4a01d4 |
+ dimm->cmd_family = NVDIMM_FAMILY_PAPR;
|
|
|
4a01d4 |
+ parse_papr_flags(dimm, buf);
|
|
|
4a01d4 |
+ }
|
|
|
4a01d4 |
+ }
|
|
|
4a01d4 |
|
|
|
4a01d4 |
dimm->health_eventfd = open(path, O_RDONLY|O_CLOEXEC);
|
|
|
4a01d4 |
rc = 0;
|
|
|
4a01d4 |
@@ -1792,7 +1766,8 @@ static void *add_dimm(void *parent, int id, const char *dimm_base)
|
|
|
4a01d4 |
if (!path)
|
|
|
4a01d4 |
return NULL;
|
|
|
4a01d4 |
|
|
|
4a01d4 |
- sprintf(path, "%s/nfit/formats", dimm_base);
|
|
|
4a01d4 |
+ sprintf(path, "%s/%s/formats", dimm_base,
|
|
|
4a01d4 |
+ ndctl_bus_has_nfit(bus) ? "nfit" : "papr");
|
|
|
4a01d4 |
if (sysfs_read_attr(ctx, path, buf) < 0)
|
|
|
4a01d4 |
formats = 1;
|
|
|
4a01d4 |
else
|
|
|
4a01d4 |
@@ -1866,13 +1841,12 @@ static void *add_dimm(void *parent, int id, const char *dimm_base)
|
|
|
4a01d4 |
else
|
|
|
4a01d4 |
dimm->fwa_result = fwa_result_to_result(buf);
|
|
|
4a01d4 |
|
|
|
4a01d4 |
+ dimm->formats = formats;
|
|
|
4a01d4 |
/* Check if the given dimm supports nfit */
|
|
|
4a01d4 |
if (ndctl_bus_has_nfit(bus)) {
|
|
|
4a01d4 |
- dimm->formats = formats;
|
|
|
4a01d4 |
- rc = add_nfit_dimm(dimm, dimm_base);
|
|
|
4a01d4 |
- } else if (ndctl_bus_has_of_node(bus)) {
|
|
|
4a01d4 |
- rc = add_papr_dimm(dimm, dimm_base);
|
|
|
4a01d4 |
- }
|
|
|
4a01d4 |
+ rc = populate_dimm_attributes(dimm, dimm_base, "nfit");
|
|
|
4a01d4 |
+ } else if (ndctl_bus_has_of_node(bus))
|
|
|
4a01d4 |
+ rc = populate_dimm_attributes(dimm, dimm_base, "papr");
|
|
|
4a01d4 |
|
|
|
4a01d4 |
if (rc == -ENODEV) {
|
|
|
4a01d4 |
/* Unprobed dimm with no family */
|
|
|
4a01d4 |
@@ -2531,13 +2505,12 @@ static void *add_region(void *parent, int id, const char *region_base)
|
|
|
4a01d4 |
goto err_read;
|
|
|
4a01d4 |
region->num_mappings = strtoul(buf, NULL, 0);
|
|
|
4a01d4 |
|
|
|
4a01d4 |
- sprintf(path, "%s/nfit/range_index", region_base);
|
|
|
4a01d4 |
- if (ndctl_bus_has_nfit(bus)) {
|
|
|
4a01d4 |
- if (sysfs_read_attr(ctx, path, buf) < 0)
|
|
|
4a01d4 |
- goto err_read;
|
|
|
4a01d4 |
- region->range_index = strtoul(buf, NULL, 0);
|
|
|
4a01d4 |
- } else
|
|
|
4a01d4 |
+ sprintf(path, "%s/%s/range_index", region_base,
|
|
|
4a01d4 |
+ ndctl_bus_has_nfit(bus) ? "nfit": "papr");
|
|
|
4a01d4 |
+ if (sysfs_read_attr(ctx, path, buf) < 0)
|
|
|
4a01d4 |
region->range_index = -1;
|
|
|
4a01d4 |
+ else
|
|
|
4a01d4 |
+ region->range_index = strtoul(buf, NULL, 0);
|
|
|
4a01d4 |
|
|
|
4a01d4 |
sprintf(path, "%s/read_only", region_base);
|
|
|
4a01d4 |
if (sysfs_read_attr(ctx, path, buf) < 0)
|