blob: 72f225817ebd20261291800f0b79f55379265be3 [file] [log] [blame]
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001/*
Andreas Herrmann4a9d2d82006-05-22 18:14:08 +02002 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andreas Herrmann4a9d2d82006-05-22 18:14:08 +02005 * (C) Copyright IBM Corp. 2002, 2006
Swen Schillig41fa2ad2007-09-07 09:15:31 +02006 *
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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#ifndef ZFCP_DEF_H
23#define ZFCP_DEF_H
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025/*************************** INCLUDES *****************************************/
26
27#include <linux/init.h>
28#include <linux/moduleparam.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/major.h>
30#include <linux/blkdev.h>
31#include <linux/delay.h>
32#include <linux/timer.h>
Heiko Carstensdd52e0e2006-09-18 22:28:49 +020033#include <linux/slab.h>
34#include <linux/mempool.h>
35#include <linux/syscalls.h>
FUJITA Tomonorif1346372007-07-30 23:01:32 +090036#include <linux/scatterlist.h>
Heiko Carstensdd52e0e2006-09-18 22:28:49 +020037#include <linux/ioctl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <scsi/scsi.h>
39#include <scsi/scsi_tcq.h>
40#include <scsi/scsi_cmnd.h>
41#include <scsi/scsi_device.h>
42#include <scsi/scsi_host.h>
43#include <scsi/scsi_transport.h>
44#include <scsi/scsi_transport_fc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <asm/ccwdev.h>
46#include <asm/qdio.h>
47#include <asm/debug.h>
48#include <asm/ebcdic.h>
Christof Schmitt2b604c92008-03-31 11:15:28 +020049#include "zfcp_dbf.h"
Heiko Carstensdd52e0e2006-09-18 22:28:49 +020050#include "zfcp_fsf.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53/********************* GENERAL DEFINES *********************************/
54
55/* zfcp version number, it consists of major, minor, and patch-level number */
Andreas Herrmann58b3ac02006-08-02 11:06:21 +020056#define ZFCP_VERSION "4.8.0"
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58/**
59 * zfcp_sg_to_address - determine kernel address from struct scatterlist
60 * @list: struct scatterlist
61 * Return: kernel address
62 */
63static inline void *
64zfcp_sg_to_address(struct scatterlist *list)
65{
Jens Axboe73fc4f02007-10-23 09:17:53 +020066 return sg_virt(list);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067}
68
69/**
70 * zfcp_address_to_sg - set up struct scatterlist from kernel address
71 * @address: kernel address
72 * @list: struct scatterlist
Jens Axboe933543292007-10-26 13:55:40 +020073 * @size: buffer size
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 */
75static inline void
Jens Axboe933543292007-10-26 13:55:40 +020076zfcp_address_to_sg(void *address, struct scatterlist *list, unsigned int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
Jens Axboe933543292007-10-26 13:55:40 +020078 sg_set_buf(list, address, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079}
80
Andreas Herrmann06506d02006-05-22 18:18:19 +020081#define REQUEST_LIST_SIZE 128
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083/********************* SCSI SPECIFIC DEFINES *********************************/
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +020084#define ZFCP_SCSI_ER_TIMEOUT (10*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
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
Swen Schillig41fa2ad2007-09-07 09:15:31 +020094
Linus Torvalds1da177e2005-04-16 15:20:36 -070095/* 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
Swen Schillig8d1a0062006-10-12 11:43:44 +0200111#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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115/* 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
Christof Schmitt18edcdb2007-11-05 12:37:45 +0100121#define ZFCP_TYPE2_RECOVERY_TIME 8 /* seconds */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
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 */
Swen Schilligb4e44592007-07-18 10:55:13 +0200130#define QBUFF_PER_PAGE (PAGE_SIZE / sizeof(struct qdio_buffer))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138#define ZFCP_STATUS_READS_RECOM FSF_STATUS_READS_RECOM
Andreas Herrmann22753fa2005-06-13 13:15:15 +0200139
140/* Do 1st retry in 1 second, then double the timeout for each following retry */
Christof Schmitt18edcdb2007-11-05 12:37:45 +0100141#define ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP 1
Andreas Herrmann22753fa2005-06-13 13:15:15 +0200142#define ZFCP_EXCHANGE_CONFIG_DATA_RETRIES 7
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144/* timeout value for "default timer" for fsf requests */
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200145#define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
147/*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
148
149typedef unsigned long long wwn_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150typedef unsigned long long fcp_lun_t;
151/* data length field may be at variable position in FCP-2 FCP_CMND IU */
152typedef unsigned int fcp_dl_t;
153
154#define ZFCP_FC_SERVICE_CLASS_DEFAULT FSF_CLASS_3
155
156/* timeout for name-server lookup (in seconds) */
157#define ZFCP_NS_GID_PN_TIMEOUT 10
158
159/* largest SCSI command we can process */
160/* FCP-2 (FCP_CMND IU) allows up to (255-3+16) */
161#define ZFCP_MAX_SCSI_CMND_LENGTH 255
162/* maximum number of commands in LUN queue (tagged queueing) */
163#define ZFCP_CMND_PER_LUN 32
164
165/* task attribute values in FCP-2 FCP_CMND IU */
166#define SIMPLE_Q 0
167#define HEAD_OF_Q 1
168#define ORDERED_Q 2
169#define ACA_Q 4
170#define UNTAGGED 5
171
172/* task management flags in FCP-2 FCP_CMND IU */
173#define FCP_CLEAR_ACA 0x40
174#define FCP_TARGET_RESET 0x20
175#define FCP_LOGICAL_UNIT_RESET 0x10
176#define FCP_CLEAR_TASK_SET 0x04
177#define FCP_ABORT_TASK_SET 0x02
178
179#define FCP_CDB_LENGTH 16
180
181#define ZFCP_DID_MASK 0x00FFFFFF
182
183/* FCP(-2) FCP_CMND IU */
184struct fcp_cmnd_iu {
185 fcp_lun_t fcp_lun; /* FCP logical unit number */
186 u8 crn; /* command reference number */
187 u8 reserved0:5; /* reserved */
188 u8 task_attribute:3; /* task attribute */
189 u8 task_management_flags; /* task management flags */
190 u8 add_fcp_cdb_length:6; /* additional FCP_CDB length */
191 u8 rddata:1; /* read data */
192 u8 wddata:1; /* write data */
193 u8 fcp_cdb[FCP_CDB_LENGTH];
194} __attribute__((packed));
195
196/* FCP(-2) FCP_RSP IU */
197struct fcp_rsp_iu {
198 u8 reserved0[10];
199 union {
200 struct {
201 u8 reserved1:3;
202 u8 fcp_conf_req:1;
203 u8 fcp_resid_under:1;
204 u8 fcp_resid_over:1;
205 u8 fcp_sns_len_valid:1;
206 u8 fcp_rsp_len_valid:1;
207 } bits;
208 u8 value;
209 } validity;
210 u8 scsi_status;
211 u32 fcp_resid;
212 u32 fcp_sns_len;
213 u32 fcp_rsp_len;
214} __attribute__((packed));
215
216
217#define RSP_CODE_GOOD 0
218#define RSP_CODE_LENGTH_MISMATCH 1
219#define RSP_CODE_FIELD_INVALID 2
220#define RSP_CODE_RO_MISMATCH 3
221#define RSP_CODE_TASKMAN_UNSUPP 4
222#define RSP_CODE_TASKMAN_FAILED 5
223
224/* see fc-fs */
Christof Schmitt24073b42008-06-10 18:20:54 +0200225#define LS_RSCN 0x61
226#define LS_LOGO 0x05
227#define LS_PLOGI 0x03
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229struct fcp_rscn_head {
230 u8 command;
231 u8 page_length; /* always 0x04 */
232 u16 payload_len;
233} __attribute__((packed));
234
235struct fcp_rscn_element {
236 u8 reserved:2;
237 u8 event_qual:4;
238 u8 addr_format:2;
239 u32 nport_did:24;
240} __attribute__((packed));
241
242#define ZFCP_PORT_ADDRESS 0x0
243#define ZFCP_AREA_ADDRESS 0x1
244#define ZFCP_DOMAIN_ADDRESS 0x2
245#define ZFCP_FABRIC_ADDRESS 0x3
246
247#define ZFCP_PORTS_RANGE_PORT 0xFFFFFF
248#define ZFCP_PORTS_RANGE_AREA 0xFFFF00
249#define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
250#define ZFCP_PORTS_RANGE_FABRIC 0x000000
251
252#define ZFCP_NO_PORTS_PER_AREA 0x100
253#define ZFCP_NO_PORTS_PER_DOMAIN 0x10000
254#define ZFCP_NO_PORTS_PER_FABRIC 0x1000000
255
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256/* see fc-ph */
257struct fcp_logo {
258 u32 command;
259 u32 nport_did;
260 wwn_t nport_wwpn;
261} __attribute__((packed));
262
263/*
264 * FC-FS stuff
265 */
266#define R_A_TOV 10 /* seconds */
267#define ZFCP_ELS_TIMEOUT (2 * R_A_TOV)
268
269#define ZFCP_LS_RLS 0x0f
270#define ZFCP_LS_ADISC 0x52
271#define ZFCP_LS_RPS 0x56
272#define ZFCP_LS_RSCN 0x61
273#define ZFCP_LS_RNID 0x78
274
275struct zfcp_ls_rjt_par {
276 u8 action;
277 u8 reason_code;
278 u8 reason_expl;
279 u8 vendor_unique;
280} __attribute__ ((packed));
281
282struct zfcp_ls_adisc {
283 u8 code;
284 u8 field[3];
285 u32 hard_nport_id;
286 u64 wwpn;
287 u64 wwnn;
288 u32 nport_id;
289} __attribute__ ((packed));
290
291struct zfcp_ls_adisc_acc {
292 u8 code;
293 u8 field[3];
294 u32 hard_nport_id;
295 u64 wwpn;
296 u64 wwnn;
297 u32 nport_id;
298} __attribute__ ((packed));
299
300struct zfcp_rc_entry {
301 u8 code;
302 const char *description;
303};
304
305/*
306 * FC-GS-2 stuff
307 */
308#define ZFCP_CT_REVISION 0x01
309#define ZFCP_CT_DIRECTORY_SERVICE 0xFC
310#define ZFCP_CT_NAME_SERVER 0x02
311#define ZFCP_CT_SYNCHRONOUS 0x00
312#define ZFCP_CT_GID_PN 0x0121
313#define ZFCP_CT_MAX_SIZE 0x1020
314#define ZFCP_CT_ACCEPT 0x8002
315#define ZFCP_CT_REJECT 0x8001
316
317/*
318 * FC-GS-4 stuff
319 */
320#define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
321
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322/******************** LOGGING MACROS AND DEFINES *****************************/
323
324/*
325 * Logging may be applied on certain kinds of driver operations
326 * independently. Additionally, different log-levels are supported for
327 * each of these areas.
328 */
329
330#define ZFCP_NAME "zfcp"
331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332/* independent log areas */
333#define ZFCP_LOG_AREA_OTHER 0
334#define ZFCP_LOG_AREA_SCSI 1
335#define ZFCP_LOG_AREA_FSF 2
336#define ZFCP_LOG_AREA_CONFIG 3
337#define ZFCP_LOG_AREA_CIO 4
338#define ZFCP_LOG_AREA_QDIO 5
339#define ZFCP_LOG_AREA_ERP 6
340#define ZFCP_LOG_AREA_FC 7
341
342/* log level values*/
343#define ZFCP_LOG_LEVEL_NORMAL 0
344#define ZFCP_LOG_LEVEL_INFO 1
345#define ZFCP_LOG_LEVEL_DEBUG 2
346#define ZFCP_LOG_LEVEL_TRACE 3
347
348/*
349 * this allows removal of logging code by the preprocessor
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200350 * (the most detailed log level still to be compiled in is specified,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 * higher log levels are removed)
352 */
353#define ZFCP_LOG_LEVEL_LIMIT ZFCP_LOG_LEVEL_TRACE
354
355/* get "loglevel" nibble assignment */
356#define ZFCP_GET_LOG_VALUE(zfcp_lognibble) \
357 ((atomic_read(&zfcp_data.loglevel) >> (zfcp_lognibble<<2)) & 0xF)
358
359/* set "loglevel" nibble */
360#define ZFCP_SET_LOG_NIBBLE(value, zfcp_lognibble) \
361 (value << (zfcp_lognibble << 2))
362
363/* all log-level defaults are combined to generate initial log-level */
364#define ZFCP_LOG_LEVEL_DEFAULTS \
365 (ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_OTHER) | \
366 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_SCSI) | \
367 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FSF) | \
368 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CONFIG) | \
369 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CIO) | \
370 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_QDIO) | \
371 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_ERP) | \
372 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FC))
373
374/* check whether we have the right level for logging */
375#define ZFCP_LOG_CHECK(level) \
376 ((ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA)) >= level)
377
378/* logging routine for zfcp */
379#define _ZFCP_LOG(fmt, args...) \
Harvey Harrison2a2cf6b2008-04-17 07:46:21 +0200380 printk(KERN_ERR ZFCP_NAME": %s(%d): " fmt, __func__, \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 __LINE__ , ##args)
382
383#define ZFCP_LOG(level, fmt, args...) \
384do { \
385 if (ZFCP_LOG_CHECK(level)) \
386 _ZFCP_LOG(fmt, ##args); \
387} while (0)
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200388
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389#if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_NORMAL
Heiko Carstens39b083f2006-09-20 15:58:51 +0200390# define ZFCP_LOG_NORMAL(fmt, args...) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391#else
392# define ZFCP_LOG_NORMAL(fmt, args...) \
393do { \
394 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_NORMAL)) \
395 printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
396} while (0)
397#endif
398
399#if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_INFO
Heiko Carstens39b083f2006-09-20 15:58:51 +0200400# define ZFCP_LOG_INFO(fmt, args...) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401#else
402# define ZFCP_LOG_INFO(fmt, args...) \
403do { \
404 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_INFO)) \
405 printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
406} while (0)
407#endif
408
409#if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_DEBUG
Heiko Carstens39b083f2006-09-20 15:58:51 +0200410# define ZFCP_LOG_DEBUG(fmt, args...) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411#else
412# define ZFCP_LOG_DEBUG(fmt, args...) \
413 ZFCP_LOG(ZFCP_LOG_LEVEL_DEBUG, fmt , ##args)
414#endif
415
416#if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_TRACE
Heiko Carstens39b083f2006-09-20 15:58:51 +0200417# define ZFCP_LOG_TRACE(fmt, args...) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418#else
419# define ZFCP_LOG_TRACE(fmt, args...) \
420 ZFCP_LOG(ZFCP_LOG_LEVEL_TRACE, fmt , ##args)
421#endif
422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423/*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
424
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200425/*
426 * Note, the leftmost status byte is common among adapter, port
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 * and unit
428 */
429#define ZFCP_COMMON_FLAGS 0xfff00000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
431/* common status bits */
432#define ZFCP_STATUS_COMMON_REMOVE 0x80000000
433#define ZFCP_STATUS_COMMON_RUNNING 0x40000000
434#define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
435#define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
436#define ZFCP_STATUS_COMMON_OPENING 0x08000000
437#define ZFCP_STATUS_COMMON_OPEN 0x04000000
438#define ZFCP_STATUS_COMMON_CLOSING 0x02000000
439#define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
440#define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
Andreas Herrmannd736a272005-06-13 13:23:57 +0200441#define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
443/* adapter status */
444#define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
445#define ZFCP_STATUS_ADAPTER_REGISTERED 0x00000004
446#define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
447#define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
448#define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
449#define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
450#define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
451#define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200452#define ZFCP_STATUS_ADAPTER_XPORT_OK 0x00000800
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454/* FC-PH/FC-GS well-known address identifiers for generic services */
455#define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA
456#define ZFCP_DID_TIME_SERVICE 0xFFFFFB
457#define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC
458#define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8
459#define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7
460
461/* remote port status */
462#define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
463#define ZFCP_STATUS_PORT_DID_DID 0x00000002
464#define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
465#define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
466#define ZFCP_STATUS_PORT_NO_SCSI_ID 0x00000010
467#define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
469/* for ports with well known addresses */
470#define ZFCP_STATUS_PORT_WKA \
471 (ZFCP_STATUS_PORT_NO_WWPN | \
472 ZFCP_STATUS_PORT_NO_SCSI_ID)
473
474/* logical unit status */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475#define ZFCP_STATUS_UNIT_TEMPORARY 0x00000002
476#define ZFCP_STATUS_UNIT_SHARED 0x00000004
477#define ZFCP_STATUS_UNIT_READONLY 0x00000008
Andreas Herrmannad58f7d2006-03-10 00:56:16 +0100478#define ZFCP_STATUS_UNIT_REGISTERED 0x00000010
Christof Schmitt5f852be2007-05-08 11:16:52 +0200479#define ZFCP_STATUS_UNIT_SCSI_WORK_PENDING 0x00000020
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
481/* FSF request status (this does not have a common part) */
482#define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000
483#define ZFCP_STATUS_FSFREQ_POOL 0x00000001
484#define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
485#define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
486#define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
487#define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
488#define ZFCP_STATUS_FSFREQ_ABORTING 0x00000020
489#define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
490#define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
491#define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
492#define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
493#define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
494#define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
495#define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
496
497/*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
498
499#define ZFCP_MAX_ERPS 3
500
501#define ZFCP_ERP_FSFREQ_TIMEOUT (30 * HZ)
502#define ZFCP_ERP_MEMWAIT_TIMEOUT HZ
503
504#define ZFCP_STATUS_ERP_TIMEDOUT 0x10000000
505#define ZFCP_STATUS_ERP_CLOSE_ONLY 0x01000000
506#define ZFCP_STATUS_ERP_DISMISSING 0x00100000
507#define ZFCP_STATUS_ERP_DISMISSED 0x00200000
508#define ZFCP_STATUS_ERP_LOWMEM 0x00400000
509
510#define ZFCP_ERP_STEP_UNINITIALIZED 0x00000000
511#define ZFCP_ERP_STEP_FSF_XCONFIG 0x00000001
512#define ZFCP_ERP_STEP_PHYS_PORT_CLOSING 0x00000010
513#define ZFCP_ERP_STEP_PORT_CLOSING 0x00000100
514#define ZFCP_ERP_STEP_NAMESERVER_OPEN 0x00000200
515#define ZFCP_ERP_STEP_NAMESERVER_LOOKUP 0x00000400
516#define ZFCP_ERP_STEP_PORT_OPENING 0x00000800
517#define ZFCP_ERP_STEP_UNIT_CLOSING 0x00001000
518#define ZFCP_ERP_STEP_UNIT_OPENING 0x00002000
519
520/* Ordered by escalation level (necessary for proper erp-code operation) */
521#define ZFCP_ERP_ACTION_REOPEN_ADAPTER 0x4
522#define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED 0x3
523#define ZFCP_ERP_ACTION_REOPEN_PORT 0x2
524#define ZFCP_ERP_ACTION_REOPEN_UNIT 0x1
525
526#define ZFCP_ERP_ACTION_RUNNING 0x1
527#define ZFCP_ERP_ACTION_READY 0x2
528
529#define ZFCP_ERP_SUCCEEDED 0x0
530#define ZFCP_ERP_FAILED 0x1
531#define ZFCP_ERP_CONTINUES 0x2
532#define ZFCP_ERP_EXIT 0x3
533#define ZFCP_ERP_DISMISSED 0x4
534#define ZFCP_ERP_NOMEM 0x5
535
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536/************************* STRUCTURE DEFINITIONS *****************************/
537
538struct zfcp_fsf_req;
539
540/* holds various memory pools of an adapter */
541struct zfcp_adapter_mempool {
542 mempool_t *fsf_req_erp;
543 mempool_t *fsf_req_scsi;
544 mempool_t *fsf_req_abort;
545 mempool_t *fsf_req_status_read;
546 mempool_t *data_status_read;
547 mempool_t *data_gid_pn;
548};
549
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550/*
551 * header for CT_IU
552 */
553struct ct_hdr {
554 u8 revision; // 0x01
555 u8 in_id[3]; // 0x00
556 u8 gs_type; // 0xFC Directory Service
557 u8 gs_subtype; // 0x02 Name Server
558 u8 options; // 0x00 single bidirectional exchange
559 u8 reserved0;
560 u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT
561 u16 max_res_size; // <= (4096 - 16) / 4
562 u8 reserved1;
563 u8 reason_code;
564 u8 reason_code_expl;
565 u8 vendor_unique;
566} __attribute__ ((packed));
567
568/* nameserver request CT_IU -- for requests where
569 * a port name is required */
570struct ct_iu_gid_pn_req {
571 struct ct_hdr header;
572 wwn_t wwpn;
573} __attribute__ ((packed));
574
575/* FS_ACC IU and data unit for GID_PN nameserver request */
576struct ct_iu_gid_pn_resp {
577 struct ct_hdr header;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200578 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579} __attribute__ ((packed));
580
581typedef void (*zfcp_send_ct_handler_t)(unsigned long);
582
583/**
584 * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
585 * @port: port where the request is sent to
586 * @req: scatter-gather list for request
587 * @resp: scatter-gather list for response
588 * @req_count: number of elements in request scatter-gather list
589 * @resp_count: number of elements in response scatter-gather list
590 * @handler: handler function (called for response to the request)
591 * @handler_data: data passed to handler function
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 * @timeout: FSF timeout for this request
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 * @completion: completion for synchronization purposes
594 * @status: used to pass error status to calling function
595 */
596struct zfcp_send_ct {
597 struct zfcp_port *port;
598 struct scatterlist *req;
599 struct scatterlist *resp;
600 unsigned int req_count;
601 unsigned int resp_count;
602 zfcp_send_ct_handler_t handler;
603 unsigned long handler_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 int timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 struct completion *completion;
606 int status;
607};
608
609/* used for name server requests in error recovery */
610struct zfcp_gid_pn_data {
611 struct zfcp_send_ct ct;
612 struct scatterlist req;
613 struct scatterlist resp;
614 struct ct_iu_gid_pn_req ct_iu_req;
615 struct ct_iu_gid_pn_resp ct_iu_resp;
616 struct zfcp_port *port;
617};
618
619typedef void (*zfcp_send_els_handler_t)(unsigned long);
620
621/**
622 * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
623 * @adapter: adapter where request is sent from
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200624 * @port: port where ELS is destinated (port reference count has to be increased)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 * @d_id: destiniation id of port where request is sent to
626 * @req: scatter-gather list for request
627 * @resp: scatter-gather list for response
628 * @req_count: number of elements in request scatter-gather list
629 * @resp_count: number of elements in response scatter-gather list
630 * @handler: handler function (called for response to the request)
631 * @handler_data: data passed to handler function
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 * @completion: completion for synchronization purposes
633 * @ls_code: hex code of ELS command
634 * @status: used to pass error status to calling function
635 */
636struct zfcp_send_els {
637 struct zfcp_adapter *adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200638 struct zfcp_port *port;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200639 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 struct scatterlist *req;
641 struct scatterlist *resp;
642 unsigned int req_count;
643 unsigned int resp_count;
644 zfcp_send_els_handler_t handler;
645 unsigned long handler_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 struct completion *completion;
647 int ls_code;
648 int status;
649};
650
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651struct zfcp_qdio_queue {
652 struct qdio_buffer *buffer[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
653 u8 free_index; /* index of next free bfr
654 in queue (free_count>0) */
655 atomic_t free_count; /* number of free buffers
656 in queue */
657 rwlock_t queue_lock; /* lock for operations on queue */
658 int distance_from_int; /* SBALs used since PCI indication
659 was last set */
660};
661
662struct zfcp_erp_action {
663 struct list_head list;
664 int action; /* requested action code */
665 struct zfcp_adapter *adapter; /* device which should be recovered */
666 struct zfcp_port *port;
667 struct zfcp_unit *unit;
668 volatile u32 status; /* recovery status */
669 u32 step; /* active step of this erp action */
670 struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
671 for this action */
672 struct timer_list timer;
673};
674
Christof Schmittc9615852008-05-06 11:00:05 +0200675struct fsf_latency_record {
676 u32 min;
677 u32 max;
678 u64 sum;
679};
680
681struct latency_cont {
682 struct fsf_latency_record channel;
683 struct fsf_latency_record fabric;
684 u64 counter;
685};
686
687struct zfcp_latencies {
688 struct latency_cont read;
689 struct latency_cont write;
690 struct latency_cont cmd;
691 spinlock_t lock;
692};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
694struct zfcp_adapter {
695 struct list_head list; /* list of adapters */
696 atomic_t refcount; /* reference count */
697 wait_queue_head_t remove_wq; /* can be used to wait for
698 refcount drop to zero */
6f71d9b2005-04-10 23:04:28 -0500699 wwn_t peer_wwnn; /* P2P peer WWNN */
700 wwn_t peer_wwpn; /* P2P peer WWPN */
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200701 u32 peer_d_id; /* P2P peer D_ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 struct ccw_device *ccw_device; /* S/390 ccw device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 u32 hydra_version; /* Hydra version */
704 u32 fsf_lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200705 u32 adapter_features; /* FCP channel features */
706 u32 connection_features; /* host connection features */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 u32 hardware_version; /* of FCP channel */
Christof Schmittc9615852008-05-06 11:00:05 +0200708 u16 timer_ticks; /* time int for a tick */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 struct list_head port_list_head; /* remote port list */
711 struct list_head port_remove_lh; /* head of ports to be
712 removed */
713 u32 ports; /* number of remote ports */
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200714 atomic_t reqs_active; /* # active FSF reqs */
715 unsigned long req_no; /* unique FSF req number */
716 struct list_head *req_list; /* list of pending reqs */
717 spinlock_t req_list_lock; /* request list lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 struct zfcp_qdio_queue request_queue; /* request queue */
719 u32 fsf_req_seq_no; /* FSF cmnd seq number */
720 wait_queue_head_t request_wq; /* can be used to wait for
721 more avaliable SBALs */
722 struct zfcp_qdio_queue response_queue; /* response queue */
723 rwlock_t abort_lock; /* Protects against SCSI
724 stack abort/command
725 completion races */
Swen Schilligd26ab062008-05-19 12:17:37 +0200726 atomic_t stat_miss; /* # missing status reads*/
727 struct work_struct stat_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 atomic_t status; /* status of this adapter */
729 struct list_head erp_ready_head; /* error recovery for this
730 adapter/devices */
731 struct list_head erp_running_head;
732 rwlock_t erp_lock;
733 struct semaphore erp_ready_sem;
734 wait_queue_head_t erp_thread_wqh;
735 wait_queue_head_t erp_done_wqh;
736 struct zfcp_erp_action erp_action; /* pending error recovery */
737 atomic_t erp_counter;
738 u32 erp_total_count; /* total nr of enqueued erp
739 actions */
740 u32 erp_low_mem_count; /* nr of erp actions waiting
741 for memory */
742 struct zfcp_port *nameserver_port; /* adapter's nameserver */
Martin Peschked79a83d2008-03-27 14:22:00 +0100743 debug_info_t *rec_dbf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200744 debug_info_t *hba_dbf;
745 debug_info_t *san_dbf; /* debug feature areas */
746 debug_info_t *scsi_dbf;
Martin Peschked79a83d2008-03-27 14:22:00 +0100747 spinlock_t rec_dbf_lock;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200748 spinlock_t hba_dbf_lock;
749 spinlock_t san_dbf_lock;
750 spinlock_t scsi_dbf_lock;
Martin Peschked79a83d2008-03-27 14:22:00 +0100751 struct zfcp_rec_dbf_record rec_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200752 struct zfcp_hba_dbf_record hba_dbf_buf;
753 struct zfcp_san_dbf_record san_dbf_buf;
754 struct zfcp_scsi_dbf_record scsi_dbf_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 struct zfcp_adapter_mempool pool; /* Adapter memory pools */
756 struct qdio_initialize qdio_init_data; /* for qdio_establish */
757 struct device generic_services; /* directory for WKA ports */
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100758 struct fc_host_statistics *fc_stats;
759 struct fsf_qtcb_bottom_port *stats_reset_data;
760 unsigned long stats_reset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761};
762
763/*
764 * the struct device sysfs_device must be at the beginning of this structure.
765 * pointer to struct device is used to free port structure in release function
766 * of the device. don't change!
767 */
768struct zfcp_port {
769 struct device sysfs_device; /* sysfs device */
Andreas Herrmann3859f6a2005-08-27 11:07:54 -0700770 struct fc_rport *rport; /* rport of fc transport class */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 struct list_head list; /* list of remote ports */
772 atomic_t refcount; /* reference count */
773 wait_queue_head_t remove_wq; /* can be used to wait for
774 refcount drop to zero */
775 struct zfcp_adapter *adapter; /* adapter used to access port */
776 struct list_head unit_list_head; /* head of logical unit list */
777 struct list_head unit_remove_lh; /* head of luns to be removed
778 list */
779 u32 units; /* # of logical units in list */
780 atomic_t status; /* status of this remote port */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 wwn_t wwnn; /* WWNN if known */
782 wwn_t wwpn; /* WWPN */
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200783 u32 d_id; /* D_ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 u32 handle; /* handle assigned by FSF */
785 struct zfcp_erp_action erp_action; /* pending error recovery */
786 atomic_t erp_counter;
Ralph Wuerthner75bfc282006-05-22 18:24:33 +0200787 u32 maxframe_size;
788 u32 supported_classes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789};
790
791/* the struct device sysfs_device must be at the beginning of this structure.
792 * pointer to struct device is used to free unit structure in release function
793 * of the device. don't change!
794 */
795struct zfcp_unit {
796 struct device sysfs_device; /* sysfs device */
797 struct list_head list; /* list of logical units */
798 atomic_t refcount; /* reference count */
799 wait_queue_head_t remove_wq; /* can be used to wait for
800 refcount drop to zero */
801 struct zfcp_port *port; /* remote port of unit */
802 atomic_t status; /* status of this logical unit */
Andreas Herrmann06506d02006-05-22 18:18:19 +0200803 unsigned int scsi_lun; /* own SCSI LUN */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 fcp_lun_t fcp_lun; /* own FCP_LUN */
805 u32 handle; /* handle assigned by FSF */
806 struct scsi_device *device; /* scsi device struct pointer */
807 struct zfcp_erp_action erp_action; /* pending error recovery */
808 atomic_t erp_counter;
Christof Schmittc9615852008-05-06 11:00:05 +0200809 struct zfcp_latencies latencies;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810};
811
812/* FSF request */
813struct zfcp_fsf_req {
814 struct list_head list; /* list of FSF requests */
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200815 unsigned long req_id; /* unique request ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 struct zfcp_adapter *adapter; /* adapter request belongs to */
817 u8 sbal_number; /* nr of SBALs free for use */
818 u8 sbal_first; /* first SBAL for this request */
Martin Peschkee891bff2008-05-19 12:17:43 +0200819 u8 sbal_last; /* last SBAL for this request */
Martin Peschked01d51b2008-05-19 12:17:42 +0200820 u8 sbal_limit; /* last possible SBAL for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 this reuest */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 u8 sbale_curr; /* current SBALE during creation
823 of request */
Martin Peschkec3baa9a22008-05-19 12:17:44 +0200824 u8 sbal_response; /* SBAL used in interrupt */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 wait_queue_head_t completion_wq; /* can be used by a routine
826 to wait for completion */
827 volatile u32 status; /* status of this request */
828 u32 fsf_command; /* FSF Command copy */
829 struct fsf_qtcb *qtcb; /* address of associated QTCB */
830 u32 seq_no; /* Sequence number of request */
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200831 unsigned long data; /* private data of request */
832 struct timer_list timer; /* used for erp or scsi er */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 struct zfcp_erp_action *erp_action; /* used if this request is
834 issued on behalf of erp */
835 mempool_t *pool; /* used if request was alloacted
836 from emergency pool */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200837 unsigned long long issued; /* request sent time (STCK) */
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200838 struct zfcp_unit *unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839};
840
841typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
842
843/* driver data */
844struct zfcp_data {
845 struct scsi_host_template scsi_host_template;
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200846 struct scsi_transport_template *scsi_transport_template;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 atomic_t status; /* Module status flags */
848 struct list_head adapter_list_head; /* head of adapter list */
849 struct list_head adapter_remove_lh; /* head of adapters to be
850 removed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 u32 adapters; /* # of adapters in list */
852 rwlock_t config_lock; /* serialises changes
853 to adapter/port/unit
854 lists */
855 struct semaphore config_sema; /* serialises configuration
856 changes */
857 atomic_t loglevel; /* current loglevel */
858 char init_busid[BUS_ID_SIZE];
859 wwn_t init_wwpn;
860 fcp_lun_t init_fcp_lun;
861 char *driver_version;
Christoph Lametere18b8902006-12-06 20:33:20 -0800862 struct kmem_cache *fsf_req_qtcb_cache;
863 struct kmem_cache *sr_buffer_cache;
864 struct kmem_cache *gid_pn_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865};
866
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867/* number of elements for various memory pools */
868#define ZFCP_POOL_FSF_REQ_ERP_NR 1
869#define ZFCP_POOL_FSF_REQ_SCSI_NR 1
870#define ZFCP_POOL_FSF_REQ_ABORT_NR 1
871#define ZFCP_POOL_STATUS_READ_NR ZFCP_STATUS_READS_RECOM
872#define ZFCP_POOL_DATA_GID_PN_NR 1
873
874/* struct used by memory pools for fsf_requests */
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200875struct zfcp_fsf_req_qtcb {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 struct zfcp_fsf_req fsf_req;
877 struct fsf_qtcb qtcb;
878};
879
880/********************** ZFCP SPECIFIC DEFINES ********************************/
881
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882#define ZFCP_REQ_AUTO_CLEANUP 0x00000002
883#define ZFCP_WAIT_FOR_SBAL 0x00000004
884#define ZFCP_REQ_NO_QTCB 0x00000008
885
886#define ZFCP_SET 0x00000100
887#define ZFCP_CLEAR 0x00000200
888
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889#ifndef atomic_test_mask
890#define atomic_test_mask(mask, target) \
891 ((atomic_read(target) & mask) == mask)
892#endif
893
894extern void _zfcp_hex_dump(char *, int);
895#define ZFCP_HEX_DUMP(level, addr, count) \
896 if (ZFCP_LOG_CHECK(level)) { \
897 _zfcp_hex_dump(addr, count); \
898 }
899
900#define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
901#define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
902#define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
903
904/*
Heiko Carstensca2d02c2007-05-08 11:17:54 +0200905 * Helper functions for request ID management.
906 */
907static inline int zfcp_reqlist_hash(unsigned long req_id)
908{
909 return req_id % REQUEST_LIST_SIZE;
910}
911
912static inline void zfcp_reqlist_add(struct zfcp_adapter *adapter,
913 struct zfcp_fsf_req *fsf_req)
914{
915 unsigned int idx;
916
917 idx = zfcp_reqlist_hash(fsf_req->req_id);
918 list_add_tail(&fsf_req->list, &adapter->req_list[idx]);
919}
920
921static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
922 struct zfcp_fsf_req *fsf_req)
923{
924 list_del(&fsf_req->list);
925}
926
927static inline struct zfcp_fsf_req *
928zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
929{
930 struct zfcp_fsf_req *request;
931 unsigned int idx;
932
933 idx = zfcp_reqlist_hash(req_id);
934 list_for_each_entry(request, &adapter->req_list[idx], list)
935 if (request->req_id == req_id)
936 return request;
937 return NULL;
938}
939
Heiko Carstensd1ad09d2007-12-20 12:30:22 +0100940static inline struct zfcp_fsf_req *
941zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req)
942{
943 struct zfcp_fsf_req *request;
944 unsigned int idx;
945
946 for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) {
947 list_for_each_entry(request, &adapter->req_list[idx], list)
948 if (request == req)
949 return request;
950 }
951 return NULL;
952}
953
Heiko Carstensca2d02c2007-05-08 11:17:54 +0200954/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 * functions needed for reference/usage counting
956 */
957
958static inline void
959zfcp_unit_get(struct zfcp_unit *unit)
960{
961 atomic_inc(&unit->refcount);
962}
963
964static inline void
965zfcp_unit_put(struct zfcp_unit *unit)
966{
967 if (atomic_dec_return(&unit->refcount) == 0)
968 wake_up(&unit->remove_wq);
969}
970
971static inline void
972zfcp_unit_wait(struct zfcp_unit *unit)
973{
974 wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
975}
976
977static inline void
978zfcp_port_get(struct zfcp_port *port)
979{
980 atomic_inc(&port->refcount);
981}
982
983static inline void
984zfcp_port_put(struct zfcp_port *port)
985{
986 if (atomic_dec_return(&port->refcount) == 0)
987 wake_up(&port->remove_wq);
988}
989
990static inline void
991zfcp_port_wait(struct zfcp_port *port)
992{
993 wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
994}
995
996static inline void
997zfcp_adapter_get(struct zfcp_adapter *adapter)
998{
999 atomic_inc(&adapter->refcount);
1000}
1001
1002static inline void
1003zfcp_adapter_put(struct zfcp_adapter *adapter)
1004{
1005 if (atomic_dec_return(&adapter->refcount) == 0)
1006 wake_up(&adapter->remove_wq);
1007}
1008
1009static inline void
1010zfcp_adapter_wait(struct zfcp_adapter *adapter)
1011{
1012 wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
1013}
1014
1015#endif /* ZFCP_DEF_H */