summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/hwp/dram_training/mss_draminit_trainadv/mss_ddr4_pda.C
blob: 9dd69c7730b70d795868b45c0b9fa0fcf61d4df5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hwpf/hwp/dram_training/mss_draminit_trainadv/mss_ddr4_pda.C $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015                             */
/* [+] 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                                                     */
// $Id: mss_ddr4_pda.C,v 1.42 2015/07/23 14:18:55 sglancy Exp $
//------------------------------------------------------------------------------
// *! (C) Copyright International Business Machines Corp. 2013
// *! All Rights Reserved -- Property of IBM
// *! ***  ***
//------------------------------------------------------------------------------
// *! TITLE : mss_ddr4_pda.C
// *! DESCRIPTION : Tools for DDR4 DIMMs centaur procedures
// *! OWNER NAME  : Stephen Glancy       Email: sglancy@us.ibm.com
// *! BACKUP NAME : Andre Marin     Email: aamarin@us.ibm.com
// #! ADDITIONAL COMMENTS :
//

//------------------------------------------------------------------------------
// Don't forget to create CVS comments when you check in your changes!
//------------------------------------------------------------------------------
// CHANGE HISTORY:
//------------------------------------------------------------------------------
// Version:|  Author: |  Date:  | Comment:
//---------|----------|---------|-----------------------------------------------
//  1.11   | 07/23/15 | sglancy | Changed code to address FW comments
//  1.10   | 06/09/15 | sglancy | Fixed bug
//  1.9    | 05/27/15 | sglancy | Fixed bug
//  1.8    | 05/13/15 | sglancy | Added new checks, FFDC, and checked
//  1.7    | 05/11/15 | sglancy | Fixed compile errors
//  1.6    | 05/11/15 | sglancy | Updated for FW comments
//  1.5    | 05/07/15 | sglancy | Updated for FW comments
//  1.4    | 04/22/15 | sglancy | Fixed several code bugs
//  1.3    | 04/21/15 | sglancy | Added support for R and LR DIMMs as well as x8, fixed minor bug in setup and disable code
//  1.2    | 11/27/14 | sglancy | Updated to allow for file inputs and changed print statements
//  1.1    | 10/27/14 | sglancy | First revision


