| Alexander Hansen | 40fb549 | 2025-10-28 17:56:12 +0100 | [diff] [blame^] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright 2020 IBM Corporation |
| 3 | |
| Matt Spinler | 1962e08 | 2020-08-05 13:44:53 -0500 | [diff] [blame] | 4 | #include "service_indicators.hpp" |
| 5 | |
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 6 | #include <phosphor-logging/lg2.hpp> |
| Matt Spinler | 1962e08 | 2020-08-05 13:44:53 -0500 | [diff] [blame] | 7 | |
| Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 8 | #include <bitset> |
| 9 | |
| Matt Spinler | 1962e08 | 2020-08-05 13:44:53 -0500 | [diff] [blame] | 10 | namespace openpower::pels::service_indicators |
| 11 | { |
| 12 | |
| Matt Spinler | 48c44db | 2020-08-25 12:47:13 -0500 | [diff] [blame] | 13 | static constexpr auto platformSaiLedGroup = |
| 14 | "/xyz/openbmc_project/led/groups/platform_system_attention_indicator"; |
| 15 | |
| Matt Spinler | 1962e08 | 2020-08-05 13:44:53 -0500 | [diff] [blame] | 16 | std::unique_ptr<Policy> getPolicy(const DataInterfaceBase& dataIface) |
| 17 | { |
| 18 | // At the moment there is just one type of policy. |
| 19 | return std::make_unique<LightPath>(dataIface); |
| 20 | } |
| 21 | |
| 22 | bool LightPath::ignore(const PEL& pel) const |
| 23 | { |
| Matt Spinler | 05f0c6d | 2020-08-05 14:21:06 -0500 | [diff] [blame] | 24 | auto creator = pel.privateHeader().creatorID(); |
| 25 | |
| 26 | // Don't ignore serviceable BMC or hostboot errors |
| 27 | if ((static_cast<CreatorID>(creator) == CreatorID::openBMC) || |
| 28 | (static_cast<CreatorID>(creator) == CreatorID::hostboot)) |
| 29 | { |
| 30 | std::bitset<16> actionFlags{pel.userHeader().actionFlags()}; |
| 31 | if (actionFlags.test(serviceActionFlagBit)) |
| 32 | { |
| 33 | return false; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | return true; |
| Matt Spinler | 1962e08 | 2020-08-05 13:44:53 -0500 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void LightPath::activate(const PEL& pel) |
| 41 | { |
| 42 | if (ignore(pel)) |
| 43 | { |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | // Now that we've gotten this far, we'll need to turn on |
| 48 | // the system attention indicator if we don't find other |
| 49 | // indicators to turn on. |
| 50 | bool sai = true; |
| 51 | auto src = pel.primarySRC(); |
| 52 | const auto& calloutsObj = (*src)->callouts(); |
| 53 | |
| 54 | if (calloutsObj && !calloutsObj->callouts().empty()) |
| 55 | { |
| 56 | const auto& callouts = calloutsObj->callouts(); |
| 57 | |
| 58 | // From the callouts, find the location codes whose |
| 59 | // LEDs need to be turned on. |
| 60 | auto locCodes = getLocationCodes(callouts); |
| 61 | if (!locCodes.empty()) |
| 62 | { |
| Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 63 | // Find the inventory paths for those location codes. |
| 64 | auto paths = getInventoryPaths(locCodes); |
| 65 | if (!paths.empty()) |
| Matt Spinler | 1962e08 | 2020-08-05 13:44:53 -0500 | [diff] [blame] | 66 | { |
| Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 67 | setNotFunctional(paths); |
| Sumit Kumar | 76198a2 | 2021-07-15 05:59:57 -0500 | [diff] [blame] | 68 | createCriticalAssociation(paths); |
| Matt Spinler | 1962e08 | 2020-08-05 13:44:53 -0500 | [diff] [blame] | 69 | sai = false; |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | if (sai) |
| 75 | { |
| Matt Spinler | 48c44db | 2020-08-25 12:47:13 -0500 | [diff] [blame] | 76 | try |
| 77 | { |
| 78 | _dataIface.assertLEDGroup(platformSaiLedGroup, true); |
| 79 | } |
| 80 | catch (const std::exception& e) |
| 81 | { |
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 82 | lg2::error("Failed to assert platform SAI LED group: {EXCEPTION}", |
| 83 | "EXCEPTION", e); |
| Matt Spinler | 48c44db | 2020-08-25 12:47:13 -0500 | [diff] [blame] | 84 | } |
| Matt Spinler | 1962e08 | 2020-08-05 13:44:53 -0500 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | |
| 88 | std::vector<std::string> LightPath::getLocationCodes( |
| 89 | const std::vector<std::unique_ptr<src::Callout>>& callouts) const |
| 90 | { |
| Matt Spinler | 05f0c6d | 2020-08-05 14:21:06 -0500 | [diff] [blame] | 91 | std::vector<std::string> locCodes; |
| 92 | bool firstCallout = true; |
| 93 | uint8_t firstCalloutPriority; |
| 94 | |
| 95 | // Collect location codes for the first group of callouts, |
| 96 | // where a group can be: |
| 97 | // * a single medium priority callout |
| 98 | // * one or more high priority callouts |
| 99 | // * one or more medium group a priority callouts |
| 100 | // |
| 101 | // All callouts in the group must be hardware callouts. |
| 102 | |
| 103 | for (const auto& callout : callouts) |
| 104 | { |
| 105 | if (firstCallout) |
| 106 | { |
| 107 | firstCallout = false; |
| 108 | |
| 109 | firstCalloutPriority = callout->priority(); |
| 110 | |
| 111 | // If the first callout is High, Medium, or Medium |
| 112 | // group A, and is a hardware callout, then we |
| 113 | // want it. |
| 114 | if (isRequiredPriority(firstCalloutPriority) && |
| 115 | isHardwareCallout(*callout)) |
| 116 | { |
| 117 | locCodes.push_back(callout->locationCode()); |
| 118 | } |
| 119 | else |
| 120 | { |
| 121 | break; |
| 122 | } |
| 123 | |
| 124 | // By definition a medium priority callout can't be part |
| 125 | // of a group, so no need to look for more. |
| 126 | if (static_cast<CalloutPriority>(firstCalloutPriority) == |
| 127 | CalloutPriority::medium) |
| 128 | { |
| 129 | break; |
| 130 | } |
| 131 | } |
| 132 | else |
| 133 | { |
| 134 | // Only continue while the callouts are the same |
| 135 | // priority as the first callout. |
| 136 | if (callout->priority() != firstCalloutPriority) |
| 137 | { |
| 138 | break; |
| 139 | } |
| 140 | |
| 141 | // If any callout in the group isn't a hardware callout, |
| 142 | // then don't light up any LEDs at all. |
| 143 | if (!isHardwareCallout(*callout)) |
| 144 | { |
| 145 | locCodes.clear(); |
| 146 | break; |
| 147 | } |
| 148 | |
| 149 | locCodes.push_back(callout->locationCode()); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | return locCodes; |
| 154 | } |
| 155 | |
| 156 | bool LightPath::isRequiredPriority(uint8_t priority) const |
| 157 | { |
| 158 | auto calloutPriority = static_cast<CalloutPriority>(priority); |
| 159 | return (calloutPriority == CalloutPriority::high) || |
| 160 | (calloutPriority == CalloutPriority::medium) || |
| 161 | (calloutPriority == CalloutPriority::mediumGroupA); |
| 162 | } |
| 163 | |
| 164 | bool LightPath::isHardwareCallout(const src::Callout& callout) const |
| 165 | { |
| 166 | const auto& fruIdentity = callout.fruIdentity(); |
| 167 | if (fruIdentity) |
| 168 | { |
| 169 | return (callout.locationCodeSize() != 0) && |
| 170 | ((fruIdentity->failingComponentType() == |
| 171 | src::FRUIdentity::hardwareFRU) || |
| 172 | (fruIdentity->failingComponentType() == |
| 173 | src::FRUIdentity::symbolicFRUTrustedLocCode)); |
| 174 | } |
| 175 | |
| 176 | return false; |
| Matt Spinler | 1962e08 | 2020-08-05 13:44:53 -0500 | [diff] [blame] | 177 | } |
| 178 | |
| Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 179 | std::vector<std::string> LightPath::getInventoryPaths( |
| Matt Spinler | 1962e08 | 2020-08-05 13:44:53 -0500 | [diff] [blame] | 180 | const std::vector<std::string>& locationCodes) const |
| 181 | { |
| Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 182 | std::vector<std::string> paths; |
| Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 183 | |
| 184 | for (const auto& locCode : locationCodes) |
| 185 | { |
| 186 | try |
| 187 | { |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 188 | auto inventoryPaths = |
| 189 | _dataIface.getInventoryFromLocCode(locCode, 0, true); |
| Matt Spinler | bad056b | 2023-01-25 14:16:57 -0600 | [diff] [blame] | 190 | for (const auto& path : inventoryPaths) |
| 191 | { |
| 192 | if (std::find(paths.begin(), paths.end(), path) == paths.end()) |
| 193 | { |
| 194 | paths.push_back(path); |
| 195 | } |
| 196 | } |
| Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 197 | } |
| 198 | catch (const std::exception& e) |
| 199 | { |
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 200 | lg2::error("Could not get inventory path for " |
| 201 | "location code {LOCCODE} ({EXCEPTION}).", |
| 202 | "LOCCODE", locCode, "EXCEPTION", e); |
| Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 203 | |
| Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 204 | // Unless we can set the LEDs for all FRUs, we can't turn |
| Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 205 | // on any of them, so clear the list and quit. |
| Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 206 | paths.clear(); |
| Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 207 | break; |
| 208 | } |
| 209 | } |
| 210 | |
| Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 211 | return paths; |
| Matt Spinler | 1962e08 | 2020-08-05 13:44:53 -0500 | [diff] [blame] | 212 | } |
| 213 | |
| Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 214 | void LightPath::setNotFunctional( |
| 215 | const std::vector<std::string>& inventoryPaths) const |
| Matt Spinler | 1962e08 | 2020-08-05 13:44:53 -0500 | [diff] [blame] | 216 | { |
| Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 217 | for (const auto& path : inventoryPaths) |
| Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 218 | { |
| 219 | try |
| 220 | { |
| Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 221 | _dataIface.setFunctional(path, false); |
| Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 222 | } |
| 223 | catch (const std::exception& e) |
| 224 | { |
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 225 | lg2::info( |
| 226 | "Could not write Functional property on {PATH} ({EXCEPTION})", |
| 227 | "PATH", path, "EXCEPTION", e); |
| Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 228 | } |
| 229 | } |
| Matt Spinler | 1962e08 | 2020-08-05 13:44:53 -0500 | [diff] [blame] | 230 | } |
| 231 | |
| Sumit Kumar | 76198a2 | 2021-07-15 05:59:57 -0500 | [diff] [blame] | 232 | void LightPath::createCriticalAssociation( |
| 233 | const std::vector<std::string>& inventoryPaths) const |
| 234 | { |
| 235 | for (const auto& path : inventoryPaths) |
| 236 | { |
| 237 | try |
| 238 | { |
| 239 | _dataIface.setCriticalAssociation(path); |
| 240 | } |
| 241 | catch (const std::exception& e) |
| 242 | { |
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 243 | lg2::info( |
| 244 | "Could not set critical association on object path {PATH} ({EXCEPTION})", |
| 245 | "PATH", path, "EXCEPTION", e); |
| Sumit Kumar | 76198a2 | 2021-07-15 05:59:57 -0500 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | } |
| 249 | |
| Matt Spinler | 1962e08 | 2020-08-05 13:44:53 -0500 | [diff] [blame] | 250 | } // namespace openpower::pels::service_indicators |