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