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