2 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
5 * (C) Copyright IBM Corp. 2002, 2006
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 /*************************** INCLUDES *****************************************/
28 #include <linux/init.h>
29 #include <linux/moduleparam.h>
30 #include <linux/miscdevice.h>
31 #include <linux/major.h>
32 #include <linux/blkdev.h>
33 #include <linux/delay.h>
34 #include <linux/timer.h>
35 #include <scsi/scsi.h>
36 #include <scsi/scsi_tcq.h>
37 #include <scsi/scsi_cmnd.h>
38 #include <scsi/scsi_device.h>
39 #include <scsi/scsi_host.h>
40 #include <scsi/scsi_transport.h>
41 #include <scsi/scsi_transport_fc.h>
42 #include "../../fc4/fc.h"
44 #include <asm/ccwdev.h>
46 #include <asm/debug.h>
47 #include <asm/ebcdic.h>
48 #include <linux/mempool.h>
49 #include <linux/syscalls.h>
50 #include <linux/ioctl.h>
53 /********************* GENERAL DEFINES *********************************/
55 /* zfcp version number, it consists of major, minor, and patch-level number */
56 #define ZFCP_VERSION "4.5.0"
59 * zfcp_sg_to_address - determine kernel address from struct scatterlist
60 * @list: struct scatterlist
61 * Return: kernel address
64 zfcp_sg_to_address(struct scatterlist
*list
)
66 return (void *) (page_address(list
->page
) + list
->offset
);
70 * zfcp_address_to_sg - set up struct scatterlist from kernel address
71 * @address: kernel address
72 * @list: struct scatterlist
75 zfcp_address_to_sg(void *address
, struct scatterlist
*list
)
77 list
->page
= virt_to_page(address
);
78 list
->offset
= ((unsigned long) address
) & (PAGE_SIZE
- 1);
81 /********************* SCSI SPECIFIC DEFINES *********************************/
83 /* 32 bit for SCSI ID and LUN as long as the SCSI stack uses this type */
84 typedef u32 scsi_id_t
;
85 typedef u32 scsi_lun_t
;
87 #define ZFCP_ERP_SCSI_LOW_MEM_TIMEOUT (100*HZ)
88 #define ZFCP_SCSI_ER_TIMEOUT (100*HZ)
90 /********************* CIO/QDIO SPECIFIC DEFINES *****************************/
92 /* Adapter Identification Parameters */
93 #define ZFCP_CONTROL_UNIT_TYPE 0x1731
94 #define ZFCP_CONTROL_UNIT_MODEL 0x03
95 #define ZFCP_DEVICE_TYPE 0x1732
96 #define ZFCP_DEVICE_MODEL 0x03
97 #define ZFCP_DEVICE_MODEL_PRIV 0x04
99 /* allow as many chained SBALs as are supported by hardware */
100 #define ZFCP_MAX_SBALS_PER_REQ FSF_MAX_SBALS_PER_REQ
101 #define ZFCP_MAX_SBALS_PER_CT_REQ FSF_MAX_SBALS_PER_REQ
102 #define ZFCP_MAX_SBALS_PER_ELS_REQ FSF_MAX_SBALS_PER_ELS_REQ
104 /* DMQ bug workaround: don't use last SBALE */
105 #define ZFCP_MAX_SBALES_PER_SBAL (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
107 /* index of last SBALE (with respect to DMQ bug workaround) */
108 #define ZFCP_LAST_SBALE_PER_SBAL (ZFCP_MAX_SBALES_PER_SBAL - 1)
110 /* max. number of (data buffer) SBALEs in largest SBAL chain */
111 #define ZFCP_MAX_SBALES_PER_REQ \
112 (ZFCP_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
113 /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
115 /* FIXME(tune): free space should be one max. SBAL chain plus what? */
116 #define ZFCP_QDIO_PCI_INTERVAL (QDIO_MAX_BUFFERS_PER_Q \
117 - (ZFCP_MAX_SBALS_PER_REQ + 4))
119 #define ZFCP_SBAL_TIMEOUT (5*HZ)
121 #define ZFCP_TYPE2_RECOVERY_TIME (8*HZ)
123 /* queue polling (values in microseconds) */
124 #define ZFCP_MAX_INPUT_THRESHOLD 5000 /* FIXME: tune */
125 #define ZFCP_MAX_OUTPUT_THRESHOLD 1000 /* FIXME: tune */
126 #define ZFCP_MIN_INPUT_THRESHOLD 1 /* ignored by QDIO layer */
127 #define ZFCP_MIN_OUTPUT_THRESHOLD 1 /* ignored by QDIO layer */
129 #define QDIO_SCSI_QFMT 1 /* 1 for FSF */
131 /********************* FSF SPECIFIC DEFINES *********************************/
133 #define ZFCP_ULP_INFO_VERSION 26
134 #define ZFCP_QTCB_VERSION FSF_QTCB_CURRENT_VERSION
135 /* ATTENTION: value must not be used by hardware */
136 #define FSF_QTCB_UNSOLICITED_STATUS 0x6305
137 #define ZFCP_STATUS_READ_FAILED_THRESHOLD 3
138 #define ZFCP_STATUS_READS_RECOM FSF_STATUS_READS_RECOM
140 /* Do 1st retry in 1 second, then double the timeout for each following retry */
141 #define ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP 100
142 #define ZFCP_EXCHANGE_CONFIG_DATA_RETRIES 7
144 /* timeout value for "default timer" for fsf requests */
145 #define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ);
147 /*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
149 typedef unsigned long long wwn_t
;
150 typedef unsigned long long fcp_lun_t
;
151 /* data length field may be at variable position in FCP-2 FCP_CMND IU */
152 typedef unsigned int fcp_dl_t
;
154 #define ZFCP_FC_SERVICE_CLASS_DEFAULT FSF_CLASS_3
156 /* timeout for name-server lookup (in seconds) */
157 #define ZFCP_NS_GID_PN_TIMEOUT 10
159 /* largest SCSI command we can process */
160 /* FCP-2 (FCP_CMND IU) allows up to (255-3+16) */
161 #define ZFCP_MAX_SCSI_CMND_LENGTH 255
162 /* maximum number of commands in LUN queue (tagged queueing) */
163 #define ZFCP_CMND_PER_LUN 32
165 /* task attribute values in FCP-2 FCP_CMND IU */
172 /* task management flags in FCP-2 FCP_CMND IU */
173 #define FCP_CLEAR_ACA 0x40
174 #define FCP_TARGET_RESET 0x20
175 #define FCP_LOGICAL_UNIT_RESET 0x10
176 #define FCP_CLEAR_TASK_SET 0x04
177 #define FCP_ABORT_TASK_SET 0x02
179 #define FCP_CDB_LENGTH 16
181 #define ZFCP_DID_MASK 0x00FFFFFF
183 /* FCP(-2) FCP_CMND IU */
185 fcp_lun_t fcp_lun
; /* FCP logical unit number */
186 u8 crn
; /* command reference number */
187 u8 reserved0
:5; /* reserved */
188 u8 task_attribute
:3; /* task attribute */
189 u8 task_management_flags
; /* task management flags */
190 u8 add_fcp_cdb_length
:6; /* additional FCP_CDB length */
191 u8 rddata
:1; /* read data */
192 u8 wddata
:1; /* write data */
193 u8 fcp_cdb
[FCP_CDB_LENGTH
];
194 } __attribute__((packed
));
196 /* FCP(-2) FCP_RSP IU */
203 u8 fcp_resid_under
:1;
205 u8 fcp_sns_len_valid
:1;
206 u8 fcp_rsp_len_valid
:1;
214 } __attribute__((packed
));
217 #define RSP_CODE_GOOD 0
218 #define RSP_CODE_LENGTH_MISMATCH 1
219 #define RSP_CODE_FIELD_INVALID 2
220 #define RSP_CODE_RO_MISMATCH 3
221 #define RSP_CODE_TASKMAN_UNSUPP 4
222 #define RSP_CODE_TASKMAN_FAILED 5
225 #define LS_FAN 0x60000000
226 #define LS_RSCN 0x61040000
228 struct fcp_rscn_head
{
230 u8 page_length
; /* always 0x04 */
232 } __attribute__((packed
));
234 struct fcp_rscn_element
{
239 } __attribute__((packed
));
241 #define ZFCP_PORT_ADDRESS 0x0
242 #define ZFCP_AREA_ADDRESS 0x1
243 #define ZFCP_DOMAIN_ADDRESS 0x2
244 #define ZFCP_FABRIC_ADDRESS 0x3
246 #define ZFCP_PORTS_RANGE_PORT 0xFFFFFF
247 #define ZFCP_PORTS_RANGE_AREA 0xFFFF00
248 #define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
249 #define ZFCP_PORTS_RANGE_FABRIC 0x000000
251 #define ZFCP_NO_PORTS_PER_AREA 0x100
252 #define ZFCP_NO_PORTS_PER_DOMAIN 0x10000
253 #define ZFCP_NO_PORTS_PER_FABRIC 0x1000000
260 } __attribute__((packed
));
267 } __attribute__((packed
));
272 #define ZFCP_DBF_TAG_SIZE 4
274 struct zfcp_dbf_dump
{
275 u8 tag
[ZFCP_DBF_TAG_SIZE
];
276 u32 total_size
; /* size of total dump data */
277 u32 offset
; /* how much data has being already dumped */
278 u32 size
; /* how much data comes with this record */
279 u8 data
[]; /* dump data */
280 } __attribute__ ((packed
));
282 /* FIXME: to be inflated when reworking the erp dbf */
283 struct zfcp_erp_dbf_record
{
285 } __attribute__ ((packed
));
287 struct zfcp_hba_dbf_record_response
{
294 u8 fsf_prot_status_qual
[FSF_PROT_STATUS_QUAL_SIZE
];
295 u8 fsf_status_qual
[FSF_STATUS_QUALIFIER_SIZE
];
323 } __attribute__ ((packed
));
325 struct zfcp_hba_dbf_record_status
{
329 struct fsf_queue_designator
332 #define ZFCP_DBF_UNSOL_PAYLOAD 80
333 #define ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL 32
334 #define ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD 56
335 #define ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT 2 * sizeof(u32)
336 u8 payload
[ZFCP_DBF_UNSOL_PAYLOAD
];
337 } __attribute__ ((packed
));
339 struct zfcp_hba_dbf_record_qdio
{
345 } __attribute__ ((packed
));
347 struct zfcp_hba_dbf_record
{
348 u8 tag
[ZFCP_DBF_TAG_SIZE
];
349 u8 tag2
[ZFCP_DBF_TAG_SIZE
];
351 struct zfcp_hba_dbf_record_response response
;
352 struct zfcp_hba_dbf_record_status status
;
353 struct zfcp_hba_dbf_record_qdio qdio
;
355 } __attribute__ ((packed
));
357 struct zfcp_san_dbf_record_ct
{
376 #define ZFCP_DBF_CT_PAYLOAD 24
377 u8 payload
[ZFCP_DBF_CT_PAYLOAD
];
378 } __attribute__ ((packed
));
380 struct zfcp_san_dbf_record_els
{
383 #define ZFCP_DBF_ELS_PAYLOAD 32
384 #define ZFCP_DBF_ELS_MAX_PAYLOAD 1024
385 u8 payload
[ZFCP_DBF_ELS_PAYLOAD
];
386 } __attribute__ ((packed
));
388 struct zfcp_san_dbf_record
{
389 u8 tag
[ZFCP_DBF_TAG_SIZE
];
395 struct zfcp_san_dbf_record_ct ct
;
396 struct zfcp_san_dbf_record_els els
;
398 } __attribute__ ((packed
));
400 struct zfcp_scsi_dbf_record
{
401 u8 tag
[ZFCP_DBF_TAG_SIZE
];
402 u8 tag2
[ZFCP_DBF_TAG_SIZE
];
408 #define ZFCP_DBF_SCSI_OPCODE 16
409 u8 scsi_opcode
[ZFCP_DBF_SCSI_OPCODE
];
422 #define ZFCP_DBF_SCSI_FCP_SNS_INFO 16
423 #define ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO 256
425 u8 sns_info
[ZFCP_DBF_SCSI_FCP_SNS_INFO
];
428 } __attribute__ ((packed
));
433 #define R_A_TOV 10 /* seconds */
434 #define ZFCP_ELS_TIMEOUT (2 * R_A_TOV)
436 #define ZFCP_LS_RLS 0x0f
437 #define ZFCP_LS_ADISC 0x52
438 #define ZFCP_LS_RPS 0x56
439 #define ZFCP_LS_RSCN 0x61
440 #define ZFCP_LS_RNID 0x78
442 struct zfcp_ls_rjt_par
{
447 } __attribute__ ((packed
));
449 struct zfcp_ls_adisc
{
456 } __attribute__ ((packed
));
458 struct zfcp_ls_adisc_acc
{
465 } __attribute__ ((packed
));
467 struct zfcp_rc_entry
{
469 const char *description
;
475 #define ZFCP_CT_REVISION 0x01
476 #define ZFCP_CT_DIRECTORY_SERVICE 0xFC
477 #define ZFCP_CT_NAME_SERVER 0x02
478 #define ZFCP_CT_SYNCHRONOUS 0x00
479 #define ZFCP_CT_GID_PN 0x0121
480 #define ZFCP_CT_MAX_SIZE 0x1020
481 #define ZFCP_CT_ACCEPT 0x8002
482 #define ZFCP_CT_REJECT 0x8001
487 #define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
489 /******************** LOGGING MACROS AND DEFINES *****************************/
492 * Logging may be applied on certain kinds of driver operations
493 * independently. Additionally, different log-levels are supported for
494 * each of these areas.
497 #define ZFCP_NAME "zfcp"
499 /* read-only LUN sharing switch initial value */
500 #define ZFCP_RO_LUN_SHARING_DEFAULTS 0
502 /* independent log areas */
503 #define ZFCP_LOG_AREA_OTHER 0
504 #define ZFCP_LOG_AREA_SCSI 1
505 #define ZFCP_LOG_AREA_FSF 2
506 #define ZFCP_LOG_AREA_CONFIG 3
507 #define ZFCP_LOG_AREA_CIO 4
508 #define ZFCP_LOG_AREA_QDIO 5
509 #define ZFCP_LOG_AREA_ERP 6
510 #define ZFCP_LOG_AREA_FC 7
512 /* log level values*/
513 #define ZFCP_LOG_LEVEL_NORMAL 0
514 #define ZFCP_LOG_LEVEL_INFO 1
515 #define ZFCP_LOG_LEVEL_DEBUG 2
516 #define ZFCP_LOG_LEVEL_TRACE 3
519 * this allows removal of logging code by the preprocessor
520 * (the most detailed log level still to be compiled in is specified,
521 * higher log levels are removed)
523 #define ZFCP_LOG_LEVEL_LIMIT ZFCP_LOG_LEVEL_TRACE
525 /* get "loglevel" nibble assignment */
526 #define ZFCP_GET_LOG_VALUE(zfcp_lognibble) \
527 ((atomic_read(&zfcp_data.loglevel) >> (zfcp_lognibble<<2)) & 0xF)
529 /* set "loglevel" nibble */
530 #define ZFCP_SET_LOG_NIBBLE(value, zfcp_lognibble) \
531 (value << (zfcp_lognibble << 2))
533 /* all log-level defaults are combined to generate initial log-level */
534 #define ZFCP_LOG_LEVEL_DEFAULTS \
535 (ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_OTHER) | \
536 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_SCSI) | \
537 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FSF) | \
538 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CONFIG) | \
539 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CIO) | \
540 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_QDIO) | \
541 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_ERP) | \
542 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FC))
544 /* check whether we have the right level for logging */
545 #define ZFCP_LOG_CHECK(level) \
546 ((ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA)) >= level)
548 /* logging routine for zfcp */
549 #define _ZFCP_LOG(fmt, args...) \
550 printk(KERN_ERR ZFCP_NAME": %s(%d): " fmt, __FUNCTION__, \
553 #define ZFCP_LOG(level, fmt, args...) \
555 if (ZFCP_LOG_CHECK(level)) \
556 _ZFCP_LOG(fmt, ##args); \
559 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_NORMAL
560 # define ZFCP_LOG_NORMAL(fmt, args...)
562 # define ZFCP_LOG_NORMAL(fmt, args...) \
564 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_NORMAL)) \
565 printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
569 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_INFO
570 # define ZFCP_LOG_INFO(fmt, args...)
572 # define ZFCP_LOG_INFO(fmt, args...) \
574 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_INFO)) \
575 printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
579 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_DEBUG
580 # define ZFCP_LOG_DEBUG(fmt, args...)
582 # define ZFCP_LOG_DEBUG(fmt, args...) \
583 ZFCP_LOG(ZFCP_LOG_LEVEL_DEBUG, fmt , ##args)
586 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_TRACE
587 # define ZFCP_LOG_TRACE(fmt, args...)
589 # define ZFCP_LOG_TRACE(fmt, args...) \
590 ZFCP_LOG(ZFCP_LOG_LEVEL_TRACE, fmt , ##args)
593 /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
596 * Note, the leftmost status byte is common among adapter, port
599 #define ZFCP_COMMON_FLAGS 0xfff00000
600 #define ZFCP_SPECIFIC_FLAGS 0x000fffff
602 /* common status bits */
603 #define ZFCP_STATUS_COMMON_REMOVE 0x80000000
604 #define ZFCP_STATUS_COMMON_RUNNING 0x40000000
605 #define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
606 #define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
607 #define ZFCP_STATUS_COMMON_OPENING 0x08000000
608 #define ZFCP_STATUS_COMMON_OPEN 0x04000000
609 #define ZFCP_STATUS_COMMON_CLOSING 0x02000000
610 #define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
611 #define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
612 #define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
615 #define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
616 #define ZFCP_STATUS_ADAPTER_REGISTERED 0x00000004
617 #define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
618 #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
619 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
620 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
621 #define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
622 #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
623 #define ZFCP_STATUS_ADAPTER_XPORT_OK 0x00000800
625 #define ZFCP_STATUS_ADAPTER_SCSI_UP \
626 (ZFCP_STATUS_COMMON_UNBLOCKED | \
627 ZFCP_STATUS_ADAPTER_REGISTERED)
630 /* FC-PH/FC-GS well-known address identifiers for generic services */
631 #define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA
632 #define ZFCP_DID_TIME_SERVICE 0xFFFFFB
633 #define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC
634 #define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8
635 #define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7
637 /* remote port status */
638 #define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
639 #define ZFCP_STATUS_PORT_DID_DID 0x00000002
640 #define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
641 #define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
642 #define ZFCP_STATUS_PORT_NO_SCSI_ID 0x00000010
643 #define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
644 #define ZFCP_STATUS_PORT_ACCESS_DENIED 0x00000040
646 /* for ports with well known addresses */
647 #define ZFCP_STATUS_PORT_WKA \
648 (ZFCP_STATUS_PORT_NO_WWPN | \
649 ZFCP_STATUS_PORT_NO_SCSI_ID)
651 /* logical unit status */
652 #define ZFCP_STATUS_UNIT_NOTSUPPUNITRESET 0x00000001
653 #define ZFCP_STATUS_UNIT_TEMPORARY 0x00000002
654 #define ZFCP_STATUS_UNIT_SHARED 0x00000004
655 #define ZFCP_STATUS_UNIT_READONLY 0x00000008
656 #define ZFCP_STATUS_UNIT_REGISTERED 0x00000010
658 /* FSF request status (this does not have a common part) */
659 #define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000
660 #define ZFCP_STATUS_FSFREQ_POOL 0x00000001
661 #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
662 #define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
663 #define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
664 #define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
665 #define ZFCP_STATUS_FSFREQ_ABORTING 0x00000020
666 #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
667 #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
668 #define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
669 #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
670 #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
671 #define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
672 #define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
674 /*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
676 #define ZFCP_MAX_ERPS 3
678 #define ZFCP_ERP_FSFREQ_TIMEOUT (30 * HZ)
679 #define ZFCP_ERP_MEMWAIT_TIMEOUT HZ
681 #define ZFCP_STATUS_ERP_TIMEDOUT 0x10000000
682 #define ZFCP_STATUS_ERP_CLOSE_ONLY 0x01000000
683 #define ZFCP_STATUS_ERP_DISMISSING 0x00100000
684 #define ZFCP_STATUS_ERP_DISMISSED 0x00200000
685 #define ZFCP_STATUS_ERP_LOWMEM 0x00400000
687 #define ZFCP_ERP_STEP_UNINITIALIZED 0x00000000
688 #define ZFCP_ERP_STEP_FSF_XCONFIG 0x00000001
689 #define ZFCP_ERP_STEP_PHYS_PORT_CLOSING 0x00000010
690 #define ZFCP_ERP_STEP_PORT_CLOSING 0x00000100
691 #define ZFCP_ERP_STEP_NAMESERVER_OPEN 0x00000200
692 #define ZFCP_ERP_STEP_NAMESERVER_LOOKUP 0x00000400
693 #define ZFCP_ERP_STEP_PORT_OPENING 0x00000800
694 #define ZFCP_ERP_STEP_UNIT_CLOSING 0x00001000
695 #define ZFCP_ERP_STEP_UNIT_OPENING 0x00002000
697 /* Ordered by escalation level (necessary for proper erp-code operation) */
698 #define ZFCP_ERP_ACTION_REOPEN_ADAPTER 0x4
699 #define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED 0x3
700 #define ZFCP_ERP_ACTION_REOPEN_PORT 0x2
701 #define ZFCP_ERP_ACTION_REOPEN_UNIT 0x1
703 #define ZFCP_ERP_ACTION_RUNNING 0x1
704 #define ZFCP_ERP_ACTION_READY 0x2
706 #define ZFCP_ERP_SUCCEEDED 0x0
707 #define ZFCP_ERP_FAILED 0x1
708 #define ZFCP_ERP_CONTINUES 0x2
709 #define ZFCP_ERP_EXIT 0x3
710 #define ZFCP_ERP_DISMISSED 0x4
711 #define ZFCP_ERP_NOMEM 0x5
714 /******************** CFDC SPECIFIC STUFF *****************************/
716 /* Firewall data channel sense data record */
717 struct zfcp_cfdc_sense_data
{
718 u32 signature
; /* Request signature */
719 u32 devno
; /* FCP adapter device number */
720 u32 command
; /* Command code */
721 u32 fsf_status
; /* FSF request status and status qualifier */
722 u8 fsf_status_qual
[FSF_STATUS_QUALIFIER_SIZE
];
723 u8 payloads
[256]; /* Access conflicts list */
724 u8 control_file
[0]; /* Access control table */
727 #define ZFCP_CFDC_SIGNATURE 0xCFDCACDF
729 #define ZFCP_CFDC_CMND_DOWNLOAD_NORMAL 0x00010001
730 #define ZFCP_CFDC_CMND_DOWNLOAD_FORCE 0x00010101
731 #define ZFCP_CFDC_CMND_FULL_ACCESS 0x00000201
732 #define ZFCP_CFDC_CMND_RESTRICTED_ACCESS 0x00000401
733 #define ZFCP_CFDC_CMND_UPLOAD 0x00010002
735 #define ZFCP_CFDC_DOWNLOAD 0x00000001
736 #define ZFCP_CFDC_UPLOAD 0x00000002
737 #define ZFCP_CFDC_WITH_CONTROL_FILE 0x00010000
739 #define ZFCP_CFDC_DEV_NAME "zfcp_cfdc"
740 #define ZFCP_CFDC_DEV_MAJOR MISC_MAJOR
741 #define ZFCP_CFDC_DEV_MINOR MISC_DYNAMIC_MINOR
743 #define ZFCP_CFDC_MAX_CONTROL_FILE_SIZE 127 * 1024
745 /************************* STRUCTURE DEFINITIONS *****************************/
749 /* holds various memory pools of an adapter */
750 struct zfcp_adapter_mempool
{
751 mempool_t
*fsf_req_erp
;
752 mempool_t
*fsf_req_scsi
;
753 mempool_t
*fsf_req_abort
;
754 mempool_t
*fsf_req_status_read
;
755 mempool_t
*data_status_read
;
756 mempool_t
*data_gid_pn
;
765 u8 gs_type
; // 0xFC Directory Service
766 u8 gs_subtype
; // 0x02 Name Server
767 u8 options
; // 0x00 single bidirectional exchange
769 u16 cmd_rsp_code
; // 0x0121 GID_PN, or 0x0100 GA_NXT
770 u16 max_res_size
; // <= (4096 - 16) / 4
775 } __attribute__ ((packed
));
777 /* nameserver request CT_IU -- for requests where
778 * a port name is required */
779 struct ct_iu_gid_pn_req
{
780 struct ct_hdr header
;
782 } __attribute__ ((packed
));
784 /* FS_ACC IU and data unit for GID_PN nameserver request */
785 struct ct_iu_gid_pn_resp
{
786 struct ct_hdr header
;
788 } __attribute__ ((packed
));
790 typedef void (*zfcp_send_ct_handler_t
)(unsigned long);
793 * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
794 * @port: port where the request is sent to
795 * @req: scatter-gather list for request
796 * @resp: scatter-gather list for response
797 * @req_count: number of elements in request scatter-gather list
798 * @resp_count: number of elements in response scatter-gather list
799 * @handler: handler function (called for response to the request)
800 * @handler_data: data passed to handler function
801 * @pool: pointer to memory pool for ct request structure
802 * @timeout: FSF timeout for this request
803 * @timer: timer (e.g. for request initiated by erp)
804 * @completion: completion for synchronization purposes
805 * @status: used to pass error status to calling function
807 struct zfcp_send_ct
{
808 struct zfcp_port
*port
;
809 struct scatterlist
*req
;
810 struct scatterlist
*resp
;
811 unsigned int req_count
;
812 unsigned int resp_count
;
813 zfcp_send_ct_handler_t handler
;
814 unsigned long handler_data
;
817 struct timer_list
*timer
;
818 struct completion
*completion
;
822 /* used for name server requests in error recovery */
823 struct zfcp_gid_pn_data
{
824 struct zfcp_send_ct ct
;
825 struct scatterlist req
;
826 struct scatterlist resp
;
827 struct ct_iu_gid_pn_req ct_iu_req
;
828 struct ct_iu_gid_pn_resp ct_iu_resp
;
829 struct zfcp_port
*port
;
832 typedef void (*zfcp_send_els_handler_t
)(unsigned long);
835 * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
836 * @adapter: adapter where request is sent from
837 * @port: port where ELS is destinated (port reference count has to be increased)
838 * @d_id: destiniation id of port where request is sent to
839 * @req: scatter-gather list for request
840 * @resp: scatter-gather list for response
841 * @req_count: number of elements in request scatter-gather list
842 * @resp_count: number of elements in response scatter-gather list
843 * @handler: handler function (called for response to the request)
844 * @handler_data: data passed to handler function
845 * @timer: timer (e.g. for request initiated by erp)
846 * @completion: completion for synchronization purposes
847 * @ls_code: hex code of ELS command
848 * @status: used to pass error status to calling function
850 struct zfcp_send_els
{
851 struct zfcp_adapter
*adapter
;
852 struct zfcp_port
*port
;
854 struct scatterlist
*req
;
855 struct scatterlist
*resp
;
856 unsigned int req_count
;
857 unsigned int resp_count
;
858 zfcp_send_els_handler_t handler
;
859 unsigned long handler_data
;
860 struct timer_list
*timer
;
861 struct completion
*completion
;
866 struct zfcp_qdio_queue
{
867 struct qdio_buffer
*buffer
[QDIO_MAX_BUFFERS_PER_Q
]; /* SBALs */
868 u8 free_index
; /* index of next free bfr
869 in queue (free_count>0) */
870 atomic_t free_count
; /* number of free buffers
872 rwlock_t queue_lock
; /* lock for operations on queue */
873 int distance_from_int
; /* SBALs used since PCI indication
877 struct zfcp_erp_action
{
878 struct list_head list
;
879 int action
; /* requested action code */
880 struct zfcp_adapter
*adapter
; /* device which should be recovered */
881 struct zfcp_port
*port
;
882 struct zfcp_unit
*unit
;
883 volatile u32 status
; /* recovery status */
884 u32 step
; /* active step of this erp action */
885 struct zfcp_fsf_req
*fsf_req
; /* fsf request currently pending
887 struct timer_list timer
;
891 struct zfcp_adapter
{
892 struct list_head list
; /* list of adapters */
893 atomic_t refcount
; /* reference count */
894 wait_queue_head_t remove_wq
; /* can be used to wait for
895 refcount drop to zero */
896 wwn_t peer_wwnn
; /* P2P peer WWNN */
897 wwn_t peer_wwpn
; /* P2P peer WWPN */
898 u32 peer_d_id
; /* P2P peer D_ID */
899 struct ccw_device
*ccw_device
; /* S/390 ccw device */
901 u32 hydra_version
; /* Hydra version */
903 u32 adapter_features
; /* FCP channel features */
904 u32 connection_features
; /* host connection features */
905 u32 hardware_version
; /* of FCP channel */
906 struct Scsi_Host
*scsi_host
; /* Pointer to mid-layer */
907 unsigned short scsi_host_no
; /* Assigned host number */
908 unsigned char name
[9];
909 struct list_head port_list_head
; /* remote port list */
910 struct list_head port_remove_lh
; /* head of ports to be
912 u32 ports
; /* number of remote ports */
913 struct timer_list scsi_er_timer
; /* SCSI err recovery watch */
914 struct list_head fsf_req_list_head
; /* head of FSF req list */
915 spinlock_t fsf_req_list_lock
; /* lock for ops on list of
917 atomic_t fsf_reqs_active
; /* # active FSF reqs */
918 struct zfcp_qdio_queue request_queue
; /* request queue */
919 u32 fsf_req_seq_no
; /* FSF cmnd seq number */
920 wait_queue_head_t request_wq
; /* can be used to wait for
921 more avaliable SBALs */
922 struct zfcp_qdio_queue response_queue
; /* response queue */
923 rwlock_t abort_lock
; /* Protects against SCSI
926 u16 status_read_failed
; /* # failed status reads */
927 atomic_t status
; /* status of this adapter */
928 struct list_head erp_ready_head
; /* error recovery for this
930 struct list_head erp_running_head
;
932 struct semaphore erp_ready_sem
;
933 wait_queue_head_t erp_thread_wqh
;
934 wait_queue_head_t erp_done_wqh
;
935 struct zfcp_erp_action erp_action
; /* pending error recovery */
936 atomic_t erp_counter
;
937 u32 erp_total_count
; /* total nr of enqueued erp
939 u32 erp_low_mem_count
; /* nr of erp actions waiting
941 struct zfcp_port
*nameserver_port
; /* adapter's nameserver */
942 debug_info_t
*erp_dbf
;
943 debug_info_t
*hba_dbf
;
944 debug_info_t
*san_dbf
; /* debug feature areas */
945 debug_info_t
*scsi_dbf
;
946 spinlock_t erp_dbf_lock
;
947 spinlock_t hba_dbf_lock
;
948 spinlock_t san_dbf_lock
;
949 spinlock_t scsi_dbf_lock
;
950 struct zfcp_erp_dbf_record erp_dbf_buf
;
951 struct zfcp_hba_dbf_record hba_dbf_buf
;
952 struct zfcp_san_dbf_record san_dbf_buf
;
953 struct zfcp_scsi_dbf_record scsi_dbf_buf
;
954 struct zfcp_adapter_mempool pool
; /* Adapter memory pools */
955 struct qdio_initialize qdio_init_data
; /* for qdio_establish */
956 struct device generic_services
; /* directory for WKA ports */
957 struct fc_host_statistics
*fc_stats
;
958 struct fsf_qtcb_bottom_port
*stats_reset_data
;
959 unsigned long stats_reset
;
963 * the struct device sysfs_device must be at the beginning of this structure.
964 * pointer to struct device is used to free port structure in release function
965 * of the device. don't change!
968 struct device sysfs_device
; /* sysfs device */
969 struct fc_rport
*rport
; /* rport of fc transport class */
970 struct list_head list
; /* list of remote ports */
971 atomic_t refcount
; /* reference count */
972 wait_queue_head_t remove_wq
; /* can be used to wait for
973 refcount drop to zero */
974 struct zfcp_adapter
*adapter
; /* adapter used to access port */
975 struct list_head unit_list_head
; /* head of logical unit list */
976 struct list_head unit_remove_lh
; /* head of luns to be removed
978 u32 units
; /* # of logical units in list */
979 atomic_t status
; /* status of this remote port */
980 wwn_t wwnn
; /* WWNN if known */
981 wwn_t wwpn
; /* WWPN */
983 u32 handle
; /* handle assigned by FSF */
984 struct zfcp_erp_action erp_action
; /* pending error recovery */
985 atomic_t erp_counter
;
988 /* the struct device sysfs_device must be at the beginning of this structure.
989 * pointer to struct device is used to free unit structure in release function
990 * of the device. don't change!
993 struct device sysfs_device
; /* sysfs device */
994 struct list_head list
; /* list of logical units */
995 atomic_t refcount
; /* reference count */
996 wait_queue_head_t remove_wq
; /* can be used to wait for
997 refcount drop to zero */
998 struct zfcp_port
*port
; /* remote port of unit */
999 atomic_t status
; /* status of this logical unit */
1000 scsi_lun_t scsi_lun
; /* own SCSI LUN */
1001 fcp_lun_t fcp_lun
; /* own FCP_LUN */
1002 u32 handle
; /* handle assigned by FSF */
1003 struct scsi_device
*device
; /* scsi device struct pointer */
1004 struct zfcp_erp_action erp_action
; /* pending error recovery */
1005 atomic_t erp_counter
;
1009 struct zfcp_fsf_req
{
1010 struct list_head list
; /* list of FSF requests */
1011 struct zfcp_adapter
*adapter
; /* adapter request belongs to */
1012 u8 sbal_number
; /* nr of SBALs free for use */
1013 u8 sbal_first
; /* first SBAL for this request */
1014 u8 sbal_last
; /* last possible SBAL for
1016 u8 sbal_curr
; /* current SBAL during creation
1018 u8 sbale_curr
; /* current SBALE during creation
1020 wait_queue_head_t completion_wq
; /* can be used by a routine
1021 to wait for completion */
1022 volatile u32 status
; /* status of this request */
1023 u32 fsf_command
; /* FSF Command copy */
1024 struct fsf_qtcb
*qtcb
; /* address of associated QTCB */
1025 u32 seq_no
; /* Sequence number of request */
1026 unsigned long data
; /* private data of request */
1027 struct zfcp_erp_action
*erp_action
; /* used if this request is
1028 issued on behalf of erp */
1029 mempool_t
*pool
; /* used if request was alloacted
1030 from emergency pool */
1031 unsigned long long issued
; /* request sent time (STCK) */
1032 struct zfcp_unit
*unit
;
1035 typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req
*);
1039 struct scsi_host_template scsi_host_template
;
1040 atomic_t status
; /* Module status flags */
1041 struct list_head adapter_list_head
; /* head of adapter list */
1042 struct list_head adapter_remove_lh
; /* head of adapters to be
1044 rwlock_t status_read_lock
; /* for status read thread */
1045 struct list_head status_read_receive_head
;
1046 struct list_head status_read_send_head
;
1047 struct semaphore status_read_sema
;
1048 wait_queue_head_t status_read_thread_wqh
;
1049 u32 adapters
; /* # of adapters in list */
1050 rwlock_t config_lock
; /* serialises changes
1051 to adapter/port/unit
1053 struct semaphore config_sema
; /* serialises configuration
1055 atomic_t loglevel
; /* current loglevel */
1056 char init_busid
[BUS_ID_SIZE
];
1058 fcp_lun_t init_fcp_lun
;
1059 char *driver_version
;
1063 * struct zfcp_sg_list - struct describing a scatter-gather list
1064 * @sg: pointer to array of (struct scatterlist)
1065 * @count: number of elements in scatter-gather list
1067 struct zfcp_sg_list
{
1068 struct scatterlist
*sg
;
1072 /* number of elements for various memory pools */
1073 #define ZFCP_POOL_FSF_REQ_ERP_NR 1
1074 #define ZFCP_POOL_FSF_REQ_SCSI_NR 1
1075 #define ZFCP_POOL_FSF_REQ_ABORT_NR 1
1076 #define ZFCP_POOL_STATUS_READ_NR ZFCP_STATUS_READS_RECOM
1077 #define ZFCP_POOL_DATA_GID_PN_NR 1
1079 /* struct used by memory pools for fsf_requests */
1080 struct zfcp_fsf_req_pool_element
{
1081 struct zfcp_fsf_req fsf_req
;
1082 struct fsf_qtcb qtcb
;
1085 /********************** ZFCP SPECIFIC DEFINES ********************************/
1087 #define ZFCP_FSFREQ_CLEANUP_TIMEOUT HZ/10
1089 #define ZFCP_KNOWN 0x00000001
1090 #define ZFCP_REQ_AUTO_CLEANUP 0x00000002
1091 #define ZFCP_WAIT_FOR_SBAL 0x00000004
1092 #define ZFCP_REQ_NO_QTCB 0x00000008
1094 #define ZFCP_SET 0x00000100
1095 #define ZFCP_CLEAR 0x00000200
1097 #define ZFCP_INTERRUPTIBLE 1
1098 #define ZFCP_UNINTERRUPTIBLE 0
1100 #ifndef atomic_test_mask
1101 #define atomic_test_mask(mask, target) \
1102 ((atomic_read(target) & mask) == mask)
1105 extern void _zfcp_hex_dump(char *, int);
1106 #define ZFCP_HEX_DUMP(level, addr, count) \
1107 if (ZFCP_LOG_CHECK(level)) { \
1108 _zfcp_hex_dump(addr, count); \
1111 #define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
1112 #define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
1113 #define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
1116 * functions needed for reference/usage counting
1120 zfcp_unit_get(struct zfcp_unit
*unit
)
1122 atomic_inc(&unit
->refcount
);
1126 zfcp_unit_put(struct zfcp_unit
*unit
)
1128 if (atomic_dec_return(&unit
->refcount
) == 0)
1129 wake_up(&unit
->remove_wq
);
1133 zfcp_unit_wait(struct zfcp_unit
*unit
)
1135 wait_event(unit
->remove_wq
, atomic_read(&unit
->refcount
) == 0);
1139 zfcp_port_get(struct zfcp_port
*port
)
1141 atomic_inc(&port
->refcount
);
1145 zfcp_port_put(struct zfcp_port
*port
)
1147 if (atomic_dec_return(&port
->refcount
) == 0)
1148 wake_up(&port
->remove_wq
);
1152 zfcp_port_wait(struct zfcp_port
*port
)
1154 wait_event(port
->remove_wq
, atomic_read(&port
->refcount
) == 0);
1158 zfcp_adapter_get(struct zfcp_adapter
*adapter
)
1160 atomic_inc(&adapter
->refcount
);
1164 zfcp_adapter_put(struct zfcp_adapter
*adapter
)
1166 if (atomic_dec_return(&adapter
->refcount
) == 0)
1167 wake_up(&adapter
->remove_wq
);
1171 zfcp_adapter_wait(struct zfcp_adapter
*adapter
)
1173 wait_event(adapter
->remove_wq
, atomic_read(&adapter
->refcount
) == 0);
1176 #endif /* ZFCP_DEF_H */