summaryrefslogtreecommitdiff
path: root/redfish-core/include
diff options
context:
space:
mode:
authorLakshmi Yadlapati <lakshmiy@us.ibm.com>2023-04-20 00:42:35 +0300
committerLakshmi Yadlapati <lakshmiy@us.ibm.com>2023-06-16 16:58:27 +0300
commitc49c329d2ccf45859030844eb205a8476148fb25 (patch)
treeb4783dd11c76922b53862e2effd53460a3a42bcc /redfish-core/include
parent44845e5f7082a16d7f105e401c24ca68529baf81 (diff)
downloadbmcweb-c49c329d2ccf45859030844eb205a8476148fb25.tar.xz
Move PCIe functions to common file
Move redfishPcieGenerationFromDbus, called from both pcie.hpp and pcie_slots.hpp, and busSlotTypeToRf functions, called from pcie_slots.hpp, to a common PCIe utility file. In the future commit, when integrating PCIeSlot with PCIeDevice, we will call the busSlotTypeToRf function from pcie.hpp, so having it in the common utility file will make it readily available. Tested: build successful, no additional testing needed. Change-Id: I6286bd5547ddafa6eac4f224ac56f6d790a44c7a Signed-off-by: Lakshmi Yadlapati <lakshmiy@us.ibm.com>
Diffstat (limited to 'redfish-core/include')
-rw-r--r--redfish-core/include/utils/pcie_util.hpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/redfish-core/include/utils/pcie_util.hpp b/redfish-core/include/utils/pcie_util.hpp
index 7b094feed1..d9e8480cc9 100644
--- a/redfish-core/include/utils/pcie_util.hpp
+++ b/redfish-core/include/utils/pcie_util.hpp
@@ -3,6 +3,8 @@
#include "async_resp.hpp"
#include "dbus_utility.hpp"
#include "error_messages.hpp"
+#include "generated/enums/pcie_device.hpp"
+#include "generated/enums/pcie_slots.hpp"
#include "http/utility.hpp"
#include <boost/system/error_code.hpp>
@@ -11,6 +13,7 @@
#include <array>
#include <memory>
+#include <optional>
#include <string>
#include <string_view>
@@ -72,5 +75,99 @@ inline void
});
}
+inline std::optional<pcie_slots::SlotTypes>
+ dbusSlotTypeToRf(const std::string& slotType)
+{
+ if (slotType ==
+ "xyz.openbmc_project.Inventory.Item.PCIeSlot.SlotTypes.FullLength")
+ {
+ return pcie_slots::SlotTypes::FullLength;
+ }
+ if (slotType ==
+ "xyz.openbmc_project.Inventory.Item.PCIeSlot.SlotTypes.HalfLength")
+ {
+ return pcie_slots::SlotTypes::HalfLength;
+ }
+ if (slotType ==
+ "xyz.openbmc_project.Inventory.Item.PCIeSlot.SlotTypes.LowProfile")
+ {
+ return pcie_slots::SlotTypes::LowProfile;
+ }
+ if (slotType ==
+ "xyz.openbmc_project.Inventory.Item.PCIeSlot.SlotTypes.Mini")
+ {
+ return pcie_slots::SlotTypes::Mini;
+ }
+ if (slotType == "xyz.openbmc_project.Inventory.Item.PCIeSlot.SlotTypes.M_2")
+ {
+ return pcie_slots::SlotTypes::M2;
+ }
+ if (slotType == "xyz.openbmc_project.Inventory.Item.PCIeSlot.SlotTypes.OEM")
+ {
+ return pcie_slots::SlotTypes::OEM;
+ }
+ if (slotType ==
+ "xyz.openbmc_project.Inventory.Item.PCIeSlot.SlotTypes.OCP3Small")
+ {
+ return pcie_slots::SlotTypes::OCP3Small;
+ }
+ if (slotType ==
+ "xyz.openbmc_project.Inventory.Item.PCIeSlot.SlotTypes.OCP3Large")
+ {
+ return pcie_slots::SlotTypes::OCP3Large;
+ }
+ if (slotType == "xyz.openbmc_project.Inventory.Item.PCIeSlot.SlotTypes.U_2")
+ {
+ return pcie_slots::SlotTypes::U2;
+ }
+ if (slotType ==
+ "xyz.openbmc_project.Inventory.Item.PCIeSlot.SlotTypes.Unknown")
+ {
+ return pcie_slots::SlotTypes::Invalid;
+ }
+
+ // Unspecified slotType should return an internal error.
+ return std::nullopt;
+}
+
+inline std::optional<pcie_device::PCIeTypes>
+ redfishPcieGenerationFromDbus(const std::string& generationInUse)
+{
+ if (generationInUse ==
+ "xyz.openbmc_project.Inventory.Item.PCIeSlot.Generations.Gen1")
+ {
+ return pcie_device::PCIeTypes::Gen1;
+ }
+ if (generationInUse ==
+ "xyz.openbmc_project.Inventory.Item.PCIeSlot.Generations.Gen2")
+ {
+ return pcie_device::PCIeTypes::Gen2;
+ }
+ if (generationInUse ==
+ "xyz.openbmc_project.Inventory.Item.PCIeSlot.Generations.Gen3")
+ {
+ return pcie_device::PCIeTypes::Gen3;
+ }
+ if (generationInUse ==
+ "xyz.openbmc_project.Inventory.Item.PCIeSlot.Generations.Gen4")
+ {
+ return pcie_device::PCIeTypes::Gen4;
+ }
+ if (generationInUse ==
+ "xyz.openbmc_project.Inventory.Item.PCIeSlot.Generations.Gen5")
+ {
+ return pcie_device::PCIeTypes::Gen5;
+ }
+ if (generationInUse.empty() ||
+ generationInUse ==
+ "xyz.openbmc_project.Inventory.Item.PCIeSlot.Generations.Unknown")
+ {
+ return pcie_device::PCIeTypes::Invalid;
+ }
+
+ // The value is not unknown or Gen1-5, need return an internal error.
+ return std::nullopt;
+}
+
} // namespace pcie_util
} // namespace redfish