summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/ipmi/phosphor-ipmi-host/0059-Move-Set-SOL-config-parameter-to-host-ipmid.patch
blob: 5623d246de5aa75fc23f0b60ee8642320319a1a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
From 55db62a92dff4bfc3d34c590b33d9da4e7706b9d Mon Sep 17 00:00:00 2001
From: Cheng C Yang <cheng.c.yang@intel.com>
Date: Wed, 3 Jul 2019 06:12:55 +0800
Subject: [PATCH] Move Set SOL config parameter to host-ipmid

Move Set SOL config parameter command from net-ipmid to host-ipmid,
so that BIOS in Intel platform can enable or disable SOL through KCS.
Get SOL config parameter command will be moved later.

Tested by:
With the related change in phospher-ipmi-net and phospher-dbus-interface,
Run commands:
ipmitool raw 0x0c 0x21 0x0e 0x00 0x01
ipmitool raw 0x0c 0x21 0x0e 0x01 0x00
ipmitool raw 0x0c 0x21 0x0e 0x02 0x03
ipmitool raw 0x0c 0x21 0x0e 0x03 0x5 0x03
ipmitool raw 0x0c 0x21 0x0e 0x04 0x5 0x03
All these commands have correct response and all dbus interface for
sol command change to same value in above commands.
After reboot BMC, "Progress" property in dbus interface change back
to 0 and other properties will not reset to default value.

Signed-off-by: Cheng C Yang <cheng.c.yang@intel.com>
---
 host-ipmid-whitelist.conf |   1 +
 transporthandler.cpp      | 289 ++++++++++++++++++++++++++++++++++++++++++++++
 transporthandler.hpp      |  33 ++++++
 3 files changed, 323 insertions(+)

diff --git a/host-ipmid-whitelist.conf b/host-ipmid-whitelist.conf
index 2b72d23..856588e 100644
--- a/host-ipmid-whitelist.conf
+++ b/host-ipmid-whitelist.conf
@@ -42,6 +42,7 @@
 0x0A:0x48    //<Storage>:<Get SEL Time>
 0x0A:0x49    //<Storage>:<Set SEL Time>
 0x0C:0x02    //<Transport>:<Get LAN Configuration Parameters>
+0x0C:0x21    //<Transport>:<Set SOL Configuration Parameters>
 0x2C:0x00    //<Group Extension>:<Group Extension Command>
 0x2C:0x01    //<Group Extension>:<Get DCMI Capabilities>
 0x2C:0x02    //<Group Extension>:<Get Power Reading>
diff --git a/transporthandler.cpp b/transporthandler.cpp
index bb624c4..25062ae 100644
--- a/transporthandler.cpp
+++ b/transporthandler.cpp
@@ -36,6 +36,9 @@ static const std::array<std::string, 3> ipAddressEnablesType = {
     "xyz.openbmc_project.Network.EthernetInterface.IPAllowed.IPv6Only",
     "xyz.openbmc_project.Network.EthernetInterface.IPAllowed.IPv4AndIPv6"};
 
+constexpr const char* solInterface = "xyz.openbmc_project.Ipmi.SOL";
+constexpr const char* solPath = "/xyz/openbmc_project/ipmi/sol/";
+
 std::map<int, std::unique_ptr<struct ChannelConfig_t>> channelConfig;
 
 using namespace phosphor::logging;
@@ -1631,6 +1634,285 @@ void createNetworkTimer()
     }
 }
 
