summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/mdia/mdiasm.H
blob: 5a304c1aa29e2e972129ea2237364cac64c8e1ed (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/mdia/mdiasm.H $                                  */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2012,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 __MDIA_MDIASM_H
#define __MDIA_MDIASM_H

/**
 * @file mdiasm.H
 * @brief mdia state machine definition
 */

#include <vector>
#include <util/threadpool.H>
#include <lib/mcbist/memdiags.H>
#include "sys/sync.h"
#include "mdiafwd.H"
#include "mdiaglobals.H"
#include <targeting/namedtarget.H>

namespace MDIA
{

// HW timeout value - 30 secs
// Nimbus DD1.0 has a workaround that will go over 30 seconds. Will need to bump
// it up for now. May consider lowering it later, but only if there is a
// problem.
static const uint64_t MAINT_CMD_TIMEOUT = 30000000000 * 10;

//Longer MBA timeout to be used when continuous tracing is enabled - 30 min
static const uint64_t MAINT_CMD_TIMEOUT_LONG = 1800000000000;

//Commit an info log for SW timeout every 10 mins
static const uint64_t MAINT_CMD_TIMEOUT_LOG =
          ( 10 * 60000000000 ) / MAINT_CMD_TIMEOUT;

/**
 * @brief work flow phases
 */
enum WorkFlowPhase
{
    START_PATTERN_0 = mss::mcbist::PATTERN_0,
    START_PATTERN_1 = mss::mcbist::PATTERN_1,
    START_PATTERN_2 = mss::mcbist::PATTERN_2,
    START_PATTERN_3 = mss::mcbist::PATTERN_3,
    START_PATTERN_4 = mss::mcbist::PATTERN_4,
    START_PATTERN_5 = mss::mcbist::PATTERN_5,
    START_PATTERN_6 = mss::mcbist::PATTERN_6,
    START_PATTERN_7 = mss::mcbist::PATTERN_7,
    START_RANDOM_PATTERN = mss::mcbist::PATTERN_RANDOM,
    DUMMY_SYNC_PHASE,
    DUMMY_ASYNC_PHASE,
    RESTORE_DRAM_REPAIRS,
    START_SCRUB,
    CLEAR_HW_CHANGED_STATE,
    ANALYZE_IPL_MNFG_CE_STATS,
};

/**
 * @brief determine whether the TargetType should be MBA or MCBIST
 *
 * @retval either TARGET_TYPE_MBA_CHIPLET or TARGET_TYPE_MCBIST
 */
fapi2::TargetType getMdiaTargetType();

/**
 * @brief memory diagnostics step state machine
 */
class StateMachine
{
    public:

        /**
         * @brief running State machine in progress indicator.
         *
         * @param[out] o_running In progress indicator.
         */
        void running(bool & o_running);

        /**
         * @brief used by Maint cmd monitor to notify that
         * maint cmd timed out - called in monitor thread context
         *
         * @param[in] i_monitorIDs Vector of monitorIDs
         */
        virtual void processCommandTimeout(
                        const MonitorIDs & i_monitorIDs);

        /**
         * @brief run the state machine to completion
         *
         * @param[in] i_list array of target / workFlow associations
         *
         * @retval 0 no errors
         * @retval !0 error occurred
         */
        errlHndl_t run(const WorkFlowAssocMap & i_list);

        /**
         * @brief shutdown state machine
         */
        void shutdown();

        /**
         * @brief processMaintCommandEvent process maint command event from prd
         *
         * @param[in] i_event the event to be processed
         *
         * @retval true a work item was dispatched
         * @retval false a work item was not dispatched
         */
        bool processMaintCommandEvent(const MaintCommandEvent & i_event);

        /**
         * @brief ctor
         */
        StateMachine();

        /**
         * @brief dtor
         */
        virtual ~StateMachine();

        /**
         * @brief set global params
         *
         * @param[in] i_globals global data
         */
        void setGlobals(Globals & i_globals);

    protected:

        /**
         * @brief serialization mutex
         */
        mutex_t iv_mutex;

        /**
         * @brief command monitor
         */
        CommandMonitor * iv_monitor;

    private:

        /**
         * @brief aliases
         */
        typedef std::vector<WorkFlowProperties *> WorkFlowPropertiesList;
        typedef std::vector<WorkFlowProperties *>::iterator
                WorkFlowPropertiesIterator;

        /**
         * @brief setup load the workflow properties for the provided
         * target / workflow association(s)
         *
         * @param[in] i_list target / workflow association(s) for which
         * to load the workflow properties
         */
        void setup(const WorkFlowAssocMap & i_list);

        /**
         * @brief start start the machine thread pool and start
         * dispatching work items
         */
        void start();

        /**
         * @brief wait wait for a started state machine to run to
         * completion
         */
        void wait();

        /**
         * @brief reset internal state
         */
        void reset();

        /**
         * @brief workItemIsAsync test the workflow properties
         * for an async work item
         *
         * @param[in] i_wfp the workflow properties to test for async
         *
         * @retval false work item is synch
         * @retval true work item is async
         */
        static bool workItemIsAsync(WorkFlowProperties & i_wfp);

        /**
         * @brief allWorkFlowsComplete check to see if all workflows are
         * finished
         *
         * @retval true all work flows are finished
         * @retval false all work flows are not finished
         */
        bool allWorkFlowsComplete();

        /**
         * @brief scheduleWorkItem
         *
         * @param[in] i_wfp the target for which a work item should be scheduled
         *
         * @retval true work item was dispatched
         * @retval false work item was not dispatched
         */
        bool scheduleWorkItem(WorkFlowProperties & i_wfp);

        /**
         * @brief doMaintCommand maint command work item handler
         *
         * determine the correct command and issue it
         *
         * @param[in] i_wfp the target for which a command should be issued
         */
        virtual errlHndl_t doMaintCommand(WorkFlowProperties & i_wfp);

        /**
         * @brief executeWorkItem work item entry point for
         * pool threads
         *
         * @param[in] i_wfp the work item to be executed
         *
         * @retval true next work item was dispatched
         * @retval false next work item was not dispatched
         */
        bool executeWorkItem(WorkFlowProperties * i_wfp);

        /**
         * @brief create and start command monitor if not
         * done already
         *
         * @retval command monitor reference
         */
        CommandMonitor & getMonitor();

        /**
         * @brief workFlow properties
         */
        WorkFlowPropertiesList iv_workFlowProperties;

        /**
         * @brief overall status condition
         */
        bool iv_done;

        /**
         * @brief shutdown indicator
         */
        bool iv_shutdown;

        /**
         * @brief thread pool
         */
        Util::ThreadPool<WorkItem> * iv_tp;

        /**
         * @brief completion condition
         */
        sync_cond_t iv_cond;

        /**
         * @brief global struct
         */
        Globals iv_globals;

        /**
         * @brief copy disabled
         */
        StateMachine(const StateMachine &);

        /**
         * @brief assignment disabled
         */
        StateMachine & operator=(const StateMachine &);

        /**
         * @brief provide internal access to unit test
         */
        friend class ::MdiaSmTest;

        /**
         * @brief provide internal access to WorkItem
         */
        friend class WorkItem;
};
}
#endif
OpenPOWER on IntegriCloud