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