summaryrefslogtreecommitdiffstats
path: root/src/usr/htmgt/htmgt_occ.H
blob: e29565fe6990c3c309d17b5e6ae9a2390fdfcbf7 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/htmgt/htmgt_occ.H $                                   */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2014,2016                        */
/* [+] 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                                                     */

#ifndef HTMGT_OCC_H
#define HTMGT_OCC_H

#include <stdint.h>
#include <vector>
#if defined(CONFIG_BMC_IPMI)
#include <ipmi/ipmisensor.H>
#endif


namespace HTMGT
{

    const uint8_t  MASTER_OCC = 0xFF;

    const uint32_t OCC_POLL_DATA_MIN_SIZE = 40;


    enum occStateId
    {
        OCC_STATE_NO_CHANGE                = 0x00,
        OCC_STATE_STANDBY                  = 0x01,
        OCC_STATE_OBSERVATION              = 0x02,
        OCC_STATE_ACTIVE                   = 0x03,
        OCC_STATE_SAFE                     = 0x04,
        OCC_STATE_RESET                    = 0x05,
        OCC_STATE_IN_TRANSITION            = 0x07,
        OCC_STATE_LOADING                  = 0x08,
        OCC_STATE_UNKNOWN                  = 0x09,
    };

    enum occRole
    {
        OCC_ROLE_SLAVE          = 0x00,
        OCC_ROLE_MASTER         = 0x01,
        OCC_ROLE_BACKUP_MASTER  = 0x02,
        OCC_ROLE_FIR_MASTER     = 0x80
    };

    enum
    {
        OCC_RESET_COUNT_THRESHOLD   = 3,
    };

    enum occResetReason
    {
        OCC_RESET_REASON_NONE              = 0x00,
        OCC_RESET_REASON_CRIT_FAILURE      = 0x01,
        OCC_RESET_REASON_PWR_ON_FAIL       = 0x02,
        OCC_RESET_REASON_ERROR             = 0x03,
        OCC_RESET_REASON_POWER_FAULT       = 0x04,
        OCC_RESET_REASON_DIFF_OCC          = 0x05,
        OCC_RESET_REASON_OCC_REQUEST       = 0x06,
    };

    // OCC Callout Structure
    struct occErrlCallout
    {
        uint8_t     type;
        uint64_t    calloutValue;
        uint8_t     priority;
        uint16_t    reserved1;
    } __attribute__ ((__packed__));
    typedef struct occErrlCallout occErrlCallout_t;


    /**
     *  @class Occ
     *
     *  @brief OCC data class
     *
     *  @par Detailed Description:
     *      Provides configuration data for a specific OCC.
     *      Data will be saved during IPL so it can be used
     *      at runtime.
     */
    class Occ
    {
        friend class OccManager;
        friend class OccCmd;

        public:
            /**
             * @brief Constructor
             *
             * @param[in] i_instance       OCC instance number
             * @param[in] i_masterCapable  Is OCC capable of being master
             * @param[in] i_homer          Virtual address of HOMER
             * @param[in] i_target         OCC target pointer
             */
            Occ(const uint8_t   i_instance,
                const bool      i_masterCapable,
                uint8_t       * i_homer,
                TARGETING::TargetHandle_t i_target,
                const occRole   i_role);


            /**
             * @brief Destructor
             */
            ~Occ();


            /**
             * @brief Return the instance nubmer
             *
             * @return instance number for this OCC
             */
            uint8_t getInstance() { return iv_instance; };


            /**
             * @brief Return pointer to the last poll response
             *
             * @param[out] o_pollRspPtr  pointer to last poll rsp data
             *
             * @return true if data is valid, else false
             */
            bool getLastPollRsp(const uint8_t * & o_pollRspPtr)
            {
                o_pollRspPtr = iv_lastPollResponse;
                return iv_lastPollValid;
            };


            /**
             * @brief Return pointer OCC target
             *
             * @return pointer to last poll response
             */
            TARGETING::TargetHandle_t getTarget() { return iv_target; };


            /**
             * @brief Poll for Errors
             *
             * @param[in]  i_flushAllErrors:
             *      If set to true, HTMGT will send poll cmds
             *      to the OCC as long as the OCC continues
             *      to report errors.  If false, only one
             *      poll will be sent.
             *
             * @return NULL on success, else error handle
             */
            errlHndl_t pollForErrors(const bool i_flushAllErrors = false);


            /**
             * @brief Return true if the specified status bit was set in
             *        the last poll response
             *
             * @param[in]  i_statusBit  Bit(s) to check in the poll response
             *
             * @return true if the bit(s) are set, else false
             */
            bool statusBitSet(const uint8_t i_statusBit);


