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