blob: 5bfe6d3b87bfdac7bd7eeb92b26fec7c75c116f1 [file] [log] [blame]
Matt Spinler03c1d912019-07-10 14:12:15 -05001#pragma once
2
Matt Spinleraadccc82020-04-10 14:33:42 -05003#include "data_interface.hpp"
Matt Spinlerfdb6a202019-09-20 14:09:20 -05004#include "elog_entry.hpp"
Aatir Manzurad0e0472019-10-07 13:18:37 -05005#include "pel_values.hpp"
Matt Spinlerfdb6a202019-09-20 14:09:20 -05006#include "registry.hpp"
Matt Spinler03c1d912019-07-10 14:12:15 -05007#include "section.hpp"
8#include "stream.hpp"
9
10namespace openpower
11{
12namespace pels
13{
14
Matt Spinler1a94cc32019-09-11 13:32:12 -050015static constexpr uint8_t userHeaderVersion = 0x01;
Matt Spinler1f93c592020-09-10 10:43:08 -050016static constexpr uint16_t actionFlagsDefault = 0xFFFF;
Matt Spinler03c1d912019-07-10 14:12:15 -050017
18/**
19 * @class UserHeader
20 *
21 * This represents the User Header section in a PEL. It is required,
22 * and it is always the second section.
23 *
24 * The Section base class handles the section header structure that every
25 * PEL section has at offset zero.
26 *
27 * The fields in this class directly correspond to the order and sizes of
28 * the fields in the section.
29 */
30class UserHeader : public Section
31{
32 public:
33 UserHeader() = delete;
34 ~UserHeader() = default;
35 UserHeader(const UserHeader&) = default;
36 UserHeader& operator=(const UserHeader&) = default;
37 UserHeader(UserHeader&&) = default;
38 UserHeader& operator=(UserHeader&&) = default;
39
40 /**
41 * @brief Constructor
42 *
Matt Spinlerfdb6a202019-09-20 14:09:20 -050043 * Creates a valid UserHeader with the passed in data.
44 *
45 * @param[in] entry - The message registry entry for this error
46 * @param[in] severity - The OpenBMC event log severity for this error
Vijay Lobo6b3f3452021-04-15 23:04:42 -050047 * @param[in] additionalData - The AdditionalData properties in this
48 * error log
Matt Spinleraadccc82020-04-10 14:33:42 -050049 * @param[in] dataIface - The DataInterface object
Matt Spinlerfdb6a202019-09-20 14:09:20 -050050 */
51 UserHeader(const message::Entry& entry,
Matt Spinleraadccc82020-04-10 14:33:42 -050052 phosphor::logging::Entry::Level severity,
Vijay Lobo6b3f3452021-04-15 23:04:42 -050053 const AdditionalData& additionalData,
Matt Spinleraadccc82020-04-10 14:33:42 -050054 const DataInterfaceBase& dataIface);
Matt Spinlerfdb6a202019-09-20 14:09:20 -050055
56 /**
57 * @brief Constructor
58 *
Matt Spinler03c1d912019-07-10 14:12:15 -050059 * Fills in this class's data fields from the stream.
60 *
61 * @param[in] pel - the PEL data stream
62 */
63 explicit UserHeader(Stream& pel);
64
65 /**
Matt Spinlercf5a8d02019-09-05 12:58:53 -050066 * @brief Flatten the section into the stream
67 *
68 * @param[in] stream - The stream to write to
69 */
Matt Spinler06885452019-11-06 10:35:42 -060070 void flatten(Stream& stream) const override;
Matt Spinlercf5a8d02019-09-05 12:58:53 -050071
72 /**
Matt Spinler03c1d912019-07-10 14:12:15 -050073 * @brief Returns the subsystem field.
74 *
Matt Spinler97d19b42019-10-29 11:34:03 -050075 * @return uint8_t - the subsystem
Matt Spinler03c1d912019-07-10 14:12:15 -050076 */
Matt Spinler97d19b42019-10-29 11:34:03 -050077 uint8_t subsystem() const
Matt Spinler03c1d912019-07-10 14:12:15 -050078 {
79 return _eventSubsystem;
80 }
81
82 /**
83 * @brief Returns the event scope field.
84 *
Matt Spinler97d19b42019-10-29 11:34:03 -050085 * @return uint8_t - the event scope
Matt Spinler03c1d912019-07-10 14:12:15 -050086 */
Matt Spinler97d19b42019-10-29 11:34:03 -050087 uint8_t scope() const
Matt Spinler03c1d912019-07-10 14:12:15 -050088 {
89 return _eventScope;
90 }
91
92 /**
93 * @brief Returns the severity field.
94 *
Matt Spinler97d19b42019-10-29 11:34:03 -050095 * @return uint8_t - the severity
Matt Spinler03c1d912019-07-10 14:12:15 -050096 */
Matt Spinler97d19b42019-10-29 11:34:03 -050097 uint8_t severity() const
Matt Spinler03c1d912019-07-10 14:12:15 -050098 {
99 return _eventSeverity;
100 }
101
102 /**
103 * @brief Returns the event type field.
104 *
Matt Spinler97d19b42019-10-29 11:34:03 -0500105 * @return uint8_t - the event type
Matt Spinler03c1d912019-07-10 14:12:15 -0500106 */
Matt Spinler97d19b42019-10-29 11:34:03 -0500107 uint8_t eventType() const
Matt Spinler03c1d912019-07-10 14:12:15 -0500108 {
109 return _eventType;
110 }
111
112 /**
Matt Spinlerf1e85e22019-11-01 11:31:31 -0500113 * @brief Set the event type field
114 *
115 * @param[in] type - the new event type
116 */
117 void setEventType(uint8_t type)
118 {
119 _eventType = type;
120 }
121
122 /**
Matt Spinler03c1d912019-07-10 14:12:15 -0500123 * @brief Returns the problem domain field.
124 *
Matt Spinler97d19b42019-10-29 11:34:03 -0500125 * @return uint8_t - the problem domain
Matt Spinler03c1d912019-07-10 14:12:15 -0500126 */
Matt Spinler97d19b42019-10-29 11:34:03 -0500127 uint8_t problemDomain() const
Matt Spinler03c1d912019-07-10 14:12:15 -0500128 {
129 return _problemDomain;
130 }
131
132 /**
133 * @brief Returns the problem vector field.
134 *
Matt Spinler97d19b42019-10-29 11:34:03 -0500135 * @return uint8_t - the problem vector
Matt Spinler03c1d912019-07-10 14:12:15 -0500136 */
Matt Spinler97d19b42019-10-29 11:34:03 -0500137 uint8_t problemVector() const
Matt Spinler03c1d912019-07-10 14:12:15 -0500138 {
139 return _problemVector;
140 }
141
142 /**
143 * @brief Returns the action flags field.
144 *
Matt Spinler97d19b42019-10-29 11:34:03 -0500145 * @return uint16_t - the action flags
Matt Spinler03c1d912019-07-10 14:12:15 -0500146 */
Matt Spinler97d19b42019-10-29 11:34:03 -0500147 uint16_t actionFlags() const
Matt Spinler03c1d912019-07-10 14:12:15 -0500148 {
149 return _actionFlags;
150 }
151
152 /**
Matt Spinlerf1e85e22019-11-01 11:31:31 -0500153 * @brief Sets the action flags field
154 *
155 * @param[in] flags - the new action flags
156 */
157 void setActionFlags(uint16_t flags)
158 {
159 _actionFlags = flags;
160 }
161
162 /**
Matt Spinlereb111442019-11-07 13:05:36 -0600163 * @brief Returns the host transmission state
164 *
165 * @return uint8_t - the host transmission state
166 */
167 uint8_t hostTransmissionState() const
168 {
169 return _states & 0xFF;
170 }
171
172 /**
173 * @brief Sets the host transmission state
174 *
175 * @param[in] state - the new state
176 */
177 void setHostTransmissionState(uint8_t state)
178 {
179 _states &= 0xFFFFFF00;
180 _states |= state;
181 }
182
183 /**
184 * @brief Returns the HMC transmission state
185 *
186 * (HMC = Hardware Management Console)
187 *
188 * @return uint8_t - the HMC transmission state
189 */
190 uint8_t hmcTransmissionState() const
191 {
192 return (_states & 0x0000FF00) >> 8;
193 }
194
195 /**
196 * @brief Sets the HMC transmission state
197 *
198 * @param[in] state - the new state
199 */
200 void setHMCTransmissionState(uint8_t state)
201 {
202 uint32_t newState = state << 8;
203 _states &= 0xFFFF00FF;
204 _states |= newState;
205 }
206
207 /**
Matt Spinler03c1d912019-07-10 14:12:15 -0500208 * @brief Returns the size of this section when flattened into a PEL
209 *
210 * @return size_t - the size of the section
211 */
212 static constexpr size_t flattenedSize()
213 {
214 return Section::flattenedSize() + sizeof(_eventSubsystem) +
215 sizeof(_eventScope) + sizeof(_eventSeverity) +
216 sizeof(_eventType) + sizeof(_reserved4Byte1) +
217 sizeof(_problemDomain) + sizeof(_problemVector) +
Matt Spinlereb111442019-11-07 13:05:36 -0600218 sizeof(_actionFlags) + sizeof(_states);
Matt Spinler03c1d912019-07-10 14:12:15 -0500219 }
220
Aatir Manzurad0e0472019-10-07 13:18:37 -0500221 /**
222 * @brief Get section in JSON.
Matt Spinlerb832aa52023-03-21 15:32:34 -0500223 *
224 * @param[in] creatorID - The creator ID for the PEL
225 *
Aatirc1489352019-12-09 13:13:20 -0600226 * @return std::optional<std::string> -User header section's JSON
Aatir Manzurad0e0472019-10-07 13:18:37 -0500227 */
Matt Spinlerb832aa52023-03-21 15:32:34 -0500228 std::optional<std::string> getJSON(uint8_t creatorID) const override;
Aatir Manzurad0e0472019-10-07 13:18:37 -0500229
Matt Spinler03c1d912019-07-10 14:12:15 -0500230 private:
231 /**
Matt Spinlercf5a8d02019-09-05 12:58:53 -0500232 * @brief Fills in the object from the stream data
233 *
234 * @param[in] stream - The stream to read from
235 */
236 void unflatten(Stream& stream);
237
238 /**
Matt Spinler03c1d912019-07-10 14:12:15 -0500239 * @brief Validates the section contents
240 *
241 * Updates _valid (in Section) with the results.
242 */
243 void validate() override;
244
245 /**
Matt Spinleraadccc82020-04-10 14:33:42 -0500246 * @brief Returns the severity value to use from the list
247 * of them passed in based on the system type.
248 *
249 * If there isn't an entry found for the current system
250 * type then std::nullopt will be returned.
251 *
252 * @param[in] severities - The array of {systype, severity}
253 * structures to find an entry in.
Matt Spinler1ab66962020-10-29 13:21:44 -0500254 * @param[in] dataIface - The DataInterface object
Matt Spinleraadccc82020-04-10 14:33:42 -0500255 */
256 std::optional<uint8_t>
257 getSeverity(const std::vector<message::RegistrySeverity>& severities,
Matt Spinler1ab66962020-10-29 13:21:44 -0500258 const DataInterfaceBase& dataIface) const;
259
Matt Spinleraadccc82020-04-10 14:33:42 -0500260 /**
Matt Spinler03c1d912019-07-10 14:12:15 -0500261 * @brief The subsystem associated with the event.
262 */
263 uint8_t _eventSubsystem;
264
265 /**
266 * @brief The event scope field.
267 */
268 uint8_t _eventScope;
269
270 /**
271 * @brief The event severity.
272 */
273 uint8_t _eventSeverity;
274
275 /**
276 * @brief The event type.
277 */
278 uint8_t _eventType;
279
280 /**
281 * @brief A reserved word placeholder
282 */
283 uint32_t _reserved4Byte1;
284
285 /**
286 * @brief The problem domain field.
287 */
288 uint8_t _problemDomain;
289
290 /**
291 * @brief The problem vector field.
292 */
293 uint8_t _problemVector;
294
295 /**
296 * @brief The action flags field.
297 */
298 uint16_t _actionFlags;
299
300 /**
Matt Spinlereb111442019-11-07 13:05:36 -0600301 * @brief The second reserved word that we are
302 * using for storing state information.
303 *
304 * 0x0000AABB
305 * Where:
306 * 0xAA = HMC transmission state
307 * 0xBB = Host transmission state
Matt Spinler03c1d912019-07-10 14:12:15 -0500308 */
Matt Spinlereb111442019-11-07 13:05:36 -0600309 uint32_t _states;
Matt Spinler03c1d912019-07-10 14:12:15 -0500310};
311
Matt Spinler03c1d912019-07-10 14:12:15 -0500312} // namespace pels
313} // namespace openpower