summaryrefslogtreecommitdiffstats
path: root/src/include/usr/hwas/common/deconfigGard.H
blob: 0a462aa43d6e2cea1fdf819cb6dc295ab26ac736 (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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/include/usr/hwas/common/deconfigGard.H $                  */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2011,2013              */
/*                                                                        */
/* p1                                                                     */
/*                                                                        */
/* Object Code Only (OCO) source materials                                */
/* Licensed Internal Code Source Materials                                */
/* IBM HostBoot Licensed Internal Code                                    */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/**
 *  @file deconfigGard.H
 *
 *  @brief Defines the DeconfigGard class that provides functions to deconfigure
 *  and create GARD records for Targets
 */

#ifndef DECONFIGGARD_H_
#define DECONFIGGARD_H_

#include <vector>
#include <hwas/common/hwasCommon.H>
#include <hwas/common/hwasCallout.H>
#include <targeting/common/attributes.H>
#include <hwas/hwasPlatDeconfigGard.H>
#include <hwas/hwasPlatThread.H>

namespace HWAS
{

/**
 *  @brief processDeferredDeconfig process any deferred deconfigure callouts
 *              that might have been 'queued' up.
 *
 *  This is outside of the DeconfigGard class because it is called
 *
 *  @return bool true if there were deferred deconfigure callouts;
 *               false if there were NO deferred deconfigure callouts;
 */
bool processDeferredDeconfig();

/**
 * @brief   collectGard   Common HWAS function to collect the GARD info
 *
 *  It will call into hwas platform-specific functions.
 *
 * @param  i_pPredicate     restrict processing - only look at GARD records
 *                          for targets that match the predicate (optional)
 *
 * @return errlHndl_t       valid errlHndl_t handle if there was an error
 *                          NULL if no errors;
 */
errlHndl_t collectGard(const TARGETING::PredicateBase *i_pPredicate = NULL);

/**
 * @brief Returns a reference to the DeconfigGard singleton.
 */
class DeconfigGard;
DeconfigGard & theDeconfigGard();

/**
 * @class DeconfigGard
 *
 * This class defines the singleton that handles Deconfigure and GARD Record
 * functionality
 */
class DeconfigGard
{

    // allow GardAddress to access private methods.
    friend class GardAddress;

public:

    enum
    {
        CLEAR_ALL_GARD_RECORDS = EMPTY_GARD_RECORDID,
        GET_ALL_GARD_RECORDS = EMPTY_GARD_RECORDID,
    };

    /**
     * @struct GardRecord
     *
     * Defines a GARD Record.
     *
     * Multiple GARD Records can exist for a specific Target
     */
    struct GardRecord
    {
        uint32_t              iv_recordId;
        TARGETING::EntityPath iv_targetId;
        uint32_t              iv_errlogPlid;
        uint8_t               iv_errorType; //from hwasCallout.H GARD_ErrorType
        uint8_t               iv_ResourceRecovery;
        uint8_t               iv_padding[6];
    };

    typedef std::vector<GardRecord> GardRecords_t;
    typedef std::vector<GardRecord>::iterator GardRecordsItr_t;
    typedef std::vector<GardRecord>::const_iterator GardRecordsCItr_t;

    /**
     * @struct DeconfigureRecord
     *
     * Defines a Deconfigure Record for deferred deconfigures
     *
     * Only one Deconfigure Record can exist for a specific Target
     */
    struct DeconfigureRecord
    {
        const TARGETING::Target * iv_target;
        uint32_t            iv_errlogPlid;
    };

    typedef std::vector<DeconfigureRecord> DeconfigureRecords_t;
    typedef std::vector<DeconfigureRecord>::iterator DeconfigureRecordsItr_t;
    typedef std::vector<DeconfigureRecord>::const_iterator DeconfigureRecordsCItr_t;

    /**
     * @brief Destructor.
     */
    ~DeconfigGard();

    /**
     * @brief Clears GARD Records for replaced Targets.
     *
     * Called by HWAS as part of initial IPL steps.
     *
     * @return errlHndl_t. Error log handle.
     */
    errlHndl_t clearGardRecordsForReplacedTargets();

    /**
     * @brief Deconfigures Targets that have GARD Records in preparation to IPL.
     *
     * @param  i_pPredicate     restrict processing - only look at GARD records
     *                          for targets that match the predicate (optional)
     *
     * Called by HWAS as part of initial IPL steps.
     *
     * If deconfiguring all such Targets will result in a configuration that is
     * unable to IPL then it figures out which subset of Targets to deconfigure
     * to give the best chance of IPL (Resource Recovery).
     *
     * @return errlHndl_t. Error log handle.
     */
    errlHndl_t deconfigureTargetsFromGardRecordsForIpl(
                const TARGETING::PredicateBase *i_pPredicate = NULL);

    /**
     * @brief Processes the Field Core Override attribute
     *
     * Called by HWAS as part of initial IPL steps.
     *
     * if the Field Core Override is non-zero, then functional cores will
     * be made non-functional, until the number of functional cores is equal
     * to the FCO value;
     *
     * @return errlHndl_t. Error log handle.
     */
    errlHndl_t processFieldCoreOverride();

    /**
     * @brief Deconfigures a Target.
     *
     * Called from processCallout, which is called
     * by ErrlManager when committing an error log containing a
     * Deconfigure request.
     *
     * This will Deconfigure the Target (set state to non-functional, do any
     * Deconfigure actions and create a Deconfigure Record) and Deconfigure
     * Targets by association. Any errors deconfiguring targets are committed
     * and the function continues. The only errors returned are usage errors.
     * By default, targets are NOT deconfigured if the system is at Runtime.
     *
     * @param[in] i_target   Reference to Target to deconfigure.
     * @param[in] i_errlPlid Error log PLID to store in Deconfigure Record.
     * @param[in] i_evenAtRunTime Deconfigure even if at RunTime
     * @return errlHndl_t. Error log handle.
     */
    errlHndl_t deconfigureTarget(TARGETING::Target & i_target,
                                 const uint32_t i_errlPlid,
                                 bool i_evenAtRunTime = false);
    /**
     * @brief Registers a Deferred Deconfigure
     *
     * Called from errludcallout, which is called
     * by hwasCallout when the user requests a
     * Deferred Deconfigure request.
     *
     * For now, just put a mark on the wall indicating that we got a deferred
     * deconfigure callout
     * TODO RTC: 45781
     *
     * @param[in] i_target   Reference to Target to deconfigure.
     * @param[in] i_errlPlid Error log PLID to store in Deconfigure Record.
     *
     */
    void registerDeferredDeconfigure(const TARGETING::Target & i_target,
                                 const uint32_t i_errlPlid);

    /**
     * @brief Creates a GARD Record for a Target.
     *
     * Called by ErrlManager when committing an error log containing a
     * GARD Record request.
     *
     * Called by an administrator to manually create a GARD Record.
     *
     * Any error creating the GARD Record will be returned to the user.
     *
     * @param[in] i_target   Reference to Target to create GARD Record for.
     * @param[in] i_errlPlid Error log PLID to store in GARD Record.
     * @param[in] i_errorType error type of the GARD Record.
     *
     * @return errlHndl_t. Error log handle.
     */
    errlHndl_t createGardRecord(const TARGETING::Target & i_target,
                                const uint32_t i_errlPlid,
                                const GARD_ErrorType i_errorType);

    /**
     * @brief Clears the specified GARD Records.
     *
     * Called by an administrator to clear GARD records manually.
     *
     * If the specified record does not exist then no error is returned. The
     * only errors returned are usage errors and errors accessing the GARD
     * Records.
     *
     * @param[in] i_recordId RecordId to clear. If zero (CLEAR_ALL_GARD_RECORDS)
     *                          then all GARD Records cleared.
     *
     * @return errlHndl_t. Error log handle.
     */
    errlHndl_t clearGardRecords(const uint32_t i_recordId);

    /**
     * @brief Clears all GARD Records for the specified Target.
     *
     * Called by an administrator to clear GARD records manually.
     *
     * If no GARD Records exist for the Target then no error is returned. The
     * only errors returned are usage errors and errors accessing the GARD
     * Records.
     *
     * @param[in] i_targetId Reference to Target ID to clear GARD Records for.
     *
     * @return errlHndl_t. Error log handle.
     */
    errlHndl_t clearGardRecords(const TARGETING::EntityPath & i_targetId);

    /**
     * @brief Gets the specified GARD Records.
     *
     * Called by an administrator to view GARD Records.
     *
     * If the specified record does not exist then no error is returned. The
     * only errors returned are usage errors and errors accessing the GARD
     * Records.
     *
     * @param[in]  i_recordId RecordId to get. If zero then all GARD Records are
     *                        retrieved.
     * @param[out] o_records  Reference to vector of GardRecords that is cleared
     *                        then filled in with records.
     *
     * @return errlHndl_t. Error log handle.
     */
    errlHndl_t getGardRecords(const uint32_t i_recordId,
                              GardRecords_t & o_records);

    /**
     * @brief Gets all GARD Records for the specified Target.
     *
     * Called by an administrator to view GARD Records.
     *
     * If no GARD Records exist for the Target then no error is returned. The
     * only errors returned are usage errors and errors accessing the GARD
     * Records.
     *
     * @param[in]  i_targetId Reference to Target ID to get GARD Records for.
     * @param[out] o_records  Reference to vector of GardRecords that is cleared
     *                        then filled in with records.
     *
     * @return errlHndl_t. Error log handle.
     */
    errlHndl_t getGardRecords(const TARGETING::EntityPath & i_targetId,
                              GardRecords_t & o_records);

protected:

    /**
     * @brief Default constructor
     *
     * Can only be called by Singleton
     */
    DeconfigGard();

private:

    // Copy constructor and assignment operator disabled
    DeconfigGard(const DeconfigGard & i_right);
    DeconfigGard & operator=(const DeconfigGard & i_right);

    /**
     * @brief Deconfigures Targets by association.
     *
     * @param[in] i_target   Reference to base Target.
     * @param[in] i_errlPlid Error log PLID to store in Deconfigure Record.
     */
    void _deconfigureByAssoc(TARGETING::Target & i_target,
                             const uint32_t i_errlPlid);

    /**
     * @brief Deconfigures a Target.
     *
     * This will Deconfigure the Target (set state to non-functional, do any
     * Deconfigure actions and create a Deconfigure Record).
     *
     * @param[in] i_target   Reference to Target to deconfigure.
     * @param[in] i_errlPlid Error log PLID to store in Deconfigure Record.
     */
    void _deconfigureTarget(TARGETING::Target & i_target,
                            const uint32_t i_errlPlid);

    /**
     * @brief Performs Deconfigure Actions.
     *
     * @param[in] i_target Reference to Target to perform actions on.
     */
    void _doDeconfigureActions(TARGETING::Target & i_target);

    /**
     * @brief Creates a Deconfigure Record
     *
     * @param[in] i_target   Reference to Target to create record for.
     * @param[in] i_errlPlid Error log PLID to store in Deconfigure Record.
     */
    void _createDeconfigureRecord(const TARGETING::Target & i_target,
                                  const uint32_t i_errlPlid);

public:

    /**
     * @brief Gets the specified Deconfigure Records.
     *
     * Called by an administrator to view Deconfigure Records. There can only be
     * one Deconfiguration Record per Target.
     *
     * If the specified record does not exist then no error is returned. The
     * only errors returned are usage errors and errors accessing the
     * Deconfigure Records.
     *
     * @note Provided for unit test only. Production code should not be
     *       clearing Deconfigure Records.
     *
     * @param[in]  i_pTargetId Pointer to the Target ID to get the Deconfigure
     *                         Record for. If NULL then all Deconfigure Records
     *                         are retrieved.
     * @param[out] o_records   Reference to vector of DeconfigureRecords that is
     *                         cleared then filled in with records.
     *
     * @return errlHndl_t. Error log handle.
     */
    errlHndl_t _getDeconfigureRecords(const TARGETING::Target * i_pTarget,
                                     DeconfigureRecords_t & o_records);

    /**
     * @brief Clears the specified Deconfigure Records.
     *
     * @note Provided for unit test only. Production code should not be
     *       clearing Deconfigure Records.
     *
     * @param[in] i_pTargetId Pointer to the Target ID to clear Deconfigure
     *                        Records for. If NULL then all Deconfigure Records
     *                        are cleared.
     */
    void _clearDeconfigureRecords(const TARGETING::Target * i_pTarget);


    /**
     *  @brief _processDeferredDeconfig process any deferred deconfigure
     *              callouts that might have been 'queued' up.
     *
     *  @return bool true if there were deferred deconfigure callouts;
     *               false if there were NO deferred deconfigure callouts;
     */
    bool _processDeferredDeconfig();

private:

    /**
     * @brief Creates a GARD Record for a Target.
     *
     * @param[in] i_target   Reference to Target to create GARD Record for.
     * @param[in] i_errlPlid Error log PLID to store in GARD Record.
     * @param[in] i_errorType Error Type of the GARD Record.
     *
     * @return errlHndl_t. Error log handle.
     */
    errlHndl_t _createGardRecord(const TARGETING::Target & i_target,
                                 const uint32_t i_errlPlid,
                                 const GARD_ErrorType i_errorType);

    /**
     * @brief Clears the specified GARD Records.
     *
     * @param[in] i_recordId RecordId to clear. If CLEAR_ALL_GARD_RECORDS
     *                          then all GARD Records cleared.
     *
     * @return errlHndl_t. Error log handle.
     */
    errlHndl_t _clearGardRecords(const uint32_t i_recordId);

    /**
     * @brief Clears all GARD Records for the specified Target.
     *
     * @param[in] i_targetId Reference to Target ID to clear GARD Records for.
     *
     * @return errlHndl_t. Error log handle.
     */
    errlHndl_t _clearGardRecords(const TARGETING::EntityPath & i_targetId);

    /**
     * @brief Gets the specified GARD Records.
     *
     * @param[in]  i_recordId RecordId to get. If zero then all GARD Records are
     *                        retrieved.
     * @param[out] o_records  Reference to vector of GardRecords that is cleared
     *                        then filled in with records.
     *
     * @return errlHndl_t. Error log handle.
     */
    errlHndl_t _getGardRecords(const uint32_t i_recordId,
                               GardRecords_t & o_records);

    /**
     * @brief Gets all GARD Records for the specified Target.
     *
     *
     * @param[in]  i_targetId Reference to Target ID to get GARD Records for.
     * @param[out] o_records  Reference to vector of GardRecords that is cleared
     *                        then filled in with records.
     *
     * @return errlHndl_t. Error log handle.
     */
    errlHndl_t _getGardRecords(const TARGETING::EntityPath & i_targetId,
                               GardRecords_t & o_records);

    /**
     * @brief sets the maxGardRecords and nextGardRecordId variables
     *
     * @param[in]  i_size size of GARD area in PNOR/memory
     */
    void _GardRecordIdSetup(uint32_t i_size);

    // Mutex for thread safety
    HWAS_MUTEX_TYPE iv_mutex;

    // GARD Record Data
    uint32_t iv_nextGardRecordId;   // Next GARD Record ID to use
    uint32_t iv_maxGardRecords;     // Maximum number of GARD Records
    GardRecord * iv_pGardRecords;   // Pointer to the GARD Records in PNOR

    // The Deconfigure Records
    DeconfigureRecords_t iv_deconfigureRecords;

}; // DeconfigGard
HWAS_DECLARE_SINGLETON(HWAS::DeconfigGard,theDeconfigGardSingleton);

// The HWAS Common code needs to allow for the fact that the platforms
//  may need to know when the DeconfigGard functions are done using the
//  PNOR area for GARD record access. To this end, GardAddress is an
//  object that the common code will create when it needs to use the
//  address to the GARD records data (iv_pGardRecords). When this object
//  goes out of scope, the destructor will get called, and the platform
//  code will know that access to the PNOR area is complete.
class GardAddress
{
public:

    /**
     * @brief Constructor.
     *  PLATFORM must implement this function
     *
     * @param[in]  o_errl  errlHndl_t set if there was an error
     */
    GardAddress(errlHndl_t &o_errl);

    /**
     * @brief Destructor.
     *  PLATFORM must implement this function
     */
    ~GardAddress();

    /**
     * @brief flush. flush all of the waiting addresses out
     *
     */
    void flush();

    /**
     * @brief writeRecord. Add the indicated address to a vector, so
     *  that the destructor knows which GARD records were updated.
     *
     * @param[in]  i_addr  address of GARD record that was updated.
     */
    void writeRecord(void *i_addr)
    {
        if (i_addr !=NULL)
        {
            iv_addr.push_back(i_addr);
        }
    }

protected:

    std::vector<void *>iv_addr;

}; // GardAddress
}

#endif
OpenPOWER on IntegriCloud