1 #pragma once 2 3 #include "MctpRequester.hpp" 4 #include "NvidiaGpuMctpVdm.hpp" 5 6 #include <boost/asio/io_context.hpp> 7 #include <boost/asio/steady_timer.hpp> 8 #include <sdbusplus/asio/connection.hpp> 9 #include <sdbusplus/asio/object_server.hpp> 10 11 #include <array> 12 #include <chrono> 13 #include <cstdint> 14 #include <memory> 15 #include <optional> 16 #include <string> 17 #include <unordered_map> 18 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> 25 { 26 public: 27 Inventory(const std::shared_ptr<sdbusplus::asio::connection>& conn, 28 sdbusplus::asio::object_server& objectServer, 29 const std::string& inventoryName, 30 mctp::MctpRequester& mctpRequester, 31 gpu::DeviceIdentification deviceType, uint8_t eid, 32 boost::asio::io_context& io); 33 34 private: 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; 60 std::shared_ptr<sdbusplus::asio::dbus_interface> acceleratorInterface; 61 std::shared_ptr<sdbusplus::asio::dbus_interface> uuidInterface; 62 std::shared_ptr<sdbusplus::asio::dbus_interface> revisionIface; 63 64 std::string name; 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; 74 }; 75