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 | |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 3 | #include "types.hpp" |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 4 | |
William A. Kennington III | 194375f | 2018-12-14 02:14:33 -0800 | [diff] [blame] | 5 | #include <ipmid/api.h> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 6 | #include <stdint.h> |
| 7 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 8 | // IPMI commands for net functions. |
| 9 | enum ipmi_netfn_sen_cmds |
| 10 | { |
Jia, Chunhui | 3342a8e | 2018-12-29 13:32:26 +0800 | [diff] [blame] | 11 | IPMI_CMD_PLATFORM_EVENT = 0x2, |
Tom Joseph | 5ca5095 | 2018-02-22 00:33:38 +0530 | [diff] [blame] | 12 | IPMI_CMD_GET_DEVICE_SDR_INFO = 0x20, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 13 | IPMI_CMD_GET_DEVICE_SDR = 0x21, |
| 14 | IPMI_CMD_RESERVE_DEVICE_SDR_REPO = 0x22, |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 15 | IPMI_CMD_GET_SENSOR_READING = 0x2D, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 16 | IPMI_CMD_GET_SENSOR_TYPE = 0x2F, |
| 17 | IPMI_CMD_SET_SENSOR = 0x30, |
Dhruvaraj Subhashchandran | 5c0beec | 2018-01-23 04:47:06 -0600 | [diff] [blame] | 18 | IPMI_CMD_GET_SENSOR_THRESHOLDS = 0x27, |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 19 | }; |
| 20 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 21 | /** |
| 22 | * @enum device_type |
| 23 | * IPMI FRU device types |
| 24 | */ |
| 25 | enum device_type |
| 26 | { |
| 27 | IPMI_PHYSICAL_FRU = 0x00, |
| 28 | IPMI_LOGICAL_FRU = 0x80, |
| 29 | }; |
| 30 | |
Emily Shaffer | 1fabf22 | 2017-04-05 08:53:21 -0700 | [diff] [blame] | 31 | // Discrete sensor types. |
| 32 | enum ipmi_sensor_types |
| 33 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 34 | IPMI_SENSOR_TEMP = 0x01, |
Emily Shaffer | 1fabf22 | 2017-04-05 08:53:21 -0700 | [diff] [blame] | 35 | IPMI_SENSOR_VOLTAGE = 0x02, |
| 36 | IPMI_SENSOR_CURRENT = 0x03, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 37 | IPMI_SENSOR_FAN = 0x04, |
| 38 | IPMI_SENSOR_TPM = 0xCC, |
Emily Shaffer | 1fabf22 | 2017-04-05 08:53:21 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 41 | #define MAX_DBUS_PATH 128 |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 42 | struct dbus_interface_t |
| 43 | { |
| 44 | uint8_t sensornumber; |
| 45 | uint8_t sensortype; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 46 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 47 | char bus[MAX_DBUS_PATH]; |
| 48 | char path[MAX_DBUS_PATH]; |
| 49 | char interface[MAX_DBUS_PATH]; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 50 | }; |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 51 | |
Jia, Chunhui | 3342a8e | 2018-12-29 13:32:26 +0800 | [diff] [blame] | 52 | struct PlatformEventRequest |
| 53 | { |
| 54 | uint8_t eventMessageRevision; |
| 55 | uint8_t sensorType; |
| 56 | uint8_t sensorNumber; |
| 57 | uint8_t eventDirectionType; |
| 58 | uint8_t data[3]; |
| 59 | }; |
| 60 | |
| 61 | static constexpr char const* ipmiSELPath = "/xyz/openbmc_project/Logging/IPMI"; |
| 62 | static constexpr char const* ipmiSELAddInterface = |
| 63 | "xyz.openbmc_project.Logging.IPMI"; |
| 64 | static const std::string ipmiSELAddMessage = "SEL Entry"; |
| 65 | |
| 66 | static constexpr int selSystemEventSizeWith3Bytes = 8; |
| 67 | static constexpr int selSystemEventSizeWith2Bytes = 7; |
| 68 | static constexpr int selSystemEventSizeWith1Bytes = 6; |
| 69 | static constexpr int selIPMBEventSize = 7; |
| 70 | static constexpr uint8_t directionMask = 0x80; |
| 71 | static constexpr uint8_t byte3EnableMask = 0x30; |
| 72 | static constexpr uint8_t byte2EnableMask = 0xC0; |
| 73 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 74 | int set_sensor_dbus_state_s(uint8_t, const char*, const char*); |
| 75 | int set_sensor_dbus_state_y(uint8_t, const char*, const uint8_t); |
| 76 | int find_openbmc_path(uint8_t, dbus_interface_t*); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 77 | |
Tom Joseph | 5ca5095 | 2018-02-22 00:33:38 +0530 | [diff] [blame] | 78 | ipmi_ret_t ipmi_sen_get_sdr(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 79 | ipmi_request_t request, ipmi_response_t response, |
| 80 | ipmi_data_len_t data_len, ipmi_context_t context); |
| 81 | |
| 82 | ipmi_ret_t ipmi_sen_reserve_sdr(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 83 | ipmi_request_t request, |
| 84 | ipmi_response_t response, |
| 85 | ipmi_data_len_t data_len, |
| 86 | ipmi_context_t context); |
| 87 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 88 | static const uint16_t FRU_RECORD_ID_START = 256; |
| 89 | static const uint8_t SDR_VERSION = 0x51; |
| 90 | static const uint16_t END_OF_RECORD = 0xFFFF; |
| 91 | static const uint8_t LENGTH_MASK = 0x1F; |
| 92 | |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 93 | /** |
Emily Shaffer | d06e0e7 | 2017-04-05 09:08:57 -0700 | [diff] [blame] | 94 | * Get SDR Info |
| 95 | */ |
| 96 | |
| 97 | namespace get_sdr_info |
| 98 | { |
| 99 | namespace request |
| 100 | { |
| 101 | // Note: for some reason the ipmi_request_t appears to be the |
| 102 | // raw value for this call. |
| 103 | inline bool get_count(void* req) |
| 104 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 105 | return (bool)((uint64_t)(req)&1); |
Emily Shaffer | d06e0e7 | 2017-04-05 09:08:57 -0700 | [diff] [blame] | 106 | } |
| 107 | } // namespace request |
| 108 | |
| 109 | namespace response |
| 110 | { |
| 111 | #define SDR_INFO_RESP_SIZE 2 |
| 112 | inline void set_lun_present(int lun, uint8_t* resp) |
| 113 | { |
| 114 | *resp |= 1 << lun; |
| 115 | } |
| 116 | inline void set_lun_not_present(int lun, uint8_t* resp) |
| 117 | { |
| 118 | *resp &= ~(1 << lun); |
| 119 | } |
| 120 | inline void set_dynamic_population(uint8_t* resp) |
| 121 | { |
| 122 | *resp |= 1 << 7; |
| 123 | } |
| 124 | inline void set_static_population(uint8_t* resp) |
| 125 | { |
| 126 | *resp &= ~(1 << 7); |
| 127 | } |
| 128 | } // namespace response |
| 129 | |
| 130 | struct GetSdrInfoResp |
| 131 | { |
| 132 | uint8_t count; |
| 133 | uint8_t luns_and_dynamic_population; |
| 134 | }; |
| 135 | |
| 136 | } // namespace get_sdr_info |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 137 | |
| 138 | /** |
| 139 | * Get SDR |
| 140 | */ |
| 141 | namespace get_sdr |
| 142 | { |
| 143 | |
| 144 | struct GetSdrReq |
| 145 | { |
| 146 | uint8_t reservation_id_lsb; |
| 147 | uint8_t reservation_id_msb; |
| 148 | uint8_t record_id_lsb; |
| 149 | uint8_t record_id_msb; |
| 150 | uint8_t offset; |
| 151 | uint8_t bytes_to_read; |
| 152 | } __attribute__((packed)); |
| 153 | |
| 154 | namespace request |
| 155 | { |
| 156 | |
| 157 | inline uint8_t get_reservation_id(GetSdrReq* req) |
| 158 | { |
| 159 | return (req->reservation_id_lsb + (req->reservation_id_msb << 8)); |
| 160 | }; |
| 161 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 162 | inline uint16_t get_record_id(GetSdrReq* req) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 163 | { |
| 164 | return (req->record_id_lsb + (req->record_id_msb << 8)); |
| 165 | }; |
| 166 | |
| 167 | } // namespace request |
| 168 | |
| 169 | // Response |
| 170 | struct GetSdrResp |
| 171 | { |
| 172 | uint8_t next_record_id_lsb; |
| 173 | uint8_t next_record_id_msb; |
| 174 | uint8_t record_data[64]; |
| 175 | } __attribute__((packed)); |
| 176 | |
| 177 | namespace response |
| 178 | { |
| 179 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 180 | inline void set_next_record_id(uint16_t next, GetSdrResp* resp) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 181 | { |
| 182 | resp->next_record_id_lsb = next & 0xff; |
| 183 | resp->next_record_id_msb = (next >> 8) & 0xff; |
| 184 | }; |
| 185 | |
| 186 | } // namespace response |
| 187 | |
| 188 | // Record header |
| 189 | struct SensorDataRecordHeader |
| 190 | { |
| 191 | uint8_t record_id_lsb; |
| 192 | uint8_t record_id_msb; |
| 193 | uint8_t sdr_version; |
| 194 | uint8_t record_type; |
| 195 | uint8_t record_length; // Length not counting the header |
| 196 | } __attribute__((packed)); |
| 197 | |
| 198 | namespace header |
| 199 | { |
| 200 | |
| 201 | inline void set_record_id(int id, SensorDataRecordHeader* hdr) |
| 202 | { |
| 203 | hdr->record_id_lsb = (id & 0xFF); |
| 204 | hdr->record_id_msb = (id >> 8) & 0xFF; |
| 205 | }; |
| 206 | |
| 207 | } // namespace header |
| 208 | |
| 209 | enum SensorDataRecordType |
| 210 | { |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 211 | SENSOR_DATA_FULL_RECORD = 0x1, |
| 212 | SENSOR_DATA_FRU_RECORD = 0x11, |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 213 | }; |
| 214 | |
| 215 | // Record key |
| 216 | struct SensorDataRecordKey |
| 217 | { |
| 218 | uint8_t owner_id; |
| 219 | uint8_t owner_lun; |
| 220 | uint8_t sensor_number; |
| 221 | } __attribute__((packed)); |
| 222 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 223 | /** @struct SensorDataFruRecordKey |
| 224 | * |
| 225 | * FRU Device Locator Record(key) - SDR Type 11 |
| 226 | */ |
| 227 | struct SensorDataFruRecordKey |
| 228 | { |
| 229 | uint8_t deviceAddress; |
| 230 | uint8_t fruID; |
| 231 | uint8_t accessLun; |
| 232 | uint8_t channelNumber; |
| 233 | } __attribute__((packed)); |
| 234 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 235 | namespace key |
| 236 | { |
| 237 | |
| 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 | |
| 271 | } // namespace key |
| 272 | |
Dhruvaraj Subhashchandran | 5c0beec | 2018-01-23 04:47:06 -0600 | [diff] [blame] | 273 | /** @struct GetSensorThresholdsResponse |
| 274 | * |
| 275 | * Response structure for Get Sensor Thresholds command |
| 276 | */ |
| 277 | struct GetSensorThresholdsResponse |
| 278 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 279 | uint8_t validMask; //!< valid mask |
| 280 | uint8_t lowerNonCritical; //!< lower non-critical threshold |
| 281 | uint8_t lowerCritical; //!< lower critical threshold |
| 282 | uint8_t lowerNonRecoverable; //!< lower non-recoverable threshold |
| 283 | uint8_t upperNonCritical; //!< upper non-critical threshold |
| 284 | uint8_t upperCritical; //!< upper critical threshold |
| 285 | uint8_t upperNonRecoverable; //!< upper non-recoverable threshold |
Dhruvaraj Subhashchandran | 5c0beec | 2018-01-23 04:47:06 -0600 | [diff] [blame] | 286 | } __attribute__((packed)); |
| 287 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 288 | // Body - full record |
| 289 | #define FULL_RECORD_ID_STR_MAX_LENGTH 16 |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 290 | |
| 291 | static const int FRU_RECORD_DEVICE_ID_MAX_LENGTH = 16; |
| 292 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 293 | struct SensorDataFullRecordBody |
| 294 | { |
| 295 | uint8_t entity_id; |
| 296 | uint8_t entity_instance; |
| 297 | uint8_t sensor_initialization; |
| 298 | uint8_t sensor_capabilities; // no macro support |
| 299 | uint8_t sensor_type; |
| 300 | uint8_t event_reading_type; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 301 | uint8_t supported_assertions[2]; // no macro support |
| 302 | uint8_t supported_deassertions[2]; // no macro support |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 303 | uint8_t discrete_reading_setting_mask[2]; // no macro support |
| 304 | uint8_t sensor_units_1; |
| 305 | uint8_t sensor_units_2_base; |
| 306 | uint8_t sensor_units_3_modifier; |
| 307 | uint8_t linearization; |
| 308 | uint8_t m_lsb; |
| 309 | uint8_t m_msb_and_tolerance; |
| 310 | uint8_t b_lsb; |
| 311 | uint8_t b_msb_and_accuracy_lsb; |
| 312 | uint8_t accuracy_and_sensor_direction; |
| 313 | uint8_t r_b_exponents; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 314 | uint8_t analog_characteristic_flags; // no macro support |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 315 | uint8_t nominal_reading; |
| 316 | uint8_t normal_max; |
| 317 | uint8_t normal_min; |
| 318 | uint8_t sensor_max; |
| 319 | uint8_t sensor_min; |
| 320 | uint8_t upper_nonrecoverable_threshold; |
| 321 | uint8_t upper_critical_threshold; |
| 322 | uint8_t upper_noncritical_threshold; |
| 323 | uint8_t lower_nonrecoverable_threshold; |
| 324 | uint8_t lower_critical_threshold; |
| 325 | uint8_t lower_noncritical_threshold; |
| 326 | uint8_t positive_threshold_hysteresis; |
| 327 | uint8_t negative_threshold_hysteresis; |
| 328 | uint16_t reserved; |
| 329 | uint8_t oem_reserved; |
| 330 | uint8_t id_string_info; |
Emily Shaffer | 10f4959 | 2017-05-10 12:01:10 -0700 | [diff] [blame] | 331 | char id_string[FULL_RECORD_ID_STR_MAX_LENGTH]; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 332 | } __attribute__((packed)); |
| 333 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 334 | /** @struct SensorDataFruRecordBody |
| 335 | * |
| 336 | * FRU Device Locator Record(body) - SDR Type 11 |
| 337 | */ |
| 338 | struct SensorDataFruRecordBody |
| 339 | { |
| 340 | uint8_t reserved; |
| 341 | uint8_t deviceType; |
| 342 | uint8_t deviceTypeModifier; |
| 343 | uint8_t entityID; |
| 344 | uint8_t entityInstance; |
| 345 | uint8_t oem; |
| 346 | uint8_t deviceIDLen; |
| 347 | char deviceID[FRU_RECORD_DEVICE_ID_MAX_LENGTH]; |
| 348 | } __attribute__((packed)); |
| 349 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 350 | namespace body |
| 351 | { |
| 352 | |
| 353 | inline void set_entity_instance_number(uint8_t n, |
| 354 | SensorDataFullRecordBody* body) |
| 355 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 356 | body->entity_instance &= 1 << 7; |
| 357 | body->entity_instance |= (n & ~(1 << 7)); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 358 | }; |
| 359 | inline void set_entity_physical_entity(SensorDataFullRecordBody* body) |
| 360 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 361 | body->entity_instance &= ~(1 << 7); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 362 | }; |
| 363 | inline void set_entity_logical_container(SensorDataFullRecordBody* body) |
| 364 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 365 | body->entity_instance |= 1 << 7; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 366 | }; |
| 367 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 368 | inline void sensor_scanning_state(bool enabled, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 369 | { |
| 370 | if (enabled) |
| 371 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 372 | body->sensor_initialization |= 1 << 0; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 373 | } |
| 374 | else |
| 375 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 376 | body->sensor_initialization &= ~(1 << 0); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 377 | }; |
| 378 | }; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 379 | inline void event_generation_state(bool enabled, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 380 | { |
| 381 | if (enabled) |
| 382 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 383 | body->sensor_initialization |= 1 << 1; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 384 | } |
| 385 | else |
| 386 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 387 | body->sensor_initialization &= ~(1 << 1); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 388 | } |
| 389 | }; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 390 | inline void init_types_state(bool enabled, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 391 | { |
| 392 | if (enabled) |
| 393 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 394 | body->sensor_initialization |= 1 << 2; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 395 | } |
| 396 | else |
| 397 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 398 | body->sensor_initialization &= ~(1 << 2); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 399 | } |
| 400 | }; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 401 | inline void init_hyst_state(bool enabled, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 402 | { |
| 403 | if (enabled) |
| 404 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 405 | body->sensor_initialization |= 1 << 3; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 406 | } |
| 407 | else |
| 408 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 409 | body->sensor_initialization &= ~(1 << 3); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 410 | } |
| 411 | }; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 412 | inline void init_thresh_state(bool enabled, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 413 | { |
| 414 | if (enabled) |
| 415 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 416 | body->sensor_initialization |= 1 << 4; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 417 | } |
| 418 | else |
| 419 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 420 | body->sensor_initialization &= ~(1 << 4); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 421 | } |
| 422 | }; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 423 | inline void init_events_state(bool enabled, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 424 | { |
| 425 | if (enabled) |
| 426 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 427 | body->sensor_initialization |= 1 << 5; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 428 | } |
| 429 | else |
| 430 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 431 | body->sensor_initialization &= ~(1 << 5); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 432 | } |
| 433 | }; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 434 | inline void init_scanning_state(bool enabled, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 435 | { |
| 436 | if (enabled) |
| 437 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 438 | body->sensor_initialization |= 1 << 6; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 439 | } |
| 440 | else |
| 441 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 442 | body->sensor_initialization &= ~(1 << 6); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 443 | } |
| 444 | }; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 445 | inline void init_settable_state(bool enabled, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 446 | { |
| 447 | if (enabled) |
| 448 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 449 | body->sensor_initialization |= 1 << 7; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 450 | } |
| 451 | else |
| 452 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 453 | body->sensor_initialization &= ~(1 << 7); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 454 | } |
| 455 | }; |
| 456 | |
| 457 | inline void set_percentage(SensorDataFullRecordBody* body) |
| 458 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 459 | body->sensor_units_1 |= 1 << 0; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 460 | }; |
| 461 | inline void unset_percentage(SensorDataFullRecordBody* body) |
| 462 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 463 | body->sensor_units_1 &= ~(1 << 0); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 464 | }; |
| 465 | inline void set_modifier_operation(uint8_t op, SensorDataFullRecordBody* body) |
| 466 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 467 | body->sensor_units_1 &= ~(3 << 1); |
| 468 | body->sensor_units_1 |= (op & 0x3) << 1; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 469 | }; |
| 470 | inline void set_rate_unit(uint8_t unit, SensorDataFullRecordBody* body) |
| 471 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 472 | body->sensor_units_1 &= ~(7 << 3); |
| 473 | body->sensor_units_1 |= (unit & 0x7) << 3; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 474 | }; |
| 475 | inline void set_analog_data_format(uint8_t format, |
| 476 | SensorDataFullRecordBody* body) |
| 477 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 478 | body->sensor_units_1 &= ~(3 << 6); |
| 479 | body->sensor_units_1 |= (format & 0x3) << 6; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 480 | }; |
| 481 | |
Emily Shaffer | 7cad3fc | 2017-08-30 17:50:37 -0700 | [diff] [blame] | 482 | inline void set_m(uint16_t m, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 483 | { |
| 484 | body->m_lsb = m & 0xff; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 485 | body->m_msb_and_tolerance &= ~(3 << 6); |
| 486 | body->m_msb_and_tolerance |= ((m & (3 << 8)) >> 2); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 487 | }; |
| 488 | inline void set_tolerance(uint8_t tol, SensorDataFullRecordBody* body) |
| 489 | { |
| 490 | body->m_msb_and_tolerance &= ~0x3f; |
| 491 | body->m_msb_and_tolerance |= tol & 0x3f; |
| 492 | }; |
| 493 | |
Emily Shaffer | 7cad3fc | 2017-08-30 17:50:37 -0700 | [diff] [blame] | 494 | inline void set_b(uint16_t b, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 495 | { |
| 496 | body->b_lsb = b & 0xff; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 497 | body->b_msb_and_accuracy_lsb &= ~(3 << 6); |
| 498 | body->b_msb_and_accuracy_lsb |= ((b & (3 << 8)) >> 2); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 499 | }; |
Emily Shaffer | 7cad3fc | 2017-08-30 17:50:37 -0700 | [diff] [blame] | 500 | inline void set_accuracy(uint16_t acc, SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 501 | { |
Emily Shaffer | 7cad3fc | 2017-08-30 17:50:37 -0700 | [diff] [blame] | 502 | // bottom 6 bits |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 503 | body->b_msb_and_accuracy_lsb &= ~0x3f; |
| 504 | body->b_msb_and_accuracy_lsb |= acc & 0x3f; |
Emily Shaffer | 7cad3fc | 2017-08-30 17:50:37 -0700 | [diff] [blame] | 505 | // top 4 bits |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 506 | body->accuracy_and_sensor_direction &= 0x0f; |
Emily Shaffer | 7cad3fc | 2017-08-30 17:50:37 -0700 | [diff] [blame] | 507 | body->accuracy_and_sensor_direction |= ((acc >> 6) & 0xf) << 4; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 508 | }; |
| 509 | inline void set_accuracy_exp(uint8_t exp, SensorDataFullRecordBody* body) |
| 510 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 511 | body->accuracy_and_sensor_direction &= ~(3 << 2); |
| 512 | body->accuracy_and_sensor_direction |= (exp & 3) << 2; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 513 | }; |
| 514 | inline void set_sensor_dir(uint8_t dir, SensorDataFullRecordBody* body) |
| 515 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 516 | body->accuracy_and_sensor_direction &= ~(3 << 0); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 517 | body->accuracy_and_sensor_direction |= (dir & 3); |
| 518 | }; |
| 519 | |
| 520 | inline void set_b_exp(uint8_t exp, SensorDataFullRecordBody* body) |
| 521 | { |
| 522 | body->r_b_exponents &= 0xf0; |
| 523 | body->r_b_exponents |= exp & 0x0f; |
| 524 | }; |
| 525 | inline void set_r_exp(uint8_t exp, SensorDataFullRecordBody* body) |
| 526 | { |
| 527 | body->r_b_exponents &= 0x0f; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 528 | body->r_b_exponents |= (exp & 0x0f) << 4; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 529 | }; |
| 530 | |
| 531 | inline void set_id_strlen(uint8_t len, SensorDataFullRecordBody* body) |
| 532 | { |
| 533 | body->id_string_info &= ~(0x1f); |
| 534 | body->id_string_info |= len & 0x1f; |
| 535 | }; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 536 | inline uint8_t get_id_strlen(SensorDataFullRecordBody* body) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 537 | { |
| 538 | return body->id_string_info & 0x1f; |
| 539 | }; |
| 540 | inline void set_id_type(uint8_t type, SensorDataFullRecordBody* body) |
| 541 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 542 | body->id_string_info &= ~(3 << 6); |
| 543 | body->id_string_info |= (type & 0x3) << 6; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 544 | }; |
| 545 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 546 | inline void set_device_id_strlen(uint8_t len, SensorDataFruRecordBody* body) |
| 547 | { |
| 548 | body->deviceIDLen &= ~(LENGTH_MASK); |
| 549 | body->deviceIDLen |= len & LENGTH_MASK; |
| 550 | }; |
| 551 | |
| 552 | inline uint8_t get_device_id_strlen(SensorDataFruRecordBody* body) |
| 553 | { |
| 554 | return body->deviceIDLen & LENGTH_MASK; |
| 555 | }; |
| 556 | |
Tom Joseph | dc212b2 | 2018-02-16 09:59:57 +0530 | [diff] [blame] | 557 | inline void set_readable_mask(uint8_t mask, SensorDataFullRecordBody* body) |
| 558 | { |
| 559 | body->discrete_reading_setting_mask[1] = mask & 0x3F; |
| 560 | } |
| 561 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 562 | } // namespace body |
| 563 | |
| 564 | // More types contained in section 43.17 Sensor Unit Type Codes, |
| 565 | // IPMI spec v2 rev 1.1 |
| 566 | enum SensorUnitTypeCodes |
| 567 | { |
| 568 | SENSOR_UNIT_UNSPECIFIED = 0, |
| 569 | SENSOR_UNIT_DEGREES_C = 1, |
| 570 | SENSOR_UNIT_VOLTS = 4, |
| 571 | SENSOR_UNIT_AMPERES = 5, |
Tom Joseph | dc212b2 | 2018-02-16 09:59:57 +0530 | [diff] [blame] | 572 | SENSOR_UNIT_WATTS = 6, |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 573 | SENSOR_UNIT_JOULES = 7, |
Kirill Pakhomov | 812e44c | 2018-10-22 16:25:35 +0300 | [diff] [blame] | 574 | SENSOR_UNIT_RPM = 18, |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 575 | SENSOR_UNIT_METERS = 34, |
| 576 | SENSOR_UNIT_REVOLUTIONS = 41, |
| 577 | }; |
| 578 | |
| 579 | struct SensorDataFullRecord |
| 580 | { |
| 581 | SensorDataRecordHeader header; |
| 582 | SensorDataRecordKey key; |
| 583 | SensorDataFullRecordBody body; |
| 584 | } __attribute__((packed)); |
| 585 | |
Ratan Gupta | e0cc855 | 2018-01-22 14:23:04 +0530 | [diff] [blame] | 586 | /** @struct SensorDataFruRecord |
| 587 | * |
| 588 | * FRU Device Locator Record - SDR Type 11 |
| 589 | */ |
| 590 | struct SensorDataFruRecord |
| 591 | { |
| 592 | SensorDataRecordHeader header; |
| 593 | SensorDataFruRecordKey key; |
| 594 | SensorDataFruRecordBody body; |
| 595 | } __attribute__((packed)); |
| 596 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 597 | } // namespace get_sdr |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 598 | |
| 599 | namespace ipmi |
| 600 | { |
| 601 | |
| 602 | namespace sensor |
| 603 | { |
| 604 | |
| 605 | /** |
| 606 | * @brief Map offset to the corresponding bit in the assertion byte. |
| 607 | * |
Gunnar Mills | 8991dd6 | 2017-10-25 17:11:29 -0500 | [diff] [blame] | 608 | * 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] | 609 | * byte and offsets 8-14 in the second byte. |
| 610 | * |
| 611 | * @param[in] offset - offset number. |
| 612 | * @param[in/out] resp - get sensor reading response. |
| 613 | */ |
| 614 | inline void setOffset(uint8_t offset, ipmi::sensor::GetReadingResponse* resp) |
| 615 | { |
| 616 | if (offset > 7) |
| 617 | { |
| 618 | resp->assertOffset8_14 |= 1 << (offset - 8); |
| 619 | } |
| 620 | else |
| 621 | { |
| 622 | resp->assertOffset0_7 |= 1 << offset; |
| 623 | } |
| 624 | } |
| 625 | |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 626 | /** |
| 627 | * @brief Set the reading field in the response. |
| 628 | * |
| 629 | * @param[in] offset - offset number. |
| 630 | * @param[in/out] resp - get sensor reading response. |
| 631 | */ |
| 632 | inline void setReading(uint8_t value, ipmi::sensor::GetReadingResponse* resp) |
| 633 | { |
| 634 | resp->reading = value; |
| 635 | } |
| 636 | |
Tom Joseph | 295f17e | 2017-09-07 00:09:46 +0530 | [diff] [blame] | 637 | /** |
| 638 | * @brief Map the value to the assertion bytes. The assertion states are stored |
| 639 | * in 2 bytes. |
| 640 | * |
| 641 | * @param[in] value - value to mapped to the assertion byte. |
| 642 | * @param[in/out] resp - get sensor reading response. |
| 643 | */ |
| 644 | inline void setAssertionBytes(uint16_t value, |
| 645 | ipmi::sensor::GetReadingResponse* resp) |
| 646 | { |
| 647 | resp->assertOffset0_7 = static_cast<uint8_t>(value & 0x00FF); |
| 648 | resp->assertOffset8_14 = static_cast<uint8_t>(value >> 8); |
| 649 | } |
| 650 | |
Tom Joseph | e05b292 | 2017-09-07 00:43:16 +0530 | [diff] [blame] | 651 | /** |
| 652 | * @brief Set the scanning enabled bit in the response. |
| 653 | * |
| 654 | * @param[in/out] resp - get sensor reading response. |
| 655 | */ |
| 656 | inline void enableScanning(ipmi::sensor::GetReadingResponse* resp) |
| 657 | { |
| 658 | resp->operation = 1 << 6; |
| 659 | } |
| 660 | |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 661 | } // namespace sensor |
| 662 | |
| 663 | } // namespace ipmi |