blob: 67f45fc62f53b3cad2e5df6b1ed86ee60046ecd7 [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/* DMQ bug workaround: don't use last SBALE */
80#define ZFCP_MAX_SBALES_PER_SBAL (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
81
82/* index of last SBALE (with respect to DMQ bug workaround) */
83#define ZFCP_LAST_SBALE_PER_SBAL (ZFCP_MAX_SBALES_PER_SBAL - 1)
84
85/* max. number of (data buffer) SBALEs in largest SBAL chain */
86#define ZFCP_MAX_SBALES_PER_REQ \
Swen Schilligc41f8cb2008-07-02 10:56:39 +020087 (FSF_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
89
Swen Schillig8d1a0062006-10-12 11:43:44 +020090#define ZFCP_MAX_SECTORS (ZFCP_MAX_SBALES_PER_REQ * 8)
91 /* max. number of (data buffer) SBALEs in largest SBAL chain
92 multiplied with number of sectors per 4k block */
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094/********************* FSF SPECIFIC DEFINES *********************************/
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096/* ATTENTION: value must not be used by hardware */
97#define FSF_QTCB_UNSOLICITED_STATUS 0x6305
Andreas Herrmann22753fa2005-06-13 13:15:15 +020098
Linus Torvalds1da177e2005-04-16 15:20:36 -070099/* timeout value for "default timer" for fsf requests */
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200100#define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
102/*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
103
104typedef unsigned long long wwn_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105typedef unsigned long long fcp_lun_t;
106/* data length field may be at variable position in FCP-2 FCP_CMND IU */
107typedef unsigned int fcp_dl_t;
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109/* timeout for name-server lookup (in seconds) */
110#define ZFCP_NS_GID_PN_TIMEOUT 10
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112/* task attribute values in FCP-2 FCP_CMND IU */
113#define SIMPLE_Q 0
114#define HEAD_OF_Q 1
115#define ORDERED_Q 2
116#define ACA_Q 4
117#define UNTAGGED 5
118
119/* task management flags in FCP-2 FCP_CMND IU */
120#define FCP_CLEAR_ACA 0x40
121#define FCP_TARGET_RESET 0x20
122#define FCP_LOGICAL_UNIT_RESET 0x10
123#define FCP_CLEAR_TASK_SET 0x04
124#define FCP_ABORT_TASK_SET 0x02
125
126#define FCP_CDB_LENGTH 16
127
128#define ZFCP_DID_MASK 0x00FFFFFF
129
130/* FCP(-2) FCP_CMND IU */
131struct fcp_cmnd_iu {
132 fcp_lun_t fcp_lun; /* FCP logical unit number */
133 u8 crn; /* command reference number */
134 u8 reserved0:5; /* reserved */
135 u8 task_attribute:3; /* task attribute */
136 u8 task_management_flags; /* task management flags */
137 u8 add_fcp_cdb_length:6; /* additional FCP_CDB length */
138 u8 rddata:1; /* read data */
139 u8 wddata:1; /* write data */
140 u8 fcp_cdb[FCP_CDB_LENGTH];
141} __attribute__((packed));
142
143/* FCP(-2) FCP_RSP IU */
144struct fcp_rsp_iu {
145 u8 reserved0[10];
146 union {
147 struct {
148 u8 reserved1:3;
149 u8 fcp_conf_req:1;
150 u8 fcp_resid_under:1;
151 u8 fcp_resid_over:1;
152 u8 fcp_sns_len_valid:1;
153 u8 fcp_rsp_len_valid:1;
154 } bits;
155 u8 value;
156 } validity;
157 u8 scsi_status;
158 u32 fcp_resid;
159 u32 fcp_sns_len;
160 u32 fcp_rsp_len;
161} __attribute__((packed));
162
163
164#define RSP_CODE_GOOD 0
165#define RSP_CODE_LENGTH_MISMATCH 1
166#define RSP_CODE_FIELD_INVALID 2
167#define RSP_CODE_RO_MISMATCH 3
168#define RSP_CODE_TASKMAN_UNSUPP 4
169#define RSP_CODE_TASKMAN_FAILED 5
170
171/* see fc-fs */
Christof Schmitt24073b42008-06-10 18:20:54 +0200172#define LS_RSCN 0x61
173#define LS_LOGO 0x05
174#define LS_PLOGI 0x03
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
176struct fcp_rscn_head {
177 u8 command;
178 u8 page_length; /* always 0x04 */
179 u16 payload_len;
180} __attribute__((packed));
181
182struct fcp_rscn_element {
183 u8 reserved:2;
184 u8 event_qual:4;
185 u8 addr_format:2;
186 u32 nport_did:24;
187} __attribute__((packed));
188
189#define ZFCP_PORT_ADDRESS 0x0
190#define ZFCP_AREA_ADDRESS 0x1
191#define ZFCP_DOMAIN_ADDRESS 0x2
192#define ZFCP_FABRIC_ADDRESS 0x3
193
194#define ZFCP_PORTS_RANGE_PORT 0xFFFFFF
195#define ZFCP_PORTS_RANGE_AREA 0xFFFF00
196#define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
197#define ZFCP_PORTS_RANGE_FABRIC 0x000000
198
199#define ZFCP_NO_PORTS_PER_AREA 0x100
200#define ZFCP_NO_PORTS_PER_DOMAIN 0x10000
201#define ZFCP_NO_PORTS_PER_FABRIC 0x1000000
202
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203/* see fc-ph */
204struct fcp_logo {
205 u32 command;
206 u32 nport_did;
207 wwn_t nport_wwpn;
208} __attribute__((packed));
209
210/*
211 * FC-FS stuff
212 */
213#define R_A_TOV 10 /* seconds */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215#define ZFCP_LS_RLS 0x0f
216#define ZFCP_LS_ADISC 0x52
217#define ZFCP_LS_RPS 0x56
218#define ZFCP_LS_RSCN 0x61
219#define ZFCP_LS_RNID 0x78
220
221struct zfcp_ls_rjt_par {
222 u8 action;
223 u8 reason_code;
224 u8 reason_expl;
225 u8 vendor_unique;
226} __attribute__ ((packed));
227
228struct zfcp_ls_adisc {
229 u8 code;
230 u8 field[3];
231 u32 hard_nport_id;
232 u64 wwpn;
233 u64 wwnn;
234 u32 nport_id;
235} __attribute__ ((packed));
236
237struct zfcp_ls_adisc_acc {
238 u8 code;
239 u8 field[3];
240 u32 hard_nport_id;
241 u64 wwpn;
242 u64 wwnn;
243 u32 nport_id;
244} __attribute__ ((packed));
245
246struct zfcp_rc_entry {
247 u8 code;
248 const char *description;
249};
250
251/*
252 * FC-GS-2 stuff
253 */
254#define ZFCP_CT_REVISION 0x01
255#define ZFCP_CT_DIRECTORY_SERVICE 0xFC
256#define ZFCP_CT_NAME_SERVER 0x02
257#define ZFCP_CT_SYNCHRONOUS 0x00
Swen Schilligcc8c2822008-06-10 18:21:00 +0200258#define ZFCP_CT_SCSI_FCP 0x08
259#define ZFCP_CT_UNABLE_TO_PERFORM_CMD 0x09
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260#define ZFCP_CT_GID_PN 0x0121
Swen Schilligcc8c2822008-06-10 18:21:00 +0200261#define ZFCP_CT_GPN_FT 0x0172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262#define ZFCP_CT_MAX_SIZE 0x1020
263#define ZFCP_CT_ACCEPT 0x8002
264#define ZFCP_CT_REJECT 0x8001
265
266/*
267 * FC-GS-4 stuff
268 */
269#define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271/*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
272
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200273/*
274 * Note, the leftmost status byte is common among adapter, port
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 * and unit
276 */
277#define ZFCP_COMMON_FLAGS 0xfff00000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
279/* common status bits */
280#define ZFCP_STATUS_COMMON_REMOVE 0x80000000
281#define ZFCP_STATUS_COMMON_RUNNING 0x40000000
282#define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
283#define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
284#define ZFCP_STATUS_COMMON_OPENING 0x08000000
285#define ZFCP_STATUS_COMMON_OPEN 0x04000000
286#define ZFCP_STATUS_COMMON_CLOSING 0x02000000
287#define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
288#define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
Andreas Herrmannd736a272005-06-13 13:23:57 +0200289#define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
Swen Schilligcc8c2822008-06-10 18:21:00 +0200290#define ZFCP_STATUS_COMMON_NOESC 0x00200000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
292/* adapter status */
293#define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
294#define ZFCP_STATUS_ADAPTER_REGISTERED 0x00000004
295#define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
296#define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
297#define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
298#define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
299#define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
300#define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200301#define ZFCP_STATUS_ADAPTER_XPORT_OK 0x00000800
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303/* FC-PH/FC-GS well-known address identifiers for generic services */
304#define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA
305#define ZFCP_DID_TIME_SERVICE 0xFFFFFB
306#define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC
307#define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8
308#define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7
309
310/* remote port status */
311#define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
312#define ZFCP_STATUS_PORT_DID_DID 0x00000002
313#define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
314#define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
315#define ZFCP_STATUS_PORT_NO_SCSI_ID 0x00000010
316#define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
318/* for ports with well known addresses */
319#define ZFCP_STATUS_PORT_WKA \
320 (ZFCP_STATUS_PORT_NO_WWPN | \
321 ZFCP_STATUS_PORT_NO_SCSI_ID)
322
323/* logical unit status */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324#define ZFCP_STATUS_UNIT_TEMPORARY 0x00000002
325#define ZFCP_STATUS_UNIT_SHARED 0x00000004
326#define ZFCP_STATUS_UNIT_READONLY 0x00000008
Andreas Herrmannad58f7d2006-03-10 00:56:16 +0100327#define ZFCP_STATUS_UNIT_REGISTERED 0x00000010
Christof Schmitt5f852be2007-05-08 11:16:52 +0200328#define ZFCP_STATUS_UNIT_SCSI_WORK_PENDING 0x00000020
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
330/* FSF request status (this does not have a common part) */
331#define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000
332#define ZFCP_STATUS_FSFREQ_POOL 0x00000001
333#define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
334#define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
335#define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
336#define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
337#define ZFCP_STATUS_FSFREQ_ABORTING 0x00000020
338#define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
339#define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
340#define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
341#define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
342#define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
343#define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
344#define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
345
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346/************************* STRUCTURE DEFINITIONS *****************************/
347
348struct zfcp_fsf_req;
349
350/* holds various memory pools of an adapter */
351struct zfcp_adapter_mempool {
352 mempool_t *fsf_req_erp;
353 mempool_t *fsf_req_scsi;
354 mempool_t *fsf_req_abort;
355 mempool_t *fsf_req_status_read;
356 mempool_t *data_status_read;
357 mempool_t *data_gid_pn;
358};
359
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360/*
361 * header for CT_IU
362 */
363struct ct_hdr {
364 u8 revision; // 0x01
365 u8 in_id[3]; // 0x00
366 u8 gs_type; // 0xFC Directory Service
367 u8 gs_subtype; // 0x02 Name Server
368 u8 options; // 0x00 single bidirectional exchange
369 u8 reserved0;
370 u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT
371 u16 max_res_size; // <= (4096 - 16) / 4
372 u8 reserved1;
373 u8 reason_code;
374 u8 reason_code_expl;
375 u8 vendor_unique;
376} __attribute__ ((packed));
377
378/* nameserver request CT_IU -- for requests where
379 * a port name is required */
380struct ct_iu_gid_pn_req {
381 struct ct_hdr header;
382 wwn_t wwpn;
383} __attribute__ ((packed));
384
385/* FS_ACC IU and data unit for GID_PN nameserver request */
386struct ct_iu_gid_pn_resp {
387 struct ct_hdr header;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200388 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389} __attribute__ ((packed));
390
391typedef void (*zfcp_send_ct_handler_t)(unsigned long);
392
393/**
394 * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
395 * @port: port where the request is sent to
396 * @req: scatter-gather list for request
397 * @resp: scatter-gather list for response
398 * @req_count: number of elements in request scatter-gather list
399 * @resp_count: number of elements in response scatter-gather list
400 * @handler: handler function (called for response to the request)
401 * @handler_data: data passed to handler function
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 * @timeout: FSF timeout for this request
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 * @completion: completion for synchronization purposes
404 * @status: used to pass error status to calling function
405 */
406struct zfcp_send_ct {
407 struct zfcp_port *port;
408 struct scatterlist *req;
409 struct scatterlist *resp;
410 unsigned int req_count;
411 unsigned int resp_count;
412 zfcp_send_ct_handler_t handler;
413 unsigned long handler_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 int timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 struct completion *completion;
416 int status;
417};
418
419/* used for name server requests in error recovery */
420struct zfcp_gid_pn_data {
421 struct zfcp_send_ct ct;
422 struct scatterlist req;
423 struct scatterlist resp;
424 struct ct_iu_gid_pn_req ct_iu_req;
425 struct ct_iu_gid_pn_resp ct_iu_resp;
426 struct zfcp_port *port;
427};
428
429typedef void (*zfcp_send_els_handler_t)(unsigned long);
430
431/**
432 * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
433 * @adapter: adapter where request is sent from
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200434 * @port: port where ELS is destinated (port reference count has to be increased)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 * @d_id: destiniation id of port where request is sent to
436 * @req: scatter-gather list for request
437 * @resp: scatter-gather list for response
438 * @req_count: number of elements in request scatter-gather list
439 * @resp_count: number of elements in response scatter-gather list
440 * @handler: handler function (called for response to the request)
441 * @handler_data: data passed to handler function
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 * @completion: completion for synchronization purposes
443 * @ls_code: hex code of ELS command
444 * @status: used to pass error status to calling function
445 */
446struct zfcp_send_els {
447 struct zfcp_adapter *adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200448 struct zfcp_port *port;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200449 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 struct scatterlist *req;
451 struct scatterlist *resp;
452 unsigned int req_count;
453 unsigned int resp_count;
454 zfcp_send_els_handler_t handler;
455 unsigned long handler_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 struct completion *completion;
457 int ls_code;
458 int status;
459};
460
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461struct zfcp_qdio_queue {
Swen Schillig00bab912008-06-10 18:20:57 +0200462 struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
463 u8 first; /* index of next free bfr
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 in queue (free_count>0) */
Swen Schillig00bab912008-06-10 18:20:57 +0200465 atomic_t count; /* number of free buffers
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 in queue */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200467 spinlock_t lock; /* lock for operations on queue */
Swen Schillig00bab912008-06-10 18:20:57 +0200468 int pci_batch; /* SBALs since PCI indication
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 was last set */
470};
471
472struct zfcp_erp_action {
473 struct list_head list;
474 int action; /* requested action code */
475 struct zfcp_adapter *adapter; /* device which should be recovered */
476 struct zfcp_port *port;
477 struct zfcp_unit *unit;
478 volatile u32 status; /* recovery status */
479 u32 step; /* active step of this erp action */
480 struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
481 for this action */
482 struct timer_list timer;
483};
484
Christof Schmittc9615852008-05-06 11:00:05 +0200485struct fsf_latency_record {
486 u32 min;
487 u32 max;
488 u64 sum;
489};
490
491struct latency_cont {
492 struct fsf_latency_record channel;
493 struct fsf_latency_record fabric;
494 u64 counter;
495};
496
497struct zfcp_latencies {
498 struct latency_cont read;
499 struct latency_cont write;
500 struct latency_cont cmd;
501 spinlock_t lock;
502};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
504struct zfcp_adapter {
505 struct list_head list; /* list of adapters */
506 atomic_t refcount; /* reference count */
507 wait_queue_head_t remove_wq; /* can be used to wait for
508 refcount drop to zero */
6f71d9b2005-04-10 23:04:28 -0500509 wwn_t peer_wwnn; /* P2P peer WWNN */
510 wwn_t peer_wwpn; /* P2P peer WWPN */
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200511 u32 peer_d_id; /* P2P peer D_ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 struct ccw_device *ccw_device; /* S/390 ccw device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 u32 hydra_version; /* Hydra version */
514 u32 fsf_lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200515 u32 adapter_features; /* FCP channel features */
516 u32 connection_features; /* host connection features */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 u32 hardware_version; /* of FCP channel */
Christof Schmittc9615852008-05-06 11:00:05 +0200518 u16 timer_ticks; /* time int for a tick */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 struct list_head port_list_head; /* remote port list */
521 struct list_head port_remove_lh; /* head of ports to be
522 removed */
523 u32 ports; /* number of remote ports */
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200524 unsigned long req_no; /* unique FSF req number */
525 struct list_head *req_list; /* list of pending reqs */
526 spinlock_t req_list_lock; /* request list lock */
Swen Schillig00bab912008-06-10 18:20:57 +0200527 struct zfcp_qdio_queue req_q; /* request queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 u32 fsf_req_seq_no; /* FSF cmnd seq number */
529 wait_queue_head_t request_wq; /* can be used to wait for
530 more avaliable SBALs */
Swen Schillig00bab912008-06-10 18:20:57 +0200531 struct zfcp_qdio_queue resp_q; /* response queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 rwlock_t abort_lock; /* Protects against SCSI
533 stack abort/command
534 completion races */
Swen Schilligd26ab062008-05-19 12:17:37 +0200535 atomic_t stat_miss; /* # missing status reads*/
536 struct work_struct stat_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 atomic_t status; /* status of this adapter */
538 struct list_head erp_ready_head; /* error recovery for this
539 adapter/devices */
540 struct list_head erp_running_head;
541 rwlock_t erp_lock;
542 struct semaphore erp_ready_sem;
543 wait_queue_head_t erp_thread_wqh;
544 wait_queue_head_t erp_done_wqh;
545 struct zfcp_erp_action erp_action; /* pending error recovery */
546 atomic_t erp_counter;
547 u32 erp_total_count; /* total nr of enqueued erp
548 actions */
549 u32 erp_low_mem_count; /* nr of erp actions waiting
550 for memory */
551 struct zfcp_port *nameserver_port; /* adapter's nameserver */
Martin Peschked79a83d2008-03-27 14:22:00 +0100552 debug_info_t *rec_dbf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200553 debug_info_t *hba_dbf;
554 debug_info_t *san_dbf; /* debug feature areas */
555 debug_info_t *scsi_dbf;
Martin Peschked79a83d2008-03-27 14:22:00 +0100556 spinlock_t rec_dbf_lock;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200557 spinlock_t hba_dbf_lock;
558 spinlock_t san_dbf_lock;
559 spinlock_t scsi_dbf_lock;
Martin Peschked79a83d2008-03-27 14:22:00 +0100560 struct zfcp_rec_dbf_record rec_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200561 struct zfcp_hba_dbf_record hba_dbf_buf;
562 struct zfcp_san_dbf_record san_dbf_buf;
563 struct zfcp_scsi_dbf_record scsi_dbf_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 struct zfcp_adapter_mempool pool; /* Adapter memory pools */
565 struct qdio_initialize qdio_init_data; /* for qdio_establish */
566 struct device generic_services; /* directory for WKA ports */
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100567 struct fc_host_statistics *fc_stats;
568 struct fsf_qtcb_bottom_port *stats_reset_data;
569 unsigned long stats_reset;
Swen Schilligcc8c2822008-06-10 18:21:00 +0200570 struct work_struct scan_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571};
572
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573struct zfcp_port {
574 struct device sysfs_device; /* sysfs device */
Andreas Herrmann3859f6a2005-08-27 11:07:54 -0700575 struct fc_rport *rport; /* rport of fc transport class */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 struct list_head list; /* list of remote ports */
577 atomic_t refcount; /* reference count */
578 wait_queue_head_t remove_wq; /* can be used to wait for
579 refcount drop to zero */
580 struct zfcp_adapter *adapter; /* adapter used to access port */
581 struct list_head unit_list_head; /* head of logical unit list */
582 struct list_head unit_remove_lh; /* head of luns to be removed
583 list */
584 u32 units; /* # of logical units in list */
585 atomic_t status; /* status of this remote port */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 wwn_t wwnn; /* WWNN if known */
587 wwn_t wwpn; /* WWPN */
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200588 u32 d_id; /* D_ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 u32 handle; /* handle assigned by FSF */
590 struct zfcp_erp_action erp_action; /* pending error recovery */
591 atomic_t erp_counter;
Ralph Wuerthner75bfc282006-05-22 18:24:33 +0200592 u32 maxframe_size;
593 u32 supported_classes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594};
595
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596struct zfcp_unit {
597 struct device sysfs_device; /* sysfs device */
598 struct list_head list; /* list of logical units */
599 atomic_t refcount; /* reference count */
600 wait_queue_head_t remove_wq; /* can be used to wait for
601 refcount drop to zero */
602 struct zfcp_port *port; /* remote port of unit */
603 atomic_t status; /* status of this logical unit */
Andreas Herrmann06506d02006-05-22 18:18:19 +0200604 unsigned int scsi_lun; /* own SCSI LUN */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 fcp_lun_t fcp_lun; /* own FCP_LUN */
606 u32 handle; /* handle assigned by FSF */
607 struct scsi_device *device; /* scsi device struct pointer */
608 struct zfcp_erp_action erp_action; /* pending error recovery */
609 atomic_t erp_counter;
Christof Schmittc9615852008-05-06 11:00:05 +0200610 struct zfcp_latencies latencies;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611};
612
613/* FSF request */
614struct zfcp_fsf_req {
615 struct list_head list; /* list of FSF requests */
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200616 unsigned long req_id; /* unique request ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 struct zfcp_adapter *adapter; /* adapter request belongs to */
618 u8 sbal_number; /* nr of SBALs free for use */
619 u8 sbal_first; /* first SBAL for this request */
Martin Peschkee891bff2008-05-19 12:17:43 +0200620 u8 sbal_last; /* last SBAL for this request */
Martin Peschked01d51b2008-05-19 12:17:42 +0200621 u8 sbal_limit; /* last possible SBAL for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 this reuest */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 u8 sbale_curr; /* current SBALE during creation
624 of request */
Martin Peschkec3baa9a22008-05-19 12:17:44 +0200625 u8 sbal_response; /* SBAL used in interrupt */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 wait_queue_head_t completion_wq; /* can be used by a routine
627 to wait for completion */
628 volatile u32 status; /* status of this request */
629 u32 fsf_command; /* FSF Command copy */
630 struct fsf_qtcb *qtcb; /* address of associated QTCB */
631 u32 seq_no; /* Sequence number of request */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200632 void *data; /* private data of request */
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200633 struct timer_list timer; /* used for erp or scsi er */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 struct zfcp_erp_action *erp_action; /* used if this request is
635 issued on behalf of erp */
636 mempool_t *pool; /* used if request was alloacted
637 from emergency pool */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200638 unsigned long long issued; /* request sent time (STCK) */
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200639 struct zfcp_unit *unit;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200640 void (*handler)(struct zfcp_fsf_req *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641};
642
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643/* driver data */
644struct zfcp_data {
645 struct scsi_host_template scsi_host_template;
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200646 struct scsi_transport_template *scsi_transport_template;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 atomic_t status; /* Module status flags */
648 struct list_head adapter_list_head; /* head of adapter list */
649 struct list_head adapter_remove_lh; /* head of adapters to be
650 removed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 u32 adapters; /* # of adapters in list */
652 rwlock_t config_lock; /* serialises changes
653 to adapter/port/unit
654 lists */
655 struct semaphore config_sema; /* serialises configuration
656 changes */
657 atomic_t loglevel; /* current loglevel */
658 char init_busid[BUS_ID_SIZE];
659 wwn_t init_wwpn;
660 fcp_lun_t init_fcp_lun;
Christoph Lametere18b8902006-12-06 20:33:20 -0800661 struct kmem_cache *fsf_req_qtcb_cache;
662 struct kmem_cache *sr_buffer_cache;
663 struct kmem_cache *gid_pn_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664};
665
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666/* struct used by memory pools for fsf_requests */
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200667struct zfcp_fsf_req_qtcb {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 struct zfcp_fsf_req fsf_req;
669 struct fsf_qtcb qtcb;
670};
671
672/********************** ZFCP SPECIFIC DEFINES ********************************/
673
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674#define ZFCP_REQ_AUTO_CLEANUP 0x00000002
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675#define ZFCP_REQ_NO_QTCB 0x00000008
676
677#define ZFCP_SET 0x00000100
678#define ZFCP_CLEAR 0x00000200
679
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680#ifndef atomic_test_mask
681#define atomic_test_mask(mask, target) \
682 ((atomic_read(target) & mask) == mask)
683#endif
684
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685#define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
686#define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
687#define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
688
689/*
Heiko Carstensca2d02c2007-05-08 11:17:54 +0200690 * Helper functions for request ID management.
691 */
692static inline int zfcp_reqlist_hash(unsigned long req_id)
693{
694 return req_id % REQUEST_LIST_SIZE;
695}
696
Heiko Carstensca2d02c2007-05-08 11:17:54 +0200697static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
698 struct zfcp_fsf_req *fsf_req)
699{
700 list_del(&fsf_req->list);
701}
702
703static inline struct zfcp_fsf_req *
704zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
705{
706 struct zfcp_fsf_req *request;
707 unsigned int idx;
708
709 idx = zfcp_reqlist_hash(req_id);
710 list_for_each_entry(request, &adapter->req_list[idx], list)
711 if (request->req_id == req_id)
712 return request;
713 return NULL;
714}
715
Heiko Carstensd1ad09d2007-12-20 12:30:22 +0100716static inline struct zfcp_fsf_req *
717zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req)
718{
719 struct zfcp_fsf_req *request;
720 unsigned int idx;
721
722 for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) {
723 list_for_each_entry(request, &adapter->req_list[idx], list)
724 if (request == req)
725 return request;
726 }
727 return NULL;
728}
729
Heiko Carstensca2d02c2007-05-08 11:17:54 +0200730/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 * functions needed for reference/usage counting
732 */
733
734static inline void
735zfcp_unit_get(struct zfcp_unit *unit)
736{
737 atomic_inc(&unit->refcount);
738}
739
740static inline void
741zfcp_unit_put(struct zfcp_unit *unit)
742{
743 if (atomic_dec_return(&unit->refcount) == 0)
744 wake_up(&unit->remove_wq);
745}
746
747static inline void
748zfcp_unit_wait(struct zfcp_unit *unit)
749{
750 wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
751}
752
753static inline void
754zfcp_port_get(struct zfcp_port *port)
755{
756 atomic_inc(&port->refcount);
757}
758
759static inline void
760zfcp_port_put(struct zfcp_port *port)
761{
762 if (atomic_dec_return(&port->refcount) == 0)
763 wake_up(&port->remove_wq);
764}
765
766static inline void
767zfcp_port_wait(struct zfcp_port *port)
768{
769 wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
770}
771
772static inline void
773zfcp_adapter_get(struct zfcp_adapter *adapter)
774{
775 atomic_inc(&adapter->refcount);
776}
777
778static inline void
779zfcp_adapter_put(struct zfcp_adapter *adapter)
780{
781 if (atomic_dec_return(&adapter->refcount) == 0)
782 wake_up(&adapter->remove_wq);
783}
784
785static inline void
786zfcp_adapter_wait(struct zfcp_adapter *adapter)
787{
788 wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
789}
790
791#endif /* ZFCP_DEF_H */