//----------------------------------------------------------------------
//  Includes
//----------------------------------------------------------------------
#include <fapi.H>
#include <mss_ddr4_pda.H>
#include <mss_funcs.H>
#include <cen_scom_addresses.H>
#include <mss_access_delay_reg.H>
#include <vector>
#include <algorithm>
using namespace fapi;
using namespace std;
extern "C" {

//PDA_Scom_Storage constructor
PDA_Scom_Storage::PDA_Scom_Storage(uint64_t sa, uint32_t sb, uint32_t nb) {
   scom_addr = sa;
   start_bit = sb;
   num_bits = nb;
}
PDA_Scom_Storage::~PDA_Scom_Storage() {}

//PDA_MRS_Storage class constructor
PDA_MRS_Storage::PDA_MRS_Storage(uint8_t ad,uint32_t an,uint8_t dr,uint8_t di,uint8_t r,uint8_t p) {
   attribute_data = ad;
   attribute_name = an;
   dram = dr;
   dimm = di;
   rank = r;
   port = p;
   MRS = 0xFF;
   pda_string[0] = '\0';
}

const uint8_t MRS0_BA = 0;
const uint8_t MRS1_BA = 1;
const uint8_t MRS2_BA = 2;  
const uint8_t MRS3_BA = 3;
const uint8_t MRS4_BA = 4;
const uint8_t MRS5_BA = 5;
const uint8_t MRS6_BA = 6;
const uint8_t MAX_NUM_DP18S = 5;
const uint8_t MAX_NUM_PORTS = 2;
const uint8_t MAX_NUM_DIMMS = 2;
const uint8_t PORT_SIZE = 2;

//generates the string
void PDA_MRS_Storage::generatePDAString() {
   snprintf(pda_string,MAX_ECMD_STRING_LEN,"ATTR_NAME 0x%08x ATTR_DATA 0x%02x MRS %d P %d DI %d R %d DR %d",attribute_name,attribute_data,MRS,port,dimm,rank,dram);
}

//sends out the string
char * PDA_MRS_Storage::c_str() {
   //generate new string
   generatePDAString(); //note using a separate function here in case some other function would need to call the generation of the string
   return pda_string;
}

//Checks to make sure that 
ReturnCode PDA_MRS_Storage::checkPDAValid(Target& i_target) {
   ReturnCode rc;
   
   //checks constants first
   //ports out of range
   if(port >= MAX_NUM_PORTS) {
      const uint32_t PORT_VALUE = port;
      const uint32_t DIMM_VALUE = dimm;
      const uint32_t RANK_VALUE = rank;
      const uint32_t DRAM_VALUE = dram;
      const fapi::Target & MBA_TARGET = i_target; 
      FAPI_SET_HWP_ERROR(rc, RC_MSS_PDA_DRAM_DNE);
      FAPI_ERR("ERROR!! Port out of valid range! Exiting...");
      return rc;
   }
   
   //DIMMs out of range
   if(dimm >= MAX_NUM_DIMMS) {
      const uint32_t PORT_VALUE = port;
      const uint32_t DIMM_VALUE = dimm;
      const uint32_t RANK_VALUE = rank;
      const uint32_t DRAM_VALUE = dram;
      const fapi::Target & MBA_TARGET = i_target; 
      FAPI_SET_HWP_ERROR(rc, RC_MSS_PDA_DRAM_DNE);
      FAPI_ERR("ERROR!! DIMM out of valid range! Exiting...");
      return rc;
   }
   
   //now checks based upon attributes
   uint8_t num_ranks[2][2];
   rc = FAPI_ATTR_GET(ATTR_EFF_NUM_RANKS_PER_DIMM,&i_target,num_ranks); 
   if(rc) return rc;
   
   //no ranks on the selected dimm
   if(num_ranks[port][dimm] == 0) {
      const uint32_t PORT_VALUE = port;
      const uint32_t DIMM_VALUE = dimm;
      const uint32_t RANK_VALUE = rank;
      const uint32_t DRAM_VALUE = dram;
      const fapi::Target & MBA_TARGET = i_target; 
      FAPI_SET_HWP_ERROR(rc, RC_MSS_PDA_DRAM_DNE);
      FAPI_ERR("ERROR!! DIMM has no valid ranks! Exiting...");
      return rc;
   }
   
   //rank is out of range
   if(num_ranks[port][dimm] <= rank) {
      const uint32_t PORT_VALUE = port;
      const uint32_t DIMM_VALUE = dimm;
      const uint32_t RANK_VALUE = rank;
      const uint32_t DRAM_VALUE = dram;
      const fapi::Target & MBA_TARGET = i_target; 
      FAPI_SET_HWP_ERROR(rc, RC_MSS_PDA_DRAM_DNE);
      FAPI_ERR("ERROR!! Rank is out of bounds! Exiting...");
      return rc;
   }
   
   uint8_t num_spares[2][2][4];
   rc = FAPI_ATTR_GET(ATTR_VPD_DIMM_SPARE,&i_target,num_spares); 
   if(rc) return rc;
   
   uint8_t dram_width;
   rc = FAPI_ATTR_GET(ATTR_EFF_DRAM_WIDTH,&i_target,dram_width); 
   if(rc) return rc;
   
   uint8_t num_spare = 0;
   if(num_spares[port][dimm][rank] == ENUM_ATTR_VPD_DIMM_SPARE_LOW_NIBBLE) {
      num_spare = 1;
   }
   if(num_spares[port][dimm][rank] == ENUM_ATTR_VPD_DIMM_SPARE_HIGH_NIBBLE) {
      num_spare = 1;
   }
   if(num_spares[port][dimm][rank] == ENUM_ATTR_VPD_DIMM_SPARE_FULL_BYTE && dram_width == ENUM_ATTR_EFF_DRAM_WIDTH_X4) {
      num_spare = 2;
   }
   if(num_spares[port][dimm][rank] == ENUM_ATTR_VPD_DIMM_SPARE_FULL_BYTE && dram_width == ENUM_ATTR_EFF_DRAM_WIDTH_X8) {
      num_spare = 1;
   }
   
   uint8_t num_dram = 72/dram_width + num_spare;
   if(num_dram <= dram) {
      const uint32_t PORT_VALUE = port;
      const uint32_t DIMM_VALUE = dimm;
      const uint32_t RANK_VALUE = rank;
      const uint32_t DRAM_VALUE = dram;
      const fapi::Target & MBA_TARGET = i_target; 
      FAPI_SET_HWP_ERROR(rc, RC_MSS_PDA_DRAM_DNE);
      FAPI_ERR("ERROR!! DRAM is out of bounds! Exiting...");
      return rc;
   }
   
   return rc;
}

//sets the MRS variable based upon the inputted attribute name
ReturnCode PDA_MRS_Storage::setMRSbyAttr(Target& i_target) {
   fapi::ReturnCode rc;
   switch(attribute_name) {
   
   //MRS0
      case ATTR_EFF_DRAM_BL: MRS = MRS0_BA; break;
      case ATTR_EFF_DRAM_RBT: MRS = MRS0_BA; break;
      case ATTR_EFF_DRAM_CL: MRS = MRS0_BA; break;
      case ATTR_EFF_DRAM_TM: MRS = MRS0_BA; break;
      case ATTR_EFF_DRAM_DLL_RESET: MRS = MRS0_BA; break;
      case ATTR_EFF_DRAM_WR: MRS = MRS0_BA; break;
      case ATTR_EFF_DRAM_TRTP: MRS = MRS0_BA; break;
      case ATTR_EFF_DRAM_DLL_PPD: MRS = MRS0_BA; break;

   //MRS1
      case ATTR_EFF_DRAM_DLL_ENABLE: MRS = MRS1_BA; break;
      case ATTR_VPD_DRAM_RON: MRS = MRS1_BA; break;
      case ATTR_VPD_DRAM_RTT_NOM: MRS = MRS1_BA; break;
      case ATTR_EFF_DRAM_AL: MRS = MRS1_BA; break;
      case ATTR_EFF_DRAM_WR_LVL_ENABLE: MRS = MRS1_BA; break;
      case ATTR_EFF_DRAM_TDQS: MRS = MRS1_BA; break;
      case ATTR_EFF_DRAM_OUTPUT_BUFFER: MRS = MRS1_BA; break;
   
   //MRS2
      case ATTR_EFF_DRAM_LPASR: MRS = MRS2_BA; break;
      case ATTR_EFF_DRAM_CWL: MRS = MRS2_BA; break;
      case ATTR_VPD_DRAM_RTT_WR: MRS = MRS2_BA; break;
      case ATTR_EFF_WRITE_CRC: MRS = MRS2_BA; break;

   //MRS3
      case ATTR_EFF_MPR_MODE: MRS = MRS3_BA; break;
      case ATTR_EFF_MPR_PAGE: MRS = MRS3_BA; break;
      case ATTR_EFF_GEARDOWN_MODE: MRS = MRS3_BA; break;
      case ATTR_EFF_PER_DRAM_ACCESS: MRS = MRS3_BA; break;
      case ATTR_EFF_TEMP_READOUT: MRS = MRS3_BA; break;
      case ATTR_EFF_FINE_REFRESH_MODE: MRS = MRS3_BA; break;
      case ATTR_EFF_CRC_WR_LATENCY: MRS = MRS3_BA; break;
      case ATTR_EFF_MPR_RD_FORMAT: MRS = MRS3_BA; break;

   //MRS4
      case ATTR_EFF_MAX_POWERDOWN_MODE: MRS = MRS4_BA; break;
      case ATTR_EFF_TEMP_REF_RANGE: MRS = MRS4_BA; break;
      case ATTR_EFF_TEMP_REF_MODE: MRS = MRS4_BA; break;
      case ATTR_EFF_INT_VREF_MON: MRS = MRS4_BA; break;
      case ATTR_EFF_CS_CMD_LATENCY: MRS = MRS4_BA; break;
      case ATTR_EFF_SELF_REF_ABORT: MRS = MRS4_BA; break;
      case ATTR_EFF_RD_PREAMBLE_TRAIN: MRS = MRS4_BA; break;
      case ATTR_EFF_RD_PREAMBLE: MRS = MRS4_BA; break;
      case ATTR_EFF_WR_PREAMBLE: MRS = MRS4_BA; break;


   //MRS5
      case ATTR_EFF_CA_PARITY_LATENCY : MRS = MRS5_BA; break;
      case ATTR_EFF_CRC_ERROR_CLEAR : MRS = MRS5_BA; break;
      case ATTR_EFF_CA_PARITY_ERROR_STATUS : MRS = MRS5_BA; break;
      case ATTR_EFF_ODT_INPUT_BUFF : MRS = MRS5_BA; break;
      case ATTR_EFF_RTT_PARK : MRS = MRS5_BA; break;
      case ATTR_EFF_CA_PARITY : MRS = MRS5_BA; break;
      case ATTR_EFF_DATA_MASK : MRS = MRS5_BA; break;
      case ATTR_EFF_WRITE_DBI : MRS = MRS5_BA; break;
      case ATTR_EFF_READ_DBI : MRS = MRS5_BA; break;

   //MRS6
      case ATTR_VREF_DQ_TRAIN_VALUE: MRS = MRS6_BA; break;
      case ATTR_VREF_DQ_TRAIN_RANGE: MRS = MRS6_BA; break;
      case ATTR_VREF_DQ_TRAIN_ENABLE: MRS = MRS6_BA; break;
      case ATTR_TCCD_L: MRS = MRS6_BA; break;
      
      //MRS attribute not found, error out
      default: 
         const uint32_t NONMRS_ATTR_NAME = attribute_name;
	 const fapi::Target & MBA_TARGET = i_target; 
	 FAPI_SET_HWP_ERROR(rc, RC_MSS_PDA_NONMRS_ATTR_NAME);
	 FAPI_ERR("ERROR!! Found attribute name not associated with an MRS! Exiting...");
   }
   return rc;
}//end setMRSbyAttr
  
//PDA_MRS_Storage class destructor
PDA_MRS_Storage::~PDA_MRS_Storage() {}

bool PDA_MRS_Storage::operator> (const PDA_MRS_Storage &PDA2) const {
   //check on the DRAM first
   //DRAM for A is greater than B return true
   if(dram > PDA2.dram) return true;
   //B > A -> false
   else if(dram < PDA2.dram) return false;
   //B == A, so go to port
   //A > B -> true
   else if(port > PDA2.port) return true;
   //A < B -> false
   else if(port < PDA2.port) return false;
   //ports are equal, so start comparing dimms
   //A > B -> true
   else if(dimm > PDA2.dimm) return true;
   //A < B -> false
   else if(dimm < PDA2.dimm) return false;
   //dimms are equal, so start comparing ranks
   //A > B -> true
   else if(rank > PDA2.rank) return true;
   //A < B -> false
   else if(rank < PDA2.rank) return false;
   //ports are equal, so start comparing the MRS number
   //A > B -> true
   else if(MRS > PDA2.MRS) return true;
   //A < B -> false
   else if(MRS < PDA2.MRS) return false;
   //ports are equal, so start comparing the attribute_name
   //A > B -> true
   else if(attribute_name > PDA2.attribute_name) return true;
   //A < B -> false
   else if(attribute_name < PDA2.attribute_name) return false;
   //ports are equal, so start comparing the attribute_data
   //A > B -> true
   else if(attribute_data > PDA2.attribute_data) return true;
   //equal or less than
   return false;
}//end operator>

bool PDA_MRS_Storage::operator< (const PDA_MRS_Storage &PDA2) const {
//check on the DRAM first
   //DRAM for A is less than B return true
   if(dram < PDA2.dram) return true;
   //B < A -> false
   else if(dram > PDA2.dram) return false;
   //B == A, so go to port
   //A < B -> true
   else if(port < PDA2.port) return true;
   //A > B -> false
   else if(port > PDA2.port) return false;
   //ports are equal, so start comparing dimms
   //A < B -> true
   else if(dimm < PDA2.dimm) return true;
   //A > B -> false
   else if(dimm > PDA2.dimm) return false;
   //dimms are equal, so start comparing ranks
   //A < B -> true
   else if(rank < PDA2.rank) return true;
   //A > B -> false
   else if(rank > PDA2.rank) return false;
   //ports are equal, so start comparing the MRS number
   //A < B -> true
   else if(MRS < PDA2.MRS) return true;
   //A > B -> false
   else if(MRS > PDA2.MRS) return false;
   //ports are equal, so start comparing the attribute_name
   //A < B -> true
   else if(attribute_name < PDA2.attribute_name) return true;
   //A > B -> false
   else if(attribute_name > PDA2.attribute_name) return false;
   //ports are equal, so start comparing the attribute_data
   //A < B -> true
   else if(attribute_data < PDA2.attribute_data) return true;
   //equal or greater than
   return false;
}//end operator<


/////////////////////////////////////////////////////////////////////////////////
/// PDA_MRS_Storage::copy
/// copies one PDA_MRS_Storage to this one
/////////////////////////////////////////////////////////////////////////////////
void PDA_MRS_Storage::copy(PDA_MRS_Storage &temp) {
   attribute_data = temp.attribute_data;
   attribute_name = temp.attribute_name;
   MRS            = temp.MRS	       ;
   dram           = temp.dram	       ;
   dimm           = temp.dimm	       ;
   rank           = temp.rank	       ;
   port           = temp.port	       ;
}

/////////////////////////////////////////////////////////////////////////////////
/// mss_ddr4_checksort_pda
/// sorts the vector of PDA_MRS_Storage, so the commands will be run in a more efficient order
/////////////////////////////////////////////////////////////////////////////////
ReturnCode mss_ddr4_checksort_pda(Target& i_target, vector<PDA_MRS_Storage>& pda) {
   ReturnCode rc;
   
   //does the check to make sure all given attributes are associated with an MRS 
   for(uint32_t i=0;i<pda.size();i++) {
      rc = pda[i].setMRSbyAttr(i_target);
      if(rc) return rc;
      rc = pda[i].checkPDAValid(i_target);
      if(rc) return rc;
   }
   
   //does the sort, sorting by the class comparator (should be DRAM first)
   sort(pda.begin(),pda.end());
   
   return rc;
}


/////////////////////////////////////////////////////////////////////////////////
/// mss_ddr4_setup_pda
/// sets up per-DRAM addressability funcitonality on both ports on the passed MBA
/////////////////////////////////////////////////////////////////////////////////
ReturnCode mss_ddr4_setup_pda(
            Target& i_target,
            uint32_t& io_ccs_inst_cnt
            )
{
    uint32_t i_port_number=0;
    uint32_t dimm_number;
    uint32_t rank_number;
    const uint32_t NUM_POLL = 10;
    const uint32_t WAIT_TIMER = 1500;
    ReturnCode rc;  
    ReturnCode rc_buff;
    uint32_t rc_num = 0;
    uint64_t reg_address;
    ecmdDataBufferBase data_buffer(64);
    ecmdDataBufferBase address_16(16);
    ecmdDataBufferBase bank_3(3);
    ecmdDataBufferBase activate_1(1);
    rc_num = rc_num | activate_1.setBit(0);
    ecmdDataBufferBase rasn_1(1);
    ecmdDataBufferBase casn_1(1);
    ecmdDataBufferBase wen_1(1);
    ecmdDataBufferBase cke_4(4);
    rc_num = rc_num | cke_4.setBit(0,4);
    ecmdDataBufferBase csn_8(8);
    rc_num = rc_num | csn_8.setBit(0,8);
    ecmdDataBufferBase odt_4(4);
    ecmdDataBufferBase ddr_cal_type_4(4);

    ecmdDataBufferBase num_idles_16(16);
    ecmdDataBufferBase num_repeat_16(16);
    ecmdDataBufferBase data_20(20);
    ecmdDataBufferBase read_compare_1(1);
    ecmdDataBufferBase rank_cal_4(4);
    ecmdDataBufferBase ddr_cal_enable_1(1);
    ecmdDataBufferBase ccs_end_1(1);

    ecmdDataBufferBase mrs3(16);
    uint16_t MRS3 = 0;
    
    uint8_t num_ranks_array[2][2]; //[port][dimm]
    
    uint8_t dimm_type;
    rc = FAPI_ATTR_GET(ATTR_EFF_DIMM_TYPE, &i_target, dimm_type);
    if(rc) return rc;
    
    uint8_t num_ranks;
    rc = FAPI_ATTR_GET(ATTR_EFF_NUM_RANKS_PER_DIMM, &i_target, num_ranks_array);
    if(rc) return rc;

    uint8_t is_sim = 0;
    rc = FAPI_ATTR_GET(ATTR_IS_SIMULATION, NULL, is_sim);
    if(rc) return rc;

    uint8_t address_mirror_map[2][2]; //address_mirror_map[port][dimm]
    rc = FAPI_ATTR_GET(ATTR_VPD_DRAM_ADDRESS_MIRRORING, &i_target, address_mirror_map);
    if(rc) return rc;

    // WORKAROUNDS 
    rc = fapiGetScom(i_target, CCS_MODEQ_AB_REG_0x030106A7, data_buffer);
    if(rc) return rc;
    //Setting up CCS mode
    rc_num = rc_num | data_buffer.setBit(51);
    
    if (rc_num)
    {
    	FAPI_ERR( "mss_ddr4_setup_pda: Error setting up buffers");
    	rc_buff.setEcmdError(rc_num);
    	return rc_buff;
    }
    
    rc = fapiPutScom(i_target, CCS_MODEQ_AB_REG_0x030106A7, data_buffer);
    if(rc) return rc;
    
    //loops through port 0 and port 1 on the given MBA
    for(i_port_number=0;i_port_number<MAX_NUM_PORTS;i_port_number++) {
       // Raise CKE high with NOPS, waiting min Reset CKE exit time (tXPR) - 400 cycles
       rc_num = rc_num | cke_4.setBit(0,4);
       rc_num = rc_num | csn_8.setBit(0,8);
       rc_num = rc_num | address_16.clearBit(0, 16);
       rc_num = rc_num | odt_4.clearBit(0,4);
       rc_num = rc_num | num_idles_16.insertFromRight((uint32_t) 400, 0, 16);
       if (rc_num)
       {
    	    FAPI_ERR( "mss_ddr4_setup_pda: Error setting up buffers");
    	    rc_buff.setEcmdError(rc_num);
    	    return rc_buff;
       }
       
       rc = mss_ccs_inst_arry_0( i_target,
    				 io_ccs_inst_cnt,
    				 address_16,
    				 bank_3,
    				 activate_1,
    				 rasn_1,
    				 casn_1,
    				 wen_1,
    				 cke_4,
    				 csn_8,
    				 odt_4,
    				 ddr_cal_type_4,
    				 i_port_number);	
       if(rc) return rc;
       rc = mss_ccs_inst_arry_1( i_target,
    				 io_ccs_inst_cnt,
    				 num_idles_16,
    				 num_repeat_16,
    				 data_20,
    				 read_compare_1,
    				 rank_cal_4,
    				 ddr_cal_enable_1,
    				 ccs_end_1);  
       if(rc) return rc;
       io_ccs_inst_cnt ++;
    }
    
    
    //Sets up MRS3 -> the MRS that has PDA
    uint8_t mpr_op; // MPR Op
    rc = FAPI_ATTR_GET(ATTR_EFF_MPR_MODE, &i_target, mpr_op);
    if(rc) return rc;
    uint8_t mpr_page; // MPR Page Selection  - NEW
    rc = FAPI_ATTR_GET(ATTR_EFF_MPR_PAGE, &i_target, mpr_page);
    if(rc) return rc;
    uint8_t geardown_mode; // Gear Down Mode  - NEW
    rc = FAPI_ATTR_GET(ATTR_EFF_GEARDOWN_MODE, &i_target, geardown_mode);
    if(rc) return rc;
    uint8_t temp_readout; // Temperature sensor readout  - NEW
    rc = FAPI_ATTR_GET(ATTR_EFF_TEMP_READOUT, &i_target, temp_readout);
    if(rc) return rc;
    uint8_t fine_refresh; // fine refresh mode  - NEW
    rc = FAPI_ATTR_GET(ATTR_EFF_FINE_REFRESH_MODE, &i_target, fine_refresh);
    if(rc) return rc;
    uint8_t wr_latency; // write latency for CRC and DM  - NEW
    rc = FAPI_ATTR_GET(ATTR_EFF_CRC_WR_LATENCY, &i_target, wr_latency);
    if(rc) return rc;
    uint8_t read_format; // MPR READ FORMAT  - NEW
    rc = FAPI_ATTR_GET(ATTR_EFF_MPR_RD_FORMAT, &i_target, read_format);
    if(rc) return rc;

    //enables PDA mode
    //loops through all ports
    for(i_port_number=0;i_port_number<MAX_NUM_PORTS;i_port_number++) {
    	// Dimm 0-1
    	for ( dimm_number = 0; dimm_number < MAX_NUM_DIMMS; dimm_number++)
    	{
    	    num_ranks = num_ranks_array[i_port_number][dimm_number];

    	    if (num_ranks == 0)
    	    {
    		FAPI_INF( "PORT%d DIMM%d not configured. Num_ranks: %d ", i_port_number, dimm_number, num_ranks);
    	    }
    	    else
    	    {
    		// Rank 0-3
    		for ( rank_number = 0; rank_number < num_ranks; rank_number++)
    		{
    		   // Only corresponding CS to rank
    		   rc_num = rc_num | csn_8.setBit(0,8); 
    		   rc_num = rc_num | csn_8.clearBit(rank_number+4*dimm_number);
    			
    		   rc_num = rc_num | bank_3.insert((uint8_t) MRS3_BA, 0, 1, 7);
    		   rc_num = rc_num | bank_3.insert((uint8_t) MRS3_BA, 1, 1, 6);
    		   rc_num = rc_num | bank_3.insert((uint8_t) MRS3_BA, 2, 1, 5);
    		   
		   //sets up MRS3 ecmd buffer
	           rc_num = rc_num | mrs3.insert((uint8_t) mpr_page, 0, 2);
	           rc_num = rc_num | mrs3.insert((uint8_t) mpr_op, 2, 1);
	           rc_num = rc_num | mrs3.insert((uint8_t) geardown_mode, 3, 1);
	           rc_num = rc_num | mrs3.insert((uint8_t) 0xff, 4, 1); //enables PDA mode!!!!
	           rc_num = rc_num | mrs3.insert((uint8_t) temp_readout, 5, 1);
	           rc_num = rc_num | mrs3.insert((uint8_t) fine_refresh, 6, 3);
	           rc_num = rc_num | mrs3.insert((uint8_t) wr_latency, 9, 2);
	           rc_num = rc_num | mrs3.insert((uint8_t) read_format, 11, 2);
	           rc_num = rc_num | mrs3.insert((uint8_t) 0x00, 13, 2);
	           rc_num = rc_num | mrs3.extractPreserve(&MRS3, 0, 16, 0);
	           rc_num = rc_num | num_idles_16.insertFromRight((uint32_t) 24, 0, 16);
		   rc_num = rc_num | address_16.insert(mrs3, 0, 16, 0);
		   
    		   if (rc_num)
    		   {
    		       FAPI_ERR( "mss_ddr4_setup_pda: Error setting up buffers");
    		       rc_buff.setEcmdError(rc_num);
    		       return rc_buff;
    		   }
    		   
	           
    		   if (( address_mirror_map[i_port_number][dimm_number] & (0x08 >> rank_number) ) && (is_sim == 0))
    		   {
    		      rc = mss_address_mirror_swizzle(i_target, i_port_number, dimm_number, rank_number, address_16, bank_3);
    		      if(rc) return rc;
    		   }
    		   
    		   
    		   // Send out to the CCS array 
    		   rc = mss_ccs_inst_arry_0( i_target,
    				     io_ccs_inst_cnt,
    				     address_16,
    				     bank_3,
    				     activate_1,
    				     rasn_1,
    				     casn_1,
    				     wen_1,
    				     cke_4,
    				     csn_8,
    				     odt_4,
    				     ddr_cal_type_4,
    				     i_port_number);
    		   if(rc) return rc;
    		   rc = mss_ccs_inst_arry_1( i_target,
    				     io_ccs_inst_cnt,
    				     num_idles_16,
    				     num_repeat_16,
    				     data_20,
    				     read_compare_1,
    				     rank_cal_4,
    				     ddr_cal_enable_1,
    				     ccs_end_1);
    		   if(rc) return rc;
    		   io_ccs_inst_cnt ++;
		   
		   //if the DIMM is an R or LR DIMM, then run inverted for the B-Side DRAM
                    if ( (dimm_type == ENUM_ATTR_EFF_DIMM_TYPE_RDIMM) || (dimm_type == ENUM_ATTR_EFF_DIMM_TYPE_LRDIMM) ) 
                    {
		       //reload all MRS values (removes address swizzling)
		       // Only corresponding CS to rank
    		       rc_num = rc_num | csn_8.setBit(0,8); 
    		       rc_num = rc_num | csn_8.clearBit(rank_number+4*dimm_number);
    		    	    
    		       rc_num = rc_num | bank_3.insert((uint8_t) MRS3_BA, 0, 1, 7);
    		       rc_num = rc_num | bank_3.insert((uint8_t) MRS3_BA, 1, 1, 6);
    		       rc_num = rc_num | bank_3.insert((uint8_t) MRS3_BA, 2, 1, 5);
    		       
		       //sets up MRS3 ecmd buffer
		       rc_num = rc_num | address_16.insert(mrs3, 0, 16, 0);
		       
		       //FLIPS all necessary bits
		       // Indicate B-Side DRAMS BG1=1 
                       rc_num = rc_num | address_16.setBit(15);  // Set BG1 = 1
 
                       rc_num = rc_num | address_16.flipBit(3,7); // Invert A3:A9
                       rc_num = rc_num | address_16.flipBit(11);  // Invert A11
                       rc_num = rc_num | address_16.flipBit(13);  // Invert A13
                       rc_num = rc_num | address_16.flipBit(14);  // Invert A17
                       rc_num = rc_num | bank_3.flipBit(0,3);	  // Invert BA0,BA1,BG0
		       
		       if (rc_num)
    		       {
    		     	   FAPI_ERR( "mss_ddr4_setup_pda: Error setting up buffers");
    		     	   rc_buff.setEcmdError(rc_num);
    		     	   return rc_buff;
    		       }
		     	   
		     	   if (( address_mirror_map[i_port_number][dimm_number] & (0x08 >> rank_number) ) && (is_sim == 0))
    		       {
    		     	  rc = mss_address_mirror_swizzle(i_target, i_port_number, dimm_number, rank_number, address_16, bank_3);
    		     	  if(rc) return rc;
    		       }
    		       
    		       // Send out to the CCS array 
    		       rc = mss_ccs_inst_arry_0( i_target,
    		     	 		 io_ccs_inst_cnt,
    		     	 		 address_16,
    		     	 		 bank_3,
    		     	 		 activate_1,
    		     	 		 rasn_1,
    		     	 		 casn_1,
    		     	 		 wen_1,
    		     	 		 cke_4,
    		     	 		 csn_8,
    		     	 		 odt_4,
    		     	 		 ddr_cal_type_4,
    		     	 		 i_port_number);
    		       if(rc) return rc;
    		       rc = mss_ccs_inst_arry_1( i_target,
    		     	 		 io_ccs_inst_cnt,
    		     	 		 num_idles_16,
    		     	 		 num_repeat_16,
    		     	 		 data_20,
    		     	 		 read_compare_1,
    		     	 		 rank_cal_4,
    		     	 		 ddr_cal_enable_1,
    		     	 		 ccs_end_1);
    		       if(rc) return rc;
    		       io_ccs_inst_cnt ++;
		    }
    		}    
    	    }
    	}
    }
    
    //runs a NOP command for 24 cycle
    rc_num = rc_num | num_idles_16.insertFromRight((uint32_t) 24, 0, 16);
    // Raise CKE high with NOPS, waiting min Reset CKE exit time (tXPR) - 400 cycles
    rc_num = rc_num | cke_4.setBit(0,4);
    rc_num = rc_num | csn_8.setBit(0,8);
    rc_num = rc_num | address_16.clearBit(0, 16);
    rc_num = rc_num | odt_4.clearBit(0,4);
    rc_num = rc_num | num_idles_16.clearBit(0,16);
    rc_num = rc_num | num_idles_16.insertFromRight((uint32_t) 24, 0, 16);
    rc_num = rc_num | rasn_1.setBit(0,1);
    rc_num = rc_num | casn_1.setBit(0,1);
    rc_num = rc_num | wen_1.setBit(0,1);
    
    if (rc_num)
    {
    	FAPI_ERR( "mss_ddr4_setup_pda: Error setting up buffers");
    	rc_buff.setEcmdError(rc_num);
    	return rc_buff;
    }
    
    rc = mss_ccs_inst_arry_0( i_target,
                              io_ccs_inst_cnt,
                              address_16,
                              bank_3,
                              activate_1,
                              rasn_1,
                              casn_1,
                              wen_1,
                              cke_4,
                              csn_8,
                              odt_4,
                              ddr_cal_type_4,
                              i_port_number);	     
    if(rc) return rc;
    rc = mss_ccs_inst_arry_1( i_target,
                              io_ccs_inst_cnt,
                              num_idles_16,
                              num_repeat_16,
                              data_20,
                              read_compare_1,
                              rank_cal_4,
                              ddr_cal_enable_1,
                              ccs_end_1);  
    
    //Setup end bit for CCS
    rc = mss_ccs_set_end_bit (i_target, io_ccs_inst_cnt);
    if (rc) return rc;
    
    //Enable CCS and set RAS/CAS/WE high during idles
   FAPI_INF("Enabling CCS\n");
   reg_address = CCS_MODEQ_AB_REG_0x030106A7;
   rc = fapiGetScom(i_target, reg_address, data_buffer);
   if(rc) return rc;

   rc_num |= data_buffer.setBit(29);    //Enable CCS
   rc_num |= data_buffer.setBit(52);    //RAS high
   rc_num |= data_buffer.setBit(53);    //CAS high
   rc_num |= data_buffer.setBit(54);    //WE high
   if (rc_num) {
      FAPI_ERR( "enable ccs setup: Error setting up buffers");
      rc.setEcmdError(rc_num);
      return rc;
   }
   rc = fapiPutScom(i_target, reg_address, data_buffer);
   if(rc) return rc;


   //Execute the CCS array
   FAPI_INF("Executing the CCS array\n");
   rc = mss_execute_ccs_inst_array (i_target, NUM_POLL, WAIT_TIMER);
   io_ccs_inst_cnt=0;
   
   //exits PDA
   //loops through the DP18's and sets everything to 1's - no PDA
   for(i_port_number=0;i_port_number<MAX_NUM_PORTS;i_port_number++) {
      for(uint8_t dp18 = 0; dp18<MAX_NUM_DP18S;dp18++) {
   	 reg_address = 0x800000010301143full + 0x0001000000000000ull*i_port_number+ 0x0000040000000000ull*(dp18);
   	 rc = fapiGetScom(i_target, reg_address, data_buffer);
   	 if(rc) return rc;

   	 rc_num |= data_buffer.setBit(60,4);	//Enable CCS
   	 if (rc_num) {
   	    FAPI_ERR( "enable ccs setup: Error setting up buffers");
   	    rc.setEcmdError(rc_num);
   	    return rc;
   	 }
   	 rc = fapiPutScom(i_target, reg_address, data_buffer);
   	 if(rc) return rc;
      }
   }
   
   rc = fapiGetScom(i_target,  DPHY01_DDRPHY_WC_CONFIG3_P0_0x8000CC050301143F, data_buffer);
   if(rc) return rc;
   //Setting up CCS mode
   rc_num = rc_num | data_buffer.setBit(48);
   if (rc_num)
   {
       FAPI_ERR( "mss_ddr4_setup_pda: Error setting up buffers");
       rc_buff.setEcmdError(rc_num);
       return rc_buff;
   }
   rc = fapiPutScom(i_target,  DPHY01_DDRPHY_WC_CONFIG3_P0_0x8000CC050301143F, data_buffer);	
   if(rc) return rc;
   
   rc = fapiGetScom(i_target,  DPHY01_DDRPHY_WC_CONFIG3_P1_0x8001CC050301143F, data_buffer);
   if(rc) return rc;
   //Setting up CCS mode
   rc_num = rc_num | data_buffer.setBit(48);
   if (rc_num)
   {
       FAPI_ERR( "mss_ddr4_setup_pda: Error setting up buffers");
       rc_buff.setEcmdError(rc_num);
       return rc_buff;
   }
   rc = fapiPutScom(i_target,  DPHY01_DDRPHY_WC_CONFIG3_P1_0x8001CC050301143F, data_buffer);	
   if(rc) return rc;
   
   return rc;
}// end mss_ddr4_setup_pda


/////////////////////////////////////////////////////////////////////////////////
/// mss_ddr4_pda
/// configures a vector of PDA accesses to run
/////////////////////////////////////////////////////////////////////////////////
ReturnCode mss_ddr4_pda(
            Target& i_target,
	    vector<PDA_MRS_Storage> pda
            )
{
    ReturnCode rc;
    uint8_t dram_loop_end;
    uint8_t dram_loop_end_with_spare;
    
    //gets the rank information
    uint8_t num_ranks_array[2][2]; //[port][dimm]
    rc = FAPI_ATTR_GET(ATTR_EFF_NUM_RANKS_PER_DIMM, &i_target, num_ranks_array);
    if(rc) return rc;
    
    //gets the spare information
    uint8_t num_spare[2][2][4]; //[port][dimm]
    rc = FAPI_ATTR_GET(ATTR_VPD_DIMM_SPARE, &i_target, num_spare);
    if(rc) return rc;
    
    //gets the WR VREF information
    uint8_t wr_vref[2][2][4]; //[port][dimm]
    rc = FAPI_ATTR_GET(ATTR_VREF_DQ_TRAIN_VALUE, &i_target, wr_vref);
    if(rc) return rc;
    
    
    uint8_t dram_width;
    rc = FAPI_ATTR_GET(ATTR_EFF_DRAM_WIDTH, &i_target, dram_width);
    if(rc) return rc;
    
    //sets the loop_end value, to ensure that the proper number of loops are conducted
    if(dram_width == 0x08) {
       dram_loop_end = 9;
    }
    //must be a x4 DRAM
    else {
       dram_loop_end = 18;
    }
    
    uint8_t array[][2][19] = {{{0x18,0x18,0x1c,0x1c,0x18,0x18,0x1c,0x1c,0x18,0x1c,0x18,0x18,0x1c,0x1c,0x1c,0x18,0x1c,0x18,0x18},{0x18,0x1c,0x20,0x1c,0x20,0x1c,0x20,0x20,0x1c,0x1c,0x20,0x1c,0x18,0x1c,0x1c,0x1c,0x1c,0x18,0x18}},{{0x18,0x1c,0x1c,0x1c,0x20,0x1c,0x20,0x18,0x18,0x18,0x1c,0x1c,0x1c,0x18,0x18,0x1c,0x18,0x18,0x1c},{0x18,0x1c,0x18,0x1c,0x20,0x1c,0x18,0x1c,0x20,0x1c,0x1c,0x1c,0x1c,0x24,0x1c,0x1c,0x1c,0x1c,0x1c}}};


    //if pda is empty then, sets up the vector for the MRS storage
    if(pda.size() == 0) {
    	//loops through each port each dimm each rank each dram and sets everything
    	for(uint8_t port = 0; port < MAX_NUM_PORTS; port++) {
    	   for(uint8_t dimm = 0; dimm < MAX_NUM_DIMMS; dimm++) {
    	      for(uint8_t rank = 0; rank < num_ranks_array[port][dimm]; rank++) {
    		 //DIMM has a spare, add one DRAM to the loop
    		 if(num_spare[port][dimm][rank]) {
    		    dram_loop_end_with_spare = dram_loop_end+1;
    		 }
    		 else {
    		    dram_loop_end_with_spare = dram_loop_end;
    		 }
    		 //loops through all dram
    		 for(uint8_t dram = 0; dram < dram_loop_end_with_spare; dram++) {
    		 //uint8_t ad,uint32_t an,uint8_t d,uint8_t r,uint8_t 
    		    if(port == 0) wr_vref[port][dimm][rank] = dram*3;
    		    else wr_vref[port][dimm][rank] = 57-dram*3;
    		    if(wr_vref[port][dimm][rank]  > 50) wr_vref[port][dimm][rank] = 50;
    		    pda.push_back(PDA_MRS_Storage(array[port][dimm][dram],ATTR_VREF_DQ_TRAIN_VALUE,dram,dimm,rank,port));
    		    FAPI_INF("PDA STRING: %d %s",pda.size()-1,pda[pda.size()-1].c_str());
    		 }
    	      }
    	   }
    	}
    }
    rc = mss_ddr4_run_pda(i_target,pda);
    return rc;
}

/////////////////////////////////////////////////////////////////////////////////
/// mss_ddr4_run_pda
/// runs per-DRAM addressability funcitonality on both ports on the passed MBA
/////////////////////////////////////////////////////////////////////////////////
ReturnCode mss_ddr4_run_pda(
            Target& i_target,
	    vector<PDA_MRS_Storage> pda
            )
{
    ReturnCode rc;  
    //no PDA was entered, just exit
    if(pda.size() == 0) return rc;
    
    uint32_t io_ccs_inst_cnt = 0;
    const uint32_t NUM_POLL = 10;
    const uint32_t WAIT_TIMER = 1500;
    ReturnCode rc_buff;
    uint32_t rc_num = 0;
    ecmdDataBufferBase data_buffer_64(64);
    ecmdDataBufferBase address_16(16);
    ecmdDataBufferBase address_16_backup(16);
    ecmdDataBufferBase bank_3(3);
    ecmdDataBufferBase activate_1(1);
    rc_num = rc_num | activate_1.setBit(0);
    ecmdDataBufferBase rasn_1(1);
    ecmdDataBufferBase casn_1(1);
    ecmdDataBufferBase wen_1(1);
    ecmdDataBufferBase cke_4(4);
    rc_num = rc_num | cke_4.setBit(0,4);
    ecmdDataBufferBase csn_8(8);
    rc_num = rc_num | csn_8.setBit(0,8);
    ecmdDataBufferBase odt_4(4);
    
    ecmdDataBufferBase ddr_cal_type_4(4);

    ecmdDataBufferBase num_idles_16(16);
    ecmdDataBufferBase num_repeat_16(16);
    ecmdDataBufferBase data_20(20);
    ecmdDataBufferBase read_compare_1(1);
    ecmdDataBufferBase rank_cal_4(4);
    ecmdDataBufferBase ddr_cal_enable_1(1);
    ecmdDataBufferBase ccs_end_1(1);
    
    //checks each MRS and saves each 
    rc = mss_ddr4_checksort_pda(i_target,pda);
    if(rc) return rc;
    
    //loads in dram type
    uint8_t dimm_type;
    rc = FAPI_ATTR_GET(ATTR_EFF_DIMM_TYPE, &i_target, dimm_type);
    if(rc) return rc;
    
    //dram density
    uint8_t dram_width;
    
    rc = FAPI_ATTR_GET(ATTR_EFF_DRAM_WIDTH, &i_target, dram_width);
    if(rc) return rc;
    
    ecmdDataBufferBase data_buffer(64);
    
    uint8_t num_ranks_array[2][2]; //[port][dimm]
    rc = FAPI_ATTR_GET(ATTR_EFF_NUM_RANKS_PER_DIMM, &i_target, num_ranks_array);
    if(rc) return rc;

    uint8_t is_sim = 0;
    rc = FAPI_ATTR_GET(ATTR_IS_SIMULATION, NULL, is_sim);
    if(rc) return rc;

    uint8_t address_mirror_map[2][2]; //address_mirror_map[port][dimm]
    rc = FAPI_ATTR_GET(ATTR_VPD_DRAM_ADDRESS_MIRRORING, &i_target, address_mirror_map);
    if(rc) return rc;

    rc = mss_ddr4_setup_pda(i_target, io_ccs_inst_cnt );
    if(rc)  return rc;
    
    rc_num = rc_num | num_idles_16.insertFromRight((uint32_t) 100, 0, 16);
   
   
   
    rc_num = rc_num | cke_4.setBit(0,4);
    rc_num = rc_num | csn_8.setBit(0,8);
    rc_num = rc_num | address_16.clearBit(0, 16);
    rc_num = rc_num | odt_4.clearBit(0,4);
    rc_num = rc_num | rasn_1.clearBit(0,1);
    rc_num = rc_num | casn_1.clearBit(0,1);
    rc_num = rc_num | wen_1.clearBit(0,1);
   
   //gets the start PDA values
   uint8_t prev_dram = pda[0].dram;
   uint8_t prev_port = pda[0].port;
   uint8_t prev_rank = pda[0].rank;
   uint8_t prev_dimm = pda[0].dimm;
   uint8_t prev_mrs  = pda[0].MRS;
   rc = mss_ddr4_load_nominal_mrs_pda(i_target,bank_3,address_16, prev_mrs, prev_port, prev_dimm, prev_rank);
   if(rc) return rc;
   
   vector<PDA_Scom_Storage> scom_storage;
   scom_storage.clear();
   rc = mss_ddr4_add_dram_pda(i_target,prev_port,prev_dram,scom_storage);
   if(rc) return rc;
   
   //runs through each PDA command
   for(uint32_t i=0;i<pda.size();i++) {
      FAPI_INF("Target %s On PDA %d is %s",i_target.toEcmdString(),i,pda[i].c_str());
      //dram, port, rank, dimm, and mrs are the same
      if(prev_dram == pda[i].dram && prev_port == pda[i].port && prev_rank == pda[i].rank && prev_dimm == pda[i].dimm && prev_mrs == pda[i].MRS) {
         //modifies this attribute
         rc = mss_ddr4_modify_mrs_pda(i_target,address_16, pda[i].attribute_name,pda[i].attribute_data);
         if(rc) return rc;
      }
      //another MRS, so set this MRS.  do additional checks to later in the code
      else {
         
	 //adds values to a backup address_16 before doing the mirroring
	 address_16_backup.clearBit(0, 16);
	 rc_num = rc_num | address_16_backup.insert(address_16, 0, 16, 0);
	 
         //loads the previous DRAM
         if (( address_mirror_map[prev_port][prev_dimm] & (0x08 >> prev_rank) ) && (is_sim == 0))
   	 {
   	     rc = mss_address_mirror_swizzle(i_target, prev_port, prev_dimm, prev_rank, address_16, bank_3);
   	     if(rc) return rc;
   	 }
	 
	 // Only corresponding CS to rank
   	 rc_num = rc_num | csn_8.setBit(0,8); 
   	 rc_num = rc_num | csn_8.clearBit(prev_rank+4*prev_dimm);
	 
   	 // Send out to the CCS array 
   	 rc = mss_ccs_inst_arry_0( i_target,
   	     	  io_ccs_inst_cnt,
   	     	  address_16,
   	     	  bank_3,
   	     	  activate_1,
   	     	  rasn_1,
   	     	  casn_1,
   	     	  wen_1,
   	     	  cke_4,
   	     	  csn_8,
   	     	  odt_4,
   	     	  ddr_cal_type_4,
   	     	  prev_port);
   	 if(rc) return rc;
   	 rc = mss_ccs_inst_arry_1( i_target,
   	     	  io_ccs_inst_cnt,
   	     	  num_idles_16,
   	     	  num_repeat_16,
   	     	  data_20,
   	     	  read_compare_1,
   	     	  rank_cal_4,
   	     	  ddr_cal_enable_1,
   	     	  ccs_end_1);
   	 if(rc) return rc;
   	 io_ccs_inst_cnt ++;
	 
	 //is an R or LR DIMM -> do a B side MRS write
	 if ( (dimm_type == ENUM_ATTR_EFF_DIMM_TYPE_RDIMM) || (dimm_type == ENUM_ATTR_EFF_DIMM_TYPE_LRDIMM) ) {
	    //takes values from the backup
	    address_16.clearBit(0, 16);
	    rc_num = rc_num | address_16.insert(address_16_backup, 0, 16, 0);
	    
	    //FLIPS all necessary bits
	    // Indicate B-Side DRAMS BG1=1 
            rc_num = rc_num | address_16.setBit(15);  // Set BG1 = 1
 
            rc_num = rc_num | address_16.flipBit(3,7); // Invert A3:A9
            rc_num = rc_num | address_16.flipBit(11);  // Invert A11
            rc_num = rc_num | address_16.flipBit(13);  // Invert A13
            rc_num = rc_num | address_16.flipBit(14);  // Invert A17
            rc_num = rc_num | bank_3.flipBit(0,3);     // Invert BA0,BA1,BG0
	    
	    //loads the previous DRAM
            if (( address_mirror_map[prev_port][prev_dimm] & (0x08 >> prev_rank) ) && (is_sim == 0))
   	    {
   	   	rc = mss_address_mirror_swizzle(i_target, prev_port, prev_dimm, prev_rank, address_16, bank_3);
   	   	if(rc) return rc;
   	    }
	    
	    // Only corresponding CS to rank
   	    rc_num = rc_num | csn_8.setBit(0,8); 
   	    rc_num = rc_num | csn_8.clearBit(prev_rank+4*prev_dimm);
	    
   	    // Send out to the CCS array 
   	    rc = mss_ccs_inst_arry_0( i_target,
   	   	     io_ccs_inst_cnt,
   	   	     address_16,
   	   	     bank_3,
   	   	     activate_1,
   	   	     rasn_1,
   	   	     casn_1,
   	   	     wen_1,
   	   	     cke_4,
   	   	     csn_8,
   	   	     odt_4,
   	   	     ddr_cal_type_4,
   	   	     prev_port);
   	    if(rc) return rc;
   	    rc = mss_ccs_inst_arry_1( i_target,
   	   	     io_ccs_inst_cnt,
   	   	     num_idles_16,
   	   	     num_repeat_16,
   	   	     data_20,
   	   	     read_compare_1,
   	   	     rank_cal_4,
   	   	     ddr_cal_enable_1,
   	   	     ccs_end_1);
   	    if(rc) return rc;
   	    io_ccs_inst_cnt ++;
	 }
	 
	 //the DRAM are different, so kick off CCS, and clear out the MRS DRAMs and set up a new DRAM
	 if(prev_dram != pda[i].dram) {
	    //sets a NOP as the last command
	    rc_num = rc_num | cke_4.setBit(0,4);
    	    rc_num = rc_num | csn_8.setBit(0,8);
    	    rc_num = rc_num | address_16.clearBit(0, 16);
    	    rc_num = rc_num | rasn_1.setBit(0,1);
    	    rc_num = rc_num | casn_1.setBit(0,1);
    	    rc_num = rc_num | wen_1.setBit(0,1);
	    
	    // Send out to the CCS array 
            rc = mss_ccs_inst_arry_0( i_target,
                     io_ccs_inst_cnt,
                     address_16,
                     bank_3,
                     activate_1,
                     rasn_1,
                     casn_1,
                     wen_1,
                     cke_4,
                     csn_8,
                     odt_4,
                     ddr_cal_type_4,
                     prev_port);
            if(rc) return rc;
            rc = mss_ccs_inst_arry_1( i_target,
                     io_ccs_inst_cnt,
                     num_idles_16,
                     num_repeat_16,
                     data_20,
                     read_compare_1,
                     rank_cal_4,
                     ddr_cal_enable_1,
                     ccs_end_1);
            if(rc) return rc;
            io_ccs_inst_cnt ++;
	    
	    //Setup end bit for CCS
            rc = mss_ccs_set_end_bit (i_target, io_ccs_inst_cnt-1);
            if (rc) return rc;
   
            //Execute the CCS array
            FAPI_INF("Executing the CCS array\n");
            rc = mss_execute_ccs_inst_array (i_target, NUM_POLL, WAIT_TIMER);
            if(rc) return rc;
	    io_ccs_inst_cnt = 0;
	    
	    // Sets NOP as the first command
            rc = mss_ccs_inst_arry_0( i_target,
                     io_ccs_inst_cnt,
                     address_16,
                     bank_3,
                     activate_1,
                     rasn_1,
                     casn_1,
                     wen_1,
                     cke_4,
                     csn_8,
                     odt_4,
                     ddr_cal_type_4,
                     prev_port);
            if(rc) return rc;
            rc = mss_ccs_inst_arry_1( i_target,
                     io_ccs_inst_cnt,
                     num_idles_16,
                     num_repeat_16,
                     data_20,
                     read_compare_1,
                     rank_cal_4,
                     ddr_cal_enable_1,
                     ccs_end_1);
            if(rc) return rc;
            io_ccs_inst_cnt ++;
	    
	    rc_num = rc_num | cke_4.setBit(0,4);
    	    rc_num = rc_num | csn_8.setBit(0,8);
    	    rc_num = rc_num | address_16.clearBit(0, 16);
    	    rc_num = rc_num | rasn_1.clearBit(0,1);
    	    rc_num = rc_num | casn_1.clearBit(0,1);
    	    rc_num = rc_num | wen_1.clearBit(0,1);
	    
	    //loops through and clears out the storage class
	    for(uint32_t scoms = 0; scoms < scom_storage.size(); scoms++) {
	       rc = fapiGetScom(i_target, scom_storage[scoms].scom_addr, data_buffer);
               if(rc) return rc;

   	       rc_num |= data_buffer.setBit(scom_storage[scoms].start_bit,scom_storage[scoms].num_bits);  //Enable CCS
   	       if (rc_num) {
   	    	  FAPI_ERR( "enable ccs setup: Error setting up buffers");
   	    	  rc.setEcmdError(rc_num);
   	    	  return rc;
   	       }
   	       rc = fapiPutScom(i_target, scom_storage[scoms].scom_addr, data_buffer);
               if(rc) return rc;
	    }
	    scom_storage.clear();
	    //enables the next dram scom
	    rc = mss_ddr4_add_dram_pda(i_target,pda[i].port,pda[i].dram,scom_storage);
            if(rc) return rc;
	 }
	 //different port but same DRAM, enable the next scom
	 else if(prev_port != pda[i].port) {
	    //enables the next dram scom
	    rc = mss_ddr4_add_dram_pda(i_target,pda[i].port,pda[i].dram,scom_storage);
            if(rc) return rc;
	 }
	 
	 //loads in the nominal MRS for this target
	 prev_dram = pda[i].dram;
	 prev_port = pda[i].port;
	 prev_rank = pda[i].rank;
	 prev_dimm = pda[i].dimm;
	 prev_mrs  = pda[i].MRS;
	 
	 rc = mss_ddr4_load_nominal_mrs_pda(i_target,bank_3,address_16, prev_mrs, prev_port, prev_dimm, prev_rank);
	 //modifies the MRS
	 rc = mss_ddr4_modify_mrs_pda(i_target,address_16, pda[i].attribute_name,pda[i].attribute_data);
         if(rc) return rc;
      } 
   }      
   
   //runs the last PDA command
   //adds values to a backup address_16 before doing the mirroring
   address_16_backup.clearBit(0, 16);
   rc_num = rc_num | address_16_backup.insert(address_16, 0, 16, 0);

   //loads the previous DRAM
   if (( address_mirror_map[prev_port][prev_dimm] & (0x08 >> prev_rank) ) && (is_sim == 0))
   {
       rc = mss_address_mirror_swizzle(i_target, prev_port, prev_dimm, prev_rank, address_16, bank_3);
       if(rc) return rc;
   }

   // Only corresponding CS to rank
   rc_num = rc_num | csn_8.setBit(0,8); 
   rc_num = rc_num | csn_8.clearBit(prev_rank+4*prev_dimm);

   // Send out to the CCS array 
   rc = mss_ccs_inst_arry_0( i_target,
   	    io_ccs_inst_cnt,
   	    address_16,
   	    bank_3,
   	    activate_1,
   	    rasn_1,
   	    casn_1,
   	    wen_1,
   	    cke_4,
   	    csn_8,
   	    odt_4,
   	    ddr_cal_type_4,
   	    prev_port);
   if(rc) return rc;
   rc = mss_ccs_inst_arry_1( i_target,
   	    io_ccs_inst_cnt,
   	    num_idles_16,
   	    num_repeat_16,
   	    data_20,
   	    read_compare_1,
   	    rank_cal_4,
   	    ddr_cal_enable_1,
   	    ccs_end_1);
   if(rc) return rc;
   io_ccs_inst_cnt ++;

   //is an R or LR DIMM -> do a B side MRS write
   if ( (dimm_type == ENUM_ATTR_EFF_DIMM_TYPE_RDIMM) || (dimm_type == ENUM_ATTR_EFF_DIMM_TYPE_LRDIMM) ) {
      //takes values from the backup
      address_16.clearBit(0, 16);
      rc_num = rc_num | address_16.insert(address_16_backup, 0, 16, 0);
      
      //FLIPS all necessary bits
      // Indicate B-Side DRAMS BG1=1 
      rc_num = rc_num | address_16.setBit(15);  // Set BG1 = 1
 
      rc_num = rc_num | address_16.flipBit(3,7); // Invert A3:A9
      rc_num = rc_num | address_16.flipBit(11);  // Invert A11
      rc_num = rc_num | address_16.flipBit(13);  // Invert A13
      rc_num = rc_num | address_16.flipBit(14);  // Invert A17
      rc_num = rc_num | bank_3.flipBit(0,3);	 // Invert BA0,BA1,BG0
      
      //loads the previous DRAM
      if (( address_mirror_map[prev_port][prev_dimm] & (0x08 >> prev_rank) ) && (is_sim == 0))
      {
   	  rc = mss_address_mirror_swizzle(i_target, prev_port, prev_dimm, prev_rank, address_16, bank_3);
   	  if(rc) return rc;
      }
      
      // Only corresponding CS to rank
      rc_num = rc_num | csn_8.setBit(0,8); 
      rc_num = rc_num | csn_8.clearBit(prev_rank+4*prev_dimm);
      
      // Send out to the CCS array 
      rc = mss_ccs_inst_arry_0( i_target,
   	       io_ccs_inst_cnt,
   	       address_16,
   	       bank_3,
   	       activate_1,
   	       rasn_1,
   	       casn_1,
   	       wen_1,
   	       cke_4,
   	       csn_8,
   	       odt_4,
   	       ddr_cal_type_4,
   	       prev_port);
      if(rc) return rc;
      rc = mss_ccs_inst_arry_1( i_target,
   	       io_ccs_inst_cnt,
   	       num_idles_16,
   	       num_repeat_16,
   	       data_20,
   	       read_compare_1,
   	       rank_cal_4,
   	       ddr_cal_enable_1,
   	       ccs_end_1);
      if(rc) return rc;
      io_ccs_inst_cnt ++;
   }
   
   
   //sets a NOP as the last command
   rc_num = rc_num | cke_4.setBit(0,4);
   rc_num = rc_num | csn_8.setBit(0,8);
   rc_num = rc_num | address_16.clearBit(0, 16);
   rc_num = rc_num | rasn_1.setBit(0,1);
   rc_num = rc_num | casn_1.setBit(0,1);
   rc_num = rc_num | wen_1.setBit(0,1);

   // Send out to the CCS array 
   rc = mss_ccs_inst_arry_0( i_target,
   	    io_ccs_inst_cnt,
   	    address_16,
   	    bank_3,
   	    activate_1,
   	    rasn_1,
   	    casn_1,
   	    wen_1,
   	    cke_4,
   	    csn_8,
   	    odt_4,
   	    ddr_cal_type_4,
   	    prev_port);
   if(rc) return rc;
   rc = mss_ccs_inst_arry_1( i_target,
   	    io_ccs_inst_cnt,
   	    num_idles_16,
   	    num_repeat_16,
   	    data_20,
   	    read_compare_1,
   	    rank_cal_4,
   	    ddr_cal_enable_1,
   	    ccs_end_1);
   if(rc) return rc;
   io_ccs_inst_cnt ++;
   
   //Setup end bit for CCS
   rc = mss_ccs_set_end_bit (i_target, io_ccs_inst_cnt-1);
   if (rc) return rc;
   
   //Execute the CCS array
   FAPI_INF("Executing the CCS array\n");
   rc = mss_execute_ccs_inst_array (i_target, NUM_POLL, WAIT_TIMER);
   if(rc) return rc;
   
   //loops through and clears out the storage class
   for(uint32_t scoms = 0; scoms < scom_storage.size(); scoms++) {
      rc = fapiGetScom(i_target, scom_storage[scoms].scom_addr, data_buffer);
      if(rc) return rc;

      rc_num |= data_buffer.setBit(scom_storage[scoms].start_bit,scom_storage[scoms].num_bits);  //Enable CCS
      if (rc_num) {
   	 FAPI_ERR( "enable ccs setup: Error setting up buffers");
   	 rc.setEcmdError(rc_num);
   	 return rc;
      }
      rc = fapiPutScom(i_target, scom_storage[scoms].scom_addr, data_buffer);
      if(rc) return rc;
   }
   //}
      
   io_ccs_inst_cnt = 0;
   rc = mss_ddr4_disable_pda(i_target,io_ccs_inst_cnt);
   return rc;
}


//////////////////////////////////////////////////////////////////////////////////
/// mss_ddr4_add_dram_pda
/// adds a specific DRAM on a specific port to receive the current MRS command in PDA mode
//////////////////////////////////////////////////////////////////////////////////
ReturnCode mss_ddr4_add_dram_pda(Target& i_target,uint8_t port,uint8_t dram,vector<PDA_Scom_Storage> & scom_storage) {
   ReturnCode rc;
   ecmdDataBufferBase data_buffer(64);
   //access delay regs function
   uint8_t i_rank_pair = 0;
   input_type_t i_input_type_e = WR_DQ;
   uint8_t i_input_index = 75;
   uint8_t i_verbose = 1;
   uint8_t phy_lane = 6;
   uint8_t phy_block = 6;
   uint8_t flag = 0;
   uint32_t scom_len = 0;
   uint32_t scom_start = 0;
   uint32_t rc_num = 0;
   
   
   uint8_t dram_width;
   rc = FAPI_ATTR_GET(ATTR_EFF_DRAM_WIDTH, &i_target, dram_width);
   if(rc) return rc;
   
   // C4 DQ to lane/block (flag = 0) in PHY or lane/block to C4 DQ (flag = 1) 
   // In this case moving from lane/block to C4 DQ to use access_delay_reg
   i_input_index = 4*dram;
   rc = mss_c4_phy(i_target,port,i_rank_pair,i_input_type_e,i_input_index,i_verbose,phy_lane,phy_block,flag); 

   uint64_t reg_address = 0x800000010301143full + 0x0001000000000000ull*port+ 0x0000040000000000ull*(phy_block);
   //gets the lane and number of bits to set to 0's
   if(dram_width == 0x04) {
      scom_start = 60 + (uint32_t)(phy_lane/4);
      scom_len = 1;
   }
   //x8 DIMM
   else {
      scom_start = 60 + (uint32_t)((phy_lane/8)*2);
      scom_len = 2;
   }
   FAPI_INF("Enabling %016llx start at %d for %d bits",reg_address,scom_start,scom_len);
   
   rc = fapiGetScom(i_target, reg_address, data_buffer);
   if(rc) return rc;

   rc_num |= data_buffer.clearBit(scom_start,scom_len);	 //Enable CCS
   if (rc_num) {
      FAPI_ERR( "enable ccs setup: Error setting up buffers");
      rc.setEcmdError(rc_num);
      return rc;
   }
   rc = fapiPutScom(i_target, reg_address, data_buffer);
   if(rc) return rc;
   
   scom_storage.push_back(PDA_Scom_Storage(reg_address,scom_start,scom_len));
   
   return rc;
}

//////////////////////////////////////////////////////////////////////////////////
/// mss_ddr4_disable_pda
/// disables per-DRAM addressability funcitonality on both ports on the passed MBA
//////////////////////////////////////////////////////////////////////////////////
ReturnCode mss_ddr4_disable_pda(Target& i_target,uint32_t& io_ccs_inst_cnt) {
    uint32_t i_port_number=0;
    uint32_t dimm_number;
    uint32_t rank_number;
    const uint32_t NUM_POLL = 10;
    const uint32_t WAIT_TIMER = 1500;
    ReturnCode rc;  
    ReturnCode rc_buff;
    uint32_t rc_num = 0;
    uint64_t reg_address;
    ecmdDataBufferBase data_buffer(64);
    ecmdDataBufferBase data_buffer_64(64);
    ecmdDataBufferBase address_16(16);
    ecmdDataBufferBase bank_3(3);
    ecmdDataBufferBase activate_1(1);
    rc_num = rc_num | activate_1.setBit(0);
    ecmdDataBufferBase rasn_1(1);
    ecmdDataBufferBase casn_1(1);
    ecmdDataBufferBase wen_1(1);
    ecmdDataBufferBase cke_4(4);
    rc_num = rc_num | cke_4.setBit(0,4);
    ecmdDataBufferBase csn_8(8);
    rc_num = rc_num | csn_8.setBit(0,8);
    ecmdDataBufferBase odt_4(4);
    ecmdDataBufferBase ddr_cal_type_4(4);

    ecmdDataBufferBase num_idles_16(16);
    ecmdDataBufferBase num_repeat_16(16);
    ecmdDataBufferBase data_20(20);
    ecmdDataBufferBase read_compare_1(1);
    ecmdDataBufferBase rank_cal_4(4);
    ecmdDataBufferBase ddr_cal_enable_1(1);
    ecmdDataBufferBase ccs_end_1(1);

    ecmdDataBufferBase mrs3(16);
    uint16_t MRS3 = 0;
    
    uint8_t num_ranks_array[2][2]; //[port][dimm]
    
    uint8_t num_ranks;
    rc = FAPI_ATTR_GET(ATTR_EFF_NUM_RANKS_PER_DIMM, &i_target, num_ranks_array);
    if(rc) return rc;

    uint8_t dimm_type;
    rc = FAPI_ATTR_GET(ATTR_EFF_DIMM_TYPE, &i_target, dimm_type);
    if(rc) return rc;

    uint8_t is_sim = 0;
    rc = FAPI_ATTR_GET(ATTR_IS_SIMULATION, NULL, is_sim);
    if(rc) return rc;

    uint8_t address_mirror_map[2][2]; //address_mirror_map[port][dimm]
    rc = FAPI_ATTR_GET(ATTR_VPD_DRAM_ADDRESS_MIRRORING, &i_target, address_mirror_map);
    if(rc) return rc;

    // WORKAROUNDS 
    rc = fapiGetScom(i_target, CCS_MODEQ_AB_REG_0x030106A7, data_buffer);
    if(rc) return rc;
    //Setting up CCS mode
    rc_num = rc_num | data_buffer.setBit(51);
    if (rc_num) {
      FAPI_ERR( "disable ccs setup: Error disabling up buffers");
      rc_buff.setEcmdError(rc_num);
      return rc_buff;
    }
    rc = fapiPutScom(i_target, CCS_MODEQ_AB_REG_0x030106A7, data_buffer);
    if(rc) return rc;   
    
    //loops through port 0 and port 1 on the given MBA
    for(i_port_number=0;i_port_number<MAX_NUM_PORTS;i_port_number++) {
       // Raise CKE high with NOPS, waiting min Reset CKE exit time (tXPR) - 400 cycles
       rc_num = rc_num | cke_4.setBit(0,4);
       rc_num = rc_num | csn_8.setBit(0,8);
       rc_num = rc_num | address_16.clearBit(0, 16);
       rc_num = rc_num | odt_4.clearBit(0,4);
       rc_num = rc_num | num_idles_16.insertFromRight((uint32_t) 400, 0, 16);
       if (rc_num) {
          FAPI_ERR( "disable ccs setup: Error disabling up buffers");
          rc_buff.setEcmdError(rc_num);
          return rc_buff;
       }
       rc = mss_ccs_inst_arry_0( i_target,
    				 io_ccs_inst_cnt,
    				 address_16,
    				 bank_3,
    				 activate_1,
    				 rasn_1,
    				 casn_1,
    				 wen_1,
    				 cke_4,
    				 csn_8,
    				 odt_4,
    				 ddr_cal_type_4,
    				 i_port_number);	
       if(rc) return rc;
       rc = mss_ccs_inst_arry_1( i_target,
    				 io_ccs_inst_cnt,
    				 num_idles_16,
    				 num_repeat_16,
    				 data_20,
    				 read_compare_1,
    				 rank_cal_4,
    				 ddr_cal_enable_1,
    				 ccs_end_1);  
       if(rc) return rc;
       io_ccs_inst_cnt ++;
    }
    
    
    //Sets up MRS3 -> the MRS that has PDA
    uint8_t mpr_op; // MPR Op
    rc = FAPI_ATTR_GET(ATTR_EFF_MPR_MODE, &i_target, mpr_op);
    if(rc) return rc;
    uint8_t mpr_page; // MPR Page Selection  
    rc = FAPI_ATTR_GET(ATTR_EFF_MPR_PAGE, &i_target, mpr_page);
    if(rc) return rc;
    uint8_t geardown_mode; // Gear Down Mode  
    rc = FAPI_ATTR_GET(ATTR_EFF_GEARDOWN_MODE, &i_target, geardown_mode);
    if(rc) return rc;
    uint8_t temp_readout; // Temperature sensor readout  
    rc = FAPI_ATTR_GET(ATTR_EFF_TEMP_READOUT, &i_target, temp_readout);
    if(rc) return rc;
    uint8_t fine_refresh; // fine refresh mode  
    rc = FAPI_ATTR_GET(ATTR_EFF_FINE_REFRESH_MODE, &i_target, fine_refresh);
    if(rc) return rc;
    uint8_t wr_latency; // write latency for CRC and DM  
    rc = FAPI_ATTR_GET(ATTR_EFF_CRC_WR_LATENCY, &i_target, wr_latency);
    if(rc) return rc;
    uint8_t read_format; // MPR READ FORMAT  
    rc = FAPI_ATTR_GET(ATTR_EFF_MPR_RD_FORMAT, &i_target, read_format);
    if(rc) return rc;
    
    //exits PDA
    for(i_port_number=0;i_port_number<2;i_port_number++) {
    //loops through the DP18's and sets everything to 0's
      for(uint8_t dp18 = 0; dp18<MAX_NUM_DP18S;dp18++) {
   	 reg_address = 0x800000010301143full + 0x0001000000000000ull*i_port_number+ 0x0000040000000000ull*(dp18);
   	 rc = fapiGetScom(i_target, reg_address, data_buffer);
   	 if(rc) return rc;

   	 rc_num |= data_buffer.clearBit(60,4);    //Enable CCS
   	 if (rc_num) {
   	    FAPI_ERR( "enable ccs setup: Error setting up buffers");
   	    rc.setEcmdError(rc_num);
   	    return rc;
   	 }
   	 rc = fapiPutScom(i_target, reg_address, data_buffer);
   	 if(rc) return rc;
      }
   }
    
    //exits PDA
    for(i_port_number=0;i_port_number<2;i_port_number++) {
    	for ( dimm_number = 0; dimm_number < MAX_NUM_DIMMS; dimm_number++)
    	{
    	    num_ranks = num_ranks_array[i_port_number][dimm_number];

    	    if (num_ranks == 0)
    	    {
    		FAPI_INF( "PORT%d DIMM%d not configured. Num_ranks: %d ", i_port_number, dimm_number, num_ranks);
    	    }
    	    else
    	    {
    		// Rank 0-3
    		for ( rank_number = 0; rank_number < num_ranks; rank_number++)
    		{
    		   // Only corresponding CS to rank
    		   rc_num = rc_num | csn_8.setBit(0,8); 
    		   rc_num = rc_num | csn_8.clearBit(rank_number+4*dimm_number);
    			
    		   rc_num = rc_num | bank_3.insert((uint8_t) MRS3_BA, 0, 1, 7);
    		   rc_num = rc_num | bank_3.insert((uint8_t) MRS3_BA, 1, 1, 6);
    		   rc_num = rc_num | bank_3.insert((uint8_t) MRS3_BA, 2, 1, 5);
    				
	           //enables PDA
	           rc_num = rc_num | mrs3.insert((uint8_t) mpr_page, 0, 2);
	           rc_num = rc_num | mrs3.insert((uint8_t) mpr_op, 2, 1);
	           rc_num = rc_num | mrs3.insert((uint8_t) geardown_mode, 3, 1);
	           rc_num = rc_num | mrs3.insert((uint8_t) 0x00, 4, 1);
	           rc_num = rc_num | mrs3.insert((uint8_t) temp_readout, 5, 1);
	           rc_num = rc_num | mrs3.insert((uint8_t) fine_refresh, 6, 3);
	           rc_num = rc_num | mrs3.insert((uint8_t) wr_latency, 9, 2);
	           rc_num = rc_num | mrs3.insert((uint8_t) read_format, 11, 2);
	           rc_num = rc_num | mrs3.insert((uint8_t) 0x00, 13, 2);
	           rc_num = rc_num | mrs3.extractPreserve(&MRS3, 0, 16, 0);
	           rc_num = rc_num | num_idles_16.insertFromRight((uint32_t) 100, 0, 16);
		   
		   //copies over values
    		   rc_num = rc_num | address_16.insert(mrs3, 0, 16, 0);
    		   if (rc_num)
    		   {
    		       FAPI_ERR( "mss_mrs_load: Error setting up buffers");
    		       rc_buff.setEcmdError(rc_num);
    		       return rc_buff;
    		   }
		   
    		   if (( address_mirror_map[i_port_number][dimm_number] & (0x08 >> rank_number) ) && (is_sim == 0))
    		   {
    		      rc = mss_address_mirror_swizzle(i_target, i_port_number, dimm_number, rank_number, address_16, bank_3);
    		      if(rc) return rc;
    		   }
		   
    		   // Send out to the CCS array 
    		   rc = mss_ccs_inst_arry_0( i_target,
    				     io_ccs_inst_cnt,
    				     address_16,
    				     bank_3,
    				     activate_1,
    				     rasn_1,
    				     casn_1,
    				     wen_1,
    				     cke_4,
    				     csn_8,
    				     odt_4,
    				     ddr_cal_type_4,
    				     i_port_number);
    		   if(rc) return rc;
    		   rc = mss_ccs_inst_arry_1( i_target,
    				     io_ccs_inst_cnt,
    				     num_idles_16,
    				     num_repeat_16,
    				     data_20,
    				     read_compare_1,
    				     rank_cal_4,
    				     ddr_cal_enable_1,
    				     ccs_end_1);
    		   if(rc) return rc;
    		   io_ccs_inst_cnt ++;
		   
		   //if the DIMM is an R or LR DIMM, then run inverted for the B-Side DRAM
                   if ( (dimm_type == ENUM_ATTR_EFF_DIMM_TYPE_RDIMM) || (dimm_type == ENUM_ATTR_EFF_DIMM_TYPE_LRDIMM) ) 
		   {
		   
		       //reload all MRS values (removes address swizzling)
		        // Only corresponding CS to rank
    		       rc_num = rc_num | csn_8.setBit(0,8); 
    		       rc_num = rc_num | csn_8.clearBit(rank_number+4*dimm_number);
    		    	    
    		       rc_num = rc_num | bank_3.insert((uint8_t) MRS3_BA, 0, 1, 7);
    		       rc_num = rc_num | bank_3.insert((uint8_t) MRS3_BA, 1, 1, 6);
    		       rc_num = rc_num | bank_3.insert((uint8_t) MRS3_BA, 2, 1, 5);
    		    		    
	               //enables PDA
	               rc_num = rc_num | mrs3.insert((uint8_t) mpr_page, 0, 2);
	               rc_num = rc_num | mrs3.insert((uint8_t) mpr_op, 2, 1);
	               rc_num = rc_num | mrs3.insert((uint8_t) geardown_mode, 3, 1);
	               rc_num = rc_num | mrs3.insert((uint8_t) 0x00, 4, 1);
	               rc_num = rc_num | mrs3.insert((uint8_t) temp_readout, 5, 1);
	               rc_num = rc_num | mrs3.insert((uint8_t) fine_refresh, 6, 3);
	               rc_num = rc_num | mrs3.insert((uint8_t) wr_latency, 9, 2);
	               rc_num = rc_num | mrs3.insert((uint8_t) read_format, 11, 2);
	               rc_num = rc_num | mrs3.insert((uint8_t) 0x00, 13, 2);
	               rc_num = rc_num | mrs3.extractPreserve(&MRS3, 0, 16, 0);
	               rc_num = rc_num | num_idles_16.insertFromRight((uint32_t) 100, 0, 16);
		       //copies over values
		       rc_num = rc_num | address_16.insert(mrs3, 0, 16, 0);
		       
		       //FLIPS all necessary bits
		       // Indicate B-Side DRAMS BG1=1 
                       rc_num = rc_num | address_16.setBit(15);  // Set BG1 = 1
 
                       rc_num = rc_num | address_16.flipBit(3,7); // Invert A3:A9
                       rc_num = rc_num | address_16.flipBit(11);  // Invert A11
                       rc_num = rc_num | address_16.flipBit(13);  // Invert A13
                       rc_num = rc_num | address_16.flipBit(14);  // Invert A17
                       rc_num = rc_num | bank_3.flipBit(0,3);	  // Invert BA0,BA1,BG0
		       
		       if (rc_num)
    		       {
    		     	   FAPI_ERR( "mss_ddr4_setup_pda: Error setting up buffers");
    		     	   rc_buff.setEcmdError(rc_num);
    		     	   return rc_buff;
    		       }
		     	   
		     	   if (( address_mirror_map[i_port_number][dimm_number] & (0x08 >> rank_number) ) && (is_sim == 0))
    		       {
    		     	  rc = mss_address_mirror_swizzle(i_target, i_port_number, dimm_number, rank_number, address_16, bank_3);
    		     	  if(rc) return rc;
    		       }
    		       
    		       // Send out to the CCS array 
    		       rc = mss_ccs_inst_arry_0( i_target,
    		     	 		 io_ccs_inst_cnt,
    		     	 		 address_16,
    		     	 		 bank_3,
    		     	 		 activate_1,
    		     	 		 rasn_1,
    		     	 		 casn_1,
    		     	 		 wen_1,
    		     	 		 cke_4,
    		     	 		 csn_8,
    		     	 		 odt_4,
    		     	 		 ddr_cal_type_4,
    		     	 		 i_port_number);
    		       if(rc) return rc;
    		       rc = mss_ccs_inst_arry_1( i_target,
    		     	 		 io_ccs_inst_cnt,
    		     	 		 num_idles_16,
    		     	 		 num_repeat_16,
    		     	 		 data_20,
    		     	 		 read_compare_1,
    		     	 		 rank_cal_4,
    		     	 		 ddr_cal_enable_1,
    		     	 		 ccs_end_1);
    		       if(rc) return rc;
    		       io_ccs_inst_cnt ++;
		    }
    		}    
    	    }
    	}
   }
   
   //Setup end bit for CCS
    rc = mss_ccs_set_end_bit (i_target, io_ccs_inst_cnt-1);
    if (rc) return rc;
   
   //Execute the CCS array
   FAPI_INF("Executing the CCS array\n");
   rc = mss_execute_ccs_inst_array (i_target, NUM_POLL, WAIT_TIMER);
   
   //Disable CCS
   FAPI_INF("Disabling CCS\n");
   reg_address = CCS_MODEQ_AB_REG_0x030106A7;
   rc = fapiGetScom(i_target, reg_address, data_buffer);
   if(rc) return rc;


   rc_num |= data_buffer.clearBit(29);
   if (rc_num) {
      FAPI_ERR( "disable ccs setup: Error disabling up buffers");
      rc_buff.setEcmdError(rc_num);
      return rc_buff;
   }
   rc = fapiPutScom(i_target, reg_address, data_buffer);
   if(rc) return rc;
   
   //disables the DDR4 PDA mode writes  
   rc = fapiGetScom(i_target,  DPHY01_DDRPHY_WC_CONFIG3_P0_0x8000CC050301143F, data_buffer);
    if(rc) return rc;
    //Setting up CCS mode
    rc_num = rc_num | data_buffer.clearBit(48);
    if (rc_num)
    {
    	FAPI_ERR( "mss_ddr4_setup_pda: Error setting up buffers");
    	rc_buff.setEcmdError(rc_num);
    	return rc_buff;
    }
    rc = fapiPutScom(i_target,  DPHY01_DDRPHY_WC_CONFIG3_P0_0x8000CC050301143F, data_buffer);    
    if(rc) return rc;
    
    rc = fapiGetScom(i_target,  DPHY01_DDRPHY_WC_CONFIG3_P1_0x8001CC050301143F, data_buffer);
    if(rc) return rc;
    //Setting up CCS mode
    rc_num = rc_num | data_buffer.clearBit(48);
    if (rc_num)
    {
    	FAPI_ERR( "mss_ddr4_setup_pda: Error setting up buffers");
    	rc_buff.setEcmdError(rc_num);
    	return rc_buff;
    }
    rc = fapiPutScom(i_target,  DPHY01_DDRPHY_WC_CONFIG3_P1_0x8001CC050301143F, data_buffer);    
    if(rc) return rc;
   
   FAPI_INF("Successfully exited out of PDA mode.");
   io_ccs_inst_cnt = 0;
   return rc;
}

//////////////////////////////////////////////////////////////////////////////////
/// mss_ddr4_modify_mrs_pda
/// disables per-DRAM addressability funcitonality on both ports on the passed MBA
//////////////////////////////////////////////////////////////////////////////////
ReturnCode mss_ddr4_modify_mrs_pda(Target& i_target,ecmdDataBufferBase& address_16,uint32_t attribute_name,uint8_t attribute_data) {
   ReturnCode rc;
   uint32_t rc_num = 0;
   uint8_t dram_bl = attribute_data;
   uint8_t read_bt = attribute_data; //Read Burst Type 
   uint8_t dram_cl = attribute_data;
   uint8_t test_mode = attribute_data; //TEST MODE 
   uint8_t dll_reset = attribute_data; //DLL Reset 
   uint8_t dram_wr = attribute_data; //DRAM write recovery
   uint8_t dram_rtp = attribute_data; //DRAM RTP - read to precharge
   uint8_t dram_wr_rtp = attribute_data;
   uint8_t dll_precharge = attribute_data; //DLL Control For Precharge if (dll_precharge == ENUM_ATTR_EFF_DRAM_DLL_PPD_SLOWEXIT)
   uint8_t dll_enable = attribute_data; //DLL Enable 
   uint8_t out_drv_imp_cntl = attribute_data;
   uint8_t dram_rtt_nom = attribute_data;
   uint8_t dram_al = attribute_data;
   uint8_t wr_lvl = attribute_data; //write leveling enable
   uint8_t tdqs_enable = attribute_data; //TDQS Enable 
   uint8_t q_off = attribute_name; //Qoff - Output buffer Enable 
   uint8_t lpasr = attribute_data; // Low Power Auto Self-Refresh -- new not yet supported
   uint8_t cwl = attribute_data; // CAS Write Latency 
   uint8_t dram_rtt_wr = attribute_data;
   uint8_t mpr_op = attribute_data; // MPR Op
   uint8_t mpr_page = attribute_data; // MPR Page Selection  
   uint8_t geardown_mode = attribute_data; // Gear Down Mode  
   uint8_t temp_readout = attribute_data; // Temperature sensor readout  
   uint8_t fine_refresh = attribute_data; // fine refresh mode  
   uint8_t wr_latency = attribute_data; // write latency for CRC and DM  
   uint8_t write_crc = attribute_data; // CAS Write Latency 
   uint8_t read_format = attribute_data; // MPR READ FORMAT  
   uint8_t max_pd_mode = attribute_data; // Max Power down mode 
   uint8_t temp_ref_range = attribute_data; // Temp ref range 
   uint8_t temp_ref_mode = attribute_data; // Temp controlled ref mode 
   uint8_t vref_mon = attribute_data; // Internal Vref Monitor 
   uint8_t cs_cmd_latency = attribute_data; // CS to CMD/ADDR Latency 
   uint8_t ref_abort = attribute_data; // Self Refresh Abort 
   uint8_t rd_pre_train_mode = attribute_data; // Read Pre amble Training Mode 
   uint8_t rd_preamble = attribute_data; // Read Pre amble 
   uint8_t wr_preamble = attribute_data; // Write Pre amble 
   uint8_t ca_parity_latency = attribute_data; //C/A Parity Latency Mode  
   uint8_t crc_error_clear = attribute_data; //CRC Error Clear  
   uint8_t ca_parity_error_status = attribute_data; //C/A Parity Error Status  
   uint8_t odt_input_buffer = attribute_data; //ODT Input Buffer during power down  
   uint8_t rtt_park = attribute_data; //RTT_Park value  
   uint8_t ca_parity = attribute_data; //CA Parity Persistance Error  
   uint8_t data_mask = attribute_data; //Data Mask  
   uint8_t write_dbi = attribute_data; //Write DBI  
   uint8_t read_dbi = attribute_data; //Read DBI  
   uint8_t vrefdq_train_value = attribute_data; //vrefdq_train value   
   uint8_t vrefdq_train_range = attribute_data; //vrefdq_train range   
   uint8_t vrefdq_train_enable = attribute_data; //vrefdq_train enable  
   uint8_t tccd_l = attribute_data; //tccd_l  
   uint8_t dram_access;

   switch (attribute_name) {
       case ATTR_EFF_DRAM_BL:
	   if (dram_bl == ENUM_ATTR_EFF_DRAM_BL_BL8)
           {
               dram_bl = 0x00;
           }
           else if (dram_bl == ENUM_ATTR_EFF_DRAM_BL_OTF)
           {
               dram_bl = 0x80;
           }
           else if (dram_bl == ENUM_ATTR_EFF_DRAM_BL_BC4)
           {
               dram_bl = 0x40;
           }
	   rc_num = rc_num | address_16.insert((uint8_t) dram_bl, 0, 2, 0);
	   break;
       case ATTR_EFF_DRAM_RBT:
	   if (read_bt == ENUM_ATTR_EFF_DRAM_RBT_SEQUENTIAL)
           {
               read_bt = 0x00;
           }
           else if (read_bt == ENUM_ATTR_EFF_DRAM_RBT_INTERLEAVE)
           {
               read_bt = 0xFF;
           }
           rc_num = rc_num | address_16.insert((uint8_t) read_bt, 3, 1, 0);
	   break;
       case ATTR_EFF_DRAM_CL:
	   if ((dram_cl > 8)&&(dram_cl < 17))
           {
               dram_cl = dram_cl - 9; 
           }
           else if ((dram_cl > 17)&&(dram_cl < 25))
           {
               dram_cl = (dram_cl >> 1) - 1;   
           }
           dram_cl = mss_reverse_8bits(dram_cl);
           rc_num = rc_num | address_16.insert((uint8_t) dram_cl, 2, 1, 0);
           rc_num = rc_num | address_16.insert((uint8_t) dram_cl, 4, 3, 1);
	   break;
       case ATTR_EFF_DRAM_TM:
	   if (test_mode == ENUM_ATTR_EFF_DRAM_TM_NORMAL)
           {
               test_mode = 0x00;
           }
           else if (test_mode == ENUM_ATTR_EFF_DRAM_TM_TEST)
           {
               test_mode = 0xFF;
           }
           rc_num = rc_num | address_16.insert((uint8_t) test_mode, 7, 1);
	   break;
       case ATTR_EFF_DRAM_DLL_RESET:
	   dll_reset = 0x00;
	   FAPI_ERR( "ERROR: ATTR_EFF_DRAM_DLL_RESET accessed during PDA functionality, overwritten");
           rc_num = rc_num | address_16.insert((uint8_t) dll_reset, 8, 1);
	   break;
       case ATTR_EFF_DRAM_WR:
           if ( (dram_wr == 10) )//&& (dram_rtp == 5) )
           {
               dram_wr_rtp = 0x00;
           }
           else if ( (dram_wr == 12) )//&& (dram_rtp == 6) )
           {
               dram_wr_rtp = 0x80;
           }
           else if ( (dram_wr == 13) )//&& (dram_rtp == 7) )
           {
               dram_wr_rtp = 0x40;
           }
           else if ( (dram_wr == 14) )//&& (dram_rtp == 8) )
           {
               dram_wr_rtp = 0xC0;
           }
           else if ( (dram_wr == 18) )//&& (dram_rtp == 9) )
           {
               dram_wr_rtp = 0x20;
           }
           else if ( (dram_wr == 20) )//&& (dram_rtp == 10) )
           {
               dram_wr_rtp = 0xA0;
           }
           else if ( (dram_wr == 24) )//&& (dram_rtp == 12) )
           {
               dram_wr_rtp = 0x60;
           }
    	   rc_num = rc_num | address_16.insert((uint8_t) dram_wr_rtp, 9, 3);
	   break;
       case ATTR_EFF_DRAM_TRTP:
           if ( (dram_rtp == 5) )
           {
               dram_wr_rtp = 0x00;
           }
           else if ( (dram_rtp == 6) )
           {
               dram_wr_rtp = 0x80;
           }
           else if ( (dram_rtp == 7) )
           {
               dram_wr_rtp = 0x40;
           }
           else if ( (dram_rtp == 8) )
           {
               dram_wr_rtp = 0xC0;
           }
           else if ( (dram_rtp == 9) )
           {
               dram_wr_rtp = 0x20;
           }
           else if ( (dram_rtp == 10) )
           {
               dram_wr_rtp = 0xA0;
           }
           else if ( (dram_rtp == 12) )
           {
               dram_wr_rtp = 0x60;
           }
    	   rc_num = rc_num | address_16.insert((uint8_t) dram_wr_rtp, 9, 3);
	   break;
       case ATTR_EFF_DRAM_DLL_PPD:
           if (dll_precharge == ENUM_ATTR_EFF_DRAM_DLL_PPD_SLOWEXIT)
	   {
               dll_precharge = 0x00;
           }
           else if (dll_precharge == ENUM_ATTR_EFF_DRAM_DLL_PPD_FASTEXIT)
           {
               dll_precharge = 0xFF;
           }
	   FAPI_INF("ERROR: ATTR_EFF_DRAM_DLL_PPD is an unused MRS value!!! Skipping...");
	   break;
       case ATTR_EFF_DRAM_DLL_ENABLE:
           if (dll_enable == ENUM_ATTR_EFF_DRAM_DLL_ENABLE_DISABLE)
           {
               dll_enable = 0x00;
           }
           else if (dll_enable == ENUM_ATTR_EFF_DRAM_DLL_ENABLE_ENABLE)
           {
               dll_enable = 0xFF;
           }
           rc_num = rc_num | address_16.insert((uint8_t) dll_enable, 0, 1, 0);
	   break;
       case ATTR_VPD_DRAM_RON:
	   if (out_drv_imp_cntl == ENUM_ATTR_VPD_DRAM_RON_OHM34)
           {
               out_drv_imp_cntl = 0x00;
           }
    	   // Not currently supported
           else if (out_drv_imp_cntl == ENUM_ATTR_VPD_DRAM_RON_OHM48) //not supported
           {
               out_drv_imp_cntl = 0x80;
           }
           rc_num = rc_num | address_16.insert((uint8_t) out_drv_imp_cntl, 1, 2, 0);
	   break;
       case ATTR_VPD_DRAM_RTT_NOM:
	   if (dram_rtt_nom == ENUM_ATTR_VPD_DRAM_RTT_NOM_DISABLE)
           {
               dram_rtt_nom = 0x00;
           }
           else if (dram_rtt_nom == ENUM_ATTR_VPD_DRAM_RTT_NOM_OHM240) //not supported
           {
               dram_rtt_nom = 0x20;
           }
           else if (dram_rtt_nom == ENUM_ATTR_VPD_DRAM_RTT_NOM_OHM48) //not supported
           {
               dram_rtt_nom = 0xA0;
           }
           else if (dram_rtt_nom == ENUM_ATTR_VPD_DRAM_RTT_NOM_OHM40)
           {
               dram_rtt_nom = 0xC0;
           }
           else if (dram_rtt_nom == ENUM_ATTR_VPD_DRAM_RTT_NOM_OHM60)
           {
               dram_rtt_nom = 0x80;
           }
           else if (dram_rtt_nom == ENUM_ATTR_VPD_DRAM_RTT_NOM_OHM120)
           {
               dram_rtt_nom = 0x40;
           }
           else if (dram_rtt_nom == ENUM_ATTR_VPD_DRAM_RTT_NOM_OHM80) // not supported
           {
               dram_rtt_nom = 0x60;
           }
           else if (dram_rtt_nom == ENUM_ATTR_VPD_DRAM_RTT_NOM_OHM34) // not supported
           {
               dram_rtt_nom = 0xE0;
           }
	   
           rc_num = rc_num | address_16.insert((uint8_t) dram_rtt_nom, 8, 3, 0);
	   break;
       case ATTR_EFF_DRAM_AL:
	   if (dram_al == ENUM_ATTR_EFF_DRAM_AL_DISABLE)
           {
               dram_al = 0x00;
           }
           else if (dram_al == ENUM_ATTR_EFF_DRAM_AL_CL_MINUS_1)
           {
               dram_al = 0x80;
           }
           else if (dram_al == ENUM_ATTR_EFF_DRAM_AL_CL_MINUS_2)
           {
               dram_al = 0x40;
           }
           rc_num = rc_num | address_16.insert((uint8_t) dram_al, 3, 2, 0);
	   break;
       case ATTR_EFF_DRAM_WR_LVL_ENABLE:
	   if (wr_lvl == ENUM_ATTR_EFF_DRAM_WR_LVL_ENABLE_DISABLE)
           {
               wr_lvl = 0x00;
           }
           else if (wr_lvl == ENUM_ATTR_EFF_DRAM_WR_LVL_ENABLE_ENABLE)
           {
               wr_lvl = 0xFF;
           }
           rc_num = rc_num | address_16.insert((uint8_t) wr_lvl, 7, 1, 0);
	   break;
       case ATTR_EFF_DRAM_TDQS:
	   if (tdqs_enable == ENUM_ATTR_EFF_DRAM_TDQS_DISABLE)
           {
               tdqs_enable = 0x00;
           }
           else if (tdqs_enable == ENUM_ATTR_EFF_DRAM_TDQS_ENABLE)
           {
               tdqs_enable = 0xFF;
           }
           rc_num = rc_num | address_16.insert((uint8_t) tdqs_enable, 11, 1, 0);
	   break;
       case ATTR_EFF_DRAM_OUTPUT_BUFFER:
           if (q_off == ENUM_ATTR_EFF_DRAM_OUTPUT_BUFFER_DISABLE)
           {
               q_off = 0xFF;
           }
           else if (q_off == ENUM_ATTR_EFF_DRAM_OUTPUT_BUFFER_ENABLE)
           {
               q_off = 0x00;
           }
           rc_num = rc_num | address_16.insert((uint8_t) q_off, 12, 1, 0);
	   break;
       case ATTR_EFF_DRAM_LPASR:
           if (lpasr == ENUM_ATTR_EFF_DRAM_LPASR_MANUAL_NORMAL)
           {
               lpasr = 0x00;
           }
           else if (lpasr == ENUM_ATTR_EFF_DRAM_LPASR_MANUAL_REDUCED)
           {
               lpasr = 0x80;
           }
           else if (lpasr == ENUM_ATTR_EFF_DRAM_LPASR_MANUAL_EXTENDED)
           {
               lpasr = 0x40;
           }
           else if (lpasr == ENUM_ATTR_EFF_DRAM_LPASR_ASR)
           {
               lpasr = 0xFF;
           }
           rc_num = rc_num | address_16.insert((uint8_t) lpasr, 6, 2);
	   break;
       case ATTR_EFF_DRAM_CWL:
	   if ((cwl > 8)&&(cwl < 13))
           {
               cwl = cwl - 9; 
           }
           else if ((cwl > 13)&&(cwl < 19))
           {
               cwl = (cwl >> 1) - 3;   
           }
           else
           {
              //no correcct value for CWL was found
              FAPI_INF("ERROR: Improper CWL value found. Setting CWL to 9 and continuing...");
              cwl = 0;
           }
	   cwl = mss_reverse_8bits(cwl);
	   rc_num = rc_num | address_16.insert((uint8_t) cwl, 3, 3);
	   break;
       case ATTR_VPD_DRAM_RTT_WR:
	   if (dram_rtt_wr == ENUM_ATTR_VPD_DRAM_RTT_WR_DISABLE)
           {
               dram_rtt_wr = 0x00;
           }
           else if (dram_rtt_wr == ENUM_ATTR_VPD_DRAM_RTT_WR_OHM120)
           {
               dram_rtt_wr = 0x80;
           }
           else if (dram_rtt_wr == 240)//ENUM_ATTR_EFF_DRAM_RTT_WR_OHM240)
           {
               dram_rtt_wr = 0x40;
           }
           else if (dram_rtt_wr == 0xFF)//ENUM_ATTR_EFF_DRAM_RTT_WR_HIGHZ)
           {
               dram_rtt_wr = 0xFF;
           }
           rc_num = rc_num | address_16.insert((uint8_t) dram_rtt_wr, 9, 2);
           break;
       case ATTR_EFF_WRITE_CRC:
	   if ( write_crc == ENUM_ATTR_EFF_WRITE_CRC_ENABLE)
           {
               write_crc = 0xFF;
           }
           else if (write_crc == ENUM_ATTR_EFF_WRITE_CRC_DISABLE)
           {
               write_crc = 0x00;
           }
           rc_num = rc_num | address_16.insert((uint8_t) write_crc, 12, 1);
	   break;
       case ATTR_EFF_MPR_MODE:
	   if (mpr_op == ENUM_ATTR_EFF_MPR_MODE_ENABLE)
           {
               mpr_op = 0xFF;
           }
           else if (mpr_op == ENUM_ATTR_EFF_MPR_MODE_DISABLE)
           {
               mpr_op = 0x00;
           }
           rc_num = rc_num | address_16.insert((uint8_t) mpr_op, 2, 1);
	   break;
       case ATTR_EFF_MPR_PAGE:
           mpr_page = mss_reverse_8bits(mpr_page);
    	   rc_num = rc_num | address_16.insert((uint8_t) mpr_page, 0, 2);
	   break;
       case ATTR_EFF_GEARDOWN_MODE:
	   if ( geardown_mode == ENUM_ATTR_EFF_GEARDOWN_MODE_HALF)
           {
        	geardown_mode = 0x00;
           }
           else if ( geardown_mode == ENUM_ATTR_EFF_GEARDOWN_MODE_QUARTER)
           {
        	geardown_mode = 0xFF;
           }
           
           if (temp_readout == ENUM_ATTR_EFF_TEMP_READOUT_ENABLE)
           {
               temp_readout = 0xFF;
           }
           else if (temp_readout == ENUM_ATTR_EFF_TEMP_READOUT_DISABLE)
           {
               temp_readout = 0x00;
           }
           rc_num = rc_num | address_16.insert((uint8_t) geardown_mode, 3, 1);
	   break;
       case ATTR_EFF_TEMP_READOUT:
	   if (temp_readout == ENUM_ATTR_EFF_TEMP_READOUT_ENABLE)
    	   {
    	       temp_readout = 0xFF;
    	   }
    	   else if (temp_readout == ENUM_ATTR_EFF_TEMP_READOUT_DISABLE)
    	   {
    	       temp_readout = 0x00;
    	   }
           rc_num = rc_num | address_16.insert((uint8_t) temp_readout, 5, 1);
	   break;
       case ATTR_EFF_FINE_REFRESH_MODE:
	   if (fine_refresh == ENUM_ATTR_EFF_FINE_REFRESH_MODE_NORMAL)
           {
               fine_refresh = 0x00;
           }
           else if (fine_refresh == ENUM_ATTR_EFF_FINE_REFRESH_MODE_FIXED_2X)
           {
               fine_refresh = 0x80;
           }
           else if (fine_refresh == ENUM_ATTR_EFF_FINE_REFRESH_MODE_FIXED_4X)
           {
               fine_refresh = 0x40;
           }
           else if (fine_refresh == ENUM_ATTR_EFF_FINE_REFRESH_MODE_FLY_2X)
           {
               fine_refresh = 0xA0;
           }
           else if (fine_refresh == ENUM_ATTR_EFF_FINE_REFRESH_MODE_FLY_4X)
           {
               fine_refresh = 0x60;
           }
           rc_num = rc_num | address_16.insert((uint8_t) fine_refresh, 6, 3);
	   break;
       case ATTR_EFF_CRC_WR_LATENCY:
           if (wr_latency == ENUM_ATTR_EFF_CRC_WR_LATENCY_4NCK)
           {
               wr_latency = 0x00;
           }
           else if (wr_latency == ENUM_ATTR_EFF_CRC_WR_LATENCY_5NCK)
           {
               wr_latency = 0x80;
           }
           else if (wr_latency == ENUM_ATTR_EFF_CRC_WR_LATENCY_6NCK)
           {
               wr_latency = 0xC0;
           }
           rc_num = rc_num | address_16.insert((uint8_t) wr_latency, 9, 2);
	   break;
       case ATTR_EFF_MPR_RD_FORMAT:
           if (read_format == ENUM_ATTR_EFF_MPR_RD_FORMAT_SERIAL)
           {
               read_format = 0x00;
           }
           else if (read_format == ENUM_ATTR_EFF_MPR_RD_FORMAT_PARALLEL)
           {
               read_format = 0x80;
           }
           else if (read_format == ENUM_ATTR_EFF_MPR_RD_FORMAT_STAGGERED)
           {
               read_format = 0x40;
           }
           else if (read_format == ENUM_ATTR_EFF_MPR_RD_FORMAT_RESERVED_TEMP)
           {
               read_format = 0xC0;
           }
           rc_num = rc_num | address_16.insert((uint8_t) read_format, 11, 2);
	   break;
       case ATTR_EFF_PER_DRAM_ACCESS:
           FAPI_INF("ERROR: ATTR_EFF_PER_DRAM_ACCESS selected.  Forcing PDA to be on for this function");
	   dram_access = 0xFF;
	   rc_num = rc_num | address_16.insert((uint8_t) dram_access, 4, 1);
	   break;
       case ATTR_EFF_MAX_POWERDOWN_MODE:
	   if ( max_pd_mode == ENUM_ATTR_EFF_MAX_POWERDOWN_MODE_ENABLE)
           {
               max_pd_mode = 0xF0;
           }
           else if ( max_pd_mode == ENUM_ATTR_EFF_MAX_POWERDOWN_MODE_DISABLE)
           {
               max_pd_mode = 0x00;
           }
           rc_num = rc_num | address_16.insert((uint8_t) max_pd_mode, 1, 1);
	   break;
       case ATTR_EFF_TEMP_REF_RANGE:
	   if (temp_ref_range == ENUM_ATTR_EFF_TEMP_REF_RANGE_NORMAL)
           {
               temp_ref_range = 0x00;
           }
           else if ( temp_ref_range== ENUM_ATTR_EFF_TEMP_REF_RANGE_EXTEND)
           {
               temp_ref_range = 0xFF;
           }
           rc_num = rc_num | address_16.insert((uint8_t) temp_ref_range, 2, 1);
	   break;
       case ATTR_EFF_TEMP_REF_MODE:
	   if (temp_ref_mode == ENUM_ATTR_EFF_TEMP_REF_MODE_ENABLE)
           {
               temp_ref_mode = 0x80;
           }
           else if (temp_ref_mode == ENUM_ATTR_EFF_TEMP_REF_MODE_DISABLE)
           {
               temp_ref_mode = 0x00;
           }
           rc_num = rc_num | address_16.insert((uint8_t) temp_ref_mode, 3, 1);
	   break;
       case ATTR_EFF_INT_VREF_MON:
	   if ( vref_mon == ENUM_ATTR_EFF_INT_VREF_MON_ENABLE)
           {
               vref_mon = 0xFF;
           }
           else if ( vref_mon == ENUM_ATTR_EFF_INT_VREF_MON_DISABLE)
           {
               vref_mon = 0x00;
           }
           rc_num = rc_num | address_16.insert((uint8_t) vref_mon, 4, 1);
	   break;
       case ATTR_EFF_CS_CMD_LATENCY:
	   if ( cs_cmd_latency == 3)
           {
               cs_cmd_latency = 0x80;
           }
           else if (cs_cmd_latency == 4)
           {
               cs_cmd_latency = 0x40;
           }
           else if (cs_cmd_latency == 5)
           {
               cs_cmd_latency = 0xC0;
           }
           else if (cs_cmd_latency == 6)
           {
               cs_cmd_latency = 0x20;
           }
           else if (cs_cmd_latency == 8)
           {
               cs_cmd_latency = 0xA0;
           }
           rc_num = rc_num | address_16.insert((uint8_t) cs_cmd_latency, 6, 3);
	   break;
       case ATTR_EFF_SELF_REF_ABORT:
	   if (ref_abort == ENUM_ATTR_EFF_SELF_REF_ABORT_ENABLE)
           {
               ref_abort = 0xFF;
           }
           else if (ref_abort == ENUM_ATTR_EFF_SELF_REF_ABORT_DISABLE)
           {
               ref_abort = 0x00;
           }
           rc_num = rc_num | address_16.insert((uint8_t) ref_abort, 9, 1);
	   break;
       case ATTR_EFF_RD_PREAMBLE_TRAIN:
	   if (rd_pre_train_mode == ENUM_ATTR_EFF_RD_PREAMBLE_TRAIN_ENABLE)
           {
               rd_pre_train_mode = 0xFF;
           }
           else if (rd_pre_train_mode == ENUM_ATTR_EFF_RD_PREAMBLE_TRAIN_DISABLE)
           {
               rd_pre_train_mode = 0x00;
           }
           rc_num = rc_num | address_16.insert((uint8_t) rd_pre_train_mode, 10, 1);
	   break;
       case ATTR_EFF_RD_PREAMBLE:
	   if (rd_preamble == ENUM_ATTR_EFF_RD_PREAMBLE_1NCLK)
           {
               rd_preamble = 0x00;
           }
           else if (rd_preamble == ENUM_ATTR_EFF_RD_PREAMBLE_2NCLK)
           {
               rd_preamble = 0xFF;
           }
           rc_num = rc_num | address_16.insert((uint8_t) rd_preamble, 11, 1);
	   break;
       case ATTR_EFF_WR_PREAMBLE:
           if (wr_preamble == ENUM_ATTR_EFF_WR_PREAMBLE_1NCLK)
           {
               wr_preamble = 0x00;
           }
           else if (wr_preamble == ENUM_ATTR_EFF_WR_PREAMBLE_2NCLK)
           {
               wr_preamble = 0xFF;
           }
           rc_num = rc_num | address_16.insert((uint8_t) wr_preamble, 12, 1);
	   break;
       case ATTR_EFF_CA_PARITY_LATENCY:
	   if (ca_parity_latency == 4)
           {
               ca_parity_latency = 0x80;
           }
           else if (ca_parity_latency == 5)
           {
               ca_parity_latency = 0x40;
           }
           else if (ca_parity_latency == 6)
           {
               ca_parity_latency = 0xC0;
           }
           else if (ca_parity_latency == 8)
           {
               ca_parity_latency = 0x20;
           }
           else if (ca_parity_latency == ENUM_ATTR_EFF_CA_PARITY_LATENCY_DISABLE)
           {
               ca_parity_latency = 0x00;
           }
           rc_num = rc_num | address_16.insert((uint8_t) ca_parity_latency, 0, 2);
	   break;
       case ATTR_EFF_CRC_ERROR_CLEAR:
	   if (crc_error_clear == ENUM_ATTR_EFF_CRC_ERROR_CLEAR_ERROR)
           {
               crc_error_clear = 0xFF;
           }
           else if (crc_error_clear == ENUM_ATTR_EFF_CRC_ERROR_CLEAR_CLEAR)
           {
               crc_error_clear = 0x00;
           }
           rc_num = rc_num | address_16.insert((uint8_t) crc_error_clear, 3, 1);
	   break;
       case ATTR_EFF_CA_PARITY_ERROR_STATUS:
	   if (ca_parity_error_status == ENUM_ATTR_EFF_CA_PARITY_ERROR_STATUS_ERROR)
           {
               ca_parity_error_status = 0xFF;
           }
           else if (ca_parity_error_status == ENUM_ATTR_EFF_CA_PARITY_ERROR_STATUS_CLEAR)
           {
               ca_parity_error_status = 0x00;
           }
           rc_num = rc_num | address_16.insert((uint8_t) ca_parity_error_status, 4, 1);
	   break;
       case ATTR_EFF_ODT_INPUT_BUFF:
	   if (odt_input_buffer == ENUM_ATTR_EFF_ODT_INPUT_BUFF_ACTIVATED)
           {
               odt_input_buffer = 0x00;
           }
           else if (odt_input_buffer == ENUM_ATTR_EFF_ODT_INPUT_BUFF_DEACTIVATED)
           {
               odt_input_buffer = 0xFF;
           }
           rc_num = rc_num | address_16.insert((uint8_t) odt_input_buffer, 5, 1);
	   break;
       case ATTR_EFF_RTT_PARK:
	   if (rtt_park == ENUM_ATTR_EFF_RTT_PARK_DISABLE)
           {
               rtt_park = 0x00;
           }
           else if (rtt_park == ENUM_ATTR_EFF_RTT_PARK_60OHM)
           {
               rtt_park = 0x80;
           }
           else if (rtt_park == ENUM_ATTR_EFF_RTT_PARK_40OHM)
           {
               rtt_park = 0xC0;
           }
           else if (rtt_park == ENUM_ATTR_EFF_RTT_PARK_120OHM)
           {
               rtt_park = 0x40;
           }
           else if (rtt_park == ENUM_ATTR_EFF_RTT_PARK_240OHM)
           {
               rtt_park = 0x20;
           }
           else if (rtt_park == ENUM_ATTR_EFF_RTT_PARK_48OHM)
           {
               rtt_park = 0xA0;
           }
           else if (rtt_park == ENUM_ATTR_EFF_RTT_PARK_80OHM)
           {
               rtt_park = 0x60;
           }
           else if (rtt_park == ENUM_ATTR_EFF_RTT_PARK_34OHM)
           {
               rtt_park = 0xE0;
           }
           rc_num = rc_num | address_16.insert((uint8_t) rtt_park, 6, 3);
	   break;
       case ATTR_EFF_CA_PARITY:
	   if (ca_parity == ENUM_ATTR_EFF_CA_PARITY_ENABLE)
           {
               ca_parity = 0xFF;
           }
           else if (ca_parity == ENUM_ATTR_EFF_CA_PARITY_DISABLE)
           {
               ca_parity = 0x00;
           }
           rc_num = rc_num | address_16.insert((uint8_t) ca_parity, 9, 1);
	   break;
       case ATTR_EFF_DATA_MASK:
	   if (data_mask == ENUM_ATTR_EFF_DATA_MASK_DISABLE)
           {
               data_mask = 0x00;
           }
           else if (data_mask == ENUM_ATTR_EFF_DATA_MASK_ENABLE)
           {
               data_mask = 0xFF;
           }
           rc_num = rc_num | address_16.insert((uint8_t) data_mask, 10, 1);
	   break;
       case ATTR_EFF_WRITE_DBI:
	   if (write_dbi == ENUM_ATTR_EFF_WRITE_DBI_DISABLE)
           {
               write_dbi = 0x00;
           }
           else if (write_dbi == ENUM_ATTR_EFF_WRITE_DBI_ENABLE)
           {
               write_dbi = 0xFF;
           }
           rc_num = rc_num | address_16.insert((uint8_t) write_dbi, 11, 1);
	   break;
       case ATTR_EFF_READ_DBI:
           if (read_dbi == ENUM_ATTR_EFF_READ_DBI_DISABLE)
           {
               read_dbi = 0x00;
           }
           else if (read_dbi == ENUM_ATTR_EFF_READ_DBI_ENABLE)
           {
               read_dbi = 0xFF;
           }
           rc_num = rc_num | address_16.insert((uint8_t) read_dbi, 12, 1);
	   break;
       case ATTR_VREF_DQ_TRAIN_VALUE:
	   vrefdq_train_value = mss_reverse_8bits(vrefdq_train_value);
           rc_num = rc_num | address_16.insert((uint8_t) vrefdq_train_value, 0, 6);
	   break;
       case ATTR_VREF_DQ_TRAIN_RANGE:
	   if (vrefdq_train_range == ENUM_ATTR_VREF_DQ_TRAIN_RANGE_RANGE1)
           {
               vrefdq_train_range = 0x00;
           }
           else if (vrefdq_train_range == ENUM_ATTR_VREF_DQ_TRAIN_RANGE_RANGE2)
           {
               vrefdq_train_range = 0xFF;
           } 
           rc_num = rc_num | address_16.insert((uint8_t) vrefdq_train_range, 6, 1);
	   break;
       case ATTR_VREF_DQ_TRAIN_ENABLE:
	   if (vrefdq_train_enable == ENUM_ATTR_VREF_DQ_TRAIN_ENABLE_ENABLE)
           {
               vrefdq_train_enable = 0xFF;
           }
           else if (vrefdq_train_enable == ENUM_ATTR_VREF_DQ_TRAIN_ENABLE_DISABLE)
           {
               vrefdq_train_enable = 0x00;
           }   
           rc_num = rc_num | address_16.insert((uint8_t) vrefdq_train_enable, 7, 1);
	   break;
       case ATTR_TCCD_L:
           if (tccd_l == 4)
           {
               tccd_l = 0x00;
           }
           else if (tccd_l == 5)
           {
               tccd_l = 0x80;
           }
           else if (tccd_l == 6)
           {
               tccd_l = 0x40;
           }	
           else if (tccd_l == 7)
           {
               tccd_l = 0xC0;
           }
           else if (tccd_l == 8)
           {
               tccd_l = 0x20;
           }
           rc_num = rc_num | address_16.insert((uint8_t) tccd_l, 10, 3);
	   break;
	//MRS attribute not found, error out
      default: 
         const uint32_t NONMRS_ATTR_NAME = attribute_name;
	 const fapi::Target & MBA_TARGET = i_target; 
	 FAPI_SET_HWP_ERROR(rc, RC_MSS_PDA_NONMRS_ATTR_NAME);
	 FAPI_ERR("ERROR!! Found attribute name not associated with an MRS! Exiting...");
   }
   if (rc_num)
   {
       FAPI_ERR( "mss_ddr4_modify_mrs_pda: Error setting up buffers");
       rc.setEcmdError(rc_num);
       return rc;
   }
   return rc;
}

//////////////////////////////////////////////////////////////////////////////////
/// mss_ddr4_load_nominal_mrs_pda
/// disables per-DRAM addressability funcitonality on both ports on the passed MBA
//////////////////////////////////////////////////////////////////////////////////
ReturnCode mss_ddr4_load_nominal_mrs_pda(Target& i_target,ecmdDataBufferBase& bank_3,ecmdDataBufferBase& address_16,uint8_t MRS,uint8_t i_port_number, uint8_t dimm_number, uint8_t rank_number) {
    ReturnCode rc;  
    ReturnCode rc_buff;
    uint32_t rc_num = 0;
    
    rc_num = rc_num | address_16.clearBit(0,16);
    rc_num = rc_num | bank_3.clearBit(0,3);
    if (rc_num)
    {
    	FAPI_ERR( "mss_mrs_load: Error setting up buffers");
    	rc_buff.setEcmdError(rc_num);
    	return rc_buff;
    }

    //Lines commented out in the following section are waiting for xml attribute adds
    //MRS0
    if(MRS == MRS0_BA) {
    	uint8_t dram_bl;
    	rc = FAPI_ATTR_GET(ATTR_EFF_DRAM_BL, &i_target, dram_bl);
    	if(rc) return rc;
    	uint8_t read_bt; //Read Burst Type 
    	rc = FAPI_ATTR_GET(ATTR_EFF_DRAM_RBT, &i_target, read_bt);
    	if(rc) return rc;
    	uint8_t dram_cl;
    	rc = FAPI_ATTR_GET(ATTR_EFF_DRAM_CL, &i_target, dram_cl);
    	if(rc) return rc;
    	uint8_t test_mode; //TEST MODE 
    	rc = FAPI_ATTR_GET(ATTR_EFF_DRAM_TM, &i_target, test_mode);
    	if(rc) return rc;
    	uint8_t dll_reset; //DLL Reset 
    	rc = FAPI_ATTR_GET(ATTR_EFF_DRAM_DLL_RESET, &i_target, dll_reset);
    	if(rc) return rc;
    	uint8_t dram_wr; //DRAM write recovery
    	rc = FAPI_ATTR_GET(ATTR_EFF_DRAM_WR, &i_target, dram_wr);
    	if(rc) return rc;
    	uint8_t dram_rtp; //DRAM RTP - read to precharge
    	rc = FAPI_ATTR_GET(ATTR_EFF_DRAM_TRTP, &i_target, dram_rtp);
    	if(rc) return rc;
    	uint8_t dll_precharge; //DLL Control For Precharge 
    	rc = FAPI_ATTR_GET(ATTR_EFF_DRAM_DLL_PPD, &i_target, dll_precharge);
    	if(rc) return rc;

    	if (dram_bl == ENUM_ATTR_EFF_DRAM_BL_BL8)
    	{
    	    dram_bl = 0x00;
    	}
    	else if (dram_bl == ENUM_ATTR_EFF_DRAM_BL_OTF)
    	{
    	    dram_bl = 0x80;
    	}
    	else if (dram_bl == ENUM_ATTR_EFF_DRAM_BL_BC4)
    	{
    	    dram_bl = 0x40;
    	}

    	uint8_t dram_wr_rtp = 0x00;
    	if ( (dram_wr == 10) )//&& (dram_rtp == 5) )
    	{
    	    dram_wr_rtp = 0x00;
    	}
    	else if ( (dram_wr == 12) )//&& (dram_rtp == 6) )
    	{
    	    dram_wr_rtp = 0x80;
    	}
    	else if ( (dram_wr == 13) )//&& (dram_rtp == 7) )
    	{
    	    dram_wr_rtp = 0x40;
    	}
    	else if ( (dram_wr == 14) )//&& (dram_rtp == 8) )
    	{
    	    dram_wr_rtp = 0xC0;
    	}
    	else if ( (dram_wr == 18) )//&& (dram_rtp == 9) )
    	{
    	    dram_wr_rtp = 0x20;
    	}
    	else if ( (dram_wr == 20) )//&& (dram_rtp == 10) )
    	{
    	    dram_wr_rtp = 0xA0;
    	}
    	else if ( (dram_wr == 24) )//&& (dram_rtp == 12) )
    	{
    	    dram_wr_rtp = 0x60;
    	}

    	if (read_bt == ENUM_ATTR_EFF_DRAM_RBT_SEQUENTIAL)
    	{
    	    read_bt = 0x00;
    	}
    	else if (read_bt == ENUM_ATTR_EFF_DRAM_RBT_INTERLEAVE)
    	{
    	    read_bt = 0xFF;
    	}

    	if ((dram_cl > 8)&&(dram_cl < 17))
    	{
    	    dram_cl = dram_cl - 9; 
    	}
    	else if ((dram_cl > 17)&&(dram_cl < 25))
    	{
    	    dram_cl = (dram_cl >> 1) - 1;   
    	}
    	dram_cl = mss_reverse_8bits(dram_cl);

    	if (test_mode == ENUM_ATTR_EFF_DRAM_TM_NORMAL)
    	{
    	    test_mode = 0x00;
    	}
    	else if (test_mode == ENUM_ATTR_EFF_DRAM_TM_TEST)
    	{
    	    test_mode = 0xFF;
    	}
	
	FAPI_INF("Overwriting DLL reset with values to not reset the DRAM.");
    	dll_reset = 0x00;

    	if (dll_precharge == ENUM_ATTR_EFF_DRAM_DLL_PPD_SLOWEXIT)
    	{
    	    dll_precharge = 0x00;
    	}
    	else if (dll_precharge == ENUM_ATTR_EFF_DRAM_DLL_PPD_FASTEXIT)
    	{
    	    dll_precharge = 0xFF;
    	}
	//For DDR4:
	//Address 14 = Address 17, Address 15 = BG1
        rc_num = rc_num | address_16.insert((uint8_t) dram_bl, 0, 2, 0);
        rc_num = rc_num | address_16.insert((uint8_t) dram_cl, 2, 1, 0);
        rc_num = rc_num | address_16.insert((uint8_t) read_bt, 3, 1, 0);
        rc_num = rc_num | address_16.insert((uint8_t) dram_cl, 4, 3, 1);
        rc_num = rc_num | address_16.insert((uint8_t) test_mode, 7, 1);
        rc_num = rc_num | address_16.insert((uint8_t) dll_reset, 8, 1);
	rc_num = rc_num | address_16.insert((uint8_t) dram_wr_rtp, 9, 3);
	rc_num = rc_num | address_16.insert((uint8_t) 0x00, 12, 4);
	
	rc_num = rc_num | bank_3.insert((uint8_t) MRS0_BA, 0, 1, 7);
        rc_num = rc_num | bank_3.insert((uint8_t) MRS0_BA, 1, 1, 6);
        rc_num = rc_num | bank_3.insert((uint8_t) MRS0_BA, 2, 1, 5);
	if (rc_num)
        {
            FAPI_ERR( "mss_mrs_load: Error setting up buffers");
            rc_buff.setEcmdError(rc_num);
            return rc_buff;
        }
    }
    
    //MRS1
    else if(MRS == MRS1_BA) {
    	uint8_t dll_enable; //DLL Enable 
    	rc = FAPI_ATTR_GET(ATTR_EFF_DRAM_DLL_ENABLE, &i_target, dll_enable);
    	if(rc) return rc;
    	uint8_t out_drv_imp_cntl[2][2];
    	rc = FAPI_ATTR_GET(ATTR_VPD_DRAM_RON, &i_target, out_drv_imp_cntl);
    	if(rc) return rc;
    	uint8_t dram_rtt_nom[2][2][4];
    	rc = FAPI_ATTR_GET(ATTR_VPD_DRAM_RTT_NOM, &i_target, dram_rtt_nom);
    	if(rc) return rc;
    	uint8_t dram_al;
    	rc = FAPI_ATTR_GET(ATTR_EFF_DRAM_AL, &i_target, dram_al);
    	if(rc) return rc;
    	uint8_t wr_lvl; //write leveling enable
    	rc = FAPI_ATTR_GET(ATTR_EFF_DRAM_WR_LVL_ENABLE, &i_target, wr_lvl);
    	if(rc) return rc;
    	uint8_t tdqs_enable; //TDQS Enable 
    	rc = FAPI_ATTR_GET(ATTR_EFF_DRAM_TDQS, &i_target, tdqs_enable);
    	if(rc) return rc;
    	uint8_t q_off; //Qoff - Output buffer Enable 
    	rc = FAPI_ATTR_GET(ATTR_EFF_DRAM_OUTPUT_BUFFER, &i_target, q_off);
    	if(rc) return rc;

    	if (dll_enable == ENUM_ATTR_EFF_DRAM_DLL_ENABLE_DISABLE)
    	{
    	    dll_enable = 0x00;
    	}
    	else if (dll_enable == ENUM_ATTR_EFF_DRAM_DLL_ENABLE_ENABLE)
    	{
    	    dll_enable = 0xFF;
    	}

    	if (dram_al == ENUM_ATTR_EFF_DRAM_AL_DISABLE)
    	{
    	    dram_al = 0x00;
    	}
    	else if (dram_al == ENUM_ATTR_EFF_DRAM_AL_CL_MINUS_1)
    	{
    	    dram_al = 0x80;
    	}
    	else if (dram_al == ENUM_ATTR_EFF_DRAM_AL_CL_MINUS_2)
    	{
    	    dram_al = 0x40;
    	}

    	if (wr_lvl == ENUM_ATTR_EFF_DRAM_WR_LVL_ENABLE_DISABLE)
    	{
    	    wr_lvl = 0x00;
    	}
    	else if (wr_lvl == ENUM_ATTR_EFF_DRAM_WR_LVL_ENABLE_ENABLE)
    	{
    	    wr_lvl = 0xFF;
    	}

    	if (tdqs_enable == ENUM_ATTR_EFF_DRAM_TDQS_DISABLE)
    	{
    	    tdqs_enable = 0x00;
    	}
    	else if (tdqs_enable == ENUM_ATTR_EFF_DRAM_TDQS_ENABLE)
    	{
    	    tdqs_enable = 0xFF;
    	}

    	if (q_off == ENUM_ATTR_EFF_DRAM_OUTPUT_BUFFER_DISABLE)
    	{
    	    q_off = 0xFF;
    	}
    	else if (q_off == ENUM_ATTR_EFF_DRAM_OUTPUT_BUFFER_ENABLE)
    	{
    	    q_off = 0x00;
    	}
        if (dram_rtt_nom[i_port_number][dimm_number][rank_number] == ENUM_ATTR_VPD_DRAM_RTT_NOM_DISABLE)
        {
            dram_rtt_nom[i_port_number][dimm_number][rank_number] = 0x00;
        }
        else if (dram_rtt_nom[i_port_number][dimm_number][rank_number] == ENUM_ATTR_VPD_DRAM_RTT_NOM_OHM240) //not supported
        {
            dram_rtt_nom[i_port_number][dimm_number][rank_number] = 0x20;
        }
        else if (dram_rtt_nom[i_port_number][dimm_number][rank_number] == ENUM_ATTR_VPD_DRAM_RTT_NOM_OHM48) //not supported
        {
            dram_rtt_nom[i_port_number][dimm_number][rank_number] = 0xA0;
        }
        else if (dram_rtt_nom[i_port_number][dimm_number][rank_number] == ENUM_ATTR_VPD_DRAM_RTT_NOM_OHM40)
        {
            dram_rtt_nom[i_port_number][dimm_number][rank_number] = 0xC0;
        }
        else if (dram_rtt_nom[i_port_number][dimm_number][rank_number] == ENUM_ATTR_VPD_DRAM_RTT_NOM_OHM60)
        {
            dram_rtt_nom[i_port_number][dimm_number][rank_number] = 0x80;
        }
        else if (dram_rtt_nom[i_port_number][dimm_number][rank_number] == ENUM_ATTR_VPD_DRAM_RTT_NOM_OHM120)
        {
            dram_rtt_nom[i_port_number][dimm_number][rank_number] = 0x40;
        }
        else if (dram_rtt_nom[i_port_number][dimm_number][rank_number] == ENUM_ATTR_VPD_DRAM_RTT_NOM_OHM80) // not supported
        {
            dram_rtt_nom[i_port_number][dimm_number][rank_number] = 0x60;
        }
        else if (dram_rtt_nom[i_port_number][dimm_number][rank_number] == ENUM_ATTR_VPD_DRAM_RTT_NOM_OHM34) // not supported
        {
            dram_rtt_nom[i_port_number][dimm_number][rank_number] = 0xE0;
        }

        if (out_drv_imp_cntl[i_port_number][dimm_number] == ENUM_ATTR_VPD_DRAM_RON_OHM34)
        {
            out_drv_imp_cntl[i_port_number][dimm_number] = 0x00;
        }
	// Not currently supported
        else if (out_drv_imp_cntl[i_port_number][dimm_number] == ENUM_ATTR_VPD_DRAM_RON_OHM48) //not supported
        {
            out_drv_imp_cntl[i_port_number][dimm_number] = 0x80;
        }

	//For DDR4:
	//Address 14 = Address 17, Address 15 = BG1
        rc_num = rc_num | address_16.insert((uint8_t) dll_enable, 0, 1, 0);
        rc_num = rc_num | address_16.insert((uint8_t) out_drv_imp_cntl[i_port_number][dimm_number], 1, 2, 0);
        rc_num = rc_num | address_16.insert((uint8_t) dram_al, 3, 2, 0);
        rc_num = rc_num | address_16.insert((uint8_t) 0x00, 5, 2);
        rc_num = rc_num | address_16.insert((uint8_t) wr_lvl, 7, 1, 0);
        rc_num = rc_num | address_16.insert((uint8_t) dram_rtt_nom[i_port_number][dimm_number][rank_number], 8, 3, 0);
        rc_num = rc_num | address_16.insert((uint8_t) tdqs_enable, 11, 1, 0);
        rc_num = rc_num | address_16.insert((uint8_t) q_off, 12, 1, 0);
        rc_num = rc_num | address_16.insert((uint8_t) 0x00, 13, 3);
	
	rc_num = rc_num | bank_3.insert((uint8_t) MRS1_BA, 0, 1, 7);
        rc_num = rc_num | bank_3.insert((uint8_t) MRS1_BA, 1, 1, 6);
        rc_num = rc_num | bank_3.insert((uint8_t) MRS1_BA, 2, 1, 5);
	if (rc_num)
        {
            FAPI_ERR( "mss_mrs_load: Error setting up buffers");
            rc_buff.setEcmdError(rc_num);
            return rc_buff;
        }
    }
    //MRS2
    else if(MRS == MRS2_BA) {
    	uint8_t lpasr; // Low Power Auto Self-Refresh -- new not yet supported
    	rc = FAPI_ATTR_GET(ATTR_EFF_DRAM_LPASR, &i_target, lpasr);
    	if(rc) return rc;
    	uint8_t cwl; // CAS Write Latency 
    	rc = FAPI_ATTR_GET(ATTR_EFF_DRAM_CWL, &i_target, cwl);
    	if(rc) return rc;
    	uint8_t dram_rtt_wr[2][2][4];
    	rc = FAPI_ATTR_GET(ATTR_VPD_DRAM_RTT_WR, &i_target, dram_rtt_wr);
    	if(rc) return rc;
    	uint8_t write_crc; // CAS Write Latency 
    	rc = FAPI_ATTR_GET(ATTR_EFF_WRITE_CRC, &i_target, write_crc);
    	if(rc) return rc;

    	if (lpasr == ENUM_ATTR_EFF_DRAM_LPASR_MANUAL_NORMAL)
    	{
    	    lpasr = 0x00;
    	}
    	else if (lpasr == ENUM_ATTR_EFF_DRAM_LPASR_MANUAL_REDUCED)
    	{
    	    lpasr = 0x80;
    	}
    	else if (lpasr == ENUM_ATTR_EFF_DRAM_LPASR_MANUAL_EXTENDED)
    	{
    	    lpasr = 0x40;
    	}
    	else if (lpasr == ENUM_ATTR_EFF_DRAM_LPASR_ASR)
    	{
    	    lpasr = 0xFF;
    	}

    	if ((cwl > 8)&&(cwl < 13))
    	{
    	    cwl = cwl - 9; 
    	}
    	else if ((cwl > 13)&&(cwl < 19))
    	{
    	    cwl = (cwl >> 1) - 3;   
    	}
    	else
    	{
    	   //no correcct value for CWL was found
    	   FAPI_INF("ERROR: Improper CWL value found. Setting CWL to 9 and continuing...");
    	   cwl = 0;
    	}
    	cwl = mss_reverse_8bits(cwl);

    	if ( write_crc == ENUM_ATTR_EFF_WRITE_CRC_ENABLE)
    	{
    	    write_crc = 0xFF;
    	}
    	else if (write_crc == ENUM_ATTR_EFF_WRITE_CRC_DISABLE)
    	{
    	    write_crc = 0x00;
    	}
	if (dram_rtt_wr[i_port_number][dimm_number][rank_number] == ENUM_ATTR_VPD_DRAM_RTT_WR_DISABLE)
        {
            dram_rtt_wr[i_port_number][dimm_number][rank_number] = 0x00;
        }
        else if (dram_rtt_wr[i_port_number][dimm_number][rank_number] == ENUM_ATTR_VPD_DRAM_RTT_WR_OHM120)
        {
            dram_rtt_wr[i_port_number][dimm_number][rank_number] = 0x80;
        }
        else if (dram_rtt_wr[i_port_number][dimm_number][rank_number] == 240)//ENUM_ATTR_EFF_DRAM_RTT_WR_OHM240)
        {
            dram_rtt_wr[i_port_number][dimm_number][rank_number] = 0x40;
        }
        else if (dram_rtt_wr[i_port_number][dimm_number][rank_number] == 0xFF)//ENUM_ATTR_EFF_DRAM_RTT_WR_HIGHZ)
        {
            dram_rtt_wr[i_port_number][dimm_number][rank_number] = 0xFF;
        }

        rc_num = rc_num | address_16.insert((uint8_t) 0x00, 0, 3);
        rc_num = rc_num | address_16.insert((uint8_t) cwl, 3, 3);
        rc_num = rc_num | address_16.insert((uint8_t) lpasr, 6, 2);
        rc_num = rc_num | address_16.insert((uint8_t) 0x00, 8, 1);
        rc_num = rc_num | address_16.insert((uint8_t) dram_rtt_wr[i_port_number][dimm_number][rank_number], 9, 2);
        rc_num = rc_num | address_16.insert((uint8_t) 0x00, 11, 1);
        rc_num = rc_num | address_16.insert((uint8_t) write_crc, 12, 1);
        rc_num = rc_num | address_16.insert((uint8_t) 0x00, 13, 2);
	
	rc_num = rc_num | bank_3.insert((uint8_t) MRS2_BA, 0, 1, 7);
        rc_num = rc_num | bank_3.insert((uint8_t) MRS2_BA, 1, 1, 6);
        rc_num = rc_num | bank_3.insert((uint8_t) MRS2_BA, 2, 1, 5);
	if (rc_num)
        {
            FAPI_ERR( "mss_mrs_load: Error setting up buffers");
            rc_buff.setEcmdError(rc_num);
            return rc_buff;
        }
    }
    //MRS3
    else if(MRS == MRS3_BA) {
    	uint8_t mpr_op; // MPR Op
    	rc = FAPI_ATTR_GET(ATTR_EFF_MPR_MODE, &i_target, mpr_op);
    	if(rc) return rc;
    	uint8_t mpr_page; // MPR Page Selection  - NEW
    	rc = FAPI_ATTR_GET(ATTR_EFF_MPR_PAGE, &i_target, mpr_page);
    	if(rc) return rc;
    	uint8_t geardown_mode; // Gear Down Mode  - NEW
    	rc = FAPI_ATTR_GET(ATTR_EFF_GEARDOWN_MODE, &i_target, geardown_mode);
    	if(rc) return rc;
    	uint8_t temp_readout; // Temperature sensor readout  - NEW
    	rc = FAPI_ATTR_GET(ATTR_EFF_TEMP_READOUT, &i_target, temp_readout);
    	if(rc) return rc;
    	uint8_t fine_refresh; // fine refresh mode  - NEW
    	rc = FAPI_ATTR_GET(ATTR_EFF_FINE_REFRESH_MODE, &i_target, fine_refresh);
    	if(rc) return rc;
    	uint8_t wr_latency; // write latency for CRC and DM  - NEW
    	rc = FAPI_ATTR_GET(ATTR_EFF_CRC_WR_LATENCY, &i_target, wr_latency);
    	if(rc) return rc;
    	uint8_t read_format; // MPR READ FORMAT  - NEW
    	rc = FAPI_ATTR_GET(ATTR_EFF_MPR_RD_FORMAT, &i_target, read_format);
    	if(rc) return rc;

    	if (mpr_op == ENUM_ATTR_EFF_MPR_MODE_ENABLE)
    	{
    	    mpr_op = 0xFF;
    	}
    	else if (mpr_op == ENUM_ATTR_EFF_MPR_MODE_DISABLE)
    	{
    	    mpr_op = 0x00;
    	}

    	mpr_page = mss_reverse_8bits(mpr_page);

    	if ( geardown_mode == ENUM_ATTR_EFF_GEARDOWN_MODE_HALF)
    	{
    	     geardown_mode = 0x00;
    	}
    	else if ( geardown_mode == ENUM_ATTR_EFF_GEARDOWN_MODE_QUARTER)
    	{
    	     geardown_mode = 0xFF;
    	}
    	
    	if (temp_readout == ENUM_ATTR_EFF_TEMP_READOUT_ENABLE)
    	{
    	    temp_readout = 0xFF;
    	}
    	else if (temp_readout == ENUM_ATTR_EFF_TEMP_READOUT_DISABLE)
    	{
    	    temp_readout = 0x00;
    	}

    	if (fine_refresh == ENUM_ATTR_EFF_FINE_REFRESH_MODE_NORMAL)
    	{
    	    fine_refresh = 0x00;
    	}
    	else if (fine_refresh == ENUM_ATTR_EFF_FINE_REFRESH_MODE_FIXED_2X)
    	{
    	    fine_refresh = 0x80;
    	}
    	else if (fine_refresh == ENUM_ATTR_EFF_FINE_REFRESH_MODE_FIXED_4X)
    	{
    	    fine_refresh = 0x40;
    	}
    	else if (fine_refresh == ENUM_ATTR_EFF_FINE_REFRESH_MODE_FLY_2X)
    	{
    	    fine_refresh = 0xA0;
    	}
    	else if (fine_refresh == ENUM_ATTR_EFF_FINE_REFRESH_MODE_FLY_4X)
    	{
    	    fine_refresh = 0x60;
    	}

    	if (wr_latency == ENUM_ATTR_EFF_CRC_WR_LATENCY_4NCK)
    	{
    	    wr_latency = 0x00;
    	}
    	else if (wr_latency == ENUM_ATTR_EFF_CRC_WR_LATENCY_5NCK)
    	{
    	    wr_latency = 0x80;
    	}
    	else if (wr_latency == ENUM_ATTR_EFF_CRC_WR_LATENCY_6NCK)
    	{
    	    wr_latency = 0xC0;
    	}

    	if (read_format == ENUM_ATTR_EFF_MPR_RD_FORMAT_SERIAL)
    	{
    	    read_format = 0x00;
    	}
    	else if (read_format == ENUM_ATTR_EFF_MPR_RD_FORMAT_PARALLEL)
    	{
    	    read_format = 0x80;
    	}
    	else if (read_format == ENUM_ATTR_EFF_MPR_RD_FORMAT_STAGGERED)
    	{
    	    read_format = 0x40;
    	}
    	else if (read_format == ENUM_ATTR_EFF_MPR_RD_FORMAT_RESERVED_TEMP)
    	{
    	    read_format = 0xC0;
    	}
	
	rc_num = rc_num | address_16.insert((uint8_t) mpr_page, 0, 2);
        rc_num = rc_num | address_16.insert((uint8_t) mpr_op, 2, 1);
        rc_num = rc_num | address_16.insert((uint8_t) geardown_mode, 3, 1);
        rc_num = rc_num | address_16.insert((uint8_t) 0xFF, 4, 1); //has PDA mode enabled!!!! just for this code!
        rc_num = rc_num | address_16.insert((uint8_t) temp_readout, 5, 1);
        rc_num = rc_num | address_16.insert((uint8_t) fine_refresh, 6, 3);
        rc_num = rc_num | address_16.insert((uint8_t) wr_latency, 9, 2);
        rc_num = rc_num | address_16.insert((uint8_t) read_format, 11, 2);
        rc_num = rc_num | address_16.insert((uint8_t) 0x00, 13, 2);
	
	rc_num = rc_num | bank_3.insert((uint8_t) MRS3_BA, 0, 1, 7);
        rc_num = rc_num | bank_3.insert((uint8_t) MRS3_BA, 1, 1, 6);
        rc_num = rc_num | bank_3.insert((uint8_t) MRS3_BA, 2, 1, 5);
	if (rc_num)
        {
            FAPI_ERR( "mss_mrs_load: Error setting up buffers");
            rc_buff.setEcmdError(rc_num);
            return rc_buff;
        }
    }
    //MRS4
    else if(MRS == MRS4_BA) {
    	uint8_t max_pd_mode; // Max Power down mode -  NEW
    	rc = FAPI_ATTR_GET(ATTR_EFF_MAX_POWERDOWN_MODE, &i_target, max_pd_mode);
    	if(rc) return rc;
    	uint8_t temp_ref_range; // Temp ref range -  NEW
    	rc = FAPI_ATTR_GET(ATTR_EFF_TEMP_REF_RANGE, &i_target, temp_ref_range);
    	if(rc) return rc;
    	uint8_t temp_ref_mode; // Temp controlled ref mode -  NEW
    	rc = FAPI_ATTR_GET(ATTR_EFF_TEMP_REF_MODE, &i_target, temp_ref_mode);
    	if(rc) return rc;
    	uint8_t vref_mon; // Internal Vref Monitor -  NEW
    	rc = FAPI_ATTR_GET(ATTR_EFF_INT_VREF_MON, &i_target, vref_mon);
    	if(rc) return rc;
    	uint8_t cs_cmd_latency; // CS to CMD/ADDR Latency -  NEW
    	rc = FAPI_ATTR_GET(ATTR_EFF_CS_CMD_LATENCY, &i_target, cs_cmd_latency);
    	if(rc) return rc;
    	uint8_t ref_abort; // Self Refresh Abort -  NEW
    	rc = FAPI_ATTR_GET(ATTR_EFF_SELF_REF_ABORT, &i_target, ref_abort);
    	if(rc) return rc;
    	uint8_t rd_pre_train_mode; // Read Pre amble Training Mode -  NEW
    	rc = FAPI_ATTR_GET(ATTR_EFF_RD_PREAMBLE_TRAIN, &i_target, rd_pre_train_mode);
    	if(rc) return rc;
    	uint8_t rd_preamble; // Read Pre amble -  NEW
    	rc = FAPI_ATTR_GET(ATTR_EFF_RD_PREAMBLE, &i_target, rd_preamble);
    	if(rc) return rc;
    	uint8_t wr_preamble; // Write Pre amble -  NEW
    	rc = FAPI_ATTR_GET(ATTR_EFF_WR_PREAMBLE, &i_target, wr_preamble);
    	if(rc) return rc;

    	if ( max_pd_mode == ENUM_ATTR_EFF_MAX_POWERDOWN_MODE_ENABLE)
    	{
    	    max_pd_mode = 0xF0;
    	}
    	else if ( max_pd_mode == ENUM_ATTR_EFF_MAX_POWERDOWN_MODE_DISABLE)
    	{
    	    max_pd_mode = 0x00;
    	}

    	if (temp_ref_range == ENUM_ATTR_EFF_TEMP_REF_RANGE_NORMAL)
    	{
    	    temp_ref_range = 0x00;
    	}
    	else if ( temp_ref_range== ENUM_ATTR_EFF_TEMP_REF_RANGE_EXTEND)
    	{
    	    temp_ref_range = 0xFF;
    	}

    	if (temp_ref_mode == ENUM_ATTR_EFF_TEMP_REF_MODE_ENABLE)
    	{
    	    temp_ref_mode = 0x80;
    	}
    	else if (temp_ref_mode == ENUM_ATTR_EFF_TEMP_REF_MODE_DISABLE)
    	{
    	    temp_ref_mode = 0x00;
    	}

    	if ( vref_mon == ENUM_ATTR_EFF_INT_VREF_MON_ENABLE)
    	{
    	    vref_mon = 0xFF;
    	}
    	else if ( vref_mon == ENUM_ATTR_EFF_INT_VREF_MON_DISABLE)
    	{
    	    vref_mon = 0x00;
    	}


    	if ( cs_cmd_latency == 3)
    	{
    	    cs_cmd_latency = 0x80;
    	}
    	else if (cs_cmd_latency == 4)
    	{
    	    cs_cmd_latency = 0x40;
    	}
    	else if (cs_cmd_latency == 5)
    	{
    	    cs_cmd_latency = 0xC0;
    	}
    	else if (cs_cmd_latency == 6)
    	{
    	    cs_cmd_latency = 0x20;
    	}
    	else if (cs_cmd_latency == 8)
    	{
    	    cs_cmd_latency = 0xA0;
    	}

    	if (ref_abort == ENUM_ATTR_EFF_SELF_REF_ABORT_ENABLE)
    	{
    	    ref_abort = 0xFF;
    	}
    	else if (ref_abort == ENUM_ATTR_EFF_SELF_REF_ABORT_DISABLE)
    	{
    	    ref_abort = 0x00;
    	}

    	if (rd_pre_train_mode == ENUM_ATTR_EFF_RD_PREAMBLE_TRAIN_ENABLE)
    	{
    	    rd_pre_train_mode = 0xFF;
    	}
    	else if (rd_pre_train_mode == ENUM_ATTR_EFF_RD_PREAMBLE_TRAIN_DISABLE)
    	{
    	    rd_pre_train_mode = 0x00;
    	}

    	if (rd_preamble == ENUM_ATTR_EFF_RD_PREAMBLE_1NCLK)
    	{
    	    rd_preamble = 0x00;
    	}
    	else if (rd_preamble == ENUM_ATTR_EFF_RD_PREAMBLE_2NCLK)
    	{
    	    rd_preamble = 0xFF;
    	}

    	if (wr_preamble == ENUM_ATTR_EFF_WR_PREAMBLE_1NCLK)
    	{
    	    wr_preamble = 0x00;
    	}
    	else if (wr_preamble == ENUM_ATTR_EFF_WR_PREAMBLE_2NCLK)
    	{
    	    wr_preamble = 0xFF;
    	}
    	rc_num = rc_num | address_16.insert((uint8_t) 0x00, 0, 1);
    	rc_num = rc_num | address_16.insert((uint8_t) max_pd_mode, 1, 1);
    	rc_num = rc_num | address_16.insert((uint8_t) temp_ref_range, 2, 1);
    	rc_num = rc_num | address_16.insert((uint8_t) temp_ref_mode, 3, 1);
    	rc_num = rc_num | address_16.insert((uint8_t) vref_mon, 4, 1);
    	rc_num = rc_num | address_16.insert((uint8_t) 0x00, 5, 1);
    	rc_num = rc_num | address_16.insert((uint8_t) cs_cmd_latency, 6, 3);
    	rc_num = rc_num | address_16.insert((uint8_t) ref_abort, 9, 1);
    	rc_num = rc_num | address_16.insert((uint8_t) rd_pre_train_mode, 10, 1);
    	rc_num = rc_num | address_16.insert((uint8_t) rd_preamble, 11, 1);
    	rc_num = rc_num | address_16.insert((uint8_t) wr_preamble, 12, 1);
	
	rc_num = rc_num | bank_3.insert((uint8_t) MRS4_BA, 0, 1, 7);
        rc_num = rc_num | bank_3.insert((uint8_t) MRS4_BA, 1, 1, 6);
        rc_num = rc_num | bank_3.insert((uint8_t) MRS4_BA, 2, 1, 5);
	if (rc_num)
        {
            FAPI_ERR( "mss_mrs_load: Error setting up buffers");
            rc_buff.setEcmdError(rc_num);
            return rc_buff;
        }
    }
    //MRS5
    else if(MRS == MRS5_BA) {
    	uint8_t ca_parity_latency; //C/A Parity Latency Mode  -  NEW
    	rc = FAPI_ATTR_GET(ATTR_EFF_CA_PARITY_LATENCY , &i_target, ca_parity_latency);
    	if(rc) return rc;
    	uint8_t crc_error_clear; //CRC Error Clear  -  NEW
    	rc = FAPI_ATTR_GET(ATTR_EFF_CRC_ERROR_CLEAR , &i_target, crc_error_clear);
    	if(rc) return rc;
    	uint8_t ca_parity_error_status; //C/A Parity Error Status  -  NEW
    	rc = FAPI_ATTR_GET(ATTR_EFF_CA_PARITY_ERROR_STATUS , &i_target, ca_parity_error_status);
    	if(rc) return rc;
    	uint8_t odt_input_buffer; //ODT Input Buffer during power down  -  NEW
    	rc = FAPI_ATTR_GET(ATTR_EFF_ODT_INPUT_BUFF , &i_target, odt_input_buffer);
    	if(rc) return rc;
    	uint8_t rtt_park[2][2][4]; //RTT_Park value  -  NEW
    	rc = FAPI_ATTR_GET(ATTR_EFF_RTT_PARK , &i_target, rtt_park);
    	if(rc) return rc;
    	uint8_t ca_parity; //CA Parity Persistance Error  -  NEW
    	rc = FAPI_ATTR_GET(ATTR_EFF_CA_PARITY , &i_target, ca_parity);
    	if(rc) return rc;
    	uint8_t data_mask; //Data Mask  -  NEW
    	rc = FAPI_ATTR_GET(ATTR_EFF_DATA_MASK , &i_target, data_mask);
    	if(rc) return rc;
    	uint8_t write_dbi; //Write DBI  -  NEW
    	rc = FAPI_ATTR_GET(ATTR_EFF_WRITE_DBI , &i_target, write_dbi);
    	if(rc) return rc;
    	uint8_t read_dbi; //Read DBI  -  NEW
    	rc = FAPI_ATTR_GET(ATTR_EFF_READ_DBI , &i_target, read_dbi);
    	if(rc) return rc;


    	if (ca_parity_latency == 4)
    	{
    	    ca_parity_latency = 0x80;
    	}
    	else if (ca_parity_latency == 5)
    	{
    	    ca_parity_latency = 0x40;
    	}
    	else if (ca_parity_latency == 6)
    	{
    	    ca_parity_latency = 0xC0;
    	}
    	else if (ca_parity_latency == 8)
    	{
    	    ca_parity_latency = 0x20;
    	}
    	else if (ca_parity_latency == ENUM_ATTR_EFF_CA_PARITY_LATENCY_DISABLE)
    	{
    	    ca_parity_latency = 0x00;
    	}

    	if (crc_error_clear == ENUM_ATTR_EFF_CRC_ERROR_CLEAR_ERROR)
    	{
    	    crc_error_clear = 0xFF;
    	}
    	else if (crc_error_clear == ENUM_ATTR_EFF_CRC_ERROR_CLEAR_CLEAR)
    	{
    	    crc_error_clear = 0x00;
    	}

    	if (ca_parity_error_status == ENUM_ATTR_EFF_CA_PARITY_ERROR_STATUS_ERROR)
    	{
    	    ca_parity_error_status = 0xFF;
    	}
    	else if (ca_parity_error_status == ENUM_ATTR_EFF_CA_PARITY_ERROR_STATUS_CLEAR)
    	{
    	    ca_parity_error_status = 0x00;
    	}

    	if (odt_input_buffer == ENUM_ATTR_EFF_ODT_INPUT_BUFF_ACTIVATED)
    	{
    	    odt_input_buffer = 0x00;
    	}
    	else if (odt_input_buffer == ENUM_ATTR_EFF_ODT_INPUT_BUFF_DEACTIVATED)
    	{
    	    odt_input_buffer = 0xFF;
    	}


    	if (ca_parity == ENUM_ATTR_EFF_CA_PARITY_ENABLE)
    	{
    	    ca_parity = 0xFF;
    	}
    	else if (ca_parity == ENUM_ATTR_EFF_CA_PARITY_DISABLE)
    	{
    	    ca_parity = 0x00;
    	}

    	if (data_mask == ENUM_ATTR_EFF_DATA_MASK_DISABLE)
    	{
    	    data_mask = 0x00;
    	}
    	else if (data_mask == ENUM_ATTR_EFF_DATA_MASK_ENABLE)
    	{
    	    data_mask = 0xFF;
    	}

    	if (write_dbi == ENUM_ATTR_EFF_WRITE_DBI_DISABLE)
    	{
    	    write_dbi = 0x00;
    	}
    	else if (write_dbi == ENUM_ATTR_EFF_WRITE_DBI_ENABLE)
    	{
    	    write_dbi = 0xFF;
    	}

    	if (read_dbi == ENUM_ATTR_EFF_READ_DBI_DISABLE)
    	{
    	    read_dbi = 0x00;
    	}
    	else if (read_dbi == ENUM_ATTR_EFF_READ_DBI_ENABLE)
    	{
    	    read_dbi = 0xFF;
    	}
    	if (rtt_park[i_port_number][dimm_number][rank_number] == ENUM_ATTR_EFF_RTT_PARK_DISABLE)
    	{
    	    rtt_park[i_port_number][dimm_number][rank_number] = 0x00;
    	}
    	else if (rtt_park[i_port_number][dimm_number][rank_number] == ENUM_ATTR_EFF_RTT_PARK_60OHM)
    	{
    	    rtt_park[i_port_number][dimm_number][rank_number] = 0x80;
    	}
    	else if (rtt_park[i_port_number][dimm_number][rank_number] == ENUM_ATTR_EFF_RTT_PARK_40OHM)
    	{
    	    rtt_park[i_port_number][dimm_number][rank_number] = 0xC0;
    	}
    	else if (rtt_park[i_port_number][dimm_number][rank_number] == ENUM_ATTR_EFF_RTT_PARK_120OHM)
    	{
    	    rtt_park[i_port_number][dimm_number][rank_number] = 0x40;
    	}
    	else if (rtt_park[i_port_number][dimm_number][rank_number] == ENUM_ATTR_EFF_RTT_PARK_240OHM)
    	{
    	    rtt_park[i_port_number][dimm_number][rank_number] = 0x20;
    	}
    	else if (rtt_park[i_port_number][dimm_number][rank_number] == ENUM_ATTR_EFF_RTT_PARK_48OHM)
    	{
    	    rtt_park[i_port_number][dimm_number][rank_number] = 0xA0;
    	}
    	else if (rtt_park[i_port_number][dimm_number][rank_number] == ENUM_ATTR_EFF_RTT_PARK_80OHM)
    	{
    	    rtt_park[i_port_number][dimm_number][rank_number] = 0x60;
    	}
    	else if (rtt_park[i_port_number][dimm_number][rank_number] == ENUM_ATTR_EFF_RTT_PARK_34OHM)
    	{
    	    rtt_park[i_port_number][dimm_number][rank_number] = 0xE0;
    	}

    	rc_num = rc_num | address_16.insert((uint8_t) ca_parity_latency, 0, 2);
    	rc_num = rc_num | address_16.insert((uint8_t) crc_error_clear, 3, 1);
    	rc_num = rc_num | address_16.insert((uint8_t) ca_parity_error_status, 4, 1);
    	rc_num = rc_num | address_16.insert((uint8_t) odt_input_buffer, 5, 1);
    	rc_num = rc_num | address_16.insert((uint8_t) rtt_park[i_port_number][dimm_number][rank_number], 6, 3);
    	rc_num = rc_num | address_16.insert((uint8_t) ca_parity, 9, 1);
    	rc_num = rc_num | address_16.insert((uint8_t) data_mask, 10, 1);
    	rc_num = rc_num | address_16.insert((uint8_t) write_dbi, 11, 1);
    	rc_num = rc_num | address_16.insert((uint8_t) read_dbi, 12, 1);
    	rc_num = rc_num | address_16.insert((uint8_t) 0x00, 13, 2);
	
	rc_num = rc_num | bank_3.insert((uint8_t) MRS5_BA, 0, 1, 7);
        rc_num = rc_num | bank_3.insert((uint8_t) MRS5_BA, 1, 1, 6);
        rc_num = rc_num | bank_3.insert((uint8_t) MRS5_BA, 2, 1, 5);
	if (rc_num)
        {
            FAPI_ERR( "mss_mrs_load: Error setting up buffers");
            rc_buff.setEcmdError(rc_num);
            return rc_buff;
        }
    }
    //MRS6
    else if(MRS == MRS6_BA) {
    	uint8_t vrefdq_train_value[2][2][4]; //vrefdq_train value   -  NEW
    	rc = FAPI_ATTR_GET( ATTR_VREF_DQ_TRAIN_VALUE, &i_target, vrefdq_train_value);
    	if(rc) return rc;
    	uint8_t vrefdq_train_range[2][2][4]; //vrefdq_train range   -  NEW
    	rc = FAPI_ATTR_GET( ATTR_VREF_DQ_TRAIN_RANGE, &i_target, vrefdq_train_range);
    	if(rc) return rc;
    	uint8_t vrefdq_train_enable[2][2][4]; //vrefdq_train enable  -  NEW
    	rc = FAPI_ATTR_GET( ATTR_VREF_DQ_TRAIN_ENABLE, &i_target, vrefdq_train_enable);
    	if(rc) return rc;
    	uint8_t tccd_l; //tccd_l  -  NEW
    	rc = FAPI_ATTR_GET( ATTR_TCCD_L, &i_target, tccd_l);
    	if(rc) return rc;
    	if (tccd_l == 4)
    	{
    	    tccd_l = 0x00;
    	}
    	else if (tccd_l == 5)
    	{
    	    tccd_l = 0x80;
    	}
    	else if (tccd_l == 6)
    	{
    	    tccd_l = 0x40;
    	}    
    	else if (tccd_l == 7)
    	{
    	    tccd_l = 0xC0;
    	}
    	else if (tccd_l == 8)
    	{
    	    tccd_l = 0x20;
    	}

    	vrefdq_train_value[i_port_number][dimm_number][rank_number] = mss_reverse_8bits(vrefdq_train_value[i_port_number][dimm_number][rank_number]);

    	if (vrefdq_train_range[i_port_number][dimm_number][rank_number] == ENUM_ATTR_VREF_DQ_TRAIN_RANGE_RANGE1)
    	{
    	    vrefdq_train_range[i_port_number][dimm_number][rank_number] = 0x00;
    	}
    	else if (vrefdq_train_range[i_port_number][dimm_number][rank_number] == ENUM_ATTR_VREF_DQ_TRAIN_RANGE_RANGE2)
    	{
    	    vrefdq_train_range[i_port_number][dimm_number][rank_number] = 0xFF;
    	}   

    	if (vrefdq_train_enable[i_port_number][dimm_number][rank_number] == ENUM_ATTR_VREF_DQ_TRAIN_ENABLE_ENABLE)
    	{
    	    vrefdq_train_enable[i_port_number][dimm_number][rank_number] = 0xFF;
    	}
    	else if (vrefdq_train_enable[i_port_number][dimm_number][rank_number] == ENUM_ATTR_VREF_DQ_TRAIN_ENABLE_DISABLE)
    	{
    	    vrefdq_train_enable[i_port_number][dimm_number][rank_number] = 0x00;
    	}   

    	rc_num = rc_num | address_16.insert((uint8_t) vrefdq_train_value[i_port_number][dimm_number][rank_number], 0, 6);
    	rc_num = rc_num | address_16.insert((uint8_t) vrefdq_train_range[i_port_number][dimm_number][rank_number], 6, 1);
    	rc_num = rc_num | address_16.insert((uint8_t) vrefdq_train_enable[i_port_number][dimm_number][rank_number], 7, 1);
    	rc_num = rc_num | address_16.insert((uint8_t) 0x00, 8, 2);
    	rc_num = rc_num | address_16.insert((uint8_t) tccd_l, 10, 3);
    	rc_num = rc_num | address_16.insert((uint8_t) 0x00, 13, 2);
	
	rc_num = rc_num | bank_3.insert((uint8_t) MRS6_BA, 0, 1, 7);
        rc_num = rc_num | bank_3.insert((uint8_t) MRS6_BA, 1, 1, 6);
        rc_num = rc_num | bank_3.insert((uint8_t) MRS6_BA, 2, 1, 5);
	if (rc_num)
        {
            FAPI_ERR( "mss_mrs_load: Error setting up buffers");
            rc_buff.setEcmdError(rc_num);
            return rc_buff;
        }
    }
    else {
        const uint32_t MRS_VALUE = MRS;
	const fapi::Target & MBA_TARGET = i_target; 
	FAPI_SET_HWP_ERROR(rc, RC_MSS_PDA_MRS_NOT_FOUND);
	FAPI_ERR("ERROR!! Found attribute name not associated with an MRS! Exiting...");
    }
    
    return rc;
}
}

OpenPOWER on IntegriCloud