blob: 73425dbb2be801fd970561c79a2cf79216f08b8c [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070042/**
43 * zfcp_sg_to_address - determine kernel address from struct scatterlist
44 * @list: struct scatterlist
45 * Return: kernel address
46 */
47static inline void *
48zfcp_sg_to_address(struct scatterlist *list)
49{
Jens Axboe73fc4f02007-10-23 09:17:53 +020050 return sg_virt(list);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051}
52
53/**
54 * zfcp_address_to_sg - set up struct scatterlist from kernel address
55 * @address: kernel address
56 * @list: struct scatterlist
Jens Axboe933543292007-10-26 13:55:40 +020057 * @size: buffer size
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 */
59static inline void
Jens Axboe933543292007-10-26 13:55:40 +020060zfcp_address_to_sg(void *address, struct scatterlist *list, unsigned int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
Jens Axboe933543292007-10-26 13:55:40 +020062 sg_set_buf(list, address, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}
64
Andreas Herrmann06506d02006-05-22 18:18:19 +020065#define REQUEST_LIST_SIZE 128
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067/********************* SCSI SPECIFIC DEFINES *********************************/
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +020068#define ZFCP_SCSI_ER_TIMEOUT (10*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
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
Swen Schillig41fa2ad2007-09-07 09:15:31 +020078
Linus Torvalds1da177e2005-04-16 15:20:36 -070079/* 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
Swen Schillig8d1a0062006-10-12 11:43:44 +020095#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
Linus Torvalds1da177e2005-04-16 15:20:36 -070099#define ZFCP_SBAL_TIMEOUT (5*HZ)
100
Christof Schmitt18edcdb2007-11-05 12:37:45 +0100101#define ZFCP_TYPE2_RECOVERY_TIME 8 /* seconds */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Swen Schilligb4e44592007-07-18 10:55:13 +0200103#define QBUFF_PER_PAGE (PAGE_SIZE / sizeof(struct qdio_buffer))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105/********************* FSF SPECIFIC DEFINES *********************************/
106
107#define ZFCP_ULP_INFO_VERSION 26
108#define ZFCP_QTCB_VERSION FSF_QTCB_CURRENT_VERSION
109/* ATTENTION: value must not be used by hardware */
110#define FSF_QTCB_UNSOLICITED_STATUS 0x6305
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#define ZFCP_STATUS_READS_RECOM FSF_STATUS_READS_RECOM
Andreas Herrmann22753fa2005-06-13 13:15:15 +0200112
113/* Do 1st retry in 1 second, then double the timeout for each following retry */
Christof Schmitt18edcdb2007-11-05 12:37:45 +0100114#define ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP 1
Andreas Herrmann22753fa2005-06-13 13:15:15 +0200115#define ZFCP_EXCHANGE_CONFIG_DATA_RETRIES 7
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117/* timeout value for "default timer" for fsf requests */
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200118#define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120/*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
121
122typedef unsigned long long wwn_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123typedef unsigned long long fcp_lun_t;
124/* data length field may be at variable position in FCP-2 FCP_CMND IU */
125typedef unsigned int fcp_dl_t;
126
127#define ZFCP_FC_SERVICE_CLASS_DEFAULT FSF_CLASS_3
128
129/* timeout for name-server lookup (in seconds) */
130#define ZFCP_NS_GID_PN_TIMEOUT 10
131
132/* largest SCSI command we can process */
133/* FCP-2 (FCP_CMND IU) allows up to (255-3+16) */
134#define ZFCP_MAX_SCSI_CMND_LENGTH 255
135/* maximum number of commands in LUN queue (tagged queueing) */
136#define ZFCP_CMND_PER_LUN 32
137
138/* task attribute values in FCP-2 FCP_CMND IU */
139#define SIMPLE_Q 0
140#define HEAD_OF_Q 1
141#define ORDERED_Q 2
142#define ACA_Q 4
143#define UNTAGGED 5
144
145/* task management flags in FCP-2 FCP_CMND IU */
146#define FCP_CLEAR_ACA 0x40
147#define FCP_TARGET_RESET 0x20
148#define FCP_LOGICAL_UNIT_RESET 0x10
149#define FCP_CLEAR_TASK_SET 0x04
150#define FCP_ABORT_TASK_SET 0x02
151
152#define FCP_CDB_LENGTH 16
153
154#define ZFCP_DID_MASK 0x00FFFFFF
155
156/* FCP(-2) FCP_CMND IU */
157struct fcp_cmnd_iu {
158 fcp_lun_t fcp_lun; /* FCP logical unit number */
159 u8 crn; /* command reference number */
160 u8 reserved0:5; /* reserved */
161 u8 task_attribute:3; /* task attribute */
162 u8 task_management_flags; /* task management flags */
163 u8 add_fcp_cdb_length:6; /* additional FCP_CDB length */
164 u8 rddata:1; /* read data */
165 u8 wddata:1; /* write data */
166 u8 fcp_cdb[FCP_CDB_LENGTH];
167} __attribute__((packed));
168
169/* FCP(-2) FCP_RSP IU */
170struct fcp_rsp_iu {
171 u8 reserved0[10];
172 union {
173 struct {
174 u8 reserved1:3;
175 u8 fcp_conf_req:1;
176 u8 fcp_resid_under:1;
177 u8 fcp_resid_over:1;
178 u8 fcp_sns_len_valid:1;
179 u8 fcp_rsp_len_valid:1;
180 } bits;
181 u8 value;
182 } validity;
183 u8 scsi_status;
184 u32 fcp_resid;
185 u32 fcp_sns_len;
186 u32 fcp_rsp_len;
187} __attribute__((packed));
188
189
190#define RSP_CODE_GOOD 0
191#define RSP_CODE_LENGTH_MISMATCH 1
192#define RSP_CODE_FIELD_INVALID 2
193#define RSP_CODE_RO_MISMATCH 3
194#define RSP_CODE_TASKMAN_UNSUPP 4
195#define RSP_CODE_TASKMAN_FAILED 5
196
197/* see fc-fs */
Christof Schmitt24073b42008-06-10 18:20:54 +0200198#define LS_RSCN 0x61
199#define LS_LOGO 0x05
200#define LS_PLOGI 0x03
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202struct fcp_rscn_head {
203 u8 command;
204 u8 page_length; /* always 0x04 */
205 u16 payload_len;
206} __attribute__((packed));
207
208struct fcp_rscn_element {
209 u8 reserved:2;
210 u8 event_qual:4;
211 u8 addr_format:2;
212 u32 nport_did:24;
213} __attribute__((packed));
214
215#define ZFCP_PORT_ADDRESS 0x0
216#define ZFCP_AREA_ADDRESS 0x1
217#define ZFCP_DOMAIN_ADDRESS 0x2
218#define ZFCP_FABRIC_ADDRESS 0x3
219
220#define ZFCP_PORTS_RANGE_PORT 0xFFFFFF
221#define ZFCP_PORTS_RANGE_AREA 0xFFFF00
222#define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
223#define ZFCP_PORTS_RANGE_FABRIC 0x000000
224
225#define ZFCP_NO_PORTS_PER_AREA 0x100
226#define ZFCP_NO_PORTS_PER_DOMAIN 0x10000
227#define ZFCP_NO_PORTS_PER_FABRIC 0x1000000
228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229/* see fc-ph */
230struct fcp_logo {
231 u32 command;
232 u32 nport_did;
233 wwn_t nport_wwpn;
234} __attribute__((packed));
235
236/*
237 * FC-FS stuff
238 */
239#define R_A_TOV 10 /* seconds */
240#define ZFCP_ELS_TIMEOUT (2 * R_A_TOV)
241
242#define ZFCP_LS_RLS 0x0f
243#define ZFCP_LS_ADISC 0x52
244#define ZFCP_LS_RPS 0x56
245#define ZFCP_LS_RSCN 0x61
246#define ZFCP_LS_RNID 0x78
247
248struct zfcp_ls_rjt_par {
249 u8 action;
250 u8 reason_code;
251 u8 reason_expl;
252 u8 vendor_unique;
253} __attribute__ ((packed));
254
255struct zfcp_ls_adisc {
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
264struct zfcp_ls_adisc_acc {
265 u8 code;
266 u8 field[3];
267 u32 hard_nport_id;
268 u64 wwpn;
269 u64 wwnn;
270 u32 nport_id;
271} __attribute__ ((packed));
272
273struct zfcp_rc_entry {
274 u8 code;
275 const char *description;
276};
277
278/*
279 * FC-GS-2 stuff
280 */
281#define ZFCP_CT_REVISION 0x01
282#define ZFCP_CT_DIRECTORY_SERVICE 0xFC
283#define ZFCP_CT_NAME_SERVER 0x02
284#define ZFCP_CT_SYNCHRONOUS 0x00
285#define ZFCP_CT_GID_PN 0x0121
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295/*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
296
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200297/*
298 * Note, the leftmost status byte is common among adapter, port
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 * and unit
300 */
301#define ZFCP_COMMON_FLAGS 0xfff00000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
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
Andreas Herrmannd736a272005-06-13 13:23:57 +0200313#define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
315/* adapter status */
316#define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
317#define ZFCP_STATUS_ADAPTER_REGISTERED 0x00000004
318#define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
319#define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
320#define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
321#define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
322#define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
323#define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200324#define ZFCP_STATUS_ADAPTER_XPORT_OK 0x00000800
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326/* FC-PH/FC-GS well-known address identifiers for generic services */
327#define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA
328#define ZFCP_DID_TIME_SERVICE 0xFFFFFB
329#define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC
330#define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8
331#define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7
332
333/* remote port status */
334#define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
335#define ZFCP_STATUS_PORT_DID_DID 0x00000002
336#define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
337#define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
338#define ZFCP_STATUS_PORT_NO_SCSI_ID 0x00000010
339#define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
341/* for ports with well known addresses */
342#define ZFCP_STATUS_PORT_WKA \
343 (ZFCP_STATUS_PORT_NO_WWPN | \
344 ZFCP_STATUS_PORT_NO_SCSI_ID)
345
346/* logical unit status */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347#define ZFCP_STATUS_UNIT_TEMPORARY 0x00000002
348#define ZFCP_STATUS_UNIT_SHARED 0x00000004
349#define ZFCP_STATUS_UNIT_READONLY 0x00000008
Andreas Herrmannad58f7d2006-03-10 00:56:16 +0100350#define ZFCP_STATUS_UNIT_REGISTERED 0x00000010
Christof Schmitt5f852be2007-05-08 11:16:52 +0200351#define ZFCP_STATUS_UNIT_SCSI_WORK_PENDING 0x00000020
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
353/* FSF request status (this does not have a common part) */
354#define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000
355#define ZFCP_STATUS_FSFREQ_POOL 0x00000001
356#define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
357#define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
358#define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
359#define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
360#define ZFCP_STATUS_FSFREQ_ABORTING 0x00000020
361#define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
362#define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
363#define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
364#define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
365#define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
366#define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
367#define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
368
369/*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
370
371#define ZFCP_MAX_ERPS 3
372
373#define ZFCP_ERP_FSFREQ_TIMEOUT (30 * HZ)
374#define ZFCP_ERP_MEMWAIT_TIMEOUT HZ
375
376#define ZFCP_STATUS_ERP_TIMEDOUT 0x10000000
377#define ZFCP_STATUS_ERP_CLOSE_ONLY 0x01000000
378#define ZFCP_STATUS_ERP_DISMISSING 0x00100000
379#define ZFCP_STATUS_ERP_DISMISSED 0x00200000
380#define ZFCP_STATUS_ERP_LOWMEM 0x00400000
381
382#define ZFCP_ERP_STEP_UNINITIALIZED 0x00000000
383#define ZFCP_ERP_STEP_FSF_XCONFIG 0x00000001
384#define ZFCP_ERP_STEP_PHYS_PORT_CLOSING 0x00000010
385#define ZFCP_ERP_STEP_PORT_CLOSING 0x00000100
386#define ZFCP_ERP_STEP_NAMESERVER_OPEN 0x00000200
387#define ZFCP_ERP_STEP_NAMESERVER_LOOKUP 0x00000400
388#define ZFCP_ERP_STEP_PORT_OPENING 0x00000800
389#define ZFCP_ERP_STEP_UNIT_CLOSING 0x00001000
390#define ZFCP_ERP_STEP_UNIT_OPENING 0x00002000
391
392/* Ordered by escalation level (necessary for proper erp-code operation) */
393#define ZFCP_ERP_ACTION_REOPEN_ADAPTER 0x4
394#define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED 0x3
395#define ZFCP_ERP_ACTION_REOPEN_PORT 0x2
396#define ZFCP_ERP_ACTION_REOPEN_UNIT 0x1
397
398#define ZFCP_ERP_ACTION_RUNNING 0x1
399#define ZFCP_ERP_ACTION_READY 0x2
400
401#define ZFCP_ERP_SUCCEEDED 0x0
402#define ZFCP_ERP_FAILED 0x1
403#define ZFCP_ERP_CONTINUES 0x2
404#define ZFCP_ERP_EXIT 0x3
405#define ZFCP_ERP_DISMISSED 0x4
406#define ZFCP_ERP_NOMEM 0x5
407
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408/************************* STRUCTURE DEFINITIONS *****************************/
409
410struct zfcp_fsf_req;
411
412/* holds various memory pools of an adapter */
413struct zfcp_adapter_mempool {
414 mempool_t *fsf_req_erp;
415 mempool_t *fsf_req_scsi;
416 mempool_t *fsf_req_abort;
417 mempool_t *fsf_req_status_read;
418 mempool_t *data_status_read;
419 mempool_t *data_gid_pn;
420};
421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422/*
423 * header for CT_IU
424 */
425struct ct_hdr {
426 u8 revision; // 0x01
427 u8 in_id[3]; // 0x00
428 u8 gs_type; // 0xFC Directory Service
429 u8 gs_subtype; // 0x02 Name Server
430 u8 options; // 0x00 single bidirectional exchange
431 u8 reserved0;
432 u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT
433 u16 max_res_size; // <= (4096 - 16) / 4
434 u8 reserved1;
435 u8 reason_code;
436 u8 reason_code_expl;
437 u8 vendor_unique;
438} __attribute__ ((packed));
439
440/* nameserver request CT_IU -- for requests where
441 * a port name is required */
442struct ct_iu_gid_pn_req {
443 struct ct_hdr header;
444 wwn_t wwpn;
445} __attribute__ ((packed));
446
447/* FS_ACC IU and data unit for GID_PN nameserver request */
448struct ct_iu_gid_pn_resp {
449 struct ct_hdr header;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200450 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451} __attribute__ ((packed));
452
453typedef void (*zfcp_send_ct_handler_t)(unsigned long);
454
455/**
456 * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
457 * @port: port where the request is sent to
458 * @req: scatter-gather list for request
459 * @resp: scatter-gather list for response
460 * @req_count: number of elements in request scatter-gather list
461 * @resp_count: number of elements in response scatter-gather list
462 * @handler: handler function (called for response to the request)
463 * @handler_data: data passed to handler function
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 * @timeout: FSF timeout for this request
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 * @completion: completion for synchronization purposes
466 * @status: used to pass error status to calling function
467 */
468struct zfcp_send_ct {
469 struct zfcp_port *port;
470 struct scatterlist *req;
471 struct scatterlist *resp;
472 unsigned int req_count;
473 unsigned int resp_count;
474 zfcp_send_ct_handler_t handler;
475 unsigned long handler_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 int timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 struct completion *completion;
478 int status;
479};
480
481/* used for name server requests in error recovery */
482struct zfcp_gid_pn_data {
483 struct zfcp_send_ct ct;
484 struct scatterlist req;
485 struct scatterlist resp;
486 struct ct_iu_gid_pn_req ct_iu_req;
487 struct ct_iu_gid_pn_resp ct_iu_resp;
488 struct zfcp_port *port;
489};
490
491typedef void (*zfcp_send_els_handler_t)(unsigned long);
492
493/**
494 * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
495 * @adapter: adapter where request is sent from
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200496 * @port: port where ELS is destinated (port reference count has to be increased)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 * @d_id: destiniation id of port where request is sent to
498 * @req: scatter-gather list for request
499 * @resp: scatter-gather list for response
500 * @req_count: number of elements in request scatter-gather list
501 * @resp_count: number of elements in response scatter-gather list
502 * @handler: handler function (called for response to the request)
503 * @handler_data: data passed to handler function
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 * @completion: completion for synchronization purposes
505 * @ls_code: hex code of ELS command
506 * @status: used to pass error status to calling function
507 */
508struct zfcp_send_els {
509 struct zfcp_adapter *adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200510 struct zfcp_port *port;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200511 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 struct scatterlist *req;
513 struct scatterlist *resp;
514 unsigned int req_count;
515 unsigned int resp_count;
516 zfcp_send_els_handler_t handler;
517 unsigned long handler_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 struct completion *completion;
519 int ls_code;
520 int status;
521};
522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523struct zfcp_qdio_queue {
Swen Schillig00bab912008-06-10 18:20:57 +0200524 struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
525 u8 first; /* index of next free bfr
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 in queue (free_count>0) */
Swen Schillig00bab912008-06-10 18:20:57 +0200527 atomic_t count; /* number of free buffers
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 in queue */
Swen Schillig00bab912008-06-10 18:20:57 +0200529 rwlock_t lock; /* lock for operations on queue */
530 int pci_batch; /* SBALs since PCI indication
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 was last set */
532};
533
534struct zfcp_erp_action {
535 struct list_head list;
536 int action; /* requested action code */
537 struct zfcp_adapter *adapter; /* device which should be recovered */
538 struct zfcp_port *port;
539 struct zfcp_unit *unit;
540 volatile u32 status; /* recovery status */
541 u32 step; /* active step of this erp action */
542 struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
543 for this action */
544 struct timer_list timer;
545};
546
Christof Schmittc9615852008-05-06 11:00:05 +0200547struct fsf_latency_record {
548 u32 min;
549 u32 max;
550 u64 sum;
551};
552
553struct latency_cont {
554 struct fsf_latency_record channel;
555 struct fsf_latency_record fabric;
556 u64 counter;
557};
558
559struct zfcp_latencies {
560 struct latency_cont read;
561 struct latency_cont write;
562 struct latency_cont cmd;
563 spinlock_t lock;
564};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
566struct zfcp_adapter {
567 struct list_head list; /* list of adapters */
568 atomic_t refcount; /* reference count */
569 wait_queue_head_t remove_wq; /* can be used to wait for
570 refcount drop to zero */
6f71d9b2005-04-10 23:04:28 -0500571 wwn_t peer_wwnn; /* P2P peer WWNN */
572 wwn_t peer_wwpn; /* P2P peer WWPN */
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200573 u32 peer_d_id; /* P2P peer D_ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 struct ccw_device *ccw_device; /* S/390 ccw device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 u32 hydra_version; /* Hydra version */
576 u32 fsf_lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200577 u32 adapter_features; /* FCP channel features */
578 u32 connection_features; /* host connection features */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 u32 hardware_version; /* of FCP channel */
Christof Schmittc9615852008-05-06 11:00:05 +0200580 u16 timer_ticks; /* time int for a tick */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 struct list_head port_list_head; /* remote port list */
583 struct list_head port_remove_lh; /* head of ports to be
584 removed */
585 u32 ports; /* number of remote ports */
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200586 unsigned long req_no; /* unique FSF req number */
587 struct list_head *req_list; /* list of pending reqs */
588 spinlock_t req_list_lock; /* request list lock */
Swen Schillig00bab912008-06-10 18:20:57 +0200589 struct zfcp_qdio_queue req_q; /* request queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 u32 fsf_req_seq_no; /* FSF cmnd seq number */
591 wait_queue_head_t request_wq; /* can be used to wait for
592 more avaliable SBALs */
Swen Schillig00bab912008-06-10 18:20:57 +0200593 struct zfcp_qdio_queue resp_q; /* response queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 rwlock_t abort_lock; /* Protects against SCSI
595 stack abort/command
596 completion races */
Swen Schilligd26ab062008-05-19 12:17:37 +0200597 atomic_t stat_miss; /* # missing status reads*/
598 struct work_struct stat_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 atomic_t status; /* status of this adapter */
600 struct list_head erp_ready_head; /* error recovery for this
601 adapter/devices */
602 struct list_head erp_running_head;
603 rwlock_t erp_lock;
604 struct semaphore erp_ready_sem;
605 wait_queue_head_t erp_thread_wqh;
606 wait_queue_head_t erp_done_wqh;
607 struct zfcp_erp_action erp_action; /* pending error recovery */
608 atomic_t erp_counter;
609 u32 erp_total_count; /* total nr of enqueued erp
610 actions */
611 u32 erp_low_mem_count; /* nr of erp actions waiting
612 for memory */
613 struct zfcp_port *nameserver_port; /* adapter's nameserver */
Martin Peschked79a83d2008-03-27 14:22:00 +0100614 debug_info_t *rec_dbf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200615 debug_info_t *hba_dbf;
616 debug_info_t *san_dbf; /* debug feature areas */
617 debug_info_t *scsi_dbf;
Martin Peschked79a83d2008-03-27 14:22:00 +0100618 spinlock_t rec_dbf_lock;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200619 spinlock_t hba_dbf_lock;
620 spinlock_t san_dbf_lock;
621 spinlock_t scsi_dbf_lock;
Martin Peschked79a83d2008-03-27 14:22:00 +0100622 struct zfcp_rec_dbf_record rec_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200623 struct zfcp_hba_dbf_record hba_dbf_buf;
624 struct zfcp_san_dbf_record san_dbf_buf;
625 struct zfcp_scsi_dbf_record scsi_dbf_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 struct zfcp_adapter_mempool pool; /* Adapter memory pools */
627 struct qdio_initialize qdio_init_data; /* for qdio_establish */
628 struct device generic_services; /* directory for WKA ports */
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100629 struct fc_host_statistics *fc_stats;
630 struct fsf_qtcb_bottom_port *stats_reset_data;
631 unsigned long stats_reset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632};
633
634/*
635 * the struct device sysfs_device must be at the beginning of this structure.
636 * pointer to struct device is used to free port structure in release function
637 * of the device. don't change!
638 */
639struct zfcp_port {
640 struct device sysfs_device; /* sysfs device */
Andreas Herrmann3859f6a2005-08-27 11:07:54 -0700641 struct fc_rport *rport; /* rport of fc transport class */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 struct list_head list; /* list of remote ports */
643 atomic_t refcount; /* reference count */
644 wait_queue_head_t remove_wq; /* can be used to wait for
645 refcount drop to zero */
646 struct zfcp_adapter *adapter; /* adapter used to access port */
647 struct list_head unit_list_head; /* head of logical unit list */
648 struct list_head unit_remove_lh; /* head of luns to be removed
649 list */
650 u32 units; /* # of logical units in list */
651 atomic_t status; /* status of this remote port */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 wwn_t wwnn; /* WWNN if known */
653 wwn_t wwpn; /* WWPN */
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200654 u32 d_id; /* D_ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 u32 handle; /* handle assigned by FSF */
656 struct zfcp_erp_action erp_action; /* pending error recovery */
657 atomic_t erp_counter;
Ralph Wuerthner75bfc282006-05-22 18:24:33 +0200658 u32 maxframe_size;
659 u32 supported_classes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660};
661
662/* the struct device sysfs_device must be at the beginning of this structure.
663 * pointer to struct device is used to free unit structure in release function
664 * of the device. don't change!
665 */
666struct zfcp_unit {
667 struct device sysfs_device; /* sysfs device */
668 struct list_head list; /* list of logical units */
669 atomic_t refcount; /* reference count */
670 wait_queue_head_t remove_wq; /* can be used to wait for
671 refcount drop to zero */
672 struct zfcp_port *port; /* remote port of unit */
673 atomic_t status; /* status of this logical unit */
Andreas Herrmann06506d02006-05-22 18:18:19 +0200674 unsigned int scsi_lun; /* own SCSI LUN */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 fcp_lun_t fcp_lun; /* own FCP_LUN */
676 u32 handle; /* handle assigned by FSF */
677 struct scsi_device *device; /* scsi device struct pointer */
678 struct zfcp_erp_action erp_action; /* pending error recovery */
679 atomic_t erp_counter;
Christof Schmittc9615852008-05-06 11:00:05 +0200680 struct zfcp_latencies latencies;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681};
682
683/* FSF request */
684struct zfcp_fsf_req {
685 struct list_head list; /* list of FSF requests */
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200686 unsigned long req_id; /* unique request ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 struct zfcp_adapter *adapter; /* adapter request belongs to */
688 u8 sbal_number; /* nr of SBALs free for use */
689 u8 sbal_first; /* first SBAL for this request */
Martin Peschkee891bff2008-05-19 12:17:43 +0200690 u8 sbal_last; /* last SBAL for this request */
Martin Peschked01d51b2008-05-19 12:17:42 +0200691 u8 sbal_limit; /* last possible SBAL for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 this reuest */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 u8 sbale_curr; /* current SBALE during creation
694 of request */
Martin Peschkec3baa9a22008-05-19 12:17:44 +0200695 u8 sbal_response; /* SBAL used in interrupt */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 wait_queue_head_t completion_wq; /* can be used by a routine
697 to wait for completion */
698 volatile u32 status; /* status of this request */
699 u32 fsf_command; /* FSF Command copy */
700 struct fsf_qtcb *qtcb; /* address of associated QTCB */
701 u32 seq_no; /* Sequence number of request */
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200702 unsigned long data; /* private data of request */
703 struct timer_list timer; /* used for erp or scsi er */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 struct zfcp_erp_action *erp_action; /* used if this request is
705 issued on behalf of erp */
706 mempool_t *pool; /* used if request was alloacted
707 from emergency pool */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200708 unsigned long long issued; /* request sent time (STCK) */
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200709 struct zfcp_unit *unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710};
711
712typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
713
714/* driver data */
715struct zfcp_data {
716 struct scsi_host_template scsi_host_template;
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200717 struct scsi_transport_template *scsi_transport_template;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 atomic_t status; /* Module status flags */
719 struct list_head adapter_list_head; /* head of adapter list */
720 struct list_head adapter_remove_lh; /* head of adapters to be
721 removed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 u32 adapters; /* # of adapters in list */
723 rwlock_t config_lock; /* serialises changes
724 to adapter/port/unit
725 lists */
726 struct semaphore config_sema; /* serialises configuration
727 changes */
728 atomic_t loglevel; /* current loglevel */
729 char init_busid[BUS_ID_SIZE];
730 wwn_t init_wwpn;
731 fcp_lun_t init_fcp_lun;
Christoph Lametere18b8902006-12-06 20:33:20 -0800732 struct kmem_cache *fsf_req_qtcb_cache;
733 struct kmem_cache *sr_buffer_cache;
734 struct kmem_cache *gid_pn_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735};
736
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737/* number of elements for various memory pools */
738#define ZFCP_POOL_FSF_REQ_ERP_NR 1
739#define ZFCP_POOL_FSF_REQ_SCSI_NR 1
740#define ZFCP_POOL_FSF_REQ_ABORT_NR 1
741#define ZFCP_POOL_STATUS_READ_NR ZFCP_STATUS_READS_RECOM
742#define ZFCP_POOL_DATA_GID_PN_NR 1
743
744/* struct used by memory pools for fsf_requests */
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200745struct zfcp_fsf_req_qtcb {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 struct zfcp_fsf_req fsf_req;
747 struct fsf_qtcb qtcb;
748};
749
750/********************** ZFCP SPECIFIC DEFINES ********************************/
751
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752#define ZFCP_REQ_AUTO_CLEANUP 0x00000002
753#define ZFCP_WAIT_FOR_SBAL 0x00000004
754#define ZFCP_REQ_NO_QTCB 0x00000008
755
756#define ZFCP_SET 0x00000100
757#define ZFCP_CLEAR 0x00000200
758
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759#ifndef atomic_test_mask
760#define atomic_test_mask(mask, target) \
761 ((atomic_read(target) & mask) == mask)
762#endif
763
764extern void _zfcp_hex_dump(char *, int);
765#define ZFCP_HEX_DUMP(level, addr, count) \
766 if (ZFCP_LOG_CHECK(level)) { \
767 _zfcp_hex_dump(addr, count); \
768 }
769
770#define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
771#define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
772#define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
773
774/*
Heiko Carstensca2d02c2007-05-08 11:17:54 +0200775 * Helper functions for request ID management.
776 */
777static inline int zfcp_reqlist_hash(unsigned long req_id)
778{
779 return req_id % REQUEST_LIST_SIZE;
780}
781
782static inline void zfcp_reqlist_add(struct zfcp_adapter *adapter,
783 struct zfcp_fsf_req *fsf_req)
784{
785 unsigned int idx;
786
787 idx = zfcp_reqlist_hash(fsf_req->req_id);
788 list_add_tail(&fsf_req->list, &adapter->req_list[idx]);
789}
790
791static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
792 struct zfcp_fsf_req *fsf_req)
793{
794 list_del(&fsf_req->list);
795}
796
797static inline struct zfcp_fsf_req *
798zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
799{
800 struct zfcp_fsf_req *request;
801 unsigned int idx;
802
803 idx = zfcp_reqlist_hash(req_id);
804 list_for_each_entry(request, &adapter->req_list[idx], list)
805 if (request->req_id == req_id)
806 return request;
807 return NULL;
808}
809
Heiko Carstensd1ad09d2007-12-20 12:30:22 +0100810static inline struct zfcp_fsf_req *
811zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req)
812{
813 struct zfcp_fsf_req *request;
814 unsigned int idx;
815
816 for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) {
817 list_for_each_entry(request, &adapter->req_list[idx], list)
818 if (request == req)
819 return request;
820 }
821 return NULL;
822}
823
Heiko Carstensca2d02c2007-05-08 11:17:54 +0200824/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 * functions needed for reference/usage counting
826 */
827
828static inline void
829zfcp_unit_get(struct zfcp_unit *unit)
830{
831 atomic_inc(&unit->refcount);
832}
833
834static inline void
835zfcp_unit_put(struct zfcp_unit *unit)
836{
837 if (atomic_dec_return(&unit->refcount) == 0)
838 wake_up(&unit->remove_wq);
839}
840
841static inline void
842zfcp_unit_wait(struct zfcp_unit *unit)
843{
844 wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
845}
846
847static inline void
848zfcp_port_get(struct zfcp_port *port)
849{
850 atomic_inc(&port->refcount);
851}
852
853static inline void
854zfcp_port_put(struct zfcp_port *port)
855{
856 if (atomic_dec_return(&port->refcount) == 0)
857 wake_up(&port->remove_wq);
858}
859
860static inline void
861zfcp_port_wait(struct zfcp_port *port)
862{
863 wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
864}
865
866static inline void
867zfcp_adapter_get(struct zfcp_adapter *adapter)
868{
869 atomic_inc(&adapter->refcount);
870}
871
872static inline void
873zfcp_adapter_put(struct zfcp_adapter *adapter)
874{
875 if (atomic_dec_return(&adapter->refcount) == 0)
876 wake_up(&adapter->remove_wq);
877}
878
879static inline void
880zfcp_adapter_wait(struct zfcp_adapter *adapter)
881{
882 wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
883}
884
885#endif /* ZFCP_DEF_H */