Commit | Line | Data |
---|---|---|
41fa2ada | 1 | /* |
4a9d2d8b AH |
2 | * This file is part of the zfcp device driver for |
3 | * FCP adapters for IBM System z9 and zSeries. | |
1da177e4 | 4 | * |
4a9d2d8b | 5 | * (C) Copyright IBM Corp. 2002, 2006 |
41fa2ada SS |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2, or (at your option) | |
10 | * any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program; if not, write to the Free Software | |
19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
20 | */ | |
1da177e4 | 21 | |
1da177e4 LT |
22 | #ifndef ZFCP_DEF_H |
23 | #define ZFCP_DEF_H | |
24 | ||
1da177e4 LT |
25 | /*************************** INCLUDES *****************************************/ |
26 | ||
27 | #include <linux/init.h> | |
28 | #include <linux/moduleparam.h> | |
29 | #include <linux/miscdevice.h> | |
30 | #include <linux/major.h> | |
31 | #include <linux/blkdev.h> | |
32 | #include <linux/delay.h> | |
33 | #include <linux/timer.h> | |
dd52e0ea HC |
34 | #include <linux/slab.h> |
35 | #include <linux/mempool.h> | |
36 | #include <linux/syscalls.h> | |
f1346372 | 37 | #include <linux/scatterlist.h> |
dd52e0ea | 38 | #include <linux/ioctl.h> |
1da177e4 LT |
39 | #include <scsi/scsi.h> |
40 | #include <scsi/scsi_tcq.h> | |
41 | #include <scsi/scsi_cmnd.h> | |
42 | #include <scsi/scsi_device.h> | |
43 | #include <scsi/scsi_host.h> | |
44 | #include <scsi/scsi_transport.h> | |
45 | #include <scsi/scsi_transport_fc.h> | |
1da177e4 LT |
46 | #include <asm/ccwdev.h> |
47 | #include <asm/qdio.h> | |
48 | #include <asm/debug.h> | |
49 | #include <asm/ebcdic.h> | |
dd52e0ea | 50 | #include "zfcp_fsf.h" |
1da177e4 | 51 | |
1da177e4 LT |
52 | |
53 | /********************* GENERAL DEFINES *********************************/ | |
54 | ||
55 | /* zfcp version number, it consists of major, minor, and patch-level number */ | |
58b3ac07 | 56 | #define ZFCP_VERSION "4.8.0" |
1da177e4 LT |
57 | |
58 | /** | |
59 | * zfcp_sg_to_address - determine kernel address from struct scatterlist | |
60 | * @list: struct scatterlist | |
61 | * Return: kernel address | |
62 | */ | |
63 | static inline void * | |
64 | zfcp_sg_to_address(struct scatterlist *list) | |
65 | { | |
73fc4f0d | 66 | return sg_virt(list); |
1da177e4 LT |
67 | } |
68 | ||
69 | /** | |
70 | * zfcp_address_to_sg - set up struct scatterlist from kernel address | |
71 | * @address: kernel address | |
72 | * @list: struct scatterlist | |
93354329 | 73 | * @size: buffer size |
1da177e4 LT |
74 | */ |
75 | static inline void | |
93354329 | 76 | zfcp_address_to_sg(void *address, struct scatterlist *list, unsigned int size) |
1da177e4 | 77 | { |
93354329 | 78 | sg_set_buf(list, address, size); |
1da177e4 LT |
79 | } |
80 | ||
06506d00 | 81 | #define REQUEST_LIST_SIZE 128 |
1da177e4 | 82 | |
06506d00 | 83 | /********************* SCSI SPECIFIC DEFINES *********************************/ |
f6c0e7a7 | 84 | #define ZFCP_SCSI_ER_TIMEOUT (10*HZ) |
1da177e4 LT |
85 | |
86 | /********************* CIO/QDIO SPECIFIC DEFINES *****************************/ | |
87 | ||
88 | /* Adapter Identification Parameters */ | |
89 | #define ZFCP_CONTROL_UNIT_TYPE 0x1731 | |
90 | #define ZFCP_CONTROL_UNIT_MODEL 0x03 | |
91 | #define ZFCP_DEVICE_TYPE 0x1732 | |
92 | #define ZFCP_DEVICE_MODEL 0x03 | |
93 | #define ZFCP_DEVICE_MODEL_PRIV 0x04 | |
41fa2ada | 94 | |
1da177e4 LT |
95 | /* allow as many chained SBALs as are supported by hardware */ |
96 | #define ZFCP_MAX_SBALS_PER_REQ FSF_MAX_SBALS_PER_REQ | |
97 | #define ZFCP_MAX_SBALS_PER_CT_REQ FSF_MAX_SBALS_PER_REQ | |
98 | #define ZFCP_MAX_SBALS_PER_ELS_REQ FSF_MAX_SBALS_PER_ELS_REQ | |
99 | ||
100 | /* DMQ bug workaround: don't use last SBALE */ | |
101 | #define ZFCP_MAX_SBALES_PER_SBAL (QDIO_MAX_ELEMENTS_PER_BUFFER - 1) | |
102 | ||
103 | /* index of last SBALE (with respect to DMQ bug workaround) */ | |
104 | #define ZFCP_LAST_SBALE_PER_SBAL (ZFCP_MAX_SBALES_PER_SBAL - 1) | |
105 | ||
106 | /* max. number of (data buffer) SBALEs in largest SBAL chain */ | |
107 | #define ZFCP_MAX_SBALES_PER_REQ \ | |
108 | (ZFCP_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2) | |
109 | /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */ | |
110 | ||
8d1a0060 SS |
111 | #define ZFCP_MAX_SECTORS (ZFCP_MAX_SBALES_PER_REQ * 8) |
112 | /* max. number of (data buffer) SBALEs in largest SBAL chain | |
113 | multiplied with number of sectors per 4k block */ | |
114 | ||
1da177e4 LT |
115 | /* FIXME(tune): free space should be one max. SBAL chain plus what? */ |
116 | #define ZFCP_QDIO_PCI_INTERVAL (QDIO_MAX_BUFFERS_PER_Q \ | |
117 | - (ZFCP_MAX_SBALS_PER_REQ + 4)) | |
118 | ||
119 | #define ZFCP_SBAL_TIMEOUT (5*HZ) | |
120 | ||
18edcdbd | 121 | #define ZFCP_TYPE2_RECOVERY_TIME 8 /* seconds */ |
1da177e4 LT |
122 | |
123 | /* queue polling (values in microseconds) */ | |
124 | #define ZFCP_MAX_INPUT_THRESHOLD 5000 /* FIXME: tune */ | |
125 | #define ZFCP_MAX_OUTPUT_THRESHOLD 1000 /* FIXME: tune */ | |
126 | #define ZFCP_MIN_INPUT_THRESHOLD 1 /* ignored by QDIO layer */ | |
127 | #define ZFCP_MIN_OUTPUT_THRESHOLD 1 /* ignored by QDIO layer */ | |
128 | ||
129 | #define QDIO_SCSI_QFMT 1 /* 1 for FSF */ | |
b4e44590 | 130 | #define QBUFF_PER_PAGE (PAGE_SIZE / sizeof(struct qdio_buffer)) |
1da177e4 LT |
131 | |
132 | /********************* FSF SPECIFIC DEFINES *********************************/ | |
133 | ||
134 | #define ZFCP_ULP_INFO_VERSION 26 | |
135 | #define ZFCP_QTCB_VERSION FSF_QTCB_CURRENT_VERSION | |
136 | /* ATTENTION: value must not be used by hardware */ | |
137 | #define FSF_QTCB_UNSOLICITED_STATUS 0x6305 | |
138 | #define ZFCP_STATUS_READ_FAILED_THRESHOLD 3 | |
139 | #define ZFCP_STATUS_READS_RECOM FSF_STATUS_READS_RECOM | |
22753fa5 AH |
140 | |
141 | /* Do 1st retry in 1 second, then double the timeout for each following retry */ | |
18edcdbd | 142 | #define ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP 1 |
22753fa5 | 143 | #define ZFCP_EXCHANGE_CONFIG_DATA_RETRIES 7 |
1da177e4 LT |
144 | |
145 | /* timeout value for "default timer" for fsf requests */ | |
2abbe866 | 146 | #define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ) |
1da177e4 LT |
147 | |
148 | /*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/ | |
149 | ||
150 | typedef unsigned long long wwn_t; | |
1da177e4 LT |
151 | typedef unsigned long long fcp_lun_t; |
152 | /* data length field may be at variable position in FCP-2 FCP_CMND IU */ | |
153 | typedef unsigned int fcp_dl_t; | |
154 | ||
155 | #define ZFCP_FC_SERVICE_CLASS_DEFAULT FSF_CLASS_3 | |
156 | ||
157 | /* timeout for name-server lookup (in seconds) */ | |
158 | #define ZFCP_NS_GID_PN_TIMEOUT 10 | |
159 | ||
160 | /* largest SCSI command we can process */ | |
161 | /* FCP-2 (FCP_CMND IU) allows up to (255-3+16) */ | |
162 | #define ZFCP_MAX_SCSI_CMND_LENGTH 255 | |
163 | /* maximum number of commands in LUN queue (tagged queueing) */ | |
164 | #define ZFCP_CMND_PER_LUN 32 | |
165 | ||
166 | /* task attribute values in FCP-2 FCP_CMND IU */ | |
167 | #define SIMPLE_Q 0 | |
168 | #define HEAD_OF_Q 1 | |
169 | #define ORDERED_Q 2 | |
170 | #define ACA_Q 4 | |
171 | #define UNTAGGED 5 | |
172 | ||
173 | /* task management flags in FCP-2 FCP_CMND IU */ | |
174 | #define FCP_CLEAR_ACA 0x40 | |
175 | #define FCP_TARGET_RESET 0x20 | |
176 | #define FCP_LOGICAL_UNIT_RESET 0x10 | |
177 | #define FCP_CLEAR_TASK_SET 0x04 | |
178 | #define FCP_ABORT_TASK_SET 0x02 | |
179 | ||
180 | #define FCP_CDB_LENGTH 16 | |
181 | ||
182 | #define ZFCP_DID_MASK 0x00FFFFFF | |
183 | ||
184 | /* FCP(-2) FCP_CMND IU */ | |
185 | struct fcp_cmnd_iu { | |
186 | fcp_lun_t fcp_lun; /* FCP logical unit number */ | |
187 | u8 crn; /* command reference number */ | |
188 | u8 reserved0:5; /* reserved */ | |
189 | u8 task_attribute:3; /* task attribute */ | |
190 | u8 task_management_flags; /* task management flags */ | |
191 | u8 add_fcp_cdb_length:6; /* additional FCP_CDB length */ | |
192 | u8 rddata:1; /* read data */ | |
193 | u8 wddata:1; /* write data */ | |
194 | u8 fcp_cdb[FCP_CDB_LENGTH]; | |
195 | } __attribute__((packed)); | |
196 | ||
197 | /* FCP(-2) FCP_RSP IU */ | |
198 | struct fcp_rsp_iu { | |
199 | u8 reserved0[10]; | |
200 | union { | |
201 | struct { | |
202 | u8 reserved1:3; | |
203 | u8 fcp_conf_req:1; | |
204 | u8 fcp_resid_under:1; | |
205 | u8 fcp_resid_over:1; | |
206 | u8 fcp_sns_len_valid:1; | |
207 | u8 fcp_rsp_len_valid:1; | |
208 | } bits; | |
209 | u8 value; | |
210 | } validity; | |
211 | u8 scsi_status; | |
212 | u32 fcp_resid; | |
213 | u32 fcp_sns_len; | |
214 | u32 fcp_rsp_len; | |
215 | } __attribute__((packed)); | |
216 | ||
217 | ||
218 | #define RSP_CODE_GOOD 0 | |
219 | #define RSP_CODE_LENGTH_MISMATCH 1 | |
220 | #define RSP_CODE_FIELD_INVALID 2 | |
221 | #define RSP_CODE_RO_MISMATCH 3 | |
222 | #define RSP_CODE_TASKMAN_UNSUPP 4 | |
223 | #define RSP_CODE_TASKMAN_FAILED 5 | |
224 | ||
225 | /* see fc-fs */ | |
06506d00 AH |
226 | #define LS_RSCN 0x61040000 |
227 | #define LS_LOGO 0x05000000 | |
228 | #define LS_PLOGI 0x03000000 | |
1da177e4 LT |
229 | |
230 | struct fcp_rscn_head { | |
231 | u8 command; | |
232 | u8 page_length; /* always 0x04 */ | |
233 | u16 payload_len; | |
234 | } __attribute__((packed)); | |
235 | ||
236 | struct fcp_rscn_element { | |
237 | u8 reserved:2; | |
238 | u8 event_qual:4; | |
239 | u8 addr_format:2; | |
240 | u32 nport_did:24; | |
241 | } __attribute__((packed)); | |
242 | ||
243 | #define ZFCP_PORT_ADDRESS 0x0 | |
244 | #define ZFCP_AREA_ADDRESS 0x1 | |
245 | #define ZFCP_DOMAIN_ADDRESS 0x2 | |
246 | #define ZFCP_FABRIC_ADDRESS 0x3 | |
247 | ||
248 | #define ZFCP_PORTS_RANGE_PORT 0xFFFFFF | |
249 | #define ZFCP_PORTS_RANGE_AREA 0xFFFF00 | |
250 | #define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000 | |
251 | #define ZFCP_PORTS_RANGE_FABRIC 0x000000 | |
252 | ||
253 | #define ZFCP_NO_PORTS_PER_AREA 0x100 | |
254 | #define ZFCP_NO_PORTS_PER_DOMAIN 0x10000 | |
255 | #define ZFCP_NO_PORTS_PER_FABRIC 0x1000000 | |
256 | ||
1da177e4 LT |
257 | /* see fc-ph */ |
258 | struct fcp_logo { | |
259 | u32 command; | |
260 | u32 nport_did; | |
261 | wwn_t nport_wwpn; | |
262 | } __attribute__((packed)); | |
263 | ||
8a36e453 MS |
264 | /* |
265 | * DBF stuff | |
266 | */ | |
267 | #define ZFCP_DBF_TAG_SIZE 4 | |
268 | ||
269 | struct zfcp_dbf_dump { | |
270 | u8 tag[ZFCP_DBF_TAG_SIZE]; | |
271 | u32 total_size; /* size of total dump data */ | |
272 | u32 offset; /* how much data has being already dumped */ | |
273 | u32 size; /* how much data comes with this record */ | |
274 | u8 data[]; /* dump data */ | |
275 | } __attribute__ ((packed)); | |
276 | ||
277 | /* FIXME: to be inflated when reworking the erp dbf */ | |
278 | struct zfcp_erp_dbf_record { | |
279 | u8 dummy[16]; | |
280 | } __attribute__ ((packed)); | |
281 | ||
348447e8 MP |
282 | struct zfcp_rec_dbf_record_thread { |
283 | u32 sema; | |
284 | u32 total; | |
285 | u32 ready; | |
286 | u32 running; | |
287 | } __attribute__ ((packed)); | |
288 | ||
698ec016 MP |
289 | struct zfcp_rec_dbf_record_target { |
290 | u64 ref; | |
291 | u32 status; | |
292 | u32 d_id; | |
293 | u64 wwpn; | |
294 | u64 fcp_lun; | |
295 | u32 erp_count; | |
296 | } __attribute__ ((packed)); | |
297 | ||
9467a9b3 MP |
298 | struct zfcp_rec_dbf_record_trigger { |
299 | u8 want; | |
300 | u8 need; | |
301 | u32 as; | |
302 | u32 ps; | |
303 | u32 us; | |
304 | u64 ref; | |
305 | u64 action; | |
306 | u64 wwpn; | |
307 | u64 fcp_lun; | |
308 | } __attribute__ ((packed)); | |
309 | ||
d79a83db MP |
310 | struct zfcp_rec_dbf_record { |
311 | u8 id; | |
312 | u8 id2; | |
313 | union { | |
348447e8 | 314 | struct zfcp_rec_dbf_record_thread thread; |
698ec016 | 315 | struct zfcp_rec_dbf_record_target target; |
9467a9b3 | 316 | struct zfcp_rec_dbf_record_trigger trigger; |
d79a83db MP |
317 | } u; |
318 | } __attribute__ ((packed)); | |
319 | ||
348447e8 MP |
320 | enum { |
321 | ZFCP_REC_DBF_ID_THREAD, | |
698ec016 | 322 | ZFCP_REC_DBF_ID_TARGET, |
9467a9b3 | 323 | ZFCP_REC_DBF_ID_TRIGGER, |
348447e8 MP |
324 | }; |
325 | ||
8a36e453 MS |
326 | struct zfcp_hba_dbf_record_response { |
327 | u32 fsf_command; | |
328 | u64 fsf_reqid; | |
329 | u32 fsf_seqno; | |
330 | u64 fsf_issued; | |
331 | u32 fsf_prot_status; | |
332 | u32 fsf_status; | |
333 | u8 fsf_prot_status_qual[FSF_PROT_STATUS_QUAL_SIZE]; | |
334 | u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE]; | |
335 | u32 fsf_req_status; | |
336 | u8 sbal_first; | |
337 | u8 sbal_curr; | |
338 | u8 sbal_last; | |
339 | u8 pool; | |
340 | u64 erp_action; | |
341 | union { | |
342 | struct { | |
343 | u64 scsi_cmnd; | |
344 | u64 scsi_serial; | |
345 | } send_fcp; | |
346 | struct { | |
347 | u64 wwpn; | |
348 | u32 d_id; | |
349 | u32 port_handle; | |
350 | } port; | |
351 | struct { | |
352 | u64 wwpn; | |
353 | u64 fcp_lun; | |
354 | u32 port_handle; | |
355 | u32 lun_handle; | |
356 | } unit; | |
357 | struct { | |
358 | u32 d_id; | |
359 | u8 ls_code; | |
360 | } send_els; | |
361 | } data; | |
362 | } __attribute__ ((packed)); | |
363 | ||
364 | struct zfcp_hba_dbf_record_status { | |
365 | u8 failed; | |
366 | u32 status_type; | |
367 | u32 status_subtype; | |
368 | struct fsf_queue_designator | |
369 | queue_designator; | |
370 | u32 payload_size; | |
371 | #define ZFCP_DBF_UNSOL_PAYLOAD 80 | |
372 | #define ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL 32 | |
373 | #define ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD 56 | |
374 | #define ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT 2 * sizeof(u32) | |
375 | u8 payload[ZFCP_DBF_UNSOL_PAYLOAD]; | |
376 | } __attribute__ ((packed)); | |
377 | ||
378 | struct zfcp_hba_dbf_record_qdio { | |
379 | u32 status; | |
380 | u32 qdio_error; | |
381 | u32 siga_error; | |
382 | u8 sbal_index; | |
383 | u8 sbal_count; | |
384 | } __attribute__ ((packed)); | |
385 | ||
386 | struct zfcp_hba_dbf_record { | |
387 | u8 tag[ZFCP_DBF_TAG_SIZE]; | |
388 | u8 tag2[ZFCP_DBF_TAG_SIZE]; | |
389 | union { | |
390 | struct zfcp_hba_dbf_record_response response; | |
391 | struct zfcp_hba_dbf_record_status status; | |
392 | struct zfcp_hba_dbf_record_qdio qdio; | |
393 | } type; | |
394 | } __attribute__ ((packed)); | |
395 | ||
396 | struct zfcp_san_dbf_record_ct { | |
397 | union { | |
398 | struct { | |
399 | u16 cmd_req_code; | |
400 | u8 revision; | |
401 | u8 gs_type; | |
402 | u8 gs_subtype; | |
403 | u8 options; | |
404 | u16 max_res_size; | |
405 | } request; | |
406 | struct { | |
407 | u16 cmd_rsp_code; | |
408 | u8 revision; | |
409 | u8 reason_code; | |
410 | u8 reason_code_expl; | |
411 | u8 vendor_unique; | |
412 | } response; | |
413 | } type; | |
414 | u32 payload_size; | |
415 | #define ZFCP_DBF_CT_PAYLOAD 24 | |
416 | u8 payload[ZFCP_DBF_CT_PAYLOAD]; | |
417 | } __attribute__ ((packed)); | |
418 | ||
419 | struct zfcp_san_dbf_record_els { | |
420 | u8 ls_code; | |
421 | u32 payload_size; | |
422 | #define ZFCP_DBF_ELS_PAYLOAD 32 | |
423 | #define ZFCP_DBF_ELS_MAX_PAYLOAD 1024 | |
424 | u8 payload[ZFCP_DBF_ELS_PAYLOAD]; | |
425 | } __attribute__ ((packed)); | |
426 | ||
427 | struct zfcp_san_dbf_record { | |
428 | u8 tag[ZFCP_DBF_TAG_SIZE]; | |
429 | u64 fsf_reqid; | |
430 | u32 fsf_seqno; | |
431 | u32 s_id; | |
432 | u32 d_id; | |
433 | union { | |
434 | struct zfcp_san_dbf_record_ct ct; | |
435 | struct zfcp_san_dbf_record_els els; | |
436 | } type; | |
437 | } __attribute__ ((packed)); | |
438 | ||
439 | struct zfcp_scsi_dbf_record { | |
440 | u8 tag[ZFCP_DBF_TAG_SIZE]; | |
441 | u8 tag2[ZFCP_DBF_TAG_SIZE]; | |
442 | u32 scsi_id; | |
443 | u32 scsi_lun; | |
444 | u32 scsi_result; | |
445 | u64 scsi_cmnd; | |
446 | u64 scsi_serial; | |
447 | #define ZFCP_DBF_SCSI_OPCODE 16 | |
448 | u8 scsi_opcode[ZFCP_DBF_SCSI_OPCODE]; | |
449 | u8 scsi_retries; | |
450 | u8 scsi_allowed; | |
451 | u64 fsf_reqid; | |
452 | u32 fsf_seqno; | |
453 | u64 fsf_issued; | |
454 | union { | |
ed829ad6 | 455 | u64 old_fsf_reqid; |
8a36e453 MS |
456 | struct { |
457 | u8 rsp_validity; | |
458 | u8 rsp_scsi_status; | |
459 | u32 rsp_resid; | |
460 | u8 rsp_code; | |
461 | #define ZFCP_DBF_SCSI_FCP_SNS_INFO 16 | |
462 | #define ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO 256 | |
463 | u32 sns_info_len; | |
464 | u8 sns_info[ZFCP_DBF_SCSI_FCP_SNS_INFO]; | |
465 | } fcp; | |
466 | } type; | |
467 | } __attribute__ ((packed)); | |
468 | ||
1da177e4 LT |
469 | /* |
470 | * FC-FS stuff | |
471 | */ | |
472 | #define R_A_TOV 10 /* seconds */ | |
473 | #define ZFCP_ELS_TIMEOUT (2 * R_A_TOV) | |
474 | ||
475 | #define ZFCP_LS_RLS 0x0f | |
476 | #define ZFCP_LS_ADISC 0x52 | |
477 | #define ZFCP_LS_RPS 0x56 | |
478 | #define ZFCP_LS_RSCN 0x61 | |
479 | #define ZFCP_LS_RNID 0x78 | |
480 | ||
481 | struct zfcp_ls_rjt_par { | |
482 | u8 action; | |
483 | u8 reason_code; | |
484 | u8 reason_expl; | |
485 | u8 vendor_unique; | |
486 | } __attribute__ ((packed)); | |
487 | ||
488 | struct zfcp_ls_adisc { | |
489 | u8 code; | |
490 | u8 field[3]; | |
491 | u32 hard_nport_id; | |
492 | u64 wwpn; | |
493 | u64 wwnn; | |
494 | u32 nport_id; | |
495 | } __attribute__ ((packed)); | |
496 | ||
497 | struct zfcp_ls_adisc_acc { | |
498 | u8 code; | |
499 | u8 field[3]; | |
500 | u32 hard_nport_id; | |
501 | u64 wwpn; | |
502 | u64 wwnn; | |
503 | u32 nport_id; | |
504 | } __attribute__ ((packed)); | |
505 | ||
506 | struct zfcp_rc_entry { | |
507 | u8 code; | |
508 | const char *description; | |
509 | }; | |
510 | ||
511 | /* | |
512 | * FC-GS-2 stuff | |
513 | */ | |
514 | #define ZFCP_CT_REVISION 0x01 | |
515 | #define ZFCP_CT_DIRECTORY_SERVICE 0xFC | |
516 | #define ZFCP_CT_NAME_SERVER 0x02 | |
517 | #define ZFCP_CT_SYNCHRONOUS 0x00 | |
518 | #define ZFCP_CT_GID_PN 0x0121 | |
519 | #define ZFCP_CT_MAX_SIZE 0x1020 | |
520 | #define ZFCP_CT_ACCEPT 0x8002 | |
521 | #define ZFCP_CT_REJECT 0x8001 | |
522 | ||
523 | /* | |
524 | * FC-GS-4 stuff | |
525 | */ | |
526 | #define ZFCP_CT_TIMEOUT (3 * R_A_TOV) | |
527 | ||
1da177e4 LT |
528 | /******************** LOGGING MACROS AND DEFINES *****************************/ |
529 | ||
530 | /* | |
531 | * Logging may be applied on certain kinds of driver operations | |
532 | * independently. Additionally, different log-levels are supported for | |
533 | * each of these areas. | |
534 | */ | |
535 | ||
536 | #define ZFCP_NAME "zfcp" | |
537 | ||
1da177e4 LT |
538 | /* independent log areas */ |
539 | #define ZFCP_LOG_AREA_OTHER 0 | |
540 | #define ZFCP_LOG_AREA_SCSI 1 | |
541 | #define ZFCP_LOG_AREA_FSF 2 | |
542 | #define ZFCP_LOG_AREA_CONFIG 3 | |
543 | #define ZFCP_LOG_AREA_CIO 4 | |
544 | #define ZFCP_LOG_AREA_QDIO 5 | |
545 | #define ZFCP_LOG_AREA_ERP 6 | |
546 | #define ZFCP_LOG_AREA_FC 7 | |
547 | ||
548 | /* log level values*/ | |
549 | #define ZFCP_LOG_LEVEL_NORMAL 0 | |
550 | #define ZFCP_LOG_LEVEL_INFO 1 | |
551 | #define ZFCP_LOG_LEVEL_DEBUG 2 | |
552 | #define ZFCP_LOG_LEVEL_TRACE 3 | |
553 | ||
554 | /* | |
555 | * this allows removal of logging code by the preprocessor | |
41fa2ada | 556 | * (the most detailed log level still to be compiled in is specified, |
1da177e4 LT |
557 | * higher log levels are removed) |
558 | */ | |
559 | #define ZFCP_LOG_LEVEL_LIMIT ZFCP_LOG_LEVEL_TRACE | |
560 | ||
561 | /* get "loglevel" nibble assignment */ | |
562 | #define ZFCP_GET_LOG_VALUE(zfcp_lognibble) \ | |
563 | ((atomic_read(&zfcp_data.loglevel) >> (zfcp_lognibble<<2)) & 0xF) | |
564 | ||
565 | /* set "loglevel" nibble */ | |
566 | #define ZFCP_SET_LOG_NIBBLE(value, zfcp_lognibble) \ | |
567 | (value << (zfcp_lognibble << 2)) | |
568 | ||
569 | /* all log-level defaults are combined to generate initial log-level */ | |
570 | #define ZFCP_LOG_LEVEL_DEFAULTS \ | |
571 | (ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_OTHER) | \ | |
572 | ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_SCSI) | \ | |
573 | ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FSF) | \ | |
574 | ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CONFIG) | \ | |
575 | ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CIO) | \ | |
576 | ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_QDIO) | \ | |
577 | ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_ERP) | \ | |
578 | ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FC)) | |
579 | ||
580 | /* check whether we have the right level for logging */ | |
581 | #define ZFCP_LOG_CHECK(level) \ | |
582 | ((ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA)) >= level) | |
583 | ||
584 | /* logging routine for zfcp */ | |
585 | #define _ZFCP_LOG(fmt, args...) \ | |
586 | printk(KERN_ERR ZFCP_NAME": %s(%d): " fmt, __FUNCTION__, \ | |
587 | __LINE__ , ##args) | |
588 | ||
589 | #define ZFCP_LOG(level, fmt, args...) \ | |
590 | do { \ | |
591 | if (ZFCP_LOG_CHECK(level)) \ | |
592 | _ZFCP_LOG(fmt, ##args); \ | |
593 | } while (0) | |
41fa2ada | 594 | |
1da177e4 | 595 | #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_NORMAL |
39b083fe | 596 | # define ZFCP_LOG_NORMAL(fmt, args...) do { } while (0) |
1da177e4 LT |
597 | #else |
598 | # define ZFCP_LOG_NORMAL(fmt, args...) \ | |
599 | do { \ | |
600 | if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_NORMAL)) \ | |
601 | printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \ | |
602 | } while (0) | |
603 | #endif | |
604 | ||
605 | #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_INFO | |
39b083fe | 606 | # define ZFCP_LOG_INFO(fmt, args...) do { } while (0) |
1da177e4 LT |
607 | #else |
608 | # define ZFCP_LOG_INFO(fmt, args...) \ | |
609 | do { \ | |
610 | if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_INFO)) \ | |
611 | printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \ | |
612 | } while (0) | |
613 | #endif | |
614 | ||
615 | #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_DEBUG | |
39b083fe | 616 | # define ZFCP_LOG_DEBUG(fmt, args...) do { } while (0) |
1da177e4 LT |
617 | #else |
618 | # define ZFCP_LOG_DEBUG(fmt, args...) \ | |
619 | ZFCP_LOG(ZFCP_LOG_LEVEL_DEBUG, fmt , ##args) | |
620 | #endif | |
621 | ||
622 | #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_TRACE | |
39b083fe | 623 | # define ZFCP_LOG_TRACE(fmt, args...) do { } while (0) |
1da177e4 LT |
624 | #else |
625 | # define ZFCP_LOG_TRACE(fmt, args...) \ | |
626 | ZFCP_LOG(ZFCP_LOG_LEVEL_TRACE, fmt , ##args) | |
627 | #endif | |
628 | ||
1da177e4 LT |
629 | /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/ |
630 | ||
41fa2ada SS |
631 | /* |
632 | * Note, the leftmost status byte is common among adapter, port | |
1da177e4 LT |
633 | * and unit |
634 | */ | |
635 | #define ZFCP_COMMON_FLAGS 0xfff00000 | |
1da177e4 LT |
636 | |
637 | /* common status bits */ | |
638 | #define ZFCP_STATUS_COMMON_REMOVE 0x80000000 | |
639 | #define ZFCP_STATUS_COMMON_RUNNING 0x40000000 | |
640 | #define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000 | |
641 | #define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000 | |
642 | #define ZFCP_STATUS_COMMON_OPENING 0x08000000 | |
643 | #define ZFCP_STATUS_COMMON_OPEN 0x04000000 | |
644 | #define ZFCP_STATUS_COMMON_CLOSING 0x02000000 | |
645 | #define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000 | |
646 | #define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000 | |
d736a27b | 647 | #define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000 |
1da177e4 LT |
648 | |
649 | /* adapter status */ | |
650 | #define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002 | |
651 | #define ZFCP_STATUS_ADAPTER_REGISTERED 0x00000004 | |
652 | #define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008 | |
653 | #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010 | |
654 | #define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020 | |
655 | #define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080 | |
656 | #define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100 | |
657 | #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200 | |
aef4a983 | 658 | #define ZFCP_STATUS_ADAPTER_XPORT_OK 0x00000800 |
1da177e4 | 659 | |
1da177e4 LT |
660 | /* FC-PH/FC-GS well-known address identifiers for generic services */ |
661 | #define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA | |
662 | #define ZFCP_DID_TIME_SERVICE 0xFFFFFB | |
663 | #define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC | |
664 | #define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8 | |
665 | #define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7 | |
666 | ||
667 | /* remote port status */ | |
668 | #define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001 | |
669 | #define ZFCP_STATUS_PORT_DID_DID 0x00000002 | |
670 | #define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004 | |
671 | #define ZFCP_STATUS_PORT_NO_WWPN 0x00000008 | |
672 | #define ZFCP_STATUS_PORT_NO_SCSI_ID 0x00000010 | |
673 | #define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020 | |
1da177e4 LT |
674 | |
675 | /* for ports with well known addresses */ | |
676 | #define ZFCP_STATUS_PORT_WKA \ | |
677 | (ZFCP_STATUS_PORT_NO_WWPN | \ | |
678 | ZFCP_STATUS_PORT_NO_SCSI_ID) | |
679 | ||
680 | /* logical unit status */ | |
1da177e4 LT |
681 | #define ZFCP_STATUS_UNIT_TEMPORARY 0x00000002 |
682 | #define ZFCP_STATUS_UNIT_SHARED 0x00000004 | |
683 | #define ZFCP_STATUS_UNIT_READONLY 0x00000008 | |
ad58f7db | 684 | #define ZFCP_STATUS_UNIT_REGISTERED 0x00000010 |
5f852be9 | 685 | #define ZFCP_STATUS_UNIT_SCSI_WORK_PENDING 0x00000020 |
1da177e4 LT |
686 | |
687 | /* FSF request status (this does not have a common part) */ | |
688 | #define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000 | |
689 | #define ZFCP_STATUS_FSFREQ_POOL 0x00000001 | |
690 | #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002 | |
691 | #define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004 | |
692 | #define ZFCP_STATUS_FSFREQ_ERROR 0x00000008 | |
693 | #define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010 | |
694 | #define ZFCP_STATUS_FSFREQ_ABORTING 0x00000020 | |
695 | #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040 | |
696 | #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080 | |
697 | #define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100 | |
698 | #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200 | |
699 | #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400 | |
700 | #define ZFCP_STATUS_FSFREQ_RETRY 0x00000800 | |
701 | #define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000 | |
702 | ||
703 | /*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/ | |
704 | ||
705 | #define ZFCP_MAX_ERPS 3 | |
706 | ||
707 | #define ZFCP_ERP_FSFREQ_TIMEOUT (30 * HZ) | |
708 | #define ZFCP_ERP_MEMWAIT_TIMEOUT HZ | |
709 | ||
710 | #define ZFCP_STATUS_ERP_TIMEDOUT 0x10000000 | |
711 | #define ZFCP_STATUS_ERP_CLOSE_ONLY 0x01000000 | |
712 | #define ZFCP_STATUS_ERP_DISMISSING 0x00100000 | |
713 | #define ZFCP_STATUS_ERP_DISMISSED 0x00200000 | |
714 | #define ZFCP_STATUS_ERP_LOWMEM 0x00400000 | |
715 | ||
716 | #define ZFCP_ERP_STEP_UNINITIALIZED 0x00000000 | |
717 | #define ZFCP_ERP_STEP_FSF_XCONFIG 0x00000001 | |
718 | #define ZFCP_ERP_STEP_PHYS_PORT_CLOSING 0x00000010 | |
719 | #define ZFCP_ERP_STEP_PORT_CLOSING 0x00000100 | |
720 | #define ZFCP_ERP_STEP_NAMESERVER_OPEN 0x00000200 | |
721 | #define ZFCP_ERP_STEP_NAMESERVER_LOOKUP 0x00000400 | |
722 | #define ZFCP_ERP_STEP_PORT_OPENING 0x00000800 | |
723 | #define ZFCP_ERP_STEP_UNIT_CLOSING 0x00001000 | |
724 | #define ZFCP_ERP_STEP_UNIT_OPENING 0x00002000 | |
725 | ||
726 | /* Ordered by escalation level (necessary for proper erp-code operation) */ | |
727 | #define ZFCP_ERP_ACTION_REOPEN_ADAPTER 0x4 | |
728 | #define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED 0x3 | |
729 | #define ZFCP_ERP_ACTION_REOPEN_PORT 0x2 | |
730 | #define ZFCP_ERP_ACTION_REOPEN_UNIT 0x1 | |
731 | ||
732 | #define ZFCP_ERP_ACTION_RUNNING 0x1 | |
733 | #define ZFCP_ERP_ACTION_READY 0x2 | |
734 | ||
735 | #define ZFCP_ERP_SUCCEEDED 0x0 | |
736 | #define ZFCP_ERP_FAILED 0x1 | |
737 | #define ZFCP_ERP_CONTINUES 0x2 | |
738 | #define ZFCP_ERP_EXIT 0x3 | |
739 | #define ZFCP_ERP_DISMISSED 0x4 | |
740 | #define ZFCP_ERP_NOMEM 0x5 | |
741 | ||
742 | ||
743 | /******************** CFDC SPECIFIC STUFF *****************************/ | |
744 | ||
745 | /* Firewall data channel sense data record */ | |
746 | struct zfcp_cfdc_sense_data { | |
747 | u32 signature; /* Request signature */ | |
748 | u32 devno; /* FCP adapter device number */ | |
749 | u32 command; /* Command code */ | |
750 | u32 fsf_status; /* FSF request status and status qualifier */ | |
751 | u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE]; | |
752 | u8 payloads[256]; /* Access conflicts list */ | |
753 | u8 control_file[0]; /* Access control table */ | |
754 | }; | |
755 | ||
756 | #define ZFCP_CFDC_SIGNATURE 0xCFDCACDF | |
757 | ||
758 | #define ZFCP_CFDC_CMND_DOWNLOAD_NORMAL 0x00010001 | |
759 | #define ZFCP_CFDC_CMND_DOWNLOAD_FORCE 0x00010101 | |
760 | #define ZFCP_CFDC_CMND_FULL_ACCESS 0x00000201 | |
761 | #define ZFCP_CFDC_CMND_RESTRICTED_ACCESS 0x00000401 | |
762 | #define ZFCP_CFDC_CMND_UPLOAD 0x00010002 | |
763 | ||
764 | #define ZFCP_CFDC_DOWNLOAD 0x00000001 | |
765 | #define ZFCP_CFDC_UPLOAD 0x00000002 | |
766 | #define ZFCP_CFDC_WITH_CONTROL_FILE 0x00010000 | |
767 | ||
768 | #define ZFCP_CFDC_DEV_NAME "zfcp_cfdc" | |
769 | #define ZFCP_CFDC_DEV_MAJOR MISC_MAJOR | |
770 | #define ZFCP_CFDC_DEV_MINOR MISC_DYNAMIC_MINOR | |
771 | ||
772 | #define ZFCP_CFDC_MAX_CONTROL_FILE_SIZE 127 * 1024 | |
773 | ||
774 | /************************* STRUCTURE DEFINITIONS *****************************/ | |
775 | ||
776 | struct zfcp_fsf_req; | |
777 | ||
778 | /* holds various memory pools of an adapter */ | |
779 | struct zfcp_adapter_mempool { | |
780 | mempool_t *fsf_req_erp; | |
781 | mempool_t *fsf_req_scsi; | |
782 | mempool_t *fsf_req_abort; | |
783 | mempool_t *fsf_req_status_read; | |
784 | mempool_t *data_status_read; | |
785 | mempool_t *data_gid_pn; | |
786 | }; | |
787 | ||
1da177e4 LT |
788 | /* |
789 | * header for CT_IU | |
790 | */ | |
791 | struct ct_hdr { | |
792 | u8 revision; // 0x01 | |
793 | u8 in_id[3]; // 0x00 | |
794 | u8 gs_type; // 0xFC Directory Service | |
795 | u8 gs_subtype; // 0x02 Name Server | |
796 | u8 options; // 0x00 single bidirectional exchange | |
797 | u8 reserved0; | |
798 | u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT | |
799 | u16 max_res_size; // <= (4096 - 16) / 4 | |
800 | u8 reserved1; | |
801 | u8 reason_code; | |
802 | u8 reason_code_expl; | |
803 | u8 vendor_unique; | |
804 | } __attribute__ ((packed)); | |
805 | ||
806 | /* nameserver request CT_IU -- for requests where | |
807 | * a port name is required */ | |
808 | struct ct_iu_gid_pn_req { | |
809 | struct ct_hdr header; | |
810 | wwn_t wwpn; | |
811 | } __attribute__ ((packed)); | |
812 | ||
813 | /* FS_ACC IU and data unit for GID_PN nameserver request */ | |
814 | struct ct_iu_gid_pn_resp { | |
815 | struct ct_hdr header; | |
13e1e1f0 | 816 | u32 d_id; |
1da177e4 LT |
817 | } __attribute__ ((packed)); |
818 | ||
819 | typedef void (*zfcp_send_ct_handler_t)(unsigned long); | |
820 | ||
821 | /** | |
822 | * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct | |
823 | * @port: port where the request is sent to | |
824 | * @req: scatter-gather list for request | |
825 | * @resp: scatter-gather list for response | |
826 | * @req_count: number of elements in request scatter-gather list | |
827 | * @resp_count: number of elements in response scatter-gather list | |
828 | * @handler: handler function (called for response to the request) | |
829 | * @handler_data: data passed to handler function | |
830 | * @pool: pointer to memory pool for ct request structure | |
831 | * @timeout: FSF timeout for this request | |
1da177e4 LT |
832 | * @completion: completion for synchronization purposes |
833 | * @status: used to pass error status to calling function | |
834 | */ | |
835 | struct zfcp_send_ct { | |
836 | struct zfcp_port *port; | |
837 | struct scatterlist *req; | |
838 | struct scatterlist *resp; | |
839 | unsigned int req_count; | |
840 | unsigned int resp_count; | |
841 | zfcp_send_ct_handler_t handler; | |
842 | unsigned long handler_data; | |
843 | mempool_t *pool; | |
844 | int timeout; | |
1da177e4 LT |
845 | struct completion *completion; |
846 | int status; | |
847 | }; | |
848 | ||
849 | /* used for name server requests in error recovery */ | |
850 | struct zfcp_gid_pn_data { | |
851 | struct zfcp_send_ct ct; | |
852 | struct scatterlist req; | |
853 | struct scatterlist resp; | |
854 | struct ct_iu_gid_pn_req ct_iu_req; | |
855 | struct ct_iu_gid_pn_resp ct_iu_resp; | |
856 | struct zfcp_port *port; | |
857 | }; | |
858 | ||
859 | typedef void (*zfcp_send_els_handler_t)(unsigned long); | |
860 | ||
861 | /** | |
862 | * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els | |
863 | * @adapter: adapter where request is sent from | |
64b29a13 | 864 | * @port: port where ELS is destinated (port reference count has to be increased) |
1da177e4 LT |
865 | * @d_id: destiniation id of port where request is sent to |
866 | * @req: scatter-gather list for request | |
867 | * @resp: scatter-gather list for response | |
868 | * @req_count: number of elements in request scatter-gather list | |
869 | * @resp_count: number of elements in response scatter-gather list | |
870 | * @handler: handler function (called for response to the request) | |
871 | * @handler_data: data passed to handler function | |
1da177e4 LT |
872 | * @completion: completion for synchronization purposes |
873 | * @ls_code: hex code of ELS command | |
874 | * @status: used to pass error status to calling function | |
875 | */ | |
876 | struct zfcp_send_els { | |
877 | struct zfcp_adapter *adapter; | |
64b29a13 | 878 | struct zfcp_port *port; |
13e1e1f0 | 879 | u32 d_id; |
1da177e4 LT |
880 | struct scatterlist *req; |
881 | struct scatterlist *resp; | |
882 | unsigned int req_count; | |
883 | unsigned int resp_count; | |
884 | zfcp_send_els_handler_t handler; | |
885 | unsigned long handler_data; | |
1da177e4 LT |
886 | struct completion *completion; |
887 | int ls_code; | |
888 | int status; | |
889 | }; | |
890 | ||
1da177e4 LT |
891 | struct zfcp_qdio_queue { |
892 | struct qdio_buffer *buffer[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */ | |
893 | u8 free_index; /* index of next free bfr | |
894 | in queue (free_count>0) */ | |
895 | atomic_t free_count; /* number of free buffers | |
896 | in queue */ | |
897 | rwlock_t queue_lock; /* lock for operations on queue */ | |
898 | int distance_from_int; /* SBALs used since PCI indication | |
899 | was last set */ | |
900 | }; | |
901 | ||
902 | struct zfcp_erp_action { | |
903 | struct list_head list; | |
904 | int action; /* requested action code */ | |
905 | struct zfcp_adapter *adapter; /* device which should be recovered */ | |
906 | struct zfcp_port *port; | |
907 | struct zfcp_unit *unit; | |
908 | volatile u32 status; /* recovery status */ | |
909 | u32 step; /* active step of this erp action */ | |
910 | struct zfcp_fsf_req *fsf_req; /* fsf request currently pending | |
911 | for this action */ | |
912 | struct timer_list timer; | |
913 | }; | |
914 | ||
915 | ||
916 | struct zfcp_adapter { | |
917 | struct list_head list; /* list of adapters */ | |
918 | atomic_t refcount; /* reference count */ | |
919 | wait_queue_head_t remove_wq; /* can be used to wait for | |
920 | refcount drop to zero */ | |
6f71d9bc JB |
921 | wwn_t peer_wwnn; /* P2P peer WWNN */ |
922 | wwn_t peer_wwpn; /* P2P peer WWPN */ | |
13e1e1f0 | 923 | u32 peer_d_id; /* P2P peer D_ID */ |
1da177e4 | 924 | struct ccw_device *ccw_device; /* S/390 ccw device */ |
1da177e4 LT |
925 | u32 hydra_version; /* Hydra version */ |
926 | u32 fsf_lic_version; | |
aef4a983 MS |
927 | u32 adapter_features; /* FCP channel features */ |
928 | u32 connection_features; /* host connection features */ | |
1da177e4 | 929 | u32 hardware_version; /* of FCP channel */ |
1da177e4 | 930 | struct Scsi_Host *scsi_host; /* Pointer to mid-layer */ |
1da177e4 LT |
931 | struct list_head port_list_head; /* remote port list */ |
932 | struct list_head port_remove_lh; /* head of ports to be | |
933 | removed */ | |
934 | u32 ports; /* number of remote ports */ | |
fea9d6c7 VS |
935 | atomic_t reqs_active; /* # active FSF reqs */ |
936 | unsigned long req_no; /* unique FSF req number */ | |
937 | struct list_head *req_list; /* list of pending reqs */ | |
938 | spinlock_t req_list_lock; /* request list lock */ | |
1da177e4 LT |
939 | struct zfcp_qdio_queue request_queue; /* request queue */ |
940 | u32 fsf_req_seq_no; /* FSF cmnd seq number */ | |
941 | wait_queue_head_t request_wq; /* can be used to wait for | |
942 | more avaliable SBALs */ | |
943 | struct zfcp_qdio_queue response_queue; /* response queue */ | |
944 | rwlock_t abort_lock; /* Protects against SCSI | |
945 | stack abort/command | |
946 | completion races */ | |
947 | u16 status_read_failed; /* # failed status reads */ | |
948 | atomic_t status; /* status of this adapter */ | |
949 | struct list_head erp_ready_head; /* error recovery for this | |
950 | adapter/devices */ | |
951 | struct list_head erp_running_head; | |
952 | rwlock_t erp_lock; | |
953 | struct semaphore erp_ready_sem; | |
954 | wait_queue_head_t erp_thread_wqh; | |
955 | wait_queue_head_t erp_done_wqh; | |
956 | struct zfcp_erp_action erp_action; /* pending error recovery */ | |
957 | atomic_t erp_counter; | |
958 | u32 erp_total_count; /* total nr of enqueued erp | |
959 | actions */ | |
960 | u32 erp_low_mem_count; /* nr of erp actions waiting | |
961 | for memory */ | |
962 | struct zfcp_port *nameserver_port; /* adapter's nameserver */ | |
8a36e453 | 963 | debug_info_t *erp_dbf; |
d79a83db | 964 | debug_info_t *rec_dbf; |
8a36e453 MS |
965 | debug_info_t *hba_dbf; |
966 | debug_info_t *san_dbf; /* debug feature areas */ | |
967 | debug_info_t *scsi_dbf; | |
968 | spinlock_t erp_dbf_lock; | |
d79a83db | 969 | spinlock_t rec_dbf_lock; |
8a36e453 MS |
970 | spinlock_t hba_dbf_lock; |
971 | spinlock_t san_dbf_lock; | |
972 | spinlock_t scsi_dbf_lock; | |
973 | struct zfcp_erp_dbf_record erp_dbf_buf; | |
d79a83db | 974 | struct zfcp_rec_dbf_record rec_dbf_buf; |
8a36e453 MS |
975 | struct zfcp_hba_dbf_record hba_dbf_buf; |
976 | struct zfcp_san_dbf_record san_dbf_buf; | |
977 | struct zfcp_scsi_dbf_record scsi_dbf_buf; | |
1da177e4 LT |
978 | struct zfcp_adapter_mempool pool; /* Adapter memory pools */ |
979 | struct qdio_initialize qdio_init_data; /* for qdio_establish */ | |
980 | struct device generic_services; /* directory for WKA ports */ | |
f6cd94b1 AH |
981 | struct fc_host_statistics *fc_stats; |
982 | struct fsf_qtcb_bottom_port *stats_reset_data; | |
983 | unsigned long stats_reset; | |
1da177e4 LT |
984 | }; |
985 | ||
986 | /* | |
987 | * the struct device sysfs_device must be at the beginning of this structure. | |
988 | * pointer to struct device is used to free port structure in release function | |
989 | * of the device. don't change! | |
990 | */ | |
991 | struct zfcp_port { | |
992 | struct device sysfs_device; /* sysfs device */ | |
3859f6a2 | 993 | struct fc_rport *rport; /* rport of fc transport class */ |
1da177e4 LT |
994 | struct list_head list; /* list of remote ports */ |
995 | atomic_t refcount; /* reference count */ | |
996 | wait_queue_head_t remove_wq; /* can be used to wait for | |
997 | refcount drop to zero */ | |
998 | struct zfcp_adapter *adapter; /* adapter used to access port */ | |
999 | struct list_head unit_list_head; /* head of logical unit list */ | |
1000 | struct list_head unit_remove_lh; /* head of luns to be removed | |
1001 | list */ | |
1002 | u32 units; /* # of logical units in list */ | |
1003 | atomic_t status; /* status of this remote port */ | |
1da177e4 LT |
1004 | wwn_t wwnn; /* WWNN if known */ |
1005 | wwn_t wwpn; /* WWPN */ | |
13e1e1f0 | 1006 | u32 d_id; /* D_ID */ |
1da177e4 LT |
1007 | u32 handle; /* handle assigned by FSF */ |
1008 | struct zfcp_erp_action erp_action; /* pending error recovery */ | |
1009 | atomic_t erp_counter; | |
75bfc283 RW |
1010 | u32 maxframe_size; |
1011 | u32 supported_classes; | |
1da177e4 LT |
1012 | }; |
1013 | ||
1014 | /* the struct device sysfs_device must be at the beginning of this structure. | |
1015 | * pointer to struct device is used to free unit structure in release function | |
1016 | * of the device. don't change! | |
1017 | */ | |
1018 | struct zfcp_unit { | |
1019 | struct device sysfs_device; /* sysfs device */ | |
1020 | struct list_head list; /* list of logical units */ | |
1021 | atomic_t refcount; /* reference count */ | |
1022 | wait_queue_head_t remove_wq; /* can be used to wait for | |
1023 | refcount drop to zero */ | |
1024 | struct zfcp_port *port; /* remote port of unit */ | |
1025 | atomic_t status; /* status of this logical unit */ | |
06506d00 | 1026 | unsigned int scsi_lun; /* own SCSI LUN */ |
1da177e4 LT |
1027 | fcp_lun_t fcp_lun; /* own FCP_LUN */ |
1028 | u32 handle; /* handle assigned by FSF */ | |
1029 | struct scsi_device *device; /* scsi device struct pointer */ | |
1030 | struct zfcp_erp_action erp_action; /* pending error recovery */ | |
1031 | atomic_t erp_counter; | |
1032 | }; | |
1033 | ||
1034 | /* FSF request */ | |
1035 | struct zfcp_fsf_req { | |
1036 | struct list_head list; /* list of FSF requests */ | |
fea9d6c7 | 1037 | unsigned long req_id; /* unique request ID */ |
1da177e4 LT |
1038 | struct zfcp_adapter *adapter; /* adapter request belongs to */ |
1039 | u8 sbal_number; /* nr of SBALs free for use */ | |
1040 | u8 sbal_first; /* first SBAL for this request */ | |
1041 | u8 sbal_last; /* last possible SBAL for | |
1042 | this reuest */ | |
1043 | u8 sbal_curr; /* current SBAL during creation | |
1044 | of request */ | |
1045 | u8 sbale_curr; /* current SBALE during creation | |
1046 | of request */ | |
1047 | wait_queue_head_t completion_wq; /* can be used by a routine | |
1048 | to wait for completion */ | |
1049 | volatile u32 status; /* status of this request */ | |
1050 | u32 fsf_command; /* FSF Command copy */ | |
1051 | struct fsf_qtcb *qtcb; /* address of associated QTCB */ | |
1052 | u32 seq_no; /* Sequence number of request */ | |
41fa2ada SS |
1053 | unsigned long data; /* private data of request */ |
1054 | struct timer_list timer; /* used for erp or scsi er */ | |
1da177e4 LT |
1055 | struct zfcp_erp_action *erp_action; /* used if this request is |
1056 | issued on behalf of erp */ | |
1057 | mempool_t *pool; /* used if request was alloacted | |
1058 | from emergency pool */ | |
8a36e453 | 1059 | unsigned long long issued; /* request sent time (STCK) */ |
059c97d0 | 1060 | struct zfcp_unit *unit; |
1da177e4 LT |
1061 | }; |
1062 | ||
1063 | typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*); | |
1064 | ||
1065 | /* driver data */ | |
1066 | struct zfcp_data { | |
1067 | struct scsi_host_template scsi_host_template; | |
dd52e0ea | 1068 | struct scsi_transport_template *scsi_transport_template; |
1da177e4 LT |
1069 | atomic_t status; /* Module status flags */ |
1070 | struct list_head adapter_list_head; /* head of adapter list */ | |
1071 | struct list_head adapter_remove_lh; /* head of adapters to be | |
1072 | removed */ | |
1da177e4 LT |
1073 | u32 adapters; /* # of adapters in list */ |
1074 | rwlock_t config_lock; /* serialises changes | |
1075 | to adapter/port/unit | |
1076 | lists */ | |
1077 | struct semaphore config_sema; /* serialises configuration | |
1078 | changes */ | |
1079 | atomic_t loglevel; /* current loglevel */ | |
1080 | char init_busid[BUS_ID_SIZE]; | |
1081 | wwn_t init_wwpn; | |
1082 | fcp_lun_t init_fcp_lun; | |
1083 | char *driver_version; | |
e18b890b CL |
1084 | struct kmem_cache *fsf_req_qtcb_cache; |
1085 | struct kmem_cache *sr_buffer_cache; | |
1086 | struct kmem_cache *gid_pn_cache; | |
1da177e4 LT |
1087 | }; |
1088 | ||
1089 | /** | |
1090 | * struct zfcp_sg_list - struct describing a scatter-gather list | |
1091 | * @sg: pointer to array of (struct scatterlist) | |
1092 | * @count: number of elements in scatter-gather list | |
1093 | */ | |
1094 | struct zfcp_sg_list { | |
1095 | struct scatterlist *sg; | |
1096 | unsigned int count; | |
1097 | }; | |
1098 | ||
1099 | /* number of elements for various memory pools */ | |
1100 | #define ZFCP_POOL_FSF_REQ_ERP_NR 1 | |
1101 | #define ZFCP_POOL_FSF_REQ_SCSI_NR 1 | |
1102 | #define ZFCP_POOL_FSF_REQ_ABORT_NR 1 | |
1103 | #define ZFCP_POOL_STATUS_READ_NR ZFCP_STATUS_READS_RECOM | |
1104 | #define ZFCP_POOL_DATA_GID_PN_NR 1 | |
1105 | ||
1106 | /* struct used by memory pools for fsf_requests */ | |
dd52e0ea | 1107 | struct zfcp_fsf_req_qtcb { |
1da177e4 LT |
1108 | struct zfcp_fsf_req fsf_req; |
1109 | struct fsf_qtcb qtcb; | |
1110 | }; | |
1111 | ||
1112 | /********************** ZFCP SPECIFIC DEFINES ********************************/ | |
1113 | ||
1da177e4 LT |
1114 | #define ZFCP_REQ_AUTO_CLEANUP 0x00000002 |
1115 | #define ZFCP_WAIT_FOR_SBAL 0x00000004 | |
1116 | #define ZFCP_REQ_NO_QTCB 0x00000008 | |
1117 | ||
1118 | #define ZFCP_SET 0x00000100 | |
1119 | #define ZFCP_CLEAR 0x00000200 | |
1120 | ||
1da177e4 LT |
1121 | #ifndef atomic_test_mask |
1122 | #define atomic_test_mask(mask, target) \ | |
1123 | ((atomic_read(target) & mask) == mask) | |
1124 | #endif | |
1125 | ||
1126 | extern void _zfcp_hex_dump(char *, int); | |
1127 | #define ZFCP_HEX_DUMP(level, addr, count) \ | |
1128 | if (ZFCP_LOG_CHECK(level)) { \ | |
1129 | _zfcp_hex_dump(addr, count); \ | |
1130 | } | |
1131 | ||
1132 | #define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id) | |
1133 | #define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter)) | |
1134 | #define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port)) | |
1135 | ||
ca2d02c2 HC |
1136 | /* |
1137 | * Helper functions for request ID management. | |
1138 | */ | |
1139 | static inline int zfcp_reqlist_hash(unsigned long req_id) | |
1140 | { | |
1141 | return req_id % REQUEST_LIST_SIZE; | |
1142 | } | |
1143 | ||
1144 | static inline void zfcp_reqlist_add(struct zfcp_adapter *adapter, | |
1145 | struct zfcp_fsf_req *fsf_req) | |
1146 | { | |
1147 | unsigned int idx; | |
1148 | ||
1149 | idx = zfcp_reqlist_hash(fsf_req->req_id); | |
1150 | list_add_tail(&fsf_req->list, &adapter->req_list[idx]); | |
1151 | } | |
1152 | ||
1153 | static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter, | |
1154 | struct zfcp_fsf_req *fsf_req) | |
1155 | { | |
1156 | list_del(&fsf_req->list); | |
1157 | } | |
1158 | ||
1159 | static inline struct zfcp_fsf_req * | |
1160 | zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id) | |
1161 | { | |
1162 | struct zfcp_fsf_req *request; | |
1163 | unsigned int idx; | |
1164 | ||
1165 | idx = zfcp_reqlist_hash(req_id); | |
1166 | list_for_each_entry(request, &adapter->req_list[idx], list) | |
1167 | if (request->req_id == req_id) | |
1168 | return request; | |
1169 | return NULL; | |
1170 | } | |
1171 | ||
d1ad09db HC |
1172 | static inline struct zfcp_fsf_req * |
1173 | zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req) | |
1174 | { | |
1175 | struct zfcp_fsf_req *request; | |
1176 | unsigned int idx; | |
1177 | ||
1178 | for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) { | |
1179 | list_for_each_entry(request, &adapter->req_list[idx], list) | |
1180 | if (request == req) | |
1181 | return request; | |
1182 | } | |
1183 | return NULL; | |
1184 | } | |
1185 | ||
1da177e4 LT |
1186 | /* |
1187 | * functions needed for reference/usage counting | |
1188 | */ | |
1189 | ||
1190 | static inline void | |
1191 | zfcp_unit_get(struct zfcp_unit *unit) | |
1192 | { | |
1193 | atomic_inc(&unit->refcount); | |
1194 | } | |
1195 | ||
1196 | static inline void | |
1197 | zfcp_unit_put(struct zfcp_unit *unit) | |
1198 | { | |
1199 | if (atomic_dec_return(&unit->refcount) == 0) | |
1200 | wake_up(&unit->remove_wq); | |
1201 | } | |
1202 | ||
1203 | static inline void | |
1204 | zfcp_unit_wait(struct zfcp_unit *unit) | |
1205 | { | |
1206 | wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0); | |
1207 | } | |
1208 | ||
1209 | static inline void | |
1210 | zfcp_port_get(struct zfcp_port *port) | |
1211 | { | |
1212 | atomic_inc(&port->refcount); | |
1213 | } | |
1214 | ||
1215 | static inline void | |
1216 | zfcp_port_put(struct zfcp_port *port) | |
1217 | { | |
1218 | if (atomic_dec_return(&port->refcount) == 0) | |
1219 | wake_up(&port->remove_wq); | |
1220 | } | |
1221 | ||
1222 | static inline void | |
1223 | zfcp_port_wait(struct zfcp_port *port) | |
1224 | { | |
1225 | wait_event(port->remove_wq, atomic_read(&port->refcount) == 0); | |
1226 | } | |
1227 | ||
1228 | static inline void | |
1229 | zfcp_adapter_get(struct zfcp_adapter *adapter) | |
1230 | { | |
1231 | atomic_inc(&adapter->refcount); | |
1232 | } | |
1233 | ||
1234 | static inline void | |
1235 | zfcp_adapter_put(struct zfcp_adapter *adapter) | |
1236 | { | |
1237 | if (atomic_dec_return(&adapter->refcount) == 0) | |
1238 | wake_up(&adapter->remove_wq); | |
1239 | } | |
1240 | ||
1241 | static inline void | |
1242 | zfcp_adapter_wait(struct zfcp_adapter *adapter) | |
1243 | { | |
1244 | wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0); | |
1245 | } | |
1246 | ||
1247 | #endif /* ZFCP_DEF_H */ |