Skip to content

Commit

Permalink
Revert "openpower-pels: Move to libpldm pldm_transport APIs" (#70)
Browse files Browse the repository at this point in the history
This reverts commit 0387a74.
  • Loading branch information
rfrandse committed Oct 7, 2024
1 parent 19d0fe0 commit 149208c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 110 deletions.
6 changes: 0 additions & 6 deletions config/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ conf_data = configuration_data()
conf_data.set('error_cap', get_option('error_cap'))
conf_data.set('error_info_cap', get_option('error_info_cap'))
conf_data.set('rsyslog_server_conf', get_option('rsyslog_server_conf'))

cxx = meson.get_compiler('cpp')
if cxx.has_header('poll.h')
add_project_arguments('-DPLDM_HAS_POLL=1', language: 'cpp')
endif

conf_h_dep = declare_dependency(
include_directories: include_directories('.'),
sources: configure_file(
Expand Down
6 changes: 2 additions & 4 deletions extensions/openpower-pels/host_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "data_interface.hpp"

#include <libpldm/transport.h>
#include <stdint.h>

#include <phosphor-logging/lg2.hpp>
Expand Down Expand Up @@ -196,10 +195,9 @@ class HostInterface
* invoked from.
* @param[in] fd - The file descriptor being used
* @param[in] revents - The event status bits
* @param[in] transport - The transport data pointer
*/
virtual void receive(sdeventplus::source::IO& io, int fd, uint32_t revents,
pldm_transport* transport) = 0;
virtual void receive(sdeventplus::source::IO& io, int fd,
uint32_t revents) = 0;

/**
* @brief An optional function to call on a successful command response.
Expand Down
106 changes: 28 additions & 78 deletions extensions/openpower-pels/pldm_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

#include <libpldm/base.h>
#include <libpldm/oem/ibm/file_io.h>
#include <libpldm/transport.h>
#include <libpldm/transport/mctp-demux.h>
#include <poll.h>
#include <unistd.h>

#include <phosphor-logging/lg2.hpp>
Expand All @@ -31,11 +28,9 @@ namespace openpower::pels

using namespace sdeventplus;
using namespace sdeventplus::source;
using TerminusID = uint8_t;

constexpr auto eidPath = "/usr/share/pldm/host_eid";
constexpr mctp_eid_t defaultEIDValue = 9;
constexpr TerminusID tid = defaultEIDValue;

constexpr uint16_t pelFileType = 0;

Expand All @@ -48,10 +43,11 @@ PLDMInterface::~PLDMInterface()

void PLDMInterface::closeFD()
{
pldm_transport_mctp_demux_destroy(mctpDemux);
mctpDemux = nullptr;
_fd = -1;
pldmTransport = nullptr;
if (_fd >= 0)
{
close(_fd);
_fd = -1;
}
}

void PLDMInterface::readEID()
Expand Down Expand Up @@ -80,54 +76,14 @@ void PLDMInterface::readEID()

void PLDMInterface::open()
{
if (pldmTransport)
{
lg2::error("open: pldmTransport already setup!");
throw std::runtime_error{"open failed"};
}

_fd = openMctpDemuxTransport();
_fd = pldm_open();
if (_fd < 0)
{
auto e = errno;
lg2::error("Transport open failed. errno = {ERRNO}, rc = {RC}", "ERRNO",
e, "RC", _fd);
throw std::runtime_error{"Transport open failed"};
}
}

int PLDMInterface::openMctpDemuxTransport()
{
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, tid, tid);
if (rc)
{
lg2::error(
"openMctpDemuxTransport: Failed to setup tid to eid mapping. rc = {RC}",
"RC", rc);
cleanupCmd();
return rc;
lg2::error("pldm_open failed. errno = {ERRNO}, rc = {RC}", "ERRNO", e,
"RC", _fd);
throw std::runtime_error{"pldm_open failed"};
}
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);
cleanupCmd();
return rc;
}
return pollfd.fd;
}

void PLDMInterface::startCommand()
Expand Down Expand Up @@ -229,7 +185,7 @@ void PLDMInterface::registerReceiveCallback()
_event, _fd, EPOLLIN,
std::bind(std::mem_fn(&PLDMInterface::receive), this,
std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3, pldmTransport));
std::placeholders::_3));
}

void PLDMInterface::doSend()
Expand All @@ -247,51 +203,45 @@ void PLDMInterface::doSend()
lg2::error("encode_new_file_req failed, rc = {RC}", "RC", rc);
throw std::runtime_error{"encode_new_file_req failed"};
}
pldm_tid_t pldmTID = static_cast<pldm_tid_t>(_eid);
rc = pldm_transport_send_msg(pldmTransport, pldmTID, requestMsg.data(),
requestMsg.size());

rc = pldm_send(_eid, _fd, requestMsg.data(), requestMsg.size());
if (rc < 0)
{
auto e = errno;
lg2::error("pldm_transport_send_msg failed, rc = {RC}, errno = {ERRNO}",
"RC", rc, "ERRNO", e);
throw std::runtime_error{"pldm_transport_send_msg failed"};
lg2::error("pldm_send failed, rc = {RC}, errno = {ERRNO}", "RC", rc,
"ERRNO", e);
throw std::runtime_error{"pldm_send failed"};
}
}

void PLDMInterface::receive(IO& /*io*/, int /*fd*/, uint32_t revents,
pldm_transport* transport)

void PLDMInterface::receive(IO& /*io*/, int fd, uint32_t revents)
{
if (!(revents & EPOLLIN))
{
return;
}

void* responseMsg = nullptr;
uint8_t* responseMsg = nullptr;
size_t responseSize = 0;
ResponseStatus status = ResponseStatus::success;

pldm_tid_t pldmTID;
auto rc = pldm_transport_recv_msg(transport, &pldmTID, &responseMsg,
&responseSize);
if (pldmTID != _eid)
{
// We got a response to someone else's message. Ignore it.
return;
}
if (rc)
auto rc = pldm_recv(_eid, fd, *_instanceID, &responseMsg, &responseSize);
if (rc < 0)
{
if (rc == PLDM_REQUESTER_NOT_RESP_MSG)
if (rc == PLDM_REQUESTER_INSTANCE_ID_MISMATCH)
{
// We got a response to someone else's message. Ignore it.
return;
}
else if (rc == PLDM_REQUESTER_NOT_RESP_MSG)
{
// Due to the MCTP loopback, we may get notified of the message
// we just sent.
return;
}

auto e = errno;
lg2::error("pldm_transport_recv_msg failed, rc = {RC}, errno = {ERRNO}",
"RC",
lg2::error("pldm_recv failed, rc = {RC}, errno = {ERRNO}", "RC",
static_cast<std::underlying_type_t<pldm_requester_rc_t>>(rc),
"ERRNO", e);
status = ResponseStatus::failure;
Expand All @@ -309,8 +259,8 @@ void PLDMInterface::receive(IO& /*io*/, int /*fd*/, uint32_t revents,
uint8_t completionCode = 0;
auto response = reinterpret_cast<pldm_msg*>(responseMsg);

auto decodeRC =
decode_new_file_resp(response, responseSize, &completionCode);
auto decodeRC = decode_new_file_resp(response, PLDM_NEW_FILE_RESP_BYTES,
&completionCode);
if (decodeRC < 0)
{
lg2::error("decode_new_file_resp failed, rc = {RC}", "RC",
Expand Down
19 changes: 2 additions & 17 deletions extensions/openpower-pels/pldm_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include <libpldm/instance-id.h>
#include <libpldm/pldm.h>
#include <libpldm/transport.h>
#include <libpldm/transport/mctp-demux.h>

#include <sdeventplus/clock.hpp>
#include <sdeventplus/source/io.hpp>
Expand Down Expand Up @@ -95,10 +93,9 @@ class PLDMInterface : public HostInterface
* @param[in] io - The event source object
* @param[in] fd - The FD used
* @param[in] revents - The event bits
* @param[in] transport - The transport data pointer
*/
void receive(sdeventplus::source::IO& io, int fd, uint32_t revents,
pldm_transport* transport) override;
void receive(sdeventplus::source::IO& io, int fd,
uint32_t revents) override;

/**
* @brief Function called when the receive timer expires.
Expand Down Expand Up @@ -126,11 +123,6 @@ class PLDMInterface : public HostInterface
*/
void open();

/** @brief Opens the MCTP socket for sending and receiving messages.
*
*/
int openMctpDemuxTransport();

/**
* @brief Encodes and sends the PLDM 'new file available' cmd
*/
Expand Down Expand Up @@ -208,13 +200,6 @@ class PLDMInterface : public HostInterface
* @brief The size of the PEL to notify the host of.
*/
uint32_t _pelSize = 0;

/**
* @brief pldm transport instance.
*/
pldm_transport* pldmTransport = nullptr;

pldm_transport_mctp_demux* mctpDemux = nullptr;
};

} // namespace openpower::pels
10 changes: 5 additions & 5 deletions test/openpower-pels/mocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ class MockHostInterface : public HostInterface
int fd = open(_fifo.c_str(), O_NONBLOCK | O_RDWR);
EXPECT_TRUE(fd >= 0) << "Unable to open FIFO";

auto callback =
[this](sdeventplus::source::IO& source, int fd, uint32_t events) {
this->receive(source, fd, events, nullptr);
};
auto callback = [this](sdeventplus::source::IO& source, int fd,
uint32_t events) {
this->receive(source, fd, events);
};

try
{
Expand Down Expand Up @@ -248,7 +248,7 @@ class MockHostInterface : public HostInterface
* @param[in] events - The event bits
*/
void receive(sdeventplus::source::IO& /*source*/, int /*fd*/,
uint32_t events, pldm_transport* /*transport*/) override
uint32_t events) override
{
if (!(events & EPOLLIN))
{
Expand Down

0 comments on commit 149208c

Please sign in to comment.