3 * linux/drivers/s390/scsi/zfcp_def.h
5 * FCP adapter driver for IBM eServer zSeries
7 * (C) Copyright IBM Corp. 2002, 2004
9 * Author(s): Martin Peschke <mpeschke@de.ibm.com>
10 * Raimund Schroeder <raimund.schroeder@de.ibm.com>
13 * Stefan Bader <stefan.bader@de.ibm.com>
14 * Heiko Carstens <heiko.carstens@de.ibm.com>
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2, or (at your option)
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 /* this drivers version (do not edit !!! generated and updated by cvs) */
36 #define ZFCP_DEF_REVISION "$Revision: 1.73 $"
38 /*************************** INCLUDES *****************************************/
40 #include <linux/init.h>
41 #include <linux/moduleparam.h>
42 #include <linux/miscdevice.h>
43 #include <linux/major.h>
44 #include <linux/blkdev.h>
45 #include <scsi/scsi.h>
46 #include <scsi/scsi_tcq.h>
47 #include <scsi/scsi_cmnd.h>
48 #include <scsi/scsi_device.h>
49 #include <scsi/scsi_host.h>
50 #include "../../fc4/fc.h"
52 #include <asm/ccwdev.h>
54 #include <asm/debug.h>
55 #include <asm/ebcdic.h>
56 #include <linux/reboot.h>
57 #include <linux/mempool.h>
58 #include <linux/syscalls.h>
59 #include <linux/ioctl.h>
60 #ifdef CONFIG_S390_SUPPORT
61 #include <linux/ioctl32.h>
64 /************************ DEBUG FLAGS *****************************************/
66 #define ZFCP_PRINT_FLAGS
68 /********************* GENERAL DEFINES *********************************/
70 /* zfcp version number, it consists of major, minor, and patch-level number */
71 #define ZFCP_VERSION "4.0.0"
74 zfcp_sg_to_address(struct scatterlist *list)
76 return (void *) (page_address(list->page) + list->offset);
80 zfcp_address_to_sg(void *address, struct scatterlist *list)
82 list->page = virt_to_page(address);
83 list->offset = ((unsigned long) address) & (PAGE_SIZE - 1);
86 /********************* SCSI SPECIFIC DEFINES *********************************/
88 /* 32 bit for SCSI ID and LUN as long as the SCSI stack uses this type */
89 typedef u32 scsi_id_t;
90 typedef u32 scsi_lun_t;
92 #define ZFCP_ERP_SCSI_LOW_MEM_TIMEOUT (100*HZ)
93 #define ZFCP_SCSI_ER_TIMEOUT (100*HZ)
95 /********************* CIO/QDIO SPECIFIC DEFINES *****************************/
97 /* Adapter Identification Parameters */
98 #define ZFCP_CONTROL_UNIT_TYPE 0x1731
99 #define ZFCP_CONTROL_UNIT_MODEL 0x03
100 #define ZFCP_DEVICE_TYPE 0x1732
101 #define ZFCP_DEVICE_MODEL 0x03
102 #define ZFCP_DEVICE_MODEL_PRIV 0x04
104 /* allow as many chained SBALs as are supported by hardware */
105 #define ZFCP_MAX_SBALS_PER_REQ FSF_MAX_SBALS_PER_REQ
106 #define ZFCP_MAX_SBALS_PER_CT_REQ FSF_MAX_SBALS_PER_REQ
107 #define ZFCP_MAX_SBALS_PER_ELS_REQ FSF_MAX_SBALS_PER_ELS_REQ
109 /* DMQ bug workaround: don't use last SBALE */
110 #define ZFCP_MAX_SBALES_PER_SBAL (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
112 /* index of last SBALE (with respect to DMQ bug workaround) */
113 #define ZFCP_LAST_SBALE_PER_SBAL (ZFCP_MAX_SBALES_PER_SBAL - 1)
115 /* max. number of (data buffer) SBALEs in largest SBAL chain */
116 #define ZFCP_MAX_SBALES_PER_REQ \
117 (ZFCP_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
118 /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
120 /* FIXME(tune): free space should be one max. SBAL chain plus what? */
121 #define ZFCP_QDIO_PCI_INTERVAL (QDIO_MAX_BUFFERS_PER_Q \
122 - (ZFCP_MAX_SBALS_PER_REQ + 4))
124 #define ZFCP_SBAL_TIMEOUT (5*HZ)
126 #define ZFCP_TYPE2_RECOVERY_TIME (8*HZ)
128 /* queue polling (values in microseconds) */
129 #define ZFCP_MAX_INPUT_THRESHOLD 5000 /* FIXME: tune */
130 #define ZFCP_MAX_OUTPUT_THRESHOLD 1000 /* FIXME: tune */
131 #define ZFCP_MIN_INPUT_THRESHOLD 1 /* ignored by QDIO layer */
132 #define ZFCP_MIN_OUTPUT_THRESHOLD 1 /* ignored by QDIO layer */
134 #define QDIO_SCSI_QFMT 1 /* 1 for FSF */
136 /********************* FSF SPECIFIC DEFINES *********************************/
138 #define ZFCP_ULP_INFO_VERSION 26
139 #define ZFCP_QTCB_VERSION FSF_QTCB_CURRENT_VERSION
140 /* ATTENTION: value must not be used by hardware */
141 #define FSF_QTCB_UNSOLICITED_STATUS 0x6305
142 #define ZFCP_STATUS_READ_FAILED_THRESHOLD 3
143 #define ZFCP_STATUS_READS_RECOM FSF_STATUS_READS_RECOM
144 #define ZFCP_EXCHANGE_CONFIG_DATA_RETRIES 6
145 #define ZFCP_EXCHANGE_CONFIG_DATA_SLEEP 50
147 /*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
149 typedef unsigned long long wwn_t;
150 typedef unsigned int fc_id_t;
151 typedef unsigned long long fcp_lun_t;
152 /* data length field may be at variable position in FCP-2 FCP_CMND IU */
153 typedef unsigned int fcp_dl_t;
155 #define ZFCP_FC_SERVICE_CLASS_DEFAULT FSF_CLASS_3
157 /* timeout for name-server lookup (in seconds) */
158 #define ZFCP_NS_GID_PN_TIMEOUT 10
159 #define ZFCP_NS_GA_NXT_TIMEOUT 120
161 /* largest SCSI command we can process */
162 /* FCP-2 (FCP_CMND IU) allows up to (255-3+16) */
163 #define ZFCP_MAX_SCSI_CMND_LENGTH 255
164 /* maximum number of commands in LUN queue (tagged queueing) */
165 #define ZFCP_CMND_PER_LUN 32
167 /* task attribute values in FCP-2 FCP_CMND IU */
174 /* task management flags in FCP-2 FCP_CMND IU */
175 #define CLEAR_ACA 0x40
176 #define TARGET_RESET 0x20
177 #define LOGICAL_UNIT_RESET 0x10
178 #define CLEAR_TASK_SET 0x04
179 #define ABORT_TASK_SET 0x02
181 #define FCP_CDB_LENGTH 16
183 #define ZFCP_DID_MASK 0x00FFFFFF
185 /* FCP(-2) FCP_CMND IU */
187 fcp_lun_t fcp_lun; /* FCP logical unit number */
188 u8 crn; /* command reference number */
189 u8 reserved0:5; /* reserved */
190 u8 task_attribute:3; /* task attribute */
191 u8 task_management_flags; /* task management flags */
192 u8 add_fcp_cdb_length:6; /* additional FCP_CDB length */
193 u8 rddata:1; /* read data */
194 u8 wddata:1; /* write data */
195 u8 fcp_cdb[FCP_CDB_LENGTH];
196 } __attribute__((packed));
198 /* FCP(-2) FCP_RSP IU */
205 u8 fcp_resid_under:1;
207 u8 fcp_sns_len_valid:1;
208 u8 fcp_rsp_len_valid:1;
216 } __attribute__((packed));
219 #define RSP_CODE_GOOD 0
220 #define RSP_CODE_LENGTH_MISMATCH 1
221 #define RSP_CODE_FIELD_INVALID 2
222 #define RSP_CODE_RO_MISMATCH 3
223 #define RSP_CODE_TASKMAN_UNSUPP 4
224 #define RSP_CODE_TASKMAN_FAILED 5
227 #define LS_FAN 0x60000000
228 #define LS_RSCN 0x61040000
230 struct fcp_rscn_head {
232 u8 page_length; /* always 0x04 */
234 } __attribute__((packed));
236 struct fcp_rscn_element {
241 } __attribute__((packed));
243 #define ZFCP_PORT_ADDRESS 0x0
244 #define ZFCP_AREA_ADDRESS 0x1
245 #define ZFCP_DOMAIN_ADDRESS 0x2
246 #define ZFCP_FABRIC_ADDRESS 0x3
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
253 #define ZFCP_NO_PORTS_PER_AREA 0x100
254 #define ZFCP_NO_PORTS_PER_DOMAIN 0x10000
255 #define ZFCP_NO_PORTS_PER_FABRIC 0x1000000
262 } __attribute__((packed));
269 } __attribute__((packed));
274 #define R_A_TOV 10 /* seconds */
275 #define ZFCP_ELS_TIMEOUT (2 * R_A_TOV)
277 #define ZFCP_LS_RJT 0x01
278 #define ZFCP_LS_ACC 0x02
279 #define ZFCP_LS_RTV 0x0E
280 #define ZFCP_LS_RLS 0x0F
281 #define ZFCP_LS_PDISC 0x50
282 #define ZFCP_LS_ADISC 0x52
283 #define ZFCP_LS_RSCN 0x61
284 #define ZFCP_LS_RNID 0x78
285 #define ZFCP_LS_RLIR 0x7A
286 #define ZFCP_LS_RTV_E_D_TOV_FLAG 0x04000000
288 /* LS_ACC Reason Codes */
289 #define ZFCP_LS_RJT_INVALID_COMMAND_CODE 0x01
290 #define ZFCP_LS_RJT_LOGICAL_ERROR 0x03
291 #define ZFCP_LS_RJT_LOGICAL_BUSY 0x05
292 #define ZFCP_LS_RJT_PROTOCOL_ERROR 0x07
293 #define ZFCP_LS_RJT_UNABLE_TO_PERFORM 0x09
294 #define ZFCP_LS_RJT_COMMAND_NOT_SUPPORTED 0x0B
295 #define ZFCP_LS_RJT_VENDOR_UNIQUE_ERROR 0xFF
304 } __attribute__ ((packed));
309 } __attribute__ ((packed));
311 struct zfcp_ls_rtv_acc {
317 } __attribute__ ((packed));
323 } __attribute__ ((packed));
325 struct zfcp_ls_rls_acc {
328 u32 link_failure_count;
329 u32 loss_of_sync_count;
330 u32 loss_of_signal_count;
331 u32 prim_seq_prot_error;
332 u32 invalid_transmition_word;
333 u32 invalid_crc_count;
334 } __attribute__ ((packed));
336 struct zfcp_ls_pdisc {
339 u8 common_svc_parm[16];
348 u8 vendor_version[16];
349 } __attribute__ ((packed));
351 struct zfcp_ls_pdisc_acc {
354 u8 common_svc_parm[16];
363 u8 vendor_version[16];
364 } __attribute__ ((packed));
366 struct zfcp_ls_adisc {
369 fc_id_t hard_nport_id;
373 } __attribute__ ((packed));
375 struct zfcp_ls_adisc_acc {
378 fc_id_t hard_nport_id;
382 } __attribute__ ((packed));
384 struct zfcp_ls_rnid {
389 } __attribute__((packed));
391 /* common identification data */
392 struct zfcp_ls_rnid_common_id {
395 } __attribute__((packed));
397 /* general topology specific identification data */
398 struct zfcp_ls_rnid_general_topology_id {
399 u8 vendor_unique[16];
401 u32 physical_port_number;
402 u32 nr_attached_nodes;
409 } __attribute__((packed));
411 struct zfcp_ls_rnid_acc {
417 u8 specific_id_length;
418 struct zfcp_ls_rnid_common_id
420 struct zfcp_ls_rnid_general_topology_id
422 } __attribute__((packed));
427 #define ZFCP_CT_REVISION 0x01
428 #define ZFCP_CT_DIRECTORY_SERVICE 0xFC
429 #define ZFCP_CT_NAME_SERVER 0x02
430 #define ZFCP_CT_SYNCHRONOUS 0x00
431 #define ZFCP_CT_GID_PN 0x0121
432 #define ZFCP_CT_GA_NXT 0x0100
433 #define ZFCP_CT_MAX_SIZE 0x1020
434 #define ZFCP_CT_ACCEPT 0x8002
439 #define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
442 /***************** S390 DEBUG FEATURE SPECIFIC DEFINES ***********************/
444 /* debug feature entries per adapter */
445 #define ZFCP_ERP_DBF_INDEX 1
446 #define ZFCP_ERP_DBF_AREAS 2
447 #define ZFCP_ERP_DBF_LENGTH 16
448 #define ZFCP_ERP_DBF_LEVEL 3
449 #define ZFCP_ERP_DBF_NAME "zfcperp"
451 #define ZFCP_CMD_DBF_INDEX 2
452 #define ZFCP_CMD_DBF_AREAS 1
453 #define ZFCP_CMD_DBF_LENGTH 8
454 #define ZFCP_CMD_DBF_LEVEL 3
455 #define ZFCP_CMD_DBF_NAME "zfcpcmd"
457 #define ZFCP_ABORT_DBF_INDEX 2
458 #define ZFCP_ABORT_DBF_AREAS 1
459 #define ZFCP_ABORT_DBF_LENGTH 8
460 #define ZFCP_ABORT_DBF_LEVEL 6
461 #define ZFCP_ABORT_DBF_NAME "zfcpabt"
463 #define ZFCP_IN_ELS_DBF_INDEX 2
464 #define ZFCP_IN_ELS_DBF_AREAS 1
465 #define ZFCP_IN_ELS_DBF_LENGTH 8
466 #define ZFCP_IN_ELS_DBF_LEVEL 6
467 #define ZFCP_IN_ELS_DBF_NAME "zfcpels"
469 /******************** LOGGING MACROS AND DEFINES *****************************/
472 * Logging may be applied on certain kinds of driver operations
473 * independently. Additionally, different log-levels are supported for
474 * each of these areas.
477 #define ZFCP_NAME "zfcp"
479 /* independent log areas */
480 #define ZFCP_LOG_AREA_OTHER 0
481 #define ZFCP_LOG_AREA_SCSI 1
482 #define ZFCP_LOG_AREA_FSF 2
483 #define ZFCP_LOG_AREA_CONFIG 3
484 #define ZFCP_LOG_AREA_CIO 4
485 #define ZFCP_LOG_AREA_QDIO 5
486 #define ZFCP_LOG_AREA_ERP 6
487 #define ZFCP_LOG_AREA_FC 7
489 /* log level values*/
490 #define ZFCP_LOG_LEVEL_NORMAL 0
491 #define ZFCP_LOG_LEVEL_INFO 1
492 #define ZFCP_LOG_LEVEL_DEBUG 2
493 #define ZFCP_LOG_LEVEL_TRACE 3
496 * this allows removal of logging code by the preprocessor
497 * (the most detailed log level still to be compiled in is specified,
498 * higher log levels are removed)
500 #define ZFCP_LOG_LEVEL_LIMIT ZFCP_LOG_LEVEL_TRACE
502 /* get "loglevel" nibble assignment */
503 #define ZFCP_GET_LOG_VALUE(zfcp_lognibble) \
504 ((atomic_read(&zfcp_data.loglevel) >> (zfcp_lognibble<<2)) & 0xF)
506 /* set "loglevel" nibble */
507 #define ZFCP_SET_LOG_NIBBLE(value, zfcp_lognibble) \
508 (value << (zfcp_lognibble << 2))
510 /* all log-level defaults are combined to generate initial log-level */
511 #define ZFCP_LOG_LEVEL_DEFAULTS \
512 (ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_INFO, ZFCP_LOG_AREA_OTHER) | \
513 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_INFO, ZFCP_LOG_AREA_SCSI) | \
514 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_INFO, ZFCP_LOG_AREA_FSF) | \
515 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_INFO, ZFCP_LOG_AREA_CONFIG) | \
516 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_INFO, ZFCP_LOG_AREA_CIO) | \
517 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_INFO, ZFCP_LOG_AREA_QDIO) | \
518 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_INFO, ZFCP_LOG_AREA_ERP) | \
519 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_INFO, ZFCP_LOG_AREA_FC))
521 /* check whether we have the right level for logging */
522 #define ZFCP_LOG_CHECK(level) \
523 ((ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA)) >= level)
525 /* logging routine for zfcp */
526 #define _ZFCP_LOG(fmt, args...) \
527 printk(KERN_ERR ZFCP_NAME": %s(%d): " fmt, __FUNCTION__, \
530 #define ZFCP_LOG(level, fmt, args...) \
531 if (ZFCP_LOG_CHECK(level)) \
532 _ZFCP_LOG(fmt , ##args)
534 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_NORMAL
535 # define ZFCP_LOG_NORMAL(fmt, args...)
537 # define ZFCP_LOG_NORMAL(fmt, args...) \
538 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_NORMAL)) \
539 printk(KERN_ERR ZFCP_NAME": " fmt , ##args);
542 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_INFO
543 # define ZFCP_LOG_INFO(fmt, args...)
545 # define ZFCP_LOG_INFO(fmt, args...) \
546 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_INFO)) \
547 printk(KERN_ERR ZFCP_NAME": " fmt , ##args);
550 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_DEBUG
551 # define ZFCP_LOG_DEBUG(fmt, args...)
553 # define ZFCP_LOG_DEBUG(fmt, args...) \
554 ZFCP_LOG(ZFCP_LOG_LEVEL_DEBUG, fmt , ##args)
557 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_TRACE
558 # define ZFCP_LOG_TRACE(fmt, args...)
560 # define ZFCP_LOG_TRACE(fmt, args...) \
561 ZFCP_LOG(ZFCP_LOG_LEVEL_TRACE, fmt , ##args)
564 #ifndef ZFCP_PRINT_FLAGS
565 # define ZFCP_LOG_FLAGS(level, fmt, args...)
567 extern u32 flags_dump;
568 # define ZFCP_LOG_FLAGS(level, fmt, args...) \
569 if (level <= flags_dump) \
570 _ZFCP_LOG(fmt , ##args)
573 /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
576 * Note, the leftmost status byte is common among adapter, port
579 #define ZFCP_COMMON_FLAGS 0xff000000
580 #define ZFCP_SPECIFIC_FLAGS 0x00ffffff
582 /* common status bits */
583 #define ZFCP_STATUS_COMMON_REMOVE 0x80000000
584 #define ZFCP_STATUS_COMMON_RUNNING 0x40000000
585 #define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
586 #define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
587 #define ZFCP_STATUS_COMMON_OPENING 0x08000000
588 #define ZFCP_STATUS_COMMON_OPEN 0x04000000
589 #define ZFCP_STATUS_COMMON_CLOSING 0x02000000
590 #define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
593 #define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
594 #define ZFCP_STATUS_ADAPTER_REGISTERED 0x00000004
595 #define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
596 #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
597 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
598 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
599 #define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
600 #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
602 #define ZFCP_STATUS_ADAPTER_SCSI_UP \
603 (ZFCP_STATUS_COMMON_UNBLOCKED | \
604 ZFCP_STATUS_ADAPTER_REGISTERED)
607 #define ZFCP_DID_NAMESERVER 0xFFFFFC
609 /* remote port status */
610 #define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
611 #define ZFCP_STATUS_PORT_DID_DID 0x00000002
612 #define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
613 #define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
614 #define ZFCP_STATUS_PORT_NO_SCSI_ID 0x00000010
615 #define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
617 #define ZFCP_STATUS_PORT_NAMESERVER \
618 (ZFCP_STATUS_PORT_NO_WWPN | \
619 ZFCP_STATUS_PORT_NO_SCSI_ID)
621 /* logical unit status */
622 #define ZFCP_STATUS_UNIT_NOTSUPPUNITRESET 0x00000001
625 /* FSF request status (this does not have a common part) */
626 #define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000
627 #define ZFCP_STATUS_FSFREQ_POOL 0x00000001
628 #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
629 #define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
630 #define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
631 #define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
632 #define ZFCP_STATUS_FSFREQ_ABORTING 0x00000020
633 #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
634 #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
635 #define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
636 #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
637 #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
638 #define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
639 #define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
641 /*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
643 #define ZFCP_MAX_ERPS 3
645 #define ZFCP_ERP_FSFREQ_TIMEOUT (30 * HZ)
646 #define ZFCP_ERP_MEMWAIT_TIMEOUT HZ
648 #define ZFCP_STATUS_ERP_TIMEDOUT 0x10000000
649 #define ZFCP_STATUS_ERP_CLOSE_ONLY 0x01000000
650 #define ZFCP_STATUS_ERP_DISMISSING 0x00100000
651 #define ZFCP_STATUS_ERP_DISMISSED 0x00200000
652 #define ZFCP_STATUS_ERP_LOWMEM 0x00400000
654 #define ZFCP_ERP_STEP_UNINITIALIZED 0x00000000
655 #define ZFCP_ERP_STEP_FSF_XCONFIG 0x00000001
656 #define ZFCP_ERP_STEP_PHYS_PORT_CLOSING 0x00000010
657 #define ZFCP_ERP_STEP_PORT_CLOSING 0x00000100
658 #define ZFCP_ERP_STEP_NAMESERVER_OPEN 0x00000200
659 #define ZFCP_ERP_STEP_NAMESERVER_LOOKUP 0x00000400
660 #define ZFCP_ERP_STEP_PORT_OPENING 0x00000800
661 #define ZFCP_ERP_STEP_UNIT_CLOSING 0x00001000
662 #define ZFCP_ERP_STEP_UNIT_OPENING 0x00002000
664 /* Ordered by escalation level (necessary for proper erp-code operation) */
665 #define ZFCP_ERP_ACTION_REOPEN_ADAPTER 0x4
666 #define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED 0x3
667 #define ZFCP_ERP_ACTION_REOPEN_PORT 0x2
668 #define ZFCP_ERP_ACTION_REOPEN_UNIT 0x1
670 #define ZFCP_ERP_ACTION_RUNNING 0x1
671 #define ZFCP_ERP_ACTION_READY 0x2
673 #define ZFCP_ERP_SUCCEEDED 0x0
674 #define ZFCP_ERP_FAILED 0x1
675 #define ZFCP_ERP_CONTINUES 0x2
676 #define ZFCP_ERP_EXIT 0x3
677 #define ZFCP_ERP_DISMISSED 0x4
678 #define ZFCP_ERP_NOMEM 0x5
681 /******************** CFDC SPECIFIC STUFF *****************************/
683 /* Firewall data channel sense data record */
684 struct zfcp_cfdc_sense_data {
685 u32 signature; /* Request signature */
686 u32 devno; /* FCP adapter device number */
687 u32 command; /* Command code */
688 u32 fsf_status; /* FSF request status and status qualifier */
689 u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
690 u8 payloads[256]; /* Access conflicts list */
691 u8 control_file[0]; /* Access control table */
694 #define ZFCP_CFDC_SIGNATURE 0xCFDCACDF
696 #define ZFCP_CFDC_CMND_DOWNLOAD_NORMAL 0x00010001
697 #define ZFCP_CFDC_CMND_DOWNLOAD_FORCE 0x00010101
698 #define ZFCP_CFDC_CMND_FULL_ACCESS 0x00000201
699 #define ZFCP_CFDC_CMND_RESTRICTED_ACCESS 0x00000401
700 #define ZFCP_CFDC_CMND_UPLOAD 0x00010002
702 #define ZFCP_CFDC_DOWNLOAD 0x00000001
703 #define ZFCP_CFDC_UPLOAD 0x00000002
704 #define ZFCP_CFDC_WITH_CONTROL_FILE 0x00010000
706 #define ZFCP_CFDC_DEV_NAME "zfcp_cfdc"
707 #define ZFCP_CFDC_DEV_MAJOR MISC_MAJOR
708 #define ZFCP_CFDC_DEV_MINOR MISC_DYNAMIC_MINOR
710 #define ZFCP_CFDC_MAX_CONTROL_FILE_SIZE 127 * 1024
712 /************************* STRUCTURE DEFINITIONS *****************************/
716 /* holds various memory pools of an adapter */
717 struct zfcp_adapter_mempool {
718 mempool_t *fsf_req_erp;
719 mempool_t *fsf_req_scsi;
720 mempool_t *fsf_req_abort;
721 mempool_t *fsf_req_status_read;
722 mempool_t *data_status_read;
723 mempool_t *data_gid_pn;
726 struct zfcp_exchange_config_data{
729 struct zfcp_open_port {
730 struct zfcp_port *port;
733 struct zfcp_close_port {
734 struct zfcp_port *port;
737 struct zfcp_open_unit {
738 struct zfcp_unit *unit;
741 struct zfcp_close_unit {
742 struct zfcp_unit *unit;
745 struct zfcp_close_physical_port {
746 struct zfcp_port *port;
749 struct zfcp_send_fcp_command_task {
750 struct zfcp_fsf_req *fsf_req;
751 struct zfcp_unit *unit;
752 struct scsi_cmnd *scsi_cmnd;
753 unsigned long start_jiffies;
756 struct zfcp_send_fcp_command_task_management {
757 struct zfcp_unit *unit;
760 struct zfcp_abort_fcp_command {
761 struct zfcp_fsf_req *fsf_req;
762 struct zfcp_unit *unit;
771 u8 gs_type; // 0xFC Directory Service
772 u8 gs_subtype; // 0x02 Name Server
773 u8 options; // 0x00 single bidirectional exchange
775 u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT
776 u16 max_res_size; // <= (4096 - 16) / 4
781 } __attribute__ ((packed));
783 /* nameserver request CT_IU -- for requests where
784 * a port name is required */
785 struct ct_iu_gid_pn_req {
786 struct ct_hdr header;
788 } __attribute__ ((packed));
790 /* nameserver request CT_IU -- for requests where
791 * a port identifier is required */
792 struct ct_iu_ga_nxt_req {
793 struct ct_hdr header;
795 } __attribute__ ((packed));
797 /* FS_ACC IU and data unit for GID_PN nameserver request */
798 struct ct_iu_gid_pn_resp {
799 struct ct_hdr header;
801 } __attribute__ ((packed));
803 /* FS_ACC IU and data unit for GA_NXT nameserver request */
804 struct ct_iu_ga_nxt_resp {
805 struct ct_hdr header;
809 u8 port_symbolic_name_length;
810 u8 port_symbolic_name[255];
812 u8 node_symbolic_name_length;
813 u8 node_symbolic_name[255];
814 u64 initial_process_associator;
822 } __attribute__ ((packed));
824 typedef void (*zfcp_send_ct_handler_t)(unsigned long);
826 /* used to pass parameters to zfcp_send_ct() */
827 struct zfcp_send_ct {
828 struct zfcp_port *port;
829 struct scatterlist *req;
830 struct scatterlist *resp;
831 unsigned int req_count;
832 unsigned int resp_count;
833 zfcp_send_ct_handler_t handler;
834 unsigned long handler_data;
835 mempool_t *pool; /* mempool for ct not for fsf_req */
837 struct timer_list *timer;
838 struct completion *completion;
842 /* used for name server requests in error recovery */
843 struct zfcp_gid_pn_data {
844 struct zfcp_send_ct ct;
845 struct scatterlist req;
846 struct scatterlist resp;
847 struct ct_iu_gid_pn_req ct_iu_req;
848 struct ct_iu_gid_pn_resp ct_iu_resp;
849 struct zfcp_port *port;
852 typedef int (*zfcp_send_els_handler_t)(unsigned long);
854 /* used to pass parameters to zfcp_send_els() */
855 /* ToDo merge send_ct() and send_els() and corresponding structs */
856 struct zfcp_send_els {
857 struct zfcp_port *port;
858 struct scatterlist *req;
859 struct scatterlist *resp;
860 unsigned int req_count;
861 unsigned int resp_count;
862 zfcp_send_els_handler_t handler;
863 unsigned long handler_data;
864 struct completion *completion;
869 struct zfcp_status_read {
870 struct fsf_status_read_buffer *buffer;
873 struct zfcp_fsf_done {
874 struct completion *complete;
878 /* request specific data */
879 union zfcp_req_data {
880 struct zfcp_exchange_config_data exchange_config_data;
881 struct zfcp_open_port open_port;
882 struct zfcp_close_port close_port;
883 struct zfcp_open_unit open_unit;
884 struct zfcp_close_unit close_unit;
885 struct zfcp_close_physical_port close_physical_port;
886 struct zfcp_send_fcp_command_task send_fcp_command_task;
887 struct zfcp_send_fcp_command_task_management
888 send_fcp_command_task_management;
889 struct zfcp_abort_fcp_command abort_fcp_command;
890 struct zfcp_send_ct *send_ct;
891 struct zfcp_send_els *send_els;
892 struct zfcp_status_read status_read;
895 struct zfcp_qdio_queue {
896 struct qdio_buffer *buffer[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
897 u8 free_index; /* index of next free bfr
898 in queue (free_count>0) */
899 atomic_t free_count; /* number of free buffers
901 rwlock_t queue_lock; /* lock for operations on queue */
902 int distance_from_int; /* SBALs used since PCI indication
906 struct zfcp_erp_action {
907 struct list_head list;
908 int action; /* requested action code */
909 struct zfcp_adapter *adapter; /* device which should be recovered */
910 struct zfcp_port *port;
911 struct zfcp_unit *unit;
912 volatile u32 status; /* recovery status */
913 u32 step; /* active step of this erp action */
914 struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
916 struct timer_list timer;
920 struct zfcp_adapter {
921 struct list_head list; /* list of adapters */
922 atomic_t refcount; /* reference count */
923 wait_queue_head_t remove_wq; /* can be used to wait for
924 refcount drop to zero */
925 wwn_t wwnn; /* WWNN */
926 wwn_t wwpn; /* WWPN */
927 fc_id_t s_id; /* N_Port ID */
928 struct ccw_device *ccw_device; /* S/390 ccw device */
930 u32 fc_topology; /* FC topology */
931 u32 fc_link_speed; /* FC interface speed */
932 u32 hydra_version; /* Hydra version */
934 u32 supported_features;/* of FCP channel */
935 u32 hardware_version; /* of FCP channel */
936 u8 serial_number[32]; /* of hardware */
937 struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
938 unsigned short scsi_host_no; /* Assigned host number */
939 unsigned char name[9];
940 struct list_head port_list_head; /* remote port list */
941 struct list_head port_remove_lh; /* head of ports to be
943 u32 ports; /* number of remote ports */
944 struct timer_list scsi_er_timer; /* SCSI err recovery watch */
945 struct list_head fsf_req_list_head; /* head of FSF req list */
946 rwlock_t fsf_req_list_lock; /* lock for ops on list of
948 atomic_t fsf_reqs_active; /* # active FSF reqs */
949 struct zfcp_qdio_queue request_queue; /* request queue */
950 u32 fsf_req_seq_no; /* FSF cmnd seq number */
951 wait_queue_head_t request_wq; /* can be used to wait for
952 more avaliable SBALs */
953 struct zfcp_qdio_queue response_queue; /* response queue */
954 rwlock_t abort_lock; /* Protects against SCSI
957 u16 status_read_failed; /* # failed status reads */
958 atomic_t status; /* status of this adapter */
959 struct list_head erp_ready_head; /* error recovery for this
961 struct list_head erp_running_head;
963 struct semaphore erp_ready_sem;
964 wait_queue_head_t erp_thread_wqh;
965 wait_queue_head_t erp_done_wqh;
966 struct zfcp_erp_action erp_action; /* pending error recovery */
967 atomic_t erp_counter;
968 u32 erp_total_count; /* total nr of enqueued erp
970 u32 erp_low_mem_count; /* nr of erp actions waiting
972 struct zfcp_port *nameserver_port; /* adapter's nameserver */
973 debug_info_t *erp_dbf; /* S/390 debug features */
974 debug_info_t *abort_dbf;
975 debug_info_t *in_els_dbf;
976 debug_info_t *cmd_dbf;
977 rwlock_t cmd_dbf_lock;
978 struct zfcp_adapter_mempool pool; /* Adapter memory pools */
979 struct qdio_initialize qdio_init_data; /* for qdio_establish */
983 * the struct device sysfs_device must be at the beginning of this structure.
984 * pointer to struct device is used to free port structure in release function
985 * of the device. don't change!
988 struct device sysfs_device; /* sysfs device */
989 struct list_head list; /* list of remote ports */
990 atomic_t refcount; /* reference count */
991 wait_queue_head_t remove_wq; /* can be used to wait for
992 refcount drop to zero */
993 struct zfcp_adapter *adapter; /* adapter used to access port */
994 struct list_head unit_list_head; /* head of logical unit list */
995 struct list_head unit_remove_lh; /* head of luns to be removed
997 u32 units; /* # of logical units in list */
998 atomic_t status; /* status of this remote port */
999 scsi_id_t scsi_id; /* own SCSI ID */
1000 wwn_t wwnn; /* WWNN if known */
1001 wwn_t wwpn; /* WWPN */
1002 fc_id_t d_id; /* D_ID */
1003 u32 handle; /* handle assigned by FSF */
1004 struct zfcp_erp_action erp_action; /* pending error recovery */
1005 atomic_t erp_counter;
1008 /* the struct device sysfs_device must be at the beginning of this structure.
1009 * pointer to struct device is used to free unit structure in release function
1010 * of the device. don't change!
1013 struct device sysfs_device; /* sysfs device */
1014 struct list_head list; /* list of logical units */
1015 atomic_t refcount; /* reference count */
1016 wait_queue_head_t remove_wq; /* can be used to wait for
1017 refcount drop to zero */
1018 struct zfcp_port *port; /* remote port of unit */
1019 atomic_t status; /* status of this logical unit */
1020 scsi_lun_t scsi_lun; /* own SCSI LUN */
1021 fcp_lun_t fcp_lun; /* own FCP_LUN */
1022 u32 handle; /* handle assigned by FSF */
1023 struct scsi_device *device; /* scsi device struct pointer */
1024 struct zfcp_erp_action erp_action; /* pending error recovery */
1025 atomic_t erp_counter;
1026 atomic_t scsi_add_work; /* used to synchronize */
1027 wait_queue_head_t scsi_add_wq; /* wait for scsi_add_device */
1031 struct zfcp_fsf_req {
1032 struct list_head list; /* list of FSF requests */
1033 struct zfcp_adapter *adapter; /* adapter request belongs to */
1034 u8 sbal_number; /* nr of SBALs free for use */
1035 u8 sbal_first; /* first SBAL for this request */
1036 u8 sbal_last; /* last possible SBAL for
1038 u8 sbal_curr; /* current SBAL during creation
1040 u8 sbale_curr; /* current SBALE during creation
1042 wait_queue_head_t completion_wq; /* can be used by a routine
1043 to wait for completion */
1044 volatile u32 status; /* status of this request */
1045 u32 fsf_command; /* FSF Command copy */
1046 struct fsf_qtcb *qtcb; /* address of associated QTCB */
1047 u32 seq_no; /* Sequence number of request */
1048 union zfcp_req_data data; /* Info fields of request */
1049 struct zfcp_erp_action *erp_action; /* used if this request is
1050 issued on behalf of erp */
1051 mempool_t *pool; /* used if request was alloacted
1052 from emergency pool */
1055 typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
1059 struct scsi_host_template scsi_host_template;
1060 atomic_t status; /* Module status flags */
1061 struct list_head adapter_list_head; /* head of adapter list */
1062 struct list_head adapter_remove_lh; /* head of adapters to be
1064 rwlock_t status_read_lock; /* for status read thread */
1065 struct list_head status_read_receive_head;
1066 struct list_head status_read_send_head;
1067 struct semaphore status_read_sema;
1068 wait_queue_head_t status_read_thread_wqh;
1069 u32 adapters; /* # of adapters in list */
1070 rwlock_t config_lock; /* serialises changes
1071 to adapter/port/unit
1073 struct semaphore config_sema; /* serialises configuration
1075 struct notifier_block reboot_notifier; /* used to register cleanup
1077 atomic_t loglevel; /* current loglevel */
1078 char init_busid[BUS_ID_SIZE];
1080 fcp_lun_t init_fcp_lun;
1083 struct zfcp_sg_list {
1084 struct scatterlist *sg;
1088 /* number of elements for various memory pools */
1089 #define ZFCP_POOL_FSF_REQ_ERP_NR 1
1090 #define ZFCP_POOL_FSF_REQ_SCSI_NR 1
1091 #define ZFCP_POOL_FSF_REQ_ABORT_NR 1
1092 #define ZFCP_POOL_STATUS_READ_NR ZFCP_STATUS_READS_RECOM
1093 #define ZFCP_POOL_DATA_GID_PN_NR 1
1095 /* struct used by memory pools for fsf_requests */
1096 struct zfcp_fsf_req_pool_element {
1097 struct zfcp_fsf_req fsf_req;
1098 struct fsf_qtcb qtcb;
1101 /********************** ZFCP SPECIFIC DEFINES ********************************/
1103 #define ZFCP_FSFREQ_CLEANUP_TIMEOUT HZ/10
1105 #define ZFCP_KNOWN 0x00000001
1106 #define ZFCP_REQ_AUTO_CLEANUP 0x00000002
1107 #define ZFCP_WAIT_FOR_SBAL 0x00000004
1108 #define ZFCP_REQ_NO_QTCB 0x00000008
1110 #define ZFCP_SET 0x00000100
1111 #define ZFCP_CLEAR 0x00000200
1113 #define ZFCP_INTERRUPTIBLE 1
1114 #define ZFCP_UNINTERRUPTIBLE 0
1116 #ifndef atomic_test_mask
1117 #define atomic_test_mask(mask, target) \
1118 ((atomic_read(target) & mask) == mask)
1121 extern void _zfcp_hex_dump(char *, int);
1122 #define ZFCP_HEX_DUMP(level, addr, count) \
1123 if (ZFCP_LOG_CHECK(level)) { \
1124 _zfcp_hex_dump(addr, count); \
1127 * Not yet optimal but useful:
1128 * Waits until the condition is met or the timeout occurs.
1129 * The condition may be a function call. This allows to
1130 * execute some additional instructions in addition
1131 * to a simple condition check.
1132 * The timeout is modified on exit and holds the remaining time.
1133 * Thus it is zero if a timeout ocurred, i.e. the condition was
1134 * not met in the specified interval.
1136 #define __ZFCP_WAIT_EVENT_TIMEOUT(timeout, condition) \
1138 set_current_state(TASK_UNINTERRUPTIBLE); \
1139 while (!(condition) && timeout) \
1140 timeout = schedule_timeout(timeout); \
1141 current->state = TASK_RUNNING; \
1144 #define ZFCP_WAIT_EVENT_TIMEOUT(waitqueue, timeout, condition) \
1146 wait_queue_t entry; \
1147 init_waitqueue_entry(&entry, current); \
1148 add_wait_queue(&waitqueue, &entry); \
1149 __ZFCP_WAIT_EVENT_TIMEOUT(timeout, condition) \
1150 remove_wait_queue(&waitqueue, &entry); \
1153 #define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
1154 #define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
1155 #define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
1158 * functions needed for reference/usage counting
1162 zfcp_unit_get(struct zfcp_unit *unit)
1164 atomic_inc(&unit->refcount);
1168 zfcp_unit_put(struct zfcp_unit *unit)
1170 if (atomic_dec_return(&unit->refcount) == 0)
1171 wake_up(&unit->remove_wq);
1175 zfcp_unit_wait(struct zfcp_unit *unit)
1177 wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
1181 zfcp_port_get(struct zfcp_port *port)
1183 atomic_inc(&port->refcount);
1187 zfcp_port_put(struct zfcp_port *port)
1189 if (atomic_dec_return(&port->refcount) == 0)
1190 wake_up(&port->remove_wq);
1194 zfcp_port_wait(struct zfcp_port *port)
1196 wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
1200 zfcp_adapter_get(struct zfcp_adapter *adapter)
1202 atomic_inc(&adapter->refcount);
1206 zfcp_adapter_put(struct zfcp_adapter *adapter)
1208 if (atomic_dec_return(&adapter->refcount) == 0)
1209 wake_up(&adapter->remove_wq);
1213 zfcp_adapter_wait(struct zfcp_adapter *adapter)
1215 wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
1218 #endif /* ZFCP_DEF_H */