static int _sdr_cache_reservation_id (ipmi_sdr_ctx_t ctx, ipmi_ctx_t ipmi_ctx, uint16_t *reservation_id) { fiid_obj_t obj_cmd_rs = NULL; uint64_t val; int rv = -1; assert (ctx); assert (ctx->magic == IPMI_SDR_CTX_MAGIC); assert (ipmi_ctx); assert (reservation_id); if (!(obj_cmd_rs = fiid_obj_create (tmpl_cmd_reserve_sdr_repository_rs))) { SDR_ERRNO_TO_SDR_ERRNUM (ctx, errno); goto cleanup; } if (ipmi_cmd_reserve_sdr_repository (ipmi_ctx, obj_cmd_rs) < 0) { SDR_SET_ERRNUM (ctx, IPMI_SDR_ERR_IPMI_ERROR); goto cleanup; } *reservation_id = 0; if (FIID_OBJ_GET (obj_cmd_rs, "reservation_id", &val) < 0) { SDR_FIID_OBJECT_ERROR_TO_SDR_ERRNUM (ctx, obj_cmd_rs); goto cleanup; } *reservation_id = val; rv = 0; cleanup: fiid_obj_destroy (obj_cmd_rs); return (rv); }
/* return (1) - is oem intel node manager, fully parsed * return (0) - is not oem intel node manager * return (-1) - error */ int ipmi_sdr_oem_parse_intel_node_manager (ipmi_sdr_ctx_t ctx, const void *sdr_record, unsigned int sdr_record_len, uint8_t *nm_device_slave_address, uint8_t *sensor_owner_lun, uint8_t *channel_number, uint8_t *nm_health_event_sensor_number, uint8_t *nm_exception_event_sensor_number, uint8_t *nm_operational_capabilities_sensor_number, uint8_t *nm_alert_threshold_exceeded_sensor_number) { uint8_t sdr_record_buf[IPMI_SDR_MAX_RECORD_LENGTH]; int sdr_record_buf_len; fiid_obj_t obj_oem_record = NULL; int expected_record_len; void *sdr_record_to_use; unsigned int sdr_record_len_to_use; uint64_t val; int rv = -1; if (!ctx || ctx->magic != IPMI_SDR_CTX_MAGIC) { ERR_TRACE (ipmi_sdr_ctx_errormsg (ctx), ipmi_sdr_ctx_errnum (ctx)); return (-1); } if (!sdr_record || !sdr_record_len) { if (ctx->operation == IPMI_SDR_OPERATION_READ_CACHE && !sdr_record && !sdr_record_len) { if ((sdr_record_buf_len = ipmi_sdr_cache_record_read (ctx, sdr_record_buf, IPMI_SDR_MAX_RECORD_LENGTH)) < 0) { SDR_SET_INTERNAL_ERRNUM (ctx); return (-1); } sdr_record_to_use = sdr_record_buf; sdr_record_len_to_use = sdr_record_buf_len; } else { SDR_SET_ERRNUM (ctx, IPMI_SDR_ERR_PARAMETERS); return (-1); } } else { sdr_record_to_use = (void *)sdr_record; sdr_record_len_to_use = sdr_record_len; } if ((expected_record_len = fiid_template_len_bytes (tmpl_sdr_oem_intel_node_manager_record)) < 0) { SDR_ERRNO_TO_SDR_ERRNUM (ctx, errno); goto cleanup; } if (sdr_record_len_to_use < expected_record_len) { rv = 0; goto cleanup; } if (!(obj_oem_record = fiid_obj_create (tmpl_sdr_oem_intel_node_manager_record))) { SDR_ERRNO_TO_SDR_ERRNUM (ctx, errno); goto cleanup; } if (fiid_obj_set_all (obj_oem_record, sdr_record_to_use, expected_record_len) < 0) { SDR_FIID_OBJECT_ERROR_TO_SDR_ERRNUM (ctx, obj_oem_record); goto cleanup; } /* achu: Node Manager documentation states that OEM ID in the * SDR record should be Intel's, but I've seen motherboards w/o * it, so don't bother checking. */ if (FIID_OBJ_GET (obj_oem_record, "record_subtype", &val) < 0) { SDR_FIID_OBJECT_ERROR_TO_SDR_ERRNUM (ctx, obj_oem_record); goto cleanup; } if (val != IPMI_SDR_OEM_INTEL_NODE_MANAGER_RECORD_SUBTYPE_NM_DISCOVERY) { rv = 0; goto cleanup; } if (FIID_OBJ_GET (obj_oem_record, "version_number", &val) < 0) { SDR_FIID_OBJECT_ERROR_TO_SDR_ERRNUM (ctx, obj_oem_record); goto cleanup; } if (val != IPMI_SDR_OEM_INTEL_NODE_MANAGER_DISCOVERY_VERSION) { rv = 0; goto cleanup; } if (nm_device_slave_address) { if (FIID_OBJ_GET (obj_oem_record, "nm_device_slave_address", &val) < 0) { SDR_FIID_OBJECT_ERROR_TO_SDR_ERRNUM (ctx, obj_oem_record); goto cleanup; } (*nm_device_slave_address) = val; } if (sensor_owner_lun) { if (FIID_OBJ_GET (obj_oem_record, "sensor_owner_lun", &val) < 0) { SDR_FIID_OBJECT_ERROR_TO_SDR_ERRNUM (ctx, obj_oem_record); goto cleanup; } (*sensor_owner_lun) = val; } if (channel_number) { if (FIID_OBJ_GET (obj_oem_record, "channel_number", &val) < 0) { SDR_FIID_OBJECT_ERROR_TO_SDR_ERRNUM (ctx, obj_oem_record); goto cleanup; } (*channel_number) = val; } if (nm_health_event_sensor_number) { if (FIID_OBJ_GET (obj_oem_record, "nm_health_event_sensor_number", &val) < 0) { SDR_FIID_OBJECT_ERROR_TO_SDR_ERRNUM (ctx, obj_oem_record); goto cleanup; } (*nm_health_event_sensor_number) = val; } if (nm_exception_event_sensor_number) { if (FIID_OBJ_GET (obj_oem_record, "nm_exception_event_sensor_number", &val) < 0) { SDR_FIID_OBJECT_ERROR_TO_SDR_ERRNUM (ctx, obj_oem_record); goto cleanup; } (*nm_exception_event_sensor_number) = val; } if (nm_operational_capabilities_sensor_number) { if (FIID_OBJ_GET (obj_oem_record, "nm_operational_capabilities_sensor_number", &val) < 0) { SDR_FIID_OBJECT_ERROR_TO_SDR_ERRNUM (ctx, obj_oem_record); goto cleanup; } (*nm_operational_capabilities_sensor_number) = val; } if (nm_alert_threshold_exceeded_sensor_number) { if (FIID_OBJ_GET (obj_oem_record, "nm_alert_threshold_exceeded_sensor_number", &val) < 0) { SDR_FIID_OBJECT_ERROR_TO_SDR_ERRNUM (ctx, obj_oem_record); goto cleanup; } (*nm_alert_threshold_exceeded_sensor_number) = val; } sdr_check_read_status (ctx); rv = 1; ctx->errnum = IPMI_SDR_ERR_SUCCESS; cleanup: fiid_obj_destroy (obj_oem_record); return (rv); }
static int _sdr_cache_get_record (ipmi_sdr_ctx_t ctx, ipmi_ctx_t ipmi_ctx, uint16_t record_id, void *record_buf, unsigned int record_buf_len, uint16_t *reservation_id, uint16_t *next_record_id) { fiid_obj_t obj_cmd_rs = NULL; fiid_obj_t obj_sdr_record_header = NULL; int sdr_record_header_length = 0; int sdr_record_len = 0; unsigned int record_length = 0; int rv = -1; unsigned int bytes_to_read = IPMI_SDR_CACHE_BYTES_TO_READ_START; unsigned int offset_into_record = 0; unsigned int reservation_id_retry_count = 0; uint8_t temp_record_buf[IPMI_SDR_MAX_RECORD_LENGTH]; uint64_t val; assert (ctx); assert (ctx->magic == IPMI_SDR_CTX_MAGIC); assert (ipmi_ctx); assert (record_buf); assert (record_buf_len); assert (reservation_id); assert (next_record_id); if (!(obj_cmd_rs = fiid_obj_create (tmpl_cmd_get_sdr_rs))) { SDR_ERRNO_TO_SDR_ERRNUM (ctx, errno); goto cleanup; } if (!(obj_sdr_record_header = fiid_obj_create (tmpl_sdr_record_header))) { SDR_ERRNO_TO_SDR_ERRNUM (ctx, errno); goto cleanup; } if ((sdr_record_header_length = fiid_template_len_bytes (tmpl_sdr_record_header)) < 0) { SDR_ERRNO_TO_SDR_ERRNUM (ctx, errno); goto cleanup; } /* achu: * * Many motherboards now allow you to read the full SDR record, try * that first. If it fails for any reason, bail and try to read via * partial reads. */ reservation_id_retry_count = 0; while (!offset_into_record) { if (ipmi_cmd_get_sdr (ipmi_ctx, *reservation_id, record_id, 0, IPMI_SDR_READ_ENTIRE_RECORD_BYTES_TO_READ, obj_cmd_rs) < 0) { if (ipmi_ctx_errnum (ipmi_ctx) == IPMI_ERR_BAD_COMPLETION_CODE) { uint8_t comp_code; if (FIID_OBJ_GET (obj_cmd_rs, "comp_code", &val) < 0) { SDR_FIID_OBJECT_ERROR_TO_SDR_ERRNUM (ctx, obj_cmd_rs); goto cleanup; } comp_code = val; if (comp_code == IPMI_COMP_CODE_RESERVATION_CANCELLED && (reservation_id_retry_count < IPMI_SDR_CACHE_MAX_RESERVATION_ID_RETRY)) { if (_sdr_cache_reservation_id (ctx, ipmi_ctx, reservation_id) < 0) goto cleanup; reservation_id_retry_count++; continue; } } goto partial_read; } if ((sdr_record_len = fiid_obj_get_data (obj_cmd_rs, "record_data", temp_record_buf, IPMI_SDR_MAX_RECORD_LENGTH)) < 0) { SDR_FIID_OBJECT_ERROR_TO_SDR_ERRNUM (ctx, obj_cmd_rs); goto cleanup; } /* Assume this is an "IPMI Error", fall through to partial reads */ if (sdr_record_len < sdr_record_header_length) goto partial_read; /* * IPMI Workaround (achu) * * Discovered on Xyratex HB-F8-SRAY * * For some reason reading the entire SDR record (with * IPMI_SDR_READ_ENTIRE_RECORD_BYTES_TO_READ) the response * returns fewer bytes than the actual length of the record. * However, when reading with partial reads things ultimately * succeed. If we notice the length is off, we fall out and do * a partial read. */ if ((((uint8_t)temp_record_buf[IPMI_SDR_RECORD_LENGTH_INDEX]) + IPMI_SDR_RECORD_HEADER_LENGTH) > sdr_record_len) goto partial_read; if (sdr_record_len > record_buf_len) { SDR_SET_ERRNUM (ctx, IPMI_SDR_ERR_INTERNAL_ERROR); goto cleanup; } if (FIID_OBJ_GET (obj_cmd_rs, "next_record_id", &val) < 0) { SDR_FIID_OBJECT_ERROR_TO_SDR_ERRNUM (ctx, obj_cmd_rs); goto cleanup; } *next_record_id = val; memcpy (record_buf, temp_record_buf, sdr_record_len); offset_into_record += sdr_record_len; goto out; } partial_read: reservation_id_retry_count = 0; while (!record_length) { uint8_t record_header_buf[IPMI_SDR_MAX_RECORD_LENGTH]; int sdr_record_header_len; if (ipmi_cmd_get_sdr (ipmi_ctx, *reservation_id, record_id, 0, sdr_record_header_length, obj_cmd_rs) < 0) { if (ipmi_ctx_errnum (ipmi_ctx) != IPMI_ERR_BAD_COMPLETION_CODE) { SDR_SET_ERRNUM (ctx, IPMI_SDR_ERR_IPMI_ERROR); goto cleanup; } else { uint8_t comp_code; if (FIID_OBJ_GET (obj_cmd_rs, "comp_code", &val) < 0) { SDR_FIID_OBJECT_ERROR_TO_SDR_ERRNUM (ctx, obj_cmd_rs); goto cleanup; } comp_code = val; if (comp_code == IPMI_COMP_CODE_RESERVATION_CANCELLED && (reservation_id_retry_count < IPMI_SDR_CACHE_MAX_RESERVATION_ID_RETRY)) { if (_sdr_cache_reservation_id (ctx, ipmi_ctx, reservation_id) < 0) goto cleanup; reservation_id_retry_count++; continue; } SDR_SET_ERRNUM (ctx, IPMI_SDR_ERR_IPMI_ERROR); goto cleanup; } } if ((sdr_record_header_len = fiid_obj_get_data (obj_cmd_rs, "record_data", record_header_buf, IPMI_SDR_MAX_RECORD_LENGTH)) < 0) { SDR_FIID_OBJECT_ERROR_TO_SDR_ERRNUM (ctx, obj_cmd_rs); goto cleanup; } if (sdr_record_header_len < sdr_record_header_length) { SDR_SET_ERRNUM (ctx, IPMI_SDR_ERR_IPMI_ERROR); goto cleanup; } if (fiid_obj_set_all (obj_sdr_record_header, record_header_buf, sdr_record_header_len) < 0) { SDR_FIID_OBJECT_ERROR_TO_SDR_ERRNUM (ctx, obj_sdr_record_header); goto cleanup; } if (FIID_OBJ_GET (obj_sdr_record_header, "record_length", &val) < 0) { SDR_FIID_OBJECT_ERROR_TO_SDR_ERRNUM (ctx, obj_sdr_record_header); goto cleanup; } if (sdr_record_header_len > record_buf_len) { SDR_SET_ERRNUM (ctx, IPMI_SDR_ERR_INTERNAL_ERROR); goto cleanup; } /* copy header into buf */ memcpy (record_buf, record_header_buf, sdr_record_header_len); offset_into_record += sdr_record_header_len; record_length = val + sdr_record_header_length; } if (record_length > record_buf_len) { SDR_SET_ERRNUM (ctx, IPMI_SDR_ERR_INTERNAL_ERROR); goto cleanup; } if (FIID_OBJ_GET (obj_cmd_rs, "next_record_id", &val) < 0) { SDR_FIID_OBJECT_ERROR_TO_SDR_ERRNUM (ctx, obj_cmd_rs); goto cleanup; } *next_record_id = val; reservation_id_retry_count = 0; while (offset_into_record < record_length) { int record_data_len; if ((record_length - offset_into_record) < bytes_to_read) bytes_to_read = record_length - offset_into_record; if (ipmi_cmd_get_sdr (ipmi_ctx, *reservation_id, record_id, offset_into_record, bytes_to_read, obj_cmd_rs) < 0) { if (ipmi_ctx_errnum (ipmi_ctx) != IPMI_ERR_BAD_COMPLETION_CODE) { SDR_SET_ERRNUM (ctx, IPMI_SDR_ERR_IPMI_ERROR); goto cleanup; } else { uint8_t comp_code; if (FIID_OBJ_GET (obj_cmd_rs, "comp_code", &val) < 0) { SDR_FIID_OBJECT_ERROR_TO_SDR_ERRNUM (ctx, obj_cmd_rs); goto cleanup; } comp_code = val; if (comp_code == IPMI_COMP_CODE_RESERVATION_CANCELLED && (reservation_id_retry_count < IPMI_SDR_CACHE_MAX_RESERVATION_ID_RETRY)) { if (_sdr_cache_reservation_id (ctx, ipmi_ctx, reservation_id) < 0) goto cleanup; reservation_id_retry_count++; continue; } else if ((comp_code == IPMI_COMP_CODE_CANNOT_RETURN_REQUESTED_NUMBER_OF_BYTES || comp_code == IPMI_COMP_CODE_UNSPECIFIED_ERROR) && bytes_to_read > sdr_record_header_length) { bytes_to_read -= IPMI_SDR_CACHE_BYTES_TO_READ_DECREMENT; if (bytes_to_read < sdr_record_header_length) bytes_to_read = sdr_record_header_length; continue; } SDR_SET_ERRNUM (ctx, IPMI_SDR_ERR_IPMI_ERROR); goto cleanup; } } if ((record_data_len = fiid_obj_get_data (obj_cmd_rs, "record_data", record_buf + offset_into_record, record_buf_len - offset_into_record)) < 0) { SDR_FIID_OBJECT_ERROR_TO_SDR_ERRNUM (ctx, obj_cmd_rs); goto cleanup; } offset_into_record += record_data_len; } out: rv = offset_into_record; cleanup: fiid_obj_destroy (obj_cmd_rs); fiid_obj_destroy (obj_sdr_record_header); return (rv); }