2 * Copyright (c) 2017 Broadcom. All rights reserved.
3 * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
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.
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.
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.
36 * Generic state machine framework declarations.
43 * State Machine (SM) IDs.
53 #define OCS_SM_EVENT_SHIFT 24
54 #define OCS_SM_EVENT_START(id) ((id) << OCS_SM_EVENT_SHIFT)
56 extern const char *ocs_sm_id[]; /**< String format of the above enums. */
59 * State Machine events.
63 OCS_EVT_ENTER = OCS_SM_EVENT_START(OCS_SM_COMMON),
67 OCS_EVT_ALL_CHILD_NODES_FREE,
69 OCS_EVT_TIMER_EXPIRED,
72 OCS_EVT_RESPONSE = OCS_SM_EVENT_START(OCS_SM_DOMAIN),
76 OCS_EVT_DOMAIN_ALLOC_OK,
77 OCS_EVT_DOMAIN_ALLOC_FAIL,
78 OCS_EVT_DOMAIN_REQ_ATTACH,
79 OCS_EVT_DOMAIN_ATTACH_OK,
80 OCS_EVT_DOMAIN_ATTACH_FAIL,
82 OCS_EVT_DOMAIN_FREE_OK,
83 OCS_EVT_DOMAIN_FREE_FAIL,
84 OCS_EVT_HW_DOMAIN_REQ_ATTACH,
85 OCS_EVT_HW_DOMAIN_REQ_FREE,
88 OCS_EVT_SPORT_ALLOC_OK = OCS_SM_EVENT_START(OCS_SM_PORT),
89 OCS_EVT_SPORT_ALLOC_FAIL,
90 OCS_EVT_SPORT_ATTACH_OK,
91 OCS_EVT_SPORT_ATTACH_FAIL,
92 OCS_EVT_SPORT_FREE_OK,
93 OCS_EVT_SPORT_FREE_FAIL,
94 OCS_EVT_SPORT_TOPOLOGY_NOTIFY,
95 OCS_EVT_HW_PORT_ALLOC_OK,
96 OCS_EVT_HW_PORT_ALLOC_FAIL,
97 OCS_EVT_HW_PORT_ATTACH_OK,
98 OCS_EVT_HW_PORT_REQ_ATTACH,
99 OCS_EVT_HW_PORT_REQ_FREE,
100 OCS_EVT_HW_PORT_FREE_OK,
103 OCS_EVT_SRRS_ELS_REQ_OK = OCS_SM_EVENT_START(OCS_SM_LOGIN),
104 OCS_EVT_SRRS_ELS_CMPL_OK,
105 OCS_EVT_SRRS_ELS_REQ_FAIL,
106 OCS_EVT_SRRS_ELS_CMPL_FAIL,
107 OCS_EVT_SRRS_ELS_REQ_RJT,
108 OCS_EVT_NODE_ATTACH_OK,
109 OCS_EVT_NODE_ATTACH_FAIL,
110 OCS_EVT_NODE_FREE_OK,
111 OCS_EVT_NODE_FREE_FAIL,
113 OCS_EVT_ELS_REQ_TIMEOUT,
114 OCS_EVT_ELS_REQ_ABORTED,
115 OCS_EVT_ABORT_ELS, /**< request an ELS IO be aborted */
116 OCS_EVT_ELS_ABORT_CMPL, /**< ELS abort process complete */
120 OCS_EVT_NODE_MISSING, /**< node is not in the GID_PT payload */
121 OCS_EVT_NODE_REFOUND, /**< node is allocated and in the GID_PT payload */
122 OCS_EVT_SHUTDOWN_IMPLICIT_LOGO, /**< node shutting down due to PLOGI recvd (implicit logo) */
123 OCS_EVT_SHUTDOWN_EXPLICIT_LOGO, /**< node shutting down due to LOGO recvd/sent (explicit logo) */
138 OCS_EVT_FCP_CMD_RCVD,
140 /* Used by fabric emulation */
145 OCS_EVT_GFPN_ID_RCVD,
152 OCS_EVT_RSNN_NN_RCVD,
153 OCS_EVT_RSPN_ID_RCVD,
157 OCS_EVT_GIDPT_DELAY_EXPIRED,
159 /* SCSI Target Server events */
161 OCS_EVT_ABORT_IO_NO_RESP,
163 OCS_EVT_IO_CMPL_ERRORS,
166 OCS_EVT_NODE_ACTIVE_IO_LIST_EMPTY,
167 OCS_EVT_NODE_DEL_INI_COMPLETE,
168 OCS_EVT_NODE_DEL_TGT_COMPLETE,
169 OCS_EVT_IO_ABORTED_BY_TMF,
170 OCS_EVT_IO_ABORT_IGNORED,
171 OCS_EVT_IO_FIRST_BURST,
172 OCS_EVT_IO_FIRST_BURST_ERR,
173 OCS_EVT_IO_FIRST_BURST_ABORTED,
179 /* Declare ocs_sm_ctx_s */
180 typedef struct ocs_sm_ctx_s ocs_sm_ctx_t;
182 /* State machine state function */
183 typedef void *(*ocs_sm_function_t)(ocs_sm_ctx_t *, ocs_sm_event_t, void *);
185 /* State machine context header */
186 struct ocs_sm_ctx_s {
187 ocs_sm_function_t current_state;
188 const char *description;
189 void *app; /** Application-specific handle. */
192 extern int ocs_sm_post_event(ocs_sm_ctx_t *, ocs_sm_event_t, void *);
193 extern void ocs_sm_transition(ocs_sm_ctx_t *, ocs_sm_function_t, void *);
194 extern void ocs_sm_disable(ocs_sm_ctx_t *ctx);
195 extern const char *ocs_sm_event_name(ocs_sm_event_t evt);
198 #define smtrace(sm) ocs_log_debug(NULL, "%s: %-20s --> %s\n", sm, ocs_sm_event_name(evt), __func__)
203 #endif /* ! _OCS_SM_H */