diff mbox series

[ndctl,RFC,2/2] cxl: add identify command to cxl tool

Message ID 20230307082102.27195-3-jehoon.park@samsung.com
State New, archived
Headers show
Series add support for IDENTIFY command | expand

Commit Message

Jehoon Park March 7, 2023, 8:21 a.m. UTC
From: jehoon park <jehoon.park@samsung.com>

Add identify command to cxl-cli. This new command displays
basic information about CXL memory device(s).
Add man page documentation for identify cli command.

Signed-off-by: jehoon park <jehoon.park@samsung.com>
---
 Documentation/cxl/cxl-identify.txt |  57 ++++++++++++
 Documentation/cxl/meson.build      |   1 +
 cxl/builtin.h                      |   1 +
 cxl/cxl.c                          |   1 +
 cxl/memdev.c                       | 141 +++++++++++++++++++++++++++++
 5 files changed, 201 insertions(+)
 create mode 100644 Documentation/cxl/cxl-identify.txt
diff mbox series

Patch

diff --git a/Documentation/cxl/cxl-identify.txt b/Documentation/cxl/cxl-identify.txt
new file mode 100644
index 0000000..ee25895
--- /dev/null
+++ b/Documentation/cxl/cxl-identify.txt
@@ -0,0 +1,57 @@ 
+// SPDX-License-Identifier: GPL-2.0
+
+cxl-identify(1)
+===============
+
+NAME
+----
+cxl-identify - display basic information about a CXL memdev
+
+SYNOPSIS
+--------
+[verse]
+'cxl identify <mem0> [<mem1>..<memN>] [<options>]'
+
+DESCRIPTION
+-----------
+This command sends an identify command to a CXL memory device, and displays
+the result. Provided information: CXL memory device's capacity
+(total, volatile and persistent), partition alignment, event log size,
+LSA size, poison list size, inject poison limit, poison handling capabilities
+and QoS telemetry capabilities.
+
+EXAMPLE
+-------
+----
+# cxl identify mem0
+FW Revision                              : BWFW VERSION 00
+Total Capacity                           : 1.00 GB
+Volatile Only Capacity                   : 1.00 GB
+Persistent Only Capacity                 : 0 B
+Partition Alignment                      : 0 B
+Informational Event Log Size             : 0
+Warning Event Log Size                   : 0
+Failure Event Log Size                   : 0
+Fatal Event Log Size                     : 0
+LSA Size                                 : 0 B
+Poison List Maximum Media Error Records  : 256
+Inject Poison Limit                      : 0
+Poison Handling Capabilities
+Injects Persistent Poison                : Not Supported
+Scans for Poison                         : Not Supported
+QoS Telemetry Capabilities
+Egress Port Congestion                   : Not Supported
+Temporary Throughput Reduction           : Not Supported
+cxl memdev: cmd_identify: identified 1 mem
+----
+
+OPTIONS
+-------
+<memory device(s)>::
+include::memdev-option.txt[]
+
+include::verbose-option.txt[]
+
+SEE ALSO
+--------
+CXL-3.0 8.2.9.8.1
diff --git a/Documentation/cxl/meson.build b/Documentation/cxl/meson.build
index a6d77ab..d60d42d 100644
--- a/Documentation/cxl/meson.build
+++ b/Documentation/cxl/meson.build
@@ -46,6 +46,7 @@  cxl_manpages = [
   'cxl-enable-region.txt',
   'cxl-destroy-region.txt',
   'cxl-monitor.txt',
+  'cxl-identify.txt',
 ]
 
 foreach man : cxl_manpages
diff --git a/cxl/builtin.h b/cxl/builtin.h
index 9baa43b..2276415 100644
--- a/cxl/builtin.h
+++ b/cxl/builtin.h
@@ -32,4 +32,5 @@  static inline int cmd_monitor(int argc, const char **argv, struct cxl_ctx *ctx)
 	return EXIT_FAILURE;
 }
 #endif
