4 * Implementation of FSF commands.
6 * Copyright IBM Corporation 2002, 2010
9 #define KMSG_COMPONENT "zfcp"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/blktrace_api.h>
13 #include <linux/slab.h>
14 #include <scsi/fc/fc_els.h>
18 #include "zfcp_qdio.h"
19 #include "zfcp_reqlist.h"
21 static void zfcp_fsf_request_timeout_handler(unsigned long data
)
23 struct zfcp_adapter
*adapter
= (struct zfcp_adapter
*) data
;
24 zfcp_erp_adapter_reopen(adapter
, ZFCP_STATUS_COMMON_ERP_FAILED
,
28 static void zfcp_fsf_start_timer(struct zfcp_fsf_req
*fsf_req
,
29 unsigned long timeout
)
31 fsf_req
->timer
.function
= zfcp_fsf_request_timeout_handler
;
32 fsf_req
->timer
.data
= (unsigned long) fsf_req
->adapter
;
33 fsf_req
->timer
.expires
= jiffies
+ timeout
;
34 add_timer(&fsf_req
->timer
);
37 static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req
*fsf_req
)
39 BUG_ON(!fsf_req
->erp_action
);
40 fsf_req
->timer
.function
= zfcp_erp_timeout_handler
;
41 fsf_req
->timer
.data
= (unsigned long) fsf_req
->erp_action
;
42 fsf_req
->timer
.expires
= jiffies
+ 30 * HZ
;
43 add_timer(&fsf_req
->timer
);
46 /* association between FSF command and FSF QTCB type */
47 static u32 fsf_qtcb_type
[] = {
48 [FSF_QTCB_FCP_CMND
] = FSF_IO_COMMAND
,
49 [FSF_QTCB_ABORT_FCP_CMND
] = FSF_SUPPORT_COMMAND
,
50 [FSF_QTCB_OPEN_PORT_WITH_DID
] = FSF_SUPPORT_COMMAND
,
51 [FSF_QTCB_OPEN_LUN
] = FSF_SUPPORT_COMMAND
,
52 [FSF_QTCB_CLOSE_LUN
] = FSF_SUPPORT_COMMAND
,
53 [FSF_QTCB_CLOSE_PORT
] = FSF_SUPPORT_COMMAND
,
54 [FSF_QTCB_CLOSE_PHYSICAL_PORT
] = FSF_SUPPORT_COMMAND
,
55 [FSF_QTCB_SEND_ELS
] = FSF_SUPPORT_COMMAND
,
56 [FSF_QTCB_SEND_GENERIC
] = FSF_SUPPORT_COMMAND
,
57 [FSF_QTCB_EXCHANGE_CONFIG_DATA
] = FSF_CONFIG_COMMAND
,
58 [FSF_QTCB_EXCHANGE_PORT_DATA
] = FSF_PORT_COMMAND
,
59 [FSF_QTCB_DOWNLOAD_CONTROL_FILE
] = FSF_SUPPORT_COMMAND
,
60 [FSF_QTCB_UPLOAD_CONTROL_FILE
] = FSF_SUPPORT_COMMAND
63 static void zfcp_act_eval_err(struct zfcp_adapter
*adapter
, u32 table
)
65 u16 subtable
= table
>> 16;
66 u16 rule
= table
& 0xffff;
67 const char *act_type
[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
69 if (subtable
&& subtable
< ARRAY_SIZE(act_type
))
70 dev_warn(&adapter
->ccw_device
->dev
,
71 "Access denied according to ACT rule type %s, "
72 "rule %d\n", act_type
[subtable
], rule
);
75 static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req
*req
,
76 struct zfcp_port
*port
)
78 struct fsf_qtcb_header
*header
= &req
->qtcb
->header
;
79 dev_warn(&req
->adapter
->ccw_device
->dev
,
80 "Access denied to port 0x%016Lx\n",
81 (unsigned long long)port
->wwpn
);
82 zfcp_act_eval_err(req
->adapter
, header
->fsf_status_qual
.halfword
[0]);
83 zfcp_act_eval_err(req
->adapter
, header
->fsf_status_qual
.halfword
[1]);
84 zfcp_erp_port_access_denied(port
, "fspad_1", req
);
85 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
88 static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req
*req
,
89 struct zfcp_unit
*unit
)
91 struct fsf_qtcb_header
*header
= &req
->qtcb
->header
;
92 dev_warn(&req
->adapter
->ccw_device
->dev
,
93 "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
94 (unsigned long long)unit
->fcp_lun
,
95 (unsigned long long)unit
->port
->wwpn
);
96 zfcp_act_eval_err(req
->adapter
, header
->fsf_status_qual
.halfword
[0]);
97 zfcp_act_eval_err(req
->adapter
, header
->fsf_status_qual
.halfword
[1]);
98 zfcp_erp_unit_access_denied(unit
, "fsuad_1", req
);
99 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
102 static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req
*req
)
104 dev_err(&req
->adapter
->ccw_device
->dev
, "FCP device not "
105 "operational because of an unsupported FC class\n");
106 zfcp_erp_adapter_shutdown(req
->adapter
, 0, "fscns_1", req
);
107 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
111 * zfcp_fsf_req_free - free memory used by fsf request
112 * @fsf_req: pointer to struct zfcp_fsf_req
114 void zfcp_fsf_req_free(struct zfcp_fsf_req
*req
)
116 if (likely(req
->pool
)) {
117 if (likely(req
->qtcb
))
118 mempool_free(req
->qtcb
, req
->adapter
->pool
.qtcb_pool
);
119 mempool_free(req
, req
->pool
);
123 if (likely(req
->qtcb
))
124 kmem_cache_free(zfcp_data
.qtcb_cache
, req
->qtcb
);
128 static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req
*req
)
131 struct fsf_status_read_buffer
*sr_buf
= req
->data
;
132 struct zfcp_adapter
*adapter
= req
->adapter
;
133 struct zfcp_port
*port
;
134 int d_id
= ntoh24(sr_buf
->d_id
);
136 read_lock_irqsave(&adapter
->port_list_lock
, flags
);
137 list_for_each_entry(port
, &adapter
->port_list
, list
)
138 if (port
->d_id
== d_id
) {
139 zfcp_erp_port_reopen(port
, 0, "fssrpc1", req
);
142 read_unlock_irqrestore(&adapter
->port_list_lock
, flags
);
145 static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req
*req
, char *id
,
146 struct fsf_link_down_info
*link_down
)
148 struct zfcp_adapter
*adapter
= req
->adapter
;
150 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
)
153 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
, &adapter
->status
);
155 zfcp_scsi_schedule_rports_block(adapter
);
160 switch (link_down
->error_code
) {
161 case FSF_PSQ_LINK_NO_LIGHT
:
162 dev_warn(&req
->adapter
->ccw_device
->dev
,
163 "There is no light signal from the local "
164 "fibre channel cable\n");
166 case FSF_PSQ_LINK_WRAP_PLUG
:
167 dev_warn(&req
->adapter
->ccw_device
->dev
,
168 "There is a wrap plug instead of a fibre "
171 case FSF_PSQ_LINK_NO_FCP
:
172 dev_warn(&req
->adapter
->ccw_device
->dev
,
173 "The adjacent fibre channel node does not "
176 case FSF_PSQ_LINK_FIRMWARE_UPDATE
:
177 dev_warn(&req
->adapter
->ccw_device
->dev
,
178 "The FCP device is suspended because of a "
179 "firmware update\n");
181 case FSF_PSQ_LINK_INVALID_WWPN
:
182 dev_warn(&req
->adapter
->ccw_device
->dev
,
183 "The FCP device detected a WWPN that is "
184 "duplicate or not valid\n");
186 case FSF_PSQ_LINK_NO_NPIV_SUPPORT
:
187 dev_warn(&req
->adapter
->ccw_device
->dev
,
188 "The fibre channel fabric does not support NPIV\n");
190 case FSF_PSQ_LINK_NO_FCP_RESOURCES
:
191 dev_warn(&req
->adapter
->ccw_device
->dev
,
192 "The FCP adapter cannot support more NPIV ports\n");
194 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES
:
195 dev_warn(&req
->adapter
->ccw_device
->dev
,
196 "The adjacent switch cannot support "
197 "more NPIV ports\n");
199 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE
:
200 dev_warn(&req
->adapter
->ccw_device
->dev
,
201 "The FCP adapter could not log in to the "
202 "fibre channel fabric\n");
204 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED
:
205 dev_warn(&req
->adapter
->ccw_device
->dev
,
206 "The WWPN assignment file on the FCP adapter "
207 "has been damaged\n");
209 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED
:
210 dev_warn(&req
->adapter
->ccw_device
->dev
,
211 "The mode table on the FCP adapter "
212 "has been damaged\n");
214 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT
:
215 dev_warn(&req
->adapter
->ccw_device
->dev
,
216 "All NPIV ports on the FCP adapter have "
220 dev_warn(&req
->adapter
->ccw_device
->dev
,
221 "The link between the FCP adapter and "
222 "the FC fabric is down\n");
225 zfcp_erp_adapter_failed(adapter
, id
, req
);
228 static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req
*req
)
230 struct fsf_status_read_buffer
*sr_buf
= req
->data
;
231 struct fsf_link_down_info
*ldi
=
232 (struct fsf_link_down_info
*) &sr_buf
->payload
;
234 switch (sr_buf
->status_subtype
) {
235 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK
:
236 zfcp_fsf_link_down_info_eval(req
, "fssrld1", ldi
);
238 case FSF_STATUS_READ_SUB_FDISC_FAILED
:
239 zfcp_fsf_link_down_info_eval(req
, "fssrld2", ldi
);
241 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE
:
242 zfcp_fsf_link_down_info_eval(req
, "fssrld3", NULL
);
246 static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req
*req
)
248 struct zfcp_adapter
*adapter
= req
->adapter
;
249 struct fsf_status_read_buffer
*sr_buf
= req
->data
;
251 if (req
->status
& ZFCP_STATUS_FSFREQ_DISMISSED
) {
252 zfcp_dbf_hba_fsf_unsol("dism", adapter
->dbf
, sr_buf
);
253 mempool_free(sr_buf
, adapter
->pool
.status_read_data
);
254 zfcp_fsf_req_free(req
);
258 zfcp_dbf_hba_fsf_unsol("read", adapter
->dbf
, sr_buf
);
260 switch (sr_buf
->status_type
) {
261 case FSF_STATUS_READ_PORT_CLOSED
:
262 zfcp_fsf_status_read_port_closed(req
);
264 case FSF_STATUS_READ_INCOMING_ELS
:
265 zfcp_fc_incoming_els(req
);
267 case FSF_STATUS_READ_SENSE_DATA_AVAIL
:
269 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD
:
270 dev_warn(&adapter
->ccw_device
->dev
,
271 "The error threshold for checksum statistics "
272 "has been exceeded\n");
273 zfcp_dbf_hba_berr(adapter
->dbf
, req
);
275 case FSF_STATUS_READ_LINK_DOWN
:
276 zfcp_fsf_status_read_link_down(req
);
278 case FSF_STATUS_READ_LINK_UP
:
279 dev_info(&adapter
->ccw_device
->dev
,
280 "The local link has been restored\n");
281 /* All ports should be marked as ready to run again */
282 zfcp_erp_modify_adapter_status(adapter
, "fssrh_1", NULL
,
283 ZFCP_STATUS_COMMON_RUNNING
,
285 zfcp_erp_adapter_reopen(adapter
,
286 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
|
287 ZFCP_STATUS_COMMON_ERP_FAILED
,
290 case FSF_STATUS_READ_NOTIFICATION_LOST
:
291 if (sr_buf
->status_subtype
& FSF_STATUS_READ_SUB_ACT_UPDATED
)
292 zfcp_erp_adapter_access_changed(adapter
, "fssrh_3",
294 if (sr_buf
->status_subtype
& FSF_STATUS_READ_SUB_INCOMING_ELS
)
295 queue_work(adapter
->work_queue
, &adapter
->scan_work
);
297 case FSF_STATUS_READ_CFDC_UPDATED
:
298 zfcp_erp_adapter_access_changed(adapter
, "fssrh_4", req
);
300 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT
:
301 adapter
->adapter_features
= sr_buf
->payload
.word
[0];
305 mempool_free(sr_buf
, adapter
->pool
.status_read_data
);
306 zfcp_fsf_req_free(req
);
308 atomic_inc(&adapter
->stat_miss
);
309 queue_work(adapter
->work_queue
, &adapter
->stat_work
);
312 static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req
*req
)
314 switch (req
->qtcb
->header
.fsf_status_qual
.word
[0]) {
315 case FSF_SQ_FCP_RSP_AVAILABLE
:
316 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE
:
317 case FSF_SQ_NO_RETRY_POSSIBLE
:
318 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED
:
320 case FSF_SQ_COMMAND_ABORTED
:
322 case FSF_SQ_NO_RECOM
:
323 dev_err(&req
->adapter
->ccw_device
->dev
,
324 "The FCP adapter reported a problem "
325 "that cannot be recovered\n");
326 zfcp_erp_adapter_shutdown(req
->adapter
, 0, "fsfsqe1", req
);
329 /* all non-return stats set FSFREQ_ERROR*/
330 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
333 static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req
*req
)
335 if (unlikely(req
->status
& ZFCP_STATUS_FSFREQ_ERROR
))
338 switch (req
->qtcb
->header
.fsf_status
) {
339 case FSF_UNKNOWN_COMMAND
:
340 dev_err(&req
->adapter
->ccw_device
->dev
,
341 "The FCP adapter does not recognize the command 0x%x\n",
342 req
->qtcb
->header
.fsf_command
);
343 zfcp_erp_adapter_shutdown(req
->adapter
, 0, "fsfse_1", req
);
344 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
346 case FSF_ADAPTER_STATUS_AVAILABLE
:
347 zfcp_fsf_fsfstatus_qual_eval(req
);
352 static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req
*req
)
354 struct zfcp_adapter
*adapter
= req
->adapter
;
355 struct fsf_qtcb
*qtcb
= req
->qtcb
;
356 union fsf_prot_status_qual
*psq
= &qtcb
->prefix
.prot_status_qual
;
358 zfcp_dbf_hba_fsf_response(req
);
360 if (req
->status
& ZFCP_STATUS_FSFREQ_DISMISSED
) {
361 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
365 switch (qtcb
->prefix
.prot_status
) {
367 case FSF_PROT_FSF_STATUS_PRESENTED
:
369 case FSF_PROT_QTCB_VERSION_ERROR
:
370 dev_err(&adapter
->ccw_device
->dev
,
371 "QTCB version 0x%x not supported by FCP adapter "
372 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION
,
373 psq
->word
[0], psq
->word
[1]);
374 zfcp_erp_adapter_shutdown(adapter
, 0, "fspse_1", req
);
376 case FSF_PROT_ERROR_STATE
:
377 case FSF_PROT_SEQ_NUMB_ERROR
:
378 zfcp_erp_adapter_reopen(adapter
, 0, "fspse_2", req
);
379 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
381 case FSF_PROT_UNSUPP_QTCB_TYPE
:
382 dev_err(&adapter
->ccw_device
->dev
,
383 "The QTCB type is not supported by the FCP adapter\n");
384 zfcp_erp_adapter_shutdown(adapter
, 0, "fspse_3", req
);
386 case FSF_PROT_HOST_CONNECTION_INITIALIZING
:
387 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
390 case FSF_PROT_DUPLICATE_REQUEST_ID
:
391 dev_err(&adapter
->ccw_device
->dev
,
392 "0x%Lx is an ambiguous request identifier\n",
393 (unsigned long long)qtcb
->bottom
.support
.req_handle
);
394 zfcp_erp_adapter_shutdown(adapter
, 0, "fspse_4", req
);
396 case FSF_PROT_LINK_DOWN
:
397 zfcp_fsf_link_down_info_eval(req
, "fspse_5",
398 &psq
->link_down_info
);
399 /* go through reopen to flush pending requests */
400 zfcp_erp_adapter_reopen(adapter
, 0, "fspse_6", req
);
402 case FSF_PROT_REEST_QUEUE
:
403 /* All ports should be marked as ready to run again */
404 zfcp_erp_modify_adapter_status(adapter
, "fspse_7", NULL
,
405 ZFCP_STATUS_COMMON_RUNNING
,
407 zfcp_erp_adapter_reopen(adapter
,
408 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
|
409 ZFCP_STATUS_COMMON_ERP_FAILED
,
413 dev_err(&adapter
->ccw_device
->dev
,
414 "0x%x is not a valid transfer protocol status\n",
415 qtcb
->prefix
.prot_status
);
416 zfcp_erp_adapter_shutdown(adapter
, 0, "fspse_9", req
);
418 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
422 * zfcp_fsf_req_complete - process completion of a FSF request
423 * @fsf_req: The FSF request that has been completed.
425 * When a request has been completed either from the FCP adapter,
426 * or it has been dismissed due to a queue shutdown, this function
427 * is called to process the completion status and trigger further
428 * events related to the FSF request.
430 static void zfcp_fsf_req_complete(struct zfcp_fsf_req
*req
)
432 if (unlikely(req
->fsf_command
== FSF_QTCB_UNSOLICITED_STATUS
)) {
433 zfcp_fsf_status_read_handler(req
);
437 del_timer(&req
->timer
);
438 zfcp_fsf_protstatus_eval(req
);
439 zfcp_fsf_fsfstatus_eval(req
);
443 zfcp_erp_notify(req
->erp_action
, 0);
445 if (likely(req
->status
& ZFCP_STATUS_FSFREQ_CLEANUP
))
446 zfcp_fsf_req_free(req
);
448 complete(&req
->completion
);
452 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
453 * @adapter: pointer to struct zfcp_adapter
455 * Never ever call this without shutting down the adapter first.
456 * Otherwise the adapter would continue using and corrupting s390 storage.
457 * Included BUG_ON() call to ensure this is done.
458 * ERP is supposed to be the only user of this function.
460 void zfcp_fsf_req_dismiss_all(struct zfcp_adapter
*adapter
)
462 struct zfcp_fsf_req
*req
, *tmp
;
463 LIST_HEAD(remove_queue
);
465 BUG_ON(atomic_read(&adapter
->status
) & ZFCP_STATUS_ADAPTER_QDIOUP
);
466 zfcp_reqlist_move(adapter
->req_list
, &remove_queue
);
468 list_for_each_entry_safe(req
, tmp
, &remove_queue
, list
) {
469 list_del(&req
->list
);
470 req
->status
|= ZFCP_STATUS_FSFREQ_DISMISSED
;
471 zfcp_fsf_req_complete(req
);
475 static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req
*req
)
477 struct fsf_qtcb_bottom_config
*bottom
= &req
->qtcb
->bottom
.config
;
478 struct zfcp_adapter
*adapter
= req
->adapter
;
479 struct Scsi_Host
*shost
= adapter
->scsi_host
;
480 struct fc_els_flogi
*nsp
, *plogi
;
482 /* adjust pointers for missing command code */
483 nsp
= (struct fc_els_flogi
*) ((u8
*)&bottom
->nport_serv_param
485 plogi
= (struct fc_els_flogi
*) ((u8
*)&bottom
->plogi_payload
489 memcpy(req
->data
, bottom
, sizeof(*bottom
));
491 fc_host_port_name(shost
) = nsp
->fl_wwpn
;
492 fc_host_node_name(shost
) = nsp
->fl_wwnn
;
493 fc_host_port_id(shost
) = ntoh24(bottom
->s_id
);
494 fc_host_speed(shost
) = bottom
->fc_link_speed
;
495 fc_host_supported_classes(shost
) = FC_COS_CLASS2
| FC_COS_CLASS3
;
497 adapter
->hydra_version
= bottom
->adapter_type
;
498 adapter
->timer_ticks
= bottom
->timer_interval
;
500 if (fc_host_permanent_port_name(shost
) == -1)
501 fc_host_permanent_port_name(shost
) = fc_host_port_name(shost
);
503 switch (bottom
->fc_topology
) {
505 adapter
->peer_d_id
= ntoh24(bottom
->peer_d_id
);
506 adapter
->peer_wwpn
= plogi
->fl_wwpn
;
507 adapter
->peer_wwnn
= plogi
->fl_wwnn
;
508 fc_host_port_type(shost
) = FC_PORTTYPE_PTP
;
510 case FSF_TOPO_FABRIC
:
511 fc_host_port_type(shost
) = FC_PORTTYPE_NPORT
;
514 fc_host_port_type(shost
) = FC_PORTTYPE_NLPORT
;
517 dev_err(&adapter
->ccw_device
->dev
,
518 "Unknown or unsupported arbitrated loop "
519 "fibre channel topology detected\n");
520 zfcp_erp_adapter_shutdown(adapter
, 0, "fsece_1", req
);
527 static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req
*req
)
529 struct zfcp_adapter
*adapter
= req
->adapter
;
530 struct fsf_qtcb
*qtcb
= req
->qtcb
;
531 struct fsf_qtcb_bottom_config
*bottom
= &qtcb
->bottom
.config
;
532 struct Scsi_Host
*shost
= adapter
->scsi_host
;
534 if (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
)
537 adapter
->fsf_lic_version
= bottom
->lic_version
;
538 adapter
->adapter_features
= bottom
->adapter_features
;
539 adapter
->connection_features
= bottom
->connection_features
;
540 adapter
->peer_wwpn
= 0;
541 adapter
->peer_wwnn
= 0;
542 adapter
->peer_d_id
= 0;
544 switch (qtcb
->header
.fsf_status
) {
546 if (zfcp_fsf_exchange_config_evaluate(req
))
549 if (bottom
->max_qtcb_size
< sizeof(struct fsf_qtcb
)) {
550 dev_err(&adapter
->ccw_device
->dev
,
551 "FCP adapter maximum QTCB size (%d bytes) "
553 bottom
->max_qtcb_size
);
554 zfcp_erp_adapter_shutdown(adapter
, 0, "fsecdh1", req
);
557 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK
,
560 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE
:
561 fc_host_node_name(shost
) = 0;
562 fc_host_port_name(shost
) = 0;
563 fc_host_port_id(shost
) = 0;
564 fc_host_speed(shost
) = FC_PORTSPEED_UNKNOWN
;
565 fc_host_port_type(shost
) = FC_PORTTYPE_UNKNOWN
;
566 adapter
->hydra_version
= 0;
568 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK
,
571 zfcp_fsf_link_down_info_eval(req
, "fsecdh2",
572 &qtcb
->header
.fsf_status_qual
.link_down_info
);
575 zfcp_erp_adapter_shutdown(adapter
, 0, "fsecdh3", req
);
579 if (adapter
->adapter_features
& FSF_FEATURE_HBAAPI_MANAGEMENT
) {
580 adapter
->hardware_version
= bottom
->hardware_version
;
581 memcpy(fc_host_serial_number(shost
), bottom
->serial_number
,
582 min(FC_SERIAL_NUMBER_SIZE
, 17));
583 EBCASC(fc_host_serial_number(shost
),
584 min(FC_SERIAL_NUMBER_SIZE
, 17));
587 if (FSF_QTCB_CURRENT_VERSION
< bottom
->low_qtcb_version
) {
588 dev_err(&adapter
->ccw_device
->dev
,
589 "The FCP adapter only supports newer "
590 "control block versions\n");
591 zfcp_erp_adapter_shutdown(adapter
, 0, "fsecdh4", req
);
594 if (FSF_QTCB_CURRENT_VERSION
> bottom
->high_qtcb_version
) {
595 dev_err(&adapter
->ccw_device
->dev
,
596 "The FCP adapter only supports older "
597 "control block versions\n");
598 zfcp_erp_adapter_shutdown(adapter
, 0, "fsecdh5", req
);
602 static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req
*req
)
604 struct zfcp_adapter
*adapter
= req
->adapter
;
605 struct fsf_qtcb_bottom_port
*bottom
= &req
->qtcb
->bottom
.port
;
606 struct Scsi_Host
*shost
= adapter
->scsi_host
;
609 memcpy(req
->data
, bottom
, sizeof(*bottom
));
611 if (adapter
->connection_features
& FSF_FEATURE_NPIV_MODE
) {
612 fc_host_permanent_port_name(shost
) = bottom
->wwpn
;
613 fc_host_port_type(shost
) = FC_PORTTYPE_NPIV
;
615 fc_host_permanent_port_name(shost
) = fc_host_port_name(shost
);
616 fc_host_maxframe_size(shost
) = bottom
->maximum_frame_size
;
617 fc_host_supported_speeds(shost
) = bottom
->supported_speed
;
618 memcpy(fc_host_supported_fc4s(shost
), bottom
->supported_fc4_types
,
620 memcpy(fc_host_active_fc4s(shost
), bottom
->active_fc4_types
,
624 static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req
*req
)
626 struct fsf_qtcb
*qtcb
= req
->qtcb
;
628 if (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
)
631 switch (qtcb
->header
.fsf_status
) {
633 zfcp_fsf_exchange_port_evaluate(req
);
635 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE
:
636 zfcp_fsf_exchange_port_evaluate(req
);
637 zfcp_fsf_link_down_info_eval(req
, "fsepdh1",
638 &qtcb
->header
.fsf_status_qual
.link_down_info
);
643 static int zfcp_fsf_sbal_check(struct zfcp_qdio
*qdio
)
645 struct zfcp_qdio_queue
*req_q
= &qdio
->req_q
;
647 spin_lock_bh(&qdio
->req_q_lock
);
648 if (atomic_read(&req_q
->count
))
650 spin_unlock_bh(&qdio
->req_q_lock
);
654 static int zfcp_fsf_req_sbal_get(struct zfcp_qdio
*qdio
)
656 struct zfcp_adapter
*adapter
= qdio
->adapter
;
659 spin_unlock_bh(&qdio
->req_q_lock
);
660 ret
= wait_event_interruptible_timeout(qdio
->req_q_wq
,
661 zfcp_fsf_sbal_check(qdio
), 5 * HZ
);
665 atomic_inc(&qdio
->req_q_full
);
666 /* assume hanging outbound queue, try queue recovery */
667 zfcp_erp_adapter_reopen(adapter
, 0, "fsrsg_1", NULL
);
670 spin_lock_bh(&qdio
->req_q_lock
);
674 static struct zfcp_fsf_req
*zfcp_fsf_alloc(mempool_t
*pool
)
676 struct zfcp_fsf_req
*req
;
679 req
= mempool_alloc(pool
, GFP_ATOMIC
);
681 req
= kmalloc(sizeof(*req
), GFP_ATOMIC
);
686 memset(req
, 0, sizeof(*req
));
691 static struct fsf_qtcb
*zfcp_qtcb_alloc(mempool_t
*pool
)
693 struct fsf_qtcb
*qtcb
;
696 qtcb
= mempool_alloc(pool
, GFP_ATOMIC
);
698 qtcb
= kmem_cache_alloc(zfcp_data
.qtcb_cache
, GFP_ATOMIC
);
703 memset(qtcb
, 0, sizeof(*qtcb
));
707 static struct zfcp_fsf_req
*zfcp_fsf_req_create(struct zfcp_qdio
*qdio
,
708 u32 fsf_cmd
, mempool_t
*pool
)
710 struct qdio_buffer_element
*sbale
;
711 struct zfcp_qdio_queue
*req_q
= &qdio
->req_q
;
712 struct zfcp_adapter
*adapter
= qdio
->adapter
;
713 struct zfcp_fsf_req
*req
= zfcp_fsf_alloc(pool
);
716 return ERR_PTR(-ENOMEM
);
718 if (adapter
->req_no
== 0)
721 INIT_LIST_HEAD(&req
->list
);
722 init_timer(&req
->timer
);
723 init_completion(&req
->completion
);
725 req
->adapter
= adapter
;
726 req
->fsf_command
= fsf_cmd
;
727 req
->req_id
= adapter
->req_no
;
728 req
->qdio_req
.sbal_number
= 1;
729 req
->qdio_req
.sbal_first
= req_q
->first
;
730 req
->qdio_req
.sbal_last
= req_q
->first
;
731 req
->qdio_req
.sbale_curr
= 1;
733 sbale
= zfcp_qdio_sbale_req(qdio
, &req
->qdio_req
);
734 sbale
[0].addr
= (void *) req
->req_id
;
735 sbale
[0].flags
|= SBAL_FLAGS0_COMMAND
;
737 if (likely(fsf_cmd
!= FSF_QTCB_UNSOLICITED_STATUS
)) {
739 req
->qtcb
= zfcp_qtcb_alloc(adapter
->pool
.qtcb_pool
);
741 req
->qtcb
= zfcp_qtcb_alloc(NULL
);
743 if (unlikely(!req
->qtcb
)) {
744 zfcp_fsf_req_free(req
);
745 return ERR_PTR(-ENOMEM
);
748 req
->seq_no
= adapter
->fsf_req_seq_no
;
749 req
->qtcb
->prefix
.req_seq_no
= adapter
->fsf_req_seq_no
;
750 req
->qtcb
->prefix
.req_id
= req
->req_id
;
751 req
->qtcb
->prefix
.ulp_info
= 26;
752 req
->qtcb
->prefix
.qtcb_type
= fsf_qtcb_type
[req
->fsf_command
];
753 req
->qtcb
->prefix
.qtcb_version
= FSF_QTCB_CURRENT_VERSION
;
754 req
->qtcb
->header
.req_handle
= req
->req_id
;
755 req
->qtcb
->header
.fsf_command
= req
->fsf_command
;
756 sbale
[1].addr
= (void *) req
->qtcb
;
757 sbale
[1].length
= sizeof(struct fsf_qtcb
);
760 if (!(atomic_read(&adapter
->status
) & ZFCP_STATUS_ADAPTER_QDIOUP
)) {
761 zfcp_fsf_req_free(req
);
762 return ERR_PTR(-EIO
);
768 static int zfcp_fsf_req_send(struct zfcp_fsf_req
*req
)
770 struct zfcp_adapter
*adapter
= req
->adapter
;
771 struct zfcp_qdio
*qdio
= adapter
->qdio
;
772 int with_qtcb
= (req
->qtcb
!= NULL
);
773 int req_id
= req
->req_id
;
775 zfcp_reqlist_add(adapter
->req_list
, req
);
777 req
->qdio_req
.qdio_outb_usage
= atomic_read(&qdio
->req_q
.count
);
778 req
->issued
= get_clock();
779 if (zfcp_qdio_send(qdio
, &req
->qdio_req
)) {
780 del_timer(&req
->timer
);
781 /* lookup request again, list might have changed */
782 zfcp_reqlist_find_rm(adapter
->req_list
, req_id
);
783 zfcp_erp_adapter_reopen(adapter
, 0, "fsrs__1", req
);
787 /* Don't increase for unsolicited status */
789 adapter
->fsf_req_seq_no
++;
796 * zfcp_fsf_status_read - send status read request
797 * @adapter: pointer to struct zfcp_adapter
798 * @req_flags: request flags
799 * Returns: 0 on success, ERROR otherwise
801 int zfcp_fsf_status_read(struct zfcp_qdio
*qdio
)
803 struct zfcp_adapter
*adapter
= qdio
->adapter
;
804 struct zfcp_fsf_req
*req
;
805 struct fsf_status_read_buffer
*sr_buf
;
806 struct qdio_buffer_element
*sbale
;
809 spin_lock_bh(&qdio
->req_q_lock
);
810 if (zfcp_fsf_req_sbal_get(qdio
))
813 req
= zfcp_fsf_req_create(qdio
, FSF_QTCB_UNSOLICITED_STATUS
,
814 adapter
->pool
.status_read_req
);
816 retval
= PTR_ERR(req
);
820 sbale
= zfcp_qdio_sbale_req(qdio
, &req
->qdio_req
);
821 sbale
[2].flags
|= SBAL_FLAGS_LAST_ENTRY
;
822 req
->qdio_req
.sbale_curr
= 2;
824 sr_buf
= mempool_alloc(adapter
->pool
.status_read_data
, GFP_ATOMIC
);
829 memset(sr_buf
, 0, sizeof(*sr_buf
));
831 sbale
= zfcp_qdio_sbale_curr(qdio
, &req
->qdio_req
);
832 sbale
->addr
= (void *) sr_buf
;
833 sbale
->length
= sizeof(*sr_buf
);
835 retval
= zfcp_fsf_req_send(req
);
837 goto failed_req_send
;
842 mempool_free(sr_buf
, adapter
->pool
.status_read_data
);
844 zfcp_fsf_req_free(req
);
845 zfcp_dbf_hba_fsf_unsol("fail", adapter
->dbf
, NULL
);
847 spin_unlock_bh(&qdio
->req_q_lock
);
851 static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req
*req
)
853 struct zfcp_unit
*unit
= req
->data
;
854 union fsf_status_qual
*fsq
= &req
->qtcb
->header
.fsf_status_qual
;
856 if (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
)
859 switch (req
->qtcb
->header
.fsf_status
) {
860 case FSF_PORT_HANDLE_NOT_VALID
:
861 if (fsq
->word
[0] == fsq
->word
[1]) {
862 zfcp_erp_adapter_reopen(unit
->port
->adapter
, 0,
864 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
867 case FSF_LUN_HANDLE_NOT_VALID
:
868 if (fsq
->word
[0] == fsq
->word
[1]) {
869 zfcp_erp_port_reopen(unit
->port
, 0, "fsafch2", req
);
870 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
873 case FSF_FCP_COMMAND_DOES_NOT_EXIST
:
874 req
->status
|= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED
;
877 zfcp_erp_port_boxed(unit
->port
, "fsafch3", req
);
878 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
881 zfcp_erp_unit_boxed(unit
, "fsafch4", req
);
882 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
884 case FSF_ADAPTER_STATUS_AVAILABLE
:
885 switch (fsq
->word
[0]) {
886 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE
:
887 zfcp_fc_test_link(unit
->port
);
889 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED
:
890 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
895 req
->status
|= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED
;
901 * zfcp_fsf_abort_fcp_command - abort running SCSI command
902 * @old_req_id: unsigned long
903 * @unit: pointer to struct zfcp_unit
904 * Returns: pointer to struct zfcp_fsf_req
907 struct zfcp_fsf_req
*zfcp_fsf_abort_fcp_command(unsigned long old_req_id
,
908 struct zfcp_unit
*unit
)
910 struct qdio_buffer_element
*sbale
;
911 struct zfcp_fsf_req
*req
= NULL
;
912 struct zfcp_qdio
*qdio
= unit
->port
->adapter
->qdio
;
914 spin_lock_bh(&qdio
->req_q_lock
);
915 if (zfcp_fsf_req_sbal_get(qdio
))
917 req
= zfcp_fsf_req_create(qdio
, FSF_QTCB_ABORT_FCP_CMND
,
918 qdio
->adapter
->pool
.scsi_abort
);
924 if (unlikely(!(atomic_read(&unit
->status
) &
925 ZFCP_STATUS_COMMON_UNBLOCKED
)))
928 sbale
= zfcp_qdio_sbale_req(qdio
, &req
->qdio_req
);
929 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_READ
;
930 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
933 req
->handler
= zfcp_fsf_abort_fcp_command_handler
;
934 req
->qtcb
->header
.lun_handle
= unit
->handle
;
935 req
->qtcb
->header
.port_handle
= unit
->port
->handle
;
936 req
->qtcb
->bottom
.support
.req_handle
= (u64
) old_req_id
;
938 zfcp_fsf_start_timer(req
, ZFCP_SCSI_ER_TIMEOUT
);
939 if (!zfcp_fsf_req_send(req
))
943 zfcp_fsf_req_free(req
);
946 spin_unlock_bh(&qdio
->req_q_lock
);
950 static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req
*req
)
952 struct zfcp_adapter
*adapter
= req
->adapter
;
953 struct zfcp_fsf_ct_els
*ct
= req
->data
;
954 struct fsf_qtcb_header
*header
= &req
->qtcb
->header
;
956 ct
->status
= -EINVAL
;
958 if (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
)
961 switch (header
->fsf_status
) {
963 zfcp_dbf_san_ct_response(req
);
966 case FSF_SERVICE_CLASS_NOT_SUPPORTED
:
967 zfcp_fsf_class_not_supp(req
);
969 case FSF_ADAPTER_STATUS_AVAILABLE
:
970 switch (header
->fsf_status_qual
.word
[0]){
971 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE
:
972 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED
:
973 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
977 case FSF_ACCESS_DENIED
:
980 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
982 case FSF_PORT_HANDLE_NOT_VALID
:
983 zfcp_erp_adapter_reopen(adapter
, 0, "fsscth1", req
);
985 case FSF_GENERIC_COMMAND_REJECTED
:
986 case FSF_PAYLOAD_SIZE_MISMATCH
:
987 case FSF_REQUEST_SIZE_TOO_LARGE
:
988 case FSF_RESPONSE_SIZE_TOO_LARGE
:
989 case FSF_SBAL_MISMATCH
:
990 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
996 ct
->handler(ct
->handler_data
);
999 static void zfcp_fsf_setup_ct_els_unchained(struct qdio_buffer_element
*sbale
,
1000 struct scatterlist
*sg_req
,
1001 struct scatterlist
*sg_resp
)
1003 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_WRITE_READ
;
1004 sbale
[2].addr
= sg_virt(sg_req
);
1005 sbale
[2].length
= sg_req
->length
;
1006 sbale
[3].addr
= sg_virt(sg_resp
);
1007 sbale
[3].length
= sg_resp
->length
;
1008 sbale
[3].flags
|= SBAL_FLAGS_LAST_ENTRY
;
1011 static int zfcp_fsf_one_sbal(struct scatterlist
*sg
)
1013 return sg_is_last(sg
) && sg
->length
<= PAGE_SIZE
;
1016 static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req
*req
,
1017 struct scatterlist
*sg_req
,
1018 struct scatterlist
*sg_resp
,
1021 struct zfcp_adapter
*adapter
= req
->adapter
;
1022 struct qdio_buffer_element
*sbale
= zfcp_qdio_sbale_req(adapter
->qdio
,
1024 u32 feat
= adapter
->adapter_features
;
1027 if (!(feat
& FSF_FEATURE_ELS_CT_CHAINED_SBALS
)) {
1028 if (!zfcp_fsf_one_sbal(sg_req
) || !zfcp_fsf_one_sbal(sg_resp
))
1031 zfcp_fsf_setup_ct_els_unchained(sbale
, sg_req
, sg_resp
);
1035 /* use single, unchained SBAL if it can hold the request */
1036 if (zfcp_fsf_one_sbal(sg_req
) && zfcp_fsf_one_sbal(sg_resp
)) {
1037 zfcp_fsf_setup_ct_els_unchained(sbale
, sg_req
, sg_resp
);
1041 bytes
= zfcp_qdio_sbals_from_sg(adapter
->qdio
, &req
->qdio_req
,
1042 SBAL_FLAGS0_TYPE_WRITE_READ
,
1046 req
->qtcb
->bottom
.support
.req_buf_length
= bytes
;
1047 req
->qdio_req
.sbale_curr
= ZFCP_LAST_SBALE_PER_SBAL
;
1049 bytes
= zfcp_qdio_sbals_from_sg(adapter
->qdio
, &req
->qdio_req
,
1050 SBAL_FLAGS0_TYPE_WRITE_READ
,
1051 sg_resp
, max_sbals
);
1052 req
->qtcb
->bottom
.support
.resp_buf_length
= bytes
;
1059 static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req
*req
,
1060 struct scatterlist
*sg_req
,
1061 struct scatterlist
*sg_resp
,
1062 int max_sbals
, unsigned int timeout
)
1066 ret
= zfcp_fsf_setup_ct_els_sbals(req
, sg_req
, sg_resp
, max_sbals
);
1070 /* common settings for ct/gs and els requests */
1072 timeout
= 255; /* max value accepted by hardware */
1073 req
->qtcb
->bottom
.support
.service_class
= FSF_CLASS_3
;
1074 req
->qtcb
->bottom
.support
.timeout
= timeout
;
1075 zfcp_fsf_start_timer(req
, (timeout
+ 10) * HZ
);
1081 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1082 * @ct: pointer to struct zfcp_send_ct with data for request
1083 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1085 int zfcp_fsf_send_ct(struct zfcp_fc_wka_port
*wka_port
,
1086 struct zfcp_fsf_ct_els
*ct
, mempool_t
*pool
,
1087 unsigned int timeout
)
1089 struct zfcp_qdio
*qdio
= wka_port
->adapter
->qdio
;
1090 struct zfcp_fsf_req
*req
;
1093 spin_lock_bh(&qdio
->req_q_lock
);
1094 if (zfcp_fsf_req_sbal_get(qdio
))
1097 req
= zfcp_fsf_req_create(qdio
, FSF_QTCB_SEND_GENERIC
, pool
);
1104 req
->status
|= ZFCP_STATUS_FSFREQ_CLEANUP
;
1105 ret
= zfcp_fsf_setup_ct_els(req
, ct
->req
, ct
->resp
,
1106 FSF_MAX_SBALS_PER_REQ
, timeout
);
1110 req
->handler
= zfcp_fsf_send_ct_handler
;
1111 req
->qtcb
->header
.port_handle
= wka_port
->handle
;
1114 zfcp_dbf_san_ct_request(req
, wka_port
->d_id
);
1116 ret
= zfcp_fsf_req_send(req
);
1123 zfcp_fsf_req_free(req
);
1125 spin_unlock_bh(&qdio
->req_q_lock
);
1129 static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req
*req
)
1131 struct zfcp_fsf_ct_els
*send_els
= req
->data
;
1132 struct zfcp_port
*port
= send_els
->port
;
1133 struct fsf_qtcb_header
*header
= &req
->qtcb
->header
;
1135 send_els
->status
= -EINVAL
;
1137 if (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
)
1138 goto skip_fsfstatus
;
1140 switch (header
->fsf_status
) {
1142 zfcp_dbf_san_els_response(req
);
1143 send_els
->status
= 0;
1145 case FSF_SERVICE_CLASS_NOT_SUPPORTED
:
1146 zfcp_fsf_class_not_supp(req
);
1148 case FSF_ADAPTER_STATUS_AVAILABLE
:
1149 switch (header
->fsf_status_qual
.word
[0]){
1150 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE
:
1151 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED
:
1152 case FSF_SQ_RETRY_IF_POSSIBLE
:
1153 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1157 case FSF_ELS_COMMAND_REJECTED
:
1158 case FSF_PAYLOAD_SIZE_MISMATCH
:
1159 case FSF_REQUEST_SIZE_TOO_LARGE
:
1160 case FSF_RESPONSE_SIZE_TOO_LARGE
:
1162 case FSF_ACCESS_DENIED
:
1164 zfcp_fsf_access_denied_port(req
, port
);
1166 case FSF_SBAL_MISMATCH
:
1167 /* should never occure, avoided in zfcp_fsf_send_els */
1170 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1174 if (send_els
->handler
)
1175 send_els
->handler(send_els
->handler_data
);
1179 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1180 * @els: pointer to struct zfcp_send_els with data for the command
1182 int zfcp_fsf_send_els(struct zfcp_adapter
*adapter
, u32 d_id
,
1183 struct zfcp_fsf_ct_els
*els
, unsigned int timeout
)
1185 struct zfcp_fsf_req
*req
;
1186 struct zfcp_qdio
*qdio
= adapter
->qdio
;
1189 spin_lock_bh(&qdio
->req_q_lock
);
1190 if (zfcp_fsf_req_sbal_get(qdio
))
1193 req
= zfcp_fsf_req_create(qdio
, FSF_QTCB_SEND_ELS
, NULL
);
1200 req
->status
|= ZFCP_STATUS_FSFREQ_CLEANUP
;
1201 ret
= zfcp_fsf_setup_ct_els(req
, els
->req
, els
->resp
, 2, timeout
);
1206 hton24(req
->qtcb
->bottom
.support
.d_id
, d_id
);
1207 req
->handler
= zfcp_fsf_send_els_handler
;
1210 zfcp_dbf_san_els_request(req
);
1212 ret
= zfcp_fsf_req_send(req
);
1219 zfcp_fsf_req_free(req
);
1221 spin_unlock_bh(&qdio
->req_q_lock
);
1225 int zfcp_fsf_exchange_config_data(struct zfcp_erp_action
*erp_action
)
1227 struct qdio_buffer_element
*sbale
;
1228 struct zfcp_fsf_req
*req
;
1229 struct zfcp_qdio
*qdio
= erp_action
->adapter
->qdio
;
1232 spin_lock_bh(&qdio
->req_q_lock
);
1233 if (zfcp_fsf_req_sbal_get(qdio
))
1236 req
= zfcp_fsf_req_create(qdio
, FSF_QTCB_EXCHANGE_CONFIG_DATA
,
1237 qdio
->adapter
->pool
.erp_req
);
1240 retval
= PTR_ERR(req
);
1244 req
->status
|= ZFCP_STATUS_FSFREQ_CLEANUP
;
1245 sbale
= zfcp_qdio_sbale_req(qdio
, &req
->qdio_req
);
1246 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_READ
;
1247 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
1249 req
->qtcb
->bottom
.config
.feature_selection
=
1251 FSF_FEATURE_LUN_SHARING
|
1252 FSF_FEATURE_NOTIFICATION_LOST
|
1253 FSF_FEATURE_UPDATE_ALERT
;
1254 req
->erp_action
= erp_action
;
1255 req
->handler
= zfcp_fsf_exchange_config_data_handler
;
1256 erp_action
->fsf_req_id
= req
->req_id
;
1258 zfcp_fsf_start_erp_timer(req
);
1259 retval
= zfcp_fsf_req_send(req
);
1261 zfcp_fsf_req_free(req
);
1262 erp_action
->fsf_req_id
= 0;
1265 spin_unlock_bh(&qdio
->req_q_lock
);
1269 int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio
*qdio
,
1270 struct fsf_qtcb_bottom_config
*data
)
1272 struct qdio_buffer_element
*sbale
;
1273 struct zfcp_fsf_req
*req
= NULL
;
1276 spin_lock_bh(&qdio
->req_q_lock
);
1277 if (zfcp_fsf_req_sbal_get(qdio
))
1280 req
= zfcp_fsf_req_create(qdio
, FSF_QTCB_EXCHANGE_CONFIG_DATA
, NULL
);
1283 retval
= PTR_ERR(req
);
1287 sbale
= zfcp_qdio_sbale_req(qdio
, &req
->qdio_req
);
1288 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_READ
;
1289 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
1290 req
->handler
= zfcp_fsf_exchange_config_data_handler
;
1292 req
->qtcb
->bottom
.config
.feature_selection
=
1294 FSF_FEATURE_LUN_SHARING
|
1295 FSF_FEATURE_NOTIFICATION_LOST
|
1296 FSF_FEATURE_UPDATE_ALERT
;
1301 zfcp_fsf_start_timer(req
, ZFCP_FSF_REQUEST_TIMEOUT
);
1302 retval
= zfcp_fsf_req_send(req
);
1303 spin_unlock_bh(&qdio
->req_q_lock
);
1305 wait_for_completion(&req
->completion
);
1307 zfcp_fsf_req_free(req
);
1311 spin_unlock_bh(&qdio
->req_q_lock
);
1316 * zfcp_fsf_exchange_port_data - request information about local port
1317 * @erp_action: ERP action for the adapter for which port data is requested
1318 * Returns: 0 on success, error otherwise
1320 int zfcp_fsf_exchange_port_data(struct zfcp_erp_action
*erp_action
)
1322 struct zfcp_qdio
*qdio
= erp_action
->adapter
->qdio
;
1323 struct qdio_buffer_element
*sbale
;
1324 struct zfcp_fsf_req
*req
;
1327 if (!(qdio
->adapter
->adapter_features
& FSF_FEATURE_HBAAPI_MANAGEMENT
))
1330 spin_lock_bh(&qdio
->req_q_lock
);
1331 if (zfcp_fsf_req_sbal_get(qdio
))
1334 req
= zfcp_fsf_req_create(qdio
, FSF_QTCB_EXCHANGE_PORT_DATA
,
1335 qdio
->adapter
->pool
.erp_req
);
1338 retval
= PTR_ERR(req
);
1342 req
->status
|= ZFCP_STATUS_FSFREQ_CLEANUP
;
1343 sbale
= zfcp_qdio_sbale_req(qdio
, &req
->qdio_req
);
1344 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_READ
;
1345 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
1347 req
->handler
= zfcp_fsf_exchange_port_data_handler
;
1348 req
->erp_action
= erp_action
;
1349 erp_action
->fsf_req_id
= req
->req_id
;
1351 zfcp_fsf_start_erp_timer(req
);
1352 retval
= zfcp_fsf_req_send(req
);
1354 zfcp_fsf_req_free(req
);
1355 erp_action
->fsf_req_id
= 0;
1358 spin_unlock_bh(&qdio
->req_q_lock
);
1363 * zfcp_fsf_exchange_port_data_sync - request information about local port
1364 * @qdio: pointer to struct zfcp_qdio
1365 * @data: pointer to struct fsf_qtcb_bottom_port
1366 * Returns: 0 on success, error otherwise
1368 int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio
*qdio
,
1369 struct fsf_qtcb_bottom_port
*data
)
1371 struct qdio_buffer_element
*sbale
;
1372 struct zfcp_fsf_req
*req
= NULL
;
1375 if (!(qdio
->adapter
->adapter_features
& FSF_FEATURE_HBAAPI_MANAGEMENT
))
1378 spin_lock_bh(&qdio
->req_q_lock
);
1379 if (zfcp_fsf_req_sbal_get(qdio
))
1382 req
= zfcp_fsf_req_create(qdio
, FSF_QTCB_EXCHANGE_PORT_DATA
, NULL
);
1385 retval
= PTR_ERR(req
);
1392 sbale
= zfcp_qdio_sbale_req(qdio
, &req
->qdio_req
);
1393 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_READ
;
1394 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
1396 req
->handler
= zfcp_fsf_exchange_port_data_handler
;
1397 zfcp_fsf_start_timer(req
, ZFCP_FSF_REQUEST_TIMEOUT
);
1398 retval
= zfcp_fsf_req_send(req
);
1399 spin_unlock_bh(&qdio
->req_q_lock
);
1402 wait_for_completion(&req
->completion
);
1404 zfcp_fsf_req_free(req
);
1409 spin_unlock_bh(&qdio
->req_q_lock
);
1413 static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req
*req
)
1415 struct zfcp_port
*port
= req
->data
;
1416 struct fsf_qtcb_header
*header
= &req
->qtcb
->header
;
1417 struct fc_els_flogi
*plogi
;
1419 if (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
)
1422 switch (header
->fsf_status
) {
1423 case FSF_PORT_ALREADY_OPEN
:
1425 case FSF_ACCESS_DENIED
:
1426 zfcp_fsf_access_denied_port(req
, port
);
1428 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED
:
1429 dev_warn(&req
->adapter
->ccw_device
->dev
,
1430 "Not enough FCP adapter resources to open "
1431 "remote port 0x%016Lx\n",
1432 (unsigned long long)port
->wwpn
);
1433 zfcp_erp_port_failed(port
, "fsoph_1", req
);
1434 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1436 case FSF_ADAPTER_STATUS_AVAILABLE
:
1437 switch (header
->fsf_status_qual
.word
[0]) {
1438 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE
:
1439 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED
:
1440 case FSF_SQ_NO_RETRY_POSSIBLE
:
1441 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1446 port
->handle
= header
->port_handle
;
1447 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN
|
1448 ZFCP_STATUS_PORT_PHYS_OPEN
, &port
->status
);
1449 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED
|
1450 ZFCP_STATUS_COMMON_ACCESS_BOXED
,
1452 /* check whether D_ID has changed during open */
1454 * FIXME: This check is not airtight, as the FCP channel does
1455 * not monitor closures of target port connections caused on
1456 * the remote side. Thus, they might miss out on invalidating
1457 * locally cached WWPNs (and other N_Port parameters) of gone
1458 * target ports. So, our heroic attempt to make things safe
1459 * could be undermined by 'open port' response data tagged with
1460 * obsolete WWPNs. Another reason to monitor potential
1461 * connection closures ourself at least (by interpreting
1462 * incoming ELS' and unsolicited status). It just crosses my
1463 * mind that one should be able to cross-check by means of
1464 * another GID_PN straight after a port has been opened.
1465 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1467 plogi
= (struct fc_els_flogi
*) req
->qtcb
->bottom
.support
.els
;
1468 if (req
->qtcb
->bottom
.support
.els1_length
>=
1470 zfcp_fc_plogi_evaluate(port
, plogi
);
1472 case FSF_UNKNOWN_OP_SUBTYPE
:
1473 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1478 put_device(&port
->dev
);
1482 * zfcp_fsf_open_port - create and send open port request
1483 * @erp_action: pointer to struct zfcp_erp_action
1484 * Returns: 0 on success, error otherwise
1486 int zfcp_fsf_open_port(struct zfcp_erp_action
*erp_action
)
1488 struct qdio_buffer_element
*sbale
;
1489 struct zfcp_qdio
*qdio
= erp_action
->adapter
->qdio
;
1490 struct zfcp_port
*port
= erp_action
->port
;
1491 struct zfcp_fsf_req
*req
;
1494 spin_lock_bh(&qdio
->req_q_lock
);
1495 if (zfcp_fsf_req_sbal_get(qdio
))
1498 req
= zfcp_fsf_req_create(qdio
, FSF_QTCB_OPEN_PORT_WITH_DID
,
1499 qdio
->adapter
->pool
.erp_req
);
1502 retval
= PTR_ERR(req
);
1506 req
->status
|= ZFCP_STATUS_FSFREQ_CLEANUP
;
1507 sbale
= zfcp_qdio_sbale_req(qdio
, &req
->qdio_req
);
1508 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_READ
;
1509 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
1511 req
->handler
= zfcp_fsf_open_port_handler
;
1512 hton24(req
->qtcb
->bottom
.support
.d_id
, port
->d_id
);
1514 req
->erp_action
= erp_action
;
1515 erp_action
->fsf_req_id
= req
->req_id
;
1516 get_device(&port
->dev
);
1518 zfcp_fsf_start_erp_timer(req
);
1519 retval
= zfcp_fsf_req_send(req
);
1521 zfcp_fsf_req_free(req
);
1522 erp_action
->fsf_req_id
= 0;
1523 put_device(&port
->dev
);
1526 spin_unlock_bh(&qdio
->req_q_lock
);
1530 static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req
*req
)
1532 struct zfcp_port
*port
= req
->data
;
1534 if (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
)
1537 switch (req
->qtcb
->header
.fsf_status
) {
1538 case FSF_PORT_HANDLE_NOT_VALID
:
1539 zfcp_erp_adapter_reopen(port
->adapter
, 0, "fscph_1", req
);
1540 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1542 case FSF_ADAPTER_STATUS_AVAILABLE
:
1545 zfcp_erp_modify_port_status(port
, "fscph_2", req
,
1546 ZFCP_STATUS_COMMON_OPEN
,
1553 * zfcp_fsf_close_port - create and send close port request
1554 * @erp_action: pointer to struct zfcp_erp_action
1555 * Returns: 0 on success, error otherwise
1557 int zfcp_fsf_close_port(struct zfcp_erp_action
*erp_action
)
1559 struct qdio_buffer_element
*sbale
;
1560 struct zfcp_qdio
*qdio
= erp_action
->adapter
->qdio
;
1561 struct zfcp_fsf_req
*req
;
1564 spin_lock_bh(&qdio
->req_q_lock
);
1565 if (zfcp_fsf_req_sbal_get(qdio
))
1568 req
= zfcp_fsf_req_create(qdio
, FSF_QTCB_CLOSE_PORT
,
1569 qdio
->adapter
->pool
.erp_req
);
1572 retval
= PTR_ERR(req
);
1576 req
->status
|= ZFCP_STATUS_FSFREQ_CLEANUP
;
1577 sbale
= zfcp_qdio_sbale_req(qdio
, &req
->qdio_req
);
1578 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_READ
;
1579 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
1581 req
->handler
= zfcp_fsf_close_port_handler
;
1582 req
->data
= erp_action
->port
;
1583 req
->erp_action
= erp_action
;
1584 req
->qtcb
->header
.port_handle
= erp_action
->port
->handle
;
1585 erp_action
->fsf_req_id
= req
->req_id
;
1587 zfcp_fsf_start_erp_timer(req
);
1588 retval
= zfcp_fsf_req_send(req
);
1590 zfcp_fsf_req_free(req
);
1591 erp_action
->fsf_req_id
= 0;
1594 spin_unlock_bh(&qdio
->req_q_lock
);
1598 static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req
*req
)
1600 struct zfcp_fc_wka_port
*wka_port
= req
->data
;
1601 struct fsf_qtcb_header
*header
= &req
->qtcb
->header
;
1603 if (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
) {
1604 wka_port
->status
= ZFCP_FC_WKA_PORT_OFFLINE
;
1608 switch (header
->fsf_status
) {
1609 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED
:
1610 dev_warn(&req
->adapter
->ccw_device
->dev
,
1611 "Opening WKA port 0x%x failed\n", wka_port
->d_id
);
1613 case FSF_ADAPTER_STATUS_AVAILABLE
:
1614 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1616 case FSF_ACCESS_DENIED
:
1617 wka_port
->status
= ZFCP_FC_WKA_PORT_OFFLINE
;
1620 wka_port
->handle
= header
->port_handle
;
1622 case FSF_PORT_ALREADY_OPEN
:
1623 wka_port
->status
= ZFCP_FC_WKA_PORT_ONLINE
;
1626 wake_up(&wka_port
->completion_wq
);
1630 * zfcp_fsf_open_wka_port - create and send open wka-port request
1631 * @wka_port: pointer to struct zfcp_fc_wka_port
1632 * Returns: 0 on success, error otherwise
1634 int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port
*wka_port
)
1636 struct qdio_buffer_element
*sbale
;
1637 struct zfcp_qdio
*qdio
= wka_port
->adapter
->qdio
;
1638 struct zfcp_fsf_req
*req
;
1641 spin_lock_bh(&qdio
->req_q_lock
);
1642 if (zfcp_fsf_req_sbal_get(qdio
))
1645 req
= zfcp_fsf_req_create(qdio
, FSF_QTCB_OPEN_PORT_WITH_DID
,
1646 qdio
->adapter
->pool
.erp_req
);
1648 if (unlikely(IS_ERR(req
))) {
1649 retval
= PTR_ERR(req
);
1653 req
->status
|= ZFCP_STATUS_FSFREQ_CLEANUP
;
1654 sbale
= zfcp_qdio_sbale_req(qdio
, &req
->qdio_req
);
1655 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_READ
;
1656 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
1658 req
->handler
= zfcp_fsf_open_wka_port_handler
;
1659 hton24(req
->qtcb
->bottom
.support
.d_id
, wka_port
->d_id
);
1660 req
->data
= wka_port
;
1662 zfcp_fsf_start_timer(req
, ZFCP_FSF_REQUEST_TIMEOUT
);
1663 retval
= zfcp_fsf_req_send(req
);
1665 zfcp_fsf_req_free(req
);
1667 spin_unlock_bh(&qdio
->req_q_lock
);
1671 static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req
*req
)
1673 struct zfcp_fc_wka_port
*wka_port
= req
->data
;
1675 if (req
->qtcb
->header
.fsf_status
== FSF_PORT_HANDLE_NOT_VALID
) {
1676 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1677 zfcp_erp_adapter_reopen(wka_port
->adapter
, 0, "fscwph1", req
);
1680 wka_port
->status
= ZFCP_FC_WKA_PORT_OFFLINE
;
1681 wake_up(&wka_port
->completion_wq
);
1685 * zfcp_fsf_close_wka_port - create and send close wka port request
1686 * @wka_port: WKA port to open
1687 * Returns: 0 on success, error otherwise
1689 int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port
*wka_port
)
1691 struct qdio_buffer_element
*sbale
;
1692 struct zfcp_qdio
*qdio
= wka_port
->adapter
->qdio
;
1693 struct zfcp_fsf_req
*req
;
1696 spin_lock_bh(&qdio
->req_q_lock
);
1697 if (zfcp_fsf_req_sbal_get(qdio
))
1700 req
= zfcp_fsf_req_create(qdio
, FSF_QTCB_CLOSE_PORT
,
1701 qdio
->adapter
->pool
.erp_req
);
1703 if (unlikely(IS_ERR(req
))) {
1704 retval
= PTR_ERR(req
);
1708 req
->status
|= ZFCP_STATUS_FSFREQ_CLEANUP
;
1709 sbale
= zfcp_qdio_sbale_req(qdio
, &req
->qdio_req
);
1710 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_READ
;
1711 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
1713 req
->handler
= zfcp_fsf_close_wka_port_handler
;
1714 req
->data
= wka_port
;
1715 req
->qtcb
->header
.port_handle
= wka_port
->handle
;
1717 zfcp_fsf_start_timer(req
, ZFCP_FSF_REQUEST_TIMEOUT
);
1718 retval
= zfcp_fsf_req_send(req
);
1720 zfcp_fsf_req_free(req
);
1722 spin_unlock_bh(&qdio
->req_q_lock
);
1726 static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req
*req
)
1728 struct zfcp_port
*port
= req
->data
;
1729 struct fsf_qtcb_header
*header
= &req
->qtcb
->header
;
1730 struct zfcp_unit
*unit
;
1732 if (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
)
1735 switch (header
->fsf_status
) {
1736 case FSF_PORT_HANDLE_NOT_VALID
:
1737 zfcp_erp_adapter_reopen(port
->adapter
, 0, "fscpph1", req
);
1738 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1740 case FSF_ACCESS_DENIED
:
1741 zfcp_fsf_access_denied_port(req
, port
);
1743 case FSF_PORT_BOXED
:
1744 /* can't use generic zfcp_erp_modify_port_status because
1745 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1746 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN
, &port
->status
);
1747 read_lock(&port
->unit_list_lock
);
1748 list_for_each_entry(unit
, &port
->unit_list
, list
)
1749 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN
,
1751 read_unlock(&port
->unit_list_lock
);
1752 zfcp_erp_port_boxed(port
, "fscpph2", req
);
1753 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1755 case FSF_ADAPTER_STATUS_AVAILABLE
:
1756 switch (header
->fsf_status_qual
.word
[0]) {
1757 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE
:
1759 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED
:
1760 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1765 /* can't use generic zfcp_erp_modify_port_status because
1766 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1768 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN
, &port
->status
);
1769 read_lock(&port
->unit_list_lock
);
1770 list_for_each_entry(unit
, &port
->unit_list
, list
)
1771 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN
,
1773 read_unlock(&port
->unit_list_lock
);
1779 * zfcp_fsf_close_physical_port - close physical port
1780 * @erp_action: pointer to struct zfcp_erp_action
1781 * Returns: 0 on success
1783 int zfcp_fsf_close_physical_port(struct zfcp_erp_action
*erp_action
)
1785 struct qdio_buffer_element
*sbale
;
1786 struct zfcp_qdio
*qdio
= erp_action
->adapter
->qdio
;
1787 struct zfcp_fsf_req
*req
;
1790 spin_lock_bh(&qdio
->req_q_lock
);
1791 if (zfcp_fsf_req_sbal_get(qdio
))
1794 req
= zfcp_fsf_req_create(qdio
, FSF_QTCB_CLOSE_PHYSICAL_PORT
,
1795 qdio
->adapter
->pool
.erp_req
);
1798 retval
= PTR_ERR(req
);
1802 req
->status
|= ZFCP_STATUS_FSFREQ_CLEANUP
;
1803 sbale
= zfcp_qdio_sbale_req(qdio
, &req
->qdio_req
);
1804 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_READ
;
1805 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
1807 req
->data
= erp_action
->port
;
1808 req
->qtcb
->header
.port_handle
= erp_action
->port
->handle
;
1809 req
->erp_action
= erp_action
;
1810 req
->handler
= zfcp_fsf_close_physical_port_handler
;
1811 erp_action
->fsf_req_id
= req
->req_id
;
1813 zfcp_fsf_start_erp_timer(req
);
1814 retval
= zfcp_fsf_req_send(req
);
1816 zfcp_fsf_req_free(req
);
1817 erp_action
->fsf_req_id
= 0;
1820 spin_unlock_bh(&qdio
->req_q_lock
);
1824 static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req
*req
)
1826 struct zfcp_adapter
*adapter
= req
->adapter
;
1827 struct zfcp_unit
*unit
= req
->data
;
1828 struct fsf_qtcb_header
*header
= &req
->qtcb
->header
;
1829 struct fsf_qtcb_bottom_support
*bottom
= &req
->qtcb
->bottom
.support
;
1830 struct fsf_queue_designator
*queue_designator
=
1831 &header
->fsf_status_qual
.fsf_queue_designator
;
1832 int exclusive
, readwrite
;
1834 if (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
)
1837 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED
|
1838 ZFCP_STATUS_COMMON_ACCESS_BOXED
|
1839 ZFCP_STATUS_UNIT_SHARED
|
1840 ZFCP_STATUS_UNIT_READONLY
,
1843 switch (header
->fsf_status
) {
1845 case FSF_PORT_HANDLE_NOT_VALID
:
1846 zfcp_erp_adapter_reopen(unit
->port
->adapter
, 0, "fsouh_1", req
);
1848 case FSF_LUN_ALREADY_OPEN
:
1850 case FSF_ACCESS_DENIED
:
1851 zfcp_fsf_access_denied_unit(req
, unit
);
1852 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED
, &unit
->status
);
1853 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY
, &unit
->status
);
1855 case FSF_PORT_BOXED
:
1856 zfcp_erp_port_boxed(unit
->port
, "fsouh_2", req
);
1857 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1859 case FSF_LUN_SHARING_VIOLATION
:
1860 if (header
->fsf_status_qual
.word
[0])
1861 dev_warn(&adapter
->ccw_device
->dev
,
1862 "LUN 0x%Lx on port 0x%Lx is already in "
1863 "use by CSS%d, MIF Image ID %x\n",
1864 (unsigned long long)unit
->fcp_lun
,
1865 (unsigned long long)unit
->port
->wwpn
,
1866 queue_designator
->cssid
,
1867 queue_designator
->hla
);
1869 zfcp_act_eval_err(adapter
,
1870 header
->fsf_status_qual
.word
[2]);
1871 zfcp_erp_unit_access_denied(unit
, "fsouh_3", req
);
1872 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED
, &unit
->status
);
1873 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY
, &unit
->status
);
1874 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1876 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED
:
1877 dev_warn(&adapter
->ccw_device
->dev
,
1878 "No handle is available for LUN "
1879 "0x%016Lx on port 0x%016Lx\n",
1880 (unsigned long long)unit
->fcp_lun
,
1881 (unsigned long long)unit
->port
->wwpn
);
1882 zfcp_erp_unit_failed(unit
, "fsouh_4", req
);
1884 case FSF_INVALID_COMMAND_OPTION
:
1885 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1887 case FSF_ADAPTER_STATUS_AVAILABLE
:
1888 switch (header
->fsf_status_qual
.word
[0]) {
1889 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE
:
1890 zfcp_fc_test_link(unit
->port
);
1892 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED
:
1893 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1899 unit
->handle
= header
->lun_handle
;
1900 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN
, &unit
->status
);
1902 if (!(adapter
->connection_features
& FSF_FEATURE_NPIV_MODE
) &&
1903 (adapter
->adapter_features
& FSF_FEATURE_LUN_SHARING
) &&
1904 !zfcp_ccw_priv_sch(adapter
)) {
1905 exclusive
= (bottom
->lun_access_info
&
1906 FSF_UNIT_ACCESS_EXCLUSIVE
);
1907 readwrite
= (bottom
->lun_access_info
&
1908 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER
);
1911 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED
,
1915 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY
,
1917 dev_info(&adapter
->ccw_device
->dev
,
1918 "SCSI device at LUN 0x%016Lx on port "
1919 "0x%016Lx opened read-only\n",
1920 (unsigned long long)unit
->fcp_lun
,
1921 (unsigned long long)unit
->port
->wwpn
);
1924 if (exclusive
&& !readwrite
) {
1925 dev_err(&adapter
->ccw_device
->dev
,
1926 "Exclusive read-only access not "
1927 "supported (unit 0x%016Lx, "
1929 (unsigned long long)unit
->fcp_lun
,
1930 (unsigned long long)unit
->port
->wwpn
);
1931 zfcp_erp_unit_failed(unit
, "fsouh_5", req
);
1932 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1933 zfcp_erp_unit_shutdown(unit
, 0, "fsouh_6", req
);
1934 } else if (!exclusive
&& readwrite
) {
1935 dev_err(&adapter
->ccw_device
->dev
,
1936 "Shared read-write access not "
1937 "supported (unit 0x%016Lx, port "
1939 (unsigned long long)unit
->fcp_lun
,
1940 (unsigned long long)unit
->port
->wwpn
);
1941 zfcp_erp_unit_failed(unit
, "fsouh_7", req
);
1942 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1943 zfcp_erp_unit_shutdown(unit
, 0, "fsouh_8", req
);
1951 * zfcp_fsf_open_unit - open unit
1952 * @erp_action: pointer to struct zfcp_erp_action
1953 * Returns: 0 on success, error otherwise
1955 int zfcp_fsf_open_unit(struct zfcp_erp_action
*erp_action
)
1957 struct qdio_buffer_element
*sbale
;
1958 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1959 struct zfcp_qdio
*qdio
= adapter
->qdio
;
1960 struct zfcp_fsf_req
*req
;
1963 spin_lock_bh(&qdio
->req_q_lock
);
1964 if (zfcp_fsf_req_sbal_get(qdio
))
1967 req
= zfcp_fsf_req_create(qdio
, FSF_QTCB_OPEN_LUN
,
1968 adapter
->pool
.erp_req
);
1971 retval
= PTR_ERR(req
);
1975 req
->status
|= ZFCP_STATUS_FSFREQ_CLEANUP
;
1976 sbale
= zfcp_qdio_sbale_req(qdio
, &req
->qdio_req
);
1977 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_READ
;
1978 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
1980 req
->qtcb
->header
.port_handle
= erp_action
->port
->handle
;
1981 req
->qtcb
->bottom
.support
.fcp_lun
= erp_action
->unit
->fcp_lun
;
1982 req
->handler
= zfcp_fsf_open_unit_handler
;
1983 req
->data
= erp_action
->unit
;
1984 req
->erp_action
= erp_action
;
1985 erp_action
->fsf_req_id
= req
->req_id
;
1987 if (!(adapter
->connection_features
& FSF_FEATURE_NPIV_MODE
))
1988 req
->qtcb
->bottom
.support
.option
= FSF_OPEN_LUN_SUPPRESS_BOXING
;
1990 zfcp_fsf_start_erp_timer(req
);
1991 retval
= zfcp_fsf_req_send(req
);
1993 zfcp_fsf_req_free(req
);
1994 erp_action
->fsf_req_id
= 0;
1997 spin_unlock_bh(&qdio
->req_q_lock
);
2001 static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req
*req
)
2003 struct zfcp_unit
*unit
= req
->data
;
2005 if (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
)
2008 switch (req
->qtcb
->header
.fsf_status
) {
2009 case FSF_PORT_HANDLE_NOT_VALID
:
2010 zfcp_erp_adapter_reopen(unit
->port
->adapter
, 0, "fscuh_1", req
);
2011 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
2013 case FSF_LUN_HANDLE_NOT_VALID
:
2014 zfcp_erp_port_reopen(unit
->port
, 0, "fscuh_2", req
);
2015 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
2017 case FSF_PORT_BOXED
:
2018 zfcp_erp_port_boxed(unit
->port
, "fscuh_3", req
);
2019 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
2021 case FSF_ADAPTER_STATUS_AVAILABLE
:
2022 switch (req
->qtcb
->header
.fsf_status_qual
.word
[0]) {
2023 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE
:
2024 zfcp_fc_test_link(unit
->port
);
2026 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED
:
2027 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
2032 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN
, &unit
->status
);
2038 * zfcp_fsf_close_unit - close zfcp unit
2039 * @erp_action: pointer to struct zfcp_unit
2040 * Returns: 0 on success, error otherwise
2042 int zfcp_fsf_close_unit(struct zfcp_erp_action
*erp_action
)
2044 struct qdio_buffer_element
*sbale
;
2045 struct zfcp_qdio
*qdio
= erp_action
->adapter
->qdio
;
2046 struct zfcp_fsf_req
*req
;
2049 spin_lock_bh(&qdio
->req_q_lock
);
2050 if (zfcp_fsf_req_sbal_get(qdio
))
2053 req
= zfcp_fsf_req_create(qdio
, FSF_QTCB_CLOSE_LUN
,
2054 qdio
->adapter
->pool
.erp_req
);
2057 retval
= PTR_ERR(req
);
2061 req
->status
|= ZFCP_STATUS_FSFREQ_CLEANUP
;
2062 sbale
= zfcp_qdio_sbale_req(qdio
, &req
->qdio_req
);
2063 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_READ
;
2064 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
2066 req
->qtcb
->header
.port_handle
= erp_action
->port
->handle
;
2067 req
->qtcb
->header
.lun_handle
= erp_action
->unit
->handle
;
2068 req
->handler
= zfcp_fsf_close_unit_handler
;
2069 req
->data
= erp_action
->unit
;
2070 req
->erp_action
= erp_action
;
2071 erp_action
->fsf_req_id
= req
->req_id
;
2073 zfcp_fsf_start_erp_timer(req
);
2074 retval
= zfcp_fsf_req_send(req
);
2076 zfcp_fsf_req_free(req
);
2077 erp_action
->fsf_req_id
= 0;
2080 spin_unlock_bh(&qdio
->req_q_lock
);
2084 static void zfcp_fsf_update_lat(struct fsf_latency_record
*lat_rec
, u32 lat
)
2086 lat_rec
->sum
+= lat
;
2087 lat_rec
->min
= min(lat_rec
->min
, lat
);
2088 lat_rec
->max
= max(lat_rec
->max
, lat
);
2091 static void zfcp_fsf_req_trace(struct zfcp_fsf_req
*req
, struct scsi_cmnd
*scsi
)
2093 struct fsf_qual_latency_info
*lat_in
;
2094 struct latency_cont
*lat
= NULL
;
2095 struct zfcp_unit
*unit
= req
->unit
;
2096 struct zfcp_blk_drv_data blktrc
;
2097 int ticks
= req
->adapter
->timer_ticks
;
2099 lat_in
= &req
->qtcb
->prefix
.prot_status_qual
.latency_info
;
2102 blktrc
.magic
= ZFCP_BLK_DRV_DATA_MAGIC
;
2103 if (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
)
2104 blktrc
.flags
|= ZFCP_BLK_REQ_ERROR
;
2105 blktrc
.inb_usage
= req
->qdio_req
.qdio_inb_usage
;
2106 blktrc
.outb_usage
= req
->qdio_req
.qdio_outb_usage
;
2108 if (req
->adapter
->adapter_features
& FSF_FEATURE_MEASUREMENT_DATA
&&
2109 !(req
->status
& ZFCP_STATUS_FSFREQ_ERROR
)) {
2110 blktrc
.flags
|= ZFCP_BLK_LAT_VALID
;
2111 blktrc
.channel_lat
= lat_in
->channel_lat
* ticks
;
2112 blktrc
.fabric_lat
= lat_in
->fabric_lat
* ticks
;
2114 switch (req
->qtcb
->bottom
.io
.data_direction
) {
2115 case FSF_DATADIR_READ
:
2116 lat
= &unit
->latencies
.read
;
2118 case FSF_DATADIR_WRITE
:
2119 lat
= &unit
->latencies
.write
;
2121 case FSF_DATADIR_CMND
:
2122 lat
= &unit
->latencies
.cmd
;
2127 spin_lock(&unit
->latencies
.lock
);
2128 zfcp_fsf_update_lat(&lat
->channel
, lat_in
->channel_lat
);
2129 zfcp_fsf_update_lat(&lat
->fabric
, lat_in
->fabric_lat
);
2131 spin_unlock(&unit
->latencies
.lock
);
2135 blk_add_driver_data(scsi
->request
->q
, scsi
->request
, &blktrc
,
2139 static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req
*req
)
2141 struct scsi_cmnd
*scpnt
;
2142 struct fcp_resp_with_ext
*fcp_rsp
;
2143 unsigned long flags
;
2145 read_lock_irqsave(&req
->adapter
->abort_lock
, flags
);
2148 if (unlikely(!scpnt
)) {
2149 read_unlock_irqrestore(&req
->adapter
->abort_lock
, flags
);
2153 if (unlikely(req
->status
& ZFCP_STATUS_FSFREQ_ERROR
)) {
2154 set_host_byte(scpnt
, DID_TRANSPORT_DISRUPTED
);
2155 goto skip_fsfstatus
;
2158 fcp_rsp
= (struct fcp_resp_with_ext
*) &req
->qtcb
->bottom
.io
.fcp_rsp
;
2159 zfcp_fc_eval_fcp_rsp(fcp_rsp
, scpnt
);
2162 zfcp_fsf_req_trace(req
, scpnt
);
2163 zfcp_dbf_scsi_result(req
->adapter
->dbf
, scpnt
, req
);
2165 scpnt
->host_scribble
= NULL
;
2166 (scpnt
->scsi_done
) (scpnt
);
2168 * We must hold this lock until scsi_done has been called.
2169 * Otherwise we may call scsi_done after abort regarding this
2170 * command has completed.
2171 * Note: scsi_done must not block!
2173 read_unlock_irqrestore(&req
->adapter
->abort_lock
, flags
);
2176 static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req
*req
)
2178 struct fcp_resp_with_ext
*fcp_rsp
;
2179 struct fcp_resp_rsp_info
*rsp_info
;
2181 fcp_rsp
= (struct fcp_resp_with_ext
*) &req
->qtcb
->bottom
.io
.fcp_rsp
;
2182 rsp_info
= (struct fcp_resp_rsp_info
*) &fcp_rsp
[1];
2184 if ((rsp_info
->rsp_code
!= FCP_TMF_CMPL
) ||
2185 (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
))
2186 req
->status
|= ZFCP_STATUS_FSFREQ_TMFUNCFAILED
;
2190 static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req
*req
)
2192 struct zfcp_unit
*unit
;
2193 struct fsf_qtcb_header
*header
= &req
->qtcb
->header
;
2195 if (unlikely(req
->status
& ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT
))
2200 if (unlikely(req
->status
& ZFCP_STATUS_FSFREQ_ERROR
))
2201 goto skip_fsfstatus
;
2203 switch (header
->fsf_status
) {
2204 case FSF_HANDLE_MISMATCH
:
2205 case FSF_PORT_HANDLE_NOT_VALID
:
2206 zfcp_erp_adapter_reopen(unit
->port
->adapter
, 0, "fssfch1", req
);
2207 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
2209 case FSF_FCPLUN_NOT_VALID
:
2210 case FSF_LUN_HANDLE_NOT_VALID
:
2211 zfcp_erp_port_reopen(unit
->port
, 0, "fssfch2", req
);
2212 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
2214 case FSF_SERVICE_CLASS_NOT_SUPPORTED
:
2215 zfcp_fsf_class_not_supp(req
);
2217 case FSF_ACCESS_DENIED
:
2218 zfcp_fsf_access_denied_unit(req
, unit
);
2220 case FSF_DIRECTION_INDICATOR_NOT_VALID
:
2221 dev_err(&req
->adapter
->ccw_device
->dev
,
2222 "Incorrect direction %d, unit 0x%016Lx on port "
2223 "0x%016Lx closed\n",
2224 req
->qtcb
->bottom
.io
.data_direction
,
2225 (unsigned long long)unit
->fcp_lun
,
2226 (unsigned long long)unit
->port
->wwpn
);
2227 zfcp_erp_adapter_shutdown(unit
->port
->adapter
, 0, "fssfch3",
2229 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
2231 case FSF_CMND_LENGTH_NOT_VALID
:
2232 dev_err(&req
->adapter
->ccw_device
->dev
,
2233 "Incorrect CDB length %d, unit 0x%016Lx on "
2234 "port 0x%016Lx closed\n",
2235 req
->qtcb
->bottom
.io
.fcp_cmnd_length
,
2236 (unsigned long long)unit
->fcp_lun
,
2237 (unsigned long long)unit
->port
->wwpn
);
2238 zfcp_erp_adapter_shutdown(unit
->port
->adapter
, 0, "fssfch4",
2240 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
2242 case FSF_PORT_BOXED
:
2243 zfcp_erp_port_boxed(unit
->port
, "fssfch5", req
);
2244 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
2247 zfcp_erp_unit_boxed(unit
, "fssfch6", req
);
2248 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
2250 case FSF_ADAPTER_STATUS_AVAILABLE
:
2251 if (header
->fsf_status_qual
.word
[0] ==
2252 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE
)
2253 zfcp_fc_test_link(unit
->port
);
2254 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
2258 if (req
->status
& ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT
)
2259 zfcp_fsf_send_fcp_ctm_handler(req
);
2261 zfcp_fsf_send_fcp_command_task_handler(req
);
2263 put_device(&unit
->dev
);
2268 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
2269 * @unit: unit where command is sent to
2270 * @scsi_cmnd: scsi command to be sent
2272 int zfcp_fsf_send_fcp_command_task(struct zfcp_unit
*unit
,
2273 struct scsi_cmnd
*scsi_cmnd
)
2275 struct zfcp_fsf_req
*req
;
2276 struct fcp_cmnd
*fcp_cmnd
;
2277 unsigned int sbtype
= SBAL_FLAGS0_TYPE_READ
;
2278 int real_bytes
, retval
= -EIO
;
2279 struct zfcp_adapter
*adapter
= unit
->port
->adapter
;
2280 struct zfcp_qdio
*qdio
= adapter
->qdio
;
2282 if (unlikely(!(atomic_read(&unit
->status
) &
2283 ZFCP_STATUS_COMMON_UNBLOCKED
)))
2286 spin_lock(&qdio
->req_q_lock
);
2287 if (atomic_read(&qdio
->req_q
.count
) <= 0) {
2288 atomic_inc(&qdio
->req_q_full
);
2292 req
= zfcp_fsf_req_create(qdio
, FSF_QTCB_FCP_CMND
,
2293 adapter
->pool
.scsi_req
);
2296 retval
= PTR_ERR(req
);
2300 req
->status
|= ZFCP_STATUS_FSFREQ_CLEANUP
;
2301 get_device(&unit
->dev
);
2303 req
->data
= scsi_cmnd
;
2304 req
->handler
= zfcp_fsf_send_fcp_command_handler
;
2305 req
->qtcb
->header
.lun_handle
= unit
->handle
;
2306 req
->qtcb
->header
.port_handle
= unit
->port
->handle
;
2307 req
->qtcb
->bottom
.io
.service_class
= FSF_CLASS_3
;
2308 req
->qtcb
->bottom
.io
.fcp_cmnd_length
= FCP_CMND_LEN
;
2310 scsi_cmnd
->host_scribble
= (unsigned char *) req
->req_id
;
2313 * set depending on data direction:
2314 * data direction bits in SBALE (SB Type)
2315 * data direction bits in QTCB
2317 switch (scsi_cmnd
->sc_data_direction
) {
2319 req
->qtcb
->bottom
.io
.data_direction
= FSF_DATADIR_CMND
;
2321 case DMA_FROM_DEVICE
:
2322 req
->qtcb
->bottom
.io
.data_direction
= FSF_DATADIR_READ
;
2325 req
->qtcb
->bottom
.io
.data_direction
= FSF_DATADIR_WRITE
;
2326 sbtype
= SBAL_FLAGS0_TYPE_WRITE
;
2328 case DMA_BIDIRECTIONAL
:
2329 goto failed_scsi_cmnd
;
2332 fcp_cmnd
= (struct fcp_cmnd
*) &req
->qtcb
->bottom
.io
.fcp_cmnd
;
2333 zfcp_fc_scsi_to_fcp(fcp_cmnd
, scsi_cmnd
);
2335 real_bytes
= zfcp_qdio_sbals_from_sg(qdio
, &req
->qdio_req
, sbtype
,
2336 scsi_sglist(scsi_cmnd
),
2337 FSF_MAX_SBALS_PER_REQ
);
2338 if (unlikely(real_bytes
< 0)) {
2339 if (req
->qdio_req
.sbal_number
>= FSF_MAX_SBALS_PER_REQ
) {
2340 dev_err(&adapter
->ccw_device
->dev
,
2341 "Oversize data package, unit 0x%016Lx "
2342 "on port 0x%016Lx closed\n",
2343 (unsigned long long)unit
->fcp_lun
,
2344 (unsigned long long)unit
->port
->wwpn
);
2345 zfcp_erp_unit_shutdown(unit
, 0, "fssfct1", req
);
2348 goto failed_scsi_cmnd
;
2351 retval
= zfcp_fsf_req_send(req
);
2352 if (unlikely(retval
))
2353 goto failed_scsi_cmnd
;
2358 put_device(&unit
->dev
);
2359 zfcp_fsf_req_free(req
);
2360 scsi_cmnd
->host_scribble
= NULL
;
2362 spin_unlock(&qdio
->req_q_lock
);
2367 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
2368 * @unit: pointer to struct zfcp_unit
2369 * @tm_flags: unsigned byte for task management flags
2370 * Returns: on success pointer to struct fsf_req, NULL otherwise
2372 struct zfcp_fsf_req
*zfcp_fsf_send_fcp_ctm(struct zfcp_unit
*unit
, u8 tm_flags
)
2374 struct qdio_buffer_element
*sbale
;
2375 struct zfcp_fsf_req
*req
= NULL
;
2376 struct fcp_cmnd
*fcp_cmnd
;
2377 struct zfcp_qdio
*qdio
= unit
->port
->adapter
->qdio
;
2379 if (unlikely(!(atomic_read(&unit
->status
) &
2380 ZFCP_STATUS_COMMON_UNBLOCKED
)))
2383 spin_lock_bh(&qdio
->req_q_lock
);
2384 if (zfcp_fsf_req_sbal_get(qdio
))
2387 req
= zfcp_fsf_req_create(qdio
, FSF_QTCB_FCP_CMND
,
2388 qdio
->adapter
->pool
.scsi_req
);
2395 req
->status
|= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT
;
2397 req
->handler
= zfcp_fsf_send_fcp_command_handler
;
2398 req
->qtcb
->header
.lun_handle
= unit
->handle
;
2399 req
->qtcb
->header
.port_handle
= unit
->port
->handle
;
2400 req
->qtcb
->bottom
.io
.data_direction
= FSF_DATADIR_CMND
;
2401 req
->qtcb
->bottom
.io
.service_class
= FSF_CLASS_3
;
2402 req
->qtcb
->bottom
.io
.fcp_cmnd_length
= FCP_CMND_LEN
;
2404 sbale
= zfcp_qdio_sbale_req(qdio
, &req
->qdio_req
);
2405 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_WRITE
;
2406 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
2408 fcp_cmnd
= (struct fcp_cmnd
*) &req
->qtcb
->bottom
.io
.fcp_cmnd
;
2409 zfcp_fc_fcp_tm(fcp_cmnd
, unit
->device
, tm_flags
);
2411 zfcp_fsf_start_timer(req
, ZFCP_SCSI_ER_TIMEOUT
);
2412 if (!zfcp_fsf_req_send(req
))
2415 zfcp_fsf_req_free(req
);
2418 spin_unlock_bh(&qdio
->req_q_lock
);
2422 static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req
*req
)
2427 * zfcp_fsf_control_file - control file upload/download
2428 * @adapter: pointer to struct zfcp_adapter
2429 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2430 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
2432 struct zfcp_fsf_req
*zfcp_fsf_control_file(struct zfcp_adapter
*adapter
,
2433 struct zfcp_fsf_cfdc
*fsf_cfdc
)
2435 struct qdio_buffer_element
*sbale
;
2436 struct zfcp_qdio
*qdio
= adapter
->qdio
;
2437 struct zfcp_fsf_req
*req
= NULL
;
2438 struct fsf_qtcb_bottom_support
*bottom
;
2439 int direction
, retval
= -EIO
, bytes
;
2441 if (!(adapter
->adapter_features
& FSF_FEATURE_CFDC
))
2442 return ERR_PTR(-EOPNOTSUPP
);
2444 switch (fsf_cfdc
->command
) {
2445 case FSF_QTCB_DOWNLOAD_CONTROL_FILE
:
2446 direction
= SBAL_FLAGS0_TYPE_WRITE
;
2448 case FSF_QTCB_UPLOAD_CONTROL_FILE
:
2449 direction
= SBAL_FLAGS0_TYPE_READ
;
2452 return ERR_PTR(-EINVAL
);
2455 spin_lock_bh(&qdio
->req_q_lock
);
2456 if (zfcp_fsf_req_sbal_get(qdio
))
2459 req
= zfcp_fsf_req_create(qdio
, fsf_cfdc
->command
, NULL
);
2465 req
->handler
= zfcp_fsf_control_file_handler
;
2467 sbale
= zfcp_qdio_sbale_req(qdio
, &req
->qdio_req
);
2468 sbale
[0].flags
|= direction
;
2470 bottom
= &req
->qtcb
->bottom
.support
;
2471 bottom
->operation_subtype
= FSF_CFDC_OPERATION_SUBTYPE
;
2472 bottom
->option
= fsf_cfdc
->option
;
2474 bytes
= zfcp_qdio_sbals_from_sg(qdio
, &req
->qdio_req
,
2475 direction
, fsf_cfdc
->sg
,
2476 FSF_MAX_SBALS_PER_REQ
);
2477 if (bytes
!= ZFCP_CFDC_MAX_SIZE
) {
2478 zfcp_fsf_req_free(req
);
2482 zfcp_fsf_start_timer(req
, ZFCP_FSF_REQUEST_TIMEOUT
);
2483 retval
= zfcp_fsf_req_send(req
);
2485 spin_unlock_bh(&qdio
->req_q_lock
);
2488 wait_for_completion(&req
->completion
);
2491 return ERR_PTR(retval
);
2495 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2496 * @adapter: pointer to struct zfcp_adapter
2497 * @sbal_idx: response queue index of SBAL to be processed
2499 void zfcp_fsf_reqid_check(struct zfcp_qdio
*qdio
, int sbal_idx
)
2501 struct zfcp_adapter
*adapter
= qdio
->adapter
;
2502 struct qdio_buffer
*sbal
= qdio
->resp_q
.sbal
[sbal_idx
];
2503 struct qdio_buffer_element
*sbale
;
2504 struct zfcp_fsf_req
*fsf_req
;
2505 unsigned long req_id
;
2508 for (idx
= 0; idx
< QDIO_MAX_ELEMENTS_PER_BUFFER
; idx
++) {
2510 sbale
= &sbal
->element
[idx
];
2511 req_id
= (unsigned long) sbale
->addr
;
2512 fsf_req
= zfcp_reqlist_find_rm(adapter
->req_list
, req_id
);
2516 * Unknown request means that we have potentially memory
2517 * corruption and must stop the machine immediately.
2519 panic("error: unknown req_id (%lx) on adapter %s.\n",
2520 req_id
, dev_name(&adapter
->ccw_device
->dev
));
2522 fsf_req
->qdio_req
.sbal_response
= sbal_idx
;
2523 fsf_req
->qdio_req
.qdio_inb_usage
=
2524 atomic_read(&qdio
->resp_q
.count
);
2525 zfcp_fsf_req_complete(fsf_req
);
2527 if (likely(sbale
->flags
& SBAL_FLAGS_LAST_ENTRY
))