blob: 024237e11e50227a6d7920abb90ba2751beaa319 [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"
5#include "registry.hpp"
Matt Spinler03c1d912019-07-10 14:12:15 -05006#include "section.hpp"
7#include "stream.hpp"
8
9namespace openpower
10{
11namespace pels
12{
13
Matt Spinler1a94cc32019-09-11 13:32:12 -050014static constexpr uint8_t userHeaderVersion = 0x01;
Matt Spinler1f93c592020-09-10 10:43:08 -050015static constexpr uint16_t actionFlagsDefault = 0xFFFF;
Matt Spinler03c1d912019-07-10 14:12:15 -050016
17/**
18 * @class UserHeader
19 *
20 * This represents the User Header section in a PEL. It is required,
21 * and it is always the second section.
22 *
23 * The Section base class handles the section header structure that every
24 * PEL section has at offset zero.
25 *
26 * The fields in this class directly correspond to the order and sizes of
27 * the fields in the section.
28 */
29class UserHeader : public Section
30{
31 public:
32 UserHeader() = delete;
Matt Spinler362f4692025-05-09 13:21:33 -050033 ~UserHeader() override = default;
Matt Spinler03c1d912019-07-10 14:12:15 -050034 UserHeader(const UserHeader&) = default;
35 UserHeader& operator=(const UserHeader&) = default;
36 UserHeader(UserHeader&&) = default;
37 UserHeader& operator=(UserHeader&&) = default;
38
39 /**
40 * @brief Constructor
41 *
Matt Spinlerfdb6a202019-09-20 14:09:20 -050042 * Creates a valid UserHeader with the passed in data.
43 *
44 * @param[in] entry - The message registry entry for this error
45 * @param[in] severity - The OpenBMC event log severity for this error
Vijay Lobo6b3f3452021-04-15 23:04:42 -050046 * @param[in] additionalData - The AdditionalData properties in this
47 * error log
Matt Spinleraadccc82020-04-10 14:33:42 -050048 * @param[in] dataIface - The DataInterface object
Matt Spinlerfdb6a202019-09-20 14:09:20 -050049 */
50 UserHeader(const message::Entry& entry,
Matt Spinleraadccc82020-04-10 14:33:42 -050051 phosphor::logging::Entry::Level severity,
Vijay Lobo6b3f3452021-04-15 23:04:42 -050052 const AdditionalData& additionalData,
Matt Spinleraadccc82020-04-10 14:33:42 -050053 const DataInterfaceBase& dataIface);
Matt Spinlerfdb6a202019-09-20 14:09:20 -050054
55 /**
56 * @brief Constructor
57 *
Matt Spinler03c1d912019-07-10 14:12:15 -050058 * Fills in this class's data fields from the stream.
59 *
60 * @param[in] pel - the PEL data stream
61 */
62 explicit UserHeader(Stream& pel);
63
64 /**
Matt Spinlercf5a8d02019-09-05 12:58:53 -050065 * @brief Flatten the section into the stream
66 *
67 * @param[in] stream - The stream to write to
68 */
Matt Spinler06885452019-11-06 10:35:42 -060069 void flatten(Stream& stream) const override;
Matt Spinlercf5a8d02019-09-05 12:58:53 -050070
71 /**
Matt Spinler03c1d912019-07-10 14:12:15 -050072 * @brief Returns the subsystem field.
73 *
Matt Spinler97d19b42019-10-29 11:34:03 -050074 * @return uint8_t - the subsystem
Matt Spinler03c1d912019-07-10 14:12:15 -050075 */
Matt Spinler97d19b42019-10-29 11:34:03 -050076 uint8_t subsystem() const
Matt Spinler03c1d912019-07-10 14:12:15 -050077 {
78 return _eventSubsystem;
79 }
80
81 /**
82 * @brief Returns the event scope field.
83 *
Matt Spinler97d19b42019-10-29 11:34:03 -050084 * @return uint8_t - the event scope
Matt Spinler03c1d912019-07-10 14:12:15 -050085 */
Matt Spinler97d19b42019-10-29 11:34:03 -050086 uint8_t scope() const
Matt Spinler03c1d912019-07-10 14:12:15 -050087 {
88 return _eventScope;
89 }
90
91 /**
92 * @brief Returns the severity field.
93 *
Matt Spinler97d19b42019-10-29 11:34:03 -050094 * @return uint8_t - the severity
Matt Spinler03c1d912019-07-10 14:12:15 -050095 */
Matt Spinler97d19b42019-10-29 11:34:03 -050096 uint8_t severity() const
Matt Spinler03c1d912019-07-10 14:12:15 -050097 {
98 return _eventSeverity;
99 }
100
101 /**
102 * @brief Returns the event type field.
103 *
Matt Spinler97d19b42019-10-29 11:34:03 -0500104 * @return uint8_t - the event type
Matt Spinler03c1d912019-07-10 14:12:15 -0500105 */
Matt Spinler97d19b42019-10-29 11:34:03 -0500106 uint8_t eventType() const
Matt Spinler03c1d912019-07-10 14:12:15 -0500107 {
108 return _eventType;
109 }
110
111 /**
Matt Spinlerf1e85e22019-11-01 11:31:31 -0500112 * @brief Set the event type field
113 *
114 * @param[in] type - the new event type
115 */
116 void setEventType(uint8_t type)
117 {
118 _eventType = type;
119 }
120
121 /**
Matt Spinler03c1d912019-07-10 14:12:15 -0500122 * @brief Returns the problem domain field.
123 *
Matt Spinler97d19b42019-10-29 11:34:03 -0500124 * @return uint8_t - the problem domain
Matt Spinler03c1d912019-07-10 14:12:15 -0500125 */
Matt Spinler97d19b42019-10-29 11:34:03 -0500126 uint8_t problemDomain() const
Matt Spinler03c1d912019-07-10 14:12:15 -0500127 {
128 return _problemDomain;
129 }
130
131 /**
132 * @brief Returns the problem vector field.
133 *
Matt Spinler97d19b42019-10-29 11:34:03 -0500134 * @return uint8_t - the problem vector
Matt Spinler03c1d912019-07-10 14:12:15 -0500135 */
Matt Spinler97d19b42019-10-29 11:34:03 -0500136 uint8_t problemVector() const
Matt Spinler03c1d912019-07-10 14:12:15 -0500137 {
138 return _problemVector;
139 }
140
141 /**
142 * @brief Returns the action flags field.
143 *
Matt Spinler97d19b42019-10-29 11:34:03 -0500144 * @return uint16_t - the action flags
Matt Spinler03c1d912019-07-10 14:12:15 -0500145 */
Matt Spinler97d19b42019-10-29 11:34:03 -0500146 uint16_t actionFlags() const
Matt Spinler03c1d912019-07-10 14:12:15 -0500147 {
148 return _actionFlags;
149 }
150
151 /**
Matt Spinlerf1e85e22019-11-01 11:31:31 -0500152 * @brief Sets the action flags field
153 *
154 * @param[in] flags - the new action flags
155 */
156 void setActionFlags(uint16_t flags)
157 {
158 _actionFlags = flags;
159 }
160
161 /**
Matt Spinlereb111442019-11-07 13:05:36 -0600162 * @brief Returns the host transmission state
163 *
164 * @return uint8_t - the host transmission state
165 */
166 uint8_t hostTransmissionState() const
167 {
168 return _states & 0xFF;
169 }
170
171 /**
172 * @brief Sets the host transmission state
173 *
174 * @param[in] state - the new state
175 */
176 void setHostTransmissionState(uint8_t state)
177 {
178 _states &= 0xFFFFFF00;
179 _states |= state;
180 }
181
182 /**
183 * @brief Returns the HMC transmission state
184 *
185 * (HMC = Hardware Management Console)
186 *
187 * @return uint8_t - the HMC transmission state
188 */
189 uint8_t hmcTransmissionState() const
190 {
191 return (_states & 0x0000FF00) >> 8;
192 }
193
194 /**
195 * @brief Sets the HMC transmission state
196 *
197 * @param[in] state - the new state
198 */
199 void setHMCTransmissionState(uint8_t state)
200 {
201 uint32_t newState = state << 8;
202 _states &= 0xFFFF00FF;
203 _states |= newState;
204 }
205
206 /**
Matt Spinler03c1d912019-07-10 14:12:15 -0500207 * @brief Returns the size of this section when flattened into a PEL
208 *
209 * @return size_t - the size of the section
210 */
211 static constexpr size_t flattenedSize()
212 {
Matt Spinlere2eb14a2025-05-09 13:34:51 -0500213 return Section::headerSize() + sizeof(_eventSubsystem) +
Matt Spinler03c1d912019-07-10 14:12:15 -0500214 sizeof(_eventScope) + sizeof(_eventSeverity) +
215 sizeof(_eventType) + sizeof(_reserved4Byte1) +
216 sizeof(_problemDomain) + sizeof(_problemVector) +
Matt Spinlereb111442019-11-07 13:05:36 -0600217 sizeof(_actionFlags) + sizeof(_states);
Matt Spinler03c1d912019-07-10 14:12:15 -0500218 }
219
Aatir Manzurad0e0472019-10-07 13:18:37 -0500220 /**
221 * @brief Get section in JSON.
Matt Spinlerb832aa52023-03-21 15:32:34 -0500222 *
223 * @param[in] creatorID - The creator ID for the PEL
224 *
Aatirc1489352019-12-09 13:13:20 -0600225 * @return std::optional<std::string> -User header section's JSON
Aatir Manzurad0e0472019-10-07 13:18:37 -0500226 */
Matt Spinlerb832aa52023-03-21 15:32:34 -0500227 std::optional<std::string> getJSON(uint8_t creatorID) const override;
Aatir Manzurad0e0472019-10-07 13:18:37 -0500228
Matt Spinler03c1d912019-07-10 14:12:15 -0500229 private:
230 /**
Matt Spinlercf5a8d02019-09-05 12:58:53 -0500231 * @brief Fills in the object from the stream data
232 *
233 * @param[in] stream - The stream to read from
234 */
235 void unflatten(Stream& stream);
236
237 /**
Matt Spinler03c1d912019-07-10 14:12:15 -0500238 * @brief Validates the section contents
239 *
240 * Updates _valid (in Section) with the results.
241 */
242 void validate() override;
243
244 /**
Matt Spinleraadccc82020-04-10 14:33:42 -0500245 * @brief Returns the severity value to use from the list
246 * of them passed in based on the system type.
247 *
248 * If there isn't an entry found for the current system
249 * type then std::nullopt will be returned.
250 *
251 * @param[in] severities - The array of {systype, severity}
252 * structures to find an entry in.
Matt Spinler1ab66962020-10-29 13:21:44 -0500253 * @param[in] dataIface - The DataInterface object
Matt Spinleraadccc82020-04-10 14:33:42 -0500254 */
Patrick Williams25291152025-02-01 08:21:42 -0500255 std::optional<uint8_t> getSeverity(
256 const std::vector<message::RegistrySeverity>& severities,
257 const DataInterfaceBase& dataIface) const;
Matt Spinler1ab66962020-10-29 13:21:44 -0500258
Matt Spinleraadccc82020-04-10 14:33:42 -0500259 /**
Matt Spinler03c1d912019-07-10 14:12:15 -0500260 * @brief The subsystem associated with the event.
261 */
262 uint8_t _eventSubsystem;
263
264 /**
265 * @brief The event scope field.
266 */
267 uint8_t _eventScope;
268
269 /**
270 * @brief The event severity.
271 */
272 uint8_t _eventSeverity;
273
274 /**
275 * @brief The event type.
276 */
277 uint8_t _eventType;
278
279 /**
280 * @brief A reserved word placeholder
281 */
282 uint32_t _reserved4Byte1;
283
284 /**
285 * @brief The problem domain field.
286 */
287 uint8_t _problemDomain;
288
289 /**
290 * @brief The problem vector field.
291 */
292 uint8_t _problemVector;
293
294 /**
295 * @brief The action flags field.
296 */
297 uint16_t _actionFlags;
298
299 /**
Matt Spinlereb111442019-11-07 13:05:36 -0600300 * @brief The second reserved word that we are
301 * using for storing state information.
302 *
303 * 0x0000AABB
304 * Where:
305 * 0xAA = HMC transmission state
306 * 0xBB = Host transmission state
Matt Spinler03c1d912019-07-10 14:12:15 -0500307 */
Matt Spinlereb111442019-11-07 13:05:36 -0600308 uint32_t _states;
Matt Spinler03c1d912019-07-10 14:12:15 -0500309};
310
Matt Spinler03c1d912019-07-10 14:12:15 -0500311} // namespace pels
312} // namespace openpower