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