blob: 56a7021f0c3ad9b437e28e0a3ef2de0fafd3a0b5 [file] [log] [blame]
Patrick Venture46470a32018-09-07 19:26:25 -07001#pragma once
Chris Austenac4604a2015-10-13 12:43:27 -05002
Patrick Venture0b02be92018-08-31 11:55:55 -07003#include <stdint.h>
4
Vernon Mauerye08fbff2019-04-03 09:19:34 -07005#include <ipmid/api.hpp>
Vernon Mauery33250242019-03-12 16:49:26 -07006#include <ipmid/types.hpp>
7
Chris Austenac4604a2015-10-13 12:43:27 -05008// IPMI commands for net functions.
9enum ipmi_netfn_sen_cmds
10{
Jia, Chunhui3342a8e2018-12-29 13:32:26 +080011 IPMI_CMD_PLATFORM_EVENT = 0x2,
Tom Joseph5ca50952018-02-22 00:33:38 +053012 IPMI_CMD_GET_DEVICE_SDR_INFO = 0x20,
Patrick Venture0b02be92018-08-31 11:55:55 -070013 IPMI_CMD_GET_DEVICE_SDR = 0x21,
14 IPMI_CMD_RESERVE_DEVICE_SDR_REPO = 0x22,
Chris Austen10ccc0f2015-12-10 18:27:04 -060015 IPMI_CMD_GET_SENSOR_READING = 0x2D,
Patrick Venture0b02be92018-08-31 11:55:55 -070016 IPMI_CMD_GET_SENSOR_TYPE = 0x2F,
17 IPMI_CMD_SET_SENSOR = 0x30,
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -060018 IPMI_CMD_GET_SENSOR_THRESHOLDS = 0x27,
Chris Austenac4604a2015-10-13 12:43:27 -050019};
20
Ratan Guptae0cc8552018-01-22 14:23:04 +053021/**
22 * @enum device_type
23 * IPMI FRU device types
24 */
25enum device_type
26{
27 IPMI_PHYSICAL_FRU = 0x00,
28 IPMI_LOGICAL_FRU = 0x80,
29};
30
Emily Shaffer1fabf222017-04-05 08:53:21 -070031// Discrete sensor types.
32enum ipmi_sensor_types
33{
Patrick Venture0b02be92018-08-31 11:55:55 -070034 IPMI_SENSOR_TEMP = 0x01,
Emily Shaffer1fabf222017-04-05 08:53:21 -070035 IPMI_SENSOR_VOLTAGE = 0x02,
36 IPMI_SENSOR_CURRENT = 0x03,
Patrick Venture0b02be92018-08-31 11:55:55 -070037 IPMI_SENSOR_FAN = 0x04,
38 IPMI_SENSOR_TPM = 0xCC,
Emily Shaffer1fabf222017-04-05 08:53:21 -070039};
40
Chris Austen0012e9b2015-10-22 01:37:46 -050041#define MAX_DBUS_PATH 128
Patrick Venture0b02be92018-08-31 11:55:55 -070042struct dbus_interface_t
43{
44 uint8_t sensornumber;
45 uint8_t sensortype;
Chris Austen0012e9b2015-10-22 01:37:46 -050046
Patrick Venture0b02be92018-08-31 11:55:55 -070047 char bus[MAX_DBUS_PATH];
48 char path[MAX_DBUS_PATH];
49 char interface[MAX_DBUS_PATH];
Chris Austen0012e9b2015-10-22 01:37:46 -050050};
Tomd700e762016-09-20 18:24:13 +053051
Jia, Chunhui3342a8e2018-12-29 13:32:26 +080052struct 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
61static constexpr char const* ipmiSELPath = "/xyz/openbmc_project/Logging/IPMI";
62static constexpr char const* ipmiSELAddInterface =
63 "xyz.openbmc_project.Logging.IPMI";
64static const std::string ipmiSELAddMessage = "SEL Entry";
65
66static constexpr int selSystemEventSizeWith3Bytes = 8;
67static constexpr int selSystemEventSizeWith2Bytes = 7;
68static constexpr int selSystemEventSizeWith1Bytes = 6;
69static constexpr int selIPMBEventSize = 7;
70static constexpr uint8_t directionMask = 0x80;
71static constexpr uint8_t byte3EnableMask = 0x30;
72static constexpr uint8_t byte2EnableMask = 0xC0;
73
Patrick Venture0b02be92018-08-31 11:55:55 -070074int set_sensor_dbus_state_s(uint8_t, const char*, const char*);
75int set_sensor_dbus_state_y(uint8_t, const char*, const uint8_t);
76int find_openbmc_path(uint8_t, dbus_interface_t*);
Tom05732372016-09-06 17:21:23 +053077
Tom Joseph5ca50952018-02-22 00:33:38 +053078ipmi_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
jayaprakash Mutyalad9578232019-05-13 20:22:50 +000082ipmi::RspType<uint16_t> ipmiSensorReserveSdr();
Tom Joseph5ca50952018-02-22 00:33:38 +053083
Ratan Guptae0cc8552018-01-22 14:23:04 +053084static const uint16_t FRU_RECORD_ID_START = 256;
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -080085static const uint16_t ENTITY_RECORD_ID_START = 512;
Ratan Guptae0cc8552018-01-22 14:23:04 +053086static const uint8_t SDR_VERSION = 0x51;
87static const uint16_t END_OF_RECORD = 0xFFFF;
88static const uint8_t LENGTH_MASK = 0x1F;
89
Tom Josephbe703f72017-03-09 12:34:35 +053090/**
Emily Shafferd06e0e72017-04-05 09:08:57 -070091 * Get SDR Info
92 */
93
94namespace get_sdr_info
95{
96namespace request
97{
98// Note: for some reason the ipmi_request_t appears to be the
99// raw value for this call.
100inline bool get_count(void* req)
101{
Patrick Venture0b02be92018-08-31 11:55:55 -0700102 return (bool)((uint64_t)(req)&1);
Emily Shafferd06e0e72017-04-05 09:08:57 -0700103}
104} // namespace request
Emily Shafferd06e0e72017-04-05 09:08:57 -0700105} // namespace get_sdr_info
Emily Shafferbbef71c2017-05-08 16:36:17 -0700106
107/**
108 * Get SDR
109 */
110namespace get_sdr
111{
112
113struct GetSdrReq
114{
115 uint8_t reservation_id_lsb;
116 uint8_t reservation_id_msb;
117 uint8_t record_id_lsb;
118 uint8_t record_id_msb;
119 uint8_t offset;
120 uint8_t bytes_to_read;
121} __attribute__((packed));
122
123namespace request
124{
125
Emily Shaffere5c9d2f2019-06-25 14:26:45 -0700126inline uint16_t get_reservation_id(GetSdrReq* req)
Emily Shafferbbef71c2017-05-08 16:36:17 -0700127{
128 return (req->reservation_id_lsb + (req->reservation_id_msb << 8));
129};
130
Ratan Guptae0cc8552018-01-22 14:23:04 +0530131inline uint16_t get_record_id(GetSdrReq* req)
Emily Shafferbbef71c2017-05-08 16:36:17 -0700132{
133 return (req->record_id_lsb + (req->record_id_msb << 8));
134};
135
136} // namespace request
137
138// Response
139struct GetSdrResp
140{
141 uint8_t next_record_id_lsb;
142 uint8_t next_record_id_msb;
143 uint8_t record_data[64];
144} __attribute__((packed));
145
146namespace response
147{
148
Ratan Guptae0cc8552018-01-22 14:23:04 +0530149inline void set_next_record_id(uint16_t next, GetSdrResp* resp)
Emily Shafferbbef71c2017-05-08 16:36:17 -0700150{
151 resp->next_record_id_lsb = next & 0xff;
152 resp->next_record_id_msb = (next >> 8) & 0xff;
153};
154
155} // namespace response
156
157// Record header
158struct SensorDataRecordHeader
159{
160 uint8_t record_id_lsb;
161 uint8_t record_id_msb;
162 uint8_t sdr_version;
163 uint8_t record_type;
164 uint8_t record_length; // Length not counting the header
165} __attribute__((packed));
166
167namespace header
168{
169
170inline void set_record_id(int id, SensorDataRecordHeader* hdr)
171{
172 hdr->record_id_lsb = (id & 0xFF);
173 hdr->record_id_msb = (id >> 8) & 0xFF;
174};
175
176} // namespace header
177
178enum SensorDataRecordType
179{
Ratan Guptae0cc8552018-01-22 14:23:04 +0530180 SENSOR_DATA_FULL_RECORD = 0x1,
181 SENSOR_DATA_FRU_RECORD = 0x11,
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -0800182 SENSOR_DATA_ENTITY_RECORD = 0x8,
Emily Shafferbbef71c2017-05-08 16:36:17 -0700183};
184
185// Record key
186struct SensorDataRecordKey
187{
188 uint8_t owner_id;
189 uint8_t owner_lun;
190 uint8_t sensor_number;
191} __attribute__((packed));
192
Ratan Guptae0cc8552018-01-22 14:23:04 +0530193/** @struct SensorDataFruRecordKey
194 *
195 * FRU Device Locator Record(key) - SDR Type 11
196 */
197struct SensorDataFruRecordKey
198{
199 uint8_t deviceAddress;
200 uint8_t fruID;
201 uint8_t accessLun;
202 uint8_t channelNumber;
203} __attribute__((packed));
204
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -0800205/** @struct SensorDataEntityRecordKey
206 *
207 * Entity Association Record(key) - SDR Type 8
208 */
209struct SensorDataEntityRecordKey
210{
211 uint8_t containerEntityId;
212 uint8_t containerEntityInstance;
213 uint8_t flags;
214 uint8_t entityId1;
215 uint8_t entityInstance1;
216} __attribute__((packed));
217
Emily Shafferbbef71c2017-05-08 16:36:17 -0700218namespace key
219{
220
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -0800221static constexpr uint8_t listOrRangeBit = 7;
222static constexpr uint8_t linkedBit = 6;
223
Emily Shafferbbef71c2017-05-08 16:36:17 -0700224inline void set_owner_id_ipmb(SensorDataRecordKey* key)
225{
226 key->owner_id &= ~0x01;
227};
228
229inline void set_owner_id_system_sw(SensorDataRecordKey* key)
230{
231 key->owner_id |= 0x01;
232};
233
Tom Joseph96423912018-01-25 00:14:34 +0530234inline void set_owner_id_bmc(SensorDataRecordKey* key)
235{
236 key->owner_id |= 0x20;
237};
238
Emily Shafferbbef71c2017-05-08 16:36:17 -0700239inline void set_owner_id_address(uint8_t addr, SensorDataRecordKey* key)
240{
241 key->owner_id &= 0x01;
Patrick Venture0b02be92018-08-31 11:55:55 -0700242 key->owner_id |= addr << 1;
Emily Shafferbbef71c2017-05-08 16:36:17 -0700243};
244
245inline void set_owner_lun(uint8_t lun, SensorDataRecordKey* key)
246{
247 key->owner_lun &= ~0x03;
Patrick Venture0b02be92018-08-31 11:55:55 -0700248 key->owner_lun |= (lun & 0x03);
Emily Shafferbbef71c2017-05-08 16:36:17 -0700249};
250
251inline void set_owner_lun_channel(uint8_t channel, SensorDataRecordKey* key)
252{
253 key->owner_lun &= 0x0f;
Patrick Venture0b02be92018-08-31 11:55:55 -0700254 key->owner_lun |= ((channel & 0xf) << 4);
Emily Shafferbbef71c2017-05-08 16:36:17 -0700255};
256
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -0800257inline void set_flags(bool isList, bool isLinked,
258 SensorDataEntityRecordKey* key)
259{
260 key->flags = 0x00;
261 if (!isList)
262 key->flags |= 1 << listOrRangeBit;
263
264 if (isLinked)
265 key->flags |= 1 << linkedBit;
266};
267
Emily Shafferbbef71c2017-05-08 16:36:17 -0700268} // namespace key
269
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600270/** @struct GetSensorThresholdsResponse
271 *
272 * Response structure for Get Sensor Thresholds command
273 */
274struct GetSensorThresholdsResponse
275{
Patrick Venture0b02be92018-08-31 11:55:55 -0700276 uint8_t validMask; //!< valid mask
277 uint8_t lowerNonCritical; //!< lower non-critical threshold
278 uint8_t lowerCritical; //!< lower critical threshold
279 uint8_t lowerNonRecoverable; //!< lower non-recoverable threshold
280 uint8_t upperNonCritical; //!< upper non-critical threshold
281 uint8_t upperCritical; //!< upper critical threshold
282 uint8_t upperNonRecoverable; //!< upper non-recoverable threshold
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600283} __attribute__((packed));
284
Emily Shafferbbef71c2017-05-08 16:36:17 -0700285// Body - full record
286#define FULL_RECORD_ID_STR_MAX_LENGTH 16
Ratan Guptae0cc8552018-01-22 14:23:04 +0530287
288static const int FRU_RECORD_DEVICE_ID_MAX_LENGTH = 16;
289
Emily Shafferbbef71c2017-05-08 16:36:17 -0700290struct SensorDataFullRecordBody
291{
292 uint8_t entity_id;
293 uint8_t entity_instance;
294 uint8_t sensor_initialization;
295 uint8_t sensor_capabilities; // no macro support
296 uint8_t sensor_type;
297 uint8_t event_reading_type;
Patrick Venture0b02be92018-08-31 11:55:55 -0700298 uint8_t supported_assertions[2]; // no macro support
299 uint8_t supported_deassertions[2]; // no macro support
Emily Shafferbbef71c2017-05-08 16:36:17 -0700300 uint8_t discrete_reading_setting_mask[2]; // no macro support
301 uint8_t sensor_units_1;
302 uint8_t sensor_units_2_base;
303 uint8_t sensor_units_3_modifier;
304 uint8_t linearization;
305 uint8_t m_lsb;
306 uint8_t m_msb_and_tolerance;
307 uint8_t b_lsb;
308 uint8_t b_msb_and_accuracy_lsb;
309 uint8_t accuracy_and_sensor_direction;
310 uint8_t r_b_exponents;
Patrick Venture0b02be92018-08-31 11:55:55 -0700311 uint8_t analog_characteristic_flags; // no macro support
Emily Shafferbbef71c2017-05-08 16:36:17 -0700312 uint8_t nominal_reading;
313 uint8_t normal_max;
314 uint8_t normal_min;
315 uint8_t sensor_max;
316 uint8_t sensor_min;
317 uint8_t upper_nonrecoverable_threshold;
318 uint8_t upper_critical_threshold;
319 uint8_t upper_noncritical_threshold;
320 uint8_t lower_nonrecoverable_threshold;
321 uint8_t lower_critical_threshold;
322 uint8_t lower_noncritical_threshold;
323 uint8_t positive_threshold_hysteresis;
324 uint8_t negative_threshold_hysteresis;
325 uint16_t reserved;
326 uint8_t oem_reserved;
327 uint8_t id_string_info;
Emily Shaffer10f49592017-05-10 12:01:10 -0700328 char id_string[FULL_RECORD_ID_STR_MAX_LENGTH];
Emily Shafferbbef71c2017-05-08 16:36:17 -0700329} __attribute__((packed));
330
Ratan Guptae0cc8552018-01-22 14:23:04 +0530331/** @struct SensorDataFruRecordBody
332 *
333 * FRU Device Locator Record(body) - SDR Type 11
334 */
335struct SensorDataFruRecordBody
336{
337 uint8_t reserved;
338 uint8_t deviceType;
339 uint8_t deviceTypeModifier;
340 uint8_t entityID;
341 uint8_t entityInstance;
342 uint8_t oem;
343 uint8_t deviceIDLen;
344 char deviceID[FRU_RECORD_DEVICE_ID_MAX_LENGTH];
345} __attribute__((packed));
346
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -0800347/** @struct SensorDataEntityRecordBody
348 *
349 * Entity Association Record(body) - SDR Type 8
350 */
351struct SensorDataEntityRecordBody
352{
353 uint8_t entityId2;
354 uint8_t entityInstance2;
355 uint8_t entityId3;
356 uint8_t entityInstance3;
357 uint8_t entityId4;
358 uint8_t entityInstance4;
359} __attribute__((packed));
360
Emily Shafferbbef71c2017-05-08 16:36:17 -0700361namespace body
362{
363
364inline void set_entity_instance_number(uint8_t n,
365 SensorDataFullRecordBody* body)
366{
Patrick Venture0b02be92018-08-31 11:55:55 -0700367 body->entity_instance &= 1 << 7;
368 body->entity_instance |= (n & ~(1 << 7));
Emily Shafferbbef71c2017-05-08 16:36:17 -0700369};
370inline void set_entity_physical_entity(SensorDataFullRecordBody* body)
371{
Patrick Venture0b02be92018-08-31 11:55:55 -0700372 body->entity_instance &= ~(1 << 7);
Emily Shafferbbef71c2017-05-08 16:36:17 -0700373};
374inline void set_entity_logical_container(SensorDataFullRecordBody* body)
375{
Patrick Venture0b02be92018-08-31 11:55:55 -0700376 body->entity_instance |= 1 << 7;
Emily Shafferbbef71c2017-05-08 16:36:17 -0700377};
378
Patrick Venture0b02be92018-08-31 11:55:55 -0700379inline void sensor_scanning_state(bool enabled, SensorDataFullRecordBody* body)
Emily Shafferbbef71c2017-05-08 16:36:17 -0700380{
381 if (enabled)
382 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700383 body->sensor_initialization |= 1 << 0;
Emily Shafferbbef71c2017-05-08 16:36:17 -0700384 }
385 else
386 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700387 body->sensor_initialization &= ~(1 << 0);
Emily Shafferbbef71c2017-05-08 16:36:17 -0700388 };
389};
Patrick Venture0b02be92018-08-31 11:55:55 -0700390inline void event_generation_state(bool enabled, SensorDataFullRecordBody* body)
Emily Shafferbbef71c2017-05-08 16:36:17 -0700391{
392 if (enabled)
393 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700394 body->sensor_initialization |= 1 << 1;
Emily Shafferbbef71c2017-05-08 16:36:17 -0700395 }
396 else
397 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700398 body->sensor_initialization &= ~(1 << 1);
Emily Shafferbbef71c2017-05-08 16:36:17 -0700399 }
400};
Patrick Venture0b02be92018-08-31 11:55:55 -0700401inline void init_types_state(bool enabled, SensorDataFullRecordBody* body)
Emily Shafferbbef71c2017-05-08 16:36:17 -0700402{
403 if (enabled)
404 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700405 body->sensor_initialization |= 1 << 2;
Emily Shafferbbef71c2017-05-08 16:36:17 -0700406 }
407 else
408 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700409 body->sensor_initialization &= ~(1 << 2);
Emily Shafferbbef71c2017-05-08 16:36:17 -0700410 }
411};
Patrick Venture0b02be92018-08-31 11:55:55 -0700412inline void init_hyst_state(bool enabled, SensorDataFullRecordBody* body)
Emily Shafferbbef71c2017-05-08 16:36:17 -0700413{
414 if (enabled)
415 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700416 body->sensor_initialization |= 1 << 3;
Emily Shafferbbef71c2017-05-08 16:36:17 -0700417 }
418 else
419 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700420 body->sensor_initialization &= ~(1 << 3);
Emily Shafferbbef71c2017-05-08 16:36:17 -0700421 }
422};
Patrick Venture0b02be92018-08-31 11:55:55 -0700423inline void init_thresh_state(bool enabled, SensorDataFullRecordBody* body)
Emily Shafferbbef71c2017-05-08 16:36:17 -0700424{
425 if (enabled)
426 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700427 body->sensor_initialization |= 1 << 4;
Emily Shafferbbef71c2017-05-08 16:36:17 -0700428 }
429 else
430 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700431 body->sensor_initialization &= ~(1 << 4);
Emily Shafferbbef71c2017-05-08 16:36:17 -0700432 }
433};
Patrick Venture0b02be92018-08-31 11:55:55 -0700434inline void init_events_state(bool enabled, SensorDataFullRecordBody* body)
Emily Shafferbbef71c2017-05-08 16:36:17 -0700435{
436 if (enabled)
437 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700438 body->sensor_initialization |= 1 << 5;
Emily Shafferbbef71c2017-05-08 16:36:17 -0700439 }
440 else
441 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700442 body->sensor_initialization &= ~(1 << 5);
Emily Shafferbbef71c2017-05-08 16:36:17 -0700443 }
444};
Patrick Venture0b02be92018-08-31 11:55:55 -0700445inline void init_scanning_state(bool enabled, SensorDataFullRecordBody* body)
Emily Shafferbbef71c2017-05-08 16:36:17 -0700446{
447 if (enabled)
448 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700449 body->sensor_initialization |= 1 << 6;
Emily Shafferbbef71c2017-05-08 16:36:17 -0700450 }
451 else
452 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700453 body->sensor_initialization &= ~(1 << 6);
Emily Shafferbbef71c2017-05-08 16:36:17 -0700454 }
455};
Patrick Venture0b02be92018-08-31 11:55:55 -0700456inline void init_settable_state(bool enabled, SensorDataFullRecordBody* body)
Emily Shafferbbef71c2017-05-08 16:36:17 -0700457{
458 if (enabled)
459 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700460 body->sensor_initialization |= 1 << 7;
Emily Shafferbbef71c2017-05-08 16:36:17 -0700461 }
462 else
463 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700464 body->sensor_initialization &= ~(1 << 7);
Emily Shafferbbef71c2017-05-08 16:36:17 -0700465 }
466};
467
468inline void set_percentage(SensorDataFullRecordBody* body)
469{
Patrick Venture0b02be92018-08-31 11:55:55 -0700470 body->sensor_units_1 |= 1 << 0;
Emily Shafferbbef71c2017-05-08 16:36:17 -0700471};
472inline void unset_percentage(SensorDataFullRecordBody* body)
473{
Patrick Venture0b02be92018-08-31 11:55:55 -0700474 body->sensor_units_1 &= ~(1 << 0);
Emily Shafferbbef71c2017-05-08 16:36:17 -0700475};
476inline void set_modifier_operation(uint8_t op, SensorDataFullRecordBody* body)
477{
Patrick Venture0b02be92018-08-31 11:55:55 -0700478 body->sensor_units_1 &= ~(3 << 1);
479 body->sensor_units_1 |= (op & 0x3) << 1;
Emily Shafferbbef71c2017-05-08 16:36:17 -0700480};
481inline void set_rate_unit(uint8_t unit, SensorDataFullRecordBody* body)
482{
Patrick Venture0b02be92018-08-31 11:55:55 -0700483 body->sensor_units_1 &= ~(7 << 3);
484 body->sensor_units_1 |= (unit & 0x7) << 3;
Emily Shafferbbef71c2017-05-08 16:36:17 -0700485};
486inline void set_analog_data_format(uint8_t format,
487 SensorDataFullRecordBody* body)
488{
Patrick Venture0b02be92018-08-31 11:55:55 -0700489 body->sensor_units_1 &= ~(3 << 6);
490 body->sensor_units_1 |= (format & 0x3) << 6;
Emily Shafferbbef71c2017-05-08 16:36:17 -0700491};
492
Emily Shaffer7cad3fc2017-08-30 17:50:37 -0700493inline void set_m(uint16_t m, SensorDataFullRecordBody* body)
Emily Shafferbbef71c2017-05-08 16:36:17 -0700494{
495 body->m_lsb = m & 0xff;
Patrick Venture0b02be92018-08-31 11:55:55 -0700496 body->m_msb_and_tolerance &= ~(3 << 6);
497 body->m_msb_and_tolerance |= ((m & (3 << 8)) >> 2);
Emily Shafferbbef71c2017-05-08 16:36:17 -0700498};
499inline void set_tolerance(uint8_t tol, SensorDataFullRecordBody* body)
500{
501 body->m_msb_and_tolerance &= ~0x3f;
502 body->m_msb_and_tolerance |= tol & 0x3f;
503};
504
Emily Shaffer7cad3fc2017-08-30 17:50:37 -0700505inline void set_b(uint16_t b, SensorDataFullRecordBody* body)
Emily Shafferbbef71c2017-05-08 16:36:17 -0700506{
507 body->b_lsb = b & 0xff;
Patrick Venture0b02be92018-08-31 11:55:55 -0700508 body->b_msb_and_accuracy_lsb &= ~(3 << 6);
509 body->b_msb_and_accuracy_lsb |= ((b & (3 << 8)) >> 2);
Emily Shafferbbef71c2017-05-08 16:36:17 -0700510};
Emily Shaffer7cad3fc2017-08-30 17:50:37 -0700511inline void set_accuracy(uint16_t acc, SensorDataFullRecordBody* body)
Emily Shafferbbef71c2017-05-08 16:36:17 -0700512{
Emily Shaffer7cad3fc2017-08-30 17:50:37 -0700513 // bottom 6 bits
Emily Shafferbbef71c2017-05-08 16:36:17 -0700514 body->b_msb_and_accuracy_lsb &= ~0x3f;
515 body->b_msb_and_accuracy_lsb |= acc & 0x3f;
Emily Shaffer7cad3fc2017-08-30 17:50:37 -0700516 // top 4 bits
Emily Shafferbbef71c2017-05-08 16:36:17 -0700517 body->accuracy_and_sensor_direction &= 0x0f;
Emily Shaffer7cad3fc2017-08-30 17:50:37 -0700518 body->accuracy_and_sensor_direction |= ((acc >> 6) & 0xf) << 4;
Emily Shafferbbef71c2017-05-08 16:36:17 -0700519};
520inline void set_accuracy_exp(uint8_t exp, SensorDataFullRecordBody* body)
521{
Patrick Venture0b02be92018-08-31 11:55:55 -0700522 body->accuracy_and_sensor_direction &= ~(3 << 2);
523 body->accuracy_and_sensor_direction |= (exp & 3) << 2;
Emily Shafferbbef71c2017-05-08 16:36:17 -0700524};
525inline void set_sensor_dir(uint8_t dir, SensorDataFullRecordBody* body)
526{
Patrick Venture0b02be92018-08-31 11:55:55 -0700527 body->accuracy_and_sensor_direction &= ~(3 << 0);
Emily Shafferbbef71c2017-05-08 16:36:17 -0700528 body->accuracy_and_sensor_direction |= (dir & 3);
529};
530
531inline void set_b_exp(uint8_t exp, SensorDataFullRecordBody* body)
532{
533 body->r_b_exponents &= 0xf0;
534 body->r_b_exponents |= exp & 0x0f;
535};
536inline void set_r_exp(uint8_t exp, SensorDataFullRecordBody* body)
537{
538 body->r_b_exponents &= 0x0f;
Patrick Venture0b02be92018-08-31 11:55:55 -0700539 body->r_b_exponents |= (exp & 0x0f) << 4;
Emily Shafferbbef71c2017-05-08 16:36:17 -0700540};
541
542inline void set_id_strlen(uint8_t len, SensorDataFullRecordBody* body)
543{
544 body->id_string_info &= ~(0x1f);
545 body->id_string_info |= len & 0x1f;
546};
Patrick Venture0b02be92018-08-31 11:55:55 -0700547inline uint8_t get_id_strlen(SensorDataFullRecordBody* body)
Emily Shafferbbef71c2017-05-08 16:36:17 -0700548{
549 return body->id_string_info & 0x1f;
550};
551inline void set_id_type(uint8_t type, SensorDataFullRecordBody* body)
552{
Patrick Venture0b02be92018-08-31 11:55:55 -0700553 body->id_string_info &= ~(3 << 6);
554 body->id_string_info |= (type & 0x3) << 6;
Emily Shafferbbef71c2017-05-08 16:36:17 -0700555};
556
Ratan Guptae0cc8552018-01-22 14:23:04 +0530557inline void set_device_id_strlen(uint8_t len, SensorDataFruRecordBody* body)
558{
559 body->deviceIDLen &= ~(LENGTH_MASK);
560 body->deviceIDLen |= len & LENGTH_MASK;
561};
562
563inline uint8_t get_device_id_strlen(SensorDataFruRecordBody* body)
564{
565 return body->deviceIDLen & LENGTH_MASK;
566};
567
Tom Josephdc212b22018-02-16 09:59:57 +0530568inline void set_readable_mask(uint8_t mask, SensorDataFullRecordBody* body)
569{
570 body->discrete_reading_setting_mask[1] = mask & 0x3F;
571}
572
Emily Shafferbbef71c2017-05-08 16:36:17 -0700573} // namespace body
574
575// More types contained in section 43.17 Sensor Unit Type Codes,
576// IPMI spec v2 rev 1.1
577enum SensorUnitTypeCodes
578{
579 SENSOR_UNIT_UNSPECIFIED = 0,
580 SENSOR_UNIT_DEGREES_C = 1,
581 SENSOR_UNIT_VOLTS = 4,
582 SENSOR_UNIT_AMPERES = 5,
Tom Josephdc212b22018-02-16 09:59:57 +0530583 SENSOR_UNIT_WATTS = 6,
Emily Shafferbbef71c2017-05-08 16:36:17 -0700584 SENSOR_UNIT_JOULES = 7,
Kirill Pakhomov812e44c2018-10-22 16:25:35 +0300585 SENSOR_UNIT_RPM = 18,
Emily Shafferbbef71c2017-05-08 16:36:17 -0700586 SENSOR_UNIT_METERS = 34,
587 SENSOR_UNIT_REVOLUTIONS = 41,
588};
589
590struct SensorDataFullRecord
591{
592 SensorDataRecordHeader header;
593 SensorDataRecordKey key;
594 SensorDataFullRecordBody body;
595} __attribute__((packed));
596
Ratan Guptae0cc8552018-01-22 14:23:04 +0530597/** @struct SensorDataFruRecord
598 *
599 * FRU Device Locator Record - SDR Type 11
600 */
601struct SensorDataFruRecord
602{
603 SensorDataRecordHeader header;
604 SensorDataFruRecordKey key;
605 SensorDataFruRecordBody body;
606} __attribute__((packed));
607
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -0800608/** @struct SensorDataEntityRecord
609 *
610 * Entity Association Record - SDR Type 8
611 */
612struct SensorDataEntityRecord
613{
614 SensorDataRecordHeader header;
615 SensorDataEntityRecordKey key;
616 SensorDataEntityRecordBody body;
617} __attribute__((packed));
618
Patrick Venture0b02be92018-08-31 11:55:55 -0700619} // namespace get_sdr
Tom Joseph816e92b2017-09-06 19:23:00 +0530620
621namespace ipmi
622{
623
624namespace sensor
625{
626
627/**
628 * @brief Map offset to the corresponding bit in the assertion byte.
629 *
Gunnar Mills8991dd62017-10-25 17:11:29 -0500630 * The discrete sensors support up to 14 states. 0-7 offsets are stored in one
Tom Joseph816e92b2017-09-06 19:23:00 +0530631 * byte and offsets 8-14 in the second byte.
632 *
633 * @param[in] offset - offset number.
634 * @param[in/out] resp - get sensor reading response.
635 */
636inline void setOffset(uint8_t offset, ipmi::sensor::GetReadingResponse* resp)
637{
638 if (offset > 7)
639 {
640 resp->assertOffset8_14 |= 1 << (offset - 8);
641 }
642 else
643 {
644 resp->assertOffset0_7 |= 1 << offset;
645 }
646}
647
Tom Josephe4014fc2017-09-06 23:57:36 +0530648/**
649 * @brief Set the reading field in the response.
650 *
651 * @param[in] offset - offset number.
652 * @param[in/out] resp - get sensor reading response.
653 */
654inline void setReading(uint8_t value, ipmi::sensor::GetReadingResponse* resp)
655{
656 resp->reading = value;
657}
658
Tom Joseph295f17e2017-09-07 00:09:46 +0530659/**
660 * @brief Map the value to the assertion bytes. The assertion states are stored
661 * in 2 bytes.
662 *
663 * @param[in] value - value to mapped to the assertion byte.
664 * @param[in/out] resp - get sensor reading response.
665 */
666inline void setAssertionBytes(uint16_t value,
667 ipmi::sensor::GetReadingResponse* resp)
668{
669 resp->assertOffset0_7 = static_cast<uint8_t>(value & 0x00FF);
670 resp->assertOffset8_14 = static_cast<uint8_t>(value >> 8);
671}
672
Tom Josephe05b2922017-09-07 00:43:16 +0530673/**
674 * @brief Set the scanning enabled bit in the response.
675 *
676 * @param[in/out] resp - get sensor reading response.
677 */
678inline void enableScanning(ipmi::sensor::GetReadingResponse* resp)
679{
680 resp->operation = 1 << 6;
681}
682
Tom Joseph816e92b2017-09-06 19:23:00 +0530683} // namespace sensor
684
685} // namespace ipmi