1f60ac27eSMatt Spinler #pragma once 2f60ac27eSMatt Spinler 3f60ac27eSMatt Spinler #include "host_interface.hpp" 4f60ac27eSMatt Spinler #include "pel.hpp" 5f60ac27eSMatt Spinler #include "repository.hpp" 6f60ac27eSMatt Spinler 7f60ac27eSMatt Spinler #include <deque> 8*f869fcf8SMatt Spinler #include <sdeventplus/clock.hpp> 9*f869fcf8SMatt Spinler #include <sdeventplus/utility/timer.hpp> 10f60ac27eSMatt Spinler 11f60ac27eSMatt Spinler namespace openpower::pels 12f60ac27eSMatt Spinler { 13f60ac27eSMatt Spinler 14f60ac27eSMatt Spinler /** 15f60ac27eSMatt Spinler * @class HostNotifier 16f60ac27eSMatt Spinler * 17f60ac27eSMatt Spinler * This class handles notifying the host firmware of new PELs. 18f60ac27eSMatt Spinler */ 19f60ac27eSMatt Spinler class HostNotifier 20f60ac27eSMatt Spinler { 21f60ac27eSMatt Spinler public: 22f60ac27eSMatt Spinler HostNotifier() = delete; 23f60ac27eSMatt Spinler HostNotifier(const HostNotifier&) = delete; 24f60ac27eSMatt Spinler HostNotifier& operator=(const HostNotifier&) = delete; 25f60ac27eSMatt Spinler HostNotifier(HostNotifier&&) = delete; 26f60ac27eSMatt Spinler HostNotifier& operator=(HostNotifier&&) = delete; 27f60ac27eSMatt Spinler 28f60ac27eSMatt Spinler /** 29f60ac27eSMatt Spinler * @brief Constructor 30f60ac27eSMatt Spinler * 31f60ac27eSMatt Spinler * @param[in] repo - The PEL repository object 32f60ac27eSMatt Spinler * @param[in] dataIface - The data interface object 33f60ac27eSMatt Spinler * @param[in] hostIface - The host interface object 34f60ac27eSMatt Spinler */ 35f60ac27eSMatt Spinler HostNotifier(Repository& repo, DataInterfaceBase& dataIface, 36f60ac27eSMatt Spinler std::unique_ptr<HostInterface> hostIface); 37f60ac27eSMatt Spinler 38f60ac27eSMatt Spinler /** 39f60ac27eSMatt Spinler * @brief Destructor 40f60ac27eSMatt Spinler */ 41f60ac27eSMatt Spinler ~HostNotifier(); 42f60ac27eSMatt Spinler 43f60ac27eSMatt Spinler /** 44f60ac27eSMatt Spinler * @brief Returns the PEL queue size. 45f60ac27eSMatt Spinler * 46f60ac27eSMatt Spinler * For testing. 47f60ac27eSMatt Spinler * 48f60ac27eSMatt Spinler * @return size_t - The queue size 49f60ac27eSMatt Spinler */ 50f60ac27eSMatt Spinler size_t queueSize() const 51f60ac27eSMatt Spinler { 52f60ac27eSMatt Spinler return _pelQueue.size(); 53f60ac27eSMatt Spinler } 54f60ac27eSMatt Spinler 55f60ac27eSMatt Spinler /** 56f60ac27eSMatt Spinler * @brief Specifies if the PEL needs to go onto the queue to be 57f60ac27eSMatt Spinler * set to the host. 58f60ac27eSMatt Spinler * 59a943b15bSMatt Spinler * Only returns false if: 60a943b15bSMatt Spinler * - Already acked by the host (or they didn't like it) 61a943b15bSMatt Spinler * - Hidden and the HMC already got it 62a943b15bSMatt Spinler * - The 'do not report to host' bit is set 63a943b15bSMatt Spinler * 64f60ac27eSMatt Spinler * @param[in] id - The PEL ID 65f60ac27eSMatt Spinler * 66f60ac27eSMatt Spinler * @return bool - If enqueue is required 67f60ac27eSMatt Spinler */ 68f60ac27eSMatt Spinler bool enqueueRequired(uint32_t id) const; 69f60ac27eSMatt Spinler 70f60ac27eSMatt Spinler private: 71f60ac27eSMatt Spinler /** 72f60ac27eSMatt Spinler * @brief This function gets called by the Repository class 73f60ac27eSMatt Spinler * when a new PEL is added to it. 74f60ac27eSMatt Spinler * 75f60ac27eSMatt Spinler * @param[in] pel - The new PEL 76f60ac27eSMatt Spinler */ 77f60ac27eSMatt Spinler void newLogCallback(const PEL& pel); 78f60ac27eSMatt Spinler 79f60ac27eSMatt Spinler /** 80f60ac27eSMatt Spinler * @brief This function runs on every existing PEL at startup 81f60ac27eSMatt Spinler * and puts the PEL on the queue to send if necessary. 82f60ac27eSMatt Spinler * 83f60ac27eSMatt Spinler * @param[in] pel - The PEL 84f60ac27eSMatt Spinler * 85f60ac27eSMatt Spinler * @return bool - This is an indicator to the Repository::for_each 86f60ac27eSMatt Spinler * function to traverse every PEL. Always false. 87f60ac27eSMatt Spinler */ 88f60ac27eSMatt Spinler bool addPELToQueue(const PEL& pel); 89f60ac27eSMatt Spinler 90f60ac27eSMatt Spinler /** 91f60ac27eSMatt Spinler * @brief Takes the PEL off the front of the queue and issues 92f60ac27eSMatt Spinler * the PLDM send. 93f60ac27eSMatt Spinler */ 94f60ac27eSMatt Spinler void doNewLogNotify(); 95f60ac27eSMatt Spinler 96f60ac27eSMatt Spinler /** 97f60ac27eSMatt Spinler * @brief Called when the host changes state. 98f60ac27eSMatt Spinler * 99f60ac27eSMatt Spinler * @param[in] hostUp - The new host state 100f60ac27eSMatt Spinler */ 101f60ac27eSMatt Spinler void hostStateChange(bool hostUp); 102f60ac27eSMatt Spinler 103f60ac27eSMatt Spinler /** 104f60ac27eSMatt Spinler * @brief The callback function invoked after the asynchronous 105f60ac27eSMatt Spinler * PLDM receive function is complete. 106f60ac27eSMatt Spinler * 107*f869fcf8SMatt Spinler * If the command was successful, the state of that PEL will 108*f869fcf8SMatt Spinler * be set to 'sent', and the next send will be triggered. 109*f869fcf8SMatt Spinler * 110*f869fcf8SMatt Spinler * If the command failed, a retry timer will be started so it 111*f869fcf8SMatt Spinler * can be sent again. 112*f869fcf8SMatt Spinler * 113f60ac27eSMatt Spinler * @param[in] status - The response status 114f60ac27eSMatt Spinler */ 115f60ac27eSMatt Spinler void commandResponse(ResponseStatus status); 116f60ac27eSMatt Spinler 117f60ac27eSMatt Spinler /** 118*f869fcf8SMatt Spinler * @brief The function called when the command failure retry 119*f869fcf8SMatt Spinler * time is up. 120*f869fcf8SMatt Spinler * 121*f869fcf8SMatt Spinler * It will issue a send of the previous PEL and increment the 122*f869fcf8SMatt Spinler * retry count. 123*f869fcf8SMatt Spinler */ 124*f869fcf8SMatt Spinler void retryTimerExpired(); 125*f869fcf8SMatt Spinler 126*f869fcf8SMatt Spinler /** 127f60ac27eSMatt Spinler * @brief The PEL repository object 128f60ac27eSMatt Spinler */ 129f60ac27eSMatt Spinler Repository& _repo; 130f60ac27eSMatt Spinler 131f60ac27eSMatt Spinler /** 132f60ac27eSMatt Spinler * @brief The data interface object 133f60ac27eSMatt Spinler */ 134f60ac27eSMatt Spinler DataInterfaceBase& _dataIface; 135f60ac27eSMatt Spinler 136f60ac27eSMatt Spinler /** 137f60ac27eSMatt Spinler * @brief Base class pointer for the host command interface 138f60ac27eSMatt Spinler */ 139f60ac27eSMatt Spinler std::unique_ptr<HostInterface> _hostIface; 140f60ac27eSMatt Spinler 141f60ac27eSMatt Spinler /** 142f60ac27eSMatt Spinler * @brief The list of PEL IDs that need to be sent. 143f60ac27eSMatt Spinler */ 144f60ac27eSMatt Spinler std::deque<uint32_t> _pelQueue; 145*f869fcf8SMatt Spinler 146*f869fcf8SMatt Spinler /** 147*f869fcf8SMatt Spinler * @brief The list of IDs that were sent, but not acked yet. 148*f869fcf8SMatt Spinler * 149*f869fcf8SMatt Spinler * These move back to _pelQueue on a power off. 150*f869fcf8SMatt Spinler */ 151*f869fcf8SMatt Spinler std::vector<uint32_t> _sentPELs; 152*f869fcf8SMatt Spinler 153*f869fcf8SMatt Spinler /** 154*f869fcf8SMatt Spinler * @brief The ID the PEL where the notification has 155*f869fcf8SMatt Spinler * been kicked off but the asynchronous response 156*f869fcf8SMatt Spinler * hasn't been received yet. 157*f869fcf8SMatt Spinler */ 158*f869fcf8SMatt Spinler uint32_t _inProgressPEL = 0; 159*f869fcf8SMatt Spinler 160*f869fcf8SMatt Spinler /** 161*f869fcf8SMatt Spinler * @brief The command retry count 162*f869fcf8SMatt Spinler */ 163*f869fcf8SMatt Spinler size_t _retryCount = 0; 164*f869fcf8SMatt Spinler 165*f869fcf8SMatt Spinler /** 166*f869fcf8SMatt Spinler * @brief The command retry timer. 167*f869fcf8SMatt Spinler */ 168*f869fcf8SMatt Spinler sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> _retryTimer; 169f60ac27eSMatt Spinler }; 170f60ac27eSMatt Spinler 171f60ac27eSMatt Spinler } // namespace openpower::pels 172