Matt Spinler | b54357f | 2017-08-21 14:38:54 -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 | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 16 | #include "ucd90160.hpp" |
| 17 | |
| 18 | #include "names_values.hpp" |
| 19 | #include "utility.hpp" |
| 20 | |
| 21 | #include <elog-errors.hpp> |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 22 | #include <org/open_power/Witherspoon/Fault/error.hpp> |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 23 | #include <phosphor-logging/elog.hpp> |
| 24 | #include <phosphor-logging/log.hpp> |
Matt Spinler | ceacf94 | 2017-10-05 13:55:02 -0500 | [diff] [blame] | 25 | #include <xyz/openbmc_project/Common/Device/error.hpp> |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 26 | |
Brandon Wyman | d1bc4ce | 2019-12-13 14:20:34 -0600 | [diff] [blame] | 27 | #include <map> |
| 28 | #include <memory> |
| 29 | |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 30 | namespace phosphor |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 31 | { |
| 32 | namespace power |
| 33 | { |
| 34 | |
| 35 | using namespace std::string_literals; |
| 36 | |
Matt Spinler | e7e432b | 2017-08-21 15:01:40 -0500 | [diff] [blame] | 37 | const auto MFR_STATUS = "mfr_status"s; |
Matt Spinler | 1e36569 | 2017-08-21 14:43:55 -0500 | [diff] [blame] | 38 | |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 39 | const auto DEVICE_NAME = "UCD90160"s; |
| 40 | const auto DRIVER_NAME = "ucd9000"s; |
Matt Spinler | e7e432b | 2017-08-21 15:01:40 -0500 | [diff] [blame] | 41 | constexpr auto NUM_PAGES = 16; |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 42 | |
Matt Spinler | 0e45ced | 2018-02-12 14:36:07 -0600 | [diff] [blame] | 43 | constexpr auto INVENTORY_OBJ_PATH = "/xyz/openbmc_project/inventory"; |
| 44 | |
Brandon Wyman | 9c7897c | 2019-03-28 17:42:34 -0500 | [diff] [blame] | 45 | namespace fs = std::filesystem; |
Matt Spinler | d998b73 | 2017-08-21 15:35:54 -0500 | [diff] [blame] | 46 | using namespace gpio; |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 47 | using namespace pmbus; |
| 48 | using namespace phosphor::logging; |
Matt Spinler | ceacf94 | 2017-10-05 13:55:02 -0500 | [diff] [blame] | 49 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 50 | namespace device_error = sdbusplus::xyz::openbmc_project::Common::Device::Error; |
| 51 | namespace power_error = sdbusplus::org::open_power::Witherspoon::Fault::Error; |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 52 | |
Patrick Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 53 | UCD90160::UCD90160(size_t instance, sdbusplus::bus_t& bus) : |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 54 | Device(DEVICE_NAME, instance), |
| 55 | interface(std::get<ucd90160::pathField>(deviceMap.find(instance)->second), |
| 56 | DRIVER_NAME, instance), |
| 57 | gpioDevice(findGPIODevice(interface.path())), bus(bus) |
Adriana Kobylak | 0c9a33d | 2021-09-13 18:05:09 +0000 | [diff] [blame] | 58 | {} |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 59 | |
| 60 | void UCD90160::onFailure() |
| 61 | { |
| 62 | try |
| 63 | { |
| 64 | auto voutError = checkVOUTFaults(); |
| 65 | |
| 66 | auto pgoodError = checkPGOODFaults(false); |
| 67 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 68 | // Not a voltage or PGOOD fault, but we know something |
| 69 | // failed so still create an error log. |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 70 | if (!voutError && !pgoodError) |
| 71 | { |
| 72 | createPowerFaultLog(); |
| 73 | } |
| 74 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 75 | catch (const device_error::ReadFailure& e) |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 76 | { |
| 77 | if (!accessError) |
| 78 | { |
Matt Spinler | ceacf94 | 2017-10-05 13:55:02 -0500 | [diff] [blame] | 79 | commit<device_error::ReadFailure>(); |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 80 | accessError = true; |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | void UCD90160::analyze() |
| 86 | { |
| 87 | try |
| 88 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 89 | // Note: Voltage faults are always fatal, so they just |
| 90 | // need to be analyzed in onFailure(). |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 91 | |
| 92 | checkPGOODFaults(true); |
| 93 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 94 | catch (const device_error::ReadFailure& e) |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 95 | { |
| 96 | if (!accessError) |
| 97 | { |
Matt Spinler | ceacf94 | 2017-10-05 13:55:02 -0500 | [diff] [blame] | 98 | commit<device_error::ReadFailure>(); |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 99 | accessError = true; |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
Matt Spinler | e7e432b | 2017-08-21 15:01:40 -0500 | [diff] [blame] | 104 | uint16_t UCD90160::readStatusWord() |
| 105 | { |
| 106 | return interface.read(STATUS_WORD, Type::Debug); |
| 107 | } |
| 108 | |
| 109 | uint32_t UCD90160::readMFRStatus() |
| 110 | { |
Matt Spinler | 233a252 | 2018-03-30 14:40:04 -0500 | [diff] [blame] | 111 | return interface.read(MFR_STATUS, Type::HwmonDeviceDebug); |
Matt Spinler | e7e432b | 2017-08-21 15:01:40 -0500 | [diff] [blame] | 112 | } |
| 113 | |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 114 | bool UCD90160::checkVOUTFaults() |
| 115 | { |
Matt Spinler | e7e432b | 2017-08-21 15:01:40 -0500 | [diff] [blame] | 116 | bool errorCreated = false; |
| 117 | auto statusWord = readStatusWord(); |
| 118 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 119 | // The status_word register has a summary bit to tell us |
| 120 | // if each page even needs to be checked |
Matt Spinler | e7e432b | 2017-08-21 15:01:40 -0500 | [diff] [blame] | 121 | if (!(statusWord & status_word::VOUT_FAULT)) |
| 122 | { |
| 123 | return errorCreated; |
| 124 | } |
| 125 | |
| 126 | for (size_t page = 0; page < NUM_PAGES; page++) |
| 127 | { |
| 128 | if (isVoutFaultLogged(page)) |
| 129 | { |
| 130 | continue; |
| 131 | } |
| 132 | |
| 133 | auto statusVout = interface.insertPageNum(STATUS_VOUT, page); |
| 134 | uint8_t vout = interface.read(statusVout, Type::Debug); |
| 135 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 136 | // If any bits are on log them, though some are just |
| 137 | // warnings so they won't cause errors |
Matt Spinler | e7e432b | 2017-08-21 15:01:40 -0500 | [diff] [blame] | 138 | if (vout) |
| 139 | { |
Matt Spinler | de16d05 | 2017-12-13 13:22:14 -0600 | [diff] [blame] | 140 | log<level::INFO>("A voltage rail has bits on in STATUS_VOUT", |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 141 | entry("STATUS_VOUT=0x%X", vout), |
| 142 | entry("PAGE=%d", page)); |
Matt Spinler | de16d05 | 2017-12-13 13:22:14 -0600 | [diff] [blame] | 143 | } |
| 144 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 145 | // Log errors if any non-warning bits on |
Matt Spinler | de16d05 | 2017-12-13 13:22:14 -0600 | [diff] [blame] | 146 | if (vout & ~status_vout::WARNING_MASK) |
| 147 | { |
Matt Spinler | e7e432b | 2017-08-21 15:01:40 -0500 | [diff] [blame] | 148 | auto& railNames = std::get<ucd90160::railNamesField>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 149 | deviceMap.find(getInstance())->second); |
Matt Spinler | e7e432b | 2017-08-21 15:01:40 -0500 | [diff] [blame] | 150 | auto railName = railNames.at(page); |
| 151 | |
| 152 | util::NamesValues nv; |
Matt Spinler | 6def909 | 2018-02-27 14:22:59 -0600 | [diff] [blame] | 153 | try |
| 154 | { |
| 155 | nv.add("STATUS_WORD", statusWord); |
| 156 | nv.add("STATUS_VOUT", vout); |
| 157 | nv.add("MFR_STATUS", readMFRStatus()); |
| 158 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 159 | catch (const device_error::ReadFailure& e) |
Matt Spinler | 6def909 | 2018-02-27 14:22:59 -0600 | [diff] [blame] | 160 | { |
| 161 | log<level::ERR>("ReadFailure when collecting metadata"); |
| 162 | commit<device_error::ReadFailure>(); |
| 163 | } |
Matt Spinler | e7e432b | 2017-08-21 15:01:40 -0500 | [diff] [blame] | 164 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 165 | using metadata = |
| 166 | org::open_power::Witherspoon::Fault::PowerSequencerVoltageFault; |
Matt Spinler | e7e432b | 2017-08-21 15:01:40 -0500 | [diff] [blame] | 167 | |
Matt Spinler | ceacf94 | 2017-10-05 13:55:02 -0500 | [diff] [blame] | 168 | report<power_error::PowerSequencerVoltageFault>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 169 | metadata::RAIL(page), metadata::RAIL_NAME(railName.c_str()), |
| 170 | metadata::RAW_STATUS(nv.get().c_str())); |
Matt Spinler | e7e432b | 2017-08-21 15:01:40 -0500 | [diff] [blame] | 171 | |
| 172 | setVoutFaultLogged(page); |
| 173 | errorCreated = true; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | return errorCreated; |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | bool UCD90160::checkPGOODFaults(bool polling) |
| 181 | { |
Matt Spinler | d998b73 | 2017-08-21 15:35:54 -0500 | [diff] [blame] | 182 | bool errorCreated = false; |
| 183 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 184 | // While PGOOD faults could show up in MFR_STATUS (and we could then |
| 185 | // check the summary bit in STATUS_WORD first), they are edge triggered, |
| 186 | // and as the device driver sends a clear faults command every time we |
| 187 | // do a read, we will never see them. So, we'll have to just read the |
| 188 | // real time GPI status GPIO. |
Matt Spinler | d998b73 | 2017-08-21 15:35:54 -0500 | [diff] [blame] | 189 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 190 | // Check only the GPIs configured on this system. |
Matt Spinler | d998b73 | 2017-08-21 15:35:54 -0500 | [diff] [blame] | 191 | auto& gpiConfigs = std::get<ucd90160::gpiConfigField>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 192 | deviceMap.find(getInstance())->second); |
Matt Spinler | d998b73 | 2017-08-21 15:35:54 -0500 | [diff] [blame] | 193 | |
| 194 | for (const auto& gpiConfig : gpiConfigs) |
| 195 | { |
| 196 | auto gpiNum = std::get<ucd90160::gpiNumField>(gpiConfig); |
| 197 | auto doPoll = std::get<ucd90160::pollField>(gpiConfig); |
| 198 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 199 | // Can skip this one if there is already an error on this input, |
| 200 | // or we are polling and these inputs don't need to be polled |
Matt Spinler | d998b73 | 2017-08-21 15:35:54 -0500 | [diff] [blame] | 201 | //(because errors on them are fatal). |
| 202 | if (isPGOODFaultLogged(gpiNum) || (polling && !doPoll)) |
| 203 | { |
| 204 | continue; |
| 205 | } |
| 206 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 207 | // The real time status is read via the pin ID |
Matt Spinler | d998b73 | 2017-08-21 15:35:54 -0500 | [diff] [blame] | 208 | auto pinID = std::get<ucd90160::pinIDField>(gpiConfig); |
| 209 | auto gpio = gpios.find(pinID); |
| 210 | Value gpiStatus; |
| 211 | |
| 212 | try |
| 213 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 214 | // The first time through, create the GPIO objects |
Matt Spinler | d998b73 | 2017-08-21 15:35:54 -0500 | [diff] [blame] | 215 | if (gpio == gpios.end()) |
| 216 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 217 | gpios.emplace(pinID, std::make_unique<GPIO>(gpioDevice, pinID, |
| 218 | Direction::input)); |
Matt Spinler | d998b73 | 2017-08-21 15:35:54 -0500 | [diff] [blame] | 219 | gpio = gpios.find(pinID); |
| 220 | } |
| 221 | |
| 222 | gpiStatus = gpio->second->read(); |
| 223 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 224 | catch (const std::exception& e) |
Matt Spinler | d998b73 | 2017-08-21 15:35:54 -0500 | [diff] [blame] | 225 | { |
| 226 | if (!accessError) |
| 227 | { |
| 228 | log<level::ERR>(e.what()); |
| 229 | accessError = true; |
| 230 | } |
| 231 | continue; |
| 232 | } |
| 233 | |
| 234 | if (gpiStatus == Value::low) |
| 235 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 236 | // There may be some extra analysis we can do to narrow the |
| 237 | // error down further. Note that finding an error here won't |
| 238 | // prevent us from checking this GPI again. |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 239 | errorCreated = doExtraAnalysis(gpiConfig); |
| 240 | |
| 241 | if (errorCreated) |
| 242 | { |
| 243 | continue; |
| 244 | } |
| 245 | |
Matt Spinler | d998b73 | 2017-08-21 15:35:54 -0500 | [diff] [blame] | 246 | auto& gpiName = std::get<ucd90160::gpiNameField>(gpiConfig); |
| 247 | auto status = (gpiStatus == Value::low) ? 0 : 1; |
| 248 | |
| 249 | util::NamesValues nv; |
Matt Spinler | 6def909 | 2018-02-27 14:22:59 -0600 | [diff] [blame] | 250 | |
| 251 | try |
| 252 | { |
| 253 | nv.add("STATUS_WORD", readStatusWord()); |
| 254 | nv.add("MFR_STATUS", readMFRStatus()); |
| 255 | nv.add("INPUT_STATUS", status); |
| 256 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 257 | catch (const device_error::ReadFailure& e) |
Matt Spinler | 6def909 | 2018-02-27 14:22:59 -0600 | [diff] [blame] | 258 | { |
| 259 | log<level::ERR>("ReadFailure when collecting metadata"); |
| 260 | commit<device_error::ReadFailure>(); |
| 261 | } |
Matt Spinler | d998b73 | 2017-08-21 15:35:54 -0500 | [diff] [blame] | 262 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 263 | using metadata = |
| 264 | org::open_power::Witherspoon::Fault::PowerSequencerPGOODFault; |
Matt Spinler | d998b73 | 2017-08-21 15:35:54 -0500 | [diff] [blame] | 265 | |
Matt Spinler | ceacf94 | 2017-10-05 13:55:02 -0500 | [diff] [blame] | 266 | report<power_error::PowerSequencerPGOODFault>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 267 | metadata::INPUT_NUM(gpiNum), |
| 268 | metadata::INPUT_NAME(gpiName.c_str()), |
| 269 | metadata::RAW_STATUS(nv.get().c_str())); |
Matt Spinler | d998b73 | 2017-08-21 15:35:54 -0500 | [diff] [blame] | 270 | |
| 271 | setPGOODFaultLogged(gpiNum); |
| 272 | errorCreated = true; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | return errorCreated; |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | void UCD90160::createPowerFaultLog() |
| 280 | { |
Matt Spinler | 9efb308 | 2017-08-21 15:43:43 -0500 | [diff] [blame] | 281 | util::NamesValues nv; |
Matt Spinler | 6def909 | 2018-02-27 14:22:59 -0600 | [diff] [blame] | 282 | |
| 283 | try |
| 284 | { |
| 285 | nv.add("STATUS_WORD", readStatusWord()); |
| 286 | nv.add("MFR_STATUS", readMFRStatus()); |
| 287 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 288 | catch (const device_error::ReadFailure& e) |
Matt Spinler | 6def909 | 2018-02-27 14:22:59 -0600 | [diff] [blame] | 289 | { |
| 290 | log<level::ERR>("ReadFailure when collecting metadata"); |
| 291 | commit<device_error::ReadFailure>(); |
| 292 | } |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 293 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 294 | using metadata = org::open_power::Witherspoon::Fault::PowerSequencerFault; |
Matt Spinler | 9efb308 | 2017-08-21 15:43:43 -0500 | [diff] [blame] | 295 | |
Matt Spinler | ceacf94 | 2017-10-05 13:55:02 -0500 | [diff] [blame] | 296 | report<power_error::PowerSequencerFault>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 297 | metadata::RAW_STATUS(nv.get().c_str())); |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 298 | } |
| 299 | |
Matt Spinler | fcd4a71 | 2017-09-19 10:45:07 -0500 | [diff] [blame] | 300 | fs::path UCD90160::findGPIODevice(const fs::path& path) |
Matt Spinler | 110b284 | 2017-08-21 15:23:27 -0500 | [diff] [blame] | 301 | { |
Matt Spinler | fcd4a71 | 2017-09-19 10:45:07 -0500 | [diff] [blame] | 302 | fs::path gpioDevicePath; |
Matt Spinler | 110b284 | 2017-08-21 15:23:27 -0500 | [diff] [blame] | 303 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 304 | // In the driver directory, look for a subdirectory |
| 305 | // named gpiochipX, where X is some number. Then |
| 306 | // we'll access the GPIO at /dev/gpiochipX. |
Matt Spinler | 110b284 | 2017-08-21 15:23:27 -0500 | [diff] [blame] | 307 | if (fs::is_directory(path)) |
| 308 | { |
| 309 | for (auto& f : fs::directory_iterator(path)) |
| 310 | { |
| 311 | if (f.path().filename().string().find("gpiochip") != |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 312 | std::string::npos) |
Matt Spinler | 110b284 | 2017-08-21 15:23:27 -0500 | [diff] [blame] | 313 | { |
Matt Spinler | fcd4a71 | 2017-09-19 10:45:07 -0500 | [diff] [blame] | 314 | gpioDevicePath = "/dev" / f.path().filename(); |
Matt Spinler | 110b284 | 2017-08-21 15:23:27 -0500 | [diff] [blame] | 315 | break; |
| 316 | } |
| 317 | } |
| 318 | } |
| 319 | |
Matt Spinler | fcd4a71 | 2017-09-19 10:45:07 -0500 | [diff] [blame] | 320 | if (gpioDevicePath.empty()) |
Matt Spinler | 110b284 | 2017-08-21 15:23:27 -0500 | [diff] [blame] | 321 | { |
Matt Spinler | fcd4a71 | 2017-09-19 10:45:07 -0500 | [diff] [blame] | 322 | log<level::ERR>("Could not find GPIO device path", |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 323 | entry("BASE_PATH=%s", path.c_str())); |
Matt Spinler | 110b284 | 2017-08-21 15:23:27 -0500 | [diff] [blame] | 324 | } |
Matt Spinler | fcd4a71 | 2017-09-19 10:45:07 -0500 | [diff] [blame] | 325 | |
| 326 | return gpioDevicePath; |
Matt Spinler | 110b284 | 2017-08-21 15:23:27 -0500 | [diff] [blame] | 327 | } |
| 328 | |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 329 | bool UCD90160::doExtraAnalysis(const ucd90160::GPIConfig& config) |
| 330 | { |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 331 | auto type = std::get<ucd90160::extraAnalysisField>(config); |
| 332 | if (type == ucd90160::extraAnalysisType::none) |
| 333 | { |
| 334 | return false; |
| 335 | } |
| 336 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 337 | // Currently the only extra analysis to do is to check other GPIOs. |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 338 | return doGPIOAnalysis(type); |
| 339 | } |
| 340 | |
| 341 | bool UCD90160::doGPIOAnalysis(ucd90160::extraAnalysisType type) |
| 342 | { |
| 343 | bool errorFound = false; |
Matt Spinler | a826965 | 2017-09-19 15:13:28 -0500 | [diff] [blame] | 344 | bool shutdown = false; |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 345 | |
| 346 | const auto& analysisConfig = std::get<ucd90160::gpioAnalysisField>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 347 | deviceMap.find(getInstance())->second); |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 348 | |
| 349 | auto gpioConfig = analysisConfig.find(type); |
| 350 | if (gpioConfig == analysisConfig.end()) |
| 351 | { |
| 352 | return errorFound; |
| 353 | } |
| 354 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 355 | auto path = std::get<ucd90160::gpioDevicePathField>(gpioConfig->second); |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 356 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 357 | // The /dev/gpiochipX device |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 358 | auto device = findGPIODevice(path); |
| 359 | |
Matt Spinler | 5c0ce17 | 2019-07-22 16:11:08 -0500 | [diff] [blame] | 360 | if (device.empty()) |
| 361 | { |
| 362 | log<level::ERR>( |
| 363 | "Missing GPIO device - cannot do GPIO analysis of fault", |
| 364 | entry("ANALYSIS_TYPE=%d\n", type)); |
| 365 | return errorFound; |
| 366 | } |
| 367 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 368 | // The GPIO value of the fault condition |
| 369 | auto polarity = std::get<ucd90160::gpioPolarityField>(gpioConfig->second); |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 370 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 371 | // The GPIOs to check |
| 372 | auto& gpios = std::get<ucd90160::gpioDefinitionField>(gpioConfig->second); |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 373 | |
| 374 | for (const auto& gpio : gpios) |
| 375 | { |
| 376 | gpio::Value value; |
| 377 | |
| 378 | try |
| 379 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 380 | GPIO g{device, std::get<ucd90160::gpioNumField>(gpio), |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 381 | Direction::input}; |
| 382 | |
| 383 | value = g.read(); |
| 384 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 385 | catch (const std::exception& e) |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 386 | { |
| 387 | if (!gpioAccessError) |
| 388 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 389 | // GPIO only throws InternalErrors - not worth committing. |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 390 | log<level::ERR>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 391 | "GPIO read failed while analyzing a power fault", |
| 392 | entry("CHIP_PATH=%s", path.c_str())); |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 393 | |
| 394 | gpioAccessError = true; |
| 395 | } |
| 396 | continue; |
| 397 | } |
| 398 | |
| 399 | if (value == polarity) |
| 400 | { |
| 401 | errorFound = true; |
| 402 | |
Matt Spinler | 0e45ced | 2018-02-12 14:36:07 -0600 | [diff] [blame] | 403 | std::string part{INVENTORY_OBJ_PATH}; |
| 404 | part = part + std::get<ucd90160::gpioCalloutField>(gpio); |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 405 | PartCallout callout{type, part}; |
| 406 | |
| 407 | if (isPartCalledOut(callout)) |
| 408 | { |
| 409 | continue; |
| 410 | } |
| 411 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 412 | // Look up and call the error creation function |
| 413 | auto logError = |
| 414 | std::get<ucd90160::errorFunctionField>(gpioConfig->second); |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 415 | |
| 416 | logError(*this, part); |
| 417 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 418 | // Save the part callout so we don't call it out again |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 419 | setPartCallout(callout); |
Matt Spinler | a826965 | 2017-09-19 15:13:28 -0500 | [diff] [blame] | 420 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 421 | // Some errors (like overtemps) require a shutdown |
Matt Spinler | a826965 | 2017-09-19 15:13:28 -0500 | [diff] [blame] | 422 | auto actions = static_cast<uint32_t>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 423 | std::get<ucd90160::optionFlagsField>(gpioConfig->second)); |
Matt Spinler | a826965 | 2017-09-19 15:13:28 -0500 | [diff] [blame] | 424 | |
| 425 | if (actions & static_cast<decltype(actions)>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 426 | ucd90160::optionFlags::shutdownOnFault)) |
Matt Spinler | a826965 | 2017-09-19 15:13:28 -0500 | [diff] [blame] | 427 | { |
| 428 | shutdown = true; |
| 429 | } |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 430 | } |
| 431 | } |
| 432 | |
Matt Spinler | a826965 | 2017-09-19 15:13:28 -0500 | [diff] [blame] | 433 | if (shutdown) |
| 434 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 435 | // Will be replaced with a GPU specific error in a future commit |
Matt Spinler | 882ce95 | 2017-10-05 16:12:41 -0500 | [diff] [blame] | 436 | util::powerOff<power_error::Shutdown>(bus); |
Matt Spinler | a826965 | 2017-09-19 15:13:28 -0500 | [diff] [blame] | 437 | } |
| 438 | |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 439 | return errorFound; |
| 440 | } |
| 441 | |
Matt Spinler | 7b14db2 | 2017-09-19 10:57:54 -0500 | [diff] [blame] | 442 | void UCD90160::gpuPGOODError(const std::string& callout) |
| 443 | { |
| 444 | util::NamesValues nv; |
Matt Spinler | 6def909 | 2018-02-27 14:22:59 -0600 | [diff] [blame] | 445 | |
| 446 | try |
| 447 | { |
| 448 | nv.add("STATUS_WORD", readStatusWord()); |
| 449 | nv.add("MFR_STATUS", readMFRStatus()); |
| 450 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 451 | catch (const device_error::ReadFailure& e) |
Matt Spinler | 6def909 | 2018-02-27 14:22:59 -0600 | [diff] [blame] | 452 | { |
| 453 | log<level::ERR>("ReadFailure when collecting metadata"); |
| 454 | commit<device_error::ReadFailure>(); |
| 455 | } |
Matt Spinler | 7b14db2 | 2017-09-19 10:57:54 -0500 | [diff] [blame] | 456 | |
Brandon Wyman | e0eb45c | 2017-10-06 12:58:42 -0500 | [diff] [blame] | 457 | using metadata = org::open_power::Witherspoon::Fault::GPUPowerFault; |
Matt Spinler | 7b14db2 | 2017-09-19 10:57:54 -0500 | [diff] [blame] | 458 | |
Matt Spinler | ceacf94 | 2017-10-05 13:55:02 -0500 | [diff] [blame] | 459 | report<power_error::GPUPowerFault>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 460 | metadata::RAW_STATUS(nv.get().c_str()), |
| 461 | metadata::CALLOUT_INVENTORY_PATH(callout.c_str())); |
Matt Spinler | 7b14db2 | 2017-09-19 10:57:54 -0500 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | void UCD90160::gpuOverTempError(const std::string& callout) |
| 465 | { |
| 466 | util::NamesValues nv; |
Matt Spinler | 6def909 | 2018-02-27 14:22:59 -0600 | [diff] [blame] | 467 | |
| 468 | try |
| 469 | { |
| 470 | nv.add("STATUS_WORD", readStatusWord()); |
| 471 | nv.add("MFR_STATUS", readMFRStatus()); |
| 472 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 473 | catch (const device_error::ReadFailure& e) |
Matt Spinler | 6def909 | 2018-02-27 14:22:59 -0600 | [diff] [blame] | 474 | { |
| 475 | log<level::ERR>("ReadFailure when collecting metadata"); |
| 476 | commit<device_error::ReadFailure>(); |
| 477 | } |
Matt Spinler | 7b14db2 | 2017-09-19 10:57:54 -0500 | [diff] [blame] | 478 | |
Brandon Wyman | e0eb45c | 2017-10-06 12:58:42 -0500 | [diff] [blame] | 479 | using metadata = org::open_power::Witherspoon::Fault::GPUOverTemp; |
Matt Spinler | 7b14db2 | 2017-09-19 10:57:54 -0500 | [diff] [blame] | 480 | |
Matt Spinler | ceacf94 | 2017-10-05 13:55:02 -0500 | [diff] [blame] | 481 | report<power_error::GPUOverTemp>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 482 | metadata::RAW_STATUS(nv.get().c_str()), |
| 483 | metadata::CALLOUT_INVENTORY_PATH(callout.c_str())); |
Matt Spinler | 7b14db2 | 2017-09-19 10:57:54 -0500 | [diff] [blame] | 484 | } |
| 485 | |
Brandon Wyman | 03c19db | 2019-05-10 17:46:41 -0500 | [diff] [blame] | 486 | void UCD90160::memGoodError(const std::string& callout) |
| 487 | { |
| 488 | util::NamesValues nv; |
| 489 | |
| 490 | try |
| 491 | { |
| 492 | nv.add("STATUS_WORD", readStatusWord()); |
| 493 | nv.add("MFR_STATUS", readMFRStatus()); |
| 494 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 495 | catch (const device_error::ReadFailure& e) |
Brandon Wyman | 03c19db | 2019-05-10 17:46:41 -0500 | [diff] [blame] | 496 | { |
| 497 | log<level::ERR>("ReadFailure when collecting metadata"); |
| 498 | commit<device_error::ReadFailure>(); |
| 499 | } |
| 500 | |
| 501 | using metadata = org::open_power::Witherspoon::Fault::MemoryPowerFault; |
| 502 | |
| 503 | report<power_error::MemoryPowerFault>( |
| 504 | metadata::RAW_STATUS(nv.get().c_str()), |
| 505 | metadata::CALLOUT_INVENTORY_PATH(callout.c_str())); |
| 506 | } |
| 507 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 508 | } // namespace power |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 509 | } // namespace phosphor |