patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / s390 / scsi / zfcp_def.h
1 /* 
2  * 
3  * linux/drivers/s390/scsi/zfcp_def.h
4  * 
5  * FCP adapter driver for IBM eServer zSeries 
6  * 
7  * (C) Copyright IBM Corp. 2002, 2004
8  *
9  * Author(s): Martin Peschke <mpeschke@de.ibm.com> 
10  *            Raimund Schroeder <raimund.schroeder@de.ibm.com> 
11  *            Aron Zeh
12  *            Wolfgang Taphorn
13  *            Stefan Bader <stefan.bader@de.ibm.com> 
14  *            Heiko Carstens <heiko.carstens@de.ibm.com> 
15  * 
16  * This program is free software; you can redistribute it and/or modify 
17  * it under the terms of the GNU General Public License as published by 
18  * the Free Software Foundation; either version 2, or (at your option) 
19  * any later version. 
20  * 
21  * This program is distributed in the hope that it will be useful, 
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
24  * GNU General Public License for more details. 
25  * 
26  * You should have received a copy of the GNU General Public License 
27  * along with this program; if not, write to the Free Software 
28  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
29  */ 
30
31
32 #ifndef ZFCP_DEF_H
33 #define ZFCP_DEF_H
34
35 /* this drivers version (do not edit !!! generated and updated by cvs) */
36 #define ZFCP_DEF_REVISION "$Revision: 1.73 $"
37
38 /*************************** INCLUDES *****************************************/
39
40 #include <linux/init.h>
41 #include <linux/moduleparam.h>
42 #include <linux/miscdevice.h>
43 #include <linux/major.h>
44 #include <linux/blkdev.h>
45 #include <scsi/scsi.h>
46 #include <scsi/scsi_tcq.h>
47 #include <scsi/scsi_cmnd.h>
48 #include <scsi/scsi_device.h>
49 #include <scsi/scsi_host.h>
50 #include "../../fc4/fc.h"
51 #include "zfcp_fsf.h"
52 #include <asm/ccwdev.h>
53 #include <asm/qdio.h>
54 #include <asm/debug.h>
55 #include <asm/ebcdic.h>
56 #include <linux/reboot.h>
57 #include <linux/mempool.h>
58 #include <linux/syscalls.h>
59 #include <linux/ioctl.h>
60 #ifdef CONFIG_S390_SUPPORT
61 #include <linux/ioctl32.h>
62 #endif
63
64 /************************ DEBUG FLAGS *****************************************/
65
66 #define ZFCP_PRINT_FLAGS
67
68 /********************* GENERAL DEFINES *********************************/
69
70 /* zfcp version number, it consists of major, minor, and patch-level number */
71 #define ZFCP_VERSION            "4.0.0"
72
73 static inline void *
74 zfcp_sg_to_address(struct scatterlist *list)
75 {
76         return (void *) (page_address(list->page) + list->offset);
77 }
78
79 static inline void
80 zfcp_address_to_sg(void *address, struct scatterlist *list)
81 {
82         list->page = virt_to_page(address);
83         list->offset = ((unsigned long) address) & (PAGE_SIZE - 1);
84 }
85
86 /********************* SCSI SPECIFIC DEFINES *********************************/
87
88 /* 32 bit for SCSI ID and LUN as long as the SCSI stack uses this type */
89 typedef u32 scsi_id_t;
90 typedef u32 scsi_lun_t;
91
92 #define ZFCP_ERP_SCSI_LOW_MEM_TIMEOUT           (100*HZ)
93 #define ZFCP_SCSI_ER_TIMEOUT                    (100*HZ)
94
95 /********************* CIO/QDIO SPECIFIC DEFINES *****************************/
96
97 /* Adapter Identification Parameters */
98 #define ZFCP_CONTROL_UNIT_TYPE  0x1731
99 #define ZFCP_CONTROL_UNIT_MODEL 0x03
100 #define ZFCP_DEVICE_TYPE        0x1732
101 #define ZFCP_DEVICE_MODEL       0x03
102 #define ZFCP_DEVICE_MODEL_PRIV  0x04
103  
104 /* allow as many chained SBALs as are supported by hardware */
105 #define ZFCP_MAX_SBALS_PER_REQ          FSF_MAX_SBALS_PER_REQ
106 #define ZFCP_MAX_SBALS_PER_CT_REQ       FSF_MAX_SBALS_PER_REQ
107 #define ZFCP_MAX_SBALS_PER_ELS_REQ      FSF_MAX_SBALS_PER_ELS_REQ
108
109 /* DMQ bug workaround: don't use last SBALE */
110 #define ZFCP_MAX_SBALES_PER_SBAL        (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
111
112 /* index of last SBALE (with respect to DMQ bug workaround) */
113 #define ZFCP_LAST_SBALE_PER_SBAL        (ZFCP_MAX_SBALES_PER_SBAL - 1)
114
115 /* max. number of (data buffer) SBALEs in largest SBAL chain */
116 #define ZFCP_MAX_SBALES_PER_REQ         \
117         (ZFCP_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
118         /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
119
120 /* FIXME(tune): free space should be one max. SBAL chain plus what? */
121 #define ZFCP_QDIO_PCI_INTERVAL          (QDIO_MAX_BUFFERS_PER_Q \
122                                          - (ZFCP_MAX_SBALS_PER_REQ + 4))
123
124 #define ZFCP_SBAL_TIMEOUT               (5*HZ)
125
126 #define ZFCP_TYPE2_RECOVERY_TIME        (8*HZ)
127
128 /* queue polling (values in microseconds) */
129 #define ZFCP_MAX_INPUT_THRESHOLD        5000    /* FIXME: tune */
130 #define ZFCP_MAX_OUTPUT_THRESHOLD       1000    /* FIXME: tune */
131 #define ZFCP_MIN_INPUT_THRESHOLD        1       /* ignored by QDIO layer */
132 #define ZFCP_MIN_OUTPUT_THRESHOLD       1       /* ignored by QDIO layer */
133
134 #define QDIO_SCSI_QFMT                  1       /* 1 for FSF */
135
136 /********************* FSF SPECIFIC DEFINES *********************************/
137
138 #define ZFCP_ULP_INFO_VERSION                   26
139 #define ZFCP_QTCB_VERSION       FSF_QTCB_CURRENT_VERSION
140 /* ATTENTION: value must not be used by hardware */
141 #define FSF_QTCB_UNSOLICITED_STATUS             0x6305
142 #define ZFCP_STATUS_READ_FAILED_THRESHOLD       3
143 #define ZFCP_STATUS_READS_RECOM                 FSF_STATUS_READS_RECOM
144 #define ZFCP_EXCHANGE_CONFIG_DATA_RETRIES       6
145 #define ZFCP_EXCHANGE_CONFIG_DATA_SLEEP         50
146
147 /*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
148
149 typedef unsigned long long wwn_t;
150 typedef unsigned int       fc_id_t;
151 typedef unsigned long long fcp_lun_t;
152 /* data length field may be at variable position in FCP-2 FCP_CMND IU */
153 typedef unsigned int       fcp_dl_t;
154
155 #define ZFCP_FC_SERVICE_CLASS_DEFAULT   FSF_CLASS_3
156
157 /* timeout for name-server lookup (in seconds) */
158 #define ZFCP_NS_GID_PN_TIMEOUT          10
159 #define ZFCP_NS_GA_NXT_TIMEOUT          120
160
161 /* largest SCSI command we can process */
162 /* FCP-2 (FCP_CMND IU) allows up to (255-3+16) */
163 #define ZFCP_MAX_SCSI_CMND_LENGTH       255
164 /* maximum number of commands in LUN queue (tagged queueing) */
165 #define ZFCP_CMND_PER_LUN               32
166
167 /* task attribute values in FCP-2 FCP_CMND IU */
168 #define SIMPLE_Q        0
169 #define HEAD_OF_Q       1
170 #define ORDERED_Q       2
171 #define ACA_Q           4
172 #define UNTAGGED        5
173
174 /* task management flags in FCP-2 FCP_CMND IU */
175 #define CLEAR_ACA               0x40
176 #define TARGET_RESET            0x20
177 #define LOGICAL_UNIT_RESET      0x10
178 #define CLEAR_TASK_SET          0x04
179 #define ABORT_TASK_SET          0x02
180
181 #define FCP_CDB_LENGTH          16
182
183 #define ZFCP_DID_MASK           0x00FFFFFF
184
185 /* FCP(-2) FCP_CMND IU */
186 struct fcp_cmnd_iu {
187         fcp_lun_t fcp_lun;         /* FCP logical unit number */
188         u8  crn;                   /* command reference number */
189         u8  reserved0:5;           /* reserved */
190         u8  task_attribute:3;      /* task attribute */
191         u8  task_management_flags; /* task management flags */
192         u8  add_fcp_cdb_length:6;  /* additional FCP_CDB length */
193         u8  rddata:1;              /* read data */
194         u8  wddata:1;              /* write data */
195         u8  fcp_cdb[FCP_CDB_LENGTH];
196 } __attribute__((packed));
197
198 /* FCP(-2) FCP_RSP IU */
199 struct fcp_rsp_iu {
200         u8  reserved0[10];
201         union {
202                 struct {
203                         u8 reserved1:3;
204                         u8 fcp_conf_req:1;
205                         u8 fcp_resid_under:1;
206                         u8 fcp_resid_over:1;
207                         u8 fcp_sns_len_valid:1;
208                         u8 fcp_rsp_len_valid:1;
209                 } bits;
210                 u8 value;
211         } validity;
212         u8  scsi_status;
213         u32 fcp_resid;
214         u32 fcp_sns_len;
215         u32 fcp_rsp_len;
216 } __attribute__((packed));
217
218
219 #define RSP_CODE_GOOD            0
220 #define RSP_CODE_LENGTH_MISMATCH 1
221 #define RSP_CODE_FIELD_INVALID   2
222 #define RSP_CODE_RO_MISMATCH     3
223 #define RSP_CODE_TASKMAN_UNSUPP  4
224 #define RSP_CODE_TASKMAN_FAILED  5
225
226 /* see fc-fs */
227 #define LS_FAN 0x60000000
228 #define LS_RSCN 0x61040000
229
230 struct fcp_rscn_head {
231         u8  command;
232         u8  page_length; /* always 0x04 */
233         u16 payload_len;
234 } __attribute__((packed));
235
236 struct fcp_rscn_element {
237         u8  reserved:2;
238         u8  event_qual:4;
239         u8  addr_format:2;
240         u32 nport_did:24;
241 } __attribute__((packed));
242
243 #define ZFCP_PORT_ADDRESS   0x0
244 #define ZFCP_AREA_ADDRESS   0x1
245 #define ZFCP_DOMAIN_ADDRESS 0x2
246 #define ZFCP_FABRIC_ADDRESS 0x3
247
248 #define ZFCP_PORTS_RANGE_PORT   0xFFFFFF
249 #define ZFCP_PORTS_RANGE_AREA   0xFFFF00
250 #define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
251 #define ZFCP_PORTS_RANGE_FABRIC 0x000000
252
253 #define ZFCP_NO_PORTS_PER_AREA    0x100
254 #define ZFCP_NO_PORTS_PER_DOMAIN  0x10000
255 #define ZFCP_NO_PORTS_PER_FABRIC  0x1000000
256
257 struct fcp_fan {
258         u32 command;
259         u32 fport_did;
260         wwn_t fport_wwpn;
261         wwn_t fport_wwname;
262 } __attribute__((packed));
263
264 /* see fc-ph */
265 struct fcp_logo {
266         u32 command;
267         u32 nport_did;
268         wwn_t nport_wwpn;
269 } __attribute__((packed));
270
271 /*
272  * FC-FS stuff
273  */
274 #define R_A_TOV                         10 /* seconds */
275 #define ZFCP_ELS_TIMEOUT                (2 * R_A_TOV)
276
277 #define ZFCP_LS_RJT                     0x01
278 #define ZFCP_LS_ACC                     0x02
279 #define ZFCP_LS_RTV                     0x0E
280 #define ZFCP_LS_RLS                     0x0F
281 #define ZFCP_LS_PDISC                   0x50
282 #define ZFCP_LS_ADISC                   0x52
283 #define ZFCP_LS_RSCN                    0x61
284 #define ZFCP_LS_RNID                    0x78
285 #define ZFCP_LS_RLIR                    0x7A
286 #define ZFCP_LS_RTV_E_D_TOV_FLAG        0x04000000
287
288 /* LS_ACC Reason Codes */
289 #define ZFCP_LS_RJT_INVALID_COMMAND_CODE        0x01
290 #define ZFCP_LS_RJT_LOGICAL_ERROR               0x03
291 #define ZFCP_LS_RJT_LOGICAL_BUSY                0x05
292 #define ZFCP_LS_RJT_PROTOCOL_ERROR              0x07
293 #define ZFCP_LS_RJT_UNABLE_TO_PERFORM           0x09
294 #define ZFCP_LS_RJT_COMMAND_NOT_SUPPORTED       0x0B
295 #define ZFCP_LS_RJT_VENDOR_UNIQUE_ERROR         0xFF
296
297 struct zfcp_ls_rjt {
298         u8              code;
299         u8              field[3];
300         u8              reserved;
301         u8      reason_code;
302         u8              reason_expl;
303         u8      vendor_unique;
304 } __attribute__ ((packed));
305
306 struct zfcp_ls_rtv {
307         u8              code;
308         u8              field[3];
309 } __attribute__ ((packed));
310
311 struct zfcp_ls_rtv_acc {
312         u8              code;
313         u8              field[3];
314         u32             r_a_tov;
315         u32             e_d_tov;
316         u32             qualifier;
317 } __attribute__ ((packed));
318
319 struct zfcp_ls_rls {
320         u8              code;
321         u8              field[3];
322         fc_id_t         port_id;
323 } __attribute__ ((packed));
324
325 struct zfcp_ls_rls_acc {
326         u8              code;
327         u8              field[3];
328         u32             link_failure_count;
329         u32             loss_of_sync_count;
330         u32             loss_of_signal_count;
331         u32             prim_seq_prot_error;
332         u32             invalid_transmition_word;
333         u32             invalid_crc_count;
334 } __attribute__ ((packed));
335
336 struct zfcp_ls_pdisc {
337         u8              code;
338         u8              field[3];
339         u8              common_svc_parm[16];
340                 wwn_t   wwpn;
341         wwn_t           wwnn;
342         struct {
343                 u8      class1[16];
344                 u8      class2[16];
345                 u8      class3[16];
346         } svc_parm;
347         u8              reserved[16];
348         u8              vendor_version[16];
349 } __attribute__ ((packed));
350
351 struct zfcp_ls_pdisc_acc {
352         u8              code;
353         u8              field[3];
354         u8              common_svc_parm[16];
355         wwn_t           wwpn;
356         wwn_t           wwnn;
357         struct {
358                 u8      class1[16];
359                 u8      class2[16];
360                 u8      class3[16];
361         } svc_parm;
362         u8              reserved[16];
363         u8              vendor_version[16];
364 } __attribute__ ((packed));
365
366 struct zfcp_ls_adisc {
367         u8              code;
368         u8              field[3];
369         fc_id_t         hard_nport_id;
370         wwn_t           wwpn;
371         wwn_t           wwnn;
372         fc_id_t         nport_id;
373 } __attribute__ ((packed));
374
375 struct zfcp_ls_adisc_acc {
376         u8              code;
377         u8              field[3];
378         fc_id_t         hard_nport_id;
379         wwn_t           wwpn;
380         wwn_t           wwnn;
381         fc_id_t         nport_id;
382 } __attribute__ ((packed));
383
384 struct zfcp_ls_rnid {
385         u8              code;
386         u8              field[3];
387         u8              node_id_format;
388         u8              reserved[3];
389 } __attribute__((packed));
390
391 /* common identification data */
392 struct zfcp_ls_rnid_common_id {
393         u64             n_port_name;
394         u64             node_name;
395 } __attribute__((packed));
396
397 /* general topology specific identification data */
398 struct zfcp_ls_rnid_general_topology_id {
399         u8              vendor_unique[16];
400         u32             associated_type;
401         u32             physical_port_number;
402         u32             nr_attached_nodes;
403         u8              node_management;
404         u8              ip_version;
405         u16             port_number;
406         u8              ip_address[16];
407         u8              reserved[2];
408         u16             vendor_specific;
409 } __attribute__((packed));
410
411 struct zfcp_ls_rnid_acc {
412         u8              code;
413         u8              field[3];
414         u8              node_id_format;
415         u8              common_id_length;
416         u8              reserved;
417         u8              specific_id_length;
418         struct zfcp_ls_rnid_common_id
419                         common_id;
420         struct zfcp_ls_rnid_general_topology_id
421                         specific_id;
422 } __attribute__((packed));
423
424 /*
425  * FC-GS-2 stuff
426  */
427 #define ZFCP_CT_REVISION                0x01
428 #define ZFCP_CT_DIRECTORY_SERVICE       0xFC
429 #define ZFCP_CT_NAME_SERVER             0x02
430 #define ZFCP_CT_SYNCHRONOUS             0x00
431 #define ZFCP_CT_GID_PN                  0x0121
432 #define ZFCP_CT_GA_NXT                  0x0100
433 #define ZFCP_CT_MAX_SIZE                0x1020
434 #define ZFCP_CT_ACCEPT                  0x8002
435
436 /*
437  * FC-GS-4 stuff
438  */
439 #define ZFCP_CT_TIMEOUT                 (3 * R_A_TOV)
440
441
442 /***************** S390 DEBUG FEATURE SPECIFIC DEFINES ***********************/
443
444 /* debug feature entries per adapter */
445 #define ZFCP_ERP_DBF_INDEX     1 
446 #define ZFCP_ERP_DBF_AREAS     2
447 #define ZFCP_ERP_DBF_LENGTH    16
448 #define ZFCP_ERP_DBF_LEVEL     3
449 #define ZFCP_ERP_DBF_NAME      "zfcperp"
450
451 #define ZFCP_CMD_DBF_INDEX     2
452 #define ZFCP_CMD_DBF_AREAS     1
453 #define ZFCP_CMD_DBF_LENGTH    8
454 #define ZFCP_CMD_DBF_LEVEL     3
455 #define ZFCP_CMD_DBF_NAME      "zfcpcmd"
456
457 #define ZFCP_ABORT_DBF_INDEX   2
458 #define ZFCP_ABORT_DBF_AREAS   1
459 #define ZFCP_ABORT_DBF_LENGTH  8
460 #define ZFCP_ABORT_DBF_LEVEL   6
461 #define ZFCP_ABORT_DBF_NAME    "zfcpabt"
462
463 #define ZFCP_IN_ELS_DBF_INDEX  2
464 #define ZFCP_IN_ELS_DBF_AREAS  1
465 #define ZFCP_IN_ELS_DBF_LENGTH 8
466 #define ZFCP_IN_ELS_DBF_LEVEL  6
467 #define ZFCP_IN_ELS_DBF_NAME   "zfcpels"
468
469 /******************** LOGGING MACROS AND DEFINES *****************************/
470
471 /*
472  * Logging may be applied on certain kinds of driver operations
473  * independently. Additionally, different log-levels are supported for
474  * each of these areas.
475  */
476
477 #define ZFCP_NAME               "zfcp"
478
479 /* independent log areas */
480 #define ZFCP_LOG_AREA_OTHER     0
481 #define ZFCP_LOG_AREA_SCSI      1
482 #define ZFCP_LOG_AREA_FSF       2
483 #define ZFCP_LOG_AREA_CONFIG    3
484 #define ZFCP_LOG_AREA_CIO       4
485 #define ZFCP_LOG_AREA_QDIO      5
486 #define ZFCP_LOG_AREA_ERP       6
487 #define ZFCP_LOG_AREA_FC        7
488
489 /* log level values*/
490 #define ZFCP_LOG_LEVEL_NORMAL   0
491 #define ZFCP_LOG_LEVEL_INFO     1
492 #define ZFCP_LOG_LEVEL_DEBUG    2
493 #define ZFCP_LOG_LEVEL_TRACE    3
494
495 /*
496  * this allows removal of logging code by the preprocessor
497  * (the most detailed log level still to be compiled in is specified, 
498  * higher log levels are removed)
499  */
500 #define ZFCP_LOG_LEVEL_LIMIT    ZFCP_LOG_LEVEL_TRACE
501
502 /* get "loglevel" nibble assignment */
503 #define ZFCP_GET_LOG_VALUE(zfcp_lognibble) \
504                ((atomic_read(&zfcp_data.loglevel) >> (zfcp_lognibble<<2)) & 0xF)
505
506 /* set "loglevel" nibble */
507 #define ZFCP_SET_LOG_NIBBLE(value, zfcp_lognibble) \
508                (value << (zfcp_lognibble << 2))
509
510 /* all log-level defaults are combined to generate initial log-level */
511 #define ZFCP_LOG_LEVEL_DEFAULTS \
512         (ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_INFO, ZFCP_LOG_AREA_OTHER) | \
513          ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_INFO, ZFCP_LOG_AREA_SCSI) | \
514          ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_INFO, ZFCP_LOG_AREA_FSF) | \
515          ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_INFO, ZFCP_LOG_AREA_CONFIG) | \
516          ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_INFO, ZFCP_LOG_AREA_CIO) | \
517          ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_INFO, ZFCP_LOG_AREA_QDIO) | \
518          ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_INFO, ZFCP_LOG_AREA_ERP) | \
519          ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_INFO, ZFCP_LOG_AREA_FC))
520
521 /* check whether we have the right level for logging */
522 #define ZFCP_LOG_CHECK(level) \
523         ((ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA)) >= level)
524
525 /* logging routine for zfcp */
526 #define _ZFCP_LOG(fmt, args...) \
527         printk(KERN_ERR ZFCP_NAME": %s(%d): " fmt, __FUNCTION__, \
528                __LINE__ , ##args);
529
530 #define ZFCP_LOG(level, fmt, args...) \
531         if (ZFCP_LOG_CHECK(level)) \
532                 _ZFCP_LOG(fmt , ##args)
533         
534 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_NORMAL
535 # define ZFCP_LOG_NORMAL(fmt, args...)
536 #else
537 # define ZFCP_LOG_NORMAL(fmt, args...) \
538         if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_NORMAL)) \
539                 printk(KERN_ERR ZFCP_NAME": " fmt , ##args);
540 #endif
541
542 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_INFO
543 # define ZFCP_LOG_INFO(fmt, args...)
544 #else
545 # define ZFCP_LOG_INFO(fmt, args...) \
546         if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_INFO)) \
547                 printk(KERN_ERR ZFCP_NAME": " fmt , ##args);
548 #endif
549
550 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_DEBUG
551 # define ZFCP_LOG_DEBUG(fmt, args...)
552 #else
553 # define ZFCP_LOG_DEBUG(fmt, args...) \
554         ZFCP_LOG(ZFCP_LOG_LEVEL_DEBUG, fmt , ##args)
555 #endif
556
557 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_TRACE
558 # define ZFCP_LOG_TRACE(fmt, args...)
559 #else
560 # define ZFCP_LOG_TRACE(fmt, args...) \
561         ZFCP_LOG(ZFCP_LOG_LEVEL_TRACE, fmt , ##args)
562 #endif
563
564 #ifndef ZFCP_PRINT_FLAGS
565 # define ZFCP_LOG_FLAGS(level, fmt, args...)
566 #else
567 extern u32 flags_dump;
568 # define ZFCP_LOG_FLAGS(level, fmt, args...) \
569         if (level <= flags_dump) \
570                 _ZFCP_LOG(fmt , ##args)
571 #endif
572
573 /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
574
575 /* 
576  * Note, the leftmost status byte is common among adapter, port 
577  * and unit
578  */
579 #define ZFCP_COMMON_FLAGS                       0xff000000
580 #define ZFCP_SPECIFIC_FLAGS                     0x00ffffff
581
582 /* common status bits */
583 #define ZFCP_STATUS_COMMON_REMOVE               0x80000000
584 #define ZFCP_STATUS_COMMON_RUNNING              0x40000000
585 #define ZFCP_STATUS_COMMON_ERP_FAILED           0x20000000
586 #define ZFCP_STATUS_COMMON_UNBLOCKED            0x10000000
587 #define ZFCP_STATUS_COMMON_OPENING              0x08000000
588 #define ZFCP_STATUS_COMMON_OPEN                 0x04000000
589 #define ZFCP_STATUS_COMMON_CLOSING              0x02000000
590 #define ZFCP_STATUS_COMMON_ERP_INUSE            0x01000000
591
592 /* adapter status */
593 #define ZFCP_STATUS_ADAPTER_QDIOUP              0x00000002
594 #define ZFCP_STATUS_ADAPTER_REGISTERED          0x00000004
595 #define ZFCP_STATUS_ADAPTER_XCONFIG_OK          0x00000008
596 #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT       0x00000010
597 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP       0x00000020
598 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL     0x00000080
599 #define ZFCP_STATUS_ADAPTER_ERP_PENDING         0x00000100
600 #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED      0x00000200
601
602 #define ZFCP_STATUS_ADAPTER_SCSI_UP                     \
603                 (ZFCP_STATUS_COMMON_UNBLOCKED | \
604                  ZFCP_STATUS_ADAPTER_REGISTERED)
605
606
607 #define ZFCP_DID_NAMESERVER                     0xFFFFFC
608
609 /* remote port status */
610 #define ZFCP_STATUS_PORT_PHYS_OPEN              0x00000001
611 #define ZFCP_STATUS_PORT_DID_DID                0x00000002
612 #define ZFCP_STATUS_PORT_PHYS_CLOSING           0x00000004
613 #define ZFCP_STATUS_PORT_NO_WWPN                0x00000008
614 #define ZFCP_STATUS_PORT_NO_SCSI_ID             0x00000010
615 #define ZFCP_STATUS_PORT_INVALID_WWPN           0x00000020
616
617 #define ZFCP_STATUS_PORT_NAMESERVER \
618                 (ZFCP_STATUS_PORT_NO_WWPN | \
619                  ZFCP_STATUS_PORT_NO_SCSI_ID)
620
621 /* logical unit status */
622 #define ZFCP_STATUS_UNIT_NOTSUPPUNITRESET       0x00000001
623
624
625 /* FSF request status (this does not have a common part) */
626 #define ZFCP_STATUS_FSFREQ_NOT_INIT             0x00000000
627 #define ZFCP_STATUS_FSFREQ_POOL                 0x00000001
628 #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT      0x00000002
629 #define ZFCP_STATUS_FSFREQ_COMPLETED            0x00000004
630 #define ZFCP_STATUS_FSFREQ_ERROR                0x00000008
631 #define ZFCP_STATUS_FSFREQ_CLEANUP              0x00000010
632 #define ZFCP_STATUS_FSFREQ_ABORTING             0x00000020
633 #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED       0x00000040
634 #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED       0x00000080
635 #define ZFCP_STATUS_FSFREQ_ABORTED              0x00000100
636 #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED         0x00000200
637 #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP        0x00000400
638 #define ZFCP_STATUS_FSFREQ_RETRY                0x00000800
639 #define ZFCP_STATUS_FSFREQ_DISMISSED            0x00001000
640
641 /*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
642
643 #define ZFCP_MAX_ERPS                   3
644
645 #define ZFCP_ERP_FSFREQ_TIMEOUT         (30 * HZ)
646 #define ZFCP_ERP_MEMWAIT_TIMEOUT        HZ
647
648 #define ZFCP_STATUS_ERP_TIMEDOUT        0x10000000
649 #define ZFCP_STATUS_ERP_CLOSE_ONLY      0x01000000
650 #define ZFCP_STATUS_ERP_DISMISSING      0x00100000
651 #define ZFCP_STATUS_ERP_DISMISSED       0x00200000
652 #define ZFCP_STATUS_ERP_LOWMEM          0x00400000
653
654 #define ZFCP_ERP_STEP_UNINITIALIZED     0x00000000
655 #define ZFCP_ERP_STEP_FSF_XCONFIG       0x00000001
656 #define ZFCP_ERP_STEP_PHYS_PORT_CLOSING 0x00000010
657 #define ZFCP_ERP_STEP_PORT_CLOSING      0x00000100
658 #define ZFCP_ERP_STEP_NAMESERVER_OPEN   0x00000200
659 #define ZFCP_ERP_STEP_NAMESERVER_LOOKUP 0x00000400
660 #define ZFCP_ERP_STEP_PORT_OPENING      0x00000800
661 #define ZFCP_ERP_STEP_UNIT_CLOSING      0x00001000
662 #define ZFCP_ERP_STEP_UNIT_OPENING      0x00002000
663
664 /* Ordered by escalation level (necessary for proper erp-code operation) */
665 #define ZFCP_ERP_ACTION_REOPEN_ADAPTER          0x4
666 #define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED      0x3
667 #define ZFCP_ERP_ACTION_REOPEN_PORT             0x2
668 #define ZFCP_ERP_ACTION_REOPEN_UNIT             0x1
669
670 #define ZFCP_ERP_ACTION_RUNNING                 0x1
671 #define ZFCP_ERP_ACTION_READY                   0x2
672
673 #define ZFCP_ERP_SUCCEEDED      0x0
674 #define ZFCP_ERP_FAILED         0x1
675 #define ZFCP_ERP_CONTINUES      0x2
676 #define ZFCP_ERP_EXIT           0x3
677 #define ZFCP_ERP_DISMISSED      0x4
678 #define ZFCP_ERP_NOMEM          0x5
679
680
681 /******************** CFDC SPECIFIC STUFF *****************************/
682
683 /* Firewall data channel sense data record */
684 struct zfcp_cfdc_sense_data {
685         u32 signature;           /* Request signature */
686         u32 devno;               /* FCP adapter device number */
687         u32 command;             /* Command code */
688         u32 fsf_status;          /* FSF request status and status qualifier */
689         u8  fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
690         u8  payloads[256];       /* Access conflicts list */
691         u8  control_file[0];     /* Access control table */
692 };
693
694 #define ZFCP_CFDC_SIGNATURE                     0xCFDCACDF
695
696 #define ZFCP_CFDC_CMND_DOWNLOAD_NORMAL          0x00010001
697 #define ZFCP_CFDC_CMND_DOWNLOAD_FORCE           0x00010101
698 #define ZFCP_CFDC_CMND_FULL_ACCESS              0x00000201
699 #define ZFCP_CFDC_CMND_RESTRICTED_ACCESS        0x00000401
700 #define ZFCP_CFDC_CMND_UPLOAD                   0x00010002
701
702 #define ZFCP_CFDC_DOWNLOAD                      0x00000001
703 #define ZFCP_CFDC_UPLOAD                        0x00000002
704 #define ZFCP_CFDC_WITH_CONTROL_FILE             0x00010000
705
706 #define ZFCP_CFDC_DEV_NAME                      "zfcp_cfdc"
707 #define ZFCP_CFDC_DEV_MAJOR                     MISC_MAJOR
708 #define ZFCP_CFDC_DEV_MINOR                     MISC_DYNAMIC_MINOR
709
710 #define ZFCP_CFDC_MAX_CONTROL_FILE_SIZE         127 * 1024
711
712 /************************* STRUCTURE DEFINITIONS *****************************/
713
714 struct zfcp_fsf_req;
715
716 /* holds various memory pools of an adapter */
717 struct zfcp_adapter_mempool {
718         mempool_t *fsf_req_erp;
719         mempool_t *fsf_req_scsi;
720         mempool_t *fsf_req_abort;
721         mempool_t *fsf_req_status_read;
722         mempool_t *data_status_read;
723         mempool_t *data_gid_pn;
724 };
725
726 struct  zfcp_exchange_config_data{
727 };
728
729 struct zfcp_open_port {
730         struct zfcp_port *port;
731 };
732
733 struct zfcp_close_port {
734         struct zfcp_port *port;
735 };
736
737 struct zfcp_open_unit {
738         struct zfcp_unit *unit;
739 };
740
741 struct zfcp_close_unit {
742         struct zfcp_unit *unit;
743 };
744
745 struct zfcp_close_physical_port {
746         struct zfcp_port *port;
747 };
748
749 struct zfcp_send_fcp_command_task {
750         struct zfcp_fsf_req *fsf_req;
751         struct zfcp_unit *unit;
752         struct scsi_cmnd *scsi_cmnd;
753         unsigned long start_jiffies;
754 };
755
756 struct zfcp_send_fcp_command_task_management {
757         struct zfcp_unit *unit;
758 };
759
760 struct zfcp_abort_fcp_command {
761         struct zfcp_fsf_req *fsf_req;
762         struct zfcp_unit *unit;
763 };
764
765 /*
766  * header for CT_IU
767  */
768 struct ct_hdr {
769         u8 revision;            // 0x01
770         u8 in_id[3];            // 0x00
771         u8 gs_type;             // 0xFC Directory Service
772         u8 gs_subtype;          // 0x02 Name Server
773         u8 options;             // 0x00 single bidirectional exchange
774         u8 reserved0;
775         u16 cmd_rsp_code;       // 0x0121 GID_PN, or 0x0100 GA_NXT
776         u16 max_res_size;       // <= (4096 - 16) / 4
777         u8 reserved1;
778         u8 reason_code;
779         u8 reason_code_expl;
780         u8 vendor_unique;
781 } __attribute__ ((packed));
782
783 /* nameserver request CT_IU -- for requests where
784  * a port name is required */
785 struct ct_iu_gid_pn_req {
786         struct ct_hdr header;
787         wwn_t wwpn;
788 } __attribute__ ((packed));
789
790 /* nameserver request CT_IU -- for requests where
791  * a port identifier is required */
792 struct ct_iu_ga_nxt_req {
793         struct ct_hdr header;
794         fc_id_t d_id;
795 } __attribute__ ((packed));
796
797 /* FS_ACC IU and data unit for GID_PN nameserver request */
798 struct ct_iu_gid_pn_resp {
799         struct ct_hdr header;
800         fc_id_t d_id;
801 } __attribute__ ((packed));
802
803 /* FS_ACC IU and data unit for GA_NXT nameserver request */
804 struct ct_iu_ga_nxt_resp {
805         struct ct_hdr header;
806         u8 port_type;
807         u8 port_id[3];
808         u64 port_wwn;
809         u8 port_symbolic_name_length;
810         u8 port_symbolic_name[255];
811         u64 node_wwn;
812         u8 node_symbolic_name_length;
813         u8 node_symbolic_name[255];
814         u64 initial_process_associator;
815         u8 node_ip[16];
816         u32 cos;
817         u8 fc4_types[32];
818         u8 port_ip[16];
819         u64 fabric_wwn;
820         u8 reserved;
821         u8 hard_address[3];
822 } __attribute__ ((packed));
823
824 typedef void (*zfcp_send_ct_handler_t)(unsigned long);
825
826 /* used to pass parameters to zfcp_send_ct() */
827 struct zfcp_send_ct {
828         struct zfcp_port *port;
829         struct scatterlist *req;
830         struct scatterlist *resp;
831         unsigned int req_count;
832         unsigned int resp_count;
833         zfcp_send_ct_handler_t handler;
834         unsigned long handler_data;
835         mempool_t *pool;                /* mempool for ct not for fsf_req */
836         int timeout;
837         struct timer_list *timer;
838         struct completion *completion;
839         int status;
840 };
841
842 /* used for name server requests in error recovery */
843 struct zfcp_gid_pn_data {
844         struct zfcp_send_ct ct;
845         struct scatterlist req;
846         struct scatterlist resp;
847         struct ct_iu_gid_pn_req ct_iu_req;
848         struct ct_iu_gid_pn_resp ct_iu_resp;
849         struct zfcp_port *port;
850 };
851
852 typedef int (*zfcp_send_els_handler_t)(unsigned long);
853
854 /* used to pass parameters to zfcp_send_els() */
855 /* ToDo merge send_ct() and send_els() and corresponding structs */
856 struct zfcp_send_els {
857         struct zfcp_port *port;
858         struct scatterlist *req;
859         struct scatterlist *resp;
860         unsigned int req_count;
861         unsigned int resp_count;
862         zfcp_send_els_handler_t handler;
863         unsigned long handler_data;
864         struct completion *completion;
865         int ls_code;
866         int status;
867 };
868
869 struct zfcp_status_read {
870         struct fsf_status_read_buffer *buffer;
871 };
872
873 struct zfcp_fsf_done {
874         struct completion *complete;
875         int status;
876 };
877
878 /* request specific data */
879 union zfcp_req_data {
880         struct zfcp_exchange_config_data exchange_config_data;
881         struct zfcp_open_port             open_port;
882         struct zfcp_close_port            close_port;
883         struct zfcp_open_unit             open_unit;
884         struct zfcp_close_unit            close_unit;
885         struct zfcp_close_physical_port   close_physical_port;
886         struct zfcp_send_fcp_command_task send_fcp_command_task;
887         struct zfcp_send_fcp_command_task_management
888                                           send_fcp_command_task_management;
889         struct zfcp_abort_fcp_command     abort_fcp_command;
890         struct zfcp_send_ct *send_ct;
891         struct zfcp_send_els *send_els;
892         struct zfcp_status_read           status_read;
893 };
894
895 struct zfcp_qdio_queue {
896         struct qdio_buffer *buffer[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
897         u8                 free_index;        /* index of next free bfr
898                                                  in queue (free_count>0) */
899         atomic_t           free_count;        /* number of free buffers
900                                                  in queue */
901         rwlock_t           queue_lock;        /* lock for operations on queue */
902         int                distance_from_int; /* SBALs used since PCI indication
903                                                  was last set */
904 };
905
906 struct zfcp_erp_action {
907         struct list_head list;
908         int action;                   /* requested action code */
909         struct zfcp_adapter *adapter; /* device which should be recovered */
910         struct zfcp_port *port;
911         struct zfcp_unit *unit;
912         volatile u32 status;          /* recovery status */
913         u32 step;                     /* active step of this erp action */
914         struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
915                                          for this action */
916         struct timer_list timer;
917 };
918
919
920 struct zfcp_adapter {
921         struct list_head        list;              /* list of adapters */
922         atomic_t                refcount;          /* reference count */
923         wait_queue_head_t       remove_wq;         /* can be used to wait for
924                                                       refcount drop to zero */
925         wwn_t                   wwnn;              /* WWNN */
926         wwn_t                   wwpn;              /* WWPN */
927         fc_id_t                 s_id;              /* N_Port ID */
928         struct ccw_device       *ccw_device;       /* S/390 ccw device */
929         u8                      fc_service_class;
930         u32                     fc_topology;       /* FC topology */
931         u32                     fc_link_speed;     /* FC interface speed */
932         u32                     hydra_version;     /* Hydra version */
933         u32                     fsf_lic_version;
934         u32                     supported_features;/* of FCP channel */
935         u32                     hardware_version;  /* of FCP channel */
936         u8                      serial_number[32]; /* of hardware */
937         struct Scsi_Host        *scsi_host;        /* Pointer to mid-layer */
938         unsigned short          scsi_host_no;      /* Assigned host number */
939         unsigned char           name[9];
940         struct list_head        port_list_head;    /* remote port list */
941         struct list_head        port_remove_lh;    /* head of ports to be
942                                                       removed */
943         u32                     ports;             /* number of remote ports */
944         struct timer_list       scsi_er_timer;     /* SCSI err recovery watch */
945         struct list_head        fsf_req_list_head; /* head of FSF req list */
946         rwlock_t                fsf_req_list_lock; /* lock for ops on list of
947                                                       FSF requests */
948         atomic_t                fsf_reqs_active;   /* # active FSF reqs */
949         struct zfcp_qdio_queue  request_queue;     /* request queue */
950         u32                     fsf_req_seq_no;    /* FSF cmnd seq number */
951         wait_queue_head_t       request_wq;        /* can be used to wait for
952                                                       more avaliable SBALs */
953         struct zfcp_qdio_queue  response_queue;    /* response queue */
954         rwlock_t                abort_lock;        /* Protects against SCSI
955                                                       stack abort/command
956                                                       completion races */
957         u16                     status_read_failed; /* # failed status reads */
958         atomic_t                status;            /* status of this adapter */
959         struct list_head        erp_ready_head;    /* error recovery for this
960                                                       adapter/devices */
961         struct list_head        erp_running_head;
962         rwlock_t                erp_lock;
963         struct semaphore        erp_ready_sem;
964         wait_queue_head_t       erp_thread_wqh;
965         wait_queue_head_t       erp_done_wqh;
966         struct zfcp_erp_action  erp_action;        /* pending error recovery */
967         atomic_t                erp_counter;
968         u32                     erp_total_count;   /* total nr of enqueued erp
969                                                       actions */
970         u32                     erp_low_mem_count; /* nr of erp actions waiting
971                                                       for memory */
972         struct zfcp_port        *nameserver_port;  /* adapter's nameserver */
973         debug_info_t            *erp_dbf;          /* S/390 debug features */
974         debug_info_t            *abort_dbf;
975         debug_info_t            *in_els_dbf;
976         debug_info_t            *cmd_dbf;
977         rwlock_t                cmd_dbf_lock;
978         struct zfcp_adapter_mempool     pool;      /* Adapter memory pools */
979         struct qdio_initialize  qdio_init_data;    /* for qdio_establish */
980 };
981
982 /*
983  * the struct device sysfs_device must be at the beginning of this structure.
984  * pointer to struct device is used to free port structure in release function
985  * of the device. don't change!
986  */
987 struct zfcp_port {
988         struct device          sysfs_device;   /* sysfs device */
989         struct list_head       list;           /* list of remote ports */
990         atomic_t               refcount;       /* reference count */
991         wait_queue_head_t      remove_wq;      /* can be used to wait for
992                                                   refcount drop to zero */
993         struct zfcp_adapter    *adapter;       /* adapter used to access port */
994         struct list_head       unit_list_head; /* head of logical unit list */
995         struct list_head       unit_remove_lh; /* head of luns to be removed
996                                                   list */
997         u32                    units;          /* # of logical units in list */
998         atomic_t               status;         /* status of this remote port */
999         scsi_id_t              scsi_id;        /* own SCSI ID */
1000         wwn_t                  wwnn;           /* WWNN if known */
1001         wwn_t                  wwpn;           /* WWPN */
1002         fc_id_t                d_id;           /* D_ID */
1003         u32                    handle;         /* handle assigned by FSF */
1004         struct zfcp_erp_action erp_action;     /* pending error recovery */
1005         atomic_t               erp_counter;
1006 };
1007
1008 /* the struct device sysfs_device must be at the beginning of this structure.
1009  * pointer to struct device is used to free unit structure in release function
1010  * of the device. don't change!
1011  */
1012 struct zfcp_unit {
1013         struct device          sysfs_device;   /* sysfs device */
1014         struct list_head       list;           /* list of logical units */
1015         atomic_t               refcount;       /* reference count */
1016         wait_queue_head_t      remove_wq;      /* can be used to wait for
1017                                                   refcount drop to zero */
1018         struct zfcp_port       *port;          /* remote port of unit */
1019         atomic_t               status;         /* status of this logical unit */
1020         scsi_lun_t             scsi_lun;       /* own SCSI LUN */
1021         fcp_lun_t              fcp_lun;        /* own FCP_LUN */
1022         u32                    handle;         /* handle assigned by FSF */
1023         struct scsi_device     *device;        /* scsi device struct pointer */
1024         struct zfcp_erp_action erp_action;     /* pending error recovery */
1025         atomic_t               erp_counter;
1026         atomic_t               scsi_add_work;  /* used to synchronize */
1027         wait_queue_head_t      scsi_add_wq;    /* wait for scsi_add_device */
1028 };
1029
1030 /* FSF request */
1031 struct zfcp_fsf_req {
1032         struct list_head       list;           /* list of FSF requests */
1033         struct zfcp_adapter    *adapter;       /* adapter request belongs to */
1034         u8                     sbal_number;    /* nr of SBALs free for use */
1035         u8                     sbal_first;     /* first SBAL for this request */
1036         u8                     sbal_last;      /* last possible SBAL for
1037                                                   this reuest */
1038         u8                     sbal_curr;      /* current SBAL during creation
1039                                                   of request */
1040         u8                     sbale_curr;     /* current SBALE during creation
1041                                                   of request */
1042         wait_queue_head_t      completion_wq;  /* can be used by a routine
1043                                                   to wait for completion */
1044         volatile u32           status;         /* status of this request */
1045         u32                    fsf_command;    /* FSF Command copy */
1046         struct fsf_qtcb        *qtcb;          /* address of associated QTCB */
1047         u32                    seq_no;         /* Sequence number of request */
1048         union zfcp_req_data    data;           /* Info fields of request */ 
1049         struct zfcp_erp_action *erp_action;    /* used if this request is
1050                                                   issued on behalf of erp */
1051         mempool_t              *pool;          /* used if request was alloacted
1052                                                   from emergency pool */
1053 };
1054
1055 typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
1056
1057 /* driver data */
1058 struct zfcp_data {
1059         struct scsi_host_template scsi_host_template;
1060         atomic_t                status;             /* Module status flags */
1061         struct list_head        adapter_list_head;  /* head of adapter list */
1062         struct list_head        adapter_remove_lh;  /* head of adapters to be
1063                                                        removed */
1064         rwlock_t                status_read_lock;   /* for status read thread */
1065         struct list_head        status_read_receive_head;
1066         struct list_head        status_read_send_head;
1067         struct semaphore        status_read_sema;
1068         wait_queue_head_t       status_read_thread_wqh;
1069         u32                     adapters;           /* # of adapters in list */
1070         rwlock_t                config_lock;        /* serialises changes
1071                                                        to adapter/port/unit
1072                                                        lists */
1073         struct semaphore        config_sema;        /* serialises configuration
1074                                                        changes */
1075         struct notifier_block   reboot_notifier;     /* used to register cleanup
1076                                                         functions */
1077         atomic_t                loglevel;            /* current loglevel */
1078         char                    init_busid[BUS_ID_SIZE];
1079         wwn_t                   init_wwpn;
1080         fcp_lun_t               init_fcp_lun;
1081 };
1082
1083 struct zfcp_sg_list {
1084         struct scatterlist *sg;
1085         unsigned int count;
1086 };
1087
1088 /* number of elements for various memory pools */
1089 #define ZFCP_POOL_FSF_REQ_ERP_NR        1
1090 #define ZFCP_POOL_FSF_REQ_SCSI_NR       1
1091 #define ZFCP_POOL_FSF_REQ_ABORT_NR      1
1092 #define ZFCP_POOL_STATUS_READ_NR        ZFCP_STATUS_READS_RECOM
1093 #define ZFCP_POOL_DATA_GID_PN_NR        1
1094
1095 /* struct used by memory pools for fsf_requests */
1096 struct zfcp_fsf_req_pool_element {
1097         struct zfcp_fsf_req fsf_req;
1098         struct fsf_qtcb qtcb;
1099 };
1100
1101 /********************** ZFCP SPECIFIC DEFINES ********************************/
1102
1103 #define ZFCP_FSFREQ_CLEANUP_TIMEOUT     HZ/10
1104
1105 #define ZFCP_KNOWN              0x00000001
1106 #define ZFCP_REQ_AUTO_CLEANUP   0x00000002
1107 #define ZFCP_WAIT_FOR_SBAL      0x00000004
1108 #define ZFCP_REQ_NO_QTCB        0x00000008
1109
1110 #define ZFCP_SET                0x00000100
1111 #define ZFCP_CLEAR              0x00000200
1112
1113 #define ZFCP_INTERRUPTIBLE      1
1114 #define ZFCP_UNINTERRUPTIBLE    0
1115
1116 #ifndef atomic_test_mask
1117 #define atomic_test_mask(mask, target) \
1118            ((atomic_read(target) & mask) == mask)
1119 #endif
1120
1121 extern void _zfcp_hex_dump(char *, int);
1122 #define ZFCP_HEX_DUMP(level, addr, count) \
1123                 if (ZFCP_LOG_CHECK(level)) { \
1124                         _zfcp_hex_dump(addr, count); \
1125                 }
1126 /*
1127  * Not yet optimal but useful:
1128  * Waits until the condition is met or the timeout occurs.
1129  * The condition may be a function call. This allows to
1130  * execute some additional instructions in addition
1131  * to a simple condition check.
1132  * The timeout is modified on exit and holds the remaining time.
1133  * Thus it is zero if a timeout ocurred, i.e. the condition was 
1134  * not met in the specified interval.
1135  */
1136 #define __ZFCP_WAIT_EVENT_TIMEOUT(timeout, condition) \
1137 do { \
1138         set_current_state(TASK_UNINTERRUPTIBLE); \
1139         while (!(condition) && timeout) \
1140                 timeout = schedule_timeout(timeout); \
1141         current->state = TASK_RUNNING; \
1142 } while (0);
1143
1144 #define ZFCP_WAIT_EVENT_TIMEOUT(waitqueue, timeout, condition) \
1145 do { \
1146         wait_queue_t entry; \
1147         init_waitqueue_entry(&entry, current); \
1148         add_wait_queue(&waitqueue, &entry); \
1149         __ZFCP_WAIT_EVENT_TIMEOUT(timeout, condition) \
1150         remove_wait_queue(&waitqueue, &entry); \
1151 } while (0);
1152
1153 #define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
1154 #define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
1155 #define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
1156
1157 /*
1158  *  functions needed for reference/usage counting
1159  */
1160
1161 static inline void
1162 zfcp_unit_get(struct zfcp_unit *unit)
1163 {
1164         atomic_inc(&unit->refcount);
1165 }
1166
1167 static inline void
1168 zfcp_unit_put(struct zfcp_unit *unit)
1169 {
1170         if (atomic_dec_return(&unit->refcount) == 0)
1171                 wake_up(&unit->remove_wq);
1172 }
1173
1174 static inline void
1175 zfcp_unit_wait(struct zfcp_unit *unit)
1176 {
1177         wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
1178 }
1179
1180 static inline void
1181 zfcp_port_get(struct zfcp_port *port)
1182 {
1183         atomic_inc(&port->refcount);
1184 }
1185
1186 static inline void
1187 zfcp_port_put(struct zfcp_port *port)
1188 {
1189         if (atomic_dec_return(&port->refcount) == 0)
1190                 wake_up(&port->remove_wq);
1191 }
1192
1193 static inline void
1194 zfcp_port_wait(struct zfcp_port *port)
1195 {
1196         wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
1197 }
1198
1199 static inline void
1200 zfcp_adapter_get(struct zfcp_adapter *adapter)
1201 {
1202         atomic_inc(&adapter->refcount);
1203 }
1204
1205 static inline void
1206 zfcp_adapter_put(struct zfcp_adapter *adapter)
1207 {
1208         if (atomic_dec_return(&adapter->refcount) == 0)
1209                 wake_up(&adapter->remove_wq);
1210 }
1211
1212 static inline void
1213 zfcp_adapter_wait(struct zfcp_adapter *adapter)
1214 {
1215         wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
1216 }
1217
1218 #endif /* ZFCP_DEF_H */