blob: fdd5520eb3d2aa4b83cd037f6b6f84a6a11ad7f4 [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>
29#include <linux/miscdevice.h>
30#include <linux/major.h>
31#include <linux/blkdev.h>
32#include <linux/delay.h>
33#include <linux/timer.h>
Heiko Carstensdd52e0e2006-09-18 22:28:49 +020034#include <linux/slab.h>
35#include <linux/mempool.h>
36#include <linux/syscalls.h>
FUJITA Tomonorif1346372007-07-30 23:01:32 +090037#include <linux/scatterlist.h>
Heiko Carstensdd52e0e2006-09-18 22:28:49 +020038#include <linux/ioctl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <scsi/scsi.h>
40#include <scsi/scsi_tcq.h>
41#include <scsi/scsi_cmnd.h>
42#include <scsi/scsi_device.h>
43#include <scsi/scsi_host.h>
44#include <scsi/scsi_transport.h>
45#include <scsi/scsi_transport_fc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <asm/ccwdev.h>
47#include <asm/qdio.h>
48#include <asm/debug.h>
49#include <asm/ebcdic.h>
Christof Schmitt2b604c92008-03-31 11:15:28 +020050#include "zfcp_dbf.h"
Heiko Carstensdd52e0e2006-09-18 22:28:49 +020051#include "zfcp_fsf.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54/********************* GENERAL DEFINES *********************************/
55
56/* zfcp version number, it consists of major, minor, and patch-level number */
Andreas Herrmann58b3ac02006-08-02 11:06:21 +020057#define ZFCP_VERSION "4.8.0"
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59/**
60 * zfcp_sg_to_address - determine kernel address from struct scatterlist
61 * @list: struct scatterlist
62 * Return: kernel address
63 */
64static inline void *
65zfcp_sg_to_address(struct scatterlist *list)
66{
Jens Axboe73fc4f02007-10-23 09:17:53 +020067 return sg_virt(list);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068}
69
70/**
71 * zfcp_address_to_sg - set up struct scatterlist from kernel address
72 * @address: kernel address
73 * @list: struct scatterlist
Jens Axboe933543292007-10-26 13:55:40 +020074 * @size: buffer size
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 */
76static inline void
Jens Axboe933543292007-10-26 13:55:40 +020077zfcp_address_to_sg(void *address, struct scatterlist *list, unsigned int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
Jens Axboe933543292007-10-26 13:55:40 +020079 sg_set_buf(list, address, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
81
Andreas Herrmann06506d02006-05-22 18:18:19 +020082#define REQUEST_LIST_SIZE 128
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084/********************* SCSI SPECIFIC DEFINES *********************************/
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +020085#define ZFCP_SCSI_ER_TIMEOUT (10*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87/********************* CIO/QDIO SPECIFIC DEFINES *****************************/
88
89/* Adapter Identification Parameters */
90#define ZFCP_CONTROL_UNIT_TYPE 0x1731
91#define ZFCP_CONTROL_UNIT_MODEL 0x03
92#define ZFCP_DEVICE_TYPE 0x1732
93#define ZFCP_DEVICE_MODEL 0x03
94#define ZFCP_DEVICE_MODEL_PRIV 0x04
Swen Schillig41fa2ad2007-09-07 09:15:31 +020095
Linus Torvalds1da177e2005-04-16 15:20:36 -070096/* allow as many chained SBALs as are supported by hardware */
97#define ZFCP_MAX_SBALS_PER_REQ FSF_MAX_SBALS_PER_REQ
98#define ZFCP_MAX_SBALS_PER_CT_REQ FSF_MAX_SBALS_PER_REQ
99#define ZFCP_MAX_SBALS_PER_ELS_REQ FSF_MAX_SBALS_PER_ELS_REQ
100
101/* DMQ bug workaround: don't use last SBALE */
102#define ZFCP_MAX_SBALES_PER_SBAL (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
103
104/* index of last SBALE (with respect to DMQ bug workaround) */
105#define ZFCP_LAST_SBALE_PER_SBAL (ZFCP_MAX_SBALES_PER_SBAL - 1)
106
107/* max. number of (data buffer) SBALEs in largest SBAL chain */
108#define ZFCP_MAX_SBALES_PER_REQ \
109 (ZFCP_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
110 /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
111
Swen Schillig8d1a0062006-10-12 11:43:44 +0200112#define ZFCP_MAX_SECTORS (ZFCP_MAX_SBALES_PER_REQ * 8)
113 /* max. number of (data buffer) SBALEs in largest SBAL chain
114 multiplied with number of sectors per 4k block */
115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116/* FIXME(tune): free space should be one max. SBAL chain plus what? */
117#define ZFCP_QDIO_PCI_INTERVAL (QDIO_MAX_BUFFERS_PER_Q \
118 - (ZFCP_MAX_SBALS_PER_REQ + 4))
119
120#define ZFCP_SBAL_TIMEOUT (5*HZ)
121
Christof Schmitt18edcdb2007-11-05 12:37:45 +0100122#define ZFCP_TYPE2_RECOVERY_TIME 8 /* seconds */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124/* queue polling (values in microseconds) */
125#define ZFCP_MAX_INPUT_THRESHOLD 5000 /* FIXME: tune */
126#define ZFCP_MAX_OUTPUT_THRESHOLD 1000 /* FIXME: tune */
127#define ZFCP_MIN_INPUT_THRESHOLD 1 /* ignored by QDIO layer */
128#define ZFCP_MIN_OUTPUT_THRESHOLD 1 /* ignored by QDIO layer */
129
130#define QDIO_SCSI_QFMT 1 /* 1 for FSF */
Swen Schilligb4e44592007-07-18 10:55:13 +0200131#define QBUFF_PER_PAGE (PAGE_SIZE / sizeof(struct qdio_buffer))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133/********************* FSF SPECIFIC DEFINES *********************************/
134
135#define ZFCP_ULP_INFO_VERSION 26
136#define ZFCP_QTCB_VERSION FSF_QTCB_CURRENT_VERSION
137/* ATTENTION: value must not be used by hardware */
138#define FSF_QTCB_UNSOLICITED_STATUS 0x6305
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#define ZFCP_STATUS_READS_RECOM FSF_STATUS_READS_RECOM
Andreas Herrmann22753fa2005-06-13 13:15:15 +0200140
141/* Do 1st retry in 1 second, then double the timeout for each following retry */
Christof Schmitt18edcdb2007-11-05 12:37:45 +0100142#define ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP 1
Andreas Herrmann22753fa2005-06-13 13:15:15 +0200143#define ZFCP_EXCHANGE_CONFIG_DATA_RETRIES 7
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145/* timeout value for "default timer" for fsf requests */
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200146#define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148/*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
149
150typedef unsigned long long wwn_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151typedef unsigned long long fcp_lun_t;
152/* data length field may be at variable position in FCP-2 FCP_CMND IU */
153typedef unsigned int fcp_dl_t;
154
155#define ZFCP_FC_SERVICE_CLASS_DEFAULT FSF_CLASS_3
156
157/* timeout for name-server lookup (in seconds) */
158#define ZFCP_NS_GID_PN_TIMEOUT 10
159
160/* largest SCSI command we can process */
161/* FCP-2 (FCP_CMND IU) allows up to (255-3+16) */
162#define ZFCP_MAX_SCSI_CMND_LENGTH 255
163/* maximum number of commands in LUN queue (tagged queueing) */
164#define ZFCP_CMND_PER_LUN 32
165
166/* task attribute values in FCP-2 FCP_CMND IU */
167#define SIMPLE_Q 0
168#define HEAD_OF_Q 1
169#define ORDERED_Q 2
170#define ACA_Q 4
171#define UNTAGGED 5
172
173/* task management flags in FCP-2 FCP_CMND IU */
174#define FCP_CLEAR_ACA 0x40
175#define FCP_TARGET_RESET 0x20
176#define FCP_LOGICAL_UNIT_RESET 0x10
177#define FCP_CLEAR_TASK_SET 0x04
178#define FCP_ABORT_TASK_SET 0x02
179
180#define FCP_CDB_LENGTH 16
181
182#define ZFCP_DID_MASK 0x00FFFFFF
183
184/* FCP(-2) FCP_CMND IU */
185struct fcp_cmnd_iu {
186 fcp_lun_t fcp_lun; /* FCP logical unit number */
187 u8 crn; /* command reference number */
188 u8 reserved0:5; /* reserved */
189 u8 task_attribute:3; /* task attribute */
190 u8 task_management_flags; /* task management flags */
191 u8 add_fcp_cdb_length:6; /* additional FCP_CDB length */
192 u8 rddata:1; /* read data */
193 u8 wddata:1; /* write data */
194 u8 fcp_cdb[FCP_CDB_LENGTH];
195} __attribute__((packed));
196
197/* FCP(-2) FCP_RSP IU */
198struct fcp_rsp_iu {
199 u8 reserved0[10];
200 union {
201 struct {
202 u8 reserved1:3;
203 u8 fcp_conf_req:1;
204 u8 fcp_resid_under:1;
205 u8 fcp_resid_over:1;
206 u8 fcp_sns_len_valid:1;
207 u8 fcp_rsp_len_valid:1;
208 } bits;
209 u8 value;
210 } validity;
211 u8 scsi_status;
212 u32 fcp_resid;
213 u32 fcp_sns_len;
214 u32 fcp_rsp_len;
215} __attribute__((packed));
216
217
218#define RSP_CODE_GOOD 0
219#define RSP_CODE_LENGTH_MISMATCH 1
220#define RSP_CODE_FIELD_INVALID 2
221#define RSP_CODE_RO_MISMATCH 3
222#define RSP_CODE_TASKMAN_UNSUPP 4
223#define RSP_CODE_TASKMAN_FAILED 5
224
225/* see fc-fs */
Andreas Herrmann06506d02006-05-22 18:18:19 +0200226#define LS_RSCN 0x61040000
227#define LS_LOGO 0x05000000
228#define LS_PLOGI 0x03000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
230struct fcp_rscn_head {
231 u8 command;
232 u8 page_length; /* always 0x04 */
233 u16 payload_len;
234} __attribute__((packed));
235
236struct fcp_rscn_element {
237 u8 reserved:2;
238 u8 event_qual:4;
239 u8 addr_format:2;
240 u32 nport_did:24;
241} __attribute__((packed));
242
243#define ZFCP_PORT_ADDRESS 0x0
244#define ZFCP_AREA_ADDRESS 0x1
245#define ZFCP_DOMAIN_ADDRESS 0x2
246#define ZFCP_FABRIC_ADDRESS 0x3
247
248#define ZFCP_PORTS_RANGE_PORT 0xFFFFFF
249#define ZFCP_PORTS_RANGE_AREA 0xFFFF00
250#define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
251#define ZFCP_PORTS_RANGE_FABRIC 0x000000
252
253#define ZFCP_NO_PORTS_PER_AREA 0x100
254#define ZFCP_NO_PORTS_PER_DOMAIN 0x10000
255#define ZFCP_NO_PORTS_PER_FABRIC 0x1000000
256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257/* see fc-ph */
258struct fcp_logo {
259 u32 command;
260 u32 nport_did;
261 wwn_t nport_wwpn;
262} __attribute__((packed));
263
264/*
265 * FC-FS stuff
266 */
267#define R_A_TOV 10 /* seconds */
268#define ZFCP_ELS_TIMEOUT (2 * R_A_TOV)
269
270#define ZFCP_LS_RLS 0x0f
271#define ZFCP_LS_ADISC 0x52
272#define ZFCP_LS_RPS 0x56
273#define ZFCP_LS_RSCN 0x61
274#define ZFCP_LS_RNID 0x78
275
276struct zfcp_ls_rjt_par {
277 u8 action;
278 u8 reason_code;
279 u8 reason_expl;
280 u8 vendor_unique;
281} __attribute__ ((packed));
282
283struct zfcp_ls_adisc {
284 u8 code;
285 u8 field[3];
286 u32 hard_nport_id;
287 u64 wwpn;
288 u64 wwnn;
289 u32 nport_id;
290} __attribute__ ((packed));
291
292struct zfcp_ls_adisc_acc {
293 u8 code;
294 u8 field[3];
295 u32 hard_nport_id;
296 u64 wwpn;
297 u64 wwnn;
298 u32 nport_id;
299} __attribute__ ((packed));
300
301struct zfcp_rc_entry {
302 u8 code;
303 const char *description;
304};
305
306/*
307 * FC-GS-2 stuff
308 */
309#define ZFCP_CT_REVISION 0x01
310#define ZFCP_CT_DIRECTORY_SERVICE 0xFC
311#define ZFCP_CT_NAME_SERVER 0x02
312#define ZFCP_CT_SYNCHRONOUS 0x00
313#define ZFCP_CT_GID_PN 0x0121
314#define ZFCP_CT_MAX_SIZE 0x1020
315#define ZFCP_CT_ACCEPT 0x8002
316#define ZFCP_CT_REJECT 0x8001
317
318/*
319 * FC-GS-4 stuff
320 */
321#define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323/******************** LOGGING MACROS AND DEFINES *****************************/
324
325/*
326 * Logging may be applied on certain kinds of driver operations
327 * independently. Additionally, different log-levels are supported for
328 * each of these areas.
329 */
330
331#define ZFCP_NAME "zfcp"
332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333/* independent log areas */
334#define ZFCP_LOG_AREA_OTHER 0
335#define ZFCP_LOG_AREA_SCSI 1
336#define ZFCP_LOG_AREA_FSF 2
337#define ZFCP_LOG_AREA_CONFIG 3
338#define ZFCP_LOG_AREA_CIO 4
339#define ZFCP_LOG_AREA_QDIO 5
340#define ZFCP_LOG_AREA_ERP 6
341#define ZFCP_LOG_AREA_FC 7
342
343/* log level values*/
344#define ZFCP_LOG_LEVEL_NORMAL 0
345#define ZFCP_LOG_LEVEL_INFO 1
346#define ZFCP_LOG_LEVEL_DEBUG 2
347#define ZFCP_LOG_LEVEL_TRACE 3
348
349/*
350 * this allows removal of logging code by the preprocessor
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200351 * (the most detailed log level still to be compiled in is specified,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 * higher log levels are removed)
353 */
354#define ZFCP_LOG_LEVEL_LIMIT ZFCP_LOG_LEVEL_TRACE
355
356/* get "loglevel" nibble assignment */
357#define ZFCP_GET_LOG_VALUE(zfcp_lognibble) \
358 ((atomic_read(&zfcp_data.loglevel) >> (zfcp_lognibble<<2)) & 0xF)
359
360/* set "loglevel" nibble */
361#define ZFCP_SET_LOG_NIBBLE(value, zfcp_lognibble) \
362 (value << (zfcp_lognibble << 2))
363
364/* all log-level defaults are combined to generate initial log-level */
365#define ZFCP_LOG_LEVEL_DEFAULTS \
366 (ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_OTHER) | \
367 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_SCSI) | \
368 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FSF) | \
369 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CONFIG) | \
370 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CIO) | \
371 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_QDIO) | \
372 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_ERP) | \
373 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FC))
374
375/* check whether we have the right level for logging */
376#define ZFCP_LOG_CHECK(level) \
377 ((ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA)) >= level)
378
379/* logging routine for zfcp */
380#define _ZFCP_LOG(fmt, args...) \
Harvey Harrison2a2cf6b2008-04-17 07:46:21 +0200381 printk(KERN_ERR ZFCP_NAME": %s(%d): " fmt, __func__, \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 __LINE__ , ##args)
383
384#define ZFCP_LOG(level, fmt, args...) \
385do { \
386 if (ZFCP_LOG_CHECK(level)) \
387 _ZFCP_LOG(fmt, ##args); \
388} while (0)
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200389
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390#if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_NORMAL
Heiko Carstens39b083f2006-09-20 15:58:51 +0200391# define ZFCP_LOG_NORMAL(fmt, args...) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392#else
393# define ZFCP_LOG_NORMAL(fmt, args...) \
394do { \
395 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_NORMAL)) \
396 printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
397} while (0)
398#endif
399
400#if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_INFO
Heiko Carstens39b083f2006-09-20 15:58:51 +0200401# define ZFCP_LOG_INFO(fmt, args...) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402#else
403# define ZFCP_LOG_INFO(fmt, args...) \
404do { \
405 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_INFO)) \
406 printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
407} while (0)
408#endif
409
410#if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_DEBUG
Heiko Carstens39b083f2006-09-20 15:58:51 +0200411# define ZFCP_LOG_DEBUG(fmt, args...) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412#else
413# define ZFCP_LOG_DEBUG(fmt, args...) \
414 ZFCP_LOG(ZFCP_LOG_LEVEL_DEBUG, fmt , ##args)
415#endif
416
417#if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_TRACE
Heiko Carstens39b083f2006-09-20 15:58:51 +0200418# define ZFCP_LOG_TRACE(fmt, args...) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419#else
420# define ZFCP_LOG_TRACE(fmt, args...) \
421 ZFCP_LOG(ZFCP_LOG_LEVEL_TRACE, fmt , ##args)
422#endif
423
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424/*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
425
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200426/*
427 * Note, the leftmost status byte is common among adapter, port
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 * and unit
429 */
430#define ZFCP_COMMON_FLAGS 0xfff00000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
432/* common status bits */
433#define ZFCP_STATUS_COMMON_REMOVE 0x80000000
434#define ZFCP_STATUS_COMMON_RUNNING 0x40000000
435#define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
436#define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
437#define ZFCP_STATUS_COMMON_OPENING 0x08000000
438#define ZFCP_STATUS_COMMON_OPEN 0x04000000
439#define ZFCP_STATUS_COMMON_CLOSING 0x02000000
440#define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
441#define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
Andreas Herrmannd736a272005-06-13 13:23:57 +0200442#define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
444/* adapter status */
445#define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
446#define ZFCP_STATUS_ADAPTER_REGISTERED 0x00000004
447#define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
448#define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
449#define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
450#define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
451#define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
452#define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200453#define ZFCP_STATUS_ADAPTER_XPORT_OK 0x00000800
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455/* FC-PH/FC-GS well-known address identifiers for generic services */
456#define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA
457#define ZFCP_DID_TIME_SERVICE 0xFFFFFB
458#define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC
459#define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8
460#define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7
461
462/* remote port status */
463#define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
464#define ZFCP_STATUS_PORT_DID_DID 0x00000002
465#define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
466#define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
467#define ZFCP_STATUS_PORT_NO_SCSI_ID 0x00000010
468#define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
470/* for ports with well known addresses */
471#define ZFCP_STATUS_PORT_WKA \
472 (ZFCP_STATUS_PORT_NO_WWPN | \
473 ZFCP_STATUS_PORT_NO_SCSI_ID)
474
475/* logical unit status */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476#define ZFCP_STATUS_UNIT_TEMPORARY 0x00000002
477#define ZFCP_STATUS_UNIT_SHARED 0x00000004
478#define ZFCP_STATUS_UNIT_READONLY 0x00000008
Andreas Herrmannad58f7d2006-03-10 00:56:16 +0100479#define ZFCP_STATUS_UNIT_REGISTERED 0x00000010
Christof Schmitt5f852be2007-05-08 11:16:52 +0200480#define ZFCP_STATUS_UNIT_SCSI_WORK_PENDING 0x00000020
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
482/* FSF request status (this does not have a common part) */
483#define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000
484#define ZFCP_STATUS_FSFREQ_POOL 0x00000001
485#define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
486#define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
487#define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
488#define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
489#define ZFCP_STATUS_FSFREQ_ABORTING 0x00000020
490#define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
491#define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
492#define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
493#define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
494#define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
495#define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
496#define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
497
498/*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
499
500#define ZFCP_MAX_ERPS 3
501
502#define ZFCP_ERP_FSFREQ_TIMEOUT (30 * HZ)
503#define ZFCP_ERP_MEMWAIT_TIMEOUT HZ
504
505#define ZFCP_STATUS_ERP_TIMEDOUT 0x10000000
506#define ZFCP_STATUS_ERP_CLOSE_ONLY 0x01000000
507#define ZFCP_STATUS_ERP_DISMISSING 0x00100000
508#define ZFCP_STATUS_ERP_DISMISSED 0x00200000
509#define ZFCP_STATUS_ERP_LOWMEM 0x00400000
510
511#define ZFCP_ERP_STEP_UNINITIALIZED 0x00000000
512#define ZFCP_ERP_STEP_FSF_XCONFIG 0x00000001
513#define ZFCP_ERP_STEP_PHYS_PORT_CLOSING 0x00000010
514#define ZFCP_ERP_STEP_PORT_CLOSING 0x00000100
515#define ZFCP_ERP_STEP_NAMESERVER_OPEN 0x00000200
516#define ZFCP_ERP_STEP_NAMESERVER_LOOKUP 0x00000400
517#define ZFCP_ERP_STEP_PORT_OPENING 0x00000800
518#define ZFCP_ERP_STEP_UNIT_CLOSING 0x00001000
519#define ZFCP_ERP_STEP_UNIT_OPENING 0x00002000
520
521/* Ordered by escalation level (necessary for proper erp-code operation) */
522#define ZFCP_ERP_ACTION_REOPEN_ADAPTER 0x4
523#define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED 0x3
524#define ZFCP_ERP_ACTION_REOPEN_PORT 0x2
525#define ZFCP_ERP_ACTION_REOPEN_UNIT 0x1
526
527#define ZFCP_ERP_ACTION_RUNNING 0x1
528#define ZFCP_ERP_ACTION_READY 0x2
529
530#define ZFCP_ERP_SUCCEEDED 0x0
531#define ZFCP_ERP_FAILED 0x1
532#define ZFCP_ERP_CONTINUES 0x2
533#define ZFCP_ERP_EXIT 0x3
534#define ZFCP_ERP_DISMISSED 0x4
535#define ZFCP_ERP_NOMEM 0x5
536
537
538/******************** CFDC SPECIFIC STUFF *****************************/
539
540/* Firewall data channel sense data record */
541struct zfcp_cfdc_sense_data {
542 u32 signature; /* Request signature */
543 u32 devno; /* FCP adapter device number */
544 u32 command; /* Command code */
545 u32 fsf_status; /* FSF request status and status qualifier */
546 u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
547 u8 payloads[256]; /* Access conflicts list */
548 u8 control_file[0]; /* Access control table */
549};
550
551#define ZFCP_CFDC_SIGNATURE 0xCFDCACDF
552
553#define ZFCP_CFDC_CMND_DOWNLOAD_NORMAL 0x00010001
554#define ZFCP_CFDC_CMND_DOWNLOAD_FORCE 0x00010101
555#define ZFCP_CFDC_CMND_FULL_ACCESS 0x00000201
556#define ZFCP_CFDC_CMND_RESTRICTED_ACCESS 0x00000401
557#define ZFCP_CFDC_CMND_UPLOAD 0x00010002
558
559#define ZFCP_CFDC_DOWNLOAD 0x00000001
560#define ZFCP_CFDC_UPLOAD 0x00000002
561#define ZFCP_CFDC_WITH_CONTROL_FILE 0x00010000
562
563#define ZFCP_CFDC_DEV_NAME "zfcp_cfdc"
564#define ZFCP_CFDC_DEV_MAJOR MISC_MAJOR
565#define ZFCP_CFDC_DEV_MINOR MISC_DYNAMIC_MINOR
566
567#define ZFCP_CFDC_MAX_CONTROL_FILE_SIZE 127 * 1024
568
569/************************* STRUCTURE DEFINITIONS *****************************/
570
571struct zfcp_fsf_req;
572
573/* holds various memory pools of an adapter */
574struct zfcp_adapter_mempool {
575 mempool_t *fsf_req_erp;
576 mempool_t *fsf_req_scsi;
577 mempool_t *fsf_req_abort;
578 mempool_t *fsf_req_status_read;
579 mempool_t *data_status_read;
580 mempool_t *data_gid_pn;
581};
582
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583/*
584 * header for CT_IU
585 */
586struct ct_hdr {
587 u8 revision; // 0x01
588 u8 in_id[3]; // 0x00
589 u8 gs_type; // 0xFC Directory Service
590 u8 gs_subtype; // 0x02 Name Server
591 u8 options; // 0x00 single bidirectional exchange
592 u8 reserved0;
593 u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT
594 u16 max_res_size; // <= (4096 - 16) / 4
595 u8 reserved1;
596 u8 reason_code;
597 u8 reason_code_expl;
598 u8 vendor_unique;
599} __attribute__ ((packed));
600
601/* nameserver request CT_IU -- for requests where
602 * a port name is required */
603struct ct_iu_gid_pn_req {
604 struct ct_hdr header;
605 wwn_t wwpn;
606} __attribute__ ((packed));
607
608/* FS_ACC IU and data unit for GID_PN nameserver request */
609struct ct_iu_gid_pn_resp {
610 struct ct_hdr header;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200611 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612} __attribute__ ((packed));
613
614typedef void (*zfcp_send_ct_handler_t)(unsigned long);
615
616/**
617 * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
618 * @port: port where the request is sent to
619 * @req: scatter-gather list for request
620 * @resp: scatter-gather list for response
621 * @req_count: number of elements in request scatter-gather list
622 * @resp_count: number of elements in response scatter-gather list
623 * @handler: handler function (called for response to the request)
624 * @handler_data: data passed to handler function
625 * @pool: pointer to memory pool for ct request structure
626 * @timeout: FSF timeout for this request
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 * @completion: completion for synchronization purposes
628 * @status: used to pass error status to calling function
629 */
630struct zfcp_send_ct {
631 struct zfcp_port *port;
632 struct scatterlist *req;
633 struct scatterlist *resp;
634 unsigned int req_count;
635 unsigned int resp_count;
636 zfcp_send_ct_handler_t handler;
637 unsigned long handler_data;
638 mempool_t *pool;
639 int timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 struct completion *completion;
641 int status;
642};
643
644/* used for name server requests in error recovery */
645struct zfcp_gid_pn_data {
646 struct zfcp_send_ct ct;
647 struct scatterlist req;
648 struct scatterlist resp;
649 struct ct_iu_gid_pn_req ct_iu_req;
650 struct ct_iu_gid_pn_resp ct_iu_resp;
651 struct zfcp_port *port;
652};
653
654typedef void (*zfcp_send_els_handler_t)(unsigned long);
655
656/**
657 * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
658 * @adapter: adapter where request is sent from
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200659 * @port: port where ELS is destinated (port reference count has to be increased)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 * @d_id: destiniation id of port where request is sent to
661 * @req: scatter-gather list for request
662 * @resp: scatter-gather list for response
663 * @req_count: number of elements in request scatter-gather list
664 * @resp_count: number of elements in response scatter-gather list
665 * @handler: handler function (called for response to the request)
666 * @handler_data: data passed to handler function
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 * @completion: completion for synchronization purposes
668 * @ls_code: hex code of ELS command
669 * @status: used to pass error status to calling function
670 */
671struct zfcp_send_els {
672 struct zfcp_adapter *adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200673 struct zfcp_port *port;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200674 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 struct scatterlist *req;
676 struct scatterlist *resp;
677 unsigned int req_count;
678 unsigned int resp_count;
679 zfcp_send_els_handler_t handler;
680 unsigned long handler_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 struct completion *completion;
682 int ls_code;
683 int status;
684};
685
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686struct zfcp_qdio_queue {
687 struct qdio_buffer *buffer[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
688 u8 free_index; /* index of next free bfr
689 in queue (free_count>0) */
690 atomic_t free_count; /* number of free buffers
691 in queue */
692 rwlock_t queue_lock; /* lock for operations on queue */
693 int distance_from_int; /* SBALs used since PCI indication
694 was last set */
695};
696
697struct zfcp_erp_action {
698 struct list_head list;
699 int action; /* requested action code */
700 struct zfcp_adapter *adapter; /* device which should be recovered */
701 struct zfcp_port *port;
702 struct zfcp_unit *unit;
703 volatile u32 status; /* recovery status */
704 u32 step; /* active step of this erp action */
705 struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
706 for this action */
707 struct timer_list timer;
708};
709
Christof Schmittc9615852008-05-06 11:00:05 +0200710struct fsf_latency_record {
711 u32 min;
712 u32 max;
713 u64 sum;
714};
715
716struct latency_cont {
717 struct fsf_latency_record channel;
718 struct fsf_latency_record fabric;
719 u64 counter;
720};
721
722struct zfcp_latencies {
723 struct latency_cont read;
724 struct latency_cont write;
725 struct latency_cont cmd;
726 spinlock_t lock;
727};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
729struct zfcp_adapter {
730 struct list_head list; /* list of adapters */
731 atomic_t refcount; /* reference count */
732 wait_queue_head_t remove_wq; /* can be used to wait for
733 refcount drop to zero */
6f71d9b2005-04-10 23:04:28 -0500734 wwn_t peer_wwnn; /* P2P peer WWNN */
735 wwn_t peer_wwpn; /* P2P peer WWPN */
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200736 u32 peer_d_id; /* P2P peer D_ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 struct ccw_device *ccw_device; /* S/390 ccw device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 u32 hydra_version; /* Hydra version */
739 u32 fsf_lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200740 u32 adapter_features; /* FCP channel features */
741 u32 connection_features; /* host connection features */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 u32 hardware_version; /* of FCP channel */
Christof Schmittc9615852008-05-06 11:00:05 +0200743 u16 timer_ticks; /* time int for a tick */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 struct list_head port_list_head; /* remote port list */
746 struct list_head port_remove_lh; /* head of ports to be
747 removed */
748 u32 ports; /* number of remote ports */
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200749 atomic_t reqs_active; /* # active FSF reqs */
750 unsigned long req_no; /* unique FSF req number */
751 struct list_head *req_list; /* list of pending reqs */
752 spinlock_t req_list_lock; /* request list lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 struct zfcp_qdio_queue request_queue; /* request queue */
754 u32 fsf_req_seq_no; /* FSF cmnd seq number */
755 wait_queue_head_t request_wq; /* can be used to wait for
756 more avaliable SBALs */
757 struct zfcp_qdio_queue response_queue; /* response queue */
758 rwlock_t abort_lock; /* Protects against SCSI
759 stack abort/command
760 completion races */
Swen Schilligd26ab062008-05-19 12:17:37 +0200761 atomic_t stat_miss; /* # missing status reads*/
762 struct work_struct stat_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 atomic_t status; /* status of this adapter */
764 struct list_head erp_ready_head; /* error recovery for this
765 adapter/devices */
766 struct list_head erp_running_head;
767 rwlock_t erp_lock;
768 struct semaphore erp_ready_sem;
769 wait_queue_head_t erp_thread_wqh;
770 wait_queue_head_t erp_done_wqh;
771 struct zfcp_erp_action erp_action; /* pending error recovery */
772 atomic_t erp_counter;
773 u32 erp_total_count; /* total nr of enqueued erp
774 actions */
775 u32 erp_low_mem_count; /* nr of erp actions waiting
776 for memory */
777 struct zfcp_port *nameserver_port; /* adapter's nameserver */
Martin Peschked79a83d2008-03-27 14:22:00 +0100778 debug_info_t *rec_dbf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200779 debug_info_t *hba_dbf;
780 debug_info_t *san_dbf; /* debug feature areas */
781 debug_info_t *scsi_dbf;
Martin Peschked79a83d2008-03-27 14:22:00 +0100782 spinlock_t rec_dbf_lock;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200783 spinlock_t hba_dbf_lock;
784 spinlock_t san_dbf_lock;
785 spinlock_t scsi_dbf_lock;
Martin Peschked79a83d2008-03-27 14:22:00 +0100786 struct zfcp_rec_dbf_record rec_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200787 struct zfcp_hba_dbf_record hba_dbf_buf;
788 struct zfcp_san_dbf_record san_dbf_buf;
789 struct zfcp_scsi_dbf_record scsi_dbf_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 struct zfcp_adapter_mempool pool; /* Adapter memory pools */
791 struct qdio_initialize qdio_init_data; /* for qdio_establish */
792 struct device generic_services; /* directory for WKA ports */
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100793 struct fc_host_statistics *fc_stats;
794 struct fsf_qtcb_bottom_port *stats_reset_data;
795 unsigned long stats_reset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796};
797
798/*
799 * the struct device sysfs_device must be at the beginning of this structure.
800 * pointer to struct device is used to free port structure in release function
801 * of the device. don't change!
802 */
803struct zfcp_port {
804 struct device sysfs_device; /* sysfs device */
Andreas Herrmann3859f6a2005-08-27 11:07:54 -0700805 struct fc_rport *rport; /* rport of fc transport class */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 struct list_head list; /* list of remote ports */
807 atomic_t refcount; /* reference count */
808 wait_queue_head_t remove_wq; /* can be used to wait for
809 refcount drop to zero */
810 struct zfcp_adapter *adapter; /* adapter used to access port */
811 struct list_head unit_list_head; /* head of logical unit list */
812 struct list_head unit_remove_lh; /* head of luns to be removed
813 list */
814 u32 units; /* # of logical units in list */
815 atomic_t status; /* status of this remote port */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 wwn_t wwnn; /* WWNN if known */
817 wwn_t wwpn; /* WWPN */
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200818 u32 d_id; /* D_ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 u32 handle; /* handle assigned by FSF */
820 struct zfcp_erp_action erp_action; /* pending error recovery */
821 atomic_t erp_counter;
Ralph Wuerthner75bfc282006-05-22 18:24:33 +0200822 u32 maxframe_size;
823 u32 supported_classes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824};
825
826/* the struct device sysfs_device must be at the beginning of this structure.
827 * pointer to struct device is used to free unit structure in release function
828 * of the device. don't change!
829 */
830struct zfcp_unit {
831 struct device sysfs_device; /* sysfs device */
832 struct list_head list; /* list of logical units */
833 atomic_t refcount; /* reference count */
834 wait_queue_head_t remove_wq; /* can be used to wait for
835 refcount drop to zero */
836 struct zfcp_port *port; /* remote port of unit */
837 atomic_t status; /* status of this logical unit */
Andreas Herrmann06506d02006-05-22 18:18:19 +0200838 unsigned int scsi_lun; /* own SCSI LUN */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 fcp_lun_t fcp_lun; /* own FCP_LUN */
840 u32 handle; /* handle assigned by FSF */
841 struct scsi_device *device; /* scsi device struct pointer */
842 struct zfcp_erp_action erp_action; /* pending error recovery */
843 atomic_t erp_counter;
Christof Schmittc9615852008-05-06 11:00:05 +0200844 struct zfcp_latencies latencies;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845};
846
847/* FSF request */
848struct zfcp_fsf_req {
849 struct list_head list; /* list of FSF requests */
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200850 unsigned long req_id; /* unique request ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 struct zfcp_adapter *adapter; /* adapter request belongs to */
852 u8 sbal_number; /* nr of SBALs free for use */
853 u8 sbal_first; /* first SBAL for this request */
Martin Peschked01d51b2008-05-19 12:17:42 +0200854 u8 sbal_limit; /* last possible SBAL for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 this reuest */
856 u8 sbal_curr; /* current SBAL during creation
857 of request */
858 u8 sbale_curr; /* current SBALE during creation
859 of request */
860 wait_queue_head_t completion_wq; /* can be used by a routine
861 to wait for completion */
862 volatile u32 status; /* status of this request */
863 u32 fsf_command; /* FSF Command copy */
864 struct fsf_qtcb *qtcb; /* address of associated QTCB */
865 u32 seq_no; /* Sequence number of request */
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200866 unsigned long data; /* private data of request */
867 struct timer_list timer; /* used for erp or scsi er */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 struct zfcp_erp_action *erp_action; /* used if this request is
869 issued on behalf of erp */
870 mempool_t *pool; /* used if request was alloacted
871 from emergency pool */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200872 unsigned long long issued; /* request sent time (STCK) */
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200873 struct zfcp_unit *unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874};
875
876typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
877
878/* driver data */
879struct zfcp_data {
880 struct scsi_host_template scsi_host_template;
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200881 struct scsi_transport_template *scsi_transport_template;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 atomic_t status; /* Module status flags */
883 struct list_head adapter_list_head; /* head of adapter list */
884 struct list_head adapter_remove_lh; /* head of adapters to be
885 removed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 u32 adapters; /* # of adapters in list */
887 rwlock_t config_lock; /* serialises changes
888 to adapter/port/unit
889 lists */
890 struct semaphore config_sema; /* serialises configuration
891 changes */
892 atomic_t loglevel; /* current loglevel */
893 char init_busid[BUS_ID_SIZE];
894 wwn_t init_wwpn;
895 fcp_lun_t init_fcp_lun;
896 char *driver_version;
Christoph Lametere18b8902006-12-06 20:33:20 -0800897 struct kmem_cache *fsf_req_qtcb_cache;
898 struct kmem_cache *sr_buffer_cache;
899 struct kmem_cache *gid_pn_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900};
901
902/**
903 * struct zfcp_sg_list - struct describing a scatter-gather list
904 * @sg: pointer to array of (struct scatterlist)
905 * @count: number of elements in scatter-gather list
906 */
907struct zfcp_sg_list {
908 struct scatterlist *sg;
909 unsigned int count;
910};
911
912/* number of elements for various memory pools */
913#define ZFCP_POOL_FSF_REQ_ERP_NR 1
914#define ZFCP_POOL_FSF_REQ_SCSI_NR 1
915#define ZFCP_POOL_FSF_REQ_ABORT_NR 1
916#define ZFCP_POOL_STATUS_READ_NR ZFCP_STATUS_READS_RECOM
917#define ZFCP_POOL_DATA_GID_PN_NR 1
918
919/* struct used by memory pools for fsf_requests */
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200920struct zfcp_fsf_req_qtcb {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 struct zfcp_fsf_req fsf_req;
922 struct fsf_qtcb qtcb;
923};
924
925/********************** ZFCP SPECIFIC DEFINES ********************************/
926
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927#define ZFCP_REQ_AUTO_CLEANUP 0x00000002
928#define ZFCP_WAIT_FOR_SBAL 0x00000004
929#define ZFCP_REQ_NO_QTCB 0x00000008
930
931#define ZFCP_SET 0x00000100
932#define ZFCP_CLEAR 0x00000200
933
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934#ifndef atomic_test_mask
935#define atomic_test_mask(mask, target) \
936 ((atomic_read(target) & mask) == mask)
937#endif
938
939extern void _zfcp_hex_dump(char *, int);
940#define ZFCP_HEX_DUMP(level, addr, count) \
941 if (ZFCP_LOG_CHECK(level)) { \
942 _zfcp_hex_dump(addr, count); \
943 }
944
945#define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
946#define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
947#define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
948
949/*
Heiko Carstensca2d02c2007-05-08 11:17:54 +0200950 * Helper functions for request ID management.
951 */
952static inline int zfcp_reqlist_hash(unsigned long req_id)
953{
954 return req_id % REQUEST_LIST_SIZE;
955}
956
957static inline void zfcp_reqlist_add(struct zfcp_adapter *adapter,
958 struct zfcp_fsf_req *fsf_req)
959{
960 unsigned int idx;
961
962 idx = zfcp_reqlist_hash(fsf_req->req_id);
963 list_add_tail(&fsf_req->list, &adapter->req_list[idx]);
964}
965
966static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
967 struct zfcp_fsf_req *fsf_req)
968{
969 list_del(&fsf_req->list);
970}
971
972static inline struct zfcp_fsf_req *
973zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
974{
975 struct zfcp_fsf_req *request;
976 unsigned int idx;
977
978 idx = zfcp_reqlist_hash(req_id);
979 list_for_each_entry(request, &adapter->req_list[idx], list)
980 if (request->req_id == req_id)
981 return request;
982 return NULL;
983}
984
Heiko Carstensd1ad09d2007-12-20 12:30:22 +0100985static inline struct zfcp_fsf_req *
986zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req)
987{
988 struct zfcp_fsf_req *request;
989 unsigned int idx;
990
991 for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) {
992 list_for_each_entry(request, &adapter->req_list[idx], list)
993 if (request == req)
994 return request;
995 }
996 return NULL;
997}
998
Heiko Carstensca2d02c2007-05-08 11:17:54 +0200999/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 * functions needed for reference/usage counting
1001 */
1002
1003static inline void
1004zfcp_unit_get(struct zfcp_unit *unit)
1005{
1006 atomic_inc(&unit->refcount);
1007}
1008
1009static inline void
1010zfcp_unit_put(struct zfcp_unit *unit)
1011{
1012 if (atomic_dec_return(&unit->refcount) == 0)
1013 wake_up(&unit->remove_wq);
1014}
1015
1016static inline void
1017zfcp_unit_wait(struct zfcp_unit *unit)
1018{
1019 wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
1020}
1021
1022static inline void
1023zfcp_port_get(struct zfcp_port *port)
1024{
1025 atomic_inc(&port->refcount);
1026}
1027
1028static inline void
1029zfcp_port_put(struct zfcp_port *port)
1030{
1031 if (atomic_dec_return(&port->refcount) == 0)
1032 wake_up(&port->remove_wq);
1033}
1034
1035static inline void
1036zfcp_port_wait(struct zfcp_port *port)
1037{
1038 wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
1039}
1040
1041static inline void
1042zfcp_adapter_get(struct zfcp_adapter *adapter)
1043{
1044 atomic_inc(&adapter->refcount);
1045}
1046
1047static inline void
1048zfcp_adapter_put(struct zfcp_adapter *adapter)
1049{
1050 if (atomic_dec_return(&adapter->refcount) == 0)
1051 wake_up(&adapter->remove_wq);
1052}
1053
1054static inline void
1055zfcp_adapter_wait(struct zfcp_adapter *adapter)
1056{
1057 wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
1058}
1059
1060#endif /* ZFCP_DEF_H */