Skip presence detect and PEL for pass1 PCIe cards

Presence pin on pass1 planar does not reflect the true state of the
slot. It does not guarantee if the card is actually present in the slot
or not. Hence, the presence pin check is irrelevant in these scenarios
and is being skipped before enabling the line for VPD collection.

Availability of EEPROM after enabling the line should confirm if the
card needs to be collected or not.

Also, PCIe cards on pass1 is expected to have invalid VPD, avoiding
logging of PELs for those error scenarios.

Change-Id: Ia646b7d442a94fadea6b4c78d1d97c5a214579cb
Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
diff --git a/configuration/ibm/50001000.json b/configuration/ibm/50001000.json
index ae161af..77c7c80 100644
--- a/configuration/ibm/50001000.json
+++ b/configuration/ibm/50001000.json
@@ -1876,10 +1876,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "SLOT0_EXPANDER_PRSNT_N",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "SLOT0_PRSNT_EN_RSVD",
                             "value": 1
@@ -1986,10 +1982,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "SLOT3_EXPANDER_PRSNT_N",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "SLOT3_PRSNT_EN_RSVD",
                             "value": 1
@@ -2096,10 +2088,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "SLOT4_EXPANDER_PRSNT_N",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "SLOT4_PRSNT_EN_RSVD",
                             "value": 1
@@ -2203,10 +2191,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "SLOT10_EXPANDER_PRSNT_N",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "SLOT10_PRSNT_EN_RSVD",
                             "value": 1
@@ -2381,10 +2365,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "SLOT2_EXPANDER_PRSNT_N",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "SLOT2_PRSNT_EN_RSVD",
                             "value": 1
@@ -2445,10 +2425,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "SLOT6_EXPANDER_PRSNT_N",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "SLOT6_PRSNT_EN_RSVD",
                             "value": 1
@@ -2502,10 +2478,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "SLOT7_EXPANDER_PRSNT_N",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "SLOT7_PRSNT_EN_RSVD",
                             "value": 1
@@ -2566,10 +2538,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "SLOT9_EXPANDER_PRSNT_N",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "SLOT9_PRSNT_EN_RSVD",
                             "value": 1
@@ -2630,10 +2598,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "SLOT11_EXPANDER_PRSNT_N",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "SLOT11_PRSNT_EN_RSVD",
                             "value": 1
@@ -2763,10 +2727,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "SLOT1_EXPANDER_PRSNT_N",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "SLOT1_PRSNT_EN_RSVD",
                             "value": 1
diff --git a/configuration/ibm/50001001.json b/configuration/ibm/50001001.json
index 59459a8..bb42dd3 100644
--- a/configuration/ibm/50001001.json
+++ b/configuration/ibm/50001001.json
@@ -1722,10 +1722,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "SLOT0_EXPANDER_PRSNT_N",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "SLOT0_PRSNT_EN_RSVD",
                             "value": 1
@@ -1832,10 +1828,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "SLOT3_EXPANDER_PRSNT_N",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "SLOT3_PRSNT_EN_RSVD",
                             "value": 1
@@ -1942,10 +1934,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "SLOT4_EXPANDER_PRSNT_N",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "SLOT4_PRSNT_EN_RSVD",
                             "value": 1
@@ -2052,10 +2040,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "SLOT10_EXPANDER_PRSNT_N",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "SLOT10_PRSNT_EN_RSVD",
                             "value": 1
@@ -2230,10 +2214,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "SLOT2_EXPANDER_PRSNT_N",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "SLOT2_PRSNT_EN_RSVD",
                             "value": 1
@@ -2294,10 +2274,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "SLOT6_EXPANDER_PRSNT_N",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "SLOT6_PRSNT_EN_RSVD",
                             "value": 1
@@ -2351,10 +2327,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "SLOT7_EXPANDER_PRSNT_N",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "SLOT7_PRSNT_EN_RSVD",
                             "value": 1
@@ -2415,10 +2387,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "SLOT9_EXPANDER_PRSNT_N",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "SLOT9_PRSNT_EN_RSVD",
                             "value": 1
@@ -2479,10 +2447,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "SLOT11_EXPANDER_PRSNT_N",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "SLOT11_PRSNT_EN_RSVD",
                             "value": 1
@@ -2612,10 +2576,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "SLOT1_EXPANDER_PRSNT_N",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "SLOT1_PRSNT_EN_RSVD",
                             "value": 1
@@ -2676,10 +2636,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "SLOT8_EXPANDER_PRSNT_N",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "SLOT8_PRSNT_EN_RSVD",
                             "value": 1
diff --git a/configuration/ibm/50003000.json b/configuration/ibm/50003000.json
index b4911f8..cfdc503 100644
--- a/configuration/ibm/50003000.json
+++ b/configuration/ibm/50003000.json
@@ -2990,10 +2990,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "expander-cable-card1",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "presence-cable-card1",
                             "value": 1
@@ -3098,10 +3094,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "expander-cable-card2",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "presence-cable-card2",
                             "value": 1
@@ -3208,10 +3200,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "expander-cable-card3",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "presence-cable-card3",
                             "value": 1
@@ -3318,10 +3306,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "expander-cable-card4",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "presence-cable-card4",
                             "value": 1
@@ -3428,10 +3412,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "expander-cable-card5",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "presence-cable-card5",
                             "value": 1
@@ -3538,10 +3518,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "expander-cable-card6",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "presence-cable-card6",
                             "value": 1