            /**
             * @brief Set the state of the OCC.
             *        This is only allowed on the master OCC
             *
             * @param[in]  i_state  Desired OCC state
             *
             * @return NULL on success, or error handle on failure
             */
            errlHndl_t setState(const occStateId i_state);


            /**
             * @brief Return OCC role
             *
             * @return role of this OCC
             */
            occRole getRole() { return iv_role; };


            /**
             * @brief Return OCC state
             *
             * @return state of this OCC
             */
            occStateId getState() { return iv_state; };

            /**
             * @brief Prepare this OCC for reset
             * @return return true if at threshold otherwise false
             */
            bool resetPrep();

            /**
             * @brief Set IPMI OCC sensor state
             * @param i_activate: true - set active
             *                    false - set inactive
             *
             * @return error log on error
             */
            errlHndl_t ipmiSensor(bool i_activate)
            {
#if !defined(CONFIG_BMC_IPMI)
                return NULL;
#else
                return SENSOR::OCCActiveSensor(iv_target).setState
                    (i_activate ? SENSOR::OCCActiveSensor::OCC_ACTIVE :
                                SENSOR::OCCActiveSensor::OCC_NOT_ACTIVE);
#endif
            }


            /**
             * @brief Set failed state
             * @param[in] failed state
             */
            void failed(bool i_state) { iv_failed = i_state; }


            /**
             * @brief Determine if OCC needs to be reset
             *
             * @return true if this OCC needs to be reset
             */
            bool needsReset() { return iv_needsReset; }


            /**
             * @brief Return OCCs present bits
             *
             * @return bitmask representing this OCC position
             */
            uint8_t getPresentBits() { return iv_occsPresent; };


            /**
             * @brief Update OCCs present bits in the master OCC
             *
             * @note Should only be called for Maseter OCC.  This is
             *       used to ensure the master can see all Slave OCCs
             *       and that no two slaves have same chip id.
             *
             * @param[in]  i_slavePresent  Bitmask for slave OCC to add
             */
            void updateOccPresentBits(uint8_t i_slavePresent);

        private:   // functions

            /**
             * @brief Process an OCC poll response
             *
             * @param[in] i_pollResponse      pointer to the response
             * @param[in] i_pollResponseSize  length of the poll response
             */
            void pollRspHandler(const uint8_t * i_pollResponse,
                                const uint16_t i_pollResponseSize);

            /**
             * @brief Collect, Commit and Clear error log from the OCC
             *
             * @param[in] i_id       OCC elog id to retrieve
             * @param[in] i_address  SRAM address for elog entry
             * @param[in] i_length   size of the elog entry
             */
            void occProcessElog(const uint8_t  i_id,
                                const uint32_t i_address,
                                const uint16_t i_length);

            /**
             * @brief Determine what actions are required for elog
             *
             * @param[in]  i_actions       Action requested by OCC
             * @param[out] o_occReset      returns true if OCC reset is needed
             * @param[out] o_errlSeverity  severity to use for elog commit
             */
            void elogProcessActions(const uint8_t i_actions,
                                    bool        & o_occReset,
                                    ERRORLOG::errlSeverity_t & o_errlSeverity);

            /**
             * @brief Add specified callout to the error log
             *
             * @param[in,out] io_errlHndl     elog to add callout
             * @param[in]     i_priority      priority for callout
             * @param[in]     i_callout       callout from OCC
             * @param[in,out] io_numCallouts  number of callouts in elog,
             *                                incremented if new callout added
             * */
            bool elogAddCallout(errlHndl_t &               io_errlHndl,
                                HWAS::callOutPriority    & i_priority,
                                const occErrlCallout_t     i_callout,
                                uint8_t &                  io_callout_num);

        protected:
            // Instance number of this OCC: 0 = first physical OCC
            uint8_t         iv_instance;
            // true if this OCC is capable of Master role (wired to APSS)
            bool            iv_masterCapable;
            // Role of this OCC
            occRole         iv_role;
            // State of this OCC
            occStateId      iv_state;
            // true if communication to this OCC has been established
            bool            iv_commEstablished;
            // true if OCC needs to be reset
            bool            iv_needsReset;
            // true if OCC failed
            bool            iv_failed;
            // Sequence number of last/current OCC command
            uint8_t         iv_seqNumber;
            // HOMER base address
            uint8_t *       iv_homer;
            // OCC target
            TARGETING::TargetHandle_t iv_target;
            // Last poll response (excluding sensor data)
            uint8_t         iv_lastPollResponse[OCC_POLL_DATA_MIN_SIZE];
            // true if lastPollResponse contains valid data
            bool            iv_lastPollValid;
            // expected occsPresent byte in POLL response
            uint8_t         iv_occsPresent;

