blob: b5f63a85a3b95f2271128aff9bac6aba54cdacbe [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
Marc Olberdingac920732025-09-28 21:56:54 -070029 void init();
30
Rohit PAI0a888262025-06-11 08:52:29 +053031 private:
Rohit PAIada6baa2025-07-01 18:26:19 +053032 struct PropertyInfo
33 {
34 std::shared_ptr<sdbusplus::asio::dbus_interface> interface;
35 std::string propertyName;
36 int retryCount{0};
37 bool isPending{false};
38 };
39 void sendInventoryPropertyRequest(gpu::InventoryPropertyId propertyId);
40 void handleInventoryPropertyResponse(gpu::InventoryPropertyId propertyId,
Marc Olberdingd0125c92025-10-08 14:37:19 -070041 const std::error_code& ec,
42 std::span<const uint8_t> buffer);
Rohit PAIada6baa2025-07-01 18:26:19 +053043 void processNextProperty();
44 void processInventoryProperty(gpu::InventoryPropertyId propertyId);
45 void registerProperty(
46 gpu::InventoryPropertyId propertyId,
47 const std::shared_ptr<sdbusplus::asio::dbus_interface>& interface,
48 const std::string& propertyName);
49 std::optional<gpu::InventoryPropertyId> getNextPendingProperty() const;
50 static void markPropertyPending(
51 std::unordered_map<gpu::InventoryPropertyId, PropertyInfo>::iterator
52 it);
53 static void markPropertyProcessed(
54 std::unordered_map<gpu::InventoryPropertyId, PropertyInfo>::iterator
55 it);
56
57 std::shared_ptr<sdbusplus::asio::dbus_interface> assetIface;
Rohit PAI0a888262025-06-11 08:52:29 +053058 std::shared_ptr<sdbusplus::asio::dbus_interface> acceleratorInterface;
Rohit PAIfb64f062025-06-13 18:20:02 +053059 std::shared_ptr<sdbusplus::asio::dbus_interface> uuidInterface;
Rohit PAI0ad57102025-06-13 19:29:20 +053060 std::shared_ptr<sdbusplus::asio::dbus_interface> revisionIface;
Rohit PAI0a888262025-06-11 08:52:29 +053061
62 std::string name;
Rohit PAIada6baa2025-07-01 18:26:19 +053063 mctp::MctpRequester& mctpRequester;
64 gpu::DeviceIdentification deviceType;
65 uint8_t eid;
66 boost::asio::steady_timer retryTimer;
67 std::unordered_map<gpu::InventoryPropertyId, PropertyInfo> properties;
Marc Olberdingd0125c92025-10-08 14:37:19 -070068 std::array<uint8_t, sizeof(gpu::GetInventoryInformationRequest)>
69 requestBuffer{};
Rohit PAIada6baa2025-07-01 18:26:19 +053070 static constexpr std::chrono::seconds retryDelay{5};
71 static constexpr int maxRetryAttempts = 3;
Rohit PAI0a888262025-06-11 08:52:29 +053072};