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.
25 /*************************** INCLUDES *****************************************/
27 #include <linux/init.h>
28 #include <linux/moduleparam.h>
29 #include <linux/miscdevice.h>
30 #include <linux/major.h>
31 #include <linux/blkdev.h>
32 #include <linux/delay.h>
33 #include <linux/timer.h>
34 #include <linux/slab.h>
35 #include <linux/mempool.h>
36 #include <linux/syscalls.h>
37 #include <linux/ioctl.h>
38 #include <scsi/scsi.h>
39 #include <scsi/scsi_tcq.h>
40 #include <scsi/scsi_cmnd.h>
41 #include <scsi/scsi_device.h>
42 #include <scsi/scsi_host.h>
43 #include <scsi/scsi_transport.h>
44 #include <scsi/scsi_transport_fc.h>
45 #include <asm/ccwdev.h>
47 #include <asm/debug.h>
48 #include <asm/ebcdic.h>
52 /********************* GENERAL DEFINES *********************************/
54 /* zfcp version number, it consists of major, minor, and patch-level number */
55 #define ZFCP_VERSION "4.8.0"
58 * zfcp_sg_to_address - determine kernel address from struct scatterlist
59 * @list: struct scatterlist
60 * Return: kernel address
63 zfcp_sg_to_address(struct scatterlist *list)
65 return (void *) (page_address(list->page) + list->offset);
69 * zfcp_address_to_sg - set up struct scatterlist from kernel address
70 * @address: kernel address
71 * @list: struct scatterlist
74 zfcp_address_to_sg(void *address, struct scatterlist *list)
76 list->page = virt_to_page(address);
77 list->offset = ((unsigned long) address) & (PAGE_SIZE - 1);
80 #define REQUEST_LIST_SIZE 128
82 /********************* SCSI SPECIFIC DEFINES *********************************/
83 #define ZFCP_SCSI_ER_TIMEOUT (10*HZ)
85 /********************* CIO/QDIO SPECIFIC DEFINES *****************************/
87 /* Adapter Identification Parameters */
88 #define ZFCP_CONTROL_UNIT_TYPE 0x1731
89 #define ZFCP_CONTROL_UNIT_MODEL 0x03
90 #define ZFCP_DEVICE_TYPE 0x1732
91 #define ZFCP_DEVICE_MODEL 0x03
92 #define ZFCP_DEVICE_MODEL_PRIV 0x04
94 /* allow as many chained SBALs as are supported by hardware */
95 #define ZFCP_MAX_SBALS_PER_REQ FSF_MAX_SBALS_PER_REQ
96 #define ZFCP_MAX_SBALS_PER_CT_REQ FSF_MAX_SBALS_PER_REQ
97 #define ZFCP_MAX_SBALS_PER_ELS_REQ FSF_MAX_SBALS_PER_ELS_REQ
99 /* DMQ bug workaround: don't use last SBALE */
100 #define ZFCP_MAX_SBALES_PER_SBAL (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
102 /* index of last SBALE (with respect to DMQ bug workaround) */
103 #define ZFCP_LAST_SBALE_PER_SBAL (ZFCP_MAX_SBALES_PER_SBAL - 1)
105 /* max. number of (data buffer) SBALEs in largest SBAL chain */
106 #define ZFCP_MAX_SBALES_PER_REQ \
107 (ZFCP_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
108 /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
110 #define ZFCP_MAX_SECTORS (ZFCP_MAX_SBALES_PER_REQ * 8)
111 /* max. number of (data buffer) SBALEs in largest SBAL chain
112 multiplied with number of sectors per 4k block */
114 /* FIXME(tune): free space should be one max. SBAL chain plus what? */
115 #define ZFCP_QDIO_PCI_INTERVAL (QDIO_MAX_BUFFERS_PER_Q \
116 - (ZFCP_MAX_SBALS_PER_REQ + 4))
118 #define ZFCP_SBAL_TIMEOUT (5*HZ)
120 #define ZFCP_TYPE2_RECOVERY_TIME (8*HZ)
122 /* queue polling (values in microseconds) */
123 #define ZFCP_MAX_INPUT_THRESHOLD 5000 /* FIXME: tune */
124 #define ZFCP_MAX_OUTPUT_THRESHOLD 1000 /* FIXME: tune */
125 #define ZFCP_MIN_INPUT_THRESHOLD 1 /* ignored by QDIO layer */
126 #define ZFCP_MIN_OUTPUT_THRESHOLD 1 /* ignored by QDIO layer */
128 #define QDIO_SCSI_QFMT 1 /* 1 for FSF */
129 #define QBUFF_PER_PAGE (PAGE_SIZE / sizeof(struct qdio_buffer))
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_RSCN 0x61040000
226 #define LS_LOGO 0x05000000
227 #define LS_PLOGI 0x03000000
229 struct fcp_rscn_head {
231 u8 page_length; /* always 0x04 */
233 } __attribute__((packed));
235 struct fcp_rscn_element {
240 } __attribute__((packed));
242 #define ZFCP_PORT_ADDRESS 0x0
243 #define ZFCP_AREA_ADDRESS 0x1
244 #define ZFCP_DOMAIN_ADDRESS 0x2
245 #define ZFCP_FABRIC_ADDRESS 0x3
247 #define ZFCP_PORTS_RANGE_PORT 0xFFFFFF
248 #define ZFCP_PORTS_RANGE_AREA 0xFFFF00
249 #define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
250 #define ZFCP_PORTS_RANGE_FABRIC 0x000000
252 #define ZFCP_NO_PORTS_PER_AREA 0x100
253 #define ZFCP_NO_PORTS_PER_DOMAIN 0x10000
254 #define ZFCP_NO_PORTS_PER_FABRIC 0x1000000
261 } __attribute__((packed));
266 #define ZFCP_DBF_TAG_SIZE 4
268 struct zfcp_dbf_dump {
269 u8 tag[ZFCP_DBF_TAG_SIZE];
270 u32 total_size; /* size of total dump data */
271 u32 offset; /* how much data has being already dumped */
272 u32 size; /* how much data comes with this record */
273 u8 data[]; /* dump data */
274 } __attribute__ ((packed));
276 /* FIXME: to be inflated when reworking the erp dbf */
277 struct zfcp_erp_dbf_record {
279 } __attribute__ ((packed));
281 struct zfcp_hba_dbf_record_response {
288 u8 fsf_prot_status_qual[FSF_PROT_STATUS_QUAL_SIZE];
289 u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
317 } __attribute__ ((packed));
319 struct zfcp_hba_dbf_record_status {
323 struct fsf_queue_designator
326 #define ZFCP_DBF_UNSOL_PAYLOAD 80
327 #define ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL 32
328 #define ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD 56
329 #define ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT 2 * sizeof(u32)
330 u8 payload[ZFCP_DBF_UNSOL_PAYLOAD];
331 } __attribute__ ((packed));
333 struct zfcp_hba_dbf_record_qdio {
339 } __attribute__ ((packed));
341 struct zfcp_hba_dbf_record {
342 u8 tag[ZFCP_DBF_TAG_SIZE];
343 u8 tag2[ZFCP_DBF_TAG_SIZE];
345 struct zfcp_hba_dbf_record_response response;
346 struct zfcp_hba_dbf_record_status status;
347 struct zfcp_hba_dbf_record_qdio qdio;
349 } __attribute__ ((packed));
351 struct zfcp_san_dbf_record_ct {
370 #define ZFCP_DBF_CT_PAYLOAD 24
371 u8 payload[ZFCP_DBF_CT_PAYLOAD];
372 } __attribute__ ((packed));
374 struct zfcp_san_dbf_record_els {
377 #define ZFCP_DBF_ELS_PAYLOAD 32
378 #define ZFCP_DBF_ELS_MAX_PAYLOAD 1024
379 u8 payload[ZFCP_DBF_ELS_PAYLOAD];
380 } __attribute__ ((packed));
382 struct zfcp_san_dbf_record {
383 u8 tag[ZFCP_DBF_TAG_SIZE];
389 struct zfcp_san_dbf_record_ct ct;
390 struct zfcp_san_dbf_record_els els;
392 } __attribute__ ((packed));
394 struct zfcp_scsi_dbf_record {
395 u8 tag[ZFCP_DBF_TAG_SIZE];
396 u8 tag2[ZFCP_DBF_TAG_SIZE];
402 #define ZFCP_DBF_SCSI_OPCODE 16
403 u8 scsi_opcode[ZFCP_DBF_SCSI_OPCODE];
416 #define ZFCP_DBF_SCSI_FCP_SNS_INFO 16
417 #define ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO 256
419 u8 sns_info[ZFCP_DBF_SCSI_FCP_SNS_INFO];
422 } __attribute__ ((packed));
427 #define R_A_TOV 10 /* seconds */
428 #define ZFCP_ELS_TIMEOUT (2 * R_A_TOV)
430 #define ZFCP_LS_RLS 0x0f
431 #define ZFCP_LS_ADISC 0x52
432 #define ZFCP_LS_RPS 0x56
433 #define ZFCP_LS_RSCN 0x61
434 #define ZFCP_LS_RNID 0x78
436 struct zfcp_ls_rjt_par {
441 } __attribute__ ((packed));
443 struct zfcp_ls_adisc {
450 } __attribute__ ((packed));
452 struct zfcp_ls_adisc_acc {
459 } __attribute__ ((packed));
461 struct zfcp_rc_entry {
463 const char *description;
469 #define ZFCP_CT_REVISION 0x01
470 #define ZFCP_CT_DIRECTORY_SERVICE 0xFC
471 #define ZFCP_CT_NAME_SERVER 0x02
472 #define ZFCP_CT_SYNCHRONOUS 0x00
473 #define ZFCP_CT_GID_PN 0x0121
474 #define ZFCP_CT_MAX_SIZE 0x1020
475 #define ZFCP_CT_ACCEPT 0x8002
476 #define ZFCP_CT_REJECT 0x8001
481 #define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
483 /******************** LOGGING MACROS AND DEFINES *****************************/
486 * Logging may be applied on certain kinds of driver operations
487 * independently. Additionally, different log-levels are supported for
488 * each of these areas.
491 #define ZFCP_NAME "zfcp"
493 /* independent log areas */
494 #define ZFCP_LOG_AREA_OTHER 0
495 #define ZFCP_LOG_AREA_SCSI 1
496 #define ZFCP_LOG_AREA_FSF 2
497 #define ZFCP_LOG_AREA_CONFIG 3
498 #define ZFCP_LOG_AREA_CIO 4
499 #define ZFCP_LOG_AREA_QDIO 5
500 #define ZFCP_LOG_AREA_ERP 6
501 #define ZFCP_LOG_AREA_FC 7
503 /* log level values*/
504 #define ZFCP_LOG_LEVEL_NORMAL 0
505 #define ZFCP_LOG_LEVEL_INFO 1
506 #define ZFCP_LOG_LEVEL_DEBUG 2
507 #define ZFCP_LOG_LEVEL_TRACE 3
510 * this allows removal of logging code by the preprocessor
511 * (the most detailed log level still to be compiled in is specified,
512 * higher log levels are removed)
514 #define ZFCP_LOG_LEVEL_LIMIT ZFCP_LOG_LEVEL_TRACE
516 /* get "loglevel" nibble assignment */
517 #define ZFCP_GET_LOG_VALUE(zfcp_lognibble) \
518 ((atomic_read(&zfcp_data.loglevel) >> (zfcp_lognibble<<2)) & 0xF)
520 /* set "loglevel" nibble */
521 #define ZFCP_SET_LOG_NIBBLE(value, zfcp_lognibble) \
522 (value << (zfcp_lognibble << 2))
524 /* all log-level defaults are combined to generate initial log-level */
525 #define ZFCP_LOG_LEVEL_DEFAULTS \
526 (ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_OTHER) | \
527 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_SCSI) | \
528 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FSF) | \
529 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CONFIG) | \
530 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CIO) | \
531 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_QDIO) | \
532 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_ERP) | \
533 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FC))
535 /* check whether we have the right level for logging */
536 #define ZFCP_LOG_CHECK(level) \
537 ((ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA)) >= level)
539 /* logging routine for zfcp */
540 #define _ZFCP_LOG(fmt, args...) \
541 printk(KERN_ERR ZFCP_NAME": %s(%d): " fmt, __FUNCTION__, \
544 #define ZFCP_LOG(level, fmt, args...) \
546 if (ZFCP_LOG_CHECK(level)) \
547 _ZFCP_LOG(fmt, ##args); \
550 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_NORMAL
551 # define ZFCP_LOG_NORMAL(fmt, args...) do { } while (0)
553 # define ZFCP_LOG_NORMAL(fmt, args...) \
555 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_NORMAL)) \
556 printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
560 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_INFO
561 # define ZFCP_LOG_INFO(fmt, args...) do { } while (0)
563 # define ZFCP_LOG_INFO(fmt, args...) \
565 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_INFO)) \
566 printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
570 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_DEBUG
571 # define ZFCP_LOG_DEBUG(fmt, args...) do { } while (0)
573 # define ZFCP_LOG_DEBUG(fmt, args...) \
574 ZFCP_LOG(ZFCP_LOG_LEVEL_DEBUG, fmt , ##args)
577 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_TRACE
578 # define ZFCP_LOG_TRACE(fmt, args...) do { } while (0)
580 # define ZFCP_LOG_TRACE(fmt, args...) \
581 ZFCP_LOG(ZFCP_LOG_LEVEL_TRACE, fmt , ##args)
584 /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
587 * Note, the leftmost status byte is common among adapter, port
590 #define ZFCP_COMMON_FLAGS 0xfff00000
592 /* common status bits */
593 #define ZFCP_STATUS_COMMON_REMOVE 0x80000000
594 #define ZFCP_STATUS_COMMON_RUNNING 0x40000000
595 #define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
596 #define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
597 #define ZFCP_STATUS_COMMON_OPENING 0x08000000
598 #define ZFCP_STATUS_COMMON_OPEN 0x04000000
599 #define ZFCP_STATUS_COMMON_CLOSING 0x02000000
600 #define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
601 #define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
602 #define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
605 #define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
606 #define ZFCP_STATUS_ADAPTER_REGISTERED 0x00000004
607 #define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
608 #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
609 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
610 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
611 #define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
612 #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
613 #define ZFCP_STATUS_ADAPTER_XPORT_OK 0x00000800
615 /* FC-PH/FC-GS well-known address identifiers for generic services */
616 #define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA
617 #define ZFCP_DID_TIME_SERVICE 0xFFFFFB
618 #define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC
619 #define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8
620 #define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7
622 /* remote port status */
623 #define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
624 #define ZFCP_STATUS_PORT_DID_DID 0x00000002
625 #define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
626 #define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
627 #define ZFCP_STATUS_PORT_NO_SCSI_ID 0x00000010
628 #define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
630 /* for ports with well known addresses */
631 #define ZFCP_STATUS_PORT_WKA \
632 (ZFCP_STATUS_PORT_NO_WWPN | \
633 ZFCP_STATUS_PORT_NO_SCSI_ID)
635 /* logical unit status */
636 #define ZFCP_STATUS_UNIT_NOTSUPPUNITRESET 0x00000001
637 #define ZFCP_STATUS_UNIT_TEMPORARY 0x00000002
638 #define ZFCP_STATUS_UNIT_SHARED 0x00000004
639 #define ZFCP_STATUS_UNIT_READONLY 0x00000008
640 #define ZFCP_STATUS_UNIT_REGISTERED 0x00000010
641 #define ZFCP_STATUS_UNIT_SCSI_WORK_PENDING 0x00000020
643 /* FSF request status (this does not have a common part) */
644 #define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000
645 #define ZFCP_STATUS_FSFREQ_POOL 0x00000001
646 #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
647 #define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
648 #define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
649 #define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
650 #define ZFCP_STATUS_FSFREQ_ABORTING 0x00000020
651 #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
652 #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
653 #define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
654 #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
655 #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
656 #define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
657 #define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
659 /*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
661 #define ZFCP_MAX_ERPS 3
663 #define ZFCP_ERP_FSFREQ_TIMEOUT (30 * HZ)
664 #define ZFCP_ERP_MEMWAIT_TIMEOUT HZ
666 #define ZFCP_STATUS_ERP_TIMEDOUT 0x10000000
667 #define ZFCP_STATUS_ERP_CLOSE_ONLY 0x01000000
668 #define ZFCP_STATUS_ERP_DISMISSING 0x00100000
669 #define ZFCP_STATUS_ERP_DISMISSED 0x00200000
670 #define ZFCP_STATUS_ERP_LOWMEM 0x00400000
672 #define ZFCP_ERP_STEP_UNINITIALIZED 0x00000000
673 #define ZFCP_ERP_STEP_FSF_XCONFIG 0x00000001
674 #define ZFCP_ERP_STEP_PHYS_PORT_CLOSING 0x00000010
675 #define ZFCP_ERP_STEP_PORT_CLOSING 0x00000100
676 #define ZFCP_ERP_STEP_NAMESERVER_OPEN 0x00000200
677 #define ZFCP_ERP_STEP_NAMESERVER_LOOKUP 0x00000400
678 #define ZFCP_ERP_STEP_PORT_OPENING 0x00000800
679 #define ZFCP_ERP_STEP_UNIT_CLOSING 0x00001000
680 #define ZFCP_ERP_STEP_UNIT_OPENING 0x00002000
682 /* Ordered by escalation level (necessary for proper erp-code operation) */
683 #define ZFCP_ERP_ACTION_REOPEN_ADAPTER 0x4
684 #define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED 0x3
685 #define ZFCP_ERP_ACTION_REOPEN_PORT 0x2
686 #define ZFCP_ERP_ACTION_REOPEN_UNIT 0x1
688 #define ZFCP_ERP_ACTION_RUNNING 0x1
689 #define ZFCP_ERP_ACTION_READY 0x2
691 #define ZFCP_ERP_SUCCEEDED 0x0
692 #define ZFCP_ERP_FAILED 0x1
693 #define ZFCP_ERP_CONTINUES 0x2
694 #define ZFCP_ERP_EXIT 0x3
695 #define ZFCP_ERP_DISMISSED 0x4
696 #define ZFCP_ERP_NOMEM 0x5
699 /******************** CFDC SPECIFIC STUFF *****************************/
701 /* Firewall data channel sense data record */
702 struct zfcp_cfdc_sense_data {
703 u32 signature; /* Request signature */
704 u32 devno; /* FCP adapter device number */
705 u32 command; /* Command code */
706 u32 fsf_status; /* FSF request status and status qualifier */
707 u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
708 u8 payloads[256]; /* Access conflicts list */
709 u8 control_file[0]; /* Access control table */
712 #define ZFCP_CFDC_SIGNATURE 0xCFDCACDF
714 #define ZFCP_CFDC_CMND_DOWNLOAD_NORMAL 0x00010001
715 #define ZFCP_CFDC_CMND_DOWNLOAD_FORCE 0x00010101
716 #define ZFCP_CFDC_CMND_FULL_ACCESS 0x00000201
717 #define ZFCP_CFDC_CMND_RESTRICTED_ACCESS 0x00000401
718 #define ZFCP_CFDC_CMND_UPLOAD 0x00010002
720 #define ZFCP_CFDC_DOWNLOAD 0x00000001
721 #define ZFCP_CFDC_UPLOAD 0x00000002
722 #define ZFCP_CFDC_WITH_CONTROL_FILE 0x00010000
724 #define ZFCP_CFDC_DEV_NAME "zfcp_cfdc"
725 #define ZFCP_CFDC_DEV_MAJOR MISC_MAJOR
726 #define ZFCP_CFDC_DEV_MINOR MISC_DYNAMIC_MINOR
728 #define ZFCP_CFDC_MAX_CONTROL_FILE_SIZE 127 * 1024
730 /************************* STRUCTURE DEFINITIONS *****************************/
734 /* holds various memory pools of an adapter */
735 struct zfcp_adapter_mempool {
736 mempool_t *fsf_req_erp;
737 mempool_t *fsf_req_scsi;
738 mempool_t *fsf_req_abort;
739 mempool_t *fsf_req_status_read;
740 mempool_t *data_status_read;
741 mempool_t *data_gid_pn;
750 u8 gs_type; // 0xFC Directory Service
751 u8 gs_subtype; // 0x02 Name Server
752 u8 options; // 0x00 single bidirectional exchange
754 u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT
755 u16 max_res_size; // <= (4096 - 16) / 4
760 } __attribute__ ((packed));
762 /* nameserver request CT_IU -- for requests where
763 * a port name is required */
764 struct ct_iu_gid_pn_req {
765 struct ct_hdr header;
767 } __attribute__ ((packed));
769 /* FS_ACC IU and data unit for GID_PN nameserver request */
770 struct ct_iu_gid_pn_resp {
771 struct ct_hdr header;
773 } __attribute__ ((packed));
775 typedef void (*zfcp_send_ct_handler_t)(unsigned long);
778 * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
779 * @port: port where the request is sent to
780 * @req: scatter-gather list for request
781 * @resp: scatter-gather list for response
782 * @req_count: number of elements in request scatter-gather list
783 * @resp_count: number of elements in response scatter-gather list
784 * @handler: handler function (called for response to the request)
785 * @handler_data: data passed to handler function
786 * @pool: pointer to memory pool for ct request structure
787 * @timeout: FSF timeout for this request
788 * @completion: completion for synchronization purposes
789 * @status: used to pass error status to calling function
791 struct zfcp_send_ct {
792 struct zfcp_port *port;
793 struct scatterlist *req;
794 struct scatterlist *resp;
795 unsigned int req_count;
796 unsigned int resp_count;
797 zfcp_send_ct_handler_t handler;
798 unsigned long handler_data;
801 struct completion *completion;
805 /* used for name server requests in error recovery */
806 struct zfcp_gid_pn_data {
807 struct zfcp_send_ct ct;
808 struct scatterlist req;
809 struct scatterlist resp;
810 struct ct_iu_gid_pn_req ct_iu_req;
811 struct ct_iu_gid_pn_resp ct_iu_resp;
812 struct zfcp_port *port;
815 typedef void (*zfcp_send_els_handler_t)(unsigned long);
818 * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
819 * @adapter: adapter where request is sent from
820 * @port: port where ELS is destinated (port reference count has to be increased)
821 * @d_id: destiniation id of port where request is sent to
822 * @req: scatter-gather list for request
823 * @resp: scatter-gather list for response
824 * @req_count: number of elements in request scatter-gather list
825 * @resp_count: number of elements in response scatter-gather list
826 * @handler: handler function (called for response to the request)
827 * @handler_data: data passed to handler function
828 * @completion: completion for synchronization purposes
829 * @ls_code: hex code of ELS command
830 * @status: used to pass error status to calling function
832 struct zfcp_send_els {
833 struct zfcp_adapter *adapter;
834 struct zfcp_port *port;
836 struct scatterlist *req;
837 struct scatterlist *resp;
838 unsigned int req_count;
839 unsigned int resp_count;
840 zfcp_send_els_handler_t handler;
841 unsigned long handler_data;
842 struct completion *completion;
847 struct zfcp_qdio_queue {
848 struct qdio_buffer *buffer[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
849 u8 free_index; /* index of next free bfr
850 in queue (free_count>0) */
851 atomic_t free_count; /* number of free buffers
853 rwlock_t queue_lock; /* lock for operations on queue */
854 int distance_from_int; /* SBALs used since PCI indication
858 struct zfcp_erp_action {
859 struct list_head list;
860 int action; /* requested action code */
861 struct zfcp_adapter *adapter; /* device which should be recovered */
862 struct zfcp_port *port;
863 struct zfcp_unit *unit;
864 volatile u32 status; /* recovery status */
865 u32 step; /* active step of this erp action */
866 struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
868 struct timer_list timer;
872 struct zfcp_adapter {
873 struct list_head list; /* list of adapters */
874 atomic_t refcount; /* reference count */
875 wait_queue_head_t remove_wq; /* can be used to wait for
876 refcount drop to zero */
877 wwn_t peer_wwnn; /* P2P peer WWNN */
878 wwn_t peer_wwpn; /* P2P peer WWPN */
879 u32 peer_d_id; /* P2P peer D_ID */
880 struct ccw_device *ccw_device; /* S/390 ccw device */
881 u32 hydra_version; /* Hydra version */
883 u32 adapter_features; /* FCP channel features */
884 u32 connection_features; /* host connection features */
885 u32 hardware_version; /* of FCP channel */
886 struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
887 struct list_head port_list_head; /* remote port list */
888 struct list_head port_remove_lh; /* head of ports to be
890 u32 ports; /* number of remote ports */
891 atomic_t reqs_active; /* # active FSF reqs */
892 unsigned long req_no; /* unique FSF req number */
893 struct list_head *req_list; /* list of pending reqs */
894 spinlock_t req_list_lock; /* request list lock */
895 struct zfcp_qdio_queue request_queue; /* request queue */
896 u32 fsf_req_seq_no; /* FSF cmnd seq number */
897 wait_queue_head_t request_wq; /* can be used to wait for
898 more avaliable SBALs */
899 struct zfcp_qdio_queue response_queue; /* response queue */
900 rwlock_t abort_lock; /* Protects against SCSI
903 u16 status_read_failed; /* # failed status reads */
904 atomic_t status; /* status of this adapter */
905 struct list_head erp_ready_head; /* error recovery for this
907 struct list_head erp_running_head;
909 struct semaphore erp_ready_sem;
910 wait_queue_head_t erp_thread_wqh;
911 wait_queue_head_t erp_done_wqh;
912 struct zfcp_erp_action erp_action; /* pending error recovery */
913 atomic_t erp_counter;
914 u32 erp_total_count; /* total nr of enqueued erp
916 u32 erp_low_mem_count; /* nr of erp actions waiting
918 struct zfcp_port *nameserver_port; /* adapter's nameserver */
919 debug_info_t *erp_dbf;
920 debug_info_t *hba_dbf;
921 debug_info_t *san_dbf; /* debug feature areas */
922 debug_info_t *scsi_dbf;
923 spinlock_t erp_dbf_lock;
924 spinlock_t hba_dbf_lock;
925 spinlock_t san_dbf_lock;
926 spinlock_t scsi_dbf_lock;
927 struct zfcp_erp_dbf_record erp_dbf_buf;
928 struct zfcp_hba_dbf_record hba_dbf_buf;
929 struct zfcp_san_dbf_record san_dbf_buf;
930 struct zfcp_scsi_dbf_record scsi_dbf_buf;
931 struct zfcp_adapter_mempool pool; /* Adapter memory pools */
932 struct qdio_initialize qdio_init_data; /* for qdio_establish */
933 struct device generic_services; /* directory for WKA ports */
934 struct fc_host_statistics *fc_stats;
935 struct fsf_qtcb_bottom_port *stats_reset_data;
936 unsigned long stats_reset;
940 * the struct device sysfs_device must be at the beginning of this structure.
941 * pointer to struct device is used to free port structure in release function
942 * of the device. don't change!
945 struct device sysfs_device; /* sysfs device */
946 struct fc_rport *rport; /* rport of fc transport class */
947 struct list_head list; /* list of remote ports */
948 atomic_t refcount; /* reference count */
949 wait_queue_head_t remove_wq; /* can be used to wait for
950 refcount drop to zero */
951 struct zfcp_adapter *adapter; /* adapter used to access port */
952 struct list_head unit_list_head; /* head of logical unit list */
953 struct list_head unit_remove_lh; /* head of luns to be removed
955 u32 units; /* # of logical units in list */
956 atomic_t status; /* status of this remote port */
957 wwn_t wwnn; /* WWNN if known */
958 wwn_t wwpn; /* WWPN */
960 u32 handle; /* handle assigned by FSF */
961 struct zfcp_erp_action erp_action; /* pending error recovery */
962 atomic_t erp_counter;
964 u32 supported_classes;
967 /* the struct device sysfs_device must be at the beginning of this structure.
968 * pointer to struct device is used to free unit structure in release function
969 * of the device. don't change!
972 struct device sysfs_device; /* sysfs device */
973 struct list_head list; /* list of logical units */
974 atomic_t refcount; /* reference count */
975 wait_queue_head_t remove_wq; /* can be used to wait for
976 refcount drop to zero */
977 struct zfcp_port *port; /* remote port of unit */
978 atomic_t status; /* status of this logical unit */
979 unsigned int scsi_lun; /* own SCSI LUN */
980 fcp_lun_t fcp_lun; /* own FCP_LUN */
981 u32 handle; /* handle assigned by FSF */
982 struct scsi_device *device; /* scsi device struct pointer */
983 struct zfcp_erp_action erp_action; /* pending error recovery */
984 atomic_t erp_counter;
985 wait_queue_head_t scsi_scan_wq; /* can be used to wait until
992 struct zfcp_fsf_req {
993 struct list_head list; /* list of FSF requests */
994 unsigned long req_id; /* unique request ID */
995 struct zfcp_adapter *adapter; /* adapter request belongs to */
996 u8 sbal_number; /* nr of SBALs free for use */
997 u8 sbal_first; /* first SBAL for this request */
998 u8 sbal_last; /* last possible SBAL for
1000 u8 sbal_curr; /* current SBAL during creation
1002 u8 sbale_curr; /* current SBALE during creation
1004 wait_queue_head_t completion_wq; /* can be used by a routine
1005 to wait for completion */
1006 volatile u32 status; /* status of this request */
1007 u32 fsf_command; /* FSF Command copy */
1008 struct fsf_qtcb *qtcb; /* address of associated QTCB */
1009 u32 seq_no; /* Sequence number of request */
1010 unsigned long data; /* private data of request */
1011 struct timer_list timer; /* used for erp or scsi er */
1012 struct zfcp_erp_action *erp_action; /* used if this request is
1013 issued on behalf of erp */
1014 mempool_t *pool; /* used if request was alloacted
1015 from emergency pool */
1016 unsigned long long issued; /* request sent time (STCK) */
1017 struct zfcp_unit *unit;
1020 typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
1024 struct scsi_host_template scsi_host_template;
1025 struct scsi_transport_template *scsi_transport_template;
1026 atomic_t status; /* Module status flags */
1027 struct list_head adapter_list_head; /* head of adapter list */
1028 struct list_head adapter_remove_lh; /* head of adapters to be
1030 u32 adapters; /* # of adapters in list */
1031 rwlock_t config_lock; /* serialises changes
1032 to adapter/port/unit
1034 struct semaphore config_sema; /* serialises configuration
1036 atomic_t loglevel; /* current loglevel */
1037 char init_busid[BUS_ID_SIZE];
1039 fcp_lun_t init_fcp_lun;
1040 char *driver_version;
1041 struct kmem_cache *fsf_req_qtcb_cache;
1042 struct kmem_cache *sr_buffer_cache;
1043 struct kmem_cache *gid_pn_cache;
1047 * struct zfcp_sg_list - struct describing a scatter-gather list
1048 * @sg: pointer to array of (struct scatterlist)
1049 * @count: number of elements in scatter-gather list
1051 struct zfcp_sg_list {
1052 struct scatterlist *sg;
1056 /* number of elements for various memory pools */
1057 #define ZFCP_POOL_FSF_REQ_ERP_NR 1
1058 #define ZFCP_POOL_FSF_REQ_SCSI_NR 1
1059 #define ZFCP_POOL_FSF_REQ_ABORT_NR 1
1060 #define ZFCP_POOL_STATUS_READ_NR ZFCP_STATUS_READS_RECOM
1061 #define ZFCP_POOL_DATA_GID_PN_NR 1
1063 /* struct used by memory pools for fsf_requests */
1064 struct zfcp_fsf_req_qtcb {
1065 struct zfcp_fsf_req fsf_req;
1066 struct fsf_qtcb qtcb;
1069 /********************** ZFCP SPECIFIC DEFINES ********************************/
1071 #define ZFCP_REQ_AUTO_CLEANUP 0x00000002
1072 #define ZFCP_WAIT_FOR_SBAL 0x00000004
1073 #define ZFCP_REQ_NO_QTCB 0x00000008
1075 #define ZFCP_SET 0x00000100
1076 #define ZFCP_CLEAR 0x00000200
1078 #ifndef atomic_test_mask
1079 #define atomic_test_mask(mask, target) \
1080 ((atomic_read(target) & mask) == mask)
1083 extern void _zfcp_hex_dump(char *, int);
1084 #define ZFCP_HEX_DUMP(level, addr, count) \
1085 if (ZFCP_LOG_CHECK(level)) { \
1086 _zfcp_hex_dump(addr, count); \
1089 #define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
1090 #define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
1091 #define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
1094 * Helper functions for request ID management.
1096 static inline int zfcp_reqlist_hash(unsigned long req_id)
1098 return req_id % REQUEST_LIST_SIZE;
1101 static inline void zfcp_reqlist_add(struct zfcp_adapter *adapter,
1102 struct zfcp_fsf_req *fsf_req)
1106 idx = zfcp_reqlist_hash(fsf_req->req_id);
1107 list_add_tail(&fsf_req->list, &adapter->req_list[idx]);
1110 static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
1111 struct zfcp_fsf_req *fsf_req)
1113 list_del(&fsf_req->list);
1116 static inline struct zfcp_fsf_req *
1117 zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
1119 struct zfcp_fsf_req *request;
1122 idx = zfcp_reqlist_hash(req_id);
1123 list_for_each_entry(request, &adapter->req_list[idx], list)
1124 if (request->req_id == req_id)
1130 * functions needed for reference/usage counting
1134 zfcp_unit_get(struct zfcp_unit *unit)
1136 atomic_inc(&unit->refcount);
1140 zfcp_unit_put(struct zfcp_unit *unit)
1142 if (atomic_dec_return(&unit->refcount) == 0)
1143 wake_up(&unit->remove_wq);
1147 zfcp_unit_wait(struct zfcp_unit *unit)
1149 wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
1153 zfcp_port_get(struct zfcp_port *port)
1155 atomic_inc(&port->refcount);
1159 zfcp_port_put(struct zfcp_port *port)
1161 if (atomic_dec_return(&port->refcount) == 0)
1162 wake_up(&port->remove_wq);
1166 zfcp_port_wait(struct zfcp_port *port)
1168 wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
1172 zfcp_adapter_get(struct zfcp_adapter *adapter)
1174 atomic_inc(&adapter->refcount);
1178 zfcp_adapter_put(struct zfcp_adapter *adapter)
1180 if (atomic_dec_return(&adapter->refcount) == 0)
1181 wake_up(&adapter->remove_wq);
1185 zfcp_adapter_wait(struct zfcp_adapter *adapter)
1187 wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
1190 #endif /* ZFCP_DEF_H */