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 | { |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 19 | GET_POWER_READING = 0x02, |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 20 | GET_SENSOR_INFO = 0x07, |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 21 | SET_CONF_PARAMS = 0x12, |
| 22 | GET_CONF_PARAMS = 0x13, |
Ratan Gupta | 11ddbd2 | 2017-08-05 11:59:39 +0530 | [diff] [blame] | 23 | }; |
| 24 | |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 25 | static constexpr auto propIntf = "org.freedesktop.DBus.Properties"; |
| 26 | static constexpr auto assetTagIntf = |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 27 | "xyz.openbmc_project.Inventory.Decorator.AssetTag"; |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 28 | static constexpr auto assetTagProp = "AssetTag"; |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 29 | static constexpr auto networkServiceName = "xyz.openbmc_project.Network"; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 30 | static constexpr auto networkConfigObj = "/xyz/openbmc_project/network/config"; |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 31 | static constexpr auto networkConfigIntf = |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 32 | "xyz.openbmc_project.Network.SystemConfiguration"; |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 33 | static constexpr auto hostNameProp = "HostName"; |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 34 | static constexpr auto temperatureSensorType = 0x01; |
Vernon Mauery | cce9ffd | 2023-07-27 14:15:17 -0700 | [diff] [blame^] | 35 | static constexpr size_t maxInstances = 255; |
| 36 | static constexpr uint8_t maxRecords = 8; |
Kirill Pakhomov | a257362 | 2018-11-02 19:00:18 +0300 | [diff] [blame] | 37 | static constexpr auto gDCMISensorsConfig = |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 38 | "/usr/share/ipmi-providers/dcmi_sensors.json"; |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 39 | static constexpr auto ethernetIntf = |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 40 | "xyz.openbmc_project.Network.EthernetInterface"; |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 41 | static constexpr auto ethernetDefaultChannelNum = 0x1; |
| 42 | static constexpr auto networkRoot = "/xyz/openbmc_project/network"; |
Jian Zhang | 958806d | 2022-12-13 13:37:09 +0800 | [diff] [blame] | 43 | static constexpr auto dhcpObj = "/xyz/openbmc_project/network/dhcp"; |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 44 | static constexpr auto dhcpIntf = |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 45 | "xyz.openbmc_project.Network.DHCPConfiguration"; |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 46 | static constexpr auto systemBusName = "org.freedesktop.systemd1"; |
| 47 | static constexpr auto systemPath = "/org/freedesktop/systemd1"; |
| 48 | static constexpr auto systemIntf = "org.freedesktop.systemd1.Manager"; |
Kirill Pakhomov | a257362 | 2018-11-02 19:00:18 +0300 | [diff] [blame] | 49 | static constexpr auto gDCMICapabilitiesConfig = |
| 50 | "/usr/share/ipmi-providers/dcmi_cap.json"; |
Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 51 | static constexpr auto gDCMIPowerMgmtCapability = "PowerManagement"; |
| 52 | static constexpr auto gDCMIPowerMgmtSupported = 0x1; |
Kirill Pakhomov | db5d9b0 | 2018-11-06 19:17:51 +0300 | [diff] [blame] | 53 | static constexpr auto gMaxSELEntriesMask = 0xFFF; |
| 54 | static constexpr auto gByteBitSize = 8; |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 55 | |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 56 | namespace sensor_info |
| 57 | { |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 58 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 59 | /** @struct Response |
| 60 | * |
| 61 | * DCMI payload for Get Sensor Info response |
| 62 | */ |
| 63 | struct Response |
| 64 | { |
| 65 | uint8_t recordIdLsb; //!< SDR record id LS byte |
| 66 | uint8_t recordIdMsb; //!< SDR record id MS byte |
| 67 | } __attribute__((packed)); |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 68 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 69 | using ResponseList = std::vector<Response>; |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 70 | } // namespace sensor_info |
| 71 | |
Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 72 | static constexpr auto groupExtId = 0xDC; |
| 73 | |
Kirill Pakhomov | 2c2af2c | 2018-11-06 16:06:10 +0300 | [diff] [blame] | 74 | /** @brief Check whether DCMI power management is supported |
| 75 | * in the DCMI Capabilities config file. |
| 76 | * |
| 77 | * @return True if DCMI power management is supported |
| 78 | */ |
| 79 | bool isDCMIPowerMgmtSupported(); |
| 80 | |
Kirill Pakhomov | a257362 | 2018-11-02 19:00:18 +0300 | [diff] [blame] | 81 | /** @brief Parse out JSON config file. |
| 82 | * |
| 83 | * @param[in] configFile - JSON config file name |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 84 | * |
| 85 | * @return A json object |
| 86 | */ |
Kirill Pakhomov | a257362 | 2018-11-02 19:00:18 +0300 | [diff] [blame] | 87 | Json parseJSONConfig(const std::string& configFile); |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 88 | |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 89 | namespace sensor_info |
| 90 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 91 | /** @brief Create response from JSON config. |
| 92 | * |
| 93 | * @param[in] config - JSON config info about DCMI sensors |
| 94 | * |
| 95 | * @return Sensor info response |
| 96 | */ |
| 97 | Response createFromJson(const Json& config); |
Deepak Kodihalli | dd4cff1 | 2018-02-06 06:48:29 -0600 | [diff] [blame] | 98 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 99 | /** @brief Read sensor info and fill up DCMI response for the Get |
| 100 | * Sensor Info command. This looks at a specific |
| 101 | * instance. |
| 102 | * |
| 103 | * @param[in] type - one of "inlet", "cpu", "baseboard" |
| 104 | * @param[in] instance - A non-zero Entity instance number |
| 105 | * @param[in] config - JSON config info about DCMI sensors |
| 106 | * |
| 107 | * @return A tuple, containing a sensor info response and |
| 108 | * number of instances. |
| 109 | */ |
| 110 | std::tuple<Response, NumInstances> read(const std::string& type, |
| 111 | uint8_t instance, const Json& config); |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 112 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 113 | /** @brief Read sensor info and fill up DCMI response for the Get |
| 114 | * Sensor Info command. This looks at a range of |
| 115 | * instances. |
| 116 | * |
| 117 | * @param[in] type - one of "inlet", "cpu", "baseboard" |
| 118 | * @param[in] instanceStart - Entity instance start index |
| 119 | * @param[in] config - JSON config info about DCMI sensors |
| 120 | * |
| 121 | * @return A tuple, containing a list of sensor info responses and the |
| 122 | * number of instances. |
| 123 | */ |
| 124 | std::tuple<ResponseList, NumInstances> |
| 125 | readAll(const std::string& type, uint8_t instanceStart, const Json& config); |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 126 | } // namespace sensor_info |
| 127 | |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 128 | /** @brief Read power reading from power reading sensor object |
| 129 | * |
| 130 | * @param[in] bus - dbus connection |
| 131 | * |
| 132 | * @return total power reading |
| 133 | */ |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 134 | int64_t getPowerReading(sdbusplus::bus_t& bus); |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 135 | |
| 136 | /** @struct GetPowerReadingRequest |
| 137 | * |
| 138 | * DCMI Get Power Reading command request. |
| 139 | * Refer DCMI specification Version 1.1 Section 6.6.1 |
| 140 | */ |
| 141 | struct GetPowerReadingRequest |
| 142 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 143 | uint8_t mode; //!< Mode |
| 144 | uint8_t modeAttribute; //!< Mode Attributes |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 145 | } __attribute__((packed)); |
| 146 | |
| 147 | /** @struct GetPowerReadingResponse |
| 148 | * |
| 149 | * DCMI Get Power Reading command response. |
| 150 | * Refer DCMI specification Version 1.1 Section 6.6.1 |
| 151 | */ |
| 152 | struct GetPowerReadingResponse |
| 153 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 154 | uint16_t currentPower; //!< Current power in watts |
| 155 | uint16_t minimumPower; //!< Minimum power over sampling duration |
| 156 | //!< in watts |
| 157 | uint16_t maximumPower; //!< Maximum power over sampling duration |
| 158 | //!< in watts |
| 159 | uint16_t averagePower; //!< Average power over sampling duration |
| 160 | //!< in watts |
| 161 | uint32_t timeStamp; //!< IPMI specification based time stamp |
| 162 | uint32_t timeFrame; //!< Statistics reporting time period in milli |
| 163 | //!< seconds. |
| 164 | uint8_t powerReadingState; //!< Power Reading State |
Marri Devender Rao | 66c5fda | 2018-01-18 10:48:37 -0600 | [diff] [blame] | 165 | } __attribute__((packed)); |
| 166 | |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 167 | /** @struct GetSensorInfoRequest |
| 168 | * |
| 169 | * DCMI payload for Get Sensor Info request |
| 170 | */ |
| 171 | struct GetSensorInfoRequest |
| 172 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 173 | uint8_t sensorType; //!< Type of the sensor |
| 174 | uint8_t entityId; //!< Entity ID |
| 175 | uint8_t entityInstance; //!< Entity Instance (0 means all instances) |
| 176 | uint8_t instanceStart; //!< Instance start (used if instance is 0) |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 177 | } __attribute__((packed)); |
| 178 | |
| 179 | /** @struct GetSensorInfoResponseHdr |
| 180 | * |
| 181 | * DCMI header for Get Sensor Info response |
| 182 | */ |
| 183 | struct GetSensorInfoResponseHdr |
| 184 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 185 | uint8_t numInstances; //!< No. of instances for requested id |
| 186 | uint8_t numRecords; //!< No. of record ids in the response |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 187 | } __attribute__((packed)); |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 188 | /** |
| 189 | * @brief Parameters for DCMI Configuration Parameters |
| 190 | */ |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 191 | enum class DCMIConfigParameters : uint8_t |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 192 | { |
| 193 | ActivateDHCP = 1, |
| 194 | DiscoveryConfig, |
| 195 | DHCPTiming1, |
| 196 | DHCPTiming2, |
| 197 | DHCPTiming3, |
| 198 | }; |
| 199 | |
| 200 | /** @struct SetConfParamsRequest |
| 201 | * |
| 202 | * DCMI Set DCMI Configuration Parameters Command. |
| 203 | * Refer DCMI specification Version 1.1 Section 6.1.2 |
| 204 | */ |
| 205 | struct SetConfParamsRequest |
| 206 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 207 | uint8_t paramSelect; //!< Parameter selector. |
| 208 | uint8_t setSelect; //!< Set Selector (use 00h for parameters that only |
| 209 | //!< have one set). |
| 210 | uint8_t data[]; //!< Configuration parameter data. |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 211 | } __attribute__((packed)); |
| 212 | |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 213 | /** @struct GetConfParamsRequest |
| 214 | * |
| 215 | * DCMI Get DCMI Configuration Parameters Command. |
| 216 | * Refer DCMI specification Version 1.1 Section 6.1.3 |
| 217 | */ |
| 218 | struct GetConfParamsRequest |
| 219 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 220 | uint8_t paramSelect; //!< Parameter selector. |
| 221 | uint8_t setSelect; //!< Set Selector. Selects a given set of parameters |
| 222 | //!< under a given Parameter selector value. 00h if |
| 223 | //!< parameter doesn't use a Set Selector. |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 224 | } __attribute__((packed)); |
| 225 | |
| 226 | /** @struct GetConfParamsResponse |
| 227 | * |
| 228 | * DCMI Get DCMI Configuration Parameters Command response. |
| 229 | * Refer DCMI specification Version 1.1 Section 6.1.3 |
| 230 | */ |
| 231 | struct GetConfParamsResponse |
| 232 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 233 | uint8_t major; //!< DCMI Spec Conformance - major ver = 01h. |
| 234 | uint8_t minor; //!< DCMI Spec Conformance - minor ver = 05h. |
| 235 | uint8_t paramRevision; //!< Parameter Revision = 01h. |
| 236 | uint8_t data[]; //!< Parameter data. |
Nagaraju Goruganti | 22be97b | 2018-02-07 01:19:59 -0600 | [diff] [blame] | 237 | } __attribute__((packed)); |
Deepak Kodihalli | 0b45955 | 2018-02-06 06:25:12 -0600 | [diff] [blame] | 238 | |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 239 | } // namespace dcmi |