xref: /openbmc/phosphor-logging/extensions/openpower-pels/host_notifier.hpp (revision 7d800a4e5d1305fa64ce02b99b0ec522bc454bbd)
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>
9*7d800a4eSMatt 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.
19f60ac27eSMatt Spinler  */
20f60ac27eSMatt Spinler class HostNotifier
21f60ac27eSMatt Spinler {
22f60ac27eSMatt Spinler   public:
23f60ac27eSMatt Spinler     HostNotifier() = delete;
24f60ac27eSMatt Spinler     HostNotifier(const HostNotifier&) = delete;
25f60ac27eSMatt Spinler     HostNotifier& operator=(const HostNotifier&) = delete;
26f60ac27eSMatt Spinler     HostNotifier(HostNotifier&&) = delete;
27f60ac27eSMatt Spinler     HostNotifier& operator=(HostNotifier&&) = delete;
28f60ac27eSMatt Spinler 
29f60ac27eSMatt Spinler     /**
30f60ac27eSMatt Spinler      * @brief Constructor
31f60ac27eSMatt Spinler      *
32f60ac27eSMatt Spinler      * @param[in] repo - The PEL repository object
33f60ac27eSMatt Spinler      * @param[in] dataIface - The data interface object
34f60ac27eSMatt Spinler      * @param[in] hostIface - The host interface object
35f60ac27eSMatt Spinler      */
36f60ac27eSMatt Spinler     HostNotifier(Repository& repo, DataInterfaceBase& dataIface,
37f60ac27eSMatt Spinler                  std::unique_ptr<HostInterface> hostIface);
38f60ac27eSMatt Spinler 
39f60ac27eSMatt Spinler     /**
40f60ac27eSMatt Spinler      * @brief Destructor
41f60ac27eSMatt Spinler      */
42f60ac27eSMatt Spinler     ~HostNotifier();
43f60ac27eSMatt Spinler 
44f60ac27eSMatt Spinler     /**
45f60ac27eSMatt Spinler      * @brief Returns the PEL queue size.
46f60ac27eSMatt Spinler      *
47f60ac27eSMatt Spinler      * For testing.
48f60ac27eSMatt Spinler      *
49f60ac27eSMatt Spinler      * @return size_t - The queue size
50f60ac27eSMatt Spinler      */
51f60ac27eSMatt Spinler     size_t queueSize() const
52f60ac27eSMatt Spinler     {
53f60ac27eSMatt Spinler         return _pelQueue.size();
54f60ac27eSMatt Spinler     }
55f60ac27eSMatt Spinler 
56f60ac27eSMatt Spinler     /**
57f60ac27eSMatt Spinler      * @brief Specifies if the PEL needs to go onto the queue to be
58f60ac27eSMatt Spinler      *        set to the host.
59f60ac27eSMatt Spinler      *
60a943b15bSMatt Spinler      * Only returns false if:
61a943b15bSMatt Spinler      *  - Already acked by the host (or they didn't like it)
62a943b15bSMatt Spinler      *  - Hidden and the HMC already got it
63a943b15bSMatt Spinler      *  - The 'do not report to host' bit is set
64a943b15bSMatt Spinler      *
65f60ac27eSMatt Spinler      * @param[in] id - The PEL ID
66f60ac27eSMatt Spinler      *
67f60ac27eSMatt Spinler      * @return bool - If enqueue is required
68f60ac27eSMatt Spinler      */
69f60ac27eSMatt Spinler     bool enqueueRequired(uint32_t id) const;
70f60ac27eSMatt Spinler 
71f77debb9SMatt Spinler     /**
72f77debb9SMatt Spinler      * @brief If the host still needs to be notified of the PEL
73f77debb9SMatt Spinler      *        at the time of the notification.
74f77debb9SMatt Spinler      *
75f77debb9SMatt Spinler      * Only returns false if:
76f77debb9SMatt Spinler      *  - Already acked by the host
77f77debb9SMatt Spinler      *  - It's hidden, and the HMC already got or will get it.
78f77debb9SMatt Spinler      *
79f77debb9SMatt Spinler      * @param[in] id - The PEL ID
80f77debb9SMatt Spinler      *
81f77debb9SMatt Spinler      * @return bool - If the notify is required
82f77debb9SMatt Spinler      */
83f77debb9SMatt Spinler     bool notifyRequired(uint32_t id) const;
84f77debb9SMatt Spinler 
85f60ac27eSMatt Spinler   private:
86f60ac27eSMatt Spinler     /**
87f60ac27eSMatt Spinler      * @brief This function gets called by the Repository class
88f60ac27eSMatt Spinler      *        when a new PEL is added to it.
89f60ac27eSMatt Spinler      *
90*7d800a4eSMatt Spinler      * This function puts the PEL on the queue to be sent up if it
91*7d800a4eSMatt Spinler      * needs it, and possibly dispatch the send if the conditions call
92*7d800a4eSMatt Spinler      * for it.
93*7d800a4eSMatt Spinler      *
94f60ac27eSMatt Spinler      * @param[in] pel - The new PEL
95f60ac27eSMatt Spinler      */
96f60ac27eSMatt Spinler     void newLogCallback(const PEL& pel);
97f60ac27eSMatt Spinler 
98f60ac27eSMatt Spinler     /**
99f60ac27eSMatt Spinler      * @brief This function runs on every existing PEL at startup
100f60ac27eSMatt Spinler      *        and puts the PEL on the queue to send if necessary.
101f60ac27eSMatt Spinler      *
102f60ac27eSMatt Spinler      * @param[in] pel - The PEL
103f60ac27eSMatt Spinler      *
104f60ac27eSMatt Spinler      * @return bool - This is an indicator to the Repository::for_each
105f60ac27eSMatt Spinler      *                function to traverse every PEL.  Always false.
106f60ac27eSMatt Spinler      */
107f60ac27eSMatt Spinler     bool addPELToQueue(const PEL& pel);
108f60ac27eSMatt Spinler 
109f60ac27eSMatt Spinler     /**
110f77debb9SMatt Spinler      * @brief Takes the first PEL from the queue that needs to be
111f77debb9SMatt Spinler      *        sent, and issues the send if conditions are right.
112f60ac27eSMatt Spinler      */
113f60ac27eSMatt Spinler     void doNewLogNotify();
114f60ac27eSMatt Spinler 
115f60ac27eSMatt Spinler     /**
116*7d800a4eSMatt Spinler      * @brief Creates the event object to handle sending the PLDM
117*7d800a4eSMatt Spinler      *        command from the event loop.
118*7d800a4eSMatt Spinler      */
119*7d800a4eSMatt Spinler     void scheduleDispatch();
120*7d800a4eSMatt Spinler 
121*7d800a4eSMatt Spinler     /**
122*7d800a4eSMatt Spinler      * @brief Kicks off the PLDM send, but called from the event
123*7d800a4eSMatt Spinler      *        loop.
124*7d800a4eSMatt Spinler      *
125*7d800a4eSMatt Spinler      * @param[in] source - The event source object
126*7d800a4eSMatt Spinler      */
127*7d800a4eSMatt Spinler     void dispatch(sdeventplus::source::EventBase& source);
128*7d800a4eSMatt Spinler 
129*7d800a4eSMatt Spinler     /**
130f60ac27eSMatt Spinler      * @brief Called when the host changes state.
131f60ac27eSMatt Spinler      *
1323019c6fbSMatt Spinler      * If the new state is host up and there are PELs to send, it
1333019c6fbSMatt Spinler      * will trigger the first command.  If the new state is off, then
1343019c6fbSMatt Spinler      * it will transfer any PELs that were sent but not acked yet back
1353019c6fbSMatt Spinler      * to the queue to be sent again.
1363019c6fbSMatt Spinler      *
137f60ac27eSMatt Spinler      * @param[in] hostUp - The new host state
138f60ac27eSMatt Spinler      */
139f60ac27eSMatt Spinler     void hostStateChange(bool hostUp);
140f60ac27eSMatt Spinler 
141f60ac27eSMatt Spinler     /**
142f60ac27eSMatt Spinler      * @brief The callback function invoked after the asynchronous
143f60ac27eSMatt Spinler      *        PLDM receive function is complete.
144f60ac27eSMatt Spinler      *
145f869fcf8SMatt Spinler      * If the command was successful, the state of that PEL will
146f869fcf8SMatt Spinler      * be set to 'sent', and the next send will be triggered.
147f869fcf8SMatt Spinler      *
148f869fcf8SMatt Spinler      * If the command failed, a retry timer will be started so it
149f869fcf8SMatt Spinler      * can be sent again.
150f869fcf8SMatt Spinler      *
151f60ac27eSMatt Spinler      * @param[in] status - The response status
152f60ac27eSMatt Spinler      */
153f60ac27eSMatt Spinler     void commandResponse(ResponseStatus status);
154f60ac27eSMatt Spinler 
155f60ac27eSMatt Spinler     /**
156f869fcf8SMatt Spinler      * @brief The function called when the command failure retry
157f869fcf8SMatt Spinler      *        time is up.
158f869fcf8SMatt Spinler      *
159f869fcf8SMatt Spinler      * It will issue a send of the previous PEL and increment the
160f869fcf8SMatt Spinler      * retry count.
161f869fcf8SMatt Spinler      */
162f869fcf8SMatt Spinler     void retryTimerExpired();
163f869fcf8SMatt Spinler 
164f869fcf8SMatt Spinler     /**
1653019c6fbSMatt Spinler      * @brief Stops an in progress command
1663019c6fbSMatt Spinler      *
1673019c6fbSMatt Spinler      * In progress meaning after the send but before the response.
1683019c6fbSMatt Spinler      */
1693019c6fbSMatt Spinler     void stopCommand();
1703019c6fbSMatt Spinler 
1713019c6fbSMatt Spinler     /**
172f60ac27eSMatt Spinler      * @brief The PEL repository object
173f60ac27eSMatt Spinler      */
174f60ac27eSMatt Spinler     Repository& _repo;
175f60ac27eSMatt Spinler 
176f60ac27eSMatt Spinler     /**
177f60ac27eSMatt Spinler      * @brief The data interface object
178f60ac27eSMatt Spinler      */
179f60ac27eSMatt Spinler     DataInterfaceBase& _dataIface;
180f60ac27eSMatt Spinler 
181f60ac27eSMatt Spinler     /**
182f60ac27eSMatt Spinler      * @brief Base class pointer for the host command interface
183f60ac27eSMatt Spinler      */
184f60ac27eSMatt Spinler     std::unique_ptr<HostInterface> _hostIface;
185f60ac27eSMatt Spinler 
186f60ac27eSMatt Spinler     /**
187f60ac27eSMatt Spinler      * @brief The list of PEL IDs that need to be sent.
188f60ac27eSMatt Spinler      */
189f60ac27eSMatt Spinler     std::deque<uint32_t> _pelQueue;
190f869fcf8SMatt Spinler 
191f869fcf8SMatt Spinler     /**
192f869fcf8SMatt Spinler      * @brief The list of IDs that were sent, but not acked yet.
193f869fcf8SMatt Spinler      *
194f869fcf8SMatt Spinler      * These move back to _pelQueue on a power off.
195f869fcf8SMatt Spinler      */
196f869fcf8SMatt Spinler     std::vector<uint32_t> _sentPELs;
197f869fcf8SMatt Spinler 
198f869fcf8SMatt Spinler     /**
199f869fcf8SMatt Spinler      * @brief The ID the PEL where the notification has
200f869fcf8SMatt Spinler      *        been kicked off but the asynchronous response
201f869fcf8SMatt Spinler      *        hasn't been received yet.
202f869fcf8SMatt Spinler      */
203f869fcf8SMatt Spinler     uint32_t _inProgressPEL = 0;
204f869fcf8SMatt Spinler 
205f869fcf8SMatt Spinler     /**
206f869fcf8SMatt Spinler      * @brief The command retry count
207f869fcf8SMatt Spinler      */
208f869fcf8SMatt Spinler     size_t _retryCount = 0;
209f869fcf8SMatt Spinler 
210f869fcf8SMatt Spinler     /**
211f869fcf8SMatt Spinler      * @brief The command retry timer.
212f869fcf8SMatt Spinler      */
213f869fcf8SMatt Spinler     sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> _retryTimer;
214*7d800a4eSMatt Spinler 
215*7d800a4eSMatt Spinler     /**
216*7d800a4eSMatt Spinler      * @brief The object used to dispatch a new PEL send from the
217*7d800a4eSMatt Spinler      *        event loop, so the calling function can be returned from
218*7d800a4eSMatt Spinler      *        first.
219*7d800a4eSMatt Spinler      */
220*7d800a4eSMatt Spinler     std::unique_ptr<sdeventplus::source::Defer> _dispatcher;
221f60ac27eSMatt Spinler };
222f60ac27eSMatt Spinler 
223f60ac27eSMatt Spinler } // namespace openpower::pels
224