nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] ndctl: add support for acknolwedge shutdown count enable
@ 2018-02-15 22:31 Dave Jiang
  2018-02-15 22:32 ` [PATCH v2 2/2] ndctl: adding unit test for enable ack shutdown count Dave Jiang
  0 siblings, 1 reply; 2+ messages in thread
From: Dave Jiang @ 2018-02-15 22:31 UTC (permalink / raw)
  To: vishal.l.verma, dan.j.williams; +Cc: linux-nvdimm

Adding generic support for Ack Shutdown Count enable and the
Enable Latch System Shutdown Status (Function Index 10) for
DSM v1.6 spec.

Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
 0 files changed

diff --git a/ndctl/lib/intel.c b/ndctl/lib/intel.c
index 8daf5d2..c40df95 100644
--- a/ndctl/lib/intel.c
+++ b/ndctl/lib/intel.c
@@ -626,6 +626,22 @@ intel_cmd_fw_xlat_firmware_status(struct ndctl_cmd *cmd)
 	return FW_EUNKNOWN;
 }
 
+static struct ndctl_cmd *
+intel_dimm_cmd_new_lss(struct ndctl_dimm *dimm)
+{
+	struct ndctl_cmd *cmd;
+
+	BUILD_ASSERT(sizeof(struct nd_intel_lss) == 5);
+
+	cmd = alloc_intel_cmd(dimm, ND_INTEL_ENABLE_LSS_STATUS, 1, 4);
+	if (!cmd)
+		return NULL;
+
+	cmd->intel->lss.enable = 1;
+	cmd->firmware_status = &cmd->intel->lss.status;
+	return cmd;
+}
+
 struct ndctl_dimm_ops * const intel_dimm_ops = &(struct ndctl_dimm_ops) {
 	.cmd_desc = intel_cmd_desc,
 	.new_smart = intel_dimm_cmd_new_smart,
@@ -678,4 +694,5 @@ struct ndctl_dimm_ops * const intel_dimm_ops = &(struct ndctl_dimm_ops) {
 	.new_fw_finish_query = intel_dimm_cmd_new_fw_finish_query,
 	.fw_fquery_get_fw_rev = intel_cmd_fw_fquery_get_fw_rev,
 	.fw_xlat_firmware_status = intel_cmd_fw_xlat_firmware_status,
+	.new_ack_shutdown_count = intel_dimm_cmd_new_lss,
 };
diff --git a/ndctl/lib/intel.h b/ndctl/lib/intel.h
index e9627b0..3b01bba 100644
--- a/ndctl/lib/intel.h
+++ b/ndctl/lib/intel.h
@@ -6,6 +6,7 @@
 #define ND_INTEL_SMART 1
 #define ND_INTEL_SMART_THRESHOLD 2
 
+#define ND_INTEL_ENABLE_LSS_STATUS 10
 #define ND_INTEL_FW_GET_INFO 12
 #define ND_INTEL_FW_START_UPDATE 13
 #define ND_INTEL_FW_SEND_DATA 14
@@ -134,6 +135,11 @@ struct nd_intel_fw_finish_query {
 	__u64 updated_fw_rev;
 } __attribute__((packed));
 
+struct nd_intel_lss {
+	__u8 enable;
+	__u32 status;
+} __attribute__((packed));
+
 struct nd_pkg_intel {
 	struct nd_cmd_pkg gen;
 	union {
@@ -146,6 +152,7 @@ struct nd_pkg_intel {
 		struct nd_intel_fw_send_data send;
 		struct nd_intel_fw_finish_update finish;
 		struct nd_intel_fw_finish_query fquery;
+		struct nd_intel_lss lss;
 	};
 };
 
diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym
index e7f9675..25fd0c2 100644
--- a/ndctl/lib/libndctl.sym
+++ b/ndctl/lib/libndctl.sym
@@ -343,4 +343,5 @@ global:
 	ndctl_cmd_fw_start_get_context;
 	ndctl_cmd_fw_fquery_get_fw_rev;
 	ndctl_cmd_fw_xlat_firmware_status;
+	ndctl_dimm_cmd_new_ack_shutdown_count;
 } LIBNDCTL_13;
diff --git a/ndctl/lib/private.h b/ndctl/lib/private.h
index b9e3c1d..f32d32a 100644
--- a/ndctl/lib/private.h
+++ b/ndctl/lib/private.h
@@ -324,6 +324,7 @@ struct ndctl_dimm_ops {
 	struct ndctl_cmd *(*new_fw_finish_query)(struct ndctl_cmd *);
 	unsigned long long (*fw_fquery_get_fw_rev)(struct ndctl_cmd *);
 	enum ND_FW_STATUS (*fw_xlat_firmware_status)(struct ndctl_cmd *);
+	struct ndctl_cmd *(*new_ack_shutdown_count)(struct ndctl_dimm *);
 };
 
 struct ndctl_dimm_ops * const intel_dimm_ops;
diff --git a/ndctl/lib/smart.c b/ndctl/lib/smart.c
index 4ab94bb..8bf5d35 100644
--- a/ndctl/lib/smart.c
+++ b/ndctl/lib/smart.c
@@ -155,3 +155,14 @@ NDCTL_EXPORT int ndctl_cmd_##op(struct ndctl_cmd *cmd, bool enable) \
 
 smart_cmd_inject(smart_inject_fatal)
 smart_cmd_inject(smart_inject_unsafe_shutdown)
+
+NDCTL_EXPORT struct ndctl_cmd *
+ndctl_dimm_cmd_new_ack_shutdown_count(struct ndctl_dimm *dimm)
+{
+	struct ndctl_dimm_ops *ops = dimm->ops;
+
+	if (ops && ops->new_ack_shutdown_count)
+		return ops->new_ack_shutdown_count(dimm);
+	else
+		return NULL;
+}
diff --git a/ndctl/libndctl.h b/ndctl/libndctl.h
index 6091ff3..0102948 100644
--- a/ndctl/libndctl.h
+++ b/ndctl/libndctl.h
@@ -624,6 +624,7 @@ unsigned long long ndctl_cmd_fw_info_get_updated_version(struct ndctl_cmd *cmd);
 unsigned int ndctl_cmd_fw_start_get_context(struct ndctl_cmd *cmd);
 unsigned long long ndctl_cmd_fw_fquery_get_fw_rev(struct ndctl_cmd *cmd);
 enum ND_FW_STATUS ndctl_cmd_fw_xlat_firmware_status(struct ndctl_cmd *cmd);
+struct ndctl_cmd *ndctl_dimm_cmd_new_ack_shutdown_count(struct ndctl_dimm *dimm);
 
 #ifdef __cplusplus
 } /* extern "C" */

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH v2 2/2] ndctl: adding unit test for enable ack shutdown count
  2018-02-15 22:31 [PATCH v2 1/2] ndctl: add support for acknolwedge shutdown count enable Dave Jiang
@ 2018-02-15 22:32 ` Dave Jiang
  0 siblings, 0 replies; 2+ messages in thread
