This repository has been archived by the owner on Oct 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
NodeManagerProxy.hpp
1589 lines (1414 loc) · 50.5 KB
/
NodeManagerProxy.hpp
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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright 2018, 2021 Intel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <boost/container/flat_set.hpp>
#include <phosphor-logging/log.hpp>
#include <sdbusplus/asio/object_server.hpp>
#include <string>
#ifndef NODEMANAGERPROXY_HPP
#define NODEMANAGERPROXY_HPP
/**
* @brief Dbus
*/
constexpr const char *nmdBus = "xyz.openbmc_project.NodeManagerProxy";
constexpr const char *nmdObj = "/xyz/openbmc_project/NodeManagerProxy";
constexpr const char *propObj = "/xyz/openbmc_project/sensors/";
constexpr const char *nmdSensorIntf = "xyz.openbmc_project.Sensor.Value";
constexpr const char *nmdPowerCapIntf = "xyz.openbmc_project.Control.Power.Cap";
constexpr const char *nmdPowerMetricIntf =
"xyz.openbmc_project.Power.PowerMetric";
constexpr const char *meSoftwareObjPath = "/xyz/openbmc_project/software/me";
constexpr const char *softwareVerIntf = "xyz.openbmc_project.Software.Version";
constexpr const char *softwareActivationIntf =
"xyz.openbmc_project.Software.Activation";
constexpr const char *ipmbBus = "xyz.openbmc_project.Ipmi.Channel.Ipmb";
constexpr const char *ipmbObj = "/xyz/openbmc_project/Ipmi/Channel/Ipmb";
constexpr const char *ipmbIntf = "org.openbmc.Ipmb";
constexpr const char *sensorConfPath =
"xyz.openbmc_project.Configuration.NMSensor";
constexpr const char *sensorName = "Node_Manager_Sensor";
constexpr const char *associationInterface =
"xyz.openbmc_project.Association.Definitions";
// this currently can be anything as it's only used to set the LED, might be
// good later to change it for redfish, but I'm not sure to what today
constexpr const char *meStatusPath = "/xyz/openbmc_project/status/me";
constexpr const sdbusplus::SdBusDuration kIpmbTimeout =
sdbusplus::SdBusDuration{1000000};
using Association = std::tuple<std::string, std::string, std::string>;
namespace power
{
const static constexpr char *busname = "xyz.openbmc_project.State.Host";
const static constexpr char *interface = "xyz.openbmc_project.State.Host";
const static constexpr char *path = "/xyz/openbmc_project/state/host0";
const static constexpr char *property = "CurrentHostState";
} // namespace power
/**
* @brief NMd defines
*/
constexpr uint32_t readingsInterval = 10; // seconds
constexpr uint32_t framesInterval =
100; // msec - number of frames per reading * framesInterval should be 2x
// less than readingsInterval
/**
* @brief Ipmb defines
*/
constexpr uint8_t ipmbMeChannelNum = 1;
/**
* @brief Ipmi defines
*/
constexpr uint32_t ipmiIanaIntel = 0x157;
typedef struct
{
uint8_t b0;
uint8_t b1;
uint8_t b2;
} __attribute__((packed)) ipmiIana;
static_assert(sizeof(ipmiIana) == 3);
constexpr void ipmiSetIntelIanaNumber(ipmiIana &iana)
{
iana.b0 = static_cast<uint8_t>(ipmiIanaIntel & 0xFF);
iana.b1 = static_cast<uint8_t>((ipmiIanaIntel >> 8) & 0xFF);
iana.b2 = static_cast<uint8_t>((ipmiIanaIntel >> 16) & 0xFF);
}
/**
* @brief Get Node Manager Statistics defines
*/
constexpr uint8_t ipmiGetNmStatisticsNetFn = 0x2E;
constexpr uint8_t ipmiGetNmStatisticsLun = 0;
constexpr uint8_t ipmiGetNmStatisticsCmd = 0xC8;
/**
* @brief Set Node Manager Policy defines
*/
constexpr uint8_t ipmiSetNmPolicyNetFn = 0x2E;
constexpr uint8_t ipmiSetNmPolicyLun = 0;
constexpr uint8_t ipmiSetNmPolicyCmd = 0xC1;
/**
* @brief Get Node Manager Policy defines
*/
constexpr uint8_t ipmiGetNmPolicyNetFn = 0x2E;
constexpr uint8_t ipmiGetNmPolicyLun = 0;
constexpr uint8_t ipmiGetNmPolicyCmd = 0xC2;
/**
* @brief Get Node Manager Capabilites defines
*/
constexpr uint8_t ipmiGetNmCapabilitesNetFn = 0x2E;
constexpr uint8_t ipmiGetNmCapabilitesLun = 0;
constexpr uint8_t ipmiGetNmCapabilitesCmd = 0xC9;
// Mode
constexpr uint8_t globalPowerStats = 0x1;
constexpr uint8_t globalInletTempStats = 0x2;
constexpr uint8_t globalThrottlingStats = 0x3;
constexpr uint8_t globalVolAirflowStats = 0x4;
constexpr uint8_t globalOutletAirflowTempStats = 0x5;
constexpr uint8_t globalChassisPowerStats = 0x6;
constexpr uint8_t policyPowerStats = 0x11;
constexpr uint8_t globalHostUnhandleReqStats = 0x1B;
constexpr uint8_t globalHostResponseTimeStats = 0x1C;
constexpr uint8_t globalHostCommFailureStats = 0x1F;
// Domain Id
constexpr uint8_t entirePlatform = 0x0;
constexpr uint8_t cpuSubsystem = 0x1;
constexpr uint8_t memorySubsystem = 0x2;
constexpr uint8_t hwProtection = 0x3;
constexpr uint8_t highPowerIOsubsystem = 0x4;
constexpr uint8_t dcTotal = 0x5;
/**
* @brief Get Device ID defines
*/
constexpr uint8_t ipmiGetDevIdNetFn = 0x6;
constexpr uint8_t ipmiGetDevIdLun = 0;
constexpr uint8_t ipmiGetDevIdCmd = 0x1;
/**
* @brief Part of Get Device ID Command Response Payload
*/
typedef struct
{
uint8_t fwMajorRev : 7, // Binary encoded Major Version
inUpgrade : 1; // In Upgrade State
uint8_t fwHotfixRev : 4, // BCD encoded Hotfix Version
fwMinorRev : 4; // BCD encoded Minor Version
} __attribute__((packed)) ipmiFwVerMajorMinor;
/**
* @brief Part of Get Device ID Command Response Payload - Auxiliary
* Firmware Revision Information
*/
typedef struct
{
uint8_t nmVersion : 4, // Node Manager Version
dcmiVersion : 4; // DCMI Version
uint8_t b : 4, // BCD encoded Build Number - tens
a : 4, // BCD encoded Build Number - hundreds
patch : 4, // BCD encoded Patch Number
c : 4; // BCD encoded Build Number - digits
uint8_t imageFlags;
} __attribute__((packed)) ipmiFwVerAux;
/**
* @brief Get Device ID Command Full Response Payload
*/
typedef struct
{
uint8_t deviceId; // Device ID
uint8_t deviceRev : 4, // Device Revision
reserved0 : 3, // Reserved bits
sdrPresent : 1; // SDR State
ipmiFwVerMajorMinor fwMajorMinor; // Major and Minor Version
uint8_t ipmiVersion; // BCD encoded IPMI Version, reversed digit order
uint8_t featureMask; // Bitmask of supported features
ipmiIana ianaId; // Manufacturers ID
uint8_t prodIdMinor; // Product ID Minor Version
uint8_t prodIdMajor; // Product ID Major Version
ipmiFwVerAux fwVerAux; // NmVersion, Build Number etc.
} __attribute__((packed)) ipmiGetDeviceIdResp;
/**
* @brief Get Node Manager Statistics request format
*/
typedef struct
{
ipmiIana iana;
uint8_t mode : 5, reserved3B : 3;
uint8_t domainId : 4, statsSide : 1, reserved : 2, perComponent : 1;
union
{
uint8_t policyId;
uint8_t componentId;
};
} __attribute__((packed)) nmIpmiGetNmStatisticsReq;
static_assert(sizeof(nmIpmiGetNmStatisticsReq) == 6);
/**
* @brief Get Node Manager Statistics response format
*/
typedef struct
{
ipmiIana iana;
union
{
struct
{
uint16_t cur;
uint16_t min;
uint16_t max;
uint16_t avg;
} stats;
uint64_t energyAccumulator;
} data;
uint32_t timeStamp;
uint32_t statsReportPeriod;
uint8_t domainId : 4, policyGlobalState : 1, policyOperationalState : 1,
measurmentsState : 1, policyActivationState : 1;
} __attribute__((packed)) nmIpmiGetNmStatisticsResp;
static_assert(sizeof(nmIpmiGetNmStatisticsResp) == 20);
/**
* @brief Set Node Manager Policy request format
*/
typedef struct
{
ipmiIana iana;
uint8_t domainId : 4, policyEnabled : 1, reservedByte4 : 3;
uint8_t policyId;
uint8_t triggerType : 4, configurationAction : 1, cpuPowerCorrection : 2,
storageOption : 1;
uint8_t sendAlert : 1, shutdownSystem : 1, reservedByte7 : 6;
int16_t limit;
uint32_t correctionTime;
uint16_t triggerLimit;
uint16_t statsPeriod;
} __attribute__((packed)) nmIpmiSetNmPolicyReq;
static_assert(sizeof(nmIpmiSetNmPolicyReq) == 17);
/**
* @brief Set Node Manager Policy response format
*/
typedef struct
{
ipmiIana iana;
} __attribute__((packed)) nmIpmiSetNmPolicyResp;
static_assert(sizeof(nmIpmiSetNmPolicyResp) == 3);
/**
* @brief Get Node Manager Policy request format
*/
typedef struct
{
ipmiIana iana;
uint8_t domainId : 4, reserved0 : 4;
uint8_t policyId;
} __attribute__((packed)) nmIpmiGetNmPolicyReq;
static_assert(sizeof(nmIpmiGetNmPolicyReq) == 5);
/**
* @brief Get Node Manager Policy response format
*/
typedef struct
{
ipmiIana iana;
uint8_t domainId : 4, policyEnabled : 1, domainEnabled : 1,
globalEnabled : 1, external : 1;
uint8_t triggerType : 4, policyType : 1, cpuPowerCorrection : 2,
storageOption : 1;
uint8_t sendAlert : 1, shutdownSystem : 1, reserved0 : 6;
int16_t limit;
uint32_t correctionTime;
uint16_t triggerLimit;
uint16_t statsPeriod;
} __attribute__((packed)) nmIpmiGetNmPolicyResp;
static_assert(sizeof(nmIpmiGetNmPolicyResp) == 16);
/**
* @brief Get Node Manager Capabilites request format
*/
typedef struct
{
ipmiIana iana;
uint8_t domainId : 4, reserved0 : 4;
uint8_t policyTriggerType : 4, policyType : 3, reserved1 : 1;
} __attribute__((packed)) nmIpmiGetNmCapabilitesReq;
static_assert(sizeof(nmIpmiGetNmCapabilitesReq) == 5);
/**
* @brief Get Node Manager Capabilites response format
*/
typedef struct
{
ipmiIana iana;
uint8_t maxConcurentSettings;
uint16_t maxLimit;
uint16_t minLimit;
uint32_t minCorrectionTime;
uint32_t maxCorrectionTime;
uint16_t minStatsReportingPeriod;
uint16_t maxStatsReportingPeriod;
uint8_t domainId : 4, reserved : 4;
} __attribute__((packed)) nmIpmiGetNmCapabilitesResp;
static_assert(sizeof(nmIpmiGetNmCapabilitesResp) == 21);
/**
* @brief Ipmb utils
*/
using IpmbDbusRspType =
std::tuple<int, uint8_t, uint8_t, uint8_t, uint8_t, std::vector<uint8_t>>;
int ipmbSendRequest(sdbusplus::asio::connection &conn,
IpmbDbusRspType &ipmbResponse,
const std::vector<uint8_t> &dataToSend, uint8_t netFn,
uint8_t lun, uint8_t cmd)
{
try
{
auto mesg =
conn.new_method_call(ipmbBus, ipmbObj, ipmbIntf, "sendRequest");
mesg.append(ipmbMeChannelNum, netFn, lun, cmd, dataToSend);
auto ret = conn.call(mesg, kIpmbTimeout);
ret.read(ipmbResponse);
return 0;
}
catch (sdbusplus::exception::exception &e)
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"ipmbSendRequest:, dbus call exception");
return -1;
}
}
/**
* @brief ME FW version class declaration
*/
class GetMeVer
{
public:
GetMeVer(std::shared_ptr<sdbusplus::asio::connection> conn,
sdbusplus::asio::object_server &server) :
conn(conn)
{
iface = server.add_interface(meSoftwareObjPath, softwareVerIntf);
iface->register_property(
"Purpose",
std::string(
"xyz.openbmc_project.Software.Version.VersionPurpose.ME"));
iface->register_property(
"Version", std::string(""),
[](const std::string &newVal, std::string &oldVal) { return 1; },
[this](const std::string &val) { return getDevId(); });
iface->initialize();
/* Activation interface represents activation state for an associated
* xyz.openbmc_project.Software.Version. since its are already active,
* set "activation" to Active and "RequestedActivation" to None.
*/
auto activationIface =
server.add_interface(meSoftwareObjPath, softwareActivationIntf);
activationIface->register_property(
"Activation",
std::string(
"xyz.openbmc_project.Software.Activation.Activations.Active"));
activationIface->register_property(
"RequestedActivation",
std::string("xyz.openbmc_project.Software.Activation."
"RequestedActivations.None"));
activationIface->initialize();
/* For all Active images, functional endpoints must be added. */
std::vector<Association> associations;
associations.push_back(
Association("functional", "software_version", meSoftwareObjPath));
auto associationsIface = server.add_interface(
"/xyz/openbmc_project/software", associationInterface);
associationsIface->register_property("Associations", associations);
associationsIface->initialize();
}
std::string getDevId()
{
constexpr const char *invalidMeVersion = "";
std::vector<uint8_t> dataToSend;
IpmbDbusRspType ipmbResponse;
int sendStatus =
ipmbSendRequest(*conn, ipmbResponse, dataToSend, ipmiGetDevIdNetFn,
ipmiGetDevIdLun, ipmiGetDevIdCmd);
if (sendStatus)
{
return invalidMeVersion;
}
const auto &[status, netfn, lun, cmd, cc, dataReceived] = ipmbResponse;
if (status)
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"getDevId: ipmb non-zero response status ",
phosphor::logging::entry("%d", status));
return invalidMeVersion;
}
if (cc)
{
phosphor::logging::log<phosphor::logging::level::WARNING>(
"getDevId: non-zero completion code ",
phosphor::logging::entry("%d", cc));
return invalidMeVersion;
}
if (dataReceived.size() != sizeof(ipmiGetDeviceIdResp))
{
phosphor::logging::log<phosphor::logging::level::WARNING>(
"getDevId: response size does not match expected value");
return invalidMeVersion;
}
auto getDevIdResp =
reinterpret_cast<const ipmiGetDeviceIdResp *>(dataReceived.data());
auto major = std::to_string(getDevIdResp->fwMajorMinor.fwMajorRev);
auto minor = std::to_string(getDevIdResp->fwMajorMinor.fwMinorRev);
auto hotfix = std::to_string(getDevIdResp->fwMajorMinor.fwHotfixRev);
auto build = std::to_string(getDevIdResp->fwVerAux.a) +
std::to_string(getDevIdResp->fwVerAux.b) +
std::to_string(getDevIdResp->fwVerAux.c);
auto patch = std::to_string(getDevIdResp->fwVerAux.patch);
return major + '.' + minor + '.' + hotfix + '.' + build + '.' + patch;
}
private:
std::shared_ptr<sdbusplus::asio::dbus_interface> iface;
std::shared_ptr<sdbusplus::asio::connection> conn;
};
/**
* @brief Request class declaration
*/
class Request
{
public:
// virtual function for sending requests to Ipmb
virtual void prepareRequest(uint8_t &netFn, uint8_t &lun, uint8_t &cmd,
std::vector<uint8_t> &dataToSend) = 0;
// virtual function for handling responses from Ipmb
virtual void handleResponse(const uint8_t completionCode,
const std::vector<uint8_t> &dataReceived) = 0;
virtual void createAssociation(sdbusplus::asio::object_server &server,
const std::string &path){};
virtual ~Request(){};
protected:
Request(){};
std::shared_ptr<sdbusplus::asio::dbus_interface> iface;
std::shared_ptr<sdbusplus::asio::dbus_interface> association;
};
/**
* @brief PowerMetric class declaration
*/
class PowerMetric : public Request
{
public:
PowerMetric(sdbusplus::asio::object_server &server)
{
iface = server.add_interface("/xyz/openbmc_project/Power/PowerMetric",
nmdPowerMetricIntf);
iface->register_property("IntervalInMin", static_cast<uint64_t>(0));
iface->register_property("MinConsumedWatts", static_cast<uint16_t>(0));
iface->register_property("MaxConsumedWatts", static_cast<uint16_t>(0));
iface->register_property("AverageConsumedWatts",
static_cast<uint16_t>(0));
iface->initialize();
}
void handleResponse(const uint8_t completionCode,
const std::vector<uint8_t> &dataReceived)
{
if (completionCode != 0)
return;
if (dataReceived.size() != sizeof(nmIpmiGetNmStatisticsResp))
{
phosphor::logging::log<phosphor::logging::level::WARNING>(
"handleResponse: response size does not match expected value");
return;
}
auto getNmStatistics =
reinterpret_cast<const nmIpmiGetNmStatisticsResp *>(
dataReceived.data());
iface->set_property(
"IntervalInMin",
static_cast<uint64_t>(getNmStatistics->statsReportPeriod));
iface->set_property(
"MinConsumedWatts",
static_cast<uint16_t>(getNmStatistics->data.stats.min));
iface->set_property(
"MaxConsumedWatts",
static_cast<uint16_t>(getNmStatistics->data.stats.max));
iface->set_property(
"AverageConsumedWatts",
static_cast<uint16_t>(getNmStatistics->data.stats.avg));
}
void prepareRequest(uint8_t &netFn, uint8_t &lun, uint8_t &cmd,
std::vector<uint8_t> &dataToSend)
{
dataToSend.resize(sizeof(nmIpmiGetNmStatisticsReq));
auto nmGetStatistics =
reinterpret_cast<nmIpmiGetNmStatisticsReq *>(dataToSend.data());
netFn = ipmiGetNmStatisticsNetFn;
lun = ipmiGetNmStatisticsLun;
cmd = ipmiGetNmStatisticsCmd;
ipmiSetIntelIanaNumber(nmGetStatistics->iana);
nmGetStatistics->mode = 1;
nmGetStatistics->reserved3B = 0;
nmGetStatistics->domainId = 0;
nmGetStatistics->statsSide = 0;
nmGetStatistics->reserved = 0;
nmGetStatistics->perComponent = 0;
nmGetStatistics->policyId = 0;
}
};
class getNmStatistics : public Request
{
public:
getNmStatistics(sdbusplus::asio::object_server &server, double minValue,
double maxValue, std::string type, std::string name,
uint8_t mode, uint8_t domainId, uint8_t policyId) :
mode(mode),
domainId(domainId), policyId(policyId), type(type), name(name)
{
iface =
server.add_interface(propObj + type + '/' + name, nmdSensorIntf);
iface->register_property("MaxValue", static_cast<double>(maxValue));
iface->register_property("MinValue", static_cast<double>(minValue));
iface->register_property("Value", static_cast<double>(0));
iface->register_property(
"Unit", std::string("xyz.openbmc_project.Sensor.Value.Unit.Watts"));
iface->initialize();
}
void createAssociation(sdbusplus::asio::object_server &server,
const std::string &path)
{
if (!association)
{
std::vector<Association> associations;
associations.push_back(Association("chassis", "all_sensors", path));
association = server.add_interface("/xyz/openbmc_project/sensors/" +
type + "/" + name,
associationInterface);
association->register_property("Associations", associations);
association->initialize();
}
}
void handleResponse(const uint8_t completionCode,
const std::vector<uint8_t> &dataReceived)
{
if (completionCode != 0)
return;
if (dataReceived.size() != sizeof(nmIpmiGetNmStatisticsResp))
{
phosphor::logging::log<phosphor::logging::level::WARNING>(
"handleResponse: response size does not match expected value");
return;
}
auto getNmStatistics =
reinterpret_cast<const nmIpmiGetNmStatisticsResp *>(
dataReceived.data());
iface->set_property(
"Value", static_cast<double>(getNmStatistics->data.stats.cur));
}
void prepareRequest(uint8_t &netFn, uint8_t &lun, uint8_t &cmd,
std::vector<uint8_t> &dataToSend)
{
dataToSend.resize(sizeof(nmIpmiGetNmStatisticsReq));
auto nmGetStatistics =
reinterpret_cast<nmIpmiGetNmStatisticsReq *>(dataToSend.data());
netFn = ipmiGetNmStatisticsNetFn;
lun = ipmiGetNmStatisticsLun;
cmd = ipmiGetNmStatisticsCmd;
ipmiSetIntelIanaNumber(nmGetStatistics->iana);
nmGetStatistics->mode = mode;
nmGetStatistics->reserved3B = 0;
nmGetStatistics->domainId = domainId;
nmGetStatistics->statsSide = 0;
nmGetStatistics->reserved = 0;
nmGetStatistics->perComponent = 0;
nmGetStatistics->policyId = policyId;
}
private:
uint8_t mode;
uint8_t domainId;
uint8_t policyId;
std::string type;
std::string name;
};
/**
* @brief Global power statistics [Watts]
*/
class GlobalPowerPlatform : public getNmStatistics
{
public:
using getNmStatistics::getNmStatistics;
};
class GlobalPowerCpu : public getNmStatistics
{
public:
using getNmStatistics::getNmStatistics;
};
class GlobalPowerMemory : public getNmStatistics
{
public:
using getNmStatistics::getNmStatistics;
};
class GlobalPowerHwProtection : public getNmStatistics
{
public:
using getNmStatistics::getNmStatistics;
};
struct HealthData
{
HealthData(std::shared_ptr<sdbusplus::asio::dbus_interface> interface) :
interface(interface)
{
}
void set(const std::string &type, const std::string &level)
{
// todo: maybe look this up via mapper
constexpr const char *globalInventoryPath =
"/xyz/openbmc_project/CallbackManager";
fatal.erase(type);
critical.erase(type);
warning.erase(type);
if (level == "fatal")
{
fatal.insert(type);
}
else if (level == "critical")
{
critical.insert(type);
}
else if (level == "warning")
{
warning.insert(type);
}
else if (level != "ok")
{
throw std::invalid_argument(type);
}
std::vector<Association> association;
if (fatal.size())
{
association.emplace_back("", "critical", globalInventoryPath);
association.emplace_back("", "critical", meStatusPath);
}
else if (critical.size())
{
association.emplace_back("", "warning", globalInventoryPath);
association.emplace_back("", "critical", meStatusPath);
}
else if (warning.size())
{
association.emplace_back("", "warning", globalInventoryPath);
association.emplace_back("", "warning", meStatusPath);
}
interface->set_property("Associations", association);
}
void clear()
{
fatal.clear();
critical.clear();
warning.clear();
interface->set_property("Associations", std::vector<Association>{});
}
std::shared_ptr<sdbusplus::asio::dbus_interface> interface;
boost::container::flat_set<std::string> fatal;
boost::container::flat_set<std::string> critical;
boost::container::flat_set<std::string> warning;
};
/**
* @brief DBus exception thrown in case any internal error
*/
struct InternalFailure final : public sdbusplus::exception_t
{
static constexpr auto errName =
"xyz.openbmc_project.Common.Error.InternalFailure";
static constexpr auto errDesc = "The operation failed internally.";
static constexpr auto errWhat =
"xyz.openbmc_project.Common.Error.InternalFailure: The operation "
"failed internally.";
const char *name() const noexcept override
{
return errName;
}
const char *description() const noexcept override
{
return errDesc;
}
const char *what() const noexcept override
{
return errWhat;
}
int get_errno() const noexcept override
{
return EACCES;
}
};
/**
* @brief DBus exception thrown when got non-success IPMI completion code
*/
struct NonSuccessCompletionCode final : public sdbusplus::exception_t
{
static constexpr auto errName =
"xyz.openbmc_project.Common.Error.NonSuccessCompletionCode";
static constexpr auto errDesc =
"The operation failed. Got non-success completion code.";
static constexpr auto errWhat =
"xyz.openbmc_project.Common.Error.NonSuccessCompletionCode: The "
"operation failed. Got non-success completion code.";
const char *name() const noexcept override
{
return errName;
}
const char *description() const noexcept override
{
return errDesc;
}
const char *what() const noexcept override
{
return errWhat;
}
int get_errno() const noexcept override
{
return EIO;
}
};
/**
* @brief DBus exception thrown when IPMI response size does not match expected
* size
*/
struct WrongResponseSize final : public sdbusplus::exception_t
{
static constexpr auto errName =
"xyz.openbmc_project.NodeManager.Error.WrongResponseSize";
static constexpr auto errDesc =
"IPMB response size does not match expected value";
static constexpr auto errWhat =
"IPMB response size does not match expected value";
const char *name() const noexcept override
{
return errName;
}
const char *description() const noexcept override
{
return errDesc;
}
const char *what() const noexcept override
{
return errWhat;
}
int get_errno() const noexcept override
{
return EIO;
}
};
struct PoliciesCannotBeCreated final : public sdbusplus::exception_t
{
static constexpr auto errName =
"xyz.openbmc_project.NodeManager.Error.PoliciesCannotBeCreated";
static constexpr auto errDesc =
"Policies in given power domain cannot be created in the current "
"configuration e.g., attempt to create predictive power limiting "
"policy in DC power domain";
static constexpr auto errWhat =
"xyz.openbmc_project.NodeManager.Error.PoliciesCannotBeCreated: "
"Policies in given power domain cannot be created in the current "
"configuration e.g., attempt to create predictive power limiting "
"policy in DC power domain";
const char *name() const noexcept override
{
return errName;
}
const char *description() const noexcept override
{
return errDesc;
}
const char *what() const noexcept override
{
return errWhat;
}
int get_errno() const noexcept override
{
return EINVAL;
}
};
/**
* @brief Policy parameters structure
*/
struct PolicyParams
{
uint32_t correctionInMs;
uint16_t limit;
uint16_t statReportingPeriod;
int policyStorage;
int powerCorrectionType;
int limitException;
std::vector<std::map<std::string,
std::variant<std::vector<std::string>, std::string>>>
suspendPeriods;
std::map<std::string, std::vector<uint16_t>> thresholds;
uint8_t componentId;
uint16_t triggerLimit;
std::string triggerType;
};
/**
* @brief Statistics type provided on DBus as return type for GetStatistics
*/
using StatValuesMap = std::map<std::string, std::variant<double, uint32_t>>;
/**
* @brief Node Manager Statistics DBus interface
* The following methods shall be supported:
* * GetStatistics
* * * return StatValuesMap - statistics collection
*/
constexpr const char *nmStatisitcsIf =
"xyz.openbmc_project.NodeManager.Statistics";
/**
* @brief Node Manager Policy Attributes DBus interface
* The following properties shall be supported:
* * uint16_t Limit
*/
constexpr const char *nmPolicyAttributesIf =
"xyz.openbmc_project.NodeManager.PolicyAttributes";
/**
* @brief Generic function used to send and receive IPMI message
*
* @tparam Req - IPMI request type
* @tparam Resp - IPMI response type
* @param conn - DBus connection
* @param netFnReq - IPMI Net Function
* @param lunReq - IPMI LUN
* @param cmdReq - IPMI command
* @param req - IPMI request
* @param resp - IPMI response
*/
template <typename Req, typename Resp>
void ipmiSendReceive(std::shared_ptr<sdbusplus::asio::connection> conn,
uint8_t netFnReq, uint8_t lunReq, uint8_t cmdReq,
const Req &req, Resp &resp)
{
IpmbDbusRspType ipmbResponse;
std::vector<uint8_t> dataToSend(reinterpret_cast<const uint8_t *>(&req),
reinterpret_cast<const uint8_t *>(&req) +
sizeof(req));
int sendStatus = ipmbSendRequest(*conn, ipmbResponse, dataToSend, netFnReq,
lunReq, cmdReq);
if (sendStatus != 0)
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"dbus error while sending IPMB request ",
phosphor::logging::entry("%d", sendStatus));
throw InternalFailure();
}
const auto &[status, netfnResp, lunResp, cmdResp, cc, dataReceived] =
ipmbResponse;
if (status)
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"transport error while sending IPMB request ",
phosphor::logging::entry("%d", status));
throw InternalFailure();
}
if (cc != 0x00)
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"error while sending IPMB request, wrong cc: ",
phosphor::logging::entry("%d", cc));
throw NonSuccessCompletionCode();
}
if (dataReceived.size() != sizeof(resp))
{
phosphor::logging::log<phosphor::logging::level::WARNING>(
"wrong response size");
throw WrongResponseSize();
}
std::copy(dataReceived.begin(), dataReceived.end(),
reinterpret_cast<uint8_t *>(&resp));
}
using DeleteCallback = std::function<void(const std::string policyId)>;
/**
* @brief Node Manager Policy
*/
class Policy
{
public:
Policy() = delete;
Policy(const Policy &) = delete;
Policy &operator=(const Policy &) = delete;
Policy(Policy &&) = delete;
Policy &operator=(Policy &&) = delete;
Policy(std::shared_ptr<sdbusplus::asio::connection> connArg,
sdbusplus::asio::object_server &server, std::string &domainDbusPath,
uint8_t domainIdArg, std::string idArg, DeleteCallback deleteArg) :
conn(connArg),
dbusPath(domainDbusPath + "/Policy/" + idArg), domainId(domainIdArg),
id(idArg), deleteCallback(deleteArg), sdserver(server)
{
createAttributesInterface(server);
createStatisticsInterface(server);
createEnabledInterface(server);
createDeleteInterface(server);
}
~Policy()
{
sdserver.remove_interface(attributesIf);
sdserver.remove_interface(statisticsIf);
sdserver.remove_interface(enabledIf);
sdserver.remove_interface(deleteIf);
}
static constexpr uint8_t dmtfPowerPolicyId = 254;