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