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
diff --git a/host-transport-extensions/pldm/default/meson.build b/host-transport-extensions/pldm/default/meson.build
new file mode 100644
index 0000000..0ddd8b5
--- /dev/null
+++ b/host-transport-extensions/pldm/default/meson.build
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: Apache-2.0
+
+phosphor_dump_manager_sources += [
+ 'host-transport-extensions/pldm/default/pldm_interface.cpp'
+]
diff --git a/host-transport-extensions/pldm/default/pldm_interface.cpp b/host-transport-extensions/pldm/default/pldm_interface.cpp
new file mode 100644
index 0000000..57658af
--- /dev/null
+++ b/host-transport-extensions/pldm/default/pldm_interface.cpp
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: Apache-2.0
+
+namespace phosphor
+{
+namespace dump
+{
+namespace host
+{
+/**
+ * @brief Initiate offload of the dump with provided dump source ID
+ *
+ * @param[in] id - The Dump Source ID.
+ *
+ */
+void requestOffload(uint32_t)
+{
+ throw std::runtime_error("PLDM: Hostdump offload method not specified");
+}
+} // namespace host
+} // namespace dump
+} // namespace phosphor
diff --git a/host-transport-extensions/pldm/meson.build b/host-transport-extensions/pldm/meson.build
index d9cedd9..fc4c143 100644
--- a/host-transport-extensions/pldm/meson.build
+++ b/host-transport-extensions/pldm/meson.build
@@ -1,7 +1,13 @@
# SPDX-License-Identifier: Apache-2.0
phosphor_dump_manager_sources += [
- 'host-transport-extensions/pldm/pldm_interface.cpp'
+ 'host-transport-extensions/pldm/common/pldm_utils.cpp'
]
phosphor_dump_manager_dependency += [ dependency('libpldm') ]
+
+if get_option('openpower-dumps-extension').enabled()
+ subdir('oem/ibm')
+else
+ subdir('default')
+endif
diff --git a/host-transport-extensions/pldm/oem/ibm/meson.build b/host-transport-extensions/pldm/oem/ibm/meson.build
new file mode 100644
index 0000000..0f79a17
--- /dev/null
+++ b/host-transport-extensions/pldm/oem/ibm/meson.build
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: Apache-2.0
+
+phosphor_dump_manager_sources += [
+ 'host-transport-extensions/pldm/oem/ibm/pldm_oem_cmds.cpp'
+]
+
+phosphor_dump_manager_incdir += include_directories('../../common')
diff --git a/host-transport-extensions/pldm/pldm_interface.cpp b/host-transport-extensions/pldm/oem/ibm/pldm_oem_cmds.cpp
similarity index 79%
rename from host-transport-extensions/pldm/pldm_interface.cpp
rename to host-transport-extensions/pldm/oem/ibm/pldm_oem_cmds.cpp
index dfff103..be78718 100644
--- a/host-transport-extensions/pldm/pldm_interface.cpp
+++ b/host-transport-extensions/pldm/oem/ibm/pldm_oem_cmds.cpp
@@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "pldm_interface.hpp"
+#include "pldm_oem_cmds.hpp"
#include "dump_utils.hpp"
+#include "pldm_utils.hpp"
#include "xyz/openbmc_project/Common/error.hpp"
#include <libpldm/base.h>
@@ -92,19 +93,6 @@
return eid;
}
-int open()
-{
- 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<InternalFailure>();
- }
- return fd;
-}
-
void requestOffload(uint32_t id)
{
uint16_t effecterId = 0x05; // TODO PhyP temporary Hardcoded value.
@@ -136,7 +124,7 @@
uint8_t* responseMsg = nullptr;
size_t responseMsgSize{};
- auto fd = open();
+ auto fd = openPLDM();
rc = pldm_send_recv(eid, fd, requestMsg.data(), requestMsg.size(),
&responseMsg, &responseMsgSize);
@@ -156,25 +144,6 @@
closeFD(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/pldm_interface.hpp b/host-transport-extensions/pldm/oem/ibm/pldm_oem_cmds.hpp
similarity index 72%
rename from host-transport-extensions/pldm/pldm_interface.hpp
rename to host-transport-extensions/pldm/oem/ibm/pldm_oem_cmds.hpp
index fffa682..7e652f5 100644
--- a/host-transport-extensions/pldm/pldm_interface.hpp
+++ b/host-transport-extensions/pldm/oem/ibm/pldm_oem_cmds.hpp
@@ -6,6 +6,17 @@
{
namespace dump
{
+namespace host
+{
+/**
+ * @brief Initiate offload of the dump with provided id
+ *
+ * @param[in] id - The Dump Source ID.
+ *
+ */
+void requestOffload(uint32_t id);
+} // namespace host
+
namespace pldm
{
@@ -33,24 +44,10 @@
mctp_eid_t readEID();
/**
- * @brief Opens the PLDM file descriptor
- */
-int open();
-
-/**
* @brief Closes the PLDM file descriptor
*/
void closeFD(int fd);
-/**
- * @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