summaryrefslogtreecommitdiffstats
path: root/extensions/openpower-pels/user_header.hpp
blob: f1fc66de28f846950954b29f9e09b289b117962c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#pragma once

#include "elog_entry.hpp"
#include "pel_values.hpp"
#include "registry.hpp"
#include "section.hpp"
#include "stream.hpp"

namespace openpower
{
namespace pels
{

static constexpr uint8_t userHeaderVersion = 0x01;

/**
 * @class UserHeader
 *
 * This represents the User Header section in a PEL.  It is required,
 * and it is always the second section.
 *
 * The Section base class handles the section header structure that every
 * PEL section has at offset zero.
 *
 * The fields in this class directly correspond to the order and sizes of
 * the fields in the section.
 */
class UserHeader : public Section
{
  public:
    UserHeader() = delete;
    ~UserHeader() = default;
    UserHeader(const UserHeader&) = default;
    UserHeader& operator=(const UserHeader&) = default;
    UserHeader(UserHeader&&) = default;
    UserHeader& operator=(UserHeader&&) = default;

    /**
     * @brief Constructor
     *
     * Creates a valid UserHeader with the passed in data.
     *
     * @param[in] entry - The message registry entry for this error
     * @param[in] severity - The OpenBMC event log severity for this error
     */
    UserHeader(const message::Entry& entry,
               phosphor::logging::Entry::Level severity);

    /**
     * @brief Constructor
     *
     * Fills in this class's data fields from the stream.
     *
     * @param[in] pel - the PEL data stream
     */
    explicit UserHeader(Stream& pel);

    /**
     * @brief Flatten the section into the stream
     *
     * @param[in] stream - The stream to write to
     */
    void flatten(Stream& stream) const override;

    /**
     * @brief Returns the subsystem field.
     *
     * @return uint8_t - the subsystem
     */
    uint8_t subsystem() const
    {
        return _eventSubsystem;
    }

    /**
     * @brief Returns the event scope field.
     *
     * @return uint8_t - the event scope
     */
    uint8_t scope() const
    {
        return _eventScope;
    }

    /**
     * @brief Returns the severity field.
     *
     * @return uint8_t - the severity
     */
    uint8_t severity() const
    {
        return _eventSeverity;
    }

    /**
     * @brief Returns the event type field.
     *
     * @return uint8_t - the event type
     */
    uint8_t eventType() const
    {
        return _eventType;
    }

    /**
     * @brief Set the event type field
     *
     * @param[in] type - the new event type
     */
    void setEventType(uint8_t type)
    {
        _eventType = type;
    }

    /**
     * @brief Returns the problem domain field.
     *
     * @return uint8_t - the problem domain
     */
    uint8_t problemDomain() const
    {
        return _problemDomain;
    }

    /**
     * @brief Returns the problem vector field.
     *
     * @return uint8_t - the problem vector
     */
    uint8_t problemVector() const
    {
        return _problemVector;
    }

    /**
     * @brief Returns the action flags field.
     *
     * @return uint16_t - the action flags
     */
    uint16_t actionFlags() const
    {
        return _actionFlags;
    }

    /**
     * @brief Sets the action flags field
     *
     * @param[in] flags - the new action flags
     */
    void setActionFlags(uint16_t flags)
    {
        _actionFlags = flags;
    }

    /**
     * @brief Returns the host transmission state
     *
     * @return uint8_t - the host transmission state
     */
    uint8_t hostTransmissionState() const
    {
        return _states & 0xFF;
    }

    /**
     * @brief Sets the host transmission state
     *
     * @param[in] state - the new state
     */
    void setHostTransmissionState(uint8_t state)
    {
        _states &= 0xFFFFFF00;
        _states |= state;
    }

    /**
     * @brief Returns the HMC transmission state
     *
     * (HMC = Hardware Management Console)
     *
     * @return uint8_t - the HMC transmission state
     */
    uint8_t hmcTransmissionState() const
    {
        return (_states & 0x0000FF00) >> 8;
    }

    /**
     * @brief Sets the HMC transmission state
     *
     * @param[in] state - the new state
     */
    void setHMCTransmissionState(uint8_t state)
    {
        uint32_t newState = state << 8;
        _states &= 0xFFFF00FF;
        _states |= newState;
    }

    /**
     * @brief Returns the size of this section when flattened into a PEL
     *
     * @return size_t - the size of the section
     */
    static constexpr size_t flattenedSize()
    {
        return Section::flattenedSize() + sizeof(_eventSubsystem) +
               sizeof(_eventScope) + sizeof(_eventSeverity) +
               sizeof(_eventType) + sizeof(_reserved4Byte1) +
               sizeof(_problemDomain) + sizeof(_problemVector) +
               sizeof(_actionFlags) + sizeof(_states);
    }

    /**
     * @brief Get section in JSON.
     * @return std::optional<std::string> -User header section's JSON
     */
    std::optional<std::string> getJSON() const override;

  private:
    /**
     * @brief Fills in the object from the stream data
     *
     * @param[in] stream - The stream to read from
     */
    void unflatten(Stream& stream);

    /**
     * @brief Validates the section contents
     *
     * Updates _valid (in Section) with the results.
     */
    void validate() override;

    /**
     * @brief The subsystem associated with the event.
     */
    uint8_t _eventSubsystem;

    /**
     * @brief The event scope field.
     */
    uint8_t _eventScope;

    /**
     * @brief The event severity.
     */
    uint8_t _eventSeverity;

    /**
     * @brief The event type.
     */
    uint8_t _eventType;

    /**
     * @brief A reserved word placeholder
     */
    uint32_t _reserved4Byte1;

    /**
     * @brief The problem domain field.
     */
    uint8_t _problemDomain;

    /**
     * @brief The problem vector field.
     */
    uint8_t _problemVector;

    /**
     * @brief The action flags field.
     */
    uint16_t _actionFlags;

    /**
     * @brief The second reserved word that we are
     *        using for storing state information.
     *
     * 0x0000AABB
     *   Where:
     *      0xAA = HMC transmission state
     *      0xBB = Host transmission state
     */
    uint32_t _states;
};

} // namespace pels
} // namespace openpower
OpenPOWER on IntegriCloud