mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-12 11:37:23 +00:00
nm: Refactor to reduce code duplication
Add nm_set_id() and nm_check_id() functions, use them and the existing htoipmi24() to reduce code duplication. Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
This commit is contained in:
parent
e0811437a2
commit
be9f1660fb
@ -19,6 +19,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ipmitool/ipmi.h>
|
#include <ipmitool/ipmi.h>
|
||||||
|
#include <ipmitool/helper.h>
|
||||||
|
|
||||||
/* Configuration and control commands per
|
/* Configuration and control commands per
|
||||||
* Intel Intelligent Power Node Manager 2.0
|
* Intel Intelligent Power Node Manager 2.0
|
||||||
@ -41,6 +42,9 @@
|
|||||||
#define IPMI_NM_GET_ALERT_DS 0xCF
|
#define IPMI_NM_GET_ALERT_DS 0xCF
|
||||||
#define IPMI_NM_LIMITING 0xF2
|
#define IPMI_NM_LIMITING 0xF2
|
||||||
|
|
||||||
|
/* Node Manager identification */
|
||||||
|
#define IPMI_NM_ID 0x000157 /* Three bytes */
|
||||||
|
|
||||||
/* Node Manager Policy Control Flags */
|
/* Node Manager Policy Control Flags */
|
||||||
#define IPMI_NM_GLOBAL_ENABLE 0x01
|
#define IPMI_NM_GLOBAL_ENABLE 0x01
|
||||||
#define IPMI_NM_DOMAIN_ENABLE 0x02
|
#define IPMI_NM_DOMAIN_ENABLE 0x02
|
||||||
@ -169,3 +173,13 @@ struct nm_suspend {
|
|||||||
} __attribute__ ((packed));
|
} __attribute__ ((packed));
|
||||||
|
|
||||||
int ipmi_nm_main(struct ipmi_intf *intf, int argc, char **argv);
|
int ipmi_nm_main(struct ipmi_intf *intf, int argc, char **argv);
|
||||||
|
|
||||||
|
static inline void nm_set_id(void *buf)
|
||||||
|
{
|
||||||
|
htoipmi24(IPMI_NM_ID, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool nm_check_id(void *buf)
|
||||||
|
{
|
||||||
|
return IPMI_NM_ID == ipmi24toh(buf);
|
||||||
|
}
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
* according to the corresponding specification.
|
* according to the corresponding specification.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include <ipmitool/ipmi_dcmi.h>
|
#include <ipmitool/ipmi_dcmi.h>
|
||||||
#include <ipmitool/ipmi_nm.h>
|
#include <ipmitool/ipmi_nm.h>
|
||||||
#include <ipmitool/helper.h>
|
#include <ipmitool/helper.h>
|
||||||
@ -313,8 +315,8 @@ chk_nm_rsp(struct ipmi_rs *rsp)
|
|||||||
val2str(rsp->ccode, completion_code_vals), rsp->ccode);
|
val2str(rsp->ccode, completion_code_vals), rsp->ccode);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/* check to make sure this is a DCMI firmware */
|
/* check to make sure this is an NM firmware */
|
||||||
if (rsp->data[0] != 0x57) {
|
if (!nm_check_id(rsp->data)) {
|
||||||
printf("\n A valid NM command was not returned! (%x)", rsp->data[0]);
|
printf("\n A valid NM command was not returned! (%x)", rsp->data[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -329,9 +331,7 @@ _ipmi_nm_discover(struct ipmi_intf *intf, struct nm_discover *disc)
|
|||||||
struct ipmi_rs *rsp;
|
struct ipmi_rs *rsp;
|
||||||
uint8_t msg_data[3]; /* 'raw' data to be sent to the BMC */
|
uint8_t msg_data[3]; /* 'raw' data to be sent to the BMC */
|
||||||
|
|
||||||
msg_data[0] = 0x57;
|
nm_set_id(msg_data);
|
||||||
msg_data[1] = 1;
|
|
||||||
msg_data[2] = 0;
|
|
||||||
memset(&req, 0, sizeof(req));
|
memset(&req, 0, sizeof(req));
|
||||||
req.msg.netfn = IPMI_NETFN_OEM;
|
req.msg.netfn = IPMI_NETFN_OEM;
|
||||||
req.msg.cmd = IPMI_NM_GET_VERSION;
|
req.msg.cmd = IPMI_NM_GET_VERSION;
|
||||||
@ -361,9 +361,7 @@ _ipmi_nm_getcapabilities(struct ipmi_intf *intf, uint8_t domain,
|
|||||||
struct ipmi_rs *rsp;
|
struct ipmi_rs *rsp;
|
||||||
uint8_t msg_data[5]; /* 'raw' data to be sent to the BMC */
|
uint8_t msg_data[5]; /* 'raw' data to be sent to the BMC */
|
||||||
|
|
||||||
msg_data[0] = 0x57;
|
nm_set_id(msg_data);
|
||||||
msg_data[1] = 1;
|
|
||||||
msg_data[2] = 0;
|
|
||||||
msg_data[3] = domain;
|
msg_data[3] = domain;
|
||||||
msg_data[4] = trigger; /* power control policy or trigger */
|
msg_data[4] = trigger; /* power control policy or trigger */
|
||||||
memset(&req, 0, sizeof(req));
|
memset(&req, 0, sizeof(req));
|
||||||
@ -387,9 +385,7 @@ _ipmi_nm_get_policy(struct ipmi_intf *intf, uint8_t domain, uint8_t policy_id,
|
|||||||
struct ipmi_rs *rsp;
|
struct ipmi_rs *rsp;
|
||||||
uint8_t msg_data[5]; /* 'raw' data to be sent to the BMC */
|
uint8_t msg_data[5]; /* 'raw' data to be sent to the BMC */
|
||||||
|
|
||||||
msg_data[0] = 0x57;
|
nm_set_id(msg_data);
|
||||||
msg_data[1] = 1;
|
|
||||||
msg_data[2] = 0;
|
|
||||||
msg_data[3] = domain;
|
msg_data[3] = domain;
|
||||||
msg_data[4] = policy_id;
|
msg_data[4] = policy_id;
|
||||||
memset(&req, 0, sizeof(req));
|
memset(&req, 0, sizeof(req));
|
||||||
@ -415,9 +411,7 @@ _ipmi_nm_set_policy(struct ipmi_intf *intf, struct nm_policy *policy)
|
|||||||
req.msg.cmd = IPMI_NM_SET_POLICY;
|
req.msg.cmd = IPMI_NM_SET_POLICY;
|
||||||
req.msg.data = (uint8_t *)policy;
|
req.msg.data = (uint8_t *)policy;
|
||||||
req.msg.data_len = sizeof(struct nm_policy);
|
req.msg.data_len = sizeof(struct nm_policy);
|
||||||
policy->intel_id[0] = 0x57;
|
nm_set_id(policy->intel_id);
|
||||||
policy->intel_id[1] = 1;
|
|
||||||
policy->intel_id[2] = 0;
|
|
||||||
rsp = intf->sendrecv(intf, &req);
|
rsp = intf->sendrecv(intf, &req);
|
||||||
if (chk_nm_rsp(rsp)) {
|
if (chk_nm_rsp(rsp)) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -435,9 +429,7 @@ _ipmi_nm_policy_limiting(struct ipmi_intf *intf, uint8_t domain)
|
|||||||
memset(&req, 0, sizeof(req));
|
memset(&req, 0, sizeof(req));
|
||||||
req.msg.netfn = IPMI_NETFN_OEM;
|
req.msg.netfn = IPMI_NETFN_OEM;
|
||||||
req.msg.cmd = IPMI_NM_LIMITING;
|
req.msg.cmd = IPMI_NM_LIMITING;
|
||||||
msg_data[0] = 0x57;
|
nm_set_id(msg_data);
|
||||||
msg_data[1] = 1;
|
|
||||||
msg_data[2] = 0;
|
|
||||||
msg_data[3] = domain;
|
msg_data[3] = domain;
|
||||||
req.msg.data = msg_data;
|
req.msg.data = msg_data;
|
||||||
req.msg.data_len = 4;
|
req.msg.data_len = 4;
|
||||||
@ -458,9 +450,7 @@ _ipmi_nm_control(struct ipmi_intf *intf, uint8_t scope,
|
|||||||
struct ipmi_rs *rsp;
|
struct ipmi_rs *rsp;
|
||||||
uint8_t msg_data[6]; /* 'raw' data to be sent to the BMC */
|
uint8_t msg_data[6]; /* 'raw' data to be sent to the BMC */
|
||||||
|
|
||||||
msg_data[0] = 0x57;
|
nm_set_id(msg_data);
|
||||||
msg_data[1] = 1;
|
|
||||||
msg_data[2] = 0;
|
|
||||||
msg_data[3] = scope;
|
msg_data[3] = scope;
|
||||||
msg_data[4] = domain;
|
msg_data[4] = domain;
|
||||||
msg_data[5] = policy_id;
|
msg_data[5] = policy_id;
|
||||||
@ -493,9 +483,7 @@ _ipmi_nm_statistics(struct ipmi_intf *intf, uint8_t mode, uint8_t domain,
|
|||||||
struct ipmi_rs *rsp;
|
struct ipmi_rs *rsp;
|
||||||
uint8_t msg_data[6]; /* 'raw' data to be sent to the BMC */
|
uint8_t msg_data[6]; /* 'raw' data to be sent to the BMC */
|
||||||
|
|
||||||
msg_data[0] = 0x57;
|
nm_set_id(msg_data);
|
||||||
msg_data[1] = 1;
|
|
||||||
msg_data[2] = 0;
|
|
||||||
msg_data[3] = mode;
|
msg_data[3] = mode;
|
||||||
msg_data[4] = domain;
|
msg_data[4] = domain;
|
||||||
msg_data[5] = policy_id;
|
msg_data[5] = policy_id;
|
||||||
@ -520,9 +508,7 @@ _ipmi_nm_reset_stats(struct ipmi_intf *intf, uint8_t mode,
|
|||||||
struct ipmi_rs *rsp;
|
struct ipmi_rs *rsp;
|
||||||
uint8_t msg_data[6]; /* 'raw' data to be sent to the BMC */
|
uint8_t msg_data[6]; /* 'raw' data to be sent to the BMC */
|
||||||
|
|
||||||
msg_data[0] = 0x57;
|
nm_set_id(msg_data);
|
||||||
msg_data[1] = 1;
|
|
||||||
msg_data[2] = 0;
|
|
||||||
msg_data[3] = mode;
|
msg_data[3] = mode;
|
||||||
msg_data[4] = domain;
|
msg_data[4] = domain;
|
||||||
msg_data[5] = policy_id;
|
msg_data[5] = policy_id;
|
||||||
@ -546,9 +532,7 @@ _nm_set_range(struct ipmi_intf *intf, uint8_t domain,
|
|||||||
struct ipmi_rs *rsp;
|
struct ipmi_rs *rsp;
|
||||||
uint8_t msg_data[8]; /* 'raw' data to be sent to the BMC */
|
uint8_t msg_data[8]; /* 'raw' data to be sent to the BMC */
|
||||||
|
|
||||||
msg_data[0] = 0x57;
|
nm_set_id(msg_data);
|
||||||
msg_data[1] = 1;
|
|
||||||
msg_data[2] = 0;
|
|
||||||
msg_data[3] = domain;
|
msg_data[3] = domain;
|
||||||
msg_data[4] = minimum & 0xFF;
|
msg_data[4] = minimum & 0xFF;
|
||||||
msg_data[5] = minimum >> 8;
|
msg_data[5] = minimum >> 8;
|
||||||
@ -573,9 +557,7 @@ _ipmi_nm_get_alert(struct ipmi_intf *intf, struct nm_set_alert *alert)
|
|||||||
struct ipmi_rs *rsp;
|
struct ipmi_rs *rsp;
|
||||||
uint8_t msg_data[3]; /* 'raw' data to be sent to the BMC */
|
uint8_t msg_data[3]; /* 'raw' data to be sent to the BMC */
|
||||||
|
|
||||||
msg_data[0] = 0x57;
|
nm_set_id(msg_data);
|
||||||
msg_data[1] = 1;
|
|
||||||
msg_data[2] = 0;
|
|
||||||
memset(&req, 0, sizeof(req));
|
memset(&req, 0, sizeof(req));
|
||||||
req.msg.netfn = IPMI_NETFN_OEM;
|
req.msg.netfn = IPMI_NETFN_OEM;
|
||||||
req.msg.cmd = IPMI_NM_GET_ALERT_DS;
|
req.msg.cmd = IPMI_NM_GET_ALERT_DS;
|
||||||
@ -596,9 +578,7 @@ _ipmi_nm_set_alert(struct ipmi_intf *intf, struct nm_set_alert *alert)
|
|||||||
struct ipmi_rs *rsp;
|
struct ipmi_rs *rsp;
|
||||||
uint8_t msg_data[6]; /* 'raw' data to be sent to the BMC */
|
uint8_t msg_data[6]; /* 'raw' data to be sent to the BMC */
|
||||||
|
|
||||||
msg_data[0] = 0x57;
|
nm_set_id(msg_data);
|
||||||
msg_data[1] = 1;
|
|
||||||
msg_data[2] = 0;
|
|
||||||
msg_data[3] = alert->chan;
|
msg_data[3] = alert->chan;
|
||||||
msg_data[4] = alert->dest;
|
msg_data[4] = alert->dest;
|
||||||
msg_data[5] = alert->string;
|
msg_data[5] = alert->string;
|
||||||
@ -629,9 +609,7 @@ _ipmi_nm_get_thresh(struct ipmi_intf *intf, uint8_t domain,
|
|||||||
struct ipmi_rs *rsp;
|
struct ipmi_rs *rsp;
|
||||||
uint8_t msg_data[5]; /* 'raw' data to be sent to the BMC */
|
uint8_t msg_data[5]; /* 'raw' data to be sent to the BMC */
|
||||||
|
|
||||||
msg_data[0] = 0x57;
|
nm_set_id(msg_data);
|
||||||
msg_data[1] = 1;
|
|
||||||
msg_data[2] = 0;
|
|
||||||
msg_data[3] = domain;
|
msg_data[3] = domain;
|
||||||
msg_data[4] = policy_id;
|
msg_data[4] = policy_id;
|
||||||
memset(&req, 0, sizeof(req));
|
memset(&req, 0, sizeof(req));
|
||||||
@ -660,9 +638,7 @@ _ipmi_nm_set_thresh(struct ipmi_intf *intf, struct nm_thresh * thresh)
|
|||||||
uint8_t msg_data[IPMI_NM_SET_THRESH_LEN]; /* 'raw' data to be sent to the BMC */
|
uint8_t msg_data[IPMI_NM_SET_THRESH_LEN]; /* 'raw' data to be sent to the BMC */
|
||||||
|
|
||||||
memset(&msg_data, 0, sizeof(msg_data));
|
memset(&msg_data, 0, sizeof(msg_data));
|
||||||
msg_data[0] = 0x57;
|
nm_set_id(msg_data);
|
||||||
msg_data[1] = 1;
|
|
||||||
msg_data[2] = 0;
|
|
||||||
msg_data[3] = thresh->domain;
|
msg_data[3] = thresh->domain;
|
||||||
msg_data[4] = thresh->policy_id;
|
msg_data[4] = thresh->policy_id;
|
||||||
msg_data[5] = thresh->count;
|
msg_data[5] = thresh->count;
|
||||||
@ -705,9 +681,7 @@ _ipmi_nm_get_suspend(struct ipmi_intf *intf, uint8_t domain,
|
|||||||
uint8_t msg_data[5]; /* 'raw' data to be sent to the BMC */
|
uint8_t msg_data[5]; /* 'raw' data to be sent to the BMC */
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
msg_data[0] = 0x57;
|
nm_set_id(msg_data);
|
||||||
msg_data[1] = 1;
|
|
||||||
msg_data[2] = 0;
|
|
||||||
msg_data[3] = domain;
|
msg_data[3] = domain;
|
||||||
msg_data[4] = policy_id;
|
msg_data[4] = policy_id;
|
||||||
memset(&req, 0, sizeof(req));
|
memset(&req, 0, sizeof(req));
|
||||||
@ -738,9 +712,7 @@ _ipmi_nm_set_suspend(struct ipmi_intf *intf, struct nm_suspend *suspend)
|
|||||||
struct nm_period *periods;
|
struct nm_period *periods;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
msg_data[0] = 0x57;
|
nm_set_id(msg_data);
|
||||||
msg_data[1] = 1;
|
|
||||||
msg_data[2] = 0;
|
|
||||||
msg_data[3] = suspend->domain;
|
msg_data[3] = suspend->domain;
|
||||||
msg_data[4] = suspend->policy_id;
|
msg_data[4] = suspend->policy_id;
|
||||||
msg_data[5] = suspend->count;
|
msg_data[5] = suspend->count;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user