@@ -3602,10 +3578,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "expander-cable-card7",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "presence-cable-card7",
                             "value": 1
@@ -3712,10 +3684,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "expander-cable-card8",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "presence-cable-card8",
                             "value": 1
@@ -3822,10 +3790,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "expander-cable-card9",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "presence-cable-card9",
                             "value": 1
@@ -3886,10 +3850,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "expander-cable-card10",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "presence-cable-card10",
                             "value": 1
@@ -3996,10 +3956,6 @@
                 "replaceableAtRuntime": true,
                 "preAction": {
                     "collection": {
-                        "gpioPresence": {
-                            "pin": "expander-cable-card11",
-                            "value": 0
-                        },
                         "setGpio": {
                             "pin": "presence-cable-card11",
                             "value": 1
diff --git a/vpd-manager/include/constants.hpp b/vpd-manager/include/constants.hpp
index 5faf8da..7f23070 100644
--- a/vpd-manager/include/constants.hpp
+++ b/vpd-manager/include/constants.hpp
@@ -90,6 +90,7 @@
 static constexpr auto VALUE_6 = 6;
 static constexpr auto VALUE_7 = 7;
 static constexpr auto VALUE_8 = 8;
+static constexpr auto VALUE_21 = 21;
 
 static constexpr auto MASK_BYTE_BITS_01 = 0x03;
 static constexpr auto MASK_BYTE_BITS_345 = 0x38;
@@ -120,6 +121,8 @@
 constexpr auto vsysInf = "com.ibm.ipzvpd.VSYS";
 constexpr auto utilInf = "com.ibm.ipzvpd.UTIL";
 constexpr auto vcenInf = "com.ibm.ipzvpd.VCEN";
+constexpr auto viniInf = "com.ibm.ipzvpd.VINI";
+constexpr auto vsbpInf = "com.ibm.ipzvpd.VSBP";
 constexpr auto kwdCCIN = "CC";
 constexpr auto kwdRG = "RG";
 constexpr auto kwdAMM = "D0";
@@ -128,6 +131,8 @@
 constexpr auto kwdFC = "FC";
 constexpr auto kwdTM = "TM";
 constexpr auto kwdSE = "SE";
+constexpr auto kwdHW = "HW";
+constexpr auto kwdIM = "IM";
 constexpr auto recVSYS = "VSYS";
 constexpr auto recVCEN = "VCEN";
 constexpr auto locationCodeInf = "com.ibm.ipzvpd.Location";
diff --git a/vpd-manager/include/utility/vpd_specific_utility.hpp b/vpd-manager/include/utility/vpd_specific_utility.hpp
index d6b92fd..9e679a7 100644
--- a/vpd-manager/include/utility/vpd_specific_utility.hpp
+++ b/vpd-manager/include/utility/vpd_specific_utility.hpp
@@ -552,5 +552,48 @@
                             " with error: " + std::string(l_ex.what()));
     }
 }
+
+/**
+ * @brief API to detect pass1 planar type.
+ *
+ * Based on HW version and IM keyword, This API detects is it is a pass1 planar
+ * or not.
+ *
+ * @return True if pass 1 planar, false otherwise.
+ */
+inline bool isPass1Planar()
+{
+    auto l_retVal = dbusUtility::readDbusProperty(
+        constants::pimServiceName, constants::systemVpdInvPath,
+        constants::viniInf, constants::kwdHW);
+
+    auto l_hwVer = std::get_if<types::BinaryVector>(&l_retVal);
+
+    l_retVal = dbusUtility::readDbusProperty(
+        constants::pimServiceName, constants::systemInvPath, constants::vsbpInf,
+        constants::kwdIM);
+
+    auto l_imValue = std::get_if<types::BinaryVector>(&l_retVal);
+
+    if (l_hwVer && l_imValue)
+    {
+        types::BinaryVector everest{80, 00, 48, 00};
+        types::BinaryVector fuji{96, 00, 32, 00};
+
+        if (((*l_imValue) == everest) || ((*l_imValue) == fuji))
+        {
+            if ((*l_hwVer).at(1) < constants::VALUE_21)
+            {
+                return true;
+            }
+        }
+        else if ((*l_hwVer).at(1) < constants::VALUE_2)
+        {
+            return true;
+        }
+    }
+
+    return false;
+}
 } // namespace vpdSpecificUtility
 } // namespace vpd
diff --git a/vpd-manager/src/worker.cpp b/vpd-manager/src/worker.cpp
index ff92264..d1bd00c 100644
--- a/vpd-manager/src/worker.cpp
+++ b/vpd-manager/src/worker.cpp
@@ -1449,6 +1449,24 @@
         // based on status of execution.
         if (typeid(ex) == std::type_index(typeid(DataException)))
         {
+            // In case of pass1 planar, VPD can be corrupted on PCIe cards. Skip
+            // logging error for these cases.
+            if (vpdSpecificUtility::isPass1Planar())
+            {
+                const std::string& l_invPathLeafValue =
+                    sdbusplus::message::object_path(
+                        jsonUtility::getInventoryObjPathFromJson(m_parsedJson,
+                                                                 i_vpdFilePath))
+                        .filename();
+
+                if ((l_invPathLeafValue.find("pcie_card", 0) !=
+                     std::string::npos))
+                {
+                    // skip logging any PEL for PCIe cards on pass 1 planar.
+                    return std::make_tuple(false, i_vpdFilePath);
+                }
+            }
+
             // TODO: Add custom handling
             logging::logMessage(ex.what());
         }