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> 8f869fcf8SMatt Spinler #include <sdeventplus/clock.hpp> 97d800a4eSMatt Spinler #include <sdeventplus/source/event.hpp> 10f869fcf8SMatt Spinler #include <sdeventplus/utility/timer.hpp> 11f60ac27eSMatt Spinler 12f60ac27eSMatt Spinler namespace openpower::pels 13f60ac27eSMatt Spinler { 14f60ac27eSMatt Spinler 15f60ac27eSMatt Spinler /** 16f60ac27eSMatt Spinler * @class HostNotifier 17f60ac27eSMatt Spinler * 18f60ac27eSMatt Spinler * This class handles notifying the host firmware of new PELs. 19*0e1593ecSMatt Spinler * 20*0e1593ecSMatt Spinler * It uses the Repository class's subscription feature to be 21*0e1593ecSMatt Spinler * notified about new PELs. 22*0e1593ecSMatt Spinler * 23*0e1593ecSMatt Spinler * Some PELs do not need to be sent - see enqueueRequired() and 24*0e1593ecSMatt Spinler * notifyRequired(). 25*0e1593ecSMatt Spinler * 26*0e1593ecSMatt Spinler * The high level good path flow for sending a single PEL is: 27*0e1593ecSMatt Spinler * 28*0e1593ecSMatt Spinler * 1) Send the ID and size of the new PEL to the host. 29*0e1593ecSMatt Spinler * - The command response is asynchronous. 30*0e1593ecSMatt Spinler * 31*0e1593ecSMatt Spinler * 2) The host reads the raw PEL data (outside of this class). 32*0e1593ecSMatt Spinler * 33*0e1593ecSMatt Spinler * 3) The host sends the PEL to the OS, and then sends an AckPEL 34*0e1593ecSMatt Spinler * PLDM command to the PLDM daemon, who makes a D-Bus method 35*0e1593ecSMatt Spinler * call to this daemon, which calls HostNotifer::ackPEL(). 36*0e1593ecSMatt Spinler * 37*0e1593ecSMatt Spinler * After this, a PEL never needs to be sent again, but if the 38*0e1593ecSMatt Spinler * host is rebooted before the ack comes it will. 39*0e1593ecSMatt Spinler * 40*0e1593ecSMatt Spinler * The host firmware has a finite amount of space to store PELs before 41*0e1593ecSMatt Spinler * sending to the OS, and it's possible it will fill up. In this case, 42*0e1593ecSMatt Spinler * the AckPEL command will have a special response that will tell the 43*0e1593ecSMatt Spinler * PLDM daemon to call HostReject D-Bus method on this daemon instead 44*0e1593ecSMatt Spinler * which will invoke HostNotifier::setHostFull(). This will stop new 45*0e1593ecSMatt Spinler * PELs from being sent, and the first PEL that hits this will have 46*0e1593ecSMatt Spinler * a timer set to retry again later. 47f60ac27eSMatt Spinler */ 48f60ac27eSMatt Spinler class HostNotifier 49f60ac27eSMatt Spinler { 50f60ac27eSMatt Spinler public: 51f60ac27eSMatt Spinler HostNotifier() = delete; 52f60ac27eSMatt Spinler HostNotifier(const HostNotifier&) = delete; 53f60ac27eSMatt Spinler HostNotifier& operator=(const HostNotifier&) = delete; 54f60ac27eSMatt Spinler HostNotifier(HostNotifier&&) = delete; 55f60ac27eSMatt Spinler HostNotifier& operator=(HostNotifier&&) = delete; 56f60ac27eSMatt Spinler 57f60ac27eSMatt Spinler /** 58f60ac27eSMatt Spinler * @brief Constructor 59f60ac27eSMatt Spinler * 60f60ac27eSMatt Spinler * @param[in] repo - The PEL repository object 61f60ac27eSMatt Spinler * @param[in] dataIface - The data interface object 62f60ac27eSMatt Spinler * @param[in] hostIface - The host interface object 63f60ac27eSMatt Spinler */ 64f60ac27eSMatt Spinler HostNotifier(Repository& repo, DataInterfaceBase& dataIface, 65f60ac27eSMatt Spinler std::unique_ptr<HostInterface> hostIface); 66f60ac27eSMatt Spinler 67f60ac27eSMatt Spinler /** 68f60ac27eSMatt Spinler * @brief Destructor 69f60ac27eSMatt Spinler */ 70f60ac27eSMatt Spinler ~HostNotifier(); 71f60ac27eSMatt Spinler 72f60ac27eSMatt Spinler /** 73f60ac27eSMatt Spinler * @brief Returns the PEL queue size. 74f60ac27eSMatt Spinler * 75f60ac27eSMatt Spinler * For testing. 76f60ac27eSMatt Spinler * 77f60ac27eSMatt Spinler * @return size_t - The queue size 78f60ac27eSMatt Spinler */ 79f60ac27eSMatt Spinler size_t queueSize() const 80f60ac27eSMatt Spinler { 81f60ac27eSMatt Spinler return _pelQueue.size(); 82f60ac27eSMatt Spinler } 83f60ac27eSMatt Spinler 84f60ac27eSMatt Spinler /** 85f60ac27eSMatt Spinler * @brief Specifies if the PEL needs to go onto the queue to be 86f60ac27eSMatt Spinler * set to the host. 87f60ac27eSMatt Spinler * 88a943b15bSMatt Spinler * Only returns false if: 89a943b15bSMatt Spinler * - Already acked by the host (or they didn't like it) 90a943b15bSMatt Spinler * - Hidden and the HMC already got it 91a943b15bSMatt Spinler * - The 'do not report to host' bit is set 92a943b15bSMatt Spinler * 93f60ac27eSMatt Spinler * @param[in] id - The PEL ID 94f60ac27eSMatt Spinler * 95f60ac27eSMatt Spinler * @return bool - If enqueue is required 96f60ac27eSMatt Spinler */ 97f60ac27eSMatt Spinler bool enqueueRequired(uint32_t id) const; 98f60ac27eSMatt Spinler 99f77debb9SMatt Spinler /** 100f77debb9SMatt Spinler * @brief If the host still needs to be notified of the PEL 101f77debb9SMatt Spinler * at the time of the notification. 102f77debb9SMatt Spinler * 103f77debb9SMatt Spinler * Only returns false if: 104f77debb9SMatt Spinler * - Already acked by the host 105f77debb9SMatt Spinler * - It's hidden, and the HMC already got or will get it. 106f77debb9SMatt Spinler * 107f77debb9SMatt Spinler * @param[in] id - The PEL ID 108f77debb9SMatt Spinler * 109f77debb9SMatt Spinler * @return bool - If the notify is required 110f77debb9SMatt Spinler */ 111f77debb9SMatt Spinler bool notifyRequired(uint32_t id) const; 112f77debb9SMatt Spinler 113cc3b64aeSMatt Spinler /** 114cc3b64aeSMatt Spinler * @brief Called when the host sends the 'ack' PLDM command. 115cc3b64aeSMatt Spinler * 116cc3b64aeSMatt Spinler * This means the PEL never needs to be sent up again. 117cc3b64aeSMatt Spinler * 11841293cb8SMatt Spinler * If the host was previously full, it is also an indication 11941293cb8SMatt Spinler * it no longer is. 12041293cb8SMatt Spinler * 121cc3b64aeSMatt Spinler * @param[in] id - The PEL ID 122cc3b64aeSMatt Spinler */ 123cc3b64aeSMatt Spinler void ackPEL(uint32_t id); 124cc3b64aeSMatt Spinler 12541293cb8SMatt Spinler /** 12641293cb8SMatt Spinler * @brief Called when the host does not have room for more 12741293cb8SMatt Spinler * PELs at this time. 12841293cb8SMatt Spinler * 12941293cb8SMatt Spinler * This can happen when an OS isn't running yet, and the 13041293cb8SMatt Spinler * staging area to hold the PELs before sending them up 13141293cb8SMatt Spinler * to the OS is full. This will stop future PEls from being 13241293cb8SMatt Spinler * sent up, as explained below. 13341293cb8SMatt Spinler * 13441293cb8SMatt Spinler * The PEL with this ID will need to be sent again, so its 13541293cb8SMatt Spinler * state is set back to 'new', and it is removed from the list 13641293cb8SMatt Spinler * of already sent PELs. 13741293cb8SMatt Spinler * 13841293cb8SMatt Spinler * A timer will be started, if it isn't already running, to 13941293cb8SMatt Spinler * issue another send in the hopes that space has been freed 14041293cb8SMatt Spinler * up by then (Receiving an ackPEL response is also an 14141293cb8SMatt Spinler * indication of this if there happened to have been other 14241293cb8SMatt Spinler * PELs in flight). 14341293cb8SMatt Spinler * 14441293cb8SMatt Spinler * @param[in] id - The PEL ID 14541293cb8SMatt Spinler */ 14641293cb8SMatt Spinler void setHostFull(uint32_t id); 14741293cb8SMatt Spinler 148a19b6234SMatt Spinler /** 149a19b6234SMatt Spinler * @brief Called when the host receives a malformed PEL. 150a19b6234SMatt Spinler * 151a19b6234SMatt Spinler * Ideally this will never happen, as the Repository 152a19b6234SMatt Spinler * class already purges malformed PELs. 153a19b6234SMatt Spinler * 154a19b6234SMatt Spinler * The PEL should never be sent up again. 155a19b6234SMatt Spinler * 156a19b6234SMatt Spinler * @param[in] id - The PEL ID 157a19b6234SMatt Spinler */ 158a19b6234SMatt Spinler void setBadPEL(uint32_t id); 159a19b6234SMatt Spinler 160f60ac27eSMatt Spinler private: 161f60ac27eSMatt Spinler /** 162f60ac27eSMatt Spinler * @brief This function gets called by the Repository class 163f60ac27eSMatt Spinler * when a new PEL is added to it. 164f60ac27eSMatt Spinler * 1657d800a4eSMatt Spinler * This function puts the PEL on the queue to be sent up if it 1667d800a4eSMatt Spinler * needs it, and possibly dispatch the send if the conditions call 1677d800a4eSMatt Spinler * for it. 1687d800a4eSMatt Spinler * 169f60ac27eSMatt Spinler * @param[in] pel - The new PEL 170f60ac27eSMatt Spinler */ 171f60ac27eSMatt Spinler void newLogCallback(const PEL& pel); 172f60ac27eSMatt Spinler 173f60ac27eSMatt Spinler /** 174f60ac27eSMatt Spinler * @brief This function runs on every existing PEL at startup 175f60ac27eSMatt Spinler * and puts the PEL on the queue to send if necessary. 176f60ac27eSMatt Spinler * 177f60ac27eSMatt Spinler * @param[in] pel - The PEL 178f60ac27eSMatt Spinler * 179f60ac27eSMatt Spinler * @return bool - This is an indicator to the Repository::for_each 180f60ac27eSMatt Spinler * function to traverse every PEL. Always false. 181f60ac27eSMatt Spinler */ 182f60ac27eSMatt Spinler bool addPELToQueue(const PEL& pel); 183f60ac27eSMatt Spinler 184f60ac27eSMatt Spinler /** 185f77debb9SMatt Spinler * @brief Takes the first PEL from the queue that needs to be 186f77debb9SMatt Spinler * sent, and issues the send if conditions are right. 187f60ac27eSMatt Spinler */ 188f60ac27eSMatt Spinler void doNewLogNotify(); 189f60ac27eSMatt Spinler 190f60ac27eSMatt Spinler /** 1917d800a4eSMatt Spinler * @brief Creates the event object to handle sending the PLDM 1927d800a4eSMatt Spinler * command from the event loop. 1937d800a4eSMatt Spinler */ 1947d800a4eSMatt Spinler void scheduleDispatch(); 1957d800a4eSMatt Spinler 1967d800a4eSMatt Spinler /** 1977d800a4eSMatt Spinler * @brief Kicks off the PLDM send, but called from the event 1987d800a4eSMatt Spinler * loop. 1997d800a4eSMatt Spinler * 2007d800a4eSMatt Spinler * @param[in] source - The event source object 2017d800a4eSMatt Spinler */ 2027d800a4eSMatt Spinler void dispatch(sdeventplus::source::EventBase& source); 2037d800a4eSMatt Spinler 2047d800a4eSMatt Spinler /** 205f60ac27eSMatt Spinler * @brief Called when the host changes state. 206f60ac27eSMatt Spinler * 2073019c6fbSMatt Spinler * If the new state is host up and there are PELs to send, it 2083019c6fbSMatt Spinler * will trigger the first command. If the new state is off, then 2093019c6fbSMatt Spinler * it will transfer any PELs that were sent but not acked yet back 2103019c6fbSMatt Spinler * to the queue to be sent again. 2113019c6fbSMatt Spinler * 212f60ac27eSMatt Spinler * @param[in] hostUp - The new host state 213f60ac27eSMatt Spinler */ 214f60ac27eSMatt Spinler void hostStateChange(bool hostUp); 215f60ac27eSMatt Spinler 216f60ac27eSMatt Spinler /** 217f60ac27eSMatt Spinler * @brief The callback function invoked after the asynchronous 218f60ac27eSMatt Spinler * PLDM receive function is complete. 219f60ac27eSMatt Spinler * 220f869fcf8SMatt Spinler * If the command was successful, the state of that PEL will 221f869fcf8SMatt Spinler * be set to 'sent', and the next send will be triggered. 222f869fcf8SMatt Spinler * 223f869fcf8SMatt Spinler * If the command failed, a retry timer will be started so it 224f869fcf8SMatt Spinler * can be sent again. 225f869fcf8SMatt Spinler * 226f60ac27eSMatt Spinler * @param[in] status - The response status 227f60ac27eSMatt Spinler */ 228f60ac27eSMatt Spinler void commandResponse(ResponseStatus status); 229f60ac27eSMatt Spinler 230f60ac27eSMatt Spinler /** 231f869fcf8SMatt Spinler * @brief The function called when the command failure retry 232f869fcf8SMatt Spinler * time is up. 233f869fcf8SMatt Spinler * 234f869fcf8SMatt Spinler * It will issue a send of the previous PEL and increment the 235f869fcf8SMatt Spinler * retry count. 236f869fcf8SMatt Spinler */ 237f869fcf8SMatt Spinler void retryTimerExpired(); 238f869fcf8SMatt Spinler 239f869fcf8SMatt Spinler /** 24041293cb8SMatt Spinler * @brief The function called when the 'host full' retry timer 24141293cb8SMatt Spinler * expires. 24241293cb8SMatt Spinler * 24341293cb8SMatt Spinler * This will re-issue a command to try again with the PEL at 24441293cb8SMatt Spinler * the front of the queue. 24541293cb8SMatt Spinler */ 24641293cb8SMatt Spinler void hostFullTimerExpired(); 24741293cb8SMatt Spinler 24841293cb8SMatt Spinler /** 2493019c6fbSMatt Spinler * @brief Stops an in progress command 2503019c6fbSMatt Spinler * 2513019c6fbSMatt Spinler * In progress meaning after the send but before the response. 2523019c6fbSMatt Spinler */ 2533019c6fbSMatt Spinler void stopCommand(); 2543019c6fbSMatt Spinler 2553019c6fbSMatt Spinler /** 256f60ac27eSMatt Spinler * @brief The PEL repository object 257f60ac27eSMatt Spinler */ 258f60ac27eSMatt Spinler Repository& _repo; 259f60ac27eSMatt Spinler 260f60ac27eSMatt Spinler /** 261f60ac27eSMatt Spinler * @brief The data interface object 262f60ac27eSMatt Spinler */ 263f60ac27eSMatt Spinler DataInterfaceBase& _dataIface; 264f60ac27eSMatt Spinler 265f60ac27eSMatt Spinler /** 266f60ac27eSMatt Spinler * @brief Base class pointer for the host command interface 267f60ac27eSMatt Spinler */ 268f60ac27eSMatt Spinler std::unique_ptr<HostInterface> _hostIface; 269f60ac27eSMatt Spinler 270f60ac27eSMatt Spinler /** 271f60ac27eSMatt Spinler * @brief The list of PEL IDs that need to be sent. 272f60ac27eSMatt Spinler */ 273f60ac27eSMatt Spinler std::deque<uint32_t> _pelQueue; 274f869fcf8SMatt Spinler 275f869fcf8SMatt Spinler /** 276f869fcf8SMatt Spinler * @brief The list of IDs that were sent, but not acked yet. 277f869fcf8SMatt Spinler * 278f869fcf8SMatt Spinler * These move back to _pelQueue on a power off. 279f869fcf8SMatt Spinler */ 280f869fcf8SMatt Spinler std::vector<uint32_t> _sentPELs; 281f869fcf8SMatt Spinler 282f869fcf8SMatt Spinler /** 283f869fcf8SMatt Spinler * @brief The ID the PEL where the notification has 284f869fcf8SMatt Spinler * been kicked off but the asynchronous response 285f869fcf8SMatt Spinler * hasn't been received yet. 286f869fcf8SMatt Spinler */ 287f869fcf8SMatt Spinler uint32_t _inProgressPEL = 0; 288f869fcf8SMatt Spinler 289f869fcf8SMatt Spinler /** 290f869fcf8SMatt Spinler * @brief The command retry count 291f869fcf8SMatt Spinler */ 292f869fcf8SMatt Spinler size_t _retryCount = 0; 293f869fcf8SMatt Spinler 294f869fcf8SMatt Spinler /** 29541293cb8SMatt Spinler * @brief Indicates if the host has said it is full and does not 29641293cb8SMatt Spinler * currently have the space for more PELs. 29741293cb8SMatt Spinler */ 29841293cb8SMatt Spinler bool _hostFull = false; 29941293cb8SMatt Spinler 30041293cb8SMatt Spinler /** 301f869fcf8SMatt Spinler * @brief The command retry timer. 302f869fcf8SMatt Spinler */ 303f869fcf8SMatt Spinler sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> _retryTimer; 3047d800a4eSMatt Spinler 3057d800a4eSMatt Spinler /** 30641293cb8SMatt Spinler * @brief The host full timer, used to retry sending a PEL if the host 30741293cb8SMatt Spinler * said it is full. 30841293cb8SMatt Spinler */ 30941293cb8SMatt Spinler sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> _hostFullTimer; 31041293cb8SMatt Spinler 31141293cb8SMatt Spinler /** 3127d800a4eSMatt Spinler * @brief The object used to dispatch a new PEL send from the 3137d800a4eSMatt Spinler * event loop, so the calling function can be returned from 3147d800a4eSMatt Spinler * first. 3157d800a4eSMatt Spinler */ 3167d800a4eSMatt Spinler std::unique_ptr<sdeventplus::source::Defer> _dispatcher; 317f60ac27eSMatt Spinler }; 318f60ac27eSMatt Spinler 319f60ac27eSMatt Spinler } // namespace openpower::pels 320