| Alexander Hansen | 40fb549 | 2025-10-28 17:56:12 +0100 | [diff] [blame^] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright 2019 IBM Corporation |
| 3 | |
| Matt Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 4 | #include "host_notifier.hpp" |
| 5 | |
| Matt Spinler | 1b41886 | 2023-06-29 12:37:41 -0500 | [diff] [blame] | 6 | #include <phosphor-logging/lg2.hpp> |
| Matt Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 7 | |
| 8 | namespace openpower::pels |
| 9 | { |
| 10 | |
| 11 | const auto subscriptionName = "PELHostNotifier"; |
| Matt Spinler | f77debb | 2019-12-12 10:04:33 -0600 | [diff] [blame] | 12 | const size_t maxRetryAttempts = 15; |
| Matt Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 13 | |
| Matt Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 14 | HostNotifier::HostNotifier(Repository& repo, DataInterfaceBase& dataIface, |
| 15 | std::unique_ptr<HostInterface> hostIface) : |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 16 | _repo(repo), _dataIface(dataIface), _hostIface(std::move(hostIface)), |
| Matt Spinler | f869fcf | 2019-12-11 15:02:20 -0600 | [diff] [blame] | 17 | _retryTimer(_hostIface->getEvent(), |
| Matt Spinler | 41293cb | 2019-12-12 13:11:09 -0600 | [diff] [blame] | 18 | std::bind(std::mem_fn(&HostNotifier::retryTimerExpired), this)), |
| 19 | _hostFullTimer( |
| 20 | _hostIface->getEvent(), |
| Matt Spinler | e5f7508 | 2022-01-24 16:09:51 -0600 | [diff] [blame] | 21 | std::bind(std::mem_fn(&HostNotifier::hostFullTimerExpired), this)), |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 22 | _hostUpTimer(_hostIface->getEvent(), |
| 23 | std::bind(std::mem_fn(&HostNotifier::hostUpTimerExpired), |
| 24 | this)) |
| Matt Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 25 | { |
| 26 | // Subscribe to be told about new PELs. |
| 27 | _repo.subscribeToAdds(subscriptionName, |
| 28 | std::bind(std::mem_fn(&HostNotifier::newLogCallback), |
| 29 | this, std::placeholders::_1)); |
| 30 | |
| Matt Spinler | 7cb985f | 2020-03-05 16:02:39 -0600 | [diff] [blame] | 31 | // Subscribe to be told about deleted PELs. |
| 32 | _repo.subscribeToDeletes( |
| 33 | subscriptionName, |
| 34 | std::bind(std::mem_fn(&HostNotifier::deleteLogCallback), this, |
| 35 | std::placeholders::_1)); |
| 36 | |
| Matt Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 37 | // Add any existing PELs to the queue to send them if necessary. |
| 38 | _repo.for_each(std::bind(std::mem_fn(&HostNotifier::addPELToQueue), this, |
| 39 | std::placeholders::_1)); |
| 40 | |
| 41 | // Subscribe to be told about host state changes. |
| 42 | _dataIface.subscribeToHostStateChange( |
| Matt Spinler | 4f1bed7 | 2022-06-09 09:06:15 -0500 | [diff] [blame] | 43 | subscriptionName, std::bind(std::mem_fn(&HostNotifier::hostStateChange), |
| 44 | this, std::placeholders::_1)); |
| Matt Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 45 | |
| 46 | // Set the function to call when the async reponse is received. |
| 47 | _hostIface->setResponseFunction( |
| 48 | std::bind(std::mem_fn(&HostNotifier::commandResponse), this, |
| 49 | std::placeholders::_1)); |
| 50 | |
| 51 | // Start sending logs if the host is running |
| 52 | if (!_pelQueue.empty() && _dataIface.isHostUp()) |
| 53 | { |
| Matt Spinler | 1b41886 | 2023-06-29 12:37:41 -0500 | [diff] [blame] | 54 | lg2::debug("Host is already up at startup"); |
| Matt Spinler | e5f7508 | 2022-01-24 16:09:51 -0600 | [diff] [blame] | 55 | _hostUpTimer.restartOnce(_hostIface->getHostUpDelay()); |
| Matt Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | |
| 59 | HostNotifier::~HostNotifier() |
| 60 | { |
| 61 | _repo.unsubscribeFromAdds(subscriptionName); |
| 62 | _dataIface.unsubscribeFromHostStateChange(subscriptionName); |
| 63 | } |
| 64 | |
| Matt Spinler | e5f7508 | 2022-01-24 16:09:51 -0600 | [diff] [blame] | 65 | void HostNotifier::hostUpTimerExpired() |
| 66 | { |
| Matt Spinler | 1b41886 | 2023-06-29 12:37:41 -0500 | [diff] [blame] | 67 | lg2::debug("Host up timer expired"); |
| Matt Spinler | e5f7508 | 2022-01-24 16:09:51 -0600 | [diff] [blame] | 68 | doNewLogNotify(); |
| 69 | } |
| 70 | |
| Matt Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 71 | bool HostNotifier::addPELToQueue(const PEL& pel) |
| 72 | { |
| 73 | if (enqueueRequired(pel.id())) |
| 74 | { |
| 75 | _pelQueue.push_back(pel.id()); |
| 76 | } |
| 77 | |
| 78 | // Return false so that Repo::for_each keeps going. |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | bool HostNotifier::enqueueRequired(uint32_t id) const |
| 83 | { |
| 84 | bool required = true; |
| Matt Spinler | a943b15 | 2019-12-11 14:44:50 -0600 | [diff] [blame] | 85 | Repository::LogID i{Repository::LogID::Pel{id}}; |
| 86 | |
| Matt Spinler | 24a8558 | 2020-01-27 16:40:21 -0600 | [diff] [blame] | 87 | // Manufacturing testing may turn off sending up PELs |
| 88 | if (!_dataIface.getHostPELEnablement()) |
| 89 | { |
| 90 | return false; |
| 91 | } |
| 92 | |
| Matt Spinler | a943b15 | 2019-12-11 14:44:50 -0600 | [diff] [blame] | 93 | if (auto attributes = _repo.getPELAttributes(i); attributes) |
| 94 | { |
| 95 | auto a = attributes.value().get(); |
| 96 | |
| 97 | if ((a.hostState == TransmissionState::acked) || |
| 98 | (a.hostState == TransmissionState::badPEL)) |
| 99 | { |
| 100 | required = false; |
| 101 | } |
| 102 | else if (a.actionFlags.test(hiddenFlagBit) && |
| 103 | (a.hmcState == TransmissionState::acked)) |
| 104 | { |
| 105 | required = false; |
| 106 | } |
| 107 | else if (a.actionFlags.test(dontReportToHostFlagBit)) |
| 108 | { |
| 109 | required = false; |
| 110 | } |
| 111 | } |
| 112 | else |
| 113 | { |
| 114 | using namespace phosphor::logging; |
| Matt Spinler | 1b41886 | 2023-06-29 12:37:41 -0500 | [diff] [blame] | 115 | lg2::error("Host Enqueue: Unable to find PEL ID {ID} in repository", |
| 116 | "ID", lg2::hex, id); |
| Matt Spinler | a943b15 | 2019-12-11 14:44:50 -0600 | [diff] [blame] | 117 | required = false; |
| 118 | } |
| Matt Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 119 | |
| 120 | return required; |
| 121 | } |
| 122 | |
| Matt Spinler | f77debb | 2019-12-12 10:04:33 -0600 | [diff] [blame] | 123 | bool HostNotifier::notifyRequired(uint32_t id) const |
| 124 | { |
| 125 | bool notify = true; |
| 126 | Repository::LogID i{Repository::LogID::Pel{id}}; |
| 127 | |
| 128 | if (auto attributes = _repo.getPELAttributes(i); attributes) |
| 129 | { |
| 130 | // If already acked by the host, don't send again. |
| 131 | // (A safety check as it shouldn't get to this point.) |
| 132 | auto a = attributes.value().get(); |
| 133 | if (a.hostState == TransmissionState::acked) |
| 134 | { |
| 135 | notify = false; |
| 136 | } |
| 137 | else if (a.actionFlags.test(hiddenFlagBit)) |
| 138 | { |
| 139 | // If hidden and acked (or will be) acked by the HMC, |
| 140 | // also don't send it. (HMC management can come and |
| 141 | // go at any time) |
| 142 | if ((a.hmcState == TransmissionState::acked) || |
| 143 | _dataIface.isHMCManaged()) |
| 144 | { |
| 145 | notify = false; |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | else |
| 150 | { |
| 151 | // Must have been deleted since put on the queue. |
| 152 | notify = false; |
| 153 | } |
| 154 | |
| 155 | return notify; |
| 156 | } |
| 157 | |
| Matt Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 158 | void HostNotifier::newLogCallback(const PEL& pel) |
| 159 | { |
| 160 | if (!enqueueRequired(pel.id())) |
| 161 | { |
| 162 | return; |
| 163 | } |
| 164 | |
| Matt Spinler | 1b41886 | 2023-06-29 12:37:41 -0500 | [diff] [blame] | 165 | lg2::debug("New PEL added to queue, PEL ID = {ID}", "ID", lg2::hex, |
| 166 | pel.id()); |
| Matt Spinler | 5f5352e | 2020-03-05 16:23:27 -0600 | [diff] [blame] | 167 | |
| Matt Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 168 | _pelQueue.push_back(pel.id()); |
| 169 | |
| Matt Spinler | e5f7508 | 2022-01-24 16:09:51 -0600 | [diff] [blame] | 170 | // Notify shouldn't happen if host is down, not up long enough, or full |
| 171 | if (!_dataIface.isHostUp() || _hostFull || _hostUpTimer.isEnabled()) |
| Matt Spinler | 7d800a4 | 2019-12-12 10:35:01 -0600 | [diff] [blame] | 172 | { |
| 173 | return; |
| 174 | } |
| 175 | |
| 176 | // Dispatch a command now if there isn't currently a command |
| 177 | // in progress and this is the first log in the queue or it |
| 178 | // previously gave up from a hard failure. |
| 179 | auto inProgress = (_inProgressPEL != 0) || _hostIface->cmdInProgress() || |
| 180 | _retryTimer.isEnabled(); |
| 181 | |
| 182 | auto firstPEL = _pelQueue.size() == 1; |
| 183 | auto gaveUp = _retryCount >= maxRetryAttempts; |
| 184 | |
| 185 | if (!inProgress && (firstPEL || gaveUp)) |
| 186 | { |
| 187 | _retryCount = 0; |
| 188 | |
| 189 | // Send a log, but from the event loop, not from here. |
| 190 | scheduleDispatch(); |
| 191 | } |
| 192 | } |
| 193 | |
| Matt Spinler | 7cb985f | 2020-03-05 16:02:39 -0600 | [diff] [blame] | 194 | void HostNotifier::deleteLogCallback(uint32_t id) |
| 195 | { |
| 196 | auto queueIt = std::find(_pelQueue.begin(), _pelQueue.end(), id); |
| 197 | if (queueIt != _pelQueue.end()) |
| 198 | { |
| Matt Spinler | 1b41886 | 2023-06-29 12:37:41 -0500 | [diff] [blame] | 199 | lg2::debug("Host notifier removing deleted log from queue"); |
| Matt Spinler | 7cb985f | 2020-03-05 16:02:39 -0600 | [diff] [blame] | 200 | _pelQueue.erase(queueIt); |
| 201 | } |
| 202 | |
| 203 | auto sentIt = std::find(_sentPELs.begin(), _sentPELs.end(), id); |
| 204 | if (sentIt != _sentPELs.end()) |
| 205 | { |
| Matt Spinler | 1b41886 | 2023-06-29 12:37:41 -0500 | [diff] [blame] | 206 | lg2::debug("Host notifier removing deleted log from sent list"); |
| Matt Spinler | 7cb985f | 2020-03-05 16:02:39 -0600 | [diff] [blame] | 207 | _sentPELs.erase(sentIt); |
| 208 | } |
| 209 | |
| 210 | // Nothing we can do about this... |
| 211 | if (id == _inProgressPEL) |
| 212 | { |
| Matt Spinler | 1b41886 | 2023-06-29 12:37:41 -0500 | [diff] [blame] | 213 | lg2::warning( |
| 214 | "A PEL was deleted while its host notification was in progress, PEL ID = {ID}", |
| 215 | "ID", lg2::hex, id); |
| Matt Spinler | 7cb985f | 2020-03-05 16:02:39 -0600 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
| Matt Spinler | 7d800a4 | 2019-12-12 10:35:01 -0600 | [diff] [blame] | 219 | void HostNotifier::scheduleDispatch() |
| 220 | { |
| 221 | _dispatcher = std::make_unique<sdeventplus::source::Defer>( |
| 222 | _hostIface->getEvent(), std::bind(std::mem_fn(&HostNotifier::dispatch), |
| 223 | this, std::placeholders::_1)); |
| 224 | } |
| 225 | |
| Patrick Williams | d26fa3e | 2021-04-21 15:22:23 -0500 | [diff] [blame] | 226 | void HostNotifier::dispatch(sdeventplus::source::EventBase& /*source*/) |
| Matt Spinler | 7d800a4 | 2019-12-12 10:35:01 -0600 | [diff] [blame] | 227 | { |
| 228 | _dispatcher.reset(); |
| 229 | |
| 230 | doNewLogNotify(); |
| Matt Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | void HostNotifier::doNewLogNotify() |
| 234 | { |
| Matt Spinler | 41293cb | 2019-12-12 13:11:09 -0600 | [diff] [blame] | 235 | if (!_dataIface.isHostUp() || _retryTimer.isEnabled() || |
| 236 | _hostFullTimer.isEnabled()) |
| Matt Spinler | f77debb | 2019-12-12 10:04:33 -0600 | [diff] [blame] | 237 | { |
| 238 | return; |
| 239 | } |
| 240 | |
| 241 | if (_retryCount >= maxRetryAttempts) |
| 242 | { |
| 243 | // Give up until a new log comes in. |
| 244 | if (_retryCount == maxRetryAttempts) |
| 245 | { |
| 246 | // If this were to really happen, the PLDM interface |
| 247 | // would be down and isolating that shouldn't left to |
| 248 | // a logging daemon, so just trace. Also, this will start |
| 249 | // trying again when the next new log comes in. |
| Matt Spinler | 1b41886 | 2023-06-29 12:37:41 -0500 | [diff] [blame] | 250 | lg2::error( |
| 251 | "PEL Host notifier hit max retry attempts. Giving up for now. PEL ID = {ID}", |
| 252 | "ID", lg2::hex, _pelQueue.front()); |
| Matt Spinler | 829b052 | 2020-03-04 08:38:46 -0600 | [diff] [blame] | 253 | |
| 254 | // Tell the host interface object to clean itself up, especially to |
| 255 | // release the PLDM instance ID it's been using. |
| 256 | _hostIface->cancelCmd(); |
| Matt Spinler | f77debb | 2019-12-12 10:04:33 -0600 | [diff] [blame] | 257 | } |
| 258 | return; |
| 259 | } |
| 260 | |
| 261 | bool doNotify = false; |
| 262 | uint32_t id = 0; |
| 263 | |
| 264 | // Find the PEL to send |
| 265 | while (!doNotify && !_pelQueue.empty()) |
| 266 | { |
| 267 | id = _pelQueue.front(); |
| 268 | _pelQueue.pop_front(); |
| 269 | |
| 270 | if (notifyRequired(id)) |
| 271 | { |
| 272 | doNotify = true; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | if (doNotify) |
| 277 | { |
| 278 | // Get the size using the repo attributes |
| 279 | Repository::LogID i{Repository::LogID::Pel{id}}; |
| 280 | if (auto attributes = _repo.getPELAttributes(i); attributes) |
| 281 | { |
| 282 | auto size = static_cast<size_t>( |
| 283 | std::filesystem::file_size((*attributes).get().path)); |
| Matt Spinler | 5f5352e | 2020-03-05 16:23:27 -0600 | [diff] [blame] | 284 | |
| Matt Spinler | 1b41886 | 2023-06-29 12:37:41 -0500 | [diff] [blame] | 285 | lg2::debug("sendNewLogCmd: ID {ID} size {SIZE}", "ID", lg2::hex, id, |
| 286 | "SIZE", size); |
| Matt Spinler | 5f5352e | 2020-03-05 16:23:27 -0600 | [diff] [blame] | 287 | |
| Matt Spinler | f77debb | 2019-12-12 10:04:33 -0600 | [diff] [blame] | 288 | auto rc = _hostIface->sendNewLogCmd(id, size); |
| 289 | |
| 290 | if (rc == CmdStatus::success) |
| 291 | { |
| 292 | _inProgressPEL = id; |
| 293 | } |
| 294 | else |
| 295 | { |
| 296 | // It failed. Retry |
| Matt Spinler | 1b41886 | 2023-06-29 12:37:41 -0500 | [diff] [blame] | 297 | lg2::error("PLDM send failed, PEL ID = {ID}", "ID", lg2::hex, |
| 298 | id); |
| Matt Spinler | f77debb | 2019-12-12 10:04:33 -0600 | [diff] [blame] | 299 | _pelQueue.push_front(id); |
| 300 | _inProgressPEL = 0; |
| 301 | _retryTimer.restartOnce(_hostIface->getSendRetryDelay()); |
| 302 | } |
| 303 | } |
| 304 | else |
| 305 | { |
| Matt Spinler | 1b41886 | 2023-06-29 12:37:41 -0500 | [diff] [blame] | 306 | lg2::error( |
| 307 | "PEL ID is not in repository. Cannot notify host. PEL ID = {ID}", |
| 308 | "ID", lg2::hex, id); |
| Matt Spinler | f77debb | 2019-12-12 10:04:33 -0600 | [diff] [blame] | 309 | } |
| 310 | } |
| Matt Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | void HostNotifier::hostStateChange(bool hostUp) |
| 314 | { |
| Matt Spinler | 3019c6f | 2019-12-11 15:24:45 -0600 | [diff] [blame] | 315 | _retryCount = 0; |
| Matt Spinler | 41293cb | 2019-12-12 13:11:09 -0600 | [diff] [blame] | 316 | _hostFull = false; |
| Matt Spinler | 3019c6f | 2019-12-11 15:24:45 -0600 | [diff] [blame] | 317 | |
| 318 | if (hostUp && !_pelQueue.empty()) |
| 319 | { |
| Matt Spinler | 1b41886 | 2023-06-29 12:37:41 -0500 | [diff] [blame] | 320 | lg2::debug("Host state change to on"); |
| Matt Spinler | e5f7508 | 2022-01-24 16:09:51 -0600 | [diff] [blame] | 321 | _hostUpTimer.restartOnce(_hostIface->getHostUpDelay()); |
| Matt Spinler | 3019c6f | 2019-12-11 15:24:45 -0600 | [diff] [blame] | 322 | } |
| 323 | else if (!hostUp) |
| 324 | { |
| Matt Spinler | 1b41886 | 2023-06-29 12:37:41 -0500 | [diff] [blame] | 325 | lg2::debug("Host state change to off"); |
| Matt Spinler | 5f5352e | 2020-03-05 16:23:27 -0600 | [diff] [blame] | 326 | |
| Matt Spinler | 3019c6f | 2019-12-11 15:24:45 -0600 | [diff] [blame] | 327 | stopCommand(); |
| 328 | |
| 329 | // Reset the state on any PELs that were sent but not acked back |
| 330 | // to new so they'll get sent again. |
| 331 | for (auto id : _sentPELs) |
| 332 | { |
| 333 | _pelQueue.push_back(id); |
| 334 | _repo.setPELHostTransState(id, TransmissionState::newPEL); |
| 335 | } |
| 336 | |
| 337 | _sentPELs.clear(); |
| Matt Spinler | 41293cb | 2019-12-12 13:11:09 -0600 | [diff] [blame] | 338 | |
| 339 | if (_hostFullTimer.isEnabled()) |
| 340 | { |
| 341 | _hostFullTimer.setEnabled(false); |
| 342 | } |
| Matt Spinler | e5f7508 | 2022-01-24 16:09:51 -0600 | [diff] [blame] | 343 | |
| 344 | if (_hostUpTimer.isEnabled()) |
| 345 | { |
| 346 | _hostUpTimer.setEnabled(false); |
| 347 | } |
| Matt Spinler | 3019c6f | 2019-12-11 15:24:45 -0600 | [diff] [blame] | 348 | } |
| Matt Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | void HostNotifier::commandResponse(ResponseStatus status) |
| 352 | { |
| Matt Spinler | f869fcf | 2019-12-11 15:02:20 -0600 | [diff] [blame] | 353 | auto id = _inProgressPEL; |
| 354 | _inProgressPEL = 0; |
| 355 | |
| 356 | if (status == ResponseStatus::success) |
| 357 | { |
| Matt Spinler | 1b41886 | 2023-06-29 12:37:41 -0500 | [diff] [blame] | 358 | lg2::debug("HostNotifier command response success, PEL ID = {ID}", "ID", |
| 359 | lg2::hex, id); |
| Matt Spinler | f869fcf | 2019-12-11 15:02:20 -0600 | [diff] [blame] | 360 | _retryCount = 0; |
| 361 | |
| 362 | _sentPELs.push_back(id); |
| 363 | |
| 364 | _repo.setPELHostTransState(id, TransmissionState::sent); |
| 365 | |
| Matt Spinler | 41293cb | 2019-12-12 13:11:09 -0600 | [diff] [blame] | 366 | // If the host is full, don't send off the next PEL |
| 367 | if (!_hostFull && !_pelQueue.empty()) |
| Matt Spinler | f869fcf | 2019-12-11 15:02:20 -0600 | [diff] [blame] | 368 | { |
| 369 | doNewLogNotify(); |
| 370 | } |
| 371 | } |
| 372 | else |
| 373 | { |
| Matt Spinler | 1b41886 | 2023-06-29 12:37:41 -0500 | [diff] [blame] | 374 | lg2::error("PLDM command response failure, PEL ID = {ID}", "ID", |
| 375 | lg2::hex, id); |
| Matt Spinler | f869fcf | 2019-12-11 15:02:20 -0600 | [diff] [blame] | 376 | // Retry |
| 377 | _pelQueue.push_front(id); |
| 378 | _retryTimer.restartOnce(_hostIface->getReceiveRetryDelay()); |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | void HostNotifier::retryTimerExpired() |
| 383 | { |
| 384 | if (_dataIface.isHostUp()) |
| 385 | { |
| Matt Spinler | 1b41886 | 2023-06-29 12:37:41 -0500 | [diff] [blame] | 386 | lg2::info("Attempting command retry, PEL ID = {ID}", "ID", lg2::hex, |
| 387 | _pelQueue.front()); |
| Matt Spinler | f869fcf | 2019-12-11 15:02:20 -0600 | [diff] [blame] | 388 | _retryCount++; |
| 389 | doNewLogNotify(); |
| 390 | } |
| Matt Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 391 | } |
| 392 | |
| Matt Spinler | 41293cb | 2019-12-12 13:11:09 -0600 | [diff] [blame] | 393 | void HostNotifier::hostFullTimerExpired() |
| 394 | { |
| Matt Spinler | 1b41886 | 2023-06-29 12:37:41 -0500 | [diff] [blame] | 395 | lg2::debug("Host full timer expired, trying send again"); |
| Matt Spinler | 41293cb | 2019-12-12 13:11:09 -0600 | [diff] [blame] | 396 | doNewLogNotify(); |
| 397 | } |
| 398 | |
| Matt Spinler | 3019c6f | 2019-12-11 15:24:45 -0600 | [diff] [blame] | 399 | void HostNotifier::stopCommand() |
| 400 | { |
| 401 | _retryCount = 0; |
| 402 | |
| 403 | if (_inProgressPEL != 0) |
| 404 | { |
| 405 | _pelQueue.push_front(_inProgressPEL); |
| 406 | _inProgressPEL = 0; |
| 407 | } |
| 408 | |
| 409 | if (_retryTimer.isEnabled()) |
| 410 | { |
| 411 | _retryTimer.setEnabled(false); |
| 412 | } |
| 413 | |
| Matt Spinler | 829b052 | 2020-03-04 08:38:46 -0600 | [diff] [blame] | 414 | // Ensure the PLDM instance ID is released |
| 415 | _hostIface->cancelCmd(); |
| Matt Spinler | 3019c6f | 2019-12-11 15:24:45 -0600 | [diff] [blame] | 416 | } |
| 417 | |
| Matt Spinler | cc3b64a | 2019-12-12 11:27:10 -0600 | [diff] [blame] | 418 | void HostNotifier::ackPEL(uint32_t id) |
| 419 | { |
| 420 | _repo.setPELHostTransState(id, TransmissionState::acked); |
| 421 | |
| 422 | // No longer just 'sent', so remove it from the sent list. |
| 423 | auto sent = std::find(_sentPELs.begin(), _sentPELs.end(), id); |
| 424 | if (sent != _sentPELs.end()) |
| 425 | { |
| 426 | _sentPELs.erase(sent); |
| 427 | } |
| Matt Spinler | 41293cb | 2019-12-12 13:11:09 -0600 | [diff] [blame] | 428 | |
| 429 | // An ack means the host is no longer full |
| 430 | if (_hostFullTimer.isEnabled()) |
| 431 | { |
| 432 | _hostFullTimer.setEnabled(false); |
| 433 | } |
| 434 | |
| 435 | if (_hostFull) |
| 436 | { |
| 437 | _hostFull = false; |
| 438 | |
| Matt Spinler | 1b41886 | 2023-06-29 12:37:41 -0500 | [diff] [blame] | 439 | lg2::debug("Host previously full, not anymore after this ack"); |
| Matt Spinler | 5f5352e | 2020-03-05 16:23:27 -0600 | [diff] [blame] | 440 | |
| Matt Spinler | 41293cb | 2019-12-12 13:11:09 -0600 | [diff] [blame] | 441 | // Start sending PELs again, from the event loop |
| 442 | if (!_pelQueue.empty()) |
| 443 | { |
| 444 | scheduleDispatch(); |
| 445 | } |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | void HostNotifier::setHostFull(uint32_t id) |
| 450 | { |
| Matt Spinler | 610e80f | 2023-09-12 09:45:01 -0500 | [diff] [blame] | 451 | lg2::debug("Received Host full indication, PEL ID = {ID}", "ID", lg2::hex, |
| 452 | id); |
| Matt Spinler | 41293cb | 2019-12-12 13:11:09 -0600 | [diff] [blame] | 453 | |
| 454 | _hostFull = true; |
| 455 | |
| 456 | // This PEL needs to get re-sent |
| 457 | auto sent = std::find(_sentPELs.begin(), _sentPELs.end(), id); |
| 458 | if (sent != _sentPELs.end()) |
| 459 | { |
| 460 | _sentPELs.erase(sent); |
| 461 | _repo.setPELHostTransState(id, TransmissionState::newPEL); |
| 462 | |
| 463 | if (std::find(_pelQueue.begin(), _pelQueue.end(), id) == |
| 464 | _pelQueue.end()) |
| 465 | { |
| 466 | _pelQueue.push_front(id); |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | // The only PELs that will be sent when the |
| 471 | // host is full is from this timer callback. |
| 472 | if (!_hostFullTimer.isEnabled()) |
| 473 | { |
| Matt Spinler | 1b41886 | 2023-06-29 12:37:41 -0500 | [diff] [blame] | 474 | lg2::debug("Starting host full timer"); |
| Matt Spinler | 41293cb | 2019-12-12 13:11:09 -0600 | [diff] [blame] | 475 | _hostFullTimer.restartOnce(_hostIface->getHostFullRetryDelay()); |
| 476 | } |
| Matt Spinler | cc3b64a | 2019-12-12 11:27:10 -0600 | [diff] [blame] | 477 | } |
| 478 | |
| Matt Spinler | a19b623 | 2019-12-12 13:30:14 -0600 | [diff] [blame] | 479 | void HostNotifier::setBadPEL(uint32_t id) |
| 480 | { |
| Matt Spinler | 1b41886 | 2023-06-29 12:37:41 -0500 | [diff] [blame] | 481 | lg2::error("PEL rejected by the host, PEL ID = {ID}", "ID", lg2::hex, id); |
| Matt Spinler | a19b623 | 2019-12-12 13:30:14 -0600 | [diff] [blame] | 482 | |
| 483 | auto sent = std::find(_sentPELs.begin(), _sentPELs.end(), id); |
| 484 | if (sent != _sentPELs.end()) |
| 485 | { |
| 486 | _sentPELs.erase(sent); |
| 487 | } |
| 488 | |
| 489 | _repo.setPELHostTransState(id, TransmissionState::badPEL); |
| 490 | } |
| 491 | |
| Matt Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 492 | } // namespace openpower::pels |