xref: /freebsd/sys/dev/ocs_fc/ocs_node.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 /*-
2  * Copyright (c) 2017 Broadcom. All rights reserved.
3  * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries.
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  * @file
34  * OCS linux driver remote node callback declarations
35  */
36 
37 #if !defined(__OCS_NODE_H__)
38 #define __OCS_NODE_H__
39 
40 #define node_sm_trace()  \
41 	do { \
42 		if (OCS_LOG_ENABLE_SM_TRACE(node->ocs)) \
43 			ocs_log_info(node->ocs, "[%s] %-20s\n", node->display_name, ocs_sm_event_name(evt)); \
44 	} while (0)
45 
46 #define node_printf(node, fmt, ...) ocs_log_debug(node->ocs, "[%s] " fmt, node->display_name, ##__VA_ARGS__)
47 
48 #define std_node_state_decl(...) \
49 	ocs_node_t *node = NULL; \
50 	ocs_t *ocs = NULL; \
51 	node = ctx->app; \
52 	ocs_assert(node, NULL); \
53 	ocs = node->ocs; \
54 	ocs_assert(ocs, NULL); \
55 	if (evt == OCS_EVT_ENTER) { \
56 		ocs_strncpy(node->current_state_name, __func__, sizeof(node->current_state_name)); \
57 	} else if (evt == OCS_EVT_EXIT) { \
58 		ocs_strncpy(node->prev_state_name, node->current_state_name, sizeof(node->prev_state_name)); \
59 		ocs_strncpy(node->current_state_name, "invalid", sizeof(node->current_state_name)); \
60 	} \
61 	node->prev_evt = node->current_evt; \
62 	node->current_evt = evt;
63 
64 #define OCS_NODEDB_PAUSE_FABRIC_LOGIN		(1U << 0)
65 #define OCS_NODEDB_PAUSE_NAMESERVER		(1U << 1)
66 #define OCS_NODEDB_PAUSE_NEW_NODES		(1U << 2)
67 
68 /**
69  * @brief Node SM IO Context Callback structure
70  *
71  * Structure used as callback argument
72  */
73 
74 struct ocs_node_cb_s {
75 	ocs_io_t *io;			/**< SCSI IO for sending response */
76 	int32_t status;			/**< completion status */
77 	int32_t ext_status;		/**< extended completion status */
78 	ocs_hw_rq_buffer_t *header;	/**< completion header buffer */
79 	ocs_hw_rq_buffer_t *payload;	/**< completion payload buffers */
80 	ocs_io_t *els;			/**< ELS IO object */
81 };
82 
83 /**
84  * @brief hold frames in pending frame list
85  *
86  * Unsolicited receive frames are held on the node pending frame list, rather than
87  * being processed.
88  *
89  * @param node pointer to node structure
90  *
91  * @return none
92  */
93 
94 static inline void
95 ocs_node_hold_frames(ocs_node_t *node)
96 {
97 	ocs_assert(node);
98 	node->hold_frames = TRUE;
99 }
100 
101 /**
102  * @brief accept frames
103  *
104  * Unsolicited receive frames processed rather than being held on the node
105  * pending frame list.
106  *
107  * @param node pointer to node structure
108  *
109  * @return none
110  */
111 
112 static inline void
113 ocs_node_accept_frames(ocs_node_t *node)
114 {
115 	ocs_assert(node);
116 	node->hold_frames = FALSE;
117 }
118 
119 extern int32_t ocs_node_create_pool(ocs_t *ocs, uint32_t node_count);
120 extern void ocs_node_free_pool(ocs_t *ocs);
121 extern ocs_node_t *ocs_node_get_instance(ocs_t *ocs, uint32_t index);
122 
123 static inline void
124 ocs_node_lock_init(ocs_node_t *node)
125 {
126 	ocs_rlock_init(node->ocs, &node->lock, "node rlock");
127 }
128 
129 static inline void
130 ocs_node_lock_free(ocs_node_t *node)
131 {
132 	ocs_rlock_free(&node->lock);
133 }
134 
135 static inline int32_t
136 ocs_node_lock_try(ocs_node_t *node)
137 {
138 	return ocs_rlock_try(&node->lock);
139 }
140 
141 static inline void
142 ocs_node_lock(ocs_node_t *node)
143 {
144 	ocs_rlock_acquire(&node->lock);
145 }
146 static inline void
147 ocs_node_unlock(ocs_node_t *node)
148 {
149 	ocs_rlock_release(&node->lock);
150 }
151 
152 /**
153  * @brief Node initiator/target enable defines
154  *
155  * All combinations of the SLI port (sport) initiator/target enable, and remote
156  * node initiator/target enable are enumerated.
157  *
158  */
159 
160 typedef enum {
161 	OCS_NODE_ENABLE_x_TO_x,
162 	OCS_NODE_ENABLE_x_TO_T,
163 	OCS_NODE_ENABLE_x_TO_I,
164 	OCS_NODE_ENABLE_x_TO_IT,
165 	OCS_NODE_ENABLE_T_TO_x,
166 	OCS_NODE_ENABLE_T_TO_T,
167 	OCS_NODE_ENABLE_T_TO_I,
168 	OCS_NODE_ENABLE_T_TO_IT,
169 	OCS_NODE_ENABLE_I_TO_x,
170 	OCS_NODE_ENABLE_I_TO_T,
171 	OCS_NODE_ENABLE_I_TO_I,
172 	OCS_NODE_ENABLE_I_TO_IT,
173 	OCS_NODE_ENABLE_IT_TO_x,
174 	OCS_NODE_ENABLE_IT_TO_T,
175 	OCS_NODE_ENABLE_IT_TO_I,
176 	OCS_NODE_ENABLE_IT_TO_IT,
177 } ocs_node_enable_e;
178 
179 static inline ocs_node_enable_e ocs_node_get_enable(ocs_node_t *node)
180 {
181 	uint32_t retval = 0;
182 
183 	if (node->sport->enable_ini) retval |= (1U << 3);
184 	if (node->sport->enable_tgt) retval |= (1U << 2);
185 	if (node->init) retval |= (1U << 1);
186 	if (node->targ) retval |= (1U << 0);
187 	return (ocs_node_enable_e) retval;
188 }
189 
190 typedef void* (*ocs_node_common_func_t)(const char *funcname, ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg);
191 
192 extern int32_t node_check_els_req(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg, uint8_t cmd, ocs_node_common_func_t node_common_func, const char *funcname);
193 extern int32_t node_check_ns_req(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg, uint32_t cmd, ocs_node_common_func_t node_common_func, const char *funcname);
194 extern int32_t ocs_remote_node_cb(void *arg, ocs_hw_remote_node_event_e event, void *data);
195 extern int32_t ocs_node_attach(ocs_node_t *node);
196 extern ocs_node_t *ocs_node_find(ocs_sport_t *sport, uint32_t port_id);
197 extern ocs_node_t *ocs_node_find_wwpn(ocs_sport_t *sport, uint64_t wwpn);
198 extern void ocs_node_dump(ocs_t *ocs);
199 extern ocs_node_t *ocs_node_alloc(ocs_sport_t *sport, uint32_t port_id, uint8_t init, uint8_t targ);
200 extern int32_t ocs_node_free(ocs_node_t *node);
201 extern void ocs_node_force_free(ocs_node_t *node);
202 extern void ocs_node_fcid_display(uint32_t fc_id, char *buffer, uint32_t buffer_length);
203 extern void ocs_node_update_display_name(ocs_node_t *node);
204 
205 extern void *__ocs_node_shutdown(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg);
206 extern void * __ocs_node_wait_node_free(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg);
207 extern void *__ocs_node_wait_els_shutdown(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg);
208 extern void *__ocs_node_wait_ios_shutdown(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg);
209 extern void ocs_node_save_sparms(ocs_node_t *node, void *payload);
210 extern void ocs_node_post_event(ocs_node_t *node, ocs_sm_event_t evt, void *arg);
211 extern void ocs_node_transition(ocs_node_t *node, ocs_sm_function_t state, void *data);
212 extern void *__ocs_node_common(const char *funcname, ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg);
213 
214 extern void ocs_node_initiate_cleanup(ocs_node_t *node);
215 extern int ocs_ddump_node(ocs_textbuf_t *textbuf, ocs_node_t *node);
216 
217 extern void ocs_node_build_eui_name(char *buffer, uint32_t buffer_len, uint64_t eui_name);
218 extern uint64_t ocs_node_get_wwpn(ocs_node_t *node);
219 extern uint64_t ocs_node_get_wwnn(ocs_node_t *node);
220 extern void ocs_node_abort_all_els(ocs_node_t *node);
221 
222 extern void ocs_node_pause(ocs_node_t *node, ocs_sm_function_t state);
223 extern int32_t ocs_node_resume(ocs_node_t *node);
224 extern void *__ocs_node_paused(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg);
225 
226 extern int ocs_node_active_ios_empty(ocs_node_t *node);
227 extern void ocs_node_send_ls_io_cleanup(ocs_node_t *node);
228 
229 extern int32_t ocs_node_recv_link_services_frame(ocs_node_t *node, ocs_hw_sequence_t *seq);
230 extern int32_t ocs_node_recv_abts_frame(ocs_node_t *node, ocs_hw_sequence_t *seq);
231 extern int32_t ocs_node_recv_els_frame(ocs_node_t *node, ocs_hw_sequence_t *seq);
232 extern int32_t ocs_node_recv_ct_frame(ocs_node_t *node, ocs_hw_sequence_t *seq);
233 extern int32_t ocs_node_recv_fcp_cmd(ocs_node_t *node, ocs_hw_sequence_t *seq);
234 extern int32_t ocs_node_recv_bls_no_sit(ocs_node_t *node, ocs_hw_sequence_t *seq);
235 
236 #endif
237