Harshit Aghera | d837b56 | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 1 | /* |
| 2 | * SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & |
Harshit Aghera | 560e6af | 2025-04-21 20:04:56 +0530 | [diff] [blame^] | 3 | * AFFILIATES. All rights reserved. |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
Harshit Aghera | d837b56 | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #pragma once |
| 8 | |
Harshit Aghera | 560e6af | 2025-04-21 20:04:56 +0530 | [diff] [blame^] | 9 | #include "MctpRequester.hpp" |
Harshit Aghera | d837b56 | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 10 | #include "Thresholds.hpp" |
| 11 | #include "Utils.hpp" |
| 12 | #include "sensor.hpp" |
| 13 | |
Harshit Aghera | 560e6af | 2025-04-21 20:04:56 +0530 | [diff] [blame^] | 14 | #include <NvidiaGpuMctpVdm.hpp> |
| 15 | #include <OcpMctpVdm.hpp> |
Harshit Aghera | d837b56 | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 16 | #include <boost/asio/io_context.hpp> |
| 17 | #include <boost/asio/steady_timer.hpp> |
| 18 | #include <boost/container/flat_map.hpp> |
| 19 | #include <sdbusplus/asio/connection.hpp> |
| 20 | #include <sdbusplus/asio/object_server.hpp> |
| 21 | #include <sdbusplus/message.hpp> |
| 22 | |
Harshit Aghera | 560e6af | 2025-04-21 20:04:56 +0530 | [diff] [blame^] | 23 | #include <array> |
| 24 | #include <chrono> |
| 25 | #include <cstdint> |
Harshit Aghera | d837b56 | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 26 | #include <memory> |
| 27 | #include <string> |
| 28 | #include <vector> |
| 29 | |
| 30 | constexpr const char* sensorPathPrefix = "/xyz/openbmc_project/sensors/"; |
| 31 | constexpr const char* sensorType = "NvidiaMctpVdm"; |
| 32 | |
| 33 | struct GpuTempSensor : |
| 34 | public Sensor, |
| 35 | public std::enable_shared_from_this<GpuTempSensor> |
| 36 | { |
| 37 | public: |
Harshit Aghera | d837b56 | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 38 | GpuTempSensor(std::shared_ptr<sdbusplus::asio::connection>& conn, |
Harshit Aghera | 560e6af | 2025-04-21 20:04:56 +0530 | [diff] [blame^] | 39 | boost::asio::io_context& io, |
| 40 | mctp::MctpRequester& mctpRequester, const std::string& name, |
Harshit Aghera | d837b56 | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 41 | const std::string& sensorConfiguration, |
| 42 | sdbusplus::asio::object_server& objectServer, |
Harshit Aghera | 560e6af | 2025-04-21 20:04:56 +0530 | [diff] [blame^] | 43 | std::vector<thresholds::Threshold>&& thresholdData, |
| 44 | std::chrono::milliseconds pollRate); |
Harshit Aghera | d837b56 | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 45 | |
Harshit Aghera | d837b56 | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 46 | ~GpuTempSensor() override; |
| 47 | |
Harshit Aghera | d837b56 | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 48 | void checkThresholds() override; |
| 49 | |
| 50 | private: |
Harshit Aghera | 560e6af | 2025-04-21 20:04:56 +0530 | [diff] [blame^] | 51 | void read(); |
| 52 | |
| 53 | void update(); |
| 54 | |
Harshit Aghera | d837b56 | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 55 | void discoverGpus(); |
| 56 | |
Harshit Aghera | 560e6af | 2025-04-21 20:04:56 +0530 | [diff] [blame^] | 57 | void processResponse(int sendRecvMsgResult); |
| 58 | |
| 59 | void processQueryDeviceIdResponse(uint8_t eid, int sendRecvMsgResult); |
| 60 | |
Harshit Aghera | d837b56 | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 61 | void queryEndpoints(const boost::system::error_code& ec, |
| 62 | const GetSubTreeType& ret); |
| 63 | |
Harshit Aghera | d837b56 | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 64 | void processEndpoint(const boost::system::error_code& ec, |
| 65 | const SensorBaseConfigMap& endpoint); |
Harshit Aghera | 560e6af | 2025-04-21 20:04:56 +0530 | [diff] [blame^] | 66 | void processGpuEndpoint(uint8_t eid); |
Harshit Aghera | d837b56 | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 67 | |
Harshit Aghera | 560e6af | 2025-04-21 20:04:56 +0530 | [diff] [blame^] | 68 | uint8_t eid{}; |
| 69 | |
| 70 | uint8_t sensorId; |
| 71 | |
| 72 | std::chrono::milliseconds sensorPollMs; |
| 73 | |
Harshit Aghera | d837b56 | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 74 | boost::asio::steady_timer waitTimer; |
| 75 | |
Harshit Aghera | 560e6af | 2025-04-21 20:04:56 +0530 | [diff] [blame^] | 76 | mctp::MctpRequester& mctpRequester; |
| 77 | |
Harshit Aghera | d837b56 | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 78 | std::shared_ptr<sdbusplus::asio::connection> conn; |
| 79 | |
Harshit Aghera | d837b56 | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 80 | sdbusplus::asio::object_server& objectServer; |
Harshit Aghera | 560e6af | 2025-04-21 20:04:56 +0530 | [diff] [blame^] | 81 | |
| 82 | std::array<uint8_t, sizeof(ocp::accelerator_management::Message) + |
| 83 | sizeof(gpu::GetTemperatureReadingRequest)> |
| 84 | getTemperatureReadingRequest{}; |
| 85 | |
| 86 | std::array<uint8_t, sizeof(ocp::accelerator_management::Message) + |
| 87 | sizeof(gpu::GetTemperatureReadingResponse)> |
| 88 | getTemperatureReadingResponse{}; |
| 89 | |
| 90 | std::array<uint8_t, sizeof(ocp::accelerator_management::Message) + |
| 91 | sizeof(gpu::QueryDeviceIdentificationRequest)> |
| 92 | queryDeviceIdentificationRequest{}; |
| 93 | |
| 94 | std::array<uint8_t, sizeof(ocp::accelerator_management::Message) + |
| 95 | sizeof(gpu::QueryDeviceIdentificationResponse)> |
| 96 | queryDeviceIdentificationResponse{}; |
Harshit Aghera | d837b56 | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 97 | }; |
| 98 | |
Harshit Aghera | d837b56 | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 99 | void createSensors( |
| 100 | boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer, |
| 101 | boost::container::flat_map<std::string, std::shared_ptr<GpuTempSensor>>& |
| 102 | sensors, |
Harshit Aghera | 560e6af | 2025-04-21 20:04:56 +0530 | [diff] [blame^] | 103 | std::shared_ptr<sdbusplus::asio::connection>& dbusConnection, |
| 104 | mctp::MctpRequester& mctpRequester); |
Harshit Aghera | d837b56 | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 105 | |
Harshit Aghera | d837b56 | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 106 | void interfaceRemoved( |
| 107 | sdbusplus::message_t& message, |
| 108 | boost::container::flat_map<std::string, std::shared_ptr<GpuTempSensor>>& |
| 109 | sensors); |