From patchwork Thu Feb 22 20:49:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 10236379 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 16E3C60209 for ; Thu, 22 Feb 2018 20:49:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 163BD28E50 for ; Thu, 22 Feb 2018 20:49:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0AD7128E5C; Thu, 22 Feb 2018 20:49:52 +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 6F19428E50 for ; Thu, 22 Feb 2018 20:49:51 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 42E3B20954CBF; Thu, 22 Feb 2018 12:43:50 -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=192.55.52.93; helo=mga11.intel.com; envelope-from=dave.jiang@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 328E6208F7AAD for ; Thu, 22 Feb 2018 12:43:48 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Feb 2018 12:49:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,378,1515484800"; d="scan'208";a="20094835" Received: from djiang5-desk3.ch.intel.com ([143.182.136.93]) by orsmga008.jf.intel.com with ESMTP; 22 Feb 2018 12:49:48 -0800 Subject: [PATCH v2 4/4] ndctl: accept DIMM name without -d option From: Dave Jiang To: vishal.l.verma@intel.com, dan.j.williams@intel.com Date: Thu, 22 Feb 2018 13:49:48 -0700 Message-ID: <151933258802.36856.4324987007442257845.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <151933257135.36856.6462188364046414070.stgit@djiang5-desk3.ch.intel.com> References: <151933257135.36856.6462188364046414070.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 Making update-firmware in sync with other ndctl syntax and accept DIMM id without using a switch. The -d option will still be accepted. Now it will accept multiple dimm ids as well as the "all" option. i.e. ndctl update-firmware -f file.bin nmem0 nmem1 Signed-off-by: Dave Jiang --- ndctl/update.c | 119 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 78 insertions(+), 41 deletions(-) diff --git a/Documentation/ndctl/ndctl-update-firmware.txt b/Documentation/ndctl/ndctl-update-firmware.txt index d742302..6d74c11 100644 --- a/Documentation/ndctl/ndctl-update-firmware.txt +++ b/Documentation/ndctl/ndctl-update-firmware.txt @@ -8,7 +8,18 @@ ndctl-update-firmware - provides updating of NVDIMM firmware SYNOPSIS -------- [verse] -'ndctl update-firmware' -f -d +'ndctl update-firmware' [..] [] + +This command updates the persistent DIMM's firmware. + +OPTIONS +------- +-f:: +--firmware:: + firmware file to be updated. +-v:: +--verbose:: + turn on verbose/debug option COPYRIGHT --------- diff --git a/ndctl/update.c b/ndctl/update.c index b148b70..acf2a64 100644 --- a/ndctl/update.c +++ b/ndctl/update.c @@ -467,32 +467,6 @@ static int update_firmware(struct update_context *uctx) return 0; } -static int get_ndctl_dimm(struct update_context *uctx, void *ctx) -{ - struct ndctl_dimm *dimm; - struct ndctl_bus *bus; - int rc = -ENODEV; - - ndctl_bus_foreach(ctx, bus) - ndctl_dimm_foreach(bus, dimm) { - if (!util_dimm_filter(dimm, uctx->dimm_id)) - continue; - if (!ndctl_dimm_fw_update_supported(dimm)) { - error("DIMM firmware update not supported by the kernel."); - return -ENOTSUP; - } - uctx->dimm = dimm; - rc = update_firmware(uctx); - if (rc < 0) { - error("Update firmware for dimm %s failed\n", - ndctl_dimm_get_devname(dimm)); - continue; - } - } - - return rc; -} - static int verify_fw_file(struct update_context *uctx) { struct stat st; @@ -538,6 +512,29 @@ cleanup: return rc; } +static int process_dimm(struct update_context *uctx, const char *dimm_id, + struct ndctl_dimm *dimm) +{ + int rc; + + if (!util_dimm_filter(dimm, dimm_id)) + return -ENODEV; + if (!ndctl_dimm_fw_update_supported(dimm)) { + error("DIMM firmware update not supported by the kernel."); + return -ENOTSUP; + } + + uctx->dimm = dimm; + rc = update_firmware(uctx); + if (rc < 0) { + error("Update firmware for dimm %s failed\n", + ndctl_dimm_get_devname(dimm)); + return rc; + } + + return -ENODEV; +} + int cmd_update_firmware(int argc, const char **argv, void *ctx) { bool verbose; @@ -554,13 +551,34 @@ int cmd_update_firmware(int argc, const char **argv, void *ctx) "ndctl update_firmware []", NULL }; - int i, rc; + int i, rc, err = 0; + unsigned long id; argc = parse_options(argc, argv, options, u, 0); - for (i = 0; i < argc; i++) - error("unknown parameter \"%s\"", argv[i]); - if (argc) + + if (argc == 0 && !uctx.dimm_id) usage_with_options(u, options); + if (!uctx.dimm_id) { + for (i = 0; i < argc; i++) { + if (strcmp(argv[i], "all") == 0) { + argv[0] = "all"; + argc = 1; + break; + } + + if (sscanf(argv[i], "nmem%lu", &id) != 1) { + fprintf(stderr, + "'%s' is not a valid dimm name\n", + argv[i]); + err++; + } + } + + if (err == argc) { + usage_with_options(u, options); + return -EINVAL; + } + } if (verbose) ndctl_set_log_priority(ctx, LOG_DEBUG); @@ -571,25 +589,44 @@ int cmd_update_firmware(int argc, const char **argv, void *ctx) return -EINVAL; } - if (!uctx.dimm_id) { - error("No DIMM ID provided"); - usage_with_options(u, options); - return -EINVAL; - } - rc = verify_fw_file(&uctx); if (rc < 0) { error("Failed to verify firmware file %s", uctx.fw_path); return rc; } - rc = get_ndctl_dimm(&uctx, ctx); - if (rc < 0) { - if (rc == -ENODEV) - error("DIMM %s not found", uctx.dimm_id); - return rc; + for (i = 0; i < argc; i++) { + struct ndctl_dimm *dimm; + struct ndctl_bus *bus; + + if (sscanf(argv[i], "nmem%lu", &id) != 1 + && strcmp(argv[i], "all") != 0) + continue; + + ndctl_bus_foreach(ctx, bus) + ndctl_dimm_foreach(bus, dimm) { + rc = process_dimm(&uctx, argv[i], dimm); + if (rc < 0) { + if (rc == -ENOTSUP) + goto cleanup; + continue; + } + } } + if (uctx.dimm_id) { + struct ndctl_dimm *dimm; + struct ndctl_bus *bus; + + ndctl_bus_foreach(ctx, bus) + ndctl_dimm_foreach(bus, dimm) { + rc = process_dimm(&uctx, uctx.dimm_id, dimm); + if (rc < 0) + goto cleanup; + } + } + +cleanup: if (uctx.start) ndctl_cmd_unref(uctx.start);