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