Matthew Barth | fd05d64 | 2019-11-14 15:01:57 -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 | */ |
Jolie Ku | 1a56865 | 2020-08-24 16:32:15 +0800 | [diff] [blame] | 16 | #include "json_parser.hpp" |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 17 | |
| 18 | #include "anyof.hpp" |
| 19 | #include "fallback.hpp" |
| 20 | #include "gpio.hpp" |
Jolie Ku | 1a56865 | 2020-08-24 16:32:15 +0800 | [diff] [blame] | 21 | #include "json_config.hpp" |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 22 | #include "sdbusplus.hpp" |
| 23 | #include "tach.hpp" |
| 24 | |
Matthew Barth | 0961fae | 2019-11-15 09:00:27 -0600 | [diff] [blame] | 25 | #include <nlohmann/json.hpp> |
Anwaar Hadi | ebead9a | 2025-03-19 20:35:57 +0000 | [diff] [blame] | 26 | #include <phosphor-logging/lg2.hpp> |
Matthew Barth | 5060b10 | 2019-12-16 10:46:35 -0600 | [diff] [blame] | 27 | #include <sdbusplus/bus.hpp> |
Mike Capps | a35a890 | 2021-06-10 10:20:14 -0400 | [diff] [blame] | 28 | #include <xyz/openbmc_project/Logging/Create/server.hpp> |
| 29 | #include <xyz/openbmc_project/Logging/Entry/server.hpp> |
Matthew Barth | fd05d64 | 2019-11-14 15:01:57 -0600 | [diff] [blame] | 30 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 31 | #include <filesystem> |
| 32 | #include <fstream> |
| 33 | #include <string> |
Matthew Barth | fd05d64 | 2019-11-14 15:01:57 -0600 | [diff] [blame] | 34 | |
| 35 | namespace phosphor |
| 36 | { |
| 37 | namespace fan |
| 38 | { |
| 39 | namespace presence |
| 40 | { |
| 41 | |
Matthew Barth | 0961fae | 2019-11-15 09:00:27 -0600 | [diff] [blame] | 42 | using json = nlohmann::json; |
| 43 | namespace fs = std::filesystem; |
Matthew Barth | 0961fae | 2019-11-15 09:00:27 -0600 | [diff] [blame] | 44 | |
Matthew Barth | fd05d64 | 2019-11-14 15:01:57 -0600 | [diff] [blame] | 45 | policies JsonConfig::_policies; |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 46 | const std::map<std::string, methodHandler> JsonConfig::_methods = { |
| 47 | {"tach", method::getTach}, {"gpio", method::getGpio}}; |
| 48 | const std::map<std::string, rpolicyHandler> JsonConfig::_rpolicies = { |
| 49 | {"anyof", rpolicy::getAnyof}, {"fallback", rpolicy::getFallback}}; |
Matthew Barth | fd05d64 | 2019-11-14 15:01:57 -0600 | [diff] [blame] | 50 | |
Mike Capps | a35a890 | 2021-06-10 10:20:14 -0400 | [diff] [blame] | 51 | const auto loggingPath = "/xyz/openbmc_project/logging"; |
| 52 | const auto loggingCreateIface = "xyz.openbmc_project.Logging.Create"; |
| 53 | |
Patrick Williams | 61b7329 | 2023-05-10 07:50:12 -0500 | [diff] [blame] | 54 | JsonConfig::JsonConfig(sdbusplus::bus_t& bus) : _bus(bus) {} |
Jolie Ku | 1a56865 | 2020-08-24 16:32:15 +0800 | [diff] [blame] | 55 | |
Matthew Barth | 5b83991 | 2021-06-21 14:46:34 -0500 | [diff] [blame] | 56 | void JsonConfig::start() |
Matt Spinler | 0daedd1 | 2021-01-25 14:46:03 -0600 | [diff] [blame] | 57 | { |
Matthew Barth | 5b83991 | 2021-06-21 14:46:34 -0500 | [diff] [blame] | 58 | using config = fan::JsonConfig; |
| 59 | |
Matt Spinler | dfc8c4d | 2022-06-22 16:52:27 -0500 | [diff] [blame] | 60 | if (!_loaded) |
Matt Spinler | 0daedd1 | 2021-01-25 14:46:03 -0600 | [diff] [blame] | 61 | { |
Mike Capps | 808d7fe | 2022-06-13 10:12:16 -0400 | [diff] [blame] | 62 | process(config::load(config::getConfFile(confAppName, confFileName))); |
Matt Spinler | dfc8c4d | 2022-06-22 16:52:27 -0500 | [diff] [blame] | 63 | |
| 64 | _loaded = true; |
| 65 | |
| 66 | for (auto& p : _policies) |
| 67 | { |
| 68 | p->monitor(); |
| 69 | } |
Matt Spinler | 0daedd1 | 2021-01-25 14:46:03 -0600 | [diff] [blame] | 70 | } |
Matthew Barth | fd05d64 | 2019-11-14 15:01:57 -0600 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | const policies& JsonConfig::get() |
| 74 | { |
| 75 | return _policies; |
| 76 | } |
| 77 | |
Mike Capps | 808d7fe | 2022-06-13 10:12:16 -0400 | [diff] [blame] | 78 | void JsonConfig::sighupHandler(sdeventplus::source::Signal& /*sigSrc*/, |
| 79 | const struct signalfd_siginfo* /*sigInfo*/) |
Matthew Barth | f3e7047 | 2019-12-03 13:33:20 -0600 | [diff] [blame] | 80 | { |
| 81 | try |
| 82 | { |
Jolie Ku | 1a56865 | 2020-08-24 16:32:15 +0800 | [diff] [blame] | 83 | using config = fan::JsonConfig; |
| 84 | |
Matt Spinler | 9e9f599 | 2020-09-30 08:29:24 -0500 | [diff] [blame] | 85 | _reporter.reset(); |
| 86 | |
Matthew Barth | f3e7047 | 2019-12-03 13:33:20 -0600 | [diff] [blame] | 87 | // Load and process the json configuration |
Mike Capps | 808d7fe | 2022-06-13 10:12:16 -0400 | [diff] [blame] | 88 | process(config::load(config::getConfFile(confAppName, confFileName))); |
Jolie Ku | 1a56865 | 2020-08-24 16:32:15 +0800 | [diff] [blame] | 89 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 90 | for (auto& p : _policies) |
Matthew Barth | f3e7047 | 2019-12-03 13:33:20 -0600 | [diff] [blame] | 91 | { |
| 92 | p->monitor(); |
| 93 | } |
Anwaar Hadi | ebead9a | 2025-03-19 20:35:57 +0000 | [diff] [blame] | 94 | lg2::info("Configuration loaded successfully"); |
Matthew Barth | f3e7047 | 2019-12-03 13:33:20 -0600 | [diff] [blame] | 95 | } |
Patrick Williams | ddb773b | 2021-10-06 11:24:49 -0500 | [diff] [blame] | 96 | catch (const std::runtime_error& re) |
Matthew Barth | f3e7047 | 2019-12-03 13:33:20 -0600 | [diff] [blame] | 97 | { |
Anwaar Hadi | ebead9a | 2025-03-19 20:35:57 +0000 | [diff] [blame] | 98 | lg2::error("Error loading config, no config changes made: {ERROR}", |
| 99 | "ERROR", re); |
Matthew Barth | f3e7047 | 2019-12-03 13:33:20 -0600 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |
Matthew Barth | 4a94dec | 2019-11-15 10:40:47 -0600 | [diff] [blame] | 103 | void JsonConfig::process(const json& jsonConf) |
| 104 | { |
Matthew Barth | f3e7047 | 2019-12-03 13:33:20 -0600 | [diff] [blame] | 105 | policies policies; |
| 106 | std::vector<fanPolicy> fans; |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 107 | // Set the expected number of fan entries |
| 108 | // to be size of the list of fan json config entries |
| 109 | // (Must be done to eliminate vector reallocation of fan references) |
Matt Spinler | 9e9f599 | 2020-09-30 08:29:24 -0500 | [diff] [blame] | 110 | fans.reserve(jsonConf.size()); |
| 111 | for (auto& member : jsonConf) |
Matthew Barth | 4a94dec | 2019-11-15 10:40:47 -0600 | [diff] [blame] | 112 | { |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 113 | if (!member.contains("name") || !member.contains("path") || |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 114 | !member.contains("methods") || !member.contains("rpolicy")) |
Matthew Barth | 4a94dec | 2019-11-15 10:40:47 -0600 | [diff] [blame] | 115 | { |
Anwaar Hadi | ebead9a | 2025-03-19 20:35:57 +0000 | [diff] [blame] | 116 | lg2::error( |
| 117 | "Missing one of the required fan presence properties, which are: 'name, path, methods, rpolicy'"); |
Matthew Barth | 4a94dec | 2019-11-15 10:40:47 -0600 | [diff] [blame] | 118 | throw std::runtime_error( |
| 119 | "Missing required fan presence properties"); |
| 120 | } |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 121 | |
| 122 | // Loop thru the configured methods of presence detection |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 123 | std::vector<std::unique_ptr<PresenceSensor>> sensors; |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 124 | for (auto& method : member["methods"].items()) |
| 125 | { |
| 126 | if (!method.value().contains("type")) |
| 127 | { |
Anwaar Hadi | ebead9a | 2025-03-19 20:35:57 +0000 | [diff] [blame] | 128 | lg2::error( |
| 129 | "Missing required fan presence method type for fan {FAN_NAME}", |
| 130 | "FAN_NAME", member["name"].get<std::string>()); |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 131 | throw std::runtime_error( |
| 132 | "Missing required fan presence method type"); |
| 133 | } |
| 134 | // The method type of fan presence detection |
| 135 | // (Must have a supported function within the method namespace) |
| 136 | auto type = method.value()["type"].get<std::string>(); |
| 137 | std::transform(type.begin(), type.end(), type.begin(), tolower); |
| 138 | auto func = _methods.find(type); |
| 139 | if (func != _methods.end()) |
| 140 | { |
| 141 | // Call function for method type |
Matthew Barth | f3e7047 | 2019-12-03 13:33:20 -0600 | [diff] [blame] | 142 | auto sensor = func->second(fans.size(), method.value()); |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 143 | if (sensor) |
| 144 | { |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 145 | sensors.emplace_back(std::move(sensor)); |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | else |
| 149 | { |
Anwaar Hadi | ebead9a | 2025-03-19 20:35:57 +0000 | [diff] [blame] | 150 | lg2::error( |
| 151 | "Invalid fan presence method type {METHOD_TYPE} for fan {FAN_NAME}", |
| 152 | "FAN_NAME", member["name"].get<std::string>(), |
| 153 | "METHOD_TYPE", type); |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 154 | throw std::runtime_error("Invalid fan presence method type"); |
| 155 | } |
| 156 | } |
Matt Spinler | 9e9f599 | 2020-09-30 08:29:24 -0500 | [diff] [blame] | 157 | |
| 158 | // Get the amount of time a fan must be not present before |
| 159 | // creating an error. |
| 160 | std::optional<size_t> timeUntilError; |
| 161 | if (member.contains("fan_missing_error_time")) |
| 162 | { |
| 163 | timeUntilError = member["fan_missing_error_time"].get<size_t>(); |
| 164 | } |
| 165 | |
Matt Spinler | bc4179e | 2022-10-04 15:15:06 -0500 | [diff] [blame] | 166 | std::unique_ptr<EEPROMDevice> eepromDevice; |
| 167 | if (member.contains("eeprom")) |
| 168 | { |
| 169 | const auto& eeprom = member.at("eeprom"); |
| 170 | if (!eeprom.contains("bus_address") || |
| 171 | !eeprom.contains("driver_name") || |
| 172 | !eeprom.contains("bind_delay_ms")) |
| 173 | { |
Anwaar Hadi | ebead9a | 2025-03-19 20:35:57 +0000 | [diff] [blame] | 174 | lg2::error( |
| 175 | "Missing address, driver_name, or bind_delay_ms in eeprom section for fan {FAN_NAME}", |
| 176 | "FAN_NAME", member["name"].get<std::string>()); |
Matt Spinler | bc4179e | 2022-10-04 15:15:06 -0500 | [diff] [blame] | 177 | |
| 178 | throw std::runtime_error("Missing address, driver_name, or " |
| 179 | "bind_delay_ms in eeprom section"); |
| 180 | } |
| 181 | eepromDevice = std::make_unique<EEPROMDevice>( |
| 182 | eeprom["bus_address"].get<std::string>(), |
| 183 | eeprom["driver_name"].get<std::string>(), |
| 184 | eeprom["bind_delay_ms"].get<size_t>()); |
| 185 | } |
| 186 | |
Patrick Williams | dfddd64 | 2024-08-16 15:21:51 -0400 | [diff] [blame] | 187 | auto fan = |
| 188 | std::make_tuple(member["name"], member["path"], timeUntilError); |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 189 | // Create a fan object |
Matthew Barth | f3e7047 | 2019-12-03 13:33:20 -0600 | [diff] [blame] | 190 | fans.emplace_back(std::make_tuple(fan, std::move(sensors))); |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 191 | |
| 192 | // Add fan presence policy |
Patrick Williams | dfddd64 | 2024-08-16 15:21:51 -0400 | [diff] [blame] | 193 | auto policy = |
| 194 | getPolicy(member["rpolicy"], fans.back(), std::move(eepromDevice)); |
Matthew Barth | f3e7047 | 2019-12-03 13:33:20 -0600 | [diff] [blame] | 195 | if (policy) |
| 196 | { |
| 197 | policies.emplace_back(std::move(policy)); |
| 198 | } |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 199 | } |
Matthew Barth | f3e7047 | 2019-12-03 13:33:20 -0600 | [diff] [blame] | 200 | |
| 201 | // Success, refresh fans and policies lists |
| 202 | _fans.clear(); |
| 203 | _fans.swap(fans); |
| 204 | |
| 205 | _policies.clear(); |
| 206 | _policies.swap(policies); |
Matt Spinler | e812239 | 2020-09-24 13:22:18 -0500 | [diff] [blame] | 207 | |
| 208 | // Create the error reporter class if necessary |
Matt Spinler | 9e9f599 | 2020-09-30 08:29:24 -0500 | [diff] [blame] | 209 | if (std::any_of(_fans.begin(), _fans.end(), [](const auto& fan) { |
Patrick Williams | dfddd64 | 2024-08-16 15:21:51 -0400 | [diff] [blame] | 210 | return std::get<std::optional<size_t>>(std::get<Fan>(fan)) != |
| 211 | std::nullopt; |
| 212 | })) |
Matt Spinler | e812239 | 2020-09-24 13:22:18 -0500 | [diff] [blame] | 213 | { |
Matt Spinler | 9e9f599 | 2020-09-30 08:29:24 -0500 | [diff] [blame] | 214 | _reporter = std::make_unique<ErrorReporter>(_bus, _fans); |
Matt Spinler | e812239 | 2020-09-24 13:22:18 -0500 | [diff] [blame] | 215 | } |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 216 | } |
| 217 | |
Patrick Williams | 4fa67aa | 2025-02-03 14:28:47 -0500 | [diff] [blame] | 218 | std::unique_ptr<RedundancyPolicy> JsonConfig::getPolicy( |
| 219 | const json& rpolicy, const fanPolicy& fpolicy, |
| 220 | std::unique_ptr<EEPROMDevice> eepromDevice) |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 221 | { |
| 222 | if (!rpolicy.contains("type")) |
| 223 | { |
Anwaar Hadi | ebead9a | 2025-03-19 20:35:57 +0000 | [diff] [blame] | 224 | lg2::error( |
| 225 | "Missing required fan presence policy type for fan {FAN_NAME}", |
| 226 | "FAN_NAME", std::get<fanPolicyFanPos>(std::get<Fan>(fpolicy))); |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 227 | throw std::runtime_error("Missing required fan presence policy type"); |
| 228 | } |
| 229 | |
| 230 | // The redundancy policy type for fan presence detection |
| 231 | // (Must have a supported function within the rpolicy namespace) |
| 232 | auto type = rpolicy["type"].get<std::string>(); |
| 233 | std::transform(type.begin(), type.end(), type.begin(), tolower); |
| 234 | auto func = _rpolicies.find(type); |
| 235 | if (func != _rpolicies.end()) |
| 236 | { |
Matthew Barth | f3e7047 | 2019-12-03 13:33:20 -0600 | [diff] [blame] | 237 | // Call function for redundancy policy type and return the policy |
Matt Spinler | bc4179e | 2022-10-04 15:15:06 -0500 | [diff] [blame] | 238 | return func->second(fpolicy, std::move(eepromDevice)); |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 239 | } |
| 240 | else |
| 241 | { |
Anwaar Hadi | ebead9a | 2025-03-19 20:35:57 +0000 | [diff] [blame] | 242 | lg2::error( |
| 243 | "Invalid fan presence policy type {RPOLICY_TYPE} for fan {FAN_NAME}", |
| 244 | "FAN_NAME", std::get<fanPolicyFanPos>(std::get<Fan>(fpolicy)), |
| 245 | "RPOLICY_TYPE", type); |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 246 | throw std::runtime_error("Invalid fan presence methods policy type"); |
Matthew Barth | 4a94dec | 2019-11-15 10:40:47 -0600 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 250 | /** |
| 251 | * Methods of fan presence detection function definitions |
| 252 | */ |
| 253 | namespace method |
| 254 | { |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 255 | // Get a constructed presence sensor for fan presence detection by tach |
| 256 | std::unique_ptr<PresenceSensor> getTach(size_t fanIndex, const json& method) |
| 257 | { |
| 258 | if (!method.contains("sensors") || method["sensors"].size() == 0) |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 259 | { |
Anwaar Hadi | ebead9a | 2025-03-19 20:35:57 +0000 | [diff] [blame] | 260 | lg2::error( |
| 261 | "Missing required tach method property 'sensors' for fan index {FAN_ENTRY}", |
| 262 | "FAN_ENTRY", fanIndex); |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 263 | throw std::runtime_error("Missing required tach method properties"); |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 264 | } |
| 265 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 266 | std::vector<std::string> sensors; |
| 267 | for (auto& sensor : method["sensors"]) |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 268 | { |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 269 | sensors.emplace_back(sensor.get<std::string>()); |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 270 | } |
| 271 | |
Patrick Williams | dfddd64 | 2024-08-16 15:21:51 -0400 | [diff] [blame] | 272 | return std::make_unique<PolicyAccess<Tach, JsonConfig>>( |
| 273 | fanIndex, std::move(sensors)); |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | // Get a constructed presence sensor for fan presence detection by gpio |
| 277 | std::unique_ptr<PresenceSensor> getGpio(size_t fanIndex, const json& method) |
| 278 | { |
| 279 | if (!method.contains("physpath") || !method.contains("devpath") || |
| 280 | !method.contains("key")) |
| 281 | { |
Anwaar Hadi | ebead9a | 2025-03-19 20:35:57 +0000 | [diff] [blame] | 282 | lg2::error( |
| 283 | "Missing one of the required gpio method properties for fan index {FAN_ENTRY}, which are: 'physpath, devpath, key'", |
| 284 | "FAN_ENTRY", fanIndex); |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 285 | throw std::runtime_error("Missing required gpio method properties"); |
| 286 | } |
| 287 | |
| 288 | auto physpath = method["physpath"].get<std::string>(); |
| 289 | auto devpath = method["devpath"].get<std::string>(); |
| 290 | auto key = method["key"].get<unsigned int>(); |
| 291 | |
Mike Capps | a35a890 | 2021-06-10 10:20:14 -0400 | [diff] [blame] | 292 | try |
| 293 | { |
| 294 | return std::make_unique<PolicyAccess<Gpio, JsonConfig>>( |
| 295 | fanIndex, physpath, devpath, key); |
| 296 | } |
| 297 | catch (const sdbusplus::exception_t& e) |
| 298 | { |
| 299 | namespace sdlogging = sdbusplus::xyz::openbmc_project::Logging::server; |
| 300 | |
Anwaar Hadi | ebead9a | 2025-03-19 20:35:57 +0000 | [diff] [blame] | 301 | lg2::error( |
| 302 | "Error creating Gpio device bridge, hardware not detected: {ERROR}", |
| 303 | "ERROR", e); |
Mike Capps | a35a890 | 2021-06-10 10:20:14 -0400 | [diff] [blame] | 304 | |
| 305 | auto severity = |
| 306 | sdlogging::convertForMessage(sdlogging::Entry::Level::Error); |
| 307 | |
| 308 | std::map<std::string, std::string> additionalData{ |
| 309 | {"PHYSPATH", physpath}, |
| 310 | {"DEVPATH", devpath}, |
| 311 | {"FANINDEX", std::to_string(fanIndex)}}; |
| 312 | |
| 313 | try |
| 314 | { |
Mike Capps | a35a890 | 2021-06-10 10:20:14 -0400 | [diff] [blame] | 315 | util::SDBusPlus::lookupAndCallMethod( |
| 316 | loggingPath, loggingCreateIface, "Create", |
| 317 | "xyz.openbmc_project.Fan.Presence.Error.GPIODeviceUnavailable", |
| 318 | severity, additionalData); |
| 319 | } |
| 320 | catch (const util::DBusError& e) |
| 321 | { |
Anwaar Hadi | ebead9a | 2025-03-19 20:35:57 +0000 | [diff] [blame] | 322 | lg2::error( |
| 323 | "Call to create an error log for presence-sensor failure failed: {ERROR}", |
| 324 | "ERROR", e); |
Mike Capps | a35a890 | 2021-06-10 10:20:14 -0400 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | return std::make_unique<PolicyAccess<NullGpio, JsonConfig>>(); |
| 328 | } |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 329 | } |
| 330 | |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 331 | } // namespace method |
| 332 | |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 333 | /** |
| 334 | * Redundancy policies for fan presence detection function definitions |
| 335 | */ |
| 336 | namespace rpolicy |
| 337 | { |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 338 | // Get an `Anyof` redundancy policy for the fan |
Patrick Williams | 4fa67aa | 2025-02-03 14:28:47 -0500 | [diff] [blame] | 339 | std::unique_ptr<RedundancyPolicy> getAnyof( |
| 340 | const fanPolicy& fan, std::unique_ptr<EEPROMDevice> eepromDevice) |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 341 | { |
| 342 | std::vector<std::reference_wrapper<PresenceSensor>> pSensors; |
| 343 | for (auto& fanSensor : std::get<fanPolicySensorListPos>(fan)) |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 344 | { |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 345 | pSensors.emplace_back(*fanSensor); |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 346 | } |
| 347 | |
Matt Spinler | bc4179e | 2022-10-04 15:15:06 -0500 | [diff] [blame] | 348 | return std::make_unique<AnyOf>(std::get<fanPolicyFanPos>(fan), pSensors, |
| 349 | std::move(eepromDevice)); |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 350 | } |
Matthew Barth | 26ad44a | 2019-11-22 15:37:14 -0600 | [diff] [blame] | 351 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 352 | // Get a `Fallback` redundancy policy for the fan |
Patrick Williams | dfddd64 | 2024-08-16 15:21:51 -0400 | [diff] [blame] | 353 | std::unique_ptr<RedundancyPolicy> getFallback( |
| 354 | const fanPolicy& fan, std::unique_ptr<EEPROMDevice> eepromDevice) |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 355 | { |
| 356 | std::vector<std::reference_wrapper<PresenceSensor>> pSensors; |
| 357 | for (auto& fanSensor : std::get<fanPolicySensorListPos>(fan)) |
| 358 | { |
| 359 | // Place in the order given to fallback correctly |
| 360 | pSensors.emplace_back(*fanSensor); |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 361 | } |
| 362 | |
Matt Spinler | bc4179e | 2022-10-04 15:15:06 -0500 | [diff] [blame] | 363 | return std::make_unique<Fallback>(std::get<fanPolicyFanPos>(fan), pSensors, |
| 364 | std::move(eepromDevice)); |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | } // namespace rpolicy |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 368 | |
Matthew Barth | fd05d64 | 2019-11-14 15:01:57 -0600 | [diff] [blame] | 369 | } // namespace presence |
| 370 | } // namespace fan |
| 371 | } // namespace phosphor |