Skip to content

Commit 60a46c2

Browse files
committed
mi: add power management feature functions
The feature is optional for the managemnet endpoint support. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent 5e1876f commit 60a46c2

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

src/libnvme.map

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
LIBNVME_UNRELEASED {
33
global:
44
nvme_mi_admin_get_features_arbitration;
5+
nvme_mi_admin_get_features_power_mgmt;
6+
nvme_mi_admin_set_features_power_mgmt;
57
};
68

79
LIBNVME_1_14 {

src/nvme/mi.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,12 @@ int nvme_mi_admin_get_features_arbitration(nvme_mi_ctrl_t ctrl, enum nvme_get_fe
14231423
return __nvme_mi_admin_get_features(ctrl, NVME_FEAT_FID_ARBITRATION, sel, result);
14241424
}
14251425

1426+
int nvme_mi_admin_get_features_power_mgmt(nvme_mi_ctrl_t ctrl, enum nvme_get_features_sel sel,
1427+
__u32 *result)
1428+
{
1429+
return __nvme_mi_admin_get_features(ctrl, NVME_FEAT_FID_POWER_MGMT, sel, result);
1430+
}
1431+
14261432
int nvme_mi_admin_set_features(nvme_mi_ctrl_t ctrl,
14271433
struct nvme_set_features_args *args)
14281434
{
@@ -1467,6 +1473,33 @@ int nvme_mi_admin_set_features(nvme_mi_ctrl_t ctrl,
14671473
return 0;
14681474
}
14691475

1476+
static int __nvme_mi_admin_set_features(nvme_mi_ctrl_t ctrl, __u8 fid, __u32 cdw11, bool save,
1477+
__u32 *result)
1478+
{
1479+
struct nvme_set_features_args args = {
1480+
.args_size = sizeof(args),
1481+
.nsid = NVME_NSID_NONE,
1482+
.cdw11 = cdw11,
1483+
.cdw12 = 0,
1484+
.save = save,
1485+
.uuidx = NVME_UUID_NONE,
1486+
.cdw15 = 0,
1487+
.data_len = 0,
1488+
.data = NULL,
1489+
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
1490+
.result = result,
1491+
};
1492+
return nvme_mi_admin_set_features(ctrl, &args);
1493+
}
1494+
1495+
int nvme_mi_admin_set_features_power_mgmt(nvme_mi_ctrl_t ctrl, __u8 ps, __u8 wh, bool save,
1496+
__u32 *result)
1497+
{
1498+
__u32 value = NVME_SET(ps, FEAT_PWRMGMT_PS) | NVME_SET(wh, FEAT_PWRMGMT_WH);
1499+
1500+
return __nvme_mi_admin_set_features(ctrl, NVME_FEAT_FID_POWER_MGMT, value, save, result);
1501+
}
1502+
14701503
int nvme_mi_admin_ns_mgmt(nvme_mi_ctrl_t ctrl,
14711504
struct nvme_ns_mgmt_args *args)
14721505
{

src/nvme/mi.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3149,6 +3149,18 @@ int nvme_mi_admin_get_features(nvme_mi_ctrl_t ctrl,
31493149
int nvme_mi_admin_get_features_arbitration(nvme_mi_ctrl_t ctrl, enum nvme_get_features_sel sel,
31503150
__u32 *result);
31513151

3152+
/**
3153+
* nvme_mi_admin_get_features_power_mgmt() - Get power management feature
3154+
* @ctrl: Controller to send command to
3155+
* @sel: Select which type of attribute to return, see &enum nvme_get_features_sel
3156+
* @result: The command completion result from CQE dword0
3157+
*
3158+
* Return: The nvme command status if a response was received (see
3159+
* &enum nvme_status_field) or -1 with errno set otherwise.
3160+
*/
3161+
int nvme_mi_admin_get_features_power_mgmt(nvme_mi_ctrl_t ctrl, enum nvme_get_features_sel sel,
3162+
__u32 *result);
3163+
31523164
/**
31533165
* nvme_mi_admin_get_features_data() - Helper function for &nvme_mi_admin_get_features()
31543166
* @ctrl: Controller to send command to
@@ -3220,6 +3232,20 @@ static inline int nvme_mi_admin_get_features_simple(nvme_mi_ctrl_t ctrl,
32203232
int nvme_mi_admin_set_features(nvme_mi_ctrl_t ctrl,
32213233
struct nvme_set_features_args *args);
32223234

3235+
/**
3236+
* nvme_mi_admin_set_features_power_mgmt() - Set power management feature
3237+
* @ctrl: Controller to send command to
3238+
* @ps: Power State
3239+
* @wh: Workload Hint
3240+
* @save: Save value across power states
3241+
* @result: The command completion result from CQE dword0
3242+
*
3243+
* Return: The nvme command status if a response was received (see
3244+
* &enum nvme_status_field) or -1 with errno set otherwise.
3245+
*/
3246+
int nvme_mi_admin_set_features_power_mgmt(nvme_mi_ctrl_t ctrl, __u8 ps, __u8 wh, bool save,
3247+
__u32 *result);
3248+
32233249
/**
32243250
* nvme_mi_admin_ns_mgmt - Issue a Namespace Management command
32253251
* @ctrl: Controller to send command to

0 commit comments

Comments
 (0)