summaryrefslogtreecommitdiffstats
path: root/src/occApplet/productApplet/dpssInitApplet.c
blob: 5015feb5d0fe296c8b449d2cd3b216db41835d76 (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
/******************************************************************************
// @file dpssInitApplet.c
// @brief DPSS initialization product applet
*/
/******************************************************************************
 *
 *       @page ChangeLogs Change Logs
 *       @section dpssInitApplet.c DPSSINITAPPLET.c
 *       @verbatim
 *
 *   Flag    Def/Fea    Userid    Date        Description
 *   ------- ---------- --------  ----------  ----------------------------------
 *   @at000             alvinwan  12/07/2011  created
 *   @dw000              dwoodham  12/16/2011  Update call to IMAGE_HEADER
 *   @rc003             rickylie  02/03/2012  Verify & Clean Up OCC Headers & Comments
 *   @nh001             neilhsu   05/23/2012  Add missing error log tags 
 *
 *  @endverbatim
 *
 *///*************************************************************************/
 
 
//*************************************************************************
// 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  // @nh001a
#include <pss_service_codes.h>
#include <state.h>
#include <appletId.h>           // For applet ID num dw000a

//*************************************************************************
// 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
//*************************************************************************
#define DPSSINITAPPLET_ID  "DPSS_Init_Aplt\0"

//*************************************************************************
// 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.
//
// Flow:  08/03/11    FN=dpss_initialize
//
// 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;
} // end dpss_initialize()

// 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.
//
// Flow: 08/03/11    FN=dpss_initialize
// Modified from original flow (approved, T. Hallett, 10/03/2011).
// Further mods recommended in DPSS code review 10/19/2011.
//
// 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();     // @th006
        }
    }

    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;
} // end dpssInitApplet





/*****************************************************************************/
// Image Header
/*****************************************************************************/
// @dw000 - Add applet ID arg to IMAGE_HEADER macro call
// TODO: Change this if/when DPSS is enabled.
IMAGE_HEADER (G_dpssInitApplet,dpssInitApplet,DPSSINITAPPLET_ID,OCC_APLT_INVALID);

OpenPOWER on IntegriCloud