xref: /openbmc/linux/drivers/scsi/ibmvscsi/ibmvfc.h (revision c88773dc)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * ibmvfc.h -- driver for IBM Power Virtual Fibre Channel Adapter
4  *
5  * Written By: Brian King <brking@linux.vnet.ibm.com>, IBM Corporation
6  *
7  * Copyright (C) IBM Corporation, 2008
8  */
9 
10 #ifndef _IBMVFC_H
11 #define _IBMVFC_H
12 
13 #include <linux/list.h>
14 #include <linux/types.h>
15 #include <scsi/viosrp.h>
16 
17 #define IBMVFC_NAME	"ibmvfc"
18 #define IBMVFC_DRIVER_VERSION		"1.0.11"
19 #define IBMVFC_DRIVER_DATE		"(April 12, 2013)"
20 
21 #define IBMVFC_DEFAULT_TIMEOUT	60
22 #define IBMVFC_ADISC_CANCEL_TIMEOUT	45
23 #define IBMVFC_ADISC_TIMEOUT		15
24 #define IBMVFC_ADISC_PLUS_CANCEL_TIMEOUT	\
25 		(IBMVFC_ADISC_TIMEOUT + IBMVFC_ADISC_CANCEL_TIMEOUT)
26 #define IBMVFC_INIT_TIMEOUT		120
27 #define IBMVFC_ABORT_TIMEOUT		8
28 #define IBMVFC_ABORT_WAIT_TIMEOUT	40
29 #define IBMVFC_MAX_REQUESTS_DEFAULT	100
30 
31 #define IBMVFC_DEBUG			0
32 #define IBMVFC_MAX_TARGETS		1024
33 #define IBMVFC_MAX_LUN			0xffffffff
34 #define IBMVFC_MAX_SECTORS		0xffffu
35 #define IBMVFC_MAX_DISC_THREADS	4
36 #define IBMVFC_TGT_MEMPOOL_SZ		64
37 #define IBMVFC_MAX_CMDS_PER_LUN	64
38 #define IBMVFC_MAX_HOST_INIT_RETRIES	6
39 #define IBMVFC_MAX_TGT_INIT_RETRIES		3
40 #define IBMVFC_DEV_LOSS_TMO		(5 * 60)
41 #define IBMVFC_DEFAULT_LOG_LEVEL	2
42 #define IBMVFC_MAX_CDB_LEN		16
43 #define IBMVFC_CLS3_ERROR		0
44 
45 /*
46  * Ensure we have resources for ERP and initialization:
47  * 1 for ERP
48  * 1 for initialization
49  * 1 for NPIV Logout
50  * 2 for BSG passthru
51  * 2 for each discovery thread
52  */
53 #define IBMVFC_NUM_INTERNAL_REQ	(1 + 1 + 1 + 2 + (disc_threads * 2))
54 
55 #define IBMVFC_MAD_SUCCESS		0x00
56 #define IBMVFC_MAD_NOT_SUPPORTED	0xF1
57 #define IBMVFC_MAD_FAILED		0xF7
58 #define IBMVFC_MAD_DRIVER_FAILED	0xEE
59 #define IBMVFC_MAD_CRQ_ERROR		0xEF
60 
61 enum ibmvfc_crq_valid {
62 	IBMVFC_CRQ_CMD_RSP		= 0x80,
63 	IBMVFC_CRQ_INIT_RSP		= 0xC0,
64 	IBMVFC_CRQ_XPORT_EVENT		= 0xFF,
65 };
66 
67 enum ibmvfc_crq_init_msg {
68 	IBMVFC_CRQ_INIT			= 0x01,
69 	IBMVFC_CRQ_INIT_COMPLETE	= 0x02,
70 };
71 
72 enum ibmvfc_crq_xport_evts {
73 	IBMVFC_PARTNER_FAILED		= 0x01,
74 	IBMVFC_PARTNER_DEREGISTER	= 0x02,
75 	IBMVFC_PARTITION_MIGRATED	= 0x06,
76 };
77 
78 enum ibmvfc_cmd_status_flags {
79 	IBMVFC_FABRIC_MAPPED		= 0x0001,
80 	IBMVFC_VIOS_FAILURE		= 0x0002,
81 	IBMVFC_FC_FAILURE			= 0x0004,
82 	IBMVFC_FC_SCSI_ERROR		= 0x0008,
83 	IBMVFC_HW_EVENT_LOGGED		= 0x0010,
84 	IBMVFC_VIOS_LOGGED		= 0x0020,
85 };
86 
87 enum ibmvfc_fabric_mapped_errors {
88 	IBMVFC_UNABLE_TO_ESTABLISH	= 0x0001,
89 	IBMVFC_XPORT_FAULT		= 0x0002,
90 	IBMVFC_CMD_TIMEOUT		= 0x0003,
91 	IBMVFC_ENETDOWN			= 0x0004,
92 	IBMVFC_HW_FAILURE			= 0x0005,
93 	IBMVFC_LINK_DOWN_ERR		= 0x0006,
94 	IBMVFC_LINK_DEAD_ERR		= 0x0007,
95 	IBMVFC_UNABLE_TO_REGISTER	= 0x0008,
96 	IBMVFC_XPORT_BUSY			= 0x000A,
97 	IBMVFC_XPORT_DEAD			= 0x000B,
98 	IBMVFC_CONFIG_ERROR		= 0x000C,
99 	IBMVFC_NAME_SERVER_FAIL		= 0x000D,
100 	IBMVFC_LINK_HALTED		= 0x000E,
101 	IBMVFC_XPORT_GENERAL		= 0x8000,
102 };
103 
104 enum ibmvfc_vios_errors {
105 	IBMVFC_CRQ_FAILURE			= 0x0001,
106 	IBMVFC_SW_FAILURE				= 0x0002,
107 	IBMVFC_INVALID_PARAMETER		= 0x0003,
108 	IBMVFC_MISSING_PARAMETER		= 0x0004,
109 	IBMVFC_HOST_IO_BUS			= 0x0005,
110 	IBMVFC_TRANS_CANCELLED			= 0x0006,
111 	IBMVFC_TRANS_CANCELLED_IMPLICIT	= 0x0007,
112 	IBMVFC_INSUFFICIENT_RESOURCE		= 0x0008,
113 	IBMVFC_PLOGI_REQUIRED			= 0x0010,
114 	IBMVFC_COMMAND_FAILED			= 0x8000,
115 };
116 
117 enum ibmvfc_mad_types {
118 	IBMVFC_NPIV_LOGIN		= 0x0001,
119 	IBMVFC_DISC_TARGETS	= 0x0002,
120 	IBMVFC_PORT_LOGIN		= 0x0004,
121 	IBMVFC_PROCESS_LOGIN	= 0x0008,
122 	IBMVFC_QUERY_TARGET	= 0x0010,
123 	IBMVFC_MOVE_LOGIN		= 0x0020,
124 	IBMVFC_IMPLICIT_LOGOUT	= 0x0040,
125 	IBMVFC_PASSTHRU		= 0x0200,
126 	IBMVFC_TMF_MAD		= 0x0100,
127 	IBMVFC_NPIV_LOGOUT	= 0x0800,
128 	IBMVFC_CHANNEL_ENQUIRY	= 0x1000,
129 	IBMVFC_CHANNEL_SETUP	= 0x2000,
130 	IBMVFC_CONNECTION_INFO	= 0x4000,
131 };
132 
133 struct ibmvfc_mad_common {
134 	__be32 version;
135 	__be32 reserved;
136 	__be32 opcode;
137 	__be16 status;
138 	__be16 length;
139 	__be64 tag;
140 } __packed __aligned(8);
141 
142 struct ibmvfc_npiv_login_mad {
143 	struct ibmvfc_mad_common common;
144 	struct srp_direct_buf buffer;
145 } __packed __aligned(8);
146 
147 struct ibmvfc_npiv_logout_mad {
148 	struct ibmvfc_mad_common common;
149 } __packed __aligned(8);
150 
151 #define IBMVFC_MAX_NAME 256
152 
153 struct ibmvfc_npiv_login {
154 	__be32 ostype;
155 #define IBMVFC_OS_LINUX	0x02
156 	__be32 pad;
157 	__be64 max_dma_len;
158 	__be32 max_payload;
159 	__be32 max_response;
160 	__be32 partition_num;
161 	__be32 vfc_frame_version;
162 	__be16 fcp_version;
163 	__be16 flags;
164 #define IBMVFC_CLIENT_MIGRATED	0x01
165 #define IBMVFC_FLUSH_ON_HALT		0x02
166 	__be32 max_cmds;
167 	__be64 capabilities;
168 #define IBMVFC_CAN_MIGRATE		0x01
169 #define IBMVFC_CAN_USE_CHANNELS		0x02
170 #define IBMVFC_CAN_HANDLE_FPIN		0x04
171 	__be64 node_name;
172 	struct srp_direct_buf async;
173 	u8 partition_name[IBMVFC_MAX_NAME];
174 	u8 device_name[IBMVFC_MAX_NAME];
175 	u8 drc_name[IBMVFC_MAX_NAME];
176 	__be64 reserved2[2];
177 } __packed __aligned(8);
178 
179 struct ibmvfc_common_svc_parms {
180 	__be16 fcph_version;
181 	__be16 b2b_credit;
182 	__be16 features;
183 	__be16 bb_rcv_sz; /* upper nibble is BB_SC_N */
184 	__be32 ratov;
185 	__be32 edtov;
186 } __packed __aligned(4);
187 
188 struct ibmvfc_service_parms {
189 	struct ibmvfc_common_svc_parms common;
190 	u8 port_name[8];
191 	u8 node_name[8];
192 	__be32 class1_parms[4];
193 	__be32 class2_parms[4];
194 	__be32 class3_parms[4];
195 	__be32 obsolete[4];
196 	__be32 vendor_version[4];
197 	__be32 services_avail[2];
198 	__be32 ext_len;
199 	__be32 reserved[30];
200 	__be32 clk_sync_qos[2];
201 	__be32 reserved2;
202 } __packed __aligned(4);
203 
204 struct ibmvfc_npiv_login_resp {
205 	__be32 version;
206 	__be16 status;
207 	__be16 error;
208 	__be32 flags;
209 #define IBMVFC_NATIVE_FC		0x01
210 	__be32 reserved;
211 	__be64 capabilities;
212 #define IBMVFC_CAN_FLUSH_ON_HALT	0x08
213 #define IBMVFC_CAN_SUPPRESS_ABTS	0x10
214 #define IBMVFC_CAN_SUPPORT_CHANNELS	0x20
215 	__be32 max_cmds;
216 	__be32 scsi_id_sz;
217 	__be64 max_dma_len;
218 	__be64 scsi_id;
219 	__be64 port_name;
220 	__be64 node_name;
221 	__be64 link_speed;
222 	u8 partition_name[IBMVFC_MAX_NAME];
223 	u8 device_name[IBMVFC_MAX_NAME];
224 	u8 port_loc_code[IBMVFC_MAX_NAME];
225 	u8 drc_name[IBMVFC_MAX_NAME];
226 	struct ibmvfc_service_parms service_parms;
227 	__be64 reserved2;
228 } __packed __aligned(8);
229 
230 union ibmvfc_npiv_login_data {
231 	struct ibmvfc_npiv_login login;
232 	struct ibmvfc_npiv_login_resp resp;
233 } __packed __aligned(8);
234 
235 struct ibmvfc_discover_targets_entry {
236 	__be32 scsi_id;
237 	__be32 pad;
238 	__be64 wwpn;
239 #define IBMVFC_DISC_TGT_SCSI_ID_MASK	0x00ffffff
240 } __packed __aligned(8);
241 
242 struct ibmvfc_discover_targets {
243 	struct ibmvfc_mad_common common;
244 	struct srp_direct_buf buffer;
245 	__be32 flags;
246 #define IBMVFC_DISC_TGT_PORT_ID_WWPN_LIST	0x02
247 	__be16 status;
248 	__be16 error;
249 	__be32 bufflen;
250 	__be32 num_avail;
251 	__be32 num_written;
252 	__be64 reserved[2];
253 } __packed __aligned(8);
254 
255 enum ibmvfc_fc_reason {
256 	IBMVFC_INVALID_ELS_CMD_CODE	= 0x01,
257 	IBMVFC_INVALID_VERSION		= 0x02,
258 	IBMVFC_LOGICAL_ERROR		= 0x03,
259 	IBMVFC_INVALID_CT_IU_SIZE	= 0x04,
260 	IBMVFC_LOGICAL_BUSY		= 0x05,
261 	IBMVFC_PROTOCOL_ERROR		= 0x07,
262 	IBMVFC_UNABLE_TO_PERFORM_REQ	= 0x09,
263 	IBMVFC_CMD_NOT_SUPPORTED	= 0x0B,
264 	IBMVFC_SERVER_NOT_AVAIL		= 0x0D,
265 	IBMVFC_CMD_IN_PROGRESS		= 0x0E,
266 	IBMVFC_VENDOR_SPECIFIC		= 0xFF,
267 };
268 
269 enum ibmvfc_fc_type {
270 	IBMVFC_FABRIC_REJECT	= 0x01,
271 	IBMVFC_PORT_REJECT	= 0x02,
272 	IBMVFC_LS_REJECT		= 0x03,
273 	IBMVFC_FABRIC_BUSY	= 0x04,
274 	IBMVFC_PORT_BUSY		= 0x05,
275 	IBMVFC_BASIC_REJECT	= 0x06,
276 };
277 
278 enum ibmvfc_gs_explain {
279 	IBMVFC_PORT_NAME_NOT_REG	= 0x02,
280 };
281 
282 struct ibmvfc_port_login {
283 	struct ibmvfc_mad_common common;
284 	__be64 scsi_id;
285 	__be16 reserved;
286 	__be16 fc_service_class;
287 	__be32 blksz;
288 	__be32 hdr_per_blk;
289 	__be16 status;
290 	__be16 error;		/* also fc_reason */
291 	__be16 fc_explain;
292 	__be16 fc_type;
293 	__be32 reserved2;
294 	struct ibmvfc_service_parms service_parms;
295 	struct ibmvfc_service_parms service_parms_change;
296 	__be64 reserved3[2];
297 } __packed __aligned(8);
298 
299 struct ibmvfc_move_login {
300 	struct ibmvfc_mad_common common;
301 	__be64 old_scsi_id;
302 	__be64 new_scsi_id;
303 	__be64 wwpn;
304 	__be64 node_name;
305 	__be32 flags;
306 #define IBMVFC_MOVE_LOGIN_IMPLICIT_OLD_FAILED	0x01
307 #define IBMVFC_MOVE_LOGIN_IMPLICIT_NEW_FAILED	0x02
308 #define IBMVFC_MOVE_LOGIN_PORT_LOGIN_FAILED	0x04
309 	__be32 reserved;
310 	struct ibmvfc_service_parms service_parms;
311 	struct ibmvfc_service_parms service_parms_change;
312 	__be32 reserved2;
313 	__be16 service_class;
314 	__be16 vios_flags;
315 #define IBMVFC_MOVE_LOGIN_VF_NOT_SENT_ADAPTER	0x01
316 	__be64 reserved3;
317 } __packed __aligned(8);
318 
319 struct ibmvfc_prli_svc_parms {
320 	u8 type;
321 #define IBMVFC_SCSI_FCP_TYPE		0x08
322 	u8 type_ext;
323 	__be16 flags;
324 #define IBMVFC_PRLI_ORIG_PA_VALID			0x8000
325 #define IBMVFC_PRLI_RESP_PA_VALID			0x4000
326 #define IBMVFC_PRLI_EST_IMG_PAIR			0x2000
327 	__be32 orig_pa;
328 	__be32 resp_pa;
329 	__be32 service_parms;
330 #define IBMVFC_PRLI_TASK_RETRY			0x00000200
331 #define IBMVFC_PRLI_RETRY				0x00000100
332 #define IBMVFC_PRLI_DATA_OVERLAY			0x00000040
333 #define IBMVFC_PRLI_INITIATOR_FUNC			0x00000020
334 #define IBMVFC_PRLI_TARGET_FUNC			0x00000010
335 #define IBMVFC_PRLI_READ_FCP_XFER_RDY_DISABLED	0x00000002
336 #define IBMVFC_PRLI_WR_FCP_XFER_RDY_DISABLED	0x00000001
337 } __packed __aligned(4);
338 
339 struct ibmvfc_process_login {
340 	struct ibmvfc_mad_common common;
341 	__be64 scsi_id;
342 	struct ibmvfc_prli_svc_parms parms;
343 	u8 reserved[48];
344 	__be16 status;
345 	__be16 error;			/* also fc_reason */
346 	__be32 reserved2;
347 	__be64 reserved3[2];
348 } __packed __aligned(8);
349 
350 struct ibmvfc_query_tgt {
351 	struct ibmvfc_mad_common common;
352 	__be64 wwpn;
353 	__be64 scsi_id;
354 	__be16 status;
355 	__be16 error;
356 	__be16 fc_explain;
357 	__be16 fc_type;
358 	__be64 reserved[2];
359 } __packed __aligned(8);
360 
361 struct ibmvfc_implicit_logout {
362 	struct ibmvfc_mad_common common;
363 	__be64 old_scsi_id;
364 	__be64 reserved[2];
365 } __packed __aligned(8);
366 
367 struct ibmvfc_tmf {
368 	struct ibmvfc_mad_common common;
369 	__be64 scsi_id;
370 	struct scsi_lun lun;
371 	__be32 flags;
372 #define IBMVFC_TMF_ABORT_TASK		0x02
373 #define IBMVFC_TMF_ABORT_TASK_SET	0x04
374 #define IBMVFC_TMF_LUN_RESET		0x10
375 #define IBMVFC_TMF_TGT_RESET		0x20
376 #define IBMVFC_TMF_LUA_VALID		0x40
377 #define IBMVFC_TMF_SUPPRESS_ABTS	0x80
378 	__be32 cancel_key;
379 	__be32 my_cancel_key;
380 	__be32 pad;
381 	__be64 reserved[2];
382 } __packed __aligned(8);
383 
384 enum ibmvfc_fcp_rsp_info_codes {
385 	RSP_NO_FAILURE		= 0x00,
386 	RSP_TMF_REJECTED		= 0x04,
387 	RSP_TMF_FAILED		= 0x05,
388 	RSP_TMF_INVALID_LUN	= 0x09,
389 };
390 
391 struct ibmvfc_fcp_rsp_info {
392 	u8 reserved[3];
393 	u8 rsp_code;
394 	u8 reserved2[4];
395 } __packed __aligned(2);
396 
397 enum ibmvfc_fcp_rsp_flags {
398 	FCP_BIDI_RSP			= 0x80,
399 	FCP_BIDI_READ_RESID_UNDER	= 0x40,
400 	FCP_BIDI_READ_RESID_OVER	= 0x20,
401 	FCP_CONF_REQ			= 0x10,
402 	FCP_RESID_UNDER			= 0x08,
403 	FCP_RESID_OVER			= 0x04,
404 	FCP_SNS_LEN_VALID			= 0x02,
405 	FCP_RSP_LEN_VALID			= 0x01,
406 };
407 
408 union ibmvfc_fcp_rsp_data {
409 	struct ibmvfc_fcp_rsp_info info;
410 	u8 sense[SCSI_SENSE_BUFFERSIZE + sizeof(struct ibmvfc_fcp_rsp_info)];
411 } __packed __aligned(8);
412 
413 struct ibmvfc_fcp_rsp {
414 	__be64 reserved;
415 	__be16 retry_delay_timer;
416 	u8 flags;
417 	u8 scsi_status;
418 	__be32 fcp_resid;
419 	__be32 fcp_sense_len;
420 	__be32 fcp_rsp_len;
421 	union ibmvfc_fcp_rsp_data data;
422 } __packed __aligned(8);
423 
424 enum ibmvfc_cmd_flags {
425 	IBMVFC_SCATTERLIST	= 0x0001,
426 	IBMVFC_NO_MEM_DESC	= 0x0002,
427 	IBMVFC_READ			= 0x0004,
428 	IBMVFC_WRITE		= 0x0008,
429 	IBMVFC_TMF			= 0x0080,
430 	IBMVFC_CLASS_3_ERR	= 0x0100,
431 };
432 
433 enum ibmvfc_fc_task_attr {
434 	IBMVFC_SIMPLE_TASK	= 0x00,
435 	IBMVFC_HEAD_OF_QUEUE	= 0x01,
436 	IBMVFC_ORDERED_TASK	= 0x02,
437 	IBMVFC_ACA_TASK		= 0x04,
438 };
439 
440 enum ibmvfc_fc_tmf_flags {
441 	IBMVFC_ABORT_TASK_SET	= 0x02,
442 	IBMVFC_LUN_RESET		= 0x10,
443 	IBMVFC_TARGET_RESET	= 0x20,
444 };
445 
446 struct ibmvfc_fcp_cmd_iu {
447 	struct scsi_lun lun;
448 	u8 crn;
449 	u8 pri_task_attr;
450 	u8 tmf_flags;
451 	u8 add_cdb_len;
452 #define IBMVFC_RDDATA		0x02
453 #define IBMVFC_WRDATA		0x01
454 	u8 cdb[IBMVFC_MAX_CDB_LEN];
455 	__be32 xfer_len;
456 } __packed __aligned(4);
457 
458 struct ibmvfc_cmd {
459 	__be64 task_tag;
460 	__be32 frame_type;
461 	__be32 payload_len;
462 	__be32 resp_len;
463 	__be32 adapter_resid;
464 	__be16 status;
465 	__be16 error;
466 	__be16 flags;
467 	__be16 response_flags;
468 #define IBMVFC_ADAPTER_RESID_VALID	0x01
469 	__be32 cancel_key;
470 	__be32 exchange_id;
471 	struct srp_direct_buf ext_func;
472 	struct srp_direct_buf ioba;
473 	struct srp_direct_buf resp;
474 	__be64 correlation;
475 	__be64 tgt_scsi_id;
476 	__be64 tag;
477 	__be64 reserved3[2];
478 	struct ibmvfc_fcp_cmd_iu iu;
479 	struct ibmvfc_fcp_rsp rsp;
480 } __packed __aligned(8);
481 
482 struct ibmvfc_passthru_fc_iu {
483 	__be32 payload[7];
484 #define IBMVFC_ADISC	0x52000000
485 	__be32 response[7];
486 };
487 
488 struct ibmvfc_passthru_iu {
489 	__be64 task_tag;
490 	__be32 cmd_len;
491 	__be32 rsp_len;
492 	__be16 status;
493 	__be16 error;
494 	__be32 flags;
495 #define IBMVFC_FC_ELS		0x01
496 #define IBMVFC_FC_CT_IU		0x02
497 	__be32 cancel_key;
498 #define IBMVFC_PASSTHRU_CANCEL_KEY	0x80000000
499 #define IBMVFC_INTERNAL_CANCEL_KEY	0x80000001
500 	__be32 reserved;
501 	struct srp_direct_buf cmd;
502 	struct srp_direct_buf rsp;
503 	__be64 correlation;
504 	__be64 scsi_id;
505 	__be64 tag;
506 	__be64 reserved2[2];
507 } __packed __aligned(8);
508 
509 struct ibmvfc_passthru_mad {
510 	struct ibmvfc_mad_common common;
511 	struct srp_direct_buf cmd_ioba;
512 	struct ibmvfc_passthru_iu iu;
513 	struct ibmvfc_passthru_fc_iu fc_iu;
514 } __packed __aligned(8);
515 
516 struct ibmvfc_channel_enquiry {
517 	struct ibmvfc_mad_common common;
518 	__be32 flags;
519 #define IBMVFC_NO_CHANNELS_TO_CRQ_SUPPORT	0x01
520 #define IBMVFC_SUPPORT_VARIABLE_SUBQ_MSG	0x02
521 #define IBMVFC_NO_N_TO_M_CHANNELS_SUPPORT	0x04
522 	__be32 num_scsi_subq_channels;
523 	__be32 num_nvmeof_subq_channels;
524 	__be32 num_scsi_vas_channels;
525 	__be32 num_nvmeof_vas_channels;
526 } __packed __aligned(8);
527 
528 struct ibmvfc_channel_setup_mad {
529 	struct ibmvfc_mad_common common;
530 	struct srp_direct_buf buffer;
531 } __packed __aligned(8);
532 
533 #define IBMVFC_MAX_CHANNELS	502
534 
535 struct ibmvfc_channel_setup {
536 	__be32 flags;
537 #define IBMVFC_CANCEL_CHANNELS		0x01
538 #define IBMVFC_USE_BUFFER		0x02
539 #define IBMVFC_CHANNELS_CANCELED	0x04
540 	__be32 reserved;
541 	__be32 num_scsi_subq_channels;
542 	__be32 num_nvmeof_subq_channels;
543 	__be32 num_scsi_vas_channels;
544 	__be32 num_nvmeof_vas_channels;
545 	struct srp_direct_buf buffer;
546 	__be64 reserved2[5];
547 	__be64 channel_handles[IBMVFC_MAX_CHANNELS];
548 } __packed __aligned(8);
549 
550 struct ibmvfc_connection_info {
551 	struct ibmvfc_mad_common common;
552 	__be64 information_bits;
553 #define IBMVFC_NO_FC_IO_CHANNEL		0x01
554 #define IBMVFC_NO_PHYP_VAS		0x02
555 #define IBMVFC_NO_PHYP_SUBQ		0x04
556 #define IBMVFC_PHYP_DEPRECATED_SUBQ	0x08
557 #define IBMVFC_PHYP_PRESERVED_SUBQ	0x10
558 #define IBMVFC_PHYP_FULL_SUBQ		0x20
559 	__be64 reserved[16];
560 } __packed __aligned(8);
561 
562 struct ibmvfc_trace_start_entry {
563 	u32 xfer_len;
564 } __packed;
565 
566 struct ibmvfc_trace_end_entry {
567 	u16 status;
568 	u16 error;
569 	u8 fcp_rsp_flags;
570 	u8 rsp_code;
571 	u8 scsi_status;
572 	u8 reserved;
573 } __packed;
574 
575 struct ibmvfc_trace_entry {
576 	struct ibmvfc_event *evt;
577 	u32 time;
578 	u32 scsi_id;
579 	u32 lun;
580 	u8 fmt;
581 	u8 op_code;
582 	u8 tmf_flags;
583 	u8 type;
584 #define IBMVFC_TRC_START	0x00
585 #define IBMVFC_TRC_END		0xff
586 	union {
587 		struct ibmvfc_trace_start_entry start;
588 		struct ibmvfc_trace_end_entry end;
589 	} u;
590 } __packed __aligned(8);
591 
592 enum ibmvfc_crq_formats {
593 	IBMVFC_CMD_FORMAT		= 0x01,
594 	IBMVFC_ASYNC_EVENT	= 0x02,
595 	IBMVFC_MAD_FORMAT		= 0x04,
596 };
597 
598 enum ibmvfc_async_event {
599 	IBMVFC_AE_ELS_PLOGI		= 0x0001,
600 	IBMVFC_AE_ELS_LOGO		= 0x0002,
601 	IBMVFC_AE_ELS_PRLO		= 0x0004,
602 	IBMVFC_AE_SCN_NPORT		= 0x0008,
603 	IBMVFC_AE_SCN_GROUP		= 0x0010,
604 	IBMVFC_AE_SCN_DOMAIN		= 0x0020,
605 	IBMVFC_AE_SCN_FABRIC		= 0x0040,
606 	IBMVFC_AE_LINK_UP			= 0x0080,
607 	IBMVFC_AE_LINK_DOWN		= 0x0100,
608 	IBMVFC_AE_LINK_DEAD		= 0x0200,
609 	IBMVFC_AE_HALT			= 0x0400,
610 	IBMVFC_AE_RESUME			= 0x0800,
611 	IBMVFC_AE_ADAPTER_FAILED	= 0x1000,
612 	IBMVFC_AE_FPIN			= 0x2000,
613 };
614 
615 struct ibmvfc_async_desc {
616 	const char *desc;
617 	enum ibmvfc_async_event ae;
618 	int log_level;
619 };
620 
621 struct ibmvfc_crq {
622 	volatile u8 valid;
623 	volatile u8 format;
624 	u8 reserved[6];
625 	volatile __be64 ioba;
626 } __packed __aligned(8);
627 
628 struct ibmvfc_crq_queue {
629 	struct ibmvfc_crq *msgs;
630 	int size, cur;
631 	dma_addr_t msg_token;
632 };
633 
634 enum ibmvfc_ae_link_state {
635 	IBMVFC_AE_LS_LINK_UP		= 0x01,
636 	IBMVFC_AE_LS_LINK_BOUNCED	= 0x02,
637 	IBMVFC_AE_LS_LINK_DOWN		= 0x04,
638 	IBMVFC_AE_LS_LINK_DEAD		= 0x08,
639 };
640 
641 enum ibmvfc_ae_fpin_status {
642 	IBMVFC_AE_FPIN_LINK_CONGESTED	= 0x1,
643 	IBMVFC_AE_FPIN_PORT_CONGESTED	= 0x2,
644 	IBMVFC_AE_FPIN_PORT_CLEARED	= 0x3,
645 	IBMVFC_AE_FPIN_PORT_DEGRADED	= 0x4,
646 };
647 
648 struct ibmvfc_async_crq {
649 	volatile u8 valid;
650 	u8 link_state;
651 	u8 fpin_status;
652 	u8 pad;
653 	__be32 pad2;
654 	volatile __be64 event;
655 	volatile __be64 scsi_id;
656 	volatile __be64 wwpn;
657 	volatile __be64 node_name;
658 	__be64 reserved;
659 } __packed __aligned(8);
660 
661 struct ibmvfc_async_crq_queue {
662 	struct ibmvfc_async_crq *msgs;
663 	int size, cur;
664 	dma_addr_t msg_token;
665 };
666 
667 union ibmvfc_iu {
668 	struct ibmvfc_mad_common mad_common;
669 	struct ibmvfc_npiv_login_mad npiv_login;
670 	struct ibmvfc_npiv_logout_mad npiv_logout;
671 	struct ibmvfc_discover_targets discover_targets;
672 	struct ibmvfc_port_login plogi;
673 	struct ibmvfc_process_login prli;
674 	struct ibmvfc_move_login move_login;
675 	struct ibmvfc_query_tgt query_tgt;
676 	struct ibmvfc_implicit_logout implicit_logout;
677 	struct ibmvfc_tmf tmf;
678 	struct ibmvfc_cmd cmd;
679 	struct ibmvfc_passthru_mad passthru;
680 	struct ibmvfc_channel_enquiry channel_enquiry;
681 	struct ibmvfc_channel_setup_mad channel_setup;
682 	struct ibmvfc_connection_info connection_info;
683 } __packed __aligned(8);
684 
685 enum ibmvfc_target_action {
686 	IBMVFC_TGT_ACTION_NONE = 0,
687 	IBMVFC_TGT_ACTION_INIT,
688 	IBMVFC_TGT_ACTION_INIT_WAIT,
689 	IBMVFC_TGT_ACTION_LOGOUT_RPORT,
690 	IBMVFC_TGT_ACTION_LOGOUT_RPORT_WAIT,
691 	IBMVFC_TGT_ACTION_DEL_RPORT,
692 	IBMVFC_TGT_ACTION_DELETED_RPORT,
693 	IBMVFC_TGT_ACTION_DEL_AND_LOGOUT_RPORT,
694 	IBMVFC_TGT_ACTION_LOGOUT_DELETED_RPORT,
695 };
696 
697 struct ibmvfc_target {
698 	struct list_head queue;
699 	struct ibmvfc_host *vhost;
700 	u64 scsi_id;
701 	u64 wwpn;
702 	u64 old_scsi_id;
703 	struct fc_rport *rport;
704 	int target_id;
705 	enum ibmvfc_target_action action;
706 	int need_login;
707 	int add_rport;
708 	int init_retries;
709 	int logo_rcvd;
710 	u32 cancel_key;
711 	struct ibmvfc_service_parms service_parms;
712 	struct ibmvfc_service_parms service_parms_change;
713 	struct fc_rport_identifiers ids;
714 	void (*job_step) (struct ibmvfc_target *);
715 	struct timer_list timer;
716 	struct kref kref;
717 };
718 
719 /* a unit of work for the hosting partition */
720 struct ibmvfc_event {
721 	struct list_head queue;
722 	struct ibmvfc_host *vhost;
723 	struct ibmvfc_target *tgt;
724 	struct scsi_cmnd *cmnd;
725 	atomic_t free;
726 	union ibmvfc_iu *xfer_iu;
727 	void (*done) (struct ibmvfc_event *);
728 	struct ibmvfc_crq crq;
729 	union ibmvfc_iu iu;
730 	union ibmvfc_iu *sync_iu;
731 	struct srp_direct_buf *ext_list;
732 	dma_addr_t ext_list_token;
733 	struct completion comp;
734 	struct completion *eh_comp;
735 	struct timer_list timer;
736 };
737 
738 /* a pool of event structs for use */
739 struct ibmvfc_event_pool {
740 	struct ibmvfc_event *events;
741 	u32 size;
742 	union ibmvfc_iu *iu_storage;
743 	dma_addr_t iu_token;
744 };
745 
746 enum ibmvfc_host_action {
747 	IBMVFC_HOST_ACTION_NONE = 0,
748 	IBMVFC_HOST_ACTION_RESET,
749 	IBMVFC_HOST_ACTION_REENABLE,
750 	IBMVFC_HOST_ACTION_LOGO,
751 	IBMVFC_HOST_ACTION_LOGO_WAIT,
752 	IBMVFC_HOST_ACTION_INIT,
753 	IBMVFC_HOST_ACTION_INIT_WAIT,
754 	IBMVFC_HOST_ACTION_QUERY,
755 	IBMVFC_HOST_ACTION_QUERY_TGTS,
756 	IBMVFC_HOST_ACTION_TGT_DEL,
757 	IBMVFC_HOST_ACTION_ALLOC_TGTS,
758 	IBMVFC_HOST_ACTION_TGT_INIT,
759 	IBMVFC_HOST_ACTION_TGT_DEL_FAILED,
760 };
761 
762 enum ibmvfc_host_state {
763 	IBMVFC_NO_CRQ = 0,
764 	IBMVFC_INITIALIZING,
765 	IBMVFC_ACTIVE,
766 	IBMVFC_HALTED,
767 	IBMVFC_LINK_DOWN,
768 	IBMVFC_LINK_DEAD,
769 	IBMVFC_HOST_OFFLINE,
770 };
771 
772 struct ibmvfc_host {
773 	char name[8];
774 	struct list_head queue;
775 	struct Scsi_Host *host;
776 	enum ibmvfc_host_state state;
777 	enum ibmvfc_host_action action;
778 #define IBMVFC_NUM_TRACE_INDEX_BITS		8
779 #define IBMVFC_NUM_TRACE_ENTRIES		(1 << IBMVFC_NUM_TRACE_INDEX_BITS)
780 #define IBMVFC_TRACE_SIZE	(sizeof(struct ibmvfc_trace_entry) * IBMVFC_NUM_TRACE_ENTRIES)
781 	struct ibmvfc_trace_entry *trace;
782 	u32 trace_index:IBMVFC_NUM_TRACE_INDEX_BITS;
783 	int num_targets;
784 	struct list_head targets;
785 	struct list_head sent;
786 	struct list_head free;
787 	struct device *dev;
788 	struct ibmvfc_event_pool pool;
789 	struct dma_pool *sg_pool;
790 	mempool_t *tgt_pool;
791 	struct ibmvfc_crq_queue crq;
792 	struct ibmvfc_async_crq_queue async_crq;
793 	struct ibmvfc_npiv_login login_info;
794 	union ibmvfc_npiv_login_data *login_buf;
795 	dma_addr_t login_buf_dma;
796 	int disc_buf_sz;
797 	int log_level;
798 	struct ibmvfc_discover_targets_entry *disc_buf;
799 	struct mutex passthru_mutex;
800 	int task_set;
801 	int init_retries;
802 	int discovery_threads;
803 	int abort_threads;
804 	int client_migrated;
805 	int reinit;
806 	int delay_init;
807 	int scan_complete;
808 	int logged_in;
809 	int aborting_passthru;
810 	int events_to_log;
811 #define IBMVFC_AE_LINKUP	0x0001
812 #define IBMVFC_AE_LINKDOWN	0x0002
813 #define IBMVFC_AE_RSCN		0x0004
814 	dma_addr_t disc_buf_dma;
815 	unsigned int partition_number;
816 	char partition_name[97];
817 	void (*job_step) (struct ibmvfc_host *);
818 	struct task_struct *work_thread;
819 	struct tasklet_struct tasklet;
820 	struct work_struct rport_add_work_q;
821 	wait_queue_head_t init_wait_q;
822 	wait_queue_head_t work_wait_q;
823 };
824 
825 #define DBG_CMD(CMD) do { if (ibmvfc_debug) CMD; } while (0)
826 
827 #define tgt_dbg(t, fmt, ...)			\
828 	DBG_CMD(dev_info((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__))
829 
830 #define tgt_info(t, fmt, ...)		\
831 	dev_info((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__)
832 
833 #define tgt_err(t, fmt, ...)		\
834 	dev_err((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__)
835 
836 #define tgt_log(t, level, fmt, ...) \
837 	do { \
838 		if ((t)->vhost->log_level >= level) \
839 			tgt_err(t, fmt, ##__VA_ARGS__); \
840 	} while (0)
841 
842 #define ibmvfc_dbg(vhost, ...) \
843 	DBG_CMD(dev_info((vhost)->dev, ##__VA_ARGS__))
844 
845 #define ibmvfc_log(vhost, level, ...) \
846 	do { \
847 		if ((vhost)->log_level >= level) \
848 			dev_err((vhost)->dev, ##__VA_ARGS__); \
849 	} while (0)
850 
851 #define ENTER DBG_CMD(printk(KERN_INFO IBMVFC_NAME": Entering %s\n", __func__))
852 #define LEAVE DBG_CMD(printk(KERN_INFO IBMVFC_NAME": Leaving %s\n", __func__))
853 
854 #ifdef CONFIG_SCSI_IBMVFC_TRACE
855 #define ibmvfc_create_trace_file(kobj, attr) sysfs_create_bin_file(kobj, attr)
856 #define ibmvfc_remove_trace_file(kobj, attr) sysfs_remove_bin_file(kobj, attr)
857 #else
858 #define ibmvfc_create_trace_file(kobj, attr) 0
859 #define ibmvfc_remove_trace_file(kobj, attr) do { } while (0)
860 #endif
861 
862 #endif
863