blob: 459cc288ba1d01abe63c28454bf73c7190bb64a4 [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>
Bryant G. Ly88a678b2016-06-28 17:05:35 -050029#include <scsi/viosrp.h>
Brian King072b91f2008-07-01 13:14:30 -050030
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
Tyrel Datwylera6104b12016-08-03 16:36:53 -050057#define IBMVFC_CLS3_ERROR 0
Brian King072b91f2008-07-01 13:14:30 -050058
59/*
60 * Ensure we have resources for ERP and initialization:
61 * 1 for ERP
62 * 1 for initialization
Brian King79111d02009-05-28 16:17:29 -050063 * 1 for NPIV Logout
Brian Kingd31429e2009-10-19 15:07:54 -050064 * 2 for BSG passthru
Brian King10501e12009-03-20 15:44:39 -050065 * 2 for each discovery thread
Brian King072b91f2008-07-01 13:14:30 -050066 */
Brian Kingd31429e2009-10-19 15:07:54 -050067#define IBMVFC_NUM_INTERNAL_REQ (1 + 1 + 1 + 2 + (disc_threads * 2))
Brian King072b91f2008-07-01 13:14:30 -050068
69#define IBMVFC_MAD_SUCCESS 0x00
70#define IBMVFC_MAD_NOT_SUPPORTED 0xF1
71#define IBMVFC_MAD_FAILED 0xF7
72#define IBMVFC_MAD_DRIVER_FAILED 0xEE
73#define IBMVFC_MAD_CRQ_ERROR 0xEF
74
75enum ibmvfc_crq_valid {
76 IBMVFC_CRQ_CMD_RSP = 0x80,
77 IBMVFC_CRQ_INIT_RSP = 0xC0,
78 IBMVFC_CRQ_XPORT_EVENT = 0xFF,
79};
80
Tyrel Datwylerd6e26352019-03-20 14:56:54 -050081enum ibmvfc_crq_init_msg {
Brian King072b91f2008-07-01 13:14:30 -050082 IBMVFC_CRQ_INIT = 0x01,
83 IBMVFC_CRQ_INIT_COMPLETE = 0x02,
Tyrel Datwylerd6e26352019-03-20 14:56:54 -050084};
85
86enum ibmvfc_crq_xport_evts {
87 IBMVFC_PARTNER_FAILED = 0x01,
88 IBMVFC_PARTNER_DEREGISTER = 0x02,
Brian King072b91f2008-07-01 13:14:30 -050089 IBMVFC_PARTITION_MIGRATED = 0x06,
90};
91
92enum ibmvfc_cmd_status_flags {
93 IBMVFC_FABRIC_MAPPED = 0x0001,
94 IBMVFC_VIOS_FAILURE = 0x0002,
95 IBMVFC_FC_FAILURE = 0x0004,
96 IBMVFC_FC_SCSI_ERROR = 0x0008,
97 IBMVFC_HW_EVENT_LOGGED = 0x0010,
98 IBMVFC_VIOS_LOGGED = 0x0020,
99};
100
101enum ibmvfc_fabric_mapped_errors {
102 IBMVFC_UNABLE_TO_ESTABLISH = 0x0001,
103 IBMVFC_XPORT_FAULT = 0x0002,
104 IBMVFC_CMD_TIMEOUT = 0x0003,
105 IBMVFC_ENETDOWN = 0x0004,
106 IBMVFC_HW_FAILURE = 0x0005,
107 IBMVFC_LINK_DOWN_ERR = 0x0006,
108 IBMVFC_LINK_DEAD_ERR = 0x0007,
109 IBMVFC_UNABLE_TO_REGISTER = 0x0008,
110 IBMVFC_XPORT_BUSY = 0x000A,
111 IBMVFC_XPORT_DEAD = 0x000B,
112 IBMVFC_CONFIG_ERROR = 0x000C,
113 IBMVFC_NAME_SERVER_FAIL = 0x000D,
114 IBMVFC_LINK_HALTED = 0x000E,
115 IBMVFC_XPORT_GENERAL = 0x8000,
116};
117
118enum ibmvfc_vios_errors {
119 IBMVFC_CRQ_FAILURE = 0x0001,
120 IBMVFC_SW_FAILURE = 0x0002,
121 IBMVFC_INVALID_PARAMETER = 0x0003,
122 IBMVFC_MISSING_PARAMETER = 0x0004,
123 IBMVFC_HOST_IO_BUS = 0x0005,
124 IBMVFC_TRANS_CANCELLED = 0x0006,
125 IBMVFC_TRANS_CANCELLED_IMPLICIT = 0x0007,
126 IBMVFC_INSUFFICIENT_RESOURCE = 0x0008,
Brian King646d3852008-11-14 13:33:53 -0600127 IBMVFC_PLOGI_REQUIRED = 0x0010,
Brian King072b91f2008-07-01 13:14:30 -0500128 IBMVFC_COMMAND_FAILED = 0x8000,
129};
130
131enum ibmvfc_mad_types {
132 IBMVFC_NPIV_LOGIN = 0x0001,
133 IBMVFC_DISC_TARGETS = 0x0002,
134 IBMVFC_PORT_LOGIN = 0x0004,
135 IBMVFC_PROCESS_LOGIN = 0x0008,
136 IBMVFC_QUERY_TARGET = 0x0010,
137 IBMVFC_IMPLICIT_LOGOUT = 0x0040,
Brian King989b8542008-07-22 08:31:47 -0500138 IBMVFC_PASSTHRU = 0x0200,
Brian King072b91f2008-07-01 13:14:30 -0500139 IBMVFC_TMF_MAD = 0x0100,
Brian King79111d02009-05-28 16:17:29 -0500140 IBMVFC_NPIV_LOGOUT = 0x0800,
Brian King072b91f2008-07-01 13:14:30 -0500141};
142
143struct ibmvfc_mad_common {
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500144 __be32 version;
145 __be32 reserved;
146 __be32 opcode;
147 __be16 status;
148 __be16 length;
149 __be64 tag;
Brian King072b91f2008-07-01 13:14:30 -0500150}__attribute__((packed, aligned (8)));
151
152struct ibmvfc_npiv_login_mad {
153 struct ibmvfc_mad_common common;
154 struct srp_direct_buf buffer;
155}__attribute__((packed, aligned (8)));
156
Brian King79111d02009-05-28 16:17:29 -0500157struct ibmvfc_npiv_logout_mad {
158 struct ibmvfc_mad_common common;
159}__attribute__((packed, aligned (8)));
160
Brian King072b91f2008-07-01 13:14:30 -0500161#define IBMVFC_MAX_NAME 256
162
163struct ibmvfc_npiv_login {
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500164 __be32 ostype;
Brian King072b91f2008-07-01 13:14:30 -0500165#define IBMVFC_OS_LINUX 0x02
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500166 __be32 pad;
167 __be64 max_dma_len;
168 __be32 max_payload;
169 __be32 max_response;
170 __be32 partition_num;
171 __be32 vfc_frame_version;
172 __be16 fcp_version;
173 __be16 flags;
Brian King072b91f2008-07-01 13:14:30 -0500174#define IBMVFC_CLIENT_MIGRATED 0x01
175#define IBMVFC_FLUSH_ON_HALT 0x02
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500176 __be32 max_cmds;
177 __be64 capabilities;
Brian King072b91f2008-07-01 13:14:30 -0500178#define IBMVFC_CAN_MIGRATE 0x01
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500179 __be64 node_name;
Brian King072b91f2008-07-01 13:14:30 -0500180 struct srp_direct_buf async;
181 u8 partition_name[IBMVFC_MAX_NAME];
182 u8 device_name[IBMVFC_MAX_NAME];
183 u8 drc_name[IBMVFC_MAX_NAME];
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500184 __be64 reserved2[2];
Brian King072b91f2008-07-01 13:14:30 -0500185}__attribute__((packed, aligned (8)));
186
187struct ibmvfc_common_svc_parms {
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500188 __be16 fcph_version;
189 __be16 b2b_credit;
190 __be16 features;
191 __be16 bb_rcv_sz; /* upper nibble is BB_SC_N */
192 __be32 ratov;
193 __be32 edtov;
Brian King072b91f2008-07-01 13:14:30 -0500194}__attribute__((packed, aligned (4)));
195
196struct ibmvfc_service_parms {
197 struct ibmvfc_common_svc_parms common;
198 u8 port_name[8];
199 u8 node_name[8];
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500200 __be32 class1_parms[4];
201 __be32 class2_parms[4];
202 __be32 class3_parms[4];
203 __be32 obsolete[4];
204 __be32 vendor_version[4];
205 __be32 services_avail[2];
206 __be32 ext_len;
207 __be32 reserved[30];
208 __be32 clk_sync_qos[2];
Brian King072b91f2008-07-01 13:14:30 -0500209}__attribute__((packed, aligned (4)));
210
211struct ibmvfc_npiv_login_resp {
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500212 __be32 version;
213 __be16 status;
214 __be16 error;
215 __be32 flags;
Brian King072b91f2008-07-01 13:14:30 -0500216#define IBMVFC_NATIVE_FC 0x01
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500217 __be32 reserved;
218 __be64 capabilities;
Brian King497f9c52009-05-28 16:17:30 -0500219#define IBMVFC_CAN_FLUSH_ON_HALT 0x08
Brian King90f725d2013-04-12 08:25:18 -0500220#define IBMVFC_CAN_SUPPRESS_ABTS 0x10
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500221 __be32 max_cmds;
222 __be32 scsi_id_sz;
223 __be64 max_dma_len;
224 __be64 scsi_id;
225 __be64 port_name;
226 __be64 node_name;
227 __be64 link_speed;
Brian King072b91f2008-07-01 13:14:30 -0500228 u8 partition_name[IBMVFC_MAX_NAME];
229 u8 device_name[IBMVFC_MAX_NAME];
230 u8 port_loc_code[IBMVFC_MAX_NAME];
231 u8 drc_name[IBMVFC_MAX_NAME];
232 struct ibmvfc_service_parms service_parms;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500233 __be64 reserved2;
Brian King072b91f2008-07-01 13:14:30 -0500234}__attribute__((packed, aligned (8)));
235
236union ibmvfc_npiv_login_data {
237 struct ibmvfc_npiv_login login;
238 struct ibmvfc_npiv_login_resp resp;
239}__attribute__((packed, aligned (8)));
240
241struct ibmvfc_discover_targets_buf {
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500242 __be32 scsi_id[1];
Brian King072b91f2008-07-01 13:14:30 -0500243#define IBMVFC_DISC_TGT_SCSI_ID_MASK 0x00ffffff
244};
245
246struct ibmvfc_discover_targets {
247 struct ibmvfc_mad_common common;
248 struct srp_direct_buf buffer;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500249 __be32 flags;
250 __be16 status;
251 __be16 error;
252 __be32 bufflen;
253 __be32 num_avail;
254 __be32 num_written;
255 __be64 reserved[2];
Brian King072b91f2008-07-01 13:14:30 -0500256}__attribute__((packed, aligned (8)));
257
258enum ibmvfc_fc_reason {
259 IBMVFC_INVALID_ELS_CMD_CODE = 0x01,
260 IBMVFC_INVALID_VERSION = 0x02,
261 IBMVFC_LOGICAL_ERROR = 0x03,
262 IBMVFC_INVALID_CT_IU_SIZE = 0x04,
263 IBMVFC_LOGICAL_BUSY = 0x05,
264 IBMVFC_PROTOCOL_ERROR = 0x07,
265 IBMVFC_UNABLE_TO_PERFORM_REQ = 0x09,
266 IBMVFC_CMD_NOT_SUPPORTED = 0x0B,
267 IBMVFC_SERVER_NOT_AVAIL = 0x0D,
268 IBMVFC_CMD_IN_PROGRESS = 0x0E,
269 IBMVFC_VENDOR_SPECIFIC = 0xFF,
270};
271
272enum ibmvfc_fc_type {
273 IBMVFC_FABRIC_REJECT = 0x01,
274 IBMVFC_PORT_REJECT = 0x02,
275 IBMVFC_LS_REJECT = 0x03,
276 IBMVFC_FABRIC_BUSY = 0x04,
277 IBMVFC_PORT_BUSY = 0x05,
278 IBMVFC_BASIC_REJECT = 0x06,
279};
280
281enum ibmvfc_gs_explain {
282 IBMVFC_PORT_NAME_NOT_REG = 0x02,
283};
284
285struct ibmvfc_port_login {
286 struct ibmvfc_mad_common common;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500287 __be64 scsi_id;
288 __be16 reserved;
289 __be16 fc_service_class;
290 __be32 blksz;
291 __be32 hdr_per_blk;
292 __be16 status;
293 __be16 error; /* also fc_reason */
294 __be16 fc_explain;
295 __be16 fc_type;
296 __be32 reserved2;
Brian King072b91f2008-07-01 13:14:30 -0500297 struct ibmvfc_service_parms service_parms;
298 struct ibmvfc_service_parms service_parms_change;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500299 __be64 reserved3[2];
Brian King072b91f2008-07-01 13:14:30 -0500300}__attribute__((packed, aligned (8)));
301
302struct ibmvfc_prli_svc_parms {
303 u8 type;
304#define IBMVFC_SCSI_FCP_TYPE 0x08
305 u8 type_ext;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500306 __be16 flags;
Brian King072b91f2008-07-01 13:14:30 -0500307#define IBMVFC_PRLI_ORIG_PA_VALID 0x8000
308#define IBMVFC_PRLI_RESP_PA_VALID 0x4000
309#define IBMVFC_PRLI_EST_IMG_PAIR 0x2000
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500310 __be32 orig_pa;
311 __be32 resp_pa;
312 __be32 service_parms;
Brian King072b91f2008-07-01 13:14:30 -0500313#define IBMVFC_PRLI_TASK_RETRY 0x00000200
314#define IBMVFC_PRLI_RETRY 0x00000100
315#define IBMVFC_PRLI_DATA_OVERLAY 0x00000040
316#define IBMVFC_PRLI_INITIATOR_FUNC 0x00000020
317#define IBMVFC_PRLI_TARGET_FUNC 0x00000010
318#define IBMVFC_PRLI_READ_FCP_XFER_RDY_DISABLED 0x00000002
319#define IBMVFC_PRLI_WR_FCP_XFER_RDY_DISABLED 0x00000001
320}__attribute__((packed, aligned (4)));
321
322struct ibmvfc_process_login {
323 struct ibmvfc_mad_common common;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500324 __be64 scsi_id;
Brian King072b91f2008-07-01 13:14:30 -0500325 struct ibmvfc_prli_svc_parms parms;
326 u8 reserved[48];
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500327 __be16 status;
328 __be16 error; /* also fc_reason */
329 __be32 reserved2;
330 __be64 reserved3[2];
Brian King072b91f2008-07-01 13:14:30 -0500331}__attribute__((packed, aligned (8)));
332
333struct ibmvfc_query_tgt {
334 struct ibmvfc_mad_common common;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500335 __be64 wwpn;
336 __be64 scsi_id;
337 __be16 status;
338 __be16 error;
339 __be16 fc_explain;
340 __be16 fc_type;
341 __be64 reserved[2];
Brian King072b91f2008-07-01 13:14:30 -0500342}__attribute__((packed, aligned (8)));
343
344struct ibmvfc_implicit_logout {
345 struct ibmvfc_mad_common common;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500346 __be64 old_scsi_id;
347 __be64 reserved[2];
Brian King072b91f2008-07-01 13:14:30 -0500348}__attribute__((packed, aligned (8)));
349
350struct ibmvfc_tmf {
351 struct ibmvfc_mad_common common;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500352 __be64 scsi_id;
Brian King072b91f2008-07-01 13:14:30 -0500353 struct scsi_lun lun;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500354 __be32 flags;
Brian King072b91f2008-07-01 13:14:30 -0500355#define IBMVFC_TMF_ABORT_TASK 0x02
356#define IBMVFC_TMF_ABORT_TASK_SET 0x04
357#define IBMVFC_TMF_LUN_RESET 0x10
358#define IBMVFC_TMF_TGT_RESET 0x20
359#define IBMVFC_TMF_LUA_VALID 0x40
Brian King90f725d2013-04-12 08:25:18 -0500360#define IBMVFC_TMF_SUPPRESS_ABTS 0x80
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500361 __be32 cancel_key;
362 __be32 my_cancel_key;
363 __be32 pad;
364 __be64 reserved[2];
Brian King072b91f2008-07-01 13:14:30 -0500365}__attribute__((packed, aligned (8)));
366
367enum ibmvfc_fcp_rsp_info_codes {
368 RSP_NO_FAILURE = 0x00,
369 RSP_TMF_REJECTED = 0x04,
370 RSP_TMF_FAILED = 0x05,
371 RSP_TMF_INVALID_LUN = 0x09,
372};
373
374struct ibmvfc_fcp_rsp_info {
Tyrel Datwylerc3981362018-01-23 20:11:32 -0600375 u8 reserved[3];
Brian King072b91f2008-07-01 13:14:30 -0500376 u8 rsp_code;
377 u8 reserved2[4];
378}__attribute__((packed, aligned (2)));
379
380enum ibmvfc_fcp_rsp_flags {
381 FCP_BIDI_RSP = 0x80,
382 FCP_BIDI_READ_RESID_UNDER = 0x40,
383 FCP_BIDI_READ_RESID_OVER = 0x20,
384 FCP_CONF_REQ = 0x10,
385 FCP_RESID_UNDER = 0x08,
386 FCP_RESID_OVER = 0x04,
387 FCP_SNS_LEN_VALID = 0x02,
388 FCP_RSP_LEN_VALID = 0x01,
389};
390
391union ibmvfc_fcp_rsp_data {
392 struct ibmvfc_fcp_rsp_info info;
393 u8 sense[SCSI_SENSE_BUFFERSIZE + sizeof(struct ibmvfc_fcp_rsp_info)];
394}__attribute__((packed, aligned (8)));
395
396struct ibmvfc_fcp_rsp {
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500397 __be64 reserved;
398 __be16 retry_delay_timer;
Brian King072b91f2008-07-01 13:14:30 -0500399 u8 flags;
400 u8 scsi_status;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500401 __be32 fcp_resid;
402 __be32 fcp_sense_len;
403 __be32 fcp_rsp_len;
Brian King072b91f2008-07-01 13:14:30 -0500404 union ibmvfc_fcp_rsp_data data;
405}__attribute__((packed, aligned (8)));
406
407enum ibmvfc_cmd_flags {
408 IBMVFC_SCATTERLIST = 0x0001,
409 IBMVFC_NO_MEM_DESC = 0x0002,
410 IBMVFC_READ = 0x0004,
411 IBMVFC_WRITE = 0x0008,
412 IBMVFC_TMF = 0x0080,
413 IBMVFC_CLASS_3_ERR = 0x0100,
414};
415
416enum ibmvfc_fc_task_attr {
417 IBMVFC_SIMPLE_TASK = 0x00,
418 IBMVFC_HEAD_OF_QUEUE = 0x01,
419 IBMVFC_ORDERED_TASK = 0x02,
420 IBMVFC_ACA_TASK = 0x04,
421};
422
423enum ibmvfc_fc_tmf_flags {
424 IBMVFC_ABORT_TASK_SET = 0x02,
425 IBMVFC_LUN_RESET = 0x10,
426 IBMVFC_TARGET_RESET = 0x20,
427};
428
429struct ibmvfc_fcp_cmd_iu {
430 struct scsi_lun lun;
431 u8 crn;
432 u8 pri_task_attr;
433 u8 tmf_flags;
434 u8 add_cdb_len;
435#define IBMVFC_RDDATA 0x02
436#define IBMVFC_WRDATA 0x01
437 u8 cdb[IBMVFC_MAX_CDB_LEN];
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500438 __be32 xfer_len;
Brian King072b91f2008-07-01 13:14:30 -0500439}__attribute__((packed, aligned (4)));
440
441struct ibmvfc_cmd {
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500442 __be64 task_tag;
443 __be32 frame_type;
444 __be32 payload_len;
445 __be32 resp_len;
446 __be32 adapter_resid;
447 __be16 status;
448 __be16 error;
449 __be16 flags;
450 __be16 response_flags;
Brian King072b91f2008-07-01 13:14:30 -0500451#define IBMVFC_ADAPTER_RESID_VALID 0x01
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500452 __be32 cancel_key;
453 __be32 exchange_id;
Brian King072b91f2008-07-01 13:14:30 -0500454 struct srp_direct_buf ext_func;
455 struct srp_direct_buf ioba;
456 struct srp_direct_buf resp;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500457 __be64 correlation;
458 __be64 tgt_scsi_id;
459 __be64 tag;
460 __be64 reserved3[2];
Brian King072b91f2008-07-01 13:14:30 -0500461 struct ibmvfc_fcp_cmd_iu iu;
462 struct ibmvfc_fcp_rsp rsp;
463}__attribute__((packed, aligned (8)));
464
Brian King989b8542008-07-22 08:31:47 -0500465struct ibmvfc_passthru_fc_iu {
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500466 __be32 payload[7];
Brian King989b8542008-07-22 08:31:47 -0500467#define IBMVFC_ADISC 0x52000000
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500468 __be32 response[7];
Brian King989b8542008-07-22 08:31:47 -0500469};
470
471struct ibmvfc_passthru_iu {
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500472 __be64 task_tag;
473 __be32 cmd_len;
474 __be32 rsp_len;
475 __be16 status;
476 __be16 error;
477 __be32 flags;
Brian King989b8542008-07-22 08:31:47 -0500478#define IBMVFC_FC_ELS 0x01
Brian Kingd31429e2009-10-19 15:07:54 -0500479#define IBMVFC_FC_CT_IU 0x02
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500480 __be32 cancel_key;
Brian Kingd31429e2009-10-19 15:07:54 -0500481#define IBMVFC_PASSTHRU_CANCEL_KEY 0x80000000
482#define IBMVFC_INTERNAL_CANCEL_KEY 0x80000001
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500483 __be32 reserved;
Brian King989b8542008-07-22 08:31:47 -0500484 struct srp_direct_buf cmd;
485 struct srp_direct_buf rsp;
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500486 __be64 correlation;
487 __be64 scsi_id;
488 __be64 tag;
489 __be64 reserved2[2];
Brian King989b8542008-07-22 08:31:47 -0500490}__attribute__((packed, aligned (8)));
491
492struct ibmvfc_passthru_mad {
493 struct ibmvfc_mad_common common;
494 struct srp_direct_buf cmd_ioba;
495 struct ibmvfc_passthru_iu iu;
496 struct ibmvfc_passthru_fc_iu fc_iu;
497}__attribute__((packed, aligned (8)));
498
Brian King072b91f2008-07-01 13:14:30 -0500499struct ibmvfc_trace_start_entry {
500 u32 xfer_len;
501}__attribute__((packed));
502
503struct ibmvfc_trace_end_entry {
504 u16 status;
505 u16 error;
506 u8 fcp_rsp_flags;
507 u8 rsp_code;
508 u8 scsi_status;
509 u8 reserved;
510}__attribute__((packed));
511
512struct ibmvfc_trace_entry {
513 struct ibmvfc_event *evt;
514 u32 time;
515 u32 scsi_id;
516 u32 lun;
517 u8 fmt;
518 u8 op_code;
519 u8 tmf_flags;
520 u8 type;
521#define IBMVFC_TRC_START 0x00
522#define IBMVFC_TRC_END 0xff
523 union {
524 struct ibmvfc_trace_start_entry start;
525 struct ibmvfc_trace_end_entry end;
526 } u;
527}__attribute__((packed, aligned (8)));
528
529enum ibmvfc_crq_formats {
530 IBMVFC_CMD_FORMAT = 0x01,
531 IBMVFC_ASYNC_EVENT = 0x02,
532 IBMVFC_MAD_FORMAT = 0x04,
533};
534
535enum ibmvfc_async_event {
536 IBMVFC_AE_ELS_PLOGI = 0x0001,
537 IBMVFC_AE_ELS_LOGO = 0x0002,
538 IBMVFC_AE_ELS_PRLO = 0x0004,
539 IBMVFC_AE_SCN_NPORT = 0x0008,
540 IBMVFC_AE_SCN_GROUP = 0x0010,
541 IBMVFC_AE_SCN_DOMAIN = 0x0020,
542 IBMVFC_AE_SCN_FABRIC = 0x0040,
543 IBMVFC_AE_LINK_UP = 0x0080,
544 IBMVFC_AE_LINK_DOWN = 0x0100,
545 IBMVFC_AE_LINK_DEAD = 0x0200,
546 IBMVFC_AE_HALT = 0x0400,
547 IBMVFC_AE_RESUME = 0x0800,
548 IBMVFC_AE_ADAPTER_FAILED = 0x1000,
549};
550
Brian Kingd99e5f42010-09-09 16:20:42 -0500551struct ibmvfc_async_desc {
Brian Kingd99e5f42010-09-09 16:20:42 -0500552 const char *desc;
Robert Jennings402c6ee2010-12-09 14:03:59 -0600553 enum ibmvfc_async_event ae;
Brian Kingd99e5f42010-09-09 16:20:42 -0500554 int log_level;
555};
556
Brian King072b91f2008-07-01 13:14:30 -0500557struct ibmvfc_crq {
Brian King5919ce22008-11-14 13:33:52 -0600558 volatile u8 valid;
559 volatile u8 format;
Brian King072b91f2008-07-01 13:14:30 -0500560 u8 reserved[6];
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500561 volatile __be64 ioba;
Brian King072b91f2008-07-01 13:14:30 -0500562}__attribute__((packed, aligned (8)));
563
564struct ibmvfc_crq_queue {
565 struct ibmvfc_crq *msgs;
566 int size, cur;
567 dma_addr_t msg_token;
568};
569
Brian King497f9c52009-05-28 16:17:30 -0500570enum ibmvfc_ae_link_state {
571 IBMVFC_AE_LS_LINK_UP = 0x01,
572 IBMVFC_AE_LS_LINK_BOUNCED = 0x02,
573 IBMVFC_AE_LS_LINK_DOWN = 0x04,
574 IBMVFC_AE_LS_LINK_DEAD = 0x08,
575};
576
Brian King072b91f2008-07-01 13:14:30 -0500577struct ibmvfc_async_crq {
Brian King5919ce22008-11-14 13:33:52 -0600578 volatile u8 valid;
Brian King497f9c52009-05-28 16:17:30 -0500579 u8 link_state;
580 u8 pad[2];
Tyrel Datwyler0aab6c32014-06-26 19:03:55 -0500581 __be32 pad2;
582 volatile __be64 event;
583 volatile __be64 scsi_id;
584 volatile __be64 wwpn;
585 volatile __be64 node_name;
586 __be64 reserved;
Brian King072b91f2008-07-01 13:14:30 -0500587}__attribute__((packed, aligned (8)));
588
589struct ibmvfc_async_crq_queue {
590 struct ibmvfc_async_crq *msgs;
591 int size, cur;
592 dma_addr_t msg_token;
593};
594
595union ibmvfc_iu {
596 struct ibmvfc_mad_common mad_common;
597 struct ibmvfc_npiv_login_mad npiv_login;
Brian King79111d02009-05-28 16:17:29 -0500598 struct ibmvfc_npiv_logout_mad npiv_logout;
Brian King072b91f2008-07-01 13:14:30 -0500599 struct ibmvfc_discover_targets discover_targets;
600 struct ibmvfc_port_login plogi;
601 struct ibmvfc_process_login prli;
602 struct ibmvfc_query_tgt query_tgt;
603 struct ibmvfc_implicit_logout implicit_logout;
604 struct ibmvfc_tmf tmf;
605 struct ibmvfc_cmd cmd;
Brian King989b8542008-07-22 08:31:47 -0500606 struct ibmvfc_passthru_mad passthru;
Brian King072b91f2008-07-01 13:14:30 -0500607}__attribute__((packed, aligned (8)));
608
609enum ibmvfc_target_action {
610 IBMVFC_TGT_ACTION_NONE = 0,
611 IBMVFC_TGT_ACTION_INIT,
612 IBMVFC_TGT_ACTION_INIT_WAIT,
Brian King072b91f2008-07-01 13:14:30 -0500613 IBMVFC_TGT_ACTION_DEL_RPORT,
Brian Kingd5da3042010-08-05 16:38:31 -0500614 IBMVFC_TGT_ACTION_DELETED_RPORT,
Brian King072b91f2008-07-01 13:14:30 -0500615};
616
617struct ibmvfc_target {
618 struct list_head queue;
619 struct ibmvfc_host *vhost;
620 u64 scsi_id;
621 u64 new_scsi_id;
622 struct fc_rport *rport;
623 int target_id;
624 enum ibmvfc_target_action action;
625 int need_login;
Brian King43c8da92009-05-28 16:17:28 -0500626 int add_rport;
Brian King072b91f2008-07-01 13:14:30 -0500627 int init_retries;
Brian King017b2ae2009-06-18 09:06:55 -0500628 int logo_rcvd;
Brian King10501e12009-03-20 15:44:39 -0500629 u32 cancel_key;
Brian King072b91f2008-07-01 13:14:30 -0500630 struct ibmvfc_service_parms service_parms;
631 struct ibmvfc_service_parms service_parms_change;
632 struct fc_rport_identifiers ids;
633 void (*job_step) (struct ibmvfc_target *);
Brian King10501e12009-03-20 15:44:39 -0500634 struct timer_list timer;
Brian King072b91f2008-07-01 13:14:30 -0500635 struct kref kref;
636};
637
638/* a unit of work for the hosting partition */
639struct ibmvfc_event {
640 struct list_head queue;
641 struct ibmvfc_host *vhost;
642 struct ibmvfc_target *tgt;
643 struct scsi_cmnd *cmnd;
644 atomic_t free;
645 union ibmvfc_iu *xfer_iu;
646 void (*done) (struct ibmvfc_event *);
647 struct ibmvfc_crq crq;
648 union ibmvfc_iu iu;
649 union ibmvfc_iu *sync_iu;
650 struct srp_direct_buf *ext_list;
651 dma_addr_t ext_list_token;
652 struct completion comp;
Brian Kingad8dcff2008-10-29 08:46:41 -0500653 struct completion *eh_comp;
Brian King072b91f2008-07-01 13:14:30 -0500654 struct timer_list timer;
655};
656
657/* a pool of event structs for use */
658struct ibmvfc_event_pool {
659 struct ibmvfc_event *events;
660 u32 size;
661 union ibmvfc_iu *iu_storage;
662 dma_addr_t iu_token;
663};
664
665enum ibmvfc_host_action {
666 IBMVFC_HOST_ACTION_NONE = 0,
Brian King73ee5d82010-06-17 13:55:13 -0500667 IBMVFC_HOST_ACTION_RESET,
668 IBMVFC_HOST_ACTION_REENABLE,
Brian King79111d02009-05-28 16:17:29 -0500669 IBMVFC_HOST_ACTION_LOGO,
670 IBMVFC_HOST_ACTION_LOGO_WAIT,
Brian King072b91f2008-07-01 13:14:30 -0500671 IBMVFC_HOST_ACTION_INIT,
672 IBMVFC_HOST_ACTION_INIT_WAIT,
673 IBMVFC_HOST_ACTION_QUERY,
674 IBMVFC_HOST_ACTION_QUERY_TGTS,
675 IBMVFC_HOST_ACTION_TGT_DEL,
676 IBMVFC_HOST_ACTION_ALLOC_TGTS,
677 IBMVFC_HOST_ACTION_TGT_INIT,
Brian King10e79492008-10-29 08:46:45 -0500678 IBMVFC_HOST_ACTION_TGT_DEL_FAILED,
Brian King072b91f2008-07-01 13:14:30 -0500679};
680
681enum ibmvfc_host_state {
682 IBMVFC_NO_CRQ = 0,
683 IBMVFC_INITIALIZING,
684 IBMVFC_ACTIVE,
685 IBMVFC_HALTED,
686 IBMVFC_LINK_DOWN,
687 IBMVFC_LINK_DEAD,
688 IBMVFC_HOST_OFFLINE,
689};
690
691struct ibmvfc_host {
692 char name[8];
693 struct list_head queue;
694 struct Scsi_Host *host;
695 enum ibmvfc_host_state state;
696 enum ibmvfc_host_action action;
697#define IBMVFC_NUM_TRACE_INDEX_BITS 8
698#define IBMVFC_NUM_TRACE_ENTRIES (1 << IBMVFC_NUM_TRACE_INDEX_BITS)
699#define IBMVFC_TRACE_SIZE (sizeof(struct ibmvfc_trace_entry) * IBMVFC_NUM_TRACE_ENTRIES)
700 struct ibmvfc_trace_entry *trace;
701 u32 trace_index:IBMVFC_NUM_TRACE_INDEX_BITS;
702 int num_targets;
703 struct list_head targets;
704 struct list_head sent;
705 struct list_head free;
706 struct device *dev;
707 struct ibmvfc_event_pool pool;
708 struct dma_pool *sg_pool;
709 mempool_t *tgt_pool;
710 struct ibmvfc_crq_queue crq;
711 struct ibmvfc_async_crq_queue async_crq;
712 struct ibmvfc_npiv_login login_info;
713 union ibmvfc_npiv_login_data *login_buf;
714 dma_addr_t login_buf_dma;
715 int disc_buf_sz;
716 int log_level;
717 struct ibmvfc_discover_targets_buf *disc_buf;
Brian Kingd31429e2009-10-19 15:07:54 -0500718 struct mutex passthru_mutex;
Brian King072b91f2008-07-01 13:14:30 -0500719 int task_set;
720 int init_retries;
721 int discovery_threads;
Brian King10501e12009-03-20 15:44:39 -0500722 int abort_threads;
Brian King072b91f2008-07-01 13:14:30 -0500723 int client_migrated;
724 int reinit;
Brian King1c41fa822008-12-03 11:02:54 -0600725 int delay_init;
Brian King43c8da92009-05-28 16:17:28 -0500726 int scan_complete;
Brian King79111d02009-05-28 16:17:29 -0500727 int logged_in;
Brian Kingd31429e2009-10-19 15:07:54 -0500728 int aborting_passthru;
Brian King072b91f2008-07-01 13:14:30 -0500729 int events_to_log;
730#define IBMVFC_AE_LINKUP 0x0001
731#define IBMVFC_AE_LINKDOWN 0x0002
732#define IBMVFC_AE_RSCN 0x0004
733 dma_addr_t disc_buf_dma;
734 unsigned int partition_number;
735 char partition_name[97];
736 void (*job_step) (struct ibmvfc_host *);
737 struct task_struct *work_thread;
Brian King039a0892009-03-20 15:44:35 -0500738 struct tasklet_struct tasklet;
Brian King43c8da92009-05-28 16:17:28 -0500739 struct work_struct rport_add_work_q;
Brian King072b91f2008-07-01 13:14:30 -0500740 wait_queue_head_t init_wait_q;
741 wait_queue_head_t work_wait_q;
742};
743
744#define DBG_CMD(CMD) do { if (ibmvfc_debug) CMD; } while (0)
745
746#define tgt_dbg(t, fmt, ...) \
Stephen Rothwell775a42e2009-01-06 14:59:00 +0000747 DBG_CMD(dev_info((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__))
Brian King072b91f2008-07-01 13:14:30 -0500748
Brian King989b8542008-07-22 08:31:47 -0500749#define tgt_info(t, fmt, ...) \
Stephen Rothwell775a42e2009-01-06 14:59:00 +0000750 dev_info((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__)
Brian King989b8542008-07-22 08:31:47 -0500751
Brian King072b91f2008-07-01 13:14:30 -0500752#define tgt_err(t, fmt, ...) \
Stephen Rothwell775a42e2009-01-06 14:59:00 +0000753 dev_err((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__)
Brian King072b91f2008-07-01 13:14:30 -0500754
Brian King7d0e4622009-05-28 16:17:26 -0500755#define tgt_log(t, level, fmt, ...) \
756 do { \
757 if ((t)->vhost->log_level >= level) \
758 tgt_err(t, fmt, ##__VA_ARGS__); \
759 } while (0)
760
Brian King072b91f2008-07-01 13:14:30 -0500761#define ibmvfc_dbg(vhost, ...) \
762 DBG_CMD(dev_info((vhost)->dev, ##__VA_ARGS__))
763
764#define ibmvfc_log(vhost, level, ...) \
765 do { \
Brian King596891a2008-10-29 08:46:33 -0500766 if ((vhost)->log_level >= level) \
Brian King072b91f2008-07-01 13:14:30 -0500767 dev_err((vhost)->dev, ##__VA_ARGS__); \
768 } while (0)
769
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700770#define ENTER DBG_CMD(printk(KERN_INFO IBMVFC_NAME": Entering %s\n", __func__))
771#define LEAVE DBG_CMD(printk(KERN_INFO IBMVFC_NAME": Leaving %s\n", __func__))
Brian King072b91f2008-07-01 13:14:30 -0500772
773#ifdef CONFIG_SCSI_IBMVFC_TRACE
774#define ibmvfc_create_trace_file(kobj, attr) sysfs_create_bin_file(kobj, attr)
775#define ibmvfc_remove_trace_file(kobj, attr) sysfs_remove_bin_file(kobj, attr)
776#else
777#define ibmvfc_create_trace_file(kobj, attr) 0
778#define ibmvfc_remove_trace_file(kobj, attr) do { } while (0)
779#endif
780
781#endif