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