summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/mdia/mdiasm.H
blob: f4c93b699b02b5d2fe968ee648a383c26f5cd3ea (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/mdia/mdiasm.H $                                  */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012,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                                                     */
#ifndef __MDIA_MDIASM_H
#define __MDIA_MDIASM_H

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

#include <vector>
#include <util/threadpool.H>
#include <utility_procedures/mss_maint_cmds.H>
#include "sys/sync.h"
#include "mdiafwd.H"

namespace MDIA
{

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

/**
 * @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();

    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 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