All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: linux-nvdimm@lists.01.org
Cc: vishal.l.verma@intel.com
Subject: [ndctl PATCH 06/16] ndctl/dimm: Prepare to emit dimm json object after firmware update
Date: Mon, 06 Jul 2020 19:40:50 -0700	[thread overview]
Message-ID: <159408965016.2386154.1586833845040694311.stgit@dwillia2-desk3.amr.corp.intel.com> (raw)
In-Reply-To: <159408961822.2386154.888266173771881937.stgit@dwillia2-desk3.amr.corp.intel.com>

Move util_dimm_firmware_to_json() internal to util_dimm_to_json().
Introduce a new UTIL_JSON_FIRMWARE flag to optionally dump firmware info
when listing the dimm from either 'ndctl list', or after 'ndctl
update-firmware'.

Move util_dimm_firmware_to_json() out of ndctl/util/json-firmware.c into
the core util/json.c.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 ndctl/Makefile.am          |    1 -
 ndctl/list.c               |   10 +----
 ndctl/util/json-firmware.c |   85 --------------------------------------------
 util/json.c                |   84 +++++++++++++++++++++++++++++++++++++++++++
 util/json.h                |   17 +++++----
 5 files changed, 95 insertions(+), 102 deletions(-)
 delete mode 100644 ndctl/util/json-firmware.c

diff --git a/ndctl/Makefile.am b/ndctl/Makefile.am
index 49c6c4ab4498..a63b1e0b8a01 100644
--- a/ndctl/Makefile.am
+++ b/ndctl/Makefile.am
@@ -25,7 +25,6 @@ ndctl_SOURCES = ndctl.c \
 		../util/json.c \
 		../util/json.h \
 		util/json-smart.c \
-		util/json-firmware.c \
 		util/keys.h \
 		inject-error.c \
 		inject-smart.c \
diff --git a/ndctl/list.c b/ndctl/list.c
index 31fb1b9593a2..1f7cc8ee1deb 100644
--- a/ndctl/list.c
+++ b/ndctl/list.c
@@ -59,6 +59,8 @@ static unsigned long listopts_to_flags(void)
 		flags |= UTIL_JSON_VERBOSE;
 	if (list.capabilities)
 		flags |= UTIL_JSON_CAPABILITIES;
+	if (list.firmware)
+		flags |= UTIL_JSON_FIRMWARE;
 	return flags;
 }
 
@@ -367,14 +369,6 @@ static void filter_dimm(struct ndctl_dimm *dimm, struct util_filter_ctx *ctx)
 		}
 	}
 
-	if (list.firmware) {
-		struct json_object *jfirmware;
-
-		jfirmware = util_dimm_firmware_to_json(dimm, lfa->flags);
-		if (jfirmware)
-			json_object_object_add(jdimm, "firmware", jfirmware);
-	}
-
 	/*
 	 * Without a bus we are collecting dimms anonymously across the
 	 * platform.
diff --git a/ndctl/util/json-firmware.c b/ndctl/util/json-firmware.c
deleted file mode 100644
index 9a9db064d851..000000000000
--- a/ndctl/util/json-firmware.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/* Copyright(c) 2018 Intel Corporation. All rights reserved. */
-#include <limits.h>
-#include <util/json.h>
-#include <uuid/uuid.h>
-#include <json-c/json.h>
-#include <ndctl/libndctl.h>
-#include <ccan/array_size/array_size.h>
-#include <ndctl.h>
-
-struct json_object *util_dimm_firmware_to_json(struct ndctl_dimm *dimm,
-		unsigned long flags)
-{
-	struct json_object *jfirmware = json_object_new_object();
-	struct json_object *jobj;
-	struct ndctl_cmd *cmd;
-	int rc;
-	uint64_t run, next;
-
-	if (!jfirmware)
-		return NULL;
-
-	cmd = ndctl_dimm_cmd_new_fw_get_info(dimm);
-	if (!cmd)
-		goto err;
-
-	rc = ndctl_cmd_submit(cmd);
-	if ((rc < 0) || ndctl_cmd_fw_xlat_firmware_status(cmd) != FW_SUCCESS) {
-		jobj = util_json_object_hex(-1, flags);
-		if (jobj)
-			json_object_object_add(jfirmware, "current_version",
-					jobj);
-		goto out;
-	}
-
-	run = ndctl_cmd_fw_info_get_run_version(cmd);
-	if (run == ULLONG_MAX) {
-		jobj = util_json_object_hex(-1, flags);
-		if (jobj)
-			json_object_object_add(jfirmware, "current_version",
-					jobj);
-		goto out;
-	}
-
-	jobj = util_json_object_hex(run, flags);
-	if (jobj)
-		json_object_object_add(jfirmware, "current_version", jobj);
-
-	rc = ndctl_dimm_fw_update_supported(dimm);
-	jobj = json_object_new_boolean(rc == 0);
-	if (jobj)
-		json_object_object_add(jfirmware, "can_update", jobj);
-
-	next = ndctl_cmd_fw_info_get_updated_version(cmd);
-	if (next == ULLONG_MAX) {
-		jobj = util_json_object_hex(-1, flags);
-		if (jobj)
-			json_object_object_add(jfirmware, "next_version",
-					jobj);
-		goto out;
-	}
-
-	if (next != 0) {
-		jobj = util_json_object_hex(next, flags);
-		if (jobj)
-			json_object_object_add(jfirmware,
-					"next_version", jobj);
-
-		jobj = json_object_new_boolean(true);
-		if (jobj)
-			json_object_object_add(jfirmware,
-					"need_powercycle", jobj);
-	}
-
-	ndctl_cmd_unref(cmd);
-	return jfirmware;
-
-err:
-	json_object_put(jfirmware);
-	jfirmware = NULL;
-out:
-	if (cmd)
-		ndctl_cmd_unref(cmd);
-	return jfirmware;
-}
diff --git a/util/json.c b/util/json.c
index 21ab25674624..59a3d07cc4a6 100644
--- a/util/json.c
+++ b/util/json.c
@@ -156,6 +156,82 @@ struct json_object *util_bus_to_json(struct ndctl_bus *bus)
 	return NULL;
 }
 
