blob: a9fecf8526c8af043167358d3116df42088f2382 [file] [log] [blame]
Matt Spinlerf9bae182019-10-09 13:37:38 -05001#pragma once
2
3#include "additional_data.hpp"
4#include "ascii_string.hpp"
5#include "callouts.hpp"
Matt Spinler075e5ba2020-02-21 15:46:00 -06006#include "data_interface.hpp"
Matt Spinlerf9bae182019-10-09 13:37:38 -05007#include "pel_types.hpp"
Matt Spinlerbd716f02019-10-15 10:54:11 -05008#include "registry.hpp"
Matt Spinlerf9bae182019-10-09 13:37:38 -05009#include "section.hpp"
10#include "stream.hpp"
11
12namespace openpower
13{
14namespace pels
15{
16
Matt Spinlerbd716f02019-10-15 10:54:11 -050017constexpr uint8_t srcSectionVersion = 0x01;
18constexpr uint8_t srcSectionSubtype = 0x01;
Matt Spinlerf9bae182019-10-09 13:37:38 -050019constexpr size_t numSRCHexDataWords = 8;
Matt Spinlerbd716f02019-10-15 10:54:11 -050020constexpr uint8_t srcVersion = 0x02;
21constexpr uint8_t bmcSRCFormat = 0x55;
22constexpr uint8_t primaryBMCPosition = 0x10;
23constexpr size_t baseSRCSize = 72;
Matt Spinlerf9bae182019-10-09 13:37:38 -050024
Harisuddin Mohamed Isa0f717e12020-01-15 20:05:33 +080025enum class DetailLevel
26{
27 message = 0x01,
28 json = 0x02
29};
Matt Spinlerf9bae182019-10-09 13:37:38 -050030/**
31 * @class SRC
32 *
33 * SRC stands for System Reference Code.
34 *
35 * This class represents the SRC sections in the PEL, of which there are 2:
36 * primary SRC and secondary SRC. These are the same structurally, the
37 * difference is that the primary SRC must be the 3rd section in the PEL if
38 * present and there is only one of them, and the secondary SRC sections are
39 * optional and there can be more than one (by definition, for there to be a
40 * secondary SRC, a primary SRC must also exist).
41 *
42 * This section consists of:
43 * - An 8B header (Has the version, flags, hexdata word count, and size fields)
44 * - 8 4B words of hex data
45 * - An ASCII character string
46 * - An optional subsection for Callouts
47 */
48class SRC : public Section
49{
50 public:
51 enum HeaderFlags
52 {
Matt Spinlerbd716f02019-10-15 10:54:11 -050053 additionalSections = 0x01,
Harisuddin Mohamed Isa0f717e12020-01-15 20:05:33 +080054 powerFaultEvent = 0x02,
55 hypDumpInit = 0x04,
56 i5OSServiceEventBit = 0x10,
57 virtualProgressSRC = 0x80
Matt Spinlerf9bae182019-10-09 13:37:38 -050058 };
59
60 SRC() = delete;
61 ~SRC() = default;
62 SRC(const SRC&) = delete;
63 SRC& operator=(const SRC&) = delete;
64 SRC(SRC&&) = delete;
65 SRC& operator=(SRC&&) = delete;
66
67 /**
68 * @brief Constructor
69 *
70 * Fills in this class's data fields from the stream.
71 *
72 * @param[in] pel - the PEL data stream
73 */
74 explicit SRC(Stream& pel);
75
76 /**
Matt Spinlerbd716f02019-10-15 10:54:11 -050077 * @brief Constructor
78 *
79 * Creates the section with data from the PEL message registry entry for
80 * this error, along with the AdditionalData property contents from the
81 * corresponding event log.
82 *
83 * @param[in] regEntry - The message registry entry for this event log
84 * @param[in] additionalData - The AdditionalData properties in this event
85 * log
Matt Spinler075e5ba2020-02-21 15:46:00 -060086 * @param[in] dataIface - The DataInterface object
Matt Spinlerbd716f02019-10-15 10:54:11 -050087 */
Matt Spinler075e5ba2020-02-21 15:46:00 -060088 SRC(const message::Entry& regEntry, const AdditionalData& additionalData,
89 const DataInterfaceBase& dataIface);
Matt Spinlerbd716f02019-10-15 10:54:11 -050090
91 /**
Matt Spinlerf9bae182019-10-09 13:37:38 -050092 * @brief Flatten the section into the stream
93 *
94 * @param[in] stream - The stream to write to
95 */
Matt Spinler06885452019-11-06 10:35:42 -060096 void flatten(Stream& stream) const override;
Matt Spinlerf9bae182019-10-09 13:37:38 -050097
98 /**
99 * @brief Returns the SRC version, which is a different field
100 * than the version byte in the section header.
101 *
102 * @return uint8_t
103 */
104 uint8_t version() const
105 {
106 return _version;
107 }
108
109 /**
110 * @brief Returns the flags byte
111 *
112 * @return uint8_t
113 */
114 uint8_t flags() const
115 {
116 return _flags;
117 }
118
119 /**
120 * @brief Returns the hex data word count.
121 *
122 * Even though there always 8 words, this returns 9 due to previous
123 * SRC version formats.
124 *
125 * @return uint8_t
126 */
127 uint8_t hexWordCount() const
128 {
129 return _wordCount;
130 }
131
132 /**
133 * @brief Returns the size of the SRC section, not including the header.
134 *
135 * @return uint16_t
136 */
137 uint16_t size() const
138 {
139 return _size;
140 }
141
142 /**
143 * @brief Returns the 8 hex data words.
144 *
145 * @return const std::array<uint32_t, numSRCHexDataWords>&
146 */
147 const std::array<uint32_t, numSRCHexDataWords>& hexwordData() const
148 {
149 return _hexData;
150 }
151
152 /**
153 * @brief Returns the ASCII string
154 *
155 * @return std::string
156 */
157 std::string asciiString() const
158 {
159 return _asciiString->get();
160 }
161
162 /**
163 * @brief Returns the callouts subsection
164 *
165 * If no callouts, this unique_ptr will be empty
166 *
167 * @return const std::unique_ptr<src::Callouts>&
168 */
169 const std::unique_ptr<src::Callouts>& callouts() const
170 {
171 return _callouts;
172 }
173
Matt Spinlerf9bae182019-10-09 13:37:38 -0500174 /**
Matt Spinlerbd716f02019-10-15 10:54:11 -0500175 * @brief Returns the size of this section when flattened into a PEL
Matt Spinlerf9bae182019-10-09 13:37:38 -0500176 *
Matt Spinlerbd716f02019-10-15 10:54:11 -0500177 * @return size_t - the size of the section
Matt Spinlerf9bae182019-10-09 13:37:38 -0500178 */
Matt Spinlerbd716f02019-10-15 10:54:11 -0500179 size_t flattenedSize() const
180 {
181 return _header.size;
182 }
Matt Spinlerf9bae182019-10-09 13:37:38 -0500183
184 /**
185 * @brief Says if this SRC has additional subsections in it
186 *
187 * Note: The callouts section is the only possible subsection.
188 *
189 * @return bool
190 */
191 inline bool hasAdditionalSections() const
192 {
Matt Spinlerbd716f02019-10-15 10:54:11 -0500193 return _flags & additionalSections;
194 }
195
196 /**
197 * @brief Indicates if this event log is for a power fault.
198 *
199 * This comes from a field in the message registry for BMC
200 * generated PELs.
201 *
202 * @return bool
203 */
204 inline bool isPowerFaultEvent() const
205 {
206 return _flags & powerFaultEvent;
207 }
208
Matt Spinlerc63e2e82019-12-02 15:50:12 -0600209 /**
210 * @brief Get the _hexData[] index to use based on the corresponding
211 * SRC word number.
212 *
213 * Converts the specification nomenclature to this data structure.
214 * See the _hexData documentation below for more information.
215 *
216 * @param[in] wordNum - The SRC word number, as defined by the spec.
217 *
218 * @return size_t The corresponding index into _hexData.
219 */
220 inline size_t getWordIndexFromWordNum(size_t wordNum) const
221 {
222 assert(wordNum >= 2 && wordNum <= 9);
223 return wordNum - 2;
224 }
225
Harisuddin Mohamed Isa0f717e12020-01-15 20:05:33 +0800226 /**
227 * @brief Get section in JSON.
Harisuddin Mohamed Isaa214ed32020-02-28 15:58:23 +0800228 * @param[in] registry - Registry object reference
Harisuddin Mohamed Isa0f717e12020-01-15 20:05:33 +0800229 * @return std::optional<std::string> - SRC section's JSON
230 */
Harisuddin Mohamed Isaa214ed32020-02-28 15:58:23 +0800231 std::optional<std::string>
232 getJSON(message::Registry& registry) const override;
Harisuddin Mohamed Isa0f717e12020-01-15 20:05:33 +0800233
234 /**
235 * @brief Get error details based on refcode and hexwords
236 * @param[in] registry - Registry object
237 * @param[in] type - detail level enum value : single message or full json
238 * @param[in] toCache - boolean to cache registry in memory, default=false
239 * @return std::optional<std::string> - Error details
240 */
241 std::optional<std::string> getErrorDetails(message::Registry& registry,
242 DetailLevel type,
243 bool toCache = false) const;
244
Matt Spinler075e5ba2020-02-21 15:46:00 -0600245 /**
246 * @brief Says if this SRC was created by the BMC (i.e. this code).
247 *
248 * @return bool - If created by the BMC or not
249 */
250 bool isBMCSRC() const;
251
Matt Spinlerbd716f02019-10-15 10:54:11 -0500252 private:
253 /**
254 * @brief Fills in the user defined hex words from the
255 * AdditionalData fields.
256 *
257 * When creating this section from a message registry entry,
258 * that entry has a field that says which AdditionalData property
259 * fields to use to fill in the user defined hex data words 6-9
260 * (which correspond to hexData words 4-7).
261 *
262 * For example, given that AdditionalData is a map of string keys
263 * to string values, find the AdditionalData value for AdditionalData
264 * key X, convert it to a uint32_t, and save it in user data word Y.
265 *
266 * @param[in] regEntry - The message registry entry for the error
267 * @param[in] additionalData - The AdditionalData map
268 */
269 void setUserDefinedHexWords(const message::Entry& regEntry,
270 const AdditionalData& additionalData);
271 /**
272 * @brief Fills in the object from the stream data
273 *
274 * @param[in] stream - The stream to read from
275 */
276 void unflatten(Stream& stream);
277
278 /**
Matt Spinlerbd716f02019-10-15 10:54:11 -0500279 * @brief Says if the word number is in the range of user defined words.
280 *
281 * This is only used for BMC generated SRCs, where words 6 - 9 are the
282 * user defined ones, meaning that setUserDefinedHexWords() will be
283 * used to fill them in based on the contents of the OpenBMC event log.
284 *
285 * @param[in] wordNum - The SRC word number, as defined by the spec.
286 *
287 * @return bool - If this word number can be filled in by the creator.
288 */
289 inline bool isUserDefinedWord(size_t wordNum) const
290 {
291 return (wordNum >= 6) && (wordNum <= 9);
292 }
293
294 /**
295 * @brief Sets the SRC format byte in the hex word data.
296 */
297 inline void setBMCFormat()
298 {
299 _hexData[0] |= bmcSRCFormat;
300 }
301
302 /**
303 * @brief Sets the hex word field that specifies which BMC
304 * (primary vs backup) created the error.
305 *
306 * Can be hardcoded until there are systems with redundant BMCs.
307 */
308 inline void setBMCPosition()
309 {
310 _hexData[1] |= primaryBMCPosition;
Matt Spinlerf9bae182019-10-09 13:37:38 -0500311 }
312
313 /**
Matt Spinler075e5ba2020-02-21 15:46:00 -0600314 * @brief Sets the motherboard CCIN hex word field
315 *
316 * @param[in] dataIface - The DataInterface object
317 */
318 void setMotherboardCCIN(const DataInterfaceBase& dataIface);
319
320 /**
Matt Spinlerf9bae182019-10-09 13:37:38 -0500321 * @brief Validates the section contents
322 *
323 * Updates _valid (in Section) with the results.
324 */
325 void validate() override;
326
327 /**
Harisuddin Mohamed Isa0f717e12020-01-15 20:05:33 +0800328 * @brief Get error description from message registry
329 * @param[in] regEntry - The message registry entry for the error
330 * @return std::optional<std::string> - Error message
331 */
332 std::optional<std::string>
333 getErrorMessage(const message::Entry& regEntry) const;
334
335 /**
336 * @brief Get Callout info in JSON
337 * @return std::optional<std::string> - Callout details
338 */
339 std::optional<std::string> getCallouts() const;
340
341 /**
Matt Spinlered046852020-03-13 13:58:15 -0500342 * @brief Checks the AdditionalData property and the message registry
343 * JSON and adds any necessary callouts.
344 *
345 * The callout sources are the AdditionalData event log property
346 * and the message registry JSON.
347 *
348 * @param[in] additionalData - the AdditionalData values
349 * @param[in] dataIface - The DataInterface object
350 */
351 void addCallouts(const AdditionalData& additionalData,
352 const DataInterfaceBase& dataIface);
353
354 /**
355 * @brief Adds a FRU callout based on an inventory path
356 *
357 * @param[in] inventoryPath - The inventory item to call out
358 * @param[in] dataIface - The DataInterface object
359 */
360 void addInventoryCallout(const std::string& inventoryPath,
361 const DataInterfaceBase& dataIface);
362
363 /**
364 * @brief Creates the Callouts object _callouts
365 * so that callouts can be added to it.
366 */
367 void createCalloutsObject()
368 {
369 if (!_callouts)
370 {
371 _callouts = std::make_unique<src::Callouts>();
372 _flags |= additionalSections;
373 }
374 }
375
376 /**
Matt Spinlerf9bae182019-10-09 13:37:38 -0500377 * @brief The SRC version field
378 */
379 uint8_t _version;
380
381 /**
382 * @brief The SRC flags field
383 */
384 uint8_t _flags;
385
386 /**
387 * @brief A byte of reserved data after the flags field
388 */
389 uint8_t _reserved1B;
390
391 /**
392 * @brief The hex data word count.
393 *
394 * To be compatible with previous versions of SRCs, this is
395 * number of hex words (8) + 1 = 9.
396 */
397 uint8_t _wordCount;
398
399 /**
400 * @brief Two bytes of reserved data after the hex word count
401 */
402 uint16_t _reserved2B;
403
404 /**
405 * @brief The total size of the SRC section, not including the section
406 * header.
407 */
408 uint16_t _size;
409
410 /**
411 * @brief The SRC 'hex words'.
412 *
413 * In the spec these are referred to as SRC words 2 - 9 as words 0 and 1
414 * are filled by the 8 bytes of fields from above.
415 */
416 std::array<uint32_t, numSRCHexDataWords> _hexData;
417
418 /**
419 * @brief The 32 byte ASCII character string of the SRC
420 *
421 * It is padded with spaces to fill the 32 bytes.
422 * An example is:
423 * "BD8D1234 "
424 *
425 * That first word is what is commonly referred to as the refcode, and
426 * sometimes also called an SRC.
427 */
428 std::unique_ptr<src::AsciiString> _asciiString;
429
430 /**
431 * @brief The callouts subsection.
432 *
433 * Optional and only created if there are callouts.
434 */
435 std::unique_ptr<src::Callouts> _callouts;
436};
437
438} // namespace pels
439} // namespace openpower