From: Dave Jiang @ 2018-02-15 22:32 UTC (permalink / raw)
  To: vishal.l.verma, dan.j.williams; +Cc: linux-nvdimm

Adding a unit test that will set the acknowledge shutdown count enable.

Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
 test/Makefile.am              |   12 +++
 test/ack-shutdown-count-set.c |  144 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 154 insertions(+), 2 deletions(-)
 create mode 100644 test/ack-shutdown-count-set.c

diff --git a/test/Makefile.am b/test/Makefile.am
index a473674..749055c 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -19,7 +19,8 @@ TESTS =\
 	btt-errors.sh \
 	hugetlb \
 	btt-pad-compat.sh \
-	firmware-update.sh
+	firmware-update.sh \
+	ack-shutdown-count-set
 
 check_PROGRAMS =\
 	libndctl \
@@ -31,7 +32,8 @@ check_PROGRAMS =\
 	smart-notify \
 	smart-listen \
 	hugetlb \
-	daxdev-errors
+	daxdev-errors \
+	ack-shutdown-count-set
 
 if ENABLE_DESTRUCTIVE
 TESTS +=\
@@ -70,6 +72,12 @@ dsm_fail_SOURCES =\
 
 dsm_fail_LDADD = $(LIBNDCTL_LIB) $(KMOD_LIBS)
 
+ack_shutdown_count_set_SOURCES =\
+	ack-shutdown-count-set.c \
+	$(testcore)
+
+ack_shutdown_count_set_LDADD = $(LIBNDCTL_LIB) $(KMOD_LIBS)
+
 blk_ns_SOURCES = blk_namespaces.c $(testcore)
 blk_ns_LDADD = $(LIBNDCTL_LIB) $(KMOD_LIBS)
 
