1 #pragma once 2 3 #include "occ_errors.hpp" 4 #include "utils.hpp" 5 6 #include <org/open_power/OCC/PassThrough/server.hpp> 7 #include <sdbusplus/bus.hpp> 8 #include <sdbusplus/server/object.hpp> 9 10 #include <string> 11 12 namespace open_power 13 { 14 namespace occ 15 { 16 17 // For waiting on signals 18 namespace sdbusRule = sdbusplus::bus::match::rules; 19 20 enum class CmdType 21 { 22 POLL = 0x00, 23 CLEAR_ERROR_LOG = 0x12, 24 SET_MODE_AND_STATE = 0x20, 25 SET_CONFIG_DATA = 0x21, 26 SET_USER_PCAP = 0x22, 27 RESET_PREP = 0x25, 28 SEND_AMBIENT = 0x30, 29 DEBUG_PASS_THROUGH = 0x40, 30 AME_PASS_THROUGH = 0x41, 31 GET_FIELD_DEBUG_DATA = 0x42, 32 MFG_TEST = 0x53 33 }; 34 35 enum class OccState 36 { 37 NO_CHANGE = 0x00, 38 STANDBY = 0x01, 39 OBSERVATION = 0x02, 40 ACTIVE = 0x03, 41 SAFE = 0x04, 42 CHARACTERIZATION = 0x05 43 }; 44 45 enum class SysPwrMode 46 { 47 NO_CHANGE = 0, 48 STATIC = 0x01, // Static Base Frequencey 49 SFP = 0x03, // Static Frequency Point (requires freqPt) 50 SAFE = 0x04, // reported when system is in SAFE mode (not settable) 51 POWER_SAVING = 0x05, // Static Power Saving 52 MAX_FREQ = 0x09, // Maximum Frequency (per chip) 53 DYNAMIC_PERF = 0x0A, // Dynamic / Balanced Performance 54 FFO = 0x0B, // Fixed Frequency Override (requires freqPt) 55 MAX_PERF = 0x0C // Maximum Performance 56 }; 57 58 // Only some of the SysPwrModes are currently supported and allowed to be set 59 #define VALID_POWER_MODE_SETTING(mode) \ 60 ((mode == SysPwrMode::STATIC) || (mode == SysPwrMode::POWER_SAVING) || \ 61 (mode == SysPwrMode::DYNAMIC_PERF) || (mode == SysPwrMode::MAX_PERF)) 62 #define VALID_OEM_POWER_MODE_SETTING(mode) \ 63 ((mode == SysPwrMode::SFP) || (mode == SysPwrMode::FFO) || \ 64 (mode == SysPwrMode::MAX_FREQ)) 65 66 enum class RspStatus 67 { 68 SUCCESS = 0x00, 69 CONDITIONAL_SUCCESS = 0x01, 70 INVALID_COMMAND = 0x11, 71 INVALID_COMMAND_LENGTH = 0x12, 72 INVALID_DATA_FIELD = 0x13, 73 CHECKSUM_FAILURE = 0x14, 74 INTERNAL_ERROR = 0x15, 75 PRESENT_STATE_PROHIBITS = 0x16, 76 COMMAND_IN_PROGRESS = 0xFF 77 }; 78 79 enum class CmdStatus 80 { 81 SUCCESS = 0x00, 82 FAILURE = 0x02, 83 COMM_FAILURE = 0x03 84 }; 85 86 /** @brief Trace block of data in hex with log<level:INFO> 87 * 88 * @param[in] data - vector containing data to trace 89 * @param[in] data_len - optional number of bytes to trace 90 * If 0, entire vector will be traced. 91 */ 92 void dump_hex(const std::vector<std::uint8_t>& data, 93 const unsigned int data_len = 0); 94 95 /** @class OccCommand 96 * @brief Send commands and process respsonses from the OCC 97 */ 98 class OccCommand 99 { 100 public: 101 OccCommand() = delete; 102 OccCommand(const OccCommand&) = delete; 103 OccCommand& operator=(const OccCommand&) = delete; 104 OccCommand(OccCommand&&) = default; 105 OccCommand& operator=(OccCommand&&) = default; 106 107 /** @brief Ctor to set up which OCC the command will go to 108 * 109 * @param[in] instance - OCC instance 110 * @param[in] path - Path to attach at 111 */ 112 OccCommand(uint8_t instance, const char* path); 113 114 /** @brief Dtor to clean up and close device */ 115 ~OccCommand() 116 { 117 closeDevice(); 118 } 119 120 /** @brief Send the command to the OCC and collect the response. 121 * The checksum will be validated and removed from the response. 122 * 123 * @param[in] command - command to pass-through 124 * @param[out] response - response 125 * returns SUCCESS if response was received 126 */ 127 CmdStatus send(const std::vector<std::uint8_t>& command, 128 std::vector<std::uint8_t>& response); 129 130 private: 131 /** @brief Instance number of the target OCC */ 132 uint8_t occInstance; 133 134 /** @brief OCC path on the bus */ 135 std::string path; 136 137 /** @brief OCC device path 138 * For now, here is the hard-coded mapping until 139 * the udev rule is in. 140 * occ0 --> /dev/occ1 141 * occ1 --> /dev/occ2 142 * ... 143 */ 144 std::string devicePath; 145 146 /** @brief Indicates whether or not the OCC is currently active */ 147 bool occActive = false; 148 149 /** brief file descriptor associated with occ device */ 150 int fd = -1; 151 152 /** @brief Subscribe to OCC Status signal 153 * 154 * Once the OCC status gets to active, only then we will get /dev/occ2 155 * populated and hence need to wait on that before opening that 156 */ 157 sdbusplus::bus::match_t activeStatusSignal; 158 159 /** Opens devicePath and populates file descriptor */ 160 void openDevice(); 161 162 /** Closed the fd associated with opened device */ 163 void closeDevice(); 164 165 /** @brief Callback function on OCC Status change signals 166 * 167 * @param[in] msg - Data associated with subscribed signal 168 */ 169 void activeStatusEvent(sdbusplus::message_t& msg); 170 }; 171 172 } // namespace occ 173 } // namespace open_power 174