summaryrefslogtreecommitdiffstats
path: root/src/usr/util/runtime/rt_fwnotify.C
blob: 939270c3c3bbc1cb9a8fde0bf1d5d50755b78054 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/util/runtime/rt_fwnotify.C $                          */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,2017                        */
/* [+] 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 <sbeio/sbe_retry_handler.H>       // SbeRetryHandler
#include <runtime/interface.h>             // firmware_notify
#include <runtime/runtime_reasoncodes.H>   // MOD_RT_FIRMWARE_NOTIFY, etc
#include <errl/errlentry.H>                // ErrlEntry
#include <errl/errlmanager.H>              // errlCommit
#include <targeting/common/target.H>       // TargetHandle_t, getTargetFromHuid

using namespace TARGETING;
using namespace RUNTIME;
using namespace ERRORLOG;
using namespace MBOX;
//using namespace SBEIO;

trace_desc_t* g_trac_hwsv = nullptr;
TRAC_INIT(&g_trac_hwsv, "HWSV_TRACE", 4*KILOBYTE);

/**
  * @brief The lower and upper bounds for the sequence ID.
  **/
const uint16_t GFMM_SEQ_ID_MIN = 0x0000;
const uint16_t GFMM_SEQ_ID_MAX =  0x7FFF;

/**
  * @brief Set the sequence ID to the minimum value
  **/
uint16_t SeqId_t::GFMM_SEQ_ID = GFMM_SEQ_ID_MIN;

/**
 *  @brief Gets the next sequence ID.
 *  @return The next sequence ID value within it's lower and upper bound
 **/
uint16_t SeqId_t::getNextSeqId()
{
    if (SeqId_t::GFMM_SEQ_ID < GFMM_SEQ_ID_MAX)
    {
        ++SeqId_t::GFMM_SEQ_ID;
    }
    else
    {
        SeqId_t::GFMM_SEQ_ID = GFMM_SEQ_ID_MIN;
    }

    return SeqId_t::GFMM_SEQ_ID;
}

/**
 *  @brief Gets the current value of the sequence ID.
 *  @return The current value of the sequence ID.
 **/
uint16_t SeqId_t::getCurrentSeqId()
{
  return SeqId_t::GFMM_SEQ_ID;
}

/**
 *  @brief Attempt an SBE recovery after an SBE error
 *  @param[in] uint64_t i_data Contains and plid (in the first 4 bytes)
 *                             and a HUID (in the last 4 bytes)
 *  @platform FSP, OpenPOWER
 **/
