blob: 5a24e560ba204026481be7d85fb2eec4b28bf734 [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 +053019class Inventory : public std::enable_shared_from_this<Inventory>
Rohit PAI0a888262025-06-11 08:52:29 +053020{
21 public:
22 Inventory(const std::shared_ptr<sdbusplus::asio::connection>& conn,
23 sdbusplus::asio::object_server& objectServer,
24 const std::string& inventoryName,
Rohit PAIada6baa2025-07-01 18:26:19 +053025 mctp::MctpRequester& mctpRequester,
26 gpu::DeviceIdentification deviceType, uint8_t eid,
27 boost::asio::io_context& io);
Rohit PAI0a888262025-06-11 08:52:29 +053028
29 private:
Rohit PAIada6baa2025-07-01 18:26:19 +053030 struct PropertyInfo
31 {
32 std::shared_ptr<sdbusplus::asio::dbus_interface> interface;
33 std::string propertyName;
34 int retryCount{0};
35 bool isPending{false};
36 };
37 void sendInventoryPropertyRequest(gpu::InventoryPropertyId propertyId);
38 void handleInventoryPropertyResponse(gpu::InventoryPropertyId propertyId,
Marc Olberdingd0125c92025-10-08 14:37:19 -070039 const std::error_code& ec,
40 std::span<const uint8_t> buffer);
Rohit PAIada6baa2025-07-01 18:26:19 +053041 void processNextProperty();
42 void processInventoryProperty(gpu::InventoryPropertyId propertyId);
43 void registerProperty(
44 gpu::InventoryPropertyId propertyId,
45 const std::shared_ptr<sdbusplus::asio::dbus_interface>& interface,
46 const std::string& propertyName);
47 std::optional<gpu::InventoryPropertyId> getNextPendingProperty() const;
48 static void markPropertyPending(
49 std::unordered_map<gpu::InventoryPropertyId, PropertyInfo>::iterator
50 it);
51 static void markPropertyProcessed(
52 std::unordered_map<gpu::InventoryPropertyId, PropertyInfo>::iterator
53 it);
54
55 std::shared_ptr<sdbusplus::asio::dbus_interface> assetIface;
Rohit PAI0a888262025-06-11 08:52:29 +053056 std::shared_ptr<sdbusplus::asio::dbus_interface> acceleratorInterface;
Rohit PAIfb64f062025-06-13 18:20:02 +053057 std::shared_ptr<sdbusplus::asio::dbus_interface> uuidInterface;
Rohit PAI0ad57102025-06-13 19:29:20 +053058 std::shared_ptr<sdbusplus::asio::dbus_interface> revisionIface;
Rohit PAI0a888262025-06-11 08:52:29 +053059
60 std::string name;
Rohit PAIada6baa2025-07-01 18:26:19 +053061 mctp::MctpRequester& mctpRequester;
62 gpu::DeviceIdentification deviceType;
63 uint8_t eid;
64 boost::asio::steady_timer retryTimer;
65 std::unordered_map<gpu::InventoryPropertyId, PropertyInfo> properties;
Marc Olberdingd0125c92025-10-08 14:37:19 -070066 std::array<uint8_t, sizeof(gpu::GetInventoryInformationRequest)>
67 requestBuffer{};
Rohit PAIada6baa2025-07-01 18:26:19 +053068 static constexpr std::chrono::seconds retryDelay{5};
69 static constexpr int maxRetryAttempts = 3;
Rohit PAI0a888262025-06-11 08:52:29 +053070};