blob: 0d6a388882d492afb5ea562f0b9b91fb84e25361 [file] [log] [blame]
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001/*
Christof Schmitt553448f2008-06-10 18:20:58 +02002 * zfcp device driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Christof Schmitt553448f2008-06-10 18:20:58 +02004 * Global definitions for the zfcp device driver.
Swen Schillig41fa2ad2007-09-07 09:15:31 +02005 *
Christof Schmitt553448f2008-06-10 18:20:58 +02006 * Copyright IBM Corporation 2002, 2008
Swen Schillig41fa2ad2007-09-07 09:15:31 +02007 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#ifndef ZFCP_DEF_H
10#define ZFCP_DEF_H
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012/*************************** INCLUDES *****************************************/
13
14#include <linux/init.h>
15#include <linux/moduleparam.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/major.h>
17#include <linux/blkdev.h>
18#include <linux/delay.h>
19#include <linux/timer.h>
Heiko Carstensdd52e0e2006-09-18 22:28:49 +020020#include <linux/slab.h>
21#include <linux/mempool.h>
22#include <linux/syscalls.h>
FUJITA Tomonorif1346372007-07-30 23:01:32 +090023#include <linux/scatterlist.h>
Heiko Carstensdd52e0e2006-09-18 22:28:49 +020024#include <linux/ioctl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/ccwdev.h>
33#include <asm/qdio.h>
34#include <asm/debug.h>
35#include <asm/ebcdic.h>
Christof Schmitt2b604c92008-03-31 11:15:28 +020036#include "zfcp_dbf.h"
Heiko Carstensdd52e0e2006-09-18 22:28:49 +020037#include "zfcp_fsf.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40/********************* GENERAL DEFINES *********************************/
41
Andreas Herrmann06506d02006-05-22 18:18:19 +020042#define REQUEST_LIST_SIZE 128
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044/********************* SCSI SPECIFIC DEFINES *********************************/
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +020045#define ZFCP_SCSI_ER_TIMEOUT (10*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
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
Swen Schillig41fa2ad2007-09-07 09:15:31 +020055
Linus Torvalds1da177e2005-04-16 15:20:36 -070056/* 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 \
Swen Schilligc41f8cb2008-07-02 10:56:39 +020064 (FSF_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
66
Swen Schillig8d1a0062006-10-12 11:43:44 +020067#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
Linus Torvalds1da177e2005-04-16 15:20:36 -070071/********************* FSF SPECIFIC DEFINES *********************************/
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073/* ATTENTION: value must not be used by hardware */
74#define FSF_QTCB_UNSOLICITED_STATUS 0x6305
Andreas Herrmann22753fa2005-06-13 13:15:15 +020075
Linus Torvalds1da177e2005-04-16 15:20:36 -070076/* timeout value for "default timer" for fsf requests */
Andreas Herrmann2abbe862006-09-18 22:29:56 +020077#define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79/*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
80
81typedef unsigned long long wwn_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082typedef unsigned long long fcp_lun_t;
83/* data length field may be at variable position in FCP-2 FCP_CMND IU */
84typedef unsigned int fcp_dl_t;
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086/* timeout for name-server lookup (in seconds) */
87#define ZFCP_NS_GID_PN_TIMEOUT 10
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089/* task attribute values in FCP-2 FCP_CMND IU */
90#define SIMPLE_Q 0
91#define HEAD_OF_Q 1
92#define ORDERED_Q 2
93#define ACA_Q 4
94#define UNTAGGED 5
95
96/* task management flags in FCP-2 FCP_CMND IU */
97#define FCP_CLEAR_ACA 0x40
98#define FCP_TARGET_RESET 0x20
99#define FCP_LOGICAL_UNIT_RESET 0x10
100#define FCP_CLEAR_TASK_SET 0x04
101#define FCP_ABORT_TASK_SET 0x02
102
103#define FCP_CDB_LENGTH 16
104
105#define ZFCP_DID_MASK 0x00FFFFFF
106
107/* FCP(-2) FCP_CMND IU */
108struct fcp_cmnd_iu {
109 fcp_lun_t fcp_lun; /* FCP logical unit number */
110 u8 crn; /* command reference number */
111 u8 reserved0:5; /* reserved */
112 u8 task_attribute:3; /* task attribute */
113 u8 task_management_flags; /* task management flags */
114 u8 add_fcp_cdb_length:6; /* additional FCP_CDB length */
115 u8 rddata:1; /* read data */
116 u8 wddata:1; /* write data */
117 u8 fcp_cdb[FCP_CDB_LENGTH];
118} __attribute__((packed));
119
120/* FCP(-2) FCP_RSP IU */
121struct fcp_rsp_iu {
122 u8 reserved0[10];
123 union {
124 struct {
125 u8 reserved1:3;
126 u8 fcp_conf_req:1;
127 u8 fcp_resid_under:1;
128 u8 fcp_resid_over:1;
129 u8 fcp_sns_len_valid:1;
130 u8 fcp_rsp_len_valid:1;
131 } bits;
132 u8 value;
133 } validity;
134 u8 scsi_status;
135 u32 fcp_resid;
136 u32 fcp_sns_len;
137 u32 fcp_rsp_len;
138} __attribute__((packed));
139
140
141#define RSP_CODE_GOOD 0
142#define RSP_CODE_LENGTH_MISMATCH 1
143#define RSP_CODE_FIELD_INVALID 2
144#define RSP_CODE_RO_MISMATCH 3
145#define RSP_CODE_TASKMAN_UNSUPP 4
146#define RSP_CODE_TASKMAN_FAILED 5
147
148/* see fc-fs */
Christof Schmitt24073b42008-06-10 18:20:54 +0200149#define LS_RSCN 0x61
150#define LS_LOGO 0x05
151#define LS_PLOGI 0x03
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153struct fcp_rscn_head {
154 u8 command;
155 u8 page_length; /* always 0x04 */
156 u16 payload_len;
157} __attribute__((packed));
158
159struct fcp_rscn_element {
160 u8 reserved:2;
161 u8 event_qual:4;
162 u8 addr_format:2;
163 u32 nport_did:24;
164} __attribute__((packed));
165
166#define ZFCP_PORT_ADDRESS 0x0
167#define ZFCP_AREA_ADDRESS 0x1
168#define ZFCP_DOMAIN_ADDRESS 0x2
169#define ZFCP_FABRIC_ADDRESS 0x3
170
171#define ZFCP_PORTS_RANGE_PORT 0xFFFFFF
172#define ZFCP_PORTS_RANGE_AREA 0xFFFF00
173#define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
174#define ZFCP_PORTS_RANGE_FABRIC 0x000000
175
176#define ZFCP_NO_PORTS_PER_AREA 0x100
177#define ZFCP_NO_PORTS_PER_DOMAIN 0x10000
178#define ZFCP_NO_PORTS_PER_FABRIC 0x1000000
179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180/* see fc-ph */
181struct fcp_logo {
182 u32 command;
183 u32 nport_did;
184 wwn_t nport_wwpn;
185} __attribute__((packed));
186
187/*
188 * FC-FS stuff
189 */
190#define R_A_TOV 10 /* seconds */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192#define ZFCP_LS_RLS 0x0f
193#define ZFCP_LS_ADISC 0x52
194#define ZFCP_LS_RPS 0x56
195#define ZFCP_LS_RSCN 0x61
196#define ZFCP_LS_RNID 0x78
197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198struct zfcp_ls_adisc {
199 u8 code;
200 u8 field[3];
201 u32 hard_nport_id;
202 u64 wwpn;
203 u64 wwnn;
204 u32 nport_id;
205} __attribute__ ((packed));
206
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207/*
208 * FC-GS-2 stuff
209 */
210#define ZFCP_CT_REVISION 0x01
211#define ZFCP_CT_DIRECTORY_SERVICE 0xFC
212#define ZFCP_CT_NAME_SERVER 0x02
213#define ZFCP_CT_SYNCHRONOUS 0x00
Swen Schilligcc8c2822008-06-10 18:21:00 +0200214#define ZFCP_CT_SCSI_FCP 0x08
215#define ZFCP_CT_UNABLE_TO_PERFORM_CMD 0x09
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216#define ZFCP_CT_GID_PN 0x0121
Swen Schilligcc8c2822008-06-10 18:21:00 +0200217#define ZFCP_CT_GPN_FT 0x0172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218#define ZFCP_CT_MAX_SIZE 0x1020
219#define ZFCP_CT_ACCEPT 0x8002
220#define ZFCP_CT_REJECT 0x8001
221
222/*
223 * FC-GS-4 stuff
224 */
225#define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
226
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227/*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
228
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200229/*
230 * Note, the leftmost status byte is common among adapter, port
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 * and unit
232 */
233#define ZFCP_COMMON_FLAGS 0xfff00000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235/* common status bits */
236#define ZFCP_STATUS_COMMON_REMOVE 0x80000000
237#define ZFCP_STATUS_COMMON_RUNNING 0x40000000
238#define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
239#define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240#define ZFCP_STATUS_COMMON_OPEN 0x04000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241#define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
242#define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
Andreas Herrmannd736a272005-06-13 13:23:57 +0200243#define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
Swen Schilligcc8c2822008-06-10 18:21:00 +0200244#define ZFCP_STATUS_COMMON_NOESC 0x00200000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
246/* adapter status */
247#define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248#define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
249#define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
250#define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
251#define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
252#define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
253#define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255/* FC-PH/FC-GS well-known address identifiers for generic services */
Swen Schillig5ab944f2008-10-01 12:42:17 +0200256#define ZFCP_DID_WKA 0xFFFFF0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257#define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA
258#define ZFCP_DID_TIME_SERVICE 0xFFFFFB
259#define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC
260#define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8
261#define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7
262
263/* remote port status */
264#define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
265#define ZFCP_STATUS_PORT_DID_DID 0x00000002
266#define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
267#define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268#define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Swen Schillig5ab944f2008-10-01 12:42:17 +0200270/* well known address (WKA) port status*/
271enum zfcp_wka_status {
272 ZFCP_WKA_PORT_OFFLINE,
273 ZFCP_WKA_PORT_CLOSING,
274 ZFCP_WKA_PORT_OPENING,
275 ZFCP_WKA_PORT_ONLINE,
276};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
278/* logical unit status */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279#define ZFCP_STATUS_UNIT_SHARED 0x00000004
280#define ZFCP_STATUS_UNIT_READONLY 0x00000008
Andreas Herrmannad58f7d2006-03-10 00:56:16 +0100281#define ZFCP_STATUS_UNIT_REGISTERED 0x00000010
Christof Schmitt5f852be2007-05-08 11:16:52 +0200282#define ZFCP_STATUS_UNIT_SCSI_WORK_PENDING 0x00000020
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284/* FSF request status (this does not have a common part) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285#define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
286#define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
287#define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
288#define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289#define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
290#define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
291#define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
292#define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
293#define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
294#define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
295#define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297/************************* STRUCTURE DEFINITIONS *****************************/
298
299struct zfcp_fsf_req;
300
301/* holds various memory pools of an adapter */
302struct zfcp_adapter_mempool {
303 mempool_t *fsf_req_erp;
304 mempool_t *fsf_req_scsi;
305 mempool_t *fsf_req_abort;
306 mempool_t *fsf_req_status_read;
307 mempool_t *data_status_read;
308 mempool_t *data_gid_pn;
309};
310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311/*
312 * header for CT_IU
313 */
314struct ct_hdr {
315 u8 revision; // 0x01
316 u8 in_id[3]; // 0x00
317 u8 gs_type; // 0xFC Directory Service
318 u8 gs_subtype; // 0x02 Name Server
319 u8 options; // 0x00 single bidirectional exchange
320 u8 reserved0;
321 u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT
322 u16 max_res_size; // <= (4096 - 16) / 4
323 u8 reserved1;
324 u8 reason_code;
325 u8 reason_code_expl;
326 u8 vendor_unique;
327} __attribute__ ((packed));
328
329/* nameserver request CT_IU -- for requests where
330 * a port name is required */
331struct ct_iu_gid_pn_req {
332 struct ct_hdr header;
333 wwn_t wwpn;
334} __attribute__ ((packed));
335
336/* FS_ACC IU and data unit for GID_PN nameserver request */
337struct ct_iu_gid_pn_resp {
338 struct ct_hdr header;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200339 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340} __attribute__ ((packed));
341
342typedef void (*zfcp_send_ct_handler_t)(unsigned long);
343
344/**
345 * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
Swen Schillig5ab944f2008-10-01 12:42:17 +0200346 * @wka_port: port where the request is sent to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 * @req: scatter-gather list for request
348 * @resp: scatter-gather list for response
349 * @req_count: number of elements in request scatter-gather list
350 * @resp_count: number of elements in response scatter-gather list
351 * @handler: handler function (called for response to the request)
352 * @handler_data: data passed to handler function
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 * @timeout: FSF timeout for this request
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 * @completion: completion for synchronization purposes
355 * @status: used to pass error status to calling function
356 */
357struct zfcp_send_ct {
Swen Schillig5ab944f2008-10-01 12:42:17 +0200358 struct zfcp_wka_port *wka_port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 struct scatterlist *req;
360 struct scatterlist *resp;
361 unsigned int req_count;
362 unsigned int resp_count;
363 zfcp_send_ct_handler_t handler;
364 unsigned long handler_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 int timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 struct completion *completion;
367 int status;
368};
369
370/* used for name server requests in error recovery */
371struct zfcp_gid_pn_data {
372 struct zfcp_send_ct ct;
373 struct scatterlist req;
374 struct scatterlist resp;
375 struct ct_iu_gid_pn_req ct_iu_req;
376 struct ct_iu_gid_pn_resp ct_iu_resp;
377 struct zfcp_port *port;
378};
379
380typedef void (*zfcp_send_els_handler_t)(unsigned long);
381
382/**
383 * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
384 * @adapter: adapter where request is sent from
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200385 * @port: port where ELS is destinated (port reference count has to be increased)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 * @d_id: destiniation id of port where request is sent to
387 * @req: scatter-gather list for request
388 * @resp: scatter-gather list for response
389 * @req_count: number of elements in request scatter-gather list
390 * @resp_count: number of elements in response scatter-gather list
391 * @handler: handler function (called for response to the request)
392 * @handler_data: data passed to handler function
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 * @completion: completion for synchronization purposes
394 * @ls_code: hex code of ELS command
395 * @status: used to pass error status to calling function
396 */
397struct zfcp_send_els {
398 struct zfcp_adapter *adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200399 struct zfcp_port *port;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200400 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 struct scatterlist *req;
402 struct scatterlist *resp;
403 unsigned int req_count;
404 unsigned int resp_count;
405 zfcp_send_els_handler_t handler;
406 unsigned long handler_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 struct completion *completion;
408 int ls_code;
409 int status;
410};
411
Swen Schillig5ab944f2008-10-01 12:42:17 +0200412struct zfcp_wka_port {
413 struct zfcp_adapter *adapter;
414 wait_queue_head_t completion_wq;
415 enum zfcp_wka_status status;
416 atomic_t refcount;
417 u32 d_id;
418 u32 handle;
419 struct mutex mutex;
420 struct delayed_work work;
421};
422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423struct zfcp_qdio_queue {
Swen Schillig00bab912008-06-10 18:20:57 +0200424 struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
425 u8 first; /* index of next free bfr
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 in queue (free_count>0) */
Swen Schillig00bab912008-06-10 18:20:57 +0200427 atomic_t count; /* number of free buffers
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 in queue */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200429 spinlock_t lock; /* lock for operations on queue */
Swen Schillig00bab912008-06-10 18:20:57 +0200430 int pci_batch; /* SBALs since PCI indication
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 was last set */
432};
433
434struct zfcp_erp_action {
435 struct list_head list;
436 int action; /* requested action code */
437 struct zfcp_adapter *adapter; /* device which should be recovered */
438 struct zfcp_port *port;
439 struct zfcp_unit *unit;
Swen Schillig44cc76f2008-10-01 12:42:16 +0200440 u32 status; /* recovery status */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 u32 step; /* active step of this erp action */
442 struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
443 for this action */
444 struct timer_list timer;
445};
446
Christof Schmittc9615852008-05-06 11:00:05 +0200447struct fsf_latency_record {
448 u32 min;
449 u32 max;
450 u64 sum;
451};
452
453struct latency_cont {
454 struct fsf_latency_record channel;
455 struct fsf_latency_record fabric;
456 u64 counter;
457};
458
459struct zfcp_latencies {
460 struct latency_cont read;
461 struct latency_cont write;
462 struct latency_cont cmd;
463 spinlock_t lock;
464};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
466struct zfcp_adapter {
467 struct list_head list; /* list of adapters */
468 atomic_t refcount; /* reference count */
469 wait_queue_head_t remove_wq; /* can be used to wait for
470 refcount drop to zero */
6f71d9b2005-04-10 23:04:28 -0500471 wwn_t peer_wwnn; /* P2P peer WWNN */
472 wwn_t peer_wwpn; /* P2P peer WWPN */
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200473 u32 peer_d_id; /* P2P peer D_ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 struct ccw_device *ccw_device; /* S/390 ccw device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 u32 hydra_version; /* Hydra version */
476 u32 fsf_lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200477 u32 adapter_features; /* FCP channel features */
478 u32 connection_features; /* host connection features */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 u32 hardware_version; /* of FCP channel */
Christof Schmittc9615852008-05-06 11:00:05 +0200480 u16 timer_ticks; /* time int for a tick */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 struct list_head port_list_head; /* remote port list */
483 struct list_head port_remove_lh; /* head of ports to be
484 removed */
485 u32 ports; /* number of remote ports */
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200486 unsigned long req_no; /* unique FSF req number */
487 struct list_head *req_list; /* list of pending reqs */
488 spinlock_t req_list_lock; /* request list lock */
Swen Schillig00bab912008-06-10 18:20:57 +0200489 struct zfcp_qdio_queue req_q; /* request queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 u32 fsf_req_seq_no; /* FSF cmnd seq number */
491 wait_queue_head_t request_wq; /* can be used to wait for
492 more avaliable SBALs */
Swen Schillig00bab912008-06-10 18:20:57 +0200493 struct zfcp_qdio_queue resp_q; /* response queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 rwlock_t abort_lock; /* Protects against SCSI
495 stack abort/command
496 completion races */
Swen Schilligd26ab062008-05-19 12:17:37 +0200497 atomic_t stat_miss; /* # missing status reads*/
498 struct work_struct stat_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 atomic_t status; /* status of this adapter */
500 struct list_head erp_ready_head; /* error recovery for this
501 adapter/devices */
502 struct list_head erp_running_head;
503 rwlock_t erp_lock;
504 struct semaphore erp_ready_sem;
505 wait_queue_head_t erp_thread_wqh;
506 wait_queue_head_t erp_done_wqh;
507 struct zfcp_erp_action erp_action; /* pending error recovery */
508 atomic_t erp_counter;
509 u32 erp_total_count; /* total nr of enqueued erp
510 actions */
511 u32 erp_low_mem_count; /* nr of erp actions waiting
512 for memory */
Swen Schillig5ab944f2008-10-01 12:42:17 +0200513 struct zfcp_wka_port nsp; /* adapter's nameserver */
Martin Peschked79a83d2008-03-27 14:22:00 +0100514 debug_info_t *rec_dbf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200515 debug_info_t *hba_dbf;
516 debug_info_t *san_dbf; /* debug feature areas */
517 debug_info_t *scsi_dbf;
Martin Peschked79a83d2008-03-27 14:22:00 +0100518 spinlock_t rec_dbf_lock;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200519 spinlock_t hba_dbf_lock;
520 spinlock_t san_dbf_lock;
521 spinlock_t scsi_dbf_lock;
Martin Peschked79a83d2008-03-27 14:22:00 +0100522 struct zfcp_rec_dbf_record rec_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200523 struct zfcp_hba_dbf_record hba_dbf_buf;
524 struct zfcp_san_dbf_record san_dbf_buf;
525 struct zfcp_scsi_dbf_record scsi_dbf_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 struct zfcp_adapter_mempool pool; /* Adapter memory pools */
527 struct qdio_initialize qdio_init_data; /* for qdio_establish */
528 struct device generic_services; /* directory for WKA ports */
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100529 struct fc_host_statistics *fc_stats;
530 struct fsf_qtcb_bottom_port *stats_reset_data;
531 unsigned long stats_reset;
Swen Schilligcc8c2822008-06-10 18:21:00 +0200532 struct work_struct scan_work;
Stefan Raspl2450d3e2008-10-01 12:42:14 +0200533 atomic_t qdio_outb_full; /* queue full incidents */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534};
535
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536struct zfcp_port {
537 struct device sysfs_device; /* sysfs device */
Andreas Herrmann3859f6a2005-08-27 11:07:54 -0700538 struct fc_rport *rport; /* rport of fc transport class */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 struct list_head list; /* list of remote ports */
540 atomic_t refcount; /* reference count */
541 wait_queue_head_t remove_wq; /* can be used to wait for
542 refcount drop to zero */
543 struct zfcp_adapter *adapter; /* adapter used to access port */
544 struct list_head unit_list_head; /* head of logical unit list */
545 struct list_head unit_remove_lh; /* head of luns to be removed
546 list */
547 u32 units; /* # of logical units in list */
548 atomic_t status; /* status of this remote port */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 wwn_t wwnn; /* WWNN if known */
550 wwn_t wwpn; /* WWPN */
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200551 u32 d_id; /* D_ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 u32 handle; /* handle assigned by FSF */
553 struct zfcp_erp_action erp_action; /* pending error recovery */
554 atomic_t erp_counter;
Ralph Wuerthner75bfc282006-05-22 18:24:33 +0200555 u32 maxframe_size;
556 u32 supported_classes;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200557 struct work_struct gid_pn_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558};
559
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560struct zfcp_unit {
561 struct device sysfs_device; /* sysfs device */
562 struct list_head list; /* list of logical units */
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 struct zfcp_port *port; /* remote port of unit */
567 atomic_t status; /* status of this logical unit */
Andreas Herrmann06506d02006-05-22 18:18:19 +0200568 unsigned int scsi_lun; /* own SCSI LUN */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 fcp_lun_t fcp_lun; /* own FCP_LUN */
570 u32 handle; /* handle assigned by FSF */
571 struct scsi_device *device; /* scsi device struct pointer */
572 struct zfcp_erp_action erp_action; /* pending error recovery */
573 atomic_t erp_counter;
Christof Schmittc9615852008-05-06 11:00:05 +0200574 struct zfcp_latencies latencies;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575};
576
577/* FSF request */
578struct zfcp_fsf_req {
579 struct list_head list; /* list of FSF requests */
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200580 unsigned long req_id; /* unique request ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 struct zfcp_adapter *adapter; /* adapter request belongs to */
582 u8 sbal_number; /* nr of SBALs free for use */
583 u8 sbal_first; /* first SBAL for this request */
Martin Peschkee891bff2008-05-19 12:17:43 +0200584 u8 sbal_last; /* last SBAL for this request */
Martin Peschked01d51b2008-05-19 12:17:42 +0200585 u8 sbal_limit; /* last possible SBAL for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 this reuest */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 u8 sbale_curr; /* current SBALE during creation
588 of request */
Martin Peschkec3baa9a22008-05-19 12:17:44 +0200589 u8 sbal_response; /* SBAL used in interrupt */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 wait_queue_head_t completion_wq; /* can be used by a routine
591 to wait for completion */
Swen Schillig44cc76f2008-10-01 12:42:16 +0200592 u32 status; /* status of this request */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 u32 fsf_command; /* FSF Command copy */
594 struct fsf_qtcb *qtcb; /* address of associated QTCB */
595 u32 seq_no; /* Sequence number of request */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200596 void *data; /* private data of request */
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200597 struct timer_list timer; /* used for erp or scsi er */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 struct zfcp_erp_action *erp_action; /* used if this request is
599 issued on behalf of erp */
600 mempool_t *pool; /* used if request was alloacted
601 from emergency pool */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200602 unsigned long long issued; /* request sent time (STCK) */
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200603 struct zfcp_unit *unit;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200604 void (*handler)(struct zfcp_fsf_req *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605};
606
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607/* driver data */
608struct zfcp_data {
609 struct scsi_host_template scsi_host_template;
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200610 struct scsi_transport_template *scsi_transport_template;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 atomic_t status; /* Module status flags */
612 struct list_head adapter_list_head; /* head of adapter list */
613 struct list_head adapter_remove_lh; /* head of adapters to be
614 removed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 u32 adapters; /* # of adapters in list */
616 rwlock_t config_lock; /* serialises changes
617 to adapter/port/unit
618 lists */
619 struct semaphore config_sema; /* serialises configuration
620 changes */
621 atomic_t loglevel; /* current loglevel */
622 char init_busid[BUS_ID_SIZE];
623 wwn_t init_wwpn;
624 fcp_lun_t init_fcp_lun;
Christoph Lametere18b8902006-12-06 20:33:20 -0800625 struct kmem_cache *fsf_req_qtcb_cache;
626 struct kmem_cache *sr_buffer_cache;
627 struct kmem_cache *gid_pn_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628};
629
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630/* struct used by memory pools for fsf_requests */
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200631struct zfcp_fsf_req_qtcb {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 struct zfcp_fsf_req fsf_req;
633 struct fsf_qtcb qtcb;
634};
635
636/********************** ZFCP SPECIFIC DEFINES ********************************/
637
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638#define ZFCP_REQ_AUTO_CLEANUP 0x00000002
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639#define ZFCP_REQ_NO_QTCB 0x00000008
640
641#define ZFCP_SET 0x00000100
642#define ZFCP_CLEAR 0x00000200
643
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644#define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
646/*
Heiko Carstensca2d02c2007-05-08 11:17:54 +0200647 * Helper functions for request ID management.
648 */
649static inline int zfcp_reqlist_hash(unsigned long req_id)
650{
651 return req_id % REQUEST_LIST_SIZE;
652}
653
Heiko Carstensca2d02c2007-05-08 11:17:54 +0200654static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
655 struct zfcp_fsf_req *fsf_req)
656{
657 list_del(&fsf_req->list);
658}
659
660static inline struct zfcp_fsf_req *
661zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
662{
663 struct zfcp_fsf_req *request;
664 unsigned int idx;
665
666 idx = zfcp_reqlist_hash(req_id);
667 list_for_each_entry(request, &adapter->req_list[idx], list)
668 if (request->req_id == req_id)
669 return request;
670 return NULL;
671}
672
Heiko Carstensd1ad09d2007-12-20 12:30:22 +0100673static inline struct zfcp_fsf_req *
674zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req)
675{
676 struct zfcp_fsf_req *request;
677 unsigned int idx;
678
679 for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) {
680 list_for_each_entry(request, &adapter->req_list[idx], list)
681 if (request == req)
682 return request;
683 }
684 return NULL;
685}
686
Heiko Carstensca2d02c2007-05-08 11:17:54 +0200687/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 * functions needed for reference/usage counting
689 */
690
691static inline void
692zfcp_unit_get(struct zfcp_unit *unit)
693{
694 atomic_inc(&unit->refcount);
695}
696
697static inline void
698zfcp_unit_put(struct zfcp_unit *unit)
699{
700 if (atomic_dec_return(&unit->refcount) == 0)
701 wake_up(&unit->remove_wq);
702}
703
704static inline void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705zfcp_port_get(struct zfcp_port *port)
706{
707 atomic_inc(&port->refcount);
708}
709
710static inline void
711zfcp_port_put(struct zfcp_port *port)
712{
713 if (atomic_dec_return(&port->refcount) == 0)
714 wake_up(&port->remove_wq);
715}
716
717static inline void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718zfcp_adapter_get(struct zfcp_adapter *adapter)
719{
720 atomic_inc(&adapter->refcount);
721}
722
723static inline void
724zfcp_adapter_put(struct zfcp_adapter *adapter)
725{
726 if (atomic_dec_return(&adapter->refcount) == 0)
727 wake_up(&adapter->remove_wq);
728}
729
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730#endif /* ZFCP_DEF_H */