1 // SPDX-License-Identifier: GPL-2.0
5 * Implementation of FSF commands.
7 * Copyright IBM Corp. 2002, 2020
10 #define KMSG_COMPONENT "zfcp"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 #include <linux/blktrace_api.h>
14 #include <linux/jiffies.h>
15 #include <linux/types.h>
16 #include <linux/slab.h>
17 #include <scsi/fc/fc_els.h>
21 #include "zfcp_qdio.h"
22 #include "zfcp_reqlist.h"
23 #include "zfcp_diag.h"
25 /* timeout for FSF requests sent during scsi_eh: abort or FCP TMF */
26 #define ZFCP_FSF_SCSI_ER_TIMEOUT (10*HZ)
27 /* timeout for: exchange config/port data outside ERP, or open/close WKA port */
28 #define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ)
30 struct kmem_cache *zfcp_fsf_qtcb_cache;
32 static bool ber_stop = true;
33 module_param(ber_stop, bool, 0600);
34 MODULE_PARM_DESC(ber_stop,
35 "Shuts down FCP devices for FCP channels that report a bit-error count in excess of its threshold (default on)");
37 static void zfcp_fsf_request_timeout_handler(struct timer_list *t)
39 struct zfcp_fsf_req *fsf_req = from_timer(fsf_req, t, timer);
40 struct zfcp_adapter *adapter = fsf_req->adapter;
42 zfcp_qdio_siosl(adapter);
43 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
47 static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
48 unsigned long timeout)
50 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
51 fsf_req->timer.expires = jiffies + timeout;
52 add_timer(&fsf_req->timer);
55 static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
57 BUG_ON(!fsf_req->erp_action);
58 fsf_req->timer.function = zfcp_erp_timeout_handler;
59 fsf_req->timer.expires = jiffies + 30 * HZ;
60 add_timer(&fsf_req->timer);
63 /* association between FSF command and FSF QTCB type */
64 static u32 fsf_qtcb_type[] = {
65 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
66 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
67 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
68 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
69 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
70 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
71 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
72 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
73 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
74 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
75 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
76 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
77 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
80 static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
82 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
83 "operational because of an unsupported FC class\n");
84 zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1");
85 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
89 * zfcp_fsf_req_free - free memory used by fsf request
90 * @req: pointer to struct zfcp_fsf_req
92 void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
94 if (likely(req->pool)) {
95 if (likely(!zfcp_fsf_req_is_status_read_buffer(req)))
96 mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
97 mempool_free(req, req->pool);
101 if (likely(!zfcp_fsf_req_is_status_read_buffer(req)))
102 kmem_cache_free(zfcp_fsf_qtcb_cache, req->qtcb);
106 static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
109 struct fsf_status_read_buffer *sr_buf = req->data;
110 struct zfcp_adapter *adapter = req->adapter;
111 struct zfcp_port *port;
112 int d_id = ntoh24(sr_buf->d_id);
114 read_lock_irqsave(&adapter->port_list_lock, flags);
115 list_for_each_entry(port, &adapter->port_list, list)
116 if (port->d_id == d_id) {
117 zfcp_erp_port_reopen(port, 0, "fssrpc1");
120 read_unlock_irqrestore(&adapter->port_list_lock, flags);
123 void zfcp_fsf_fc_host_link_down(struct zfcp_adapter *adapter)
125 struct Scsi_Host *shost = adapter->scsi_host;
127 adapter->hydra_version = 0;
128 adapter->peer_wwpn = 0;
129 adapter->peer_wwnn = 0;
130 adapter->peer_d_id = 0;
132 /* if there is no shost yet, we have nothing to zero-out */
136 fc_host_port_id(shost) = 0;
137 fc_host_fabric_name(shost) = 0;
138 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
139 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
140 snprintf(fc_host_model(shost), FC_SYMBOLIC_NAME_SIZE, "0x%04x", 0);
141 memset(fc_host_active_fc4s(shost), 0, FC_FC4_LIST_SIZE);
144 static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req,
145 struct fsf_link_down_info *link_down)
147 struct zfcp_adapter *adapter = req->adapter;
149 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
152 atomic_or(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
154 zfcp_scsi_schedule_rports_block(adapter);
156 zfcp_fsf_fc_host_link_down(adapter);
161 switch (link_down->error_code) {
162 case FSF_PSQ_LINK_NO_LIGHT:
163 dev_warn(&req->adapter->ccw_device->dev,
164 "There is no light signal from the local "
165 "fibre channel cable\n");
167 case FSF_PSQ_LINK_WRAP_PLUG:
168 dev_warn(&req->adapter->ccw_device->dev,
169 "There is a wrap plug instead of a fibre "
172 case FSF_PSQ_LINK_NO_FCP:
173 dev_warn(&req->adapter->ccw_device->dev,
174 "The adjacent fibre channel node does not "
177 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
178 dev_warn(&req->adapter->ccw_device->dev,
179 "The FCP device is suspended because of a "
180 "firmware update\n");
182 case FSF_PSQ_LINK_INVALID_WWPN:
183 dev_warn(&req->adapter->ccw_device->dev,
184 "The FCP device detected a WWPN that is "
185 "duplicate or not valid\n");
187 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
188 dev_warn(&req->adapter->ccw_device->dev,
189 "The fibre channel fabric does not support NPIV\n");
191 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
192 dev_warn(&req->adapter->ccw_device->dev,
193 "The FCP adapter cannot support more NPIV ports\n");
195 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
196 dev_warn(&req->adapter->ccw_device->dev,
197 "The adjacent switch cannot support "
198 "more NPIV ports\n");
200 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
201 dev_warn(&req->adapter->ccw_device->dev,
202 "The FCP adapter could not log in to the "
203 "fibre channel fabric\n");
205 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
206 dev_warn(&req->adapter->ccw_device->dev,
207 "The WWPN assignment file on the FCP adapter "
208 "has been damaged\n");
210 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
211 dev_warn(&req->adapter->ccw_device->dev,
212 "The mode table on the FCP adapter "
213 "has been damaged\n");
215 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
216 dev_warn(&req->adapter->ccw_device->dev,
217 "All NPIV ports on the FCP adapter have "
221 dev_warn(&req->adapter->ccw_device->dev,
222 "The link between the FCP adapter and "
223 "the FC fabric is down\n");
226 zfcp_erp_set_adapter_status(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
229 static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
231 struct fsf_status_read_buffer *sr_buf = req->data;
232 struct fsf_link_down_info *ldi =
233 (struct fsf_link_down_info *) &sr_buf->payload;
235 switch (sr_buf->status_subtype) {
236 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
237 case FSF_STATUS_READ_SUB_FDISC_FAILED:
238 zfcp_fsf_link_down_info_eval(req, ldi);
240 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
241 zfcp_fsf_link_down_info_eval(req, NULL);
245 static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
247 struct zfcp_adapter *adapter = req->adapter;
248 struct fsf_status_read_buffer *sr_buf = req->data;
250 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
251 zfcp_dbf_hba_fsf_uss("fssrh_1", req);
252 mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
253 zfcp_fsf_req_free(req);
257 zfcp_dbf_hba_fsf_uss("fssrh_4", req);
259 switch (sr_buf->status_type) {
260 case FSF_STATUS_READ_PORT_CLOSED:
261 zfcp_fsf_status_read_port_closed(req);
263 case FSF_STATUS_READ_INCOMING_ELS:
264 zfcp_fc_incoming_els(req);
266 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
268 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
269 zfcp_dbf_hba_bit_err("fssrh_3", req);
271 dev_warn(&adapter->ccw_device->dev,
272 "All paths over this FCP device are disused because of excessive bit errors\n");
273 zfcp_erp_adapter_shutdown(adapter, 0, "fssrh_b");
275 dev_warn(&adapter->ccw_device->dev,
276 "The error threshold for checksum statistics has been exceeded\n");
279 case FSF_STATUS_READ_LINK_DOWN:
280 zfcp_fsf_status_read_link_down(req);
281 zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKDOWN, 0);
283 case FSF_STATUS_READ_LINK_UP:
284 dev_info(&adapter->ccw_device->dev,
285 "The local link has been restored\n");
286 /* All ports should be marked as ready to run again */
287 zfcp_erp_set_adapter_status(adapter,
288 ZFCP_STATUS_COMMON_RUNNING);
289 zfcp_erp_adapter_reopen(adapter,
290 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
291 ZFCP_STATUS_COMMON_ERP_FAILED,
293 zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKUP, 0);
296 case FSF_STATUS_READ_NOTIFICATION_LOST:
297 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
298 zfcp_fc_conditional_port_scan(adapter);
300 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
301 adapter->adapter_features = sr_buf->payload.word[0];
305 mempool_free(virt_to_page(sr_buf), adapter->pool.sr_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_qdio_siosl(req->adapter);
327 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1");
330 /* all non-return stats set FSFREQ_ERROR*/
331 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
334 static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
336 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
339 switch (req->qtcb->header.fsf_status) {
340 case FSF_UNKNOWN_COMMAND:
341 dev_err(&req->adapter->ccw_device->dev,
342 "The FCP adapter does not recognize the command 0x%x\n",
343 req->qtcb->header.fsf_command);
344 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1");
345 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
347 case FSF_ADAPTER_STATUS_AVAILABLE:
348 zfcp_fsf_fsfstatus_qual_eval(req);
353 static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
355 struct zfcp_adapter *adapter = req->adapter;
356 struct fsf_qtcb *qtcb = req->qtcb;
357 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
359 zfcp_dbf_hba_fsf_response(req);
361 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
362 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
366 switch (qtcb->prefix.prot_status) {
368 case FSF_PROT_FSF_STATUS_PRESENTED:
370 case FSF_PROT_QTCB_VERSION_ERROR:
371 dev_err(&adapter->ccw_device->dev,
372 "QTCB version 0x%x not supported by FCP adapter "
373 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
374 psq->word[0], psq->word[1]);
375 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1");
377 case FSF_PROT_ERROR_STATE:
378 case FSF_PROT_SEQ_NUMB_ERROR:
379 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2");
380 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
382 case FSF_PROT_UNSUPP_QTCB_TYPE:
383 dev_err(&adapter->ccw_device->dev,
384 "The QTCB type is not supported by the FCP adapter\n");
385 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3");
387 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
388 atomic_or(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
391 case FSF_PROT_DUPLICATE_REQUEST_ID:
392 dev_err(&adapter->ccw_device->dev,
393 "0x%Lx is an ambiguous request identifier\n",
394 (unsigned long long)qtcb->bottom.support.req_handle);
395 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4");
397 case FSF_PROT_LINK_DOWN:
398 zfcp_fsf_link_down_info_eval(req, &psq->link_down_info);
399 /* go through reopen to flush pending requests */
400 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6");
402 case FSF_PROT_REEST_QUEUE:
403 /* All ports should be marked as ready to run again */
404 zfcp_erp_set_adapter_status(adapter,
405 ZFCP_STATUS_COMMON_RUNNING);
406 zfcp_erp_adapter_reopen(adapter,
407 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
408 ZFCP_STATUS_COMMON_ERP_FAILED,
412 dev_err(&adapter->ccw_device->dev,
413 "0x%x is not a valid transfer protocol status\n",
414 qtcb->prefix.prot_status);
415 zfcp_qdio_siosl(adapter);
416 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9");
418 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
422 * zfcp_fsf_req_complete - process completion of a FSF request
423 * @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.
429 * Caller must ensure that the request has been removed from
430 * adapter->req_list, to protect against concurrent modification
431 * by zfcp_erp_strategy_check_fsfreq().
433 static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
435 struct zfcp_erp_action *erp_action;
437 if (unlikely(zfcp_fsf_req_is_status_read_buffer(req))) {
438 zfcp_fsf_status_read_handler(req);
442 del_timer_sync(&req->timer);
443 zfcp_fsf_protstatus_eval(req);
444 zfcp_fsf_fsfstatus_eval(req);
447 erp_action = req->erp_action;
449 zfcp_erp_notify(erp_action, 0);
451 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
452 zfcp_fsf_req_free(req);
454 complete(&req->completion);
458 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
459 * @adapter: pointer to struct zfcp_adapter
461 * Never ever call this without shutting down the adapter first.
462 * Otherwise the adapter would continue using and corrupting s390 storage.
463 * Included BUG_ON() call to ensure this is done.
464 * ERP is supposed to be the only user of this function.
466 void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
468 struct zfcp_fsf_req *req, *tmp;
469 LIST_HEAD(remove_queue);
471 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
472 zfcp_reqlist_move(adapter->req_list, &remove_queue);
474 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
475 list_del(&req->list);
476 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
477 zfcp_fsf_req_complete(req);
481 #define ZFCP_FSF_PORTSPEED_1GBIT (1 << 0)
482 #define ZFCP_FSF_PORTSPEED_2GBIT (1 << 1)
483 #define ZFCP_FSF_PORTSPEED_4GBIT (1 << 2)
484 #define ZFCP_FSF_PORTSPEED_10GBIT (1 << 3)
485 #define ZFCP_FSF_PORTSPEED_8GBIT (1 << 4)
486 #define ZFCP_FSF_PORTSPEED_16GBIT (1 << 5)
487 #define ZFCP_FSF_PORTSPEED_32GBIT (1 << 6)
488 #define ZFCP_FSF_PORTSPEED_64GBIT (1 << 7)
489 #define ZFCP_FSF_PORTSPEED_128GBIT (1 << 8)
490 #define ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED (1 << 15)
492 u32 zfcp_fsf_convert_portspeed(u32 fsf_speed)
495 if (fsf_speed & ZFCP_FSF_PORTSPEED_1GBIT)
496 fdmi_speed |= FC_PORTSPEED_1GBIT;
497 if (fsf_speed & ZFCP_FSF_PORTSPEED_2GBIT)
498 fdmi_speed |= FC_PORTSPEED_2GBIT;
499 if (fsf_speed & ZFCP_FSF_PORTSPEED_4GBIT)
500 fdmi_speed |= FC_PORTSPEED_4GBIT;
501 if (fsf_speed & ZFCP_FSF_PORTSPEED_10GBIT)
502 fdmi_speed |= FC_PORTSPEED_10GBIT;
503 if (fsf_speed & ZFCP_FSF_PORTSPEED_8GBIT)
504 fdmi_speed |= FC_PORTSPEED_8GBIT;
505 if (fsf_speed & ZFCP_FSF_PORTSPEED_16GBIT)
506 fdmi_speed |= FC_PORTSPEED_16GBIT;
507 if (fsf_speed & ZFCP_FSF_PORTSPEED_32GBIT)
508 fdmi_speed |= FC_PORTSPEED_32GBIT;
509 if (fsf_speed & ZFCP_FSF_PORTSPEED_64GBIT)
510 fdmi_speed |= FC_PORTSPEED_64GBIT;
511 if (fsf_speed & ZFCP_FSF_PORTSPEED_128GBIT)
512 fdmi_speed |= FC_PORTSPEED_128GBIT;
513 if (fsf_speed & ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED)
514 fdmi_speed |= FC_PORTSPEED_NOT_NEGOTIATED;
518 static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
520 struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
521 struct zfcp_adapter *adapter = req->adapter;
522 struct fc_els_flogi *plogi;
524 /* adjust pointers for missing command code */
525 plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
529 memcpy(req->data, bottom, sizeof(*bottom));
531 adapter->timer_ticks = bottom->timer_interval & ZFCP_FSF_TIMER_INT_MASK;
532 adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
533 (u16)FSF_STATUS_READS_RECOM);
535 /* no error return above here, otherwise must fix call chains */
536 /* do not evaluate invalid fields */
537 if (req->qtcb->header.fsf_status == FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE)
540 adapter->hydra_version = bottom->adapter_type;
542 switch (bottom->fc_topology) {
544 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
545 adapter->peer_wwpn = be64_to_cpu(plogi->fl_wwpn);
546 adapter->peer_wwnn = be64_to_cpu(plogi->fl_wwnn);
548 case FSF_TOPO_FABRIC:
552 dev_err(&adapter->ccw_device->dev,
553 "Unknown or unsupported arbitrated loop "
554 "fibre channel topology detected\n");
555 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1");
562 static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
564 struct zfcp_adapter *adapter = req->adapter;
565 struct zfcp_diag_header *const diag_hdr =
566 &adapter->diagnostics->config_data.header;
567 struct fsf_qtcb *qtcb = req->qtcb;
568 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
570 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
573 adapter->fsf_lic_version = bottom->lic_version;
574 adapter->adapter_features = bottom->adapter_features;
575 adapter->connection_features = bottom->connection_features;
576 adapter->peer_wwpn = 0;
577 adapter->peer_wwnn = 0;
578 adapter->peer_d_id = 0;
580 switch (qtcb->header.fsf_status) {
583 * usually we wait with an update till the cache is too old,
584 * but because we have the data available, update it anyway
586 zfcp_diag_update_xdata(diag_hdr, bottom, false);
588 zfcp_scsi_shost_update_config_data(adapter, bottom, false);
589 if (zfcp_fsf_exchange_config_evaluate(req))
592 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
593 dev_err(&adapter->ccw_device->dev,
594 "FCP adapter maximum QTCB size (%d bytes) "
596 bottom->max_qtcb_size);
597 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1");
600 atomic_or(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
603 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
604 zfcp_diag_update_xdata(diag_hdr, bottom, true);
605 req->status |= ZFCP_STATUS_FSFREQ_XDATAINCOMPLETE;
607 /* avoids adapter shutdown to be able to recognize
608 * events such as LINK UP */
609 atomic_or(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
611 zfcp_fsf_link_down_info_eval(req,
612 &qtcb->header.fsf_status_qual.link_down_info);
614 zfcp_scsi_shost_update_config_data(adapter, bottom, true);
615 if (zfcp_fsf_exchange_config_evaluate(req))
619 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3");
623 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)
624 adapter->hardware_version = bottom->hardware_version;
626 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
627 dev_err(&adapter->ccw_device->dev,
628 "The FCP adapter only supports newer "
629 "control block versions\n");
630 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4");
633 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
634 dev_err(&adapter->ccw_device->dev,
635 "The FCP adapter only supports older "
636 "control block versions\n");
637 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5");
642 * Mapping of FC Endpoint Security flag masks to mnemonics
644 * NOTE: Update macro ZFCP_FSF_MAX_FC_SECURITY_MNEMONIC_LENGTH when making any
647 static const struct {
650 } zfcp_fsf_fc_security_mnemonics[] = {
651 { FSF_FC_SECURITY_AUTH, "Authentication" },
652 { FSF_FC_SECURITY_ENC_FCSP2 |
653 FSF_FC_SECURITY_ENC_ERAS, "Encryption" },
656 /* maximum strlen(zfcp_fsf_fc_security_mnemonics[...].name) + 1 */
657 #define ZFCP_FSF_MAX_FC_SECURITY_MNEMONIC_LENGTH 15
660 * zfcp_fsf_scnprint_fc_security() - translate FC Endpoint Security flags into
661 * mnemonics and place in a buffer
662 * @buf : the buffer to place the translated FC Endpoint Security flag(s)
664 * @size : the size of the buffer, including the trailing null space
665 * @fc_security: one or more FC Endpoint Security flags, or zero
666 * @fmt : specifies whether a list or a single item is to be put into the
669 * The Fibre Channel (FC) Endpoint Security flags are translated into mnemonics.
670 * If the FC Endpoint Security flags are zero "none" is placed into the buffer.
672 * With ZFCP_FSF_PRINT_FMT_LIST the mnemonics are placed as a list separated by
673 * a comma followed by a space into the buffer. If one or more FC Endpoint
674 * Security flags cannot be translated into a mnemonic, as they are undefined
675 * in zfcp_fsf_fc_security_mnemonics, their bitwise ORed value in hexadecimal
676 * representation is placed into the buffer.
678 * With ZFCP_FSF_PRINT_FMT_SINGLEITEM only one single mnemonic is placed into
679 * the buffer. If the FC Endpoint Security flag cannot be translated, as it is
680 * undefined in zfcp_fsf_fc_security_mnemonics, its value in hexadecimal
681 * representation is placed into the buffer. If more than one FC Endpoint
682 * Security flag was specified, their value in hexadecimal representation is
683 * placed into the buffer. The macro ZFCP_FSF_MAX_FC_SECURITY_MNEMONIC_LENGTH
684 * can be used to define a buffer that is large enough to hold one mnemonic.
686 * Return: The number of characters written into buf not including the trailing
687 * '\0'. If size is == 0 the function returns 0.
689 ssize_t zfcp_fsf_scnprint_fc_security(char *buf, size_t size, u32 fc_security,
690 enum zfcp_fsf_print_fmt fmt)
692 const char *prefix = "";
696 if (fc_security == 0)
697 return scnprintf(buf, size, "none");
698 if (fmt == ZFCP_FSF_PRINT_FMT_SINGLEITEM && hweight32(fc_security) != 1)
699 return scnprintf(buf, size, "0x%08x", fc_security);
701 for (i = 0; i < ARRAY_SIZE(zfcp_fsf_fc_security_mnemonics); i++) {
702 if (!(fc_security & zfcp_fsf_fc_security_mnemonics[i].mask))
705 len += scnprintf(buf + len, size - len, "%s%s", prefix,
706 zfcp_fsf_fc_security_mnemonics[i].name);
708 fc_security &= ~zfcp_fsf_fc_security_mnemonics[i].mask;
711 if (fc_security != 0)
712 len += scnprintf(buf + len, size - len, "%s0x%08x",
713 prefix, fc_security);
718 static void zfcp_fsf_dbf_adapter_fc_security(struct zfcp_adapter *adapter,
719 struct zfcp_fsf_req *req)
721 if (adapter->fc_security_algorithms ==
722 adapter->fc_security_algorithms_old) {
723 /* no change, no trace */
727 zfcp_dbf_hba_fsf_fces("fsfcesa", req, ZFCP_DBF_INVALID_WWPN,
728 adapter->fc_security_algorithms_old,
729 adapter->fc_security_algorithms);
731 adapter->fc_security_algorithms_old = adapter->fc_security_algorithms;
734 static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
736 struct zfcp_adapter *adapter = req->adapter;
737 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
740 memcpy(req->data, bottom, sizeof(*bottom));
742 if (adapter->adapter_features & FSF_FEATURE_FC_SECURITY)
743 adapter->fc_security_algorithms =
744 bottom->fc_security_algorithms;
746 adapter->fc_security_algorithms = 0;
747 zfcp_fsf_dbf_adapter_fc_security(adapter, req);
750 static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
752 struct zfcp_diag_header *const diag_hdr =
753 &req->adapter->diagnostics->port_data.header;
754 struct fsf_qtcb *qtcb = req->qtcb;
755 struct fsf_qtcb_bottom_port *bottom = &qtcb->bottom.port;
757 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
760 switch (qtcb->header.fsf_status) {
763 * usually we wait with an update till the cache is too old,
764 * but because we have the data available, update it anyway
766 zfcp_diag_update_xdata(diag_hdr, bottom, false);
768 zfcp_scsi_shost_update_port_data(req->adapter, bottom);
769 zfcp_fsf_exchange_port_evaluate(req);
771 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
772 zfcp_diag_update_xdata(diag_hdr, bottom, true);
773 req->status |= ZFCP_STATUS_FSFREQ_XDATAINCOMPLETE;
775 zfcp_fsf_link_down_info_eval(req,
776 &qtcb->header.fsf_status_qual.link_down_info);
778 zfcp_scsi_shost_update_port_data(req->adapter, bottom);
779 zfcp_fsf_exchange_port_evaluate(req);
784 static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
786 struct zfcp_fsf_req *req;
789 req = mempool_alloc(pool, GFP_ATOMIC);
791 req = kmalloc(sizeof(*req), GFP_ATOMIC);
796 memset(req, 0, sizeof(*req));
801 static struct fsf_qtcb *zfcp_fsf_qtcb_alloc(mempool_t *pool)
803 struct fsf_qtcb *qtcb;
806 qtcb = mempool_alloc(pool, GFP_ATOMIC);
808 qtcb = kmem_cache_alloc(zfcp_fsf_qtcb_cache, GFP_ATOMIC);
813 memset(qtcb, 0, sizeof(*qtcb));
817 static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
818 u32 fsf_cmd, u8 sbtype,
821 struct zfcp_adapter *adapter = qdio->adapter;
822 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
825 return ERR_PTR(-ENOMEM);
827 if (adapter->req_no == 0)
830 INIT_LIST_HEAD(&req->list);
831 timer_setup(&req->timer, NULL, 0);
832 init_completion(&req->completion);
834 req->adapter = adapter;
835 req->req_id = adapter->req_no;
837 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
839 req->qtcb = zfcp_fsf_qtcb_alloc(
840 adapter->pool.qtcb_pool);
842 req->qtcb = zfcp_fsf_qtcb_alloc(NULL);
844 if (unlikely(!req->qtcb)) {
845 zfcp_fsf_req_free(req);
846 return ERR_PTR(-ENOMEM);
849 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
850 req->qtcb->prefix.req_id = req->req_id;
851 req->qtcb->prefix.ulp_info = 26;
852 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[fsf_cmd];
853 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
854 req->qtcb->header.req_handle = req->req_id;
855 req->qtcb->header.fsf_command = fsf_cmd;
858 zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
859 req->qtcb, sizeof(struct fsf_qtcb));
864 static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
866 const bool is_srb = zfcp_fsf_req_is_status_read_buffer(req);
867 struct zfcp_adapter *adapter = req->adapter;
868 struct zfcp_qdio *qdio = adapter->qdio;
869 int req_id = req->req_id;
871 zfcp_reqlist_add(adapter->req_list, req);
873 req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free);
874 req->issued = get_tod_clock();
875 if (zfcp_qdio_send(qdio, &req->qdio_req)) {
876 del_timer_sync(&req->timer);
877 /* lookup request again, list might have changed */
878 zfcp_reqlist_find_rm(adapter->req_list, req_id);
879 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1");
884 * NOTE: DO NOT TOUCH ASYNC req PAST THIS POINT.
885 * ONLY TOUCH SYNC req AGAIN ON req->completion.
887 * The request might complete and be freed concurrently at any point
888 * now. This is not protected by the QDIO-lock (req_q_lock). So any
889 * uncontrolled access after this might result in an use-after-free bug.
890 * Only if the request doesn't have ZFCP_STATUS_FSFREQ_CLEANUP set, and
891 * when it is completed via req->completion, is it safe to use req
895 /* Don't increase for unsolicited status */
897 adapter->fsf_req_seq_no++;
904 * zfcp_fsf_status_read - send status read request
905 * @qdio: pointer to struct zfcp_qdio
906 * Returns: 0 on success, ERROR otherwise
908 int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
910 struct zfcp_adapter *adapter = qdio->adapter;
911 struct zfcp_fsf_req *req;
912 struct fsf_status_read_buffer *sr_buf;
916 spin_lock_irq(&qdio->req_q_lock);
917 if (zfcp_qdio_sbal_get(qdio))
920 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS,
921 SBAL_SFLAGS0_TYPE_STATUS,
922 adapter->pool.status_read_req);
924 retval = PTR_ERR(req);
928 page = mempool_alloc(adapter->pool.sr_data, GFP_ATOMIC);
933 sr_buf = page_address(page);
934 memset(sr_buf, 0, sizeof(*sr_buf));
937 zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
938 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
940 retval = zfcp_fsf_req_send(req);
942 goto failed_req_send;
943 /* NOTE: DO NOT TOUCH req PAST THIS POINT! */
949 mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
951 zfcp_dbf_hba_fsf_uss("fssr__1", req);
952 zfcp_fsf_req_free(req);
954 spin_unlock_irq(&qdio->req_q_lock);
958 static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
960 struct scsi_device *sdev = req->data;
961 struct zfcp_scsi_dev *zfcp_sdev;
962 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
964 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
967 zfcp_sdev = sdev_to_zfcp(sdev);
969 switch (req->qtcb->header.fsf_status) {
970 case FSF_PORT_HANDLE_NOT_VALID:
971 if (fsq->word[0] == fsq->word[1]) {
972 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0,
974 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
977 case FSF_LUN_HANDLE_NOT_VALID:
978 if (fsq->word[0] == fsq->word[1]) {
979 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fsafch2");
980 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
983 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
984 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
987 zfcp_erp_set_port_status(zfcp_sdev->port,
988 ZFCP_STATUS_COMMON_ACCESS_BOXED);
989 zfcp_erp_port_reopen(zfcp_sdev->port,
990 ZFCP_STATUS_COMMON_ERP_FAILED, "fsafch3");
991 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
994 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
995 zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
997 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
999 case FSF_ADAPTER_STATUS_AVAILABLE:
1000 switch (fsq->word[0]) {
1001 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1002 zfcp_fc_test_link(zfcp_sdev->port);
1004 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1005 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1010 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1016 * zfcp_fsf_abort_fcp_cmnd - abort running SCSI command
1017 * @scmnd: The SCSI command to abort
1018 * Returns: pointer to struct zfcp_fsf_req
1021 struct zfcp_fsf_req *zfcp_fsf_abort_fcp_cmnd(struct scsi_cmnd *scmnd)
1023 struct zfcp_fsf_req *req = NULL;
1024 struct scsi_device *sdev = scmnd->device;
1025 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
1026 struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
1027 unsigned long old_req_id = (unsigned long) scmnd->host_scribble;
1029 spin_lock_irq(&qdio->req_q_lock);
1030 if (zfcp_qdio_sbal_get(qdio))
1032 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
1033 SBAL_SFLAGS0_TYPE_READ,
1034 qdio->adapter->pool.scsi_abort);
1040 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
1041 ZFCP_STATUS_COMMON_UNBLOCKED)))
1042 goto out_error_free;
1044 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1047 req->handler = zfcp_fsf_abort_fcp_command_handler;
1048 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
1049 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
1050 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1052 zfcp_fsf_start_timer(req, ZFCP_FSF_SCSI_ER_TIMEOUT);
1053 if (!zfcp_fsf_req_send(req)) {
1054 /* NOTE: DO NOT TOUCH req, UNTIL IT COMPLETES! */
1059 zfcp_fsf_req_free(req);
1062 spin_unlock_irq(&qdio->req_q_lock);
1066 static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
1068 struct zfcp_adapter *adapter = req->adapter;
1069 struct zfcp_fsf_ct_els *ct = req->data;
1070 struct fsf_qtcb_header *header = &req->qtcb->header;
1072 ct->status = -EINVAL;
1074 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1075 goto skip_fsfstatus;
1077 switch (header->fsf_status) {
1080 zfcp_dbf_san_res("fsscth2", req);
1082 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1083 zfcp_fsf_class_not_supp(req);
1085 case FSF_ADAPTER_STATUS_AVAILABLE:
1086 switch (header->fsf_status_qual.word[0]){
1087 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1088 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1089 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1093 case FSF_PORT_BOXED:
1094 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1096 case FSF_PORT_HANDLE_NOT_VALID:
1097 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1");
1099 case FSF_GENERIC_COMMAND_REJECTED:
1100 case FSF_PAYLOAD_SIZE_MISMATCH:
1101 case FSF_REQUEST_SIZE_TOO_LARGE:
1102 case FSF_RESPONSE_SIZE_TOO_LARGE:
1103 case FSF_SBAL_MISMATCH:
1104 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1110 ct->handler(ct->handler_data);
1113 static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
1114 struct zfcp_qdio_req *q_req,
1115 struct scatterlist *sg_req,
1116 struct scatterlist *sg_resp)
1118 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
1119 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
1120 zfcp_qdio_set_sbale_last(qdio, q_req);
1123 static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
1124 struct scatterlist *sg_req,
1125 struct scatterlist *sg_resp)
1127 struct zfcp_adapter *adapter = req->adapter;
1128 struct zfcp_qdio *qdio = adapter->qdio;
1129 struct fsf_qtcb *qtcb = req->qtcb;
1130 u32 feat = adapter->adapter_features;
1132 if (zfcp_adapter_multi_buffer_active(adapter)) {
1133 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
1135 qtcb->bottom.support.req_buf_length =
1136 zfcp_qdio_real_bytes(sg_req);
1137 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
1139 qtcb->bottom.support.resp_buf_length =
1140 zfcp_qdio_real_bytes(sg_resp);
1142 zfcp_qdio_set_data_div(qdio, &req->qdio_req, sg_nents(sg_req));
1143 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1144 zfcp_qdio_set_scount(qdio, &req->qdio_req);
1148 /* use single, unchained SBAL if it can hold the request */
1149 if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
1150 zfcp_fsf_setup_ct_els_unchained(qdio, &req->qdio_req,
1155 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS))
1158 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
1161 qtcb->bottom.support.req_buf_length = zfcp_qdio_real_bytes(sg_req);
1163 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1164 zfcp_qdio_skip_to_last_sbale(qdio, &req->qdio_req);
1166 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
1169 qtcb->bottom.support.resp_buf_length = zfcp_qdio_real_bytes(sg_resp);
1171 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1176 static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1177 struct scatterlist *sg_req,
1178 struct scatterlist *sg_resp,
1179 unsigned int timeout)
1183 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
1187 /* common settings for ct/gs and els requests */
1189 timeout = 255; /* max value accepted by hardware */
1190 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
1191 req->qtcb->bottom.support.timeout = timeout;
1192 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
1198 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1199 * @wka_port: pointer to zfcp WKA port to send CT/GS to
1200 * @ct: pointer to struct zfcp_send_ct with data for request
1201 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1202 * @timeout: timeout that hardware should use, and a later software timeout
1204 int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
1205 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1206 unsigned int timeout)
1208 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1209 struct zfcp_fsf_req *req;
1212 spin_lock_irq(&qdio->req_q_lock);
1213 if (zfcp_qdio_sbal_get(qdio))
1216 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
1217 SBAL_SFLAGS0_TYPE_WRITE_READ, pool);
1224 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1225 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
1229 req->handler = zfcp_fsf_send_ct_handler;
1230 req->qtcb->header.port_handle = wka_port->handle;
1231 ct->d_id = wka_port->d_id;
1234 zfcp_dbf_san_req("fssct_1", req, wka_port->d_id);
1236 ret = zfcp_fsf_req_send(req);
1239 /* NOTE: DO NOT TOUCH req PAST THIS POINT! */
1244 zfcp_fsf_req_free(req);
1246 spin_unlock_irq(&qdio->req_q_lock);
1250 static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1252 struct zfcp_fsf_ct_els *send_els = req->data;
1253 struct fsf_qtcb_header *header = &req->qtcb->header;
1255 send_els->status = -EINVAL;
1257 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1258 goto skip_fsfstatus;
1260 switch (header->fsf_status) {
1262 send_els->status = 0;
1263 zfcp_dbf_san_res("fsselh1", req);
1265 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1266 zfcp_fsf_class_not_supp(req);
1268 case FSF_ADAPTER_STATUS_AVAILABLE:
1269 switch (header->fsf_status_qual.word[0]){
1270 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1271 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1272 case FSF_SQ_RETRY_IF_POSSIBLE:
1273 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1277 case FSF_ELS_COMMAND_REJECTED:
1278 case FSF_PAYLOAD_SIZE_MISMATCH:
1279 case FSF_REQUEST_SIZE_TOO_LARGE:
1280 case FSF_RESPONSE_SIZE_TOO_LARGE:
1282 case FSF_SBAL_MISMATCH:
1283 /* should never occur, avoided in zfcp_fsf_send_els */
1286 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1290 if (send_els->handler)
1291 send_els->handler(send_els->handler_data);
1295 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1296 * @adapter: pointer to zfcp adapter
1297 * @d_id: N_Port_ID to send ELS to
1298 * @els: pointer to struct zfcp_send_els with data for the command
1299 * @timeout: timeout that hardware should use, and a later software timeout
1301 int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
1302 struct zfcp_fsf_ct_els *els, unsigned int timeout)
1304 struct zfcp_fsf_req *req;
1305 struct zfcp_qdio *qdio = adapter->qdio;
1308 spin_lock_irq(&qdio->req_q_lock);
1309 if (zfcp_qdio_sbal_get(qdio))
1312 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
1313 SBAL_SFLAGS0_TYPE_WRITE_READ, NULL);
1320 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1322 if (!zfcp_adapter_multi_buffer_active(adapter))
1323 zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
1325 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
1330 hton24(req->qtcb->bottom.support.d_id, d_id);
1331 req->handler = zfcp_fsf_send_els_handler;
1335 zfcp_dbf_san_req("fssels1", req, d_id);
1337 ret = zfcp_fsf_req_send(req);
1340 /* NOTE: DO NOT TOUCH req PAST THIS POINT! */
1345 zfcp_fsf_req_free(req);
1347 spin_unlock_irq(&qdio->req_q_lock);
1351 int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1353 struct zfcp_fsf_req *req;
1354 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1357 spin_lock_irq(&qdio->req_q_lock);
1358 if (zfcp_qdio_sbal_get(qdio))
1361 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1362 SBAL_SFLAGS0_TYPE_READ,
1363 qdio->adapter->pool.erp_req);
1366 retval = PTR_ERR(req);
1370 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1371 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1373 req->qtcb->bottom.config.feature_selection =
1374 FSF_FEATURE_NOTIFICATION_LOST |
1375 FSF_FEATURE_UPDATE_ALERT |
1376 FSF_FEATURE_REQUEST_SFP_DATA |
1377 FSF_FEATURE_FC_SECURITY;
1378 req->erp_action = erp_action;
1379 req->handler = zfcp_fsf_exchange_config_data_handler;
1380 erp_action->fsf_req_id = req->req_id;
1382 zfcp_fsf_start_erp_timer(req);
1383 retval = zfcp_fsf_req_send(req);
1385 zfcp_fsf_req_free(req);
1386 erp_action->fsf_req_id = 0;
1388 /* NOTE: DO NOT TOUCH req PAST THIS POINT! */
1390 spin_unlock_irq(&qdio->req_q_lock);
1396 * zfcp_fsf_exchange_config_data_sync() - Request information about FCP channel.
1397 * @qdio: pointer to the QDIO-Queue to use for sending the command.
1398 * @data: pointer to the QTCB-Bottom for storing the result of the command,
1402 * * 0 - Exchange Config Data was successful, @data is complete
1403 * * -EIO - Exchange Config Data was not successful, @data is invalid
1404 * * -EAGAIN - @data contains incomplete data
1405 * * -ENOMEM - Some memory allocation failed along the way
1407 int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
1408 struct fsf_qtcb_bottom_config *data)
1410 struct zfcp_fsf_req *req = NULL;
1413 spin_lock_irq(&qdio->req_q_lock);
1414 if (zfcp_qdio_sbal_get(qdio))
1417 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1418 SBAL_SFLAGS0_TYPE_READ, NULL);
1421 retval = PTR_ERR(req);
1425 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1426 req->handler = zfcp_fsf_exchange_config_data_handler;
1428 req->qtcb->bottom.config.feature_selection =
1429 FSF_FEATURE_NOTIFICATION_LOST |
1430 FSF_FEATURE_UPDATE_ALERT |
1431 FSF_FEATURE_REQUEST_SFP_DATA |
1432 FSF_FEATURE_FC_SECURITY;
1437 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1438 retval = zfcp_fsf_req_send(req);
1439 spin_unlock_irq(&qdio->req_q_lock);
1442 /* NOTE: ONLY TOUCH SYNC req AGAIN ON req->completion. */
1443 wait_for_completion(&req->completion);
1446 (ZFCP_STATUS_FSFREQ_ERROR | ZFCP_STATUS_FSFREQ_DISMISSED))
1448 else if (req->status & ZFCP_STATUS_FSFREQ_XDATAINCOMPLETE)
1452 zfcp_fsf_req_free(req);
1456 spin_unlock_irq(&qdio->req_q_lock);
1461 * zfcp_fsf_exchange_port_data - request information about local port
1462 * @erp_action: ERP action for the adapter for which port data is requested
1463 * Returns: 0 on success, error otherwise
1465 int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1467 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1468 struct zfcp_fsf_req *req;
1471 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1474 spin_lock_irq(&qdio->req_q_lock);
1475 if (zfcp_qdio_sbal_get(qdio))
1478 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1479 SBAL_SFLAGS0_TYPE_READ,
1480 qdio->adapter->pool.erp_req);
1483 retval = PTR_ERR(req);
1487 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1488 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1490 req->handler = zfcp_fsf_exchange_port_data_handler;
1491 req->erp_action = erp_action;
1492 erp_action->fsf_req_id = req->req_id;
1494 zfcp_fsf_start_erp_timer(req);
1495 retval = zfcp_fsf_req_send(req);
1497 zfcp_fsf_req_free(req);
1498 erp_action->fsf_req_id = 0;
1500 /* NOTE: DO NOT TOUCH req PAST THIS POINT! */
1502 spin_unlock_irq(&qdio->req_q_lock);
1507 * zfcp_fsf_exchange_port_data_sync() - Request information about local port.
1508 * @qdio: pointer to the QDIO-Queue to use for sending the command.
1509 * @data: pointer to the QTCB-Bottom for storing the result of the command,
1513 * * 0 - Exchange Port Data was successful, @data is complete
1514 * * -EIO - Exchange Port Data was not successful, @data is invalid
1515 * * -EAGAIN - @data contains incomplete data
1516 * * -ENOMEM - Some memory allocation failed along the way
1517 * * -EOPNOTSUPP - This operation is not supported
1519 int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
1520 struct fsf_qtcb_bottom_port *data)
1522 struct zfcp_fsf_req *req = NULL;
1525 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1528 spin_lock_irq(&qdio->req_q_lock);
1529 if (zfcp_qdio_sbal_get(qdio))
1532 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1533 SBAL_SFLAGS0_TYPE_READ, NULL);
1536 retval = PTR_ERR(req);
1543 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1545 req->handler = zfcp_fsf_exchange_port_data_handler;
1546 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1547 retval = zfcp_fsf_req_send(req);
1548 spin_unlock_irq(&qdio->req_q_lock);
1551 /* NOTE: ONLY TOUCH SYNC req AGAIN ON req->completion. */
1552 wait_for_completion(&req->completion);
1555 (ZFCP_STATUS_FSFREQ_ERROR | ZFCP_STATUS_FSFREQ_DISMISSED))
1557 else if (req->status & ZFCP_STATUS_FSFREQ_XDATAINCOMPLETE)
1561 zfcp_fsf_req_free(req);
1565 spin_unlock_irq(&qdio->req_q_lock);
1569 static void zfcp_fsf_log_port_fc_security(struct zfcp_port *port,
1570 struct zfcp_fsf_req *req)
1572 char mnemonic_old[ZFCP_FSF_MAX_FC_SECURITY_MNEMONIC_LENGTH];
1573 char mnemonic_new[ZFCP_FSF_MAX_FC_SECURITY_MNEMONIC_LENGTH];
1575 if (port->connection_info == port->connection_info_old) {
1576 /* no change, no log nor trace */
1580 zfcp_dbf_hba_fsf_fces("fsfcesp", req, port->wwpn,
1581 port->connection_info_old,
1582 port->connection_info);
1584 zfcp_fsf_scnprint_fc_security(mnemonic_old, sizeof(mnemonic_old),
1585 port->connection_info_old,
1586 ZFCP_FSF_PRINT_FMT_SINGLEITEM);
1587 zfcp_fsf_scnprint_fc_security(mnemonic_new, sizeof(mnemonic_new),
1588 port->connection_info,
1589 ZFCP_FSF_PRINT_FMT_SINGLEITEM);
1591 if (strncmp(mnemonic_old, mnemonic_new,
1592 ZFCP_FSF_MAX_FC_SECURITY_MNEMONIC_LENGTH) == 0) {
1593 /* no change in string representation, no log */
1597 if (port->connection_info_old == 0) {
1599 dev_info(&port->adapter->ccw_device->dev,
1600 "FC Endpoint Security of connection to remote port 0x%16llx enabled: %s\n",
1601 port->wwpn, mnemonic_new);
1602 } else if (port->connection_info == 0) {
1604 dev_warn(&port->adapter->ccw_device->dev,
1605 "FC Endpoint Security of connection to remote port 0x%16llx disabled: was %s\n",
1606 port->wwpn, mnemonic_old);
1609 dev_warn(&port->adapter->ccw_device->dev,
1610 "FC Endpoint Security of connection to remote port 0x%16llx changed: from %s to %s\n",
1611 port->wwpn, mnemonic_old, mnemonic_new);
1615 port->connection_info_old = port->connection_info;
1618 static void zfcp_fsf_log_security_error(const struct device *dev, u32 fsf_sqw0,
1624 * Open Port command error codes
1627 case FSF_SQ_SECURITY_REQUIRED:
1628 dev_warn_ratelimited(dev,
1629 "FC Endpoint Security error: FC security is required but not supported or configured on remote port 0x%016llx\n",
1632 case FSF_SQ_SECURITY_TIMEOUT:
1633 dev_warn_ratelimited(dev,
1634 "FC Endpoint Security error: a timeout prevented opening remote port 0x%016llx\n",
1637 case FSF_SQ_SECURITY_KM_UNAVAILABLE:
1638 dev_warn_ratelimited(dev,
1639 "FC Endpoint Security error: opening remote port 0x%016llx failed because local and external key manager cannot communicate\n",
1642 case FSF_SQ_SECURITY_RKM_UNAVAILABLE:
1643 dev_warn_ratelimited(dev,
1644 "FC Endpoint Security error: opening remote port 0x%016llx failed because it cannot communicate with the external key manager\n",
1647 case FSF_SQ_SECURITY_AUTH_FAILURE:
1648 dev_warn_ratelimited(dev,
1649 "FC Endpoint Security error: the device could not verify the identity of remote port 0x%016llx\n",
1654 * Send FCP command error codes
1657 case FSF_SQ_SECURITY_ENC_FAILURE:
1658 dev_warn_ratelimited(dev,
1659 "FC Endpoint Security error: FC connection to remote port 0x%016llx closed because encryption broke down\n",
1664 * Unknown error codes
1668 dev_warn_ratelimited(dev,
1669 "FC Endpoint Security error: the device issued an unknown error code 0x%08x related to the FC connection to remote port 0x%016llx\n",
1674 static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1676 struct zfcp_adapter *adapter = req->adapter;
1677 struct zfcp_port *port = req->data;
1678 struct fsf_qtcb_header *header = &req->qtcb->header;
1679 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1680 struct fc_els_flogi *plogi;
1682 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1685 switch (header->fsf_status) {
1686 case FSF_PORT_ALREADY_OPEN:
1688 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1689 dev_warn(&adapter->ccw_device->dev,
1690 "Not enough FCP adapter resources to open "
1691 "remote port 0x%016Lx\n",
1692 (unsigned long long)port->wwpn);
1693 zfcp_erp_set_port_status(port,
1694 ZFCP_STATUS_COMMON_ERP_FAILED);
1695 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1697 case FSF_SECURITY_ERROR:
1698 zfcp_fsf_log_security_error(&req->adapter->ccw_device->dev,
1699 header->fsf_status_qual.word[0],
1701 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1703 case FSF_ADAPTER_STATUS_AVAILABLE:
1704 switch (header->fsf_status_qual.word[0]) {
1705 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1706 /* no zfcp_fc_test_link() with failed open port */
1708 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1709 case FSF_SQ_NO_RETRY_POSSIBLE:
1710 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1715 port->handle = header->port_handle;
1716 if (adapter->adapter_features & FSF_FEATURE_FC_SECURITY)
1717 port->connection_info = bottom->connection_info;
1719 port->connection_info = 0;
1720 zfcp_fsf_log_port_fc_security(port, req);
1721 atomic_or(ZFCP_STATUS_COMMON_OPEN |
1722 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1723 atomic_andnot(ZFCP_STATUS_COMMON_ACCESS_BOXED,
1725 /* check whether D_ID has changed during open */
1727 * FIXME: This check is not airtight, as the FCP channel does
1728 * not monitor closures of target port connections caused on
1729 * the remote side. Thus, they might miss out on invalidating
1730 * locally cached WWPNs (and other N_Port parameters) of gone
1731 * target ports. So, our heroic attempt to make things safe
1732 * could be undermined by 'open port' response data tagged with
1733 * obsolete WWPNs. Another reason to monitor potential
1734 * connection closures ourself at least (by interpreting
1735 * incoming ELS' and unsolicited status). It just crosses my
1736 * mind that one should be able to cross-check by means of
1737 * another GID_PN straight after a port has been opened.
1738 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1740 plogi = (struct fc_els_flogi *) bottom->els;
1741 if (bottom->els1_length >= FSF_PLOGI_MIN_LEN)
1742 zfcp_fc_plogi_evaluate(port, plogi);
1744 case FSF_UNKNOWN_OP_SUBTYPE:
1745 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1750 put_device(&port->dev);
1754 * zfcp_fsf_open_port - create and send open port request
1755 * @erp_action: pointer to struct zfcp_erp_action
1756 * Returns: 0 on success, error otherwise
1758 int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
1760 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1761 struct zfcp_port *port = erp_action->port;
1762 struct zfcp_fsf_req *req;
1765 spin_lock_irq(&qdio->req_q_lock);
1766 if (zfcp_qdio_sbal_get(qdio))
1769 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1770 SBAL_SFLAGS0_TYPE_READ,
1771 qdio->adapter->pool.erp_req);
1774 retval = PTR_ERR(req);
1778 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1779 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1781 req->handler = zfcp_fsf_open_port_handler;
1782 hton24(req->qtcb->bottom.support.d_id, port->d_id);
1784 req->erp_action = erp_action;
1785 erp_action->fsf_req_id = req->req_id;
1786 get_device(&port->dev);
1788 zfcp_fsf_start_erp_timer(req);
1789 retval = zfcp_fsf_req_send(req);
1791 zfcp_fsf_req_free(req);
1792 erp_action->fsf_req_id = 0;
1793 put_device(&port->dev);
1795 /* NOTE: DO NOT TOUCH req PAST THIS POINT! */
1797 spin_unlock_irq(&qdio->req_q_lock);
1801 static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
1803 struct zfcp_port *port = req->data;
1805 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1808 switch (req->qtcb->header.fsf_status) {
1809 case FSF_PORT_HANDLE_NOT_VALID:
1810 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1");
1811 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1813 case FSF_ADAPTER_STATUS_AVAILABLE:
1816 zfcp_erp_clear_port_status(port, ZFCP_STATUS_COMMON_OPEN);
1822 * zfcp_fsf_close_port - create and send close port request
1823 * @erp_action: pointer to struct zfcp_erp_action
1824 * Returns: 0 on success, error otherwise
1826 int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
1828 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1829 struct zfcp_fsf_req *req;
1832 spin_lock_irq(&qdio->req_q_lock);
1833 if (zfcp_qdio_sbal_get(qdio))
1836 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1837 SBAL_SFLAGS0_TYPE_READ,
1838 qdio->adapter->pool.erp_req);
1841 retval = PTR_ERR(req);
1845 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1846 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1848 req->handler = zfcp_fsf_close_port_handler;
1849 req->data = erp_action->port;
1850 req->erp_action = erp_action;
1851 req->qtcb->header.port_handle = erp_action->port->handle;
1852 erp_action->fsf_req_id = req->req_id;
1854 zfcp_fsf_start_erp_timer(req);
1855 retval = zfcp_fsf_req_send(req);
1857 zfcp_fsf_req_free(req);
1858 erp_action->fsf_req_id = 0;
1860 /* NOTE: DO NOT TOUCH req PAST THIS POINT! */
1862 spin_unlock_irq(&qdio->req_q_lock);
1866 static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1868 struct zfcp_fc_wka_port *wka_port = req->data;
1869 struct fsf_qtcb_header *header = &req->qtcb->header;
1871 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1872 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1876 switch (header->fsf_status) {
1877 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1878 dev_warn(&req->adapter->ccw_device->dev,
1879 "Opening WKA port 0x%x failed\n", wka_port->d_id);
1881 case FSF_ADAPTER_STATUS_AVAILABLE:
1882 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1883 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1886 wka_port->handle = header->port_handle;
1888 case FSF_PORT_ALREADY_OPEN:
1889 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
1892 wake_up(&wka_port->opened);
1896 * zfcp_fsf_open_wka_port - create and send open wka-port request
1897 * @wka_port: pointer to struct zfcp_fc_wka_port
1898 * Returns: 0 on success, error otherwise
1900 int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
1902 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1903 struct zfcp_fsf_req *req;
1904 unsigned long req_id = 0;
1907 spin_lock_irq(&qdio->req_q_lock);
1908 if (zfcp_qdio_sbal_get(qdio))
1911 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1912 SBAL_SFLAGS0_TYPE_READ,
1913 qdio->adapter->pool.erp_req);
1916 retval = PTR_ERR(req);
1920 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1921 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1923 req->handler = zfcp_fsf_open_wka_port_handler;
1924 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
1925 req->data = wka_port;
1927 req_id = req->req_id;
1929 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1930 retval = zfcp_fsf_req_send(req);
1932 zfcp_fsf_req_free(req);
1933 /* NOTE: DO NOT TOUCH req PAST THIS POINT! */
1935 spin_unlock_irq(&qdio->req_q_lock);
1937 zfcp_dbf_rec_run_wka("fsowp_1", wka_port, req_id);
1941 static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1943 struct zfcp_fc_wka_port *wka_port = req->data;
1945 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1946 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1947 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1");
1950 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1951 wake_up(&wka_port->closed);
1955 * zfcp_fsf_close_wka_port - create and send close wka port request
1956 * @wka_port: WKA port to open
1957 * Returns: 0 on success, error otherwise
1959 int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
1961 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1962 struct zfcp_fsf_req *req;
1963 unsigned long req_id = 0;
1966 spin_lock_irq(&qdio->req_q_lock);
1967 if (zfcp_qdio_sbal_get(qdio))
1970 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1971 SBAL_SFLAGS0_TYPE_READ,
1972 qdio->adapter->pool.erp_req);
1975 retval = PTR_ERR(req);
1979 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1980 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1982 req->handler = zfcp_fsf_close_wka_port_handler;
1983 req->data = wka_port;
1984 req->qtcb->header.port_handle = wka_port->handle;
1986 req_id = req->req_id;
1988 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1989 retval = zfcp_fsf_req_send(req);
1991 zfcp_fsf_req_free(req);
1992 /* NOTE: DO NOT TOUCH req PAST THIS POINT! */
1994 spin_unlock_irq(&qdio->req_q_lock);
1996 zfcp_dbf_rec_run_wka("fscwp_1", wka_port, req_id);
2000 static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
2002 struct zfcp_port *port = req->data;
2003 struct fsf_qtcb_header *header = &req->qtcb->header;
2004 struct scsi_device *sdev;
2006 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2009 switch (header->fsf_status) {
2010 case FSF_PORT_HANDLE_NOT_VALID:
2011 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1");
2012 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2014 case FSF_PORT_BOXED:
2015 /* can't use generic zfcp_erp_modify_port_status because
2016 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
2017 atomic_andnot(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2018 shost_for_each_device(sdev, port->adapter->scsi_host)
2019 if (sdev_to_zfcp(sdev)->port == port)
2020 atomic_andnot(ZFCP_STATUS_COMMON_OPEN,
2021 &sdev_to_zfcp(sdev)->status);
2022 zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_ACCESS_BOXED);
2023 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED,
2025 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2027 case FSF_ADAPTER_STATUS_AVAILABLE:
2028 switch (header->fsf_status_qual.word[0]) {
2029 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2030 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2031 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2036 /* can't use generic zfcp_erp_modify_port_status because
2037 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2039 atomic_andnot(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2040 shost_for_each_device(sdev, port->adapter->scsi_host)
2041 if (sdev_to_zfcp(sdev)->port == port)
2042 atomic_andnot(ZFCP_STATUS_COMMON_OPEN,
2043 &sdev_to_zfcp(sdev)->status);
2049 * zfcp_fsf_close_physical_port - close physical port
2050 * @erp_action: pointer to struct zfcp_erp_action
2051 * Returns: 0 on success
2053 int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2055 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
2056 struct zfcp_fsf_req *req;
2059 spin_lock_irq(&qdio->req_q_lock);
2060 if (zfcp_qdio_sbal_get(qdio))
2063 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
2064 SBAL_SFLAGS0_TYPE_READ,
2065 qdio->adapter->pool.erp_req);
2068 retval = PTR_ERR(req);
2072 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2073 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
2075 req->data = erp_action->port;
2076 req->qtcb->header.port_handle = erp_action->port->handle;
2077 req->erp_action = erp_action;
2078 req->handler = zfcp_fsf_close_physical_port_handler;
2079 erp_action->fsf_req_id = req->req_id;
2081 zfcp_fsf_start_erp_timer(req);
2082 retval = zfcp_fsf_req_send(req);
2084 zfcp_fsf_req_free(req);
2085 erp_action->fsf_req_id = 0;
2087 /* NOTE: DO NOT TOUCH req PAST THIS POINT! */
2089 spin_unlock_irq(&qdio->req_q_lock);
2093 static void zfcp_fsf_open_lun_handler(struct zfcp_fsf_req *req)
2095 struct zfcp_adapter *adapter = req->adapter;
2096 struct scsi_device *sdev = req->data;
2097 struct zfcp_scsi_dev *zfcp_sdev;
2098 struct fsf_qtcb_header *header = &req->qtcb->header;
2099 union fsf_status_qual *qual = &header->fsf_status_qual;
2101 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2104 zfcp_sdev = sdev_to_zfcp(sdev);
2106 atomic_andnot(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2107 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2108 &zfcp_sdev->status);
2110 switch (header->fsf_status) {
2112 case FSF_PORT_HANDLE_NOT_VALID:
2113 zfcp_erp_adapter_reopen(adapter, 0, "fsouh_1");
2115 case FSF_LUN_ALREADY_OPEN:
2117 case FSF_PORT_BOXED:
2118 zfcp_erp_set_port_status(zfcp_sdev->port,
2119 ZFCP_STATUS_COMMON_ACCESS_BOXED);
2120 zfcp_erp_port_reopen(zfcp_sdev->port,
2121 ZFCP_STATUS_COMMON_ERP_FAILED, "fsouh_2");
2122 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2124 case FSF_LUN_SHARING_VIOLATION:
2126 dev_warn(&zfcp_sdev->port->adapter->ccw_device->dev,
2127 "LUN 0x%016Lx on port 0x%016Lx is already in "
2128 "use by CSS%d, MIF Image ID %x\n",
2129 zfcp_scsi_dev_lun(sdev),
2130 (unsigned long long)zfcp_sdev->port->wwpn,
2131 qual->fsf_queue_designator.cssid,
2132 qual->fsf_queue_designator.hla);
2133 zfcp_erp_set_lun_status(sdev,
2134 ZFCP_STATUS_COMMON_ERP_FAILED |
2135 ZFCP_STATUS_COMMON_ACCESS_DENIED);
2136 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2138 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
2139 dev_warn(&adapter->ccw_device->dev,
2140 "No handle is available for LUN "
2141 "0x%016Lx on port 0x%016Lx\n",
2142 (unsigned long long)zfcp_scsi_dev_lun(sdev),
2143 (unsigned long long)zfcp_sdev->port->wwpn);
2144 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ERP_FAILED);
2146 case FSF_INVALID_COMMAND_OPTION:
2147 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2149 case FSF_ADAPTER_STATUS_AVAILABLE:
2150 switch (header->fsf_status_qual.word[0]) {
2151 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2152 zfcp_fc_test_link(zfcp_sdev->port);
2154 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2155 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2161 zfcp_sdev->lun_handle = header->lun_handle;
2162 atomic_or(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
2168 * zfcp_fsf_open_lun - open LUN
2169 * @erp_action: pointer to struct zfcp_erp_action
2170 * Returns: 0 on success, error otherwise
2172 int zfcp_fsf_open_lun(struct zfcp_erp_action *erp_action)
2174 struct zfcp_adapter *adapter = erp_action->adapter;
2175 struct zfcp_qdio *qdio = adapter->qdio;
2176 struct zfcp_fsf_req *req;
2179 spin_lock_irq(&qdio->req_q_lock);
2180 if (zfcp_qdio_sbal_get(qdio))
2183 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
2184 SBAL_SFLAGS0_TYPE_READ,
2185 adapter->pool.erp_req);
2188 retval = PTR_ERR(req);
2192 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2193 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
2195 req->qtcb->header.port_handle = erp_action->port->handle;
2196 req->qtcb->bottom.support.fcp_lun = zfcp_scsi_dev_lun(erp_action->sdev);
2197 req->handler = zfcp_fsf_open_lun_handler;
2198 req->data = erp_action->sdev;
2199 req->erp_action = erp_action;
2200 erp_action->fsf_req_id = req->req_id;
2202 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
2203 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
2205 zfcp_fsf_start_erp_timer(req);
2206 retval = zfcp_fsf_req_send(req);
2208 zfcp_fsf_req_free(req);
2209 erp_action->fsf_req_id = 0;
2211 /* NOTE: DO NOT TOUCH req PAST THIS POINT! */
2213 spin_unlock_irq(&qdio->req_q_lock);
2217 static void zfcp_fsf_close_lun_handler(struct zfcp_fsf_req *req)
2219 struct scsi_device *sdev = req->data;
2220 struct zfcp_scsi_dev *zfcp_sdev;
2222 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2225 zfcp_sdev = sdev_to_zfcp(sdev);
2227 switch (req->qtcb->header.fsf_status) {
2228 case FSF_PORT_HANDLE_NOT_VALID:
2229 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fscuh_1");
2230 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2232 case FSF_LUN_HANDLE_NOT_VALID:
2233 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fscuh_2");
2234 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2236 case FSF_PORT_BOXED:
2237 zfcp_erp_set_port_status(zfcp_sdev->port,
2238 ZFCP_STATUS_COMMON_ACCESS_BOXED);
2239 zfcp_erp_port_reopen(zfcp_sdev->port,
2240 ZFCP_STATUS_COMMON_ERP_FAILED, "fscuh_3");
2241 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2243 case FSF_ADAPTER_STATUS_AVAILABLE:
2244 switch (req->qtcb->header.fsf_status_qual.word[0]) {
2245 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2246 zfcp_fc_test_link(zfcp_sdev->port);
2248 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2249 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2254 atomic_andnot(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
2260 * zfcp_fsf_close_LUN - close LUN
2261 * @erp_action: pointer to erp_action triggering the "close LUN"
2262 * Returns: 0 on success, error otherwise
2264 int zfcp_fsf_close_lun(struct zfcp_erp_action *erp_action)
2266 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
2267 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(erp_action->sdev);
2268 struct zfcp_fsf_req *req;
2271 spin_lock_irq(&qdio->req_q_lock);
2272 if (zfcp_qdio_sbal_get(qdio))
2275 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
2276 SBAL_SFLAGS0_TYPE_READ,
2277 qdio->adapter->pool.erp_req);
2280 retval = PTR_ERR(req);
2284 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2285 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
2287 req->qtcb->header.port_handle = erp_action->port->handle;
2288 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2289 req->handler = zfcp_fsf_close_lun_handler;
2290 req->data = erp_action->sdev;
2291 req->erp_action = erp_action;
2292 erp_action->fsf_req_id = req->req_id;
2294 zfcp_fsf_start_erp_timer(req);
2295 retval = zfcp_fsf_req_send(req);
2297 zfcp_fsf_req_free(req);
2298 erp_action->fsf_req_id = 0;
2300 /* NOTE: DO NOT TOUCH req PAST THIS POINT! */
2302 spin_unlock_irq(&qdio->req_q_lock);
2306 static void zfcp_fsf_update_lat(struct zfcp_latency_record *lat_rec, u32 lat)
2308 lat_rec->sum += lat;
2309 lat_rec->min = min(lat_rec->min, lat);
2310 lat_rec->max = max(lat_rec->max, lat);
2313 static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
2315 struct fsf_qual_latency_info *lat_in;
2316 struct zfcp_latency_cont *lat = NULL;
2317 struct zfcp_scsi_dev *zfcp_sdev;
2318 struct zfcp_blk_drv_data blktrc;
2319 int ticks = req->adapter->timer_ticks;
2321 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
2324 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2325 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2326 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
2327 blktrc.inb_usage = 0;
2328 blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
2330 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
2331 !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2332 zfcp_sdev = sdev_to_zfcp(scsi->device);
2333 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2334 blktrc.channel_lat = lat_in->channel_lat * ticks;
2335 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2337 switch (req->qtcb->bottom.io.data_direction) {
2338 case FSF_DATADIR_DIF_READ_STRIP:
2339 case FSF_DATADIR_DIF_READ_CONVERT:
2340 case FSF_DATADIR_READ:
2341 lat = &zfcp_sdev->latencies.read;
2343 case FSF_DATADIR_DIF_WRITE_INSERT:
2344 case FSF_DATADIR_DIF_WRITE_CONVERT:
2345 case FSF_DATADIR_WRITE:
2346 lat = &zfcp_sdev->latencies.write;
2348 case FSF_DATADIR_CMND:
2349 lat = &zfcp_sdev->latencies.cmd;
2354 spin_lock(&zfcp_sdev->latencies.lock);
2355 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2356 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2358 spin_unlock(&zfcp_sdev->latencies.lock);
2362 blk_add_driver_data(scsi->request, &blktrc, sizeof(blktrc));
2366 * zfcp_fsf_fcp_handler_common() - FCP response handler common to I/O and TMF.
2367 * @req: Pointer to FSF request.
2368 * @sdev: Pointer to SCSI device as request context.
2370 static void zfcp_fsf_fcp_handler_common(struct zfcp_fsf_req *req,
2371 struct scsi_device *sdev)
2373 struct zfcp_scsi_dev *zfcp_sdev;
2374 struct fsf_qtcb_header *header = &req->qtcb->header;
2376 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2379 zfcp_sdev = sdev_to_zfcp(sdev);
2381 switch (header->fsf_status) {
2382 case FSF_HANDLE_MISMATCH:
2383 case FSF_PORT_HANDLE_NOT_VALID:
2384 zfcp_erp_adapter_reopen(req->adapter, 0, "fssfch1");
2385 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2387 case FSF_FCPLUN_NOT_VALID:
2388 case FSF_LUN_HANDLE_NOT_VALID:
2389 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fssfch2");
2390 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2392 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2393 zfcp_fsf_class_not_supp(req);
2395 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2396 dev_err(&req->adapter->ccw_device->dev,
2397 "Incorrect direction %d, LUN 0x%016Lx on port "
2398 "0x%016Lx closed\n",
2399 req->qtcb->bottom.io.data_direction,
2400 (unsigned long long)zfcp_scsi_dev_lun(sdev),
2401 (unsigned long long)zfcp_sdev->port->wwpn);
2402 zfcp_erp_adapter_shutdown(req->adapter, 0, "fssfch3");
2403 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2405 case FSF_CMND_LENGTH_NOT_VALID:
2406 dev_err(&req->adapter->ccw_device->dev,
2407 "Incorrect FCP_CMND length %d, FCP device closed\n",
2408 req->qtcb->bottom.io.fcp_cmnd_length);
2409 zfcp_erp_adapter_shutdown(req->adapter, 0, "fssfch4");
2410 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2412 case FSF_PORT_BOXED:
2413 zfcp_erp_set_port_status(zfcp_sdev->port,
2414 ZFCP_STATUS_COMMON_ACCESS_BOXED);
2415 zfcp_erp_port_reopen(zfcp_sdev->port,
2416 ZFCP_STATUS_COMMON_ERP_FAILED, "fssfch5");
2417 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2420 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
2421 zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
2423 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2425 case FSF_ADAPTER_STATUS_AVAILABLE:
2426 if (header->fsf_status_qual.word[0] ==
2427 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
2428 zfcp_fc_test_link(zfcp_sdev->port);
2429 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2431 case FSF_SECURITY_ERROR:
2432 zfcp_fsf_log_security_error(&req->adapter->ccw_device->dev,
2433 header->fsf_status_qual.word[0],
2434 zfcp_sdev->port->wwpn);
2435 zfcp_erp_port_forced_reopen(zfcp_sdev->port, 0, "fssfch7");
2436 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2441 static void zfcp_fsf_fcp_cmnd_handler(struct zfcp_fsf_req *req)
2443 struct scsi_cmnd *scpnt;
2444 struct fcp_resp_with_ext *fcp_rsp;
2445 unsigned long flags;
2447 read_lock_irqsave(&req->adapter->abort_lock, flags);
2450 if (unlikely(!scpnt)) {
2451 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2455 zfcp_fsf_fcp_handler_common(req, scpnt->device);
2457 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2458 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
2459 goto skip_fsfstatus;
2462 switch (req->qtcb->header.fsf_status) {
2463 case FSF_INCONSISTENT_PROT_DATA:
2464 case FSF_INVALID_PROT_PARM:
2465 set_host_byte(scpnt, DID_ERROR);
2466 goto skip_fsfstatus;
2467 case FSF_BLOCK_GUARD_CHECK_FAILURE:
2468 zfcp_scsi_dif_sense_error(scpnt, 0x1);
2469 goto skip_fsfstatus;
2470 case FSF_APP_TAG_CHECK_FAILURE:
2471 zfcp_scsi_dif_sense_error(scpnt, 0x2);
2472 goto skip_fsfstatus;
2473 case FSF_REF_TAG_CHECK_FAILURE:
2474 zfcp_scsi_dif_sense_error(scpnt, 0x3);
2475 goto skip_fsfstatus;
2477 BUILD_BUG_ON(sizeof(struct fcp_resp_with_ext) > FSF_FCP_RSP_SIZE);
2478 fcp_rsp = &req->qtcb->bottom.io.fcp_rsp.iu;
2479 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
2482 zfcp_fsf_req_trace(req, scpnt);
2483 zfcp_dbf_scsi_result(scpnt, req);
2485 scpnt->host_scribble = NULL;
2486 (scpnt->scsi_done) (scpnt);
2488 * We must hold this lock until scsi_done has been called.
2489 * Otherwise we may call scsi_done after abort regarding this
2490 * command has completed.
2491 * Note: scsi_done must not block!
2493 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2496 static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir)
2498 switch (scsi_get_prot_op(scsi_cmnd)) {
2499 case SCSI_PROT_NORMAL:
2500 switch (scsi_cmnd->sc_data_direction) {
2502 *data_dir = FSF_DATADIR_CMND;
2504 case DMA_FROM_DEVICE:
2505 *data_dir = FSF_DATADIR_READ;
2508 *data_dir = FSF_DATADIR_WRITE;
2510 case DMA_BIDIRECTIONAL:
2515 case SCSI_PROT_READ_STRIP:
2516 *data_dir = FSF_DATADIR_DIF_READ_STRIP;
2518 case SCSI_PROT_WRITE_INSERT:
2519 *data_dir = FSF_DATADIR_DIF_WRITE_INSERT;
2521 case SCSI_PROT_READ_PASS:
2522 *data_dir = FSF_DATADIR_DIF_READ_CONVERT;
2524 case SCSI_PROT_WRITE_PASS:
2525 *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT;
2535 * zfcp_fsf_fcp_cmnd - initiate an FCP command (for a SCSI command)
2536 * @scsi_cmnd: scsi command to be sent
2538 int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
2540 struct zfcp_fsf_req *req;
2541 struct fcp_cmnd *fcp_cmnd;
2542 u8 sbtype = SBAL_SFLAGS0_TYPE_READ;
2544 struct scsi_device *sdev = scsi_cmnd->device;
2545 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
2546 struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
2547 struct zfcp_qdio *qdio = adapter->qdio;
2548 struct fsf_qtcb_bottom_io *io;
2549 unsigned long flags;
2551 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
2552 ZFCP_STATUS_COMMON_UNBLOCKED)))
2555 spin_lock_irqsave(&qdio->req_q_lock, flags);
2556 if (atomic_read(&qdio->req_q_free) <= 0) {
2557 atomic_inc(&qdio->req_q_full);
2561 if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
2562 sbtype = SBAL_SFLAGS0_TYPE_WRITE;
2564 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2565 sbtype, adapter->pool.scsi_req);
2568 retval = PTR_ERR(req);
2572 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2574 io = &req->qtcb->bottom.io;
2575 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2576 req->data = scsi_cmnd;
2577 req->handler = zfcp_fsf_fcp_cmnd_handler;
2578 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2579 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
2580 io->service_class = FSF_CLASS_3;
2581 io->fcp_cmnd_length = FCP_CMND_LEN;
2583 if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
2584 io->data_block_length = scsi_cmnd->device->sector_size;
2585 io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
2588 if (zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction))
2589 goto failed_scsi_cmnd;
2591 BUILD_BUG_ON(sizeof(struct fcp_cmnd) > FSF_FCP_CMND_SIZE);
2592 fcp_cmnd = &req->qtcb->bottom.io.fcp_cmnd.iu;
2593 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
2595 if ((scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) &&
2596 scsi_prot_sg_count(scsi_cmnd)) {
2597 zfcp_qdio_set_data_div(qdio, &req->qdio_req,
2598 scsi_prot_sg_count(scsi_cmnd));
2599 retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2600 scsi_prot_sglist(scsi_cmnd));
2602 goto failed_scsi_cmnd;
2603 io->prot_data_length = zfcp_qdio_real_bytes(
2604 scsi_prot_sglist(scsi_cmnd));
2607 retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2608 scsi_sglist(scsi_cmnd));
2609 if (unlikely(retval))
2610 goto failed_scsi_cmnd;
2612 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
2613 if (zfcp_adapter_multi_buffer_active(adapter))
2614 zfcp_qdio_set_scount(qdio, &req->qdio_req);
2616 retval = zfcp_fsf_req_send(req);
2617 if (unlikely(retval))
2618 goto failed_scsi_cmnd;
2619 /* NOTE: DO NOT TOUCH req PAST THIS POINT! */
2624 zfcp_fsf_req_free(req);
2625 scsi_cmnd->host_scribble = NULL;
2627 spin_unlock_irqrestore(&qdio->req_q_lock, flags);
2631 static void zfcp_fsf_fcp_task_mgmt_handler(struct zfcp_fsf_req *req)
2633 struct scsi_device *sdev = req->data;
2634 struct fcp_resp_with_ext *fcp_rsp;
2635 struct fcp_resp_rsp_info *rsp_info;
2637 zfcp_fsf_fcp_handler_common(req, sdev);
2639 fcp_rsp = &req->qtcb->bottom.io.fcp_rsp.iu;
2640 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2642 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
2643 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2644 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
2648 * zfcp_fsf_fcp_task_mgmt() - Send SCSI task management command (TMF).
2649 * @sdev: Pointer to SCSI device to send the task management command to.
2650 * @tm_flags: Unsigned byte for task management flags.
2652 * Return: On success pointer to struct zfcp_fsf_req, %NULL otherwise.
2654 struct zfcp_fsf_req *zfcp_fsf_fcp_task_mgmt(struct scsi_device *sdev,
2657 struct zfcp_fsf_req *req = NULL;
2658 struct fcp_cmnd *fcp_cmnd;
2659 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
2660 struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
2662 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
2663 ZFCP_STATUS_COMMON_UNBLOCKED)))
2666 spin_lock_irq(&qdio->req_q_lock);
2667 if (zfcp_qdio_sbal_get(qdio))
2670 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2671 SBAL_SFLAGS0_TYPE_WRITE,
2672 qdio->adapter->pool.scsi_req);
2681 req->handler = zfcp_fsf_fcp_task_mgmt_handler;
2682 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2683 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
2684 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2685 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2686 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
2688 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
2690 fcp_cmnd = &req->qtcb->bottom.io.fcp_cmnd.iu;
2691 zfcp_fc_fcp_tm(fcp_cmnd, sdev, tm_flags);
2693 zfcp_fsf_start_timer(req, ZFCP_FSF_SCSI_ER_TIMEOUT);
2694 if (!zfcp_fsf_req_send(req)) {
2695 /* NOTE: DO NOT TOUCH req, UNTIL IT COMPLETES! */
2699 zfcp_fsf_req_free(req);
2702 spin_unlock_irq(&qdio->req_q_lock);
2707 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2708 * @qdio: pointer to struct zfcp_qdio
2709 * @sbal_idx: response queue index of SBAL to be processed
2711 void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
2713 struct zfcp_adapter *adapter = qdio->adapter;
2714 struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
2715 struct qdio_buffer_element *sbale;
2716 struct zfcp_fsf_req *fsf_req;
2717 unsigned long req_id;
2720 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2722 sbale = &sbal->element[idx];
2723 req_id = sbale->addr;
2724 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
2728 * Unknown request means that we have potentially memory
2729 * corruption and must stop the machine immediately.
2731 zfcp_qdio_siosl(adapter);
2732 panic("error: unknown req_id (%lx) on adapter %s.\n",
2733 req_id, dev_name(&adapter->ccw_device->dev));
2736 zfcp_fsf_req_complete(fsf_req);
2738 if (likely(sbale->eflags & SBAL_EFLAGS_LAST_ENTRY))