blob: 0a846be7380b3cf3ea4e9e4fc80a76cab8158bd1 [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{
19 // Get capability bits
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -060020 GET_CAPABILITIES = 0x01,
Marri Devender Rao66c5fda2018-01-18 10:48:37 -060021 GET_POWER_READING = 0x02,
Deepak Kodihalli0b459552018-02-06 06:25:12 -060022 GET_SENSOR_INFO = 0x07,
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +030023 GET_MGMNT_CTRL_ID_STR = 0x09,
24 SET_MGMNT_CTRL_ID_STR = 0x0A,
Deepak Kodihalliee717d72018-01-24 04:53:09 -060025 GET_TEMP_READINGS = 0x10,
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -060026 SET_CONF_PARAMS = 0x12,
27 GET_CONF_PARAMS = 0x13,
Ratan Gupta11ddbd22017-08-05 11:59:39 +053028};
29
Tom Josephbe5eaa12017-07-12 19:54:44 +053030static constexpr auto propIntf = "org.freedesktop.DBus.Properties";
31static constexpr auto assetTagIntf =
Patrick Venture0b02be92018-08-31 11:55:55 -070032 "xyz.openbmc_project.Inventory.Decorator.AssetTag";
Tom Josephbe5eaa12017-07-12 19:54:44 +053033static constexpr auto assetTagProp = "AssetTag";
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +030034static constexpr auto networkServiceName = "xyz.openbmc_project.Network";
Patrick Venture0b02be92018-08-31 11:55:55 -070035static constexpr auto networkConfigObj = "/xyz/openbmc_project/network/config";
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +030036static constexpr auto networkConfigIntf =
Patrick Venture0b02be92018-08-31 11:55:55 -070037 "xyz.openbmc_project.Network.SystemConfiguration";
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +030038static constexpr auto hostNameProp = "HostName";
Deepak Kodihalliee717d72018-01-24 04:53:09 -060039static constexpr auto temperatureSensorType = 0x01;
Deepak Kodihalli0b459552018-02-06 06:25:12 -060040static constexpr auto maxInstances = 255;
Kirill Pakhomova2573622018-11-02 19:00:18 +030041static constexpr auto gDCMISensorsConfig =
Deepak Kodihalli0b459552018-02-06 06:25:12 -060042 "/usr/share/ipmi-providers/dcmi_sensors.json";
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -060043static constexpr auto ethernetIntf =
Patrick Venture0b02be92018-08-31 11:55:55 -070044 "xyz.openbmc_project.Network.EthernetInterface";
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -060045static constexpr auto ethernetDefaultChannelNum = 0x1;
46static constexpr auto networkRoot = "/xyz/openbmc_project/network";
Jian Zhang958806d2022-12-13 13:37:09 +080047static constexpr auto dhcpObj = "/xyz/openbmc_project/network/dhcp";
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -060048static constexpr auto dhcpIntf =
Patrick Venture0b02be92018-08-31 11:55:55 -070049 "xyz.openbmc_project.Network.DHCPConfiguration";
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -060050static constexpr auto systemBusName = "org.freedesktop.systemd1";
51static constexpr auto systemPath = "/org/freedesktop/systemd1";
52static constexpr auto systemIntf = "org.freedesktop.systemd1.Manager";
Kirill Pakhomova2573622018-11-02 19:00:18 +030053static constexpr auto gDCMICapabilitiesConfig =
54 "/usr/share/ipmi-providers/dcmi_cap.json";
Kirill Pakhomov2c2af2c2018-11-06 16:06:10 +030055static constexpr auto gDCMIPowerMgmtCapability = "PowerManagement";
56static constexpr auto gDCMIPowerMgmtSupported = 0x1;
Kirill Pakhomovdb5d9b02018-11-06 19:17:51 +030057static constexpr auto gMaxSELEntriesMask = 0xFFF;
58static constexpr auto gByteBitSize = 8;
Tom Josephbe5eaa12017-07-12 19:54:44 +053059
Deepak Kodihalliee717d72018-01-24 04:53:09 -060060namespace temp_readings
61{
Patrick Venture0b02be92018-08-31 11:55:55 -070062static constexpr auto maxDataSets = 8;
63static constexpr auto maxTemp = 127; // degrees C
Deepak Kodihalliee717d72018-01-24 04:53:09 -060064
Patrick Venture0b02be92018-08-31 11:55:55 -070065/** @struct Response
66 *
67 * DCMI payload for Get Temperature Readings response
68 */
69struct Response
70{
Deepak Kodihalliee717d72018-01-24 04:53:09 -060071#if BYTE_ORDER == LITTLE_ENDIAN
Patrick Venture0b02be92018-08-31 11:55:55 -070072 uint8_t temperature : 7; //!< Temperature reading in Celsius
73 uint8_t sign : 1; //!< Sign bit
Deepak Kodihalliee717d72018-01-24 04:53:09 -060074#endif
75#if BYTE_ORDER == BIG_ENDIAN
Patrick Venture0b02be92018-08-31 11:55:55 -070076 uint8_t sign : 1; //!< Sign bit
77 uint8_t temperature : 7; //!< Temperature reading in Celsius
Deepak Kodihalliee717d72018-01-24 04:53:09 -060078#endif
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -050079 uint8_t instance; //!< Entity instance number
Patrick Venture0b02be92018-08-31 11:55:55 -070080} __attribute__((packed));
Deepak Kodihalliee717d72018-01-24 04:53:09 -060081
Patrick Venture0b02be92018-08-31 11:55:55 -070082using ResponseList = std::vector<Response>;
83using Value = uint8_t;
84using Sign = bool;
85using Temperature = std::tuple<Value, Sign>;
86} // namespace temp_readings
Deepak Kodihalliee717d72018-01-24 04:53:09 -060087
Deepak Kodihalli0b459552018-02-06 06:25:12 -060088namespace sensor_info
89{
Patrick Venture0b02be92018-08-31 11:55:55 -070090static constexpr auto maxRecords = 8;
Deepak Kodihalli0b459552018-02-06 06:25:12 -060091
Patrick Venture0b02be92018-08-31 11:55:55 -070092/** @struct Response
93 *
94 * DCMI payload for Get Sensor Info response
95 */
96struct Response
97{
98 uint8_t recordIdLsb; //!< SDR record id LS byte
99 uint8_t recordIdMsb; //!< SDR record id MS byte
100} __attribute__((packed));
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600101
Patrick Venture0b02be92018-08-31 11:55:55 -0700102using ResponseList = std::vector<Response>;
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600103} // namespace sensor_info
104
Tom Joseph6f6dd4d2017-07-12 20:07:11 +0530105static constexpr auto groupExtId = 0xDC;
106
Kirill Pakhomov2c2af2c2018-11-06 16:06:10 +0300107/** @brief Check whether DCMI power management is supported
108 * in the DCMI Capabilities config file.
109 *
110 * @return True if DCMI power management is supported
111 */
112bool isDCMIPowerMgmtSupported();
113
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300114/** @struct GetMgmntCtrlIdStrRequest
115 *
116 * DCMI payload for Get Management Controller Identifier String cmd request.
117 */
118struct GetMgmntCtrlIdStrRequest
119{
William A. Kennington III5d06cc62019-04-25 02:10:55 -0700120 uint8_t offset; //!< Offset to read.
121 uint8_t bytes; //!< Number of bytes to read.
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300122} __attribute__((packed));
123
124/** @struct GetMgmntCtrlIdStrResponse
125 *
126 * DCMI payload for Get Management Controller Identifier String cmd response.
127 */
128struct GetMgmntCtrlIdStrResponse
129{
William A. Kennington III5d06cc62019-04-25 02:10:55 -0700130 uint8_t strLen; //!< ID string length.
131 char data[]; //!< ID string
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300132} __attribute__((packed));
133
134/** @struct SetMgmntCtrlIdStrRequest
135 *
136 * DCMI payload for Set Management Controller Identifier String cmd request.
137 */
138struct SetMgmntCtrlIdStrRequest
139{
William A. Kennington III5d06cc62019-04-25 02:10:55 -0700140 uint8_t offset; //!< Offset to write.
141 uint8_t bytes; //!< Number of bytes to read.
142 char data[]; //!< ID string
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300143} __attribute__((packed));
144
145/** @struct GetMgmntCtrlIdStrResponse
146 *
147 * DCMI payload for Get Management Controller Identifier String cmd response.
148 */
149struct SetMgmntCtrlIdStrResponse
150{
William A. Kennington III5d06cc62019-04-25 02:10:55 -0700151 uint8_t offset; //!< Last Offset Written.
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300152} __attribute__((packed));
153
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600154/** @enum DCMICapParameters
155 *
156 * DCMI Capability parameters
157 */
158enum class DCMICapParameters
159{
160 SUPPORTED_DCMI_CAPS = 0x01, //!< Supported DCMI Capabilities
161 MANDATORY_PLAT_ATTRIBUTES = 0x02, //!< Mandatory Platform Attributes
162 OPTIONAL_PLAT_ATTRIBUTES = 0x03, //!< Optional Platform Attributes
163 MANAGEABILITY_ACCESS_ATTRIBUTES = 0x04, //!< Manageability Access Attributes
164};
165
166/** @struct GetDCMICapRequest
167 *
168 * DCMI payload for Get capabilities cmd request.
169 */
170struct GetDCMICapRequest
171{
William A. Kennington III5d06cc62019-04-25 02:10:55 -0700172 uint8_t param; //!< Capability parameter selector.
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600173} __attribute__((packed));
174
175/** @struct GetDCMICapRequest
176 *
177 * DCMI payload for Get capabilities cmd response.
178 */
179struct GetDCMICapResponse
180{
Patrick Venture0b02be92018-08-31 11:55:55 -0700181 uint8_t major; //!< DCMI Specification Conformance - major ver
182 uint8_t minor; //!< DCMI Specification Conformance - minor ver
183 uint8_t paramRevision; //!< Parameter Revision = 02h
184 uint8_t data[]; //!< Capability array
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600185} __attribute__((packed));
186
187/** @struct DCMICap
188 *
189 * DCMI capabilities protocol info.
190 */
191struct DCMICap
192{
Patrick Venture0b02be92018-08-31 11:55:55 -0700193 std::string name; //!< Name of DCMI capability.
194 uint8_t bytePosition; //!< Starting byte number from DCMI spec.
195 uint8_t position; //!< bit position from the DCMI spec.
196 uint8_t length; //!< Length of the value from DCMI spec.
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600197};
198
199using DCMICapList = std::vector<DCMICap>;
200
201/** @struct DCMICapEntry
202 *
203 * DCMI capabilities list and size for each parameter.
204 */
205struct DCMICapEntry
206{
Patrick Venture0b02be92018-08-31 11:55:55 -0700207 uint8_t size; //!< Size of capability array in bytes.
208 DCMICapList capList; //!< List of capabilities for a parameter.
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600209};
210
211using DCMICaps = std::map<DCMICapParameters, DCMICapEntry>;
212
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600213/** @struct GetTempReadingsRequest
214 *
215 * DCMI payload for Get Temperature Readings request
216 */
217struct GetTempReadingsRequest
218{
Patrick Venture0b02be92018-08-31 11:55:55 -0700219 uint8_t sensorType; //!< Type of the sensor
220 uint8_t entityId; //!< Entity ID
221 uint8_t entityInstance; //!< Entity Instance (0 means all instances)
222 uint8_t instanceStart; //!< Instance start (used if instance is 0)
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600223} __attribute__((packed));
224
225/** @struct GetTempReadingsResponse
226 *
227 * DCMI header for Get Temperature Readings response
228 */
229struct GetTempReadingsResponseHdr
230{
Patrick Venture0b02be92018-08-31 11:55:55 -0700231 uint8_t numInstances; //!< No. of instances for requested id
232 uint8_t numDataSets; //!< No. of sets of temperature data
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600233} __attribute__((packed));
234
Kirill Pakhomova2573622018-11-02 19:00:18 +0300235/** @brief Parse out JSON config file.
236 *
237 * @param[in] configFile - JSON config file name
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600238 *
239 * @return A json object
240 */
Kirill Pakhomova2573622018-11-02 19:00:18 +0300241Json parseJSONConfig(const std::string& configFile);
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600242
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600243namespace temp_readings
244{
Patrick Venture0b02be92018-08-31 11:55:55 -0700245/** @brief Read temperature from a d-bus object, scale it as per dcmi
246 * get temperature reading requirements.
247 *
248 * @param[in] dbusService - the D-Bus service
249 * @param[in] dbusPath - the D-Bus path
250 *
251 * @return A temperature reading
252 */
253Temperature readTemp(const std::string& dbusService,
254 const std::string& dbusPath);
Deepak Kodihallib1e8fba2018-01-24 04:57:10 -0600255
Patrick Venture0b02be92018-08-31 11:55:55 -0700256/** @brief Read temperatures and fill up DCMI response for the Get
257 * Temperature Readings command. This looks at a specific
258 * instance.
259 *
260 * @param[in] type - one of "inlet", "cpu", "baseboard"
261 * @param[in] instance - A non-zero Entity instance number
262 *
263 * @return A tuple, containing a temperature reading and the
264 * number of instances.
265 */
266std::tuple<Response, NumInstances> read(const std::string& type,
267 uint8_t instance);
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600268
Patrick Venture0b02be92018-08-31 11:55:55 -0700269/** @brief Read temperatures and fill up DCMI response for the Get
270 * Temperature Readings command. This looks at a range of
271 * instances.
272 *
273 * @param[in] type - one of "inlet", "cpu", "baseboard"
274 * @param[in] instanceStart - Entity instance start index
275 *
276 * @return A tuple, containing a list of temperature readings and the
277 * number of instances.
278 */
279std::tuple<ResponseList, NumInstances> readAll(const std::string& type,
280 uint8_t instanceStart);
281} // namespace temp_readings
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600282
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600283namespace sensor_info
284{
Patrick Venture0b02be92018-08-31 11:55:55 -0700285/** @brief Create response from JSON config.
286 *
287 * @param[in] config - JSON config info about DCMI sensors
288 *
289 * @return Sensor info response
290 */
291Response createFromJson(const Json& config);
Deepak Kodihallidd4cff12018-02-06 06:48:29 -0600292
Patrick Venture0b02be92018-08-31 11:55:55 -0700293/** @brief Read sensor info and fill up DCMI response for the Get
294 * Sensor Info command. This looks at a specific
295 * instance.
296 *
297 * @param[in] type - one of "inlet", "cpu", "baseboard"
298 * @param[in] instance - A non-zero Entity instance number
299 * @param[in] config - JSON config info about DCMI sensors
300 *
301 * @return A tuple, containing a sensor info response and
302 * number of instances.
303 */
304std::tuple<Response, NumInstances> read(const std::string& type,
305 uint8_t instance, const Json& config);
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600306
Patrick Venture0b02be92018-08-31 11:55:55 -0700307/** @brief Read sensor info and fill up DCMI response for the Get
308 * Sensor Info command. This looks at a range of
309 * instances.
310 *
311 * @param[in] type - one of "inlet", "cpu", "baseboard"
312 * @param[in] instanceStart - Entity instance start index
313 * @param[in] config - JSON config info about DCMI sensors
314 *
315 * @return A tuple, containing a list of sensor info responses and the
316 * number of instances.
317 */
318std::tuple<ResponseList, NumInstances>
319 readAll(const std::string& type, uint8_t instanceStart, const Json& config);
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600320} // namespace sensor_info
321
Marri Devender Rao66c5fda2018-01-18 10:48:37 -0600322/** @brief Read power reading from power reading sensor object
323 *
324 * @param[in] bus - dbus connection
325 *
326 * @return total power reading
327 */
Patrick Williams5d82f472022-07-22 19:26:53 -0500328int64_t getPowerReading(sdbusplus::bus_t& bus);
Marri Devender Rao66c5fda2018-01-18 10:48:37 -0600329
330/** @struct GetPowerReadingRequest
331 *
332 * DCMI Get Power Reading command request.
333 * Refer DCMI specification Version 1.1 Section 6.6.1
334 */
335struct GetPowerReadingRequest
336{
Patrick Venture0b02be92018-08-31 11:55:55 -0700337 uint8_t mode; //!< Mode
338 uint8_t modeAttribute; //!< Mode Attributes
Marri Devender Rao66c5fda2018-01-18 10:48:37 -0600339} __attribute__((packed));
340
341/** @struct GetPowerReadingResponse
342 *
343 * DCMI Get Power Reading command response.
344 * Refer DCMI specification Version 1.1 Section 6.6.1
345 */
346struct GetPowerReadingResponse
347{
Patrick Venture0b02be92018-08-31 11:55:55 -0700348 uint16_t currentPower; //!< Current power in watts
349 uint16_t minimumPower; //!< Minimum power over sampling duration
350 //!< in watts
351 uint16_t maximumPower; //!< Maximum power over sampling duration
352 //!< in watts
353 uint16_t averagePower; //!< Average power over sampling duration
354 //!< in watts
355 uint32_t timeStamp; //!< IPMI specification based time stamp
356 uint32_t timeFrame; //!< Statistics reporting time period in milli
357 //!< seconds.
358 uint8_t powerReadingState; //!< Power Reading State
Marri Devender Rao66c5fda2018-01-18 10:48:37 -0600359} __attribute__((packed));
360
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600361/** @struct GetSensorInfoRequest
362 *
363 * DCMI payload for Get Sensor Info request
364 */
365struct GetSensorInfoRequest
366{
Patrick Venture0b02be92018-08-31 11:55:55 -0700367 uint8_t sensorType; //!< Type of the sensor
368 uint8_t entityId; //!< Entity ID
369 uint8_t entityInstance; //!< Entity Instance (0 means all instances)
370 uint8_t instanceStart; //!< Instance start (used if instance is 0)
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600371} __attribute__((packed));
372
373/** @struct GetSensorInfoResponseHdr
374 *
375 * DCMI header for Get Sensor Info response
376 */
377struct GetSensorInfoResponseHdr
378{
Patrick Venture0b02be92018-08-31 11:55:55 -0700379 uint8_t numInstances; //!< No. of instances for requested id
380 uint8_t numRecords; //!< No. of record ids in the response
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600381} __attribute__((packed));
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600382/**
383 * @brief Parameters for DCMI Configuration Parameters
384 */
Patrick Venture0b02be92018-08-31 11:55:55 -0700385enum class DCMIConfigParameters : uint8_t
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600386{
387 ActivateDHCP = 1,
388 DiscoveryConfig,
389 DHCPTiming1,
390 DHCPTiming2,
391 DHCPTiming3,
392};
393
394/** @struct SetConfParamsRequest
395 *
396 * DCMI Set DCMI Configuration Parameters Command.
397 * Refer DCMI specification Version 1.1 Section 6.1.2
398 */
399struct SetConfParamsRequest
400{
Patrick Venture0b02be92018-08-31 11:55:55 -0700401 uint8_t paramSelect; //!< Parameter selector.
402 uint8_t setSelect; //!< Set Selector (use 00h for parameters that only
403 //!< have one set).
404 uint8_t data[]; //!< Configuration parameter data.
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600405} __attribute__((packed));
406
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600407/** @struct GetConfParamsRequest
408 *
409 * DCMI Get DCMI Configuration Parameters Command.
410 * Refer DCMI specification Version 1.1 Section 6.1.3
411 */
412struct GetConfParamsRequest
413{
Patrick Venture0b02be92018-08-31 11:55:55 -0700414 uint8_t paramSelect; //!< Parameter selector.
415 uint8_t setSelect; //!< Set Selector. Selects a given set of parameters
416 //!< under a given Parameter selector value. 00h if
417 //!< parameter doesn't use a Set Selector.
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600418} __attribute__((packed));
419
420/** @struct GetConfParamsResponse
421 *
422 * DCMI Get DCMI Configuration Parameters Command response.
423 * Refer DCMI specification Version 1.1 Section 6.1.3
424 */
425struct GetConfParamsResponse
426{
Patrick Venture0b02be92018-08-31 11:55:55 -0700427 uint8_t major; //!< DCMI Spec Conformance - major ver = 01h.
428 uint8_t minor; //!< DCMI Spec Conformance - minor ver = 05h.
429 uint8_t paramRevision; //!< Parameter Revision = 01h.
430 uint8_t data[]; //!< Parameter data.
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600431} __attribute__((packed));
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600432
Tom Josephbe5eaa12017-07-12 19:54:44 +0530433} // namespace dcmi