+struct json_object *util_dimm_firmware_to_json(struct ndctl_dimm *dimm,
+		unsigned long flags)
+{
+	struct json_object *jfirmware = json_object_new_object();
+	struct json_object *jobj;
+	struct ndctl_cmd *cmd;
+	int rc;
+	uint64_t run, next;
+
+	if (!jfirmware)
+		return NULL;
+
+	cmd = ndctl_dimm_cmd_new_fw_get_info(dimm);
+	if (!cmd)
+		goto err;
+
+	rc = ndctl_cmd_submit(cmd);
+	if ((rc < 0) || ndctl_cmd_fw_xlat_firmware_status(cmd) != FW_SUCCESS) {
+		jobj = util_json_object_hex(-1, flags);
+		if (jobj)
+			json_object_object_add(jfirmware, "current_version",
+					jobj);
+		goto out;
+	}
+
+	run = ndctl_cmd_fw_info_get_run_version(cmd);
+	if (run == ULLONG_MAX) {
+		jobj = util_json_object_hex(-1, flags);
+		if (jobj)
+			json_object_object_add(jfirmware, "current_version",
+					jobj);
+		goto out;
+	}
+
+	jobj = util_json_object_hex(run, flags);
+	if (jobj)
+		json_object_object_add(jfirmware, "current_version", jobj);
+
+	rc = ndctl_dimm_fw_update_supported(dimm);
+	jobj = json_object_new_boolean(rc == 0);
+	if (jobj)
+		json_object_object_add(jfirmware, "can_update", jobj);
+
+	next = ndctl_cmd_fw_info_get_updated_version(cmd);
+	if (next == ULLONG_MAX) {
+		jobj = util_json_object_hex(-1, flags);
+		if (jobj)
+			json_object_object_add(jfirmware, "next_version",
+					jobj);
+		goto out;
+	}
+
+	if (next != 0) {
+		jobj = util_json_object_hex(next, flags);
+		if (jobj)
+			json_object_object_add(jfirmware,
+					"next_version", jobj);
+
+		jobj = json_object_new_boolean(true);
+		if (jobj)
+			json_object_object_add(jfirmware,
+					"need_powercycle", jobj);
+	}
+
+	ndctl_cmd_unref(cmd);
+	return jfirmware;
+
+err:
+	json_object_put(jfirmware);
+	jfirmware = NULL;
+out:
+	if (cmd)
+		ndctl_cmd_unref(cmd);
+	return jfirmware;
+}
+
 struct json_object *util_dimm_to_json(struct ndctl_dimm *dimm,
 		unsigned long flags)
 {
@@ -266,6 +342,14 @@ struct json_object *util_dimm_to_json(struct ndctl_dimm *dimm,
 			json_object_object_add(jdimm, "security_frozen", jobj);
 	}
 
+	if (flags & UTIL_JSON_FIRMWARE) {
+		struct json_object *jfirmware;
+
+		jfirmware = util_dimm_firmware_to_json(dimm, flags);
+		if (jfirmware)
+			json_object_object_add(jdimm, "firmware", jfirmware);
+	}
+
 	return jdimm;
  err:
 	json_object_put(jdimm);
diff --git a/util/json.h b/util/json.h
index 6d39d3aa4693..fc91a8db034f 100644
--- a/util/json.h
+++ b/util/json.h
@@ -18,14 +18,15 @@
 #include <ccan/short_types/short_types.h>
 
 enum util_json_flags {
-	UTIL_JSON_IDLE = (1 << 0),
-	UTIL_JSON_MEDIA_ERRORS = (1 << 1),
-	UTIL_JSON_DAX = (1 << 2),
-	UTIL_JSON_DAX_DEVS = (1 << 3),
-	UTIL_JSON_HUMAN = (1 << 4),
-	UTIL_JSON_VERBOSE = (1 << 5),
-	UTIL_JSON_CAPABILITIES = (1 << 6),
-	UTIL_JSON_CONFIGURED = (1 << 7),
+	UTIL_JSON_IDLE		= (1 << 0),
+	UTIL_JSON_MEDIA_ERRORS	= (1 << 1),
+	UTIL_JSON_DAX		= (1 << 2),
+	UTIL_JSON_DAX_DEVS	= (1 << 3),
+	UTIL_JSON_HUMAN		= (1 << 4),
+	UTIL_JSON_VERBOSE	= (1 << 5),
+	UTIL_JSON_CAPABILITIES	= (1 << 6),
+	UTIL_JSON_CONFIGURED	= (1 << 7),
+	UTIL_JSON_FIRMWARE	= (1 << 8),
 };
 
 struct json_object;
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

  parent reply	other threads:[~2020-07-07  2:57 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-07  2:40 [ndctl PATCH 00/16] Firmware Activation and Test Updates Dan Williams
2020-07-07  2:40 ` [ndctl PATCH 01/16] ndctl/build: Fix zero-length array warnings Dan Williams
2020-07-07  2:40 ` [ndctl PATCH 02/16] ndctl/dimm: Fix chatty status messages Dan Williams
2020-07-07  2:40 ` [ndctl PATCH 03/16] ndctl/list: Indicate firmware update capability Dan Williams
2020-07-07  2:40 ` [ndctl PATCH 04/16] ndctl/dimm: Detect firmware-update vs ARS conflict Dan Williams
2020-07-07  2:40 ` [ndctl PATCH 05/16] ndctl/dimm: Improve firmware-update failure message Dan Williams
2020-07-07  2:40 ` Dan Williams [this message]
2020-07-07  2:40 ` [ndctl PATCH 07/16] ndctl/dimm: Emit dimm firmware details after update Dan Williams
2020-07-07  2:41 ` [ndctl PATCH 08/16] ndctl/list: Add firmware activation enumeration Dan Williams
2020-07-07  2:41 ` [ndctl PATCH 09/16] ndctl/dimm: Auto-arm firmware activation Dan Williams
2020-07-07  2:41 ` [ndctl PATCH 10/16] ndctl/bus: Add 'activate-firmware' command Dan Williams
2020-07-07  2:41 ` [ndctl PATCH 11/16] ndctl/docs: Update copyright date Dan Williams
2020-07-07  2:41 ` [ndctl PATCH 12/16] ndctl/test: Test firmware-activation interface Dan Williams
2020-07-07  2:41 ` [ndctl PATCH 13/16] test: Validate strict iomem protections of pmem Dan Williams
2020-07-07  2:41 ` [ndctl PATCH 14/16] ndctl: Refactor nfit.h to acpi.h Dan Williams
2020-07-07  2:41 ` [ndctl PATCH 15/16] daxctl: Add 'split-acpi' command to generate custom ACPI tables Dan Williams
2020-07-07  2:41 ` [ndctl PATCH 16/16] test/ndctl: mremap pmd confusion Dan Williams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=159408965016.2386154.1586833845040694311.stgit@dwillia2-desk3.amr.corp.intel.com \
    --to=dan.j.williams@intel.com \
    --cc=linux-nvdimm@lists.01.org \
    --cc=vishal.l.verma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.