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

//*************************************************************************/
// Includes
//*************************************************************************/
#include <common_types.h>       // imageHdr_t declaration and image header macro
#include <errl.h>               // For error handle
#include <dpss.h>
#include <trac.h>               // For traces
#include <occ_sys_config.h>
#include <occ_service_codes.h>  // for SSX_GENERIC_FAILURE
#include <pss_service_codes.h>
#include <state.h>

//*************************************************************************/
// Externs
//*************************************************************************/
extern PoreEntryPoint GPE_dpss_send_command_stream;
extern PoreFlex G_dpss_read_status_request;
extern gpeDpssCommandStream_t G_gpe_dpss_read_status;

//*************************************************************************/
// Macros
//*************************************************************************/

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

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

//*************************************************************************/
// Globals
//*************************************************************************/

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

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

// Function Specification
//
// Name:  dpss_initialize
//
// Description: Initializes DPSS fans and oversubscription interrupt
//   If errHndl is returned, caller should call this function again,
//   one time only, in the hopes that it will work on the retry.
//
// End Function Specification
errlHndl_t dpss_initialize(void)
{
    errlHndl_t l_err = NULL;
    PoreFlex request;
    uint8_t i, l_idx_limit;  // index counter and limit value

    // Build command data
    // Structures from this array we will be passed into our GPE program one-by-one
    gpeDpssCommandStream_t l_gpe_dpss_stream_dpss_config[] = {

        { .dpss_msg_stream = {
              .command[0] = DPSS_CMD_SET_MIN_FANS  | G_sysConfigData.dpss_fan.min_fans,
              .command[1] = DPSS_CMD_SET_PWM_DELAY | G_sysConfigData.dpss_fan.pwm_delay_reg,
              .command[2] = DPSS_CMD_SET_PWM_STEP  | G_sysConfigData.dpss_fan.pwm_step_reg,
              .command[3] = 0x0000,
              .response = {0}
          },
        },

        { .dpss_msg_stream = {
              .command[0] = DPSS_CMD_SET_FAN_PPR_0 | G_sysConfigData.dpss_fan.fan_ppr[0],
              .command[1] = DPSS_CMD_SET_FAN_PPR_1 | G_sysConfigData.dpss_fan.fan_ppr[1],
              .command[2] = 0x0000,
              .command[3] = 0x0000,
              .response = {0}
          },
        },

        // Fan hysterisis: write low byte, then high byte
        { .dpss_msg_stream = {
              .command[0] = DPSS_CMD_SET_FAN_HYST_1_LO | G_sysConfigData.dpss_fan.fan_hysterisis[1],
              .command[1] = DPSS_CMD_SET_FAN_HYST_0_HI | G_sysConfigData.dpss_fan.fan_hysterisis[0],
              .command[2] = 0x0000,
              .command[3] = 0x0000,
              .response = {0}
          },
        },

        // Fan hysterisis: write low byte, then high byte
        { .dpss_msg_stream = {
              .command[0] = DPSS_CMD_SET_FAN_HYST_3_LO | G_sysConfigData.dpss_fan.fan_hysterisis[3],
              .command[1] = DPSS_CMD_SET_FAN_HYST_2_HI | G_sysConfigData.dpss_fan.fan_hysterisis[2],
              .command[2] = DPSS_CMD_SET_FAN_MODE      | G_sysConfigData.dpss_fan.fan_mode,
              .command[3] = 0x0000,
              .response = {0}
          },
        },

        { .dpss_msg_stream = {
              .command[0] = DPSS_CMD_SET_FAN_MASK      | G_sysConfigData.dpss_fan.fan_mask,
              .command[1] = DPSS_CMD_SET_FAN_HYST_MASK | G_sysConfigData.dpss_fan.fan_hyst_mask,
              .command[2] = DPSS_CMD_SET_MAX_FAN_PWM   | G_sysConfigData.dpss_fan.max_fan_pwm,
              .command[3] = 0x0000,
              .response = {0}
          },
        },

        { .dpss_msg_stream = {
              .command[0] = DPSS_CMD_SET_MIN_PWM  | G_sysConfigData.dpss_fan.min_pwm,
              .command[1] = DPSS_CMD_SET_SPI_FFS  | G_sysConfigData.dpss_fan.spi_ffs,
              .command[2] = DPSS_CMD_SET_SPIS_INT_MASK   | G_sysConfigData.dpss_spis_int_mask,
              .command[3] = 0x0000,
              .response = {0}
          },
        },

        { .dpss_msg_stream = {
              .command[0] = DPSS_CMD_SET_END_COUNT       | G_sysConfigData.dpss_fan.end_count_reg,
              .command[1] = DPSS_CMD_SET_FAN_WARN_COUNT  | G_sysConfigData.dpss_fan.fan_warning_cnt,
              .command[2] = 0x0000,
              .command[3] = 0x0000,
              .response = {0}
          },
        },
    };

    // Calculate the array size dynamically so we don't have to update it if the array changes.
    l_idx_limit = sizeof(l_gpe_dpss_stream_dpss_config) / sizeof(gpeDpssCommandStream_t);

    for( i = 0; i < l_idx_limit; i++) {
        // Clear the error reporting parts of the argument structure.
        l_gpe_dpss_stream_dpss_config[i].gpe_error.error = 0;
        l_gpe_dpss_stream_dpss_config[i].gpe_error.ffdc  = 0;

        // Create GPE program request
        DPSS_DEBUG_PRINTF(("%s: Calling GPE_dpss_send_command_stream for index %d\n", __FUNCTION__, i));
        pore_flex_create(&request,                                    // request
                         &pore_gpe0_queue,                            // queue
                         (void*)GPE_dpss_send_command_stream,         // GPE entry_point
                         (uint32_t)&l_gpe_dpss_stream_dpss_config[i], // GPE argument_ptr
                         NULL,                                        // callback
                         NULL,                                        // callback arg
                         ASYNC_REQUEST_BLOCKING);                     // options

        // Schedule the request to be executed
        // Because our GPE structures are not in non-cacheable RAM (they are in the .init section instead),
        // we have to flush the dcache before making the pore flex request, then invalidate the dcache afterward.
        dcache_flush(&l_gpe_dpss_stream_dpss_config[i], sizeof(l_gpe_dpss_stream_dpss_config[i]));
        pore_flex_schedule(&request);
        dcache_invalidate((void *)(&l_gpe_dpss_stream_dpss_config[i]), sizeof(l_gpe_dpss_stream_dpss_config[i]));

        DPSS_DEBUG_PRINTF(("%s: GPE_dpss_send_command_stream for index %d returned: 0x%08X\n", __FUNCTION__, i, l_gpe_dpss_stream_dpss_config[i].gpe_error.rc));
        DPSS_DEBUG_PRINTF(("\tcommand[0] = 0x%04x, response[0] = 0x%04x\n", l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.command[0], l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.response[0]));
        DPSS_DEBUG_PRINTF(("\tcommand[1] = 0x%04x, response[1] = 0x%04x\n", l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.command[1], l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.response[1]));
        DPSS_DEBUG_PRINTF(("\tcommand[2] = 0x%04x, response[2] = 0x%04x\n", l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.command[2], l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.response[2]));
        DPSS_DEBUG_PRINTF(("\tcommand[3] = 0x%04x, response[3] = 0x%04x\n", l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.command[3], l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.response[3]));

        // Check for errors and invalid DPSS responses.
        // (Valid DPSS responses should be an echo of the cmd & data passed in).
        if ( (l_gpe_dpss_stream_dpss_config[i].gpe_error.rc != 0) ||
             (l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.response[0] != l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.command[0]) ||
             (l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.response[1] != l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.command[1]) ||
             (l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.response[2] != l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.command[2]) )
        {
            DPSS_DEBUG_PRINTF(("%s: ...Failed with error.\n", __FUNCTION__));

            /*@
             * @moduleid   PSS_MID_DPSS_INIT
             * @reasonCode INTERNAL_HW_FAILURE
             * @severity   ERRL_SEV_UNRECOVERABLE
             * @userdata1  GPE error return code
             * @userdata2  GPE error ffdc
             * @userdata4  OCC_NO_EXTENDED_RC
             * @devdesc    GPE command failed to initialize the DPSS
             */
            l_err = createErrl(PSS_MID_DPSS_INIT,       // i_modId,
                               INTERNAL_HW_FAILURE,     // i_reasonCode,
                               OCC_NO_EXTENDED_RC,      // extended reason code // @nh001a
                               ERRL_SEV_UNRECOVERABLE,
                               NULL,                    // tracDesc_t i_trace,
                               0x0000,                  // i_traceSz,
                               l_gpe_dpss_stream_dpss_config[i].gpe_error.rc,          // i_userData1,
                               l_gpe_dpss_stream_dpss_config[i].gpe_error.ffdc >> 32); // i_userData2

            // Put extra debug info into local data struct
            addUsrDtlsToErrl(l_err,
                             (uint8_t*)&l_gpe_dpss_stream_dpss_config[i],
                             sizeof(l_gpe_dpss_stream_dpss_config[i]),
                             ERRL_STRUCT_VERSION_1,
                             ERRL_USR_DTL_TRACE_DATA);
            break;
        }
        else {
            DPSS_DEBUG_PRINTF(("%s: ...Success!\n", __FUNCTION__));
        }
    }

    return l_err;
}

