summaryrefslogtreecommitdiffstats
path: root/src/include/usr/sbeio/sbe_ffdc_package_parser.H
blob: 1fa9cada9a76cac0a80890ac7bb43b9e62f17ed8 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/include/usr/sbeio/sbe_ffdc_package_parser.H $             */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 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                                                     */
#ifndef __SBEIO_SBE_FFDC_PACKAGE_PARSER_H
#define __SBEIO_SBE_FFDC_PACKAGE_PARSER_H

#include <stdint.h>
#include <memory>

#include <errl/errlentry.H>
#include <sbeio/sbe_ffdc_parser.H>
#include <targeting/common/target.H>

namespace SBEIO
{

/**
 * @brief A class to support processing of parsed ffdc data.
 *
 * FFDC data schema is related to RC codes. There does not
 * exist a facility code to identify common types of FFDC data.
 * Instead, each RC code is given an FFDC schema based upon settings
 * in the error_info xml files. Although many error codes share the same
 * FFDC format, there is nothing to relate similar FFDC schemas to RC values,
 * The mapping is the other way around, individual fapi RC codes map to
 * FFDC formats. In addition, because of the use of template type deduction
 * in populating FFDC data, type information which may prove useful for parsing
 * is lost. To illustrate, the SBE uses a global variable to hold FFDC data for
 * a request. The global variable contains a field for storing the fapiRC code
 * and an array of up to 10 sbeFfdc_t structs used to hold the FFDC data. For a
 * Scom PIB error, the schema of the FFDC places the scom address and size in
 * first sbeFfdc_t struct and the pib rc in the second struct. Each sbeFfdc_t
 * struct is just a uint64_t for the data and a uint32_t for the size. There
 * is no type information stored. The uint64_t in some instances can hold
 * a pointer to a target, in other instances data such as the PIB RC code and
 * yet in other cases an address such as the scom address. The Scom PIB errors
 * from the SBE uses only two of the sbeFfdc_t slots. Other errors use 3,4 or
 * more sbeFfdc_t data.
 * Because of the lack of parsing support available, this base class and
 * derived classes are manually coded to group fapi RC values with similar FFDC
 * formats in order to aid parsing of FFDC data. Currently, we only parse the
 * format used for the scom pib memory errors returned from the SBE.
 *
 *
 */
class FfdcParsedPackage
{
public:

    /**
     * @brief Used to identify FFDC schema.
     *
     */
    enum class ParsedType{
                            NONE,
                            SBE_SCOM_PIB_ERROR
                         };

    virtual ~FfdcParsedPackage() = default;

    /**
     * @brief Determines if the FFDC package was successfully parsed.
     *
     * @return True if the ffdc package was parsed, false otherwise.
     */
    bool isValid() const {return iv_packageType != ParsedType::NONE;}

    /**
     * @brief Obtain the FFDC package type that was parsed.
     */
    ParsedType parsedType() const {return iv_packageType;}

    /**
     * @brief Perform the default action on the parsed
     *        ffdc data.
     *
     * @param[in] i_target, the target of the request.
     * @param[in] i_errl, error entry for processing.
     *
     */
    virtual void operator()(TARGETING::Target* i_target,
                            errlHndl_t i_errl
                           ) const {};

    /**
     * @brief bool operator for isValid.
     *
     */
    operator bool() const {return isValid();}

    /**
     * @brief Convert fapiRC to a ParsedType.
     *
     * @param[in] fapiRc, the rc to convert.
     *
     * @return The ParsedType corresponding to fapiRc
     *
     */
    static ParsedType rcToParsedType(uint32_t fapiRc);

    /**
     * @brief parse the FFDC package and perform the default
     *        operation if parsing was successful.
     *
     * @param[in] i_ffdc_package, the ffdc to parse and process.
     * @param[in] i_target, the target of the default processing.
     * @param[in] i_errl, the ErrlEntry to be used for default processing.
     *
     */
    static void doDefaultProcessing(const ffdc_package& i_ffdc_package,
                                    TARGETING::Target* i_target,
                                    errlHndl_t i_errl
                                    );

    /**
     * @brief Parse the given FFDC data.
     *
     * @param[in] i_ffdc_package to parse.
     *
     * @return a shared pointer to an object derived from FfdcParsedPackage.
     *         If the package could not be parsed a raw FfdcParsedPackage
     *         is returned.
     */
    static std::shared_ptr<const FfdcParsedPackage>
           getParsedPackage(const ffdc_package& i_ffdc_package);

protected:

