summaryrefslogtreecommitdiffstats
path: root/src/occ_405/state.c
blob: a0efa22541cfc770d144e1734adbf1d8f56bef0a (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
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/occ_405/state.c $                                         */
/*                                                                        */
/* OpenPOWER OnChipController Project                                     */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2011,2017                        */
/* [+] 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                                                     */

#include <occ_common.h>
#include <common_types.h>
#include <centaur_data.h>
#include "ssx_io.h"
#include "trac.h"
#include "rtls.h"
#include "state.h"
#include "dcom.h"
#include "occ_service_codes.h"
#include "cmdh_fsp_cmds_datacnfg.h"
#include "cmdh_fsp.h"
#include "proc_data.h"
#include "scom.h"
#include <fir_data_collect.h>
#include <dimm.h>
#include "pgpe_interface.h"
#include "pstate_pgpe_occ_api.h"
#include "amec_sys.h"

// Maximum time to wait for a PGPE task before timeout
// must wait at least 1 tick time to ensure proc_data_control() runs to set
// clips on active->obs state transition
#define WAIT_PGPE_TASK_TIMEOUT (MICS_PER_TICK + 20)

extern bool G_mem_monitoring_allowed;
extern task_t G_task_table[TASK_END];  // Global task table
extern bool G_simics_environment;

extern pstateStatus G_proc_pstate_status;
extern uint16_t G_proc_fmax_mhz;
extern GpeRequest G_clip_update_req;
extern GPE_BUFFER(ipcmsg_clip_update_t*  G_clip_update_parms_ptr);

// OCC is ready to transition to observation state?
extern bool G_active_to_observation_ready;

extern PMCR_OWNER G_proc_pmcr_owner;

// State that OCC is currently in
OCC_STATE          G_occ_internal_state     = OCC_STATE_STANDBY;

// State that OCC is requesting that TMGT put OCC into
OCC_STATE          G_occ_internal_req_state = OCC_STATE_NOCHANGE;

// State that TMGT wants to put OCC into
OCC_STATE          G_occ_external_req_state = OCC_STATE_NOCHANGE;

// Indicates if we are currently in a state transition
bool               G_state_transition_occuring = FALSE;

// State that OCC Master is requesting
OCC_STATE          G_occ_master_state       = OCC_STATE_NOCHANGE;

// Semaphore to allow state change to be called from multiple threads
SsxSemaphore G_smgrStateChangeSem;

// Table that indicates which functions should be run for a given mode
// transition.
const smgr_state_trans_t G_smgr_state_trans[] =
{
    /* ----- SPECIFIC CASE STATE TRANSITIONS ----- */
    /* These are specific state transitions for when it matters what
     * state we were in before the transition.  These must come before
     * the agnostic state transitions below, and will be run instead of
     * those catch-all transition functions. */

    /* Current State        New State              Transition Function */
    {OCC_STATE_STANDBY,          OCC_STATE_OBSERVATION,      &SMGR_standby_to_observation},
    {OCC_STATE_STANDBY,          OCC_STATE_CHARACTERIZATION, &SMGR_standby_to_characterization},
    {OCC_STATE_STANDBY,          OCC_STATE_ACTIVE,           &SMGR_standby_to_active},
    {OCC_STATE_OBSERVATION,      OCC_STATE_CHARACTERIZATION, &SMGR_observation_to_characterization},
    {OCC_STATE_OBSERVATION,      OCC_STATE_ACTIVE,           &SMGR_observation_to_active},
    {OCC_STATE_CHARACTERIZATION, OCC_STATE_OBSERVATION,      &SMGR_characterization_to_observation},
    {OCC_STATE_CHARACTERIZATION, OCC_STATE_ACTIVE,           &SMGR_characterization_to_active},
    {OCC_STATE_ACTIVE,           OCC_STATE_OBSERVATION,      &SMGR_active_to_observation},
    {OCC_STATE_ACTIVE,           OCC_STATE_CHARACTERIZATION, &SMGR_active_to_characterization},

    /* ----- DEFAULT STATE TRANSITIONS ----- */
    /* These are default state transitions for when it doesn't matter what
     * state we were in before the transition. */

    /* Current State        New State              Transition Function */
    {OCC_STATE_ALL,         OCC_STATE_STANDBY,     &SMGR_all_to_standby},
    {OCC_STATE_ALL,         OCC_STATE_SAFE,        &SMGR_all_to_safe},
};

const uint8_t G_smgr_state_trans_count = sizeof(G_smgr_state_trans)/sizeof(smgr_state_trans_t);


uint32_t G_smgr_validate_data_active_mask = SMGR_VALIDATE_DATA_ACTIVE_MASK_HARDCODES;
uint32_t G_smgr_validate_data_observation_mask = SMGR_VALIDATE_DATA_OBSERVATION_MASK_HARDCODES;

// Function Specification
//
// Name: SMGR_is_state_transitioning
//
// Description: Indicates if we are transitioning between states
//
// End Function Specification
inline bool SMGR_is_state_transitioning(void)
{
   return G_state_transition_occuring;
}


// Function Specification
//
// Name:
//
// Description:
//
// End Function Specification
errlHndl_t SMGR_standby_to_observation()
{
    errlHndl_t              l_errlHndl = NULL;
    static bool L_error_logged = FALSE;  // To prevent trace and error log happened over and over

    if( SMGR_MASK_OBSERVATION_READY ==
        (SMGR_validate_get_valid_states() & SMGR_MASK_OBSERVATION_READY))
    {
        L_error_logged = FALSE;
        TRAC_IMP("SMGR: Standby to Observation Transition Started");

        memory_init();

        // Set the RTL Flags to indicate which tasks can run
        //   - Set OBSERVATION b/c we're in OBSERVATION State
        rtl_clr_run_mask_deferred(RTL_FLAG_STANDBY);
        rtl_set_run_mask_deferred(RTL_FLAG_OBS);

        // Set the actual STATE now that we have finished everything else
        CURRENT_STATE() = OCC_STATE_OBSERVATION;

        TRAC_IMP("SMGR: Standby to Observation Transition Completed");

    }
    else if(FALSE == L_error_logged)
    {
        L_error_logged = TRUE;
        TRAC_ERR("SMGR: Standby to Observation Transition Failed due to not OBS_READY");
        /* @
         * @errortype
         * @moduleid    MAIN_STATE_TRANSITION_MID
         * @reasoncode  INTERNAL_FAILURE
         * @userdata1   none
         * @userdata4   ERC_STATE_FROM_STB_TO_OBS_FAILURE
         * @devdesc     Failed changing from standby to observation
         */
        l_errlHndl = createErrl(MAIN_STATE_TRANSITION_MID,        //modId
                                INTERNAL_FAILURE,                 //reasoncode
                                ERC_STATE_FROM_STB_TO_OBS_FAILURE,//Extended reason code
                                ERRL_SEV_UNRECOVERABLE,           //Severity
                                NULL,                             //Trace Buf
                                DEFAULT_TRACE_SIZE,               //Trace Size
                                0,                                //userdata1
                                0);                               //userdata2

        // Callout firmware
        addCalloutToErrl(l_errlHndl,
                     ERRL_CALLOUT_TYPE_COMPONENT_ID,
                     ERRL_COMPONENT_ID_FIRMWARE,
                     ERRL_CALLOUT_PRIORITY_HIGH);
    }
    return l_errlHndl;
}


// Function Specification
//
// Name: SMGR_standby_to_characterization
//
// Description: switch from standby state to characterization state
//
// End Function Specification
errlHndl_t SMGR_standby_to_characterization()
{
    errlHndl_t  l_errlHndl = NULL;
    int         rc = 0;
    static bool L_error_logged = FALSE;  // To prevent trace and error log happened over and over
    Pstate      l_pstate;
    do
    {
        // characterization state will have Pstate protocol enabled check that all data for active
        // is available (frequency points)
        if( SMGR_MASK_ACTIVE_READY ==
            (SMGR_validate_get_valid_states() & SMGR_MASK_ACTIVE_READY))
        {
            L_error_logged = FALSE;
            TRAC_IMP("SMGR: Standby to Characterization State Transition Started");

            // set pstate clips
            l_pstate = proc_freq2pstate(G_proc_fmax_mhz);
            rc = pgpe_set_clip_blocking(l_pstate);

            if(rc)
            {
                TRAC_ERR("SMGR: failed to set pstate clips.");
                break;
            }
            else // successfully set clips; enable pstates, then start transition
            {

                // Start pstates on PGPE and set Characterization as owner
                rc = pgpe_start_suspend(PGPE_ACTION_PSTATE_START, PMCR_OWNER_CHAR);

                if(rc)
                {
                    TRAC_ERR("SMGR: failed to start the pstate protocol for char owner on PGPE.");
                    break;
                }
                else // Clips set and pstates started successfully, start transition
                {
                    memory_init();

                    // Set the RTL Flags to indicate which tasks can run
                    //   - Set OBSERVATION flags in Characterization State
                    rtl_clr_run_mask_deferred(RTL_FLAG_STANDBY);
                    rtl_set_run_mask_deferred(RTL_FLAG_OBS);

                    // Set the actual STATE now that we have finished everything else
                    CURRENT_STATE() = OCC_STATE_CHARACTERIZATION;

                    TRAC_IMP("SMGR: Standby to Characterization Transition Completed");
                }
            }
        }
    } while (0);

    if(l_errlHndl && (false == L_error_logged))
    {
        L_error_logged = TRUE;
        TRAC_ERR("SMGR: Standby to Characterization Transition Failed due to not ACTIVE_READY");
        /* @
         * @errortype
         * @moduleid    MAIN_STATE_TRANSITION_MID
         * @reasoncode  INTERNAL_FAILURE
         * @userdata1   none
         * @userdata4   ERC_STATE_FROM_STB_TO_CHR_FAILURE
         * @devdesc     Failed changing from standby to characterization
         */
        l_errlHndl = createErrl(MAIN_STATE_TRANSITION_MID,          //modId
                                INTERNAL_FAILURE,                   //reasoncode
                                ERC_STATE_FROM_STB_TO_CHR_FAILURE,  //Extended reason code
                                ERRL_SEV_UNRECOVERABLE,             //Severity
                                NULL,                               //Trace Buf
                                DEFAULT_TRACE_SIZE,                 //Trace Size
                                0,                                  //userdata1
                                0);                                 //userdata2

        // Callout firmware
        addCalloutToErrl(l_errlHndl,
                         ERRL_CALLOUT_TYPE_COMPONENT_ID,
                         ERRL_COMPONENT_ID_FIRMWARE,
                         ERRL_CALLOUT_PRIORITY_HIGH);
    }

    return l_errlHndl;
}


// Function Specification
//
// Name: SMGR_all_to_standby
//
// Description: Switch from any state to standby state
//
// End Function Specification
errlHndl_t SMGR_all_to_standby()
{
    uint8_t     wait_time = 0;
    int         rc;

    TRAC_IMP("SMGR: Transition from State (%d) to Standby Started", CURRENT_STATE());

    // if Psates in transition (a pgpe_start_suspend IPC call still running),
    // wait until it is settled up to WAIT_PGPE_TASK_TIMEOUT usec
    while( (G_proc_pstate_status == PSTATES_IN_TRANSITION) &&
           (wait_time < WAIT_PGPE_TASK_TIMEOUT) )
    {
        // wait until pgpe_start_suspend call is completed. Sleep enables context switching.
        ssx_sleep(SSX_MICROSECONDS(10));
        wait_time += 10;
    }

    // check for timeout while waiting for pgpe_start_suspend() IPC completion
    if(wait_time >= WAIT_PGPE_TASK_TIMEOUT)
    {
        TRAC_ERR("SMGR_all_to_standby: Timeout waiting for Pstates start/suspend IPC task");
    }
    // Stop Pstates if enabled
    else if(G_proc_pstate_status == PSTATES_ENABLED)
    {
        rc = pgpe_start_suspend(PGPE_ACTION_PSTATE_STOP, G_proc_pmcr_owner);
        if(rc)
        {
            TRAC_ERR("SMGR_all_to_standby: Failed to stop the pstate protocol on PGPE. rc[%08X]", rc);
        }
    }

    // Pstates should be disabled, ready to safely transition to standby
    // Set the RTL Flags to indicate which tasks can run
    //   - Clear ACTIVE b/c not in ACTIVE State
    //   - Clear OBSERVATION b/c not in CHARACTERIZATION State
    rtl_clr_run_mask_deferred(RTL_FLAG_ACTIVE | RTL_FLAG_OBS );
    rtl_set_run_mask_deferred(RTL_FLAG_STANDBY);

    // Set the actual STATE now that we have finished everything else
    CURRENT_STATE() = OCC_STATE_STANDBY;

    TRAC_IMP("SMGR: Transition to Standby Completed");

    return NULL;
}

// Function Specification
//
// Name: SMGR_characterization_to_observation
//
// Description: Switch from characterization to observation state
//
// End Function Specification
errlHndl_t SMGR_characterization_to_observation()
{
    errlHndl_t  l_errlHndl     = NULL;
    int         rc             = 0;
    Pstate      l_pstate;
    TRAC_IMP("SMGR: Characterization to Observation Transition Started");

    do
    {
        // set clips to legacy turbo
        l_pstate = proc_freq2pstate(G_sysConfigData.sys_mode_freq.table[OCC_MODE_TURBO]);
        rc = pgpe_set_clip_blocking(l_pstate);
        if(rc)
        {
            TRAC_ERR("SMGR_char_to_obs: failed to set pstate clip to legacy turbo rc[%08X]", rc);
            break;
        }
        else // clips set to legacy turbo; stop pstate protocol
        {
            rc = pgpe_start_suspend(PGPE_ACTION_PSTATE_STOP, G_proc_pmcr_owner);
            if(rc)
            {
                TRAC_ERR("SMGR_char_to_obs: Failed to stop pstate protocol rc[%08X]", rc);
                break;
            }
            else // Clips tightened successfully, and pstates disabled: perform transition
            {
                // No RTL Flag changes; only state change
                CURRENT_STATE() = OCC_STATE_OBSERVATION;

                TRAC_IMP("SMGR: Characterization to Observation Transition Completed");
            }
        }
    } while (0);

    if(rc)
    {
        TRAC_ERR("SMGR: Characterization to Observation Transition Failed");

        /* @
         * @errortype
         * @moduleid    MAIN_STATE_TRANSITION_MID
         * @reasoncode  INTERNAL_FAILURE
         * @userdata1   rc
         * @userdata4   ERC_STATE_FROM_CHR_TO_OBS_FAILURE
         * @devdesc     Failed changing from observation to characterization
         */
        l_errlHndl = createErrl(MAIN_STATE_TRANSITION_MID,          //modId
                                INTERNAL_FAILURE,                   //reasoncode
                                ERC_STATE_FROM_CHR_TO_OBS_FAILURE,  //Extended reason code
                                ERRL_SEV_UNRECOVERABLE,             //Severity
                                NULL,                               //Trace Buf
                                DEFAULT_TRACE_SIZE,                 //Trace Size
                                rc,                                 //userdata1
                                0);                                 //userdata2

        // Callout firmware
        addCalloutToErrl(l_errlHndl,
                         ERRL_CALLOUT_TYPE_COMPONENT_ID,
                         ERRL_COMPONENT_ID_FIRMWARE,
                         ERRL_CALLOUT_PRIORITY_HIGH);
    }

    return l_errlHndl;
}


// Function Specification
//
// Name: SMGR_observation_to_characterization
//
// Description: Switch from Observation to Characterization state
//
// End Function Specification
errlHndl_t SMGR_observation_to_characterization()
{
    int         rc             = 0;
    errlHndl_t  l_errlHndl     = NULL;
    static bool L_error_logged = FALSE;  // To prevent trace and error logging over and over
    Pstate      l_pstate;
    TRAC_IMP("SMGR: Observation to Characterization Transition Started");

    // no change in RTL flags, just turn-on pstate protocol, and set clips

    do
    {
        // Must be active ready if transitioning to characterization state
        if( (SMGR_MASK_ACTIVE_READY !=
             (SMGR_validate_get_valid_states() & SMGR_MASK_ACTIVE_READY)) )
        {
            TRAC_ERR("SMGR: failed to transition to characterization state "
                     "since OCC is not active ready.");
            break;
        }
        // set pstate clips
        l_pstate = proc_freq2pstate(G_proc_fmax_mhz);
        rc = pgpe_set_clip_blocking(l_pstate);

        if(rc)
        {
            TRAC_ERR("SMGR_obs_to_char: failed to set pstate clips rc[%08X]", rc);
            break;
        }
        else // successfully set clips; enable pstates, then start transition
        {
            // Start pstates on PGPE and set Characterization as owner
            rc = pgpe_start_suspend(PGPE_ACTION_PSTATE_START, PMCR_OWNER_CHAR);

            if(rc)
            {
                TRAC_ERR("SMGR_obs_to_char: failed to start pstate protocol rc[%08X]", rc);
                break;
            }
            else // Clips set successfully and pstates enabled; complete transition
            {
                // Set the actual STATE now that we have finished everything else
                CURRENT_STATE() = OCC_STATE_CHARACTERIZATION;

                TRAC_IMP("SMGR: Observation to Characterization Transition Completed");
            }
        }
    } while (0);

    if(rc && (false == L_error_logged))
    {
        L_error_logged = TRUE;
        TRAC_ERR("SMGR: Observation to Characterization Transition Failed");
        /* @
         * @errortype
         * @moduleid    MAIN_STATE_TRANSITION_MID
         * @reasoncode  INTERNAL_FAILURE
         * @userdata1   rc
         * @userdata4   ERC_STATE_FROM_OBS_TO_CHR_FAILURE
         * @devdesc     Failed changing from observation to characterization
         */
        l_errlHndl = createErrl(MAIN_STATE_TRANSITION_MID,          //modId
                                INTERNAL_FAILURE,                   //reasoncode
                                ERC_STATE_FROM_OBS_TO_CHR_FAILURE,  //Extended reason code
                                ERRL_SEV_UNRECOVERABLE,             //Severity
                                NULL,                               //Trace Buf
                                DEFAULT_TRACE_SIZE,                 //Trace Size
                                rc,                                 //userdata1
                                0);                                 //userdata2

        // Callout firmware
        addCalloutToErrl(l_errlHndl,
                         ERRL_CALLOUT_TYPE_COMPONENT_ID,
                         ERRL_COMPONENT_ID_FIRMWARE,
                         ERRL_CALLOUT_PRIORITY_HIGH);
    }

    return l_errlHndl;
}



// Function Specification
//
// Name: SMGR_observation_to_active
//
// Description: Transition from Observation state to Active state
//
// End Function Specification
errlHndl_t SMGR_observation_to_active()
{
    errlHndl_t      l_errlHndl = NULL;
    static bool     L_error_logged = FALSE;  // To prevent trace and error log happened over and over
    int             l_extRc = OCC_NO_EXTENDED_RC;
    int             l_rc = 0;
    Pstate          l_pstate;

    // clear mnfg quad pstate request to default OCC to control all quads
    memset(&g_amec->mnfg_parms.quad_pstate[0], 0xFF, MAXIMUM_QUADS);

    do
    {
        // NOTE that this is really unnecessary if you follow the TMGT OCC
        // Interface Spec, which tells you that you need to check for the "Active
        // Ready" bit in the poll response before you go to active state.
        // But since we have scenerios where TMGT isn't the one putting us in
        // active state (we are going there automatically) we needed to add this.

        // If we have all data we need to go to active state, but don't have pstates
        // enabled yet...then we will do the aforementioned wait
        if(SMGR_MASK_ACTIVE_READY ==
           (SMGR_validate_get_valid_states() & SMGR_MASK_ACTIVE_READY))
        {
            TRAC_IMP("SMGR: Observation to Active Transition Started");
            l_pstate = proc_freq2pstate(G_proc_fmax_mhz);
            l_rc = pgpe_set_clip_blocking(l_pstate);

            if(l_rc)
            {
                TRAC_ERR("SMGR_obs_to_active: Set Pstate clips failed rc[%08X]", l_rc);
                break;
            }

            else // Clips set with no errors, enable Pstates on PGPE
            {

                // Pstates are enabled via an IPC call to PGPE, which will set the
                // G_proc_pstate_status flag. PMCR owner is set based on system type.
                if(G_sysConfigData.system_type.kvm)
                {
                    l_rc = pgpe_start_suspend(PGPE_ACTION_PSTATE_START, PMCR_OWNER_HOST);
                }
                else
                {
                    l_rc = pgpe_start_suspend(PGPE_ACTION_PSTATE_START, PMCR_OWNER_OCC);
                }
                if(l_rc)
                {
                    TRAC_ERR("SMGR_obs_to_active: Failed to start pstate protocol rc[%08X]", l_rc);
                    break;
                }
            }

            // Wait for pstates enablement completition.
            SsxTimebase start = ssx_timebase_get();
            SsxInterval timeout =  SSX_SECONDS(5);
            while( ! proc_is_hwpstate_enabled() )
            {
                if ((ssx_timebase_get() - start) > timeout)
                {
                    l_rc = 1;
                    if(FALSE == L_error_logged)
                    {
                        TRAC_ERR("SMGR_obs_to_active: Timeout waiting for Pstates to be enabled, "
                                 "chips_present[%02x], Cores Present [%08x]",
                                 G_sysConfigData.is_occ_present,
                                 (uint32_t) ((in64(OCB_CCSR)) >> 32));
                    }
                    l_extRc = ERC_GENERIC_TIMEOUT;
                    break;
                }
                ssx_sleep(SSX_MICROSECONDS(10));
            }

            // if pstates are now enabled, all conditions are already met
            // to transition to active state.
            if(proc_is_hwpstate_enabled() )
            {
                TRAC_IMP("SMGR_obs_to_active: Pstates are enabled, continuing with state trans");

                L_error_logged = FALSE;

                // Set the RTL Flags to indicate which tasks can run
                //   - Clear OBSERVATION b/c not in OBSERVATION State
                //   - Set ACTIVE b/c we're in ACTIVE State
                rtl_clr_run_mask_deferred(RTL_FLAG_OBS);
                rtl_set_run_mask_deferred(RTL_FLAG_ACTIVE);

                // Pstates enabled, update OPAL static table in main memory with pState info
                proc_pstate_kvm_setup();

                // Set the actual STATE now that we have finished everything else
                CURRENT_STATE() = OCC_STATE_ACTIVE;
                TRAC_IMP("SMGR: Observation to Active Transition Completed. OCC role = %d", G_occ_role);
            }
            else
            {
                TRAC_ERR("SMGR: Observation to Active Transition Failed, because pstates are not enabled");
            }

            if(l_rc && FALSE == L_error_logged)
            {
                L_error_logged = TRUE;
                /* @
                 * @errortype
                 * @moduleid    MAIN_STATE_TRANSITION_MID
                 * @reasoncode  INTERNAL_FAILURE
                 * @userdata1   SMGR_MASK_ACTIVE_READY
                 * @userdata2   valid states
                 * @userdata4   ERC_GENERIC_TIMEOUT
                 * @devdesc     Failed changing from observation to active
                 */
                l_errlHndl = createErrl(MAIN_STATE_TRANSITION_MID,        //modId
                                        INTERNAL_FAILURE,                 //reasoncode
                                        l_extRc,                          //Extended reason code
                                        ERRL_SEV_UNRECOVERABLE,           //Severity
                                        NULL,                             //Trace Buf
                                        DEFAULT_TRACE_SIZE,               //Trace Size
                                        SMGR_MASK_ACTIVE_READY,           //userdata1
                                        SMGR_validate_get_valid_states());//userdata2

                // Callout firmware
                addCalloutToErrl(l_errlHndl,
                                 ERRL_CALLOUT_TYPE_COMPONENT_ID,
                                 ERRL_COMPONENT_ID_FIRMWARE,
                                 ERRL_CALLOUT_PRIORITY_HIGH);
            }
        }   // Active Ready
        else
        {
            TRAC_ERR("SMGR: Observation to Active Transition Failed, "
                     "OCC is not Active Ready cnfgdata=0x%08x, reqd=0x%08x",
                     DATA_get_present_cnfgdata(),
                     SMGR_VALIDATE_DATA_ACTIVE_MASK);
        }
    } while (0);


    return l_errlHndl;
}

// Function Specification
//
// Name: SMGR_characterization_to_active
//
// Description: Transition from Characterization state to Active state
//
// End Function Specification
errlHndl_t SMGR_characterization_to_active()
{
    int         rc         = 0;
    errlHndl_t  l_errlHndl = NULL;
    static bool L_error_logged = FALSE;  // To prevent trace and error log happened over and over

    TRAC_IMP("SMGR: Characterization to Active Transition Started");

    do
    {
        // change PMCR ownership via an IPC call to PGPE based on system type.
        if(G_sysConfigData.system_type.kvm)
        {
            rc = pgpe_start_suspend(PGPE_ACTION_PSTATE_START, PMCR_OWNER_HOST);
        }
        else
        {
            rc = pgpe_start_suspend(PGPE_ACTION_PSTATE_START, PMCR_OWNER_OCC);
        }
        if(rc)
        {
            TRAC_ERR("SMGR_char_to_active: Failed to change PMCR ownership rc[%08X]", rc);
            break;
        }

        // Wait for ownership change to complete
        SsxTimebase start = ssx_timebase_get();
        SsxInterval timeout =  SSX_SECONDS(5);
        while( ! proc_is_hwpstate_enabled() )
        {
            if ((ssx_timebase_get() - start) > timeout)
            {
                rc = 1;
                TRAC_ERR("SMGR_char_to_active: Timeout waiting for PMCR ownership change");
                break;
            }
            ssx_sleep(SSX_MICROSECONDS(10));
        }

        if(proc_is_hwpstate_enabled())
        {
            L_error_logged = FALSE;

            // Set the RTL Flags to indicate which tasks can run
            //   - Clear OBSERVATION b/c not in CHARACTERIZATION State
            //   - Set ACTIVE b/c we're in ACTIVE State
            rtl_clr_run_mask_deferred(RTL_FLAG_OBS);
            rtl_set_run_mask_deferred(RTL_FLAG_ACTIVE);

            // Set the actual STATE now that we have finished everything else
            CURRENT_STATE() = OCC_STATE_ACTIVE;
            TRAC_IMP("SMGR: Characterization to Active Transition Completed");
        }
    } while (0);

    if(rc && (false == L_error_logged))
    {
        L_error_logged = TRUE;
        /* @
         * @errortype
         * @moduleid    MAIN_STATE_TRANSITION_MID
         * @reasoncode  INTERNAL_FAILURE
         * @userdata1   rc
         * @userdata2   valid states
         * @userdata4   ERC_STATE_FROM_CHR_TO_ACT_FAILURE
         * @devdesc     Failed changing from characterization to active
         */
        l_errlHndl = createErrl(MAIN_STATE_TRANSITION_MID,           //modId
                                INTERNAL_FAILURE,                    //reasoncode
                                ERC_STATE_FROM_CHR_TO_ACT_FAILURE,   //Extended reason code
                                ERRL_SEV_UNRECOVERABLE,              //Severity
                                NULL,                                //Trace Buf
                                DEFAULT_TRACE_SIZE,                  //Trace Size
                                rc,                                  //userdata1
                                SMGR_validate_get_valid_states());   //userdata2

        // Callout firmware
        addCalloutToErrl(l_errlHndl,
                         ERRL_CALLOUT_TYPE_COMPONENT_ID,
                         ERRL_COMPONENT_ID_FIRMWARE,
                         ERRL_CALLOUT_PRIORITY_HIGH);
    }

    return l_errlHndl;
}

// Function Specification
//
// Name:  SMGR_active_to_observation
//
// Description:
//
// End Function Specification

errlHndl_t SMGR_active_to_observation()
{
    int              rc         = 0;
    errlHndl_t       l_errlHndl = NULL;
    uint8_t          wait_time  = 0;

    TRAC_IMP("SMGR: Active to Observation Transition Started");

    do
    {
        // wait until task_core_data_control() declares that
        // OCC is ready to transition to Observation state
        while(!G_active_to_observation_ready)
        {
            if(wait_time > WAIT_PGPE_TASK_TIMEOUT)
            {
                break;
            }

            // Sleep enables context switching.
            ssx_sleep(SSX_MICROSECONDS(10));
            wait_time += 10;
        }

        // check for timeout while waiting for pgpe_start_suspend() IPC completion
        if(wait_time > WAIT_PGPE_TASK_TIMEOUT)
        {
            TRAC_ERR("SMGR_act_to_obs: Timeout waiting for G_active_to_observation_ready flag.");

            /* @
             * @errortype
             * @moduleid    MAIN_STATE_TRANSITION_MID
             * @reasoncode  PGPE_FAILURE
             * @userdata1   wait_time
             * @userdata4   ERC_PGPE_ACTIVE_TO_OBSERVATION_TIMEOUT
             * @devdesc     timeout waiting for pstates start/suspend task
             */
            l_errlHndl = createErrl(MAIN_STATE_TRANSITION_MID,              //modId
                                    PGPE_FAILURE,                           //reasoncode
                                    ERC_PGPE_ACTIVE_TO_OBSERVATION_TIMEOUT, //Extended reason code
                                    ERRL_SEV_UNRECOVERABLE,                 //Severity
                                    NULL,                                   //Trace Buf
                                    DEFAULT_TRACE_SIZE,                     //Trace Size
                                    wait_time,                              //userdata1
                                    0);                                     //userdata2

            // Callout firmware
            addCalloutToErrl(l_errlHndl,
                             ERRL_CALLOUT_TYPE_COMPONENT_ID,
                             ERRL_COMPONENT_ID_FIRMWARE,
                             ERRL_CALLOUT_PRIORITY_HIGH);

            rc = PGPE_FAILURE;
            break;
        }

        wait_time = 0;

        // wait until clip update task is done
        while(!async_request_is_idle(&G_clip_update_req.request))
        {
            if(wait_time > WAIT_PGPE_TASK_TIMEOUT)
            {
                break;
            }

            // wait until pgpe_start_suspend call is completed.
            // Sleep enables context switching.
            ssx_sleep(SSX_MICROSECONDS(10));
            wait_time += 10;
        }

        // check for timeout while waiting for Pstate clips IPC completion
        if(wait_time > WAIT_PGPE_TASK_TIMEOUT)
        {
            TRAC_ERR("SMGR_act_to_obs: Timeout waiting for clip update IPC task");

            /* @
             * @errortype
             * @moduleid    MAIN_STATE_TRANSITION_MID
             * @reasoncode  PGPE_FAILURE
             * @userdata1   wait_time
             * @userdata4   ERC_PGPE_TASK_TIMEOUT
             * @devdesc     timeout waiting for pstates start/suspend task
             */
            l_errlHndl = createErrl(MAIN_STATE_TRANSITION_MID,          //modId
                                    PGPE_FAILURE,                       //reasoncode
                                    ERC_PGPE_TASK_TIMEOUT,              //Extended reason code
                                    ERRL_SEV_UNRECOVERABLE,             //Severity
                                    NULL,                               //Trace Buf
                                    DEFAULT_TRACE_SIZE,                 //Trace Size
                                    wait_time,                          //userdata1
                                    0);                                 //userdata2

            // Callout firmware
            addCalloutToErrl(l_errlHndl,
                             ERRL_CALLOUT_TYPE_COMPONENT_ID,
                             ERRL_COMPONENT_ID_FIRMWARE,
                             ERRL_CALLOUT_PRIORITY_HIGH);

            rc = PGPE_FAILURE;
            break;
        }

        rc = pgpe_start_suspend(PGPE_ACTION_PSTATE_STOP, G_proc_pmcr_owner);
        if(rc)
        {
            TRAC_ERR("SMGR_act_to_obs: failed to stop the pstate protocol on PGPE.");
            break;
        }
        else // Pstates Disabled and clips set successfully, perform state transition
        {
            // Set the RTL Flags to indicate which tasks can run
            //   - Set OBSERVATION b/c in OBSERVATION State
            //   - Clear ACTIVE b/c not in ACTIVE State
            rtl_clr_run_mask_deferred(RTL_FLAG_ACTIVE);
            rtl_set_run_mask_deferred(RTL_FLAG_OBS);

            // Set the actual STATE now that we have finished everything else
            CURRENT_STATE() = OCC_STATE_OBSERVATION;

            // clear G_active_to_observation_ready flag again
            // (for next active_to_observation transition)
            G_active_to_observation_ready = false;
        }

    } while (0);

    if(rc)
    {
        TRAC_ERR("SMGR: Failed with rc = %d to switch to Observation state", rc);
    }
    else
    {
        TRAC_IMP("SMGR: Active to Observation Transition Completed");
    }

    return l_errlHndl;
}


// Function Specification
//
// Name:  SMGR_active_to_characterization
//
// Description: Switch from Active to characterization state
//
// End Function Specification
errlHndl_t SMGR_active_to_characterization()
{
    int          rc         = 0;
    errlHndl_t   l_errlHndl = NULL;
    Pstate       l_pstate;

    TRAC_IMP("SMGR: Active to Characterization Transition Started");

    do
    {
        // set pstate clips
        l_pstate = proc_freq2pstate(G_proc_fmax_mhz);
        rc = pgpe_set_clip_blocking(l_pstate);

        if(rc)
        {
            TRAC_ERR("SMGR_act_to_char: failed to set pstate clips.");
            break;
        }
        else // clips set successfully, keep pstates enabled, but change ownership
        {
            rc = pgpe_start_suspend(PGPE_ACTION_PSTATE_START, PMCR_OWNER_CHAR);

            if(rc)
            {
                TRAC_ERR("SMGR: failed to change PMCR ownership.");
                break;
            }
            else // Request successfully scheduled on PGPE now verify it completed
            {
               // Wait for ownership change to complete
               SsxTimebase start = ssx_timebase_get();
               SsxInterval timeout =  SSX_SECONDS(5);
               while( ! proc_is_hwpstate_enabled() )
               {
                  if ((ssx_timebase_get() - start) > timeout)
                  {
                      rc = 1;
                      TRAC_ERR("SMGR_active_to_char: Timeout waiting for PMCR ownership change");
                      break;
                  }
                  ssx_sleep(SSX_MICROSECONDS(10));
               }
               if(proc_is_hwpstate_enabled())
               {
                   // Set the RTL Flags to indicate which tasks can run
                   //   - Set OBSERVATION RTL flags for Characterization State
                   //   - Clear ACTIVE b/c not in ACTIVE State
                   rtl_clr_run_mask_deferred(RTL_FLAG_ACTIVE);
                   rtl_set_run_mask_deferred(RTL_FLAG_OBS);

                   // Set the actual STATE now that we have finished everything else
                   CURRENT_STATE() = OCC_STATE_CHARACTERIZATION;
               }
            }
        }
    } while (0);

    if(rc)
    {
        TRAC_ERR("SMGR: Failed to switch to Characterization state");
        /* @
         * @errortype
         * @moduleid    MAIN_STATE_TRANSITION_MID
         * @reasoncode  INTERNAL_FAILURE
         * @userdata1   rc
         * @userdata4   ERC_STATE_FROM_ACT_TO_CHR_FAILURE
         * @devdesc     Failed changing from standby to observation
         */
        l_errlHndl = createErrl(MAIN_STATE_TRANSITION_MID,        //modId
                                INTERNAL_FAILURE,                 //reasoncode
                                ERC_STATE_FROM_ACT_TO_CHR_FAILURE,//Extended reason code
                                ERRL_SEV_UNRECOVERABLE,           //Severity
                                NULL,                             //Trace Buf
                                DEFAULT_TRACE_SIZE,               //Trace Size
                                rc,                                //userdata1
                                0);                               //userdata2

        // Callout firmware
        addCalloutToErrl(l_errlHndl,
                         ERRL_CALLOUT_TYPE_COMPONENT_ID,
                         ERRL_COMPONENT_ID_FIRMWARE,
                         ERRL_CALLOUT_PRIORITY_HIGH);
    }
    else
    {
        TRAC_IMP("SMGR: Active to Characterization Transition Completed");
    }

    return l_errlHndl;
}


// Function Specification
//
// Name:  SMGR_standby_to_active
//
// Description: Makes the appropriate calls when transitioning from
//              standby to active.
//
// End Function Specification
errlHndl_t SMGR_standby_to_active()
{
    errlHndl_t              l_errlHndl = NULL;

    TRAC_IMP("SMGR: Standby to Active Transition Started");

    // Transtion through both functions on this multi-state transtion
    l_errlHndl = SMGR_standby_to_observation();
    if(NULL == l_errlHndl)
    {
       l_errlHndl = SMGR_observation_to_active();
    }

    if(l_errlHndl)
    {
        TRAC_ERR("SMGR: Standby to Active Transition Failed");
    }
    else
    {
        TRAC_IMP("SMGR: Standby to Active Transition Completed");
    }

    return l_errlHndl;
}


// Function Specification
//
// Name:  SMGR_all_to_safe
//
// Description:
//
// End Function Specification
errlHndl_t SMGR_all_to_safe()
{
    errlHndl_t              l_errlHndl = NULL;

    TRAC_IMP("SMGR: All States to Safe Transition Started");

    // If we are master, make sure we are broadcasting that the requested
    // state is "safe state"
    if (OCC_MASTER == G_occ_role)
    {
       G_occ_external_req_state = OCC_STATE_SAFE;
    }

    // If we are master, we will wait 15ms to go to full on safe mode
    // This is to give the slaves time to see that we are broadcasting
    // Safe State, and react to it.  This must be > 10ms.  It doesn't hurt
    // to do this on the slaves also.
    ssx_sleep(SSX_MILLISECONDS(15));

    // Set the RTL Flags to indicate which tasks can run
    //   - Clear ACTIVE b/c not in ACTIVE State
    //   - Clear OBSERVATION b/c not in OBSERVATION State
    //   - Clear STANDBY b/c not in STANDBY State
    rtl_clr_run_mask_deferred(RTL_FLAG_ACTIVE | RTL_FLAG_OBS | RTL_FLAG_STANDBY);

    // Only reset task & wdt task will run from now on
    // !!! There is no recovery to this except a reset !!!
    rtl_set_run_mask_deferred(RTL_FLAG_RST_REQ);

    // Notes:
    //  - We can still talk to FSP
    //  - We will still be able to go out on PIB
    //  - We will still attempt to load an applet if told to do so
    //  - The master will no longer broadcast to slaves, and vice versa

    // Set the actual STATE now that we have finished everything else
    CURRENT_STATE() = OCC_STATE_SAFE;

    TRAC_IMP("SMGR: All States to Safe Transition Completed");

    return l_errlHndl;
}


// Function Specification
//
// Name:  SMGR_set_state
//
// Description:
//
// End Function Specification
errlHndl_t SMGR_set_state(OCC_STATE i_new_state)
{
    errlHndl_t l_transResult = NULL; //Was the transition successful?
    int jj=0;

    do
    {
        // Get lock for critical section
        if(ssx_semaphore_pend(&G_smgrStateChangeSem,SSX_WAIT_FOREVER))
        {
            /* @
             * @errortype
             * @moduleid    MAIN_STATE_TRANSITION_MID
             * @reasoncode  SSX_GENERIC_FAILURE
             * @userdata1   none
             * @userdata4   ERC_RUNNING_SEM_PENDING_FAILURE
             * @devdesc     SSX semaphore related failure
             */
            l_transResult = createErrl(MAIN_STATE_TRANSITION_MID,        //modId
                                       SSX_GENERIC_FAILURE,              //reasoncode
                                       ERC_RUNNING_SEM_PENDING_FAILURE,  //Extended reason code
                                       ERRL_SEV_UNRECOVERABLE,           //Severity
                                       NULL,                             //Trace Buf
                                       DEFAULT_TRACE_SIZE,               //Trace Size
                                       0,                                //userdata1
                                       0);                               //userdata2

            addCalloutToErrl(l_transResult,
                             ERRL_CALLOUT_TYPE_COMPONENT_ID,
                             ERRL_COMPONENT_ID_FIRMWARE,
                             ERRL_CALLOUT_PRIORITY_HIGH);

            break;
        }

        //If there is no change to the state, just exit
        if(i_new_state == OCC_STATE_NOCHANGE)
        {
            break;
        }

        // Loop through state transition table, and find the state
        // transition function that matches the transition we need to do.
        for(jj=0; jj<G_smgr_state_trans_count; jj++)
        {
            if(((G_smgr_state_trans[jj].old_state == G_occ_internal_state)
                ||
                (G_smgr_state_trans[jj].old_state == OCC_STATE_ALL))
               &&
               (G_smgr_state_trans[jj].new_state == i_new_state))
            {
                // We found the transtion that matches, now run the function
                // that is associated with that state transition.
                if(NULL != G_smgr_state_trans[jj].trans_func_ptr)
                {
                    // Signal that we are now in a state transition
                    G_state_transition_occuring = TRUE;
                    // Run transition function

                    l_transResult = (G_smgr_state_trans[jj].trans_func_ptr)();


                    // Signal that we are done with the transition
                    G_state_transition_occuring = FALSE;

                    //State transition done: If KVM, update the OPAL dynamic data
                    if(G_sysConfigData.system_type.kvm)
                    {
                        ssx_semaphore_post(&G_dcomThreadWakeupSem);
                    }

                    break;
                }
            }
        }

        // Check if we hit the end of the table without finding a valid
        // state transition.  If we did, log an internal error.
        if(G_smgr_state_trans_count == jj)
        {
            TRAC_ERR("No transition (or NULL) found for the state change");

            /* @
             * @errortype
             * @moduleid    MAIN_STATE_TRANSITION_MID
             * @reasoncode  INTERNAL_FAILURE
             * @userdata1   G_occ_internal_state
             * @userdata2   i_new_state
             * @userdata4   ERC_SMGR_NO_VALID_STATE_TRANSITION_CALL
             * @devdesc     no valid state transition routine found
             */
            l_transResult = createErrl(MAIN_STATE_TRANSITION_MID,                //modId
                                       INTERNAL_FAILURE,                         //reasoncode
                                       ERC_SMGR_NO_VALID_STATE_TRANSITION_CALL,  //Extended reason code
                                       ERRL_SEV_UNRECOVERABLE,                   //Severity
                                       NULL,                                     //Trace Buf
                                       DEFAULT_TRACE_SIZE,                       //Trace Size
                                       G_occ_internal_state,                     //userdata1
                                       i_new_state);                             //userdata2

            addCalloutToErrl(l_transResult,
                             ERRL_CALLOUT_TYPE_COMPONENT_ID,
                             ERRL_COMPONENT_ID_FIRMWARE,
                             ERRL_CALLOUT_PRIORITY_HIGH);

            break;
        }

        // If the state OCC requested from TMGT is the state we are now in,
        // then change the requested state to NO CHANGE.
        if(CURRENT_STATE() == REQUESTED_STATE())
        {
            REQUESTED_STATE() = OCC_STATE_NOCHANGE;
        }
    } while ( 0 );

    // Get lock for critical section
    ssx_semaphore_post(&G_smgrStateChangeSem);

    return l_transResult;
}


// Function Specification
//
// Name:  SMGR_validate_get_valid_states
//
// Description: Return a byte of status masks that correspond to the v20 poll
//              response definition status byte.
//
// End Function Specification
uint8_t SMGR_validate_get_valid_states(void)
{
    uint8_t         l_valid_states = 0;
    uint32_t        l_datamask = DATA_get_present_cnfgdata();
    static BOOLEAN  l_throttle_traced = FALSE;

    // If we have everything we need to go to observation state
    if((l_datamask & SMGR_VALIDATE_DATA_OBSERVATION_MASK) ==
            SMGR_VALIDATE_DATA_OBSERVATION_MASK)
    {
        l_valid_states |= SMGR_MASK_OBSERVATION_READY;
    }

    // If we have everything we need to go to active state
    if(((l_datamask & SMGR_VALIDATE_DATA_ACTIVE_MASK) ==
            SMGR_VALIDATE_DATA_ACTIVE_MASK) )
    {
        l_valid_states |= SMGR_MASK_ACTIVE_READY;

        if(!l_throttle_traced)
        {
            TRAC_IMP("Setting Active Bit for this OCC");
            l_throttle_traced = TRUE;
        }
    }

    // If we are master OCC, set this bit
    if(OCC_MASTER == G_occ_role)
    {
       l_valid_states |= SMGR_MASK_MASTER_OCC;
    }

    // Indicate if this OCC is the FIR master.
    if (OCC_IS_FIR_MASTER())
    {
        l_valid_states |= OCC_ROLE_FIR_MASTER_MASK;
    }

    if(G_simics_environment)
    {
        l_valid_states |= OCC_SIMICS_ENVIRONMENT;
    }

    if(G_proc_pmcr_owner == PMCR_OWNER_OCC)
    {
        l_valid_states |= OCC_PMCR_OWNER_POLL_STATUS_MASK;
    }

    return l_valid_states;
}

OpenPOWER on IntegriCloud