Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions common/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,25 @@ using MctpMedium = std::string;
* uint32_t is used as defined in MCTP Endpoint D-Bus Interface
*/
using NetworkId = uint32_t;
using NetworkInterface = std::string;
using LocalEid = uint8_t;

/** @brief Type definition of MCTP name in string
*/
using MctpInfoName = std::optional<std::string>;

/** @brief Type definition of MCTP interface information between two endpoints.
* eid : Endpoint EID in byte. Defined to match with MCTP D-Bus
* interface
* UUID : Endpoint UUID which is used to different the endpoints
* MctpMedium: Endpoint MCTP Medium info (Resersed)
* NetworkId: MCTP network index
* name: Alias name of the endpoint, e.g. BMC, NIC, etc.
*
* eid : Endpoint EID (byte). Matches MCTP D-Bus endpoint EID.
* UUID : Endpoint UUID used to uniquely identify endpoints.
* MctpMedium : Endpoint MCTP medium information (reserved/transport-specific).
* NetworkId : MCTP network index identifying the MCTP network.
* MctpInfoName : Alias name of the endpoint (e.g. BMC, NIC, etc.).
* NetworkInterface : Underlying transport interface used for MCTP communication
* (e.g. mctpi3c4, mctppcie0).
* LocalEid : Host-assigned identifier associated with the interface.
*/
using MctpInfo = std::tuple<eid, UUID, MctpMedium, NetworkId, MctpInfoName>;
using MctpInfo = std::tuple<eid, UUID, MctpMedium, NetworkId, MctpInfoName, NetworkInterface, LocalEid>;

/** @brief Type definition of MCTP endpoint D-Bus properties in
* xyz.openbmc_project.MCTP.Endpoint D-Bus interface.
Expand All @@ -54,7 +59,7 @@ using MctpInfo = std::tuple<eid, UUID, MctpMedium, NetworkId, MctpInfoName>;
* interface
* MCTPMsgTypes: MCTP message types
*/
using MctpEndpointProps = std::tuple<NetworkId, eid, MCTPMsgTypes>;
using MctpEndpointProps = std::tuple<NetworkId, eid, MCTPMsgTypes, NetworkInterface>;

