OneCore⢠Storage SDK Release 11.2
User Space FC/FCoE Target RAMD Driver (Uspace ocs_fc_ramd)
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
ocs_sm.c
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2011-2015, Emulex
3
* All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
7
*
8
* 1. Redistributions of source code must retain the above copyright notice,
9
* this list of conditions and the following disclaimer.
10
*
11
* 2. Redistributions in binary form must reproduce the above copyright notice,
12
* this list of conditions and the following disclaimer in the documentation
13
* and/or other materials provided with the distribution.
14
*
15
* 3. Neither the name of the copyright holder nor the names of its contributors
16
* may be used to endorse or promote products derived from this software
17
* without specific prior written permission.
18
*
19
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
* POSSIBILITY OF SUCH DAMAGE.
30
*
31
*/
32
33
/**
34
* @file
35
* Generic state machine framework.
36
*/
37
38
#include "ocs_os.h"
39
#include "
ocs_sm.h
"
40
41
const
char
*
ocs_sm_id
[] = {
42
"common"
,
43
"domain"
,
44
"login"
45
};
46
47
/**
48
* @brief Post an event to a context.
49
*
50
* @param ctx State machine context
51
* @param evt Event to post
52
* @param data Event-specific data (if any)
53
*
54
* @return 0 if successfully posted event; -1 if state machine
55
* is disabled
56
*/
57
int
58
ocs_sm_post_event
(ocs_sm_ctx_t *ctx,
ocs_sm_event_t
evt,
void
*data)
59
{
60
if
(ctx->current_state) {
61
ctx->current_state(ctx, evt, data);
62
return
0;
63
}
else
{
64
return
-1;
65
}
66
}
67
68
/**
69
* @brief Transition to a new state.
70
*/
71
void
72
ocs_sm_transition
(ocs_sm_ctx_t *ctx,
ocs_sm_function_t
state,
void
*data)
73
{
74
if
(ctx->current_state == state) {
75
ocs_sm_post_event
(ctx,
OCS_EVT_REENTER
, data);
76
}
else
{
77
ocs_sm_post_event
(ctx,
OCS_EVT_EXIT
, data);
78
ctx->current_state = state;
79
ocs_sm_post_event
(ctx,
OCS_EVT_ENTER
, data);
80
}
81
}
82
83
/**
84
* @brief Disable further state machine processing.
85
*/
86
void
87
ocs_sm_disable
(ocs_sm_ctx_t *ctx)
88
{
89
ctx->current_state = NULL;
90
}
91
92
const
char
*
ocs_sm_event_name
(
ocs_sm_event_t
evt)
93
{
94
switch
(evt) {
95
#define RETEVT(x) case x: return #x;
96
RETEVT
(
OCS_EVT_ENTER
)
97
RETEVT
(
OCS_EVT_REENTER
)
98
RETEVT
(
OCS_EVT_EXIT
)
99
RETEVT
(
OCS_EVT_SHUTDOWN
)
100
RETEVT
(
OCS_EVT_RESPONSE
)
101
RETEVT
(
OCS_EVT_RESUME
)
102
RETEVT
(
OCS_EVT_TIMER_EXPIRED
)
103
RETEVT
(
OCS_EVT_ERROR
)
104
RETEVT
(
OCS_EVT_SRRS_ELS_REQ_OK
)
105
RETEVT
(
OCS_EVT_SRRS_ELS_CMPL_OK
)
106
RETEVT
(
OCS_EVT_SRRS_ELS_REQ_FAIL
)
107
RETEVT
(
OCS_EVT_SRRS_ELS_CMPL_FAIL
)
108
RETEVT
(
OCS_EVT_SRRS_ELS_REQ_RJT
)
109
RETEVT
(
OCS_EVT_NODE_ATTACH_OK
)
110
RETEVT
(
OCS_EVT_NODE_ATTACH_FAIL
)
111
RETEVT
(
OCS_EVT_NODE_FREE_OK
)
112
RETEVT
(
OCS_EVT_ELS_REQ_TIMEOUT
)
113
RETEVT
(
OCS_EVT_ELS_REQ_ABORTED
)
114
RETEVT
(
OCS_EVT_ABORT_ELS
)
115
RETEVT
(
OCS_EVT_ELS_ABORT_CMPL
)
116
117
RETEVT
(
OCS_EVT_DOMAIN_FOUND
)
118
RETEVT
(
OCS_EVT_DOMAIN_ALLOC_OK
)
119
RETEVT
(
OCS_EVT_DOMAIN_ALLOC_FAIL
)
120
RETEVT
(
OCS_EVT_DOMAIN_REQ_ATTACH
)
121
RETEVT
(
OCS_EVT_DOMAIN_ATTACH_OK
)
122
RETEVT
(
OCS_EVT_DOMAIN_ATTACH_FAIL
)
123
RETEVT
(
OCS_EVT_DOMAIN_LOST
)
124
RETEVT
(
OCS_EVT_DOMAIN_FREE_OK
)
125
RETEVT
(
OCS_EVT_DOMAIN_FREE_FAIL
)
126
RETEVT
(
OCS_EVT_HAL_DOMAIN_REQ_ATTACH
)
127
RETEVT
(
OCS_EVT_HAL_DOMAIN_REQ_FREE
)
128
RETEVT
(
OCS_EVT_ALL_CHILD_NODES_FREE
)
129
130
RETEVT
(
OCS_EVT_SPORT_ALLOC_OK
)
131
RETEVT
(
OCS_EVT_SPORT_ALLOC_FAIL
)
132
RETEVT
(
OCS_EVT_SPORT_ATTACH_OK
)
133
RETEVT
(
OCS_EVT_SPORT_ATTACH_FAIL
)
134
RETEVT
(
OCS_EVT_SPORT_FREE_OK
)
135
RETEVT
(
OCS_EVT_SPORT_FREE_FAIL
)
136
RETEVT
(
OCS_EVT_SPORT_TOPOLOGY_NOTIFY
)
137
RETEVT
(
OCS_EVT_HAL_PORT_ALLOC_OK
)
138
RETEVT
(
OCS_EVT_HAL_PORT_ALLOC_FAIL
)
139
RETEVT
(
OCS_EVT_HAL_PORT_ATTACH_OK
)
140
RETEVT
(
OCS_EVT_HAL_PORT_REQ_ATTACH
)
141
RETEVT
(
OCS_EVT_HAL_PORT_REQ_FREE
)
142
RETEVT
(
OCS_EVT_HAL_PORT_FREE_OK
)
143
144
RETEVT
(
OCS_EVT_NODE_FREE_FAIL
)
145
146
RETEVT
(
OCS_EVT_ABTS_RCVD
)
147
148
RETEVT
(
OCS_EVT_NODE_MISSING
)
149
RETEVT
(
OCS_EVT_NODE_REFOUND
)
150
RETEVT
(
OCS_EVT_SHUTDOWN_IMPLICIT_LOGO
)
151
RETEVT
(
OCS_EVT_SHUTDOWN_EXPLICIT_LOGO
)
152
153
RETEVT
(
OCS_EVT_ELS_FRAME
)
154
RETEVT
(
OCS_EVT_PLOGI_RCVD
)
155
RETEVT
(
OCS_EVT_FLOGI_RCVD
)
156
RETEVT
(
OCS_EVT_LOGO_RCVD
)
157
RETEVT
(
OCS_EVT_PRLI_RCVD
)
158
RETEVT
(
OCS_EVT_PRLO_RCVD
)
159
RETEVT
(
OCS_EVT_PDISC_RCVD
)
160
RETEVT
(
OCS_EVT_FDISC_RCVD
)
161
RETEVT
(
OCS_EVT_ADISC_RCVD
)
162
RETEVT
(
OCS_EVT_RSCN_RCVD
)
163
RETEVT
(
OCS_EVT_SCR_RCVD
)
164
RETEVT
(
OCS_EVT_ELS_RCVD
)
165
RETEVT
(
OCS_EVT_LAST
)
166
RETEVT
(
OCS_EVT_FCP_CMD_RCVD
)
167
168
RETEVT
(
OCS_EVT_RFT_ID_RCVD
)
169
RETEVT
(
OCS_EVT_RFF_ID_RCVD
)
170
RETEVT
(
OCS_EVT_GNN_ID_RCVD
)
171
RETEVT
(
OCS_EVT_GPN_ID_RCVD
)
172
RETEVT
(
OCS_EVT_GFPN_ID_RCVD
)
173
RETEVT
(
OCS_EVT_GFF_ID_RCVD
)
174
RETEVT
(
OCS_EVT_GID_FT_RCVD
)
175
RETEVT
(
OCS_EVT_GID_PT_RCVD
)
176
RETEVT
(
OCS_EVT_RPN_ID_RCVD
)
177
RETEVT
(
OCS_EVT_RNN_ID_RCVD
)
178
RETEVT
(
OCS_EVT_RCS_ID_RCVD
)
179
RETEVT
(
OCS_EVT_RSNN_NN_RCVD
)
180
RETEVT
(
OCS_EVT_RSPN_ID_RCVD
)
181
RETEVT
(
OCS_EVT_RHBA_RCVD
)
182
RETEVT
(
OCS_EVT_RPA_RCVD
)
183
184
RETEVT
(
OCS_EVT_GIDPT_DELAY_EXPIRED
)
185
186
RETEVT
(
OCS_EVT_ABORT_IO
)
187
RETEVT
(
OCS_EVT_ABORT_IO_NO_RESP
)
188
RETEVT
(
OCS_EVT_IO_CMPL
)
189
RETEVT
(
OCS_EVT_IO_CMPL_ERRORS
)
190
RETEVT
(
OCS_EVT_RESP_CMPL
)
191
RETEVT
(
OCS_EVT_ABORT_CMPL
)
192
RETEVT
(
OCS_EVT_NODE_ACTIVE_IO_LIST_EMPTY
)
193
RETEVT
(
OCS_EVT_NODE_LAST_ACTIVE_IO
)
194
RETEVT
(
OCS_EVT_NODE_DEL_INI_COMPLETE
)
195
RETEVT
(
OCS_EVT_NODE_DEL_TGT_COMPLETE
)
196
RETEVT
(
OCS_EVT_IO_ABORTED_BY_TMF
)
197
RETEVT
(
OCS_EVT_IO_ABORT_IGNORED
)
198
RETEVT
(
OCS_EVT_IO_FIRST_BURST
)
199
RETEVT
(
OCS_EVT_IO_FIRST_BURST_ERR
)
200
RETEVT
(
OCS_EVT_IO_FIRST_BURST_ABORTED
)
201
RETEVT
(
OCS_EVT_CT_LOOPBACK_RCVD
)
202
RETEVT
(
OCS_EVT_CT_LOOPBACK_RCVD_NO_IO
)
203
204
default
:
205
break
;
206
#undef RETEVT
207
}
208
return
"unknown"
;
209
}
210
211
/* vim: set noexpandtab textwidth=120: */
OCS_EVT_SPORT_ALLOC_FAIL
Definition:
ocs_sm.h:88
OCS_EVT_NODE_DEL_TGT_COMPLETE
Definition:
ocs_sm.h:169
OCS_EVT_ABORT_CMPL
Definition:
ocs_sm.h:165
OCS_EVT_DOMAIN_FREE_FAIL
Definition:
ocs_sm.h:82
OCS_EVT_NODE_ACTIVE_IO_LIST_EMPTY
Definition:
ocs_sm.h:166
OCS_EVT_RSCN_RCVD
Definition:
ocs_sm.h:133
OCS_EVT_FCP_CMD_RCVD
Definition:
ocs_sm.h:137
OCS_EVT_SCR_RCVD
Definition:
ocs_sm.h:134
OCS_EVT_ABTS_RCVD
Definition:
ocs_sm.h:117
OCS_EVT_LAST
Definition:
ocs_sm.h:181
OCS_EVT_ELS_REQ_ABORTED
Definition:
ocs_sm.h:113
OCS_EVT_ALL_CHILD_NODES_FREE
Definition:
ocs_sm.h:66
OCS_EVT_EXIT
Definition:
ocs_sm.h:64
OCS_EVT_SRRS_ELS_CMPL_FAIL
Definition:
ocs_sm.h:105
OCS_EVT_ELS_ABORT_CMPL
Definition:
ocs_sm.h:115
OCS_EVT_DOMAIN_ATTACH_FAIL
Definition:
ocs_sm.h:79
OCS_EVT_DOMAIN_ATTACH_OK
Definition:
ocs_sm.h:78
OCS_EVT_ABORT_IO
Definition:
ocs_sm.h:160
OCS_EVT_DOMAIN_REQ_ATTACH
Definition:
ocs_sm.h:77
OCS_EVT_NODE_LAST_ACTIVE_IO
Definition:
ocs_sm.h:167
OCS_EVT_SPORT_ATTACH_FAIL
Definition:
ocs_sm.h:90
OCS_EVT_RESUME
Definition:
ocs_sm.h:67
OCS_EVT_LOGO_RCVD
Definition:
ocs_sm.h:126
OCS_EVT_RESP_CMPL
Definition:
ocs_sm.h:164
OCS_EVT_ERROR
Definition:
ocs_sm.h:72
OCS_EVT_RPN_ID_RCVD
Definition:
ocs_sm.h:148
OCS_EVT_SPORT_FREE_FAIL
Definition:
ocs_sm.h:92
OCS_EVT_SRRS_ELS_CMPL_OK
Definition:
ocs_sm.h:103
OCS_EVT_SPORT_FREE_OK
Definition:
ocs_sm.h:91
OCS_EVT_IO_FIRST_BURST_ERR
Definition:
ocs_sm.h:173
OCS_EVT_IO_FIRST_BURST_ABORTED
Definition:
ocs_sm.h:174
OCS_EVT_SRRS_ELS_REQ_FAIL
Definition:
ocs_sm.h:104
OCS_EVT_DOMAIN_LOST
Definition:
ocs_sm.h:80
OCS_EVT_HAL_PORT_FREE_OK
Definition:
ocs_sm.h:99
OCS_EVT_NODE_FREE_OK
Definition:
ocs_sm.h:109
OCS_EVT_GID_PT_RCVD
Definition:
ocs_sm.h:147
OCS_EVT_RCS_ID_RCVD
Definition:
ocs_sm.h:150
OCS_EVT_NODE_DEL_INI_COMPLETE
Definition:
ocs_sm.h:168
ocs_sm_id
const char * ocs_sm_id[]
Definition:
ocs_sm.c:41
OCS_EVT_IO_CMPL_ERRORS
Definition:
ocs_sm.h:163
OCS_EVT_ADISC_RCVD
Definition:
ocs_sm.h:132
OCS_EVT_DOMAIN_FREE_OK
Definition:
ocs_sm.h:81
ocs_sm_event_name
const char * ocs_sm_event_name(ocs_sm_event_t evt)
Definition:
ocs_sm.c:92
OCS_EVT_SPORT_ATTACH_OK
Definition:
ocs_sm.h:89
OCS_EVT_RESPONSE
Definition:
ocs_sm.h:71
OCS_EVT_SPORT_TOPOLOGY_NOTIFY
Definition:
ocs_sm.h:93
OCS_EVT_RSPN_ID_RCVD
Definition:
ocs_sm.h:152
OCS_EVT_TIMER_EXPIRED
Definition:
ocs_sm.h:68
OCS_EVT_ELS_FRAME
Definition:
ocs_sm.h:111
OCS_EVT_PDISC_RCVD
Definition:
ocs_sm.h:130
OCS_EVT_SRRS_ELS_REQ_RJT
Definition:
ocs_sm.h:106
OCS_EVT_ELS_RCVD
Definition:
ocs_sm.h:135
ocs_sm_function_t
void *(* ocs_sm_function_t)(ocs_sm_ctx_t *, ocs_sm_event_t, void *)
Definition:
ocs_sm.h:188
OCS_EVT_HAL_PORT_ALLOC_OK
Definition:
ocs_sm.h:94
OCS_EVT_REENTER
Definition:
ocs_sm.h:63
OCS_EVT_ENTER
Definition:
ocs_sm.h:62
OCS_EVT_RNN_ID_RCVD
Definition:
ocs_sm.h:149
OCS_EVT_NODE_ATTACH_OK
Definition:
ocs_sm.h:107
OCS_EVT_GPN_ID_RCVD
Definition:
ocs_sm.h:143
OCS_EVT_HAL_PORT_ATTACH_OK
Definition:
ocs_sm.h:96
OCS_EVT_IO_CMPL
Definition:
ocs_sm.h:162
ocs_sm_transition
void ocs_sm_transition(ocs_sm_ctx_t *ctx, ocs_sm_function_t state, void *data)
Transition to a new state.
Definition:
ocs_sm.c:72
OCS_EVT_RFF_ID_RCVD
Definition:
ocs_sm.h:141
OCS_EVT_CT_LOOPBACK_RCVD
Definition:
ocs_sm.h:177
OCS_EVT_PRLI_RCVD
Definition:
ocs_sm.h:128
OCS_EVT_SPORT_ALLOC_OK
Definition:
ocs_sm.h:87
OCS_EVT_ABORT_ELS
Definition:
ocs_sm.h:114
ocs_sm.h
OCS_EVT_HAL_PORT_REQ_ATTACH
Definition:
ocs_sm.h:97
ocs_sm_post_event
int ocs_sm_post_event(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *data)
Post an event to a context.
Definition:
ocs_sm.c:58
OCS_EVT_NODE_REFOUND
Definition:
ocs_sm.h:120
OCS_EVT_DOMAIN_ALLOC_OK
Definition:
ocs_sm.h:75
OCS_EVT_IO_ABORTED_BY_TMF
Definition:
ocs_sm.h:170
OCS_EVT_NODE_FREE_FAIL
Definition:
ocs_sm.h:110
OCS_EVT_HAL_DOMAIN_REQ_FREE
Definition:
ocs_sm.h:84
OCS_EVT_IO_ABORT_IGNORED
Definition:
ocs_sm.h:171
OCS_EVT_GNN_ID_RCVD
Definition:
ocs_sm.h:142
OCS_EVT_PLOGI_RCVD
Definition:
ocs_sm.h:124
OCS_EVT_FLOGI_RCVD
Definition:
ocs_sm.h:125
OCS_EVT_SHUTDOWN_IMPLICIT_LOGO
Definition:
ocs_sm.h:121
OCS_EVT_GID_FT_RCVD
Definition:
ocs_sm.h:146
OCS_EVT_PRLO_RCVD
Definition:
ocs_sm.h:129
OCS_EVT_NODE_ATTACH_FAIL
Definition:
ocs_sm.h:108
OCS_EVT_HAL_PORT_ALLOC_FAIL
Definition:
ocs_sm.h:95
OCS_EVT_GFF_ID_RCVD
Definition:
ocs_sm.h:145
OCS_EVT_SHUTDOWN_EXPLICIT_LOGO
Definition:
ocs_sm.h:122
RETEVT
#define RETEVT(x)
OCS_EVT_HAL_DOMAIN_REQ_ATTACH
Definition:
ocs_sm.h:83
OCS_EVT_ABORT_IO_NO_RESP
Definition:
ocs_sm.h:161
OCS_EVT_GFPN_ID_RCVD
Definition:
ocs_sm.h:144
OCS_EVT_DOMAIN_FOUND
Definition:
ocs_sm.h:74
OCS_EVT_GIDPT_DELAY_EXPIRED
Definition:
ocs_sm.h:157
OCS_EVT_RFT_ID_RCVD
Definition:
ocs_sm.h:140
ocs_sm_event_t
ocs_sm_event_t
Definition:
ocs_sm.h:60
OCS_EVT_RHBA_RCVD
Definition:
ocs_sm.h:153
OCS_EVT_RPA_RCVD
Definition:
ocs_sm.h:154
OCS_EVT_CT_LOOPBACK_RCVD_NO_IO
Definition:
ocs_sm.h:178
OCS_EVT_SRRS_ELS_REQ_OK
Definition:
ocs_sm.h:102
ocs_sm_disable
void ocs_sm_disable(ocs_sm_ctx_t *ctx)
Disable further state machine processing.
Definition:
ocs_sm.c:87
OCS_EVT_RSNN_NN_RCVD
Definition:
ocs_sm.h:151
OCS_EVT_NODE_MISSING
Definition:
ocs_sm.h:119
OCS_EVT_FDISC_RCVD
Definition:
ocs_sm.h:131
OCS_EVT_DOMAIN_ALLOC_FAIL
Definition:
ocs_sm.h:76
OCS_EVT_IO_FIRST_BURST
Definition:
ocs_sm.h:172
OCS_EVT_HAL_PORT_REQ_FREE
Definition:
ocs_sm.h:98
OCS_EVT_SHUTDOWN
Definition:
ocs_sm.h:65
OCS_EVT_ELS_REQ_TIMEOUT
Definition:
ocs_sm.h:112
common
hal
ocs_sm.c