From patchwork Mon Aug 7 06:35:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jehoon Park X-Patchwork-Id: 13343106 X-Patchwork-Delegate: vishal.l.verma@intel.com Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 251BC1C04 for ; Mon, 7 Aug 2023 06:35:42 +0000 (UTC) Received: from epcas2p4.samsung.com (unknown [182.195.41.56]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20230807063540epoutp023d3d9879768affd9e04829dc7a7f893a~5Bl8roipx2951329513epoutp02X for ; Mon, 7 Aug 2023 06:35:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20230807063540epoutp023d3d9879768affd9e04829dc7a7f893a~5Bl8roipx2951329513epoutp02X DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1691390140; bh=UdZyML6B24ScUvSgDKW8/+eMj4Rfa9MYaG249Qxddzo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mk5VdhhOt4CIgy8tUtIB/FsnIPid/id5Wsa81UZPZ1IL0eGPnWsYGHZndAdLxYqlc w6+zKrDH+inE41nsPjAfHJqxfBxYQp/50UX3K2u/V9GbERrxmRaoL70P396KgIT5ec mEhSY8revEcChjc4VaS4LU7vcFsjLALxy3AW1FPk= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas2p3.samsung.com (KnoxPortal) with ESMTP id 20230807063540epcas2p3b86d2b1bcbfb8ffc62d2982b65b7d7ba~5Bl8HD7yV0737307373epcas2p30; Mon, 7 Aug 2023 06:35:40 +0000 (GMT) Received: from epsmges2p4.samsung.com (unknown [182.195.36.91]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4RK65R4S0sz4x9QB; Mon, 7 Aug 2023 06:35:39 +0000 (GMT) Received: from epcas2p4.samsung.com ( [182.195.41.56]) by epsmges2p4.samsung.com (Symantec Messaging Gateway) with SMTP id FE.66.32393.BB090D46; Mon, 7 Aug 2023 15:35:39 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas2p4.samsung.com (KnoxPortal) with ESMTPA id 20230807063538epcas2p4965d5d117b8ef87ac4217bec53beff95~5Bl67FpCa0920509205epcas2p43; Mon, 7 Aug 2023 06:35:38 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230807063538epsmtrp15a4709b12f6903875d791f18d8e1ca6e~5Bl66AjFX2729227292epsmtrp1J; Mon, 7 Aug 2023 06:35:38 +0000 (GMT) X-AuditID: b6c32a48-adffa70000007e89-b1-64d090bb61b8 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id DD.1F.34491.AB090D46; Mon, 7 Aug 2023 15:35:38 +0900 (KST) Received: from jehoon-Precision-7920-Tower.dsn.sec.samsung.com (unknown [10.229.83.133]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230807063538epsmtip228fdd2b9d55344aa2776e77cf46889fd~5Bl6ua8ly1913019130epsmtip2g; Mon, 7 Aug 2023 06:35:38 +0000 (GMT) From: Jehoon Park To: linux-cxl@vger.kernel.org Cc: nvdimm@lists.linux.dev, Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Dave Jiang , Davidlohr Bueso , Jonathan Cameron , Kyungsan Kim , Junhyeok Im , Jehoon Park Subject: [ndctl PATCH v2 2/3] libcxl: Fix accessors for temperature field to support negative value Date: Mon, 7 Aug 2023 15:35:48 +0900 Message-Id: <20230807063549.5942-3-jehoon.park@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230807063549.5942-1-jehoon.park@samsung.com> X-Brightm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/TZLbWJTk33t 0xo9LSLtz88VmTuWH2u1TKrSEDhQxyvqfXi+yEOLvqiCpZt8Y/+zlB3f8V2JpTgj0VCLuag4 EQC+NW3bxQIAAA== X-CMS-MailID: 20230807063538epcas2p4965d5d117b8ef87ac4217bec53beff95 X-Msg-Generator: CA X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230807063538epcas2p4965d5d117b8ef87ac4217bec53beff95 References: <20230807063549.5942-1-jehoon.park@samsung.com> Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Add a new macro function to retrieve a signed value such as a temperature. Modify accessors for signed value to return INT_MAX when error occurs and set errno to corresponding errno codes. Signed-off-by: Jehoon Park --- cxl/lib/libcxl.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c index af4ca44..fc64de1 100644 --- a/cxl/lib/libcxl.c +++ b/cxl/lib/libcxl.c @@ -3661,11 +3661,23 @@ 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) { \ + errno = -rc; \ + return INT_MAX; \ + } \ + 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); } @@ -3673,7 +3685,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); } @@ -3681,7 +3693,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); } @@ -3689,7 +3701,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); } @@ -3905,8 +3917,6 @@ CXL_EXPORT int cxl_cmd_health_info_get_life_used(struct cxl_cmd *cmd) { int rc = health_info_get_life_used_raw(cmd); - if (rc < 0) - return rc; if (rc == CXL_CMD_HEALTH_INFO_LIFE_USED_NOT_IMPL) return -EOPNOTSUPP; return rc; @@ -3914,7 +3924,7 @@ CXL_EXPORT int cxl_cmd_health_info_get_life_used(struct cxl_cmd *cmd) 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); } @@ -3922,10 +3932,10 @@ CXL_EXPORT int cxl_cmd_health_info_get_temperature(struct cxl_cmd *cmd) { int rc = health_info_get_temperature_raw(cmd); - if (rc < 0) - return rc; - if (rc == CXL_CMD_HEALTH_INFO_TEMPERATURE_NOT_IMPL) - return -EOPNOTSUPP; + if (rc == CXL_CMD_HEALTH_INFO_TEMPERATURE_NOT_IMPL) { + errno = EOPNOTSUPP; + return INT_MAX; + } return rc; }