            occResetReason  iv_resetReason;

            // Value of last exception committed (to prevent duplicates)
            uint8_t         iv_exceptionLogged;

            /**
             * @brief Clear flags after OCC has been reset
             */
            void postResetClear();


        private:
            // Reset count
            uint8_t         iv_resetCount;
            // Version of data stored (0 = not written)
            uint8_t         iv_version;

    };



    /**
     *  @class OccManager
     *
     *  @brief System / Node class
     *
     *  @par Detailed Description:
     *      Manages all Occ classes and contains data specific to
     *      this system / node.
     */
    class OccManager
    {
        friend class Occ;

        public:
            /**
             * @brief Constructor
             */
            OccManager();


            /**
             * @brief Destructor
             */
            ~OccManager();


            /**
             * @brief Query the functional OCCs and build OCC objects
             *
             * @return NULL on success, or error handle on failure
             */
            static errlHndl_t buildOccs();


            /**
             * @brief Get number of functional OCCs
             *
             * @return number of OCCs
             */
            static uint8_t getNumOccs();


            /**
             * @brief Return array of current OCCs
             *
             * @return vector of OCC objects
             */
            static std::vector<Occ*> getOccArray();


            /**
             * @brief Return pointer to master OCC
             *
             * @return pointer to master OCC
             */
            static Occ * getMasterOcc();


            /**
             * @brief Return pointer to specified OCC
             *
             * @return pointer to specified OCC or NULL if not found
             */
            static Occ * getOcc(const uint8_t i_instance);


            /**
             * @brief Reset the OCCs
             *
             * @param[in] Failing occ target
             * @param[in] i_skipCountIncrement  true will prevent incrementing
             *            the system reset count
             * @param[in] i_skipComm            true will prevent attempts to
             *            communicate with OCC before reset (poll/resetPrep)
             *            Used when exiting safe mode.
             * @return Error Log | NULL
             */
            static errlHndl_t resetOccs(TARGETING::Target * i_failedOccTarget,
                                        bool i_skipCountIncrement = false,
                                        bool i_skipComm = false);


            /**
             * @brief Set the state of the OCCs.  If i_state is
             *        not specified (NO_CHANGE), OCCs will be set
             *        to the target state (last requested state
             *        or if not requested the default is ACTIVE)
             *
             * @param[in]  i_state  Desired OCC state
             *
             * @return NULL on success, or error handle on failure
             */
            static errlHndl_t setOccState(const occStateId i_state =
                                          OCC_STATE_NO_CHANGE);


            /**
             * @brief Get the OCC state that should be used after the OCCs
             *        have been loaded or reset
             *
             * @note Target state will default to ACTIVE, but
             *       can be changed with HTMGT::enableOccActuation()
             *
             * @return target state
             */
            static occStateId getTargetState();



            /**
             * @brief Wait for all of the OCCs to reach their checkpoint
             *        state.  That indicates that the OCCs are ready to
             *        communicate and start handling commands.  This
             *        function will wait up to 10 seconds for all OCCs
             *        before returning to the caller.
             */
            static void waitForOccCheckpoint();


            /**
             * @brief Send a poll command to one or all OCCs
             *
             * @param[in]  i_flushAllErrors:
             *                 If set to true, HTMGT will send poll cmds
             *                 to each OCC that is selected as long as that OCC
             *                 continues to report errors.  If false, only one
             *                 poll will be send to each OCC.
             * @param[in] i_occTarget: The Selected OCC or NULL for all OCCs
             *
             * @return NULL on success, else error handle
             */
            static errlHndl_t
                sendOccPoll(const bool i_flushAllErrors = false,
                            TARGETING::Target * i_occTarget = NULL);


            /**
             * @brief Save the reason that the system is entering safe mode
             *
             * @param[in]  i_src       SRC which triggered safe mode
             * @param[in]  i_instance  OCC which triggered safe mode
             */
            static void updateSafeModeReason(uint32_t i_src,
                                             uint32_t i_instance);


            /**
             * @brief Return the reason the system entered safe mode
             *
             * @param[out]  o_instance   OCC instance
             *
             * @return     SRC which triggered safe mode
             */
            static uint32_t getSafeModeReason(uint32_t & o_instance);


            /**
             * @brief Check if any OCCs need to be reset
             *
             * @return true if any OCC needs to be reset
             */
            static bool occNeedsReset();


            /**
             * @brief Collect FFDC debug data for HTMGT and OCCs
             *
             * @param[out] o_length Length of data returned in o_data
             * @param[out] o_data   Buffer of 256 bytes where data will
             *                      be copied
             */
            static void getOccData(uint16_t & o_length, uint8_t *o_data);


