]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/s390/scsi/zfcp_def.h
[SCSI] zfcp: Cleanup of code in zfcp_scsi.c
[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 /* task attribute values in FCP-2 FCP_CMND IU */
130 #define SIMPLE_Q        0
131 #define HEAD_OF_Q       1
132 #define ORDERED_Q       2
133 #define ACA_Q           4
134 #define UNTAGGED        5
135
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
142
143 #define FCP_CDB_LENGTH          16
144
145 #define ZFCP_DID_MASK           0x00FFFFFF
146
147 /* FCP(-2) FCP_CMND IU */
148 struct 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));
159
160 /* FCP(-2) FCP_RSP IU */
161 struct fcp_rsp_iu {
162         u8  reserved0[10];
163         union {
164                 struct {
165                         u8 reserved1:3;
166                         u8 fcp_conf_req:1;
167                         u8 fcp_resid_under:1;
168                         u8 fcp_resid_over:1;
169                         u8 fcp_sns_len_valid:1;
170                         u8 fcp_rsp_len_valid:1;
171                 } bits;
172                 u8 value;
173         } validity;
174         u8  scsi_status;
175         u32 fcp_resid;
176         u32 fcp_sns_len;
177         u32 fcp_rsp_len;
178 } __attribute__((packed));
179
180
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
187
188 /* see fc-fs */
189 #define LS_RSCN  0x61
190 #define LS_LOGO  0x05
191 #define LS_PLOGI 0x03
192
193 struct fcp_rscn_head {
194         u8  command;
195         u8  page_length; /* always 0x04 */
196         u16 payload_len;
197 } __attribute__((packed));
198
199 struct fcp_rscn_element {
200         u8  reserved:2;
201         u8  event_qual:4;
202         u8  addr_format:2;
203         u32 nport_did:24;
204 } __attribute__((packed));
205
206 #define ZFCP_PORT_ADDRESS   0x0
207 #define ZFCP_AREA_ADDRESS   0x1
208 #define ZFCP_DOMAIN_ADDRESS 0x2
209 #define ZFCP_FABRIC_ADDRESS 0x3
210
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
215
216 #define ZFCP_NO_PORTS_PER_AREA    0x100
217 #define ZFCP_NO_PORTS_PER_DOMAIN  0x10000
218 #define ZFCP_NO_PORTS_PER_FABRIC  0x1000000
219
220 /* see fc-ph */
221 struct fcp_logo {
222         u32 command;
223         u32 nport_did;
224         wwn_t nport_wwpn;
225 } __attribute__((packed));
226
227 /*
228  * FC-FS stuff
229  */
230 #define R_A_TOV                         10 /* seconds */
231 #define ZFCP_ELS_TIMEOUT                (2 * R_A_TOV)
232
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
238
239 struct zfcp_ls_rjt_par {
240         u8 action;
241         u8 reason_code;
242         u8 reason_expl;
243         u8 vendor_unique;
244 } __attribute__ ((packed));
245
246 struct zfcp_ls_adisc {
247         u8              code;
248         u8              field[3];
249         u32             hard_nport_id;
250         u64             wwpn;
251         u64             wwnn;
252         u32             nport_id;
253 } __attribute__ ((packed));
254
255 struct zfcp_ls_adisc_acc {
256         u8              code;
257         u8              field[3];
258         u32             hard_nport_id;
259         u64             wwpn;
260         u64             wwnn;
261         u32             nport_id;
262 } __attribute__ ((packed));
263
264 struct zfcp_rc_entry {
265         u8 code;
266         const char *description;
267 };
268
269 /*
270  * FC-GS-2 stuff
271  */
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
283
284 /*
285  * FC-GS-4 stuff
286  */
287 #define ZFCP_CT_TIMEOUT                 (3 * R_A_TOV)
288
289 /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
290
291 /*
292  * Note, the leftmost status byte is common among adapter, port
293  * and unit
294  */
295 #define ZFCP_COMMON_FLAGS                       0xfff00000
296
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
309
310 /* adapter status */
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
320
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
327
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
335
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)
340
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
347
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
363
364 /*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
365
366 #define ZFCP_MAX_ERPS                   3
367
368 #define ZFCP_ERP_FSFREQ_TIMEOUT         (30 * HZ)
369 #define ZFCP_ERP_MEMWAIT_TIMEOUT        HZ
370
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
376
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
386
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
392
393 #define ZFCP_ERP_ACTION_RUNNING                 0x1
394 #define ZFCP_ERP_ACTION_READY                   0x2
395
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
402
403 /************************* STRUCTURE DEFINITIONS *****************************/
404
405 struct zfcp_fsf_req;
406
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;
415 };
416
417 /*
418  * header for CT_IU
419  */
420 struct ct_hdr {
421         u8 revision;            // 0x01
422         u8 in_id[3];            // 0x00
423         u8 gs_type;             // 0xFC Directory Service
424         u8 gs_subtype;          // 0x02 Name Server
425         u8 options;             // 0x00 single bidirectional exchange
426         u8 reserved0;
427         u16 cmd_rsp_code;       // 0x0121 GID_PN, or 0x0100 GA_NXT
428         u16 max_res_size;       // <= (4096 - 16) / 4
429         u8 reserved1;
430         u8 reason_code;
431         u8 reason_code_expl;
432         u8 vendor_unique;
433 } __attribute__ ((packed));
434
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;
439         wwn_t wwpn;
440 } __attribute__ ((packed));
441
442 /* FS_ACC IU and data unit for GID_PN nameserver request */
443 struct ct_iu_gid_pn_resp {
444         struct ct_hdr header;
445         u32 d_id;
446 } __attribute__ ((packed));
447
448 typedef void (*zfcp_send_ct_handler_t)(unsigned long);
449
450 /**
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
462  */
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;
471         int timeout;
472         struct completion *completion;
473         int status;
474 };
475
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;
484 };
485
486 typedef void (*zfcp_send_els_handler_t)(unsigned long);
487
488 /**
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
502  */
503 struct zfcp_send_els {
504         struct zfcp_adapter *adapter;
505         struct zfcp_port *port;
506         u32 d_id;
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;
514         int ls_code;
515         int status;
516 };
517
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
523                                                  in queue */
524         rwlock_t           lock;              /* lock for operations on queue */
525         int                pci_batch;         /* SBALs since PCI indication
526                                                  was last set */
527 };
528
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
538                                          for this action */
539         struct timer_list timer;
540 };
541
542 struct fsf_latency_record {
543         u32 min;
544         u32 max;
545         u64 sum;
546 };
547
548 struct latency_cont {
549         struct fsf_latency_record channel;
550         struct fsf_latency_record fabric;
551         u64 counter;
552 };
553
554 struct zfcp_latencies {
555         struct latency_cont read;
556         struct latency_cont write;
557         struct latency_cont cmd;
558         spinlock_t lock;
559 };
560
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 */
571         u32                     fsf_lic_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
579                                                       removed */
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
590                                                       stack abort/command
591                                                       completion races */
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
596                                                       adapter/devices */
597         struct list_head        erp_running_head;
598         rwlock_t                erp_lock;
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
605                                                       actions */
606         u32                     erp_low_mem_count; /* nr of erp actions waiting
607                                                       for memory */
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;
628 };
629
630 /*
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!
634  */
635 struct zfcp_port {
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
645                                                   list */
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 */
650         u32                    d_id;           /* D_ID */
651         u32                    handle;         /* handle assigned by FSF */
652         struct zfcp_erp_action erp_action;     /* pending error recovery */
653         atomic_t               erp_counter;
654         u32                    maxframe_size;
655         u32                    supported_classes;
656 };
657
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!
661  */
662 struct zfcp_unit {
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;
677 };
678
679 /* FSF request */
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
688                                                   this reuest */
689         u8                     sbale_curr;     /* current SBALE during creation
690                                                   of request */
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;
706 };
707
708 typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
709
710 /* driver data */
711 struct zfcp_data {
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
717                                                        removed */
718         u32                     adapters;           /* # of adapters in list */
719         rwlock_t                config_lock;        /* serialises changes
720                                                        to adapter/port/unit
721                                                        lists */
722         struct semaphore        config_sema;        /* serialises configuration
723                                                        changes */
724         atomic_t                loglevel;            /* current loglevel */
725         char                    init_busid[BUS_ID_SIZE];
726         wwn_t                   init_wwpn;
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;
731 };
732
733 /* number of elements for various memory pools */
734 #define ZFCP_POOL_FSF_REQ_ERP_NR        1
735 #define ZFCP_POOL_FSF_REQ_SCSI_NR       1
736 #define ZFCP_POOL_FSF_REQ_ABORT_NR      1
737 #define ZFCP_POOL_STATUS_READ_NR        FSF_STATUS_READS_RECOM
738 #define ZFCP_POOL_DATA_GID_PN_NR        1
739
740 /* struct used by memory pools for fsf_requests */
741 struct zfcp_fsf_req_qtcb {
742         struct zfcp_fsf_req fsf_req;
743         struct fsf_qtcb qtcb;
744 };
745
746 /********************** ZFCP SPECIFIC DEFINES ********************************/
747
748 #define ZFCP_REQ_AUTO_CLEANUP   0x00000002
749 #define ZFCP_WAIT_FOR_SBAL      0x00000004
750 #define ZFCP_REQ_NO_QTCB        0x00000008
751
752 #define ZFCP_SET                0x00000100
753 #define ZFCP_CLEAR              0x00000200
754
755 #ifndef atomic_test_mask
756 #define atomic_test_mask(mask, target) \
757            ((atomic_read(target) & mask) == mask)
758 #endif
759
760 extern void _zfcp_hex_dump(char *, int);
761 #define ZFCP_HEX_DUMP(level, addr, count) \
762                 if (ZFCP_LOG_CHECK(level)) { \
763                         _zfcp_hex_dump(addr, count); \
764                 }
765
766 #define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
767 #define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
768 #define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
769
770 /*
771  * Helper functions for request ID management.
772  */
773 static inline int zfcp_reqlist_hash(unsigned long req_id)
774 {
775         return req_id % REQUEST_LIST_SIZE;
776 }
777
778 static inline void zfcp_reqlist_add(struct zfcp_adapter *adapter,
779                                     struct zfcp_fsf_req *fsf_req)
780 {
781         unsigned int idx;
782
783         idx = zfcp_reqlist_hash(fsf_req->req_id);
784         list_add_tail(&fsf_req->list, &adapter->req_list[idx]);
785 }
786
787 static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
788                                        struct zfcp_fsf_req *fsf_req)
789 {
790         list_del(&fsf_req->list);
791 }
792
793 static inline struct zfcp_fsf_req *
794 zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
795 {
796         struct zfcp_fsf_req *request;
797         unsigned int idx;
798
799         idx = zfcp_reqlist_hash(req_id);
800         list_for_each_entry(request, &adapter->req_list[idx], list)
801                 if (request->req_id == req_id)
802                         return request;
803         return NULL;
804 }
805
806 static inline struct zfcp_fsf_req *
807 zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req)
808 {
809         struct zfcp_fsf_req *request;
810         unsigned int idx;
811
812         for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) {
813                 list_for_each_entry(request, &adapter->req_list[idx], list)
814                         if (request == req)
815                                 return request;
816         }
817         return NULL;
818 }
819
820 /*
821  *  functions needed for reference/usage counting
822  */
823
824 static inline void
825 zfcp_unit_get(struct zfcp_unit *unit)
826 {
827         atomic_inc(&unit->refcount);
828 }
829
830 static inline void
831 zfcp_unit_put(struct zfcp_unit *unit)
832 {
833         if (atomic_dec_return(&unit->refcount) == 0)
834                 wake_up(&unit->remove_wq);
835 }
836
837 static inline void
838 zfcp_unit_wait(struct zfcp_unit *unit)
839 {
840         wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
841 }
842
843 static inline void
844 zfcp_port_get(struct zfcp_port *port)
845 {
846         atomic_inc(&port->refcount);
847 }
848
849 static inline void
850 zfcp_port_put(struct zfcp_port *port)
851 {
852         if (atomic_dec_return(&port->refcount) == 0)
853                 wake_up(&port->remove_wq);
854 }
855
856 static inline void
857 zfcp_port_wait(struct zfcp_port *port)
858 {
859         wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
860 }
861
862 static inline void
863 zfcp_adapter_get(struct zfcp_adapter *adapter)
864 {
865         atomic_inc(&adapter->refcount);
866 }
867
868 static inline void
869 zfcp_adapter_put(struct zfcp_adapter *adapter)
870 {
871         if (atomic_dec_return(&adapter->refcount) == 0)
872                 wake_up(&adapter->remove_wq);
873 }
874
875 static inline void
876 zfcp_adapter_wait(struct zfcp_adapter *adapter)
877 {
878         wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
879 }
880
881 #endif /* ZFCP_DEF_H */