Move to libpldm pldm_transport APIs
Replaced pldm transport APIs with libpldm pldm_transport APIs to
remove the dependency on pldm.
This change removes the dependency on pldm by utilizing the
standardized libpldm APIs for transport operations, improving
maintainability and compatibility.
We don't currently have the infrastructure in place to get the correct
TIDs, so to keep everything working as before use the EID as the TID in
the EID-to-TID mapping.
Test: Tested the resource dump download and delete using GUI
and it works as expected.
Change-Id: I3ec741024c7b99f0ee630678f3b3b49f741e1ea1
Signed-off-by: Lakshmi Yadlapati <lakshmiy@us.ibm.com>
Signed-off-by: Eddie James <eajames@linux.ibm.com>
diff --git a/host-transport-extensions/pldm/common/pldm_utils.cpp b/host-transport-extensions/pldm/common/pldm_utils.cpp
index 39da125..a951fd7 100644
--- a/host-transport-extensions/pldm/common/pldm_utils.cpp
+++ b/host-transport-extensions/pldm/common/pldm_utils.cpp
@@ -6,6 +6,8 @@
#include "xyz/openbmc_project/Common/error.hpp"
#include <libpldm/transport.h>
+#include <libpldm/transport/mctp-demux.h>
+#include <poll.h>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/lg2.hpp>
@@ -22,6 +24,8 @@
using Reason = xyz::openbmc_project::Common::NotAllowed::REASON;
pldm_instance_db* pldmInstanceIdDb = nullptr;
+pldm_transport* pldmTransport = nullptr;
+pldm_transport_mctp_demux* mctpDemux = nullptr;
PLDMInstanceManager::PLDMInstanceManager()
{
@@ -90,21 +94,72 @@
}
}
-int openPLDM()
+int openPLDM(mctp_eid_t eid)
{
- auto fd = pldm_open();
+ auto fd = -1;
+ if (pldmTransport)
+ {
+ lg2::error("open: pldmTransport already setup!");
+ elog<NotAllowed>(Reason(
+ "Required host dump action via pldm is not allowed due "
+ "to openPLDM failed"));
+ return fd;
+ }
+
+ fd = openMctpDemuxTransport(eid);
if (fd < 0)
{
auto e = errno;
- lg2::error("pldm_open failed, errno: {ERRNO}, FD: FD", "ERRNO", e, "FD",
+ lg2::error("openPLDM failed, errno: {ERRNO}, FD: FD", "ERRNO", e, "FD",
fd);
elog<NotAllowed>(Reason(
"Required host dump action via pldm is not allowed due "
- "to pldm_open failed"));
+ "to openPLDM failed"));
}
return fd;
}
+int openMctpDemuxTransport(mctp_eid_t eid)
+{
+ int rc = pldm_transport_mctp_demux_init(&mctpDemux);
+ if (rc)
+ {
+ lg2::error(
+ "openMctpDemuxTransport: Failed to init MCTP demux transport. rc = {RC}",
+ "RC", rc);
+ return rc;
+ }
+
+ rc = pldm_transport_mctp_demux_map_tid(mctpDemux, eid, eid);
+ if (rc)
+ {
+ lg2::error(
+ "openMctpDemuxTransport: Failed to setup tid to eid mapping. rc = {RC}",
+ "RC", rc);
+ pldmClose();
+ return rc;
+ }
+ pldmTransport = pldm_transport_mctp_demux_core(mctpDemux);
+
+ struct pollfd pollfd;
+ rc = pldm_transport_mctp_demux_init_pollfd(pldmTransport, &pollfd);
+ if (rc)
+ {
+ lg2::error("openMctpDemuxTransport: Failed to get pollfd. rc = {RC}",
+ "RC", rc);
+ pldmClose();
+ return rc;
+ }
+ return pollfd.fd;
+}
+
+void pldmClose()
+{
+ pldm_transport_mctp_demux_destroy(mctpDemux);
+ mctpDemux = nullptr;
+ pldmTransport = nullptr;
+}
+
} // 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
index 7006f5b..68f68c5 100644
--- a/host-transport-extensions/pldm/common/pldm_utils.hpp
+++ b/host-transport-extensions/pldm/common/pldm_utils.hpp
@@ -4,6 +4,7 @@
#include <libpldm/instance-id.h>
#include <libpldm/pldm.h>
+#include <libpldm/transport.h>
namespace phosphor
{
@@ -11,6 +12,7 @@
{
namespace pldm
{
+extern struct pldm_transport* pldmTransport;
class PLDMInstanceManager
{
@@ -38,13 +40,23 @@
};
/**
- * @brief Opens the PLDM file descriptor
+ * @brief setup PLDM transport for sending and receiving messages
*
+ * @param[in] eid - MCTP endpoint ID
* @return file descriptor on success and throw
* exception (xyz::openbmc_project::Common::Error::NotAllowed) on
* failures.
*/
-int openPLDM();
+int openPLDM(mctp_eid_t eid);
+
+/** @brief Opens the MCTP socket for sending and receiving messages.
+ *
+ * @param[in] eid - MCTP endpoint ID
+ */
+int openMctpDemuxTransport(mctp_eid_t eid);
+
+/** @brief Close the PLDM file */
+void pldmClose();
/**
* @brief Returns the PLDM instance ID to use for PLDM commands
diff --git a/host-transport-extensions/pldm/oem/ibm/pldm_oem_cmds.cpp b/host-transport-extensions/pldm/oem/ibm/pldm_oem_cmds.cpp
index 34d602e..b51aeaf 100644
--- a/host-transport-extensions/pldm/oem/ibm/pldm_oem_cmds.cpp
+++ b/host-transport-extensions/pldm/oem/ibm/pldm_oem_cmds.cpp
@@ -127,22 +127,33 @@
"allowed due to encode failed"));
}
- CustomFd fd(openPLDM());
+ rc = openPLDM(eid);
+ if (rc < 0)
+ {
+ freePLDMInstanceID(instanceID, eid);
+ lg2::error(" openPLDMfailure. RC: {RC}", "RC", rc);
+ elog<NotAllowed>(Reason("Host dump offload via pldm is not "
+ "allowed due to openPLDM failed"));
+ }
lg2::info("Sending request to offload dump id: {ID}, eid: {EID}", "ID", id,
"EID", eid);
- rc = pldm_send(eid, fd(), requestMsg.data(), requestMsg.size());
+ pldm_tid_t pldmTID = static_cast<pldm_tid_t>(eid);
+ rc = pldm_transport_send_msg(pldmTransport, pldmTID, requestMsg.data(),
+ requestMsg.size());
if (rc < 0)
{
freePLDMInstanceID(instanceID, eid);
+ pldmClose();
auto e = errno;
- lg2::error("pldm_send failed, RC: {RC}, errno: {ERRNO}", "RC", rc,
- "ERRNO", e);
+ lg2::error("pldm_transport_send_msg failed, RC: {RC}, errno: {ERRNO}",
+ "RC", rc, "ERRNO", e);
elog<NotAllowed>(Reason("Host dump offload via pldm is not "
"allowed due to fileack send failed"));
}
freePLDMInstanceID(instanceID, eid);
+ pldmClose();
lg2::info("Done. PLDM message, id: {ID}, RC: {RC}", "ID", id, "RC", rc);
}
@@ -188,14 +199,28 @@
"allowed due to encode fileack failed"));
}
- CustomFd pldmFd(openPLDM());
-
- retCode = pldm_send(mctpEndPointId, pldmFd(), fileAckReqMsg.data(),
- fileAckReqMsg.size());
- if (retCode != PLDM_REQUESTER_SUCCESS)
+ retCode = openPLDM(mctpEndPointId);
+ if (retCode < 0)
{
freePLDMInstanceID(pldmInstanceId, mctpEndPointId);
+ lg2::error(
+ "Failed to openPLDM to delete host dump, "
+ "SRC_DUMP_ID: {SRC_DUMP_ID}, PLDM_FILE_IO_TYPE: {PLDM_DUMP_TYPE}, "
+ "PLDM_RETURN_CODE: {RET_CODE}",
+ "SRC_DUMP_ID", dumpId, "PLDM_DUMP_TYPE", pldmDumpType, "RET_CODE",
+ retCode);
+ elog<NotAllowed>(Reason("Host dump deletion via pldm is not "
+ "allowed due to openPLDM failed"));
+ }
+
+ pldm_tid_t pldmTID = static_cast<pldm_tid_t>(mctpEndPointId);
+ retCode = pldm_transport_send_msg(
+ pldmTransport, pldmTID, fileAckReqMsg.data(), fileAckReqMsg.size());
+ if (retCode != PLDM_REQUESTER_SUCCESS)
+ {
auto errorNumber = errno;
+ freePLDMInstanceID(pldmInstanceId, mctpEndPointId);
+ pldmClose();
lg2::error(
"Failed to send pldm FileAck to delete host dump, "
"SRC_DUMP_ID: {SRC_DUMP_ID}, PLDM_FILE_IO_TYPE: {PLDM_DUMP_TYPE}, "
@@ -210,6 +235,7 @@
}
freePLDMInstanceID(pldmInstanceId, mctpEndPointId);
+ pldmClose();
lg2::info(
"Sent request to host to delete the dump, SRC_DUMP_ID: {SRC_DUMP_ID}",
"SRC_DUMP_ID", dumpId);
diff --git a/meson.build b/meson.build
index b80beec..0207520 100644
--- a/meson.build
+++ b/meson.build
@@ -119,6 +119,10 @@
description : 'Turn on rotate config for bmc dump'
)
+if cpp.has_header('poll.h')
+ add_project_arguments('-DPLDM_HAS_POLL=1', language: 'cpp')
+endif
+
configure_file(configuration : conf_data,
output : 'config.h'
)