+static std::string
+    getSOLService(std::shared_ptr<sdbusplus::asio::connection> dbus,
+                  const std::string& solPathWitheEthName)
+{
+    static std::string solService{};
+    if (solService.empty())
+    {
+        try
+        {
+            solService =
+                ipmi::getService(*dbus, solInterface, solPathWitheEthName);
+        }
+        catch (const sdbusplus::exception::SdBusError& e)
+        {
+            solService.clear();
+            phosphor::logging::log<phosphor::logging::level::ERR>(
+                "Error: get SOL service failed");
+            return solService;
+        }
+    }
+    return solService;
+}
+
+static int setSOLParameter(const std::string& property,
+                           const ipmi::Value& value, const uint8_t& channelNum)
+{
+    auto dbus = getSdBus();
+
+    std::string ethdevice = ipmi::getChannelName(channelNum);
+
+    std::string solPathWitheEthName = std::string(solPath) + ethdevice;
+
+    std::string service = getSOLService(dbus, solPathWitheEthName);
+    if (service.empty())
+    {
+        phosphor::logging::log<phosphor::logging::level::ERR>(
+            "Unable to get SOL service failed");
+        return -1;
+    }
+    try
+    {
+        ipmi::setDbusProperty(*dbus, service, solPathWitheEthName, solInterface,
+                              property, value);
+    }
+    catch (sdbusplus::exception_t&)
+    {
+        phosphor::logging::log<phosphor::logging::level::ERR>(
+            "Error setting sol parameter");
+        return -1;
+    }
+
+    return 0;
+}
+
+static int getSOLParameter(const std::string& property, ipmi::Value& value,
+                           const uint8_t& channelNum)
+{
+    auto dbus = getSdBus();
+
+    std::string ethdevice = ipmi::getChannelName(channelNum);
+
+    std::string solPathWitheEthName = std::string(solPath) + ethdevice;
+
+    std::string service = getSOLService(dbus, solPathWitheEthName);
+    if (service.empty())
+    {
+        phosphor::logging::log<phosphor::logging::level::ERR>(
+            "Unable to get SOL service failed");
+        return -1;
+    }
+    try
+    {
+        value = ipmi::getDbusProperty(*dbus, service, solPathWitheEthName,
+                                      solInterface, property);
+    }
+    catch (sdbusplus::exception_t&)
+    {
+        phosphor::logging::log<phosphor::logging::level::ERR>(
+            "Error getting sol parameter");
+        return -1;
+    }
+
+    return 0;
+}
+
+void initializeSOLInProgress()
+{
+    ipmi::ChannelInfo chInfo;
+    for (int chNum = 0; chNum < ipmi::maxIpmiChannels; chNum++)
+    {
+        if (!ipmi::isValidChannel(static_cast<uint8_t>(chNum)))
+        {
+            continue;
+        }
+        ipmi_ret_t compCode =
+            ipmi::getChannelInfo(static_cast<uint8_t>(chNum), chInfo);
+        if (compCode != IPMI_CC_OK ||
+            chInfo.mediumType !=
+                static_cast<uint8_t>(ipmi::EChannelMediumType::lan8032))
+        {
+            continue;
+        }
+        if (setSOLParameter("Progress", static_cast<uint8_t>(0), chNum) < 0)
+        {
+            phosphor::logging::log<phosphor::logging::level::ERR>(
+                "Error initialize sol progress");
+        }
+    }
+}
+
+static const constexpr uint8_t encryptMask = 0x80;
+static const constexpr uint8_t encryptShift = 7;
+static const constexpr uint8_t authMask = 0x40;
+static const constexpr uint8_t authShift = 6;
+static const constexpr uint8_t privilegeMask = 0xf;
+
+namespace ipmi
+{
+constexpr Cc ccParmNotSupported = 0x80;
+constexpr Cc ccSetInProgressActive = 0x81;
+constexpr Cc ccSystemInfoParameterSetReadOnly = 0x82;
+
+static inline auto responseParmNotSupported()
+{
+    return response(ccParmNotSupported);
+}
+static inline auto responseSetInProgressActive()
+{
+    return response(ccSetInProgressActive);
+}
+static inline auto responseSystemInfoParameterSetReadOnly()
+{
+    return response(ccSystemInfoParameterSetReadOnly);
+}
+
+} // namespace ipmi
+
+ipmi::RspType<> setSOLConfParams(ipmi::Context::ptr ctx, uint4_t chNum,
+                                 uint4_t reserved, uint8_t paramSelector,
+                                 uint8_t configParamData1,
+                                 std::optional<uint8_t> configParamData2)
+{
+    ipmi::ChannelInfo chInfo;
+    uint8_t channelNum = ipmi::convertCurrentChannelNum(
+        static_cast<uint8_t>(chNum), ctx->channel);
+    if (reserved != 0 ||
+        (!ipmi::isValidChannel(static_cast<uint8_t>(channelNum))))
+    {
+        return ipmi::responseInvalidFieldRequest();
+    }
+
+    ipmi_ret_t compCode =
+        ipmi::getChannelInfo(static_cast<uint8_t>(channelNum), chInfo);
+    if (compCode != IPMI_CC_OK ||
+        chInfo.mediumType !=
+            static_cast<uint8_t>(ipmi::EChannelMediumType::lan8032))
+    {
+        return ipmi::responseInvalidFieldRequest();
+    }
+
+    switch (static_cast<sol::Parameter>(paramSelector))
+    {
+        case sol::Parameter::progress:
+        {
+            if (configParamData2)
+            {
+                return ipmi::responseReqDataLenInvalid();
+            }
+            uint8_t progress = configParamData1 & progressMask;
+            ipmi::Value currentProgress = 0;
+            if (getSOLParameter("Progress", currentProgress, channelNum) < 0)
+            {
+                return ipmi::responseUnspecifiedError();
+            }
+
+            if ((std::get<uint8_t>(currentProgress) == 1) && (progress == 1))
+            {
+                return ipmi::responseSetInProgressActive();
+            }
+
+            if (setSOLParameter("Progress", progress, channelNum) < 0)
+            {
+                return ipmi::responseUnspecifiedError();
+            }
+            break;
+        }
+        case sol::Parameter::enable:
+        {
+            if (configParamData2)
+            {
+                return ipmi::responseReqDataLenInvalid();
+            }
+            bool enable = configParamData1 & enableMask;
+            if (setSOLParameter("Enable", enable, channelNum) < 0)
+            {
+                return ipmi::responseUnspecifiedError();
+            }
+            break;
+        }
+        case sol::Parameter::authentication:
+        {
+            if (configParamData2)
+            {
+                return ipmi::responseReqDataLenInvalid();
+            }
+            uint8_t encrypt = (configParamData1 & encryptMask) >> encryptShift;
+            uint8_t auth = (configParamData1 & authMask) >> authShift;
+            uint8_t privilege = configParamData1 & privilegeMask;
+            // For security considering encryption and authentication must be
+            // true.
+            if (!encrypt || !auth)
+            {
+                return ipmi::responseSystemInfoParameterSetReadOnly();
+            }
+            else if (privilege <
+                         static_cast<uint8_t>(sol::Privilege::userPriv) ||
+                     privilege > static_cast<uint8_t>(sol::Privilege::oemPriv))
+            {
+                return ipmi::responseInvalidFieldRequest();
+            }
+
+            if (setSOLParameter("Privilege", privilege, channelNum) < 0)
+            {
+                return ipmi::responseUnspecifiedError();
+            }
+
+            break;
+        }
+        case sol::Parameter::accumulate:
+        {
+            if (!configParamData2)
+            {
+                return ipmi::responseReqDataLenInvalid();
+            }
+            if (*configParamData2 == 0)
+            {
+                return ipmi::responseInvalidFieldRequest();
+            }
+            if (setSOLParameter("AccumulateIntervalMS", configParamData1,
+                                channelNum) < 0)
+            {
+                return ipmi::responseUnspecifiedError();
+            }
+            if (setSOLParameter("Threshold", *configParamData2, channelNum) < 0)
+            {
+                return ipmi::responseUnspecifiedError();
+            }
+            break;
+        }
+        case sol::Parameter::retry:
+        {
+            if (!configParamData2)
+            {
+                return ipmi::responseReqDataLenInvalid();
+            }
+            if ((setSOLParameter("RetryCount", (configParamData1 & 0x7),
+                                 channelNum) < 0) ||
+                (setSOLParameter("RetryIntervalMS", *configParamData2,
+                                 channelNum) < 0))
+            {
+                return ipmi::responseUnspecifiedError();
+            }
+
+            break;
+        }
+        case sol::Parameter::port:
+        {
+            return ipmi::responseSystemInfoParameterSetReadOnly();
+        }
+        case sol::Parameter::nvbitrate:
+        case sol::Parameter::vbitrate:
+        case sol::Parameter::channel:
+        default:
+            return ipmi::responseParmNotSupported();
+    }
+
+    return ipmi::responseSuccess();
+}
+
 void register_netfn_transport_functions()
 {
     // As this timer is only for transport handler
@@ -1648,5 +1930,12 @@ void register_netfn_transport_functions()
     ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_GET_LAN, NULL,
                            ipmi_transport_get_lan, PRIVILEGE_OPERATOR);
 
