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
|
/* IBM_PROLOG_BEGIN_TAG */
/* This is an automatically generated prolog. */
/* */
/* $Source: src/usr/initservice/istepdispatcher/istepdispatcher.C $ */
/* */
/* IBM CONFIDENTIAL */
/* */
/* COPYRIGHT International Business Machines Corp. 2011,2013 */
/* */
/* p1 */
/* */
/* Object Code Only (OCO) source materials */
/* Licensed Internal Code Source Materials */
/* IBM HostBoot Licensed Internal Code */
/* */
/* The source code for this program is not published or otherwise */
/* divested of its trade secrets, irrespective of what has been */
/* deposited with the U.S. Copyright Office. */
/* */
/* Origin: 30 */
/* */
/* IBM_PROLOG_END_TAG */
/**
* @file istepdispatcher.C
*
* IStep Dispatcher code. Launched from Extended Initialization Service
*
* PNOR Driver and Trace should be available by the time this is launched.
*
*/
/******************************************************************************/
// Includes
/******************************************************************************/
#include <stdint.h>
#include <sys/time.h> //nanosleep
#include <kernel/console.H> // printk status
#include <vfs/vfs.H> // for VFS::module_load
#include <sys/task.h> // tid_t, task_create, etc
#include <errl/errlentry.H> // errlHndl_t
#include <initservice/isteps_trace.H> // ISTEPS_TRACE buffer
#include <initservice/initsvcudistep.H> // InitSvcUserDetailsIstep
#include <initservice/taskargs.H> // TASK_ENTRY_MACRO
#include <targeting/common/targetservice.H>
#include <targeting/attrsync.H>
#include <establish_system_smp.H>
#include <hwpf/plat/fapiPlatAttributeService.H>
#include <mbox/mbox_queues.H> // HB_ISTEP_MSGQ
#include <mbox/mboxif.H> // register mailbox
#include <isteps/istepmasterlist.H>
#include "istepdispatcher.H"
#include "istep_mbox_msgs.H"
#include "splesscommon.H"
#include <diag/attn/attn.H>
#include <hwpf/istepreasoncodes.H>
#include <hwas/common/deconfigGard.H>
#include <hwas/hwasPlat.H>
namespace ISTEPS_TRACE
{
// declare storage for isteps_trace!
trace_desc_t * g_trac_isteps_trace = NULL;
TRAC_INIT(&ISTEPS_TRACE::g_trac_isteps_trace, "ISTEPS_TRACE", 2*KILOBYTE);
}
namespace INITSERVICE
{
/******************************************************************************/
// Globals/Constants
/******************************************************************************/
extern trace_desc_t *g_trac_initsvc;
const MBOX::queue_id_t HWSVRQ = MBOX::IPL_SERVICE_QUEUE;
const uint8_t INNER_START_STEP = 12;
const uint8_t INNER_START_SUBSTEP = 1;
const uint8_t INNER_STOP_STEP = 12;
const uint8_t INNER_STOP_SUBSTEP = 5;
const uint8_t OUTER_START_STEP = 13;
const uint8_t OUTER_START_SUBSTEP = 1;
const uint8_t OUTER_STOP_STEP = 14;
const uint8_t OUTER_STOP_SUBSTEP = 7;
const uint8_t HB_START_ISTEP = 6;
/**
* _start() task entry procedure using the macro in taskargs.H
*/
TASK_ENTRY_MACRO( IStepDispatcher::getTheInstance().init );
// ----------------------------------------------------------------------------
// IstepDispatcher()
// ----------------------------------------------------------------------------
IStepDispatcher::IStepDispatcher() :
iv_syncPointReached(false),
iv_istepModulesLoaded(0),
iv_progressThreadStarted(false),
iv_curIStep(0),
iv_curSubStep(0),
iv_pIstepMsg(NULL)
{
mutex_init(&iv_bkPtMutex);
mutex_init(&iv_mutex);
mutex_init(&iv_syncMutex);
sync_cond_init(&iv_syncHit);
TARGETING::Target* l_pSys = NULL;
TARGETING::targetService().getTopLevelTarget(l_pSys);
iv_mpiplMode = l_pSys->getAttr<TARGETING::ATTR_IS_MPIPL_HB>();
TRACFCOMP(g_trac_initsvc, "IStepDispatcher: MPIPL Mode: %d", iv_mpiplMode);
iv_istepMode = l_pSys->getAttr<TARGETING::ATTR_ISTEP_MODE>();
TRACFCOMP(g_trac_initsvc, "IStepDispatcher: IStep Mode: %d", iv_istepMode);
iv_spBaseServicesEnabled = spBaseServicesEnabled();
TRACFCOMP(g_trac_initsvc, "IStepDispatcher: SP base Services Enabled: %d",
iv_spBaseServicesEnabled);
iv_mailboxEnabled = MBOX::mailbox_enabled();
TRACFCOMP(g_trac_initsvc, "IStepDispatcher: Mailbox Enabled: %d",
iv_mailboxEnabled);
if (iv_spBaseServicesEnabled)
{
// SP Base Services Enabled implies that HWSV is running. If this is
// true then the mailbox must be enabled
assert(iv_mailboxEnabled);
}
// Note that if SP Base Services are not enabled and the Mailbox is enabled
// then Cronus is sending messages to Hostboot.
clock_gettime(CLOCK_MONOTONIC, &iv_lastProgressMsgTime);
iv_msgQ = msg_q_create();
}
// ----------------------------------------------------------------------------
// ~IstepDispatcher()
// ----------------------------------------------------------------------------
IStepDispatcher::~IStepDispatcher ()
{
TRACFCOMP( g_trac_initsvc, ENTER_MRK "IStepDispatcher::~IStepDispatcher "
"destructor" );
// Singleton destructor gets run when module gets unloaded.
// The istepdispatcher module never gets unloaded. So rather to send a
// message to error log daemon and tell it to shutdow and delete
// the queue we will assert here because the destructor never gets
// call.
assert(0);
}
// ----------------------------------------------------------------------------
// IstepDispatcher::getTheInstance()
// ----------------------------------------------------------------------------
IStepDispatcher& IStepDispatcher::getTheInstance()
{
return Singleton<IStepDispatcher>::instance();
}
// ----------------------------------------------------------------------------
// IStepDispatcher::init()
// ----------------------------------------------------------------------------
void IStepDispatcher::init(errlHndl_t &io_rtaskRetErrl)
{
errlHndl_t err = NULL;
printk( "IStepDispatcher entry.\n" );
TRACFCOMP( g_trac_initsvc, "IStepDispatcher entry." );
do
{
if(iv_mailboxEnabled)
{
// Register message Q with FSP Mailbox
err = MBOX::msgq_register( MBOX::HB_ISTEP_MSGQ, iv_msgQ );
if(err)
{
TRACFCOMP(g_trac_initsvc,
"ERROR: Failed to register mailbox, terminating");
break;
}
}
if(iv_istepMode)
{
// IStep mode (receive messages to run individual steps)
if (!iv_mailboxEnabled)
{
// Cannot get messages from either HWSV or Cronus. Launch SPTask
// to accept messages from the SPless user console
TRACFCOMP(g_trac_initsvc, "IStep mode and SPLESS");
tid_t spTaskTid = task_create(spTask, iv_msgQ);
assert(spTaskTid > 0);
}
// Call the message handler to handle messages from FSP or SPless
// user console, these messages include the IStep messages. This
// function never returns.
msgHndlr();
}
else
{
// Non-IStep mode (run all isteps automatically)
if(iv_spBaseServicesEnabled)
{
// Base Services available. Figure out if HWSV has overrides
uint8_t l_attrOverridesExist = 0;
TARGETING::Target* l_pTopLevelTarget = NULL;
TARGETING::targetService().getTopLevelTarget(l_pTopLevelTarget);
if (l_pTopLevelTarget == NULL)
{
TRACFCOMP(g_trac_initsvc,
"init: ERROR: Top level target not found");
}
else
{
l_attrOverridesExist = l_pTopLevelTarget->
getAttr<TARGETING::ATTR_PLCK_IPL_ATTR_OVERRIDES_EXIST>();
}
if (l_attrOverridesExist)
{
fapi::theAttrOverrideSync().getAttrOverridesFromFsp();
}
// Start a new thread to handle non-IStep messages from the FSP
// (e.g. sync point reached)
tid_t msgHndlrTaskTid = task_create(startMsgHndlrThread, this);
assert(msgHndlrTaskTid > 0);
}
err = executeAllISteps();
if(err)
{
// Sync all attributes to FSP
TRACFCOMP( g_trac_initsvc, "sync attributes to FSP");
errlHndl_t l_syncAttrErrl = TARGETING::syncAllAttributesToFsp();
if(l_syncAttrErrl)
{
TRACFCOMP(g_trac_initsvc, "Attribute sync failed, see"
"%x for details", l_syncAttrErrl->eid());
errlCommit(l_syncAttrErrl, INITSVC_COMP_ID);
}
break;
}
// Send the potentially modified set of Attribute overrides and any
// Attributes to sync to the FSP
fapi::theAttrOverrideSync().sendAttrOverridesAndSyncsToFsp();
}
} while(0);
TRACFCOMP( g_trac_initsvc, "IStepDispatcher finished.");
printk( "IStepDispatcher exit.\n" );
io_rtaskRetErrl = err;
}
// ----------------------------------------------------------------------------
// IStepDispatcher::executeAllISteps()
// ----------------------------------------------------------------------------
errlHndl_t IStepDispatcher::executeAllISteps()
{
errlHndl_t err = NULL;
uint32_t istep = 0;
uint32_t substep = 0;
bool l_deconfigs = false;
uint32_t numReconfigs = 0;
const uint32_t MAX_NUM_RECONFIG_ATTEMPTS = 30;
TRACFCOMP(g_trac_initsvc, ENTER_MRK"IStepDispatcher::executeAllISteps()");
while (istep < MaxISteps)
{
substep = 0;
while (substep < g_isteps[istep].numitems)
{
err = doIstep(istep, substep, l_deconfigs);
if (err)
{
// IStep error, check if a reconfig loop should be attempted
TRACFCOMP(g_trac_initsvc, ERR_MRK"executeAllISteps: IStep Error on %d:%d",
istep, substep);
uint8_t newIstep = 0;
uint8_t newSubstep = 0;
// Check for reconfigure. If istep returns an error, and there
// was a deconfigure, and checkReconfig is true (meaning the
// error is within the loops) then reconfigure. Else, break out
// with istep error.
if ( l_deconfigs &&
(checkReconfig(istep, substep, newIstep, newSubstep) ==
true))
{
if (numReconfigs >= MAX_NUM_RECONFIG_ATTEMPTS)
{
// Reconfigure loop has already been attempted too
// often, break out with the istep error
TRACFCOMP(g_trac_initsvc, ERR_MRK"executeAllISteps: No Reconfig Loop, Max count exceeded");
break;
}
// Delete the Istep error and create a new info error with
// the same plid stating that a reconfig loop was performed
uint32_t l_plid = err->plid();
delete err;
err = NULL;
numReconfigs++;
uint64_t errWord = FOUR_UINT16_TO_UINT64(
istep, substep, newIstep, newSubstep);
/*@
* @errortype
* @reasoncode ISTEP_RECONFIG_LOOP_ENTERED
* @severity ERRORLOG::ERRL_SEV_INFORMATIONAL
* @moduleid ISTEP_INITSVC_MOD_ID
* @userdata1[0:15] Istep that failed
* @userdata1[16:31] Substep that failed
* @userdata1[32:47] Istep that reconfig looped back to
* @userdata1[48:63] Substep that reconfig looped back to
* @userdata2 The number of reconfigs loops tried
* @devdesc IStep failed and HW deconfigured.
* Looped back to an earlier istep
* (Reconfigure loop).
*/
err = new ERRORLOG::ErrlEntry(
ERRORLOG::ERRL_SEV_INFORMATIONAL,
ISTEP_INITSVC_MOD_ID,
ISTEP_RECONFIG_LOOP_ENTERED,
errWord,
numReconfigs);
err->plid(l_plid);
errlCommit(err, INITSVC_COMP_ID);
istep = newIstep;
substep = newSubstep;
TRACFCOMP(g_trac_initsvc, ERR_MRK"executeAllISteps: Reconfig Loop: Back to %d:%d",
istep, substep);
}
else
{
// Break out with the istep error
TRACFCOMP(g_trac_initsvc, ERR_MRK"executeAllISteps: No Reconfig Loop");
break;
}
}
else
{
substep++;
}
}
if (err)
{
break;
}
istep++;
}
TRACFCOMP(g_trac_initsvc, EXIT_MRK"IStepDispatcher::executeAllISteps()");
return err;
}
// ----------------------------------------------------------------------------
// IStepDispatcher::doIstep()
// ----------------------------------------------------------------------------
errlHndl_t IStepDispatcher::doIstep(uint32_t i_istep,
uint32_t i_substep,
bool & o_deconfigs)
{
errlHndl_t err = NULL;
o_deconfigs = false;
// Get the Task Info for this step
const TaskInfo * theStep = findTaskInfo(i_istep, i_substep);
// If the step has valid work to be done, then execute it.
if(NULL != theStep)
{
TRACFCOMP(g_trac_initsvc,ENTER_MRK"doIstep: step %d, substep %d, task %s",
i_istep, i_substep, theStep->taskname);
// Send progress codes if in run-all mode
if (!iv_istepMode)
{
mutex_lock(&iv_mutex);
iv_curIStep = i_istep;
iv_curSubStep = i_substep;
// Send Progress Code
err = this->sendProgressCode(false);
mutex_unlock(&iv_mutex);
if(err)
{
// Commit the error and continue
errlCommit(err, INITSVC_COMP_ID);
}
// Start progress thread, if not yet started
if (!iv_progressThreadStarted)
{
tid_t l_progTid = task_create(startProgressThread,this);
assert( l_progTid > 0 );
iv_progressThreadStarted = true;
}
}
if(iv_istepModulesLoaded != i_istep)
{
// unload the modules from the previous step
unLoadModules(iv_istepModulesLoaded);
// load modules for this step
loadModules(i_istep);
iv_istepModulesLoaded = i_istep;
}
uint32_t preDeconfigs = HWAS::theDeconfigGard().getDeconfigureStatus();
err = InitService::getTheInstance().executeFn(theStep, NULL);
// flush contTrace immediately after each i_istep/substep returns
TRAC_FLUSH_BUFFERS();
// sync the attributes to fsp in single step mode but only after step 6
// is complete to allow discoverTargets() to run before the sync is done
if(iv_istepMode && (i_istep > HB_START_ISTEP))
{
if(isAttrSyncEnabled())
{
TRACFCOMP(g_trac_initsvc, INFO_MRK"doIstep: sync attributes to FSP");
errlHndl_t l_errl = TARGETING::syncAllAttributesToFsp();
if(l_errl)
{
TRACFCOMP(g_trac_initsvc, ERR_MRK"doIstep: syncattributes failed see %x for details",
l_errl->eid());
errlCommit(l_errl, INITSVC_COMP_ID);
}
}
}
// Check for Power Line Disturbance (PLD)
if (HWAS::hwasPLDDetection())
{
// There was a PLD, clear any deferred deconfig records
TRACFCOMP(g_trac_initsvc, ERR_MRK"doIstep: PLD, clearing deferred deconfig records");
HWAS::theDeconfigGard().clearDeconfigureRecords(NULL);
}
else
{
// There was no PLD, process any deferred deconfig records (i.e.
// actually do the deconfigures)
bool deferredDeconfigs = HWAS::processDeferredDeconfig();
if (deferredDeconfigs)
{
TRACFCOMP(g_trac_initsvc, ERR_MRK"doIstep: Processed deferred deconfig records");
}
}
uint32_t postDeconfigs = HWAS::theDeconfigGard().getDeconfigureStatus();
if (postDeconfigs != preDeconfigs)
{
o_deconfigs = true;
if (err == NULL)
{
// IStep returned success, but HW was deconfigured! IStep
// success is a contract that the IStep worked and the system
// config did not change. Therefore create an error.
TRACFCOMP(g_trac_initsvc, ERR_MRK"doIstep: Creating deconfig error");
/*@
* @errortype
* @reasoncode ISTEP_FAILED_DUE_TO_DECONFIG
* @severity ERRORLOG::ERRL_SEV_UNRECOVERABLE
* @moduleid ISTEP_INITSVC_MOD_ID
* @userdata1 Istep that failed
* @userdata2 SubStep that failed
* @devdesc IStep reported success but HW deconfigured
*/
err = new ERRORLOG::ErrlEntry(
ERRORLOG::ERRL_SEV_UNRECOVERABLE,
ISTEP_INITSVC_MOD_ID,
ISTEP_FAILED_DUE_TO_DECONFIG,
i_istep, i_substep);
}
}
if(err)
{
TRACFCOMP(g_trac_initsvc, ERR_MRK"doIstep: Istep failed, plid 0x%x",
err->plid());
}
// Check for any attentions and invoke PRD for analysis
else if (true == theStep->taskflags.check_attn)
{
TRACDCOMP(g_trac_initsvc,
INFO_MRK"Check for attentions and invoke PRD" );
err = ATTN::checkForIplAttentions();
if ( err )
{
TRACFCOMP( g_trac_initsvc, ERR_MRK"doIstep: error from checkForIplAttentions");
}
}
TRACFCOMP(g_trac_initsvc, EXIT_MRK"doIstep: step %d, substep %d",
i_istep, i_substep);
}
else
{
TRACDCOMP( g_trac_initsvc, INFO_MRK"doIstep: Empty Istep, nothing to do!" );
}
return err;
}
// ----------------------------------------------------------------------------
// findTaskInfo()
// ----------------------------------------------------------------------------
const TaskInfo * IStepDispatcher::findTaskInfo(const uint32_t i_IStep,
const uint32_t i_SubStep)
{
// default return is NULL
const TaskInfo *l_pistep = NULL;
// apply filters
do
{
// Sanity check / dummy IStep
if(g_isteps[i_IStep].pti == NULL)
{
TRACDCOMP( g_trac_initsvc,
"g_isteps[%d].pti == NULL (substep=%d)",
i_IStep,
i_SubStep );
break;
}
// check input range - IStep
if( i_IStep >= MaxISteps )
{
TRACDCOMP( g_trac_initsvc,
"IStep %d out of range. (substep=%d) ",
i_IStep,
i_SubStep );
break; // break out with l_pistep set to NULL
}
// check input range - ISubStep
if( i_SubStep >= g_isteps[i_IStep].numitems )
{
TRACDCOMP( g_trac_initsvc,
"IStep %d Substep %d out of range.",
i_IStep,
i_SubStep );
break; // break out with l_pistep set to NULL
}
// check for end of list.
if( g_isteps[i_IStep].pti[i_SubStep].taskflags.task_type
== END_TASK_LIST )
{
TRACDCOMP( g_trac_initsvc,
"IStep %d SubStep %d task_type==END_TASK_LIST.",
i_IStep,
i_SubStep );
break;
}
// check to see if the pointer to the function is NULL.
// This is possible if some of the substeps aren't working yet
// and are just placeholders.
if( g_isteps[i_IStep].pti[i_SubStep].taskfn == NULL )
{
TRACDCOMP( g_trac_initsvc,
"IStep %d SubStep %d fn ptr is NULL.",
i_IStep,
i_SubStep );
break;
}
// check to see if we should skip this istep
// This is possible depending on which IPL mode we're in
uint8_t l_ipl_op = g_isteps[i_IStep].pti[i_SubStep].taskflags.ipl_op;
if (true == iv_mpiplMode)
{
if (!(l_ipl_op & MPIPL_OP))
{
TRACDCOMP( g_trac_initsvc,
"Skipping IStep %d SubStep %d for MPIPL mode",
i_IStep,
i_SubStep );
break;
}
}
else
{
if (!(l_ipl_op & NORMAL_IPL_OP))
{
TRACDCOMP( g_trac_initsvc,
"Skipping IStep %d SubStep %d for non MPIPL mode",
i_IStep,
i_SubStep );
break;
}
}
// we're good, set the istep & return it to caller
l_pistep = &( g_isteps[i_IStep].pti[i_SubStep] );
} while( 0 );
return l_pistep;
}
// ----------------------------------------------------------------------------
// loadModules()
// ----------------------------------------------------------------------------
void IStepDispatcher::loadModules(uint32_t istepNumber) const
{
errlHndl_t l_errl = NULL;
do
{
// if no dep modules then just exit out, let the call to
// executeFN load the module based on the function being
// called.
if( g_isteps[istepNumber].depModules == NULL)
{
TRACDCOMP( g_trac_initsvc,
"g_isteps[%d].depModules == NULL",
istepNumber );
break;
}
uint32_t i = 0;
while( ( l_errl == NULL ) &&
( g_isteps[istepNumber].depModules->modulename[i][0] != 0) )
{
TRACFCOMP( g_trac_initsvc,
"loading [%s]",
g_isteps[istepNumber].depModules->modulename[i]);
l_errl = VFS::module_load(
g_isteps[istepNumber].depModules->modulename[i] );
i++;
}
if( l_errl )
{
errlCommit( l_errl, ISTEP_COMP_ID );
assert(0);
}
}while(0);
}
// ----------------------------------------------------------------------------
// unloadModules()
// ----------------------------------------------------------------------------
void IStepDispatcher::unLoadModules(uint32_t istepNumber) const
{
errlHndl_t l_errl = NULL;
do
{
// if no dep modules then just exit out
if( g_isteps[istepNumber].depModules == NULL)
{
TRACDCOMP( g_trac_initsvc,
"g_isteps[%d].depModules == NULL",
istepNumber );
break;
}
uint32_t i = 0;
while( ( l_errl == NULL ) &&
( g_isteps[istepNumber].depModules->modulename[i][0] != 0) )
{
TRACFCOMP( g_trac_initsvc,
"unloading [%s]",
g_isteps[istepNumber].depModules->modulename[i]);
l_errl = VFS::module_unload(
g_isteps[istepNumber].depModules->modulename[i] );
i++;
}
if( l_errl )
{
TRACFCOMP( g_trac_initsvc,
" failed to unload module, commit error and move on");
errlCommit(l_errl, INITSVC_COMP_ID );
l_errl = NULL;
}
}while(0);
}
// ----------------------------------------------------------------------------
// IStepDispatcher::isAttrSyncEnabled()
// ----------------------------------------------------------------------------
bool IStepDispatcher::isAttrSyncEnabled() const
{
TARGETING::Target* l_pTopLevel = NULL;
TARGETING::targetService().getTopLevelTarget(l_pTopLevel);
uint8_t l_syncEnabled =
l_pTopLevel->getAttr<TARGETING::ATTR_SYNC_BETWEEN_STEPS>();
return l_syncEnabled;
}
// ----------------------------------------------------------------------------
// IStepDispatcher::msgHndlr()
// ----------------------------------------------------------------------------
void IStepDispatcher::msgHndlr()
{
TRACFCOMP( g_trac_initsvc, ENTER_MRK"IStepDispatcher::msgHndlr");
// Loop forever
while(1)
{
msg_t * pMsg = NULL;
pMsg = msg_wait(iv_msgQ);
switch(pMsg->type)
{
case SYNC_POINT_REACHED:
// Sync point reached from Fsp
TRACFCOMP(g_trac_initsvc, INFO_MRK"msgHndlr: SYNC_POINT_REACHED");
handleSyncPointReachedMsg(pMsg);
break;
case PROCESS_IOVALID_REQUEST:
TRACFCOMP(g_trac_initsvc, INFO_MRK"msgHndlr: PROCESS_IOVALID_REQUEST");
handleProcFabIovalidMsg(pMsg);
break;
case ISTEP_MSG_TYPE:
TRACFCOMP(g_trac_initsvc, INFO_MRK"msgHndlr: ISTEP_MSG_TYPE");
if (iv_istepMode)
{
handleIStepRequestMsg(pMsg);
}
else
{
TRACFCOMP(g_trac_initsvc, ERR_MRK"msgHndlr: Ignoring IStep msg in non-IStep mode!");
}
break;
default:
TRACFCOMP(g_trac_initsvc, ERR_MRK"msgHndlr: Ignoring unknown message 0x%08x",
pMsg->type);
break;
};
}
TRACFCOMP( g_trac_initsvc, EXIT_MRK"IStepDispatcher::msgHndlr");
}
// ----------------------------------------------------------------------------
// IStepDispatcher::waitForSyncPoint()
// ----------------------------------------------------------------------------
void IStepDispatcher::waitForSyncPoint()
{
TRACFCOMP(g_trac_initsvc, ENTER_MRK"IStepDispatcher::waitForSyncPoint");
if(iv_istepMode || (!iv_spBaseServicesEnabled))
{
TRACFCOMP(g_trac_initsvc, INFO_MRK"waitForSyncPoint: Istep mode or no base services, returning");
}
else
{
// Wait for the condition variable to be signalled
mutex_lock(&iv_syncMutex);
while(!iv_syncPointReached)
{
sync_cond_wait(&iv_syncHit, &iv_syncMutex);
}
iv_syncPointReached = false;
mutex_unlock(&iv_syncMutex);
}
TRACFCOMP(g_trac_initsvc, EXIT_MRK"IStepDispatcher::waitForSyncPoint");
}
// ----------------------------------------------------------------------------
// IStepDispatcher::sendSyncPoint()
// ----------------------------------------------------------------------------
errlHndl_t IStepDispatcher::sendSyncPoint()
{
errlHndl_t err = NULL;
TRACFCOMP(g_trac_initsvc, ENTER_MRK"IStepDispatcher::sendSyncPoint");
if(iv_istepMode || (!iv_spBaseServicesEnabled))
{
TRACFCOMP( g_trac_initsvc, INFO_MRK"sendSyncPoint: Istep mode or no base services, returning");
}
else
{
msg_t * myMsg = msg_allocate();
myMsg->type = SYNC_POINT_REACHED;
mutex_lock(&iv_mutex);
uint64_t tmpVal = iv_curIStep;
tmpVal = tmpVal << 32;
tmpVal |= iv_curSubStep;
mutex_unlock(&iv_mutex);
myMsg->data[0] = tmpVal;
myMsg->data[1] = 0x0;
myMsg->extra_data = NULL;
err = MBOX::send(HWSVRQ, myMsg);
if (err)
{
TRACFCOMP( g_trac_initsvc, ERR_MRK"sendSyncPoint: Error sending message");
}
}
TRACFCOMP( g_trac_initsvc, EXIT_MRK"IStepDispatcher::sendSyncPoint");
return err;
}
// ----------------------------------------------------------------------------
// IStepDispatcher::sendIstepCompleteMsg()
// ----------------------------------------------------------------------------
errlHndl_t IStepDispatcher::sendIstepCompleteMsg()
{
errlHndl_t err = NULL;
TRACFCOMP( g_trac_initsvc, ENTER_MRK"IStepDispatcher::sendIstepCompleteMsg");
//Send progress code and update clock in thread
/* 15 sec msg constraint not planned for GA1
err = this->sendProgressCode();
if( err )
{
break;
}
*/
// Respond to the IStep message stashed in iv_pIstepMsg
mutex_lock(&iv_mutex);
uint8_t curIStep = iv_curIStep;
uint8_t curSubStep = iv_curSubStep;
msg_t * pMsg = iv_pIstepMsg;
iv_pIstepMsg = NULL;
mutex_unlock(&iv_mutex);
if(pMsg)
{
pMsg->data[0] = 0;
msg_respond(iv_msgQ, pMsg );
pMsg = NULL;
}
else
{
TRACFCOMP(g_trac_initsvc, ERR_MRK"sendIstepCompleteMsg: No message to respond to!");
/*@
* @errortype
* @reasoncode NO_MSG_PRESENT
* @severity ERRORLOG::ERRL_SEV_UNRECOVERABLE
* @moduleid ISTEP_INITSVC_MOD_ID
* @userdata1 Current Istep
* @userdata2 Current SubStep
* @devdesc Request to send Istep Complete msg to Fsp, but
* no outstanding message from Fsp found.
*/
err = new ERRORLOG::ErrlEntry( ERRORLOG::ERRL_SEV_UNRECOVERABLE,
ISTEP_INITSVC_MOD_ID,
NO_MSG_PRESENT,
curIStep,
curSubStep );
}
TRACFCOMP( g_trac_initsvc, EXIT_MRK"IStepDispatcher::sendIstepCompleteMsg");
return err;
}
// ----------------------------------------------------------------------------
// IStepDispatcher::handleSyncPointReachedMsg()
// ----------------------------------------------------------------------------
void IStepDispatcher::handleSyncPointReachedMsg(msg_t * & io_pMsg)
{
TRACFCOMP(g_trac_initsvc, ENTER_MRK"IStepDispatcher::handleSyncPointReachedMsg");
// Signal any IStep waiting for a sync point
mutex_lock(&iv_syncMutex);
iv_syncPointReached = true;
sync_cond_signal(&iv_syncHit);
mutex_unlock(&iv_syncMutex);
if (msg_is_async(io_pMsg))
{
// It is expected that Sync Point Reached messages are async
msg_free(io_pMsg);
io_pMsg = NULL;
}
else
{
// Send the message back as a response
msg_respond(iv_msgQ, io_pMsg);
io_pMsg = NULL;
}
TRACFCOMP(g_trac_initsvc, EXIT_MRK"IStepDispatcher::handleSyncPointReachedMsg");
}
// ----------------------------------------------------------------------------
// IStepDispatcher::iStepBreakPoint()
// ----------------------------------------------------------------------------
void IStepDispatcher::iStepBreakPoint(uint32_t i_info)
{
// Throttle the breakpoints by locking here.
mutex_lock(&iv_bkPtMutex);
errlHndl_t err = NULL;
TRACFCOMP(g_trac_initsvc, ENTER_MRK"IStepDispatcher::handleBreakpointMsg");
// Breakpoints are only supported when FSP is attached
if(iv_mailboxEnabled)
{
// Send a breakpoint message to the FSP and wait for response
msg_t * pMsg = msg_allocate();
pMsg->type = BREAKPOINT;
pMsg->data[0] = i_info;
pMsg->data[1] = 0x0;
pMsg->extra_data = NULL;
err = MBOX::sendrecv(HWSVRQ, pMsg);
if(err)
{
TRACFCOMP(g_trac_initsvc, ERR_MRK"handleBreakpointMsg: Error sending message");
errlCommit(err, INITSVC_COMP_ID);
msg_free(pMsg);
pMsg = NULL;
}
}
TRACFCOMP(g_trac_initsvc, EXIT_MRK"IStepDispatcher::handleBreakpointMsg");
mutex_unlock(&iv_bkPtMutex);
}
// ----------------------------------------------------------------------------
// IStepDispatcher::handleIStepRequestMsg()
// ----------------------------------------------------------------------------
void IStepDispatcher::handleIStepRequestMsg(msg_t * & io_pMsg)
{
errlHndl_t err = NULL;
bool l_deconfigs = false;
// find the step/substep. The step is in the top 32bits, the substep is in
// the bottom 32bits and is a byte
uint8_t istep = ((io_pMsg->data[0] & 0x000000FF00000000) >> 32);
uint8_t substep = (io_pMsg->data[0] & 0x00000000000000FF);
TRACFCOMP(g_trac_initsvc, ENTER_MRK"handleIstepRequestMsg: 0x%016x, istep: %d, substep: %d",
io_pMsg->data[0], istep, substep);
// Transfer ownership of the message pointer to iv_pIstepMsg because if the
// IStep doesn't return (start_payload), it will call sendIstepCompleteMsg
// which will respond to iv_pIstepMsg
mutex_lock(&iv_mutex);
iv_curIStep = istep;
iv_curSubStep = substep;
iv_pIstepMsg = io_pMsg;
io_pMsg = NULL;
mutex_unlock(&iv_mutex);
err = doIstep (istep, substep, l_deconfigs);
uint64_t status = 0;
if (err)
{
// Commit the error and record the plid as status in the top 32bits
status = err->plid();
status <<= 32;
errlCommit(err, INITSVC_COMP_ID);
}
// Transfer ownership of the message pointer back from iv_pIstepMsg
mutex_lock(&iv_mutex);
io_pMsg = iv_pIstepMsg;
iv_pIstepMsg = NULL;
mutex_unlock(&iv_mutex);
if (io_pMsg == NULL)
{
// An IStep already responded to the message!!
TRACFCOMP(g_trac_initsvc, ERR_MRK"handleIstepRequestMsg: message response already sent!");
}
else
{
if (msg_is_async(io_pMsg))
{
// Unexpected
TRACFCOMP(g_trac_initsvc, ERR_MRK"handleIstepRequestMsg: async istep message!");
}
else
{
io_pMsg->data[0] = status;
io_pMsg->data[1] = 0x0;
io_pMsg->extra_data = NULL;
msg_respond(iv_msgQ, io_pMsg);
io_pMsg = NULL;
}
}
TRACFCOMP( g_trac_initsvc, EXIT_MRK"IStepDispatcher::handleIStepRequestMsg");
}
// ----------------------------------------------------------------------------
// IStepDispatcher::handleProcFabIovalidMsg()
// ----------------------------------------------------------------------------
void IStepDispatcher::handleProcFabIovalidMsg(msg_t * & io_pMsg)
{
TRACFCOMP(g_trac_initsvc, ENTER_MRK"IStepDispatcher::handleProcFabIovalidMsg");
// Ensure the library is loaded
errlHndl_t err = VFS::module_load("libestablish_system_smp.so");
if (err)
{
TRACFCOMP(g_trac_initsvc, "handleProcFabIovalidMsg: Error loading module, PLID = 0x%x",
err->plid());
errlCommit(err, INITSVC_COMP_ID);
msg_free(io_pMsg);
io_pMsg = NULL;
}
else
{
// $TODO RTC:88284 - Create Child Thread
ESTABLISH_SYSTEM_SMP::host_sys_fab_iovalid_processing(io_pMsg);
// if there was an error don't winkle ?
if(io_pMsg->data[0] == HWSVR_MSG_SUCCESS)
{
TRACFCOMP( g_trac_initsvc,
"$TODO RTC:71447 - winkle all cores");
}
// Send the message back as a response
msg_respond(iv_msgQ, io_pMsg);
io_pMsg = NULL;
}
TRACFCOMP( g_trac_initsvc, EXIT_MRK"IStepDispatcher::handleProcFabIovalidMsg");
}
// ----------------------------------------------------------------------------
// IStepDispatcher::handleProcFabIovalidMsg()
// This method has a default of true for i_needsLock
// ----------------------------------------------------------------------------
errlHndl_t IStepDispatcher::sendProgressCode(bool i_needsLock)
{
if (i_needsLock)
{
mutex_lock( &iv_mutex );
}
TRACDCOMP( g_trac_initsvc,ENTER_MRK"IStepDispatcher::sendProgressCode()");
errlHndl_t err = NULL;
// Put in rolling bit RTC: 84794
msg_t * myMsg = msg_allocate();
myMsg->type = IPL_PROGRESS_CODE;
myMsg->data[0] = iv_curIStep;
myMsg->data[1] = iv_curSubStep;
myMsg->extra_data = NULL;
err = MBOX::send(HWSVRQ, myMsg);
clock_gettime(CLOCK_MONOTONIC, &iv_lastProgressMsgTime);
TRACFCOMP( g_trac_initsvc,INFO_MRK"Progress Code %d.%d Sent",
myMsg->data[0],myMsg->data[1]);
TRACDCOMP( g_trac_initsvc,EXIT_MRK"IStepDispatcher::sendProgressCode()" );
if (i_needsLock)
{
mutex_unlock( &iv_mutex );
}
return err;
}
// ----------------------------------------------------------------------------
// IStepDispatcher::runProgressThread()
// ----------------------------------------------------------------------------
void IStepDispatcher::runProgressThread()
{
TRACDCOMP(g_trac_initsvc, ENTER_MRK"IStepDispatcher::runProgressThread");
timespec_t l_CurTime;
timespec_t l_PrevTime;
//errlHndl_t err = NULL;
mutex_lock( &iv_mutex );
while(1)
{
l_PrevTime = iv_lastProgressMsgTime;
clock_gettime(CLOCK_MONOTONIC, &l_CurTime);
if( (l_CurTime.tv_sec - l_PrevTime.tv_sec) < MAX_WAIT_TIME_SEC )
{
mutex_unlock( &iv_mutex );
nanosleep( MAX_WAIT_TIME_SEC - (l_CurTime.tv_sec -
l_PrevTime.tv_sec), 0 );
mutex_lock( &iv_mutex );
}
if( l_PrevTime.tv_sec == iv_lastProgressMsgTime.tv_sec &&
l_PrevTime.tv_nsec == iv_lastProgressMsgTime.tv_nsec)
{
#if 0
/* 15 sec msg constraint not planned for GA1
err = this->sendProgressCode(false);
commit error in future
*/
#else
// Normally this would be done in sendProgressCode but do it here
// to prevent thread from becoming a CPU hog.
clock_gettime(CLOCK_MONOTONIC, &iv_lastProgressMsgTime);
#endif
}
}
TRACDCOMP(g_trac_initsvc, EXIT_MRK"IStepDispatcher::runProgressThread");
}
// ----------------------------------------------------------------------------
// IStepDispatcher::startProgressThread()
// ----------------------------------------------------------------------------
void * IStepDispatcher::startProgressThread(void * p)
{
IStepDispatcher * l_pDispatcher = reinterpret_cast<IStepDispatcher *>(p);
TRACDCOMP(g_trac_initsvc,INFO_MRK"startProgressThread: runProgressThread");
l_pDispatcher->runProgressThread();
return NULL;
}
// ----------------------------------------------------------------------------
// IStepDispatcher::startMsgHndlrThread()
// ----------------------------------------------------------------------------
void * IStepDispatcher::startMsgHndlrThread(void * p)
{
IStepDispatcher * l_pDispatcher = reinterpret_cast<IStepDispatcher *>(p);
TRACDCOMP(g_trac_initsvc,INFO_MRK"msgHndlrThread");
l_pDispatcher->msgHndlr();
return NULL;
}
// ----------------------------------------------------------------------------
// IStepDispatcher::checkReconfig()
// ----------------------------------------------------------------------------
bool IStepDispatcher::checkReconfig(const uint8_t i_curIstep,
const uint8_t i_curSubstep,
uint8_t & o_newIstep,
uint8_t & o_newSubstep)
{
bool doReconfigure = false;
TRACDCOMP(g_trac_initsvc, ENTER_MRK"IStepDispatcher::checkReconfig(): istep %d.%d",
i_curIstep, i_curSubstep);
uint16_t current = (i_curIstep << 8) | i_curSubstep;
const uint16_t INNER_START = (INNER_START_STEP << 8) | INNER_START_SUBSTEP;
const uint16_t INNER_STOP = (INNER_STOP_STEP << 8) | INNER_STOP_SUBSTEP;
const uint16_t OUTER_START = (OUTER_START_STEP << 8) | OUTER_START_SUBSTEP;
const uint16_t OUTER_STOP = (OUTER_STOP_STEP << 8) | OUTER_STOP_SUBSTEP;
if ((current >= INNER_START) && (current <= INNER_STOP))
{
doReconfigure = true;
o_newIstep = INNER_START_STEP;
o_newSubstep = INNER_START_SUBSTEP;
}
else if ((current >= OUTER_START) && (current <= OUTER_STOP))
{
doReconfigure = true;
o_newIstep = OUTER_START_STEP;
o_newSubstep = OUTER_START_SUBSTEP;
}
TRACDCOMP(g_trac_initsvc, EXIT_MRK"IStepDispatcher::checkReconfig: reconfig new istep/substep: %d %d.%d",
doReconfigure, o_newIstep, o_newSubstep);
return doReconfigure;
}
// ----------------------------------------------------------------------------
// Extarnal functions defined that map directly to IStepDispatcher public member
// functions.
// Defined in istepdispatcherif.H, initsvcbreakpoint.H
// ----------------------------------------------------------------------------
void waitForSyncPoint()
{
IStepDispatcher::getTheInstance().waitForSyncPoint();
}
errlHndl_t sendSyncPoint()
{
return IStepDispatcher::getTheInstance().sendSyncPoint();
}
errlHndl_t sendIstepCompleteMsg()
{
return IStepDispatcher::getTheInstance().sendIstepCompleteMsg();
}
void iStepBreakPoint(uint32_t i_info)
{
IStepDispatcher::getTheInstance().iStepBreakPoint( i_info );
}
} // namespace
|