diff --git a/test/ack-shutdown-count-set.c b/test/ack-shutdown-count-set.c
new file mode 100644
index 0000000..ef38176
--- /dev/null
+++ b/test/ack-shutdown-count-set.c
@@ -0,0 +1,144 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright(c) 2018 Intel Corporation. All rights reserved. */
+
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <errno.h>
+#include <syslog.h>
+#include <libkmod.h>
+#include <util/log.h>
+#include <util/sysfs.h>
+#include <linux/version.h>
+
+#include <ccan/array_size/array_size.h>
+#include <ndctl/libndctl.h>
+#ifdef HAVE_NDCTL_H
+#include <linux/ndctl.h>
+#else
+#include <ndctl.h>
+#endif
+#include <test.h>
+
+static int test_dimm(struct ndctl_dimm *dimm)
+{
+	struct ndctl_cmd *cmd;
+	int rc = 0;
+
+	cmd = ndctl_dimm_cmd_new_ack_shutdown_count(dimm);
+	if (!cmd)
+		return -ENOMEM;
+
+	rc = ndctl_cmd_submit(cmd);
+	if (rc < 0)
+		goto out;
+
+	rc = ndctl_cmd_get_firmware_status(cmd);
+	if (rc != 0) {
+		fprintf(stderr, "dimm %s LSS enable set failed\n",
+				ndctl_dimm_get_devname(dimm));
+		goto out;
+	}
+
+	printf("DIMM %s LSS enable set\n", ndctl_dimm_get_devname(dimm));
+
+out:
+	ndctl_cmd_unref(cmd);
+	return rc;
+}
+
+static void reset_bus(struct ndctl_bus *bus)
+{
+	struct ndctl_region *region;
+	struct ndctl_dimm *dimm;
+
+	/* disable all regions so that set_config_data commands are permitted */
+	ndctl_region_foreach(bus, region)
+		ndctl_region_disable_invalidate(region);
+
+	ndctl_dimm_foreach(bus, dimm)
+		ndctl_dimm_zero_labels(dimm);
+}
+
+static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
+{
+	struct ndctl_bus *bus = ndctl_bus_get_by_provider(ctx, "nfit_test.0");
+	struct ndctl_dimm *dimm;
+	struct ndctl_region *region;
+	struct log_ctx log_ctx;
+	int rc = 0;
+
+	if (!ndctl_test_attempt(test, KERNEL_VERSION(4, 15, 0)))
+		return 77;
+
+	if (!bus)
+		return -ENXIO;
+
+	log_init(&log_ctx, "test/ack-shutdown-count-set", "NDCTL_TEST");
+
+	ndctl_bus_wait_probe(bus);
+
+	ndctl_region_foreach(bus, region)
+		ndctl_region_disable_invalidate(region);
+
+	ndctl_dimm_foreach(bus, dimm) {
+		fprintf(stderr, "Testing dimm: %s\n",
+				ndctl_dimm_get_devname(dimm));
+		rc = test_dimm(dimm);
+		if (rc < 0) {
+			fprintf(stderr, "dimm %s failed\n",
+				ndctl_dimm_get_devname(dimm));
+			goto out;
+		}
+	}
+
+out:
+	reset_bus(bus);
+	return rc;
+}
+
+static int test_ack_shutdown_count_set(int loglevel, struct ndctl_test *test,
+		struct ndctl_ctx *ctx)
+{
+	struct kmod_module *mod;
+	struct kmod_ctx *kmod_ctx;
+	int result = EXIT_FAILURE, err;
+
+	ndctl_set_log_priority(ctx, loglevel);
+	err = nfit_test_init(&kmod_ctx, &mod, NULL, loglevel, test);
+	if (err < 0) {
+		result = 77;
+		ndctl_test_skip(test);
+		fprintf(stderr, "%s unavailable skipping tests\n",
+				"nfit_test");
+		return result;
+	}
+
+	result = do_test(ctx, test);
+	kmod_module_remove_module(mod, 0);
+
+	kmod_unref(kmod_ctx);
+	return result;
+}
+
+int main(int argc, char *argv[])
+{
+	struct ndctl_test *test = ndctl_test_new(0);
+	struct ndctl_ctx *ctx;
+	int rc;
+
+	if (!test) {
+		fprintf(stderr, "failed to initialize test\n");
+		return EXIT_FAILURE;
+	}
+
+	rc = ndctl_new(&ctx);
+	if (rc)
+		return ndctl_test_result(test, rc);
+	rc = test_ack_shutdown_count_set(LOG_DEBUG, test, ctx);
+	ndctl_unref(ctx);
+
+	return ndctl_test_result(test, rc);
+}

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-02-15 22:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-15 22:31 [PATCH v2 1/2] ndctl: add support for acknolwedge shutdown count enable Dave Jiang
2018-02-15 22:32 ` [PATCH v2 2/2] ndctl: adding unit test for enable ack shutdown count Dave Jiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).