blob: e19e46ae4a68a24b5803f2dc8ef9be994b6f99e5 [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 Schmittbd43a422008-12-25 13:38:50 +010036#include <asm/sysinfo.h>
Christof Schmitt2b604c92008-03-31 11:15:28 +020037#include "zfcp_dbf.h"
Heiko Carstensdd52e0e2006-09-18 22:28:49 +020038#include "zfcp_fsf.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41/********************* GENERAL DEFINES *********************************/
42
Andreas Herrmann06506d02006-05-22 18:18:19 +020043#define REQUEST_LIST_SIZE 128
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045/********************* SCSI SPECIFIC DEFINES *********************************/
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +020046#define ZFCP_SCSI_ER_TIMEOUT (10*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48/********************* CIO/QDIO SPECIFIC DEFINES *****************************/
49
50/* Adapter Identification Parameters */
51#define ZFCP_CONTROL_UNIT_TYPE 0x1731
52#define ZFCP_CONTROL_UNIT_MODEL 0x03
53#define ZFCP_DEVICE_TYPE 0x1732
54#define ZFCP_DEVICE_MODEL 0x03
55#define ZFCP_DEVICE_MODEL_PRIV 0x04
Swen Schillig41fa2ad2007-09-07 09:15:31 +020056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057/* DMQ bug workaround: don't use last SBALE */
58#define ZFCP_MAX_SBALES_PER_SBAL (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
59
60/* index of last SBALE (with respect to DMQ bug workaround) */
61#define ZFCP_LAST_SBALE_PER_SBAL (ZFCP_MAX_SBALES_PER_SBAL - 1)
62
63/* max. number of (data buffer) SBALEs in largest SBAL chain */
64#define ZFCP_MAX_SBALES_PER_REQ \
Swen Schilligc41f8cb2008-07-02 10:56:39 +020065 (FSF_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
67
Swen Schillig8d1a0062006-10-12 11:43:44 +020068#define ZFCP_MAX_SECTORS (ZFCP_MAX_SBALES_PER_REQ * 8)
69 /* max. number of (data buffer) SBALEs in largest SBAL chain
70 multiplied with number of sectors per 4k block */
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072/********************* FSF SPECIFIC DEFINES *********************************/
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074/* ATTENTION: value must not be used by hardware */
75#define FSF_QTCB_UNSOLICITED_STATUS 0x6305
Andreas Herrmann22753fa2005-06-13 13:15:15 +020076
Linus Torvalds1da177e2005-04-16 15:20:36 -070077/* timeout value for "default timer" for fsf requests */
Andreas Herrmann2abbe862006-09-18 22:29:56 +020078#define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80/*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
81
Linus Torvalds1da177e2005-04-16 15:20:36 -070082/* timeout for name-server lookup (in seconds) */
83#define ZFCP_NS_GID_PN_TIMEOUT 10
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085/* task attribute values in FCP-2 FCP_CMND IU */
86#define SIMPLE_Q 0
87#define HEAD_OF_Q 1
88#define ORDERED_Q 2
89#define ACA_Q 4
90#define UNTAGGED 5
91
92/* task management flags in FCP-2 FCP_CMND IU */
93#define FCP_CLEAR_ACA 0x40
94#define FCP_TARGET_RESET 0x20
95#define FCP_LOGICAL_UNIT_RESET 0x10
96#define FCP_CLEAR_TASK_SET 0x04
97#define FCP_ABORT_TASK_SET 0x02
98
99#define FCP_CDB_LENGTH 16
100
101#define ZFCP_DID_MASK 0x00FFFFFF
102
103/* FCP(-2) FCP_CMND IU */
104struct fcp_cmnd_iu {
Swen Schillig7ba58c92008-10-01 12:42:18 +0200105 u64 fcp_lun; /* FCP logical unit number */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 u8 crn; /* command reference number */
107 u8 reserved0:5; /* reserved */
108 u8 task_attribute:3; /* task attribute */
109 u8 task_management_flags; /* task management flags */
110 u8 add_fcp_cdb_length:6; /* additional FCP_CDB length */
111 u8 rddata:1; /* read data */
112 u8 wddata:1; /* write data */
113 u8 fcp_cdb[FCP_CDB_LENGTH];
114} __attribute__((packed));
115
116/* FCP(-2) FCP_RSP IU */
117struct fcp_rsp_iu {
118 u8 reserved0[10];
119 union {
120 struct {
121 u8 reserved1:3;
122 u8 fcp_conf_req:1;
123 u8 fcp_resid_under:1;
124 u8 fcp_resid_over:1;
125 u8 fcp_sns_len_valid:1;
126 u8 fcp_rsp_len_valid:1;
127 } bits;
128 u8 value;
129 } validity;
130 u8 scsi_status;
131 u32 fcp_resid;
132 u32 fcp_sns_len;
133 u32 fcp_rsp_len;
134} __attribute__((packed));
135
136
137#define RSP_CODE_GOOD 0
138#define RSP_CODE_LENGTH_MISMATCH 1
139#define RSP_CODE_FIELD_INVALID 2
140#define RSP_CODE_RO_MISMATCH 3
141#define RSP_CODE_TASKMAN_UNSUPP 4
142#define RSP_CODE_TASKMAN_FAILED 5
143
144/* see fc-fs */
Christof Schmitt24073b42008-06-10 18:20:54 +0200145#define LS_RSCN 0x61
146#define LS_LOGO 0x05
147#define LS_PLOGI 0x03
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149struct fcp_rscn_head {
150 u8 command;
151 u8 page_length; /* always 0x04 */
152 u16 payload_len;
153} __attribute__((packed));
154
155struct fcp_rscn_element {
156 u8 reserved:2;
157 u8 event_qual:4;
158 u8 addr_format:2;
159 u32 nport_did:24;
160} __attribute__((packed));
161
162#define ZFCP_PORT_ADDRESS 0x0
163#define ZFCP_AREA_ADDRESS 0x1
164#define ZFCP_DOMAIN_ADDRESS 0x2
165#define ZFCP_FABRIC_ADDRESS 0x3
166
167#define ZFCP_PORTS_RANGE_PORT 0xFFFFFF
168#define ZFCP_PORTS_RANGE_AREA 0xFFFF00
169#define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
170#define ZFCP_PORTS_RANGE_FABRIC 0x000000
171
172#define ZFCP_NO_PORTS_PER_AREA 0x100
173#define ZFCP_NO_PORTS_PER_DOMAIN 0x10000
174#define ZFCP_NO_PORTS_PER_FABRIC 0x1000000
175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176/* see fc-ph */
177struct fcp_logo {
178 u32 command;
179 u32 nport_did;
Swen Schillig7ba58c92008-10-01 12:42:18 +0200180 u64 nport_wwpn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181} __attribute__((packed));
182
183/*
184 * FC-FS stuff
185 */
186#define R_A_TOV 10 /* seconds */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188#define ZFCP_LS_RLS 0x0f
189#define ZFCP_LS_ADISC 0x52
190#define ZFCP_LS_RPS 0x56
191#define ZFCP_LS_RSCN 0x61
192#define ZFCP_LS_RNID 0x78
193
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194struct zfcp_ls_adisc {
195 u8 code;
196 u8 field[3];
197 u32 hard_nport_id;
198 u64 wwpn;
199 u64 wwnn;
200 u32 nport_id;
201} __attribute__ ((packed));
202
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203/*
204 * FC-GS-2 stuff
205 */
206#define ZFCP_CT_REVISION 0x01
207#define ZFCP_CT_DIRECTORY_SERVICE 0xFC
208#define ZFCP_CT_NAME_SERVER 0x02
209#define ZFCP_CT_SYNCHRONOUS 0x00
Swen Schilligcc8c2822008-06-10 18:21:00 +0200210#define ZFCP_CT_SCSI_FCP 0x08
211#define ZFCP_CT_UNABLE_TO_PERFORM_CMD 0x09
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212#define ZFCP_CT_GID_PN 0x0121
Swen Schilligcc8c2822008-06-10 18:21:00 +0200213#define ZFCP_CT_GPN_FT 0x0172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214#define ZFCP_CT_MAX_SIZE 0x1020
215#define ZFCP_CT_ACCEPT 0x8002
216#define ZFCP_CT_REJECT 0x8001
217
218/*
219 * FC-GS-4 stuff
220 */
221#define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223/*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
224
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200225/*
226 * Note, the leftmost status byte is common among adapter, port
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 * and unit
228 */
229#define ZFCP_COMMON_FLAGS 0xfff00000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231/* common status bits */
232#define ZFCP_STATUS_COMMON_REMOVE 0x80000000
233#define ZFCP_STATUS_COMMON_RUNNING 0x40000000
234#define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
235#define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236#define ZFCP_STATUS_COMMON_OPEN 0x04000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237#define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
238#define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
Andreas Herrmannd736a272005-06-13 13:23:57 +0200239#define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
Swen Schilligcc8c2822008-06-10 18:21:00 +0200240#define ZFCP_STATUS_COMMON_NOESC 0x00200000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
242/* adapter status */
243#define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244#define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
245#define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
246#define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
247#define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
248#define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
249#define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
250
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251/* FC-PH/FC-GS well-known address identifiers for generic services */
Swen Schillig5ab944f2008-10-01 12:42:17 +0200252#define ZFCP_DID_WKA 0xFFFFF0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253#define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA
254#define ZFCP_DID_TIME_SERVICE 0xFFFFFB
255#define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC
256#define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8
257#define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7
258
259/* remote port status */
260#define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
261#define ZFCP_STATUS_PORT_DID_DID 0x00000002
262#define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
263#define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264#define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Swen Schillig5ab944f2008-10-01 12:42:17 +0200266/* well known address (WKA) port status*/
267enum zfcp_wka_status {
268 ZFCP_WKA_PORT_OFFLINE,
269 ZFCP_WKA_PORT_CLOSING,
270 ZFCP_WKA_PORT_OPENING,
271 ZFCP_WKA_PORT_ONLINE,
272};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
274/* logical unit status */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275#define ZFCP_STATUS_UNIT_SHARED 0x00000004
276#define ZFCP_STATUS_UNIT_READONLY 0x00000008
Andreas Herrmannad58f7d2006-03-10 00:56:16 +0100277#define ZFCP_STATUS_UNIT_REGISTERED 0x00000010
Christof Schmitt5f852be2007-05-08 11:16:52 +0200278#define ZFCP_STATUS_UNIT_SCSI_WORK_PENDING 0x00000020
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
280/* FSF request status (this does not have a common part) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281#define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
282#define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
283#define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
284#define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285#define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
286#define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
287#define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
288#define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
289#define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
290#define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
291#define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
292
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293/************************* STRUCTURE DEFINITIONS *****************************/
294
295struct zfcp_fsf_req;
296
297/* holds various memory pools of an adapter */
298struct zfcp_adapter_mempool {
299 mempool_t *fsf_req_erp;
300 mempool_t *fsf_req_scsi;
301 mempool_t *fsf_req_abort;
302 mempool_t *fsf_req_status_read;
303 mempool_t *data_status_read;
304 mempool_t *data_gid_pn;
305};
306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307/*
308 * header for CT_IU
309 */
310struct ct_hdr {
311 u8 revision; // 0x01
312 u8 in_id[3]; // 0x00
313 u8 gs_type; // 0xFC Directory Service
314 u8 gs_subtype; // 0x02 Name Server
315 u8 options; // 0x00 single bidirectional exchange
316 u8 reserved0;
317 u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT
318 u16 max_res_size; // <= (4096 - 16) / 4
319 u8 reserved1;
320 u8 reason_code;
321 u8 reason_code_expl;
322 u8 vendor_unique;
323} __attribute__ ((packed));
324
325/* nameserver request CT_IU -- for requests where
326 * a port name is required */
327struct ct_iu_gid_pn_req {
328 struct ct_hdr header;
Swen Schillig7ba58c92008-10-01 12:42:18 +0200329 u64 wwpn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330} __attribute__ ((packed));
331
332/* FS_ACC IU and data unit for GID_PN nameserver request */
333struct ct_iu_gid_pn_resp {
334 struct ct_hdr header;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200335 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336} __attribute__ ((packed));
337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338/**
339 * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
Swen Schillig5ab944f2008-10-01 12:42:17 +0200340 * @wka_port: port where the request is sent to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 * @req: scatter-gather list for request
342 * @resp: scatter-gather list for response
343 * @req_count: number of elements in request scatter-gather list
344 * @resp_count: number of elements in response scatter-gather list
345 * @handler: handler function (called for response to the request)
346 * @handler_data: data passed to handler function
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 * @timeout: FSF timeout for this request
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 * @completion: completion for synchronization purposes
349 * @status: used to pass error status to calling function
350 */
351struct zfcp_send_ct {
Swen Schillig5ab944f2008-10-01 12:42:17 +0200352 struct zfcp_wka_port *wka_port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 struct scatterlist *req;
354 struct scatterlist *resp;
355 unsigned int req_count;
356 unsigned int resp_count;
Swen Schillig7ba58c92008-10-01 12:42:18 +0200357 void (*handler)(unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 unsigned long handler_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 int timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 struct completion *completion;
361 int status;
362};
363
364/* used for name server requests in error recovery */
365struct zfcp_gid_pn_data {
366 struct zfcp_send_ct ct;
367 struct scatterlist req;
368 struct scatterlist resp;
369 struct ct_iu_gid_pn_req ct_iu_req;
370 struct ct_iu_gid_pn_resp ct_iu_resp;
371 struct zfcp_port *port;
372};
373
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374/**
375 * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
376 * @adapter: adapter where request is sent from
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200377 * @port: port where ELS is destinated (port reference count has to be increased)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 * @d_id: destiniation id of port where request is sent to
379 * @req: scatter-gather list for request
380 * @resp: scatter-gather list for response
381 * @req_count: number of elements in request scatter-gather list
382 * @resp_count: number of elements in response scatter-gather list
383 * @handler: handler function (called for response to the request)
384 * @handler_data: data passed to handler function
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 * @completion: completion for synchronization purposes
386 * @ls_code: hex code of ELS command
387 * @status: used to pass error status to calling function
388 */
389struct zfcp_send_els {
390 struct zfcp_adapter *adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200391 struct zfcp_port *port;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200392 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 struct scatterlist *req;
394 struct scatterlist *resp;
395 unsigned int req_count;
396 unsigned int resp_count;
Swen Schillig7ba58c92008-10-01 12:42:18 +0200397 void (*handler)(unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 unsigned long handler_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 struct completion *completion;
400 int ls_code;
401 int status;
402};
403
Swen Schillig5ab944f2008-10-01 12:42:17 +0200404struct zfcp_wka_port {
405 struct zfcp_adapter *adapter;
406 wait_queue_head_t completion_wq;
407 enum zfcp_wka_status status;
408 atomic_t refcount;
409 u32 d_id;
410 u32 handle;
411 struct mutex mutex;
412 struct delayed_work work;
413};
414
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415struct zfcp_qdio_queue {
Christof Schmitt04062892008-10-01 12:42:20 +0200416 struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q];
417 u8 first; /* index of next free bfr in queue */
418 atomic_t count; /* number of free buffers in queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419};
420
421struct zfcp_erp_action {
422 struct list_head list;
423 int action; /* requested action code */
424 struct zfcp_adapter *adapter; /* device which should be recovered */
425 struct zfcp_port *port;
426 struct zfcp_unit *unit;
Swen Schillig44cc76f2008-10-01 12:42:16 +0200427 u32 status; /* recovery status */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 u32 step; /* active step of this erp action */
429 struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
430 for this action */
431 struct timer_list timer;
432};
433
Christof Schmittc9615852008-05-06 11:00:05 +0200434struct fsf_latency_record {
435 u32 min;
436 u32 max;
437 u64 sum;
438};
439
440struct latency_cont {
441 struct fsf_latency_record channel;
442 struct fsf_latency_record fabric;
443 u64 counter;
444};
445
446struct zfcp_latencies {
447 struct latency_cont read;
448 struct latency_cont write;
449 struct latency_cont cmd;
450 spinlock_t lock;
451};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
453struct zfcp_adapter {
454 struct list_head list; /* list of adapters */
455 atomic_t refcount; /* reference count */
456 wait_queue_head_t remove_wq; /* can be used to wait for
457 refcount drop to zero */
Swen Schillig7ba58c92008-10-01 12:42:18 +0200458 u64 peer_wwnn; /* P2P peer WWNN */
459 u64 peer_wwpn; /* P2P peer WWPN */
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200460 u32 peer_d_id; /* P2P peer D_ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 struct ccw_device *ccw_device; /* S/390 ccw device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 u32 hydra_version; /* Hydra version */
463 u32 fsf_lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200464 u32 adapter_features; /* FCP channel features */
465 u32 connection_features; /* host connection features */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 u32 hardware_version; /* of FCP channel */
Christof Schmittc9615852008-05-06 11:00:05 +0200467 u16 timer_ticks; /* time int for a tick */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 struct list_head port_list_head; /* remote port list */
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200470 unsigned long req_no; /* unique FSF req number */
471 struct list_head *req_list; /* list of pending reqs */
472 spinlock_t req_list_lock; /* request list lock */
Swen Schillig00bab912008-06-10 18:20:57 +0200473 struct zfcp_qdio_queue req_q; /* request queue */
Christof Schmitt04062892008-10-01 12:42:20 +0200474 spinlock_t req_q_lock; /* for operations on queue */
475 int req_q_pci_batch; /* SBALs since PCI indication
476 was last set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 u32 fsf_req_seq_no; /* FSF cmnd seq number */
478 wait_queue_head_t request_wq; /* can be used to wait for
479 more avaliable SBALs */
Swen Schillig00bab912008-06-10 18:20:57 +0200480 struct zfcp_qdio_queue resp_q; /* response queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 rwlock_t abort_lock; /* Protects against SCSI
482 stack abort/command
483 completion races */
Swen Schilligd26ab062008-05-19 12:17:37 +0200484 atomic_t stat_miss; /* # missing status reads*/
485 struct work_struct stat_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 atomic_t status; /* status of this adapter */
487 struct list_head erp_ready_head; /* error recovery for this
488 adapter/devices */
489 struct list_head erp_running_head;
490 rwlock_t erp_lock;
491 struct semaphore erp_ready_sem;
492 wait_queue_head_t erp_thread_wqh;
493 wait_queue_head_t erp_done_wqh;
494 struct zfcp_erp_action erp_action; /* pending error recovery */
495 atomic_t erp_counter;
496 u32 erp_total_count; /* total nr of enqueued erp
497 actions */
498 u32 erp_low_mem_count; /* nr of erp actions waiting
499 for memory */
Swen Schillig5ab944f2008-10-01 12:42:17 +0200500 struct zfcp_wka_port nsp; /* adapter's nameserver */
Martin Peschked79a83d2008-03-27 14:22:00 +0100501 debug_info_t *rec_dbf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200502 debug_info_t *hba_dbf;
503 debug_info_t *san_dbf; /* debug feature areas */
504 debug_info_t *scsi_dbf;
Martin Peschked79a83d2008-03-27 14:22:00 +0100505 spinlock_t rec_dbf_lock;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200506 spinlock_t hba_dbf_lock;
507 spinlock_t san_dbf_lock;
508 spinlock_t scsi_dbf_lock;
Martin Peschked79a83d2008-03-27 14:22:00 +0100509 struct zfcp_rec_dbf_record rec_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200510 struct zfcp_hba_dbf_record hba_dbf_buf;
511 struct zfcp_san_dbf_record san_dbf_buf;
512 struct zfcp_scsi_dbf_record scsi_dbf_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 struct zfcp_adapter_mempool pool; /* Adapter memory pools */
514 struct qdio_initialize qdio_init_data; /* for qdio_establish */
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100515 struct fc_host_statistics *fc_stats;
516 struct fsf_qtcb_bottom_port *stats_reset_data;
517 unsigned long stats_reset;
Swen Schilligcc8c2822008-06-10 18:21:00 +0200518 struct work_struct scan_work;
Christof Schmittbd43a422008-12-25 13:38:50 +0100519 struct service_level service_level;
Stefan Raspl2450d3e2008-10-01 12:42:14 +0200520 atomic_t qdio_outb_full; /* queue full incidents */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521};
522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523struct zfcp_port {
524 struct device sysfs_device; /* sysfs device */
Andreas Herrmann3859f6a2005-08-27 11:07:54 -0700525 struct fc_rport *rport; /* rport of fc transport class */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 struct list_head list; /* list of remote ports */
527 atomic_t refcount; /* reference count */
528 wait_queue_head_t remove_wq; /* can be used to wait for
529 refcount drop to zero */
530 struct zfcp_adapter *adapter; /* adapter used to access port */
531 struct list_head unit_list_head; /* head of logical unit list */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 atomic_t status; /* status of this remote port */
Swen Schillig7ba58c92008-10-01 12:42:18 +0200533 u64 wwnn; /* WWNN if known */
534 u64 wwpn; /* WWPN */
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200535 u32 d_id; /* D_ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 u32 handle; /* handle assigned by FSF */
537 struct zfcp_erp_action erp_action; /* pending error recovery */
538 atomic_t erp_counter;
Ralph Wuerthner75bfc282006-05-22 18:24:33 +0200539 u32 maxframe_size;
540 u32 supported_classes;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200541 struct work_struct gid_pn_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542};
543
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544struct zfcp_unit {
545 struct device sysfs_device; /* sysfs device */
546 struct list_head list; /* list of logical units */
547 atomic_t refcount; /* reference count */
548 wait_queue_head_t remove_wq; /* can be used to wait for
549 refcount drop to zero */
550 struct zfcp_port *port; /* remote port of unit */
551 atomic_t status; /* status of this logical unit */
Swen Schillig7ba58c92008-10-01 12:42:18 +0200552 u64 fcp_lun; /* own FCP_LUN */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 u32 handle; /* handle assigned by FSF */
554 struct scsi_device *device; /* scsi device struct pointer */
555 struct zfcp_erp_action erp_action; /* pending error recovery */
556 atomic_t erp_counter;
Christof Schmittc9615852008-05-06 11:00:05 +0200557 struct zfcp_latencies latencies;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558};
559
560/* FSF request */
561struct zfcp_fsf_req {
562 struct list_head list; /* list of FSF requests */
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200563 unsigned long req_id; /* unique request ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 struct zfcp_adapter *adapter; /* adapter request belongs to */
565 u8 sbal_number; /* nr of SBALs free for use */
566 u8 sbal_first; /* first SBAL for this request */
Martin Peschkee891bff2008-05-19 12:17:43 +0200567 u8 sbal_last; /* last SBAL for this request */
Martin Peschked01d51b2008-05-19 12:17:42 +0200568 u8 sbal_limit; /* last possible SBAL for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 this reuest */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 u8 sbale_curr; /* current SBALE during creation
571 of request */
Martin Peschkec3baa9a22008-05-19 12:17:44 +0200572 u8 sbal_response; /* SBAL used in interrupt */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 wait_queue_head_t completion_wq; /* can be used by a routine
574 to wait for completion */
Swen Schillig44cc76f2008-10-01 12:42:16 +0200575 u32 status; /* status of this request */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 u32 fsf_command; /* FSF Command copy */
577 struct fsf_qtcb *qtcb; /* address of associated QTCB */
578 u32 seq_no; /* Sequence number of request */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200579 void *data; /* private data of request */
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200580 struct timer_list timer; /* used for erp or scsi er */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 struct zfcp_erp_action *erp_action; /* used if this request is
582 issued on behalf of erp */
583 mempool_t *pool; /* used if request was alloacted
584 from emergency pool */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200585 unsigned long long issued; /* request sent time (STCK) */
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200586 struct zfcp_unit *unit;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200587 void (*handler)(struct zfcp_fsf_req *);
Stefan Raspl0997f1c2008-10-16 08:23:39 +0200588 u16 qdio_outb_usage;/* usage of outbound queue */
589 u16 qdio_inb_usage; /* usage of inbound queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590};
591
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592/* driver data */
593struct zfcp_data {
594 struct scsi_host_template scsi_host_template;
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200595 struct scsi_transport_template *scsi_transport_template;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 struct list_head adapter_list_head; /* head of adapter list */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 rwlock_t config_lock; /* serialises changes
598 to adapter/port/unit
599 lists */
600 struct semaphore config_sema; /* serialises configuration
601 changes */
602 atomic_t loglevel; /* current loglevel */
Kay Sievers2a0217d2008-10-10 21:33:09 +0200603 char init_busid[20];
Swen Schillig7ba58c92008-10-01 12:42:18 +0200604 u64 init_wwpn;
605 u64 init_fcp_lun;
606 struct kmem_cache *fsf_req_qtcb_cache;
607 struct kmem_cache *sr_buffer_cache;
608 struct kmem_cache *gid_pn_cache;
Swen Schilligb7f15f32008-10-01 12:42:22 +0200609 struct workqueue_struct *work_queue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610};
611
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612/* struct used by memory pools for fsf_requests */
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200613struct zfcp_fsf_req_qtcb {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 struct zfcp_fsf_req fsf_req;
615 struct fsf_qtcb qtcb;
616};
617
618/********************** ZFCP SPECIFIC DEFINES ********************************/
619
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620#define ZFCP_REQ_AUTO_CLEANUP 0x00000002
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621#define ZFCP_REQ_NO_QTCB 0x00000008
622
623#define ZFCP_SET 0x00000100
624#define ZFCP_CLEAR 0x00000200
625
Cornelia Huckb9d3aed2008-10-10 21:33:11 +0200626#define zfcp_get_busid_by_adapter(adapter) (dev_name(&adapter->ccw_device->dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
628/*
Heiko Carstensca2d02c2007-05-08 11:17:54 +0200629 * Helper functions for request ID management.
630 */
631static inline int zfcp_reqlist_hash(unsigned long req_id)
632{
633 return req_id % REQUEST_LIST_SIZE;
634}
635
Heiko Carstensca2d02c2007-05-08 11:17:54 +0200636static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
637 struct zfcp_fsf_req *fsf_req)
638{
639 list_del(&fsf_req->list);
640}
641
642static inline struct zfcp_fsf_req *
643zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
644{
645 struct zfcp_fsf_req *request;
646 unsigned int idx;
647
648 idx = zfcp_reqlist_hash(req_id);
649 list_for_each_entry(request, &adapter->req_list[idx], list)
650 if (request->req_id == req_id)
651 return request;
652 return NULL;
653}
654
Heiko Carstensd1ad09d2007-12-20 12:30:22 +0100655static inline struct zfcp_fsf_req *
656zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req)
657{
658 struct zfcp_fsf_req *request;
659 unsigned int idx;
660
661 for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) {
662 list_for_each_entry(request, &adapter->req_list[idx], list)
663 if (request == req)
664 return request;
665 }
666 return NULL;
667}
668
Heiko Carstensca2d02c2007-05-08 11:17:54 +0200669/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 * functions needed for reference/usage counting
671 */
672
673static inline void
674zfcp_unit_get(struct zfcp_unit *unit)
675{
676 atomic_inc(&unit->refcount);
677}
678
679static inline void
680zfcp_unit_put(struct zfcp_unit *unit)
681{
682 if (atomic_dec_return(&unit->refcount) == 0)
683 wake_up(&unit->remove_wq);
684}
685
686static inline void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687zfcp_port_get(struct zfcp_port *port)
688{
689 atomic_inc(&port->refcount);
690}
691
692static inline void
693zfcp_port_put(struct zfcp_port *port)
694{
695 if (atomic_dec_return(&port->refcount) == 0)
696 wake_up(&port->remove_wq);
697}
698
699static inline void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700zfcp_adapter_get(struct zfcp_adapter *adapter)
701{
702 atomic_inc(&adapter->refcount);
703}
704
705static inline void
706zfcp_adapter_put(struct zfcp_adapter *adapter)
707{
708 if (atomic_dec_return(&adapter->refcount) == 0)
709 wake_up(&adapter->remove_wq);
710}
711
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712#endif /* ZFCP_DEF_H */