xref: /openbmc/phosphor-logging/extensions/openpower-pels/host_notifier.hpp (revision 3019c6fb08b99af5e550910f241836e6e46f1c7b)
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>
9f869fcf8SMatt 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      *
99*3019c6fbSMatt Spinler      * If the new state is host up and there are PELs to send, it
100*3019c6fbSMatt Spinler      * will trigger the first command.  If the new state is off, then
101*3019c6fbSMatt Spinler      * it will transfer any PELs that were sent but not acked yet back
102*3019c6fbSMatt Spinler      * to the queue to be sent again.
103*3019c6fbSMatt Spinler      *
104f60ac27eSMatt Spinler      * @param[in] hostUp - The new host state
105f60ac27eSMatt Spinler      */
106f60ac27eSMatt Spinler     void hostStateChange(bool hostUp);
107f60ac27eSMatt Spinler 
108f60ac27eSMatt Spinler     /**
109f60ac27eSMatt Spinler      * @brief The callback function invoked after the asynchronous
110f60ac27eSMatt Spinler      *        PLDM receive function is complete.
111f60ac27eSMatt Spinler      *
112f869fcf8SMatt Spinler      * If the command was successful, the state of that PEL will
113f869fcf8SMatt Spinler      * be set to 'sent', and the next send will be triggered.
114f869fcf8SMatt Spinler      *
115f869fcf8SMatt Spinler      * If the command failed, a retry timer will be started so it
116f869fcf8SMatt Spinler      * can be sent again.
117f869fcf8SMatt Spinler      *
118f60ac27eSMatt Spinler      * @param[in] status - The response status
119f60ac27eSMatt Spinler      */
120f60ac27eSMatt Spinler     void commandResponse(ResponseStatus status);
121f60ac27eSMatt Spinler 
122f60ac27eSMatt Spinler     /**
123f869fcf8SMatt Spinler      * @brief The function called when the command failure retry
124f869fcf8SMatt Spinler      *        time is up.
125f869fcf8SMatt Spinler      *
126f869fcf8SMatt Spinler      * It will issue a send of the previous PEL and increment the
127f869fcf8SMatt Spinler      * retry count.
128f869fcf8SMatt Spinler      */
129f869fcf8SMatt Spinler     void retryTimerExpired();
130f869fcf8SMatt Spinler 
131f869fcf8SMatt Spinler     /**
132*3019c6fbSMatt Spinler      * @brief Stops an in progress command
133*3019c6fbSMatt Spinler      *
134*3019c6fbSMatt Spinler      * In progress meaning after the send but before the response.
135*3019c6fbSMatt Spinler      */
136*3019c6fbSMatt Spinler     void stopCommand();
137*3019c6fbSMatt Spinler 
138*3019c6fbSMatt Spinler     /**
139f60ac27eSMatt Spinler      * @brief The PEL repository object
140f60ac27eSMatt Spinler      */
141f60ac27eSMatt Spinler     Repository& _repo;
142f60ac27eSMatt Spinler 
143f60ac27eSMatt Spinler     /**
144f60ac27eSMatt Spinler      * @brief The data interface object
145f60ac27eSMatt Spinler      */
146f60ac27eSMatt Spinler     DataInterfaceBase& _dataIface;
147f60ac27eSMatt Spinler 
148f60ac27eSMatt Spinler     /**
149f60ac27eSMatt Spinler      * @brief Base class pointer for the host command interface
150f60ac27eSMatt Spinler      */
151f60ac27eSMatt Spinler     std::unique_ptr<HostInterface> _hostIface;
152f60ac27eSMatt Spinler 
153f60ac27eSMatt Spinler     /**
154f60ac27eSMatt Spinler      * @brief The list of PEL IDs that need to be sent.
155f60ac27eSMatt Spinler      */
156f60ac27eSMatt Spinler     std::deque<uint32_t> _pelQueue;
157f869fcf8SMatt Spinler 
158f869fcf8SMatt Spinler     /**
159f869fcf8SMatt Spinler      * @brief The list of IDs that were sent, but not acked yet.
160f869fcf8SMatt Spinler      *
161f869fcf8SMatt Spinler      * These move back to _pelQueue on a power off.
162f869fcf8SMatt Spinler      */
163f869fcf8SMatt Spinler     std::vector<uint32_t> _sentPELs;
164f869fcf8SMatt Spinler 
165f869fcf8SMatt Spinler     /**
166f869fcf8SMatt Spinler      * @brief The ID the PEL where the notification has
167f869fcf8SMatt Spinler      *        been kicked off but the asynchronous response
168f869fcf8SMatt Spinler      *        hasn't been received yet.
169f869fcf8SMatt Spinler      */
170f869fcf8SMatt Spinler     uint32_t _inProgressPEL = 0;
171f869fcf8SMatt Spinler 
172f869fcf8SMatt Spinler     /**
173f869fcf8SMatt Spinler      * @brief The command retry count
174f869fcf8SMatt Spinler      */
175f869fcf8SMatt Spinler     size_t _retryCount = 0;
176f869fcf8SMatt Spinler 
177f869fcf8SMatt Spinler     /**
178f869fcf8SMatt Spinler      * @brief The command retry timer.
179f869fcf8SMatt Spinler      */
180f869fcf8SMatt Spinler     sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> _retryTimer;
181f60ac27eSMatt Spinler };
182f60ac27eSMatt Spinler 
183f60ac27eSMatt Spinler } // namespace openpower::pels
184