blob: 865427fc7d40fda3511c60fc823da93f024ba408 [file] [log] [blame]
Jason M. Bills3f7c5e42018-10-03 14:00:41 -07001/*
2// Copyright (c) 2017 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16
17#pragma once
Vernon Mauerye035c582023-06-06 15:15:14 -070018#include <ipmid/api-types.hpp>
19#include <ipmid/api.hpp>
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070020
James Feistfcd2d3a2020-05-28 10:38:15 -070021#include <cstdint>
22
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070023static constexpr uint8_t ipmiSdrVersion = 0x51;
24
Jason M. Billsc04e2e72018-11-28 15:15:56 -080025namespace intel_oem::ipmi::sel
26{
Jason M. Billsc04e2e72018-11-28 15:15:56 -080027static constexpr uint8_t selOperationSupport = 0x02;
28static constexpr uint8_t systemEvent = 0x02;
29static constexpr size_t systemEventSize = 3;
30static constexpr uint8_t oemTsEventFirst = 0xC0;
31static constexpr uint8_t oemTsEventLast = 0xDF;
32static constexpr size_t oemTsEventSize = 9;
33static constexpr uint8_t oemEventFirst = 0xE0;
34static constexpr uint8_t oemEventLast = 0xFF;
35static constexpr size_t oemEventSize = 13;
36static constexpr uint8_t eventMsgRev = 0x04;
37} // namespace intel_oem::ipmi::sel
38
Vernon Mauerye035c582023-06-06 15:15:14 -070039//////////////////////////////////////////////////////////////////////////////
40//
41// blurbs from ipmi-host/sensorhandler.hpp
42//
43//////////////////////////////////////////////////////////////////////////////
44static constexpr int FULL_RECORD_ID_STR_MAX_LENGTH = 16;
45namespace get_sdr
46{
47// Record header
48struct SensorDataRecordHeader
49{
50 uint8_t record_id_lsb;
51 uint8_t record_id_msb;
52 uint8_t sdr_version;
53 uint8_t record_type;
54 uint8_t record_length; // Length not counting the header
55} __attribute__((packed));
56
57namespace header
58{
59
60inline void set_record_id(int id, SensorDataRecordHeader* hdr)
61{
62 hdr->record_id_lsb = (id & 0xFF);
63 hdr->record_id_msb = (id >> 8) & 0xFF;
64};
65
66} // namespace header
67
68/** @struct SensorDataFruRecordKey
69 *
70 * FRU Device Locator Record(key) - SDR Type 11
71 */
72struct SensorDataFruRecordKey
73{
74 uint8_t deviceAddress;
75 uint8_t fruID;
76 uint8_t accessLun;
77 uint8_t channelNumber;
78} __attribute__((packed));
79
80static constexpr int FRU_RECORD_DEVICE_ID_MAX_LENGTH = 16;
81
82/** @struct SensorDataFruRecordBody
83 *
84 * FRU Device Locator Record(body) - SDR Type 11
85 */
86struct SensorDataFruRecordBody
87{
88 uint8_t reserved;
89 uint8_t deviceType;
90 uint8_t deviceTypeModifier;
91 uint8_t entityID;
92 uint8_t entityInstance;
93 uint8_t oem;
94 uint8_t deviceIDLen;
95 char deviceID[FRU_RECORD_DEVICE_ID_MAX_LENGTH];
96} __attribute__((packed));
97
98/** @struct SensorDataFruRecord
99 *
100 * FRU Device Locator Record - SDR Type 11
101 */
102struct SensorDataFruRecord
103{
104 SensorDataRecordHeader header;
105 SensorDataFruRecordKey key;
106 SensorDataFruRecordBody body;
107} __attribute__((packed));
108
109enum SensorDataRecordType
110{
111 SENSOR_DATA_FULL_RECORD = 0x1,
112 SENSOR_DATA_EVENT_RECORD = 0x3,
113 SENSOR_DATA_FRU_RECORD = 0x11,
114 SENSOR_DATA_ENTITY_RECORD = 0x8,
115};
116
117// Record key
118struct SensorDataRecordKey
119{
120 uint8_t owner_id;
121 uint8_t owner_lun;
122 uint8_t sensor_number;
123} __attribute__((packed));
124
125struct SensorDataFullRecordBody
126{
127 uint8_t entity_id;
128 uint8_t entity_instance;
129 uint8_t sensor_initialization;
130 uint8_t sensor_capabilities; // no macro support
131 uint8_t sensor_type;
132 uint8_t event_reading_type;
133 uint8_t supported_assertions[2]; // no macro support
134 uint8_t supported_deassertions[2]; // no macro support
135 uint8_t discrete_reading_setting_mask[2]; // no macro support
136 uint8_t sensor_units_1;
137 uint8_t sensor_units_2_base;
138 uint8_t sensor_units_3_modifier;
139 uint8_t linearization;
140 uint8_t m_lsb;
141 uint8_t m_msb_and_tolerance;
142 uint8_t b_lsb;
143 uint8_t b_msb_and_accuracy_lsb;
144 uint8_t accuracy_and_sensor_direction;
145 uint8_t r_b_exponents;
146 uint8_t analog_characteristic_flags; // no macro support
147 uint8_t nominal_reading;
148 uint8_t normal_max;
149 uint8_t normal_min;
150 uint8_t sensor_max;
151 uint8_t sensor_min;
152 uint8_t upper_nonrecoverable_threshold;
153 uint8_t upper_critical_threshold;
154 uint8_t upper_noncritical_threshold;
155 uint8_t lower_nonrecoverable_threshold;
156 uint8_t lower_critical_threshold;
157 uint8_t lower_noncritical_threshold;
158 uint8_t positive_threshold_hysteresis;
159 uint8_t negative_threshold_hysteresis;
160 uint16_t reserved;
161 uint8_t oem_reserved;
162 uint8_t id_string_info;
163 char id_string[FULL_RECORD_ID_STR_MAX_LENGTH];
164} __attribute__((packed));
165
166struct SensorDataFullRecord
167{
168 SensorDataRecordHeader header;
169 SensorDataRecordKey key;
170 SensorDataFullRecordBody body;
171} __attribute__((packed));
172
173namespace body
174{
175inline void set_id_strlen(uint8_t len, SensorDataFullRecordBody* body)
176{
177 body->id_string_info &= ~(0x1f);
178 body->id_string_info |= len & 0x1f;
179};
180inline void set_id_type(uint8_t type, SensorDataFullRecordBody* body)
181{
182 body->id_string_info &= ~(3 << 6);
183 body->id_string_info |= (type & 0x3) << 6;
184};
185} // namespace body
186} // namespace get_sdr
187//////////////////////////////////////////////////////////////////////////////
188//
189// <end> blurbs from ipmi-host/sensorhandler.hpp
190//
191//////////////////////////////////////////////////////////////////////////////
192
193//////////////////////////////////////////////////////////////////////////////
194//
195// blurbs from ipmi-host/selutility.hpp
196//
197//////////////////////////////////////////////////////////////////////////////
198namespace ipmi::sel
199{
200static constexpr auto firstEntry = 0x0000;
201static constexpr auto lastEntry = 0xFFFF;
202static constexpr auto entireRecord = 0xFF;
203static constexpr auto selVersion = 0x51;
204static constexpr auto invalidTimeStamp = 0xFFFFFFFF;
205static constexpr auto getEraseStatus = 0x00;
206static constexpr auto eraseComplete = 0x01;
207static constexpr auto initiateErase = 0xAA;
208
209} // namespace ipmi::sel
210//////////////////////////////////////////////////////////////////////////////
211//
212// <end> blurbs from ipmi-host/selutility.hpp
213//
214//////////////////////////////////////////////////////////////////////////////
215
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700216#pragma pack(push, 1)
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700217struct GetSDRReq
218{
219 uint16_t reservationID;
220 uint16_t recordID;
221 uint8_t offset;
222 uint8_t bytesToRead;
223};
224#pragma pack(pop)
225
226enum class SdrRepositoryInfoOps : uint8_t
227{
228 allocCommandSupported = 0x1,
229 reserveSDRRepositoryCommandSupported = 0x2,
230 partialAddSDRSupported = 0x4,
231 deleteSDRSupported = 0x8,
232 reserved = 0x10,
233 modalLSB = 0x20,
234 modalMSB = 0x40,
235 overflow = 0x80
236};
237
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700238enum class GetFRUAreaAccessType : uint8_t
239{
240 byte = 0x0,
241 words = 0x1
242};
243
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700244enum class SensorUnits : uint8_t
245{
246 unspecified = 0x0,
247 degreesC = 0x1,
248 volts = 0x4,
249 amps = 0x5,
250 watts = 0x6,
251 rpm = 0x12,
252};
253
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700254#pragma pack(push, 1)
255struct FRUHeader
256{
257 uint8_t commonHeaderFormat;
258 uint8_t internalOffset;
259 uint8_t chassisOffset;
260 uint8_t boardOffset;
261 uint8_t productOffset;
262 uint8_t multiRecordOffset;
263 uint8_t pad;
264 uint8_t checksum;
265};
266#pragma pack(pop)
267
James Feist74c50c62019-08-14 14:18:41 -0700268#pragma pack(push, 1)
269struct Type12Record
270{
271 get_sdr::SensorDataRecordHeader header;
Matt Simmering80d4d5f2023-02-15 15:18:51 -0800272 uint8_t targetAddress;
James Feist74c50c62019-08-14 14:18:41 -0700273 uint8_t channelNumber;
274 uint8_t powerStateNotification;
275 uint8_t deviceCapabilities;
Johnathan Manteyf4d5e052021-09-22 12:58:08 -0700276 // define reserved bytes explicitly. The uint24_t is silently expanded to
277 // uint32_t, which ruins the byte alignment required by this structure.
278 uint8_t reserved[3];
James Feist74c50c62019-08-14 14:18:41 -0700279 uint8_t entityID;
280 uint8_t entityInstance;
281 uint8_t oem;
282 uint8_t typeLengthCode;
283 char name[16];
Johnathan Manteyf4d5e052021-09-22 12:58:08 -0700284
285 Type12Record(uint16_t recordID, uint8_t address, uint8_t chNumber,
286 uint8_t pwrStateNotification, uint8_t capabilities,
287 uint8_t eid, uint8_t entityInst, uint8_t mfrDefined,
288 const std::string& sensorname) :
Matt Simmering80d4d5f2023-02-15 15:18:51 -0800289 targetAddress(address),
Johnathan Manteyf4d5e052021-09-22 12:58:08 -0700290 channelNumber(chNumber), powerStateNotification(pwrStateNotification),
291 deviceCapabilities(capabilities), reserved{}, entityID(eid),
292 entityInstance(entityInst), oem(mfrDefined)
293 {
294 get_sdr::header::set_record_id(recordID, &header);
295 header.sdr_version = ipmiSdrVersion;
296 header.record_type = 0x12;
297 size_t nameLen = std::min(sensorname.size(), sizeof(name));
298 header.record_length = sizeof(Type12Record) -
299 sizeof(get_sdr::SensorDataRecordHeader) -
300 sizeof(name) + nameLen;
301 typeLengthCode = 0xc0 | nameLen;
302 std::copy(sensorname.begin(), sensorname.begin() + nameLen, name);
303 }
James Feist74c50c62019-08-14 14:18:41 -0700304};
305#pragma pack(pop)
306
Yong Lifee5e4c2020-01-17 19:36:29 +0800307#pragma pack(push, 1)
308struct NMDiscoveryRecord
309{
310 get_sdr::SensorDataRecordHeader header;
311 uint8_t oemID0;
312 uint8_t oemID1;
313 uint8_t oemID2;
314 uint8_t subType;
315 uint8_t version;
Matt Simmering80d4d5f2023-02-15 15:18:51 -0800316 uint8_t targetAddress;
Yong Lifee5e4c2020-01-17 19:36:29 +0800317 uint8_t channelNumber;
318 uint8_t healthEventSensor;
319 uint8_t exceptionEventSensor;
320 uint8_t operationalCapSensor;
321 uint8_t thresholdExceededSensor;
322};
323#pragma pack(pop)
324
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700325namespace ipmi
326{
327namespace storage
328{
James Feist74c50c62019-08-14 14:18:41 -0700329
Yong Lifee5e4c2020-01-17 19:36:29 +0800330constexpr const size_t nmDiscoverySDRCount = 1;
James Feist74c50c62019-08-14 14:18:41 -0700331constexpr const size_t type12Count = 2;
Vernon Mauerydcff1502022-09-28 11:12:46 -0700332ipmi::Cc getFruSdrs(ipmi::Context::ptr& ctx, size_t index,
333 get_sdr::SensorDataFruRecord& resp);
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700334
Vernon Mauerydcff1502022-09-28 11:12:46 -0700335ipmi::Cc getFruSdrCount(ipmi::Context::ptr& ctx, size_t& count);
James Feist74c50c62019-08-14 14:18:41 -0700336
337std::vector<uint8_t> getType12SDRs(uint16_t index, uint16_t recordId);
Yong Lifee5e4c2020-01-17 19:36:29 +0800338std::vector<uint8_t> getNMDiscoverySDR(uint16_t index, uint16_t recordId);
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700339} // namespace storage
340} // namespace ipmi