blob: a4c2924464e0ffe8cf00810e9b63fb4160fa8b84 [file] [log] [blame]
Vernon Mauerya3702c12019-05-22 13:20:59 -07001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16
17#pragma once
18
19#include <ipmid/api-types.hpp>
20#include <ipmid/utils.hpp>
21#include <phosphor-logging/log.hpp>
22#include <sdbusplus/bus.hpp>
23#include <sdbusplus/message.hpp>
24#include <sdbusplus/timer.hpp>
James Feistfcd2d3a2020-05-28 10:38:15 -070025
Vernon Mauerya3702c12019-05-22 13:20:59 -070026#include <vector>
27
28#define FAN_SENSOR_NOT_PRESENT (0 << 0)
29#define FAN_SENSOR_PRESENT (1 << 0)
30#define FAN_NOT_PRESENT (0 << 1)
31#define FAN_PRESENT (1 << 1)
32
33namespace ipmi
34{
35
36// TODO: Service names may change. Worth to consider dynamic detection.
37static constexpr const char* fanService = "xyz.openbmc_project.FanSensor";
Jason M. Bills38d2b5a2019-06-03 16:26:11 -070038static constexpr const char* buttonService =
39 "xyz.openbmc_project.Chassis.Buttons";
Jayaprakash Mutyalafc5c80e2024-10-18 07:07:46 +000040static constexpr const char* ledService = "xyz.openbmc_project.LED.Controller";
Vernon Mauerya3702c12019-05-22 13:20:59 -070041
42static constexpr const char* ledPathPrefix =
43 "/xyz/openbmc_project/led/physical/";
44static constexpr const char* fanPwmPath =
Alex Schendel90eb7872022-09-01 11:56:52 -070045 "/xyz/openbmc_project/sensors/fan_pwm/";
Richard Marian Thomaiyar147daec2019-06-15 07:43:48 +053046static constexpr const char* fanTachBasePath =
47 "/xyz/openbmc_project/sensors/fan_tach/";
Vernon Mauerya3702c12019-05-22 13:20:59 -070048
49static constexpr const char* fanIntf = "xyz.openbmc_project.Sensor.Value";
Jason M. Bills38d2b5a2019-06-03 16:26:11 -070050static constexpr const char* buttonIntf = "xyz.openbmc_project.Chassis.Buttons";
Vernon Mauerya3702c12019-05-22 13:20:59 -070051static constexpr const char* ledIntf = "xyz.openbmc_project.Led.Physical";
52
anil kumar appana98705b32019-09-11 14:15:50 +000053static constexpr const char* intrusionService =
54 "xyz.openbmc_project.IntrusionSensor";
55static constexpr const char* intrusionPath =
56 "/xyz/openbmc_project/Intrusion/Chassis_Intrusion";
57static constexpr const char* intrusionIntf =
58 "xyz.openbmc_project.Chassis.Intrusion";
59
Vernon Mauerya3702c12019-05-22 13:20:59 -070060static constexpr const char* busPropertyIntf =
61 "org.freedesktop.DBus.Properties";
62static constexpr const char* ledStateStr =
63 "xyz.openbmc_project.Led.Physical.Action."; // Comes with postfix Off/On
Vernon Mauerya3702c12019-05-22 13:20:59 -070064
Richard Marian Thomaiyar666dd012019-08-02 20:55:37 +053065static constexpr const char* specialModeService =
66 "xyz.openbmc_project.SpecialMode";
67static constexpr const char* specialModeObjPath =
68 "/xyz/openbmc_project/security/special_mode";
69static constexpr const char* specialModeIntf =
70 "xyz.openbmc_project.Security.SpecialMode";
71
Vasu V97c30902023-05-19 15:56:15 +053072static constexpr const char* mctpPcieSlotService =
73 "xyz.openbmc_project.MCTP_SMBus_PCIe_slot";
74static constexpr const char* mctpHsbpService =
75 "xyz.openbmc_project.MCTP_SMBus_HSBP";
76static constexpr const char* mctpObjPath = "/xyz/openbmc_project/mctp";
77static constexpr const char* mctpBaseIntf = "xyz.openbmc_project.MCTP.Base";
78
79constexpr const uint8_t slotNumMask = 0x0F;
80constexpr const uint8_t muxTypeMask = 0xF0;
81constexpr const uint8_t muxTypeShift = 4;
82
Richard Marian Thomaiyarae13ac62019-12-17 15:45:12 +053083enum class SpecialMode : uint8_t
84{
85 none = 0,
86 mfg = 1,
87#ifdef BMC_VALIDATION_UNSECURE_FEATURE
88 valUnsecure = 2
89#endif
90};
91
Vernon Mauerya3702c12019-05-22 13:20:59 -070092enum class SmActionGet : uint8_t
93{
94 sample = 0,
95 ignore = 1,
96 revert = 2
97};
98
99enum class SmActionSet : uint8_t
100{
101 forceDeasserted = 0,
102 forceAsserted = 1,
103 revert = 2
104};
105
106enum class SmSignalGet : uint8_t
107{
108 smPowerButton = 0,
109 smResetButton = 1,
110 smSleepButton,
Jason M. Bills38d2b5a2019-06-03 16:26:11 -0700111 smNMIButton = 3,
Vernon Mauerya3702c12019-05-22 13:20:59 -0700112 smChassisIntrusion = 4,
113 smPowerGood,
114 smPowerRequestGet,
115 smSleepRequestGet,
116 smFrbTimerHaltGet,
117 smForceUpdate,
118 smRingIndication,
119 smCarrierDetect,
120 smIdentifyButton = 0xc,
121 smFanPwmGet = 0xd,
122 smSignalReserved,
123 smFanTachometerGet = 0xf,
124 smNcsiDiag = 0x10,
Vernon Mauerya3702c12019-05-22 13:20:59 -0700125 smGetSignalMax
126};
127
128enum class SmSignalSet : uint8_t
129{
130 smPowerLed = 0,
131 smPowerFaultLed,
132 smClusterLed,
133 smDiskFaultLed,
134 smCoolingFaultLed,
135 smFanPowerSpeed = 5,
136 smPowerRequestSet,
137 smSleepRequestSet,
138 smAcpiSci,
139 smSpeaker,
140 smFanPackFaultLed,
141 smCpuFailLed,
142 smDimmFailLed,
143 smIdentifyLed,
144 smHddLed,
145 smSystemReadyLed,
146 smLcdBacklight = 0x10,
147 smSetSignalMax
148};
149
anil kumar appana98705b32019-09-11 14:15:50 +0000150/** @enum IntrusionStatus
151.*
152 * Intrusion Status
153 */
154enum class IntrusionStatus : uint8_t
155{
156 normal = 0,
157 hardwareIntrusion,
158 tamperingDetected
159};
160
Arun P. Mohanan06584cd2021-08-13 20:56:01 +0530161enum SupportedFeatureControls : uint8_t
162{
163 mctp = 0,
Jason M. Bills5cb2c042021-08-17 12:03:39 -0700164 pcieScan,
Vasu V97c30902023-05-19 15:56:15 +0530165 mctpSlotSupport
166};
167
168enum SupportedFeatureMuxs : uint8_t
169{
170 pcieMuxSlot = 0,
171 pcieMcioMuxSlot,
172 pcieM2EdSffMuxSlot,
173 leftRaiserMuxSlot,
174 rightRaiserMuxSlot,
175 HsbpMuxSlot
Arun P. Mohanan06584cd2021-08-13 20:56:01 +0530176};
177
178enum SupportedFeatureActions : uint8_t
179{
180 stop = 0,
181 start,
182 disable,
183 enable,
184};
185
186enum SupportedMCTPBindings : uint8_t
187{
188 mctpPCIe = 0,
189 mctpSMBusHSBP,
190 mctpSMBusPCIeSlot
191};
192
Vernon Mauerya3702c12019-05-22 13:20:59 -0700193struct SetSmSignalReq
194{
195 SmSignalSet Signal;
196 uint8_t Instance;
197 SmActionSet Action;
198 uint8_t Value;
199};
200
Vernon Mauerya3702c12019-05-22 13:20:59 -0700201class LedProperty
202{
203 SmSignalSet signal;
204 std::string name;
205 std::string prevState;
206 std::string currentState;
207 bool isLocked;
208
209 public:
210 LedProperty(SmSignalSet signal_, std::string name_) :
211 signal(signal_), name(name_), prevState(""), isLocked(false)
James Feistfcd2d3a2020-05-28 10:38:15 -0700212 {}
Vernon Mauerya3702c12019-05-22 13:20:59 -0700213
214 LedProperty() = delete;
215
216 SmSignalSet getSignal() const
217 {
218 return signal;
219 }
220
221 void setLock(const bool& lock)
222 {
223 isLocked = lock;
224 }
225 void setPrevState(const std::string& state)
226 {
227 prevState = state;
228 }
229 void setCurrState(const std::string& state)
230 {
231 currentState = state;
232 }
233 std::string getCurrState() const
234 {
235 return currentState;
236 }
237 bool getLock() const
238 {
239 return isLocked;
240 }
241 std::string getPrevState() const
242 {
243 return prevState;
244 }
245 std::string getName() const
246 {
247 return name;
248 }
249};
250
251/** @class Manufacturing
252 *
253 * @brief Implemet commands to support Manufacturing Test Mode.
254 */
255class Manufacturing
256{
257 std::string path;
258 std::string gpioPaths[(uint8_t)SmSignalGet::smGetSignalMax];
259 std::vector<LedProperty> ledPropertyList;
260 void initData();
261
262 public:
263 Manufacturing();
264
265 ipmi_return_codes detectAccessLvl(ipmi_request_t request,
266 ipmi_data_len_t req_len);
267
268 LedProperty* findLedProperty(const SmSignalSet& signal)
269 {
270 auto it = std::find_if(ledPropertyList.begin(), ledPropertyList.end(),
271 [&signal](const LedProperty& led) {
Patrick Williams1bcced02024-08-16 15:20:24 -0400272 return led.getSignal() == signal;
273 });
Vernon Mauerya3702c12019-05-22 13:20:59 -0700274 if (it != ledPropertyList.end())
275 {
276 return &(*it);
277 }
278 return nullptr;
279 }
280
281 std::string getLedPropertyName(const SmSignalSet signal)
282 {
283 LedProperty* led = findLedProperty(signal);
284 if (led != nullptr)
285 {
286 return led->getName();
287 }
288 else
289 {
290 return "";
291 }
292 }
293
Jason M. Bills38d2b5a2019-06-03 16:26:11 -0700294 int8_t getProperty(const std::string& service, const std::string& path,
295 const std::string& interface,
296 const std::string& propertyName, ipmi::Value* value);
297 int8_t setProperty(const std::string& service, const std::string& path,
298 const std::string& interface,
299 const std::string& propertyName, ipmi::Value value);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700300 int8_t disablePidControlService(const bool disable);
301
302 void revertTimerHandler();
303
Richard Marian Thomaiyarae13ac62019-12-17 15:45:12 +0530304 SpecialMode getMfgMode(void)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700305 {
Richard Marian Thomaiyar8d4f8d72019-11-11 12:06:40 +0530306 ipmi::Value mode;
307 if (getProperty(specialModeService, specialModeObjPath, specialModeIntf,
308 "SpecialMode", &mode) != 0)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700309 {
Richard Marian Thomaiyarae13ac62019-12-17 15:45:12 +0530310 return SpecialMode::none;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700311 }
Richard Marian Thomaiyar8d4f8d72019-11-11 12:06:40 +0530312 if (std::get<std::string>(mode) ==
313 "xyz.openbmc_project.Control.Security.SpecialMode.Modes."
314 "Manufacturing")
315 {
Richard Marian Thomaiyarae13ac62019-12-17 15:45:12 +0530316 return SpecialMode::mfg;
Richard Marian Thomaiyar8d4f8d72019-11-11 12:06:40 +0530317 }
Richard Marian Thomaiyar99d7d352019-11-11 12:11:35 +0530318#ifdef BMC_VALIDATION_UNSECURE_FEATURE
319 if (std::get<std::string>(mode) ==
320 "xyz.openbmc_project.Control.Security.SpecialMode.Modes."
321 "ValidationUnsecure")
322 {
Richard Marian Thomaiyarae13ac62019-12-17 15:45:12 +0530323 return SpecialMode::valUnsecure;
Richard Marian Thomaiyar99d7d352019-11-11 12:11:35 +0530324 }
325#endif
Richard Marian Thomaiyarae13ac62019-12-17 15:45:12 +0530326 return SpecialMode::none;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700327 }
328
Vernon Mauerya3702c12019-05-22 13:20:59 -0700329 bool revertFanPWM = false;
330 bool revertLedCallback = false;
Patrick Williamsf0feb492023-12-05 12:45:02 -0600331 sdbusplus::Timer revertTimer;
Ayushi Smritid872a4a2019-10-15 10:20:11 +0530332 int mtmTestBeepFd = -1;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700333};
334
335} // namespace ipmi