gpu : add support for communication to the endpoint
The commit uses MCTP VDM protocol to read temperature sensor value from
the gpu.
The MCTP VDM protocol is an extension of the OCP Accelerator Management
Interface specification -
'''
https://www.opencompute.org/documents/ocp-gpu-accelerator-management-interfaces-v1-pdf
'''
Tested.
Build an image for gb200nvl-obmc machine with the following patches
cherry picked. This patches are needed to enable the mctp stack.
https://gerrit.openbmc.org/c/openbmc/openbmc/+/79312
https://gerrit.openbmc.org/c/openbmc/openbmc/+/79410
https://gerrit.openbmc.org/c/openbmc/openbmc/+/79422
Copy the configuration file on gb200nvl-obmc machine and restart the
entity-manager service.
```
root@gb200nvl-obmc:~# rm -rf /var/configuration/
root@gb200nvl-obmc:~# systemctl restart xyz.openbmc_project.EntityManager.service
```
Copy the gpusensor app and run it.
```
root@gb200nvl-obmc:~# ./gpusensor
```
The app is detecting entity-manager configuration on gb200nvl-obmc
machine. The app is also able to detect all the endpoints from the mctp
service dbus tree. The app is reading temperature sensor value from gpu
correctly and the temperature sensor is also present on redfish.
```
$ curl -k -u 'root:0penBmc' https://10.137.203.137/redfish/v1/Chassis/NVIDIA_GB200_1/Sensors/temperature_NVIDIA_GB200_GPU
{
"@odata.id": "/redfish/v1/Chassis/NVIDIA_GB200_1/Sensors/temperature_NVIDIA_GB200_GPU",
"@odata.type": "#Sensor.v1_2_0.Sensor",
"Id": "temperature_NVIDIA_GB200_GPU",
"Name": "NVIDIA GB200 GPU",
"Reading": 36.4375,
"ReadingRangeMax": 127.0,
"ReadingRangeMin": -128.0,
"ReadingType": "Temperature",
"ReadingUnits": "Cel",
"Status": {
"Health": "OK",
"State": "Enabled"
}
}%
root@gb200nvl-obmc:~# busctl tree xyz.openbmc_project.GpuSensor
└─ /xyz
└─ /xyz/openbmc_project
└─ /xyz/openbmc_project/sensors
└─ /xyz/openbmc_project/sensors/temperature
└─ /xyz/openbmc_project/sensors/temperature/NVIDIA_GB200_GPU
root@gb200nvl-obmc:~# busctl introspect xyz.openbmc_project.GpuSensor /xyz/openbmc_project/sensors/temperature/NVIDIA_GB200_GPU
NAME TYPE SIGNATURE RESULT/VALUE FLAGS
org.freedesktop.DBus.Introspectable interface - - -
.Introspect method - s -
org.freedesktop.DBus.Peer interface - - -
.GetMachineId method - s -
.Ping method - - -
org.freedesktop.DBus.Properties interface - - -
.Get method ss v -
.GetAll method s a{sv} -
.Set method ssv - -
.PropertiesChanged signal sa{sv}as - -
xyz.openbmc_project.Association.Definitions interface - - -
.Associations property a(sss) 1 "chassis" "all_sensors" "/xyz/openbmc… emits-change
xyz.openbmc_project.Sensor.Value interface - - -
.MaxValue property d 127 emits-change
.MinValue property d -128 emits-change
.Unit property s "xyz.openbmc_project.Sensor.Value.Unit.… emits-change
.Value property d 36.3125 emits-change writable
xyz.openbmc_project.Sensor.ValueMutability interface - - -
.Mutable property b true emits-change
xyz.openbmc_project.State.Decorator.Availability interface - - -
.Available property b true emits-change writable
xyz.openbmc_project.State.Decorator.OperationalStatus interface - - -
.Functional property b true emits-change
```
Change-Id: Ied938b9e5c19751ee283b4b948e16c905c78fb48
Signed-off-by: Harshit Aghera <haghera@nvidia.com>
diff --git a/src/gpu/MctpRequester.hpp b/src/gpu/MctpRequester.hpp
new file mode 100644
index 0000000..63a5ba6
--- /dev/null
+++ b/src/gpu/MctpRequester.hpp
@@ -0,0 +1,94 @@
+/*
+ * SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION &
+ * AFFILIATES. All rights reserved. SPDX-License-Identifier: Apache-2.0
+ */
+
+#pragma once
+
+#include <boost/asio/io_context.hpp>
+#include <boost/asio/local/datagram_protocol.hpp>
+
+#include <cstddef>
+#include <cstdint>
+#include <functional>
+#include <vector>
+
+// Define MCTP EID type
+using mctp_eid_t = uint8_t;
+
+namespace mctp
+{
+/**
+ * @brief MCTP requester class
+ *
+ * This class provides a simple interface for sending and receiving MCTP
+ * messages.
+ */
+class MctpRequester
+{
+ public:
+ MctpRequester() = delete;
+
+ MctpRequester(const MctpRequester&) = delete;
+
+ MctpRequester(MctpRequester&&) = delete;
+
+ MctpRequester& operator=(const MctpRequester&) = delete;
+
+ MctpRequester& operator=(MctpRequester&&) = delete;
+
+ /**
+ * @brief Constructor
+ * @param ctx - The IO context to use
+ * @param msgType - The message type to use
+ */
+ MctpRequester(boost::asio::io_context& ctx, uint8_t msgType);
+
+ /**
+ * @brief Send an MCTP request message and receive the response
+ *
+ * This function sends a request message to the specified endpoint ID and
+ * asynchronously waits for a response. It uses the MCTP socket to handle
+ * the communication. Results are provided via the callback.
+ *
+ * @param[in] eid - The endpoint ID to send the message to
+ * @param[in] reqMsg - The request message to send
+ * @param[in] callback - Callback function to be invoked when response is
+ * received The callback takes two parameters:
+ * - An integer status code (0 for success, negative for error)
+ * - A vector containing the response message bytes
+ */
+ void sendRecvMsg(
+ mctp_eid_t eid, const std::vector<uint8_t>& reqMsg,
+ const std::function<void(int, std::vector<uint8_t>)>& callback);
+
+ private:
+ /**
+ * @brief Process received message
+ *
+ * This function processes a received message and invokes the callback with
+ * the appropriate status code and response message bytes.
+ *
+ * @param[in] eid - The endpoint ID from which the message was received
+ * @param[in] reqMsg - The received request message bytes
+ * @param[in] callback - The callback function to invoke with the result
+ * @param[in] peekedLength - The length of the peeked data
+ */
+ void processRecvMsg(
+ mctp_eid_t eid, const std::vector<uint8_t>& reqMsg,
+ const std::function<void(int, std::vector<uint8_t>)>& callback,
+ size_t peekedLength) const;
+
+ /** @brief IO context to use */
+ boost::asio::io_context& ctx;
+
+ /** @brief Socket file descriptor */
+ int sockfd = -1;
+
+ /** @brief Local socket */
+ boost::asio::local::datagram_protocol::socket mctpSocket;
+
+ /** @brief MCTP message type */
+ uint8_t msgType;
+};
+} // namespace mctp