4 * Global definitions for the zfcp device driver.
6 * Copyright IBM Corporation 2002, 2009
12 /*************************** INCLUDES *****************************************/
14 #include <linux/init.h>
15 #include <linux/moduleparam.h>
16 #include <linux/major.h>
17 #include <linux/blkdev.h>
18 #include <linux/delay.h>
19 #include <linux/timer.h>
20 #include <linux/slab.h>
21 #include <linux/mempool.h>
22 #include <linux/syscalls.h>
23 #include <linux/scatterlist.h>
24 #include <linux/ioctl.h>
25 #include <scsi/fc/fc_fs.h>
26 #include <scsi/fc/fc_gs.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_tcq.h>
29 #include <scsi/scsi_cmnd.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_transport.h>
33 #include <scsi/scsi_transport_fc.h>
34 #include <scsi/scsi_bsg_fc.h>
35 #include <asm/ccwdev.h>
37 #include <asm/debug.h>
38 #include <asm/ebcdic.h>
39 #include <asm/sysinfo.h>
42 /********************* GENERAL DEFINES *********************************/
44 #define REQUEST_LIST_SIZE 128
46 /********************* SCSI SPECIFIC DEFINES *********************************/
47 #define ZFCP_SCSI_ER_TIMEOUT (10*HZ)
49 /********************* CIO/QDIO SPECIFIC DEFINES *****************************/
51 /* DMQ bug workaround: don't use last SBALE */
52 #define ZFCP_MAX_SBALES_PER_SBAL (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
54 /* index of last SBALE (with respect to DMQ bug workaround) */
55 #define ZFCP_LAST_SBALE_PER_SBAL (ZFCP_MAX_SBALES_PER_SBAL - 1)
57 /* max. number of (data buffer) SBALEs in largest SBAL chain */
58 #define ZFCP_MAX_SBALES_PER_REQ \
59 (FSF_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
60 /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
62 #define ZFCP_MAX_SECTORS (ZFCP_MAX_SBALES_PER_REQ * 8)
63 /* max. number of (data buffer) SBALEs in largest SBAL chain
64 multiplied with number of sectors per 4k block */
66 /********************* FSF SPECIFIC DEFINES *********************************/
68 /* ATTENTION: value must not be used by hardware */
69 #define FSF_QTCB_UNSOLICITED_STATUS 0x6305
71 /* timeout value for "default timer" for fsf requests */
72 #define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ)
74 /*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
76 /* timeout for name-server lookup (in seconds) */
77 #define ZFCP_NS_GID_PN_TIMEOUT 10
79 /* task attribute values in FCP-2 FCP_CMND IU */
86 /* task management flags in FCP-2 FCP_CMND IU */
87 #define FCP_CLEAR_ACA 0x40
88 #define FCP_TARGET_RESET 0x20
89 #define FCP_LOGICAL_UNIT_RESET 0x10
90 #define FCP_CLEAR_TASK_SET 0x04
91 #define FCP_ABORT_TASK_SET 0x02
93 #define FCP_CDB_LENGTH 16
95 #define ZFCP_DID_MASK 0x00FFFFFF
97 /* FCP(-2) FCP_CMND IU */
99 u64 fcp_lun
; /* FCP logical unit number */
100 u8 crn
; /* command reference number */
101 u8 reserved0
:5; /* reserved */
102 u8 task_attribute
:3; /* task attribute */
103 u8 task_management_flags
; /* task management flags */
104 u8 add_fcp_cdb_length
:6; /* additional FCP_CDB length */
105 u8 rddata
:1; /* read data */
106 u8 wddata
:1; /* write data */
107 u8 fcp_cdb
[FCP_CDB_LENGTH
];
108 } __attribute__((packed
));
110 /* FCP(-2) FCP_RSP IU */
117 u8 fcp_resid_under
:1;
119 u8 fcp_sns_len_valid
:1;
120 u8 fcp_rsp_len_valid
:1;
128 } __attribute__((packed
));
131 #define RSP_CODE_GOOD 0
132 #define RSP_CODE_LENGTH_MISMATCH 1
133 #define RSP_CODE_FIELD_INVALID 2
134 #define RSP_CODE_RO_MISMATCH 3
135 #define RSP_CODE_TASKMAN_UNSUPP 4
136 #define RSP_CODE_TASKMAN_FAILED 5
141 #define LS_PLOGI 0x03
143 struct fcp_rscn_head
{
145 u8 page_length
; /* always 0x04 */
147 } __attribute__((packed
));
149 struct fcp_rscn_element
{
154 } __attribute__((packed
));
161 } __attribute__((packed
));
166 #define R_A_TOV 10 /* seconds */
168 #define ZFCP_LS_RLS 0x0f
169 #define ZFCP_LS_ADISC 0x52
170 #define ZFCP_LS_RPS 0x56
171 #define ZFCP_LS_RSCN 0x61
172 #define ZFCP_LS_RNID 0x78
174 struct zfcp_ls_adisc
{
181 } __attribute__ ((packed
));
186 #define ZFCP_CT_REVISION 0x01
187 #define ZFCP_CT_DIRECTORY_SERVICE 0xFC
188 #define ZFCP_CT_NAME_SERVER 0x02
189 #define ZFCP_CT_SYNCHRONOUS 0x00
190 #define ZFCP_CT_SCSI_FCP 0x08
191 #define ZFCP_CT_UNABLE_TO_PERFORM_CMD 0x09
192 #define ZFCP_CT_GID_PN 0x0121
193 #define ZFCP_CT_GPN_FT 0x0172
194 #define ZFCP_CT_ACCEPT 0x8002
195 #define ZFCP_CT_REJECT 0x8001
200 #define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
202 /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
205 * Note, the leftmost status byte is common among adapter, port
208 #define ZFCP_COMMON_FLAGS 0xfff00000
210 /* common status bits */
211 #define ZFCP_STATUS_COMMON_REMOVE 0x80000000
212 #define ZFCP_STATUS_COMMON_RUNNING 0x40000000
213 #define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
214 #define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
215 #define ZFCP_STATUS_COMMON_OPEN 0x04000000
216 #define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
217 #define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
218 #define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
219 #define ZFCP_STATUS_COMMON_NOESC 0x00200000
222 #define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
223 #define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
224 #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
225 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
226 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
227 #define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
228 #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
230 /* FC-PH/FC-GS well-known address identifiers for generic services */
231 #define ZFCP_DID_WKA 0xFFFFF0
233 /* remote port status */
234 #define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
235 #define ZFCP_STATUS_PORT_LINK_TEST 0x00000002
237 /* well known address (WKA) port status*/
238 enum zfcp_wka_status
{
239 ZFCP_WKA_PORT_OFFLINE
,
240 ZFCP_WKA_PORT_CLOSING
,
241 ZFCP_WKA_PORT_OPENING
,
242 ZFCP_WKA_PORT_ONLINE
,
245 /* logical unit status */
246 #define ZFCP_STATUS_UNIT_SHARED 0x00000004
247 #define ZFCP_STATUS_UNIT_READONLY 0x00000008
249 /* FSF request status (this does not have a common part) */
250 #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
251 #define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
252 #define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
253 #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
254 #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
255 #define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
256 #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
257 #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
258 #define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
259 #define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
261 /************************* STRUCTURE DEFINITIONS *****************************/
265 /* holds various memory pools of an adapter */
266 struct zfcp_adapter_mempool
{
268 mempool_t
*gid_pn_req
;
270 mempool_t
*scsi_abort
;
271 mempool_t
*status_read_req
;
272 mempool_t
*status_read_data
;
273 mempool_t
*gid_pn_data
;
274 mempool_t
*qtcb_pool
;
283 u8 gs_type
; // 0xFC Directory Service
284 u8 gs_subtype
; // 0x02 Name Server
285 u8 options
; // 0x00 single bidirectional exchange
287 u16 cmd_rsp_code
; // 0x0121 GID_PN, or 0x0100 GA_NXT
288 u16 max_res_size
; // <= (4096 - 16) / 4
293 } __attribute__ ((packed
));
295 /* nameserver request CT_IU -- for requests where
296 * a port name is required */
297 struct ct_iu_gid_pn_req
{
298 struct ct_hdr header
;
300 } __attribute__ ((packed
));
302 /* FS_ACC IU and data unit for GID_PN nameserver request */
303 struct ct_iu_gid_pn_resp
{
304 struct ct_hdr header
;
306 } __attribute__ ((packed
));
308 struct ct_iu_gpn_ft_req
{
309 struct ct_hdr header
;
314 } __attribute__ ((packed
));
318 * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
319 * @wka_port: port where the request is sent to
320 * @req: scatter-gather list for request
321 * @resp: scatter-gather list for response
322 * @handler: handler function (called for response to the request)
323 * @handler_data: data passed to handler function
324 * @timeout: FSF timeout for this request
325 * @completion: completion for synchronization purposes
326 * @status: used to pass error status to calling function
328 struct zfcp_send_ct
{
329 struct zfcp_wka_port
*wka_port
;
330 struct scatterlist
*req
;
331 struct scatterlist
*resp
;
332 void (*handler
)(unsigned long);
333 unsigned long handler_data
;
335 struct completion
*completion
;
339 /* used for name server requests in error recovery */
340 struct zfcp_gid_pn_data
{
341 struct zfcp_send_ct ct
;
342 struct scatterlist req
;
343 struct scatterlist resp
;
344 struct ct_iu_gid_pn_req ct_iu_req
;
345 struct ct_iu_gid_pn_resp ct_iu_resp
;
346 struct zfcp_port
*port
;
350 * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
351 * @adapter: adapter where request is sent from
352 * @port: port where ELS is destinated (port reference count has to be increased)
353 * @d_id: destiniation id of port where request is sent to
354 * @req: scatter-gather list for request
355 * @resp: scatter-gather list for response
356 * @handler: handler function (called for response to the request)
357 * @handler_data: data passed to handler function
358 * @completion: completion for synchronization purposes
359 * @ls_code: hex code of ELS command
360 * @status: used to pass error status to calling function
362 struct zfcp_send_els
{
363 struct zfcp_adapter
*adapter
;
364 struct zfcp_port
*port
;
366 struct scatterlist
*req
;
367 struct scatterlist
*resp
;
368 void (*handler
)(unsigned long);
369 unsigned long handler_data
;
370 struct completion
*completion
;
375 struct zfcp_wka_port
{
376 struct zfcp_adapter
*adapter
;
377 wait_queue_head_t completion_wq
;
378 enum zfcp_wka_status status
;
383 struct delayed_work work
;
386 struct zfcp_wka_ports
{
387 struct zfcp_wka_port ms
; /* management service */
388 struct zfcp_wka_port ts
; /* time service */
389 struct zfcp_wka_port ds
; /* directory service */
390 struct zfcp_wka_port as
; /* alias service */
391 struct zfcp_wka_port ks
; /* key distribution service */
394 struct zfcp_qdio_queue
{
395 struct qdio_buffer
*sbal
[QDIO_MAX_BUFFERS_PER_Q
];
396 u8 first
; /* index of next free bfr in queue */
397 atomic_t count
; /* number of free buffers in queue */
400 struct zfcp_erp_action
{
401 struct list_head list
;
402 int action
; /* requested action code */
403 struct zfcp_adapter
*adapter
; /* device which should be recovered */
404 struct zfcp_port
*port
;
405 struct zfcp_unit
*unit
;
406 u32 status
; /* recovery status */
407 u32 step
; /* active step of this erp action */
408 struct zfcp_fsf_req
*fsf_req
; /* fsf request currently pending
410 struct timer_list timer
;
413 struct fsf_latency_record
{
419 struct latency_cont
{
420 struct fsf_latency_record channel
;
421 struct fsf_latency_record fabric
;
425 struct zfcp_latencies
{
426 struct latency_cont read
;
427 struct latency_cont write
;
428 struct latency_cont cmd
;
432 /** struct zfcp_qdio - basic QDIO data structure
433 * @resp_q: response queue
434 * @req_q: request queue
435 * @stat_lock: lock to protect req_q_util and req_q_time
436 * @req_q_lock; lock to serialize access to request queue
437 * @req_q_time: time of last fill level change
438 * @req_q_util: used for accounting
439 * @req_q_full: queue full incidents
440 * @req_q_wq: used to wait for SBAL availability
441 * @adapter: adapter used in conjunction with this QDIO structure
444 struct zfcp_qdio_queue resp_q
;
445 struct zfcp_qdio_queue req_q
;
446 spinlock_t stat_lock
;
447 spinlock_t req_q_lock
;
451 wait_queue_head_t req_q_wq
;
452 struct zfcp_adapter
*adapter
;
455 struct zfcp_adapter
{
456 atomic_t refcount
; /* reference count */
457 wait_queue_head_t remove_wq
; /* can be used to wait for
458 refcount drop to zero */
459 u64 peer_wwnn
; /* P2P peer WWNN */
460 u64 peer_wwpn
; /* P2P peer WWPN */
461 u32 peer_d_id
; /* P2P peer D_ID */
462 struct ccw_device
*ccw_device
; /* S/390 ccw device */
463 struct zfcp_qdio
*qdio
;
464 u32 hydra_version
; /* Hydra version */
466 u32 adapter_features
; /* FCP channel features */
467 u32 connection_features
; /* host connection features */
468 u32 hardware_version
; /* of FCP channel */
469 u16 timer_ticks
; /* time int for a tick */
470 struct Scsi_Host
*scsi_host
; /* Pointer to mid-layer */
471 struct list_head port_list_head
; /* remote port list */
472 unsigned long req_no
; /* unique FSF req number */
473 struct list_head
*req_list
; /* list of pending reqs */
474 spinlock_t req_list_lock
; /* request list lock */
475 u32 fsf_req_seq_no
; /* FSF cmnd seq number */
476 rwlock_t abort_lock
; /* Protects against SCSI
479 atomic_t stat_miss
; /* # missing status reads*/
480 struct work_struct stat_work
;
481 atomic_t status
; /* status of this adapter */
482 struct list_head erp_ready_head
; /* error recovery for this
484 struct list_head erp_running_head
;
486 struct semaphore erp_ready_sem
;
487 wait_queue_head_t erp_thread_wqh
;
488 wait_queue_head_t erp_done_wqh
;
489 struct zfcp_erp_action erp_action
; /* pending error recovery */
490 atomic_t erp_counter
;
491 u32 erp_total_count
; /* total nr of enqueued erp
493 u32 erp_low_mem_count
; /* nr of erp actions waiting
495 struct zfcp_wka_ports
*gs
; /* generic services */
496 struct zfcp_dbf
*dbf
; /* debug traces */
497 struct zfcp_adapter_mempool pool
; /* Adapter memory pools */
498 struct fc_host_statistics
*fc_stats
;
499 struct fsf_qtcb_bottom_port
*stats_reset_data
;
500 unsigned long stats_reset
;
501 struct work_struct scan_work
;
502 struct service_level service_level
;
503 struct workqueue_struct
*work_queue
;
507 struct device sysfs_device
; /* sysfs device */
508 struct fc_rport
*rport
; /* rport of fc transport class */
509 struct list_head list
; /* list of remote ports */
510 atomic_t refcount
; /* reference count */
511 wait_queue_head_t remove_wq
; /* can be used to wait for
512 refcount drop to zero */
513 struct zfcp_adapter
*adapter
; /* adapter used to access port */
514 struct list_head unit_list_head
; /* head of logical unit list */
515 atomic_t status
; /* status of this remote port */
516 u64 wwnn
; /* WWNN if known */
519 u32 handle
; /* handle assigned by FSF */
520 struct zfcp_erp_action erp_action
; /* pending error recovery */
521 atomic_t erp_counter
;
523 u32 supported_classes
;
524 struct work_struct gid_pn_work
;
525 struct work_struct test_link_work
;
526 struct work_struct rport_work
;
527 enum { RPORT_NONE
, RPORT_ADD
, RPORT_DEL
} rport_task
;
531 struct device sysfs_device
; /* sysfs device */
532 struct list_head list
; /* list of logical units */
533 atomic_t refcount
; /* reference count */
534 wait_queue_head_t remove_wq
; /* can be used to wait for
535 refcount drop to zero */
536 struct zfcp_port
*port
; /* remote port of unit */
537 atomic_t status
; /* status of this logical unit */
538 u64 fcp_lun
; /* own FCP_LUN */
539 u32 handle
; /* handle assigned by FSF */
540 struct scsi_device
*device
; /* scsi device struct pointer */
541 struct zfcp_erp_action erp_action
; /* pending error recovery */
542 atomic_t erp_counter
;
543 struct zfcp_latencies latencies
;
544 struct work_struct scsi_work
;
548 * struct zfcp_queue_req - queue related values for a request
549 * @sbal_number: number of free SBALs
550 * @sbal_first: first SBAL for this request
551 * @sbal_last: last SBAL for this request
552 * @sbal_limit: last possible SBAL for this request
553 * @sbale_curr: current SBALE at creation of this request
554 * @sbal_response: SBAL used in interrupt
555 * @qdio_outb_usage: usage of outbound queue
556 * @qdio_inb_usage: usage of inbound queue
558 struct zfcp_queue_req
{
570 * struct zfcp_fsf_req - basic FSF request structure
571 * @list: list of FSF requests
572 * @req_id: unique request ID
573 * @adapter: adapter this request belongs to
574 * @queue_req: queue related values
575 * @completion: used to signal the completion of the request
576 * @status: status of the request
577 * @fsf_command: FSF command issued
578 * @qtcb: associated QTCB
579 * @seq_no: sequence number of this request
580 * @data: private data
581 * @timer: timer data of this request
582 * @erp_action: reference to erp action if request issued on behalf of ERP
583 * @pool: reference to memory pool if used for this request
584 * @issued: time when request was send (STCK)
585 * @unit: reference to unit if this request is a SCSI request
586 * @handler: handler which should be called to process response
588 struct zfcp_fsf_req
{
589 struct list_head list
;
590 unsigned long req_id
;
591 struct zfcp_adapter
*adapter
;
592 struct zfcp_queue_req queue_req
;
593 struct completion completion
;
596 struct fsf_qtcb
*qtcb
;
599 struct timer_list timer
;
600 struct zfcp_erp_action
*erp_action
;
602 unsigned long long issued
;
603 struct zfcp_unit
*unit
;
604 void (*handler
)(struct zfcp_fsf_req
*);
609 struct scsi_host_template scsi_host_template
;
610 struct scsi_transport_template
*scsi_transport_template
;
611 rwlock_t config_lock
; /* serialises changes
614 struct semaphore config_sema
; /* serialises configuration
616 struct kmem_cache
*gpn_ft_cache
;
617 struct kmem_cache
*qtcb_cache
;
618 struct kmem_cache
*sr_buffer_cache
;
619 struct kmem_cache
*gid_pn_cache
;
622 /********************** ZFCP SPECIFIC DEFINES ********************************/
624 #define ZFCP_SET 0x00000100
625 #define ZFCP_CLEAR 0x00000200
628 * Helper functions for request ID management.
630 static inline int zfcp_reqlist_hash(unsigned long req_id
)
632 return req_id
% REQUEST_LIST_SIZE
;
635 static inline void zfcp_reqlist_remove(struct zfcp_adapter
*adapter
,
636 struct zfcp_fsf_req
*fsf_req
)
638 list_del(&fsf_req
->list
);
641 static inline struct zfcp_fsf_req
*
642 zfcp_reqlist_find(struct zfcp_adapter
*adapter
, unsigned long req_id
)
644 struct zfcp_fsf_req
*request
;
647 idx
= zfcp_reqlist_hash(req_id
);
648 list_for_each_entry(request
, &adapter
->req_list
[idx
], list
)
649 if (request
->req_id
== req_id
)
654 static inline struct zfcp_fsf_req
*
655 zfcp_reqlist_find_safe(struct zfcp_adapter
*adapter
, struct zfcp_fsf_req
*req
)
657 struct zfcp_fsf_req
*request
;
660 for (idx
= 0; idx
< REQUEST_LIST_SIZE
; idx
++) {
661 list_for_each_entry(request
, &adapter
->req_list
[idx
], list
)
669 * functions needed for reference/usage counting
673 zfcp_unit_get(struct zfcp_unit
*unit
)
675 atomic_inc(&unit
->refcount
);
679 zfcp_unit_put(struct zfcp_unit
*unit
)
681 if (atomic_dec_return(&unit
->refcount
) == 0)
682 wake_up(&unit
->remove_wq
);
686 zfcp_port_get(struct zfcp_port
*port
)
688 atomic_inc(&port
->refcount
);
692 zfcp_port_put(struct zfcp_port
*port
)
694 if (atomic_dec_return(&port
->refcount
) == 0)
695 wake_up(&port
->remove_wq
);
699 zfcp_adapter_get(struct zfcp_adapter
*adapter
)
701 atomic_inc(&adapter
->refcount
);
705 zfcp_adapter_put(struct zfcp_adapter
*adapter
)
707 if (atomic_dec_return(&adapter
->refcount
) == 0)
708 wake_up(&adapter
->remove_wq
);
711 #endif /* ZFCP_DEF_H */