summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/hwp/mc_config/mss_freq/mss_freq.C
blob: 89e5e80f59c47ba9fb8f4e916d4a919b695d62c3 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hwpf/hwp/mc_config/mss_freq/mss_freq.C $              */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012,2013              */
/*                                                                        */
/* p1                                                                     */
/*                                                                        */
/* Object Code Only (OCO) source materials                                */
/* Licensed Internal Code Source Materials                                */
/* IBM HostBoot Licensed Internal Code                                    */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
// $Id: mss_freq.C,v 1.21 2013/02/13 00:23:34 jdsloat Exp $
/* File mss_volt.C created by JEFF SABROWSKI on Fri 21 Oct 2011. */

//------------------------------------------------------------------------------
// *! (C) Copyright International Business Machines Corp. 2007
// *! All Rights Reserved -- Property of IBM
// *! *** IBM Confidential ***
//------------------------------------------------------------------------------
// *! TITLE : mss_freq.C
// *! DESCRIPTION : Tools for centaur procedures
// *! OWNER NAME :   Jeff Sabrowski (jsabrow@us.ibm.com)
// *! BACKUP NAME :  
// #! ADDITIONAL COMMENTS :
//
// General purpose funcs

//------------------------------------------------------------------------------
// Don't forget to create CVS comments when you check in your changes!
//------------------------------------------------------------------------------
// CHANGE HISTORY:
//------------------------------------------------------------------------------
// Version:|  Author: |   Date:  | Comment:
//---------|----------|----------|----------------------------------------------
//  1.1    | jsabrow  | 09/30/11 | Initial draft.
//  1.2    | bellows  | 12/21/11 | fixed function call to mss_freq
//  1.4    | jsabrow  |
//  1.6    | jdsloat  | 05/03/12 | Fixed per Firmware request, added CL calc
//  1.7    | jdsloat  | 05/03/12 | Uncommented Set Attributes
//  1.8    | jdsloat  | 05/07/12 | fixed per Firmware request
//  1.9    | jdsloat  | 05/07/12 | Unused Variables removed
//  1.11   | jdsloat  | 05/07/12 | Uncommented Set Attributes
//  1.12   | jdsloat  | 05/08/12 | Fixed per Firmware request, fixed CL attribute set, fixed MTB usage.
//  1.13   | jdsloat  | 05/09/12 | Fixed per Firmware request
//  1.14   | jdsloat  | 05/10/12 | Fixed per Firmware Request, RC checks, 0 checks
//  1.15   | jdsloat  | 06/04/12 | Added a Configuration check
//  1.16   | jdsloat  | 06/08/12 | Updates per Firware request
//  1.17   | bellows  | 07/16/12 | added in Id tag
//  1.18   | jdsloat  | 09/07/12 | Added FTB offset to TAA and TCK
//  1.19   | jdsloat  | 01/30/13 | Added Check for l_spd_min_tck_max
//  1.20   | jdsloat  | 02/12/13 | Added path for freq_override
//  1.21   | jdsloat  | 02/12/13 | Added Debug messages
//
// This procedure takes CENTAUR as argument.  for each DIMM (under each MBA)
// DIMM SPD attributes are read to determine optimal DRAM frequency
// frequency bins:  800*, 1066*, 1333, 1600, 1866, 2133, 2400*, 2666*
//    (*=not supported in product as of feb'12)

//----------------------------------------------------------------------
//  Includes - FAPI
//----------------------------------------------------------------------
#include <fapi.H>
#include <mss_freq.H>

//----------------------------------------------------------------------
// ENUMs   
//----------------------------------------------------------------------
enum {
   MSS_FREQ_EMPTY = 0,
   MSS_FREQ_SINGLE_DROP = 1,
   MSS_FREQ_DUAL_DROP = 2,
   MSS_FREQ_VALID = 255,
};


using namespace fapi;

