blob: 3d3b3045e69bd715314a9a5e2e69dd7a59ab5fab [file] [log] [blame]
#pragma once
#include "xyz/openbmc_project/Logging/Entry/server.hpp"
#include <phal_exception.H>
#include <nlohmann/json.hpp>
#include <xyz/openbmc_project/Logging/Create/server.hpp>
#include <optional>
#include <string>
#include <tuple>
#include <vector>
namespace openpower::dump::pel
{
using FFDCData = std::vector<std::pair<std::string, std::string>>;
using Severity = sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level;
using json = nlohmann::json;
using namespace openpower::phal;
using PELFFDCInfo = std::vector<std::tuple<
sdbusplus::xyz::openbmc_project::Logging::server::Create::FFDCFormat,
uint8_t, uint8_t, sdbusplus::message::unix_fd>>;
/**
* @brief Create SBE boot error PEL and return id
*
* @param[in] event - the event type
* @param[in] sbeError - SBE error object
* @param[in] ffdcData - failure data to append to PEL
* @param[in] severity - severity of the log
* @return Platform log id
*/
uint32_t createSbeErrorPEL(
const std::string& event, const sbeError_t& sbeError,
const FFDCData& ffdcData, const Severity severity = Severity::Error,
const std::optional<PELFFDCInfo>& pelFFDCInfoOpt = std::nullopt);
/**
* @brief Convert a FAPI2 severity code to PEL severity.
*
* @param[in] severity - Severity code from FAPI2 error logs.
* @return Severity - The corresponding Severity enumeration value.
*/
openpower::dump::pel::Severity convertSeverityToEnum(uint8_t severity);
/**
* @brief Process FFDC packets and create PELs for each packet.
*
* @param[in] sbeError - An SBE error object containing FFDC packet information.
* @param[in] event - The event identifier associated with the PELs.
* @param[out] pelAdditionalData - A reference to additional PEL data to be
* included in the PEL.
*/
void processFFDCPackets(const openpower::phal::sbeError_t& sbeError,
const std::string& event,
openpower::dump::pel::FFDCData& pelAdditionalData);
/**
* @class FFDCFile
* @brief This class is used to create ffdc data file and to get fd
*/
class FFDCFile
{
public:
FFDCFile() = delete;
FFDCFile(const FFDCFile&) = delete;
FFDCFile& operator=(const FFDCFile&) = delete;
FFDCFile(FFDCFile&&) = delete;
FFDCFile& operator=(FFDCFile&&) = delete;
/**
* Used to pass json object to create unique ffdc file by using
* passed json data.
*/
explicit FFDCFile(const json& pHALCalloutData);
/**
* Used to remove created ffdc file.
*/
~FFDCFile();
/**
* Used to get created ffdc file file descriptor id.
*
* @return file descriptor id
*/
int getFileFD() const;
private:
/**
* Used to store callout ffdc data from passed json object.
*/
std::string calloutData;
/**
* Used to store unique ffdc file name.
*/
std::string calloutFile;
/**
* Used to store created ffdc file descriptor id.
*/
int fileFD;
/**
* Used to create ffdc file to pass PEL api for creating
* pel records.
*
* @return NULL
*/
void prepareFFDCFile();
/**
* Create unique ffdc file.
*
* @return NULL
*/
void createCalloutFile();
/**
* Used write json object value into created file.
*
* @return NULL
*/
void writeCalloutData();
/**
* Used set ffdc file seek position beginning to consume by PEL
*
* @return NULL
*/
void setCalloutFileSeekPos();
/**
* Used to remove created ffdc file.
*
* @return NULL
*/
void removeCalloutFile();
}; // FFDCFile end
} // namespace openpower::dump::pel