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