blob: ea38f6f3084dd9d8253a1d8d8864d8c7be0f1f32 [file] [log] [blame]
Rohit PAI0a888262025-06-11 08:52:29 +05301#pragma once
2
Rohit PAIada6baa2025-07-01 18:26:19 +05303#include "MctpRequester.hpp"
Rohit PAI0a888262025-06-11 08:52:29 +05304#include "NvidiaGpuMctpVdm.hpp"
5
Rohit PAIada6baa2025-07-01 18:26:19 +05306#include <boost/asio/io_context.hpp>
7#include <boost/asio/steady_timer.hpp>
Rohit PAI0a888262025-06-11 08:52:29 +05308#include <sdbusplus/asio/connection.hpp>
9#include <sdbusplus/asio/object_server.hpp>
10
Rohit PAIada6baa2025-07-01 18:26:19 +053011#include <array>
12#include <chrono>
13#include <cstdint>
Rohit PAI0a888262025-06-11 08:52:29 +053014#include <memory>
Rohit PAIada6baa2025-07-01 18:26:19 +053015#include <optional>
Rohit PAI0a888262025-06-11 08:52:29 +053016#include <string>
Rohit PAIada6baa2025-07-01 18:26:19 +053017#include <unordered_map>
Rohit PAI0a888262025-06-11 08:52:29 +053018
Rohit PAIada6baa2025-07-01 18:26:19 +053019using InventoryRequestBuffer =
20 std::array<uint8_t, sizeof(gpu::GetInventoryInformationRequest)>;
21using InventoryResponseBuffer =
22 std::array<uint8_t, sizeof(gpu::GetInventoryInformationResponse)>;
23
24class Inventory : public std::enable_shared_from_this<Inventory>
Rohit PAI0a888262025-06-11 08:52:29 +053025{
26 public:
27 Inventory(const std::shared_ptr<sdbusplus::asio::connection>& conn,
28 sdbusplus::asio::object_server& objectServer,
29 const std::string& inventoryName,
Rohit PAIada6baa2025-07-01 18:26:19 +053030 mctp::MctpRequester& mctpRequester,
31 gpu::DeviceIdentification deviceType, uint8_t eid,
32 boost::asio::io_context& io);
Rohit PAI0a888262025-06-11 08:52:29 +053033
34 private:
Rohit PAIada6baa2025-07-01 18:26:19 +053035 struct PropertyInfo
36 {
37 std::shared_ptr<sdbusplus::asio::dbus_interface> interface;
38 std::string propertyName;
39 int retryCount{0};
40 bool isPending{false};
41 };
42 void sendInventoryPropertyRequest(gpu::InventoryPropertyId propertyId);
43 void handleInventoryPropertyResponse(gpu::InventoryPropertyId propertyId,
44 int sendRecvMsgResult);
45 void processNextProperty();
46 void processInventoryProperty(gpu::InventoryPropertyId propertyId);
47 void registerProperty(
48 gpu::InventoryPropertyId propertyId,
49 const std::shared_ptr<sdbusplus::asio::dbus_interface>& interface,
50 const std::string& propertyName);
51 std::optional<gpu::InventoryPropertyId> getNextPendingProperty() const;
52 static void markPropertyPending(
53 std::unordered_map<gpu::InventoryPropertyId, PropertyInfo>::iterator
54 it);
55 static void markPropertyProcessed(
56 std::unordered_map<gpu::InventoryPropertyId, PropertyInfo>::iterator
57 it);
58
59 std::shared_ptr<sdbusplus::asio::dbus_interface> assetIface;
Rohit PAI0a888262025-06-11 08:52:29 +053060 std::shared_ptr<sdbusplus::asio::dbus_interface> acceleratorInterface;
Rohit PAIfb64f062025-06-13 18:20:02 +053061 std::shared_ptr<sdbusplus::asio::dbus_interface> uuidInterface;
Rohit PAI0ad57102025-06-13 19:29:20 +053062 std::shared_ptr<sdbusplus::asio::dbus_interface> revisionIface;
Rohit PAI0a888262025-06-11 08:52:29 +053063
64 std::string name;
Rohit PAIada6baa2025-07-01 18:26:19 +053065 mctp::MctpRequester& mctpRequester;
66 gpu::DeviceIdentification deviceType;
67 uint8_t eid;
68 boost::asio::steady_timer retryTimer;
69 std::unordered_map<gpu::InventoryPropertyId, PropertyInfo> properties;
70 std::shared_ptr<InventoryRequestBuffer> requestBuffer;
71 std::shared_ptr<InventoryResponseBuffer> responseBuffer;
72 static constexpr std::chrono::seconds retryDelay{5};
73 static constexpr int maxRetryAttempts = 3;
Rohit PAI0a888262025-06-11 08:52:29 +053074};