From 7469522fbb57c62fc2736661b0ac6939726cd60e Mon Sep 17 00:00:00 2001 From: Alexander Amelkin Date: Mon, 25 Feb 2019 18:31:33 +0300 Subject: [PATCH] nm: Refactor to get rid of magic completion codes Replace all magic numbers implied to mean NM completions codes with descriptive macro names. Signed-off-by: Alexander Amelkin --- include/ipmitool/ipmi_nm.h | 16 ++++++++++++ lib/ipmi_nm.c | 50 ++++++++++++++++++++++++++------------ 2 files changed, 50 insertions(+), 16 deletions(-) diff --git a/include/ipmitool/ipmi_nm.h b/include/ipmitool/ipmi_nm.h index 2cb0849..5623464 100644 --- a/include/ipmitool/ipmi_nm.h +++ b/include/ipmitool/ipmi_nm.h @@ -60,6 +60,22 @@ #define IPMI_NM_RESET_TRIGGER 0x03 #define IPMI_NM_BOOT_TRIGGER 0x04 +/* Node Manager status codes, as per + * "Intel Intelligent Power Node Manager 3.0 + * External Interface Specification using IPMI" + */ +#define IPMI_NM_CC_POLICY_ID_INVALID 0x80 +#define IPMI_NM_CC_POLICY_DOMAIN_INVALID 0x81 +#define IPMI_NM_CC_POLICY_TRIGGER_UNKNOWN 0x82 +#define IPMI_NM_CC_POLICY_CORRECTION_RANGE 0x85 +#define IPMI_NM_CC_POLICY_TRIGGER_RANGE 0x86 +#define IPMI_NM_CC_POLICY_STATS_RANGE 0x89 +#define IPMI_NM_CC_POLICY_LIMIT_NONE 0xA1 +#define IPMI_NM_CC_POLICY_PARAM_BUSY 0xD5 +#define IPMI_NM_CC_POLICY_VALUE_INVALID 0x8B +#define IPMI_NM_CC_STATS_MODE_INVALID 0x88 +#define IPMI_NM_CC_POWER_LIMIT_RANGE 0x84 + /* Policy Exception Actions flags */ #define IPMI_NM_POLICY_ALERT 0x01 #define IPMI_NM_POLICY_SHUT 0x02 diff --git a/lib/ipmi_nm.c b/lib/ipmi_nm.c index 3a7a45e..b273ff1 100644 --- a/lib/ipmi_nm.c +++ b/lib/ipmi_nm.c @@ -269,20 +269,37 @@ const struct dcmi_cmd nm_suspend_cmds[] = { }; const struct valstr nm_ccode_vals[] = { - { 0x80, "Policy ID Invalid" }, - { 0x81, "Domain ID Invalid" }, - { 0x82, "Unknown policy trigger type" }, - { 0x84, "Power Limit out of range" }, - { 0x85, "Correction Time out of range" }, - { 0x86, "Policy Trigger value out of range" }, - { 0x88, "Invalid Mode" }, - { 0x89, "Statistics Reporting Period out of range" }, - { 0x8B, "Invalid value for Aggressive CPU correction field" }, - { 0xA1, "No policy is currently limiting for the specified domain ID" }, - { 0xC4, "No space available" }, - { 0xD4, "Insufficient privilege level due wrong responder LUN" }, - { 0xD5, "Policy exists and param unchangeable while enabled" }, - { 0xD6, "Command subfunction disabled or unavailable" }, + { IPMI_NM_CC_POLICY_ID_INVALID, + "Policy ID Invalid" }, + { IPMI_NM_CC_POLICY_DOMAIN_INVALID, + "Domain ID Invalid" }, + { IPMI_NM_CC_POLICY_LIMIT_NONE, + "No policy is currently limiting for the specified domain ID" }, + { IPMI_NM_CC_POLICY_CORRECTION_RANGE, + "Correction Time out of range" }, + { IPMI_NM_CC_POLICY_TRIGGER_UNKNOWN, + "Unknown policy trigger type" }, + { IPMI_NM_CC_POLICY_TRIGGER_RANGE, + "Policy Trigger value out of range" }, + { IPMI_NM_CC_POLICY_PARAM_BUSY, + "Policy exists and param unchangeable while enabled" }, + { IPMI_NM_CC_POLICY_DOMAIN_ERR, + "Policies in given power domain cannot be created in the " + "current configuration" }, + { IPMI_NM_CC_POLICY_STATS_RANGE, + "Statistics Reporting Period out of range" }, + { IPMI_NM_CC_POLICY_VALUE_INVALID, + "Invalid value for Aggressive CPU correction field" }, + { IPMI_NM_CC_POWER_LIMIT_RANGE, + "Power Limit out of range" }, + { IPMI_NM_CC_STATS_MODE_INVALID, + "Invalid Mode" }, + { IPMI_CC_OUT_OF_SPACE, + "No space available" }, + { IPMI_CC_INSUFFICIENT_PRIVILEGES, + "Insufficient privilege level or other security restriction" }, + { IPMI_CC_ILLEGAL_COMMAND_DISABLED, + "Command subfunction disabled or unavailable" }, { 0xFF, NULL }, }; /* clang-format on */ @@ -306,7 +323,8 @@ chk_nm_rsp(struct ipmi_rs *rsp) * use val2str from helper.c to print the error from either the DCMI * completion code struct or the generic IPMI completion_code_vals struct */ - if ((rsp->ccode >= 0x80) && (rsp->ccode <= 0xD6)) { + if ((rsp->ccode >= IPMI_NM_CC_POLICY_ID_INVALID) + && (rsp->ccode <= IPMI_NM_CC_POLICY_DOMAIN_ERR)) { lprintf(LOG_ERR, "\n NM request failed because: %s (%x)", val2str(rsp->ccode, nm_ccode_vals), rsp->ccode); return 1; @@ -435,7 +453,7 @@ _ipmi_nm_policy_limiting(struct ipmi_intf *intf, uint8_t domain) req.msg.data_len = 4; rsp = intf->sendrecv(intf, &req); /* check for special case error of no policy is limiting */ - if (rsp && (rsp->ccode == 0xA1)) + if (rsp && (rsp->ccode == IPMI_NM_CC_POLICY_LIMIT_NONE)) return 0x80; else if (chk_nm_rsp(rsp)) return -1;