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 /* task attribute values in FCP-2 FCP_CMND IU */
136 /* task management flags in FCP-2 FCP_CMND IU */
137 #define FCP_CLEAR_ACA 0x40
138 #define FCP_TARGET_RESET 0x20
139 #define FCP_LOGICAL_UNIT_RESET 0x10
140 #define FCP_CLEAR_TASK_SET 0x04
141 #define FCP_ABORT_TASK_SET 0x02
143 #define FCP_CDB_LENGTH 16
145 #define ZFCP_DID_MASK 0x00FFFFFF
147 /* FCP(-2) FCP_CMND IU */
149 fcp_lun_t fcp_lun; /* FCP logical unit number */
150 u8 crn; /* command reference number */
151 u8 reserved0:5; /* reserved */
152 u8 task_attribute:3; /* task attribute */
153 u8 task_management_flags; /* task management flags */
154 u8 add_fcp_cdb_length:6; /* additional FCP_CDB length */
155 u8 rddata:1; /* read data */
156 u8 wddata:1; /* write data */
157 u8 fcp_cdb[FCP_CDB_LENGTH];
158 } __attribute__((packed));
160 /* FCP(-2) FCP_RSP IU */
167 u8 fcp_resid_under:1;
169 u8 fcp_sns_len_valid:1;
170 u8 fcp_rsp_len_valid:1;
178 } __attribute__((packed));
181 #define RSP_CODE_GOOD 0
182 #define RSP_CODE_LENGTH_MISMATCH 1
183 #define RSP_CODE_FIELD_INVALID 2
184 #define RSP_CODE_RO_MISMATCH 3
185 #define RSP_CODE_TASKMAN_UNSUPP 4
186 #define RSP_CODE_TASKMAN_FAILED 5
191 #define LS_PLOGI 0x03
193 struct fcp_rscn_head {
195 u8 page_length; /* always 0x04 */
197 } __attribute__((packed));
199 struct fcp_rscn_element {
204 } __attribute__((packed));
206 #define ZFCP_PORT_ADDRESS 0x0
207 #define ZFCP_AREA_ADDRESS 0x1
208 #define ZFCP_DOMAIN_ADDRESS 0x2
209 #define ZFCP_FABRIC_ADDRESS 0x3
211 #define ZFCP_PORTS_RANGE_PORT 0xFFFFFF
212 #define ZFCP_PORTS_RANGE_AREA 0xFFFF00
213 #define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
214 #define ZFCP_PORTS_RANGE_FABRIC 0x000000
216 #define ZFCP_NO_PORTS_PER_AREA 0x100
217 #define ZFCP_NO_PORTS_PER_DOMAIN 0x10000
218 #define ZFCP_NO_PORTS_PER_FABRIC 0x1000000
225 } __attribute__((packed));
230 #define R_A_TOV 10 /* seconds */
231 #define ZFCP_ELS_TIMEOUT (2 * R_A_TOV)
233 #define ZFCP_LS_RLS 0x0f
234 #define ZFCP_LS_ADISC 0x52
235 #define ZFCP_LS_RPS 0x56
236 #define ZFCP_LS_RSCN 0x61
237 #define ZFCP_LS_RNID 0x78
239 struct zfcp_ls_rjt_par {
244 } __attribute__ ((packed));
246 struct zfcp_ls_adisc {
253 } __attribute__ ((packed));
255 struct zfcp_ls_adisc_acc {
262 } __attribute__ ((packed));
264 struct zfcp_rc_entry {
266 const char *description;
272 #define ZFCP_CT_REVISION 0x01
273 #define ZFCP_CT_DIRECTORY_SERVICE 0xFC
274 #define ZFCP_CT_NAME_SERVER 0x02
275 #define ZFCP_CT_SYNCHRONOUS 0x00
276 #define ZFCP_CT_SCSI_FCP 0x08
277 #define ZFCP_CT_UNABLE_TO_PERFORM_CMD 0x09
278 #define ZFCP_CT_GID_PN 0x0121
279 #define ZFCP_CT_GPN_FT 0x0172
280 #define ZFCP_CT_MAX_SIZE 0x1020
281 #define ZFCP_CT_ACCEPT 0x8002
282 #define ZFCP_CT_REJECT 0x8001
287 #define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
289 /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
292 * Note, the leftmost status byte is common among adapter, port
295 #define ZFCP_COMMON_FLAGS 0xfff00000
297 /* common status bits */
298 #define ZFCP_STATUS_COMMON_REMOVE 0x80000000
299 #define ZFCP_STATUS_COMMON_RUNNING 0x40000000
300 #define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
301 #define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
302 #define ZFCP_STATUS_COMMON_OPENING 0x08000000
303 #define ZFCP_STATUS_COMMON_OPEN 0x04000000
304 #define ZFCP_STATUS_COMMON_CLOSING 0x02000000
305 #define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
306 #define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
307 #define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
308 #define ZFCP_STATUS_COMMON_NOESC 0x00200000
311 #define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
312 #define ZFCP_STATUS_ADAPTER_REGISTERED 0x00000004
313 #define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
314 #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
315 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
316 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
317 #define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
318 #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
319 #define ZFCP_STATUS_ADAPTER_XPORT_OK 0x00000800
321 /* FC-PH/FC-GS well-known address identifiers for generic services */
322 #define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA
323 #define ZFCP_DID_TIME_SERVICE 0xFFFFFB
324 #define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC
325 #define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8
326 #define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7
328 /* remote port status */
329 #define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
330 #define ZFCP_STATUS_PORT_DID_DID 0x00000002
331 #define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
332 #define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
333 #define ZFCP_STATUS_PORT_NO_SCSI_ID 0x00000010
334 #define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
336 /* for ports with well known addresses */
337 #define ZFCP_STATUS_PORT_WKA \
338 (ZFCP_STATUS_PORT_NO_WWPN | \
339 ZFCP_STATUS_PORT_NO_SCSI_ID)
341 /* logical unit status */
342 #define ZFCP_STATUS_UNIT_TEMPORARY 0x00000002
343 #define ZFCP_STATUS_UNIT_SHARED 0x00000004
344 #define ZFCP_STATUS_UNIT_READONLY 0x00000008
345 #define ZFCP_STATUS_UNIT_REGISTERED 0x00000010
346 #define ZFCP_STATUS_UNIT_SCSI_WORK_PENDING 0x00000020
348 /* FSF request status (this does not have a common part) */
349 #define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000
350 #define ZFCP_STATUS_FSFREQ_POOL 0x00000001
351 #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
352 #define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
353 #define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
354 #define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
355 #define ZFCP_STATUS_FSFREQ_ABORTING 0x00000020
356 #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
357 #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
358 #define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
359 #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
360 #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
361 #define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
362 #define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
364 /*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
366 #define ZFCP_MAX_ERPS 3
368 #define ZFCP_ERP_FSFREQ_TIMEOUT (30 * HZ)
369 #define ZFCP_ERP_MEMWAIT_TIMEOUT HZ
371 #define ZFCP_STATUS_ERP_TIMEDOUT 0x10000000
372 #define ZFCP_STATUS_ERP_CLOSE_ONLY 0x01000000
373 #define ZFCP_STATUS_ERP_DISMISSING 0x00100000
374 #define ZFCP_STATUS_ERP_DISMISSED 0x00200000
375 #define ZFCP_STATUS_ERP_LOWMEM 0x00400000
377 #define ZFCP_ERP_STEP_UNINITIALIZED 0x00000000
378 #define ZFCP_ERP_STEP_FSF_XCONFIG 0x00000001
379 #define ZFCP_ERP_STEP_PHYS_PORT_CLOSING 0x00000010
380 #define ZFCP_ERP_STEP_PORT_CLOSING 0x00000100
381 #define ZFCP_ERP_STEP_NAMESERVER_OPEN 0x00000200
382 #define ZFCP_ERP_STEP_NAMESERVER_LOOKUP 0x00000400
383 #define ZFCP_ERP_STEP_PORT_OPENING 0x00000800
384 #define ZFCP_ERP_STEP_UNIT_CLOSING 0x00001000
385 #define ZFCP_ERP_STEP_UNIT_OPENING 0x00002000
387 /* Ordered by escalation level (necessary for proper erp-code operation) */
388 #define ZFCP_ERP_ACTION_REOPEN_ADAPTER 0x4
389 #define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED 0x3
390 #define ZFCP_ERP_ACTION_REOPEN_PORT 0x2
391 #define ZFCP_ERP_ACTION_REOPEN_UNIT 0x1
393 #define ZFCP_ERP_ACTION_RUNNING 0x1
394 #define ZFCP_ERP_ACTION_READY 0x2
396 #define ZFCP_ERP_SUCCEEDED 0x0
397 #define ZFCP_ERP_FAILED 0x1
398 #define ZFCP_ERP_CONTINUES 0x2
399 #define ZFCP_ERP_EXIT 0x3
400 #define ZFCP_ERP_DISMISSED 0x4
401 #define ZFCP_ERP_NOMEM 0x5
403 /************************* STRUCTURE DEFINITIONS *****************************/
407 /* holds various memory pools of an adapter */
408 struct zfcp_adapter_mempool {
409 mempool_t *fsf_req_erp;
410 mempool_t *fsf_req_scsi;
411 mempool_t *fsf_req_abort;
412 mempool_t *fsf_req_status_read;
413 mempool_t *data_status_read;
414 mempool_t *data_gid_pn;
423 u8 gs_type; // 0xFC Directory Service
424 u8 gs_subtype; // 0x02 Name Server
425 u8 options; // 0x00 single bidirectional exchange
427 u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT
428 u16 max_res_size; // <= (4096 - 16) / 4
433 } __attribute__ ((packed));
435 /* nameserver request CT_IU -- for requests where
436 * a port name is required */
437 struct ct_iu_gid_pn_req {
438 struct ct_hdr header;
440 } __attribute__ ((packed));
442 /* FS_ACC IU and data unit for GID_PN nameserver request */
443 struct ct_iu_gid_pn_resp {
444 struct ct_hdr header;
446 } __attribute__ ((packed));
448 typedef void (*zfcp_send_ct_handler_t)(unsigned long);
451 * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
452 * @port: port where the request is sent to
453 * @req: scatter-gather list for request
454 * @resp: scatter-gather list for response
455 * @req_count: number of elements in request scatter-gather list
456 * @resp_count: number of elements in response scatter-gather list
457 * @handler: handler function (called for response to the request)
458 * @handler_data: data passed to handler function
459 * @timeout: FSF timeout for this request
460 * @completion: completion for synchronization purposes
461 * @status: used to pass error status to calling function
463 struct zfcp_send_ct {
464 struct zfcp_port *port;
465 struct scatterlist *req;
466 struct scatterlist *resp;
467 unsigned int req_count;
468 unsigned int resp_count;
469 zfcp_send_ct_handler_t handler;
470 unsigned long handler_data;
472 struct completion *completion;
476 /* used for name server requests in error recovery */
477 struct zfcp_gid_pn_data {
478 struct zfcp_send_ct ct;
479 struct scatterlist req;
480 struct scatterlist resp;
481 struct ct_iu_gid_pn_req ct_iu_req;
482 struct ct_iu_gid_pn_resp ct_iu_resp;
483 struct zfcp_port *port;
486 typedef void (*zfcp_send_els_handler_t)(unsigned long);
489 * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
490 * @adapter: adapter where request is sent from
491 * @port: port where ELS is destinated (port reference count has to be increased)
492 * @d_id: destiniation id of port where request is sent to
493 * @req: scatter-gather list for request
494 * @resp: scatter-gather list for response
495 * @req_count: number of elements in request scatter-gather list
496 * @resp_count: number of elements in response scatter-gather list
497 * @handler: handler function (called for response to the request)
498 * @handler_data: data passed to handler function
499 * @completion: completion for synchronization purposes
500 * @ls_code: hex code of ELS command
501 * @status: used to pass error status to calling function
503 struct zfcp_send_els {
504 struct zfcp_adapter *adapter;
505 struct zfcp_port *port;
507 struct scatterlist *req;
508 struct scatterlist *resp;
509 unsigned int req_count;
510 unsigned int resp_count;
511 zfcp_send_els_handler_t handler;
512 unsigned long handler_data;
513 struct completion *completion;
518 struct zfcp_qdio_queue {
519 struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
520 u8 first; /* index of next free bfr
521 in queue (free_count>0) */
522 atomic_t count; /* number of free buffers
524 rwlock_t lock; /* lock for operations on queue */
525 int pci_batch; /* SBALs since PCI indication
529 struct zfcp_erp_action {
530 struct list_head list;
531 int action; /* requested action code */
532 struct zfcp_adapter *adapter; /* device which should be recovered */
533 struct zfcp_port *port;
534 struct zfcp_unit *unit;
535 volatile u32 status; /* recovery status */
536 u32 step; /* active step of this erp action */
537 struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
539 struct timer_list timer;
542 struct fsf_latency_record {
548 struct latency_cont {
549 struct fsf_latency_record channel;
550 struct fsf_latency_record fabric;
554 struct zfcp_latencies {
555 struct latency_cont read;
556 struct latency_cont write;
557 struct latency_cont cmd;
561 struct zfcp_adapter {
562 struct list_head list; /* list of adapters */
563 atomic_t refcount; /* reference count */
564 wait_queue_head_t remove_wq; /* can be used to wait for
565 refcount drop to zero */
566 wwn_t peer_wwnn; /* P2P peer WWNN */
567 wwn_t peer_wwpn; /* P2P peer WWPN */
568 u32 peer_d_id; /* P2P peer D_ID */
569 struct ccw_device *ccw_device; /* S/390 ccw device */
570 u32 hydra_version; /* Hydra version */
572 u32 adapter_features; /* FCP channel features */
573 u32 connection_features; /* host connection features */
574 u32 hardware_version; /* of FCP channel */
575 u16 timer_ticks; /* time int for a tick */
576 struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
577 struct list_head port_list_head; /* remote port list */
578 struct list_head port_remove_lh; /* head of ports to be
580 u32 ports; /* number of remote ports */
581 unsigned long req_no; /* unique FSF req number */
582 struct list_head *req_list; /* list of pending reqs */
583 spinlock_t req_list_lock; /* request list lock */
584 struct zfcp_qdio_queue req_q; /* request queue */
585 u32 fsf_req_seq_no; /* FSF cmnd seq number */
586 wait_queue_head_t request_wq; /* can be used to wait for
587 more avaliable SBALs */
588 struct zfcp_qdio_queue resp_q; /* response queue */
589 rwlock_t abort_lock; /* Protects against SCSI
592 atomic_t stat_miss; /* # missing status reads*/
593 struct work_struct stat_work;
594 atomic_t status; /* status of this adapter */
595 struct list_head erp_ready_head; /* error recovery for this
597 struct list_head erp_running_head;
599 struct semaphore erp_ready_sem;
600 wait_queue_head_t erp_thread_wqh;
601 wait_queue_head_t erp_done_wqh;
602 struct zfcp_erp_action erp_action; /* pending error recovery */
603 atomic_t erp_counter;
604 u32 erp_total_count; /* total nr of enqueued erp
606 u32 erp_low_mem_count; /* nr of erp actions waiting
608 struct zfcp_port *nameserver_port; /* adapter's nameserver */
609 debug_info_t *rec_dbf;
610 debug_info_t *hba_dbf;
611 debug_info_t *san_dbf; /* debug feature areas */
612 debug_info_t *scsi_dbf;
613 spinlock_t rec_dbf_lock;
614 spinlock_t hba_dbf_lock;
615 spinlock_t san_dbf_lock;
616 spinlock_t scsi_dbf_lock;
617 struct zfcp_rec_dbf_record rec_dbf_buf;
618 struct zfcp_hba_dbf_record hba_dbf_buf;
619 struct zfcp_san_dbf_record san_dbf_buf;
620 struct zfcp_scsi_dbf_record scsi_dbf_buf;
621 struct zfcp_adapter_mempool pool; /* Adapter memory pools */
622 struct qdio_initialize qdio_init_data; /* for qdio_establish */
623 struct device generic_services; /* directory for WKA ports */
624 struct fc_host_statistics *fc_stats;
625 struct fsf_qtcb_bottom_port *stats_reset_data;
626 unsigned long stats_reset;
627 struct work_struct scan_work;
631 * the struct device sysfs_device must be at the beginning of this structure.
632 * pointer to struct device is used to free port structure in release function
633 * of the device. don't change!
636 struct device sysfs_device; /* sysfs device */
637 struct fc_rport *rport; /* rport of fc transport class */
638 struct list_head list; /* list of remote ports */
639 atomic_t refcount; /* reference count */
640 wait_queue_head_t remove_wq; /* can be used to wait for
641 refcount drop to zero */
642 struct zfcp_adapter *adapter; /* adapter used to access port */
643 struct list_head unit_list_head; /* head of logical unit list */
644 struct list_head unit_remove_lh; /* head of luns to be removed
646 u32 units; /* # of logical units in list */
647 atomic_t status; /* status of this remote port */
648 wwn_t wwnn; /* WWNN if known */
649 wwn_t wwpn; /* WWPN */
651 u32 handle; /* handle assigned by FSF */
652 struct zfcp_erp_action erp_action; /* pending error recovery */
653 atomic_t erp_counter;
655 u32 supported_classes;
658 /* the struct device sysfs_device must be at the beginning of this structure.
659 * pointer to struct device is used to free unit structure in release function
660 * of the device. don't change!
663 struct device sysfs_device; /* sysfs device */
664 struct list_head list; /* list of logical units */
665 atomic_t refcount; /* reference count */
666 wait_queue_head_t remove_wq; /* can be used to wait for
667 refcount drop to zero */
668 struct zfcp_port *port; /* remote port of unit */
669 atomic_t status; /* status of this logical unit */
670 unsigned int scsi_lun; /* own SCSI LUN */
671 fcp_lun_t fcp_lun; /* own FCP_LUN */
672 u32 handle; /* handle assigned by FSF */
673 struct scsi_device *device; /* scsi device struct pointer */
674 struct zfcp_erp_action erp_action; /* pending error recovery */
675 atomic_t erp_counter;
676 struct zfcp_latencies latencies;
680 struct zfcp_fsf_req {
681 struct list_head list; /* list of FSF requests */
682 unsigned long req_id; /* unique request ID */
683 struct zfcp_adapter *adapter; /* adapter request belongs to */
684 u8 sbal_number; /* nr of SBALs free for use */
685 u8 sbal_first; /* first SBAL for this request */
686 u8 sbal_last; /* last SBAL for this request */
687 u8 sbal_limit; /* last possible SBAL for
689 u8 sbale_curr; /* current SBALE during creation
691 u8 sbal_response; /* SBAL used in interrupt */
692 wait_queue_head_t completion_wq; /* can be used by a routine
693 to wait for completion */
694 volatile u32 status; /* status of this request */
695 u32 fsf_command; /* FSF Command copy */
696 struct fsf_qtcb *qtcb; /* address of associated QTCB */
697 u32 seq_no; /* Sequence number of request */
698 unsigned long data; /* private data of request */
699 struct timer_list timer; /* used for erp or scsi er */
700 struct zfcp_erp_action *erp_action; /* used if this request is
701 issued on behalf of erp */
702 mempool_t *pool; /* used if request was alloacted
703 from emergency pool */
704 unsigned long long issued; /* request sent time (STCK) */
705 struct zfcp_unit *unit;
708 typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
712 struct scsi_host_template scsi_host_template;
713 struct scsi_transport_template *scsi_transport_template;
714 atomic_t status; /* Module status flags */
715 struct list_head adapter_list_head; /* head of adapter list */
716 struct list_head adapter_remove_lh; /* head of adapters to be
718 u32 adapters; /* # of adapters in list */
719 rwlock_t config_lock; /* serialises changes
722 struct semaphore config_sema; /* serialises configuration
724 atomic_t loglevel; /* current loglevel */
725 char init_busid[BUS_ID_SIZE];
727 fcp_lun_t init_fcp_lun;
728 struct kmem_cache *fsf_req_qtcb_cache;
729 struct kmem_cache *sr_buffer_cache;
730 struct kmem_cache *gid_pn_cache;
733 /* struct used by memory pools for fsf_requests */
734 struct zfcp_fsf_req_qtcb {
735 struct zfcp_fsf_req fsf_req;
736 struct fsf_qtcb qtcb;
739 /********************** ZFCP SPECIFIC DEFINES ********************************/
741 #define ZFCP_REQ_AUTO_CLEANUP 0x00000002
742 #define ZFCP_WAIT_FOR_SBAL 0x00000004
743 #define ZFCP_REQ_NO_QTCB 0x00000008
745 #define ZFCP_SET 0x00000100
746 #define ZFCP_CLEAR 0x00000200
748 #ifndef atomic_test_mask
749 #define atomic_test_mask(mask, target) \
750 ((atomic_read(target) & mask) == mask)
753 #define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
754 #define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
755 #define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
758 * Helper functions for request ID management.
760 static inline int zfcp_reqlist_hash(unsigned long req_id)
762 return req_id % REQUEST_LIST_SIZE;
765 static inline void zfcp_reqlist_add(struct zfcp_adapter *adapter,
766 struct zfcp_fsf_req *fsf_req)
770 idx = zfcp_reqlist_hash(fsf_req->req_id);
771 list_add_tail(&fsf_req->list, &adapter->req_list[idx]);
774 static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
775 struct zfcp_fsf_req *fsf_req)
777 list_del(&fsf_req->list);
780 static inline struct zfcp_fsf_req *
781 zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
783 struct zfcp_fsf_req *request;
786 idx = zfcp_reqlist_hash(req_id);
787 list_for_each_entry(request, &adapter->req_list[idx], list)
788 if (request->req_id == req_id)
793 static inline struct zfcp_fsf_req *
794 zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req)
796 struct zfcp_fsf_req *request;
799 for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) {
800 list_for_each_entry(request, &adapter->req_list[idx], list)
808 * functions needed for reference/usage counting
812 zfcp_unit_get(struct zfcp_unit *unit)
814 atomic_inc(&unit->refcount);
818 zfcp_unit_put(struct zfcp_unit *unit)
820 if (atomic_dec_return(&unit->refcount) == 0)
821 wake_up(&unit->remove_wq);
825 zfcp_unit_wait(struct zfcp_unit *unit)
827 wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
831 zfcp_port_get(struct zfcp_port *port)
833 atomic_inc(&port->refcount);
837 zfcp_port_put(struct zfcp_port *port)
839 if (atomic_dec_return(&port->refcount) == 0)
840 wake_up(&port->remove_wq);
844 zfcp_port_wait(struct zfcp_port *port)
846 wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
850 zfcp_adapter_get(struct zfcp_adapter *adapter)
852 atomic_inc(&adapter->refcount);
856 zfcp_adapter_put(struct zfcp_adapter *adapter)
858 if (atomic_dec_return(&adapter->refcount) == 0)
859 wake_up(&adapter->remove_wq);
863 zfcp_adapter_wait(struct zfcp_adapter *adapter)
865 wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
868 #endif /* ZFCP_DEF_H */