Patrick Venture | 46470a3 | 2018-09-07 19:26:25 -0700 | [diff] [blame] | 1 | #pragma once |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 2 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 3 | #include "nlohmann/json.hpp" |
| 4 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 5 | #include <sdbusplus/bus.hpp> |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame^] | 6 | |
| 7 | #include <map> |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 11 | namespace dcmi |
| 12 | { |
| 13 | |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 14 | using NumInstances = size_t; |
| 15 | using Json = nlohmann::json; |
| 16 | |
Ratan Gupta | 11ddbd2 | 2017-08-05 11:59:39 +0530 | [diff] [blame] | 17 | enum Commands |
| 18 | { |
| 19 | // Get capability bits |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 20 | GET_CAPABILITIES = 0x01, |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 21 | GET_POWER_READING = 0x02, |
Ratan Gupta | 11ddbd2 | 2017-08-05 11:59:39 +0530 | [diff] [blame] | 22 | GET_POWER_LIMIT = 0x03, |
| 23 | SET_POWER_LIMIT = 0x04, |
| 24 | APPLY_POWER_LIMIT = 0x05, |
| 25 | GET_ASSET_TAG = 0x06, |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 26 | GET_SENSOR_INFO = 0x07, |
Ratan Gupta | 11ddbd2 | 2017-08-05 11:59:39 +0530 | [diff] [blame] | 27 | SET_ASSET_TAG = 0x08, |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 28 | GET_MGMNT_CTRL_ID_STR = 0x09, |
| 29 | SET_MGMNT_CTRL_ID_STR = 0x0A, |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 30 | GET_TEMP_READINGS = 0x10, |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 31 | SET_CONF_PARAMS = 0x12, |
| 32 | GET_CONF_PARAMS = 0x13, |
Ratan Gupta | 11ddbd2 | 2017-08-05 11:59:39 +0530 | [diff] [blame] | 33 | }; |
| 34 | |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 35 | static constexpr auto propIntf = "org.freedesktop.DBus.Properties"; |
| 36 | static constexpr auto assetTagIntf = |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 37 | "xyz.openbmc_project.Inventory.Decorator.AssetTag"; |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 38 | static constexpr auto assetTagProp = "AssetTag"; |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 39 | static constexpr auto networkServiceName = "xyz.openbmc_project.Network"; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 40 | static constexpr auto networkConfigObj = "/xyz/openbmc_project/network/config"; |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 41 | static constexpr auto networkConfigIntf = |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 42 | "xyz.openbmc_project.Network.SystemConfiguration"; |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 43 | static constexpr auto hostNameProp = "HostName"; |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 44 | static constexpr auto temperatureSensorType = 0x01; |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 45 | static constexpr auto maxInstances = 255; |
Kirill Pakhomov | a257362 | 2018-11-02 19:00:18 +0300 | [diff] [blame] | 46 | static constexpr auto gDCMISensorsConfig = |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 47 | "/usr/share/ipmi-providers/dcmi_sensors.json"; |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 48 | static constexpr auto ethernetIntf = |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 49 | "xyz.openbmc_project.Network.EthernetInterface"; |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 50 | static constexpr auto ethernetDefaultChannelNum = 0x1; |
| 51 | static constexpr auto networkRoot = "/xyz/openbmc_project/network"; |
Jian Zhang | 958806d | 2022-12-13 13:37:09 +0800 | [diff] [blame] | 52 | static constexpr auto dhcpObj = "/xyz/openbmc_project/network/dhcp"; |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 53 | static constexpr auto dhcpIntf = |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 54 | "xyz.openbmc_project.Network.DHCPConfiguration"; |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 55 | static constexpr auto systemBusName = "org.freedesktop.systemd1"; |
| 56 | static constexpr auto systemPath = "/org/freedesktop/systemd1"; |
| 57 | static constexpr auto systemIntf = "org.freedesktop.systemd1.Manager"; |
Kirill Pakhomov | a257362 | 2018-11-02 19:00:18 +0300 | [diff] [blame] | 58 | static constexpr auto gDCMICapabilitiesConfig = |
| 59 | "/usr/share/ipmi-providers/dcmi_cap.json"; |
Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 60 | static constexpr auto gDCMIPowerMgmtCapability = "PowerManagement"; |
| 61 | static constexpr auto gDCMIPowerMgmtSupported = 0x1; |
Kirill Pakhomov | db5d9b0 | 2018-11-06 19:17:51 +0300 | [diff] [blame] | 62 | static constexpr auto gMaxSELEntriesMask = 0xFFF; |
| 63 | static constexpr auto gByteBitSize = 8; |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 64 | |
| 65 | namespace assettag |
| 66 | { |
| 67 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 68 | using ObjectPath = std::string; |
| 69 | using Service = std::string; |
| 70 | using Interfaces = std::vector<std::string>; |
| 71 | using ObjectTree = std::map<ObjectPath, std::map<Service, Interfaces>>; |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 72 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 73 | } // namespace assettag |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 74 | |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 75 | namespace temp_readings |
| 76 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 77 | static constexpr auto maxDataSets = 8; |
| 78 | static constexpr auto maxTemp = 127; // degrees C |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 79 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 80 | /** @struct Response |
| 81 | * |
| 82 | * DCMI payload for Get Temperature Readings response |
| 83 | */ |
| 84 | struct Response |
| 85 | { |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 86 | #if BYTE_ORDER == LITTLE_ENDIAN |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 87 | uint8_t temperature : 7; //!< Temperature reading in Celsius |
| 88 | uint8_t sign : 1; //!< Sign bit |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 89 | #endif |
| 90 | #if BYTE_ORDER == BIG_ENDIAN |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 91 | uint8_t sign : 1; //!< Sign bit |
| 92 | uint8_t temperature : 7; //!< Temperature reading in Celsius |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 93 | #endif |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame^] | 94 | uint8_t instance; //!< Entity instance number |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 95 | } __attribute__((packed)); |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 96 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 97 | using ResponseList = std::vector<Response>; |
| 98 | using Value = uint8_t; |
| 99 | using Sign = bool; |
| 100 | using Temperature = std::tuple<Value, Sign>; |
| 101 | } // namespace temp_readings |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 102 | |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 103 | namespace sensor_info |
| 104 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 105 | static constexpr auto maxRecords = 8; |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 106 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 107 | /** @struct Response |
| 108 | * |
| 109 | * DCMI payload for Get Sensor Info response |
| 110 | */ |
| 111 | struct Response |
| 112 | { |
| 113 | uint8_t recordIdLsb; //!< SDR record id LS byte |
| 114 | uint8_t recordIdMsb; //!< SDR record id MS byte |
| 115 | } __attribute__((packed)); |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 116 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 117 | using ResponseList = std::vector<Response>; |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 118 | } // namespace sensor_info |
| 119 | |
Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 120 | static constexpr auto groupExtId = 0xDC; |
| 121 | |
| 122 | static constexpr auto assetTagMaxOffset = 62; |
| 123 | static constexpr auto assetTagMaxSize = 63; |
| 124 | static constexpr auto maxBytes = 16; |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 125 | static constexpr size_t maxCtrlIdStrLen = 63; |
Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 126 | |
| 127 | /** @struct GetAssetTagRequest |
| 128 | * |
| 129 | * DCMI payload for Get Asset Tag command request. |
| 130 | */ |
| 131 | struct GetAssetTagRequest |
| 132 | { |
William A. Kennington III | 5d06cc6 | 2019-04-25 02:10:55 -0700 | [diff] [blame] | 133 | uint8_t offset; //!< Offset to read. |
| 134 | uint8_t bytes; //!< Number of bytes to read. |
Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 135 | } __attribute__((packed)); |
| 136 | |
| 137 | /** @struct GetAssetTagResponse |
| 138 | * |
| 139 | * DCMI payload for Get Asset Tag command response. |
| 140 | */ |
| 141 | struct GetAssetTagResponse |
| 142 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 143 | uint8_t tagLength; //!< Total asset tag length. |
Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 144 | } __attribute__((packed)); |
| 145 | |
Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 146 | /** @struct SetAssetTagRequest |
| 147 | * |
| 148 | * DCMI payload for Set Asset Tag command request. |
| 149 | */ |
| 150 | struct SetAssetTagRequest |
| 151 | { |
William A. Kennington III | 5d06cc6 | 2019-04-25 02:10:55 -0700 | [diff] [blame] | 152 | uint8_t offset; //!< Offset to write. |
| 153 | uint8_t bytes; //!< Number of bytes to write. |
Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 154 | } __attribute__((packed)); |
| 155 | |
| 156 | /** @struct SetAssetTagResponse |
| 157 | * |
| 158 | * DCMI payload for Set Asset Tag command response. |
| 159 | */ |
| 160 | struct SetAssetTagResponse |
| 161 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 162 | uint8_t tagLength; //!< Total asset tag length. |
Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 163 | } __attribute__((packed)); |
| 164 | |
Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 165 | /** @brief Check whether DCMI power management is supported |
| 166 | * in the DCMI Capabilities config file. |
| 167 | * |
| 168 | * @return True if DCMI power management is supported |
| 169 | */ |
| 170 | bool isDCMIPowerMgmtSupported(); |
| 171 | |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 172 | /** @brief Read the object tree to fetch the object path that implemented the |
| 173 | * Asset tag interface. |
| 174 | * |
| 175 | * @param[in,out] objectTree - object tree |
| 176 | * |
| 177 | * @return On success return the object tree with the object path that |
| 178 | * implemented the AssetTag interface. |
| 179 | */ |
| 180 | void readAssetTagObjectTree(dcmi::assettag::ObjectTree& objectTree); |
| 181 | |
| 182 | /** @brief Read the asset tag of the server |
| 183 | * |
| 184 | * @return On success return the asset tag. |
| 185 | */ |
| 186 | std::string readAssetTag(); |
| 187 | |
Tom Joseph | be5b989 | 2017-07-15 00:55:23 +0530 | [diff] [blame] | 188 | /** @brief Write the asset tag to the asset tag DBUS property |
| 189 | * |
| 190 | * @param[in] assetTag - Asset Tag to be written to the property. |
| 191 | */ |
| 192 | void writeAssetTag(const std::string& assetTag); |
| 193 | |
Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 194 | /** @brief Read the current power cap value |
| 195 | * |
| 196 | * @param[in] bus - dbus connection |
| 197 | * |
| 198 | * @return On success return the power cap value. |
| 199 | */ |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 200 | uint32_t getPcap(sdbusplus::bus_t& bus); |
Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 201 | |
| 202 | /** @brief Check if the power capping is enabled |
| 203 | * |
| 204 | * @param[in] bus - dbus connection |
| 205 | * |
| 206 | * @return true if the powerCap is enabled and false if the powercap |
| 207 | * is disabled. |
| 208 | */ |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 209 | bool getPcapEnabled(sdbusplus::bus_t& bus); |
Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 210 | |
Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 211 | /** @struct GetPowerLimitResponse |
| 212 | * |
| 213 | * DCMI payload for Get Power Limit command response. |
| 214 | */ |
| 215 | struct GetPowerLimitResponse |
| 216 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 217 | uint16_t reserved; //!< Reserved. |
| 218 | uint8_t exceptionAction; //!< Exception action. |
| 219 | uint16_t powerLimit; //!< Power limit requested in watts. |
| 220 | uint32_t correctionTime; //!< Correction time limit in milliseconds. |
| 221 | uint16_t reserved1; //!< Reserved. |
| 222 | uint16_t samplingPeriod; //!< Statistics sampling period in seconds. |
Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 223 | } __attribute__((packed)); |
| 224 | |
Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 225 | /** @brief Set the power cap value |
| 226 | * |
| 227 | * @param[in] bus - dbus connection |
| 228 | * @param[in] powerCap - power cap value |
| 229 | */ |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 230 | void setPcap(sdbusplus::bus_t& bus, const uint32_t powerCap); |
Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 231 | |
| 232 | /** @struct SetPowerLimitRequest |
| 233 | * |
| 234 | * DCMI payload for Set Power Limit command request. |
| 235 | */ |
| 236 | struct SetPowerLimitRequest |
| 237 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 238 | uint16_t reserved; //!< Reserved |
| 239 | uint8_t reserved1; //!< Reserved |
| 240 | uint8_t exceptionAction; //!< Exception action. |
| 241 | uint16_t powerLimit; //!< Power limit requested in watts. |
| 242 | uint32_t correctionTime; //!< Correction time limit in milliseconds. |
| 243 | uint16_t reserved2; //!< Reserved. |
| 244 | uint16_t samplingPeriod; //!< Statistics sampling period in seconds. |
Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 245 | } __attribute__((packed)); |
| 246 | |
Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 247 | /** @brief Enable or disable the power capping |
| 248 | * |
| 249 | * @param[in] bus - dbus connection |
| 250 | * @param[in] enabled - enable/disable |
| 251 | */ |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 252 | void setPcapEnable(sdbusplus::bus_t& bus, bool enabled); |
Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 253 | |
| 254 | /** @struct ApplyPowerLimitRequest |
| 255 | * |
| 256 | * DCMI payload for Activate/Deactivate Power Limit command request. |
| 257 | */ |
| 258 | struct ApplyPowerLimitRequest |
| 259 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 260 | uint8_t powerLimitAction; //!< Power limit activation |
| 261 | uint16_t reserved; //!< Reserved |
Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 262 | } __attribute__((packed)); |
| 263 | |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 264 | /** @struct GetMgmntCtrlIdStrRequest |
| 265 | * |
| 266 | * DCMI payload for Get Management Controller Identifier String cmd request. |
| 267 | */ |
| 268 | struct GetMgmntCtrlIdStrRequest |
| 269 | { |
William A. Kennington III | 5d06cc6 | 2019-04-25 02:10:55 -0700 | [diff] [blame] | 270 | uint8_t offset; //!< Offset to read. |
| 271 | uint8_t bytes; //!< Number of bytes to read. |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 272 | } __attribute__((packed)); |
| 273 | |
| 274 | /** @struct GetMgmntCtrlIdStrResponse |
| 275 | * |
| 276 | * DCMI payload for Get Management Controller Identifier String cmd response. |
| 277 | */ |
| 278 | struct GetMgmntCtrlIdStrResponse |
| 279 | { |
William A. Kennington III | 5d06cc6 | 2019-04-25 02:10:55 -0700 | [diff] [blame] | 280 | uint8_t strLen; //!< ID string length. |
| 281 | char data[]; //!< ID string |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 282 | } __attribute__((packed)); |
| 283 | |
| 284 | /** @struct SetMgmntCtrlIdStrRequest |
| 285 | * |
| 286 | * DCMI payload for Set Management Controller Identifier String cmd request. |
| 287 | */ |
| 288 | struct SetMgmntCtrlIdStrRequest |
| 289 | { |
William A. Kennington III | 5d06cc6 | 2019-04-25 02:10:55 -0700 | [diff] [blame] | 290 | uint8_t offset; //!< Offset to write. |
| 291 | uint8_t bytes; //!< Number of bytes to read. |
| 292 | char data[]; //!< ID string |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 293 | } __attribute__((packed)); |
| 294 | |
| 295 | /** @struct GetMgmntCtrlIdStrResponse |
| 296 | * |
| 297 | * DCMI payload for Get Management Controller Identifier String cmd response. |
| 298 | */ |
| 299 | struct SetMgmntCtrlIdStrResponse |
| 300 | { |
William A. Kennington III | 5d06cc6 | 2019-04-25 02:10:55 -0700 | [diff] [blame] | 301 | uint8_t offset; //!< Last Offset Written. |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 302 | } __attribute__((packed)); |
| 303 | |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 304 | /** @enum DCMICapParameters |
| 305 | * |
| 306 | * DCMI Capability parameters |
| 307 | */ |
| 308 | enum class DCMICapParameters |
| 309 | { |
| 310 | SUPPORTED_DCMI_CAPS = 0x01, //!< Supported DCMI Capabilities |
| 311 | MANDATORY_PLAT_ATTRIBUTES = 0x02, //!< Mandatory Platform Attributes |
| 312 | OPTIONAL_PLAT_ATTRIBUTES = 0x03, //!< Optional Platform Attributes |
| 313 | MANAGEABILITY_ACCESS_ATTRIBUTES = 0x04, //!< Manageability Access Attributes |
| 314 | }; |
| 315 | |
| 316 | /** @struct GetDCMICapRequest |
| 317 | * |
| 318 | * DCMI payload for Get capabilities cmd request. |
| 319 | */ |
| 320 | struct GetDCMICapRequest |
| 321 | { |
William A. Kennington III | 5d06cc6 | 2019-04-25 02:10:55 -0700 | [diff] [blame] | 322 | uint8_t param; //!< Capability parameter selector. |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 323 | } __attribute__((packed)); |
| 324 | |
| 325 | /** @struct GetDCMICapRequest |
| 326 | * |
| 327 | * DCMI payload for Get capabilities cmd response. |
| 328 | */ |
| 329 | struct GetDCMICapResponse |
| 330 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 331 | uint8_t major; //!< DCMI Specification Conformance - major ver |
| 332 | uint8_t minor; //!< DCMI Specification Conformance - minor ver |
| 333 | uint8_t paramRevision; //!< Parameter Revision = 02h |
| 334 | uint8_t data[]; //!< Capability array |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 335 | } __attribute__((packed)); |
| 336 | |
| 337 | /** @struct DCMICap |
| 338 | * |
| 339 | * DCMI capabilities protocol info. |
| 340 | */ |
| 341 | struct DCMICap |
| 342 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 343 | std::string name; //!< Name of DCMI capability. |
| 344 | uint8_t bytePosition; //!< Starting byte number from DCMI spec. |
| 345 | uint8_t position; //!< bit position from the DCMI spec. |
| 346 | uint8_t length; //!< Length of the value from DCMI spec. |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 347 | }; |
| 348 | |
| 349 | using DCMICapList = std::vector<DCMICap>; |
| 350 | |
| 351 | /** @struct DCMICapEntry |
| 352 | * |
| 353 | * DCMI capabilities list and size for each parameter. |
| 354 | */ |
| 355 | struct DCMICapEntry |
| 356 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 357 | uint8_t size; //!< Size of capability array in bytes. |
| 358 | DCMICapList capList; //!< List of capabilities for a parameter. |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 359 | }; |
| 360 | |
| 361 | using DCMICaps = std::map<DCMICapParameters, DCMICapEntry>; |
| 362 | |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 363 | /** @struct GetTempReadingsRequest |
| 364 | * |
| 365 | * DCMI payload for Get Temperature Readings request |
| 366 | */ |
| 367 | struct GetTempReadingsRequest |
| 368 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 369 | uint8_t sensorType; //!< Type of the sensor |
| 370 | uint8_t entityId; //!< Entity ID |
| 371 | uint8_t entityInstance; //!< Entity Instance (0 means all instances) |
| 372 | uint8_t instanceStart; //!< Instance start (used if instance is 0) |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 373 | } __attribute__((packed)); |
| 374 | |
| 375 | /** @struct GetTempReadingsResponse |
| 376 | * |
| 377 | * DCMI header for Get Temperature Readings response |
| 378 | */ |
| 379 | struct GetTempReadingsResponseHdr |
| 380 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 381 | uint8_t numInstances; //!< No. of instances for requested id |
| 382 | uint8_t numDataSets; //!< No. of sets of temperature data |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 383 | } __attribute__((packed)); |
| 384 | |
Kirill Pakhomov | a257362 | 2018-11-02 19:00:18 +0300 | [diff] [blame] | 385 | /** @brief Parse out JSON config file. |
| 386 | * |
| 387 | * @param[in] configFile - JSON config file name |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 388 | * |
| 389 | * @return A json object |
| 390 | */ |
Kirill Pakhomov | a257362 | 2018-11-02 19:00:18 +0300 | [diff] [blame] | 391 | Json parseJSONConfig(const std::string& configFile); |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 392 | |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 393 | namespace temp_readings |
| 394 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 395 | /** @brief Read temperature from a d-bus object, scale it as per dcmi |
| 396 | * get temperature reading requirements. |
| 397 | * |
| 398 | * @param[in] dbusService - the D-Bus service |
| 399 | * @param[in] dbusPath - the D-Bus path |
| 400 | * |
| 401 | * @return A temperature reading |
| 402 | */ |
| 403 | Temperature readTemp(const std::string& dbusService, |
| 404 | const std::string& dbusPath); |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 405 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 406 | /** @brief Read temperatures and fill up DCMI response for the Get |
| 407 | * Temperature Readings command. This looks at a specific |
| 408 | * instance. |
| 409 | * |
| 410 | * @param[in] type - one of "inlet", "cpu", "baseboard" |
| 411 | * @param[in] instance - A non-zero Entity instance number |
| 412 | * |
| 413 | * @return A tuple, containing a temperature reading and the |
| 414 | * number of instances. |
| 415 | */ |
| 416 | std::tuple<Response, NumInstances> read(const std::string& type, |
| 417 | uint8_t instance); |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 418 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 419 | /** @brief Read temperatures and fill up DCMI response for the Get |
| 420 | * Temperature Readings command. This looks at a range of |
| 421 | * instances. |
| 422 | * |
| 423 | * @param[in] type - one of "inlet", "cpu", "baseboard" |
| 424 | * @param[in] instanceStart - Entity instance start index |
| 425 | * |
| 426 | * @return A tuple, containing a list of temperature readings and the |
| 427 | * number of instances. |
| 428 | */ |
| 429 | std::tuple<ResponseList, NumInstances> readAll(const std::string& type, |
| 430 | uint8_t instanceStart); |
| 431 | } // namespace temp_readings |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 432 | |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 433 | namespace sensor_info |
| 434 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 435 | /** @brief Create response from JSON config. |
| 436 | * |
| 437 | * @param[in] config - JSON config info about DCMI sensors |
| 438 | * |
| 439 | * @return Sensor info response |
| 440 | */ |
| 441 | Response createFromJson(const Json& config); |
Deepak Kodihalli | dd4cff1 | 2018-02-06 06:48:29 -0600 | [diff] [blame] | 442 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 443 | /** @brief Read sensor info and fill up DCMI response for the Get |
| 444 | * Sensor Info command. This looks at a specific |
| 445 | * instance. |
| 446 | * |
| 447 | * @param[in] type - one of "inlet", "cpu", "baseboard" |
| 448 | * @param[in] instance - A non-zero Entity instance number |
| 449 | * @param[in] config - JSON config info about DCMI sensors |
| 450 | * |
| 451 | * @return A tuple, containing a sensor info response and |
| 452 | * number of instances. |
| 453 | */ |
| 454 | std::tuple<Response, NumInstances> read(const std::string& type, |
| 455 | uint8_t instance, const Json& config); |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 456 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 457 | /** @brief Read sensor info and fill up DCMI response for the Get |
| 458 | * Sensor Info command. This looks at a range of |
| 459 | * instances. |
| 460 | * |
| 461 | * @param[in] type - one of "inlet", "cpu", "baseboard" |
| 462 | * @param[in] instanceStart - Entity instance start index |
| 463 | * @param[in] config - JSON config info about DCMI sensors |
| 464 | * |
| 465 | * @return A tuple, containing a list of sensor info responses and the |
| 466 | * number of instances. |
| 467 | */ |
| 468 | std::tuple<ResponseList, NumInstances> |
| 469 | readAll(const std::string& type, uint8_t instanceStart, const Json& config); |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 470 | } // namespace sensor_info |
| 471 | |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 472 | /** @brief Read power reading from power reading sensor object |
| 473 | * |
| 474 | * @param[in] bus - dbus connection |
| 475 | * |
| 476 | * @return total power reading |
| 477 | */ |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 478 | int64_t getPowerReading(sdbusplus::bus_t& bus); |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 479 | |
| 480 | /** @struct GetPowerReadingRequest |
| 481 | * |
| 482 | * DCMI Get Power Reading command request. |
| 483 | * Refer DCMI specification Version 1.1 Section 6.6.1 |
| 484 | */ |
| 485 | struct GetPowerReadingRequest |
| 486 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 487 | uint8_t mode; //!< Mode |
| 488 | uint8_t modeAttribute; //!< Mode Attributes |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 489 | } __attribute__((packed)); |
| 490 | |
| 491 | /** @struct GetPowerReadingResponse |
| 492 | * |
| 493 | * DCMI Get Power Reading command response. |
| 494 | * Refer DCMI specification Version 1.1 Section 6.6.1 |
| 495 | */ |
| 496 | struct GetPowerReadingResponse |
| 497 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 498 | uint16_t currentPower; //!< Current power in watts |
| 499 | uint16_t minimumPower; //!< Minimum power over sampling duration |
| 500 | //!< in watts |
| 501 | uint16_t maximumPower; //!< Maximum power over sampling duration |
| 502 | //!< in watts |
| 503 | uint16_t averagePower; //!< Average power over sampling duration |
| 504 | //!< in watts |
| 505 | uint32_t timeStamp; //!< IPMI specification based time stamp |
| 506 | uint32_t timeFrame; //!< Statistics reporting time period in milli |
| 507 | //!< seconds. |
| 508 | uint8_t powerReadingState; //!< Power Reading State |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 509 | } __attribute__((packed)); |
| 510 | |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 511 | /** @struct GetSensorInfoRequest |
| 512 | * |
| 513 | * DCMI payload for Get Sensor Info request |
| 514 | */ |
| 515 | struct GetSensorInfoRequest |
| 516 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 517 | uint8_t sensorType; //!< Type of the sensor |
| 518 | uint8_t entityId; //!< Entity ID |
| 519 | uint8_t entityInstance; //!< Entity Instance (0 means all instances) |
| 520 | uint8_t instanceStart; //!< Instance start (used if instance is 0) |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 521 | } __attribute__((packed)); |
| 522 | |
| 523 | /** @struct GetSensorInfoResponseHdr |
| 524 | * |
| 525 | * DCMI header for Get Sensor Info response |
| 526 | */ |
| 527 | struct GetSensorInfoResponseHdr |
| 528 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 529 | uint8_t numInstances; //!< No. of instances for requested id |
| 530 | uint8_t numRecords; //!< No. of record ids in the response |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 531 | } __attribute__((packed)); |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 532 | /** |
| 533 | * @brief Parameters for DCMI Configuration Parameters |
| 534 | */ |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 535 | enum class DCMIConfigParameters : uint8_t |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 536 | { |
| 537 | ActivateDHCP = 1, |
| 538 | DiscoveryConfig, |
| 539 | DHCPTiming1, |
| 540 | DHCPTiming2, |
| 541 | DHCPTiming3, |
| 542 | }; |
| 543 | |
| 544 | /** @struct SetConfParamsRequest |
| 545 | * |
| 546 | * DCMI Set DCMI Configuration Parameters Command. |
| 547 | * Refer DCMI specification Version 1.1 Section 6.1.2 |
| 548 | */ |
| 549 | struct SetConfParamsRequest |
| 550 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 551 | uint8_t paramSelect; //!< Parameter selector. |
| 552 | uint8_t setSelect; //!< Set Selector (use 00h for parameters that only |
| 553 | //!< have one set). |
| 554 | uint8_t data[]; //!< Configuration parameter data. |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 555 | } __attribute__((packed)); |
| 556 | |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 557 | /** @struct GetConfParamsRequest |
| 558 | * |
| 559 | * DCMI Get DCMI Configuration Parameters Command. |
| 560 | * Refer DCMI specification Version 1.1 Section 6.1.3 |
| 561 | */ |
| 562 | struct GetConfParamsRequest |
| 563 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 564 | uint8_t paramSelect; //!< Parameter selector. |
| 565 | uint8_t setSelect; //!< Set Selector. Selects a given set of parameters |
| 566 | //!< under a given Parameter selector value. 00h if |
| 567 | //!< parameter doesn't use a Set Selector. |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 568 | } __attribute__((packed)); |
| 569 | |
| 570 | /** @struct GetConfParamsResponse |
| 571 | * |
| 572 | * DCMI Get DCMI Configuration Parameters Command response. |
| 573 | * Refer DCMI specification Version 1.1 Section 6.1.3 |
| 574 | */ |
| 575 | struct GetConfParamsResponse |
| 576 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 577 | uint8_t major; //!< DCMI Spec Conformance - major ver = 01h. |
| 578 | uint8_t minor; //!< DCMI Spec Conformance - minor ver = 05h. |
| 579 | uint8_t paramRevision; //!< Parameter Revision = 01h. |
| 580 | uint8_t data[]; //!< Parameter data. |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 581 | } __attribute__((packed)); |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 582 | |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 583 | } // namespace dcmi |