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/scsi.h>
26 #include <scsi/scsi_tcq.h>
27 #include <scsi/scsi_cmnd.h>
28 #include <scsi/scsi_device.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_transport.h>
31 #include <scsi/scsi_transport_fc.h>
32 #include <asm/ccwdev.h>
34 #include <asm/debug.h>
35 #include <asm/ebcdic.h>
36 #include <asm/sysinfo.h>
41 /********************* GENERAL DEFINES *********************************/
43 #define REQUEST_LIST_SIZE 128
45 /********************* SCSI SPECIFIC DEFINES *********************************/
46 #define ZFCP_SCSI_ER_TIMEOUT (10*HZ)
48 /********************* CIO/QDIO SPECIFIC DEFINES *****************************/
50 /* Adapter Identification Parameters */
51 #define ZFCP_CONTROL_UNIT_TYPE 0x1731
52 #define ZFCP_CONTROL_UNIT_MODEL 0x03
53 #define ZFCP_DEVICE_TYPE 0x1732
54 #define ZFCP_DEVICE_MODEL 0x03
55 #define ZFCP_DEVICE_MODEL_PRIV 0x04
57 /* DMQ bug workaround: don't use last SBALE */
58 #define ZFCP_MAX_SBALES_PER_SBAL (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
60 /* index of last SBALE (with respect to DMQ bug workaround) */
61 #define ZFCP_LAST_SBALE_PER_SBAL (ZFCP_MAX_SBALES_PER_SBAL - 1)
63 /* max. number of (data buffer) SBALEs in largest SBAL chain */
64 #define ZFCP_MAX_SBALES_PER_REQ \
65 (FSF_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
66 /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
68 #define ZFCP_MAX_SECTORS (ZFCP_MAX_SBALES_PER_REQ * 8)
69 /* max. number of (data buffer) SBALEs in largest SBAL chain
70 multiplied with number of sectors per 4k block */
72 /********************* FSF SPECIFIC DEFINES *********************************/
74 /* ATTENTION: value must not be used by hardware */
75 #define FSF_QTCB_UNSOLICITED_STATUS 0x6305
77 /* timeout value for "default timer" for fsf requests */
78 #define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ)
80 /*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
82 /* timeout for name-server lookup (in seconds) */
83 #define ZFCP_NS_GID_PN_TIMEOUT 10
85 /* task attribute values in FCP-2 FCP_CMND IU */
92 /* task management flags in FCP-2 FCP_CMND IU */
93 #define FCP_CLEAR_ACA 0x40
94 #define FCP_TARGET_RESET 0x20
95 #define FCP_LOGICAL_UNIT_RESET 0x10
96 #define FCP_CLEAR_TASK_SET 0x04
97 #define FCP_ABORT_TASK_SET 0x02
99 #define FCP_CDB_LENGTH 16
101 #define ZFCP_DID_MASK 0x00FFFFFF
103 /* FCP(-2) FCP_CMND IU */
105 u64 fcp_lun; /* FCP logical unit number */
106 u8 crn; /* command reference number */
107 u8 reserved0:5; /* reserved */
108 u8 task_attribute:3; /* task attribute */
109 u8 task_management_flags; /* task management flags */
110 u8 add_fcp_cdb_length:6; /* additional FCP_CDB length */
111 u8 rddata:1; /* read data */
112 u8 wddata:1; /* write data */
113 u8 fcp_cdb[FCP_CDB_LENGTH];
114 } __attribute__((packed));
116 /* FCP(-2) FCP_RSP IU */
123 u8 fcp_resid_under:1;
125 u8 fcp_sns_len_valid:1;
126 u8 fcp_rsp_len_valid:1;
134 } __attribute__((packed));
137 #define RSP_CODE_GOOD 0
138 #define RSP_CODE_LENGTH_MISMATCH 1
139 #define RSP_CODE_FIELD_INVALID 2
140 #define RSP_CODE_RO_MISMATCH 3
141 #define RSP_CODE_TASKMAN_UNSUPP 4
142 #define RSP_CODE_TASKMAN_FAILED 5
147 #define LS_PLOGI 0x03
149 struct fcp_rscn_head {
151 u8 page_length; /* always 0x04 */
153 } __attribute__((packed));
155 struct fcp_rscn_element {
160 } __attribute__((packed));
167 } __attribute__((packed));
172 #define R_A_TOV 10 /* seconds */
174 #define ZFCP_LS_RLS 0x0f
175 #define ZFCP_LS_ADISC 0x52
176 #define ZFCP_LS_RPS 0x56
177 #define ZFCP_LS_RSCN 0x61
178 #define ZFCP_LS_RNID 0x78
180 struct zfcp_ls_adisc {
187 } __attribute__ ((packed));
192 #define ZFCP_CT_REVISION 0x01
193 #define ZFCP_CT_DIRECTORY_SERVICE 0xFC
194 #define ZFCP_CT_NAME_SERVER 0x02
195 #define ZFCP_CT_SYNCHRONOUS 0x00
196 #define ZFCP_CT_SCSI_FCP 0x08
197 #define ZFCP_CT_UNABLE_TO_PERFORM_CMD 0x09
198 #define ZFCP_CT_GID_PN 0x0121
199 #define ZFCP_CT_GPN_FT 0x0172
200 #define ZFCP_CT_ACCEPT 0x8002
201 #define ZFCP_CT_REJECT 0x8001
206 #define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
208 /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
211 * Note, the leftmost status byte is common among adapter, port
214 #define ZFCP_COMMON_FLAGS 0xfff00000
216 /* common status bits */
217 #define ZFCP_STATUS_COMMON_REMOVE 0x80000000
218 #define ZFCP_STATUS_COMMON_RUNNING 0x40000000
219 #define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
220 #define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
221 #define ZFCP_STATUS_COMMON_OPEN 0x04000000
222 #define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
223 #define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
224 #define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
225 #define ZFCP_STATUS_COMMON_NOESC 0x00200000
228 #define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
229 #define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
230 #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
231 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
232 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
233 #define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
234 #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
236 /* FC-PH/FC-GS well-known address identifiers for generic services */
237 #define ZFCP_DID_WKA 0xFFFFF0
238 #define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA
239 #define ZFCP_DID_TIME_SERVICE 0xFFFFFB
240 #define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC
241 #define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8
242 #define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7
244 /* remote port status */
245 #define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
247 /* well known address (WKA) port status*/
248 enum zfcp_wka_status {
249 ZFCP_WKA_PORT_OFFLINE,
250 ZFCP_WKA_PORT_CLOSING,
251 ZFCP_WKA_PORT_OPENING,
252 ZFCP_WKA_PORT_ONLINE,
255 /* logical unit status */
256 #define ZFCP_STATUS_UNIT_SHARED 0x00000004
257 #define ZFCP_STATUS_UNIT_READONLY 0x00000008
259 /* FSF request status (this does not have a common part) */
260 #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
261 #define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
262 #define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
263 #define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
264 #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
265 #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
266 #define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
267 #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
268 #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
269 #define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
270 #define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
272 /************************* STRUCTURE DEFINITIONS *****************************/
276 /* holds various memory pools of an adapter */
277 struct zfcp_adapter_mempool {
278 mempool_t *fsf_req_erp;
279 mempool_t *fsf_req_scsi;
280 mempool_t *fsf_req_abort;
281 mempool_t *fsf_req_status_read;
282 mempool_t *data_status_read;
283 mempool_t *data_gid_pn;
292 u8 gs_type; // 0xFC Directory Service
293 u8 gs_subtype; // 0x02 Name Server
294 u8 options; // 0x00 single bidirectional exchange
296 u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT
297 u16 max_res_size; // <= (4096 - 16) / 4
302 } __attribute__ ((packed));
304 /* nameserver request CT_IU -- for requests where
305 * a port name is required */
306 struct ct_iu_gid_pn_req {
307 struct ct_hdr header;
309 } __attribute__ ((packed));
311 /* FS_ACC IU and data unit for GID_PN nameserver request */
312 struct ct_iu_gid_pn_resp {
313 struct ct_hdr header;
315 } __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_qdio_queue {
387 struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q];
388 u8 first; /* index of next free bfr in queue */
389 atomic_t count; /* number of free buffers in queue */
392 struct zfcp_erp_action {
393 struct list_head list;
394 int action; /* requested action code */
395 struct zfcp_adapter *adapter; /* device which should be recovered */
396 struct zfcp_port *port;
397 struct zfcp_unit *unit;
398 u32 status; /* recovery status */
399 u32 step; /* active step of this erp action */
400 struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
402 struct timer_list timer;
405 struct fsf_latency_record {
411 struct latency_cont {
412 struct fsf_latency_record channel;
413 struct fsf_latency_record fabric;
417 struct zfcp_latencies {
418 struct latency_cont read;
419 struct latency_cont write;
420 struct latency_cont cmd;
424 struct zfcp_adapter {
425 atomic_t refcount; /* reference count */
426 wait_queue_head_t remove_wq; /* can be used to wait for
427 refcount drop to zero */
428 u64 peer_wwnn; /* P2P peer WWNN */
429 u64 peer_wwpn; /* P2P peer WWPN */
430 u32 peer_d_id; /* P2P peer D_ID */
431 struct ccw_device *ccw_device; /* S/390 ccw device */
432 u32 hydra_version; /* Hydra version */
434 u32 adapter_features; /* FCP channel features */
435 u32 connection_features; /* host connection features */
436 u32 hardware_version; /* of FCP channel */
437 u16 timer_ticks; /* time int for a tick */
438 struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
439 struct list_head port_list_head; /* remote port list */
440 unsigned long req_no; /* unique FSF req number */
441 struct list_head *req_list; /* list of pending reqs */
442 spinlock_t req_list_lock; /* request list lock */
443 struct zfcp_qdio_queue req_q; /* request queue */
444 spinlock_t req_q_lock; /* for operations on queue */
445 ktime_t req_q_time; /* time of last fill level change */
446 u64 req_q_util; /* for accounting */
447 spinlock_t qdio_stat_lock;
448 u32 fsf_req_seq_no; /* FSF cmnd seq number */
449 wait_queue_head_t request_wq; /* can be used to wait for
450 more avaliable SBALs */
451 struct zfcp_qdio_queue resp_q; /* response queue */
452 rwlock_t abort_lock; /* Protects against SCSI
455 atomic_t stat_miss; /* # missing status reads*/
456 struct work_struct stat_work;
457 atomic_t status; /* status of this adapter */
458 struct list_head erp_ready_head; /* error recovery for this
460 struct list_head erp_running_head;
462 struct semaphore erp_ready_sem;
463 wait_queue_head_t erp_thread_wqh;
464 wait_queue_head_t erp_done_wqh;
465 struct zfcp_erp_action erp_action; /* pending error recovery */
466 atomic_t erp_counter;
467 u32 erp_total_count; /* total nr of enqueued erp
469 u32 erp_low_mem_count; /* nr of erp actions waiting
471 struct zfcp_wka_port nsp; /* adapter's nameserver */
472 debug_info_t *rec_dbf;
473 debug_info_t *hba_dbf;
474 debug_info_t *san_dbf; /* debug feature areas */
475 debug_info_t *scsi_dbf;
476 spinlock_t rec_dbf_lock;
477 spinlock_t hba_dbf_lock;
478 spinlock_t san_dbf_lock;
479 spinlock_t scsi_dbf_lock;
480 struct zfcp_rec_dbf_record rec_dbf_buf;
481 struct zfcp_hba_dbf_record hba_dbf_buf;
482 struct zfcp_san_dbf_record san_dbf_buf;
483 struct zfcp_scsi_dbf_record scsi_dbf_buf;
484 struct zfcp_adapter_mempool pool; /* Adapter memory pools */
485 struct qdio_initialize qdio_init_data; /* for qdio_establish */
486 struct fc_host_statistics *fc_stats;
487 struct fsf_qtcb_bottom_port *stats_reset_data;
488 unsigned long stats_reset;
489 struct work_struct scan_work;
490 struct service_level service_level;
491 atomic_t qdio_outb_full; /* queue full incidents */
495 struct device sysfs_device; /* sysfs device */
496 struct fc_rport *rport; /* rport of fc transport class */
497 struct list_head list; /* list of remote ports */
498 atomic_t refcount; /* reference count */
499 wait_queue_head_t remove_wq; /* can be used to wait for
500 refcount drop to zero */
501 struct zfcp_adapter *adapter; /* adapter used to access port */
502 struct list_head unit_list_head; /* head of logical unit list */
503 atomic_t status; /* status of this remote port */
504 u64 wwnn; /* WWNN if known */
507 u32 handle; /* handle assigned by FSF */
508 struct zfcp_erp_action erp_action; /* pending error recovery */
509 atomic_t erp_counter;
511 u32 supported_classes;
512 struct work_struct gid_pn_work;
513 struct work_struct test_link_work;
514 struct work_struct rport_work;
515 enum { RPORT_NONE, RPORT_ADD, RPORT_DEL } rport_task;
519 struct device sysfs_device; /* sysfs device */
520 struct list_head list; /* list of logical units */
521 atomic_t refcount; /* reference count */
522 wait_queue_head_t remove_wq; /* can be used to wait for
523 refcount drop to zero */
524 struct zfcp_port *port; /* remote port of unit */
525 atomic_t status; /* status of this logical unit */
526 u64 fcp_lun; /* own FCP_LUN */
527 u32 handle; /* handle assigned by FSF */
528 struct scsi_device *device; /* scsi device struct pointer */
529 struct zfcp_erp_action erp_action; /* pending error recovery */
530 atomic_t erp_counter;
531 struct zfcp_latencies latencies;
532 struct work_struct scsi_work;
536 struct zfcp_fsf_req {
537 struct list_head list; /* list of FSF requests */
538 unsigned long req_id; /* unique request ID */
539 struct zfcp_adapter *adapter; /* adapter request belongs to */
540 u8 sbal_number; /* nr of SBALs free for use */
541 u8 sbal_first; /* first SBAL for this request */
542 u8 sbal_last; /* last SBAL for this request */
543 u8 sbal_limit; /* last possible SBAL for
545 u8 sbale_curr; /* current SBALE during creation
547 u8 sbal_response; /* SBAL used in interrupt */
548 wait_queue_head_t completion_wq; /* can be used by a routine
549 to wait for completion */
550 u32 status; /* status of this request */
551 u32 fsf_command; /* FSF Command copy */
552 struct fsf_qtcb *qtcb; /* address of associated QTCB */
553 u32 seq_no; /* Sequence number of request */
554 void *data; /* private data of request */
555 struct timer_list timer; /* used for erp or scsi er */
556 struct zfcp_erp_action *erp_action; /* used if this request is
557 issued on behalf of erp */
558 mempool_t *pool; /* used if request was alloacted
559 from emergency pool */
560 unsigned long long issued; /* request sent time (STCK) */
561 struct zfcp_unit *unit;
562 void (*handler)(struct zfcp_fsf_req *);
563 u16 qdio_outb_usage;/* usage of outbound queue */
564 u16 qdio_inb_usage; /* usage of inbound queue */
569 struct scsi_host_template scsi_host_template;
570 struct scsi_transport_template *scsi_transport_template;
571 rwlock_t config_lock; /* serialises changes
574 struct semaphore config_sema; /* serialises configuration
576 struct kmem_cache *fsf_req_qtcb_cache;
577 struct kmem_cache *sr_buffer_cache;
578 struct kmem_cache *gid_pn_cache;
579 struct workqueue_struct *work_queue;
582 /* struct used by memory pools for fsf_requests */
583 struct zfcp_fsf_req_qtcb {
584 struct zfcp_fsf_req fsf_req;
585 struct fsf_qtcb qtcb;
588 /********************** ZFCP SPECIFIC DEFINES ********************************/
590 #define ZFCP_SET 0x00000100
591 #define ZFCP_CLEAR 0x00000200
594 * Helper functions for request ID management.
596 static inline int zfcp_reqlist_hash(unsigned long req_id)
598 return req_id % REQUEST_LIST_SIZE;
601 static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
602 struct zfcp_fsf_req *fsf_req)
604 list_del(&fsf_req->list);
607 static inline struct zfcp_fsf_req *
608 zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
610 struct zfcp_fsf_req *request;
613 idx = zfcp_reqlist_hash(req_id);
614 list_for_each_entry(request, &adapter->req_list[idx], list)
615 if (request->req_id == req_id)
620 static inline struct zfcp_fsf_req *
621 zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req)
623 struct zfcp_fsf_req *request;
626 for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) {
627 list_for_each_entry(request, &adapter->req_list[idx], list)
635 * functions needed for reference/usage counting
639 zfcp_unit_get(struct zfcp_unit *unit)
641 atomic_inc(&unit->refcount);
645 zfcp_unit_put(struct zfcp_unit *unit)
647 if (atomic_dec_return(&unit->refcount) == 0)
648 wake_up(&unit->remove_wq);
652 zfcp_port_get(struct zfcp_port *port)
654 atomic_inc(&port->refcount);
658 zfcp_port_put(struct zfcp_port *port)
660 if (atomic_dec_return(&port->refcount) == 0)
661 wake_up(&port->remove_wq);
665 zfcp_adapter_get(struct zfcp_adapter *adapter)
667 atomic_inc(&adapter->refcount);
671 zfcp_adapter_put(struct zfcp_adapter *adapter)
673 if (atomic_dec_return(&adapter->refcount) == 0)
674 wake_up(&adapter->remove_wq);
677 #endif /* ZFCP_DEF_H */