xref: /openbmc/linux/drivers/scsi/elx/libefc/efc_node.h (revision 3cf3cdea)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2021 Broadcom. All Rights Reserved. The term
4  * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
5  */
6 
7 #if !defined(__EFC_NODE_H__)
8 #define __EFC_NODE_H__
9 #include "scsi/fc/fc_ns.h"
10 
11 #define EFC_NODEDB_PAUSE_FABRIC_LOGIN	(1 << 0)
12 #define EFC_NODEDB_PAUSE_NAMESERVER	(1 << 1)
13 #define EFC_NODEDB_PAUSE_NEW_NODES	(1 << 2)
14 
15 #define MAX_ACC_REJECT_PAYLOAD	sizeof(struct fc_els_ls_rjt)
16 
17 #define scsi_io_printf(io, fmt, ...) \
18 	efc_log_debug(io->efc, "[%s] [%04x][i:%04x t:%04x h:%04x]" fmt, \
19 	io->node->display_name, io->instance_index, io->init_task_tag, \
20 	io->tgt_task_tag, io->hw_tag, ##__VA_ARGS__)
21 
22 static inline void
23 efc_node_evt_set(struct efc_sm_ctx *ctx, enum efc_sm_event evt,
24 		 const char *handler)
25 {
26 	struct efc_node *node = ctx->app;
27 
28 	if (evt == EFC_EVT_ENTER) {
29 		strncpy(node->current_state_name, handler,
30 			sizeof(node->current_state_name));
31 	} else if (evt == EFC_EVT_EXIT) {
32 		strncpy(node->prev_state_name, node->current_state_name,
33 			sizeof(node->prev_state_name));
34 		strncpy(node->current_state_name, "invalid",
35 			sizeof(node->current_state_name));
36 	}
37 	node->prev_evt = node->current_evt;
38 	node->current_evt = evt;
39 }
40 
41 /**
42  * hold frames in pending frame list
43  *
44  * Unsolicited receive frames are held on the node pending frame list,
45  * rather than being processed.
46  */
47 
48 static inline void
49 efc_node_hold_frames(struct efc_node *node)
50 {
51 	node->hold_frames = true;
52 }
53 
54 /**
55  * accept frames
56  *
57  * Unsolicited receive frames processed rather than being held on the node
58  * pending frame list.
59  */
60 
61 static inline void
62 efc_node_accept_frames(struct efc_node *node)
63 {
64 	node->hold_frames = false;
65 }
66 
67 /*
68  * Node initiator/target enable defines
69  * All combinations of the SLI port (nport) initiator/target enable,
70  * and remote node initiator/target enable are enumerated.
71  * ex: EFC_NODE_ENABLE_T_TO_IT decodes to target mode is enabled on SLI port
72  * and I+T is enabled on remote node.
73  */
74 enum efc_node_enable {
75 	EFC_NODE_ENABLE_x_TO_x,
76 	EFC_NODE_ENABLE_x_TO_T,
77 	EFC_NODE_ENABLE_x_TO_I,
78 	EFC_NODE_ENABLE_x_TO_IT,
79 	EFC_NODE_ENABLE_T_TO_x,
80 	EFC_NODE_ENABLE_T_TO_T,
81 	EFC_NODE_ENABLE_T_TO_I,
82 	EFC_NODE_ENABLE_T_TO_IT,
83 	EFC_NODE_ENABLE_I_TO_x,
84 	EFC_NODE_ENABLE_I_TO_T,
85 	EFC_NODE_ENABLE_I_TO_I,
86 	EFC_NODE_ENABLE_I_TO_IT,
87 	EFC_NODE_ENABLE_IT_TO_x,
88 	EFC_NODE_ENABLE_IT_TO_T,
89 	EFC_NODE_ENABLE_IT_TO_I,
90 	EFC_NODE_ENABLE_IT_TO_IT,
91 };
92 
93 static inline enum efc_node_enable
94 efc_node_get_enable(struct efc_node *node)
95 {
96 	u32 retval = 0;
97 
98 	if (node->nport->enable_ini)
99 		retval |= (1U << 3);
100 	if (node->nport->enable_tgt)
101 		retval |= (1U << 2);
102 	if (node->init)
103 		retval |= (1U << 1);
104 	if (node->targ)
105 		retval |= (1U << 0);
106 	return (enum efc_node_enable)retval;
107 }
108 
109 int
110 efc_node_check_els_req(struct efc_sm_ctx *ctx,
111 		       enum efc_sm_event evt, void *arg,
112 		       u8 cmd, void (*efc_node_common_func)(const char *,
113 		       struct efc_sm_ctx *, enum efc_sm_event, void *),
114 		       const char *funcname);
115 int
116 efc_node_check_ns_req(struct efc_sm_ctx *ctx,
117 		      enum efc_sm_event evt, void *arg,
118 		      u16 cmd, void (*efc_node_common_func)(const char *,
119 		      struct efc_sm_ctx *, enum efc_sm_event, void *),
120 		      const char *funcname);
121 int
122 efc_node_attach(struct efc_node *node);
123 struct efc_node *
124 efc_node_alloc(struct efc_nport *nport, u32 port_id,
125 	       bool init, bool targ);
126 void
127 efc_node_free(struct efc_node *efc);
128 void
129 efc_node_update_display_name(struct efc_node *node);
130 void efc_node_post_event(struct efc_node *node, enum efc_sm_event evt,
131 			 void *arg);
132 
133 void
134 __efc_node_shutdown(struct efc_sm_ctx *ctx,
135 		    enum efc_sm_event evt, void *arg);
136 void
137 __efc_node_wait_node_free(struct efc_sm_ctx *ctx,
138 			  enum efc_sm_event evt, void *arg);
139 void
140 __efc_node_wait_els_shutdown(struct efc_sm_ctx *ctx,
141 			     enum efc_sm_event evt, void *arg);
142 void
143 __efc_node_wait_ios_shutdown(struct efc_sm_ctx *ctx,
144 			     enum efc_sm_event evt, void *arg);
145 void
146 efc_node_save_sparms(struct efc_node *node, void *payload);
147 void
148 efc_node_transition(struct efc_node *node,
149 		    void (*state)(struct efc_sm_ctx *, enum efc_sm_event,
150 				  void *), void *data);
151 void
152 __efc_node_common(const char *funcname, struct efc_sm_ctx *ctx,
153 		  enum efc_sm_event evt, void *arg);
154 
155 void
156 efc_node_initiate_cleanup(struct efc_node *node);
157 
158 void
159 efc_node_build_eui_name(char *buf, u32 buf_len, uint64_t eui_name);
160 
161 void
162 efc_node_pause(struct efc_node *node,
163 	       void (*state)(struct efc_sm_ctx *ctx,
164 			     enum efc_sm_event evt, void *arg));
165 void
166 __efc_node_paused(struct efc_sm_ctx *ctx,
167 		  enum efc_sm_event evt, void *arg);
168 int
169 efc_node_active_ios_empty(struct efc_node *node);
170 void
171 efc_node_send_ls_io_cleanup(struct efc_node *node);
172 
173 int
174 efc_els_io_list_empty(struct efc_node *node, struct list_head *list);
175 
176 void
177 efc_process_node_pending(struct efc_node *domain);
178 
179 u64 efc_node_get_wwnn(struct efc_node *node);
180 struct efc_node *
181 efc_node_find(struct efc_nport *nport, u32 id);
182 void
183 efc_node_post_els_resp(struct efc_node *node, u32 evt, void *arg);
184 void
185 efc_node_recv_els_frame(struct efc_node *node, struct efc_hw_sequence *s);
186 void
187 efc_node_recv_ct_frame(struct efc_node *node, struct efc_hw_sequence *seq);
188 void
189 efc_node_recv_fcp_cmd(struct efc_node *node, struct efc_hw_sequence *seq);
190 
191 #endif /* __EFC_NODE_H__ */
192