blob: 1bb753887f7138afe89f59f367d2d6b774f333c1 [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>
9#include <sdeventplus/utility/timer.hpp>
Matt Spinlerf60ac272019-12-11 13:47:50 -060010
11namespace openpower::pels
12{
13
14/**
15 * @class HostNotifier
16 *
17 * This class handles notifying the host firmware of new PELs.
18 */
19class HostNotifier
20{
21 public:
22 HostNotifier() = delete;
23 HostNotifier(const HostNotifier&) = delete;
24 HostNotifier& operator=(const HostNotifier&) = delete;
25 HostNotifier(HostNotifier&&) = delete;
26 HostNotifier& operator=(HostNotifier&&) = delete;
27
28 /**
29 * @brief Constructor
30 *
31 * @param[in] repo - The PEL repository object
32 * @param[in] dataIface - The data interface object
33 * @param[in] hostIface - The host interface object
34 */
35 HostNotifier(Repository& repo, DataInterfaceBase& dataIface,
36 std::unique_ptr<HostInterface> hostIface);
37
38 /**
39 * @brief Destructor
40 */
41 ~HostNotifier();
42
43 /**
44 * @brief Returns the PEL queue size.
45 *
46 * For testing.
47 *
48 * @return size_t - The queue size
49 */
50 size_t queueSize() const
51 {
52 return _pelQueue.size();
53 }
54
55 /**
56 * @brief Specifies if the PEL needs to go onto the queue to be
57 * set to the host.
58 *
Matt Spinlera943b152019-12-11 14:44:50 -060059 * Only returns false if:
60 * - Already acked by the host (or they didn't like it)
61 * - Hidden and the HMC already got it
62 * - The 'do not report to host' bit is set
63 *
Matt Spinlerf60ac272019-12-11 13:47:50 -060064 * @param[in] id - The PEL ID
65 *
66 * @return bool - If enqueue is required
67 */
68 bool enqueueRequired(uint32_t id) const;
69
70 private:
71 /**
72 * @brief This function gets called by the Repository class
73 * when a new PEL is added to it.
74 *
75 * @param[in] pel - The new PEL
76 */
77 void newLogCallback(const PEL& pel);
78
79 /**
80 * @brief This function runs on every existing PEL at startup
81 * and puts the PEL on the queue to send if necessary.
82 *
83 * @param[in] pel - The PEL
84 *
85 * @return bool - This is an indicator to the Repository::for_each
86 * function to traverse every PEL. Always false.
87 */
88 bool addPELToQueue(const PEL& pel);
89
90 /**
91 * @brief Takes the PEL off the front of the queue and issues
92 * the PLDM send.
93 */
94 void doNewLogNotify();
95
96 /**
97 * @brief Called when the host changes state.
98 *
Matt Spinler3019c6f2019-12-11 15:24:45 -060099 * If the new state is host up and there are PELs to send, it
100 * will trigger the first command. If the new state is off, then
101 * it will transfer any PELs that were sent but not acked yet back
102 * to the queue to be sent again.
103 *
Matt Spinlerf60ac272019-12-11 13:47:50 -0600104 * @param[in] hostUp - The new host state
105 */
106 void hostStateChange(bool hostUp);
107
108 /**
109 * @brief The callback function invoked after the asynchronous
110 * PLDM receive function is complete.
111 *
Matt Spinlerf869fcf2019-12-11 15:02:20 -0600112 * If the command was successful, the state of that PEL will
113 * be set to 'sent', and the next send will be triggered.
114 *
115 * If the command failed, a retry timer will be started so it
116 * can be sent again.
117 *
Matt Spinlerf60ac272019-12-11 13:47:50 -0600118 * @param[in] status - The response status
119 */
120 void commandResponse(ResponseStatus status);
121
122 /**
Matt Spinlerf869fcf2019-12-11 15:02:20 -0600123 * @brief The function called when the command failure retry
124 * time is up.
125 *
126 * It will issue a send of the previous PEL and increment the
127 * retry count.
128 */
129 void retryTimerExpired();
130
131 /**
Matt Spinler3019c6f2019-12-11 15:24:45 -0600132 * @brief Stops an in progress command
133 *
134 * In progress meaning after the send but before the response.
135 */
136 void stopCommand();
137
138 /**
Matt Spinlerf60ac272019-12-11 13:47:50 -0600139 * @brief The PEL repository object
140 */
141 Repository& _repo;
142
143 /**
144 * @brief The data interface object
145 */
146 DataInterfaceBase& _dataIface;
147
148 /**
149 * @brief Base class pointer for the host command interface
150 */
151 std::unique_ptr<HostInterface> _hostIface;
152
153 /**
154 * @brief The list of PEL IDs that need to be sent.
155 */
156 std::deque<uint32_t> _pelQueue;
Matt Spinlerf869fcf2019-12-11 15:02:20 -0600157
158 /**
159 * @brief The list of IDs that were sent, but not acked yet.
160 *
161 * These move back to _pelQueue on a power off.
162 */
163 std::vector<uint32_t> _sentPELs;
164
165 /**
166 * @brief The ID the PEL where the notification has
167 * been kicked off but the asynchronous response
168 * hasn't been received yet.
169 */
170 uint32_t _inProgressPEL = 0;
171
172 /**
173 * @brief The command retry count
174 */
175 size_t _retryCount = 0;
176
177 /**
178 * @brief The command retry timer.
179 */
180 sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> _retryTimer;
Matt Spinlerf60ac272019-12-11 13:47:50 -0600181};
182
183} // namespace openpower::pels