blob: 3e50c836345edc5e785c214b4eb94d61c7f6a302 [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 Spinlerf60ac272019-12-11 13:47:50 -060085 private:
86 /**
87 * @brief This function gets called by the Repository class
88 * when a new PEL is added to it.
89 *
Matt Spinler7d800a42019-12-12 10:35:01 -060090 * This function puts the PEL on the queue to be sent up if it
91 * needs it, and possibly dispatch the send if the conditions call
92 * for it.
93 *
Matt Spinlerf60ac272019-12-11 13:47:50 -060094 * @param[in] pel - The new PEL
95 */
96 void newLogCallback(const PEL& pel);
97
98 /**
99 * @brief This function runs on every existing PEL at startup
100 * and puts the PEL on the queue to send if necessary.
101 *
102 * @param[in] pel - The PEL
103 *
104 * @return bool - This is an indicator to the Repository::for_each
105 * function to traverse every PEL. Always false.
106 */
107 bool addPELToQueue(const PEL& pel);
108
109 /**
Matt Spinlerf77debb2019-12-12 10:04:33 -0600110 * @brief Takes the first PEL from the queue that needs to be
111 * sent, and issues the send if conditions are right.
Matt Spinlerf60ac272019-12-11 13:47:50 -0600112 */
113 void doNewLogNotify();
114
115 /**
Matt Spinler7d800a42019-12-12 10:35:01 -0600116 * @brief Creates the event object to handle sending the PLDM
117 * command from the event loop.
118 */
119 void scheduleDispatch();
120
121 /**
122 * @brief Kicks off the PLDM send, but called from the event
123 * loop.
124 *
125 * @param[in] source - The event source object
126 */
127 void dispatch(sdeventplus::source::EventBase& source);
128
129 /**
Matt Spinlerf60ac272019-12-11 13:47:50 -0600130 * @brief Called when the host changes state.
131 *
Matt Spinler3019c6f2019-12-11 15:24:45 -0600132 * If the new state is host up and there are PELs to send, it
133 * will trigger the first command. If the new state is off, then
134 * it will transfer any PELs that were sent but not acked yet back
135 * to the queue to be sent again.
136 *
Matt Spinlerf60ac272019-12-11 13:47:50 -0600137 * @param[in] hostUp - The new host state
138 */
139 void hostStateChange(bool hostUp);
140
141 /**
142 * @brief The callback function invoked after the asynchronous
143 * PLDM receive function is complete.
144 *
Matt Spinlerf869fcf2019-12-11 15:02:20 -0600145 * If the command was successful, the state of that PEL will
146 * be set to 'sent', and the next send will be triggered.
147 *
148 * If the command failed, a retry timer will be started so it
149 * can be sent again.
150 *
Matt Spinlerf60ac272019-12-11 13:47:50 -0600151 * @param[in] status - The response status
152 */
153 void commandResponse(ResponseStatus status);
154
155 /**
Matt Spinlerf869fcf2019-12-11 15:02:20 -0600156 * @brief The function called when the command failure retry
157 * time is up.
158 *
159 * It will issue a send of the previous PEL and increment the
160 * retry count.
161 */
162 void retryTimerExpired();
163
164 /**
Matt Spinler3019c6f2019-12-11 15:24:45 -0600165 * @brief Stops an in progress command
166 *
167 * In progress meaning after the send but before the response.
168 */
169 void stopCommand();
170
171 /**
Matt Spinlerf60ac272019-12-11 13:47:50 -0600172 * @brief The PEL repository object
173 */
174 Repository& _repo;
175
176 /**
177 * @brief The data interface object
178 */
179 DataInterfaceBase& _dataIface;
180
181 /**
182 * @brief Base class pointer for the host command interface
183 */
184 std::unique_ptr<HostInterface> _hostIface;
185
186 /**
187 * @brief The list of PEL IDs that need to be sent.
188 */
189 std::deque<uint32_t> _pelQueue;
Matt Spinlerf869fcf2019-12-11 15:02:20 -0600190
191 /**
192 * @brief The list of IDs that were sent, but not acked yet.
193 *
194 * These move back to _pelQueue on a power off.
195 */
196 std::vector<uint32_t> _sentPELs;
197
198 /**
199 * @brief The ID the PEL where the notification has
200 * been kicked off but the asynchronous response
201 * hasn't been received yet.
202 */
203 uint32_t _inProgressPEL = 0;
204
205 /**
206 * @brief The command retry count
207 */
208 size_t _retryCount = 0;
209
210 /**
211 * @brief The command retry timer.
212 */
213 sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> _retryTimer;
Matt Spinler7d800a42019-12-12 10:35:01 -0600214
215 /**
216 * @brief The object used to dispatch a new PEL send from the
217 * event loop, so the calling function can be returned from
218 * first.
219 */
220 std::unique_ptr<sdeventplus::source::Defer> _dispatcher;
Matt Spinlerf60ac272019-12-11 13:47:50 -0600221};
222
223} // namespace openpower::pels