blob: 05d70603040291d205e5b6ff925f37fbb27a09e1 [file] [log] [blame]
Rohit PAId87bf7f2025-06-11 08:52:29 +05301#pragma once
2
3#include "MctpRequester.hpp"
4
5#include <NvidiaGpuMctpVdm.hpp>
Rohit PAI15e5d9f2025-06-12 17:11:46 +05306#include <boost/asio/steady_timer.hpp>
Rohit PAId87bf7f2025-06-11 08:52:29 +05307#include <sdbusplus/asio/connection.hpp>
8#include <sdbusplus/asio/object_server.hpp>
9
10#include <array>
11#include <memory>
Rohit PAI15e5d9f2025-06-12 17:11:46 +053012#include <optional>
13#include <queue>
Rohit PAId87bf7f2025-06-11 08:52:29 +053014#include <string>
Rohit PAI15e5d9f2025-06-12 17:11:46 +053015#include <string_view>
16#include <unordered_map>
Rohit PAId87bf7f2025-06-11 08:52:29 +053017
Rohit PAI15e5d9f2025-06-12 17:11:46 +053018using InventoryRequestBuffer =
19 std::array<uint8_t, sizeof(gpu::GetInventoryInformationRequest)>;
20using InventoryResponseBuffer =
21 std::array<uint8_t, sizeof(gpu::GetInventoryInformationResponse)>;
22
23class Inventory : public std::enable_shared_from_this<Inventory>
Rohit PAId87bf7f2025-06-11 08:52:29 +053024{
25 public:
26 enum class DeviceType
27 {
28 Unknown,
29 GPU,
30 };
31
32 Inventory(const std::shared_ptr<sdbusplus::asio::connection>& conn,
33 sdbusplus::asio::object_server& objectServer,
34 const std::string& inventoryName,
35 mctp::MctpRequester& mctpRequester, DeviceType deviceType,
Rohit PAI15e5d9f2025-06-12 17:11:46 +053036 uint8_t eid, boost::asio::io_context& io);
37
38 void fetchBoardPartNumber();
39 void fetchSerialNumber();
40 void update();
41
42 static std::optional<std::string_view> dbusPropertyNameForId(
43 gpu::InventoryPropertyId propertyId);
Rohit PAId87bf7f2025-06-11 08:52:29 +053044
45 private:
Rohit PAI15e5d9f2025-06-12 17:11:46 +053046 struct PropertyInfo
47 {
48 std::shared_ptr<sdbusplus::asio::dbus_interface> interface;
49 std::string propertyName;
50 int retryCount{0};
51 bool isPending{false};
52 };
53
54 void requestInventoryProperty(gpu::InventoryPropertyId propertyId);
55 void handleInventoryPropertyResponse(gpu::InventoryPropertyId propertyId,
56 int sendRecvMsgResult);
57 void processNextProperty();
58 void fetchInventoryProperty(gpu::InventoryPropertyId propertyId);
59 void registerProperty(gpu::InventoryPropertyId propertyId,
60 const std::string& interfaceName,
61 const std::string& propertyName);
62 std::optional<gpu::InventoryPropertyId> getNextPendingProperty() const;
63 void markPropertyPending(gpu::InventoryPropertyId propertyId);
64 void markPropertyProcessed(gpu::InventoryPropertyId propertyId);
65
66 std::shared_ptr<sdbusplus::asio::dbus_interface> assetIface;
Rohit PAId87bf7f2025-06-11 08:52:29 +053067 std::shared_ptr<sdbusplus::asio::dbus_interface> acceleratorInterface;
68
69 std::string name;
70 mctp::MctpRequester& mctpRequester;
71 DeviceType deviceType;
72 uint8_t eid;
Rohit PAI15e5d9f2025-06-12 17:11:46 +053073 boost::asio::steady_timer retryTimer;
74 std::unordered_map<gpu::InventoryPropertyId, PropertyInfo> properties;
75 std::shared_ptr<InventoryRequestBuffer> requestBuffer;
76 std::shared_ptr<InventoryResponseBuffer> responseBuffer;
77 static constexpr std::chrono::seconds retryDelay{5};
78 static constexpr int maxRetryAttempts = 3;
Rohit PAId87bf7f2025-06-11 08:52:29 +053079};