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