blob: d160dd483acdd446e8abf0c5459296b9cd0c3cbe [file] [log] [blame]
Matt Spinlerf60ac272019-12-11 13:47:50 -06001#pragma once
2
3#include "host_interface.hpp"
4#include "pel.hpp"
5#include "repository.hpp"
6
7#include <deque>
Matt Spinlerf869fcf2019-12-11 15:02:20 -06008#include <sdeventplus/clock.hpp>
Matt Spinler7d800a42019-12-12 10:35:01 -06009#include <sdeventplus/source/event.hpp>
Matt Spinlerf869fcf2019-12-11 15:02:20 -060010#include <sdeventplus/utility/timer.hpp>
Matt Spinlerf60ac272019-12-11 13:47:50 -060011
12namespace openpower::pels
13{
14
15/**
16 * @class HostNotifier
17 *
18 * This class handles notifying the host firmware of new PELs.
19 */
20class HostNotifier
21{
22 public:
23 HostNotifier() = delete;
24 HostNotifier(const HostNotifier&) = delete;
25 HostNotifier& operator=(const HostNotifier&) = delete;
26 HostNotifier(HostNotifier&&) = delete;
27 HostNotifier& operator=(HostNotifier&&) = delete;
28
29 /**
30 * @brief Constructor
31 *
32 * @param[in] repo - The PEL repository object
33 * @param[in] dataIface - The data interface object
34 * @param[in] hostIface - The host interface object
35 */
36 HostNotifier(Repository& repo, DataInterfaceBase& dataIface,
37 std::unique_ptr<HostInterface> hostIface);
38
39 /**
40 * @brief Destructor
41 */
42 ~HostNotifier();
43
44 /**
45 * @brief Returns the PEL queue size.
46 *
47 * For testing.
48 *
49 * @return size_t - The queue size
50 */
51 size_t queueSize() const
52 {
53 return _pelQueue.size();
54 }
55
56 /**
57 * @brief Specifies if the PEL needs to go onto the queue to be
58 * set to the host.
59 *
Matt Spinlera943b152019-12-11 14:44:50 -060060 * Only returns false if:
61 * - Already acked by the host (or they didn't like it)
62 * - Hidden and the HMC already got it
63 * - The 'do not report to host' bit is set
64 *
Matt Spinlerf60ac272019-12-11 13:47:50 -060065 * @param[in] id - The PEL ID
66 *
67 * @return bool - If enqueue is required
68 */
69 bool enqueueRequired(uint32_t id) const;
70
Matt Spinlerf77debb2019-12-12 10:04:33 -060071 /**
72 * @brief If the host still needs to be notified of the PEL
73 * at the time of the notification.
74 *
75 * Only returns false if:
76 * - Already acked by the host
77 * - It's hidden, and the HMC already got or will get it.
78 *
79 * @param[in] id - The PEL ID
80 *
81 * @return bool - If the notify is required
82 */
83 bool notifyRequired(uint32_t id) const;
84
Matt Spinlercc3b64a2019-12-12 11:27:10 -060085 /**
86 * @brief Called when the host sends the 'ack' PLDM command.
87 *
88 * This means the PEL never needs to be sent up again.
89 *
90 * @param[in] id - The PEL ID
91 */
92 void ackPEL(uint32_t id);
93
Matt Spinlerf60ac272019-12-11 13:47:50 -060094 private:
95 /**
96 * @brief This function gets called by the Repository class
97 * when a new PEL is added to it.
98 *
Matt Spinler7d800a42019-12-12 10:35:01 -060099 * This function puts the PEL on the queue to be sent up if it
100 * needs it, and possibly dispatch the send if the conditions call
101 * for it.
102 *
Matt Spinlerf60ac272019-12-11 13:47:50 -0600103 * @param[in] pel - The new PEL
104 */
105 void newLogCallback(const PEL& pel);
106
107 /**
108 * @brief This function runs on every existing PEL at startup
109 * and puts the PEL on the queue to send if necessary.
110 *
111 * @param[in] pel - The PEL
112 *
113 * @return bool - This is an indicator to the Repository::for_each
114 * function to traverse every PEL. Always false.
115 */
116 bool addPELToQueue(const PEL& pel);
117
118 /**
Matt Spinlerf77debb2019-12-12 10:04:33 -0600119 * @brief Takes the first PEL from the queue that needs to be
120 * sent, and issues the send if conditions are right.
Matt Spinlerf60ac272019-12-11 13:47:50 -0600121 */
122 void doNewLogNotify();
123
124 /**
Matt Spinler7d800a42019-12-12 10:35:01 -0600125 * @brief Creates the event object to handle sending the PLDM
126 * command from the event loop.
127 */
128 void scheduleDispatch();
129
130 /**
131 * @brief Kicks off the PLDM send, but called from the event
132 * loop.
133 *
134 * @param[in] source - The event source object
135 */
136 void dispatch(sdeventplus::source::EventBase& source);
137
138 /**
Matt Spinlerf60ac272019-12-11 13:47:50 -0600139 * @brief Called when the host changes state.
140 *
Matt Spinler3019c6f2019-12-11 15:24:45 -0600141 * If the new state is host up and there are PELs to send, it
142 * will trigger the first command. If the new state is off, then
143 * it will transfer any PELs that were sent but not acked yet back
144 * to the queue to be sent again.
145 *
Matt Spinlerf60ac272019-12-11 13:47:50 -0600146 * @param[in] hostUp - The new host state
147 */
148 void hostStateChange(bool hostUp);
149
150 /**
151 * @brief The callback function invoked after the asynchronous
152 * PLDM receive function is complete.
153 *
Matt Spinlerf869fcf2019-12-11 15:02:20 -0600154 * If the command was successful, the state of that PEL will
155 * be set to 'sent', and the next send will be triggered.
156 *
157 * If the command failed, a retry timer will be started so it
158 * can be sent again.
159 *
Matt Spinlerf60ac272019-12-11 13:47:50 -0600160 * @param[in] status - The response status
161 */
162 void commandResponse(ResponseStatus status);
163
164 /**
Matt Spinlerf869fcf2019-12-11 15:02:20 -0600165 * @brief The function called when the command failure retry
166 * time is up.
167 *
168 * It will issue a send of the previous PEL and increment the
169 * retry count.
170 */
171 void retryTimerExpired();
172
173 /**
Matt Spinler3019c6f2019-12-11 15:24:45 -0600174 * @brief Stops an in progress command
175 *
176 * In progress meaning after the send but before the response.
177 */
178 void stopCommand();
179
180 /**
Matt Spinlerf60ac272019-12-11 13:47:50 -0600181 * @brief The PEL repository object
182 */
183 Repository& _repo;
184
185 /**
186 * @brief The data interface object
187 */
188 DataInterfaceBase& _dataIface;
189
190 /**
191 * @brief Base class pointer for the host command interface
192 */
193 std::unique_ptr<HostInterface> _hostIface;
194
195 /**
196 * @brief The list of PEL IDs that need to be sent.
197 */
198 std::deque<uint32_t> _pelQueue;
Matt Spinlerf869fcf2019-12-11 15:02:20 -0600199
200 /**
201 * @brief The list of IDs that were sent, but not acked yet.
202 *
203 * These move back to _pelQueue on a power off.
204 */
205 std::vector<uint32_t> _sentPELs;
206
207 /**
208 * @brief The ID the PEL where the notification has
209 * been kicked off but the asynchronous response
210 * hasn't been received yet.
211 */
212 uint32_t _inProgressPEL = 0;
213
214 /**
215 * @brief The command retry count
216 */
217 size_t _retryCount = 0;
218
219 /**
220 * @brief The command retry timer.
221 */
222 sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> _retryTimer;
Matt Spinler7d800a42019-12-12 10:35:01 -0600223
224 /**
225 * @brief The object used to dispatch a new PEL send from the
226 * event loop, so the calling function can be returned from
227 * first.
228 */
229 std::unique_ptr<sdeventplus::source::Defer> _dispatcher;
Matt Spinlerf60ac272019-12-11 13:47:50 -0600230};
231
232} // namespace openpower::pels