PEL: Modify the sbe ffdc handler to cater for POZ format

A new format is defined for the FFDC data received from
odyssey SBE.

The old format will be used for the proc chip, and the new format will
be used for odyssey OCMB.

Using the chiptype defined in the additionalData section of the
PEL to collect the respective FFDC.

passing "chip type" to libekb to collect respective ffdc data.

Tested:
'''
---p10-poz format---
phosphor-log-manager[11319]: POZFFDC magic bytes 0xfbad
phosphor-log-manager[11319]: POZFFDC lengthinWords 0x18
phosphor-log-manager[11319]: POZFFDC seqId 0x0
phosphor-log-manager[11319]: POZFFDC cmdClass 0xc1
phosphor-log-manager[11319]: POZFFDC cmd 0x1
phosphor-log-manager[11319]: POZFFDC slid 0x2
phosphor-log-manager[11319]: POZFFDC severity 0x2
phosphor-log-manager[11319]: POZFFDC chipId 0x0
phosphor-log-manager[11319]: POZFFDC fapiRc 0x9fb509
phosphor-log-manager[11319]: POZFFDC pktLenWords 0x15

phosphor-log-manager[11319]: HWP_RC= RC_ERROR_UNSUPPORTED_BY_SBE
phosphor-log-manager[11319]: HWP_RC_DESC= An error was encountered
that the SBE didn't expect.
phosphor-log-manager[11319]: HWP_FFDC_INVALID_ERRVAL= 009fb509

---p10-ffdc format---
phosphor-log-manager[364]: SBE FFDC processing requested
phosphor-log-manager[364]: SBE FFDC file fd:(8), parsing started
phosphor-log-manager[364]: P10 FFDC magic: 65500 length in
	words:151 Fapirc:81920
phosphor-log-manager[364]: P10 FFDC magic: 65500 length in
	words:24 Fapirc:131584
phosphor-log-manager[364]: Created PEL 0x50005409 (BMC ID 842)
	with SRC BD20F401
'''
Signed-off-by: Marri Devender Rao <devenrao@in.ibm.com>
Change-Id: Id6b1eb0e2b91c2459bf78abd52e6a3d233d81206
diff --git a/extensions/openpower-pels/sbe_ffdc_handler.cpp b/extensions/openpower-pels/sbe_ffdc_handler.cpp
index 67f515c..8d420bf 100644
--- a/extensions/openpower-pels/sbe_ffdc_handler.cpp
+++ b/extensions/openpower-pels/sbe_ffdc_handler.cpp
@@ -25,6 +25,7 @@
 #include "temporary_file.hpp"
 
 #include <ekb/hwpf/fapi2/include/return_code_defs.H>
+#include <ekb/hwpf/fapi2/include/target_types.H>
 #include <libekb.H>
 
 #include <phosphor-logging/log.hpp>
@@ -39,13 +40,13 @@
 namespace sbe
 {
 
-using namespace phosphor::logging;
-
 constexpr uint32_t sbeMaxFfdcPackets = 20;
-constexpr uint32_t ffdcPkgOneWord = 1;
-const uint16_t ffdcMagicCode = 0xFFDC;
+constexpr uint16_t p10FfdcMagicCode = 0xFFDC;
+constexpr uint16_t pozFfdcMagicCode = 0xFBAD;
+constexpr uint16_t p10FfdcSkipWords = 2;
+constexpr uint16_t pozFfdcSkipWords = 3;
 
-typedef struct
+struct p10FfdcHeader
 {
     uint32_t magic_bytes:16;
     uint32_t lengthinWords:16;
@@ -53,10 +54,25 @@
     uint32_t cmdClass:8;
     uint32_t cmd:8;
     uint32_t fapiRc;
-} __attribute__((packed)) fapiFfdcBufType;
+} __attribute__((packed));
+
+struct pozFfdcHeader
+{
+    uint32_t magicByte:16;
+    uint32_t lengthinWords:16;
+    uint32_t seqId:16;
+    uint32_t cmdClass:8;
+    uint32_t cmd:8;
+    uint32_t slid:16;
+    uint32_t severity:8;
+    uint32_t chipId:8;
+    uint32_t fapiRc;
+} __attribute__((packed));
+
+using namespace phosphor::logging;
 
 SbeFFDC::SbeFFDC(const AdditionalData& aData, const PelFFDC& files) :
-    ffdcType(FFDC_TYPE_NONE)
+    ffdcType(FFDC_TYPE_NONE), chipType(fapi2::TARGET_TYPE_PROC_CHIP)
 {
     log<level::INFO>("SBE FFDC processing requested");
 
@@ -71,7 +87,7 @@
     }
     try
     {
-        procPos = (std::stoi(src6.value()) & 0xFFFF0000) >> 16;
+        chipPos = (std::stoi(src6.value()) & 0xFFFF0000) >> 16;
     }
     catch (const std::exception& err)
     {
@@ -79,6 +95,21 @@
             std::format("Conversion failure errormsg({})", err.what()).c_str());
         return;
     }
