fru: add fru_cc_rq2big helper method for code checks

Add fru_cc_rq2big helper method to reduce duplicate
code checking for specific size-based IPMI response
codes.

Signed-off-by: Patrick Venture <venture@google.com>
This commit is contained in:
Patrick Venture 2018-12-04 09:44:27 -08:00 committed by Alexander Amelkin
parent 1c4a00d26b
commit 6dcb168442

View File

@ -101,6 +101,12 @@ static const char * chassis_type_desc[] = {
"Blade Enclosure" "Blade Enclosure"
}; };
static inline bool fru_cc_rq2big(int code) {
return (code == IPMI_CC_REQ_DATA_INV_LENGTH
|| code == IPMI_CC_REQ_DATA_FIELD_EXCEED
|| code == IPMI_CC_CANT_RET_NUM_REQ_BYTES);
}
/* From lib/dimm_spd.c: */ /* From lib/dimm_spd.c: */
int int
ipmi_spd_print_fru(struct ipmi_intf * intf, uint8_t id); ipmi_spd_print_fru(struct ipmi_intf * intf, uint8_t id);
@ -598,16 +604,14 @@ write_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id,
break; break;
} }
if (rsp->ccode == IPMI_CC_REQ_DATA_INV_LENGTH if (fru_cc_rq2big(rsp->ccode)) {
|| rsp->ccode == IPMI_CC_REQ_DATA_FIELD_EXCEED
|| rsp->ccode == IPMI_CC_CANT_RET_NUM_REQ_BYTES) {
if (fru->max_write_size > 8) { if (fru->max_write_size > 8) {
fru->max_write_size -= 8; fru->max_write_size -= 8;
lprintf(LOG_INFO, "Retrying FRU write with request size %d", lprintf(LOG_INFO, "Retrying FRU write with request size %d",
fru->max_write_size); fru->max_write_size);
continue; continue;
} }
} else if(rsp->ccode == 0x80) { } else if (rsp->ccode == 0x80) {
rsp->ccode = 0; rsp->ccode = 0;
// Write protected section // Write protected section
protected_bloc = 1; protected_bloc = 1;
@ -732,9 +736,7 @@ read_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id,
if (rsp->ccode) { if (rsp->ccode) {
/* if we get C7h or C8h or CAh return code then we requested too /* if we get C7h or C8h or CAh return code then we requested too
* many bytes at once so try again with smaller size */ * many bytes at once so try again with smaller size */
if ((rsp->ccode == IPMI_CC_REQ_DATA_INV_LENGTH if (fru_cc_rq2big(rsp->ccode)
|| rsp->ccode == IPMI_CC_REQ_DATA_FIELD_EXCEED
|| rsp->ccode == IPMI_CC_CANT_RET_NUM_REQ_BYTES)
&& fru->max_read_size > 8) { && fru->max_read_size > 8) {
if (fru->max_read_size > 32) { if (fru->max_read_size > 32) {
/* subtract read length more aggressively */ /* subtract read length more aggressively */
@ -840,10 +842,7 @@ read_fru_area_section(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id,
if (rsp->ccode) { if (rsp->ccode) {
/* if we get C7 or C8 or CA return code then we requested too /* if we get C7 or C8 or CA return code then we requested too
* many bytes at once so try again with smaller size */ * many bytes at once so try again with smaller size */
if ((rsp->ccode == IPMI_CC_REQ_DATA_INV_LENGTH if (fru_cc_rq2big(rsp->ccode) && (--fru_data_rqst_size > 8)) {
|| rsp->ccode == IPMI_CC_REQ_DATA_FIELD_EXCEED
|| rsp->ccode == IPMI_CC_CANT_RET_NUM_REQ_BYTES)
&& (--fru_data_rqst_size > 8)) {
lprintf(LOG_INFO, lprintf(LOG_INFO,
"Retrying FRU read with request size %d", "Retrying FRU read with request size %d",
fru_data_rqst_size); fru_data_rqst_size);