176c14c3bSShawn McCarney /** 276c14c3bSShawn McCarney * Copyright © 2020 IBM Corporation 376c14c3bSShawn McCarney * 476c14c3bSShawn McCarney * Licensed under the Apache License, Version 2.0 (the "License"); 576c14c3bSShawn McCarney * you may not use this file except in compliance with the License. 676c14c3bSShawn McCarney * You may obtain a copy of the License at 776c14c3bSShawn McCarney * 876c14c3bSShawn McCarney * http://www.apache.org/licenses/LICENSE-2.0 976c14c3bSShawn McCarney * 1076c14c3bSShawn McCarney * Unless required by applicable law or agreed to in writing, software 1176c14c3bSShawn McCarney * distributed under the License is distributed on an "AS IS" BASIS, 1276c14c3bSShawn McCarney * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1376c14c3bSShawn McCarney * See the License for the specific language governing permissions and 1476c14c3bSShawn McCarney * limitations under the License. 1576c14c3bSShawn McCarney */ 1676c14c3bSShawn McCarney #pragma once 1776c14c3bSShawn McCarney 181df5954cSShawn McCarney #include "ffdc_file.hpp" 191df5954cSShawn McCarney #include "journal.hpp" 205dab5d3dSShawn McCarney #include "phase_fault.hpp" 211df5954cSShawn McCarney #include "xyz/openbmc_project/Logging/Create/server.hpp" 221df5954cSShawn McCarney #include "xyz/openbmc_project/Logging/Entry/server.hpp" 231df5954cSShawn McCarney 2476c14c3bSShawn McCarney #include <sdbusplus/bus.hpp> 2576c14c3bSShawn McCarney 261df5954cSShawn McCarney #include <cstdint> 271df5954cSShawn McCarney #include <map> 281df5954cSShawn McCarney #include <string> 291df5954cSShawn McCarney #include <tuple> 301df5954cSShawn McCarney #include <vector> 311df5954cSShawn McCarney 3276c14c3bSShawn McCarney namespace phosphor::power::regulators 3376c14c3bSShawn McCarney { 3476c14c3bSShawn McCarney 351df5954cSShawn McCarney using namespace sdbusplus::xyz::openbmc_project::Logging::server; 361df5954cSShawn McCarney using FFDCTuple = 371df5954cSShawn McCarney std::tuple<FFDCFormat, uint8_t, uint8_t, sdbusplus::message::unix_fd>; 381df5954cSShawn McCarney 3976c14c3bSShawn McCarney /** 4076c14c3bSShawn McCarney * @class ErrorLogging 4176c14c3bSShawn McCarney * 4276c14c3bSShawn McCarney * Abstract base class that provides an error logging interface. 4376c14c3bSShawn McCarney * 4476c14c3bSShawn McCarney * The interface is used to create error logs. 4576c14c3bSShawn McCarney */ 4676c14c3bSShawn McCarney class ErrorLogging 4776c14c3bSShawn McCarney { 4876c14c3bSShawn McCarney public: 4976c14c3bSShawn McCarney // Specify which compiler-generated methods we want 5076c14c3bSShawn McCarney ErrorLogging() = default; 5176c14c3bSShawn McCarney ErrorLogging(const ErrorLogging&) = delete; 5276c14c3bSShawn McCarney ErrorLogging(ErrorLogging&&) = delete; 5376c14c3bSShawn McCarney ErrorLogging& operator=(const ErrorLogging&) = delete; 5476c14c3bSShawn McCarney ErrorLogging& operator=(ErrorLogging&&) = delete; 5576c14c3bSShawn McCarney virtual ~ErrorLogging() = default; 5676c14c3bSShawn McCarney 571df5954cSShawn McCarney /** 581df5954cSShawn McCarney * Log a regulators configuration file error. 591df5954cSShawn McCarney * 601df5954cSShawn McCarney * This error is logged when the regulators configuration file could not be 611df5954cSShawn McCarney * found, could not be read, or had invalid contents. 621df5954cSShawn McCarney * 631df5954cSShawn McCarney * @param severity severity level 641df5954cSShawn McCarney * @param journal system journal 651df5954cSShawn McCarney */ 661df5954cSShawn McCarney virtual void logConfigFileError(Entry::Level severity, 671df5954cSShawn McCarney Journal& journal) = 0; 681df5954cSShawn McCarney 691df5954cSShawn McCarney /** 701df5954cSShawn McCarney * Log a D-Bus error. 711df5954cSShawn McCarney * 721df5954cSShawn McCarney * This error is logged when D-Bus communication fails. 731df5954cSShawn McCarney * 741df5954cSShawn McCarney * @param severity severity level 751df5954cSShawn McCarney * @param journal system journal 761df5954cSShawn McCarney */ 771df5954cSShawn McCarney virtual void logDBusError(Entry::Level severity, Journal& journal) = 0; 781df5954cSShawn McCarney 791df5954cSShawn McCarney /** 801df5954cSShawn McCarney * Log an I2C communication error. 811df5954cSShawn McCarney * 821df5954cSShawn McCarney * @param severity severity level 831df5954cSShawn McCarney * @param journal system journal 841df5954cSShawn McCarney * @param bus I2C bus in the form "/dev/i2c-X", where X is the 0-based bus 851df5954cSShawn McCarney * number 861df5954cSShawn McCarney * @param addr 7 bit I2C address 871df5954cSShawn McCarney * @param errorNumber errno value from the failed I2C operation 881df5954cSShawn McCarney */ 891df5954cSShawn McCarney virtual void logI2CError(Entry::Level severity, Journal& journal, 901df5954cSShawn McCarney const std::string& bus, uint8_t addr, 911df5954cSShawn McCarney int errorNumber) = 0; 921df5954cSShawn McCarney 931df5954cSShawn McCarney /** 941df5954cSShawn McCarney * Log an internal firmware error. 951df5954cSShawn McCarney * 961df5954cSShawn McCarney * @param severity severity level 971df5954cSShawn McCarney * @param journal system journal 981df5954cSShawn McCarney */ 991df5954cSShawn McCarney virtual void logInternalError(Entry::Level severity, Journal& journal) = 0; 1001df5954cSShawn McCarney 1011df5954cSShawn McCarney /** 1025dab5d3dSShawn McCarney * Log a phase fault error. 1035dab5d3dSShawn McCarney * 1045dab5d3dSShawn McCarney * This error is logged when a regulator has lost a redundant phase. 1055dab5d3dSShawn McCarney * 1065dab5d3dSShawn McCarney * @param severity severity level 1075dab5d3dSShawn McCarney * @param journal system journal 1085dab5d3dSShawn McCarney * @param type phase fault type 1095dab5d3dSShawn McCarney * @param inventoryPath D-Bus inventory path of the device where the error 1105dab5d3dSShawn McCarney * occurred 1115dab5d3dSShawn McCarney * @param additionalData additional error data (if any) 1125dab5d3dSShawn McCarney */ 1135dab5d3dSShawn McCarney virtual void 1145dab5d3dSShawn McCarney logPhaseFault(Entry::Level severity, Journal& journal, 1155dab5d3dSShawn McCarney PhaseFaultType type, const std::string& inventoryPath, 1165dab5d3dSShawn McCarney std::map<std::string, std::string> additionalData) = 0; 1175dab5d3dSShawn McCarney 1185dab5d3dSShawn McCarney /** 1191df5954cSShawn McCarney * Log a PMBus error. 1201df5954cSShawn McCarney * 1211df5954cSShawn McCarney * This error is logged when the I2C communication was successful, but the 1221df5954cSShawn McCarney * PMBus value read is invalid or unsupported. 1231df5954cSShawn McCarney * 1241df5954cSShawn McCarney * @param severity severity level 1251df5954cSShawn McCarney * @param journal system journal 1261df5954cSShawn McCarney * @param inventoryPath D-Bus inventory path of the device where the error 1271df5954cSShawn McCarney * occurred 1281df5954cSShawn McCarney */ 1291df5954cSShawn McCarney virtual void logPMBusError(Entry::Level severity, Journal& journal, 1301df5954cSShawn McCarney const std::string& inventoryPath) = 0; 1311df5954cSShawn McCarney 1321df5954cSShawn McCarney /** 1331df5954cSShawn McCarney * Log a write verification error. 1341df5954cSShawn McCarney * 1351df5954cSShawn McCarney * This error is logged when a device register is written, read back, and 1361df5954cSShawn McCarney * the two values do not match. This is also called a read-back error. 1371df5954cSShawn McCarney * 1381df5954cSShawn McCarney * @param severity severity level 1391df5954cSShawn McCarney * @param journal system journal 1401df5954cSShawn McCarney * @param inventoryPath D-Bus inventory path of the device where the error 1411df5954cSShawn McCarney * occurred 1421df5954cSShawn McCarney */ 1431df5954cSShawn McCarney virtual void 1441df5954cSShawn McCarney logWriteVerificationError(Entry::Level severity, Journal& journal, 1451df5954cSShawn McCarney const std::string& inventoryPath) = 0; 14676c14c3bSShawn McCarney }; 14776c14c3bSShawn McCarney 14876c14c3bSShawn McCarney /** 14976c14c3bSShawn McCarney * @class DBusErrorLogging 15076c14c3bSShawn McCarney * 15176c14c3bSShawn McCarney * Implementation of the ErrorLogging interface using D-Bus method calls. 15276c14c3bSShawn McCarney */ 15376c14c3bSShawn McCarney class DBusErrorLogging : public ErrorLogging 15476c14c3bSShawn McCarney { 15576c14c3bSShawn McCarney public: 15676c14c3bSShawn McCarney // Specify which compiler-generated methods we want 15776c14c3bSShawn McCarney DBusErrorLogging() = delete; 15876c14c3bSShawn McCarney DBusErrorLogging(const DBusErrorLogging&) = delete; 15976c14c3bSShawn McCarney DBusErrorLogging(DBusErrorLogging&&) = delete; 16076c14c3bSShawn McCarney DBusErrorLogging& operator=(const DBusErrorLogging&) = delete; 16176c14c3bSShawn McCarney DBusErrorLogging& operator=(DBusErrorLogging&&) = delete; 16276c14c3bSShawn McCarney virtual ~DBusErrorLogging() = default; 16376c14c3bSShawn McCarney 16476c14c3bSShawn McCarney /** 16576c14c3bSShawn McCarney * Constructor. 16676c14c3bSShawn McCarney * 16776c14c3bSShawn McCarney * @param bus D-Bus bus object 16876c14c3bSShawn McCarney */ DBusErrorLogging(sdbusplus::bus_t & bus)169*48781aefSPatrick Williams explicit DBusErrorLogging(sdbusplus::bus_t& bus) : bus{bus} {} 17076c14c3bSShawn McCarney 1711df5954cSShawn McCarney /** @copydoc ErrorLogging::logConfigFileError() */ 1721df5954cSShawn McCarney virtual void logConfigFileError(Entry::Level severity, 1731df5954cSShawn McCarney Journal& journal) override; 1741df5954cSShawn McCarney 1751df5954cSShawn McCarney /** @copydoc ErrorLogging::logDBusError() */ 1761df5954cSShawn McCarney virtual void logDBusError(Entry::Level severity, Journal& journal) override; 1771df5954cSShawn McCarney 1781df5954cSShawn McCarney /** @copydoc ErrorLogging::logI2CError() */ 1791df5954cSShawn McCarney virtual void logI2CError(Entry::Level severity, Journal& journal, 1801df5954cSShawn McCarney const std::string& bus, uint8_t addr, 1811df5954cSShawn McCarney int errorNumber) override; 1821df5954cSShawn McCarney 1831df5954cSShawn McCarney /** @copydoc ErrorLogging::logInternalError() */ 1841df5954cSShawn McCarney virtual void logInternalError(Entry::Level severity, 1851df5954cSShawn McCarney Journal& journal) override; 1861df5954cSShawn McCarney 1875dab5d3dSShawn McCarney /** @copydoc ErrorLogging::logPhaseFault() */ 1885dab5d3dSShawn McCarney virtual void logPhaseFault( 1895dab5d3dSShawn McCarney Entry::Level severity, Journal& journal, PhaseFaultType type, 1905dab5d3dSShawn McCarney const std::string& inventoryPath, 1915dab5d3dSShawn McCarney std::map<std::string, std::string> additionalData) override; 1925dab5d3dSShawn McCarney 1931df5954cSShawn McCarney /** @copydoc ErrorLogging::logPMBusError() */ 1941df5954cSShawn McCarney virtual void logPMBusError(Entry::Level severity, Journal& journal, 1951df5954cSShawn McCarney const std::string& inventoryPath) override; 1961df5954cSShawn McCarney 1971df5954cSShawn McCarney /** @copydoc ErrorLogging::logWriteVerificationError() */ 1981df5954cSShawn McCarney virtual void 1991df5954cSShawn McCarney logWriteVerificationError(Entry::Level severity, Journal& journal, 2001df5954cSShawn McCarney const std::string& inventoryPath) override; 20176c14c3bSShawn McCarney 20276c14c3bSShawn McCarney private: 20376c14c3bSShawn McCarney /** 2041df5954cSShawn McCarney * Create an FFDCFile object containing the specified lines of text data. 2051df5954cSShawn McCarney * 2061df5954cSShawn McCarney * Throws an exception if an error occurs. 2071df5954cSShawn McCarney * 2081df5954cSShawn McCarney * @param lines lines of text data to write to file 2091df5954cSShawn McCarney * @return FFDCFile object 2101df5954cSShawn McCarney */ 2111df5954cSShawn McCarney FFDCFile createFFDCFile(const std::vector<std::string>& lines); 2121df5954cSShawn McCarney 2131df5954cSShawn McCarney /** 2141df5954cSShawn McCarney * Create FFDCFile objects containing debug data to store in the error log. 2151df5954cSShawn McCarney * 2161df5954cSShawn McCarney * If an error occurs, the error is written to the journal but an exception 2171df5954cSShawn McCarney * is not thrown. 2181df5954cSShawn McCarney * 2191df5954cSShawn McCarney * @param journal system journal 2201df5954cSShawn McCarney * @return vector of FFDCFile objects 2211df5954cSShawn McCarney */ 2221df5954cSShawn McCarney std::vector<FFDCFile> createFFDCFiles(Journal& journal); 2231df5954cSShawn McCarney 2241df5954cSShawn McCarney /** 2251df5954cSShawn McCarney * Create FFDCTuple objects corresponding to the specified FFDC files. 2261df5954cSShawn McCarney * 2271df5954cSShawn McCarney * The D-Bus method to create an error log requires a vector of tuples to 2281df5954cSShawn McCarney * pass in the FFDC file information. 2291df5954cSShawn McCarney * 2301df5954cSShawn McCarney * @param files FFDC files 2311df5954cSShawn McCarney * @return vector of FFDCTuple objects 2321df5954cSShawn McCarney */ 2331df5954cSShawn McCarney std::vector<FFDCTuple> createFFDCTuples(std::vector<FFDCFile>& files); 2341df5954cSShawn McCarney 2351df5954cSShawn McCarney /** 2361df5954cSShawn McCarney * Logs an error using the D-Bus CreateWithFFDCFiles method. 2371df5954cSShawn McCarney * 2381df5954cSShawn McCarney * If logging fails, a message is written to the journal but an exception is 2391df5954cSShawn McCarney * not thrown. 2401df5954cSShawn McCarney * 2411df5954cSShawn McCarney * @param message Message property of the error log entry 2421df5954cSShawn McCarney * @param severity Severity property of the error log entry 2431df5954cSShawn McCarney * @param additionalData AdditionalData property of the error log entry 2441df5954cSShawn McCarney * @param journal system journal 2451df5954cSShawn McCarney */ 2461df5954cSShawn McCarney void logError(const std::string& message, Entry::Level severity, 2471df5954cSShawn McCarney std::map<std::string, std::string>& additionalData, 2481df5954cSShawn McCarney Journal& journal); 2491df5954cSShawn McCarney 2501df5954cSShawn McCarney /** 2511df5954cSShawn McCarney * Removes the specified FFDC files from the file system. 2521df5954cSShawn McCarney * 2531df5954cSShawn McCarney * Also clears the specified vector, removing the FFDCFile objects. 2541df5954cSShawn McCarney * 2551df5954cSShawn McCarney * If an error occurs, the error is written to the journal but an exception 2561df5954cSShawn McCarney * is not thrown. 2571df5954cSShawn McCarney * 2581df5954cSShawn McCarney * @param files FFDC files to remove 2591df5954cSShawn McCarney * @param journal system journal 2601df5954cSShawn McCarney */ 2611df5954cSShawn McCarney void removeFFDCFiles(std::vector<FFDCFile>& files, Journal& journal); 2621df5954cSShawn McCarney 2631df5954cSShawn McCarney /** 26476c14c3bSShawn McCarney * D-Bus bus object. 26576c14c3bSShawn McCarney */ 2667354ce62SPatrick Williams sdbusplus::bus_t& bus; 26776c14c3bSShawn McCarney }; 26876c14c3bSShawn McCarney 26976c14c3bSShawn McCarney } // namespace phosphor::power::regulators 270