blob: 2baad4078e320c73ba9fb0978c865b96c60a16ff [file] [log] [blame]
Patrick Venture46470a32018-09-07 19:26:25 -07001#pragma once
Tom Josephbe5eaa12017-07-12 19:54:44 +05302
Patrick Venture0b02be92018-08-31 11:55:55 -07003#include "nlohmann/json.hpp"
4
Patrick Venture0b02be92018-08-31 11:55:55 -07005#include <sdbusplus/bus.hpp>
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05006
7#include <map>
Tom Josephbe5eaa12017-07-12 19:54:44 +05308#include <string>
9#include <vector>
10
Tom Josephbe5eaa12017-07-12 19:54:44 +053011namespace dcmi
12{
13
Deepak Kodihalli0b459552018-02-06 06:25:12 -060014using NumInstances = size_t;
15using Json = nlohmann::json;
16
Ratan Gupta11ddbd22017-08-05 11:59:39 +053017enum Commands
18{
Marri Devender Rao66c5fda2018-01-18 10:48:37 -060019 GET_POWER_READING = 0x02,
Deepak Kodihalli0b459552018-02-06 06:25:12 -060020 GET_SENSOR_INFO = 0x07,
Deepak Kodihalliee717d72018-01-24 04:53:09 -060021 GET_TEMP_READINGS = 0x10,
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -060022 SET_CONF_PARAMS = 0x12,
23 GET_CONF_PARAMS = 0x13,
Ratan Gupta11ddbd22017-08-05 11:59:39 +053024};
25
Tom Josephbe5eaa12017-07-12 19:54:44 +053026static constexpr auto propIntf = "org.freedesktop.DBus.Properties";
27static constexpr auto assetTagIntf =
Patrick Venture0b02be92018-08-31 11:55:55 -070028 "xyz.openbmc_project.Inventory.Decorator.AssetTag";
Tom Josephbe5eaa12017-07-12 19:54:44 +053029static constexpr auto assetTagProp = "AssetTag";
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +030030static constexpr auto networkServiceName = "xyz.openbmc_project.Network";
Patrick Venture0b02be92018-08-31 11:55:55 -070031static constexpr auto networkConfigObj = "/xyz/openbmc_project/network/config";
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +030032static constexpr auto networkConfigIntf =
Patrick Venture0b02be92018-08-31 11:55:55 -070033 "xyz.openbmc_project.Network.SystemConfiguration";
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +030034static constexpr auto hostNameProp = "HostName";
Deepak Kodihalliee717d72018-01-24 04:53:09 -060035static constexpr auto temperatureSensorType = 0x01;
Deepak Kodihalli0b459552018-02-06 06:25:12 -060036static constexpr auto maxInstances = 255;
Kirill Pakhomova2573622018-11-02 19:00:18 +030037static constexpr auto gDCMISensorsConfig =
Deepak Kodihalli0b459552018-02-06 06:25:12 -060038 "/usr/share/ipmi-providers/dcmi_sensors.json";
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -060039static constexpr auto ethernetIntf =
Patrick Venture0b02be92018-08-31 11:55:55 -070040 "xyz.openbmc_project.Network.EthernetInterface";
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -060041static constexpr auto ethernetDefaultChannelNum = 0x1;
42static constexpr auto networkRoot = "/xyz/openbmc_project/network";
Jian Zhang958806d2022-12-13 13:37:09 +080043static constexpr auto dhcpObj = "/xyz/openbmc_project/network/dhcp";
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -060044static constexpr auto dhcpIntf =
Patrick Venture0b02be92018-08-31 11:55:55 -070045 "xyz.openbmc_project.Network.DHCPConfiguration";
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -060046static constexpr auto systemBusName = "org.freedesktop.systemd1";
47static constexpr auto systemPath = "/org/freedesktop/systemd1";
48static constexpr auto systemIntf = "org.freedesktop.systemd1.Manager";
Kirill Pakhomova2573622018-11-02 19:00:18 +030049static constexpr auto gDCMICapabilitiesConfig =
50 "/usr/share/ipmi-providers/dcmi_cap.json";
Kirill Pakhomov2c2af2c2018-11-06 16:06:10 +030051static constexpr auto gDCMIPowerMgmtCapability = "PowerManagement";
52static constexpr auto gDCMIPowerMgmtSupported = 0x1;
Kirill Pakhomovdb5d9b02018-11-06 19:17:51 +030053static constexpr auto gMaxSELEntriesMask = 0xFFF;
54static constexpr auto gByteBitSize = 8;
Tom Josephbe5eaa12017-07-12 19:54:44 +053055
Deepak Kodihalliee717d72018-01-24 04:53:09 -060056namespace temp_readings
57{
Patrick Venture0b02be92018-08-31 11:55:55 -070058static constexpr auto maxDataSets = 8;
59static constexpr auto maxTemp = 127; // degrees C
Deepak Kodihalliee717d72018-01-24 04:53:09 -060060
Patrick Venture0b02be92018-08-31 11:55:55 -070061/** @struct Response
62 *
63 * DCMI payload for Get Temperature Readings response
64 */
65struct Response
66{
Deepak Kodihalliee717d72018-01-24 04:53:09 -060067#if BYTE_ORDER == LITTLE_ENDIAN
Patrick Venture0b02be92018-08-31 11:55:55 -070068 uint8_t temperature : 7; //!< Temperature reading in Celsius
69 uint8_t sign : 1; //!< Sign bit
Deepak Kodihalliee717d72018-01-24 04:53:09 -060070#endif
71#if BYTE_ORDER == BIG_ENDIAN
Patrick Venture0b02be92018-08-31 11:55:55 -070072 uint8_t sign : 1; //!< Sign bit
73 uint8_t temperature : 7; //!< Temperature reading in Celsius
Deepak Kodihalliee717d72018-01-24 04:53:09 -060074#endif
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -050075 uint8_t instance; //!< Entity instance number
Patrick Venture0b02be92018-08-31 11:55:55 -070076} __attribute__((packed));
Deepak Kodihalliee717d72018-01-24 04:53:09 -060077
Patrick Venture0b02be92018-08-31 11:55:55 -070078using ResponseList = std::vector<Response>;
79using Value = uint8_t;
80using Sign = bool;
81using Temperature = std::tuple<Value, Sign>;
82} // namespace temp_readings
Deepak Kodihalliee717d72018-01-24 04:53:09 -060083
Deepak Kodihalli0b459552018-02-06 06:25:12 -060084namespace sensor_info
85{
Patrick Venture0b02be92018-08-31 11:55:55 -070086static constexpr auto maxRecords = 8;
Deepak Kodihalli0b459552018-02-06 06:25:12 -060087
Patrick Venture0b02be92018-08-31 11:55:55 -070088/** @struct Response
89 *
90 * DCMI payload for Get Sensor Info response
91 */
92struct Response
93{
94 uint8_t recordIdLsb; //!< SDR record id LS byte
95 uint8_t recordIdMsb; //!< SDR record id MS byte
96} __attribute__((packed));
Deepak Kodihalli0b459552018-02-06 06:25:12 -060097
Patrick Venture0b02be92018-08-31 11:55:55 -070098using ResponseList = std::vector<Response>;
Deepak Kodihalli0b459552018-02-06 06:25:12 -060099} // namespace sensor_info
100
Tom Joseph6f6dd4d2017-07-12 20:07:11 +0530101static constexpr auto groupExtId = 0xDC;
102
Kirill Pakhomov2c2af2c2018-11-06 16:06:10 +0300103/** @brief Check whether DCMI power management is supported
104 * in the DCMI Capabilities config file.
105 *
106 * @return True if DCMI power management is supported
107 */
108bool isDCMIPowerMgmtSupported();
109
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600110/** @struct GetTempReadingsRequest
111 *
112 * DCMI payload for Get Temperature Readings request
113 */
114struct GetTempReadingsRequest
115{
Patrick Venture0b02be92018-08-31 11:55:55 -0700116 uint8_t sensorType; //!< Type of the sensor
117 uint8_t entityId; //!< Entity ID
118 uint8_t entityInstance; //!< Entity Instance (0 means all instances)
119 uint8_t instanceStart; //!< Instance start (used if instance is 0)
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600120} __attribute__((packed));
121
122/** @struct GetTempReadingsResponse
123 *
124 * DCMI header for Get Temperature Readings response
125 */
126struct GetTempReadingsResponseHdr
127{
Patrick Venture0b02be92018-08-31 11:55:55 -0700128 uint8_t numInstances; //!< No. of instances for requested id
129 uint8_t numDataSets; //!< No. of sets of temperature data
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600130} __attribute__((packed));
131
Kirill Pakhomova2573622018-11-02 19:00:18 +0300132/** @brief Parse out JSON config file.
133 *
134 * @param[in] configFile - JSON config file name
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600135 *
136 * @return A json object
137 */
Kirill Pakhomova2573622018-11-02 19:00:18 +0300138Json parseJSONConfig(const std::string& configFile);
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600139
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600140namespace temp_readings
141{
Patrick Venture0b02be92018-08-31 11:55:55 -0700142/** @brief Read temperature from a d-bus object, scale it as per dcmi
143 * get temperature reading requirements.
144 *
145 * @param[in] dbusService - the D-Bus service
146 * @param[in] dbusPath - the D-Bus path
147 *
148 * @return A temperature reading
149 */
150Temperature readTemp(const std::string& dbusService,
151 const std::string& dbusPath);
Deepak Kodihallib1e8fba2018-01-24 04:57:10 -0600152
Patrick Venture0b02be92018-08-31 11:55:55 -0700153/** @brief Read temperatures and fill up DCMI response for the Get
154 * Temperature Readings command. This looks at a specific
155 * instance.
156 *
157 * @param[in] type - one of "inlet", "cpu", "baseboard"
158 * @param[in] instance - A non-zero Entity instance number
159 *
160 * @return A tuple, containing a temperature reading and the
161 * number of instances.
162 */
163std::tuple<Response, NumInstances> read(const std::string& type,
164 uint8_t instance);
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600165
Patrick Venture0b02be92018-08-31 11:55:55 -0700166/** @brief Read temperatures and fill up DCMI response for the Get
167 * Temperature Readings command. This looks at a range of
168 * instances.
169 *
170 * @param[in] type - one of "inlet", "cpu", "baseboard"
171 * @param[in] instanceStart - Entity instance start index
172 *
173 * @return A tuple, containing a list of temperature readings and the
174 * number of instances.
175 */
176std::tuple<ResponseList, NumInstances> readAll(const std::string& type,
177 uint8_t instanceStart);
178} // namespace temp_readings
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600179
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600180namespace sensor_info
181{
Patrick Venture0b02be92018-08-31 11:55:55 -0700182/** @brief Create response from JSON config.
183 *
184 * @param[in] config - JSON config info about DCMI sensors
185 *
186 * @return Sensor info response
187 */
188Response createFromJson(const Json& config);
Deepak Kodihallidd4cff12018-02-06 06:48:29 -0600189
Patrick Venture0b02be92018-08-31 11:55:55 -0700190/** @brief Read sensor info and fill up DCMI response for the Get
191 * Sensor Info command. This looks at a specific
192 * instance.
193 *
194 * @param[in] type - one of "inlet", "cpu", "baseboard"
195 * @param[in] instance - A non-zero Entity instance number
196 * @param[in] config - JSON config info about DCMI sensors
197 *
198 * @return A tuple, containing a sensor info response and
199 * number of instances.
200 */
201std::tuple<Response, NumInstances> read(const std::string& type,
202 uint8_t instance, const Json& config);
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600203
Patrick Venture0b02be92018-08-31 11:55:55 -0700204/** @brief Read sensor info and fill up DCMI response for the Get
205 * Sensor Info command. This looks at a range of
206 * instances.
207 *
208 * @param[in] type - one of "inlet", "cpu", "baseboard"
209 * @param[in] instanceStart - Entity instance start index
210 * @param[in] config - JSON config info about DCMI sensors
211 *
212 * @return A tuple, containing a list of sensor info responses and the
213 * number of instances.
214 */
215std::tuple<ResponseList, NumInstances>
216 readAll(const std::string& type, uint8_t instanceStart, const Json& config);
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600217} // namespace sensor_info
218
Marri Devender Rao66c5fda2018-01-18 10:48:37 -0600219/** @brief Read power reading from power reading sensor object
220 *
221 * @param[in] bus - dbus connection
222 *
223 * @return total power reading
224 */
Patrick Williams5d82f472022-07-22 19:26:53 -0500225int64_t getPowerReading(sdbusplus::bus_t& bus);
Marri Devender Rao66c5fda2018-01-18 10:48:37 -0600226
227/** @struct GetPowerReadingRequest
228 *
229 * DCMI Get Power Reading command request.
230 * Refer DCMI specification Version 1.1 Section 6.6.1
231 */
232struct GetPowerReadingRequest
233{
Patrick Venture0b02be92018-08-31 11:55:55 -0700234 uint8_t mode; //!< Mode
235 uint8_t modeAttribute; //!< Mode Attributes
Marri Devender Rao66c5fda2018-01-18 10:48:37 -0600236} __attribute__((packed));
237
238/** @struct GetPowerReadingResponse
239 *
240 * DCMI Get Power Reading command response.
241 * Refer DCMI specification Version 1.1 Section 6.6.1
242 */
243struct GetPowerReadingResponse
244{
Patrick Venture0b02be92018-08-31 11:55:55 -0700245 uint16_t currentPower; //!< Current power in watts
246 uint16_t minimumPower; //!< Minimum power over sampling duration
247 //!< in watts
248 uint16_t maximumPower; //!< Maximum power over sampling duration
249 //!< in watts
250 uint16_t averagePower; //!< Average power over sampling duration
251 //!< in watts
252 uint32_t timeStamp; //!< IPMI specification based time stamp
253 uint32_t timeFrame; //!< Statistics reporting time period in milli
254 //!< seconds.
255 uint8_t powerReadingState; //!< Power Reading State
Marri Devender Rao66c5fda2018-01-18 10:48:37 -0600256} __attribute__((packed));
257
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600258/** @struct GetSensorInfoRequest
259 *
260 * DCMI payload for Get Sensor Info request
261 */
262struct GetSensorInfoRequest
263{
Patrick Venture0b02be92018-08-31 11:55:55 -0700264 uint8_t sensorType; //!< Type of the sensor
265 uint8_t entityId; //!< Entity ID
266 uint8_t entityInstance; //!< Entity Instance (0 means all instances)
267 uint8_t instanceStart; //!< Instance start (used if instance is 0)
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600268} __attribute__((packed));
269
270/** @struct GetSensorInfoResponseHdr
271 *
272 * DCMI header for Get Sensor Info response
273 */
274struct GetSensorInfoResponseHdr
275{
Patrick Venture0b02be92018-08-31 11:55:55 -0700276 uint8_t numInstances; //!< No. of instances for requested id
277 uint8_t numRecords; //!< No. of record ids in the response
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600278} __attribute__((packed));
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600279/**
280 * @brief Parameters for DCMI Configuration Parameters
281 */
Patrick Venture0b02be92018-08-31 11:55:55 -0700282enum class DCMIConfigParameters : uint8_t
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600283{
284 ActivateDHCP = 1,
285 DiscoveryConfig,
286 DHCPTiming1,
287 DHCPTiming2,
288 DHCPTiming3,
289};
290
291/** @struct SetConfParamsRequest
292 *
293 * DCMI Set DCMI Configuration Parameters Command.
294 * Refer DCMI specification Version 1.1 Section 6.1.2
295 */
296struct SetConfParamsRequest
297{
Patrick Venture0b02be92018-08-31 11:55:55 -0700298 uint8_t paramSelect; //!< Parameter selector.
299 uint8_t setSelect; //!< Set Selector (use 00h for parameters that only
300 //!< have one set).
301 uint8_t data[]; //!< Configuration parameter data.
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600302} __attribute__((packed));
303
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600304/** @struct GetConfParamsRequest
305 *
306 * DCMI Get DCMI Configuration Parameters Command.
307 * Refer DCMI specification Version 1.1 Section 6.1.3
308 */
309struct GetConfParamsRequest
310{
Patrick Venture0b02be92018-08-31 11:55:55 -0700311 uint8_t paramSelect; //!< Parameter selector.
312 uint8_t setSelect; //!< Set Selector. Selects a given set of parameters
313 //!< under a given Parameter selector value. 00h if
314 //!< parameter doesn't use a Set Selector.
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600315} __attribute__((packed));
316
317/** @struct GetConfParamsResponse
318 *
319 * DCMI Get DCMI Configuration Parameters Command response.
320 * Refer DCMI specification Version 1.1 Section 6.1.3
321 */
322struct GetConfParamsResponse
323{
Patrick Venture0b02be92018-08-31 11:55:55 -0700324 uint8_t major; //!< DCMI Spec Conformance - major ver = 01h.
325 uint8_t minor; //!< DCMI Spec Conformance - minor ver = 05h.
326 uint8_t paramRevision; //!< Parameter Revision = 01h.
327 uint8_t data[]; //!< Parameter data.
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600328} __attribute__((packed));
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600329
Tom Josephbe5eaa12017-07-12 19:54:44 +0530330} // namespace dcmi