blob: c1becfc1e7fe9bd4b3c057e5a3980c2c9df1d567 [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 Schmitta2fa0ae2009-03-02 13:09:08 +01006 * Copyright IBM Corporation 2002, 2009
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>
Sven Schuetz9d544f22009-04-06 18:31:47 +020025#include <scsi/fc/fc_fs.h>
26#include <scsi/fc/fc_gs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <scsi/scsi.h>
28#include <scsi/scsi_tcq.h>
29#include <scsi/scsi_cmnd.h>
30#include <scsi/scsi_device.h>
31#include <scsi/scsi_host.h>
32#include <scsi/scsi_transport.h>
33#include <scsi/scsi_transport_fc.h>
Sven Schuetz9d544f22009-04-06 18:31:47 +020034#include <scsi/scsi_bsg_fc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <asm/ccwdev.h>
36#include <asm/qdio.h>
37#include <asm/debug.h>
38#include <asm/ebcdic.h>
Christof Schmittbd43a422008-12-25 13:38:50 +010039#include <asm/sysinfo.h>
Heiko Carstensdd52e0e2006-09-18 22:28:49 +020040#include "zfcp_fsf.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Linus Torvalds1da177e2005-04-16 15:20:36 -070042/********************* GENERAL DEFINES *********************************/
43
Andreas Herrmann06506d02006-05-22 18:18:19 +020044#define REQUEST_LIST_SIZE 128
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046/********************* SCSI SPECIFIC DEFINES *********************************/
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +020047#define ZFCP_SCSI_ER_TIMEOUT (10*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49/********************* CIO/QDIO SPECIFIC DEFINES *****************************/
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051/* DMQ bug workaround: don't use last SBALE */
52#define ZFCP_MAX_SBALES_PER_SBAL (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
53
54/* index of last SBALE (with respect to DMQ bug workaround) */
55#define ZFCP_LAST_SBALE_PER_SBAL (ZFCP_MAX_SBALES_PER_SBAL - 1)
56
57/* max. number of (data buffer) SBALEs in largest SBAL chain */
58#define ZFCP_MAX_SBALES_PER_REQ \
Swen Schilligc41f8cb2008-07-02 10:56:39 +020059 (FSF_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
61
Swen Schillig8d1a0062006-10-12 11:43:44 +020062#define ZFCP_MAX_SECTORS (ZFCP_MAX_SBALES_PER_REQ * 8)
63 /* max. number of (data buffer) SBALEs in largest SBAL chain
64 multiplied with number of sectors per 4k block */
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066/********************* FSF SPECIFIC DEFINES *********************************/
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068/* ATTENTION: value must not be used by hardware */
69#define FSF_QTCB_UNSOLICITED_STATUS 0x6305
Andreas Herrmann22753fa2005-06-13 13:15:15 +020070
Linus Torvalds1da177e2005-04-16 15:20:36 -070071/* timeout value for "default timer" for fsf requests */
Andreas Herrmann2abbe862006-09-18 22:29:56 +020072#define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74/*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
75
Linus Torvalds1da177e2005-04-16 15:20:36 -070076/* timeout for name-server lookup (in seconds) */
77#define ZFCP_NS_GID_PN_TIMEOUT 10
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079/* task attribute values in FCP-2 FCP_CMND IU */
80#define SIMPLE_Q 0
81#define HEAD_OF_Q 1
82#define ORDERED_Q 2
83#define ACA_Q 4
84#define UNTAGGED 5
85
86/* task management flags in FCP-2 FCP_CMND IU */
87#define FCP_CLEAR_ACA 0x40
88#define FCP_TARGET_RESET 0x20
89#define FCP_LOGICAL_UNIT_RESET 0x10
90#define FCP_CLEAR_TASK_SET 0x04
91#define FCP_ABORT_TASK_SET 0x02
92
93#define FCP_CDB_LENGTH 16
94
95#define ZFCP_DID_MASK 0x00FFFFFF
96
97/* FCP(-2) FCP_CMND IU */
98struct fcp_cmnd_iu {
Swen Schillig7ba58c92008-10-01 12:42:18 +020099 u64 fcp_lun; /* FCP logical unit number */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 u8 crn; /* command reference number */
101 u8 reserved0:5; /* reserved */
102 u8 task_attribute:3; /* task attribute */
103 u8 task_management_flags; /* task management flags */
104 u8 add_fcp_cdb_length:6; /* additional FCP_CDB length */
105 u8 rddata:1; /* read data */
106 u8 wddata:1; /* write data */
107 u8 fcp_cdb[FCP_CDB_LENGTH];
108} __attribute__((packed));
109
110/* FCP(-2) FCP_RSP IU */
111struct fcp_rsp_iu {
112 u8 reserved0[10];
113 union {
114 struct {
115 u8 reserved1:3;
116 u8 fcp_conf_req:1;
117 u8 fcp_resid_under:1;
118 u8 fcp_resid_over:1;
119 u8 fcp_sns_len_valid:1;
120 u8 fcp_rsp_len_valid:1;
121 } bits;
122 u8 value;
123 } validity;
124 u8 scsi_status;
125 u32 fcp_resid;
126 u32 fcp_sns_len;
127 u32 fcp_rsp_len;
128} __attribute__((packed));
129
130
131#define RSP_CODE_GOOD 0
132#define RSP_CODE_LENGTH_MISMATCH 1
133#define RSP_CODE_FIELD_INVALID 2
134#define RSP_CODE_RO_MISMATCH 3
135#define RSP_CODE_TASKMAN_UNSUPP 4
136#define RSP_CODE_TASKMAN_FAILED 5
137
138/* see fc-fs */
Christof Schmitt24073b42008-06-10 18:20:54 +0200139#define LS_RSCN 0x61
140#define LS_LOGO 0x05
141#define LS_PLOGI 0x03
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143struct fcp_rscn_head {
144 u8 command;
145 u8 page_length; /* always 0x04 */
146 u16 payload_len;
147} __attribute__((packed));
148
149struct fcp_rscn_element {
150 u8 reserved:2;
151 u8 event_qual:4;
152 u8 addr_format:2;
153 u32 nport_did:24;
154} __attribute__((packed));
155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156/* see fc-ph */
157struct fcp_logo {
158 u32 command;
159 u32 nport_did;
Swen Schillig7ba58c92008-10-01 12:42:18 +0200160 u64 nport_wwpn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161} __attribute__((packed));
162
163/*
164 * FC-FS stuff
165 */
166#define R_A_TOV 10 /* seconds */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168#define ZFCP_LS_RLS 0x0f
169#define ZFCP_LS_ADISC 0x52
170#define ZFCP_LS_RPS 0x56
171#define ZFCP_LS_RSCN 0x61
172#define ZFCP_LS_RNID 0x78
173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174struct zfcp_ls_adisc {
175 u8 code;
176 u8 field[3];
177 u32 hard_nport_id;
178 u64 wwpn;
179 u64 wwnn;
180 u32 nport_id;
181} __attribute__ ((packed));
182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183/*
184 * FC-GS-2 stuff
185 */
186#define ZFCP_CT_REVISION 0x01
187#define ZFCP_CT_DIRECTORY_SERVICE 0xFC
188#define ZFCP_CT_NAME_SERVER 0x02
189#define ZFCP_CT_SYNCHRONOUS 0x00
Swen Schilligcc8c2822008-06-10 18:21:00 +0200190#define ZFCP_CT_SCSI_FCP 0x08
191#define ZFCP_CT_UNABLE_TO_PERFORM_CMD 0x09
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192#define ZFCP_CT_GID_PN 0x0121
Swen Schilligcc8c2822008-06-10 18:21:00 +0200193#define ZFCP_CT_GPN_FT 0x0172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194#define ZFCP_CT_ACCEPT 0x8002
195#define ZFCP_CT_REJECT 0x8001
196
197/*
198 * FC-GS-4 stuff
199 */
200#define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202/*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
203
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200204/*
205 * Note, the leftmost status byte is common among adapter, port
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 * and unit
207 */
208#define ZFCP_COMMON_FLAGS 0xfff00000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210/* common status bits */
211#define ZFCP_STATUS_COMMON_REMOVE 0x80000000
212#define ZFCP_STATUS_COMMON_RUNNING 0x40000000
213#define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
214#define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215#define ZFCP_STATUS_COMMON_OPEN 0x04000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216#define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
217#define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
Andreas Herrmannd736a272005-06-13 13:23:57 +0200218#define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
Swen Schilligcc8c2822008-06-10 18:21:00 +0200219#define ZFCP_STATUS_COMMON_NOESC 0x00200000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221/* adapter status */
222#define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223#define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
224#define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
225#define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
226#define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
227#define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
228#define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230/* FC-PH/FC-GS well-known address identifiers for generic services */
Swen Schillig5ab944f2008-10-01 12:42:17 +0200231#define ZFCP_DID_WKA 0xFFFFF0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
233/* remote port status */
234#define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
Christof Schmitt14e242e2009-08-18 15:43:11 +0200235#define ZFCP_STATUS_PORT_LINK_TEST 0x00000002
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
Swen Schillig5ab944f2008-10-01 12:42:17 +0200237/* well known address (WKA) port status*/
238enum zfcp_wka_status {
239 ZFCP_WKA_PORT_OFFLINE,
240 ZFCP_WKA_PORT_CLOSING,
241 ZFCP_WKA_PORT_OPENING,
242 ZFCP_WKA_PORT_ONLINE,
243};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
245/* logical unit status */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246#define ZFCP_STATUS_UNIT_SHARED 0x00000004
247#define ZFCP_STATUS_UNIT_READONLY 0x00000008
248
249/* FSF request status (this does not have a common part) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250#define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
251#define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
252#define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
253#define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254#define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
255#define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
256#define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
257#define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
258#define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
259#define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
260#define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262/************************* STRUCTURE DEFINITIONS *****************************/
263
264struct zfcp_fsf_req;
265
266/* holds various memory pools of an adapter */
267struct zfcp_adapter_mempool {
268 mempool_t *fsf_req_erp;
269 mempool_t *fsf_req_scsi;
270 mempool_t *fsf_req_abort;
271 mempool_t *fsf_req_status_read;
272 mempool_t *data_status_read;
273 mempool_t *data_gid_pn;
274};
275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276/*
277 * header for CT_IU
278 */
279struct ct_hdr {
280 u8 revision; // 0x01
281 u8 in_id[3]; // 0x00
282 u8 gs_type; // 0xFC Directory Service
283 u8 gs_subtype; // 0x02 Name Server
284 u8 options; // 0x00 single bidirectional exchange
285 u8 reserved0;
286 u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT
287 u16 max_res_size; // <= (4096 - 16) / 4
288 u8 reserved1;
289 u8 reason_code;
290 u8 reason_code_expl;
291 u8 vendor_unique;
292} __attribute__ ((packed));
293
294/* nameserver request CT_IU -- for requests where
295 * a port name is required */
296struct ct_iu_gid_pn_req {
297 struct ct_hdr header;
Swen Schillig7ba58c92008-10-01 12:42:18 +0200298 u64 wwpn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299} __attribute__ ((packed));
300
301/* FS_ACC IU and data unit for GID_PN nameserver request */
302struct ct_iu_gid_pn_resp {
303 struct ct_hdr header;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200304 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305} __attribute__ ((packed));
306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307/**
308 * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
Swen Schillig5ab944f2008-10-01 12:42:17 +0200309 * @wka_port: port where the request is sent to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 * @req: scatter-gather list for request
311 * @resp: scatter-gather list for response
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 * @handler: handler function (called for response to the request)
313 * @handler_data: data passed to handler function
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 * @timeout: FSF timeout for this request
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 * @completion: completion for synchronization purposes
316 * @status: used to pass error status to calling function
317 */
318struct zfcp_send_ct {
Swen Schillig5ab944f2008-10-01 12:42:17 +0200319 struct zfcp_wka_port *wka_port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 struct scatterlist *req;
321 struct scatterlist *resp;
Swen Schillig7ba58c92008-10-01 12:42:18 +0200322 void (*handler)(unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 unsigned long handler_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 int timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 struct completion *completion;
326 int status;
327};
328
329/* used for name server requests in error recovery */
330struct zfcp_gid_pn_data {
331 struct zfcp_send_ct ct;
332 struct scatterlist req;
333 struct scatterlist resp;
334 struct ct_iu_gid_pn_req ct_iu_req;
335 struct ct_iu_gid_pn_resp ct_iu_resp;
336 struct zfcp_port *port;
337};
338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339/**
340 * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
341 * @adapter: adapter where request is sent from
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200342 * @port: port where ELS is destinated (port reference count has to be increased)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 * @d_id: destiniation id of port where request is sent to
344 * @req: scatter-gather list for request
345 * @resp: scatter-gather list for response
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 * @handler: handler function (called for response to the request)
347 * @handler_data: data passed to handler function
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 * @completion: completion for synchronization purposes
349 * @ls_code: hex code of ELS command
350 * @status: used to pass error status to calling function
351 */
352struct zfcp_send_els {
353 struct zfcp_adapter *adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200354 struct zfcp_port *port;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200355 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 struct scatterlist *req;
357 struct scatterlist *resp;
Swen Schillig7ba58c92008-10-01 12:42:18 +0200358 void (*handler)(unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 unsigned long handler_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 struct completion *completion;
361 int ls_code;
362 int status;
363};
364
Swen Schillig5ab944f2008-10-01 12:42:17 +0200365struct zfcp_wka_port {
366 struct zfcp_adapter *adapter;
367 wait_queue_head_t completion_wq;
368 enum zfcp_wka_status status;
369 atomic_t refcount;
370 u32 d_id;
371 u32 handle;
372 struct mutex mutex;
373 struct delayed_work work;
374};
375
Sven Schuetz9d544f22009-04-06 18:31:47 +0200376struct zfcp_wka_ports {
377 struct zfcp_wka_port ms; /* management service */
378 struct zfcp_wka_port ts; /* time service */
379 struct zfcp_wka_port ds; /* directory service */
380 struct zfcp_wka_port as; /* alias service */
381 struct zfcp_wka_port ks; /* key distribution service */
382};
383
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384struct zfcp_qdio_queue {
Christof Schmitt04062892008-10-01 12:42:20 +0200385 struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q];
386 u8 first; /* index of next free bfr in queue */
387 atomic_t count; /* number of free buffers in queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388};
389
390struct zfcp_erp_action {
391 struct list_head list;
392 int action; /* requested action code */
393 struct zfcp_adapter *adapter; /* device which should be recovered */
394 struct zfcp_port *port;
395 struct zfcp_unit *unit;
Swen Schillig44cc76f2008-10-01 12:42:16 +0200396 u32 status; /* recovery status */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 u32 step; /* active step of this erp action */
398 struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
399 for this action */
400 struct timer_list timer;
401};
402
Christof Schmittc9615852008-05-06 11:00:05 +0200403struct fsf_latency_record {
404 u32 min;
405 u32 max;
406 u64 sum;
407};
408
409struct latency_cont {
410 struct fsf_latency_record channel;
411 struct fsf_latency_record fabric;
412 u64 counter;
413};
414
415struct zfcp_latencies {
416 struct latency_cont read;
417 struct latency_cont write;
418 struct latency_cont cmd;
419 spinlock_t lock;
420};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
422struct zfcp_adapter {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 atomic_t refcount; /* reference count */
424 wait_queue_head_t remove_wq; /* can be used to wait for
425 refcount drop to zero */
Swen Schillig7ba58c92008-10-01 12:42:18 +0200426 u64 peer_wwnn; /* P2P peer WWNN */
427 u64 peer_wwpn; /* P2P peer WWPN */
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200428 u32 peer_d_id; /* P2P peer D_ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 struct ccw_device *ccw_device; /* S/390 ccw device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 u32 hydra_version; /* Hydra version */
431 u32 fsf_lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200432 u32 adapter_features; /* FCP channel features */
433 u32 connection_features; /* host connection features */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 u32 hardware_version; /* of FCP channel */
Christof Schmittc9615852008-05-06 11:00:05 +0200435 u16 timer_ticks; /* time int for a tick */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 struct list_head port_list_head; /* remote port list */
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200438 unsigned long req_no; /* unique FSF req number */
439 struct list_head *req_list; /* list of pending reqs */
440 spinlock_t req_list_lock; /* request list lock */
Swen Schillig00bab912008-06-10 18:20:57 +0200441 struct zfcp_qdio_queue req_q; /* request queue */
Christof Schmitt04062892008-10-01 12:42:20 +0200442 spinlock_t req_q_lock; /* for operations on queue */
Martin Peschke94506fd2009-03-02 13:08:56 +0100443 ktime_t req_q_time; /* time of last fill level change */
444 u64 req_q_util; /* for accounting */
445 spinlock_t qdio_stat_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 u32 fsf_req_seq_no; /* FSF cmnd seq number */
447 wait_queue_head_t request_wq; /* can be used to wait for
448 more avaliable SBALs */
Swen Schillig00bab912008-06-10 18:20:57 +0200449 struct zfcp_qdio_queue resp_q; /* response queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 rwlock_t abort_lock; /* Protects against SCSI
451 stack abort/command
452 completion races */
Swen Schilligd26ab062008-05-19 12:17:37 +0200453 atomic_t stat_miss; /* # missing status reads*/
454 struct work_struct stat_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 atomic_t status; /* status of this adapter */
456 struct list_head erp_ready_head; /* error recovery for this
457 adapter/devices */
458 struct list_head erp_running_head;
459 rwlock_t erp_lock;
460 struct semaphore erp_ready_sem;
461 wait_queue_head_t erp_thread_wqh;
462 wait_queue_head_t erp_done_wqh;
463 struct zfcp_erp_action erp_action; /* pending error recovery */
464 atomic_t erp_counter;
465 u32 erp_total_count; /* total nr of enqueued erp
466 actions */
467 u32 erp_low_mem_count; /* nr of erp actions waiting
468 for memory */
Sven Schuetz9d544f22009-04-06 18:31:47 +0200469 struct zfcp_wka_ports *gs; /* generic services */
Christof Schmittd46f3842009-08-18 15:43:07 +0200470 struct zfcp_dbf *dbf; /* debug traces */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 struct zfcp_adapter_mempool pool; /* Adapter memory pools */
472 struct qdio_initialize qdio_init_data; /* for qdio_establish */
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100473 struct fc_host_statistics *fc_stats;
474 struct fsf_qtcb_bottom_port *stats_reset_data;
475 unsigned long stats_reset;
Swen Schilligcc8c2822008-06-10 18:21:00 +0200476 struct work_struct scan_work;
Christof Schmittbd43a422008-12-25 13:38:50 +0100477 struct service_level service_level;
Stefan Raspl2450d3e2008-10-01 12:42:14 +0200478 atomic_t qdio_outb_full; /* queue full incidents */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479};
480
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481struct zfcp_port {
482 struct device sysfs_device; /* sysfs device */
Andreas Herrmann3859f6a2005-08-27 11:07:54 -0700483 struct fc_rport *rport; /* rport of fc transport class */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 struct list_head list; /* list of remote ports */
485 atomic_t refcount; /* reference count */
486 wait_queue_head_t remove_wq; /* can be used to wait for
487 refcount drop to zero */
488 struct zfcp_adapter *adapter; /* adapter used to access port */
489 struct list_head unit_list_head; /* head of logical unit list */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 atomic_t status; /* status of this remote port */
Swen Schillig7ba58c92008-10-01 12:42:18 +0200491 u64 wwnn; /* WWNN if known */
492 u64 wwpn; /* WWPN */
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200493 u32 d_id; /* D_ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 u32 handle; /* handle assigned by FSF */
495 struct zfcp_erp_action erp_action; /* pending error recovery */
496 atomic_t erp_counter;
Ralph Wuerthner75bfc282006-05-22 18:24:33 +0200497 u32 maxframe_size;
498 u32 supported_classes;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200499 struct work_struct gid_pn_work;
Christof Schmitt8fdf30d2009-03-02 13:09:01 +0100500 struct work_struct test_link_work;
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100501 struct work_struct rport_work;
502 enum { RPORT_NONE, RPORT_ADD, RPORT_DEL } rport_task;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503};
504
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505struct zfcp_unit {
506 struct device sysfs_device; /* sysfs device */
507 struct list_head list; /* list of logical units */
508 atomic_t refcount; /* reference count */
509 wait_queue_head_t remove_wq; /* can be used to wait for
510 refcount drop to zero */
511 struct zfcp_port *port; /* remote port of unit */
512 atomic_t status; /* status of this logical unit */
Swen Schillig7ba58c92008-10-01 12:42:18 +0200513 u64 fcp_lun; /* own FCP_LUN */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 u32 handle; /* handle assigned by FSF */
515 struct scsi_device *device; /* scsi device struct pointer */
516 struct zfcp_erp_action erp_action; /* pending error recovery */
517 atomic_t erp_counter;
Christof Schmittc9615852008-05-06 11:00:05 +0200518 struct zfcp_latencies latencies;
Swen Schillig92d51932009-04-17 15:08:04 +0200519 struct work_struct scsi_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520};
521
522/* FSF request */
523struct zfcp_fsf_req {
524 struct list_head list; /* list of FSF requests */
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200525 unsigned long req_id; /* unique request ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 struct zfcp_adapter *adapter; /* adapter request belongs to */
527 u8 sbal_number; /* nr of SBALs free for use */
528 u8 sbal_first; /* first SBAL for this request */
Martin Peschkee891bff2008-05-19 12:17:43 +0200529 u8 sbal_last; /* last SBAL for this request */
Martin Peschked01d51b2008-05-19 12:17:42 +0200530 u8 sbal_limit; /* last possible SBAL for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 this reuest */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 u8 sbale_curr; /* current SBALE during creation
533 of request */
Martin Peschkec3baa9a22008-05-19 12:17:44 +0200534 u8 sbal_response; /* SBAL used in interrupt */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 wait_queue_head_t completion_wq; /* can be used by a routine
536 to wait for completion */
Swen Schillig44cc76f2008-10-01 12:42:16 +0200537 u32 status; /* status of this request */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 u32 fsf_command; /* FSF Command copy */
539 struct fsf_qtcb *qtcb; /* address of associated QTCB */
540 u32 seq_no; /* Sequence number of request */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200541 void *data; /* private data of request */
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200542 struct timer_list timer; /* used for erp or scsi er */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 struct zfcp_erp_action *erp_action; /* used if this request is
544 issued on behalf of erp */
545 mempool_t *pool; /* used if request was alloacted
546 from emergency pool */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200547 unsigned long long issued; /* request sent time (STCK) */
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200548 struct zfcp_unit *unit;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200549 void (*handler)(struct zfcp_fsf_req *);
Stefan Raspl0997f1c2008-10-16 08:23:39 +0200550 u16 qdio_outb_usage;/* usage of outbound queue */
551 u16 qdio_inb_usage; /* usage of inbound queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552};
553
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554/* driver data */
555struct zfcp_data {
556 struct scsi_host_template scsi_host_template;
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200557 struct scsi_transport_template *scsi_transport_template;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 rwlock_t config_lock; /* serialises changes
559 to adapter/port/unit
560 lists */
561 struct semaphore config_sema; /* serialises configuration
562 changes */
Swen Schillig7ba58c92008-10-01 12:42:18 +0200563 struct kmem_cache *fsf_req_qtcb_cache;
564 struct kmem_cache *sr_buffer_cache;
565 struct kmem_cache *gid_pn_cache;
Swen Schilligb7f15f32008-10-01 12:42:22 +0200566 struct workqueue_struct *work_queue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567};
568
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569/* struct used by memory pools for fsf_requests */
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200570struct zfcp_fsf_req_qtcb {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 struct zfcp_fsf_req fsf_req;
572 struct fsf_qtcb qtcb;
573};
574
575/********************** ZFCP SPECIFIC DEFINES ********************************/
576
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577#define ZFCP_SET 0x00000100
578#define ZFCP_CLEAR 0x00000200
579
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580/*
Heiko Carstensca2d02c2007-05-08 11:17:54 +0200581 * Helper functions for request ID management.
582 */
583static inline int zfcp_reqlist_hash(unsigned long req_id)
584{
585 return req_id % REQUEST_LIST_SIZE;
586}
587
Heiko Carstensca2d02c2007-05-08 11:17:54 +0200588static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
589 struct zfcp_fsf_req *fsf_req)
590{
591 list_del(&fsf_req->list);
592}
593
594static inline struct zfcp_fsf_req *
595zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
596{
597 struct zfcp_fsf_req *request;
598 unsigned int idx;
599
600 idx = zfcp_reqlist_hash(req_id);
601 list_for_each_entry(request, &adapter->req_list[idx], list)
602 if (request->req_id == req_id)
603 return request;
604 return NULL;
605}
606
Heiko Carstensd1ad09d2007-12-20 12:30:22 +0100607static inline struct zfcp_fsf_req *
608zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req)
609{
610 struct zfcp_fsf_req *request;
611 unsigned int idx;
612
613 for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) {
614 list_for_each_entry(request, &adapter->req_list[idx], list)
615 if (request == req)
616 return request;
617 }
618 return NULL;
619}
620
Heiko Carstensca2d02c2007-05-08 11:17:54 +0200621/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 * functions needed for reference/usage counting
623 */
624
625static inline void
626zfcp_unit_get(struct zfcp_unit *unit)
627{
628 atomic_inc(&unit->refcount);
629}
630
631static inline void
632zfcp_unit_put(struct zfcp_unit *unit)
633{
634 if (atomic_dec_return(&unit->refcount) == 0)
635 wake_up(&unit->remove_wq);
636}
637
638static inline void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639zfcp_port_get(struct zfcp_port *port)
640{
641 atomic_inc(&port->refcount);
642}
643
644static inline void
645zfcp_port_put(struct zfcp_port *port)
646{
647 if (atomic_dec_return(&port->refcount) == 0)
648 wake_up(&port->remove_wq);
649}
650
651static inline void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652zfcp_adapter_get(struct zfcp_adapter *adapter)
653{
654 atomic_inc(&adapter->refcount);
655}
656
657static inline void
658zfcp_adapter_put(struct zfcp_adapter *adapter)
659{
660 if (atomic_dec_return(&adapter->refcount) == 0)
661 wake_up(&adapter->remove_wq);
662}
663
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664#endif /* ZFCP_DEF_H */