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