summaryrefslogtreecommitdiffstats
path: root/src/import/chips/centaur/procedures/hwp/memory/p9c_mss_freq.C
blob: d15ff20633e8efbe5b78dc8bbaac50f2641f524d (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/centaur/procedures/hwp/memory/p9c_mss_freq.C $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,2018                        */
/* [+] 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 p9c_mss_freq.C
/// @brief DIMM SPD attributes are read to determine optimal DRAM frequency
///
/// *HWP HWP Owner: Luke Mulkey <lwmulkey@us.ibm.com>
/// *HWP HWP Backup: Andre Marin <aamaring@us.ibm.com>
/// *HWP Team: Memory
/// *HWP Level: 2
/// *HWP Consumed by: HB
///

//----------------------------------------------------------------------
//  Includes - FAPI
//----------------------------------------------------------------------
#include <fapi2.H>
#include <p9c_mss_freq.H>
#include <dimmConsts.H>
#include <generic/memory/lib/utils/c_str.H>
//----------------------------------------------------------------------
// ENUMs
//----------------------------------------------------------------------
enum
{
    MSS_FREQ_EMPTY = 0,
    MSS_FREQ_SINGLE_DROP = 1,
    MSS_FREQ_DUAL_DROP = 2,
    MSS_FREQ_VALID = 255,
};

//----------------------------------------------------------------------
//  Constants
//----------------------------------------------------------------------
constexpr uint8_t DDR4_MTB_DIVIDEND = 1;
constexpr uint8_t DDR4_MTB_DIVISOR = 8;
constexpr uint8_t DDR4_FTB_DIVIDEND = 1;
constexpr uint8_t DDR4_FTB_DIVISOR = 1;
constexpr uint8_t NUM_CL_SUPPORTED = 21;
constexpr uint8_t DDR3_CL_SUPPORT_OFFSET = 4;
constexpr uint8_t DDR4_CL_SUPPORT_OFFSET = 7;
constexpr uint8_t MAX_CL_SUPPORTED = 14;
constexpr uint64_t DDR3_TAA_MAX = 20000;
constexpr uint64_t DDR4_TAA_MAX = 18000;
constexpr uint64_t DDR4_3DS_TAA_MAX = 21500;

///Bool function for DDR3/DDR4 CL Supported Check
///
/// @brief Checks calculated CL against supported list in SPD
/// @param[in] i_spd_cas_lat_supported_all List of CL supported in SPD
/// @param[in] i_cl_support_offset Offset for DDR3/DDR4 decode
/// @param[in] i_cas_latency Calculated CAS Latency
/// @return 1 if unsupported, 0 if supported
///
bool mss_freq_unsupported_cl(
    const uint32_t i_spd_cas_lat_supported_all,
    const uint8_t  i_cl_support_offset,
    const uint8_t  i_cas_latency)
{
    return (!( i_spd_cas_lat_supported_all & (0x00000001 << (i_cas_latency - i_cl_support_offset))));
}

///
/// @brief DIMM SPD attributes are read to determine optimal DRAM frequency
/// @param[in] i_target_memb Centaur target
/// @return FAPI2_RC_SUCCESS iff frequency + CL found successfully
///
fapi2::ReturnCode p9c_mss_freq(const fapi2::Target<fapi2::TARGET_TYPE_MEMBUF_CHIP>& i_target_memb)
{
    uint8_t l_spd_mtb_dividend = 0;
    uint8_t l_spd_mtb_divisor = 0;
    uint8_t l_spd_ftb_dividend = 0;
    uint8_t l_spd_ftb_divisor = 0;
    uint32_t l_dimm_freq_calc = 0;
    uint32_t l_dimm_freq_min = 9999;
    uint8_t l_spd_min_tck_MTB = 0;
    uint8_t l_spd_tck_offset_FTB = 0;
    uint8_t l_spd_tck_offset = 0;
    uint32_t l_spd_min_tck = 0;
    uint32_t l_spd_min_tck_max = 0;
    uint8_t  l_spd_min_taa_MTB = 0;
    uint8_t  l_spd_taa_offset_FTB = 0;
    uint8_t  l_spd_taa_offset = 0;
    uint32_t l_spd_min_taa = 0;
    uint32_t l_spd_min_taa_max = 0;
    uint32_t l_selected_dimm_freq = 0;
    uint32_t l_spd_cas_lat_supported = 0xFFFFFFFF;
    uint32_t l_spd_cas_lat_supported_all = 0xFFFFFFFF;
    uint8_t l_cas_latency = 0;
    uint32_t l_cl_mult_tck = 0;
    uint8_t l_cur_mba_port = 0;
    uint8_t l_cur_mba_dimm = 0;
    uint8_t l_cur_mba = 0;
    uint8_t l_cur_dimm_spd_valid_u8array[MAX_MBA_PER_CEN][MAX_PORTS_PER_MBA][MAX_DIMM_PER_PORT] = {{{0}}};
    uint8_t l_plug_config = 0;
    uint8_t l_module_type = 0;
    uint8_t l_module_type_deconfig = 0;
    uint8_t l_module_type_group_1 = 0;
    uint8_t l_module_type_group_2 = 0;
    uint8_t l_module_type_group_1_total = 0;
    uint8_t l_module_type_group_2_total = 0;
    uint8_t l_num_ranks[MAX_MBA_PER_CEN][MAX_PORTS_PER_MBA][MAX_DIMM_PER_PORT] = {{{0}}};
    uint8_t l_num_ranks_total = 0;
    uint32_t  l_freq_override = 0;
    uint8_t l_override_path = 0;
    uint8_t l_nest_capable_frequencies = 0;
    uint8_t l_spd_dram_dev_type;
    uint8_t l_spd_tb_mtb_ddr4 = 0;
    uint8_t l_spd_tb_ftb_ddr4 = 0;
    uint8_t l_spd_tckmax_ddr4 = 0;
    uint8_t l_cl_count_array[NUM_CL_SUPPORTED];
    uint8_t l_highest_common_cl = 0;
    uint8_t l_highest_cl_count = 0;
    uint8_t l_lowest_common_cl = 0;
    uint32_t l_lowest_cl_count = 0xFFFFFFFF;
    uint8_t l_cl_support_offset = 0;
    uint64_t l_taa_max = 0;
    uint8_t l_spd_sdram_dev_type = 0;
    uint8_t l_spd_sdram_dev_type_sig_loading = 0;

    for(uint8_t i = 0; i < NUM_CL_SUPPORTED; i++)
    {
        l_cl_count_array[i] = 0; // Initializing each element separately
    }

    // Get associated MBA's on this centaur
    const auto l_mbaChiplets = i_target_memb.getChildren<fapi2::TARGET_TYPE_MBA>();

    // Loop through the 2 MBA's
    for (const auto& l_mba : l_mbaChiplets)
    {
        // Get a vector of DIMM targets
        const auto l_dimm_targets = l_mba.getChildren<fapi2::TARGET_TYPE_DIMM>();

        for (const auto& l_dimm : l_dimm_targets)
        {
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_SPD_DRAM_DEVICE_TYPE, l_dimm,  l_spd_dram_dev_type));
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_SPD_SDRAM_DEVICE_TYPE, l_dimm, l_spd_sdram_dev_type));
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_SPD_SDRAM_DEVICE_TYPE_SIGNAL_LOADING, l_dimm, l_spd_sdram_dev_type_sig_loading));


            if (l_spd_dram_dev_type == fapi2::ENUM_ATTR_CEN_SPD_DRAM_DEVICE_TYPE_DDR4)
            {
                // DDR4 ONLY
                FAPI_DBG("DDR4 detected");

                FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_SPD_TIMEBASE_MTB_DDR4, l_dimm,  l_spd_tb_mtb_ddr4));
                FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_SPD_TIMEBASE_FTB_DDR4, l_dimm,  l_spd_tb_ftb_ddr4));
                FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_SPD_TCKMAX_DDR4, l_dimm,  l_spd_tckmax_ddr4));

                if ( (l_spd_tb_mtb_ddr4 == 0) && (l_spd_tb_ftb_ddr4 == 0))
                {
                    // These are now considered constant within DDR4
                    // If DDR4 spec changes to include other values, these const's need to be updated
                    l_spd_mtb_dividend = DDR4_MTB_DIVIDEND;
                    l_spd_mtb_divisor = DDR4_MTB_DIVISOR;
                    l_spd_ftb_dividend = DDR4_FTB_DIVIDEND;
                    l_spd_ftb_divisor = DDR4_FTB_DIVISOR;
                }
                else
                {
                    //Invalid due to the fact that JEDEC dictates that these should be zero.
                    // Log error and continue to next DIMM
                    FAPI_ASSERT_NOEXIT(false,
                                       fapi2::CEN_MSS_UNSUPPORTED_SPD_DATA_DDR4().
                                       set_MTB_DDR4(l_spd_tb_mtb_ddr4).
                                       set_FTB_DDR4(l_spd_tb_ftb_ddr4).
                                       set_DIMM_TARGET( l_dimm),
                                       "Invalid data received from SPD DDR4 MTB/FTB Timebase");
                    continue;
                }
            }
            else
            {
                // DDR3 ONLY
                FAPI_DBG("DDR3 detected");

                FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_SPD_MTB_DIVIDEND, l_dimm, l_spd_mtb_dividend),
                         "Unable to read SPD Medium Timebase Dividend.");
                FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_SPD_MTB_DIVISOR, l_dimm, l_spd_mtb_divisor),
                         "Unable to read SPD Medium Timebase Divisor.");
                FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_SPD_FTB_DIVIDEND,  l_dimm, l_spd_ftb_dividend),
                         "Unable to read the SPD FTB dividend");
                FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_SPD_FTB_DIVISOR,  l_dimm, l_spd_ftb_divisor),
                         "Unable to read the SPD FTB divisor");
                FAPI_ASSERT((l_spd_mtb_dividend != 0) && (l_spd_mtb_divisor != 0) && (l_spd_ftb_dividend != 0)
                            && (l_spd_ftb_divisor != 0),
                            fapi2::CEN_MSS_UNSUPPORTED_SPD_DATA_DDR3().
                            set_MTB_DIVIDEND(l_spd_mtb_dividend).
                            set_MTB_DIVISOR(l_spd_mtb_divisor).
                            set_FTB_DIVIDEND(l_spd_ftb_dividend).
                            set_FTB_DIVISOR(l_spd_ftb_divisor).
                            set_DIMM_TARGET(l_dimm),
                            "Invalid data received from SPD within MTB/FTB Dividend, MTB/FTB Divisor");

            }

            // common to both DDR3 & DDR4
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_SPD_TCKMIN, l_dimm,  l_spd_min_tck_MTB));
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_SPD_TAAMIN, l_dimm,  l_spd_min_taa_MTB));
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_SPD_CAS_LATENCIES_SUPPORTED, l_dimm,  l_spd_cas_lat_supported));
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_MBA_PORT, l_dimm,  l_cur_mba_port));
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_MBA_DIMM, l_dimm,  l_cur_mba_dimm));
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CHIP_UNIT_POS, l_mba,  l_cur_mba));
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_SPD_MODULE_TYPE, l_dimm,  l_module_type));

            // from dimm_spd_attributes.xml, R1 = 0x00, R2 = 0x01, R3 = 0x02, R4 = 0x03
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_SPD_NUM_RANKS, l_dimm,
                                   l_num_ranks[l_cur_mba][l_cur_mba_port][l_cur_mba_dimm]));

            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_SPD_FINE_OFFSET_TAAMIN, l_dimm,  l_spd_taa_offset_FTB));
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_SPD_FINE_OFFSET_TCKMIN, l_dimm,  l_spd_tck_offset_FTB));

            l_cur_dimm_spd_valid_u8array[l_cur_mba][l_cur_mba_port][l_cur_mba_dimm] = MSS_FREQ_VALID;

            if ((l_spd_min_tck_MTB == 0) || (l_spd_min_taa_MTB == 0))
            {
                //Invalid due to the fact that JEDEC dictates that these should be non-zero.
                // Log error and continue to next DIMM
                FAPI_ASSERT_NOEXIT(false,
                                   fapi2::CEN_MSS_UNSUPPORTED_SPD_DATA_COMMON().
                                   set_MIN_TCK(l_spd_min_tck_MTB).
                                   set_MIN_TAA(l_spd_min_taa_MTB).
                                   set_DIMM_TARGET(l_dimm).

                                   set_TARGET(i_target_memb),
                                   "Invalid data received from SPD within TCK Min, or TAA Min");
                continue;
            }

            // Calc done on PS units (the multiplication of 1000) to avoid rounding errors.
            // Frequency listed with multiplication of 2 as clocking data on both +- edges
            l_spd_min_tck =  ( 1000 * l_spd_min_tck_MTB * l_spd_mtb_dividend ) / l_spd_mtb_divisor;
            l_spd_min_taa =  ( 1000 * l_spd_min_taa_MTB * l_spd_mtb_dividend ) / l_spd_mtb_divisor;

            FAPI_INF("min tck = %i, taa = %i", l_spd_min_tck, l_spd_min_taa);
            FAPI_INF("FTB tck 0x%x, taa 0x%x", l_spd_tck_offset_FTB, l_spd_taa_offset_FTB);

            // Adjusting by tck offset -- tck offset represented in 2's compliment as it could be positive or negative adjustment
            // No multiplication of 1000 as it is already in picoseconds.
            if (l_spd_tck_offset_FTB & 0x80)
            {
                l_spd_tck_offset_FTB = ~( l_spd_tck_offset_FTB ) + 1;
                l_spd_tck_offset = (l_spd_tck_offset_FTB  * l_spd_ftb_dividend )  / l_spd_ftb_divisor;
                l_spd_min_tck =  l_spd_min_tck - l_spd_tck_offset;
                FAPI_INF("FTB minus offset %i, min tck %i", l_spd_tck_offset, l_spd_min_tck);
            }
            else
            {
                l_spd_tck_offset = (l_spd_tck_offset_FTB  * l_spd_ftb_dividend )  / l_spd_ftb_divisor;
                l_spd_min_tck =  l_spd_min_tck + l_spd_tck_offset;
                FAPI_INF("FTB plus offset %i, min tck %i", l_spd_tck_offset, l_spd_min_tck);
            }

            // Adjusting by taa offset -- taa offset represented in 2's compliment as it could be positive or negative adjustment
            if (l_spd_taa_offset_FTB & 0x80)
            {
                l_spd_taa_offset_FTB = ~( l_spd_taa_offset_FTB) + 1;
                l_spd_taa_offset = (l_spd_taa_offset_FTB  * l_spd_ftb_dividend )  / l_spd_ftb_divisor;
                l_spd_min_taa =  l_spd_min_taa - l_spd_taa_offset;
            }
            else
            {
                l_spd_taa_offset = (l_spd_taa_offset_FTB  * l_spd_ftb_dividend )  / l_spd_ftb_divisor;
                l_spd_min_taa =  l_spd_min_taa + l_spd_taa_offset;
            }

            if ((l_spd_min_tck == 0) || (l_spd_min_taa == 0))
            {
                //Invalid due to the fact that JEDEC dictates that these should be non-zero.
                // Log error and continue to next DIMM
                FAPI_ASSERT_NOEXIT(false,
                                   fapi2::CEN_MSS_UNSUPPORTED_SPD_DATA_COMMON().
                                   set_MIN_TCK(l_spd_min_tck_MTB).
                                   set_MIN_TAA(l_spd_min_taa_MTB).
                                   set_DIMM_TARGET(l_dimm).
                                   set_TARGET(i_target_memb),
                                   "Invalid data received from SPD causing TCK Min or TAA Min to be 0");
                continue;
            }

            l_dimm_freq_calc = 2000000 / l_spd_min_tck;

            FAPI_INF( "TAA(ps): %d TCK(ps): %d Calc'ed Freq for this dimm: %d", l_spd_min_taa, l_spd_min_tck, l_dimm_freq_calc);

            //is this the slowest dimm?
            if (l_dimm_freq_calc < l_dimm_freq_min)
            {
                l_dimm_freq_min = l_dimm_freq_calc;
            }

            if (l_spd_min_tck > l_spd_min_tck_max)
            {
                l_spd_min_tck_max = l_spd_min_tck;
            }

            if (l_spd_min_taa > l_spd_min_taa_max)
            {
                l_spd_min_taa_max = l_spd_min_taa;
            }

            if ( l_spd_cas_lat_supported & 0x00000001 )
            {
                l_cl_count_array[0]++;
            }
            else if ( l_spd_cas_lat_supported & 0x00000002 )
            {
                l_cl_count_array[1]++;
            }
            else if ( l_spd_cas_lat_supported & 0x00000004 )
            {
                l_cl_count_array[2]++;
            }
            else if ( l_spd_cas_lat_supported & 0x00000008 )
            {
                l_cl_count_array[3]++;
            }
            else if ( l_spd_cas_lat_supported & 0x00000010 )
            {
                l_cl_count_array[4]++;
            }
            else if ( l_spd_cas_lat_supported & 0x00000020 )
            {
                l_cl_count_array[5]++;
            }
            else if ( l_spd_cas_lat_supported & 0x00000040 )
            {
                l_cl_count_array[6]++;
            }
            else if ( l_spd_cas_lat_supported & 0x00000080 )
            {
                l_cl_count_array[7]++;
            }
            else if ( l_spd_cas_lat_supported & 0x00000100 )
            {
                l_cl_count_array[8]++;
            }
            else if ( l_spd_cas_lat_supported & 0x00000200 )
            {
                l_cl_count_array[9]++;
            }
            else if ( l_spd_cas_lat_supported & 0x00000400)
            {
                l_cl_count_array[10]++;
            }
            else if ( l_spd_cas_lat_supported & 0x00000800 )
            {
                l_cl_count_array[11]++;
            }
            else if ( l_spd_cas_lat_supported & 0x00001000 )
            {
                l_cl_count_array[12]++;
            }
            else if ( l_spd_cas_lat_supported & 0x00002000 )
            {
                l_cl_count_array[13]++;
            }
            else if ( l_spd_cas_lat_supported & 0x00004000)
            {
                l_cl_count_array[14]++;
            }
            else if ( l_spd_cas_lat_supported & 0x00008000 )
            {
                l_cl_count_array[15]++;
            }
            else if ( l_spd_cas_lat_supported & 0x00010000 )
            {
                l_cl_count_array[16]++;
            }
            else if ( l_spd_cas_lat_supported & 0x00020000 )
            {
                l_cl_count_array[17]++;
            }
            else if ( l_spd_cas_lat_supported & 0x00040000)
            {
                l_cl_count_array[18]++;
            }
            else if ( l_spd_cas_lat_supported & 0x00080000 )
            {
                l_cl_count_array[19]++;
            }
            else if ( l_spd_cas_lat_supported & 0x00100000 )
            {
                l_cl_count_array[20]++;
            }

            l_spd_cas_lat_supported_all = l_spd_cas_lat_supported_all & l_spd_cas_lat_supported;

            if ( (l_module_type_group_1 == l_module_type) || (l_module_type_group_1 == 0) )
            {
                l_module_type_group_1 = l_module_type;
                l_module_type_group_1_total++;
            }
            else if ( (l_module_type_group_2 == l_module_type) || (l_module_type_group_2 == 0) )
            {
                l_module_type_group_2 = l_module_type;
                l_module_type_group_2_total++;
            }

        } // DIMM
    } // MBA

    // Check for DIMM Module Type Mixing
    if (l_module_type_group_2 != 0)
    {
        if (l_module_type_group_1_total > l_module_type_group_2_total)
        {
            l_module_type_deconfig = l_module_type_group_1;
        }
        else
        {
            l_module_type_deconfig = l_module_type_group_2;
        }

        // Loop through the 2 MBA's
        for (const auto& l_mba : l_mbaChiplets)
        {
            // Get a vector of DIMM targets
            const auto l_dimm_targets = l_mba.getChildren<fapi2::TARGET_TYPE_DIMM>();

            for (const auto& l_dimm : l_dimm_targets)
            {
                FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_SPD_MODULE_TYPE, l_dimm,  l_module_type));

                FAPI_ASSERT_NOEXIT(l_module_type != l_module_type_deconfig,
                                   fapi2::CEN_MSS_MODULE_TYPE_MIX().
                                   set_DIMM_TARGET(l_dimm).
                                   set_MODULE_TYPE(l_module_type),
                                   "Mixing of DIMM Module Types (%d, %d) deconfiguring minority type: %d", l_module_type_group_1, l_module_type_group_2,
                                   l_module_type_deconfig);
            } // DIMM
        } // MBA
    } // if

    FAPI_INF( "Highest Supported Frequency amongst DIMMs: %d", l_dimm_freq_min);
    FAPI_INF( "Minimum TAA(ps) amongst DIMMs: %d Minimum TCK(ps) amongst DIMMs: %d", l_spd_min_taa_max, l_spd_min_tck_max);

    //Determining the cnfg for imposing any cnfg speed limitations
    if (((l_cur_dimm_spd_valid_u8array[0][0][0] == MSS_FREQ_VALID)
         && (l_cur_dimm_spd_valid_u8array[0][0][1] == MSS_FREQ_EMPTY))
        || ((l_cur_dimm_spd_valid_u8array[0][0][1] == MSS_FREQ_VALID)
            && (l_cur_dimm_spd_valid_u8array[0][0][0] == MSS_FREQ_EMPTY)))
    {
        l_plug_config = MSS_FREQ_SINGLE_DROP;
        l_num_ranks_total = l_num_ranks[0][0][0] + 1;
    }
    else if (((l_cur_dimm_spd_valid_u8array[1][0][0] == MSS_FREQ_VALID)
              && (l_cur_dimm_spd_valid_u8array[1][0][1] == MSS_FREQ_EMPTY))
             || ((l_cur_dimm_spd_valid_u8array[1][0][1] == MSS_FREQ_VALID)
                 && (l_cur_dimm_spd_valid_u8array[1][0][0] == MSS_FREQ_EMPTY)))
    {
        l_plug_config = MSS_FREQ_SINGLE_DROP;
        l_num_ranks_total = l_num_ranks[1][0][0] + 1;
    }
    else if ((l_cur_dimm_spd_valid_u8array[0][0][0] == MSS_FREQ_VALID)
             && (l_cur_dimm_spd_valid_u8array[0][0][1] == MSS_FREQ_VALID))
    {
        l_plug_config = MSS_FREQ_DUAL_DROP;
        l_num_ranks_total = (l_num_ranks[0][0][0] + 1) + (l_num_ranks[0][0][1] + 1);
    }
    else if ((l_cur_dimm_spd_valid_u8array[1][0][0] == MSS_FREQ_VALID)
             && (l_cur_dimm_spd_valid_u8array[1][0][1] == MSS_FREQ_VALID))
    {
        l_plug_config = MSS_FREQ_DUAL_DROP;
        l_num_ranks_total = (l_num_ranks[1][0][0] + 1) + (l_num_ranks[1][0][1] + 1);
    }
    else
    {
        l_plug_config = MSS_FREQ_EMPTY;
    }

    FAPI_INF( "PLUG CONFIG(from SPD): %d, Type of Dimm(from SPD): 0x%02X, Num Ranks(from SPD): %d",  l_plug_config,
              l_module_type, l_num_ranks_total);

    // Impose configuration limitations
    // Single Drop RDIMMs Cnfgs cannot run faster than 1333
    // DDR4 min speed 1600 and Cen no longer supports 1866.
    if (l_spd_dram_dev_type == fapi2::ENUM_ATTR_CEN_SPD_DRAM_DEVICE_TYPE_DDR4)
    {
        l_dimm_freq_min = 1600;
        l_spd_min_tck_max = 1250;
        FAPI_INF( "DDR4/Centaur limitation. Centaur no longer handles 1866 and 1600 is min speed of DDR4.  New Freq: %d",
                  l_dimm_freq_min);
    }
    else if ((l_module_type_group_1 == fapi2::ENUM_ATTR_CEN_SPD_MODULE_TYPE_RDIMM)
             && (l_plug_config == MSS_FREQ_SINGLE_DROP)
             && (l_dimm_freq_min > 1333))
    {
        l_dimm_freq_min = 1333;
        l_spd_min_tck_max = 1500;
        FAPI_INF( "Single Drop RDIMM with more than 1 Rank Cnfg limitation.  New Freq: %d", l_dimm_freq_min);
    }
    // Double Drop RDIMMs Cnfgs cannot run faster than 1333 with less than 8 ranks total per port
    else if ((l_module_type_group_1 == fapi2::ENUM_ATTR_CEN_SPD_MODULE_TYPE_RDIMM) && (l_plug_config == MSS_FREQ_DUAL_DROP)
             && (l_num_ranks_total < 8) && (l_dimm_freq_min > 1333))
    {
        l_dimm_freq_min = 1333;
        l_spd_min_tck_max = 1500;
        FAPI_INF( "Dual Drop RDIMM with more than 4 Rank Cnfg limitation.  New Freq: %d", l_dimm_freq_min);
    }
    // Double Drop RDIMMs Cnfgs cannot run faster than 1066 with 8 ranks total per port
    else if ((l_module_type_group_1 == fapi2::ENUM_ATTR_CEN_SPD_MODULE_TYPE_RDIMM) && (l_plug_config == MSS_FREQ_DUAL_DROP)
             && (l_num_ranks_total == 8) && (l_dimm_freq_min > 1066))
    {
        l_dimm_freq_min = 1066;
        l_spd_min_tck_max = 1875;
        FAPI_INF( "Dual Drop RDIMM with more than 8 Rank Cnfg limitation.  New Freq: %d", l_dimm_freq_min);
    }

    if ( l_spd_min_tck_max == 0)
    {
        // Loop through the 2 MBA's
        for (const auto& l_mba : l_mbaChiplets)
        {
            // Get a vector of DIMM targets
            const auto l_dimm_targets = l_mba.getChildren<fapi2::TARGET_TYPE_DIMM>();

            for (const auto& l_dimm : l_dimm_targets)
            {
                FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_SPD_TCKMIN, l_dimm,  l_spd_min_tck_MTB));

                FAPI_ASSERT_NOEXIT(l_spd_min_tck_MTB != 0,
                                   fapi2::CEN_MSS_UNSUPPORTED_SPD_DATA_COMMON().
                                   set_MIN_TCK(l_spd_min_tck_max).
                                   set_MIN_TAA(l_spd_min_taa_max).
                                   set_DIMM_TARGET( l_dimm).
                                   set_TARGET(i_target_memb),
                                   "l_spd_min_tck_max = 0 unable to calculate freq or cl.  Possibly no centaurs configured. ");
            } // DIMM
        } // MBA
    } // if

    FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_MSS_FREQ_OVERRIDE, i_target_memb,  l_freq_override));

    if ( l_freq_override != 0)
    {
        // The relationship is as such
        // l_dimm_freq_min = 2000000 / l_spd_min_tck_max

        if (l_freq_override == 1866)
        {
            l_dimm_freq_min = 1866;
            l_spd_min_tck_max = 1072;
        }

        if (l_freq_override == 1600)
        {
            l_dimm_freq_min = 1600;
            l_spd_min_tck_max = 1250;
        }

        if (l_freq_override == 1333)
        {
            l_dimm_freq_min = 1333;
            l_spd_min_tck_max = 1500;
        }

        if (l_freq_override == 1066)
        {
            l_dimm_freq_min = 1066;
            l_spd_min_tck_max = 1875;
        }

        FAPI_INF( "Override Frequency Detected: %d", l_dimm_freq_min);
    }

    //If no common supported CL get rid of the minority DIMMs
    FAPI_INF("l_spd_cas_lat_supported_all: %x", l_spd_cas_lat_supported_all);

    if ((l_spd_cas_lat_supported_all == 0))
    {
        FAPI_INF("l_spd_cas_lat_supported_all: %x", l_spd_cas_lat_supported_all);

        for(uint8_t i = 0; i < 20; i++)
        {
            if (l_cl_count_array[i] > l_highest_cl_count)
            {
                l_highest_common_cl = i;
            }
        }

        // Loop through the 2 MBA's
        for (const auto& l_mba : l_mbaChiplets)
        {
            // Get a vector of DIMM targets
            const auto l_dimm_targets = l_mba.getChildren<fapi2::TARGET_TYPE_DIMM>();

            for (const auto& l_dimm : l_dimm_targets)
            {
                FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_SPD_CAS_LATENCIES_SUPPORTED, l_dimm,  l_spd_cas_lat_supported));

                FAPI_ASSERT_NOEXIT(l_spd_cas_lat_supported & 0x0000001 << l_highest_common_cl,
                                   fapi2::CEN_MSS_NO_COMMON_SUPPORTED_CL().
                                   set_DIMM_TARGET(l_dimm).
                                   set_CL_SUPPORTED(l_spd_cas_lat_supported),
                                   "No common supported CAS latencies between DIMMS.");
            } // DIMM
        } // MBA
    }//if

    //Determine a proposed CAS latency
    l_cas_latency = l_spd_min_taa_max / l_spd_min_tck_max;

    FAPI_INF( "CL = TAA / TCK ... TAA(ps): %d TCK(ps): %d", l_spd_min_taa_max, l_spd_min_tck_max);
    FAPI_INF( "Calculated CL: %d", l_cas_latency);

    if ( l_spd_min_taa_max % l_spd_min_tck_max)
    {
        l_cas_latency++;
        FAPI_INF( "After rounding up ... CL: %d", l_cas_latency);
    }

    l_cl_mult_tck = l_cas_latency * l_spd_min_tck_max;


    l_cl_support_offset = (l_spd_dram_dev_type == fapi2::ENUM_ATTR_CEN_SPD_DRAM_DEVICE_TYPE_DDR3) ?
                          DDR3_CL_SUPPORT_OFFSET : DDR4_CL_SUPPORT_OFFSET;

    if(l_spd_dram_dev_type == fapi2::ENUM_ATTR_CEN_SPD_DRAM_DEVICE_TYPE_DDR4)
    {
        if((l_spd_sdram_dev_type == fapi2::ENUM_ATTR_CEN_SPD_SDRAM_DEVICE_TYPE_NON_STANDARD)
           && (l_spd_sdram_dev_type_sig_loading == fapi2::ENUM_ATTR_CEN_SPD_SDRAM_DEVICE_TYPE_SIGNAL_LOADING_SINGLE_LOAD_STACK))
        {
            l_taa_max = DDR4_3DS_TAA_MAX;
        }
        else
        {
            l_taa_max = DDR4_TAA_MAX;
        }
    }
    else
    {
        l_taa_max = DDR3_TAA_MAX;
    }

    FAPI_INF("taa_max = %d", l_taa_max);

    // If the CL proposed is not supported or the TAA exceeds TAA max
    // Spec defines tAAmax as 20 ns for all DDR3 speed grades.
    // Break loop if we have an override condition without a solution.

    while ( ( ( mss_freq_unsupported_cl(l_spd_cas_lat_supported_all, l_cl_support_offset, l_cas_latency) )
              || (l_cl_mult_tck > l_taa_max) )
            && ( l_override_path == 0) )
    {
        FAPI_INF( "Warning calculated CL is not supported in VPD.  Searching for a new CL.");

        // If not supported, increment the CL up to 18 (highest supported CL) looking for Supported CL
        while ( ( mss_freq_unsupported_cl(l_spd_cas_lat_supported_all, l_cl_support_offset, l_cas_latency) )
                && (l_cas_latency < MAX_CL_SUPPORTED) )
        {
            l_cas_latency++;
        }

        // If still not supported CL or TAA is > 20 ns ... pick a slower TCK and start again
        l_cl_mult_tck = l_cas_latency * l_spd_min_tck_max;

        // Do not move freq if using an override freq.  Just continue.  Hence the overide in this if statement
        if ( ( ( mss_freq_unsupported_cl(l_spd_cas_lat_supported_all, l_cl_support_offset, l_cas_latency) )
               || (l_cl_mult_tck > l_taa_max) )
             && ( l_freq_override == 0) )
        {

            FAPI_INF( "No Supported CL works for calculating frequency.  Lowering frequency and trying CL Algorithm again.");

            if (l_spd_min_tck_max < 1500)
            {
                //1600 to 1333
                l_spd_min_tck_max = 1500;
            }
            else if (l_spd_min_tck_max < 1875)
            {
                //1333 to 1066
                l_spd_min_tck_max = 1875;
            }
            else if (l_spd_min_tck_max < 2500)
            {
                //1066 to 800
                l_spd_min_tck_max = 2500;
            }
            else
            {
                //This is minimum frequency and cannot be lowered
                //Therefore we will deconfig the minority dimms.
                //Any CL 20+ is unsupported speed bin for Centaur
                for(uint8_t i = 0; i < 20; i++)
                {
                    if (l_cl_count_array[i] > l_lowest_cl_count)
                    {
                        l_lowest_common_cl = i;
                    }
                }

                // Loop through the 2 MBA's
                for (const auto& l_mba : l_mbaChiplets)
                {
                    // Get a vector of DIMM targets
                    const auto l_dimm_targets = l_mba.getChildren<fapi2::TARGET_TYPE_DIMM>();

                    for (const auto& l_dimm : l_dimm_targets)
                    {
                        FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_SPD_CAS_LATENCIES_SUPPORTED, l_dimm,  l_spd_cas_lat_supported));

                        if (l_spd_cas_lat_supported & 0x0000001 << l_lowest_common_cl)
                        {
                            FAPI_ASSERT_NOEXIT(false,
                                               fapi2::CEN_MSS_EXCEED_TAA_MAX_NO_CL().
                                               set_DIMM_TARGET(l_dimm).
                                               set_CL_SUPPORTED(l_spd_cas_lat_supported),
                                               "Lowered Frequency to TCLK MIN finding no supported CL without exceeding TAA MAX.");
                        }
                    } // DIMM
                } // MBA
            } // else

            // Re-calculate with new tck
            l_cas_latency = l_spd_min_taa_max / l_spd_min_tck_max;

            if ( l_spd_min_taa_max % l_spd_min_tck_max)
            {
                l_cas_latency++;
            }

            l_cl_mult_tck = l_cas_latency * l_spd_min_tck_max;
            l_dimm_freq_min = 2000000 / l_spd_min_tck_max;

        } // if

        // Need to break the loop in case we reach this condition because no longer modify freq and CL
        // With an overrride
        if ( ( ( mss_freq_unsupported_cl(l_spd_cas_lat_supported_all, l_cl_support_offset, l_cas_latency) )
               || (l_cl_mult_tck > l_taa_max) )
             && ( l_freq_override != 0) )
        {
            FAPI_INF( "No Supported CL works for override frequency.  Using override frequency with an unsupported CL.");
            l_override_path = 1;
        }
    } // while

    //bucketize dimm freq.
    if (l_dimm_freq_min < 1013)
    {
        FAPI_ASSERT(false,
                    fapi2::CEN_MSS_UNSUPPORTED_FREQ_CALCULATED().
                    set_DIMM_MIN_FREQ(l_dimm_freq_min),
                    "Unsupported frequency:  DIMM Freq calculated < 1013 MHz");

    }
    else if (l_dimm_freq_min < 1266)
    {
        // 1066
        l_selected_dimm_freq = 1066;
    }
    else if (l_dimm_freq_min < 1520)
    {
        // 1333
        l_selected_dimm_freq = 1333;
    }
    else if (l_dimm_freq_min < 1773)
    {
        // 1600
        l_selected_dimm_freq = 1600;
    }
    else if (l_dimm_freq_min < 2026)
    {
        // 1866
        l_selected_dimm_freq = 1866;
    }
    else if (l_dimm_freq_min < 2280)
    {
        // 2133
        l_selected_dimm_freq = 2133;
    }
    else
    {
        FAPI_ASSERT(false,
                    fapi2::CEN_MSS_UNSUPPORTED_FREQ_CALCULATED().
                    set_DIMM_MIN_FREQ(l_dimm_freq_min),
                    "Unsupported frequency:  DIMM Freq calculated > 2133 MHz: %d", l_dimm_freq_min);

    }

    // 0x03 = capable of both 8.0G/9.6G, 0x01 = capable of 8.0G, 0x02 = capable 9.6G
    if ( l_selected_dimm_freq == 1066)
    {
        l_nest_capable_frequencies = 0x01;
        FAPI_TRY(FAPI_ATTR_SET(fapi2::ATTR_CEN_MSS_NEST_CAPABLE_FREQUENCIES, i_target_memb,  l_nest_capable_frequencies));
    }
    else
    {
        l_nest_capable_frequencies = 0x03;
        FAPI_TRY(FAPI_ATTR_SET(fapi2::ATTR_CEN_MSS_NEST_CAPABLE_FREQUENCIES, i_target_memb,  l_nest_capable_frequencies));
    }

    // set frequency in centaur attribute ATTR_MSS_FREQ
    FAPI_TRY(FAPI_ATTR_SET(fapi2::ATTR_CEN_MSS_FREQ, i_target_memb,  l_selected_dimm_freq));
    FAPI_INF( "Final Chosen Frequency: %d ",  l_selected_dimm_freq);
    FAPI_INF( "Final Chosen CL: %d ",  l_cas_latency);

    for (uint32_t k = 0; k < l_mbaChiplets.size(); k++)
    {
        FAPI_TRY(FAPI_ATTR_SET(fapi2::ATTR_CEN_EFF_DRAM_CL, l_mbaChiplets[k],  l_cas_latency));
    }

fapi_try_exit:
    return fapi2::current_err;
}

OpenPOWER on IntegriCloud