// Function Specification
//
// Name:  dpssInitApplet (old name is start_dpss)
//
// Description:
// Entry-point for enabling DPSS functionality.
// Initializes the DPSS chip.  Starts the "DPSS Read Status" RTLS task.
//
// End Function Specification
errlHndl_t dpssInitApplet(void * i_arg)
{
    // Init DPSS
    TRAC_INFO("Initializing DPSS registers...");

    errlHndl_t l_errl = dpss_initialize();

    if (l_errl)
    {
        // init failed, attempt one more time before giving up
        TRAC_ERR("dpss_initialize failed! (retrying)...");

        // Convert the error severity to info and log it.
        setErrlSevToInfo(l_errl);
        commitErrl( &l_errl );

        l_errl = dpss_initialize();

        if (l_errl)
        {
            TRAC_ERR("dpss_initialize failed again!  OCC will be reset.");
            // Log the error with its original unrecoverable severity
            commitErrl( &l_errl );
            REQUEST_RESET();
        }
    }

    if (!l_errl)
    {
        TRAC_INFO("...DPSS initialized.");
        TRAC_INFO("Enabling DPSS Read Status RTLS task.");

        // Init the global DPSS read-status PORE flex request.
        // None of these values is expected to change.
        pore_flex_create(&G_dpss_read_status_request,                 // request
                         &pore_gpe0_queue,                            // queue
                         (void*)GPE_dpss_send_command_stream,         // GPE entry_point
                         (uint32_t)&G_gpe_dpss_read_status,           // GPE argument_ptr
                         NULL,                                        // callback
                         NULL,                                        // callback arg
                         0);                                          // options  DO NOT set this to ASYNC_REQUEST_BLOCKING

        // Make this task runnable.
        rtl_start_task(TASK_ID_DPSS_RD_STATUS);
    }

    return l_errl;
}

OpenPOWER on IntegriCloud