Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2017 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 | */ |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 16 | #include "fan.hpp" |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 17 | |
Matt Spinler | ae1f8ef | 2020-10-14 16:15:51 -0500 | [diff] [blame] | 18 | #include "logging.hpp" |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 19 | #include "sdbusplus.hpp" |
Matt Spinler | b0412d0 | 2020-10-12 16:53:52 -0500 | [diff] [blame] | 20 | #include "system.hpp" |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 21 | #include "types.hpp" |
Matt Spinler | b1e1851 | 2017-04-27 14:42:33 -0500 | [diff] [blame] | 22 | #include "utility.hpp" |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 23 | |
Jay Meyer | a7aed01 | 2020-10-06 14:32:22 -0500 | [diff] [blame] | 24 | #include <fmt/format.h> |
| 25 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 26 | #include <phosphor-logging/log.hpp> |
| 27 | |
| 28 | #include <algorithm> |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 29 | |
| 30 | namespace phosphor |
| 31 | { |
| 32 | namespace fan |
| 33 | { |
| 34 | namespace monitor |
| 35 | { |
| 36 | |
| 37 | using namespace phosphor::logging; |
Matt Spinler | b0412d0 | 2020-10-12 16:53:52 -0500 | [diff] [blame] | 38 | using namespace sdbusplus::bus::match; |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 39 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 40 | Fan::Fan(Mode mode, sdbusplus::bus::bus& bus, const sdeventplus::Event& event, |
Matt Spinler | b0412d0 | 2020-10-12 16:53:52 -0500 | [diff] [blame] | 41 | std::unique_ptr<trust::Manager>& trust, const FanDefinition& def, |
| 42 | System& system) : |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 43 | _bus(bus), |
| 44 | _name(std::get<fanNameField>(def)), |
| 45 | _deviation(std::get<fanDeviationField>(def)), |
Matt Spinler | c39e859 | 2017-09-28 13:13:08 -0500 | [diff] [blame] | 46 | _numSensorFailsForNonFunc(std::get<numSensorFailsForNonfuncField>(def)), |
Matt Spinler | b0412d0 | 2020-10-12 16:53:52 -0500 | [diff] [blame] | 47 | _trustManager(trust), |
| 48 | #ifdef MONITOR_USE_JSON |
| 49 | _monitorDelay(std::get<monitorStartDelayField>(def)), |
| 50 | _monitorTimer(event, std::bind(std::mem_fn(&Fan::startMonitor), this)), |
| 51 | #endif |
Matt Spinler | b63aa09 | 2020-10-14 09:45:11 -0500 | [diff] [blame] | 52 | _system(system), |
| 53 | _presenceMatch(bus, |
| 54 | rules::propertiesChanged(util::INVENTORY_PATH + _name, |
| 55 | util::INV_ITEM_IFACE), |
| 56 | std::bind(std::mem_fn(&Fan::presenceChanged), this, |
Matt Spinler | 27f6b68 | 2020-10-27 08:43:37 -0500 | [diff] [blame] | 57 | std::placeholders::_1)), |
| 58 | _fanMissingErrorDelay(std::get<fanMissingErrDelayField>(def)) |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 59 | { |
Matt Spinler | ae1f8ef | 2020-10-14 16:15:51 -0500 | [diff] [blame] | 60 | // Start from a known state of functional (even if |
| 61 | // _numSensorFailsForNonFunc is 0) |
Jolie Ku | 4c3c24f | 2020-09-09 11:01:46 +0800 | [diff] [blame] | 62 | updateInventory(true); |
| 63 | |
Matthew Barth | 0a9fe16 | 2018-01-26 12:53:15 -0600 | [diff] [blame] | 64 | // Setup tach sensors for monitoring |
| 65 | auto& sensors = std::get<sensorListField>(def); |
| 66 | for (auto& s : sensors) |
| 67 | { |
| 68 | try |
| 69 | { |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 70 | _sensors.emplace_back(std::make_shared<TachSensor>( |
| 71 | mode, bus, *this, std::get<sensorNameField>(s), |
| 72 | std::get<hasTargetField>(s), std::get<funcDelay>(def), |
| 73 | std::get<targetInterfaceField>(s), std::get<factorField>(s), |
Jolie Ku | 69f2f48 | 2020-10-21 09:59:43 +0800 | [diff] [blame] | 74 | std::get<offsetField>(s), std::get<methodField>(def), |
| 75 | std::get<thresholdField>(s), std::get<timeoutField>(def), |
Matt Spinler | f13b42e | 2020-10-26 15:29:49 -0500 | [diff] [blame] | 76 | std::get<nonfuncRotorErrDelayField>(def), event)); |
Matthew Barth | 0a9fe16 | 2018-01-26 12:53:15 -0600 | [diff] [blame] | 77 | |
| 78 | _trustManager->registerSensor(_sensors.back()); |
| 79 | } |
| 80 | catch (InvalidSensorError& e) |
Jolie Ku | 4c3c24f | 2020-09-09 11:01:46 +0800 | [diff] [blame] | 81 | { |
Matt Spinler | ae1f8ef | 2020-10-14 16:15:51 -0500 | [diff] [blame] | 82 | // Count the number of failed tach sensors, though if |
| 83 | // _numSensorFailsForNonFunc is zero that means the fan should not |
| 84 | // be set to nonfunctional. |
| 85 | if (_numSensorFailsForNonFunc && |
| 86 | (++_numFailedSensor >= _numSensorFailsForNonFunc)) |
Jolie Ku | 5d564a9 | 2020-10-23 09:04:28 +0800 | [diff] [blame] | 87 | { |
| 88 | // Mark associated fan as nonfunctional |
| 89 | updateInventory(false); |
| 90 | } |
Jolie Ku | 4c3c24f | 2020-09-09 11:01:46 +0800 | [diff] [blame] | 91 | } |
Matthew Barth | 0a9fe16 | 2018-01-26 12:53:15 -0600 | [diff] [blame] | 92 | } |
| 93 | |
Matt Spinler | b0412d0 | 2020-10-12 16:53:52 -0500 | [diff] [blame] | 94 | #ifndef MONITOR_USE_JSON |
Matthew Barth | 0a9fe16 | 2018-01-26 12:53:15 -0600 | [diff] [blame] | 95 | // Check current tach state when entering monitor mode |
Matthew Barth | 6ad2843 | 2017-08-22 11:18:19 -0500 | [diff] [blame] | 96 | if (mode != Mode::init) |
| 97 | { |
Matt Spinler | b0412d0 | 2020-10-12 16:53:52 -0500 | [diff] [blame] | 98 | _monitorReady = true; |
| 99 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 100 | // The TachSensors will now have already read the input |
| 101 | // and target values, so check them. |
Matthew Barth | 6ad2843 | 2017-08-22 11:18:19 -0500 | [diff] [blame] | 102 | tachChanged(); |
| 103 | } |
Matt Spinler | b0412d0 | 2020-10-12 16:53:52 -0500 | [diff] [blame] | 104 | #else |
| 105 | // If it used the JSON config, then it also will do all the work |
| 106 | // out of fan-monitor-init, after _monitorDelay. |
| 107 | _monitorTimer.restartOnce(std::chrono::seconds(_monitorDelay)); |
Matt Spinler | b0412d0 | 2020-10-12 16:53:52 -0500 | [diff] [blame] | 108 | #endif |
Matt Spinler | b63aa09 | 2020-10-14 09:45:11 -0500 | [diff] [blame] | 109 | |
| 110 | // Get the initial presence state |
Matt Spinler | 0648014 | 2021-01-20 13:45:31 -0600 | [diff] [blame] | 111 | bool available = true; |
| 112 | |
| 113 | try |
| 114 | { |
| 115 | _present = util::SDBusPlus::getProperty<bool>( |
| 116 | util::INVENTORY_PATH + _name, util::INV_ITEM_IFACE, "Present"); |
| 117 | } |
| 118 | catch (const util::DBusServiceError& e) |
| 119 | { |
| 120 | // This could be the initial boot and phosphor-fan-presence hasn't |
| 121 | // written to the inventory yet. |
| 122 | available = false; |
| 123 | } |
Matt Spinler | 27f6b68 | 2020-10-27 08:43:37 -0500 | [diff] [blame] | 124 | |
| 125 | if (_fanMissingErrorDelay) |
| 126 | { |
| 127 | _fanMissingErrorTimer = std::make_unique< |
| 128 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>>( |
| 129 | event, std::bind(&System::fanMissingErrorTimerExpired, &system, |
| 130 | std::ref(*this))); |
| 131 | |
Matt Spinler | 0648014 | 2021-01-20 13:45:31 -0600 | [diff] [blame] | 132 | if (!_present && available) |
Matt Spinler | 27f6b68 | 2020-10-27 08:43:37 -0500 | [diff] [blame] | 133 | { |
Matt Spinler | ac37297 | 2021-01-25 15:11:22 -0600 | [diff] [blame] | 134 | getLogger().log( |
| 135 | fmt::format("On startup, fan {} is missing", _name)); |
Matt Spinler | 27f6b68 | 2020-10-27 08:43:37 -0500 | [diff] [blame] | 136 | _fanMissingErrorTimer->restartOnce( |
| 137 | std::chrono::seconds{*_fanMissingErrorDelay}); |
| 138 | } |
| 139 | } |
Matt Spinler | b0412d0 | 2020-10-12 16:53:52 -0500 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | void Fan::startMonitor() |
| 143 | { |
| 144 | _monitorReady = true; |
| 145 | |
| 146 | tachChanged(); |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 147 | } |
| 148 | |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 149 | void Fan::tachChanged() |
| 150 | { |
Matt Spinler | b0412d0 | 2020-10-12 16:53:52 -0500 | [diff] [blame] | 151 | if (_monitorReady) |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 152 | { |
Matt Spinler | b0412d0 | 2020-10-12 16:53:52 -0500 | [diff] [blame] | 153 | for (auto& s : _sensors) |
| 154 | { |
| 155 | tachChanged(*s); |
| 156 | } |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 157 | } |
| 158 | } |
| 159 | |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 160 | void Fan::tachChanged(TachSensor& sensor) |
| 161 | { |
Matt Spinler | c39e859 | 2017-09-28 13:13:08 -0500 | [diff] [blame] | 162 | if (_trustManager->active()) |
| 163 | { |
| 164 | if (!_trustManager->checkTrust(sensor)) |
| 165 | { |
| 166 | return; |
| 167 | } |
| 168 | } |
| 169 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 170 | // If this sensor is out of range at this moment, start |
| 171 | // its timer, at the end of which the inventory |
| 172 | // for the fan may get updated to not functional. |
Matt Spinler | a4c8f1f | 2017-04-27 14:38:38 -0500 | [diff] [blame] | 173 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 174 | // If this sensor is OK, put everything back into a good state. |
Matt Spinler | a4c8f1f | 2017-04-27 14:38:38 -0500 | [diff] [blame] | 175 | |
| 176 | if (outOfRange(sensor)) |
| 177 | { |
Matthew Barth | e11cbc6 | 2018-02-20 12:11:07 -0600 | [diff] [blame] | 178 | if (sensor.functional()) |
Matt Spinler | a4c8f1f | 2017-04-27 14:38:38 -0500 | [diff] [blame] | 179 | { |
Jolie Ku | 69f2f48 | 2020-10-21 09:59:43 +0800 | [diff] [blame] | 180 | switch (sensor.getMethod()) |
| 181 | { |
| 182 | case MethodMode::timebased: |
| 183 | // Start nonfunctional timer if not already running |
| 184 | sensor.startTimer(TimerMode::nonfunc); |
| 185 | break; |
| 186 | case MethodMode::count: |
| 187 | sensor.setCounter(true); |
| 188 | if (sensor.getCounter() >= sensor.getThreshold()) |
| 189 | { |
| 190 | updateState(sensor); |
| 191 | } |
| 192 | break; |
| 193 | } |
Matt Spinler | a4c8f1f | 2017-04-27 14:38:38 -0500 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | else |
| 197 | { |
Jolie Ku | 69f2f48 | 2020-10-21 09:59:43 +0800 | [diff] [blame] | 198 | switch (sensor.getMethod()) |
Matt Spinler | a4c8f1f | 2017-04-27 14:38:38 -0500 | [diff] [blame] | 199 | { |
Jolie Ku | 69f2f48 | 2020-10-21 09:59:43 +0800 | [diff] [blame] | 200 | case MethodMode::timebased: |
| 201 | if (sensor.functional()) |
| 202 | { |
Matthew Barth | 11b5d8f | 2021-01-28 14:04:09 -0600 | [diff] [blame] | 203 | if (sensor.timerRunning()) |
| 204 | { |
| 205 | sensor.stopTimer(); |
| 206 | } |
Jolie Ku | 69f2f48 | 2020-10-21 09:59:43 +0800 | [diff] [blame] | 207 | } |
| 208 | else |
| 209 | { |
| 210 | // Start functional timer if not already running |
| 211 | sensor.startTimer(TimerMode::func); |
| 212 | } |
| 213 | break; |
| 214 | case MethodMode::count: |
| 215 | sensor.setCounter(false); |
| 216 | if (!sensor.functional() && sensor.getCounter() == 0) |
| 217 | { |
| 218 | updateState(sensor); |
| 219 | } |
| 220 | break; |
Matt Spinler | a4c8f1f | 2017-04-27 14:38:38 -0500 | [diff] [blame] | 221 | } |
| 222 | } |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 223 | } |
| 224 | |
Matthew Barth | f552ea5 | 2018-01-15 16:22:04 -0600 | [diff] [blame] | 225 | uint64_t Fan::findTargetSpeed() |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 226 | { |
| 227 | uint64_t target = 0; |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 228 | // The sensor doesn't support a target, |
| 229 | // so get it from another sensor. |
Matthew Barth | f552ea5 | 2018-01-15 16:22:04 -0600 | [diff] [blame] | 230 | auto s = std::find_if(_sensors.begin(), _sensors.end(), |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 231 | [](const auto& s) { return s->hasTarget(); }); |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 232 | |
Matthew Barth | f552ea5 | 2018-01-15 16:22:04 -0600 | [diff] [blame] | 233 | if (s != _sensors.end()) |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 234 | { |
Matthew Barth | f552ea5 | 2018-01-15 16:22:04 -0600 | [diff] [blame] | 235 | target = (*s)->getTarget(); |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | return target; |
| 239 | } |
| 240 | |
Matthew Barth | 7c23a04 | 2021-01-26 16:21:45 -0600 | [diff] [blame] | 241 | size_t Fan::countNonFunctionalSensors() |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 242 | { |
Matthew Barth | 7c23a04 | 2021-01-26 16:21:45 -0600 | [diff] [blame] | 243 | return std::count_if(_sensors.begin(), _sensors.end(), |
| 244 | [](const auto& s) { return !s->functional(); }); |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 245 | } |
| 246 | |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 247 | bool Fan::outOfRange(const TachSensor& sensor) |
| 248 | { |
| 249 | auto actual = static_cast<uint64_t>(sensor.getInput()); |
Matthew Barth | 7c23a04 | 2021-01-26 16:21:45 -0600 | [diff] [blame] | 250 | auto range = sensor.getRange(_deviation); |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 251 | |
Matthew Barth | 7c23a04 | 2021-01-26 16:21:45 -0600 | [diff] [blame] | 252 | if ((actual < range.first) || (actual > range.second)) |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 253 | { |
| 254 | return true; |
| 255 | } |
| 256 | |
| 257 | return false; |
| 258 | } |
| 259 | |
Jolie Ku | 69f2f48 | 2020-10-21 09:59:43 +0800 | [diff] [blame] | 260 | void Fan::updateState(TachSensor& sensor) |
Matt Spinler | a9406a7 | 2017-04-27 14:29:24 -0500 | [diff] [blame] | 261 | { |
Matthew Barth | 7c23a04 | 2021-01-26 16:21:45 -0600 | [diff] [blame] | 262 | auto range = sensor.getRange(_deviation); |
Matthew Barth | e11cbc6 | 2018-02-20 12:11:07 -0600 | [diff] [blame] | 263 | sensor.setFunctional(!sensor.functional()); |
Matt Spinler | ae1f8ef | 2020-10-14 16:15:51 -0500 | [diff] [blame] | 264 | getLogger().log( |
| 265 | fmt::format("Setting tach sensor {} functional state to {}. " |
Matthew Barth | 7c23a04 | 2021-01-26 16:21:45 -0600 | [diff] [blame] | 266 | "[target = {}, input = {}, allowed range = ({} - {})]", |
| 267 | sensor.name(), sensor.functional(), sensor.getTarget(), |
| 268 | sensor.getInput(), range.first, range.second)); |
Matt Spinler | ae1f8ef | 2020-10-14 16:15:51 -0500 | [diff] [blame] | 269 | |
| 270 | // A zero value for _numSensorFailsForNonFunc means we aren't dealing |
| 271 | // with fan FRU functional status, only sensor functional status. |
| 272 | if (_numSensorFailsForNonFunc) |
Matthew Barth | e11cbc6 | 2018-02-20 12:11:07 -0600 | [diff] [blame] | 273 | { |
Matthew Barth | 7c23a04 | 2021-01-26 16:21:45 -0600 | [diff] [blame] | 274 | auto numNonFuncSensors = countNonFunctionalSensors(); |
Matt Spinler | ae1f8ef | 2020-10-14 16:15:51 -0500 | [diff] [blame] | 275 | // If the fan was nonfunctional and enough sensors are now OK, |
Matthew Barth | 7c23a04 | 2021-01-26 16:21:45 -0600 | [diff] [blame] | 276 | // the fan can be set to functional |
| 277 | if (!_functional && !(numNonFuncSensors >= _numSensorFailsForNonFunc)) |
Matt Spinler | ae1f8ef | 2020-10-14 16:15:51 -0500 | [diff] [blame] | 278 | { |
Matthew Barth | 7c23a04 | 2021-01-26 16:21:45 -0600 | [diff] [blame] | 279 | getLogger().log(fmt::format("Setting fan {} to functional, number " |
| 280 | "of nonfunctional sensors = {}", |
| 281 | _name, numNonFuncSensors)); |
Matt Spinler | ae1f8ef | 2020-10-14 16:15:51 -0500 | [diff] [blame] | 282 | updateInventory(true); |
| 283 | } |
Matt Spinler | a9406a7 | 2017-04-27 14:29:24 -0500 | [diff] [blame] | 284 | |
Matt Spinler | ae1f8ef | 2020-10-14 16:15:51 -0500 | [diff] [blame] | 285 | // If the fan is currently functional, but too many |
| 286 | // contained sensors are now nonfunctional, update |
Matthew Barth | 7c23a04 | 2021-01-26 16:21:45 -0600 | [diff] [blame] | 287 | // the fan to nonfunctional. |
| 288 | if (_functional && (numNonFuncSensors >= _numSensorFailsForNonFunc)) |
Matt Spinler | ae1f8ef | 2020-10-14 16:15:51 -0500 | [diff] [blame] | 289 | { |
Matthew Barth | 7c23a04 | 2021-01-26 16:21:45 -0600 | [diff] [blame] | 290 | getLogger().log(fmt::format("Setting fan {} to nonfunctional, " |
| 291 | "number of nonfunctional sensors = {}", |
| 292 | _name, numNonFuncSensors)); |
Matt Spinler | ae1f8ef | 2020-10-14 16:15:51 -0500 | [diff] [blame] | 293 | updateInventory(false); |
| 294 | } |
Matt Spinler | b1e1851 | 2017-04-27 14:42:33 -0500 | [diff] [blame] | 295 | } |
Matt Spinler | b63aa09 | 2020-10-14 09:45:11 -0500 | [diff] [blame] | 296 | |
| 297 | _system.fanStatusChange(*this); |
Matt Spinler | a9406a7 | 2017-04-27 14:29:24 -0500 | [diff] [blame] | 298 | } |
| 299 | |
Matt Spinler | b1e1851 | 2017-04-27 14:42:33 -0500 | [diff] [blame] | 300 | void Fan::updateInventory(bool functional) |
| 301 | { |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 302 | auto objectMap = |
| 303 | util::getObjMap<bool>(_name, util::OPERATIONAL_STATUS_INTF, |
| 304 | util::FUNCTIONAL_PROPERTY, functional); |
Matthew Barth | 51dd185 | 2017-11-16 15:21:13 -0600 | [diff] [blame] | 305 | auto response = util::SDBusPlus::lookupAndCallMethod( |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 306 | _bus, util::INVENTORY_PATH, util::INVENTORY_INTF, "Notify", objectMap); |
Matt Spinler | b1e1851 | 2017-04-27 14:42:33 -0500 | [diff] [blame] | 307 | if (response.is_method_error()) |
| 308 | { |
| 309 | log<level::ERR>("Error in Notify call to update inventory"); |
| 310 | return; |
| 311 | } |
| 312 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 313 | // This will always track the current state of the inventory. |
Matt Spinler | b1e1851 | 2017-04-27 14:42:33 -0500 | [diff] [blame] | 314 | _functional = functional; |
| 315 | } |
| 316 | |
Matt Spinler | b63aa09 | 2020-10-14 09:45:11 -0500 | [diff] [blame] | 317 | void Fan::presenceChanged(sdbusplus::message::message& msg) |
| 318 | { |
| 319 | std::string interface; |
| 320 | std::map<std::string, std::variant<bool>> properties; |
| 321 | |
| 322 | msg.read(interface, properties); |
| 323 | |
| 324 | auto presentProp = properties.find("Present"); |
| 325 | if (presentProp != properties.end()) |
| 326 | { |
| 327 | _present = std::get<bool>(presentProp->second); |
| 328 | |
Matt Spinler | 27f6b68 | 2020-10-27 08:43:37 -0500 | [diff] [blame] | 329 | getLogger().log( |
Matt Spinler | ac37297 | 2021-01-25 15:11:22 -0600 | [diff] [blame] | 330 | fmt::format("Fan {} presence state change to {}", _name, _present)); |
Matt Spinler | 27f6b68 | 2020-10-27 08:43:37 -0500 | [diff] [blame] | 331 | |
Matt Spinler | b63aa09 | 2020-10-14 09:45:11 -0500 | [diff] [blame] | 332 | _system.fanStatusChange(*this); |
Matt Spinler | 27f6b68 | 2020-10-27 08:43:37 -0500 | [diff] [blame] | 333 | |
| 334 | if (_fanMissingErrorDelay) |
| 335 | { |
| 336 | if (!_present) |
| 337 | { |
| 338 | _fanMissingErrorTimer->restartOnce( |
| 339 | std::chrono::seconds{*_fanMissingErrorDelay}); |
| 340 | } |
| 341 | else if (_fanMissingErrorTimer->isEnabled()) |
| 342 | { |
| 343 | _fanMissingErrorTimer->setEnabled(false); |
| 344 | } |
| 345 | } |
Matt Spinler | b63aa09 | 2020-10-14 09:45:11 -0500 | [diff] [blame] | 346 | } |
| 347 | } |
Matt Spinler | f13b42e | 2020-10-26 15:29:49 -0500 | [diff] [blame] | 348 | |
| 349 | void Fan::sensorErrorTimerExpired(const TachSensor& sensor) |
| 350 | { |
| 351 | if (_present) |
| 352 | { |
| 353 | _system.sensorErrorTimerExpired(*this, sensor); |
| 354 | } |
| 355 | } |
| 356 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 357 | } // namespace monitor |
| 358 | } // namespace fan |
| 359 | } // namespace phosphor |