Linux CXL
 help / color / mirror / Atom feed
From: Jehoon Park <jehoon.park@samsung.com>
To: linux-cxl@vger.kernel.org
Cc: nvdimm@lists.linux.dev,
	Alison Schofield <alison.schofield@intel.com>,
	Vishal Verma <vishal.l.verma@intel.com>,
	Ira Weiny <ira.weiny@intel.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Dave Jiang <dave.jiang@intel.com>,
	Davidlohr Bueso <dave@stgolabs.net>,
	Jonathan Cameron <jonathan.cameron@huawei.com>,
	Kyungsan Kim <ks0204.kim@samsung.com>,
	Junhyeok Im <junhyeok.im@samsung.com>,
	Jehoon Park <jehoon.park@samsung.com>
Subject: [ndctl PATCH RESEND 2/2] libcxl: Fix accessors for temperature field to support negative value
Date: Mon, 17 Jul 2023 15:29:08 +0900	[thread overview]
Message-ID: <20230717062908.8292-3-jehoon.park@samsung.com> (raw)
In-Reply-To: <20230717062908.8292-1-jehoon.park@samsung.com>

Add a new macro function to retrieve a signed value such as a temperature.
Replace indistinguishable error numbers with debug message.

Signed-off-by: Jehoon Park <jehoon.park@samsung.com>
---
 cxl/lib/libcxl.c | 36 ++++++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
index 769cd8a..fca7faa 100644
--- a/cxl/lib/libcxl.c
+++ b/cxl/lib/libcxl.c
@@ -3452,11 +3452,21 @@ cxl_cmd_alert_config_get_life_used_prog_warn_threshold(struct cxl_cmd *cmd)
 			 life_used_prog_warn_threshold);
 }
 
+#define cmd_get_field_s16(cmd, n, N, field)				\
+do {									\
+	struct cxl_cmd_##n *c =						\
+		(struct cxl_cmd_##n *)cmd->send_cmd->out.payload;	\
+	int rc = cxl_cmd_validate_status(cmd, CXL_MEM_COMMAND_ID_##N);	\
+	if (rc)								\
+		return 0xffff;						\
+	return (int16_t)le16_to_cpu(c->field);					\
+} while(0)
+
 CXL_EXPORT int
 cxl_cmd_alert_config_get_dev_over_temperature_crit_alert_threshold(
 	struct cxl_cmd *cmd)
 {
-	cmd_get_field_u16(cmd, get_alert_config, GET_ALERT_CONFIG,
+	cmd_get_field_s16(cmd, get_alert_config, GET_ALERT_CONFIG,
 			  dev_over_temperature_crit_alert_threshold);
 }
 
@@ -3464,7 +3474,7 @@ CXL_EXPORT int
 cxl_cmd_alert_config_get_dev_under_temperature_crit_alert_threshold(
 	struct cxl_cmd *cmd)
 {
-	cmd_get_field_u16(cmd, get_alert_config, GET_ALERT_CONFIG,
+	cmd_get_field_s16(cmd, get_alert_config, GET_ALERT_CONFIG,
 			  dev_under_temperature_crit_alert_threshold);
 }
 
@@ -3472,7 +3482,7 @@ CXL_EXPORT int
 cxl_cmd_alert_config_get_dev_over_temperature_prog_warn_threshold(
 	struct cxl_cmd *cmd)
 {
-	cmd_get_field_u16(cmd, get_alert_config, GET_ALERT_CONFIG,
+	cmd_get_field_s16(cmd, get_alert_config, GET_ALERT_CONFIG,
 			  dev_over_temperature_prog_warn_threshold);
 }
 
@@ -3480,7 +3490,7 @@ CXL_EXPORT int
 cxl_cmd_alert_config_get_dev_under_temperature_prog_warn_threshold(
 	struct cxl_cmd *cmd)
 {
-	cmd_get_field_u16(cmd, get_alert_config, GET_ALERT_CONFIG,
+	cmd_get_field_s16(cmd, get_alert_config, GET_ALERT_CONFIG,
 			  dev_under_temperature_prog_warn_threshold);
 }
 
@@ -3695,28 +3705,34 @@ static int health_info_get_life_used_raw(struct cxl_cmd *cmd)
 CXL_EXPORT int cxl_cmd_health_info_get_life_used(struct cxl_cmd *cmd)
 {
 	int rc = health_info_get_life_used_raw(cmd);
+	struct cxl_ctx *ctx = cxl_memdev_get_ctx(cmd->memdev);
 
 	if (rc < 0)
-		return rc;
+		dbg(ctx, "%s: Invalid command status\n",
+		    cxl_memdev_get_devname(cmd->memdev));
 	if (rc == CXL_CMD_HEALTH_INFO_LIFE_USED_NOT_IMPL)
-		return -EOPNOTSUPP;
+		dbg(ctx, "%s: Life Used not implemented\n",
+		    cxl_memdev_get_devname(cmd->memdev));
 	return rc;
 }
 
 static int health_info_get_temperature_raw(struct cxl_cmd *cmd)
 {
-	cmd_get_field_u16(cmd, get_health_info, GET_HEALTH_INFO,
+	cmd_get_field_s16(cmd, get_health_info, GET_HEALTH_INFO,
 				 temperature);
 }
 
 CXL_EXPORT int cxl_cmd_health_info_get_temperature(struct cxl_cmd *cmd)
 {
 	int rc = health_info_get_temperature_raw(cmd);
+	struct cxl_ctx *ctx = cxl_memdev_get_ctx(cmd->memdev);
 
-	if (rc < 0)
-		return rc;
+	if (rc == 0xffff)
+		dbg(ctx, "%s: Invalid command status\n",
+		    cxl_memdev_get_devname(cmd->memdev));
 	if (rc == CXL_CMD_HEALTH_INFO_TEMPERATURE_NOT_IMPL)
-		return -EOPNOTSUPP;
+		dbg(ctx, "%s: Device Temperature not implemented\n",
+		    cxl_memdev_get_devname(cmd->memdev));
 	return rc;
 }
 
-- 
2.17.1


  parent reply	other threads:[~2023-07-17  6:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20230717062617epcas2p46229ab9feac5a094afd44761e2b9a403@epcas2p4.samsung.com>
2023-07-17  6:29 ` [ndctl PATCH RESEND 0/2] Fix accessors for temperature field when it is negative Jehoon Park
2023-07-17  6:29   ` [ndctl PATCH RESEND 1/2] cxl: Update a revision by CXL 3.0 specification Jehoon Park
2023-07-17 13:18     ` Nathan Fontenot
2023-07-18  4:34       ` Jehoon Park
2023-07-17  6:29   ` Jehoon Park [this message]
2023-07-24 21:08     ` [ndctl PATCH RESEND 2/2] libcxl: Fix accessors for temperature field to support negative value Verma, Vishal L
2023-07-31  3:17       ` Jehoon Park
2023-07-31 18:45         ` Verma, Vishal L

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=20230717062908.8292-3-jehoon.park@samsung.com \
    --to=jehoon.park@samsung.com \
    --cc=alison.schofield@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --cc=ira.weiny@intel.com \
    --cc=jonathan.cameron@huawei.com \
    --cc=junhyeok.im@samsung.com \
    --cc=ks0204.kim@samsung.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox