blob: cf26380820fbf1d3428d599cd21a72e2e1153767 [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 King534841b2009-03-20 15:44:40 -050032#define IBMVFC_DRIVER_VERSION "1.0.5"
33#define IBMVFC_DRIVER_DATE "(March 19, 2009)"
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 King072b91f2008-07-01 13:14:30 -050041#define IBMVFC_MAX_REQUESTS_DEFAULT 100
42
43#define IBMVFC_DEBUG 0
44#define IBMVFC_MAX_TARGETS 1024
45#define IBMVFC_MAX_LUN 0xffffffff
46#define IBMVFC_MAX_SECTORS 0xffffu
47#define IBMVFC_MAX_DISC_THREADS 4
48#define IBMVFC_TGT_MEMPOOL_SZ 64
49#define IBMVFC_MAX_CMDS_PER_LUN 64
Brian King1c41fa822008-12-03 11:02:54 -060050#define IBMVFC_MAX_HOST_INIT_RETRIES 6
51#define IBMVFC_MAX_TGT_INIT_RETRIES 3
Brian King072b91f2008-07-01 13:14:30 -050052#define IBMVFC_DEV_LOSS_TMO (5 * 60)
53#define IBMVFC_DEFAULT_LOG_LEVEL 2
54#define IBMVFC_MAX_CDB_LEN 16
55
56/*
57 * Ensure we have resources for ERP and initialization:
58 * 1 for ERP
59 * 1 for initialization
Brian King79111d02009-05-28 16:17:29 -050060 * 1 for NPIV Logout
Brian King10501e12009-03-20 15:44:39 -050061 * 2 for each discovery thread
Brian King072b91f2008-07-01 13:14:30 -050062 */
Brian King79111d02009-05-28 16:17:29 -050063#define IBMVFC_NUM_INTERNAL_REQ (1 + 1 + 1 + (disc_threads * 2))
Brian King072b91f2008-07-01 13:14:30 -050064
65#define IBMVFC_MAD_SUCCESS 0x00
66#define IBMVFC_MAD_NOT_SUPPORTED 0xF1
67#define IBMVFC_MAD_FAILED 0xF7
68#define IBMVFC_MAD_DRIVER_FAILED 0xEE
69#define IBMVFC_MAD_CRQ_ERROR 0xEF
70
71enum ibmvfc_crq_valid {
72 IBMVFC_CRQ_CMD_RSP = 0x80,
73 IBMVFC_CRQ_INIT_RSP = 0xC0,
74 IBMVFC_CRQ_XPORT_EVENT = 0xFF,
75};
76
77enum ibmvfc_crq_format {
78 IBMVFC_CRQ_INIT = 0x01,
79 IBMVFC_CRQ_INIT_COMPLETE = 0x02,
80 IBMVFC_PARTITION_MIGRATED = 0x06,
81};
82
83enum ibmvfc_cmd_status_flags {
84 IBMVFC_FABRIC_MAPPED = 0x0001,
85 IBMVFC_VIOS_FAILURE = 0x0002,
86 IBMVFC_FC_FAILURE = 0x0004,
87 IBMVFC_FC_SCSI_ERROR = 0x0008,
88 IBMVFC_HW_EVENT_LOGGED = 0x0010,
89 IBMVFC_VIOS_LOGGED = 0x0020,
90};
91
92enum ibmvfc_fabric_mapped_errors {
93 IBMVFC_UNABLE_TO_ESTABLISH = 0x0001,
94 IBMVFC_XPORT_FAULT = 0x0002,
95 IBMVFC_CMD_TIMEOUT = 0x0003,
96 IBMVFC_ENETDOWN = 0x0004,
97 IBMVFC_HW_FAILURE = 0x0005,
98 IBMVFC_LINK_DOWN_ERR = 0x0006,
99 IBMVFC_LINK_DEAD_ERR = 0x0007,
100 IBMVFC_UNABLE_TO_REGISTER = 0x0008,
101 IBMVFC_XPORT_BUSY = 0x000A,
102 IBMVFC_XPORT_DEAD = 0x000B,
103 IBMVFC_CONFIG_ERROR = 0x000C,
104 IBMVFC_NAME_SERVER_FAIL = 0x000D,
105 IBMVFC_LINK_HALTED = 0x000E,
106 IBMVFC_XPORT_GENERAL = 0x8000,
107};
108
109enum ibmvfc_vios_errors {
110 IBMVFC_CRQ_FAILURE = 0x0001,
111 IBMVFC_SW_FAILURE = 0x0002,
112 IBMVFC_INVALID_PARAMETER = 0x0003,
113 IBMVFC_MISSING_PARAMETER = 0x0004,
114 IBMVFC_HOST_IO_BUS = 0x0005,
115 IBMVFC_TRANS_CANCELLED = 0x0006,
116 IBMVFC_TRANS_CANCELLED_IMPLICIT = 0x0007,
117 IBMVFC_INSUFFICIENT_RESOURCE = 0x0008,
Brian King646d3852008-11-14 13:33:53 -0600118 IBMVFC_PLOGI_REQUIRED = 0x0010,
Brian King072b91f2008-07-01 13:14:30 -0500119 IBMVFC_COMMAND_FAILED = 0x8000,
120};
121
122enum ibmvfc_mad_types {
123 IBMVFC_NPIV_LOGIN = 0x0001,
124 IBMVFC_DISC_TARGETS = 0x0002,
125 IBMVFC_PORT_LOGIN = 0x0004,
126 IBMVFC_PROCESS_LOGIN = 0x0008,
127 IBMVFC_QUERY_TARGET = 0x0010,
128 IBMVFC_IMPLICIT_LOGOUT = 0x0040,
Brian King989b8542008-07-22 08:31:47 -0500129 IBMVFC_PASSTHRU = 0x0200,
Brian King072b91f2008-07-01 13:14:30 -0500130 IBMVFC_TMF_MAD = 0x0100,
Brian King79111d02009-05-28 16:17:29 -0500131 IBMVFC_NPIV_LOGOUT = 0x0800,
Brian King072b91f2008-07-01 13:14:30 -0500132};
133
134struct ibmvfc_mad_common {
135 u32 version;
136 u32 reserved;
137 u32 opcode;
138 u16 status;
139 u16 length;
140 u64 tag;
141}__attribute__((packed, aligned (8)));
142
143struct ibmvfc_npiv_login_mad {
144 struct ibmvfc_mad_common common;
145 struct srp_direct_buf buffer;
146}__attribute__((packed, aligned (8)));
147
Brian King79111d02009-05-28 16:17:29 -0500148struct ibmvfc_npiv_logout_mad {
149 struct ibmvfc_mad_common common;
150}__attribute__((packed, aligned (8)));
151
Brian King072b91f2008-07-01 13:14:30 -0500152#define IBMVFC_MAX_NAME 256
153
154struct ibmvfc_npiv_login {
155 u32 ostype;
156#define IBMVFC_OS_LINUX 0x02
157 u32 pad;
158 u64 max_dma_len;
159 u32 max_payload;
160 u32 max_response;
161 u32 partition_num;
162 u32 vfc_frame_version;
163 u16 fcp_version;
164 u16 flags;
165#define IBMVFC_CLIENT_MIGRATED 0x01
166#define IBMVFC_FLUSH_ON_HALT 0x02
167 u32 max_cmds;
168 u64 capabilities;
169#define IBMVFC_CAN_MIGRATE 0x01
170 u64 node_name;
171 struct srp_direct_buf async;
172 u8 partition_name[IBMVFC_MAX_NAME];
173 u8 device_name[IBMVFC_MAX_NAME];
174 u8 drc_name[IBMVFC_MAX_NAME];
175 u64 reserved2[2];
176}__attribute__((packed, aligned (8)));
177
178struct ibmvfc_common_svc_parms {
179 u16 fcph_version;
180 u16 b2b_credit;
181 u16 features;
182 u16 bb_rcv_sz; /* upper nibble is BB_SC_N */
183 u32 ratov;
184 u32 edtov;
185}__attribute__((packed, aligned (4)));
186
187struct ibmvfc_service_parms {
188 struct ibmvfc_common_svc_parms common;
189 u8 port_name[8];
190 u8 node_name[8];
191 u32 class1_parms[4];
192 u32 class2_parms[4];
193 u32 class3_parms[4];
194 u32 obsolete[4];
195 u32 vendor_version[4];
196 u32 services_avail[2];
197 u32 ext_len;
198 u32 reserved[30];
199 u32 clk_sync_qos[2];
200}__attribute__((packed, aligned (4)));
201
202struct ibmvfc_npiv_login_resp {
203 u32 version;
204 u16 status;
205 u16 error;
206 u32 flags;
207#define IBMVFC_NATIVE_FC 0x01
208#define IBMVFC_CAN_FLUSH_ON_HALT 0x08
209 u32 reserved;
Brian King497f9c52009-05-28 16:17:30 -0500210 u64 capabilities;
211#define IBMVFC_CAN_FLUSH_ON_HALT 0x08
Brian King072b91f2008-07-01 13:14:30 -0500212 u32 max_cmds;
213 u32 scsi_id_sz;
214 u64 max_dma_len;
215 u64 scsi_id;
216 u64 port_name;
217 u64 node_name;
218 u64 link_speed;
219 u8 partition_name[IBMVFC_MAX_NAME];
220 u8 device_name[IBMVFC_MAX_NAME];
221 u8 port_loc_code[IBMVFC_MAX_NAME];
222 u8 drc_name[IBMVFC_MAX_NAME];
223 struct ibmvfc_service_parms service_parms;
224 u64 reserved2;
225}__attribute__((packed, aligned (8)));
226
227union ibmvfc_npiv_login_data {
228 struct ibmvfc_npiv_login login;
229 struct ibmvfc_npiv_login_resp resp;
230}__attribute__((packed, aligned (8)));
231
232struct ibmvfc_discover_targets_buf {
233 u32 scsi_id[1];
234#define IBMVFC_DISC_TGT_SCSI_ID_MASK 0x00ffffff
235};
236
237struct ibmvfc_discover_targets {
238 struct ibmvfc_mad_common common;
239 struct srp_direct_buf buffer;
240 u32 flags;
241 u16 status;
242 u16 error;
243 u32 bufflen;
244 u32 num_avail;
245 u32 num_written;
246 u64 reserved[2];
247}__attribute__((packed, aligned (8)));
248
249enum ibmvfc_fc_reason {
250 IBMVFC_INVALID_ELS_CMD_CODE = 0x01,
251 IBMVFC_INVALID_VERSION = 0x02,
252 IBMVFC_LOGICAL_ERROR = 0x03,
253 IBMVFC_INVALID_CT_IU_SIZE = 0x04,
254 IBMVFC_LOGICAL_BUSY = 0x05,
255 IBMVFC_PROTOCOL_ERROR = 0x07,
256 IBMVFC_UNABLE_TO_PERFORM_REQ = 0x09,
257 IBMVFC_CMD_NOT_SUPPORTED = 0x0B,
258 IBMVFC_SERVER_NOT_AVAIL = 0x0D,
259 IBMVFC_CMD_IN_PROGRESS = 0x0E,
260 IBMVFC_VENDOR_SPECIFIC = 0xFF,
261};
262
263enum ibmvfc_fc_type {
264 IBMVFC_FABRIC_REJECT = 0x01,
265 IBMVFC_PORT_REJECT = 0x02,
266 IBMVFC_LS_REJECT = 0x03,
267 IBMVFC_FABRIC_BUSY = 0x04,
268 IBMVFC_PORT_BUSY = 0x05,
269 IBMVFC_BASIC_REJECT = 0x06,
270};
271
272enum ibmvfc_gs_explain {
273 IBMVFC_PORT_NAME_NOT_REG = 0x02,
274};
275
276struct ibmvfc_port_login {
277 struct ibmvfc_mad_common common;
278 u64 scsi_id;
279 u16 reserved;
280 u16 fc_service_class;
281 u32 blksz;
282 u32 hdr_per_blk;
283 u16 status;
284 u16 error; /* also fc_reason */
285 u16 fc_explain;
286 u16 fc_type;
287 u32 reserved2;
288 struct ibmvfc_service_parms service_parms;
289 struct ibmvfc_service_parms service_parms_change;
290 u64 reserved3[2];
291}__attribute__((packed, aligned (8)));
292
293struct ibmvfc_prli_svc_parms {
294 u8 type;
295#define IBMVFC_SCSI_FCP_TYPE 0x08
296 u8 type_ext;
297 u16 flags;
298#define IBMVFC_PRLI_ORIG_PA_VALID 0x8000
299#define IBMVFC_PRLI_RESP_PA_VALID 0x4000
300#define IBMVFC_PRLI_EST_IMG_PAIR 0x2000
301 u32 orig_pa;
302 u32 resp_pa;
303 u32 service_parms;
304#define IBMVFC_PRLI_TASK_RETRY 0x00000200
305#define IBMVFC_PRLI_RETRY 0x00000100
306#define IBMVFC_PRLI_DATA_OVERLAY 0x00000040
307#define IBMVFC_PRLI_INITIATOR_FUNC 0x00000020
308#define IBMVFC_PRLI_TARGET_FUNC 0x00000010
309#define IBMVFC_PRLI_READ_FCP_XFER_RDY_DISABLED 0x00000002
310#define IBMVFC_PRLI_WR_FCP_XFER_RDY_DISABLED 0x00000001
311}__attribute__((packed, aligned (4)));
312
313struct ibmvfc_process_login {
314 struct ibmvfc_mad_common common;
315 u64 scsi_id;
316 struct ibmvfc_prli_svc_parms parms;
317 u8 reserved[48];
318 u16 status;
319 u16 error; /* also fc_reason */
320 u32 reserved2;
321 u64 reserved3[2];
322}__attribute__((packed, aligned (8)));
323
324struct ibmvfc_query_tgt {
325 struct ibmvfc_mad_common common;
326 u64 wwpn;
327 u64 scsi_id;
328 u16 status;
329 u16 error;
330 u16 fc_explain;
331 u16 fc_type;
332 u64 reserved[2];
333}__attribute__((packed, aligned (8)));
334
335struct ibmvfc_implicit_logout {
336 struct ibmvfc_mad_common common;
337 u64 old_scsi_id;
338 u64 reserved[2];
339}__attribute__((packed, aligned (8)));
340
341struct ibmvfc_tmf {
342 struct ibmvfc_mad_common common;
343 u64 scsi_id;
344 struct scsi_lun lun;
345 u32 flags;
346#define IBMVFC_TMF_ABORT_TASK 0x02
347#define IBMVFC_TMF_ABORT_TASK_SET 0x04
348#define IBMVFC_TMF_LUN_RESET 0x10
349#define IBMVFC_TMF_TGT_RESET 0x20
350#define IBMVFC_TMF_LUA_VALID 0x40
351 u32 cancel_key;
352 u32 my_cancel_key;
Brian King072b91f2008-07-01 13:14:30 -0500353 u32 pad;
354 u64 reserved[2];
355}__attribute__((packed, aligned (8)));
356
357enum ibmvfc_fcp_rsp_info_codes {
358 RSP_NO_FAILURE = 0x00,
359 RSP_TMF_REJECTED = 0x04,
360 RSP_TMF_FAILED = 0x05,
361 RSP_TMF_INVALID_LUN = 0x09,
362};
363
364struct ibmvfc_fcp_rsp_info {
365 u16 reserved;
366 u8 rsp_code;
367 u8 reserved2[4];
368}__attribute__((packed, aligned (2)));
369
370enum ibmvfc_fcp_rsp_flags {
371 FCP_BIDI_RSP = 0x80,
372 FCP_BIDI_READ_RESID_UNDER = 0x40,
373 FCP_BIDI_READ_RESID_OVER = 0x20,
374 FCP_CONF_REQ = 0x10,
375 FCP_RESID_UNDER = 0x08,
376 FCP_RESID_OVER = 0x04,
377 FCP_SNS_LEN_VALID = 0x02,
378 FCP_RSP_LEN_VALID = 0x01,
379};
380
381union ibmvfc_fcp_rsp_data {
382 struct ibmvfc_fcp_rsp_info info;
383 u8 sense[SCSI_SENSE_BUFFERSIZE + sizeof(struct ibmvfc_fcp_rsp_info)];
384}__attribute__((packed, aligned (8)));
385
386struct ibmvfc_fcp_rsp {
387 u64 reserved;
388 u16 retry_delay_timer;
389 u8 flags;
390 u8 scsi_status;
391 u32 fcp_resid;
392 u32 fcp_sense_len;
393 u32 fcp_rsp_len;
394 union ibmvfc_fcp_rsp_data data;
395}__attribute__((packed, aligned (8)));
396
397enum ibmvfc_cmd_flags {
398 IBMVFC_SCATTERLIST = 0x0001,
399 IBMVFC_NO_MEM_DESC = 0x0002,
400 IBMVFC_READ = 0x0004,
401 IBMVFC_WRITE = 0x0008,
402 IBMVFC_TMF = 0x0080,
403 IBMVFC_CLASS_3_ERR = 0x0100,
404};
405
406enum ibmvfc_fc_task_attr {
407 IBMVFC_SIMPLE_TASK = 0x00,
408 IBMVFC_HEAD_OF_QUEUE = 0x01,
409 IBMVFC_ORDERED_TASK = 0x02,
410 IBMVFC_ACA_TASK = 0x04,
411};
412
413enum ibmvfc_fc_tmf_flags {
414 IBMVFC_ABORT_TASK_SET = 0x02,
415 IBMVFC_LUN_RESET = 0x10,
416 IBMVFC_TARGET_RESET = 0x20,
417};
418
419struct ibmvfc_fcp_cmd_iu {
420 struct scsi_lun lun;
421 u8 crn;
422 u8 pri_task_attr;
423 u8 tmf_flags;
424 u8 add_cdb_len;
425#define IBMVFC_RDDATA 0x02
426#define IBMVFC_WRDATA 0x01
427 u8 cdb[IBMVFC_MAX_CDB_LEN];
428 u32 xfer_len;
429}__attribute__((packed, aligned (4)));
430
431struct ibmvfc_cmd {
432 u64 task_tag;
433 u32 frame_type;
434 u32 payload_len;
435 u32 resp_len;
436 u32 adapter_resid;
437 u16 status;
438 u16 error;
439 u16 flags;
440 u16 response_flags;
441#define IBMVFC_ADAPTER_RESID_VALID 0x01
442 u32 cancel_key;
443 u32 exchange_id;
444 struct srp_direct_buf ext_func;
445 struct srp_direct_buf ioba;
446 struct srp_direct_buf resp;
447 u64 correlation;
448 u64 tgt_scsi_id;
449 u64 tag;
450 u64 reserved3[2];
451 struct ibmvfc_fcp_cmd_iu iu;
452 struct ibmvfc_fcp_rsp rsp;
453}__attribute__((packed, aligned (8)));
454
Brian King989b8542008-07-22 08:31:47 -0500455struct ibmvfc_passthru_fc_iu {
456 u32 payload[7];
457#define IBMVFC_ADISC 0x52000000
458 u32 response[7];
459};
460
461struct ibmvfc_passthru_iu {
462 u64 task_tag;
463 u32 cmd_len;
464 u32 rsp_len;
465 u16 status;
466 u16 error;
467 u32 flags;
468#define IBMVFC_FC_ELS 0x01
469 u32 cancel_key;
470 u32 reserved;
471 struct srp_direct_buf cmd;
472 struct srp_direct_buf rsp;
473 u64 correlation;
474 u64 scsi_id;
475 u64 tag;
476 u64 reserved2[2];
477}__attribute__((packed, aligned (8)));
478
479struct ibmvfc_passthru_mad {
480 struct ibmvfc_mad_common common;
481 struct srp_direct_buf cmd_ioba;
482 struct ibmvfc_passthru_iu iu;
483 struct ibmvfc_passthru_fc_iu fc_iu;
484}__attribute__((packed, aligned (8)));
485
Brian King072b91f2008-07-01 13:14:30 -0500486struct ibmvfc_trace_start_entry {
487 u32 xfer_len;
488}__attribute__((packed));
489
490struct ibmvfc_trace_end_entry {
491 u16 status;
492 u16 error;
493 u8 fcp_rsp_flags;
494 u8 rsp_code;
495 u8 scsi_status;
496 u8 reserved;
497}__attribute__((packed));
498
499struct ibmvfc_trace_entry {
500 struct ibmvfc_event *evt;
501 u32 time;
502 u32 scsi_id;
503 u32 lun;
504 u8 fmt;
505 u8 op_code;
506 u8 tmf_flags;
507 u8 type;
508#define IBMVFC_TRC_START 0x00
509#define IBMVFC_TRC_END 0xff
510 union {
511 struct ibmvfc_trace_start_entry start;
512 struct ibmvfc_trace_end_entry end;
513 } u;
514}__attribute__((packed, aligned (8)));
515
516enum ibmvfc_crq_formats {
517 IBMVFC_CMD_FORMAT = 0x01,
518 IBMVFC_ASYNC_EVENT = 0x02,
519 IBMVFC_MAD_FORMAT = 0x04,
520};
521
522enum ibmvfc_async_event {
523 IBMVFC_AE_ELS_PLOGI = 0x0001,
524 IBMVFC_AE_ELS_LOGO = 0x0002,
525 IBMVFC_AE_ELS_PRLO = 0x0004,
526 IBMVFC_AE_SCN_NPORT = 0x0008,
527 IBMVFC_AE_SCN_GROUP = 0x0010,
528 IBMVFC_AE_SCN_DOMAIN = 0x0020,
529 IBMVFC_AE_SCN_FABRIC = 0x0040,
530 IBMVFC_AE_LINK_UP = 0x0080,
531 IBMVFC_AE_LINK_DOWN = 0x0100,
532 IBMVFC_AE_LINK_DEAD = 0x0200,
533 IBMVFC_AE_HALT = 0x0400,
534 IBMVFC_AE_RESUME = 0x0800,
535 IBMVFC_AE_ADAPTER_FAILED = 0x1000,
536};
537
538struct ibmvfc_crq {
Brian King5919ce22008-11-14 13:33:52 -0600539 volatile u8 valid;
540 volatile u8 format;
Brian King072b91f2008-07-01 13:14:30 -0500541 u8 reserved[6];
Brian King5919ce22008-11-14 13:33:52 -0600542 volatile u64 ioba;
Brian King072b91f2008-07-01 13:14:30 -0500543}__attribute__((packed, aligned (8)));
544
545struct ibmvfc_crq_queue {
546 struct ibmvfc_crq *msgs;
547 int size, cur;
548 dma_addr_t msg_token;
549};
550
Brian King497f9c52009-05-28 16:17:30 -0500551enum ibmvfc_ae_link_state {
552 IBMVFC_AE_LS_LINK_UP = 0x01,
553 IBMVFC_AE_LS_LINK_BOUNCED = 0x02,
554 IBMVFC_AE_LS_LINK_DOWN = 0x04,
555 IBMVFC_AE_LS_LINK_DEAD = 0x08,
556};
557
Brian King072b91f2008-07-01 13:14:30 -0500558struct ibmvfc_async_crq {
Brian King5919ce22008-11-14 13:33:52 -0600559 volatile u8 valid;
Brian King497f9c52009-05-28 16:17:30 -0500560 u8 link_state;
561 u8 pad[2];
Brian King072b91f2008-07-01 13:14:30 -0500562 u32 pad2;
Brian King5919ce22008-11-14 13:33:52 -0600563 volatile u64 event;
564 volatile u64 scsi_id;
565 volatile u64 wwpn;
566 volatile u64 node_name;
Brian King072b91f2008-07-01 13:14:30 -0500567 u64 reserved;
568}__attribute__((packed, aligned (8)));
569
570struct ibmvfc_async_crq_queue {
571 struct ibmvfc_async_crq *msgs;
572 int size, cur;
573 dma_addr_t msg_token;
574};
575
576union ibmvfc_iu {
577 struct ibmvfc_mad_common mad_common;
578 struct ibmvfc_npiv_login_mad npiv_login;
Brian King79111d02009-05-28 16:17:29 -0500579 struct ibmvfc_npiv_logout_mad npiv_logout;
Brian King072b91f2008-07-01 13:14:30 -0500580 struct ibmvfc_discover_targets discover_targets;
581 struct ibmvfc_port_login plogi;
582 struct ibmvfc_process_login prli;
583 struct ibmvfc_query_tgt query_tgt;
584 struct ibmvfc_implicit_logout implicit_logout;
585 struct ibmvfc_tmf tmf;
586 struct ibmvfc_cmd cmd;
Brian King989b8542008-07-22 08:31:47 -0500587 struct ibmvfc_passthru_mad passthru;
Brian King072b91f2008-07-01 13:14:30 -0500588}__attribute__((packed, aligned (8)));
589
590enum ibmvfc_target_action {
591 IBMVFC_TGT_ACTION_NONE = 0,
592 IBMVFC_TGT_ACTION_INIT,
593 IBMVFC_TGT_ACTION_INIT_WAIT,
Brian King072b91f2008-07-01 13:14:30 -0500594 IBMVFC_TGT_ACTION_DEL_RPORT,
595};
596
597struct ibmvfc_target {
598 struct list_head queue;
599 struct ibmvfc_host *vhost;
600 u64 scsi_id;
601 u64 new_scsi_id;
602 struct fc_rport *rport;
603 int target_id;
604 enum ibmvfc_target_action action;
605 int need_login;
Brian King43c8da92009-05-28 16:17:28 -0500606 int add_rport;
Brian King072b91f2008-07-01 13:14:30 -0500607 int init_retries;
Brian King10501e12009-03-20 15:44:39 -0500608 u32 cancel_key;
Brian King072b91f2008-07-01 13:14:30 -0500609 struct ibmvfc_service_parms service_parms;
610 struct ibmvfc_service_parms service_parms_change;
611 struct fc_rport_identifiers ids;
612 void (*job_step) (struct ibmvfc_target *);
Brian King10501e12009-03-20 15:44:39 -0500613 struct timer_list timer;
Brian King072b91f2008-07-01 13:14:30 -0500614 struct kref kref;
615};
616
617/* a unit of work for the hosting partition */
618struct ibmvfc_event {
619 struct list_head queue;
620 struct ibmvfc_host *vhost;
621 struct ibmvfc_target *tgt;
622 struct scsi_cmnd *cmnd;
623 atomic_t free;
624 union ibmvfc_iu *xfer_iu;
625 void (*done) (struct ibmvfc_event *);
626 struct ibmvfc_crq crq;
627 union ibmvfc_iu iu;
628 union ibmvfc_iu *sync_iu;
629 struct srp_direct_buf *ext_list;
630 dma_addr_t ext_list_token;
631 struct completion comp;
Brian Kingad8dcff2008-10-29 08:46:41 -0500632 struct completion *eh_comp;
Brian King072b91f2008-07-01 13:14:30 -0500633 struct timer_list timer;
634};
635
636/* a pool of event structs for use */
637struct ibmvfc_event_pool {
638 struct ibmvfc_event *events;
639 u32 size;
640 union ibmvfc_iu *iu_storage;
641 dma_addr_t iu_token;
642};
643
644enum ibmvfc_host_action {
645 IBMVFC_HOST_ACTION_NONE = 0,
Brian King79111d02009-05-28 16:17:29 -0500646 IBMVFC_HOST_ACTION_LOGO,
647 IBMVFC_HOST_ACTION_LOGO_WAIT,
Brian King072b91f2008-07-01 13:14:30 -0500648 IBMVFC_HOST_ACTION_INIT,
649 IBMVFC_HOST_ACTION_INIT_WAIT,
650 IBMVFC_HOST_ACTION_QUERY,
651 IBMVFC_HOST_ACTION_QUERY_TGTS,
652 IBMVFC_HOST_ACTION_TGT_DEL,
653 IBMVFC_HOST_ACTION_ALLOC_TGTS,
654 IBMVFC_HOST_ACTION_TGT_INIT,
Brian King10e79492008-10-29 08:46:45 -0500655 IBMVFC_HOST_ACTION_TGT_DEL_FAILED,
Brian King072b91f2008-07-01 13:14:30 -0500656};
657
658enum ibmvfc_host_state {
659 IBMVFC_NO_CRQ = 0,
660 IBMVFC_INITIALIZING,
661 IBMVFC_ACTIVE,
662 IBMVFC_HALTED,
663 IBMVFC_LINK_DOWN,
664 IBMVFC_LINK_DEAD,
665 IBMVFC_HOST_OFFLINE,
666};
667
668struct ibmvfc_host {
669 char name[8];
670 struct list_head queue;
671 struct Scsi_Host *host;
672 enum ibmvfc_host_state state;
673 enum ibmvfc_host_action action;
674#define IBMVFC_NUM_TRACE_INDEX_BITS 8
675#define IBMVFC_NUM_TRACE_ENTRIES (1 << IBMVFC_NUM_TRACE_INDEX_BITS)
676#define IBMVFC_TRACE_SIZE (sizeof(struct ibmvfc_trace_entry) * IBMVFC_NUM_TRACE_ENTRIES)
677 struct ibmvfc_trace_entry *trace;
678 u32 trace_index:IBMVFC_NUM_TRACE_INDEX_BITS;
679 int num_targets;
680 struct list_head targets;
681 struct list_head sent;
682 struct list_head free;
683 struct device *dev;
684 struct ibmvfc_event_pool pool;
685 struct dma_pool *sg_pool;
686 mempool_t *tgt_pool;
687 struct ibmvfc_crq_queue crq;
688 struct ibmvfc_async_crq_queue async_crq;
689 struct ibmvfc_npiv_login login_info;
690 union ibmvfc_npiv_login_data *login_buf;
691 dma_addr_t login_buf_dma;
692 int disc_buf_sz;
693 int log_level;
694 struct ibmvfc_discover_targets_buf *disc_buf;
695 int task_set;
696 int init_retries;
697 int discovery_threads;
Brian King10501e12009-03-20 15:44:39 -0500698 int abort_threads;
Brian King072b91f2008-07-01 13:14:30 -0500699 int client_migrated;
700 int reinit;
Brian King1c41fa822008-12-03 11:02:54 -0600701 int delay_init;
Brian King43c8da92009-05-28 16:17:28 -0500702 int scan_complete;
Brian King79111d02009-05-28 16:17:29 -0500703 int logged_in;
Brian King072b91f2008-07-01 13:14:30 -0500704 int events_to_log;
705#define IBMVFC_AE_LINKUP 0x0001
706#define IBMVFC_AE_LINKDOWN 0x0002
707#define IBMVFC_AE_RSCN 0x0004
708 dma_addr_t disc_buf_dma;
709 unsigned int partition_number;
710 char partition_name[97];
711 void (*job_step) (struct ibmvfc_host *);
712 struct task_struct *work_thread;
Brian King039a0892009-03-20 15:44:35 -0500713 struct tasklet_struct tasklet;
Brian King43c8da92009-05-28 16:17:28 -0500714 struct work_struct rport_add_work_q;
Brian King072b91f2008-07-01 13:14:30 -0500715 wait_queue_head_t init_wait_q;
716 wait_queue_head_t work_wait_q;
717};
718
719#define DBG_CMD(CMD) do { if (ibmvfc_debug) CMD; } while (0)
720
721#define tgt_dbg(t, fmt, ...) \
Stephen Rothwell775a42e2009-01-06 14:59:00 +0000722 DBG_CMD(dev_info((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__))
Brian King072b91f2008-07-01 13:14:30 -0500723
Brian King989b8542008-07-22 08:31:47 -0500724#define tgt_info(t, fmt, ...) \
Stephen Rothwell775a42e2009-01-06 14:59:00 +0000725 dev_info((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__)
Brian King989b8542008-07-22 08:31:47 -0500726
Brian King072b91f2008-07-01 13:14:30 -0500727#define tgt_err(t, fmt, ...) \
Stephen Rothwell775a42e2009-01-06 14:59:00 +0000728 dev_err((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__)
Brian King072b91f2008-07-01 13:14:30 -0500729
Brian King7d0e4622009-05-28 16:17:26 -0500730#define tgt_log(t, level, fmt, ...) \
731 do { \
732 if ((t)->vhost->log_level >= level) \
733 tgt_err(t, fmt, ##__VA_ARGS__); \
734 } while (0)
735
Brian King072b91f2008-07-01 13:14:30 -0500736#define ibmvfc_dbg(vhost, ...) \
737 DBG_CMD(dev_info((vhost)->dev, ##__VA_ARGS__))
738
739#define ibmvfc_log(vhost, level, ...) \
740 do { \
Brian King596891a2008-10-29 08:46:33 -0500741 if ((vhost)->log_level >= level) \
Brian King072b91f2008-07-01 13:14:30 -0500742 dev_err((vhost)->dev, ##__VA_ARGS__); \
743 } while (0)
744
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700745#define ENTER DBG_CMD(printk(KERN_INFO IBMVFC_NAME": Entering %s\n", __func__))
746#define LEAVE DBG_CMD(printk(KERN_INFO IBMVFC_NAME": Leaving %s\n", __func__))
Brian King072b91f2008-07-01 13:14:30 -0500747
748#ifdef CONFIG_SCSI_IBMVFC_TRACE
749#define ibmvfc_create_trace_file(kobj, attr) sysfs_create_bin_file(kobj, attr)
750#define ibmvfc_remove_trace_file(kobj, attr) sysfs_remove_bin_file(kobj, attr)
751#else
752#define ibmvfc_create_trace_file(kobj, attr) 0
753#define ibmvfc_remove_trace_file(kobj, attr) do { } while (0)
754#endif
755
756#endif