blob: f29bee52848941bafbe3fc7811f13eee4a015471 [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>
Heiko Carstensdd52e0e2006-09-18 22:28:49 +020050#include "zfcp_fsf.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53/********************* GENERAL DEFINES *********************************/
54
55/* zfcp version number, it consists of major, minor, and patch-level number */
Andreas Herrmann58b3ac02006-08-02 11:06:21 +020056#define ZFCP_VERSION "4.8.0"
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58/**
59 * zfcp_sg_to_address - determine kernel address from struct scatterlist
60 * @list: struct scatterlist
61 * Return: kernel address
62 */
63static inline void *
64zfcp_sg_to_address(struct scatterlist *list)
65{
Jens Axboe73fc4f02007-10-23 09:17:53 +020066 return sg_virt(list);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067}
68
69/**
70 * zfcp_address_to_sg - set up struct scatterlist from kernel address
71 * @address: kernel address
72 * @list: struct scatterlist
Jens Axboe933543292007-10-26 13:55:40 +020073 * @size: buffer size
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 */
75static inline void
Jens Axboe933543292007-10-26 13:55:40 +020076zfcp_address_to_sg(void *address, struct scatterlist *list, unsigned int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
Jens Axboe933543292007-10-26 13:55:40 +020078 sg_set_buf(list, address, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079}
80
Andreas Herrmann06506d02006-05-22 18:18:19 +020081#define REQUEST_LIST_SIZE 128
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083/********************* SCSI SPECIFIC DEFINES *********************************/
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +020084#define ZFCP_SCSI_ER_TIMEOUT (10*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86/********************* CIO/QDIO SPECIFIC DEFINES *****************************/
87
88/* Adapter Identification Parameters */
89#define ZFCP_CONTROL_UNIT_TYPE 0x1731
90#define ZFCP_CONTROL_UNIT_MODEL 0x03
91#define ZFCP_DEVICE_TYPE 0x1732
92#define ZFCP_DEVICE_MODEL 0x03
93#define ZFCP_DEVICE_MODEL_PRIV 0x04
Swen Schillig41fa2ad2007-09-07 09:15:31 +020094
Linus Torvalds1da177e2005-04-16 15:20:36 -070095/* allow as many chained SBALs as are supported by hardware */
96#define ZFCP_MAX_SBALS_PER_REQ FSF_MAX_SBALS_PER_REQ
97#define ZFCP_MAX_SBALS_PER_CT_REQ FSF_MAX_SBALS_PER_REQ
98#define ZFCP_MAX_SBALS_PER_ELS_REQ FSF_MAX_SBALS_PER_ELS_REQ
99
100/* DMQ bug workaround: don't use last SBALE */
101#define ZFCP_MAX_SBALES_PER_SBAL (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
102
103/* index of last SBALE (with respect to DMQ bug workaround) */
104#define ZFCP_LAST_SBALE_PER_SBAL (ZFCP_MAX_SBALES_PER_SBAL - 1)
105
106/* max. number of (data buffer) SBALEs in largest SBAL chain */
107#define ZFCP_MAX_SBALES_PER_REQ \
108 (ZFCP_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
109 /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
110
Swen Schillig8d1a0062006-10-12 11:43:44 +0200111#define ZFCP_MAX_SECTORS (ZFCP_MAX_SBALES_PER_REQ * 8)
112 /* max. number of (data buffer) SBALEs in largest SBAL chain
113 multiplied with number of sectors per 4k block */
114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115/* FIXME(tune): free space should be one max. SBAL chain plus what? */
116#define ZFCP_QDIO_PCI_INTERVAL (QDIO_MAX_BUFFERS_PER_Q \
117 - (ZFCP_MAX_SBALS_PER_REQ + 4))
118
119#define ZFCP_SBAL_TIMEOUT (5*HZ)
120
Christof Schmitt18edcdb2007-11-05 12:37:45 +0100121#define ZFCP_TYPE2_RECOVERY_TIME 8 /* seconds */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
123/* queue polling (values in microseconds) */
124#define ZFCP_MAX_INPUT_THRESHOLD 5000 /* FIXME: tune */
125#define ZFCP_MAX_OUTPUT_THRESHOLD 1000 /* FIXME: tune */
126#define ZFCP_MIN_INPUT_THRESHOLD 1 /* ignored by QDIO layer */
127#define ZFCP_MIN_OUTPUT_THRESHOLD 1 /* ignored by QDIO layer */
128
129#define QDIO_SCSI_QFMT 1 /* 1 for FSF */
Swen Schilligb4e44592007-07-18 10:55:13 +0200130#define QBUFF_PER_PAGE (PAGE_SIZE / sizeof(struct qdio_buffer))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132/********************* FSF SPECIFIC DEFINES *********************************/
133
134#define ZFCP_ULP_INFO_VERSION 26
135#define ZFCP_QTCB_VERSION FSF_QTCB_CURRENT_VERSION
136/* ATTENTION: value must not be used by hardware */
137#define FSF_QTCB_UNSOLICITED_STATUS 0x6305
138#define ZFCP_STATUS_READ_FAILED_THRESHOLD 3
139#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/*
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200265 * DBF stuff
266 */
267#define ZFCP_DBF_TAG_SIZE 4
268
269struct zfcp_dbf_dump {
270 u8 tag[ZFCP_DBF_TAG_SIZE];
271 u32 total_size; /* size of total dump data */
272 u32 offset; /* how much data has being already dumped */
273 u32 size; /* how much data comes with this record */
274 u8 data[]; /* dump data */
275} __attribute__ ((packed));
276
277/* FIXME: to be inflated when reworking the erp dbf */
278struct zfcp_erp_dbf_record {
279 u8 dummy[16];
280} __attribute__ ((packed));
281
Martin Peschked79a83d2008-03-27 14:22:00 +0100282struct zfcp_rec_dbf_record {
283 u8 id;
284 u8 id2;
285 union {
286 } u;
287} __attribute__ ((packed));
288
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200289struct zfcp_hba_dbf_record_response {
290 u32 fsf_command;
291 u64 fsf_reqid;
292 u32 fsf_seqno;
293 u64 fsf_issued;
294 u32 fsf_prot_status;
295 u32 fsf_status;
296 u8 fsf_prot_status_qual[FSF_PROT_STATUS_QUAL_SIZE];
297 u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
298 u32 fsf_req_status;
299 u8 sbal_first;
300 u8 sbal_curr;
301 u8 sbal_last;
302 u8 pool;
303 u64 erp_action;
304 union {
305 struct {
306 u64 scsi_cmnd;
307 u64 scsi_serial;
308 } send_fcp;
309 struct {
310 u64 wwpn;
311 u32 d_id;
312 u32 port_handle;
313 } port;
314 struct {
315 u64 wwpn;
316 u64 fcp_lun;
317 u32 port_handle;
318 u32 lun_handle;
319 } unit;
320 struct {
321 u32 d_id;
322 u8 ls_code;
323 } send_els;
324 } data;
325} __attribute__ ((packed));
326
327struct zfcp_hba_dbf_record_status {
328 u8 failed;
329 u32 status_type;
330 u32 status_subtype;
331 struct fsf_queue_designator
332 queue_designator;
333 u32 payload_size;
334#define ZFCP_DBF_UNSOL_PAYLOAD 80
335#define ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL 32
336#define ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD 56
337#define ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT 2 * sizeof(u32)
338 u8 payload[ZFCP_DBF_UNSOL_PAYLOAD];
339} __attribute__ ((packed));
340
341struct zfcp_hba_dbf_record_qdio {
342 u32 status;
343 u32 qdio_error;
344 u32 siga_error;
345 u8 sbal_index;
346 u8 sbal_count;
347} __attribute__ ((packed));
348
349struct zfcp_hba_dbf_record {
350 u8 tag[ZFCP_DBF_TAG_SIZE];
351 u8 tag2[ZFCP_DBF_TAG_SIZE];
352 union {
353 struct zfcp_hba_dbf_record_response response;
354 struct zfcp_hba_dbf_record_status status;
355 struct zfcp_hba_dbf_record_qdio qdio;
356 } type;
357} __attribute__ ((packed));
358
359struct zfcp_san_dbf_record_ct {
360 union {
361 struct {
362 u16 cmd_req_code;
363 u8 revision;
364 u8 gs_type;
365 u8 gs_subtype;
366 u8 options;
367 u16 max_res_size;
368 } request;
369 struct {
370 u16 cmd_rsp_code;
371 u8 revision;
372 u8 reason_code;
373 u8 reason_code_expl;
374 u8 vendor_unique;
375 } response;
376 } type;
377 u32 payload_size;
378#define ZFCP_DBF_CT_PAYLOAD 24
379 u8 payload[ZFCP_DBF_CT_PAYLOAD];
380} __attribute__ ((packed));
381
382struct zfcp_san_dbf_record_els {
383 u8 ls_code;
384 u32 payload_size;
385#define ZFCP_DBF_ELS_PAYLOAD 32
386#define ZFCP_DBF_ELS_MAX_PAYLOAD 1024
387 u8 payload[ZFCP_DBF_ELS_PAYLOAD];
388} __attribute__ ((packed));
389
390struct zfcp_san_dbf_record {
391 u8 tag[ZFCP_DBF_TAG_SIZE];
392 u64 fsf_reqid;
393 u32 fsf_seqno;
394 u32 s_id;
395 u32 d_id;
396 union {
397 struct zfcp_san_dbf_record_ct ct;
398 struct zfcp_san_dbf_record_els els;
399 } type;
400} __attribute__ ((packed));
401
402struct zfcp_scsi_dbf_record {
403 u8 tag[ZFCP_DBF_TAG_SIZE];
404 u8 tag2[ZFCP_DBF_TAG_SIZE];
405 u32 scsi_id;
406 u32 scsi_lun;
407 u32 scsi_result;
408 u64 scsi_cmnd;
409 u64 scsi_serial;
410#define ZFCP_DBF_SCSI_OPCODE 16
411 u8 scsi_opcode[ZFCP_DBF_SCSI_OPCODE];
412 u8 scsi_retries;
413 u8 scsi_allowed;
414 u64 fsf_reqid;
415 u32 fsf_seqno;
416 u64 fsf_issued;
417 union {
Maxim Shchetynined829ad2006-02-11 01:42:58 +0100418 u64 old_fsf_reqid;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200419 struct {
420 u8 rsp_validity;
421 u8 rsp_scsi_status;
422 u32 rsp_resid;
423 u8 rsp_code;
424#define ZFCP_DBF_SCSI_FCP_SNS_INFO 16
425#define ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO 256
426 u32 sns_info_len;
427 u8 sns_info[ZFCP_DBF_SCSI_FCP_SNS_INFO];
428 } fcp;
429 } type;
430} __attribute__ ((packed));
431
432/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 * FC-FS stuff
434 */
435#define R_A_TOV 10 /* seconds */
436#define ZFCP_ELS_TIMEOUT (2 * R_A_TOV)
437
438#define ZFCP_LS_RLS 0x0f
439#define ZFCP_LS_ADISC 0x52
440#define ZFCP_LS_RPS 0x56
441#define ZFCP_LS_RSCN 0x61
442#define ZFCP_LS_RNID 0x78
443
444struct zfcp_ls_rjt_par {
445 u8 action;
446 u8 reason_code;
447 u8 reason_expl;
448 u8 vendor_unique;
449} __attribute__ ((packed));
450
451struct zfcp_ls_adisc {
452 u8 code;
453 u8 field[3];
454 u32 hard_nport_id;
455 u64 wwpn;
456 u64 wwnn;
457 u32 nport_id;
458} __attribute__ ((packed));
459
460struct zfcp_ls_adisc_acc {
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_rc_entry {
470 u8 code;
471 const char *description;
472};
473
474/*
475 * FC-GS-2 stuff
476 */
477#define ZFCP_CT_REVISION 0x01
478#define ZFCP_CT_DIRECTORY_SERVICE 0xFC
479#define ZFCP_CT_NAME_SERVER 0x02
480#define ZFCP_CT_SYNCHRONOUS 0x00
481#define ZFCP_CT_GID_PN 0x0121
482#define ZFCP_CT_MAX_SIZE 0x1020
483#define ZFCP_CT_ACCEPT 0x8002
484#define ZFCP_CT_REJECT 0x8001
485
486/*
487 * FC-GS-4 stuff
488 */
489#define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491/******************** LOGGING MACROS AND DEFINES *****************************/
492
493/*
494 * Logging may be applied on certain kinds of driver operations
495 * independently. Additionally, different log-levels are supported for
496 * each of these areas.
497 */
498
499#define ZFCP_NAME "zfcp"
500
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501/* independent log areas */
502#define ZFCP_LOG_AREA_OTHER 0
503#define ZFCP_LOG_AREA_SCSI 1
504#define ZFCP_LOG_AREA_FSF 2
505#define ZFCP_LOG_AREA_CONFIG 3
506#define ZFCP_LOG_AREA_CIO 4
507#define ZFCP_LOG_AREA_QDIO 5
508#define ZFCP_LOG_AREA_ERP 6
509#define ZFCP_LOG_AREA_FC 7
510
511/* log level values*/
512#define ZFCP_LOG_LEVEL_NORMAL 0
513#define ZFCP_LOG_LEVEL_INFO 1
514#define ZFCP_LOG_LEVEL_DEBUG 2
515#define ZFCP_LOG_LEVEL_TRACE 3
516
517/*
518 * this allows removal of logging code by the preprocessor
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200519 * (the most detailed log level still to be compiled in is specified,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 * higher log levels are removed)
521 */
522#define ZFCP_LOG_LEVEL_LIMIT ZFCP_LOG_LEVEL_TRACE
523
524/* get "loglevel" nibble assignment */
525#define ZFCP_GET_LOG_VALUE(zfcp_lognibble) \
526 ((atomic_read(&zfcp_data.loglevel) >> (zfcp_lognibble<<2)) & 0xF)
527
528/* set "loglevel" nibble */
529#define ZFCP_SET_LOG_NIBBLE(value, zfcp_lognibble) \
530 (value << (zfcp_lognibble << 2))
531
532/* all log-level defaults are combined to generate initial log-level */
533#define ZFCP_LOG_LEVEL_DEFAULTS \
534 (ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_OTHER) | \
535 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_SCSI) | \
536 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FSF) | \
537 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CONFIG) | \
538 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CIO) | \
539 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_QDIO) | \
540 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_ERP) | \
541 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FC))
542
543/* check whether we have the right level for logging */
544#define ZFCP_LOG_CHECK(level) \
545 ((ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA)) >= level)
546
547/* logging routine for zfcp */
548#define _ZFCP_LOG(fmt, args...) \
549 printk(KERN_ERR ZFCP_NAME": %s(%d): " fmt, __FUNCTION__, \
550 __LINE__ , ##args)
551
552#define ZFCP_LOG(level, fmt, args...) \
553do { \
554 if (ZFCP_LOG_CHECK(level)) \
555 _ZFCP_LOG(fmt, ##args); \
556} while (0)
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200557
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558#if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_NORMAL
Heiko Carstens39b083f2006-09-20 15:58:51 +0200559# define ZFCP_LOG_NORMAL(fmt, args...) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560#else
561# define ZFCP_LOG_NORMAL(fmt, args...) \
562do { \
563 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_NORMAL)) \
564 printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
565} while (0)
566#endif
567
568#if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_INFO
Heiko Carstens39b083f2006-09-20 15:58:51 +0200569# define ZFCP_LOG_INFO(fmt, args...) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570#else
571# define ZFCP_LOG_INFO(fmt, args...) \
572do { \
573 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_INFO)) \
574 printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
575} while (0)
576#endif
577
578#if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_DEBUG
Heiko Carstens39b083f2006-09-20 15:58:51 +0200579# define ZFCP_LOG_DEBUG(fmt, args...) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580#else
581# define ZFCP_LOG_DEBUG(fmt, args...) \
582 ZFCP_LOG(ZFCP_LOG_LEVEL_DEBUG, fmt , ##args)
583#endif
584
585#if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_TRACE
Heiko Carstens39b083f2006-09-20 15:58:51 +0200586# define ZFCP_LOG_TRACE(fmt, args...) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587#else
588# define ZFCP_LOG_TRACE(fmt, args...) \
589 ZFCP_LOG(ZFCP_LOG_LEVEL_TRACE, fmt , ##args)
590#endif
591
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592/*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
593
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200594/*
595 * Note, the leftmost status byte is common among adapter, port
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 * and unit
597 */
598#define ZFCP_COMMON_FLAGS 0xfff00000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
600/* common status bits */
601#define ZFCP_STATUS_COMMON_REMOVE 0x80000000
602#define ZFCP_STATUS_COMMON_RUNNING 0x40000000
603#define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
604#define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
605#define ZFCP_STATUS_COMMON_OPENING 0x08000000
606#define ZFCP_STATUS_COMMON_OPEN 0x04000000
607#define ZFCP_STATUS_COMMON_CLOSING 0x02000000
608#define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
609#define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
Andreas Herrmannd736a272005-06-13 13:23:57 +0200610#define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
612/* adapter status */
613#define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
614#define ZFCP_STATUS_ADAPTER_REGISTERED 0x00000004
615#define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
616#define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
617#define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
618#define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
619#define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
620#define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200621#define ZFCP_STATUS_ADAPTER_XPORT_OK 0x00000800
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623/* FC-PH/FC-GS well-known address identifiers for generic services */
624#define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA
625#define ZFCP_DID_TIME_SERVICE 0xFFFFFB
626#define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC
627#define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8
628#define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7
629
630/* remote port status */
631#define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
632#define ZFCP_STATUS_PORT_DID_DID 0x00000002
633#define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
634#define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
635#define ZFCP_STATUS_PORT_NO_SCSI_ID 0x00000010
636#define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637
638/* for ports with well known addresses */
639#define ZFCP_STATUS_PORT_WKA \
640 (ZFCP_STATUS_PORT_NO_WWPN | \
641 ZFCP_STATUS_PORT_NO_SCSI_ID)
642
643/* logical unit status */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644#define ZFCP_STATUS_UNIT_TEMPORARY 0x00000002
645#define ZFCP_STATUS_UNIT_SHARED 0x00000004
646#define ZFCP_STATUS_UNIT_READONLY 0x00000008
Andreas Herrmannad58f7d2006-03-10 00:56:16 +0100647#define ZFCP_STATUS_UNIT_REGISTERED 0x00000010
Christof Schmitt5f852be2007-05-08 11:16:52 +0200648#define ZFCP_STATUS_UNIT_SCSI_WORK_PENDING 0x00000020
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
650/* FSF request status (this does not have a common part) */
651#define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000
652#define ZFCP_STATUS_FSFREQ_POOL 0x00000001
653#define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
654#define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
655#define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
656#define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
657#define ZFCP_STATUS_FSFREQ_ABORTING 0x00000020
658#define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
659#define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
660#define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
661#define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
662#define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
663#define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
664#define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
665
666/*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
667
668#define ZFCP_MAX_ERPS 3
669
670#define ZFCP_ERP_FSFREQ_TIMEOUT (30 * HZ)
671#define ZFCP_ERP_MEMWAIT_TIMEOUT HZ
672
673#define ZFCP_STATUS_ERP_TIMEDOUT 0x10000000
674#define ZFCP_STATUS_ERP_CLOSE_ONLY 0x01000000
675#define ZFCP_STATUS_ERP_DISMISSING 0x00100000
676#define ZFCP_STATUS_ERP_DISMISSED 0x00200000
677#define ZFCP_STATUS_ERP_LOWMEM 0x00400000
678
679#define ZFCP_ERP_STEP_UNINITIALIZED 0x00000000
680#define ZFCP_ERP_STEP_FSF_XCONFIG 0x00000001
681#define ZFCP_ERP_STEP_PHYS_PORT_CLOSING 0x00000010
682#define ZFCP_ERP_STEP_PORT_CLOSING 0x00000100
683#define ZFCP_ERP_STEP_NAMESERVER_OPEN 0x00000200
684#define ZFCP_ERP_STEP_NAMESERVER_LOOKUP 0x00000400
685#define ZFCP_ERP_STEP_PORT_OPENING 0x00000800
686#define ZFCP_ERP_STEP_UNIT_CLOSING 0x00001000
687#define ZFCP_ERP_STEP_UNIT_OPENING 0x00002000
688
689/* Ordered by escalation level (necessary for proper erp-code operation) */
690#define ZFCP_ERP_ACTION_REOPEN_ADAPTER 0x4
691#define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED 0x3
692#define ZFCP_ERP_ACTION_REOPEN_PORT 0x2
693#define ZFCP_ERP_ACTION_REOPEN_UNIT 0x1
694
695#define ZFCP_ERP_ACTION_RUNNING 0x1
696#define ZFCP_ERP_ACTION_READY 0x2
697
698#define ZFCP_ERP_SUCCEEDED 0x0
699#define ZFCP_ERP_FAILED 0x1
700#define ZFCP_ERP_CONTINUES 0x2
701#define ZFCP_ERP_EXIT 0x3
702#define ZFCP_ERP_DISMISSED 0x4
703#define ZFCP_ERP_NOMEM 0x5
704
705
706/******************** CFDC SPECIFIC STUFF *****************************/
707
708/* Firewall data channel sense data record */
709struct zfcp_cfdc_sense_data {
710 u32 signature; /* Request signature */
711 u32 devno; /* FCP adapter device number */
712 u32 command; /* Command code */
713 u32 fsf_status; /* FSF request status and status qualifier */
714 u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
715 u8 payloads[256]; /* Access conflicts list */
716 u8 control_file[0]; /* Access control table */
717};
718
719#define ZFCP_CFDC_SIGNATURE 0xCFDCACDF
720
721#define ZFCP_CFDC_CMND_DOWNLOAD_NORMAL 0x00010001
722#define ZFCP_CFDC_CMND_DOWNLOAD_FORCE 0x00010101
723#define ZFCP_CFDC_CMND_FULL_ACCESS 0x00000201
724#define ZFCP_CFDC_CMND_RESTRICTED_ACCESS 0x00000401
725#define ZFCP_CFDC_CMND_UPLOAD 0x00010002
726
727#define ZFCP_CFDC_DOWNLOAD 0x00000001
728#define ZFCP_CFDC_UPLOAD 0x00000002
729#define ZFCP_CFDC_WITH_CONTROL_FILE 0x00010000
730
731#define ZFCP_CFDC_DEV_NAME "zfcp_cfdc"
732#define ZFCP_CFDC_DEV_MAJOR MISC_MAJOR
733#define ZFCP_CFDC_DEV_MINOR MISC_DYNAMIC_MINOR
734
735#define ZFCP_CFDC_MAX_CONTROL_FILE_SIZE 127 * 1024
736
737/************************* STRUCTURE DEFINITIONS *****************************/
738
739struct zfcp_fsf_req;
740
741/* holds various memory pools of an adapter */
742struct zfcp_adapter_mempool {
743 mempool_t *fsf_req_erp;
744 mempool_t *fsf_req_scsi;
745 mempool_t *fsf_req_abort;
746 mempool_t *fsf_req_status_read;
747 mempool_t *data_status_read;
748 mempool_t *data_gid_pn;
749};
750
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751/*
752 * header for CT_IU
753 */
754struct ct_hdr {
755 u8 revision; // 0x01
756 u8 in_id[3]; // 0x00
757 u8 gs_type; // 0xFC Directory Service
758 u8 gs_subtype; // 0x02 Name Server
759 u8 options; // 0x00 single bidirectional exchange
760 u8 reserved0;
761 u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT
762 u16 max_res_size; // <= (4096 - 16) / 4
763 u8 reserved1;
764 u8 reason_code;
765 u8 reason_code_expl;
766 u8 vendor_unique;
767} __attribute__ ((packed));
768
769/* nameserver request CT_IU -- for requests where
770 * a port name is required */
771struct ct_iu_gid_pn_req {
772 struct ct_hdr header;
773 wwn_t wwpn;
774} __attribute__ ((packed));
775
776/* FS_ACC IU and data unit for GID_PN nameserver request */
777struct ct_iu_gid_pn_resp {
778 struct ct_hdr header;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200779 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780} __attribute__ ((packed));
781
782typedef void (*zfcp_send_ct_handler_t)(unsigned long);
783
784/**
785 * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
786 * @port: port where the request is sent to
787 * @req: scatter-gather list for request
788 * @resp: scatter-gather list for response
789 * @req_count: number of elements in request scatter-gather list
790 * @resp_count: number of elements in response scatter-gather list
791 * @handler: handler function (called for response to the request)
792 * @handler_data: data passed to handler function
793 * @pool: pointer to memory pool for ct request structure
794 * @timeout: FSF timeout for this request
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 * @completion: completion for synchronization purposes
796 * @status: used to pass error status to calling function
797 */
798struct zfcp_send_ct {
799 struct zfcp_port *port;
800 struct scatterlist *req;
801 struct scatterlist *resp;
802 unsigned int req_count;
803 unsigned int resp_count;
804 zfcp_send_ct_handler_t handler;
805 unsigned long handler_data;
806 mempool_t *pool;
807 int timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 struct completion *completion;
809 int status;
810};
811
812/* used for name server requests in error recovery */
813struct zfcp_gid_pn_data {
814 struct zfcp_send_ct ct;
815 struct scatterlist req;
816 struct scatterlist resp;
817 struct ct_iu_gid_pn_req ct_iu_req;
818 struct ct_iu_gid_pn_resp ct_iu_resp;
819 struct zfcp_port *port;
820};
821
822typedef void (*zfcp_send_els_handler_t)(unsigned long);
823
824/**
825 * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
826 * @adapter: adapter where request is sent from
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200827 * @port: port where ELS is destinated (port reference count has to be increased)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 * @d_id: destiniation id of port where request is sent to
829 * @req: scatter-gather list for request
830 * @resp: scatter-gather list for response
831 * @req_count: number of elements in request scatter-gather list
832 * @resp_count: number of elements in response scatter-gather list
833 * @handler: handler function (called for response to the request)
834 * @handler_data: data passed to handler function
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 * @completion: completion for synchronization purposes
836 * @ls_code: hex code of ELS command
837 * @status: used to pass error status to calling function
838 */
839struct zfcp_send_els {
840 struct zfcp_adapter *adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200841 struct zfcp_port *port;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200842 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 struct scatterlist *req;
844 struct scatterlist *resp;
845 unsigned int req_count;
846 unsigned int resp_count;
847 zfcp_send_els_handler_t handler;
848 unsigned long handler_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 struct completion *completion;
850 int ls_code;
851 int status;
852};
853
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854struct zfcp_qdio_queue {
855 struct qdio_buffer *buffer[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
856 u8 free_index; /* index of next free bfr
857 in queue (free_count>0) */
858 atomic_t free_count; /* number of free buffers
859 in queue */
860 rwlock_t queue_lock; /* lock for operations on queue */
861 int distance_from_int; /* SBALs used since PCI indication
862 was last set */
863};
864
865struct zfcp_erp_action {
866 struct list_head list;
867 int action; /* requested action code */
868 struct zfcp_adapter *adapter; /* device which should be recovered */
869 struct zfcp_port *port;
870 struct zfcp_unit *unit;
871 volatile u32 status; /* recovery status */
872 u32 step; /* active step of this erp action */
873 struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
874 for this action */
875 struct timer_list timer;
876};
877
878
879struct zfcp_adapter {
880 struct list_head list; /* list of adapters */
881 atomic_t refcount; /* reference count */
882 wait_queue_head_t remove_wq; /* can be used to wait for
883 refcount drop to zero */
6f71d9b2005-04-10 23:04:28 -0500884 wwn_t peer_wwnn; /* P2P peer WWNN */
885 wwn_t peer_wwpn; /* P2P peer WWPN */
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200886 u32 peer_d_id; /* P2P peer D_ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 struct ccw_device *ccw_device; /* S/390 ccw device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 u32 hydra_version; /* Hydra version */
889 u32 fsf_lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200890 u32 adapter_features; /* FCP channel features */
891 u32 connection_features; /* host connection features */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 u32 hardware_version; /* of FCP channel */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 struct list_head port_list_head; /* remote port list */
895 struct list_head port_remove_lh; /* head of ports to be
896 removed */
897 u32 ports; /* number of remote ports */
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200898 atomic_t reqs_active; /* # active FSF reqs */
899 unsigned long req_no; /* unique FSF req number */
900 struct list_head *req_list; /* list of pending reqs */
901 spinlock_t req_list_lock; /* request list lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 struct zfcp_qdio_queue request_queue; /* request queue */
903 u32 fsf_req_seq_no; /* FSF cmnd seq number */
904 wait_queue_head_t request_wq; /* can be used to wait for
905 more avaliable SBALs */
906 struct zfcp_qdio_queue response_queue; /* response queue */
907 rwlock_t abort_lock; /* Protects against SCSI
908 stack abort/command
909 completion races */
910 u16 status_read_failed; /* # failed status reads */
911 atomic_t status; /* status of this adapter */
912 struct list_head erp_ready_head; /* error recovery for this
913 adapter/devices */
914 struct list_head erp_running_head;
915 rwlock_t erp_lock;
916 struct semaphore erp_ready_sem;
917 wait_queue_head_t erp_thread_wqh;
918 wait_queue_head_t erp_done_wqh;
919 struct zfcp_erp_action erp_action; /* pending error recovery */
920 atomic_t erp_counter;
921 u32 erp_total_count; /* total nr of enqueued erp
922 actions */
923 u32 erp_low_mem_count; /* nr of erp actions waiting
924 for memory */
925 struct zfcp_port *nameserver_port; /* adapter's nameserver */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200926 debug_info_t *erp_dbf;
Martin Peschked79a83d2008-03-27 14:22:00 +0100927 debug_info_t *rec_dbf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200928 debug_info_t *hba_dbf;
929 debug_info_t *san_dbf; /* debug feature areas */
930 debug_info_t *scsi_dbf;
931 spinlock_t erp_dbf_lock;
Martin Peschked79a83d2008-03-27 14:22:00 +0100932 spinlock_t rec_dbf_lock;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200933 spinlock_t hba_dbf_lock;
934 spinlock_t san_dbf_lock;
935 spinlock_t scsi_dbf_lock;
936 struct zfcp_erp_dbf_record erp_dbf_buf;
Martin Peschked79a83d2008-03-27 14:22:00 +0100937 struct zfcp_rec_dbf_record rec_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200938 struct zfcp_hba_dbf_record hba_dbf_buf;
939 struct zfcp_san_dbf_record san_dbf_buf;
940 struct zfcp_scsi_dbf_record scsi_dbf_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 struct zfcp_adapter_mempool pool; /* Adapter memory pools */
942 struct qdio_initialize qdio_init_data; /* for qdio_establish */
943 struct device generic_services; /* directory for WKA ports */
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100944 struct fc_host_statistics *fc_stats;
945 struct fsf_qtcb_bottom_port *stats_reset_data;
946 unsigned long stats_reset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947};
948
949/*
950 * the struct device sysfs_device must be at the beginning of this structure.
951 * pointer to struct device is used to free port structure in release function
952 * of the device. don't change!
953 */
954struct zfcp_port {
955 struct device sysfs_device; /* sysfs device */
Andreas Herrmann3859f6a2005-08-27 11:07:54 -0700956 struct fc_rport *rport; /* rport of fc transport class */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 struct list_head list; /* list of remote ports */
958 atomic_t refcount; /* reference count */
959 wait_queue_head_t remove_wq; /* can be used to wait for
960 refcount drop to zero */
961 struct zfcp_adapter *adapter; /* adapter used to access port */
962 struct list_head unit_list_head; /* head of logical unit list */
963 struct list_head unit_remove_lh; /* head of luns to be removed
964 list */
965 u32 units; /* # of logical units in list */
966 atomic_t status; /* status of this remote port */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 wwn_t wwnn; /* WWNN if known */
968 wwn_t wwpn; /* WWPN */
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200969 u32 d_id; /* D_ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 u32 handle; /* handle assigned by FSF */
971 struct zfcp_erp_action erp_action; /* pending error recovery */
972 atomic_t erp_counter;
Ralph Wuerthner75bfc282006-05-22 18:24:33 +0200973 u32 maxframe_size;
974 u32 supported_classes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975};
976
977/* the struct device sysfs_device must be at the beginning of this structure.
978 * pointer to struct device is used to free unit structure in release function
979 * of the device. don't change!
980 */
981struct zfcp_unit {
982 struct device sysfs_device; /* sysfs device */
983 struct list_head list; /* list of logical units */
984 atomic_t refcount; /* reference count */
985 wait_queue_head_t remove_wq; /* can be used to wait for
986 refcount drop to zero */
987 struct zfcp_port *port; /* remote port of unit */
988 atomic_t status; /* status of this logical unit */
Andreas Herrmann06506d02006-05-22 18:18:19 +0200989 unsigned int scsi_lun; /* own SCSI LUN */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 fcp_lun_t fcp_lun; /* own FCP_LUN */
991 u32 handle; /* handle assigned by FSF */
992 struct scsi_device *device; /* scsi device struct pointer */
993 struct zfcp_erp_action erp_action; /* pending error recovery */
994 atomic_t erp_counter;
995};
996
997/* FSF request */
998struct zfcp_fsf_req {
999 struct list_head list; /* list of FSF requests */
Volker Sameskefea9d6c2006-08-02 11:05:16 +02001000 unsigned long req_id; /* unique request ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 struct zfcp_adapter *adapter; /* adapter request belongs to */
1002 u8 sbal_number; /* nr of SBALs free for use */
1003 u8 sbal_first; /* first SBAL for this request */
1004 u8 sbal_last; /* last possible SBAL for
1005 this reuest */
1006 u8 sbal_curr; /* current SBAL during creation
1007 of request */
1008 u8 sbale_curr; /* current SBALE during creation
1009 of request */
1010 wait_queue_head_t completion_wq; /* can be used by a routine
1011 to wait for completion */
1012 volatile u32 status; /* status of this request */
1013 u32 fsf_command; /* FSF Command copy */
1014 struct fsf_qtcb *qtcb; /* address of associated QTCB */
1015 u32 seq_no; /* Sequence number of request */
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001016 unsigned long data; /* private data of request */
1017 struct timer_list timer; /* used for erp or scsi er */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 struct zfcp_erp_action *erp_action; /* used if this request is
1019 issued on behalf of erp */
1020 mempool_t *pool; /* used if request was alloacted
1021 from emergency pool */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001022 unsigned long long issued; /* request sent time (STCK) */
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001023 struct zfcp_unit *unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024};
1025
1026typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
1027
1028/* driver data */
1029struct zfcp_data {
1030 struct scsi_host_template scsi_host_template;
Heiko Carstensdd52e0e2006-09-18 22:28:49 +02001031 struct scsi_transport_template *scsi_transport_template;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 atomic_t status; /* Module status flags */
1033 struct list_head adapter_list_head; /* head of adapter list */
1034 struct list_head adapter_remove_lh; /* head of adapters to be
1035 removed */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 u32 adapters; /* # of adapters in list */
1037 rwlock_t config_lock; /* serialises changes
1038 to adapter/port/unit
1039 lists */
1040 struct semaphore config_sema; /* serialises configuration
1041 changes */
1042 atomic_t loglevel; /* current loglevel */
1043 char init_busid[BUS_ID_SIZE];
1044 wwn_t init_wwpn;
1045 fcp_lun_t init_fcp_lun;
1046 char *driver_version;
Christoph Lametere18b8902006-12-06 20:33:20 -08001047 struct kmem_cache *fsf_req_qtcb_cache;
1048 struct kmem_cache *sr_buffer_cache;
1049 struct kmem_cache *gid_pn_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050};
1051
1052/**
1053 * struct zfcp_sg_list - struct describing a scatter-gather list
1054 * @sg: pointer to array of (struct scatterlist)
1055 * @count: number of elements in scatter-gather list
1056 */
1057struct zfcp_sg_list {
1058 struct scatterlist *sg;
1059 unsigned int count;
1060};
1061
1062/* number of elements for various memory pools */
1063#define ZFCP_POOL_FSF_REQ_ERP_NR 1
1064#define ZFCP_POOL_FSF_REQ_SCSI_NR 1
1065#define ZFCP_POOL_FSF_REQ_ABORT_NR 1
1066#define ZFCP_POOL_STATUS_READ_NR ZFCP_STATUS_READS_RECOM
1067#define ZFCP_POOL_DATA_GID_PN_NR 1
1068
1069/* struct used by memory pools for fsf_requests */
Heiko Carstensdd52e0e2006-09-18 22:28:49 +02001070struct zfcp_fsf_req_qtcb {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 struct zfcp_fsf_req fsf_req;
1072 struct fsf_qtcb qtcb;
1073};
1074
1075/********************** ZFCP SPECIFIC DEFINES ********************************/
1076
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077#define ZFCP_REQ_AUTO_CLEANUP 0x00000002
1078#define ZFCP_WAIT_FOR_SBAL 0x00000004
1079#define ZFCP_REQ_NO_QTCB 0x00000008
1080
1081#define ZFCP_SET 0x00000100
1082#define ZFCP_CLEAR 0x00000200
1083
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084#ifndef atomic_test_mask
1085#define atomic_test_mask(mask, target) \
1086 ((atomic_read(target) & mask) == mask)
1087#endif
1088
1089extern void _zfcp_hex_dump(char *, int);
1090#define ZFCP_HEX_DUMP(level, addr, count) \
1091 if (ZFCP_LOG_CHECK(level)) { \
1092 _zfcp_hex_dump(addr, count); \
1093 }
1094
1095#define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
1096#define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
1097#define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
1098
1099/*
Heiko Carstensca2d02c2007-05-08 11:17:54 +02001100 * Helper functions for request ID management.
1101 */
1102static inline int zfcp_reqlist_hash(unsigned long req_id)
1103{
1104 return req_id % REQUEST_LIST_SIZE;
1105}
1106
1107static inline void zfcp_reqlist_add(struct zfcp_adapter *adapter,
1108 struct zfcp_fsf_req *fsf_req)
1109{
1110 unsigned int idx;
1111
1112 idx = zfcp_reqlist_hash(fsf_req->req_id);
1113 list_add_tail(&fsf_req->list, &adapter->req_list[idx]);
1114}
1115
1116static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
1117 struct zfcp_fsf_req *fsf_req)
1118{
1119 list_del(&fsf_req->list);
1120}
1121
1122static inline struct zfcp_fsf_req *
1123zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
1124{
1125 struct zfcp_fsf_req *request;
1126 unsigned int idx;
1127
1128 idx = zfcp_reqlist_hash(req_id);
1129 list_for_each_entry(request, &adapter->req_list[idx], list)
1130 if (request->req_id == req_id)
1131 return request;
1132 return NULL;
1133}
1134
Heiko Carstensd1ad09d2007-12-20 12:30:22 +01001135static inline struct zfcp_fsf_req *
1136zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req)
1137{
1138 struct zfcp_fsf_req *request;
1139 unsigned int idx;
1140
1141 for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) {
1142 list_for_each_entry(request, &adapter->req_list[idx], list)
1143 if (request == req)
1144 return request;
1145 }
1146 return NULL;
1147}
1148
Heiko Carstensca2d02c2007-05-08 11:17:54 +02001149/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 * functions needed for reference/usage counting
1151 */
1152
1153static inline void
1154zfcp_unit_get(struct zfcp_unit *unit)
1155{
1156 atomic_inc(&unit->refcount);
1157}
1158
1159static inline void
1160zfcp_unit_put(struct zfcp_unit *unit)
1161{
1162 if (atomic_dec_return(&unit->refcount) == 0)
1163 wake_up(&unit->remove_wq);
1164}
1165
1166static inline void
1167zfcp_unit_wait(struct zfcp_unit *unit)
1168{
1169 wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
1170}
1171
1172static inline void
1173zfcp_port_get(struct zfcp_port *port)
1174{
1175 atomic_inc(&port->refcount);
1176}
1177
1178static inline void
1179zfcp_port_put(struct zfcp_port *port)
1180{
1181 if (atomic_dec_return(&port->refcount) == 0)
1182 wake_up(&port->remove_wq);
1183}
1184
1185static inline void
1186zfcp_port_wait(struct zfcp_port *port)
1187{
1188 wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
1189}
1190
1191static inline void
1192zfcp_adapter_get(struct zfcp_adapter *adapter)
1193{
1194 atomic_inc(&adapter->refcount);
1195}
1196
1197static inline void
1198zfcp_adapter_put(struct zfcp_adapter *adapter)
1199{
1200 if (atomic_dec_return(&adapter->refcount) == 0)
1201 wake_up(&adapter->remove_wq);
1202}
1203
1204static inline void
1205zfcp_adapter_wait(struct zfcp_adapter *adapter)
1206{
1207 wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
1208}
1209
1210#endif /* ZFCP_DEF_H */