-
Notifications
You must be signed in to change notification settings - Fork 97
/
ddr_phy.C
1572 lines (1306 loc) · 67.2 KB
/
ddr_phy.C
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
/* IBM_PROLOG_BEGIN_TAG */
/* This is an automatically generated prolog. */
/* */
/* $Source: src/import/chips/p9/procedures/hwp/memory/lib/phy/ddr_phy.C $ */
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2015,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 */
///
/// @file ddr_phy.C
/// @brief Subroutines to manipulate the phy, or used during phy procedures
///
// *HWP HWP Owner: Brian Silver <bsilver@us.ibm.com>
// *HWP HWP Backup: Andre Marin <aamarin@us.ibm.com>
// *HWP Team: Memory
// *HWP Level: 2
// *HWP Consumed by: FSP:HB
#include <vector>
#include <initializer_list>
#include <fapi2.H>
#include <mss.H>
#include <lib/phy/ddr_phy.H>
#include <lib/phy/read_cntrl.H>
#include <lib/phy/phy_cntrl.H>
#include <lib/phy/apb.H>
#include <lib/phy/adr32s.H>
#include <lib/phy/adr.H>
#include <lib/phy/seq.H>
#include <lib/workarounds/dp16_workarounds.H>
#include <lib/workarounds/wr_vref_workarounds.H>
#include <lib/dimm/ddr4/latch_wr_vref.H>
#include <lib/workarounds/seq_workarounds.H>
#include <lib/utils/bit_count.H>
#include <lib/utils/find.H>
#include <lib/utils/dump_regs.H>
#include <generic/memory/lib/utils/scom.H>
#include <lib/utils/count_dimm.H>
using fapi2::TARGET_TYPE_MCBIST;
using fapi2::TARGET_TYPE_PROC_CHIP;
using fapi2::TARGET_TYPE_SYSTEM;
using fapi2::TARGET_TYPE_MCA;
using fapi2::TARGET_TYPE_MCS;
using fapi2::TARGET_TYPE_DIMM;
using fapi2::FAPI2_RC_SUCCESS;
namespace mss
{
///
/// @brief change resetn to the given state
/// @param[in] i_target the mcbist
/// @param[in] i_state the desired state
/// @return FAPI2_RC_SUCCESS iff ok
///
fapi2::ReturnCode change_resetn( const fapi2::Target<TARGET_TYPE_MCBIST>& i_target, states i_state )
{
fapi2::buffer<uint64_t> l_data;
// Need to run on the magic port too
for (const auto& p : mss::find_targets_with_magic<TARGET_TYPE_MCA>(i_target))
{
FAPI_INF("Change reset to %s PHY: %s", (i_state == HIGH ? "high" : "low"), mss::c_str(p));
FAPI_TRY( mss::getScom(p, MCA_MBA_CAL0Q, l_data) );
i_state == HIGH ? l_data.setBit<MCA_MBA_CAL0Q_RESET_RECOVER>() : l_data.clearBit<MCA_MBA_CAL0Q_RESET_RECOVER>();
FAPI_TRY( mss::putScom(p, MCA_MBA_CAL0Q, l_data) );
}
fapi_try_exit:
return fapi2::current_err;
}
///
/// @brief Perform the zctl enable process
/// @param[in] i_target the mcbist for the reset recover
/// @return FAPI2_RC_SUCCESS iff ok
///
fapi2::ReturnCode enable_zctl( const fapi2::Target<TARGET_TYPE_MCBIST>& i_target )
{
// We only need to zcal the magic ports - they have the logic for all the other ports.
const auto l_ports = mss::find_magic_targets<TARGET_TYPE_MCA>(i_target);
fapi2::buffer<uint64_t> l_data;
constexpr uint64_t l_zcal_reset_reg = pcTraits<TARGET_TYPE_MCA>::PC_RESETS_REG;
constexpr uint64_t l_zcal_status_reg = pcTraits<TARGET_TYPE_MCA>::PC_DLL_ZCAL_CAL_STATUS_REG;
uint8_t l_sim = 0;
FAPI_TRY( mss::is_simulation( l_sim) );
if (l_sim)
{
return fapi2::FAPI2_RC_SUCCESS;
}
// 11. Assert the ZCNTL enable to the internal impedance controller in DDRPHY_PC_RESETS register
mss::pc::set_enable_zcal(l_data, mss::HIGH);
FAPI_TRY( mss::scom_blastah(l_ports, l_zcal_reset_reg, l_data) );
// 12. Wait at least 1024 dphy_gckn cycles (no sense in doing this in the polling loop as
// we'll end up doing this delay for every port when we only need to do it once since we
// kicked them all off in parallel
fapi2::delay(mss::cycles_to_ns(i_target, 1024), mss::cycles_to_simcycles(1024));
// 13. Check for DONE in DDRPHY_PC_DLL_ZCAL
for (const auto& p : l_ports)
{
bool l_poll = mss::poll(p, l_zcal_status_reg, poll_parameters(),
[](const size_t poll_remaining, const fapi2::buffer<uint64_t>& stat_reg) -> bool
{
FAPI_INF("phy control zcal cal stat 0x%llx, remaining: %d", stat_reg, poll_remaining);
return mss::pc::get_zcal_status(stat_reg) == mss::YES;
});
FAPI_ASSERT(l_poll,
fapi2::MSS_ZCNTL_FAILED_TO_COMPLETE().set_MCA_IN_ERROR(p),
"zctl enable failed: %s", mss::c_str(p));
}
fapi_try_exit:
return fapi2::current_err;
}
/// @brief Change mclk low
/// @param[in] i_target mcbist target
/// @param[in] i_state mss::HIGH or mss::LOW - desired state.
/// @return FAPI2_RC_SUCCESS iff ok
///
fapi2::ReturnCode change_force_mclk_low (const fapi2::Target<TARGET_TYPE_MCBIST>& i_target,
const mss::states i_state)
{
// Working with Goldade, we learned this:
// From John Bailas: 9:49:46 AM: you need to use that force_mclk_low signal, it needs to be asserted which
// forces RESETN on, and CK/CKN to 0, and all other address/cmd to Z. Then the MC has to establish valid
// values for all signals after PHY reset before force_mclk_low gets de-asserted
// And to celar up the ambiguity of "on" <grin>
// John S. Bialas Jr: Hi Brian, force_mclk_low should force RESETN, CK, and CK# to 0, and all
// other address/command signals to Z
// So, this should be enough to get us going. BRS
// Additionally: from John Bailas
// The PHY should be reset and initialized such that it can synchronously control the RESETN, CK, and CKN
// to the DIMM, then force_mclk_low can be de-asserted and the control of those signals will be synchronously
// maintained. Beyond that the remainder of the DIMM init sequence can be performed, ie. start CK/CKN,
// de-assert RESETN, etc
fapi2::buffer<uint64_t> l_data;
uint8_t l_sim = 0;
// We want to force the memory clocks low for all ports, including the magic port if it's not
// otherwise functional. We don't want to re-enable memory clocks for the magic port if it's
// not otherwise functional.
auto l_ports = (i_state == mss::LOW) ? mss::find_targets_with_magic<TARGET_TYPE_MCA>(i_target) :
mss::find_targets<TARGET_TYPE_MCA>(i_target);
FAPI_INF("force mclk %s for all ports", (i_state == mss::LOW ? "low" : "high") );
FAPI_TRY( mss::is_simulation( l_sim) );
// On cycle sim for some reason clearing force_mclk_low makes the DIMM interface go tri-state.
// On real hardware this should release the memory clocks
if (l_sim && (i_state == mss::LOW))
{
return fapi2::FAPI2_RC_SUCCESS;
}
for (const auto& p : l_ports)
{
FAPI_TRY( mss::getScom(p, MCA_MBA_FARB5Q, l_data) );
l_data.writeBit<MCA_MBA_FARB5Q_CFG_FORCE_MCLK_LOW_N>(i_state);
FAPI_TRY(mss::putScom( p, MCA_MBA_FARB5Q, l_data));
}
fapi_try_exit:
return fapi2::current_err;
}
///
/// @brief Change the continuous update mode of the PR CNTL registers
/// @note Will take the SYSCLK control out of reset, too
/// @param[in] i_target the mcbist target
/// @param[in] i_state, mss::ON if you want to be in continuous mode, mss::OFF to turn it off
/// @return FAPI2_RC_SUCCES iff ok
///
fapi2::ReturnCode setup_phase_rotator_control_registers( const fapi2::Target<TARGET_TYPE_MCBIST>& i_target,
const states i_state )
{
// From the DDR PHY workbook
constexpr uint64_t CONTINUOUS_UPDATE = 0x8024;
FAPI_INF("continuous update: 0x%x", CONTINUOUS_UPDATE);
constexpr uint64_t SIM_OVERRIDE = 0x8080;
constexpr uint64_t PHASE_CNTL_EN = 0x8020;
uint8_t l_sim = 0;
fapi2::buffer<uint64_t> l_update( i_state == mss::ON ? CONTINUOUS_UPDATE : PHASE_CNTL_EN );
const auto l_mca = find_targets<TARGET_TYPE_MCA>(i_target);
std::vector<uint64_t> addrs(
{
MCA_DDRPHY_ADR_SYSCLK_CNTL_PR_P0_ADR32S0, MCA_DDRPHY_ADR_SYSCLK_CNTL_PR_P0_ADR32S1,
MCA_DDRPHY_DP16_SYSCLK_PR0_P0_0, MCA_DDRPHY_DP16_SYSCLK_PR1_P0_0,
MCA_DDRPHY_DP16_SYSCLK_PR0_P0_1, MCA_DDRPHY_DP16_SYSCLK_PR1_P0_1,
MCA_DDRPHY_DP16_SYSCLK_PR0_P0_2, MCA_DDRPHY_DP16_SYSCLK_PR1_P0_2,
MCA_DDRPHY_DP16_SYSCLK_PR0_P0_3, MCA_DDRPHY_DP16_SYSCLK_PR1_P0_3,
// Don't enable MCA_DDRPHY_DP16_SYSCLK_PR1_P0_4 on Nimbus, there is no dp8 there
MCA_DDRPHY_DP16_SYSCLK_PR0_P0_4,
} );
if (l_mca.size() == 0)
{
// No MCA, no problem
return fapi2::FAPI2_RC_SUCCESS;
}
FAPI_TRY( mss::is_simulation( l_sim) );
if (l_sim)
{
// Per Bialas, we don't want to do true alignment in the cycle sim as we have
// a chance of being off one-tick (which is detrimental.) Per his recomendations,
// we write 0's to the control registers and then configure them with 0x8080.
l_update = (i_state == mss::ON) ? 0x0 : SIM_OVERRIDE;
}
// All the MCA (and both registers) will be in the same state, so we can get the first and use it to create the
// values for the others.
FAPI_INF("Write 0x%lx into the ADR SysClk Phase Rotator Control Regs", l_update);
// WRCLK Phase rotators are taken care of in the phy initfile. BRS 6/16.
FAPI_TRY( mss::scom_blastah(l_mca, addrs, l_update) );
fapi_try_exit:
return fapi2::current_err;
}
///
/// @brief Deassert the sys clk reset
/// @param[in] i_target the mcbist target
/// @return FAPI2_RC_SUCCES iff ok
///
fapi2::ReturnCode deassert_sysclk_reset( const fapi2::Target<TARGET_TYPE_MCBIST>& i_target )
{
typedef pcTraits<TARGET_TYPE_MCA> TT;
// Can't just cram 0's in to PC_RESETS as we can't clear the ZCTL_ENABLE bit
FAPI_INF("Clear SysClk reset in the PC Resets Register. This deasserts the SysClk Reset.");
for (const auto& p : mss::find_targets<TARGET_TYPE_MCA>(i_target))
{
fapi2::buffer<uint64_t> l_read;
FAPI_TRY( mss::getScom(p, TT::PC_RESETS_REG, l_read) );
l_read.clearBit<TT::SYSCLK_RESET>();
FAPI_TRY( mss::putScom(p, TT::PC_RESETS_REG, l_read) );
}
fapi_try_exit:
return fapi2::current_err;
}
///
/// @brief Check if the bang bang lock has succeeded
/// @param[in] i_target a MCBIST target
/// @return FAPI2_RC_SUCCESs iff ok
///
fapi2::ReturnCode check_bang_bang_lock( const fapi2::Target<fapi2::TARGET_TYPE_MCBIST>& i_target )
{
fapi2::buffer<uint64_t> l_read;
uint8_t l_sim = 0;
// On each port there are 5 DP16's which have lock registers.
static const std::vector<uint64_t> l_addresses =
{
MCA_DDRPHY_DP16_SYSCLK_PR_VALUE_P0_0,
MCA_DDRPHY_DP16_SYSCLK_PR_VALUE_P0_1,
MCA_DDRPHY_DP16_SYSCLK_PR_VALUE_P0_2,
MCA_DDRPHY_DP16_SYSCLK_PR_VALUE_P0_3,
MCA_DDRPHY_DP16_SYSCLK_PR_VALUE_P0_4,
};
FAPI_TRY( mss::is_simulation( l_sim) );
// There's nothing going on in sim ...
if (l_sim)
{
return fapi2::FAPI2_RC_SUCCESS;
}
for (const auto& p : mss::find_targets<TARGET_TYPE_MCA>(i_target))
{
// Check the ADR lock bit
// Little duplication - makes things more clear and simpler, and allows us to callout the
// bugger which first caused a problem. Since we waited before the check (us) was called
// we can just use the default poll parameters. It will also allow all the subsequent
// polls to complete quickly - as if they're done they don't need a delay.
FAPI_INF("checking %s MCA_DDRPHY_ADR_SYSCLK_PR_VALUE_RO_P0_ADR32S0 0x%016x",
mss::c_str(p), MCA_DDRPHY_ADR_SYSCLK_PR_VALUE_RO_P0_ADR32S0);
FAPI_ASSERT(
mss::poll(p, MCA_DDRPHY_ADR_SYSCLK_PR_VALUE_RO_P0_ADR32S0, poll_parameters(),
[&l_read](const size_t poll_remaining, const fapi2::buffer<uint64_t>& stat_reg) -> bool
{
FAPI_INF("adr32s0 sysclk pr bb lock 0x%llx, remaining: %d", stat_reg, poll_remaining);
l_read = stat_reg;
return stat_reg.getBit<MCA_DDRPHY_ADR_SYSCLK_PR_VALUE_RO_P0_ADR32S0_ADR0_BB_LOCK>() == mss::ON;
}),
fapi2::MSS_ADR_BANG_BANG_FAILED_TO_LOCK().set_MCA_IN_ERROR(p).set_ADR(0),
"ADR failed bb lock. ADR%d register 0x%016lx 0x%016lx", 0,
MCA_DDRPHY_ADR_SYSCLK_PR_VALUE_RO_P0_ADR32S0, l_read
);
FAPI_INF("checking %s MCA_DDRPHY_ADR_SYSCLK_PR_VALUE_RO_P0_ADR32S1 0x%016x",
mss::c_str(p), MCA_DDRPHY_ADR_SYSCLK_PR_VALUE_RO_P0_ADR32S1);
FAPI_ASSERT(
mss::poll(p, MCA_DDRPHY_ADR_SYSCLK_PR_VALUE_RO_P0_ADR32S1, poll_parameters(),
[&l_read](const size_t poll_remaining, const fapi2::buffer<uint64_t>& stat_reg) -> bool
{
FAPI_INF("adr32s1 sysclk pr bb lock 0x%llx, remaining: %d", stat_reg, poll_remaining);
l_read = stat_reg;
return stat_reg.getBit<MCA_DDRPHY_ADR_SYSCLK_PR_VALUE_RO_P0_ADR32S1_ADR1_BB_LOCK>() == mss::ON;
}),
fapi2::MSS_ADR_BANG_BANG_FAILED_TO_LOCK().set_MCA_IN_ERROR(p).set_ADR(1),
"ADR failed bb lock. ADR%d register 0x%016lx 0x%016lx", 1,
MCA_DDRPHY_ADR_SYSCLK_PR_VALUE_RO_P0_ADR32S1, l_read
);
// Pop thru the registers on the ports and see if all the sysclks are locked.
// FFDC regiser collection will collect interesting information so we only need
// to catch the first fail.
for (const auto r : l_addresses)
{
FAPI_TRY( mss::getScom(p, r, l_read) );
FAPI_INF("checking %s MCA_DDRPHY_DP16_SYSCLK_PR_VALUE_P0_0_01_BB_LOCK0 0x%016x",
mss::c_str(p), l_read);
FAPI_ASSERT(
mss::poll(p, r, poll_parameters(),
[&l_read](const size_t poll_remaining, const fapi2::buffer<uint64_t>& stat_reg) -> bool
{
FAPI_INF("dp16 sysclk pr bb lock 0x%llx, remaining: %d", stat_reg, poll_remaining);
l_read = stat_reg;
return stat_reg.getBit<MCA_DDRPHY_DP16_SYSCLK_PR_VALUE_P0_0_01_BB_LOCK0>() == mss::ON;
}),
fapi2::MSS_DP16_BANG_BANG_FAILED_TO_LOCK().set_MCA_IN_ERROR(p).set_ROTATOR(0),
"DP16 failed bb lock. rotator %d register 0x%016lx 0x%016lx", 0, r, l_read
);
FAPI_INF("checking %s MCA_DDRPHY_DP16_SYSCLK_PR_VALUE_P0_0_01_BB_LOCK1 0x%016x",
mss::c_str(p), l_read);
// We're on Nimbus, there are no spares which means the BB_LOCK1 of the last dp16 will never lock
if (r != MCA_DDRPHY_DP16_SYSCLK_PR_VALUE_P0_4)
{
FAPI_ASSERT(
mss::poll(p, r, poll_parameters(),
[&l_read](const size_t poll_remaining, const fapi2::buffer<uint64_t>& stat_reg) -> bool
{
FAPI_INF("dp16 sysclk pr bb lock 0x%llx, remaining: %d", stat_reg, poll_remaining);
l_read = stat_reg;
return stat_reg.getBit<MCA_DDRPHY_DP16_SYSCLK_PR_VALUE_P0_0_01_BB_LOCK1>() == mss::ON;
}),
fapi2::MSS_DP16_BANG_BANG_FAILED_TO_LOCK().set_MCA_IN_ERROR(p).set_ROTATOR(1),
"DP16 failed bb lock. rotator %d register 0x%016lx 0x%016lx", 1, r, l_read
);
}
}
}
fapi_try_exit:
return fapi2::current_err;
}
///
/// @brief Return the DIMM target for the primary rank in the specificed rank pair
/// @param[in] i_target the MCA target
/// @param[in] i_rp the rank pair
/// @param[out] o_dimm fapi2::Target<TARGET_TYPE_DIMM>
/// @return FAPI2_RC_SUCCESS iff ok, FAPI2_RC_INVALID_PARAMETER if rank pair mapping problem
///
template<>
fapi2::ReturnCode rank_pair_primary_to_dimm( const fapi2::Target<TARGET_TYPE_MCA>& i_target,
const uint64_t i_rp,
fapi2::Target<TARGET_TYPE_DIMM>& o_dimm)
{
std::vector<uint64_t> l_ranks_in_rp = {NO_RANK};
// Sanity check the rank pair
FAPI_INF("%s rank pair: %d", mss::c_str(i_target), i_rp);
fapi2::Assert(i_rp < MAX_RANK_PER_DIMM);
// Get the rp's primary rank, and figure out which DIMM it's on
FAPI_TRY( mss::rank::get_ranks_in_pair(i_target, i_rp, l_ranks_in_rp) );
// Make sure we have a valid rank
if (l_ranks_in_rp[0] == NO_RANK)
{
FAPI_ERR("%s No primary rank in rank pair %d", mss::c_str(i_target), i_rp);
return fapi2::FAPI2_RC_INVALID_PARAMETER;
}
FAPI_TRY( mss::rank::get_dimm_target_from_rank(i_target, l_ranks_in_rp[0], o_dimm) );
FAPI_INF("%s rank pair %d is on dimm: %s", mss::c_str(i_target), i_rp, mss::c_str(o_dimm));
fapi_try_exit:
return fapi2::current_err;
}
///
/// @brief check and process initial cal errors
/// @param[in] i_target the port in question
/// @return fapi2::ReturnCode, FAPI2_RC_SUCCESS iff no error
///
template<>
fapi2::ReturnCode process_initial_cal_errors( const fapi2::Target<TARGET_TYPE_MCA>& i_target )
{
typedef pcTraits<TARGET_TYPE_MCA> TT;
uint64_t l_errors = 0;
uint64_t l_rank_pairs = 0;
uint8_t cal_abort_on_error = 0;
fapi2::buffer<uint64_t> l_err_data;
fapi2::Target<TARGET_TYPE_DIMM> l_failed_dimm;
FAPI_TRY( mss::cal_abort_on_error(cal_abort_on_error) );
FAPI_TRY( pc::read_init_cal_error(i_target, l_err_data) );
l_err_data.extractToRight<TT::INIT_CAL_ERROR_WR_LEVEL, TT::CAL_ERROR_FIELD_LEN>(l_errors);
l_err_data.extractToRight<TT::INIT_CAL_ERROR_RANK_PAIR, TT::INIT_CAL_ERROR_RANK_PAIR_LEN>(l_rank_pairs);
FAPI_INF("initial cal err: 0x%016llx, rp: 0x%016llx (0x%016llx)", l_errors, l_rank_pairs, uint64_t(l_err_data));
// Check for RDVREF calibration errors. This fapi_try catches scom errors. Any errors from the
// RDVREF itself are assumed errors only after read centering
FAPI_TRY( dp16::process_rdvref_cal_errors(i_target) );
// WR VREF error processing acts the same as the RD VREF processing
FAPI_TRY( dp16::process_wrvref_cal_errors(i_target) );
if ((l_rank_pairs == 0) || (l_errors == 0))
{
FAPI_INF("Initial cal - no errors reported");
return fapi2::FAPI2_RC_SUCCESS;
}
// Error information from other registers is gathered in the FFDC from the XML
// Get the DIMM which failed. We should only have one rank pair as we calibrate the
// rank pairs individually (we do this so we can see which DIMM failed if more than one
// fails ...) Note first_bit_set gives a bit position (0 being left most.) So, the rank
// in question is the bit postion minus the position of the 0th rank in the register.
// (the rank bits are bits 60:63, for example, so rank 0 is in position 60)
FAPI_TRY( mss::rank_pair_primary_to_dimm(i_target, mss::first_bit_set(l_rank_pairs) - TT::INIT_CAL_ERROR_RANK_PAIR,
l_failed_dimm) );
FAPI_ERR("initial cal failed for %s", mss::c_str(l_failed_dimm));
// If we aborted on error, the disable bits aren't complete so we can't make a determination about
// whether the port is repairable.
if (cal_abort_on_error == fapi2::ENUM_ATTR_MSS_CAL_ABORT_ON_ERROR_YES)
{
FAPI_INF("can't process disable bits as we aborted on error - disable bits might be incomplete");
}
else
{
// Process the disable bits. The PHY will disable bits that it finds don't work for whatever reason.
// However, we can handle a number of bad bits without resorting to killing the DIMM. Do the bad
// bit processing here, and if we can go on and ignore these bad bits, we'll see a succcess here.
if (dp16::process_bad_bits(i_target, l_failed_dimm, l_rank_pairs) == fapi2::FAPI2_RC_SUCCESS)
{
FAPI_INF("Initial cal - errors reported, but only 1 nibble + 1 bit marked %s", mss::c_str(l_failed_dimm));
// If we're on a pre-DD1.02 Nimbus, Anuwat requests we 'pass' training with 1 nibble + 1 bit.
if (mss::chip_ec_feature_mss_training_bad_bits(i_target))
{
return fapi2::FAPI2_RC_SUCCESS;
}
}
}
// So we can do a few things here. If we're aborting on the first calibration error,
// we only expect to have one error bit set. If we ran all the calibrations, we can
// either have one bit set or more than one bit set. If we have more than one bit set
// the result is the same - a broken DIMM which will be deconfigured. So put enough
// information in the FFDC for the lab but we don't need one error for every cal fail.
FAPI_ASSERT(mss::bit_count(l_errors) == 1,
fapi2::MSS_DRAMINIT_TRAINING_MULTIPLE_ERRORS()
.set_FAILED_STEPS(uint64_t(l_err_data))
.set_PORT_POSITION(mss::fapi_pos(i_target))
.set_RANKGROUP_POSITION(l_rank_pairs)
.set_TARGET_IN_ERROR(l_failed_dimm)
.set_TARGET_WITH_REGISTERS(i_target),
"Initial CAL failed %s. dimm: %s, cal err: 0x%016llx",
"multiple training steps", mss::c_str(l_failed_dimm), uint64_t(l_err_data)
);
FAPI_ASSERT( ! l_err_data.getBit<TT::INIT_CAL_ERROR_WR_LEVEL>(),
fapi2::MSS_DRAMINIT_TRAINING_WR_LVL_ERROR()
.set_PORT_POSITION(mss::fapi_pos(i_target))
.set_RANKGROUP_POSITION(l_rank_pairs)
.set_TARGET_IN_ERROR(l_failed_dimm)
.set_TARGET_WITH_REGISTERS(i_target),
"Initial CAL failed %s. dimm: %s, cal err: 0x%016llx",
"write leveling", mss::c_str(l_failed_dimm), uint64_t(l_err_data)
);
FAPI_ASSERT( ! l_err_data.getBit<TT::INIT_CAL_ERROR_INITIAL_PAT_WRITE>(),
fapi2::MSS_DRAMINIT_TRAINING_INITIAL_PAT_WRITE_ERROR()
.set_PORT_POSITION(mss::fapi_pos(i_target))
.set_RANKGROUP_POSITION(l_rank_pairs)
.set_TARGET_IN_ERROR(l_failed_dimm)
.set_TARGET_WITH_REGISTERS(i_target),
"Initial CAL failed %s. dimm: %s, cal err: 0x%016llx",
"initial pattern write", mss::c_str(l_failed_dimm), uint64_t(l_err_data)
);
FAPI_ASSERT( ! l_err_data.getBit<TT::INIT_CAL_ERROR_DQS_ALIGN>(),
fapi2::MSS_DRAMINIT_TRAINING_DQS_ALIGNMENT_ERROR()
.set_PORT_POSITION(mss::fapi_pos(i_target))
.set_RANKGROUP_POSITION(l_rank_pairs)
.set_TARGET_IN_ERROR(l_failed_dimm)
.set_TARGET_WITH_REGISTERS(i_target),
"Initial CAL failed %s. dimm: %s, cal err: 0x%016llx",
"DQS alignment", mss::c_str(l_failed_dimm), uint64_t(l_err_data)
);
FAPI_ASSERT( ! l_err_data.getBit<TT::INIT_CAL_ERROR_RDCLK_ALIGN>(),
fapi2::MSS_DRAMINIT_TRAINING_RD_CLK_SYS_CLK_ALIGNMENT_ERROR()
.set_PORT_POSITION(mss::fapi_pos(i_target))
.set_RANKGROUP_POSITION(l_rank_pairs)
.set_TARGET_IN_ERROR(l_failed_dimm)
.set_TARGET_WITH_REGISTERS(i_target),
"Initial CAL failed %s. dimm: %s, cal err: 0x%016llx",
"read clk alignment", mss::c_str(l_failed_dimm), uint64_t(l_err_data)
);
FAPI_ASSERT( ! l_err_data.getBit<TT::INIT_CAL_ERROR_READ_CTR>(),
fapi2::MSS_DRAMINIT_TRAINING_RD_CENTERING_ERROR()
.set_PORT_POSITION(mss::fapi_pos(i_target))
.set_RANKGROUP_POSITION(l_rank_pairs)
.set_TARGET_IN_ERROR(l_failed_dimm)
.set_TARGET_WITH_REGISTERS(i_target),
"Initial CAL failed %s. dimm: %s, cal err: 0x%016llx",
"read centering", mss::c_str(l_failed_dimm), uint64_t(l_err_data)
);
FAPI_ASSERT( ! l_err_data.getBit<TT::INIT_CAL_ERROR_WRITE_CTR>(),
fapi2::MSS_DRAMINIT_TRAINING_WR_CENTERING_ERROR()
.set_PORT_POSITION(mss::fapi_pos(i_target))
.set_RANKGROUP_POSITION(l_rank_pairs)
.set_TARGET_IN_ERROR(l_failed_dimm)
.set_TARGET_WITH_REGISTERS(i_target),
"Initial CAL failed %s. dimm: %s, cal err: 0x%016llx",
"write centering", mss::c_str(l_failed_dimm), uint64_t(l_err_data)
);
FAPI_ASSERT( ! l_err_data.getBit<TT::INIT_CAL_ERROR_INITIAL_COARSE_WR>(),
fapi2::MSS_DRAMINIT_TRAINING_INITIAL_COARSE_WR_ERROR()
.set_PORT_POSITION(mss::fapi_pos(i_target))
.set_RANKGROUP_POSITION(l_rank_pairs)
.set_TARGET_IN_ERROR(l_failed_dimm)
.set_TARGET_WITH_REGISTERS(i_target),
"Initial CAL failed %s. dimm: %s, cal err: 0x%016llx",
"initial coarse write", mss::c_str(l_failed_dimm), uint64_t(l_err_data)
);
FAPI_ASSERT( ! l_err_data.getBit<TT::INIT_CAL_ERROR_COARSE_RD>(),
fapi2::MSS_DRAMINIT_TRAINING_COARSE_RD_ERROR()
.set_PORT_POSITION(mss::fapi_pos(i_target))
.set_RANKGROUP_POSITION(l_rank_pairs)
.set_TARGET_IN_ERROR(l_failed_dimm)
.set_TARGET_WITH_REGISTERS(i_target),
"Initial CAL failed %s. dimm: %s, cal err: 0x%016llx",
"coarse read", mss::c_str(l_failed_dimm), uint64_t(l_err_data)
);
FAPI_ASSERT( ! l_err_data.getBit<TT::INIT_CAL_ERROR_CUSTOM_RD>(),
fapi2::MSS_DRAMINIT_TRAINING_CUSTOM_PATTERN_RD_ERROR()
.set_PORT_POSITION(mss::fapi_pos(i_target))
.set_RANKGROUP_POSITION(l_rank_pairs)
.set_TARGET_IN_ERROR(l_failed_dimm)
.set_TARGET_WITH_REGISTERS(i_target),
"Initial CAL failed %s. dimm: %s, cal err: 0x%016llx",
"custom read", mss::c_str(l_failed_dimm), uint64_t(l_err_data)
);
FAPI_ASSERT( ! l_err_data.getBit<TT::INIT_CAL_ERROR_CUSTOM_WR>(),
fapi2::MSS_DRAMINIT_TRAINING_CUSTOM_PATTERN_WR_ERROR()
.set_PORT_POSITION(mss::fapi_pos(i_target))
.set_RANKGROUP_POSITION(l_rank_pairs)
.set_TARGET_IN_ERROR(l_failed_dimm)
.set_TARGET_WITH_REGISTERS(i_target),
"Initial CAL failed %s. dimm: %s, cal err: 0x%016llx",
"custom write", mss::c_str(l_failed_dimm), uint64_t(l_err_data)
);
FAPI_ASSERT( ! l_err_data.getBit<TT::INIT_CAL_ERROR_DIGITAL_EYE>(),
fapi2::MSS_DRAMINIT_TRAINING_DIGITAL_EYE_ERROR()
.set_PORT_POSITION(mss::fapi_pos(i_target))
.set_RANKGROUP_POSITION(l_rank_pairs)
.set_TARGET_IN_ERROR(l_failed_dimm)
.set_TARGET_WITH_REGISTERS(i_target),
"Initial CAL failed %s. dimm: %s, cal err: 0x%016llx",
"digital eye", mss::c_str(l_failed_dimm), uint64_t(l_err_data)
);
FAPI_ASSERT( ! l_err_data.getBit<TT::INIT_CAL_ERROR_VREF>(),
fapi2::MSS_DRAMINIT_TRAINING_VREF_ERROR()
.set_PORT_POSITION(mss::fapi_pos(i_target))
.set_RANKGROUP_POSITION(l_rank_pairs)
.set_TARGET_IN_ERROR(l_failed_dimm)
.set_TARGET_WITH_REGISTERS(i_target),
"Initial CAL failed %s. dimm: %s, cal err: 0x%016llx",
"VREF calibration", mss::c_str(l_failed_dimm), uint64_t(l_err_data)
);
fapi_try_exit:
return fapi2::current_err;
}
///
/// @brief Sets up the IO impedances (ADR DRV's and DP DRV's/RCV's) - MCA specialization
/// @tparam T the fapi2::TargetType
/// @param[in] i_target the target (MCA/MCBIST or MBA?)
/// @return FAPI2_RC_SUCCESS if and only if ok
///
template<>
fapi2::ReturnCode reset_io_impedances(const fapi2::Target<fapi2::TARGET_TYPE_MCA>& i_target)
{
FAPI_TRY( mss::dp16::reset_dq_dqs_drv_imp(i_target) );
FAPI_TRY( mss::dp16::reset_dq_dqs_rcv_imp(i_target) );
FAPI_TRY( mss::adr::reset_imp_clk(i_target) );
FAPI_TRY( mss::adr::reset_imp_cmd_addr(i_target) );
FAPI_TRY( mss::adr::reset_imp_cntl(i_target) );
FAPI_TRY( mss::adr::reset_imp_cscid(i_target) );
fapi_try_exit:
return fapi2::current_err;
}
///
/// @brief Perform initializations for the PHY
/// @param[in] i_target the MCBIST which has the PHYs to initialize
/// @return FAPI2_RC_SUCCESS iff ok
///
fapi2::ReturnCode phy_scominit(const fapi2::Target<TARGET_TYPE_MCBIST>& i_target)
{
// Returned from set_rank_pairs, it tells us how many rank pairs we configured on this port.
std::vector<uint64_t> l_pairs;
// Setup the DP16 IO TX, DLL/VREG. They use freq which is an MCBIST attribute
FAPI_TRY( mss::dp16::reset_io_tx_config0(i_target) );
FAPI_TRY( mss::dp16::reset_dll_vreg_config1(i_target) );
for (const auto& p : mss::find_targets<TARGET_TYPE_MCA>(i_target))
{
// No point in bothering if we don't have any DIMM
if (mss::count_dimm(p) == 0)
{
FAPI_INF("No DIMM on %s, not running phy_scominit", mss::c_str(p));
continue;
}
// The following registers must be configured to the correct operating environment:
// Section 5.2.1.3 PC Rank Pair 0 on page 177
// Section 5.2.1.4 PC Rank Pair 1 on page 179
FAPI_TRY( mss::rank::set_rank_pairs(p) );
// Section 5.2.4.1 DP16 Data Bit Enable 0 on page 284
// Section 5.2.4.2 DP16 Data Bit Enable 1 on page 285
// Section 5.2.4.3 DP16 Data Bit Disable 0 on page 288
// Section 5.2.4.4 DP16 Data Bit Disable 1 on page 289
FAPI_TRY( mss::dp16::reset_data_bit_enable(p) );
// Not going to load bad bits from the attributes until after f/w bring up
#ifdef LOAD_BAD_BITS_FROM_ATTR
FAPI_TRY( mss::dp16::reset_bad_bits(p) );
#endif
// New for Nimbus reset the DLL
FAPI_TRY( mss::dp16::reset_dll(p) );
FAPI_TRY( mss::rank::get_rank_pairs(p, l_pairs) );
// Section 5.2.4.8 DP16 Write Clock Enable & Clock Selection on page 301
FAPI_TRY( mss::dp16::reset_write_clock_enable(p, l_pairs) );
FAPI_TRY( mss::dp16::reset_read_clock_enable(p, l_pairs) );
// Reset Read VREF according to ATTR_MSS_VPD_MT_VREF_MC_RD value
FAPI_TRY( mss::dp16::reset_rd_vref(p) );
// PHY Control reset
FAPI_TRY( mss::pc::reset(p) );
// Write Control reset
FAPI_TRY( mss::wc::reset(p) );
// Read Control reset
FAPI_TRY( mss::rc::reset(p) );
// Reset the SEQ block
FAPI_TRY( mss::seq::reset(p) );
// Reset the AC Boost controls from the values in VPD
FAPI_TRY( mss::dp16::reset_ac_boost_cntl(p) );
// Reset the CTLE controls from the values in VPD
FAPI_TRY( mss::dp16::reset_ctle_cntl(p) );
// Shove the ADR delay values from VPD into the ADR delay registers
FAPI_TRY( mss::adr::reset_delay(p) );
// Write tsys adr and tsys data
FAPI_TRY( mss::adr32s::reset_tsys_adr(p) );
FAPI_TRY( mss::dp16::reset_tsys_data(p) );
// Resets all of the IO impedances
FAPI_TRY( mss::reset_io_impedances(p) );
// Resets all WR VREF related registers
FAPI_TRY( mss::dp16::reset_wr_vref_registers(p));
// Reset the windage registers
FAPI_TRY( mss::dp16::reset_read_delay_offset_registers(p) );
//
// Workarounds
//
FAPI_TRY( mss::workarounds::dp16::dqs_polarity(p) );
FAPI_TRY( mss::workarounds::dp16::rd_dia_config5(p) );
FAPI_TRY( mss::workarounds::dp16::dqsclk_offset(p) );
FAPI_TRY( mss::workarounds::seq::odt_config(p) );
}
fapi_try_exit:
return fapi2::current_err;
}
///
/// @brief Setup all the cal config register
/// @param[in] i_target the MCA target associated with this cal setup
/// @param[in] i_rank_pairs the vector of currently configured rank pairs
/// @param[in] i_cal_steps_enabled fapi2::buffer<uint8_t> representing the cal steps to enable
/// @return FAPI2_RC_SUCCESS iff setup was successful
///
template<>
fapi2::ReturnCode setup_cal_config( const fapi2::Target<fapi2::TARGET_TYPE_MCA>& i_target,
const std::vector<uint64_t> i_rank_pairs,
fapi2::buffer<uint16_t> i_cal_steps_enabled)
{
fapi2::buffer<uint64_t> l_cal_config;
uint8_t l_sim = 0;
uint8_t cal_abort_on_error = 0;
uint16_t l_vref_cal_enable = 0;
FAPI_TRY( mss::cal_abort_on_error(cal_abort_on_error) );
FAPI_TRY( mss::is_simulation(l_sim) );
FAPI_TRY( mss::vref_cal_enable(i_target, l_vref_cal_enable) );
// This is the buffer which will be written to CAL_CONFIG0. It starts
// life assuming no cal sequences, no rank pairs - but we set the abort-on-error
// bit ahead of time.
l_cal_config.writeBit<MCA_DDRPHY_PC_INIT_CAL_CONFIG0_P0_ABORT_ON_ERROR>(cal_abort_on_error);
// Check the write centering bits - if write centering is defined, don't run 2D. Vice versa.
if (i_cal_steps_enabled.getBit<WRITE_CTR>() && i_cal_steps_enabled.getBit<WRITE_CTR_2D_VREF>())
{
FAPI_INF("Both 1D and 2D write centering were defined - only performing 2D");
i_cal_steps_enabled.clearBit<WRITE_CTR>();
}
// Sadly, the bits in the register don't align directly with the bits in the attribute.
// So, arrange the bits accordingly and write the config register.
{
// Skip EXT_ZQCAL as it's not in the config register - we do it outside.
// Loop (unrolled because static) over the remaining bits.
l_cal_config.writeBit<MCA_DDRPHY_PC_INIT_CAL_CONFIG0_P0_ENA_WR_LEVEL>(
i_cal_steps_enabled.getBit<WR_LEVEL>());
l_cal_config.writeBit<MCA_DDRPHY_PC_INIT_CAL_CONFIG0_P0_ENA_DQS_ALIGN>(
i_cal_steps_enabled.getBit<DQS_ALIGN>());
l_cal_config.writeBit<MCA_DDRPHY_PC_INIT_CAL_CONFIG0_P0_ENA_RDCLK_ALIGN>(
i_cal_steps_enabled.getBit<RDCLK_ALIGN>());
l_cal_config.writeBit<MCA_DDRPHY_PC_INIT_CAL_CONFIG0_P0_ENA_READ_CTR>(
i_cal_steps_enabled.getBit<READ_CTR>() || i_cal_steps_enabled.getBit<READ_CTR_2D_VREF>());
l_cal_config.writeBit<MCA_DDRPHY_PC_INIT_CAL_CONFIG0_P0_ENA_WRITE_CTR>(
i_cal_steps_enabled.getBit<WRITE_CTR>() || i_cal_steps_enabled.getBit<WRITE_CTR_2D_VREF>());
l_cal_config.writeBit<MCA_DDRPHY_PC_INIT_CAL_CONFIG0_P0_ENA_INITIAL_COARSE_WR>(
i_cal_steps_enabled.getBit<COARSE_WR>());
l_cal_config.writeBit<MCA_DDRPHY_PC_INIT_CAL_CONFIG0_P0_ENA_COARSE_RD>(
i_cal_steps_enabled.getBit<COARSE_RD>());
// Always turn on initial pattern write in h/w, never for sim (makes the DIMM behavioral lose it's mind)
if (!l_sim)
{
l_cal_config.setBit<MCA_DDRPHY_PC_INIT_CAL_CONFIG0_P0_ENA_INITIAL_PAT_WR>();
}
}
// Blast the VREF config with the proper setting for these cal bits if there were any enable bits set
if (l_vref_cal_enable != 0)
{
fapi2::buffer<uint64_t> l_data;
// The two bits we care about are the calibration enable and skip read centering
// bits in rc_vref_config1. We always run RDVREF config, but sometimes skip
// read centering after (if we're not doing those steps.
FAPI_TRY( mss::rc::read_vref_config1(i_target, l_data) );
FAPI_INF("enabling read VREF cal, read centering is %s", i_cal_steps_enabled.getBit<READ_CTR>() ? "yup" : "nope");
l_data.setBit<MCA_DDRPHY_RC_RDVREF_CONFIG1_P0_CALIBRATION_ENABLE>();
if ((i_cal_steps_enabled.getBit<READ_CTR>() == mss::LOW) &&
(i_cal_steps_enabled.getBit<READ_CTR_2D_VREF>() == mss::LOW))
{
FAPI_INF("skipping read centering");
l_data.clearBit<MCA_DDRPHY_RC_RDVREF_CONFIG1_P0_SKIP_RDCENTERING>();
}
FAPI_TRY( mss::rc::write_vref_config1(i_target, l_data) );
}
// Configures WR VREF config register to run 1D (write centering only) or 2D (write centering + VREF) calibration
{
std::vector<fapi2::buffer<uint64_t>> l_vref_config;
FAPI_TRY( mss::scom_suckah(i_target, mss::dp16Traits<fapi2::TARGET_TYPE_MCA>::WR_VREF_CONFIG0_REG, l_vref_config) );
// Loops and sets or clears the 2D VREF bit on all DPs
// Note: 2D VREF needs to be a 0 in the reg if it is to be enabled, hence the not in the write bit function
for(auto& l_data : l_vref_config)
{
l_data.writeBit<MCA_DDRPHY_DP16_WR_VREF_CONFIG0_P0_0_01_CTR_1D_CHICKEN_SWITCH>
(!i_cal_steps_enabled.getBit<WRITE_CTR_2D_VREF>());
}
FAPI_TRY(mss::scom_blastah(i_target, mss::dp16Traits<fapi2::TARGET_TYPE_MCA>::WR_VREF_CONFIG0_REG, l_vref_config));
}
// loops through all RP's running workarounds and latching the VREF's as need be
for(const auto& l_rp : i_rank_pairs)
{
// Latches in the WR VREF values
// Overrides will be set by mss::workarounds::wr_vref::execute.
// If the execute code is skipped, then it will read from the attributes
uint8_t l_vrefdq_train_range_override = mss::ddr4::USE_DEFAULT_WR_VREF_SETTINGS;
uint8_t l_vrefdq_train_value_override = mss::ddr4::USE_DEFAULT_WR_VREF_SETTINGS;
// Runs WR VREF workarounds if needed
// it will check and see if it needs to run, if not it will return success
FAPI_TRY( mss::workarounds::wr_vref::execute(i_target,
l_rp,
i_cal_steps_enabled,
l_vrefdq_train_range_override,
l_vrefdq_train_value_override) );
// Latches the VREF's
FAPI_TRY( mss::ddr4::latch_wr_vref_commands_by_rank_pair( i_target,
l_rp,
l_vrefdq_train_range_override,
l_vrefdq_train_value_override ) );
}
// Note: This rank encoding isn't used if the cal is initiated from the CCS engine
// as they use the recal inteface.
// Configure the rank pairs
for (const auto& rp : i_rank_pairs)
{
l_cal_config.setBit(MCA_DDRPHY_PC_INIT_CAL_CONFIG0_P0_ENA_RANK_PAIR + rp);
}
FAPI_INF("cal_config for %s: 0x%lx (steps: 0x%lx)",
mss::c_str(i_target), uint16_t(l_cal_config), uint16_t(i_cal_steps_enabled));
FAPI_TRY( mss::putScom(i_target, MCA_DDRPHY_PC_INIT_CAL_CONFIG0_P0, l_cal_config) );
// Setsup the workarounds
FAPI_TRY(mss::workarounds::dp16::rd_vref_vref_sense_setup(i_target));
fapi_try_exit:
return fapi2::current_err;
}
///
/// @brief Setup all the cal config register
/// @param[in] i_target the target associated with this cal setup
/// @param[in] i_rank one currently configured rank pairs
/// @param[in] i_cal_steps_enabled fapi2::buffer<uint16_t> representing the cal steps to enable
/// @return FAPI2_RC_SUCCESS iff setup was successful
///
fapi2::ReturnCode setup_cal_config( const fapi2::Target<fapi2::TARGET_TYPE_MCA>& i_target,
const uint64_t i_rank,
const fapi2::buffer<uint16_t> i_cal_steps_enabled)
{
std::vector< uint64_t > l_ranks({i_rank});
return setup_cal_config(i_target, l_ranks, i_cal_steps_enabled);
}
///
/// @brief Execute a set of PHY cal steps
/// Specializaton for TARGET_TYPE_MCA
/// @param[in] i_target the target associated with this cal
/// @param[in] i_rp one of the currently configured rank pairs
/// @param[in] i_cal_steps_enabled fapi2::buffer<uint16_t> representing the cal steps to enable
/// @param[in] i_abort_on_error CAL_ABORT_ON_ERROR override
/// @return FAPI2_RC_SUCCESS iff setup was successful
/// @note This is a helper function. Library users are required to call setup_and_execute_cal
///
template<>
fapi2::ReturnCode execute_cal_steps_helper( const fapi2::Target<fapi2::TARGET_TYPE_MCA>& i_target,
const uint64_t i_rp,
const fapi2::buffer<uint16_t> i_cal_steps_enabled,
const uint8_t i_abort_on_error)
{
const auto& l_mcbist = mss::find_target<TARGET_TYPE_MCBIST>(i_target);
auto l_cal_inst = mss::ccs::initial_cal_command<TARGET_TYPE_MCBIST>(i_rp);
mss::ccs::program<TARGET_TYPE_MCBIST, TARGET_TYPE_MCA> l_program;
// Sanity check due to WR_LEVEL termination requirement
if ((i_cal_steps_enabled.getBit<mss::cal_steps::WR_LEVEL>()) &&
(mss::bit_count(static_cast<uint64_t>(i_cal_steps_enabled)) != 1))
{
FAPI_ERR("WR_LEVEL cal step requires special terminations, so must be run separately from other cal steps");
fapi2::Assert(false);
}
FAPI_DBG("executing training CCS instruction: 0x%llx, 0x%llx", l_cal_inst.arr0, l_cal_inst.arr1);
// Delays in the CCS instruction ARR1 for training are supposed to be 0xFFFF,
// and we're supposed to poll for the done or timeout bit. But we don't want
// to wait 0xFFFF cycles before we start polling - that's too long. So we put
// in a best-guess of how long to wait. This, in a perfect world, would be the
// time it takes one rank to train one training algorithm times the number of
// ranks we're going to train. We fail-safe as worst-case we simply poll the
// register too much - so we can tune this as we learn more.
l_program.iv_poll.iv_initial_sim_delay = 200;
l_program.iv_poll.iv_poll_count = 0xFFFF;
l_program.iv_instructions.push_back(l_cal_inst);
// We need to figure out how long to wait before we start polling. Each cal step has an expected
// duration, so for each cal step which was enabled, we update the CCS program.
FAPI_TRY( mss::cal_timer_setup(i_target, l_program.iv_poll, i_cal_steps_enabled) );
FAPI_TRY( mss::setup_cal_config(i_target, i_rp, i_cal_steps_enabled) );
// In the event of an init cal hang, CCS_STATQ(2) will assert and CCS_STATQ(3:5) = “001” to indicate a
// timeout. Otherwise, if calibration completes, FW should inspect DDRPHY_FIR_REG bits (50) and (58)
// for signs of a calibration error. If either bit is on, then the DDRPHY_PC_INIT_CAL_ERROR register
// should be polled to determine which calibration step failed.
// If we got a cal timeout, or another CCS error just leave now. If we got success, check the error
// bits for a cal failure. We'll return the proper ReturnCode so all we need to do is FAPI_TRY.
FAPI_TRY( mss::ccs::execute(l_mcbist, l_program, i_target) );
fapi_try_exit:
return fapi2::current_err;
}
///
/// @brief Perform necessary termination setup and execute a set of PHY cal steps
/// Specializaton for TARGET_TYPE_MCA
/// @param[in] i_target the target associated with this cal
/// @param[in] i_rp one of the currently configured rank pairs