xref: /openbmc/dbus-sensors/src/nvidia-gpu/NvidiaPcieInterface.hpp (revision e0b80e1e58bddcf218369f2f9e3ba2002b59b6f9)
1 /*
2  * SPDX-FileCopyrightText: Copyright OpenBMC Authors
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #pragma once
7 
8 #include "MctpRequester.hpp"
9 
10 #include <NvidiaGpuMctpVdm.hpp>
11 #include <sdbusplus/asio/connection.hpp>
12 #include <sdbusplus/asio/object_server.hpp>
13 
14 #include <array>
15 #include <cstddef>
16 #include <cstdint>
17 #include <memory>
18 #include <string>
19 #include <vector>
20 
21 struct NvidiaPcieInterface :
22     public std::enable_shared_from_this<NvidiaPcieInterface>
23 {
24   public:
25     NvidiaPcieInterface(std::shared_ptr<sdbusplus::asio::connection>& conn,
26                         mctp::MctpRequester& mctpRequester,
27                         const std::string& name, const std::string& path,
28                         uint8_t eid,
29                         sdbusplus::asio::object_server& objectServer);
30 
31     void update();
32 
33     static size_t decodeLinkWidth(uint32_t value);
34 
35   private:
36     static constexpr size_t maxTelemetryValues = 64;
37 
38     void processResponse(const std::error_code& ec,
39                          std::span<const uint8_t> response);
40 
41     static std::string mapPcieGeneration(uint32_t value);
42 
43     uint8_t eid{};
44 
45     std::string path;
46 
47     std::shared_ptr<sdbusplus::asio::connection> conn;
48 
49     mctp::MctpRequester& mctpRequester;
50 
51     std::array<uint8_t, sizeof(gpu::QueryScalarGroupTelemetryV2Request)>
52         request{};
53 
54     std::shared_ptr<sdbusplus::asio::dbus_interface> pcieDeviceInterface;
55     std::shared_ptr<sdbusplus::asio::dbus_interface> switchInterface;
56 
57     std::vector<uint32_t> telemetryValues{maxTelemetryValues};
58 };
59