Patrick Venture | 46470a3 | 2018-09-07 19:26:25 -0700 | [diff] [blame] | 1 | #pragma once |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 2 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 3 | #include <stdint.h> |
| 4 | |
Brandon Kim | 9cf8562 | 2019-06-19 12:05:08 -0700 | [diff] [blame] | 5 | #include <exception> |
Vernon Mauery | e08fbff | 2019-04-03 09:19:34 -0700 | [diff] [blame] | 6 | #include <ipmid/api.hpp> |
Vernon Mauery | 3325024 | 2019-03-12 16:49:26 -0700 | [diff] [blame] | 7 | #include <ipmid/types.hpp> |
| 8 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 9 | // IPMI commands for net functions. |
| 10 | enum ipmi_netfn_sen_cmds |
| 11 | { |
Jia, Chunhui | 3342a8e | 2018-12-29 13:32:26 +0800 | [diff] [blame] | 12 | IPMI_CMD_PLATFORM_EVENT = 0x2, |
Tom Joseph | 5ca5095 | 2018-02-22 00:33:38 +0530 | [diff] [blame] | 13 | IPMI_CMD_GET_DEVICE_SDR_INFO = 0x20, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 14 | IPMI_CMD_GET_DEVICE_SDR = 0x21, |
| 15 | IPMI_CMD_RESERVE_DEVICE_SDR_REPO = 0x22, |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 16 | IPMI_CMD_GET_SENSOR_READING = 0x2D, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 17 | IPMI_CMD_GET_SENSOR_TYPE = 0x2F, |
| 18 | IPMI_CMD_SET_SENSOR = 0x30, |
Dhruvaraj Subhashchandran | 5c0beec | 2018-01-23 04:47:06 -0600 | [diff] [blame] | 19 | IPMI_CMD_GET_SENSOR_THRESHOLDS = 0x27, |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 20 | }; |
| 21 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 22 | /** |
| 23 | * @enum device_type |
| 24 | * IPMI FRU device types |
| 25 | */ |
| 26 | enum device_type |
| 27 | { |
| 28 | IPMI_PHYSICAL_FRU = 0x00, |
| 29 | IPMI_LOGICAL_FRU = 0x80, |
| 30 | }; |
| 31 | |
Emily Shaffer | 1fabf22 | 2017-04-05 08:53:21 -0700 | [diff] [blame] | 32 | // Discrete sensor types. |
| 33 | enum ipmi_sensor_types |
| 34 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 35 | IPMI_SENSOR_TEMP = 0x01, |
Emily Shaffer | 1fabf22 | 2017-04-05 08:53:21 -0700 | [diff] [blame] | 36 | IPMI_SENSOR_VOLTAGE = 0x02, |
| 37 | IPMI_SENSOR_CURRENT = 0x03, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 38 | IPMI_SENSOR_FAN = 0x04, |
| 39 | IPMI_SENSOR_TPM = 0xCC, |
Emily Shaffer | 1fabf22 | 2017-04-05 08:53:21 -0700 | [diff] [blame] | 40 | }; |
| 41 | |
Brandon Kim | 9cf8562 | 2019-06-19 12:05:08 -0700 | [diff] [blame] | 42 | /** @brief Custom exception for reading sensors that are not funcitonal. |
| 43 | */ |
| 44 | struct SensorFunctionalError : public std::exception |
| 45 | { |
| 46 | const char* what() const noexcept |
| 47 | { |
| 48 | return "Sensor not functional"; |
| 49 | } |
| 50 | }; |
| 51 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 52 | #define MAX_DBUS_PATH 128 |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 53 | struct dbus_interface_t |
| 54 | { |
| 55 | uint8_t sensornumber; |
| 56 | uint8_t sensortype; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 57 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 58 | char bus[MAX_DBUS_PATH]; |
| 59 | char path[MAX_DBUS_PATH]; |
| 60 | char interface[MAX_DBUS_PATH]; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 61 | }; |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 62 | |
Jia, Chunhui | 3342a8e | 2018-12-29 13:32:26 +0800 | [diff] [blame] | 63 | struct PlatformEventRequest |
| 64 | { |
| 65 | uint8_t eventMessageRevision; |
| 66 | uint8_t sensorType; |
| 67 | uint8_t sensorNumber; |
| 68 | uint8_t eventDirectionType; |
| 69 | uint8_t data[3]; |
| 70 | }; |
| 71 | |
| 72 | static constexpr char const* ipmiSELPath = "/xyz/openbmc_project/Logging/IPMI"; |
| 73 | static constexpr char const* ipmiSELAddInterface = |
| 74 | "xyz.openbmc_project.Logging.IPMI"; |
| 75 | static const std::string ipmiSELAddMessage = "SEL Entry"; |
| 76 | |
| 77 | static constexpr int selSystemEventSizeWith3Bytes = 8; |
| 78 | static constexpr int selSystemEventSizeWith2Bytes = 7; |
| 79 | static constexpr int selSystemEventSizeWith1Bytes = 6; |
| 80 | static constexpr int selIPMBEventSize = 7; |
| 81 | static constexpr uint8_t directionMask = 0x80; |
| 82 | static constexpr uint8_t byte3EnableMask = 0x30; |
| 83 | static constexpr uint8_t byte2EnableMask = 0xC0; |
| 84 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 85 | int set_sensor_dbus_state_s(uint8_t, const char*, const char*); |
| 86 | int set_sensor_dbus_state_y(uint8_t, const char*, const uint8_t); |
| 87 | int find_openbmc_path(uint8_t, dbus_interface_t*); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 88 | |
Tom Joseph | 5ca5095 | 2018-02-22 00:33:38 +0530 | [diff] [blame] | 89 | ipmi_ret_t ipmi_sen_get_sdr(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 90 | ipmi_request_t request, ipmi_response_t response, |
| 91 | ipmi_data_len_t data_len, ipmi_context_t context); |
| 92 | |
jayaprakash Mutyala | d957823 | 2019-05-13 20:22:50 +0000 | [diff] [blame] | 93 | ipmi::RspType<uint16_t> ipmiSensorReserveSdr(); |
Tom Joseph | 5ca5095 | 2018-02-22 00:33:38 +0530 | [diff] [blame] | 94 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 95 | static const uint16_t FRU_RECORD_ID_START = 256; |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 96 | static const uint16_t ENTITY_RECORD_ID_START = 512; |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 97 | static const uint8_t SDR_VERSION = 0x51; |
| 98 | static const uint16_t END_OF_RECORD = 0xFFFF; |
| 99 | static const uint8_t LENGTH_MASK = 0x1F; |
| 100 | |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 101 | /** |
Emily Shaffer | d06e0e7 | 2017-04-05 09:08:57 -0700 | [diff] [blame] | 102 | * Get SDR Info |
| 103 | */ |
| 104 | |
| 105 | namespace get_sdr_info |
| 106 | { |
| 107 | namespace request |
| 108 | { |
| 109 | // Note: for some reason the ipmi_request_t appears to be the |
| 110 | // raw value for this call. |
| 111 | inline bool get_count(void* req) |
| 112 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 113 | return (bool)((uint64_t)(req)&1); |
Emily Shaffer | d06e0e7 | 2017-04-05 09:08:57 -0700 | [diff] [blame] | 114 | } |
| 115 | } // namespace request |
Emily Shaffer | d06e0e7 | 2017-04-05 09:08:57 -0700 | [diff] [blame] | 116 | } // namespace get_sdr_info |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 117 | |
| 118 | /** |
| 119 | * Get SDR |
| 120 | */ |
| 121 | namespace get_sdr |
| 122 | { |
| 123 | |
| 124 | struct GetSdrReq |
| 125 | { |
| 126 | uint8_t reservation_id_lsb; |
| 127 | uint8_t reservation_id_msb; |
| 128 | uint8_t record_id_lsb; |
| 129 | uint8_t record_id_msb; |
| 130 | uint8_t offset; |
| 131 | uint8_t bytes_to_read; |
| 132 | } __attribute__((packed)); |
| 133 | |
| 134 | namespace request |
| 135 | { |
| 136 | |
Emily Shaffer | e5c9d2f | 2019-06-25 14:26:45 -0700 | [diff] [blame] | 137 | inline uint16_t get_reservation_id(GetSdrReq* req) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 138 | { |
| 139 | return (req->reservation_id_lsb + (req->reservation_id_msb << 8)); |
| 140 | }; |
| 141 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 142 | inline uint16_t get_record_id(GetSdrReq* req) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 143 | { |
| 144 | return (req->record_id_lsb + (req->record_id_msb << 8)); |
| 145 | }; |
| 146 | |
| 147 | } // namespace request |
| 148 | |
| 149 | // Response |
| 150 | struct GetSdrResp |
| 151 | { |
| 152 | uint8_t next_record_id_lsb; |
| 153 | uint8_t next_record_id_msb; |
| 154 | uint8_t record_data[64]; |
| 155 | } __attribute__((packed)); |
| 156 | |
| 157 | namespace response |
| 158 | { |
| 159 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 160 | inline void set_next_record_id(uint16_t next, GetSdrResp* resp) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 161 | { |
| 162 | resp->next_record_id_lsb = next & 0xff; |
| 163 | resp->next_record_id_msb = (next >> 8) & 0xff; |
| 164 | }; |
| 165 | |
| 166 | } // namespace response |
| 167 | |
| 168 | // Record header |
| 169 | struct SensorDataRecordHeader |
| 170 | { |
| 171 | uint8_t record_id_lsb; |
| 172 | uint8_t record_id_msb; |
| 173 | uint8_t sdr_version; |
| 174 | uint8_t record_type; |
| 175 | uint8_t record_length; // Length not counting the header |
| 176 | } __attribute__((packed)); |
| 177 | |
| 178 | namespace header |
| 179 | { |
| 180 | |
| 181 | inline void set_record_id(int id, SensorDataRecordHeader* hdr) |
| 182 | { |
| 183 | hdr->record_id_lsb = (id & 0xFF); |
| 184 | hdr->record_id_msb = (id >> 8) & 0xFF; |
| 185 | }; |
| 186 | |
| 187 | } // namespace header |
| 188 | |
| 189 | enum SensorDataRecordType |
| 190 | { |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 191 | SENSOR_DATA_FULL_RECORD = 0x1, |
selvaganapathi | 7b2e550 | 2023-02-14 07:10:47 +0530 | [diff] [blame] | 192 | SENSOR_DATA_COMPACT_RECORD = 0x2, |
Hao Jiang | da06d15 | 2021-01-19 15:27:43 -0800 | [diff] [blame] | 193 | SENSOR_DATA_EVENT_RECORD = 0x3, |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 194 | SENSOR_DATA_ENTITY_RECORD = 0x8, |
Harvey Wu | a347627 | 2023-03-22 10:09:38 +0800 | [diff] [blame^] | 195 | SENSOR_DATA_FRU_RECORD = 0x11, |
| 196 | SENSOR_DATA_MGMT_CTRL_LOCATOR = 0x12, |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 197 | }; |
| 198 | |
| 199 | // Record key |
| 200 | struct SensorDataRecordKey |
| 201 | { |
| 202 | uint8_t owner_id; |
| 203 | uint8_t owner_lun; |
| 204 | uint8_t sensor_number; |
| 205 | } __attribute__((packed)); |
| 206 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 207 | /** @struct SensorDataFruRecordKey |
| 208 | * |
| 209 | * FRU Device Locator Record(key) - SDR Type 11 |
| 210 | */ |
| 211 | struct SensorDataFruRecordKey |
| 212 | { |
| 213 | uint8_t deviceAddress; |
| 214 | uint8_t fruID; |
| 215 | uint8_t accessLun; |
| 216 | uint8_t channelNumber; |
| 217 | } __attribute__((packed)); |
| 218 | |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 219 | /** @struct SensorDataEntityRecordKey |
| 220 | * |
| 221 | * Entity Association Record(key) - SDR Type 8 |
| 222 | */ |
| 223 | struct SensorDataEntityRecordKey |
| 224 | { |
| 225 | uint8_t containerEntityId; |
| 226 | uint8_t containerEntityInstance; |
| 227 | uint8_t flags; |
| 228 | uint8_t entityId1; |
| 229 | uint8_t entityInstance1; |
| 230 | } __attribute__((packed)); |
| 231 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 232 | namespace key |
| 233 | { |
| 234 | |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 235 | static constexpr uint8_t listOrRangeBit = 7; |
| 236 | static constexpr uint8_t linkedBit = 6; |
| 237 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 238 | inline void set_owner_id_ipmb(SensorDataRecordKey* key) |
| 239 | { |
| 240 | key->owner_id &= ~0x01; |
| 241 | }; |
| 242 | |
| 243 | inline void set_owner_id_system_sw(SensorDataRecordKey* key) |
| 244 | { |
| 245 | key->owner_id |= 0x01; |
| 246 | }; |
| 247 | |
Tom Joseph | 9642391 | 2018-01-25 00:14:34 +0530 | [diff] [blame] | 248 | inline void set_owner_id_bmc(SensorDataRecordKey* key) |
| 249 | { |
| 250 | key->owner_id |= 0x20; |
| 251 | }; |
| 252 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 253 | inline void set_owner_id_address(uint8_t addr, SensorDataRecordKey* key) |
| 254 | { |
| 255 | key->owner_id &= 0x01; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 256 | key->owner_id |= addr << 1; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 257 | }; |
| 258 | |
| 259 | inline void set_owner_lun(uint8_t lun, SensorDataRecordKey* key) |
| 260 | { |
| 261 | key->owner_lun &= ~0x03; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 262 | key->owner_lun |= (lun & 0x03); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 263 | }; |
| 264 | |
| 265 | inline void set_owner_lun_channel(uint8_t channel, SensorDataRecordKey* key) |
| 266 | { |
| 267 | key->owner_lun &= 0x0f; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 268 | key->owner_lun |= ((channel & 0xf) << 4); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 269 | }; |
| 270 | |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 271 | inline void set_flags(bool isList, bool isLinked, |
| 272 | SensorDataEntityRecordKey* key) |
| 273 | { |
| 274 | key->flags = 0x00; |
| 275 | if (!isList) |
| 276 | key->flags |= 1 << listOrRangeBit; |
| 277 | |
| 278 | if (isLinked) |
| 279 | key->flags |= 1 << linkedBit; |
| 280 | }; |
| 281 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 282 | } // namespace key |
| 283 | |
Dhruvaraj Subhashchandran | 5c0beec | 2018-01-23 04:47:06 -0600 | [diff] [blame] | 284 | /** @struct GetSensorThresholdsResponse |
| 285 | * |
| 286 | * Response structure for Get Sensor Thresholds command |
| 287 | */ |
| 288 | struct GetSensorThresholdsResponse |
| 289 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 290 | uint8_t validMask; //!< valid mask |
| 291 | uint8_t lowerNonCritical; //!< lower non-critical threshold |
| 292 | uint8_t lowerCritical; //!< lower critical threshold |
| 293 | uint8_t lowerNonRecoverable; //!< lower non-recoverable threshold |
| 294 | uint8_t upperNonCritical; //!< upper non-critical threshold |
| 295 | uint8_t upperCritical; //!< upper critical threshold |
| 296 | uint8_t upperNonRecoverable; //!< upper non-recoverable threshold |
Dhruvaraj Subhashchandran | 5c0beec | 2018-01-23 04:47:06 -0600 | [diff] [blame] | 297 | } __attribute__((packed)); |
| 298 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 299 | // Body - full record |
| 300 | #define FULL_RECORD_ID_STR_MAX_LENGTH 16 |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 301 | |
| 302 | static const int FRU_RECORD_DEVICE_ID_MAX_LENGTH = 16; |
| 303 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 304 | struct SensorDataFullRecordBody |
| 305 | { |
| 306 | uint8_t entity_id; |
| 307 | uint8_t entity_instance; |
| 308 | uint8_t sensor_initialization; |
| 309 | uint8_t sensor_capabilities; // no macro support |
| 310 | uint8_t sensor_type; |
| 311 | uint8_t event_reading_type; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 312 | uint8_t supported_assertions[2]; // no macro support |
| 313 | uint8_t supported_deassertions[2]; // no macro support |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 314 | uint8_t discrete_reading_setting_mask[2]; // no macro support |
| 315 | uint8_t sensor_units_1; |
| 316 | uint8_t sensor_units_2_base; |
| 317 | uint8_t sensor_units_3_modifier; |
| 318 | uint8_t linearization; |
| 319 | uint8_t m_lsb; |
| 320 | uint8_t m_msb_and_tolerance; |
| 321 | uint8_t b_lsb; |
| 322 | uint8_t b_msb_and_accuracy_lsb; |
| 323 | uint8_t accuracy_and_sensor_direction; |
| 324 | uint8_t r_b_exponents; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 325 | uint8_t analog_characteristic_flags; // no macro support |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 326 | uint8_t nominal_reading; |
| 327 | uint8_t normal_max; |
| 328 | uint8_t normal_min; |
| 329 | uint8_t sensor_max; |
| 330 | uint8_t sensor_min; |
| 331 | uint8_t upper_nonrecoverable_threshold; |
| 332 | uint8_t upper_critical_threshold; |
| 333 | uint8_t upper_noncritical_threshold; |
| 334 | uint8_t lower_nonrecoverable_threshold; |
| 335 | uint8_t lower_critical_threshold; |
| 336 | uint8_t lower_noncritical_threshold; |
| 337 | uint8_t positive_threshold_hysteresis; |
| 338 | uint8_t negative_threshold_hysteresis; |
| 339 | uint16_t reserved; |
| 340 | uint8_t oem_reserved; |
| 341 | uint8_t id_string_info; |
Emily Shaffer | 10f4959 | 2017-05-10 12:01:10 -0700 | [diff] [blame] | 342 | char id_string[FULL_RECORD_ID_STR_MAX_LENGTH]; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 343 | } __attribute__((packed)); |
| 344 | |
selvaganapathi | 7b2e550 | 2023-02-14 07:10:47 +0530 | [diff] [blame] | 345 | /** @struct SensorDataCompactRecord |
| 346 | * |
| 347 | * Compact Sensor Record(body) - SDR Type 2 |
| 348 | */ |
| 349 | struct SensorDataCompactRecordBody |
| 350 | { |
| 351 | uint8_t entity_id; |
| 352 | uint8_t entity_instance; |
| 353 | uint8_t sensor_initialization; |
| 354 | uint8_t sensor_capabilities; // no macro support |
| 355 | uint8_t sensor_type; |
| 356 | uint8_t event_reading_type; |
| 357 | uint8_t supported_assertions[2]; // no macro support |
| 358 | uint8_t supported_deassertions[2]; // no macro support |
| 359 | uint8_t discrete_reading_setting_mask[2]; // no macro support |
| 360 | uint8_t sensor_units_1; |
| 361 | uint8_t sensor_units_2_base; |
| 362 | uint8_t sensor_units_3_modifier; |
| 363 | uint8_t record_sharing[2]; |
| 364 | uint8_t positive_threshold_hysteresis; |
| 365 | uint8_t negative_threshold_hysteresis; |
| 366 | uint8_t reserved[3]; |
| 367 | uint8_t oem_reserved; |
| 368 | uint8_t id_string_info; |
| 369 | char id_string[FULL_RECORD_ID_STR_MAX_LENGTH]; |
| 370 | } __attribute__((packed)); |
| 371 | |
Hao Jiang | da06d15 | 2021-01-19 15:27:43 -0800 | [diff] [blame] | 372 | /** @struct SensorDataEventRecord |
| 373 | * |
| 374 | * Event Only Sensor Record(body) - SDR Type 3 |
| 375 | */ |
| 376 | struct SensorDataEventRecordBody |
| 377 | { |
| 378 | uint8_t entity_id; |
| 379 | uint8_t entity_instance; |
| 380 | uint8_t sensor_type; |
| 381 | uint8_t event_reading_type; |
| 382 | uint8_t sensor_record_sharing_1; |
| 383 | uint8_t sensor_record_sharing_2; |
| 384 | uint8_t reserved; |
| 385 | uint8_t oem_reserved; |
| 386 | uint8_t id_string_info; |
| 387 | char id_string[FULL_RECORD_ID_STR_MAX_LENGTH]; |
| 388 | } __attribute__((packed)); |
| 389 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 390 | /** @struct SensorDataFruRecordBody |
| 391 | * |
| 392 | * FRU Device Locator Record(body) - SDR Type 11 |
| 393 | */ |
| 394 | struct SensorDataFruRecordBody |
| 395 | { |
| 396 | uint8_t reserved; |
| 397 | uint8_t deviceType; |
| 398 | uint8_t deviceTypeModifier; |
| 399 | uint8_t entityID; |
| 400 | uint8_t entityInstance; |
| 401 | uint8_t oem; |
| 402 | uint8_t deviceIDLen; |
| 403 | char deviceID[FRU_RECORD_DEVICE_ID_MAX_LENGTH]; |
| 404 | } __attribute__((packed)); |
| 405 | |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 406 | /** @struct SensorDataEntityRecordBody |
| 407 | * |
| 408 | * Entity Association Record(body) - SDR Type 8 |
| 409 | */ |
| 410 | struct SensorDataEntityRecordBody |
| 411 | { |
| 412 | uint8_t entityId2; |
| 413 | uint8_t entityInstance2; |
| 414 | uint8_t entityId3; |
| 415 | uint8_t entityInstance3; |
| 416 | uint8_t entityId4; |
| 417 | uint8_t entityInstance4; |
| 418 | } __attribute__((packed)); |
| 419 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 420 | namespace body |
| 421 | { |
| 422 | |
| 423 | inline void set_entity_instance_number(uint8_t n, |
| 424 | SensorDataFullRecordBody* body) |
| 425 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 426 | body->entity_instance &= 1 << 7; |
| 427 | body->entity_instance |= (n & ~(1 << 7)); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 428 | }; |
| 429 | inline void set_entity_physical_entity(SensorDataFullRecordBody* body) |
| 430 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 431 | body->entity_instance &= ~(1 << 7); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 432 | }; |
| 433 | inline void set_entity_logical_container(SensorDataFullRecordBody* body) |
| 434 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 435 | body->entity_instance |= 1 << 7; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 436 | }; |
| 437 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 438 | inline void sensor_scanning_state(bool enabled, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 439 | { |
| 440 | if (enabled) |
| 441 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 442 | body->sensor_initialization |= 1 << 0; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 443 | } |
| 444 | else |
| 445 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 446 | body->sensor_initialization &= ~(1 << 0); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 447 | }; |
| 448 | }; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 449 | inline void event_generation_state(bool enabled, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 450 | { |
| 451 | if (enabled) |
| 452 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 453 | body->sensor_initialization |= 1 << 1; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 454 | } |
| 455 | else |
| 456 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 457 | body->sensor_initialization &= ~(1 << 1); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 458 | } |
| 459 | }; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 460 | inline void init_types_state(bool enabled, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 461 | { |
| 462 | if (enabled) |
| 463 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 464 | body->sensor_initialization |= 1 << 2; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 465 | } |
| 466 | else |
| 467 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 468 | body->sensor_initialization &= ~(1 << 2); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 469 | } |
| 470 | }; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 471 | inline void init_hyst_state(bool enabled, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 472 | { |
| 473 | if (enabled) |
| 474 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 475 | body->sensor_initialization |= 1 << 3; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 476 | } |
| 477 | else |
| 478 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 479 | body->sensor_initialization &= ~(1 << 3); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 480 | } |
| 481 | }; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 482 | inline void init_thresh_state(bool enabled, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 483 | { |
| 484 | if (enabled) |
| 485 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 486 | body->sensor_initialization |= 1 << 4; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 487 | } |
| 488 | else |
| 489 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 490 | body->sensor_initialization &= ~(1 << 4); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 491 | } |
| 492 | }; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 493 | inline void init_events_state(bool enabled, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 494 | { |
| 495 | if (enabled) |
| 496 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 497 | body->sensor_initialization |= 1 << 5; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 498 | } |
| 499 | else |
| 500 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 501 | body->sensor_initialization &= ~(1 << 5); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 502 | } |
| 503 | }; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 504 | inline void init_scanning_state(bool enabled, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 505 | { |
| 506 | if (enabled) |
| 507 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 508 | body->sensor_initialization |= 1 << 6; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 509 | } |
| 510 | else |
| 511 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 512 | body->sensor_initialization &= ~(1 << 6); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 513 | } |
| 514 | }; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 515 | inline void init_settable_state(bool enabled, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 516 | { |
| 517 | if (enabled) |
| 518 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 519 | body->sensor_initialization |= 1 << 7; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 520 | } |
| 521 | else |
| 522 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 523 | body->sensor_initialization &= ~(1 << 7); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 524 | } |
| 525 | }; |
| 526 | |
| 527 | inline void set_percentage(SensorDataFullRecordBody* body) |
| 528 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 529 | body->sensor_units_1 |= 1 << 0; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 530 | }; |
| 531 | inline void unset_percentage(SensorDataFullRecordBody* body) |
| 532 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 533 | body->sensor_units_1 &= ~(1 << 0); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 534 | }; |
| 535 | inline void set_modifier_operation(uint8_t op, SensorDataFullRecordBody* body) |
| 536 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 537 | body->sensor_units_1 &= ~(3 << 1); |
| 538 | body->sensor_units_1 |= (op & 0x3) << 1; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 539 | }; |
| 540 | inline void set_rate_unit(uint8_t unit, SensorDataFullRecordBody* body) |
| 541 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 542 | body->sensor_units_1 &= ~(7 << 3); |
| 543 | body->sensor_units_1 |= (unit & 0x7) << 3; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 544 | }; |
| 545 | inline void set_analog_data_format(uint8_t format, |
| 546 | SensorDataFullRecordBody* body) |
| 547 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 548 | body->sensor_units_1 &= ~(3 << 6); |
| 549 | body->sensor_units_1 |= (format & 0x3) << 6; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 550 | }; |
| 551 | |
Emily Shaffer | 7cad3fc | 2017-08-30 17:50:37 -0700 | [diff] [blame] | 552 | inline void set_m(uint16_t m, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 553 | { |
| 554 | body->m_lsb = m & 0xff; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 555 | body->m_msb_and_tolerance &= ~(3 << 6); |
| 556 | body->m_msb_and_tolerance |= ((m & (3 << 8)) >> 2); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 557 | }; |
| 558 | inline void set_tolerance(uint8_t tol, SensorDataFullRecordBody* body) |
| 559 | { |
| 560 | body->m_msb_and_tolerance &= ~0x3f; |
| 561 | body->m_msb_and_tolerance |= tol & 0x3f; |
| 562 | }; |
| 563 | |
Emily Shaffer | 7cad3fc | 2017-08-30 17:50:37 -0700 | [diff] [blame] | 564 | inline void set_b(uint16_t b, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 565 | { |
| 566 | body->b_lsb = b & 0xff; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 567 | body->b_msb_and_accuracy_lsb &= ~(3 << 6); |
| 568 | body->b_msb_and_accuracy_lsb |= ((b & (3 << 8)) >> 2); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 569 | }; |
Emily Shaffer | 7cad3fc | 2017-08-30 17:50:37 -0700 | [diff] [blame] | 570 | inline void set_accuracy(uint16_t acc, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 571 | { |
Emily Shaffer | 7cad3fc | 2017-08-30 17:50:37 -0700 | [diff] [blame] | 572 | // bottom 6 bits |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 573 | body->b_msb_and_accuracy_lsb &= ~0x3f; |
| 574 | body->b_msb_and_accuracy_lsb |= acc & 0x3f; |
Emily Shaffer | 7cad3fc | 2017-08-30 17:50:37 -0700 | [diff] [blame] | 575 | // top 4 bits |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 576 | body->accuracy_and_sensor_direction &= 0x0f; |
Emily Shaffer | 7cad3fc | 2017-08-30 17:50:37 -0700 | [diff] [blame] | 577 | body->accuracy_and_sensor_direction |= ((acc >> 6) & 0xf) << 4; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 578 | }; |
| 579 | inline void set_accuracy_exp(uint8_t exp, SensorDataFullRecordBody* body) |
| 580 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 581 | body->accuracy_and_sensor_direction &= ~(3 << 2); |
| 582 | body->accuracy_and_sensor_direction |= (exp & 3) << 2; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 583 | }; |
| 584 | inline void set_sensor_dir(uint8_t dir, SensorDataFullRecordBody* body) |
| 585 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 586 | body->accuracy_and_sensor_direction &= ~(3 << 0); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 587 | body->accuracy_and_sensor_direction |= (dir & 3); |
| 588 | }; |
| 589 | |
| 590 | inline void set_b_exp(uint8_t exp, SensorDataFullRecordBody* body) |
| 591 | { |
| 592 | body->r_b_exponents &= 0xf0; |
| 593 | body->r_b_exponents |= exp & 0x0f; |
| 594 | }; |
| 595 | inline void set_r_exp(uint8_t exp, SensorDataFullRecordBody* body) |
| 596 | { |
| 597 | body->r_b_exponents &= 0x0f; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 598 | body->r_b_exponents |= (exp & 0x0f) << 4; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 599 | }; |
| 600 | |
| 601 | inline void set_id_strlen(uint8_t len, SensorDataFullRecordBody* body) |
| 602 | { |
| 603 | body->id_string_info &= ~(0x1f); |
| 604 | body->id_string_info |= len & 0x1f; |
| 605 | }; |
Willy Tu | eae8859 | 2022-12-13 14:28:02 -0800 | [diff] [blame] | 606 | inline void set_id_strlen(uint8_t len, SensorDataEventRecordBody* body) |
| 607 | { |
| 608 | body->id_string_info &= ~(0x1f); |
| 609 | body->id_string_info |= len & 0x1f; |
| 610 | }; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 611 | inline uint8_t get_id_strlen(SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 612 | { |
| 613 | return body->id_string_info & 0x1f; |
| 614 | }; |
| 615 | inline void set_id_type(uint8_t type, SensorDataFullRecordBody* body) |
| 616 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 617 | body->id_string_info &= ~(3 << 6); |
| 618 | body->id_string_info |= (type & 0x3) << 6; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 619 | }; |
Willy Tu | eae8859 | 2022-12-13 14:28:02 -0800 | [diff] [blame] | 620 | inline void set_id_type(uint8_t type, SensorDataEventRecordBody* body) |
| 621 | { |
| 622 | body->id_string_info &= ~(3 << 6); |
| 623 | body->id_string_info |= (type & 0x3) << 6; |
| 624 | }; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 625 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 626 | inline void set_device_id_strlen(uint8_t len, SensorDataFruRecordBody* body) |
| 627 | { |
| 628 | body->deviceIDLen &= ~(LENGTH_MASK); |
| 629 | body->deviceIDLen |= len & LENGTH_MASK; |
| 630 | }; |
| 631 | |
| 632 | inline uint8_t get_device_id_strlen(SensorDataFruRecordBody* body) |
| 633 | { |
| 634 | return body->deviceIDLen & LENGTH_MASK; |
| 635 | }; |
| 636 | |
Tom Joseph | dc212b2 | 2018-02-16 09:59:57 +0530 | [diff] [blame] | 637 | inline void set_readable_mask(uint8_t mask, SensorDataFullRecordBody* body) |
| 638 | { |
| 639 | body->discrete_reading_setting_mask[1] = mask & 0x3F; |
| 640 | } |
| 641 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 642 | } // namespace body |
| 643 | |
| 644 | // More types contained in section 43.17 Sensor Unit Type Codes, |
| 645 | // IPMI spec v2 rev 1.1 |
| 646 | enum SensorUnitTypeCodes |
| 647 | { |
| 648 | SENSOR_UNIT_UNSPECIFIED = 0, |
| 649 | SENSOR_UNIT_DEGREES_C = 1, |
| 650 | SENSOR_UNIT_VOLTS = 4, |
| 651 | SENSOR_UNIT_AMPERES = 5, |
Tom Joseph | dc212b2 | 2018-02-16 09:59:57 +0530 | [diff] [blame] | 652 | SENSOR_UNIT_WATTS = 6, |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 653 | SENSOR_UNIT_JOULES = 7, |
Kirill Pakhomov | 812e44c | 2018-10-22 16:25:35 +0300 | [diff] [blame] | 654 | SENSOR_UNIT_RPM = 18, |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 655 | SENSOR_UNIT_METERS = 34, |
| 656 | SENSOR_UNIT_REVOLUTIONS = 41, |
| 657 | }; |
| 658 | |
| 659 | struct SensorDataFullRecord |
| 660 | { |
| 661 | SensorDataRecordHeader header; |
| 662 | SensorDataRecordKey key; |
| 663 | SensorDataFullRecordBody body; |
| 664 | } __attribute__((packed)); |
| 665 | |
selvaganapathi | 7b2e550 | 2023-02-14 07:10:47 +0530 | [diff] [blame] | 666 | /** @struct SensorDataComapactRecord |
| 667 | * |
| 668 | * Compact Sensor Record - SDR Type 2 |
| 669 | */ |
| 670 | struct SensorDataCompactRecord |
| 671 | { |
| 672 | SensorDataRecordHeader header; |
| 673 | SensorDataRecordKey key; |
| 674 | SensorDataCompactRecordBody body; |
| 675 | } __attribute__((packed)); |
| 676 | |
Hao Jiang | da06d15 | 2021-01-19 15:27:43 -0800 | [diff] [blame] | 677 | /** @struct SensorDataEventRecord |
| 678 | * |
| 679 | * Event Only Sensor Record - SDR Type 3 |
| 680 | */ |
| 681 | struct SensorDataEventRecord |
| 682 | { |
| 683 | SensorDataRecordHeader header; |
| 684 | SensorDataRecordKey key; |
| 685 | SensorDataEventRecordBody body; |
| 686 | } __attribute__((packed)); |
| 687 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 688 | /** @struct SensorDataFruRecord |
| 689 | * |
| 690 | * FRU Device Locator Record - SDR Type 11 |
| 691 | */ |
| 692 | struct SensorDataFruRecord |
| 693 | { |
| 694 | SensorDataRecordHeader header; |
| 695 | SensorDataFruRecordKey key; |
| 696 | SensorDataFruRecordBody body; |
| 697 | } __attribute__((packed)); |
| 698 | |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 699 | /** @struct SensorDataEntityRecord |
| 700 | * |
| 701 | * Entity Association Record - SDR Type 8 |
| 702 | */ |
| 703 | struct SensorDataEntityRecord |
| 704 | { |
| 705 | SensorDataRecordHeader header; |
| 706 | SensorDataEntityRecordKey key; |
| 707 | SensorDataEntityRecordBody body; |
| 708 | } __attribute__((packed)); |
| 709 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 710 | } // namespace get_sdr |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 711 | |
| 712 | namespace ipmi |
| 713 | { |
| 714 | |
| 715 | namespace sensor |
| 716 | { |
| 717 | |
| 718 | /** |
| 719 | * @brief Map offset to the corresponding bit in the assertion byte. |
| 720 | * |
Gunnar Mills | 8991dd6 | 2017-10-25 17:11:29 -0500 | [diff] [blame] | 721 | * The discrete sensors support up to 14 states. 0-7 offsets are stored in one |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 722 | * byte and offsets 8-14 in the second byte. |
| 723 | * |
| 724 | * @param[in] offset - offset number. |
| 725 | * @param[in/out] resp - get sensor reading response. |
| 726 | */ |
Sui Chen | 4cc4255 | 2019-09-11 10:28:35 -0700 | [diff] [blame] | 727 | inline void setOffset(uint8_t offset, ipmi::sensor::GetSensorResponse* resp) |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 728 | { |
| 729 | if (offset > 7) |
| 730 | { |
Sui Chen | 4cc4255 | 2019-09-11 10:28:35 -0700 | [diff] [blame] | 731 | resp->discreteReadingSensorStates |= 1 << (offset - 8); |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 732 | } |
| 733 | else |
| 734 | { |
Sui Chen | 4cc4255 | 2019-09-11 10:28:35 -0700 | [diff] [blame] | 735 | resp->thresholdLevelsStates |= 1 << offset; |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 736 | } |
| 737 | } |
| 738 | |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 739 | /** |
| 740 | * @brief Set the reading field in the response. |
| 741 | * |
| 742 | * @param[in] offset - offset number. |
| 743 | * @param[in/out] resp - get sensor reading response. |
| 744 | */ |
Sui Chen | 4cc4255 | 2019-09-11 10:28:35 -0700 | [diff] [blame] | 745 | inline void setReading(uint8_t value, ipmi::sensor::GetSensorResponse* resp) |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 746 | { |
| 747 | resp->reading = value; |
| 748 | } |
| 749 | |
Tom Joseph | 295f17e | 2017-09-07 00:09:46 +0530 | [diff] [blame] | 750 | /** |
| 751 | * @brief Map the value to the assertion bytes. The assertion states are stored |
| 752 | * in 2 bytes. |
| 753 | * |
| 754 | * @param[in] value - value to mapped to the assertion byte. |
| 755 | * @param[in/out] resp - get sensor reading response. |
| 756 | */ |
| 757 | inline void setAssertionBytes(uint16_t value, |
Sui Chen | 4cc4255 | 2019-09-11 10:28:35 -0700 | [diff] [blame] | 758 | ipmi::sensor::GetSensorResponse* resp) |
Tom Joseph | 295f17e | 2017-09-07 00:09:46 +0530 | [diff] [blame] | 759 | { |
Sui Chen | 4cc4255 | 2019-09-11 10:28:35 -0700 | [diff] [blame] | 760 | resp->thresholdLevelsStates = static_cast<uint8_t>(value & 0x00FF); |
| 761 | resp->discreteReadingSensorStates = static_cast<uint8_t>(value >> 8); |
Tom Joseph | 295f17e | 2017-09-07 00:09:46 +0530 | [diff] [blame] | 762 | } |
| 763 | |
Tom Joseph | e05b292 | 2017-09-07 00:43:16 +0530 | [diff] [blame] | 764 | /** |
| 765 | * @brief Set the scanning enabled bit in the response. |
| 766 | * |
| 767 | * @param[in/out] resp - get sensor reading response. |
| 768 | */ |
Sui Chen | 4cc4255 | 2019-09-11 10:28:35 -0700 | [diff] [blame] | 769 | inline void enableScanning(ipmi::sensor::GetSensorResponse* resp) |
Tom Joseph | e05b292 | 2017-09-07 00:43:16 +0530 | [diff] [blame] | 770 | { |
Sui Chen | 4cc4255 | 2019-09-11 10:28:35 -0700 | [diff] [blame] | 771 | resp->readingOrStateUnavailable = false; |
| 772 | resp->scanningEnabled = true; |
| 773 | resp->allEventMessagesEnabled = false; |
Tom Joseph | e05b292 | 2017-09-07 00:43:16 +0530 | [diff] [blame] | 774 | } |
| 775 | |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 776 | } // namespace sensor |
| 777 | |
| 778 | } // namespace ipmi |