[SCSI] zfcp: remove all typedefs and replace them with standards
[safe/jmp/linux-2.6] / drivers / s390 / scsi / zfcp_def.h
1 /*
2  * zfcp device driver
3  *
4  * Global definitions for the zfcp device driver.
5  *
6  * Copyright IBM Corporation 2002, 2008
7  */
8
9 #ifndef ZFCP_DEF_H
10 #define ZFCP_DEF_H
11
12 /*************************** INCLUDES *****************************************/
13
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>
33 #include <asm/qdio.h>
34 #include <asm/debug.h>
35 #include <asm/ebcdic.h>
36 #include "zfcp_dbf.h"
37 #include "zfcp_fsf.h"
38
39
40 /********************* GENERAL DEFINES *********************************/
41
42 #define REQUEST_LIST_SIZE 128
43
44 /********************* SCSI SPECIFIC DEFINES *********************************/
45 #define ZFCP_SCSI_ER_TIMEOUT                    (10*HZ)
46
47 /********************* CIO/QDIO SPECIFIC DEFINES *****************************/
48
49 /* Adapter Identification Parameters */
50 #define ZFCP_CONTROL_UNIT_TYPE  0x1731
51 #define ZFCP_CONTROL_UNIT_MODEL 0x03
52 #define ZFCP_DEVICE_TYPE        0x1732
53 #define ZFCP_DEVICE_MODEL       0x03
54 #define ZFCP_DEVICE_MODEL_PRIV  0x04
55
56 /* DMQ bug workaround: don't use last SBALE */
57 #define ZFCP_MAX_SBALES_PER_SBAL        (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
58
59 /* index of last SBALE (with respect to DMQ bug workaround) */
60 #define ZFCP_LAST_SBALE_PER_SBAL        (ZFCP_MAX_SBALES_PER_SBAL - 1)
61
62 /* max. number of (data buffer) SBALEs in largest SBAL chain */
63 #define ZFCP_MAX_SBALES_PER_REQ         \
64         (FSF_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
65         /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
66
67 #define ZFCP_MAX_SECTORS (ZFCP_MAX_SBALES_PER_REQ * 8)
68         /* max. number of (data buffer) SBALEs in largest SBAL chain
69            multiplied with number of sectors per 4k block */
70
71 /********************* FSF SPECIFIC DEFINES *********************************/
72
73 /* ATTENTION: value must not be used by hardware */
74 #define FSF_QTCB_UNSOLICITED_STATUS             0x6305
75
76 /* timeout value for "default timer" for fsf requests */
77 #define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ)
78
79 /*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
80
81 /* timeout for name-server lookup (in seconds) */
82 #define ZFCP_NS_GID_PN_TIMEOUT          10
83
84 /* task attribute values in FCP-2 FCP_CMND IU */
85 #define SIMPLE_Q        0
86 #define HEAD_OF_Q       1
87 #define ORDERED_Q       2
88 #define ACA_Q           4
89 #define UNTAGGED        5
90
91 /* task management flags in FCP-2 FCP_CMND IU */
92 #define FCP_CLEAR_ACA           0x40
93 #define FCP_TARGET_RESET        0x20
94 #define FCP_LOGICAL_UNIT_RESET  0x10
95 #define FCP_CLEAR_TASK_SET      0x04
96 #define FCP_ABORT_TASK_SET      0x02
97
98 #define FCP_CDB_LENGTH          16
99
100 #define ZFCP_DID_MASK           0x00FFFFFF
101
102 /* FCP(-2) FCP_CMND IU */
103 struct fcp_cmnd_iu {
104         u64 fcp_lun;       /* FCP logical unit number */
105         u8  crn;                   /* command reference number */
106         u8  reserved0:5;           /* reserved */
107         u8  task_attribute:3;      /* task attribute */
108         u8  task_management_flags; /* task management flags */
109         u8  add_fcp_cdb_length:6;  /* additional FCP_CDB length */
110         u8  rddata:1;              /* read data */
111         u8  wddata:1;              /* write data */
112         u8  fcp_cdb[FCP_CDB_LENGTH];
113 } __attribute__((packed));
114
115 /* FCP(-2) FCP_RSP IU */
116 struct fcp_rsp_iu {
117         u8  reserved0[10];
118         union {
119                 struct {
120                         u8 reserved1:3;
121                         u8 fcp_conf_req:1;
122                         u8 fcp_resid_under:1;
123                         u8 fcp_resid_over:1;
124                         u8 fcp_sns_len_valid:1;
125                         u8 fcp_rsp_len_valid:1;
126                 } bits;
127                 u8 value;
128         } validity;
129         u8  scsi_status;
130         u32 fcp_resid;
131         u32 fcp_sns_len;
132         u32 fcp_rsp_len;
133 } __attribute__((packed));
134
135
136 #define RSP_CODE_GOOD            0
137 #define RSP_CODE_LENGTH_MISMATCH 1
138 #define RSP_CODE_FIELD_INVALID   2
139 #define RSP_CODE_RO_MISMATCH     3
140 #define RSP_CODE_TASKMAN_UNSUPP  4
141 #define RSP_CODE_TASKMAN_FAILED  5
142
143 /* see fc-fs */
144 #define LS_RSCN  0x61
145 #define LS_LOGO  0x05
146 #define LS_PLOGI 0x03
147
148 struct fcp_rscn_head {
149         u8  command;
150         u8  page_length; /* always 0x04 */
151         u16 payload_len;
152 } __attribute__((packed));
153
154 struct fcp_rscn_element {
155         u8  reserved:2;
156         u8  event_qual:4;
157         u8  addr_format:2;
158         u32 nport_did:24;
159 } __attribute__((packed));
160
161 #define ZFCP_PORT_ADDRESS   0x0
162 #define ZFCP_AREA_ADDRESS   0x1
163 #define ZFCP_DOMAIN_ADDRESS 0x2
164 #define ZFCP_FABRIC_ADDRESS 0x3
165
166 #define ZFCP_PORTS_RANGE_PORT   0xFFFFFF
167 #define ZFCP_PORTS_RANGE_AREA   0xFFFF00
168 #define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
169 #define ZFCP_PORTS_RANGE_FABRIC 0x000000
170
171 #define ZFCP_NO_PORTS_PER_AREA    0x100
172 #define ZFCP_NO_PORTS_PER_DOMAIN  0x10000
173 #define ZFCP_NO_PORTS_PER_FABRIC  0x1000000
174
175 /* see fc-ph */
176 struct fcp_logo {
177         u32 command;
178         u32 nport_did;
179         u64 nport_wwpn;
180 } __attribute__((packed));
181
182 /*
183  * FC-FS stuff
184  */
185 #define R_A_TOV                         10 /* seconds */
186
187 #define ZFCP_LS_RLS                     0x0f
188 #define ZFCP_LS_ADISC                   0x52
189 #define ZFCP_LS_RPS                     0x56
190 #define ZFCP_LS_RSCN                    0x61
191 #define ZFCP_LS_RNID                    0x78
192
193 struct zfcp_ls_adisc {
194         u8              code;
195         u8              field[3];
196         u32             hard_nport_id;
197         u64             wwpn;
198         u64             wwnn;
199         u32             nport_id;
200 } __attribute__ ((packed));
201
202 /*
203  * FC-GS-2 stuff
204  */
205 #define ZFCP_CT_REVISION                0x01
206 #define ZFCP_CT_DIRECTORY_SERVICE       0xFC
207 #define ZFCP_CT_NAME_SERVER             0x02
208 #define ZFCP_CT_SYNCHRONOUS             0x00
209 #define ZFCP_CT_SCSI_FCP                0x08
210 #define ZFCP_CT_UNABLE_TO_PERFORM_CMD   0x09
211 #define ZFCP_CT_GID_PN                  0x0121
212 #define ZFCP_CT_GPN_FT                  0x0172
213 #define ZFCP_CT_MAX_SIZE                0x1020
214 #define ZFCP_CT_ACCEPT                  0x8002
215 #define ZFCP_CT_REJECT                  0x8001
216
217 /*
218  * FC-GS-4 stuff
219  */
220 #define ZFCP_CT_TIMEOUT                 (3 * R_A_TOV)
221
222 /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
223
224 /*
225  * Note, the leftmost status byte is common among adapter, port
226  * and unit
227  */
228 #define ZFCP_COMMON_FLAGS                       0xfff00000
229
230 /* common status bits */
231 #define ZFCP_STATUS_COMMON_REMOVE               0x80000000
232 #define ZFCP_STATUS_COMMON_RUNNING              0x40000000
233 #define ZFCP_STATUS_COMMON_ERP_FAILED           0x20000000
234 #define ZFCP_STATUS_COMMON_UNBLOCKED            0x10000000
235 #define ZFCP_STATUS_COMMON_OPEN                 0x04000000
236 #define ZFCP_STATUS_COMMON_ERP_INUSE            0x01000000
237 #define ZFCP_STATUS_COMMON_ACCESS_DENIED        0x00800000
238 #define ZFCP_STATUS_COMMON_ACCESS_BOXED         0x00400000
239 #define ZFCP_STATUS_COMMON_NOESC                0x00200000
240
241 /* adapter status */
242 #define ZFCP_STATUS_ADAPTER_QDIOUP              0x00000002
243 #define ZFCP_STATUS_ADAPTER_XCONFIG_OK          0x00000008
244 #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT       0x00000010
245 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP       0x00000020
246 #define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL     0x00000080
247 #define ZFCP_STATUS_ADAPTER_ERP_PENDING         0x00000100
248 #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED      0x00000200
249
250 /* FC-PH/FC-GS well-known address identifiers for generic services */
251 #define ZFCP_DID_WKA                            0xFFFFF0
252 #define ZFCP_DID_MANAGEMENT_SERVICE             0xFFFFFA
253 #define ZFCP_DID_TIME_SERVICE                   0xFFFFFB
254 #define ZFCP_DID_DIRECTORY_SERVICE              0xFFFFFC
255 #define ZFCP_DID_ALIAS_SERVICE                  0xFFFFF8
256 #define ZFCP_DID_KEY_DISTRIBUTION_SERVICE       0xFFFFF7
257
258 /* remote port status */
259 #define ZFCP_STATUS_PORT_PHYS_OPEN              0x00000001
260 #define ZFCP_STATUS_PORT_DID_DID                0x00000002
261 #define ZFCP_STATUS_PORT_PHYS_CLOSING           0x00000004
262 #define ZFCP_STATUS_PORT_NO_WWPN                0x00000008
263 #define ZFCP_STATUS_PORT_INVALID_WWPN           0x00000020
264
265 /* well known address (WKA) port status*/
266 enum zfcp_wka_status {
267         ZFCP_WKA_PORT_OFFLINE,
268         ZFCP_WKA_PORT_CLOSING,
269         ZFCP_WKA_PORT_OPENING,
270         ZFCP_WKA_PORT_ONLINE,
271 };
272
273 /* logical unit status */
274 #define ZFCP_STATUS_UNIT_SHARED                 0x00000004
275 #define ZFCP_STATUS_UNIT_READONLY               0x00000008
276 #define ZFCP_STATUS_UNIT_REGISTERED             0x00000010
277 #define ZFCP_STATUS_UNIT_SCSI_WORK_PENDING      0x00000020
278
279 /* FSF request status (this does not have a common part) */
280 #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT      0x00000002
281 #define ZFCP_STATUS_FSFREQ_COMPLETED            0x00000004
282 #define ZFCP_STATUS_FSFREQ_ERROR                0x00000008
283 #define ZFCP_STATUS_FSFREQ_CLEANUP              0x00000010
284 #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED       0x00000040
285 #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED       0x00000080
286 #define ZFCP_STATUS_FSFREQ_ABORTED              0x00000100
287 #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED         0x00000200
288 #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP        0x00000400
289 #define ZFCP_STATUS_FSFREQ_RETRY                0x00000800
290 #define ZFCP_STATUS_FSFREQ_DISMISSED            0x00001000
291
292 /************************* STRUCTURE DEFINITIONS *****************************/
293
294 struct zfcp_fsf_req;
295
296 /* holds various memory pools of an adapter */
297 struct zfcp_adapter_mempool {
298         mempool_t *fsf_req_erp;
299         mempool_t *fsf_req_scsi;
300         mempool_t *fsf_req_abort;
301         mempool_t *fsf_req_status_read;
302         mempool_t *data_status_read;
303         mempool_t *data_gid_pn;
304 };
305
306 /*
307  * header for CT_IU
308  */
309 struct ct_hdr {
310         u8 revision;            // 0x01
311         u8 in_id[3];            // 0x00
312         u8 gs_type;             // 0xFC Directory Service
313         u8 gs_subtype;          // 0x02 Name Server
314         u8 options;             // 0x00 single bidirectional exchange
315         u8 reserved0;
316         u16 cmd_rsp_code;       // 0x0121 GID_PN, or 0x0100 GA_NXT
317         u16 max_res_size;       // <= (4096 - 16) / 4
318         u8 reserved1;
319         u8 reason_code;
320         u8 reason_code_expl;
321         u8 vendor_unique;
322 } __attribute__ ((packed));
323
324 /* nameserver request CT_IU -- for requests where
325  * a port name is required */
326 struct ct_iu_gid_pn_req {
327         struct ct_hdr header;
328         u64 wwpn;
329 } __attribute__ ((packed));
330
331 /* FS_ACC IU and data unit for GID_PN nameserver request */
332 struct ct_iu_gid_pn_resp {
333         struct ct_hdr header;
334         u32 d_id;
335 } __attribute__ ((packed));
336
337 /**
338  * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
339  * @wka_port: port where the request is sent to
340  * @req: scatter-gather list for request
341  * @resp: scatter-gather list for response
342  * @req_count: number of elements in request scatter-gather list
343  * @resp_count: number of elements in response scatter-gather list
344  * @handler: handler function (called for response to the request)
345  * @handler_data: data passed to handler function
346  * @timeout: FSF timeout for this request
347  * @completion: completion for synchronization purposes
348  * @status: used to pass error status to calling function
349  */
350 struct zfcp_send_ct {
351         struct zfcp_wka_port *wka_port;
352         struct scatterlist *req;
353         struct scatterlist *resp;
354         unsigned int req_count;
355         unsigned int resp_count;
356         void (*handler)(unsigned long);
357         unsigned long handler_data;
358         int timeout;
359         struct completion *completion;
360         int status;
361 };
362
363 /* used for name server requests in error recovery */
364 struct zfcp_gid_pn_data {
365         struct zfcp_send_ct ct;
366         struct scatterlist req;
367         struct scatterlist resp;
368         struct ct_iu_gid_pn_req ct_iu_req;
369         struct ct_iu_gid_pn_resp ct_iu_resp;
370         struct zfcp_port *port;
371 };
372
373 /**
374  * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
375  * @adapter: adapter where request is sent from
376  * @port: port where ELS is destinated (port reference count has to be increased)
377  * @d_id: destiniation id of port where request is sent to
378  * @req: scatter-gather list for request
379  * @resp: scatter-gather list for response
380  * @req_count: number of elements in request scatter-gather list
381  * @resp_count: number of elements in response scatter-gather list
382  * @handler: handler function (called for response to the request)
383  * @handler_data: data passed to handler function
384  * @completion: completion for synchronization purposes
385  * @ls_code: hex code of ELS command
386  * @status: used to pass error status to calling function
387  */
388 struct zfcp_send_els {
389         struct zfcp_adapter *adapter;
390         struct zfcp_port *port;
391         u32 d_id;
392         struct scatterlist *req;
393         struct scatterlist *resp;
394         unsigned int req_count;
395         unsigned int resp_count;
396         void (*handler)(unsigned long);
397         unsigned long handler_data;
398         struct completion *completion;
399         int ls_code;
400         int status;
401 };
402
403 struct zfcp_wka_port {
404         struct zfcp_adapter     *adapter;
405         wait_queue_head_t       completion_wq;
406         enum zfcp_wka_status    status;
407         atomic_t                refcount;
408         u32                     d_id;
409         u32                     handle;
410         struct mutex            mutex;
411         struct delayed_work     work;
412 };
413
414 struct zfcp_qdio_queue {
415         struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
416         u8                 first;             /* index of next free bfr
417                                                  in queue (free_count>0) */
418         atomic_t           count;             /* number of free buffers
419                                                  in queue */
420         spinlock_t         lock;              /* lock for operations on queue */
421         int                pci_batch;         /* SBALs since PCI indication
422                                                  was last set */
423 };
424
425 struct zfcp_erp_action {
426         struct list_head list;
427         int action;                   /* requested action code */
428         struct zfcp_adapter *adapter; /* device which should be recovered */
429         struct zfcp_port *port;
430         struct zfcp_unit *unit;
431         u32             status;       /* recovery status */
432         u32 step;                     /* active step of this erp action */
433         struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
434                                          for this action */
435         struct timer_list timer;
436 };
437
438 struct fsf_latency_record {
439         u32 min;
440         u32 max;
441         u64 sum;
442 };
443
444 struct latency_cont {
445         struct fsf_latency_record channel;
446         struct fsf_latency_record fabric;
447         u64 counter;
448 };
449
450 struct zfcp_latencies {
451         struct latency_cont read;
452         struct latency_cont write;
453         struct latency_cont cmd;
454         spinlock_t lock;
455 };
456
457 struct zfcp_adapter {
458         struct list_head        list;              /* list of adapters */
459         atomic_t                refcount;          /* reference count */
460         wait_queue_head_t       remove_wq;         /* can be used to wait for
461                                                       refcount drop to zero */
462         u64                     peer_wwnn;         /* P2P peer WWNN */
463         u64                     peer_wwpn;         /* P2P peer WWPN */
464         u32                     peer_d_id;         /* P2P peer D_ID */
465         struct ccw_device       *ccw_device;       /* S/390 ccw device */
466         u32                     hydra_version;     /* Hydra version */
467         u32                     fsf_lic_version;
468         u32                     adapter_features;  /* FCP channel features */
469         u32                     connection_features; /* host connection features */
470         u32                     hardware_version;  /* of FCP channel */
471         u16                     timer_ticks;       /* time int for a tick */
472         struct Scsi_Host        *scsi_host;        /* Pointer to mid-layer */
473         struct list_head        port_list_head;    /* remote port list */
474         struct list_head        port_remove_lh;    /* head of ports to be
475                                                       removed */
476         u32                     ports;             /* number of remote ports */
477         unsigned long           req_no;            /* unique FSF req number */
478         struct list_head        *req_list;         /* list of pending reqs */
479         spinlock_t              req_list_lock;     /* request list lock */
480         struct zfcp_qdio_queue  req_q;             /* request queue */
481         u32                     fsf_req_seq_no;    /* FSF cmnd seq number */
482         wait_queue_head_t       request_wq;        /* can be used to wait for
483                                                       more avaliable SBALs */
484         struct zfcp_qdio_queue  resp_q;    /* response queue */
485         rwlock_t                abort_lock;        /* Protects against SCSI
486                                                       stack abort/command
487                                                       completion races */
488         atomic_t                stat_miss;         /* # missing status reads*/
489         struct work_struct      stat_work;
490         atomic_t                status;            /* status of this adapter */
491         struct list_head        erp_ready_head;    /* error recovery for this
492                                                       adapter/devices */
493         struct list_head        erp_running_head;
494         rwlock_t                erp_lock;
495         struct semaphore        erp_ready_sem;
496         wait_queue_head_t       erp_thread_wqh;
497         wait_queue_head_t       erp_done_wqh;
498         struct zfcp_erp_action  erp_action;        /* pending error recovery */
499         atomic_t                erp_counter;
500         u32                     erp_total_count;   /* total nr of enqueued erp
501                                                       actions */
502         u32                     erp_low_mem_count; /* nr of erp actions waiting
503                                                       for memory */
504         struct zfcp_wka_port    nsp;               /* adapter's nameserver */
505         debug_info_t            *rec_dbf;
506         debug_info_t            *hba_dbf;
507         debug_info_t            *san_dbf;          /* debug feature areas */
508         debug_info_t            *scsi_dbf;
509         spinlock_t              rec_dbf_lock;
510         spinlock_t              hba_dbf_lock;
511         spinlock_t              san_dbf_lock;
512         spinlock_t              scsi_dbf_lock;
513         struct zfcp_rec_dbf_record      rec_dbf_buf;
514         struct zfcp_hba_dbf_record      hba_dbf_buf;
515         struct zfcp_san_dbf_record      san_dbf_buf;
516         struct zfcp_scsi_dbf_record     scsi_dbf_buf;
517         struct zfcp_adapter_mempool     pool;      /* Adapter memory pools */
518         struct qdio_initialize  qdio_init_data;    /* for qdio_establish */
519         struct device           generic_services;  /* directory for WKA ports */
520         struct fc_host_statistics *fc_stats;
521         struct fsf_qtcb_bottom_port *stats_reset_data;
522         unsigned long           stats_reset;
523         struct work_struct      scan_work;
524         atomic_t                qdio_outb_full;    /* queue full incidents */
525 };
526
527 struct zfcp_port {
528         struct device          sysfs_device;   /* sysfs device */
529         struct fc_rport        *rport;         /* rport of fc transport class */
530         struct list_head       list;           /* list of remote ports */
531         atomic_t               refcount;       /* reference count */
532         wait_queue_head_t      remove_wq;      /* can be used to wait for
533                                                   refcount drop to zero */
534         struct zfcp_adapter    *adapter;       /* adapter used to access port */
535         struct list_head       unit_list_head; /* head of logical unit list */
536         struct list_head       unit_remove_lh; /* head of luns to be removed
537                                                   list */
538         u32                    units;          /* # of logical units in list */
539         atomic_t               status;         /* status of this remote port */
540         u64                    wwnn;           /* WWNN if known */
541         u64                    wwpn;           /* WWPN */
542         u32                    d_id;           /* D_ID */
543         u32                    handle;         /* handle assigned by FSF */
544         struct zfcp_erp_action erp_action;     /* pending error recovery */
545         atomic_t               erp_counter;
546         u32                    maxframe_size;
547         u32                    supported_classes;
548         struct work_struct     gid_pn_work;
549 };
550
551 struct zfcp_unit {
552         struct device          sysfs_device;   /* sysfs device */
553         struct list_head       list;           /* list of logical units */
554         atomic_t               refcount;       /* reference count */
555         wait_queue_head_t      remove_wq;      /* can be used to wait for
556                                                   refcount drop to zero */
557         struct zfcp_port       *port;          /* remote port of unit */
558         atomic_t               status;         /* status of this logical unit */
559         unsigned int           scsi_lun;       /* own SCSI LUN */
560         u64                    fcp_lun;        /* own FCP_LUN */
561         u32                    handle;         /* handle assigned by FSF */
562         struct scsi_device     *device;        /* scsi device struct pointer */
563         struct zfcp_erp_action erp_action;     /* pending error recovery */
564         atomic_t               erp_counter;
565         struct zfcp_latencies   latencies;
566 };
567
568 /* FSF request */
569 struct zfcp_fsf_req {
570         struct list_head       list;           /* list of FSF requests */
571         unsigned long          req_id;         /* unique request ID */
572         struct zfcp_adapter    *adapter;       /* adapter request belongs to */
573         u8                     sbal_number;    /* nr of SBALs free for use */
574         u8                     sbal_first;     /* first SBAL for this request */
575         u8                     sbal_last;      /* last SBAL for this request */
576         u8                     sbal_limit;      /* last possible SBAL for
577                                                   this reuest */
578         u8                     sbale_curr;     /* current SBALE during creation
579                                                   of request */
580         u8                      sbal_response;  /* SBAL used in interrupt */
581         wait_queue_head_t      completion_wq;  /* can be used by a routine
582                                                   to wait for completion */
583         u32                     status;        /* status of this request */
584         u32                    fsf_command;    /* FSF Command copy */
585         struct fsf_qtcb        *qtcb;          /* address of associated QTCB */
586         u32                    seq_no;         /* Sequence number of request */
587         void                    *data;           /* private data of request */
588         struct timer_list     timer;           /* used for erp or scsi er */
589         struct zfcp_erp_action *erp_action;    /* used if this request is
590                                                   issued on behalf of erp */
591         mempool_t              *pool;          /* used if request was alloacted
592                                                   from emergency pool */
593         unsigned long long     issued;         /* request sent time (STCK) */
594         struct zfcp_unit       *unit;
595         void                    (*handler)(struct zfcp_fsf_req *);
596 };
597
598 /* driver data */
599 struct zfcp_data {
600         struct scsi_host_template scsi_host_template;
601         struct scsi_transport_template *scsi_transport_template;
602         atomic_t                status;             /* Module status flags */
603         struct list_head        adapter_list_head;  /* head of adapter list */
604         struct list_head        adapter_remove_lh;  /* head of adapters to be
605                                                        removed */
606         u32                     adapters;           /* # of adapters in list */
607         rwlock_t                config_lock;        /* serialises changes
608                                                        to adapter/port/unit
609                                                        lists */
610         struct semaphore        config_sema;        /* serialises configuration
611                                                        changes */
612         atomic_t                loglevel;            /* current loglevel */
613         char                    init_busid[BUS_ID_SIZE];
614         u64                     init_wwpn;
615         u64                     init_fcp_lun;
616         struct kmem_cache       *fsf_req_qtcb_cache;
617         struct kmem_cache       *sr_buffer_cache;
618         struct kmem_cache       *gid_pn_cache;
619 };
620
621 /* struct used by memory pools for fsf_requests */
622 struct zfcp_fsf_req_qtcb {
623         struct zfcp_fsf_req fsf_req;
624         struct fsf_qtcb qtcb;
625 };
626
627 /********************** ZFCP SPECIFIC DEFINES ********************************/
628
629 #define ZFCP_REQ_AUTO_CLEANUP   0x00000002
630 #define ZFCP_REQ_NO_QTCB        0x00000008
631
632 #define ZFCP_SET                0x00000100
633 #define ZFCP_CLEAR              0x00000200
634
635 #define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
636
637 /*
638  * Helper functions for request ID management.
639  */
640 static inline int zfcp_reqlist_hash(unsigned long req_id)
641 {
642         return req_id % REQUEST_LIST_SIZE;
643 }
644
645 static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
646                                        struct zfcp_fsf_req *fsf_req)
647 {
648         list_del(&fsf_req->list);
649 }
650
651 static inline struct zfcp_fsf_req *
652 zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
653 {
654         struct zfcp_fsf_req *request;
655         unsigned int idx;
656
657         idx = zfcp_reqlist_hash(req_id);
658         list_for_each_entry(request, &adapter->req_list[idx], list)
659                 if (request->req_id == req_id)
660                         return request;
661         return NULL;
662 }
663
664 static inline struct zfcp_fsf_req *
665 zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req)
666 {
667         struct zfcp_fsf_req *request;
668         unsigned int idx;
669
670         for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) {
671                 list_for_each_entry(request, &adapter->req_list[idx], list)
672                         if (request == req)
673                                 return request;
674         }
675         return NULL;
676 }
677
678 /*
679  *  functions needed for reference/usage counting
680  */
681
682 static inline void
683 zfcp_unit_get(struct zfcp_unit *unit)
684 {
685         atomic_inc(&unit->refcount);
686 }
687
688 static inline void
689 zfcp_unit_put(struct zfcp_unit *unit)
690 {
691         if (atomic_dec_return(&unit->refcount) == 0)
692                 wake_up(&unit->remove_wq);
693 }
694
695 static inline void
696 zfcp_port_get(struct zfcp_port *port)
697 {
698         atomic_inc(&port->refcount);
699 }
700
701 static inline void
702 zfcp_port_put(struct zfcp_port *port)
703 {
704         if (atomic_dec_return(&port->refcount) == 0)
705                 wake_up(&port->remove_wq);
706 }
707
708 static inline void
709 zfcp_adapter_get(struct zfcp_adapter *adapter)
710 {
711         atomic_inc(&adapter->refcount);
712 }
713
714 static inline void
715 zfcp_adapter_put(struct zfcp_adapter *adapter)
716 {
717         if (atomic_dec_return(&adapter->refcount) == 0)
718                 wake_up(&adapter->remove_wq);
719 }
720
721 #endif /* ZFCP_DEF_H */