Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 3 | #include "device.hpp" |
| 4 | #include "gpio.hpp" |
| 5 | #include "pmbus.hpp" |
| 6 | #include "types.hpp" |
| 7 | |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 8 | #include <algorithm> |
Brandon Wyman | 9c7897c | 2019-03-28 17:42:34 -0500 | [diff] [blame] | 9 | #include <filesystem> |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 10 | #include <map> |
Matt Spinler | a826965 | 2017-09-19 15:13:28 -0500 | [diff] [blame] | 11 | #include <sdbusplus/bus.hpp> |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 12 | #include <vector> |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 13 | |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 14 | namespace phosphor |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 15 | { |
| 16 | namespace power |
| 17 | { |
| 18 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 19 | // Error type, callout |
| 20 | using PartCallout = std::tuple<ucd90160::extraAnalysisType, std::string>; |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 21 | |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 22 | /** |
| 23 | * @class UCD90160 |
| 24 | * |
| 25 | * This class implements fault analysis for the UCD90160 |
| 26 | * power sequencer device. |
| 27 | * |
| 28 | */ |
| 29 | class UCD90160 : public Device |
| 30 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 31 | public: |
| 32 | UCD90160() = delete; |
| 33 | ~UCD90160() = default; |
| 34 | UCD90160(const UCD90160&) = delete; |
| 35 | UCD90160& operator=(const UCD90160&) = delete; |
| 36 | UCD90160(UCD90160&&) = default; |
| 37 | UCD90160& operator=(UCD90160&&) = default; |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 38 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 39 | /** |
| 40 | * Constructor |
| 41 | * |
| 42 | * @param[in] instance - the device instance number |
| 43 | * @param[in] bus - D-Bus bus object |
| 44 | */ |
| 45 | UCD90160(size_t instance, sdbusplus::bus::bus& bus); |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 46 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 47 | /** |
| 48 | * Analyzes the device for errors when the device is |
| 49 | * known to be in an error state. A log will be created. |
| 50 | */ |
| 51 | void onFailure() override; |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 52 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 53 | /** |
| 54 | * Checks the device for errors and only creates a log |
| 55 | * if one is found. |
| 56 | */ |
| 57 | void analyze() override; |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 58 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 59 | /** |
| 60 | * Clears faults in the device |
| 61 | */ |
| 62 | void clearFaults() override |
| 63 | { |
| 64 | } |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 65 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 66 | private: |
| 67 | /** |
| 68 | * Reports an error for a GPU PGOOD failure |
| 69 | * |
| 70 | * @param[in] callout - the GPU callout string |
| 71 | */ |
| 72 | void gpuPGOODError(const std::string& callout); |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 73 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 74 | /** |
| 75 | * Reports an error for a GPU OverTemp failure |
| 76 | * |
| 77 | * @param[in] callout - the GPU callout string |
| 78 | */ |
| 79 | void gpuOverTempError(const std::string& callout); |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 80 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 81 | /** |
Brandon Wyman | 03c19db | 2019-05-10 17:46:41 -0500 | [diff] [blame] | 82 | * Reports an error for a MEM_GOODx failure. |
| 83 | * |
| 84 | * @param[in] callout - The MEM callout string |
| 85 | */ |
| 86 | void memGoodError(const std::string& callout); |
| 87 | |
| 88 | /** |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 89 | * Given the device path for a chip, find its gpiochip |
| 90 | * path |
| 91 | * |
| 92 | * @param[in] path - device path, like |
| 93 | * /sys/devices/.../i2c-11/11-0064 |
| 94 | * |
| 95 | * @return fs::path - The gpiochip path, like |
| 96 | * /dev/gpiochip1 |
| 97 | */ |
Brandon Wyman | 9c7897c | 2019-03-28 17:42:34 -0500 | [diff] [blame] | 98 | static std::filesystem::path |
| 99 | findGPIODevice(const std::filesystem::path& path); |
Matt Spinler | 7b14db2 | 2017-09-19 10:57:54 -0500 | [diff] [blame] | 100 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 101 | /** |
| 102 | * Checks for VOUT faults on the device. |
| 103 | * |
| 104 | * This device can monitor voltages of its dependent |
| 105 | * devices, and VOUT faults are voltage faults |
| 106 | * on these devices. |
| 107 | * |
| 108 | * @return bool - true if an error log was created |
| 109 | */ |
| 110 | bool checkVOUTFaults(); |
Matt Spinler | 7b14db2 | 2017-09-19 10:57:54 -0500 | [diff] [blame] | 111 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 112 | /** |
| 113 | * Checks for PGOOD faults on the device. |
| 114 | * |
| 115 | * This device can monitor the PGOOD signals of its dependent |
| 116 | * devices, and this check will look for faults of |
| 117 | * those PGOODs. |
| 118 | * |
| 119 | * @param[in] polling - If this is running while polling for errors, |
| 120 | * as opposing to analyzing a fail condition. |
| 121 | * |
| 122 | * @return bool - true if an error log was created |
| 123 | */ |
| 124 | bool checkPGOODFaults(bool polling); |
Matt Spinler | 110b284 | 2017-08-21 15:23:27 -0500 | [diff] [blame] | 125 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 126 | /** |
| 127 | * Creates an error log when the device has an error |
| 128 | * but it isn't a PGOOD or voltage failure. |
| 129 | */ |
| 130 | void createPowerFaultLog(); |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 131 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 132 | /** |
| 133 | * Reads the status_word register |
| 134 | * |
| 135 | * @return uint16_t - the register contents |
| 136 | */ |
| 137 | uint16_t readStatusWord(); |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 138 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 139 | /** |
| 140 | * Reads the mfr_status register |
| 141 | * |
| 142 | * @return uint32_t - the register contents |
| 143 | */ |
| 144 | uint32_t readMFRStatus(); |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 145 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 146 | /** |
| 147 | * Does any additional fault analysis based on the |
| 148 | * value of the extraAnalysisType field in the GPIOConfig |
| 149 | * entry. |
| 150 | * |
| 151 | * Used to get better callouts. |
| 152 | * |
| 153 | * @param[in] config - the GPIOConfig entry to use |
| 154 | * |
| 155 | * @return bool - true if a HW error was found, false else |
| 156 | */ |
| 157 | bool doExtraAnalysis(const ucd90160::GPIConfig& config); |
Matt Spinler | e7e432b | 2017-08-21 15:01:40 -0500 | [diff] [blame] | 158 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 159 | /** |
| 160 | * Does additional fault analysis using GPIOs to |
| 161 | * specifically identify the failing part. |
| 162 | * |
| 163 | * Used when there are too many PGOOD inputs for |
| 164 | * the UCD90160 to handle, so just a summary bit |
| 165 | * is wired into the chip, and then the specific |
| 166 | * fault GPIOs are off of a different GPIO device, |
| 167 | * like an IO expander. |
| 168 | * |
| 169 | * @param[in] type - the type of analysis to do |
| 170 | * |
| 171 | * @return bool - true if a HW error was found, false else |
| 172 | */ |
| 173 | bool doGPIOAnalysis(ucd90160::extraAnalysisType type); |
Matt Spinler | e7e432b | 2017-08-21 15:01:40 -0500 | [diff] [blame] | 174 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 175 | /** |
| 176 | * Says if we've already logged a Vout fault |
| 177 | * |
| 178 | * The policy is only 1 of the same error will |
| 179 | * be logged for the duration of a class instance. |
| 180 | * |
| 181 | * @param[in] page - the page to check |
| 182 | * |
| 183 | * @return bool - if we've already logged a fault against |
| 184 | * this page |
| 185 | */ |
| 186 | inline bool isVoutFaultLogged(uint32_t page) const |
| 187 | { |
| 188 | return std::find(voutErrors.begin(), voutErrors.end(), page) != |
| 189 | voutErrors.end(); |
| 190 | } |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 191 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 192 | /** |
| 193 | * Saves that a Vout fault has been logged |
| 194 | * |
| 195 | * @param[in] page - the page the error was logged against |
| 196 | */ |
| 197 | inline void setVoutFaultLogged(uint32_t page) |
| 198 | { |
| 199 | voutErrors.push_back(page); |
| 200 | } |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 201 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 202 | /** |
| 203 | * Says if we've already logged a PGOOD fault |
| 204 | * |
| 205 | * The policy is only 1 of the same errors will |
| 206 | * be logged for the duration of a class instance. |
| 207 | * |
| 208 | * @param[in] input - the input to check |
| 209 | * |
| 210 | * @return bool - if we've already logged a fault against |
| 211 | * this input |
| 212 | */ |
| 213 | inline bool isPGOODFaultLogged(uint32_t input) const |
| 214 | { |
| 215 | return std::find(pgoodErrors.begin(), pgoodErrors.end(), input) != |
| 216 | pgoodErrors.end(); |
| 217 | } |
Matt Spinler | e7e432b | 2017-08-21 15:01:40 -0500 | [diff] [blame] | 218 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 219 | /** |
| 220 | * Says if we've already logged a specific fault |
| 221 | * against a specific part |
| 222 | * |
| 223 | * @param[in] callout - error type and name tuple |
| 224 | * |
| 225 | * @return bool - if we've already logged this fault |
| 226 | * against this part |
| 227 | */ |
| 228 | inline bool isPartCalledOut(const PartCallout& callout) const |
| 229 | { |
| 230 | return std::find(callouts.begin(), callouts.end(), callout) != |
| 231 | callouts.end(); |
| 232 | } |
Matt Spinler | e7e432b | 2017-08-21 15:01:40 -0500 | [diff] [blame] | 233 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 234 | /** |
| 235 | * Saves that a PGOOD fault has been logged |
| 236 | * |
| 237 | * @param[in] input - the input the error was logged against |
| 238 | */ |
| 239 | inline void setPGOODFaultLogged(uint32_t input) |
| 240 | { |
| 241 | pgoodErrors.push_back(input); |
| 242 | } |
Matt Spinler | d998b73 | 2017-08-21 15:35:54 -0500 | [diff] [blame] | 243 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 244 | /** |
| 245 | * Saves that a specific fault on a specific part has been done |
| 246 | * |
| 247 | * @param[in] callout - error type and name tuple |
| 248 | */ |
| 249 | inline void setPartCallout(const PartCallout& callout) |
| 250 | { |
| 251 | callouts.push_back(callout); |
| 252 | } |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 253 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 254 | /** |
| 255 | * List of pages that Vout errors have |
| 256 | * already been logged against |
| 257 | */ |
| 258 | std::vector<uint32_t> voutErrors; |
Matt Spinler | d998b73 | 2017-08-21 15:35:54 -0500 | [diff] [blame] | 259 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 260 | /** |
| 261 | * List of inputs that PGOOD errors have |
| 262 | * already been logged against |
| 263 | */ |
| 264 | std::vector<uint32_t> pgoodErrors; |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 265 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 266 | /** |
| 267 | * List of callouts that already been done |
| 268 | */ |
| 269 | std::vector<PartCallout> callouts; |
Matt Spinler | e7e432b | 2017-08-21 15:01:40 -0500 | [diff] [blame] | 270 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 271 | /** |
| 272 | * The read/write interface to this hardware |
| 273 | */ |
| 274 | pmbus::PMBus interface; |
Matt Spinler | d998b73 | 2017-08-21 15:35:54 -0500 | [diff] [blame] | 275 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 276 | /** |
| 277 | * A map of GPI pin IDs to the GPIO object |
| 278 | * used to access them |
| 279 | */ |
| 280 | std::map<size_t, std::unique_ptr<gpio::GPIO>> gpios; |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 281 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 282 | /** |
| 283 | * Keeps track of device access errors to avoid repeatedly |
| 284 | * logging errors for bad hardware |
| 285 | */ |
| 286 | bool accessError = false; |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 287 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 288 | /** |
| 289 | * Keeps track of GPIO access errors when doing the in depth |
| 290 | * PGOOD fault analysis to avoid repeatedly logging errors |
| 291 | * for bad hardware |
| 292 | */ |
| 293 | bool gpioAccessError = false; |
Matt Spinler | d998b73 | 2017-08-21 15:35:54 -0500 | [diff] [blame] | 294 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 295 | /** |
| 296 | * The path to the GPIO device used to read |
| 297 | * the GPI (PGOOD) status |
| 298 | */ |
Brandon Wyman | 9c7897c | 2019-03-28 17:42:34 -0500 | [diff] [blame] | 299 | std::filesystem::path gpioDevice; |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 300 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 301 | /** |
| 302 | * The D-Bus bus object |
| 303 | */ |
| 304 | sdbusplus::bus::bus& bus; |
Matt Spinler | 8bc1283 | 2017-09-19 11:17:54 -0500 | [diff] [blame] | 305 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 306 | /** |
| 307 | * Map of device instance to the instance specific data |
| 308 | */ |
| 309 | static const ucd90160::DeviceMap deviceMap; |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 310 | }; |
| 311 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 312 | } // namespace power |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 313 | } // namespace phosphor |