| 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 | class Inventory : public std::enable_shared_from_this<Inventory> |
| Rohit PAI | 0a88826 | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 20 | { |
| 21 | public: |
| 22 | Inventory(const std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 23 | sdbusplus::asio::object_server& objectServer, |
| 24 | const std::string& inventoryName, |
| Rohit PAI | ada6baa | 2025-07-01 18:26:19 +0530 | [diff] [blame] | 25 | mctp::MctpRequester& mctpRequester, |
| 26 | gpu::DeviceIdentification deviceType, uint8_t eid, |
| 27 | boost::asio::io_context& io); |
| Rohit PAI | 0a88826 | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 28 | |
| Marc Olberding | ac92073 | 2025-09-28 21:56:54 -0700 | [diff] [blame] | 29 | void init(); |
| 30 | |
| Rohit PAI | 0a88826 | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 31 | private: |
| Rohit PAI | ada6baa | 2025-07-01 18:26:19 +0530 | [diff] [blame] | 32 | 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 Olberding | d0125c9 | 2025-10-08 14:37:19 -0700 | [diff] [blame] | 41 | const std::error_code& ec, |
| 42 | std::span<const uint8_t> buffer); |
| Rohit PAI | ada6baa | 2025-07-01 18:26:19 +0530 | [diff] [blame] | 43 | 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 PAI | 0a88826 | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 58 | std::shared_ptr<sdbusplus::asio::dbus_interface> acceleratorInterface; |
| Rohit PAI | fb64f06 | 2025-06-13 18:20:02 +0530 | [diff] [blame] | 59 | std::shared_ptr<sdbusplus::asio::dbus_interface> uuidInterface; |
| Rohit PAI | 0ad5710 | 2025-06-13 19:29:20 +0530 | [diff] [blame] | 60 | std::shared_ptr<sdbusplus::asio::dbus_interface> revisionIface; |
| Rohit PAI | 0a88826 | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 61 | |
| 62 | std::string name; |
| Rohit PAI | ada6baa | 2025-07-01 18:26:19 +0530 | [diff] [blame] | 63 | 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 Olberding | d0125c9 | 2025-10-08 14:37:19 -0700 | [diff] [blame] | 68 | std::array<uint8_t, sizeof(gpu::GetInventoryInformationRequest)> |
| 69 | requestBuffer{}; |
| Rohit PAI | ada6baa | 2025-07-01 18:26:19 +0530 | [diff] [blame] | 70 | static constexpr std::chrono::seconds retryDelay{5}; |
| 71 | static constexpr int maxRetryAttempts = 3; |
| Rohit PAI | 0a88826 | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 72 | }; |