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 #define ZFCP_DEF_REVISION "$Revision: 1.111 $"
39 /*************************** INCLUDES *****************************************/
41 #include <linux/init.h>
42 #include <linux/moduleparam.h>
43 #include <linux/miscdevice.h>
44 #include <linux/major.h>
45 #include <linux/blkdev.h>
46 #include <linux/delay.h>
47 #include <linux/timer.h>
48 #include <scsi/scsi.h>
49 #include <scsi/scsi_tcq.h>
50 #include <scsi/scsi_cmnd.h>
51 #include <scsi/scsi_device.h>
52 #include <scsi/scsi_host.h>
53 #include <scsi/scsi_transport.h>
54 #include <scsi/scsi_transport_fc.h>
55 #include "../../fc4/fc.h"
57 #include <asm/ccwdev.h>
59 #include <asm/debug.h>
60 #include <asm/ebcdic.h>
61 #include <linux/mempool.h>
62 #include <linux/syscalls.h>
63 #include <linux/ioctl.h>
66 /********************* GENERAL DEFINES *********************************/
68 /* zfcp version number, it consists of major, minor, and patch-level number */
69 #define ZFCP_VERSION "4.3.0"
72 * zfcp_sg_to_address - determine kernel address from struct scatterlist
73 * @list: struct scatterlist
74 * Return: kernel address
77 zfcp_sg_to_address(struct scatterlist
*list
)
79 return (void *) (page_address(list
->page
) + list
->offset
);
83 * zfcp_address_to_sg - set up struct scatterlist from kernel address
84 * @address: kernel address
85 * @list: struct scatterlist
88 zfcp_address_to_sg(void *address
, struct scatterlist
*list
)
90 list
->page
= virt_to_page(address
);
91 list
->offset
= ((unsigned long) address
) & (PAGE_SIZE
- 1);
94 /********************* SCSI SPECIFIC DEFINES *********************************/
96 /* 32 bit for SCSI ID and LUN as long as the SCSI stack uses this type */
97 typedef u32 scsi_id_t
;
98 typedef u32 scsi_lun_t
;
100 #define ZFCP_ERP_SCSI_LOW_MEM_TIMEOUT (100*HZ)
101 #define ZFCP_SCSI_ER_TIMEOUT (100*HZ)
103 /********************* CIO/QDIO SPECIFIC DEFINES *****************************/
105 /* Adapter Identification Parameters */
106 #define ZFCP_CONTROL_UNIT_TYPE 0x1731
107 #define ZFCP_CONTROL_UNIT_MODEL 0x03
108 #define ZFCP_DEVICE_TYPE 0x1732
109 #define ZFCP_DEVICE_MODEL 0x03
110 #define ZFCP_DEVICE_MODEL_PRIV 0x04
112 /* allow as many chained SBALs as are supported by hardware */
113 #define ZFCP_MAX_SBALS_PER_REQ FSF_MAX_SBALS_PER_REQ
114 #define ZFCP_MAX_SBALS_PER_CT_REQ FSF_MAX_SBALS_PER_REQ
115 #define ZFCP_MAX_SBALS_PER_ELS_REQ FSF_MAX_SBALS_PER_ELS_REQ
117 /* DMQ bug workaround: don't use last SBALE */
118 #define ZFCP_MAX_SBALES_PER_SBAL (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
120 /* index of last SBALE (with respect to DMQ bug workaround) */
121 #define ZFCP_LAST_SBALE_PER_SBAL (ZFCP_MAX_SBALES_PER_SBAL - 1)
123 /* max. number of (data buffer) SBALEs in largest SBAL chain */
124 #define ZFCP_MAX_SBALES_PER_REQ \
125 (ZFCP_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
126 /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
128 /* FIXME(tune): free space should be one max. SBAL chain plus what? */
129 #define ZFCP_QDIO_PCI_INTERVAL (QDIO_MAX_BUFFERS_PER_Q \
130 - (ZFCP_MAX_SBALS_PER_REQ + 4))
132 #define ZFCP_SBAL_TIMEOUT (5*HZ)
134 #define ZFCP_TYPE2_RECOVERY_TIME (8*HZ)
136 /* queue polling (values in microseconds) */
137 #define ZFCP_MAX_INPUT_THRESHOLD 5000 /* FIXME: tune */
138 #define ZFCP_MAX_OUTPUT_THRESHOLD 1000 /* FIXME: tune */
139 #define ZFCP_MIN_INPUT_THRESHOLD 1 /* ignored by QDIO layer */
140 #define ZFCP_MIN_OUTPUT_THRESHOLD 1 /* ignored by QDIO layer */
142 #define QDIO_SCSI_QFMT 1 /* 1 for FSF */
144 /********************* FSF SPECIFIC DEFINES *********************************/
146 #define ZFCP_ULP_INFO_VERSION 26
147 #define ZFCP_QTCB_VERSION FSF_QTCB_CURRENT_VERSION
148 /* ATTENTION: value must not be used by hardware */
149 #define FSF_QTCB_UNSOLICITED_STATUS 0x6305
150 #define ZFCP_STATUS_READ_FAILED_THRESHOLD 3
151 #define ZFCP_STATUS_READS_RECOM FSF_STATUS_READS_RECOM
152 #define ZFCP_EXCHANGE_CONFIG_DATA_RETRIES 6
153 #define ZFCP_EXCHANGE_CONFIG_DATA_SLEEP 50
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 int fc_id_t
;
162 typedef unsigned long long fcp_lun_t
;
163 /* data length field may be at variable position in FCP-2 FCP_CMND IU */
164 typedef unsigned int fcp_dl_t
;
166 #define ZFCP_FC_SERVICE_CLASS_DEFAULT FSF_CLASS_3
168 /* timeout for name-server lookup (in seconds) */
169 #define ZFCP_NS_GID_PN_TIMEOUT 10
171 /* largest SCSI command we can process */
172 /* FCP-2 (FCP_CMND IU) allows up to (255-3+16) */
173 #define ZFCP_MAX_SCSI_CMND_LENGTH 255
174 /* maximum number of commands in LUN queue (tagged queueing) */
175 #define ZFCP_CMND_PER_LUN 32
177 /* task attribute values in FCP-2 FCP_CMND IU */
184 /* task management flags in FCP-2 FCP_CMND IU */
185 #define FCP_CLEAR_ACA 0x40
186 #define FCP_TARGET_RESET 0x20
187 #define FCP_LOGICAL_UNIT_RESET 0x10
188 #define FCP_CLEAR_TASK_SET 0x04
189 #define FCP_ABORT_TASK_SET 0x02
191 #define FCP_CDB_LENGTH 16
193 #define ZFCP_DID_MASK 0x00FFFFFF
195 /* FCP(-2) FCP_CMND IU */
197 fcp_lun_t fcp_lun
; /* FCP logical unit number */
198 u8 crn
; /* command reference number */
199 u8 reserved0
:5; /* reserved */
200 u8 task_attribute
:3; /* task attribute */
201 u8 task_management_flags
; /* task management flags */
202 u8 add_fcp_cdb_length
:6; /* additional FCP_CDB length */
203 u8 rddata
:1; /* read data */
204 u8 wddata
:1; /* write data */
205 u8 fcp_cdb
[FCP_CDB_LENGTH
];
206 } __attribute__((packed
));
208 /* FCP(-2) FCP_RSP IU */
215 u8 fcp_resid_under
:1;
217 u8 fcp_sns_len_valid
:1;
218 u8 fcp_rsp_len_valid
:1;
226 } __attribute__((packed
));
229 #define RSP_CODE_GOOD 0
230 #define RSP_CODE_LENGTH_MISMATCH 1
231 #define RSP_CODE_FIELD_INVALID 2
232 #define RSP_CODE_RO_MISMATCH 3
233 #define RSP_CODE_TASKMAN_UNSUPP 4
234 #define RSP_CODE_TASKMAN_FAILED 5
237 #define LS_FAN 0x60000000
238 #define LS_RSCN 0x61040000
240 struct fcp_rscn_head
{
242 u8 page_length
; /* always 0x04 */
244 } __attribute__((packed
));
246 struct fcp_rscn_element
{
251 } __attribute__((packed
));
253 #define ZFCP_PORT_ADDRESS 0x0
254 #define ZFCP_AREA_ADDRESS 0x1
255 #define ZFCP_DOMAIN_ADDRESS 0x2
256 #define ZFCP_FABRIC_ADDRESS 0x3
258 #define ZFCP_PORTS_RANGE_PORT 0xFFFFFF
259 #define ZFCP_PORTS_RANGE_AREA 0xFFFF00
260 #define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
261 #define ZFCP_PORTS_RANGE_FABRIC 0x000000
263 #define ZFCP_NO_PORTS_PER_AREA 0x100
264 #define ZFCP_NO_PORTS_PER_DOMAIN 0x10000
265 #define ZFCP_NO_PORTS_PER_FABRIC 0x1000000
272 } __attribute__((packed
));
279 } __attribute__((packed
));
284 #define R_A_TOV 10 /* seconds */
285 #define ZFCP_ELS_TIMEOUT (2 * R_A_TOV)
287 #define ZFCP_LS_RLS 0x0f
288 #define ZFCP_LS_ADISC 0x52
289 #define ZFCP_LS_RPS 0x56
290 #define ZFCP_LS_RSCN 0x61
291 #define ZFCP_LS_RNID 0x78
293 struct zfcp_ls_rjt_par
{
298 } __attribute__ ((packed
));
300 struct zfcp_ls_adisc
{
307 } __attribute__ ((packed
));
309 struct zfcp_ls_adisc_acc
{
316 } __attribute__ ((packed
));
318 struct zfcp_rc_entry
{
320 const char *description
;
326 #define ZFCP_CT_REVISION 0x01
327 #define ZFCP_CT_DIRECTORY_SERVICE 0xFC
328 #define ZFCP_CT_NAME_SERVER 0x02
329 #define ZFCP_CT_SYNCHRONOUS 0x00
330 #define ZFCP_CT_GID_PN 0x0121
331 #define ZFCP_CT_MAX_SIZE 0x1020
332 #define ZFCP_CT_ACCEPT 0x8002
333 #define ZFCP_CT_REJECT 0x8001
338 #define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
341 /***************** S390 DEBUG FEATURE SPECIFIC DEFINES ***********************/
343 /* debug feature entries per adapter */
344 #define ZFCP_ERP_DBF_INDEX 1
345 #define ZFCP_ERP_DBF_AREAS 2
346 #define ZFCP_ERP_DBF_LENGTH 16
347 #define ZFCP_ERP_DBF_LEVEL 3
348 #define ZFCP_ERP_DBF_NAME "zfcperp"
350 #define ZFCP_CMD_DBF_INDEX 2
351 #define ZFCP_CMD_DBF_AREAS 1
352 #define ZFCP_CMD_DBF_LENGTH 8
353 #define ZFCP_CMD_DBF_LEVEL 3
354 #define ZFCP_CMD_DBF_NAME "zfcpcmd"
356 #define ZFCP_ABORT_DBF_INDEX 2
357 #define ZFCP_ABORT_DBF_AREAS 1
358 #define ZFCP_ABORT_DBF_LENGTH 8
359 #define ZFCP_ABORT_DBF_LEVEL 6
360 #define ZFCP_ABORT_DBF_NAME "zfcpabt"
362 #define ZFCP_IN_ELS_DBF_INDEX 2
363 #define ZFCP_IN_ELS_DBF_AREAS 1
364 #define ZFCP_IN_ELS_DBF_LENGTH 8
365 #define ZFCP_IN_ELS_DBF_LEVEL 6
366 #define ZFCP_IN_ELS_DBF_NAME "zfcpels"
368 /******************** LOGGING MACROS AND DEFINES *****************************/
371 * Logging may be applied on certain kinds of driver operations
372 * independently. Additionally, different log-levels are supported for
373 * each of these areas.
376 #define ZFCP_NAME "zfcp"
378 /* read-only LUN sharing switch initial value */
379 #define ZFCP_RO_LUN_SHARING_DEFAULTS 0
381 /* independent log areas */
382 #define ZFCP_LOG_AREA_OTHER 0
383 #define ZFCP_LOG_AREA_SCSI 1
384 #define ZFCP_LOG_AREA_FSF 2
385 #define ZFCP_LOG_AREA_CONFIG 3
386 #define ZFCP_LOG_AREA_CIO 4
387 #define ZFCP_LOG_AREA_QDIO 5
388 #define ZFCP_LOG_AREA_ERP 6
389 #define ZFCP_LOG_AREA_FC 7
391 /* log level values*/
392 #define ZFCP_LOG_LEVEL_NORMAL 0
393 #define ZFCP_LOG_LEVEL_INFO 1
394 #define ZFCP_LOG_LEVEL_DEBUG 2
395 #define ZFCP_LOG_LEVEL_TRACE 3
398 * this allows removal of logging code by the preprocessor
399 * (the most detailed log level still to be compiled in is specified,
400 * higher log levels are removed)
402 #define ZFCP_LOG_LEVEL_LIMIT ZFCP_LOG_LEVEL_TRACE
404 /* get "loglevel" nibble assignment */
405 #define ZFCP_GET_LOG_VALUE(zfcp_lognibble) \
406 ((atomic_read(&zfcp_data.loglevel) >> (zfcp_lognibble<<2)) & 0xF)
408 /* set "loglevel" nibble */
409 #define ZFCP_SET_LOG_NIBBLE(value, zfcp_lognibble) \
410 (value << (zfcp_lognibble << 2))
412 /* all log-level defaults are combined to generate initial log-level */
413 #define ZFCP_LOG_LEVEL_DEFAULTS \
414 (ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_OTHER) | \
415 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_SCSI) | \
416 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FSF) | \
417 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CONFIG) | \
418 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CIO) | \
419 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_QDIO) | \
420 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_ERP) | \
421 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FC))
423 /* check whether we have the right level for logging */
424 #define ZFCP_LOG_CHECK(level) \
425 ((ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA)) >= level)
427 /* logging routine for zfcp */
428 #define _ZFCP_LOG(fmt, args...) \
429 printk(KERN_ERR ZFCP_NAME": %s(%d): " fmt, __FUNCTION__, \
432 #define ZFCP_LOG(level, fmt, args...) \
434 if (ZFCP_LOG_CHECK(level)) \
435 _ZFCP_LOG(fmt, ##args); \
438 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_NORMAL
439 # define ZFCP_LOG_NORMAL(fmt, args...)
441 # define ZFCP_LOG_NORMAL(fmt, args...) \
443 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_NORMAL)) \
444 printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
448 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_INFO
449 # define ZFCP_LOG_INFO(fmt, args...)
451 # define ZFCP_LOG_INFO(fmt, args...) \
453 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_INFO)) \
454 printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
458 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_DEBUG
459 # define ZFCP_LOG_DEBUG(fmt, args...)
461 # define ZFCP_LOG_DEBUG(fmt, args...) \
462 ZFCP_LOG(ZFCP_LOG_LEVEL_DEBUG, fmt , ##args)
465 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_TRACE
466 # define ZFCP_LOG_TRACE(fmt, args...)
468 # define ZFCP_LOG_TRACE(fmt, args...) \
469 ZFCP_LOG(ZFCP_LOG_LEVEL_TRACE, fmt , ##args)
472 /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
475 * Note, the leftmost status byte is common among adapter, port
478 #define ZFCP_COMMON_FLAGS 0xfff00000
479 #define ZFCP_SPECIFIC_FLAGS 0x000fffff
481 /* common status bits */
482 #define ZFCP_STATUS_COMMON_REMOVE 0x80000000
483 #define ZFCP_STATUS_COMMON_RUNNING 0x40000000
484 #define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
485 #define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
486 #define ZFCP_STATUS_COMMON_OPENING 0x08000000
487 #define ZFCP_STATUS_COMMON_OPEN 0x04000000
488 #define ZFCP_STATUS_COMMON_CLOSING 0x02000000
489 #define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
490 #define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
493 #define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
494 #define ZFCP_STATUS_ADAPTER_REGISTERED 0x00000004
495 #define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
496 #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
497 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
498 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
499 #define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
500 #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
502 #define ZFCP_STATUS_ADAPTER_SCSI_UP \
503 (ZFCP_STATUS_COMMON_UNBLOCKED | \
504 ZFCP_STATUS_ADAPTER_REGISTERED)
507 /* FC-PH/FC-GS well-known address identifiers for generic services */
508 #define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA
509 #define ZFCP_DID_TIME_SERVICE 0xFFFFFB
510 #define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC
511 #define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8
512 #define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7
514 /* remote port status */
515 #define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
516 #define ZFCP_STATUS_PORT_DID_DID 0x00000002
517 #define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
518 #define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
519 #define ZFCP_STATUS_PORT_NO_SCSI_ID 0x00000010
520 #define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
521 #define ZFCP_STATUS_PORT_ACCESS_DENIED 0x00000040
523 /* for ports with well known addresses */
524 #define ZFCP_STATUS_PORT_WKA \
525 (ZFCP_STATUS_PORT_NO_WWPN | \
526 ZFCP_STATUS_PORT_NO_SCSI_ID)
528 /* logical unit status */
529 #define ZFCP_STATUS_UNIT_NOTSUPPUNITRESET 0x00000001
530 #define ZFCP_STATUS_UNIT_TEMPORARY 0x00000002
531 #define ZFCP_STATUS_UNIT_SHARED 0x00000004
532 #define ZFCP_STATUS_UNIT_READONLY 0x00000008
534 /* FSF request status (this does not have a common part) */
535 #define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000
536 #define ZFCP_STATUS_FSFREQ_POOL 0x00000001
537 #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
538 #define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
539 #define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
540 #define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
541 #define ZFCP_STATUS_FSFREQ_ABORTING 0x00000020
542 #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
543 #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
544 #define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
545 #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
546 #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
547 #define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
548 #define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
550 /*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
552 #define ZFCP_MAX_ERPS 3
554 #define ZFCP_ERP_FSFREQ_TIMEOUT (30 * HZ)
555 #define ZFCP_ERP_MEMWAIT_TIMEOUT HZ
557 #define ZFCP_STATUS_ERP_TIMEDOUT 0x10000000
558 #define ZFCP_STATUS_ERP_CLOSE_ONLY 0x01000000
559 #define ZFCP_STATUS_ERP_DISMISSING 0x00100000
560 #define ZFCP_STATUS_ERP_DISMISSED 0x00200000
561 #define ZFCP_STATUS_ERP_LOWMEM 0x00400000
563 #define ZFCP_ERP_STEP_UNINITIALIZED 0x00000000
564 #define ZFCP_ERP_STEP_FSF_XCONFIG 0x00000001
565 #define ZFCP_ERP_STEP_PHYS_PORT_CLOSING 0x00000010
566 #define ZFCP_ERP_STEP_PORT_CLOSING 0x00000100
567 #define ZFCP_ERP_STEP_NAMESERVER_OPEN 0x00000200
568 #define ZFCP_ERP_STEP_NAMESERVER_LOOKUP 0x00000400
569 #define ZFCP_ERP_STEP_PORT_OPENING 0x00000800
570 #define ZFCP_ERP_STEP_UNIT_CLOSING 0x00001000
571 #define ZFCP_ERP_STEP_UNIT_OPENING 0x00002000
573 /* Ordered by escalation level (necessary for proper erp-code operation) */
574 #define ZFCP_ERP_ACTION_REOPEN_ADAPTER 0x4
575 #define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED 0x3
576 #define ZFCP_ERP_ACTION_REOPEN_PORT 0x2
577 #define ZFCP_ERP_ACTION_REOPEN_UNIT 0x1
579 #define ZFCP_ERP_ACTION_RUNNING 0x1
580 #define ZFCP_ERP_ACTION_READY 0x2
582 #define ZFCP_ERP_SUCCEEDED 0x0
583 #define ZFCP_ERP_FAILED 0x1
584 #define ZFCP_ERP_CONTINUES 0x2
585 #define ZFCP_ERP_EXIT 0x3
586 #define ZFCP_ERP_DISMISSED 0x4
587 #define ZFCP_ERP_NOMEM 0x5
590 /******************** CFDC SPECIFIC STUFF *****************************/
592 /* Firewall data channel sense data record */
593 struct zfcp_cfdc_sense_data
{
594 u32 signature
; /* Request signature */
595 u32 devno
; /* FCP adapter device number */
596 u32 command
; /* Command code */
597 u32 fsf_status
; /* FSF request status and status qualifier */
598 u8 fsf_status_qual
[FSF_STATUS_QUALIFIER_SIZE
];
599 u8 payloads
[256]; /* Access conflicts list */
600 u8 control_file
[0]; /* Access control table */
603 #define ZFCP_CFDC_SIGNATURE 0xCFDCACDF
605 #define ZFCP_CFDC_CMND_DOWNLOAD_NORMAL 0x00010001
606 #define ZFCP_CFDC_CMND_DOWNLOAD_FORCE 0x00010101
607 #define ZFCP_CFDC_CMND_FULL_ACCESS 0x00000201
608 #define ZFCP_CFDC_CMND_RESTRICTED_ACCESS 0x00000401
609 #define ZFCP_CFDC_CMND_UPLOAD 0x00010002
611 #define ZFCP_CFDC_DOWNLOAD 0x00000001
612 #define ZFCP_CFDC_UPLOAD 0x00000002
613 #define ZFCP_CFDC_WITH_CONTROL_FILE 0x00010000
615 #define ZFCP_CFDC_DEV_NAME "zfcp_cfdc"
616 #define ZFCP_CFDC_DEV_MAJOR MISC_MAJOR
617 #define ZFCP_CFDC_DEV_MINOR MISC_DYNAMIC_MINOR
619 #define ZFCP_CFDC_MAX_CONTROL_FILE_SIZE 127 * 1024
621 /************************* STRUCTURE DEFINITIONS *****************************/
625 /* holds various memory pools of an adapter */
626 struct zfcp_adapter_mempool
{
627 mempool_t
*fsf_req_erp
;
628 mempool_t
*fsf_req_scsi
;
629 mempool_t
*fsf_req_abort
;
630 mempool_t
*fsf_req_status_read
;
631 mempool_t
*data_status_read
;
632 mempool_t
*data_gid_pn
;
635 struct zfcp_exchange_config_data
{
638 struct zfcp_open_port
{
639 struct zfcp_port
*port
;
642 struct zfcp_close_port
{
643 struct zfcp_port
*port
;
646 struct zfcp_open_unit
{
647 struct zfcp_unit
*unit
;
650 struct zfcp_close_unit
{
651 struct zfcp_unit
*unit
;
654 struct zfcp_close_physical_port
{
655 struct zfcp_port
*port
;
658 struct zfcp_send_fcp_command_task
{
659 struct zfcp_fsf_req
*fsf_req
;
660 struct zfcp_unit
*unit
;
661 struct scsi_cmnd
*scsi_cmnd
;
662 unsigned long start_jiffies
;
665 struct zfcp_send_fcp_command_task_management
{
666 struct zfcp_unit
*unit
;
669 struct zfcp_abort_fcp_command
{
670 struct zfcp_fsf_req
*fsf_req
;
671 struct zfcp_unit
*unit
;
680 u8 gs_type
; // 0xFC Directory Service
681 u8 gs_subtype
; // 0x02 Name Server
682 u8 options
; // 0x00 single bidirectional exchange
684 u16 cmd_rsp_code
; // 0x0121 GID_PN, or 0x0100 GA_NXT
685 u16 max_res_size
; // <= (4096 - 16) / 4
690 } __attribute__ ((packed
));
692 /* nameserver request CT_IU -- for requests where
693 * a port name is required */
694 struct ct_iu_gid_pn_req
{
695 struct ct_hdr header
;
697 } __attribute__ ((packed
));
699 /* FS_ACC IU and data unit for GID_PN nameserver request */
700 struct ct_iu_gid_pn_resp
{
701 struct ct_hdr header
;
703 } __attribute__ ((packed
));
705 typedef void (*zfcp_send_ct_handler_t
)(unsigned long);
708 * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
709 * @port: port where the request is sent to
710 * @req: scatter-gather list for request
711 * @resp: scatter-gather list for response
712 * @req_count: number of elements in request scatter-gather list
713 * @resp_count: number of elements in response scatter-gather list
714 * @handler: handler function (called for response to the request)
715 * @handler_data: data passed to handler function
716 * @pool: pointer to memory pool for ct request structure
717 * @timeout: FSF timeout for this request
718 * @timer: timer (e.g. for request initiated by erp)
719 * @completion: completion for synchronization purposes
720 * @status: used to pass error status to calling function
722 struct zfcp_send_ct
{
723 struct zfcp_port
*port
;
724 struct scatterlist
*req
;
725 struct scatterlist
*resp
;
726 unsigned int req_count
;
727 unsigned int resp_count
;
728 zfcp_send_ct_handler_t handler
;
729 unsigned long handler_data
;
732 struct timer_list
*timer
;
733 struct completion
*completion
;
737 /* used for name server requests in error recovery */
738 struct zfcp_gid_pn_data
{
739 struct zfcp_send_ct ct
;
740 struct scatterlist req
;
741 struct scatterlist resp
;
742 struct ct_iu_gid_pn_req ct_iu_req
;
743 struct ct_iu_gid_pn_resp ct_iu_resp
;
744 struct zfcp_port
*port
;
747 typedef void (*zfcp_send_els_handler_t
)(unsigned long);
750 * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
751 * @adapter: adapter where request is sent from
752 * @d_id: destiniation id of port where request is sent to
753 * @req: scatter-gather list for request
754 * @resp: scatter-gather list for response
755 * @req_count: number of elements in request scatter-gather list
756 * @resp_count: number of elements in response scatter-gather list
757 * @handler: handler function (called for response to the request)
758 * @handler_data: data passed to handler function
759 * @timer: timer (e.g. for request initiated by erp)
760 * @completion: completion for synchronization purposes
761 * @ls_code: hex code of ELS command
762 * @status: used to pass error status to calling function
764 struct zfcp_send_els
{
765 struct zfcp_adapter
*adapter
;
767 struct scatterlist
*req
;
768 struct scatterlist
*resp
;
769 unsigned int req_count
;
770 unsigned int resp_count
;
771 zfcp_send_els_handler_t handler
;
772 unsigned long handler_data
;
773 struct timer_list
*timer
;
774 struct completion
*completion
;
779 struct zfcp_status_read
{
780 struct fsf_status_read_buffer
*buffer
;
783 struct zfcp_fsf_done
{
784 struct completion
*complete
;
788 /* request specific data */
789 union zfcp_req_data
{
790 struct zfcp_exchange_config_data exchange_config_data
;
791 struct zfcp_open_port open_port
;
792 struct zfcp_close_port close_port
;
793 struct zfcp_open_unit open_unit
;
794 struct zfcp_close_unit close_unit
;
795 struct zfcp_close_physical_port close_physical_port
;
796 struct zfcp_send_fcp_command_task send_fcp_command_task
;
797 struct zfcp_send_fcp_command_task_management
798 send_fcp_command_task_management
;
799 struct zfcp_abort_fcp_command abort_fcp_command
;
800 struct zfcp_send_ct
*send_ct
;
801 struct zfcp_send_els
*send_els
;
802 struct zfcp_status_read status_read
;
803 struct fsf_qtcb_bottom_port
*port_data
;
806 struct zfcp_qdio_queue
{
807 struct qdio_buffer
*buffer
[QDIO_MAX_BUFFERS_PER_Q
]; /* SBALs */
808 u8 free_index
; /* index of next free bfr
809 in queue (free_count>0) */
810 atomic_t free_count
; /* number of free buffers
812 rwlock_t queue_lock
; /* lock for operations on queue */
813 int distance_from_int
; /* SBALs used since PCI indication
817 struct zfcp_erp_action
{
818 struct list_head list
;
819 int action
; /* requested action code */
820 struct zfcp_adapter
*adapter
; /* device which should be recovered */
821 struct zfcp_port
*port
;
822 struct zfcp_unit
*unit
;
823 volatile u32 status
; /* recovery status */
824 u32 step
; /* active step of this erp action */
825 struct zfcp_fsf_req
*fsf_req
; /* fsf request currently pending
827 struct timer_list timer
;
831 struct zfcp_adapter
{
832 struct list_head list
; /* list of adapters */
833 atomic_t refcount
; /* reference count */
834 wait_queue_head_t remove_wq
; /* can be used to wait for
835 refcount drop to zero */
836 wwn_t wwnn
; /* WWNN */
837 wwn_t wwpn
; /* WWPN */
838 fc_id_t s_id
; /* N_Port ID */
839 wwn_t peer_wwnn
; /* P2P peer WWNN */
840 wwn_t peer_wwpn
; /* P2P peer WWPN */
841 fc_id_t peer_d_id
; /* P2P peer D_ID */
842 struct ccw_device
*ccw_device
; /* S/390 ccw device */
844 u32 fc_topology
; /* FC topology */
845 u32 fc_link_speed
; /* FC interface speed */
846 u32 hydra_version
; /* Hydra version */
848 u32 supported_features
;/* of FCP channel */
849 u32 hardware_version
; /* of FCP channel */
850 u8 serial_number
[32]; /* of hardware */
851 struct Scsi_Host
*scsi_host
; /* Pointer to mid-layer */
852 unsigned short scsi_host_no
; /* Assigned host number */
853 unsigned char name
[9];
854 struct list_head port_list_head
; /* remote port list */
855 struct list_head port_remove_lh
; /* head of ports to be
857 u32 ports
; /* number of remote ports */
858 struct timer_list scsi_er_timer
; /* SCSI err recovery watch */
859 struct list_head fsf_req_list_head
; /* head of FSF req list */
860 rwlock_t fsf_req_list_lock
; /* lock for ops on list of
862 atomic_t fsf_reqs_active
; /* # active FSF reqs */
863 struct zfcp_qdio_queue request_queue
; /* request queue */
864 u32 fsf_req_seq_no
; /* FSF cmnd seq number */
865 wait_queue_head_t request_wq
; /* can be used to wait for
866 more avaliable SBALs */
867 struct zfcp_qdio_queue response_queue
; /* response queue */
868 rwlock_t abort_lock
; /* Protects against SCSI
871 u16 status_read_failed
; /* # failed status reads */
872 atomic_t status
; /* status of this adapter */
873 struct list_head erp_ready_head
; /* error recovery for this
875 struct list_head erp_running_head
;
877 struct semaphore erp_ready_sem
;
878 wait_queue_head_t erp_thread_wqh
;
879 wait_queue_head_t erp_done_wqh
;
880 struct zfcp_erp_action erp_action
; /* pending error recovery */
881 atomic_t erp_counter
;
882 u32 erp_total_count
; /* total nr of enqueued erp
884 u32 erp_low_mem_count
; /* nr of erp actions waiting
886 struct zfcp_port
*nameserver_port
; /* adapter's nameserver */
887 debug_info_t
*erp_dbf
; /* S/390 debug features */
888 debug_info_t
*abort_dbf
;
889 debug_info_t
*in_els_dbf
;
890 debug_info_t
*cmd_dbf
;
892 struct zfcp_adapter_mempool pool
; /* Adapter memory pools */
893 struct qdio_initialize qdio_init_data
; /* for qdio_establish */
894 struct device generic_services
; /* directory for WKA ports */
898 * the struct device sysfs_device must be at the beginning of this structure.
899 * pointer to struct device is used to free port structure in release function
900 * of the device. don't change!
903 struct device sysfs_device
; /* sysfs device */
904 struct list_head list
; /* list of remote ports */
905 atomic_t refcount
; /* reference count */
906 wait_queue_head_t remove_wq
; /* can be used to wait for
907 refcount drop to zero */
908 struct zfcp_adapter
*adapter
; /* adapter used to access port */
909 struct list_head unit_list_head
; /* head of logical unit list */
910 struct list_head unit_remove_lh
; /* head of luns to be removed
912 u32 units
; /* # of logical units in list */
913 atomic_t status
; /* status of this remote port */
914 scsi_id_t scsi_id
; /* own SCSI ID */
915 wwn_t wwnn
; /* WWNN if known */
916 wwn_t wwpn
; /* WWPN */
917 fc_id_t d_id
; /* D_ID */
918 u32 handle
; /* handle assigned by FSF */
919 struct zfcp_erp_action erp_action
; /* pending error recovery */
920 atomic_t erp_counter
;
923 /* the struct device sysfs_device must be at the beginning of this structure.
924 * pointer to struct device is used to free unit structure in release function
925 * of the device. don't change!
928 struct device sysfs_device
; /* sysfs device */
929 struct list_head list
; /* list of logical units */
930 atomic_t refcount
; /* reference count */
931 wait_queue_head_t remove_wq
; /* can be used to wait for
932 refcount drop to zero */
933 struct zfcp_port
*port
; /* remote port of unit */
934 atomic_t status
; /* status of this logical unit */
935 scsi_lun_t scsi_lun
; /* own SCSI LUN */
936 fcp_lun_t fcp_lun
; /* own FCP_LUN */
937 u32 handle
; /* handle assigned by FSF */
938 struct scsi_device
*device
; /* scsi device struct pointer */
939 struct zfcp_erp_action erp_action
; /* pending error recovery */
940 atomic_t erp_counter
;
944 struct zfcp_fsf_req
{
945 struct list_head list
; /* list of FSF requests */
946 struct zfcp_adapter
*adapter
; /* adapter request belongs to */
947 u8 sbal_number
; /* nr of SBALs free for use */
948 u8 sbal_first
; /* first SBAL for this request */
949 u8 sbal_last
; /* last possible SBAL for
951 u8 sbal_curr
; /* current SBAL during creation
953 u8 sbale_curr
; /* current SBALE during creation
955 wait_queue_head_t completion_wq
; /* can be used by a routine
956 to wait for completion */
957 volatile u32 status
; /* status of this request */
958 u32 fsf_command
; /* FSF Command copy */
959 struct fsf_qtcb
*qtcb
; /* address of associated QTCB */
960 u32 seq_no
; /* Sequence number of request */
961 union zfcp_req_data data
; /* Info fields of request */
962 struct zfcp_erp_action
*erp_action
; /* used if this request is
963 issued on behalf of erp */
964 mempool_t
*pool
; /* used if request was alloacted
965 from emergency pool */
968 typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req
*);
972 struct scsi_host_template scsi_host_template
;
973 atomic_t status
; /* Module status flags */
974 struct list_head adapter_list_head
; /* head of adapter list */
975 struct list_head adapter_remove_lh
; /* head of adapters to be
977 rwlock_t status_read_lock
; /* for status read thread */
978 struct list_head status_read_receive_head
;
979 struct list_head status_read_send_head
;
980 struct semaphore status_read_sema
;
981 wait_queue_head_t status_read_thread_wqh
;
982 u32 adapters
; /* # of adapters in list */
983 rwlock_t config_lock
; /* serialises changes
986 struct semaphore config_sema
; /* serialises configuration
988 atomic_t loglevel
; /* current loglevel */
989 char init_busid
[BUS_ID_SIZE
];
991 fcp_lun_t init_fcp_lun
;
992 char *driver_version
;
996 * struct zfcp_sg_list - struct describing a scatter-gather list
997 * @sg: pointer to array of (struct scatterlist)
998 * @count: number of elements in scatter-gather list
1000 struct zfcp_sg_list
{
1001 struct scatterlist
*sg
;
1005 /* number of elements for various memory pools */
1006 #define ZFCP_POOL_FSF_REQ_ERP_NR 1
1007 #define ZFCP_POOL_FSF_REQ_SCSI_NR 1
1008 #define ZFCP_POOL_FSF_REQ_ABORT_NR 1
1009 #define ZFCP_POOL_STATUS_READ_NR ZFCP_STATUS_READS_RECOM
1010 #define ZFCP_POOL_DATA_GID_PN_NR 1
1012 /* struct used by memory pools for fsf_requests */
1013 struct zfcp_fsf_req_pool_element
{
1014 struct zfcp_fsf_req fsf_req
;
1015 struct fsf_qtcb qtcb
;
1018 /********************** ZFCP SPECIFIC DEFINES ********************************/
1020 #define ZFCP_FSFREQ_CLEANUP_TIMEOUT HZ/10
1022 #define ZFCP_KNOWN 0x00000001
1023 #define ZFCP_REQ_AUTO_CLEANUP 0x00000002
1024 #define ZFCP_WAIT_FOR_SBAL 0x00000004
1025 #define ZFCP_REQ_NO_QTCB 0x00000008
1027 #define ZFCP_SET 0x00000100
1028 #define ZFCP_CLEAR 0x00000200
1030 #define ZFCP_INTERRUPTIBLE 1
1031 #define ZFCP_UNINTERRUPTIBLE 0
1033 #ifndef atomic_test_mask
1034 #define atomic_test_mask(mask, target) \
1035 ((atomic_read(target) & mask) == mask)
1038 extern void _zfcp_hex_dump(char *, int);
1039 #define ZFCP_HEX_DUMP(level, addr, count) \
1040 if (ZFCP_LOG_CHECK(level)) { \
1041 _zfcp_hex_dump(addr, count); \
1044 #define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
1045 #define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
1046 #define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
1049 * functions needed for reference/usage counting
1053 zfcp_unit_get(struct zfcp_unit
*unit
)
1055 atomic_inc(&unit
->refcount
);
1059 zfcp_unit_put(struct zfcp_unit
*unit
)
1061 if (atomic_dec_return(&unit
->refcount
) == 0)
1062 wake_up(&unit
->remove_wq
);
1066 zfcp_unit_wait(struct zfcp_unit
*unit
)
1068 wait_event(unit
->remove_wq
, atomic_read(&unit
->refcount
) == 0);
1072 zfcp_port_get(struct zfcp_port
*port
)
1074 atomic_inc(&port
->refcount
);
1078 zfcp_port_put(struct zfcp_port
*port
)
1080 if (atomic_dec_return(&port
->refcount
) == 0)
1081 wake_up(&port
->remove_wq
);
1085 zfcp_port_wait(struct zfcp_port
*port
)
1087 wait_event(port
->remove_wq
, atomic_read(&port
->refcount
) == 0);
1091 zfcp_adapter_get(struct zfcp_adapter
*adapter
)
1093 atomic_inc(&adapter
->refcount
);
1097 zfcp_adapter_put(struct zfcp_adapter
*adapter
)
1099 if (atomic_dec_return(&adapter
->refcount
) == 0)
1100 wake_up(&adapter
->remove_wq
);
1104 zfcp_adapter_wait(struct zfcp_adapter
*adapter
)
1106 wait_event(adapter
->remove_wq
, atomic_read(&adapter
->refcount
) == 0);
1109 #endif /* ZFCP_DEF_H */