blob: 4a739c2b07dac5d9e9114af68e359d1d41d65573 [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,
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -060021 SET_CONF_PARAMS = 0x12,
22 GET_CONF_PARAMS = 0x13,
Ratan Gupta11ddbd22017-08-05 11:59:39 +053023};
24
Tom Josephbe5eaa12017-07-12 19:54:44 +053025static constexpr auto propIntf = "org.freedesktop.DBus.Properties";
26static constexpr auto assetTagIntf =
Patrick Venture0b02be92018-08-31 11:55:55 -070027 "xyz.openbmc_project.Inventory.Decorator.AssetTag";
Tom Josephbe5eaa12017-07-12 19:54:44 +053028static constexpr auto assetTagProp = "AssetTag";
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +030029static constexpr auto networkServiceName = "xyz.openbmc_project.Network";
Patrick Venture0b02be92018-08-31 11:55:55 -070030static constexpr auto networkConfigObj = "/xyz/openbmc_project/network/config";
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +030031static constexpr auto networkConfigIntf =
Patrick Venture0b02be92018-08-31 11:55:55 -070032 "xyz.openbmc_project.Network.SystemConfiguration";
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +030033static constexpr auto hostNameProp = "HostName";
Deepak Kodihalliee717d72018-01-24 04:53:09 -060034static constexpr auto temperatureSensorType = 0x01;
Vernon Mauerycce9ffd2023-07-27 14:15:17 -070035static constexpr size_t maxInstances = 255;
36static constexpr uint8_t maxRecords = 8;
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 Kodihalli0b459552018-02-06 06:25:12 -060056namespace sensor_info
57{
Deepak Kodihalli0b459552018-02-06 06:25:12 -060058
Patrick Venture0b02be92018-08-31 11:55:55 -070059/** @struct Response
60 *
61 * DCMI payload for Get Sensor Info response
62 */
63struct Response
64{
65 uint8_t recordIdLsb; //!< SDR record id LS byte
66 uint8_t recordIdMsb; //!< SDR record id MS byte
67} __attribute__((packed));
Deepak Kodihalli0b459552018-02-06 06:25:12 -060068
Patrick Venture0b02be92018-08-31 11:55:55 -070069using ResponseList = std::vector<Response>;
Deepak Kodihalli0b459552018-02-06 06:25:12 -060070} // namespace sensor_info
71
Tom Joseph6f6dd4d2017-07-12 20:07:11 +053072static constexpr auto groupExtId = 0xDC;
73
Kirill Pakhomov2c2af2c2018-11-06 16:06:10 +030074/** @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 */
79bool isDCMIPowerMgmtSupported();
80
Kirill Pakhomova2573622018-11-02 19:00:18 +030081/** @brief Parse out JSON config file.
82 *
83 * @param[in] configFile - JSON config file name
Deepak Kodihalli0b459552018-02-06 06:25:12 -060084 *
85 * @return A json object
86 */
Kirill Pakhomova2573622018-11-02 19:00:18 +030087Json parseJSONConfig(const std::string& configFile);
Deepak Kodihalli0b459552018-02-06 06:25:12 -060088
Deepak Kodihalli0b459552018-02-06 06:25:12 -060089namespace sensor_info
90{
Patrick Venture0b02be92018-08-31 11:55:55 -070091/** @brief Create response from JSON config.
92 *
93 * @param[in] config - JSON config info about DCMI sensors
94 *
95 * @return Sensor info response
96 */
97Response createFromJson(const Json& config);
Deepak Kodihallidd4cff12018-02-06 06:48:29 -060098
Patrick Venture0b02be92018-08-31 11:55:55 -070099/** @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 */
110std::tuple<Response, NumInstances> read(const std::string& type,
111 uint8_t instance, const Json& config);
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600112
Patrick Venture0b02be92018-08-31 11:55:55 -0700113/** @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 */
124std::tuple<ResponseList, NumInstances>
125 readAll(const std::string& type, uint8_t instanceStart, const Json& config);
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600126} // namespace sensor_info
127
Marri Devender Rao66c5fda2018-01-18 10:48:37 -0600128/** @brief Read power reading from power reading sensor object
129 *
130 * @param[in] bus - dbus connection
131 *
132 * @return total power reading
133 */
Patrick Williams5d82f472022-07-22 19:26:53 -0500134int64_t getPowerReading(sdbusplus::bus_t& bus);
Marri Devender Rao66c5fda2018-01-18 10:48:37 -0600135
136/** @struct GetPowerReadingRequest
137 *
138 * DCMI Get Power Reading command request.
139 * Refer DCMI specification Version 1.1 Section 6.6.1
140 */
141struct GetPowerReadingRequest
142{
Patrick Venture0b02be92018-08-31 11:55:55 -0700143 uint8_t mode; //!< Mode
144 uint8_t modeAttribute; //!< Mode Attributes
Marri Devender Rao66c5fda2018-01-18 10:48:37 -0600145} __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 */
152struct GetPowerReadingResponse
153{
Patrick Venture0b02be92018-08-31 11:55:55 -0700154 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 Rao66c5fda2018-01-18 10:48:37 -0600165} __attribute__((packed));
166
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600167/** @struct GetSensorInfoRequest
168 *
169 * DCMI payload for Get Sensor Info request
170 */
171struct GetSensorInfoRequest
172{
Patrick Venture0b02be92018-08-31 11:55:55 -0700173 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 Kodihalli0b459552018-02-06 06:25:12 -0600177} __attribute__((packed));
178
179/** @struct GetSensorInfoResponseHdr
180 *
181 * DCMI header for Get Sensor Info response
182 */
183struct GetSensorInfoResponseHdr
184{
Patrick Venture0b02be92018-08-31 11:55:55 -0700185 uint8_t numInstances; //!< No. of instances for requested id
186 uint8_t numRecords; //!< No. of record ids in the response
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600187} __attribute__((packed));
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600188/**
189 * @brief Parameters for DCMI Configuration Parameters
190 */
Patrick Venture0b02be92018-08-31 11:55:55 -0700191enum class DCMIConfigParameters : uint8_t
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600192{
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 */
205struct SetConfParamsRequest
206{
Patrick Venture0b02be92018-08-31 11:55:55 -0700207 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 Goruganti22be97b2018-02-07 01:19:59 -0600211} __attribute__((packed));
212
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600213/** @struct GetConfParamsRequest
214 *
215 * DCMI Get DCMI Configuration Parameters Command.
216 * Refer DCMI specification Version 1.1 Section 6.1.3
217 */
218struct GetConfParamsRequest
219{
Patrick Venture0b02be92018-08-31 11:55:55 -0700220 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 Goruganti22be97b2018-02-07 01:19:59 -0600224} __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 */
231struct GetConfParamsResponse
232{
Patrick Venture0b02be92018-08-31 11:55:55 -0700233 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 Goruganti22be97b2018-02-07 01:19:59 -0600237} __attribute__((packed));
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600238
Tom Josephbe5eaa12017-07-12 19:54:44 +0530239} // namespace dcmi