146470a38SPatrick Venture #pragma once 246470a38SPatrick Venture 346470a38SPatrick Venture #include <stdint.h> 446470a38SPatrick Venture 59cf85627SBrandon Kim #include <exception> 6e08fbffcSVernon Mauery #include <ipmid/api.hpp> 733250240SVernon Mauery #include <ipmid/types.hpp> 833250240SVernon Mauery 946470a38SPatrick Venture // IPMI commands for net functions. 1046470a38SPatrick Venture enum ipmi_netfn_sen_cmds 1146470a38SPatrick Venture { 123342a8e0SJia, Chunhui IPMI_CMD_PLATFORM_EVENT = 0x2, 1346470a38SPatrick Venture IPMI_CMD_GET_DEVICE_SDR_INFO = 0x20, 1446470a38SPatrick Venture IPMI_CMD_GET_DEVICE_SDR = 0x21, 1546470a38SPatrick Venture IPMI_CMD_RESERVE_DEVICE_SDR_REPO = 0x22, 1646470a38SPatrick Venture IPMI_CMD_GET_SENSOR_READING = 0x2D, 1746470a38SPatrick Venture IPMI_CMD_GET_SENSOR_TYPE = 0x2F, 1846470a38SPatrick Venture IPMI_CMD_SET_SENSOR = 0x30, 1946470a38SPatrick Venture IPMI_CMD_GET_SENSOR_THRESHOLDS = 0x27, 2046470a38SPatrick Venture }; 2146470a38SPatrick Venture 2246470a38SPatrick Venture /** 2346470a38SPatrick Venture * @enum device_type 2446470a38SPatrick Venture * IPMI FRU device types 2546470a38SPatrick Venture */ 2646470a38SPatrick Venture enum device_type 2746470a38SPatrick Venture { 2846470a38SPatrick Venture IPMI_PHYSICAL_FRU = 0x00, 2946470a38SPatrick Venture IPMI_LOGICAL_FRU = 0x80, 3046470a38SPatrick Venture }; 3146470a38SPatrick Venture 3246470a38SPatrick Venture // Discrete sensor types. 3346470a38SPatrick Venture enum ipmi_sensor_types 3446470a38SPatrick Venture { 3546470a38SPatrick Venture IPMI_SENSOR_TEMP = 0x01, 3646470a38SPatrick Venture IPMI_SENSOR_VOLTAGE = 0x02, 3746470a38SPatrick Venture IPMI_SENSOR_CURRENT = 0x03, 3846470a38SPatrick Venture IPMI_SENSOR_FAN = 0x04, 3946470a38SPatrick Venture IPMI_SENSOR_TPM = 0xCC, 4046470a38SPatrick Venture }; 4146470a38SPatrick Venture 429cf85627SBrandon Kim /** @brief Custom exception for reading sensors that are not funcitonal. 439cf85627SBrandon Kim */ 449cf85627SBrandon Kim struct SensorFunctionalError : public std::exception 459cf85627SBrandon Kim { 469cf85627SBrandon Kim const char* what() const noexcept 479cf85627SBrandon Kim { 489cf85627SBrandon Kim return "Sensor not functional"; 499cf85627SBrandon Kim } 509cf85627SBrandon Kim }; 519cf85627SBrandon Kim 5246470a38SPatrick Venture #define MAX_DBUS_PATH 128 5346470a38SPatrick Venture struct dbus_interface_t 5446470a38SPatrick Venture { 5546470a38SPatrick Venture uint8_t sensornumber; 5646470a38SPatrick Venture uint8_t sensortype; 5746470a38SPatrick Venture 5846470a38SPatrick Venture char bus[MAX_DBUS_PATH]; 5946470a38SPatrick Venture char path[MAX_DBUS_PATH]; 6046470a38SPatrick Venture char interface[MAX_DBUS_PATH]; 6146470a38SPatrick Venture }; 6246470a38SPatrick Venture 633342a8e0SJia, Chunhui struct PlatformEventRequest 643342a8e0SJia, Chunhui { 653342a8e0SJia, Chunhui uint8_t eventMessageRevision; 663342a8e0SJia, Chunhui uint8_t sensorType; 673342a8e0SJia, Chunhui uint8_t sensorNumber; 683342a8e0SJia, Chunhui uint8_t eventDirectionType; 693342a8e0SJia, Chunhui uint8_t data[3]; 703342a8e0SJia, Chunhui }; 713342a8e0SJia, Chunhui 723342a8e0SJia, Chunhui static constexpr char const* ipmiSELPath = "/xyz/openbmc_project/Logging/IPMI"; 733342a8e0SJia, Chunhui static constexpr char const* ipmiSELAddInterface = 743342a8e0SJia, Chunhui "xyz.openbmc_project.Logging.IPMI"; 753342a8e0SJia, Chunhui static const std::string ipmiSELAddMessage = "SEL Entry"; 763342a8e0SJia, Chunhui 773342a8e0SJia, Chunhui static constexpr int selSystemEventSizeWith3Bytes = 8; 783342a8e0SJia, Chunhui static constexpr int selSystemEventSizeWith2Bytes = 7; 793342a8e0SJia, Chunhui static constexpr int selSystemEventSizeWith1Bytes = 6; 803342a8e0SJia, Chunhui static constexpr int selIPMBEventSize = 7; 813342a8e0SJia, Chunhui static constexpr uint8_t directionMask = 0x80; 823342a8e0SJia, Chunhui static constexpr uint8_t byte3EnableMask = 0x30; 833342a8e0SJia, Chunhui static constexpr uint8_t byte2EnableMask = 0xC0; 843342a8e0SJia, Chunhui 8546470a38SPatrick Venture int set_sensor_dbus_state_s(uint8_t, const char*, const char*); 8646470a38SPatrick Venture int set_sensor_dbus_state_y(uint8_t, const char*, const uint8_t); 8746470a38SPatrick Venture int find_openbmc_path(uint8_t, dbus_interface_t*); 8846470a38SPatrick Venture 8946470a38SPatrick Venture ipmi_ret_t ipmi_sen_get_sdr(ipmi_netfn_t netfn, ipmi_cmd_t cmd, 9046470a38SPatrick Venture ipmi_request_t request, ipmi_response_t response, 9146470a38SPatrick Venture ipmi_data_len_t data_len, ipmi_context_t context); 9246470a38SPatrick Venture 93d957823eSjayaprakash Mutyala ipmi::RspType<uint16_t> ipmiSensorReserveSdr(); 9446470a38SPatrick Venture 9546470a38SPatrick Venture static const uint16_t FRU_RECORD_ID_START = 256; 969c11894eSJaghathiswari Rankappagounder Natarajan static const uint16_t ENTITY_RECORD_ID_START = 512; 9746470a38SPatrick Venture static const uint8_t SDR_VERSION = 0x51; 9846470a38SPatrick Venture static const uint16_t END_OF_RECORD = 0xFFFF; 9946470a38SPatrick Venture static const uint8_t LENGTH_MASK = 0x1F; 10046470a38SPatrick Venture 10146470a38SPatrick Venture /** 10246470a38SPatrick Venture * Get SDR Info 10346470a38SPatrick Venture */ 10446470a38SPatrick Venture 10546470a38SPatrick Venture namespace get_sdr_info 10646470a38SPatrick Venture { 10746470a38SPatrick Venture namespace request 10846470a38SPatrick Venture { 10946470a38SPatrick Venture // Note: for some reason the ipmi_request_t appears to be the 11046470a38SPatrick Venture // raw value for this call. 11146470a38SPatrick Venture inline bool get_count(void* req) 11246470a38SPatrick Venture { 11346470a38SPatrick Venture return (bool)((uint64_t)(req)&1); 11446470a38SPatrick Venture } 11546470a38SPatrick Venture } // namespace request 11646470a38SPatrick Venture } // namespace get_sdr_info 11746470a38SPatrick Venture 11846470a38SPatrick Venture /** 11946470a38SPatrick Venture * Get SDR 12046470a38SPatrick Venture */ 12146470a38SPatrick Venture namespace get_sdr 12246470a38SPatrick Venture { 12346470a38SPatrick Venture 12446470a38SPatrick Venture struct GetSdrReq 12546470a38SPatrick Venture { 12646470a38SPatrick Venture uint8_t reservation_id_lsb; 12746470a38SPatrick Venture uint8_t reservation_id_msb; 12846470a38SPatrick Venture uint8_t record_id_lsb; 12946470a38SPatrick Venture uint8_t record_id_msb; 13046470a38SPatrick Venture uint8_t offset; 13146470a38SPatrick Venture uint8_t bytes_to_read; 13246470a38SPatrick Venture } __attribute__((packed)); 13346470a38SPatrick Venture 13446470a38SPatrick Venture namespace request 13546470a38SPatrick Venture { 13646470a38SPatrick Venture 137e5c9d2fbSEmily Shaffer inline uint16_t get_reservation_id(GetSdrReq* req) 13846470a38SPatrick Venture { 13946470a38SPatrick Venture return (req->reservation_id_lsb + (req->reservation_id_msb << 8)); 14046470a38SPatrick Venture }; 14146470a38SPatrick Venture 14246470a38SPatrick Venture inline uint16_t get_record_id(GetSdrReq* req) 14346470a38SPatrick Venture { 14446470a38SPatrick Venture return (req->record_id_lsb + (req->record_id_msb << 8)); 14546470a38SPatrick Venture }; 14646470a38SPatrick Venture 14746470a38SPatrick Venture } // namespace request 14846470a38SPatrick Venture 14946470a38SPatrick Venture // Response 15046470a38SPatrick Venture struct GetSdrResp 15146470a38SPatrick Venture { 15246470a38SPatrick Venture uint8_t next_record_id_lsb; 15346470a38SPatrick Venture uint8_t next_record_id_msb; 15446470a38SPatrick Venture uint8_t record_data[64]; 15546470a38SPatrick Venture } __attribute__((packed)); 15646470a38SPatrick Venture 15746470a38SPatrick Venture namespace response 15846470a38SPatrick Venture { 15946470a38SPatrick Venture 16046470a38SPatrick Venture inline void set_next_record_id(uint16_t next, GetSdrResp* resp) 16146470a38SPatrick Venture { 16246470a38SPatrick Venture resp->next_record_id_lsb = next & 0xff; 16346470a38SPatrick Venture resp->next_record_id_msb = (next >> 8) & 0xff; 16446470a38SPatrick Venture }; 16546470a38SPatrick Venture 16646470a38SPatrick Venture } // namespace response 16746470a38SPatrick Venture 16846470a38SPatrick Venture // Record header 16946470a38SPatrick Venture struct SensorDataRecordHeader 17046470a38SPatrick Venture { 17146470a38SPatrick Venture uint8_t record_id_lsb; 17246470a38SPatrick Venture uint8_t record_id_msb; 17346470a38SPatrick Venture uint8_t sdr_version; 17446470a38SPatrick Venture uint8_t record_type; 17546470a38SPatrick Venture uint8_t record_length; // Length not counting the header 17646470a38SPatrick Venture } __attribute__((packed)); 17746470a38SPatrick Venture 17846470a38SPatrick Venture namespace header 17946470a38SPatrick Venture { 18046470a38SPatrick Venture 18146470a38SPatrick Venture inline void set_record_id(int id, SensorDataRecordHeader* hdr) 18246470a38SPatrick Venture { 18346470a38SPatrick Venture hdr->record_id_lsb = (id & 0xFF); 18446470a38SPatrick Venture hdr->record_id_msb = (id >> 8) & 0xFF; 18546470a38SPatrick Venture }; 18646470a38SPatrick Venture 18746470a38SPatrick Venture } // namespace header 18846470a38SPatrick Venture 18946470a38SPatrick Venture enum SensorDataRecordType 19046470a38SPatrick Venture { 19146470a38SPatrick Venture SENSOR_DATA_FULL_RECORD = 0x1, 1927b2e5504Sselvaganapathi SENSOR_DATA_COMPACT_RECORD = 0x2, 193da06d15cSHao Jiang SENSOR_DATA_EVENT_RECORD = 0x3, 1949c11894eSJaghathiswari Rankappagounder Natarajan SENSOR_DATA_ENTITY_RECORD = 0x8, 195*a3476273SHarvey Wu SENSOR_DATA_FRU_RECORD = 0x11, 196*a3476273SHarvey Wu SENSOR_DATA_MGMT_CTRL_LOCATOR = 0x12, 19746470a38SPatrick Venture }; 19846470a38SPatrick Venture 19946470a38SPatrick Venture // Record key 20046470a38SPatrick Venture struct SensorDataRecordKey 20146470a38SPatrick Venture { 20246470a38SPatrick Venture uint8_t owner_id; 20346470a38SPatrick Venture uint8_t owner_lun; 20446470a38SPatrick Venture uint8_t sensor_number; 20546470a38SPatrick Venture } __attribute__((packed)); 20646470a38SPatrick Venture 20746470a38SPatrick Venture /** @struct SensorDataFruRecordKey 20846470a38SPatrick Venture * 20946470a38SPatrick Venture * FRU Device Locator Record(key) - SDR Type 11 21046470a38SPatrick Venture */ 21146470a38SPatrick Venture struct SensorDataFruRecordKey 21246470a38SPatrick Venture { 21346470a38SPatrick Venture uint8_t deviceAddress; 21446470a38SPatrick Venture uint8_t fruID; 21546470a38SPatrick Venture uint8_t accessLun; 21646470a38SPatrick Venture uint8_t channelNumber; 21746470a38SPatrick Venture } __attribute__((packed)); 21846470a38SPatrick Venture 2199c11894eSJaghathiswari Rankappagounder Natarajan /** @struct SensorDataEntityRecordKey 2209c11894eSJaghathiswari Rankappagounder Natarajan * 2219c11894eSJaghathiswari Rankappagounder Natarajan * Entity Association Record(key) - SDR Type 8 2229c11894eSJaghathiswari Rankappagounder Natarajan */ 2239c11894eSJaghathiswari Rankappagounder Natarajan struct SensorDataEntityRecordKey 2249c11894eSJaghathiswari Rankappagounder Natarajan { 2259c11894eSJaghathiswari Rankappagounder Natarajan uint8_t containerEntityId; 2269c11894eSJaghathiswari Rankappagounder Natarajan uint8_t containerEntityInstance; 2279c11894eSJaghathiswari Rankappagounder Natarajan uint8_t flags; 2289c11894eSJaghathiswari Rankappagounder Natarajan uint8_t entityId1; 2299c11894eSJaghathiswari Rankappagounder Natarajan uint8_t entityInstance1; 2309c11894eSJaghathiswari Rankappagounder Natarajan } __attribute__((packed)); 2319c11894eSJaghathiswari Rankappagounder Natarajan 23246470a38SPatrick Venture namespace key 23346470a38SPatrick Venture { 23446470a38SPatrick Venture 2359c11894eSJaghathiswari Rankappagounder Natarajan static constexpr uint8_t listOrRangeBit = 7; 2369c11894eSJaghathiswari Rankappagounder Natarajan static constexpr uint8_t linkedBit = 6; 2379c11894eSJaghathiswari Rankappagounder Natarajan 23846470a38SPatrick Venture inline void set_owner_id_ipmb(SensorDataRecordKey* key) 23946470a38SPatrick Venture { 24046470a38SPatrick Venture key->owner_id &= ~0x01; 24146470a38SPatrick Venture }; 24246470a38SPatrick Venture 24346470a38SPatrick Venture inline void set_owner_id_system_sw(SensorDataRecordKey* key) 24446470a38SPatrick Venture { 24546470a38SPatrick Venture key->owner_id |= 0x01; 24646470a38SPatrick Venture }; 24746470a38SPatrick Venture 24846470a38SPatrick Venture inline void set_owner_id_bmc(SensorDataRecordKey* key) 24946470a38SPatrick Venture { 25046470a38SPatrick Venture key->owner_id |= 0x20; 25146470a38SPatrick Venture }; 25246470a38SPatrick Venture 25346470a38SPatrick Venture inline void set_owner_id_address(uint8_t addr, SensorDataRecordKey* key) 25446470a38SPatrick Venture { 25546470a38SPatrick Venture key->owner_id &= 0x01; 25646470a38SPatrick Venture key->owner_id |= addr << 1; 25746470a38SPatrick Venture }; 25846470a38SPatrick Venture 25946470a38SPatrick Venture inline void set_owner_lun(uint8_t lun, SensorDataRecordKey* key) 26046470a38SPatrick Venture { 26146470a38SPatrick Venture key->owner_lun &= ~0x03; 26246470a38SPatrick Venture key->owner_lun |= (lun & 0x03); 26346470a38SPatrick Venture }; 26446470a38SPatrick Venture 26546470a38SPatrick Venture inline void set_owner_lun_channel(uint8_t channel, SensorDataRecordKey* key) 26646470a38SPatrick Venture { 26746470a38SPatrick Venture key->owner_lun &= 0x0f; 26846470a38SPatrick Venture key->owner_lun |= ((channel & 0xf) << 4); 26946470a38SPatrick Venture }; 27046470a38SPatrick Venture 2719c11894eSJaghathiswari Rankappagounder Natarajan inline void set_flags(bool isList, bool isLinked, 2729c11894eSJaghathiswari Rankappagounder Natarajan SensorDataEntityRecordKey* key) 2739c11894eSJaghathiswari Rankappagounder Natarajan { 2749c11894eSJaghathiswari Rankappagounder Natarajan key->flags = 0x00; 2759c11894eSJaghathiswari Rankappagounder Natarajan if (!isList) 2769c11894eSJaghathiswari Rankappagounder Natarajan key->flags |= 1 << listOrRangeBit; 2779c11894eSJaghathiswari Rankappagounder Natarajan 2789c11894eSJaghathiswari Rankappagounder Natarajan if (isLinked) 2799c11894eSJaghathiswari Rankappagounder Natarajan key->flags |= 1 << linkedBit; 2809c11894eSJaghathiswari Rankappagounder Natarajan }; 2819c11894eSJaghathiswari Rankappagounder Natarajan 28246470a38SPatrick Venture } // namespace key 28346470a38SPatrick Venture 28446470a38SPatrick Venture /** @struct GetSensorThresholdsResponse 28546470a38SPatrick Venture * 28646470a38SPatrick Venture * Response structure for Get Sensor Thresholds command 28746470a38SPatrick Venture */ 28846470a38SPatrick Venture struct GetSensorThresholdsResponse 28946470a38SPatrick Venture { 29046470a38SPatrick Venture uint8_t validMask; //!< valid mask 29146470a38SPatrick Venture uint8_t lowerNonCritical; //!< lower non-critical threshold 29246470a38SPatrick Venture uint8_t lowerCritical; //!< lower critical threshold 29346470a38SPatrick Venture uint8_t lowerNonRecoverable; //!< lower non-recoverable threshold 29446470a38SPatrick Venture uint8_t upperNonCritical; //!< upper non-critical threshold 29546470a38SPatrick Venture uint8_t upperCritical; //!< upper critical threshold 29646470a38SPatrick Venture uint8_t upperNonRecoverable; //!< upper non-recoverable threshold 29746470a38SPatrick Venture } __attribute__((packed)); 29846470a38SPatrick Venture 29946470a38SPatrick Venture // Body - full record 30046470a38SPatrick Venture #define FULL_RECORD_ID_STR_MAX_LENGTH 16 30146470a38SPatrick Venture 30246470a38SPatrick Venture static const int FRU_RECORD_DEVICE_ID_MAX_LENGTH = 16; 30346470a38SPatrick Venture 30446470a38SPatrick Venture struct SensorDataFullRecordBody 30546470a38SPatrick Venture { 30646470a38SPatrick Venture uint8_t entity_id; 30746470a38SPatrick Venture uint8_t entity_instance; 30846470a38SPatrick Venture uint8_t sensor_initialization; 30946470a38SPatrick Venture uint8_t sensor_capabilities; // no macro support 31046470a38SPatrick Venture uint8_t sensor_type; 31146470a38SPatrick Venture uint8_t event_reading_type; 31246470a38SPatrick Venture uint8_t supported_assertions[2]; // no macro support 31346470a38SPatrick Venture uint8_t supported_deassertions[2]; // no macro support 31446470a38SPatrick Venture uint8_t discrete_reading_setting_mask[2]; // no macro support 31546470a38SPatrick Venture uint8_t sensor_units_1; 31646470a38SPatrick Venture uint8_t sensor_units_2_base; 31746470a38SPatrick Venture uint8_t sensor_units_3_modifier; 31846470a38SPatrick Venture uint8_t linearization; 31946470a38SPatrick Venture uint8_t m_lsb; 32046470a38SPatrick Venture uint8_t m_msb_and_tolerance; 32146470a38SPatrick Venture uint8_t b_lsb; 32246470a38SPatrick Venture uint8_t b_msb_and_accuracy_lsb; 32346470a38SPatrick Venture uint8_t accuracy_and_sensor_direction; 32446470a38SPatrick Venture uint8_t r_b_exponents; 32546470a38SPatrick Venture uint8_t analog_characteristic_flags; // no macro support 32646470a38SPatrick Venture uint8_t nominal_reading; 32746470a38SPatrick Venture uint8_t normal_max; 32846470a38SPatrick Venture uint8_t normal_min; 32946470a38SPatrick Venture uint8_t sensor_max; 33046470a38SPatrick Venture uint8_t sensor_min; 33146470a38SPatrick Venture uint8_t upper_nonrecoverable_threshold; 33246470a38SPatrick Venture uint8_t upper_critical_threshold; 33346470a38SPatrick Venture uint8_t upper_noncritical_threshold; 33446470a38SPatrick Venture uint8_t lower_nonrecoverable_threshold; 33546470a38SPatrick Venture uint8_t lower_critical_threshold; 33646470a38SPatrick Venture uint8_t lower_noncritical_threshold; 33746470a38SPatrick Venture uint8_t positive_threshold_hysteresis; 33846470a38SPatrick Venture uint8_t negative_threshold_hysteresis; 33946470a38SPatrick Venture uint16_t reserved; 34046470a38SPatrick Venture uint8_t oem_reserved; 34146470a38SPatrick Venture uint8_t id_string_info; 34246470a38SPatrick Venture char id_string[FULL_RECORD_ID_STR_MAX_LENGTH]; 34346470a38SPatrick Venture } __attribute__((packed)); 34446470a38SPatrick Venture 3457b2e5504Sselvaganapathi /** @struct SensorDataCompactRecord 3467b2e5504Sselvaganapathi * 3477b2e5504Sselvaganapathi * Compact Sensor Record(body) - SDR Type 2 3487b2e5504Sselvaganapathi */ 3497b2e5504Sselvaganapathi struct SensorDataCompactRecordBody 3507b2e5504Sselvaganapathi { 3517b2e5504Sselvaganapathi uint8_t entity_id; 3527b2e5504Sselvaganapathi uint8_t entity_instance; 3537b2e5504Sselvaganapathi uint8_t sensor_initialization; 3547b2e5504Sselvaganapathi uint8_t sensor_capabilities; // no macro support 3557b2e5504Sselvaganapathi uint8_t sensor_type; 3567b2e5504Sselvaganapathi uint8_t event_reading_type; 3577b2e5504Sselvaganapathi uint8_t supported_assertions[2]; // no macro support 3587b2e5504Sselvaganapathi uint8_t supported_deassertions[2]; // no macro support 3597b2e5504Sselvaganapathi uint8_t discrete_reading_setting_mask[2]; // no macro support 3607b2e5504Sselvaganapathi uint8_t sensor_units_1; 3617b2e5504Sselvaganapathi uint8_t sensor_units_2_base; 3627b2e5504Sselvaganapathi uint8_t sensor_units_3_modifier; 3637b2e5504Sselvaganapathi uint8_t record_sharing[2]; 3647b2e5504Sselvaganapathi uint8_t positive_threshold_hysteresis; 3657b2e5504Sselvaganapathi uint8_t negative_threshold_hysteresis; 3667b2e5504Sselvaganapathi uint8_t reserved[3]; 3677b2e5504Sselvaganapathi uint8_t oem_reserved; 3687b2e5504Sselvaganapathi uint8_t id_string_info; 3697b2e5504Sselvaganapathi char id_string[FULL_RECORD_ID_STR_MAX_LENGTH]; 3707b2e5504Sselvaganapathi } __attribute__((packed)); 3717b2e5504Sselvaganapathi 372da06d15cSHao Jiang /** @struct SensorDataEventRecord 373da06d15cSHao Jiang * 374da06d15cSHao Jiang * Event Only Sensor Record(body) - SDR Type 3 375da06d15cSHao Jiang */ 376da06d15cSHao Jiang struct SensorDataEventRecordBody 377da06d15cSHao Jiang { 378da06d15cSHao Jiang uint8_t entity_id; 379da06d15cSHao Jiang uint8_t entity_instance; 380da06d15cSHao Jiang uint8_t sensor_type; 381da06d15cSHao Jiang uint8_t event_reading_type; 382da06d15cSHao Jiang uint8_t sensor_record_sharing_1; 383da06d15cSHao Jiang uint8_t sensor_record_sharing_2; 384da06d15cSHao Jiang uint8_t reserved; 385da06d15cSHao Jiang uint8_t oem_reserved; 386da06d15cSHao Jiang uint8_t id_string_info; 387da06d15cSHao Jiang char id_string[FULL_RECORD_ID_STR_MAX_LENGTH]; 388da06d15cSHao Jiang } __attribute__((packed)); 389da06d15cSHao Jiang 39046470a38SPatrick Venture /** @struct SensorDataFruRecordBody 39146470a38SPatrick Venture * 39246470a38SPatrick Venture * FRU Device Locator Record(body) - SDR Type 11 39346470a38SPatrick Venture */ 39446470a38SPatrick Venture struct SensorDataFruRecordBody 39546470a38SPatrick Venture { 39646470a38SPatrick Venture uint8_t reserved; 39746470a38SPatrick Venture uint8_t deviceType; 39846470a38SPatrick Venture uint8_t deviceTypeModifier; 39946470a38SPatrick Venture uint8_t entityID; 40046470a38SPatrick Venture uint8_t entityInstance; 40146470a38SPatrick Venture uint8_t oem; 40246470a38SPatrick Venture uint8_t deviceIDLen; 40346470a38SPatrick Venture char deviceID[FRU_RECORD_DEVICE_ID_MAX_LENGTH]; 40446470a38SPatrick Venture } __attribute__((packed)); 40546470a38SPatrick Venture 4069c11894eSJaghathiswari Rankappagounder Natarajan /** @struct SensorDataEntityRecordBody 4079c11894eSJaghathiswari Rankappagounder Natarajan * 4089c11894eSJaghathiswari Rankappagounder Natarajan * Entity Association Record(body) - SDR Type 8 4099c11894eSJaghathiswari Rankappagounder Natarajan */ 4109c11894eSJaghathiswari Rankappagounder Natarajan struct SensorDataEntityRecordBody 4119c11894eSJaghathiswari Rankappagounder Natarajan { 4129c11894eSJaghathiswari Rankappagounder Natarajan uint8_t entityId2; 4139c11894eSJaghathiswari Rankappagounder Natarajan uint8_t entityInstance2; 4149c11894eSJaghathiswari Rankappagounder Natarajan uint8_t entityId3; 4159c11894eSJaghathiswari Rankappagounder Natarajan uint8_t entityInstance3; 4169c11894eSJaghathiswari Rankappagounder Natarajan uint8_t entityId4; 4179c11894eSJaghathiswari Rankappagounder Natarajan uint8_t entityInstance4; 4189c11894eSJaghathiswari Rankappagounder Natarajan } __attribute__((packed)); 4199c11894eSJaghathiswari Rankappagounder Natarajan 42046470a38SPatrick Venture namespace body 42146470a38SPatrick Venture { 42246470a38SPatrick Venture 42346470a38SPatrick Venture inline void set_entity_instance_number(uint8_t n, 42446470a38SPatrick Venture SensorDataFullRecordBody* body) 42546470a38SPatrick Venture { 42646470a38SPatrick Venture body->entity_instance &= 1 << 7; 42746470a38SPatrick Venture body->entity_instance |= (n & ~(1 << 7)); 42846470a38SPatrick Venture }; 42946470a38SPatrick Venture inline void set_entity_physical_entity(SensorDataFullRecordBody* body) 43046470a38SPatrick Venture { 43146470a38SPatrick Venture body->entity_instance &= ~(1 << 7); 43246470a38SPatrick Venture }; 43346470a38SPatrick Venture inline void set_entity_logical_container(SensorDataFullRecordBody* body) 43446470a38SPatrick Venture { 43546470a38SPatrick Venture body->entity_instance |= 1 << 7; 43646470a38SPatrick Venture }; 43746470a38SPatrick Venture 43846470a38SPatrick Venture inline void sensor_scanning_state(bool enabled, SensorDataFullRecordBody* body) 43946470a38SPatrick Venture { 44046470a38SPatrick Venture if (enabled) 44146470a38SPatrick Venture { 44246470a38SPatrick Venture body->sensor_initialization |= 1 << 0; 44346470a38SPatrick Venture } 44446470a38SPatrick Venture else 44546470a38SPatrick Venture { 44646470a38SPatrick Venture body->sensor_initialization &= ~(1 << 0); 44746470a38SPatrick Venture }; 44846470a38SPatrick Venture }; 44946470a38SPatrick Venture inline void event_generation_state(bool enabled, SensorDataFullRecordBody* body) 45046470a38SPatrick Venture { 45146470a38SPatrick Venture if (enabled) 45246470a38SPatrick Venture { 45346470a38SPatrick Venture body->sensor_initialization |= 1 << 1; 45446470a38SPatrick Venture } 45546470a38SPatrick Venture else 45646470a38SPatrick Venture { 45746470a38SPatrick Venture body->sensor_initialization &= ~(1 << 1); 45846470a38SPatrick Venture } 45946470a38SPatrick Venture }; 46046470a38SPatrick Venture inline void init_types_state(bool enabled, SensorDataFullRecordBody* body) 46146470a38SPatrick Venture { 46246470a38SPatrick Venture if (enabled) 46346470a38SPatrick Venture { 46446470a38SPatrick Venture body->sensor_initialization |= 1 << 2; 46546470a38SPatrick Venture } 46646470a38SPatrick Venture else 46746470a38SPatrick Venture { 46846470a38SPatrick Venture body->sensor_initialization &= ~(1 << 2); 46946470a38SPatrick Venture } 47046470a38SPatrick Venture }; 47146470a38SPatrick Venture inline void init_hyst_state(bool enabled, SensorDataFullRecordBody* body) 47246470a38SPatrick Venture { 47346470a38SPatrick Venture if (enabled) 47446470a38SPatrick Venture { 47546470a38SPatrick Venture body->sensor_initialization |= 1 << 3; 47646470a38SPatrick Venture } 47746470a38SPatrick Venture else 47846470a38SPatrick Venture { 47946470a38SPatrick Venture body->sensor_initialization &= ~(1 << 3); 48046470a38SPatrick Venture } 48146470a38SPatrick Venture }; 48246470a38SPatrick Venture inline void init_thresh_state(bool enabled, SensorDataFullRecordBody* body) 48346470a38SPatrick Venture { 48446470a38SPatrick Venture if (enabled) 48546470a38SPatrick Venture { 48646470a38SPatrick Venture body->sensor_initialization |= 1 << 4; 48746470a38SPatrick Venture } 48846470a38SPatrick Venture else 48946470a38SPatrick Venture { 49046470a38SPatrick Venture body->sensor_initialization &= ~(1 << 4); 49146470a38SPatrick Venture } 49246470a38SPatrick Venture }; 49346470a38SPatrick Venture inline void init_events_state(bool enabled, SensorDataFullRecordBody* body) 49446470a38SPatrick Venture { 49546470a38SPatrick Venture if (enabled) 49646470a38SPatrick Venture { 49746470a38SPatrick Venture body->sensor_initialization |= 1 << 5; 49846470a38SPatrick Venture } 49946470a38SPatrick Venture else 50046470a38SPatrick Venture { 50146470a38SPatrick Venture body->sensor_initialization &= ~(1 << 5); 50246470a38SPatrick Venture } 50346470a38SPatrick Venture }; 50446470a38SPatrick Venture inline void init_scanning_state(bool enabled, SensorDataFullRecordBody* body) 50546470a38SPatrick Venture { 50646470a38SPatrick Venture if (enabled) 50746470a38SPatrick Venture { 50846470a38SPatrick Venture body->sensor_initialization |= 1 << 6; 50946470a38SPatrick Venture } 51046470a38SPatrick Venture else 51146470a38SPatrick Venture { 51246470a38SPatrick Venture body->sensor_initialization &= ~(1 << 6); 51346470a38SPatrick Venture } 51446470a38SPatrick Venture }; 51546470a38SPatrick Venture inline void init_settable_state(bool enabled, SensorDataFullRecordBody* body) 51646470a38SPatrick Venture { 51746470a38SPatrick Venture if (enabled) 51846470a38SPatrick Venture { 51946470a38SPatrick Venture body->sensor_initialization |= 1 << 7; 52046470a38SPatrick Venture } 52146470a38SPatrick Venture else 52246470a38SPatrick Venture { 52346470a38SPatrick Venture body->sensor_initialization &= ~(1 << 7); 52446470a38SPatrick Venture } 52546470a38SPatrick Venture }; 52646470a38SPatrick Venture 52746470a38SPatrick Venture inline void set_percentage(SensorDataFullRecordBody* body) 52846470a38SPatrick Venture { 52946470a38SPatrick Venture body->sensor_units_1 |= 1 << 0; 53046470a38SPatrick Venture }; 53146470a38SPatrick Venture inline void unset_percentage(SensorDataFullRecordBody* body) 53246470a38SPatrick Venture { 53346470a38SPatrick Venture body->sensor_units_1 &= ~(1 << 0); 53446470a38SPatrick Venture }; 53546470a38SPatrick Venture inline void set_modifier_operation(uint8_t op, SensorDataFullRecordBody* body) 53646470a38SPatrick Venture { 53746470a38SPatrick Venture body->sensor_units_1 &= ~(3 << 1); 53846470a38SPatrick Venture body->sensor_units_1 |= (op & 0x3) << 1; 53946470a38SPatrick Venture }; 54046470a38SPatrick Venture inline void set_rate_unit(uint8_t unit, SensorDataFullRecordBody* body) 54146470a38SPatrick Venture { 54246470a38SPatrick Venture body->sensor_units_1 &= ~(7 << 3); 54346470a38SPatrick Venture body->sensor_units_1 |= (unit & 0x7) << 3; 54446470a38SPatrick Venture }; 54546470a38SPatrick Venture inline void set_analog_data_format(uint8_t format, 54646470a38SPatrick Venture SensorDataFullRecordBody* body) 54746470a38SPatrick Venture { 54846470a38SPatrick Venture body->sensor_units_1 &= ~(3 << 6); 54946470a38SPatrick Venture body->sensor_units_1 |= (format & 0x3) << 6; 55046470a38SPatrick Venture }; 55146470a38SPatrick Venture 55246470a38SPatrick Venture inline void set_m(uint16_t m, SensorDataFullRecordBody* body) 55346470a38SPatrick Venture { 55446470a38SPatrick Venture body->m_lsb = m & 0xff; 55546470a38SPatrick Venture body->m_msb_and_tolerance &= ~(3 << 6); 55646470a38SPatrick Venture body->m_msb_and_tolerance |= ((m & (3 << 8)) >> 2); 55746470a38SPatrick Venture }; 55846470a38SPatrick Venture inline void set_tolerance(uint8_t tol, SensorDataFullRecordBody* body) 55946470a38SPatrick Venture { 56046470a38SPatrick Venture body->m_msb_and_tolerance &= ~0x3f; 56146470a38SPatrick Venture body->m_msb_and_tolerance |= tol & 0x3f; 56246470a38SPatrick Venture }; 56346470a38SPatrick Venture 56446470a38SPatrick Venture inline void set_b(uint16_t b, SensorDataFullRecordBody* body) 56546470a38SPatrick Venture { 56646470a38SPatrick Venture body->b_lsb = b & 0xff; 56746470a38SPatrick Venture body->b_msb_and_accuracy_lsb &= ~(3 << 6); 56846470a38SPatrick Venture body->b_msb_and_accuracy_lsb |= ((b & (3 << 8)) >> 2); 56946470a38SPatrick Venture }; 57046470a38SPatrick Venture inline void set_accuracy(uint16_t acc, SensorDataFullRecordBody* body) 57146470a38SPatrick Venture { 57246470a38SPatrick Venture // bottom 6 bits 57346470a38SPatrick Venture body->b_msb_and_accuracy_lsb &= ~0x3f; 57446470a38SPatrick Venture body->b_msb_and_accuracy_lsb |= acc & 0x3f; 57546470a38SPatrick Venture // top 4 bits 57646470a38SPatrick Venture body->accuracy_and_sensor_direction &= 0x0f; 57746470a38SPatrick Venture body->accuracy_and_sensor_direction |= ((acc >> 6) & 0xf) << 4; 57846470a38SPatrick Venture }; 57946470a38SPatrick Venture inline void set_accuracy_exp(uint8_t exp, SensorDataFullRecordBody* body) 58046470a38SPatrick Venture { 58146470a38SPatrick Venture body->accuracy_and_sensor_direction &= ~(3 << 2); 58246470a38SPatrick Venture body->accuracy_and_sensor_direction |= (exp & 3) << 2; 58346470a38SPatrick Venture }; 58446470a38SPatrick Venture inline void set_sensor_dir(uint8_t dir, SensorDataFullRecordBody* body) 58546470a38SPatrick Venture { 58646470a38SPatrick Venture body->accuracy_and_sensor_direction &= ~(3 << 0); 58746470a38SPatrick Venture body->accuracy_and_sensor_direction |= (dir & 3); 58846470a38SPatrick Venture }; 58946470a38SPatrick Venture 59046470a38SPatrick Venture inline void set_b_exp(uint8_t exp, SensorDataFullRecordBody* body) 59146470a38SPatrick Venture { 59246470a38SPatrick Venture body->r_b_exponents &= 0xf0; 59346470a38SPatrick Venture body->r_b_exponents |= exp & 0x0f; 59446470a38SPatrick Venture }; 59546470a38SPatrick Venture inline void set_r_exp(uint8_t exp, SensorDataFullRecordBody* body) 59646470a38SPatrick Venture { 59746470a38SPatrick Venture body->r_b_exponents &= 0x0f; 59846470a38SPatrick Venture body->r_b_exponents |= (exp & 0x0f) << 4; 59946470a38SPatrick Venture }; 60046470a38SPatrick Venture 60146470a38SPatrick Venture inline void set_id_strlen(uint8_t len, SensorDataFullRecordBody* body) 60246470a38SPatrick Venture { 60346470a38SPatrick Venture body->id_string_info &= ~(0x1f); 60446470a38SPatrick Venture body->id_string_info |= len & 0x1f; 60546470a38SPatrick Venture }; 606eae8859cSWilly Tu inline void set_id_strlen(uint8_t len, SensorDataEventRecordBody* body) 607eae8859cSWilly Tu { 608eae8859cSWilly Tu body->id_string_info &= ~(0x1f); 609eae8859cSWilly Tu body->id_string_info |= len & 0x1f; 610eae8859cSWilly Tu }; 61146470a38SPatrick Venture inline uint8_t get_id_strlen(SensorDataFullRecordBody* body) 61246470a38SPatrick Venture { 61346470a38SPatrick Venture return body->id_string_info & 0x1f; 61446470a38SPatrick Venture }; 61546470a38SPatrick Venture inline void set_id_type(uint8_t type, SensorDataFullRecordBody* body) 61646470a38SPatrick Venture { 61746470a38SPatrick Venture body->id_string_info &= ~(3 << 6); 61846470a38SPatrick Venture body->id_string_info |= (type & 0x3) << 6; 61946470a38SPatrick Venture }; 620eae8859cSWilly Tu inline void set_id_type(uint8_t type, SensorDataEventRecordBody* body) 621eae8859cSWilly Tu { 622eae8859cSWilly Tu body->id_string_info &= ~(3 << 6); 623eae8859cSWilly Tu body->id_string_info |= (type & 0x3) << 6; 624eae8859cSWilly Tu }; 62546470a38SPatrick Venture 62646470a38SPatrick Venture inline void set_device_id_strlen(uint8_t len, SensorDataFruRecordBody* body) 62746470a38SPatrick Venture { 62846470a38SPatrick Venture body->deviceIDLen &= ~(LENGTH_MASK); 62946470a38SPatrick Venture body->deviceIDLen |= len & LENGTH_MASK; 63046470a38SPatrick Venture }; 63146470a38SPatrick Venture 63246470a38SPatrick Venture inline uint8_t get_device_id_strlen(SensorDataFruRecordBody* body) 63346470a38SPatrick Venture { 63446470a38SPatrick Venture return body->deviceIDLen & LENGTH_MASK; 63546470a38SPatrick Venture }; 63646470a38SPatrick Venture 63746470a38SPatrick Venture inline void set_readable_mask(uint8_t mask, SensorDataFullRecordBody* body) 63846470a38SPatrick Venture { 63946470a38SPatrick Venture body->discrete_reading_setting_mask[1] = mask & 0x3F; 64046470a38SPatrick Venture } 64146470a38SPatrick Venture 64246470a38SPatrick Venture } // namespace body 64346470a38SPatrick Venture 64446470a38SPatrick Venture // More types contained in section 43.17 Sensor Unit Type Codes, 64546470a38SPatrick Venture // IPMI spec v2 rev 1.1 64646470a38SPatrick Venture enum SensorUnitTypeCodes 64746470a38SPatrick Venture { 64846470a38SPatrick Venture SENSOR_UNIT_UNSPECIFIED = 0, 64946470a38SPatrick Venture SENSOR_UNIT_DEGREES_C = 1, 65046470a38SPatrick Venture SENSOR_UNIT_VOLTS = 4, 65146470a38SPatrick Venture SENSOR_UNIT_AMPERES = 5, 65246470a38SPatrick Venture SENSOR_UNIT_WATTS = 6, 65346470a38SPatrick Venture SENSOR_UNIT_JOULES = 7, 654812e44c7SKirill Pakhomov SENSOR_UNIT_RPM = 18, 65546470a38SPatrick Venture SENSOR_UNIT_METERS = 34, 65646470a38SPatrick Venture SENSOR_UNIT_REVOLUTIONS = 41, 65746470a38SPatrick Venture }; 65846470a38SPatrick Venture 65946470a38SPatrick Venture struct SensorDataFullRecord 66046470a38SPatrick Venture { 66146470a38SPatrick Venture SensorDataRecordHeader header; 66246470a38SPatrick Venture SensorDataRecordKey key; 66346470a38SPatrick Venture SensorDataFullRecordBody body; 66446470a38SPatrick Venture } __attribute__((packed)); 66546470a38SPatrick Venture 6667b2e5504Sselvaganapathi /** @struct SensorDataComapactRecord 6677b2e5504Sselvaganapathi * 6687b2e5504Sselvaganapathi * Compact Sensor Record - SDR Type 2 6697b2e5504Sselvaganapathi */ 6707b2e5504Sselvaganapathi struct SensorDataCompactRecord 6717b2e5504Sselvaganapathi { 6727b2e5504Sselvaganapathi SensorDataRecordHeader header; 6737b2e5504Sselvaganapathi SensorDataRecordKey key; 6747b2e5504Sselvaganapathi SensorDataCompactRecordBody body; 6757b2e5504Sselvaganapathi } __attribute__((packed)); 6767b2e5504Sselvaganapathi 677da06d15cSHao Jiang /** @struct SensorDataEventRecord 678da06d15cSHao Jiang * 679da06d15cSHao Jiang * Event Only Sensor Record - SDR Type 3 680da06d15cSHao Jiang */ 681da06d15cSHao Jiang struct SensorDataEventRecord 682da06d15cSHao Jiang { 683da06d15cSHao Jiang SensorDataRecordHeader header; 684da06d15cSHao Jiang SensorDataRecordKey key; 685da06d15cSHao Jiang SensorDataEventRecordBody body; 686da06d15cSHao Jiang } __attribute__((packed)); 687da06d15cSHao Jiang 68846470a38SPatrick Venture /** @struct SensorDataFruRecord 68946470a38SPatrick Venture * 69046470a38SPatrick Venture * FRU Device Locator Record - SDR Type 11 69146470a38SPatrick Venture */ 69246470a38SPatrick Venture struct SensorDataFruRecord 69346470a38SPatrick Venture { 69446470a38SPatrick Venture SensorDataRecordHeader header; 69546470a38SPatrick Venture SensorDataFruRecordKey key; 69646470a38SPatrick Venture SensorDataFruRecordBody body; 69746470a38SPatrick Venture } __attribute__((packed)); 69846470a38SPatrick Venture 6999c11894eSJaghathiswari Rankappagounder Natarajan /** @struct SensorDataEntityRecord 7009c11894eSJaghathiswari Rankappagounder Natarajan * 7019c11894eSJaghathiswari Rankappagounder Natarajan * Entity Association Record - SDR Type 8 7029c11894eSJaghathiswari Rankappagounder Natarajan */ 7039c11894eSJaghathiswari Rankappagounder Natarajan struct SensorDataEntityRecord 7049c11894eSJaghathiswari Rankappagounder Natarajan { 7059c11894eSJaghathiswari Rankappagounder Natarajan SensorDataRecordHeader header; 7069c11894eSJaghathiswari Rankappagounder Natarajan SensorDataEntityRecordKey key; 7079c11894eSJaghathiswari Rankappagounder Natarajan SensorDataEntityRecordBody body; 7089c11894eSJaghathiswari Rankappagounder Natarajan } __attribute__((packed)); 7099c11894eSJaghathiswari Rankappagounder Natarajan 71046470a38SPatrick Venture } // namespace get_sdr 71146470a38SPatrick Venture 71246470a38SPatrick Venture namespace ipmi 71346470a38SPatrick Venture { 71446470a38SPatrick Venture 71546470a38SPatrick Venture namespace sensor 71646470a38SPatrick Venture { 71746470a38SPatrick Venture 71846470a38SPatrick Venture /** 71946470a38SPatrick Venture * @brief Map offset to the corresponding bit in the assertion byte. 72046470a38SPatrick Venture * 72146470a38SPatrick Venture * The discrete sensors support up to 14 states. 0-7 offsets are stored in one 72246470a38SPatrick Venture * byte and offsets 8-14 in the second byte. 72346470a38SPatrick Venture * 72446470a38SPatrick Venture * @param[in] offset - offset number. 72546470a38SPatrick Venture * @param[in/out] resp - get sensor reading response. 72646470a38SPatrick Venture */ 7274cc42556SSui Chen inline void setOffset(uint8_t offset, ipmi::sensor::GetSensorResponse* resp) 72846470a38SPatrick Venture { 72946470a38SPatrick Venture if (offset > 7) 73046470a38SPatrick Venture { 7314cc42556SSui Chen resp->discreteReadingSensorStates |= 1 << (offset - 8); 73246470a38SPatrick Venture } 73346470a38SPatrick Venture else 73446470a38SPatrick Venture { 7354cc42556SSui Chen resp->thresholdLevelsStates |= 1 << offset; 73646470a38SPatrick Venture } 73746470a38SPatrick Venture } 73846470a38SPatrick Venture 73946470a38SPatrick Venture /** 74046470a38SPatrick Venture * @brief Set the reading field in the response. 74146470a38SPatrick Venture * 74246470a38SPatrick Venture * @param[in] offset - offset number. 74346470a38SPatrick Venture * @param[in/out] resp - get sensor reading response. 74446470a38SPatrick Venture */ 7454cc42556SSui Chen inline void setReading(uint8_t value, ipmi::sensor::GetSensorResponse* resp) 74646470a38SPatrick Venture { 74746470a38SPatrick Venture resp->reading = value; 74846470a38SPatrick Venture } 74946470a38SPatrick Venture 75046470a38SPatrick Venture /** 75146470a38SPatrick Venture * @brief Map the value to the assertion bytes. The assertion states are stored 75246470a38SPatrick Venture * in 2 bytes. 75346470a38SPatrick Venture * 75446470a38SPatrick Venture * @param[in] value - value to mapped to the assertion byte. 75546470a38SPatrick Venture * @param[in/out] resp - get sensor reading response. 75646470a38SPatrick Venture */ 75746470a38SPatrick Venture inline void setAssertionBytes(uint16_t value, 7584cc42556SSui Chen ipmi::sensor::GetSensorResponse* resp) 75946470a38SPatrick Venture { 7604cc42556SSui Chen resp->thresholdLevelsStates = static_cast<uint8_t>(value & 0x00FF); 7614cc42556SSui Chen resp->discreteReadingSensorStates = static_cast<uint8_t>(value >> 8); 76246470a38SPatrick Venture } 76346470a38SPatrick Venture 76446470a38SPatrick Venture /** 76546470a38SPatrick Venture * @brief Set the scanning enabled bit in the response. 76646470a38SPatrick Venture * 76746470a38SPatrick Venture * @param[in/out] resp - get sensor reading response. 76846470a38SPatrick Venture */ 7694cc42556SSui Chen inline void enableScanning(ipmi::sensor::GetSensorResponse* resp) 77046470a38SPatrick Venture { 7714cc42556SSui Chen resp->readingOrStateUnavailable = false; 7724cc42556SSui Chen resp->scanningEnabled = true; 7734cc42556SSui Chen resp->allEventMessagesEnabled = false; 77446470a38SPatrick Venture } 77546470a38SPatrick Venture 77646470a38SPatrick Venture } // namespace sensor 77746470a38SPatrick Venture 77846470a38SPatrick Venture } // namespace ipmi 779