1 // SPDX-License-Identifier: GPL-2.0
5 * Implementation of FSF commands.
7 * Copyright IBM Corp. 2002, 2017
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 struct kmem_cache *zfcp_fsf_qtcb_cache;
24 static bool ber_stop = true;
25 module_param(ber_stop, bool, 0600);
26 MODULE_PARM_DESC(ber_stop,
27 "Shuts down FCP devices for FCP channels that report a bit-error count in excess of its threshold (default on)");
29 static void zfcp_fsf_request_timeout_handler(unsigned long data)
31 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
32 zfcp_qdio_siosl(adapter);
33 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
37 static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
38 unsigned long timeout)
40 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
41 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
42 fsf_req->timer.expires = jiffies + timeout;
43 add_timer(&fsf_req->timer);
46 static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
48 BUG_ON(!fsf_req->erp_action);
49 fsf_req->timer.function = zfcp_erp_timeout_handler;
50 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
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 * @fsf_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(req->qtcb))
88 mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
89 mempool_free(req, req->pool);
93 if (likely(req->qtcb))
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 zfcp_dbf_hba_bit_err("fssrh_3", req);
240 dev_warn(&adapter->ccw_device->dev,
241 "All paths over this FCP device are disused because of excessive bit errors\n");
242 zfcp_erp_adapter_shutdown(adapter, 0, "fssrh_b");
244 dev_warn(&adapter->ccw_device->dev,
245 "The error threshold for checksum statistics has been exceeded\n");
248 case FSF_STATUS_READ_LINK_DOWN:
249 zfcp_fsf_status_read_link_down(req);
250 zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKDOWN, 0);
252 case FSF_STATUS_READ_LINK_UP:
253 dev_info(&adapter->ccw_device->dev,
254 "The local link has been restored\n");
255 /* All ports should be marked as ready to run again */
256 zfcp_erp_set_adapter_status(adapter,
257 ZFCP_STATUS_COMMON_RUNNING);
258 zfcp_erp_adapter_reopen(adapter,
259 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
260 ZFCP_STATUS_COMMON_ERP_FAILED,
262 zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKUP, 0);
265 case FSF_STATUS_READ_NOTIFICATION_LOST:
266 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
267 zfcp_fc_conditional_port_scan(adapter);
269 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
270 adapter->adapter_features = sr_buf->payload.word[0];
274 mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
275 zfcp_fsf_req_free(req);
277 atomic_inc(&adapter->stat_miss);
278 queue_work(adapter->work_queue, &adapter->stat_work);
281 static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
283 switch (req->qtcb->header.fsf_status_qual.word[0]) {
284 case FSF_SQ_FCP_RSP_AVAILABLE:
285 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
286 case FSF_SQ_NO_RETRY_POSSIBLE:
287 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
289 case FSF_SQ_COMMAND_ABORTED:
291 case FSF_SQ_NO_RECOM:
292 dev_err(&req->adapter->ccw_device->dev,
293 "The FCP adapter reported a problem "
294 "that cannot be recovered\n");
295 zfcp_qdio_siosl(req->adapter);
296 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1");
299 /* all non-return stats set FSFREQ_ERROR*/
300 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
303 static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
305 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
308 switch (req->qtcb->header.fsf_status) {
309 case FSF_UNKNOWN_COMMAND:
310 dev_err(&req->adapter->ccw_device->dev,
311 "The FCP adapter does not recognize the command 0x%x\n",
312 req->qtcb->header.fsf_command);
313 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1");
314 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
316 case FSF_ADAPTER_STATUS_AVAILABLE:
317 zfcp_fsf_fsfstatus_qual_eval(req);
322 static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
324 struct zfcp_adapter *adapter = req->adapter;
325 struct fsf_qtcb *qtcb = req->qtcb;
326 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
328 zfcp_dbf_hba_fsf_response(req);
330 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
331 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
335 switch (qtcb->prefix.prot_status) {
337 case FSF_PROT_FSF_STATUS_PRESENTED:
339 case FSF_PROT_QTCB_VERSION_ERROR:
340 dev_err(&adapter->ccw_device->dev,
341 "QTCB version 0x%x not supported by FCP adapter "
342 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
343 psq->word[0], psq->word[1]);
344 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1");
346 case FSF_PROT_ERROR_STATE:
347 case FSF_PROT_SEQ_NUMB_ERROR:
348 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2");
349 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
351 case FSF_PROT_UNSUPP_QTCB_TYPE:
352 dev_err(&adapter->ccw_device->dev,
353 "The QTCB type is not supported by the FCP adapter\n");
354 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3");
356 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
357 atomic_or(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
360 case FSF_PROT_DUPLICATE_REQUEST_ID:
361 dev_err(&adapter->ccw_device->dev,
362 "0x%Lx is an ambiguous request identifier\n",
363 (unsigned long long)qtcb->bottom.support.req_handle);
364 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4");
366 case FSF_PROT_LINK_DOWN:
367 zfcp_fsf_link_down_info_eval(req, &psq->link_down_info);
368 /* go through reopen to flush pending requests */
369 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6");
371 case FSF_PROT_REEST_QUEUE:
372 /* All ports should be marked as ready to run again */
373 zfcp_erp_set_adapter_status(adapter,
374 ZFCP_STATUS_COMMON_RUNNING);
375 zfcp_erp_adapter_reopen(adapter,
376 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
377 ZFCP_STATUS_COMMON_ERP_FAILED,
381 dev_err(&adapter->ccw_device->dev,
382 "0x%x is not a valid transfer protocol status\n",
383 qtcb->prefix.prot_status);
384 zfcp_qdio_siosl(adapter);
385 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9");
387 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
391 * zfcp_fsf_req_complete - process completion of a FSF request
392 * @fsf_req: The FSF request that has been completed.
394 * When a request has been completed either from the FCP adapter,
395 * or it has been dismissed due to a queue shutdown, this function
396 * is called to process the completion status and trigger further
397 * events related to the FSF request.
399 static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
401 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
402 zfcp_fsf_status_read_handler(req);
406 del_timer(&req->timer);
407 zfcp_fsf_protstatus_eval(req);
408 zfcp_fsf_fsfstatus_eval(req);
412 zfcp_erp_notify(req->erp_action, 0);
414 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
415 zfcp_fsf_req_free(req);
417 complete(&req->completion);
421 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
422 * @adapter: pointer to struct zfcp_adapter
424 * Never ever call this without shutting down the adapter first.
425 * Otherwise the adapter would continue using and corrupting s390 storage.
426 * Included BUG_ON() call to ensure this is done.
427 * ERP is supposed to be the only user of this function.
429 void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
431 struct zfcp_fsf_req *req, *tmp;
432 LIST_HEAD(remove_queue);
434 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
435 zfcp_reqlist_move(adapter->req_list, &remove_queue);
437 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
438 list_del(&req->list);
439 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
440 zfcp_fsf_req_complete(req);
444 #define ZFCP_FSF_PORTSPEED_1GBIT (1 << 0)
445 #define ZFCP_FSF_PORTSPEED_2GBIT (1 << 1)
446 #define ZFCP_FSF_PORTSPEED_4GBIT (1 << 2)
447 #define ZFCP_FSF_PORTSPEED_10GBIT (1 << 3)
448 #define ZFCP_FSF_PORTSPEED_8GBIT (1 << 4)
449 #define ZFCP_FSF_PORTSPEED_16GBIT (1 << 5)
450 #define ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED (1 << 15)
452 static u32 zfcp_fsf_convert_portspeed(u32 fsf_speed)
455 if (fsf_speed & ZFCP_FSF_PORTSPEED_1GBIT)
456 fdmi_speed |= FC_PORTSPEED_1GBIT;
457 if (fsf_speed & ZFCP_FSF_PORTSPEED_2GBIT)
458 fdmi_speed |= FC_PORTSPEED_2GBIT;
459 if (fsf_speed & ZFCP_FSF_PORTSPEED_4GBIT)
460 fdmi_speed |= FC_PORTSPEED_4GBIT;
461 if (fsf_speed & ZFCP_FSF_PORTSPEED_10GBIT)
462 fdmi_speed |= FC_PORTSPEED_10GBIT;
463 if (fsf_speed & ZFCP_FSF_PORTSPEED_8GBIT)
464 fdmi_speed |= FC_PORTSPEED_8GBIT;
465 if (fsf_speed & ZFCP_FSF_PORTSPEED_16GBIT)
466 fdmi_speed |= FC_PORTSPEED_16GBIT;
467 if (fsf_speed & ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED)
468 fdmi_speed |= FC_PORTSPEED_NOT_NEGOTIATED;
472 static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
474 struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
475 struct zfcp_adapter *adapter = req->adapter;
476 struct Scsi_Host *shost = adapter->scsi_host;
477 struct fc_els_flogi *nsp, *plogi;
479 /* adjust pointers for missing command code */
480 nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
482 plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
486 memcpy(req->data, bottom, sizeof(*bottom));
488 fc_host_port_name(shost) = be64_to_cpu(nsp->fl_wwpn);
489 fc_host_node_name(shost) = be64_to_cpu(nsp->fl_wwnn);
490 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
492 adapter->timer_ticks = bottom->timer_interval & ZFCP_FSF_TIMER_INT_MASK;
493 adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
494 (u16)FSF_STATUS_READS_RECOM);
496 if (fc_host_permanent_port_name(shost) == -1)
497 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
499 zfcp_scsi_set_prot(adapter);
501 /* no error return above here, otherwise must fix call chains */
502 /* do not evaluate invalid fields */
503 if (req->qtcb->header.fsf_status == FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE)
506 fc_host_port_id(shost) = ntoh24(bottom->s_id);
507 fc_host_speed(shost) =
508 zfcp_fsf_convert_portspeed(bottom->fc_link_speed);
510 adapter->hydra_version = bottom->adapter_type;
512 switch (bottom->fc_topology) {
514 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
515 adapter->peer_wwpn = be64_to_cpu(plogi->fl_wwpn);
516 adapter->peer_wwnn = be64_to_cpu(plogi->fl_wwnn);
517 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
519 case FSF_TOPO_FABRIC:
520 if (bottom->connection_features & FSF_FEATURE_NPIV_MODE)
521 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
523 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
526 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
529 dev_err(&adapter->ccw_device->dev,
530 "Unknown or unsupported arbitrated loop "
531 "fibre channel topology detected\n");
532 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1");
539 static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
541 struct zfcp_adapter *adapter = req->adapter;
542 struct fsf_qtcb *qtcb = req->qtcb;
543 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
544 struct Scsi_Host *shost = adapter->scsi_host;
546 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
549 adapter->fsf_lic_version = bottom->lic_version;
550 adapter->adapter_features = bottom->adapter_features;
551 adapter->connection_features = bottom->connection_features;
552 adapter->peer_wwpn = 0;
553 adapter->peer_wwnn = 0;
554 adapter->peer_d_id = 0;
556 switch (qtcb->header.fsf_status) {
558 if (zfcp_fsf_exchange_config_evaluate(req))
561 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
562 dev_err(&adapter->ccw_device->dev,
563 "FCP adapter maximum QTCB size (%d bytes) "
565 bottom->max_qtcb_size);
566 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1");
569 atomic_or(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
572 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
573 fc_host_node_name(shost) = 0;
574 fc_host_port_name(shost) = 0;
575 fc_host_port_id(shost) = 0;
576 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
577 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
578 adapter->hydra_version = 0;
580 /* avoids adapter shutdown to be able to recognize
581 * events such as LINK UP */
582 atomic_or(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
584 zfcp_fsf_link_down_info_eval(req,
585 &qtcb->header.fsf_status_qual.link_down_info);
586 if (zfcp_fsf_exchange_config_evaluate(req))
590 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3");
594 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
595 adapter->hardware_version = bottom->hardware_version;
596 memcpy(fc_host_serial_number(shost), bottom->serial_number,
597 min(FC_SERIAL_NUMBER_SIZE, 17));
598 EBCASC(fc_host_serial_number(shost),
599 min(FC_SERIAL_NUMBER_SIZE, 17));
602 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
603 dev_err(&adapter->ccw_device->dev,
604 "The FCP adapter only supports newer "
605 "control block versions\n");
606 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4");
609 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
610 dev_err(&adapter->ccw_device->dev,
611 "The FCP adapter only supports older "
612 "control block versions\n");
613 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5");
617 static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
619 struct zfcp_adapter *adapter = req->adapter;
620 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
621 struct Scsi_Host *shost = adapter->scsi_host;
624 memcpy(req->data, bottom, sizeof(*bottom));
626 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
627 fc_host_permanent_port_name(shost) = bottom->wwpn;
629 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
630 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
631 fc_host_supported_speeds(shost) =
632 zfcp_fsf_convert_portspeed(bottom->supported_speed);
633 memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
635 memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
639 static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
641 struct fsf_qtcb *qtcb = req->qtcb;
643 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
646 switch (qtcb->header.fsf_status) {
648 zfcp_fsf_exchange_port_evaluate(req);
650 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
651 zfcp_fsf_exchange_port_evaluate(req);
652 zfcp_fsf_link_down_info_eval(req,
653 &qtcb->header.fsf_status_qual.link_down_info);
658 static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
660 struct zfcp_fsf_req *req;
663 req = mempool_alloc(pool, GFP_ATOMIC);
665 req = kmalloc(sizeof(*req), GFP_ATOMIC);
670 memset(req, 0, sizeof(*req));
675 static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
677 struct fsf_qtcb *qtcb;
680 qtcb = mempool_alloc(pool, GFP_ATOMIC);
682 qtcb = kmem_cache_alloc(zfcp_fsf_qtcb_cache, GFP_ATOMIC);
687 memset(qtcb, 0, sizeof(*qtcb));
691 static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
692 u32 fsf_cmd, u8 sbtype,
695 struct zfcp_adapter *adapter = qdio->adapter;
696 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
699 return ERR_PTR(-ENOMEM);
701 if (adapter->req_no == 0)
704 INIT_LIST_HEAD(&req->list);
705 init_timer(&req->timer);
706 init_completion(&req->completion);
708 req->adapter = adapter;
709 req->fsf_command = fsf_cmd;
710 req->req_id = adapter->req_no;
712 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
714 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
716 req->qtcb = zfcp_qtcb_alloc(NULL);
718 if (unlikely(!req->qtcb)) {
719 zfcp_fsf_req_free(req);
720 return ERR_PTR(-ENOMEM);
723 req->seq_no = adapter->fsf_req_seq_no;
724 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
725 req->qtcb->prefix.req_id = req->req_id;
726 req->qtcb->prefix.ulp_info = 26;
727 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
728 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
729 req->qtcb->header.req_handle = req->req_id;
730 req->qtcb->header.fsf_command = req->fsf_command;
733 zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
734 req->qtcb, sizeof(struct fsf_qtcb));
739 static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
741 struct zfcp_adapter *adapter = req->adapter;
742 struct zfcp_qdio *qdio = adapter->qdio;
743 int with_qtcb = (req->qtcb != NULL);
744 int req_id = req->req_id;
746 zfcp_reqlist_add(adapter->req_list, req);
748 req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free);
749 req->issued = get_tod_clock();
750 if (zfcp_qdio_send(qdio, &req->qdio_req)) {
751 del_timer(&req->timer);
752 /* lookup request again, list might have changed */
753 zfcp_reqlist_find_rm(adapter->req_list, req_id);
754 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1");
758 /* Don't increase for unsolicited status */
760 adapter->fsf_req_seq_no++;
767 * zfcp_fsf_status_read - send status read request
768 * @adapter: pointer to struct zfcp_adapter
769 * @req_flags: request flags
770 * Returns: 0 on success, ERROR otherwise
772 int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
774 struct zfcp_adapter *adapter = qdio->adapter;
775 struct zfcp_fsf_req *req;
776 struct fsf_status_read_buffer *sr_buf;
780 spin_lock_irq(&qdio->req_q_lock);
781 if (zfcp_qdio_sbal_get(qdio))
784 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS,
785 SBAL_SFLAGS0_TYPE_STATUS,
786 adapter->pool.status_read_req);
788 retval = PTR_ERR(req);
792 page = mempool_alloc(adapter->pool.sr_data, GFP_ATOMIC);
797 sr_buf = page_address(page);
798 memset(sr_buf, 0, sizeof(*sr_buf));
801 zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
802 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
804 retval = zfcp_fsf_req_send(req);
806 goto failed_req_send;
812 mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
814 zfcp_dbf_hba_fsf_uss("fssr__1", req);
815 zfcp_fsf_req_free(req);
817 spin_unlock_irq(&qdio->req_q_lock);
821 static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
823 struct scsi_device *sdev = req->data;
824 struct zfcp_scsi_dev *zfcp_sdev;
825 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
827 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
830 zfcp_sdev = sdev_to_zfcp(sdev);
832 switch (req->qtcb->header.fsf_status) {
833 case FSF_PORT_HANDLE_NOT_VALID:
834 if (fsq->word[0] == fsq->word[1]) {
835 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0,
837 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
840 case FSF_LUN_HANDLE_NOT_VALID:
841 if (fsq->word[0] == fsq->word[1]) {
842 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fsafch2");
843 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
846 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
847 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
850 zfcp_erp_set_port_status(zfcp_sdev->port,
851 ZFCP_STATUS_COMMON_ACCESS_BOXED);
852 zfcp_erp_port_reopen(zfcp_sdev->port,
853 ZFCP_STATUS_COMMON_ERP_FAILED, "fsafch3");
854 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
857 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
858 zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
860 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
862 case FSF_ADAPTER_STATUS_AVAILABLE:
863 switch (fsq->word[0]) {
864 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
865 zfcp_fc_test_link(zfcp_sdev->port);
867 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
868 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
873 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
879 * zfcp_fsf_abort_fcp_cmnd - abort running SCSI command
880 * @scmnd: The SCSI command to abort
881 * Returns: pointer to struct zfcp_fsf_req
884 struct zfcp_fsf_req *zfcp_fsf_abort_fcp_cmnd(struct scsi_cmnd *scmnd)
886 struct zfcp_fsf_req *req = NULL;
887 struct scsi_device *sdev = scmnd->device;
888 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
889 struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
890 unsigned long old_req_id = (unsigned long) scmnd->host_scribble;
892 spin_lock_irq(&qdio->req_q_lock);
893 if (zfcp_qdio_sbal_get(qdio))
895 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
896 SBAL_SFLAGS0_TYPE_READ,
897 qdio->adapter->pool.scsi_abort);
903 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
904 ZFCP_STATUS_COMMON_UNBLOCKED)))
907 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
910 req->handler = zfcp_fsf_abort_fcp_command_handler;
911 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
912 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
913 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
915 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
916 if (!zfcp_fsf_req_send(req))
920 zfcp_fsf_req_free(req);
923 spin_unlock_irq(&qdio->req_q_lock);
927 static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
929 struct zfcp_adapter *adapter = req->adapter;
930 struct zfcp_fsf_ct_els *ct = req->data;
931 struct fsf_qtcb_header *header = &req->qtcb->header;
933 ct->status = -EINVAL;
935 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
938 switch (header->fsf_status) {
941 zfcp_dbf_san_res("fsscth2", req);
943 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
944 zfcp_fsf_class_not_supp(req);
946 case FSF_ADAPTER_STATUS_AVAILABLE:
947 switch (header->fsf_status_qual.word[0]){
948 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
949 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
950 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
955 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
957 case FSF_PORT_HANDLE_NOT_VALID:
958 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1");
960 case FSF_GENERIC_COMMAND_REJECTED:
961 case FSF_PAYLOAD_SIZE_MISMATCH:
962 case FSF_REQUEST_SIZE_TOO_LARGE:
963 case FSF_RESPONSE_SIZE_TOO_LARGE:
964 case FSF_SBAL_MISMATCH:
965 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
971 ct->handler(ct->handler_data);
974 static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
975 struct zfcp_qdio_req *q_req,
976 struct scatterlist *sg_req,
977 struct scatterlist *sg_resp)
979 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
980 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
981 zfcp_qdio_set_sbale_last(qdio, q_req);
984 static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
985 struct scatterlist *sg_req,
986 struct scatterlist *sg_resp)
988 struct zfcp_adapter *adapter = req->adapter;
989 struct zfcp_qdio *qdio = adapter->qdio;
990 struct fsf_qtcb *qtcb = req->qtcb;
991 u32 feat = adapter->adapter_features;
993 if (zfcp_adapter_multi_buffer_active(adapter)) {
994 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
996 qtcb->bottom.support.req_buf_length =
997 zfcp_qdio_real_bytes(sg_req);
998 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
1000 qtcb->bottom.support.resp_buf_length =
1001 zfcp_qdio_real_bytes(sg_resp);
1003 zfcp_qdio_set_data_div(qdio, &req->qdio_req, sg_nents(sg_req));
1004 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1005 zfcp_qdio_set_scount(qdio, &req->qdio_req);
1009 /* use single, unchained SBAL if it can hold the request */
1010 if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
1011 zfcp_fsf_setup_ct_els_unchained(qdio, &req->qdio_req,
1016 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS))
1019 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
1022 qtcb->bottom.support.req_buf_length = zfcp_qdio_real_bytes(sg_req);
1024 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1025 zfcp_qdio_skip_to_last_sbale(qdio, &req->qdio_req);
1027 if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
1030 qtcb->bottom.support.resp_buf_length = zfcp_qdio_real_bytes(sg_resp);
1032 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1037 static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1038 struct scatterlist *sg_req,
1039 struct scatterlist *sg_resp,
1040 unsigned int timeout)
1044 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
1048 /* common settings for ct/gs and els requests */
1050 timeout = 255; /* max value accepted by hardware */
1051 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
1052 req->qtcb->bottom.support.timeout = timeout;
1053 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
1059 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1060 * @ct: pointer to struct zfcp_send_ct with data for request
1061 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1063 int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
1064 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1065 unsigned int timeout)
1067 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1068 struct zfcp_fsf_req *req;
1071 spin_lock_irq(&qdio->req_q_lock);
1072 if (zfcp_qdio_sbal_get(qdio))
1075 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
1076 SBAL_SFLAGS0_TYPE_WRITE_READ, pool);
1083 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1084 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
1088 req->handler = zfcp_fsf_send_ct_handler;
1089 req->qtcb->header.port_handle = wka_port->handle;
1090 ct->d_id = wka_port->d_id;
1093 zfcp_dbf_san_req("fssct_1", req, wka_port->d_id);
1095 ret = zfcp_fsf_req_send(req);
1102 zfcp_fsf_req_free(req);
1104 spin_unlock_irq(&qdio->req_q_lock);
1108 static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1110 struct zfcp_fsf_ct_els *send_els = req->data;
1111 struct fsf_qtcb_header *header = &req->qtcb->header;
1113 send_els->status = -EINVAL;
1115 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1116 goto skip_fsfstatus;
1118 switch (header->fsf_status) {
1120 send_els->status = 0;
1121 zfcp_dbf_san_res("fsselh1", req);
1123 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1124 zfcp_fsf_class_not_supp(req);
1126 case FSF_ADAPTER_STATUS_AVAILABLE:
1127 switch (header->fsf_status_qual.word[0]){
1128 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1129 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1130 case FSF_SQ_RETRY_IF_POSSIBLE:
1131 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1135 case FSF_ELS_COMMAND_REJECTED:
1136 case FSF_PAYLOAD_SIZE_MISMATCH:
1137 case FSF_REQUEST_SIZE_TOO_LARGE:
1138 case FSF_RESPONSE_SIZE_TOO_LARGE:
1140 case FSF_SBAL_MISMATCH:
1141 /* should never occur, avoided in zfcp_fsf_send_els */
1144 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1148 if (send_els->handler)
1149 send_els->handler(send_els->handler_data);
1153 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1154 * @els: pointer to struct zfcp_send_els with data for the command
1156 int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
1157 struct zfcp_fsf_ct_els *els, unsigned int timeout)
1159 struct zfcp_fsf_req *req;
1160 struct zfcp_qdio *qdio = adapter->qdio;
1163 spin_lock_irq(&qdio->req_q_lock);
1164 if (zfcp_qdio_sbal_get(qdio))
1167 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
1168 SBAL_SFLAGS0_TYPE_WRITE_READ, NULL);
1175 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1177 if (!zfcp_adapter_multi_buffer_active(adapter))
1178 zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
1180 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
1185 hton24(req->qtcb->bottom.support.d_id, d_id);
1186 req->handler = zfcp_fsf_send_els_handler;
1190 zfcp_dbf_san_req("fssels1", req, d_id);
1192 ret = zfcp_fsf_req_send(req);
1199 zfcp_fsf_req_free(req);
1201 spin_unlock_irq(&qdio->req_q_lock);
1205 int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1207 struct zfcp_fsf_req *req;
1208 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1211 spin_lock_irq(&qdio->req_q_lock);
1212 if (zfcp_qdio_sbal_get(qdio))
1215 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1216 SBAL_SFLAGS0_TYPE_READ,
1217 qdio->adapter->pool.erp_req);
1220 retval = PTR_ERR(req);
1224 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1225 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1227 req->qtcb->bottom.config.feature_selection =
1228 FSF_FEATURE_NOTIFICATION_LOST |
1229 FSF_FEATURE_UPDATE_ALERT;
1230 req->erp_action = erp_action;
1231 req->handler = zfcp_fsf_exchange_config_data_handler;
1232 erp_action->fsf_req_id = req->req_id;
1234 zfcp_fsf_start_erp_timer(req);
1235 retval = zfcp_fsf_req_send(req);
1237 zfcp_fsf_req_free(req);
1238 erp_action->fsf_req_id = 0;
1241 spin_unlock_irq(&qdio->req_q_lock);
1245 int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
1246 struct fsf_qtcb_bottom_config *data)
1248 struct zfcp_fsf_req *req = NULL;
1251 spin_lock_irq(&qdio->req_q_lock);
1252 if (zfcp_qdio_sbal_get(qdio))
1255 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1256 SBAL_SFLAGS0_TYPE_READ, NULL);
1259 retval = PTR_ERR(req);
1263 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1264 req->handler = zfcp_fsf_exchange_config_data_handler;
1266 req->qtcb->bottom.config.feature_selection =
1267 FSF_FEATURE_NOTIFICATION_LOST |
1268 FSF_FEATURE_UPDATE_ALERT;
1273 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1274 retval = zfcp_fsf_req_send(req);
1275 spin_unlock_irq(&qdio->req_q_lock);
1277 wait_for_completion(&req->completion);
1279 zfcp_fsf_req_free(req);
1283 spin_unlock_irq(&qdio->req_q_lock);
1288 * zfcp_fsf_exchange_port_data - request information about local port
1289 * @erp_action: ERP action for the adapter for which port data is requested
1290 * Returns: 0 on success, error otherwise
1292 int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1294 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1295 struct zfcp_fsf_req *req;
1298 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1301 spin_lock_irq(&qdio->req_q_lock);
1302 if (zfcp_qdio_sbal_get(qdio))
1305 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1306 SBAL_SFLAGS0_TYPE_READ,
1307 qdio->adapter->pool.erp_req);
1310 retval = PTR_ERR(req);
1314 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1315 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1317 req->handler = zfcp_fsf_exchange_port_data_handler;
1318 req->erp_action = erp_action;
1319 erp_action->fsf_req_id = req->req_id;
1321 zfcp_fsf_start_erp_timer(req);
1322 retval = zfcp_fsf_req_send(req);
1324 zfcp_fsf_req_free(req);
1325 erp_action->fsf_req_id = 0;
1328 spin_unlock_irq(&qdio->req_q_lock);
1333 * zfcp_fsf_exchange_port_data_sync - request information about local port
1334 * @qdio: pointer to struct zfcp_qdio
1335 * @data: pointer to struct fsf_qtcb_bottom_port
1336 * Returns: 0 on success, error otherwise
1338 int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
1339 struct fsf_qtcb_bottom_port *data)
1341 struct zfcp_fsf_req *req = NULL;
1344 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1347 spin_lock_irq(&qdio->req_q_lock);
1348 if (zfcp_qdio_sbal_get(qdio))
1351 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1352 SBAL_SFLAGS0_TYPE_READ, NULL);
1355 retval = PTR_ERR(req);
1362 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1364 req->handler = zfcp_fsf_exchange_port_data_handler;
1365 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1366 retval = zfcp_fsf_req_send(req);
1367 spin_unlock_irq(&qdio->req_q_lock);
1370 wait_for_completion(&req->completion);
1372 zfcp_fsf_req_free(req);
1377 spin_unlock_irq(&qdio->req_q_lock);
1381 static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1383 struct zfcp_port *port = req->data;
1384 struct fsf_qtcb_header *header = &req->qtcb->header;
1385 struct fc_els_flogi *plogi;
1387 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1390 switch (header->fsf_status) {
1391 case FSF_PORT_ALREADY_OPEN:
1393 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1394 dev_warn(&req->adapter->ccw_device->dev,
1395 "Not enough FCP adapter resources to open "
1396 "remote port 0x%016Lx\n",
1397 (unsigned long long)port->wwpn);
1398 zfcp_erp_set_port_status(port,
1399 ZFCP_STATUS_COMMON_ERP_FAILED);
1400 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1402 case FSF_ADAPTER_STATUS_AVAILABLE:
1403 switch (header->fsf_status_qual.word[0]) {
1404 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1405 /* no zfcp_fc_test_link() with failed open port */
1407 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1408 case FSF_SQ_NO_RETRY_POSSIBLE:
1409 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1414 port->handle = header->port_handle;
1415 atomic_or(ZFCP_STATUS_COMMON_OPEN |
1416 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1417 atomic_andnot(ZFCP_STATUS_COMMON_ACCESS_BOXED,
1419 /* check whether D_ID has changed during open */
1421 * FIXME: This check is not airtight, as the FCP channel does
1422 * not monitor closures of target port connections caused on
1423 * the remote side. Thus, they might miss out on invalidating
1424 * locally cached WWPNs (and other N_Port parameters) of gone
1425 * target ports. So, our heroic attempt to make things safe
1426 * could be undermined by 'open port' response data tagged with
1427 * obsolete WWPNs. Another reason to monitor potential
1428 * connection closures ourself at least (by interpreting
1429 * incoming ELS' and unsolicited status). It just crosses my
1430 * mind that one should be able to cross-check by means of
1431 * another GID_PN straight after a port has been opened.
1432 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1434 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
1435 if (req->qtcb->bottom.support.els1_length >=
1437 zfcp_fc_plogi_evaluate(port, plogi);
1439 case FSF_UNKNOWN_OP_SUBTYPE:
1440 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1445 put_device(&port->dev);
1449 * zfcp_fsf_open_port - create and send open port request
1450 * @erp_action: pointer to struct zfcp_erp_action
1451 * Returns: 0 on success, error otherwise
1453 int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
1455 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1456 struct zfcp_port *port = erp_action->port;
1457 struct zfcp_fsf_req *req;
1460 spin_lock_irq(&qdio->req_q_lock);
1461 if (zfcp_qdio_sbal_get(qdio))
1464 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1465 SBAL_SFLAGS0_TYPE_READ,
1466 qdio->adapter->pool.erp_req);
1469 retval = PTR_ERR(req);
1473 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1474 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1476 req->handler = zfcp_fsf_open_port_handler;
1477 hton24(req->qtcb->bottom.support.d_id, port->d_id);
1479 req->erp_action = erp_action;
1480 erp_action->fsf_req_id = req->req_id;
1481 get_device(&port->dev);
1483 zfcp_fsf_start_erp_timer(req);
1484 retval = zfcp_fsf_req_send(req);
1486 zfcp_fsf_req_free(req);
1487 erp_action->fsf_req_id = 0;
1488 put_device(&port->dev);
1491 spin_unlock_irq(&qdio->req_q_lock);
1495 static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
1497 struct zfcp_port *port = req->data;
1499 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1502 switch (req->qtcb->header.fsf_status) {
1503 case FSF_PORT_HANDLE_NOT_VALID:
1504 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1");
1505 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1507 case FSF_ADAPTER_STATUS_AVAILABLE:
1510 zfcp_erp_clear_port_status(port, ZFCP_STATUS_COMMON_OPEN);
1516 * zfcp_fsf_close_port - create and send close port request
1517 * @erp_action: pointer to struct zfcp_erp_action
1518 * Returns: 0 on success, error otherwise
1520 int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
1522 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1523 struct zfcp_fsf_req *req;
1526 spin_lock_irq(&qdio->req_q_lock);
1527 if (zfcp_qdio_sbal_get(qdio))
1530 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1531 SBAL_SFLAGS0_TYPE_READ,
1532 qdio->adapter->pool.erp_req);
1535 retval = PTR_ERR(req);
1539 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1540 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1542 req->handler = zfcp_fsf_close_port_handler;
1543 req->data = erp_action->port;
1544 req->erp_action = erp_action;
1545 req->qtcb->header.port_handle = erp_action->port->handle;
1546 erp_action->fsf_req_id = req->req_id;
1548 zfcp_fsf_start_erp_timer(req);
1549 retval = zfcp_fsf_req_send(req);
1551 zfcp_fsf_req_free(req);
1552 erp_action->fsf_req_id = 0;
1555 spin_unlock_irq(&qdio->req_q_lock);
1559 static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1561 struct zfcp_fc_wka_port *wka_port = req->data;
1562 struct fsf_qtcb_header *header = &req->qtcb->header;
1564 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1565 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1569 switch (header->fsf_status) {
1570 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1571 dev_warn(&req->adapter->ccw_device->dev,
1572 "Opening WKA port 0x%x failed\n", wka_port->d_id);
1574 case FSF_ADAPTER_STATUS_AVAILABLE:
1575 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1576 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1579 wka_port->handle = header->port_handle;
1581 case FSF_PORT_ALREADY_OPEN:
1582 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
1585 wake_up(&wka_port->opened);
1589 * zfcp_fsf_open_wka_port - create and send open wka-port request
1590 * @wka_port: pointer to struct zfcp_fc_wka_port
1591 * Returns: 0 on success, error otherwise
1593 int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
1595 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1596 struct zfcp_fsf_req *req;
1597 unsigned long req_id = 0;
1600 spin_lock_irq(&qdio->req_q_lock);
1601 if (zfcp_qdio_sbal_get(qdio))
1604 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1605 SBAL_SFLAGS0_TYPE_READ,
1606 qdio->adapter->pool.erp_req);
1609 retval = PTR_ERR(req);
1613 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1614 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1616 req->handler = zfcp_fsf_open_wka_port_handler;
1617 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
1618 req->data = wka_port;
1620 req_id = req->req_id;
1622 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1623 retval = zfcp_fsf_req_send(req);
1625 zfcp_fsf_req_free(req);
1627 spin_unlock_irq(&qdio->req_q_lock);
1629 zfcp_dbf_rec_run_wka("fsowp_1", wka_port, req_id);
1633 static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1635 struct zfcp_fc_wka_port *wka_port = req->data;
1637 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1638 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1639 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1");
1642 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1643 wake_up(&wka_port->closed);
1647 * zfcp_fsf_close_wka_port - create and send close wka port request
1648 * @wka_port: WKA port to open
1649 * Returns: 0 on success, error otherwise
1651 int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
1653 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1654 struct zfcp_fsf_req *req;
1655 unsigned long req_id = 0;
1658 spin_lock_irq(&qdio->req_q_lock);
1659 if (zfcp_qdio_sbal_get(qdio))
1662 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1663 SBAL_SFLAGS0_TYPE_READ,
1664 qdio->adapter->pool.erp_req);
1667 retval = PTR_ERR(req);
1671 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1672 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1674 req->handler = zfcp_fsf_close_wka_port_handler;
1675 req->data = wka_port;
1676 req->qtcb->header.port_handle = wka_port->handle;
1678 req_id = req->req_id;
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_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%Lx on port 0x%Lx 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 fsf_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 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,
2055 static void zfcp_fsf_fcp_handler_common(struct zfcp_fsf_req *req)
2057 struct scsi_cmnd *scmnd = req->data;
2058 struct scsi_device *sdev = scmnd->device;
2059 struct zfcp_scsi_dev *zfcp_sdev;
2060 struct fsf_qtcb_header *header = &req->qtcb->header;
2062 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2065 zfcp_sdev = sdev_to_zfcp(sdev);
2067 switch (header->fsf_status) {
2068 case FSF_HANDLE_MISMATCH:
2069 case FSF_PORT_HANDLE_NOT_VALID:
2070 zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fssfch1");
2071 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2073 case FSF_FCPLUN_NOT_VALID:
2074 case FSF_LUN_HANDLE_NOT_VALID:
2075 zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fssfch2");
2076 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2078 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2079 zfcp_fsf_class_not_supp(req);
2081 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2082 dev_err(&req->adapter->ccw_device->dev,
2083 "Incorrect direction %d, LUN 0x%016Lx on port "
2084 "0x%016Lx closed\n",
2085 req->qtcb->bottom.io.data_direction,
2086 (unsigned long long)zfcp_scsi_dev_lun(sdev),
2087 (unsigned long long)zfcp_sdev->port->wwpn);
2088 zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
2090 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2092 case FSF_CMND_LENGTH_NOT_VALID:
2093 dev_err(&req->adapter->ccw_device->dev,
2094 "Incorrect CDB length %d, LUN 0x%016Lx on "
2095 "port 0x%016Lx closed\n",
2096 req->qtcb->bottom.io.fcp_cmnd_length,
2097 (unsigned long long)zfcp_scsi_dev_lun(sdev),
2098 (unsigned long long)zfcp_sdev->port->wwpn);
2099 zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
2101 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2103 case FSF_PORT_BOXED:
2104 zfcp_erp_set_port_status(zfcp_sdev->port,
2105 ZFCP_STATUS_COMMON_ACCESS_BOXED);
2106 zfcp_erp_port_reopen(zfcp_sdev->port,
2107 ZFCP_STATUS_COMMON_ERP_FAILED, "fssfch5");
2108 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2111 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
2112 zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
2114 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2116 case FSF_ADAPTER_STATUS_AVAILABLE:
2117 if (header->fsf_status_qual.word[0] ==
2118 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
2119 zfcp_fc_test_link(zfcp_sdev->port);
2120 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2125 static void zfcp_fsf_fcp_cmnd_handler(struct zfcp_fsf_req *req)
2127 struct scsi_cmnd *scpnt;
2128 struct fcp_resp_with_ext *fcp_rsp;
2129 unsigned long flags;
2131 read_lock_irqsave(&req->adapter->abort_lock, flags);
2134 if (unlikely(!scpnt)) {
2135 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2139 zfcp_fsf_fcp_handler_common(req);
2141 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2142 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
2143 goto skip_fsfstatus;
2146 switch (req->qtcb->header.fsf_status) {
2147 case FSF_INCONSISTENT_PROT_DATA:
2148 case FSF_INVALID_PROT_PARM:
2149 set_host_byte(scpnt, DID_ERROR);
2150 goto skip_fsfstatus;
2151 case FSF_BLOCK_GUARD_CHECK_FAILURE:
2152 zfcp_scsi_dif_sense_error(scpnt, 0x1);
2153 goto skip_fsfstatus;
2154 case FSF_APP_TAG_CHECK_FAILURE:
2155 zfcp_scsi_dif_sense_error(scpnt, 0x2);
2156 goto skip_fsfstatus;
2157 case FSF_REF_TAG_CHECK_FAILURE:
2158 zfcp_scsi_dif_sense_error(scpnt, 0x3);
2159 goto skip_fsfstatus;
2161 BUILD_BUG_ON(sizeof(struct fcp_resp_with_ext) > FSF_FCP_RSP_SIZE);
2162 fcp_rsp = &req->qtcb->bottom.io.fcp_rsp.iu;
2163 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
2166 zfcp_fsf_req_trace(req, scpnt);
2167 zfcp_dbf_scsi_result(scpnt, req);
2169 scpnt->host_scribble = NULL;
2170 (scpnt->scsi_done) (scpnt);
2172 * We must hold this lock until scsi_done has been called.
2173 * Otherwise we may call scsi_done after abort regarding this
2174 * command has completed.
2175 * Note: scsi_done must not block!
2177 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2180 static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir)
2182 switch (scsi_get_prot_op(scsi_cmnd)) {
2183 case SCSI_PROT_NORMAL:
2184 switch (scsi_cmnd->sc_data_direction) {
2186 *data_dir = FSF_DATADIR_CMND;
2188 case DMA_FROM_DEVICE:
2189 *data_dir = FSF_DATADIR_READ;
2192 *data_dir = FSF_DATADIR_WRITE;
2194 case DMA_BIDIRECTIONAL:
2199 case SCSI_PROT_READ_STRIP:
2200 *data_dir = FSF_DATADIR_DIF_READ_STRIP;
2202 case SCSI_PROT_WRITE_INSERT:
2203 *data_dir = FSF_DATADIR_DIF_WRITE_INSERT;
2205 case SCSI_PROT_READ_PASS:
2206 *data_dir = FSF_DATADIR_DIF_READ_CONVERT;
2208 case SCSI_PROT_WRITE_PASS:
2209 *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT;
2219 * zfcp_fsf_fcp_cmnd - initiate an FCP command (for a SCSI command)
2220 * @scsi_cmnd: scsi command to be sent
2222 int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
2224 struct zfcp_fsf_req *req;
2225 struct fcp_cmnd *fcp_cmnd;
2226 u8 sbtype = SBAL_SFLAGS0_TYPE_READ;
2228 struct scsi_device *sdev = scsi_cmnd->device;
2229 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
2230 struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
2231 struct zfcp_qdio *qdio = adapter->qdio;
2232 struct fsf_qtcb_bottom_io *io;
2233 unsigned long flags;
2235 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
2236 ZFCP_STATUS_COMMON_UNBLOCKED)))
2239 spin_lock_irqsave(&qdio->req_q_lock, flags);
2240 if (atomic_read(&qdio->req_q_free) <= 0) {
2241 atomic_inc(&qdio->req_q_full);
2245 if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
2246 sbtype = SBAL_SFLAGS0_TYPE_WRITE;
2248 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2249 sbtype, adapter->pool.scsi_req);
2252 retval = PTR_ERR(req);
2256 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2258 io = &req->qtcb->bottom.io;
2259 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2260 req->data = scsi_cmnd;
2261 req->handler = zfcp_fsf_fcp_cmnd_handler;
2262 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2263 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
2264 io->service_class = FSF_CLASS_3;
2265 io->fcp_cmnd_length = FCP_CMND_LEN;
2267 if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
2268 io->data_block_length = scsi_cmnd->device->sector_size;
2269 io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
2272 if (zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction))
2273 goto failed_scsi_cmnd;
2275 BUILD_BUG_ON(sizeof(struct fcp_cmnd) > FSF_FCP_CMND_SIZE);
2276 fcp_cmnd = &req->qtcb->bottom.io.fcp_cmnd.iu;
2277 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd, 0);
2279 if ((scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) &&
2280 scsi_prot_sg_count(scsi_cmnd)) {
2281 zfcp_qdio_set_data_div(qdio, &req->qdio_req,
2282 scsi_prot_sg_count(scsi_cmnd));
2283 retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2284 scsi_prot_sglist(scsi_cmnd));
2286 goto failed_scsi_cmnd;
2287 io->prot_data_length = zfcp_qdio_real_bytes(
2288 scsi_prot_sglist(scsi_cmnd));
2291 retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2292 scsi_sglist(scsi_cmnd));
2293 if (unlikely(retval))
2294 goto failed_scsi_cmnd;
2296 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
2297 if (zfcp_adapter_multi_buffer_active(adapter))
2298 zfcp_qdio_set_scount(qdio, &req->qdio_req);
2300 retval = zfcp_fsf_req_send(req);
2301 if (unlikely(retval))
2302 goto failed_scsi_cmnd;
2307 zfcp_fsf_req_free(req);
2308 scsi_cmnd->host_scribble = NULL;
2310 spin_unlock_irqrestore(&qdio->req_q_lock, flags);
2314 static void zfcp_fsf_fcp_task_mgmt_handler(struct zfcp_fsf_req *req)
2316 struct fcp_resp_with_ext *fcp_rsp;
2317 struct fcp_resp_rsp_info *rsp_info;
2319 zfcp_fsf_fcp_handler_common(req);
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
2331 * @scmnd: SCSI command to send the task management command for
2332 * @tm_flags: unsigned byte for task management flags
2333 * Returns: on success pointer to struct fsf_req, NULL otherwise
2335 struct zfcp_fsf_req *zfcp_fsf_fcp_task_mgmt(struct scsi_cmnd *scmnd,
2338 struct zfcp_fsf_req *req = NULL;
2339 struct fcp_cmnd *fcp_cmnd;
2340 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scmnd->device);
2341 struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
2343 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
2344 ZFCP_STATUS_COMMON_UNBLOCKED)))
2347 spin_lock_irq(&qdio->req_q_lock);
2348 if (zfcp_qdio_sbal_get(qdio))
2351 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2352 SBAL_SFLAGS0_TYPE_WRITE,
2353 qdio->adapter->pool.scsi_req);
2361 req->handler = zfcp_fsf_fcp_task_mgmt_handler;
2362 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
2363 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
2364 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2365 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2366 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
2368 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
2370 fcp_cmnd = &req->qtcb->bottom.io.fcp_cmnd.iu;
2371 zfcp_fc_scsi_to_fcp(fcp_cmnd, scmnd, tm_flags);
2373 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2374 if (!zfcp_fsf_req_send(req))
2377 zfcp_fsf_req_free(req);
2380 spin_unlock_irq(&qdio->req_q_lock);
2385 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2386 * @adapter: pointer to struct zfcp_adapter
2387 * @sbal_idx: response queue index of SBAL to be processed
2389 void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
2391 struct zfcp_adapter *adapter = qdio->adapter;
2392 struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
2393 struct qdio_buffer_element *sbale;
2394 struct zfcp_fsf_req *fsf_req;
2395 unsigned long req_id;
2398 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2400 sbale = &sbal->element[idx];
2401 req_id = (unsigned long) sbale->addr;
2402 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
2406 * Unknown request means that we have potentially memory
2407 * corruption and must stop the machine immediately.
2409 zfcp_qdio_siosl(adapter);
2410 panic("error: unknown req_id (%lx) on adapter %s.\n",
2411 req_id, dev_name(&adapter->ccw_device->dev));
2414 zfcp_fsf_req_complete(fsf_req);
2416 if (likely(sbale->eflags & SBAL_EFLAGS_LAST_ENTRY))