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