void sbeAttemptRecovery(uint64_t i_data)
{
    errlHndl_t l_err = nullptr;

    do
    {
        // Create a useful structure to get to the data
        // The data is expected to be a plid (in the first 4 bytes)
        // followed by a HUID (in the last 4 bytes).
        struct sbeErrorData_t
        {
            uint32_t plid;
            uint32_t huid;
        } PACKED ;

        sbeErrorData_t *l_sbeErrorDataReq = (sbeErrorData_t*)(&i_data);
        TargetHandle_t l_target =
                        Target::getTargetFromHuid(l_sbeErrorDataReq->huid);
        if (nullptr == l_target)
        {
             TRACFCOMP( g_trac_hwsv, "firmware_notify: No target assoicated "
                       "with HUID:0x%.8X", l_sbeErrorDataReq->huid);
            /*@
             * @errortype    ERRL_SEV_PREDICTIVE
             * @moduleid     RUNTIME::MOD_RT_FIRMWARE_NOTIFY
             * @reasoncode   RUNTIME::RC_SBE_RT_INVALID_HUID
             * @userdata1    HUID of target
             * @userdata2    HWSV error log id (plid)
             * @devdesc      SBE error recovery attempt failed
             */
            l_err = new ErrlEntry( ERRL_SEV_PREDICTIVE,
                                   MOD_RT_FIRMWARE_NOTIFY,
                                   RC_SBE_RT_INVALID_HUID,
                                   l_sbeErrorDataReq->huid,
                                   l_sbeErrorDataReq->plid,
                                   true);
            break;
        }

        // Make the call to SbeExtractDD to attempt SBE recovery
        // Get the SBE Retry Handler
        //SbeRetryHandler l_SBEobj = SbeRetryHandler();

        // Need to set the Plid from SbeRetryHandler (still being debated)
        // to l_sbeErrorDataReq->plid;

        // Retry the recovery of the SBE
        //l_SBEobj.main_sbe_handler(l_target, false);

        // Get the recovery results
        // NOTE: This method is not in place yet
        //bool l_recoverySuccessful = l_SBEobj.isSbeRestarted();

        // Set to TRUE for now
        bool l_recoverySuccessful = true;

        if (nullptr == g_hostInterfaces ||
            nullptr == g_hostInterfaces->firmware_request)
        {
             TRACFCOMP( g_trac_hwsv, "firmware_notify: Hypervisor "
                       "firmware_request interface not linked");

            /*@
             * @errortype    ERRL_SEV_PREDICTIVE
             * @moduleid     RUNTIME::MOD_RT_FIRMWARE_NOTIFY
             * @reasoncode   RUNTIME::RC_FW_REQUEST_RT_NULL_PTR
             * @userdata1    HUID of target
             * @userdata2    HWSV error log id (plid)
             * @devdesc      SBE error recovery attempt failed
             */
            l_err = new ErrlEntry( ERRL_SEV_PREDICTIVE,
                                   MOD_RT_FIRMWARE_NOTIFY,
                                   RC_FW_REQUEST_RT_NULL_PTR,
                                   l_sbeErrorDataReq->huid,
                                   l_sbeErrorDataReq->plid,
                                   true);


           break;
        }

        // Create the firmware_request request structure to send data
        hostInterfaces::hbrt_fw_msg l_req_fw_msg;
        memset(&l_req_fw_msg, 0, sizeof(l_req_fw_msg));

        // Set the data for the request
        l_req_fw_msg.io_type = hostInterfaces::HBRT_FW_MSG_HBRT_FSP_REQ;
        l_req_fw_msg.generic_msg.initialize();
        l_req_fw_msg.generic_msg.msgq = GFMM_MSG_SBE_ERROR;
        l_req_fw_msg.generic_msg.__req = GFMM_REQUEST;
        l_req_fw_msg.generic_msg.__onlyError = GFMM_NOT_ERROR_ONLY;
        l_req_fw_msg.generic_msg.data = i_data;

        if (l_recoverySuccessful)
        {
            l_req_fw_msg.generic_msg.msgType= GFMM_MSG_SBE_RECOVERY_SUCCESS;
        }
        else
        {
            l_req_fw_msg.generic_msg.msgType = GFMM_MSG_SBE_RECOVERY_FAILED;
        }

        // Create the firmware_request response structure to receive data
        hostInterfaces::hbrt_fw_msg l_resp_fw_msg;
        size_t l_resp_fw_msg_size = sizeof(l_resp_fw_msg);
        memset(&l_resp_fw_msg, 0, l_resp_fw_msg_size);

        size_t rc = g_hostInterfaces->firmware_request(sizeof(l_req_fw_msg),
                                                       &l_req_fw_msg,
                                                       &l_resp_fw_msg_size,
                                                       &l_resp_fw_msg);

        // Error log id
        uint32_t l_errPlid(0);

        sbeErrorData_t *l_sbeErrorDataResp =
                   (sbeErrorData_t*)&(l_resp_fw_msg.generic_msg.data);

        // Capture the error log ID if any
        // The return code (rc) may return OK, but there still may be an issue
        // with the HWSV code on the FSP.
        if ((hostInterfaces::HBRT_FW_MSG_HBRT_FSP_RESP
                                                  == l_resp_fw_msg.io_type) &&
           (0 != l_sbeErrorDataResp->plid) )
        {
            l_errPlid = l_sbeErrorDataResp->plid;
        }

        // Gather up the error data and create an error log out of it
        if (rc || l_errPlid)
        {
            /*@
             * @errortype        ERRL_SEV_PREDICTIVE
             * @moduleid         RUNTIME::MOD_RT_FIRMWARE_NOTIFY
             * @reasoncode       RUNTIME::RC_SBE_RT_RECOVERY_ERR
             * @userdata1[0:31]  Firmware Request return code
             * @userdata1[32:63] HWSV error log id (plid)
             * @userdata2[0:31]  MBOX message type
             * @userdata2[32:63] Message Tyepe
             * @devdesc          SBE error recovery attempt failed
             */
            l_err = new ERRORLOG::ErrlEntry(
                                   ERRL_SEV_PREDICTIVE,
                                   MOD_RT_FIRMWARE_NOTIFY,
                                   RC_SBE_RT_RECOVERY_ERR,
                                   TWO_UINT32_TO_UINT64(rc, l_errPlid),
                                   TWO_UINT32_TO_UINT64(
                                   l_resp_fw_msg.generic_msg.msgq,
                                   l_resp_fw_msg.generic_msg.msgType),
                                   true);

            l_err->addFFDC( RUNTIME_COMP_ID,
                            &l_resp_fw_msg,
                            l_resp_fw_msg_size,
                            0, 0, false );

            if (sizeof(l_req_fw_msg) > 0)
            {
                l_err->addFFDC( RUNTIME_COMP_ID,
                                &l_req_fw_msg,
                                sizeof(l_req_fw_msg),
                                0, 0, false );
            }

            l_err->collectTrace( "SBE", 256);

            if (l_errPlid)
            {
                l_err->plid(l_errPlid);
            }

            break;
        }
    } while(0);

    if (l_err)
    {
       //Commit the error if it exists
       errlCommit(l_err, RUNTIME_COMP_ID);
    }
}

