xref: /openbmc/fb-ipmi-oem/include/sdrutils.hpp (revision 63c99be4)
1 #pragma once
2 
3 #include <ipmid/api.h>
4 #include <stdint.h>
5 
6 #include <ipmid/types.hpp>
7 
8 /**
9  * Get SDR
10  */
11 namespace get_sdr
12 {
13 
14 // Response
15 struct GetSdrResp
16 {
17     uint8_t next_record_id_lsb;
18     uint8_t next_record_id_msb;
19     uint8_t record_data[64];
20 } __attribute__((packed));
21 
22 // Record header
23 struct SensorDataRecordHeader
24 {
25     uint8_t record_id_lsb;
26     uint8_t record_id_msb;
27     uint8_t sdr_version;
28     uint8_t record_type;
29     uint8_t record_length; // Length not counting the header
30 } __attribute__((packed));
31 
32 enum SensorDataRecordType
33 {
34     SENSOR_DATA_FULL_RECORD = 0x1,
35     SENSOR_DATA_FRU_RECORD = 0x11,
36     SENSOR_DATA_ENTITY_RECORD = 0x8,
37 };
38 
39 // Record key
40 struct SensorDataRecordKey
41 {
42     uint8_t owner_id;
43     uint8_t owner_lun;
44     uint8_t sensor_number;
45 } __attribute__((packed));
46 
47 /** @struct SensorDataFruRecordKey
48  *
49  *  FRU Device Locator Record(key) - SDR Type 11
50  */
51 struct SensorDataFruRecordKey
52 {
53     uint8_t deviceAddress;
54     uint8_t fruID;
55     uint8_t accessLun;
56     uint8_t channelNumber;
57 } __attribute__((packed));
58 
59 // Body - full record
60 #define FULL_RECORD_ID_STR_MAX_LENGTH 16
61 
62 static const int FRU_RECORD_DEVICE_ID_MAX_LENGTH = 16;
63 
64 struct SensorDataFullRecordBody
65 {
66     uint8_t entity_id;
67     uint8_t entity_instance;
68     uint8_t sensor_initialization;
69     uint8_t sensor_capabilities; // no macro support
70     uint8_t sensor_type;
71     uint8_t event_reading_type;
72     uint8_t supported_assertions[2];          // no macro support
73     uint8_t supported_deassertions[2];        // no macro support
74     uint8_t discrete_reading_setting_mask[2]; // no macro support
75     uint8_t sensor_units_1;
76     uint8_t sensor_units_2_base;
77     uint8_t sensor_units_3_modifier;
78     uint8_t linearization;
79     uint8_t m_lsb;
80     uint8_t m_msb_and_tolerance;
81     uint8_t b_lsb;
82     uint8_t b_msb_and_accuracy_lsb;
83     uint8_t accuracy_and_sensor_direction;
84     uint8_t r_b_exponents;
85     uint8_t analog_characteristic_flags; // no macro support
86     uint8_t nominal_reading;
87     uint8_t normal_max;
88     uint8_t normal_min;
89     uint8_t sensor_max;
90     uint8_t sensor_min;
91     uint8_t upper_nonrecoverable_threshold;
92     uint8_t upper_critical_threshold;
93     uint8_t upper_noncritical_threshold;
94     uint8_t lower_nonrecoverable_threshold;
95     uint8_t lower_critical_threshold;
96     uint8_t lower_noncritical_threshold;
97     uint8_t positive_threshold_hysteresis;
98     uint8_t negative_threshold_hysteresis;
99     uint16_t reserved;
100     uint8_t oem_reserved;
101     uint8_t id_string_info;
102     char id_string[FULL_RECORD_ID_STR_MAX_LENGTH];
103 } __attribute__((packed));
104 
105 /** @struct SensorDataFruRecordBody
106  *
107  *  FRU Device Locator Record(body) - SDR Type 11
108  */
109 struct SensorDataFruRecordBody
110 {
111     uint8_t reserved;
112     uint8_t deviceType;
113     uint8_t deviceTypeModifier;
114     uint8_t entityID;
115     uint8_t entityInstance;
116     uint8_t oem;
117     uint8_t deviceIDLen;
118     char deviceID[FRU_RECORD_DEVICE_ID_MAX_LENGTH];
119 } __attribute__((packed));
120 
121 struct SensorDataFullRecord
122 {
123     SensorDataRecordHeader header;
124     SensorDataRecordKey key;
125     SensorDataFullRecordBody body;
126 } __attribute__((packed));
127 
128 /** @struct SensorDataFruRecord
129  *
130  *  FRU Device Locator Record - SDR Type 11
131  */
132 struct SensorDataFruRecord
133 {
134     SensorDataRecordHeader header;
135     SensorDataFruRecordKey key;
136     SensorDataFruRecordBody body;
137 } __attribute__((packed));
138 
139 } // namespace get_sdr
140