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