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