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