xref: /openbmc/dbus-sensors/src/nvidia-gpu/Inventory.hpp (revision ada6baa945fbd1bd1969facb1d7dc2fc12453f2e)
10a88826fSRohit PAI #pragma once
20a88826fSRohit PAI 
3*ada6baa9SRohit PAI #include "MctpRequester.hpp"
40a88826fSRohit PAI #include "NvidiaGpuMctpVdm.hpp"
50a88826fSRohit PAI 
6*ada6baa9SRohit PAI #include <boost/asio/io_context.hpp>
7*ada6baa9SRohit PAI #include <boost/asio/steady_timer.hpp>
80a88826fSRohit PAI #include <sdbusplus/asio/connection.hpp>
90a88826fSRohit PAI #include <sdbusplus/asio/object_server.hpp>
100a88826fSRohit PAI 
11*ada6baa9SRohit PAI #include <array>
12*ada6baa9SRohit PAI #include <chrono>
13*ada6baa9SRohit PAI #include <cstdint>
140a88826fSRohit PAI #include <memory>
15*ada6baa9SRohit PAI #include <optional>
160a88826fSRohit PAI #include <string>
17*ada6baa9SRohit PAI #include <unordered_map>
180a88826fSRohit PAI 
19*ada6baa9SRohit PAI using InventoryRequestBuffer =
20*ada6baa9SRohit PAI     std::array<uint8_t, sizeof(gpu::GetInventoryInformationRequest)>;
21*ada6baa9SRohit PAI using InventoryResponseBuffer =
22*ada6baa9SRohit PAI     std::array<uint8_t, sizeof(gpu::GetInventoryInformationResponse)>;
23*ada6baa9SRohit PAI 
24*ada6baa9SRohit 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,
30*ada6baa9SRohit PAI               mctp::MctpRequester& mctpRequester,
31*ada6baa9SRohit PAI               gpu::DeviceIdentification deviceType, uint8_t eid,
32*ada6baa9SRohit PAI               boost::asio::io_context& io);
330a88826fSRohit PAI 
340a88826fSRohit PAI   private:
35*ada6baa9SRohit PAI     struct PropertyInfo
36*ada6baa9SRohit PAI     {
37*ada6baa9SRohit PAI         std::shared_ptr<sdbusplus::asio::dbus_interface> interface;
38*ada6baa9SRohit PAI         std::string propertyName;
39*ada6baa9SRohit PAI         int retryCount{0};
40*ada6baa9SRohit PAI         bool isPending{false};
41*ada6baa9SRohit PAI     };
42*ada6baa9SRohit PAI     void sendInventoryPropertyRequest(gpu::InventoryPropertyId propertyId);
43*ada6baa9SRohit PAI     void handleInventoryPropertyResponse(gpu::InventoryPropertyId propertyId,
44*ada6baa9SRohit PAI                                          int sendRecvMsgResult);
45*ada6baa9SRohit PAI     void processNextProperty();
46*ada6baa9SRohit PAI     void processInventoryProperty(gpu::InventoryPropertyId propertyId);
47*ada6baa9SRohit PAI     void registerProperty(
48*ada6baa9SRohit PAI         gpu::InventoryPropertyId propertyId,
49*ada6baa9SRohit PAI         const std::shared_ptr<sdbusplus::asio::dbus_interface>& interface,
50*ada6baa9SRohit PAI         const std::string& propertyName);
51*ada6baa9SRohit PAI     std::optional<gpu::InventoryPropertyId> getNextPendingProperty() const;
52*ada6baa9SRohit PAI     static void markPropertyPending(
53*ada6baa9SRohit PAI         std::unordered_map<gpu::InventoryPropertyId, PropertyInfo>::iterator
54*ada6baa9SRohit PAI             it);
55*ada6baa9SRohit PAI     static void markPropertyProcessed(
56*ada6baa9SRohit PAI         std::unordered_map<gpu::InventoryPropertyId, PropertyInfo>::iterator
57*ada6baa9SRohit PAI             it);
58*ada6baa9SRohit PAI 
59*ada6baa9SRohit PAI     std::shared_ptr<sdbusplus::asio::dbus_interface> assetIface;
600a88826fSRohit PAI     std::shared_ptr<sdbusplus::asio::dbus_interface> acceleratorInterface;
610a88826fSRohit PAI 
620a88826fSRohit PAI     std::string name;
63*ada6baa9SRohit PAI     mctp::MctpRequester& mctpRequester;
64*ada6baa9SRohit PAI     gpu::DeviceIdentification deviceType;
65*ada6baa9SRohit PAI     uint8_t eid;
66*ada6baa9SRohit PAI     boost::asio::steady_timer retryTimer;
67*ada6baa9SRohit PAI     std::unordered_map<gpu::InventoryPropertyId, PropertyInfo> properties;
68*ada6baa9SRohit PAI     std::shared_ptr<InventoryRequestBuffer> requestBuffer;
69*ada6baa9SRohit PAI     std::shared_ptr<InventoryResponseBuffer> responseBuffer;
70*ada6baa9SRohit PAI     static constexpr std::chrono::seconds retryDelay{5};
71*ada6baa9SRohit PAI     static constexpr int maxRetryAttempts = 3;
720a88826fSRohit PAI };
73