From patchwork Tue Feb 13 00:11:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 10214951 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AF68060236 for ; Tue, 13 Feb 2018 00:11:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C98228E42 for ; Tue, 13 Feb 2018 00:11:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A8CF28E36; Tue, 13 Feb 2018 00:11:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D091F28E3E for ; Tue, 13 Feb 2018 00:11:04 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 443FB223DB7AE; Mon, 12 Feb 2018 16:05:14 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=dave.jiang@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 441EA21E0B9F2 for ; Mon, 12 Feb 2018 16:05:12 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Feb 2018 16:11:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,504,1511856000"; d="scan'208";a="200661004" Received: from djiang5-desk3.ch.intel.com ([143.182.136.93]) by orsmga005.jf.intel.com with ESMTP; 12 Feb 2018 16:11:02 -0800 Subject: [PATCH] ndctl: add option to list firmware information for a DIMM From: Dave Jiang To: dan.j.williams@intel.com Date: Mon, 12 Feb 2018 17:11:02 -0700 Message-ID: <151848066201.13592.3757378386488366418.stgit@djiang5-desk3.ch.intel.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-nvdimm@lists.01.org Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Adding firmware output of firmware information when ndctl list -D -F is used. Components displayed are current firmware version, updated firmware version, and if a coldboot is required (firmware updated). Signed-off-by: Dave Jiang --- Documentation/ndctl/ndctl-list.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Documentation/ndctl/ndctl-list.txt b/Documentation/ndctl/ndctl-list.txt index fc07a71..85b87d4 100644 --- a/Documentation/ndctl/ndctl-list.txt +++ b/Documentation/ndctl/ndctl-list.txt @@ -110,6 +110,19 @@ include::xable-region-options.txt[] } } +-F:: +--firmware:: + Include dimm firmware info in the listing. For example: +[verse] +{ + "dev":"nmem0", + "firmware":{ + "current_version":0, + "next_version":1, + "coldboot_required":true + } +} + -X:: --device-dax:: Include device-dax ("daxregion") details when a namespace is in diff --git a/ndctl/Makefile.am b/ndctl/Makefile.am index 2054c1a..e0db97b 100644 --- a/ndctl/Makefile.am +++ b/ndctl/Makefile.am @@ -13,6 +13,7 @@ ndctl_SOURCES = ndctl.c \ test.c \ ../util/json.c \ util/json-smart.c \ + util/json-firmware.c \ inject-error.c \ update.c \ inject-smart.c diff --git a/ndctl/list.c b/ndctl/list.c index 37a224a..ebe0a67 100644 --- a/ndctl/list.c +++ b/ndctl/list.c @@ -35,6 +35,7 @@ static struct { bool dax; bool media_errors; bool human; + bool firmware; } list; static unsigned long listopts_to_flags(void) @@ -277,6 +278,7 @@ int cmd_list(int argc, const char **argv, void *ctx) "filter by region-type"), OPT_BOOLEAN('B', "buses", &list.buses, "include bus info"), OPT_BOOLEAN('D', "dimms", &list.dimms, "include dimm info"), + OPT_BOOLEAN('F', "firmware", &list.firmware, "include firmware info"), OPT_BOOLEAN('H', "health", &list.health, "include dimm health"), OPT_BOOLEAN('R', "regions", &list.regions, "include region info"), @@ -420,6 +422,25 @@ int cmd_list(int argc, const char **argv, void *ctx) } } + if (list.firmware) { + struct json_object *jfirmware; + + jfirmware = util_dimm_firmware_to_json(dimm); + if (jfirmware) + json_object_object_add(jdimm, + "firmware", + jfirmware); + else if (ndctl_dimm_is_cmd_supported(dimm, + ND_CMD_CALL)) { + /* + * Failed to retrieve firmware + * version. + */ + fail("\n"); + continue; + } + } + /* * 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 new file mode 100644 index 0000000..0010493 --- /dev/null +++ b/ndctl/util/json-firmware.c @@ -0,0 +1,88 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include +#include +#include +#include +#include +#include +#include + +struct json_object *util_dimm_firmware_to_json(struct ndctl_dimm *dimm) +{ + struct json_object *jfirmware = json_object_new_object(); + struct json_object *jobj; + struct ndctl_cmd *cmd; + int rc; + uint64_t run, updated; + bool reboot = false; + + if (!jfirmware) + return NULL; + + cmd = ndctl_dimm_cmd_new_fw_get_info(dimm); + if (!cmd) + goto err; + + rc = ndctl_cmd_submit(cmd); + if (rc || ndctl_cmd_fw_xlat_firmware_status(cmd) != FW_SUCCESS) { + jobj = json_object_new_string("unknown"); + if (jobj) + json_object_object_add(jfirmware, "version", + jobj); + goto out; + } + + run = ndctl_cmd_fw_info_get_run_version(cmd); + if (run == ULLONG_MAX) { + jobj = json_object_new_string("unknown"); + if (jobj) + json_object_object_add(jfirmware, "current_version", + jobj); + goto out; + } + + jobj = json_object_new_int64(run); + if (jobj) + json_object_object_add(jfirmware, "current_version", jobj); + + updated = ndctl_cmd_fw_info_get_updated_version(cmd); + if (updated == ULLONG_MAX) { + jobj = json_object_new_string("unknown"); + if (jobj) + json_object_object_add(jfirmware, "next_version", + jobj); + goto out; + } + + if (updated == 0) { + jobj = json_object_new_string("none"); + if (jobj) + json_object_object_add(jfirmware, "next_version", + jobj); + } else { + reboot = true; + jobj = json_object_new_int64(updated); + if (jobj) + json_object_object_add(jfirmware, + "next_version", jobj); + } + + if (reboot) { + jobj = json_object_new_boolean(reboot); + if (jobj) + json_object_object_add(jfirmware, + "coldboot_required", 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.h b/util/json.h index 9663475..8504d5c 100644 --- a/util/json.h +++ b/util/json.h @@ -52,4 +52,5 @@ struct json_object *util_json_object_size(unsigned long long size, struct json_object *util_json_object_hex(unsigned long long val, unsigned long flags); struct json_object *util_dimm_health_to_json(struct ndctl_dimm *dimm); +struct json_object *util_dimm_firmware_to_json(struct ndctl_dimm *dimm); #endif /* __NDCTL_JSON_H__ */