summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/hwp/mc_config/mss_eff_config/mss_eff_grouping.C
blob: 48c35633994b19339da83a259964807683eb911d (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hwpf/hwp/mc_config/mss_eff_config/mss_eff_grouping.C $ */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012                   */
/*                                                                        */
/* p1                                                                     */
/*                                                                        */
/* Object Code Only (OCO) source materials                                */
/* Licensed Internal Code Source Materials                                */
/* IBM HostBoot Licensed Internal Code                                    */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
// $Id: mss_eff_grouping.C,v 1.16 2012/12/14 08:41:20 gpaulraj Exp $
//------------------------------------------------------------------------------
// *! (C) Copyright International Business Machines Corp. 2011
// *! All Rights Reserved -- Property of IBM
// *! *** IBM Confidential ***
//------------------------------------------------------------------------------
// *! TITLE       : mss_eff_grouping.C
// *! DESCRIPTION : see additional comments below
//------------------------------------------------------------------------------
// Don't forget to create CVS comments when you check in your changes!
//------------------------------------------------------------------------------
//Owner :- Girisankar paulraj
//Back-up owner :- Mark bellows
//
// CHANGE HISTORY:
//------------------------------------------------------------------------------
// Version:|  Author: |  Date:  | Comment:
//---------|----------|---------|-----------------------------------------------
//  1.16   | gpaulraj | 12-14-12| Modified "unable to group dimm size" as Error message
//  1.15   | bellows  | 12-11-12| Picked up latest updates from Girisankar
//  1.14   | bellows  | 12-11-12| added ; to DBG line
//  1.13   | bellows  | 12-07-12| fix for interleaving attr and array bounds
//  1.11   | bellows  | 11-27-12| review updates
//  1.10   | bellows  | 09-27-12| Additional Review Updates
//  1.9    | bellows  | 09-25-12| updates from review, code from Girisankar
//  1.8    | bellows  | 09-06-12| updates suggested by Van
//  1.7    | bellows  | 08-31-12| updates from Girisankar: C++ Object. Also use 32 bit Attribute
//  1.6    | bellows  | 08-29-12| expanded group id temporaily to 32 bits, fixed compiler warnings
//         |          |         | Read old 8bit attr, and move to 32
//         |          |         | Removed read of attr that has not been written
//  1.2    | bellows  | 07-16-12| bellows | added in Id tag
//  1.1    | gpaulraj | 03-19-12| First drop for centaur
//----------------------------------------------------------------------
//  Includes
//----------------------------------------------------------------------

#include <mss_eff_grouping.H>
#include <fapi.H>
#include "cen_scom_addresses.H"
//#include <mss_funcs.H>

//#ifdef FAPIECMD
extern "C" {
//#endif

  using namespace fapi;
//----------------------------------------------
// MSS EFF GROUPING FUNCTIONs............
//----------------------------------------------------

  ReturnCode mss_eff_grouping(const fapi::Target & i_target, std::vector<fapi::Target> & i_associated_centaurs); // Target is Proc target & Each MCS connected to each Centaur. Associated centaur is collection of the Centaure location for the processor
  uint8_t mss_eff_grouping_recursion(uint32_t number);
//ReturnCode mba_collection(std::vector<fapi::Target> & associated_centaurs);
//ReturnCode mcs_grouping(const fapi::Target & target);
//ReturnCode mcs_grouping_general();
//ReturnCode mcs_grouping_reorder();
//ReturnCode mcs_group_base_address(const fapi::Target & target);
//ReturnCode mcs_attributes_setting(const fapi::Target & target);

// PLAN:---
//    Parameter  of the populated Dimm details for each MCS looper
//    Starts with Zero MCS base address. Identifies Dimm parameters belong to MCS
//    Configure the Group primary MCS0 Registers
//    Configure the Group seconary MCS0 Registers /// identifies it base address based on the Primary group size
//    Identify Mirror details setup accordingly
//    Set up each translation registry accordingly
//    SIM configuration
//    Venice model has MCS0 & MCS1 - Murano model has MCS4 & MCS5
//    -------------------------|-----------------------------------|
//    -------    MCS0 ---------|-------------MCS1------------------|
//    -------------------------|-----------------------------------|
//    ---  MBA0  --- MBA1 -----|--------  MBA0  --- MBA1 ----------|
//     0-  32GB  --- 32GB -----|---- D0-  32GB  --- 32GB ----------|
//    D1-  32GB  --- 32GB  ----|-----D1-  32GB  --- 32GB  ---------|
//    -------------------------|-----------------------------------|
//    - Base address MCS0 - 0x0  Group Size - 128GB
//    - MCS0 -  Grouping base address  - 0GB Group size - 128GB
//    - MCS1 -  Grouping base address  - 128GB+ Group size - 128GB
//----------------------------------------------------
// MSS EFF GROUPING Variables..........
//----------------------------------------------------



  ReturnCode mss_eff_grouping(
                              const fapi::Target & i_target,
                              std::vector<fapi::Target> & i_associated_centaurs
                              ) {
    ReturnCode rc;
    Eff_Grouping_Data eff_grouping_data,tempgpID;
       //Eff_Grouping_Data &eff_grouping_data;
        //eff_grouping_data.groupID[16][16]={{0}};
    //uint32_t pos=0;
    uint64_t mss_base_address;
    uint64_t mirror_base;
        //uint32_t MBA_size[8][2]={{0}};
        //uint32_t MCS_size[8]={0};
    uint32_t l_unit_pos =0;
        //uint32_t l_count=0;
    uint8_t gp_pos=0;
    uint8_t min_group = 1;
    std::vector<fapi::Target> l_proc_chiplets;
    int i; int j;
    for(i=0;i<MBA_SIZE_MCS;i++) {
      eff_grouping_data.MCS_size[i]=0;
      for(j=0;j<MBA_SIZE_PORT;j++)
        eff_grouping_data.MBA_size[i][j]=0;
    }
    for(i=0;i<MBA_GROUP_SIZE;i++) {
      for(j=0;j<MBA_GROUP_DATA;j++)
        eff_grouping_data.groupID[i][j]=0;
    }

    do
    {
      FAPI_INF("MCS grouping begins");
//	rc=mba_collection(associated_centaurs, &eff_grouping_data);
//	if(!rc.ok()) {FAPI_ERR("MBA memory: There is no valid memory dimm available"); break;}
///	rc=mcs_grouping(target);
//    	if(!rc.ok()) {FAPI_ERR("MCS Grouping: MCS grouping is not feasible"); break;}
//	rc=mcs_grouping_reorder();
//	if(!rc.ok()) {FAPI_ERR("MCS Grouping: MCS grouping re-ordering is not feasible"); break;}
//	rc=mcs_group_base_address(target);
//  /  if(!rc.ok()) {FAPI_ERR("MCS Grouping: MCS grouping base address is greater not than largest group size"); break;}
//	rc=mcs_attributes_setting(target);
//    if(!rc.ok()) {FAPI_ERR("MCS Grouping: MCS gruping attributes is not defined correctly"); break;}

      uint8_t centaur;
      uint8_t mba_i;
      uint8_t mba=0;
      uint8_t dimm=0;
      uint32_t cenpos;
      uint32_t procpos;
      uint8_t port;
      uint8_t mba_pos[2][2] = { {0, 0},{0,0}};
      std::vector<fapi::Target> l_mba_chiplets;
      FAPI_INF("Happy starting");
      uint8_t cen_count=0;
      rc = FAPI_ATTR_GET(ATTR_POS,&i_target, procpos);
      if(rc) return rc;
   //   for(centaur= procpos*8; centaur <= procpos*8+8; centaur++) {
      for(centaur= 0; centaur < i_associated_centaurs.size(); centaur++) {
        mba=0;port=0;dimm=0;
        fapi::Target & centaur_t = i_associated_centaurs[centaur];
//        centaur_t=i_associated_centaurs[centaur];
        rc = FAPI_ATTR_GET(ATTR_POS,&centaur_t, cenpos);
        if(rc) return rc;
        if(cenpos>=procpos*8 && cenpos<(procpos*8+8)){
                FAPI_INF("... working on centaur %d", cenpos);
                rc = fapiGetChildChiplets(i_associated_centaurs[centaur], fapi::TARGET_TYPE_MBA_CHIPLET, l_mba_chiplets);
                if(rc) return rc;
                for(mba_i=0; mba_i<l_mba_chiplets.size(); mba_i++) {

                  rc = FAPI_ATTR_GET(ATTR_CHIP_UNIT_POS, &l_mba_chiplets[mba_i], mba);
                  if(rc) return rc;
                  FAPI_INF("... working on mba %d", mba);
                  rc = FAPI_ATTR_GET(ATTR_EFF_DIMM_SIZE, &l_mba_chiplets[mba_i],mba_pos);
                  if(rc) return rc;
                  for(port = 0; port<2; port++)
                  {	
                    for(dimm=0; dimm<2; dimm++) {
                      eff_grouping_data.MCS_size[cenpos - procpos * 8]+=mba_pos[port][dimm];
                      eff_grouping_data.MBA_size[cenpos - procpos * 8][mba] += mba_pos[port][dimm];
                    }
                  }
                  FAPI_INF(" Cen Pos %d mba %d DIMM SIZE %d \n",cenpos,mba,eff_grouping_data.MBA_size[cenpos - procpos * 8][mba]);
                  FAPI_INF(" Cen Pos %d MBA SIZE %d %d  %d %d \n",cenpos, mba_pos[0][0],mba_pos[0][1],mba_pos[1][0],mba_pos[1][1]);
                  FAPI_INF(" MCS SIZE %d\n",eff_grouping_data.MCS_size[cenpos - procpos * 8]);
   //               cen_count++; l_unit_pos++;
            }
            cen_count++;l_unit_pos++;
        }
//        cen_count++; l_unit_pos++;
      }
      FAPI_INF("attr_mss_setting %d and  no  of MBAs   %d \n",min_group,l_unit_pos);
      for (uint8_t i=0;i<8;i++)
      {
        FAPI_INF("MCS SIZE %d \n",eff_grouping_data.MCS_size[i]);
      }
      FAPI_INF("Group parsing Starting..");
// 	groupID[i][0]=Size;
//  groupID[i][1]= number of MBA in the group for example 4 MBA in the group
//  groupID[i][2]= Total size of memory
//  groupID[i][3] to groupIDsize[i][6]  - group pos indication
    //  uint32_t temp[12];
      uint8_t count=0;
        uint8_t done;
        uint8_t pos;
        uint8_t config_4MCS[6][4]={{0,1,4,5},{2,3,6,7},{0,1,6,7},{2,3,4,5},{0,1,2,3},{4,5,6,7}};
        int flag;
        uint8_t config4_pos[6];
        uint8_t groups_allowed;
        // uint8_t tempgpID.groupID[16][16];
        uint8_t grouped[16];
        uint8_t check_board;
        uint8_t gp=0;
        uint8_t pos1=0;
        uint8_t pos2=0;
        uint8_t allowed=0;



        for(uint8_t i=0;i<6;i++)
          config4_pos[i]=0;

	rc = FAPI_ATTR_GET(ATTR_MSS_INTERLEAVE_ENABLE,&i_target,groups_allowed);
	if(!rc.ok()) {FAPI_ERR("MSS_INTERLEAVE_ENABLE is not available"); return rc; }
	rc = FAPI_ATTR_GET(ATTR_ALL_MCS_IN_INTERLEAVING_GROUP, NULL,check_board); // system level attribute
	if (!rc.ok()) { FAPI_ERR("Error reading ATTR_ALL_MCS_IN_INTERLEAVING_GROUP"); return rc; }



        for(uint8_t i=0;i<16;i++)
        {
             grouped[i]=0;
             for(uint8_t j=0;j<16;j++)
             {
                 eff_grouping_data.groupID[i][j]=0;
                 tempgpID.groupID[i][j]=0;
             }
         }


        gp_pos=0;

        for(pos=0;pos<8;pos++)
        {
             eff_grouping_data.groupID[gp_pos][0] = eff_grouping_data.MCS_size[pos];
             eff_grouping_data.groupID[gp_pos][1] = 1;
             eff_grouping_data.groupID[gp_pos][4]= pos;

             if(eff_grouping_data.MBA_size[pos][0]>eff_grouping_data.MBA_size[pos][1])
                  eff_grouping_data.groupID[gp_pos][15]= eff_grouping_data.MBA_size[pos][0];
             else
                  eff_grouping_data.groupID[gp_pos][15]= eff_grouping_data.MBA_size[pos][1];

             gp_pos++;
         }


           done = 0 ;
           if(!done && (groups_allowed & 0x08) && check_board)
           {
          	
                count =0;
                for(pos=0;pos< gp_pos;pos++)
                {
                    if(eff_grouping_data.groupID[0][0] == eff_grouping_data.groupID[pos][0] && eff_grouping_data.groupID[pos][0] !=0)
                    {
                      count++;
                    }
                 }

                 if(count == 8)
                 {
                   done=1;
                   eff_grouping_data.groupID[0][1] = 8;
                   eff_grouping_data.groupID[0][4] = 0;
                   eff_grouping_data.groupID[0][5] = 4;
                   eff_grouping_data.groupID[0][6] = 1;
                   eff_grouping_data.groupID[0][7] = 5;
                   eff_grouping_data.groupID[0][8] = 2;
                   eff_grouping_data.groupID[0][9] = 6;
                   eff_grouping_data.groupID[0][10] = 3;
                   eff_grouping_data.groupID[0][11] = 7;
                   for(uint8_t i=1;i<16;i++)
                     for(uint8_t j=0;j<16;j++)
                       eff_grouping_data.groupID[i][j]=0;
                 }

            }
            if(!done && (groups_allowed & 0x04) && check_board)
            {
                 count=0;
                 for(uint8_t i=0;i<6;i++)
                 {
                   flag=0;
                   for( int j=0;j<4;j++)
                    {
                      if((eff_grouping_data.groupID[config_4MCS[i][0]][0]== 0) || (eff_grouping_data.groupID[config_4MCS[i][0]][0] != eff_grouping_data.groupID[config_4MCS[i][j]][0]))
                       {
                         flag=1;
                       }
                    }
                    if(!flag)
                    {

                    config4_pos[i]=1;
                    count++;
                    }
                 }
                 if(count>=2)
                 {
                    if(config4_pos[0] && config4_pos[1])
                    {
                       allowed=1;
                       pos1=0;
                       pos2=1;
                    }
                    else if(config4_pos[2] && config4_pos[3])
                    {
                       allowed=1;
                       pos1=2;
                       pos2=3;
                    }
                    else if(config4_pos[4] && config4_pos[5])
                    {
                       allowed=1;
                       pos1=4;
                       pos2=5;
                    }
                 }
                 if(allowed)
                  {
          	           done =1;
                         //define the group_data
                         eff_grouping_data.groupID[0][0] =eff_grouping_data.groupID[config_4MCS[pos1][0]][0];
                         eff_grouping_data.groupID[0][1] = 4;
                         eff_grouping_data.groupID[0][4] = config_4MCS[pos1][0];
                         eff_grouping_data.groupID[0][5] = config_4MCS[pos1][2];
                         eff_grouping_data.groupID[0][6] = config_4MCS[pos1][1];
                         eff_grouping_data.groupID[0][7] = config_4MCS[pos1][3];
                         eff_grouping_data.groupID[0][15] =eff_grouping_data.groupID[config_4MCS[pos1][0]][15];

                         eff_grouping_data.groupID[1][0] =eff_grouping_data.groupID[config_4MCS[pos2][0]][0];
                         eff_grouping_data.groupID[1][1] = 4;
                         eff_grouping_data.groupID[1][4] = config_4MCS[pos2][0];
                         eff_grouping_data.groupID[1][5] = config_4MCS[pos2][2];
                         eff_grouping_data.groupID[1][6] = config_4MCS[pos2][1];
                         eff_grouping_data.groupID[1][7] = config_4MCS[pos2][3];
                         eff_grouping_data.groupID[1][15] =eff_grouping_data.groupID[config_4MCS[pos2][0]][15];

                         for(uint8_t i=2;i<16;i++)
                           for(uint8_t j=0;j<16;j++)
                             eff_grouping_data.groupID[i][j]=0;
                  }
                  else if (count ==1 || !allowed )
                  {
                       for(uint8_t i=0;i<6;i++)
                       {
                         if(config4_pos[i])
                         {
                           allowed=1;
                           pos1=i;
                           break;
                         }
                       }
                       if(allowed)
                       {
          	          //define the group_data
          	           tempgpID.groupID[0][0] = eff_grouping_data.groupID[config_4MCS[pos1][0]][0];
                           tempgpID.groupID[0][1] = 4;
                           tempgpID.groupID[0][4] = config_4MCS[pos1][0];
                           tempgpID.groupID[0][5] = config_4MCS[pos1][2];
                           tempgpID.groupID[0][6] = config_4MCS[pos1][1];
                           tempgpID.groupID[0][7] = config_4MCS[pos1][3];
                           tempgpID.groupID[0][15] = eff_grouping_data.groupID[config_4MCS[pos1][0]][15];
          	           gp++;
                           for(int i=0; i<4;i++)
                           {
                              eff_grouping_data.groupID[config_4MCS[pos1][i]][0]=0;
                              grouped[config_4MCS[config4_pos[0]][i]]=1;
                           }
                       }
                   }
           }
           if(!done && (groups_allowed & 0x02) && check_board)
           {
            for(pos=0;pos< gp_pos;pos=pos+2)
            {
                 if(eff_grouping_data.groupID[pos][0] == eff_grouping_data.groupID[pos+1][0] && eff_grouping_data.groupID[pos][0] !=0  )
                 {
                  //group
                  tempgpID.groupID[gp][0] =eff_grouping_data.groupID[pos][0] ;
                  tempgpID.groupID[gp][1] = 2;
                  tempgpID.groupID[gp][4] =  pos;
                  tempgpID.groupID[gp][5] = pos+1;
                  tempgpID.groupID[gp][15] =eff_grouping_data.groupID[pos][15] ;
                  grouped[pos]=1;
                  grouped[pos+1]=1;
                  eff_grouping_data.groupID[pos][0]=0;
                  eff_grouping_data.groupID[pos+1][0]=0;
                  gp++;
                 }
             }
           }
           if(!done && (groups_allowed & 0x01)&& !check_board)
           {
            for(pos=0;pos< gp_pos;pos++)
            {
                 if(eff_grouping_data.groupID[pos][0] !=0  )
                 {
                  //group
                  tempgpID.groupID[gp][0] =eff_grouping_data.groupID[pos][0] ;
                  tempgpID.groupID[gp][1] = 1;
                  tempgpID.groupID[gp][4] =  pos;
                  tempgpID.groupID[gp][15] =eff_grouping_data.groupID[pos][15] ;
                  grouped[pos]=1;
                  eff_grouping_data.groupID[pos][0]=0;
                  gp++;
                 }
             }
           }
           if(!done)
           {
              for(uint8_t i=0;i<8;i++)
              {
          		   if(grouped[i] !=1 && eff_grouping_data.groupID[i][0] != 0 )
          		   FAPI_ERR ("UNABLE TO GROUP MCS%d size is %d", i,eff_grouping_data.groupID[i][0]);
              }

             for(uint8_t i=0;i<gp;i++)
               for(uint8_t j=0;j<16;j++)
                 eff_grouping_data.groupID[i][j]=tempgpID.groupID[i][j];

             for(uint8_t i=gp ; i<8 ; i++)
               for(uint8_t j=0;j<16;j++)
               eff_grouping_data.groupID[i][j]=0;
           }
            flag=0;
            for(uint8_t i=0;i<16;i++)
               if(grouped[i])
                  flag=1;
            gp_pos=0;
            if(done || flag)
            {
               for(uint8_t i=0;i<16;i++)
               {
            	      if( eff_grouping_data.groupID[i][0] !=0)
            	      {
                         gp_pos++;
                         FAPI_INF(" group no= %d , num of MCS = %d , size of MCS = %d \n ", i,eff_grouping_data.groupID[i][1],eff_grouping_data.groupID[i][0]);
                         for(uint8_t k=0 ; k< eff_grouping_data.groupID[i][1];k++)
                         {
            	           FAPI_INF("MCSID%d = %d \n ", k, eff_grouping_data.groupID[i][4+k]);
                         }
                      }
                  }
             }
      uint32_t temp[16];
      uint8_t i=0;
      uint8_t j=0;
      count=0;

    for(pos=0;pos<=gp_pos;pos++)
      {
        eff_grouping_data.groupID[pos][2] = eff_grouping_data.groupID[pos][0]*eff_grouping_data.groupID[pos][1];
        //eff_grouping_data.groupID[pos+8][2]= eff_grouping_data.groupID[pos][2]/2; // group size when mirrored

        count =  mss_eff_grouping_recursion(eff_grouping_data.groupID[pos][2]);
        if(count>1)
        {
          FAPI_INF("MCS pos %d needs alternate bars defintation group Size %d\n",pos,eff_grouping_data.groupID[pos][3]);



            eff_grouping_data.groupID[pos][2] = eff_grouping_data.groupID[pos][15]*2*eff_grouping_data.groupID[pos][1];
            eff_grouping_data.groupID[pos][13] = eff_grouping_data.groupID[pos][1]*(eff_grouping_data.groupID[pos][0]-eff_grouping_data.groupID[pos][15]);

            //mirrored group
            //eff_grouping_data.groupID[pos+8][2] = eff_grouping_data.groupID[pos][2]/2;  //group size with alternate bars
            //eff_grouping_data.groupID[pos+8][13] = eff_grouping_data.groupID[pos][13]/2;
             eff_grouping_data.groupID[pos][12] =1;
        }
      }
      for(i=0;i<gp_pos;i++)
      {
          for(j=0;j<12;j++)
          {
            FAPI_INF(" groupID[%d][%d] = %d",i,j,eff_grouping_data.groupID[i][j]);
          }
          FAPI_INF("\n");
      }
      for(pos=0;pos<=gp_pos;pos++)
      {	
        for(i=pos;i< gp_pos;i++)
        {
          if ( eff_grouping_data.groupID[i][2] > eff_grouping_data.groupID[pos][2])
          {
            for(j=0;j<16;j++)	temp[j] = eff_grouping_data.groupID[pos][j];
            for(j=0;j<16;j++)	eff_grouping_data.groupID[pos][j] = eff_grouping_data.groupID[i][j];
            for(j=0;j<16;j++)	eff_grouping_data.groupID[i][j] = temp[j];
          }
          else {}
        }
      }


       // calcutate mirrored group size
       for(pos=0;pos<gp_pos;pos++)
      {
        if(eff_grouping_data.groupID[pos][0]!=0 && eff_grouping_data.groupID[pos][1]>1 )
        {
          eff_grouping_data.groupID[pos+8][2]= eff_grouping_data.groupID[pos][2]/2; // group size when mirrored


          if(eff_grouping_data.groupID[pos][12])
          {
            FAPI_INF("Mirrored group pos %d needs alternate bars defintation group Size %d\n",pos,eff_grouping_data.groupID[pos][3]);
            //mirrored group
            eff_grouping_data.groupID[pos+8][2] = eff_grouping_data.groupID[pos][2]/2;  //group size with alternate bars
            eff_grouping_data.groupID[pos+8][13] = eff_grouping_data.groupID[pos][13]/2;

          }
        }
      }

      rc = FAPI_ATTR_GET(ATTR_PROC_MEM_BASE,&i_target,mss_base_address);
      mss_base_address =   mss_base_address >> 30;
      if(!rc.ok()) return rc;

      rc = FAPI_ATTR_GET(ATTR_PROC_MIRROR_BASE,&i_target,mirror_base);
      mirror_base =   mirror_base >> 30;

      if(!rc.ok()) return rc;

      for(pos=0;pos<gp_pos;pos++)
      {
        if(pos==0)
        {

          eff_grouping_data.groupID[pos][3] =mss_base_address;
          eff_grouping_data.groupID[pos+8][3]=mirror_base;  //mirrored base address
          if(eff_grouping_data.groupID[pos][12])
          {

            eff_grouping_data.groupID[pos][14] = eff_grouping_data.groupID[pos][3]+ eff_grouping_data.groupID[pos][2]/2;
            eff_grouping_data.groupID[pos+8][14] = eff_grouping_data.groupID[pos+8][3]+ eff_grouping_data.groupID[pos+8][2]/2; //mirrored base address with alternate bars
          }
        }
        else
        {
          eff_grouping_data.groupID[pos][3] = eff_grouping_data.groupID[pos-1][3]+eff_grouping_data.groupID[pos-1][2];
          eff_grouping_data.groupID[pos+8][3]= eff_grouping_data.groupID[pos-1+8][3]+eff_grouping_data.groupID[pos-1+8][2];

          if(eff_grouping_data.groupID[pos][12])
          {
            eff_grouping_data.groupID[pos][14] = eff_grouping_data.groupID[pos][3]+ eff_grouping_data.groupID[pos][2]/2;
            eff_grouping_data.groupID[pos+8][14] = eff_grouping_data.groupID[pos+8][3]+ eff_grouping_data.groupID[pos+8][2]/2; //mirrored base address with alternate bars
          }
        }		
      }		
      ecmdDataBufferBase MC_IN_GP(8);
      uint8_t mcs_in_group[8];
      for(uint8_t i=0;i<8;i++)
           mcs_in_group[i]=0;
      for(uint8_t i=0;i<gp_pos;i++)
      {
        count=0;
        MC_IN_GP.flushTo0();
        if(eff_grouping_data.groupID[i][0]!=0)
        {
          count = eff_grouping_data.groupID[i][1];
          for(uint8_t j=0;j<count;j++)
                 MC_IN_GP.setBit(eff_grouping_data.groupID[i][4+j]);
          mcs_in_group[i]= MC_IN_GP.getByte(0);
        }
       }
       FAPI_DBG("  ATTR_MSS_MEM_MC_IN_GROUP[0]: 0x%x", mcs_in_group[0]);
       FAPI_DBG("  ATTR_MSS_MEM_MC_IN_GROUP[1]: 0x%x", mcs_in_group[1]);
       FAPI_DBG("  ATTR_MSS_MEM_MC_IN_GROUP[2]: 0x%x", mcs_in_group[2]);
       FAPI_DBG("  ATTR_MSS_MEM_MC_IN_GROUP[3]: 0x%x", mcs_in_group[3]);
       FAPI_DBG("  ATTR_MSS_MEM_MC_IN_GROUP[4]: 0x%x", mcs_in_group[4]);
       FAPI_DBG("  ATTR_MSS_MEM_MC_IN_GROUP[5]: 0x%x", mcs_in_group[5]);
       FAPI_DBG("  ATTR_MSS_MEM_MC_IN_GROUP[6]: 0x%x", mcs_in_group[6]);
       FAPI_DBG("  ATTR_MSS_MEM_MC_IN_GROUP[7]: 0x%x", mcs_in_group[7]);

       rc= FAPI_ATTR_SET(ATTR_MSS_MEM_MC_IN_GROUP, &i_target, mcs_in_group);
       if (!rc.ok())FAPI_ERR("Error writing ATTR_MSS_MEM_MC_IN_GROUP");

      uint64_t mem_bases[8];
      uint64_t l_memory_sizes[8];
      //uint64_t mirror_base;
      uint64_t mirror_bases[4];
      uint64_t l_mirror_sizes[4];
        //uint32_t temp[8];
      for(uint8_t i=0;i<8;i++)
      {
        if(eff_grouping_data.groupID[i][0]>0)
        {
          FAPI_INF (" Group   %d MCS Size  %4d   ",i,eff_grouping_data.groupID[i][0]);
          FAPI_INF (" No of MCS %4d ",eff_grouping_data.groupID[i][1]);
          FAPI_INF (" Group Size %4d ",eff_grouping_data.groupID[i][2]);
          FAPI_INF (" Base Add.  %4d ",eff_grouping_data.groupID[i][3]);
          FAPI_INF (" Mirrored Group SIze %4d", eff_grouping_data.groupID[i+8][2]);
          FAPI_INF (" Mirror Base Add %4d", eff_grouping_data.groupID[i+8][3]);
          for(uint8_t j=4;j<4+eff_grouping_data.groupID[i][1];j++)
          {
            FAPI_INF (" MCSID%d- Pos %4d",(j-4),eff_grouping_data.groupID[i][j]);
          }
          FAPI_INF (" Alter-bar  %4d",eff_grouping_data.groupID[i][12]);
          FAPI_INF("Alter-bar base add = %4d",eff_grouping_data.groupID[i][14]);
          FAPI_INF("Alter-bar size = %4d",eff_grouping_data.groupID[i][13]);
          FAPI_INF("Alter-bar Mirrored Base add = %4d", eff_grouping_data.groupID[i+8][14]);
          FAPI_INF("Alter-bar Mirrored size = %4d", eff_grouping_data.groupID[i+8][13]);
        }
        else
        {
          eff_grouping_data.groupID[i][0] = 0;
          eff_grouping_data.groupID[i][1] = 0;
          eff_grouping_data.groupID[i][2] = 0;
          eff_grouping_data.groupID[i][3] = 0;
          eff_grouping_data.groupID[i][4] = 0;
          eff_grouping_data.groupID[i][5] = 0;
          eff_grouping_data.groupID[i][6] = 0;
          eff_grouping_data.groupID[i][7] = 0;
          eff_grouping_data.groupID[i][8] = 0;
          eff_grouping_data.groupID[i][9] = 0;
        }
      }
//       rc = FAPI_ATTR_GET(ATTR_MSS_MCS_GROUP_32, &target, eff_grouping_data.groupID);
//        if (!rc.ok())
//        {
//            FAPI_ERR("Error reading ATTR_MSS_MCS_GROUP");
//          //  break;
//        }
        // base addresses for distinct non-mirrored ranges
      mem_bases[0]=eff_grouping_data.groupID[0][3];
      mem_bases[0] = mem_bases[0] <<30;
      mem_bases[1]=eff_grouping_data.groupID[1][3];
      mem_bases[1] =  mem_bases[1] <<30;
      mem_bases[2]=eff_grouping_data.groupID[2][3];
      mem_bases[2] =  mem_bases[2] <<30;
      mem_bases[3]=eff_grouping_data.groupID[3][3];
      mem_bases[3] =  mem_bases[3] <<30;
      mem_bases[4]=eff_grouping_data.groupID[4][3];
      mem_bases[4] =  mem_bases[4] <<30;
      mem_bases[5]=eff_grouping_data.groupID[5][3];
      mem_bases[5] =  mem_bases[5] <<30;
      mem_bases[6]=eff_grouping_data.groupID[6][3];
      mem_bases[6] =  mem_bases[6] <<30;
      mem_bases[7]=eff_grouping_data.groupID[7][3];
      mem_bases[7] =  mem_bases[7] <<30;

      FAPI_DBG("  ATTR_PROC_MEM_BASES[0]: %016llx", mem_bases[0]);
      FAPI_DBG("  ATTR_PROC_MEM_BASES[1]: %016llx", mem_bases[1]);
      FAPI_DBG("  ATTR_PROC_MEM_BASES[2]: %016llx", mem_bases[2]);
      FAPI_DBG("  ATTR_PROC_MEM_BASES[3]: %016llx", mem_bases[3]);
      FAPI_DBG("  ATTR_PROC_MEM_BASES[4]: %016llx", mem_bases[4]);
      FAPI_DBG("  ATTR_PROC_MEM_BASES[5]: %016llx", mem_bases[5]);
      FAPI_DBG("  ATTR_PROC_MEM_BASES[6]: %016llx", mem_bases[6]);
      FAPI_DBG("  ATTR_PROC_MEM_BASES[7]: %016llx", mem_bases[7]);

      rc = FAPI_ATTR_SET(ATTR_PROC_MEM_BASES, &i_target, mem_bases);
      if (!rc.ok())
      {
        FAPI_ERR("Error writing ATTR_PROC_MEM_BASES");
            //break;
      }

        // sizes for distinct non-mirrored ranges
      l_memory_sizes[0]=eff_grouping_data.groupID[0][2];
      l_memory_sizes[0] =  l_memory_sizes[0] <<30;
      l_memory_sizes[1]=eff_grouping_data.groupID[1][2];
      l_memory_sizes[1] =  l_memory_sizes[1] <<30;
      l_memory_sizes[2]=eff_grouping_data.groupID[2][2];
      l_memory_sizes[2] =  l_memory_sizes[2] <<30;
      l_memory_sizes[3]=eff_grouping_data.groupID[3][2];
      l_memory_sizes[3] =  l_memory_sizes[3] <<30;
      l_memory_sizes[4]=eff_grouping_data.groupID[4][2];
      l_memory_sizes[4] =  l_memory_sizes[4] <<30;
      l_memory_sizes[5]=eff_grouping_data.groupID[5][2];
      l_memory_sizes[5] =  l_memory_sizes[5] <<30;
      l_memory_sizes[6]=eff_grouping_data.groupID[6][2];
      l_memory_sizes[6] =  l_memory_sizes[6] <<30;
      l_memory_sizes[7]=eff_grouping_data.groupID[7][2];
      l_memory_sizes[7] =  l_memory_sizes[7] <<30;

      FAPI_DBG("  ATTR_PROC_MEM_SIZES[0]: %016llx", l_memory_sizes[0]);
      FAPI_DBG("  ATTR_PROC_MEM_SIZES[1]: %016llx", l_memory_sizes[1]);
      FAPI_DBG("  ATTR_PROC_MEM_SIZES[2]: %016llx", l_memory_sizes[2]);
      FAPI_DBG("  ATTR_PROC_MEM_SIZES[3]: %016llx", l_memory_sizes[3]);
      FAPI_DBG("  ATTR_PROC_MEM_SIZES[4]: %016llx", l_memory_sizes[4]);
      FAPI_DBG("  ATTR_PROC_MEM_SIZES[5]: %016llx", l_memory_sizes[5]);
      FAPI_DBG("  ATTR_PROC_MEM_SIZES[6]: %016llx", l_memory_sizes[6]);
      FAPI_DBG("  ATTR_PROC_MEM_SIZES[7]: %016llx", l_memory_sizes[7]);

      rc = FAPI_ATTR_SET(ATTR_PROC_MEM_SIZES, &i_target, l_memory_sizes);
      if (!rc.ok())
      {
        FAPI_ERR("Error writing ATTR_PROC_MEM_SIZES");
        break;
      }
       rc = FAPI_ATTR_GET(ATTR_PROC_MEM_SIZES, &i_target, l_memory_sizes);
        if (!rc.ok())
      {
        FAPI_ERR("Error writing ATTR_PROC_MEM_SIZES");
        break;
      }
       FAPI_DBG("  ATTR_PROC_MEM_SIZES[0]: %016llx", l_memory_sizes[0]);
      FAPI_DBG("  ATTR_PROC_MEM_SIZES[1]: %016llx", l_memory_sizes[1]);
      FAPI_DBG("  ATTR_PROC_MEM_SIZES[2]: %016llx", l_memory_sizes[2]);
      FAPI_DBG("  ATTR_PROC_MEM_SIZES[3]: %016llx", l_memory_sizes[3]);
      FAPI_DBG("  ATTR_PROC_MEM_SIZES[4]: %016llx", l_memory_sizes[4]);
      FAPI_DBG("  ATTR_PROC_MEM_SIZES[5]: %016llx", l_memory_sizes[5]);
      FAPI_DBG("  ATTR_PROC_MEM_SIZES[6]: %016llx", l_memory_sizes[6]);
      FAPI_DBG("  ATTR_PROC_MEM_SIZES[7]: %016llx", l_memory_sizes[7]);

      rc = FAPI_ATTR_SET(ATTR_MSS_MCS_GROUP_32,&i_target, eff_grouping_data.groupID);
      if (!rc.ok())
      {
        FAPI_ERR("Error writing ATTR_MSS_MCS_GROUP");
        break;
      }
          // process mirrored ranges
        //

        // read chip base address attribute
///      rc = FAPI_ATTR_GET(ATTR_PROC_MIRROR_BASE, &i_chip_target, mirror_base);
//      if (!rc.ok())
//      {
//        FAPI_ERR("Error reading ATTR_PROC_MIRROR_BASE");
//        break;
//      }

        // base addresses for distinct mirrored ranges
      mirror_bases[0] = eff_grouping_data.groupID[8][3];
      mirror_bases[1] = eff_grouping_data.groupID[9][3];
      mirror_bases[2] = eff_grouping_data.groupID[10][3];
      mirror_bases[3] = eff_grouping_data.groupID[11][3];

      mirror_bases[0] = mirror_bases[0]<<30;
      mirror_bases[1] = mirror_bases[1]<<30;
      mirror_bases[2] = mirror_bases[2]<<30;
      mirror_bases[3] = mirror_bases[3]<<30;
      FAPI_DBG("  ATTR_PROC_MIRROR_BASES[0]: %016llx", mirror_bases[0]);
      FAPI_DBG("  ATTR_PROC_MIRROR_BASES[1]: %016llx", mirror_bases[1]);
      FAPI_DBG("  ATTR_PROC_MIRROR_BASES[2]: %016llx", mirror_bases[2]);
      FAPI_DBG("  ATTR_PROC_MIRROR_BASES[3]: %016llx", mirror_bases[3]);

      rc = FAPI_ATTR_SET(ATTR_PROC_MIRROR_BASES, &i_target, mirror_bases);
      if (!rc.ok())
      {
        FAPI_ERR("Error writing ATTR_PROC_MIRROR_BASES");
        break;
      }

        // sizes for distinct mirrored ranges
      l_mirror_sizes[0]=eff_grouping_data.groupID[8][2];
      l_mirror_sizes[1]=eff_grouping_data.groupID[9][2];
      l_mirror_sizes[2]=eff_grouping_data.groupID[10][2];
      l_mirror_sizes[3]=eff_grouping_data.groupID[11][2];

      l_mirror_sizes[0] = l_mirror_sizes[0]<<30;
      l_mirror_sizes[1] = l_mirror_sizes[1]<<30;
      l_mirror_sizes[2] = l_mirror_sizes[2]<<30;
      l_mirror_sizes[3] = l_mirror_sizes[3]<<30;

      FAPI_DBG("  ATTR_PROC_MIRROR_SIZES[0]: %016llx", l_mirror_sizes[0]);
      FAPI_DBG("  ATTR_PROC_MIRROR_SIZES[1]: %016llx", l_mirror_sizes[1]);
      FAPI_DBG("  ATTR_PROC_MIRROR_SIZES[2]: %016llx", l_mirror_sizes[2]);
      FAPI_DBG("  ATTR_PROC_MIRROR_SIZES[3]: %016llx", l_mirror_sizes[3]);

      rc = FAPI_ATTR_SET(ATTR_PROC_MIRROR_SIZES, &i_target, l_mirror_sizes);
      if (!rc.ok())
      {
        FAPI_ERR("Error writing ATTR_PROC_MIRROR_SIZES");
        break;
       }
    }while(0);
    return rc;			
  }

  uint8_t  mss_eff_grouping_recursion(uint32_t number){
    uint32_t temp = number;
    uint8_t count=0;
    uint8_t buffersize=0;	
    while(1)
    {
      if(temp%2)
      {
        count++;buffersize++;
        temp=temp/2;
        FAPI_INF(" %d buffer Size %d*Count %d\n",number,buffersize,count);
      }
      else
      {
        temp=temp/2;
        buffersize++;
      }
      if (temp ==0 || temp ==1)
      {
        if(temp)
        {count++;}
        buffersize++;
        FAPI_INF(" %d buffer Size %d*Count %d\n",number,buffersize,count);
        break;	  	
      }
    }	
    return count;
  }

//#ifdef FAPIECMD
} //end extern C
//#endif
OpenPOWER on IntegriCloud