| SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 1 | #include "config.h" | 
|  | 2 |  | 
|  | 3 | #include "manager.hpp" | 
|  | 4 |  | 
| Santosh Puranik | bf78ed8 | 2022-04-20 13:17:04 +0530 | [diff] [blame] | 5 | #include "common_utility.hpp" | 
| SunnySrivastava1984 | d076da8 | 2020-03-05 05:33:35 -0600 | [diff] [blame] | 6 | #include "editor_impl.hpp" | 
| Sunny Srivastava | 6c71c9d | 2021-04-15 04:43:54 -0500 | [diff] [blame] | 7 | #include "ibm_vpd_utils.hpp" | 
| SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 8 | #include "ipz_parser.hpp" | 
| Santosh Puranik | 6b2b537 | 2022-06-02 20:49:02 +0530 | [diff] [blame] | 9 | #include "parser_factory.hpp" | 
| SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame] | 10 | #include "reader_impl.hpp" | 
| SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 11 | #include "vpd_exceptions.hpp" | 
|  | 12 |  | 
| Sunny Srivastava | 4788e1b | 2024-03-19 02:11:07 -0500 | [diff] [blame] | 13 | #include <unistd.h> | 
|  | 14 |  | 
| SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 15 | #include <phosphor-logging/elog-errors.hpp> | 
| Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 16 | #include <xyz/openbmc_project/Common/error.hpp> | 
| SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 17 |  | 
| Patrick Williams | c78d887 | 2023-05-10 07:50:56 -0500 | [diff] [blame] | 18 | #include <filesystem> | 
|  | 19 |  | 
| SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 20 | using namespace openpower::vpd::constants; | 
| SunnySrivastava1984 | 1356d7e | 2020-04-24 04:29:35 -0500 | [diff] [blame] | 21 | using namespace openpower::vpd::inventory; | 
| SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 22 | using namespace openpower::vpd::manager::editor; | 
| SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame] | 23 | using namespace openpower::vpd::manager::reader; | 
| SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 24 | using namespace std; | 
|  | 25 | using namespace openpower::vpd::parser; | 
| Santosh Puranik | 6b2b537 | 2022-06-02 20:49:02 +0530 | [diff] [blame] | 26 | using namespace openpower::vpd::parser::factory; | 
|  | 27 | using namespace openpower::vpd::ipz::parser; | 
| SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 28 | using namespace openpower::vpd::exceptions; | 
|  | 29 | using namespace phosphor::logging; | 
| SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 30 |  | 
|  | 31 | namespace openpower | 
|  | 32 | { | 
|  | 33 | namespace vpd | 
|  | 34 | { | 
|  | 35 | namespace manager | 
|  | 36 | { | 
| Sunny Srivastava | c6e7ea9 | 2023-11-03 21:10:43 +0530 | [diff] [blame] | 37 |  | 
| Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 38 | Manager::Manager(std::shared_ptr<boost::asio::io_context>& ioCon, | 
|  | 39 | std::shared_ptr<sdbusplus::asio::dbus_interface>& iFace, | 
|  | 40 | std::shared_ptr<sdbusplus::asio::connection>& conn) : | 
| Patrick Williams | 08dc31c | 2024-08-16 15:21:06 -0400 | [diff] [blame^] | 41 | ioContext(ioCon), interface(iFace), conn(conn) | 
| SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 42 | { | 
| Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 43 | interface->register_method( | 
|  | 44 | "WriteKeyword", | 
|  | 45 | [this](const sdbusplus::message::object_path& path, | 
|  | 46 | const std::string& recordName, const std::string& keyword, | 
|  | 47 | const Binary& value) { | 
| Patrick Williams | 08dc31c | 2024-08-16 15:21:06 -0400 | [diff] [blame^] | 48 | this->writeKeyword(path, recordName, keyword, value); | 
|  | 49 | }); | 
| Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 50 |  | 
|  | 51 | interface->register_method( | 
|  | 52 | "GetFRUsByUnexpandedLocationCode", | 
|  | 53 | [this](const std::string& locationCode, | 
|  | 54 | const uint16_t nodeNumber) -> inventory::ListOfPaths { | 
| Patrick Williams | 08dc31c | 2024-08-16 15:21:06 -0400 | [diff] [blame^] | 55 | return this->getFRUsByUnexpandedLocationCode(locationCode, | 
|  | 56 | nodeNumber); | 
|  | 57 | }); | 
| Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 58 |  | 
|  | 59 | interface->register_method( | 
|  | 60 | "GetFRUsByExpandedLocationCode", | 
|  | 61 | [this](const std::string& locationCode) -> inventory::ListOfPaths { | 
| Patrick Williams | 08dc31c | 2024-08-16 15:21:06 -0400 | [diff] [blame^] | 62 | return this->getFRUsByExpandedLocationCode(locationCode); | 
|  | 63 | }); | 
| Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 64 |  | 
|  | 65 | interface->register_method( | 
|  | 66 | "GetExpandedLocationCode", | 
|  | 67 | [this](const std::string& locationCode, | 
|  | 68 | const uint16_t nodeNumber) -> std::string { | 
| Patrick Williams | 08dc31c | 2024-08-16 15:21:06 -0400 | [diff] [blame^] | 69 | return this->getExpandedLocationCode(locationCode, nodeNumber); | 
|  | 70 | }); | 
| Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 71 |  | 
| Patrick Williams | 08dc31c | 2024-08-16 15:21:06 -0400 | [diff] [blame^] | 72 | interface->register_method("PerformVPDRecollection", [this]() { | 
|  | 73 | this->performVPDRecollection(); | 
|  | 74 | }); | 
| Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 75 |  | 
| Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 76 | interface->register_method( | 
|  | 77 | "deleteFRUVPD", [this](const sdbusplus::message::object_path& path) { | 
| Patrick Williams | 08dc31c | 2024-08-16 15:21:06 -0400 | [diff] [blame^] | 78 | this->deleteFRUVPD(path); | 
|  | 79 | }); | 
| Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 80 |  | 
| Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 81 | interface->register_method( | 
|  | 82 | "CollectFRUVPD", [this](const sdbusplus::message::object_path& path) { | 
| Patrick Williams | 08dc31c | 2024-08-16 15:21:06 -0400 | [diff] [blame^] | 83 | this->collectFRUVPD(path); | 
|  | 84 | }); | 
| Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 85 |  | 
| Sunny Srivastava | fdf9ff2 | 2022-06-15 11:15:54 -0500 | [diff] [blame] | 86 | sd_bus_default(&sdBus); | 
| Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 87 | initManager(); | 
| SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 88 | } | 
|  | 89 |  | 
| Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 90 | void Manager::initManager() | 
| SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 91 | { | 
| SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 92 | try | 
|  | 93 | { | 
|  | 94 | processJSON(); | 
| Santosh Puranik | 6b2b537 | 2022-06-02 20:49:02 +0530 | [diff] [blame] | 95 | restoreSystemVpd(); | 
| Sunny Srivastava | ecb5c7d | 2021-09-02 07:20:24 -0500 | [diff] [blame] | 96 | listenHostState(); | 
| Santosh Puranik | b62f605 | 2022-04-06 18:37:54 +0530 | [diff] [blame] | 97 | listenAssetTag(); | 
| Alpana Kumari | b17dd3b | 2020-10-01 00:18:10 -0500 | [diff] [blame] | 98 |  | 
| Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 99 | // Create an instance of the BIOS handler | 
| Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 100 | biosHandler = std::make_shared<BiosHandler>(conn, *this); | 
| Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 101 |  | 
| Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 102 | // instantiate gpioMonitor class | 
|  | 103 | gpioMon = std::make_shared<GpioMonitor>(jsonFile, ioContext); | 
| SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 104 | } | 
|  | 105 | catch (const std::exception& e) | 
|  | 106 | { | 
|  | 107 | std::cerr << e.what() << "\n"; | 
|  | 108 | } | 
| SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 109 | } | 
|  | 110 |  | 
| Santosh Puranik | 6b2b537 | 2022-06-02 20:49:02 +0530 | [diff] [blame] | 111 | /** | 
|  | 112 | * @brief An api to get list of blank system VPD properties. | 
|  | 113 | * @param[in] vpdMap - IPZ vpd map. | 
|  | 114 | * @param[in] objectPath - Object path for the FRU. | 
|  | 115 | * @param[out] blankPropertyList - Properties which are blank in System VPD and | 
|  | 116 | * needs to be updated as standby. | 
|  | 117 | */ | 
|  | 118 | static void | 
|  | 119 | getListOfBlankSystemVpd(Parsed& vpdMap, const string& objectPath, | 
|  | 120 | std::vector<RestoredEeproms>& blankPropertyList) | 
|  | 121 | { | 
|  | 122 | for (const auto& systemRecKwdPair : svpdKwdMap) | 
|  | 123 | { | 
|  | 124 | auto it = vpdMap.find(systemRecKwdPair.first); | 
|  | 125 |  | 
|  | 126 | // check if record is found in map we got by parser | 
|  | 127 | if (it != vpdMap.end()) | 
|  | 128 | { | 
|  | 129 | const auto& kwdListForRecord = systemRecKwdPair.second; | 
| Priyanga Ramasamy | 952d6c5 | 2022-11-07 07:20:24 -0600 | [diff] [blame] | 130 | for (const auto& keywordInfo : kwdListForRecord) | 
| Santosh Puranik | 6b2b537 | 2022-06-02 20:49:02 +0530 | [diff] [blame] | 131 | { | 
| Priyanga Ramasamy | 952d6c5 | 2022-11-07 07:20:24 -0600 | [diff] [blame] | 132 | const auto& keyword = get<0>(keywordInfo); | 
|  | 133 |  | 
| Santosh Puranik | 6b2b537 | 2022-06-02 20:49:02 +0530 | [diff] [blame] | 134 | DbusPropertyMap& kwdValMap = it->second; | 
|  | 135 | auto iterator = kwdValMap.find(keyword); | 
|  | 136 |  | 
|  | 137 | if (iterator != kwdValMap.end()) | 
|  | 138 | { | 
|  | 139 | string& kwdValue = iterator->second; | 
|  | 140 |  | 
|  | 141 | // check bus data | 
|  | 142 | const string& recordName = systemRecKwdPair.first; | 
|  | 143 | const string& busValue = readBusProperty( | 
|  | 144 | objectPath, ipzVpdInf + recordName, keyword); | 
|  | 145 |  | 
| Priyanga Ramasamy | 834c078 | 2023-02-14 12:22:39 -0600 | [diff] [blame] | 146 | const auto& defaultValue = get<1>(keywordInfo); | 
|  | 147 |  | 
|  | 148 | if (Binary(busValue.begin(), busValue.end()) != | 
|  | 149 | defaultValue) | 
| Santosh Puranik | 6b2b537 | 2022-06-02 20:49:02 +0530 | [diff] [blame] | 150 | { | 
| Priyanga Ramasamy | 834c078 | 2023-02-14 12:22:39 -0600 | [diff] [blame] | 151 | if (Binary(kwdValue.begin(), kwdValue.end()) == | 
|  | 152 | defaultValue) | 
| Santosh Puranik | 6b2b537 | 2022-06-02 20:49:02 +0530 | [diff] [blame] | 153 | { | 
|  | 154 | // implies data is blank on EEPROM but not on cache. | 
|  | 155 | // So EEPROM vpd update is required. | 
|  | 156 | Binary busData(busValue.begin(), busValue.end()); | 
|  | 157 |  | 
|  | 158 | blankPropertyList.push_back(std::make_tuple( | 
|  | 159 | objectPath, recordName, keyword, busData)); | 
|  | 160 | } | 
|  | 161 | } | 
|  | 162 | } | 
|  | 163 | } | 
|  | 164 | } | 
|  | 165 | } | 
|  | 166 | } | 
|  | 167 |  | 
|  | 168 | void Manager::restoreSystemVpd() | 
|  | 169 | { | 
|  | 170 | std::cout << "Attempting system VPD restore" << std::endl; | 
|  | 171 | ParserInterface* parser = nullptr; | 
|  | 172 | try | 
|  | 173 | { | 
|  | 174 | auto vpdVector = getVpdDataInVector(jsonFile, systemVpdFilePath); | 
| girik | 18bb985 | 2022-11-16 05:48:13 -0600 | [diff] [blame] | 175 | uint32_t vpdStartOffset = 0; | 
| Sunny Srivastava | f31a91b | 2022-06-09 08:11:29 -0500 | [diff] [blame] | 176 | const auto& inventoryPath = | 
|  | 177 | jsonFile["frus"][systemVpdFilePath][0]["inventoryPath"] | 
|  | 178 | .get_ref<const nlohmann::json::string_t&>(); | 
|  | 179 |  | 
| girik | 18bb985 | 2022-11-16 05:48:13 -0600 | [diff] [blame] | 180 | parser = ParserFactory::getParser(vpdVector, (pimPath + inventoryPath), | 
|  | 181 | systemVpdFilePath, vpdStartOffset); | 
| Santosh Puranik | 6b2b537 | 2022-06-02 20:49:02 +0530 | [diff] [blame] | 182 | auto parseResult = parser->parse(); | 
|  | 183 |  | 
|  | 184 | if (auto pVal = std::get_if<Store>(&parseResult)) | 
|  | 185 | { | 
|  | 186 | // map to hold all the keywords whose value is blank and | 
|  | 187 | // needs to be updated at standby. | 
|  | 188 | std::vector<RestoredEeproms> blankSystemVpdProperties{}; | 
|  | 189 | getListOfBlankSystemVpd(pVal->getVpdMap(), SYSTEM_OBJECT, | 
|  | 190 | blankSystemVpdProperties); | 
|  | 191 |  | 
|  | 192 | // if system VPD restore is required, update the | 
|  | 193 | // EEPROM | 
|  | 194 | for (const auto& item : blankSystemVpdProperties) | 
|  | 195 | { | 
|  | 196 | std::cout << "Restoring keyword: " << std::get<2>(item) | 
|  | 197 | << std::endl; | 
|  | 198 | writeKeyword(std::get<0>(item), std::get<1>(item), | 
|  | 199 | std::get<2>(item), std::get<3>(item)); | 
|  | 200 | } | 
|  | 201 | } | 
|  | 202 | else | 
|  | 203 | { | 
|  | 204 | std::cerr << "Not a valid format to restore system VPD" | 
|  | 205 | << std::endl; | 
|  | 206 | } | 
|  | 207 | } | 
|  | 208 | catch (const std::exception& e) | 
|  | 209 | { | 
|  | 210 | std::cerr << "Failed to restore system VPD due to exception: " | 
|  | 211 | << e.what() << std::endl; | 
|  | 212 | } | 
|  | 213 | // release the parser object | 
|  | 214 | ParserFactory::freeParser(parser); | 
|  | 215 | } | 
|  | 216 |  | 
| Sunny Srivastava | ecb5c7d | 2021-09-02 07:20:24 -0500 | [diff] [blame] | 217 | void Manager::listenHostState() | 
|  | 218 | { | 
| Patrick Williams | 2eb0176 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 219 | static std::shared_ptr<sdbusplus::bus::match_t> hostState = | 
|  | 220 | std::make_shared<sdbusplus::bus::match_t>( | 
| Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 221 | *conn, | 
| Sunny Srivastava | ecb5c7d | 2021-09-02 07:20:24 -0500 | [diff] [blame] | 222 | sdbusplus::bus::match::rules::propertiesChanged( | 
|  | 223 | "/xyz/openbmc_project/state/host0", | 
|  | 224 | "xyz.openbmc_project.State.Host"), | 
| Patrick Williams | 2eb0176 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 225 | [this](sdbusplus::message_t& msg) { hostStateCallBack(msg); }); | 
| Sunny Srivastava | ecb5c7d | 2021-09-02 07:20:24 -0500 | [diff] [blame] | 226 | } | 
|  | 227 |  | 
| Sunny Srivastava | fdf9ff2 | 2022-06-15 11:15:54 -0500 | [diff] [blame] | 228 | void Manager::checkEssentialFrus() | 
|  | 229 | { | 
|  | 230 | for (const auto& invPath : essentialFrus) | 
|  | 231 | { | 
|  | 232 | const auto res = readBusProperty(invPath, invItemIntf, "Present"); | 
|  | 233 |  | 
|  | 234 | // implies the essential FRU is missing. Log PEL. | 
|  | 235 | if (res == "false") | 
|  | 236 | { | 
|  | 237 | auto rc = sd_bus_call_method_async( | 
|  | 238 | sdBus, NULL, loggerService, loggerObjectPath, | 
|  | 239 | loggerCreateInterface, "Create", NULL, NULL, "ssa{ss}", | 
|  | 240 | errIntfForEssentialFru, | 
|  | 241 | "xyz.openbmc_project.Logging.Entry.Level.Warning", 2, | 
|  | 242 | "DESCRIPTION", "Essential fru missing from the system.", | 
|  | 243 | "CALLOUT_INVENTORY_PATH", (pimPath + invPath).c_str()); | 
|  | 244 |  | 
|  | 245 | if (rc < 0) | 
|  | 246 | { | 
|  | 247 | log<level::ERR>("Error calling sd_bus_call_method_async", | 
|  | 248 | entry("RC=%d", rc), | 
|  | 249 | entry("MSG=%s", strerror(-rc))); | 
|  | 250 | } | 
|  | 251 | } | 
|  | 252 | } | 
|  | 253 | } | 
|  | 254 |  | 
| Patrick Williams | 7a975f0 | 2022-12-07 03:19:53 -0600 | [diff] [blame] | 255 | void Manager::hostStateCallBack(sdbusplus::message_t& msg) | 
| Sunny Srivastava | ecb5c7d | 2021-09-02 07:20:24 -0500 | [diff] [blame] | 256 | { | 
|  | 257 | if (msg.is_method_error()) | 
|  | 258 | { | 
|  | 259 | std::cerr << "Error in reading signal " << std::endl; | 
|  | 260 | } | 
|  | 261 |  | 
|  | 262 | Path object; | 
|  | 263 | PropertyMap propMap; | 
|  | 264 | msg.read(object, propMap); | 
|  | 265 | const auto itr = propMap.find("CurrentHostState"); | 
|  | 266 | if (itr != propMap.end()) | 
|  | 267 | { | 
|  | 268 | if (auto hostState = std::get_if<std::string>(&(itr->second))) | 
|  | 269 | { | 
|  | 270 | // implies system is moving from standby to power on state | 
|  | 271 | if (*hostState == "xyz.openbmc_project.State.Host.HostState." | 
|  | 272 | "TransitioningToRunning") | 
|  | 273 | { | 
| Sunny Srivastava | fdf9ff2 | 2022-06-15 11:15:54 -0500 | [diff] [blame] | 274 | // detect if essential frus are present in the system. | 
|  | 275 | checkEssentialFrus(); | 
|  | 276 |  | 
| Manojkiran Eda | af92175 | 2024-06-17 15:10:21 +0530 | [diff] [blame] | 277 | // check and perform recollection for FRUs replaceable at | 
| Sunny Srivastava | ecb5c7d | 2021-09-02 07:20:24 -0500 | [diff] [blame] | 278 | // standby. | 
|  | 279 | performVPDRecollection(); | 
|  | 280 | return; | 
|  | 281 | } | 
|  | 282 | } | 
| Sunny Srivastava | ecb5c7d | 2021-09-02 07:20:24 -0500 | [diff] [blame] | 283 | } | 
|  | 284 | } | 
|  | 285 |  | 
| Santosh Puranik | b62f605 | 2022-04-06 18:37:54 +0530 | [diff] [blame] | 286 | void Manager::listenAssetTag() | 
|  | 287 | { | 
| Patrick Williams | 2eb0176 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 288 | static std::shared_ptr<sdbusplus::bus::match_t> assetMatcher = | 
|  | 289 | std::make_shared<sdbusplus::bus::match_t>( | 
| Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 290 | *conn, | 
| Santosh Puranik | b62f605 | 2022-04-06 18:37:54 +0530 | [diff] [blame] | 291 | sdbusplus::bus::match::rules::propertiesChanged( | 
|  | 292 | "/xyz/openbmc_project/inventory/system", | 
|  | 293 | "xyz.openbmc_project.Inventory.Decorator.AssetTag"), | 
| Patrick Williams | 2eb0176 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 294 | [this](sdbusplus::message_t& msg) { assetTagCallback(msg); }); | 
| Santosh Puranik | b62f605 | 2022-04-06 18:37:54 +0530 | [diff] [blame] | 295 | } | 
|  | 296 |  | 
| Patrick Williams | 2eb0176 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 297 | void Manager::assetTagCallback(sdbusplus::message_t& msg) | 
| Santosh Puranik | b62f605 | 2022-04-06 18:37:54 +0530 | [diff] [blame] | 298 | { | 
|  | 299 | if (msg.is_method_error()) | 
|  | 300 | { | 
|  | 301 | std::cerr << "Error in reading signal " << std::endl; | 
|  | 302 | } | 
|  | 303 |  | 
|  | 304 | Path object; | 
|  | 305 | PropertyMap propMap; | 
|  | 306 | msg.read(object, propMap); | 
|  | 307 | const auto itr = propMap.find("AssetTag"); | 
|  | 308 | if (itr != propMap.end()) | 
|  | 309 | { | 
|  | 310 | if (auto assetTag = std::get_if<std::string>(&(itr->second))) | 
|  | 311 | { | 
|  | 312 | // Call Notify to persist the AssetTag | 
|  | 313 | inventory::ObjectMap objectMap = { | 
|  | 314 | {std::string{"/system"}, | 
|  | 315 | {{"xyz.openbmc_project.Inventory.Decorator.AssetTag", | 
|  | 316 | {{"AssetTag", *assetTag}}}}}}; | 
|  | 317 |  | 
|  | 318 | common::utility::callPIM(std::move(objectMap)); | 
|  | 319 | } | 
|  | 320 | else | 
|  | 321 | { | 
|  | 322 | std::cerr << "Failed to read asset tag" << std::endl; | 
|  | 323 | } | 
|  | 324 | } | 
|  | 325 | } | 
|  | 326 |  | 
| SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 327 | void Manager::processJSON() | 
|  | 328 | { | 
| Santosh Puranik | 0246a4d | 2020-11-04 16:57:39 +0530 | [diff] [blame] | 329 | std::ifstream json(INVENTORY_JSON_SYM_LINK, std::ios::binary); | 
| SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 330 |  | 
|  | 331 | if (!json) | 
|  | 332 | { | 
|  | 333 | throw std::runtime_error("json file not found"); | 
|  | 334 | } | 
|  | 335 |  | 
|  | 336 | jsonFile = nlohmann::json::parse(json); | 
|  | 337 | if (jsonFile.find("frus") == jsonFile.end()) | 
|  | 338 | { | 
|  | 339 | throw std::runtime_error("frus group not found in json"); | 
|  | 340 | } | 
|  | 341 |  | 
|  | 342 | const nlohmann::json& groupFRUS = | 
|  | 343 | jsonFile["frus"].get_ref<const nlohmann::json::object_t&>(); | 
|  | 344 | for (const auto& itemFRUS : groupFRUS.items()) | 
|  | 345 | { | 
|  | 346 | const std::vector<nlohmann::json>& groupEEPROM = | 
|  | 347 | itemFRUS.value().get_ref<const nlohmann::json::array_t&>(); | 
|  | 348 | for (const auto& itemEEPROM : groupEEPROM) | 
| SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 349 | { | 
| SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 350 | bool isMotherboard = false; | 
| Santosh Puranik | a0b2391 | 2022-02-10 13:37:09 +0530 | [diff] [blame] | 351 | std::string redundantPath; | 
|  | 352 |  | 
| SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 353 | if (itemEEPROM["extraInterfaces"].find( | 
|  | 354 | "xyz.openbmc_project.Inventory.Item.Board.Motherboard") != | 
|  | 355 | itemEEPROM["extraInterfaces"].end()) | 
|  | 356 | { | 
|  | 357 | isMotherboard = true; | 
|  | 358 | } | 
| Santosh Puranik | a0b2391 | 2022-02-10 13:37:09 +0530 | [diff] [blame] | 359 | if (itemEEPROM.find("redundantEeprom") != itemEEPROM.end()) | 
|  | 360 | { | 
|  | 361 | redundantPath = itemEEPROM["redundantEeprom"] | 
|  | 362 | .get_ref<const nlohmann::json::string_t&>(); | 
|  | 363 | } | 
|  | 364 | frus.emplace( | 
|  | 365 | itemEEPROM["inventoryPath"] | 
|  | 366 | .get_ref<const nlohmann::json::string_t&>(), | 
|  | 367 | std::make_tuple(itemFRUS.key(), redundantPath, isMotherboard)); | 
| SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame] | 368 |  | 
| Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 369 | if (itemEEPROM["extraInterfaces"].find(IBM_LOCATION_CODE_INF) != | 
| Alpana Kumari | 920408d | 2020-05-14 00:07:03 -0500 | [diff] [blame] | 370 | itemEEPROM["extraInterfaces"].end()) | 
|  | 371 | { | 
|  | 372 | fruLocationCode.emplace( | 
| Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 373 | itemEEPROM["extraInterfaces"][IBM_LOCATION_CODE_INF] | 
| Alpana Kumari | 920408d | 2020-05-14 00:07:03 -0500 | [diff] [blame] | 374 | ["LocationCode"] | 
|  | 375 | .get_ref<const nlohmann::json::string_t&>(), | 
|  | 376 | itemEEPROM["inventoryPath"] | 
|  | 377 | .get_ref<const nlohmann::json::string_t&>()); | 
|  | 378 | } | 
| SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 379 |  | 
| Sunny Srivastava | ecb5c7d | 2021-09-02 07:20:24 -0500 | [diff] [blame] | 380 | if (itemEEPROM.value("replaceableAtStandby", false)) | 
| SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 381 | { | 
|  | 382 | replaceableFrus.emplace_back(itemFRUS.key()); | 
|  | 383 | } | 
| Sunny Srivastava | fdf9ff2 | 2022-06-15 11:15:54 -0500 | [diff] [blame] | 384 |  | 
|  | 385 | if (itemEEPROM.value("essentialFru", false)) | 
|  | 386 | { | 
|  | 387 | essentialFrus.emplace_back(itemEEPROM["inventoryPath"]); | 
|  | 388 | } | 
| SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 389 | } | 
|  | 390 | } | 
|  | 391 | } | 
|  | 392 |  | 
| Sunny Srivastava | 8377086 | 2023-10-31 12:57:20 -0500 | [diff] [blame] | 393 | void Manager::updateSystemVPDBackUpFRU(const std::string& recordName, | 
|  | 394 | const std::string& keyword, | 
|  | 395 | const Binary& value) | 
|  | 396 | { | 
|  | 397 | const std::string& systemVpdBackupPath = | 
|  | 398 | jsonFile["frus"][systemVpdFilePath].at(0).value("systemVpdBackupPath", | 
|  | 399 | ""); | 
|  | 400 |  | 
|  | 401 | if (!systemVpdBackupPath.empty() && | 
|  | 402 | jsonFile["frus"][systemVpdBackupPath].at(0).contains("inventoryPath")) | 
|  | 403 | { | 
|  | 404 | std::string systemVpdBackupInvPath = | 
|  | 405 | jsonFile["frus"][systemVpdBackupPath][0]["inventoryPath"] | 
|  | 406 | .get_ref<const nlohmann::json::string_t&>(); | 
|  | 407 |  | 
|  | 408 | const auto& itr = svpdKwdMap.find(recordName); | 
|  | 409 | if (itr != svpdKwdMap.end()) | 
|  | 410 | { | 
|  | 411 | auto systemKwdInfoList = itr->second; | 
| Patrick Williams | 08dc31c | 2024-08-16 15:21:06 -0400 | [diff] [blame^] | 412 | const auto& itrToKwd = | 
|  | 413 | find_if(systemKwdInfoList.begin(), systemKwdInfoList.end(), | 
|  | 414 | [&keyword](const auto& kwdInfo) { | 
|  | 415 | return (keyword == std::get<0>(kwdInfo)); | 
|  | 416 | }); | 
| Sunny Srivastava | 8377086 | 2023-10-31 12:57:20 -0500 | [diff] [blame] | 417 |  | 
|  | 418 | if (itrToKwd != systemKwdInfoList.end()) | 
|  | 419 | { | 
|  | 420 | EditorImpl edit(systemVpdBackupPath, jsonFile, | 
|  | 421 | std::get<4>(*itrToKwd), std::get<5>(*itrToKwd), | 
|  | 422 | systemVpdBackupInvPath); | 
|  | 423 |  | 
|  | 424 | // Setup offset, if any | 
|  | 425 | uint32_t offset = 0; | 
|  | 426 | if (jsonFile["frus"][systemVpdBackupPath].at(0).contains( | 
|  | 427 | "offset")) | 
|  | 428 | { | 
|  | 429 | offset = | 
|  | 430 | jsonFile["frus"][systemVpdBackupPath].at(0).contains( | 
|  | 431 | "offset"); | 
|  | 432 | } | 
|  | 433 |  | 
|  | 434 | edit.updateKeyword(value, offset, true); | 
|  | 435 | } | 
|  | 436 | } | 
|  | 437 | } | 
|  | 438 | else | 
|  | 439 | { | 
|  | 440 | if (systemVpdBackupPath.empty()) | 
|  | 441 | { | 
|  | 442 | throw std::runtime_error( | 
|  | 443 | "Invalid entry for systemVpdBackupPath in JSON"); | 
|  | 444 | } | 
|  | 445 | else | 
|  | 446 | { | 
|  | 447 | throw std::runtime_error( | 
|  | 448 | "Inventory path missing for systemVpdBackupPath"); | 
|  | 449 | } | 
|  | 450 | } | 
|  | 451 | } | 
|  | 452 |  | 
| Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 453 | void Manager::writeKeyword(const sdbusplus::message::object_path& path, | 
|  | 454 | const std::string& recordName, | 
|  | 455 | const std::string& keyword, const Binary& value) | 
| SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 456 | { | 
| SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 457 | try | 
|  | 458 | { | 
| Santosh Puranik | 8c79681 | 2021-12-01 19:17:56 +0530 | [diff] [blame] | 459 | std::string objPath{path}; | 
|  | 460 | // Strip any inventory prefix in path | 
|  | 461 | if (objPath.find(INVENTORY_PATH) == 0) | 
|  | 462 | { | 
|  | 463 | objPath = objPath.substr(sizeof(INVENTORY_PATH) - 1); | 
|  | 464 | } | 
|  | 465 |  | 
|  | 466 | if (frus.find(objPath) == frus.end()) | 
| SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 467 | { | 
|  | 468 | throw std::runtime_error("Inventory path not found"); | 
|  | 469 | } | 
|  | 470 |  | 
| Santosh Puranik | a0b2391 | 2022-02-10 13:37:09 +0530 | [diff] [blame] | 471 | inventory::Path vpdFilePath = std::get<0>(frus.find(objPath)->second); | 
| SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 472 |  | 
| SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 473 | // instantiate editor class to update the data | 
| Santosh Puranik | 8c79681 | 2021-12-01 19:17:56 +0530 | [diff] [blame] | 474 | EditorImpl edit(vpdFilePath, jsonFile, recordName, keyword, objPath); | 
| Santosh Puranik | a0b2391 | 2022-02-10 13:37:09 +0530 | [diff] [blame] | 475 |  | 
|  | 476 | uint32_t offset = 0; | 
|  | 477 | // Setup offset, if any | 
|  | 478 | for (const auto& item : jsonFile["frus"][vpdFilePath]) | 
|  | 479 | { | 
|  | 480 | if (item.find("offset") != item.end()) | 
|  | 481 | { | 
|  | 482 | offset = item["offset"]; | 
|  | 483 | break; | 
|  | 484 | } | 
|  | 485 | } | 
|  | 486 |  | 
|  | 487 | edit.updateKeyword(value, offset, true); | 
|  | 488 |  | 
| Sunny Srivastava | 8377086 | 2023-10-31 12:57:20 -0500 | [diff] [blame] | 489 | // If system VPD is being updated and system VPD is marked for back up | 
|  | 490 | // on another FRU, update data on back up as well. | 
|  | 491 | if (objPath == sdbusplus::message::object_path{SYSTEM_OBJECT} && | 
|  | 492 | jsonFile["frus"][systemVpdFilePath].at(0).contains( | 
|  | 493 | "systemVpdBackupPath")) | 
|  | 494 | { | 
|  | 495 | updateSystemVPDBackUpFRU(recordName, keyword, value); | 
|  | 496 | } | 
|  | 497 |  | 
| Santosh Puranik | a0b2391 | 2022-02-10 13:37:09 +0530 | [diff] [blame] | 498 | // If we have a redundant EEPROM to update, then update just the EEPROM, | 
|  | 499 | // not the cache since that is already done when we updated the primary | 
|  | 500 | if (!std::get<1>(frus.find(objPath)->second).empty()) | 
|  | 501 | { | 
|  | 502 | EditorImpl edit(std::get<1>(frus.find(objPath)->second), jsonFile, | 
| Sunny Srivastava | f31a91b | 2022-06-09 08:11:29 -0500 | [diff] [blame] | 503 | recordName, keyword, objPath); | 
| Santosh Puranik | a0b2391 | 2022-02-10 13:37:09 +0530 | [diff] [blame] | 504 | edit.updateKeyword(value, offset, false); | 
|  | 505 | } | 
| SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 506 |  | 
| SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 507 | // if it is a motehrboard FRU need to check for location expansion | 
| Santosh Puranik | a0b2391 | 2022-02-10 13:37:09 +0530 | [diff] [blame] | 508 | if (std::get<2>(frus.find(objPath)->second)) | 
| SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 509 | { | 
|  | 510 | if (recordName == "VCEN" && (keyword == "FC" || keyword == "SE")) | 
|  | 511 | { | 
|  | 512 | edit.expandLocationCode("fcs"); | 
|  | 513 | } | 
|  | 514 | else if (recordName == "VSYS" && | 
|  | 515 | (keyword == "TM" || keyword == "SE")) | 
|  | 516 | { | 
|  | 517 | edit.expandLocationCode("mts"); | 
|  | 518 | } | 
|  | 519 | } | 
|  | 520 |  | 
| SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 521 | return; | 
| SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 522 | } | 
|  | 523 | catch (const std::exception& e) | 
|  | 524 | { | 
|  | 525 | std::cerr << e.what() << std::endl; | 
|  | 526 | } | 
| SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 527 | } | 
|  | 528 |  | 
| Patrick Williams | 08dc31c | 2024-08-16 15:21:06 -0400 | [diff] [blame^] | 529 | ListOfPaths Manager::getFRUsByUnexpandedLocationCode( | 
|  | 530 | const LocationCode& locationCode, const NodeNumber nodeNumber) | 
| SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 531 | { | 
| SunnySrivastava1984 | 1356d7e | 2020-04-24 04:29:35 -0500 | [diff] [blame] | 532 | ReaderImpl read; | 
|  | 533 | return read.getFrusAtLocation(locationCode, nodeNumber, fruLocationCode); | 
| SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 534 | } | 
|  | 535 |  | 
| SunnySrivastava1984 | 1356d7e | 2020-04-24 04:29:35 -0500 | [diff] [blame] | 536 | ListOfPaths | 
| Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 537 | Manager::getFRUsByExpandedLocationCode(const LocationCode& locationCode) | 
| SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 538 | { | 
| SunnySrivastava1984 | fb5815a | 2020-04-24 08:03:52 -0500 | [diff] [blame] | 539 | ReaderImpl read; | 
|  | 540 | return read.getFRUsByExpandedLocationCode(locationCode, fruLocationCode); | 
| SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 541 | } | 
|  | 542 |  | 
| Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 543 | LocationCode Manager::getExpandedLocationCode(const LocationCode& locationCode, | 
| SunnySrivastava1984 | fb5815a | 2020-04-24 08:03:52 -0500 | [diff] [blame] | 544 | const NodeNumber nodeNumber) | 
| SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 545 | { | 
| SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame] | 546 | ReaderImpl read; | 
|  | 547 | return read.getExpandedLocationCode(locationCode, nodeNumber, | 
|  | 548 | fruLocationCode); | 
| SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 549 | } | 
| SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 550 |  | 
| SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 551 | void Manager::performVPDRecollection() | 
|  | 552 | { | 
|  | 553 | // get list of FRUs replaceable at standby | 
|  | 554 | for (const auto& item : replaceableFrus) | 
|  | 555 | { | 
|  | 556 | const vector<nlohmann::json>& groupEEPROM = jsonFile["frus"][item]; | 
|  | 557 | const nlohmann::json& singleFru = groupEEPROM[0]; | 
|  | 558 |  | 
|  | 559 | const string& inventoryPath = | 
|  | 560 | singleFru["inventoryPath"] | 
|  | 561 | .get_ref<const nlohmann::json::string_t&>(); | 
|  | 562 |  | 
| Santosh Puranik | d40e42d | 2022-03-23 13:58:06 +0530 | [diff] [blame] | 563 | bool prePostActionRequired = false; | 
|  | 564 |  | 
|  | 565 | if ((jsonFile["frus"][item].at(0)).find("preAction") != | 
|  | 566 | jsonFile["frus"][item].at(0).end()) | 
|  | 567 | { | 
| Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 568 | try | 
| Santosh Puranik | d40e42d | 2022-03-23 13:58:06 +0530 | [diff] [blame] | 569 | { | 
| Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 570 | if (!executePreAction(jsonFile, item)) | 
|  | 571 | { | 
|  | 572 | // if the FRU has preAction defined then its execution | 
|  | 573 | // should pass to ensure bind/unbind of data. | 
|  | 574 | // preAction execution failed. should not call | 
|  | 575 | // bind/unbind. | 
|  | 576 | log<level::ERR>( | 
|  | 577 | "Pre-Action execution failed for the FRU", | 
|  | 578 | entry("ERROR=%s", | 
|  | 579 | ("Inventory path: " + inventoryPath).c_str())); | 
|  | 580 | continue; | 
|  | 581 | } | 
|  | 582 | } | 
|  | 583 | catch (const GpioException& e) | 
|  | 584 | { | 
|  | 585 | log<level::ERR>(e.what()); | 
|  | 586 | PelAdditionalData additionalData{}; | 
|  | 587 | additionalData.emplace("DESCRIPTION", e.what()); | 
|  | 588 | createPEL(additionalData, PelSeverity::WARNING, | 
|  | 589 | errIntfForGpioError, sdBus); | 
| Santosh Puranik | d40e42d | 2022-03-23 13:58:06 +0530 | [diff] [blame] | 590 | continue; | 
|  | 591 | } | 
|  | 592 | prePostActionRequired = true; | 
|  | 593 | } | 
|  | 594 |  | 
| Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 595 | // unbind, bind the driver to trigger parser. | 
|  | 596 | triggerVpdCollection(singleFru, inventoryPath); | 
| Santosh Puranik | d40e42d | 2022-03-23 13:58:06 +0530 | [diff] [blame] | 597 |  | 
|  | 598 | // this check is added to avoid file system expensive call in case not | 
|  | 599 | // required. | 
|  | 600 | if (prePostActionRequired) | 
|  | 601 | { | 
| Manojkiran Eda | af92175 | 2024-06-17 15:10:21 +0530 | [diff] [blame] | 602 | // The sleep of 1sec is sliced up in 10 retries of 10 milliseconds | 
| Sunny Srivastava | 4788e1b | 2024-03-19 02:11:07 -0500 | [diff] [blame] | 603 | // each. | 
|  | 604 | for (auto retryCounter = VALUE_0; retryCounter <= VALUE_10; | 
|  | 605 | retryCounter++) | 
| Santosh Puranik | d40e42d | 2022-03-23 13:58:06 +0530 | [diff] [blame] | 606 | { | 
| Manojkiran Eda | af92175 | 2024-06-17 15:10:21 +0530 | [diff] [blame] | 607 | // sleep for 10 millisecond | 
| Sunny Srivastava | 4788e1b | 2024-03-19 02:11:07 -0500 | [diff] [blame] | 608 | if (usleep(VALUE_100000) != VALUE_0) | 
| Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 609 | { | 
| Sunny Srivastava | 4788e1b | 2024-03-19 02:11:07 -0500 | [diff] [blame] | 610 | std::cout << "Sleep failed before accessing the file" | 
|  | 611 | << std::endl; | 
| Sunny Srivastava | a2ddc96 | 2022-06-29 08:53:16 -0500 | [diff] [blame] | 612 | } | 
| Alpana Kumari | 41d498c | 2021-09-16 00:29:12 -0500 | [diff] [blame] | 613 |  | 
| Sunny Srivastava | 4788e1b | 2024-03-19 02:11:07 -0500 | [diff] [blame] | 614 | // Check if file showed up | 
|  | 615 | if (!filesystem::exists(item)) | 
|  | 616 | { | 
|  | 617 | // Do we need to retry? | 
|  | 618 | if (retryCounter < VALUE_10) | 
|  | 619 | { | 
|  | 620 | continue; | 
|  | 621 | } | 
|  | 622 |  | 
|  | 623 | try | 
|  | 624 | { | 
|  | 625 | // If not, then take failure postAction | 
|  | 626 | executePostFailAction(jsonFile, item); | 
|  | 627 | } | 
|  | 628 | catch (const GpioException& e) | 
|  | 629 | { | 
|  | 630 | PelAdditionalData additionalData{}; | 
|  | 631 | additionalData.emplace("DESCRIPTION", e.what()); | 
|  | 632 | createPEL(additionalData, PelSeverity::WARNING, | 
|  | 633 | errIntfForGpioError, sdBus); | 
|  | 634 | } | 
|  | 635 | } | 
|  | 636 | else | 
|  | 637 | { | 
|  | 638 | // bind the LED driver | 
|  | 639 | string chipAddr = singleFru.value("pcaChipAddress", ""); | 
|  | 640 | cout | 
|  | 641 | << "performVPDRecollection: Executing driver binding for " | 
|  | 642 | "chip " | 
|  | 643 | "address - " | 
|  | 644 | << chipAddr << endl; | 
|  | 645 |  | 
|  | 646 | executeCmd(createBindUnbindDriverCmnd( | 
|  | 647 | chipAddr, "i2c", "leds-pca955x", "/bind")); | 
|  | 648 |  | 
|  | 649 | // File has been found, kill the retry loop. | 
|  | 650 | break; | 
|  | 651 | } | 
| Alpana Kumari | 41d498c | 2021-09-16 00:29:12 -0500 | [diff] [blame] | 652 | } | 
| Santosh Puranik | d40e42d | 2022-03-23 13:58:06 +0530 | [diff] [blame] | 653 | } | 
| SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 654 | } | 
|  | 655 | } | 
|  | 656 |  | 
| Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 657 | void Manager::collectFRUVPD(const sdbusplus::message::object_path& path) | 
|  | 658 | { | 
| Sunny Srivastava | 5ef6ccc | 2022-05-30 01:35:13 -0500 | [diff] [blame] | 659 | std::cout << "Manager called to collect vpd for fru: " << std::string{path} | 
|  | 660 | << std::endl; | 
|  | 661 |  | 
| Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 662 | using InvalidArgument = | 
|  | 663 | sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument; | 
|  | 664 | using Argument = xyz::openbmc_project::Common::InvalidArgument; | 
|  | 665 |  | 
| Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 666 | std::string objPath{path}; | 
|  | 667 |  | 
|  | 668 | // Strip any inventory prefix in path | 
|  | 669 | if (objPath.find(INVENTORY_PATH) == 0) | 
| Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 670 | { | 
| Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 671 | objPath = objPath.substr(sizeof(INVENTORY_PATH) - 1); | 
| Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 672 | } | 
|  | 673 |  | 
| Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 674 | // if path not found in Json. | 
|  | 675 | if (frus.find(objPath) == frus.end()) | 
|  | 676 | { | 
|  | 677 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("Object Path"), | 
|  | 678 | Argument::ARGUMENT_VALUE(objPath.c_str())); | 
|  | 679 | } | 
|  | 680 |  | 
|  | 681 | inventory::Path vpdFilePath = std::get<0>(frus.find(objPath)->second); | 
| Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 682 |  | 
|  | 683 | const std::vector<nlohmann::json>& groupEEPROM = | 
|  | 684 | jsonFile["frus"][vpdFilePath].get_ref<const nlohmann::json::array_t&>(); | 
|  | 685 |  | 
| Sunny Srivastava | ab2304d | 2023-01-10 23:30:05 -0600 | [diff] [blame] | 686 | nlohmann::json singleFru{}; | 
|  | 687 | for (const auto& item : groupEEPROM) | 
|  | 688 | { | 
|  | 689 | if (item["inventoryPath"] == objPath) | 
|  | 690 | { | 
|  | 691 | // this is the inventory we are looking for | 
|  | 692 | singleFru = item; | 
|  | 693 | break; | 
|  | 694 | } | 
|  | 695 | } | 
| Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 696 |  | 
|  | 697 | // check if the device qualifies for CM. | 
|  | 698 | if (singleFru.value("concurrentlyMaintainable", false)) | 
|  | 699 | { | 
|  | 700 | bool prePostActionRequired = false; | 
|  | 701 |  | 
|  | 702 | if ((jsonFile["frus"][vpdFilePath].at(0)).find("preAction") != | 
|  | 703 | jsonFile["frus"][vpdFilePath].at(0).end()) | 
|  | 704 | { | 
|  | 705 | if (!executePreAction(jsonFile, vpdFilePath)) | 
|  | 706 | { | 
|  | 707 | // if the FRU has preAction defined then its execution should | 
|  | 708 | // pass to ensure bind/unbind of data. | 
|  | 709 | // preAction execution failed. should not call bind/unbind. | 
|  | 710 | log<level::ERR>("Pre-Action execution failed for the FRU"); | 
|  | 711 | return; | 
|  | 712 | } | 
|  | 713 |  | 
|  | 714 | prePostActionRequired = true; | 
|  | 715 | } | 
|  | 716 |  | 
|  | 717 | // unbind, bind the driver to trigger parser. | 
| Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 718 | triggerVpdCollection(singleFru, objPath); | 
| Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 719 |  | 
|  | 720 | // this check is added to avoid file system expensive call in case not | 
|  | 721 | // required. | 
|  | 722 | if (prePostActionRequired) | 
|  | 723 | { | 
|  | 724 | // Check if device showed up (test for file) | 
|  | 725 | if (!filesystem::exists(vpdFilePath)) | 
|  | 726 | { | 
| Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 727 | try | 
|  | 728 | { | 
|  | 729 | // If not, then take failure postAction | 
|  | 730 | executePostFailAction(jsonFile, vpdFilePath); | 
|  | 731 | } | 
|  | 732 | catch (const GpioException& e) | 
|  | 733 | { | 
|  | 734 | PelAdditionalData additionalData{}; | 
|  | 735 | additionalData.emplace("DESCRIPTION", e.what()); | 
|  | 736 | createPEL(additionalData, PelSeverity::WARNING, | 
|  | 737 | errIntfForGpioError, sdBus); | 
|  | 738 | } | 
| Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 739 | } | 
| Alpana Kumari | 41d498c | 2021-09-16 00:29:12 -0500 | [diff] [blame] | 740 | else | 
|  | 741 | { | 
|  | 742 | // bind the LED driver | 
|  | 743 | string chipAddr = jsonFile["frus"][vpdFilePath].at(0).value( | 
|  | 744 | "pcaChipAddress", ""); | 
|  | 745 | cout << "Executing driver binding for chip address - " | 
|  | 746 | << chipAddr << endl; | 
|  | 747 |  | 
|  | 748 | executeCmd(createBindUnbindDriverCmnd(chipAddr, "i2c", | 
|  | 749 | "leds-pca955x", "/bind")); | 
|  | 750 | } | 
| Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 751 | } | 
|  | 752 | return; | 
|  | 753 | } | 
|  | 754 | else | 
|  | 755 | { | 
| Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 756 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("Object Path"), | 
|  | 757 | Argument::ARGUMENT_VALUE(objPath.c_str())); | 
| Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 758 | } | 
|  | 759 | } | 
|  | 760 |  | 
|  | 761 | void Manager::triggerVpdCollection(const nlohmann::json& singleFru, | 
|  | 762 | const std::string& path) | 
|  | 763 | { | 
|  | 764 | if ((singleFru.find("devAddress") == singleFru.end()) || | 
|  | 765 | (singleFru.find("driverType") == singleFru.end()) || | 
|  | 766 | (singleFru.find("busType") == singleFru.end())) | 
|  | 767 | { | 
|  | 768 | // The FRUs is marked for collection but missing mandatory | 
|  | 769 | // fields for collection. Log error and return. | 
|  | 770 | log<level::ERR>( | 
|  | 771 | "Collection Failed as mandatory field missing in Json", | 
|  | 772 | entry("ERROR=%s", ("Recollection failed for " + (path)).c_str())); | 
|  | 773 |  | 
|  | 774 | return; | 
|  | 775 | } | 
|  | 776 |  | 
|  | 777 | string deviceAddress = singleFru["devAddress"]; | 
|  | 778 | const string& driverType = singleFru["driverType"]; | 
|  | 779 | const string& busType = singleFru["busType"]; | 
|  | 780 |  | 
|  | 781 | // devTreeStatus flag is present in json as false to mention | 
|  | 782 | // that the EEPROM is not mentioned in device tree. If this flag | 
|  | 783 | // is absent consider the value to be true, i.e EEPROM is | 
|  | 784 | // mentioned in device tree | 
|  | 785 | if (!singleFru.value("devTreeStatus", true)) | 
|  | 786 | { | 
|  | 787 | auto pos = deviceAddress.find('-'); | 
|  | 788 | if (pos != string::npos) | 
|  | 789 | { | 
|  | 790 | string busNum = deviceAddress.substr(0, pos); | 
|  | 791 | deviceAddress = "0x" + deviceAddress.substr(pos + 1, string::npos); | 
|  | 792 |  | 
| Patrick Williams | 08dc31c | 2024-08-16 15:21:06 -0400 | [diff] [blame^] | 793 | string deleteDevice = | 
|  | 794 | "echo" + deviceAddress + " > /sys/bus/" + busType + | 
|  | 795 | "/devices/" + busType + "-" + busNum + "/delete_device"; | 
| Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 796 | executeCmd(deleteDevice); | 
|  | 797 |  | 
| Patrick Williams | 08dc31c | 2024-08-16 15:21:06 -0400 | [diff] [blame^] | 798 | string addDevice = | 
|  | 799 | "echo" + driverType + " " + deviceAddress + " > /sys/bus/" + | 
|  | 800 | busType + "/devices/" + busType + "-" + busNum + "/new_device"; | 
| Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 801 | executeCmd(addDevice); | 
|  | 802 | } | 
|  | 803 | else | 
|  | 804 | { | 
|  | 805 | const string& inventoryPath = | 
|  | 806 | singleFru["inventoryPath"] | 
|  | 807 | .get_ref<const nlohmann::json::string_t&>(); | 
|  | 808 |  | 
|  | 809 | log<level::ERR>( | 
|  | 810 | "Wrong format of device address in Json", | 
|  | 811 | entry("ERROR=%s", | 
|  | 812 | ("Recollection failed for " + inventoryPath).c_str())); | 
|  | 813 | } | 
|  | 814 | } | 
|  | 815 | else | 
|  | 816 | { | 
|  | 817 | executeCmd(createBindUnbindDriverCmnd(deviceAddress, busType, | 
|  | 818 | driverType, "/unbind")); | 
|  | 819 | executeCmd(createBindUnbindDriverCmnd(deviceAddress, busType, | 
|  | 820 | driverType, "/bind")); | 
|  | 821 | } | 
|  | 822 | } | 
|  | 823 |  | 
| Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 824 | void Manager::deleteFRUVPD(const sdbusplus::message::object_path& path) | 
|  | 825 | { | 
| Sunny Srivastava | 5ef6ccc | 2022-05-30 01:35:13 -0500 | [diff] [blame] | 826 | std::cout << "Manager called to delete vpd for fru: " << std::string{path} | 
|  | 827 | << std::endl; | 
|  | 828 |  | 
| Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 829 | using InvalidArgument = | 
|  | 830 | sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument; | 
|  | 831 | using Argument = xyz::openbmc_project::Common::InvalidArgument; | 
|  | 832 |  | 
| Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 833 | std::string objPath{path}; | 
|  | 834 |  | 
|  | 835 | // Strip any inventory prefix in path | 
|  | 836 | if (objPath.find(INVENTORY_PATH) == 0) | 
| Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 837 | { | 
| Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 838 | objPath = objPath.substr(sizeof(INVENTORY_PATH) - 1); | 
| Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 839 | } | 
|  | 840 |  | 
| Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 841 | // if path not found in Json. | 
|  | 842 | if (frus.find(objPath) == frus.end()) | 
|  | 843 | { | 
|  | 844 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("Object Path"), | 
|  | 845 | Argument::ARGUMENT_VALUE(objPath.c_str())); | 
|  | 846 | } | 
|  | 847 |  | 
|  | 848 | inventory::Path& vpdFilePath = std::get<0>(frus.find(objPath)->second); | 
| Alpana Kumari | 41d498c | 2021-09-16 00:29:12 -0500 | [diff] [blame] | 849 |  | 
|  | 850 | string chipAddress = | 
|  | 851 | jsonFile["frus"][vpdFilePath].at(0).value("pcaChipAddress", ""); | 
|  | 852 |  | 
| Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 853 | // if the FRU is not present then log error | 
| Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 854 | if (readBusProperty(objPath, "xyz.openbmc_project.Inventory.Item", | 
| Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 855 | "Present") == "false") | 
|  | 856 | { | 
| Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 857 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("FRU not preset"), | 
|  | 858 | Argument::ARGUMENT_VALUE(objPath.c_str())); | 
| Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 859 | } | 
|  | 860 | else | 
|  | 861 | { | 
| Sunny Srivastava | 893bf5d | 2024-06-14 02:03:39 -0500 | [diff] [blame] | 862 | // check if we have cxp-port populated for the given object path. | 
|  | 863 | std::vector<std::string> interfaceList{ | 
|  | 864 | "xyz.openbmc_project.State.Decorator.OperationalStatus"}; | 
| Patrick Williams | 08dc31c | 2024-08-16 15:21:06 -0400 | [diff] [blame^] | 865 | MapperResponse subTree = | 
|  | 866 | getObjectSubtreeForInterfaces(path, 0, interfaceList); | 
| Sunny Srivastava | 893bf5d | 2024-06-14 02:03:39 -0500 | [diff] [blame] | 867 |  | 
|  | 868 | if (subTree.size() != 0) | 
|  | 869 | { | 
|  | 870 | for (auto [objectPath, serviceInterfaceMap] : subTree) | 
|  | 871 | { | 
|  | 872 | std::string subTreeObjPath{objectPath}; | 
|  | 873 | if (subTreeObjPath.find("cxp_top") != std::string::npos || | 
|  | 874 | subTreeObjPath.find("cxp_bot") != std::string::npos) | 
|  | 875 | { | 
|  | 876 | // Strip any inventory prefix in path | 
|  | 877 | if (subTreeObjPath.find(INVENTORY_PATH) == 0) | 
|  | 878 | { | 
|  | 879 | subTreeObjPath = | 
|  | 880 | subTreeObjPath.substr(sizeof(INVENTORY_PATH) - 1); | 
|  | 881 | } | 
|  | 882 |  | 
|  | 883 | inventory::ObjectMap objectMap{ | 
|  | 884 | {subTreeObjPath, | 
|  | 885 | {{"xyz.openbmc_project.State.Decorator.OperationalStatus", | 
|  | 886 | {{"Functional", true}}}}}}; | 
|  | 887 |  | 
|  | 888 | // objectMap.emplace(objectPath, move(interfaceMap)); | 
|  | 889 | common::utility::callPIM(move(objectMap)); | 
|  | 890 | } | 
|  | 891 | } | 
|  | 892 | } | 
|  | 893 |  | 
|  | 894 | // Unbind the LED driver for this FRU | 
|  | 895 | cout << "Unbinding device- " << chipAddress << endl; | 
|  | 896 | executeCmd(createBindUnbindDriverCmnd(chipAddress, "i2c", | 
|  | 897 | "leds-pca955x", "/unbind")); | 
|  | 898 |  | 
| Sunny Srivastava | c6e7ea9 | 2023-11-03 21:10:43 +0530 | [diff] [blame] | 899 | inventory::InterfaceMap interfacesPropMap; | 
|  | 900 | clearVpdOnRemoval(INVENTORY_PATH + objPath, interfacesPropMap); | 
| Santosh Puranik | bc59947 | 2022-12-19 20:17:10 +0530 | [diff] [blame] | 901 |  | 
|  | 902 | inventory::ObjectMap objectMap; | 
| Sunny Srivastava | c6e7ea9 | 2023-11-03 21:10:43 +0530 | [diff] [blame] | 903 | objectMap.emplace(objPath, move(interfacesPropMap)); | 
| Sunny Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 904 |  | 
|  | 905 | common::utility::callPIM(move(objectMap)); | 
|  | 906 | } | 
|  | 907 | } | 
|  | 908 |  | 
| SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 909 | } // namespace manager | 
|  | 910 | } // namespace vpd | 
| Patrick Williams | c78d887 | 2023-05-10 07:50:56 -0500 | [diff] [blame] | 911 | } // namespace openpower |