summaryrefslogtreecommitdiffstats
path: root/src/occ_405/cmdh/cmdh_tunable_parms.c
blob: 4c88f6583295ca4fec1e0344d77c438f3086b6dc (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/occ_405/cmdh/cmdh_tunable_parms.c $                       */
/*                                                                        */
/* OpenPOWER OnChipController Project                                     */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2011,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                                                     */

#include "cmdh_tunable_parms.h"
#include "cmdh_service_codes.h"
#include "cmdh_fsp_cmds.h"
#include "dcom.h"

// Function Specification
//
// Name:  cmdh_tunable_parms_query
//
// Description: This function returns all supported tuanble parameters from the
// Tunable Parameters List that this system type supports.
//
// End Function Specification
uint8_t cmdh_tunable_parms_query(   const cmdh_fsp_cmd_t * i_cmd_ptr,
                                    cmdh_fsp_rsp_t * o_rsp_ptr)
{
    uint8_t                     l_rc = ERRL_RC_SUCCESS;
    uint16_t                    l_numParms = 0;
    tunable_parms_query_cmd_t  *l_cmd_ptr = (tunable_parms_query_cmd_t*) i_cmd_ptr;
    tunable_parms_query_rsp_t  *l_rsp_ptr = (tunable_parms_query_rsp_t*) o_rsp_ptr;

    do
    {
        // Check version
        if ( l_cmd_ptr->version !=  TUNABLE_PARMS_QUERY_VERSION )
        {
            TRAC_ERR("cmdh_tunable_parms_query: Tunable Parms invalid version: %x", l_cmd_ptr->version );
            l_rc = ERRL_RC_INVALID_DATA;
            break;
        }


        // Start setting up response ::

        // Version
        l_rsp_ptr->version = TUNABLE_PARMS_QUERY_VERSION;

        // Number of parameters
        l_numParms = sizeof(G_mst_tunable_parameter_table) / sizeof (cmdh_tunable_param_table_t);
        l_rsp_ptr->numParms = l_numParms;

        TRAC_INFO("cmdh_tunable_parms_query: Found %d entries", l_numParms );

        // Copy complete global array data into response
        memcpy( l_rsp_ptr->data, G_mst_tunable_parameter_table, sizeof(G_mst_tunable_parameter_table) );

    }while(0);

    // Setup the response data packet info
    uint16_t l_size = 2 + sizeof(G_mst_tunable_parameter_table);
    G_rsp_status = l_rc;
    o_rsp_ptr->data_length[0] = ((uint8_t *)&l_size)[0];
    o_rsp_ptr->data_length[1] = ((uint8_t *)&l_size)[1];

    return l_rc;
}

// Function Specification
//
// Name:  cmdh_tunable_parms_write
//
// Description: This function is used to set the values for tunable parameters
//
// End Function Specification
uint8_t cmdh_tunable_parms_write(   const cmdh_fsp_cmd_t * i_cmd_ptr,
                                    cmdh_fsp_rsp_t * o_rsp_ptr)
{
    uint8_t                     l_rc = ERRL_RC_SUCCESS;
    tunable_parms_write_cmd_t  *l_cmd_ptr = (tunable_parms_write_cmd_t*) i_cmd_ptr;

    do
    {
        // Check version
        if ( l_cmd_ptr->version !=  TUNABLE_PARMS_WRITE_VERSION )
        {
            TRAC_ERR("cmdh_tunable_parms_write: Tunable Parms invalid version: %x", l_cmd_ptr->version );
            l_rc = ERRL_RC_INVALID_DATA;
            break;
        }

        // Loop through each parameter entry sent
        uint8_t i = 0;
        for (i=0; i < l_cmd_ptr->numParms; i++)
        {
            // Check if id is valid
            uint8_t l_id = l_cmd_ptr->data[i].id;
            if ( (l_id>0) && (l_id<=CMDH_DEFAULT_TUNABLE_PARAM_NUM) )
            {
                // Save off value
                G_mst_tunable_parameter_table[l_id-1].value = CONVERT_UINT8_ARRAY_UINT16(l_cmd_ptr->data[i].value[0], l_cmd_ptr->data[i].value[1]);
                G_mst_tunable_parameter_table_ext[l_id-1].adj_value = G_mst_tunable_parameter_table[l_id-1].value*G_mst_tunable_parameter_table_ext[l_id-1].multiplier;

                TRAC_INFO("New tunable parameter value received: id[%u] value[%u] adj_value[%u]",
                          l_id,
                          G_mst_tunable_parameter_table[l_id-1].value,
                          G_mst_tunable_parameter_table_ext[l_id-1].adj_value);
            }
            else
            {
                TRAC_INFO("cmdh_tunable_parms_write: Tunable Parms invalid data found id=%x, value=%x",
                        l_id, CONVERT_UINT8_ARRAY_UINT16(l_cmd_ptr->data[i].value[0], l_cmd_ptr->data[i].value[1]) );

                l_rc = ERRL_RC_INVALID_DATA;
            }
        }

    }while(0);

    // Populate the response data packet
    G_rsp_status = l_rc;

    // Set global var
    G_mst_tunable_parameter_overwrite = 1;

    return l_rc;
}

// Function Specification
//
// Name:  cmdh_tunable_parms_restore
//
// Description: This is used to tell OCC to use default value for all supported
// tunable parameters defined in the Tunable Parameters list.
//
// End Function Specification
uint8_t cmdh_tunable_parms_restore(const cmdh_fsp_cmd_t * i_cmd_ptr,
                           cmdh_fsp_rsp_t * o_rsp_ptr)
{
    uint8_t                         l_rc = ERRL_RC_SUCCESS;

    do
    {
        // Loop through global array
        uint8_t i = 0;
        for (i=0; i<CMDH_DEFAULT_TUNABLE_PARAM_NUM; i++)
        {
            // Update value using default value
            G_mst_tunable_parameter_table[i].value = G_mst_tunable_parameter_table_ext[i].def_value;
            G_mst_tunable_parameter_table_ext[i].adj_value = G_mst_tunable_parameter_table_ext[i].def_value*G_mst_tunable_parameter_table_ext[i].multiplier;
        }

    }while(0);

    // Populate the response data header
    G_rsp_status = l_rc;

    // Set global var
    G_mst_tunable_parameter_overwrite = 2;

    return l_rc;
}



// Function Specification
//
// Name:  cmdh_tunable_parms
//
// Description:  This function parses the tunable parms commands sent via TMGT.
//
// End Function Specification
errlHndl_t cmdh_tunable_parms (   const cmdh_fsp_cmd_t * i_cmd_ptr,
                            cmdh_fsp_rsp_t * o_rsp_ptr)
{
    uint8_t                     l_rc = 0;
    uint8_t                     l_sub_cmd = 0;
    errlHndl_t                  l_errl = NULL;

    do
    {
        // Command is only supported on Master OCC
        if (G_occ_role == OCC_SLAVE)
        {
            TRAC_ERR("cmdh_tunable_parms: Tunable Parameters command not supported on Slave OCCs!");
            l_rc = ERRL_RC_INVALID_CMD;
            break;
        }

        // Sub-command is always first byte of data
        l_sub_cmd = i_cmd_ptr->data[0];

        TRAC_INFO("cmdh_tunable_parms: Tunable Parms sub-command [%d]", l_sub_cmd );

        switch (l_sub_cmd)
        {
            case TUNABLE_PARMS_QUERY:
                l_rc = cmdh_tunable_parms_query(i_cmd_ptr, o_rsp_ptr);
                break;

            case TUNABLE_PARMS_WRITE:
                l_rc = cmdh_tunable_parms_write(i_cmd_ptr, o_rsp_ptr);
                break;

            case TUNABLE_PARMS_RESTORE:
                l_rc = cmdh_tunable_parms_restore(i_cmd_ptr, o_rsp_ptr);
                break;

            default:
                // Should never get here...
                l_rc = ERRL_RC_INVALID_DATA;
                break;
        }
    } while (0);

    // All errors in TUNABLE PARMS logged internally
    if (l_rc)
    {
        TRAC_ERR("Tunable Parms command 0x%02x failed with rc = %d", l_sub_cmd, l_rc);

        // Build Error Response packet
        cmdh_build_errl_rsp(i_cmd_ptr, o_rsp_ptr, l_rc, &l_errl);
    }

    return l_errl;
}

OpenPOWER on IntegriCloud