pldm: Convert to using libpldm transport APIs
A significant amount of logic can be removed by exploiting the new
transport APIs provided by libpldm. Switch the pldm repository over to
use these by introducing an RAII wrapper for the APIs. The current
stance is to continue using the legacy mctp-demux transport
implementation, but we also provide a build option to switch to the
AF_MCTP transport.
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.
Change-Id: I366f079082b102cfc0e90db0f62208581eb8693e
Signed-off-by: Rashmica Gupta <rashmica@linux.ibm.com>
Signed-off-by: Delphine CC Chiu <Delphine_CC_Chiu@wiwynn.com>
Signed-off-by: Thu Nguyen <thu@os.amperecomputing.com>
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Signed-off-by: Konstantin Aladyshev <aladyshev22@gmail.com>
diff --git a/softoff/softoff.cpp b/softoff/softoff.cpp
index f80e048..3135b3d 100644
--- a/softoff/softoff.cpp
+++ b/softoff/softoff.cpp
@@ -1,11 +1,11 @@
#include "softoff.hpp"
#include "common/instance_id.hpp"
+#include "common/transport.hpp"
#include "common/utils.hpp"
#include <libpldm/entity.h>
#include <libpldm/platform.h>
-#include <libpldm/pldm.h>
#include <libpldm/state_set.h>
#include <phosphor-logging/lg2.hpp>
@@ -291,8 +291,9 @@
int SoftPowerOff::hostSoftOff(sdeventplus::Event& event)
{
constexpr uint8_t effecterCount = 1;
- uint8_t mctpEID;
+ PldmTransport pldmTransport{};
uint8_t instanceID;
+ uint8_t mctpEID;
mctpEID = pldm::utils::readHostEID();
// TODO: fix mapping to work around OpenBMC ecosystem deficiencies
@@ -317,14 +318,6 @@
return PLDM_ERROR;
}
- // Open connection to MCTP socket
- int fd = pldm_open();
- if (-1 == fd)
- {
- error("Failed to connect to mctp demux daemon");
- return PLDM_ERROR;
- }
-
// Add a timer to the event loop, default 30s.
auto timerCallback =
[=, this](Timer& /*source*/, Timer::TimePoint /*time*/) mutable {
@@ -341,18 +334,23 @@
std::chrono::seconds{1}, std::move(timerCallback));
// Add a callback to handle EPOLLIN on fd
- auto callback = [=, this](IO& io, int fd, uint32_t revents) mutable {
+ auto callback =
+ [=, &pldmTransport, this](IO& io, int fd, uint32_t revents) mutable {
+ if (fd != pldmTransport.getEventSource())
+ {
+ return;
+ }
+
if (!(revents & EPOLLIN))
{
return;
}
- uint8_t* responseMsg = nullptr;
+ void* responseMsg = nullptr;
size_t responseMsgSize{};
pldm_tid_t srcTID = pldmTID;
- auto rc = pldm_recv(mctpEID, fd, request->hdr.instance_id, &responseMsg,
- &responseMsgSize);
+ auto rc = pldmTransport.recvMsg(pldmTID, responseMsg, responseMsgSize);
if (rc)
{
error("Soft off: failed to recv pldm data. PLDM RC = {RC}", "RC",
@@ -360,8 +358,8 @@
return;
}
- std::unique_ptr<uint8_t, decltype(std::free)*> responseMsgPtr{
- responseMsg, std::free};
+ std::unique_ptr<void, decltype(std::free)*> responseMsgPtr{responseMsg,
+ std::free};
// We've got the response meant for the PLDM request msg that was
// sent out
@@ -409,10 +407,10 @@
}
return;
};
- IO io(event, fd, EPOLLIN, std::move(callback));
+ IO io(event, pldmTransport.getEventSource(), EPOLLIN, std::move(callback));
- // Send PLDM Request message - pldm_send doesn't wait for response
- rc = pldm_send(mctpEID, fd, requestMsg.data(), requestMsg.size());
+ // Asynchronously send the PLDM request
+ rc = pldmTransport.sendMsg(pldmTID, requestMsg.data(), requestMsg.size());
if (0 > rc)
{
instanceIdDb.free(pldmTID, instanceID);