diff --git a/src/libnvme.map b/src/libnvme.map index bae5962ce..d1229ba98 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -1,5 +1,9 @@ # SPDX-License-Identifier: LGPL-2.1-or-later 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 855b6d81c..db6e362d0 100644 --- a/src/nvme/mi.c +++ b/src/nvme/mi.c @@ -1398,6 +1398,37 @@ 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_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) { @@ -1442,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 ac75ec4cc..52190636d 100644 --- a/src/nvme/mi.h +++ b/src/nvme/mi.h @@ -3137,6 +3137,30 @@ 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_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 @@ -3208,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