| #pragma once |
| |
| #include "occ_errors.hpp" |
| #include "utils.hpp" |
| |
| #include <org/open_power/OCC/PassThrough/server.hpp> |
| #include <sdbusplus/bus.hpp> |
| #include <sdbusplus/server/object.hpp> |
| |
| #include <format> |
| #include <string> |
| #include <utility> |
| |
| namespace open_power |
| { |
| namespace occ |
| { |
| |
| // For waiting on signals |
| namespace sdbusRule = sdbusplus::bus::match::rules; |
| |
| enum class CmdType |
| { |
| POLL = 0x00, |
| CLEAR_ERROR_LOG = 0x12, |
| SET_MODE_AND_STATE = 0x20, |
| SET_CONFIG_DATA = 0x21, |
| SET_USER_PCAP = 0x22, |
| RESET_PREP = 0x25, |
| SEND_AMBIENT = 0x30, |
| DEBUG_PASS_THROUGH = 0x40, |
| AME_PASS_THROUGH = 0x41, |
| GET_FIELD_DEBUG_DATA = 0x42, |
| MFG_TEST = 0x53 |
| }; |
| |
| enum class OccState |
| { |
| NO_CHANGE = 0x00, |
| STANDBY = 0x01, |
| OBSERVATION = 0x02, |
| ACTIVE = 0x03, |
| SAFE = 0x04, |
| CHARACTERIZATION = 0x05 |
| }; |
| |
| enum class SysPwrMode |
| { |
| NO_CHANGE = 0, |
| STATIC = 0x01, // Static Base Frequencey |
| NON_DETERMINISTIC = 0x02, // Non-Deterministic |
| SFP = 0x03, // Static Frequency Point (requires freqPt) |
| SAFE = 0x04, // reported when system is in SAFE mode (not settable) |
| POWER_SAVING = 0x05, // Static Power Saving |
| EFF_FAVOR_POWER = 0x06, // Efficiency - Favor Power |
| EFF_FAVOR_PERF = 0x07, // Efficiency - Favor Performance |
| MAX_FREQ = 0x09, // Maximum Frequency (per chip) |
| BALANCED_PERF = 0x0A, // Balanced Performance |
| FFO = 0x0B, // Fixed Frequency Override (requires freqPt) |
| MAX_PERF = 0x0C // Maximum Performance |
| }; |
| |
| enum class RspStatus |
| { |
| SUCCESS = 0x00, |
| CONDITIONAL_SUCCESS = 0x01, |
| INVALID_COMMAND = 0x11, |
| INVALID_COMMAND_LENGTH = 0x12, |
| INVALID_DATA_FIELD = 0x13, |
| CHECKSUM_FAILURE = 0x14, |
| INTERNAL_ERROR = 0x15, |
| PRESENT_STATE_PROHIBITS = 0x16, |
| COMMAND_IN_PROGRESS = 0xFF |
| }; |
| |
| enum class CmdStatus |
| { |
| SUCCESS = 0x00, |
| FAILURE = 0x02, |
| COMM_FAILURE = 0x03 |
| }; |
| |
| /** @brief Trace block of data in hex with log<level:INFO> |
| * |
| * @param[in] data - vector containing data to trace |
| * @param[in] data_len - optional number of bytes to trace |
| * If 0, entire vector will be traced. |
| */ |
| void dump_hex(const std::vector<std::uint8_t>& data, |
| const unsigned int data_len = 0); |
| |
| /** @class OccCommand |
| * @brief Send commands and process respsonses from the OCC |
| */ |
| class OccCommand |
| { |
| public: |
| OccCommand() = delete; |
| OccCommand(const OccCommand&) = delete; |
| OccCommand& operator=(const OccCommand&) = delete; |
| OccCommand(OccCommand&&) = default; |
| OccCommand& operator=(OccCommand&&) = default; |
| |
| /** @brief Ctor to set up which OCC the command will go to |
| * |
| * @param[in] instance - OCC instance |
| * @param[in] path - Path to attach at |
| */ |
| OccCommand(uint8_t instance, const char* path); |
| |
| /** @brief Dtor to clean up and close device */ |
| ~OccCommand() |
| { |
| closeDevice(); |
| } |
| |
| /** @brief Send the command to the OCC and collect the response. |
| * The checksum will be validated and removed from the response. |
| * |
| * @param[in] command - command to pass-through |
| * @param[out] response - response |
| * returns SUCCESS if response was received |
| */ |
| CmdStatus send(const std::vector<std::uint8_t>& command, |
| std::vector<std::uint8_t>& response); |
| |
| private: |
| /** @brief Instance number of the target OCC */ |
| uint8_t occInstance; |
| |
| /** @brief OCC path on the bus */ |
| std::string path; |
| |
| /** @brief OCC device path |
| * For now, here is the hard-coded mapping until |
| * the udev rule is in. |
| * occ0 --> /dev/occ1 |
| * occ1 --> /dev/occ2 |
| * ... |
| */ |
| std::string devicePath; |
| |
| /** @brief Indicates whether or not the OCC is currently active */ |
| bool occActive = false; |
| |
| /** brief file descriptor associated with occ device */ |
| int fd = -1; |
| |
| /** @brief Subscribe to OCC Status signal |
| * |
| * Once the OCC status gets to active, only then we will get /dev/occ2 |
| * populated and hence need to wait on that before opening that |
| */ |
| sdbusplus::bus::match_t activeStatusSignal; |
| |
| /** Opens devicePath and populates file descriptor */ |
| void openDevice(); |
| |
| /** Closed the fd associated with opened device */ |
| void closeDevice(); |
| |
| /** @brief Callback function on OCC Status change signals |
| * |
| * @param[in] msg - Data associated with subscribed signal |
| */ |
| void activeStatusEvent(sdbusplus::message_t& msg); |
| }; |
| |
| } // namespace occ |
| } // namespace open_power |
| |
| template <> |
| struct std::formatter<open_power::occ::SysPwrMode> : formatter<int> |
| { |
| auto format(open_power::occ::SysPwrMode f, format_context& ctx) const |
| { |
| return formatter<int>::format(std::to_underlying(f), ctx); |
| } |
| }; |
| |
| template <> |
| struct std::formatter<open_power::occ::CmdStatus> : formatter<int> |
| { |
| auto format(open_power::occ::CmdStatus f, format_context& ctx) const |
| { |
| return formatter<int>::format(std::to_underlying(f), ctx); |
| } |
| }; |