1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at src/sun_nws/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at src/sun_nws/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 #ifndef _IDM_CONN_SM_H_
  27 #define _IDM_CONN_SM_H_
  28 
  29 #pragma ident   "@(#)idm_conn_sm.h      1.7     08/03/23 SMI"
  30 
  31 #ifdef  __cplusplus
  32 extern "C" {
  33 #endif
  34 
  35 
  36 /*
  37  * IDM connection state machine events.  Most events get generated internally
  38  * either by the state machine or by the IDM TX/RX code.  For example when IDM
  39  * receives a login request for a target connectionit will generate a
  40  * CE_LOGIN_RCV event.  Similarly when the target sends a successful login
  41  * response IDM generate a "CE_LOGIN_SUCCESS_SND" event.  The following
  42  * events are not detected on the TX/RX path and must be generated explicitly
  43  * by the client when appropriate:
  44  *
  45  * CE_LOGOUT_OTHER_CONN_RCV
  46  * CE_ASYNC_DROP_CONN_RCV   (Only because the message may be received on
  47  * a different connection from the connection being dropped)
  48  * CE_ASYNC_DROP_ALL_CONN_RCV
  49  * CE_LOGOUT_OTHER_CONN_SND
  50  * CE_ASYNC_DROP_ALL_CONN_SND
  51  *
  52  * The following events might occur in any state since they are driven
  53  * by the PDU's that IDM receives:
  54  *
  55  * CE_LOGIN_RCV
  56  * CE_LOGIN_SUCCESS_RCV
  57  * CE_LOGIN_FAIL_RCV
  58  * CE_LOGOUT_SUCCESS_RCV
  59  * CE_LOGOUT_FAIL_RCV
  60  * CE_ASYNC_LOGOUT_RCV
  61  * CE_MISC_RCV
  62  * CE_RX_PROTOCOL_ERROR
  63  */
  64 
  65 #define IDM_LOGIN_SECONDS       20
  66 #define IDM_CLEANUP_SECONDS     0
  67 
  68 /* Update idm_ce_name table whenever connection events are modified */
  69 typedef enum {
  70         CE_UNDEFINED = 0,
  71 
  72         /* Initiator events */
  73         CE_CONNECT_REQ,
  74         CE_CONNECT_FAIL,
  75         CE_CONNECT_SUCCESS,
  76         CE_LOGIN_SND,
  77         CE_LOGIN_SUCCESS_RCV,
  78         CE_LOGIN_FAIL_RCV,
  79         CE_LOGOUT_THIS_CONN_SND,
  80         CE_LOGOUT_OTHER_CONN_SND,
  81         CE_LOGOUT_SESSION_SND,
  82         CE_LOGOUT_SUCCESS_RCV,
  83         CE_LOGOUT_FAIL_RCV,
  84         CE_ASYNC_LOGOUT_RCV,
  85         CE_ASYNC_DROP_CONN_RCV,
  86         CE_ASYNC_DROP_ALL_CONN_RCV,
  87 
  88         /* Target events */
  89         CE_CONNECT_ACCEPT,
  90         CE_CONNECT_REJECT,
  91         CE_LOGIN_RCV,
  92         CE_LOGIN_TIMEOUT,
  93         CE_LOGIN_SUCCESS_SND,
  94         CE_LOGIN_FAIL_SND,
  95         CE_LOGOUT_THIS_CONN_RCV,
  96         CE_LOGOUT_OTHER_CONN_RCV,
  97         CE_LOGOUT_SESSION_RCV,
  98         CE_LOGOUT_SUCCESS_SND,
  99         CE_LOGOUT_FAIL_SND,
 100         CE_CLEANUP_TIMEOUT,
 101         CE_ASYNC_LOGOUT_SND,
 102         CE_ASYNC_DROP_CONN_SND,
 103         CE_ASYNC_DROP_ALL_CONN_SND,
 104 
 105         /* Common events */
 106         CE_TRANSPORT_FAIL,
 107         CE_MISC_TX,
 108         CE_TX_PROTOCOL_ERROR,
 109         CE_MISC_RX,
 110         CE_RX_PROTOCOL_ERROR,
 111         CE_LOGOUT_SESSION_SUCCESS,
 112         CE_CONN_REINSTATE,
 113         CE_CONN_REINSTATE_SUCCESS,
 114         CE_CONN_REINSTATE_FAIL,
 115 
 116         CE_MAX_EVENT
 117 } idm_conn_event_t;
 118 
 119 /* Update idm_cs_name table whenever connection states are modified */
 120 typedef enum {
 121         CS_S0_UNDEFINED = 0,
 122 
 123         CS_S1_FREE,
 124         CS_S2_XPT_WAIT,
 125         CS_S3_XPT_UP,
 126         CS_S4_IN_LOGIN,
 127         CS_S5_LOGGED_IN,
 128         CS_S6_IN_LOGOUT,
 129         CS_S7_LOGOUT_REQ,
 130         CS_S8_CLEANUP,
 131         CS_S9_INIT_ERROR,
 132         CS_S10_IN_CLEANUP,
 133         CS_S11_COMPLETE,
 134 
 135         CS_MAX_STATE
 136 } idm_conn_state_t;
 137 
 138 typedef enum {
 139         CT_NONE = 0,
 140         CT_RX_PDU,
 141         CT_TX_PDU
 142 } idm_pdu_event_type_t;
 143 
 144 typedef enum {
 145         CA_TX_PROTOCOL_ERROR,   /* Send "protocol error" to state machine */
 146         CA_RX_PROTOCOL_ERROR,   /* Send "protocol error" to state machine */
 147         CA_FORWARD              /* State machine event and foward to client */
 148 } idm_pdu_event_action_t;
 149 
 150 typedef struct {
 151         struct idm_conn_s       *iec_ic;
 152         idm_conn_event_t        iec_event;
 153         uintptr_t               iec_info;
 154         idm_pdu_event_type_t    iec_pdu_event_type;
 155 } idm_conn_event_ctx_t;
 156 
 157 idm_status_t
 158 idm_conn_sm_init(struct idm_conn_s *ic);
 159 
 160 void
 161 idm_conn_sm_fini(struct idm_conn_s *ic);
 162 
 163 idm_status_t /* XXX SHould this be called from outside the state machine? */
 164 idm_notify_client(struct idm_conn_s *ic, idm_client_notify_t cn,
 165     uintptr_t data);
 166 
 167 void
 168 idm_conn_event(struct idm_conn_s *ic, idm_conn_event_t event, uintptr_t data);
 169 
 170 idm_status_t
 171 idm_conn_reinstate_event(struct idm_conn_s *old_ic, struct idm_conn_s *new_ic);
 172 
 173 void
 174 idm_conn_tx_pdu_event(struct idm_conn_s *ic, idm_conn_event_t event,
 175     uintptr_t data);
 176 
 177 void
 178 idm_conn_rx_pdu_event(struct idm_conn_s *ic, idm_conn_event_t event,
 179     uintptr_t data);
 180 
 181 char *
 182 idm_conn_state_str(struct idm_conn_s *ic);
 183 
 184 #ifdef  __cplusplus
 185 }
 186 #endif
 187 
 188 #endif /* _IDM_CONN_SM_H_ */