]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/s390/scsi/zfcp_def.h
[SCSI] zfcp: Small QDIO cleanups
[linux-2.6-omap-h63xx.git] / 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 /**
43  * zfcp_sg_to_address - determine kernel address from struct scatterlist
44  * @list: struct scatterlist
45  * Return: kernel address
46  */
47 static inline void *
48 zfcp_sg_to_address(struct scatterlist *list)
49 {
50         return sg_virt(list);
51 }
52
53 /**
54  * zfcp_address_to_sg - set up struct scatterlist from kernel address
55  * @address: kernel address
56  * @list: struct scatterlist
57  * @size: buffer size
58  */
59 static inline void
60 zfcp_address_to_sg(void *address, struct scatterlist *list, unsigned int size)
61 {
62         sg_set_buf(list, address, size);
63 }
64
65 #define REQUEST_LIST_SIZE 128
66
67 /********************* SCSI SPECIFIC DEFINES *********************************/
68 #define ZFCP_SCSI_ER_TIMEOUT                    (10*HZ)
69
70 /********************* CIO/QDIO SPECIFIC DEFINES *****************************/
71
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
78
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
83
84 /* DMQ bug workaround: don't use last SBALE */
85 #define ZFCP_MAX_SBALES_PER_SBAL        (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
86
87 /* index of last SBALE (with respect to DMQ bug workaround) */
88 #define ZFCP_LAST_SBALE_PER_SBAL        (ZFCP_MAX_SBALES_PER_SBAL - 1)
89
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 */
94
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 */
98
99 #define ZFCP_SBAL_TIMEOUT               (5*HZ)
100
101 #define ZFCP_TYPE2_RECOVERY_TIME        8       /* seconds */
102
103 /********************* FSF SPECIFIC DEFINES *********************************/
104
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
109
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
113
114 /* timeout value for "default timer" for fsf requests */
115 #define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ)
116
117 /*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
118
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;
123
124 #define ZFCP_FC_SERVICE_CLASS_DEFAULT   FSF_CLASS_3
125
126 /* timeout for name-server lookup (in seconds) */
127 #define ZFCP_NS_GID_PN_TIMEOUT          10
128
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
134
135 /* task attribute values in FCP-2 FCP_CMND IU */
136 #define SIMPLE_Q        0
137 #define HEAD_OF_Q       1
138 #define ORDERED_Q       2
139 #define ACA_Q           4
140 #define UNTAGGED        5
141
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
148
149 #define FCP_CDB_LENGTH          16
150
151 #define ZFCP_DID_MASK           0x00FFFFFF
152
153 /* FCP(-2) FCP_CMND IU */
154 struct 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));
165
166 /* FCP(-2) FCP_RSP IU */
167 struct fcp_rsp_iu {
168         u8  reserved0[10];
169         union {
170                 struct {
171                         u8 reserved1:3;
172                         u8 fcp_conf_req:1;
173                         u8 fcp_resid_under:1;
174                         u8 fcp_resid_over:1;
175                         u8 fcp_sns_len_valid:1;
176                         u8 fcp_rsp_len_valid:1;
177                 } bits;
178                 u8 value;
179         } validity;
180         u8  scsi_status;
181         u32 fcp_resid;
182         u32 fcp_sns_len;
183         u32 fcp_rsp_len;
184 } __attribute__((packed));
185
186
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
193
194 /* see fc-fs */
195 #define LS_RSCN  0x61
196 #define LS_LOGO  0x05
197 #define LS_PLOGI 0x03
198
199 struct fcp_rscn_head {
200         u8  command;
201         u8  page_length; /* always 0x04 */
202         u16 payload_len;
203 } __attribute__((packed));
204
205 struct fcp_rscn_element {
206         u8  reserved:2;
207         u8  event_qual:4;
208         u8  addr_format:2;
209         u32 nport_did:24;
210 } __attribute__((packed));
211
212 #define ZFCP_PORT_ADDRESS   0x0
213 #define ZFCP_AREA_ADDRESS   0x1
214 #define ZFCP_DOMAIN_ADDRESS 0x2
215 #define ZFCP_FABRIC_ADDRESS 0x3
216
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
221
222 #define ZFCP_NO_PORTS_PER_AREA    0x100
223 #define ZFCP_NO_PORTS_PER_DOMAIN  0x10000
224 #define ZFCP_NO_PORTS_PER_FABRIC  0x1000000
225
226 /* see fc-ph */
227 struct fcp_logo {
228         u32 command;
229         u32 nport_did;
230         wwn_t nport_wwpn;
231 } __attribute__((packed));
232
233 /*
234  * FC-FS stuff
235  */
236 #define R_A_TOV                         10 /* seconds */
237 #define ZFCP_ELS_TIMEOUT                (2 * R_A_TOV)
238
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
244
245 struct zfcp_ls_rjt_par {
246         u8 action;
247         u8 reason_code;
248         u8 reason_expl;
249         u8 vendor_unique;
250 } __attribute__ ((packed));
251
252 struct zfcp_ls_adisc {
253         u8              code;
254         u8              field[3];
255         u32             hard_nport_id;
256         u64             wwpn;
257         u64             wwnn;
258         u32             nport_id;
259 } __attribute__ ((packed));
260
261 struct zfcp_ls_adisc_acc {
262         u8              code;
263         u8              field[3];
264         u32             hard_nport_id;
265         u64             wwpn;
266         u64             wwnn;
267         u32             nport_id;
268 } __attribute__ ((packed));
269
270 struct zfcp_rc_entry {
271         u8 code;
272         const char *description;
273 };
274
275 /*
276  * FC-GS-2 stuff
277  */
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
289
290 /*
291  * FC-GS-4 stuff
292  */
293 #define ZFCP_CT_TIMEOUT                 (3 * R_A_TOV)
294
295 /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
296
297 /*
298  * Note, the leftmost status byte is common among adapter, port
299  * and unit
300  */
301 #define ZFCP_COMMON_FLAGS                       0xfff00000
302
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
315
316 /* adapter status */
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
326
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
333
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
341
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)
346
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
353
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
369
370 /*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
371
372 #define ZFCP_MAX_ERPS                   3
373
374 #define ZFCP_ERP_FSFREQ_TIMEOUT         (30 * HZ)
375 #define ZFCP_ERP_MEMWAIT_TIMEOUT        HZ
376
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
382
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
392
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
398
399 #define ZFCP_ERP_ACTION_RUNNING                 0x1
400 #define ZFCP_ERP_ACTION_READY                   0x2
401
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
408
409 /************************* STRUCTURE DEFINITIONS *****************************/
410
411 struct zfcp_fsf_req;
412
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;
421 };
422
423 /*
424  * header for CT_IU
425  */
426 struct ct_hdr {
427         u8 revision;            // 0x01
428         u8 in_id[3];            // 0x00
429         u8 gs_type;             // 0xFC Directory Service
430         u8 gs_subtype;          // 0x02 Name Server
431         u8 options;             // 0x00 single bidirectional exchange
432         u8 reserved0;
433         u16 cmd_rsp_code;       // 0x0121 GID_PN, or 0x0100 GA_NXT
434         u16 max_res_size;       // <= (4096 - 16) / 4
435         u8 reserved1;
436         u8 reason_code;
437         u8 reason_code_expl;
438         u8 vendor_unique;
439 } __attribute__ ((packed));
440
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;
445         wwn_t wwpn;
446 } __attribute__ ((packed));
447
448 /* FS_ACC IU and data unit for GID_PN nameserver request */
449 struct ct_iu_gid_pn_resp {
450         struct ct_hdr header;
451         u32 d_id;
452 } __attribute__ ((packed));
453
454 typedef void (*zfcp_send_ct_handler_t)(unsigned long);
455
456 /**
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
468  */
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;
477         int timeout;
478         struct completion *completion;
479         int status;
480 };
481
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;
490 };
491
492 typedef void (*zfcp_send_els_handler_t)(unsigned long);
493
494 /**
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
508  */
509 struct zfcp_send_els {
510         struct zfcp_adapter *adapter;
511         struct zfcp_port *port;
512         u32 d_id;
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;
520         int ls_code;
521         int status;
522 };
523
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
529                                                  in queue */
530         rwlock_t           lock;              /* lock for operations on queue */
531         int                pci_batch;         /* SBALs since PCI indication
532                                                  was last set */
533 };
534
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
544                                          for this action */
545         struct timer_list timer;
546 };
547
548 struct fsf_latency_record {
549         u32 min;
550         u32 max;
551         u64 sum;
552 };
553
554 struct latency_cont {
555         struct fsf_latency_record channel;
556         struct fsf_latency_record fabric;
557         u64 counter;
558 };
559
560 struct zfcp_latencies {
561         struct latency_cont read;
562         struct latency_cont write;
563         struct latency_cont cmd;
564         spinlock_t lock;
565 };
566
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 */
577         u32                     fsf_lic_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
585                                                       removed */
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
596                                                       stack abort/command
597                                                       completion races */
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
602                                                       adapter/devices */
603         struct list_head        erp_running_head;
604         rwlock_t                erp_lock;
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
611                                                       actions */
612         u32                     erp_low_mem_count; /* nr of erp actions waiting
613                                                       for memory */
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;
634 };
635
636 /*
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!
640  */
641 struct zfcp_port {
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
651                                                   list */
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 */
656         u32                    d_id;           /* D_ID */
657         u32                    handle;         /* handle assigned by FSF */
658         struct zfcp_erp_action erp_action;     /* pending error recovery */
659         atomic_t               erp_counter;
660         u32                    maxframe_size;
661         u32                    supported_classes;
662 };
663
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!
667  */
668 struct zfcp_unit {
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;
683 };
684
685 /* FSF request */
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
694                                                   this reuest */
695         u8                     sbale_curr;     /* current SBALE during creation
696                                                   of request */
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;
712 };
713
714 typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
715
716 /* driver data */
717 struct zfcp_data {
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
723                                                        removed */
724         u32                     adapters;           /* # of adapters in list */
725         rwlock_t                config_lock;        /* serialises changes
726                                                        to adapter/port/unit
727                                                        lists */
728         struct semaphore        config_sema;        /* serialises configuration
729                                                        changes */
730         atomic_t                loglevel;            /* current loglevel */
731         char                    init_busid[BUS_ID_SIZE];
732         wwn_t                   init_wwpn;
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;
737 };
738
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
745
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;
750 };
751
752 /********************** ZFCP SPECIFIC DEFINES ********************************/
753
754 #define ZFCP_REQ_AUTO_CLEANUP   0x00000002
755 #define ZFCP_WAIT_FOR_SBAL      0x00000004
756 #define ZFCP_REQ_NO_QTCB        0x00000008
757
758 #define ZFCP_SET                0x00000100
759 #define ZFCP_CLEAR              0x00000200
760
761 #ifndef atomic_test_mask
762 #define atomic_test_mask(mask, target) \
763            ((atomic_read(target) & mask) == mask)
764 #endif
765
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); \
770                 }
771
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))
775
776 /*
777  * Helper functions for request ID management.
778  */
779 static inline int zfcp_reqlist_hash(unsigned long req_id)
780 {
781         return req_id % REQUEST_LIST_SIZE;
782 }
783
784 static inline void zfcp_reqlist_add(struct zfcp_adapter *adapter,
785                                     struct zfcp_fsf_req *fsf_req)
786 {
787         unsigned int idx;
788
789         idx = zfcp_reqlist_hash(fsf_req->req_id);
790         list_add_tail(&fsf_req->list, &adapter->req_list[idx]);
791 }
792
793 static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
794                                        struct zfcp_fsf_req *fsf_req)
795 {
796         list_del(&fsf_req->list);
797 }
798
799 static inline struct zfcp_fsf_req *
800 zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
801 {
802         struct zfcp_fsf_req *request;
803         unsigned int idx;
804
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)
808                         return request;
809         return NULL;
810 }
811
812 static inline struct zfcp_fsf_req *
813 zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req)
814 {
815         struct zfcp_fsf_req *request;
816         unsigned int idx;
817
818         for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) {
819                 list_for_each_entry(request, &adapter->req_list[idx], list)
820                         if (request == req)
821                                 return request;
822         }
823         return NULL;
824 }
825
826 /*
827  *  functions needed for reference/usage counting
828  */
829
830 static inline void
831 zfcp_unit_get(struct zfcp_unit *unit)
832 {
833         atomic_inc(&unit->refcount);
834 }
835
836 static inline void
837 zfcp_unit_put(struct zfcp_unit *unit)
838 {
839         if (atomic_dec_return(&unit->refcount) == 0)
840                 wake_up(&unit->remove_wq);
841 }
842
843 static inline void
844 zfcp_unit_wait(struct zfcp_unit *unit)
845 {
846         wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
847 }
848
849 static inline void
850 zfcp_port_get(struct zfcp_port *port)
851 {
852         atomic_inc(&port->refcount);
853 }
854
855 static inline void
856 zfcp_port_put(struct zfcp_port *port)
857 {
858         if (atomic_dec_return(&port->refcount) == 0)
859                 wake_up(&port->remove_wq);
860 }
861
862 static inline void
863 zfcp_port_wait(struct zfcp_port *port)
864 {
865         wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
866 }
867
868 static inline void
869 zfcp_adapter_get(struct zfcp_adapter *adapter)
870 {
871         atomic_inc(&adapter->refcount);
872 }
873
874 static inline void
875 zfcp_adapter_put(struct zfcp_adapter *adapter)
876 {
877         if (atomic_dec_return(&adapter->refcount) == 0)
878                 wake_up(&adapter->remove_wq);
879 }
880
881 static inline void
882 zfcp_adapter_wait(struct zfcp_adapter *adapter)
883 {
884         wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
885 }
886
887 #endif /* ZFCP_DEF_H */