1f60ac27eSMatt Spinler /**
2f60ac27eSMatt Spinler  * Copyright © 2019 IBM Corporation
3f60ac27eSMatt Spinler  *
4f60ac27eSMatt Spinler  * Licensed under the Apache License, Version 2.0 (the "License");
5f60ac27eSMatt Spinler  * you may not use this file except in compliance with the License.
6f60ac27eSMatt Spinler  * You may obtain a copy of the License at
7f60ac27eSMatt Spinler  *
8f60ac27eSMatt Spinler  *     http://www.apache.org/licenses/LICENSE-2.0
9f60ac27eSMatt Spinler  *
10f60ac27eSMatt Spinler  * Unless required by applicable law or agreed to in writing, software
11f60ac27eSMatt Spinler  * distributed under the License is distributed on an "AS IS" BASIS,
12f60ac27eSMatt Spinler  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13f60ac27eSMatt Spinler  * See the License for the specific language governing permissions and
14f60ac27eSMatt Spinler  * limitations under the License.
15f60ac27eSMatt Spinler  */
16f60ac27eSMatt Spinler #include "host_notifier.hpp"
17f60ac27eSMatt Spinler 
18f60ac27eSMatt Spinler #include <phosphor-logging/log.hpp>
19f60ac27eSMatt Spinler 
20f60ac27eSMatt Spinler namespace openpower::pels
21f60ac27eSMatt Spinler {
22f60ac27eSMatt Spinler 
23f60ac27eSMatt Spinler const auto subscriptionName = "PELHostNotifier";
24f77debb9SMatt Spinler const size_t maxRetryAttempts = 15;
25f60ac27eSMatt Spinler 
26f60ac27eSMatt Spinler using namespace phosphor::logging;
27f60ac27eSMatt Spinler 
28f60ac27eSMatt Spinler HostNotifier::HostNotifier(Repository& repo, DataInterfaceBase& dataIface,
29f60ac27eSMatt Spinler                            std::unique_ptr<HostInterface> hostIface) :
30f60ac27eSMatt Spinler     _repo(repo),
31f869fcf8SMatt Spinler     _dataIface(dataIface), _hostIface(std::move(hostIface)),
32f869fcf8SMatt Spinler     _retryTimer(_hostIface->getEvent(),
3341293cb8SMatt Spinler                 std::bind(std::mem_fn(&HostNotifier::retryTimerExpired), this)),
3441293cb8SMatt Spinler     _hostFullTimer(
3541293cb8SMatt Spinler         _hostIface->getEvent(),
3641293cb8SMatt Spinler         std::bind(std::mem_fn(&HostNotifier::hostFullTimerExpired), this))
37f60ac27eSMatt Spinler {
38f60ac27eSMatt Spinler     // Subscribe to be told about new PELs.
39f60ac27eSMatt Spinler     _repo.subscribeToAdds(subscriptionName,
40f60ac27eSMatt Spinler                           std::bind(std::mem_fn(&HostNotifier::newLogCallback),
41f60ac27eSMatt Spinler                                     this, std::placeholders::_1));
42f60ac27eSMatt Spinler 
43f60ac27eSMatt Spinler     // Add any existing PELs to the queue to send them if necessary.
44f60ac27eSMatt Spinler     _repo.for_each(std::bind(std::mem_fn(&HostNotifier::addPELToQueue), this,
45f60ac27eSMatt Spinler                              std::placeholders::_1));
46f60ac27eSMatt Spinler 
47f60ac27eSMatt Spinler     // Subscribe to be told about host state changes.
48f60ac27eSMatt Spinler     _dataIface.subscribeToHostStateChange(
49f60ac27eSMatt Spinler         subscriptionName,
50f60ac27eSMatt Spinler         std::bind(std::mem_fun(&HostNotifier::hostStateChange), this,
51f60ac27eSMatt Spinler                   std::placeholders::_1));
52f60ac27eSMatt Spinler 
53f60ac27eSMatt Spinler     // Set the function to call when the async reponse is received.
54f60ac27eSMatt Spinler     _hostIface->setResponseFunction(
55f60ac27eSMatt Spinler         std::bind(std::mem_fn(&HostNotifier::commandResponse), this,
56f60ac27eSMatt Spinler                   std::placeholders::_1));
57f60ac27eSMatt Spinler 
58f60ac27eSMatt Spinler     // Start sending logs if the host is running
59f60ac27eSMatt Spinler     if (!_pelQueue.empty() && _dataIface.isHostUp())
60f60ac27eSMatt Spinler     {
61f60ac27eSMatt Spinler         doNewLogNotify();
62f60ac27eSMatt Spinler     }
63f60ac27eSMatt Spinler }
64f60ac27eSMatt Spinler 
65f60ac27eSMatt Spinler HostNotifier::~HostNotifier()
66f60ac27eSMatt Spinler {
67f60ac27eSMatt Spinler     _repo.unsubscribeFromAdds(subscriptionName);
68f60ac27eSMatt Spinler     _dataIface.unsubscribeFromHostStateChange(subscriptionName);
69f60ac27eSMatt Spinler }
70f60ac27eSMatt Spinler 
71f60ac27eSMatt Spinler bool HostNotifier::addPELToQueue(const PEL& pel)
72f60ac27eSMatt Spinler {
73f60ac27eSMatt Spinler     if (enqueueRequired(pel.id()))
74f60ac27eSMatt Spinler     {
75f60ac27eSMatt Spinler         _pelQueue.push_back(pel.id());
76f60ac27eSMatt Spinler     }
77f60ac27eSMatt Spinler 
78f60ac27eSMatt Spinler     // Return false so that Repo::for_each keeps going.
79f60ac27eSMatt Spinler     return false;
80f60ac27eSMatt Spinler }
81f60ac27eSMatt Spinler 
82f60ac27eSMatt Spinler bool HostNotifier::enqueueRequired(uint32_t id) const
83f60ac27eSMatt Spinler {
84f60ac27eSMatt Spinler     bool required = true;
85a943b15bSMatt Spinler     Repository::LogID i{Repository::LogID::Pel{id}};
86a943b15bSMatt Spinler 
87*24a8558bSMatt Spinler     // Manufacturing testing may turn off sending up PELs
88*24a8558bSMatt Spinler     if (!_dataIface.getHostPELEnablement())
89*24a8558bSMatt Spinler     {
90*24a8558bSMatt Spinler         return false;
91*24a8558bSMatt Spinler     }
92*24a8558bSMatt Spinler 
93a943b15bSMatt Spinler     if (auto attributes = _repo.getPELAttributes(i); attributes)
94a943b15bSMatt Spinler     {
95a943b15bSMatt Spinler         auto a = attributes.value().get();
96a943b15bSMatt Spinler 
97a943b15bSMatt Spinler         if ((a.hostState == TransmissionState::acked) ||
98a943b15bSMatt Spinler             (a.hostState == TransmissionState::badPEL))
99a943b15bSMatt Spinler         {
100a943b15bSMatt Spinler             required = false;
101a943b15bSMatt Spinler         }
102a943b15bSMatt Spinler         else if (a.actionFlags.test(hiddenFlagBit) &&
103a943b15bSMatt Spinler                  (a.hmcState == TransmissionState::acked))
104a943b15bSMatt Spinler         {
105a943b15bSMatt Spinler             required = false;
106a943b15bSMatt Spinler         }
107a943b15bSMatt Spinler         else if (a.actionFlags.test(dontReportToHostFlagBit))
108a943b15bSMatt Spinler         {
109a943b15bSMatt Spinler             required = false;
110a943b15bSMatt Spinler         }
111a943b15bSMatt Spinler     }
112a943b15bSMatt Spinler     else
113a943b15bSMatt Spinler     {
114a943b15bSMatt Spinler         using namespace phosphor::logging;
115a943b15bSMatt Spinler         log<level::ERR>("Host Enqueue: Unable to find PEL ID in repository",
116a943b15bSMatt Spinler                         entry("PEL_ID=0x%X", id));
117a943b15bSMatt Spinler         required = false;
118a943b15bSMatt Spinler     }
119f60ac27eSMatt Spinler 
120f60ac27eSMatt Spinler     return required;
121f60ac27eSMatt Spinler }
122f60ac27eSMatt Spinler 
123f77debb9SMatt Spinler bool HostNotifier::notifyRequired(uint32_t id) const
124f77debb9SMatt Spinler {
125f77debb9SMatt Spinler     bool notify = true;
126f77debb9SMatt Spinler     Repository::LogID i{Repository::LogID::Pel{id}};
127f77debb9SMatt Spinler 
128f77debb9SMatt Spinler     if (auto attributes = _repo.getPELAttributes(i); attributes)
129f77debb9SMatt Spinler     {
130f77debb9SMatt Spinler         // If already acked by the host, don't send again.
131f77debb9SMatt Spinler         // (A safety check as it shouldn't get to this point.)
132f77debb9SMatt Spinler         auto a = attributes.value().get();
133f77debb9SMatt Spinler         if (a.hostState == TransmissionState::acked)
134f77debb9SMatt Spinler         {
135f77debb9SMatt Spinler             notify = false;
136f77debb9SMatt Spinler         }
137f77debb9SMatt Spinler         else if (a.actionFlags.test(hiddenFlagBit))
138f77debb9SMatt Spinler         {
139f77debb9SMatt Spinler             // If hidden and acked (or will be) acked by the HMC,
140f77debb9SMatt Spinler             // also don't send it. (HMC management can come and
141f77debb9SMatt Spinler             // go at any time)
142f77debb9SMatt Spinler             if ((a.hmcState == TransmissionState::acked) ||
143f77debb9SMatt Spinler                 _dataIface.isHMCManaged())
144f77debb9SMatt Spinler             {
145f77debb9SMatt Spinler                 notify = false;
146f77debb9SMatt Spinler             }
147f77debb9SMatt Spinler         }
148f77debb9SMatt Spinler     }
149f77debb9SMatt Spinler     else
150f77debb9SMatt Spinler     {
151f77debb9SMatt Spinler         // Must have been deleted since put on the queue.
152f77debb9SMatt Spinler         notify = false;
153f77debb9SMatt Spinler     }
154f77debb9SMatt Spinler 
155f77debb9SMatt Spinler     return notify;
156f77debb9SMatt Spinler }
157f77debb9SMatt Spinler 
158f60ac27eSMatt Spinler void HostNotifier::newLogCallback(const PEL& pel)
159f60ac27eSMatt Spinler {
160f60ac27eSMatt Spinler     if (!enqueueRequired(pel.id()))
161f60ac27eSMatt Spinler     {
162f60ac27eSMatt Spinler         return;
163f60ac27eSMatt Spinler     }
164f60ac27eSMatt Spinler 
165f60ac27eSMatt Spinler     _pelQueue.push_back(pel.id());
166f60ac27eSMatt Spinler 
16741293cb8SMatt Spinler     // Notify shouldn't happen if host is down or full
16841293cb8SMatt Spinler     if (!_dataIface.isHostUp() || _hostFull)
1697d800a4eSMatt Spinler     {
1707d800a4eSMatt Spinler         return;
1717d800a4eSMatt Spinler     }
1727d800a4eSMatt Spinler 
1737d800a4eSMatt Spinler     // Dispatch a command now if there isn't currently a command
1747d800a4eSMatt Spinler     // in progress and this is the first log in the queue or it
1757d800a4eSMatt Spinler     // previously gave up from a hard failure.
1767d800a4eSMatt Spinler     auto inProgress = (_inProgressPEL != 0) || _hostIface->cmdInProgress() ||
1777d800a4eSMatt Spinler                       _retryTimer.isEnabled();
1787d800a4eSMatt Spinler 
1797d800a4eSMatt Spinler     auto firstPEL = _pelQueue.size() == 1;
1807d800a4eSMatt Spinler     auto gaveUp = _retryCount >= maxRetryAttempts;
1817d800a4eSMatt Spinler 
1827d800a4eSMatt Spinler     if (!inProgress && (firstPEL || gaveUp))
1837d800a4eSMatt Spinler     {
1847d800a4eSMatt Spinler         _retryCount = 0;
1857d800a4eSMatt Spinler 
1867d800a4eSMatt Spinler         // Send a log, but from the event loop, not from here.
1877d800a4eSMatt Spinler         scheduleDispatch();
1887d800a4eSMatt Spinler     }
1897d800a4eSMatt Spinler }
1907d800a4eSMatt Spinler 
1917d800a4eSMatt Spinler void HostNotifier::scheduleDispatch()
1927d800a4eSMatt Spinler {
1937d800a4eSMatt Spinler     _dispatcher = std::make_unique<sdeventplus::source::Defer>(
1947d800a4eSMatt Spinler         _hostIface->getEvent(), std::bind(std::mem_fn(&HostNotifier::dispatch),
1957d800a4eSMatt Spinler                                           this, std::placeholders::_1));
1967d800a4eSMatt Spinler }
1977d800a4eSMatt Spinler 
1987d800a4eSMatt Spinler void HostNotifier::dispatch(sdeventplus::source::EventBase& source)
1997d800a4eSMatt Spinler {
2007d800a4eSMatt Spinler     _dispatcher.reset();
2017d800a4eSMatt Spinler 
2027d800a4eSMatt Spinler     doNewLogNotify();
203f60ac27eSMatt Spinler }
204f60ac27eSMatt Spinler 
205f60ac27eSMatt Spinler void HostNotifier::doNewLogNotify()
206f60ac27eSMatt Spinler {
20741293cb8SMatt Spinler     if (!_dataIface.isHostUp() || _retryTimer.isEnabled() ||
20841293cb8SMatt Spinler         _hostFullTimer.isEnabled())
209f77debb9SMatt Spinler     {
210f77debb9SMatt Spinler         return;
211f77debb9SMatt Spinler     }
212f77debb9SMatt Spinler 
213f77debb9SMatt Spinler     if (_retryCount >= maxRetryAttempts)
214f77debb9SMatt Spinler     {
215f77debb9SMatt Spinler         // Give up until a new log comes in.
216f77debb9SMatt Spinler         if (_retryCount == maxRetryAttempts)
217f77debb9SMatt Spinler         {
218f77debb9SMatt Spinler             // If this were to really happen, the PLDM interface
219f77debb9SMatt Spinler             // would be down and isolating that shouldn't left to
220f77debb9SMatt Spinler             // a logging daemon, so just trace.  Also, this will start
221f77debb9SMatt Spinler             // trying again when the next new log comes in.
222f77debb9SMatt Spinler             log<level::ERR>(
223f77debb9SMatt Spinler                 "PEL Host notifier hit max retry attempts. Giving up for now.",
224f77debb9SMatt Spinler                 entry("PEL_ID=0x%X", _pelQueue.front()));
225f77debb9SMatt Spinler         }
226f77debb9SMatt Spinler         return;
227f77debb9SMatt Spinler     }
228f77debb9SMatt Spinler 
229f77debb9SMatt Spinler     bool doNotify = false;
230f77debb9SMatt Spinler     uint32_t id = 0;
231f77debb9SMatt Spinler 
232f77debb9SMatt Spinler     // Find the PEL to send
233f77debb9SMatt Spinler     while (!doNotify && !_pelQueue.empty())
234f77debb9SMatt Spinler     {
235f77debb9SMatt Spinler         id = _pelQueue.front();
236f77debb9SMatt Spinler         _pelQueue.pop_front();
237f77debb9SMatt Spinler 
238f77debb9SMatt Spinler         if (notifyRequired(id))
239f77debb9SMatt Spinler         {
240f77debb9SMatt Spinler             doNotify = true;
241f77debb9SMatt Spinler         }
242f77debb9SMatt Spinler     }
243f77debb9SMatt Spinler 
244f77debb9SMatt Spinler     if (doNotify)
245f77debb9SMatt Spinler     {
246f77debb9SMatt Spinler         // Get the size using the repo attributes
247f77debb9SMatt Spinler         Repository::LogID i{Repository::LogID::Pel{id}};
248f77debb9SMatt Spinler         if (auto attributes = _repo.getPELAttributes(i); attributes)
249f77debb9SMatt Spinler         {
250f77debb9SMatt Spinler             auto size = static_cast<size_t>(
251f77debb9SMatt Spinler                 std::filesystem::file_size((*attributes).get().path));
252f77debb9SMatt Spinler             auto rc = _hostIface->sendNewLogCmd(id, size);
253f77debb9SMatt Spinler 
254f77debb9SMatt Spinler             if (rc == CmdStatus::success)
255f77debb9SMatt Spinler             {
256f77debb9SMatt Spinler                 _inProgressPEL = id;
257f77debb9SMatt Spinler             }
258f77debb9SMatt Spinler             else
259f77debb9SMatt Spinler             {
260f77debb9SMatt Spinler                 // It failed.  Retry
261f77debb9SMatt Spinler                 log<level::ERR>("PLDM send failed", entry("PEL_ID=0x%X", id));
262f77debb9SMatt Spinler                 _pelQueue.push_front(id);
263f77debb9SMatt Spinler                 _inProgressPEL = 0;
264f77debb9SMatt Spinler                 _retryTimer.restartOnce(_hostIface->getSendRetryDelay());
265f77debb9SMatt Spinler             }
266f77debb9SMatt Spinler         }
267f77debb9SMatt Spinler         else
268f77debb9SMatt Spinler         {
269f77debb9SMatt Spinler             log<level::ERR>("PEL ID not in repository.  Cannot notify host",
270f77debb9SMatt Spinler                             entry("PEL_ID=0x%X", id));
271f77debb9SMatt Spinler         }
272f77debb9SMatt Spinler     }
273f60ac27eSMatt Spinler }
274f60ac27eSMatt Spinler 
275f60ac27eSMatt Spinler void HostNotifier::hostStateChange(bool hostUp)
276f60ac27eSMatt Spinler {
2773019c6fbSMatt Spinler     _retryCount = 0;
27841293cb8SMatt Spinler     _hostFull = false;
2793019c6fbSMatt Spinler 
2803019c6fbSMatt Spinler     if (hostUp && !_pelQueue.empty())
2813019c6fbSMatt Spinler     {
2823019c6fbSMatt Spinler         doNewLogNotify();
2833019c6fbSMatt Spinler     }
2843019c6fbSMatt Spinler     else if (!hostUp)
2853019c6fbSMatt Spinler     {
2863019c6fbSMatt Spinler         stopCommand();
2873019c6fbSMatt Spinler 
2883019c6fbSMatt Spinler         // Reset the state on any PELs that were sent but not acked back
2893019c6fbSMatt Spinler         // to new so they'll get sent again.
2903019c6fbSMatt Spinler         for (auto id : _sentPELs)
2913019c6fbSMatt Spinler         {
2923019c6fbSMatt Spinler             _pelQueue.push_back(id);
2933019c6fbSMatt Spinler             _repo.setPELHostTransState(id, TransmissionState::newPEL);
2943019c6fbSMatt Spinler         }
2953019c6fbSMatt Spinler 
2963019c6fbSMatt Spinler         _sentPELs.clear();
29741293cb8SMatt Spinler 
29841293cb8SMatt Spinler         if (_hostFullTimer.isEnabled())
29941293cb8SMatt Spinler         {
30041293cb8SMatt Spinler             _hostFullTimer.setEnabled(false);
30141293cb8SMatt Spinler         }
3023019c6fbSMatt Spinler     }
303f60ac27eSMatt Spinler }
304f60ac27eSMatt Spinler 
305f60ac27eSMatt Spinler void HostNotifier::commandResponse(ResponseStatus status)
306f60ac27eSMatt Spinler {
307f869fcf8SMatt Spinler     auto id = _inProgressPEL;
308f869fcf8SMatt Spinler     _inProgressPEL = 0;
309f869fcf8SMatt Spinler 
310f869fcf8SMatt Spinler     if (status == ResponseStatus::success)
311f869fcf8SMatt Spinler     {
312f869fcf8SMatt Spinler         _retryCount = 0;
313f869fcf8SMatt Spinler 
314f869fcf8SMatt Spinler         _sentPELs.push_back(id);
315f869fcf8SMatt Spinler 
316f869fcf8SMatt Spinler         _repo.setPELHostTransState(id, TransmissionState::sent);
317f869fcf8SMatt Spinler 
31841293cb8SMatt Spinler         // If the host is full, don't send off the next PEL
31941293cb8SMatt Spinler         if (!_hostFull && !_pelQueue.empty())
320f869fcf8SMatt Spinler         {
321f869fcf8SMatt Spinler             doNewLogNotify();
322f869fcf8SMatt Spinler         }
323f869fcf8SMatt Spinler     }
324f869fcf8SMatt Spinler     else
325f869fcf8SMatt Spinler     {
326f869fcf8SMatt Spinler         log<level::ERR>("PLDM command response failure",
327f869fcf8SMatt Spinler                         entry("PEL_ID=0x%X", id));
328f869fcf8SMatt Spinler         // Retry
329f869fcf8SMatt Spinler         _pelQueue.push_front(id);
330f869fcf8SMatt Spinler         _retryTimer.restartOnce(_hostIface->getReceiveRetryDelay());
331f869fcf8SMatt Spinler     }
332f869fcf8SMatt Spinler }
333f869fcf8SMatt Spinler 
334f869fcf8SMatt Spinler void HostNotifier::retryTimerExpired()
335f869fcf8SMatt Spinler {
336f869fcf8SMatt Spinler     if (_dataIface.isHostUp())
337f869fcf8SMatt Spinler     {
338f869fcf8SMatt Spinler         log<level::INFO>("Attempting command retry",
339f869fcf8SMatt Spinler                          entry("PEL_ID=0x%X", _pelQueue.front()));
340f869fcf8SMatt Spinler         _retryCount++;
341f869fcf8SMatt Spinler         doNewLogNotify();
342f869fcf8SMatt Spinler     }
343f60ac27eSMatt Spinler }
344f60ac27eSMatt Spinler 
34541293cb8SMatt Spinler void HostNotifier::hostFullTimerExpired()
34641293cb8SMatt Spinler {
34741293cb8SMatt Spinler     doNewLogNotify();
34841293cb8SMatt Spinler }
34941293cb8SMatt Spinler 
3503019c6fbSMatt Spinler void HostNotifier::stopCommand()
3513019c6fbSMatt Spinler {
3523019c6fbSMatt Spinler     _retryCount = 0;
3533019c6fbSMatt Spinler 
3543019c6fbSMatt Spinler     if (_inProgressPEL != 0)
3553019c6fbSMatt Spinler     {
3563019c6fbSMatt Spinler         _pelQueue.push_front(_inProgressPEL);
3573019c6fbSMatt Spinler         _inProgressPEL = 0;
3583019c6fbSMatt Spinler     }
3593019c6fbSMatt Spinler 
3603019c6fbSMatt Spinler     if (_retryTimer.isEnabled())
3613019c6fbSMatt Spinler     {
3623019c6fbSMatt Spinler         _retryTimer.setEnabled(false);
3633019c6fbSMatt Spinler     }
3643019c6fbSMatt Spinler 
3653019c6fbSMatt Spinler     if (_hostIface->cmdInProgress())
3663019c6fbSMatt Spinler     {
3673019c6fbSMatt Spinler         _hostIface->cancelCmd();
3683019c6fbSMatt Spinler     }
3693019c6fbSMatt Spinler }
3703019c6fbSMatt Spinler 
371cc3b64aeSMatt Spinler void HostNotifier::ackPEL(uint32_t id)
372cc3b64aeSMatt Spinler {
373cc3b64aeSMatt Spinler     _repo.setPELHostTransState(id, TransmissionState::acked);
374cc3b64aeSMatt Spinler 
375cc3b64aeSMatt Spinler     // No longer just 'sent', so remove it from the sent list.
376cc3b64aeSMatt Spinler     auto sent = std::find(_sentPELs.begin(), _sentPELs.end(), id);
377cc3b64aeSMatt Spinler     if (sent != _sentPELs.end())
378cc3b64aeSMatt Spinler     {
379cc3b64aeSMatt Spinler         _sentPELs.erase(sent);
380cc3b64aeSMatt Spinler     }
38141293cb8SMatt Spinler 
38241293cb8SMatt Spinler     // An ack means the host is no longer full
38341293cb8SMatt Spinler     if (_hostFullTimer.isEnabled())
38441293cb8SMatt Spinler     {
38541293cb8SMatt Spinler         _hostFullTimer.setEnabled(false);
38641293cb8SMatt Spinler     }
38741293cb8SMatt Spinler 
38841293cb8SMatt Spinler     if (_hostFull)
38941293cb8SMatt Spinler     {
39041293cb8SMatt Spinler         _hostFull = false;
39141293cb8SMatt Spinler 
39241293cb8SMatt Spinler         // Start sending PELs again, from the event loop
39341293cb8SMatt Spinler         if (!_pelQueue.empty())
39441293cb8SMatt Spinler         {
39541293cb8SMatt Spinler             scheduleDispatch();
39641293cb8SMatt Spinler         }
39741293cb8SMatt Spinler     }
39841293cb8SMatt Spinler }
39941293cb8SMatt Spinler 
40041293cb8SMatt Spinler void HostNotifier::setHostFull(uint32_t id)
40141293cb8SMatt Spinler {
40241293cb8SMatt Spinler     log<level::INFO>("Received Host full indication", entry("PEL_ID=0x%X", id));
40341293cb8SMatt Spinler 
40441293cb8SMatt Spinler     _hostFull = true;
40541293cb8SMatt Spinler 
40641293cb8SMatt Spinler     // This PEL needs to get re-sent
40741293cb8SMatt Spinler     auto sent = std::find(_sentPELs.begin(), _sentPELs.end(), id);
40841293cb8SMatt Spinler     if (sent != _sentPELs.end())
40941293cb8SMatt Spinler     {
41041293cb8SMatt Spinler         _sentPELs.erase(sent);
41141293cb8SMatt Spinler         _repo.setPELHostTransState(id, TransmissionState::newPEL);
41241293cb8SMatt Spinler 
41341293cb8SMatt Spinler         if (std::find(_pelQueue.begin(), _pelQueue.end(), id) ==
41441293cb8SMatt Spinler             _pelQueue.end())
41541293cb8SMatt Spinler         {
41641293cb8SMatt Spinler             _pelQueue.push_front(id);
41741293cb8SMatt Spinler         }
41841293cb8SMatt Spinler     }
41941293cb8SMatt Spinler 
42041293cb8SMatt Spinler     // The only PELs that will be sent when the
42141293cb8SMatt Spinler     // host is full is from this timer callback.
42241293cb8SMatt Spinler     if (!_hostFullTimer.isEnabled())
42341293cb8SMatt Spinler     {
42441293cb8SMatt Spinler         _hostFullTimer.restartOnce(_hostIface->getHostFullRetryDelay());
42541293cb8SMatt Spinler     }
426cc3b64aeSMatt Spinler }
427cc3b64aeSMatt Spinler 
428a19b6234SMatt Spinler void HostNotifier::setBadPEL(uint32_t id)
429a19b6234SMatt Spinler {
430a19b6234SMatt Spinler     log<level::ERR>("PEL rejected by the host", entry("PEL_ID=0x%X", id));
431a19b6234SMatt Spinler 
432a19b6234SMatt Spinler     auto sent = std::find(_sentPELs.begin(), _sentPELs.end(), id);
433a19b6234SMatt Spinler     if (sent != _sentPELs.end())
434a19b6234SMatt Spinler     {
435a19b6234SMatt Spinler         _sentPELs.erase(sent);
436a19b6234SMatt Spinler     }
437a19b6234SMatt Spinler 
438a19b6234SMatt Spinler     _repo.setPELHostTransState(id, TransmissionState::badPEL);
439a19b6234SMatt Spinler }
440a19b6234SMatt Spinler 
441f60ac27eSMatt Spinler } // namespace openpower::pels
442