10a88826fSRohit PAI #pragma once 20a88826fSRohit PAI 3ada6baa9SRohit PAI #include "MctpRequester.hpp" 40a88826fSRohit PAI #include "NvidiaGpuMctpVdm.hpp" 50a88826fSRohit PAI 6ada6baa9SRohit PAI #include <boost/asio/io_context.hpp> 7ada6baa9SRohit PAI #include <boost/asio/steady_timer.hpp> 80a88826fSRohit PAI #include <sdbusplus/asio/connection.hpp> 90a88826fSRohit PAI #include <sdbusplus/asio/object_server.hpp> 100a88826fSRohit PAI 11ada6baa9SRohit PAI #include <array> 12ada6baa9SRohit PAI #include <chrono> 13ada6baa9SRohit PAI #include <cstdint> 140a88826fSRohit PAI #include <memory> 15ada6baa9SRohit PAI #include <optional> 160a88826fSRohit PAI #include <string> 17ada6baa9SRohit PAI #include <unordered_map> 180a88826fSRohit PAI 19ada6baa9SRohit PAI using InventoryRequestBuffer = 20ada6baa9SRohit PAI std::array<uint8_t, sizeof(gpu::GetInventoryInformationRequest)>; 21ada6baa9SRohit PAI using InventoryResponseBuffer = 22ada6baa9SRohit PAI std::array<uint8_t, sizeof(gpu::GetInventoryInformationResponse)>; 23ada6baa9SRohit PAI 24ada6baa9SRohit PAI class Inventory : public std::enable_shared_from_this<Inventory> 250a88826fSRohit PAI { 260a88826fSRohit PAI public: 270a88826fSRohit PAI Inventory(const std::shared_ptr<sdbusplus::asio::connection>& conn, 280a88826fSRohit PAI sdbusplus::asio::object_server& objectServer, 290a88826fSRohit PAI const std::string& inventoryName, 30ada6baa9SRohit PAI mctp::MctpRequester& mctpRequester, 31ada6baa9SRohit PAI gpu::DeviceIdentification deviceType, uint8_t eid, 32ada6baa9SRohit PAI boost::asio::io_context& io); 330a88826fSRohit PAI 340a88826fSRohit PAI private: 35ada6baa9SRohit PAI struct PropertyInfo 36ada6baa9SRohit PAI { 37ada6baa9SRohit PAI std::shared_ptr<sdbusplus::asio::dbus_interface> interface; 38ada6baa9SRohit PAI std::string propertyName; 39ada6baa9SRohit PAI int retryCount{0}; 40ada6baa9SRohit PAI bool isPending{false}; 41ada6baa9SRohit PAI }; 42ada6baa9SRohit PAI void sendInventoryPropertyRequest(gpu::InventoryPropertyId propertyId); 43ada6baa9SRohit PAI void handleInventoryPropertyResponse(gpu::InventoryPropertyId propertyId, 44ada6baa9SRohit PAI int sendRecvMsgResult); 45ada6baa9SRohit PAI void processNextProperty(); 46ada6baa9SRohit PAI void processInventoryProperty(gpu::InventoryPropertyId propertyId); 47ada6baa9SRohit PAI void registerProperty( 48ada6baa9SRohit PAI gpu::InventoryPropertyId propertyId, 49ada6baa9SRohit PAI const std::shared_ptr<sdbusplus::asio::dbus_interface>& interface, 50ada6baa9SRohit PAI const std::string& propertyName); 51ada6baa9SRohit PAI std::optional<gpu::InventoryPropertyId> getNextPendingProperty() const; 52ada6baa9SRohit PAI static void markPropertyPending( 53ada6baa9SRohit PAI std::unordered_map<gpu::InventoryPropertyId, PropertyInfo>::iterator 54ada6baa9SRohit PAI it); 55ada6baa9SRohit PAI static void markPropertyProcessed( 56ada6baa9SRohit PAI std::unordered_map<gpu::InventoryPropertyId, PropertyInfo>::iterator 57ada6baa9SRohit PAI it); 58ada6baa9SRohit PAI 59ada6baa9SRohit PAI std::shared_ptr<sdbusplus::asio::dbus_interface> assetIface; 600a88826fSRohit PAI std::shared_ptr<sdbusplus::asio::dbus_interface> acceleratorInterface; 61fb64f063SRohit PAI std::shared_ptr<sdbusplus::asio::dbus_interface> uuidInterface; 62*0ad57100SRohit PAI std::shared_ptr<sdbusplus::asio::dbus_interface> revisionIface; 630a88826fSRohit PAI 640a88826fSRohit PAI std::string name; 65ada6baa9SRohit PAI mctp::MctpRequester& mctpRequester; 66ada6baa9SRohit PAI gpu::DeviceIdentification deviceType; 67ada6baa9SRohit PAI uint8_t eid; 68ada6baa9SRohit PAI boost::asio::steady_timer retryTimer; 69ada6baa9SRohit PAI std::unordered_map<gpu::InventoryPropertyId, PropertyInfo> properties; 70ada6baa9SRohit PAI std::shared_ptr<InventoryRequestBuffer> requestBuffer; 71ada6baa9SRohit PAI std::shared_ptr<InventoryResponseBuffer> responseBuffer; 72ada6baa9SRohit PAI static constexpr std::chrono::seconds retryDelay{5}; 73ada6baa9SRohit PAI static constexpr int maxRetryAttempts = 3; 740a88826fSRohit PAI }; 75