/**
 * @brief Receive an async notification from firmware
 * @param[in] i_len   length of notification data
 * @param[in] i_data  notification data
 * @platform FSP, OpenPOWER
 */
void firmware_notify( uint64_t i_len, void *i_data )
{
    errlHndl_t l_err = nullptr;

    do
    {
        // make sure the length of the data is not less than the
        // structure we are expecting to receive
        if (i_len < sizeof(GenericFspMboxMessage_t))
        {
            TRACFCOMP( g_trac_hwsv,
               "firmware_notify: Received a non GenericFspMboxMessage "
               "data stream" );

            /*@
             * @errortype
             * @moduleid     RUNTIME::MOD_RT_FIRMWARE_NOTIFY
             * @reasoncode   RUNTIME::RC_FW_NOTIFY_RT_INVALID_MSG
             * @userdata1    Unused
             * @userdata2    Unused
             * @devdesc      Error with Firmware Notify request
             */
            l_err = new ErrlEntry( ERRL_SEV_PREDICTIVE,
                                   MOD_RT_FIRMWARE_NOTIFY,
                                   RC_FW_NOTIFY_RT_INVALID_MSG,
                                   0, 0, true);
            break;
        }

        // Cast the data to the structure we wish to parse
        GenericFspMboxMessage_t* genericMsg =
                       static_cast<GenericFspMboxMessage_t*>(i_data);

        // Do function based on message type (msgType)
        switch(genericMsg->msgType)
        {
           case GFMM_MSG_SBE_ERROR: sbeAttemptRecovery(genericMsg->data);
               break;

           default:
               {
                   TRACFCOMP( g_trac_hwsv, "firmware_notify: Unknown "
                              "message type:0x%.8X, message queue id:0x%.8X ",
                              genericMsg->msgq, genericMsg->msgType);

                   /*@
                    * @errortype
                    * @moduleid     RUNTIME::MOD_RT_FIRMWARE_NOTIFY
                    * @reasoncode   RUNTIME::RC_FW_NOTIFY_RT_INVALID_MSG_TYPE
                    * @userdata1    Message Queue ID
                    * @userdata2    Message Type
                    * @devdesc      Error with Firmware Notify request
                    */
                   l_err = new ErrlEntry( ERRL_SEV_PREDICTIVE,
                                          MOD_RT_FIRMWARE_NOTIFY,
                                          RC_FW_NOTIFY_RT_INVALID_MSG_TYPE,
                                          genericMsg->msgq,
                                          genericMsg->msgType,
                                          true);
               }
               break;
        };

    } while(0);

    if (l_err)
    {
       //Commit the error if it exists
       errlCommit(l_err, RUNTIME_COMP_ID);
    }
};

struct registerFwNotify
{
    registerFwNotify()
    {
        getRuntimeInterfaces()->firmware_notify = &firmware_notify;
    }
};

registerFwNotify g_registerFwNotify;
OpenPOWER on IntegriCloud