Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 3 | #include "data_interface.hpp" |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 4 | #include "elog_entry.hpp" |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 5 | #include "pel_values.hpp" |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 6 | #include "registry.hpp" |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 7 | #include "section.hpp" |
| 8 | #include "stream.hpp" |
| 9 | |
| 10 | namespace openpower |
| 11 | { |
| 12 | namespace pels |
| 13 | { |
| 14 | |
Matt Spinler | 1a94cc3 | 2019-09-11 13:32:12 -0500 | [diff] [blame] | 15 | static constexpr uint8_t userHeaderVersion = 0x01; |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 16 | |
| 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 | */ |
| 29 | class UserHeader : public Section |
| 30 | { |
| 31 | public: |
| 32 | UserHeader() = delete; |
| 33 | ~UserHeader() = default; |
| 34 | 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 Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 42 | * 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 |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 46 | * @param[in] dataIface - The DataInterface object |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 47 | */ |
| 48 | UserHeader(const message::Entry& entry, |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 49 | phosphor::logging::Entry::Level severity, |
| 50 | const DataInterfaceBase& dataIface); |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 51 | |
| 52 | /** |
| 53 | * @brief Constructor |
| 54 | * |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 55 | * Fills in this class's data fields from the stream. |
| 56 | * |
| 57 | * @param[in] pel - the PEL data stream |
| 58 | */ |
| 59 | explicit UserHeader(Stream& pel); |
| 60 | |
| 61 | /** |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 62 | * @brief Flatten the section into the stream |
| 63 | * |
| 64 | * @param[in] stream - The stream to write to |
| 65 | */ |
Matt Spinler | 0688545 | 2019-11-06 10:35:42 -0600 | [diff] [blame] | 66 | void flatten(Stream& stream) const override; |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 67 | |
| 68 | /** |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 69 | * @brief Returns the subsystem field. |
| 70 | * |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 71 | * @return uint8_t - the subsystem |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 72 | */ |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 73 | uint8_t subsystem() const |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 74 | { |
| 75 | return _eventSubsystem; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * @brief Returns the event scope field. |
| 80 | * |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 81 | * @return uint8_t - the event scope |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 82 | */ |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 83 | uint8_t scope() const |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 84 | { |
| 85 | return _eventScope; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * @brief Returns the severity field. |
| 90 | * |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 91 | * @return uint8_t - the severity |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 92 | */ |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 93 | uint8_t severity() const |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 94 | { |
| 95 | return _eventSeverity; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * @brief Returns the event type field. |
| 100 | * |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 101 | * @return uint8_t - the event type |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 102 | */ |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 103 | uint8_t eventType() const |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 104 | { |
| 105 | return _eventType; |
| 106 | } |
| 107 | |
| 108 | /** |
Matt Spinler | f1e85e2 | 2019-11-01 11:31:31 -0500 | [diff] [blame] | 109 | * @brief Set the event type field |
| 110 | * |
| 111 | * @param[in] type - the new event type |
| 112 | */ |
| 113 | void setEventType(uint8_t type) |
| 114 | { |
| 115 | _eventType = type; |
| 116 | } |
| 117 | |
| 118 | /** |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 119 | * @brief Returns the problem domain field. |
| 120 | * |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 121 | * @return uint8_t - the problem domain |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 122 | */ |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 123 | uint8_t problemDomain() const |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 124 | { |
| 125 | return _problemDomain; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * @brief Returns the problem vector field. |
| 130 | * |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 131 | * @return uint8_t - the problem vector |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 132 | */ |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 133 | uint8_t problemVector() const |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 134 | { |
| 135 | return _problemVector; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * @brief Returns the action flags field. |
| 140 | * |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 141 | * @return uint16_t - the action flags |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 142 | */ |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 143 | uint16_t actionFlags() const |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 144 | { |
| 145 | return _actionFlags; |
| 146 | } |
| 147 | |
| 148 | /** |
Matt Spinler | f1e85e2 | 2019-11-01 11:31:31 -0500 | [diff] [blame] | 149 | * @brief Sets the action flags field |
| 150 | * |
| 151 | * @param[in] flags - the new action flags |
| 152 | */ |
| 153 | void setActionFlags(uint16_t flags) |
| 154 | { |
| 155 | _actionFlags = flags; |
| 156 | } |
| 157 | |
| 158 | /** |
Matt Spinler | eb11144 | 2019-11-07 13:05:36 -0600 | [diff] [blame] | 159 | * @brief Returns the host transmission state |
| 160 | * |
| 161 | * @return uint8_t - the host transmission state |
| 162 | */ |
| 163 | uint8_t hostTransmissionState() const |
| 164 | { |
| 165 | return _states & 0xFF; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * @brief Sets the host transmission state |
| 170 | * |
| 171 | * @param[in] state - the new state |
| 172 | */ |
| 173 | void setHostTransmissionState(uint8_t state) |
| 174 | { |
| 175 | _states &= 0xFFFFFF00; |
| 176 | _states |= state; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * @brief Returns the HMC transmission state |
| 181 | * |
| 182 | * (HMC = Hardware Management Console) |
| 183 | * |
| 184 | * @return uint8_t - the HMC transmission state |
| 185 | */ |
| 186 | uint8_t hmcTransmissionState() const |
| 187 | { |
| 188 | return (_states & 0x0000FF00) >> 8; |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * @brief Sets the HMC transmission state |
| 193 | * |
| 194 | * @param[in] state - the new state |
| 195 | */ |
| 196 | void setHMCTransmissionState(uint8_t state) |
| 197 | { |
| 198 | uint32_t newState = state << 8; |
| 199 | _states &= 0xFFFF00FF; |
| 200 | _states |= newState; |
| 201 | } |
| 202 | |
| 203 | /** |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 204 | * @brief Returns the size of this section when flattened into a PEL |
| 205 | * |
| 206 | * @return size_t - the size of the section |
| 207 | */ |
| 208 | static constexpr size_t flattenedSize() |
| 209 | { |
| 210 | return Section::flattenedSize() + sizeof(_eventSubsystem) + |
| 211 | sizeof(_eventScope) + sizeof(_eventSeverity) + |
| 212 | sizeof(_eventType) + sizeof(_reserved4Byte1) + |
| 213 | sizeof(_problemDomain) + sizeof(_problemVector) + |
Matt Spinler | eb11144 | 2019-11-07 13:05:36 -0600 | [diff] [blame] | 214 | sizeof(_actionFlags) + sizeof(_states); |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 215 | } |
| 216 | |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 217 | /** |
| 218 | * @brief Get section in JSON. |
Aatir | c148935 | 2019-12-09 13:13:20 -0600 | [diff] [blame] | 219 | * @return std::optional<std::string> -User header section's JSON |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 220 | */ |
| 221 | std::optional<std::string> getJSON() const override; |
| 222 | |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 223 | private: |
| 224 | /** |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 225 | * @brief Fills in the object from the stream data |
| 226 | * |
| 227 | * @param[in] stream - The stream to read from |
| 228 | */ |
| 229 | void unflatten(Stream& stream); |
| 230 | |
| 231 | /** |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 232 | * @brief Validates the section contents |
| 233 | * |
| 234 | * Updates _valid (in Section) with the results. |
| 235 | */ |
| 236 | void validate() override; |
| 237 | |
| 238 | /** |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 239 | * @brief Returns the severity value to use from the list |
| 240 | * of them passed in based on the system type. |
| 241 | * |
| 242 | * If there isn't an entry found for the current system |
| 243 | * type then std::nullopt will be returned. |
| 244 | * |
| 245 | * @param[in] severities - The array of {systype, severity} |
| 246 | * structures to find an entry in. |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 247 | * @param[in] systemNames - List of compatible system type names |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 248 | */ |
| 249 | std::optional<uint8_t> |
| 250 | getSeverity(const std::vector<message::RegistrySeverity>& severities, |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 251 | const std::vector<std::string>& systemNames) const; |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 252 | /** |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 253 | * @brief The subsystem associated with the event. |
| 254 | */ |
| 255 | uint8_t _eventSubsystem; |
| 256 | |
| 257 | /** |
| 258 | * @brief The event scope field. |
| 259 | */ |
| 260 | uint8_t _eventScope; |
| 261 | |
| 262 | /** |
| 263 | * @brief The event severity. |
| 264 | */ |
| 265 | uint8_t _eventSeverity; |
| 266 | |
| 267 | /** |
| 268 | * @brief The event type. |
| 269 | */ |
| 270 | uint8_t _eventType; |
| 271 | |
| 272 | /** |
| 273 | * @brief A reserved word placeholder |
| 274 | */ |
| 275 | uint32_t _reserved4Byte1; |
| 276 | |
| 277 | /** |
| 278 | * @brief The problem domain field. |
| 279 | */ |
| 280 | uint8_t _problemDomain; |
| 281 | |
| 282 | /** |
| 283 | * @brief The problem vector field. |
| 284 | */ |
| 285 | uint8_t _problemVector; |
| 286 | |
| 287 | /** |
| 288 | * @brief The action flags field. |
| 289 | */ |
| 290 | uint16_t _actionFlags; |
| 291 | |
| 292 | /** |
Matt Spinler | eb11144 | 2019-11-07 13:05:36 -0600 | [diff] [blame] | 293 | * @brief The second reserved word that we are |
| 294 | * using for storing state information. |
| 295 | * |
| 296 | * 0x0000AABB |
| 297 | * Where: |
| 298 | * 0xAA = HMC transmission state |
| 299 | * 0xBB = Host transmission state |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 300 | */ |
Matt Spinler | eb11144 | 2019-11-07 13:05:36 -0600 | [diff] [blame] | 301 | uint32_t _states; |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 302 | }; |
| 303 | |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 304 | } // namespace pels |
| 305 | } // namespace openpower |