| Rohit PAI | 0a88826 | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 1 | #pragma once | 
|  | 2 |  | 
| Rohit PAI | ada6baa | 2025-07-01 18:26:19 +0530 | [diff] [blame] | 3 | #include "MctpRequester.hpp" | 
| Rohit PAI | 0a88826 | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 4 | #include "NvidiaGpuMctpVdm.hpp" | 
|  | 5 |  | 
| Rohit PAI | ada6baa | 2025-07-01 18:26:19 +0530 | [diff] [blame] | 6 | #include <boost/asio/io_context.hpp> | 
|  | 7 | #include <boost/asio/steady_timer.hpp> | 
| Rohit PAI | 0a88826 | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 8 | #include <sdbusplus/asio/connection.hpp> | 
|  | 9 | #include <sdbusplus/asio/object_server.hpp> | 
|  | 10 |  | 
| Rohit PAI | ada6baa | 2025-07-01 18:26:19 +0530 | [diff] [blame] | 11 | #include <array> | 
|  | 12 | #include <chrono> | 
|  | 13 | #include <cstdint> | 
| Rohit PAI | 0a88826 | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 14 | #include <memory> | 
| Rohit PAI | ada6baa | 2025-07-01 18:26:19 +0530 | [diff] [blame] | 15 | #include <optional> | 
| Rohit PAI | 0a88826 | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 16 | #include <string> | 
| Rohit PAI | ada6baa | 2025-07-01 18:26:19 +0530 | [diff] [blame] | 17 | #include <unordered_map> | 
| Rohit PAI | 0a88826 | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 18 |  | 
| Rohit PAI | ada6baa | 2025-07-01 18:26:19 +0530 | [diff] [blame] | 19 | using InventoryRequestBuffer = | 
|  | 20 | std::array<uint8_t, sizeof(gpu::GetInventoryInformationRequest)>; | 
|  | 21 | using InventoryResponseBuffer = | 
|  | 22 | std::array<uint8_t, sizeof(gpu::GetInventoryInformationResponse)>; | 
|  | 23 |  | 
|  | 24 | class Inventory : public std::enable_shared_from_this<Inventory> | 
| Rohit PAI | 0a88826 | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 25 | { | 
|  | 26 | public: | 
|  | 27 | Inventory(const std::shared_ptr<sdbusplus::asio::connection>& conn, | 
|  | 28 | sdbusplus::asio::object_server& objectServer, | 
|  | 29 | const std::string& inventoryName, | 
| Rohit PAI | ada6baa | 2025-07-01 18:26:19 +0530 | [diff] [blame] | 30 | mctp::MctpRequester& mctpRequester, | 
|  | 31 | gpu::DeviceIdentification deviceType, uint8_t eid, | 
|  | 32 | boost::asio::io_context& io); | 
| Rohit PAI | 0a88826 | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 33 |  | 
|  | 34 | private: | 
| Rohit PAI | ada6baa | 2025-07-01 18:26:19 +0530 | [diff] [blame] | 35 | 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 PAI | 0a88826 | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 60 | std::shared_ptr<sdbusplus::asio::dbus_interface> acceleratorInterface; | 
| Rohit PAI | fb64f06 | 2025-06-13 18:20:02 +0530 | [diff] [blame] | 61 | std::shared_ptr<sdbusplus::asio::dbus_interface> uuidInterface; | 
| Rohit PAI | 0ad5710 | 2025-06-13 19:29:20 +0530 | [diff] [blame] | 62 | std::shared_ptr<sdbusplus::asio::dbus_interface> revisionIface; | 
| Rohit PAI | 0a88826 | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 63 |  | 
|  | 64 | std::string name; | 
| Rohit PAI | ada6baa | 2025-07-01 18:26:19 +0530 | [diff] [blame] | 65 | 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 PAI | 0a88826 | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 74 | }; |