103c1d915SMatt Spinler #pragma once 203c1d915SMatt Spinler 3*aadccc85SMatt Spinler #include "data_interface.hpp" 4fdb6a202SMatt Spinler #include "elog_entry.hpp" 5ad0e0476SAatir Manzur #include "pel_values.hpp" 6fdb6a202SMatt Spinler #include "registry.hpp" 703c1d915SMatt Spinler #include "section.hpp" 803c1d915SMatt Spinler #include "stream.hpp" 903c1d915SMatt Spinler 1003c1d915SMatt Spinler namespace openpower 1103c1d915SMatt Spinler { 1203c1d915SMatt Spinler namespace pels 1303c1d915SMatt Spinler { 1403c1d915SMatt Spinler 151a94cc38SMatt Spinler static constexpr uint8_t userHeaderVersion = 0x01; 1603c1d915SMatt Spinler 1703c1d915SMatt Spinler /** 1803c1d915SMatt Spinler * @class UserHeader 1903c1d915SMatt Spinler * 2003c1d915SMatt Spinler * This represents the User Header section in a PEL. It is required, 2103c1d915SMatt Spinler * and it is always the second section. 2203c1d915SMatt Spinler * 2303c1d915SMatt Spinler * The Section base class handles the section header structure that every 2403c1d915SMatt Spinler * PEL section has at offset zero. 2503c1d915SMatt Spinler * 2603c1d915SMatt Spinler * The fields in this class directly correspond to the order and sizes of 2703c1d915SMatt Spinler * the fields in the section. 2803c1d915SMatt Spinler */ 2903c1d915SMatt Spinler class UserHeader : public Section 3003c1d915SMatt Spinler { 3103c1d915SMatt Spinler public: 3203c1d915SMatt Spinler UserHeader() = delete; 3303c1d915SMatt Spinler ~UserHeader() = default; 3403c1d915SMatt Spinler UserHeader(const UserHeader&) = default; 3503c1d915SMatt Spinler UserHeader& operator=(const UserHeader&) = default; 3603c1d915SMatt Spinler UserHeader(UserHeader&&) = default; 3703c1d915SMatt Spinler UserHeader& operator=(UserHeader&&) = default; 3803c1d915SMatt Spinler 3903c1d915SMatt Spinler /** 4003c1d915SMatt Spinler * @brief Constructor 4103c1d915SMatt Spinler * 42fdb6a202SMatt Spinler * Creates a valid UserHeader with the passed in data. 43fdb6a202SMatt Spinler * 44fdb6a202SMatt Spinler * @param[in] entry - The message registry entry for this error 45fdb6a202SMatt Spinler * @param[in] severity - The OpenBMC event log severity for this error 46*aadccc85SMatt Spinler * @param[in] dataIface - The DataInterface object 47fdb6a202SMatt Spinler */ 48fdb6a202SMatt Spinler UserHeader(const message::Entry& entry, 49*aadccc85SMatt Spinler phosphor::logging::Entry::Level severity, 50*aadccc85SMatt Spinler const DataInterfaceBase& dataIface); 51fdb6a202SMatt Spinler 52fdb6a202SMatt Spinler /** 53fdb6a202SMatt Spinler * @brief Constructor 54fdb6a202SMatt Spinler * 5503c1d915SMatt Spinler * Fills in this class's data fields from the stream. 5603c1d915SMatt Spinler * 5703c1d915SMatt Spinler * @param[in] pel - the PEL data stream 5803c1d915SMatt Spinler */ 5903c1d915SMatt Spinler explicit UserHeader(Stream& pel); 6003c1d915SMatt Spinler 6103c1d915SMatt Spinler /** 62cf5a8d0fSMatt Spinler * @brief Flatten the section into the stream 63cf5a8d0fSMatt Spinler * 64cf5a8d0fSMatt Spinler * @param[in] stream - The stream to write to 65cf5a8d0fSMatt Spinler */ 660688545bSMatt Spinler void flatten(Stream& stream) const override; 67cf5a8d0fSMatt Spinler 68cf5a8d0fSMatt Spinler /** 6903c1d915SMatt Spinler * @brief Returns the subsystem field. 7003c1d915SMatt Spinler * 7197d19b48SMatt Spinler * @return uint8_t - the subsystem 7203c1d915SMatt Spinler */ 7397d19b48SMatt Spinler uint8_t subsystem() const 7403c1d915SMatt Spinler { 7503c1d915SMatt Spinler return _eventSubsystem; 7603c1d915SMatt Spinler } 7703c1d915SMatt Spinler 7803c1d915SMatt Spinler /** 7903c1d915SMatt Spinler * @brief Returns the event scope field. 8003c1d915SMatt Spinler * 8197d19b48SMatt Spinler * @return uint8_t - the event scope 8203c1d915SMatt Spinler */ 8397d19b48SMatt Spinler uint8_t scope() const 8403c1d915SMatt Spinler { 8503c1d915SMatt Spinler return _eventScope; 8603c1d915SMatt Spinler } 8703c1d915SMatt Spinler 8803c1d915SMatt Spinler /** 8903c1d915SMatt Spinler * @brief Returns the severity field. 9003c1d915SMatt Spinler * 9197d19b48SMatt Spinler * @return uint8_t - the severity 9203c1d915SMatt Spinler */ 9397d19b48SMatt Spinler uint8_t severity() const 9403c1d915SMatt Spinler { 9503c1d915SMatt Spinler return _eventSeverity; 9603c1d915SMatt Spinler } 9703c1d915SMatt Spinler 9803c1d915SMatt Spinler /** 9903c1d915SMatt Spinler * @brief Returns the event type field. 10003c1d915SMatt Spinler * 10197d19b48SMatt Spinler * @return uint8_t - the event type 10203c1d915SMatt Spinler */ 10397d19b48SMatt Spinler uint8_t eventType() const 10403c1d915SMatt Spinler { 10503c1d915SMatt Spinler return _eventType; 10603c1d915SMatt Spinler } 10703c1d915SMatt Spinler 10803c1d915SMatt Spinler /** 109f1e85e20SMatt Spinler * @brief Set the event type field 110f1e85e20SMatt Spinler * 111f1e85e20SMatt Spinler * @param[in] type - the new event type 112f1e85e20SMatt Spinler */ 113f1e85e20SMatt Spinler void setEventType(uint8_t type) 114f1e85e20SMatt Spinler { 115f1e85e20SMatt Spinler _eventType = type; 116f1e85e20SMatt Spinler } 117f1e85e20SMatt Spinler 118f1e85e20SMatt Spinler /** 11903c1d915SMatt Spinler * @brief Returns the problem domain field. 12003c1d915SMatt Spinler * 12197d19b48SMatt Spinler * @return uint8_t - the problem domain 12203c1d915SMatt Spinler */ 12397d19b48SMatt Spinler uint8_t problemDomain() const 12403c1d915SMatt Spinler { 12503c1d915SMatt Spinler return _problemDomain; 12603c1d915SMatt Spinler } 12703c1d915SMatt Spinler 12803c1d915SMatt Spinler /** 12903c1d915SMatt Spinler * @brief Returns the problem vector field. 13003c1d915SMatt Spinler * 13197d19b48SMatt Spinler * @return uint8_t - the problem vector 13203c1d915SMatt Spinler */ 13397d19b48SMatt Spinler uint8_t problemVector() const 13403c1d915SMatt Spinler { 13503c1d915SMatt Spinler return _problemVector; 13603c1d915SMatt Spinler } 13703c1d915SMatt Spinler 13803c1d915SMatt Spinler /** 13903c1d915SMatt Spinler * @brief Returns the action flags field. 14003c1d915SMatt Spinler * 14197d19b48SMatt Spinler * @return uint16_t - the action flags 14203c1d915SMatt Spinler */ 14397d19b48SMatt Spinler uint16_t actionFlags() const 14403c1d915SMatt Spinler { 14503c1d915SMatt Spinler return _actionFlags; 14603c1d915SMatt Spinler } 14703c1d915SMatt Spinler 14803c1d915SMatt Spinler /** 149f1e85e20SMatt Spinler * @brief Sets the action flags field 150f1e85e20SMatt Spinler * 151f1e85e20SMatt Spinler * @param[in] flags - the new action flags 152f1e85e20SMatt Spinler */ 153f1e85e20SMatt Spinler void setActionFlags(uint16_t flags) 154f1e85e20SMatt Spinler { 155f1e85e20SMatt Spinler _actionFlags = flags; 156f1e85e20SMatt Spinler } 157f1e85e20SMatt Spinler 158f1e85e20SMatt Spinler /** 159eb111447SMatt Spinler * @brief Returns the host transmission state 160eb111447SMatt Spinler * 161eb111447SMatt Spinler * @return uint8_t - the host transmission state 162eb111447SMatt Spinler */ 163eb111447SMatt Spinler uint8_t hostTransmissionState() const 164eb111447SMatt Spinler { 165eb111447SMatt Spinler return _states & 0xFF; 166eb111447SMatt Spinler } 167eb111447SMatt Spinler 168eb111447SMatt Spinler /** 169eb111447SMatt Spinler * @brief Sets the host transmission state 170eb111447SMatt Spinler * 171eb111447SMatt Spinler * @param[in] state - the new state 172eb111447SMatt Spinler */ 173eb111447SMatt Spinler void setHostTransmissionState(uint8_t state) 174eb111447SMatt Spinler { 175eb111447SMatt Spinler _states &= 0xFFFFFF00; 176eb111447SMatt Spinler _states |= state; 177eb111447SMatt Spinler } 178eb111447SMatt Spinler 179eb111447SMatt Spinler /** 180eb111447SMatt Spinler * @brief Returns the HMC transmission state 181eb111447SMatt Spinler * 182eb111447SMatt Spinler * (HMC = Hardware Management Console) 183eb111447SMatt Spinler * 184eb111447SMatt Spinler * @return uint8_t - the HMC transmission state 185eb111447SMatt Spinler */ 186eb111447SMatt Spinler uint8_t hmcTransmissionState() const 187eb111447SMatt Spinler { 188eb111447SMatt Spinler return (_states & 0x0000FF00) >> 8; 189eb111447SMatt Spinler } 190eb111447SMatt Spinler 191eb111447SMatt Spinler /** 192eb111447SMatt Spinler * @brief Sets the HMC transmission state 193eb111447SMatt Spinler * 194eb111447SMatt Spinler * @param[in] state - the new state 195eb111447SMatt Spinler */ 196eb111447SMatt Spinler void setHMCTransmissionState(uint8_t state) 197eb111447SMatt Spinler { 198eb111447SMatt Spinler uint32_t newState = state << 8; 199eb111447SMatt Spinler _states &= 0xFFFF00FF; 200eb111447SMatt Spinler _states |= newState; 201eb111447SMatt Spinler } 202eb111447SMatt Spinler 203eb111447SMatt Spinler /** 20403c1d915SMatt Spinler * @brief Returns the size of this section when flattened into a PEL 20503c1d915SMatt Spinler * 20603c1d915SMatt Spinler * @return size_t - the size of the section 20703c1d915SMatt Spinler */ 20803c1d915SMatt Spinler static constexpr size_t flattenedSize() 20903c1d915SMatt Spinler { 21003c1d915SMatt Spinler return Section::flattenedSize() + sizeof(_eventSubsystem) + 21103c1d915SMatt Spinler sizeof(_eventScope) + sizeof(_eventSeverity) + 21203c1d915SMatt Spinler sizeof(_eventType) + sizeof(_reserved4Byte1) + 21303c1d915SMatt Spinler sizeof(_problemDomain) + sizeof(_problemVector) + 214eb111447SMatt Spinler sizeof(_actionFlags) + sizeof(_states); 21503c1d915SMatt Spinler } 21603c1d915SMatt Spinler 217ad0e0476SAatir Manzur /** 218ad0e0476SAatir Manzur * @brief Get section in JSON. 219c1489351SAatir * @return std::optional<std::string> -User header section's JSON 220ad0e0476SAatir Manzur */ 221ad0e0476SAatir Manzur std::optional<std::string> getJSON() const override; 222ad0e0476SAatir Manzur 22303c1d915SMatt Spinler private: 22403c1d915SMatt Spinler /** 225cf5a8d0fSMatt Spinler * @brief Fills in the object from the stream data 226cf5a8d0fSMatt Spinler * 227cf5a8d0fSMatt Spinler * @param[in] stream - The stream to read from 228cf5a8d0fSMatt Spinler */ 229cf5a8d0fSMatt Spinler void unflatten(Stream& stream); 230cf5a8d0fSMatt Spinler 231cf5a8d0fSMatt Spinler /** 23203c1d915SMatt Spinler * @brief Validates the section contents 23303c1d915SMatt Spinler * 23403c1d915SMatt Spinler * Updates _valid (in Section) with the results. 23503c1d915SMatt Spinler */ 23603c1d915SMatt Spinler void validate() override; 23703c1d915SMatt Spinler 23803c1d915SMatt Spinler /** 239*aadccc85SMatt Spinler * @brief Returns the severity value to use from the list 240*aadccc85SMatt Spinler * of them passed in based on the system type. 241*aadccc85SMatt Spinler * 242*aadccc85SMatt Spinler * If there isn't an entry found for the current system 243*aadccc85SMatt Spinler * type then std::nullopt will be returned. 244*aadccc85SMatt Spinler * 245*aadccc85SMatt Spinler * @param[in] severities - The array of {systype, severity} 246*aadccc85SMatt Spinler * structures to find an entry in. 247*aadccc85SMatt Spinler * @param[in] systemType - The system type from DataInterface. 248*aadccc85SMatt Spinler */ 249*aadccc85SMatt Spinler std::optional<uint8_t> 250*aadccc85SMatt Spinler getSeverity(const std::vector<message::RegistrySeverity>& severities, 251*aadccc85SMatt Spinler const std::string& systemType) const; 252*aadccc85SMatt Spinler /** 25303c1d915SMatt Spinler * @brief The subsystem associated with the event. 25403c1d915SMatt Spinler */ 25503c1d915SMatt Spinler uint8_t _eventSubsystem; 25603c1d915SMatt Spinler 25703c1d915SMatt Spinler /** 25803c1d915SMatt Spinler * @brief The event scope field. 25903c1d915SMatt Spinler */ 26003c1d915SMatt Spinler uint8_t _eventScope; 26103c1d915SMatt Spinler 26203c1d915SMatt Spinler /** 26303c1d915SMatt Spinler * @brief The event severity. 26403c1d915SMatt Spinler */ 26503c1d915SMatt Spinler uint8_t _eventSeverity; 26603c1d915SMatt Spinler 26703c1d915SMatt Spinler /** 26803c1d915SMatt Spinler * @brief The event type. 26903c1d915SMatt Spinler */ 27003c1d915SMatt Spinler uint8_t _eventType; 27103c1d915SMatt Spinler 27203c1d915SMatt Spinler /** 27303c1d915SMatt Spinler * @brief A reserved word placeholder 27403c1d915SMatt Spinler */ 27503c1d915SMatt Spinler uint32_t _reserved4Byte1; 27603c1d915SMatt Spinler 27703c1d915SMatt Spinler /** 27803c1d915SMatt Spinler * @brief The problem domain field. 27903c1d915SMatt Spinler */ 28003c1d915SMatt Spinler uint8_t _problemDomain; 28103c1d915SMatt Spinler 28203c1d915SMatt Spinler /** 28303c1d915SMatt Spinler * @brief The problem vector field. 28403c1d915SMatt Spinler */ 28503c1d915SMatt Spinler uint8_t _problemVector; 28603c1d915SMatt Spinler 28703c1d915SMatt Spinler /** 28803c1d915SMatt Spinler * @brief The action flags field. 28903c1d915SMatt Spinler */ 29003c1d915SMatt Spinler uint16_t _actionFlags; 29103c1d915SMatt Spinler 29203c1d915SMatt Spinler /** 293eb111447SMatt Spinler * @brief The second reserved word that we are 294eb111447SMatt Spinler * using for storing state information. 295eb111447SMatt Spinler * 296eb111447SMatt Spinler * 0x0000AABB 297eb111447SMatt Spinler * Where: 298eb111447SMatt Spinler * 0xAA = HMC transmission state 299eb111447SMatt Spinler * 0xBB = Host transmission state 30003c1d915SMatt Spinler */ 301eb111447SMatt Spinler uint32_t _states; 30203c1d915SMatt Spinler }; 30303c1d915SMatt Spinler 30403c1d915SMatt Spinler } // namespace pels 30503c1d915SMatt Spinler } // namespace openpower 306