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/scatterlist.h>
38 #include <linux/ioctl.h>
39 #include <scsi/scsi.h>
40 #include <scsi/scsi_tcq.h>
41 #include <scsi/scsi_cmnd.h>
42 #include <scsi/scsi_device.h>
43 #include <scsi/scsi_host.h>
44 #include <scsi/scsi_transport.h>
45 #include <scsi/scsi_transport_fc.h>
46 #include <asm/ccwdev.h>
48 #include <asm/debug.h>
49 #include <asm/ebcdic.h>
54 /********************* GENERAL DEFINES *********************************/
56 /* zfcp version number, it consists of major, minor, and patch-level number */
57 #define ZFCP_VERSION "4.8.0"
60 * zfcp_sg_to_address - determine kernel address from struct scatterlist
61 * @list: struct scatterlist
62 * Return: kernel address
65 zfcp_sg_to_address(struct scatterlist
*list
)
71 * zfcp_address_to_sg - set up struct scatterlist from kernel address
72 * @address: kernel address
73 * @list: struct scatterlist
77 zfcp_address_to_sg(void *address
, struct scatterlist
*list
, unsigned int size
)
79 sg_set_buf(list
, address
, size
);
82 #define REQUEST_LIST_SIZE 128
84 /********************* SCSI SPECIFIC DEFINES *********************************/
85 #define ZFCP_SCSI_ER_TIMEOUT (10*HZ)
87 /********************* CIO/QDIO SPECIFIC DEFINES *****************************/
89 /* Adapter Identification Parameters */
90 #define ZFCP_CONTROL_UNIT_TYPE 0x1731
91 #define ZFCP_CONTROL_UNIT_MODEL 0x03
92 #define ZFCP_DEVICE_TYPE 0x1732
93 #define ZFCP_DEVICE_MODEL 0x03
94 #define ZFCP_DEVICE_MODEL_PRIV 0x04
96 /* allow as many chained SBALs as are supported by hardware */
97 #define ZFCP_MAX_SBALS_PER_REQ FSF_MAX_SBALS_PER_REQ
98 #define ZFCP_MAX_SBALS_PER_CT_REQ FSF_MAX_SBALS_PER_REQ
99 #define ZFCP_MAX_SBALS_PER_ELS_REQ FSF_MAX_SBALS_PER_ELS_REQ
101 /* DMQ bug workaround: don't use last SBALE */
102 #define ZFCP_MAX_SBALES_PER_SBAL (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
104 /* index of last SBALE (with respect to DMQ bug workaround) */
105 #define ZFCP_LAST_SBALE_PER_SBAL (ZFCP_MAX_SBALES_PER_SBAL - 1)
107 /* max. number of (data buffer) SBALEs in largest SBAL chain */
108 #define ZFCP_MAX_SBALES_PER_REQ \
109 (ZFCP_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
110 /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
112 #define ZFCP_MAX_SECTORS (ZFCP_MAX_SBALES_PER_REQ * 8)
113 /* max. number of (data buffer) SBALEs in largest SBAL chain
114 multiplied with number of sectors per 4k block */
116 /* FIXME(tune): free space should be one max. SBAL chain plus what? */
117 #define ZFCP_QDIO_PCI_INTERVAL (QDIO_MAX_BUFFERS_PER_Q \
118 - (ZFCP_MAX_SBALS_PER_REQ + 4))
120 #define ZFCP_SBAL_TIMEOUT (5*HZ)
122 #define ZFCP_TYPE2_RECOVERY_TIME 8 /* seconds */
124 /* queue polling (values in microseconds) */
125 #define ZFCP_MAX_INPUT_THRESHOLD 5000 /* FIXME: tune */
126 #define ZFCP_MAX_OUTPUT_THRESHOLD 1000 /* FIXME: tune */
127 #define ZFCP_MIN_INPUT_THRESHOLD 1 /* ignored by QDIO layer */
128 #define ZFCP_MIN_OUTPUT_THRESHOLD 1 /* ignored by QDIO layer */
130 #define QDIO_SCSI_QFMT 1 /* 1 for FSF */
131 #define QBUFF_PER_PAGE (PAGE_SIZE / sizeof(struct qdio_buffer))
133 /********************* FSF SPECIFIC DEFINES *********************************/
135 #define ZFCP_ULP_INFO_VERSION 26
136 #define ZFCP_QTCB_VERSION FSF_QTCB_CURRENT_VERSION
137 /* ATTENTION: value must not be used by hardware */
138 #define FSF_QTCB_UNSOLICITED_STATUS 0x6305
139 #define ZFCP_STATUS_READ_FAILED_THRESHOLD 3
140 #define ZFCP_STATUS_READS_RECOM FSF_STATUS_READS_RECOM
142 /* Do 1st retry in 1 second, then double the timeout for each following retry */
143 #define ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP 1
144 #define ZFCP_EXCHANGE_CONFIG_DATA_RETRIES 7
146 /* timeout value for "default timer" for fsf requests */
147 #define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ)
149 /*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
151 typedef unsigned long long wwn_t
;
152 typedef unsigned long long fcp_lun_t
;
153 /* data length field may be at variable position in FCP-2 FCP_CMND IU */
154 typedef unsigned int fcp_dl_t
;
156 #define ZFCP_FC_SERVICE_CLASS_DEFAULT FSF_CLASS_3
158 /* timeout for name-server lookup (in seconds) */
159 #define ZFCP_NS_GID_PN_TIMEOUT 10
161 /* largest SCSI command we can process */
162 /* FCP-2 (FCP_CMND IU) allows up to (255-3+16) */
163 #define ZFCP_MAX_SCSI_CMND_LENGTH 255
164 /* maximum number of commands in LUN queue (tagged queueing) */
165 #define ZFCP_CMND_PER_LUN 32
167 /* task attribute values in FCP-2 FCP_CMND IU */
174 /* task management flags in FCP-2 FCP_CMND IU */
175 #define FCP_CLEAR_ACA 0x40
176 #define FCP_TARGET_RESET 0x20
177 #define FCP_LOGICAL_UNIT_RESET 0x10
178 #define FCP_CLEAR_TASK_SET 0x04
179 #define FCP_ABORT_TASK_SET 0x02
181 #define FCP_CDB_LENGTH 16
183 #define ZFCP_DID_MASK 0x00FFFFFF
185 /* FCP(-2) FCP_CMND IU */
187 fcp_lun_t fcp_lun
; /* FCP logical unit number */
188 u8 crn
; /* command reference number */
189 u8 reserved0
:5; /* reserved */
190 u8 task_attribute
:3; /* task attribute */
191 u8 task_management_flags
; /* task management flags */
192 u8 add_fcp_cdb_length
:6; /* additional FCP_CDB length */
193 u8 rddata
:1; /* read data */
194 u8 wddata
:1; /* write data */
195 u8 fcp_cdb
[FCP_CDB_LENGTH
];
196 } __attribute__((packed
));
198 /* FCP(-2) FCP_RSP IU */
205 u8 fcp_resid_under
:1;
207 u8 fcp_sns_len_valid
:1;
208 u8 fcp_rsp_len_valid
:1;
216 } __attribute__((packed
));
219 #define RSP_CODE_GOOD 0
220 #define RSP_CODE_LENGTH_MISMATCH 1
221 #define RSP_CODE_FIELD_INVALID 2
222 #define RSP_CODE_RO_MISMATCH 3
223 #define RSP_CODE_TASKMAN_UNSUPP 4
224 #define RSP_CODE_TASKMAN_FAILED 5
227 #define LS_RSCN 0x61040000
228 #define LS_LOGO 0x05000000
229 #define LS_PLOGI 0x03000000
231 struct fcp_rscn_head
{
233 u8 page_length
; /* always 0x04 */
235 } __attribute__((packed
));
237 struct fcp_rscn_element
{
242 } __attribute__((packed
));
244 #define ZFCP_PORT_ADDRESS 0x0
245 #define ZFCP_AREA_ADDRESS 0x1
246 #define ZFCP_DOMAIN_ADDRESS 0x2
247 #define ZFCP_FABRIC_ADDRESS 0x3
249 #define ZFCP_PORTS_RANGE_PORT 0xFFFFFF
250 #define ZFCP_PORTS_RANGE_AREA 0xFFFF00
251 #define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
252 #define ZFCP_PORTS_RANGE_FABRIC 0x000000
254 #define ZFCP_NO_PORTS_PER_AREA 0x100
255 #define ZFCP_NO_PORTS_PER_DOMAIN 0x10000
256 #define ZFCP_NO_PORTS_PER_FABRIC 0x1000000
263 } __attribute__((packed
));
268 #define R_A_TOV 10 /* seconds */
269 #define ZFCP_ELS_TIMEOUT (2 * R_A_TOV)
271 #define ZFCP_LS_RLS 0x0f
272 #define ZFCP_LS_ADISC 0x52
273 #define ZFCP_LS_RPS 0x56
274 #define ZFCP_LS_RSCN 0x61
275 #define ZFCP_LS_RNID 0x78
277 struct zfcp_ls_rjt_par
{
282 } __attribute__ ((packed
));
284 struct zfcp_ls_adisc
{
291 } __attribute__ ((packed
));
293 struct zfcp_ls_adisc_acc
{
300 } __attribute__ ((packed
));
302 struct zfcp_rc_entry
{
304 const char *description
;
310 #define ZFCP_CT_REVISION 0x01
311 #define ZFCP_CT_DIRECTORY_SERVICE 0xFC
312 #define ZFCP_CT_NAME_SERVER 0x02
313 #define ZFCP_CT_SYNCHRONOUS 0x00
314 #define ZFCP_CT_GID_PN 0x0121
315 #define ZFCP_CT_MAX_SIZE 0x1020
316 #define ZFCP_CT_ACCEPT 0x8002
317 #define ZFCP_CT_REJECT 0x8001
322 #define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
324 /******************** LOGGING MACROS AND DEFINES *****************************/
327 * Logging may be applied on certain kinds of driver operations
328 * independently. Additionally, different log-levels are supported for
329 * each of these areas.
332 #define ZFCP_NAME "zfcp"
334 /* independent log areas */
335 #define ZFCP_LOG_AREA_OTHER 0
336 #define ZFCP_LOG_AREA_SCSI 1
337 #define ZFCP_LOG_AREA_FSF 2
338 #define ZFCP_LOG_AREA_CONFIG 3
339 #define ZFCP_LOG_AREA_CIO 4
340 #define ZFCP_LOG_AREA_QDIO 5
341 #define ZFCP_LOG_AREA_ERP 6
342 #define ZFCP_LOG_AREA_FC 7
344 /* log level values*/
345 #define ZFCP_LOG_LEVEL_NORMAL 0
346 #define ZFCP_LOG_LEVEL_INFO 1
347 #define ZFCP_LOG_LEVEL_DEBUG 2
348 #define ZFCP_LOG_LEVEL_TRACE 3
351 * this allows removal of logging code by the preprocessor
352 * (the most detailed log level still to be compiled in is specified,
353 * higher log levels are removed)
355 #define ZFCP_LOG_LEVEL_LIMIT ZFCP_LOG_LEVEL_TRACE
357 /* get "loglevel" nibble assignment */
358 #define ZFCP_GET_LOG_VALUE(zfcp_lognibble) \
359 ((atomic_read(&zfcp_data.loglevel) >> (zfcp_lognibble<<2)) & 0xF)
361 /* set "loglevel" nibble */
362 #define ZFCP_SET_LOG_NIBBLE(value, zfcp_lognibble) \
363 (value << (zfcp_lognibble << 2))
365 /* all log-level defaults are combined to generate initial log-level */
366 #define ZFCP_LOG_LEVEL_DEFAULTS \
367 (ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_OTHER) | \
368 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_SCSI) | \
369 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FSF) | \
370 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CONFIG) | \
371 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CIO) | \
372 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_QDIO) | \
373 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_ERP) | \
374 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FC))
376 /* check whether we have the right level for logging */
377 #define ZFCP_LOG_CHECK(level) \
378 ((ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA)) >= level)
380 /* logging routine for zfcp */
381 #define _ZFCP_LOG(fmt, args...) \
382 printk(KERN_ERR ZFCP_NAME": %s(%d): " fmt, __func__, \
385 #define ZFCP_LOG(level, fmt, args...) \
387 if (ZFCP_LOG_CHECK(level)) \
388 _ZFCP_LOG(fmt, ##args); \
391 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_NORMAL
392 # define ZFCP_LOG_NORMAL(fmt, args...) do { } while (0)
394 # define ZFCP_LOG_NORMAL(fmt, args...) \
396 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_NORMAL)) \
397 printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
401 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_INFO
402 # define ZFCP_LOG_INFO(fmt, args...) do { } while (0)
404 # define ZFCP_LOG_INFO(fmt, args...) \
406 if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_INFO)) \
407 printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
411 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_DEBUG
412 # define ZFCP_LOG_DEBUG(fmt, args...) do { } while (0)
414 # define ZFCP_LOG_DEBUG(fmt, args...) \
415 ZFCP_LOG(ZFCP_LOG_LEVEL_DEBUG, fmt , ##args)
418 #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_TRACE
419 # define ZFCP_LOG_TRACE(fmt, args...) do { } while (0)
421 # define ZFCP_LOG_TRACE(fmt, args...) \
422 ZFCP_LOG(ZFCP_LOG_LEVEL_TRACE, fmt , ##args)
425 /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
428 * Note, the leftmost status byte is common among adapter, port
431 #define ZFCP_COMMON_FLAGS 0xfff00000
433 /* common status bits */
434 #define ZFCP_STATUS_COMMON_REMOVE 0x80000000
435 #define ZFCP_STATUS_COMMON_RUNNING 0x40000000
436 #define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
437 #define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
438 #define ZFCP_STATUS_COMMON_OPENING 0x08000000
439 #define ZFCP_STATUS_COMMON_OPEN 0x04000000
440 #define ZFCP_STATUS_COMMON_CLOSING 0x02000000
441 #define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
442 #define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
443 #define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
446 #define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
447 #define ZFCP_STATUS_ADAPTER_REGISTERED 0x00000004
448 #define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
449 #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
450 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
451 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
452 #define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
453 #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
454 #define ZFCP_STATUS_ADAPTER_XPORT_OK 0x00000800
456 /* FC-PH/FC-GS well-known address identifiers for generic services */
457 #define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA
458 #define ZFCP_DID_TIME_SERVICE 0xFFFFFB
459 #define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC
460 #define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8
461 #define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7
463 /* remote port status */
464 #define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
465 #define ZFCP_STATUS_PORT_DID_DID 0x00000002
466 #define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
467 #define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
468 #define ZFCP_STATUS_PORT_NO_SCSI_ID 0x00000010
469 #define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
471 /* for ports with well known addresses */
472 #define ZFCP_STATUS_PORT_WKA \
473 (ZFCP_STATUS_PORT_NO_WWPN | \
474 ZFCP_STATUS_PORT_NO_SCSI_ID)
476 /* logical unit status */
477 #define ZFCP_STATUS_UNIT_TEMPORARY 0x00000002
478 #define ZFCP_STATUS_UNIT_SHARED 0x00000004
479 #define ZFCP_STATUS_UNIT_READONLY 0x00000008
480 #define ZFCP_STATUS_UNIT_REGISTERED 0x00000010
481 #define ZFCP_STATUS_UNIT_SCSI_WORK_PENDING 0x00000020
483 /* FSF request status (this does not have a common part) */
484 #define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000
485 #define ZFCP_STATUS_FSFREQ_POOL 0x00000001
486 #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
487 #define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
488 #define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
489 #define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
490 #define ZFCP_STATUS_FSFREQ_ABORTING 0x00000020
491 #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
492 #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
493 #define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
494 #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
495 #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
496 #define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
497 #define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
499 /*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
501 #define ZFCP_MAX_ERPS 3
503 #define ZFCP_ERP_FSFREQ_TIMEOUT (30 * HZ)
504 #define ZFCP_ERP_MEMWAIT_TIMEOUT HZ
506 #define ZFCP_STATUS_ERP_TIMEDOUT 0x10000000
507 #define ZFCP_STATUS_ERP_CLOSE_ONLY 0x01000000
508 #define ZFCP_STATUS_ERP_DISMISSING 0x00100000
509 #define ZFCP_STATUS_ERP_DISMISSED 0x00200000
510 #define ZFCP_STATUS_ERP_LOWMEM 0x00400000
512 #define ZFCP_ERP_STEP_UNINITIALIZED 0x00000000
513 #define ZFCP_ERP_STEP_FSF_XCONFIG 0x00000001
514 #define ZFCP_ERP_STEP_PHYS_PORT_CLOSING 0x00000010
515 #define ZFCP_ERP_STEP_PORT_CLOSING 0x00000100
516 #define ZFCP_ERP_STEP_NAMESERVER_OPEN 0x00000200
517 #define ZFCP_ERP_STEP_NAMESERVER_LOOKUP 0x00000400
518 #define ZFCP_ERP_STEP_PORT_OPENING 0x00000800
519 #define ZFCP_ERP_STEP_UNIT_CLOSING 0x00001000
520 #define ZFCP_ERP_STEP_UNIT_OPENING 0x00002000
522 /* Ordered by escalation level (necessary for proper erp-code operation) */
523 #define ZFCP_ERP_ACTION_REOPEN_ADAPTER 0x4
524 #define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED 0x3
525 #define ZFCP_ERP_ACTION_REOPEN_PORT 0x2
526 #define ZFCP_ERP_ACTION_REOPEN_UNIT 0x1
528 #define ZFCP_ERP_ACTION_RUNNING 0x1
529 #define ZFCP_ERP_ACTION_READY 0x2
531 #define ZFCP_ERP_SUCCEEDED 0x0
532 #define ZFCP_ERP_FAILED 0x1
533 #define ZFCP_ERP_CONTINUES 0x2
534 #define ZFCP_ERP_EXIT 0x3
535 #define ZFCP_ERP_DISMISSED 0x4
536 #define ZFCP_ERP_NOMEM 0x5
539 /******************** CFDC SPECIFIC STUFF *****************************/
541 /* Firewall data channel sense data record */
542 struct zfcp_cfdc_sense_data
{
543 u32 signature
; /* Request signature */
544 u32 devno
; /* FCP adapter device number */
545 u32 command
; /* Command code */
546 u32 fsf_status
; /* FSF request status and status qualifier */
547 u8 fsf_status_qual
[FSF_STATUS_QUALIFIER_SIZE
];
548 u8 payloads
[256]; /* Access conflicts list */
549 u8 control_file
[0]; /* Access control table */
552 #define ZFCP_CFDC_SIGNATURE 0xCFDCACDF
554 #define ZFCP_CFDC_CMND_DOWNLOAD_NORMAL 0x00010001
555 #define ZFCP_CFDC_CMND_DOWNLOAD_FORCE 0x00010101
556 #define ZFCP_CFDC_CMND_FULL_ACCESS 0x00000201
557 #define ZFCP_CFDC_CMND_RESTRICTED_ACCESS 0x00000401
558 #define ZFCP_CFDC_CMND_UPLOAD 0x00010002
560 #define ZFCP_CFDC_DOWNLOAD 0x00000001
561 #define ZFCP_CFDC_UPLOAD 0x00000002
562 #define ZFCP_CFDC_WITH_CONTROL_FILE 0x00010000
564 #define ZFCP_CFDC_DEV_NAME "zfcp_cfdc"
565 #define ZFCP_CFDC_DEV_MAJOR MISC_MAJOR
566 #define ZFCP_CFDC_DEV_MINOR MISC_DYNAMIC_MINOR
568 #define ZFCP_CFDC_MAX_CONTROL_FILE_SIZE 127 * 1024
570 /************************* STRUCTURE DEFINITIONS *****************************/
574 /* holds various memory pools of an adapter */
575 struct zfcp_adapter_mempool
{
576 mempool_t
*fsf_req_erp
;
577 mempool_t
*fsf_req_scsi
;
578 mempool_t
*fsf_req_abort
;
579 mempool_t
*fsf_req_status_read
;
580 mempool_t
*data_status_read
;
581 mempool_t
*data_gid_pn
;
590 u8 gs_type
; // 0xFC Directory Service
591 u8 gs_subtype
; // 0x02 Name Server
592 u8 options
; // 0x00 single bidirectional exchange
594 u16 cmd_rsp_code
; // 0x0121 GID_PN, or 0x0100 GA_NXT
595 u16 max_res_size
; // <= (4096 - 16) / 4
600 } __attribute__ ((packed
));
602 /* nameserver request CT_IU -- for requests where
603 * a port name is required */
604 struct ct_iu_gid_pn_req
{
605 struct ct_hdr header
;
607 } __attribute__ ((packed
));
609 /* FS_ACC IU and data unit for GID_PN nameserver request */
610 struct ct_iu_gid_pn_resp
{
611 struct ct_hdr header
;
613 } __attribute__ ((packed
));
615 typedef void (*zfcp_send_ct_handler_t
)(unsigned long);
618 * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
619 * @port: port where the request is sent to
620 * @req: scatter-gather list for request
621 * @resp: scatter-gather list for response
622 * @req_count: number of elements in request scatter-gather list
623 * @resp_count: number of elements in response scatter-gather list
624 * @handler: handler function (called for response to the request)
625 * @handler_data: data passed to handler function
626 * @pool: pointer to memory pool for ct request structure
627 * @timeout: FSF timeout for this request
628 * @completion: completion for synchronization purposes
629 * @status: used to pass error status to calling function
631 struct zfcp_send_ct
{
632 struct zfcp_port
*port
;
633 struct scatterlist
*req
;
634 struct scatterlist
*resp
;
635 unsigned int req_count
;
636 unsigned int resp_count
;
637 zfcp_send_ct_handler_t handler
;
638 unsigned long handler_data
;
641 struct completion
*completion
;
645 /* used for name server requests in error recovery */
646 struct zfcp_gid_pn_data
{
647 struct zfcp_send_ct ct
;
648 struct scatterlist req
;
649 struct scatterlist resp
;
650 struct ct_iu_gid_pn_req ct_iu_req
;
651 struct ct_iu_gid_pn_resp ct_iu_resp
;
652 struct zfcp_port
*port
;
655 typedef void (*zfcp_send_els_handler_t
)(unsigned long);
658 * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
659 * @adapter: adapter where request is sent from
660 * @port: port where ELS is destinated (port reference count has to be increased)
661 * @d_id: destiniation id of port where request is sent to
662 * @req: scatter-gather list for request
663 * @resp: scatter-gather list for response
664 * @req_count: number of elements in request scatter-gather list
665 * @resp_count: number of elements in response scatter-gather list
666 * @handler: handler function (called for response to the request)
667 * @handler_data: data passed to handler function
668 * @completion: completion for synchronization purposes
669 * @ls_code: hex code of ELS command
670 * @status: used to pass error status to calling function
672 struct zfcp_send_els
{
673 struct zfcp_adapter
*adapter
;
674 struct zfcp_port
*port
;
676 struct scatterlist
*req
;
677 struct scatterlist
*resp
;
678 unsigned int req_count
;
679 unsigned int resp_count
;
680 zfcp_send_els_handler_t handler
;
681 unsigned long handler_data
;
682 struct completion
*completion
;
687 struct zfcp_qdio_queue
{
688 struct qdio_buffer
*buffer
[QDIO_MAX_BUFFERS_PER_Q
]; /* SBALs */
689 u8 free_index
; /* index of next free bfr
690 in queue (free_count>0) */
691 atomic_t free_count
; /* number of free buffers
693 rwlock_t queue_lock
; /* lock for operations on queue */
694 int distance_from_int
; /* SBALs used since PCI indication
698 struct zfcp_erp_action
{
699 struct list_head list
;
700 int action
; /* requested action code */
701 struct zfcp_adapter
*adapter
; /* device which should be recovered */
702 struct zfcp_port
*port
;
703 struct zfcp_unit
*unit
;
704 volatile u32 status
; /* recovery status */
705 u32 step
; /* active step of this erp action */
706 struct zfcp_fsf_req
*fsf_req
; /* fsf request currently pending
708 struct timer_list timer
;
712 struct zfcp_adapter
{
713 struct list_head list
; /* list of adapters */
714 atomic_t refcount
; /* reference count */
715 wait_queue_head_t remove_wq
; /* can be used to wait for
716 refcount drop to zero */
717 wwn_t peer_wwnn
; /* P2P peer WWNN */
718 wwn_t peer_wwpn
; /* P2P peer WWPN */
719 u32 peer_d_id
; /* P2P peer D_ID */
720 struct ccw_device
*ccw_device
; /* S/390 ccw device */
721 u32 hydra_version
; /* Hydra version */
723 u32 adapter_features
; /* FCP channel features */
724 u32 connection_features
; /* host connection features */
725 u32 hardware_version
; /* of FCP channel */
726 struct Scsi_Host
*scsi_host
; /* Pointer to mid-layer */
727 struct list_head port_list_head
; /* remote port list */
728 struct list_head port_remove_lh
; /* head of ports to be
730 u32 ports
; /* number of remote ports */
731 atomic_t reqs_active
; /* # active FSF reqs */
732 unsigned long req_no
; /* unique FSF req number */
733 struct list_head
*req_list
; /* list of pending reqs */
734 spinlock_t req_list_lock
; /* request list lock */
735 struct zfcp_qdio_queue request_queue
; /* request queue */
736 u32 fsf_req_seq_no
; /* FSF cmnd seq number */
737 wait_queue_head_t request_wq
; /* can be used to wait for
738 more avaliable SBALs */
739 struct zfcp_qdio_queue response_queue
; /* response queue */
740 rwlock_t abort_lock
; /* Protects against SCSI
743 u16 status_read_failed
; /* # failed status reads */
744 atomic_t status
; /* status of this adapter */
745 struct list_head erp_ready_head
; /* error recovery for this
747 struct list_head erp_running_head
;
749 struct semaphore erp_ready_sem
;
750 wait_queue_head_t erp_thread_wqh
;
751 wait_queue_head_t erp_done_wqh
;
752 struct zfcp_erp_action erp_action
; /* pending error recovery */
753 atomic_t erp_counter
;
754 u32 erp_total_count
; /* total nr of enqueued erp
756 u32 erp_low_mem_count
; /* nr of erp actions waiting
758 struct zfcp_port
*nameserver_port
; /* adapter's nameserver */
759 debug_info_t
*rec_dbf
;
760 debug_info_t
*hba_dbf
;
761 debug_info_t
*san_dbf
; /* debug feature areas */
762 debug_info_t
*scsi_dbf
;
763 spinlock_t rec_dbf_lock
;
764 spinlock_t hba_dbf_lock
;
765 spinlock_t san_dbf_lock
;
766 spinlock_t scsi_dbf_lock
;
767 struct zfcp_rec_dbf_record rec_dbf_buf
;
768 struct zfcp_hba_dbf_record hba_dbf_buf
;
769 struct zfcp_san_dbf_record san_dbf_buf
;
770 struct zfcp_scsi_dbf_record scsi_dbf_buf
;
771 struct zfcp_adapter_mempool pool
; /* Adapter memory pools */
772 struct qdio_initialize qdio_init_data
; /* for qdio_establish */
773 struct device generic_services
; /* directory for WKA ports */
774 struct fc_host_statistics
*fc_stats
;
775 struct fsf_qtcb_bottom_port
*stats_reset_data
;
776 unsigned long stats_reset
;
780 * the struct device sysfs_device must be at the beginning of this structure.
781 * pointer to struct device is used to free port structure in release function
782 * of the device. don't change!
785 struct device sysfs_device
; /* sysfs device */
786 struct fc_rport
*rport
; /* rport of fc transport class */
787 struct list_head list
; /* list of remote ports */
788 atomic_t refcount
; /* reference count */
789 wait_queue_head_t remove_wq
; /* can be used to wait for
790 refcount drop to zero */
791 struct zfcp_adapter
*adapter
; /* adapter used to access port */
792 struct list_head unit_list_head
; /* head of logical unit list */
793 struct list_head unit_remove_lh
; /* head of luns to be removed
795 u32 units
; /* # of logical units in list */
796 atomic_t status
; /* status of this remote port */
797 wwn_t wwnn
; /* WWNN if known */
798 wwn_t wwpn
; /* WWPN */
800 u32 handle
; /* handle assigned by FSF */
801 struct zfcp_erp_action erp_action
; /* pending error recovery */
802 atomic_t erp_counter
;
804 u32 supported_classes
;
807 /* the struct device sysfs_device must be at the beginning of this structure.
808 * pointer to struct device is used to free unit structure in release function
809 * of the device. don't change!
812 struct device sysfs_device
; /* sysfs device */
813 struct list_head list
; /* list of logical units */
814 atomic_t refcount
; /* reference count */
815 wait_queue_head_t remove_wq
; /* can be used to wait for
816 refcount drop to zero */
817 struct zfcp_port
*port
; /* remote port of unit */
818 atomic_t status
; /* status of this logical unit */
819 unsigned int scsi_lun
; /* own SCSI LUN */
820 fcp_lun_t fcp_lun
; /* own FCP_LUN */
821 u32 handle
; /* handle assigned by FSF */
822 struct scsi_device
*device
; /* scsi device struct pointer */
823 struct zfcp_erp_action erp_action
; /* pending error recovery */
824 atomic_t erp_counter
;
828 struct zfcp_fsf_req
{
829 struct list_head list
; /* list of FSF requests */
830 unsigned long req_id
; /* unique request ID */
831 struct zfcp_adapter
*adapter
; /* adapter request belongs to */
832 u8 sbal_number
; /* nr of SBALs free for use */
833 u8 sbal_first
; /* first SBAL for this request */
834 u8 sbal_last
; /* last possible SBAL for
836 u8 sbal_curr
; /* current SBAL during creation
838 u8 sbale_curr
; /* current SBALE during creation
840 wait_queue_head_t completion_wq
; /* can be used by a routine
841 to wait for completion */
842 volatile u32 status
; /* status of this request */
843 u32 fsf_command
; /* FSF Command copy */
844 struct fsf_qtcb
*qtcb
; /* address of associated QTCB */
845 u32 seq_no
; /* Sequence number of request */
846 unsigned long data
; /* private data of request */
847 struct timer_list timer
; /* used for erp or scsi er */
848 struct zfcp_erp_action
*erp_action
; /* used if this request is
849 issued on behalf of erp */
850 mempool_t
*pool
; /* used if request was alloacted
851 from emergency pool */
852 unsigned long long issued
; /* request sent time (STCK) */
853 struct zfcp_unit
*unit
;
856 typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req
*);
860 struct scsi_host_template scsi_host_template
;
861 struct scsi_transport_template
*scsi_transport_template
;
862 atomic_t status
; /* Module status flags */
863 struct list_head adapter_list_head
; /* head of adapter list */
864 struct list_head adapter_remove_lh
; /* head of adapters to be
866 u32 adapters
; /* # of adapters in list */
867 rwlock_t config_lock
; /* serialises changes
870 struct semaphore config_sema
; /* serialises configuration
872 atomic_t loglevel
; /* current loglevel */
873 char init_busid
[BUS_ID_SIZE
];
875 fcp_lun_t init_fcp_lun
;
876 char *driver_version
;
877 struct kmem_cache
*fsf_req_qtcb_cache
;
878 struct kmem_cache
*sr_buffer_cache
;
879 struct kmem_cache
*gid_pn_cache
;
883 * struct zfcp_sg_list - struct describing a scatter-gather list
884 * @sg: pointer to array of (struct scatterlist)
885 * @count: number of elements in scatter-gather list
887 struct zfcp_sg_list
{
888 struct scatterlist
*sg
;
892 /* number of elements for various memory pools */
893 #define ZFCP_POOL_FSF_REQ_ERP_NR 1
894 #define ZFCP_POOL_FSF_REQ_SCSI_NR 1
895 #define ZFCP_POOL_FSF_REQ_ABORT_NR 1
896 #define ZFCP_POOL_STATUS_READ_NR ZFCP_STATUS_READS_RECOM
897 #define ZFCP_POOL_DATA_GID_PN_NR 1
899 /* struct used by memory pools for fsf_requests */
900 struct zfcp_fsf_req_qtcb
{
901 struct zfcp_fsf_req fsf_req
;
902 struct fsf_qtcb qtcb
;
905 /********************** ZFCP SPECIFIC DEFINES ********************************/
907 #define ZFCP_REQ_AUTO_CLEANUP 0x00000002
908 #define ZFCP_WAIT_FOR_SBAL 0x00000004
909 #define ZFCP_REQ_NO_QTCB 0x00000008
911 #define ZFCP_SET 0x00000100
912 #define ZFCP_CLEAR 0x00000200
914 #ifndef atomic_test_mask
915 #define atomic_test_mask(mask, target) \
916 ((atomic_read(target) & mask) == mask)
919 extern void _zfcp_hex_dump(char *, int);
920 #define ZFCP_HEX_DUMP(level, addr, count) \
921 if (ZFCP_LOG_CHECK(level)) { \
922 _zfcp_hex_dump(addr, count); \
925 #define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
926 #define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
927 #define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
930 * Helper functions for request ID management.
932 static inline int zfcp_reqlist_hash(unsigned long req_id
)
934 return req_id
% REQUEST_LIST_SIZE
;
937 static inline void zfcp_reqlist_add(struct zfcp_adapter
*adapter
,
938 struct zfcp_fsf_req
*fsf_req
)
942 idx
= zfcp_reqlist_hash(fsf_req
->req_id
);
943 list_add_tail(&fsf_req
->list
, &adapter
->req_list
[idx
]);
946 static inline void zfcp_reqlist_remove(struct zfcp_adapter
*adapter
,
947 struct zfcp_fsf_req
*fsf_req
)
949 list_del(&fsf_req
->list
);
952 static inline struct zfcp_fsf_req
*
953 zfcp_reqlist_find(struct zfcp_adapter
*adapter
, unsigned long req_id
)
955 struct zfcp_fsf_req
*request
;
958 idx
= zfcp_reqlist_hash(req_id
);
959 list_for_each_entry(request
, &adapter
->req_list
[idx
], list
)
960 if (request
->req_id
== req_id
)
965 static inline struct zfcp_fsf_req
*
966 zfcp_reqlist_find_safe(struct zfcp_adapter
*adapter
, struct zfcp_fsf_req
*req
)
968 struct zfcp_fsf_req
*request
;
971 for (idx
= 0; idx
< REQUEST_LIST_SIZE
; idx
++) {
972 list_for_each_entry(request
, &adapter
->req_list
[idx
], list
)
980 * functions needed for reference/usage counting
984 zfcp_unit_get(struct zfcp_unit
*unit
)
986 atomic_inc(&unit
->refcount
);
990 zfcp_unit_put(struct zfcp_unit
*unit
)
992 if (atomic_dec_return(&unit
->refcount
) == 0)
993 wake_up(&unit
->remove_wq
);
997 zfcp_unit_wait(struct zfcp_unit
*unit
)
999 wait_event(unit
->remove_wq
, atomic_read(&unit
->refcount
) == 0);
1003 zfcp_port_get(struct zfcp_port
*port
)
1005 atomic_inc(&port
->refcount
);
1009 zfcp_port_put(struct zfcp_port
*port
)
1011 if (atomic_dec_return(&port
->refcount
) == 0)
1012 wake_up(&port
->remove_wq
);
1016 zfcp_port_wait(struct zfcp_port
*port
)
1018 wait_event(port
->remove_wq
, atomic_read(&port
->refcount
) == 0);
1022 zfcp_adapter_get(struct zfcp_adapter
*adapter
)
1024 atomic_inc(&adapter
->refcount
);
1028 zfcp_adapter_put(struct zfcp_adapter
*adapter
)
1030 if (atomic_dec_return(&adapter
->refcount
) == 0)
1031 wake_up(&adapter
->remove_wq
);
1035 zfcp_adapter_wait(struct zfcp_adapter
*adapter
)
1037 wait_event(adapter
->remove_wq
, atomic_read(&adapter
->refcount
) == 0);
1040 #endif /* ZFCP_DEF_H */