From 3a775cffb8b8dbde0dc206f9c6291fd8d4bf7d0a Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 1 Jun 2025 11:18:58 +0900 Subject: [PATCH 1/2] mi: add arbitration feature get function The set feature is prohibited for the management endpoint support. Signed-off-by: Tokunori Ikegami --- src/libnvme.map | 2 ++ src/nvme/mi.c | 25 +++++++++++++++++++++++++ src/nvme/mi.h | 12 ++++++++++++ 3 files changed, 39 insertions(+) diff --git a/src/libnvme.map b/src/libnvme.map index bae5962ce..44e5c49f8 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -1,5 +1,7 @@ # SPDX-License-Identifier: LGPL-2.1-or-later LIBNVME_UNRELEASED { + global: + nvme_mi_admin_get_features_arbitration; }; LIBNVME_1_14 { diff --git a/src/nvme/mi.c b/src/nvme/mi.c index 855b6d81c..396b72f27 100644 --- a/src/nvme/mi.c +++ b/src/nvme/mi.c @@ -1398,6 +1398,31 @@ int nvme_mi_admin_get_features(nvme_mi_ctrl_t ctrl, return 0; } +static int __nvme_mi_admin_get_features(nvme_mi_ctrl_t ctrl, enum nvme_features_id fid, + enum nvme_get_features_sel sel, __u32 *result) +{ + struct nvme_get_features_args args = { + .args_size = sizeof(args), + .fid = fid, + .nsid = NVME_NSID_NONE, + .sel = sel, + .cdw11 = 0, + .uuidx = NVME_UUID_NONE, + .data_len = 0, + .data = NULL, + .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, + .result = result, + }; + + return nvme_mi_admin_get_features(ctrl, &args); +} + +int nvme_mi_admin_get_features_arbitration(nvme_mi_ctrl_t ctrl, enum nvme_get_features_sel sel, + __u32 *result) +{ + return __nvme_mi_admin_get_features(ctrl, NVME_FEAT_FID_ARBITRATION, sel, result); +} + int nvme_mi_admin_set_features(nvme_mi_ctrl_t ctrl, struct nvme_set_features_args *args) { diff --git a/src/nvme/mi.h b/src/nvme/mi.h index ac75ec4cc..c4179e846 100644 --- a/src/nvme/mi.h +++ b/src/nvme/mi.h @@ -3137,6 +3137,18 @@ int nvme_mi_admin_security_recv(nvme_mi_ctrl_t ctrl, int nvme_mi_admin_get_features(nvme_mi_ctrl_t ctrl, struct nvme_get_features_args *args); +/** + * nvme_mi_admin_get_features_arbitration() - Get arbitration feature + * @ctrl: Controller to send command to + * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @result: The feature data is returned in this argument + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +int nvme_mi_admin_get_features_arbitration(nvme_mi_ctrl_t ctrl, enum nvme_get_features_sel sel, + __u32 *result); + /** * nvme_mi_admin_get_features_data() - Helper function for &nvme_mi_admin_get_features() * @ctrl: Controller to send command to From c05d9486cd0c278e277a6962f7328697e14762c3 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 1 Jun 2025 20:27:14 +0900 Subject: [PATCH 2/2] mi: add power management feature functions The feature is optional for the management endpoint support. Signed-off-by: Tokunori Ikegami --- src/libnvme.map | 2 ++ src/nvme/mi.c | 33 +++++++++++++++++++++++++++++++++ src/nvme/mi.h | 26 ++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/src/libnvme.map b/src/libnvme.map index 44e5c49f8..d1229ba98 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -2,6 +2,8 @@ LIBNVME_UNRELEASED { global: nvme_mi_admin_get_features_arbitration; + nvme_mi_admin_get_features_power_mgmt; + nvme_mi_admin_set_features_power_mgmt; }; LIBNVME_1_14 { diff --git a/src/nvme/mi.c b/src/nvme/mi.c index 396b72f27..db6e362d0 100644 --- a/src/nvme/mi.c +++ b/src/nvme/mi.c @@ -1423,6 +1423,12 @@ int nvme_mi_admin_get_features_arbitration(nvme_mi_ctrl_t ctrl, enum nvme_get_fe return __nvme_mi_admin_get_features(ctrl, NVME_FEAT_FID_ARBITRATION, sel, result); } +int nvme_mi_admin_get_features_power_mgmt(nvme_mi_ctrl_t ctrl, enum nvme_get_features_sel sel, + __u32 *result) +{ + return __nvme_mi_admin_get_features(ctrl, NVME_FEAT_FID_POWER_MGMT, sel, result); +} + int nvme_mi_admin_set_features(nvme_mi_ctrl_t ctrl, struct nvme_set_features_args *args) { @@ -1467,6 +1473,33 @@ int nvme_mi_admin_set_features(nvme_mi_ctrl_t ctrl, return 0; } +static int __nvme_mi_admin_set_features(nvme_mi_ctrl_t ctrl, __u8 fid, __u32 cdw11, bool save, + __u32 *result) +{ + struct nvme_set_features_args args = { + .args_size = sizeof(args), + .nsid = NVME_NSID_NONE, + .cdw11 = cdw11, + .cdw12 = 0, + .save = save, + .uuidx = NVME_UUID_NONE, + .cdw15 = 0, + .data_len = 0, + .data = NULL, + .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, + .result = result, + }; + return nvme_mi_admin_set_features(ctrl, &args); +} + +int nvme_mi_admin_set_features_power_mgmt(nvme_mi_ctrl_t ctrl, __u8 ps, __u8 wh, bool save, + __u32 *result) +{ + __u32 value = NVME_SET(ps, FEAT_PWRMGMT_PS) | NVME_SET(wh, FEAT_PWRMGMT_WH); + + return __nvme_mi_admin_set_features(ctrl, NVME_FEAT_FID_POWER_MGMT, value, save, result); +} + int nvme_mi_admin_ns_mgmt(nvme_mi_ctrl_t ctrl, struct nvme_ns_mgmt_args *args) { diff --git a/src/nvme/mi.h b/src/nvme/mi.h index c4179e846..52190636d 100644 --- a/src/nvme/mi.h +++ b/src/nvme/mi.h @@ -3149,6 +3149,18 @@ int nvme_mi_admin_get_features(nvme_mi_ctrl_t ctrl, int nvme_mi_admin_get_features_arbitration(nvme_mi_ctrl_t ctrl, enum nvme_get_features_sel sel, __u32 *result); +/** + * nvme_mi_admin_get_features_power_mgmt() - Get power management feature + * @ctrl: Controller to send command to + * @sel: Select which type of attribute to return, see &enum nvme_get_features_sel + * @result: The feature data is returned in this argument + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +int nvme_mi_admin_get_features_power_mgmt(nvme_mi_ctrl_t ctrl, enum nvme_get_features_sel sel, + __u32 *result); + /** * nvme_mi_admin_get_features_data() - Helper function for &nvme_mi_admin_get_features() * @ctrl: Controller to send command to @@ -3220,6 +3232,20 @@ static inline int nvme_mi_admin_get_features_simple(nvme_mi_ctrl_t ctrl, int nvme_mi_admin_set_features(nvme_mi_ctrl_t ctrl, struct nvme_set_features_args *args); +/** + * nvme_mi_admin_set_features_power_mgmt() - Set power management feature + * @ctrl: Controller to send command to + * @ps: Power State + * @wh: Workload Hint + * @save: Save value across power states + * @result: The feature data is returned in this argument + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +int nvme_mi_admin_set_features_power_mgmt(nvme_mi_ctrl_t ctrl, __u8 ps, __u8 wh, bool save, + __u32 *result); + /** * nvme_mi_admin_ns_mgmt - Issue a Namespace Management command * @ctrl: Controller to send command to