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.75 $"
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 <scsi/scsi_transport.h>
51 #include <scsi/scsi_transport_fc.h>
52 #include "../../fc4/fc.h"
54 #include <asm/ccwdev.h>
56 #include <asm/debug.h>
57 #include <asm/ebcdic.h>
58 #include <linux/reboot.h>
59 #include <linux/mempool.h>
60 #include <linux/syscalls.h>
61 #include <linux/ioctl.h>
62 #ifdef CONFIG_S390_SUPPORT
63 #include <linux/ioctl32.h>
66 /************************ DEBUG FLAGS *****************************************/
68 #define ZFCP_PRINT_FLAGS
70 /********************* GENERAL DEFINES *********************************/
72 /* zfcp version number, it consists of major, minor, and patch-level number */
73 #define ZFCP_VERSION "4.0.0"
76 zfcp_sg_to_address(struct scatterlist *list)
78 return (void *) (page_address(list->page) + list->offset);
82 zfcp_address_to_sg(void *address, struct scatterlist *list)
84 list->page = virt_to_page(address);
85 list->offset = ((unsigned long) address) & (PAGE_SIZE - 1);
88 /********************* SCSI SPECIFIC DEFINES *********************************/
90 /* 32 bit for SCSI ID and LUN as long as the SCSI stack uses this type */
91 typedef u32 scsi_id_t;
92 typedef u32 scsi_lun_t;
94 #define ZFCP_ERP_SCSI_LOW_MEM_TIMEOUT (100*HZ)
95 #define ZFCP_SCSI_ER_TIMEOUT (100*HZ)
97 /********************* CIO/QDIO SPECIFIC DEFINES *****************************/
99 /* Adapter Identification Parameters */
100 #define ZFCP_CONTROL_UNIT_TYPE 0x1731
101 #define ZFCP_CONTROL_UNIT_MODEL 0x03
102 #define ZFCP_DEVICE_TYPE 0x1732
103 #define ZFCP_DEVICE_MODEL 0x03
104 #define ZFCP_DEVICE_MODEL_PRIV 0x04
106 /* allow as many chained SBALs as are supported by hardware */
107 #define ZFCP_MAX_SBALS_PER_REQ FSF_MAX_SBALS_PER_REQ
108 #define ZFCP_MAX_SBALS_PER_CT_REQ FSF_MAX_SBALS_PER_REQ
109 #define ZFCP_MAX_SBALS_PER_ELS_REQ FSF_MAX_SBALS_PER_ELS_REQ
111 /* DMQ bug workaround: don't use last SBALE */
112 #define ZFCP_MAX_SBALES_PER_SBAL (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
114 /* index of last SBALE (with respect to DMQ bug workaround) */
115 #define ZFCP_LAST_SBALE_PER_SBAL (ZFCP_MAX_SBALES_PER_SBAL - 1)
117 /* max. number of (data buffer) SBALEs in largest SBAL chain */
118 #define ZFCP_MAX_SBALES_PER_REQ \
119 (ZFCP_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
120 /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
122 /* FIXME(tune): free space should be one max. SBAL chain plus what? */
123 #define ZFCP_QDIO_PCI_INTERVAL (QDIO_MAX_BUFFERS_PER_Q \
124 - (ZFCP_MAX_SBALS_PER_REQ + 4))
126 #define ZFCP_SBAL_TIMEOUT (5*HZ)
128 #define ZFCP_TYPE2_RECOVERY_TIME (8*HZ)
130 /* queue polling (values in microseconds) */
131 #define ZFCP_MAX_INPUT_THRESHOLD 5000 /* FIXME: tune */
132 #define ZFCP_MAX_OUTPUT_THRESHOLD 1000 /* FIXME: tune */
133 #define ZFCP_MIN_INPUT_THRESHOLD 1 /* ignored by QDIO layer */
134 #define ZFCP_MIN_OUTPUT_THRESHOLD 1 /* ignored by QDIO layer */
136 #define QDIO_SCSI_QFMT 1 /* 1 for FSF */
138 /********************* FSF SPECIFIC DEFINES *********************************/
140 #define ZFCP_ULP_INFO_VERSION 26
141 #define ZFCP_QTCB_VERSION FSF_QTCB_CURRENT_VERSION
142 /* ATTENTION: value must not be used by hardware */
143 #define FSF_QTCB_UNSOLICITED_STATUS 0x6305
144 #define ZFCP_STATUS_READ_FAILED_THRESHOLD 3
145 #define ZFCP_STATUS_READS_RECOM FSF_STATUS_READS_RECOM
146 #define ZFCP_EXCHANGE_CONFIG_DATA_RETRIES 6
147 #define ZFCP_EXCHANGE_CONFIG_DATA_SLEEP 50
149 /*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
151 typedef unsigned long long wwn_t;
152 typedef unsigned int fc_id_t;
153 typedef unsigned long long fcp_lun_t;
154 /* data length field may be at variable position in FCP-2 FCP_CMND IU */
155 typedef unsigned int fcp_dl_t;
157 #define ZFCP_FC_SERVICE_CLASS_DEFAULT FSF_CLASS_3
159 /* timeout for name-server lookup (in seconds) */
160 #define ZFCP_NS_GID_PN_TIMEOUT 10
161 #define ZFCP_NS_GA_NXT_TIMEOUT 120
163 /* largest SCSI command we can process */
164 /* FCP-2 (FCP_CMND IU) allows up to (255-3+16) */
165 #define ZFCP_MAX_SCSI_CMND_LENGTH 255
166 /* maximum number of commands in LUN queue (tagged queueing) */
167 #define ZFCP_CMND_PER_LUN 32
169 /* task attribute values in FCP-2 FCP_CMND IU */
176 /* task management flags in FCP-2 FCP_CMND IU */
177 #define CLEAR_ACA 0x40
178 #define TARGET_RESET 0x20
179 #define LOGICAL_UNIT_RESET 0x10
180 #define CLEAR_TASK_SET 0x04
181 #define ABORT_TASK_SET 0x02
183 #define FCP_CDB_LENGTH 16
185 #define ZFCP_DID_MASK 0x00FFFFFF
187 /* FCP(-2) FCP_CMND IU */
189 fcp_lun_t fcp_lun; /* FCP logical unit number */
190 u8 crn; /* command reference number */
191 u8 reserved0:5; /* reserved */
192 u8 task_attribute:3; /* task attribute */
193 u8 task_management_flags; /* task management flags */
194 u8 add_fcp_cdb_length:6; /* additional FCP_CDB length */
195 u8 rddata:1; /* read data */
196 u8 wddata:1; /* write data */
197 u8 fcp_cdb[FCP_CDB_LENGTH];
198 } __attribute__((packed));
200 /* FCP(-2) FCP_RSP IU */
207 u8 fcp_resid_under:1;
209 u8 fcp_sns_len_valid:1;
210 u8 fcp_rsp_len_valid:1;
218 } __attribute__((packed));
221 #define RSP_CODE_GOOD 0
222 #define RSP_CODE_LENGTH_MISMATCH 1
223 #define RSP_CODE_FIELD_INVALID 2
224 #define RSP_CODE_RO_MISMATCH 3
225 #define RSP_CODE_TASKMAN_UNSUPP 4
226 #define RSP_CODE_TASKMAN_FAILED 5
229 #define LS_FAN 0x60000000
230 #define LS_RSCN 0x61040000
232 struct fcp_rscn_head {
234 u8 page_length; /* always 0x04 */
236 } __attribute__((packed));
238 struct fcp_rscn_element {
243 } __attribute__((packed));
245 #define ZFCP_PORT_ADDRESS 0x0
246 #define ZFCP_AREA_ADDRESS 0x1
247 #define ZFCP_DOMAIN_ADDRESS 0x2
248 #define ZFCP_FABRIC_ADDRESS 0x3
250 #define ZFCP_PORTS_RANGE_PORT 0xFFFFFF
251 #define ZFCP_PORTS_RANGE_AREA 0xFFFF00
252 #define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
253 #define ZFCP_PORTS_RANGE_FABRIC 0x000000
255 #define ZFCP_NO_PORTS_PER_AREA 0x100
256 #define ZFCP_NO_PORTS_PER_DOMAIN 0x10000
257 #define ZFCP_NO_PORTS_PER_FABRIC 0x1000000
264 } __attribute__((packed));
271 } __attribute__((packed));
276 #define R_A_TOV 10 /* seconds */
277 #define ZFCP_ELS_TIMEOUT (2 * R_A_TOV)
279 #define ZFCP_LS_RJT 0x01
280 #define ZFCP_LS_ACC 0x02
281 #define ZFCP_LS_RTV 0x0E
282 #define ZFCP_LS_RLS 0x0F
283 #define ZFCP_LS_PDISC 0x50
284 #define ZFCP_LS_ADISC 0x52
285 #define ZFCP_LS_RSCN 0x61
286 #define ZFCP_LS_RNID 0x78
287 #define ZFCP_LS_RLIR 0x7A
288 #define ZFCP_LS_RTV_E_D_TOV_FLAG 0x04000000
290 /* LS_ACC Reason Codes */
291 #define ZFCP_LS_RJT_INVALID_COMMAND_CODE 0x01
292 #define ZFCP_LS_RJT_LOGICAL_ERROR 0x03
293 #define ZFCP_LS_RJT_LOGICAL_BUSY 0x05
294 #define ZFCP_LS_RJT_PROTOCOL_ERROR 0x07
295 #define ZFCP_LS_RJT_UNABLE_TO_PERFORM 0x09
296 #define ZFCP_LS_RJT_COMMAND_NOT_SUPPORTED 0x0B
297 #define ZFCP_LS_RJT_VENDOR_UNIQUE_ERROR 0xFF
306 } __attribute__ ((packed));
311 } __attribute__ ((packed));
313 struct zfcp_ls_rtv_acc {
319 } __attribute__ ((packed));
325 } __attribute__ ((packed));
327 struct zfcp_ls_rls_acc {
330 u32 link_failure_count;
331 u32 loss_of_sync_count;
332 u32 loss_of_signal_count;
333 u32 prim_seq_prot_error;
334 u32 invalid_transmition_word;
335 u32 invalid_crc_count;
336 } __attribute__ ((packed));
338 struct zfcp_ls_pdisc {
341 u8 common_svc_parm[16];
350 u8 vendor_version[16];
351 } __attribute__ ((packed));
353 struct zfcp_ls_pdisc_acc {
356 u8 common_svc_parm[16];
365 u8 vendor_version[16];
366 } __attribute__ ((packed));
368 struct zfcp_ls_adisc {
371 fc_id_t hard_nport_id;
375 } __attribute__ ((packed));
377 struct zfcp_ls_adisc_acc {
380 fc_id_t hard_nport_id;
384 } __attribute__ ((packed));
386 struct zfcp_ls_rnid {
391 } __attribute__((packed));
393 /* common identification data */
394 struct zfcp_ls_rnid_common_id {
397 } __attribute__((packed));
399 /* general topology specific identification data */
400 struct zfcp_ls_rnid_general_topology_id {
401 u8 vendor_unique[16];
403 u32 physical_port_number;
404 u32 nr_attached_nodes;
411 } __attribute__((packed));
413 struct zfcp_ls_rnid_acc {
419 u8 specific_id_length;
420 struct zfcp_ls_rnid_common_id
422 struct zfcp_ls_rnid_general_topology_id
424 } __attribute__((packed));
429 #define ZFCP_CT_REVISION 0x01
430 #define ZFCP_CT_DIRECTORY_SERVICE 0xFC
431 #define ZFCP_CT_NAME_SERVER 0x02
432 #define ZFCP_CT_SYNCHRONOUS 0x00
433 #define ZFCP_CT_GID_PN 0x0121
434 #define ZFCP_CT_GA_NXT 0x0100
435 #define ZFCP_CT_MAX_SIZE 0x1020
436 #define ZFCP_CT_ACCEPT 0x8002
441 #define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
444 /***************** S390 DEBUG FEATURE SPECIFIC DEFINES ***********************/
446 /* debug feature entries per adapter */
447 #define ZFCP_ERP_DBF_INDEX 1
448 #define ZFCP_ERP_DBF_AREAS 2
449 #define ZFCP_ERP_DBF_LENGTH 16
450 #define ZFCP_ERP_DBF_LEVEL 3
451 #define ZFCP_ERP_DBF_NAME "zfcperp"
453 #define ZFCP_CMD_DBF_INDEX 2
454 #define ZFCP_CMD_DBF_AREAS 1
455 #define ZFCP_CMD_DBF_LENGTH 8
456 #define ZFCP_CMD_DBF_LEVEL 3
457 #define ZFCP_CMD_DBF_NAME "zfcpcmd"
459 #define ZFCP_ABORT_DBF_INDEX 2
460 #define ZFCP_ABORT_DBF_AREAS 1
461 #define ZFCP_ABORT_DBF_LENGTH 8
462 #define ZFCP_ABORT_DBF_LEVEL 6
463 #define ZFCP_ABORT_DBF_NAME "zfcpabt"
465 #define ZFCP_IN_ELS_DBF_INDEX 2
466 #define ZFCP_IN_ELS_DBF_AREAS 1
467 #define ZFCP_IN_ELS_DBF_LENGTH 8
468 #define ZFCP_IN_ELS_DBF_LEVEL 6
469 #define ZFCP_IN_ELS_DBF_NAME "zfcpels"
471 /******************** LOGGING MACROS AND DEFINES *****************************/
474 * Logging may be applied on certain kinds of driver operations
475 * independently. Additionally, different log-levels are supported for
476 * each of these areas.
479 #define ZFCP_NAME "zfcp"
481 /* independent log areas */
482 #define ZFCP_LOG_AREA_OTHER 0
483 #define ZFCP_LOG_AREA_SCSI 1
484 #define ZFCP_LOG_AREA_FSF 2
485 #define ZFCP_LOG_AREA_CONFIG 3
486 #define ZFCP_LOG_AREA_CIO 4
487 #define ZFCP_LOG_AREA_QDIO 5
488 #define ZFCP_LOG_AREA_ERP 6
489 #define ZFCP_LOG_AREA_FC 7
491 /* log level values*/
492 #define ZFCP_LOG_LEVEL_NORMAL 0
493 #define ZFCP_LOG_LEVEL_INFO 1
494 #define ZFCP_LOG_LEVEL_DEBUG 2
495 #define ZFCP_LOG_LEVEL_TRACE 3
498 * this allows removal of logging code by the preprocessor
499 * (the most detailed log level still to be compiled in is specified,
500 * higher log levels are removed)
502 #define ZFCP_LOG_LEVEL_LIMIT ZFCP_LOG_LEVEL_TRACE
504 /* get "loglevel" nibble assignment */
505 #define ZFCP_GET_LOG_VALUE(zfcp_lognibble) \
506 ((atomic_read(&zfcp_data.loglevel) >> (zfcp_lognibble<<2)) & 0xF)
508 /* set "loglevel" nibble */
509 #define ZFCP_SET_LOG_NIBBLE(value, zfcp_lognibble) \
510 (value << (zfcp_lognibble << 2))
512 /* all log-level defaults are combined to generate initial log-level */
513 #define ZFCP_LOG_LEVEL_DEFAULTS \
514 (ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_OTHER) | \
515 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_SCSI) | \
516 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FSF) | \
517 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CONFIG) | \
518 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CIO) | \
519 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_QDIO) | \
520 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_ERP) | \
521 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FC))
523 /* check whether we have the right level for logging */
524 #define ZFCP_LOG_CHECK(level) \
525 ((ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA)) >= level)
527 /* logging routine for zfcp */
528 #define _ZFCP_LOG(fmt, args...) \
529 printk(KERN_ERR ZFCP_NAME": %s(%d): " fmt, __FUNCTION__, \
532 #define ZFCP_LOG(level, fmt, args...) \
533 if (ZFCP_LOG_CHECK(level)) \
534 _ZFCP_LOG(fmt , ##args)
536 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_NORMAL
537 # define ZFCP_LOG_NORMAL(fmt, args...)
539 # define ZFCP_LOG_NORMAL(fmt, args...) \
540 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_NORMAL)) \
541 printk(KERN_ERR ZFCP_NAME": " fmt , ##args);
544 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_INFO
545 # define ZFCP_LOG_INFO(fmt, args...)
547 # define ZFCP_LOG_INFO(fmt, args...) \
548 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_INFO)) \
549 printk(KERN_ERR ZFCP_NAME": " fmt , ##args);
552 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_DEBUG
553 # define ZFCP_LOG_DEBUG(fmt, args...)
555 # define ZFCP_LOG_DEBUG(fmt, args...) \
556 ZFCP_LOG(ZFCP_LOG_LEVEL_DEBUG, fmt , ##args)
559 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_TRACE
560 # define ZFCP_LOG_TRACE(fmt, args...)
562 # define ZFCP_LOG_TRACE(fmt, args...) \
563 ZFCP_LOG(ZFCP_LOG_LEVEL_TRACE, fmt , ##args)
566 #ifndef ZFCP_PRINT_FLAGS
567 # define ZFCP_LOG_FLAGS(level, fmt, args...)
569 extern u32 flags_dump;
570 # define ZFCP_LOG_FLAGS(level, fmt, args...) \
571 if (level <= flags_dump) \
572 _ZFCP_LOG(fmt , ##args)
575 /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
578 * Note, the leftmost status byte is common among adapter, port
581 #define ZFCP_COMMON_FLAGS 0xff000000
582 #define ZFCP_SPECIFIC_FLAGS 0x00ffffff
584 /* common status bits */
585 #define ZFCP_STATUS_COMMON_REMOVE 0x80000000
586 #define ZFCP_STATUS_COMMON_RUNNING 0x40000000
587 #define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
588 #define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
589 #define ZFCP_STATUS_COMMON_OPENING 0x08000000
590 #define ZFCP_STATUS_COMMON_OPEN 0x04000000
591 #define ZFCP_STATUS_COMMON_CLOSING 0x02000000
592 #define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
595 #define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
596 #define ZFCP_STATUS_ADAPTER_REGISTERED 0x00000004
597 #define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
598 #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
599 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
600 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
601 #define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
602 #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
604 #define ZFCP_STATUS_ADAPTER_SCSI_UP \
605 (ZFCP_STATUS_COMMON_UNBLOCKED | \
606 ZFCP_STATUS_ADAPTER_REGISTERED)
609 #define ZFCP_DID_NAMESERVER 0xFFFFFC
611 /* remote port status */
612 #define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
613 #define ZFCP_STATUS_PORT_DID_DID 0x00000002
614 #define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
615 #define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
616 #define ZFCP_STATUS_PORT_NO_SCSI_ID 0x00000010
617 #define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
619 #define ZFCP_STATUS_PORT_NAMESERVER \
620 (ZFCP_STATUS_PORT_NO_WWPN | \
621 ZFCP_STATUS_PORT_NO_SCSI_ID)
623 /* logical unit status */
624 #define ZFCP_STATUS_UNIT_NOTSUPPUNITRESET 0x00000001
627 /* FSF request status (this does not have a common part) */
628 #define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000
629 #define ZFCP_STATUS_FSFREQ_POOL 0x00000001
630 #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
631 #define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
632 #define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
633 #define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
634 #define ZFCP_STATUS_FSFREQ_ABORTING 0x00000020
635 #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
636 #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
637 #define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
638 #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
639 #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
640 #define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
641 #define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
643 /*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
645 #define ZFCP_MAX_ERPS 3
647 #define ZFCP_ERP_FSFREQ_TIMEOUT (30 * HZ)
648 #define ZFCP_ERP_MEMWAIT_TIMEOUT HZ
650 #define ZFCP_STATUS_ERP_TIMEDOUT 0x10000000
651 #define ZFCP_STATUS_ERP_CLOSE_ONLY 0x01000000
652 #define ZFCP_STATUS_ERP_DISMISSING 0x00100000
653 #define ZFCP_STATUS_ERP_DISMISSED 0x00200000
654 #define ZFCP_STATUS_ERP_LOWMEM 0x00400000
656 #define ZFCP_ERP_STEP_UNINITIALIZED 0x00000000
657 #define ZFCP_ERP_STEP_FSF_XCONFIG 0x00000001
658 #define ZFCP_ERP_STEP_PHYS_PORT_CLOSING 0x00000010
659 #define ZFCP_ERP_STEP_PORT_CLOSING 0x00000100
660 #define ZFCP_ERP_STEP_NAMESERVER_OPEN 0x00000200
661 #define ZFCP_ERP_STEP_NAMESERVER_LOOKUP 0x00000400
662 #define ZFCP_ERP_STEP_PORT_OPENING 0x00000800
663 #define ZFCP_ERP_STEP_UNIT_CLOSING 0x00001000
664 #define ZFCP_ERP_STEP_UNIT_OPENING 0x00002000
666 /* Ordered by escalation level (necessary for proper erp-code operation) */
667 #define ZFCP_ERP_ACTION_REOPEN_ADAPTER 0x4
668 #define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED 0x3
669 #define ZFCP_ERP_ACTION_REOPEN_PORT 0x2
670 #define ZFCP_ERP_ACTION_REOPEN_UNIT 0x1
672 #define ZFCP_ERP_ACTION_RUNNING 0x1
673 #define ZFCP_ERP_ACTION_READY 0x2
675 #define ZFCP_ERP_SUCCEEDED 0x0
676 #define ZFCP_ERP_FAILED 0x1
677 #define ZFCP_ERP_CONTINUES 0x2
678 #define ZFCP_ERP_EXIT 0x3
679 #define ZFCP_ERP_DISMISSED 0x4
680 #define ZFCP_ERP_NOMEM 0x5
683 /******************** CFDC SPECIFIC STUFF *****************************/
685 /* Firewall data channel sense data record */
686 struct zfcp_cfdc_sense_data {
687 u32 signature; /* Request signature */
688 u32 devno; /* FCP adapter device number */
689 u32 command; /* Command code */
690 u32 fsf_status; /* FSF request status and status qualifier */
691 u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
692 u8 payloads[256]; /* Access conflicts list */
693 u8 control_file[0]; /* Access control table */
696 #define ZFCP_CFDC_SIGNATURE 0xCFDCACDF
698 #define ZFCP_CFDC_CMND_DOWNLOAD_NORMAL 0x00010001
699 #define ZFCP_CFDC_CMND_DOWNLOAD_FORCE 0x00010101
700 #define ZFCP_CFDC_CMND_FULL_ACCESS 0x00000201
701 #define ZFCP_CFDC_CMND_RESTRICTED_ACCESS 0x00000401
702 #define ZFCP_CFDC_CMND_UPLOAD 0x00010002
704 #define ZFCP_CFDC_DOWNLOAD 0x00000001
705 #define ZFCP_CFDC_UPLOAD 0x00000002
706 #define ZFCP_CFDC_WITH_CONTROL_FILE 0x00010000
708 #define ZFCP_CFDC_DEV_NAME "zfcp_cfdc"
709 #define ZFCP_CFDC_DEV_MAJOR MISC_MAJOR
710 #define ZFCP_CFDC_DEV_MINOR MISC_DYNAMIC_MINOR
712 #define ZFCP_CFDC_MAX_CONTROL_FILE_SIZE 127 * 1024
714 /************************* STRUCTURE DEFINITIONS *****************************/
718 /* holds various memory pools of an adapter */
719 struct zfcp_adapter_mempool {
720 mempool_t *fsf_req_erp;
721 mempool_t *fsf_req_scsi;
722 mempool_t *fsf_req_abort;
723 mempool_t *fsf_req_status_read;
724 mempool_t *data_status_read;
725 mempool_t *data_gid_pn;
728 struct zfcp_exchange_config_data{
731 struct zfcp_open_port {
732 struct zfcp_port *port;
735 struct zfcp_close_port {
736 struct zfcp_port *port;
739 struct zfcp_open_unit {
740 struct zfcp_unit *unit;
743 struct zfcp_close_unit {
744 struct zfcp_unit *unit;
747 struct zfcp_close_physical_port {
748 struct zfcp_port *port;
751 struct zfcp_send_fcp_command_task {
752 struct zfcp_fsf_req *fsf_req;
753 struct zfcp_unit *unit;
754 struct scsi_cmnd *scsi_cmnd;
755 unsigned long start_jiffies;
758 struct zfcp_send_fcp_command_task_management {
759 struct zfcp_unit *unit;
762 struct zfcp_abort_fcp_command {
763 struct zfcp_fsf_req *fsf_req;
764 struct zfcp_unit *unit;
773 u8 gs_type; // 0xFC Directory Service
774 u8 gs_subtype; // 0x02 Name Server
775 u8 options; // 0x00 single bidirectional exchange
777 u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT
778 u16 max_res_size; // <= (4096 - 16) / 4
783 } __attribute__ ((packed));
785 /* nameserver request CT_IU -- for requests where
786 * a port name is required */
787 struct ct_iu_gid_pn_req {
788 struct ct_hdr header;
790 } __attribute__ ((packed));
792 /* nameserver request CT_IU -- for requests where
793 * a port identifier is required */
794 struct ct_iu_ga_nxt_req {
795 struct ct_hdr header;
797 } __attribute__ ((packed));
799 /* FS_ACC IU and data unit for GID_PN nameserver request */
800 struct ct_iu_gid_pn_resp {
801 struct ct_hdr header;
803 } __attribute__ ((packed));
805 /* FS_ACC IU and data unit for GA_NXT nameserver request */
806 struct ct_iu_ga_nxt_resp {
807 struct ct_hdr header;
811 u8 port_symbolic_name_length;
812 u8 port_symbolic_name[255];
814 u8 node_symbolic_name_length;
815 u8 node_symbolic_name[255];
816 u64 initial_process_associator;
824 } __attribute__ ((packed));
826 typedef void (*zfcp_send_ct_handler_t)(unsigned long);
828 /* used to pass parameters to zfcp_send_ct() */
829 struct zfcp_send_ct {
830 struct zfcp_port *port;
831 struct scatterlist *req;
832 struct scatterlist *resp;
833 unsigned int req_count;
834 unsigned int resp_count;
835 zfcp_send_ct_handler_t handler;
836 unsigned long handler_data;
837 mempool_t *pool; /* mempool for ct not for fsf_req */
839 struct timer_list *timer;
840 struct completion *completion;
844 /* used for name server requests in error recovery */
845 struct zfcp_gid_pn_data {
846 struct zfcp_send_ct ct;
847 struct scatterlist req;
848 struct scatterlist resp;
849 struct ct_iu_gid_pn_req ct_iu_req;
850 struct ct_iu_gid_pn_resp ct_iu_resp;
851 struct zfcp_port *port;
854 typedef int (*zfcp_send_els_handler_t)(unsigned long);
856 /* used to pass parameters to zfcp_send_els() */
857 /* ToDo merge send_ct() and send_els() and corresponding structs */
858 struct zfcp_send_els {
859 struct zfcp_port *port;
860 struct scatterlist *req;
861 struct scatterlist *resp;
862 unsigned int req_count;
863 unsigned int resp_count;
864 zfcp_send_els_handler_t handler;
865 unsigned long handler_data;
866 struct completion *completion;
871 struct zfcp_status_read {
872 struct fsf_status_read_buffer *buffer;
875 struct zfcp_fsf_done {
876 struct completion *complete;
880 /* request specific data */
881 union zfcp_req_data {
882 struct zfcp_exchange_config_data exchange_config_data;
883 struct zfcp_open_port open_port;
884 struct zfcp_close_port close_port;
885 struct zfcp_open_unit open_unit;
886 struct zfcp_close_unit close_unit;
887 struct zfcp_close_physical_port close_physical_port;
888 struct zfcp_send_fcp_command_task send_fcp_command_task;
889 struct zfcp_send_fcp_command_task_management
890 send_fcp_command_task_management;
891 struct zfcp_abort_fcp_command abort_fcp_command;
892 struct zfcp_send_ct *send_ct;
893 struct zfcp_send_els *send_els;
894 struct zfcp_status_read status_read;
897 struct zfcp_qdio_queue {
898 struct qdio_buffer *buffer[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
899 u8 free_index; /* index of next free bfr
900 in queue (free_count>0) */
901 atomic_t free_count; /* number of free buffers
903 rwlock_t queue_lock; /* lock for operations on queue */
904 int distance_from_int; /* SBALs used since PCI indication
908 struct zfcp_erp_action {
909 struct list_head list;
910 int action; /* requested action code */
911 struct zfcp_adapter *adapter; /* device which should be recovered */
912 struct zfcp_port *port;
913 struct zfcp_unit *unit;
914 volatile u32 status; /* recovery status */
915 u32 step; /* active step of this erp action */
916 struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
918 struct timer_list timer;
922 struct zfcp_adapter {
923 struct list_head list; /* list of adapters */
924 atomic_t refcount; /* reference count */
925 wait_queue_head_t remove_wq; /* can be used to wait for
926 refcount drop to zero */
927 wwn_t wwnn; /* WWNN */
928 wwn_t wwpn; /* WWPN */
929 fc_id_t s_id; /* N_Port ID */
930 struct ccw_device *ccw_device; /* S/390 ccw device */
932 u32 fc_topology; /* FC topology */
933 u32 fc_link_speed; /* FC interface speed */
934 u32 hydra_version; /* Hydra version */
936 u32 supported_features;/* of FCP channel */
937 u32 hardware_version; /* of FCP channel */
938 u8 serial_number[32]; /* of hardware */
939 struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
940 unsigned short scsi_host_no; /* Assigned host number */
941 unsigned char name[9];
942 struct list_head port_list_head; /* remote port list */
943 struct list_head port_remove_lh; /* head of ports to be
945 u32 ports; /* number of remote ports */
946 struct timer_list scsi_er_timer; /* SCSI err recovery watch */
947 struct list_head fsf_req_list_head; /* head of FSF req list */
948 rwlock_t fsf_req_list_lock; /* lock for ops on list of
950 atomic_t fsf_reqs_active; /* # active FSF reqs */
951 struct zfcp_qdio_queue request_queue; /* request queue */
952 u32 fsf_req_seq_no; /* FSF cmnd seq number */
953 wait_queue_head_t request_wq; /* can be used to wait for
954 more avaliable SBALs */
955 struct zfcp_qdio_queue response_queue; /* response queue */
956 rwlock_t abort_lock; /* Protects against SCSI
959 u16 status_read_failed; /* # failed status reads */
960 atomic_t status; /* status of this adapter */
961 struct list_head erp_ready_head; /* error recovery for this
963 struct list_head erp_running_head;
965 struct semaphore erp_ready_sem;
966 wait_queue_head_t erp_thread_wqh;
967 wait_queue_head_t erp_done_wqh;
968 struct zfcp_erp_action erp_action; /* pending error recovery */
969 atomic_t erp_counter;
970 u32 erp_total_count; /* total nr of enqueued erp
972 u32 erp_low_mem_count; /* nr of erp actions waiting
974 struct zfcp_port *nameserver_port; /* adapter's nameserver */
975 debug_info_t *erp_dbf; /* S/390 debug features */
976 debug_info_t *abort_dbf;
977 debug_info_t *in_els_dbf;
978 debug_info_t *cmd_dbf;
979 rwlock_t cmd_dbf_lock;
980 struct zfcp_adapter_mempool pool; /* Adapter memory pools */
981 struct qdio_initialize qdio_init_data; /* for qdio_establish */
985 * the struct device sysfs_device must be at the beginning of this structure.
986 * pointer to struct device is used to free port structure in release function
987 * of the device. don't change!
990 struct device sysfs_device; /* sysfs device */
991 struct list_head list; /* list of remote ports */
992 atomic_t refcount; /* reference count */
993 wait_queue_head_t remove_wq; /* can be used to wait for
994 refcount drop to zero */
995 struct zfcp_adapter *adapter; /* adapter used to access port */
996 struct list_head unit_list_head; /* head of logical unit list */
997 struct list_head unit_remove_lh; /* head of luns to be removed
999 u32 units; /* # of logical units in list */
1000 atomic_t status; /* status of this remote port */
1001 scsi_id_t scsi_id; /* own SCSI ID */
1002 wwn_t wwnn; /* WWNN if known */
1003 wwn_t wwpn; /* WWPN */
1004 fc_id_t d_id; /* D_ID */
1005 u32 handle; /* handle assigned by FSF */
1006 struct zfcp_erp_action erp_action; /* pending error recovery */
1007 atomic_t erp_counter;
1010 /* the struct device sysfs_device must be at the beginning of this structure.
1011 * pointer to struct device is used to free unit structure in release function
1012 * of the device. don't change!
1015 struct device sysfs_device; /* sysfs device */
1016 struct list_head list; /* list of logical units */
1017 atomic_t refcount; /* reference count */
1018 wait_queue_head_t remove_wq; /* can be used to wait for
1019 refcount drop to zero */
1020 struct zfcp_port *port; /* remote port of unit */
1021 atomic_t status; /* status of this logical unit */
1022 scsi_lun_t scsi_lun; /* own SCSI LUN */
1023 fcp_lun_t fcp_lun; /* own FCP_LUN */
1024 u32 handle; /* handle assigned by FSF */
1025 struct scsi_device *device; /* scsi device struct pointer */
1026 struct zfcp_erp_action erp_action; /* pending error recovery */
1027 atomic_t erp_counter;
1028 atomic_t scsi_add_work; /* used to synchronize */
1029 wait_queue_head_t scsi_add_wq; /* wait for scsi_add_device */
1033 struct zfcp_fsf_req {
1034 struct list_head list; /* list of FSF requests */
1035 struct zfcp_adapter *adapter; /* adapter request belongs to */
1036 u8 sbal_number; /* nr of SBALs free for use */
1037 u8 sbal_first; /* first SBAL for this request */
1038 u8 sbal_last; /* last possible SBAL for
1040 u8 sbal_curr; /* current SBAL during creation
1042 u8 sbale_curr; /* current SBALE during creation
1044 wait_queue_head_t completion_wq; /* can be used by a routine
1045 to wait for completion */
1046 volatile u32 status; /* status of this request */
1047 u32 fsf_command; /* FSF Command copy */
1048 struct fsf_qtcb *qtcb; /* address of associated QTCB */
1049 u32 seq_no; /* Sequence number of request */
1050 union zfcp_req_data data; /* Info fields of request */
1051 struct zfcp_erp_action *erp_action; /* used if this request is
1052 issued on behalf of erp */
1053 mempool_t *pool; /* used if request was alloacted
1054 from emergency pool */
1057 typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
1061 struct scsi_host_template scsi_host_template;
1062 atomic_t status; /* Module status flags */
1063 struct list_head adapter_list_head; /* head of adapter list */
1064 struct list_head adapter_remove_lh; /* head of adapters to be
1066 rwlock_t status_read_lock; /* for status read thread */
1067 struct list_head status_read_receive_head;
1068 struct list_head status_read_send_head;
1069 struct semaphore status_read_sema;
1070 wait_queue_head_t status_read_thread_wqh;
1071 u32 adapters; /* # of adapters in list */
1072 rwlock_t config_lock; /* serialises changes
1073 to adapter/port/unit
1075 struct semaphore config_sema; /* serialises configuration
1077 struct notifier_block reboot_notifier; /* used to register cleanup
1079 atomic_t loglevel; /* current loglevel */
1080 char init_busid[BUS_ID_SIZE];
1082 fcp_lun_t init_fcp_lun;
1085 struct zfcp_sg_list {
1086 struct scatterlist *sg;
1090 /* number of elements for various memory pools */
1091 #define ZFCP_POOL_FSF_REQ_ERP_NR 1
1092 #define ZFCP_POOL_FSF_REQ_SCSI_NR 1
1093 #define ZFCP_POOL_FSF_REQ_ABORT_NR 1
1094 #define ZFCP_POOL_STATUS_READ_NR ZFCP_STATUS_READS_RECOM
1095 #define ZFCP_POOL_DATA_GID_PN_NR 1
1097 /* struct used by memory pools for fsf_requests */
1098 struct zfcp_fsf_req_pool_element {
1099 struct zfcp_fsf_req fsf_req;
1100 struct fsf_qtcb qtcb;
1103 /********************** ZFCP SPECIFIC DEFINES ********************************/
1105 #define ZFCP_FSFREQ_CLEANUP_TIMEOUT HZ/10
1107 #define ZFCP_KNOWN 0x00000001
1108 #define ZFCP_REQ_AUTO_CLEANUP 0x00000002
1109 #define ZFCP_WAIT_FOR_SBAL 0x00000004
1110 #define ZFCP_REQ_NO_QTCB 0x00000008
1112 #define ZFCP_SET 0x00000100
1113 #define ZFCP_CLEAR 0x00000200
1115 #define ZFCP_INTERRUPTIBLE 1
1116 #define ZFCP_UNINTERRUPTIBLE 0
1118 #ifndef atomic_test_mask
1119 #define atomic_test_mask(mask, target) \
1120 ((atomic_read(target) & mask) == mask)
1123 extern void _zfcp_hex_dump(char *, int);
1124 #define ZFCP_HEX_DUMP(level, addr, count) \
1125 if (ZFCP_LOG_CHECK(level)) { \
1126 _zfcp_hex_dump(addr, count); \
1129 * Not yet optimal but useful:
1130 * Waits until the condition is met or the timeout occurs.
1131 * The condition may be a function call. This allows to
1132 * execute some additional instructions in addition
1133 * to a simple condition check.
1134 * The timeout is modified on exit and holds the remaining time.
1135 * Thus it is zero if a timeout ocurred, i.e. the condition was
1136 * not met in the specified interval.
1138 #define __ZFCP_WAIT_EVENT_TIMEOUT(timeout, condition) \
1140 set_current_state(TASK_UNINTERRUPTIBLE); \
1141 while (!(condition) && timeout) \
1142 timeout = schedule_timeout(timeout); \
1143 current->state = TASK_RUNNING; \
1146 #define ZFCP_WAIT_EVENT_TIMEOUT(waitqueue, timeout, condition) \
1148 wait_queue_t entry; \
1149 init_waitqueue_entry(&entry, current); \
1150 add_wait_queue(&waitqueue, &entry); \
1151 __ZFCP_WAIT_EVENT_TIMEOUT(timeout, condition) \
1152 remove_wait_queue(&waitqueue, &entry); \
1155 #define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
1156 #define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
1157 #define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
1160 * functions needed for reference/usage counting
1164 zfcp_unit_get(struct zfcp_unit *unit)
1166 atomic_inc(&unit->refcount);
1170 zfcp_unit_put(struct zfcp_unit *unit)
1172 if (atomic_dec_return(&unit->refcount) == 0)
1173 wake_up(&unit->remove_wq);
1177 zfcp_unit_wait(struct zfcp_unit *unit)
1179 wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
1183 zfcp_port_get(struct zfcp_port *port)
1185 atomic_inc(&port->refcount);
1189 zfcp_port_put(struct zfcp_port *port)
1191 if (atomic_dec_return(&port->refcount) == 0)
1192 wake_up(&port->remove_wq);
1196 zfcp_port_wait(struct zfcp_port *port)
1198 wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
1202 zfcp_adapter_get(struct zfcp_adapter *adapter)
1204 atomic_inc(&adapter->refcount);
1208 zfcp_adapter_put(struct zfcp_adapter *adapter)
1210 if (atomic_dec_return(&adapter->refcount) == 0)
1211 wake_up(&adapter->remove_wq);
1215 zfcp_adapter_wait(struct zfcp_adapter *adapter)
1217 wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
1220 #endif /* ZFCP_DEF_H */