fapi::ReturnCode mss_freq(const fapi::Target &i_target_memb)
{

     // Define attribute array size
    const uint8_t PORT_SIZE = 2;
    const uint8_t DIMM_SIZE = 2;

  fapi::ReturnCode l_rc;
  std::vector<fapi::Target> l_mbaChiplets;
  std::vector<fapi::Target> l_dimm_targets;
  uint8_t l_spd_mtb_dividend=0;
  uint8_t l_spd_mtb_divisor=0;
  uint8_t l_spd_ftb_dividend=0;
  uint8_t l_spd_ftb_divisor=0;
  uint32_t l_dimm_freq_calc=0;
  uint32_t l_dimm_freq_min=9999;
  uint8_t l_spd_min_tck_MTB=0;
  uint8_t l_spd_tck_offset_FTB=0;
  uint8_t l_spd_tck_offset=0;
  uint32_t l_spd_min_tck=0;
  uint32_t l_spd_min_tck_max=0;
  uint8_t  l_spd_min_taa_MTB=0;
  uint8_t  l_spd_taa_offset_FTB=0;
  uint8_t  l_spd_taa_offset=0;
  uint32_t l_spd_min_taa=0;
  uint32_t l_spd_min_taa_max=0;
  uint32_t l_selected_dimm_freq=0;
  uint32_t l_spd_cas_lat_supported = 0xFFFFFFFF;
  uint32_t l_spd_cas_lat_supported_all = 0xFFFFFFFF;
  uint8_t l_cas_latency = 0;
  uint32_t l_cl_mult_tck = 0;
  uint8_t cur_mba_port = 0;
  uint8_t cur_mba_dimm = 0;
  uint8_t cur_dimm_spd_valid_u8array[PORT_SIZE][DIMM_SIZE] = {{0}};
  uint8_t plug_config = 0;
  uint8_t module_type = 0;
  uint8_t module_type_all = 0;
  uint8_t num_ranks = 0;
  uint8_t num_ranks_total = 0;
  uint32_t  l_freq_override = 0;
  uint8_t l_override_path = 0;

  // Get associated MBA's on this centaur                                                                                      
  l_rc=fapiGetChildChiplets(i_target_memb, fapi::TARGET_TYPE_MBA_CHIPLET, l_mbaChiplets);
  if (l_rc)
  {
      FAPI_ERR("Error Getting MBA targets.");
      return l_rc;
  }
  // Loop through the 2 MBA's                                                                                                  
  for (uint32_t i=0; i < l_mbaChiplets.size(); i++)
    {
      // Get a vector of DIMM targets                                                                                          
      l_rc = fapiGetAssociatedDimms(l_mbaChiplets[i], l_dimm_targets);
      if (l_rc)
      {
	  FAPI_ERR("Error Getting DIMM targets.");
	  return l_rc;
      }
      for (uint32_t j=0; j < l_dimm_targets.size(); j++)
	{
	  
	  l_rc = FAPI_ATTR_GET(ATTR_SPD_MTB_DIVIDEND, &l_dimm_targets[j], l_spd_mtb_dividend);
	  if (l_rc)
	    {
	      FAPI_ERR("Unable to read SPD Medium Timebase Dividend.");
	      break;
	    }

	  l_rc = FAPI_ATTR_GET(ATTR_SPD_MTB_DIVISOR, &l_dimm_targets[j], l_spd_mtb_divisor);
	  if (l_rc)
	    {
	      FAPI_ERR("Unable to read SPD Medium Timebase Divisor.");
	      break;
	    }

	  l_rc = FAPI_ATTR_GET(ATTR_SPD_TCKMIN, &l_dimm_targets[j], l_spd_min_tck_MTB);
	  if (l_rc)
	    {
	      FAPI_ERR("Unable to read SPD Minimum TCK (Min Clock Cycle).");
	      break;
	    }

	  l_rc = FAPI_ATTR_GET(ATTR_SPD_TAAMIN, &l_dimm_targets[j], l_spd_min_taa_MTB);
	  if (l_rc)
	    {
	      FAPI_ERR("Unable to read SPD Minimum TAA (Min CAS Latency Time).");
	      break;
	    }
	  l_rc = FAPI_ATTR_GET(ATTR_SPD_CAS_LATENCIES_SUPPORTED, &l_dimm_targets[j], l_spd_cas_lat_supported);
	  if (l_rc)
	    {
	      FAPI_ERR("Unable to read SPD Supported CAS Latencies.");
	      break;
	    }

	  l_rc = FAPI_ATTR_GET(ATTR_MBA_PORT,  &l_dimm_targets[j], cur_mba_port);
	  if (l_rc)
	    {
	      FAPI_ERR("Unable to read the Port Info in order to determine configuration.");
	      break;
	    }
	  l_rc = FAPI_ATTR_GET(ATTR_MBA_DIMM,  &l_dimm_targets[j], cur_mba_dimm);
	  if (l_rc)
	    {
	      FAPI_ERR("Unable to read the DIMM Info in order to determine configuration.");
	      break;
	    }
	  l_rc = FAPI_ATTR_GET(ATTR_SPD_MODULE_TYPE,  &l_dimm_targets[j], module_type);
	  if (l_rc)
	  {
	      FAPI_ERR("Unable to read the SPD module type.");
	      break;
	  }
	  l_rc = FAPI_ATTR_GET(ATTR_SPD_NUM_RANKS,  &l_dimm_targets[j], num_ranks);
	  if (l_rc)
	  {
	      FAPI_ERR("Unable to read the SPD number of ranks");
	      break;
	  }
	  l_rc = FAPI_ATTR_GET(ATTR_SPD_FINE_OFFSET_TAAMIN,  &l_dimm_targets[j], l_spd_taa_offset_FTB); 
	  if (l_rc)
	  {
	      FAPI_ERR("Unable to read the SPD TAA offset (FTB)");
	      break;
	  }
	  l_rc = FAPI_ATTR_GET(ATTR_SPD_FINE_OFFSET_TCKMIN,  &l_dimm_targets[j], l_spd_tck_offset_FTB);
	  if (l_rc)
	  {
	      FAPI_ERR("Unable to read the SPD TCK offset (FTB)");
	      break;
	  }
	  l_rc = FAPI_ATTR_GET(ATTR_SPD_FTB_DIVIDEND,  &l_dimm_targets[j], l_spd_ftb_dividend);
	  if (l_rc)
	  {
	      FAPI_ERR("Unable to read the SPD FTB dividend");
	      break;
	  }
	  l_rc = FAPI_ATTR_GET(ATTR_SPD_FTB_DIVISOR,  &l_dimm_targets[j], l_spd_ftb_divisor);
	  if (l_rc)
	  {
	      FAPI_ERR("Unable to read the SPD FTB divisor");
	      break;
	  }

	  cur_dimm_spd_valid_u8array[cur_mba_port][cur_mba_dimm] = MSS_FREQ_VALID;

	  if ((l_spd_min_tck_MTB == 0)||(l_spd_mtb_dividend == 0)||(l_spd_mtb_divisor == 0)||(l_spd_min_taa_MTB == 0)||(l_spd_ftb_dividend == 0)||(l_spd_ftb_divisor == 0))
	  {
	      //Invalid due to the fact that JEDEC dictates that these should be non-zero.
	      FAPI_ERR("Invalid data recieved from SPD within MTB Dividend, MTB Divisor, TCK Min, or TAA Min");
	      FAPI_SET_HWP_ERROR(l_rc, RC_MSS_UNSUPPORTED_SPD_DATA);
	      break;
	  }

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

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

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

	  if ((l_spd_min_tck == 0)||(l_spd_min_taa == 0))
	  {
	      //Invalid due to the fact that JEDEC dictates that these should be non-zero.
	      FAPI_ERR("Invalid data recieved from SPD causing TCK Min or TAA Min to be 0");
	      FAPI_SET_HWP_ERROR(l_rc, RC_MSS_UNSUPPORTED_SPD_DATA);
	      break;
	  }
	  l_dimm_freq_calc = 2000000 / l_spd_min_tck;

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

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

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

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

	  l_spd_cas_lat_supported_all = l_spd_cas_lat_supported_all & l_spd_cas_lat_supported;
	  num_ranks_total = num_ranks_total + num_ranks;
	  if (module_type_all == 0)
	  {
	      module_type_all = module_type;
	  }
	  else if (module_type_all != module_type)
	  {
	      FAPI_ERR("Mixing of DIMM Module Types (%d, %d)", module_type_all, module_type);
	      FAPI_SET_HWP_ERROR(l_rc, RC_MSS_MODULE_TYPE_MIX);
	  }

      }
      if (l_rc)
      {
	  break;
      }
  }

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

  //Determining the cnfg for imposing any cnfg speed limitations
  if ((cur_dimm_spd_valid_u8array[0][0] == MSS_FREQ_VALID) && (cur_dimm_spd_valid_u8array[0][1] == MSS_FREQ_VALID))
  {
      plug_config = MSS_FREQ_DUAL_DROP;
  }
  else if ((cur_dimm_spd_valid_u8array[0][0] == MSS_FREQ_VALID) && (cur_dimm_spd_valid_u8array[0][1] == MSS_FREQ_EMPTY))
  {
      plug_config = MSS_FREQ_SINGLE_DROP;
  }
  else
  {
      plug_config = MSS_FREQ_EMPTY;
  }


  FAPI_INF( "PLUG CONFIG(from SPD): %d Type of Dimm(from SPD): 0x%02X Num Ranks(from SPD): %d",  plug_config, module_type, num_ranks);

  // Impose configuration limitations
  // Single Drop RDIMMs Cnfgs cannot run faster than 1333 unless it only has 1 rank
  if ((module_type_all == ENUM_ATTR_SPD_MODULE_TYPE_RDIMM)&&(plug_config == MSS_FREQ_SINGLE_DROP)&&(num_ranks_total > 1)&&(l_dimm_freq_min > 1333))
  {
      l_dimm_freq_min = 1333;
      l_spd_min_tck_max = 1500;
      FAPI_INF( "Single Drop RDIMM with more than 1 Rank Cnfg limitation.  New Freq: %d", l_dimm_freq_min); 
  }
  // Double Drop RDIMMs Cnfgs cannot run faster than 1333 with 4 ranks total
  else if ((module_type_all == ENUM_ATTR_SPD_MODULE_TYPE_RDIMM)&&(plug_config == MSS_FREQ_DUAL_DROP)&&(num_ranks_total == 4)&&(l_dimm_freq_min > 1333))
  {
      l_dimm_freq_min = 1333;
      l_spd_min_tck_max = 1500;
      FAPI_INF( "Dual Drop RDIMM with more than 4 Rank Cnfg limitation.  New Freq: %d", l_dimm_freq_min); 
  }
  // Double Drop RDIMMs Cnfgs cannot run faster than 1066 with 8 ranks total
  else if ((module_type_all == ENUM_ATTR_SPD_MODULE_TYPE_RDIMM)&&(plug_config == MSS_FREQ_DUAL_DROP)&&(num_ranks_total == 8)&&(l_dimm_freq_min > 1066))
  {
      l_dimm_freq_min = 1066;
      l_spd_min_tck_max = 1875;
      FAPI_INF( "Dual Drop RDIMM with more than 8 Rank Cnfg limitation.  New Freq: %d", l_dimm_freq_min); 
  }
  // Single Drop LRDIMMs Cnfgs cannot run faster than 1333 with greater than 2 ranks
  else if ((module_type_all == ENUM_ATTR_SPD_MODULE_TYPE_LRDIMM)&&(plug_config == MSS_FREQ_SINGLE_DROP)&&(num_ranks_total > 2)&&(l_dimm_freq_min > 1333))
  {
      l_dimm_freq_min = 1333;
      l_spd_min_tck_max = 1500;
      FAPI_INF( "Single Drop LRDIMM with more than 2 Rank Cnfg limitation.  New Freq: %d", l_dimm_freq_min); 
  }
  // Dual Drop LRDIMMs Cnfgs cannot run faster than 1333
  else if ((module_type_all == ENUM_ATTR_SPD_MODULE_TYPE_LRDIMM)&&(plug_config == MSS_FREQ_DUAL_DROP)&&(l_dimm_freq_min > 1333))
  {
      l_dimm_freq_min = 1333;
      l_spd_min_tck_max = 1500;
      FAPI_INF( "Dual Drop LRDIMM Cnfg limitation.  New Freq: %d", l_dimm_freq_min); 
  }

  if ( l_spd_min_tck_max == 0)
  {
      FAPI_ERR("l_spd_min_tck_max = 0 unable to calculate freq or cl.  Possibly no centaurs configured. ");
      FAPI_SET_HWP_ERROR(l_rc, RC_MSS_UNSUPPORTED_SPD_DATA);
  }

  l_rc = FAPI_ATTR_GET(ATTR_MSS_FREQ_OVERRIDE,  &i_target_memb, l_freq_override); 
  if ( l_freq_override != 0)
  {
      // The relationship is as such
      // l_dimm_freq_min = 2000000 / l_spd_min_tck_max

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

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

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

      if (l_freq_override == 1066)
      {
	  l_dimm_freq_min = 1066;
	  l_spd_min_tck_max = 1875;
      }
  FAPI_INF( "Override Frequency Detected: %d", l_dimm_freq_min); 
  }

  if ((l_spd_cas_lat_supported_all == 0) && (!l_rc))
  {
      FAPI_ERR("No common supported CAS latencies between DIMMS.");
      FAPI_SET_HWP_ERROR(l_rc, RC_MSS_NO_COMMON_SUPPORTED_CL);
  }

  if (!l_rc) 
  {

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

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

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

      l_cl_mult_tck = l_cas_latency * l_spd_min_tck_max;

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

      while (    ( (!( l_spd_cas_lat_supported_all & (0x00000001<<(l_cas_latency-4)))) || (l_cl_mult_tck > 20000) )
	      && ( l_override_path = 0 ) )
      {

	  FAPI_INF( "Warning calculated CL is not supported in VPD.  Searching for a new CL.");

          // If not supported, increment the CL up to 18 (highest supported CL) looking for Supported CL 
	  while ((!( l_spd_cas_lat_supported_all & (0x00000001<<(l_cas_latency-4))))&&(l_cas_latency < 18))
	  {
	      l_cas_latency++;
	  }

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

	  // Do not move freq if using an override freq.  Just continue.  Hence the overide in this if statement
	  if ( ( (!( l_spd_cas_lat_supported_all & (0x00000001<<(l_cas_latency-4)))) || (l_cl_mult_tck > 20000) )
	      && ( l_freq_override == 0) )
	  {
	      FAPI_INF( "No Supported CL works for calculating frequency.  Lowering frequency and trying CL Algorithm again.");

	      if (l_spd_min_tck_max < 1500)
	      {
	          //1600 to 1333
		  l_spd_min_tck_max = 1500;

	      }
	      else if (l_spd_min_tck_max < 1875)
	      {
	          //1333 to 1066 
		  l_spd_min_tck_max = 1875;
	      }
	      else if (l_spd_min_tck_max < 2500)
	      {
	          //1066 to 800
		  l_spd_min_tck_max = 2500;
	      }
	      else
	      {
	          //This is minimum frequency and cannot be lowered
		  FAPI_ERR("Lowered Frequency to TCLK MIN finding no supported CL without exceeding TAA MAX.");
		  FAPI_SET_HWP_ERROR(l_rc, RC_MSS_EXCEED_TAA_MAX_NO_CL );
		  break;
	      }

	      // Re-calculate with new tck
	      l_cas_latency = l_spd_min_taa_max / l_spd_min_tck_max;
	      if ( l_spd_min_taa_max % l_spd_min_tck_max)
	      {
		  l_cas_latency++;
	      } 
	      l_cl_mult_tck = l_cas_latency * l_spd_min_tck_max;
	      l_dimm_freq_min = 2000000 / l_spd_min_tck_max;

	  }
	  // Need to break the loop in case we reach this condition because no longer modify freq and CL
	  // With an overrride
	  if ( ( (!( l_spd_cas_lat_supported_all & (0x00000001<<(l_cas_latency-4)))) || (l_cl_mult_tck > 20000) )
	      && ( l_freq_override == 1) )
	  {

	      FAPI_INF( "No Supported CL works for override frequency.  Using override frequency with an unsupported CL.");
	      l_override_path = 1;
	  }
      }
  }

  //bucketize dimm freq.
  if (!l_rc) 
  {
      if (l_dimm_freq_min < 1013)
	{
          FAPI_ERR("Unsupported frequency:  DIMM Freq calculated < 1013 MHz");
	  FAPI_SET_HWP_ERROR(l_rc, RC_MSS_UNSUPPORTED_FREQ_CALCULATED);
	}
      else if (l_dimm_freq_min < 1266)
	{
	  // 1066 
	  l_selected_dimm_freq=1066;
	}
      else if (l_dimm_freq_min < 1520)
	{
	  // 1333
	  l_selected_dimm_freq=1333;
	}
      else if (l_dimm_freq_min < 1773)
	{
	  // 1600
	  l_selected_dimm_freq=1600;
	}
      else if (l_dimm_freq_min < 2026)
	{
	  // 1866
	  l_selected_dimm_freq=1866;
	}
      else if (l_dimm_freq_min < 2280)
	{
	  // 2133
	  l_selected_dimm_freq=2133;
	}
      else
	{
	  FAPI_ERR("Unsupported frequency:  DIMM Freq calculated > 2133 MHz: %d", l_dimm_freq_min);
	  FAPI_SET_HWP_ERROR(l_rc, RC_MSS_UNSUPPORTED_FREQ_CALCULATED);
	}
  }

  // set frequency in centaur attribute ATTR_MSS_FREQ
  if (!l_rc) 
  {
      l_rc = FAPI_ATTR_SET(ATTR_MSS_FREQ, &i_target_memb, l_selected_dimm_freq);
      if (l_rc) 
      {
	  return l_rc;
      }
      FAPI_INF( "Final Chosen Frequency: %d ",  l_selected_dimm_freq);
      FAPI_INF( "Final Chosen CL: %d ",  l_cas_latency);
      for (uint32_t k=0; k < l_mbaChiplets.size(); k++)
      {
	  l_rc = FAPI_ATTR_SET(ATTR_EFF_DRAM_CL, &l_mbaChiplets[k], l_cas_latency);
	  if (l_rc) 
	  {
	      return l_rc;
	  }
      }
  }

  //all done.
  return l_rc;
}
OpenPOWER on IntegriCloud