summaryrefslogtreecommitdiffstats
path: root/src/occ_405/amec/amec_data.c
blob: 43ff5b39ce400f41c88f809f692b5fdc469ed5c8 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/occ_405/amec/amec_data.c $                                */
/*                                                                        */
/* OpenPOWER OnChipController Project                                     */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2011,2018                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

//*************************************************************************
// Includes
//*************************************************************************
#include <occ_common.h>
#include <ssx.h>
#include <errl.h>
#include "sensor.h"
#include "rtls.h"
#include "occ_sys_config.h"
#include "occ_service_codes.h"  // for SSX_GENERIC_FAILURE
#include "dcom.h"
#include "proc_data.h"
#include "proc_data_control.h"
#include "amec_smh.h"
#include "amec_slave_smh.h"
#include <trac.h>
#include "amec_sys.h"
#include "sensor_enum.h"
#include "amec_service_codes.h"
#include <amec_sensors_core.h>
#include <amec_sensors_power.h>
#include <amec_sensors_fw.h>
#include <amec_data.h>
#include <amec_freq.h>
#include <pgpe_interface.h>
#include <p9_pstates_occ.h>

//*************************************************************************
// Externs
//*************************************************************************

//*************************************************************************
// Defines/Enums
//*************************************************************************

//*************************************************************************
// Structures
//*************************************************************************

//*************************************************************************
// Globals
//*************************************************************************
extern uint8_t G_occ_interrupt_type;

//max(fturbo,futurbo)
extern uint16_t G_proc_fmax_mhz;

//*************************************************************************
// Function Prototypes
//*************************************************************************

//*************************************************************************
// Functions
//*************************************************************************


// Function Specification
//
// Name:  AMEC_data_write_fcurr
//
// Description:
//
// Thread: RealTime Loop
//
// Task Flags:
//
// End Function Specification
errlHndl_t AMEC_data_write_fcurr(const OCC_MODE i_mode)
{
    /*------------------------------------------------------------------------*/
    /*  Local Variables                                                       */
    /*------------------------------------------------------------------------*/
    errlHndl_t      l_err = NULL;

    /*------------------------------------------------------------------------*/
    /*  Code                                                                  */
    /*------------------------------------------------------------------------*/

    // Load new range into DVFS MIN/MAX,
    // Use i_mode here since this function understands turbo
    l_err = amec_set_freq_range(i_mode);

    if(l_err)
    {
        //break;
    }

    // If we are in OpenPower environment with OPAL, load this new range into DVFS
    // min/max for AMEC component.  PowerVM on BMC and FSP the min/max is set above
    // in amec_set_freq_range() based on mode
    if((G_occ_interrupt_type != FSP_SUPPORTED_OCC) && (G_sysConfigData.system_type.kvm))
    {
        if(g_amec->wof.wof_disabled)
        {
            g_amec->sys.fmax = G_sysConfigData.sys_mode_freq.table[OCC_MODE_TURBO];
        }
        else
        {
            g_amec->sys.fmax = G_proc_fmax_mhz;
        }
        g_amec->sys.fmin = G_sysConfigData.sys_mode_freq.table[OCC_MODE_MIN_FREQUENCY];

        TRAC_INFO("AMEC_data_write_fcurr: New frequency range Fmin[%u] Fmax[%u]",
                  g_amec->sys.fmin,
                  g_amec->sys.fmax);
    }

    return l_err;
}

