4 * Global definitions for the zfcp device driver.
6 * Copyright IBM Corporation 2002, 2008
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>
40 /********************* GENERAL DEFINES *********************************/
43 * zfcp_sg_to_address - determine kernel address from struct scatterlist
44 * @list: struct scatterlist
45 * Return: kernel address
48 zfcp_sg_to_address(struct scatterlist *list)
54 * zfcp_address_to_sg - set up struct scatterlist from kernel address
55 * @address: kernel address
56 * @list: struct scatterlist
60 zfcp_address_to_sg(void *address, struct scatterlist *list, unsigned int size)
62 sg_set_buf(list, address, size);
65 #define REQUEST_LIST_SIZE 128
67 /********************* SCSI SPECIFIC DEFINES *********************************/
68 #define ZFCP_SCSI_ER_TIMEOUT (10*HZ)
70 /********************* CIO/QDIO SPECIFIC DEFINES *****************************/
72 /* Adapter Identification Parameters */
73 #define ZFCP_CONTROL_UNIT_TYPE 0x1731
74 #define ZFCP_CONTROL_UNIT_MODEL 0x03
75 #define ZFCP_DEVICE_TYPE 0x1732
76 #define ZFCP_DEVICE_MODEL 0x03
77 #define ZFCP_DEVICE_MODEL_PRIV 0x04
79 /* allow as many chained SBALs as are supported by hardware */
80 #define ZFCP_MAX_SBALS_PER_REQ FSF_MAX_SBALS_PER_REQ
81 #define ZFCP_MAX_SBALS_PER_CT_REQ FSF_MAX_SBALS_PER_REQ
82 #define ZFCP_MAX_SBALS_PER_ELS_REQ FSF_MAX_SBALS_PER_ELS_REQ
84 /* DMQ bug workaround: don't use last SBALE */
85 #define ZFCP_MAX_SBALES_PER_SBAL (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
87 /* index of last SBALE (with respect to DMQ bug workaround) */
88 #define ZFCP_LAST_SBALE_PER_SBAL (ZFCP_MAX_SBALES_PER_SBAL - 1)
90 /* max. number of (data buffer) SBALEs in largest SBAL chain */
91 #define ZFCP_MAX_SBALES_PER_REQ \
92 (ZFCP_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
93 /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
95 #define ZFCP_MAX_SECTORS (ZFCP_MAX_SBALES_PER_REQ * 8)
96 /* max. number of (data buffer) SBALEs in largest SBAL chain
97 multiplied with number of sectors per 4k block */
99 #define ZFCP_SBAL_TIMEOUT (5*HZ)
101 #define ZFCP_TYPE2_RECOVERY_TIME 8 /* seconds */
103 /********************* FSF SPECIFIC DEFINES *********************************/
105 #define ZFCP_ULP_INFO_VERSION 26
106 #define ZFCP_QTCB_VERSION FSF_QTCB_CURRENT_VERSION
107 /* ATTENTION: value must not be used by hardware */
108 #define FSF_QTCB_UNSOLICITED_STATUS 0x6305
110 /* Do 1st retry in 1 second, then double the timeout for each following retry */
111 #define ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP 1
112 #define ZFCP_EXCHANGE_CONFIG_DATA_RETRIES 7
114 /* timeout value for "default timer" for fsf requests */
115 #define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ)
117 /*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
119 typedef unsigned long long wwn_t;
120 typedef unsigned long long fcp_lun_t;
121 /* data length field may be at variable position in FCP-2 FCP_CMND IU */
122 typedef unsigned int fcp_dl_t;
124 #define ZFCP_FC_SERVICE_CLASS_DEFAULT FSF_CLASS_3
126 /* timeout for name-server lookup (in seconds) */
127 #define ZFCP_NS_GID_PN_TIMEOUT 10
129 /* largest SCSI command we can process */
130 /* FCP-2 (FCP_CMND IU) allows up to (255-3+16) */
131 #define ZFCP_MAX_SCSI_CMND_LENGTH 255
132 /* maximum number of commands in LUN queue (tagged queueing) */
133 #define ZFCP_CMND_PER_LUN 32
135 /* task attribute values in FCP-2 FCP_CMND IU */
142 /* task management flags in FCP-2 FCP_CMND IU */
143 #define FCP_CLEAR_ACA 0x40
144 #define FCP_TARGET_RESET 0x20
145 #define FCP_LOGICAL_UNIT_RESET 0x10
146 #define FCP_CLEAR_TASK_SET 0x04
147 #define FCP_ABORT_TASK_SET 0x02
149 #define FCP_CDB_LENGTH 16
151 #define ZFCP_DID_MASK 0x00FFFFFF
153 /* FCP(-2) FCP_CMND IU */
155 fcp_lun_t fcp_lun; /* FCP logical unit number */
156 u8 crn; /* command reference number */
157 u8 reserved0:5; /* reserved */
158 u8 task_attribute:3; /* task attribute */
159 u8 task_management_flags; /* task management flags */
160 u8 add_fcp_cdb_length:6; /* additional FCP_CDB length */
161 u8 rddata:1; /* read data */
162 u8 wddata:1; /* write data */
163 u8 fcp_cdb[FCP_CDB_LENGTH];
164 } __attribute__((packed));
166 /* FCP(-2) FCP_RSP IU */
173 u8 fcp_resid_under:1;
175 u8 fcp_sns_len_valid:1;
176 u8 fcp_rsp_len_valid:1;
184 } __attribute__((packed));
187 #define RSP_CODE_GOOD 0
188 #define RSP_CODE_LENGTH_MISMATCH 1
189 #define RSP_CODE_FIELD_INVALID 2
190 #define RSP_CODE_RO_MISMATCH 3
191 #define RSP_CODE_TASKMAN_UNSUPP 4
192 #define RSP_CODE_TASKMAN_FAILED 5
197 #define LS_PLOGI 0x03
199 struct fcp_rscn_head {
201 u8 page_length; /* always 0x04 */
203 } __attribute__((packed));
205 struct fcp_rscn_element {
210 } __attribute__((packed));
212 #define ZFCP_PORT_ADDRESS 0x0
213 #define ZFCP_AREA_ADDRESS 0x1
214 #define ZFCP_DOMAIN_ADDRESS 0x2
215 #define ZFCP_FABRIC_ADDRESS 0x3
217 #define ZFCP_PORTS_RANGE_PORT 0xFFFFFF
218 #define ZFCP_PORTS_RANGE_AREA 0xFFFF00
219 #define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
220 #define ZFCP_PORTS_RANGE_FABRIC 0x000000
222 #define ZFCP_NO_PORTS_PER_AREA 0x100
223 #define ZFCP_NO_PORTS_PER_DOMAIN 0x10000
224 #define ZFCP_NO_PORTS_PER_FABRIC 0x1000000
231 } __attribute__((packed));
236 #define R_A_TOV 10 /* seconds */
237 #define ZFCP_ELS_TIMEOUT (2 * R_A_TOV)
239 #define ZFCP_LS_RLS 0x0f
240 #define ZFCP_LS_ADISC 0x52
241 #define ZFCP_LS_RPS 0x56
242 #define ZFCP_LS_RSCN 0x61
243 #define ZFCP_LS_RNID 0x78
245 struct zfcp_ls_rjt_par {
250 } __attribute__ ((packed));
252 struct zfcp_ls_adisc {
259 } __attribute__ ((packed));
261 struct zfcp_ls_adisc_acc {
268 } __attribute__ ((packed));
270 struct zfcp_rc_entry {
272 const char *description;
278 #define ZFCP_CT_REVISION 0x01
279 #define ZFCP_CT_DIRECTORY_SERVICE 0xFC
280 #define ZFCP_CT_NAME_SERVER 0x02
281 #define ZFCP_CT_SYNCHRONOUS 0x00
282 #define ZFCP_CT_SCSI_FCP 0x08
283 #define ZFCP_CT_UNABLE_TO_PERFORM_CMD 0x09
284 #define ZFCP_CT_GID_PN 0x0121
285 #define ZFCP_CT_GPN_FT 0x0172
286 #define ZFCP_CT_MAX_SIZE 0x1020
287 #define ZFCP_CT_ACCEPT 0x8002
288 #define ZFCP_CT_REJECT 0x8001
293 #define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
295 /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
298 * Note, the leftmost status byte is common among adapter, port
301 #define ZFCP_COMMON_FLAGS 0xfff00000
303 /* common status bits */
304 #define ZFCP_STATUS_COMMON_REMOVE 0x80000000
305 #define ZFCP_STATUS_COMMON_RUNNING 0x40000000
306 #define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
307 #define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
308 #define ZFCP_STATUS_COMMON_OPENING 0x08000000
309 #define ZFCP_STATUS_COMMON_OPEN 0x04000000
310 #define ZFCP_STATUS_COMMON_CLOSING 0x02000000
311 #define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
312 #define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
313 #define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
314 #define ZFCP_STATUS_COMMON_NOESC 0x00200000
317 #define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
318 #define ZFCP_STATUS_ADAPTER_REGISTERED 0x00000004
319 #define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
320 #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
321 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
322 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
323 #define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
324 #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
325 #define ZFCP_STATUS_ADAPTER_XPORT_OK 0x00000800
327 /* FC-PH/FC-GS well-known address identifiers for generic services */
328 #define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA
329 #define ZFCP_DID_TIME_SERVICE 0xFFFFFB
330 #define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC
331 #define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8
332 #define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7
334 /* remote port status */
335 #define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
336 #define ZFCP_STATUS_PORT_DID_DID 0x00000002
337 #define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
338 #define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
339 #define ZFCP_STATUS_PORT_NO_SCSI_ID 0x00000010
340 #define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
342 /* for ports with well known addresses */
343 #define ZFCP_STATUS_PORT_WKA \
344 (ZFCP_STATUS_PORT_NO_WWPN | \
345 ZFCP_STATUS_PORT_NO_SCSI_ID)
347 /* logical unit status */
348 #define ZFCP_STATUS_UNIT_TEMPORARY 0x00000002
349 #define ZFCP_STATUS_UNIT_SHARED 0x00000004
350 #define ZFCP_STATUS_UNIT_READONLY 0x00000008
351 #define ZFCP_STATUS_UNIT_REGISTERED 0x00000010
352 #define ZFCP_STATUS_UNIT_SCSI_WORK_PENDING 0x00000020
354 /* FSF request status (this does not have a common part) */
355 #define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000
356 #define ZFCP_STATUS_FSFREQ_POOL 0x00000001
357 #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
358 #define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
359 #define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
360 #define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
361 #define ZFCP_STATUS_FSFREQ_ABORTING 0x00000020
362 #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
363 #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
364 #define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
365 #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
366 #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
367 #define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
368 #define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
370 /*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
372 #define ZFCP_MAX_ERPS 3
374 #define ZFCP_ERP_FSFREQ_TIMEOUT (30 * HZ)
375 #define ZFCP_ERP_MEMWAIT_TIMEOUT HZ
377 #define ZFCP_STATUS_ERP_TIMEDOUT 0x10000000
378 #define ZFCP_STATUS_ERP_CLOSE_ONLY 0x01000000
379 #define ZFCP_STATUS_ERP_DISMISSING 0x00100000
380 #define ZFCP_STATUS_ERP_DISMISSED 0x00200000
381 #define ZFCP_STATUS_ERP_LOWMEM 0x00400000
383 #define ZFCP_ERP_STEP_UNINITIALIZED 0x00000000
384 #define ZFCP_ERP_STEP_FSF_XCONFIG 0x00000001
385 #define ZFCP_ERP_STEP_PHYS_PORT_CLOSING 0x00000010
386 #define ZFCP_ERP_STEP_PORT_CLOSING 0x00000100
387 #define ZFCP_ERP_STEP_NAMESERVER_OPEN 0x00000200
388 #define ZFCP_ERP_STEP_NAMESERVER_LOOKUP 0x00000400
389 #define ZFCP_ERP_STEP_PORT_OPENING 0x00000800
390 #define ZFCP_ERP_STEP_UNIT_CLOSING 0x00001000
391 #define ZFCP_ERP_STEP_UNIT_OPENING 0x00002000
393 /* Ordered by escalation level (necessary for proper erp-code operation) */
394 #define ZFCP_ERP_ACTION_REOPEN_ADAPTER 0x4
395 #define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED 0x3
396 #define ZFCP_ERP_ACTION_REOPEN_PORT 0x2
397 #define ZFCP_ERP_ACTION_REOPEN_UNIT 0x1
399 #define ZFCP_ERP_ACTION_RUNNING 0x1
400 #define ZFCP_ERP_ACTION_READY 0x2
402 #define ZFCP_ERP_SUCCEEDED 0x0
403 #define ZFCP_ERP_FAILED 0x1
404 #define ZFCP_ERP_CONTINUES 0x2
405 #define ZFCP_ERP_EXIT 0x3
406 #define ZFCP_ERP_DISMISSED 0x4
407 #define ZFCP_ERP_NOMEM 0x5
409 /************************* STRUCTURE DEFINITIONS *****************************/
413 /* holds various memory pools of an adapter */
414 struct zfcp_adapter_mempool {
415 mempool_t *fsf_req_erp;
416 mempool_t *fsf_req_scsi;
417 mempool_t *fsf_req_abort;
418 mempool_t *fsf_req_status_read;
419 mempool_t *data_status_read;
420 mempool_t *data_gid_pn;
429 u8 gs_type; // 0xFC Directory Service
430 u8 gs_subtype; // 0x02 Name Server
431 u8 options; // 0x00 single bidirectional exchange
433 u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT
434 u16 max_res_size; // <= (4096 - 16) / 4
439 } __attribute__ ((packed));
441 /* nameserver request CT_IU -- for requests where
442 * a port name is required */
443 struct ct_iu_gid_pn_req {
444 struct ct_hdr header;
446 } __attribute__ ((packed));
448 /* FS_ACC IU and data unit for GID_PN nameserver request */
449 struct ct_iu_gid_pn_resp {
450 struct ct_hdr header;
452 } __attribute__ ((packed));
454 typedef void (*zfcp_send_ct_handler_t)(unsigned long);
457 * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
458 * @port: port where the request is sent to
459 * @req: scatter-gather list for request
460 * @resp: scatter-gather list for response
461 * @req_count: number of elements in request scatter-gather list
462 * @resp_count: number of elements in response scatter-gather list
463 * @handler: handler function (called for response to the request)
464 * @handler_data: data passed to handler function
465 * @timeout: FSF timeout for this request
466 * @completion: completion for synchronization purposes
467 * @status: used to pass error status to calling function
469 struct zfcp_send_ct {
470 struct zfcp_port *port;
471 struct scatterlist *req;
472 struct scatterlist *resp;
473 unsigned int req_count;
474 unsigned int resp_count;
475 zfcp_send_ct_handler_t handler;
476 unsigned long handler_data;
478 struct completion *completion;
482 /* used for name server requests in error recovery */
483 struct zfcp_gid_pn_data {
484 struct zfcp_send_ct ct;
485 struct scatterlist req;
486 struct scatterlist resp;
487 struct ct_iu_gid_pn_req ct_iu_req;
488 struct ct_iu_gid_pn_resp ct_iu_resp;
489 struct zfcp_port *port;
492 typedef void (*zfcp_send_els_handler_t)(unsigned long);
495 * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
496 * @adapter: adapter where request is sent from
497 * @port: port where ELS is destinated (port reference count has to be increased)
498 * @d_id: destiniation id of port where request is sent to
499 * @req: scatter-gather list for request
500 * @resp: scatter-gather list for response
501 * @req_count: number of elements in request scatter-gather list
502 * @resp_count: number of elements in response scatter-gather list
503 * @handler: handler function (called for response to the request)
504 * @handler_data: data passed to handler function
505 * @completion: completion for synchronization purposes
506 * @ls_code: hex code of ELS command
507 * @status: used to pass error status to calling function
509 struct zfcp_send_els {
510 struct zfcp_adapter *adapter;
511 struct zfcp_port *port;
513 struct scatterlist *req;
514 struct scatterlist *resp;
515 unsigned int req_count;
516 unsigned int resp_count;
517 zfcp_send_els_handler_t handler;
518 unsigned long handler_data;
519 struct completion *completion;
524 struct zfcp_qdio_queue {
525 struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
526 u8 first; /* index of next free bfr
527 in queue (free_count>0) */
528 atomic_t count; /* number of free buffers
530 rwlock_t lock; /* lock for operations on queue */
531 int pci_batch; /* SBALs since PCI indication
535 struct zfcp_erp_action {
536 struct list_head list;
537 int action; /* requested action code */
538 struct zfcp_adapter *adapter; /* device which should be recovered */
539 struct zfcp_port *port;
540 struct zfcp_unit *unit;
541 volatile u32 status; /* recovery status */
542 u32 step; /* active step of this erp action */
543 struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
545 struct timer_list timer;
548 struct fsf_latency_record {
554 struct latency_cont {
555 struct fsf_latency_record channel;
556 struct fsf_latency_record fabric;
560 struct zfcp_latencies {
561 struct latency_cont read;
562 struct latency_cont write;
563 struct latency_cont cmd;
567 struct zfcp_adapter {
568 struct list_head list; /* list of adapters */
569 atomic_t refcount; /* reference count */
570 wait_queue_head_t remove_wq; /* can be used to wait for
571 refcount drop to zero */
572 wwn_t peer_wwnn; /* P2P peer WWNN */
573 wwn_t peer_wwpn; /* P2P peer WWPN */
574 u32 peer_d_id; /* P2P peer D_ID */
575 struct ccw_device *ccw_device; /* S/390 ccw device */
576 u32 hydra_version; /* Hydra version */
578 u32 adapter_features; /* FCP channel features */
579 u32 connection_features; /* host connection features */
580 u32 hardware_version; /* of FCP channel */
581 u16 timer_ticks; /* time int for a tick */
582 struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
583 struct list_head port_list_head; /* remote port list */
584 struct list_head port_remove_lh; /* head of ports to be
586 u32 ports; /* number of remote ports */
587 unsigned long req_no; /* unique FSF req number */
588 struct list_head *req_list; /* list of pending reqs */
589 spinlock_t req_list_lock; /* request list lock */
590 struct zfcp_qdio_queue req_q; /* request queue */
591 u32 fsf_req_seq_no; /* FSF cmnd seq number */
592 wait_queue_head_t request_wq; /* can be used to wait for
593 more avaliable SBALs */
594 struct zfcp_qdio_queue resp_q; /* response queue */
595 rwlock_t abort_lock; /* Protects against SCSI
598 atomic_t stat_miss; /* # missing status reads*/
599 struct work_struct stat_work;
600 atomic_t status; /* status of this adapter */
601 struct list_head erp_ready_head; /* error recovery for this
603 struct list_head erp_running_head;
605 struct semaphore erp_ready_sem;
606 wait_queue_head_t erp_thread_wqh;
607 wait_queue_head_t erp_done_wqh;
608 struct zfcp_erp_action erp_action; /* pending error recovery */
609 atomic_t erp_counter;
610 u32 erp_total_count; /* total nr of enqueued erp
612 u32 erp_low_mem_count; /* nr of erp actions waiting
614 struct zfcp_port *nameserver_port; /* adapter's nameserver */
615 debug_info_t *rec_dbf;
616 debug_info_t *hba_dbf;
617 debug_info_t *san_dbf; /* debug feature areas */
618 debug_info_t *scsi_dbf;
619 spinlock_t rec_dbf_lock;
620 spinlock_t hba_dbf_lock;
621 spinlock_t san_dbf_lock;
622 spinlock_t scsi_dbf_lock;
623 struct zfcp_rec_dbf_record rec_dbf_buf;
624 struct zfcp_hba_dbf_record hba_dbf_buf;
625 struct zfcp_san_dbf_record san_dbf_buf;
626 struct zfcp_scsi_dbf_record scsi_dbf_buf;
627 struct zfcp_adapter_mempool pool; /* Adapter memory pools */
628 struct qdio_initialize qdio_init_data; /* for qdio_establish */
629 struct device generic_services; /* directory for WKA ports */
630 struct fc_host_statistics *fc_stats;
631 struct fsf_qtcb_bottom_port *stats_reset_data;
632 unsigned long stats_reset;
633 struct work_struct scan_work;
637 * the struct device sysfs_device must be at the beginning of this structure.
638 * pointer to struct device is used to free port structure in release function
639 * of the device. don't change!
642 struct device sysfs_device; /* sysfs device */
643 struct fc_rport *rport; /* rport of fc transport class */
644 struct list_head list; /* list of remote ports */
645 atomic_t refcount; /* reference count */
646 wait_queue_head_t remove_wq; /* can be used to wait for
647 refcount drop to zero */
648 struct zfcp_adapter *adapter; /* adapter used to access port */
649 struct list_head unit_list_head; /* head of logical unit list */
650 struct list_head unit_remove_lh; /* head of luns to be removed
652 u32 units; /* # of logical units in list */
653 atomic_t status; /* status of this remote port */
654 wwn_t wwnn; /* WWNN if known */
655 wwn_t wwpn; /* WWPN */
657 u32 handle; /* handle assigned by FSF */
658 struct zfcp_erp_action erp_action; /* pending error recovery */
659 atomic_t erp_counter;
661 u32 supported_classes;
664 /* the struct device sysfs_device must be at the beginning of this structure.
665 * pointer to struct device is used to free unit structure in release function
666 * of the device. don't change!
669 struct device sysfs_device; /* sysfs device */
670 struct list_head list; /* list of logical units */
671 atomic_t refcount; /* reference count */
672 wait_queue_head_t remove_wq; /* can be used to wait for
673 refcount drop to zero */
674 struct zfcp_port *port; /* remote port of unit */
675 atomic_t status; /* status of this logical unit */
676 unsigned int scsi_lun; /* own SCSI LUN */
677 fcp_lun_t fcp_lun; /* own FCP_LUN */
678 u32 handle; /* handle assigned by FSF */
679 struct scsi_device *device; /* scsi device struct pointer */
680 struct zfcp_erp_action erp_action; /* pending error recovery */
681 atomic_t erp_counter;
682 struct zfcp_latencies latencies;
686 struct zfcp_fsf_req {
687 struct list_head list; /* list of FSF requests */
688 unsigned long req_id; /* unique request ID */
689 struct zfcp_adapter *adapter; /* adapter request belongs to */
690 u8 sbal_number; /* nr of SBALs free for use */
691 u8 sbal_first; /* first SBAL for this request */
692 u8 sbal_last; /* last SBAL for this request */
693 u8 sbal_limit; /* last possible SBAL for
695 u8 sbale_curr; /* current SBALE during creation
697 u8 sbal_response; /* SBAL used in interrupt */
698 wait_queue_head_t completion_wq; /* can be used by a routine
699 to wait for completion */
700 volatile u32 status; /* status of this request */
701 u32 fsf_command; /* FSF Command copy */
702 struct fsf_qtcb *qtcb; /* address of associated QTCB */
703 u32 seq_no; /* Sequence number of request */
704 unsigned long data; /* private data of request */
705 struct timer_list timer; /* used for erp or scsi er */
706 struct zfcp_erp_action *erp_action; /* used if this request is
707 issued on behalf of erp */
708 mempool_t *pool; /* used if request was alloacted
709 from emergency pool */
710 unsigned long long issued; /* request sent time (STCK) */
711 struct zfcp_unit *unit;
714 typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
718 struct scsi_host_template scsi_host_template;
719 struct scsi_transport_template *scsi_transport_template;
720 atomic_t status; /* Module status flags */
721 struct list_head adapter_list_head; /* head of adapter list */
722 struct list_head adapter_remove_lh; /* head of adapters to be
724 u32 adapters; /* # of adapters in list */
725 rwlock_t config_lock; /* serialises changes
728 struct semaphore config_sema; /* serialises configuration
730 atomic_t loglevel; /* current loglevel */
731 char init_busid[BUS_ID_SIZE];
733 fcp_lun_t init_fcp_lun;
734 struct kmem_cache *fsf_req_qtcb_cache;
735 struct kmem_cache *sr_buffer_cache;
736 struct kmem_cache *gid_pn_cache;
739 /* number of elements for various memory pools */
740 #define ZFCP_POOL_FSF_REQ_ERP_NR 1
741 #define ZFCP_POOL_FSF_REQ_SCSI_NR 1
742 #define ZFCP_POOL_FSF_REQ_ABORT_NR 1
743 #define ZFCP_POOL_STATUS_READ_NR FSF_STATUS_READS_RECOM
744 #define ZFCP_POOL_DATA_GID_PN_NR 1
746 /* struct used by memory pools for fsf_requests */
747 struct zfcp_fsf_req_qtcb {
748 struct zfcp_fsf_req fsf_req;
749 struct fsf_qtcb qtcb;
752 /********************** ZFCP SPECIFIC DEFINES ********************************/
754 #define ZFCP_REQ_AUTO_CLEANUP 0x00000002
755 #define ZFCP_WAIT_FOR_SBAL 0x00000004
756 #define ZFCP_REQ_NO_QTCB 0x00000008
758 #define ZFCP_SET 0x00000100
759 #define ZFCP_CLEAR 0x00000200
761 #ifndef atomic_test_mask
762 #define atomic_test_mask(mask, target) \
763 ((atomic_read(target) & mask) == mask)
766 extern void _zfcp_hex_dump(char *, int);
767 #define ZFCP_HEX_DUMP(level, addr, count) \
768 if (ZFCP_LOG_CHECK(level)) { \
769 _zfcp_hex_dump(addr, count); \
772 #define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
773 #define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
774 #define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
777 * Helper functions for request ID management.
779 static inline int zfcp_reqlist_hash(unsigned long req_id)
781 return req_id % REQUEST_LIST_SIZE;
784 static inline void zfcp_reqlist_add(struct zfcp_adapter *adapter,
785 struct zfcp_fsf_req *fsf_req)
789 idx = zfcp_reqlist_hash(fsf_req->req_id);
790 list_add_tail(&fsf_req->list, &adapter->req_list[idx]);
793 static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
794 struct zfcp_fsf_req *fsf_req)
796 list_del(&fsf_req->list);
799 static inline struct zfcp_fsf_req *
800 zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
802 struct zfcp_fsf_req *request;
805 idx = zfcp_reqlist_hash(req_id);
806 list_for_each_entry(request, &adapter->req_list[idx], list)
807 if (request->req_id == req_id)
812 static inline struct zfcp_fsf_req *
813 zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req)
815 struct zfcp_fsf_req *request;
818 for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) {
819 list_for_each_entry(request, &adapter->req_list[idx], list)
827 * functions needed for reference/usage counting
831 zfcp_unit_get(struct zfcp_unit *unit)
833 atomic_inc(&unit->refcount);
837 zfcp_unit_put(struct zfcp_unit *unit)
839 if (atomic_dec_return(&unit->refcount) == 0)
840 wake_up(&unit->remove_wq);
844 zfcp_unit_wait(struct zfcp_unit *unit)
846 wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
850 zfcp_port_get(struct zfcp_port *port)
852 atomic_inc(&port->refcount);
856 zfcp_port_put(struct zfcp_port *port)
858 if (atomic_dec_return(&port->refcount) == 0)
859 wake_up(&port->remove_wq);
863 zfcp_port_wait(struct zfcp_port *port)
865 wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
869 zfcp_adapter_get(struct zfcp_adapter *adapter)
871 atomic_inc(&adapter->refcount);
875 zfcp_adapter_put(struct zfcp_adapter *adapter)
877 if (atomic_dec_return(&adapter->refcount) == 0)
878 wake_up(&adapter->remove_wq);
882 zfcp_adapter_wait(struct zfcp_adapter *adapter)
884 wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
887 #endif /* ZFCP_DEF_H */