+    ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnTransport,
+                          ipmi::transport::cmdSetSolConfigParameters,
+                          ipmi::Privilege::Admin, setSOLConfParams);
+
+    // Initialize dbus property progress to 0 every time sol manager restart.
+    initializeSOLInProgress();
+
     return;
 }
diff --git a/transporthandler.hpp b/transporthandler.hpp
index bd23391..1237658 100644
--- a/transporthandler.hpp
+++ b/transporthandler.hpp
@@ -1,5 +1,6 @@
 #pragma once
 
+#include <ipmid/api-types.hpp>
 #include <ipmid/types.hpp>
 #include <string>
 // IPMI commands for Transport net functions.
@@ -8,6 +9,8 @@ enum ipmi_netfn_storage_cmds
     // Get capability bits
     IPMI_CMD_SET_LAN = 0x01,
     IPMI_CMD_GET_LAN = 0x02,
+    IPMI_CMD_SET_SOL_CONF_PARAMS = 0x21,
+    IPMI_CMD_GET_SOL_CONF_PARAMS = 0x22,
 };
 
 // Command specific completion codes
@@ -186,3 +189,33 @@ void commitNetworkChanges();
  * @param[in] channel: channel number.
  */
 void applyChanges(int channel);
+
+namespace sol
+{
+enum class Parameter
+{
+    progress,       //!< Set In Progress.
+    enable,         //!< SOL Enable.
+    authentication, //!< SOL Authentication.
+    accumulate,     //!< Character Accumulate Interval & Send Threshold.
+    retry,          //!< SOL Retry.
+    nvbitrate,      //!< SOL non-volatile bit rate.
+    vbitrate,       //!< SOL volatile bit rate.
+    channel,        //!< SOL payload channel.
+    port,           //!< SOL payload port.
+};
+
+enum class Privilege : uint8_t
+{
+    highestPriv,
+    callbackPriv,
+    userPriv,
+    operatorPriv,
+    adminPriv,
+    oemPriv,
+};
+
+} // namespace sol
+
+constexpr uint8_t progressMask = 0x03;
+constexpr uint8_t enableMask = 0x01;
-- 
2.7.4