1 // SPDX-License-Identifier: GPL-2.0
5 * Implementation of FSF commands.
7 * Copyright IBM Corp. 2002, 2018
10 #define KMSG_COMPONENT "zfcp"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 #include <linux/blktrace_api.h>
14 #include <linux/slab.h>
15 #include <scsi/fc/fc_els.h>
19 #include "zfcp_qdio.h"
20 #include "zfcp_reqlist.h"
22 /* timeout for FSF requests sent during scsi_eh: abort or FCP TMF */
23 #define ZFCP_FSF_SCSI_ER_TIMEOUT (10*HZ)
24 /* timeout for: exchange config/port data outside ERP, or open/close WKA port */
25 #define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ)
27 struct kmem_cache *zfcp_fsf_qtcb_cache;
29 static void zfcp_fsf_request_timeout_handler(struct timer_list *t)
31 struct zfcp_fsf_req *fsf_req = from_timer(fsf_req, t, timer);
32 struct zfcp_adapter *adapter = fsf_req->adapter;
34 zfcp_qdio_siosl(adapter);
35 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
39 static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
40 unsigned long timeout)
42 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
43 fsf_req->timer.expires = jiffies + timeout;
44 add_timer(&fsf_req->timer);
47 static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
49 BUG_ON(!fsf_req->erp_action);
50 fsf_req->timer.function = zfcp_erp_timeout_handler;
51 fsf_req->timer.expires = jiffies + 30 * HZ;
52 add_timer(&fsf_req->timer);
55 /* association between FSF command and FSF QTCB type */
56 static u32 fsf_qtcb_type[] = {
57 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
58 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
59 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
60 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
61 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
62 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
63 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
64 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
65 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
66 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
67 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
68 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
69 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
72 static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
74 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
75 "operational because of an unsupported FC class\n");
76 zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1");
77 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
81 * zfcp_fsf_req_free - free memory used by fsf request
82 * @req: pointer to struct zfcp_fsf_req
84 void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
86 if (likely(req->pool)) {
87 if (likely(!zfcp_fsf_req_is_status_read_buffer(req)))
88 mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
89 mempool_free(req, req->pool);
93 if (likely(!zfcp_fsf_req_is_status_read_buffer(req)))
94 kmem_cache_free(zfcp_fsf_qtcb_cache, req->qtcb);
98 static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
101 struct fsf_status_read_buffer *sr_buf = req->data;
102 struct zfcp_adapter *adapter = req->adapter;
103 struct zfcp_port *port;
104 int d_id = ntoh24(sr_buf->d_id);
106 read_lock_irqsave(&adapter->port_list_lock, flags);
107 list_for_each_entry(port, &adapter->port_list, list)
108 if (port->d_id == d_id) {
109 zfcp_erp_port_reopen(port, 0, "fssrpc1");
112 read_unlock_irqrestore(&adapter->port_list_lock, flags);
115 static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req,
116 struct fsf_link_down_info *link_down)
118 struct zfcp_adapter *adapter = req->adapter;
120 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
123 atomic_or(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
125 zfcp_scsi_schedule_rports_block(adapter);
130 switch (link_down->error_code) {
131 case FSF_PSQ_LINK_NO_LIGHT:
132 dev_warn(&req->adapter->ccw_device->dev,
133 "There is no light signal from the local "
134 "fibre channel cable\n");
136 case FSF_PSQ_LINK_WRAP_PLUG:
137 dev_warn(&req->adapter->ccw_device->dev,
138 "There is a wrap plug instead of a fibre "
141 case FSF_PSQ_LINK_NO_FCP:
142 dev_warn(&req->adapter->ccw_device->dev,
143 "The adjacent fibre channel node does not "
146 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
147 dev_warn(&req->adapter->ccw_device->dev,
148 "The FCP device is suspended because of a "
149 "firmware update\n");
151 case FSF_PSQ_LINK_INVALID_WWPN:
152 dev_warn(&req->adapter->ccw_device->dev,
153 "The FCP device detected a WWPN that is "
154 "duplicate or not valid\n");
156 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
157 dev_warn(&req->adapter->ccw_device->dev,
158 "The fibre channel fabric does not support NPIV\n");
160 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
161 dev_warn(&req->adapter->ccw_device->dev,
162 "The FCP adapter cannot support more NPIV ports\n");
164 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
165 dev_warn(&req->adapter->ccw_device->dev,
166 "The adjacent switch cannot support "
167 "more NPIV ports\n");
169 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
170 dev_warn(&req->adapter->ccw_device->dev,
171 "The FCP adapter could not log in to the "
172 "fibre channel fabric\n");
174 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
175 dev_warn(&req->adapter->ccw_device->dev,
176 "The WWPN assignment file on the FCP adapter "
177 "has been damaged\n");
179 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
180 dev_warn(&req->adapter->ccw_device->dev,
181 "The mode table on the FCP adapter "
182 "has been damaged\n");
184 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
185 dev_warn(&req->adapter->ccw_device->dev,
186 "All NPIV ports on the FCP adapter have "
190 dev_warn(&req->adapter->ccw_device->dev,
191 "The link between the FCP adapter and "
192 "the FC fabric is down\n");
195 zfcp_erp_set_adapter_status(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
198 static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
200 struct fsf_status_read_buffer *sr_buf = req->data;
201 struct fsf_link_down_info *ldi =
202 (struct fsf_link_down_info *) &sr_buf->payload;
204 switch (sr_buf->status_subtype) {
205 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
206 case FSF_STATUS_READ_SUB_FDISC_FAILED:
207 zfcp_fsf_link_down_info_eval(req, ldi);
209 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
210 zfcp_fsf_link_down_info_eval(req, NULL);
214 static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
216 struct zfcp_adapter *adapter = req->adapter;
217 struct fsf_status_read_buffer *sr_buf = req->data;
219 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
220 zfcp_dbf_hba_fsf_uss("fssrh_1", req);
221 mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
222 zfcp_fsf_req_free(req);
226 zfcp_dbf_hba_fsf_uss("fssrh_4", req);
228 switch (sr_buf->status_type) {
229 case FSF_STATUS_READ_PORT_CLOSED:
230 zfcp_fsf_status_read_port_closed(req);
232 case FSF_STATUS_READ_INCOMING_ELS:
233 zfcp_fc_incoming_els(req);
235 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
237 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
238 dev_warn(&adapter->ccw_device->dev,
239 "The error threshold for checksum statistics "
240 "has been exceeded\n");
241 zfcp_dbf_hba_bit_err("fssrh_3", req);
243 case FSF_STATUS_READ_LINK_DOWN:
244 zfcp_fsf_status_read_link_down(req);
245 zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKDOWN, 0);
247 case FSF_STATUS_READ_LINK_UP:
248 dev_info(&adapter->ccw_device->dev,
249 "The local link has been restored\n");
250 /* All ports should be marked as ready to run again */
251 zfcp_erp_set_adapter_status(adapter,
252 ZFCP_STATUS_COMMON_RUNNING);
253 zfcp_erp_adapter_reopen(adapter,
254 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
255 ZFCP_STATUS_COMMON_ERP_FAILED,
257 zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKUP, 0);
260 case FSF_STATUS_READ_NOTIFICATION_LOST:
261 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
262 zfcp_fc_conditional_port_scan(adapter);
264 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
265 adapter->adapter_features = sr_buf->payload.word[0];
269 mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
270 zfcp_fsf_req_free(req);
272 atomic_inc(&adapter->stat_miss);
273 queue_work(adapter->work_queue, &adapter->stat_work);
276 static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
278 switch (req->qtcb->header.fsf_status_qual.word[0]) {
279 case FSF_SQ_FCP_RSP_AVAILABLE:
280 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
281 case FSF_SQ_NO_RETRY_POSSIBLE:
282 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
284 case FSF_SQ_COMMAND_ABORTED:
286 case FSF_SQ_NO_RECOM:
287 dev_err(&req->adapter->ccw_device->dev,
288 "The FCP adapter reported a problem "
289 "that cannot be recovered\n");
290 zfcp_qdio_siosl(req->adapter);
291 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1");
294 /* all non-return stats set FSFREQ_ERROR*/
295 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
298 static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
300 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
303 switch (req->qtcb->header.fsf_status) {
304 case FSF_UNKNOWN_COMMAND:
305 dev_err(&req->adapter->ccw_device->dev,
306 "The FCP adapter does not recognize the command 0x%x\n",
307 req->qtcb->header.fsf_command);
308 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1");
309 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
311 case FSF_ADAPTER_STATUS_AVAILABLE:
312 zfcp_fsf_fsfstatus_qual_eval(req);
317 static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
319 struct zfcp_adapter *adapter = req->adapter;
320 struct fsf_qtcb *qtcb = req->qtcb;
321 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
323 zfcp_dbf_hba_fsf_response(req);
325 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
326 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
330 switch (qtcb->prefix.prot_status) {
332 case FSF_PROT_FSF_STATUS_PRESENTED:
334 case FSF_PROT_QTCB_VERSION_ERROR:
335 dev_err(&adapter->ccw_device->dev,
336 "QTCB version 0x%x not supported by FCP adapter "
337 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
338 psq->word[0], psq->word[1]);
339 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1");
341 case FSF_PROT_ERROR_STATE:
342 case FSF_PROT_SEQ_NUMB_ERROR:
343 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2");
344 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
346 case FSF_PROT_UNSUPP_QTCB_TYPE:
347 dev_err(&adapter->ccw_device->dev,
348 "The QTCB type is not supported by the FCP adapter\n");
349 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3");
351 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
352 atomic_or(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
355 case FSF_PROT_DUPLICATE_REQUEST_ID:
356 dev_err(&adapter->ccw_device->dev,
357 "0x%Lx is an ambiguous request identifier\n",
358 (unsigned long long)qtcb->bottom.support.req_handle);
359 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4");
361 case FSF_PROT_LINK_DOWN:
362 zfcp_fsf_link_down_info_eval(req, &psq->link_down_info);
363 /* go through reopen to flush pending requests */
364 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6");
366 case FSF_PROT_REEST_QUEUE:
367 /* All ports should be marked as ready to run again */
368 zfcp_erp_set_adapter_status(adapter,
369 ZFCP_STATUS_COMMON_RUNNING);
370 zfcp_erp_adapter_reopen(adapter,
371 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
372 ZFCP_STATUS_COMMON_ERP_FAILED,
376 dev_err(&adapter->ccw_device->dev,
377 "0x%x is not a valid transfer protocol status\n",
378 qtcb->prefix.prot_status);
379 zfcp_qdio_siosl(adapter);
380 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9");
382 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
386 * zfcp_fsf_req_complete - process completion of a FSF request
387 * @req: The FSF request that has been completed.
389 * When a request has been completed either from the FCP adapter,
390 * or it has been dismissed due to a queue shutdown, this function
391 * is called to process the completion status and trigger further
392 * events related to the FSF request.
394 static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
396 if (unlikely(zfcp_fsf_req_is_status_read_buffer(req))) {
397 zfcp_fsf_status_read_handler(req);
401 del_timer(&req->timer);
402 zfcp_fsf_protstatus_eval(req);
403 zfcp_fsf_fsfstatus_eval(req);
407 zfcp_erp_notify(req->erp_action, 0);
409 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
410 zfcp_fsf_req_free(req);
412 complete(&req->completion);
416 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
417 * @adapter: pointer to struct zfcp_adapter
419 * Never ever call this without shutting down the adapter first.
420 * Otherwise the adapter would continue using and corrupting s390 storage.
421 * Included BUG_ON() call to ensure this is done.
422 * ERP is supposed to be the only user of this function.
424 void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
426 struct zfcp_fsf_req *req, *tmp;
427 LIST_HEAD(remove_queue);
429 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
430 zfcp_reqlist_move(adapter->req_list, &remove_queue);
432 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
433 list_del(&req->list);
434 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
435 zfcp_fsf_req_complete(req);
439 #define ZFCP_FSF_PORTSPEED_1GBIT (1 << 0)
440 #define ZFCP_FSF_PORTSPEED_2GBIT (1 << 1)
441 #define ZFCP_FSF_PORTSPEED_4GBIT (1 << 2)
442 #define ZFCP_FSF_PORTSPEED_10GBIT (1 << 3)
443 #define ZFCP_FSF_PORTSPEED_8GBIT (1 << 4)
444 #define ZFCP_FSF_PORTSPEED_16GBIT (1 << 5)
445 #define ZFCP_FSF_PORTSPEED_32GBIT (1 << 6)
446 #define ZFCP_FSF_PORTSPEED_64GBIT (1 << 7)
447 #define ZFCP_FSF_PORTSPEED_128GBIT (1 << 8)
448 #define ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED (1 << 15)
450 static u32 zfcp_fsf_convert_portspeed(u32 fsf_speed)
453 if (fsf_speed & ZFCP_FSF_PORTSPEED_1GBIT)
454 fdmi_speed |= FC_PORTSPEED_1GBIT;
455 if (fsf_speed & ZFCP_FSF_PORTSPEED_2GBIT)
456 fdmi_speed |= FC_PORTSPEED_2GBIT;
457 if (fsf_speed & ZFCP_FSF_PORTSPEED_4GBIT)
458 fdmi_speed |= FC_PORTSPEED_4GBIT;
459 if (fsf_speed & ZFCP_FSF_PORTSPEED_10GBIT)
460 fdmi_speed |= FC_PORTSPEED_10GBIT;
461 if (fsf_speed & ZFCP_FSF_PORTSPEED_8GBIT)
462 fdmi_speed |= FC_PORTSPEED_8GBIT;
463 if (fsf_speed & ZFCP_FSF_PORTSPEED_16GBIT)
464 fdmi_speed |= FC_PORTSPEED_16GBIT;
465 if (fsf_speed & ZFCP_FSF_PORTSPEED_32GBIT)
466 fdmi_speed |= FC_PORTSPEED_32GBIT;
467 if (fsf_speed & ZFCP_FSF_PORTSPEED_64GBIT)
468 fdmi_speed |= FC_PORTSPEED_64GBIT;
469 if (fsf_speed & ZFCP_FSF_PORTSPEED_128GBIT)
470 fdmi_speed |= FC_PORTSPEED_128GBIT;
471 if (fsf_speed & ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED)
472 fdmi_speed |= FC_PORTSPEED_NOT_NEGOTIATED;
476 static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
478 struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
479 struct zfcp_adapter *adapter = req->adapter;
480 struct Scsi_Host *shost = adapter->scsi_host;
481 struct fc_els_flogi *nsp, *plogi;
483 /* adjust pointers for missing command code */
484 nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
486 plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
490 memcpy(req->data, bottom, sizeof(*bottom));
492 fc_host_port_name(shost) = be64_to_cpu(nsp->fl_wwpn);
493 fc_host_node_name(shost) = be64_to_cpu(nsp->fl_wwnn);
494 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
496 adapter->timer_ticks = bottom->timer_interval & ZFCP_FSF_TIMER_INT_MASK;
497 adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
498 (u16)FSF_STATUS_READS_RECOM);
500 if (fc_host_permanent_port_name(shost) == -1)
501 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
503 zfcp_scsi_set_prot(adapter);
505 /* no error return above here, otherwise must fix call chains */
506 /* do not evaluate invalid fields */
507 if (req->qtcb->header.fsf_status == FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE)
510 fc_host_port_id(shost) = ntoh24(bottom->s_id);
511 fc_host_speed(shost) =
512 zfcp_fsf_convert_portspeed(bottom->fc_link_speed);
514 adapter->hydra_version = bottom->adapter_type;
516 switch (bottom->fc_topology) {
518 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
519 adapter->peer_wwpn = be64_to_cpu(plogi->fl_wwpn);
520 adapter->peer_wwnn = be64_to_cpu(plogi->fl_wwnn);
521 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
523 case FSF_TOPO_FABRIC:
524 if (bottom->connection_features & FSF_FEATURE_NPIV_MODE)
525 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
527 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
530 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
533 dev_err(&adapter->ccw_device->dev,
534 "Unknown or unsupported arbitrated loop "
535 "fibre channel topology detected\n");
536 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1");
543 static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
545 struct zfcp_adapter *adapter = req->adapter;
546 struct fsf_qtcb *qtcb = req->qtcb;
547 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
548 struct Scsi_Host *shost = adapter->scsi_host;
550 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
553 adapter->fsf_lic_version = bottom->lic_version;
554 adapter->adapter_features = bottom->adapter_features;
555 adapter->connection_features = bottom->connection_features;
556 adapter->peer_wwpn = 0;
557 adapter->peer_wwnn = 0;
558 adapter->peer_d_id = 0;
560 switch (qtcb->header.fsf_status) {
562 if (zfcp_fsf_exchange_config_evaluate(req))
565 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
566 dev_err(&adapter->ccw_device->dev,
567 "FCP adapter maximum QTCB size (%d bytes) "
569 bottom->max_qtcb_size);
570 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1");
573 atomic_or(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
576 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
577 fc_host_node_name(shost) = 0;
578 fc_host_port_name(shost) = 0;
579 fc_host_port_id(shost) = 0;
580 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
581 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
582 adapter->hydra_version = 0;
584 /* avoids adapter shutdown to be able to recognize
585 * events such as LINK UP */
586 atomic_or(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
588 zfcp_fsf_link_down_info_eval(req,
589 &qtcb->header.fsf_status_qual.link_down_info);
590 if (zfcp_fsf_exchange_config_evaluate(req))
594 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3");
598 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
599 adapter->hardware_version = bottom->hardware_version;
600 memcpy(fc_host_serial_number(shost), bottom->serial_number,
601 min(FC_SERIAL_NUMBER_SIZE, 17));
602 EBCASC(fc_host_serial_number(shost),
603 min(FC_SERIAL_NUMBER_SIZE, 17));
606 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
607 dev_err(&adapter->ccw_device->dev,
608 "The FCP adapter only supports newer "
609 "control block versions\n");
610 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4");
613 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
614 dev_err(&adapter->ccw_device->dev,
615 "The FCP adapter only supports older "
616 "control block versions\n");
617 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5");
621 static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
623 struct zfcp_adapter *adapter = req->adapter;
624 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
625 struct Scsi_Host *shost = adapter->scsi_host;
628 memcpy(req->data, bottom, sizeof(*bottom));
630 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
631 fc_host_permanent_port_name(shost) = bottom->wwpn;
633 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
634 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
635 fc_host_supported_speeds(shost) =
636 zfcp_fsf_convert_portspeed(bottom->supported_speed);
637 memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
639 memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
643 static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
645 struct fsf_qtcb *qtcb = req->qtcb;
647 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
650 switch (qtcb->header.fsf_status) {
652 zfcp_fsf_exchange_port_evaluate(req);
654 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
655 zfcp_fsf_exchange_port_evaluate(req);
656 zfcp_fsf_link_down_info_eval(req,
657 &qtcb->header.fsf_status_qual.link_down_info);
662 static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
664 struct zfcp_fsf_req *req;
667 req = mempool_alloc(pool, GFP_ATOMIC);
669 req = kmalloc(sizeof(*req), GFP_ATOMIC);
674 memset(req, 0, sizeof(*req));
679 static struct fsf_qtcb *zfcp_fsf_qtcb_alloc(mempool_t *pool)
681 struct fsf_qtcb *qtcb;
684 qtcb = mempool_alloc(pool, GFP_ATOMIC);
686 qtcb = kmem_cache_alloc(zfcp_fsf_qtcb_cache, GFP_ATOMIC);
691 memset(qtcb, 0, sizeof(*qtcb));
695 static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
696 u32 fsf_cmd, u8 sbtype,
699 struct zfcp_adapter *adapter = qdio->adapter;
700 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
703 return ERR_PTR(-ENOMEM);
705 if (adapter->req_no == 0)
708 INIT_LIST_HEAD(&req->list);
709 timer_setup(&req->timer, NULL, 0);
710 init_completion(&req->completion);
712 req->adapter = adapter;
713 req->req_id = adapter->req_no;
715 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
717 req->qtcb = zfcp_fsf_qtcb_alloc(
718 adapter->pool.qtcb_pool);
720 req->qtcb = zfcp_fsf_qtcb_alloc(NULL);
722 if (unlikely(!req->qtcb)) {
723 zfcp_fsf_req_free(req);
724 return ERR_PTR(-ENOMEM);
727 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
728 req->qtcb->prefix.req_id = req->req_id;
729 req->qtcb->prefix.ulp_info = 26;
730 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[fsf_cmd];
731 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
732 req->qtcb->header.req_handle = req->req_id;
733 req->qtcb->header.fsf_command = fsf_cmd;
736 zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
737 req->qtcb, sizeof(struct fsf_qtcb));
742 static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
744 struct zfcp_adapter *adapter = req->adapter;
745 struct zfcp_qdio *qdio = adapter->qdio;
746 int req_id = req->req_id;
748 zfcp_reqlist_add(adapter->req_list, req);
750 req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free);
751 req->issued = get_tod_clock();
752 if (zfcp_qdio_send(qdio, &req->qdio_req)) {
753 del_timer(&req->timer);
754 /* lookup request again, list might have changed */
755 zfcp_reqlist_find_rm(adapter->req_list, req_id);
756 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1");
760 /* Don't increase for unsolicited status */
761 if (!zfcp_fsf_req_is_status_read_buffer(req))
762 adapter->fsf_req_seq_no++;
769 * zfcp_fsf_status_read - send status read request
770 * @qdio: pointer to struct zfcp_qdio
771 * Returns: 0 on success, ERROR otherwise
773 int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
775 struct zfcp_adapter *adapter = qdio->adapter;
776 struct zfcp_fsf_req *req;
777 struct fsf_status_read_buffer *sr_buf;
781 spin_lock_irq(&qdio->req_q_lock);
782 if (zfcp_qdio_sbal_get(qdio))
785 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS,
786 SBAL_SFLAGS0_TYPE_STATUS,
787 adapter->pool.status_read_req);
789 retval = PTR_ERR(req);
793 page = mempool_alloc(adapter->pool.sr_data, GFP_ATOMIC);
798 sr_buf = page_address(page);
799 memset(sr_buf, 0, sizeof(*sr_buf));
802 zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
803 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
805 retval = zfcp_fsf_req_send(req);
807 goto failed_req_send;
813 mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
815 zfcp_dbf_hba_fsf_uss("fssr__1", req);
816 zfcp_fsf_req_free(req);
818 spin_unlock_irq(&qdio->req_q_lock);
822 static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
824 struct scsi_device *sdev = req->data;
825 struct zfcp_scsi_dev *zfcp_sdev;
826 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
828 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
831 zfcp_sdev = sdev_to_zfcp(sdev);
833 switch (req->qtcb->header.fsf_status) {
834 case FSF_PORT_HANDLE_NOT_VALID:
835 if (fsq->word[0] == fsq->word[1]) {
836 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0,
838 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
841 case FSF_LUN_HANDLE_NOT_VALID:
842 if (fsq->word[0] == fsq->word[1]) {
843 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fsafch2");
844 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
847 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
848 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
851 zfcp_erp_set_port_status(zfcp_sdev->port,
852 ZFCP_STATUS_COMMON_ACCESS_BOXED);
853 zfcp_erp_port_reopen(zfcp_sdev->port,
854 ZFCP_STATUS_COMMON_ERP_FAILED, "fsafch3");
855 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
858 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
859 zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
861 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
863 case FSF_ADAPTER_STATUS_AVAILABLE:
864 switch (fsq->word[0]) {
865 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
866 zfcp_fc_test_link(zfcp_sdev->port);
868 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
869 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
874 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
880 * zfcp_fsf_abort_fcp_cmnd - abort running SCSI command
881 * @scmnd: The SCSI command to abort
882 * Returns: pointer to struct zfcp_fsf_req
885 struct zfcp_fsf_req *zfcp_fsf_abort_fcp_cmnd(struct scsi_cmnd *scmnd)
887 struct zfcp_fsf_req *req = NULL;
888 struct scsi_device *sdev = scmnd->device;
889 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
890 struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
891 unsigned long old_req_id = (unsigned long) scmnd->host_scribble;
893 spin_lock_irq(&qdio->req_q_lock);
894 if (zfcp_qdio_sbal_get(qdio))
896 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
897 SBAL_SFLAGS0_TYPE_READ,
898 qdio->adapter->pool.scsi_abort);
904 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
905 ZFCP_STATUS_COMMON_UNBLOCKED)))
908 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
911 req->handler = zfcp_fsf_abort_fcp_command_handler;
912 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
913 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
914 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
916 zfcp_fsf_start_timer(req, ZFCP_FSF_SCSI_ER_TIMEOUT);
917 if (!zfcp_fsf_req_send(req))
921 zfcp_fsf_req_free(req);
924 spin_unlock_irq(&qdio->req_q_lock);
928 static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
930 struct zfcp_adapter *adapter = req->adapter;
931 struct zfcp_fsf_ct_els *ct = req->data;
932 struct fsf_qtcb_header *header = &req->qtcb->header;
934 ct->status = -EINVAL;
936 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
939 switch (header->fsf_status) {
942 zfcp_dbf_san_res("fsscth2", req);
944 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
945 zfcp_fsf_class_not_supp(req);
947 case FSF_ADAPTER_STATUS_AVAILABLE:
948 switch (header->fsf_status_qual.word[0]){
949 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
950 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
951 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
956 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
958 case FSF_PORT_HANDLE_NOT_VALID:
959 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1");
961 case FSF_GENERIC_COMMAND_REJECTED:
962 case FSF_PAYLOAD_SIZE_MISMATCH:
963 case FSF_REQUEST_SIZE_TOO_LARGE:
964 case FSF_RESPONSE_SIZE_TOO_LARGE:
965 case FSF_SBAL_MISMATCH:
966 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
972 ct->handler(ct->handler_data);
975 static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
976 struct zfcp_qdio_req *q_req,
977 struct scatterlist *sg_req,
978 struct scatterlist *sg_resp)
980 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
981 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
982 zfcp_qdio_set_sbale_last(qdio, q_req);
985 static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
986 struct scatterlist *sg_req,
987 struct scatterlist *sg_resp)
989 struct zfcp_adapter *adapter = req->adapter;
990 struct zfcp_qdio *qdio = adapter->qdio;
991 struct fsf_qtcb *qtcb = req->qtcb;
992 u32 feat = adapter->adapter_features;
994 if (zfcp_adapter_multi_buffer_active(adapter)) {
995 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
997 qtcb->bottom.support.req_buf_length =
998 zfcp_qdio_real_bytes(sg_req);
999 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
1001 qtcb->bottom.support.resp_buf_length =
1002 zfcp_qdio_real_bytes(sg_resp);
1004 zfcp_qdio_set_data_div(qdio, &req->qdio_req, sg_nents(sg_req));
1005 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1006 zfcp_qdio_set_scount(qdio, &req->qdio_req);
1010 /* use single, unchained SBAL if it can hold the request */
1011 if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
1012 zfcp_fsf_setup_ct_els_unchained(qdio, &req->qdio_req,
1017 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS))
1020 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
1023 qtcb->bottom.support.req_buf_length = zfcp_qdio_real_bytes(sg_req);
1025 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1026 zfcp_qdio_skip_to_last_sbale(qdio, &req->qdio_req);
1028 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
1031 qtcb->bottom.support.resp_buf_length = zfcp_qdio_real_bytes(sg_resp);
1033 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1038 static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1039 struct scatterlist *sg_req,
1040 struct scatterlist *sg_resp,
1041 unsigned int timeout)
1045 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
1049 /* common settings for ct/gs and els requests */
1051 timeout = 255; /* max value accepted by hardware */
1052 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
1053 req->qtcb->bottom.support.timeout = timeout;
1054 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
1060 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1061 * @wka_port: pointer to zfcp WKA port to send CT/GS to
1062 * @ct: pointer to struct zfcp_send_ct with data for request
1063 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1064 * @timeout: timeout that hardware should use, and a later software timeout
1066 int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
1067 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1068 unsigned int timeout)
1070 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1071 struct zfcp_fsf_req *req;
1074 spin_lock_irq(&qdio->req_q_lock);
1075 if (zfcp_qdio_sbal_get(qdio))
1078 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
1079 SBAL_SFLAGS0_TYPE_WRITE_READ, pool);
1086 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1087 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
1091 req->handler = zfcp_fsf_send_ct_handler;
1092 req->qtcb->header.port_handle = wka_port->handle;
1093 ct->d_id = wka_port->d_id;
1096 zfcp_dbf_san_req("fssct_1", req, wka_port->d_id);
1098 ret = zfcp_fsf_req_send(req);
1105 zfcp_fsf_req_free(req);
1107 spin_unlock_irq(&qdio->req_q_lock);
1111 static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1113 struct zfcp_fsf_ct_els *send_els = req->data;
1114 struct fsf_qtcb_header *header = &req->qtcb->header;
1116 send_els->status = -EINVAL;
1118 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1119 goto skip_fsfstatus;
1121 switch (header->fsf_status) {
1123 send_els->status = 0;
1124 zfcp_dbf_san_res("fsselh1", req);
1126 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1127 zfcp_fsf_class_not_supp(req);
1129 case FSF_ADAPTER_STATUS_AVAILABLE:
1130 switch (header->fsf_status_qual.word[0]){
1131 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1132 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1133 case FSF_SQ_RETRY_IF_POSSIBLE:
1134 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1138 case FSF_ELS_COMMAND_REJECTED:
1139 case FSF_PAYLOAD_SIZE_MISMATCH:
1140 case FSF_REQUEST_SIZE_TOO_LARGE:
1141 case FSF_RESPONSE_SIZE_TOO_LARGE:
1143 case FSF_SBAL_MISMATCH:
1144 /* should never occur, avoided in zfcp_fsf_send_els */
1147 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1151 if (send_els->handler)
1152 send_els->handler(send_els->handler_data);
1156 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1157 * @adapter: pointer to zfcp adapter
1158 * @d_id: N_Port_ID to send ELS to
1159 * @els: pointer to struct zfcp_send_els with data for the command
1160 * @timeout: timeout that hardware should use, and a later software timeout
1162 int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
1163 struct zfcp_fsf_ct_els *els, unsigned int timeout)
1165 struct zfcp_fsf_req *req;
1166 struct zfcp_qdio *qdio = adapter->qdio;
1169 spin_lock_irq(&qdio->req_q_lock);
1170 if (zfcp_qdio_sbal_get(qdio))
1173 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
1174 SBAL_SFLAGS0_TYPE_WRITE_READ, NULL);
1181 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1183 if (!zfcp_adapter_multi_buffer_active(adapter))
1184 zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
1186 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
1191 hton24(req->qtcb->bottom.support.d_id, d_id);
1192 req->handler = zfcp_fsf_send_els_handler;
1196 zfcp_dbf_san_req("fssels1", req, d_id);
1198 ret = zfcp_fsf_req_send(req);
1205 zfcp_fsf_req_free(req);
1207 spin_unlock_irq(&qdio->req_q_lock);
1211 int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1213 struct zfcp_fsf_req *req;
1214 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1217 spin_lock_irq(&qdio->req_q_lock);
1218 if (zfcp_qdio_sbal_get(qdio))
1221 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1222 SBAL_SFLAGS0_TYPE_READ,
1223 qdio->adapter->pool.erp_req);
1226 retval = PTR_ERR(req);
1230 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1231 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1233 req->qtcb->bottom.config.feature_selection =
1234 FSF_FEATURE_NOTIFICATION_LOST |
1235 FSF_FEATURE_UPDATE_ALERT;
1236 req->erp_action = erp_action;
1237 req->handler = zfcp_fsf_exchange_config_data_handler;
1238 erp_action->fsf_req_id = req->req_id;
1240 zfcp_fsf_start_erp_timer(req);
1241 retval = zfcp_fsf_req_send(req);
1243 zfcp_fsf_req_free(req);
1244 erp_action->fsf_req_id = 0;
1247 spin_unlock_irq(&qdio->req_q_lock);
1251 int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
1252 struct fsf_qtcb_bottom_config *data)
1254 struct zfcp_fsf_req *req = NULL;
1257 spin_lock_irq(&qdio->req_q_lock);
1258 if (zfcp_qdio_sbal_get(qdio))
1261 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1262 SBAL_SFLAGS0_TYPE_READ, NULL);
1265 retval = PTR_ERR(req);
1269 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1270 req->handler = zfcp_fsf_exchange_config_data_handler;
1272 req->qtcb->bottom.config.feature_selection =
1273 FSF_FEATURE_NOTIFICATION_LOST |
1274 FSF_FEATURE_UPDATE_ALERT;
1279 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1280 retval = zfcp_fsf_req_send(req);
1281 spin_unlock_irq(&qdio->req_q_lock);
1283 wait_for_completion(&req->completion);
1285 zfcp_fsf_req_free(req);
1289 spin_unlock_irq(&qdio->req_q_lock);
1294 * zfcp_fsf_exchange_port_data - request information about local port
1295 * @erp_action: ERP action for the adapter for which port data is requested
1296 * Returns: 0 on success, error otherwise
1298 int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1300 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1301 struct zfcp_fsf_req *req;
1304 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1307 spin_lock_irq(&qdio->req_q_lock);
1308 if (zfcp_qdio_sbal_get(qdio))
1311 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1312 SBAL_SFLAGS0_TYPE_READ,
1313 qdio->adapter->pool.erp_req);
1316 retval = PTR_ERR(req);
1320 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1321 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1323 req->handler = zfcp_fsf_exchange_port_data_handler;
1324 req->erp_action = erp_action;
1325 erp_action->fsf_req_id = req->req_id;
1327 zfcp_fsf_start_erp_timer(req);
1328 retval = zfcp_fsf_req_send(req);
1330 zfcp_fsf_req_free(req);
1331 erp_action->fsf_req_id = 0;
1334 spin_unlock_irq(&qdio->req_q_lock);
1339 * zfcp_fsf_exchange_port_data_sync - request information about local port
1340 * @qdio: pointer to struct zfcp_qdio
1341 * @data: pointer to struct fsf_qtcb_bottom_port
1342 * Returns: 0 on success, error otherwise
1344 int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
1345 struct fsf_qtcb_bottom_port *data)
1347 struct zfcp_fsf_req *req = NULL;
1350 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1353 spin_lock_irq(&qdio->req_q_lock);
1354 if (zfcp_qdio_sbal_get(qdio))
1357 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1358 SBAL_SFLAGS0_TYPE_READ, NULL);
1361 retval = PTR_ERR(req);
1368 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1370 req->handler = zfcp_fsf_exchange_port_data_handler;
1371 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1372 retval = zfcp_fsf_req_send(req);
1373 spin_unlock_irq(&qdio->req_q_lock);
1376 wait_for_completion(&req->completion);
1378 zfcp_fsf_req_free(req);
1383 spin_unlock_irq(&qdio->req_q_lock);
1387 static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1389 struct zfcp_port *port = req->data;
1390 struct fsf_qtcb_header *header = &req->qtcb->header;
1391 struct fc_els_flogi *plogi;
1393 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1396 switch (header->fsf_status) {
1397 case FSF_PORT_ALREADY_OPEN:
1399 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1400 dev_warn(&req->adapter->ccw_device->dev,
1401 "Not enough FCP adapter resources to open "
1402 "remote port 0x%016Lx\n",
1403 (unsigned long long)port->wwpn);
1404 zfcp_erp_set_port_status(port,
1405 ZFCP_STATUS_COMMON_ERP_FAILED);
1406 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1408 case FSF_ADAPTER_STATUS_AVAILABLE:
1409 switch (header->fsf_status_qual.word[0]) {
1410 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1411 /* no zfcp_fc_test_link() with failed open port */
1413 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1414 case FSF_SQ_NO_RETRY_POSSIBLE:
1415 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1420 port->handle = header->port_handle;
1421 atomic_or(ZFCP_STATUS_COMMON_OPEN |
1422 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1423 atomic_andnot(ZFCP_STATUS_COMMON_ACCESS_BOXED,
1425 /* check whether D_ID has changed during open */
1427 * FIXME: This check is not airtight, as the FCP channel does
1428 * not monitor closures of target port connections caused on
1429 * the remote side. Thus, they might miss out on invalidating
1430 * locally cached WWPNs (and other N_Port parameters) of gone
1431 * target ports. So, our heroic attempt to make things safe
1432 * could be undermined by 'open port' response data tagged with
1433 * obsolete WWPNs. Another reason to monitor potential
1434 * connection closures ourself at least (by interpreting
1435 * incoming ELS' and unsolicited status). It just crosses my
1436 * mind that one should be able to cross-check by means of
1437 * another GID_PN straight after a port has been opened.
1438 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1440 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
1441 if (req->qtcb->bottom.support.els1_length >=
1443 zfcp_fc_plogi_evaluate(port, plogi);
1445 case FSF_UNKNOWN_OP_SUBTYPE:
1446 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1451 put_device(&port->dev);
1455 * zfcp_fsf_open_port - create and send open port request
1456 * @erp_action: pointer to struct zfcp_erp_action
1457 * Returns: 0 on success, error otherwise
1459 int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
1461 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1462 struct zfcp_port *port = erp_action->port;
1463 struct zfcp_fsf_req *req;
1466 spin_lock_irq(&qdio->req_q_lock);
1467 if (zfcp_qdio_sbal_get(qdio))
1470 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1471 SBAL_SFLAGS0_TYPE_READ,
1472 qdio->adapter->pool.erp_req);
1475 retval = PTR_ERR(req);
1479 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1480 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1482 req->handler = zfcp_fsf_open_port_handler;
1483 hton24(req->qtcb->bottom.support.d_id, port->d_id);
1485 req->erp_action = erp_action;
1486 erp_action->fsf_req_id = req->req_id;
1487 get_device(&port->dev);
1489 zfcp_fsf_start_erp_timer(req);
1490 retval = zfcp_fsf_req_send(req);
1492 zfcp_fsf_req_free(req);
1493 erp_action->fsf_req_id = 0;
1494 put_device(&port->dev);
1497 spin_unlock_irq(&qdio->req_q_lock);
1501 static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
1503 struct zfcp_port *port = req->data;
1505 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1508 switch (req->qtcb->header.fsf_status) {
1509 case FSF_PORT_HANDLE_NOT_VALID:
1510 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1");
1511 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1513 case FSF_ADAPTER_STATUS_AVAILABLE:
1516 zfcp_erp_clear_port_status(port, ZFCP_STATUS_COMMON_OPEN);
1522 * zfcp_fsf_close_port - create and send close port request
1523 * @erp_action: pointer to struct zfcp_erp_action
1524 * Returns: 0 on success, error otherwise
1526 int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
1528 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1529 struct zfcp_fsf_req *req;
1532 spin_lock_irq(&qdio->req_q_lock);
1533 if (zfcp_qdio_sbal_get(qdio))
1536 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1537 SBAL_SFLAGS0_TYPE_READ,
1538 qdio->adapter->pool.erp_req);
1541 retval = PTR_ERR(req);
1545 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1546 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1548 req->handler = zfcp_fsf_close_port_handler;
1549 req->data = erp_action->port;
1550 req->erp_action = erp_action;
1551 req->qtcb->header.port_handle = erp_action->port->handle;
1552 erp_action->fsf_req_id = req->req_id;
1554 zfcp_fsf_start_erp_timer(req);
1555 retval = zfcp_fsf_req_send(req);
1557 zfcp_fsf_req_free(req);
1558 erp_action->fsf_req_id = 0;
1561 spin_unlock_irq(&qdio->req_q_lock);
1565 static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1567 struct zfcp_fc_wka_port *wka_port = req->data;
1568 struct fsf_qtcb_header *header = &req->qtcb->header;
1570 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1571 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1575 switch (header->fsf_status) {
1576 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1577 dev_warn(&req->adapter->ccw_device->dev,
1578 "Opening WKA port 0x%x failed\n", wka_port->d_id);
1580 case FSF_ADAPTER_STATUS_AVAILABLE:
1581 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1582 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1585 wka_port->handle = header->port_handle;
1587 case FSF_PORT_ALREADY_OPEN:
1588 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
1591 wake_up(&wka_port->completion_wq);
1595 * zfcp_fsf_open_wka_port - create and send open wka-port request
1596 * @wka_port: pointer to struct zfcp_fc_wka_port
1597 * Returns: 0 on success, error otherwise
1599 int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
1601 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1602 struct zfcp_fsf_req *req;
1605 spin_lock_irq(&qdio->req_q_lock);
1606 if (zfcp_qdio_sbal_get(qdio))
1609 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1610 SBAL_SFLAGS0_TYPE_READ,
1611 qdio->adapter->pool.erp_req);
1614 retval = PTR_ERR(req);
1618 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1619 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1621 req->handler = zfcp_fsf_open_wka_port_handler;
1622 hton24(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_irq(&qdio->req_q_lock);
1632 zfcp_dbf_rec_run_wka("fsowp_1", wka_port, req->req_id);
1636 static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1638 struct zfcp_fc_wka_port *wka_port = req->data;
1640 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1641 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1642 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1");
1645 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1646 wake_up(&wka_port->completion_wq);
1650 * zfcp_fsf_close_wka_port - create and send close wka port request
1651 * @wka_port: WKA port to open
1652 * Returns: 0 on success, error otherwise
1654 int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
1656 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1657 struct zfcp_fsf_req *req;
1660 spin_lock_irq(&qdio->req_q_lock);
1661 if (zfcp_qdio_sbal_get(qdio))
1664 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1665 SBAL_SFLAGS0_TYPE_READ,
1666 qdio->adapter->pool.erp_req);
1669 retval = PTR_ERR(req);
1673 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1674 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1676 req->handler = zfcp_fsf_close_wka_port_handler;
1677 req->data = wka_port;
1678 req->qtcb->header.port_handle = wka_port->handle;
1680 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1681 retval = zfcp_fsf_req_send(req);
1683 zfcp_fsf_req_free(req);
1685 spin_unlock_irq(&qdio->req_q_lock);
1687 zfcp_dbf_rec_run_wka("fscwp_1", wka_port, req->req_id);
1691 static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
1693 struct zfcp_port *port = req->data;
1694 struct fsf_qtcb_header *header = &req->qtcb->header;
1695 struct scsi_device *sdev;
1697 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1700 switch (header->fsf_status) {
1701 case FSF_PORT_HANDLE_NOT_VALID:
1702 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1");
1703 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1705 case FSF_PORT_BOXED:
1706 /* can't use generic zfcp_erp_modify_port_status because
1707 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1708 atomic_andnot(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1709 shost_for_each_device(sdev, port->adapter->scsi_host)
1710 if (sdev_to_zfcp(sdev)->port == port)
1711 atomic_andnot(ZFCP_STATUS_COMMON_OPEN,
1712 &sdev_to_zfcp(sdev)->status);
1713 zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_ACCESS_BOXED);
1714 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED,
1716 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1718 case FSF_ADAPTER_STATUS_AVAILABLE:
1719 switch (header->fsf_status_qual.word[0]) {
1720 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1722 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1723 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1728 /* can't use generic zfcp_erp_modify_port_status because
1729 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1731 atomic_andnot(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1732 shost_for_each_device(sdev, port->adapter->scsi_host)
1733 if (sdev_to_zfcp(sdev)->port == port)
1734 atomic_andnot(ZFCP_STATUS_COMMON_OPEN,
1735 &sdev_to_zfcp(sdev)->status);
1741 * zfcp_fsf_close_physical_port - close physical port
1742 * @erp_action: pointer to struct zfcp_erp_action
1743 * Returns: 0 on success
1745 int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
1747 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1748 struct zfcp_fsf_req *req;
1751 spin_lock_irq(&qdio->req_q_lock);
1752 if (zfcp_qdio_sbal_get(qdio))
1755 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
1756 SBAL_SFLAGS0_TYPE_READ,
1757 qdio->adapter->pool.erp_req);
1760 retval = PTR_ERR(req);
1764 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1765 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
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_id = req->req_id;
1773 zfcp_fsf_start_erp_timer(req);
1774 retval = zfcp_fsf_req_send(req);
1776 zfcp_fsf_req_free(req);
1777 erp_action->fsf_req_id = 0;
1780 spin_unlock_irq(&qdio->req_q_lock);
1784 static void zfcp_fsf_open_lun_handler(struct zfcp_fsf_req *req)
1786 struct zfcp_adapter *adapter = req->adapter;
1787 struct scsi_device *sdev = req->data;
1788 struct zfcp_scsi_dev *zfcp_sdev;
1789 struct fsf_qtcb_header *header = &req->qtcb->header;
1790 union fsf_status_qual *qual = &header->fsf_status_qual;
1792 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1795 zfcp_sdev = sdev_to_zfcp(sdev);
1797 atomic_andnot(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1798 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1799 &zfcp_sdev->status);
1801 switch (header->fsf_status) {
1803 case FSF_PORT_HANDLE_NOT_VALID:
1804 zfcp_erp_adapter_reopen(adapter, 0, "fsouh_1");
1806 case FSF_LUN_ALREADY_OPEN:
1808 case FSF_PORT_BOXED:
1809 zfcp_erp_set_port_status(zfcp_sdev->port,
1810 ZFCP_STATUS_COMMON_ACCESS_BOXED);
1811 zfcp_erp_port_reopen(zfcp_sdev->port,
1812 ZFCP_STATUS_COMMON_ERP_FAILED, "fsouh_2");
1813 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1815 case FSF_LUN_SHARING_VIOLATION:
1817 dev_warn(&zfcp_sdev->port->adapter->ccw_device->dev,
1818 "LUN 0x%016Lx on port 0x%016Lx is already in "
1819 "use by CSS%d, MIF Image ID %x\n",
1820 zfcp_scsi_dev_lun(sdev),
1821 (unsigned long long)zfcp_sdev->port->wwpn,
1822 qual->fsf_queue_designator.cssid,
1823 qual->fsf_queue_designator.hla);
1824 zfcp_erp_set_lun_status(sdev,
1825 ZFCP_STATUS_COMMON_ERP_FAILED |
1826 ZFCP_STATUS_COMMON_ACCESS_DENIED);
1827 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1829 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
1830 dev_warn(&adapter->ccw_device->dev,
1831 "No handle is available for LUN "
1832 "0x%016Lx on port 0x%016Lx\n",
1833 (unsigned long long)zfcp_scsi_dev_lun(sdev),
1834 (unsigned long long)zfcp_sdev->port->wwpn);
1835 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ERP_FAILED);
1837 case FSF_INVALID_COMMAND_OPTION:
1838 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1840 case FSF_ADAPTER_STATUS_AVAILABLE:
1841 switch (header->fsf_status_qual.word[0]) {
1842 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1843 zfcp_fc_test_link(zfcp_sdev->port);
1845 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1846 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1852 zfcp_sdev->lun_handle = header->lun_handle;
1853 atomic_or(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
1859 * zfcp_fsf_open_lun - open LUN
1860 * @erp_action: pointer to struct zfcp_erp_action
1861 * Returns: 0 on success, error otherwise
1863 int zfcp_fsf_open_lun(struct zfcp_erp_action *erp_action)
1865 struct zfcp_adapter *adapter = erp_action->adapter;
1866 struct zfcp_qdio *qdio = adapter->qdio;
1867 struct zfcp_fsf_req *req;
1870 spin_lock_irq(&qdio->req_q_lock);
1871 if (zfcp_qdio_sbal_get(qdio))
1874 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
1875 SBAL_SFLAGS0_TYPE_READ,
1876 adapter->pool.erp_req);
1879 retval = PTR_ERR(req);
1883 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1884 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1886 req->qtcb->header.port_handle = erp_action->port->handle;
1887 req->qtcb->bottom.support.fcp_lun = zfcp_scsi_dev_lun(erp_action->sdev);
1888 req->handler = zfcp_fsf_open_lun_handler;
1889 req->data = erp_action->sdev;
1890 req->erp_action = erp_action;
1891 erp_action->fsf_req_id = req->req_id;
1893 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1894 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
1896 zfcp_fsf_start_erp_timer(req);
1897 retval = zfcp_fsf_req_send(req);
1899 zfcp_fsf_req_free(req);
1900 erp_action->fsf_req_id = 0;
1903 spin_unlock_irq(&qdio->req_q_lock);
1907 static void zfcp_fsf_close_lun_handler(struct zfcp_fsf_req *req)
1909 struct scsi_device *sdev = req->data;
1910 struct zfcp_scsi_dev *zfcp_sdev;
1912 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1915 zfcp_sdev = sdev_to_zfcp(sdev);
1917 switch (req->qtcb->header.fsf_status) {
1918 case FSF_PORT_HANDLE_NOT_VALID:
1919 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fscuh_1");
1920 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1922 case FSF_LUN_HANDLE_NOT_VALID:
1923 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fscuh_2");
1924 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1926 case FSF_PORT_BOXED:
1927 zfcp_erp_set_port_status(zfcp_sdev->port,
1928 ZFCP_STATUS_COMMON_ACCESS_BOXED);
1929 zfcp_erp_port_reopen(zfcp_sdev->port,
1930 ZFCP_STATUS_COMMON_ERP_FAILED, "fscuh_3");
1931 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1933 case FSF_ADAPTER_STATUS_AVAILABLE:
1934 switch (req->qtcb->header.fsf_status_qual.word[0]) {
1935 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1936 zfcp_fc_test_link(zfcp_sdev->port);
1938 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1939 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1944 atomic_andnot(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
1950 * zfcp_fsf_close_LUN - close LUN
1951 * @erp_action: pointer to erp_action triggering the "close LUN"
1952 * Returns: 0 on success, error otherwise
1954 int zfcp_fsf_close_lun(struct zfcp_erp_action *erp_action)
1956 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1957 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(erp_action->sdev);
1958 struct zfcp_fsf_req *req;
1961 spin_lock_irq(&qdio->req_q_lock);
1962 if (zfcp_qdio_sbal_get(qdio))
1965 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
1966 SBAL_SFLAGS0_TYPE_READ,
1967 qdio->adapter->pool.erp_req);
1970 retval = PTR_ERR(req);
1974 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1975 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1977 req->qtcb->header.port_handle = erp_action->port->handle;
1978 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
1979 req->handler = zfcp_fsf_close_lun_handler;
1980 req->data = erp_action->sdev;
1981 req->erp_action = erp_action;
1982 erp_action->fsf_req_id = req->req_id;
1984 zfcp_fsf_start_erp_timer(req);
1985 retval = zfcp_fsf_req_send(req);
1987 zfcp_fsf_req_free(req);
1988 erp_action->fsf_req_id = 0;
1991 spin_unlock_irq(&qdio->req_q_lock);
1995 static void zfcp_fsf_update_lat(struct zfcp_latency_record *lat_rec, u32 lat)
1997 lat_rec->sum += lat;
1998 lat_rec->min = min(lat_rec->min, lat);
1999 lat_rec->max = max(lat_rec->max, lat);
2002 static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
2004 struct fsf_qual_latency_info *lat_in;
2005 struct zfcp_latency_cont *lat = NULL;
2006 struct zfcp_scsi_dev *zfcp_sdev;
2007 struct zfcp_blk_drv_data blktrc;
2008 int ticks = req->adapter->timer_ticks;
2010 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
2013 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2014 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2015 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
2016 blktrc.inb_usage = 0;
2017 blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
2019 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
2020 !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2021 zfcp_sdev = sdev_to_zfcp(scsi->device);
2022 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2023 blktrc.channel_lat = lat_in->channel_lat * ticks;
2024 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2026 switch (req->qtcb->bottom.io.data_direction) {
2027 case FSF_DATADIR_DIF_READ_STRIP:
2028 case FSF_DATADIR_DIF_READ_CONVERT:
2029 case FSF_DATADIR_READ:
2030 lat = &zfcp_sdev->latencies.read;
2032 case FSF_DATADIR_DIF_WRITE_INSERT:
2033 case FSF_DATADIR_DIF_WRITE_CONVERT:
2034 case FSF_DATADIR_WRITE:
2035 lat = &zfcp_sdev->latencies.write;
2037 case FSF_DATADIR_CMND:
2038 lat = &zfcp_sdev->latencies.cmd;
2043 spin_lock(&zfcp_sdev->latencies.lock);
2044 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2045 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2047 spin_unlock(&zfcp_sdev->latencies.lock);
2051 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2056 * zfcp_fsf_fcp_handler_common() - FCP response handler common to I/O and TMF.
2057 * @req: Pointer to FSF request.
2058 * @sdev: Pointer to SCSI device as request context.
2060 static void zfcp_fsf_fcp_handler_common(struct zfcp_fsf_req *req,
2061 struct scsi_device *sdev)
2063 struct zfcp_scsi_dev *zfcp_sdev;
2064 struct fsf_qtcb_header *header = &req->qtcb->header;
2066 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2069 zfcp_sdev = sdev_to_zfcp(sdev);
2071 switch (header->fsf_status) {
2072 case FSF_HANDLE_MISMATCH:
2073 case FSF_PORT_HANDLE_NOT_VALID:
2074 zfcp_erp_adapter_reopen(req->adapter, 0, "fssfch1");
2075 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2077 case FSF_FCPLUN_NOT_VALID:
2078 case FSF_LUN_HANDLE_NOT_VALID:
2079 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fssfch2");
2080 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2082 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2083 zfcp_fsf_class_not_supp(req);
2085 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2086 dev_err(&req->adapter->ccw_device->dev,
2087 "Incorrect direction %d, LUN 0x%016Lx on port "
2088 "0x%016Lx closed\n",
2089 req->qtcb->bottom.io.data_direction,
2090 (unsigned long long)zfcp_scsi_dev_lun(sdev),
2091 (unsigned long long)zfcp_sdev->port->wwpn);
2092 zfcp_erp_adapter_shutdown(req->adapter, 0, "fssfch3");
2093 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2095 case FSF_CMND_LENGTH_NOT_VALID:
2096 dev_err(&req->adapter->ccw_device->dev,
2097 "Incorrect FCP_CMND length %d, FCP device closed\n",
2098 req->qtcb->bottom.io.fcp_cmnd_length);
2099 zfcp_erp_adapter_shutdown(req->adapter, 0, "fssfch4");
2100 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2102 case FSF_PORT_BOXED:
2103 zfcp_erp_set_port_status(zfcp_sdev->port,
2104 ZFCP_STATUS_COMMON_ACCESS_BOXED);
2105 zfcp_erp_port_reopen(zfcp_sdev->port,
2106 ZFCP_STATUS_COMMON_ERP_FAILED, "fssfch5");
2107 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2110 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
2111 zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
2113 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2115 case FSF_ADAPTER_STATUS_AVAILABLE:
2116 if (header->fsf_status_qual.word[0] ==
2117 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
2118 zfcp_fc_test_link(zfcp_sdev->port);
2119 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2124 static void zfcp_fsf_fcp_cmnd_handler(struct zfcp_fsf_req *req)
2126 struct scsi_cmnd *scpnt;
2127 struct fcp_resp_with_ext *fcp_rsp;
2128 unsigned long flags;
2130 read_lock_irqsave(&req->adapter->abort_lock, flags);
2133 if (unlikely(!scpnt)) {
2134 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2138 zfcp_fsf_fcp_handler_common(req, scpnt->device);
2140 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2141 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
2142 goto skip_fsfstatus;
2145 switch (req->qtcb->header.fsf_status) {
2146 case FSF_INCONSISTENT_PROT_DATA:
2147 case FSF_INVALID_PROT_PARM:
2148 set_host_byte(scpnt, DID_ERROR);
2149 goto skip_fsfstatus;
2150 case FSF_BLOCK_GUARD_CHECK_FAILURE:
2151 zfcp_scsi_dif_sense_error(scpnt, 0x1);
2152 goto skip_fsfstatus;
2153 case FSF_APP_TAG_CHECK_FAILURE:
2154 zfcp_scsi_dif_sense_error(scpnt, 0x2);
2155 goto skip_fsfstatus;
2156 case FSF_REF_TAG_CHECK_FAILURE:
2157 zfcp_scsi_dif_sense_error(scpnt, 0x3);
2158 goto skip_fsfstatus;
2160 BUILD_BUG_ON(sizeof(struct fcp_resp_with_ext) > FSF_FCP_RSP_SIZE);
2161 fcp_rsp = &req->qtcb->bottom.io.fcp_rsp.iu;
2162 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
2165 zfcp_fsf_req_trace(req, scpnt);
2166 zfcp_dbf_scsi_result(scpnt, req);
2168 scpnt->host_scribble = NULL;
2169 (scpnt->scsi_done) (scpnt);
2171 * We must hold this lock until scsi_done has been called.
2172 * Otherwise we may call scsi_done after abort regarding this
2173 * command has completed.
2174 * Note: scsi_done must not block!
2176 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2179 static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir)
2181 switch (scsi_get_prot_op(scsi_cmnd)) {
2182 case SCSI_PROT_NORMAL:
2183 switch (scsi_cmnd->sc_data_direction) {
2185 *data_dir = FSF_DATADIR_CMND;
2187 case DMA_FROM_DEVICE:
2188 *data_dir = FSF_DATADIR_READ;
2191 *data_dir = FSF_DATADIR_WRITE;
2193 case DMA_BIDIRECTIONAL:
2198 case SCSI_PROT_READ_STRIP:
2199 *data_dir = FSF_DATADIR_DIF_READ_STRIP;
2201 case SCSI_PROT_WRITE_INSERT:
2202 *data_dir = FSF_DATADIR_DIF_WRITE_INSERT;
2204 case SCSI_PROT_READ_PASS:
2205 *data_dir = FSF_DATADIR_DIF_READ_CONVERT;
2207 case SCSI_PROT_WRITE_PASS:
2208 *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT;
2218 * zfcp_fsf_fcp_cmnd - initiate an FCP command (for a SCSI command)
2219 * @scsi_cmnd: scsi command to be sent
2221 int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
2223 struct zfcp_fsf_req *req;
2224 struct fcp_cmnd *fcp_cmnd;
2225 u8 sbtype = SBAL_SFLAGS0_TYPE_READ;
2227 struct scsi_device *sdev = scsi_cmnd->device;
2228 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
2229 struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
2230 struct zfcp_qdio *qdio = adapter->qdio;
2231 struct fsf_qtcb_bottom_io *io;
2232 unsigned long flags;
2234 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
2235 ZFCP_STATUS_COMMON_UNBLOCKED)))
2238 spin_lock_irqsave(&qdio->req_q_lock, flags);
2239 if (atomic_read(&qdio->req_q_free) <= 0) {
2240 atomic_inc(&qdio->req_q_full);
2244 if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
2245 sbtype = SBAL_SFLAGS0_TYPE_WRITE;
2247 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2248 sbtype, adapter->pool.scsi_req);
2251 retval = PTR_ERR(req);
2255 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2257 io = &req->qtcb->bottom.io;
2258 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2259 req->data = scsi_cmnd;
2260 req->handler = zfcp_fsf_fcp_cmnd_handler;
2261 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2262 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
2263 io->service_class = FSF_CLASS_3;
2264 io->fcp_cmnd_length = FCP_CMND_LEN;
2266 if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
2267 io->data_block_length = scsi_cmnd->device->sector_size;
2268 io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
2271 if (zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction))
2272 goto failed_scsi_cmnd;
2274 BUILD_BUG_ON(sizeof(struct fcp_cmnd) > FSF_FCP_CMND_SIZE);
2275 fcp_cmnd = &req->qtcb->bottom.io.fcp_cmnd.iu;
2276 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
2278 if ((scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) &&
2279 scsi_prot_sg_count(scsi_cmnd)) {
2280 zfcp_qdio_set_data_div(qdio, &req->qdio_req,
2281 scsi_prot_sg_count(scsi_cmnd));
2282 retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2283 scsi_prot_sglist(scsi_cmnd));
2285 goto failed_scsi_cmnd;
2286 io->prot_data_length = zfcp_qdio_real_bytes(
2287 scsi_prot_sglist(scsi_cmnd));
2290 retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2291 scsi_sglist(scsi_cmnd));
2292 if (unlikely(retval))
2293 goto failed_scsi_cmnd;
2295 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
2296 if (zfcp_adapter_multi_buffer_active(adapter))
2297 zfcp_qdio_set_scount(qdio, &req->qdio_req);
2299 retval = zfcp_fsf_req_send(req);
2300 if (unlikely(retval))
2301 goto failed_scsi_cmnd;
2306 zfcp_fsf_req_free(req);
2307 scsi_cmnd->host_scribble = NULL;
2309 spin_unlock_irqrestore(&qdio->req_q_lock, flags);
2313 static void zfcp_fsf_fcp_task_mgmt_handler(struct zfcp_fsf_req *req)
2315 struct scsi_device *sdev = req->data;
2316 struct fcp_resp_with_ext *fcp_rsp;
2317 struct fcp_resp_rsp_info *rsp_info;
2319 zfcp_fsf_fcp_handler_common(req, sdev);
2321 fcp_rsp = &req->qtcb->bottom.io.fcp_rsp.iu;
2322 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2324 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
2325 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2326 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
2330 * zfcp_fsf_fcp_task_mgmt() - Send SCSI task management command (TMF).
2331 * @sdev: Pointer to SCSI device to send the task management command to.
2332 * @tm_flags: Unsigned byte for task management flags.
2334 * Return: On success pointer to struct zfcp_fsf_req, %NULL otherwise.
2336 struct zfcp_fsf_req *zfcp_fsf_fcp_task_mgmt(struct scsi_device *sdev,
2339 struct zfcp_fsf_req *req = NULL;
2340 struct fcp_cmnd *fcp_cmnd;
2341 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
2342 struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
2344 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
2345 ZFCP_STATUS_COMMON_UNBLOCKED)))
2348 spin_lock_irq(&qdio->req_q_lock);
2349 if (zfcp_qdio_sbal_get(qdio))
2352 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2353 SBAL_SFLAGS0_TYPE_WRITE,
2354 qdio->adapter->pool.scsi_req);
2363 req->handler = zfcp_fsf_fcp_task_mgmt_handler;
2364 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2365 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
2366 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2367 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2368 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
2370 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
2372 fcp_cmnd = &req->qtcb->bottom.io.fcp_cmnd.iu;
2373 zfcp_fc_fcp_tm(fcp_cmnd, sdev, tm_flags);
2375 zfcp_fsf_start_timer(req, ZFCP_FSF_SCSI_ER_TIMEOUT);
2376 if (!zfcp_fsf_req_send(req))
2379 zfcp_fsf_req_free(req);
2382 spin_unlock_irq(&qdio->req_q_lock);
2387 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2388 * @qdio: pointer to struct zfcp_qdio
2389 * @sbal_idx: response queue index of SBAL to be processed
2391 void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
2393 struct zfcp_adapter *adapter = qdio->adapter;
2394 struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
2395 struct qdio_buffer_element *sbale;
2396 struct zfcp_fsf_req *fsf_req;
2397 unsigned long req_id;
2400 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2402 sbale = &sbal->element[idx];
2403 req_id = (unsigned long) sbale->addr;
2404 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
2408 * Unknown request means that we have potentially memory
2409 * corruption and must stop the machine immediately.
2411 zfcp_qdio_siosl(adapter);
2412 panic("error: unknown req_id (%lx) on adapter %s.\n",
2413 req_id, dev_name(&adapter->ccw_device->dev));
2416 zfcp_fsf_req_complete(fsf_req);
2418 if (likely(sbale->eflags & SBAL_EFLAGS_LAST_ENTRY))