From 87a6257b5048cc06637a9c600b39ccb5ef2a3b50 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Fri, 2 May 2025 23:54:50 +0900 Subject: [PATCH 1/2] types: add temperature threshold feature TMPTHH field The field supported by NVMe revision 2.1. Signed-off-by: Tokunori Ikegami --- src/libnvme.map | 1 + src/nvme/ioctl.c | 13 +++++++++++++ src/nvme/ioctl.h | 17 +++++++++++++++++ src/nvme/types.h | 4 ++++ src/nvme/util.h | 5 ++++- 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/libnvme.map b/src/libnvme.map index 2bfa82517..a6fc02dfb 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -1,6 +1,7 @@ # SPDX-License-Identifier: LGPL-2.1-or-later LIBNVME_UNRELEASED { global: + nvme_set_features_temp_thresh2; nvme_subsystem_get_serial; }; diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 2417863d3..a634a8b28 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -722,6 +722,19 @@ int nvme_set_features_temp_thresh(int fd, __u16 tmpth, __u8 tmpsel, result); } +int nvme_set_features_temp_thresh2(int fd, __u16 tmpth, __u8 tmpsel, + enum nvme_feat_tmpthresh_thsel thsel, __u8 tmpthh, + bool save, __u32 *result) +{ + __u32 value = NVME_SET(tmpth, FEAT_TT_TMPTH) | + NVME_SET(tmpsel, FEAT_TT_TMPSEL) | + NVME_SET(thsel, FEAT_TT_THSEL) | + NVME_SET(tmpthh, FEAT_TT_TMPTHH); + + return __nvme_set_features(fd, NVME_FEAT_FID_TEMP_THRESH, value, save, + result); +} + int nvme_set_features_err_recovery(int fd, __u32 nsid, __u16 tler, bool dulbe, bool save, __u32 *result) { diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index f0e9636eb..d8ba877ab 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -2721,6 +2721,23 @@ int nvme_set_features_temp_thresh(int fd, __u16 tmpth, __u8 tmpsel, enum nvme_feat_tmpthresh_thsel thsel, bool save, __u32 *result); +/** + * nvme_set_features_temp_thresh2() - Set temperature threshold feature + * @fd: File descriptor of nvme device + * @tmpth: Temperature Threshold + * @tmpsel: Threshold Temperature Select + * @thsel: Threshold Type Select + * @tmpthh: Temperature Threshold Hysteresis + * @save: Save value across power states + * @result: The command completion result from CQE dword0 + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +int nvme_set_features_temp_thresh2(int fd, __u16 tmpth, __u8 tmpsel, + enum nvme_feat_tmpthresh_thsel thsel, __u8 tmpthh, + bool save, __u32 *result); + /** * nvme_set_features_err_recovery() - Set error recovery feature * @fd: File descriptor of nvme device diff --git a/src/nvme/types.h b/src/nvme/types.h index 74db346bb..fafbb7e88 100644 --- a/src/nvme/types.h +++ b/src/nvme/types.h @@ -8796,6 +8796,8 @@ enum nvme_features_id { * @NVME_FEAT_TT_TMPSEL_MASK: * @NVME_FEAT_TT_THSEL_SHIFT: * @NVME_FEAT_TT_THSEL_MASK: + * @NVME_FEAT_TT_TMPTHH_SHIFT: + * @NVME_FEAT_TT_TMPTHH_MASK: * @NVME_FEAT_ERROR_RECOVERY_TLER_SHIFT: * @NVME_FEAT_ERROR_RECOVERY_TLER_MASK: * @NVME_FEAT_ERROR_RECOVERY_DULBE_SHIFT: @@ -8940,6 +8942,8 @@ enum nvme_feat { NVME_FEAT_TT_TMPSEL_MASK = 0xf, NVME_FEAT_TT_THSEL_SHIFT = 20, NVME_FEAT_TT_THSEL_MASK = 0x3, + NVME_FEAT_TT_TMPTHH_SHIFT = 22, + NVME_FEAT_TT_TMPTHH_MASK = 0x7, NVME_FEAT_ERROR_RECOVERY_TLER_SHIFT = 0, NVME_FEAT_ERROR_RECOVERY_TLER_MASK = 0xffff, NVME_FEAT_ERROR_RECOVERY_DULBE_SHIFT = 16, diff --git a/src/nvme/util.h b/src/nvme/util.h index 1b0c4c5ff..4c97652df 100644 --- a/src/nvme/util.h +++ b/src/nvme/util.h @@ -263,13 +263,16 @@ static inline void nvme_feature_decode_lba_range(__u32 value, __u8 *num) #define NVME_FEAT_TT_TMPTH(v) NVME_GET(v, FEAT_TT_TMPTH) #define NVME_FEAT_TT_TMPSEL(v) NVME_GET(v, FEAT_TT_TMPSEL) #define NVME_FEAT_TT_THSEL(v) NVME_GET(v, FEAT_TT_THSEL) +#define NVME_FEAT_TT_TMPTHH(v) NVME_GET(v, FEAT_TT_TMPTHH) static inline void nvme_feature_decode_temp_threshold(__u32 value, __u16 *tmpth, - __u8 *tmpsel, __u8 *thsel) + __u8 *tmpsel, __u8 *thsel, + __u8 *tmpthh) { *tmpth = NVME_FEAT_TT_TMPTH(value); *tmpsel = NVME_FEAT_TT_TMPSEL(value); *thsel = NVME_FEAT_TT_THSEL(value); + *tmpthh = NVME_FEAT_TT_TMPTHH(value); } #define NVME_FEAT_ER_TLER(v) NVME_GET(v, FEAT_ERROR_RECOVERY_TLER) From cad1f2b00fc848d4eb02aa473f5dcc51f3164993 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sat, 3 May 2025 02:13:24 +0900 Subject: [PATCH 2/2] ioctl: add temperature threshold TMPSEL and THSEL parameters to get Those required to get the feature temperature values. Signed-off-by: Tokunori Ikegami --- src/libnvme.map | 1 + src/nvme/ioctl.c | 20 ++++++++++++++++++++ src/nvme/ioctl.h | 14 ++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/src/libnvme.map b/src/libnvme.map index a6fc02dfb..768f240f8 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -1,6 +1,7 @@ # SPDX-License-Identifier: LGPL-2.1-or-later LIBNVME_UNRELEASED { global: + nvme_get_features_temp_thresh2; nvme_set_features_temp_thresh2; nvme_subsystem_get_serial; }; diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index a634a8b28..4e362c95d 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1091,6 +1091,26 @@ int nvme_get_features_temp_thresh(int fd, enum nvme_get_features_sel sel, return __nvme_get_features(fd, NVME_FEAT_FID_TEMP_THRESH, sel, result); } +int nvme_get_features_temp_thresh2(int fd, enum nvme_get_features_sel sel, __u8 tmpsel, + enum nvme_feat_tmpthresh_thsel thsel, __u32 *result) +{ + struct nvme_get_features_args args = { + .args_size = sizeof(args), + .fd = fd, + .fid = NVME_FEAT_FID_TEMP_THRESH, + .nsid = NVME_NSID_NONE, + .sel = sel, + .cdw11 = NVME_SET(tmpsel, FEAT_TT_TMPSEL) | NVME_SET(thsel, FEAT_TT_THSEL), + .uuidx = NVME_UUID_NONE, + .data_len = 0, + .data = NULL, + .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, + .result = result, + }; + + return nvme_get_features(&args); +} + int nvme_get_features_err_recovery(int fd, enum nvme_get_features_sel sel, __u32 *result) { diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index d8ba877ab..fd3dd3985 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -3225,6 +3225,20 @@ int nvme_get_features_lba_range2(int fd, enum nvme_get_features_sel sel, int nvme_get_features_temp_thresh(int fd, enum nvme_get_features_sel sel, __u32 *result); +/** + * nvme_get_features_temp_thresh2() - Get temperature threshold feature + * @fd: File descriptor of nvme device + * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @tmpsel: Threshold Temperature Select + * @thsel: Threshold Type Select + * @result: The command completion result from CQE dword0 + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +int nvme_get_features_temp_thresh2(int fd, enum nvme_get_features_sel sel, __u8 tmpsel, + enum nvme_feat_tmpthresh_thsel thsel, __u32 *result); + /** * nvme_get_features_err_recovery() - Get error recovery feature *