+    auto type = aData.getValue("CHIP_TYPE");
+    if (type != std::nullopt)
+    {
+        try
+        {
+            chipType = std::stoi(type.value());
+        }
+        catch (const std::exception& err)
+        {
+            log<level::ERR>(
+                std::format("Conversion failure errormsg({})", err.what())
+                    .c_str());
+            return;
+        }
+    }
 
     if (files.empty())
     {
@@ -117,40 +148,73 @@
     while ((ffdcBufOffset < ffdcData.size()) && (sbeMaxFfdcPackets != pktCount))
     {
         sbeFfdcPacketType ffdcPkt;
-
         // Next un-extracted FFDC Packet
-        fapiFfdcBufType* ffdc =
-            reinterpret_cast<fapiFfdcBufType*>(ffdcData.data() + ffdcBufOffset);
-        auto magicBytes = ntohs(ffdc->magic_bytes);
-        auto lenWords = ntohs(ffdc->lengthinWords);
-        auto fapiRc = ntohl(ffdc->fapiRc);
-
-        auto msg = std::format("FFDC magic: {} length in words:{} Fapirc:{}",
-                               magicBytes, lenWords, fapiRc);
-        log<level::INFO>(msg.c_str());
-
-        if (magicBytes != ffdcMagicCode)
+        uint16_t magicBytes =
+            *(reinterpret_cast<uint16_t*>(ffdcData.data() + ffdcBufOffset));
+        magicBytes = ntohs(magicBytes);
+        uint32_t pktLenWords = 0;
+        uint16_t lenWords = 0;
+        if (magicBytes == p10FfdcMagicCode)
         {
-            log<level::ERR>("Invalid FFDC magic code in Header: Skipping ");
-            return;
+            p10FfdcHeader* ffdc = reinterpret_cast<p10FfdcHeader*>(
+                ffdcData.data() + ffdcBufOffset);
+            lenWords = ntohs(ffdc->lengthinWords);
+            auto fapiRc = ntohl(ffdc->fapiRc);
+
+            auto msg =
+                std::format("P10 FFDC magic: {} length in words:{} Fapirc:{}",
+                            magicBytes, lenWords, fapiRc);
+            log<level::INFO>(msg.c_str());
+
+            ffdcPkt.fapiRc = fapiRc;
+            // Not interested in the first 2 words (these are not ffdc)
+            pktLenWords = lenWords - p10FfdcSkipWords;
+            ffdcPkt.ffdcLengthInWords = pktLenWords;
+            if (pktLenWords)
+            {
+                ffdcPkt.ffdcData = new uint32_t[pktLenWords];
+                memcpy(ffdcPkt.ffdcData,
+                       ((reinterpret_cast<uint32_t*>(ffdc)) + p10FfdcSkipWords),
+                       (pktLenWords * sizeof(uint32_t)));
+            }
+            else
+            {
+                log<level::ERR>("FFDC packet size is zero skipping");
+                return;
+            }
         }
-        ffdcPkt.fapiRc = fapiRc;
-        // Not interested in the first 2 words (these are not ffdc)
-        auto pktLenWords = lenWords - (2 * ffdcPkgOneWord);
-        ffdcPkt.ffdcLengthInWords = pktLenWords;
-        if (pktLenWords)
+        else if (magicBytes == pozFfdcMagicCode)
         {
-            // Memory freeing will be taking care by ffdcPkt structure
-            // destructor
-            ffdcPkt.ffdcData = new uint32_t[pktLenWords];
-            memcpy(ffdcPkt.ffdcData,
-                   ((reinterpret_cast<uint32_t*>(ffdc)) +
-                    (2 * ffdcPkgOneWord)), // skip first 2 words
-                   (pktLenWords * sizeof(uint32_t)));
+            pozFfdcHeader* ffdc = reinterpret_cast<pozFfdcHeader*>(
+                ffdcData.data() + ffdcBufOffset);
+            lenWords = ntohs(ffdc->lengthinWords);
+            auto fapiRc = ntohl(ffdc->fapiRc);
+
+            auto msg =
+                std::format("P0Z FFDC magic: {} length in words:{} Fapirc:{}",
+                            magicBytes, lenWords, fapiRc);
+            log<level::INFO>(msg.c_str());
+
+            ffdcPkt.fapiRc = fapiRc;
+            // Not interested in the first 3 words (these are not ffdc)
+            pktLenWords = lenWords - pozFfdcSkipWords;
+            ffdcPkt.ffdcLengthInWords = pktLenWords;
+            if (pktLenWords)
+            {
+                ffdcPkt.ffdcData = new uint32_t[pktLenWords];
+                memcpy(ffdcPkt.ffdcData,
+                       ((reinterpret_cast<uint32_t*>(ffdc)) + pozFfdcSkipWords),
+                       (pktLenWords * sizeof(uint32_t)));
+            }
+            else
+            {
+                log<level::ERR>("FFDC packet size is zero skipping");
+                return;
+            }
         }
         else
         {
-            log<level::ERR>("FFDC packet size is zero skipping");
+            log<level::ERR>("Invalid FFDC magic code in Header: Skipping ");
             return;
         }
 
@@ -202,7 +266,7 @@
     {
         // libekb provided wrapper function to convert SBE FFDC
         // in to known ffdc structure.
-        libekb_get_sbe_ffdc(ffdc, ffdcPkt, procPos);
+        libekb_get_sbe_ffdc(ffdc, ffdcPkt, chipPos, chipType);
     }
     catch (...)
     {
diff --git a/extensions/openpower-pels/sbe_ffdc_handler.hpp b/extensions/openpower-pels/sbe_ffdc_handler.hpp
index effee2f..b2cfe17 100644
--- a/extensions/openpower-pels/sbe_ffdc_handler.hpp
+++ b/extensions/openpower-pels/sbe_ffdc_handler.hpp
@@ -32,7 +32,8 @@
  *    1. A failed hardware procedure (e.g. local variable values
  *       at point of failure) or
  *    2. SBE firmware (e.g. traces, attributes and other information).
- *    ___________________________________________________________
+ *
+ *   -------------------P10 proc-----------------------
  *   |        |  Byte 0   |  Byte 1  |  Byte 2    |    Byte 3   |
  *   |----------------------------------------------------------|
  *   | Word 0 | Magic Bytes : 0xFFDC | Length in words (N+4)    |
@@ -42,6 +43,51 @@
  *   |  ...                                                     |
  *   | Word N+3 |  FFDC Data – Word N                           |
  *    -----------------------------------------------------------
+ *
+ *   --------------POZ - PowerOdysseyZEE-----------------------
+ *   First FFDC packet structure
+ *   --------------------------------------------------------------
+ *   |          |  Byte 0   |  Byte 1  |  Byte 2    |    Byte 3   |
+ *   |------------------------------------------------------------|
+ *   | Word 0   | Magic Bytes : 0xFBAD | Length in words (N+4)    |
+ *   | Word 1   | [Sequence ID]        | Command-Class | Command  |
+ *   | Word 2   | SLID                 | Severity      | Chip ID  |
+ *   | Word 3   |           FAPI RC (HWP)                         |
+ *   | Word 4   | HWP FFDC Dump Fields (Local FFDC | HW Register) |
+ *   | Word 6   | Field ID 0(Local FFDC) | Field ID 0 Length      |
+ *   | Word 7   |          Filed Data 0(Size1, data2)             |
+ *   |  ...                                                       |
+ *   | Word N   |          Filed Data N(Size1, data2)             |
+ *   | Word N+1 | Field ID 1(HW Register) | Field ID 1 Length     |
+ *   | Word N+2 |              Filed Data 0)                      |
+ *   |  ...                                                       |
+ *   | Word Y   |              Filed Data M)                      |
+ *    -------------------------------------------------------------
+ *   Second FFDC packet structure
+ *   --------------------------------------------------------------
+ *   |          |  Byte 0   |  Byte 1  |  Byte 2    |    Byte 3   |
+ *   |------------------------------------------------------------|
+ *   | Word 0   | Magic Bytes : 0xFBAD | Length in words (N+4)    |
+ *   | Word 1   | [Sequence ID]        | Command-Class | Command  |
+ *   | Word 2   | SLID                 | Severity      | Chip ID  |
+ *   | Word 3   |       FAPI RC (PLAT ERR SEE DATA)               |
+ *   | Word 4   | Primary Status       | Secondary Status         |
+ *   | Word 5   |             FW commit ID                        |
+ *   | Word 5   | Reserve | DD Major   | DD Minor      | Thread ID|
+ *   | Word 4   |         SBE FFDC Dump Fields (Bitmaped)         |
+ *   | Word 6   | Field ID 0           | Field ID 0 Length        |
+ *   | Word 7   |              Filed Data 0                       |
+ *   |  ...                                                       |
+ *   | Word N   |              Filed Data N                       |
+ *   | Word N+1 | Field ID 1           | Field ID 1 Length        |
+ *   | Word N+2 |       Filed Data 0)                             |
+ *   |  ...                                                       |
+ *   | Word Y   |       Filed Data M)                             |
+ *   | Word Y+1 | 0xCODE               | 0xA8         | 0x1       |
+ *   | Word Y+2 | Primary Status       | Secondary Status         |
+ *   | Word Y+3 |          Distance to Header                     |
+ *    -------------------------------------------------------------
+ *
  **/
 
 using LogSeverity = phosphor::logging::Entry::Level;
@@ -172,14 +218,19 @@
     PelFFDC ffdcFiles;
 
     /**
-     * @brief Processor position associated to SBE FFDC
+     * @brief Chip position associated to SBE FFDC
      */
-    uint32_t procPos;
+    uint32_t chipPos;
 
     /**
      * @brief Used to get type of ffdc
      */
     FFDC_TYPE ffdcType;
+
+    /**
+     * @brief Chip type associated to SBE FFDC
+     */
+    uint32_t chipType;
 };
 
 } // namespace sbe