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