offload: Moved existing pldm offload as oem/ibm command
Currently used host mctp end point id is ibm specific and also
the used effecter id (0x05) is for phyp and "SetNumericEffecterValue"
pldm command is common so, changing existing pldm offload implementation
into oem based and added default pldm offload interface as well.
Signed-off-by: Ramesh Iyyar <rameshi1@in.ibm.com>
Change-Id: I8a401e03d29f9245dd54577b8b7b1d87d4a13d18
diff --git a/host-transport-extensions/pldm/common/pldm_utils.cpp b/host-transport-extensions/pldm/common/pldm_utils.cpp
new file mode 100644
index 0000000..7c15929
--- /dev/null
+++ b/host-transport-extensions/pldm/common/pldm_utils.cpp
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: Apache-2.0
+
+#include "pldm_utils.hpp"
+
+#include "dump_utils.hpp"
+#include "xyz/openbmc_project/Common/error.hpp"
+
+#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/log.hpp>
+
+namespace phosphor
+{
+namespace dump
+{
+namespace pldm
+{
+
+using namespace phosphor::logging;
+using NotAllowed = sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;
+using Reason = xyz::openbmc_project::Common::NotAllowed::REASON;
+
+int openPLDM()
+{
+ auto fd = pldm_open();
+ if (fd < 0)
+ {
+ auto e = errno;
+ log<level::ERR>("pldm_open failed", entry("ERRNO=%d", e),
+ entry("FD=%d\n", fd));
+ elog<NotAllowed>(Reason("Required host dump action via pldm is not "
+ "allowed due to pldm_open failed"));
+ }
+ return fd;
+}
+
+uint8_t getPLDMInstanceID(uint8_t eid)
+{
+
+ constexpr auto pldmRequester = "xyz.openbmc_project.PLDM.Requester";
+ constexpr auto pldm = "/xyz/openbmc_project/pldm";
+
+ auto bus = sdbusplus::bus::new_default();
+ auto service = phosphor::dump::getService(bus, pldm, pldmRequester);
+
+ auto method = bus.new_method_call(service.c_str(), pldm, pldmRequester,
+ "GetInstanceId");
+ method.append(eid);
+ auto reply = bus.call(method);
+
+ uint8_t instanceID = 0;
+ reply.read(instanceID);
+
+ return instanceID;
+}
+
+} // namespace pldm
+} // namespace dump
+} // namespace phosphor
diff --git a/host-transport-extensions/pldm/common/pldm_utils.hpp b/host-transport-extensions/pldm/common/pldm_utils.hpp
new file mode 100644
index 0000000..80a4725
--- /dev/null
+++ b/host-transport-extensions/pldm/common/pldm_utils.hpp
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: Apache-2.0
+
+#pragma once
+
+#include <libpldm/pldm.h>
+
+namespace phosphor
+{
+namespace dump
+{
+namespace pldm
+{
+
+/**
+ * @brief Opens the PLDM file descriptor
+ *
+ * @return file descriptor on success and throw
+ * exception (xyz::openbmc_project::Common::Error::NotAllowed) on
+ * failures.
+ */
+int openPLDM();
+
+/**
+ * @brief Returns the PLDM instance ID to use for PLDM commands
+ *
+ * @param[in] eid - The PLDM EID
+ *
+ * @return uint8_t - The instance ID
+ **/
+uint8_t getPLDMInstanceID(uint8_t eid);
+
+} // namespace pldm
+} // namespace dump
+} // namespace phosphor