From patchwork Tue Jul 11 07:10:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jehoon Park X-Patchwork-Id: 13308191 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) (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 BEC77171BB for ; Tue, 11 Jul 2023 07:14:09 +0000 (UTC) Received: from epcas2p2.samsung.com (unknown [182.195.41.54]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20230711070812epoutp0120660e1e4301ec23efc2cb4c33092146~wvnpFb53I1546315463epoutp01Q for ; Tue, 11 Jul 2023 07:08:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20230711070812epoutp0120660e1e4301ec23efc2cb4c33092146~wvnpFb53I1546315463epoutp01Q DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1689059292; bh=hWWV/CYz9PEFgUzb2vw2IElLf62KvNvLaJjeuRHOgIc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ERYs2aGvSdh7qulv7rV4OT+pf4J+jNLIq2UMOSUGl4WG92tkC7lH0u3D64yxgHWoZ u/uKfNgVSYF2+SaRcSuF4WUHD0n0akeFNJtDfoA5H5iwjzGvjDsGr37Xqu0x5m2/OZ rGmPuwBs/BpR1CaLAYFNUpt+K49S3SiY+EZLvcuo= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas2p3.samsung.com (KnoxPortal) with ESMTP id 20230711070812epcas2p3d765feeb1bdfd5947fd2c4de4412f130~wvnokpyUf2574425744epcas2p37; Tue, 11 Jul 2023 07:08:12 +0000 (GMT) Received: from epsmges2p2.samsung.com (unknown [182.195.36.99]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4R0X5N4Y4jz4x9Q1; Tue, 11 Jul 2023 07:08:08 +0000 (GMT) Received: from epcas2p2.samsung.com ( [182.195.41.54]) by epsmges2p2.samsung.com (Symantec Messaging Gateway) with SMTP id 94.F8.40133.8DFFCA46; Tue, 11 Jul 2023 16:08:08 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas2p3.samsung.com (KnoxPortal) with ESMTPA id 20230711070808epcas2p327adc8a7b29b653af17244d49eb38318~wvnk4mryt2804428044epcas2p3g; Tue, 11 Jul 2023 07:08:08 +0000 (GMT) Received: from epsmgms1p2new.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230711070808epsmtrp1cb14709a3f3fd3530a0a6b7bf23edd70~wvnk2KJxz2535025350epsmtrp16; Tue, 11 Jul 2023 07:08:08 +0000 (GMT) X-AuditID: b6c32a46-4edb870000009cc5-ea-64acffd8cb9e Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2new.samsung.com (Symantec Messaging Gateway) with SMTP id D9.D3.30535.7DFFCA46; Tue, 11 Jul 2023 16:08:07 +0900 (KST) Received: from jehoon-Precision-7920-Tower.dsn.sec.samsung.com (unknown [10.229.83.133]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230711070807epsmtip10e7e1fac12adad48df1945062f854d44~wvnknuVDU1618416184epsmtip12; Tue, 11 Jul 2023 07:08:07 +0000 (GMT) From: Jehoon Park To: linux-cxl@vger.kernel.org Cc: nvdimm@lists.linux.dev, Alison Schofield , Vishal Verma , Ira Weiny , Ben Widawsky , Dan Williams , Dave Jiang , Kyungsan Kim , Junhyeok Im , Jehoon Park Subject: [ndctl PATCH 1/2] libcxl: add support for Set Alert Configuration mailbox command Date: Tue, 11 Jul 2023 16:10:18 +0900 Message-Id: <20230711071019.7151-2-jehoon.park@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230711071019.7151-1-jehoon.park@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrHKsWR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Qi7moOBEA7QGPyr0CAAA= X-CMS-MailID: 20230711070808epcas2p327adc8a7b29b653af17244d49eb38318 X-Msg-Generator: CA X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230711070808epcas2p327adc8a7b29b653af17244d49eb38318 References: <20230711071019.7151-1-jehoon.park@samsung.com> Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: CXL 3.0 Spec 8.2.9.8.3.3 defines Set Alert Configuration mailbox command which allows a CXL host to configure programmable warning thresholds optionally. Add methods to issue the command and set fields. Signed-off-by: Jehoon Park --- Documentation/cxl/lib/libcxl.txt | 1 + cxl/lib/libcxl.c | 21 +++++++++++++++++++++ cxl/lib/libcxl.sym | 12 ++++++++++++ cxl/lib/private.h | 12 ++++++++++++ cxl/libcxl.h | 16 ++++++++++++++++ 5 files changed, 62 insertions(+) diff --git a/Documentation/cxl/lib/libcxl.txt b/Documentation/cxl/lib/libcxl.txt index 31bc855..bcb8928 100644 --- a/Documentation/cxl/lib/libcxl.txt +++ b/Documentation/cxl/lib/libcxl.txt @@ -122,6 +122,7 @@ struct cxl_cmd *cxl_cmd_new_raw(struct cxl_memdev *memdev, int opcode); struct cxl_cmd *cxl_cmd_new_identify(struct cxl_memdev *memdev); struct cxl_cmd *cxl_cmd_new_get_health_info(struct cxl_memdev *memdev); struct cxl_cmd *cxl_cmd_new_get_alert_config(struct cxl_memdev *memdev); +struct cxl_cmd *cxl_cmd_new_set_alert_config(struct cxl_memdev *memdev); struct cxl_cmd *cxl_cmd_new_read_label(struct cxl_memdev *memdev, unsigned int offset, unsigned int length); struct cxl_cmd *cxl_cmd_new_write_label(struct cxl_memdev *memdev, void *buf, diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c index 769cd8a..a70b064 100644 --- a/cxl/lib/libcxl.c +++ b/cxl/lib/libcxl.c @@ -4166,3 +4166,24 @@ CXL_EXPORT int cxl_memdev_read_label(struct cxl_memdev *memdev, void *buf, { return lsa_op(memdev, LSA_OP_GET, buf, length, offset); } + +#define cxl_alert_config_set_field(field) \ +CXL_EXPORT int cxl_cmd_alert_config_set_##field(struct cxl_cmd *cmd, int val) \ +{ \ + struct cxl_cmd_set_alert_config *setalert = cmd->input_payload; \ + setalert->field = val; \ + return 0; \ +} + +cxl_alert_config_set_field(life_used_prog_warn_threshold) +cxl_alert_config_set_field(dev_over_temperature_prog_warn_threshold) +cxl_alert_config_set_field(dev_under_temperature_prog_warn_threshold) +cxl_alert_config_set_field(corrected_volatile_mem_err_prog_warn_threshold) +cxl_alert_config_set_field(corrected_pmem_err_prog_warn_threshold) +cxl_alert_config_set_field(valid_alert_actions) +cxl_alert_config_set_field(enable_alert_actions) + +CXL_EXPORT struct cxl_cmd *cxl_cmd_new_set_alert_config(struct cxl_memdev *memdev) +{ + return cxl_cmd_new_generic(memdev, CXL_MEM_COMMAND_ID_SET_ALERT_CONFIG); +} diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym index c6545c7..334f01f 100644 --- a/cxl/lib/libcxl.sym +++ b/cxl/lib/libcxl.sym @@ -250,3 +250,15 @@ global: cxl_region_get_daxctl_region; cxl_port_get_parent_dport; } LIBCXL_4; + +LIBCXL_6 { +global: + cxl_cmd_alert_config_set_life_used_prog_warn_threshold; + cxl_cmd_alert_config_set_dev_over_temperature_prog_warn_threshold; + cxl_cmd_alert_config_set_dev_under_temperature_prog_warn_threshold; + cxl_cmd_alert_config_set_corrected_volatile_mem_err_prog_warn_threshold; + cxl_cmd_alert_config_set_corrected_pmem_err_prog_warn_threshold; + cxl_cmd_alert_config_set_valid_alert_actions; + cxl_cmd_alert_config_set_enable_alert_actions; + cxl_cmd_new_set_alert_config; +} LIBCXL_5; diff --git a/cxl/lib/private.h b/cxl/lib/private.h index d49b560..43bf1d7 100644 --- a/cxl/lib/private.h +++ b/cxl/lib/private.h @@ -273,6 +273,18 @@ struct cxl_cmd_get_alert_config { #define CXL_CMD_ALERT_CONFIG_PROG_ALERTS_CORRECTED_PMEM_ERR_PROG_WARN_THRESHOLD_MASK \ BIT(4) +/* CXL 3.0 8.2.9.8.3.3 Set Alert Configuration */ +struct cxl_cmd_set_alert_config { + u8 valid_alert_actions; + u8 enable_alert_actions; + u8 life_used_prog_warn_threshold; + u8 rsvd; + le16 dev_over_temperature_prog_warn_threshold; + le16 dev_under_temperature_prog_warn_threshold; + le16 corrected_volatile_mem_err_prog_warn_threshold; + le16 corrected_pmem_err_prog_warn_threshold; +} __attribute__((packed)); + struct cxl_cmd_get_partition { le64 active_volatile; le64 active_persistent; diff --git a/cxl/libcxl.h b/cxl/libcxl.h index 0218d73..c981683 100644 --- a/cxl/libcxl.h +++ b/cxl/libcxl.h @@ -425,6 +425,22 @@ enum cxl_setpartition_mode { int cxl_cmd_partition_set_mode(struct cxl_cmd *cmd, enum cxl_setpartition_mode mode); +int cxl_cmd_alert_config_set_life_used_prog_warn_threshold(struct cxl_cmd *cmd, + int threshold); +int cxl_cmd_alert_config_set_dev_over_temperature_prog_warn_threshold( + struct cxl_cmd *cmd, int threshold); +int cxl_cmd_alert_config_set_dev_under_temperature_prog_warn_threshold( + struct cxl_cmd *cmd, int threshold); +int cxl_cmd_alert_config_set_corrected_volatile_mem_err_prog_warn_threshold( + struct cxl_cmd *cmd, int threshold); +int cxl_cmd_alert_config_set_corrected_pmem_err_prog_warn_threshold( + struct cxl_cmd *cmd, int threshold); +int cxl_cmd_alert_config_set_valid_alert_actions(struct cxl_cmd *cmd, + int action); +int cxl_cmd_alert_config_set_enable_alert_actions(struct cxl_cmd *cmd, + int enable); +struct cxl_cmd *cxl_cmd_new_set_alert_config(struct cxl_memdev *memdev); + #ifdef __cplusplus } /* extern "C" */ #endif From patchwork Tue Jul 11 07:10:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jehoon Park X-Patchwork-Id: 13308192 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) (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 91215171BB for ; Tue, 11 Jul 2023 07:15:47 +0000 (UTC) Received: from epcas2p3.samsung.com (unknown [182.195.41.55]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20230711070822epoutp03b8d954537421303a6939ebe3398ac966~wvnx07UJC0509105091epoutp03M for ; Tue, 11 Jul 2023 07:08:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20230711070822epoutp03b8d954537421303a6939ebe3398ac966~wvnx07UJC0509105091epoutp03M DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1689059302; bh=PeznLp+QChb8GZyUlzCUDTlSHKy7b9Tl1ojTFn1Xi+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a2ATooyp/VikA/1U0ChUCXu//6aSfaWvW6YDo9s9p3yonJvqZZR4h97tEBXicaBSI SEMiBU/tXhVdyHyJuSV7k5mhJx0pUbTD+ZHtx0Q/rBL8canB6lzNHUAeEwvTSzn1/U onoegTy9ikF4JkN9/Co5zqIk29KjYMONgATL56Eg= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas2p1.samsung.com (KnoxPortal) with ESMTP id 20230711070821epcas2p1a80b602222eb41debd894f4d59e1728f~wvnxUG74O0398103981epcas2p1Y; Tue, 11 Jul 2023 07:08:21 +0000 (GMT) Received: from epsmges2p2.samsung.com (unknown [182.195.36.101]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4R0X5c5qBPz4x9Q5; Tue, 11 Jul 2023 07:08:20 +0000 (GMT) Received: from epcas2p3.samsung.com ( [182.195.41.55]) by epsmges2p2.samsung.com (Symantec Messaging Gateway) with SMTP id BE.09.40133.4EFFCA46; Tue, 11 Jul 2023 16:08:20 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas2p4.samsung.com (KnoxPortal) with ESMTPA id 20230711070820epcas2p4ec4884b434c9cb748d5ebda4dd385955~wvnwUOcAa3251032510epcas2p44; Tue, 11 Jul 2023 07:08:20 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230711070820epsmtrp2b886fb7a724153bf191883d1e81a38d0~wvnwTMt8x1113611136epsmtrp2X; Tue, 11 Jul 2023 07:08:20 +0000 (GMT) X-AuditID: b6c32a46-4edb870000009cc5-23-64acffe42e36 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 20.63.34491.4EFFCA46; Tue, 11 Jul 2023 16:08:20 +0900 (KST) Received: from jehoon-Precision-7920-Tower.dsn.sec.samsung.com (unknown [10.229.83.133]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230711070820epsmtip1ce4740f21a573ec6415b11f1a3dce6ff~wvnwBkeoc1608916089epsmtip1r; Tue, 11 Jul 2023 07:08:20 +0000 (GMT) From: Jehoon Park To: linux-cxl@vger.kernel.org Cc: nvdimm@lists.linux.dev, Alison Schofield , Vishal Verma , Ira Weiny , Ben Widawsky , Dan Williams , Dave Jiang , Kyungsan Kim , Junhyeok Im , Jehoon Park Subject: [ndctl PATCH 2/2] cxl: add 'set-alert-config' command to cxl tool Date: Tue, 11 Jul 2023 16:10:19 +0900 Message-Id: <20230711071019.7151-3-jehoon.park@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230711071019.7151-1-jehoon.park@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrLKsWRmVeSWpSXmKPExsWy7bCmue6T/2tSDBY06ljcfXyBzaJ58mJG i+lTLzBanLjZyGax/+lzFosDrxvYLRYfncFscXQPh8X5WadYLFb++MNqcWvCMSYHbo/Fe14y eWxa1cnm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nDC9+Ghb/6nGyoA2JZbijERDLeai4kQAxVTU1wAEAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrJLMWRmVeSWpSXmKPExsWy7bCSnO6T/2tSDJqn81jcfXyBzaJ58mJG i+lTLzBanLjZyGax/+lzFosDrxvYLRYfncFscXQPh8X5WadYLFb++MNqcWvCMSYHbo/Fe14y eWxa1cnm8WLzTEaPvi2rGD0+b5ILYI3isklJzcksSy3St0vgyug+xlLwooWx4s2aVuYGxtlx XYycHBICJhIHd21k6mLk4hAS2M0osXBlGwtEQlriXvMVdghbWOJ+yxFWEFtIoJtJ4sA8TxCb TUBb4v72DWwgtoiArETzugdgg5gFupglDu7/DZTg4BAW8JI41+AIUsMioCqxdu4CJhCbV8Ba 4uOyR1Dz5SVWbzjADGJzCthIPJmzjAVil7XElRMXWCYw8i1gZFjFKJlaUJybnltsWGCYl1qu V5yYW1yal66XnJ+7iREcmlqaOxi3r/qgd4iRiYPxEKMEB7OSCG/BwVUpQrwpiZVVqUX58UWl OanFhxilOViUxHnFX/SmCAmkJ5akZqemFqQWwWSZODilGpjiG0+vn7bsnJCVwtYLzQn5WkKn nvPzXxXwmeQzU/sj9xLuLat/7rm9w1L0VPzzW+3banec+ehV8yZ+Eusj5agIHdlpFRnLn3Xy btIvXF909+l7661Xj71d92taSNybHRa/Gf52v/WbIXbQ1HfN7EedrQ7h+7h26M5/ffbz7Z6k CRu23cq+tOHqvtndMxbMUmm9FHDrood5sIXC308HDu6X+HYr1vuFhnJgutxmRSkhf9uPvUsb nkjoBirOW3dEJUJjXcZ0gcdMDo8586TcF0qtWr5e4ISN04sJ7hyst71sHoWnd3gyu6X4zXso a5WZvH3Lp6ful09XmdTO3TKjPajY/0r/Go1vM131Hi47I85opMRSnJFoqMVcVJwIAIN3CuK8 AgAA X-CMS-MailID: 20230711070820epcas2p4ec4884b434c9cb748d5ebda4dd385955 X-Msg-Generator: CA X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230711070820epcas2p4ec4884b434c9cb748d5ebda4dd385955 References: <20230711071019.7151-1-jehoon.park@samsung.com> Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Add a new command: 'set-alert-config', which configures device's warning alert usage: cxl set-alert-config [..] [] -v, --verbose turn on debug -S, --serial use serial numbers to id memdevs -L, --life-used-threshold threshold value for life used warning alert --life-used-alert <'on' or 'off'> enable or disable life used warning alert -O, --over-temperature-threshold threshold value for device over temperature warning alert --over-temperature-alert <'on' or 'off'> enable or disable device over temperature warning alert -U, --under-temperature-threshold threshold value for device under temperature warning alert --under-temperature-alert <'on' or 'off'> enable or disable device under temperature warning alert -V, --volatile-mem-err-threshold threshold value for corrected volatile mem error warning alert --volatile-mem-err-alert <'on' or 'off'> enable or disable corrected volatile mem error warning alert -P, --pmem-err-threshold threshold value for corrected pmem error warning alert --pmem-err-alert <'on' or 'off'> enable or disable corrected pmem error warning alert Signed-off-by: Jehoon Park --- Documentation/cxl/cxl-set-alert-config.txt | 96 +++++++++ Documentation/cxl/meson.build | 1 + cxl/builtin.h | 1 + cxl/cxl.c | 1 + cxl/memdev.c | 219 ++++++++++++++++++++- 5 files changed, 317 insertions(+), 1 deletion(-) create mode 100644 Documentation/cxl/cxl-set-alert-config.txt diff --git a/Documentation/cxl/cxl-set-alert-config.txt b/Documentation/cxl/cxl-set-alert-config.txt new file mode 100644 index 0000000..a291c09 --- /dev/null +++ b/Documentation/cxl/cxl-set-alert-config.txt @@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-2.0 + +cxl-set-alert-config(1) +======================= + +NAME +---- +cxl-set-alert-config - set the warning alert threshold on a CXL memdev + +SYNOPSIS +-------- +[verse] +'cxl set-alert-config [..] []' + +DESCRIPTION +----------- +CXL device raises an alert when its health status is changed. Critical alert +shall automatically be configured by the device after a device reset. +If supported, programmable warning thresholds also be initialized to vendor +recommended defaults, then could be configured by the host. + +Use this command to configure warning alert thresholds of a device. +Having issued this command, the newly requested warning thresholds would +override the previously programmed warning thresholds. + +To enable warning alert, set both 'threshold=value' and 'alert=on'. To disable +warning alert, set only 'alert=off'. Other cases would cause errors. + +Use "cxl list -m -A" to examine the programming warning threshold +capabilities of a device. + +EXAMPLES +-------- +Set warning threshold to 30 and enable alert for life used. +[verse] +cxl set-alert-config mem0 -L 30 --life-used-alert=on + +Disable warning alert for device over temperature. +[verse] +cxl set-alert-config mem0 --over-temperature-alert=off + +OPTIONS +------- +:: +include::memdev-option.txt[] + +-v:: +--verbose=:: + Turn on verbose debug messages in the library (if libcxl was built with + logging and debug enabled). + +-L:: +--life-used-threshold=:: + Set for the life used warning alert threshold. + +--life-used-alert=:: + Enable or disable the life used warning alert. + Options are 'on' or 'off'. + +-O:: +--over-temperature-threshold=:: + Set for the device over temperature warning alert threshold. + +--over-temperature-alert=:: + Enable or disable the device over temperature warning alert. + Options are 'on' or 'off'. + +-U:: +--under-temperature-threshold=:: + Set for the device under temperature warning alert threshold. + +--under-temperature-alert=:: + Enable or disable the device under temperature warning alert. + Options are 'on' or 'off'. + +-V:: +--volatile-mem-err-threshold=:: + Set for the corrected volatile memory error warning alert + threshold. + +--volatile-mem-err-alert=:: + Enable or disable the corrected volatile memory error warning alert. + Options are 'on' or 'off'. + +-P:: +--pmem-err-threshold=:: + Set for the corrected persistent memory error warning alert + threshold. + +--pmem-err-alert=:: + Enable or disable the corrected persistent memory error warning alert. + Options are 'on' or 'off'. + +SEE ALSO +-------- +CXL-3.0 8.2.9.8.3.3 diff --git a/Documentation/cxl/meson.build b/Documentation/cxl/meson.build index a6d77ab..3ea412d 100644 --- a/Documentation/cxl/meson.build +++ b/Documentation/cxl/meson.build @@ -46,6 +46,7 @@ cxl_manpages = [ 'cxl-enable-region.txt', 'cxl-destroy-region.txt', 'cxl-monitor.txt', + 'cxl-set-alert-config.txt', ] foreach man : cxl_manpages diff --git a/cxl/builtin.h b/cxl/builtin.h index 9baa43b..7b2274c 100644 --- a/cxl/builtin.h +++ b/cxl/builtin.h @@ -32,4 +32,5 @@ static inline int cmd_monitor(int argc, const char **argv, struct cxl_ctx *ctx) return EXIT_FAILURE; } #endif +int cmd_set_alert_config(int argc, const char **argv, struct cxl_ctx *ctx); #endif /* _CXL_BUILTIN_H_ */ diff --git a/cxl/cxl.c b/cxl/cxl.c index 3be7026..15eb1e6 100644 --- a/cxl/cxl.c +++ b/cxl/cxl.c @@ -77,6 +77,7 @@ static struct cmd_struct commands[] = { { "disable-region", .c_fn = cmd_disable_region }, { "destroy-region", .c_fn = cmd_destroy_region }, { "monitor", .c_fn = cmd_monitor }, + { "set-alert-config", .c_fn = cmd_set_alert_config }, }; int main(int argc, const char **argv) diff --git a/cxl/memdev.c b/cxl/memdev.c index 0b3ad02..2587189 100644 --- a/cxl/memdev.c +++ b/cxl/memdev.c @@ -34,10 +34,38 @@ static struct parameters { const char *type; const char *size; const char *decoder_filter; + const char *life_used_threshold; + const char *dev_over_temperature_threshold; + const char *dev_under_temperature_threshold; + const char *corrected_volatile_mem_err_threshold; + const char *corrected_pmem_err_threshold; + const char *life_used_alert; + const char *dev_over_temperature_alert; + const char *dev_under_temperature_alert; + const char *corrected_volatile_mem_err_alert; + const char *corrected_pmem_err_alert; } param; static struct log_ctx ml; +struct alert_context { + int valid_alert_actions; + int enable_alert_actions; + int life_used_threshold; + int dev_over_temperature_threshold; + int dev_under_temperature_threshold; + int corrected_volatile_mem_err_threshold; + int corrected_pmem_err_threshold; +}; + +enum cxl_setalert_event { + CXL_SETALERT_LIFE_USED, + CXL_SETALERT_OVER_TEMP, + CXL_SETALERT_UNDER_TEMP, + CXL_SETALERT_VOLATILE_MEM_ERROR, + CXL_SETALERT_PMEM_ERROR, +}; + enum cxl_setpart_type { CXL_SETPART_PMEM, CXL_SETPART_VOLATILE, @@ -85,6 +113,36 @@ OPT_STRING('t', "type", ¶m.type, "type", \ OPT_BOOLEAN('f', "force", ¶m.force, \ "Attempt 'expected to fail' operations") +#define SET_ALERT_OPTIONS() \ +OPT_STRING('L', "life-used-threshold", ¶m.life_used_threshold, \ + "threshold", "threshold value for life used warning alert"), \ +OPT_STRING('\0', "life-used-alert", ¶m.life_used_alert, \ + "'on' or 'off'", "enable or disable life used warning alert"), \ +OPT_STRING('O', "over-temperature-threshold", \ + ¶m.dev_over_temperature_threshold, "threshold", \ + "threshold value for device over temperature warning alert"), \ +OPT_STRING('\0', "over-temperature-alert", \ + ¶m.dev_over_temperature_alert, "'on' or 'off'", \ + "enable or disable device over temperature warning alert"), \ +OPT_STRING('U', "under-temperature-threshold", \ + ¶m.dev_under_temperature_threshold, "threshold", \ + "threshold value for device under temperature warning alert"), \ +OPT_STRING('\0', "under-temperature-alert", \ + ¶m.dev_under_temperature_alert, "'on' or 'off'", \ + "enable or disable device under temperature warning alert"), \ +OPT_STRING('V', "volatile-mem-err-threshold", \ + ¶m.corrected_volatile_mem_err_threshold, "threshold", \ + "threshold value for corrected volatile mem error warning alert"), \ +OPT_STRING('\0', "volatile-mem-err-alert", \ + ¶m.corrected_volatile_mem_err_alert, "'on' or 'off'", \ + "enable or disable corrected volatile mem error warning alert"), \ +OPT_STRING('P', "pmem-err-threshold", \ + ¶m.corrected_pmem_err_threshold, "threshold", \ + "threshold value for corrected pmem error warning alert"), \ +OPT_STRING('\0', "pmem-err-alert", \ + ¶m.corrected_pmem_err_alert, "'on' or 'off'", \ + "enable or disable corrected pmem error warning alert") + static const struct option read_options[] = { BASE_OPTIONS(), LABEL_OPTIONS(), @@ -135,6 +193,12 @@ static const struct option free_dpa_options[] = { OPT_END(), }; +static const struct option set_alert_options[] = { + BASE_OPTIONS(), + SET_ALERT_OPTIONS(), + OPT_END(), +}; + enum reserve_dpa_mode { DPA_ALLOC, DPA_FREE, @@ -653,6 +717,148 @@ out_err: return rc; } +static int validate_alert_threshold(enum cxl_setalert_event event, + int threshold) +{ + if (event == CXL_SETALERT_LIFE_USED) { + if (threshold < 0 || threshold > 100) { + log_err(&ml, "Invalid life used threshold: %d\n", + threshold); + return -EINVAL; + } + } else if (event == CXL_SETALERT_OVER_TEMP || + event == CXL_SETALERT_UNDER_TEMP) { + if (threshold < SHRT_MIN || threshold > SHRT_MAX) { + log_err(&ml, + "Invalid device temperature threshold: %d\n", + threshold); + return -EINVAL; + } + } else { + if (threshold < 0 || threshold > USHRT_MAX) { + log_err(&ml, + "Invalid corrected mem error threshold: %d\n", + threshold); + return -EINVAL; + } + } + return 0; +} + +#define alert_param_set_threshold(arg, alert_event) \ +{ \ + if (!param.arg##_alert) { \ + if (param.arg##_threshold) { \ + log_err(&ml, "Action not specified\n"); \ + return -EINVAL; \ + } \ + } else if (strncmp(param.arg##_alert, "on", 2) == 0) { \ + if (param.arg##_threshold) { \ + char *endptr; \ + alertctx.arg##_threshold = \ + strtol(param.arg##_threshold, &endptr, 10); \ + if (endptr[0] != '\0') { \ + log_err(&ml, "Invalid threshold: %s\n", \ + param.arg##_threshold); \ + return -EINVAL; \ + } \ + rc = validate_alert_threshold( \ + alert_event, alertctx.arg##_threshold); \ + if (rc != 0) \ + return rc; \ + alertctx.valid_alert_actions |= 1 << alert_event; \ + alertctx.enable_alert_actions |= 1 << alert_event; \ + } else { \ + log_err(&ml, "Threshold not specified\n"); \ + return -EINVAL; \ + } \ + } else if (strncmp(param.arg##_alert, "off", 3) == 0) { \ + if (!param.arg##_threshold) { \ + alertctx.valid_alert_actions |= 1 << alert_event; \ + alertctx.enable_alert_actions &= ~(1 << alert_event); \ + } else { \ + log_err(&ml, "Disable not require threshold\n"); \ + return -EINVAL; \ + } \ + } else { \ + log_err(&ml, "Invalid action: %s\n", param.arg##_alert); \ + return -EINVAL; \ + } \ +} + +#define setup_threshold_field(arg) \ +{ \ + if (param.arg##_threshold) \ + cxl_cmd_alert_config_set_##arg##_prog_warn_threshold( \ + cmd, alertctx.arg##_threshold); \ +} + +static int action_set_alert_config(struct cxl_memdev *memdev, + struct action_context *actx) +{ + const char *devname = cxl_memdev_get_devname(memdev); + struct cxl_cmd *cmd; + struct alert_context alertctx = { 0 }; + struct json_object *jmemdev; + unsigned long flags; + int rc = 0; + + alert_param_set_threshold(life_used, CXL_SETALERT_LIFE_USED) + alert_param_set_threshold(dev_over_temperature, CXL_SETALERT_OVER_TEMP) + alert_param_set_threshold(dev_under_temperature, + CXL_SETALERT_UNDER_TEMP) + alert_param_set_threshold(corrected_volatile_mem_err, + CXL_SETALERT_VOLATILE_MEM_ERROR) + alert_param_set_threshold(corrected_pmem_err, CXL_SETALERT_PMEM_ERROR) + if (alertctx.valid_alert_actions == 0) { + log_err(&ml, "No action specified\n"); + return -EINVAL; + } + + cmd = cxl_cmd_new_set_alert_config(memdev); + if (!cmd) { + rc = -ENXIO; + goto out_err; + } + + setup_threshold_field(life_used) + setup_threshold_field(dev_over_temperature) + setup_threshold_field(dev_under_temperature) + setup_threshold_field(corrected_volatile_mem_err) + setup_threshold_field(corrected_pmem_err) + cxl_cmd_alert_config_set_valid_alert_actions( + cmd, alertctx.valid_alert_actions); + cxl_cmd_alert_config_set_enable_alert_actions( + cmd, alertctx.enable_alert_actions); + + rc = cxl_cmd_submit(cmd); + if (rc < 0) { + log_err(&ml, "cmd submission failed: %s\n", strerror(-rc)); + goto out_cmd; + } + + rc = cxl_cmd_get_mbox_status(cmd); + if (rc != 0) { + log_err(&ml, "%s: mbox status: %d\n", __func__, rc); + rc = -ENXIO; + } + +out_cmd: + cxl_cmd_unref(cmd); +out_err: + if (rc) + log_err(&ml, "%s error: %s\n", devname, strerror(-rc)); + + flags = UTIL_JSON_ALERT_CONFIG; + if (actx->f_out == stdout && isatty(1)) + flags |= UTIL_JSON_HUMAN; + jmemdev = util_cxl_memdev_to_json(memdev, flags); + if (actx->jdevs && jmemdev) + json_object_array_add(actx->jdevs, jmemdev); + + return rc; +} + static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx, int (*action)(struct cxl_memdev *memdev, struct action_context *actx), @@ -696,7 +902,7 @@ static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx, } if (action == action_setpartition || action == action_reserve_dpa || - action == action_free_dpa) + action == action_free_dpa || action == action_set_alert_config) actx.jdevs = json_object_new_array(); if (err == argc) { @@ -893,3 +1099,14 @@ int cmd_free_dpa(int argc, const char **argv, struct cxl_ctx *ctx) return count >= 0 ? 0 : EXIT_FAILURE; } + +int cmd_set_alert_config(int argc, const char **argv, struct cxl_ctx *ctx) +{ + int count = memdev_action( + argc, argv, ctx, action_set_alert_config, set_alert_options, + "cxl set-alert-config [..] []"); + log_info(&ml, "set alert configuration %d mem%s\n", + count >= 0 ? count : 0, count > 1 ? "s" : ""); + + return count >= 0 ? 0 : EXIT_FAILURE; +}