blob: 911b51e5522a3a3b87ff30f0b3a1c2374ac0eb70 [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,
Deepak Kodihalliee717d72018-01-24 04:53:09 -060023 GET_TEMP_READINGS = 0x10,
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -060024 SET_CONF_PARAMS = 0x12,
25 GET_CONF_PARAMS = 0x13,
Ratan Gupta11ddbd22017-08-05 11:59:39 +053026};
27
Tom Josephbe5eaa12017-07-12 19:54:44 +053028static constexpr auto propIntf = "org.freedesktop.DBus.Properties";
29static constexpr auto assetTagIntf =
Patrick Venture0b02be92018-08-31 11:55:55 -070030 "xyz.openbmc_project.Inventory.Decorator.AssetTag";
Tom Josephbe5eaa12017-07-12 19:54:44 +053031static constexpr auto assetTagProp = "AssetTag";
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +030032static constexpr auto networkServiceName = "xyz.openbmc_project.Network";
Patrick Venture0b02be92018-08-31 11:55:55 -070033static constexpr auto networkConfigObj = "/xyz/openbmc_project/network/config";
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +030034static constexpr auto networkConfigIntf =
Patrick Venture0b02be92018-08-31 11:55:55 -070035 "xyz.openbmc_project.Network.SystemConfiguration";
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +030036static constexpr auto hostNameProp = "HostName";
Deepak Kodihalliee717d72018-01-24 04:53:09 -060037static constexpr auto temperatureSensorType = 0x01;
Deepak Kodihalli0b459552018-02-06 06:25:12 -060038static constexpr auto maxInstances = 255;
Kirill Pakhomova2573622018-11-02 19:00:18 +030039static constexpr auto gDCMISensorsConfig =
Deepak Kodihalli0b459552018-02-06 06:25:12 -060040 "/usr/share/ipmi-providers/dcmi_sensors.json";
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -060041static constexpr auto ethernetIntf =
Patrick Venture0b02be92018-08-31 11:55:55 -070042 "xyz.openbmc_project.Network.EthernetInterface";
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -060043static constexpr auto ethernetDefaultChannelNum = 0x1;
44static constexpr auto networkRoot = "/xyz/openbmc_project/network";
Jian Zhang958806d2022-12-13 13:37:09 +080045static constexpr auto dhcpObj = "/xyz/openbmc_project/network/dhcp";
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -060046static constexpr auto dhcpIntf =
Patrick Venture0b02be92018-08-31 11:55:55 -070047 "xyz.openbmc_project.Network.DHCPConfiguration";
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -060048static constexpr auto systemBusName = "org.freedesktop.systemd1";
49static constexpr auto systemPath = "/org/freedesktop/systemd1";
50static constexpr auto systemIntf = "org.freedesktop.systemd1.Manager";
Kirill Pakhomova2573622018-11-02 19:00:18 +030051static constexpr auto gDCMICapabilitiesConfig =
52 "/usr/share/ipmi-providers/dcmi_cap.json";
Kirill Pakhomov2c2af2c2018-11-06 16:06:10 +030053static constexpr auto gDCMIPowerMgmtCapability = "PowerManagement";
54static constexpr auto gDCMIPowerMgmtSupported = 0x1;
Kirill Pakhomovdb5d9b02018-11-06 19:17:51 +030055static constexpr auto gMaxSELEntriesMask = 0xFFF;
56static constexpr auto gByteBitSize = 8;
Tom Josephbe5eaa12017-07-12 19:54:44 +053057
Deepak Kodihalliee717d72018-01-24 04:53:09 -060058namespace temp_readings
59{
Patrick Venture0b02be92018-08-31 11:55:55 -070060static constexpr auto maxDataSets = 8;
61static constexpr auto maxTemp = 127; // degrees C
Deepak Kodihalliee717d72018-01-24 04:53:09 -060062
Patrick Venture0b02be92018-08-31 11:55:55 -070063/** @struct Response
64 *
65 * DCMI payload for Get Temperature Readings response
66 */
67struct Response
68{
Deepak Kodihalliee717d72018-01-24 04:53:09 -060069#if BYTE_ORDER == LITTLE_ENDIAN
Patrick Venture0b02be92018-08-31 11:55:55 -070070 uint8_t temperature : 7; //!< Temperature reading in Celsius
71 uint8_t sign : 1; //!< Sign bit
Deepak Kodihalliee717d72018-01-24 04:53:09 -060072#endif
73#if BYTE_ORDER == BIG_ENDIAN
Patrick Venture0b02be92018-08-31 11:55:55 -070074 uint8_t sign : 1; //!< Sign bit
75 uint8_t temperature : 7; //!< Temperature reading in Celsius
Deepak Kodihalliee717d72018-01-24 04:53:09 -060076#endif
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -050077 uint8_t instance; //!< Entity instance number
Patrick Venture0b02be92018-08-31 11:55:55 -070078} __attribute__((packed));
Deepak Kodihalliee717d72018-01-24 04:53:09 -060079
Patrick Venture0b02be92018-08-31 11:55:55 -070080using ResponseList = std::vector<Response>;
81using Value = uint8_t;
82using Sign = bool;
83using Temperature = std::tuple<Value, Sign>;
84} // namespace temp_readings
Deepak Kodihalliee717d72018-01-24 04:53:09 -060085
Deepak Kodihalli0b459552018-02-06 06:25:12 -060086namespace sensor_info
87{
Patrick Venture0b02be92018-08-31 11:55:55 -070088static constexpr auto maxRecords = 8;
Deepak Kodihalli0b459552018-02-06 06:25:12 -060089
Patrick Venture0b02be92018-08-31 11:55:55 -070090/** @struct Response
91 *
92 * DCMI payload for Get Sensor Info response
93 */
94struct Response
95{
96 uint8_t recordIdLsb; //!< SDR record id LS byte
97 uint8_t recordIdMsb; //!< SDR record id MS byte
98} __attribute__((packed));
Deepak Kodihalli0b459552018-02-06 06:25:12 -060099
Patrick Venture0b02be92018-08-31 11:55:55 -0700100using ResponseList = std::vector<Response>;
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600101} // namespace sensor_info
102
Tom Joseph6f6dd4d2017-07-12 20:07:11 +0530103static constexpr auto groupExtId = 0xDC;
104
Kirill Pakhomov2c2af2c2018-11-06 16:06:10 +0300105/** @brief Check whether DCMI power management is supported
106 * in the DCMI Capabilities config file.
107 *
108 * @return True if DCMI power management is supported
109 */
110bool isDCMIPowerMgmtSupported();
111
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600112/** @enum DCMICapParameters
113 *
114 * DCMI Capability parameters
115 */
116enum class DCMICapParameters
117{
118 SUPPORTED_DCMI_CAPS = 0x01, //!< Supported DCMI Capabilities
119 MANDATORY_PLAT_ATTRIBUTES = 0x02, //!< Mandatory Platform Attributes
120 OPTIONAL_PLAT_ATTRIBUTES = 0x03, //!< Optional Platform Attributes
121 MANAGEABILITY_ACCESS_ATTRIBUTES = 0x04, //!< Manageability Access Attributes
122};
123
124/** @struct GetDCMICapRequest
125 *
126 * DCMI payload for Get capabilities cmd request.
127 */
128struct GetDCMICapRequest
129{
William A. Kennington III5d06cc62019-04-25 02:10:55 -0700130 uint8_t param; //!< Capability parameter selector.
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600131} __attribute__((packed));
132
133/** @struct GetDCMICapRequest
134 *
135 * DCMI payload for Get capabilities cmd response.
136 */
137struct GetDCMICapResponse
138{
Patrick Venture0b02be92018-08-31 11:55:55 -0700139 uint8_t major; //!< DCMI Specification Conformance - major ver
140 uint8_t minor; //!< DCMI Specification Conformance - minor ver
141 uint8_t paramRevision; //!< Parameter Revision = 02h
142 uint8_t data[]; //!< Capability array
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600143} __attribute__((packed));
144
145/** @struct DCMICap
146 *
147 * DCMI capabilities protocol info.
148 */
149struct DCMICap
150{
Patrick Venture0b02be92018-08-31 11:55:55 -0700151 std::string name; //!< Name of DCMI capability.
152 uint8_t bytePosition; //!< Starting byte number from DCMI spec.
153 uint8_t position; //!< bit position from the DCMI spec.
154 uint8_t length; //!< Length of the value from DCMI spec.
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600155};
156
157using DCMICapList = std::vector<DCMICap>;
158
159/** @struct DCMICapEntry
160 *
161 * DCMI capabilities list and size for each parameter.
162 */
163struct DCMICapEntry
164{
Patrick Venture0b02be92018-08-31 11:55:55 -0700165 uint8_t size; //!< Size of capability array in bytes.
166 DCMICapList capList; //!< List of capabilities for a parameter.
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600167};
168
169using DCMICaps = std::map<DCMICapParameters, DCMICapEntry>;
170
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600171/** @struct GetTempReadingsRequest
172 *
173 * DCMI payload for Get Temperature Readings request
174 */
175struct GetTempReadingsRequest
176{
Patrick Venture0b02be92018-08-31 11:55:55 -0700177 uint8_t sensorType; //!< Type of the sensor
178 uint8_t entityId; //!< Entity ID
179 uint8_t entityInstance; //!< Entity Instance (0 means all instances)
180 uint8_t instanceStart; //!< Instance start (used if instance is 0)
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600181} __attribute__((packed));
182
183/** @struct GetTempReadingsResponse
184 *
185 * DCMI header for Get Temperature Readings response
186 */
187struct GetTempReadingsResponseHdr
188{
Patrick Venture0b02be92018-08-31 11:55:55 -0700189 uint8_t numInstances; //!< No. of instances for requested id
190 uint8_t numDataSets; //!< No. of sets of temperature data
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600191} __attribute__((packed));
192
Kirill Pakhomova2573622018-11-02 19:00:18 +0300193/** @brief Parse out JSON config file.
194 *
195 * @param[in] configFile - JSON config file name
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600196 *
197 * @return A json object
198 */
Kirill Pakhomova2573622018-11-02 19:00:18 +0300199Json parseJSONConfig(const std::string& configFile);
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600200
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600201namespace temp_readings
202{
Patrick Venture0b02be92018-08-31 11:55:55 -0700203/** @brief Read temperature from a d-bus object, scale it as per dcmi
204 * get temperature reading requirements.
205 *
206 * @param[in] dbusService - the D-Bus service
207 * @param[in] dbusPath - the D-Bus path
208 *
209 * @return A temperature reading
210 */
211Temperature readTemp(const std::string& dbusService,
212 const std::string& dbusPath);
Deepak Kodihallib1e8fba2018-01-24 04:57:10 -0600213
Patrick Venture0b02be92018-08-31 11:55:55 -0700214/** @brief Read temperatures and fill up DCMI response for the Get
215 * Temperature Readings command. This looks at a specific
216 * instance.
217 *
218 * @param[in] type - one of "inlet", "cpu", "baseboard"
219 * @param[in] instance - A non-zero Entity instance number
220 *
221 * @return A tuple, containing a temperature reading and the
222 * number of instances.
223 */
224std::tuple<Response, NumInstances> read(const std::string& type,
225 uint8_t instance);
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600226
Patrick Venture0b02be92018-08-31 11:55:55 -0700227/** @brief Read temperatures and fill up DCMI response for the Get
228 * Temperature Readings command. This looks at a range of
229 * instances.
230 *
231 * @param[in] type - one of "inlet", "cpu", "baseboard"
232 * @param[in] instanceStart - Entity instance start index
233 *
234 * @return A tuple, containing a list of temperature readings and the
235 * number of instances.
236 */
237std::tuple<ResponseList, NumInstances> readAll(const std::string& type,
238 uint8_t instanceStart);
239} // namespace temp_readings
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600240
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600241namespace sensor_info
242{
Patrick Venture0b02be92018-08-31 11:55:55 -0700243/** @brief Create response from JSON config.
244 *
245 * @param[in] config - JSON config info about DCMI sensors
246 *
247 * @return Sensor info response
248 */
249Response createFromJson(const Json& config);
Deepak Kodihallidd4cff12018-02-06 06:48:29 -0600250
Patrick Venture0b02be92018-08-31 11:55:55 -0700251/** @brief Read sensor info and fill up DCMI response for the Get
252 * Sensor Info command. This looks at a specific
253 * instance.
254 *
255 * @param[in] type - one of "inlet", "cpu", "baseboard"
256 * @param[in] instance - A non-zero Entity instance number
257 * @param[in] config - JSON config info about DCMI sensors
258 *
259 * @return A tuple, containing a sensor info response and
260 * number of instances.
261 */
262std::tuple<Response, NumInstances> read(const std::string& type,
263 uint8_t instance, const Json& config);
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600264
Patrick Venture0b02be92018-08-31 11:55:55 -0700265/** @brief Read sensor info and fill up DCMI response for the Get
266 * Sensor Info command. This looks at a range of
267 * instances.
268 *
269 * @param[in] type - one of "inlet", "cpu", "baseboard"
270 * @param[in] instanceStart - Entity instance start index
271 * @param[in] config - JSON config info about DCMI sensors
272 *
273 * @return A tuple, containing a list of sensor info responses and the
274 * number of instances.
275 */
276std::tuple<ResponseList, NumInstances>
277 readAll(const std::string& type, uint8_t instanceStart, const Json& config);
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600278} // namespace sensor_info
279
Marri Devender Rao66c5fda2018-01-18 10:48:37 -0600280/** @brief Read power reading from power reading sensor object
281 *
282 * @param[in] bus - dbus connection
283 *
284 * @return total power reading
285 */
Patrick Williams5d82f472022-07-22 19:26:53 -0500286int64_t getPowerReading(sdbusplus::bus_t& bus);
Marri Devender Rao66c5fda2018-01-18 10:48:37 -0600287
288/** @struct GetPowerReadingRequest
289 *
290 * DCMI Get Power Reading command request.
291 * Refer DCMI specification Version 1.1 Section 6.6.1
292 */
293struct GetPowerReadingRequest
294{
Patrick Venture0b02be92018-08-31 11:55:55 -0700295 uint8_t mode; //!< Mode
296 uint8_t modeAttribute; //!< Mode Attributes
Marri Devender Rao66c5fda2018-01-18 10:48:37 -0600297} __attribute__((packed));
298
299/** @struct GetPowerReadingResponse
300 *
301 * DCMI Get Power Reading command response.
302 * Refer DCMI specification Version 1.1 Section 6.6.1
303 */
304struct GetPowerReadingResponse
305{
Patrick Venture0b02be92018-08-31 11:55:55 -0700306 uint16_t currentPower; //!< Current power in watts
307 uint16_t minimumPower; //!< Minimum power over sampling duration
308 //!< in watts
309 uint16_t maximumPower; //!< Maximum power over sampling duration
310 //!< in watts
311 uint16_t averagePower; //!< Average power over sampling duration
312 //!< in watts
313 uint32_t timeStamp; //!< IPMI specification based time stamp
314 uint32_t timeFrame; //!< Statistics reporting time period in milli
315 //!< seconds.
316 uint8_t powerReadingState; //!< Power Reading State
Marri Devender Rao66c5fda2018-01-18 10:48:37 -0600317} __attribute__((packed));
318
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600319/** @struct GetSensorInfoRequest
320 *
321 * DCMI payload for Get Sensor Info request
322 */
323struct GetSensorInfoRequest
324{
Patrick Venture0b02be92018-08-31 11:55:55 -0700325 uint8_t sensorType; //!< Type of the sensor
326 uint8_t entityId; //!< Entity ID
327 uint8_t entityInstance; //!< Entity Instance (0 means all instances)
328 uint8_t instanceStart; //!< Instance start (used if instance is 0)
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600329} __attribute__((packed));
330
331/** @struct GetSensorInfoResponseHdr
332 *
333 * DCMI header for Get Sensor Info response
334 */
335struct GetSensorInfoResponseHdr
336{
Patrick Venture0b02be92018-08-31 11:55:55 -0700337 uint8_t numInstances; //!< No. of instances for requested id
338 uint8_t numRecords; //!< No. of record ids in the response
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600339} __attribute__((packed));
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600340/**
341 * @brief Parameters for DCMI Configuration Parameters
342 */
Patrick Venture0b02be92018-08-31 11:55:55 -0700343enum class DCMIConfigParameters : uint8_t
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600344{
345 ActivateDHCP = 1,
346 DiscoveryConfig,
347 DHCPTiming1,
348 DHCPTiming2,
349 DHCPTiming3,
350};
351
352/** @struct SetConfParamsRequest
353 *
354 * DCMI Set DCMI Configuration Parameters Command.
355 * Refer DCMI specification Version 1.1 Section 6.1.2
356 */
357struct SetConfParamsRequest
358{
Patrick Venture0b02be92018-08-31 11:55:55 -0700359 uint8_t paramSelect; //!< Parameter selector.
360 uint8_t setSelect; //!< Set Selector (use 00h for parameters that only
361 //!< have one set).
362 uint8_t data[]; //!< Configuration parameter data.
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600363} __attribute__((packed));
364
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600365/** @struct GetConfParamsRequest
366 *
367 * DCMI Get DCMI Configuration Parameters Command.
368 * Refer DCMI specification Version 1.1 Section 6.1.3
369 */
370struct GetConfParamsRequest
371{
Patrick Venture0b02be92018-08-31 11:55:55 -0700372 uint8_t paramSelect; //!< Parameter selector.
373 uint8_t setSelect; //!< Set Selector. Selects a given set of parameters
374 //!< under a given Parameter selector value. 00h if
375 //!< parameter doesn't use a Set Selector.
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600376} __attribute__((packed));
377
378/** @struct GetConfParamsResponse
379 *
380 * DCMI Get DCMI Configuration Parameters Command response.
381 * Refer DCMI specification Version 1.1 Section 6.1.3
382 */
383struct GetConfParamsResponse
384{
Patrick Venture0b02be92018-08-31 11:55:55 -0700385 uint8_t major; //!< DCMI Spec Conformance - major ver = 01h.
386 uint8_t minor; //!< DCMI Spec Conformance - minor ver = 05h.
387 uint8_t paramRevision; //!< Parameter Revision = 01h.
388 uint8_t data[]; //!< Parameter data.
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600389} __attribute__((packed));
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600390
Tom Josephbe5eaa12017-07-12 19:54:44 +0530391} // namespace dcmi