/** * Copyright © 2022 IBM Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "extensions/phal/clock_logger.hpp" #include "util.hpp" #include #include #include #include #include #include using namespace openpower::pel; PHOSPHOR_LOG2_USING; namespace openpower::phal::clock { constexpr auto CLOCK_DAILY_LOGGER_TIMEOUT_IN_HOUR = 24; Manager::Manager(const sdeventplus::Event& event) : _event(event), timer(event, std::bind(&Manager::timerExpired, this)) { try { // pdbg initialisation openpower::phal::pdbg::init(); // Create clock data log. createClockDataLog(); } catch (const std::exception& e) { error("Clock Data Log exception ({ERROR})", "ERROR", e); } addTimer(); } void Manager::addTimer() { // Set timer for 24 hours. timer.restart(std::chrono::hours(CLOCK_DAILY_LOGGER_TIMEOUT_IN_HOUR)); } void Manager::timerExpired() { info("Clock daily logging started"); try { // Create clock data log. createClockDataLog(); } catch (const std::exception& e) { error("createClockDataLog exception ({ERROR})", "ERROR", e); } } void Manager::createClockDataLog() { // check chassis power state. auto powerState = openpower::util::getChassisPowerState(); if (powerState != "xyz.openbmc_project.State.Chassis.PowerState.On") { warning("The chassis power state({POWERSTATE}) is not ON, Skipping " "clock data " "logging", "POWERSTATE", powerState); return; } // Data logger storage FFDCData clockDataLog; struct pdbg_target* procTarget; ATTR_HWAS_STATE_Type hwasState; pdbg_for_each_class_target("proc", procTarget) { if (DT_GET_PROP(ATTR_HWAS_STATE, procTarget, hwasState)) { error("{TARGET} Could not read HWAS_STATE attribute", "TARGET", pdbg_target_path(procTarget)); continue; } if (!hwasState.present) { continue; } auto index = std::to_string(pdbg_target_index(procTarget)); // update functional State std::string funState = "Non Functional"; if (hwasState.functional) { funState = "Functional"; } std::stringstream ssState; ssState << "Proc" << index; clockDataLog.push_back(std::make_pair(ssState.str(), funState)); // update location code information ATTR_LOCATION_CODE_Type locationCode; memset(&locationCode, '\0', sizeof(locationCode)); try { openpower::phal::pdbg::getLocationCode(procTarget, locationCode); } catch (const std::exception& e) { error("getLocationCode on {TARGET} thrown exception ({ERROR})", "TARGET", pdbg_target_path(procTarget), "ERROR", e); } std::stringstream ssLoc; ssLoc << "Proc" << index << " Location Code"; clockDataLog.push_back(std::make_pair(ssLoc.str(), locationCode)); // Update Processor EC level ATTR_EC_Type ecVal = 0; if (DT_GET_PROP(ATTR_EC, procTarget, ecVal)) { error("Could not read ATTR_EC attribute"); } std::stringstream ssEC; ssEC << "Proc" << index << " EC"; std::stringstream ssECVal; ssECVal << "0x" << std::setfill('0') << std::setw(10) << std::hex << (uint16_t)ecVal; clockDataLog.push_back(std::make_pair(ssEC.str(), ssECVal.str())); // Add CFAM register information. addCFAMData(procTarget, clockDataLog); } openpower::pel::createPEL("org.open_power.PHAL.Info.ClockDailyLog", clockDataLog); } void Manager::addCFAMData(struct pdbg_target* proc, openpower::pel::FFDCData& clockDataLog) { // collect Processor CFAM register data const std::vector procCFAMAddr = { 0x1007, 0x2804, 0x2810, 0x2813, 0x2814, 0x2815, 0x2816, 0x281D, 0x281E}; auto index = std::to_string(pdbg_target_index(proc)); for (int addr : procCFAMAddr) { auto val = 0xDEADBEEF; try { val = openpower::phal::pdbg::getCFAM(proc, addr); } catch (const std::exception& e) { error("getCFAM on {TARGET} thrown exception({ERROR}): Addr ({REG})", "TARGET", pdbg_target_path(proc), "ERROR", e, "REG", addr); } std::stringstream ssData; ssData << "0x" << std::setfill('0') << std::setw(8) << std::hex << val; std::stringstream ssAddr; ssAddr << "Proc" << index << " REG 0x" << std::hex << addr; // update the data clockDataLog.push_back(make_pair(ssAddr.str(), ssData.str())); } } } // namespace openpower::phal::clock