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