/** @brief Type defined for list of MCTP interface information
*/
Expand Down
10 changes: 8 additions & 2 deletions configurations/pdr/com.amd.Hardware.Chassis/pdr_config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{
"uuids": {
"28318908-bc42-4463-a8f8-f0cc7b43c5e6": 0,
"8bc76e13-94c1-4e52-992b-d4d845e3572a": 1
"28318908-bc42-4463-a8f8-f0cc7b43c5e6": {
"mctpi3c4": 0,
"mctpi3c5": 1
},
"8bc76e13-94c1-4e52-992b-d4d845e3572a": {
"mctpi3c4": 0,
"mctpi3c5": 1
}
},

"excludeNumericEffecterPDRs": [
Expand Down
2 changes: 1 addition & 1 deletion fw-update/manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Manager : public pldm::MctpDiscoveryHandlerIntf
std::vector<mctp_eid_t> eids;
for (const auto& mctpInfo : mctpInfos)
{
eids.emplace_back(std::get<mctp_eid_t>(mctpInfo));
eids.emplace_back(std::get<0>(mctpInfo));
}

inventoryMgr.discoverFDs(eids);
Expand Down
26 changes: 18 additions & 8 deletions oem/amd/platform-mc/platform_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ std::optional<std::vector<uint8_t>> decode_compact_numeric_sensor_pdr(

/* Setting default values when getPDRRepositoryInfo fails or does not support */
exec::task<int> PlatformManager::get_pdr_from_json(
std::shared_ptr<Terminus> terminus, std::string targetUuid)
std::shared_ptr<Terminus> terminus, std::string targetUuid,
std::string networkInterface)
{
pldm_tid_t tid = terminus->getTid();

Expand All @@ -345,15 +346,24 @@ exec::task<int> PlatformManager::get_pdr_from_json(
throw std::runtime_error("Could not open UUID mapping file");
}

// 2. Parse directly into a map
using InterfaceMap = std::unordered_map<std::string, int>;
using UuidMap = std::unordered_map<std::string, InterfaceMap>;

// Parse JSON
auto j = nlohmann::json::parse(uuidFile);
auto uuid_map = j["uuids"].get<std::unordered_map<std::string, int>>();
auto uuidMap = j["uuids"].get<UuidMap>();

// Find UUID
auto uuidIt = uuidMap.find(targetUuid);
if (uuidIt == uuidMap.end())
{
co_return PLDM_ERROR_INVALID_DATA;
}

// Early exit if the UUID is not in the map
auto it = uuid_map.find(targetUuid);
if (it == uuid_map.end())
// Find interface
auto ifaceIt = uuidIt->second.find(networkInterface);
if (ifaceIt == uuidIt->second.end())
{
// UUID not found in the mapping
co_return PLDM_ERROR_INVALID_DATA;
}

Expand All @@ -378,7 +388,7 @@ exec::task<int> PlatformManager::get_pdr_from_json(
}
#endif

int processorIndex = it->second;
int processorIndex = ifaceIt->second;
std::string procName = "Processor" + std::to_string(processorIndex);
std::string procPdrDir = pdrDir + "/" + procName;
lg2::info("Loading PDRs for TID {TID} from {PATH}", "TID", tid, "PATH", procPdrDir);
Expand Down
20 changes: 17 additions & 3 deletions platform-mc/platform_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ exec::task<int> PlatformManager::initTerminus()
auto mctpInfo = terminusManager.getMctpInfoForTid(tid);
if (mctpInfo.has_value()) {
std::string uuid = std::get<1>(*mctpInfo);
auto rc = co_await get_pdr_from_json(terminus, uuid);
std::string networkInterface = std::get<2>(*mctpInfo);
auto rc = co_await get_pdr_from_json(terminus, uuid, networkInterface);
if (rc)
{
lg2::error(
Expand Down Expand Up @@ -140,7 +141,7 @@ exec::task<int> PlatformManager::initTerminus()
if (info)
{
pldm::utils::emitRDEDeviceDetectedSignal(
tid, info->first, info->second, redfishResources);
tid, std::get<0>(*info), std::get<1>(*info), redfishResources);
}
else
{
Expand Down Expand Up @@ -541,6 +542,7 @@ exec::task<int> PlatformManager::setEventReceiver(
pldm_tid_t tid, pldm_event_message_global_enable eventMessageGlobalEnable,
pldm_transport_protocol_type protocolType, uint16_t heartbeatTimer)
{
uint8_t localEid = 0;
size_t requestBytes = PLDM_SET_EVENT_RECEIVER_REQ_BYTES;
/**
* Ignore heartbeatTimer bytes when eventMessageGlobalEnable is not
Expand All @@ -553,9 +555,21 @@ exec::task<int> PlatformManager::setEventReceiver(
}
Request request(sizeof(pldm_msg_hdr) + requestBytes);
auto requestMsg = new (request.data()) pldm_msg;

auto info = terminusManager.getMctpInfoForTid(tid);
if (info)
{
localEid = std::get<3>(*info);
}
else
{
lg2::error("Failed to find Mctp Info for terminus with TID: {TID}", "TID", tid);
}
lg2::info("Set event receiver: LocalEid {LID} for tid: {TID}", "LID", localEid, "TID", tid);

auto rc = encode_set_event_receiver_req(
0, eventMessageGlobalEnable, protocolType,
terminusManager.getLocalEid(), heartbeatTimer, requestMsg);
localEid, heartbeatTimer, requestMsg);
if (rc)
{
lg2::error(
Expand Down
4 changes: 3 additions & 1 deletion platform-mc/platform_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ class PlatformManager
exec::task<int> getPDRs(std::shared_ptr<Terminus> terminus);

#ifdef OEM_AMD
exec::task<int> get_pdr_from_json(std::shared_ptr<Terminus> terminus, std::string targetUuid);
exec::task<int> get_pdr_from_json(
std::shared_ptr<Terminus> terminus, std::string targetUuid,
std::string networkInterface);
#endif

/** @brief Fetch PDR from terminus
Expand Down
37 changes: 9 additions & 28 deletions platform-mc/terminus_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,8 +780,8 @@ std::optional<mctp_eid_t> TerminusManager::getActiveEidByName(
return std::nullopt;
}

std::optional<std::pair<eid, UUID>> TerminusManager::getMctpInfoForTid(
pldm_tid_t tid)
std::optional<std::tuple<eid, UUID, NetworkInterface, LocalEid>>
TerminusManager::getMctpInfoForTid(pldm_tid_t tid)
{
auto it = mctpInfoTable.find(tid);
if (it == mctpInfoTable.end())
Expand All @@ -790,33 +790,14 @@ std::optional<std::pair<eid, UUID>> TerminusManager::getMctpInfoForTid(
}

const auto& mctpInfo = it->second;
return std::make_pair(std::get<0>(mctpInfo), std::get<1>(mctpInfo));
}

std::optional<uint8_t> TerminusManager::getBmcMctpEid()
{
const std::string fileName = "/var/run/bmceid0";

try
{
std::ifstream toDevice;

toDevice.exceptions(std::ios::failbit | std::ios::badbit);
toDevice.open(fileName);

uint8_t bmcMctpEid = 0;
toDevice.read(reinterpret_cast<char*>(&bmcMctpEid), sizeof(bmcMctpEid));

return bmcMctpEid;
}

catch (const std::ios_base::failure& iose)
{
std::cerr << "In file I/O error: " << iose.what() << fileName
<< std::endl;
}

return std::nullopt;
return std::make_tuple(
std::get<0>(mctpInfo), // eid
std::get<1>(mctpInfo), // uuid
std::get<5>(mctpInfo), // interface
std::get<6>(mctpInfo) // hostid
);
}

} // namespace platform_mc
} // namespace pldm
26 changes: 7 additions & 19 deletions platform-mc/terminus_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,6 @@ class TerminusManager
*/
bool unmapTid(const pldm_tid_t& tid);

/** @brief getter of local EID
*
* @return uint8_t - local EID
*/
mctp_eid_t getLocalEid()
{
auto hostEid = getBmcMctpEid();

if (hostEid.has_value())
return *hostEid;

return localEid;
}

/** @brief Helper function to invoke registered handlers for
* updating the availability status of the MCTP endpoint
*
Expand Down Expand Up @@ -196,18 +182,20 @@ class TerminusManager
* @return std::optional<std::pair<eid, UUID>> Returns a pair of EID and
* UUID if the TID is found, or std::nullopt if not found.
*/
std::optional<std::pair<eid, UUID>> getMctpInfoForTid(pldm_tid_t tid);
std::optional<std::tuple<eid, UUID, NetworkInterface, LocalEid>> getMctpInfoForTid(
pldm_tid_t tid);

/**
* @brief Get the BMC Host EID stored in a file
*
* This function looks up the a file and if the file exists and
* This function looks up a file and, if the file exists and
* can be read, reads the MCTP EID stored in that file.
*
* @return std::optional<std::<uint8_t> Returns a BMC MCTP EID
* stored in the file and in case of any errors, return NULL value.
* @param[in] hostNumber The identifier of the specific host.
* @return std::optional<uint8_t> Returns the BMC MCTP EID stored
* in the file, or std::nullopt in case of any errors.
*/
std::optional<uint8_t> getBmcMctpEid();
std::optional<uint8_t> getBmcMctpEid(const int hostNumber);

private:
/** @brief Find the terminus object pointer in termini list.
Expand Down
Loading