            /**
             * @brief Load specified pstate tables for all OCCs.
             *        This will reset all OCCs so they pick up the new
             *        tables.
             *
             * @param[in] i_normalPstates true to generate normal pstate tables
             *                            false to generate mfg pstate tables
             *
             * @return NULL on success, else error handle
             */
            static errlHndl_t loadPstates(bool i_normalPstates);


            /**
             * @brief Determine if normal pstate tables should be used
             *
             * @return true if normal pstates should be used
             */
            static bool isNormalPstate();


            /**
             * @brief Determine if normal pstate tables should be used
             *
             * @param[in] i_useNormal  Set to true if normal pstate table
             *                         should be used (vs MFG table)
             */
            static void setPstateTable(bool i_useNormal);


            /**
             * @brief Update error log with safe mode callouts and set
             *        attribute indicating system is in safe mode.
             *
             * @param[in,out] io_err  Error log to be updated
             * */
            void updateForSafeMode(errlHndl_t & io_err);


            /**
             * @brief Check if any OCC has failed
             *
             * @return true if any OCC has been marked as failed
             */
            static bool occFailed();


            /**
             * @brief Update OCC manager state with consolidated OCC state
             *
             */
            static void syncOccStates();


            /**
             * @brief Clear all OCC reset counts
             *
             */
            static void clearResetCounts();


        private:

            typedef std::vector<Occ*> occList_t;

            Occ *                   iv_occMaster;
            occList_t               iv_occArray;
            occStateId              iv_state;
            occStateId              iv_targetState;
            uint8_t                 iv_resetCount;
            bool                    iv_normalPstateTables;


            /**
             * @brief SRC that caused system to enter safe mode
             */
            static uint32_t         cv_safeReturnCode;

            /**
             * @brief OCC instance that triggered safe mode
             */
            static uint32_t         cv_safeOccInstance;


            /* See buildOccs() above */
            errlHndl_t _buildOccs();


            /* See getNumOccs() above */
            uint8_t _getNumOccs() { return iv_occArray.size(); };


            /* See getOccArray() above */
            std::vector<Occ*> _getOccArray() { return iv_occArray; };


            /* See getTargetState() above */
            occStateId _getTargetState() { return iv_targetState; };


            /**
             * @brief Remove all OCC objects
             */
            void _removeAllOccs();


            /**
             * @brief Add a functional OCC to be monitored
             *
             * @param[in] i_instance       OCC instance number
             * @param[in] i_masterCapable  Is OCC capable of being master
             * @param[in] i_homer          Virtual address of HOMER
             * @param[in] i_target         OCC target pointer
             * @param[in] i_role           OCC role
             */
            void  _addOcc(const uint8_t   i_instance,
                          const bool      i_masterCapable,
                          uint8_t       * i_homer,
                          TARGETING::TargetHandle_t i_target);


            /* See getMasterOcc() above */
            Occ * _getMasterOcc() { return iv_occMaster; };


            /* See getOcc() above */
            Occ * _getOcc(const uint8_t i_instance);


            /* See setOccState() above */
            errlHndl_t _setOccState(const occStateId i_state);

            void _waitForOccCheckpoint();

            /* See resetOccs() above */
            errlHndl_t _resetOccs(TARGETING::Target * i_failedOccTarget,
                                  bool i_skipCountIncrement = false,
                                  bool i_skipComm = false);

            /** See sendOccPoll() above */
            errlHndl_t
                _sendOccPoll(const bool i_flushAllErrors,
                            TARGETING::Target * i_occTarget);

            /** See updateSafeModeReason() above */
            void _updateSafeModeReason(uint32_t i_src,
                                       uint32_t i_instance);

            /** See getSafeModeReason() above */
            uint32_t _getSafeModeReason(uint32_t & o_instance);

            /** See occNeedsReset() above */
            bool _occNeedsReset();

            /** See occFailed() above */
            bool _occFailed();

            /** See getOccData() above */
            void _getOccData(uint16_t & o_length, uint8_t *o_data);

            /** See loadPstates() above */
            errlHndl_t _loadPstates(bool i_normalPstates);

            /** See isNormalPstate() above */
            bool _isNormalPstate()
            {
                return(true == iv_normalPstateTables);
            };

            /** See setPstateTable() above */
            void _setPstateTable(bool i_useNormal)
            {
                iv_normalPstateTables = i_useNormal;
            };

            /** See syncOccStates() above */
            void _syncOccStates();

            /** See clearResetCounts() above */
            void _clearResetCounts();
    };

    typedef Singleton<OccManager> occMgr;

} // end namespace
#endif
OpenPOWER on IntegriCloud