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