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>
64 #include <linux/ioctl32.h>
66 /************************ DEBUG FLAGS *****************************************/
68 #define ZFCP_PRINT_FLAGS
70 /********************* GENERAL DEFINES *********************************/
72 /* zfcp version number, it consists of major, minor, and patch-level number */
73 #define ZFCP_VERSION "4.2.0"
76 * zfcp_sg_to_address - determine kernel address from struct scatterlist
77 * @list: struct scatterlist
78 * Return: kernel address
81 zfcp_sg_to_address(struct scatterlist
*list
)
83 return (void *) (page_address(list
->page
) + list
->offset
);
87 * zfcp_address_to_sg - set up struct scatterlist from kernel address
88 * @address: kernel address
89 * @list: struct scatterlist
92 zfcp_address_to_sg(void *address
, struct scatterlist
*list
)
94 list
->page
= virt_to_page(address
);
95 list
->offset
= ((unsigned long) address
) & (PAGE_SIZE
- 1);
98 /********************* SCSI SPECIFIC DEFINES *********************************/
100 /* 32 bit for SCSI ID and LUN as long as the SCSI stack uses this type */
101 typedef u32 scsi_id_t
;
102 typedef u32 scsi_lun_t
;
104 #define ZFCP_ERP_SCSI_LOW_MEM_TIMEOUT (100*HZ)
105 #define ZFCP_SCSI_ER_TIMEOUT (100*HZ)
107 /********************* CIO/QDIO SPECIFIC DEFINES *****************************/
109 /* Adapter Identification Parameters */
110 #define ZFCP_CONTROL_UNIT_TYPE 0x1731
111 #define ZFCP_CONTROL_UNIT_MODEL 0x03
112 #define ZFCP_DEVICE_TYPE 0x1732
113 #define ZFCP_DEVICE_MODEL 0x03
114 #define ZFCP_DEVICE_MODEL_PRIV 0x04
116 /* allow as many chained SBALs as are supported by hardware */
117 #define ZFCP_MAX_SBALS_PER_REQ FSF_MAX_SBALS_PER_REQ
118 #define ZFCP_MAX_SBALS_PER_CT_REQ FSF_MAX_SBALS_PER_REQ
119 #define ZFCP_MAX_SBALS_PER_ELS_REQ FSF_MAX_SBALS_PER_ELS_REQ
121 /* DMQ bug workaround: don't use last SBALE */
122 #define ZFCP_MAX_SBALES_PER_SBAL (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
124 /* index of last SBALE (with respect to DMQ bug workaround) */
125 #define ZFCP_LAST_SBALE_PER_SBAL (ZFCP_MAX_SBALES_PER_SBAL - 1)
127 /* max. number of (data buffer) SBALEs in largest SBAL chain */
128 #define ZFCP_MAX_SBALES_PER_REQ \
129 (ZFCP_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
130 /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
132 /* FIXME(tune): free space should be one max. SBAL chain plus what? */
133 #define ZFCP_QDIO_PCI_INTERVAL (QDIO_MAX_BUFFERS_PER_Q \
134 - (ZFCP_MAX_SBALS_PER_REQ + 4))
136 #define ZFCP_SBAL_TIMEOUT (5*HZ)
138 #define ZFCP_TYPE2_RECOVERY_TIME (8*HZ)
140 /* queue polling (values in microseconds) */
141 #define ZFCP_MAX_INPUT_THRESHOLD 5000 /* FIXME: tune */
142 #define ZFCP_MAX_OUTPUT_THRESHOLD 1000 /* FIXME: tune */
143 #define ZFCP_MIN_INPUT_THRESHOLD 1 /* ignored by QDIO layer */
144 #define ZFCP_MIN_OUTPUT_THRESHOLD 1 /* ignored by QDIO layer */
146 #define QDIO_SCSI_QFMT 1 /* 1 for FSF */
148 /********************* FSF SPECIFIC DEFINES *********************************/
150 #define ZFCP_ULP_INFO_VERSION 26
151 #define ZFCP_QTCB_VERSION FSF_QTCB_CURRENT_VERSION
152 /* ATTENTION: value must not be used by hardware */
153 #define FSF_QTCB_UNSOLICITED_STATUS 0x6305
154 #define ZFCP_STATUS_READ_FAILED_THRESHOLD 3
155 #define ZFCP_STATUS_READS_RECOM FSF_STATUS_READS_RECOM
156 #define ZFCP_EXCHANGE_CONFIG_DATA_RETRIES 6
157 #define ZFCP_EXCHANGE_CONFIG_DATA_SLEEP 50
159 /* timeout value for "default timer" for fsf requests */
160 #define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ);
162 /*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
164 typedef unsigned long long wwn_t
;
165 typedef unsigned int fc_id_t
;
166 typedef unsigned long long fcp_lun_t
;
167 /* data length field may be at variable position in FCP-2 FCP_CMND IU */
168 typedef unsigned int fcp_dl_t
;
170 #define ZFCP_FC_SERVICE_CLASS_DEFAULT FSF_CLASS_3
172 /* timeout for name-server lookup (in seconds) */
173 #define ZFCP_NS_GID_PN_TIMEOUT 10
175 /* largest SCSI command we can process */
176 /* FCP-2 (FCP_CMND IU) allows up to (255-3+16) */
177 #define ZFCP_MAX_SCSI_CMND_LENGTH 255
178 /* maximum number of commands in LUN queue (tagged queueing) */
179 #define ZFCP_CMND_PER_LUN 32
181 /* task attribute values in FCP-2 FCP_CMND IU */
188 /* task management flags in FCP-2 FCP_CMND IU */
189 #define FCP_CLEAR_ACA 0x40
190 #define FCP_TARGET_RESET 0x20
191 #define FCP_LOGICAL_UNIT_RESET 0x10
192 #define FCP_CLEAR_TASK_SET 0x04
193 #define FCP_ABORT_TASK_SET 0x02
195 #define FCP_CDB_LENGTH 16
197 #define ZFCP_DID_MASK 0x00FFFFFF
199 /* FCP(-2) FCP_CMND IU */
201 fcp_lun_t fcp_lun
; /* FCP logical unit number */
202 u8 crn
; /* command reference number */
203 u8 reserved0
:5; /* reserved */
204 u8 task_attribute
:3; /* task attribute */
205 u8 task_management_flags
; /* task management flags */
206 u8 add_fcp_cdb_length
:6; /* additional FCP_CDB length */
207 u8 rddata
:1; /* read data */
208 u8 wddata
:1; /* write data */
209 u8 fcp_cdb
[FCP_CDB_LENGTH
];
210 } __attribute__((packed
));
212 /* FCP(-2) FCP_RSP IU */
219 u8 fcp_resid_under
:1;
221 u8 fcp_sns_len_valid
:1;
222 u8 fcp_rsp_len_valid
:1;
230 } __attribute__((packed
));
233 #define RSP_CODE_GOOD 0
234 #define RSP_CODE_LENGTH_MISMATCH 1
235 #define RSP_CODE_FIELD_INVALID 2
236 #define RSP_CODE_RO_MISMATCH 3
237 #define RSP_CODE_TASKMAN_UNSUPP 4
238 #define RSP_CODE_TASKMAN_FAILED 5
241 #define LS_FAN 0x60000000
242 #define LS_RSCN 0x61040000
244 struct fcp_rscn_head
{
246 u8 page_length
; /* always 0x04 */
248 } __attribute__((packed
));
250 struct fcp_rscn_element
{
255 } __attribute__((packed
));
257 #define ZFCP_PORT_ADDRESS 0x0
258 #define ZFCP_AREA_ADDRESS 0x1
259 #define ZFCP_DOMAIN_ADDRESS 0x2
260 #define ZFCP_FABRIC_ADDRESS 0x3
262 #define ZFCP_PORTS_RANGE_PORT 0xFFFFFF
263 #define ZFCP_PORTS_RANGE_AREA 0xFFFF00
264 #define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
265 #define ZFCP_PORTS_RANGE_FABRIC 0x000000
267 #define ZFCP_NO_PORTS_PER_AREA 0x100
268 #define ZFCP_NO_PORTS_PER_DOMAIN 0x10000
269 #define ZFCP_NO_PORTS_PER_FABRIC 0x1000000
276 } __attribute__((packed
));
283 } __attribute__((packed
));
288 #define R_A_TOV 10 /* seconds */
289 #define ZFCP_ELS_TIMEOUT (2 * R_A_TOV)
291 #define ZFCP_LS_RLS 0x0f
292 #define ZFCP_LS_ADISC 0x52
293 #define ZFCP_LS_RPS 0x56
294 #define ZFCP_LS_RSCN 0x61
295 #define ZFCP_LS_RNID 0x78
297 struct zfcp_ls_rjt_par
{
302 } __attribute__ ((packed
));
304 struct zfcp_ls_adisc
{
311 } __attribute__ ((packed
));
313 struct zfcp_ls_adisc_acc
{
320 } __attribute__ ((packed
));
322 struct zfcp_rc_entry
{
324 const char *description
;
330 #define ZFCP_CT_REVISION 0x01
331 #define ZFCP_CT_DIRECTORY_SERVICE 0xFC
332 #define ZFCP_CT_NAME_SERVER 0x02
333 #define ZFCP_CT_SYNCHRONOUS 0x00
334 #define ZFCP_CT_GID_PN 0x0121
335 #define ZFCP_CT_MAX_SIZE 0x1020
336 #define ZFCP_CT_ACCEPT 0x8002
337 #define ZFCP_CT_REJECT 0x8001
342 #define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
345 /***************** S390 DEBUG FEATURE SPECIFIC DEFINES ***********************/
347 /* debug feature entries per adapter */
348 #define ZFCP_ERP_DBF_INDEX 1
349 #define ZFCP_ERP_DBF_AREAS 2
350 #define ZFCP_ERP_DBF_LENGTH 16
351 #define ZFCP_ERP_DBF_LEVEL 3
352 #define ZFCP_ERP_DBF_NAME "zfcperp"
354 #define ZFCP_CMD_DBF_INDEX 2
355 #define ZFCP_CMD_DBF_AREAS 1
356 #define ZFCP_CMD_DBF_LENGTH 8
357 #define ZFCP_CMD_DBF_LEVEL 3
358 #define ZFCP_CMD_DBF_NAME "zfcpcmd"
360 #define ZFCP_ABORT_DBF_INDEX 2
361 #define ZFCP_ABORT_DBF_AREAS 1
362 #define ZFCP_ABORT_DBF_LENGTH 8
363 #define ZFCP_ABORT_DBF_LEVEL 6
364 #define ZFCP_ABORT_DBF_NAME "zfcpabt"
366 #define ZFCP_IN_ELS_DBF_INDEX 2
367 #define ZFCP_IN_ELS_DBF_AREAS 1
368 #define ZFCP_IN_ELS_DBF_LENGTH 8
369 #define ZFCP_IN_ELS_DBF_LEVEL 6
370 #define ZFCP_IN_ELS_DBF_NAME "zfcpels"
372 /******************** LOGGING MACROS AND DEFINES *****************************/
375 * Logging may be applied on certain kinds of driver operations
376 * independently. Additionally, different log-levels are supported for
377 * each of these areas.
380 #define ZFCP_NAME "zfcp"
382 /* read-only LUN sharing switch initial value */
383 #define ZFCP_RO_LUN_SHARING_DEFAULTS 0
385 /* independent log areas */
386 #define ZFCP_LOG_AREA_OTHER 0
387 #define ZFCP_LOG_AREA_SCSI 1
388 #define ZFCP_LOG_AREA_FSF 2
389 #define ZFCP_LOG_AREA_CONFIG 3
390 #define ZFCP_LOG_AREA_CIO 4
391 #define ZFCP_LOG_AREA_QDIO 5
392 #define ZFCP_LOG_AREA_ERP 6
393 #define ZFCP_LOG_AREA_FC 7
395 /* log level values*/
396 #define ZFCP_LOG_LEVEL_NORMAL 0
397 #define ZFCP_LOG_LEVEL_INFO 1
398 #define ZFCP_LOG_LEVEL_DEBUG 2
399 #define ZFCP_LOG_LEVEL_TRACE 3
402 * this allows removal of logging code by the preprocessor
403 * (the most detailed log level still to be compiled in is specified,
404 * higher log levels are removed)
406 #define ZFCP_LOG_LEVEL_LIMIT ZFCP_LOG_LEVEL_TRACE
408 /* get "loglevel" nibble assignment */
409 #define ZFCP_GET_LOG_VALUE(zfcp_lognibble) \
410 ((atomic_read(&zfcp_data.loglevel) >> (zfcp_lognibble<<2)) & 0xF)
412 /* set "loglevel" nibble */
413 #define ZFCP_SET_LOG_NIBBLE(value, zfcp_lognibble) \
414 (value << (zfcp_lognibble << 2))
416 /* all log-level defaults are combined to generate initial log-level */
417 #define ZFCP_LOG_LEVEL_DEFAULTS \
418 (ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_OTHER) | \
419 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_SCSI) | \
420 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FSF) | \
421 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CONFIG) | \
422 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CIO) | \
423 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_QDIO) | \
424 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_ERP) | \
425 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FC))
427 /* check whether we have the right level for logging */
428 #define ZFCP_LOG_CHECK(level) \
429 ((ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA)) >= level)
431 /* logging routine for zfcp */
432 #define _ZFCP_LOG(fmt, args...) \
433 printk(KERN_ERR ZFCP_NAME": %s(%d): " fmt, __FUNCTION__, \
436 #define ZFCP_LOG(level, fmt, args...) \
438 if (ZFCP_LOG_CHECK(level)) \
439 _ZFCP_LOG(fmt, ##args); \
442 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_NORMAL
443 # define ZFCP_LOG_NORMAL(fmt, args...)
445 # define ZFCP_LOG_NORMAL(fmt, args...) \
447 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_NORMAL)) \
448 printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
452 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_INFO
453 # define ZFCP_LOG_INFO(fmt, args...)
455 # define ZFCP_LOG_INFO(fmt, args...) \
457 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_INFO)) \
458 printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
462 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_DEBUG
463 # define ZFCP_LOG_DEBUG(fmt, args...)
465 # define ZFCP_LOG_DEBUG(fmt, args...) \
466 ZFCP_LOG(ZFCP_LOG_LEVEL_DEBUG, fmt , ##args)
469 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_TRACE
470 # define ZFCP_LOG_TRACE(fmt, args...)
472 # define ZFCP_LOG_TRACE(fmt, args...) \
473 ZFCP_LOG(ZFCP_LOG_LEVEL_TRACE, fmt , ##args)
476 #ifndef ZFCP_PRINT_FLAGS
477 # define ZFCP_LOG_FLAGS(level, fmt, args...)
479 extern u32 flags_dump
;
480 # define ZFCP_LOG_FLAGS(level, fmt, args...) \
482 if (level <= flags_dump) \
483 _ZFCP_LOG(fmt, ##args); \
487 /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
490 * Note, the leftmost status byte is common among adapter, port
493 #define ZFCP_COMMON_FLAGS 0xfff00000
494 #define ZFCP_SPECIFIC_FLAGS 0x000fffff
496 /* common status bits */
497 #define ZFCP_STATUS_COMMON_REMOVE 0x80000000
498 #define ZFCP_STATUS_COMMON_RUNNING 0x40000000
499 #define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
500 #define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
501 #define ZFCP_STATUS_COMMON_OPENING 0x08000000
502 #define ZFCP_STATUS_COMMON_OPEN 0x04000000
503 #define ZFCP_STATUS_COMMON_CLOSING 0x02000000
504 #define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
505 #define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
508 #define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
509 #define ZFCP_STATUS_ADAPTER_REGISTERED 0x00000004
510 #define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
511 #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
512 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
513 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
514 #define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
515 #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
517 #define ZFCP_STATUS_ADAPTER_SCSI_UP \
518 (ZFCP_STATUS_COMMON_UNBLOCKED | \
519 ZFCP_STATUS_ADAPTER_REGISTERED)
522 /* FC-PH/FC-GS well-known address identifiers for generic services */
523 #define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA
524 #define ZFCP_DID_TIME_SERVICE 0xFFFFFB
525 #define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC
526 #define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8
527 #define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7
529 /* remote port status */
530 #define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
531 #define ZFCP_STATUS_PORT_DID_DID 0x00000002
532 #define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
533 #define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
534 #define ZFCP_STATUS_PORT_NO_SCSI_ID 0x00000010
535 #define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
536 #define ZFCP_STATUS_PORT_ACCESS_DENIED 0x00000040
538 /* for ports with well known addresses */
539 #define ZFCP_STATUS_PORT_WKA \
540 (ZFCP_STATUS_PORT_NO_WWPN | \
541 ZFCP_STATUS_PORT_NO_SCSI_ID)
543 /* logical unit status */
544 #define ZFCP_STATUS_UNIT_NOTSUPPUNITRESET 0x00000001
545 #define ZFCP_STATUS_UNIT_TEMPORARY 0x00000002
546 #define ZFCP_STATUS_UNIT_SHARED 0x00000004
547 #define ZFCP_STATUS_UNIT_READONLY 0x00000008
549 /* FSF request status (this does not have a common part) */
550 #define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000
551 #define ZFCP_STATUS_FSFREQ_POOL 0x00000001
552 #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
553 #define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
554 #define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
555 #define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
556 #define ZFCP_STATUS_FSFREQ_ABORTING 0x00000020
557 #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
558 #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
559 #define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
560 #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
561 #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
562 #define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
563 #define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
565 /*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
567 #define ZFCP_MAX_ERPS 3
569 #define ZFCP_ERP_FSFREQ_TIMEOUT (30 * HZ)
570 #define ZFCP_ERP_MEMWAIT_TIMEOUT HZ
572 #define ZFCP_STATUS_ERP_TIMEDOUT 0x10000000
573 #define ZFCP_STATUS_ERP_CLOSE_ONLY 0x01000000
574 #define ZFCP_STATUS_ERP_DISMISSING 0x00100000
575 #define ZFCP_STATUS_ERP_DISMISSED 0x00200000
576 #define ZFCP_STATUS_ERP_LOWMEM 0x00400000
578 #define ZFCP_ERP_STEP_UNINITIALIZED 0x00000000
579 #define ZFCP_ERP_STEP_FSF_XCONFIG 0x00000001
580 #define ZFCP_ERP_STEP_PHYS_PORT_CLOSING 0x00000010
581 #define ZFCP_ERP_STEP_PORT_CLOSING 0x00000100
582 #define ZFCP_ERP_STEP_NAMESERVER_OPEN 0x00000200
583 #define ZFCP_ERP_STEP_NAMESERVER_LOOKUP 0x00000400
584 #define ZFCP_ERP_STEP_PORT_OPENING 0x00000800
585 #define ZFCP_ERP_STEP_UNIT_CLOSING 0x00001000
586 #define ZFCP_ERP_STEP_UNIT_OPENING 0x00002000
588 /* Ordered by escalation level (necessary for proper erp-code operation) */
589 #define ZFCP_ERP_ACTION_REOPEN_ADAPTER 0x4
590 #define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED 0x3
591 #define ZFCP_ERP_ACTION_REOPEN_PORT 0x2
592 #define ZFCP_ERP_ACTION_REOPEN_UNIT 0x1
594 #define ZFCP_ERP_ACTION_RUNNING 0x1
595 #define ZFCP_ERP_ACTION_READY 0x2
597 #define ZFCP_ERP_SUCCEEDED 0x0
598 #define ZFCP_ERP_FAILED 0x1
599 #define ZFCP_ERP_CONTINUES 0x2
600 #define ZFCP_ERP_EXIT 0x3
601 #define ZFCP_ERP_DISMISSED 0x4
602 #define ZFCP_ERP_NOMEM 0x5
605 /******************** CFDC SPECIFIC STUFF *****************************/
607 /* Firewall data channel sense data record */
608 struct zfcp_cfdc_sense_data
{
609 u32 signature
; /* Request signature */
610 u32 devno
; /* FCP adapter device number */
611 u32 command
; /* Command code */
612 u32 fsf_status
; /* FSF request status and status qualifier */
613 u8 fsf_status_qual
[FSF_STATUS_QUALIFIER_SIZE
];
614 u8 payloads
[256]; /* Access conflicts list */
615 u8 control_file
[0]; /* Access control table */
618 #define ZFCP_CFDC_SIGNATURE 0xCFDCACDF
620 #define ZFCP_CFDC_CMND_DOWNLOAD_NORMAL 0x00010001
621 #define ZFCP_CFDC_CMND_DOWNLOAD_FORCE 0x00010101
622 #define ZFCP_CFDC_CMND_FULL_ACCESS 0x00000201
623 #define ZFCP_CFDC_CMND_RESTRICTED_ACCESS 0x00000401
624 #define ZFCP_CFDC_CMND_UPLOAD 0x00010002
626 #define ZFCP_CFDC_DOWNLOAD 0x00000001
627 #define ZFCP_CFDC_UPLOAD 0x00000002
628 #define ZFCP_CFDC_WITH_CONTROL_FILE 0x00010000
630 #define ZFCP_CFDC_DEV_NAME "zfcp_cfdc"
631 #define ZFCP_CFDC_DEV_MAJOR MISC_MAJOR
632 #define ZFCP_CFDC_DEV_MINOR MISC_DYNAMIC_MINOR
634 #define ZFCP_CFDC_MAX_CONTROL_FILE_SIZE 127 * 1024
636 /************************* STRUCTURE DEFINITIONS *****************************/
640 /* holds various memory pools of an adapter */
641 struct zfcp_adapter_mempool
{
642 mempool_t
*fsf_req_erp
;
643 mempool_t
*fsf_req_scsi
;
644 mempool_t
*fsf_req_abort
;
645 mempool_t
*fsf_req_status_read
;
646 mempool_t
*data_status_read
;
647 mempool_t
*data_gid_pn
;
650 struct zfcp_exchange_config_data
{
653 struct zfcp_open_port
{
654 struct zfcp_port
*port
;
657 struct zfcp_close_port
{
658 struct zfcp_port
*port
;
661 struct zfcp_open_unit
{
662 struct zfcp_unit
*unit
;
665 struct zfcp_close_unit
{
666 struct zfcp_unit
*unit
;
669 struct zfcp_close_physical_port
{
670 struct zfcp_port
*port
;
673 struct zfcp_send_fcp_command_task
{
674 struct zfcp_fsf_req
*fsf_req
;
675 struct zfcp_unit
*unit
;
676 struct scsi_cmnd
*scsi_cmnd
;
677 unsigned long start_jiffies
;
680 struct zfcp_send_fcp_command_task_management
{
681 struct zfcp_unit
*unit
;
684 struct zfcp_abort_fcp_command
{
685 struct zfcp_fsf_req
*fsf_req
;
686 struct zfcp_unit
*unit
;
695 u8 gs_type
; // 0xFC Directory Service
696 u8 gs_subtype
; // 0x02 Name Server
697 u8 options
; // 0x00 single bidirectional exchange
699 u16 cmd_rsp_code
; // 0x0121 GID_PN, or 0x0100 GA_NXT
700 u16 max_res_size
; // <= (4096 - 16) / 4
705 } __attribute__ ((packed
));
707 /* nameserver request CT_IU -- for requests where
708 * a port name is required */
709 struct ct_iu_gid_pn_req
{
710 struct ct_hdr header
;
712 } __attribute__ ((packed
));
714 /* FS_ACC IU and data unit for GID_PN nameserver request */
715 struct ct_iu_gid_pn_resp
{
716 struct ct_hdr header
;
718 } __attribute__ ((packed
));
720 typedef void (*zfcp_send_ct_handler_t
)(unsigned long);
723 * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
724 * @port: port where the request is sent to
725 * @req: scatter-gather list for request
726 * @resp: scatter-gather list for response
727 * @req_count: number of elements in request scatter-gather list
728 * @resp_count: number of elements in response scatter-gather list
729 * @handler: handler function (called for response to the request)
730 * @handler_data: data passed to handler function
731 * @pool: pointer to memory pool for ct request structure
732 * @timeout: FSF timeout for this request
733 * @timer: timer (e.g. for request initiated by erp)
734 * @completion: completion for synchronization purposes
735 * @status: used to pass error status to calling function
737 struct zfcp_send_ct
{
738 struct zfcp_port
*port
;
739 struct scatterlist
*req
;
740 struct scatterlist
*resp
;
741 unsigned int req_count
;
742 unsigned int resp_count
;
743 zfcp_send_ct_handler_t handler
;
744 unsigned long handler_data
;
747 struct timer_list
*timer
;
748 struct completion
*completion
;
752 /* used for name server requests in error recovery */
753 struct zfcp_gid_pn_data
{
754 struct zfcp_send_ct ct
;
755 struct scatterlist req
;
756 struct scatterlist resp
;
757 struct ct_iu_gid_pn_req ct_iu_req
;
758 struct ct_iu_gid_pn_resp ct_iu_resp
;
759 struct zfcp_port
*port
;
762 typedef void (*zfcp_send_els_handler_t
)(unsigned long);
765 * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
766 * @adapter: adapter where request is sent from
767 * @d_id: destiniation id of port where request is sent to
768 * @req: scatter-gather list for request
769 * @resp: scatter-gather list for response
770 * @req_count: number of elements in request scatter-gather list
771 * @resp_count: number of elements in response scatter-gather list
772 * @handler: handler function (called for response to the request)
773 * @handler_data: data passed to handler function
774 * @timer: timer (e.g. for request initiated by erp)
775 * @completion: completion for synchronization purposes
776 * @ls_code: hex code of ELS command
777 * @status: used to pass error status to calling function
779 struct zfcp_send_els
{
780 struct zfcp_adapter
*adapter
;
782 struct scatterlist
*req
;
783 struct scatterlist
*resp
;
784 unsigned int req_count
;
785 unsigned int resp_count
;
786 zfcp_send_els_handler_t handler
;
787 unsigned long handler_data
;
788 struct timer_list
*timer
;
789 struct completion
*completion
;
794 struct zfcp_status_read
{
795 struct fsf_status_read_buffer
*buffer
;
798 struct zfcp_fsf_done
{
799 struct completion
*complete
;
803 /* request specific data */
804 union zfcp_req_data
{
805 struct zfcp_exchange_config_data exchange_config_data
;
806 struct zfcp_open_port open_port
;
807 struct zfcp_close_port close_port
;
808 struct zfcp_open_unit open_unit
;
809 struct zfcp_close_unit close_unit
;
810 struct zfcp_close_physical_port close_physical_port
;
811 struct zfcp_send_fcp_command_task send_fcp_command_task
;
812 struct zfcp_send_fcp_command_task_management
813 send_fcp_command_task_management
;
814 struct zfcp_abort_fcp_command abort_fcp_command
;
815 struct zfcp_send_ct
*send_ct
;
816 struct zfcp_send_els
*send_els
;
817 struct zfcp_status_read status_read
;
818 struct fsf_qtcb_bottom_port
*port_data
;
821 struct zfcp_qdio_queue
{
822 struct qdio_buffer
*buffer
[QDIO_MAX_BUFFERS_PER_Q
]; /* SBALs */
823 u8 free_index
; /* index of next free bfr
824 in queue (free_count>0) */
825 atomic_t free_count
; /* number of free buffers
827 rwlock_t queue_lock
; /* lock for operations on queue */
828 int distance_from_int
; /* SBALs used since PCI indication
832 struct zfcp_erp_action
{
833 struct list_head list
;
834 int action
; /* requested action code */
835 struct zfcp_adapter
*adapter
; /* device which should be recovered */
836 struct zfcp_port
*port
;
837 struct zfcp_unit
*unit
;
838 volatile u32 status
; /* recovery status */
839 u32 step
; /* active step of this erp action */
840 struct zfcp_fsf_req
*fsf_req
; /* fsf request currently pending
842 struct timer_list timer
;
846 struct zfcp_adapter
{
847 struct list_head list
; /* list of adapters */
848 atomic_t refcount
; /* reference count */
849 wait_queue_head_t remove_wq
; /* can be used to wait for
850 refcount drop to zero */
851 wwn_t wwnn
; /* WWNN */
852 wwn_t wwpn
; /* WWPN */
853 fc_id_t s_id
; /* N_Port ID */
854 struct ccw_device
*ccw_device
; /* S/390 ccw device */
856 u32 fc_topology
; /* FC topology */
857 u32 fc_link_speed
; /* FC interface speed */
858 u32 hydra_version
; /* Hydra version */
860 u32 supported_features
;/* of FCP channel */
861 u32 hardware_version
; /* of FCP channel */
862 u8 serial_number
[32]; /* of hardware */
863 struct Scsi_Host
*scsi_host
; /* Pointer to mid-layer */
864 unsigned short scsi_host_no
; /* Assigned host number */
865 unsigned char name
[9];
866 struct list_head port_list_head
; /* remote port list */
867 struct list_head port_remove_lh
; /* head of ports to be
869 u32 ports
; /* number of remote ports */
870 struct timer_list scsi_er_timer
; /* SCSI err recovery watch */
871 struct list_head fsf_req_list_head
; /* head of FSF req list */
872 rwlock_t fsf_req_list_lock
; /* lock for ops on list of
874 atomic_t fsf_reqs_active
; /* # active FSF reqs */
875 struct zfcp_qdio_queue request_queue
; /* request queue */
876 u32 fsf_req_seq_no
; /* FSF cmnd seq number */
877 wait_queue_head_t request_wq
; /* can be used to wait for
878 more avaliable SBALs */
879 struct zfcp_qdio_queue response_queue
; /* response queue */
880 rwlock_t abort_lock
; /* Protects against SCSI
883 u16 status_read_failed
; /* # failed status reads */
884 atomic_t status
; /* status of this adapter */
885 struct list_head erp_ready_head
; /* error recovery for this
887 struct list_head erp_running_head
;
889 struct semaphore erp_ready_sem
;
890 wait_queue_head_t erp_thread_wqh
;
891 wait_queue_head_t erp_done_wqh
;
892 struct zfcp_erp_action erp_action
; /* pending error recovery */
893 atomic_t erp_counter
;
894 u32 erp_total_count
; /* total nr of enqueued erp
896 u32 erp_low_mem_count
; /* nr of erp actions waiting
898 struct zfcp_port
*nameserver_port
; /* adapter's nameserver */
899 debug_info_t
*erp_dbf
; /* S/390 debug features */
900 debug_info_t
*abort_dbf
;
901 debug_info_t
*in_els_dbf
;
902 debug_info_t
*cmd_dbf
;
904 struct zfcp_adapter_mempool pool
; /* Adapter memory pools */
905 struct qdio_initialize qdio_init_data
; /* for qdio_establish */
906 struct device generic_services
; /* directory for WKA ports */
910 * the struct device sysfs_device must be at the beginning of this structure.
911 * pointer to struct device is used to free port structure in release function
912 * of the device. don't change!
915 struct device sysfs_device
; /* sysfs device */
916 struct list_head list
; /* list of remote ports */
917 atomic_t refcount
; /* reference count */
918 wait_queue_head_t remove_wq
; /* can be used to wait for
919 refcount drop to zero */
920 struct zfcp_adapter
*adapter
; /* adapter used to access port */
921 struct list_head unit_list_head
; /* head of logical unit list */
922 struct list_head unit_remove_lh
; /* head of luns to be removed
924 u32 units
; /* # of logical units in list */
925 atomic_t status
; /* status of this remote port */
926 scsi_id_t scsi_id
; /* own SCSI ID */
927 wwn_t wwnn
; /* WWNN if known */
928 wwn_t wwpn
; /* WWPN */
929 fc_id_t d_id
; /* D_ID */
930 u32 handle
; /* handle assigned by FSF */
931 struct zfcp_erp_action erp_action
; /* pending error recovery */
932 atomic_t erp_counter
;
935 /* the struct device sysfs_device must be at the beginning of this structure.
936 * pointer to struct device is used to free unit structure in release function
937 * of the device. don't change!
940 struct device sysfs_device
; /* sysfs device */
941 struct list_head list
; /* list of logical units */
942 atomic_t refcount
; /* reference count */
943 wait_queue_head_t remove_wq
; /* can be used to wait for
944 refcount drop to zero */
945 struct zfcp_port
*port
; /* remote port of unit */
946 atomic_t status
; /* status of this logical unit */
947 scsi_lun_t scsi_lun
; /* own SCSI LUN */
948 fcp_lun_t fcp_lun
; /* own FCP_LUN */
949 u32 handle
; /* handle assigned by FSF */
950 struct scsi_device
*device
; /* scsi device struct pointer */
951 struct zfcp_erp_action erp_action
; /* pending error recovery */
952 atomic_t erp_counter
;
956 struct zfcp_fsf_req
{
957 struct list_head list
; /* list of FSF requests */
958 struct zfcp_adapter
*adapter
; /* adapter request belongs to */
959 u8 sbal_number
; /* nr of SBALs free for use */
960 u8 sbal_first
; /* first SBAL for this request */
961 u8 sbal_last
; /* last possible SBAL for
963 u8 sbal_curr
; /* current SBAL during creation
965 u8 sbale_curr
; /* current SBALE during creation
967 wait_queue_head_t completion_wq
; /* can be used by a routine
968 to wait for completion */
969 volatile u32 status
; /* status of this request */
970 u32 fsf_command
; /* FSF Command copy */
971 struct fsf_qtcb
*qtcb
; /* address of associated QTCB */
972 u32 seq_no
; /* Sequence number of request */
973 union zfcp_req_data data
; /* Info fields of request */
974 struct zfcp_erp_action
*erp_action
; /* used if this request is
975 issued on behalf of erp */
976 mempool_t
*pool
; /* used if request was alloacted
977 from emergency pool */
980 typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req
*);
984 struct scsi_host_template scsi_host_template
;
985 atomic_t status
; /* Module status flags */
986 struct list_head adapter_list_head
; /* head of adapter list */
987 struct list_head adapter_remove_lh
; /* head of adapters to be
989 rwlock_t status_read_lock
; /* for status read thread */
990 struct list_head status_read_receive_head
;
991 struct list_head status_read_send_head
;
992 struct semaphore status_read_sema
;
993 wait_queue_head_t status_read_thread_wqh
;
994 u32 adapters
; /* # of adapters in list */
995 rwlock_t config_lock
; /* serialises changes
998 struct semaphore config_sema
; /* serialises configuration
1000 atomic_t loglevel
; /* current loglevel */
1001 char init_busid
[BUS_ID_SIZE
];
1003 fcp_lun_t init_fcp_lun
;
1004 char *driver_version
;
1008 * struct zfcp_sg_list - struct describing a scatter-gather list
1009 * @sg: pointer to array of (struct scatterlist)
1010 * @count: number of elements in scatter-gather list
1012 struct zfcp_sg_list
{
1013 struct scatterlist
*sg
;
1017 /* number of elements for various memory pools */
1018 #define ZFCP_POOL_FSF_REQ_ERP_NR 1
1019 #define ZFCP_POOL_FSF_REQ_SCSI_NR 1
1020 #define ZFCP_POOL_FSF_REQ_ABORT_NR 1
1021 #define ZFCP_POOL_STATUS_READ_NR ZFCP_STATUS_READS_RECOM
1022 #define ZFCP_POOL_DATA_GID_PN_NR 1
1024 /* struct used by memory pools for fsf_requests */
1025 struct zfcp_fsf_req_pool_element
{
1026 struct zfcp_fsf_req fsf_req
;
1027 struct fsf_qtcb qtcb
;
1030 /********************** ZFCP SPECIFIC DEFINES ********************************/
1032 #define ZFCP_FSFREQ_CLEANUP_TIMEOUT HZ/10
1034 #define ZFCP_KNOWN 0x00000001
1035 #define ZFCP_REQ_AUTO_CLEANUP 0x00000002
1036 #define ZFCP_WAIT_FOR_SBAL 0x00000004
1037 #define ZFCP_REQ_NO_QTCB 0x00000008
1039 #define ZFCP_SET 0x00000100
1040 #define ZFCP_CLEAR 0x00000200
1042 #define ZFCP_INTERRUPTIBLE 1
1043 #define ZFCP_UNINTERRUPTIBLE 0
1045 #ifndef atomic_test_mask
1046 #define atomic_test_mask(mask, target) \
1047 ((atomic_read(target) & mask) == mask)
1050 extern void _zfcp_hex_dump(char *, int);
1051 #define ZFCP_HEX_DUMP(level, addr, count) \
1052 if (ZFCP_LOG_CHECK(level)) { \
1053 _zfcp_hex_dump(addr, count); \
1056 #define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
1057 #define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
1058 #define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
1061 * functions needed for reference/usage counting
1065 zfcp_unit_get(struct zfcp_unit
*unit
)
1067 atomic_inc(&unit
->refcount
);
1071 zfcp_unit_put(struct zfcp_unit
*unit
)
1073 if (atomic_dec_return(&unit
->refcount
) == 0)
1074 wake_up(&unit
->remove_wq
);
1078 zfcp_unit_wait(struct zfcp_unit
*unit
)
1080 wait_event(unit
->remove_wq
, atomic_read(&unit
->refcount
) == 0);
1084 zfcp_port_get(struct zfcp_port
*port
)
1086 atomic_inc(&port
->refcount
);
1090 zfcp_port_put(struct zfcp_port
*port
)
1092 if (atomic_dec_return(&port
->refcount
) == 0)
1093 wake_up(&port
->remove_wq
);
1097 zfcp_port_wait(struct zfcp_port
*port
)
1099 wait_event(port
->remove_wq
, atomic_read(&port
->refcount
) == 0);
1103 zfcp_adapter_get(struct zfcp_adapter
*adapter
)
1105 atomic_inc(&adapter
->refcount
);
1109 zfcp_adapter_put(struct zfcp_adapter
*adapter
)
1111 if (atomic_dec_return(&adapter
->refcount
) == 0)
1112 wake_up(&adapter
->remove_wq
);
1116 zfcp_adapter_wait(struct zfcp_adapter
*adapter
)
1118 wait_event(adapter
->remove_wq
, atomic_read(&adapter
->refcount
) == 0);
1121 #endif /* ZFCP_DEF_H */