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