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