// Function Specification
//
// Name:  AMEC_data_write_thrm_thresholds
//
// Description: This function loads data from the Thermal Control Threshold
// data packet (format 0x13) into g_amec structure. This function should be
// called when OCC goes active or changes modes
//
// Thread: RealTime Loop
//
// Task Flags:
//
// End Function Specification
errlHndl_t AMEC_data_write_thrm_thresholds(const OCC_MODE i_mode)
{

    /*------------------------------------------------------------------------*/
    /*  Local Variables                                                       */
    /*------------------------------------------------------------------------*/
    errlHndl_t                  l_err = NULL;
    cmdh_thrm_thresholds_t      *l_data = NULL;
    cmdh_thrm_thresholds_set_t  *l_frudata = NULL;
    uint8_t                     l_dvfs_temp = 0;
    uint8_t                     l_error = 0;
    bool                        l_pm_limits = false;

    /*------------------------------------------------------------------------*/
    /*  Code                                                                  */
    /*------------------------------------------------------------------------*/
    do
    {
        // Retrieve the thermal control threshold data
        l_err = DATA_get_thrm_thresholds(&l_data);
        if(l_err)
        {
            TRAC_ERR("AMEC_data_write_thrm_thresholds: Error retrieving thermal control threshold data");
            break;
        }

        l_frudata = l_data->data;

        // Store the processor thermal data
        if ((i_mode == OCC_MODE_NOMINAL) || (G_sysConfigData.system_type.kvm))
        {
            // use normal thresholds for Nominal or OPAL
            l_dvfs_temp = l_frudata[DATA_FRU_PROC].dvfs;
            l_error = l_frudata[DATA_FRU_PROC].error;
        }
        else
        {
            l_pm_limits = true;
            TRAC_INFO("AMEC_data_write_thrm_thresholds: Using PM limits");

            l_dvfs_temp = l_frudata[DATA_FRU_PROC].pm_dvfs;
            if(i_mode == OCC_MODE_TURBO)
            {
                //Need to log an error if we dvfs in static turbo mode (for mfg)
                l_error = l_dvfs_temp;
            }
            else
            {
                l_error = l_frudata[DATA_FRU_PROC].pm_error;
            }
        }
        // Store the DVFS thermal setpoint in 0.1 degrees C
        g_amec->thermalproc.setpoint = l_dvfs_temp * 10;
        // Store the error temperature for OT detection
        g_amec->thermalproc.ot_error = l_error;
        // Store the temperature timeout value
        g_amec->thermalproc.temp_timeout = l_frudata[DATA_FRU_PROC].max_read_timeout;

        TRAC_INFO("AMEC_data_write_thrm_thresholds: Processor setpoints - DVFS: %u, Error: %u",
                  l_dvfs_temp, l_error);

        // Store the Centaur thermal data
        if (!l_pm_limits)
        {
            // use normal thresholds for Nominal or OPAL
            l_dvfs_temp = l_frudata[DATA_FRU_CENTAUR].dvfs;
            l_error = l_frudata[DATA_FRU_CENTAUR].error;
        }
        else
        {
            l_dvfs_temp = l_frudata[DATA_FRU_CENTAUR].pm_dvfs;
            if(i_mode == OCC_MODE_TURBO)
            {
                //Need to log an error if we throttle in static turbo mode (for mfg)
                l_error = l_dvfs_temp;
            }
            else
            {
                l_error = l_frudata[DATA_FRU_CENTAUR].pm_error;
            }
        }

        // Store the DVFS thermal setpoint in 0.1 degrees C
        g_amec->thermalcent.setpoint = l_dvfs_temp * 10;
        // Store the error temperature for OT detection
        g_amec->thermalcent.ot_error = l_error;
        // Store the temperature timeout value
        g_amec->thermalcent.temp_timeout = l_frudata[DATA_FRU_CENTAUR].max_read_timeout;

        TRAC_INFO("AMEC_data_write_thrm_thresholds: Centaur setpoints - DVFS: %u, Error: %u",
                  l_dvfs_temp, l_error);

        // Store the DIMM thermal data
        if (!l_pm_limits)
        {
            // use normal thresholds for Nominal or OPAL
            l_dvfs_temp = l_frudata[DATA_FRU_DIMM].dvfs;
            l_error = l_frudata[DATA_FRU_DIMM].error;
        }
        else
        {
            l_dvfs_temp = l_frudata[DATA_FRU_DIMM].pm_dvfs;
            if(i_mode == OCC_MODE_TURBO)
            {
                //Need to log an error if we throttle in static turbo mode (for mfg)
                l_error = l_dvfs_temp;
            }
            else
            {
                l_error = l_frudata[DATA_FRU_DIMM].pm_error;
            }
        }
        // Store the DVFS thermal setpoint in 0.1 degrees C
        g_amec->thermaldimm.setpoint = l_dvfs_temp * 10;
        // Store the error temperature for OT detection
        g_amec->thermaldimm.ot_error = l_error;
        // Store the temperature timeout value
        g_amec->thermaldimm.temp_timeout = l_frudata[DATA_FRU_DIMM].max_read_timeout;

        TRAC_INFO("AMEC_data_write_thrm_thresholds: DIMM setpoints - DVFS: %u, Error: %u",
                  l_dvfs_temp, l_error);

        // Store the VRM Vdd thermal data
        if (!l_pm_limits)
        {
            // use normal thresholds for Nominal or OPAL
            l_dvfs_temp = l_frudata[DATA_FRU_VRM_VDD].dvfs;
            l_error = l_frudata[DATA_FRU_VRM_VDD].error;
        }
        else
        {
            l_dvfs_temp = l_frudata[DATA_FRU_VRM_VDD].pm_dvfs;
            if(i_mode == OCC_MODE_TURBO)
            {
                //Need to log an error if we dvfs in static turbo mode (for mfg)
                l_error = l_dvfs_temp;
            }
            else
            {
                l_error = l_frudata[DATA_FRU_VRM_VDD].pm_error;
            }
        }
        // Store the DVFS thermal setpoint in 0.1 degrees C
        g_amec->thermalvdd.setpoint = l_dvfs_temp * 10;
        // Store the error temperature for OT detection
        g_amec->thermalvdd.ot_error = l_error;
        // Store the temperature timeout value
        g_amec->thermalvdd.temp_timeout = l_frudata[DATA_FRU_VRM_VDD].max_read_timeout;

        TRAC_INFO("AMEC_data_write_thrm_thresholds: VRM Vdd setpoints - DVFS: %u, Error: %u",
                  l_dvfs_temp, l_error);

    } while(0);

    return l_err;
}

