summaryrefslogtreecommitdiffstats
path: root/src/include/usr/ipmi/ipmisensor.H
blob: 4da69dc0c1dc7f32954a2403ab70f126a00a4aab (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
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/include/usr/ipmi/ipmisensor.H $                           */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2014,2018                        */
/* [+] Google Inc.                                                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* 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.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/**
 *  @file ipmisensor.H
 *
 *  @brief Interface for the Sensor class
 *
 *  This header file contains the interfaces for the sensor class which
 *  is used to handle setting the virtual sensors maintained by the BMC.
 */

#include <initservice/initsvcstructs.H>
#include <attributeenums.H>
#include <targeting/common/target.H>
#include <errl/errlentry.H>
#include <targeting/common/targetservice.H>
#include <targeting/targplatutil.H>
#include <ipmi/ipmiif.H>

#ifndef __IPMI_IPMISENSOR_H
#define __IPMI_IPMISENSOR_H

namespace SENSOR
{

    const uint8_t INVALID_TYPE = 0xFF;

    /**
     * @brief Default reboot count value.
     */
    static const uint16_t DEFAULT_REBOOT_COUNT = 0x0002;

    /**
     *  @enum sensorReadingTypes
     *  Sensor specific completion codes, defined in IPMI Spec.
     *
     */
    enum sensorReadingType
    {
        THRESHOLD                   = 0x01,
        DIGITAL_ASSERT_DEASSERT     = 0x03,
        DIGITAL_ENABLE_DISABLE      = 0x09,
        SENSOR_SPECIFIC             = 0x6f,
    };


    /**
     *  @enum procStatusSensorOffsets
     *  Sensor specific completion codes, defined in IPMI Spec.
     *
     */
    enum procStatusSensorOffsets
    {
        IERR                            = 0x00,
        THERMAL_TRIP                    = 0x01,
        BIST_FAILURE                    = 0x02,
        HANG_IN_POST                    = 0x03,
        INIT_FAILURE                    = 0x04,
        PROC_CONFIG_ERROR               = 0x05,
        BIOS_ERROR                      = 0x06,
        PROC_PRESENCE_DETECTED          = 0x07,
        PROC_DISABLED                   = 0x08,
        TERMINATOR_PRESNCE_DETECTED     = 0x09,
        PROCESSOR_THROTTLED             = 0x0A,
        MACHINE_CHECK_EXCEPTION         = 0x0B,
        CORRECTABLE_MACHINE_CHECK       = 0x0C,
        INVALID_OFFSET                  = 0xFF,

    };

    /**
     *  @enum dimmStatusSensorOffsets
     *  Dimm specific offsets for status sensor, defined in IPMI Spec.
     *
     */
    enum dimmStatusSensorOffsets
    {
        CORRECTABLE_ECC_ERROR           = 0x00,
        UNCORRECTABLE_ECC_ERROR         = 0x01,
        PARITY_ERROR                    = 0x02,
        MEMORY_SCRUB_ERROR              = 0x03,
        MEMORY_DEVICE_DISABLED          = 0x04,
        CORRECTABLE_ECC_ER_LIMIT_REACH  = 0x05,
        MEM_DEVICE_PRESENCE_DETECTED    = 0x06,
        MEM_CONFIG_ERROR                = 0x07,
        SPARE                           = 0x08,
        MEMORY_AUTOMATICALLY_THROTTLED  = 0x09,
        CRITICAL_OVER_TEMP              = 0x0A,
    };

    /**
     *  @enum firmwareBootProgressSensorOffsets
     *  Boot progress specific offsets defined in IPMI Spec.
     *
     */
    enum firmwareProgressSensorOffsets
    {
        // offset 02h
        SYSTEM_FIRMWARE_PROGRESS = 0x02,
    };


    /**
     *  @enum systemEventSensorOffsets
     *  offSets specific to the system event sensor.
     *
     */
    enum systemEventSensorOffsets
    {
        // offset 02h
        UNDETERMINED_SYSTEM_HW_FAILURE = 0x02,
    };


    /**
     *  @enum discrete09_Offsets
     *
     *      Offsets specific to IPMI sensor reading type 09
     *      digital discrete sensors. These offsets result in
     *      Device Enabled or Device Disabled events in the
     *      BMC event log.
     *
     */
    enum discrete09_Offsets
    {
        // offset 00h
        DEVICE_DISABLED = 0x0,

        //offset 01h
        DEVICE_ENABLED  = 0x1,
    };

     /**
     *  @enum discrete03_Offsets
     *
     *      Offsets specific to IPMI sensor reading type 03
     *      digital discrete sensors. These offsets result in generic
     *      State Asserted or State Deasserted events in the
     *      BMC event log.
     *
     */
    enum discrete03_Offsets
    {
        // offset 00h
        DEASSERTED = 0x00,

        //offset 01h
        ASSERTED   = 0x01,
    };

     /**
     *  @enum acpiPowerState_Offsets
     *
     *      Offsets specific to IPMI ACPI Power state
     *      senosrs. These offsets result in power
     *      state messages in the BMC event log.
     *
     */
    enum acpiPowerState_Offsets
    {
        // offset 0h
        S0_G0_WORKING   = 0x00,

        // offset 05h
        G5_SOFT_OFF     = 0x05,

        //offset 0Bh
        LEGACY_ON       = 0x0B,

    };

    //**  Bit definition for set sensor reading cmd operation field
    //      [7:6] 10b - write given values to event data bytes let BMC handle
    //                  offset in event data 1 when an external event is
    //                  triggered based on the new data.
    //      [5:4] 10b - a one causes a one in the corresponding position of
    //                  the event assertion bits, zeros are ignored.
    //      [3:2] 10b - a one causes a one in the  corresponding position of
    //                  the event deassertion bits, zeros are ignored.
    //      [0:1] 01b - write the given value to the sensor reading byte.
    //
    //      Note: Per AMI implementation bits 0:1 will force the assertion
    //            mask value as sent to be the new sensor value, all other bits
    //            are ignored.
    //
    //      default operation = 1010 1001
    static const uint8_t DEFAULT_OPERATION = 0xA8;  // see IPMI Spec. "Set

    // use this value for sensors which use assertion fields for sensor values
    // eg. Reboot count
    static const uint8_t SET_SENSOR_VALUE_OPERATION = 0x01;

    // Sensor Reading and Event
    // Status command" for
    // details on this byte.

    // Mask which preserves major type of the sensor
    static const uint16_t SENSOR_NAME_MAJOR_MASK = 0xFF00;

    // Mask which preserves minor type of the sensor
    static const uint16_t SENSOR_NAME_MINOR_MASK = 0x00FF;

    /**
     *   @struct setSensorReadingRequest
     *       structure holding the data for the set sensor reading command which
     *       Hostboot will send to the BMC to update sensor status/readings.
     *
     */
    struct setSensorReadingRequest
    {
        uint8_t   iv_sensor_number;
        uint8_t   iv_operation;
        uint8_t   iv_sensor_reading;
        uint16_t  iv_assertion_mask;
        uint16_t  iv_deassertion_mask;
        uint8_t   iv_event_data[3];

        // constructor for our data set
        setSensorReadingRequest()
            :iv_sensor_number(0),iv_operation(DEFAULT_OPERATION),
            iv_sensor_reading(0), iv_assertion_mask(0), iv_deassertion_mask(0)
        {
            memset(iv_event_data,0, sizeof(iv_event_data));
        };
    }PACKED;

    /**
     *   @struct getSensorReadingData
     *       structure holding the data returned by the get sensor reading
     *       command.
     *
     */
    struct getSensorReadingData
    {
        uint8_t   completion_code;
        uint8_t   sensor_status;
        uint8_t   sensor_reading;
        uint16_t  event_status;

        // constructor for our data set
        getSensorReadingData()
            :completion_code(0),sensor_status(0),
            sensor_reading(0), event_status(0)
        {

        };
    };

    /**
     *  @enum  completionCode
     *  Sensor specific completion codes, defined in IPMI Spec.
     *
     */
    enum completionCode
    {
        CC_SENSOR_READING_NOT_SETTABLE    = 0x80,
        CC_EVENT_DATA_BYTES_NOT_SETTABLE  = 0x81
    };
    /**
     * @enum SensorReadingValidEnum
     *
     *  enum defining masks used when reading a sensor
     *
     */
    enum SensorReadingValidEnum
    {
        SENSOR_DISABLED = 0x80,
        SENSOR_SCANNING_DISABLED = 0x40,
        READING_UNAVAILABLE = 0x20,
    };

    /**
     *  @class SensorBase
     *
     *  @brief Base class for sensors
     *
     *  @par Detailed Description:
     *      Provides the base functionality to set IPMI sensor from Hostboot
     *      including finding the sensor number given a specific target type.
     *      The constructor takes a SENSOR_NAME and a target pointer. If a null
     *      is passed in as the target pointer, the system target will be used
     *      to search for the requested sensor name.
     */
    class SensorBase
    {

        public:
            /**
             *  @brief Generic base class constructor for sensor objects
             *
             *  @brief Base class for sensor derivation - takes a sensor name,
             *  and a target* as input.
             *
             *  @par Detailed Description:
             */
            SensorBase(TARGETING::SENSOR_NAME i_name,
                    TARGETING::ConstTargetHandle_t i_target);

            /**
             *  @brief Destructor for the base sensor object
             *
             *  Destroys the sensor object and any owned resources, does not
             *  alter the state on the BMC
             *
             *  @post Sensor object is destroyed, and all resources are
             *        reclaimed
             */
            virtual  ~SensorBase();

            // low level communication to update sensor readings on the BMC

            /**
             * @brief write sensor data
             *    Low level interface to send the set sensor and event data
             *    reading command to the BMC through the BT interface.
             *
             * @return Errorlog handle
             *
             */
            virtual errlHndl_t  writeSensorData();

            /**
             * @brief read sensor data
             *    Low level interface to send get sensor and event data reading
             *    command to the BMC through the BT interface.
             *
             * @param[out] o_data - buffer containing the response data from the
             *                      BMC,
             *  NOTE: caller is responsible for deleting the memory pointed to
             *        by o_data.
             *
             * @return Errorlog handle
             *
             */
            virtual errlHndl_t readSensorData(getSensorReadingData& o_data);


            /**
             * @brief process completion codes
             *    Converts completion code values returned from the IPMI
             *    transport layer into an error log.
             *
             * @param[in] i_cc - completion code returned from the IPMI
             *                   transport layer.
             *
             * @return Errorlog handle
             *
             */
            errlHndl_t processCompletionCode(IPMI::completion_code i_cc);

            /**
             * @brief Send set sensor reading and event status command
             *    Helper function to send the sensor reading to the BMC, this
             *    command executes asynchronously.
             *
             * @param[in] i_data - Contains the command and data
             *                      to send to the BMC.
             *
             * @return Errorlog handle
             *
             */
            errlHndl_t sendSetSensorReading(
                    setSensorReadingRequest * i_data);

            /**
             * @brief helper function to get the sensor number
             */
            virtual uint32_t getSensorNumber( )
            {
                return TARGETING::UTIL::getSensorNumber(iv_target, iv_name );
            };


            // return the sensor type and event reading data
            static errlHndl_t getSensorType(uint32_t i_sensorNumber,
                                     uint8_t &o_sensorType,
                                     uint8_t &o_eventReadingType );

        protected:

            /**
             * @brief setup mask for event assertion/deassertion
             *
             * Translate the passed in offset into a mask for use in
             * as an assertion or deassertion mask.
             *
             * @param[in] = i_offset - offset for event do be signaled
             * @param[in] = i_swap   - indicates if mask should be
             *                         byteswapped before returning
             *                         true =  byte swap mask
             *                         false = do not byte swap the mask
             *
             * @return  eventMask - event status mask with correctly set bit
             *                      matching the offset passed in.
             *
             */
            static uint16_t setMask( uint8_t i_offset, bool i_swap = true );

            /**
             * @brief return the event offset from an assertion/deassertion mask
             *
             * Translate the assertion/deassertion mask into the correct event
             * offset.
             *
             * @param[in] = i_mask - offset for event do be signaled
             *
             * @return offset - offset of the bit which is set in the passed in
             *                  mask.
             *
             */
            static uint8_t getOffset( uint16_t i_mask );

            // Name of this sensor, name is used to find the sensor number in
            // the IPMI_SENSORS attribute.
            TARGETING::SENSOR_NAME iv_name;

            // Target associated with this sensor.
            TARGETING::ConstTargetHandle_t iv_target;

            // data structure for the send sensor reading command.
            setSensorReadingRequest * iv_msg;

        private:
            //disable default constructor, copy constructor and the assignment
            // operator.
            SensorBase();

            SensorBase& operator=(const SensorBase& i_right);

            SensorBase(const SensorBase& thing );

    };

    /**
     *  @class FirmwareProgressSensor
     *
     *  @brief Specialized sensor class for the firmware progress sensor
     *
     *  @par Detailed Description:
     *      Provides the functionality needed to set the firmware progress
     *      virtual sensor maintained by the BMC.
     */
    class FirmwareProgressSensor : public SensorBase
    {

        public:

            /**
             *  @brief Constructor for the FirmwareProgressSensor
             *
             *  The firmware progress sensor is used to update the BMC
             *  with the current firmware phase.
             *  The system target holds the IPMI sensor number for this sensor.
             *
             */
            FirmwareProgressSensor();

            /**
             *  @brief destructor for the FirmwareProgressSensor
             *
             *  The firmware progress sensor is used to update the BMC
             */
            ~FirmwareProgressSensor();

            /**
             *
             * @brief Set the current firmware boot progress phase
             *    Interface used to update the event status for the system
             *    firmware progress sensor.  phases are defined by the enum
             *    firmware_progress_phase. Further information can be found in
             *    the IPMI specification.
             *
             * @param[in] i_phase - current firmware progress phase.
             *
             * @return Errorlog handle
             *
             */
            errlHndl_t setBootProgressPhase(
                            INITSERVICE::firmwareProgressPhase i_phase);

        private:
            // @enum firmwareProgressOfsets
            //
            // sensor specific offset used to specify that the event which is
            // being signaled is for the system firmware progress sensor.
            enum firmwareProgressOffsets
            {
                SYSTEM_FIRMWARE_PROGRESS    = 0x02  //< Sensor specific offset
                                                    //< for system firmware
                                                    //< progress event.
            };

    };

    /**
     *  @class HostStatusSensor
     *
     *  @brief Specialized class for the host status sensor.
     *
     *  @par Detailed Description:
     *      Provides the functionality needed to set the Host_Status sensor also
     *      known as the ACPI power state. The Host_status sensor is a virtual
     *      sensor maintained by the BMC,
     */
    class HostStatusSensor : public SensorBase
    {
        public:

            /**
             * @enum hostStatus
             *      enum to define the ACPI power state of the system, this
             *      sensor will be updated by Hostboot and opal.
             */
            enum hostStatus
            {
                S0_G0_WORKING   = 0x00,  //< Host up
                S5_G2_SOFT_OFF  = 0x05,  //< Soft power off
                LEGACY_ON_STATE = 0x0B   //< Host not up, but started
            };

            /**
             *  @brief Constructor for the HostStatusSensor
             *
             *  The firmware progress sensor is used to update the BMC
             *  with the current ACIP power state of the system.
             *  The system target holds the IPMI sensor number for this sensor.
             *
             */
            HostStatusSensor();

            /**
             *  @brief Destructor for the HostStatusSensor
             *
             */
            ~HostStatusSensor();

            /**
             *
             * @brief Set the current HostStatus
             *    Interface used to update the event status for the ACPI
             *    power state of the system. States are defined by the enum
             *    host_status.  Further information can be found in the IPMI
             *    specification.
             *
             *
             * @param[in] i_phase - current firmware progress phase.
             *
             * @return Errorlog handle
             *
             */
            errlHndl_t updateHostStatus( hostStatus status );

    };

    /**
     *  @class RebootCountSensor
     *
     *  @brief Specialized class for the system reboot count.
     *
     *  @par Detailed Description:
     *      Provides the functionality needed to set the reboot count. The
     *      reboot count is a special sensor maintained by the BMC.
     *
     *   Usage:
     *     reboot_count_t count = 3;
     *      RebootCountSensor l_sensor;
     *      l_sensor.setRebootCount( count );
     *
     */
    class RebootCountSensor : public SensorBase
    {

        public:

            /**
             *  @brief Constructor for the RebootCountSensor
             *
             *  The reboot count sensor is used to update the reboot count
             *  sensor maintained by the BMC.
             *
             *  The system target holds the IPMI sensor number for this sensor.
             *
             */
            RebootCountSensor();

            /**
             *  @brief Destructor for the RebootCountSensor
             *
             */
            ~RebootCountSensor();

            /**
             * @brief Set the value for the reboot count to the BMC.
             *
             * @param[in] i_count - new reboot count value.
             *
             * @return Errorlog handle
             *
             */
            errlHndl_t setRebootCount( uint16_t i_count );

            /**
             * @brief get the value of the reboot count from the BMC.
             *
             * @param[o] o_rebootCount - new reboot count value.
             *
             * @return Errorlog handle
             *
             */
            errlHndl_t getRebootCount( uint16_t& o_rebootCount );

    };

    /**
     *  @class RebootControlSensor
     *
     *  @brief Specialized class for the system reboot control
     *
     *  @par Detailed Description:
     *      Provides the functionality needed to enable/disable auto reboot
     *      control controlled by the BMC.
     *
     *   Usage:
     *      RebootControlSensor l_rbotCtl;
     *      l_rbotCtl.setRebootControl( autoRebootSetting::ENABLE_REBOOTS );
     *      l_rbotCtl.setRebootControl( autoRebootSetting::DISABLE_REBOOTS );
     *
     */
    class RebootControlSensor : public SensorBase
    {

        public:
            /**
             * @enum autoRebootSetting
             *      enum to define the control sensor state
             *      Note: bit based setting: 0 -> 0x01
             *                               1 -> 0x02
             */
            enum autoRebootSetting
            {
                DISABLE_REBOOTS = 0x01, // keep current state
                ENABLE_REBOOTS  = 0x02, // allow reboot for FIRDATA analysis
            };

            /**
             *  @brief Constructor for the RebootControlSensor
             *
             *  The system target holds the IPMI sensor number for this sensor.
             *
             */
            RebootControlSensor();

            /**
             *  @brief Destructor for the RebootControlSensor
             *
             */
            ~RebootControlSensor();

            /**
             * @brief Set reboots to enabled or disabled
             *
             * @param[in] i_setting - enable/disable
             *
             * @return Errorlog handle
             *
             */
            errlHndl_t setRebootControl( autoRebootSetting i_setting );

            /**
             * @brief get the value of the reboot control from the BMC.
             *
             * @param[o] i_setting - reboot control value
             *
             * @return Errorlog handle
             *
             */
            errlHndl_t getRebootControl( autoRebootSetting& o_setting );

    };


    /**
     *  @class StatusSensor
     *
     *  @brief Specialized class to handle DIMM, PROC and Core status.
     *
     *  @par Detailed Description:
     *      Provides the functionality needed to set the status of DIMMS, Cores,
     *      and processors.  The object will determine from the Target* what
     *      sensor offsets should be used, and configure itself accordingly.
     */

    class StatusSensor : public SensorBase
    {

        public:

            /**
             * @enum statusEnum
             *
             *  enum defining the status of targets which use the
             *  status sensor to report functional and present states.
             */
            enum statusEnum
            {
                NOT_PRESENT             = 0x0000,
                PRESENT                 = 0x0001,
                FUNCTIONAL              = 0x0002,
                PRESENT_FUNCTIONAL      = 0x0003,
                NON_FUNCTIONAL          = 0x0004,
                PRESENT_NONFUNCTIONAL   = 0x0005,
            };

            /**
             *  @brief Constructor for a status sensor
             *
             *  The status sensor is used for DIMMS, Cores and Procs. Hostboot
             *  will update the present and functional state for the status
             *  sensor associated with each instance of these target types.
             *
             *
             *  The IPMI sensor number for these sensors are associated with
             *  each instance of the DIMM, CORE and Processor targets.
             *
             */
            StatusSensor( TARGETING::ConstTargetHandle_t );

            /**
             *  @brief Destructor for the StatusSensor
             *
             */
            ~StatusSensor();

            errlHndl_t setStatus( statusEnum status );

        protected:
            // internal offset data which is configured based on target type
            // used in construction.
            uint8_t iv_presentOffset;
            uint8_t iv_functionalOffset;

        private:
            // disable the default constructor
            StatusSensor();
    };

    /**
     *  @class FaultSensor
     *
     *  @brief Specialized class implementing a simple fault sensor
     *
     *  @par Detailed Description:
     *      Provides the functionality needed to assert or deassert a fault
     *      condition for a given target.  These are typically used for
     *      things that have failed which may not have a full targeting
     *      implementation.  Implemented using a 0x03 'digital' discrete
     *      generic sensor profile.
     */
    class FaultSensor : public SensorBase
    {
        public:

            /**
             *  @enum FAULT_SENSOR_OFFSET
             *
             *  Indicates the correct sensor offset to use for sensor fault
             *  assertions/deassertions.
             */
            enum FAULT_SENSOR_OFFSET
            {
                FAULT_DEASSERTED_OFFSET = 0x00,
                FAULT_ASSERTED_OFFSET   = 0x01,
            };

            /**
             *  @enum FAULT_STATE
             *
             *  Enum indicating whether the fault sensor is asserted or not
             */
            enum FAULT_STATE
            {
                FAULT_STATE_DEASSERTED = 0x00,
                FAULT_STATE_ASSERTED   = 0x01,
            };

            /**
             *  @brief Constructor for a fault sensor
             *
             *  @param[in] i_pTarget
             *      Target associated with the fault sensor.  Must not be NULL.
             */
            FaultSensor(TARGETING::ConstTargetHandle_t i_pTarget);

            /**
             *  @brief Constructor for a fault sensor, used to differentiate
             *      multiple sensors of similar type on same target
             *
             *  @param[in] i_pTarget
             *      Target associated with the fault sensor.  Must not be NULL.
             *
             *  @param[in] i_associatedType
             *      Type of non-instantiated target linked to the main target
             *      for which this sensor provides readings.
             */
            FaultSensor(TARGETING::ConstTargetHandle_t i_pTarget,
                TARGETING::ENTITY_ID i_associatedType =
                                            TARGETING::ENTITY_ID_NA);

            /**
             *  @brief Destructor for a fault sensor
             *
             */
            ~FaultSensor();

            /**
             *  @brief Set the fault sensor to faulted or non-faulted
             *
             *  @param[in] i_faultState
             *      Whether sensor is faulted or not
             *
             *  @return Error log handle
             *  @retval NULL  Status set successfully
             *  @retval !NULL Failed to set status
             */
            errlHndl_t setStatus(FAULT_STATE i_faultState);

        private:

            // Disable the default constructor
            FaultSensor();

            // Disable assignment operator
            FaultSensor& operator=(const FaultSensor& i_rhs);

            // Disable copy constructor
            FaultSensor(const FaultSensor& i_rhs);
    };


    /**
     *  @class GpuSensor
     *
     *  @brief Specialized class to handle GPU sensor status.
     *
     *  @par Detailed Description:
     *      Provides the functionality needed to set the status of GPU sensors.
     */
    class GpuSensor : public StatusSensor
    {

        public:

            /**
             *  @brief Constructor for a gpu sensor
             *
             *  The status sensor is used for GPUs attached to Procs. Hostboot
             *  will update the present and functional state for the status
             *  sensor associated with each instance of these target types.
             *
             *  @param[in] - Sensor name enum
             *  @param[in] - number identifying particular sensor
             *  @param[in] - Processor target that contains the sensors
             */
            GpuSensor(TARGETING::SENSOR_NAME i_name, uint16_t i_num,
                      TARGETING::ConstTargetHandle_t i_target );

            /**
             *  @brief return the unique number identifying this sensor
             */
            uint32_t getSensorNumber() override
            {
                return iv_sensorNumber;
            };

            /**
             *  @brief Destructor for the GpuSensor
             */
            ~GpuSensor();

        private:
            /**
             *  @brief unique number identifying this particular gpu sensor
             */
            uint16_t iv_sensorNumber;

            // disable the default constructor
            GpuSensor();
    };


    /**
     *  @class HbVolatileSensor
     *
     *  @brief Specialized class for the hostboot volatile memory setup
     *
     *  @par Detailed Description:
     *      Provides the functionality needed by OpenBMC to set hostboot
     *      section as volatile or not
     *
     *   Usage:
     *      HbVolatileSensor l_hbVolatileCtl;
     *      l_hbVolatileCtl.setHbVolatile( HbVolatileSensor::ENABLE_VOLATILE );
     *      l_hbVolatileCtl.setHbVolatile( HbVolatileSensor::DISABLE_VOLATILE );
     *
     */
    class HbVolatileSensor : public SensorBase
    {

        public:

            /**
             * @enum hbVolatileSetting
             *      enum to define the HB volatile sensor setting
             *      Note: bit based setting: BMC 0 -> 0x01 (off)
             *                               BMC 1 -> 0x02 (on)
             */
            enum hbVolatileSetting
            {
                DISABLE_VOLATILE = 0x01, // (default)
                ENABLE_VOLATILE  = 0x02, // allow volatile memory to be cleared
            };

            /**
             *  @brief Constructor for the HbVolatileSensor
             *
             *  The system target holds the IPMI sensor number for this sensor.
             *
             */
            HbVolatileSensor();

            /**
             *  @brief Destructor for the HbVolatileSensor
             *
             */
            ~HbVolatileSensor();

            /**
             * @brief Set hostboot volatile section to volatile or not
             *
             * @param[in] i_setting - enable/disable volatility of section
             *
             * @return Errorlog handle
             *
             */
            errlHndl_t setHbVolatile( hbVolatileSetting i_setting );

            /**
             * @brief get the value of the hostboot volatile
             *        section from the BMC.
             *
             * @param[o] i_setting - value = volatile or not
             *
             * @return Errorlog handle
             *
             */
            errlHndl_t getHbVolatile( hbVolatileSetting & o_setting );

    };

    /**
     *  @brief Updates initial state of Hostboot relevant fault sensors on the
     *      BMC
     *
     *  @par Detailed Description:
     *      Updates initial state of Hostboot relevant fault sensors on the
     *      BMC to "not faulted" for all applicable fault sensors detected in
     *      the system.  All errors will be internally committed.
     */
    void updateBMCFaultSensorStatus(void);

    /*
     *  @class OCCActiveSensor
     *
     *  @brief Specialized class to handle OCC_Active sensors.
     *
     *  @par Detailed Description:
     *      Provides the functionality needed to set the functional status of
     *      the OCCs.  The object will determine from the Target* which of
     *      the OCC sensors to set.  The OCC_Active sensor is defined as a
     *      processor type sensor so it will use the offsets defined in the
     *      ipmi spec for that type of sensor.
     */

    class OCCActiveSensor : public SensorBase
    {

        public:

            /**
             * @enum OccStateEnum
             *
             *  enum defining the state of the OCC sensor
             */
            enum OccStateEnum
            {
                OCC_NOT_ACTIVE          = 0x00,
                OCC_ACTIVE              = 0x01
            };


            /**
             *  @brief Constructor for an OccActive sensor
             *
             *  The OCCActiveSensor sensor is used to mark the OCC as functional
             *
             *  The IPMI sensor number for this sensor is associated with
             *  each instance of a Processor target.
             *
             */
            OCCActiveSensor( TARGETING::Target * );

            /**
             *  @brief Destructor for OCC_Active
             *
             */
            ~OCCActiveSensor();

            /**
             *  @brief Interface to set the state of the OCC
             *  active sensor.
             *
             */
            errlHndl_t setState( OccStateEnum i_state );

            /**
             *  @brief Interface to determine if the OCC associated
             *  with the passed in target is active.
             *
             */
            bool isActive();

        private:
            // disable the default constructor
            OCCActiveSensor();

    };

    /*
     *   @brief Return the fault sensor number for a target
     *   Will return either the status sensor or Fault sensor number for a
     *   given target.  If the target passed in does not have either of those
     *   sensor types, the "System Error" sensor number will be returned.
     *
     */
    uint32_t getFaultSensorNumber(TARGETING::ConstTargetHandle_t i_pTarget );


    /**
     *   @brief Update DIMM/CORE/Processor status sensors on the BMC.
     *   Update the present/functional status on the BMC for status sensors
     *   monitored by Hostboot.  The sensor will be updated based on the
     *   HWAS state of the target. Currently handles DIMM/CORE/PROC present
     *   and functional status.
     *
     */
    void updateBMCSensorStatus(void);


    /**
     *   Helper function to update the status sensor for a specific target
     *   type.  Currently supports DIMM, CORE and Processor target types.
     *
     *  @param[in] - i_type, target type to set the status for
     *
     */
    void updateBMCSensorStatus( TARGETING::TYPE i_type );

    /**
     *   Helper function to return the system power limit from the BMC.
     *   This limit is set by the system administrator to limit the amout
     *   of power the system can use.
     *
     *  @param[out] - o_powerLimit  - user defined power limit setting.
     *  @param[out] - o_limitActive - indicates the limit has been activated
     *                                using the dcmi "activate power limit"
     *                                command.
     *
     *  @return Errorlog handle
     */
    errlHndl_t getUserPowerLimit( uint16_t &o_powerLimit,
                                  bool &o_activeActive );

    /**
     *   Helper function to return the system power limit from the BMC.
     *   This limit is set by the system administrator to limit the amount
     *   of power the system can use.
     *
     *  @param[out] - o_sensor_numbers - pointer to a static array containing
     *                                   the sensor numbers for each of the 16
     *                                   apss channels
     *
     *  @return Errorlog handle
     *
     */
    errlHndl_t getAPSSChannelSensorNumbers(
                                     const uint32_t (* &o_sensor_numbers)[16]);

    /**
     *   Helper function to return a mask of the supported masks for the
     *   sensor passed in.
     *
     *  @param[i] - sensor name to determine the offset for.
     *  @param[o] - sensor reading type, defined in IPMI spec for the
     *              passed in sensor number.
     *
     *
     *  @return sensor offsets
     */
    uint16_t getSensorOffsets(TARGETING::SENSOR_NAME i_name,
                              sensorReadingType &o_readType );

    /**
     *   Helper function to return the backplane fault sensor
     *
     *  @return sensor number
     */
    uint8_t getBackPlaneFaultSensor();

    /**
     * @brief Maximum GPU sensors on a single processor
     */
    static const uint8_t MAX_GPU_SENSORS_PER_PROCESSOR = 3;

    /**
     *  @brief Grab the GPU sensor type IDs for a particular processor target
     *
     *   Will return all sensor ids that match the type for a given target.
     *
     *  @param[in] - i_proc  - processor target
     *  @param[in] - i_type  - Functional/state, gpucoretemp, gpumemtemp
     *  @param[out] - o_num_ids - number of valid IDs returned in o_ids
     *  @param[out] - o_ids     - ordered list of sensor IDs
     *
     *  @return Errorlog handle
     */
    errlHndl_t getGpuSensors( TARGETING::Target* i_proc,
                              HWAS::sensorTypeEnum i_type,
                              uint8_t & o_num_ids,
                              uint32_t o_ids[MAX_GPU_SENSORS_PER_PROCESSOR] );

    /**
     * @brief Maximum number of GPUs associated with a processor
     */
    static const uint8_t MAX_PROCESSOR_GPUS = 3;

    /**
     *  @brief  Updates GPU sensor status for GPUs on this
     *          particular processor target
     *
     *  @param[in] - i_proc       - processor target
     *  @param[in] - i_gpu_status - status of GPU0, GPU1 and GPU2
     */
    void updateGpuSensorStatus( TARGETING::Target* i_proc,
                    StatusSensor::statusEnum i_gpu_status[MAX_PROCESSOR_GPUS] );


}; // end namespace

#endif
OpenPOWER on IntegriCloud