4 * Implementation of FSF commands.
6 * Copyright IBM Corporation 2002, 2009
9 #define KMSG_COMPONENT "zfcp"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/blktrace_api.h>
16 #define ZFCP_REQ_AUTO_CLEANUP 0x00000002
17 #define ZFCP_REQ_NO_QTCB 0x00000008
19 static void zfcp_fsf_request_timeout_handler(unsigned long data)
21 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
22 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
26 static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
27 unsigned long timeout)
29 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
30 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
31 fsf_req->timer.expires = jiffies + timeout;
32 add_timer(&fsf_req->timer);
35 static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
37 BUG_ON(!fsf_req->erp_action);
38 fsf_req->timer.function = zfcp_erp_timeout_handler;
39 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
40 fsf_req->timer.expires = jiffies + 30 * HZ;
41 add_timer(&fsf_req->timer);
44 /* association between FSF command and FSF QTCB type */
45 static u32 fsf_qtcb_type[] = {
46 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
47 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
48 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
49 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
50 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
51 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
52 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
53 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
54 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
55 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
56 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
57 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
58 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
61 static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
63 u16 subtable = table >> 16;
64 u16 rule = table & 0xffff;
65 const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
67 if (subtable && subtable < ARRAY_SIZE(act_type))
68 dev_warn(&adapter->ccw_device->dev,
69 "Access denied according to ACT rule type %s, "
70 "rule %d\n", act_type[subtable], rule);
73 static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
74 struct zfcp_port *port)
76 struct fsf_qtcb_header *header = &req->qtcb->header;
77 dev_warn(&req->adapter->ccw_device->dev,
78 "Access denied to port 0x%016Lx\n",
79 (unsigned long long)port->wwpn);
80 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
81 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
82 zfcp_erp_port_access_denied(port, "fspad_1", req);
83 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
86 static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
87 struct zfcp_unit *unit)
89 struct fsf_qtcb_header *header = &req->qtcb->header;
90 dev_warn(&req->adapter->ccw_device->dev,
91 "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
92 (unsigned long long)unit->fcp_lun,
93 (unsigned long long)unit->port->wwpn);
94 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
95 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
96 zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
97 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
100 static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
102 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
103 "operational because of an unsupported FC class\n");
104 zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
105 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
109 * zfcp_fsf_req_free - free memory used by fsf request
110 * @fsf_req: pointer to struct zfcp_fsf_req
112 void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
114 if (likely(req->pool)) {
115 mempool_free(req, req->pool);
120 kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, req);
125 static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
127 struct fsf_status_read_buffer *sr_buf = req->data;
128 struct zfcp_adapter *adapter = req->adapter;
129 struct zfcp_port *port;
130 int d_id = sr_buf->d_id & ZFCP_DID_MASK;
133 read_lock_irqsave(&zfcp_data.config_lock, flags);
134 list_for_each_entry(port, &adapter->port_list_head, list)
135 if (port->d_id == d_id) {
136 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
137 zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
140 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
143 static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
144 struct fsf_link_down_info *link_down)
146 struct zfcp_adapter *adapter = req->adapter;
149 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
152 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
154 read_lock_irqsave(&zfcp_data.config_lock, flags);
155 zfcp_scsi_schedule_rports_block(adapter);
156 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
161 switch (link_down->error_code) {
162 case FSF_PSQ_LINK_NO_LIGHT:
163 dev_warn(&req->adapter->ccw_device->dev,
164 "There is no light signal from the local "
165 "fibre channel cable\n");
167 case FSF_PSQ_LINK_WRAP_PLUG:
168 dev_warn(&req->adapter->ccw_device->dev,
169 "There is a wrap plug instead of a fibre "
172 case FSF_PSQ_LINK_NO_FCP:
173 dev_warn(&req->adapter->ccw_device->dev,
174 "The adjacent fibre channel node does not "
177 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
178 dev_warn(&req->adapter->ccw_device->dev,
179 "The FCP device is suspended because of a "
180 "firmware update\n");
182 case FSF_PSQ_LINK_INVALID_WWPN:
183 dev_warn(&req->adapter->ccw_device->dev,
184 "The FCP device detected a WWPN that is "
185 "duplicate or not valid\n");
187 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
188 dev_warn(&req->adapter->ccw_device->dev,
189 "The fibre channel fabric does not support NPIV\n");
191 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
192 dev_warn(&req->adapter->ccw_device->dev,
193 "The FCP adapter cannot support more NPIV ports\n");
195 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
196 dev_warn(&req->adapter->ccw_device->dev,
197 "The adjacent switch cannot support "
198 "more NPIV ports\n");
200 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
201 dev_warn(&req->adapter->ccw_device->dev,
202 "The FCP adapter could not log in to the "
203 "fibre channel fabric\n");
205 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
206 dev_warn(&req->adapter->ccw_device->dev,
207 "The WWPN assignment file on the FCP adapter "
208 "has been damaged\n");
210 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
211 dev_warn(&req->adapter->ccw_device->dev,
212 "The mode table on the FCP adapter "
213 "has been damaged\n");
215 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
216 dev_warn(&req->adapter->ccw_device->dev,
217 "All NPIV ports on the FCP adapter have "
221 dev_warn(&req->adapter->ccw_device->dev,
222 "The link between the FCP adapter and "
223 "the FC fabric is down\n");
226 zfcp_erp_adapter_failed(adapter, id, req);
229 static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
231 struct fsf_status_read_buffer *sr_buf = req->data;
232 struct fsf_link_down_info *ldi =
233 (struct fsf_link_down_info *) &sr_buf->payload;
235 switch (sr_buf->status_subtype) {
236 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
237 zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
239 case FSF_STATUS_READ_SUB_FDISC_FAILED:
240 zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
242 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
243 zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
247 static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
249 struct zfcp_adapter *adapter = req->adapter;
250 struct fsf_status_read_buffer *sr_buf = req->data;
252 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
253 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, sr_buf);
254 mempool_free(sr_buf, adapter->pool.data_status_read);
255 zfcp_fsf_req_free(req);
259 zfcp_hba_dbf_event_fsf_unsol("read", adapter, sr_buf);
261 switch (sr_buf->status_type) {
262 case FSF_STATUS_READ_PORT_CLOSED:
263 zfcp_fsf_status_read_port_closed(req);
265 case FSF_STATUS_READ_INCOMING_ELS:
266 zfcp_fc_incoming_els(req);
268 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
270 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
271 dev_warn(&adapter->ccw_device->dev,
272 "The error threshold for checksum statistics "
273 "has been exceeded\n");
274 zfcp_hba_dbf_event_berr(adapter, req);
276 case FSF_STATUS_READ_LINK_DOWN:
277 zfcp_fsf_status_read_link_down(req);
279 case FSF_STATUS_READ_LINK_UP:
280 dev_info(&adapter->ccw_device->dev,
281 "The local link has been restored\n");
282 /* All ports should be marked as ready to run again */
283 zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
284 ZFCP_STATUS_COMMON_RUNNING,
286 zfcp_erp_adapter_reopen(adapter,
287 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
288 ZFCP_STATUS_COMMON_ERP_FAILED,
291 case FSF_STATUS_READ_NOTIFICATION_LOST:
292 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
293 zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
295 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
296 schedule_work(&adapter->scan_work);
298 case FSF_STATUS_READ_CFDC_UPDATED:
299 zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
301 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
302 adapter->adapter_features = sr_buf->payload.word[0];
306 mempool_free(sr_buf, adapter->pool.data_status_read);
307 zfcp_fsf_req_free(req);
309 atomic_inc(&adapter->stat_miss);
310 queue_work(zfcp_data.work_queue, &adapter->stat_work);
313 static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
315 switch (req->qtcb->header.fsf_status_qual.word[0]) {
316 case FSF_SQ_FCP_RSP_AVAILABLE:
317 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
318 case FSF_SQ_NO_RETRY_POSSIBLE:
319 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
321 case FSF_SQ_COMMAND_ABORTED:
322 req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
324 case FSF_SQ_NO_RECOM:
325 dev_err(&req->adapter->ccw_device->dev,
326 "The FCP adapter reported a problem "
327 "that cannot be recovered\n");
328 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
331 /* all non-return stats set FSFREQ_ERROR*/
332 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
335 static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
337 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
340 switch (req->qtcb->header.fsf_status) {
341 case FSF_UNKNOWN_COMMAND:
342 dev_err(&req->adapter->ccw_device->dev,
343 "The FCP adapter does not recognize the command 0x%x\n",
344 req->qtcb->header.fsf_command);
345 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
346 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
348 case FSF_ADAPTER_STATUS_AVAILABLE:
349 zfcp_fsf_fsfstatus_qual_eval(req);
354 static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
356 struct zfcp_adapter *adapter = req->adapter;
357 struct fsf_qtcb *qtcb = req->qtcb;
358 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
360 zfcp_hba_dbf_event_fsf_response(req);
362 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
363 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
364 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
368 switch (qtcb->prefix.prot_status) {
370 case FSF_PROT_FSF_STATUS_PRESENTED:
372 case FSF_PROT_QTCB_VERSION_ERROR:
373 dev_err(&adapter->ccw_device->dev,
374 "QTCB version 0x%x not supported by FCP adapter "
375 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
376 psq->word[0], psq->word[1]);
377 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
379 case FSF_PROT_ERROR_STATE:
380 case FSF_PROT_SEQ_NUMB_ERROR:
381 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
382 req->status |= ZFCP_STATUS_FSFREQ_RETRY;
384 case FSF_PROT_UNSUPP_QTCB_TYPE:
385 dev_err(&adapter->ccw_device->dev,
386 "The QTCB type is not supported by the FCP adapter\n");
387 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
389 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
390 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
393 case FSF_PROT_DUPLICATE_REQUEST_ID:
394 dev_err(&adapter->ccw_device->dev,
395 "0x%Lx is an ambiguous request identifier\n",
396 (unsigned long long)qtcb->bottom.support.req_handle);
397 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
399 case FSF_PROT_LINK_DOWN:
400 zfcp_fsf_link_down_info_eval(req, "fspse_5",
401 &psq->link_down_info);
402 /* FIXME: reopening adapter now? better wait for link up */
403 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
405 case FSF_PROT_REEST_QUEUE:
406 /* All ports should be marked as ready to run again */
407 zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
408 ZFCP_STATUS_COMMON_RUNNING,
410 zfcp_erp_adapter_reopen(adapter,
411 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
412 ZFCP_STATUS_COMMON_ERP_FAILED,
416 dev_err(&adapter->ccw_device->dev,
417 "0x%x is not a valid transfer protocol status\n",
418 qtcb->prefix.prot_status);
419 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
421 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
425 * zfcp_fsf_req_complete - process completion of a FSF request
426 * @fsf_req: The FSF request that has been completed.
428 * When a request has been completed either from the FCP adapter,
429 * or it has been dismissed due to a queue shutdown, this function
430 * is called to process the completion status and trigger further
431 * events related to the FSF request.
433 static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
435 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
436 zfcp_fsf_status_read_handler(req);
440 del_timer(&req->timer);
441 zfcp_fsf_protstatus_eval(req);
442 zfcp_fsf_fsfstatus_eval(req);
446 zfcp_erp_notify(req->erp_action, 0);
448 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
449 zfcp_fsf_req_free(req);
451 complete(&req->completion);
455 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
456 * @adapter: pointer to struct zfcp_adapter
458 * Never ever call this without shutting down the adapter first.
459 * Otherwise the adapter would continue using and corrupting s390 storage.
460 * Included BUG_ON() call to ensure this is done.
461 * ERP is supposed to be the only user of this function.
463 void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
465 struct zfcp_fsf_req *req, *tmp;
467 LIST_HEAD(remove_queue);
470 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
471 spin_lock_irqsave(&adapter->req_list_lock, flags);
472 for (i = 0; i < REQUEST_LIST_SIZE; i++)
473 list_splice_init(&adapter->req_list[i], &remove_queue);
474 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
476 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
477 list_del(&req->list);
478 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
479 zfcp_fsf_req_complete(req);
483 static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
485 struct fsf_qtcb_bottom_config *bottom;
486 struct zfcp_adapter *adapter = req->adapter;
487 struct Scsi_Host *shost = adapter->scsi_host;
489 bottom = &req->qtcb->bottom.config;
492 memcpy(req->data, bottom, sizeof(*bottom));
494 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
495 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
496 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
497 fc_host_speed(shost) = bottom->fc_link_speed;
498 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
500 adapter->hydra_version = bottom->adapter_type;
501 adapter->timer_ticks = bottom->timer_interval;
503 if (fc_host_permanent_port_name(shost) == -1)
504 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
506 switch (bottom->fc_topology) {
508 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
509 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
510 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
511 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
513 case FSF_TOPO_FABRIC:
514 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
517 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
520 dev_err(&adapter->ccw_device->dev,
521 "Unknown or unsupported arbitrated loop "
522 "fibre channel topology detected\n");
523 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
530 static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
532 struct zfcp_adapter *adapter = req->adapter;
533 struct fsf_qtcb *qtcb = req->qtcb;
534 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
535 struct Scsi_Host *shost = adapter->scsi_host;
537 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
540 adapter->fsf_lic_version = bottom->lic_version;
541 adapter->adapter_features = bottom->adapter_features;
542 adapter->connection_features = bottom->connection_features;
543 adapter->peer_wwpn = 0;
544 adapter->peer_wwnn = 0;
545 adapter->peer_d_id = 0;
547 switch (qtcb->header.fsf_status) {
549 if (zfcp_fsf_exchange_config_evaluate(req))
552 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
553 dev_err(&adapter->ccw_device->dev,
554 "FCP adapter maximum QTCB size (%d bytes) "
556 bottom->max_qtcb_size);
557 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
560 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
563 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
564 fc_host_node_name(shost) = 0;
565 fc_host_port_name(shost) = 0;
566 fc_host_port_id(shost) = 0;
567 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
568 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
569 adapter->hydra_version = 0;
571 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
574 zfcp_fsf_link_down_info_eval(req, "fsecdh2",
575 &qtcb->header.fsf_status_qual.link_down_info);
578 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
582 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
583 adapter->hardware_version = bottom->hardware_version;
584 memcpy(fc_host_serial_number(shost), bottom->serial_number,
585 min(FC_SERIAL_NUMBER_SIZE, 17));
586 EBCASC(fc_host_serial_number(shost),
587 min(FC_SERIAL_NUMBER_SIZE, 17));
590 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
591 dev_err(&adapter->ccw_device->dev,
592 "The FCP adapter only supports newer "
593 "control block versions\n");
594 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
597 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
598 dev_err(&adapter->ccw_device->dev,
599 "The FCP adapter only supports older "
600 "control block versions\n");
601 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
605 static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
607 struct zfcp_adapter *adapter = req->adapter;
608 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
609 struct Scsi_Host *shost = adapter->scsi_host;
612 memcpy(req->data, bottom, sizeof(*bottom));
614 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
615 fc_host_permanent_port_name(shost) = bottom->wwpn;
616 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
618 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
619 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
620 fc_host_supported_speeds(shost) = bottom->supported_speed;
623 static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
625 struct fsf_qtcb *qtcb = req->qtcb;
627 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
630 switch (qtcb->header.fsf_status) {
632 zfcp_fsf_exchange_port_evaluate(req);
634 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
635 zfcp_fsf_exchange_port_evaluate(req);
636 zfcp_fsf_link_down_info_eval(req, "fsepdh1",
637 &qtcb->header.fsf_status_qual.link_down_info);
642 static int zfcp_fsf_sbal_check(struct zfcp_adapter *adapter)
644 struct zfcp_qdio_queue *req_q = &adapter->req_q;
646 spin_lock_bh(&adapter->req_q_lock);
647 if (atomic_read(&req_q->count))
649 spin_unlock_bh(&adapter->req_q_lock);
653 static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter)
657 spin_unlock_bh(&adapter->req_q_lock);
658 ret = wait_event_interruptible_timeout(adapter->request_wq,
659 zfcp_fsf_sbal_check(adapter), 5 * HZ);
663 atomic_inc(&adapter->qdio_outb_full);
664 /* assume hanging outbound queue, try queue recovery */
665 zfcp_erp_adapter_reopen(adapter, 0, "fsrsg_1", NULL);
668 spin_lock_bh(&adapter->req_q_lock);
672 static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool)
674 struct zfcp_fsf_req *req;
675 req = mempool_alloc(pool, GFP_ATOMIC);
678 memset(req, 0, sizeof(*req));
683 static struct zfcp_fsf_req *zfcp_fsf_alloc_qtcb(mempool_t *pool)
685 struct zfcp_fsf_req_qtcb *qtcb;
688 qtcb = mempool_alloc(pool, GFP_ATOMIC);
690 qtcb = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
695 memset(qtcb, 0, sizeof(*qtcb));
696 qtcb->fsf_req.qtcb = &qtcb->qtcb;
697 qtcb->fsf_req.pool = pool;
699 return &qtcb->fsf_req;
702 static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter,
703 u32 fsf_cmd, int req_flags,
706 struct qdio_buffer_element *sbale;
708 struct zfcp_fsf_req *req;
709 struct zfcp_qdio_queue *req_q = &adapter->req_q;
711 if (req_flags & ZFCP_REQ_NO_QTCB)
712 req = zfcp_fsf_alloc_noqtcb(pool);
714 req = zfcp_fsf_alloc_qtcb(pool);
717 return ERR_PTR(-ENOMEM);
719 if (adapter->req_no == 0)
722 INIT_LIST_HEAD(&req->list);
723 init_timer(&req->timer);
724 init_completion(&req->completion);
726 req->adapter = adapter;
727 req->fsf_command = fsf_cmd;
728 req->req_id = adapter->req_no;
729 req->sbal_number = 1;
730 req->sbal_first = req_q->first;
731 req->sbal_last = req_q->first;
734 sbale = zfcp_qdio_sbale_req(req);
735 sbale[0].addr = (void *) req->req_id;
736 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
738 if (likely(req->qtcb)) {
739 req->qtcb->prefix.req_seq_no = req->adapter->fsf_req_seq_no;
740 req->qtcb->prefix.req_id = req->req_id;
741 req->qtcb->prefix.ulp_info = 26;
742 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
743 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
744 req->qtcb->header.req_handle = req->req_id;
745 req->qtcb->header.fsf_command = req->fsf_command;
746 req->seq_no = adapter->fsf_req_seq_no;
747 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
748 sbale[1].addr = (void *) req->qtcb;
749 sbale[1].length = sizeof(struct fsf_qtcb);
752 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
753 zfcp_fsf_req_free(req);
754 return ERR_PTR(-EIO);
757 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP))
758 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
763 static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
765 struct zfcp_adapter *adapter = req->adapter;
768 int with_qtcb = (req->qtcb != NULL);
770 /* put allocated FSF request into hash table */
771 spin_lock_irqsave(&adapter->req_list_lock, flags);
772 idx = zfcp_reqlist_hash(req->req_id);
773 list_add_tail(&req->list, &adapter->req_list[idx]);
774 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
776 req->qdio_outb_usage = atomic_read(&adapter->req_q.count);
777 req->issued = get_clock();
778 if (zfcp_qdio_send(req)) {
779 del_timer(&req->timer);
780 spin_lock_irqsave(&adapter->req_list_lock, flags);
781 /* lookup request again, list might have changed */
782 if (zfcp_reqlist_find_safe(adapter, req))
783 zfcp_reqlist_remove(adapter, req);
784 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
785 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
789 /* Don't increase for unsolicited status */
791 adapter->fsf_req_seq_no++;
798 * zfcp_fsf_status_read - send status read request
799 * @adapter: pointer to struct zfcp_adapter
800 * @req_flags: request flags
801 * Returns: 0 on success, ERROR otherwise
803 int zfcp_fsf_status_read(struct zfcp_adapter *adapter)
805 struct zfcp_fsf_req *req;
806 struct fsf_status_read_buffer *sr_buf;
807 struct qdio_buffer_element *sbale;
810 spin_lock_bh(&adapter->req_q_lock);
811 if (zfcp_fsf_req_sbal_get(adapter))
814 req = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
816 adapter->pool.fsf_req_status_read);
818 retval = PTR_ERR(req);
822 sbale = zfcp_qdio_sbale_req(req);
823 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
826 sr_buf = mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
831 memset(sr_buf, 0, sizeof(*sr_buf));
833 sbale = zfcp_qdio_sbale_curr(req);
834 sbale->addr = (void *) sr_buf;
835 sbale->length = sizeof(*sr_buf);
837 retval = zfcp_fsf_req_send(req);
839 goto failed_req_send;
844 mempool_free(sr_buf, adapter->pool.data_status_read);
846 zfcp_fsf_req_free(req);
847 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
849 spin_unlock_bh(&adapter->req_q_lock);
853 static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
855 struct zfcp_unit *unit = req->data;
856 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
858 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
861 switch (req->qtcb->header.fsf_status) {
862 case FSF_PORT_HANDLE_NOT_VALID:
863 if (fsq->word[0] == fsq->word[1]) {
864 zfcp_erp_adapter_reopen(unit->port->adapter, 0,
866 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
869 case FSF_LUN_HANDLE_NOT_VALID:
870 if (fsq->word[0] == fsq->word[1]) {
871 zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
872 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
875 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
876 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
879 zfcp_erp_port_boxed(unit->port, "fsafch3", req);
880 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
881 ZFCP_STATUS_FSFREQ_RETRY;
884 zfcp_erp_unit_boxed(unit, "fsafch4", req);
885 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
886 ZFCP_STATUS_FSFREQ_RETRY;
888 case FSF_ADAPTER_STATUS_AVAILABLE:
889 switch (fsq->word[0]) {
890 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
891 zfcp_test_link(unit->port);
893 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
894 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
899 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
905 * zfcp_fsf_abort_fcp_command - abort running SCSI command
906 * @old_req_id: unsigned long
907 * @unit: pointer to struct zfcp_unit
908 * Returns: pointer to struct zfcp_fsf_req
911 struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
912 struct zfcp_unit *unit)
914 struct qdio_buffer_element *sbale;
915 struct zfcp_fsf_req *req = NULL;
916 struct zfcp_adapter *adapter = unit->port->adapter;
918 spin_lock_bh(&adapter->req_q_lock);
919 if (zfcp_fsf_req_sbal_get(adapter))
921 req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
922 0, adapter->pool.fsf_req_abort);
928 if (unlikely(!(atomic_read(&unit->status) &
929 ZFCP_STATUS_COMMON_UNBLOCKED)))
932 sbale = zfcp_qdio_sbale_req(req);
933 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
934 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
937 req->handler = zfcp_fsf_abort_fcp_command_handler;
938 req->qtcb->header.lun_handle = unit->handle;
939 req->qtcb->header.port_handle = unit->port->handle;
940 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
942 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
943 if (!zfcp_fsf_req_send(req))
947 zfcp_fsf_req_free(req);
950 spin_unlock_bh(&adapter->req_q_lock);
954 static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
956 struct zfcp_adapter *adapter = req->adapter;
957 struct zfcp_send_ct *send_ct = req->data;
958 struct fsf_qtcb_header *header = &req->qtcb->header;
960 send_ct->status = -EINVAL;
962 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
965 switch (header->fsf_status) {
967 zfcp_san_dbf_event_ct_response(req);
970 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
971 zfcp_fsf_class_not_supp(req);
973 case FSF_ADAPTER_STATUS_AVAILABLE:
974 switch (header->fsf_status_qual.word[0]){
975 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
976 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
977 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
981 case FSF_ACCESS_DENIED:
984 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
985 ZFCP_STATUS_FSFREQ_RETRY;
987 case FSF_PORT_HANDLE_NOT_VALID:
988 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
990 case FSF_GENERIC_COMMAND_REJECTED:
991 case FSF_PAYLOAD_SIZE_MISMATCH:
992 case FSF_REQUEST_SIZE_TOO_LARGE:
993 case FSF_RESPONSE_SIZE_TOO_LARGE:
994 case FSF_SBAL_MISMATCH:
995 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1000 if (send_ct->handler)
1001 send_ct->handler(send_ct->handler_data);
1004 static void zfcp_fsf_setup_ct_els_unchained(struct qdio_buffer_element *sbale,
1005 struct scatterlist *sg_req,
1006 struct scatterlist *sg_resp)
1008 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1009 sbale[2].addr = sg_virt(sg_req);
1010 sbale[2].length = sg_req->length;
1011 sbale[3].addr = sg_virt(sg_resp);
1012 sbale[3].length = sg_resp->length;
1013 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1016 static int zfcp_fsf_one_sbal(struct scatterlist *sg)
1018 return sg_is_last(sg) && sg->length <= PAGE_SIZE;
1021 static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
1022 struct scatterlist *sg_req,
1023 struct scatterlist *sg_resp,
1026 struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(req);
1027 u32 feat = req->adapter->adapter_features;
1030 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
1031 if (!zfcp_fsf_one_sbal(sg_req) || !zfcp_fsf_one_sbal(sg_resp))
1034 zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
1038 /* use single, unchained SBAL if it can hold the request */
1039 if (zfcp_fsf_one_sbal(sg_req) && zfcp_fsf_one_sbal(sg_resp)) {
1040 zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
1044 bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
1048 req->qtcb->bottom.support.req_buf_length = bytes;
1049 req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1051 bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
1052 sg_resp, max_sbals);
1055 req->qtcb->bottom.support.resp_buf_length = bytes;
1061 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
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 * @erp_action: if non-null the Generic Service request sent within ERP
1066 int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1067 struct zfcp_erp_action *erp_action)
1069 struct zfcp_wka_port *wka_port = ct->wka_port;
1070 struct zfcp_adapter *adapter = wka_port->adapter;
1071 struct zfcp_fsf_req *req;
1074 spin_lock_bh(&adapter->req_q_lock);
1075 if (zfcp_fsf_req_sbal_get(adapter))
1078 req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1079 ZFCP_REQ_AUTO_CLEANUP, pool);
1085 ret = zfcp_fsf_setup_ct_els_sbals(req, ct->req, ct->resp,
1086 FSF_MAX_SBALS_PER_REQ);
1090 req->handler = zfcp_fsf_send_ct_handler;
1091 req->qtcb->header.port_handle = wka_port->handle;
1092 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
1093 req->qtcb->bottom.support.timeout = ct->timeout;
1096 zfcp_san_dbf_event_ct_request(req);
1099 erp_action->fsf_req = req;
1100 req->erp_action = erp_action;
1101 zfcp_fsf_start_erp_timer(req);
1103 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1105 ret = zfcp_fsf_req_send(req);
1112 zfcp_fsf_req_free(req);
1114 erp_action->fsf_req = NULL;
1116 spin_unlock_bh(&adapter->req_q_lock);
1120 static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1122 struct zfcp_send_els *send_els = req->data;
1123 struct zfcp_port *port = send_els->port;
1124 struct fsf_qtcb_header *header = &req->qtcb->header;
1126 send_els->status = -EINVAL;
1128 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1129 goto skip_fsfstatus;
1131 switch (header->fsf_status) {
1133 zfcp_san_dbf_event_els_response(req);
1134 send_els->status = 0;
1136 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1137 zfcp_fsf_class_not_supp(req);
1139 case FSF_ADAPTER_STATUS_AVAILABLE:
1140 switch (header->fsf_status_qual.word[0]){
1141 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1142 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1143 zfcp_test_link(port);
1145 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1146 case FSF_SQ_RETRY_IF_POSSIBLE:
1147 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1151 case FSF_ELS_COMMAND_REJECTED:
1152 case FSF_PAYLOAD_SIZE_MISMATCH:
1153 case FSF_REQUEST_SIZE_TOO_LARGE:
1154 case FSF_RESPONSE_SIZE_TOO_LARGE:
1156 case FSF_ACCESS_DENIED:
1158 zfcp_fsf_access_denied_port(req, port);
1160 case FSF_SBAL_MISMATCH:
1161 /* should never occure, avoided in zfcp_fsf_send_els */
1164 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1168 if (send_els->handler)
1169 send_els->handler(send_els->handler_data);
1173 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1174 * @els: pointer to struct zfcp_send_els with data for the command
1176 int zfcp_fsf_send_els(struct zfcp_send_els *els)
1178 struct zfcp_fsf_req *req;
1179 struct zfcp_adapter *adapter = els->adapter;
1180 struct fsf_qtcb_bottom_support *bottom;
1183 spin_lock_bh(&adapter->req_q_lock);
1184 if (zfcp_fsf_req_sbal_get(adapter))
1186 req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1187 ZFCP_REQ_AUTO_CLEANUP, NULL);
1193 ret = zfcp_fsf_setup_ct_els_sbals(req, els->req, els->resp, 2);
1198 bottom = &req->qtcb->bottom.support;
1199 req->handler = zfcp_fsf_send_els_handler;
1200 bottom->d_id = els->d_id;
1201 bottom->service_class = FSF_CLASS_3;
1202 bottom->timeout = 2 * R_A_TOV;
1205 zfcp_san_dbf_event_els_request(req);
1207 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1208 ret = zfcp_fsf_req_send(req);
1215 zfcp_fsf_req_free(req);
1217 spin_unlock_bh(&adapter->req_q_lock);
1221 int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1223 struct qdio_buffer_element *sbale;
1224 struct zfcp_fsf_req *req;
1225 struct zfcp_adapter *adapter = erp_action->adapter;
1228 spin_lock_bh(&adapter->req_q_lock);
1229 if (zfcp_fsf_req_sbal_get(adapter))
1231 req = zfcp_fsf_req_create(adapter,
1232 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1233 ZFCP_REQ_AUTO_CLEANUP,
1234 adapter->pool.fsf_req_erp);
1236 retval = PTR_ERR(req);
1240 sbale = zfcp_qdio_sbale_req(req);
1241 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1242 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1244 req->qtcb->bottom.config.feature_selection =
1246 FSF_FEATURE_LUN_SHARING |
1247 FSF_FEATURE_NOTIFICATION_LOST |
1248 FSF_FEATURE_UPDATE_ALERT;
1249 req->erp_action = erp_action;
1250 req->handler = zfcp_fsf_exchange_config_data_handler;
1251 erp_action->fsf_req = req;
1253 zfcp_fsf_start_erp_timer(req);
1254 retval = zfcp_fsf_req_send(req);
1256 zfcp_fsf_req_free(req);
1257 erp_action->fsf_req = NULL;
1260 spin_unlock_bh(&adapter->req_q_lock);
1264 int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
1265 struct fsf_qtcb_bottom_config *data)
1267 struct qdio_buffer_element *sbale;
1268 struct zfcp_fsf_req *req = NULL;
1271 spin_lock_bh(&adapter->req_q_lock);
1272 if (zfcp_fsf_req_sbal_get(adapter))
1275 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1278 retval = PTR_ERR(req);
1282 sbale = zfcp_qdio_sbale_req(req);
1283 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1284 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1285 req->handler = zfcp_fsf_exchange_config_data_handler;
1287 req->qtcb->bottom.config.feature_selection =
1289 FSF_FEATURE_LUN_SHARING |
1290 FSF_FEATURE_NOTIFICATION_LOST |
1291 FSF_FEATURE_UPDATE_ALERT;
1296 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1297 retval = zfcp_fsf_req_send(req);
1298 spin_unlock_bh(&adapter->req_q_lock);
1300 wait_for_completion(&req->completion);
1302 zfcp_fsf_req_free(req);
1306 spin_unlock_bh(&adapter->req_q_lock);
1311 * zfcp_fsf_exchange_port_data - request information about local port
1312 * @erp_action: ERP action for the adapter for which port data is requested
1313 * Returns: 0 on success, error otherwise
1315 int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1317 struct qdio_buffer_element *sbale;
1318 struct zfcp_fsf_req *req;
1319 struct zfcp_adapter *adapter = erp_action->adapter;
1322 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1325 spin_lock_bh(&adapter->req_q_lock);
1326 if (zfcp_fsf_req_sbal_get(adapter))
1328 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
1329 ZFCP_REQ_AUTO_CLEANUP,
1330 adapter->pool.fsf_req_erp);
1332 retval = PTR_ERR(req);
1336 sbale = zfcp_qdio_sbale_req(req);
1337 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1338 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1340 req->handler = zfcp_fsf_exchange_port_data_handler;
1341 req->erp_action = erp_action;
1342 erp_action->fsf_req = req;
1344 zfcp_fsf_start_erp_timer(req);
1345 retval = zfcp_fsf_req_send(req);
1347 zfcp_fsf_req_free(req);
1348 erp_action->fsf_req = NULL;
1351 spin_unlock_bh(&adapter->req_q_lock);
1356 * zfcp_fsf_exchange_port_data_sync - request information about local port
1357 * @adapter: pointer to struct zfcp_adapter
1358 * @data: pointer to struct fsf_qtcb_bottom_port
1359 * Returns: 0 on success, error otherwise
1361 int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
1362 struct fsf_qtcb_bottom_port *data)
1364 struct qdio_buffer_element *sbale;
1365 struct zfcp_fsf_req *req = NULL;
1368 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1371 spin_lock_bh(&adapter->req_q_lock);
1372 if (zfcp_fsf_req_sbal_get(adapter))
1375 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0,
1378 retval = PTR_ERR(req);
1385 sbale = zfcp_qdio_sbale_req(req);
1386 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1387 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1389 req->handler = zfcp_fsf_exchange_port_data_handler;
1390 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1391 retval = zfcp_fsf_req_send(req);
1392 spin_unlock_bh(&adapter->req_q_lock);
1395 wait_for_completion(&req->completion);
1397 zfcp_fsf_req_free(req);
1402 spin_unlock_bh(&adapter->req_q_lock);
1406 static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1408 struct zfcp_port *port = req->data;
1409 struct fsf_qtcb_header *header = &req->qtcb->header;
1410 struct fsf_plogi *plogi;
1412 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1415 switch (header->fsf_status) {
1416 case FSF_PORT_ALREADY_OPEN:
1418 case FSF_ACCESS_DENIED:
1419 zfcp_fsf_access_denied_port(req, port);
1421 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1422 dev_warn(&req->adapter->ccw_device->dev,
1423 "Not enough FCP adapter resources to open "
1424 "remote port 0x%016Lx\n",
1425 (unsigned long long)port->wwpn);
1426 zfcp_erp_port_failed(port, "fsoph_1", req);
1427 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1429 case FSF_ADAPTER_STATUS_AVAILABLE:
1430 switch (header->fsf_status_qual.word[0]) {
1431 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1432 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1433 case FSF_SQ_NO_RETRY_POSSIBLE:
1434 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1439 port->handle = header->port_handle;
1440 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1441 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1442 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1443 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1445 /* check whether D_ID has changed during open */
1447 * FIXME: This check is not airtight, as the FCP channel does
1448 * not monitor closures of target port connections caused on
1449 * the remote side. Thus, they might miss out on invalidating
1450 * locally cached WWPNs (and other N_Port parameters) of gone
1451 * target ports. So, our heroic attempt to make things safe
1452 * could be undermined by 'open port' response data tagged with
1453 * obsolete WWPNs. Another reason to monitor potential
1454 * connection closures ourself at least (by interpreting
1455 * incoming ELS' and unsolicited status). It just crosses my
1456 * mind that one should be able to cross-check by means of
1457 * another GID_PN straight after a port has been opened.
1458 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1460 plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
1461 if (req->qtcb->bottom.support.els1_length >=
1462 FSF_PLOGI_MIN_LEN) {
1463 if (plogi->serv_param.wwpn != port->wwpn)
1466 port->wwnn = plogi->serv_param.wwnn;
1467 zfcp_fc_plogi_evaluate(port, plogi);
1471 case FSF_UNKNOWN_OP_SUBTYPE:
1472 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1477 zfcp_port_put(port);
1481 * zfcp_fsf_open_port - create and send open port request
1482 * @erp_action: pointer to struct zfcp_erp_action
1483 * Returns: 0 on success, error otherwise
1485 int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
1487 struct qdio_buffer_element *sbale;
1488 struct zfcp_adapter *adapter = erp_action->adapter;
1489 struct zfcp_fsf_req *req;
1490 struct zfcp_port *port = erp_action->port;
1493 spin_lock_bh(&adapter->req_q_lock);
1494 if (zfcp_fsf_req_sbal_get(adapter))
1497 req = zfcp_fsf_req_create(adapter,
1498 FSF_QTCB_OPEN_PORT_WITH_DID,
1499 ZFCP_REQ_AUTO_CLEANUP,
1500 adapter->pool.fsf_req_erp);
1502 retval = PTR_ERR(req);
1506 sbale = zfcp_qdio_sbale_req(req);
1507 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1508 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1510 req->handler = zfcp_fsf_open_port_handler;
1511 req->qtcb->bottom.support.d_id = port->d_id;
1513 req->erp_action = erp_action;
1514 erp_action->fsf_req = req;
1515 zfcp_port_get(port);
1517 zfcp_fsf_start_erp_timer(req);
1518 retval = zfcp_fsf_req_send(req);
1520 zfcp_fsf_req_free(req);
1521 erp_action->fsf_req = NULL;
1522 zfcp_port_put(port);
1525 spin_unlock_bh(&adapter->req_q_lock);
1529 static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
1531 struct zfcp_port *port = req->data;
1533 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1536 switch (req->qtcb->header.fsf_status) {
1537 case FSF_PORT_HANDLE_NOT_VALID:
1538 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
1539 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1541 case FSF_ADAPTER_STATUS_AVAILABLE:
1544 zfcp_erp_modify_port_status(port, "fscph_2", req,
1545 ZFCP_STATUS_COMMON_OPEN,
1552 * zfcp_fsf_close_port - create and send close port request
1553 * @erp_action: pointer to struct zfcp_erp_action
1554 * Returns: 0 on success, error otherwise
1556 int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
1558 struct qdio_buffer_element *sbale;
1559 struct zfcp_adapter *adapter = erp_action->adapter;
1560 struct zfcp_fsf_req *req;
1563 spin_lock_bh(&adapter->req_q_lock);
1564 if (zfcp_fsf_req_sbal_get(adapter))
1567 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
1568 ZFCP_REQ_AUTO_CLEANUP,
1569 adapter->pool.fsf_req_erp);
1571 retval = PTR_ERR(req);
1575 sbale = zfcp_qdio_sbale_req(req);
1576 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1577 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1579 req->handler = zfcp_fsf_close_port_handler;
1580 req->data = erp_action->port;
1581 req->erp_action = erp_action;
1582 req->qtcb->header.port_handle = erp_action->port->handle;
1583 erp_action->fsf_req = req;
1585 zfcp_fsf_start_erp_timer(req);
1586 retval = zfcp_fsf_req_send(req);
1588 zfcp_fsf_req_free(req);
1589 erp_action->fsf_req = NULL;
1592 spin_unlock_bh(&adapter->req_q_lock);
1596 static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1598 struct zfcp_wka_port *wka_port = req->data;
1599 struct fsf_qtcb_header *header = &req->qtcb->header;
1601 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1602 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
1606 switch (header->fsf_status) {
1607 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1608 dev_warn(&req->adapter->ccw_device->dev,
1609 "Opening WKA port 0x%x failed\n", wka_port->d_id);
1611 case FSF_ADAPTER_STATUS_AVAILABLE:
1612 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1614 case FSF_ACCESS_DENIED:
1615 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
1618 wka_port->handle = header->port_handle;
1620 case FSF_PORT_ALREADY_OPEN:
1621 wka_port->status = ZFCP_WKA_PORT_ONLINE;
1624 wake_up(&wka_port->completion_wq);
1628 * zfcp_fsf_open_wka_port - create and send open wka-port request
1629 * @wka_port: pointer to struct zfcp_wka_port
1630 * Returns: 0 on success, error otherwise
1632 int zfcp_fsf_open_wka_port(struct zfcp_wka_port *wka_port)
1634 struct qdio_buffer_element *sbale;
1635 struct zfcp_adapter *adapter = wka_port->adapter;
1636 struct zfcp_fsf_req *req;
1639 spin_lock_bh(&adapter->req_q_lock);
1640 if (zfcp_fsf_req_sbal_get(adapter))
1643 req = zfcp_fsf_req_create(adapter,
1644 FSF_QTCB_OPEN_PORT_WITH_DID,
1645 ZFCP_REQ_AUTO_CLEANUP,
1646 adapter->pool.fsf_req_erp);
1647 if (unlikely(IS_ERR(req))) {
1648 retval = PTR_ERR(req);
1652 sbale = zfcp_qdio_sbale_req(req);
1653 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1654 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1656 req->handler = zfcp_fsf_open_wka_port_handler;
1657 req->qtcb->bottom.support.d_id = wka_port->d_id;
1658 req->data = wka_port;
1660 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1661 retval = zfcp_fsf_req_send(req);
1663 zfcp_fsf_req_free(req);
1665 spin_unlock_bh(&adapter->req_q_lock);
1669 static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1671 struct zfcp_wka_port *wka_port = req->data;
1673 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1674 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1675 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
1678 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
1679 wake_up(&wka_port->completion_wq);
1683 * zfcp_fsf_close_wka_port - create and send close wka port request
1684 * @erp_action: pointer to struct zfcp_erp_action
1685 * Returns: 0 on success, error otherwise
1687 int zfcp_fsf_close_wka_port(struct zfcp_wka_port *wka_port)
1689 struct qdio_buffer_element *sbale;
1690 struct zfcp_adapter *adapter = wka_port->adapter;
1691 struct zfcp_fsf_req *req;
1694 spin_lock_bh(&adapter->req_q_lock);
1695 if (zfcp_fsf_req_sbal_get(adapter))
1698 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
1699 ZFCP_REQ_AUTO_CLEANUP,
1700 adapter->pool.fsf_req_erp);
1701 if (unlikely(IS_ERR(req))) {
1702 retval = PTR_ERR(req);
1706 sbale = zfcp_qdio_sbale_req(req);
1707 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1708 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1710 req->handler = zfcp_fsf_close_wka_port_handler;
1711 req->data = wka_port;
1712 req->qtcb->header.port_handle = wka_port->handle;
1714 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1715 retval = zfcp_fsf_req_send(req);
1717 zfcp_fsf_req_free(req);
1719 spin_unlock_bh(&adapter->req_q_lock);
1723 static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
1725 struct zfcp_port *port = req->data;
1726 struct fsf_qtcb_header *header = &req->qtcb->header;
1727 struct zfcp_unit *unit;
1729 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1732 switch (header->fsf_status) {
1733 case FSF_PORT_HANDLE_NOT_VALID:
1734 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
1735 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1737 case FSF_ACCESS_DENIED:
1738 zfcp_fsf_access_denied_port(req, port);
1740 case FSF_PORT_BOXED:
1741 /* can't use generic zfcp_erp_modify_port_status because
1742 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1743 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1744 list_for_each_entry(unit, &port->unit_list_head, list)
1745 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1747 zfcp_erp_port_boxed(port, "fscpph2", req);
1748 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1749 ZFCP_STATUS_FSFREQ_RETRY;
1752 case FSF_ADAPTER_STATUS_AVAILABLE:
1753 switch (header->fsf_status_qual.word[0]) {
1754 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1756 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1757 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1762 /* can't use generic zfcp_erp_modify_port_status because
1763 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1765 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1766 list_for_each_entry(unit, &port->unit_list_head, list)
1767 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1774 * zfcp_fsf_close_physical_port - close physical port
1775 * @erp_action: pointer to struct zfcp_erp_action
1776 * Returns: 0 on success
1778 int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
1780 struct qdio_buffer_element *sbale;
1781 struct zfcp_adapter *adapter = erp_action->adapter;
1782 struct zfcp_fsf_req *req;
1785 spin_lock_bh(&adapter->req_q_lock);
1786 if (zfcp_fsf_req_sbal_get(adapter))
1789 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT,
1790 ZFCP_REQ_AUTO_CLEANUP,
1791 adapter->pool.fsf_req_erp);
1793 retval = PTR_ERR(req);
1797 sbale = zfcp_qdio_sbale_req(req);
1798 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1799 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1801 req->data = erp_action->port;
1802 req->qtcb->header.port_handle = erp_action->port->handle;
1803 req->erp_action = erp_action;
1804 req->handler = zfcp_fsf_close_physical_port_handler;
1805 erp_action->fsf_req = req;
1807 zfcp_fsf_start_erp_timer(req);
1808 retval = zfcp_fsf_req_send(req);
1810 zfcp_fsf_req_free(req);
1811 erp_action->fsf_req = NULL;
1814 spin_unlock_bh(&adapter->req_q_lock);
1818 static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
1820 struct zfcp_adapter *adapter = req->adapter;
1821 struct zfcp_unit *unit = req->data;
1822 struct fsf_qtcb_header *header = &req->qtcb->header;
1823 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1824 struct fsf_queue_designator *queue_designator =
1825 &header->fsf_status_qual.fsf_queue_designator;
1826 int exclusive, readwrite;
1828 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1831 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1832 ZFCP_STATUS_COMMON_ACCESS_BOXED |
1833 ZFCP_STATUS_UNIT_SHARED |
1834 ZFCP_STATUS_UNIT_READONLY,
1837 switch (header->fsf_status) {
1839 case FSF_PORT_HANDLE_NOT_VALID:
1840 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
1842 case FSF_LUN_ALREADY_OPEN:
1844 case FSF_ACCESS_DENIED:
1845 zfcp_fsf_access_denied_unit(req, unit);
1846 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1847 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1849 case FSF_PORT_BOXED:
1850 zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
1851 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1852 ZFCP_STATUS_FSFREQ_RETRY;
1854 case FSF_LUN_SHARING_VIOLATION:
1855 if (header->fsf_status_qual.word[0])
1856 dev_warn(&adapter->ccw_device->dev,
1857 "LUN 0x%Lx on port 0x%Lx is already in "
1858 "use by CSS%d, MIF Image ID %x\n",
1859 (unsigned long long)unit->fcp_lun,
1860 (unsigned long long)unit->port->wwpn,
1861 queue_designator->cssid,
1862 queue_designator->hla);
1864 zfcp_act_eval_err(adapter,
1865 header->fsf_status_qual.word[2]);
1866 zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
1867 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1868 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1869 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1871 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
1872 dev_warn(&adapter->ccw_device->dev,
1873 "No handle is available for LUN "
1874 "0x%016Lx on port 0x%016Lx\n",
1875 (unsigned long long)unit->fcp_lun,
1876 (unsigned long long)unit->port->wwpn);
1877 zfcp_erp_unit_failed(unit, "fsouh_4", req);
1879 case FSF_INVALID_COMMAND_OPTION:
1880 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1882 case FSF_ADAPTER_STATUS_AVAILABLE:
1883 switch (header->fsf_status_qual.word[0]) {
1884 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1885 zfcp_test_link(unit->port);
1887 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1888 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1894 unit->handle = header->lun_handle;
1895 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1897 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1898 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
1899 !zfcp_ccw_priv_sch(adapter)) {
1900 exclusive = (bottom->lun_access_info &
1901 FSF_UNIT_ACCESS_EXCLUSIVE);
1902 readwrite = (bottom->lun_access_info &
1903 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1906 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1910 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1912 dev_info(&adapter->ccw_device->dev,
1913 "SCSI device at LUN 0x%016Lx on port "
1914 "0x%016Lx opened read-only\n",
1915 (unsigned long long)unit->fcp_lun,
1916 (unsigned long long)unit->port->wwpn);
1919 if (exclusive && !readwrite) {
1920 dev_err(&adapter->ccw_device->dev,
1921 "Exclusive read-only access not "
1922 "supported (unit 0x%016Lx, "
1924 (unsigned long long)unit->fcp_lun,
1925 (unsigned long long)unit->port->wwpn);
1926 zfcp_erp_unit_failed(unit, "fsouh_5", req);
1927 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1928 zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
1929 } else if (!exclusive && readwrite) {
1930 dev_err(&adapter->ccw_device->dev,
1931 "Shared read-write access not "
1932 "supported (unit 0x%016Lx, port "
1934 (unsigned long long)unit->fcp_lun,
1935 (unsigned long long)unit->port->wwpn);
1936 zfcp_erp_unit_failed(unit, "fsouh_7", req);
1937 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1938 zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
1946 * zfcp_fsf_open_unit - open unit
1947 * @erp_action: pointer to struct zfcp_erp_action
1948 * Returns: 0 on success, error otherwise
1950 int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
1952 struct qdio_buffer_element *sbale;
1953 struct zfcp_adapter *adapter = erp_action->adapter;
1954 struct zfcp_fsf_req *req;
1957 spin_lock_bh(&adapter->req_q_lock);
1958 if (zfcp_fsf_req_sbal_get(adapter))
1961 req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN,
1962 ZFCP_REQ_AUTO_CLEANUP,
1963 adapter->pool.fsf_req_erp);
1965 retval = PTR_ERR(req);
1969 sbale = zfcp_qdio_sbale_req(req);
1970 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1971 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1973 req->qtcb->header.port_handle = erp_action->port->handle;
1974 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1975 req->handler = zfcp_fsf_open_unit_handler;
1976 req->data = erp_action->unit;
1977 req->erp_action = erp_action;
1978 erp_action->fsf_req = req;
1980 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1981 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
1983 zfcp_fsf_start_erp_timer(req);
1984 retval = zfcp_fsf_req_send(req);
1986 zfcp_fsf_req_free(req);
1987 erp_action->fsf_req = NULL;
1990 spin_unlock_bh(&adapter->req_q_lock);
1994 static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
1996 struct zfcp_unit *unit = req->data;
1998 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2001 switch (req->qtcb->header.fsf_status) {
2002 case FSF_PORT_HANDLE_NOT_VALID:
2003 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
2004 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2006 case FSF_LUN_HANDLE_NOT_VALID:
2007 zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
2008 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2010 case FSF_PORT_BOXED:
2011 zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
2012 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2013 ZFCP_STATUS_FSFREQ_RETRY;
2015 case FSF_ADAPTER_STATUS_AVAILABLE:
2016 switch (req->qtcb->header.fsf_status_qual.word[0]) {
2017 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2018 zfcp_test_link(unit->port);
2020 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2021 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2026 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2032 * zfcp_fsf_close_unit - close zfcp unit
2033 * @erp_action: pointer to struct zfcp_unit
2034 * Returns: 0 on success, error otherwise
2036 int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
2038 struct qdio_buffer_element *sbale;
2039 struct zfcp_adapter *adapter = erp_action->adapter;
2040 struct zfcp_fsf_req *req;
2043 spin_lock_bh(&adapter->req_q_lock);
2044 if (zfcp_fsf_req_sbal_get(adapter))
2046 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN,
2047 ZFCP_REQ_AUTO_CLEANUP,
2048 adapter->pool.fsf_req_erp);
2050 retval = PTR_ERR(req);
2054 sbale = zfcp_qdio_sbale_req(req);
2055 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2056 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2058 req->qtcb->header.port_handle = erp_action->port->handle;
2059 req->qtcb->header.lun_handle = erp_action->unit->handle;
2060 req->handler = zfcp_fsf_close_unit_handler;
2061 req->data = erp_action->unit;
2062 req->erp_action = erp_action;
2063 erp_action->fsf_req = req;
2065 zfcp_fsf_start_erp_timer(req);
2066 retval = zfcp_fsf_req_send(req);
2068 zfcp_fsf_req_free(req);
2069 erp_action->fsf_req = NULL;
2072 spin_unlock_bh(&adapter->req_q_lock);
2076 static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2078 lat_rec->sum += lat;
2079 lat_rec->min = min(lat_rec->min, lat);
2080 lat_rec->max = max(lat_rec->max, lat);
2083 static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
2085 struct fsf_qual_latency_info *lat_inf;
2086 struct latency_cont *lat;
2087 struct zfcp_unit *unit = req->unit;
2089 lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
2091 switch (req->qtcb->bottom.io.data_direction) {
2092 case FSF_DATADIR_READ:
2093 lat = &unit->latencies.read;
2095 case FSF_DATADIR_WRITE:
2096 lat = &unit->latencies.write;
2098 case FSF_DATADIR_CMND:
2099 lat = &unit->latencies.cmd;
2105 spin_lock(&unit->latencies.lock);
2106 zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
2107 zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
2109 spin_unlock(&unit->latencies.lock);
2112 #ifdef CONFIG_BLK_DEV_IO_TRACE
2113 static void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
2115 struct fsf_qual_latency_info *lat_inf;
2116 struct scsi_cmnd *scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
2117 struct request *req = scsi_cmnd->request;
2118 struct zfcp_blk_drv_data trace;
2119 int ticks = fsf_req->adapter->timer_ticks;
2122 trace.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2123 if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
2124 trace.flags |= ZFCP_BLK_LAT_VALID;
2125 lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info;
2126 trace.channel_lat = lat_inf->channel_lat * ticks;
2127 trace.fabric_lat = lat_inf->fabric_lat * ticks;
2129 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2130 trace.flags |= ZFCP_BLK_REQ_ERROR;
2131 trace.inb_usage = fsf_req->qdio_inb_usage;
2132 trace.outb_usage = fsf_req->qdio_outb_usage;
2134 blk_add_driver_data(req->q, req, &trace, sizeof(trace));
2137 static inline void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
2142 static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
2144 struct scsi_cmnd *scpnt;
2145 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
2146 &(req->qtcb->bottom.io.fcp_rsp);
2148 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
2149 unsigned long flags;
2151 read_lock_irqsave(&req->adapter->abort_lock, flags);
2154 if (unlikely(!scpnt)) {
2155 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2159 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
2160 set_host_byte(scpnt, DID_SOFT_ERROR);
2161 goto skip_fsfstatus;
2164 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2165 set_host_byte(scpnt, DID_ERROR);
2166 goto skip_fsfstatus;
2169 set_msg_byte(scpnt, COMMAND_COMPLETE);
2171 scpnt->result |= fcp_rsp_iu->scsi_status;
2173 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
2174 zfcp_fsf_req_latency(req);
2176 zfcp_fsf_trace_latency(req);
2178 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
2179 if (fcp_rsp_info[3] == RSP_CODE_GOOD)
2180 set_host_byte(scpnt, DID_OK);
2182 set_host_byte(scpnt, DID_ERROR);
2183 goto skip_fsfstatus;
2187 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
2188 sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
2189 fcp_rsp_iu->fcp_rsp_len;
2190 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
2191 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
2193 memcpy(scpnt->sense_buffer,
2194 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
2197 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
2198 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
2199 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
2201 set_host_byte(scpnt, DID_ERROR);
2204 if (scpnt->result != 0)
2205 zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
2206 else if (scpnt->retries > 0)
2207 zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
2209 zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
2211 scpnt->host_scribble = NULL;
2212 (scpnt->scsi_done) (scpnt);
2214 * We must hold this lock until scsi_done has been called.
2215 * Otherwise we may call scsi_done after abort regarding this
2216 * command has completed.
2217 * Note: scsi_done must not block!
2219 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2222 static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
2224 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
2225 &(req->qtcb->bottom.io.fcp_rsp);
2226 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
2228 if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
2229 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2230 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
2234 static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2236 struct zfcp_unit *unit;
2237 struct fsf_qtcb_header *header = &req->qtcb->header;
2239 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2244 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2245 goto skip_fsfstatus;
2247 switch (header->fsf_status) {
2248 case FSF_HANDLE_MISMATCH:
2249 case FSF_PORT_HANDLE_NOT_VALID:
2250 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
2251 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2253 case FSF_FCPLUN_NOT_VALID:
2254 case FSF_LUN_HANDLE_NOT_VALID:
2255 zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
2256 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2258 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2259 zfcp_fsf_class_not_supp(req);
2261 case FSF_ACCESS_DENIED:
2262 zfcp_fsf_access_denied_unit(req, unit);
2264 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2265 dev_err(&req->adapter->ccw_device->dev,
2266 "Incorrect direction %d, unit 0x%016Lx on port "
2267 "0x%016Lx closed\n",
2268 req->qtcb->bottom.io.data_direction,
2269 (unsigned long long)unit->fcp_lun,
2270 (unsigned long long)unit->port->wwpn);
2271 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
2273 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2275 case FSF_CMND_LENGTH_NOT_VALID:
2276 dev_err(&req->adapter->ccw_device->dev,
2277 "Incorrect CDB length %d, unit 0x%016Lx on "
2278 "port 0x%016Lx closed\n",
2279 req->qtcb->bottom.io.fcp_cmnd_length,
2280 (unsigned long long)unit->fcp_lun,
2281 (unsigned long long)unit->port->wwpn);
2282 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
2284 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2286 case FSF_PORT_BOXED:
2287 zfcp_erp_port_boxed(unit->port, "fssfch5", req);
2288 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2289 ZFCP_STATUS_FSFREQ_RETRY;
2292 zfcp_erp_unit_boxed(unit, "fssfch6", req);
2293 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2294 ZFCP_STATUS_FSFREQ_RETRY;
2296 case FSF_ADAPTER_STATUS_AVAILABLE:
2297 if (header->fsf_status_qual.word[0] ==
2298 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
2299 zfcp_test_link(unit->port);
2300 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2304 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2305 zfcp_fsf_send_fcp_ctm_handler(req);
2307 zfcp_fsf_send_fcp_command_task_handler(req);
2309 zfcp_unit_put(unit);
2313 static void zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, u32 fcp_dl)
2318 * fcp_dl_addr = start address of fcp_cmnd structure +
2319 * size of fixed part + size of dynamically sized add_dcp_cdb field
2320 * SEE FCP-2 documentation
2322 fcp_dl_ptr = (u32 *) ((unsigned char *) &fcp_cmd[1] +
2323 (fcp_cmd->add_fcp_cdb_length << 2));
2324 *fcp_dl_ptr = fcp_dl;
2328 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
2329 * @unit: unit where command is sent to
2330 * @scsi_cmnd: scsi command to be sent
2332 int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2333 struct scsi_cmnd *scsi_cmnd)
2335 struct zfcp_fsf_req *req;
2336 struct fcp_cmnd_iu *fcp_cmnd_iu;
2337 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
2338 int real_bytes, retval = -EIO;
2339 struct zfcp_adapter *adapter = unit->port->adapter;
2341 if (unlikely(!(atomic_read(&unit->status) &
2342 ZFCP_STATUS_COMMON_UNBLOCKED)))
2345 spin_lock(&adapter->req_q_lock);
2346 if (atomic_read(&adapter->req_q.count) <= 0) {
2347 atomic_inc(&adapter->qdio_outb_full);
2350 req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND,
2351 ZFCP_REQ_AUTO_CLEANUP,
2352 adapter->pool.fsf_req_scsi);
2354 retval = PTR_ERR(req);
2358 zfcp_unit_get(unit);
2360 req->data = scsi_cmnd;
2361 req->handler = zfcp_fsf_send_fcp_command_handler;
2362 req->qtcb->header.lun_handle = unit->handle;
2363 req->qtcb->header.port_handle = unit->port->handle;
2364 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2366 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2368 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
2369 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2371 * set depending on data direction:
2372 * data direction bits in SBALE (SB Type)
2373 * data direction bits in QTCB
2374 * data direction bits in FCP_CMND IU
2376 switch (scsi_cmnd->sc_data_direction) {
2378 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2380 case DMA_FROM_DEVICE:
2381 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
2382 fcp_cmnd_iu->rddata = 1;
2385 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
2386 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2387 fcp_cmnd_iu->wddata = 1;
2389 case DMA_BIDIRECTIONAL:
2390 goto failed_scsi_cmnd;
2393 if (likely((scsi_cmnd->device->simple_tags) ||
2394 ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
2395 (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
2396 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
2398 fcp_cmnd_iu->task_attribute = UNTAGGED;
2400 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
2401 fcp_cmnd_iu->add_fcp_cdb_length =
2402 (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
2404 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
2406 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
2407 fcp_cmnd_iu->add_fcp_cdb_length + sizeof(u32);
2409 real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype,
2410 scsi_sglist(scsi_cmnd),
2411 FSF_MAX_SBALS_PER_REQ);
2412 if (unlikely(real_bytes < 0)) {
2413 if (req->sbal_number >= FSF_MAX_SBALS_PER_REQ) {
2414 dev_err(&adapter->ccw_device->dev,
2415 "Oversize data package, unit 0x%016Lx "
2416 "on port 0x%016Lx closed\n",
2417 (unsigned long long)unit->fcp_lun,
2418 (unsigned long long)unit->port->wwpn);
2419 zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
2422 goto failed_scsi_cmnd;
2425 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
2427 retval = zfcp_fsf_req_send(req);
2428 if (unlikely(retval))
2429 goto failed_scsi_cmnd;
2434 zfcp_unit_put(unit);
2435 zfcp_fsf_req_free(req);
2436 scsi_cmnd->host_scribble = NULL;
2438 spin_unlock(&adapter->req_q_lock);
2443 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
2444 * @unit: pointer to struct zfcp_unit
2445 * @tm_flags: unsigned byte for task management flags
2446 * Returns: on success pointer to struct fsf_req, NULL otherwise
2448 struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
2450 struct qdio_buffer_element *sbale;
2451 struct zfcp_fsf_req *req = NULL;
2452 struct fcp_cmnd_iu *fcp_cmnd_iu;
2453 struct zfcp_adapter *adapter = unit->port->adapter;
2455 if (unlikely(!(atomic_read(&unit->status) &
2456 ZFCP_STATUS_COMMON_UNBLOCKED)))
2459 spin_lock_bh(&adapter->req_q_lock);
2460 if (zfcp_fsf_req_sbal_get(adapter))
2462 req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, 0,
2463 adapter->pool.fsf_req_scsi);
2469 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2471 req->handler = zfcp_fsf_send_fcp_command_handler;
2472 req->qtcb->header.lun_handle = unit->handle;
2473 req->qtcb->header.port_handle = unit->port->handle;
2474 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2475 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2476 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
2479 sbale = zfcp_qdio_sbale_req(req);
2480 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
2481 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2483 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
2484 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2485 fcp_cmnd_iu->task_management_flags = tm_flags;
2487 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2488 if (!zfcp_fsf_req_send(req))
2491 zfcp_fsf_req_free(req);
2494 spin_unlock_bh(&adapter->req_q_lock);
2498 static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2503 * zfcp_fsf_control_file - control file upload/download
2504 * @adapter: pointer to struct zfcp_adapter
2505 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2506 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
2508 struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2509 struct zfcp_fsf_cfdc *fsf_cfdc)
2511 struct qdio_buffer_element *sbale;
2512 struct zfcp_fsf_req *req = NULL;
2513 struct fsf_qtcb_bottom_support *bottom;
2514 int direction, retval = -EIO, bytes;
2516 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2517 return ERR_PTR(-EOPNOTSUPP);
2519 switch (fsf_cfdc->command) {
2520 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2521 direction = SBAL_FLAGS0_TYPE_WRITE;
2523 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2524 direction = SBAL_FLAGS0_TYPE_READ;
2527 return ERR_PTR(-EINVAL);
2530 spin_lock_bh(&adapter->req_q_lock);
2531 if (zfcp_fsf_req_sbal_get(adapter))
2534 req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL);
2540 req->handler = zfcp_fsf_control_file_handler;
2542 sbale = zfcp_qdio_sbale_req(req);
2543 sbale[0].flags |= direction;
2545 bottom = &req->qtcb->bottom.support;
2546 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
2547 bottom->option = fsf_cfdc->option;
2549 bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg,
2550 FSF_MAX_SBALS_PER_REQ);
2551 if (bytes != ZFCP_CFDC_MAX_SIZE) {
2552 zfcp_fsf_req_free(req);
2556 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2557 retval = zfcp_fsf_req_send(req);
2559 spin_unlock_bh(&adapter->req_q_lock);
2562 wait_for_completion(&req->completion);
2565 return ERR_PTR(retval);
2569 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2570 * @adapter: pointer to struct zfcp_adapter
2571 * @sbal_idx: response queue index of SBAL to be processed
2573 void zfcp_fsf_reqid_check(struct zfcp_adapter *adapter, int sbal_idx)
2575 struct qdio_buffer *sbal = adapter->resp_q.sbal[sbal_idx];
2576 struct qdio_buffer_element *sbale;
2577 struct zfcp_fsf_req *fsf_req;
2578 unsigned long flags, req_id;
2581 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2583 sbale = &sbal->element[idx];
2584 req_id = (unsigned long) sbale->addr;
2585 spin_lock_irqsave(&adapter->req_list_lock, flags);
2586 fsf_req = zfcp_reqlist_find(adapter, req_id);
2590 * Unknown request means that we have potentially memory
2591 * corruption and must stop the machine immediately.
2593 panic("error: unknown req_id (%lx) on adapter %s.\n",
2594 req_id, dev_name(&adapter->ccw_device->dev));
2596 list_del(&fsf_req->list);
2597 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
2599 fsf_req->sbal_response = sbal_idx;
2600 fsf_req->qdio_inb_usage = atomic_read(&adapter->resp_q.count);
2601 zfcp_fsf_req_complete(fsf_req);
2603 if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))