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