blob: 5fcb555e1484e9bccddb3b3704ac94ea1d7c34d9 [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#define ZFCP_SBAL_TIMEOUT (5*HZ)
116
Christof Schmitt18edcdb2007-11-05 12:37:45 +0100117#define ZFCP_TYPE2_RECOVERY_TIME 8 /* seconds */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Swen Schilligb4e44592007-07-18 10:55:13 +0200119#define QBUFF_PER_PAGE (PAGE_SIZE / sizeof(struct qdio_buffer))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121/********************* FSF SPECIFIC DEFINES *********************************/
122
123#define ZFCP_ULP_INFO_VERSION 26
124#define ZFCP_QTCB_VERSION FSF_QTCB_CURRENT_VERSION
125/* ATTENTION: value must not be used by hardware */
126#define FSF_QTCB_UNSOLICITED_STATUS 0x6305
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#define ZFCP_STATUS_READS_RECOM FSF_STATUS_READS_RECOM
Andreas Herrmann22753fa2005-06-13 13:15:15 +0200128
129/* Do 1st retry in 1 second, then double the timeout for each following retry */
Christof Schmitt18edcdb2007-11-05 12:37:45 +0100130#define ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP 1
Andreas Herrmann22753fa2005-06-13 13:15:15 +0200131#define ZFCP_EXCHANGE_CONFIG_DATA_RETRIES 7
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133/* timeout value for "default timer" for fsf requests */
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200134#define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136/*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
137
138typedef unsigned long long wwn_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139typedef unsigned long long fcp_lun_t;
140/* data length field may be at variable position in FCP-2 FCP_CMND IU */
141typedef unsigned int fcp_dl_t;
142
143#define ZFCP_FC_SERVICE_CLASS_DEFAULT FSF_CLASS_3
144
145/* timeout for name-server lookup (in seconds) */
146#define ZFCP_NS_GID_PN_TIMEOUT 10
147
148/* largest SCSI command we can process */
149/* FCP-2 (FCP_CMND IU) allows up to (255-3+16) */
150#define ZFCP_MAX_SCSI_CMND_LENGTH 255
151/* maximum number of commands in LUN queue (tagged queueing) */
152#define ZFCP_CMND_PER_LUN 32
153
154/* task attribute values in FCP-2 FCP_CMND IU */
155#define SIMPLE_Q 0
156#define HEAD_OF_Q 1
157#define ORDERED_Q 2
158#define ACA_Q 4
159#define UNTAGGED 5
160
161/* task management flags in FCP-2 FCP_CMND IU */
162#define FCP_CLEAR_ACA 0x40
163#define FCP_TARGET_RESET 0x20
164#define FCP_LOGICAL_UNIT_RESET 0x10
165#define FCP_CLEAR_TASK_SET 0x04
166#define FCP_ABORT_TASK_SET 0x02
167
168#define FCP_CDB_LENGTH 16
169
170#define ZFCP_DID_MASK 0x00FFFFFF
171
172/* FCP(-2) FCP_CMND IU */
173struct fcp_cmnd_iu {
174 fcp_lun_t fcp_lun; /* FCP logical unit number */
175 u8 crn; /* command reference number */
176 u8 reserved0:5; /* reserved */
177 u8 task_attribute:3; /* task attribute */
178 u8 task_management_flags; /* task management flags */
179 u8 add_fcp_cdb_length:6; /* additional FCP_CDB length */
180 u8 rddata:1; /* read data */
181 u8 wddata:1; /* write data */
182 u8 fcp_cdb[FCP_CDB_LENGTH];
183} __attribute__((packed));
184
185/* FCP(-2) FCP_RSP IU */
186struct fcp_rsp_iu {
187 u8 reserved0[10];
188 union {
189 struct {
190 u8 reserved1:3;
191 u8 fcp_conf_req:1;
192 u8 fcp_resid_under:1;
193 u8 fcp_resid_over:1;
194 u8 fcp_sns_len_valid:1;
195 u8 fcp_rsp_len_valid:1;
196 } bits;
197 u8 value;
198 } validity;
199 u8 scsi_status;
200 u32 fcp_resid;
201 u32 fcp_sns_len;
202 u32 fcp_rsp_len;
203} __attribute__((packed));
204
205
206#define RSP_CODE_GOOD 0
207#define RSP_CODE_LENGTH_MISMATCH 1
208#define RSP_CODE_FIELD_INVALID 2
209#define RSP_CODE_RO_MISMATCH 3
210#define RSP_CODE_TASKMAN_UNSUPP 4
211#define RSP_CODE_TASKMAN_FAILED 5
212
213/* see fc-fs */
Christof Schmitt24073b42008-06-10 18:20:54 +0200214#define LS_RSCN 0x61
215#define LS_LOGO 0x05
216#define LS_PLOGI 0x03
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
218struct fcp_rscn_head {
219 u8 command;
220 u8 page_length; /* always 0x04 */
221 u16 payload_len;
222} __attribute__((packed));
223
224struct fcp_rscn_element {
225 u8 reserved:2;
226 u8 event_qual:4;
227 u8 addr_format:2;
228 u32 nport_did:24;
229} __attribute__((packed));
230
231#define ZFCP_PORT_ADDRESS 0x0
232#define ZFCP_AREA_ADDRESS 0x1
233#define ZFCP_DOMAIN_ADDRESS 0x2
234#define ZFCP_FABRIC_ADDRESS 0x3
235
236#define ZFCP_PORTS_RANGE_PORT 0xFFFFFF
237#define ZFCP_PORTS_RANGE_AREA 0xFFFF00
238#define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
239#define ZFCP_PORTS_RANGE_FABRIC 0x000000
240
241#define ZFCP_NO_PORTS_PER_AREA 0x100
242#define ZFCP_NO_PORTS_PER_DOMAIN 0x10000
243#define ZFCP_NO_PORTS_PER_FABRIC 0x1000000
244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245/* see fc-ph */
246struct fcp_logo {
247 u32 command;
248 u32 nport_did;
249 wwn_t nport_wwpn;
250} __attribute__((packed));
251
252/*
253 * FC-FS stuff
254 */
255#define R_A_TOV 10 /* seconds */
256#define ZFCP_ELS_TIMEOUT (2 * R_A_TOV)
257
258#define ZFCP_LS_RLS 0x0f
259#define ZFCP_LS_ADISC 0x52
260#define ZFCP_LS_RPS 0x56
261#define ZFCP_LS_RSCN 0x61
262#define ZFCP_LS_RNID 0x78
263
264struct zfcp_ls_rjt_par {
265 u8 action;
266 u8 reason_code;
267 u8 reason_expl;
268 u8 vendor_unique;
269} __attribute__ ((packed));
270
271struct zfcp_ls_adisc {
272 u8 code;
273 u8 field[3];
274 u32 hard_nport_id;
275 u64 wwpn;
276 u64 wwnn;
277 u32 nport_id;
278} __attribute__ ((packed));
279
280struct zfcp_ls_adisc_acc {
281 u8 code;
282 u8 field[3];
283 u32 hard_nport_id;
284 u64 wwpn;
285 u64 wwnn;
286 u32 nport_id;
287} __attribute__ ((packed));
288
289struct zfcp_rc_entry {
290 u8 code;
291 const char *description;
292};
293
294/*
295 * FC-GS-2 stuff
296 */
297#define ZFCP_CT_REVISION 0x01
298#define ZFCP_CT_DIRECTORY_SERVICE 0xFC
299#define ZFCP_CT_NAME_SERVER 0x02
300#define ZFCP_CT_SYNCHRONOUS 0x00
301#define ZFCP_CT_GID_PN 0x0121
302#define ZFCP_CT_MAX_SIZE 0x1020
303#define ZFCP_CT_ACCEPT 0x8002
304#define ZFCP_CT_REJECT 0x8001
305
306/*
307 * FC-GS-4 stuff
308 */
309#define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311/******************** LOGGING MACROS AND DEFINES *****************************/
312
313/*
314 * Logging may be applied on certain kinds of driver operations
315 * independently. Additionally, different log-levels are supported for
316 * each of these areas.
317 */
318
319#define ZFCP_NAME "zfcp"
320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321/* independent log areas */
322#define ZFCP_LOG_AREA_OTHER 0
323#define ZFCP_LOG_AREA_SCSI 1
324#define ZFCP_LOG_AREA_FSF 2
325#define ZFCP_LOG_AREA_CONFIG 3
326#define ZFCP_LOG_AREA_CIO 4
327#define ZFCP_LOG_AREA_QDIO 5
328#define ZFCP_LOG_AREA_ERP 6
329#define ZFCP_LOG_AREA_FC 7
330
331/* log level values*/
332#define ZFCP_LOG_LEVEL_NORMAL 0
333#define ZFCP_LOG_LEVEL_INFO 1
334#define ZFCP_LOG_LEVEL_DEBUG 2
335#define ZFCP_LOG_LEVEL_TRACE 3
336
337/*
338 * this allows removal of logging code by the preprocessor
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200339 * (the most detailed log level still to be compiled in is specified,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 * higher log levels are removed)
341 */
342#define ZFCP_LOG_LEVEL_LIMIT ZFCP_LOG_LEVEL_TRACE
343
344/* get "loglevel" nibble assignment */
345#define ZFCP_GET_LOG_VALUE(zfcp_lognibble) \
346 ((atomic_read(&zfcp_data.loglevel) >> (zfcp_lognibble<<2)) & 0xF)
347
348/* set "loglevel" nibble */
349#define ZFCP_SET_LOG_NIBBLE(value, zfcp_lognibble) \
350 (value << (zfcp_lognibble << 2))
351
352/* all log-level defaults are combined to generate initial log-level */
353#define ZFCP_LOG_LEVEL_DEFAULTS \
354 (ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_OTHER) | \
355 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_SCSI) | \
356 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FSF) | \
357 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CONFIG) | \
358 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CIO) | \
359 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_QDIO) | \
360 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_ERP) | \
361 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FC))
362
363/* check whether we have the right level for logging */
364#define ZFCP_LOG_CHECK(level) \
365 ((ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA)) >= level)
366
367/* logging routine for zfcp */
368#define _ZFCP_LOG(fmt, args...) \
Harvey Harrison2a2cf6b2008-04-17 07:46:21 +0200369 printk(KERN_ERR ZFCP_NAME": %s(%d): " fmt, __func__, \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 __LINE__ , ##args)
371
372#define ZFCP_LOG(level, fmt, args...) \
373do { \
374 if (ZFCP_LOG_CHECK(level)) \
375 _ZFCP_LOG(fmt, ##args); \
376} while (0)
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378#if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_NORMAL
Heiko Carstens39b083f2006-09-20 15:58:51 +0200379# define ZFCP_LOG_NORMAL(fmt, args...) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380#else
381# define ZFCP_LOG_NORMAL(fmt, args...) \
382do { \
383 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_NORMAL)) \
384 printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
385} while (0)
386#endif
387
388#if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_INFO
Heiko Carstens39b083f2006-09-20 15:58:51 +0200389# define ZFCP_LOG_INFO(fmt, args...) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390#else
391# define ZFCP_LOG_INFO(fmt, args...) \
392do { \
393 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_INFO)) \
394 printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
395} while (0)
396#endif
397
398#if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_DEBUG
Heiko Carstens39b083f2006-09-20 15:58:51 +0200399# define ZFCP_LOG_DEBUG(fmt, args...) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400#else
401# define ZFCP_LOG_DEBUG(fmt, args...) \
402 ZFCP_LOG(ZFCP_LOG_LEVEL_DEBUG, fmt , ##args)
403#endif
404
405#if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_TRACE
Heiko Carstens39b083f2006-09-20 15:58:51 +0200406# define ZFCP_LOG_TRACE(fmt, args...) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407#else
408# define ZFCP_LOG_TRACE(fmt, args...) \
409 ZFCP_LOG(ZFCP_LOG_LEVEL_TRACE, fmt , ##args)
410#endif
411
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412/*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
413
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200414/*
415 * Note, the leftmost status byte is common among adapter, port
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 * and unit
417 */
418#define ZFCP_COMMON_FLAGS 0xfff00000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
420/* common status bits */
421#define ZFCP_STATUS_COMMON_REMOVE 0x80000000
422#define ZFCP_STATUS_COMMON_RUNNING 0x40000000
423#define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
424#define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
425#define ZFCP_STATUS_COMMON_OPENING 0x08000000
426#define ZFCP_STATUS_COMMON_OPEN 0x04000000
427#define ZFCP_STATUS_COMMON_CLOSING 0x02000000
428#define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
429#define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
Andreas Herrmannd736a272005-06-13 13:23:57 +0200430#define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
432/* adapter status */
433#define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
434#define ZFCP_STATUS_ADAPTER_REGISTERED 0x00000004
435#define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
436#define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
437#define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
438#define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
439#define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
440#define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200441#define ZFCP_STATUS_ADAPTER_XPORT_OK 0x00000800
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443/* FC-PH/FC-GS well-known address identifiers for generic services */
444#define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA
445#define ZFCP_DID_TIME_SERVICE 0xFFFFFB
446#define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC
447#define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8
448#define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7
449
450/* remote port status */
451#define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
452#define ZFCP_STATUS_PORT_DID_DID 0x00000002
453#define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
454#define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
455#define ZFCP_STATUS_PORT_NO_SCSI_ID 0x00000010
456#define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
458/* for ports with well known addresses */
459#define ZFCP_STATUS_PORT_WKA \
460 (ZFCP_STATUS_PORT_NO_WWPN | \
461 ZFCP_STATUS_PORT_NO_SCSI_ID)
462
463/* logical unit status */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464#define ZFCP_STATUS_UNIT_TEMPORARY 0x00000002
465#define ZFCP_STATUS_UNIT_SHARED 0x00000004
466#define ZFCP_STATUS_UNIT_READONLY 0x00000008
Andreas Herrmannad58f7d2006-03-10 00:56:16 +0100467#define ZFCP_STATUS_UNIT_REGISTERED 0x00000010
Christof Schmitt5f852be2007-05-08 11:16:52 +0200468#define ZFCP_STATUS_UNIT_SCSI_WORK_PENDING 0x00000020
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
470/* FSF request status (this does not have a common part) */
471#define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000
472#define ZFCP_STATUS_FSFREQ_POOL 0x00000001
473#define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
474#define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
475#define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
476#define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
477#define ZFCP_STATUS_FSFREQ_ABORTING 0x00000020
478#define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
479#define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
480#define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
481#define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
482#define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
483#define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
484#define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
485
486/*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
487
488#define ZFCP_MAX_ERPS 3
489
490#define ZFCP_ERP_FSFREQ_TIMEOUT (30 * HZ)
491#define ZFCP_ERP_MEMWAIT_TIMEOUT HZ
492
493#define ZFCP_STATUS_ERP_TIMEDOUT 0x10000000
494#define ZFCP_STATUS_ERP_CLOSE_ONLY 0x01000000
495#define ZFCP_STATUS_ERP_DISMISSING 0x00100000
496#define ZFCP_STATUS_ERP_DISMISSED 0x00200000
497#define ZFCP_STATUS_ERP_LOWMEM 0x00400000
498
499#define ZFCP_ERP_STEP_UNINITIALIZED 0x00000000
500#define ZFCP_ERP_STEP_FSF_XCONFIG 0x00000001
501#define ZFCP_ERP_STEP_PHYS_PORT_CLOSING 0x00000010
502#define ZFCP_ERP_STEP_PORT_CLOSING 0x00000100
503#define ZFCP_ERP_STEP_NAMESERVER_OPEN 0x00000200
504#define ZFCP_ERP_STEP_NAMESERVER_LOOKUP 0x00000400
505#define ZFCP_ERP_STEP_PORT_OPENING 0x00000800
506#define ZFCP_ERP_STEP_UNIT_CLOSING 0x00001000
507#define ZFCP_ERP_STEP_UNIT_OPENING 0x00002000
508
509/* Ordered by escalation level (necessary for proper erp-code operation) */
510#define ZFCP_ERP_ACTION_REOPEN_ADAPTER 0x4
511#define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED 0x3
512#define ZFCP_ERP_ACTION_REOPEN_PORT 0x2
513#define ZFCP_ERP_ACTION_REOPEN_UNIT 0x1
514
515#define ZFCP_ERP_ACTION_RUNNING 0x1
516#define ZFCP_ERP_ACTION_READY 0x2
517
518#define ZFCP_ERP_SUCCEEDED 0x0
519#define ZFCP_ERP_FAILED 0x1
520#define ZFCP_ERP_CONTINUES 0x2
521#define ZFCP_ERP_EXIT 0x3
522#define ZFCP_ERP_DISMISSED 0x4
523#define ZFCP_ERP_NOMEM 0x5
524
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525/************************* STRUCTURE DEFINITIONS *****************************/
526
527struct zfcp_fsf_req;
528
529/* holds various memory pools of an adapter */
530struct zfcp_adapter_mempool {
531 mempool_t *fsf_req_erp;
532 mempool_t *fsf_req_scsi;
533 mempool_t *fsf_req_abort;
534 mempool_t *fsf_req_status_read;
535 mempool_t *data_status_read;
536 mempool_t *data_gid_pn;
537};
538
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539/*
540 * header for CT_IU
541 */
542struct ct_hdr {
543 u8 revision; // 0x01
544 u8 in_id[3]; // 0x00
545 u8 gs_type; // 0xFC Directory Service
546 u8 gs_subtype; // 0x02 Name Server
547 u8 options; // 0x00 single bidirectional exchange
548 u8 reserved0;
549 u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT
550 u16 max_res_size; // <= (4096 - 16) / 4
551 u8 reserved1;
552 u8 reason_code;
553 u8 reason_code_expl;
554 u8 vendor_unique;
555} __attribute__ ((packed));
556
557/* nameserver request CT_IU -- for requests where
558 * a port name is required */
559struct ct_iu_gid_pn_req {
560 struct ct_hdr header;
561 wwn_t wwpn;
562} __attribute__ ((packed));
563
564/* FS_ACC IU and data unit for GID_PN nameserver request */
565struct ct_iu_gid_pn_resp {
566 struct ct_hdr header;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200567 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568} __attribute__ ((packed));
569
570typedef void (*zfcp_send_ct_handler_t)(unsigned long);
571
572/**
573 * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
574 * @port: port where the request is sent to
575 * @req: scatter-gather list for request
576 * @resp: scatter-gather list for response
577 * @req_count: number of elements in request scatter-gather list
578 * @resp_count: number of elements in response scatter-gather list
579 * @handler: handler function (called for response to the request)
580 * @handler_data: data passed to handler function
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 * @timeout: FSF timeout for this request
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 * @completion: completion for synchronization purposes
583 * @status: used to pass error status to calling function
584 */
585struct zfcp_send_ct {
586 struct zfcp_port *port;
587 struct scatterlist *req;
588 struct scatterlist *resp;
589 unsigned int req_count;
590 unsigned int resp_count;
591 zfcp_send_ct_handler_t handler;
592 unsigned long handler_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 int timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 struct completion *completion;
595 int status;
596};
597
598/* used for name server requests in error recovery */
599struct zfcp_gid_pn_data {
600 struct zfcp_send_ct ct;
601 struct scatterlist req;
602 struct scatterlist resp;
603 struct ct_iu_gid_pn_req ct_iu_req;
604 struct ct_iu_gid_pn_resp ct_iu_resp;
605 struct zfcp_port *port;
606};
607
608typedef void (*zfcp_send_els_handler_t)(unsigned long);
609
610/**
611 * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
612 * @adapter: adapter where request is sent from
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200613 * @port: port where ELS is destinated (port reference count has to be increased)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 * @d_id: destiniation id of port where request is sent to
615 * @req: scatter-gather list for request
616 * @resp: scatter-gather list for response
617 * @req_count: number of elements in request scatter-gather list
618 * @resp_count: number of elements in response scatter-gather list
619 * @handler: handler function (called for response to the request)
620 * @handler_data: data passed to handler function
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 * @completion: completion for synchronization purposes
622 * @ls_code: hex code of ELS command
623 * @status: used to pass error status to calling function
624 */
625struct zfcp_send_els {
626 struct zfcp_adapter *adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200627 struct zfcp_port *port;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200628 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 struct scatterlist *req;
630 struct scatterlist *resp;
631 unsigned int req_count;
632 unsigned int resp_count;
633 zfcp_send_els_handler_t handler;
634 unsigned long handler_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 struct completion *completion;
636 int ls_code;
637 int status;
638};
639
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640struct zfcp_qdio_queue {
Swen Schillig00bab912008-06-10 18:20:57 +0200641 struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
642 u8 first; /* index of next free bfr
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 in queue (free_count>0) */
Swen Schillig00bab912008-06-10 18:20:57 +0200644 atomic_t count; /* number of free buffers
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 in queue */
Swen Schillig00bab912008-06-10 18:20:57 +0200646 rwlock_t lock; /* lock for operations on queue */
647 int pci_batch; /* SBALs since PCI indication
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 was last set */
649};
650
651struct zfcp_erp_action {
652 struct list_head list;
653 int action; /* requested action code */
654 struct zfcp_adapter *adapter; /* device which should be recovered */
655 struct zfcp_port *port;
656 struct zfcp_unit *unit;
657 volatile u32 status; /* recovery status */
658 u32 step; /* active step of this erp action */
659 struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
660 for this action */
661 struct timer_list timer;
662};
663
Christof Schmittc9615852008-05-06 11:00:05 +0200664struct fsf_latency_record {
665 u32 min;
666 u32 max;
667 u64 sum;
668};
669
670struct latency_cont {
671 struct fsf_latency_record channel;
672 struct fsf_latency_record fabric;
673 u64 counter;
674};
675
676struct zfcp_latencies {
677 struct latency_cont read;
678 struct latency_cont write;
679 struct latency_cont cmd;
680 spinlock_t lock;
681};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
683struct zfcp_adapter {
684 struct list_head list; /* list of adapters */
685 atomic_t refcount; /* reference count */
686 wait_queue_head_t remove_wq; /* can be used to wait for
687 refcount drop to zero */
6f71d9b2005-04-10 23:04:28 -0500688 wwn_t peer_wwnn; /* P2P peer WWNN */
689 wwn_t peer_wwpn; /* P2P peer WWPN */
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200690 u32 peer_d_id; /* P2P peer D_ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 struct ccw_device *ccw_device; /* S/390 ccw device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 u32 hydra_version; /* Hydra version */
693 u32 fsf_lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200694 u32 adapter_features; /* FCP channel features */
695 u32 connection_features; /* host connection features */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 u32 hardware_version; /* of FCP channel */
Christof Schmittc9615852008-05-06 11:00:05 +0200697 u16 timer_ticks; /* time int for a tick */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 struct list_head port_list_head; /* remote port list */
700 struct list_head port_remove_lh; /* head of ports to be
701 removed */
702 u32 ports; /* number of remote ports */
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200703 unsigned long req_no; /* unique FSF req number */
704 struct list_head *req_list; /* list of pending reqs */
705 spinlock_t req_list_lock; /* request list lock */
Swen Schillig00bab912008-06-10 18:20:57 +0200706 struct zfcp_qdio_queue req_q; /* request queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 u32 fsf_req_seq_no; /* FSF cmnd seq number */
708 wait_queue_head_t request_wq; /* can be used to wait for
709 more avaliable SBALs */
Swen Schillig00bab912008-06-10 18:20:57 +0200710 struct zfcp_qdio_queue resp_q; /* response queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 rwlock_t abort_lock; /* Protects against SCSI
712 stack abort/command
713 completion races */
Swen Schilligd26ab062008-05-19 12:17:37 +0200714 atomic_t stat_miss; /* # missing status reads*/
715 struct work_struct stat_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 atomic_t status; /* status of this adapter */
717 struct list_head erp_ready_head; /* error recovery for this
718 adapter/devices */
719 struct list_head erp_running_head;
720 rwlock_t erp_lock;
721 struct semaphore erp_ready_sem;
722 wait_queue_head_t erp_thread_wqh;
723 wait_queue_head_t erp_done_wqh;
724 struct zfcp_erp_action erp_action; /* pending error recovery */
725 atomic_t erp_counter;
726 u32 erp_total_count; /* total nr of enqueued erp
727 actions */
728 u32 erp_low_mem_count; /* nr of erp actions waiting
729 for memory */
730 struct zfcp_port *nameserver_port; /* adapter's nameserver */
Martin Peschked79a83d2008-03-27 14:22:00 +0100731 debug_info_t *rec_dbf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200732 debug_info_t *hba_dbf;
733 debug_info_t *san_dbf; /* debug feature areas */
734 debug_info_t *scsi_dbf;
Martin Peschked79a83d2008-03-27 14:22:00 +0100735 spinlock_t rec_dbf_lock;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200736 spinlock_t hba_dbf_lock;
737 spinlock_t san_dbf_lock;
738 spinlock_t scsi_dbf_lock;
Martin Peschked79a83d2008-03-27 14:22:00 +0100739 struct zfcp_rec_dbf_record rec_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200740 struct zfcp_hba_dbf_record hba_dbf_buf;
741 struct zfcp_san_dbf_record san_dbf_buf;
742 struct zfcp_scsi_dbf_record scsi_dbf_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 struct zfcp_adapter_mempool pool; /* Adapter memory pools */
744 struct qdio_initialize qdio_init_data; /* for qdio_establish */
745 struct device generic_services; /* directory for WKA ports */
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100746 struct fc_host_statistics *fc_stats;
747 struct fsf_qtcb_bottom_port *stats_reset_data;
748 unsigned long stats_reset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749};
750
751/*
752 * the struct device sysfs_device must be at the beginning of this structure.
753 * pointer to struct device is used to free port structure in release function
754 * of the device. don't change!
755 */
756struct zfcp_port {
757 struct device sysfs_device; /* sysfs device */
Andreas Herrmann3859f6a2005-08-27 11:07:54 -0700758 struct fc_rport *rport; /* rport of fc transport class */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 struct list_head list; /* list of remote ports */
760 atomic_t refcount; /* reference count */
761 wait_queue_head_t remove_wq; /* can be used to wait for
762 refcount drop to zero */
763 struct zfcp_adapter *adapter; /* adapter used to access port */
764 struct list_head unit_list_head; /* head of logical unit list */
765 struct list_head unit_remove_lh; /* head of luns to be removed
766 list */
767 u32 units; /* # of logical units in list */
768 atomic_t status; /* status of this remote port */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 wwn_t wwnn; /* WWNN if known */
770 wwn_t wwpn; /* WWPN */
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200771 u32 d_id; /* D_ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 u32 handle; /* handle assigned by FSF */
773 struct zfcp_erp_action erp_action; /* pending error recovery */
774 atomic_t erp_counter;
Ralph Wuerthner75bfc282006-05-22 18:24:33 +0200775 u32 maxframe_size;
776 u32 supported_classes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777};
778
779/* the struct device sysfs_device must be at the beginning of this structure.
780 * pointer to struct device is used to free unit structure in release function
781 * of the device. don't change!
782 */
783struct zfcp_unit {
784 struct device sysfs_device; /* sysfs device */
785 struct list_head list; /* list of logical units */
786 atomic_t refcount; /* reference count */
787 wait_queue_head_t remove_wq; /* can be used to wait for
788 refcount drop to zero */
789 struct zfcp_port *port; /* remote port of unit */
790 atomic_t status; /* status of this logical unit */
Andreas Herrmann06506d02006-05-22 18:18:19 +0200791 unsigned int scsi_lun; /* own SCSI LUN */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 fcp_lun_t fcp_lun; /* own FCP_LUN */
793 u32 handle; /* handle assigned by FSF */
794 struct scsi_device *device; /* scsi device struct pointer */
795 struct zfcp_erp_action erp_action; /* pending error recovery */
796 atomic_t erp_counter;
Christof Schmittc9615852008-05-06 11:00:05 +0200797 struct zfcp_latencies latencies;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798};
799
800/* FSF request */
801struct zfcp_fsf_req {
802 struct list_head list; /* list of FSF requests */
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200803 unsigned long req_id; /* unique request ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 struct zfcp_adapter *adapter; /* adapter request belongs to */
805 u8 sbal_number; /* nr of SBALs free for use */
806 u8 sbal_first; /* first SBAL for this request */
Martin Peschkee891bff2008-05-19 12:17:43 +0200807 u8 sbal_last; /* last SBAL for this request */
Martin Peschked01d51b2008-05-19 12:17:42 +0200808 u8 sbal_limit; /* last possible SBAL for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 this reuest */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 u8 sbale_curr; /* current SBALE during creation
811 of request */
Martin Peschkec3baa9a22008-05-19 12:17:44 +0200812 u8 sbal_response; /* SBAL used in interrupt */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 wait_queue_head_t completion_wq; /* can be used by a routine
814 to wait for completion */
815 volatile u32 status; /* status of this request */
816 u32 fsf_command; /* FSF Command copy */
817 struct fsf_qtcb *qtcb; /* address of associated QTCB */
818 u32 seq_no; /* Sequence number of request */
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200819 unsigned long data; /* private data of request */
820 struct timer_list timer; /* used for erp or scsi er */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 struct zfcp_erp_action *erp_action; /* used if this request is
822 issued on behalf of erp */
823 mempool_t *pool; /* used if request was alloacted
824 from emergency pool */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200825 unsigned long long issued; /* request sent time (STCK) */
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200826 struct zfcp_unit *unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827};
828
829typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
830
831/* driver data */
832struct zfcp_data {
833 struct scsi_host_template scsi_host_template;
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200834 struct scsi_transport_template *scsi_transport_template;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 atomic_t status; /* Module status flags */
836 struct list_head adapter_list_head; /* head of adapter list */
837 struct list_head adapter_remove_lh; /* head of adapters to be
838 removed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 u32 adapters; /* # of adapters in list */
840 rwlock_t config_lock; /* serialises changes
841 to adapter/port/unit
842 lists */
843 struct semaphore config_sema; /* serialises configuration
844 changes */
845 atomic_t loglevel; /* current loglevel */
846 char init_busid[BUS_ID_SIZE];
847 wwn_t init_wwpn;
848 fcp_lun_t init_fcp_lun;
849 char *driver_version;
Christoph Lametere18b8902006-12-06 20:33:20 -0800850 struct kmem_cache *fsf_req_qtcb_cache;
851 struct kmem_cache *sr_buffer_cache;
852 struct kmem_cache *gid_pn_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853};
854
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855/* number of elements for various memory pools */
856#define ZFCP_POOL_FSF_REQ_ERP_NR 1
857#define ZFCP_POOL_FSF_REQ_SCSI_NR 1
858#define ZFCP_POOL_FSF_REQ_ABORT_NR 1
859#define ZFCP_POOL_STATUS_READ_NR ZFCP_STATUS_READS_RECOM
860#define ZFCP_POOL_DATA_GID_PN_NR 1
861
862/* struct used by memory pools for fsf_requests */
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200863struct zfcp_fsf_req_qtcb {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 struct zfcp_fsf_req fsf_req;
865 struct fsf_qtcb qtcb;
866};
867
868/********************** ZFCP SPECIFIC DEFINES ********************************/
869
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870#define ZFCP_REQ_AUTO_CLEANUP 0x00000002
871#define ZFCP_WAIT_FOR_SBAL 0x00000004
872#define ZFCP_REQ_NO_QTCB 0x00000008
873
874#define ZFCP_SET 0x00000100
875#define ZFCP_CLEAR 0x00000200
876
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877#ifndef atomic_test_mask
878#define atomic_test_mask(mask, target) \
879 ((atomic_read(target) & mask) == mask)
880#endif
881
882extern void _zfcp_hex_dump(char *, int);
883#define ZFCP_HEX_DUMP(level, addr, count) \
884 if (ZFCP_LOG_CHECK(level)) { \
885 _zfcp_hex_dump(addr, count); \
886 }
887
888#define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
889#define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
890#define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
891
892/*
Heiko Carstensca2d02c2007-05-08 11:17:54 +0200893 * Helper functions for request ID management.
894 */
895static inline int zfcp_reqlist_hash(unsigned long req_id)
896{
897 return req_id % REQUEST_LIST_SIZE;
898}
899
900static inline void zfcp_reqlist_add(struct zfcp_adapter *adapter,
901 struct zfcp_fsf_req *fsf_req)
902{
903 unsigned int idx;
904
905 idx = zfcp_reqlist_hash(fsf_req->req_id);
906 list_add_tail(&fsf_req->list, &adapter->req_list[idx]);
907}
908
909static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
910 struct zfcp_fsf_req *fsf_req)
911{
912 list_del(&fsf_req->list);
913}
914
915static inline struct zfcp_fsf_req *
916zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
917{
918 struct zfcp_fsf_req *request;
919 unsigned int idx;
920
921 idx = zfcp_reqlist_hash(req_id);
922 list_for_each_entry(request, &adapter->req_list[idx], list)
923 if (request->req_id == req_id)
924 return request;
925 return NULL;
926}
927
Heiko Carstensd1ad09d2007-12-20 12:30:22 +0100928static inline struct zfcp_fsf_req *
929zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req)
930{
931 struct zfcp_fsf_req *request;
932 unsigned int idx;
933
934 for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) {
935 list_for_each_entry(request, &adapter->req_list[idx], list)
936 if (request == req)
937 return request;
938 }
939 return NULL;
940}
941
Heiko Carstensca2d02c2007-05-08 11:17:54 +0200942/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 * functions needed for reference/usage counting
944 */
945
946static inline void
947zfcp_unit_get(struct zfcp_unit *unit)
948{
949 atomic_inc(&unit->refcount);
950}
951
952static inline void
953zfcp_unit_put(struct zfcp_unit *unit)
954{
955 if (atomic_dec_return(&unit->refcount) == 0)
956 wake_up(&unit->remove_wq);
957}
958
959static inline void
960zfcp_unit_wait(struct zfcp_unit *unit)
961{
962 wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
963}
964
965static inline void
966zfcp_port_get(struct zfcp_port *port)
967{
968 atomic_inc(&port->refcount);
969}
970
971static inline void
972zfcp_port_put(struct zfcp_port *port)
973{
974 if (atomic_dec_return(&port->refcount) == 0)
975 wake_up(&port->remove_wq);
976}
977
978static inline void
979zfcp_port_wait(struct zfcp_port *port)
980{
981 wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
982}
983
984static inline void
985zfcp_adapter_get(struct zfcp_adapter *adapter)
986{
987 atomic_inc(&adapter->refcount);
988}
989
990static inline void
991zfcp_adapter_put(struct zfcp_adapter *adapter)
992{
993 if (atomic_dec_return(&adapter->refcount) == 0)
994 wake_up(&adapter->remove_wq);
995}
996
997static inline void
998zfcp_adapter_wait(struct zfcp_adapter *adapter)
999{
1000 wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
1001}
1002
1003#endif /* ZFCP_DEF_H */