blob: f68142e973356ea9a54251f423447c59139606e6 [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>
25#include <variantvisitors.hpp>
26#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";
Vernon Mauerya3702c12019-05-22 13:20:59 -070040static constexpr const char* ledServicePrefix =
41 "xyz.openbmc_project.LED.Controller.";
42
43static constexpr const char* ledPathPrefix =
44 "/xyz/openbmc_project/led/physical/";
45static constexpr const char* fanPwmPath =
46 "/xyz/openbmc_project/sensors/fan_pwm/Pwm_";
Richard Marian Thomaiyar147daec2019-06-15 07:43:48 +053047static constexpr const char* fanTachBasePath =
48 "/xyz/openbmc_project/sensors/fan_tach/";
Vernon Mauerya3702c12019-05-22 13:20:59 -070049
50static constexpr const char* fanIntf = "xyz.openbmc_project.Sensor.Value";
Jason M. Bills38d2b5a2019-06-03 16:26:11 -070051static constexpr const char* buttonIntf = "xyz.openbmc_project.Chassis.Buttons";
Vernon Mauerya3702c12019-05-22 13:20:59 -070052static constexpr const char* ledIntf = "xyz.openbmc_project.Led.Physical";
53
54static constexpr const char* busPropertyIntf =
55 "org.freedesktop.DBus.Properties";
56static constexpr const char* ledStateStr =
57 "xyz.openbmc_project.Led.Physical.Action."; // Comes with postfix Off/On
Vernon Mauerya3702c12019-05-22 13:20:59 -070058
Richard Marian Thomaiyar666dd012019-08-02 20:55:37 +053059static constexpr const char* specialModeService =
60 "xyz.openbmc_project.SpecialMode";
61static constexpr const char* specialModeObjPath =
62 "/xyz/openbmc_project/security/special_mode";
63static constexpr const char* specialModeIntf =
64 "xyz.openbmc_project.Security.SpecialMode";
65
Vernon Mauerya3702c12019-05-22 13:20:59 -070066enum class SmActionGet : uint8_t
67{
68 sample = 0,
69 ignore = 1,
70 revert = 2
71};
72
73enum class SmActionSet : uint8_t
74{
75 forceDeasserted = 0,
76 forceAsserted = 1,
77 revert = 2
78};
79
80enum class SmSignalGet : uint8_t
81{
82 smPowerButton = 0,
83 smResetButton = 1,
84 smSleepButton,
Jason M. Bills38d2b5a2019-06-03 16:26:11 -070085 smNMIButton = 3,
Vernon Mauerya3702c12019-05-22 13:20:59 -070086 smChassisIntrusion = 4,
87 smPowerGood,
88 smPowerRequestGet,
89 smSleepRequestGet,
90 smFrbTimerHaltGet,
91 smForceUpdate,
92 smRingIndication,
93 smCarrierDetect,
94 smIdentifyButton = 0xc,
95 smFanPwmGet = 0xd,
96 smSignalReserved,
97 smFanTachometerGet = 0xf,
98 smNcsiDiag = 0x10,
Vernon Mauerya3702c12019-05-22 13:20:59 -070099 smGetSignalMax
100};
101
102enum class SmSignalSet : uint8_t
103{
104 smPowerLed = 0,
105 smPowerFaultLed,
106 smClusterLed,
107 smDiskFaultLed,
108 smCoolingFaultLed,
109 smFanPowerSpeed = 5,
110 smPowerRequestSet,
111 smSleepRequestSet,
112 smAcpiSci,
113 smSpeaker,
114 smFanPackFaultLed,
115 smCpuFailLed,
116 smDimmFailLed,
117 smIdentifyLed,
118 smHddLed,
119 smSystemReadyLed,
120 smLcdBacklight = 0x10,
121 smSetSignalMax
122};
123
124struct SetSmSignalReq
125{
126 SmSignalSet Signal;
127 uint8_t Instance;
128 SmActionSet Action;
129 uint8_t Value;
130};
131
Vernon Mauerya3702c12019-05-22 13:20:59 -0700132class LedProperty
133{
134 SmSignalSet signal;
135 std::string name;
136 std::string prevState;
137 std::string currentState;
138 bool isLocked;
139
140 public:
141 LedProperty(SmSignalSet signal_, std::string name_) :
142 signal(signal_), name(name_), prevState(""), isLocked(false)
143 {
144 }
145
146 LedProperty() = delete;
147
148 SmSignalSet getSignal() const
149 {
150 return signal;
151 }
152
153 void setLock(const bool& lock)
154 {
155 isLocked = lock;
156 }
157 void setPrevState(const std::string& state)
158 {
159 prevState = state;
160 }
161 void setCurrState(const std::string& state)
162 {
163 currentState = state;
164 }
165 std::string getCurrState() const
166 {
167 return currentState;
168 }
169 bool getLock() const
170 {
171 return isLocked;
172 }
173 std::string getPrevState() const
174 {
175 return prevState;
176 }
177 std::string getName() const
178 {
179 return name;
180 }
181};
182
183/** @class Manufacturing
184 *
185 * @brief Implemet commands to support Manufacturing Test Mode.
186 */
187class Manufacturing
188{
189 std::string path;
190 std::string gpioPaths[(uint8_t)SmSignalGet::smGetSignalMax];
191 std::vector<LedProperty> ledPropertyList;
192 void initData();
193
194 public:
195 Manufacturing();
196
197 ipmi_return_codes detectAccessLvl(ipmi_request_t request,
198 ipmi_data_len_t req_len);
199
200 LedProperty* findLedProperty(const SmSignalSet& signal)
201 {
202 auto it = std::find_if(ledPropertyList.begin(), ledPropertyList.end(),
203 [&signal](const LedProperty& led) {
204 return led.getSignal() == signal;
205 });
206 if (it != ledPropertyList.end())
207 {
208 return &(*it);
209 }
210 return nullptr;
211 }
212
213 std::string getLedPropertyName(const SmSignalSet signal)
214 {
215 LedProperty* led = findLedProperty(signal);
216 if (led != nullptr)
217 {
218 return led->getName();
219 }
220 else
221 {
222 return "";
223 }
224 }
225
Jason M. Bills38d2b5a2019-06-03 16:26:11 -0700226 int8_t getProperty(const std::string& service, const std::string& path,
227 const std::string& interface,
228 const std::string& propertyName, ipmi::Value* value);
229 int8_t setProperty(const std::string& service, const std::string& path,
230 const std::string& interface,
231 const std::string& propertyName, ipmi::Value value);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700232 int8_t disablePidControlService(const bool disable);
233
234 void revertTimerHandler();
235
Richard Marian Thomaiyar8d4f8d72019-11-11 12:06:40 +0530236 bool isMfgMode(void)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700237 {
Richard Marian Thomaiyar8d4f8d72019-11-11 12:06:40 +0530238 ipmi::Value mode;
239 if (getProperty(specialModeService, specialModeObjPath, specialModeIntf,
240 "SpecialMode", &mode) != 0)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700241 {
Richard Marian Thomaiyar8d4f8d72019-11-11 12:06:40 +0530242 return false;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700243 }
Richard Marian Thomaiyar8d4f8d72019-11-11 12:06:40 +0530244 if (std::get<std::string>(mode) ==
245 "xyz.openbmc_project.Control.Security.SpecialMode.Modes."
246 "Manufacturing")
247 {
248 return true;
249 }
250 return false;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700251 }
252
Vernon Mauerya3702c12019-05-22 13:20:59 -0700253 bool revertFanPWM = false;
254 bool revertLedCallback = false;
255 phosphor::Timer revertTimer;
Ayushi Smritid872a4a2019-10-15 10:20:11 +0530256 int mtmTestBeepFd = -1;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700257};
258
259} // namespace ipmi