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>
15 * Andreas Herrmann <aherrman@de.ibm.com>
16 * Volker Sameske <sameske@de.ibm.com>
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2, or (at your option)
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
37 /*************************** INCLUDES *****************************************/
39 #include <linux/init.h>
40 #include <linux/moduleparam.h>
41 #include <linux/miscdevice.h>
42 #include <linux/major.h>
43 #include <linux/blkdev.h>
44 #include <linux/delay.h>
45 #include <linux/timer.h>
46 #include <scsi/scsi.h>
47 #include <scsi/scsi_tcq.h>
48 #include <scsi/scsi_cmnd.h>
49 #include <scsi/scsi_device.h>
50 #include <scsi/scsi_host.h>
51 #include <scsi/scsi_transport.h>
52 #include <scsi/scsi_transport_fc.h>
53 #include "../../fc4/fc.h"
55 #include <asm/ccwdev.h>
57 #include <asm/debug.h>
58 #include <asm/ebcdic.h>
59 #include <linux/mempool.h>
60 #include <linux/syscalls.h>
61 #include <linux/ioctl.h>
64 /********************* GENERAL DEFINES *********************************/
66 /* zfcp version number, it consists of major, minor, and patch-level number */
67 #define ZFCP_VERSION "4.5.0"
70 * zfcp_sg_to_address - determine kernel address from struct scatterlist
71 * @list: struct scatterlist
72 * Return: kernel address
75 zfcp_sg_to_address(struct scatterlist *list)
77 return (void *) (page_address(list->page) + list->offset);
81 * zfcp_address_to_sg - set up struct scatterlist from kernel address
82 * @address: kernel address
83 * @list: struct scatterlist
86 zfcp_address_to_sg(void *address, struct scatterlist *list)
88 list->page = virt_to_page(address);
89 list->offset = ((unsigned long) address) & (PAGE_SIZE - 1);
92 /********************* SCSI SPECIFIC DEFINES *********************************/
94 /* 32 bit for SCSI ID and LUN as long as the SCSI stack uses this type */
95 typedef u32 scsi_id_t;
96 typedef u32 scsi_lun_t;
98 #define ZFCP_ERP_SCSI_LOW_MEM_TIMEOUT (100*HZ)
99 #define ZFCP_SCSI_ER_TIMEOUT (100*HZ)
101 /********************* CIO/QDIO SPECIFIC DEFINES *****************************/
103 /* Adapter Identification Parameters */
104 #define ZFCP_CONTROL_UNIT_TYPE 0x1731
105 #define ZFCP_CONTROL_UNIT_MODEL 0x03
106 #define ZFCP_DEVICE_TYPE 0x1732
107 #define ZFCP_DEVICE_MODEL 0x03
108 #define ZFCP_DEVICE_MODEL_PRIV 0x04
110 /* allow as many chained SBALs as are supported by hardware */
111 #define ZFCP_MAX_SBALS_PER_REQ FSF_MAX_SBALS_PER_REQ
112 #define ZFCP_MAX_SBALS_PER_CT_REQ FSF_MAX_SBALS_PER_REQ
113 #define ZFCP_MAX_SBALS_PER_ELS_REQ FSF_MAX_SBALS_PER_ELS_REQ
115 /* DMQ bug workaround: don't use last SBALE */
116 #define ZFCP_MAX_SBALES_PER_SBAL (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
118 /* index of last SBALE (with respect to DMQ bug workaround) */
119 #define ZFCP_LAST_SBALE_PER_SBAL (ZFCP_MAX_SBALES_PER_SBAL - 1)
121 /* max. number of (data buffer) SBALEs in largest SBAL chain */
122 #define ZFCP_MAX_SBALES_PER_REQ \
123 (ZFCP_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
124 /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
126 /* FIXME(tune): free space should be one max. SBAL chain plus what? */
127 #define ZFCP_QDIO_PCI_INTERVAL (QDIO_MAX_BUFFERS_PER_Q \
128 - (ZFCP_MAX_SBALS_PER_REQ + 4))
130 #define ZFCP_SBAL_TIMEOUT (5*HZ)
132 #define ZFCP_TYPE2_RECOVERY_TIME (8*HZ)
134 /* queue polling (values in microseconds) */
135 #define ZFCP_MAX_INPUT_THRESHOLD 5000 /* FIXME: tune */
136 #define ZFCP_MAX_OUTPUT_THRESHOLD 1000 /* FIXME: tune */
137 #define ZFCP_MIN_INPUT_THRESHOLD 1 /* ignored by QDIO layer */
138 #define ZFCP_MIN_OUTPUT_THRESHOLD 1 /* ignored by QDIO layer */
140 #define QDIO_SCSI_QFMT 1 /* 1 for FSF */
142 /********************* FSF SPECIFIC DEFINES *********************************/
144 #define ZFCP_ULP_INFO_VERSION 26
145 #define ZFCP_QTCB_VERSION FSF_QTCB_CURRENT_VERSION
146 /* ATTENTION: value must not be used by hardware */
147 #define FSF_QTCB_UNSOLICITED_STATUS 0x6305
148 #define ZFCP_STATUS_READ_FAILED_THRESHOLD 3
149 #define ZFCP_STATUS_READS_RECOM FSF_STATUS_READS_RECOM
151 /* Do 1st retry in 1 second, then double the timeout for each following retry */
152 #define ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP 100
153 #define ZFCP_EXCHANGE_CONFIG_DATA_RETRIES 7
155 /* timeout value for "default timer" for fsf requests */
156 #define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ);
158 /*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
160 typedef unsigned long long wwn_t;
161 typedef unsigned long long fcp_lun_t;
162 /* data length field may be at variable position in FCP-2 FCP_CMND IU */
163 typedef unsigned int fcp_dl_t;
165 #define ZFCP_FC_SERVICE_CLASS_DEFAULT FSF_CLASS_3
167 /* timeout for name-server lookup (in seconds) */
168 #define ZFCP_NS_GID_PN_TIMEOUT 10
170 /* largest SCSI command we can process */
171 /* FCP-2 (FCP_CMND IU) allows up to (255-3+16) */
172 #define ZFCP_MAX_SCSI_CMND_LENGTH 255
173 /* maximum number of commands in LUN queue (tagged queueing) */
174 #define ZFCP_CMND_PER_LUN 32
176 /* task attribute values in FCP-2 FCP_CMND IU */
183 /* task management flags in FCP-2 FCP_CMND IU */
184 #define FCP_CLEAR_ACA 0x40
185 #define FCP_TARGET_RESET 0x20
186 #define FCP_LOGICAL_UNIT_RESET 0x10
187 #define FCP_CLEAR_TASK_SET 0x04
188 #define FCP_ABORT_TASK_SET 0x02
190 #define FCP_CDB_LENGTH 16
192 #define ZFCP_DID_MASK 0x00FFFFFF
194 /* FCP(-2) FCP_CMND IU */
196 fcp_lun_t fcp_lun; /* FCP logical unit number */
197 u8 crn; /* command reference number */
198 u8 reserved0:5; /* reserved */
199 u8 task_attribute:3; /* task attribute */
200 u8 task_management_flags; /* task management flags */
201 u8 add_fcp_cdb_length:6; /* additional FCP_CDB length */
202 u8 rddata:1; /* read data */
203 u8 wddata:1; /* write data */
204 u8 fcp_cdb[FCP_CDB_LENGTH];
205 } __attribute__((packed));
207 /* FCP(-2) FCP_RSP IU */
214 u8 fcp_resid_under:1;
216 u8 fcp_sns_len_valid:1;
217 u8 fcp_rsp_len_valid:1;
225 } __attribute__((packed));
228 #define RSP_CODE_GOOD 0
229 #define RSP_CODE_LENGTH_MISMATCH 1
230 #define RSP_CODE_FIELD_INVALID 2
231 #define RSP_CODE_RO_MISMATCH 3
232 #define RSP_CODE_TASKMAN_UNSUPP 4
233 #define RSP_CODE_TASKMAN_FAILED 5
236 #define LS_FAN 0x60000000
237 #define LS_RSCN 0x61040000
239 struct fcp_rscn_head {
241 u8 page_length; /* always 0x04 */
243 } __attribute__((packed));
245 struct fcp_rscn_element {
250 } __attribute__((packed));
252 #define ZFCP_PORT_ADDRESS 0x0
253 #define ZFCP_AREA_ADDRESS 0x1
254 #define ZFCP_DOMAIN_ADDRESS 0x2
255 #define ZFCP_FABRIC_ADDRESS 0x3
257 #define ZFCP_PORTS_RANGE_PORT 0xFFFFFF
258 #define ZFCP_PORTS_RANGE_AREA 0xFFFF00
259 #define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
260 #define ZFCP_PORTS_RANGE_FABRIC 0x000000
262 #define ZFCP_NO_PORTS_PER_AREA 0x100
263 #define ZFCP_NO_PORTS_PER_DOMAIN 0x10000
264 #define ZFCP_NO_PORTS_PER_FABRIC 0x1000000
271 } __attribute__((packed));
278 } __attribute__((packed));
283 #define ZFCP_DBF_TAG_SIZE 4
285 struct zfcp_dbf_dump {
286 u8 tag[ZFCP_DBF_TAG_SIZE];
287 u32 total_size; /* size of total dump data */
288 u32 offset; /* how much data has being already dumped */
289 u32 size; /* how much data comes with this record */
290 u8 data[]; /* dump data */
291 } __attribute__ ((packed));
293 /* FIXME: to be inflated when reworking the erp dbf */
294 struct zfcp_erp_dbf_record {
296 } __attribute__ ((packed));
298 struct zfcp_hba_dbf_record_response {
305 u8 fsf_prot_status_qual[FSF_PROT_STATUS_QUAL_SIZE];
306 u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
334 } __attribute__ ((packed));
336 struct zfcp_hba_dbf_record_status {
340 struct fsf_queue_designator
343 #define ZFCP_DBF_UNSOL_PAYLOAD 80
344 #define ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL 32
345 #define ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD 56
346 #define ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT 2 * sizeof(u32)
347 u8 payload[ZFCP_DBF_UNSOL_PAYLOAD];
348 } __attribute__ ((packed));
350 struct zfcp_hba_dbf_record_qdio {
356 } __attribute__ ((packed));
358 struct zfcp_hba_dbf_record {
359 u8 tag[ZFCP_DBF_TAG_SIZE];
360 u8 tag2[ZFCP_DBF_TAG_SIZE];
362 struct zfcp_hba_dbf_record_response response;
363 struct zfcp_hba_dbf_record_status status;
364 struct zfcp_hba_dbf_record_qdio qdio;
366 } __attribute__ ((packed));
368 struct zfcp_san_dbf_record_ct {
387 #define ZFCP_DBF_CT_PAYLOAD 24
388 u8 payload[ZFCP_DBF_CT_PAYLOAD];
389 } __attribute__ ((packed));
391 struct zfcp_san_dbf_record_els {
394 #define ZFCP_DBF_ELS_PAYLOAD 32
395 #define ZFCP_DBF_ELS_MAX_PAYLOAD 1024
396 u8 payload[ZFCP_DBF_ELS_PAYLOAD];
397 } __attribute__ ((packed));
399 struct zfcp_san_dbf_record {
400 u8 tag[ZFCP_DBF_TAG_SIZE];
406 struct zfcp_san_dbf_record_ct ct;
407 struct zfcp_san_dbf_record_els els;
409 } __attribute__ ((packed));
411 struct zfcp_scsi_dbf_record {
412 u8 tag[ZFCP_DBF_TAG_SIZE];
413 u8 tag2[ZFCP_DBF_TAG_SIZE];
419 #define ZFCP_DBF_SCSI_OPCODE 16
420 u8 scsi_opcode[ZFCP_DBF_SCSI_OPCODE];
433 #define ZFCP_DBF_SCSI_FCP_SNS_INFO 16
434 #define ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO 256
436 u8 sns_info[ZFCP_DBF_SCSI_FCP_SNS_INFO];
439 } __attribute__ ((packed));
444 #define R_A_TOV 10 /* seconds */
445 #define ZFCP_ELS_TIMEOUT (2 * R_A_TOV)
447 #define ZFCP_LS_RLS 0x0f
448 #define ZFCP_LS_ADISC 0x52
449 #define ZFCP_LS_RPS 0x56
450 #define ZFCP_LS_RSCN 0x61
451 #define ZFCP_LS_RNID 0x78
453 struct zfcp_ls_rjt_par {
458 } __attribute__ ((packed));
460 struct zfcp_ls_adisc {
467 } __attribute__ ((packed));
469 struct zfcp_ls_adisc_acc {
476 } __attribute__ ((packed));
478 struct zfcp_rc_entry {
480 const char *description;
486 #define ZFCP_CT_REVISION 0x01
487 #define ZFCP_CT_DIRECTORY_SERVICE 0xFC
488 #define ZFCP_CT_NAME_SERVER 0x02
489 #define ZFCP_CT_SYNCHRONOUS 0x00
490 #define ZFCP_CT_GID_PN 0x0121
491 #define ZFCP_CT_MAX_SIZE 0x1020
492 #define ZFCP_CT_ACCEPT 0x8002
493 #define ZFCP_CT_REJECT 0x8001
498 #define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
500 /******************** LOGGING MACROS AND DEFINES *****************************/
503 * Logging may be applied on certain kinds of driver operations
504 * independently. Additionally, different log-levels are supported for
505 * each of these areas.
508 #define ZFCP_NAME "zfcp"
510 /* read-only LUN sharing switch initial value */
511 #define ZFCP_RO_LUN_SHARING_DEFAULTS 0
513 /* independent log areas */
514 #define ZFCP_LOG_AREA_OTHER 0
515 #define ZFCP_LOG_AREA_SCSI 1
516 #define ZFCP_LOG_AREA_FSF 2
517 #define ZFCP_LOG_AREA_CONFIG 3
518 #define ZFCP_LOG_AREA_CIO 4
519 #define ZFCP_LOG_AREA_QDIO 5
520 #define ZFCP_LOG_AREA_ERP 6
521 #define ZFCP_LOG_AREA_FC 7
523 /* log level values*/
524 #define ZFCP_LOG_LEVEL_NORMAL 0
525 #define ZFCP_LOG_LEVEL_INFO 1
526 #define ZFCP_LOG_LEVEL_DEBUG 2
527 #define ZFCP_LOG_LEVEL_TRACE 3
530 * this allows removal of logging code by the preprocessor
531 * (the most detailed log level still to be compiled in is specified,
532 * higher log levels are removed)
534 #define ZFCP_LOG_LEVEL_LIMIT ZFCP_LOG_LEVEL_TRACE
536 /* get "loglevel" nibble assignment */
537 #define ZFCP_GET_LOG_VALUE(zfcp_lognibble) \
538 ((atomic_read(&zfcp_data.loglevel) >> (zfcp_lognibble<<2)) & 0xF)
540 /* set "loglevel" nibble */
541 #define ZFCP_SET_LOG_NIBBLE(value, zfcp_lognibble) \
542 (value << (zfcp_lognibble << 2))
544 /* all log-level defaults are combined to generate initial log-level */
545 #define ZFCP_LOG_LEVEL_DEFAULTS \
546 (ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_OTHER) | \
547 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_SCSI) | \
548 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FSF) | \
549 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CONFIG) | \
550 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CIO) | \
551 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_QDIO) | \
552 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_ERP) | \
553 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FC))
555 /* check whether we have the right level for logging */
556 #define ZFCP_LOG_CHECK(level) \
557 ((ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA)) >= level)
559 /* logging routine for zfcp */
560 #define _ZFCP_LOG(fmt, args...) \
561 printk(KERN_ERR ZFCP_NAME": %s(%d): " fmt, __FUNCTION__, \
564 #define ZFCP_LOG(level, fmt, args...) \
566 if (ZFCP_LOG_CHECK(level)) \
567 _ZFCP_LOG(fmt, ##args); \
570 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_NORMAL
571 # define ZFCP_LOG_NORMAL(fmt, args...)
573 # define ZFCP_LOG_NORMAL(fmt, args...) \
575 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_NORMAL)) \
576 printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
580 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_INFO
581 # define ZFCP_LOG_INFO(fmt, args...)
583 # define ZFCP_LOG_INFO(fmt, args...) \
585 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_INFO)) \
586 printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
590 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_DEBUG
591 # define ZFCP_LOG_DEBUG(fmt, args...)
593 # define ZFCP_LOG_DEBUG(fmt, args...) \
594 ZFCP_LOG(ZFCP_LOG_LEVEL_DEBUG, fmt , ##args)
597 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_TRACE
598 # define ZFCP_LOG_TRACE(fmt, args...)
600 # define ZFCP_LOG_TRACE(fmt, args...) \
601 ZFCP_LOG(ZFCP_LOG_LEVEL_TRACE, fmt , ##args)
604 /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
607 * Note, the leftmost status byte is common among adapter, port
610 #define ZFCP_COMMON_FLAGS 0xfff00000
611 #define ZFCP_SPECIFIC_FLAGS 0x000fffff
613 /* common status bits */
614 #define ZFCP_STATUS_COMMON_REMOVE 0x80000000
615 #define ZFCP_STATUS_COMMON_RUNNING 0x40000000
616 #define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
617 #define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
618 #define ZFCP_STATUS_COMMON_OPENING 0x08000000
619 #define ZFCP_STATUS_COMMON_OPEN 0x04000000
620 #define ZFCP_STATUS_COMMON_CLOSING 0x02000000
621 #define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
622 #define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
623 #define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
626 #define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
627 #define ZFCP_STATUS_ADAPTER_REGISTERED 0x00000004
628 #define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
629 #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
630 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
631 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
632 #define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
633 #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
634 #define ZFCP_STATUS_ADAPTER_XPORT_OK 0x00000800
636 #define ZFCP_STATUS_ADAPTER_SCSI_UP \
637 (ZFCP_STATUS_COMMON_UNBLOCKED | \
638 ZFCP_STATUS_ADAPTER_REGISTERED)
641 /* FC-PH/FC-GS well-known address identifiers for generic services */
642 #define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA
643 #define ZFCP_DID_TIME_SERVICE 0xFFFFFB
644 #define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC
645 #define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8
646 #define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7
648 /* remote port status */
649 #define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
650 #define ZFCP_STATUS_PORT_DID_DID 0x00000002
651 #define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
652 #define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
653 #define ZFCP_STATUS_PORT_NO_SCSI_ID 0x00000010
654 #define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
655 #define ZFCP_STATUS_PORT_ACCESS_DENIED 0x00000040
657 /* for ports with well known addresses */
658 #define ZFCP_STATUS_PORT_WKA \
659 (ZFCP_STATUS_PORT_NO_WWPN | \
660 ZFCP_STATUS_PORT_NO_SCSI_ID)
662 /* logical unit status */
663 #define ZFCP_STATUS_UNIT_NOTSUPPUNITRESET 0x00000001
664 #define ZFCP_STATUS_UNIT_TEMPORARY 0x00000002
665 #define ZFCP_STATUS_UNIT_SHARED 0x00000004
666 #define ZFCP_STATUS_UNIT_READONLY 0x00000008
668 /* FSF request status (this does not have a common part) */
669 #define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000
670 #define ZFCP_STATUS_FSFREQ_POOL 0x00000001
671 #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
672 #define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
673 #define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
674 #define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
675 #define ZFCP_STATUS_FSFREQ_ABORTING 0x00000020
676 #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
677 #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
678 #define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
679 #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
680 #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
681 #define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
682 #define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
684 /*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
686 #define ZFCP_MAX_ERPS 3
688 #define ZFCP_ERP_FSFREQ_TIMEOUT (30 * HZ)
689 #define ZFCP_ERP_MEMWAIT_TIMEOUT HZ
691 #define ZFCP_STATUS_ERP_TIMEDOUT 0x10000000
692 #define ZFCP_STATUS_ERP_CLOSE_ONLY 0x01000000
693 #define ZFCP_STATUS_ERP_DISMISSING 0x00100000
694 #define ZFCP_STATUS_ERP_DISMISSED 0x00200000
695 #define ZFCP_STATUS_ERP_LOWMEM 0x00400000
697 #define ZFCP_ERP_STEP_UNINITIALIZED 0x00000000
698 #define ZFCP_ERP_STEP_FSF_XCONFIG 0x00000001
699 #define ZFCP_ERP_STEP_PHYS_PORT_CLOSING 0x00000010
700 #define ZFCP_ERP_STEP_PORT_CLOSING 0x00000100
701 #define ZFCP_ERP_STEP_NAMESERVER_OPEN 0x00000200
702 #define ZFCP_ERP_STEP_NAMESERVER_LOOKUP 0x00000400
703 #define ZFCP_ERP_STEP_PORT_OPENING 0x00000800
704 #define ZFCP_ERP_STEP_UNIT_CLOSING 0x00001000
705 #define ZFCP_ERP_STEP_UNIT_OPENING 0x00002000
707 /* Ordered by escalation level (necessary for proper erp-code operation) */
708 #define ZFCP_ERP_ACTION_REOPEN_ADAPTER 0x4
709 #define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED 0x3
710 #define ZFCP_ERP_ACTION_REOPEN_PORT 0x2
711 #define ZFCP_ERP_ACTION_REOPEN_UNIT 0x1
713 #define ZFCP_ERP_ACTION_RUNNING 0x1
714 #define ZFCP_ERP_ACTION_READY 0x2
716 #define ZFCP_ERP_SUCCEEDED 0x0
717 #define ZFCP_ERP_FAILED 0x1
718 #define ZFCP_ERP_CONTINUES 0x2
719 #define ZFCP_ERP_EXIT 0x3
720 #define ZFCP_ERP_DISMISSED 0x4
721 #define ZFCP_ERP_NOMEM 0x5
724 /******************** CFDC SPECIFIC STUFF *****************************/
726 /* Firewall data channel sense data record */
727 struct zfcp_cfdc_sense_data {
728 u32 signature; /* Request signature */
729 u32 devno; /* FCP adapter device number */
730 u32 command; /* Command code */
731 u32 fsf_status; /* FSF request status and status qualifier */
732 u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
733 u8 payloads[256]; /* Access conflicts list */
734 u8 control_file[0]; /* Access control table */
737 #define ZFCP_CFDC_SIGNATURE 0xCFDCACDF
739 #define ZFCP_CFDC_CMND_DOWNLOAD_NORMAL 0x00010001
740 #define ZFCP_CFDC_CMND_DOWNLOAD_FORCE 0x00010101
741 #define ZFCP_CFDC_CMND_FULL_ACCESS 0x00000201
742 #define ZFCP_CFDC_CMND_RESTRICTED_ACCESS 0x00000401
743 #define ZFCP_CFDC_CMND_UPLOAD 0x00010002
745 #define ZFCP_CFDC_DOWNLOAD 0x00000001
746 #define ZFCP_CFDC_UPLOAD 0x00000002
747 #define ZFCP_CFDC_WITH_CONTROL_FILE 0x00010000
749 #define ZFCP_CFDC_DEV_NAME "zfcp_cfdc"
750 #define ZFCP_CFDC_DEV_MAJOR MISC_MAJOR
751 #define ZFCP_CFDC_DEV_MINOR MISC_DYNAMIC_MINOR
753 #define ZFCP_CFDC_MAX_CONTROL_FILE_SIZE 127 * 1024
755 /************************* STRUCTURE DEFINITIONS *****************************/
759 /* holds various memory pools of an adapter */
760 struct zfcp_adapter_mempool {
761 mempool_t *fsf_req_erp;
762 mempool_t *fsf_req_scsi;
763 mempool_t *fsf_req_abort;
764 mempool_t *fsf_req_status_read;
765 mempool_t *data_status_read;
766 mempool_t *data_gid_pn;
775 u8 gs_type; // 0xFC Directory Service
776 u8 gs_subtype; // 0x02 Name Server
777 u8 options; // 0x00 single bidirectional exchange
779 u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT
780 u16 max_res_size; // <= (4096 - 16) / 4
785 } __attribute__ ((packed));
787 /* nameserver request CT_IU -- for requests where
788 * a port name is required */
789 struct ct_iu_gid_pn_req {
790 struct ct_hdr header;
792 } __attribute__ ((packed));
794 /* FS_ACC IU and data unit for GID_PN nameserver request */
795 struct ct_iu_gid_pn_resp {
796 struct ct_hdr header;
798 } __attribute__ ((packed));
800 typedef void (*zfcp_send_ct_handler_t)(unsigned long);
803 * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
804 * @port: port where the request is sent to
805 * @req: scatter-gather list for request
806 * @resp: scatter-gather list for response
807 * @req_count: number of elements in request scatter-gather list
808 * @resp_count: number of elements in response scatter-gather list
809 * @handler: handler function (called for response to the request)
810 * @handler_data: data passed to handler function
811 * @pool: pointer to memory pool for ct request structure
812 * @timeout: FSF timeout for this request
813 * @timer: timer (e.g. for request initiated by erp)
814 * @completion: completion for synchronization purposes
815 * @status: used to pass error status to calling function
817 struct zfcp_send_ct {
818 struct zfcp_port *port;
819 struct scatterlist *req;
820 struct scatterlist *resp;
821 unsigned int req_count;
822 unsigned int resp_count;
823 zfcp_send_ct_handler_t handler;
824 unsigned long handler_data;
827 struct timer_list *timer;
828 struct completion *completion;
832 /* used for name server requests in error recovery */
833 struct zfcp_gid_pn_data {
834 struct zfcp_send_ct ct;
835 struct scatterlist req;
836 struct scatterlist resp;
837 struct ct_iu_gid_pn_req ct_iu_req;
838 struct ct_iu_gid_pn_resp ct_iu_resp;
839 struct zfcp_port *port;
842 typedef void (*zfcp_send_els_handler_t)(unsigned long);
845 * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
846 * @adapter: adapter where request is sent from
847 * @port: port where ELS is destinated (port reference count has to be increased)
848 * @d_id: destiniation id of port where request is sent to
849 * @req: scatter-gather list for request
850 * @resp: scatter-gather list for response
851 * @req_count: number of elements in request scatter-gather list
852 * @resp_count: number of elements in response scatter-gather list
853 * @handler: handler function (called for response to the request)
854 * @handler_data: data passed to handler function
855 * @timer: timer (e.g. for request initiated by erp)
856 * @completion: completion for synchronization purposes
857 * @ls_code: hex code of ELS command
858 * @status: used to pass error status to calling function
860 struct zfcp_send_els {
861 struct zfcp_adapter *adapter;
862 struct zfcp_port *port;
864 struct scatterlist *req;
865 struct scatterlist *resp;
866 unsigned int req_count;
867 unsigned int resp_count;
868 zfcp_send_els_handler_t handler;
869 unsigned long handler_data;
870 struct timer_list *timer;
871 struct completion *completion;
876 struct zfcp_qdio_queue {
877 struct qdio_buffer *buffer[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
878 u8 free_index; /* index of next free bfr
879 in queue (free_count>0) */
880 atomic_t free_count; /* number of free buffers
882 rwlock_t queue_lock; /* lock for operations on queue */
883 int distance_from_int; /* SBALs used since PCI indication
887 struct zfcp_erp_action {
888 struct list_head list;
889 int action; /* requested action code */
890 struct zfcp_adapter *adapter; /* device which should be recovered */
891 struct zfcp_port *port;
892 struct zfcp_unit *unit;
893 volatile u32 status; /* recovery status */
894 u32 step; /* active step of this erp action */
895 struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
897 struct timer_list timer;
901 struct zfcp_adapter {
902 struct list_head list; /* list of adapters */
903 atomic_t refcount; /* reference count */
904 wait_queue_head_t remove_wq; /* can be used to wait for
905 refcount drop to zero */
906 wwn_t peer_wwnn; /* P2P peer WWNN */
907 wwn_t peer_wwpn; /* P2P peer WWPN */
908 u32 peer_d_id; /* P2P peer D_ID */
909 struct ccw_device *ccw_device; /* S/390 ccw device */
911 u32 hydra_version; /* Hydra version */
913 u32 adapter_features; /* FCP channel features */
914 u32 connection_features; /* host connection features */
915 u32 hardware_version; /* of FCP channel */
916 struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
917 unsigned short scsi_host_no; /* Assigned host number */
918 unsigned char name[9];
919 struct list_head port_list_head; /* remote port list */
920 struct list_head port_remove_lh; /* head of ports to be
922 u32 ports; /* number of remote ports */
923 struct timer_list scsi_er_timer; /* SCSI err recovery watch */
924 struct list_head fsf_req_list_head; /* head of FSF req list */
925 spinlock_t fsf_req_list_lock; /* lock for ops on list of
927 atomic_t fsf_reqs_active; /* # active FSF reqs */
928 struct zfcp_qdio_queue request_queue; /* request queue */
929 u32 fsf_req_seq_no; /* FSF cmnd seq number */
930 wait_queue_head_t request_wq; /* can be used to wait for
931 more avaliable SBALs */
932 struct zfcp_qdio_queue response_queue; /* response queue */
933 rwlock_t abort_lock; /* Protects against SCSI
936 u16 status_read_failed; /* # failed status reads */
937 atomic_t status; /* status of this adapter */
938 struct list_head erp_ready_head; /* error recovery for this
940 struct list_head erp_running_head;
942 struct semaphore erp_ready_sem;
943 wait_queue_head_t erp_thread_wqh;
944 wait_queue_head_t erp_done_wqh;
945 struct zfcp_erp_action erp_action; /* pending error recovery */
946 atomic_t erp_counter;
947 u32 erp_total_count; /* total nr of enqueued erp
949 u32 erp_low_mem_count; /* nr of erp actions waiting
951 struct zfcp_port *nameserver_port; /* adapter's nameserver */
952 debug_info_t *erp_dbf;
953 debug_info_t *hba_dbf;
954 debug_info_t *san_dbf; /* debug feature areas */
955 debug_info_t *scsi_dbf;
956 spinlock_t erp_dbf_lock;
957 spinlock_t hba_dbf_lock;
958 spinlock_t san_dbf_lock;
959 spinlock_t scsi_dbf_lock;
960 struct zfcp_erp_dbf_record erp_dbf_buf;
961 struct zfcp_hba_dbf_record hba_dbf_buf;
962 struct zfcp_san_dbf_record san_dbf_buf;
963 struct zfcp_scsi_dbf_record scsi_dbf_buf;
964 struct zfcp_adapter_mempool pool; /* Adapter memory pools */
965 struct qdio_initialize qdio_init_data; /* for qdio_establish */
966 struct device generic_services; /* directory for WKA ports */
967 struct fc_host_statistics *fc_stats;
968 struct fsf_qtcb_bottom_port *stats_reset_data;
969 unsigned long stats_reset;
973 * the struct device sysfs_device must be at the beginning of this structure.
974 * pointer to struct device is used to free port structure in release function
975 * of the device. don't change!
978 struct device sysfs_device; /* sysfs device */
979 struct fc_rport *rport; /* rport of fc transport class */
980 struct list_head list; /* list of remote ports */
981 atomic_t refcount; /* reference count */
982 wait_queue_head_t remove_wq; /* can be used to wait for
983 refcount drop to zero */
984 struct zfcp_adapter *adapter; /* adapter used to access port */
985 struct list_head unit_list_head; /* head of logical unit list */
986 struct list_head unit_remove_lh; /* head of luns to be removed
988 u32 units; /* # of logical units in list */
989 atomic_t status; /* status of this remote port */
990 wwn_t wwnn; /* WWNN if known */
991 wwn_t wwpn; /* WWPN */
993 u32 handle; /* handle assigned by FSF */
994 struct zfcp_erp_action erp_action; /* pending error recovery */
995 atomic_t erp_counter;
998 /* the struct device sysfs_device must be at the beginning of this structure.
999 * pointer to struct device is used to free unit structure in release function
1000 * of the device. don't change!
1003 struct device sysfs_device; /* sysfs device */
1004 struct list_head list; /* list of logical units */
1005 atomic_t refcount; /* reference count */
1006 wait_queue_head_t remove_wq; /* can be used to wait for
1007 refcount drop to zero */
1008 struct zfcp_port *port; /* remote port of unit */
1009 atomic_t status; /* status of this logical unit */
1010 scsi_lun_t scsi_lun; /* own SCSI LUN */
1011 fcp_lun_t fcp_lun; /* own FCP_LUN */
1012 u32 handle; /* handle assigned by FSF */
1013 struct scsi_device *device; /* scsi device struct pointer */
1014 struct zfcp_erp_action erp_action; /* pending error recovery */
1015 atomic_t erp_counter;
1019 struct zfcp_fsf_req {
1020 struct list_head list; /* list of FSF requests */
1021 struct zfcp_adapter *adapter; /* adapter request belongs to */
1022 u8 sbal_number; /* nr of SBALs free for use */
1023 u8 sbal_first; /* first SBAL for this request */
1024 u8 sbal_last; /* last possible SBAL for
1026 u8 sbal_curr; /* current SBAL during creation
1028 u8 sbale_curr; /* current SBALE during creation
1030 wait_queue_head_t completion_wq; /* can be used by a routine
1031 to wait for completion */
1032 volatile u32 status; /* status of this request */
1033 u32 fsf_command; /* FSF Command copy */
1034 struct fsf_qtcb *qtcb; /* address of associated QTCB */
1035 u32 seq_no; /* Sequence number of request */
1036 unsigned long data; /* private data of request */
1037 struct zfcp_erp_action *erp_action; /* used if this request is
1038 issued on behalf of erp */
1039 mempool_t *pool; /* used if request was alloacted
1040 from emergency pool */
1041 unsigned long long issued; /* request sent time (STCK) */
1042 struct zfcp_unit *unit;
1045 typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
1049 struct scsi_host_template scsi_host_template;
1050 atomic_t status; /* Module status flags */
1051 struct list_head adapter_list_head; /* head of adapter list */
1052 struct list_head adapter_remove_lh; /* head of adapters to be
1054 rwlock_t status_read_lock; /* for status read thread */
1055 struct list_head status_read_receive_head;
1056 struct list_head status_read_send_head;
1057 struct semaphore status_read_sema;
1058 wait_queue_head_t status_read_thread_wqh;
1059 u32 adapters; /* # of adapters in list */
1060 rwlock_t config_lock; /* serialises changes
1061 to adapter/port/unit
1063 struct semaphore config_sema; /* serialises configuration
1065 atomic_t loglevel; /* current loglevel */
1066 char init_busid[BUS_ID_SIZE];
1068 fcp_lun_t init_fcp_lun;
1069 char *driver_version;
1073 * struct zfcp_sg_list - struct describing a scatter-gather list
1074 * @sg: pointer to array of (struct scatterlist)
1075 * @count: number of elements in scatter-gather list
1077 struct zfcp_sg_list {
1078 struct scatterlist *sg;
1082 /* number of elements for various memory pools */
1083 #define ZFCP_POOL_FSF_REQ_ERP_NR 1
1084 #define ZFCP_POOL_FSF_REQ_SCSI_NR 1
1085 #define ZFCP_POOL_FSF_REQ_ABORT_NR 1
1086 #define ZFCP_POOL_STATUS_READ_NR ZFCP_STATUS_READS_RECOM
1087 #define ZFCP_POOL_DATA_GID_PN_NR 1
1089 /* struct used by memory pools for fsf_requests */
1090 struct zfcp_fsf_req_pool_element {
1091 struct zfcp_fsf_req fsf_req;
1092 struct fsf_qtcb qtcb;
1095 /********************** ZFCP SPECIFIC DEFINES ********************************/
1097 #define ZFCP_FSFREQ_CLEANUP_TIMEOUT HZ/10
1099 #define ZFCP_KNOWN 0x00000001
1100 #define ZFCP_REQ_AUTO_CLEANUP 0x00000002
1101 #define ZFCP_WAIT_FOR_SBAL 0x00000004
1102 #define ZFCP_REQ_NO_QTCB 0x00000008
1104 #define ZFCP_SET 0x00000100
1105 #define ZFCP_CLEAR 0x00000200
1107 #define ZFCP_INTERRUPTIBLE 1
1108 #define ZFCP_UNINTERRUPTIBLE 0
1110 #ifndef atomic_test_mask
1111 #define atomic_test_mask(mask, target) \
1112 ((atomic_read(target) & mask) == mask)
1115 extern void _zfcp_hex_dump(char *, int);
1116 #define ZFCP_HEX_DUMP(level, addr, count) \
1117 if (ZFCP_LOG_CHECK(level)) { \
1118 _zfcp_hex_dump(addr, count); \
1121 #define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
1122 #define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
1123 #define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
1126 * functions needed for reference/usage counting
1130 zfcp_unit_get(struct zfcp_unit *unit)
1132 atomic_inc(&unit->refcount);
1136 zfcp_unit_put(struct zfcp_unit *unit)
1138 if (atomic_dec_return(&unit->refcount) == 0)
1139 wake_up(&unit->remove_wq);
1143 zfcp_unit_wait(struct zfcp_unit *unit)
1145 wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
1149 zfcp_port_get(struct zfcp_port *port)
1151 atomic_inc(&port->refcount);
1155 zfcp_port_put(struct zfcp_port *port)
1157 if (atomic_dec_return(&port->refcount) == 0)
1158 wake_up(&port->remove_wq);
1162 zfcp_port_wait(struct zfcp_port *port)
1164 wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
1168 zfcp_adapter_get(struct zfcp_adapter *adapter)
1170 atomic_inc(&adapter->refcount);
1174 zfcp_adapter_put(struct zfcp_adapter *adapter)
1176 if (atomic_dec_return(&adapter->refcount) == 0)
1177 wake_up(&adapter->remove_wq);
1181 zfcp_adapter_wait(struct zfcp_adapter *adapter)
1183 wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
1186 #endif /* ZFCP_DEF_H */