Rohit PAI | d87bf7f | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "MctpRequester.hpp" |
| 4 | |
| 5 | #include <NvidiaGpuMctpVdm.hpp> |
Rohit PAI | 15e5d9f | 2025-06-12 17:11:46 +0530 | [diff] [blame^] | 6 | #include <boost/asio/steady_timer.hpp> |
Rohit PAI | d87bf7f | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 7 | #include <sdbusplus/asio/connection.hpp> |
| 8 | #include <sdbusplus/asio/object_server.hpp> |
| 9 | |
| 10 | #include <array> |
| 11 | #include <memory> |
Rohit PAI | 15e5d9f | 2025-06-12 17:11:46 +0530 | [diff] [blame^] | 12 | #include <optional> |
| 13 | #include <queue> |
Rohit PAI | d87bf7f | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 14 | #include <string> |
Rohit PAI | 15e5d9f | 2025-06-12 17:11:46 +0530 | [diff] [blame^] | 15 | #include <string_view> |
| 16 | #include <unordered_map> |
Rohit PAI | d87bf7f | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 17 | |
Rohit PAI | 15e5d9f | 2025-06-12 17:11:46 +0530 | [diff] [blame^] | 18 | using InventoryRequestBuffer = |
| 19 | std::array<uint8_t, sizeof(gpu::GetInventoryInformationRequest)>; |
| 20 | using InventoryResponseBuffer = |
| 21 | std::array<uint8_t, sizeof(gpu::GetInventoryInformationResponse)>; |
| 22 | |
| 23 | class Inventory : public std::enable_shared_from_this<Inventory> |
Rohit PAI | d87bf7f | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 24 | { |
| 25 | public: |
| 26 | enum class DeviceType |
| 27 | { |
| 28 | Unknown, |
| 29 | GPU, |
| 30 | }; |
| 31 | |
| 32 | Inventory(const std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 33 | sdbusplus::asio::object_server& objectServer, |
| 34 | const std::string& inventoryName, |
| 35 | mctp::MctpRequester& mctpRequester, DeviceType deviceType, |
Rohit PAI | 15e5d9f | 2025-06-12 17:11:46 +0530 | [diff] [blame^] | 36 | uint8_t eid, boost::asio::io_context& io); |
| 37 | |
| 38 | void fetchBoardPartNumber(); |
| 39 | void fetchSerialNumber(); |
| 40 | void update(); |
| 41 | |
| 42 | static std::optional<std::string_view> dbusPropertyNameForId( |
| 43 | gpu::InventoryPropertyId propertyId); |
Rohit PAI | d87bf7f | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 44 | |
| 45 | private: |
Rohit PAI | 15e5d9f | 2025-06-12 17:11:46 +0530 | [diff] [blame^] | 46 | struct PropertyInfo |
| 47 | { |
| 48 | std::shared_ptr<sdbusplus::asio::dbus_interface> interface; |
| 49 | std::string propertyName; |
| 50 | int retryCount{0}; |
| 51 | bool isPending{false}; |
| 52 | }; |
| 53 | |
| 54 | void requestInventoryProperty(gpu::InventoryPropertyId propertyId); |
| 55 | void handleInventoryPropertyResponse(gpu::InventoryPropertyId propertyId, |
| 56 | int sendRecvMsgResult); |
| 57 | void processNextProperty(); |
| 58 | void fetchInventoryProperty(gpu::InventoryPropertyId propertyId); |
| 59 | void registerProperty(gpu::InventoryPropertyId propertyId, |
| 60 | const std::string& interfaceName, |
| 61 | const std::string& propertyName); |
| 62 | std::optional<gpu::InventoryPropertyId> getNextPendingProperty() const; |
| 63 | void markPropertyPending(gpu::InventoryPropertyId propertyId); |
| 64 | void markPropertyProcessed(gpu::InventoryPropertyId propertyId); |
| 65 | |
| 66 | std::shared_ptr<sdbusplus::asio::dbus_interface> assetIface; |
Rohit PAI | d87bf7f | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 67 | std::shared_ptr<sdbusplus::asio::dbus_interface> acceleratorInterface; |
| 68 | |
| 69 | std::string name; |
| 70 | mctp::MctpRequester& mctpRequester; |
| 71 | DeviceType deviceType; |
| 72 | uint8_t eid; |
Rohit PAI | 15e5d9f | 2025-06-12 17:11:46 +0530 | [diff] [blame^] | 73 | boost::asio::steady_timer retryTimer; |
| 74 | std::unordered_map<gpu::InventoryPropertyId, PropertyInfo> properties; |
| 75 | std::shared_ptr<InventoryRequestBuffer> requestBuffer; |
| 76 | std::shared_ptr<InventoryResponseBuffer> responseBuffer; |
| 77 | static constexpr std::chrono::seconds retryDelay{5}; |
| 78 | static constexpr int maxRetryAttempts = 3; |
Rohit PAI | d87bf7f | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 79 | }; |