    /**
     * @brief Set the parsed ffdc type.
     *
     * @param[in] The new Parsed FFDC Type value.
     *
     */
    void parsedType(const ParsedType& i_parsedType)
    {
        iv_packageType = i_parsedType;
    }

private:

    ParsedType iv_packageType{ParsedType::NONE}; /**< The FFDC type */
};



/**
 * @brief Processing for SBE scom pib FFDC.
 *
 * The FFDC schema parsed by this class is as follows:
 *
 *        u32          u32           u64         u32          u64
 *     | FapiRC | Scom Addr Size | Scom Addr | PIB RC Size | PIB RC |
 *
 */
class FfdcScomPibErrorPackage: public FfdcParsedPackage
{
public:
    /**
     * @brief Contsructor
     *
     * @param[in] i_ffdc, the unparsed raw ffdc data.
     * @param[in] i_ignoreRC, if true then validation of the ffdc
     *            schema has already been performed by the
     *            static method doesPackageMatchSchema. In this
     *            case the rc of the ffdc does not match the list of
     *            known fapiRC values that correspond to the ffdc
     *            schema parsed by this class. However, if it is assumed
     *            that a new fapiRC is responsible for this condition
     *            then we may use this class to process the FFDC regardless
     *            of the corresponding fapiRC. This could prove useful as
     *            SBE errors in messaging currently only send Scom Pib errors
     *            as the first FFDC entry.
     */
    explicit FfdcScomPibErrorPackage(const ffdc_package& i_ffdc,
                                     bool i_ignoreRC = false);

    virtual ~FfdcScomPibErrorPackage() = default;

    /**
     * @brief Call operator for default processing. For this FFDC schema
     *        we call the addFruCallouts method.
     *
     * @param[in] i_target, the target of the default processing.
     * @param[in] i_errl, the ErrlEntry to be used for default processing.
     *
     */
    void operator() (TARGETING::Target* i_target,
                     errlHndl_t i_errl
                    ) const override;

    /**
     * @brief Use parsed data to add Fru Callouts. The method
     *        is virtual to facilitate a unit test seam.
     *
     * @param[in] i_target, the target for the callout.
     * @param[in] i_errl, the ErrlEntry to which to add the callout.
     *
     */
    virtual void addFruCallouts (TARGETING::Target* i_target,
                                 errlHndl_t i_errl
                                ) const;

    /**
     * @brief Accessor for the PIB RC parsed data.
     *
     * @return The PIB RC Code from the FFDC data.
     *
     */
    uint64_t getPibRc() const {return iv_pibRc;}

    /**
     * @brief Accessor for the PIB RC parsed data.
     *
     * @return The PIB RC Code from the FFDC data.
     *
     */
    uint64_t getScomAddress() const {return iv_scomAddress;}

    /**
     * @brief Check if the FFDC schema matches that expected by this class,
     *        with the exception of the RC code. This is intended for use
     *        when we are always expecting a certain FFDC schema from a
     *        function call but perhaps a new RC has been added that has not
     *        yet been added to those we know of.
     *
     * @param[in] i_ffdc: the ffdc data to validate.
     *
     * @return True if the FFDC schema matches what we are expecting, false
     *         otherwise.
     *
     */
    static bool doesPackageMatchSchema(const ffdc_package& i_ffdc);

    static const uint64_t INVALID_DATA = uint64_t(-1);

private:

    /**
     * @brief Validate that the passed in FFDC data has a schema consistent
     *        with what we are expecting.
     *
     * @param[in] i_ffdc, the FFDC data to validate.
     * @param[in] i_ignoreRC, Do not base validation on RC value. Setting
     *            this parameter to true indicates that the schema has already
     *            been checked by the doesPackageMatchSchema function and
     *            as such we just need to parse the data and not validate.
     *
     * @return True if the FFDC data was successfully validated and parsed,
     *         False otherwise.
     *
     */
    bool validateFFDCPackage(const ffdc_package& i_ffdc, bool i_ignoreRC);

    uint64_t iv_pibRc{INVALID_DATA}; /**< parsed pib rc code */
    uint64_t iv_scomAddress{INVALID_DATA}; /**< parsed scom address */
};


}

#endif
OpenPOWER on IntegriCloud