From patchwork Thu Feb 8 21:04:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 10208031 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 567E6603EE for ; Thu, 8 Feb 2018 21:04:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46D32296AF for ; Thu, 8 Feb 2018 21:04:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3BAE5296B1; Thu, 8 Feb 2018 21:04:35 +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 EBD00296B0 for ; Thu, 8 Feb 2018 21:04:34 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 61F432237A4F3; Thu, 8 Feb 2018 12:58:49 -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.31; helo=mga06.intel.com; envelope-from=vishal.l.verma@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 D31E8222DE14D for ; Thu, 8 Feb 2018 12:58:47 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Feb 2018 13:04:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,480,1511856000"; d="scan'208";a="202461225" Received: from vverma7-desk1.lm.intel.com ([10.232.112.218]) by fmsmga005.fm.intel.com with ESMTP; 08 Feb 2018 13:04:32 -0800 From: Vishal Verma To: Subject: [ndctl PATCH 2/4] ndctl: add ndctl_encode_smart_temperature() Date: Thu, 8 Feb 2018 14:04:26 -0700 Message-Id: <20180208210428.7285-2-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180208210428.7285-1-vishal.l.verma@intel.com> References: <20180208210428.7285-1-vishal.l.verma@intel.com> 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: , MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP This provides for encoding of a human-readable temperature value into the format expected by the smart command Cc: Dan Williams Signed-off-by: Vishal Verma --- ndctl/lib/libndctl.c | 16 ++++++++++++++++ ndctl/lib/libndctl.sym | 1 + ndctl/libndctl.h | 1 + 3 files changed, 18 insertions(+) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index 4119a2e..ed5a65b 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -87,6 +87,22 @@ NDCTL_EXPORT double ndctl_decode_smart_temperature(unsigned int temp) return t; } +NDCTL_EXPORT unsigned int ndctl_encode_smart_temperature(double temp) +{ + bool negative = false; + unsigned int t; + + if (temp < 0) { + negative = true; + temp *= -1; + } + t = temp; + t *= 16; + if (negative) + t |= (1 << 15); + return t; +} + struct ndctl_ctx; /** diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym index c160847..e7f9675 100644 --- a/ndctl/lib/libndctl.sym +++ b/ndctl/lib/libndctl.sym @@ -322,6 +322,7 @@ global: ndctl_cmd_smart_threshold_set_ctrl_temperature; ndctl_cmd_smart_threshold_set_spares; ndctl_decode_smart_temperature; + ndctl_encode_smart_temperature; ndctl_dimm_cmd_new_smart_inject; ndctl_cmd_smart_inject_media_temperature; ndctl_cmd_smart_inject_spares; diff --git a/ndctl/libndctl.h b/ndctl/libndctl.h index bd33d39..6091ff3 100644 --- a/ndctl/libndctl.h +++ b/ndctl/libndctl.h @@ -76,6 +76,7 @@ size_t ndctl_min_namespace_size(void); size_t ndctl_sizeof_namespace_index(void); size_t ndctl_sizeof_namespace_label(void); double ndctl_decode_smart_temperature(unsigned int temp); +unsigned int ndctl_encode_smart_temperature(double temp); struct ndctl_ctx; struct ndctl_ctx *ndctl_ref(struct ndctl_ctx *ctx);