// Function Specification
//
// Name:  AMEC_data_write_ips_config
//
// Description: This function loads data from the IPS Config data packet
// (format 0x11) into g_amec structure. This function should only by called by
// Master OCC firmware.
//
// Thread: RealTime Loop
//
// End Function Specification
errlHndl_t AMEC_data_write_ips_cnfg(void)
{
    /*------------------------------------------------------------------------*/
    /*  Local Variables                                                       */
    /*------------------------------------------------------------------------*/
    errlHndl_t                  l_err = NULL;
    cmdh_ips_config_data_t      *l_data = NULL;

    /*------------------------------------------------------------------------*/
    /*  Code                                                                  */
    /*------------------------------------------------------------------------*/
    do
    {
        // Retrieve the thermal control threshold data
        l_err = DATA_get_ips_cnfg(&l_data);
        if(l_err)
        {
            TRAC_ERR("AMEC_data_write_ips_cnfg: Error retrieving IPS config data");
            break;
        }

        // Store Idle Power Saver settings for AMEC
        // Delay times should be stored in number of samples
        g_amec->mst_ips_parms.entry_delay = l_data->iv_delayTimeforEntry *
            AMEC_DPS_SAMPLING_RATE;
        g_amec->mst_ips_parms.exit_delay = l_data->iv_delayTimeforExit *
            AMEC_DPS_SAMPLING_RATE;

        // Utilization thresholds should be stored in hundredths of a percent
        g_amec->mst_ips_parms.entry_threshold = l_data->iv_utilizationForEntry * 100;
        g_amec->mst_ips_parms.exit_threshold = l_data->iv_utilizationForExit * 100;

        // Enable/disable Idle Power Saver
        g_amec->mst_ips_parms.enable = l_data->iv_ipsEnabled;

    } while(0);

    return l_err;
}

