nsmd : select mctp eid based on the binding
If an endpoint has multiple mctp eids, select the eid whose binding
offers higher bandwidth
Tested.
Both eid 10 (HMC ERoT SPI) and 15 (HMC ERoT USB) are discovered, but
only eid 15 is used.
```
root@gb200nvl-hmc:~# busctl tree xyz.openbmc_project.NSM
|- /ResetStatistics
`- /xyz
`- /xyz/openbmc_project
|- /xyz/openbmc_project/FruDevice
| |- /xyz/openbmc_project/FruDevice/12
| |- /xyz/openbmc_project/FruDevice/13
| |- /xyz/openbmc_project/FruDevice/15
| |- /xyz/openbmc_project/FruDevice/16
| |- /xyz/openbmc_project/FruDevice/18
| |- /xyz/openbmc_project/FruDevice/19
| |- /xyz/openbmc_project/FruDevice/20
| |- /xyz/openbmc_project/FruDevice/21
| |- /xyz/openbmc_project/FruDevice/24
| |- /xyz/openbmc_project/FruDevice/26
| `- /xyz/openbmc_project/FruDevice/27
|- /xyz/openbmc_project/NSM
| `- /xyz/openbmc_project/NSM/Raw
|- /xyz/openbmc_project/inventory
| `- /xyz/openbmc_project/inventory/system
| |- /xyz/openbmc_project/inventory/system/HGX_Module_0_SPI
| |- /xyz/openbmc_project/inventory/system/accelerator
| | |- /xyz/openbmc_project/inventory/system/accelerator/Diagnostics
root@gb200nvl-hmc:~# journalctl -u nsmd -b | grep -i 'found nsm'
Jul 30 09:20:19 gb200nvl-hmc nsmd[1466]: found NSM device, eid=10 uuid=f72d6fa0-5675-11ed-9b6a-0242ac120002
Jul 30 09:20:19 gb200nvl-hmc nsmd[1466]: found NSM device, eid=12 uuid=c01dc250-5678-11ed-9b6a-0242ac120002
Jul 30 09:20:19 gb200nvl-hmc nsmd[1466]: found NSM device, eid=13 uuid=f72d6f50-5675-11ed-9b6a-0242ac120002
Jul 30 09:20:19 gb200nvl-hmc nsmd[1466]: found NSM device, eid=15 uuid=f72d6fa0-5675-11ed-9b6a-0242ac120002
Jul 30 09:20:19 gb200nvl-hmc nsmd[1466]: found NSM device, eid=16 uuid=f72d6f60-5675-11ed-9b6a-0242ac120002
Jul 30 09:20:48 gb200nvl-hmc nsmd[1466]: found NSM device, eid=20 uuid=c01dc251-5678-11ed-9b6a-0242ac120002
Jul 30 09:20:48 gb200nvl-hmc nsmd[1466]: found NSM device, eid=21 uuid=f72d6f51-5675-11ed-9b6a-0242ac120002
Jul 30 09:20:48 gb200nvl-hmc nsmd[1466]: found NSM device, eid=24 uuid=f72d6f61-5675-11ed-9b6a-0242ac120002
Jul 30 09:21:00 gb200nvl-hmc nsmd[1466]: found NSM device, eid=18 uuid=f72d6fb0-5675-11ed-9b6a-0242ac120002
Jul 30 09:21:00 gb200nvl-hmc nsmd[1466]: found NSM device, eid=19 uuid=f72d6fb1-5675-11ed-9b6a-0242ac120002
Jul 30 09:21:00 gb200nvl-hmc nsmd[1466]: found NSM device, eid=26 uuid=f72d6fb2-5675-11ed-9b6a-0242ac120002
Jul 30 09:21:00 gb200nvl-hmc nsmd[1466]: found NSM device, eid=27 uuid=f72d6fb3-5675-11ed-9b6a-0242ac120002
root@gb200nvl-hmc:~# journalctl -u nsmd -b | grep 'doPollingTask: found'
Jul 30 09:20:52 gb200nvl-hmc nsmd[1466]: doPollingTask: found EID:15 by searchEID for nsmDevice(4,0,0)
Jul 30 09:20:52 gb200nvl-hmc nsmd[1466]: doPollingTask: found EID:16 by searchEID for nsmDevice(4,3,0)
Jul 30 09:20:52 gb200nvl-hmc nsmd[1466]: doPollingTask: found EID:24 by searchEID for nsmDevice(4,4,0)
Jul 30 09:20:52 gb200nvl-hmc nsmd[1466]: doPollingTask: found EID:13 by searchEID for nsmDevice(4,1,0)
Jul 30 09:20:52 gb200nvl-hmc nsmd[1466]: doPollingTask: found EID:21 by searchEID for nsmDevice(4,2,0)
Jul 30 09:20:52 gb200nvl-hmc nsmd[1466]: doPollingTask: found EID:12 by searchEID for nsmDevice(3,0,0)
Jul 30 09:20:52 gb200nvl-hmc nsmd[1466]: doPollingTask: found EID:20 by searchEID for nsmDevice(3,1,0)
Jul 30 09:21:00 gb200nvl-hmc nsmd[1466]: doPollingTask: found EID:26 by searchEID for nsmDevice(0,2,0)
Jul 30 09:21:00 gb200nvl-hmc nsmd[1466]: doPollingTask: found EID:18 by searchEID for nsmDevice(0,0,0)
Jul 30 09:21:00 gb200nvl-hmc nsmd[1466]: doPollingTask: found EID:19 by searchEID for nsmDevice(0,1,0)
Jul 30 09:21:00 gb200nvl-hmc nsmd[1466]: doPollingTask: found EID:27 by searchEID for nsmDevice(0,3,0)
```
fixes JIRA https://
Signed-off-by: Harshit Aghera <haghera@nvidia.com>
diff --git a/nsmd/deviceManager.cpp b/nsmd/deviceManager.cpp
index 773e238..02b50b8 100644
--- a/nsmd/deviceManager.cpp
+++ b/nsmd/deviceManager.cpp
@@ -108,6 +108,19 @@
// update eid table [from UUID from MCTP dbus property]
insertIntoEidTableifNotExist(
mctpUuid, std::make_tuple(eid, mctpMedium, mctpBinding));
+
+ auto nsmDevice = findNsmDeviceByUUID(nsmDevices, mctpUuid);
+ if (nsmDevice)
+ {
+ // if nsmDevice already exists, update its EID based on the MCTP
+ // Binding
+
+ lg2::info(
+ "Found additional EID for existing NSM device. UUID={UUID} EID={EID}",
+ "UUID", mctpUuid, "EID", eid);
+
+ co_await nsmDevice->setOffline();
+ }
}
queuedMctpInfos.pop();
}
@@ -873,6 +886,49 @@
return instanceNumber;
}
+/**
+ * @brief MCTP Medium Type priority table ordering by bandwidth
+ */
+static std::unordered_map<MctpMedium, int> mediumPriority = {
+ {"xyz.openbmc_project.MCTP.Endpoint.MediaTypes.PCIe", 0},
+ {"xyz.openbmc_project.MCTP.Endpoint.MediaTypes.USB", 1},
+ {"xyz.openbmc_project.MCTP.Endpoint.MediaTypes.SPI", 2},
+ {"xyz.openbmc_project.MCTP.Endpoint.MediaTypes.I3C", 3},
+ {"xyz.openbmc_project.MCTP.Endpoint.MediaTypes.KCS", 4},
+ {"xyz.openbmc_project.MCTP.Endpoint.MediaTypes.Serial", 5},
+ {"xyz.openbmc_project.MCTP.Endpoint.MediaTypes.SMBus", 6}};
+
+/**
+ * @brief MCTP Binding Type priority table ordering by bandwidth
+ */
+static std::unordered_map<MctpBinding, int> bindingPriority = {
+ {"xyz.openbmc_project.MCTP.Binding.BindingTypes.PCIe", 0},
+ {"xyz.openbmc_project.MCTP.Binding.BindingTypes.USB", 1},
+ {"xyz.openbmc_project.MCTP.Binding.BindingTypes.SPI", 2},
+ {"xyz.openbmc_project.MCTP.Binding.BindingTypes.KCS", 3},
+ {"xyz.openbmc_project.MCTP.Binding.BindingTypes.Serial", 4},
+ {"xyz.openbmc_project.MCTP.Binding.BindingTypes.SMBus", 5}};
+
+static bool isPreferred(
+ const std::tuple<eid_t, MctpMedium, MctpBinding>& currentMctpInfo,
+ const std::tuple<eid_t, MctpMedium, MctpBinding>& newMctpInfo)
+{
+ auto currentMedium = std::get<1>(currentMctpInfo);
+ auto newMedium = std::get<1>(newMctpInfo);
+ auto currentBinding = std::get<2>(currentMctpInfo);
+ auto newBinding = std::get<2>(newMctpInfo);
+
+ if (mediumPriority.at(currentMedium) == mediumPriority.at(newMedium))
+ {
+ return bindingPriority.at(currentBinding) >
+ bindingPriority.at(newBinding);
+ }
+ else
+ {
+ return mediumPriority.at(currentMedium) > mediumPriority.at(newMedium);
+ }
+}
+
std::optional<mctp_eid_t>
DeviceManager::searchEID(uint8_t nsmDeviceType,
uint8_t nsmDeviceIntanceNumber,
@@ -900,6 +956,48 @@
if (matchedCnt == 1 && matchedActive == true)
{
+ // Search for all eids for matched UUID and select one based on MCTP
+ // binding priority order
+
+ std::tuple<eid_t, MctpMedium, MctpBinding> currentBindings;
+
+ auto uuidRange = eidTable.equal_range(matchedUuid);
+
+ for (auto it = uuidRange.first; it != uuidRange.second; ++it)
+ {
+ const auto& bindings = it->second;
+ const auto& [eid, medium, binding] = bindings;
+ if (eid == matchedEid)
+ {
+ currentBindings = bindings;
+ break;
+ }
+ }
+
+ for (auto it = uuidRange.first; it != uuidRange.second; ++it)
+ {
+ const auto& newBindings = it->second;
+ const auto& [eid, medium, binding] = newBindings;
+
+ if (eid != matchedEid)
+ {
+ if (isPreferred(currentBindings, newBindings))
+ {
+ auto discoveredEID = discoveredEIDs.find(eid);
+ if (discoveredEID != discoveredEIDs.end())
+ {
+ auto& [uuid, mctpDeviceType, mctpDeviceInstanceNumber,
+ active] = discoveredEID->second;
+ if (uuid == matchedUuid && active == true)
+ {
+ matchedEid = eid;
+ currentBindings = newBindings;
+ }
+ }
+ }
+ }
+ }
+
return matchedEid;
}
return std::nullopt;