blob: 8436e06fd6aecd4c71accd190ae82d8fb6e85006 [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 *
99 * @param[in] hostUp - The new host state
100 */
101 void hostStateChange(bool hostUp);
102
103 /**
104 * @brief The callback function invoked after the asynchronous
105 * PLDM receive function is complete.
106 *
Matt Spinlerf869fcf2019-12-11 15:02:20 -0600107 * If the command was successful, the state of that PEL will
108 * be set to 'sent', and the next send will be triggered.
109 *
110 * If the command failed, a retry timer will be started so it
111 * can be sent again.
112 *
Matt Spinlerf60ac272019-12-11 13:47:50 -0600113 * @param[in] status - The response status
114 */
115 void commandResponse(ResponseStatus status);
116
117 /**
Matt Spinlerf869fcf2019-12-11 15:02:20 -0600118 * @brief The function called when the command failure retry
119 * time is up.
120 *
121 * It will issue a send of the previous PEL and increment the
122 * retry count.
123 */
124 void retryTimerExpired();
125
126 /**
Matt Spinlerf60ac272019-12-11 13:47:50 -0600127 * @brief The PEL repository object
128 */
129 Repository& _repo;
130
131 /**
132 * @brief The data interface object
133 */
134 DataInterfaceBase& _dataIface;
135
136 /**
137 * @brief Base class pointer for the host command interface
138 */
139 std::unique_ptr<HostInterface> _hostIface;
140
141 /**
142 * @brief The list of PEL IDs that need to be sent.
143 */
144 std::deque<uint32_t> _pelQueue;
Matt Spinlerf869fcf2019-12-11 15:02:20 -0600145
146 /**
147 * @brief The list of IDs that were sent, but not acked yet.
148 *
149 * These move back to _pelQueue on a power off.
150 */
151 std::vector<uint32_t> _sentPELs;
152
153 /**
154 * @brief The ID the PEL where the notification has
155 * been kicked off but the asynchronous response
156 * hasn't been received yet.
157 */
158 uint32_t _inProgressPEL = 0;
159
160 /**
161 * @brief The command retry count
162 */
163 size_t _retryCount = 0;
164
165 /**
166 * @brief The command retry timer.
167 */
168 sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> _retryTimer;
Matt Spinlerf60ac272019-12-11 13:47:50 -0600169};
170
171} // namespace openpower::pels