xref: /titanic_41/usr/src/uts/common/sys/fct.h (revision 3fb517f786391b507780c78aabb8d98bfea9efe9)
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 usr/src/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 usr/src/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  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 #ifndef	_FCT_H
25 #define	_FCT_H
26 
27 /*
28  * Definitions for common FC Target.
29  */
30 #include <sys/note.h>
31 #include <sys/stmf_defines.h>
32 #include <sys/fct_defines.h>
33 #include <sys/portif.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 typedef enum fct_struct_id {
40 	FCT_STRUCT_LOCAL_PORT = 1,
41 	FCT_STRUCT_REMOTE_PORT,
42 	FCT_STRUCT_CMD_RCVD_ELS,
43 	FCT_STRUCT_CMD_SOL_ELS,
44 	FCT_STRUCT_CMD_SOL_CT,
45 	FCT_STRUCT_CMD_RCVD_ABTS,
46 	FCT_STRUCT_CMD_FCP_XCHG,
47 	FCT_STRUCT_DBUF_STORE,
48 
49 	FCT_MAX_STRUCT_IDS
50 } fct_struct_id_t;
51 
52 typedef struct fct_remote_port {
53 	void		*rp_fct_private;
54 	void		*rp_fca_private;
55 
56 	struct fct_local_port *rp_port;
57 	char		rp_nwwn_str[FC_WWN_BUFLEN];
58 	char		rp_pwwn_str[FC_WWN_BUFLEN];
59 	uint8_t		rp_nwwn[FC_WWN_LEN];
60 	uint8_t		rp_pwwn[FC_WWN_LEN];
61 	uint32_t	rp_id;		/* 8 or 24 bit */
62 	uint32_t	rp_hard_address;
63 	uint16_t	rp_handle;
64 } fct_remote_port_t;
65 
66 #define	FCT_HANDLE_NONE	0xffff
67 
68 typedef struct fct_cmd {
69 	void		*cmd_fct_private;
70 	void		*cmd_fca_private;
71 	void		*cmd_specific;
72 
73 	struct fct_local_port	*cmd_port;
74 
75 	/* During cmd porting this can be set to NULL */
76 	struct fct_remote_port	*cmd_rp;
77 
78 	/* To link cmds together for handling things like ABTS. */
79 	struct fct_cmd	*cmd_link;
80 	uint8_t		cmd_type;
81 	uint8_t		cmd_rsvd1;
82 
83 	/* During cmd posting this can be set to FCT_HANDLE_NONE */
84 	uint16_t	cmd_rp_handle;
85 	uint32_t	cmd_handle;
86 	uint32_t	cmd_rportid;
87 	uint32_t	cmd_lportid;
88 	uint32_t	cmd_rsvd2;
89 	uint16_t	cmd_oxid;
90 	uint16_t	cmd_rxid;
91 	fct_status_t	cmd_comp_status;
92 } fct_cmd_t;
93 
94 /*
95  * fcmd_cmd_handle: Bit definitions.
96  *   31		  23	       15	    7	       0
97  *  +--------------+------------+------------+------------+
98  *  | V |uniq_cntr |fca specific|   cmd slot index	  |
99  *  +--------------+------------+------------+------------+
100  * V = handle valid.
101  */
102 #define	CMD_HANDLE_SLOT_INDEX(x)	((x) & 0xffff)
103 #define	CMD_HANDLE_VALID(x)		((x) & 0x80000000)
104 
105 enum fct_cmd_types {
106 	FCT_CMD_FCP_XCHG =	0x0001,
107 	FCT_CMD_RCVD_ELS =	0x0002,
108 	FCT_CMD_SOL_ELS =	0x0004,
109 	FCT_CMD_RCVD_ABTS =	0x0008,
110 	FCT_CMD_SOL_CT =	0x0010,
111 
112 	FCT_CMD_TYPE_ALL =	0xffff
113 };
114 
115 typedef struct fct_els {
116 	uint16_t	els_req_size;
117 	uint16_t	els_resp_size;
118 	uint16_t	els_req_alloc_size;
119 	uint16_t	els_resp_alloc_size;
120 	uint8_t		*els_req_payload;
121 	uint8_t		*els_resp_payload;
122 } fct_els_t;
123 
124 typedef struct fct_sol_ct {
125 	uint16_t	ct_req_size;
126 	uint16_t	ct_resp_size;
127 	uint16_t	ct_req_alloc_size;
128 	uint16_t	ct_resp_alloc_size;
129 	uint8_t		*ct_req_payload;
130 	uint8_t		*ct_resp_payload;
131 } fct_sol_ct_t;
132 
133 typedef struct fct_rcvd_abts {
134 	uint8_t		abts_resp_rctl;	/* Can be BA_ACC or BA_RJT */
135 	uint8_t		abts_state;
136 	uint16_t	rsvd;
137 	uint8_t		abts_resp_payload[12];
138 } fct_rcvd_abts_t;
139 
140 /*
141  * abts state
142  */
143 #define	ABTS_STATE_RECEIVED		0
144 #define	ABTS_STATE_RESPONDED		1
145 #define	ABTS_STATE_COMPLETED		2
146 #define	ABTS_STATE_ABORT_REQUESTED	3
147 #define	ABTS_STATE_ABORT_COMPLETED	4
148 
149 #define	FCHBA_MANUFACTURER_LEN		64
150 #define	FCHBA_SERIAL_NUMBER_LEN		64
151 #define	FCHBA_MODEL_LEN			256
152 #define	FCHBA_MODEL_DESCRIPTION_LEN	256
153 #define	FCHBA_HARDWARE_VERSION_LEN	256
154 #define	FCHBA_DRIVER_VERSION_LEN	256
155 #define	FCHBA_OPTION_ROM_VERSION_LEN	256
156 #define	FCHBA_FIRMWARE_VERSION_LEN	256
157 #define	FCHBA_DRIVER_NAME_LEN		256
158 #define	FCHBA_SYMB_NAME_LEN		255
159 
160 #define	FC_TGT_PORT_INFO_CMD		(((uint32_t)'I') << 24)
161 #define	FC_TGT_PORT_RLS			FC_TGT_PORT_INFO_CMD + 0x1
162 
163 typedef struct fct_port_attrs {
164 	char		manufacturer[FCHBA_MANUFACTURER_LEN];
165 	char		serial_number[FCHBA_SERIAL_NUMBER_LEN];
166 	char		model[FCHBA_MODEL_LEN];
167 	char		model_description[FCHBA_MODEL_DESCRIPTION_LEN];
168 	char		hardware_version[FCHBA_HARDWARE_VERSION_LEN];
169 	char		driver_version[FCHBA_DRIVER_VERSION_LEN];
170 	char		option_rom_version[FCHBA_OPTION_ROM_VERSION_LEN];
171 	char		firmware_version[FCHBA_FIRMWARE_VERSION_LEN];
172 	char		driver_name[FCHBA_DRIVER_NAME_LEN];
173 	uint32_t	vendor_specific_id;
174 	uint32_t	supported_cos;
175 	uint32_t	supported_speed;
176 	uint32_t	max_frame_size;
177 } fct_port_attrs_t;
178 
179 typedef struct fct_port_link_status {
180 	uint32_t	LinkFailureCount;
181 	uint32_t	LossOfSyncCount;
182 	uint32_t	LossOfSignalsCount;
183 	uint32_t	PrimitiveSeqProtocolErrorCount;
184 	uint32_t	InvalidTransmissionWordCount;
185 	uint32_t	InvalidCRCCount;
186 } fct_port_link_status_t;
187 
188 typedef struct fct_dbuf_store {
189 	void			*fds_fct_private;
190 	void			*fds_fca_private;
191 	struct stmf_dbuf_store	*fds_ds;
192 
193 	stmf_data_buf_t *(*fds_alloc_data_buf)(struct fct_local_port *port,
194 			    uint32_t size, uint32_t *pminsize, uint32_t flags);
195 	void		(*fds_free_data_buf)(struct fct_dbuf_store *fds,
196 			    stmf_data_buf_t *dbuf);
197 	stmf_status_t	(*fds_setup_dbuf)(struct fct_local_port *port,
198 			    stmf_data_buf_t *dbuf, uint32_t flags);
199 	void		(*fds_teardown_dbuf)(struct fct_dbuf_store *fds,
200 			    stmf_data_buf_t *dbuf);
201 
202 	uint32_t		fds_max_sgl_xfer_len;
203 	uint32_t		fds_copy_threshold;
204 } fct_dbuf_store_t;
205 
206 #define	FCT_FCA_MODREV_1	1
207 
208 typedef struct fct_local_port {
209 	void			*port_fct_private;
210 	void			*port_fca_private;
211 	stmf_local_port_t	*port_lport;
212 
213 	char			port_nwwn_str[FC_WWN_BUFLEN];
214 	char			port_pwwn_str[FC_WWN_BUFLEN];
215 	uint8_t			port_nwwn[FC_WWN_LEN];
216 	uint8_t			port_pwwn[FC_WWN_LEN];
217 	char			*port_default_alias;
218 	char			*port_sym_node_name;
219 	char			*port_sym_port_name;
220 
221 	stmf_port_provider_t	*port_pp;
222 
223 	uint32_t		port_hard_address;
224 	uint16_t		port_max_logins;
225 	uint16_t		port_max_xchges;
226 	uint32_t		port_fca_fcp_cmd_size;
227 	uint32_t		port_fca_rp_private_size;
228 	uint32_t		port_fca_sol_els_private_size;
229 	uint32_t		port_fca_sol_ct_private_size;
230 
231 	/* in milliseconds */
232 	uint32_t		port_fca_abort_timeout;
233 
234 	fct_dbuf_store_t	*port_fds;
235 	fct_status_t		(*port_get_link_info)(
236 		struct fct_local_port *port, struct fct_link_info *li);
237 	fct_status_t		(*port_register_remote_port)(
238 		struct fct_local_port *port, struct fct_remote_port *rp,
239 		struct fct_cmd *login_els);
240 	fct_status_t		(*port_deregister_remote_port)(
241 		struct fct_local_port *port, struct fct_remote_port *rp);
242 	fct_status_t		(*port_send_cmd)(fct_cmd_t *cmd);
243 	fct_status_t		(*port_xfer_scsi_data)(fct_cmd_t *cmd,
244 			stmf_data_buf_t *dbuf, uint32_t flags);
245 	fct_status_t		(*port_send_cmd_response)(fct_cmd_t *cmd,
246 					uint32_t ioflags);
247 	fct_status_t		(*port_abort_cmd)(struct fct_local_port *port,
248 			fct_cmd_t *cmd, uint32_t flags);
249 	void			(*port_ctl)(struct fct_local_port *port,
250 						int cmd, void *arg);
251 	fct_status_t		(*port_flogi_xchg)(struct fct_local_port *port,
252 			struct fct_flogi_xchg *fx);
253 	void			(*port_populate_hba_details)(
254 		struct fct_local_port *port, struct fct_port_attrs *port_attrs);
255 	fct_status_t		(*port_info)(uint32_t cmd,
256 		struct fct_local_port *port, void *arg, uint8_t *buf,
257 		uint32_t *bufsizep);
258 	int		port_fca_version;
259 } fct_local_port_t;
260 
261 /*
262  * Common struct used during FLOGI exchange.
263  */
264 typedef struct fct_flogi_xchg {
265 	uint8_t		fx_op;		/* ELS_OP_FLOGI or ELS_OP_ACC/RJT */
266 	uint8_t		fx_rjt_reason;
267 	uint8_t		fx_rjt_expl;
268 	uint8_t		fx_sec_timeout;	/* Timeout in seconds */
269 	uint32_t	fx_fport:1,	/* 0=N_port, 1=F_port */
270 			rsvd2:31;
271 	uint32_t	fx_sid;		/* 24 bit SID to use */
272 	uint32_t	fx_did;		/* 24 bit DID to use */
273 	uint8_t		fx_pwwn[8];
274 	uint8_t		fx_nwwn[8];
275 } fct_flogi_xchg_t;
276 
277 typedef struct fct_link_info {
278 	uint32_t		portid;
279 	uint8_t			port_topology;
280 	uint8_t			port_speed;
281 
282 	uint8_t			rsvd:5,
283 
284 	/*
285 	 * FCA sets this bit to indicate that fct does not need to do FLOGI
286 	 * because either FCA did the FLOGI or it determined that its a private
287 	 * loop. Setting this bit by FCA is optional.
288 	 */
289 				port_no_fct_flogi:1,
290 
291 	/* FCA sets this bit to indicate that it did FLOGI */
292 				port_fca_flogi_done:1,
293 
294 	/* FCT sets this bit to indicate that it did FLOGI */
295 				port_fct_flogi_done:1;
296 
297 	uint8_t			rsvd1;
298 
299 	/* The fields below are only valid if someone did a successful flogi */
300 	uint8_t			port_rnwwn[8];
301 	uint8_t			port_rpwwn[8];
302 } fct_link_info_t;
303 
304 typedef struct fct_port_stat {
305 	kstat_named_t	link_failure_cnt;
306 	kstat_named_t	loss_of_sync_cnt;
307 	kstat_named_t	loss_of_signals_cnt;
308 	kstat_named_t	prim_seq_protocol_err_cnt;
309 	kstat_named_t	invalid_tx_word_cnt;
310 	kstat_named_t	invalid_crc_cnt;
311 } fct_port_stat_t;
312 
313 /*
314  * port topology
315  */
316 #define	PORT_TOPOLOGY_UNKNOWN		0
317 #define	PORT_TOPOLOGY_PT_TO_PT		1
318 #define	PORT_TOPOLOGY_PRIVATE_LOOP	2
319 #define	PORT_TOPOLOGY_PUBLIC_LOOP	6
320 #define	PORT_TOPOLOGY_FABRIC_PT_TO_PT	5
321 #define	PORT_TOPOLOGY_FABRIC_BIT	4
322 
323 #define	PORT_FLOGI_DONE(li)	(((li)->port_fca_flogi_done) || \
324 					((li)->port_fct_flogi_done))
325 
326 /*
327  * port speed
328  */
329 #define	PORT_SPEED_UNKNOWN		0
330 #define	PORT_SPEED_1G			1
331 #define	PORT_SPEED_2G			2
332 #define	PORT_SPEED_4G			4
333 #define	PORT_SPEED_8G			8
334 #define	PORT_SPEED_10G			16
335 
336 /*
337  * Abort commands
338  */
339 #define	FCT_TERMINATE_CMD		1
340 
341 /*
342  * FCT port states.
343  */
344 #define	FCT_STATE_OFFLINE	0
345 #define	FCT_STATE_ONLINING	1
346 #define	FCT_STATE_ONLINE	2
347 #define	FCT_STATE_OFFLINING	3
348 
349 /*
350  * fct ctl commands. These should not conflict with stmf ctl commands
351  */
352 #define	FCT_CMD_PORT_ONLINE		(STMF_LPORT_CTL_CMDS | 0x01)
353 #define	FCT_CMD_PORT_ONLINE_COMPLETE	(STMF_LPORT_CTL_CMDS | 0x02)
354 #define	FCT_CMD_PORT_OFFLINE		(STMF_LPORT_CTL_CMDS | 0x03)
355 #define	FCT_CMD_PORT_OFFLINE_COMPLETE	(STMF_LPORT_CTL_CMDS | 0x04)
356 #define	FCT_ACK_PORT_ONLINE_COMPLETE	(STMF_LPORT_CTL_CMDS | 0x05)
357 #define	FCT_ACK_PORT_OFFLINE_COMPLETE	(STMF_LPORT_CTL_CMDS | 0x06)
358 #define	FCT_CMD_FORCE_LIP		(STMF_LPORT_CTL_CMDS | 0x07)
359 
360 /*
361  * IO flags for cmd flow.
362  */
363 #define	FCT_IOF_FCA_DONE		0x10000
364 #define	FCT_IOF_FORCE_FCA_DONE		0x20000
365 
366 /*
367  * Fill CTIU preample
368  */
369 #ifdef	lint
370 #define	FCT_FILL_CTIU_PREAMPLE(x_payload, x_ctop)	_NOTE(EMPTY)
371 #else
372 #define	FCT_FILL_CTIU_PREAMPLE(x_payload, x_ctop)	\
373 	do {						\
374 		x_payload[0] = 0x02;			\
375 		x_payload[4] = 0xFC;			\
376 		x_payload[5] = 0x02;			\
377 		x_payload[8] = 0xFF & (x_ctop >> 8);	\
378 		x_payload[9] = 0xFF & (x_ctop);		\
379 	} while (0)
380 #endif
381 
382 uint64_t fct_netbuf_to_value(uint8_t *buf, uint8_t nbytes);
383 void fct_value_to_netbuf(uint64_t value, uint8_t *buf, uint8_t nbytes);
384 void *fct_alloc(fct_struct_id_t struct_id, int additional_size, int flags);
385 void fct_free(void *ptr);
386 fct_cmd_t *fct_scsi_task_alloc(struct fct_local_port *port,
387     uint16_t rp_handle, uint32_t rportid, uint8_t *lun,
388     uint16_t cdb_length, uint16_t task_ext);
389 fct_status_t fct_register_local_port(fct_local_port_t *port);
390 fct_status_t fct_deregister_local_port(fct_local_port_t *port);
391 void fct_handle_event(fct_local_port_t *port, int event_id,
392     uint32_t event_flags, caddr_t arg);
393 void fct_post_rcvd_cmd(fct_cmd_t *cmd, stmf_data_buf_t *dbuf);
394 void fct_queue_cmd_for_termination(fct_cmd_t *cmd, fct_status_t s);
395 void fct_queue_scsi_task_for_termination(fct_cmd_t *cmd, fct_status_t s);
396 fct_cmd_t *fct_handle_to_cmd(fct_local_port_t *port, uint32_t fct_handle);
397 void fct_ctl(struct stmf_local_port *lport, int cmd, void *arg);
398 void fct_cmd_fca_aborted(fct_cmd_t *cmd, fct_status_t s, uint32_t ioflags);
399 uint16_t fct_get_rp_handle(fct_local_port_t *port, uint32_t rportid);
400 void fct_send_response_done(fct_cmd_t *cmd, fct_status_t s, uint32_t ioflags);
401 void fct_send_cmd_done(fct_cmd_t *cmd, fct_status_t s, uint32_t ioflags);
402 void fct_scsi_data_xfer_done(fct_cmd_t *cmd, stmf_data_buf_t *dbuf,
403     uint32_t ioflags);
404 fct_status_t fct_port_initialize(fct_local_port_t *port, uint32_t rflags,
405     char *additional_info);
406 fct_status_t fct_port_shutdown(fct_local_port_t *port, uint32_t rflags,
407     char *additional_info);
408 fct_status_t fct_handle_rcvd_flogi(fct_local_port_t *port,
409     fct_flogi_xchg_t *fx);
410 void fct_log_local_port_event(fct_local_port_t *port, char *subclass);
411 void fct_log_remote_port_event(fct_local_port_t *port, char *subclass,
412     uint8_t *rp_pwwn, uint32_t rp_id);
413 void fct_wwn_to_str(char *to_ptr, const uint8_t *from_ptr);
414 
415 #ifdef	__cplusplus
416 }
417 #endif
418 
419 #endif /* _FCT_H */
420