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