mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-12 11:37:23 +00:00
fru: Reduce duplicate code
Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
This commit is contained in:
parent
55ec2df41f
commit
57dc21a486
196
lib/ipmi_fru.c
196
lib/ipmi_fru.c
@ -2872,27 +2872,32 @@ static void ipmi_fru_picmg_ext_print(uint8_t * fru_data, int off, int length)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** __ipmi_get_fru_hdr - read FRU info and header from IPMI interface
|
||||||
/* __ipmi_fru_print - Do actual work to print a FRU by its ID
|
*
|
||||||
*
|
* @param[in] intf ipmi interface
|
||||||
* @intf: ipmi interface
|
* @param[in] id fru id
|
||||||
* @id: fru id
|
* @param[out] fru fru info structure pointer
|
||||||
*
|
* @param[out] size size of the allocated fru structure
|
||||||
* returns -1 on error
|
*
|
||||||
* returns 0 if successful
|
* @retval 0 error
|
||||||
* returns 1 if device not present
|
* @retval 1 success
|
||||||
*/
|
*/
|
||||||
static int
|
static int __ipmi_get_fru_hdr(struct ipmi_intf *intf,
|
||||||
__ipmi_fru_print(struct ipmi_intf * intf, uint8_t id)
|
uint8_t id,
|
||||||
|
struct fru_info *fru,
|
||||||
|
struct fru_header *header)
|
||||||
{
|
{
|
||||||
struct ipmi_rs * rsp;
|
struct ipmi_rs *rsp;
|
||||||
struct ipmi_rq req;
|
struct ipmi_rq req;
|
||||||
struct fru_info fru;
|
|
||||||
struct fru_header header;
|
|
||||||
uint8_t msg_data[4];
|
uint8_t msg_data[4];
|
||||||
|
|
||||||
memset(&fru, 0, sizeof(struct fru_info));
|
/* Sanity checks */
|
||||||
memset(&header, 0, sizeof(struct fru_header));
|
if (!fru) return 0;
|
||||||
|
if (!header) return 0;
|
||||||
|
if (!intf) return 0;
|
||||||
|
|
||||||
|
memset(fru, 0, sizeof(*fru));
|
||||||
|
memset(header, 0, sizeof(*header));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get info about this FRU
|
* get info about this FRU
|
||||||
@ -2909,59 +2914,56 @@ __ipmi_fru_print(struct ipmi_intf * intf, uint8_t id)
|
|||||||
rsp = intf->sendrecv(intf, &req);
|
rsp = intf->sendrecv(intf, &req);
|
||||||
if (!rsp) {
|
if (!rsp) {
|
||||||
printf(" Device not present (No Response)\n");
|
printf(" Device not present (No Response)\n");
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
if (rsp->ccode) {
|
if (rsp->ccode) {
|
||||||
printf(" Device not present (%s)\n",
|
printf(" Device not present (%s)\n",
|
||||||
val2str(rsp->ccode, completion_code_vals));
|
val2str(rsp->ccode, completion_code_vals));
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&fru, 0, sizeof(fru));
|
fru->size = (rsp->data[1] << 8) | rsp->data[0];
|
||||||
fru.size = (rsp->data[1] << 8) | rsp->data[0];
|
fru->access = rsp->data[2] & 0x1;
|
||||||
fru.access = rsp->data[2] & 0x1;
|
|
||||||
|
|
||||||
lprintf(LOG_DEBUG, "fru.size = %d bytes (accessed by %s)",
|
lprintf(LOG_DEBUG, "fru.size = %d bytes (accessed by %s)",
|
||||||
fru.size, fru.access ? "words" : "bytes");
|
fru->size, fru->access ? "words" : "bytes");
|
||||||
|
|
||||||
if (fru.size < 1) {
|
if (fru->size < 1) {
|
||||||
lprintf(LOG_ERR, " Invalid FRU size %d", fru.size);
|
lprintf(LOG_ERR, " Invalid FRU size %d", fru->size);
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* Read the FRU header */
|
||||||
* retrieve the FRU header
|
if (read_fru_area(intf, fru, id, 0, sizeof(*header), header)) {
|
||||||
*/
|
lprintf(LOG_ERR, " Failed to read FRU header");
|
||||||
msg_data[0] = id;
|
return 0;
|
||||||
msg_data[1] = 0;
|
|
||||||
msg_data[2] = 0;
|
|
||||||
msg_data[3] = 8;
|
|
||||||
|
|
||||||
memset(&req, 0, sizeof(req));
|
|
||||||
req.msg.netfn = IPMI_NETFN_STORAGE;
|
|
||||||
req.msg.cmd = GET_FRU_DATA;
|
|
||||||
req.msg.data = msg_data;
|
|
||||||
req.msg.data_len = 4;
|
|
||||||
|
|
||||||
rsp = intf->sendrecv(intf, &req);
|
|
||||||
if (!rsp) {
|
|
||||||
printf(" Device not present (No Response)\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (rsp->ccode) {
|
|
||||||
printf(" Device not present (%s)\n",
|
|
||||||
val2str(rsp->ccode, completion_code_vals));
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose > 1)
|
if (header->version != 1) {
|
||||||
printbuf(rsp->data, rsp->data_len, "FRU DATA");
|
|
||||||
|
|
||||||
memcpy(&header, rsp->data + 1, 8);
|
|
||||||
|
|
||||||
if (header.version != 1) {
|
|
||||||
lprintf(LOG_ERR, " Unknown FRU header version 0x%02x",
|
lprintf(LOG_ERR, " Unknown FRU header version 0x%02x",
|
||||||
header.version);
|
header->version);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* __ipmi_fru_print - Do actual work to print a FRU by its ID
|
||||||
|
*
|
||||||
|
* @intf: ipmi interface
|
||||||
|
* @id: fru id
|
||||||
|
*
|
||||||
|
* returns -1 on error
|
||||||
|
* returns 0 if successful
|
||||||
|
* returns 1 if device not present
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
__ipmi_fru_print(struct ipmi_intf * intf, uint8_t id)
|
||||||
|
{
|
||||||
|
struct fru_info fru;
|
||||||
|
struct fru_header header;
|
||||||
|
|
||||||
|
if (!__ipmi_get_fru_hdr(intf, id, &fru, &header)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4056,91 +4058,19 @@ ipmi_fru_get_multirec_location_from_fru(struct ipmi_intf * intf,
|
|||||||
* returns 1 if device not present
|
* returns 1 if device not present
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
ipmi_fru_get_internal_use_info( struct ipmi_intf * intf,
|
ipmi_fru_get_internal_use_info(struct ipmi_intf *intf,
|
||||||
uint8_t id,
|
uint8_t id,
|
||||||
struct fru_info * fru,
|
struct fru_info *fru,
|
||||||
uint16_t * size,
|
uint16_t *size,
|
||||||
uint16_t * offset)
|
uint16_t *offset)
|
||||||
{
|
{
|
||||||
struct ipmi_rs * rsp;
|
|
||||||
struct ipmi_rq req;
|
|
||||||
struct fru_header header;
|
struct fru_header header;
|
||||||
uint8_t msg_data[4];
|
|
||||||
|
|
||||||
// Init output value
|
// Init output value
|
||||||
* offset = 0;
|
* offset = 0;
|
||||||
* size = 0;
|
* size = 0;
|
||||||
|
|
||||||
memset(fru, 0, sizeof(struct fru_info));
|
if (!__ipmi_get_fru_hdr(intf, id, fru, &header)) {
|
||||||
memset(&header, 0, sizeof(struct fru_header));
|
|
||||||
|
|
||||||
/*
|
|
||||||
* get info about this FRU
|
|
||||||
*/
|
|
||||||
memset(msg_data, 0, 4);
|
|
||||||
msg_data[0] = id;
|
|
||||||
|
|
||||||
memset(&req, 0, sizeof(req));
|
|
||||||
req.msg.netfn = IPMI_NETFN_STORAGE;
|
|
||||||
req.msg.cmd = GET_FRU_INFO;
|
|
||||||
req.msg.data = msg_data;
|
|
||||||
req.msg.data_len = 1;
|
|
||||||
|
|
||||||
rsp = intf->sendrecv(intf, &req);
|
|
||||||
if (!rsp) {
|
|
||||||
printf(" Device not present (No Response)\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (rsp->ccode) {
|
|
||||||
printf(" Device not present (%s)\n",
|
|
||||||
val2str(rsp->ccode, completion_code_vals));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
fru->size = (rsp->data[1] << 8) | rsp->data[0];
|
|
||||||
fru->access = rsp->data[2] & 0x1;
|
|
||||||
|
|
||||||
lprintf(LOG_DEBUG, "fru.size = %d bytes (accessed by %s)",
|
|
||||||
fru->size, fru->access ? "words" : "bytes");
|
|
||||||
|
|
||||||
if (fru->size < 1) {
|
|
||||||
lprintf(LOG_ERR, " Invalid FRU size %d", fru->size);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* retrieve the FRU header
|
|
||||||
*/
|
|
||||||
msg_data[0] = id;
|
|
||||||
msg_data[1] = 0;
|
|
||||||
msg_data[2] = 0;
|
|
||||||
msg_data[3] = 8;
|
|
||||||
|
|
||||||
memset(&req, 0, sizeof(req));
|
|
||||||
req.msg.netfn = IPMI_NETFN_STORAGE;
|
|
||||||
req.msg.cmd = GET_FRU_DATA;
|
|
||||||
req.msg.data = msg_data;
|
|
||||||
req.msg.data_len = 4;
|
|
||||||
|
|
||||||
rsp = intf->sendrecv(intf, &req);
|
|
||||||
if (!rsp) {
|
|
||||||
printf(" Device not present (No Response)\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (rsp->ccode) {
|
|
||||||
printf(" Device not present (%s)\n",
|
|
||||||
val2str(rsp->ccode, completion_code_vals));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (verbose > 1)
|
|
||||||
printbuf(rsp->data, rsp->data_len, "FRU DATA");
|
|
||||||
|
|
||||||
memcpy(&header, rsp->data + 1, 8);
|
|
||||||
|
|
||||||
if (header.version != 1) {
|
|
||||||
lprintf(LOG_ERR, " Unknown FRU header version 0x%02x",
|
|
||||||
header.version);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user