// Function Specification
//
// Name: AMEC_data_change
//
// Description:
//
// Thread: RealTime Loop
//
// Task Flags:
//
// End Function Specification
errlHndl_t AMEC_data_change(const uint32_t i_data_mask)
{
    /*------------------------------------------------------------------------*/
    /*  Local Variables                                                       */
    /*------------------------------------------------------------------------*/
    errlHndl_t                  l_err       = NULL;
    OCC_MODE                    l_cur_mode  = OCC_MODE_NOCHANGE;

    /*------------------------------------------------------------------------*/
    /*  Code                                                                  */
    /*------------------------------------------------------------------------*/
    //l_cur_state = CURRENT_STATE();
    l_cur_mode = CURRENT_MODE();

    //If we received the frequency from TMGT
    if(i_data_mask & DATA_MASK_FREQ_PRESENT)
    {
        l_err = AMEC_data_write_fcurr(l_cur_mode);

        if(l_err)
        {
            TRAC_ERR("AMEC_data_change: Error writing frequency range!");
        }
    }
    else if(i_data_mask & DATA_MASK_THRM_THRESHOLDS)
    {
        l_err = AMEC_data_write_thrm_thresholds(l_cur_mode);

        if(l_err)
        {
            TRAC_ERR("AMEC_data_change: Error writing thermal threshold data!");
        }
    }
    else if(i_data_mask & DATA_MASK_IPS_CNFG)
    {
        l_err = AMEC_data_write_ips_cnfg();

        if(l_err)
        {
            TRAC_ERR("AMEC_data_change: Error writing IPS config data!");
        }
    }

    return l_err;
}

// Function Specification
//
// Name: amec_data_write_pcap
//
// Description: Function called by slave interrupt handler to collect pcap
//              data sent by Master OCC.
//              If a new packet is received from Master, it will be written to
//              G_sysConfigData.pcap, and g_amec->pcap will be updated too.
//              Otherwise nothing happens.
//
// Thread: Interrupt Handler
//
// End Function Specification
void amec_data_write_pcap(void)
{
    /*------------------------------------------------------------------------*/
    /*  Local Variables                                                       */
    /*------------------------------------------------------------------------*/
    static uint8_t  L_pcap_data_count = 0;
    uint16_t        l_customer = 0;
    uint16_t        l_system   = 0;

    /*------------------------------------------------------------------------*/
    /*  Code                                                                  */
    /*------------------------------------------------------------------------*/

    //Check if Master sent a new packet of data.
    if(L_pcap_data_count != G_dcom_slv_inbox_doorbell_rx.pcap.pcap_data_count)
    {
        //Update counter
        L_pcap_data_count = G_dcom_slv_inbox_doorbell_rx.pcap.pcap_data_count;

        //Copy pcap data received from Master OCC to G_sysConfigData
        memcpy(&(G_sysConfigData.pcap),&(G_dcom_slv_inbox_doorbell_rx.pcap),
               sizeof(pcap_config_data_t));

        //Check node power cap requested by customer/system.
        // 0 means there is no pcap for that parameter.
        if(0 == G_sysConfigData.pcap.current_pcap)
        {
            l_customer = 0xFFFF;
        }
        else
        {
            l_customer = G_sysConfigData.pcap.current_pcap;
        }

        //Check fixed node power cap required by the system.
        // 0 means there is no pcap for that parameter.
        if(0 == G_sysConfigData.pcap.system_pcap)
        {
            l_system = 0xFFFF;
        }
        else
        {
            l_system = G_sysConfigData.pcap.system_pcap;
        }

        //Set the normal node pcap to the least of both system and customer pcap.
        if(l_customer < l_system)
        {
            g_amec->pcap.norm_node_pcap = l_customer;
        }
        else
        {
            g_amec->pcap.norm_node_pcap = l_system;
        }

        ///////////////////////////////
        //Set the oversubscription pcap
        if(0 != G_sysConfigData.pcap.oversub_pcap)
        {
            g_amec->pcap.ovs_node_pcap = G_sysConfigData.pcap.oversub_pcap;
        }
        else
        {
            g_amec->pcap.ovs_node_pcap = G_sysConfigData.pcap.hard_min_pcap;
        }

        //for all new pcap data setting: If KVM, update the OPAL dynamic data
        if(G_sysConfigData.system_type.kvm)
        {
            ssx_semaphore_post(&G_dcomThreadWakeupSem);
        }

        // update data mask notifying we got pcap information
        extern data_cnfg_t * G_data_cnfg;
        G_data_cnfg->data_mask |= DATA_MASK_PCAP_PRESENT;
        TRAC_IMP("amec_data_write: PCAP Config data: pcap[%d]: data_mask[%x]",
                 g_amec->pcap.norm_node_pcap, G_data_cnfg->data_mask);
    }
}

/*----------------------------------------------------------------------------*/
/* End                                                                        */
/*----------------------------------------------------------------------------*/
OpenPOWER on IntegriCloud