4 * Implementation of FSF commands.
6 * Copyright IBM Corporation 2002, 2008
11 static void zfcp_fsf_request_timeout_handler(unsigned long data
)
13 struct zfcp_adapter
*adapter
= (struct zfcp_adapter
*) data
;
14 zfcp_erp_adapter_reopen(adapter
, ZFCP_STATUS_COMMON_ERP_FAILED
, 62,
18 static void zfcp_fsf_start_timer(struct zfcp_fsf_req
*fsf_req
,
19 unsigned long timeout
)
21 fsf_req
->timer
.function
= zfcp_fsf_request_timeout_handler
;
22 fsf_req
->timer
.data
= (unsigned long) fsf_req
->adapter
;
23 fsf_req
->timer
.expires
= jiffies
+ timeout
;
24 add_timer(&fsf_req
->timer
);
27 static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req
*fsf_req
)
29 BUG_ON(!fsf_req
->erp_action
);
30 fsf_req
->timer
.function
= zfcp_erp_timeout_handler
;
31 fsf_req
->timer
.data
= (unsigned long) fsf_req
->erp_action
;
32 fsf_req
->timer
.expires
= jiffies
+ 30 * HZ
;
33 add_timer(&fsf_req
->timer
);
36 /* association between FSF command and FSF QTCB type */
37 static u32 fsf_qtcb_type
[] = {
38 [FSF_QTCB_FCP_CMND
] = FSF_IO_COMMAND
,
39 [FSF_QTCB_ABORT_FCP_CMND
] = FSF_SUPPORT_COMMAND
,
40 [FSF_QTCB_OPEN_PORT_WITH_DID
] = FSF_SUPPORT_COMMAND
,
41 [FSF_QTCB_OPEN_LUN
] = FSF_SUPPORT_COMMAND
,
42 [FSF_QTCB_CLOSE_LUN
] = FSF_SUPPORT_COMMAND
,
43 [FSF_QTCB_CLOSE_PORT
] = FSF_SUPPORT_COMMAND
,
44 [FSF_QTCB_CLOSE_PHYSICAL_PORT
] = FSF_SUPPORT_COMMAND
,
45 [FSF_QTCB_SEND_ELS
] = FSF_SUPPORT_COMMAND
,
46 [FSF_QTCB_SEND_GENERIC
] = FSF_SUPPORT_COMMAND
,
47 [FSF_QTCB_EXCHANGE_CONFIG_DATA
] = FSF_CONFIG_COMMAND
,
48 [FSF_QTCB_EXCHANGE_PORT_DATA
] = FSF_PORT_COMMAND
,
49 [FSF_QTCB_DOWNLOAD_CONTROL_FILE
] = FSF_SUPPORT_COMMAND
,
50 [FSF_QTCB_UPLOAD_CONTROL_FILE
] = FSF_SUPPORT_COMMAND
53 static void zfcp_act_eval_err(struct zfcp_adapter
*adapter
, u32 table
)
55 u16 subtable
= table
>> 16;
56 u16 rule
= table
& 0xffff;
57 const char *act_type
[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
59 if (subtable
&& subtable
< ARRAY_SIZE(act_type
))
60 dev_warn(&adapter
->ccw_device
->dev
,
61 "Access denied according to ACT rule type %s, "
62 "rule %d\n", act_type
[subtable
], rule
);
65 static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req
*req
,
66 struct zfcp_port
*port
)
68 struct fsf_qtcb_header
*header
= &req
->qtcb
->header
;
69 dev_warn(&req
->adapter
->ccw_device
->dev
,
70 "Access denied to port 0x%016Lx\n",
72 zfcp_act_eval_err(req
->adapter
, header
->fsf_status_qual
.halfword
[0]);
73 zfcp_act_eval_err(req
->adapter
, header
->fsf_status_qual
.halfword
[1]);
74 zfcp_erp_port_access_denied(port
, 55, req
);
75 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
78 static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req
*req
,
79 struct zfcp_unit
*unit
)
81 struct fsf_qtcb_header
*header
= &req
->qtcb
->header
;
82 dev_warn(&req
->adapter
->ccw_device
->dev
,
83 "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
84 unit
->fcp_lun
, unit
->port
->wwpn
);
85 zfcp_act_eval_err(req
->adapter
, header
->fsf_status_qual
.halfword
[0]);
86 zfcp_act_eval_err(req
->adapter
, header
->fsf_status_qual
.halfword
[1]);
87 zfcp_erp_unit_access_denied(unit
, 59, req
);
88 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
91 static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req
*req
)
93 dev_err(&req
->adapter
->ccw_device
->dev
, "FCP device not "
94 "operational because of an unsupported FC class\n");
95 zfcp_erp_adapter_shutdown(req
->adapter
, 0, 123, req
);
96 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
100 * zfcp_fsf_req_free - free memory used by fsf request
101 * @fsf_req: pointer to struct zfcp_fsf_req
103 void zfcp_fsf_req_free(struct zfcp_fsf_req
*req
)
105 if (likely(req
->pool
)) {
106 mempool_free(req
, req
->pool
);
111 kmem_cache_free(zfcp_data
.fsf_req_qtcb_cache
, req
);
117 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
118 * @adapter: pointer to struct zfcp_adapter
120 * Never ever call this without shutting down the adapter first.
121 * Otherwise the adapter would continue using and corrupting s390 storage.
122 * Included BUG_ON() call to ensure this is done.
123 * ERP is supposed to be the only user of this function.
125 void zfcp_fsf_req_dismiss_all(struct zfcp_adapter
*adapter
)
127 struct zfcp_fsf_req
*req
, *tmp
;
129 LIST_HEAD(remove_queue
);
132 BUG_ON(atomic_read(&adapter
->status
) & ZFCP_STATUS_ADAPTER_QDIOUP
);
133 spin_lock_irqsave(&adapter
->req_list_lock
, flags
);
134 for (i
= 0; i
< REQUEST_LIST_SIZE
; i
++)
135 list_splice_init(&adapter
->req_list
[i
], &remove_queue
);
136 spin_unlock_irqrestore(&adapter
->req_list_lock
, flags
);
138 list_for_each_entry_safe(req
, tmp
, &remove_queue
, list
) {
139 list_del(&req
->list
);
140 req
->status
|= ZFCP_STATUS_FSFREQ_DISMISSED
;
141 zfcp_fsf_req_complete(req
);
145 static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req
*req
)
147 struct fsf_status_read_buffer
*sr_buf
= req
->data
;
148 struct zfcp_adapter
*adapter
= req
->adapter
;
149 struct zfcp_port
*port
;
150 int d_id
= sr_buf
->d_id
& ZFCP_DID_MASK
;
153 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
154 list_for_each_entry(port
, &adapter
->port_list_head
, list
)
155 if (port
->d_id
== d_id
) {
156 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
157 switch (sr_buf
->status_subtype
) {
158 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT
:
159 zfcp_erp_port_reopen(port
, 0, 101, req
);
161 case FSF_STATUS_READ_SUB_ERROR_PORT
:
162 zfcp_erp_port_shutdown(port
, 0, 122, req
);
167 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
170 static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req
*req
, u8 id
,
171 struct fsf_link_down_info
*link_down
)
173 struct zfcp_adapter
*adapter
= req
->adapter
;
175 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
)
178 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
, &adapter
->status
);
183 switch (link_down
->error_code
) {
184 case FSF_PSQ_LINK_NO_LIGHT
:
185 dev_warn(&req
->adapter
->ccw_device
->dev
,
186 "There is no light signal from the local "
187 "fibre channel cable\n");
189 case FSF_PSQ_LINK_WRAP_PLUG
:
190 dev_warn(&req
->adapter
->ccw_device
->dev
,
191 "There is a wrap plug instead of a fibre "
194 case FSF_PSQ_LINK_NO_FCP
:
195 dev_warn(&req
->adapter
->ccw_device
->dev
,
196 "The adjacent fibre channel node does not "
199 case FSF_PSQ_LINK_FIRMWARE_UPDATE
:
200 dev_warn(&req
->adapter
->ccw_device
->dev
,
201 "The FCP device is suspended because of a "
202 "firmware update\n");
204 case FSF_PSQ_LINK_INVALID_WWPN
:
205 dev_warn(&req
->adapter
->ccw_device
->dev
,
206 "The FCP device detected a WWPN that is "
207 "duplicate or not valid\n");
209 case FSF_PSQ_LINK_NO_NPIV_SUPPORT
:
210 dev_warn(&req
->adapter
->ccw_device
->dev
,
211 "The fibre channel fabric does not support NPIV\n");
213 case FSF_PSQ_LINK_NO_FCP_RESOURCES
:
214 dev_warn(&req
->adapter
->ccw_device
->dev
,
215 "The FCP adapter cannot support more NPIV ports\n");
217 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES
:
218 dev_warn(&req
->adapter
->ccw_device
->dev
,
219 "The adjacent switch cannot support "
220 "more NPIV ports\n");
222 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE
:
223 dev_warn(&req
->adapter
->ccw_device
->dev
,
224 "The FCP adapter could not log in to the "
225 "fibre channel fabric\n");
227 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED
:
228 dev_warn(&req
->adapter
->ccw_device
->dev
,
229 "The WWPN assignment file on the FCP adapter "
230 "has been damaged\n");
232 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED
:
233 dev_warn(&req
->adapter
->ccw_device
->dev
,
234 "The mode table on the FCP adapter "
235 "has been damaged\n");
237 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT
:
238 dev_warn(&req
->adapter
->ccw_device
->dev
,
239 "All NPIV ports on the FCP adapter have "
243 dev_warn(&req
->adapter
->ccw_device
->dev
,
244 "The link between the FCP adapter and "
245 "the FC fabric is down\n");
248 zfcp_erp_adapter_failed(adapter
, id
, req
);
251 static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req
*req
)
253 struct fsf_status_read_buffer
*sr_buf
= req
->data
;
254 struct fsf_link_down_info
*ldi
=
255 (struct fsf_link_down_info
*) &sr_buf
->payload
;
257 switch (sr_buf
->status_subtype
) {
258 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK
:
259 zfcp_fsf_link_down_info_eval(req
, 38, ldi
);
261 case FSF_STATUS_READ_SUB_FDISC_FAILED
:
262 zfcp_fsf_link_down_info_eval(req
, 39, ldi
);
264 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE
:
265 zfcp_fsf_link_down_info_eval(req
, 40, NULL
);
269 static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req
*req
)
271 struct zfcp_adapter
*adapter
= req
->adapter
;
272 struct fsf_status_read_buffer
*sr_buf
= req
->data
;
274 if (req
->status
& ZFCP_STATUS_FSFREQ_DISMISSED
) {
275 zfcp_hba_dbf_event_fsf_unsol("dism", adapter
, sr_buf
);
276 mempool_free(sr_buf
, adapter
->pool
.data_status_read
);
277 zfcp_fsf_req_free(req
);
281 zfcp_hba_dbf_event_fsf_unsol("read", adapter
, sr_buf
);
283 switch (sr_buf
->status_type
) {
284 case FSF_STATUS_READ_PORT_CLOSED
:
285 zfcp_fsf_status_read_port_closed(req
);
287 case FSF_STATUS_READ_INCOMING_ELS
:
288 zfcp_fc_incoming_els(req
);
290 case FSF_STATUS_READ_SENSE_DATA_AVAIL
:
292 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD
:
293 dev_warn(&adapter
->ccw_device
->dev
,
294 "The error threshold for checksum statistics "
295 "has been exceeded\n");
297 case FSF_STATUS_READ_LINK_DOWN
:
298 zfcp_fsf_status_read_link_down(req
);
300 case FSF_STATUS_READ_LINK_UP
:
301 dev_info(&adapter
->ccw_device
->dev
,
302 "The local link has been restored\n");
303 /* All ports should be marked as ready to run again */
304 zfcp_erp_modify_adapter_status(adapter
, 30, NULL
,
305 ZFCP_STATUS_COMMON_RUNNING
,
307 zfcp_erp_adapter_reopen(adapter
,
308 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
|
309 ZFCP_STATUS_COMMON_ERP_FAILED
,
312 case FSF_STATUS_READ_NOTIFICATION_LOST
:
313 if (sr_buf
->status_subtype
& FSF_STATUS_READ_SUB_ACT_UPDATED
)
314 zfcp_erp_adapter_access_changed(adapter
, 135, req
);
315 if (sr_buf
->status_subtype
& FSF_STATUS_READ_SUB_INCOMING_ELS
)
316 schedule_work(&adapter
->scan_work
);
318 case FSF_STATUS_READ_CFDC_UPDATED
:
319 zfcp_erp_adapter_access_changed(adapter
, 136, req
);
321 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT
:
322 adapter
->adapter_features
= sr_buf
->payload
.word
[0];
326 mempool_free(sr_buf
, adapter
->pool
.data_status_read
);
327 zfcp_fsf_req_free(req
);
329 atomic_inc(&adapter
->stat_miss
);
330 schedule_work(&adapter
->stat_work
);
333 static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req
*req
)
335 switch (req
->qtcb
->header
.fsf_status_qual
.word
[0]) {
336 case FSF_SQ_FCP_RSP_AVAILABLE
:
337 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE
:
338 case FSF_SQ_NO_RETRY_POSSIBLE
:
339 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED
:
341 case FSF_SQ_COMMAND_ABORTED
:
342 req
->status
|= ZFCP_STATUS_FSFREQ_ABORTED
;
344 case FSF_SQ_NO_RECOM
:
345 dev_err(&req
->adapter
->ccw_device
->dev
,
346 "The FCP adapter reported a problem "
347 "that cannot be recovered\n");
348 zfcp_erp_adapter_shutdown(req
->adapter
, 0, 121, req
);
351 /* all non-return stats set FSFREQ_ERROR*/
352 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
355 static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req
*req
)
357 if (unlikely(req
->status
& ZFCP_STATUS_FSFREQ_ERROR
))
360 switch (req
->qtcb
->header
.fsf_status
) {
361 case FSF_UNKNOWN_COMMAND
:
362 dev_err(&req
->adapter
->ccw_device
->dev
,
363 "The FCP adapter does not recognize the command 0x%x\n",
364 req
->qtcb
->header
.fsf_command
);
365 zfcp_erp_adapter_shutdown(req
->adapter
, 0, 120, req
);
366 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
368 case FSF_ADAPTER_STATUS_AVAILABLE
:
369 zfcp_fsf_fsfstatus_qual_eval(req
);
374 static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req
*req
)
376 struct zfcp_adapter
*adapter
= req
->adapter
;
377 struct fsf_qtcb
*qtcb
= req
->qtcb
;
378 union fsf_prot_status_qual
*psq
= &qtcb
->prefix
.prot_status_qual
;
380 zfcp_hba_dbf_event_fsf_response(req
);
382 if (req
->status
& ZFCP_STATUS_FSFREQ_DISMISSED
) {
383 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
|
384 ZFCP_STATUS_FSFREQ_RETRY
; /* only for SCSI cmnds. */
388 switch (qtcb
->prefix
.prot_status
) {
390 case FSF_PROT_FSF_STATUS_PRESENTED
:
392 case FSF_PROT_QTCB_VERSION_ERROR
:
393 dev_err(&adapter
->ccw_device
->dev
,
394 "QTCB version 0x%x not supported by FCP adapter "
395 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION
,
396 psq
->word
[0], psq
->word
[1]);
397 zfcp_erp_adapter_shutdown(adapter
, 0, 117, req
);
399 case FSF_PROT_ERROR_STATE
:
400 case FSF_PROT_SEQ_NUMB_ERROR
:
401 zfcp_erp_adapter_reopen(adapter
, 0, 98, req
);
402 req
->status
|= ZFCP_STATUS_FSFREQ_RETRY
;
404 case FSF_PROT_UNSUPP_QTCB_TYPE
:
405 dev_err(&adapter
->ccw_device
->dev
,
406 "The QTCB type is not supported by the FCP adapter\n");
407 zfcp_erp_adapter_shutdown(adapter
, 0, 118, req
);
409 case FSF_PROT_HOST_CONNECTION_INITIALIZING
:
410 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
413 case FSF_PROT_DUPLICATE_REQUEST_ID
:
414 dev_err(&adapter
->ccw_device
->dev
,
415 "0x%Lx is an ambiguous request identifier\n",
416 (unsigned long long)qtcb
->bottom
.support
.req_handle
);
417 zfcp_erp_adapter_shutdown(adapter
, 0, 78, req
);
419 case FSF_PROT_LINK_DOWN
:
420 zfcp_fsf_link_down_info_eval(req
, 37, &psq
->link_down_info
);
421 /* FIXME: reopening adapter now? better wait for link up */
422 zfcp_erp_adapter_reopen(adapter
, 0, 79, req
);
424 case FSF_PROT_REEST_QUEUE
:
425 /* All ports should be marked as ready to run again */
426 zfcp_erp_modify_adapter_status(adapter
, 28, NULL
,
427 ZFCP_STATUS_COMMON_RUNNING
,
429 zfcp_erp_adapter_reopen(adapter
,
430 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
|
431 ZFCP_STATUS_COMMON_ERP_FAILED
, 99, req
);
434 dev_err(&adapter
->ccw_device
->dev
,
435 "0x%x is not a valid transfer protocol status\n",
436 qtcb
->prefix
.prot_status
);
437 zfcp_erp_adapter_shutdown(adapter
, 0, 119, req
);
439 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
443 * zfcp_fsf_req_complete - process completion of a FSF request
444 * @fsf_req: The FSF request that has been completed.
446 * When a request has been completed either from the FCP adapter,
447 * or it has been dismissed due to a queue shutdown, this function
448 * is called to process the completion status and trigger further
449 * events related to the FSF request.
451 void zfcp_fsf_req_complete(struct zfcp_fsf_req
*req
)
453 if (unlikely(req
->fsf_command
== FSF_QTCB_UNSOLICITED_STATUS
)) {
454 zfcp_fsf_status_read_handler(req
);
458 del_timer(&req
->timer
);
459 zfcp_fsf_protstatus_eval(req
);
460 zfcp_fsf_fsfstatus_eval(req
);
464 zfcp_erp_notify(req
->erp_action
, 0);
465 req
->status
|= ZFCP_STATUS_FSFREQ_COMPLETED
;
467 if (likely(req
->status
& ZFCP_STATUS_FSFREQ_CLEANUP
))
468 zfcp_fsf_req_free(req
);
470 /* notify initiator waiting for the requests completion */
472 * FIXME: Race! We must not access fsf_req here as it might have been
473 * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
474 * flag. It's an improbable case. But, we have the same paranoia for
475 * the cleanup flag already.
476 * Might better be handled using complete()?
477 * (setting the flag and doing wakeup ought to be atomic
478 * with regard to checking the flag as long as waitqueue is
479 * part of the to be released structure)
481 wake_up(&req
->completion_wq
);
484 static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req
*req
)
486 struct fsf_qtcb_bottom_config
*bottom
;
487 struct zfcp_adapter
*adapter
= req
->adapter
;
488 struct Scsi_Host
*shost
= adapter
->scsi_host
;
490 bottom
= &req
->qtcb
->bottom
.config
;
493 memcpy(req
->data
, bottom
, sizeof(*bottom
));
495 fc_host_node_name(shost
) = bottom
->nport_serv_param
.wwnn
;
496 fc_host_port_name(shost
) = bottom
->nport_serv_param
.wwpn
;
497 fc_host_port_id(shost
) = bottom
->s_id
& ZFCP_DID_MASK
;
498 fc_host_speed(shost
) = bottom
->fc_link_speed
;
499 fc_host_supported_classes(shost
) = FC_COS_CLASS2
| FC_COS_CLASS3
;
501 adapter
->hydra_version
= bottom
->adapter_type
;
502 adapter
->timer_ticks
= bottom
->timer_interval
;
504 if (fc_host_permanent_port_name(shost
) == -1)
505 fc_host_permanent_port_name(shost
) = fc_host_port_name(shost
);
507 switch (bottom
->fc_topology
) {
509 adapter
->peer_d_id
= bottom
->peer_d_id
& ZFCP_DID_MASK
;
510 adapter
->peer_wwpn
= bottom
->plogi_payload
.wwpn
;
511 adapter
->peer_wwnn
= bottom
->plogi_payload
.wwnn
;
512 fc_host_port_type(shost
) = FC_PORTTYPE_PTP
;
514 case FSF_TOPO_FABRIC
:
515 fc_host_port_type(shost
) = FC_PORTTYPE_NPORT
;
518 fc_host_port_type(shost
) = FC_PORTTYPE_NLPORT
;
520 dev_err(&adapter
->ccw_device
->dev
,
521 "Unknown or unsupported arbitrated loop "
522 "fibre channel topology detected\n");
523 zfcp_erp_adapter_shutdown(adapter
, 0, 127, req
);
530 static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req
*req
)
532 struct zfcp_adapter
*adapter
= req
->adapter
;
533 struct fsf_qtcb
*qtcb
= req
->qtcb
;
534 struct fsf_qtcb_bottom_config
*bottom
= &qtcb
->bottom
.config
;
535 struct Scsi_Host
*shost
= adapter
->scsi_host
;
537 if (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
)
540 adapter
->fsf_lic_version
= bottom
->lic_version
;
541 adapter
->adapter_features
= bottom
->adapter_features
;
542 adapter
->connection_features
= bottom
->connection_features
;
543 adapter
->peer_wwpn
= 0;
544 adapter
->peer_wwnn
= 0;
545 adapter
->peer_d_id
= 0;
547 switch (qtcb
->header
.fsf_status
) {
549 if (zfcp_fsf_exchange_config_evaluate(req
))
552 if (bottom
->max_qtcb_size
< sizeof(struct fsf_qtcb
)) {
553 dev_err(&adapter
->ccw_device
->dev
,
554 "FCP adapter maximum QTCB size (%d bytes) "
556 bottom
->max_qtcb_size
);
557 zfcp_erp_adapter_shutdown(adapter
, 0, 129, req
);
560 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK
,
563 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE
:
564 fc_host_node_name(shost
) = 0;
565 fc_host_port_name(shost
) = 0;
566 fc_host_port_id(shost
) = 0;
567 fc_host_speed(shost
) = FC_PORTSPEED_UNKNOWN
;
568 fc_host_port_type(shost
) = FC_PORTTYPE_UNKNOWN
;
569 adapter
->hydra_version
= 0;
571 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK
,
574 zfcp_fsf_link_down_info_eval(req
, 42,
575 &qtcb
->header
.fsf_status_qual
.link_down_info
);
578 zfcp_erp_adapter_shutdown(adapter
, 0, 130, req
);
582 if (adapter
->adapter_features
& FSF_FEATURE_HBAAPI_MANAGEMENT
) {
583 adapter
->hardware_version
= bottom
->hardware_version
;
584 memcpy(fc_host_serial_number(shost
), bottom
->serial_number
,
585 min(FC_SERIAL_NUMBER_SIZE
, 17));
586 EBCASC(fc_host_serial_number(shost
),
587 min(FC_SERIAL_NUMBER_SIZE
, 17));
590 if (FSF_QTCB_CURRENT_VERSION
< bottom
->low_qtcb_version
) {
591 dev_err(&adapter
->ccw_device
->dev
,
592 "The FCP adapter only supports newer "
593 "control block versions\n");
594 zfcp_erp_adapter_shutdown(adapter
, 0, 125, req
);
597 if (FSF_QTCB_CURRENT_VERSION
> bottom
->high_qtcb_version
) {
598 dev_err(&adapter
->ccw_device
->dev
,
599 "The FCP adapter only supports older "
600 "control block versions\n");
601 zfcp_erp_adapter_shutdown(adapter
, 0, 126, req
);
605 static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req
*req
)
607 struct zfcp_adapter
*adapter
= req
->adapter
;
608 struct fsf_qtcb_bottom_port
*bottom
= &req
->qtcb
->bottom
.port
;
609 struct Scsi_Host
*shost
= adapter
->scsi_host
;
612 memcpy(req
->data
, bottom
, sizeof(*bottom
));
614 if (adapter
->connection_features
& FSF_FEATURE_NPIV_MODE
)
615 fc_host_permanent_port_name(shost
) = bottom
->wwpn
;
617 fc_host_permanent_port_name(shost
) = fc_host_port_name(shost
);
618 fc_host_maxframe_size(shost
) = bottom
->maximum_frame_size
;
619 fc_host_supported_speeds(shost
) = bottom
->supported_speed
;
622 static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req
*req
)
624 struct fsf_qtcb
*qtcb
= req
->qtcb
;
626 if (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
)
629 switch (qtcb
->header
.fsf_status
) {
631 zfcp_fsf_exchange_port_evaluate(req
);
633 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE
:
634 zfcp_fsf_exchange_port_evaluate(req
);
635 zfcp_fsf_link_down_info_eval(req
, 43,
636 &qtcb
->header
.fsf_status_qual
.link_down_info
);
641 static int zfcp_fsf_sbal_check(struct zfcp_qdio_queue
*queue
)
643 spin_lock_bh(&queue
->lock
);
644 if (atomic_read(&queue
->count
))
646 spin_unlock_bh(&queue
->lock
);
650 static int zfcp_fsf_sbal_available(struct zfcp_adapter
*adapter
)
652 unsigned int count
= atomic_read(&adapter
->req_q
.count
);
654 atomic_inc(&adapter
->qdio_outb_full
);
658 static int zfcp_fsf_req_sbal_get(struct zfcp_adapter
*adapter
)
661 struct zfcp_qdio_queue
*req_q
= &adapter
->req_q
;
663 spin_unlock_bh(&req_q
->lock
);
664 ret
= wait_event_interruptible_timeout(adapter
->request_wq
,
665 zfcp_fsf_sbal_check(req_q
), 5 * HZ
);
669 atomic_inc(&adapter
->qdio_outb_full
);
671 spin_lock_bh(&req_q
->lock
);
675 static struct zfcp_fsf_req
*zfcp_fsf_alloc_noqtcb(mempool_t
*pool
)
677 struct zfcp_fsf_req
*req
;
678 req
= mempool_alloc(pool
, GFP_ATOMIC
);
681 memset(req
, 0, sizeof(*req
));
685 static struct zfcp_fsf_req
*zfcp_fsf_alloc_qtcb(mempool_t
*pool
)
687 struct zfcp_fsf_req_qtcb
*qtcb
;
690 qtcb
= mempool_alloc(pool
, GFP_ATOMIC
);
692 qtcb
= kmem_cache_alloc(zfcp_data
.fsf_req_qtcb_cache
,
697 memset(qtcb
, 0, sizeof(*qtcb
));
698 qtcb
->fsf_req
.qtcb
= &qtcb
->qtcb
;
699 qtcb
->fsf_req
.pool
= pool
;
701 return &qtcb
->fsf_req
;
704 static struct zfcp_fsf_req
*zfcp_fsf_req_create(struct zfcp_adapter
*adapter
,
705 u32 fsf_cmd
, int req_flags
,
708 struct qdio_buffer_element
*sbale
;
710 struct zfcp_fsf_req
*req
;
711 struct zfcp_qdio_queue
*req_q
= &adapter
->req_q
;
713 if (req_flags
& ZFCP_REQ_NO_QTCB
)
714 req
= zfcp_fsf_alloc_noqtcb(pool
);
716 req
= zfcp_fsf_alloc_qtcb(pool
);
719 return ERR_PTR(-EIO
);
721 if (adapter
->req_no
== 0)
724 INIT_LIST_HEAD(&req
->list
);
725 init_timer(&req
->timer
);
726 init_waitqueue_head(&req
->completion_wq
);
728 req
->adapter
= adapter
;
729 req
->fsf_command
= fsf_cmd
;
730 req
->req_id
= adapter
->req_no
++;
731 req
->sbal_number
= 1;
732 req
->sbal_first
= req_q
->first
;
733 req
->sbal_last
= req_q
->first
;
736 sbale
= zfcp_qdio_sbale_req(req
);
737 sbale
[0].addr
= (void *) req
->req_id
;
738 sbale
[0].flags
|= SBAL_FLAGS0_COMMAND
;
740 if (likely(req
->qtcb
)) {
741 req
->qtcb
->prefix
.req_seq_no
= req
->adapter
->fsf_req_seq_no
;
742 req
->qtcb
->prefix
.req_id
= req
->req_id
;
743 req
->qtcb
->prefix
.ulp_info
= 26;
744 req
->qtcb
->prefix
.qtcb_type
= fsf_qtcb_type
[req
->fsf_command
];
745 req
->qtcb
->prefix
.qtcb_version
= FSF_QTCB_CURRENT_VERSION
;
746 req
->qtcb
->header
.req_handle
= req
->req_id
;
747 req
->qtcb
->header
.fsf_command
= req
->fsf_command
;
748 req
->seq_no
= adapter
->fsf_req_seq_no
;
749 req
->qtcb
->prefix
.req_seq_no
= adapter
->fsf_req_seq_no
;
750 sbale
[1].addr
= (void *) req
->qtcb
;
751 sbale
[1].length
= sizeof(struct fsf_qtcb
);
754 if (!(atomic_read(&adapter
->status
) & ZFCP_STATUS_ADAPTER_QDIOUP
)) {
755 zfcp_fsf_req_free(req
);
756 return ERR_PTR(-EIO
);
759 if (likely(req_flags
& ZFCP_REQ_AUTO_CLEANUP
))
760 req
->status
|= ZFCP_STATUS_FSFREQ_CLEANUP
;
765 static int zfcp_fsf_req_send(struct zfcp_fsf_req
*req
)
767 struct zfcp_adapter
*adapter
= req
->adapter
;
768 struct zfcp_qdio_queue
*req_q
= &adapter
->req_q
;
771 /* put allocated FSF request into hash table */
772 spin_lock(&adapter
->req_list_lock
);
773 idx
= zfcp_reqlist_hash(req
->req_id
);
774 list_add_tail(&req
->list
, &adapter
->req_list
[idx
]);
775 spin_unlock(&adapter
->req_list_lock
);
777 req
->issued
= get_clock();
778 if (zfcp_qdio_send(req
)) {
779 /* Queues are down..... */
780 del_timer(&req
->timer
);
781 spin_lock(&adapter
->req_list_lock
);
782 zfcp_reqlist_remove(adapter
, req
);
783 spin_unlock(&adapter
->req_list_lock
);
784 /* undo changes in request queue made for this request */
785 atomic_add(req
->sbal_number
, &req_q
->count
);
786 req_q
->first
-= req
->sbal_number
;
787 req_q
->first
+= QDIO_MAX_BUFFERS_PER_Q
;
788 req_q
->first
%= QDIO_MAX_BUFFERS_PER_Q
; /* wrap */
789 zfcp_erp_adapter_reopen(adapter
, 0, 116, req
);
793 /* Don't increase for unsolicited status */
795 adapter
->fsf_req_seq_no
++;
801 * zfcp_fsf_status_read - send status read request
802 * @adapter: pointer to struct zfcp_adapter
803 * @req_flags: request flags
804 * Returns: 0 on success, ERROR otherwise
806 int zfcp_fsf_status_read(struct zfcp_adapter
*adapter
)
808 struct zfcp_fsf_req
*req
;
809 struct fsf_status_read_buffer
*sr_buf
;
810 struct qdio_buffer_element
*sbale
;
813 spin_lock_bh(&adapter
->req_q
.lock
);
814 if (zfcp_fsf_req_sbal_get(adapter
))
817 req
= zfcp_fsf_req_create(adapter
, FSF_QTCB_UNSOLICITED_STATUS
,
819 adapter
->pool
.fsf_req_status_read
);
821 retval
= PTR_ERR(req
);
825 sbale
= zfcp_qdio_sbale_req(req
);
826 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_STATUS
;
827 sbale
[2].flags
|= SBAL_FLAGS_LAST_ENTRY
;
830 sr_buf
= mempool_alloc(adapter
->pool
.data_status_read
, GFP_ATOMIC
);
835 memset(sr_buf
, 0, sizeof(*sr_buf
));
837 sbale
= zfcp_qdio_sbale_curr(req
);
838 sbale
->addr
= (void *) sr_buf
;
839 sbale
->length
= sizeof(*sr_buf
);
841 retval
= zfcp_fsf_req_send(req
);
843 goto failed_req_send
;
848 mempool_free(sr_buf
, adapter
->pool
.data_status_read
);
850 zfcp_fsf_req_free(req
);
851 zfcp_hba_dbf_event_fsf_unsol("fail", adapter
, NULL
);
853 spin_unlock_bh(&adapter
->req_q
.lock
);
857 static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req
*req
)
859 struct zfcp_unit
*unit
= req
->data
;
860 union fsf_status_qual
*fsq
= &req
->qtcb
->header
.fsf_status_qual
;
862 if (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
)
865 switch (req
->qtcb
->header
.fsf_status
) {
866 case FSF_PORT_HANDLE_NOT_VALID
:
867 if (fsq
->word
[0] == fsq
->word
[1]) {
868 zfcp_erp_adapter_reopen(unit
->port
->adapter
, 0, 104,
870 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
873 case FSF_LUN_HANDLE_NOT_VALID
:
874 if (fsq
->word
[0] == fsq
->word
[1]) {
875 zfcp_erp_port_reopen(unit
->port
, 0, 105, req
);
876 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
879 case FSF_FCP_COMMAND_DOES_NOT_EXIST
:
880 req
->status
|= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED
;
883 zfcp_erp_port_boxed(unit
->port
, 47, req
);
884 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
|
885 ZFCP_STATUS_FSFREQ_RETRY
;
888 zfcp_erp_unit_boxed(unit
, 48, req
);
889 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
|
890 ZFCP_STATUS_FSFREQ_RETRY
;
892 case FSF_ADAPTER_STATUS_AVAILABLE
:
893 switch (fsq
->word
[0]) {
894 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE
:
895 zfcp_test_link(unit
->port
);
896 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED
:
897 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
902 req
->status
|= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED
;
908 * zfcp_fsf_abort_fcp_command - abort running SCSI command
909 * @old_req_id: unsigned long
910 * @adapter: pointer to struct zfcp_adapter
911 * @unit: pointer to struct zfcp_unit
912 * @req_flags: integer specifying the request flags
913 * Returns: pointer to struct zfcp_fsf_req
915 * FIXME(design): should be watched by a timeout !!!
918 struct zfcp_fsf_req
*zfcp_fsf_abort_fcp_command(unsigned long old_req_id
,
919 struct zfcp_adapter
*adapter
,
920 struct zfcp_unit
*unit
,
923 struct qdio_buffer_element
*sbale
;
924 struct zfcp_fsf_req
*req
= NULL
;
926 spin_lock(&adapter
->req_q
.lock
);
927 if (!zfcp_fsf_sbal_available(adapter
))
929 req
= zfcp_fsf_req_create(adapter
, FSF_QTCB_ABORT_FCP_CMND
,
930 req_flags
, adapter
->pool
.fsf_req_abort
);
934 if (unlikely(!(atomic_read(&unit
->status
) &
935 ZFCP_STATUS_COMMON_UNBLOCKED
)))
938 sbale
= zfcp_qdio_sbale_req(req
);
939 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_READ
;
940 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
943 req
->handler
= zfcp_fsf_abort_fcp_command_handler
;
944 req
->qtcb
->header
.lun_handle
= unit
->handle
;
945 req
->qtcb
->header
.port_handle
= unit
->port
->handle
;
946 req
->qtcb
->bottom
.support
.req_handle
= (u64
) old_req_id
;
948 zfcp_fsf_start_timer(req
, ZFCP_SCSI_ER_TIMEOUT
);
949 if (!zfcp_fsf_req_send(req
))
953 zfcp_fsf_req_free(req
);
956 spin_unlock(&adapter
->req_q
.lock
);
960 static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req
*req
)
962 struct zfcp_adapter
*adapter
= req
->adapter
;
963 struct zfcp_send_ct
*send_ct
= req
->data
;
964 struct fsf_qtcb_header
*header
= &req
->qtcb
->header
;
966 send_ct
->status
= -EINVAL
;
968 if (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
)
971 switch (header
->fsf_status
) {
973 zfcp_san_dbf_event_ct_response(req
);
976 case FSF_SERVICE_CLASS_NOT_SUPPORTED
:
977 zfcp_fsf_class_not_supp(req
);
979 case FSF_ADAPTER_STATUS_AVAILABLE
:
980 switch (header
->fsf_status_qual
.word
[0]){
981 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE
:
982 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED
:
983 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
987 case FSF_ACCESS_DENIED
:
990 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
|
991 ZFCP_STATUS_FSFREQ_RETRY
;
993 case FSF_PORT_HANDLE_NOT_VALID
:
994 zfcp_erp_adapter_reopen(adapter
, 0, 106, req
);
995 case FSF_GENERIC_COMMAND_REJECTED
:
996 case FSF_PAYLOAD_SIZE_MISMATCH
:
997 case FSF_REQUEST_SIZE_TOO_LARGE
:
998 case FSF_RESPONSE_SIZE_TOO_LARGE
:
999 case FSF_SBAL_MISMATCH
:
1000 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1005 if (send_ct
->handler
)
1006 send_ct
->handler(send_ct
->handler_data
);
1009 static int zfcp_fsf_setup_sbals(struct zfcp_fsf_req
*req
,
1010 struct scatterlist
*sg_req
,
1011 struct scatterlist
*sg_resp
, int max_sbals
)
1015 bytes
= zfcp_qdio_sbals_from_sg(req
, SBAL_FLAGS0_TYPE_WRITE_READ
,
1019 req
->qtcb
->bottom
.support
.req_buf_length
= bytes
;
1020 req
->sbale_curr
= ZFCP_LAST_SBALE_PER_SBAL
;
1022 bytes
= zfcp_qdio_sbals_from_sg(req
, SBAL_FLAGS0_TYPE_WRITE_READ
,
1023 sg_resp
, max_sbals
);
1026 req
->qtcb
->bottom
.support
.resp_buf_length
= bytes
;
1032 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1033 * @ct: pointer to struct zfcp_send_ct with data for request
1034 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1035 * @erp_action: if non-null the Generic Service request sent within ERP
1037 int zfcp_fsf_send_ct(struct zfcp_send_ct
*ct
, mempool_t
*pool
,
1038 struct zfcp_erp_action
*erp_action
)
1040 struct zfcp_wka_port
*wka_port
= ct
->wka_port
;
1041 struct zfcp_adapter
*adapter
= wka_port
->adapter
;
1042 struct zfcp_fsf_req
*req
;
1045 spin_lock_bh(&adapter
->req_q
.lock
);
1046 if (zfcp_fsf_req_sbal_get(adapter
))
1049 req
= zfcp_fsf_req_create(adapter
, FSF_QTCB_SEND_GENERIC
,
1050 ZFCP_REQ_AUTO_CLEANUP
, pool
);
1056 ret
= zfcp_fsf_setup_sbals(req
, ct
->req
, ct
->resp
,
1057 FSF_MAX_SBALS_PER_REQ
);
1061 req
->handler
= zfcp_fsf_send_ct_handler
;
1062 req
->qtcb
->header
.port_handle
= wka_port
->handle
;
1063 req
->qtcb
->bottom
.support
.service_class
= FSF_CLASS_3
;
1064 req
->qtcb
->bottom
.support
.timeout
= ct
->timeout
;
1067 zfcp_san_dbf_event_ct_request(req
);
1070 erp_action
->fsf_req
= req
;
1071 req
->erp_action
= erp_action
;
1072 zfcp_fsf_start_erp_timer(req
);
1074 zfcp_fsf_start_timer(req
, ZFCP_FSF_REQUEST_TIMEOUT
);
1076 ret
= zfcp_fsf_req_send(req
);
1083 zfcp_fsf_req_free(req
);
1085 erp_action
->fsf_req
= NULL
;
1087 spin_unlock_bh(&adapter
->req_q
.lock
);
1091 static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req
*req
)
1093 struct zfcp_send_els
*send_els
= req
->data
;
1094 struct zfcp_port
*port
= send_els
->port
;
1095 struct fsf_qtcb_header
*header
= &req
->qtcb
->header
;
1097 send_els
->status
= -EINVAL
;
1099 if (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
)
1100 goto skip_fsfstatus
;
1102 switch (header
->fsf_status
) {
1104 zfcp_san_dbf_event_els_response(req
);
1105 send_els
->status
= 0;
1107 case FSF_SERVICE_CLASS_NOT_SUPPORTED
:
1108 zfcp_fsf_class_not_supp(req
);
1110 case FSF_ADAPTER_STATUS_AVAILABLE
:
1111 switch (header
->fsf_status_qual
.word
[0]){
1112 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE
:
1113 if (port
&& (send_els
->ls_code
!= ZFCP_LS_ADISC
))
1114 zfcp_test_link(port
);
1116 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED
:
1117 case FSF_SQ_RETRY_IF_POSSIBLE
:
1118 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1122 case FSF_ELS_COMMAND_REJECTED
:
1123 case FSF_PAYLOAD_SIZE_MISMATCH
:
1124 case FSF_REQUEST_SIZE_TOO_LARGE
:
1125 case FSF_RESPONSE_SIZE_TOO_LARGE
:
1127 case FSF_ACCESS_DENIED
:
1128 zfcp_fsf_access_denied_port(req
, port
);
1130 case FSF_SBAL_MISMATCH
:
1131 /* should never occure, avoided in zfcp_fsf_send_els */
1134 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1138 if (send_els
->handler
)
1139 send_els
->handler(send_els
->handler_data
);
1143 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1144 * @els: pointer to struct zfcp_send_els with data for the command
1146 int zfcp_fsf_send_els(struct zfcp_send_els
*els
)
1148 struct zfcp_fsf_req
*req
;
1149 struct zfcp_adapter
*adapter
= els
->adapter
;
1150 struct fsf_qtcb_bottom_support
*bottom
;
1153 if (unlikely(!(atomic_read(&els
->port
->status
) &
1154 ZFCP_STATUS_COMMON_UNBLOCKED
)))
1157 spin_lock(&adapter
->req_q
.lock
);
1158 if (!zfcp_fsf_sbal_available(adapter
))
1160 req
= zfcp_fsf_req_create(adapter
, FSF_QTCB_SEND_ELS
,
1161 ZFCP_REQ_AUTO_CLEANUP
, NULL
);
1167 ret
= zfcp_fsf_setup_sbals(req
, els
->req
, els
->resp
, 2);
1172 bottom
= &req
->qtcb
->bottom
.support
;
1173 req
->handler
= zfcp_fsf_send_els_handler
;
1174 bottom
->d_id
= els
->d_id
;
1175 bottom
->service_class
= FSF_CLASS_3
;
1176 bottom
->timeout
= 2 * R_A_TOV
;
1179 zfcp_san_dbf_event_els_request(req
);
1181 zfcp_fsf_start_timer(req
, ZFCP_FSF_REQUEST_TIMEOUT
);
1182 ret
= zfcp_fsf_req_send(req
);
1189 zfcp_fsf_req_free(req
);
1191 spin_unlock(&adapter
->req_q
.lock
);
1195 int zfcp_fsf_exchange_config_data(struct zfcp_erp_action
*erp_action
)
1197 struct qdio_buffer_element
*sbale
;
1198 struct zfcp_fsf_req
*req
;
1199 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1202 spin_lock_bh(&adapter
->req_q
.lock
);
1203 if (!zfcp_fsf_sbal_available(adapter
))
1205 req
= zfcp_fsf_req_create(adapter
,
1206 FSF_QTCB_EXCHANGE_CONFIG_DATA
,
1207 ZFCP_REQ_AUTO_CLEANUP
,
1208 adapter
->pool
.fsf_req_erp
);
1210 retval
= PTR_ERR(req
);
1214 sbale
= zfcp_qdio_sbale_req(req
);
1215 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_READ
;
1216 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
1218 req
->qtcb
->bottom
.config
.feature_selection
=
1220 FSF_FEATURE_LUN_SHARING
|
1221 FSF_FEATURE_NOTIFICATION_LOST
|
1222 FSF_FEATURE_UPDATE_ALERT
;
1223 req
->erp_action
= erp_action
;
1224 req
->handler
= zfcp_fsf_exchange_config_data_handler
;
1225 erp_action
->fsf_req
= req
;
1227 zfcp_fsf_start_erp_timer(req
);
1228 retval
= zfcp_fsf_req_send(req
);
1230 zfcp_fsf_req_free(req
);
1231 erp_action
->fsf_req
= NULL
;
1234 spin_unlock_bh(&adapter
->req_q
.lock
);
1238 int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter
*adapter
,
1239 struct fsf_qtcb_bottom_config
*data
)
1241 struct qdio_buffer_element
*sbale
;
1242 struct zfcp_fsf_req
*req
= NULL
;
1245 spin_lock_bh(&adapter
->req_q
.lock
);
1246 if (zfcp_fsf_req_sbal_get(adapter
))
1249 req
= zfcp_fsf_req_create(adapter
, FSF_QTCB_EXCHANGE_CONFIG_DATA
,
1252 retval
= PTR_ERR(req
);
1256 sbale
= zfcp_qdio_sbale_req(req
);
1257 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_READ
;
1258 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
1259 req
->handler
= zfcp_fsf_exchange_config_data_handler
;
1261 req
->qtcb
->bottom
.config
.feature_selection
=
1263 FSF_FEATURE_LUN_SHARING
|
1264 FSF_FEATURE_NOTIFICATION_LOST
|
1265 FSF_FEATURE_UPDATE_ALERT
;
1270 zfcp_fsf_start_timer(req
, ZFCP_FSF_REQUEST_TIMEOUT
);
1271 retval
= zfcp_fsf_req_send(req
);
1273 spin_unlock_bh(&adapter
->req_q
.lock
);
1275 wait_event(req
->completion_wq
,
1276 req
->status
& ZFCP_STATUS_FSFREQ_COMPLETED
);
1278 zfcp_fsf_req_free(req
);
1284 * zfcp_fsf_exchange_port_data - request information about local port
1285 * @erp_action: ERP action for the adapter for which port data is requested
1286 * Returns: 0 on success, error otherwise
1288 int zfcp_fsf_exchange_port_data(struct zfcp_erp_action
*erp_action
)
1290 struct qdio_buffer_element
*sbale
;
1291 struct zfcp_fsf_req
*req
;
1292 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1295 if (!(adapter
->adapter_features
& FSF_FEATURE_HBAAPI_MANAGEMENT
))
1298 spin_lock_bh(&adapter
->req_q
.lock
);
1299 if (!zfcp_fsf_sbal_available(adapter
))
1301 req
= zfcp_fsf_req_create(adapter
, FSF_QTCB_EXCHANGE_PORT_DATA
,
1302 ZFCP_REQ_AUTO_CLEANUP
,
1303 adapter
->pool
.fsf_req_erp
);
1305 retval
= PTR_ERR(req
);
1309 sbale
= zfcp_qdio_sbale_req(req
);
1310 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_READ
;
1311 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
1313 req
->handler
= zfcp_fsf_exchange_port_data_handler
;
1314 req
->erp_action
= erp_action
;
1315 erp_action
->fsf_req
= req
;
1317 zfcp_fsf_start_erp_timer(req
);
1318 retval
= zfcp_fsf_req_send(req
);
1320 zfcp_fsf_req_free(req
);
1321 erp_action
->fsf_req
= NULL
;
1324 spin_unlock_bh(&adapter
->req_q
.lock
);
1329 * zfcp_fsf_exchange_port_data_sync - request information about local port
1330 * @adapter: pointer to struct zfcp_adapter
1331 * @data: pointer to struct fsf_qtcb_bottom_port
1332 * Returns: 0 on success, error otherwise
1334 int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter
*adapter
,
1335 struct fsf_qtcb_bottom_port
*data
)
1337 struct qdio_buffer_element
*sbale
;
1338 struct zfcp_fsf_req
*req
= NULL
;
1341 if (!(adapter
->adapter_features
& FSF_FEATURE_HBAAPI_MANAGEMENT
))
1344 spin_lock_bh(&adapter
->req_q
.lock
);
1345 if (!zfcp_fsf_sbal_available(adapter
))
1348 req
= zfcp_fsf_req_create(adapter
, FSF_QTCB_EXCHANGE_PORT_DATA
, 0,
1351 retval
= PTR_ERR(req
);
1358 sbale
= zfcp_qdio_sbale_req(req
);
1359 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_READ
;
1360 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
1362 req
->handler
= zfcp_fsf_exchange_port_data_handler
;
1363 zfcp_fsf_start_timer(req
, ZFCP_FSF_REQUEST_TIMEOUT
);
1364 retval
= zfcp_fsf_req_send(req
);
1366 spin_unlock_bh(&adapter
->req_q
.lock
);
1368 wait_event(req
->completion_wq
,
1369 req
->status
& ZFCP_STATUS_FSFREQ_COMPLETED
);
1370 zfcp_fsf_req_free(req
);
1375 static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req
*req
)
1377 struct zfcp_port
*port
= req
->data
;
1378 struct fsf_qtcb_header
*header
= &req
->qtcb
->header
;
1379 struct fsf_plogi
*plogi
;
1381 if (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
)
1384 switch (header
->fsf_status
) {
1385 case FSF_PORT_ALREADY_OPEN
:
1387 case FSF_ACCESS_DENIED
:
1388 zfcp_fsf_access_denied_port(req
, port
);
1390 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED
:
1391 dev_warn(&req
->adapter
->ccw_device
->dev
,
1392 "Not enough FCP adapter resources to open "
1393 "remote port 0x%016Lx\n", port
->wwpn
);
1394 zfcp_erp_port_failed(port
, 31, req
);
1395 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1397 case FSF_ADAPTER_STATUS_AVAILABLE
:
1398 switch (header
->fsf_status_qual
.word
[0]) {
1399 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE
:
1400 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED
:
1401 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1403 case FSF_SQ_NO_RETRY_POSSIBLE
:
1404 dev_warn(&req
->adapter
->ccw_device
->dev
,
1405 "Remote port 0x%016Lx could not be opened\n",
1407 zfcp_erp_port_failed(port
, 32, req
);
1408 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1413 port
->handle
= header
->port_handle
;
1414 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN
|
1415 ZFCP_STATUS_PORT_PHYS_OPEN
, &port
->status
);
1416 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED
|
1417 ZFCP_STATUS_COMMON_ACCESS_BOXED
,
1419 /* check whether D_ID has changed during open */
1421 * FIXME: This check is not airtight, as the FCP channel does
1422 * not monitor closures of target port connections caused on
1423 * the remote side. Thus, they might miss out on invalidating
1424 * locally cached WWPNs (and other N_Port parameters) of gone
1425 * target ports. So, our heroic attempt to make things safe
1426 * could be undermined by 'open port' response data tagged with
1427 * obsolete WWPNs. Another reason to monitor potential
1428 * connection closures ourself at least (by interpreting
1429 * incoming ELS' and unsolicited status). It just crosses my
1430 * mind that one should be able to cross-check by means of
1431 * another GID_PN straight after a port has been opened.
1432 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1434 plogi
= (struct fsf_plogi
*) req
->qtcb
->bottom
.support
.els
;
1435 if (req
->qtcb
->bottom
.support
.els1_length
>= sizeof(*plogi
)) {
1436 if (plogi
->serv_param
.wwpn
!= port
->wwpn
)
1437 atomic_clear_mask(ZFCP_STATUS_PORT_DID_DID
,
1440 port
->wwnn
= plogi
->serv_param
.wwnn
;
1441 zfcp_fc_plogi_evaluate(port
, plogi
);
1445 case FSF_UNKNOWN_OP_SUBTYPE
:
1446 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1452 * zfcp_fsf_open_port - create and send open port request
1453 * @erp_action: pointer to struct zfcp_erp_action
1454 * Returns: 0 on success, error otherwise
1456 int zfcp_fsf_open_port(struct zfcp_erp_action
*erp_action
)
1458 struct qdio_buffer_element
*sbale
;
1459 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1460 struct zfcp_fsf_req
*req
;
1463 spin_lock_bh(&adapter
->req_q
.lock
);
1464 if (zfcp_fsf_req_sbal_get(adapter
))
1467 req
= zfcp_fsf_req_create(adapter
,
1468 FSF_QTCB_OPEN_PORT_WITH_DID
,
1469 ZFCP_REQ_AUTO_CLEANUP
,
1470 adapter
->pool
.fsf_req_erp
);
1472 retval
= PTR_ERR(req
);
1476 sbale
= zfcp_qdio_sbale_req(req
);
1477 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_READ
;
1478 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
1480 req
->handler
= zfcp_fsf_open_port_handler
;
1481 req
->qtcb
->bottom
.support
.d_id
= erp_action
->port
->d_id
;
1482 req
->data
= erp_action
->port
;
1483 req
->erp_action
= erp_action
;
1484 erp_action
->fsf_req
= req
;
1486 zfcp_fsf_start_erp_timer(req
);
1487 retval
= zfcp_fsf_req_send(req
);
1489 zfcp_fsf_req_free(req
);
1490 erp_action
->fsf_req
= NULL
;
1493 spin_unlock_bh(&adapter
->req_q
.lock
);
1497 static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req
*req
)
1499 struct zfcp_port
*port
= req
->data
;
1501 if (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
)
1504 switch (req
->qtcb
->header
.fsf_status
) {
1505 case FSF_PORT_HANDLE_NOT_VALID
:
1506 zfcp_erp_adapter_reopen(port
->adapter
, 0, 107, req
);
1507 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1509 case FSF_ADAPTER_STATUS_AVAILABLE
:
1512 zfcp_erp_modify_port_status(port
, 33, req
,
1513 ZFCP_STATUS_COMMON_OPEN
,
1520 * zfcp_fsf_close_port - create and send close port request
1521 * @erp_action: pointer to struct zfcp_erp_action
1522 * Returns: 0 on success, error otherwise
1524 int zfcp_fsf_close_port(struct zfcp_erp_action
*erp_action
)
1526 struct qdio_buffer_element
*sbale
;
1527 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1528 struct zfcp_fsf_req
*req
;
1531 spin_lock_bh(&adapter
->req_q
.lock
);
1532 if (zfcp_fsf_req_sbal_get(adapter
))
1535 req
= zfcp_fsf_req_create(adapter
, FSF_QTCB_CLOSE_PORT
,
1536 ZFCP_REQ_AUTO_CLEANUP
,
1537 adapter
->pool
.fsf_req_erp
);
1539 retval
= PTR_ERR(req
);
1543 sbale
= zfcp_qdio_sbale_req(req
);
1544 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_READ
;
1545 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
1547 req
->handler
= zfcp_fsf_close_port_handler
;
1548 req
->data
= erp_action
->port
;
1549 req
->erp_action
= erp_action
;
1550 req
->qtcb
->header
.port_handle
= erp_action
->port
->handle
;
1551 erp_action
->fsf_req
= req
;
1553 zfcp_fsf_start_erp_timer(req
);
1554 retval
= zfcp_fsf_req_send(req
);
1556 zfcp_fsf_req_free(req
);
1557 erp_action
->fsf_req
= NULL
;
1560 spin_unlock_bh(&adapter
->req_q
.lock
);
1564 static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req
*req
)
1566 struct zfcp_wka_port
*wka_port
= req
->data
;
1567 struct fsf_qtcb_header
*header
= &req
->qtcb
->header
;
1569 if (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
) {
1570 wka_port
->status
= ZFCP_WKA_PORT_OFFLINE
;
1574 switch (header
->fsf_status
) {
1575 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED
:
1576 dev_warn(&req
->adapter
->ccw_device
->dev
,
1577 "Opening WKA port 0x%x failed\n", wka_port
->d_id
);
1578 case FSF_ADAPTER_STATUS_AVAILABLE
:
1579 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1580 case FSF_ACCESS_DENIED
:
1581 wka_port
->status
= ZFCP_WKA_PORT_OFFLINE
;
1583 case FSF_PORT_ALREADY_OPEN
:
1585 wka_port
->handle
= header
->port_handle
;
1586 wka_port
->status
= ZFCP_WKA_PORT_ONLINE
;
1589 wake_up(&wka_port
->completion_wq
);
1593 * zfcp_fsf_open_wka_port - create and send open wka-port request
1594 * @wka_port: pointer to struct zfcp_wka_port
1595 * Returns: 0 on success, error otherwise
1597 int zfcp_fsf_open_wka_port(struct zfcp_wka_port
*wka_port
)
1599 struct qdio_buffer_element
*sbale
;
1600 struct zfcp_adapter
*adapter
= wka_port
->adapter
;
1601 struct zfcp_fsf_req
*req
;
1604 spin_lock_bh(&adapter
->req_q
.lock
);
1605 if (zfcp_fsf_req_sbal_get(adapter
))
1608 req
= zfcp_fsf_req_create(adapter
,
1609 FSF_QTCB_OPEN_PORT_WITH_DID
,
1610 ZFCP_REQ_AUTO_CLEANUP
,
1611 adapter
->pool
.fsf_req_erp
);
1612 if (unlikely(IS_ERR(req
))) {
1613 retval
= PTR_ERR(req
);
1617 sbale
= zfcp_qdio_sbale_req(req
);
1618 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_READ
;
1619 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
1621 req
->handler
= zfcp_fsf_open_wka_port_handler
;
1622 req
->qtcb
->bottom
.support
.d_id
= wka_port
->d_id
;
1623 req
->data
= wka_port
;
1625 zfcp_fsf_start_timer(req
, ZFCP_FSF_REQUEST_TIMEOUT
);
1626 retval
= zfcp_fsf_req_send(req
);
1628 zfcp_fsf_req_free(req
);
1630 spin_unlock_bh(&adapter
->req_q
.lock
);
1634 static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req
*req
)
1636 struct zfcp_wka_port
*wka_port
= req
->data
;
1638 if (req
->qtcb
->header
.fsf_status
== FSF_PORT_HANDLE_NOT_VALID
) {
1639 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1640 zfcp_erp_adapter_reopen(wka_port
->adapter
, 0, 107, req
);
1643 wka_port
->status
= ZFCP_WKA_PORT_OFFLINE
;
1644 wake_up(&wka_port
->completion_wq
);
1648 * zfcp_fsf_close_wka_port - create and send close wka port request
1649 * @erp_action: pointer to struct zfcp_erp_action
1650 * Returns: 0 on success, error otherwise
1652 int zfcp_fsf_close_wka_port(struct zfcp_wka_port
*wka_port
)
1654 struct qdio_buffer_element
*sbale
;
1655 struct zfcp_adapter
*adapter
= wka_port
->adapter
;
1656 struct zfcp_fsf_req
*req
;
1659 spin_lock_bh(&adapter
->req_q
.lock
);
1660 if (zfcp_fsf_req_sbal_get(adapter
))
1663 req
= zfcp_fsf_req_create(adapter
, FSF_QTCB_CLOSE_PORT
,
1664 ZFCP_REQ_AUTO_CLEANUP
,
1665 adapter
->pool
.fsf_req_erp
);
1666 if (unlikely(IS_ERR(req
))) {
1667 retval
= PTR_ERR(req
);
1671 sbale
= zfcp_qdio_sbale_req(req
);
1672 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_READ
;
1673 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
1675 req
->handler
= zfcp_fsf_close_wka_port_handler
;
1676 req
->data
= wka_port
;
1677 req
->qtcb
->header
.port_handle
= wka_port
->handle
;
1679 zfcp_fsf_start_timer(req
, ZFCP_FSF_REQUEST_TIMEOUT
);
1680 retval
= zfcp_fsf_req_send(req
);
1682 zfcp_fsf_req_free(req
);
1684 spin_unlock_bh(&adapter
->req_q
.lock
);
1688 static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req
*req
)
1690 struct zfcp_port
*port
= req
->data
;
1691 struct fsf_qtcb_header
*header
= &req
->qtcb
->header
;
1692 struct zfcp_unit
*unit
;
1694 if (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
)
1695 goto skip_fsfstatus
;
1697 switch (header
->fsf_status
) {
1698 case FSF_PORT_HANDLE_NOT_VALID
:
1699 zfcp_erp_adapter_reopen(port
->adapter
, 0, 108, req
);
1700 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1702 case FSF_ACCESS_DENIED
:
1703 zfcp_fsf_access_denied_port(req
, port
);
1705 case FSF_PORT_BOXED
:
1706 zfcp_erp_port_boxed(port
, 50, req
);
1707 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
|
1708 ZFCP_STATUS_FSFREQ_RETRY
;
1709 /* can't use generic zfcp_erp_modify_port_status because
1710 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1711 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN
, &port
->status
);
1712 list_for_each_entry(unit
, &port
->unit_list_head
, list
)
1713 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN
,
1716 case FSF_ADAPTER_STATUS_AVAILABLE
:
1717 switch (header
->fsf_status_qual
.word
[0]) {
1718 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE
:
1720 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED
:
1721 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1726 /* can't use generic zfcp_erp_modify_port_status because
1727 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1729 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN
, &port
->status
);
1730 list_for_each_entry(unit
, &port
->unit_list_head
, list
)
1731 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN
,
1736 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING
, &port
->status
);
1740 * zfcp_fsf_close_physical_port - close physical port
1741 * @erp_action: pointer to struct zfcp_erp_action
1742 * Returns: 0 on success
1744 int zfcp_fsf_close_physical_port(struct zfcp_erp_action
*erp_action
)
1746 struct qdio_buffer_element
*sbale
;
1747 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1748 struct zfcp_fsf_req
*req
;
1751 spin_lock_bh(&adapter
->req_q
.lock
);
1752 if (zfcp_fsf_req_sbal_get(adapter
))
1755 req
= zfcp_fsf_req_create(adapter
, FSF_QTCB_CLOSE_PHYSICAL_PORT
,
1756 ZFCP_REQ_AUTO_CLEANUP
,
1757 adapter
->pool
.fsf_req_erp
);
1759 retval
= PTR_ERR(req
);
1763 sbale
= zfcp_qdio_sbale_req(req
);
1764 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_READ
;
1765 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
1767 req
->data
= erp_action
->port
;
1768 req
->qtcb
->header
.port_handle
= erp_action
->port
->handle
;
1769 req
->erp_action
= erp_action
;
1770 req
->handler
= zfcp_fsf_close_physical_port_handler
;
1771 erp_action
->fsf_req
= req
;
1772 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING
,
1773 &erp_action
->port
->status
);
1775 zfcp_fsf_start_erp_timer(req
);
1776 retval
= zfcp_fsf_req_send(req
);
1778 zfcp_fsf_req_free(req
);
1779 erp_action
->fsf_req
= NULL
;
1782 spin_unlock_bh(&adapter
->req_q
.lock
);
1786 static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req
*req
)
1788 struct zfcp_adapter
*adapter
= req
->adapter
;
1789 struct zfcp_unit
*unit
= req
->data
;
1790 struct fsf_qtcb_header
*header
= &req
->qtcb
->header
;
1791 struct fsf_qtcb_bottom_support
*bottom
= &req
->qtcb
->bottom
.support
;
1792 struct fsf_queue_designator
*queue_designator
=
1793 &header
->fsf_status_qual
.fsf_queue_designator
;
1794 int exclusive
, readwrite
;
1796 if (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
)
1799 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED
|
1800 ZFCP_STATUS_COMMON_ACCESS_BOXED
|
1801 ZFCP_STATUS_UNIT_SHARED
|
1802 ZFCP_STATUS_UNIT_READONLY
,
1805 switch (header
->fsf_status
) {
1807 case FSF_PORT_HANDLE_NOT_VALID
:
1808 zfcp_erp_adapter_reopen(unit
->port
->adapter
, 0, 109, req
);
1810 case FSF_LUN_ALREADY_OPEN
:
1812 case FSF_ACCESS_DENIED
:
1813 zfcp_fsf_access_denied_unit(req
, unit
);
1814 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED
, &unit
->status
);
1815 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY
, &unit
->status
);
1817 case FSF_PORT_BOXED
:
1818 zfcp_erp_port_boxed(unit
->port
, 51, req
);
1819 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
|
1820 ZFCP_STATUS_FSFREQ_RETRY
;
1822 case FSF_LUN_SHARING_VIOLATION
:
1823 if (header
->fsf_status_qual
.word
[0])
1824 dev_warn(&adapter
->ccw_device
->dev
,
1825 "LUN 0x%Lx on port 0x%Lx is already in "
1826 "use by CSS%d, MIF Image ID %x\n",
1829 queue_designator
->cssid
,
1830 queue_designator
->hla
);
1832 zfcp_act_eval_err(adapter
,
1833 header
->fsf_status_qual
.word
[2]);
1834 zfcp_erp_unit_access_denied(unit
, 60, req
);
1835 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED
, &unit
->status
);
1836 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY
, &unit
->status
);
1837 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1839 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED
:
1840 dev_warn(&adapter
->ccw_device
->dev
,
1841 "No handle is available for LUN "
1842 "0x%016Lx on port 0x%016Lx\n",
1843 unit
->fcp_lun
, unit
->port
->wwpn
);
1844 zfcp_erp_unit_failed(unit
, 34, req
);
1846 case FSF_INVALID_COMMAND_OPTION
:
1847 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1849 case FSF_ADAPTER_STATUS_AVAILABLE
:
1850 switch (header
->fsf_status_qual
.word
[0]) {
1851 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE
:
1852 zfcp_test_link(unit
->port
);
1854 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED
:
1855 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1861 unit
->handle
= header
->lun_handle
;
1862 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN
, &unit
->status
);
1864 if (!(adapter
->connection_features
& FSF_FEATURE_NPIV_MODE
) &&
1865 (adapter
->adapter_features
& FSF_FEATURE_LUN_SHARING
) &&
1866 (adapter
->ccw_device
->id
.dev_model
!= ZFCP_DEVICE_MODEL_PRIV
)) {
1867 exclusive
= (bottom
->lun_access_info
&
1868 FSF_UNIT_ACCESS_EXCLUSIVE
);
1869 readwrite
= (bottom
->lun_access_info
&
1870 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER
);
1873 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED
,
1877 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY
,
1879 dev_info(&adapter
->ccw_device
->dev
,
1880 "SCSI device at LUN 0x%016Lx on port "
1881 "0x%016Lx opened read-only\n",
1882 unit
->fcp_lun
, unit
->port
->wwpn
);
1885 if (exclusive
&& !readwrite
) {
1886 dev_err(&adapter
->ccw_device
->dev
,
1887 "Exclusive read-only access not "
1888 "supported (unit 0x%016Lx, "
1890 unit
->fcp_lun
, unit
->port
->wwpn
);
1891 zfcp_erp_unit_failed(unit
, 35, req
);
1892 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1893 zfcp_erp_unit_shutdown(unit
, 0, 80, req
);
1894 } else if (!exclusive
&& readwrite
) {
1895 dev_err(&adapter
->ccw_device
->dev
,
1896 "Shared read-write access not "
1897 "supported (unit 0x%016Lx, port "
1899 unit
->fcp_lun
, unit
->port
->wwpn
);
1900 zfcp_erp_unit_failed(unit
, 36, req
);
1901 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1902 zfcp_erp_unit_shutdown(unit
, 0, 81, req
);
1910 * zfcp_fsf_open_unit - open unit
1911 * @erp_action: pointer to struct zfcp_erp_action
1912 * Returns: 0 on success, error otherwise
1914 int zfcp_fsf_open_unit(struct zfcp_erp_action
*erp_action
)
1916 struct qdio_buffer_element
*sbale
;
1917 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1918 struct zfcp_fsf_req
*req
;
1921 spin_lock_bh(&adapter
->req_q
.lock
);
1922 if (zfcp_fsf_req_sbal_get(adapter
))
1925 req
= zfcp_fsf_req_create(adapter
, FSF_QTCB_OPEN_LUN
,
1926 ZFCP_REQ_AUTO_CLEANUP
,
1927 adapter
->pool
.fsf_req_erp
);
1929 retval
= PTR_ERR(req
);
1933 sbale
= zfcp_qdio_sbale_req(req
);
1934 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_READ
;
1935 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
1937 req
->qtcb
->header
.port_handle
= erp_action
->port
->handle
;
1938 req
->qtcb
->bottom
.support
.fcp_lun
= erp_action
->unit
->fcp_lun
;
1939 req
->handler
= zfcp_fsf_open_unit_handler
;
1940 req
->data
= erp_action
->unit
;
1941 req
->erp_action
= erp_action
;
1942 erp_action
->fsf_req
= req
;
1944 if (!(adapter
->connection_features
& FSF_FEATURE_NPIV_MODE
))
1945 req
->qtcb
->bottom
.support
.option
= FSF_OPEN_LUN_SUPPRESS_BOXING
;
1947 zfcp_fsf_start_erp_timer(req
);
1948 retval
= zfcp_fsf_req_send(req
);
1950 zfcp_fsf_req_free(req
);
1951 erp_action
->fsf_req
= NULL
;
1954 spin_unlock_bh(&adapter
->req_q
.lock
);
1958 static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req
*req
)
1960 struct zfcp_unit
*unit
= req
->data
;
1962 if (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
)
1965 switch (req
->qtcb
->header
.fsf_status
) {
1966 case FSF_PORT_HANDLE_NOT_VALID
:
1967 zfcp_erp_adapter_reopen(unit
->port
->adapter
, 0, 110, req
);
1968 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1970 case FSF_LUN_HANDLE_NOT_VALID
:
1971 zfcp_erp_port_reopen(unit
->port
, 0, 111, req
);
1972 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1974 case FSF_PORT_BOXED
:
1975 zfcp_erp_port_boxed(unit
->port
, 52, req
);
1976 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
|
1977 ZFCP_STATUS_FSFREQ_RETRY
;
1979 case FSF_ADAPTER_STATUS_AVAILABLE
:
1980 switch (req
->qtcb
->header
.fsf_status_qual
.word
[0]) {
1981 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE
:
1982 zfcp_test_link(unit
->port
);
1984 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED
:
1985 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
1990 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN
, &unit
->status
);
1996 * zfcp_fsf_close_unit - close zfcp unit
1997 * @erp_action: pointer to struct zfcp_unit
1998 * Returns: 0 on success, error otherwise
2000 int zfcp_fsf_close_unit(struct zfcp_erp_action
*erp_action
)
2002 struct qdio_buffer_element
*sbale
;
2003 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
2004 struct zfcp_fsf_req
*req
;
2007 spin_lock_bh(&adapter
->req_q
.lock
);
2008 if (zfcp_fsf_req_sbal_get(adapter
))
2010 req
= zfcp_fsf_req_create(adapter
, FSF_QTCB_CLOSE_LUN
,
2011 ZFCP_REQ_AUTO_CLEANUP
,
2012 adapter
->pool
.fsf_req_erp
);
2014 retval
= PTR_ERR(req
);
2018 sbale
= zfcp_qdio_sbale_req(req
);
2019 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_READ
;
2020 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
2022 req
->qtcb
->header
.port_handle
= erp_action
->port
->handle
;
2023 req
->qtcb
->header
.lun_handle
= erp_action
->unit
->handle
;
2024 req
->handler
= zfcp_fsf_close_unit_handler
;
2025 req
->data
= erp_action
->unit
;
2026 req
->erp_action
= erp_action
;
2027 erp_action
->fsf_req
= req
;
2029 zfcp_fsf_start_erp_timer(req
);
2030 retval
= zfcp_fsf_req_send(req
);
2032 zfcp_fsf_req_free(req
);
2033 erp_action
->fsf_req
= NULL
;
2036 spin_unlock_bh(&adapter
->req_q
.lock
);
2040 static void zfcp_fsf_update_lat(struct fsf_latency_record
*lat_rec
, u32 lat
)
2042 lat_rec
->sum
+= lat
;
2043 lat_rec
->min
= min(lat_rec
->min
, lat
);
2044 lat_rec
->max
= max(lat_rec
->max
, lat
);
2047 static void zfcp_fsf_req_latency(struct zfcp_fsf_req
*req
)
2049 struct fsf_qual_latency_info
*lat_inf
;
2050 struct latency_cont
*lat
;
2051 struct zfcp_unit
*unit
= req
->unit
;
2052 unsigned long flags
;
2054 lat_inf
= &req
->qtcb
->prefix
.prot_status_qual
.latency_info
;
2056 switch (req
->qtcb
->bottom
.io
.data_direction
) {
2057 case FSF_DATADIR_READ
:
2058 lat
= &unit
->latencies
.read
;
2060 case FSF_DATADIR_WRITE
:
2061 lat
= &unit
->latencies
.write
;
2063 case FSF_DATADIR_CMND
:
2064 lat
= &unit
->latencies
.cmd
;
2070 spin_lock_irqsave(&unit
->latencies
.lock
, flags
);
2071 zfcp_fsf_update_lat(&lat
->channel
, lat_inf
->channel_lat
);
2072 zfcp_fsf_update_lat(&lat
->fabric
, lat_inf
->fabric_lat
);
2074 spin_unlock_irqrestore(&unit
->latencies
.lock
, flags
);
2077 static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req
*req
)
2079 struct scsi_cmnd
*scpnt
= req
->data
;
2080 struct fcp_rsp_iu
*fcp_rsp_iu
= (struct fcp_rsp_iu
*)
2081 &(req
->qtcb
->bottom
.io
.fcp_rsp
);
2083 char *fcp_rsp_info
= (unsigned char *) &fcp_rsp_iu
[1];
2084 unsigned long flags
;
2086 if (unlikely(!scpnt
))
2089 read_lock_irqsave(&req
->adapter
->abort_lock
, flags
);
2091 if (unlikely(req
->status
& ZFCP_STATUS_FSFREQ_ABORTED
)) {
2092 set_host_byte(scpnt
, DID_SOFT_ERROR
);
2093 set_driver_byte(scpnt
, SUGGEST_RETRY
);
2094 goto skip_fsfstatus
;
2097 if (unlikely(req
->status
& ZFCP_STATUS_FSFREQ_ERROR
)) {
2098 set_host_byte(scpnt
, DID_ERROR
);
2099 goto skip_fsfstatus
;
2102 set_msg_byte(scpnt
, COMMAND_COMPLETE
);
2104 scpnt
->result
|= fcp_rsp_iu
->scsi_status
;
2106 if (req
->adapter
->adapter_features
& FSF_FEATURE_MEASUREMENT_DATA
)
2107 zfcp_fsf_req_latency(req
);
2109 if (unlikely(fcp_rsp_iu
->validity
.bits
.fcp_rsp_len_valid
)) {
2110 if (fcp_rsp_info
[3] == RSP_CODE_GOOD
)
2111 set_host_byte(scpnt
, DID_OK
);
2113 set_host_byte(scpnt
, DID_ERROR
);
2114 goto skip_fsfstatus
;
2118 if (unlikely(fcp_rsp_iu
->validity
.bits
.fcp_sns_len_valid
)) {
2119 sns_len
= FSF_FCP_RSP_SIZE
- sizeof(struct fcp_rsp_iu
) +
2120 fcp_rsp_iu
->fcp_rsp_len
;
2121 sns_len
= min(sns_len
, (u32
) SCSI_SENSE_BUFFERSIZE
);
2122 sns_len
= min(sns_len
, fcp_rsp_iu
->fcp_sns_len
);
2124 memcpy(scpnt
->sense_buffer
,
2125 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu
), sns_len
);
2128 if (unlikely(fcp_rsp_iu
->validity
.bits
.fcp_resid_under
)) {
2129 scsi_set_resid(scpnt
, fcp_rsp_iu
->fcp_resid
);
2130 if (scsi_bufflen(scpnt
) - scsi_get_resid(scpnt
) <
2132 set_host_byte(scpnt
, DID_ERROR
);
2135 if (scpnt
->result
!= 0)
2136 zfcp_scsi_dbf_event_result("erro", 3, req
->adapter
, scpnt
, req
);
2137 else if (scpnt
->retries
> 0)
2138 zfcp_scsi_dbf_event_result("retr", 4, req
->adapter
, scpnt
, req
);
2140 zfcp_scsi_dbf_event_result("norm", 6, req
->adapter
, scpnt
, req
);
2142 scpnt
->host_scribble
= NULL
;
2143 (scpnt
->scsi_done
) (scpnt
);
2145 * We must hold this lock until scsi_done has been called.
2146 * Otherwise we may call scsi_done after abort regarding this
2147 * command has completed.
2148 * Note: scsi_done must not block!
2150 read_unlock_irqrestore(&req
->adapter
->abort_lock
, flags
);
2153 static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req
*req
)
2155 struct fcp_rsp_iu
*fcp_rsp_iu
= (struct fcp_rsp_iu
*)
2156 &(req
->qtcb
->bottom
.io
.fcp_rsp
);
2157 char *fcp_rsp_info
= (unsigned char *) &fcp_rsp_iu
[1];
2159 if ((fcp_rsp_info
[3] != RSP_CODE_GOOD
) ||
2160 (req
->status
& ZFCP_STATUS_FSFREQ_ERROR
))
2161 req
->status
|= ZFCP_STATUS_FSFREQ_TMFUNCFAILED
;
2165 static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req
*req
)
2167 struct zfcp_unit
*unit
;
2168 struct fsf_qtcb_header
*header
= &req
->qtcb
->header
;
2170 if (unlikely(req
->status
& ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT
))
2175 if (unlikely(req
->status
& ZFCP_STATUS_FSFREQ_ERROR
))
2176 goto skip_fsfstatus
;
2178 switch (header
->fsf_status
) {
2179 case FSF_HANDLE_MISMATCH
:
2180 case FSF_PORT_HANDLE_NOT_VALID
:
2181 zfcp_erp_adapter_reopen(unit
->port
->adapter
, 0, 112, req
);
2182 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
2184 case FSF_FCPLUN_NOT_VALID
:
2185 case FSF_LUN_HANDLE_NOT_VALID
:
2186 zfcp_erp_port_reopen(unit
->port
, 0, 113, req
);
2187 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
2189 case FSF_SERVICE_CLASS_NOT_SUPPORTED
:
2190 zfcp_fsf_class_not_supp(req
);
2192 case FSF_ACCESS_DENIED
:
2193 zfcp_fsf_access_denied_unit(req
, unit
);
2195 case FSF_DIRECTION_INDICATOR_NOT_VALID
:
2196 dev_err(&req
->adapter
->ccw_device
->dev
,
2197 "Incorrect direction %d, unit 0x%016Lx on port "
2198 "0x%016Lx closed\n",
2199 req
->qtcb
->bottom
.io
.data_direction
,
2200 unit
->fcp_lun
, unit
->port
->wwpn
);
2201 zfcp_erp_adapter_shutdown(unit
->port
->adapter
, 0, 133, req
);
2202 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
2204 case FSF_CMND_LENGTH_NOT_VALID
:
2205 dev_err(&req
->adapter
->ccw_device
->dev
,
2206 "Incorrect CDB length %d, unit 0x%016Lx on "
2207 "port 0x%016Lx closed\n",
2208 req
->qtcb
->bottom
.io
.fcp_cmnd_length
,
2209 unit
->fcp_lun
, unit
->port
->wwpn
);
2210 zfcp_erp_adapter_shutdown(unit
->port
->adapter
, 0, 134, req
);
2211 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
2213 case FSF_PORT_BOXED
:
2214 zfcp_erp_port_boxed(unit
->port
, 53, req
);
2215 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
|
2216 ZFCP_STATUS_FSFREQ_RETRY
;
2219 zfcp_erp_unit_boxed(unit
, 54, req
);
2220 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
|
2221 ZFCP_STATUS_FSFREQ_RETRY
;
2223 case FSF_ADAPTER_STATUS_AVAILABLE
:
2224 if (header
->fsf_status_qual
.word
[0] ==
2225 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE
)
2226 zfcp_test_link(unit
->port
);
2227 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
2231 if (req
->status
& ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT
)
2232 zfcp_fsf_send_fcp_ctm_handler(req
);
2234 zfcp_fsf_send_fcp_command_task_handler(req
);
2236 zfcp_unit_put(unit
);
2241 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
2242 * @adapter: adapter where scsi command is issued
2243 * @unit: unit where command is sent to
2244 * @scsi_cmnd: scsi command to be sent
2245 * @timer: timer to be started when request is initiated
2246 * @req_flags: flags for fsf_request
2248 int zfcp_fsf_send_fcp_command_task(struct zfcp_adapter
*adapter
,
2249 struct zfcp_unit
*unit
,
2250 struct scsi_cmnd
*scsi_cmnd
,
2251 int use_timer
, int req_flags
)
2253 struct zfcp_fsf_req
*req
;
2254 struct fcp_cmnd_iu
*fcp_cmnd_iu
;
2255 unsigned int sbtype
;
2256 int real_bytes
, retval
= -EIO
;
2258 if (unlikely(!(atomic_read(&unit
->status
) &
2259 ZFCP_STATUS_COMMON_UNBLOCKED
)))
2262 spin_lock(&adapter
->req_q
.lock
);
2263 if (!zfcp_fsf_sbal_available(adapter
))
2265 req
= zfcp_fsf_req_create(adapter
, FSF_QTCB_FCP_CMND
, req_flags
,
2266 adapter
->pool
.fsf_req_scsi
);
2268 retval
= PTR_ERR(req
);
2272 zfcp_unit_get(unit
);
2274 req
->data
= scsi_cmnd
;
2275 req
->handler
= zfcp_fsf_send_fcp_command_handler
;
2276 req
->qtcb
->header
.lun_handle
= unit
->handle
;
2277 req
->qtcb
->header
.port_handle
= unit
->port
->handle
;
2278 req
->qtcb
->bottom
.io
.service_class
= FSF_CLASS_3
;
2280 scsi_cmnd
->host_scribble
= (unsigned char *) req
->req_id
;
2282 fcp_cmnd_iu
= (struct fcp_cmnd_iu
*) &(req
->qtcb
->bottom
.io
.fcp_cmnd
);
2283 fcp_cmnd_iu
->fcp_lun
= unit
->fcp_lun
;
2285 * set depending on data direction:
2286 * data direction bits in SBALE (SB Type)
2287 * data direction bits in QTCB
2288 * data direction bits in FCP_CMND IU
2290 switch (scsi_cmnd
->sc_data_direction
) {
2292 req
->qtcb
->bottom
.io
.data_direction
= FSF_DATADIR_CMND
;
2293 sbtype
= SBAL_FLAGS0_TYPE_READ
;
2295 case DMA_FROM_DEVICE
:
2296 req
->qtcb
->bottom
.io
.data_direction
= FSF_DATADIR_READ
;
2297 sbtype
= SBAL_FLAGS0_TYPE_READ
;
2298 fcp_cmnd_iu
->rddata
= 1;
2301 req
->qtcb
->bottom
.io
.data_direction
= FSF_DATADIR_WRITE
;
2302 sbtype
= SBAL_FLAGS0_TYPE_WRITE
;
2303 fcp_cmnd_iu
->wddata
= 1;
2305 case DMA_BIDIRECTIONAL
:
2308 goto failed_scsi_cmnd
;
2311 if (likely((scsi_cmnd
->device
->simple_tags
) ||
2312 ((atomic_read(&unit
->status
) & ZFCP_STATUS_UNIT_READONLY
) &&
2313 (atomic_read(&unit
->status
) & ZFCP_STATUS_UNIT_SHARED
))))
2314 fcp_cmnd_iu
->task_attribute
= SIMPLE_Q
;
2316 fcp_cmnd_iu
->task_attribute
= UNTAGGED
;
2318 if (unlikely(scsi_cmnd
->cmd_len
> FCP_CDB_LENGTH
))
2319 fcp_cmnd_iu
->add_fcp_cdb_length
=
2320 (scsi_cmnd
->cmd_len
- FCP_CDB_LENGTH
) >> 2;
2322 memcpy(fcp_cmnd_iu
->fcp_cdb
, scsi_cmnd
->cmnd
, scsi_cmnd
->cmd_len
);
2324 req
->qtcb
->bottom
.io
.fcp_cmnd_length
= sizeof(struct fcp_cmnd_iu
) +
2325 fcp_cmnd_iu
->add_fcp_cdb_length
+ sizeof(fcp_dl_t
);
2327 real_bytes
= zfcp_qdio_sbals_from_sg(req
, sbtype
,
2328 scsi_sglist(scsi_cmnd
),
2329 FSF_MAX_SBALS_PER_REQ
);
2330 if (unlikely(real_bytes
< 0)) {
2331 if (req
->sbal_number
< FSF_MAX_SBALS_PER_REQ
)
2334 dev_err(&adapter
->ccw_device
->dev
,
2335 "Oversize data package, unit 0x%016Lx "
2336 "on port 0x%016Lx closed\n",
2337 unit
->fcp_lun
, unit
->port
->wwpn
);
2338 zfcp_erp_unit_shutdown(unit
, 0, 131, req
);
2341 goto failed_scsi_cmnd
;
2344 zfcp_set_fcp_dl(fcp_cmnd_iu
, real_bytes
);
2347 zfcp_fsf_start_timer(req
, ZFCP_FSF_REQUEST_TIMEOUT
);
2349 retval
= zfcp_fsf_req_send(req
);
2350 if (unlikely(retval
))
2351 goto failed_scsi_cmnd
;
2356 zfcp_unit_put(unit
);
2357 zfcp_fsf_req_free(req
);
2358 scsi_cmnd
->host_scribble
= NULL
;
2360 spin_unlock(&adapter
->req_q
.lock
);
2365 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
2366 * @adapter: pointer to struct zfcp-adapter
2367 * @unit: pointer to struct zfcp_unit
2368 * @tm_flags: unsigned byte for task management flags
2369 * @req_flags: int request flags
2370 * Returns: on success pointer to struct fsf_req, NULL otherwise
2372 struct zfcp_fsf_req
*zfcp_fsf_send_fcp_ctm(struct zfcp_adapter
*adapter
,
2373 struct zfcp_unit
*unit
,
2374 u8 tm_flags
, int req_flags
)
2376 struct qdio_buffer_element
*sbale
;
2377 struct zfcp_fsf_req
*req
= NULL
;
2378 struct fcp_cmnd_iu
*fcp_cmnd_iu
;
2380 if (unlikely(!(atomic_read(&unit
->status
) &
2381 ZFCP_STATUS_COMMON_UNBLOCKED
)))
2384 spin_lock(&adapter
->req_q
.lock
);
2385 if (!zfcp_fsf_sbal_available(adapter
))
2387 req
= zfcp_fsf_req_create(adapter
, FSF_QTCB_FCP_CMND
, req_flags
,
2388 adapter
->pool
.fsf_req_scsi
);
2392 req
->status
|= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT
;
2394 req
->handler
= zfcp_fsf_send_fcp_command_handler
;
2395 req
->qtcb
->header
.lun_handle
= unit
->handle
;
2396 req
->qtcb
->header
.port_handle
= unit
->port
->handle
;
2397 req
->qtcb
->bottom
.io
.data_direction
= FSF_DATADIR_CMND
;
2398 req
->qtcb
->bottom
.io
.service_class
= FSF_CLASS_3
;
2399 req
->qtcb
->bottom
.io
.fcp_cmnd_length
= sizeof(struct fcp_cmnd_iu
) +
2402 sbale
= zfcp_qdio_sbale_req(req
);
2403 sbale
[0].flags
|= SBAL_FLAGS0_TYPE_WRITE
;
2404 sbale
[1].flags
|= SBAL_FLAGS_LAST_ENTRY
;
2406 fcp_cmnd_iu
= (struct fcp_cmnd_iu
*) &req
->qtcb
->bottom
.io
.fcp_cmnd
;
2407 fcp_cmnd_iu
->fcp_lun
= unit
->fcp_lun
;
2408 fcp_cmnd_iu
->task_management_flags
= tm_flags
;
2410 zfcp_fsf_start_timer(req
, ZFCP_SCSI_ER_TIMEOUT
);
2411 if (!zfcp_fsf_req_send(req
))
2414 zfcp_fsf_req_free(req
);
2417 spin_unlock(&adapter
->req_q
.lock
);
2421 static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req
*req
)
2423 if (req
->qtcb
->header
.fsf_status
!= FSF_GOOD
)
2424 req
->status
|= ZFCP_STATUS_FSFREQ_ERROR
;
2428 * zfcp_fsf_control_file - control file upload/download
2429 * @adapter: pointer to struct zfcp_adapter
2430 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2431 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
2433 struct zfcp_fsf_req
*zfcp_fsf_control_file(struct zfcp_adapter
*adapter
,
2434 struct zfcp_fsf_cfdc
*fsf_cfdc
)
2436 struct qdio_buffer_element
*sbale
;
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(&adapter
->req_q
.lock
);
2456 if (zfcp_fsf_req_sbal_get(adapter
))
2459 req
= zfcp_fsf_req_create(adapter
, fsf_cfdc
->command
, 0, NULL
);
2465 req
->handler
= zfcp_fsf_control_file_handler
;
2467 sbale
= zfcp_qdio_sbale_req(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(req
, direction
, fsf_cfdc
->sg
,
2475 FSF_MAX_SBALS_PER_REQ
);
2476 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(&adapter
->req_q
.lock
);
2488 wait_event(req
->completion_wq
,
2489 req
->status
& ZFCP_STATUS_FSFREQ_COMPLETED
);
2492 return ERR_PTR(retval
);