Augment cxl-list with some more fields obtained from sending an 'Identify' command to the device. If/when these fields are added to the sysfs representation of the memdev, the command submission detour can be removed and replaced with data from sysfs.
Cc: Ben Widawsky <[email protected]> Cc: Dan Williams <[email protected]> Signed-off-by: Vishal Verma <[email protected]> --- util/json.h | 3 ++- cxl/list.c | 29 +++++++++++++++++++++++++++-- util/json.c | 22 +++++++++++++++++++++- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/util/json.h b/util/json.h index 91918c8..831f9bb 100644 --- a/util/json.h +++ b/util/json.h @@ -6,6 +6,7 @@ #include <stdbool.h> #include <ndctl/libndctl.h> #include <daxctl/libdaxctl.h> +#include <cxl/libcxl.h> #include <ccan/short_types/short_types.h> enum util_json_flags { @@ -57,5 +58,5 @@ struct json_object *util_dimm_firmware_to_json(struct ndctl_dimm *dimm, struct json_object *util_region_capabilities_to_json(struct ndctl_region *region); struct cxl_memdev; struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev, - unsigned long flags); + struct cxl_cmd *id, unsigned long flags); #endif /* __NDCTL_JSON_H__ */ diff --git a/cxl/list.c b/cxl/list.c index 3d44244..7afe2b4 100644 --- a/cxl/list.c +++ b/cxl/list.c @@ -5,6 +5,7 @@ #include <stdlib.h> #include <unistd.h> #include <limits.h> +#include <util/log.h> #include <util/json.h> #include <util/filter.h> #include <json-c/json.h> @@ -16,6 +17,7 @@ static struct { bool memdevs; bool idle; bool human; + bool verbose; } list; static unsigned long listopts_to_flags(void) @@ -47,6 +49,19 @@ static int num_list_flags(void) return list.memdevs; } +struct cxl_cmd *memdev_identify(struct cxl_memdev *memdev) +{ + struct cxl_cmd *id; + + id = cxl_cmd_new_identify(memdev); + if (!id) + return NULL; + + if (cxl_cmd_submit(id) != 0) + return NULL; + return id; +} + int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx) { const struct option options[] = { @@ -56,7 +71,9 @@ int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx) "include CXL memory device info"), OPT_BOOLEAN('i', "idle", &list.idle, "include idle devices"), OPT_BOOLEAN('u', "human", &list.human, - "use human friendly number formats "), + "use human friendly number formats"), + OPT_BOOLEAN('v', "verbose", &list.verbose, + "enable verbose output"), OPT_END(), }; const char * const u[] = { @@ -80,27 +97,35 @@ int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx) list_flags = listopts_to_flags(); + if (list.verbose) + cxl_set_log_priority(ctx, LOG_DEBUG); + cxl_memdev_foreach(ctx, memdev) { struct json_object *jdev = NULL; + struct cxl_cmd *id; if (!util_cxl_memdev_filter(memdev, param.memdev)) continue; if (list.memdevs) { + id = memdev_identify(memdev); if (!jdevs) { jdevs = json_object_new_array(); if (!jdevs) { fail("\n"); + cxl_cmd_unref(id); continue; } } - jdev = util_cxl_memdev_to_json(memdev, list_flags); + jdev = util_cxl_memdev_to_json(memdev, id, list_flags); if (!jdev) { fail("\n"); + cxl_cmd_unref(id); continue; } json_object_array_add(jdevs, jdev); + cxl_cmd_unref(id); } } diff --git a/util/json.c b/util/json.c index a855571..24d4477 100644 --- a/util/json.c +++ b/util/json.c @@ -1432,10 +1432,11 @@ struct json_object *util_badblock_rec_to_json(u64 block, u64 count, } struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev, - unsigned long flags) + struct cxl_cmd *id, unsigned long flags) { const char *devname = cxl_memdev_get_devname(memdev); struct json_object *jdev, *jobj; + char fw_rev[0x10]; jdev = json_object_new_object(); if (!devname || !jdev) @@ -1453,5 +1454,24 @@ struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev, if (jobj) json_object_object_add(jdev, "ram_size", jobj); + if (!id) + return jdev; + + if (cxl_cmd_identify_get_fw_rev(id, fw_rev, 0x10) == 0) { + jobj = json_object_new_string(fw_rev); + if (jobj) + json_object_object_add(jdev, "fw_revision", jobj); + } + + jobj = util_json_object_size(cxl_cmd_identify_get_partition_align(id), + flags); + if (jobj) + json_object_object_add(jdev, "partition_align", jobj); + + jobj = util_json_object_size(cxl_cmd_identify_get_lsa_size(id), + flags); + if (jobj) + json_object_object_add(jdev, "lsa_size", jobj); + return jdev; } -- 2.29.2 _______________________________________________ Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