+int cmd_identify(int argc, const char **argv, struct cxl_ctx *ctx);
 #endif /* _CXL_BUILTIN_H_ */
diff --git a/cxl/cxl.c b/cxl/cxl.c
index 3be7026..be536ea 100644
--- a/cxl/cxl.c
+++ b/cxl/cxl.c
@@ -77,6 +77,7 @@  static struct cmd_struct commands[] = {
 	{ "disable-region", .c_fn = cmd_disable_region },
 	{ "destroy-region", .c_fn = cmd_destroy_region },
 	{ "monitor", .c_fn = cmd_monitor },
+	{ "identify", .c_fn = cmd_identify },
 };
 
 int main(int argc, const char **argv)
diff --git a/cxl/memdev.c b/cxl/memdev.c
index 0b3ad02..638107c 100644
--- a/cxl/memdev.c
+++ b/cxl/memdev.c
@@ -135,6 +135,136 @@  static const struct option free_dpa_options[] = {
 	OPT_END(),
 };
 
+static const struct option identify_options[] = {
+	BASE_OPTIONS(),
+	OPT_END(),
+};
+
+static void bytes_to_str(unsigned long long bytes, char *str, int len)
+{
+	/* convert bytes to human friendly formats (B, KB, MB, GB, TB) */
+
+	if (bytes == ULLONG_MAX)
+		snprintf(str, len, "Invalid");
+	else if (bytes < SZ_1K)
+		snprintf(str, len, "%lld B", bytes);
+	else if (bytes < SZ_1M)
+		snprintf(str, len, "%.2lf KB", (double)bytes / SZ_1K);
+	else if (bytes < SZ_1G)
+		snprintf(str, len, "%.2lf MB", (double)bytes / SZ_1M);
+	else if (bytes < SZ_1T)
+		snprintf(str, len, "%.2lf GB", (double)bytes / SZ_1G);
+	else
+		snprintf(str, len, "%.2lf TB", (double)bytes / SZ_1T);
+}
+
+static int action_identify(struct cxl_memdev *memdev,
+			   struct action_context *actx)
+{
+	const char *devname = cxl_memdev_get_devname(memdev);
+	struct cxl_cmd *cmd;
+	int rc;
+	char fw_rev[0x10], total_cap[10], volatile_only[10],
+		persistent_only[10], alignment[10], lsa_size[10];
+	int info_log_size, warn_log_size, fail_log_size, fatal_log_size,
+		poison_list_max, inject_poison_limit, inject_persistent_poison,
+		scan_poison, egress_port_congestion, temp_throughput_reduction;
+
+	cmd = cxl_cmd_new_identify(memdev);
+	if (!cmd)
+		return -ENOMEM;
+
+	rc = cxl_cmd_submit(cmd);
+	if (rc < 0) {
+		log_err(&ml, "cmd submission failed: %s\n", strerror(-rc));
+		return rc;
+	}
+
+	rc = cxl_cmd_get_mbox_status(cmd);
+	if (rc != 0) {
+		log_err(&ml, "%s: mbox status: %d\n", __func__, rc);
+		return -ENXIO;
+	}
+
+	rc = cxl_cmd_identify_get_fw_rev(cmd, fw_rev, 0x10);
+	if (rc != 0) {
+		log_err(&ml, "%s: can't get firmware revision\n", devname);
+	}
+
+	bytes_to_str(cxl_cmd_identify_get_total_size(cmd), total_cap,
+		     sizeof(total_cap));
+	bytes_to_str(cxl_cmd_identify_get_volatile_only_size(cmd),
+		     volatile_only, sizeof(volatile_only));
+	bytes_to_str(cxl_cmd_identify_get_persistent_only_size(cmd),
+		     persistent_only, sizeof(persistent_only));
+	bytes_to_str(cxl_cmd_identify_get_partition_align(cmd), alignment,
+		     sizeof(alignment));
+	info_log_size =
+		cxl_cmd_identify_get_event_log_size(cmd, CXL_IDENTIFY_INFO);
+	warn_log_size =
+		cxl_cmd_identify_get_event_log_size(cmd, CXL_IDENTIFY_WARN);
+	fail_log_size =
+		cxl_cmd_identify_get_event_log_size(cmd, CXL_IDENTIFY_FAIL);
+	fatal_log_size =
+		cxl_cmd_identify_get_event_log_size(cmd, CXL_IDENTIFY_FATAL);
+	bytes_to_str(cxl_cmd_identify_get_label_size(cmd), lsa_size,
+		     sizeof(lsa_size));
+	poison_list_max = cxl_cmd_identify_get_poison_list_max(cmd);
+	inject_poison_limit = cxl_cmd_identify_get_inject_poison_limit(cmd);
+	inject_persistent_poison =
+		cxl_cmd_identify_injects_persistent_poison(cmd);
+	scan_poison = cxl_cmd_identify_scans_for_poison(cmd);
+	egress_port_congestion = cxl_cmd_identify_egress_port_congestion(cmd);
+	temp_throughput_reduction =
+		cxl_cmd_identify_temporary_throughput_reduction(cmd);
+
+	printf("CXL Identify Memory Device \"%s\"\n", devname);
+	printf("FW Revision                              : %s\n", fw_rev);
+	printf("Total Capacity                           : %s\n", total_cap);
+	printf("Volatile Only Capacity                   : %s\n",
+	       volatile_only);
+	printf("Persistent Only Capacity                 : %s\n",
+	       persistent_only);
+	printf("Partition Alignment                      : %s\n", alignment);
+	printf("Informational Event Log Size             : %d\n",
+	       info_log_size);
+	printf("Warning Event Log Size                   : %d\n",
+	       warn_log_size);
+	printf("Failure Event Log Size                   : %d\n",
+	       fail_log_size);
+	printf("Fatal Event Log Size                     : %d\n",
+	       fatal_log_size);
+	printf("LSA Size                                 : %s\n", lsa_size);
+	printf("Poison List Maximum Media Error Records  : %d\n",
+	       poison_list_max);
+	printf("Inject Poison Limit                      : %d\n",
+	       inject_poison_limit);
+	printf("Poison Handling Capabilities\n");
+	printf("Injects Persistent Poison                : ");
+	if (inject_persistent_poison)
+		printf("Supported\n");
+	else
+		printf("Not Supported\n");
+	printf("Scans for Poison                         : ");
+	if (scan_poison)
+		printf("Supported\n");
+	else
+		printf("Not Supported\n");
+	printf("QoS Telemetry Capabilities\n");
+	printf("Egress Port Congestion                   : ");
+	if (egress_port_congestion)
+		printf("Supported\n");
+	else
+		printf("Not Supported\n");
+	printf("Temporary Throughput Reduction           : ");
+	if (temp_throughput_reduction)
+		printf("Supported\n");
+	else
+		printf("Not Supported\n");
+
+	return 0;
+}
+
 enum reserve_dpa_mode {
 	DPA_ALLOC,
 	DPA_FREE,
@@ -893,3 +1023,14 @@  int cmd_free_dpa(int argc, const char **argv, struct cxl_ctx *ctx)
 
 	return count >= 0 ? 0 : EXIT_FAILURE;
 }
+
+int cmd_identify(int argc, const char **argv, struct cxl_ctx *ctx)
+{
+	int count = memdev_action(
+		argc, argv, ctx, action_identify, identify_options,
+		"cxl identify <mem0> [<mem1>..<memn>] [<options>]");
+	log_info(&ml, "identified %d mem%s\n", count >= 0 ? count : 0,
+		 count > 1 ? "s" : "");
+
+	return count >= 0 ? 0 : EXIT_FAILURE;
+}