blob: 8fae03215a85d2d26920146617cbfc68c8a845ed [file] [log] [blame]
Brian King072b91f2008-07-01 13:14:30 -05001/*
2 * ibmvfc.h -- driver for IBM Power Virtual Fibre Channel Adapter
3 *
4 * Written By: Brian King <brking@linux.vnet.ibm.com>, IBM Corporation
5 *
6 * Copyright (C) IBM Corporation, 2008
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24#ifndef _IBMVFC_H
25#define _IBMVFC_H
26
27#include <linux/list.h>
28#include <linux/types.h>
29#include "viosrp.h"
30
31#define IBMVFC_NAME "ibmvfc"
Brian King88346782013-04-12 08:25:19 -050032#define IBMVFC_DRIVER_VERSION "1.0.11"
33#define IBMVFC_DRIVER_DATE "(April 12, 2013)"
Brian King072b91f2008-07-01 13:14:30 -050034
Brian King14ae6fa2009-02-04 16:13:13 -060035#define IBMVFC_DEFAULT_TIMEOUT 60
Brian King10501e12009-03-20 15:44:39 -050036#define IBMVFC_ADISC_CANCEL_TIMEOUT 45
37#define IBMVFC_ADISC_TIMEOUT 15
38#define IBMVFC_ADISC_PLUS_CANCEL_TIMEOUT \
39 (IBMVFC_ADISC_TIMEOUT + IBMVFC_ADISC_CANCEL_TIMEOUT)
Brian Kingd2131b32008-12-18 09:26:51 -060040#define IBMVFC_INIT_TIMEOUT 120
Brian Kingd2fab5c2010-08-05 16:38:34 -050041#define IBMVFC_ABORT_TIMEOUT 8
Brian Kingdaa142d2010-04-20 14:21:35 -050042#define IBMVFC_ABORT_WAIT_TIMEOUT 40
Brian King072b91f2008-07-01 13:14:30 -050043#define IBMVFC_MAX_REQUESTS_DEFAULT 100
44
45#define IBMVFC_DEBUG 0
46#define IBMVFC_MAX_TARGETS 1024
47#define IBMVFC_MAX_LUN 0xffffffff
48#define IBMVFC_MAX_SECTORS 0xffffu
49#define IBMVFC_MAX_DISC_THREADS 4
50#define IBMVFC_TGT_MEMPOOL_SZ 64
51#define IBMVFC_MAX_CMDS_PER_LUN 64
Brian King1c41fa822008-12-03 11:02:54 -060052#define IBMVFC_MAX_HOST_INIT_RETRIES 6
53#define IBMVFC_MAX_TGT_INIT_RETRIES 3
Brian King072b91f2008-07-01 13:14:30 -050054#define IBMVFC_DEV_LOSS_TMO (5 * 60)
55#define IBMVFC_DEFAULT_LOG_LEVEL 2
56#define IBMVFC_MAX_CDB_LEN 16
57
58/*
59 * Ensure we have resources for ERP and initialization:
60 * 1 for ERP
61 * 1 for initialization
Brian King79111d02009-05-28 16:17:29 -050062 * 1 for NPIV Logout
Brian Kingd31429e2009-10-19 15:07:54 -050063 * 2 for BSG passthru
Brian King10501e12009-03-20 15:44:39 -050064 * 2 for each discovery thread
Brian King072b91f2008-07-01 13:14:30 -050065 */
Brian Kingd31429e2009-10-19 15:07:54 -050066#define IBMVFC_NUM_INTERNAL_REQ (1 + 1 + 1 + 2 + (disc_threads * 2))
Brian King072b91f2008-07-01 13:14:30 -050067
68#define IBMVFC_MAD_SUCCESS 0x00
69#define IBMVFC_MAD_NOT_SUPPORTED 0xF1
70#define IBMVFC_MAD_FAILED 0xF7
71#define IBMVFC_MAD_DRIVER_FAILED 0xEE
72#define IBMVFC_MAD_CRQ_ERROR 0xEF
73
74enum ibmvfc_crq_valid {
75 IBMVFC_CRQ_CMD_RSP = 0x80,
76 IBMVFC_CRQ_INIT_RSP = 0xC0,
77 IBMVFC_CRQ_XPORT_EVENT = 0xFF,
78};
79
80enum ibmvfc_crq_format {
81 IBMVFC_CRQ_INIT = 0x01,
82 IBMVFC_CRQ_INIT_COMPLETE = 0x02,
83 IBMVFC_PARTITION_MIGRATED = 0x06,
84};
85
86enum ibmvfc_cmd_status_flags {
87 IBMVFC_FABRIC_MAPPED = 0x0001,
88 IBMVFC_VIOS_FAILURE = 0x0002,
89 IBMVFC_FC_FAILURE = 0x0004,
90 IBMVFC_FC_SCSI_ERROR = 0x0008,
91 IBMVFC_HW_EVENT_LOGGED = 0x0010,
92 IBMVFC_VIOS_LOGGED = 0x0020,
93};
94
95enum ibmvfc_fabric_mapped_errors {
96 IBMVFC_UNABLE_TO_ESTABLISH = 0x0001,
97 IBMVFC_XPORT_FAULT = 0x0002,
98 IBMVFC_CMD_TIMEOUT = 0x0003,
99 IBMVFC_ENETDOWN = 0x0004,
100 IBMVFC_HW_FAILURE = 0x0005,
101 IBMVFC_LINK_DOWN_ERR = 0x0006,
102 IBMVFC_LINK_DEAD_ERR = 0x0007,
103 IBMVFC_UNABLE_TO_REGISTER = 0x0008,
104 IBMVFC_XPORT_BUSY = 0x000A,
105 IBMVFC_XPORT_DEAD = 0x000B,
106 IBMVFC_CONFIG_ERROR = 0x000C,
107 IBMVFC_NAME_SERVER_FAIL = 0x000D,
108 IBMVFC_LINK_HALTED = 0x000E,
109 IBMVFC_XPORT_GENERAL = 0x8000,
110};
111
112enum ibmvfc_vios_errors {
113 IBMVFC_CRQ_FAILURE = 0x0001,
114 IBMVFC_SW_FAILURE = 0x0002,
115 IBMVFC_INVALID_PARAMETER = 0x0003,
116 IBMVFC_MISSING_PARAMETER = 0x0004,
117 IBMVFC_HOST_IO_BUS = 0x0005,
118 IBMVFC_TRANS_CANCELLED = 0x0006,
119 IBMVFC_TRANS_CANCELLED_IMPLICIT = 0x0007,
120 IBMVFC_INSUFFICIENT_RESOURCE = 0x0008,
Brian King646d3852008-11-14 13:33:53 -0600121 IBMVFC_PLOGI_REQUIRED = 0x0010,
Brian King072b91f2008-07-01 13:14:30 -0500122 IBMVFC_COMMAND_FAILED = 0x8000,
123};
124
125enum ibmvfc_mad_types {
126 IBMVFC_NPIV_LOGIN = 0x0001,
127 IBMVFC_DISC_TARGETS = 0x0002,
128 IBMVFC_PORT_LOGIN = 0x0004,
129 IBMVFC_PROCESS_LOGIN = 0x0008,
130 IBMVFC_QUERY_TARGET = 0x0010,
131 IBMVFC_IMPLICIT_LOGOUT = 0x0040,
Brian King989b8542008-07-22 08:31:47 -0500132 IBMVFC_PASSTHRU = 0x0200,
Brian King072b91f2008-07-01 13:14:30 -0500133 IBMVFC_TMF_MAD = 0x0100,
Brian King79111d02009-05-28 16:17:29 -0500134 IBMVFC_NPIV_LOGOUT = 0x0800,
Brian King072b91f2008-07-01 13:14:30 -0500135};
136
137struct ibmvfc_mad_common {
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500138 __be32 version;
139 __be32 reserved;
140 __be32 opcode;
141 __be16 status;
142 __be16 length;
143 __be64 tag;
Brian King072b91f2008-07-01 13:14:30 -0500144}__attribute__((packed, aligned (8)));
145
146struct ibmvfc_npiv_login_mad {
147 struct ibmvfc_mad_common common;
148 struct srp_direct_buf buffer;
149}__attribute__((packed, aligned (8)));
150
Brian King79111d02009-05-28 16:17:29 -0500151struct ibmvfc_npiv_logout_mad {
152 struct ibmvfc_mad_common common;
153}__attribute__((packed, aligned (8)));
154
Brian King072b91f2008-07-01 13:14:30 -0500155#define IBMVFC_MAX_NAME 256
156
157struct ibmvfc_npiv_login {
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500158 __be32 ostype;
Brian King072b91f2008-07-01 13:14:30 -0500159#define IBMVFC_OS_LINUX 0x02
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500160 __be32 pad;
161 __be64 max_dma_len;
162 __be32 max_payload;
163 __be32 max_response;
164 __be32 partition_num;
165 __be32 vfc_frame_version;
166 __be16 fcp_version;
167 __be16 flags;
Brian King072b91f2008-07-01 13:14:30 -0500168#define IBMVFC_CLIENT_MIGRATED 0x01
169#define IBMVFC_FLUSH_ON_HALT 0x02
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500170 __be32 max_cmds;
171 __be64 capabilities;
Brian King072b91f2008-07-01 13:14:30 -0500172#define IBMVFC_CAN_MIGRATE 0x01
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500173 __be64 node_name;
Brian King072b91f2008-07-01 13:14:30 -0500174 struct srp_direct_buf async;
175 u8 partition_name[IBMVFC_MAX_NAME];
176 u8 device_name[IBMVFC_MAX_NAME];
177 u8 drc_name[IBMVFC_MAX_NAME];
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500178 __be64 reserved2[2];
Brian King072b91f2008-07-01 13:14:30 -0500179}__attribute__((packed, aligned (8)));
180
181struct ibmvfc_common_svc_parms {
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500182 __be16 fcph_version;
183 __be16 b2b_credit;
184 __be16 features;
185 __be16 bb_rcv_sz; /* upper nibble is BB_SC_N */
186 __be32 ratov;
187 __be32 edtov;
Brian King072b91f2008-07-01 13:14:30 -0500188}__attribute__((packed, aligned (4)));
189
190struct ibmvfc_service_parms {
191 struct ibmvfc_common_svc_parms common;
192 u8 port_name[8];
193 u8 node_name[8];
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500194 __be32 class1_parms[4];
195 __be32 class2_parms[4];
196 __be32 class3_parms[4];
197 __be32 obsolete[4];
198 __be32 vendor_version[4];
199 __be32 services_avail[2];
200 __be32 ext_len;
201 __be32 reserved[30];
202 __be32 clk_sync_qos[2];
Brian King072b91f2008-07-01 13:14:30 -0500203}__attribute__((packed, aligned (4)));
204
205struct ibmvfc_npiv_login_resp {
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500206 __be32 version;
207 __be16 status;
208 __be16 error;
209 __be32 flags;
Brian King072b91f2008-07-01 13:14:30 -0500210#define IBMVFC_NATIVE_FC 0x01
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500211 __be32 reserved;
212 __be64 capabilities;
Brian King497f9c52009-05-28 16:17:30 -0500213#define IBMVFC_CAN_FLUSH_ON_HALT 0x08
Brian King90f725d2013-04-12 08:25:18 -0500214#define IBMVFC_CAN_SUPPRESS_ABTS 0x10
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500215 __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;
Brian King072b91f2008-07-01 13:14:30 -0500222 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;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500227 __be64 reserved2;
Brian King072b91f2008-07-01 13:14:30 -0500228}__attribute__((packed, aligned (8)));
229
230union ibmvfc_npiv_login_data {
231 struct ibmvfc_npiv_login login;
232 struct ibmvfc_npiv_login_resp resp;
233}__attribute__((packed, aligned (8)));
234
235struct ibmvfc_discover_targets_buf {
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500236 __be32 scsi_id[1];
Brian King072b91f2008-07-01 13:14:30 -0500237#define IBMVFC_DISC_TGT_SCSI_ID_MASK 0x00ffffff
238};
239
240struct ibmvfc_discover_targets {
241 struct ibmvfc_mad_common common;
242 struct srp_direct_buf buffer;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500243 __be32 flags;
244 __be16 status;
245 __be16 error;
246 __be32 bufflen;
247 __be32 num_avail;
248 __be32 num_written;
249 __be64 reserved[2];
Brian King072b91f2008-07-01 13:14:30 -0500250}__attribute__((packed, aligned (8)));
251
252enum ibmvfc_fc_reason {
253 IBMVFC_INVALID_ELS_CMD_CODE = 0x01,
254 IBMVFC_INVALID_VERSION = 0x02,
255 IBMVFC_LOGICAL_ERROR = 0x03,
256 IBMVFC_INVALID_CT_IU_SIZE = 0x04,
257 IBMVFC_LOGICAL_BUSY = 0x05,
258 IBMVFC_PROTOCOL_ERROR = 0x07,
259 IBMVFC_UNABLE_TO_PERFORM_REQ = 0x09,
260 IBMVFC_CMD_NOT_SUPPORTED = 0x0B,
261 IBMVFC_SERVER_NOT_AVAIL = 0x0D,
262 IBMVFC_CMD_IN_PROGRESS = 0x0E,
263 IBMVFC_VENDOR_SPECIFIC = 0xFF,
264};
265
266enum ibmvfc_fc_type {
267 IBMVFC_FABRIC_REJECT = 0x01,
268 IBMVFC_PORT_REJECT = 0x02,
269 IBMVFC_LS_REJECT = 0x03,
270 IBMVFC_FABRIC_BUSY = 0x04,
271 IBMVFC_PORT_BUSY = 0x05,
272 IBMVFC_BASIC_REJECT = 0x06,
273};
274
275enum ibmvfc_gs_explain {
276 IBMVFC_PORT_NAME_NOT_REG = 0x02,
277};
278
279struct ibmvfc_port_login {
280 struct ibmvfc_mad_common common;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500281 __be64 scsi_id;
282 __be16 reserved;
283 __be16 fc_service_class;
284 __be32 blksz;
285 __be32 hdr_per_blk;
286 __be16 status;
287 __be16 error; /* also fc_reason */
288 __be16 fc_explain;
289 __be16 fc_type;
290 __be32 reserved2;
Brian King072b91f2008-07-01 13:14:30 -0500291 struct ibmvfc_service_parms service_parms;
292 struct ibmvfc_service_parms service_parms_change;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500293 __be64 reserved3[2];
Brian King072b91f2008-07-01 13:14:30 -0500294}__attribute__((packed, aligned (8)));
295
296struct ibmvfc_prli_svc_parms {
297 u8 type;
298#define IBMVFC_SCSI_FCP_TYPE 0x08
299 u8 type_ext;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500300 __be16 flags;
Brian King072b91f2008-07-01 13:14:30 -0500301#define IBMVFC_PRLI_ORIG_PA_VALID 0x8000
302#define IBMVFC_PRLI_RESP_PA_VALID 0x4000
303#define IBMVFC_PRLI_EST_IMG_PAIR 0x2000
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500304 __be32 orig_pa;
305 __be32 resp_pa;
306 __be32 service_parms;
Brian King072b91f2008-07-01 13:14:30 -0500307#define IBMVFC_PRLI_TASK_RETRY 0x00000200
308#define IBMVFC_PRLI_RETRY 0x00000100
309#define IBMVFC_PRLI_DATA_OVERLAY 0x00000040
310#define IBMVFC_PRLI_INITIATOR_FUNC 0x00000020
311#define IBMVFC_PRLI_TARGET_FUNC 0x00000010
312#define IBMVFC_PRLI_READ_FCP_XFER_RDY_DISABLED 0x00000002
313#define IBMVFC_PRLI_WR_FCP_XFER_RDY_DISABLED 0x00000001
314}__attribute__((packed, aligned (4)));
315
316struct ibmvfc_process_login {
317 struct ibmvfc_mad_common common;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500318 __be64 scsi_id;
Brian King072b91f2008-07-01 13:14:30 -0500319 struct ibmvfc_prli_svc_parms parms;
320 u8 reserved[48];
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500321 __be16 status;
322 __be16 error; /* also fc_reason */
323 __be32 reserved2;
324 __be64 reserved3[2];
Brian King072b91f2008-07-01 13:14:30 -0500325}__attribute__((packed, aligned (8)));
326
327struct ibmvfc_query_tgt {
328 struct ibmvfc_mad_common common;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500329 __be64 wwpn;
330 __be64 scsi_id;
331 __be16 status;
332 __be16 error;
333 __be16 fc_explain;
334 __be16 fc_type;
335 __be64 reserved[2];
Brian King072b91f2008-07-01 13:14:30 -0500336}__attribute__((packed, aligned (8)));
337
338struct ibmvfc_implicit_logout {
339 struct ibmvfc_mad_common common;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500340 __be64 old_scsi_id;
341 __be64 reserved[2];
Brian King072b91f2008-07-01 13:14:30 -0500342}__attribute__((packed, aligned (8)));
343
344struct ibmvfc_tmf {
345 struct ibmvfc_mad_common common;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500346 __be64 scsi_id;
Brian King072b91f2008-07-01 13:14:30 -0500347 struct scsi_lun lun;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500348 __be32 flags;
Brian King072b91f2008-07-01 13:14:30 -0500349#define IBMVFC_TMF_ABORT_TASK 0x02
350#define IBMVFC_TMF_ABORT_TASK_SET 0x04
351#define IBMVFC_TMF_LUN_RESET 0x10
352#define IBMVFC_TMF_TGT_RESET 0x20
353#define IBMVFC_TMF_LUA_VALID 0x40
Brian King90f725d2013-04-12 08:25:18 -0500354#define IBMVFC_TMF_SUPPRESS_ABTS 0x80
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500355 __be32 cancel_key;
356 __be32 my_cancel_key;
357 __be32 pad;
358 __be64 reserved[2];
Brian King072b91f2008-07-01 13:14:30 -0500359}__attribute__((packed, aligned (8)));
360
361enum ibmvfc_fcp_rsp_info_codes {
362 RSP_NO_FAILURE = 0x00,
363 RSP_TMF_REJECTED = 0x04,
364 RSP_TMF_FAILED = 0x05,
365 RSP_TMF_INVALID_LUN = 0x09,
366};
367
368struct ibmvfc_fcp_rsp_info {
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500369 __be16 reserved;
Brian King072b91f2008-07-01 13:14:30 -0500370 u8 rsp_code;
371 u8 reserved2[4];
372}__attribute__((packed, aligned (2)));
373
374enum ibmvfc_fcp_rsp_flags {
375 FCP_BIDI_RSP = 0x80,
376 FCP_BIDI_READ_RESID_UNDER = 0x40,
377 FCP_BIDI_READ_RESID_OVER = 0x20,
378 FCP_CONF_REQ = 0x10,
379 FCP_RESID_UNDER = 0x08,
380 FCP_RESID_OVER = 0x04,
381 FCP_SNS_LEN_VALID = 0x02,
382 FCP_RSP_LEN_VALID = 0x01,
383};
384
385union ibmvfc_fcp_rsp_data {
386 struct ibmvfc_fcp_rsp_info info;
387 u8 sense[SCSI_SENSE_BUFFERSIZE + sizeof(struct ibmvfc_fcp_rsp_info)];
388}__attribute__((packed, aligned (8)));
389
390struct ibmvfc_fcp_rsp {
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500391 __be64 reserved;
392 __be16 retry_delay_timer;
Brian King072b91f2008-07-01 13:14:30 -0500393 u8 flags;
394 u8 scsi_status;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500395 __be32 fcp_resid;
396 __be32 fcp_sense_len;
397 __be32 fcp_rsp_len;
Brian King072b91f2008-07-01 13:14:30 -0500398 union ibmvfc_fcp_rsp_data data;
399}__attribute__((packed, aligned (8)));
400
401enum ibmvfc_cmd_flags {
402 IBMVFC_SCATTERLIST = 0x0001,
403 IBMVFC_NO_MEM_DESC = 0x0002,
404 IBMVFC_READ = 0x0004,
405 IBMVFC_WRITE = 0x0008,
406 IBMVFC_TMF = 0x0080,
407 IBMVFC_CLASS_3_ERR = 0x0100,
408};
409
410enum ibmvfc_fc_task_attr {
411 IBMVFC_SIMPLE_TASK = 0x00,
412 IBMVFC_HEAD_OF_QUEUE = 0x01,
413 IBMVFC_ORDERED_TASK = 0x02,
414 IBMVFC_ACA_TASK = 0x04,
415};
416
417enum ibmvfc_fc_tmf_flags {
418 IBMVFC_ABORT_TASK_SET = 0x02,
419 IBMVFC_LUN_RESET = 0x10,
420 IBMVFC_TARGET_RESET = 0x20,
421};
422
423struct ibmvfc_fcp_cmd_iu {
424 struct scsi_lun lun;
425 u8 crn;
426 u8 pri_task_attr;
427 u8 tmf_flags;
428 u8 add_cdb_len;
429#define IBMVFC_RDDATA 0x02
430#define IBMVFC_WRDATA 0x01
431 u8 cdb[IBMVFC_MAX_CDB_LEN];
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500432 __be32 xfer_len;
Brian King072b91f2008-07-01 13:14:30 -0500433}__attribute__((packed, aligned (4)));
434
435struct ibmvfc_cmd {
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500436 __be64 task_tag;
437 __be32 frame_type;
438 __be32 payload_len;
439 __be32 resp_len;
440 __be32 adapter_resid;
441 __be16 status;
442 __be16 error;
443 __be16 flags;
444 __be16 response_flags;
Brian King072b91f2008-07-01 13:14:30 -0500445#define IBMVFC_ADAPTER_RESID_VALID 0x01
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500446 __be32 cancel_key;
447 __be32 exchange_id;
Brian King072b91f2008-07-01 13:14:30 -0500448 struct srp_direct_buf ext_func;
449 struct srp_direct_buf ioba;
450 struct srp_direct_buf resp;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500451 __be64 correlation;
452 __be64 tgt_scsi_id;
453 __be64 tag;
454 __be64 reserved3[2];
Brian King072b91f2008-07-01 13:14:30 -0500455 struct ibmvfc_fcp_cmd_iu iu;
456 struct ibmvfc_fcp_rsp rsp;
457}__attribute__((packed, aligned (8)));
458
Brian King989b8542008-07-22 08:31:47 -0500459struct ibmvfc_passthru_fc_iu {
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500460 __be32 payload[7];
Brian King989b8542008-07-22 08:31:47 -0500461#define IBMVFC_ADISC 0x52000000
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500462 __be32 response[7];
Brian King989b8542008-07-22 08:31:47 -0500463};
464
465struct ibmvfc_passthru_iu {
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500466 __be64 task_tag;
467 __be32 cmd_len;
468 __be32 rsp_len;
469 __be16 status;
470 __be16 error;
471 __be32 flags;
Brian King989b8542008-07-22 08:31:47 -0500472#define IBMVFC_FC_ELS 0x01
Brian Kingd31429e2009-10-19 15:07:54 -0500473#define IBMVFC_FC_CT_IU 0x02
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500474 __be32 cancel_key;
Brian Kingd31429e2009-10-19 15:07:54 -0500475#define IBMVFC_PASSTHRU_CANCEL_KEY 0x80000000
476#define IBMVFC_INTERNAL_CANCEL_KEY 0x80000001
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500477 __be32 reserved;
Brian King989b8542008-07-22 08:31:47 -0500478 struct srp_direct_buf cmd;
479 struct srp_direct_buf rsp;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500480 __be64 correlation;
481 __be64 scsi_id;
482 __be64 tag;
483 __be64 reserved2[2];
Brian King989b8542008-07-22 08:31:47 -0500484}__attribute__((packed, aligned (8)));
485
486struct ibmvfc_passthru_mad {
487 struct ibmvfc_mad_common common;
488 struct srp_direct_buf cmd_ioba;
489 struct ibmvfc_passthru_iu iu;
490 struct ibmvfc_passthru_fc_iu fc_iu;
491}__attribute__((packed, aligned (8)));
492
Brian King072b91f2008-07-01 13:14:30 -0500493struct ibmvfc_trace_start_entry {
494 u32 xfer_len;
495}__attribute__((packed));
496
497struct ibmvfc_trace_end_entry {
498 u16 status;
499 u16 error;
500 u8 fcp_rsp_flags;
501 u8 rsp_code;
502 u8 scsi_status;
503 u8 reserved;
504}__attribute__((packed));
505
506struct ibmvfc_trace_entry {
507 struct ibmvfc_event *evt;
508 u32 time;
509 u32 scsi_id;
510 u32 lun;
511 u8 fmt;
512 u8 op_code;
513 u8 tmf_flags;
514 u8 type;
515#define IBMVFC_TRC_START 0x00
516#define IBMVFC_TRC_END 0xff
517 union {
518 struct ibmvfc_trace_start_entry start;
519 struct ibmvfc_trace_end_entry end;
520 } u;
521}__attribute__((packed, aligned (8)));
522
523enum ibmvfc_crq_formats {
524 IBMVFC_CMD_FORMAT = 0x01,
525 IBMVFC_ASYNC_EVENT = 0x02,
526 IBMVFC_MAD_FORMAT = 0x04,
527};
528
529enum ibmvfc_async_event {
530 IBMVFC_AE_ELS_PLOGI = 0x0001,
531 IBMVFC_AE_ELS_LOGO = 0x0002,
532 IBMVFC_AE_ELS_PRLO = 0x0004,
533 IBMVFC_AE_SCN_NPORT = 0x0008,
534 IBMVFC_AE_SCN_GROUP = 0x0010,
535 IBMVFC_AE_SCN_DOMAIN = 0x0020,
536 IBMVFC_AE_SCN_FABRIC = 0x0040,
537 IBMVFC_AE_LINK_UP = 0x0080,
538 IBMVFC_AE_LINK_DOWN = 0x0100,
539 IBMVFC_AE_LINK_DEAD = 0x0200,
540 IBMVFC_AE_HALT = 0x0400,
541 IBMVFC_AE_RESUME = 0x0800,
542 IBMVFC_AE_ADAPTER_FAILED = 0x1000,
543};
544
Brian Kingd99e5f42010-09-09 16:20:42 -0500545struct ibmvfc_async_desc {
Brian Kingd99e5f42010-09-09 16:20:42 -0500546 const char *desc;
Robert Jennings402c6ee2010-12-09 14:03:59 -0600547 enum ibmvfc_async_event ae;
Brian Kingd99e5f42010-09-09 16:20:42 -0500548 int log_level;
549};
550
Brian King072b91f2008-07-01 13:14:30 -0500551struct ibmvfc_crq {
Brian King5919ce22008-11-14 13:33:52 -0600552 volatile u8 valid;
553 volatile u8 format;
Brian King072b91f2008-07-01 13:14:30 -0500554 u8 reserved[6];
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500555 volatile __be64 ioba;
Brian King072b91f2008-07-01 13:14:30 -0500556}__attribute__((packed, aligned (8)));
557
558struct ibmvfc_crq_queue {
559 struct ibmvfc_crq *msgs;
560 int size, cur;
561 dma_addr_t msg_token;
562};
563
Brian King497f9c52009-05-28 16:17:30 -0500564enum ibmvfc_ae_link_state {
565 IBMVFC_AE_LS_LINK_UP = 0x01,
566 IBMVFC_AE_LS_LINK_BOUNCED = 0x02,
567 IBMVFC_AE_LS_LINK_DOWN = 0x04,
568 IBMVFC_AE_LS_LINK_DEAD = 0x08,
569};
570
Brian King072b91f2008-07-01 13:14:30 -0500571struct ibmvfc_async_crq {
Brian King5919ce22008-11-14 13:33:52 -0600572 volatile u8 valid;
Brian King497f9c52009-05-28 16:17:30 -0500573 u8 link_state;
574 u8 pad[2];
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500575 __be32 pad2;
576 volatile __be64 event;
577 volatile __be64 scsi_id;
578 volatile __be64 wwpn;
579 volatile __be64 node_name;
580 __be64 reserved;
Brian King072b91f2008-07-01 13:14:30 -0500581}__attribute__((packed, aligned (8)));
582
583struct ibmvfc_async_crq_queue {
584 struct ibmvfc_async_crq *msgs;
585 int size, cur;
586 dma_addr_t msg_token;
587};
588
589union ibmvfc_iu {
590 struct ibmvfc_mad_common mad_common;
591 struct ibmvfc_npiv_login_mad npiv_login;
Brian King79111d02009-05-28 16:17:29 -0500592 struct ibmvfc_npiv_logout_mad npiv_logout;
Brian King072b91f2008-07-01 13:14:30 -0500593 struct ibmvfc_discover_targets discover_targets;
594 struct ibmvfc_port_login plogi;
595 struct ibmvfc_process_login prli;
596 struct ibmvfc_query_tgt query_tgt;
597 struct ibmvfc_implicit_logout implicit_logout;
598 struct ibmvfc_tmf tmf;
599 struct ibmvfc_cmd cmd;
Brian King989b8542008-07-22 08:31:47 -0500600 struct ibmvfc_passthru_mad passthru;
Brian King072b91f2008-07-01 13:14:30 -0500601}__attribute__((packed, aligned (8)));
602
603enum ibmvfc_target_action {
604 IBMVFC_TGT_ACTION_NONE = 0,
605 IBMVFC_TGT_ACTION_INIT,
606 IBMVFC_TGT_ACTION_INIT_WAIT,
Brian King072b91f2008-07-01 13:14:30 -0500607 IBMVFC_TGT_ACTION_DEL_RPORT,
Brian Kingd5da3042010-08-05 16:38:31 -0500608 IBMVFC_TGT_ACTION_DELETED_RPORT,
Brian King072b91f2008-07-01 13:14:30 -0500609};
610
611struct ibmvfc_target {
612 struct list_head queue;
613 struct ibmvfc_host *vhost;
614 u64 scsi_id;
615 u64 new_scsi_id;
616 struct fc_rport *rport;
617 int target_id;
618 enum ibmvfc_target_action action;
619 int need_login;
Brian King43c8da92009-05-28 16:17:28 -0500620 int add_rport;
Brian King072b91f2008-07-01 13:14:30 -0500621 int init_retries;
Brian King017b2ae2009-06-18 09:06:55 -0500622 int logo_rcvd;
Brian King10501e12009-03-20 15:44:39 -0500623 u32 cancel_key;
Brian King072b91f2008-07-01 13:14:30 -0500624 struct ibmvfc_service_parms service_parms;
625 struct ibmvfc_service_parms service_parms_change;
626 struct fc_rport_identifiers ids;
627 void (*job_step) (struct ibmvfc_target *);
Brian King10501e12009-03-20 15:44:39 -0500628 struct timer_list timer;
Brian King072b91f2008-07-01 13:14:30 -0500629 struct kref kref;
630};
631
632/* a unit of work for the hosting partition */
633struct ibmvfc_event {
634 struct list_head queue;
635 struct ibmvfc_host *vhost;
636 struct ibmvfc_target *tgt;
637 struct scsi_cmnd *cmnd;
638 atomic_t free;
639 union ibmvfc_iu *xfer_iu;
640 void (*done) (struct ibmvfc_event *);
641 struct ibmvfc_crq crq;
642 union ibmvfc_iu iu;
643 union ibmvfc_iu *sync_iu;
644 struct srp_direct_buf *ext_list;
645 dma_addr_t ext_list_token;
646 struct completion comp;
Brian Kingad8dcff2008-10-29 08:46:41 -0500647 struct completion *eh_comp;
Brian King072b91f2008-07-01 13:14:30 -0500648 struct timer_list timer;
649};
650
651/* a pool of event structs for use */
652struct ibmvfc_event_pool {
653 struct ibmvfc_event *events;
654 u32 size;
655 union ibmvfc_iu *iu_storage;
656 dma_addr_t iu_token;
657};
658
659enum ibmvfc_host_action {
660 IBMVFC_HOST_ACTION_NONE = 0,
Brian King73ee5d82010-06-17 13:55:13 -0500661 IBMVFC_HOST_ACTION_RESET,
662 IBMVFC_HOST_ACTION_REENABLE,
Brian King79111d02009-05-28 16:17:29 -0500663 IBMVFC_HOST_ACTION_LOGO,
664 IBMVFC_HOST_ACTION_LOGO_WAIT,
Brian King072b91f2008-07-01 13:14:30 -0500665 IBMVFC_HOST_ACTION_INIT,
666 IBMVFC_HOST_ACTION_INIT_WAIT,
667 IBMVFC_HOST_ACTION_QUERY,
668 IBMVFC_HOST_ACTION_QUERY_TGTS,
669 IBMVFC_HOST_ACTION_TGT_DEL,
670 IBMVFC_HOST_ACTION_ALLOC_TGTS,
671 IBMVFC_HOST_ACTION_TGT_INIT,
Brian King10e79492008-10-29 08:46:45 -0500672 IBMVFC_HOST_ACTION_TGT_DEL_FAILED,
Brian King072b91f2008-07-01 13:14:30 -0500673};
674
675enum ibmvfc_host_state {
676 IBMVFC_NO_CRQ = 0,
677 IBMVFC_INITIALIZING,
678 IBMVFC_ACTIVE,
679 IBMVFC_HALTED,
680 IBMVFC_LINK_DOWN,
681 IBMVFC_LINK_DEAD,
682 IBMVFC_HOST_OFFLINE,
683};
684
685struct ibmvfc_host {
686 char name[8];
687 struct list_head queue;
688 struct Scsi_Host *host;
689 enum ibmvfc_host_state state;
690 enum ibmvfc_host_action action;
691#define IBMVFC_NUM_TRACE_INDEX_BITS 8
692#define IBMVFC_NUM_TRACE_ENTRIES (1 << IBMVFC_NUM_TRACE_INDEX_BITS)
693#define IBMVFC_TRACE_SIZE (sizeof(struct ibmvfc_trace_entry) * IBMVFC_NUM_TRACE_ENTRIES)
694 struct ibmvfc_trace_entry *trace;
695 u32 trace_index:IBMVFC_NUM_TRACE_INDEX_BITS;
696 int num_targets;
697 struct list_head targets;
698 struct list_head sent;
699 struct list_head free;
700 struct device *dev;
701 struct ibmvfc_event_pool pool;
702 struct dma_pool *sg_pool;
703 mempool_t *tgt_pool;
704 struct ibmvfc_crq_queue crq;
705 struct ibmvfc_async_crq_queue async_crq;
706 struct ibmvfc_npiv_login login_info;
707 union ibmvfc_npiv_login_data *login_buf;
708 dma_addr_t login_buf_dma;
709 int disc_buf_sz;
710 int log_level;
711 struct ibmvfc_discover_targets_buf *disc_buf;
Brian Kingd31429e2009-10-19 15:07:54 -0500712 struct mutex passthru_mutex;
Brian King072b91f2008-07-01 13:14:30 -0500713 int task_set;
714 int init_retries;
715 int discovery_threads;
Brian King10501e12009-03-20 15:44:39 -0500716 int abort_threads;
Brian King072b91f2008-07-01 13:14:30 -0500717 int client_migrated;
718 int reinit;
Brian King1c41fa822008-12-03 11:02:54 -0600719 int delay_init;
Brian King43c8da92009-05-28 16:17:28 -0500720 int scan_complete;
Brian King79111d02009-05-28 16:17:29 -0500721 int logged_in;
Brian Kingd31429e2009-10-19 15:07:54 -0500722 int aborting_passthru;
Brian King072b91f2008-07-01 13:14:30 -0500723 int events_to_log;
724#define IBMVFC_AE_LINKUP 0x0001
725#define IBMVFC_AE_LINKDOWN 0x0002
726#define IBMVFC_AE_RSCN 0x0004
727 dma_addr_t disc_buf_dma;
728 unsigned int partition_number;
729 char partition_name[97];
730 void (*job_step) (struct ibmvfc_host *);
731 struct task_struct *work_thread;
Brian King039a0892009-03-20 15:44:35 -0500732 struct tasklet_struct tasklet;
Brian King43c8da92009-05-28 16:17:28 -0500733 struct work_struct rport_add_work_q;
Brian King072b91f2008-07-01 13:14:30 -0500734 wait_queue_head_t init_wait_q;
735 wait_queue_head_t work_wait_q;
736};
737
738#define DBG_CMD(CMD) do { if (ibmvfc_debug) CMD; } while (0)
739
740#define tgt_dbg(t, fmt, ...) \
Stephen Rothwell775a42e2009-01-06 14:59:00 +0000741 DBG_CMD(dev_info((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__))
Brian King072b91f2008-07-01 13:14:30 -0500742
Brian King989b8542008-07-22 08:31:47 -0500743#define tgt_info(t, fmt, ...) \
Stephen Rothwell775a42e2009-01-06 14:59:00 +0000744 dev_info((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__)
Brian King989b8542008-07-22 08:31:47 -0500745
Brian King072b91f2008-07-01 13:14:30 -0500746#define tgt_err(t, fmt, ...) \
Stephen Rothwell775a42e2009-01-06 14:59:00 +0000747 dev_err((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__)
Brian King072b91f2008-07-01 13:14:30 -0500748
Brian King7d0e4622009-05-28 16:17:26 -0500749#define tgt_log(t, level, fmt, ...) \
750 do { \
751 if ((t)->vhost->log_level >= level) \
752 tgt_err(t, fmt, ##__VA_ARGS__); \
753 } while (0)
754
Brian King072b91f2008-07-01 13:14:30 -0500755#define ibmvfc_dbg(vhost, ...) \
756 DBG_CMD(dev_info((vhost)->dev, ##__VA_ARGS__))
757
758#define ibmvfc_log(vhost, level, ...) \
759 do { \
Brian King596891a2008-10-29 08:46:33 -0500760 if ((vhost)->log_level >= level) \
Brian King072b91f2008-07-01 13:14:30 -0500761 dev_err((vhost)->dev, ##__VA_ARGS__); \
762 } while (0)
763
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700764#define ENTER DBG_CMD(printk(KERN_INFO IBMVFC_NAME": Entering %s\n", __func__))
765#define LEAVE DBG_CMD(printk(KERN_INFO IBMVFC_NAME": Leaving %s\n", __func__))
Brian King072b91f2008-07-01 13:14:30 -0500766
767#ifdef CONFIG_SCSI_IBMVFC_TRACE
768#define ibmvfc_create_trace_file(kobj, attr) sysfs_create_bin_file(kobj, attr)
769#define ibmvfc_remove_trace_file(kobj, attr) sysfs_remove_bin_file(kobj, attr)
770#else
771#define ibmvfc_create_trace_file(kobj, attr) 0
772#define ibmvfc_remove_trace_file(kobj, attr) do { } while (0)
773#endif
774
775#endif